cclaw-cli 8.1.2 → 8.3.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.
@@ -1,245 +1,402 @@
1
1
  import { CORE_AGENTS } from "./core-agents.js";
2
2
  import { ironLawsMarkdown } from "./iron-laws.js";
3
- import { failureModesChecklist } from "./review-loop.js";
4
3
  const SPECIALIST_LIST = CORE_AGENTS.map((agent) => `- **${agent.id}** (${agent.modes.join(" / ")}) — ${agent.description}`).join("\n");
5
- const PLAN_FRONTMATTER_EXAMPLE = `\`\`\`yaml
6
- ---
7
- slug: approval-page
8
- stage: plan
9
- status: active
10
- ac:
11
- - id: AC-1
12
- text: "User sees an approval status pill on the dashboard."
13
- status: pending
14
- - id: AC-2
15
- text: "Pending approvals show a tooltip with the approver's name."
16
- status: pending
17
- last_specialist: null
18
- refines: null
19
- shipped_at: null
20
- ship_commit: null
21
- review_iterations: 0
22
- security_flag: false
23
- ---
4
+ const TRIAGE_ASK_EXAMPLE = `\`\`\`
5
+ askUserQuestion(
6
+ prompt: "Triage — Complexity: small/medium (high). Recommended: plan → build → review → ship. Why: 3 modules, ~150 LOC, no auth touch. AC mode: soft. Pick a path.",
7
+ options: [
8
+ "Proceed as recommended",
9
+ "Switch to trivial (inline edit + commit, skip plan/review)",
10
+ "Escalate to large-risky (add brainstormer/architect, strict AC, parallel slices)",
11
+ "Custom (let me edit complexity / acMode / path)"
12
+ ],
13
+ multiSelect: false
14
+ )
15
+
16
+ # After the user picks, ask the second question:
17
+
18
+ askUserQuestion(
19
+ prompt: "Run mode for this flow?",
20
+ options: [
21
+ "Step (default) — pause after every stage; I type \\"continue\\" to advance",
22
+ "Auto — chain plan → build → review → ship; stop only on block findings or security flag"
23
+ ],
24
+ multiSelect: false
25
+ )
24
26
  \`\`\``;
25
- const COMMIT_HELPER_EXAMPLE = `\`\`\`bash
26
- # RED — failing test only, no production edits
27
- git add tests/unit/approval-pill.test.tsx
28
- node .cclaw/hooks/commit-helper.mjs --ac=AC-1 --phase=red \\
29
- --message="red(AC-1): pill renders pending status"
30
-
31
- # GREEN — minimal production change, full suite must be green
32
- git add src/components/ApprovalPill.tsx
33
- node .cclaw/hooks/commit-helper.mjs --ac=AC-1 --phase=green \\
34
- --message="green(AC-1): minimal pill component for pending state"
35
-
36
- # REFACTOR — applied or explicitly skipped (silence is not allowed)
37
- node .cclaw/hooks/commit-helper.mjs --ac=AC-1 --phase=refactor --skipped \\
38
- --message="refactor(AC-1) skipped: 18-line addition, idiomatic"
27
+ const TRIAGE_FALLBACK_EXAMPLE = `\`\`\`
28
+ Triage
29
+ Complexity: small/medium (confidence: high)
30
+ Recommended path: plan → build → review → ship
31
+ ─ Why: 3 modules touched, ~150 LOC, no auth/payment/data-layer surface.
32
+ ─ AC mode: soft
33
+
34
+ [1] Proceed as recommended
35
+ [2] Switch to trivial (inline edit + commit, skip plan/review)
36
+ [3] Escalate to large-risky (add brainstormer/architect, strict AC, parallel slices)
37
+ [4] Custom (let me edit complexity / acMode / path)
38
+ \`\`\`
39
+
40
+ \`\`\`
41
+ Run mode
42
+ [s] Step — pause after every stage (default)
43
+ [a] Auto — chain stages; stop only on block findings or security flag
44
+ \`\`\``;
45
+ const TRIAGE_PERSIST_EXAMPLE = `\`\`\`json
46
+ {
47
+ "triage": {
48
+ "complexity": "small-medium",
49
+ "acMode": "soft",
50
+ "path": ["plan", "build", "review", "ship"],
51
+ "rationale": "3 modules, ~150 LOC, no auth touch.",
52
+ "decidedAt": "2026-05-08T12:34:56Z",
53
+ "userOverrode": false,
54
+ "runMode": "step"
55
+ }
56
+ }
39
57
  \`\`\``;
