pi-gauntlet 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/LICENSE +24 -0
  3. package/README.md +278 -0
  4. package/agents/code-reviewer.md +48 -0
  5. package/agents/conformance-reviewer.md +139 -0
  6. package/agents/implementer.md +40 -0
  7. package/agents/spec-council-member.md +47 -0
  8. package/agents/spec-council-synthesizer.md +39 -0
  9. package/agents/spec-reviewer.md +47 -0
  10. package/agents/spec-summarizer.md +42 -0
  11. package/bin/install-agents.mjs +141 -0
  12. package/extensions/phase-tracker.ts +622 -0
  13. package/extensions/plan-tracker.ts +308 -0
  14. package/extensions/verify-before-ship.ts +132 -0
  15. package/package.json +43 -0
  16. package/skills/brainstorming/SKILL.md +290 -0
  17. package/skills/dispatching-parallel-agents/SKILL.md +192 -0
  18. package/skills/finishing-a-development-branch/SKILL.md +311 -0
  19. package/skills/receiving-code-review/SKILL.md +200 -0
  20. package/skills/requesting-code-review/SKILL.md +115 -0
  21. package/skills/requesting-code-review/code-reviewer.md +166 -0
  22. package/skills/roasting-the-spec/SKILL.md +139 -0
  23. package/skills/subagent-driven-development/SKILL.md +223 -0
  24. package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +25 -0
  25. package/skills/subagent-driven-development/implementer-prompt.md +113 -0
  26. package/skills/subagent-driven-development/spec-reviewer-prompt.md +68 -0
  27. package/skills/systematic-debugging/SKILL.md +151 -0
  28. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  29. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  30. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  31. package/skills/systematic-debugging/find-polluter.sh +63 -0
  32. package/skills/systematic-debugging/reference/rationalizations.md +61 -0
  33. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  34. package/skills/test-driven-development/SKILL.md +230 -0
  35. package/skills/test-driven-development/reference/examples.md +99 -0
  36. package/skills/test-driven-development/reference/rationalizations.md +65 -0
  37. package/skills/test-driven-development/reference/when-stuck.md +31 -0
  38. package/skills/test-driven-development/testing-anti-patterns.md +299 -0
  39. package/skills/using-git-worktrees/SKILL.md +193 -0
  40. package/skills/verification-before-completion/SKILL.md +169 -0
  41. package/skills/verification-before-completion/reference/conformance-check.md +220 -0
  42. package/skills/writing-plans/SKILL.md +244 -0
  43. package/skills/writing-skills/SKILL.md +429 -0
  44. package/skills/writing-skills/reference/anthropic-best-practices.md +1130 -0
  45. package/skills/writing-skills/reference/persuasion.md +187 -0
  46. package/skills/writing-skills/reference/testing-skills-with-subagents.md +384 -0
