@nklisch/pi-agile-workflow 0.15.3 → 0.16.3

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 (41) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/docs/ARCHITECTURE.md +117 -65
  5. package/docs/PRINCIPLES.md +84 -18
  6. package/docs/SPEC.md +70 -2
  7. package/docs/VISION.md +33 -12
  8. package/hooks/scripts/prompt-context.py +7 -1
  9. package/hooks/scripts/test_prompt_context.py +16 -0
  10. package/package.json +1 -1
  11. package/scripts/tests/convert-content-integrity.test.sh +4 -4
  12. package/scripts/tests/convert-review-weight.test.sh +61 -0
  13. package/scripts/work-view.sh +1 -1
  14. package/skills/autopilot/SKILL.md +138 -91
  15. package/skills/convert/SKILL.md +55 -11
  16. package/skills/epic-design/SKILL.md +37 -70
  17. package/skills/feature-design/SKILL.md +52 -68
  18. package/skills/fix/SKILL.md +52 -34
  19. package/skills/gate-cruft/SKILL.md +69 -24
  20. package/skills/gate-docs/SKILL.md +12 -5
  21. package/skills/gate-patterns/SKILL.md +7 -3
  22. package/skills/gate-refactor/SKILL.md +18 -6
  23. package/skills/gate-security/SKILL.md +16 -7
  24. package/skills/gate-tests/SKILL.md +86 -71
  25. package/skills/implement/SKILL.md +79 -58
  26. package/skills/implement-orchestrator/SKILL.md +274 -587
  27. package/skills/perf-design/SKILL.md +11 -12
  28. package/skills/principles/SKILL.md +175 -379
  29. package/skills/principles/references/advisory-review.md +76 -0
  30. package/skills/principles/references/code-design.md +164 -0
  31. package/skills/principles/references/models.md +42 -63
  32. package/skills/prose-author/SKILL.md +9 -4
  33. package/skills/refactor-design/SKILL.md +26 -17
  34. package/skills/review/SKILL.md +169 -64
  35. package/skills/review/references/substrate-side-effects.md +17 -10
  36. package/skills/scope/SKILL.md +20 -7
  37. package/work-view/crates/cli/.work-view-version +1 -1
  38. package/work-view/dist/aarch64-apple-darwin/work-view +0 -0
  39. package/work-view/dist/aarch64-unknown-linux-musl/work-view +0 -0
  40. package/work-view/dist/x86_64-apple-darwin/work-view +0 -0
  41. package/work-view/dist/x86_64-unknown-linux-musl/work-view +0 -0
@@ -2,603 +2,290 @@
2
2
  name: implement-orchestrator
3
3
  description: >
4
4
  ALWAYS invoke when the user asks to implement substrate items, work through stage:implementing
5
- items, drain the queue, or implement a feature/epic scope. Default implementation path; call
6
- implement directly only when the user says "inline". Builds a depends_on graph, bundles related
7
- work, chooses wave width and worktree isolation, and dispatches implementation sub-agents when
8
- useful. This skill authorizes sub-agents, including large non-overlapping write paths when ownership
9
- and verification make that safe. Advances parents whose children all reach stage:review.
5
+ items, drain the queue, or implement a feature or epic scope. Coordinates implementation from the
6
+ unified dependency graph, derives worker ownership and execution waves from repository shape and
7
+ risk, verifies every wave, rolls eligible parents to review, and continues through the review lane
8
+ by default. Use implement instead when one cohesive delivery is safer to keep in the host context.
10
9
  ---
11
10
 
12
11
  # Implement-Orchestrator
13
12
 
