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,734 +1,32 @@
1
- import fs from "node:fs/promises";
2
- import os from "node:os";
3
- import path from "node:path";
4
- export const REVIEW_LOOP_STAGES = ["scope", "design"];
5
- export const REVIEW_LOOP_DEFAULT_MAX_ITERATIONS = 3;
6
- export const REVIEW_LOOP_DEFAULT_TARGET_SCORE = 0.8;
7
- const REVIEW_LOOP_RESPONSE_SCHEMA = `{
8
- "findings": [
1
+ export const FIVE_FAILURE_MODES = [
9
2
  {
10
- "id": "F-1",
11
- "dimensionId": "<one checklist id>",
12
- "severity": "critical|important|suggestion",
13
- "summary": "what is wrong",
14
- "evidence": "artifact quote/path",
15
- "recommendation": "concrete fix"
16
- }
17
- ],
18
- "dimensionScores": [
3
+ id: "hallucinated-actions",
4
+ name: "Hallucinated actions",
5
+ description: "File paths, env vars, ids, or function names that do not exist in the repository. Cross-check every reference before reporting it as done."
6
+ },
19
7
  {
20
- "dimensionId": "<one checklist id>",
21
- "score": 0.0
22
- }
23
- ]
24
- }`;
25
- export function reviewLoopPolicySummary(stage) {
26
- const checklist = REVIEW_LOOP_CHECKLISTS[stage];
27
- const ids = checklist.map((dimension) => `\`${dimension.id}\``).join(", ");
28
- return `outside-voice review loop policy: use checklist dimensions ${ids}; stop at quality score >= ${REVIEW_LOOP_DEFAULT_TARGET_SCORE} or max ${REVIEW_LOOP_DEFAULT_MAX_ITERATIONS} iterations.`;
29
- }
30
- export function reviewLoopSecondOpinionSummary(stage) {
31
- return `when \`.cclaw/config.yaml::reviewLoop.externalSecondOpinion.enabled\` is true, run an extra external-model pass for ${stage} and explicitly reconcile score/finding disagreements.`;
32
- }
33
- export const REVIEW_LOOP_CHECKLISTS = {
34
- scope: [
35
- {
36
- id: "premise_fit",
37
- label: "Premise fit",
38
- weight: 1,
39
- guidance: "Does the scope contract solve the actual user/problem framing without drifting into adjacent asks?"
40
- },
41
- {
42
- id: "alternatives_coverage",
43
- label: "Alternatives coverage",
44
- weight: 1,
45
- guidance: "Are meaningful alternatives compared with explicit trade-offs and one clear recommendation?"
46
- },
47
- {
48
- id: "error_rescue_registry",
49
- label: "Error and rescue coverage",
50
- weight: 1,
51
- guidance: "Does each scoped capability define failure mode, detection signal, and fallback/rescue behavior?"
52
- },
53
- {
54
- id: "scope_creep_risk",
55
- label: "Scope-creep risk",
56
- weight: 1,
57
- guidance: "Are in/out boundaries explicit and protected against silent expansion/reduction language?"
58
- },
59
- {
60
- id: "completion_status_fidelity",
61
- label: "Completion status fidelity",
62
- weight: 1,
63
- guidance: "Does the completion dashboard honestly report unresolved risks, decision count, and stop reason?"
64
- }
65
- ],
66
- design: [
67
- {
68
- id: "architecture_fit",
69
- label: "Architecture fit",
70
- weight: 1,
71
- guidance: "Do architecture boundaries and diagrams align with scope and real blast-radius code?"
72
- },
73
- {
74
- id: "failure_mode_coverage",
75
- label: "Failure-mode coverage",
76
- weight: 1,
77
- guidance: "Does the failure-mode table capture method/exception/rescue/user-visible impact for critical paths?"
78
- },
79
- {
80
- id: "test_coverage_realism",
81
- label: "Test coverage realism",
82
- weight: 1,
83
- guidance: "Is the proposed test split realistic (unit/integration/e2e) with explicit gap handling?"
84
- },
85
- {
86
- id: "performance_budget",
87
- label: "Performance budget",
88
- weight: 1,
89
- guidance: "Are critical metrics, thresholds, and measurement methods concrete and enforceable?"
90
- },
91
- {
92
- id: "observability_adequacy",
93
- label: "Observability adequacy",
94
- weight: 1,
95
- guidance: "Can on-call trace a failure from user symptom to root cause via logs/metrics/traces/alerts?"
96
- }
97
- ]
98
- };
99
- function clampScore(value) {
100
- if (Number.isNaN(value))
101
- return 0;
102
- if (value < 0)
103
- return 0;
104
- if (value > 1)
105
- return 1;
106
- return value;
107
- }
108
- function normalizeBudget(budget) {
109
- const maxIterations = typeof budget?.maxIterations === "number" && Number.isInteger(budget.maxIterations)
110
- ? Math.min(Math.max(budget.maxIterations, 1), 10)
111
- : REVIEW_LOOP_DEFAULT_MAX_ITERATIONS;
112
- const targetScore = typeof budget?.targetScore === "number"
113
- ? clampScore(budget.targetScore)
114
- : REVIEW_LOOP_DEFAULT_TARGET_SCORE;
115
- return { maxIterations, targetScore };
116
- }
117
- function formatChecklistForPrompt(checklist) {
118
- return checklist
119
- .map((dimension, index) => {
120
- return `${index + 1}. [${dimension.id}] ${dimension.label} (weight=${dimension.weight})\n - ${dimension.guidance}`;
121
- })
122
- .join("\n");
123
- }
124
- function formatPriorIterationsForPrompt(priorIterations) {
125
- if (priorIterations.length === 0) {
126
- return "- none";
127
- }
128
- return priorIterations
129
- .map((row) => {
130
- return `- iteration ${row.iteration}: score=${row.qualityScore.toFixed(3)}, findings=${row.findingsCount}`;
131
- })
132
- .join("\n");
133
- }
134
- export function buildOutsideVoiceReviewPrompt(request) {
135
- return [
136
- "You are the Outside Voice adversarial reviewer.",
137
- "Review ONLY the provided artifact markdown and return strict JSON (no prose).",
138
- "",
139
- `Stage: ${request.stage}`,
140
- `Iteration: ${request.iteration}/${request.budget.maxIterations}`,
141
- `Target quality score: ${request.budget.targetScore}`,
142
- "",
143
- "Checklist dimensions:",
144
- formatChecklistForPrompt(request.checklist),
145
- "",
146
- "Prior iterations:",
147
- formatPriorIterationsForPrompt(request.priorIterations),
148
- "",
149
- "Return JSON schema:",
150
- REVIEW_LOOP_RESPONSE_SCHEMA
151
- ].join("\n");
152
- }
153
- export function createOutsideVoiceDispatcher(adapter) {
154
- return async (request) => {
155
- return adapter({
156
- request,
157
- prompt: buildOutsideVoiceReviewPrompt(request),
158
- responseSchema: REVIEW_LOOP_RESPONSE_SCHEMA
159
- });
160
- };
161
- }
162
- function normalizeSeverity(value) {
163
- if (typeof value !== "string")
164
- return "important";
165
- const normalized = value.trim().toLowerCase();
166
- if (normalized === "critical")
167
- return "critical";
168
- if (normalized === "suggestion")
169
- return "suggestion";
170
- return "important";
171
- }
172
- function asRecord(value) {
173
- if (!value || typeof value !== "object" || Array.isArray(value))
174
- return null;
175
- return value;
176
- }
177
- function parseFindings(value, checklist) {
178
- if (!Array.isArray(value))
179
- return [];
180
- const fallbackDimension = checklist[0]?.id ?? "general";
181
- const allowedDimensions = new Set(checklist.map((item) => item.id));
182
- const findings = [];
183
- value.forEach((raw, index) => {
184
- const row = asRecord(raw);
185
- if (!row)
186
- return;
187
- const summary = typeof row.summary === "string"
188
- ? row.summary.trim()
189
- : typeof row.finding === "string"
190
- ? row.finding.trim()
191
- : "";
192
- if (summary.length === 0)
193
- return;
194
- const requestedDimension = typeof row.dimensionId === "string"
195
- ? row.dimensionId
196
- : typeof row.dimension === "string"
197
- ? row.dimension
198
- : fallbackDimension;
199
- const dimensionId = allowedDimensions.has(requestedDimension)
200
- ? requestedDimension
201
- : fallbackDimension;
202
- findings.push({
203
- id: typeof row.id === "string" && row.id.trim().length > 0
204
- ? row.id.trim()
205
- : `F-${index + 1}`,
206
- dimensionId,
207
- severity: normalizeSeverity(row.severity),
208
- summary,
209
- evidence: typeof row.evidence === "string" ? row.evidence : undefined,
210
- recommendation: typeof row.recommendation === "string" ? row.recommendation : undefined
211
- });
212
- });
213
- return findings;
214
- }
215
- function inferDimensionScoresFromFindings(checklist, findings) {
216
- const byDimension = new Map(checklist.map((dimension) => [dimension.id, 1]));
217
- for (const finding of findings) {
218
- const current = byDimension.get(finding.dimensionId) ?? 1;
219
- const penalty = finding.severity === "critical"
220
- ? 0.4
221
- : finding.severity === "important"
222
- ? 0.2
223
- : 0.1;
224
- byDimension.set(finding.dimensionId, clampScore(current - penalty));
225
- }
226
- return checklist.map((dimension) => ({
227
- dimensionId: dimension.id,
228
- score: byDimension.get(dimension.id) ?? 0,
229
- weight: dimension.weight
230
- }));
231
- }
232
- function parseDimensionScores(value, checklist, findings) {
233
- if (!Array.isArray(value)) {
234
- return inferDimensionScoresFromFindings(checklist, findings);
235
- }
236
- const allowedDimensions = new Set(checklist.map((item) => item.id));
237
- const parsed = [];
238
- value.forEach((raw) => {
239
- const row = asRecord(raw);
240
- if (!row)
241
- return;
242
- const rawDimension = typeof row.dimensionId === "string"
243
- ? row.dimensionId
244
- : typeof row.dimension === "string"
245
- ? row.dimension
246
- : "";
247
- if (!allowedDimensions.has(rawDimension))
248
- return;
249
- if (typeof row.score !== "number" || Number.isNaN(row.score))
250
- return;
251
- parsed.push({
252
- dimensionId: rawDimension,
253
- score: clampScore(row.score),
254
- weight: typeof row.weight === "number" ? row.weight : undefined,
255
- rationale: typeof row.rationale === "string" ? row.rationale : undefined
256
- });
257
- });
258
- if (parsed.length === 0) {
259
- return inferDimensionScoresFromFindings(checklist, findings);
260
- }
261
- return parsed;
262
- }
263
- function unwrapDispatcherPayload(raw) {
264
- if (typeof raw === "string") {
265
- try {
266
- return JSON.parse(raw);
267
- }
268
- catch {
269
- return {
270
- findings: [{ summary: raw, severity: "important" }]
271
- };
272
- }
273
- }
274
- const record = asRecord(raw);
275
- if (!record) {
276
- return raw;
277
- }
278
- const payload = asRecord(record.payload);
279
- if (payload && (Array.isArray(payload.findings) || Array.isArray(payload.dimensionScores))) {
280
- return payload;
281
- }
282
- if (typeof record.output === "string") {
283
- try {
284
- return JSON.parse(record.output);
285
- }
286
- catch {
287
- return { findings: [{ summary: record.output, severity: "important" }] };
288
- }
289
- }
290
- if (typeof record.text === "string") {
291
- try {
292
- return JSON.parse(record.text);
293
- }
294
- catch {
295
- return { findings: [{ summary: record.text, severity: "important" }] };
296
- }
297
- }
298
- return raw;
299
- }
300
- export function parseReviewLoopDispatcherResult(raw, checklist) {
301
- const payload = unwrapDispatcherPayload(raw);
302
- const record = asRecord(payload);
303
- const findings = parseFindings(record?.findings, checklist);
304
- const dimensionScores = parseDimensionScores(record?.dimensionScores, checklist, findings);
305
- return { findings, dimensionScores };
306
- }
307
- function normalizeSecondOpinionPolicy(policy) {
308
- const enabled = policy?.enabled === true;
309
- const scoreDeltaThreshold = typeof policy?.scoreDeltaThreshold === "number"
310
- ? clampScore(policy.scoreDeltaThreshold)
311
- : 0.2;
312
- const modelLabel = typeof policy?.modelLabel === "string" && policy.modelLabel.trim().length > 0
313
- ? policy.modelLabel.trim()
314
- : undefined;
315
- return { enabled, scoreDeltaThreshold, modelLabel };
316
- }
317
- function dedupeFindings(findings) {
318
- const seen = new Set();
319
- const out = [];
320
- for (const finding of findings) {
321
- const key = `${finding.dimensionId}:${finding.severity}:${finding.summary.trim().toLowerCase()}`;
322
- if (seen.has(key))
323
- continue;
324
- seen.add(key);
325
- out.push(finding);
326
- }
327
- return out;
328
- }
329
- export function mergeSecondOpinionResults(primaryRaw, secondOpinionRaw, checklist, policy) {
330
- const normalizedPolicy = normalizeSecondOpinionPolicy(policy);
331
- const primary = parseReviewLoopDispatcherResult(primaryRaw, checklist);
332
- const secondOpinion = parseReviewLoopDispatcherResult(secondOpinionRaw, checklist);
333
- const primaryScore = aggregateQualityScore(primary.dimensionScores, checklist);
334
- const secondOpinionScore = aggregateQualityScore(secondOpinion.dimensionScores, checklist);
335
- const scoreDelta = Math.abs(primaryScore - secondOpinionScore);
336
- const byDimension = new Map();
337
- for (const dimension of checklist) {
338
- byDimension.set(dimension.id, []);
339
- }
340
- for (const row of [...primary.dimensionScores, ...secondOpinion.dimensionScores]) {
341
- const bucket = byDimension.get(row.dimensionId);
342
- if (!bucket)
343
- continue;
344
- bucket.push(clampScore(row.score));
345
- }
346
- const dimensionScores = checklist.map((dimension) => {
347
- const bucket = byDimension.get(dimension.id) ?? [];
348
- const average = bucket.length > 0 ? bucket.reduce((sum, score) => sum + score, 0) / bucket.length : 0;
349
- return {
350
- dimensionId: dimension.id,
351
- score: clampScore(average),
352
- weight: dimension.weight
353
- };
354
- });
355
- const findings = dedupeFindings([...primary.findings, ...secondOpinion.findings]);
356
- if (scoreDelta >= normalizedPolicy.scoreDeltaThreshold) {
357
- findings.push({
358
- id: "F-cross-model-disagreement",
359
- dimensionId: checklist[0]?.id ?? "general",
360
- severity: "important",
361
- summary: "Cross-model second opinion found a meaningful quality-score disagreement that needs explicit disposition.",
362
- evidence: `primary=${primaryScore.toFixed(3)} secondOpinion=${secondOpinionScore.toFixed(3)} threshold=${normalizedPolicy.scoreDeltaThreshold.toFixed(3)}`,
363
- recommendation: "Record why the team accepts one view or synthesize both findings before closing the review loop."
364
- });
365
- }
366
- return {
367
- findings,
368
- dimensionScores,
369
- secondOpinion: {
370
- enabled: true,
371
- modelLabel: normalizedPolicy.modelLabel,
372
- primaryScore,
373
- secondOpinionScore,
374
- scoreDelta,
375
- threshold: normalizedPolicy.scoreDeltaThreshold
376
- }
377
- };
378
- }
379
- export function createSecondOpinionDispatcher(args) {
380
- const normalizedPolicy = normalizeSecondOpinionPolicy(args.policy);
381
- return async (request) => {
382
- const primaryRaw = await args.primary(request);
383
- if (!normalizedPolicy.enabled || !args.secondOpinion) {
384
- return primaryRaw;
385
- }
386
- const secondOpinionRaw = await args.secondOpinion(request);
387
- return mergeSecondOpinionResults(primaryRaw, secondOpinionRaw, request.checklist, normalizedPolicy);
388
- };
389
- }
390
- export function aggregateQualityScore(scores, checklist) {
391
- if (checklist.length === 0)
392
- return 0;
393
- const byDimension = new Map(scores.map((row) => [row.dimensionId, row]));
394
- let weightedScore = 0;
395
- let totalWeight = 0;
396
- for (const dimension of checklist) {
397
- const scoreRow = byDimension.get(dimension.id);
398
- const score = clampScore(scoreRow?.score ?? 0);
399
- const weight = typeof scoreRow?.weight === "number" && scoreRow.weight > 0
400
- ? scoreRow.weight
401
- : dimension.weight;
402
- totalWeight += weight;
403
- weightedScore += score * weight;
404
- }
405
- if (totalWeight <= 0)
406
- return 0;
407
- return clampScore(weightedScore / totalWeight);
408
- }
409
- async function materializeArtifactForDispatch(artifactPath, stage, iteration) {
410
- const markdown = await fs.readFile(artifactPath, "utf8");
411
- const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), `cclaw-review-loop-${stage}-`));
412
- const tempArtifactPath = path.join(tempDir, `artifact-iteration-${iteration}.md`);
413
- await fs.writeFile(tempArtifactPath, markdown, "utf8");
414
- return { tempDir, tempArtifactPath };
415
- }
416
- export async function runReviewLoopIteration(input, dispatcher) {
417
- const checklist = input.checklist ?? REVIEW_LOOP_CHECKLISTS[input.stage];
418
- const budget = normalizeBudget(input.budget);
419
- const priorIterations = input.priorIterations ?? [];
420
- const { tempDir, tempArtifactPath } = await materializeArtifactForDispatch(input.artifactPath, input.stage, input.iteration);
421
- try {
422
- const raw = await dispatcher({
423
- stage: input.stage,
424
- artifactPath: tempArtifactPath,
425
- checklist,
426
- priorIterations,
427
- iteration: input.iteration,
428
- budget
429
- });
430
- const { findings, dimensionScores } = parseReviewLoopDispatcherResult(raw, checklist);
431
- const qualityScore = aggregateQualityScore(dimensionScores, checklist);
432
- return {
433
- qualityScore,
434
- findings,
435
- iteration: input.iteration,
436
- shouldContinue: qualityScore < budget.targetScore && input.iteration < budget.maxIterations,
437
- dimensionScores
438
- };
439
- }
440
- finally {
441
- await fs.rm(tempDir, { recursive: true, force: true });
442
- }
443
- }
444
- export function buildReviewLoopEnvelope(args) {
445
- return {
446
- type: "review-loop",
447
- version: "1",
448
- stage: args.stage,
449
- artifactPath: args.artifactPath,
450
- targetScore: args.targetScore,
451
- maxIterations: args.maxIterations,
452
- stopReason: args.stopReason,
453
- iterations: [...args.iterations]
454
- };
455
- }
456
- function formatScore(value) {
457
- return clampScore(value).toFixed(3);
458
- }
459
- function reviewLoopHeading(stage) {
460
- return stage === "scope" ? "Scope Outside Voice Loop" : "Design Outside Voice Loop";
461
- }
462
- function finalEnvelopeScore(envelope) {
463
- if (envelope.iterations.length === 0)
464
- return 0;
465
- return envelope.iterations[envelope.iterations.length - 1].qualityScore;
466
- }
467
- export function renderReviewLoopHeader(envelope) {
468
- return `> Review Loop Quality: ${formatScore(finalEnvelopeScore(envelope))} | stop: ${envelope.stopReason} | iterations: ${envelope.iterations.length}/${envelope.maxIterations}`;
469
- }
470
- export function upsertReviewLoopHeader(markdown, envelope) {
471
- const header = renderReviewLoopHeader(envelope);
472
- const existingHeader = /^>\s+Review Loop Quality:.*$/m;
473
- if (existingHeader.test(markdown)) {
474
- return markdown.replace(existingHeader, header);
475
- }
476
- const firstHeading = /^# .+$/m.exec(markdown);
477
- if (!firstHeading || firstHeading.index < 0) {
478
- const prefix = markdown.length > 0 ? `${header}\n\n` : `${header}\n`;
479
- return `${prefix}${markdown}`;
480
- }
481
- const headingEnd = firstHeading.index + firstHeading[0].length;
482
- return `${markdown.slice(0, headingEnd)}\n\n${header}${markdown.slice(headingEnd)}`;
483
- }
484
- export function renderReviewLoopSummarySection(envelope) {
485
- const rows = envelope.iterations.length > 0
486
- ? envelope.iterations
487
- .map((row) => {
488
- return `| ${row.iteration} | ${formatScore(row.qualityScore)} | ${row.findingsCount} |`;
489
- })
490
- .join("\n")
491
- : "| 0 | 0.000 | 0 |";
492
- const heading = reviewLoopHeading(envelope.stage);
493
- return `## ${heading}
494
- | Iteration | Quality Score | Findings |
495
- |---|---|---|
496
- ${rows}
497
-
498
- - Stop reason: ${envelope.stopReason}
499
- - Target score: ${formatScore(envelope.targetScore)}
500
- - Max iterations: ${envelope.maxIterations}`;
501
- }
502
- export function upsertReviewLoopSummary(markdown, envelope) {
503
- const withHeader = upsertReviewLoopHeader(markdown, envelope);
504
- const section = renderReviewLoopSummarySection(envelope);
505
- const headingCandidates = [reviewLoopHeading(envelope.stage), "Spec Review Loop"];
506
- const match = headingCandidates
507
- .map((heading) => {
508
- const escapedHeading = heading.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
509
- return new RegExp(`^##\\s+${escapedHeading}\\s*$`, "m").exec(withHeader);
510
- })
511
- .find((candidate) => candidate !== null && candidate.index >= 0);
512
- if (!match) {
513
- const needsBreak = withHeader.endsWith("\n") ? "" : "\n";
514
- return `${withHeader}${needsBreak}\n${section}\n`;
515
- }
516
- const start = match.index;
517
- const afterStart = withHeader.slice(start + match[0].length);
518
- const nextHeading = /\n##\s+/m.exec(afterStart);
519
- const end = nextHeading ? start + match[0].length + nextHeading.index + 1 : withHeader.length;
520
- return `${withHeader.slice(0, start)}${section}\n${withHeader.slice(end)}`.replace(/\n{3,}/g, "\n\n");
521
- }
522
- function extractH2Section(markdown, heading) {
523
- const escaped = heading.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
524
- const sectionStartRe = new RegExp(`^##\\s+${escaped}\\s*$`, "mi");
525
- const startMatch = sectionStartRe.exec(markdown);
526
- if (!startMatch || startMatch.index < 0) {
527
- return null;
528
- }
529
- const start = startMatch.index + startMatch[0].length;
530
- const rest = markdown.slice(start);
531
- const nextHeading = /\n##\s+/m.exec(rest);
532
- const end = nextHeading ? start + nextHeading.index + 1 : markdown.length;
533
- return markdown.slice(start, end).trim();
534
- }
535
- function normalizeStopReason(value) {
536
- if (typeof value !== "string")
537
- return null;
538
- const normalized = value.trim();
539
- if (normalized === "quality_threshold_met")
540
- return "quality_threshold_met";
541
- if (normalized === "max_iterations_reached")
542
- return "max_iterations_reached";
543
- if (normalized === "user_opt_out")
544
- return "user_opt_out";
545
- return null;
546
- }
547
- function parseScoreCell(value) {
548
- const percent = /([0-9]*\.?[0-9]+)\s*%/u.exec(value)?.[1];
549
- if (percent !== undefined) {
550
- const score = Number(percent) / 100;
551
- return Number.isFinite(score) ? clampScore(score) : null;
552
- }
553
- const direct = Number(value.trim());
554
- if (Number.isFinite(direct)) {
555
- return clampScore(direct > 1 ? direct / 100 : direct);
556
- }
557
- const embedded = /([0-9]*\.?[0-9]+)/u.exec(value)?.[1];
558
- if (embedded === undefined)
559
- return null;
560
- const score = Number(embedded);
561
- if (!Number.isFinite(score))
562
- return null;
563
- return clampScore(score > 1 ? score / 100 : score);
564
- }
565
- function parseFindingsCountCell(value) {
566
- if (/\b(?:none|zero|clear|no findings?|0)\b/iu.test(value))
567
- return 0;
568
- const match = /(\d+)/u.exec(value);
569
- if (!match)
570
- return null;
571
- const count = Number(match[1]);
572
- return Number.isInteger(count) && count >= 0 ? count : null;
573
- }
574
- function parseIterationsTable(sectionBody) {
575
- const rows = [];
576
- const lines = sectionBody.split(/\r?\n/gu);
577
- for (const line of lines) {
578
- const trimmed = line.trim();
579
- if (!trimmed.startsWith("|"))
580
- continue;
581
- const cells = trimmed
582
- .split("|")
583
- .slice(1, -1)
584
- .map((cell) => cell.trim());
585
- if (cells.length < 3)
586
- continue;
587
- if (/^iteration$/iu.test(cells[0] ?? ""))
588
- continue;
589
- if (/^-+$/u.test((cells[0] ?? "").replace(/:/gu, "")))
590
- continue;
591
- const iteration = Number(/(\d+)/u.exec(cells[0] ?? "")?.[1] ?? "");
592
- const qualityScore = parseScoreCell(cells[1] ?? "");
593
- const findingsCount = parseFindingsCountCell(cells[2] ?? "");
594
- if (!Number.isInteger(iteration) || iteration < 1)
595
- continue;
596
- if (qualityScore === null)
597
- continue;
598
- if (findingsCount === null)
599
- continue;
600
- rows.push({
601
- iteration,
602
- qualityScore,
603
- findingsCount
604
- });
605
- }
606
- rows.sort((a, b) => a.iteration - b.iteration);
607
- return rows;
608
- }
609
- function parseHeaderMeta(markdown) {
610
- const match = /^>\s*Review Loop Quality:\s*([0-9]*\.?[0-9]+)\s*\|\s*stop:\s*([a-z_]+)\s*\|\s*iterations:\s*(\d+)\s*\/\s*(\d+)\s*$/mi.exec(markdown);
611
- if (!match)
612
- return {};
613
- const score = Number(match[1]);
614
- const stopReason = normalizeStopReason(match[2] ?? "");
615
- const iterations = Number(match[3]);
616
- const maxIterations = Number(match[4]);
617
- return {
618
- score: Number.isFinite(score) ? clampScore(score) : undefined,
619
- stopReason: stopReason ?? undefined,
620
- iterations: Number.isInteger(iterations) ? iterations : undefined,
621
- maxIterations: Number.isInteger(maxIterations) ? maxIterations : undefined
622
- };
623
- }
624
- export function extractReviewLoopEnvelopeFromArtifact(markdown, stage, artifactPath) {
625
- const sectionBody = extractH2Section(markdown, reviewLoopHeading(stage))
626
- ?? extractH2Section(markdown, "Spec Review Loop");
627
- if (!sectionBody)
628
- return null;
629
- const iterations = parseIterationsTable(sectionBody);
630
- if (iterations.length === 0)
631
- return null;
632
- const stopReasonFromSection = normalizeStopReason(/-\s*Stop reason:\s*([a-z_]+)/iu.exec(sectionBody)?.[1]);
633
- const targetFromSection = parseScoreCell(/-\s*Target score:\s*([^\n]+)/iu.exec(sectionBody)?.[1] ?? "");
634
- const maxFromSection = Number(/-\s*Max iterations:\s*(\d+)/iu.exec(sectionBody)?.[1] ?? "");
635
- const header = parseHeaderMeta(markdown);
636
- const targetScore = targetFromSection !== null
637
- ? targetFromSection
638
- : REVIEW_LOOP_DEFAULT_TARGET_SCORE;
639
- const maxIterationsCandidate = Number.isInteger(maxFromSection) && maxFromSection > 0
640
- ? maxFromSection
641
- : Number.isInteger(header.maxIterations) && (header.maxIterations ?? 0) > 0
642
- ? header.maxIterations
643
- : REVIEW_LOOP_DEFAULT_MAX_ITERATIONS;
644
- const maxIterations = Math.max(maxIterationsCandidate, iterations.length);
645
- const stopReason = stopReasonFromSection
646
- ?? header.stopReason
647
- ?? (iterations[iterations.length - 1].qualityScore >= targetScore
648
- ? "quality_threshold_met"
649
- : iterations.length >= maxIterations
650
- ? "max_iterations_reached"
651
- : "user_opt_out");
652
- return {
653
- type: "review-loop",
654
- version: "1",
655
- stage,
656
- artifactPath,
657
- targetScore,
658
- maxIterations,
659
- stopReason,
660
- iterations
661
- };
662
- }
663
- export function toSkillEnvelope(envelope, emittedAt = new Date().toISOString(), agent) {
664
- return {
665
- version: "1",
666
- kind: "stage-output",
667
- stage: envelope.stage,
668
- payload: envelope,
669
- emittedAt,
670
- ...(agent ? { agent } : {})
671
- };
672
- }
673
- export async function runReviewLoop(input, options) {
674
- const budget = normalizeBudget(input.budget);
675
- const prior = [...(input.priorIterations ?? [])];
676
- const iterations = [];
677
- let stopReason = "max_iterations_reached";
678
- while (iterations.length < budget.maxIterations) {
679
- if (options.shouldOptOut?.()) {
680
- stopReason = "user_opt_out";
681
- break;
682
- }
683
- const iteration = prior.length + iterations.length + 1;
684
- const result = await runReviewLoopIteration({
685
- ...input,
686
- iteration,
687
- priorIterations: [
688
- ...prior,
689
- ...iterations.map((row) => ({
690
- iteration: row.iteration,
691
- qualityScore: row.qualityScore,
692
- findingsCount: row.findings.length
693
- }))
694
- ]
695
- }, options.dispatcher);
696
- iterations.push(result);
697
- await options.applyFindings(result);
698
- if (result.qualityScore >= budget.targetScore) {
699
- stopReason = "quality_threshold_met";
700
- break;
701
- }
702
- if (iterations.length >= budget.maxIterations) {
703
- stopReason = "max_iterations_reached";
704
- break;
705
- }
706
- }
707
- const summaryRows = [
708
- ...prior,
709
- ...iterations.map((row) => ({
710
- iteration: row.iteration,
711
- qualityScore: row.qualityScore,
712
- findingsCount: row.findings.length
713
- }))
714
- ];
715
- const finalQualityScore = summaryRows.length > 0 ? summaryRows[summaryRows.length - 1].qualityScore : 0;
716
- const envelope = buildReviewLoopEnvelope({
717
- stage: input.stage,
718
- artifactPath: input.artifactPath,
719
- targetScore: budget.targetScore,
720
- maxIterations: budget.maxIterations,
721
- stopReason,
722
- iterations: summaryRows
723
- });
724
- options.emitEnvelope?.(envelope);
725
- return {
726
- iterations,
727
- qualityScore: finalQualityScore,
728
- stopReason,
729
- envelope
730
- };
731
- }
732
- export function isReviewLoopStage(stage) {
733
- return REVIEW_LOOP_STAGES.includes(stage);
8
+ id: "scope-creep",
9
+ name: "Scope creep",
10
+ description: "Changes outside the declared AC. If the diff touches files no AC mentions, surface the question instead of proceeding."
11
+ },
12
+ {
13
+ id: "cascading-errors",
14
+ name: "Cascading errors",
15
+ description: "One fix introduces new failures (typecheck, runtime, tests). Verify build/typecheck/test is green for the affected files after each change."
16
+ },
17
+ {
18
+ id: "context-loss",
19
+ name: "Context loss",
20
+ description: "Earlier decisions, constraints, or AC text are forgotten. Re-read plan.md frontmatter and AC list before each iteration."
21
+ },
22
+ {
23
+ id: "tool-misuse",
24
+ name: "Tool misuse",
25
+ description: "Tool used in the wrong mode or without understanding effects (force pushes, destructive deletes, ambiguous patches). Pause and ask."
26
+ }
27
+ ];
28
+ export const REVIEW_ITERATION_HARD_CAP = 5;
29
+ export function failureModesChecklist() {
30
+ const items = FIVE_FAILURE_MODES.map((mode, index) => `${index + 1}. **${mode.name}** — ${mode.description}`).join("\n");
31
+ return `### Review checklist — Five Failure Modes\n\n${items}\n\nHard cap: stop after ${REVIEW_ITERATION_HARD_CAP} review/fix iterations and report what remains.`;
734
32
  }