cclaw-cli 0.48.35 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +54 -82
  2. package/dist/artifact-linter.d.ts +4 -0
  3. package/dist/artifact-linter.js +24 -3
  4. package/dist/cli.d.ts +1 -19
  5. package/dist/cli.js +49 -495
  6. package/dist/constants.d.ts +2 -13
  7. package/dist/constants.js +1 -46
  8. package/dist/content/closeout-guidance.d.ts +14 -0
  9. package/dist/content/closeout-guidance.js +42 -0
  10. package/dist/content/core-agents.js +51 -9
  11. package/dist/content/decision-protocol.d.ts +12 -0
  12. package/dist/content/decision-protocol.js +20 -0
  13. package/dist/content/diff-command.d.ts +1 -2
  14. package/dist/content/diff-command.js +8 -94
  15. package/dist/content/examples.d.ts +4 -10
  16. package/dist/content/examples.js +10 -20
  17. package/dist/content/hook-events.js +2 -2
  18. package/dist/content/hook-inline-snippets.d.ts +5 -2
  19. package/dist/content/hook-inline-snippets.js +33 -1
  20. package/dist/content/hook-manifest.d.ts +3 -4
  21. package/dist/content/hook-manifest.js +11 -12
  22. package/dist/content/hooks.js +2 -0
  23. package/dist/content/ideate-command.d.ts +2 -0
  24. package/dist/content/ideate-command.js +31 -25
  25. package/dist/content/iron-laws.d.ts +5 -5
  26. package/dist/content/iron-laws.js +5 -5
  27. package/dist/content/learnings.d.ts +3 -4
  28. package/dist/content/learnings.js +24 -50
  29. package/dist/content/meta-skill.js +31 -24
  30. package/dist/content/next-command.js +38 -38
  31. package/dist/content/node-hooks.js +17 -343
  32. package/dist/content/opencode-plugin.js +2 -100
  33. package/dist/content/research-playbooks.js +14 -14
  34. package/dist/content/review-loop.d.ts +2 -0
  35. package/dist/content/review-loop.js +8 -0
  36. package/dist/content/session-hooks.js +14 -46
  37. package/dist/content/skills.d.ts +0 -5
  38. package/dist/content/skills.js +53 -128
  39. package/dist/content/stage-common-guidance.d.ts +0 -1
  40. package/dist/content/stage-common-guidance.js +15 -14
  41. package/dist/content/stage-schema.d.ts +26 -1
  42. package/dist/content/stage-schema.js +121 -40
  43. package/dist/content/stages/_lint-metadata/index.js +9 -15
  44. package/dist/content/stages/brainstorm.js +22 -43
  45. package/dist/content/stages/design.js +37 -57
  46. package/dist/content/stages/plan.js +22 -13
  47. package/dist/content/stages/review.js +24 -27
  48. package/dist/content/stages/scope.js +34 -46
  49. package/dist/content/stages/ship.js +7 -4
  50. package/dist/content/stages/spec.js +20 -9
  51. package/dist/content/stages/tdd.js +64 -44
  52. package/dist/content/start-command.js +10 -12
  53. package/dist/content/status-command.d.ts +2 -7
  54. package/dist/content/status-command.js +19 -146
  55. package/dist/content/subagents.d.ts +0 -5
  56. package/dist/content/subagents.js +47 -28
  57. package/dist/content/templates.d.ts +1 -1
  58. package/dist/content/templates.js +126 -135
  59. package/dist/content/track-render-context.d.ts +17 -0
  60. package/dist/content/track-render-context.js +44 -0
  61. package/dist/content/tree-command.d.ts +1 -2
  62. package/dist/content/tree-command.js +4 -87
  63. package/dist/content/utility-skills.d.ts +2 -29
  64. package/dist/content/utility-skills.js +2 -1533
  65. package/dist/content/view-command.js +29 -11
  66. package/dist/delegation.d.ts +1 -1
  67. package/dist/delegation.js +5 -15
  68. package/dist/doctor-registry.js +20 -21
  69. package/dist/doctor.js +88 -408
  70. package/dist/flow-state.d.ts +3 -0
  71. package/dist/flow-state.js +2 -0
  72. package/dist/harness-adapters.d.ts +1 -1
  73. package/dist/harness-adapters.js +48 -57
  74. package/dist/install.js +128 -520
  75. package/dist/internal/advance-stage.js +3 -9
  76. package/dist/internal/compound-readiness.d.ts +1 -1
  77. package/dist/internal/compound-readiness.js +1 -1
  78. package/dist/internal/tdd-loop-status.d.ts +1 -1
  79. package/dist/internal/tdd-loop-status.js +1 -1
  80. package/dist/knowledge-store.d.ts +16 -10
  81. package/dist/knowledge-store.js +51 -15
  82. package/dist/policy.js +16 -109
  83. package/dist/run-archive.d.ts +4 -6
  84. package/dist/run-archive.js +15 -20
  85. package/dist/run-persistence.d.ts +2 -2
  86. package/dist/run-persistence.js +3 -9
  87. package/package.json +1 -2
  88. package/dist/content/archive-command.d.ts +0 -2
  89. package/dist/content/archive-command.js +0 -124
  90. package/dist/content/compound-command.d.ts +0 -5
  91. package/dist/content/compound-command.js +0 -193
  92. package/dist/content/contexts.d.ts +0 -9
  93. package/dist/content/contexts.js +0 -65
  94. package/dist/content/contracts.d.ts +0 -2
  95. package/dist/content/contracts.js +0 -51
  96. package/dist/content/doctor-references.d.ts +0 -2
  97. package/dist/content/doctor-references.js +0 -150
  98. package/dist/content/eval-scaffold.d.ts +0 -15
  99. package/dist/content/eval-scaffold.js +0 -370
  100. package/dist/content/feature-command.d.ts +0 -2
  101. package/dist/content/feature-command.js +0 -123
  102. package/dist/content/flow-map.d.ts +0 -23
  103. package/dist/content/flow-map.js +0 -134
  104. package/dist/content/harness-doc.d.ts +0 -2
  105. package/dist/content/harness-doc.js +0 -202
  106. package/dist/content/harness-playbooks.d.ts +0 -24
  107. package/dist/content/harness-playbooks.js +0 -393
  108. package/dist/content/harness-tool-refs.d.ts +0 -20
  109. package/dist/content/harness-tool-refs.js +0 -268
  110. package/dist/content/ops-command.d.ts +0 -2
  111. package/dist/content/ops-command.js +0 -71
  112. package/dist/content/protocols.d.ts +0 -7
  113. package/dist/content/protocols.js +0 -215
  114. package/dist/content/retro-command.d.ts +0 -2
  115. package/dist/content/retro-command.js +0 -165
  116. package/dist/content/rewind-command.d.ts +0 -2
  117. package/dist/content/rewind-command.js +0 -106
  118. package/dist/content/tdd-log-command.d.ts +0 -2
  119. package/dist/content/tdd-log-command.js +0 -85
  120. package/dist/eval/agents/single-shot.d.ts +0 -27
  121. package/dist/eval/agents/single-shot.js +0 -79
  122. package/dist/eval/agents/with-tools.d.ts +0 -44
  123. package/dist/eval/agents/with-tools.js +0 -261
  124. package/dist/eval/agents/workflow.d.ts +0 -31
  125. package/dist/eval/agents/workflow.js +0 -155
  126. package/dist/eval/baseline.d.ts +0 -38
  127. package/dist/eval/baseline.js +0 -282
  128. package/dist/eval/config-loader.d.ts +0 -14
  129. package/dist/eval/config-loader.js +0 -395
  130. package/dist/eval/corpus.d.ts +0 -30
  131. package/dist/eval/corpus.js +0 -330
  132. package/dist/eval/cost-guard.d.ts +0 -102
  133. package/dist/eval/cost-guard.js +0 -190
  134. package/dist/eval/diff.d.ts +0 -64
  135. package/dist/eval/diff.js +0 -323
  136. package/dist/eval/llm-client.d.ts +0 -176
  137. package/dist/eval/llm-client.js +0 -267
  138. package/dist/eval/mode.d.ts +0 -28
  139. package/dist/eval/mode.js +0 -61
  140. package/dist/eval/progress.d.ts +0 -83
  141. package/dist/eval/progress.js +0 -59
  142. package/dist/eval/report.d.ts +0 -11
  143. package/dist/eval/report.js +0 -181
  144. package/dist/eval/rubric-loader.d.ts +0 -20
  145. package/dist/eval/rubric-loader.js +0 -143
  146. package/dist/eval/runner.d.ts +0 -81
  147. package/dist/eval/runner.js +0 -746
  148. package/dist/eval/runs.d.ts +0 -41
  149. package/dist/eval/runs.js +0 -114
  150. package/dist/eval/sandbox.d.ts +0 -38
  151. package/dist/eval/sandbox.js +0 -137
  152. package/dist/eval/tools/glob.d.ts +0 -2
  153. package/dist/eval/tools/glob.js +0 -163
  154. package/dist/eval/tools/grep.d.ts +0 -2
  155. package/dist/eval/tools/grep.js +0 -152
  156. package/dist/eval/tools/index.d.ts +0 -7
  157. package/dist/eval/tools/index.js +0 -35
  158. package/dist/eval/tools/read.d.ts +0 -2
  159. package/dist/eval/tools/read.js +0 -122
  160. package/dist/eval/tools/types.d.ts +0 -49
  161. package/dist/eval/tools/types.js +0 -41
  162. package/dist/eval/tools/write.d.ts +0 -2
  163. package/dist/eval/tools/write.js +0 -92
  164. package/dist/eval/types.d.ts +0 -561
  165. package/dist/eval/types.js +0 -47
  166. package/dist/eval/verifiers/judge.d.ts +0 -40
  167. package/dist/eval/verifiers/judge.js +0 -256
  168. package/dist/eval/verifiers/rules.d.ts +0 -24
  169. package/dist/eval/verifiers/rules.js +0 -218
  170. package/dist/eval/verifiers/structural.d.ts +0 -14
  171. package/dist/eval/verifiers/structural.js +0 -171
  172. package/dist/eval/verifiers/traceability.d.ts +0 -23
  173. package/dist/eval/verifiers/traceability.js +0 -84
  174. package/dist/eval/verifiers/workflow-consistency.d.ts +0 -21
  175. package/dist/eval/verifiers/workflow-consistency.js +0 -225
  176. package/dist/eval/workflow-corpus.d.ts +0 -7
  177. package/dist/eval/workflow-corpus.js +0 -207
  178. package/dist/feature-system.d.ts +0 -42
  179. package/dist/feature-system.js +0 -432
  180. package/dist/internal/knowledge-digest.d.ts +0 -7
  181. package/dist/internal/knowledge-digest.js +0 -93
