cclaw-cli 0.1.1 → 0.2.1

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 (48) hide show
  1. package/dist/artifact-linter.d.ts +20 -0
  2. package/dist/artifact-linter.js +368 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +8 -2
  5. package/dist/config.d.ts +4 -4
  6. package/dist/config.js +56 -5
  7. package/dist/constants.d.ts +4 -4
  8. package/dist/constants.js +6 -3
  9. package/dist/content/autoplan.js +51 -4
  10. package/dist/content/contexts.d.ts +9 -0
  11. package/dist/content/contexts.js +65 -0
  12. package/dist/content/hooks.d.ts +6 -2
  13. package/dist/content/hooks.js +448 -16
  14. package/dist/content/meta-skill.js +26 -0
  15. package/dist/content/next-command.d.ts +9 -0
  16. package/dist/content/next-command.js +138 -0
  17. package/dist/content/observe.d.ts +5 -1
  18. package/dist/content/observe.js +506 -24
  19. package/dist/content/skills.js +126 -0
  20. package/dist/content/stage-schema.d.ts +7 -0
  21. package/dist/content/stage-schema.js +70 -12
  22. package/dist/content/subagents.js +33 -0
  23. package/dist/content/templates.d.ts +1 -0
  24. package/dist/content/templates.js +182 -77
  25. package/dist/content/utility-skills.d.ts +5 -1
  26. package/dist/content/utility-skills.js +208 -2
  27. package/dist/delegation.d.ts +21 -0
  28. package/dist/delegation.js +94 -0
  29. package/dist/doctor.d.ts +5 -1
  30. package/dist/doctor.js +274 -23
  31. package/dist/fs-utils.d.ts +10 -0
  32. package/dist/fs-utils.js +47 -0
  33. package/dist/gate-evidence.d.ts +26 -0
  34. package/dist/gate-evidence.js +157 -0
  35. package/dist/harness-adapters.js +2 -0
  36. package/dist/hook-schema.d.ts +6 -0
  37. package/dist/hook-schema.js +45 -0
  38. package/dist/hook-schemas/claude-hooks.v1.json +12 -0
  39. package/dist/hook-schemas/codex-hooks.v1.json +12 -0
  40. package/dist/hook-schemas/cursor-hooks.v1.json +15 -0
  41. package/dist/install.js +431 -16
  42. package/dist/policy.d.ts +5 -1
  43. package/dist/policy.js +52 -1
  44. package/dist/runs.js +8 -3
  45. package/dist/trace-matrix.d.ts +13 -0
  46. package/dist/trace-matrix.js +182 -0
  47. package/dist/types.d.ts +11 -1
  48. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { RUNTIME_ROOT } from "../constants.js";
1
2
  import { stageExamples } from "./examples.js";
2
3
  import { selfImprovementBlock } from "./learnings.js";
3
4
  import { nextCclawCommand, stageAutoSubagentDispatch, stageSchema } from "./stage-schema.js";
@@ -88,6 +89,16 @@ Before starting stage execution:
88
89
  3. Load upstream artifacts required by this stage:
89
90
  ${readLines}
90
91
  4. If canonical run artifact is missing, fallback to the \`.cclaw/artifacts/\` mirror and record that fallback.
92
+ `;
93
+ }
94
+ function whenNotToUseBlock(stage) {
95
+ const schema = stageSchema(stage);
96
+ if (!schema.whenNotToUse || schema.whenNotToUse.length === 0) {
97
+ return "";
98
+ }
99
+ return `## When Not to Use
100
+ ${schema.whenNotToUse.map((item) => `- ${item}`).join("\n")}
101
+
91
102
  `;
92
103
  }
93
104
  function autoSubagentDispatchBlock(stage) {
@@ -100,6 +111,9 @@ function autoSubagentDispatchBlock(stage) {
100
111
  return `| ${rule.agent} | ${rule.mode} | ${rule.when} | ${rule.purpose} | ${userGate} |`;
101
112
  })
102
113
  .join("\n");