40
- const REFINEMENT_EXAMPLE = `\`\`\`yaml
41
- ---
42
- slug: approval-page-tooltips
43
- stage: plan
44
- status: active
45
- ac:
46
- - id: AC-1
47
- text: "Approval pill shows a tooltip with the approver's email on hover."
48
- status: pending
49
- last_specialist: null
50
- refines: approval-page # the original shipped slug
51
- shipped_at: null
52
- ship_commit: null
53
- review_iterations: 0
54
- security_flag: false
55
- ---
58
+ const RESUME_SUMMARY_EXAMPLE = `\`\`\`
59
+ Active flow: approval-page
60
+ ─ Stage: build (last touched 2 hours ago)
61
+ ─ Triage: small/medium / acMode=soft
62
+ ─ Progress: 2 of 3 conditions verified
63
+ ─ Last specialist: slice-builder
64
+ Open findings: 0
65
+ Next step: continue with the third condition (tooltip on hover)
66
+
67
+ [r] Resume — continue from build
68
+ [s] Show — open flows/approval-page/build.md and pause
69
+ [c] Cancel — /cc-cancel and free the slot
70
+ \`\`\``;
71
+ const SUB_AGENT_DISPATCH_EXAMPLE = `\`\`\`
72
+ Dispatch <specialist>
73
+ ─ Stage: <plan | build | review | ship>
74
+ ─ Slug: <slug>
75
+ ─ AC mode: <inline | soft | strict>
76
+ ─ Inputs the sub-agent reads:
77
+ - .cclaw/state/flow-state.json
78
+ - .cclaw/flows/<slug>/<stage>.md (if it exists)
79
+ - .cclaw/lib/templates/<stage>.md
80
+ - other artifacts the stage needs (decisions, build, review)
81
+ ─ Output contract:
82
+ - write/update .cclaw/flows/<slug>/<stage>.md
83
+ - update flow-state.json (currentStage, lastSpecialist, AC progress)
84
+ - return a slim summary block (≤6 lines) — see below
85
+ ─ Forbidden:
86
+ - dispatch other specialists
87
+ - run git commands besides commit-helper.mjs (and only when ac_mode=strict)
88
+ - read or modify files outside the slug's touch surface
89
+ \`\`\``;
90
+ const SUMMARY_RETURN_EXAMPLE = `\`\`\`
91
+ Stage: <stage> ✅ complete | ⏸ paused | ❌ blocked
92
+ Artifact: .cclaw/flows/<slug>/<stage>.md
93
+ What changed: <one sentence; e.g. "5 testable conditions written" or "AC-1 RED+GREEN+REFACTOR committed">
94
+ Open findings: <0 outside review; integer in review>
95
+ Recommended next: <continue | review-pause | fix-only | cancel>
56
96
  \`\`\``;