@@ -0,0 +1,290 @@
1
+ ---
2
+ name: brainstorming
3
+ description: "You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation."
4
+ ---
5
+
6
+ > **Related skills:** Use `/skill:using-git-worktrees` **before** writing the spec — the spec is the worktree's first artifact. Then `/skill:writing-plans` for implementation planning.
7
+
8
+ # Brainstorming Ideas Into Designs
9
+
10
+ ## Overview
11
+
12
+ Help turn ideas into fully formed designs and specs through natural collaborative dialogue.
13
+
14
+ Identify the target project → set up an isolated worktree → understand current project context → ask questions one at a time → propose 2-3 approaches with trade-offs → present the design in 200-300-word sections, validating each → write spec to disk inside the worktree → user reviews before any implementation.
15
+
16
+ ## HARD CONSTRAINT
17
+
18
+ While this skill is active, do **not** take any implementation action until you have presented a design and the user has approved it. This applies to **every** change regardless of perceived simplicity. An implementation-heavy request ("test it end-to-end", "push a request to rabbit", "run the service") does not lift this gate — it just tells you what the spec must cover.
19
+
20
+ You **may**:
21
+ - Read code and docs
22
+ - Run the existing system to observe its **current** behaviour — this is research and feeds the spec (boot a local service, replay a sample request, capture a baseline classification, etc.)
23
+ - Write to the project's `doc/specs/` directory
24
+
25
+ You may **not**:
26
+ - Write or edit code outside `doc/specs/`
27
+ - Scaffold a project, or take any action that builds, deploys, or validates the **proposed change** — running new/edited code, exercising behaviour that doesn't exist yet, or "testing the fix" before there is one
28
+ - Run implementation skills (`/skill:test-driven-development`, `/skill:subagent-driven-development`, etc.)
29
+ - Commit the spec directly on `main` in the primary checkout — it must land inside the worktree (see [Worktree First](#worktree-first))
30
+ - Start writing the plan (that's `/skill:writing-plans` — separate phase)
31
+
32
+ The line: exercising the system **as it is today** is research; exercising the **change you're proposing** is implementation and waits for the gate.
33
+
34
+ This skill ends with a **written, user-reviewed spec inside a worktree**. Nothing else.
35
+
36
+ ## Checklist
37
+
38
+ Work through the items below **in order**. This is your own checklist to follow, not a `plan_tracker` plan — brainstorming is open-ended exploration, and `plan_tracker` is execution-only (the implement phase). The terminal state is the user review gate; after approval the **only** next skill is `/skill:writing-plans`. Do not jump to implementation, and do not silently drop the critique pass.
39
+
40
+ 1. **Start brainstorm tracking (fresh epoch)** — as the **first action on entry**, before reading code, setting up the worktree, or answering the user, reset **both** trackers and then start the phase. A new brainstorm is a new flow, so it owns a clean slate — clear any stale phases *and* tasks left in the session by earlier work:
41
+ ```
42
+ phase_tracker({ action: "reset" }) // clears all phases
43
+ plan_tracker({ action: "clear" }) // clears all tasks
44
+ phase_tracker({ action: "start", phase: "brainstorm" })
45
+ ```
46
+ Re-entering while a brainstorm is already in progress is safe: mid-brainstorm there are no tasks or later phases to lose, so the reset just re-establishes the same clean slate.
47
+ 2. **Set up the worktree** — see [Worktree First](#worktree-first)
48
+ 3. **Explore project context** — files, docs, recent commits, current behaviour
49
+ 4. **Ask clarifying questions** — one at a time
50
+ 5. **Propose 2-3 approaches** — with trade-offs and a recommendation
51
+ 6. **Present the design** — in sections, get approval after each
52
+ 7. **Write the spec** — to `doc/specs/` (see [Filename Convention](#filename-convention))
53
+ 8. **Spec self-review (lint)** — placeholder scan + internal consistency + documentation named, run inline
54
+ 9. **Critique pass (auto-dispatched)** — scope + ambiguity; the spec council via `/skill:roasting-the-spec` when `members` is configured, else a fresh `worker` (see [Spec Council](#spec-council-optional))
55
+ 10. **Re-run placeholder scan** — after the critique pass returns, first inline any `external-ref:` flags it raised (see [Spec Self-Review](#spec-self-review-before-user-review-gate)), then re-scan for placeholders its edits may have introduced; surface any ambiguity the worker could not safely resolve at the user gate
56
+ 11. **Generate spec summary** — dispatch a fresh, spec-only `spec-summarizer` and render its returned text **verbatim** at the top of the gate message — do not paraphrase, condense, re-section, or rewrite it (see [User Review Gate](#user-review-gate)); this is part of the existing gate, not a new one
57
+ 12. **User review gate** — user reviews the committed spec
58
+ 13. **Transition** — only after approval, invoke `/skill:writing-plans`
59
+
60
+ ## Project Routing
61
+
62
+ Before brainstorming, identify the target project. The match drives the spec directory, AGENTS.md to read, and verification commands.
63
+
64
+ Read the repo's top-level `AGENTS.md` (already in pi's context) and any service-level `AGENTS.md` for the area the user mentioned. If the project documents a routing table mapping subprojects to spec directories and verification commands, follow it. Otherwise rely on the conventions you find.
65
+
66
+ Detection order:
67
+ 1. Issue tracker reference (Linear, Jira, GitHub Issues) → infer from labels, description, or mentioned file paths
68
+ 2. cwd inside a service / package directory → use that area
69
+ 3. Unclear → ask the developer
70
+
71
+ If the project's `AGENTS.md` calls out additional reading for a specific area (e.g. a TDD workflow doc), read it before brainstorming work in that area.
72
+
73
+ ## Worktree First
74
+
75
+ The spec is the **first commit in a dedicated worktree**, not a separate commit on `main`. Before drafting any spec content:
76
+
77
+ 1. Invoke `/skill:using-git-worktrees`. Worktrees live under `.worktrees/` at the repo root, or wherever a project-native worktree script places them.
78
+ 2. Switch into the worktree.
79
+ 3. From there, write the spec, run self-review, commit, hand off.
80
+
81
+ Spec doc, plan doc, and implementation all live in the same worktree and ship together as a single squash commit (see `/skill:finishing-a-development-branch`).
82
+
83
+ **Exception:** trivial one-off edits the user explicitly asks for outside this skill flow (e.g. "fix this typo") do not require a worktree.
84
+
85
+ ## The Process
86
+
87
+ ### 1. Check git state
88
+
89
+ ```bash
90
+ git status
91
+ git --no-pager log --oneline -5
92
+ ```
93
+
94
+ If on a feature branch with uncommitted or unmerged work, ask:
95
+
96
+ > "You're on `<branch>` with uncommitted changes. Want to finish/merge that first, stash it, or continue here?"
97
+
98
+ Require one of: finish prior work, stash, or explicit "continue here". If the topic is new, set up the worktree per [Worktree First](#worktree-first) before continuing.
99
+
100
+ ### 2. Scope check
101
+
102
+ If the request spans multiple independent subsystems (e.g., "build a new ingestion pipeline and a new admin UI and a new auth flow"), stop and flag it:
103
+
104
+ > "This looks like 2-3 independent specs to me — A, B, C. Should we brainstorm each separately, or is there a tight coupling I'm missing?"
105
+
106
+ Don't try to design a multi-subsystem monolith in one spec doc.
107
+
108
+ ### 3. Understand the idea
109
+
110
+ - Check the current project state first: files, docs, recent commits, neighboring services.
111
+ - **Check if the codebase or ecosystem already solves this** before designing from scratch. Grep, read existing AGENTS.md, look at `doc/` and `doc/specs/`.
112
+ - Ask questions **one at a time** to refine the idea.
113
+ - Prefer multiple-choice questions; open-ended is fine when needed.
114
+ - One question per message. If a topic needs more exploration, split into multiple turns.
115
+ - Focus on: purpose, constraints, success criteria, who/what it touches.
116
+
117
+ ### 4. Explore approaches
118
+
119
+ - Propose 2-3 different approaches with trade-offs.
120
+ - Lead with your recommended option and explain why.
121
+ - Present conversationally — don't dump a comparison table unless the user asks.
122
+
123
+ ### 5. Design for clarity and isolation
124
+
125
+ When sketching the design, prefer:
126
+
127
+ - **Clear boundaries** — clean interfaces between components, easy to test in isolation.
128
+ - **YAGNI ruthlessly** — every component you add is a component you must maintain.
129
+ - **Match existing patterns** — if a service has a convention, follow it. Reference the service's `AGENTS.md` and neighboring code.
130
+ - **Single source of truth** — point at the schema/contract that owns the data (the migration, type definition, or API contract that defines it); don't invent parallel state.
131
+ - **Explicit error and edge cases** — name them. "Out of scope" is a valid answer, but it has to be stated.
132
+
133
+ ### 6. Present the design in sections
134
+
135
+ Sections of 200-300 words. Ask after each whether it looks right.
136
+
137
+ Cover at minimum:
138
+ - Architecture overview
139
+ - Components / responsibilities
140
+ - Data flow (or request flow)
141
+ - Error handling and edge cases
142
+ - Testing approach
143
+ - Documentation impact — name each doc that changes (README, AGENTS.md, CHANGELOG, API contracts, inline docs), or write "none". Doc updates ship in the same commit and are verified against the spec by the conformance gate.
144
+
145
+ Be ready to go back and clarify when something doesn't make sense.
146
+
147
+ ## Linear Ticket Handling
148
+
149
+ When a ticket ID is given, fetch the ticket and treat it as **guidance, not the sole source of truth**. Propose changes to scope, approach, or acceptance criteria when they don't align with the codebase. Surface deviations in the spec doc.
150
+
151
+ ## First-Feature Oversight (Early Project Stages)
152
+
153
+ For the **first two features** of a new initiative — a new top-level module/package, a new long-lived component, a new persistence/schema area, or any pattern that will repeat — pause and ask the developer to confirm before proceeding on:
154
+
155
+ - Directory and module structure decisions
156
+ - Naming conventions (public types, files, routes, identifiers)
157
+ - New shared abstraction (location, responsibility, boundary)
158
+ - Persistence/schema design (entity names, field types, indexing)
159
+ - Proposed additions to AGENTS.md or doc/ files
160
+
161
+ If the developer hasn't provided guidance, ask explicitly:
162
+ > "This is one of the first features in this initiative. Before I proceed, I need your confirmation on: [list specific decisions]."
163
+
164
+ After the first two features establish patterns, follow those patterns without gating.
165
+
166
+ ## Anti-Pattern: "Too simple to need a design"
167
+
168
+ Watch for the rationalization "this is just a small change, let's skip the spec and code it":
169
+
170
+ - Small changes that touch shared schemas, contracts, or invariants need a spec.
171
+ - "Small" often hides assumptions that the spec process would surface.
172
+ - A 5-minute spec saves an hour of rework when the assumption was wrong.
173
+
174
+ If the change truly is mechanical and contained (rename, formatter run, dependency bump), say so explicitly and skip brainstorming. Otherwise: spec first.
175
+
176
+ ## Filename Convention
177
+
178
+ Spec lives in the project's `doc/specs/` (see [Project Routing](#project-routing)) with one of:
179
+
180
+ - With Linear ticket: `YYYY-MM-DD-E-12345-<topic>.md`
181
+ - Without Linear ticket: `YYYY-MM-DD-<topic>.md`
182
+
183
+ `<topic>` is a short kebab-case slug (3–6 words). Do **not** append `-design` or any other suffix.
184
+
185
+ ## Spec Self-Review (Before User Review Gate)
186
+
187
+ After writing the spec to `<project>/doc/specs/<filename>.md` (per [Filename Convention](#filename-convention)) and before showing it to the user, run a self-review pass. **Read all five bullets first, then act:** only the **first three** run here at the main loop (the inline lint); the **last two** (scope + ambiguity) do **not** run inline — they are the dispatched critique pass (checklist item 9). Do not apply scope/ambiguity edits yourself.
188
+
189
+ - **Placeholder scan.** Any `TODO`, `TBD`, `<fill in>`, `[example]`, `xxx`? Either resolve them or convert to explicit "Open Questions" with names.
190
+ - **Internal consistency.** Does Section 4 contradict Section 2? Are component names and field names consistent throughout?
191
+ - **Documentation named.** Does the spec state which docs change (or an explicit "none")?
192
+ - **Scope check.** Does every paragraph serve the goal? Cut filler. If something is out of scope, say it's out of scope.
193
+ - **Ambiguity check.** Is every "we should…" backed by a concrete decision? Replace "we could probably" with "we will" or "we won't".
194
+
195
+ The first three checks — **placeholder scan**, **internal consistency**, and **documentation named** — are the inline **lint**: run them here at the main loop and fix what they surface. The last two — **scope** and **ambiguity** — are **not** run inline; they are the **critique pass**, auto-dispatched (per [Spec Council](#spec-council-optional)):
196
+
197
+ - **Council configured** (`piGauntlet.specCouncil.members` non-empty) → invoke `/skill:roasting-the-spec`; it runs the critique and proposes dispositions.
198
+ - **Otherwise** → dispatch one fresh `worker` that applies the scope + ambiguity checks and fixes them in place:
199
+
200
+ ```
201
+ subagent({ agent: "worker", context: "fresh", cwd: "<abs worktree path, from git rev-parse --show-toplevel>", task:
202
+ "Problem statement: <the problem the spec addresses + the user's stated intent>.\n" +
203
+ "Read the spec at <abs path to doc/specs/...>. Edit ONLY that file. Apply two checks and\n" +
204
+ "fix what you find in place: (1) Scope — does every paragraph serve the goal? Cut filler;\n" +
205
+ "state out-of-scope explicitly. (2) Ambiguity — is every 'we should' a concrete decision?\n" +
206
+ "Replace 'we could probably' with 'we will'/'we won't'. Also flag (do NOT fetch) any\n" +
207
+ "load-bearing external reference (ticket AC, commit SHA, doc) the spec relies on but does\n" +
208
+ "not inline, and recommend inlining it. Return a summary of what you changed, and flag any\n" +
209
+ "ambiguity you could NOT safely resolve." })
210
+ ```
211
+
212
+ `worker`'s model resolves from `subagents.agentOverrides.worker.model` in `settings.json` (unset → inherits the main loop); the dispatch passes no `model:`.
213
+
214
+ After the critique pass returns, scan it for load-bearing external references before re-running the placeholder scan: in the council path, look for chair clusters whose theme is prefixed `external-ref:`; in the worker path, look for the worker's external-ref flag. For each, inline the referenced content you have context for (e.g. the ticket fetched during brainstorming) via the normal disposition/edit path - you hold the ticket, the critics do not. Then re-run the placeholder scan to catch anything the edits introduced. If the worker flagged ambiguities it could not safely resolve, surface them in the [User Review Gate](#user-review-gate) message so the user decides - the worker auto-applies fixes but never silently swallows an open question.
215
+
216
+ ## Spec Council (Optional)
217
+
218
+ After the inline lint and before the user review gate, **brainstorming owns the critique-pass gate**: resolve `piGauntlet.specCouncil` from **two** settings files, repo-local first, and select the path.
219
+
220
+ Lookup order (first file that **defines** `specCouncil` wins — do not merge across files):
221
+
222
+ 1. `<repo-root>/.pi/settings.json` — repo root from `git rev-parse --show-toplevel` (the worktree root inside a worktree). A repo that defines `specCouncil` overrides the preset, even with empty `members` (explicit "no council here").
223
+ 2. `$PI_CODING_AGENT_DIR/settings.json` — agent preset; consulted only when the repo file does not define `specCouncil`.
224
+
225
+ Both files may contain comments — read them, don't strict-parse. **Expand `$PI_CODING_AGENT_DIR`; never substitute a hardcoded project path for it** (reading the repo `.pi/settings.json` as if it were the preset file is the classic miss — repo-local and preset are different files). **When `members` is non-empty, the council *is* the critique pass — invoke `/skill:roasting-the-spec` automatically (no offer, no prompt).** When it is absent or empty, run the fresh-`worker` critique instead (see [Spec Self-Review](#spec-self-review-before-user-review-gate)); if `specCouncil` is present but malformed, emit one warning line and fall back to the worker. Approved council edits (or the worker's in-place fixes) are applied to the spec and ride in the same worktree commit as the rest of this skill's output.
226
+
227
+ ## User Review Gate
228
+
229
+ After self-review (and council review, if configured) and after inlining any external-ref flags, dispatch the spec-only summarizer, then commit the spec on the worktree branch and stop. This is the **same** single human gate - the summary is folded into it, not a new gate.
230
+
231
+ Dispatch the summarizer on a fresh context, reading only the spec (no `output:` path - capture the return inline; no `model:` - it inherits the main loop unless a preset sets `subagents.agentOverrides.spec-summarizer.model`):
232
+
233
+ ```
234
+ subagent({ agent: "spec-summarizer", context: "fresh", cwd: "<abs worktree path, from git rev-parse --show-toplevel>", task:
235
+ "Summarize the spec at <abs path to doc/specs/...> for the user review gate. Read ONLY that file." })
236
+ ```
237
+
238
+ If the dispatch fails, reach the gate anyway with a one-line "summary generation failed" note - the summary is an aid, not a gate.
239
+
240
+ Render the summarizer's returned text **verbatim** first — paste it as-is, do **not** paraphrase, condense, re-section, drop sections, or merge it with council output. "Fold into the gate" means *place it inside the gate message*, not *rewrite it*. After the verbatim block, append the commit confirmation, then — as their **own** adjacent lines, not edits to the summary — any council outcome, critique-pass-unresolved ambiguities, and every entry from the summarizer's gap/external-context footer (surface **all** of them, not just the top risk):
241
+
242
+ ```
243
+ <spec-only summary from spec-summarizer — pasted verbatim, unedited>
244
+
245
+ Spec written and committed to <project>/doc/specs/<filename>.md (worktree: <path>).
246
+
247
+ <council outcome, if any; unresolved ambiguities; every gap-footer entry from the summary>
248
+
249
+ Please review. Approve to proceed, or tell me what to change in the spec.
250
+ ```
251
+
252
+ If you believe the summary needs correcting, do **not** silently rewrite it — re-dispatch the summarizer or note the discrepancy as an adjacent line beneath the verbatim block.
253
+
254
+ Wait for the user. On a change request, revise and re-present. On approval, proceed immediately to `/skill:writing-plans` with no further prompt — the plan and execution mode are mechanical derivatives, so the only human gate here is spec approval itself. Don't land the spec on `main`; it stays in the worktree and ships in the same squash commit as the implementation.
255
+
256
+ After approval, mark the brainstorm phase complete:
257
+
258
+ ```
259
+ phase_tracker({ action: "complete", phase: "brainstorm" })
260
+ ```
261
+
262
+ ## Key Principles
263
+
264
+ - **One question at a time.**
265
+ - **Multiple choice preferred** when possible.
266
+ - **YAGNI ruthlessly.**
267
+ - **Design for testability** — clear boundaries enable TDD.
268
+ - **Explore 2-3 approaches** before settling.
269
+ - **Incremental validation** — present in sections, validate each.
270
+ - **Be flexible** — go back and clarify when something doesn't make sense.
271
+
272
+ ## Red Flags — STOP
273
+
274
+ - About to write code or start a non-spec edit while this skill is active
275
+ - About to run, deploy, or validate the **proposed change** (vs. observing current behaviour) before the user approved the design
276
+ - About to skip the critique pass (council if configured, else fresh worker)
277
+ - Critique dispatch (council or worker) failed to complete and you proceeded to the gate anyway
278
+ - About to reach the user gate without re-running the placeholder scan after the critique returned
279
+ - About to reach the user gate without rendering the spec-only summary (dispatch `spec-summarizer` first; a failed dispatch degrades to a one-line note, it is not silently skipped)
280
+ - About to present a paraphrased, condensed, or re-sectioned version of the summarizer's output instead of pasting its returned text verbatim — rewriting the summary counts as not rendering it
281
+ - About to run the scope or ambiguity checks inline yourself instead of dispatching them (those two are the critique pass, not the inline lint)
282
+ - About to skip the self-review pass
283
+ - About to proceed to `/skill:writing-plans` before the user has approved the spec (proceeding *after* approval is correct; skipping the gate is the violation)
284
+ - Spec contains `TODO`, `TBD`, or unnamed components
285
+ - Spec spans multiple independent subsystems with no decomposition flag
286
+ - User said "this is just a small change" and you accepted it without applying the [Anti-Pattern](#anti-pattern-too-simple-to-need-a-design) check
287
+
288
+ ## Project overrides
289
+
290
+ If `.pi/gauntlet-overrides.md` exists, read it. Any sections relevant to this skill — by name match, by topic (routing, verification, worktrees, etc.), or by workflow convention — override or extend the instructions above. Project-local `AGENTS.md` is already in context — check it for project-specific routing tables, service paths, and verification commands.
@@ -0,0 +1,192 @@
1
+ ---
2
+ name: dispatching-parallel-agents
3
+ description: Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies
4
+ ---
5
+
6
+ > **Related skills:** Debug each problem with `/skill:systematic-debugging`. Verify all fixes with `/skill:verification-before-completion`.
7
+
8
+ # Dispatching Parallel Agents
9
+
10
+ ## Overview
11
+
12
+ When you have multiple **independent tasks** — unrelated test failures, or implementation tasks from a plan wave — that touch disjoint files, running them sequentially wastes time. Each can happen in parallel.
13
+
14
+ **Core principle:** Dispatch one agent per independent problem domain (one bug, one subsystem, or one plan task). Let them work concurrently.
15
+
16
+ This skill is the **mechanic home** for parallel fan-out: fresh-context isolation, `worktree: true` filesystem isolation, and serial patch integration. `subagent-driven-development`'s Parallel-Wave Mode builds its per-wave dispatch on this skill — debugging is the worked example below, but the mechanics are identical for implementation tasks.
17
+
18
+ **Why parallel subagents:** each agent gets a fresh context window with only its problem domain. No cross-contamination between investigations, smaller diffs, faster wall-clock time. You stay the orchestrator — you read the summaries, resolve any file overlap, and run the integrated tests.
19
+
20
+ **Fresh context is not the default.** Some packaged subagents (including `worker`) fork the parent context unless you opt out. Always pass `context: "fresh"` on every task entry — if it's missing, you're getting forked agents and losing the isolation that makes parallel dispatch worth doing in the first place.
21
+
22
+ ## When to Use
23
+
24
+ ```dot
25
+ digraph when_to_use {
26
+ "Multiple failures?" [shape=diamond];
27
+ "Are they independent?" [shape=diamond];
28
+ "Single agent investigates all" [shape=box];
29
+ "One agent per problem domain" [shape=box];
30
+ "Can they work in parallel?" [shape=diamond];
31
+ "Sequential agents" [shape=box];
32
+ "Parallel dispatch" [shape=box];
33
+
34
+ "Multiple failures?" -> "Are they independent?" [label="yes"];
35
+ "Are they independent?" -> "Single agent investigates all" [label="no - related"];
36
+ "Are they independent?" -> "Can they work in parallel?" [label="yes"];
37
+ "Can they work in parallel?" -> "Parallel dispatch" [label="yes"];
38
+ "Can they work in parallel?" -> "Sequential agents" [label="no - shared state"];
39
+ }
40
+ ```
41
+
42
+ **Use when:**
43
+ - 3+ test files failing with different root causes
44
+ - Multiple subsystems broken independently
45
+ - Each problem can be understood without context from others
46
+ - No shared state between investigations
47
+
48
+ **Don't use when:**
49
+ - Failures are related (fix one might fix others)
50
+ - Need to understand full system state
51
+ - Agents would interfere with each other
52
+
53
+ ## The Pattern
54
+
55
+ ### 1. Identify Independent Domains
56
+
57
+ Group failures by what's broken:
58
+ - File A tests: Tool approval flow
59
+ - File B tests: Batch completion behavior
60
+ - File C tests: Abort functionality
61
+
62
+ Each domain is independent - fixing tool approval doesn't affect abort tests.
63
+
64
+ ### 2. Create Focused Agent Tasks
65
+
66
+ Each agent gets:
67
+ - **Specific scope:** One test file or subsystem
68
+ - **Clear goal:** Make these tests pass
69
+ - **Constraints:** Don't change other code
70
+ - **Expected output:** Summary of what you found and fixed
71
+
72
+ ### 3. Dispatch in Parallel
73
+
74
+ **How to dispatch:**
75
+
76
+ Use the `subagent` tool in parallel mode, with explicit fresh context per task:
77
+
78
+ ```ts
79
+ subagent({
80
+ context: "fresh",
81
+ tasks: [
82
+ { agent: "worker", task: "Fix agent-tool-abort.test.ts failures" },
83
+ { agent: "worker", task: "Fix batch-completion-behavior.test.ts failures" },
84
+ { agent: "worker", task: "Fix tool-approval-race-conditions.test.ts failures" },
85
+ ],
86
+ })
87
+ ```
88
+
89
+ The top-level `context: "fresh"` applies to every task in the batch. Omitting it produces parallel-but-forked agents that share parent history — the worst of both worlds.
90
+
91
+ **Editing tasks:** add `worktree: true` so each task's writes are isolated in its own git worktree (see [pi-cohort Integration](#pi-cohort-integration)); omit it only for read-only investigations.
92
+
93
+ ### 4. Review and Integrate
94
+
95
+ When agents return:
96
+ - Read each summary
97
+ - Verify fixes don't conflict
98
+ - Run full test suite
99
+ - Integrate all changes
100
+
101
+ **If agents edited the same files (textual conflict):** the orchestrator does **not** hand-merge code. Prefer re-running one agent sequentially with the other's integrated changes as context, so it adapts. Manual per-hunk merge is a last resort. (Avoid this entirely by giving each agent disjoint files — see the file-ownership contract in `writing-plans`.)
102
+
103
+ **If integrated changes apply cleanly but the suite fails (semantic conflict):** agents made incompatible assumptions across disjoint files (renamed symbol, changed shape). Diagnose the incompatible pair and re-run the offending task sequentially on the integrated HEAD.
104
+
105
+ **If some agents failed:** Integrate successful agents first (commit their work). Then retry the failed agent with fresh context that includes the integrated changes.
106
+
107
+ ## Agent Prompt Structure
108
+
109
+ Good agent prompts are:
110
+ 1. **Focused** - One clear problem domain
111
+ 2. **Self-contained** - All context needed to understand the problem
112
+ 3. **Specific about output** - What should the agent return?
113
+
114
+ ```markdown
115
+ Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
116
+
117
+ 1. "should abort tool with partial output capture" - expects 'interrupted at' in message
118
+ 2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed
119
+ 3. "should properly track pendingToolCount" - expects 3 results but gets 0
120
+
121
+ These are timing/race condition issues. Your task:
122
+
123
+ 1. Read the test file and understand what each test verifies
124
+ 2. Identify root cause - timing issues or actual bugs?
125
+ 3. Fix by:
126
+ - Replacing arbitrary timeouts with event-based waiting
127
+ - Fixing bugs in abort implementation if found
128
+ - Adjusting test expectations if testing changed behavior
129
+
130
+ Do NOT just increase timeouts - find the real issue.
131
+
132
+ Return: Summary of what you found and what you fixed.
133
+ ```
134
+
135
+ ## Common Mistakes
136
+
137
+ **❌ Too broad:** "Fix all the tests" - agent gets lost
138
+ **✅ Specific:** "Fix agent-tool-abort.test.ts" - focused scope
139
+
140
+ **❌ No context:** "Fix the race condition" - agent doesn't know where
141
+ **✅ Context:** Paste the error messages and test names
142
+
143
+ **❌ No constraints:** Agent might refactor everything
144
+ **✅ Constraints:** "Do NOT change production code" or "Fix tests only"
145
+
146
+ **❌ Vague output:** "Fix it" - you don't know what changed
147
+ **✅ Specific:** "Return summary of root cause and changes"
148
+
149
+ ## When NOT to Use
150
+
151
+ **Related failures:** Fixing one might fix others - investigate together first
152
+ **Need full context:** Understanding requires seeing entire system
153
+ **Exploratory debugging:** You don't know what's broken yet
154
+ **Shared state:** Agents would interfere (editing same files, using same resources)
155
+
156
+ ## pi-cohort Integration
157
+
158
+ Parallel dispatch rides on the `subagent` tool (the pi-cohort package). Mechanics that matter here:
159
+
160
+ - **Parallel mode** — pass a `tasks` array; entries run concurrently. `concurrency` (default 4) caps how many run at once.
161
+ - **Context** — `context: "fresh"` at the top level applies to every task. Mandatory here (see above); without it `worker` forks parent history and you lose isolation.
162
+ - **Filesystem isolation** — `worktree: true` runs each task in its own git worktree so concurrent edits can't collide. Requires clean git state; each task's diff returns separately for you to integrate. Omit it for read-only investigations.
163
+ - **Worktree base / `cwd`** — under `worktree: true` the base commit is `HEAD` resolved from the **top-level `cwd`**, which defaults to the orchestrator's process cwd. When you orchestrate from inside a git worktree, pass that worktree's absolute path as the top-level `cwd`, or children branch from the wrong checkout. Don't set per-task `cwd` with `worktree: true` — it must equal the shared cwd or the run errors.
164
+ - **Agent choice** — `worker` is the pi-cohort builtin generalist. Use a persona (`implementer`, `code-reviewer`) when you want its system prompt and tool profile. Persona frontmatter (tools, thinking, context) is fixed; only `model`, `task`, `output`, `reads`, `progress`, `skill` are callable per task.
165
+ - **Output capture** — `output: "<file>"` writes a task's summary to a file instead of inline; add `outputMode: "file-only"` for large results.
166
+
167
+ ```ts
168
+ subagent({
169
+ context: "fresh",
170
+ worktree: true, // isolate edits; omit for read-only investigations
171
+ concurrency: 3,
172
+ tasks: [
173
+ { agent: "worker", task: "Fix + explain failures in src/a.test.ts", output: "a.md" },
174
+ { agent: "worker", task: "Fix + explain failures in src/b.test.ts", output: "b.md" },
175
+ { agent: "worker", task: "Fix + explain failures in src/c.test.ts", output: "c.md" },
176
+ ],
177
+ })
178
+ ```
179
+
180
+ For chains, async runs, intercom coordination, and the full agent roster, read the `pi-cohort` skill — this skill covers only the parallel fan-out case.
181
+
182
+ ## Verification
183
+
184
+ After agents return:
185
+ 1. **Review each summary** - Understand what changed
186
+ 2. **Check for conflicts** - Did agents edit same code?
187
+ 3. **Run full suite** - Verify all fixes work together
188
+ 4. **Spot check** - Agents can make systematic errors
189
+
190
+ ## Project overrides
191
+
192
+ If `.pi/gauntlet-overrides.md` exists, read it. Any sections relevant to this skill — by name match, by topic (routing, verification, worktrees, etc.), or by workflow convention — override or extend the instructions above. Project-local `AGENTS.md` is already in context — check it for project-specific routing tables, service paths, and verification commands.