@@ -3,6 +3,7 @@ import { STAGE_TO_SKILL_FOLDER } from "../constants.js";
3
3
  import { BRAINSTORM, SCOPE, DESIGN, SPEC, PLAN, TDD, REVIEW, SHIP } from "./stages/index.js";
4
4
  import { stagePolicyNeedlesFromMetadata } from "./stages/_lint-metadata/index.js";
5
5
  import { tddStageForTrack } from "./stages/tdd.js";
6
+ import { trackRenderContext } from "./track-render-context.js";
6
7
  // ---------------------------------------------------------------------------
7
8
  // NOTE: The former QUESTION_FORMAT_SPEC / ERROR_BUDGET_SPEC exports were
8
9
  // hoisted into `src/content/meta-skill.ts` (Shared Decision + Tool-Use
@@ -14,6 +15,7 @@ export const SKILL_ENVELOPE_KINDS = [
14
15
  "gate-result",
15
16
  "delegation-record"
16
17
  ];
18
+ export const NON_FLOW_ENVELOPE_STAGE = "non-flow";
17
19
  const FLOW_STAGE_SET = new Set(FLOW_STAGES);
18
20
  const SKILL_ENVELOPE_KIND_SET = new Set(SKILL_ENVELOPE_KINDS);
19
21
  const COMPLEXITY_TIER_ORDER = {
@@ -21,6 +23,93 @@ const COMPLEXITY_TIER_ORDER = {
21
23
  standard: 1,
22
24
  deep: 2
23
25
  };
26
+ const REVIEW_STACK_AWARE_ROUTES = [
27
+ {
28
+ stack: "TypeScript/JavaScript",
29
+ agent: "reviewer",
30
+ signals: ["package.json", "tsconfig.json"],
31
+ focus: "type safety, package scripts, build/test config, dependency boundaries"
32
+ },
33
+ {
34
+ stack: "Python",
35
+ agent: "reviewer",
36
+ signals: ["pyproject.toml", "requirements.txt"],
37
+ focus: "packaging, virtualenv assumptions, typing, pytest or unittest evidence"
38
+ },
39
+ {
40
+ stack: "Ruby/Rails",
41
+ agent: "reviewer",
42
+ signals: ["Gemfile", "config/"],
43
+ focus: "Rails conventions, migrations, routes/controllers, RSpec or Minitest evidence"
44
+ },
45
+ {
46
+ stack: "Go",
47
+ agent: "reviewer",
48
+ signals: ["go.mod"],
49
+ focus: "interfaces, concurrency, error handling, go test coverage"
50
+ },
51
+ {
52
+ stack: "Rust",
53
+ agent: "reviewer",
54
+ signals: ["Cargo.toml"],
55
+ focus: "ownership, error/result handling, feature flags, cargo test coverage"
56
+ }
57
+ ];
58
+ function stackAwareRoutesForStage(stage) {
59
+ return stage === "review" ? reviewStackAwareRoutes() : [];
60
+ }
61
+ export function reviewStackAwareRoutes() {
62
+ return REVIEW_STACK_AWARE_ROUTES.map((route) => ({
63
+ ...route,
64
+ signals: [...route.signals]
65
+ }));
66
+ }
67
+ export function reviewStackAwareRoutingSummary() {
68
+ const routeList = REVIEW_STACK_AWARE_ROUTES
69
+ .map((route) => `${route.stack} via ${route.signals.join("/")}`)
70
+ .join("; ");
71
+ return `Stack-aware review routing: keep the default reviewer and security-reviewer passes, then proactively route matching reviewer lenses when repo signals or review context match (${routeList}). Do not run every stack lens unconditionally.`;
72
+ }
73
+ function dedupeAgentsInOrder(agents) {
74
+ const out = [];
75
+ const seen = new Set();
76
+ for (const agent of agents) {
77
+ if (seen.has(agent))
78
+ continue;
79
+ seen.add(agent);
80
+ out.push(agent);
81
+ }
82
+ return out;
83
+ }
84
+ /**
85
+ * Canonical delegation summary derived from STAGE_AUTO_SUBAGENT_DISPATCH.
86
+ *
87
+ * Keep all generated routing surfaces (skills, AGENTS.md) on this helper so
88
+ * stage->agent defaults are maintained in one place.
89
+ */
90
+ export function stageDelegationSummary(complexityTier = "standard") {
91
+ const currentTierRank = COMPLEXITY_TIER_ORDER[complexityTier];
92
+ return FLOW_STAGES.map((stage) => {
93
+ const eligibleRows = STAGE_AUTO_SUBAGENT_DISPATCH[stage].filter((row) => {
94
+ const requiredAt = row.requiredAtTier ?? "standard";
95
+ return currentTierRank >= COMPLEXITY_TIER_ORDER[requiredAt];
96
+ });
97
+ const mandatoryAgents = dedupeAgentsInOrder(eligibleRows
98
+ .filter((row) => row.mode === "mandatory")
99
+ .map((row) => row.agent));
100
+ const proactiveAgents = dedupeAgentsInOrder(eligibleRows
101
+ .filter((row) => row.mode === "proactive")
102
+ .map((row) => row.agent));
103
+ const primaryAgents = dedupeAgentsInOrder([...mandatoryAgents, ...proactiveAgents]);
104
+ return {
105
+ stage,
106
+ mandatoryAgents,
107
+ proactiveAgents,
108
+ primaryAgents,
109
+ stackAwareRoutes: stackAwareRoutesForStage(stage)
110
+ };
111
+ });
112
+ }
24
113
  function asRecord(value) {
25
114
  if (!value || typeof value !== "object" || Array.isArray(value)) {
26
115
  return null;
@@ -39,8 +128,9 @@ export function validateSkillEnvelope(value) {
39
128
  if (typeof record.kind !== "string" || !SKILL_ENVELOPE_KIND_SET.has(record.kind)) {
40
129
  errors.push(`envelope.kind must be one of: ${SKILL_ENVELOPE_KINDS.join(", ")}.`);
41
130
  }
42
- if (typeof record.stage !== "string" || !FLOW_STAGE_SET.has(record.stage)) {
43
- errors.push(`envelope.stage must be one of: ${FLOW_STAGES.join(", ")}.`);
131
+ if (typeof record.stage !== "string" ||
132
+ (record.stage !== NON_FLOW_ENVELOPE_STAGE && !FLOW_STAGE_SET.has(record.stage))) {
133
+ errors.push(`envelope.stage must be one of: ${FLOW_STAGES.join(", ")} or ${NON_FLOW_ENVELOPE_STAGE}.`);
44
134
  }
45
135
  if (!Object.prototype.hasOwnProperty.call(record, "payload")) {
46
136
  errors.push("envelope.payload is required.");
@@ -114,15 +204,19 @@ const REQUIRED_GATE_IDS = {
114
204
  spec: [
115
205
  "spec_acceptance_measurable",
116
206
  "spec_testability_confirmed",
207
+ "spec_assumptions_surfaced",
117
208
  "spec_user_approved"
118
209
  ],
119
210
  plan: [
120
211
  "plan_tasks_sliced_2_5_min",
121
212
  "plan_dependency_batches_defined",
122
213
  "plan_acceptance_mapped",
214
+ "plan_execution_posture_recorded",
123
215
  "plan_wait_for_confirm"
124
216
  ],
125
217
  tdd: (track) => [
218
+ "tdd_test_discovery_complete",
219
+ "tdd_impact_check_complete",
126
220
  "tdd_red_test_written",
127
221
  "tdd_green_full_suite",
128
222
  "tdd_refactor_completed",
@@ -164,10 +258,10 @@ const REQUIRED_ARTIFACT_SECTIONS = {
164
258
  "Deployment & Rollout",
165
259
  "Completion Dashboard"
166
260
  ],
167
- spec: ["Acceptance Criteria", "Edge Cases", "Testability Map", "Approval"],
168
- plan: ["Task List", "Dependency Batches", "Acceptance Mapping", "WAIT_FOR_CONFIRM"],
169
- tdd: ["RED Evidence", "GREEN Evidence", "REFACTOR Notes", "Traceability", "Verification Ladder"],
170
- review: ["Layer 1 Verdict", "Review Army Contract", "Severity Summary", "Final Verdict"],
261
+ spec: ["Acceptance Criteria", "Edge Cases", "Assumptions Before Finalization", "Testability Map", "Approval"],
262
+ plan: ["Task List", "Dependency Batches", "Acceptance Mapping", "Execution Posture", "WAIT_FOR_CONFIRM"],
263
+ tdd: ["Test Discovery", "System-Wide Impact Check", "RED Evidence", "GREEN Evidence", "REFACTOR Notes", "Traceability", "Verification Ladder"],
264
+ review: ["Layer 1 Verdict", "Review Findings Contract", "Severity Summary", "Final Verdict"],
171
265
  ship: ["Preflight Results", "Release Notes", "Rollback Plan", "Finalization"]
172
266
  };
173
267
  function resolveRequiredGateIds(stage, track) {
@@ -328,28 +422,10 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
328
422
  agent: "test-author",
329
423
  mode: "mandatory",
330
424
  requiredAtTier: "lightweight",
331
- when: "Always during TDD cycle (RED phase).",
332
- purpose: "Produce failing RED tests only; no production writes.",
425
+ when: "Always during the TDD cycle.",
426
+ purpose: "Own phase-specific RED/GREEN/REFACTOR evidence for each slice: failing tests before production writes, minimal GREEN implementation, then behavior-preserving refactor notes.",
333
427
  requiresUserGate: false,
334
- skill: "tdd-red-phase"
335
- },
336
- {
337
- agent: "test-author",
338
- mode: "mandatory",
339
- requiredAtTier: "lightweight",
340
- when: "Always during TDD cycle (GREEN phase).",
341
- purpose: "Implement minimum production changes to satisfy RED and prove full-suite GREEN.",
342
- requiresUserGate: false,
343
- skill: "tdd-green-phase"
344
- },
345
- {
346
- agent: "test-author",
347
- mode: "mandatory",
348
- requiredAtTier: "lightweight",
349
- when: "Always during TDD cycle (REFACTOR phase).",
350
- purpose: "Refactor only after GREEN proof, preserving behavior and test pass state.",
351
- requiresUserGate: false,
352
- skill: "tdd-refactor-phase"
428
+ skill: "tdd-cycle-evidence"
353
429
  },
354
430
  {
355
431
  agent: "doc-updater",
@@ -365,7 +441,7 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
365
441
  mode: "mandatory",
366
442
  requiredAtTier: "lightweight",
367
443
  when: "Always in review stage.",
368
- purpose: "Layer 1 spec compliance pass plus coordination of parallel Layer 2 fan-out (correctness, performance, architecture, external-safety) with source-tagged findings.",
444
+ purpose: "Layer 1 spec compliance plus integrated Layer 2 review across correctness, performance, architecture, and external-safety tags with source-tagged findings.",
369
445
  requiresUserGate: false,
370
446
  skill: "review-spec-pass"
371
447
  },
@@ -380,10 +456,9 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
380
456
  },
381
457
  {
382
458
  agent: "reviewer",
383
- mode: "mandatory",
384
- requiredAtTier: "lightweight",
385
- when: "Mandatory when the diff exceeds 100 changed lines, touches more than 10 files, or modifies trust boundaries — dispatch a SECOND, independent reviewer with the adversarial-review skill loaded so the review army has at least two voices on a high-blast-radius change.",
386
- purpose: "Adversarial second-opinion review on large or trust-sensitive diffs. The second reviewer treats the implementation as hostile and tries to break it (hostile-user, future-maintainer, competitor lenses) instead of sympathetically explaining it.",
459
+ mode: "proactive",
460
+ when: "When trust boundaries changed, Critical/Important ambiguity remains, or the diff is both large and high-risk.",
461
+ purpose: "Adversarial second-opinion review for genuinely high-blast-radius changes. Treat the implementation as hostile and try to break it before ship.",
387
462
  requiresUserGate: false,
388
463
  skill: "adversarial-review"
389
464
  },
@@ -394,6 +469,14 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
394
469
  purpose: "Run the receiving-code-review workflow so every incoming feedback item gets an explicit disposition with evidence, and the queue is mirrored into review artifacts.",
395
470
  requiresUserGate: false,
396
471
  skill: "receiving-code-review"
472
+ },
473
+ {
474
+ agent: "reviewer",
475
+ mode: "proactive",
476
+ when: "When repo signals or review context indicate TypeScript/JavaScript, Python, Ruby/Rails, Go, or Rust coverage is relevant.",
477
+ purpose: "Route a matching stack-aware reviewer lens while keeping the default general review pass intact; do not run every stack lens unconditionally.",
478
+ requiresUserGate: false,
479
+ skill: "stack-aware-review"
397
480
  }
398
481
  ],
399
482
  ship: [
@@ -416,14 +499,9 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
416
499
  };
417
500
  /** Transition guard: agents with `mode: "mandatory"` in auto-subagent dispatch for this stage. */
418
501
  export function mandatoryDelegationsForStage(stage, complexityTier = "standard") {
419
- const currentTierRank = COMPLEXITY_TIER_ORDER[complexityTier];
420
- return [...new Set(STAGE_AUTO_SUBAGENT_DISPATCH[stage]
421
- .filter((d) => d.mode === "mandatory")
422
- .filter((d) => {
423
- const requiredAt = d.requiredAtTier ?? "standard";
424
- return currentTierRank >= COMPLEXITY_TIER_ORDER[requiredAt];
425
- })
426
- .map((d) => d.agent))];
502
+ const summary = stageDelegationSummary(complexityTier)
503
+ .find((row) => row.stage === stage);
504
+ return summary ? summary.mandatoryAgents : [];
427
505
  }
428
506
  export function stageSchema(stage, track = "standard") {
429
507
  const rawInput = stage === "tdd" ? tddStageForTrack(track) : STAGE_SCHEMA_MAP[stage];
@@ -538,6 +616,9 @@ export function buildTransitionRules() {
538
616
  export function stagePolicyNeedles(stage, track = "standard") {
539
617
  return stagePolicyNeedlesFromMetadata(stage, track);
540
618
  }
619
+ export function stageTrackRenderContext(track = "standard") {
620
+ return trackRenderContext(track);
621
+ }
541
622
  export function stageAutoSubagentDispatch(stage) {
542
623
  return STAGE_AUTO_SUBAGENT_DISPATCH[stage];
543
624
  }
@@ -1,4 +1,5 @@
1
1
  import { SHIP_FINALIZATION_MODES } from "../../../constants.js";
2
+ import { renderTrackTerminology, trackRenderContext } from "../../track-render-context.js";
2
3
  const STAGE_POLICY_NEEDLES = {
3
4
  brainstorm: [
4
5
  "Explore project context",
@@ -25,13 +26,14 @@ const STAGE_POLICY_NEEDLES = {
25
26
  "Performance Budget",
26
27
  "One issue at a time"
27
28
  ],
28
- spec: ["Acceptance Criteria", "Constraints", "Testability", "approved spec", "Edge Cases"],
29
+ spec: ["Acceptance Criteria", "Constraints", "Assumptions Before Finalization", "Testability", "approved spec", "Edge Cases"],
29
30
  plan: [
30
31
  "WAIT_FOR_CONFIRM",
31
32
  "Task Graph",
32
33
  "Dependency Batches",
33
34
  "Acceptance Mapping",
34
35
  "verification steps",
36
+ "Execution Posture",
35
37
  "Locked Decision Coverage"
36
38
  ],
37
39
  tdd: [
@@ -39,6 +41,8 @@ const STAGE_POLICY_NEEDLES = {
39
41
  "GREEN",
40
42
  "REFACTOR",
41
43
  "failing test",
44
+ "Test Discovery",
45
+ "System-Wide Impact Check",
42
46
  "full test suite",
43
47
  "acceptance criteria",
44
48
  "traceable to plan slice"
@@ -47,7 +51,7 @@ const STAGE_POLICY_NEEDLES = {
47
51
  "Layer 1",
48
52
  "Layer 2",
49
53
  "Critical",
50
- "Review Army",
54
+ "Review Findings",
51
55
  "Ready to Ship",
52
56
  "ROUTE_BACK_TO_TDD",
53
57
  "One issue at a time"
@@ -59,21 +63,11 @@ const STAGE_POLICY_NEEDLES = {
59
63
  ...SHIP_FINALIZATION_MODES
60
64
  ]
61
65
  };
62
- function quickTrackText(value) {
63
- return value
64
- .replace(/\btask from the plan\b/giu, "acceptance criterion from the spec")
65
- .replace(/\bplan task ID\b/giu, "acceptance criterion ID")
66
- .replace(/\bplan task\b/giu, "acceptance criterion")
67
- .replace(/\bplan row\b/giu, "acceptance row")
68
- .replace(/\bplan slice\b/giu, "acceptance slice")
69
- .replace(/\bplan artifact\b/giu, "spec artifact")
70
- .replace(/\btraceable to plan slice\b/giu, "traceable to acceptance criterion")
71
- .replace(/05-plan\.md/gu, "04-spec.md");
72
- }
73
66
  export function stagePolicyNeedlesFromMetadata(stage, track = "standard") {
74
67
  const needles = STAGE_POLICY_NEEDLES[stage];
75
- if (stage === "tdd" && track === "quick") {
76
- return needles.map(quickTrackText);
68
+ const renderContext = trackRenderContext(track);
69
+ if (stage === "tdd" && !renderContext.usesPlanTerminology) {
70
+ return needles.map((needle) => renderTrackTerminology(needle, renderContext));
77
71
  }
78
72
  return [...needles];
79
73
  }
@@ -36,52 +36,31 @@ export const BRAINSTORM = {
36
36
  },
37
37
  executionModel: {
38
38
  checklist: [
39
- "**Explore project context** — check files, docs, recent commits to understand what already exists.",
40
- "**Assess depth tier first** — classify the request as Lightweight / Standard / Deep. Lightweight = narrow/localized ask; Standard = cross-module but bounded; Deep = platform or multi-surface product change.",
41
- "**Assess scope** — if the request covers multiple independent subsystems, flag it and help decompose before deep-diving. Each sub-project gets its own brainstorm cycle.",
42
- "**Short-circuit gate** — if requirements are already concrete and unambiguous, write a minimal brainstorm stub (problem + approved intent + constraints) and hand off to scope.",
43
- "**Ask clarifying questions** — one at a time, understand purpose, constraints, and success criteria. Prefer multiple choice when possible. Each question should change what we build, not just gather trivia.",
44
- "**Propose 2-3 architecturally distinct approaches** — with real trade-offs and no recommendation yet. At least one option must be a higher-upside challenger that raises ambition vs the user's initial ask.",
45
- "**Collect user reaction** — ask which approach feels closest and what concerns remain before stating your recommendation.",
46
- "**Recommend only after reaction** — present final recommendation with rationale that explicitly references user feedback.",
47
- "**Plant-seed shelf (optional)** — when a non-selected approach is still promising, capture it as `.cclaw/seeds/SEED-<YYYY-MM-DD>-<slug>.md` with `trigger_when`, hypothesis, and suggested action instead of losing it.",
48
- "**Present design by sections** — scale each section to its complexity. Ask after each section whether it looks right so far. Cover: architecture, key components, data flow.",
49
- "**Optional visual companion** — when architecture/data flow complexity is medium+ offer a compact diagram (ASCII or Mermaid) before artifact write-up.",
50
- "**Write artifact** to `.cclaw/artifacts/01-brainstorm-<slug>.md`.",
51
- "**Document-quality pass** — run a brief adversarial review of the artifact (gaps, contradictions, missing trade-offs), then patch before user review.",
52
- "**Self-review** — scan for placeholders/TODOs, check internal consistency, verify scope is focused, resolve any ambiguity.",
53
- "**User reviews artifact** — ask the user to review the written artifact and explicitly approve or request changes.",
54
- "**Handoff** — only then complete stage and point to `/cc-next`."
39
+ "**Explore project context** — inspect existing files/docs/recent activity before asking what to build.",
40
+ "**Classify depth and scope** — pick Lightweight / Standard / Deep; decompose independent subsystems before deeper work.",
41
+ "**Short-circuit concrete asks** — for unambiguous requests, write a compact brainstorm stub (context, problem, approved intent, constraints, assumptions) and ask for one explicit approval.",
42
+ "**Ask only decision-changing questions** — one at a time; if answers would not change approach, state the assumption and continue.",
43
+ "**Compare 2-3 distinct approaches** — include real trade-offs, withhold recommendation, and include one higher-upside challenger.",
44
+ "**Collect reaction before recommending** — ask which option feels closest and what concern remains, then recommend based on that reaction.",
45
+ "**Write and tighten the artifact** — scale sections to complexity, optionally add a compact diagram, then patch contradictions, weak trade-offs, placeholders, and ambiguity.",
46
+ "**Request explicit approval** — state exactly what direction is being approved; do not advance without approval and artifact review.",
47
+ "**Handoff** — only after approval, complete the stage and point to `/cc-next`."
55
48
  ],
56
49
  interactionProtocol: [
57
- "Explore what exists before asking what to build check project files first.",
58
- "If the idea is vague or could mean many different things, your FIRST question narrows to a specific kind of project. Do not ask detail questions until the project type is clear.",
59
- "Ask exactly one question per turn. Prefer multiple choice. No bundled questions.",
60
- "After 2-3 questions, summarize your emerging understanding before continuing so the user can correct course early.",
61
- "Each question should change a concrete design decision. Litmus test: if the two most likely answers do not lead to different architectures, make the choice yourself and state it.",
62
- "Present design in sections scaled to their complexity — a few sentences for simple aspects, detailed for nuanced ones. Get approval after each section.",
63
- "When proposing approaches, do NOT reveal your recommendation yet. Present options first, gather reaction, then recommend.",
64
- "At least one approach must be a higher-upside challenger; avoid three same-altitude variants.",
65
- "State explicitly what is being approved when requesting approval.",
66
- "Run a brief self-review (placeholders, contradictions, scope, ambiguity) before presenting the artifact.",
67
- "**STOP.** Wait for explicit user approval after writing the artifact. Do NOT auto-advance."
50
+ "Start from observed project context; if the idea is vague, first narrow the project type.",
51
+ "Ask at most one question per turn, only when decision-changing; prefer multiple choice, and summarize after 2-3 answers.",
52
+ "If likely answers do not change architecture or scope boundaries, choose the default and state the assumption.",
53
+ "Show approaches before the recommendation; include a higher-upside challenger and gather reaction first.",
54
+ "State exactly what is being approved, then **STOP** until the user explicitly approves the artifact."
68
55
  ],
69
56
  process: [
70
- "Explore project context: check files, docs, recent activity.",
71
- "Classify depth tier (Lightweight / Standard / Deep) before diving.",
72
- "Assess scope: flag if request is too broad, help decompose first.",
73
- "Apply short-circuit when requirements are already concrete enough for scope.",
74
- "Ask clarifying questions one at a time — focus on purpose, constraints, success criteria.",
75
- "Propose 2-3 architecturally distinct approaches with trade-offs (one must be higher-upside challenger).",
76
- "Collect user reaction before giving your recommendation.",
77
- "Recommend after reaction and explain how feedback changed the recommendation.",
78
- "Optionally plant promising non-selected approaches into `.cclaw/seeds/SEED-<YYYY-MM-DD>-<slug>.md` with trigger_when/action notes.",
79
- "Present design sections incrementally, get approval after each.",
80
- "Write approved direction to `.cclaw/artifacts/01-brainstorm-<slug>.md`.",
81
- "Run document-quality pass to close contradictions and weak trade-off reasoning.",
82
- "Self-review: placeholder scan, internal consistency, scope check, ambiguity check.",
83
- "Request explicit user approval of the artifact.",
84
- "Handoff to scope only after approval is explicit."
57
+ "Explore project context and classify depth/scope.",
58
+ "Short-circuit concrete asks or ask one decision-changing question at a time.",
59
+ "Compare 2-3 distinct approaches, including a higher-upside challenger.",
60
+ "Collect reaction, then recommend with rationale tied to that reaction.",
61
+ "Optionally park promising non-selected ideas in `.cclaw/seeds/`.",
62
+ "Write and self-review `.cclaw/artifacts/01-brainstorm-<slug>.md`.",
63
+ "Request explicit approval before handoff to scope."
85
64
  ],
86
65
  requiredGates: [
87
66
  { id: "brainstorm_approaches_compared", description: "2-3 architecturally distinct approaches were compared with real trade-offs and a recommendation." },
@@ -139,7 +118,7 @@ export const BRAINSTORM = {
139
118
  { section: "Problem", required: true, validationRule: "Must define what we're solving, success criteria, and constraints." },
140
119
  { section: "Clarifying Questions", required: false, validationRule: "Must capture question, answer, and decision impact for each clarifying question." },
141
120
  { section: "Approach Tier", required: true, validationRule: "Must classify depth as Lightweight/Standard/Deep and explain why." },
142
- { section: "Short-Circuit Decision", required: false, validationRule: "Must include Status/Why/Scope handoff lines when short-circuit is discussed." },
121
+ { section: "Short-Circuit Decision", required: false, validationRule: "Must include Status/Why/Scope handoff lines when short-circuit is discussed; compact stubs are valid for concrete asks." },
143
122
  { section: "Approaches", required: true, validationRule: "Must compare 2-3 architecturally distinct options with real trade-offs and include one row labeled `challenger: higher-upside`." },
144
123
  { section: "Approach Reaction", required: true, validationRule: "Must summarize user reaction before recommendation, including concerns that changed direction." },
145
124
  { section: "Selected Direction", required: true, validationRule: "Must include the selected approach, rationale tied to user reaction/feedback, and explicit approval marker." },
@@ -1,4 +1,5 @@
1
- import { REVIEW_LOOP_CHECKLISTS } from "../review-loop.js";
1
+ import { REVIEW_LOOP_CHECKLISTS, reviewLoopPolicySummary, reviewLoopSecondOpinionSummary } from "../review-loop.js";
2
+ import { decisionProtocolInstruction } from "../decision-protocol.js";
2
3
  // ---------------------------------------------------------------------------
3
4
  // DESIGN — reference: gstack Eng review
4
5
  // ---------------------------------------------------------------------------
@@ -39,60 +40,38 @@ export const DESIGN = {
39
40
  },
40
41
  executionModel: {
41
42
  checklist: [
42
- "Trivial-Change Escape Hatch — If scope artifact shows ≤3 files, zero new interfaces, and no cross-module data flow, skip full review sections. Produce a mini-design: one paragraph of rationale, list of changed files, one risk to watch. Proceed to spec.",
43
- "Parallel Research Fleet — run `research/research-fleet.md` before architecture lock. Fleet size scales by complexity: Lightweight=1 lens (pitfalls), Standard=2 lenses (architecture+pitfalls), Deep=4 lenses. Record findings in `.cclaw/artifacts/02a-research.md` and summarize resulting decisions in `## Research Fleet Synthesis`.",
44
- "Design Doc Check — read existing design docs, scope artifact, brainstorm artifact. If a design doc exists that covers this area, check for 'Supersedes:' and use the latest. Use upstream artifacts as source of truth.",
45
- "Codebase InvestigationBefore any design decision, read the actual code in the blast radius. List every file that will be touched, its current responsibilities, and existing patterns (error handling, naming, test style). Design must conform to discovered patterns, not impose new ones without justification.",
46
- "Step 0: Scope Challenge — what existing code solves sub-problems? Minimum change set? Complexity check: 8+ files or 2+ new services = complexity smell flag for possible scope reduction.",
47
- "Search Before Building For each technical choice (library, pattern, architecture), search for existing solutions. Label findings: Layer 1 (exact match), Layer 2 (partial match, needs adaptation), Layer 3 (inspiration only), EUREKA (unexpected perfect solution). Default to existing before custom.",
48
- "Architecture Review lock component boundaries and one realistic failure scenario per new codepath. **Mandatory diagrams by tier:** Lightweight=Architecture Diagram, Standard=+Data-Flow Shadow Paths + Error Flow Diagram, Deep=+State Machine Diagram + Rollback Flowchart + Deployment Sequence Diagram.",
49
- "Security & Threat Model Review trust boundaries, authn/authz, input validation, secrets handling, data exposure risks, abuse cases, and mitigation ownership.",
50
- "Code Quality Review — code organization, DRY violations, error handling patterns, over/under-engineering assessment. Include stale-diagram audit for touched files.",
51
- "Test Reviewdiagram every new flow, data path, error path. For each: what test type covers it? Does one exist? What is the gap? Produce test plan artifact.",
52
- "Performance Review — N+1 queries, memory concerns, caching opportunities, slow code paths. What breaks at 10x load? At 100x?",
53
- "Observability & Debuggability Review — logging, metrics, traces, alerts, and on-call diagnosis path for each critical failure mode.",
54
- "Deployment & Rollout Review — migration sequencing, flag strategy, rollback plan, compatibility window, and post-deploy verification steps.",
55
- "Parallelization Strategy — If multiple independent modules, produce dependency table: which can be built in parallel? Where are conflict risks? Flag shared-state modules.",
56
- "Outside Voice + Spec Review Loop — run adversarial second-opinion review, reconcile findings, and iterate up to 3 cycles or until quality score >= 0.8. When `.cclaw/config.yaml::reviewLoop.externalSecondOpinion.enabled` is true, run an additional external-model pass and explicitly resolve score/finding disagreements.",
57
- "Stale Diagram Audit (opt-in) — when `.cclaw/config.yaml::optInAudits.staleDiagramAudit` is true, compare blast-radius file mtimes against diagram-marker freshness and flag stale diagrams before design lock.",
58
- "Plant-seed shelf (optional) — when an unresolved/deferred design idea has upside, capture it as `.cclaw/seeds/SEED-<YYYY-MM-DD>-<slug>.md` with trigger_when and action so it can be recalled on future `/cc` starts.",
59
- "Unresolved Decisions — List any design decisions that could not be resolved in this session. For each: what information is missing? Who can provide it? What is the default if no answer comes?",
60
- "Distribution Check — If the plan creates new artifact types (packages, CLI tools, configs), document the build/publish story. How does it reach the user?",
61
- "Deferred Items Cross-Reference — Collect every item explicitly deferred during design review. Each must appear in the Unresolved Decisions table or in the upstream scope artifact's deferred list. No deferred item may exist only in conversation — it must be written down."
43
+ "Trivial-Change Escape Hatch — for <=3 files, no new interfaces, and no cross-module data flow, produce a mini-design (rationale, changed files, one risk) and proceed to spec.",
44
+ "Tiered Research Fleet — run `research/research-fleet.md` before lock; record `.cclaw/artifacts/02a-research.md` and summarize concrete decisions in `## Research Fleet Synthesis`.",
45
+ "Design Doc Check — read upstream artifacts and current design docs; latest superseding doc wins.",
46
+ "Investigator passbefore design decisions, read blast-radius code and record touched files, responsibilities, reuse candidates, and existing patterns.",
47
+ "Scope Challenge + Search Before Building find existing solutions, minimum change set, and complexity smells before custom architecture.",
48
+ "Architecture Reviewlock boundaries, one realistic failure scenario per new codepath, and high-risk choices with chosen path, one shadow alternative, switch trigger, and verification evidence; include tier-required diagrams.",
49
+ "Review core risk areas security/threat model, code quality, tests, performance, observability/debuggability, deployment/rollout, and parallelization when modules are independent.",
50
+ `Critic passrun/reconcile adversarial second opinion on architecture, coupling, failure modes, and cheaper alternatives. ${reviewLoopPolicySummary("design")} ${reviewLoopSecondOpinionSummary("design")}`,
51
+ "Run optional stale-diagram audit only when configured.",
52
+ "Capture leftoversseed high-upside deferred ideas, list unresolved decisions with defaults, document distribution for new artifact types, and cross-reference deferred items to scope or unresolved decisions."
62
53
  ],
63
54
  interactionProtocol: [
64
- "Review architecture decisions section-by-section.",
65
- "For EACH issue found in a review section, present it ONE AT A TIME. Do NOT batch multiple issues.",
66
- "For each issue: use the Decision Protocol — describe concretely with file/line references, present labeled options (A/B/C) with trade-offs, effort estimate (S/M/L/XL), risk level (Low/Med/High), and mark one as (recommended). Do NOT use a numeric Completeness rubric. If the harness's native structured-ask tool is available (`AskUserQuestion` / `AskQuestion` / `question` / `request_user_input`), send exactly ONE question per call and fall back to plain-text letters on schema/tool failure.",
67
- "Only proceed to the next review section after ALL issues in the current section are resolved.",
55
+ "Review section-by-section: investigator first, critic second, then reconcile.",
56
+ "Present each issue one at a time; do not batch issues or move sections until current issues are resolved.",
57
+ decisionProtocolInstruction("each issue", "describe concretely with file/line references, present labeled options (A/B/C) with trade-offs, effort estimate (S/M/L/XL), risk level (Low/Med/High), and mark one as (recommended)", "recommend the option that closes the issue with the smallest blast radius and clearest verification path"),
68
58
  "If a section has no issues, say 'No issues found' and move on.",
69
- "Do not skip failure-mode mapping.",
70
- "Use Failure Mode Table columns in fixed order: Method, Exception, Rescue, UserSees. Silent user impact without rescue is treated as critical.",
71
- "For design baseline approval: present the full baseline. **STOP.** Do NOT proceed until user explicitly approves the design.",
72
- "**STOP BEFORE ADVANCE.** Mandatory delegation `planner` must be marked completed or explicitly waived in `.cclaw/state/delegation-log.json`. Then close the stage via `node .cclaw/hooks/stage-complete.mjs design` (do not hand-edit `.cclaw/state/flow-state.json`).",
73
- "Take a firm position on every recommendation. Do NOT hedge with 'it depends' or 'you could do either'. State your opinion, then justify it.",
74
- "Use pushback for weak framing: 'small changes' on shared interfaces can still have large blast radius.",
75
- "When the user's proposed architecture is suboptimal, say so directly. Offer the alternative with concrete trade-offs, do not bury criticism in praise.",
76
- "When encountering ambiguity, classify it before acting: (A) ask user for missing info, (B) enumerate interpretations and pick one with justification, (C) propose hypothesis with validation path. Do NOT silently resolve ambiguity.",
77
- "Before final approval, run outside-voice review loop and reconcile each finding (accept/reject/defer) with rationale.",
78
- "Bound review-loop retries: max 3 iterations or early stop at quality score >= 0.8."
59
+ "Do not skip failure-mode mapping; use Method/Exception/Rescue/UserSees and treat silent user impact without rescue as critical.",
60
+ "Take a firm position, push back on weak framing, and call out suboptimal architecture with concrete alternatives.",
61
+ "Classify ambiguity before acting: ask, enumerate-and-pick, or propose a hypothesis with validation path.",
62
+ "Before final approval, run the critic pass, reconcile material findings, and bound retries with the review-loop policy.",
63
+ "For baseline approval, present the full design and **STOP** until explicit approval.",
64
+ "**STOP BEFORE ADVANCE.** Mandatory delegation `planner` must be completed or explicitly waived, then close via `node .cclaw/hooks/stage-complete.mjs design`."
79
65
  ],
80
66
  process: [
81
- "Read upstream artifacts (brainstorm, scope).",
82
- "Run the research fleet playbook with tiered fleet size and write `.cclaw/artifacts/02a-research.md` before locking architecture choices.",
83
- "Investigate codebase: read files in blast radius, catalogue current patterns and responsibilities.",
84
- "Run Step 0 scope challenge: existing code leverage, minimum change set, complexity check.",
85
- "Walk through each review section interactively.",
86
- "Define architecture boundaries and ownership.",
87
- "Describe data flow and state transitions with edge paths + interaction edge-case matrix.",
88
- "Map failure modes and recovery strategy using Method/Exception/Rescue/UserSees table.",
89
- "Add security, observability, and deployment reviews for Standard+ changes.",
90
- "Run stale-diagram audit in touched files and reconcile drift.",
91
- "Define test coverage strategy and performance budget.",
92
- "Produce required outputs: NOT-in-scope section, What-already-exists section, tier-required diagrams with markers, failure mode table.",
93
- "Optionally plant unresolved high-upside ideas into `.cclaw/seeds/SEED-<YYYY-MM-DD>-<slug>.md` with trigger_when/action notes.",
94
- "Run outside-voice spec review loop (up to 3 iterations, quality score target >= 0.8). If configured, include external second opinion and reconcile deltas.",
95
- "Produce completion dashboard: status per review section, critical/open gap counts, decision count, unresolved items.",
67
+ "Read upstream artifacts and current design docs.",
68
+ "Run tiered research fleet and write `.cclaw/artifacts/02a-research.md` before architecture lock.",
69
+ "Run investigator pass plus scope challenge/search-before-building.",
70
+ "Walk review sections interactively and lock boundaries, data flow, state transitions, edge cases, and failure modes.",
71
+ "Cover security, observability, deployment, tests, and performance for Standard+ changes.",
72
+ "Run configured stale-diagram audit when enabled.",
73
+ "Produce required outputs: NOT-in-scope, What-already-exists, tier diagrams, failure table, completion dashboard.",
74
+ "Plant high-upside deferred ideas when useful and reconcile critic/outside-voice findings.",
96
75
  "Write design lock artifact for downstream spec/plan."
97
76
  ],
98
77
  requiredGates: [
@@ -111,8 +90,8 @@ export const DESIGN = {
111
90
  "Security & threat model findings are documented with mitigations.",
112
91
  "Observability and deployment plans are explicit for critical flows.",
113
92
  "Outside-voice findings and dispositions are recorded (accept/reject/defer).",
114
- "Spec review loop summary includes iteration count and quality score trajectory.",
115
- "When `.cclaw/config.yaml::reviewLoop.externalSecondOpinion.enabled` is true, external second-opinion disposition is captured.",
93
+ `Spec review loop summary includes iteration count and quality score trajectory per ${reviewLoopPolicySummary("design")}`,
94
+ reviewLoopSecondOpinionSummary("design"),
116
95
  "Test strategy includes unit/integration/e2e expectations.",
117
96
  "When a high-upside idea is deferred, a seed file is created under `.cclaw/seeds/` and referenced in the artifact.",
118
97
  "NOT-in-scope section produced.",
@@ -162,12 +141,13 @@ export const DESIGN = {
162
141
  traceabilityRule: "Every architecture decision must trace to a scope boundary. Every downstream spec requirement must trace to a design decision."
163
142
  },
164
143
  artifactValidation: [
165
- { section: "Research Fleet Synthesis", required: true, validationRule: "Must summarize all four lenses (stack/features/architecture/pitfalls) and map findings to concrete design decisions." },
166
- { section: "Codebase Investigation", required: false, validationRule: "Must list blast-radius files with current responsibilities and discovered patterns." },
144
+ { section: "Upstream Handoff", required: false, validationRule: "Summarizes scope/research decisions, constraints, open questions, and explicit drift before design choices." },
145
+ { section: "Research Fleet Synthesis", required: true, validationRule: "Must summarize the tiered lenses actually run (Lightweight=pitfalls, Standard=architecture+pitfalls, Deep=all four) and map findings to concrete design decisions." },
146
+ { section: "Codebase Investigation", required: false, validationRule: "Investigator pass: list blast-radius files with current responsibilities, discovered patterns, and reuse candidates." },
167
147
  { section: "Search Before Building", required: false, validationRule: "For each technical choice: Layer 1 (exact match), Layer 2 (partial match), Layer 3 (inspiration), EUREKA labels with reuse-first default." },
168
148
  { section: "Architecture Boundaries", required: true, validationRule: "Must list component boundaries with ownership." },
169
149
  { section: "Architecture Diagram", required: true, validationRule: "Must include `<!-- diagram: architecture -->` marker. Diagram must label concrete nodes, label arrows, mark direction, distinguish sync/async edges, and include at least one failure/degraded edge." },
170
- { section: "Data-Flow Shadow Paths", required: false, validationRule: "Standard/Deep: include `<!-- diagram: data-flow-shadow-paths -->` marker and path table with trigger plus fallback/degrade behavior." },
150
+ { section: "Data-Flow Shadow Paths", required: false, validationRule: "Standard/Deep: include `<!-- diagram: data-flow-shadow-paths -->` marker plus a table for high-risk choices: chosen path, shadow alternative, switch trigger, fallback/degrade behavior, and verification evidence." },
171
151
  { section: "Error Flow Diagram", required: false, validationRule: "Standard/Deep: include `<!-- diagram: error-flow -->` marker and failure-detection -> rescue -> user-visible outcome flow." },
172
152
  { section: "State Machine Diagram", required: false, validationRule: "Deep: include `<!-- diagram: state-machine -->` marker and state transitions for critical flow lifecycle." },
173
153
  { section: "Rollback Flowchart", required: false, validationRule: "Deep: include `<!-- diagram: rollback-flowchart -->` marker with trigger -> rollback actions -> verification." },
@@ -181,8 +161,8 @@ export const DESIGN = {
181
161
  { section: "Observability & Debuggability", required: true, validationRule: "Must define logs/metrics/traces plus alerting/debug path for critical failure modes." },
182
162
  { section: "Deployment & Rollout", required: true, validationRule: "Must define migration/flag strategy, rollback plan, and post-deploy verification steps." },
183
163
  { section: "What Already Exists", required: false, validationRule: "For each sub-problem: existing code/library found (Layer 1-3/EUREKA label), reuse decision, and adaptation needed." },
184
- { section: "Outside Voice Findings", required: false, validationRule: "List adversarial findings and disposition (accept/reject/defer) with rationale per finding." },
185
- { section: "Spec Review Loop", required: false, validationRule: "Record iteration table (max 3) with quality score per iteration, stop reason, and unresolved concerns." },
164
+ { section: "Outside Voice Findings", required: false, validationRule: "Critic pass: list adversarial findings and disposition (accept/reject/defer) with rationale per material finding." },
165
+ { section: "Spec Review Loop", required: false, validationRule: `Record iteration table with quality score per iteration, stop reason, and unresolved concerns. Enforce ${reviewLoopPolicySummary("design")}` },
186
166
  { section: "NOT in scope", required: false, validationRule: "Work considered and explicitly deferred with one-line rationale." },
187
167
  { section: "Parallelization Strategy", required: false, validationRule: "If multi-module: dependency table, parallel lanes, conflict flags." },
188
168
  { section: "Unresolved Decisions", required: false, validationRule: "If any: what info is missing, who provides it, default if unanswered." },