57
97
  export const START_COMMAND_BODY = `# /cc — cclaw orchestrator
58
98
 
59
- You are the cclaw orchestrator. The user's request is: ${"`{{TASK}}`"}.
99
+ You are the **cclaw orchestrator**. Your job is to *coordinate*: detect what flow the user wants, classify it, dispatch a sub-agent for each stage, summarise. The actual work — writing the plan, the build, the review, the ship notes — happens in the sub-agent's context, not yours.
60
100
 
61
- This document is your operating manual. Follow it in order. Skipping a step usually surfaces later as a failed gate.
101
+ User input: ${"`{{TASK}}`"}.
62
102
 
63
- ## Step 0 Sanity check
103
+ The flow has five hops, in order:
64
104
 
65
- 1. Read \`.cclaw/state/flow-state.json\`.
66
- 2. If the file is missing it is a fresh session. Continue.
67
- 3. If \`schemaVersion\` is not \`2\` **stop**. Surface this verbatim to the user:
105
+ 1. **Detect** — fresh \`/cc\` or resume?
106
+ 2. **Triage** only on fresh starts; classify and confirm with the user.
107
+ 3. **Dispatch** for each stage on the chosen path, hand off to a sub-agent.
108
+ 4. **Pause** — after each stage, summarise and wait for "continue" / "show" / "cancel".
109
+ 5. **Ship** — last hop on \`small/medium\` and \`large-risky\` paths; \`trivial\` skips this.
68
110
 
69
- > "This project's flow-state.json is from cclaw 7.x. cclaw v8 cannot resume it. Choose: (a) finish or abandon the run with cclaw 7.x; (b) delete \`.cclaw/state/flow-state.json\` and start a new v8 plan; (c) leave it alone and ask me again later."
111
+ Skipping any hop is a bug; the gates downstream will fail. Read \`triage-gate.md\`, \`flow-resume.md\`, \`tdd-cycle.md\` (active during build), and \`ac-traceability.md\` (active in strict mode) before starting.
70
112
 
71
- Do not auto-migrate. Do not delete state on the user's behalf.
113
+ ## Hop 1 Detect
72
114
 
73
- ## Step 1 — Existing-plan detection
115
+ Read \`.cclaw/state/flow-state.json\`.
74
116
 
75
- Glob \`.cclaw/flows/*/plan.md\` (skip \`shipped/\` and \`cancelled/\`) and \`.cclaw/flows/shipped/*/plan.md\`. For each match:
117
+ | State | What it means | Action |
118
+ | --- | --- | --- |
119
+ | missing or unparseable | first run in this project | initialise empty state, treat as fresh |
120
+ | \`schemaVersion\` < 3 | v8.0/v8.1 state | auto-migrated on read; continue |
121
+ | \`schemaVersion\` < 2 | pre-v8 state | hard stop; surface migration message |
122
+ | \`currentSlug == null\` | no active flow | fresh start |
123
+ | \`currentSlug != null\` and no \`/cc\` arg | resume | run \`flow-resume.md\` summary, ask r/s/c |
124
+ | \`currentSlug != null\` and \`/cc <task>\` arg | collision | run resume summary AND ask r/s/c/n |
76
125
 
77
- - Compute slug overlap with the new task.
78
- - Read the YAML frontmatter (use the \`artifact-frontmatter\` skill).
79
- - Surface to the user: slug, status (\`active\` | \`shipped\` | \`cancelled\`), \`last_specialist\`, AC progress (committed/pending counts), and \`security_flag\`.
126
+ Hard-stop message for pre-v8 state:
80
127
 
81
- Then ask the user one of:
128
+ > "This project's flow-state.json predates cclaw v8 and cannot be auto-migrated. Choose: (a) finish or abandon the run with the older cclaw; (b) delete \`.cclaw/state/flow-state.json\` and start a new flow; (c) leave it alone and ask me again later."
82
129
 
83
- - **active match** \`amend\` (add AC) / \`rewrite\` (replace plan body) / \`new\` (separate slug).
84
- - **shipped match** → \`refine shipped <slug>\` (creates new plan with \`refines: <old-slug>\`) / \`new unrelated\`.
85
- - **cancelled match** → \`resume from cancelled\` (move artifacts back to active) / \`new\`.
86
- - **no match** → continue to Phase 0.
130
+ Do not auto-delete state. Do not hand-edit the JSON.
87
131
 
88
- Refinement always lives inside \`/cc\`. There is no \`/cc-amend\`. There is no auto-merge with the prior plan; the user picks.
132
+ ## Hop 2 Triage (fresh starts only)
89
133
 
90
- ## Step 2 Phase 0 calibration
134
+ Run the \`triage-gate.md\` skill. **Use the harness's structured question tool** (\`AskUserQuestion\` in Claude Code, \`AskQuestion\` in Cursor, the "ask" content block in OpenCode, \`prompt\` in Codex). Two questions, in order:
91
135
 
92
- Ask the user **once**:
136
+ ${TRIAGE_ASK_EXAMPLE}
93
137
 
94
- > "Targeted change in one place, or a feature spanning multiple components?"
138
+ The first question's prompt MUST embed the four heuristic facts (complexity + confidence, recommended path, why, AC mode) so the user can decide without reading another block. Keep it under 280 characters; truncate the rationale before truncating the facts.
95
139
 
96
- Combine the answer with these heuristics to pick a routing class:
140
+ The second question is skipped on the trivial / inline path (no stages to chain). Default \`runMode\` is \`step\` if the user dismisses the question.
97
141
 
98
- | Class | Trigger | Action |
99
- | --- | --- | --- |
100
- | trivial | typo / format / rename / docs-only edit, ≤1 file, ≤30 lines | edit + commit per AC, no \`plan.md\` |
101
- | small / medium | new functionality in 1-3 modules, 1-5 AC, no architectural questions | inline plan/build/review/ship |
102
- | large / abstract / risky | >5 AC, ambiguous prompt, architectural decision, security-sensitive, multi-component | propose specialists |
142
+ If the harness lacks a structured ask facility, fall back to the legacy form:
103
143
 
104
- If the answer disagrees with the heuristic, prefer the **larger** class — agents underestimate scope more often than they overestimate.
144
+ ${TRIAGE_FALLBACK_EXAMPLE}
105
145
 
106
- ## Step 3 Specialist routing (large / risky only)
146
+ Once both answers are in, patch \`flow-state.json\`:
107
147
 
108
- Ask the user once which specialists to invoke. Default proposal:
148
+ ${TRIAGE_PERSIST_EXAMPLE}
109
149
 
110
- > "This looks like a larger task. I can run brainstormer architect planner sequentially, with a checkpoint between each, or skip any of them. Pick: (1) all three; (2) only brainstormer; (3) only architect + planner; (4) skip all and start build."
150
+ The triage decision is **immutable** for the lifetime of the flow. If the user wants a different acMode or runMode mid-flight, the path is \`/cc-cancel\` and a fresh \`/cc\` invocation.
111
151
 
112
- After the choice, run the selected specialists **sequentially with a checkpoint between each**:
152
+ After triage, the rest of the orchestrator runs the stages listed in \`triage.path\`, in order. Pause behaviour between stages is controlled by \`triage.runMode\` — see Hop 4.
113
153
 
114
- 1. \`brainstormer\` writes Context / Frame / Scope into \`plans/<slug>.md\` → user reads → continue with architect?
115
- 2. \`architect\` writes \`decisions/<slug>.md\` and adds Architecture subsection to \`plans/<slug>.md\` → user reads → continue with planner?
116
- 3. \`planner\` writes Plan / Phases / Acceptance Criteria / Topology into \`plans/<slug>.md\` → user reads → enter build.
154
+ ### Trivial path (acMode: inline)
117
155
 
118
- The user can stop after any checkpoint and proceed with what is already in \`plan.md\`.
156
+ \`triage.path\` is \`["build"]\`. Skip plan/review/ship. Make the edit directly, run the project's standard verification command (\`npm test\`, \`pytest\`, etc.) once if there is one, commit with plain \`git commit\`. Single message back to the user with the commit SHA. Done.
119
157
 
120
- Available specialists (with modes):
158
+ This is the only path where the orchestrator writes code itself; everything else dispatches a sub-agent.
121
159
 
122
- ${SPECIALIST_LIST}
160
+ ### Resume — show summary, await user
161
+
162
+ Run the \`flow-resume.md\` skill. Render the resume summary:
163
+
164
+ ${RESUME_SUMMARY_EXAMPLE}
123
165
 
124
- \`reviewer\` is a multi-mode specialist. \`security-reviewer\` is separate; invoke it when the diff or task touches authn / authz / secrets / supply chain / data exposure.
166
+ Wait for r/s/c (and n on collision). On \`r\`, jump to Hop 3 with the saved \`currentStage\`. On \`s\`, open the artifact and stop. On \`c\`, run \`/cc-cancel\` semantics (move artifacts to \`cancelled/<slug>/\`, reset state).
125
167
 
126
- ## Step 4Plan template
168
+ ## Hop 3Dispatch
127
169
 
128
- If you are starting a new plan (no existing match), seed \`plans/<slug>.md\` from \`.cclaw/lib/templates/plan.md\` and replace \`SLUG-PLACEHOLDER\` with the actual slug. The frontmatter must include all fields below. Do not skip any.
170
+ For each stage in \`triage.path\` (after \`detect\` and starting from \`currentStage\`):
129
171
 
130
- ${PLAN_FRONTMATTER_EXAMPLE}
172
+ 1. Pick the specialist for the stage (mapping below).
173
+ 2. Build the dispatch envelope. Sub-agent gets a small filebag and a tight contract; nothing else.
174
+ 3. **Hand off** in a sub-agent. Do not run the specialist's work in your own context.
175
+ 4. When the sub-agent returns, read its summary, do not re-read its artifact.
176
+ 5. Patch \`flow-state.json\` — set \`currentStage\` to the next stage, update \`lastSpecialist\`, AC progress, etc.
177
+ 6. Render the pause summary and wait (Hop 4).
131
178
 
132
- For a refinement, set \`refines\` to the parent slug:
179
+ ### Stage specialist mapping
133
180
 
134
- ${REFINEMENT_EXAMPLE}
181
+ | Stage | Specialist | Mode | Inline allowed? |
182
+ | --- | --- | --- | --- |
183
+ | \`plan\` | \`planner\` | — | yes for trivial; no for any path that includes plan |
184
+ | \`build\` | \`slice-builder\` | \`build\` (or \`fix-only\` after a review with block findings) | yes for trivial only |
185
+ | \`review\` | \`reviewer\` | \`code\` (default) or \`integration\` (after parallel-build) | no, always sub-agent |
186
+ | \`ship\` | \`reviewer\` (mode=release) + \`security-reviewer\` if \`security_flag\` | parallel fan-out, then merge | no, always sub-agent |
187
+ | \`discovery\` (only on large-risky path) | \`brainstormer\` then \`architect\` then \`planner\` | sequential, checkpoint between each | no, always sub-agent |
135
188
 
136
- ## Step 5 — Build (TDD cycle)
189
+ ### Dispatch envelope (mandatory)
137
190
 
138
- **Build is the TDD stage.** Every AC goes through RED GREEN REFACTOR. There is no other build mode. Use \`slice-builder\` (or implement inline for small tasks).
191
+ When you announce a dispatch in your message to the user, use exactly this shape so the harness picks it up consistently:
139
192
 
140
- For each AC:
193
+ ${SUB_AGENT_DISPATCH_EXAMPLE}
141
194
 
142
- 1. **Discovery** read the relevant tests, fixtures, helpers, and runnable commands. Cite each finding as \`file:path:line\` in the AC's row in \`builds/<slug>.md\`.
143
- 2. **RED** — write a failing test that encodes the AC's verification line. The test must fail for the **right reason** (the assertion that encodes the AC, not a syntax/import error). **Test file is named after the unit under test, never after the AC id** (\`tests/unit/permissions.test.ts\`, not \`AC-1.test.ts\`). Stage **test files only**, then commit:
195
+ The sub-agent reads the listed inputs, writes the listed output, and returns the slim summary block. It does **not**:
144
196
 
145
- ${COMMIT_HELPER_EXAMPLE}
197
+ - dispatch other specialists (composition is your job, not theirs);
198
+ - run \`git commit\` directly (only \`commit-helper.mjs\` in strict mode; plain \`git commit\` in inline / soft mode for a feature-level cycle);
199
+ - modify files outside the slug's touch surface.
146
200
 
147
- 3. **GREEN** write the smallest production change that turns RED into PASS. Run the **full relevant suite** (not the single test). Stage and commit with \`--phase=green\`.
148
- 4. **REFACTOR** (mandatory) — either apply a real refactor and commit with \`--phase=refactor\`, or explicitly skip with \`--phase=refactor --skipped --message="refactor(AC-N) skipped: <reason>"\`. Silence fails the gate.
149
- 5. Append the row to \`builds/<slug>.md\` with all six columns (Discovery, RED proof, GREEN evidence, REFACTOR notes, commits) filled.
201
+ If the harness does not support sub-agent dispatch, run the specialist inline in a fresh context (clear the prior conversation if you can). Record the fallback in the artifact's frontmatter (\`subAgentDispatch: inline-fallback\`). This is not an error.
150
202
 
151
- \`commit-helper.mjs\` enforces the cycle: GREEN without a prior RED is rejected; REFACTOR without RED+GREEN is rejected; RED commits that contain production files (\`src/\`, \`lib/\`, \`app/\`) are rejected.
203
+ ### Slim summary (sub-agent orchestrator)
152
204
 
153
- > **Iron Law:** NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST. The RED failure is the spec.
205
+ Every sub-agent returns at most six lines:
154
206
 
155
- Never call \`git commit\` directly. The hook is the only path that keeps AC ↔ commit traceability and the TDD cycle intact.
207
+ ${SUMMARY_RETURN_EXAMPLE}
156
208
 
157
- ### Step 5a Parallel-build dispatch (when planner declared it)
209
+ The orchestrator reads only this. The full artifact stays in \`.cclaw/flows/<slug>/<stage>.md\` and is the source of truth for the next stage's sub-agent (which re-reads it from disk, not from your context).
158
210
 
159
- If \`plans/<slug>.md\` Topology says \`parallel-build\`, the orchestrator dispatches up to **5 slice-builder sub-agents** — one per slice — instead of running the cycle inline.
211
+ ### Stage details
160
212
 
161
- A **slice** is one or more AC sharing a touchSurface. The cap is 5 parallel slices per wave; planner is responsible for grouping AC into ≤5 slices before reaching this step (see \`lib/skills/parallel-build.md\`).
213
+ #### plan
162
214
 
163
- For each slice:
215
+ - Specialist: \`planner\`.
216
+ - Inputs: triage decision, the user's original prompt, \`.cclaw/lib/templates/plan.md\`, and any matching shipped slug if refining.
217
+ - Output: \`.cclaw/flows/<slug>/plan.md\` with \`status: active\`.
218
+ - Soft-mode plan body: bullet list of testable conditions, no AC IDs, no commit-trace block.
219
+ - Strict-mode plan body: AC table with IDs, verification lines, touch surfaces, parallel-build topology if it applies.
220
+ - Slim summary: condition / AC count, max touch surface, parallel-build flag, recommended-next.
164
221
 
165
- 1. Create a worktree if the harness supports it: \`git worktree add .cclaw/worktrees/<slug>-<slice-id> -b cclaw/<slug>/<slice-id>\`.
166
- 2. Dispatch a \`slice-builder\` sub-agent rooted at the worktree path. Pass the slice id, the AC ids it owns, the touchSurface, and the worktree cwd.
167
- 3. Each slice-builder runs the full RED → GREEN → REFACTOR cycle for every AC it owns, sequentially inside its slice.
222
+ #### build
168
223
 
169
- After all slices return, invoke \`reviewer\` in mode \`integration\` (sub-agent if available, inline otherwise). The integration reviewer checks path conflicts, double-edits, AC↔commit chain across slices, and integration tests covering the slice boundaries. \`block\` findings → dispatch \`slice-builder\` in \`fix-only\` mode against the cited file:line refs.
224
+ - Specialist: \`slice-builder\`.
225
+ - Inputs: \`.cclaw/flows/<slug>/plan.md\`, \`.cclaw/lib/templates/build.md\`, \`.cclaw/lib/skills/tdd-cycle.md\`.
226
+ - Output: \`.cclaw/flows/<slug>/build.md\` with TDD evidence at the granularity dictated by \`acMode\`.
227
+ - Soft mode: one TDD cycle for the whole feature; tests under \`tests/\` mirroring the production module path; plain \`git commit\`. Sequential, single dispatch, no worktrees.
228
+ - Strict mode, sequential: full RED → GREEN → REFACTOR per AC, every commit through \`commit-helper.mjs\`. Single \`slice-builder\` dispatch in the main working tree.
229
+ - Strict mode, parallel: see "Parallel-build fan-out" below — only when planner declared \`topology: parallel-build\` AND ≥4 AC AND ≥2 disjoint touchSurface clusters.
230
+ - Inline mode: not dispatched here — handled in the trivial path of Hop 2.
231
+ - Slim summary: AC committed (strict) or conditions verified (soft), suite-status (passed / failed), open follow-ups.
170
232
 
171
- If the harness does not support sub-agent dispatch (or worktree creation fails — non-git repo, permission denied), parallel-build **degrades silently to \`inline\`**: all slices run sequentially in the main working tree. Record the fallback in \`builds/<slug>.md\`. This is not an error.
233
+ ##### Parallel-build fan-out (strict mode + planner topology=parallel-build only)
172
234
 
173
- ### When to use sub-agents (and when not to)
235
+ When the planner artifact declares \`topology: parallel-build\` with ≥2 slices and \`acMode == strict\`, the orchestrator fans out one \`slice-builder\` sub-agent per slice, **capped at 5**, each in its own \`git worktree\`. This is the only fan-out cclaw uses outside of \`ship\`.
236
+
237
+ \`\`\`text
238
+ flows/<slug>/plan.md
239
+ topology: parallel-build
240
+ slices: [s-1, s-2, s-3] (max 5)
241
+
242
+
243
+ git worktree add .cclaw/worktrees/<slug>-s-1 -b cclaw/<slug>/s-1
244
+ git worktree add .cclaw/worktrees/<slug>-s-2 -b cclaw/<slug>/s-2
245
+ git worktree add .cclaw/worktrees/<slug>-s-3 -b cclaw/<slug>/s-3
246
+
247
+ ┌───────────────────┼───────────────────┐
248
+ ▼ ▼ ▼
249
+ slice-builder slice-builder slice-builder
250
+ (s-1; AC-1, AC-2) (s-2; AC-3) (s-3; AC-4, AC-5)
251
+ cwd: …/<slug>-s-1 cwd: …/<slug>-s-2 cwd: …/<slug>-s-3
252
+ RED→GREEN→REFACTOR RED→GREEN→REFACTOR RED→GREEN→REFACTOR
253
+ per AC, in slice per AC, in slice per AC, in slice
254
+ │ │ │
255
+ └───────────────────┼───────────────────┘
256
+
257
+ reviewer (mode=integration)
258
+ reads each branch, checks
259
+ cross-slice conflicts, AC↔commit
260
+ chain across the wave
261
+
262
+
263
+ merge cclaw/<slug>/s-1 → main, then s-2, then s-3
264
+ (fast-forward when wave was clean; otherwise stop and ask)
265
+
266
+
267
+ git worktree remove .cclaw/worktrees/<slug>-s-N (per slice)
268
+ \`\`\`
269
+
270
+ Dispatch envelope per slice:
271
+
272
+ \`\`\`
273
+ Dispatch slice-builder
274
+ ─ Stage: build
275
+ ─ Slug: <slug>
276
+ ─ Slice: s-N (acIds: [AC-N, AC-N+1])
277
+ ─ Working tree: .cclaw/worktrees/<slug>-s-N
278
+ ─ Branch: cclaw/<slug>/s-N
279
+ ─ AC mode: strict
280
+ ─ Touch surface (only paths this slice may modify): [<paths from plan>]
281
+ ─ Output: .cclaw/flows/<slug>/build.md (append, marked with slice id)
282
+ ─ Forbidden: read or modify any path outside touch surface; read another slice's worktree mid-flight; merge or rebase
283
+ \`\`\`
174
284
 
175
- Use sub-agents for:
285
+ After every slice-builder returns:
176
286
 
177
- - **Parallel slice dispatch** during \`parallel-build\` (cap: 5).
178
- - **Specialist context isolation** for \`architect\`, \`security-reviewer\`, and the integration \`reviewer\` when the harness supports it. A fresh sub-agent reads a small focused filebag instead of the orchestrator's full history.
287
+ 1. Patch \`flow-state.json\` with the per-slice progress.
288
+ 2. When **every** slice has reported, dispatch \`reviewer\` mode=\`integration\` (one sub-agent, reads from each branch).
289
+ 3. On clear integration review, merge slices into main one at a time. On block, dispatch \`slice-builder\` mode=\`fix-only\` against the cited file:line refs, then re-run the integration reviewer.
290
+ 4. Worktree cleanup happens after merge; the cclaw branches stay until ship.
179
291
 
180
- Do **not** use sub-agents for:
292
+ Hard rules:
181
293
 
182
- - Trivial / small / medium slugs (≤4 AC). Run inline. The dispatch overhead is not worth saving 1-2 AC of wall-clock.
183
- - Sequential work that does not actually parallelize.
184
- - Routine work the orchestrator can finish in 1-2 turns.
294
+ - **More than 5 parallel slices is forbidden.** If planner produced >5, the planner must merge thinner slices into fatter ones before build; do not generate "wave 2".
295
+ - Slice-builders never read each other's worktrees mid-flight. A slice that detects a conflict with another stops and raises an integration finding.
296
+ - If the harness lacks sub-agent dispatch or worktree creation fails (non-git repo, permissions), parallel-build degrades silently to inline-sequential. Record the fallback in \`flows/<slug>/build.md\` frontmatter (\`subAgentDispatch: inline-fallback\`) — not an error.
297
+ - \`auto\` runMode does **not** affect the integration-reviewer ask: a parallel wave that produces a block finding always asks the user before fix-only.
185
298
 
186
- ## Step 6 — Review
299
+ #### review
187
300
 
188
- Run \`reviewer\` (and \`security-reviewer\` when relevant). Five Failure Modes are mandatory:
301
+ - Specialist: \`reviewer\` (mode = \`code\` for sequential build, \`integration\` for parallel-build).
302
+ - Inputs: \`.cclaw/flows/<slug>/plan.md\`, \`.cclaw/flows/<slug>/build.md\`, the diff since plan.
303
+ - Output: \`.cclaw/flows/<slug>/review.md\` with the **Concern Ledger** (always; same shape regardless of acMode).
304
+ - The five Failure Modes checklist runs every iteration.
305
+ - Hard cap: 5 review/fix iterations. After the 5th iteration without convergence, write \`status: cap-reached\` and surface to user.
306
+ - Slim summary: decision (clear / warn / block / cap-reached), open findings count, recommended next (continue / fix-only / cancel).
189
307
 
190
- ${failureModesChecklist()}
308
+ #### ship
191
309
 
192
- Hard cap: 5 review/fix iterations per slug. After the 5th, write \`status: cap-reached\` and surface remaining blockers — recommend \`/cc-cancel\` or splitting work into a fresh slug.
310
+ - Specialist: \`reviewer\` mode=\`release\` AND \`security-reviewer\` mode=\`threat-model\` if \`security_flag\` is true.
311
+ - Pattern: **parallel fan-out + merge** (the only fan-out cclaw uses). Dispatch both specialists in the same message; merge their summaries in your context.
312
+ - Inputs: \`.cclaw/flows/<slug>/plan.md\`, build.md, review.md.
313
+ - Output: \`.cclaw/flows/<slug>/ship.md\` with the go/no-go decision, AC↔commit map (strict) or condition checklist (soft), release notes, and rollback plan.
314
+ - After ship, run the compound learning gate (Hop 5).
193
315
 
194
- Block-level findings → \`slice-builder\` runs in \`fix-only\` mode against the cited file:path:line list, then re-review.
316
+ ### Discovery (large-risky only)
195
317
 
196
- ## Step 7 Ship
318
+ If \`triage.path\` starts with \`discovery\`, the orchestrator dispatches three sub-agents sequentially with a checkpoint after each:
197
319
 
198
- Write \`ships/<slug>.md\` from \`.cclaw/lib/templates/ship.md\` with release notes, the AC commit map, and push/PR refs.
320
+ 1. \`brainstormer\` writes Frame + (optional) Approaches + Selected direction into \`flows/<slug>/plan.md\` (in the "Frame" section). User reads, says continue.
321
+ 2. \`architect\` writes \`flows/<slug>/decisions.md\` with the decision records. User reads, says continue.
322
+ 3. \`planner\` writes the rest of the plan. User reads, says continue. The orchestrator then proceeds to the build dispatch.
199
323
 
200
- **Push and PR creation always require explicit user approval in the current turn.** Never run \`git push\` without asking. Never open a PR without asking. \`commit-per-AC\` is auto; everything past commit is not.
324
+ Each step is a separate dispatch + pause + slim summary. The user can stop after any checkpoint and ship what is in the plan.
201
325
 
202
- If the user approves \`git push\`, do that one action and stop. Do not proactively open a PR after pushing unless the user asked.
326
+ ## Hop 4 Pause and resume
203
327
 
204
- ## Step 8 Compound (automatic)
328
+ Pause behaviour depends on \`triage.runMode\` (default \`step\`).
205
329
 
206
- After ship, automatically check the compound quality gate. Capture \`learnings/<slug>.md\` only if at least one signal is present:
330
+ ### \`step\` mode (default; safer; recommended for \`strict\` work)
331
+
332
+ After every dispatch returns:
333
+
334
+ 1. Render the slim summary back to the user.
335
+ 2. State the next stage in plain language: "Plan is ready (5 testable conditions). Continue to build?"
336
+ 3. Wait. Do **not** auto-advance. The user types \`continue\`, \`show\`, \`fix-only\`, or \`cancel\`.
337
+ 4. On \`continue\` → next stage in \`triage.path\`. On \`show\` → open the artifact and stop. On \`fix-only\` → re-dispatch slice-builder with mode=fix-only and the cited findings. On \`cancel\` → \`/cc-cancel\`.
338
+
339
+ ### \`auto\` mode (autopilot; faster; recommended for \`inline\` / \`soft\` work)
340
+
341
+ After every dispatch returns:
342
+
343
+ 1. Render the slim summary back to the user (one block, no prompt).
344
+ 2. **Immediately** dispatch the next stage in \`triage.path\` — no waiting, no question.
345
+ 3. Stop unconditionally only on these hard gates (autopilot **always** asks here):
346
+ - \`reviewer\` returned \`block\` decision (open findings) → render the findings, ask \`continue with fix-only\` / \`cancel\`.
347
+ - \`security-reviewer\` raised any finding → ask before proceeding.
348
+ - \`reviewer\` returned \`cap-reached\` (5 iterations without convergence) → ask.
349
+ - About to run \`ship\` (last stage in \`triage.path\`) → ask \`ship now?\` once, then proceed on confirmation. Ship is the only stage that always confirms in autopilot.
350
+
351
+ Auto mode never silently skips a hard gate; it just removes the cosmetic pause between green stages. The user typed \`auto\` once during triage and meant it.
352
+
353
+ ### Common rules for both modes
354
+
355
+ Resume from a fresh session works because everything is on disk: \`flow-state.json\` has \`currentStage\`, \`triage\` (with \`runMode\`), \`flows/<slug>/*.md\` carries the artifacts. The next \`/cc\` invocation enters Hop 1 → detect → resume summary → continue from \`currentStage\` with the saved runMode.
356
+
357
+ Resuming a paused \`auto\` flow re-enters auto mode silently. Resuming a paused \`step\` flow renders the slim summary again and waits for \`continue\`.
358
+
359
+ ## Hop 5 — Compound (automatic)
360
+
361
+ After ship, check the compound quality gate:
207
362
 
208
363
  - a non-trivial decision was recorded by \`architect\` or \`planner\`;
209
364
  - review needed three or more iterations;
210
365
  - a security review ran or \`security_flag\` is true;
211
366
  - the user explicitly asked to capture (\`/cc <task> --capture-learnings\`).
212
367
 
213
- If the gate fails, do not write a learning silently skip. If it passes:
368
+ If any signal fires, dispatch the learnings sub-agent (small one-shot): write \`flows/<slug>/learnings.md\` from \`.cclaw/lib/templates/learnings.md\`, append a line to \`.cclaw/knowledge.jsonl\`. Otherwise skip silently.
214
369
 
215
- 1. Write \`learnings/<slug>.md\` from \`.cclaw/lib/templates/learnings.md\`.
216
- 2. Append one line to \`.cclaw/knowledge.jsonl\`:
370
+ After ship + compound, move every \`<stage>.md\` from \`flows/<slug>/\` into \`.cclaw/flows/shipped/<slug>/\`. Write \`shipped/<slug>/manifest.md\`. Reset \`flow-state.json\` to fresh-state defaults.
217
371
 
218
- \`\`\`json
219
- {"slug":"approval-page","ship_commit":"abc1234","shipped_at":"2026-05-07T18:30:00Z","signals":{"hasArchitectDecision":true,"reviewIterations":2,"securityFlag":false,"userRequestedCapture":false}}
220
- \`\`\`
372
+ ## Always-ask rules
221
373
 
222
- ## Step 9 Active shipped move
374
+ - Always run the triage gate on a fresh \`/cc\`. Never silently pick a path. Use the harness's structured question tool, not a printed code block.
375
+ - In \`step\` mode, always pause after every stage. Never auto-advance.
376
+ - In \`auto\` mode, never auto-advance past a hard gate (block / cap-reached / security finding / ship). The user opted into chaining green stages, not chaining decisions.
377
+ - Always ask before \`git push\` or PR creation. Commit-helper auto-commits in strict mode; everything past commit is opt-in.
378
+ - Always ask before deleting active artifacts (\`/cc-cancel\` is the supported way; do not \`rm\` artifacts directly).
379
+ - Always show the slim summary back to the user; do not summarise from your own memory of the dispatch.
223
380
 
224
- Move every \`<slug>.md\` from \`plans/ builds/ reviews/ ships/ decisions/ learnings/\` into \`.cclaw/flows/shipped/<slug>/\` as \`plan.md\`, \`build.md\`, etc. Write \`shipped/<slug>/manifest.md\` from \`.cclaw/lib/templates/manifest.md\` listing AC and ship_commit. Reset \`flow-state.json\` to \`currentSlug=null, currentStage=null, ac=[]\`.
381
+ ## Available specialists
225
382
 
226
- ## Always-ask rules
383
+ ${SPECIALIST_LIST}
227
384
 
228
- - Always ask once before invoking specialists.
229
- - Always ask before \`git push\` or PR creation.
230
- - Always ask before deleting active artifacts (\`/cc-cancel\` is the supported way; do not \`rm\` artifacts directly).
231
- - Always ask before resuming a refinement that crosses the trivial / medium / large boundary.
385
+ \`reviewer\` is multi-mode (\`code\` / \`text-review\` / \`integration\` / \`release\` / \`adversarial\`). \`security-reviewer\` is separate; invoke it when the diff or task touches authn / authz / secrets / supply chain / data exposure.
232
386
 
233
387
  ## Skills attached
234
388
 
235
- The following skills auto-trigger during this flow. Do not re-explain them; obey them.
389
+ These skills auto-trigger during \`/cc\`. Do not re-explain them; obey them.
236
390
 
237
- - **conversation-language** — always-on; reply in the user's language but never translate \`AC-N\`, \`D-N\`, \`F-N\`, slugs, paths, frontmatter keys, or hook output.
391
+ - **conversation-language** — always-on; reply in the user's language but never translate \`AC-N\`, \`D-N\`, \`F-N\`, slugs, paths, frontmatter keys, mode names, or hook output.
392
+ - **anti-slop** — always-on for any code-modifying step; bans redundant verification and environment shims.
393
+ - **triage-gate** — Hop 2 of every fresh \`/cc\`.
394
+ - **flow-resume** — when \`/cc\` is invoked with no task or with an active flow.
238
395
  - **plan-authoring** — on every edit to \`.cclaw/flows/<slug>/plan.md\`.
239
- - **ac-traceability** — before every commit and before push.
240
- - **tdd-cycle** — always-on while stage=build; enforces RED GREEN → REFACTOR per AC and the test-file-naming rule.
396
+ - **ac-traceability** — strict mode only; before every commit.
397
+ - **tdd-cycle** — always-on while stage=build; granularity scales with acMode.
241
398
  - **refinement** — when an existing plan match is detected.
242
- - **parallel-build** — when planner topology is \`parallel-build\`; enforces the 5-slice cap and worktree dispatch.
399
+ - **parallel-build** — strict mode + planner topology=parallel-build; enforces 5-slice cap and worktree dispatch.
243
400
  - **security-review** — when the diff touches sensitive surfaces.
244
401
  - **review-loop** — wraps every reviewer / security-reviewer invocation; runs the Concern Ledger + convergence detector.
245
402