14
- You orchestrate the implementation of one or more substrate items at
15
- `stage: implementing`. Your value is in the prompt crafting and the
16
- dependency-aware scheduling across whatever scope you've been given
17
- not in writing line-by-line code yourself. You delegate the writing to
18
- implementation sub-agents when the work can be split productively. You determine
19
- how to parallelize: bundles, waves, worker ownership, worktree isolation, and
20
- serialization are your call.
21
-
22
- ## Sub-agent contract
23
-
24
- Invocation of this skill is explicit authorization to spawn implementation
25
- sub-agents. Do not wait for the user to separately say "use sub-agents" once this
26
- skill is active. The user has chosen the orchestrator because the orchestrator is
27
- the parallelization brain.
28
-
29
- Authorization is not a mandate to fan out before sizing the system. Do a
30
- read-first scope probe before choosing exploratory sub-agents, bundle shape, wave width,
31
- or worktree isolation. Direct reading is often faster and more accurate when the
32
- work points at a known module, a small file set, or a few obvious integration
33
- points.
34
-
35
- Use sub-agents as the primary scaling mechanism when the work has separable
36
- ownership. Large write paths may still run in parallel when you assign explicit
37
- file/module ownership, tell workers they are not alone in the codebase, use
38
- worktree isolation when overlap or merge risk warrants it, and verify integration
39
- after each wave. Serialize only the portions whose write sets or dependency
40
- edges make parallel work unsafe.
41
-
42
- ### Implementation tier (settle once, before dispatch)
43
-
44
- The worker subagent posture and effort tier are a **dial**, not a silent
45
- default. Agile-workflow does not ship an implementation role; each worker is a
46
- generic subagent prompted with the implementer capsule from
47
- `../principles/references/subagents.md`. Before spawning the first wave,
48
- determine the implementation tier:
49
-
50
- 1. **Honor an explicit choice** — a tier named in the goal/args/user request,
51
- an autopilot caller note, or a stable project convention (e.g. a
52
- `.work/CONVENTIONS.md` model note), wins. Use it and skip the question.
53
- 2. **Autopilot mode is non-interactive** — when delegated by an active
54
- autopilot run, use the tier autopilot settled for the scoped run. If the
55
- caller note is missing the tier, fall back to the host runtime's
56
- medium/default **baseline** worker capability and state the fallback in the
57
- run notes. Do not ask the user from inside an autopilot-driven implementation
58
- pass.
59
- 3. **All other modes ask once** — when there is no explicit/project/autopilot
60
- choice, ask the user what implementation effort tier to use (structured
61
- question tool when available), then lock it for the whole run; never re-ask
62
- per wave. Pick a **baseline**, **raised**, or **highest** tier
63
- by capability, not by name — concrete model resolution per host is in
64
- [../principles/references/models.md](../principles/references/models.md):
65
- - **Baseline** = write fidelity at low cost: routine, well-scoped code.
66
- - **Raised** = deeper reasoning/stamina for multi-item, cross-module, or
67
- orchestration-critical bundles.
68
- - **Highest** = the strongest reasoning available for large cross-feature
69
- write paths, risky migrations, or repeated failed attempts.
70
- The vocabulary matches `deep-code-scan`'s scanner-tier dial so the two read
71
- alike.
72
-
73
- Use explicit runtime paths: spawn implementation workers through the host's
74
- generic/code-writing subagent mechanism, with the settled effort tier and the
75
- implementer prompt posture from `../principles/references/subagents.md`. Map
76
- routine small/single-item bundles to the settled baseline, raise effort within
77
- the same model family for multi-item, cross-module, or orchestration-critical
78
- bundles, and reserve the highest tier for large cross-feature write paths,
79
- risky migrations, difficult generated-code reconciliation, or repeated failed
80
- attempts. Use read-only exploratory subagents prompted with the explorer capsule
81
- at medium/high reasoning for mapping. Do not use peeragent for routine
82
- implementation-worker fanout.
83
-
84
- In every runtime, make each worker prompt self-contained and require one commit
85
- per item.
86
-
87
- ## Trigger
88
-
89
- This is the **default implementation path** for everything at
90
- `stage: implementing` — features (with or without children), lone stories, or
91
- mixed batches across multiple features. Even a single ready story routes here
92
- by default; the one-agent wave is still worth running because the grounding,
93
- the prompt, and the post-wave verification all add value the inline `implement`
94
- skill skips.
95
-
96
- Reach for `/agile-workflow:implement` directly only when the delivery is **very
97
- small** (the criteria are spelled out in that skill's trigger section: ≤ 2
98
- files, ~≤ 50 LoC, single unit of work, no `depends_on` coordination, or land
99
- mode). When in doubt, route here.
100
-
101
- Common phrases:
102
- - "implement feature X" / "implement story Y"
103
- - "implement everything ready under epic Z"
104
- - "fan out the implementing band"
105
- - "drain the ready stories"
13
+ Coordinate one or more substrate items from `stage: implementing` through their
14
+ appropriate review outcome. Derive the execution topology from the work in front
15
+ of you rather than applying fixed bundle sizes, wave widths, or worker recipes.
16
+
17
+ The orchestrator adds value through complete grounding, dependency-aware
18
+ scheduling, explicit write ownership, fresh worker context, integration
19
+ verification, and conservative lifecycle roll-up. Delegation is authorized when
20
+ this skill is active, but it is useful only where separate ownership, isolation,
21
+ or parallel execution improves the result.
22
+
23
+ ## Outcomes
24
+
25
+ A successful run leaves:
26
+
27
+ - every selected item either advanced through review to `done`, explicitly left
28
+ at `review` by a `stop-at-review` request, bounced with durable review
29
+ findings, or documented with a blocker;
30
+ - every implementation transition backed by passing verification;
31
+ - every changed item represented by its own commit;
32
+ - eligible parent features advanced from `implementing` to `review` only after
33
+ all their children are terminal-or-review;
34
+ - run notes that explain scope resolution, execution topology, worker
35
+ capability, effective review weight, verification, and deviations.
36
+
37
+ Reaching `review` is not the default handoff boundary. Invoke the review skill
38
+ for the advanced scope in the same run, passing the effective `review_weight`,
39
+ unless the caller says `stop at review`, `leave at review`, `hand off for
40
+ review`, or a stable project convention sets that boundary. Review owns
41
+ approval, bounce handling, and the `review → done` ancestor roll-up. Do not
42
+ replace that lane with inline self-approval.
106
43
 
107
44
  ## Scope arguments
108
45
 
