feat(skills,core): worktree guard + per-fork question filter + trade-off mandate#160
Merged
Merged
Conversation
…off mandate
Three coupled fixes that enforce forge protocols across parallel Claude Code
sessions.
1. Worktree branch bleed (skills/_shared/worktree-guard.md + workspace.ts)
/pickup-task creates a git worktree but downstream skills (/implement, /ship,
/qa, /fix, /review, /plan-task) had no cwd contract. Parallel sessions all
sitting in the main checkout clobbered each other's HEAD.
- workspace.create() now writes .forge/worktree-task.json on every worktree
creation as the binding marker (regardless of copyMeta). cleanup()
whitelists the marker and physically removes baseline files before calling
git worktree remove so it stays clean.
- skills/pickup-task inline bash writes the same marker.
- Each task-scoped mutating skill gained a "## Preflight: worktree guard"
block that exits 1 on the default branch when no marker is present, and
warns (but proceeds) on a feature branch without a marker.
- skills/_shared/worktree-guard.md documents the contract.
2. Per-fork architectural questions (ETHOS + plan-task + implement)
Memory file said "90% of architectural forks must be asked via
AskUserQuestion" but the rule lived only in private memory. /plan-task was
thin, /implement only said "STOP and ask", and plans bundled 11 decisions
into rubber-stamped tables.
- ETHOS Confusion Protocol now defines a four-dimension severity filter
(decision_type, blast_radius, reversibility, plan_branch) and explicitly
calls out decision-bundling as an anti-pattern.
- /plan-task adds an explicit fork-detection step, asks per fork in batches
of <=4, and records "Questions asked & answers applied" in the plan.
- /implement applies the same filter to mid-implementation forks and records
each surfaced decision in the commit message body.
3. Trade-off mandate in AskUserQuestion (ETHOS + skills/_shared/question-format)
Existing format had pro/option but trade-offs were implicit. Options-as-pros
trains users to rubber-stamp the recommendation.
- ETHOS now requires every option carry both a benefit and a concrete
trade-off (vendor lock-in, migration cost, irreversibility, blast radius),
with an escape hatch for genuinely equivalent options ("no meaningful
trade-off - this is a naming preference") so agents don't invent contrast.
- skills/_shared/question-format.md is the canonical reference, with
good/bad examples and the five-part structure (re-ground / simplify /
recommend / options / trade-offs).
Verification: 876/887 tests pass (0 fail, 11 pre-existing skips). Build clean
(ESM + CJS). npm-pack-gate clean (0 forbidden paths in 65-file tarball).
forge --version returns 0.2.2.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three coupled fixes to enforce forge protocols across parallel Claude Code sessions. Second-opinion reviewed via
/codex(verdict: agree-with-modification on all three, applied).1. Worktree branch bleed (P0 — operational)
/pickup-taskcorrectly creates agit worktree, but downstream skills had no cwd contract. Parallel sessions all sitting in the main checkout clobbered each other'sHEAD.workspace.create()writes.forge/worktree-task.jsonas the binding marker on every creation (regardless ofcopyMeta).cleanup()whitelists it and physically removes baseline files beforegit worktree removeso it stays clean.skills/pickup-taskinline bash writes the same marker.plan-task,implement,qa,fix,review,ship) gained a Preflight: worktree guard block that exits 1 on the default branch when no marker is present, warns on a feature branch without a marker, and passes silently when the marker is found. Skills that intentionally run from main (sync-status,decompose,push-to-tracker,setup-repo,init) are not guarded.skills/_shared/worktree-guard.mddocuments the contract.2. Per-fork architectural questions
/plan-taskand/implementwere thin and silently auto-decided architectural forks, bundling them into "Questions decided" tables the user rubber-stamped at plan approval.ETHOS.mdConfusion Protocol now defines a four-dimension severity filter (decision_type,blast_radius,reversibility,plan_branch) and calls out decision-bundling as an anti-pattern./plan-taskadds an explicit fork-detection step, asks per fork in batches of ≤4, and records "Questions asked & answers applied" in the plan (not silent decisions)./implementapplies the same filter to mid-implementation forks and records each surfaced decision in the commit message body.3. Trade-off mandate in AskUserQuestion
Existing format presented options as pro-only lists, training users to rubber-stamp the agent's recommendation.
ETHOS.mdConfusion Protocol now requires every option carry both a benefit AND a concrete trade-off (vendor lock-in, migration cost, irreversibility, blast radius).skills/_shared/question-format.mdis the canonical reference, with good/bad examples and the five-part structure (re-ground / simplify / recommend / options / trade-offs).Test plan
npm test— 876/887 pass, 0 fail (11 pre-existing skips)npm run typecheck— cleannpm run build— clean ESM + CJSnpm run test:pack— 0 forbidden paths in 65-file tarballnode dist/bin/forge.cjs --version—0.2.2/pickup-taskthen/implementfrom main checkout — confirm guard refuses/pickup-taskthencdinto worktree, run/implement— confirm guard passesAskUserQuestionfires per-fork, not bundledFiles changed
src/core/workspace.ts— marker write + cleanup whitelist + physical baseline removaltest/unit/workspace.test.ts— marker assertions on both copyMeta variantsETHOS.md— Confusion Protocol expansion (severity filter, trade-off mandate, anti-pattern)skills/_shared/worktree-guard.md(new) — contract docskills/_shared/question-format.md(new) — canonical AskUserQuestion referenceskills/pickup-task/SKILL.md— write marker in inline bashskills/plan-task/SKILL.md— preflight + fork-detection step + severity filterskills/implement/SKILL.md— preflight + mid-fork enforcementskills/{ship,qa,fix,review}/SKILL.md— preflight onlyCodex review (2nd opinion)
Codex agreed with all three diagnoses (9/8/7 confidence) with these modifications, all applied:
Full transcript:
/tmp/codex-three-fixes-review.txt(local).