cclaw-cli 7.7.1 → 8.1.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 (284) hide show
  1. package/README.md +211 -134
  2. package/dist/artifact-frontmatter.d.ts +51 -0
  3. package/dist/artifact-frontmatter.js +131 -0
  4. package/dist/artifact-paths.d.ts +7 -27
  5. package/dist/artifact-paths.js +20 -249
  6. package/dist/cancel.d.ts +16 -0
  7. package/dist/cancel.js +66 -0
  8. package/dist/cli.d.ts +2 -27
  9. package/dist/cli.js +107 -511
  10. package/dist/compound.d.ts +26 -0
  11. package/dist/compound.js +96 -0
  12. package/dist/config.d.ts +14 -51
  13. package/dist/config.js +23 -359
  14. package/dist/constants.d.ts +11 -18
  15. package/dist/constants.js +19 -106
  16. package/dist/content/antipatterns.d.ts +1 -0
  17. package/dist/content/antipatterns.js +109 -0
  18. package/dist/content/artifact-templates.d.ts +10 -0
  19. package/dist/content/artifact-templates.js +550 -0
  20. package/dist/content/cancel-command.d.ts +2 -2
  21. package/dist/content/cancel-command.js +25 -17
  22. package/dist/content/core-agents.d.ts +9 -233
  23. package/dist/content/core-agents.js +39 -768
  24. package/dist/content/decision-protocol.d.ts +1 -12
  25. package/dist/content/decision-protocol.js +27 -20
  26. package/dist/content/examples.d.ts +8 -42
  27. package/dist/content/examples.js +293 -425
  28. package/dist/content/idea-command.d.ts +2 -0
  29. package/dist/content/idea-command.js +38 -0
  30. package/dist/content/iron-laws.d.ts +4 -138
  31. package/dist/content/iron-laws.js +18 -197
  32. package/dist/content/meta-skill.d.ts +1 -3
  33. package/dist/content/meta-skill.js +57 -134
  34. package/dist/content/node-hooks.d.ts +12 -8
  35. package/dist/content/node-hooks.js +188 -838
  36. package/dist/content/recovery.d.ts +8 -0
  37. package/dist/content/recovery.js +179 -0
  38. package/dist/content/reference-patterns.d.ts +4 -13
  39. package/dist/content/reference-patterns.js +260 -389
  40. package/dist/content/research-playbooks.d.ts +8 -8
  41. package/dist/content/research-playbooks.js +108 -121
  42. package/dist/content/review-loop.d.ts +6 -192
  43. package/dist/content/review-loop.js +29 -731
  44. package/dist/content/skills.d.ts +8 -38
  45. package/dist/content/skills.js +681 -732
  46. package/dist/content/specialist-prompts/architect.d.ts +1 -0
  47. package/dist/content/specialist-prompts/architect.js +225 -0
  48. package/dist/content/specialist-prompts/brainstormer.d.ts +1 -0
  49. package/dist/content/specialist-prompts/brainstormer.js +168 -0
  50. package/dist/content/specialist-prompts/index.d.ts +2 -0
  51. package/dist/content/specialist-prompts/index.js +14 -0
  52. package/dist/content/specialist-prompts/planner.d.ts +1 -0
  53. package/dist/content/specialist-prompts/planner.js +182 -0
  54. package/dist/content/specialist-prompts/reviewer.d.ts +1 -0
  55. package/dist/content/specialist-prompts/reviewer.js +193 -0
  56. package/dist/content/specialist-prompts/security-reviewer.d.ts +1 -0
  57. package/dist/content/specialist-prompts/security-reviewer.js +133 -0
  58. package/dist/content/specialist-prompts/slice-builder.d.ts +1 -0
  59. package/dist/content/specialist-prompts/slice-builder.js +232 -0
  60. package/dist/content/stage-playbooks.d.ts +8 -0
  61. package/dist/content/stage-playbooks.js +404 -0
  62. package/dist/content/start-command.d.ts +2 -12
  63. package/dist/content/start-command.js +221 -207
  64. package/dist/flow-state.d.ts +21 -178
  65. package/dist/flow-state.js +67 -170
  66. package/dist/fs-utils.d.ts +6 -26
  67. package/dist/fs-utils.js +29 -162
  68. package/dist/gitignore.d.ts +2 -1
  69. package/dist/gitignore.js +51 -34
  70. package/dist/harness-detect.d.ts +10 -0
  71. package/dist/harness-detect.js +29 -0
  72. package/dist/harness-prompt.d.ts +26 -0
  73. package/dist/harness-prompt.js +142 -0
  74. package/dist/install.d.ts +35 -15
  75. package/dist/install.js +238 -1347
  76. package/dist/knowledge-store.d.ts +19 -163
  77. package/dist/knowledge-store.js +56 -590
  78. package/dist/logger.d.ts +8 -3
  79. package/dist/logger.js +13 -4
  80. package/dist/orchestrator-routing.d.ts +29 -0
  81. package/dist/orchestrator-routing.js +156 -0
  82. package/dist/run-persistence.d.ts +7 -118
  83. package/dist/run-persistence.js +29 -845
  84. package/dist/runtime/run-hook.entry.d.ts +1 -3
  85. package/dist/runtime/run-hook.entry.js +19 -4
  86. package/dist/runtime/run-hook.mjs +13 -1024
  87. package/dist/types.d.ts +25 -261
  88. package/dist/types.js +8 -36
  89. package/package.json +6 -3
  90. package/dist/artifact-linter/brainstorm.d.ts +0 -2
  91. package/dist/artifact-linter/brainstorm.js +0 -353
  92. package/dist/artifact-linter/design.d.ts +0 -18
  93. package/dist/artifact-linter/design.js +0 -444
  94. package/dist/artifact-linter/findings-dedup.d.ts +0 -56
  95. package/dist/artifact-linter/findings-dedup.js +0 -232
  96. package/dist/artifact-linter/plan.d.ts +0 -2
  97. package/dist/artifact-linter/plan.js +0 -826
  98. package/dist/artifact-linter/review-army.d.ts +0 -49
  99. package/dist/artifact-linter/review-army.js +0 -520
  100. package/dist/artifact-linter/review.d.ts +0 -2
  101. package/dist/artifact-linter/review.js +0 -113
  102. package/dist/artifact-linter/scope.d.ts +0 -2
  103. package/dist/artifact-linter/scope.js +0 -158
  104. package/dist/artifact-linter/shared.d.ts +0 -637
  105. package/dist/artifact-linter/shared.js +0 -2163
  106. package/dist/artifact-linter/ship.d.ts +0 -2
  107. package/dist/artifact-linter/ship.js +0 -250
  108. package/dist/artifact-linter/spec.d.ts +0 -2
  109. package/dist/artifact-linter/spec.js +0 -176
  110. package/dist/artifact-linter/tdd.d.ts +0 -118
  111. package/dist/artifact-linter/tdd.js +0 -1404
  112. package/dist/artifact-linter.d.ts +0 -15
  113. package/dist/artifact-linter.js +0 -517
  114. package/dist/codex-feature-flag.d.ts +0 -58
  115. package/dist/codex-feature-flag.js +0 -193
  116. package/dist/content/closeout-guidance.d.ts +0 -14
  117. package/dist/content/closeout-guidance.js +0 -44
  118. package/dist/content/diff-command.d.ts +0 -1
  119. package/dist/content/diff-command.js +0 -43
  120. package/dist/content/harness-doc.d.ts +0 -1
  121. package/dist/content/harness-doc.js +0 -65
  122. package/dist/content/hook-events.d.ts +0 -9
  123. package/dist/content/hook-events.js +0 -23
  124. package/dist/content/hook-manifest.d.ts +0 -81
  125. package/dist/content/hook-manifest.js +0 -156
  126. package/dist/content/hooks.d.ts +0 -11
  127. package/dist/content/hooks.js +0 -1972
  128. package/dist/content/idea.d.ts +0 -60
  129. package/dist/content/idea.js +0 -416
  130. package/dist/content/language-policy.d.ts +0 -2
  131. package/dist/content/language-policy.js +0 -13
  132. package/dist/content/learnings.d.ts +0 -6
  133. package/dist/content/learnings.js +0 -141
  134. package/dist/content/observe.d.ts +0 -19
  135. package/dist/content/observe.js +0 -86
  136. package/dist/content/opencode-plugin.d.ts +0 -1
  137. package/dist/content/opencode-plugin.js +0 -635
  138. package/dist/content/review-prompts.d.ts +0 -1
  139. package/dist/content/review-prompts.js +0 -104
  140. package/dist/content/runtime-shared-snippets.d.ts +0 -8
  141. package/dist/content/runtime-shared-snippets.js +0 -80
  142. package/dist/content/session-hooks.d.ts +0 -7
  143. package/dist/content/session-hooks.js +0 -107
  144. package/dist/content/skills-elicitation.d.ts +0 -1
  145. package/dist/content/skills-elicitation.js +0 -167
  146. package/dist/content/stage-command.d.ts +0 -2
  147. package/dist/content/stage-command.js +0 -17
  148. package/dist/content/stage-schema.d.ts +0 -117
  149. package/dist/content/stage-schema.js +0 -955
  150. package/dist/content/stages/_lint-metadata/index.d.ts +0 -2
  151. package/dist/content/stages/_lint-metadata/index.js +0 -97
  152. package/dist/content/stages/brainstorm.d.ts +0 -2
  153. package/dist/content/stages/brainstorm.js +0 -184
  154. package/dist/content/stages/design.d.ts +0 -2
  155. package/dist/content/stages/design.js +0 -288
  156. package/dist/content/stages/index.d.ts +0 -8
  157. package/dist/content/stages/index.js +0 -11
  158. package/dist/content/stages/plan.d.ts +0 -2
  159. package/dist/content/stages/plan.js +0 -191
  160. package/dist/content/stages/review.d.ts +0 -2
  161. package/dist/content/stages/review.js +0 -240
  162. package/dist/content/stages/schema-types.d.ts +0 -203
  163. package/dist/content/stages/schema-types.js +0 -1
  164. package/dist/content/stages/scope.d.ts +0 -2
  165. package/dist/content/stages/scope.js +0 -254
  166. package/dist/content/stages/ship.d.ts +0 -2
  167. package/dist/content/stages/ship.js +0 -159
  168. package/dist/content/stages/spec.d.ts +0 -2
  169. package/dist/content/stages/spec.js +0 -170
  170. package/dist/content/stages/tdd.d.ts +0 -4
  171. package/dist/content/stages/tdd.js +0 -273
  172. package/dist/content/state-contracts.d.ts +0 -1
  173. package/dist/content/state-contracts.js +0 -63
  174. package/dist/content/status-command.d.ts +0 -4
  175. package/dist/content/status-command.js +0 -109
  176. package/dist/content/subagent-context-skills.d.ts +0 -4
  177. package/dist/content/subagent-context-skills.js +0 -279
  178. package/dist/content/subagents.d.ts +0 -3
  179. package/dist/content/subagents.js +0 -997
  180. package/dist/content/templates.d.ts +0 -26
  181. package/dist/content/templates.js +0 -1692
  182. package/dist/content/track-render-context.d.ts +0 -18
  183. package/dist/content/track-render-context.js +0 -53
  184. package/dist/content/tree-command.d.ts +0 -1
  185. package/dist/content/tree-command.js +0 -64
  186. package/dist/content/utility-skills.d.ts +0 -30
  187. package/dist/content/utility-skills.js +0 -160
  188. package/dist/content/view-command.d.ts +0 -2
  189. package/dist/content/view-command.js +0 -92
  190. package/dist/delegation.d.ts +0 -649
  191. package/dist/delegation.js +0 -1539
  192. package/dist/early-loop.d.ts +0 -70
  193. package/dist/early-loop.js +0 -302
  194. package/dist/execution-topology.d.ts +0 -44
  195. package/dist/execution-topology.js +0 -95
  196. package/dist/gate-evidence.d.ts +0 -85
  197. package/dist/gate-evidence.js +0 -631
  198. package/dist/harness-adapters.d.ts +0 -151
  199. package/dist/harness-adapters.js +0 -756
  200. package/dist/harness-selection.d.ts +0 -31
  201. package/dist/harness-selection.js +0 -214
  202. package/dist/hook-schema.d.ts +0 -6
  203. package/dist/hook-schema.js +0 -114
  204. package/dist/hook-schemas/claude-hooks.v1.json +0 -10
  205. package/dist/hook-schemas/codex-hooks.v1.json +0 -10
  206. package/dist/hook-schemas/cursor-hooks.v1.json +0 -13
  207. package/dist/init-detect.d.ts +0 -2
  208. package/dist/init-detect.js +0 -50
  209. package/dist/internal/advance-stage/advance.d.ts +0 -89
  210. package/dist/internal/advance-stage/advance.js +0 -655
  211. package/dist/internal/advance-stage/cancel-run.d.ts +0 -8
  212. package/dist/internal/advance-stage/cancel-run.js +0 -19
  213. package/dist/internal/advance-stage/flow-state-coercion.d.ts +0 -3
  214. package/dist/internal/advance-stage/flow-state-coercion.js +0 -81
  215. package/dist/internal/advance-stage/helpers.d.ts +0 -14
  216. package/dist/internal/advance-stage/helpers.js +0 -145
  217. package/dist/internal/advance-stage/hook.d.ts +0 -8
  218. package/dist/internal/advance-stage/hook.js +0 -40
  219. package/dist/internal/advance-stage/parsers.d.ts +0 -72
  220. package/dist/internal/advance-stage/parsers.js +0 -357
  221. package/dist/internal/advance-stage/proactive-delegation-trace.d.ts +0 -24
  222. package/dist/internal/advance-stage/proactive-delegation-trace.js +0 -56
  223. package/dist/internal/advance-stage/review-loop.d.ts +0 -16
  224. package/dist/internal/advance-stage/review-loop.js +0 -199
  225. package/dist/internal/advance-stage/rewind.d.ts +0 -14
  226. package/dist/internal/advance-stage/rewind.js +0 -108
  227. package/dist/internal/advance-stage/start-flow.d.ts +0 -13
  228. package/dist/internal/advance-stage/start-flow.js +0 -241
  229. package/dist/internal/advance-stage/verify.d.ts +0 -21
  230. package/dist/internal/advance-stage/verify.js +0 -185
  231. package/dist/internal/advance-stage.d.ts +0 -7
  232. package/dist/internal/advance-stage.js +0 -138
  233. package/dist/internal/cohesion-contract-stub.d.ts +0 -24
  234. package/dist/internal/cohesion-contract-stub.js +0 -148
  235. package/dist/internal/compound-readiness.d.ts +0 -23
  236. package/dist/internal/compound-readiness.js +0 -102
  237. package/dist/internal/detect-public-api-changes.d.ts +0 -5
  238. package/dist/internal/detect-public-api-changes.js +0 -45
  239. package/dist/internal/detect-supply-chain-changes.d.ts +0 -6
  240. package/dist/internal/detect-supply-chain-changes.js +0 -138
  241. package/dist/internal/early-loop-status.d.ts +0 -7
  242. package/dist/internal/early-loop-status.js +0 -93
  243. package/dist/internal/envelope-validate.d.ts +0 -7
  244. package/dist/internal/envelope-validate.js +0 -66
  245. package/dist/internal/flow-state-repair.d.ts +0 -20
  246. package/dist/internal/flow-state-repair.js +0 -104
  247. package/dist/internal/plan-split-waves.d.ts +0 -190
  248. package/dist/internal/plan-split-waves.js +0 -764
  249. package/dist/internal/runtime-integrity.d.ts +0 -7
  250. package/dist/internal/runtime-integrity.js +0 -268
  251. package/dist/internal/slice-commit.d.ts +0 -7
  252. package/dist/internal/slice-commit.js +0 -619
  253. package/dist/internal/tdd-loop-status.d.ts +0 -14
  254. package/dist/internal/tdd-loop-status.js +0 -68
  255. package/dist/internal/tdd-red-evidence.d.ts +0 -7
  256. package/dist/internal/tdd-red-evidence.js +0 -153
  257. package/dist/internal/waiver-grant.d.ts +0 -62
  258. package/dist/internal/waiver-grant.js +0 -294
  259. package/dist/internal/wave-status.d.ts +0 -74
  260. package/dist/internal/wave-status.js +0 -506
  261. package/dist/managed-resources.d.ts +0 -53
  262. package/dist/managed-resources.js +0 -313
  263. package/dist/policy.d.ts +0 -10
  264. package/dist/policy.js +0 -167
  265. package/dist/retro-gate.d.ts +0 -9
  266. package/dist/retro-gate.js +0 -47
  267. package/dist/run-archive.d.ts +0 -61
  268. package/dist/run-archive.js +0 -391
  269. package/dist/runs.d.ts +0 -2
  270. package/dist/runs.js +0 -2
  271. package/dist/stack-detection.d.ts +0 -116
  272. package/dist/stack-detection.js +0 -489
  273. package/dist/streaming/event-stream.d.ts +0 -31
  274. package/dist/streaming/event-stream.js +0 -114
  275. package/dist/tdd-cycle.d.ts +0 -107
  276. package/dist/tdd-cycle.js +0 -289
  277. package/dist/tdd-verification-evidence.d.ts +0 -17
  278. package/dist/tdd-verification-evidence.js +0 -122
  279. package/dist/track-heuristics.d.ts +0 -27
  280. package/dist/track-heuristics.js +0 -154
  281. package/dist/util/slice-id.d.ts +0 -58
  282. package/dist/util/slice-id.js +0 -89
  283. package/dist/worktree-manager.d.ts +0 -20
  284. package/dist/worktree-manager.js +0 -108
