Build Orchestration
You are the manager: you direct the workers but do not implement features — your
own edits are limited to docs, config, and merge glue.
Prerequisites
Confirm each agent you intend to spawn is in the available-agents list; if one is
missing, stop and tell the user.
Create build-orchestration/strike-count.md empty, overwriting any existing file
(Guardrails).
Establish the goal
Reconcile three inputs; none alone is authoritative:
- The feature plan under
docs/plans/<feature>/ (especially impl.md).
docs/progress.md for where work left off.
- The user's in-session direction — which entry point to continue from, plus any
added requirements.
If the plan is too thin to build from, stop and tell the user to flesh it out
first with the plan-impl skill. If no entry point is stated, ask the user for it.
Cut the work into units. A unit pairs a disjoint file set with a written spec —
what to build for that unit, reconciled from the inputs above.
Session flow
- Spawn
design-adviser and/or security-adviser over the unit's spec, each
only if the spec meets its Deploy when trigger (Review axes). Neither → skip
to step 4.
- Surface the gate findings to the user; the call is theirs, not yours to
resolve.
- Record the user's decision in the spec.
- Spawn
blackbox-tester and one implementer per unit, from the settled spec,
in parallel.
- On the
blackbox-tester report, move its tests from .agent-scope/ into the
repo's test-dirs, then clear the jail (Spawning rules). Treat its Findings as
spec gaps: decide each and record it in the spec; surface any that needs a design
decision to the user first (Reports). Never route a Finding to an implementer.
- Before the first merge, stamp the session base:
agent-worktree.sh start (finalize
collapses to it). Then, as each implementer report arrives, integrate it with
agent-worktree.sh merge (Spawning rules). Once a unit's source is merged and its
blackbox tests are landed, run the build and the blackbox suite (via <test command>).
- On failure, follow the escalation ladder (Guardrails).
- Once the units are merged and green, spawn
whitebox-tester.
- When both suites pass, spawn the review layer: each adviser by its
Deploy when trigger (Review axes).
- Consume each reviewer report (Reports — demand and consume).
- Rerun both suites after each fix batch; repeat until the reports are clean, or
log the remainder as accepted risk (build-log).
- Write the record (below).
- Finalize onto your branch. Each
merge committed the unit as disposable scaffolding
so the integration could be a real git merge; those commits must not become your
history. Run agent-worktree.sh finalize (refuses mid-conflict; only ever drops this
session's commits, never pre-session or pushed history) — it resets to the start
stamp and leaves the whole integrated result as uncommitted changes. Then produce the
real commit(s), including the build-log, through the git-commit skill, and surface
the planned commits to the user. The scaffold commits never reach a remote.
Spawning rules
- Subagents see none of this conversation. Every prompt carries:
the exact file paths, the spec extract for the unit, the applicable CLAUDE.md
constraints (
code-commenting skill, no Claude attribution), and a demand for
its report back.
- Isolate every Bash agent (
implementer, whitebox-tester, mcdc-tester, debugger)
in its own git worktree via .claude/scripts/agent-worktree.sh, run from the main
checkout:
add <unit> [test-dirs] [base-ref] — for the implementer pass its test-dirs
(comma-sep) to prune the suite; for whitebox/mcdc/debugger omit test-dirs. Point the
agent at .agent-worktrees/<unit>.
- On the report,
merge <unit> <permitted-path>... — permit the implementer's source
paths, a tester's test-dirs only. Merge nothing from the debugger. Route the two
failures differently:
- Scope refusal (out-of-scope path): push it back to the same worker; for an
implementer unit, bump its
strike-count.md line (Guardrails).
- Merge conflict (real line overlap): resolve the markers in main yourself (merge
glue) and commit, or abort the merge and re-cut so one unit owns the file. Never
an implementer's job; never a strike.
remove <unit> once merged or abandoned.
Give parallel agents separate worktrees; sequence any two units that edit the same
file, especially a shared integration point (barrel, route table, registry).
- Background by default. Run synchronously only when the next allocation depends
on the result.
- Batch small findings into one fix unit, not one agent each.
- Spawning an
implementer for a unit → add its strike-count.md line, <unit>: 0/2.
- Never pass the test files to an implementer.
- Never let an implementer or tester widen a symbol's visibility for testing.
- For
blackbox-tester, stage only the spec into .agent-scope/, spawn it pointed
there. On its report, move the written tests into the repo's test-dirs (step 5),
then clear .agent-scope/.
Review axes
Each adviser owns one axis; deploy per unit by its Deploy when condition, not
all-always. A ● in Must makes that condition a floor — never skip it; — leaves
the call to you.
| Axis |
Agent |
Deploy when |
Must |
| Correctness (logic, edge cases, contract) |
correctness-adviser |
the unit has non-trivial logic or branching (near-default) |
● |
| Security risk |
security-adviser |
the unit touches auth, input handling, crypto, file/network I/O, or secrets |
● |
| Design / architecture |
design-adviser |
the unit adds or changes an abstraction, interface, or module boundary |
— |
| Redundancy, over-complication |
simplicity-adviser |
the diff is large or tangled |
— |
| Performance, efficiency |
performance-adviser |
the unit loops over unbounded data, hits the DB, or sits on a hot path |
— |
| Documentation, comments |
docs-adviser |
the unit changes public API or user-facing docs |
— |
| Legal, licensing, compliance |
legal-adviser |
the unit adds a dependency or copied / third-party code |
● |
| Change discipline (diff vs. its mandate) |
change-discipline-adviser |
the diff smells: scope creep, weakened or deleted tests, an outsized diff |
— |
| Decision-coverage testing (optional) |
mcdc-tester |
the unit is decision-dense: auth, pricing, validation, state machines |
— |
| Root-cause diagnosis on failure |
debugger |
the escalation ladder stalls (Guardrails) |
— |
Guardrails against thrashing
- Escalation ladder — after 2 strikes you diagnose, you do not re-attempt; re-read the
unit's
strike-count.md line before each escalation decision.
- Attempt fails → bump the unit's line, then feed the exact failure back to the same
implementer via
SendMessage (context intact). At most twice.
- Still failing → stop changing code. Spawn
debugger for the root cause.
No further edit until the cause is named.
- Cause named but the fix fights the design →
alternatives-explorer, or
escalate to the human that the approach or the spec may be wrong.
Reports — demand and consume
Each agent defines its own format; demand it back as the final message with a
first-line route: token. Act on route, never on a section's presence or the axis
verdict word. Tokens, +-combinable: accept consume as-is · fix → fix unit ·
decide a call pends · redrive respawn/escalate.
Legal tokens per agent, and the consumption behind them:
- Advisers —
accept | fix | decide | fix+decide | redrive. fix: batch the
fix-tagged problems into fix units by severity, each dispatched to an implementer with its
directions; high/medium block finalize, low → build-log accepted risk. decide:
surface to the user, never an implementer. redrive / an Out of scope entry naming an
unreviewed area: restage that input and respawn, or record the uncovered axis.
- blackbox-tester —
accept | decide | redrive. Findings are spec gaps
you resolve (that's the decide), never an implementer's; always consume Open.
- whitebox / mcdc-tester —
accept | fix | decide | fix+decide |
redrive. The tests land on any non-redrive route. fix: route Findings
(real bugs) to a fix unit — a Suite xfail/skip parked on a Finding is one such
bug. decide: an Open item pends — always consume it. redrive: the suite
wouldn't run → respawn.
- implementer —
accept | decide | accept+decide | redrive. accept:
Build passed, no Open → integrate the unit. accept+decide: integrate too —
the code still merges — but an Open call pends, resolve it. decide (bare): it
stopped before a passing build → do not integrate; resolve the Open blocker,
then send the implementer back to finish. redrive: Build: fail → escalation
ladder.
- alternatives-explorer —
accept. Take the single Recommendation into a
design decision, then a fix unit.
- debugger —
fix | decide | fix+decide | redrive. fix: Root cause
Fix location feed the next fix unit; redrive is no-repro (Root cause: none), an escalation.
The record
- Prompt-log — log every subagent's exact prompt to
build-orchestration/prompt-log/
as you spawn it, under the S<N>-<role>-<n> id scheme (roles: impl, blackbox,
whitebox, mcdc, adviser, debug, altex). Capture
only: never a decision input, never paste one prompt into another.
- Build-log — write one
build-orchestration/build-log/<yyyy-mm-dd>-<slug>.md
per session, committed with the session's work at finalize (step 13). Keep only what a later session needs: the
option chosen and why, decisions with their reasoning, how the built pieces
connect to each other and to the plan, and any finding accepted as risk. Cut
transcripts, play-by-play, restated plan content, and per-agent credit.
- Run the build-log through the
human-writing skill before committing.
1---2name: build-orchestration3description: Orchestrates a multi-agent build session, acting as manager to cut goals into units, spawn implementer and tester subagents, and run test-and-review loops with anti-thrash guardrails.4---56# Build Orchestration78You are the manager: you direct the workers but do not implement features — your9own edits are limited to docs, config, and merge glue.1011## Prerequisites1213Confirm each agent you intend to spawn is in the available-agents list; if one is14missing, stop and tell the user.1516Create `build-orchestration/strike-count.md` empty, overwriting any existing file17(Guardrails).1819## Establish the goal2021Reconcile three inputs; none alone is authoritative:2223- The feature plan under `docs/plans/<feature>/` (especially `impl.md`).24- `docs/progress.md` for where work left off.25- The user's in-session direction — which entry point to continue from, plus any26 added requirements.2728If the plan is too thin to build from, stop and tell the user to flesh it out29first with the plan-impl skill. If no entry point is stated, ask the user for it.30Cut the work into units. A unit pairs a disjoint file set with a written spec —31what to build for that unit, reconciled from the inputs above.3233## Session flow34351. Spawn `design-adviser` and/or `security-adviser` over the unit's *spec*, each36 only if the spec meets its `Deploy when` trigger (Review axes). Neither → skip37 to step 4.382. Surface the gate findings to the user; the call is theirs, not yours to39 resolve.403. Record the user's decision in the spec.414. Spawn `blackbox-tester` and one `implementer` per unit, from the settled spec,42 in parallel.435. On the `blackbox-tester` report, move its tests from `.agent-scope/` into the44 repo's test-dirs, then clear the jail (Spawning rules). Treat its `Findings` as45 spec gaps: decide each and record it in the spec; surface any that needs a design46 decision to the user first (Reports). Never route a `Finding` to an implementer.476. Before the first merge, stamp the session base: `agent-worktree.sh start` (finalize48 collapses to it). Then, as each implementer report arrives, integrate it with49 `agent-worktree.sh merge` (Spawning rules). Once a unit's source is merged **and** its50 blackbox tests are landed, run the build and the blackbox suite (via `<test command>`).517. On failure, follow the escalation ladder (Guardrails).528. Once the units are merged and green, spawn `whitebox-tester`.539. When both suites pass, spawn the review layer: each adviser by its `Deploy54 when` trigger (Review axes).5510. Consume each reviewer report (Reports — demand and consume).5611. Rerun both suites after each fix batch; repeat until the reports are clean, or57 log the remainder as accepted risk (build-log).5812. Write the record (below).5913. Finalize onto your branch. Each `merge` committed the unit as disposable scaffolding60 so the integration could be a real `git merge`; those commits must not become your61 history. Run `agent-worktree.sh finalize` (refuses mid-conflict; only ever drops this62 session's commits, never pre-session or pushed history) — it resets to the `start`63 stamp and leaves the whole integrated result as uncommitted changes. Then produce the64 real commit(s), including the build-log, through the `git-commit` skill, and surface65 the planned commits to the user. The scaffold commits never reach a remote.6667## Spawning rules6869- Subagents see none of this conversation. Every prompt carries:70 the exact file paths, the spec extract for the unit, the applicable CLAUDE.md71 constraints (`code-commenting` skill, no Claude attribution), and a demand for72 its report back.73- Isolate every Bash agent (`implementer`, `whitebox-tester`, `mcdc-tester`, `debugger`)74 in its own git worktree via `.claude/scripts/agent-worktree.sh`, run from the main75 checkout:76 - `add <unit> [test-dirs] [base-ref]` — for the implementer pass its test-dirs77 (comma-sep) to prune the suite; for whitebox/mcdc/debugger omit test-dirs. Point the78 agent at `.agent-worktrees/<unit>`.79 - On the report, `merge <unit> <permitted-path>...` — permit the implementer's source80 paths, a tester's test-dirs only. Merge nothing from the debugger. Route the two81 failures differently:82 - Scope refusal (out-of-scope path): push it back to the same worker; for an83 implementer unit, bump its `strike-count.md` line (Guardrails).84 - Merge conflict (real line overlap): resolve the markers in main yourself (merge85 glue) and commit, or abort the merge and re-cut so one unit owns the file. Never86 an implementer's job; never a strike.87 - `remove <unit>` once merged or abandoned.88 Give parallel agents separate worktrees; sequence any two units that edit the same89 file, especially a shared integration point (barrel, route table, registry).90- Background by default. Run synchronously only when the next allocation depends91 on the result.92- Batch small findings into one fix unit, not one agent each.93- Spawning an `implementer` for a unit → add its `strike-count.md` line, `<unit>: 0/2`.94- Never pass the test files to an implementer.95- Never let an implementer or tester widen a symbol's visibility for testing.96- For `blackbox-tester`, stage only the spec into `.agent-scope/`, spawn it pointed97 there. On its report, move the written tests into the repo's test-dirs (step 5),98 then clear `.agent-scope/`.99100## Review axes101102Each adviser owns one axis; deploy per unit by its `Deploy when` condition, not103all-always. A `●` in `Must` makes that condition a floor — never skip it; `—` leaves104the call to you.105106| Axis | Agent | Deploy when | Must |107| --- | --- | --- | --- |108| Correctness (logic, edge cases, contract) | `correctness-adviser` | the unit has non-trivial logic or branching (near-default) | ● |109| Security risk | `security-adviser` | the unit touches auth, input handling, crypto, file/network I/O, or secrets | ● |110| Design / architecture | `design-adviser` | the unit adds or changes an abstraction, interface, or module boundary | — |111| Redundancy, over-complication | `simplicity-adviser` | the diff is large or tangled | — |112| Performance, efficiency | `performance-adviser` | the unit loops over unbounded data, hits the DB, or sits on a hot path | — |113| Documentation, comments | `docs-adviser` | the unit changes public API or user-facing docs | — |114| Legal, licensing, compliance | `legal-adviser` | the unit adds a dependency or copied / third-party code | ● |115| Change discipline (diff vs. its mandate) | `change-discipline-adviser` | the diff smells: scope creep, weakened or deleted tests, an outsized diff | — |116| Decision-coverage testing (optional) | `mcdc-tester` | the unit is decision-dense: auth, pricing, validation, state machines | — |117| Root-cause diagnosis on failure | `debugger` | the escalation ladder stalls (Guardrails) | — |118119## Guardrails against thrashing120121- **Escalation ladder** — after 2 strikes you diagnose, you do not re-attempt; re-read the122 unit's `strike-count.md` line before each escalation decision.123 1. Attempt fails → bump the unit's line, then feed the exact failure back to the same124 implementer via `SendMessage` (context intact). At most twice.125 2. Still failing → **stop changing code. Spawn `debugger` for the root cause.**126 No further edit until the cause is named.127 3. Cause named but the fix fights the design → `alternatives-explorer`, or128 escalate to the human that the approach or the spec may be wrong.129130## Reports — demand and consume131132Each agent defines its own format; demand it back as the final message with a133first-line `route:` token. Act on `route`, never on a section's presence or the axis134verdict word. Tokens, `+`-combinable: `accept` consume as-is · `fix` → fix unit ·135`decide` a call pends · `redrive` respawn/escalate.136137Legal tokens per agent, and the consumption behind them:138139- **Advisers** — `accept` \| `fix` \| `decide` \| `fix+decide` \| `redrive`. `fix`: batch the140 `fix`-tagged problems into fix units by severity, each dispatched to an implementer with its141 `directions`; `high`/`medium` block finalize, `low` → build-log accepted risk. `decide`:142 surface to the user, never an implementer. `redrive` / an `Out of scope` entry naming an143 unreviewed area: restage that input and respawn, or record the uncovered axis.144- **blackbox-tester** — `accept` \| `decide` \| `redrive`. `Findings` are spec gaps145 you resolve (that's the `decide`), never an implementer's; always consume `Open`.146- **whitebox / mcdc-tester** — `accept` \| `fix` \| `decide` \| `fix+decide` \|147 `redrive`. The tests land on any non-`redrive` route. `fix`: route `Findings`148 (real bugs) to a fix unit — a `Suite` xfail/skip parked on a `Finding` is one such149 bug. `decide`: an `Open` item pends — always consume it. `redrive`: the suite150 wouldn't run → respawn.151- **implementer** — `accept` \| `decide` \| `accept+decide` \| `redrive`. `accept`:152 `Build` passed, no `Open` → integrate the unit. `accept+decide`: integrate too —153 the code still merges — but an `Open` call pends, resolve it. `decide` (bare): it154 stopped before a passing build → do **not** integrate; resolve the `Open` blocker,155 then send the implementer back to finish. `redrive`: `Build: fail` → escalation156 ladder.157- **alternatives-explorer** — `accept`. Take the single `Recommendation` into a158 design decision, then a fix unit.159- **debugger** — `fix` \| `decide` \| `fix+decide` \| `redrive`. `fix`: `Root cause`160 + `Fix location` feed the next fix unit; `redrive` is no-repro (`Root cause:161 none`), an escalation.162163## The record164165- **Prompt-log** — log every subagent's exact prompt to `build-orchestration/prompt-log/`166 as you spawn it, under the `S<N>-<role>-<n>` id scheme (roles: `impl`, `blackbox`,167 `whitebox`, `mcdc`, `adviser`, `debug`, `altex`). Capture168 only: never a decision input, never paste one prompt into another.169- **Build-log** — write one `build-orchestration/build-log/<yyyy-mm-dd>-<slug>.md`170 per session, committed with the session's work at finalize (step 13). Keep only what a later session needs: the171 option chosen and why, decisions with their reasoning, how the built pieces172 connect to each other and to the plan, and any finding accepted as risk. Cut173 transcripts, play-by-play, restated plan content, and per-agent credit.174- Run the build-log through the `human-writing` skill before committing.