109
- Accept any of:
110
-
111
- - no arg equivalent to `--all` (the default)
112
- - `--all` every implementing item in `.work/active/` (regardless of parent)
113
- - `<feature-id>` — every child story of that feature at `stage: implementing`,
114
- plus the feature itself if it has no children
115
- - `<epic-id>` every implementing item transitively under that epic
116
- - `<id> [<id>...]` explicit list, can mix kinds and parents
117
- - single `<story-id>` with no parent or whose parent isn't in scope — run as a
118
- one-agent wave, advance only that story
119
- - `<NL filter>` (e.g. "the auth stories", "everything tagged refactor") — same
120
- shape as autopilot's free-text scope: interpret against the implementing-band
121
- items, log the interpretation in the run summary
122
-
123
- Disambiguation: an arg is treated as an id only if a matching file exists in
124
- `.work/active/`. Otherwise it's an NL filter. Whatever you accept, the rest of
125
- the workflow is the same the difference is just which items populate the
126
- queue at Phase 1.
46
+ Accept the orchestration argument shapes defined in `principles` Part V:
47
+
48
+ - no argument or `--all` selects the full implementing queue;
49
+ - a feature id selects its implementing children, or the feature itself when it
50
+ has no children;
51
+ - an epic id selects implementing descendants transitively;
52
+ - an id list selects those items across kinds and parents;
53
+ - a lone story id selects that story without implicitly advancing its parent;
54
+ - a natural-language filter is interpreted against implementing items and its
55
+ interpretation is recorded.
56
+
57
+ Treat a value as an id only when a matching active item exists. Treat
58
+ `stop-at-review` as a lifecycle modifier, not part of the item filter.
59
+
60
+ ## Invariants
61
+
62
+ These constraints govern every topology the orchestrator derives.
63
+
64
+ ### Grounding and freshness
65
+
66
+ - Read every selected item and every distinct parent feature in full before
67
+ dispatch. Cross-feature scope increases the grounding obligation.
68
+ - Read referenced foundation and research documents, project instructions,
69
+ `.agents/rules/*.md`, and the concrete code and tests that define each
70
+ integration boundary.
71
+ - Probe locally with `work-view`, file listing, search, and direct reads before
72
+ using exploratory sub-agents. Delegate exploration only for named unknowns or
73
+ independent surfaces that local probes do not resolve.
74
+ - Re-read project instructions, force-loaded rules, and relevant pattern
75
+ sources immediately before dispatch. Re-check the working tree and item
76
+ stages before each wave; concurrent work may have changed assumptions.
77
+ - Record the dispatch rationale when it affects ownership, grouping, isolation,
78
+ or concurrency.
79
+
80
+ ### Dependency integrity
81
+
82
+ - Build one unified `depends_on` graph for the selected work. Parent boundaries
83
+ do not partition scheduling, and cross-feature dependencies are valid.
84
+ - Validate that every dependency id exists and that the graph is acyclic before
85
+ dispatch.
86
+ - An item is ready only when every dependency is terminal-done or was completed
87
+ and verified by an earlier wave.
88
+ - If a dependency outside the selected scope is not terminal, drop the dependent
89
+ item from this run and record the unmet dependency. Never bypass or silently
90
+ rewrite the edge.
91
+ - Recompute readiness after each verified wave rather than relying on the
92
+ initial graph snapshot.
93
+
94
+ ### Ownership and concurrency
95
+
96
+ - Derive worker groupings and waves from dependency layers, write sets,
97
+ repository shape, coupling, uncertainty, runtime capacity, and verification
98
+ cost. Item count alone does not determine parallelism.
99
+ - Parallel workers must have independent write sets and explicit ownership.
100
+ Serialize or combine work when write sets overlap or when coherence matters
101
+ more than isolation.
102
+ - Use worktree isolation when overlap is hard to predict or when large,
103
+ disjoint write paths are safer to reconcile independently.
104
+ - Tell every worker that other agents may be editing disjoint files. Workers
105
+ must preserve unrelated changes and stop rather than expanding their write
106
+ scope silently.
107
+ - Dependency ordering is never weakened by grouping. A worker may process
108
+ related items sequentially only when each item becomes ready in that order.
109
+
110
+ ### Verification and commits
111
+
112
+ - Verify each item within its worker scope and verify the integrated repository
113
+ after every wave using the project's authoritative checks.
114
+ - Do not dispatch the next wave until the current wave's item transitions,
115
+ commits, and integration checks are verified.
116
+ - Keep one commit per item, including separate commits for parent stage
117
+ transitions. Never batch multiple item transitions into one commit and never
118
+ push.
119
+ - A partial wave is valid only when completed items remain independently
120
+ verified and committed; preserve untouched items at their current stage and
121
+ durably record every bounce or blocker.
122
+ - Treat test gaming as a blocking verification failure, not a successful wave.
123
+
124
+ ### Conservative parent roll-up
125
+
126
+ After verified children reach `review` or a terminal stage, inspect every
127
+ parent feature touched by the run. Advance a parent from `implementing` to
128
+ `review` only when all of its children, including children outside the selected
129
+ scope, are terminal-or-review. Append an implementation summary and
130
+ verification result, then commit that parent transition as its own item commit.
131
+ Leave an ineligible parent unchanged.
132
+
133
+ The subsequent review lane decides whether reviewed items and ancestors reach
134
+ `done`; do not duplicate or pre-empt review's roll-up contract here.
135
+
136
+ ## Worker capability
137
+
138
+ Choose worker capability from the risk and scope of the owned delivery. Consider
139
+ reasoning depth, cross-module impact, migration or generated-contract risk,
140
+ uncertainty, and prior failed attempts. Honor an explicit capability or model
141
+ choice from the caller, an autopilot caller note, or a stable project convention
142
+ when present; otherwise make the choice yourself. Record the chosen capability
143
+ and rationale in run notes before dispatch, and do not ask a routine tier
144
+ question or re-ask between waves.
145
+
146
+ Use the host's generic code-writing sub-agent mechanism. Do not use peeragent
147
+ for routine implementation fan-out. If no suitable worker adapter exists, keep
148
+ cohesive work in the host session while preserving the same ownership,
149
+ verification, item-update, and commit contracts.
150
+
151
+ ## Effective review weight
152
+
153
+ Determine or receive one effective `review_weight` for the proactive review
154
+ handoff. Precedence is: explicit caller or autopilot override, then stable
155
+ project convention, then `standard`. Record the effective value and its source
156
+ in run notes and pass it to the review invocation. The principles and review
157
+ skill own the meaning and execution of each weight; do not recreate their
158
+ selection matrix here. A weight of `none` still requires green implementation
159
+ verification, then uses the review lane without an independent review pass.
160
+
161
+ ## Worker self-containment
162
+
163
+ Craft each worker brief dynamically from the implementer posture in
164
+ [principles/references/subagents.md](../principles/references/subagents.md).
165
+ Do not assume an installed agile-workflow worker role, shared conversation
166
+ context, or fixed prompt wording. The brief must carry all information required
167
+ to execute safely:
168
+
169
+ - the owned item ids, exact allowed write scope, forbidden scope, parent design
170
+ context, acceptance criteria, relevant paths, verified patterns, and current
171
+ repository discrepancies;
172
+ - dependency readiness and the instruction to return without advancing when a
173
+ dependency is unmet;
174
+ - land-mode detection: inspect whether the implementation already exists,
175
+ reconcile the item body to as-built reality, fill meaningful test gaps, and
176
+ verify before advancing;
177
+ - the design-flaw escape hatch: record an `## Implementation discovery`, move
178
+ the affected item back to `drafting`, and return rather than forcing a flawed
179
+ design through;
180
+ - project verification commands, required implementation notes, the
181
+ `implementing → review` transition, and exactly one `implement: <item-id>`
182
+ commit per completed item with no push;
183
+ - endpoint boundaries: no nested delegation or peeragent, no silent scope
184
+ expansion, preserve unrelated concurrent changes, and report blockers;
185
+ - the full test-integrity rule: repair stale fixtures, drifted assertions,
186
+ broken mocks, and outdated snapshots; park real production bugs and
187
+ pre-existing flakes instead of folding them into the item; never weaken,
188
+ delete, broadly skip, or rewrite a test merely to obtain green output; when a
189
+ known bug prevents green verification, document the failure honestly and link
190
+ the parked work rather than asserting whatever the code returns;
191
+ - emotional framing that invites pride in craft, careful verification, and
192
+ candid blocker reporting without pressure or threat language.
193
+
194
+ Reference paths and signatures rather than pasting whole source files, but
195
+ include enough parent and item intent that the worker does not need the
196
+ orchestrator's private context. For a worker owning multiple sequential items,
197
+ retain separate readiness checks, notes, transitions, verification, and commits
198
+ for each item.
127
199
 