114
+ const mandatory = stageSchema(stage).mandatoryDelegations;
115
+ const mandatoryList = mandatory.length > 0 ? mandatory.map((a) => `\`${a}\``).join(", ") : "(none — only proactive dispatch applies)";
116
+ const delegationLogRel = `${RUNTIME_ROOT}/runs/<activeRunId>/delegation-log.json`;
103
117
  return `## Automatic Subagent Dispatch
104
118
 
105
119
  Machine-only work should be delegated to specialist agents automatically according to the matrix below.
@@ -109,9 +123,117 @@ Machine-only work should be delegated to specialist agents automatically accordi
109
123
  ${rows}
110
124
 
111
125
  **Gate rule:** user interaction is required only for approval/override decisions. Do not ask the user to manually trigger machine-only specialist checks.
126
+
127
+ ## Delegation Enforcement
128
+
129
+ Before completing this stage, verify that ALL mandatory delegations are recorded. If using a harness that supports Task/delegate tools, each mandatory agent must have been invoked. If the harness does not support delegation, record a waiver with reason \`harness_limitation\` in the delegation log.
130
+
131
+ Mandatory agents for this stage: ${mandatoryList}. Stage transition is BLOCKED until all are **completed** or **explicitly waived** by the user (waived entries must name the agent and carry an explicit waiver reason).
132
+
133
+ On session stop or stage completion, the agent should write delegation entries to \`${delegationLogRel}\` for audit.
112
134
  `;
113
135
  }
114
136
  const VERIFICATION_STAGES = ["build", "review", "ship"];