@@ -1,784 +1,55 @@
1
- import { conversationLanguagePolicyBullets } from "./language-policy.js";
2
- function yamlScalarString(value) {
3
- // JSON double-quoted strings are valid YAML scalars and escape reliably.
4
- return JSON.stringify(value);
5
- }
6
- function yamlFlowSequence(values) {
7
- return JSON.stringify(values);
8
- }
9
- const WORKER_RETURN_SCHEMA = {
10
- statusField: "status",
11
- allowedStatuses: ["DONE", "DONE_WITH_CONCERNS", "NEEDS_CONTEXT", "BLOCKED"],
12
- requiredFields: ["status", "filesChanged", "testsRun", "evidenceRefs", "concerns", "needsContext", "blockers"],
13
- evidenceFields: ["testsRun", "evidenceRefs"]
14
- };
15
- const REVIEW_RETURN_SCHEMA = {
16
- statusField: "status",
17
- allowedStatuses: ["PASS", "PASS_WITH_GAPS", "FAIL", "BLOCKED"],
18
- requiredFields: ["status", "findings", "criteria", "evidenceRefs", "blockers"],
19
- evidenceFields: ["findings.location", "criteria.evidence", "evidenceRefs"]
20
- };
21
- const ADVISORY_RETURN_SCHEMA = {
22
- statusField: "status",
23
- allowedStatuses: ["DONE", "DONE_WITH_CONCERNS", "NEEDS_CONTEXT", "BLOCKED"],
24
- requiredFields: ["status", "summary", "recommendations", "evidenceRefs", "unknowns"],
25
- evidenceFields: ["evidenceRefs", "recommendations"]
26
- };
27
- const CRITIC_ADVISORY_RETURN_SCHEMA = {
28
- ...ADVISORY_RETURN_SCHEMA,
29
- optionalFields: ["predictions", "predictionsValidated", "openQuestions", "realistCheckResults"]
30
- };
31
- const DOC_RETURN_SCHEMA = {
32
- statusField: "status",
33
- allowedStatuses: ["DONE", "DONE_WITH_CONCERNS", "NEEDS_CONTEXT", "BLOCKED"],
34
- requiredFields: ["status", "filesUpdated", "summary", "evidenceRefs", "openQuestions"],
35
- evidenceFields: ["filesUpdated", "evidenceRefs"]
36
- };
37
- function workerAckContract() {
38
- return `## Worker ACK Contract
39
-
40
- Before doing substantive work, return an ACK object that the parent can record:
41
-
42
- \`\`\`json
43
- {
44
- "status": "ACK",
45
- "spanId": "<parent spanId>",
46
- "dispatchId": "<parent dispatchId or workerRunId>",
47
- "dispatchSurface": "claude-task|cursor-task|opencode-agent|codex-agent|generic-task|role-switch",
48
- "agentDefinitionPath": ".cclaw/agents/<agent>.md or harness generated path",
49
- "ackTs": "<ISO timestamp>"
50
- }
51
- \`\`\`
52
-
53
- Finish with the required return schema plus the same \`spanId\` and \`dispatchId\`. The parent must not claim isolated completion unless ACK/result proof matches the ledger/event span.`;
54
- }
55
- /**
56
- * TDD worker self-record contract. The parent records `scheduled` and
57
- * `launched` rows BEFORE dispatching the Task; the worker records
58
- * `acknowledged` (on entry) and `completed` (on exit).
59
- */
60
- function tddWorkerSelfRecordContract(agentName) {
61
- const isBuilder = agentName === "slice-builder";
62
- const refactorOutcomeFlag = isBuilder
63
- ? " --refactor-outcome=inline|deferred [--refactor-rationale=\"<why>\"]"
64
- : "";
65
- const laneFlags = isBuilder
66
- ? " [--claim-token=<t>] [--lane-id=<lane>] [--lease-until=<iso>]"
67
- : "";
68
- return `## TDD worker delegation self-record contract
69
-
70
- You are a TDD worker dispatched via \`Task\`. The parent already wrote your \`scheduled\` and \`launched\` ledger rows BEFORE invoking you. **Your responsibility is to self-record \`acknowledged\` on entry and \`completed\` on exit** by invoking \`.cclaw/hooks/delegation-record.mjs\` directly. Do NOT skip these — the controller depends on them, the linter validates them, and back-fill via \`--repair\` is reserved for recovery only.
71
-
72
- **On entry — record acknowledgement (BEFORE doing work):**
73
-
74
- \`\`\`bash
75
- ACK_TS="$(date -u +%Y-%m-%dT%H:%M:%S.%3NZ 2>/dev/null || date -u +%Y-%m-%dT%H:%M:%SZ)"
76
- node .cclaw/hooks/delegation-record.mjs \\
77
- --stage=tdd --agent=${agentName} --mode=mandatory \\
78
- --status=acknowledged \\
79
- --span-id=<spanId from controller dispatch> \\
80
- --dispatch-id=<dispatchId from controller dispatch> \\
81
- --dispatch-surface=<surface from controller dispatch> \\
82
- --agent-definition-path=.cclaw/agents/${agentName}.md \\
83
- --ack-ts="$ACK_TS" \\
84
- --json
85
- \`\`\`
86
-
87
- **On exit — record completion (AFTER work + verification):**
88
-
89
- \`\`\`bash
90
- COMPLETED_TS="$(date -u +%Y-%m-%dT%H:%M:%S.%3NZ 2>/dev/null || date -u +%Y-%m-%dT%H:%M:%SZ)"
91
- node .cclaw/hooks/delegation-record.mjs \\
92
- --stage=tdd --agent=${agentName} --mode=mandatory \\
93
- --status=completed \\
94
- --span-id=<same spanId> \\
95
- --completed-ts="$COMPLETED_TS" \\
96
- --evidence-ref="<test-path-or-artifact-ref>"${refactorOutcomeFlag}${laneFlags} \\
97
- --json
98
- \`\`\`
99
-
100
- Reuse the same \`<spanId>\` and \`<dispatchId>\` across both rows. **GREEN evidence freshness** (slice-builder): the FIRST \`--evidence-ref\` MUST (1) reference the same test the matching \`phase=red\` row cited (basename/stem substring; reject \`green_evidence_red_test_mismatch\`), (2) include a recognized passing-runner line such as \`=> N passed; 0 failed\`, \`N passed in 0.42s\`, or \`ok pkg 0.12s\` (reject \`green_evidence_passing_assertion_missing\`), AND (3) be captured AFTER \`ackTs\` of this span — \`completedTs - ackTs\` must be ≥ \`flow-state.json::tddGreenMinElapsedMs\` (default 4000ms; reject \`green_evidence_too_fresh\`). Escape clause for legitimate observational GREEN: pass \`--green-mode=observational\`. \`--ack-ts\` and \`--completed-ts\` must be monotonic on the span (\`startTs ≤ launchedTs ≤ ackTs ≤ completedTs\`); the helper rejects out-of-order writes with \`delegation_timestamp_non_monotonic\`. If the helper rejects with \`dispatch_active_span_collision\` against a stale span, surface the conflicting \`spanId\` to the parent — do NOT silently retry with \`--allow-parallel\`.`;
101
- }
102
- function formatReturnSchema(schema) {
103
- const lines = [
104
- `- Status field: \`${schema.statusField}\``,
105
- `- Allowed statuses: ${schema.allowedStatuses.map((status) => `\`${status}\``).join(", ")}`,
106
- `- Required fields: ${schema.requiredFields.map((field) => `\`${field}\``).join(", ")}`,
107
- `- Evidence fields: ${schema.evidenceFields.map((field) => `\`${field}\``).join(", ")}`
108
- ];
109
- if (schema.optionalFields && schema.optionalFields.length > 0) {
110
- lines.push(`- Optional fields: ${schema.optionalFields.map((field) => `\`${field}\``).join(", ")}`);
111
- }
112
- return lines.join("\n");
113
- }
114
- function formattedAgentsForStages(stages) {
115
- const summary = stageDelegationSummary("standard");
116
- const merged = [];
117
- for (const stage of stages) {
118
- const row = summary.find((item) => item.stage === stage);
119
- if (!row)
120
- continue;
121
- for (const agent of row.primaryAgents) {
122
- if (!merged.includes(agent)) {
123
- merged.push(agent);
124
- }
125
- }
126
- }
127
- return merged.length > 0 ? merged.join(", ") : "none";
128
- }
129
- function activationModeSummary() {
130
- const summary = stageDelegationSummary("standard");
131
- const mandatory = new Set();
132
- const proactive = new Set();
133
- for (const row of summary) {
134
- for (const agent of row.mandatoryAgents) {
135
- mandatory.add(agent);
136
- }
137
- for (const agent of row.proactiveAgents) {
138
- proactive.add(agent);
139
- }
140
- }
141
- return {
142
- mandatory: [...mandatory].join(", "),
143
- proactive: [...proactive].join(", ")
144
- };
145
- }
146
- /**
147
- * Canonical slice-builder worker protocol text (embedded in the agent body and
148
- * echoed in the TDD skill block).
149
- */
150
- export function sliceBuilderProtocol() {
151
- return [
152
- "## slice-builder protocol",
153
- "",
154
- "**slice-builder** is the canonical worker for **one feature-atomic implementation unit/slice** end-to-end: **RED → GREEN → REFACTOR → inline DOC** in **one** delegated span. The unit may contain internal 2-5 minute TDD steps; do not split those into separate agents unless the parent selected `strict-micro`. Multiple slice-builder spans run in parallel only when topology is `parallel-builders` and the wave plan declares disjoint `claimedPaths`.",
155
- "",
156
- "**Multi-slice batch under `single-builder`:** the controller may dispatch ONE slice-builder span that owns MORE than one ready slice (e.g. when the router collapses a wave into single-builder mode). Treat each slice in the batch as its own RED → GREEN → REFACTOR → DOC mini-cycle: emit a separate `phase=red|green|refactor|doc` row per `--slice` value (use the same `spanId`/`dispatchId` for the whole batch), keep `claimedPaths` disjoint per-slice within the batch, and author one `tdd-slices/S-<id>.md` per slice. Phase-status rules from the table below stay unchanged — never collapse multiple slices into one phase row.",
157
- "",
158
- "### Invariants",
159
- "- Produce failing RED evidence (or cite the delegated RED artifact) **before** production edits.",
160
- "- Stay inside the slice contract: `claimedPaths`, acceptance mapping, and forbidden-change lists from the parent.",
161
- "- When `tdd.isolationMode=worktree|auto`, run the slice inside the assigned worktree path (never in the shared repo root) so filesystem isolation enforces the claimed-path fence.",
162
- "- When `tdd.commitMode=managed-per-slice`, do **not** hand-edit git state for slice files (no manual `git add/commit` on claimed paths). Let `.cclaw/hooks/slice-commit.mjs` own per-slice commits.",
163
- "- After GREEN, refactor inline **or** record deferred refactor via the same `--refactor-outcome` mechanics the controller specifies.",
164
- "- Own the prose slice summary at `<artifacts-dir>/tdd-slices/S-<id>.md` yourself.",
165
- "",
166
- "### Events",
167
- "- Honor every `delegation-record`/`delegation-record.mjs` row shape the controller requests so artifact linters keep passing.",
168
- "- The umbrella `slice-completed` row ties RED/GREEN/REFACTOR/DOC timestamps to your builder span.",
169
- "",
170
- "### Event → status flag table (7.6.0 — phase-event status validation)",
171
- "",
172
- "Phase-level granularity is only meaningful on terminal outcomes. The dispatch-level ack (no `--phase`) is the controller saying \"I see the dispatch surface back\" — it stays on `--status=acknowledged`. Phase events MUST use `--status=completed` or `--status=failed`. The hook rejects mismatches with `phase_event_requires_completed_or_failed_status` (exit 2) and prints a corrected-command hint.",
173
- "",
174
- "| event | --phase | --status |",
175
- "|---|---|---|",
176
- "| dispatch ack (controller-side) | (none) | `acknowledged` |",
177
- "| RED watched-fail captured | `red` | `completed` |",
178
- "| GREEN test passes | `green` | `completed` (with `--refactor-outcome=inline\\|deferred\\|...`) |",
179
- "| REFACTOR landed | `refactor` | `completed` |",
180
- "| DOC card landed (triggers slice-commit) | `doc` | `completed` |",
181
- "| BLOCKED / unrecoverable | (any phase reached) | `failed` |",
182
- "",
183
- "Common slip: recording every phase event with `--status=acknowledged` (e.g. `--phase=doc --status=acknowledged`). The event row is silently dropped from terminal-phase aggregations, `slice-commit.mjs` never fires (it only triggers on `phase=doc status=completed`), and `wave-status` reports the slice as phantom-open. Recovery requires raw backfill commands. The 7.6.0 hook validator forbids this configuration up front.",
184
- "",
185
- "### Streaming output contract",
186
- "- Emit one JSON line to stdout per completed phase: `{\"event\":\"phase-completed\",\"stage\":\"tdd\",\"sliceId\":\"S-<n>\",\"phase\":\"<red|green|refactor|refactor-deferred|doc>\",\"spanId\":\"<span>\",\"runId\":\"<run>\",\"ts\":\"<iso>\"}`.",
187
- "- For `phase=green` with inline/deferred refactor folding, include `refactorOutcome.mode` in the same JSON line so live controllers can close the slice without waiting for file sync.",
188
- "- If streaming is unavailable in your harness/runtime, keep writing canonical `delegation-record` rows; controller-side live mode will fall back to file-based events.",
189
- "",
190
- "**Role boundary:** do not widen scope, do not self-approve ship-level review, and do not recurse into other agents unless the parent explicitly directs it."
191
- ].join("\n");
192
- }
193
- /**
194
- * Canonical specialist roster materialized under `.cclaw/agents/`.
195
- *
196
- * Declared with `satisfies` so the array retains literal `name` types for
197
- * downstream type-level consumers (e.g. `AgentName`), while still being
198
- * checked against the `AgentDefinition` shape at compile time. Do not add
199
- * an explicit `AgentDefinition[]` annotation here — it would widen `name`
200
- * to `string` and break the compile-time drift guard.
201
- */
202
- export const CCLAW_AGENTS = [
1
+ import { SPECIALIST_PROMPTS } from "./specialist-prompts/index.js";
2
+ export const CORE_AGENTS = [
203
3
  {
204
- name: "researcher",
205
- description: "PROACTIVE when context readiness, repo search, reference patterns, or external docs could change a stage decision. MUST summarize search-before-read evidence before large reads.",
206
- tools: ["Read", "Grep", "Glob", "WebSearch"],
207
- model: "fast",
208
- activation: "proactive",
209
- relatedStages: ["brainstorm", "scope", "design", "plan"],
210
- returnSchema: ADVISORY_RETURN_SCHEMA,
211
- body: [
212
- "You are a **context readiness and research specialist**.",
213
- "",
214
- "When invoked:",
215
- "1. Start with search/query summaries before reading large files.",
216
- "2. Name provider status when known: graph/search/docs/MCP/semantic index freshness.",
217
- "3. Separate observed facts from assumptions and stale or missing context.",
218
- "4. Return concise evidence refs the controller can paste into stage artifacts.",
219
- "",
220
- "**Role boundary:** research and context synthesis only. Do NOT edit files."
221
- ].join("\n")
222
- },
223
- {
224
- name: "planner",
225
- description: "MANDATORY for scope/design/plan and PROACTIVE for high-ambiguity work. MUST BE USED when sequencing, dependency mapping, or risk trade-offs are required before coding.",
226
- tools: ["Read", "Grep", "Glob", "WebSearch"],
227
- model: "deep",
228
- activation: "mandatory",
229
- relatedStages: ["brainstorm", "scope", "design", "spec", "plan"],
230
- returnSchema: ADVISORY_RETURN_SCHEMA,
231
- body: [
232
- "You are an **implementation planning specialist** (staff engineer mindset).",
233
- "",
234
- "When invoked:",
235
- "1. Map upstream decisions, scope boundaries, and explicit drift before planning.",
236
- "2. Break the work into concrete sub-problems with dependencies and existing-module fit.",
237
- "3. Enforce one-question discipline: ask only decision-changing questions, one at a time.",
238
- "4. Produce an ordered execution plan with verification checks and handoff quality notes.",
239
- "5. Highlight risks and unknowns that need user decisions.",
240
- "",
241
- "**Role boundary:** planning only. Do NOT write production code."
242
- ].join("\n")
243
- },
244
- {
245
- name: "product-discovery",
246
- description: "MANDATORY during brainstorm and PROACTIVE during scope when value framing or expansion strategy needs product-level discovery pressure.",
247
- tools: ["Read", "Grep", "Glob", "WebSearch"],
248
- model: "deep",
249
- activation: "mandatory",
250
- relatedStages: ["brainstorm", "scope"],
251
- returnSchema: ADVISORY_RETURN_SCHEMA,
252
- body: [
253
- "You are a **product discovery specialist**.",
254
- "",
255
- "**Mode: discovery** (default)",
256
- "- persona / user and job to be done",
257
- "- pain or trigger",
258
- "- value hypothesis and success metric",
259
- "- evidence or signal strength",
260
- "- why now, do-nothing consequence, and non-goals",
261
- "",
262
- "**Mode: strategist** (trigger when scope mode is SCOPE EXPANSION or SELECTIVE EXPANSION)",
263
- "- 10x vision and ideal outcome versus baseline scope",
264
- "- concrete expansion proposals (not cosmetic variants)",
265
- "- expected upside, reversibility, and trajectory impact",
266
- "- explicit add/defer/skip recommendation per proposal",
267
- "",
268
- "For technical-maintenance work, translate these modes to operator/developer outcomes, failure-mode reduction, verification signal quality, and trajectory impact.",
269
- "",
270
- "**Role boundary:** frame value and trajectory fit. Do NOT choose implementation architecture."
271
- ].join("\n")
272
- },
273
- {
274
- name: "divergent-thinker",
275
- description: "PROACTIVE before planner/critic convergence when brainstorm or scope needs option-space expansion and alternative framings.",
276
- tools: ["Read", "Grep", "Glob", "WebSearch"],
277
- model: "balanced",
278
- activation: "proactive",
279
- relatedStages: ["brainstorm", "scope"],
280
- returnSchema: ADVISORY_RETURN_SCHEMA,
281
- body: [
282
- "You are a **creative divergent-thinker** dispatched BEFORE planner/critic converge on a single path.",
283
- "",
284
- "Your job:",
285
- "1. Generate 3-5 alternative framings of the problem.",
286
- "2. Generate 3-5 alternative approaches per framing where reasonable.",
287
- "3. For each option, include one-line pro/con plus reversibility flag.",
288
- "4. Highlight option-space the user might not have considered.",
289
- "5. Return concise structured output in `recommendations[]` for planner/critic consumption.",
290
- "",
291
- "Role boundary: divergence only.",
292
- "- Do NOT recommend a single approach.",
293
- "- Do NOT validate feasibility (feasibility-reviewer owns that).",
294
- "- Do NOT critique premise validity (critic owns that).",
295
- "",
296
- "You are an explicit amplifier of option-space; convergence happens after you."
297
- ].join("\n")
298
- },
299
- {
300
- name: "critic",
301
- description: "PROACTIVE during brainstorm/scope/design when premises, alternatives, cost, rollback, or hidden assumptions need adversarial pressure.",
302
- tools: ["Read", "Grep", "Glob", "WebSearch"],
303
- model: "balanced",
304
- activation: "proactive",
305
- relatedStages: ["brainstorm", "scope", "design"],
306
- returnSchema: CRITIC_ADVISORY_RETURN_SCHEMA,
307
- body: [
308
- "You are an **adversarial critic** for product and engineering decisions.",
309
- "",
310
- "## Why this matters",
311
- "False approval is expensive: a missed flaw early can cost 10-100x more to unwind after implementation.",
312
- "Anchor every concern in evidence and avoid inventing hypothetical blockers without proof.",
313
- "",
314
- "## Pre-commitment predictions",
315
- "Before deep investigation, list your hypotheses in `predictions[]` (what you expect to find and why).",
316
- "",
317
- "## Multi-perspective angles",
318
- "Pick context-aware angles before analysis:",
319
- "- plan/spec/scope: `executor`, `stakeholder`, `skeptic`",
320
- "- design/code: `security`, `operator`, `new-hire`",
321
- "",
322
- "## Gap analysis",
323
- "Name what is missing (evidence gaps, undefined contracts, absent safeguards), not just what looks wrong.",
324
- "",
325
- "## Self-audit",
326
- "Low-confidence concerns (confidence <=4/10) must move into `openQuestions[]` and should not block stage transition by themselves.",
327
- "",
328
- "## Realist check",
329
- "For each Critical/Major concern, test if it would realistically ship; downgrade or suppress concerns that are not plausible in this context.",
330
- "Record the result in `realistCheckResults[]`.",
331
- "",
332
- "## ADVERSARIAL mode escalation",
333
- "Escalate to ADVERSARIAL mode when reviewers disagree, your confidence is low, or trust/security boundaries are involved.",
334
- "",
335
- "Return validated risks, disproven predictions in `predictionsValidated[]`, and the smallest decision-changing recommendation."
336
- ].join("\n")
337
- },
338
- {
339
- name: "architect",
340
- description: "MANDATORY during design and final ship verification. MUST BE USED to validate architecture boundaries, alternatives, failure modes, rollout, and cross-stage cohesion before release.",
341
- tools: ["Read", "Grep", "Glob", "WebSearch"],
342
- model: "deep",
343
- activation: "mandatory",
344
- relatedStages: ["design", "ship"],
345
- returnSchema: ADVISORY_RETURN_SCHEMA,
346
- body: [
347
- "You are an **architecture validation specialist**.",
348
- "",
349
- "Check architecture boundaries, existing-system fit, critical paths, data/state flow, alternatives, rescue paths, and verification hooks.",
350
- "Return chosen path risks, rejected alternatives, switch triggers, and required evidence before spec handoff.",
351
- "At ship, perform cross-stage verification across scope/design/spec/plan/review/code and flag DRIFT_DETECTED when shipped behavior diverges from locked decisions.",
352
- "",
353
- "**Role boundary:** design validation only. Do NOT write implementation code."
354
- ].join("\n")
355
- },
356
- {
357
- name: "spec-validator",
358
- description: "MANDATORY during standard/deep spec. MUST BE USED to validate measurable acceptance criteria, assumptions, edge cases, and testability mapping.",
359
- tools: ["Read", "Grep", "Glob"],
360
- model: "balanced",
361
- activation: "mandatory",
362
- relatedStages: ["spec"],
363
- returnSchema: REVIEW_RETURN_SCHEMA,
364
- body: [
365
- "You are a **specification validation specialist**.",
366
- "",
367
- "For every acceptance criterion, verify it is observable, measurable, falsifiable, mapped to upstream decisions, and paired with concrete verification evidence.",
368
- "Flag vague language, missing edge cases, hidden assumptions, and RED tests that cannot be expressed.",
369
- "",
370
- "**Role boundary:** validate the spec; do NOT write plan tasks or implementation."
371
- ].join("\n")
372
- },
373
- {
374
- name: "spec-document-reviewer",
375
- description: "PROACTIVE during spec when self-review surfaces issues, subsystem boundaries feel broad, or the artifact needs a final plan-readiness pass.",
376
- tools: ["Read", "Grep", "Glob"],
377
- model: "balanced",
378
- activation: "proactive",
379
- relatedStages: ["spec"],
380
- returnSchema: REVIEW_RETURN_SCHEMA,
381
- body: [
382
- "You are a **spec document reviewer** focused on plan-readiness.",
383
- "",
384
- "Run a concise pass over:",
385
- "- completeness of required spec sections",
386
- "- consistency across acceptance criteria, assumptions, and mapping",
387
- "- clarity / ambiguity / placeholder drift",
388
- "- single-subsystem scope fit and YAGNI pressure",
389
- "",
390
- "Return `PASS`, `PASS_WITH_GAPS`, `FAIL`, or `BLOCKED` with concrete evidence refs and minimal corrective actions.",
391
- "",
392
- "**Role boundary:** review the spec artifact only; do NOT write plan tasks or implementation."
393
- ].join("\n")
394
- },
395
- {
396
- name: "coherence-reviewer",
397
- description: "PROACTIVE during spec/plan/design when internal consistency must be validated across sections, terminology, references, and dependency narratives.",
398
- tools: ["Read", "Grep", "Glob"],
399
- model: "balanced",
400
- activation: "proactive",
401
- relatedStages: ["spec", "plan", "design"],
402
- returnSchema: REVIEW_RETURN_SCHEMA,
403
- body: [
404
- "You are a **document coherence reviewer** focused on consistency, not quality scoring.",
405
- "",
406
- "Check for:",
407
- "- contradictions between sections",
408
- "- terminology drift (same concept named differently)",
409
- "- broken internal references and forward-reference mismatches",
410
- "- dependency/storyline conflicts between architecture, scope, and execution notes",
411
- "",
412
- "Return `PASS`, `PASS_WITH_GAPS`, `FAIL`, or `BLOCKED` with calibrated, evidence-anchored findings.",
413
- "",
414
- "**Role boundary:** consistency checks only. Do NOT rewrite the document or propose architecture alternatives."
415
- ].join("\n")
416
- },
417
- {
418
- name: "scope-guardian-reviewer",
419
- description: "PROACTIVE during scope/plan/design when complexity growth, scope drift, or unnecessary abstraction risk needs a dedicated challenge pass.",
420
- tools: ["Read", "Grep", "Glob"],
421
- model: "balanced",
422
- activation: "proactive",
423
- relatedStages: ["scope", "plan", "design"],
424
- returnSchema: REVIEW_RETURN_SCHEMA,
425
- body: [
426
- "You are a **scope guard reviewer** focused on minimum viable change and complexity discipline.",
427
- "",
428
- "Check for:",
429
- "- whether the document reuses existing solutions before adding abstractions",
430
- "- scope-goal alignment and minimum useful slice",
431
- "- complexity smell tests (generic utilities, framework-ahead-of-need patterns, speculative layers)",
432
- "- dependency ordering that can accidentally widen scope",
433
- "",
434
- "Return `PASS`, `PASS_WITH_GAPS`, `FAIL`, or `BLOCKED` with concrete evidence refs and smallest corrective action.",
435
- "",
436
- "**Role boundary:** challenge over-scope and unnecessary complexity; do NOT replace planner/architect ownership."
437
- ].join("\n")
438
- },
439
- {
440
- name: "feasibility-reviewer",
441
- description: "PROACTIVE during plan/design when resource, runtime, environment, dependency, or rollout assumptions can make the solution non-viable.",
442
- tools: ["Read", "Grep", "Glob"],
443
- model: "balanced",
444
- activation: "proactive",
445
- relatedStages: ["plan", "design"],
446
- returnSchema: REVIEW_RETURN_SCHEMA,
447
- body: [
448
- "You are a **feasibility reviewer** focused on execution realism.",
449
- "",
450
- "Check for:",
451
- "- resource/time assumptions versus current constraints",
452
- "- runtime and environment assumptions (infrastructure, limits, deployment shape)",
453
- "- availability/reliability assumptions for external dependencies",
454
- "- rollout and operational risk under real-world conditions",
455
- "",
456
- "Return `PASS`, `PASS_WITH_GAPS`, `FAIL`, or `BLOCKED` with evidence and explicit risk-to-ship mapping.",
457
- "",
458
- "**Role boundary:** feasibility realism only; do NOT redesign architecture unless feasibility is blocked."
459
- ].join("\n")
460
- },
461
- {
462
- name: "reviewer",
463
- description: "MANDATORY during review. MUST BE USED to run a two-pass audit with explicit inline lens coverage for performance, compatibility, and observability.",
464
- tools: ["Read", "Grep", "Glob"],
465
- model: "balanced",
466
- activation: "mandatory",
467
- relatedStages: ["spec", "review", "ship"],
468
- returnSchema: REVIEW_RETURN_SCHEMA,
469
- body: [
470
- "You are a **combined spec + code reviewer**.",
471
- "",
472
- "Run two explicit passes:",
473
- "",
474
- "1. **Spec pass**",
475
- " - For each acceptance criterion: PASS / PARTIAL / FAIL.",
476
- " - Cite evidence as `file:line`.",
477
- "",
478
- "2. **Code-quality pass**",
479
- " - Correctness: logic, boundaries, state transitions.",
480
- " - Maintainability: naming, structure, complexity, debt risks.",
481
- " - Performance: avoid obvious hot-path regressions.",
482
- " - Architecture fit: layering and contract stability.",
483
- "",
484
- "## Lens Coverage",
485
- "Performance: NO_IMPACT / FOUND_<n>",
486
- "Compatibility: NO_IMPACT / FOUND_<n>",
487
- "Observability: NO_IMPACT / FOUND_<n>",
488
- "Security: routed to security-reviewer (always separate)",
489
- "",
490
- "### Companion lens skills (load on-demand, never all-at-once)",
491
- "- **review-perf-lens** — load when reviewing code touching hot paths, loops over large data, network/disk I/O, render hot paths, or sub-100ms latency budgets.",
492
- "- **review-compat-lens** — load when reviewing code that runs on multiple OS/runtime/browser targets, modifies shared library APIs, or changes serialized payload shapes.",
493
- "- **review-observability-lens** — load when reviewing code that adds/removes logging, metrics, traces, error reporting, or audit/compliance signals.",
494
- "If none of those triggers apply, do NOT load the lens skills — they are deep-dive context, not default reading.",
495
- "",
496
- "For each finding include:",
497
- "- Severity: `Critical` | `Important` | `Suggestion`",
498
- "- Location: `file:line`; if no line is possible, state the no-line reason",
499
- "- Problem and concrete recommendation",
500
- "",
501
- "Also report files inspected, changed-file coverage, diagnostics run, dependency/version audit when relevant, and a no-finding attestation when no issues are found.",
502
- "",
503
- "**Trust model:** never rely on implementer claims; verify by reading code."
504
- ].join("\n")
505
- },
506
- {
507
- name: "security-reviewer",
508
- description: "MANDATORY during review; PROACTIVE during design/ship for trust-boundary changes. Always produce an explicit no-change attestation when no security-relevant surface moved.",
509
- tools: ["Read", "Grep", "Glob"],
510
- model: "balanced",
511
- activation: "mandatory",
512
- relatedStages: ["design", "review", "ship"],
513
- returnSchema: REVIEW_RETURN_SCHEMA,
514
- body: [
515
- "You are a **security vulnerability specialist** focused on exploitability.",
516
- "",
517
- "Check for (non-exhaustive):",
518
- "- validation gaps and injection vectors",
519
- "- authz/authn boundary violations",
520
- "- secret leakage in code/logging",
521
- "- unsafe file/system/network operations",
522
- "- privilege escalation and trust-boundary misuse",
523
- "",
524
- "For each finding include:",
525
- "- severity aligned to ship risk",
526
- "- CWE ID when possible (or UNKNOWN)",
527
- "- short proof-of-concept vector",
528
- "- concrete control-oriented fix",
529
- "- `NO_CHANGE_ATTESTATION` or `NO_SECURITY_IMPACT` with inspected surfaces when no security finding exists"
530
- ].join("\n")
4
+ id: "brainstormer",
5
+ title: "Brainstormer",
6
+ activation: "on-demand",
7
+ modes: ["frame", "scope", "alternatives"],
8
+ description: "Frame what/why and scope. Optional alternatives sweep when the request is ambiguous.",
9
+ prompt: SPECIALIST_PROMPTS.brainstormer
531
10
  },
532
11
  {
533
- name: "integration-overseer",
534
- description: "ON-DEMAND after TDD fan-out to verify cross-slice cohesion contract integrity, integration surfaces, and shared invariants before review handoff.",
535
- tools: ["Read", "Grep", "Glob"],
536
- model: "balanced",
12
+ id: "architect",
13
+ title: "Architect",
537
14
  activation: "on-demand",
538
- relatedStages: ["tdd", "review"],
539
- returnSchema: REVIEW_RETURN_SCHEMA,
540
- body: [
541
- "You are an **integration overseer** for TDD fan-out runs.",
542
- "",
543
- "You are dispatched after parallel `slice-builder` lanes complete.",
544
- "",
545
- "Checks:",
546
- "- every integration test named in `cohesion-contract.md` passes (or has explicit gap rationale)",
547
- "- naming conventions remain consistent across slices",
548
- "- shared invariants stay true after fan-in",
549
- "- boundary types at touchpoints match the contract",
550
- "- integration between slices is executable and regression-safe",
551
- "",
552
- "Return `PASS`, `PASS_WITH_GAPS`, `FAIL`, or `BLOCKED` with evidence refs and explicit integration risks.",
553
- "",
554
- "**Role boundary:** integration and cohesion oversight only; do NOT implement production code."
555
- ].join("\n")
15
+ modes: ["architecture", "feasibility"],
16
+ description: "Architectural decisions plus feasibility against the current codebase.",
17
+ prompt: SPECIALIST_PROMPTS.architect
556
18
  },
557
19
  {
558
- name: "release-reviewer",
559
- description: "MANDATORY during ship. MUST BE USED for release readiness, rollback, finalization mode, evidence freshness, and victory detector checks.",
560
- tools: ["Read", "Grep", "Glob", "Bash"],
561
- model: "balanced",
562
- activation: "mandatory",
563
- relatedStages: ["ship"],
564
- returnSchema: REVIEW_RETURN_SCHEMA,
565
- body: [
566
- "You are a **release readiness reviewer**.",
567
- "",
568
- "Verify preflight evidence, review verdict freshness, rollback trigger and steps, finalization enum, no-VCS handoff when applicable, learnings capture, and handoff completeness.",
569
- "Block ship on stale evidence, unresolved criticals, missing rollback, or ambiguous finalization."
570
- ].join("\n")
20
+ id: "planner",
21
+ title: "Planner",
22
+ activation: "on-demand",
23
+ modes: ["research", "work-breakdown", "topology"],
24
+ description: "Targeted research, work breakdown into AC, execution topology recommendation.",
25
+ prompt: SPECIALIST_PROMPTS.planner
571
26
  },
572
27
  {
573
- name: "doc-updater",
574
- description: "MANDATORY only at ship; PROACTIVE during tdd/review whenever behavior, config, or public API changes. Keep docs and runbooks in lockstep with shipped behavior.",
575
- tools: ["Read", "Write", "Edit", "Grep", "Glob"],
576
- model: "fast",
577
- activation: "mandatory",
578
- relatedStages: ["tdd", "ship"],
579
- returnSchema: DOC_RETURN_SCHEMA,
580
- body: [
581
- "You are a **documentation maintenance specialist**.",
582
- "",
583
- "After code changes, verify and update only stale sections in:",
584
- "- README / setup / usage",
585
- "- API docs and examples",
586
- "- migration, rollout, rollback, and operational notes",
587
- "- public-surface change notes tied to actual changed files",
588
- "",
589
- "Preserve existing tone and structure; avoid rewrites for style alone."
590
- ].join("\n")
28
+ id: "reviewer",
29
+ title: "Reviewer",
30
+ activation: "on-demand",
31
+ modes: ["code", "text-review", "integration", "release", "adversarial"],
32
+ description: "Multi-mode reviewer covering code, plan/spec text, integration, release readiness, and adversarial sweeps.",
33
+ prompt: SPECIALIST_PROMPTS.reviewer
591
34
  },
592
35
  {
593
- name: "slice-builder",
594
- description: "MANDATORY for delegated TDD slices. Owns RED → GREEN → REFACTOR → per-slice DOC for one feature-atomic implementation unit/slice in a single delegated span. Multiple slice-builder spans run in parallel only under `parallel-builders` topology with disjoint `claimedPaths`; `strict-micro` keeps tiny tasks separate.",
595
- tools: ["Read", "Write", "Edit", "Grep", "Glob", "Bash"],
596
- model: "balanced",
597
- activation: "mandatory",
598
- relatedStages: ["tdd"],
599
- returnSchema: WORKER_RETURN_SCHEMA,
600
- body: [
601
- "You are **slice-builder**, the canonical vertical-slice TDD worker.",
602
- "",
603
- sliceBuilderProtocol(),
604
- "",
605
- "**Mode hints:**",
606
- "- **TDD-bound (default)** — RED evidence precedes GREEN; preserve behavior across REFACTOR; document outcomes in `tdd-slices/S-<id>.md`.",
607
- "- **Generic** — only when the parent explicitly disables TDD gates for quick-track breadth; bounded scope and verification still apply.",
608
- "",
609
- "**Role boundary:** obey the parent's phase flags (`--phase=red|green|refactor|doc`); never improvise undeclared parallelism."
610
- ].join("\n")
36
+ id: "security-reviewer",
37
+ title: "Security reviewer",
38
+ activation: "on-demand",
39
+ modes: ["threat-model", "sensitive-change"],
40
+ description: "Threat-model + focused review of sensitive changes. Sets security_flag for compound learnings.",
41
+ prompt: SPECIALIST_PROMPTS["security-reviewer"]
611
42
  },
612
43
  {
613
- name: "fixer",
614
- description: "ON-DEMAND fresh worker after review FAIL/PARTIAL evidence. Must fix only the cited criterion within explicit allowed files.",
615
- tools: ["Read", "Write", "Edit", "Grep", "Glob", "Bash"],
616
- model: "balanced",
44
+ id: "slice-builder",
45
+ title: "Slice builder",
617
46
  activation: "on-demand",
618
- relatedStages: ["review", "tdd"],
619
- returnSchema: WORKER_RETURN_SCHEMA,
620
- body: [
621
- "You are a **fresh fixer worker** dispatched after a review found a concrete gap.",
622
- "",
623
- "Rules:",
624
- "1. Start from the failing criterion and reviewer evidence, not from implementer claims.",
625
- "2. Stay inside the allowed files and forbidden-change constraints.",
626
- "3. Apply the smallest fix and rerun the relevant verification.",
627
- "4. Return the strict fixer JSON schema before prose.",
628
- "",
629
- "**Role boundary:** fix only the cited gap; do not redesign the slice."
630
- ].join("\n")
47
+ modes: ["build", "fix-only"],
48
+ description: "Implements AC slices and post-review scoped fixes. Always commits per AC via commit-helper.",
49
+ prompt: SPECIALIST_PROMPTS["slice-builder"]
631
50
  }
632
51
  ];
633
- /**
634
- * Agents whose rendered `.cclaw/agents/<name>.md` file gets the TDD worker
635
- * self-record helper template. Controllers dispatch these via `Task` during
636
- * TDD; they own `acknowledged` and `completed` ledger writes.
637
- */
638
- const TDD_WORKER_SELF_RECORD_AGENTS = new Set([
639
- "slice-builder",
640
- "integration-overseer"
641
- ]);
642
- import { stageDelegationSummary } from "./stage-schema.js";
643
- /**
644
- * Render a complete cclaw agent markdown file (YAML frontmatter + body).
645
- */
646
- function defaultTaskDelegationSection(agentName) {
647
- return `
648
-
649
- ## Task Tool Delegation
650
-
651
- Use native Task/subagent delegation only when this agent's role requires isolated context or strict lifecycle evidence. Keep the delegation prompt self-contained and bounded to this agent's role.
652
-
653
- ${agentName === "reviewer"
654
- ? "- For large/high-risk diffs, load optional deep lens skills (`review-perf-lens`, `review-compat-lens`, `review-observability-lens`) before final verdict."
655
- : "_No extra agent-specific delegation template is required._"}
656
- `;
657
- }
658
- export function agentMarkdown(agent) {
659
- const frontmatter = [
660
- "---",
661
- `name: ${agent.name}`,
662
- `description: ${yamlScalarString(agent.description)}`,
663
- `tools: ${yamlFlowSequence(agent.tools)}`,
664
- `model: ${agent.model}`,
665
- "---"
666
- ].join("\n");
667
- const relatedStages = agent.relatedStages.length > 0 ? agent.relatedStages.join(", ") : "(none)";
668
- const taskDelegation = defaultTaskDelegationSection(agent.name);
669
- const tddWorkerSelfRecordSection = TDD_WORKER_SELF_RECORD_AGENTS.has(agent.name)
670
- ? `\n${tddWorkerSelfRecordContract(agent.name)}\n`
671
- : "";
672
- return `${frontmatter}
673
-
674
- # ${agent.name}
675
-
676
- ${agent.body}
677
-
678
- ## Activation
679
-
680
- - Mode: ${agent.activation}
681
- - Related stages: ${relatedStages}
682
-
683
- ${workerAckContract()}
684
- ${tddWorkerSelfRecordSection}
685
- ## Required Return Schema
686
-
687
- STRICT_RETURN_SCHEMA: return a structured object matching this contract before any narrative when delegated. Include \`spanId\`, \`dispatchId\` or \`workerRunId\`, \`dispatchSurface\`, \`agentDefinitionPath\`, and lifecycle timestamps when provided by the parent.
688
-
689
- ${formatReturnSchema(agent.returnSchema)}
690
-
691
- ## Rules
692
-
693
- ## Conversation Language Policy
694
-
695
- ${conversationLanguagePolicyBullets()}
696
- - Cite file:line for every finding
697
- - Do not make changes outside your specialist domain
698
- - Report findings with severity classification
699
- - If uncertain, say "UNKNOWN" - never guess
700
-
701
- ${taskDelegation}
702
- `;
703
- }
704
- /**
705
- * Markdown table mapping cclaw stage entry points to specialist agents.
706
- */
707
- export function agentRoutingTable() {
708
- const brainstormPrimary = formattedAgentsForStages(["brainstorm"]);
709
- const scopeDesignPlanPrimary = formattedAgentsForStages(["scope", "design", "plan"]);
710
- const specPrimary = formattedAgentsForStages(["spec"]);
711
- const tddPrimary = formattedAgentsForStages(["tdd"]);
712
- const reviewPrimary = formattedAgentsForStages(["review"]);
713
- const shipPrimary = formattedAgentsForStages(["ship"]);
714
- return `| Stage Entry | Primary Agent(s) | Supporting guidance |
715
- |---|---|---|
716
- | Brainstorm (start with \`/cc <idea>\`) | ${brainstormPrimary} | Run in-thread research playbooks: \`research/repo-scan.md\`, \`research/learnings-lookup.md\` |
717
- | Scope / Design / Plan (via \`/cc\`) | ${scopeDesignPlanPrimary} | Use \`research/git-history.md\` (scope) and \`research/framework-docs-lookup.md\` + \`research/best-practices-lookup.md\` (design) as needed |
718
- | Spec (via \`/cc\`) | ${specPrimary} | planner (if ambiguity or conflicts remain) |
719
- | TDD (via \`/cc\`) | ${tddPrimary} | doc-updater on public behavior/config changes |
720
- | Review (via \`/cc\`) | ${reviewPrimary} | conditional second reviewer for high blast-radius diffs |
721
- | Ship (via \`/cc\`) | ${shipPrimary} | security-reviewer when release risk is elevated |
722
- `;
723
- }
724
- /**
725
- * Cost tier routing for the specialist agent roster.
726
- */
727
- export function agentCostTierTable() {
728
- return `| Tier | Use for | Example agents |
729
- |---|---|---|
730
- | \`deep\` | one heavy planning/strategy pass per stage | planner, product-discovery |
731
- | \`balanced\` | discovery, criticism, review, TDD, and bounded worker execution | critic, spec-document-reviewer, coherence-reviewer, scope-guardian-reviewer, feasibility-reviewer, reviewer, security-reviewer, slice-builder, fixer |
732
- | \`fast\` | bounded maintenance updates with limited blast radius | doc-updater |
733
- `;
734
- }
735
- export function agentRegistryMatrix() {
736
- const rows = CCLAW_AGENTS.map((agent) => {
737
- const stages = agent.relatedStages.length > 0 ? agent.relatedStages.join(", ") : "none";
738
- return `| ${agent.name} | ${agent.activation} | ${agent.model} | ${stages} | ${agent.returnSchema.allowedStatuses.join(" / ")} |`;
739
- }).join("\n");
740
- return `| Agent | Activation | Model | Related stages | Terminal statuses |
741
- |---|---|---|---|---|
742
- ${rows}`;
743
- }
744
- /**
745
- * AGENTS.md-ready section describing cclaw’s specialist delegation model.
746
- */
747
- export function agentsAgentsMdBlock() {
748
- return `### Agent Specialists
749
-
750
- cclaw defines specialist personas for \`.cclaw/agents/\`: ${CCLAW_AGENTS.map((agent) => agent.name).join(", ")}.
751
- **TDD work** is owned end-to-end by **slice-builder** — one worker per slice, multiple workers in parallel within a wave when \`claimedPaths\` are disjoint.
752
-
753
- ${agentRoutingTable()}
754
-
755
- ### Agent Registry Matrix
756
-
757
- ${agentRegistryMatrix()}
758
-
759
- ### Research Playbooks (in-thread)
760
-
761
- Research work is no longer modeled as standalone personas. Use in-thread playbooks under \`.cclaw/skills/research/\`:
762
-
763
- - \`repo-scan.md\`
764
- - \`learnings-lookup.md\`
765
- - \`framework-docs-lookup.md\`
766
- - \`best-practices-lookup.md\`
767
- - \`git-history.md\`
768
-
769
- ### Activation modes
770
-
771
- ${(() => {
772
- const mode = activationModeSummary();
773
- return `- **Mandatory:** ${mode.mandatory}.
774
- - **Proactive:** ${mode.proactive}.
775
- - **On-demand:** fixer. Research playbooks are in-thread procedures.`;
776
- })()}
777
-
778
- ### Cost-aware routing
779
-
780
- ${agentCostTierTable()}
781
-
782
- **Agent files:** \`.cclaw/agents/{name}.md\` — each contains YAML frontmatter with tools and model tier.
783
- `;
52
+ export function renderAgentMarkdown(agent) {
53
+ const modes = agent.modes.map((mode) => `- ${mode}`).join("\n");
54
+ return `---\nname: ${agent.id}\ntitle: ${agent.title}\nactivation: ${agent.activation}\n---\n\n# ${agent.title}\n\n${agent.description}\n\n## Modes\n\n${modes}\n\n## Prompt\n\n${agent.prompt}\n`;
784
55
  }