128
200
  ## Workflow
129
201
 
130
- ### Phase 1: Resolve scope and ground yourself
131
-
132
- First, resolve the scope arg into a concrete **work set** the items you'll
133
- actually drive in this run. Use `work-view` with the appropriate filters; the
134
- exact invocation depends on what you were given:
135
-
136
- - A feature id its child stories at `stage: implementing`, plus the feature
137
- itself if it has no children
138
- - An epic id walk the parent chain to gather every implementing item beneath
139
- it (features without children, plus all stories)
140
- - `--all` (or no arg) → every item under `.work/active/` at `stage: implementing`
141
- - An explicit id list use those items directly
142
- - An NL filter → interpret against the implementing-band items, keep matches,
143
- log the interpretation
144
-
145
- Note the **set of distinct parent features** that appear in the work set. Some
146
- items may share a parent, others may not. You'll need each distinct parent for
147
- the grounding step and for Phase 9 advancement.
148
-
149
- Then read deeply the quality of your agent prompts depends on this.
150
-
151
- 1. **Every parent feature** in the work set full design, all units, all
152
- referenced patterns. Read each one fully; do not skim. If the work set
153
- spans multiple features, that's more reading, not less.
154
- 2. **Every item in the work set** — the story or childless feature you'll
155
- spawn an agent for. Read its body, design, acceptance criteria, and
156
- `depends_on`.
157
- 3. **Foundation docs** referenced by any of the above: `docs/SPEC.md`,
158
- `docs/ARCHITECTURE.md`
159
- 4. **Principles** both paradigms via the auto-loaded principles skill
160
- 5. **AGENTS.md / CLAUDE.md** project conventions, build commands
161
- 5a. **`.agents/rules/*.md`** (if present) the project's force-loaded agent
162
- rules (tag semantics, test integrity, review policy)
163
- 6. **Concrete pattern examples** in the codebase — for each type of code the
164
- agents will write, find an existing example. Read 3-5 key files yourself.
165
- Use exploratory sub-agents only for breadth you can name after local search.
166
- 7. **Discrepancies between design and repo reality** — for every file the
167
- designs reference, confirm interfaces match. Note discrepancies for
168
- inclusion in agent prompts.
169
-
170
- ### Phase 1.5: Size the system before delegation
171
-
172
- Apply the Agent Dispatch Economy principle from `principles/SKILL.md` before
173
- spawning discovery or implementation agents. Build a quick sizing note:
174
-
175
- - likely write roots and known files
176
- - item count, expected edit size, and dependency layers
177
- - unknowns that require discovery
178
- - whether the scope is direct-read, one-Explore, or parallel-Explore sized
179
-
180
- If the work set points at a handful of known files, read them directly and skip
181
- Explore. If one bounded area remains fuzzy, use one focused exploratory sub-agent. If
182
- several independent surfaces remain unknown, use parallel exploratory sub-agents with
183
- different questions. Feed this sizing decision into bundling and wave width; do
184
- not default to a wide wave because many items are present.
185
-
186
- ### Phase 2: Build the dependency graph
187
-
188
- For every item in the work set, parse its `depends_on` field. Build a unified
189
- map across the whole scope dependencies do not need to share a parent:
190
-
191
- - `item-id → list of dep ids it waits on`
192
- - `dep id → list of items that wait on it`
193
-
194
- A story under feature A may legitimately depend on a story under feature B.
195
- The graph treats the work set as a flat pool; parents are bookkeeping for
196
- Phase 9, not partitions of the schedule.
197
-
198
- Validate:
199
- - All `depends_on` entries refer to existing items
200
- - No cycles (`work-view --blocking` per id)
201
- - Cross-scope deps (an item whose `depends_on` points outside the work set)
202
- must already be at `stage: done` or terminal — if not, drop the dependent
203
- item from this run and log it; you can't satisfy that dep here.
204
-
205
- ### Phase 3: Bundle, schedule, and check for conflicts
206
-
207
- #### 3a — Detect bundles
208
-
209
- Default to **one implementation sub-agent per item**, but bundle tightly-coupled
210
- small items into a single sub-agent when doing so produces better code than
211
- parallel agents fighting the same module. A bundle is a group of items owned by
212
- one implementation sub-agent that
213
- walks them sequentially, sharing context across all of them.
214
-
215
- Bundle a group of items together when **all** of these hold:
216
-
217
- - **Adjacent scope.** They touch the same subdirectory, the same module family,
218
- or files that import each other heavily. "I'd refactor these together if I
219
- were holding the whole thing in my head" is the test.
220
- - **Individually small.** Each item is roughly under ~200 LoC of net new/changed
221
- code, judged from its design. Big items belong in their own agent — they
222
- already saturate one agent's attention.
223
- - **Shared patterns / conventions / dependencies.** They follow the same idioms,
224
- import the same modules, or depend on each other in ways that benefit from
225
- the agent having loaded the full context once.
226
- - **Same dependency layer.** Every bundle member must be eligible for the same
227
- wave — i.e. an item cannot be bundled with one of its own (transitive)
228
- dependencies. Two items that depend on the same upstream are fine; a
229
- parent-child dep pair is not.
230
- - **Fits one sub-agent's context budget.** Keep each bundle small enough that
231
- the worker can load its prompt, designs, relevant code, and verification
232
- output without losing precision. In practice that's roughly 3–8 small items
233
- per bundle. When in doubt, bundle smaller.
234
-
235
- A single-item "bundle" is the common case and is fine. Don't force bundling.
236
- The win is reserved for clusters where the coordination overhead between
237
- parallel agents (file overlap, convention drift, repeated grounding) would
238
- exceed the cost of sequencing them inside one head.
239
-
240
- For each candidate bundle, record:
241
-
242
- - `bundle-id` (synthetic, e.g. `B1`, `B2`)
243
- - ordered item list (dependency order if intra-bundle deps exist)
244
- - shared scope description (e.g. "auth middleware family — `src/auth/*.ts`")
245
- - rationale (1 sentence on why these belong together)
246
-
247
- Log every bundling decision in your run notes; surface them in the final
248
- output so the user can audit the call.
249
-
250
- #### 3b — Topological wave plan over bundles
251
-
252
- Treat each bundle (single-item or multi-item) as one schedulable unit. Build
253
- the wave plan from the unified `depends_on` graph, lifted to the bundle level:
254
- bundle A depends on bundle B if any item in A depends on any item in B.
255
-
256
- - **Wave 1** (parallel): all bundles whose every external dependency is at
257
- `stage: done` (or terminal in releases/archive)
258
- - **Wave 2** (parallel): bundles whose dependencies are wave-1 bundles
259
- - **Wave N** (parallel): bundles whose dependencies are wave-(N-1) bundles
260
-
261
- Choose parallelism per wave based on write-set independence, dependency edges,
262
- runtime capacity, and verification cost. Three bundles per wave is the safe
263
- default for ordinary mixed implementation work. You may raise that for clearly
264
- disjoint write paths or large independent subsystems, especially with worktree
265
- isolation. You should lower it or serialize when bundles touch the same files,
266
- share fragile generated artifacts, or require ordered API/type evolution.
267
-
268
- #### 3c — File-overlap conflict check (cross-bundle)
269
-
270
- Within-bundle file overlap is already resolved — one agent owns the bundle, so
271
- "overlap" inside it is just sequential edits. Check for overlap **across
272
- bundles in the same wave**. If two bundles in one wave name overlapping files,
273
- choose one of three mitigations:
274
-
275
- - **Merge the bundles** — if they're small enough to fit one agent's budget
276
- and the overlap is the reason they should be together, collapse them into
277
- one bundle. Often the cleanest answer.
278
- - **Serialize the conflicting bundles** — pull one into a later sub-wave so
279
- they don't share a slot. Preferred when merging would blow the budget.
280
- - **Spawn the wave with worktree isolation** — each agent gets its own
281
- worktree, you reconcile after. Use when serialization would balloon the
282
- wave count or when you can't predict overlap precisely.
283
-
284
- Cross-feature bundles make this check important — siblings under one feature
285
- usually had disjoint files by design; bundles drawn from different features
286
- have no such guarantee.
287
-
288
- ### Phase 4: Re-align to project standards
289
-
290
- Re-read `AGENTS.md` and `CLAUDE.md` if both exist. Treat `AGENTS.md` as
291
- canonical when they disagree; `CLAUDE.md` is usually a symlink or compatibility
292
- shim. Also read `.agents/rules/*.md` (if present) — the project's force-loaded
293
- agent rules (tag semantics, test integrity, review policy) — and
294
- `.agents/skills/patterns/` and legacy `.claude/skills/patterns/` if present.
295
- Recency improves prompt adherence.
296
-
297
- ### Phase 5: Craft agent prompts
298
-
299
- The per-bundle prompt mirrors `/agile-workflow:implement`'s workflow — same
300
- phases, same logic — just inlined so a sub-agent can execute it self-contained.
301
- Whatever capabilities `implement` gains over time should be reflected here too.
302
-
303
- There are two prompt shapes depending on bundle size:
304
-
305
- - **Single-item bundle** (1 item): the classic per-story prompt described below.
306
- - **Multi-item bundle** (2+ items): a per-bundle prompt that walks each item in
307
- dependency order, sharing context across all items. See "Multi-item bundle
308
- prompts" subsection at the end.
309
-
310
- For each **single-item** bundle, write a self-contained prompt with:
311
-
312
- 1. **Role and goal** — one sentence with ownership framing: "You are
313
- implementing <story-name> for feature <feature-name> — write
314
- production-quality code that you'd be proud to have reviewed."
315
-
316
- 2. **Land-mode check** (from implement Phase 4a) — "Before writing new code,
317
- check if the implementation already exists in the working tree. Signals: a
318
- 'Files in this cluster' list in the story body, retroactive-capture note,
319
- sparse design with concrete file paths matching `git status`. If you're
320
- in land mode: read the existing code, update the story body's design
321
- section to reflect as-built reality, validate (typecheck/lint/test scoped
322
- to touched packages), add tests for any meaningful behavior that lacks
323
- them, log 'Land mode' in implementation notes, then proceed to commit."
324
-
325
- 3. **Dep readiness check** (from implement Phase 2) — "If this story has
326
- non-empty `depends_on`, verify each dep is at `stage: done` (or in
327
- releases/archive). If any dep is unmet, append a one-line note and return
328
- without advancing — don't try to implement on top of unmet deps."
329
-
330
- 4. **Story file content** — paste the story body verbatim. Tell the agent:
331
- "Update this file with implementation notes when done."
332
-
333
- 5. **Parent feature design excerpt** — paste the relevant implementation units
334
- from the item's parent feature body. Don't summarize — exact specs matter.
335
- When the work set spans multiple features, each agent gets only the
336
- excerpt that belongs to its item's parent (don't dump unrelated features'
337
- designs into the prompt).
338
-
339
- 6. **Codebase context** — concrete:
340
- - Key file paths it will read or modify (specific, not generic)
341
- - Existing patterns to follow with concrete codebase examples
342
- - Discrepancies between design and repo reality you found
343
- - Specific imports needed
344
- - Project conventions from AGENTS.md / CLAUDE.md
345
-
346
- 7. **Design-flaw escape hatch** (from implement guardrails) — "If during
347
- implementation you discover a genuine design flaw, don't muscle through.
348
- Update the story body with a `## Implementation discovery` section, set
349
- stage back to `drafting`, and return. The orchestrator will route the
350
- story back through the design family on the next pass."
351
-
352
- 8. **Stage transition instruction** — "When done, update the story's
353
- frontmatter `stage: implementing → review` and append implementation notes.
354
- The PostToolUse hook auto-bumps `updated:`."
355
-
356
- 9. **Verification commands** — from AGENTS.md / CLAUDE.md (e.g.,
357
- `pnpm typecheck && pnpm lint && pnpm test`).
358
-
359
- 10. **Commit instruction** — "After build and tests pass, commit with message
360
- `implement: <story-id>`. Do NOT push."
361
-
362
- 11. **Test integrity** — "When tests fail during verification: fix bad
363
- tests (stale fixtures, drifted assertions, broken mocks) in-session.
364
- Park real production bugs via `/agile-workflow:park` instead of
365
- silently fixing mid-pass. Park pre-existing flakes too — don't bundle.
366
- NEVER game a test to make it pass. A failing test that documents *why*
367
- it fails (inline comment naming the bug, `skip` linked to a backlog
368
- id, `xfail` with reason) is more honest than a green test that lies.
369
- No `expect(true).toBe(true)`, no asserting on whatever the code
370
- happens to return, no deleting a test as 'flaky' without root-causing
371
- first."
372
-
373
- 12. **Emotional framing** — pride in craft, permission to report blockers,
374
- quality as aspiration not threat. Avoid pressure language.
375
-
376
- #### Multi-item bundle prompts
377
-
378
- For a **multi-item bundle**, write one self-contained prompt covering every
379
- item in the bundle. The agent loads the shared context once and walks the
380
- items sequentially, gaining coherence the parallel-agents alternative loses.
381
- Structure the prompt as:
382
-
383
- 1. **Bundle role and goal** — "You own a tightly-coupled cluster of N items
384
- in <shared-scope>. Treat them as one coherent delivery — you'll walk them
385
- in order, but the design intent crosses items. Aim for production-quality
386
- code you'd be proud to have reviewed."
387
-
388
- 2. **Shared context block** (loaded once for all items):
389
- - Why these items are bundled (the rationale from Phase 3a)
390
- - Parent-feature design excerpts relevant to the bundle (paste verbatim,
391
- deduped — don't repeat the same excerpt per item)
392
- - Shared codebase context: the file paths the bundle will touch, the
393
- patterns and conventions shared across items, the imports and module
394
- boundaries common to the cluster
395
- - Discrepancies between design and repo reality you found that apply to
396
- the bundle as a whole
397
-
398
- 3. **Land-mode check** (shared) — same logic as single-item, applied per item
399
- as the agent reaches it.
400
-
401
- 4. **Per-item working list** — in dependency order, for each item:
402
- - Item id and name, with a one-line goal
403
- - Story body content verbatim
404
- - Item-specific design excerpt (only the parts of parent-feature design
405
- not already covered by the shared block)
406
- - Item-specific files and conventions only-this-item touches
407
- - Item-specific `depends_on` and the readiness check for it
408
-
409
- 5. **Per-item execution loop** — "For each item in order: (a) verify
410
- `depends_on` is satisfied; (b) implement; (c) run scoped verification;
411
- (d) update the item file's body with implementation notes and advance
412
- `stage: implementing → review`; (e) commit with message
413
- `implement: <item-id>`; (f) move to the next item. Do NOT batch commits
414
- across items — one commit per item keeps the substrate clean and lets
415
- review roll back items independently."
416
-
417
- 6. **Bundle-final verification** — "After the last item is committed, run
418
- the full project verification commands (typecheck, lint, full test suite)
419
- once for the whole bundle. If anything fails, fix it — the fix is part of
420
- the bundle's delivery, not a follow-up."
421
-
422
- 7. **Design-flaw escape hatch (per item)** — "If during implementation of
423
- any item you discover a genuine design flaw in that item, do NOT muscle
424
- through. Update that item's body with a `## Implementation discovery`
425
- section, set its stage back to `drafting`, commit the items already
426
- completed, and return. The orchestrator will route the flawed item back
427
- through the design family on the next pass. The completed items remain
428
- at `stage: review`."
429
-
430
- 8. **Test integrity** — same wording as single-item; reinforce that bundle
431
- scope is NOT a license to silence tests across items.
432
-
433
- 9. **Emotional framing** — "Holding the whole cluster in your head is the
434
- point of this bundle — that's what produces coherent code. Take your time
435
- per item; the bundle isn't a race."
436
-
437
- The bundle prompt is longer than a single-item prompt, but the agent reads
438
- the shared context once and amortizes it across every item — that's the
439
- budget win the bundle is buying.
440
-
441
- ### Phase 6: Spawn sub-agents (per wave)
442
-
443
- Spawn one implementation sub-agent per bundle, regardless of bundle size.
444
-
445
- Spawn code-writing worker subagents through the host's generic/general-purpose
446
- subagent mechanism, prompted with the implementer capsule and the settled effort
447
- tier from the kickoff decision:
448
- - baseline / host medium-default for small or single-item bundles
449
- - raised / host high-effort for multi-item, cross-module, or orchestration-critical
450
- bundles when the settled choice allows escalation
451
- - highest / host maximum-effort only for large cross-feature write paths, deep
452
- migrations, high-risk reconciliation, or repeated failed attempts, and only
453
- when selected explicitly or permitted by the settled tier
454
- - no model override outside the settled family/tier unless the user has named
455
- one or the project has a stable model convention
456
-
457
- Use the deployment's existing `Explore` role for read-only mapping only when it
458
- is already available; agile-workflow does not ship an Explore override or any
459
- implementation/review roles. If no suitable generic subagent adapter exists,
460
- keep the bounded work in the host session or use the fresh-context fallback
461
- already described by the skill.
462
-
463
- For waves with multiple bundles, send all in a **single message** with multiple
464
- sub-agent calls when the runtime supports parallel execution.
465
-
466
- The `description` should make the bundle scope visible — e.g.
467
- `"Implement B2: 4 stories under auth middleware"` for a multi-item bundle, or
468
- `"Implement story S-12"` for a single-item bundle.
469
-
470
- Use worktree isolation if multiple bundles in the same wave will modify
471
- overlapping files and you chose not to merge them (see Phase 3c), or if large
472
- independent write paths are safer to reconcile from separate worktrees. Within a
473
- bundle, isolation is unnecessary — one sub-agent owns the whole cluster.
474
-
475
- ### Phase 7: Review wave results
476
-
477
- After each wave:
478
- 1. Read each agent's result summary
479
- 2. For each bundle: verify the agent advanced **every** item in the bundle to
480
- `stage: review` (or back to `drafting` if a design-flaw escape hatch
481
- fired), and wrote implementation notes on each item's body
482
- 3. Verify the agent committed once per item (multi-item bundles produce N
483
- commits, not 1)
484
- 4. Run the verification commands yourself to confirm integration is clean
485
- across all bundles in the wave
486
-
487
- If a bundle agent fully completed only some of its items and bailed (e.g. a
488
- design-flaw escape hatch fired on item 3 of 5), accept the partial result:
489
- items 1–2 stay at `review`, item 3 is back at `drafting`, items 4–5 stay at
490
- `implementing` and will be picked up next pass.
491
-
492
- If an agent reported a blocker or left gaps:
493
- - Small fix → make it yourself directly
494
- - Larger issue → spawn a focused follow-up agent with a targeted prompt
495
-
496
- Don't proceed to the next wave if the previous wave's results aren't verified.
497
-
498
- ### Phase 8: Iterate waves until done
499
-
500
- Continue spawning waves until every item in the work set is at `stage: review`
501
- (or `done` if review-skipping for trivial ones, but generally items advance
502
- to `review` only).
503
-
504
- ### Phase 9: Advance every parent feature whose children are now all at review
505
-
506
- For each distinct parent feature you noted during Phase 1, check whether every
507
- one of its child stories is now at `stage: review` or `done`. A parent
508
- qualifies for advancement when **all** of its children are terminal-or-review,
509
- not just the subset you happened to touch in this run — children outside your
510
- work set must also already be at one of those stages.
511
-
512
- For each qualifying parent feature:
513
-
514
- 1. Append a summary to its body:
515
- - Stories implemented in this run (list with their statuses)
516
- - Any cross-cutting deviations
517
- - Verification status (build + tests pass)
518
- 2. Advance its frontmatter: `stage: implementing → review`. The PostToolUse
519
- hook bumps `updated:`.
520
- 3. Commit it:
521
- ```bash
522
- git add .work/active/features/<id>.md
523
- git commit -m "implement: <feature-id> (<N> stories ready for review)"
524
- ```
525
-
526
- If a parent has children outside the work set still at `stage: implementing`,
527
- leave its stage at `implementing` — a later orchestrator run (or autopilot
528
- pass) will pick those up and advance the parent then. Don't force-advance a
529
- parent whose work isn't complete.
530
-
531
- For items in the work set that have no parent feature (lone stories,
532
- parentless items), there's nothing to advance at this phase — the items
533
- themselves already moved to `stage: review` via their agents.
202
+ ### 1. Resolve and ground the work set
203
+
204
+ Resolve the argument to concrete active items and note distinct parent features.
205
+ Read the full item and parent bodies, referenced docs, project rules, and current
206
+ integration code. Confirm the designs still match repository reality.
207
+
208
+ Create a concise sizing note covering likely write roots, dependency layers,
209
+ known coupling, risk, remaining unknowns, and whether direct reading or focused
210
+ exploration is justified. This is evidence for the topology, not a numerical
211
+ recipe.
212
+
213
+ ### 2. Build and validate the graph
214
+
215
+ Construct the unified dependency graph, validate ids and cycles, classify
216
+ external dependencies, and remove dependents whose external prerequisites are
217
+ not terminal. Record every exclusion. Compute the currently ready layer.
218
+
219
+ ### 3. Derive ownership and waves
220
+
221
+ For the ready layer, assign coherent write ownership and identify conflicts.
222
+ Choose serialization, shared sequential ownership, direct-host execution, or
223
+ isolated parallel workers according to the invariants above. Select and record
224
+ worker capability. Refresh rules, stages, and working-tree state before sending
225
+ self-contained briefs.
226
+
227
+ ### 4. Execute and verify a wave
228
+
229
+ Dispatch only ready work. On return:
230
+
231
+ 1. inspect each result and the actual diff;
232
+ 2. confirm every completed item contains implementation notes and reached
233
+ `review`, or that a design flaw, bounce, or blocker is durably recorded;
234
+ 3. confirm exactly one commit exists for each completed item and that it does
235
+ not include unrelated ownership;
236
+ 4. run authoritative integration checks across the combined wave;
237
+ 5. inspect test changes for integrity violations.
238
+
239
+ Fix a bounded integration issue in the owning item context or dispatch a focused
240
+ follow-up with the same boundary contract. Do not accept an unverified wave.
241
+
242
+ ### 5. Recompute and continue
243
+
244
+ Refresh item stages and the dependency graph after verification. Continue with
245
+ newly ready work until the selected scope has no executable implementing items.
246
+ If progress stops, record the exact unmet dependency, design bounce, failed
247
+ verification, or ownership conflict rather than declaring success.
248
+
249
+ ### 6. Roll up implementation readiness
250
+
251
+ For each touched parent, apply the conservative parent roll-up invariant. Record
252
+ children advanced, deviations, and verification in the parent body before its
253
+ own commit.
254
+
255
+ ### 7. Continue through review
256
+
257
+ Unless `stop-at-review` applies, resolve the effective `review_weight` and
258
+ invoke `/agile-workflow:review` with it for each advanced parent and for
259
+ advanced items not covered by a parent review. Let the review skill interpret
260
+ the weight and perform any required fresh-context review. With `none`, require
261
+ the same green implementation verification and let review complete its stage
262
+ contract without an independent review pass.
263
+
264
+ Honor the review result:
265
+
266
+ - approved work advances to `done` under review's contract;
267
+ - bounced work returns to `implementing` with `## Review findings` and the run
268
+ reports the bounce;
269
+ - blocked work retains a durable `## Blocker` and the run reports the blocker.
270
+
271
+ Do not loop blindly after a bounce. Resume implementation only when the finding
272
+ is bounded and still belongs to the current invocation; otherwise return the
273
+ review outcome as the honest completion boundary.
534
274
 
535
275
  ## Output
536
276
 
537
- In conversation:
538
- - **Scope**: how the scope arg resolved (e.g., "epic E-04 → 7 stories under 3
539
- features", or "story S-12 alone")
540
- - **Bundles**: how the items packed into agent-sized units (e.g., "9 items →
541
- 5 bundles: 1 multi-item bundle of 4 stories under `src/auth/*`, 1 of 2
542
- stories under `src/billing/webhooks`, 3 single-item bundles"). Include a
543
- one-line rationale per multi-item bundle.
544
- - **Items advanced**: count + list, with which parent each belongs to
545
- - **Parent features advanced to review**: list (only those whose children are
546
- all terminal-or-review now)
547
- - **Parent features still at implementing**: list (children outside the run
548
- remain note which)
549
- - **Waves**: how many waves ran, parallelism per wave (in bundles), any
550
- worktree isolation
551
- - **Deviations across items**: list (or "none")
552
- - **Verification**: build + test status
553
- - **Next**: `/agile-workflow:review <id>` for each advanced parent or item
554
-
555
- ## Guardrails
556
-
557
- - Ground yourself before spawning agents. Vague prompts produce vague
558
- implementations. Cross-feature scopes mean more reading, not less — every
559
- parent in the work set gets the full read.
560
- - Size the system before dispatch. If local search and direct file reads answer
561
- the discovery question, skip exploratory fanout and record that choice. Spawn Explore
562
- only for named unknowns or genuinely independent surfaces.
563
- - Decide parallelism deliberately. Three sub-agents per wave is a conservative
564
- default, not a hard ceiling. Use more only when write ownership is clear,
565
- dependencies are independent, and verification/reconciliation remains bounded.
566
- Use fewer when write sets overlap or the system is fragile. Bigger scopes mean
567
- more waves or wider safe waves, scheduled by the unified `depends_on` graph
568
- lifted to the bundle level.
569
- - **Bundle when the cluster wants to be one delivery; don't bundle for its
570
- own sake.** The default is still one agent per item. Reach for a multi-item
571
- bundle only when the criteria in Phase 3a all hold — adjacent scope, small
572
- individual items, shared patterns, same dependency layer, fits one sub-agent's
573
- context budget. Over-bundling produces an agent that loses the thread;
574
- under-bundling produces parallel agents that fight the same module.
575
- - **Don't bundle a parent-child dependency pair into the same bundle.** A
576
- bundle is a wave-slot; intra-bundle dependencies are sequenced inside the
577
- agent prompt, but the dependency must already be satisfiable when the bundle
578
- starts — that means deps inside a bundle only go from later items to earlier
579
- ones in the bundle's own order, never from earlier items to later ones.
580
- - Every agent prompt must be self-contained. Agents share no context. When
581
- the scope spans multiple features, each agent's prompt includes only the
582
- parent-feature design excerpt(s) relevant to its bundle's items.
583
- - Reference paths and key signatures in prompts, not entire files. Agents
584
- read files.
585
- - Only reference patterns you've verified by reading.
586
- - Run the verification commands after each wave. Integration issues only
587
- surface at the seams between agents' work — and cross-feature waves widen
588
- those seams. Bundle-level verification runs inside the agent; wave-level
589
- verification is still yours.
590
- - Check for file-overlap conflicts across bundles in Phase 3c before spawning.
591
- Two bundles in the same wave that touch the same file is a recipe for a
592
- merge accident — merge them, serialize them, or run with worktree isolation.
593
- - The orchestrator (you) updates parent features' stages to `review`, NOT
594
- individual agents. Agents only manage their own item files. And only
595
- advance a parent whose children are *all* at `review` or terminal — partial
596
- parents stay at `implementing`.
597
- - **Test integrity** is reinforced in every agent prompt and again at your
598
- post-wave verification (Phase 7). If an agent's commit silenced a test
599
- to make it pass — deletion, broad skip, `expect(true).toBe(true)`,
600
- asserting on whatever the code now returns — treat that as a blocker:
601
- revert or fix yourself, and surface it in the run summary. Real
602
- production bugs surfaced during verification get parked, not bundled.
603
- (Note: "bundled" here means rolled into another item, the old usage —
604
- it is unrelated to the new wave-slot bundle concept above.)
277
+ Report:
278
+
279
+ - resolved scope and any dropped items with unmet external dependencies;
280
+ - derived ownership, dependency waves, isolation decisions, and their rationale;
281
+ - worker capability choices and override source, if any;
282
+ - effective `review_weight` and whether it came from the caller, autopilot,
283
+ project convention, or default;
284
+ - items advanced, bounced, blocked, or left at review by explicit request;
285
+ - parent features advanced or left implementing, with the eligibility reason;
286
+ - per-wave and final verification results;
287
+ - commits created, one per item;
288
+ - review lane outcomes and remaining executable next step.
289
+
290
+ Do not prescribe a manual review invocation as the default next step: review is
291
+ part of this run unless the caller explicitly chose the review boundary.