137
+ function waveExecutionModeBlock(stage) {
138
+ const schema = stageSchema(stage);
139
+ if (!schema.waveExecutionAllowed) {
140
+ return "";
141
+ }
142
+ return `## Wave Execution Mode
143
+
144
+ After plan approval (**WAIT_FOR_CONFIRM** / \`plan_wait_for_confirm\` satisfied), process **all tasks in the current dependency wave** sequentially: **RED → GREEN → REFACTOR** per task, recording evidence per slice. **Stop** only on **BLOCKED**, a test failure that **requires user input**, or **wave completion** (every task in the wave has the required RED / GREEN / REFACTOR evidence per the plan artifact).
145
+
146
+ `;
147
+ }
148
+ function stageRequiresExplicitPause(schema) {
149
+ const pauseRules = [
150
+ /\bWAIT_FOR_CONFIRM\b/,
151
+ /Do NOT auto-advance/i,
152
+ /wait for explicit user approval/i,
153
+ /wait for explicit approval/i,
154
+ /explicitly pause/i
155
+ ];
156
+ const stageText = [
157
+ schema.hardGate,
158
+ ...schema.checklist,
159
+ ...schema.interactionProtocol,
160
+ ...schema.process,
161
+ ...schema.exitCriteria
162
+ ];
163
+ return stageText.some((line) => pauseRules.some((rule) => rule.test(line)));
164
+ }
165
+ function stageTransitionAutoAdvanceBlock(schema, nextCommand) {
166
+ if (schema.next === "done") {
167
+ return "";
168
+ }
169
+ if (stageRequiresExplicitPause(schema)) {
170
+ return `## Stage transition (autoAdvance)
171
+
172
+ If project config at \`${RUNTIME_ROOT}/config.yaml\` has \`autoAdvance: true\`, treat it as advisory only. This stage has an explicit pause or confirmation rule, so do NOT auto-advance after the gates pass. Suggest the next command (\`${nextCommand}\`) only after the required confirmation is satisfied, then wait.
173
+
174
+ `;
175
+ }
176
+ return `## Stage transition (autoAdvance)
177
+
178
+ If project config at \`${RUNTIME_ROOT}/config.yaml\` has \`autoAdvance: true\`, proceed to the next stage automatically after all gates pass for this stage. Otherwise, suggest the next command (\`${nextCommand}\`) and wait.
179
+
180
+ `;
181
+ }
182
+ function progressiveDisclosureBlock(stage, nextCommand) {
183
+ const schema = stageSchema(stage);
184
+ const stageSpecificRefs = {
185
+ brainstorm: [
186
+ "- `.cclaw/skills/autoplan/SKILL.md` — when the user wants brainstorm→plan orchestration in one flow",
187
+ "- `.cclaw/skills/learnings/SKILL.md` — to capture durable framing insights early"
188
+ ],
189
+ scope: [
190
+ "- `.cclaw/skills/autoplan/SKILL.md` — for coordinated premise challenge across early stages",
191
+ "- `.cclaw/skills/learnings/SKILL.md` — to persist rejected assumptions and constraints"
192
+ ],
193
+ design: [
194
+ "- `.cclaw/skills/performance/SKILL.md` — when architectural choices carry perf trade-offs",
195
+ "- `.cclaw/skills/security/SKILL.md` — when design choices touch auth/secrets/trust boundaries"
196
+ ],
197
+ spec: [
198
+ "- `.cclaw/skills/docs/SKILL.md` — for API/contract wording quality and ADR-style decision capture",
199
+ "- `.cclaw/skills/learnings/SKILL.md` — to preserve acceptance criteria traps and edge-case learnings"
200
+ ],
201
+ plan: [
202
+ "- `.cclaw/skills/subagent-dev/SKILL.md` — for specialist delegation prompts by task slice",
203
+ "- `.cclaw/skills/parallel-dispatch/SKILL.md` — for multi-agent review planning and reconciliation setup"
204
+ ],
205
+ test: [
206
+ "- `.cclaw/skills/debugging/SKILL.md` — when RED behavior is unclear or flakes appear",
207
+ "- `.cclaw/skills/subagent-dev/SKILL.md` — for machine-only test-slice delegation"
208
+ ],
209
+ build: [
210
+ "- `.cclaw/skills/debugging/SKILL.md` — for root-cause workflow when implementation fails tests",
211
+ "- `.cclaw/skills/performance/SKILL.md` — when implementation choices impact latency/throughput"
212
+ ],
213
+ review: [
214
+ "- `.cclaw/skills/security/SKILL.md` — mandatory lens for exploitable risk detection",
215
+ "- `.cclaw/skills/parallel-dispatch/SKILL.md` — for review-army dispatch and reconciliation discipline"
216
+ ],
217
+ ship: [
218
+ "- `.cclaw/skills/ci-cd/SKILL.md` — for release gates, pipeline health, and deployment guardrails",
219
+ "- `.cclaw/skills/docs/SKILL.md` — for release docs, migration notes, and ADR/public API updates"
220
+ ]
221
+ };
222
+ return `## Progressive Disclosure
223
+
224
+ ### Depth
225
+ - Primary stage procedure (this file): \`.cclaw/skills/${schema.skillFolder}/SKILL.md\`
226
+ - Orchestrator contract (gate language and handoff): \`.cclaw/commands/${stage}.md\`
227
+ - Artifact structure baseline: \`.cclaw/templates/${schema.artifactFile}\`
228
+ - Runtime state truth source: \`.cclaw/state/flow-state.json\` + \`.cclaw/runs/<activeRunId>/\`
229
+
230
+ ### See also
231
+ - Meta routing and activation rules: \`.cclaw/skills/using-cclaw/SKILL.md\`
232
+ - Session continuity and checkpoint behavior: \`.cclaw/skills/session/SKILL.md\`
233
+ ${stageSpecificRefs[stage].join("\n")}
234
+ - Next-stage handoff command: \`${nextCommand}\`
235
+ `;
236
+ }
115
237
  function verificationBlock(stage) {
116
238
  if (!VERIFICATION_STAGES.includes(stage))
117
239
  return "";
@@ -192,6 +314,7 @@ ${schema.purpose}
192
314
  ## When to Use
193
315
  ${schema.whenToUse.map((item) => `- ${item}`).join("\n")}
194
316
 
317
+ ${whenNotToUseBlock(stage)}
195
318
  ## Inputs
196
319
  ${schema.inputs.length > 0 ? schema.inputs.map((item) => `- ${item}`).join("\n") : "- (first stage — no required inputs)"}
197
320
 
@@ -218,6 +341,7 @@ ${cognitivePatternsList(stage)}
218
341
  ## Interaction Protocol
219
342
  ${schema.interactionProtocol.map((item, i) => `${i + 1}. ${item}`).join("\n")}
220
343
 
344
+ ${waveExecutionModeBlock(stage)}
221
345
  ## Required Gates
222
346
  ${gateList}
223
347
 
@@ -248,6 +372,8 @@ ${completionStatusBlock(stage)}
248
372
  ## Verification
249
373
  ${schema.exitCriteria.map((item) => `- [ ] ${item}`).join("\n")}
250
374
 
375
+ ${stageTransitionAutoAdvanceBlock(schema, nextCommand)}
376
+ ${progressiveDisclosureBlock(stage, nextCommand)}
251
377
  ${selfImprovementBlock(stage)}
252
378
  ## Handoff
253
379
  - Next command: ${nextCommand}
@@ -45,6 +45,7 @@ export interface StageSchema {
45
45
  hardGate: string;
46
46
  purpose: string;
47
47
  whenToUse: string[];
48
+ whenNotToUse: string[];
48
49
  interactionProtocol: string[];
49
50
  process: string[];
50
51
  requiredGates: StageGate[];
@@ -68,7 +69,13 @@ export interface StageSchema {
68
69
  artifactValidation: ArtifactValidation[];
69
70
  namedAntiPattern?: NamedAntiPattern;
70
71
  decisionRecordFormat?: string;
72
+ /** When true, stage skill includes wave auto-execute guidance (test/build). */
73
+ waveExecutionAllowed?: boolean;
74
+ /** Agent names that MUST be dispatched (or waived) before stage transition — derived from mandatory auto-subagent rows. */
75
+ mandatoryDelegations: string[];
71
76
  }
77
+ /** Transition guard: agents with `mode: "mandatory"` in auto-subagent dispatch for this stage. */
78
+ export declare function mandatoryDelegationsForStage(stage: FlowStage): string[];
72
79
  export declare function stageSchema(stage: FlowStage): StageSchema;
73
80
  export declare function orderedStageSchemas(): StageSchema[];
74
81
  export declare function stageGateIds(stage: FlowStage): string[];
@@ -1,7 +1,4 @@
1
1
  import { COMMAND_FILE_ORDER } from "../constants.js";
2
- // ---------------------------------------------------------------------------
3
- // BRAINSTORM — reference: superpowers brainstorming
4
- // ---------------------------------------------------------------------------
5
2
  const BRAINSTORM = {
6
3
  stage: "brainstorm",
7
4
  skillFolder: "brainstorming",
@@ -14,6 +11,11 @@ const BRAINSTORM = {
14
11
  "Requirements are ambiguous or solution path is unclear",
15
12
  "Before any implementation-stage command"
16
13
  ],
14
+ whenNotToUse: [
15
+ "An approved design, spec, and plan already exist and work is in execution stages",
16
+ "The request is strictly branch finalization or release handoff work",
17
+ "The task is purely retrospective after ship with no new design decisions needed"
18
+ ],
17
19
  checklist: [
18
20
  "Explore project context — check files, docs, recent commits, existing behavior.",
19
21
  "Assess scope — if the request describes multiple independent subsystems, flag for decomposition before detailed questions.",
@@ -144,6 +146,11 @@ const SCOPE = {
144
146
  "Before architecture/design lock-in",
145
147
  "When ambition vs feasibility trade-off is unclear"
146
148
  ],
149
+ whenNotToUse: [
150
+ "Brainstorm has not been approved yet",
151
+ "Scope boundaries are already locked and user requested no scope changes",
152
+ "The work is a pure implementation or debugging pass within existing scope"
153
+ ],
147
154
  checklist: [
148
155
  "Prime Directives — Zero silent failures (every failure mode visible). Every error has a name (not 'handle errors' — name the exception). Every data flow has four paths: happy, nil input, upstream error, downstream timeout. Observability is a scope deliverable, not a post-launch add-on.",
149
156
  "Premise Challenge — Is this the right problem? Could a different framing yield a simpler or more impactful solution? What happens if we do nothing? What are we optimizing for — speed, quality, cost, user experience?",
@@ -319,6 +326,11 @@ const DESIGN = {
319
326
  "Before writing final spec and execution plan",
320
327
  "When architecture risks need explicit treatment"
321
328
  ],
329
+ whenNotToUse: [
330
+ "Scope mode and boundaries are still unresolved",
331
+ "The change is docs-only or metadata-only with no architecture impact",
332
+ "Implementation has already started and requires review instead of design lock"
333
+ ],
322
334
  checklist: [
323
335
  "Design Doc Check — read existing design docs, scope artifact, brainstorm artifact. If a design doc exists that covers this area, check for 'Supersedes:' and use the latest. Use upstream artifacts as source of truth.",
324
336
  "Step 0: Scope Challenge — what existing code solves sub-problems? Minimum change set? Complexity check: 8+ files or 2+ new services = complexity smell → flag for possible scope reduction.",
@@ -526,6 +538,11 @@ const SPEC = {
526
538
  "Before planning and implementation",
527
539
  "When acceptance criteria must be measurable"
528
540
  ],
541
+ whenNotToUse: [
542
+ "Design decisions are still unresolved or disputed",
543
+ "The task is implementation-only cleanup with unchanged behavior",
544
+ "You still need to challenge scope rather than author requirements"
545
+ ],
529
546
  checklist: [
530
547
  "Read upstream — load design artifact and scope contract. Cross-reference architecture decisions.",
531
548
  "Define measurable acceptance criteria — each criterion must be observable and falsifiable. No vague adjectives.",
@@ -640,6 +657,11 @@ const PLAN = {
640
657
  "Before writing tests or implementation",
641
658
  "When delivery path and dependency order are needed"
642
659
  ],
660
+ whenNotToUse: [
661
+ "Specification is unapproved or lacks measurable acceptance criteria",
662
+ "Execution is already in test/build stages with active slice evidence",
663
+ "The request is only release packaging with no task decomposition needed"
664
+ ],
643
665
  checklist: [
644
666
  "Read upstream — load spec, design, and scope artifacts. Cross-reference acceptance criteria.",
645
667
  "Build dependency graph — identify task ordering, parallel opportunities, and blocking dependencies.",
@@ -754,6 +776,11 @@ const TEST = {
754
776
  "Before /cc-build",
755
777
  "For every behavior change in scope"
756
778
  ],
779
+ whenNotToUse: [
780
+ "Plan approval is still pending WAIT_FOR_CONFIRM",
781
+ "The change is docs-only and does not alter behavior",
782
+ "GREEN implementation has started before RED evidence"
783
+ ],
757
784
  checklist: [
758
785
  "Select plan slice — pick one task from the plan. Do not batch multiple tasks.",
759
786
  "Map to acceptance criterion — identify the specific spec criterion this test proves.",
@@ -838,7 +865,8 @@ const TEST = {
838
865
  { section: "RED Evidence", required: true, validationRule: "Failing test output captured per slice." },
839
866
  { section: "Acceptance Mapping", required: true, validationRule: "Each RED test links to a plan task and spec criterion." },
840
867
  { section: "Failure Analysis", required: true, validationRule: "Failure reason matches expected missing behavior." }
841
- ]
868
+ ],
869
+ waveExecutionAllowed: true
842
870
  };
843
871
  // ---------------------------------------------------------------------------
844
872
  // BUILD — TDD GREEN + REFACTOR stage
@@ -855,6 +883,11 @@ const BUILD = {
855
883
  "For one accepted plan slice at a time",
856
884
  "Before review stage"
857
885
  ],
886
+ whenNotToUse: [
887
+ "RED evidence is missing or failure reason is unverified",
888
+ "Multiple unrelated slices are being merged into one build pass",
889
+ "The stage intent is review/ship sign-off rather than implementation"
890
+ ],
858
891
  checklist: [
859
892
  "Minimal GREEN change — implement the smallest code change that makes the RED tests pass. No extra features.",
860
893
  "Run full suite — execute ALL tests, not just the ones you wrote. The full suite must be GREEN.",
@@ -940,7 +973,8 @@ const BUILD = {
940
973
  { section: "GREEN Evidence", required: true, validationRule: "Full suite pass output captured." },
941
974
  { section: "REFACTOR Notes", required: true, validationRule: "What changed, why, behavior preservation confirmed." },
942
975
  { section: "Traceability", required: true, validationRule: "Plan task ID and spec criterion linked." }
943
- ]
976
+ ],
977
+ waveExecutionAllowed: true
944
978
  };
945
979
  // ---------------------------------------------------------------------------
946
980
  // REVIEW — reference: superpowers code-review + gstack /review
@@ -957,6 +991,11 @@ const REVIEW = {
957
991
  "Before any ship action",
958
992
  "When release risk must be assessed explicitly"
959
993
  ],
994
+ whenNotToUse: [
995
+ "There is no implementation diff to review",
996
+ "Build stage evidence is missing or stale",
997
+ "The goal is direct release execution without layered quality checks"
998
+ ],
960
999
  checklist: [
961
1000
  "Diff Scope — Run `git diff` against base branch. If no diff, exit early with APPROVED (no changes to review). Scope the review to changed files unless blast-radius analysis requires wider inspection.",
962
1001
  "Change-Size Check — ~100 lines = normal. ~300 lines = consider splitting. ~1000+ lines = strongly recommend stacked PRs. Flag large diffs to the user.",
@@ -1136,6 +1175,7 @@ const REVIEW = {
1136
1175
  { section: "Layer 1 Verdict", required: true, validationRule: "Per-criterion pass/fail with references." },
1137
1176
  { section: "Layer 2 Findings", required: true, validationRule: "Each finding has severity, description, and resolution status." },
1138
1177
  { section: "Review Army Contract", required: true, validationRule: "Structured findings include id/severity/confidence/fingerprint/reportedBy/status with dedup reconciliation summary." },
1178
+ { section: "Review Readiness Dashboard", required: true, validationRule: "At least 4 readiness checklist lines including blocker and recommendation status." },
1139
1179
  { section: "Severity Summary", required: true, validationRule: "Counts: N critical, N important, N suggestion." },
1140
1180
  { section: "Final Verdict", required: true, validationRule: "Exactly one of: APPROVED, APPROVED_WITH_CONCERNS, BLOCKED." }
1141
1181
  ],
@@ -1159,6 +1199,11 @@ const SHIP = {
1159
1199
  "Before creating PR/merge/final branch action",
1160
1200
  "When release notes and rollback plan are required"
1161
1201
  ],
1202
+ whenNotToUse: [
1203
+ "Review verdict is BLOCKED or unresolved critical findings remain",
1204
+ "Preflight checks cannot run and no approved exception exists",
1205
+ "The request is still design/spec/implementation work, not release handoff"
1206
+ ],
1162
1207
  checklist: [
1163
1208
  "Validate upstream gates — verify review verdict is APPROVED or APPROVED_WITH_CONCERNS. If BLOCKED, stop immediately.",
1164
1209
  "Run preflight checks — tests pass, build succeeds, linter clean, type-check clean, no uncommitted changes. Every check must produce fresh output in this message.",
@@ -1167,14 +1212,14 @@ const SHIP = {
1167
1212
  "Generate release notes — summarize what changed, why, and what it affects. Reference spec criteria. Include: breaking changes, new dependencies, migration steps if any.",
1168
1213
  "Write rollback plan — trigger conditions (what tells you it is broken), rollback steps (exact commands/git operations), and verification (how to confirm rollback worked).",
1169
1214
  "Monitoring checklist — what should be watched after deploy? Error rates, latency, key business metrics. If no monitoring exists, flag it as a risk.",
1170
- "Select finalization mode — exactly ONE of: (A) merge to main locally, (B) create PR with description, (C) keep branch for later, (D) discard branch. For discard: list what will be deleted, require typed confirmation.",
1215
+ "Select finalization mode — exactly ONE enum: (A) FINALIZE_MERGE_LOCAL, (B) FINALIZE_OPEN_PR, (C) FINALIZE_KEEP_BRANCH, (D) FINALIZE_DISCARD_BRANCH. For discard: list what will be deleted, require typed confirmation.",
1171
1216
  "Execute finalization — perform the selected action. For merge: verify clean merge. For PR: include structured body (summary, test plan, rollback). For discard: verify deletion.",
1172
1217
  "Worktree cleanup — if using git worktrees, clean up the worktree after merge/discard. Keep it only for 'keep branch' mode."
1173
1218
  ],
1174
1219
  interactionProtocol: [
1175
1220
  "Run preflight checks before any release action.",
1176
1221
  "Document release notes and rollback plan explicitly.",
1177
- "For finalization mode: use the Decision Protocol — present modes as labeled options (A/B/C) with consequences, mark one as (recommended), use AskQuestion/AskUserQuestion tool when available.",
1222
+ "For finalization mode: use the Decision Protocol — present modes as labeled options (A/B/C/D) with consequences, mark one as (recommended), use AskQuestion/AskUserQuestion tool when available.",
1178
1223
  "Do not proceed if critical blockers remain from review.",
1179
1224
  "Execute the selected finalization action and verify."
1180
1225
  ],
@@ -1182,7 +1227,7 @@ const SHIP = {
1182
1227
  "Validate review and test gates.",
1183
1228
  "Run preflight: build, test, lint, uncommitted-changes check.",
1184
1229
  "Generate release notes and rollback procedure.",
1185
- "Choose one finalization mode: merge, PR, keep branch, discard branch.",
1230
+ "Choose one finalization enum: FINALIZE_MERGE_LOCAL, FINALIZE_OPEN_PR, FINALIZE_KEEP_BRANCH, or FINALIZE_DISCARD_BRANCH.",
1186
1231
  "Execute finalization action.",
1187
1232
  "Write ship artifact with decision, rationale, and execution result."
1188
1233
  ],
@@ -1198,7 +1243,7 @@ const SHIP = {
1198
1243
  "Artifact written to `.cclaw/artifacts/08-ship.md`.",
1199
1244
  "Release notes section is complete.",
1200
1245
  "Rollback section includes trigger conditions, steps, and verification.",
1201
- "Finalization mode shows exactly one selected.",
1246
+ "Finalization section shows exactly one selected enum token.",
1202
1247
  "Execution result documented."
1203
1248
  ],
1204
1249
  inputs: ["review verdict", "test/build outputs", "release context"],
@@ -1238,7 +1283,10 @@ const SHIP = {
1238
1283
  "Pre-Ship Checks",
1239
1284
  "Release Notes",
1240
1285
  "Rollback Plan",
1241
- "merge / PR / keep branch / discard branch"
1286
+ "FINALIZE_MERGE_LOCAL",
1287
+ "FINALIZE_OPEN_PR",
1288
+ "FINALIZE_KEEP_BRANCH",
1289
+ "FINALIZE_DISCARD_BRANCH"
1242
1290
  ],
1243
1291
  artifactFile: "08-ship.md",
1244
1292
  next: "done",
@@ -1283,7 +1331,7 @@ const SHIP = {
1283
1331
  { section: "Release Notes", required: true, validationRule: "What changed, why, impact. References spec criteria. Breaking changes flagged." },
1284
1332
  { section: "Rollback Plan", required: true, validationRule: "Trigger conditions, rollback steps (exact commands), verification steps." },
1285
1333
  { section: "Monitoring", required: false, validationRule: "If applicable: what metrics/logs to watch post-deploy. Risk note if no monitoring." },
1286
- { section: "Finalization", required: true, validationRule: "Exactly one mode selected. Execution result documented. Worktree cleaned if applicable." }
1334
+ { section: "Finalization", required: true, validationRule: "Exactly one finalization enum token selected. Execution result documented. Worktree cleaned if applicable." }
1287
1335
  ]
1288
1336
  };
1289
1337
  // ---------------------------------------------------------------------------
@@ -1418,8 +1466,18 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
1418
1466
  }
1419
1467
  ]
1420
1468
  };
1469
+ /** Transition guard: agents with `mode: "mandatory"` in auto-subagent dispatch for this stage. */
1470
+ export function mandatoryDelegationsForStage(stage) {
1471
+ return STAGE_AUTO_SUBAGENT_DISPATCH[stage]
1472
+ .filter((d) => d.mode === "mandatory")
1473
+ .map((d) => d.agent);
1474
+ }
1421
1475
  export function stageSchema(stage) {
1422
- return STAGE_SCHEMA_MAP[stage];
1476
+ const base = STAGE_SCHEMA_MAP[stage];
1477
+ return {
1478
+ ...base,
1479
+ mandatoryDelegations: mandatoryDelegationsForStage(stage)
1480
+ };
1423
1481
  }
1424
1482
  export function orderedStageSchemas() {
1425
1483
  return COMMAND_FILE_ORDER.map((stage) => stageSchema(stage));
@@ -40,6 +40,25 @@ For cclaw flow stages, machine-only specialist work should auto-dispatch without
40
40
 
41
41
  Human input remains mandatory only at explicit approval gates (plan approval, user challenge resolution, release finalization mode).
42
42
 
43
+ ## Model & Harness Routing Notes
44
+
45
+ ### Harness routing
46
+
47
+ | Harness | Delegation tool | Structured ask tool | Routing note |
48
+ |---|---|---|---|
49
+ | Claude | Task/delegate | AskUserQuestion | Preferred for rich multi-step delegation + explicit approvals. |
50
+ | Cursor | Task | AskQuestion | Use option-based asks for mode/waiver decisions; keep subagent payloads concise. |
51
+ | Codex | Task (if available) | None native | Use numbered choices in chat for approvals; keep prompts fully self-contained. |
52
+ | OpenCode | Task (if available) | None native | Log delegation outcomes in artifacts/state explicitly; do not assume built-in ask workflows. |
53
+
54
+ If delegation tooling is unavailable in the active harness, run the same controller protocol in-thread and record a delegation waiver with reason \`harness_limitation\`.
55
+
56
+ ### Model routing
57
+
58
+ - **Use a faster model** for bounded, deterministic tasks (single slice implementation, mechanical refactors, straightforward lint/test fixes).
59
+ - **Use a more capable model** for high-ambiguity or high-risk analysis (security review, architecture conflicts, spec contradiction resolution).
60
+ - During review-heavy stages, prefer **mixed routing**: faster first-pass triage + escalate only high-severity/low-confidence findings.
61
+
43
62
  ## HARD-GATE
44
63
 
45
64
  **Never dispatch a subagent without a concrete, self-contained task description pasted into the prompt. Do not pass file references the subagent must read to understand its task.**
@@ -241,6 +260,20 @@ Implementation that touches shared source trees must remain **sequential** unles
241
260
  - **Multi-specialist review** where reviewers must not contaminate each other’s first impressions.
242
261
  - **Parallel test/log analysis** across unrelated failures (distinct subsystems).
243
262
 
263
+ ## Model & Harness Routing Notes
264
+
265
+ ### Harness routing
266
+
267
+ - Launch all parallel Task calls in a **single message** only on harnesses that support concurrent delegation.
268
+ - If the harness cannot safely fan out parallel delegations, run lenses sequentially and preserve the same reconciliation schema.
269
+ - For harnesses without structured ask tools, put reconciliation decisions as explicit numbered options in chat and wait for user selection on blockers.
270
+
271
+ ### Model routing
272
+
273
+ - **Faster model:** broad first-pass scans, duplicate detection, low-risk normalization.
274
+ - **More capable model:** conflict reconciliation, architectural contradiction analysis, security-critical tie-breaks.
275
+ - Escalation trigger: any finding that is \`Critical\`, contradictory across specialists, or confidence <5 with potential ship impact.
276
+
244
277
  ## Dispatch Protocol
245
278
 
246
279
  1. **Identify independent problem domains** (no file overlap; no shared mutable working assumptions).
@@ -1,3 +1,4 @@
1
1
  export declare const ARTIFACT_TEMPLATES: Record<string, string>;
2
2
  export declare const RULEBOOK_MARKDOWN = "# Cclaw Rulebook\n\n## MUST_ALWAYS\n- Follow flow order: brainstorm -> scope -> design -> spec -> plan -> test -> build -> review -> ship\n- Require explicit user confirmation after /plan before /test or /build\n- Keep evidence artifacts in `.cclaw/artifacts/`\n- Enforce RED before GREEN in TDD\n- Run two-layer review (spec_compliance and code_quality) before ship\n- Validate all inputs before processing \u2014 never trust external data without sanitization\n- Prefer immutable data patterns and pure functions where the language supports them\n- Follow existing repo conventions, patterns, and directory structure \u2014 match the codebase\n- Verify claims with fresh evidence: \"tests pass\" requires running tests in this message\n- Use conventional commits: `type(scope): description` (feat, fix, refactor, test, docs, chore)\n\n## MUST_NEVER\n- Skip /test and jump directly to /build\n- Ship with critical review findings\n- Start implementation during /brainstorm\n- Modify generated cclaw files manually when CLI can regenerate them\n- Commit `.cclaw/` or generated shim files\n- Expose secrets, tokens, API keys, or absolute system paths in agent output\n- Duplicate existing functionality without explicit justification \u2014 search before building\n- Bypass security checks, linting hooks, or type checking to \"move faster\"\n- Claim success (\"Done,\" \"All good,\" \"Tests pass\") without running verification in this message\n- Make changes outside the blast radius of the current task without user consent\n\n## DELEGATION\nWhen a task requires specialist knowledge (security audit, performance profiling, database review),\ndelegate to a specialized agent or skill if the harness supports it. The primary agent should:\n1. Identify the specialist domain\n2. Provide focused context (relevant files, the specific concern)\n3. Evaluate the specialist output before acting on it \u2014 do not blindly apply recommendations\n";
3
+ export declare const CURSOR_WORKFLOW_RULE_MDC = "---\ndescription: cclaw workflow guardrails for Cursor agent sessions\nglobs:\n - \"**/*\"\nalwaysApply: true\n---\n\n<!-- cclaw-managed-cursor-workflow-rule -->\n\n# Cclaw Workflow Guardrails\n\n- Follow stage order: brainstorm -> scope -> design -> spec -> plan -> test -> build -> review -> ship.\n- Read `.cclaw/state/flow-state.json` before acting; continue from current stage when active.\n- Use `/cc-next` only after required gates pass; never bypass explicit pause/approval rules.\n- Keep evidence in `.cclaw/artifacts/` and canonical run copies in `.cclaw/runs/<activeRunId>/artifacts/`.\n- For machine-only checks in design/plan/test/build/review/ship, dispatch required specialists automatically when tooling supports it.\n- Ask for user input only at explicit approval gates (scope mode, plan approval, user challenge resolution, ship finalization).\n- Treat `.cclaw/skills/using-cclaw/SKILL.md` as routing source of truth; load contextual utility skills only when their triggers apply.\n";
3
4
  export declare function buildRulesJson(): Record<string, unknown>;