cclaw-cli 0.51.23 → 0.51.25

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 (42) hide show
  1. package/README.md +135 -414
  2. package/dist/artifact-linter.js +10 -6
  3. package/dist/config.d.ts +1 -1
  4. package/dist/config.js +28 -3
  5. package/dist/content/core-agents.d.ts +128 -2
  6. package/dist/content/core-agents.js +291 -13
  7. package/dist/content/examples.js +21 -10
  8. package/dist/content/next-command.js +10 -6
  9. package/dist/content/reference-patterns.d.ts +18 -0
  10. package/dist/content/reference-patterns.js +391 -0
  11. package/dist/content/seed-shelf.js +73 -8
  12. package/dist/content/skills.js +39 -34
  13. package/dist/content/stage-common-guidance.js +19 -3
  14. package/dist/content/stage-schema.d.ts +12 -0
  15. package/dist/content/stage-schema.js +224 -24
  16. package/dist/content/stages/_lint-metadata/index.js +3 -2
  17. package/dist/content/stages/brainstorm.js +27 -18
  18. package/dist/content/stages/design.js +27 -18
  19. package/dist/content/stages/review.js +20 -9
  20. package/dist/content/stages/schema-types.d.ts +9 -2
  21. package/dist/content/stages/scope.js +21 -10
  22. package/dist/content/stages/ship.js +3 -2
  23. package/dist/content/stages/tdd.js +18 -13
  24. package/dist/content/start-command.js +3 -2
  25. package/dist/content/status-command.js +9 -4
  26. package/dist/content/subagents.js +336 -38
  27. package/dist/content/templates.js +182 -25
  28. package/dist/delegation.d.ts +2 -0
  29. package/dist/delegation.js +27 -6
  30. package/dist/doctor.js +167 -25
  31. package/dist/flow-state.d.ts +1 -0
  32. package/dist/flow-state.js +1 -0
  33. package/dist/gate-evidence.js +25 -2
  34. package/dist/install.js +72 -8
  35. package/dist/internal/advance-stage.js +179 -26
  36. package/dist/knowledge-store.js +30 -6
  37. package/dist/run-archive.js +11 -0
  38. package/dist/run-persistence.js +35 -10
  39. package/dist/tdd-verification-evidence.d.ts +17 -0
  40. package/dist/tdd-verification-evidence.js +43 -0
  41. package/dist/types.d.ts +10 -0
  42. package/package.json +1 -1
@@ -14,6 +14,11 @@ ${conversationLanguagePolicyMarkdown()}
14
14
  harvest learnings, then use \`/cc-next\` for progression.
15
15
  - Do not create separate protocol files.
16
16
 
17
+ ## Context readiness
18
+
19
+ - Before drafting, know the upstream artifact freshness, required template shape, relevant code/reference patterns, and unresolved blockers.
20
+ - If any item is missing, load it or stop with a blocker instead of inventing content.
21
+
17
22
  ## Shared decision protocol
18
23
 
19
24
  - Ask only decision-changing questions.
@@ -28,7 +33,7 @@ Use this same closeout menu for every stage:
28
33
  - **A) Advance** — run \`/cc-next\` and continue the critical path; after \`ship\`, the same command drives \`retro -> compound -> archive\`.
29
34
  - **B) Revise this stage** — stay on current stage and apply feedback.
30
35
  - **C) Pause / park** — run \`/cc-view status\`, then stop and resume later.
31
- - **D) Rewind** — run \`npx cclaw-cli internal rewind <target-stage> "<reason>"\` as a support/runtime repair action.
36
+ - **D) Rewind** — run \`npx cclaw-cli internal rewind <target-stage> "<reason>"\` as the managed support/runtime repair action; after redoing the target stage, run \`npx cclaw-cli internal rewind --ack <target-stage>\` to clear the stale marker.
32
37
  - **E) Abandon** — only when the user explicitly wants to end a non-ship active run early, archive with \`npx cclaw-cli archive --skip-retro --retro-reason="<reason>"\`. Once in post-ship closeout, continue \`/cc-next\` through retro/compound/archive instead.
33
38
 
34
39
  Recommendation defaults:
@@ -37,6 +42,12 @@ Recommendation defaults:
37
42
  - Completion status \`DONE_WITH_CONCERNS\` -> recommend **B**.
38
43
  - Completion status \`BLOCKED\` -> recommend **B** or **C**.
39
44
 
45
+ ## Iterate / Victory Detector
46
+
47
+ - Iterate while a required gate, artifact section, or fresh evidence item is missing.
48
+ - Stop only when the stage-specific Victory Detector passes or a named blocker is recorded.
49
+ - Do not use vague closeout wording such as \`looks good\`, \`done enough\`, or \`all set\` without the detector evidence.
50
+
40
51
  ## Completion status vocabulary
41
52
 
42
53
  - \`DONE\` — all required gates and checks satisfied.
@@ -63,9 +74,12 @@ Rollback / fallback: <if decision proves wrong>
63
74
 
64
75
  Before closeout, fill the artifact \`## Learnings\` section (do not write
65
76
  \`.cclaw/knowledge.jsonl\` by hand):
66
- - \`- None this stage.\` when nothing reusable emerged.
77
+ - \`- None this stage.\` only when nothing reusable emerged.
67
78
  - Or 1-3 JSON bullets with required keys \`type\`, \`trigger\`, \`action\`,
68
79
  \`confidence\` (optional fields may mirror knowledge.jsonl schema keys).
80
+ - For meaningful \`design\`, \`tdd\`, or \`review\` work, prefer a small JSON
81
+ learning over \`None\` when you made a reusable decision, found a testing
82
+ pattern, or caught a review/security issue.
69
83
  During \`node .cclaw/hooks/stage-complete.mjs <stage>\`, cclaw validates those
70
84
  bullets, appends unique entries to \`.cclaw/knowledge.jsonl\`, and stamps a
71
85
  harvest marker in the artifact.
@@ -78,7 +92,9 @@ Track policy:
78
92
  - \`quick\`: recommended only.
79
93
 
80
94
  \`- None this stage.\` is acceptable only when the stage produced no reusable
81
- insight (for example, purely mechanical edits with no new decisions).
95
+ insight (for example, purely mechanical edits with no new decisions). If unsure,
96
+ record a concise \`lesson\` with \`confidence":"medium"\` instead of dropping
97
+ operator knowledge.
82
98
 
83
99
  ## Progressive disclosure baseline
84
100
 
@@ -23,11 +23,23 @@ export interface StageStackAwareReviewRoute {
23
23
  signals: string[];
24
24
  focus: string;
25
25
  }
26
+ export interface StageDelegationDispatchRule {
27
+ agent: string;
28
+ mode: "mandatory" | "proactive";
29
+ when: string;
30
+ purpose: string;
31
+ requiresUserGate: boolean;
32
+ requiredAtTier?: StageComplexityTier;
33
+ dispatchClass: NonNullable<StageAutoSubagentDispatch["dispatchClass"]>;
34
+ returnSchema: NonNullable<StageAutoSubagentDispatch["returnSchema"]>;
35
+ skill?: string;
36
+ }
26
37
  export interface StageDelegationSummary {
27
38
  stage: FlowStage;
28
39
  mandatoryAgents: string[];
29
40
  proactiveAgents: string[];
30
41
  primaryAgents: string[];
42
+ dispatchRules: StageDelegationDispatchRule[];
31
43
  stackAwareRoutes: StageStackAwareReviewRoute[];
32
44
  }
33
45
  export declare function reviewStackAwareRoutes(): StageStackAwareReviewRoute[];
@@ -81,6 +81,66 @@ function dedupeAgentsInOrder(agents) {
81
81
  }
82
82
  return out;
83
83
  }
84
+ function defaultReturnSchemaForAgent(agent) {
85
+ switch (agent) {
86
+ case "researcher":
87
+ return "research-return";
88
+ case "architect":
89
+ return "architecture-return";
90
+ case "spec-validator":
91
+ return "spec-validation-return";
92
+ case "slice-implementer":
93
+ return "worker-return";
94
+ case "performance-reviewer":
95
+ return "performance-return";
96
+ case "compatibility-reviewer":
97
+ return "compatibility-return";
98
+ case "observability-reviewer":
99
+ return "observability-return";
100
+ case "release-reviewer":
101
+ return "release-return";
102
+ case "planner":
103
+ return "planning-return";
104
+ case "product-manager":
105
+ return "product-return";
106
+ case "critic":
107
+ return "critic-return";
108
+ case "reviewer":
109
+ return "review-return";
110
+ case "security-reviewer":
111
+ return "security-return";
112
+ case "test-author":
113
+ return "tdd-return";
114
+ case "doc-updater":
115
+ return "docs-return";
116
+ case "fixer":
117
+ return "fixer-return";
118
+ case "implementer":
119
+ return "worker-return";
120
+ }
121
+ }
122
+ function dispatchClassForRow(row) {
123
+ if (row.dispatchClass)
124
+ return row.dispatchClass;
125
+ if (row.agent === "implementer" || row.agent === "fixer" || row.agent === "slice-implementer")
126
+ return "worker";
127
+ return row.skill?.includes("review") || row.agent === "reviewer" || row.agent === "security-reviewer" || row.agent.endsWith("-reviewer")
128
+ ? "review-lens"
129
+ : "stage-specialist";
130
+ }
131
+ function delegationDispatchRule(row) {
132
+ return {
133
+ agent: row.agent,
134
+ mode: row.mode,
135
+ when: row.when,
136
+ purpose: row.purpose,
137
+ requiresUserGate: row.requiresUserGate,
138
+ requiredAtTier: row.requiredAtTier,
139
+ dispatchClass: dispatchClassForRow(row),
140
+ returnSchema: row.returnSchema ?? defaultReturnSchemaForAgent(row.agent),
141
+ skill: row.skill
142
+ };
143
+ }
84
144
  /**
85
145
  * Canonical delegation summary derived from STAGE_AUTO_SUBAGENT_DISPATCH.
86
146
  *
@@ -106,6 +166,7 @@ export function stageDelegationSummary(complexityTier = "standard") {
106
166
  mandatoryAgents,
107
167
  proactiveAgents,
108
168
  primaryAgents,
169
+ dispatchRules: eligibleRows.map(delegationDispatchRule),
109
170
  stackAwareRoutes: stackAwareRoutesForStage(stage)
110
171
  };
111
172
  });
@@ -242,27 +303,29 @@ const REQUIRED_GATE_IDS = {
242
303
  const REQUIRED_ARTIFACT_SECTIONS = {
243
304
  brainstorm: [
244
305
  "Context",
245
- "Problem",
306
+ "Problem Decision Record",
246
307
  "Approach Tier",
247
308
  "Approaches",
248
309
  "Approach Reaction",
249
310
  "Selected Direction"
250
311
  ],
251
- scope: ["Scope Mode", "In Scope / Out of Scope", "Completion Dashboard", "Scope Summary"],
312
+ scope: ["Scope Contract", "Scope Mode", "In Scope / Out of Scope", "Completion Dashboard", "Scope Summary"],
252
313
  design: [
253
314
  "Research Fleet Synthesis",
315
+ "Engineering Lock",
254
316
  "Architecture Boundaries",
255
317
  "Architecture Diagram",
256
318
  "Failure Mode Table",
257
319
  "Security & Threat Model",
258
320
  "Observability & Debuggability",
259
321
  "Deployment & Rollout",
322
+ "Spec Handoff",
260
323
  "Completion Dashboard"
261
324
  ],
262
325
  spec: ["Acceptance Criteria", "Edge Cases", "Assumptions Before Finalization", "Acceptance Mapping", "Approval"],
263
326
  plan: ["Task List", "Dependency Batches", "Acceptance Mapping", "Execution Posture", "WAIT_FOR_CONFIRM"],
264
327
  tdd: ["Test Discovery", "System-Wide Impact Check", "RED Evidence", "GREEN Evidence", "REFACTOR Notes", "Traceability", "Verification Ladder"],
265
- review: ["Layer 1 Verdict", "Review Findings Contract", "Severity Summary", "Final Verdict"],
328
+ review: ["Review Evidence Scope", "Changed-File Coverage", "Layer 1 Verdict", "Review Findings Contract", "Severity Summary", "Final Verdict"],
266
329
  ship: ["Preflight Results", "Release Notes", "Rollback Plan", "Finalization"]
267
330
  };
268
331
  function resolveRequiredGateIds(stage, track) {
@@ -358,10 +421,26 @@ const STAGE_SCHEMA_MAP = {
358
421
  const STAGE_AUTO_SUBAGENT_DISPATCH = {
359
422
  brainstorm: [
360
423
  {
361
- agent: "planner",
424
+ agent: "product-manager",
425
+ mode: "mandatory",
426
+ requiredAtTier: "standard",
427
+ when: "Always for standard/deep brainstorm to validate value, persona/JTBD, success metric, and why-now framing.",
428
+ purpose: "Pressure-test problem/value fit and produce product-discovery evidence for the Problem Decision Record.",
429
+ requiresUserGate: false
430
+ },
431
+ {
432
+ agent: "critic",
433
+ mode: "mandatory",
434
+ requiredAtTier: "standard",
435
+ when: "Always for standard/deep brainstorm to challenge the premise, do-nothing path, and higher-upside alternatives.",
436
+ purpose: "Attack assumptions and surface non-goals before direction approval.",
437
+ requiresUserGate: false
438
+ },
439
+ {
440
+ agent: "researcher",
362
441
  mode: "proactive",
363
- when: "When request is ambiguous, multi-surface, or spans multiple modules.",
364
- purpose: "Map scope and alternatives before direction lock.",
442
+ when: "When repository, market, docs, or prior-art context changes the approach set.",
443
+ purpose: "Provide search-before-read summaries and context-readiness evidence before large reads or decisions.",
365
444
  requiresUserGate: false
366
445
  }
367
446
  ],
@@ -373,38 +452,99 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
373
452
  when: "Always during scope shaping.",
374
453
  purpose: "Challenge premise, map alternatives, and produce explicit in/out contract.",
375
454
  requiresUserGate: false
455
+ },
456
+ {
457
+ agent: "critic",
458
+ mode: "mandatory",
459
+ requiredAtTier: "standard",
460
+ when: "Always during scope shaping for standard/deep work.",
461
+ purpose: "Test whether the selected scope mode is too timid, too broad, or hiding a smaller useful slice.",
462
+ requiresUserGate: false
463
+ },
464
+ {
465
+ agent: "researcher",
466
+ mode: "proactive",
467
+ when: "When churn, prior attempts, reference patterns, or external constraints may change scope boundaries.",
468
+ purpose: "Summarize search/context findings before the scope contract locks accepted/rejected/deferred ideas.",
469
+ requiresUserGate: false
470
+ },
471
+ {
472
+ agent: "product-manager",
473
+ mode: "proactive",
474
+ when: "When scope choices change user value, success metrics, or product positioning.",
475
+ purpose: "Keep accepted/deferred reference ideas tied to user value and measurable success.",
476
+ requiresUserGate: false
376
477
  }
377
478
  ],
378
479
  design: [
379
480
  {
380
- agent: "planner",
481
+ agent: "architect",
381
482
  mode: "mandatory",
382
483
  requiredAtTier: "standard",
383
484
  when: "Always during design lock.",
384
- purpose: "Stress architecture boundaries and dependency graph.",
485
+ purpose: "Stress architecture boundaries, dependency graph, critical path, and spec handoff.",
486
+ requiresUserGate: false
487
+ },
488
+ {
489
+ agent: "test-author",
490
+ mode: "mandatory",
491
+ requiredAtTier: "standard",
492
+ when: "Always during design lock.",
493
+ purpose: "Check test diagram mapping, RED expressibility, assertion quality, and verification routes before implementation.",
494
+ requiresUserGate: false
495
+ },
496
+ {
497
+ agent: "critic",
498
+ mode: "proactive",
499
+ when: "When architecture alternatives, coupling, cost, or rollback risk remain debatable.",
500
+ purpose: "Produce a shadow alternative, switch trigger, and cheaper-path challenge for the engineering lock.",
501
+ requiresUserGate: false
502
+ },
503
+ {
504
+ agent: "researcher",
505
+ mode: "proactive",
506
+ when: "When framework/library docs, repo graph context, or reference contracts may change the design.",
507
+ purpose: "Run search-before-read context synthesis before architecture locks.",
385
508
  requiresUserGate: false
386
509
  },
387
510
  {
388
511
  agent: "security-reviewer",
389
512
  mode: "proactive",
390
- when: "When trust boundaries, auth, secrets, or external inputs are involved.",
513
+ when: "When trust boundaries, auth, secrets, sensitive data, or external inputs are involved.",
391
514
  purpose: "Catch design-level security risks before implementation.",
392
515
  requiresUserGate: false
516
+ },
517
+ {
518
+ agent: "compatibility-reviewer",
519
+ mode: "proactive",
520
+ requiredAtTier: "lightweight",
521
+ when: "When public API, config, persisted data, CLI, generated clients, or cross-version behavior can change.",
522
+ purpose: "Identify backward-compatibility and migration hazards before spec/plan.",
523
+ requiresUserGate: false
524
+ },
525
+ {
526
+ agent: "observability-reviewer",
527
+ mode: "proactive",
528
+ requiredAtTier: "lightweight",
529
+ when: "When runtime/debuggability, rollout, failure detection, or supportability matters.",
530
+ purpose: "Validate logs/metrics/traces, alerting, and rescue-path visibility before implementation.",
531
+ requiresUserGate: false
393
532
  }
394
533
  ],
395
534
  spec: [
396
535
  {
397
- agent: "planner",
398
- mode: "proactive",
399
- when: "When acceptance criteria are unclear or constraints conflict.",
400
- purpose: "Normalize measurable criteria and testability mapping.",
536
+ agent: "spec-validator",
537
+ mode: "mandatory",
538
+ requiredAtTier: "standard",
539
+ when: "Always for standard/deep specs before plan handoff.",
540
+ purpose: "Validate measurability, edge cases, assumptions, and AC-to-testability mapping.",
401
541
  requiresUserGate: false
402
542
  },
403
543
  {
404
- agent: "reviewer",
544
+ agent: "test-author",
405
545
  mode: "proactive",
406
- when: "When acceptance criteria and edge cases are drafted and need independent validation before plan stage.",
407
- purpose: "Independent review of spec against measurability, testability, and completeness before locking the contract for plan.",
546
+ when: "When acceptance criteria need testability review or RED expressibility is uncertain.",
547
+ purpose: "Confirm likely test levels, commands/manual evidence, and assertion surfaces are concrete.",
408
548
  requiresUserGate: false
409
549
  }
410
550
  ],
@@ -414,7 +554,14 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
414
554
  mode: "mandatory",
415
555
  requiredAtTier: "standard",
416
556
  when: "Always when producing execution slices.",
417
- purpose: "Create dependency-aware task graph with verification steps.",
557
+ purpose: "Create dependency-aware executable packets with expected failing test, passing command, stop condition, and verification evidence.",
558
+ requiresUserGate: false
559
+ },
560
+ {
561
+ agent: "researcher",
562
+ mode: "proactive",
563
+ when: "When plan tasks touch unfamiliar areas or reference-pattern adoption needs source verification.",
564
+ purpose: "Confirm context/search evidence before plan packets rely on discovered patterns.",
418
565
  requiresUserGate: false
419
566
  }
420
567
  ],
@@ -424,10 +571,25 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
424
571
  mode: "mandatory",
425
572
  requiredAtTier: "lightweight",
426
573
  when: "Always during the TDD cycle.",
427
- purpose: "Own phase-specific RED/GREEN/REFACTOR evidence for each slice: failing tests before production writes, minimal GREEN implementation, then behavior-preserving refactor notes.",
574
+ purpose: "Own RED quality and per-slice RED/GREEN/REFACTOR evidence: failing tests before production writes, minimal GREEN implementation, then behavior-preserving refactor notes.",
428
575
  requiresUserGate: false,
429
576
  skill: "tdd-cycle-evidence"
430
577
  },
578
+ {
579
+ agent: "slice-implementer",
580
+ mode: "proactive",
581
+ requiredAtTier: "lightweight",
582
+ when: "When a bounded GREEN/REFACTOR slice has non-overlapping file ownership and a clear RED failure.",
583
+ purpose: "Implement the minimal passing slice inside explicit file boundaries and return strict worker evidence.",
584
+ requiresUserGate: false
585
+ },
586
+ {
587
+ agent: "reviewer",
588
+ mode: "proactive",
589
+ when: "When per-slice review triggers fire or assertion quality needs an independent read-only overseer.",
590
+ purpose: "Read-only overseer pass for slice spec fit, assertion quality, and simpler alternatives.",
591
+ requiresUserGate: false
592
+ },
431
593
  {
432
594
  agent: "doc-updater",
433
595
  mode: "proactive",
@@ -442,7 +604,7 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
442
604
  mode: "mandatory",
443
605
  requiredAtTier: "lightweight",
444
606
  when: "Always in review stage.",
445
- purpose: "Layer 1 spec compliance plus integrated Layer 2 review across correctness, performance, architecture, and external-safety tags with source-tagged findings.",
607
+ purpose: "Layer 1 spec compliance plus integrated Layer 2 review across correctness, architecture, and external-safety tags with source-tagged findings.",
446
608
  requiresUserGate: false,
447
609
  skill: "review-spec-pass"
448
610
  },
@@ -450,11 +612,35 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
450
612
  agent: "security-reviewer",
451
613
  mode: "mandatory",
452
614
  requiredAtTier: "lightweight",
453
- when: "Always in review stage. Even when no trust boundaries changed, produce an explicit 'no-change' security attestation.",
454
- purpose: "Guarantee a dedicated security pass on every diff: auth, input validation, secrets, injection, privilege, and blast-radius review are never opt-in. MUST load the `security-audit` skill and run a pattern-based sweep across the diff scope and touched modules in addition to the per-diff Layer 2 security checklist.",
615
+ when: "Always in review stage. Even when no trust boundaries changed, produce an explicit no-change/no-impact security attestation.",
616
+ purpose: "Guarantee a dedicated security pass on every diff: auth, input validation, secrets, injection, privilege, and blast-radius review are never opt-in.",
455
617
  requiresUserGate: false,
456
618
  skill: "security-audit"
457
619
  },
620
+ {
621
+ agent: "performance-reviewer",
622
+ mode: "proactive",
623
+ requiredAtTier: "lightweight",
624
+ when: "When hot paths, IO, data volume, rendering, caching, or algorithmic cost can move.",
625
+ purpose: "Run a focused performance lens and report evidence-backed regressions or no-impact rationale.",
626
+ requiresUserGate: false
627
+ },
628
+ {
629
+ agent: "compatibility-reviewer",
630
+ mode: "proactive",
631
+ requiredAtTier: "lightweight",
632
+ when: "When public API, CLI/config, persisted data, generated clients, or dependency versions change.",
633
+ purpose: "Check compatibility, migrations, and consumer-facing contract stability.",
634
+ requiresUserGate: false
635
+ },
636
+ {
637
+ agent: "observability-reviewer",
638
+ mode: "proactive",
639
+ requiredAtTier: "lightweight",
640
+ when: "When failure diagnosis, logging/metrics/traces, rollout, or operational support matters.",
641
+ purpose: "Check observability and supportability evidence against the design/review artifact.",
642
+ requiresUserGate: false
643
+ },
458
644
  {
459
645
  agent: "reviewer",
460
646
  mode: "proactive",
@@ -467,7 +653,7 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
467
653
  agent: "reviewer",
468
654
  mode: "proactive",
469
655
  when: "When external reviewer comments, bot findings, or CI annotations are present after the initial review pass.",
470
- 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.",
656
+ purpose: "Run the receiving-code-review workflow so every incoming feedback item gets an explicit disposition with evidence.",
471
657
  requiresUserGate: false,
472
658
  skill: "receiving-code-review"
473
659
  },
@@ -482,10 +668,17 @@ const STAGE_AUTO_SUBAGENT_DISPATCH = {
482
668
  ],
483
669
  ship: [
484
670
  {
485
- agent: "doc-updater",
671
+ agent: "release-reviewer",
486
672
  mode: "mandatory",
487
673
  requiredAtTier: "lightweight",
488
674
  when: "Always in ship stage.",
675
+ purpose: "Run release readiness, finalization mode, rollback, evidence freshness, and victory-detector checks before archive/ship.",
676
+ requiresUserGate: false
677
+ },
678
+ {
679
+ agent: "doc-updater",
680
+ mode: "proactive",
681
+ when: "When release notes, migrations, public behavior, CLI/config, or docs changed.",
489
682
  purpose: "Ensure release notes and docs reflect actual shipped behavior.",
490
683
  requiresUserGate: false
491
684
  },
@@ -617,5 +810,12 @@ export function stageTrackRenderContext(track = "standard") {
617
810
  return trackRenderContext(track);
618
811
  }
619
812
  export function stageAutoSubagentDispatch(stage) {
620
- return STAGE_AUTO_SUBAGENT_DISPATCH[stage];
813
+ return STAGE_AUTO_SUBAGENT_DISPATCH[stage].map((row) => {
814
+ const normalized = delegationDispatchRule(row);
815
+ return {
816
+ ...row,
817
+ dispatchClass: normalized.dispatchClass,
818
+ returnSchema: normalized.returnSchema
819
+ };
820
+ });
621
821
  }
@@ -1,5 +1,6 @@
1
1
  import { SHIP_FINALIZATION_MODES } from "../../../constants.js";
2
2
  import { renderTrackTerminology, trackRenderContext } from "../../track-render-context.js";
3
+ import { referencePatternPolicyNeedles } from "../../reference-patterns.js";
3
4
  const STAGE_POLICY_NEEDLES = {
4
5
  brainstorm: [
5
6
  "Explore project context",
@@ -64,10 +65,10 @@ const STAGE_POLICY_NEEDLES = {
64
65
  ]
65
66
  };
66
67
  export function stagePolicyNeedlesFromMetadata(stage, track = "standard") {
67
- const needles = STAGE_POLICY_NEEDLES[stage];
68
+ const needles = [...STAGE_POLICY_NEEDLES[stage], ...referencePatternPolicyNeedles(stage)];
68
69
  const renderContext = trackRenderContext(track);
69
70
  if (stage === "tdd" && !renderContext.usesPlanTerminology) {
70
71
  return needles.map((needle) => renderTrackTerminology(needle, renderContext));
71
72
  }
72
- return [...needles];
73
+ return needles;
73
74
  }
@@ -7,11 +7,11 @@ export const BRAINSTORM = {
7
7
  complexityTier: "standard",
8
8
  skillFolder: "brainstorming",
9
9
  skillName: "brainstorming",
10
- skillDescription: "Design-first stage. Explore context, understand intent through collaborative dialogue, propose distinct approaches, and lock an approved direction before scope/design work.",
10
+ skillDescription: "Problem-discovery stage. Build a concise Problem Decision Record, choose lite/standard/deep depth, compare distinct directions, and hand approved decisions to scope.",
11
11
  philosophy: {
12
12
  hardGate: "Do NOT invoke implementation skills, write code, scaffold projects, or mutate product behavior until a concrete direction is approved by the user.",
13
13
  ironLaw: "NO ARTIFACT IS COMPLETE WITHOUT AN EXPLICITLY APPROVED DIRECTION — SILENCE IS NOT APPROVAL.",
14
- purpose: "Turn an initial idea into an approved design direction through natural collaborative dialogue understanding the problem before proposing solutions.",
14
+ purpose: "Turn an initial idea into an approved problem frame and direction, using product or technical-maintenance discovery before proposing solutions.",
15
15
  whenToUse: [
16
16
  "Starting a new feature or behavior change",
17
17
  "Requirements are ambiguous or trade-offs are unclear",
@@ -37,22 +37,25 @@ export const BRAINSTORM = {
37
37
  executionModel: {
38
38
  checklist: [
39
39
  "**Explore project context** — inspect existing files/docs/recent activity before asking what to build; capture matching files/patterns/seeds in `Context > Discovered context` so downstream stages don't redo discovery.",
40
- "**Classify depth and scope** — pick Lightweight / Standard / Deep; decompose independent subsystems before deeper work.",
40
+ "**Classify stage depth** — choose `lite` for clear low-risk tasks, `standard` for normal product/engineering changes, or `deep` for ambiguity, architecture, external dependency, security/data risk, or explicit think-bigger requests.",
41
+ "**Write the Problem Decision Record** — product work captures persona/JTBD/pain/value/evidence/success/why-now/do-nothing/non-goals; technical-maintenance work captures affected operator/developer, failure mode, operational improvement, verification signal, do-nothing cost, and non-goals.",
41
42
  "**Premise check (one pass)** — answer the three gstack-style questions in the artifact body: *Right problem? Direct path? What if we do nothing?* Take a position; do not hedge.",
42
- "**Reframe with How Might We** — write a single `How Might We …?` line that names the user, the desired outcome, and the constraint. This is the altitude check before approaches.",
43
- "**Sharpening questions (3-5)** — capture decision-changing question/answer pairs in the `Sharpening Questions` table with the actual decision impact; only non-critical preference/default assumptions may continue. STOP and ask on scope, architecture, security, data loss, public API, migration, auth/pricing, or user-approval uncertainty.",
43
+ "**Reframe with How Might We** — write a single `How Might We …?` line that names the user/operator, the desired outcome, and the constraint. This is the altitude check before approaches.",
44
+ "**Run Clarity Gate** — record ambiguity score (0.00-1.00), decision boundaries, reaffirmed non-goals, and residual-risk handoff before locking recommendations. If ambiguity remains high (>0.40), ask one decision-changing question before recommending.",
45
+ "**Sharpening question discipline** — ask one decision-changing question at a time. Do not default to 3-5 batched questions; record only questions that changed the direction or a critical stop decision.",
44
46
  "**Use compact discovery for simple apps** — for concrete low-risk asks (todo app, landing page, local widget), do one context pass, compare one baseline and one challenger, then ask for one explicit approval; do not drag the user through a full workshop.",
45
- "**Short-circuit concrete asks** — for unambiguous implementation-only requests, write a compact brainstorm stub (context, problem, approved intent, constraints, assumptions) and ask for one explicit approval.",
47
+ "**Early-exit concrete asks** — for unambiguous implementation-only requests, write a compact Problem Decision Record plus short-circuit handoff (context, approved intent, constraints, assumptions, next-stage risks) and ask for one explicit approval.",
46
48
  "**Ask only decision-changing questions** — one at a time; if answers would not change approach and are non-critical preference/default assumptions, state the assumption and continue; STOP on scope, architecture, security, data loss, public API, migration, auth/pricing, or user approval uncertainty.",
47
- "**Compare 2-3 distinct approaches with stable Role/Upside columns** — Role values are `baseline` | `challenger` | `wild-card`; Upside is `low` | `modest` | `high` | `higher`; include real trade-offs and reuse notes; include exactly one challenger with explicit `high` or `higher` upside.",
49
+ "**Compare 2-3 distinct approaches with stable Role/Upside columns** — Role values are `baseline` | `challenger` | `wild-card`; Upside is `low` | `modest` | `high` | `higher`; include real trade-offs, reuse notes, and reference-pattern source/disposition when a known pattern influenced the option; include exactly one challenger with explicit `high` or `higher` upside.",
48
50
  "**Collect reaction before recommending** — ask which option feels closest and what concern remains, then recommend based on that reaction.",
49
51
  "**Write the `Not Doing` list** — name 3-5 things this brainstorm explicitly is not committing to (vs. deferred). This protects scope from silent enlargement and the next stage from rework.",
50
52
  "**Self-review before user approval** — re-read the artifact and patch contradictions, weak trade-offs, placeholders, ambiguity, and weak handoff language. Record the result in `Self-Review Notes` using the calibrated review format: `- Status: Approved` (or `Issues Found`), `- Patches applied:` with inline note or sub-bullets, `- Remaining concerns:` with inline note or sub-bullets. Use `Patches applied: None` and `Remaining concerns: None` when there is nothing to record.",
51
53
  "**Request explicit approval** — state exactly what direction is being approved; do not advance without approval and artifact review.",
52
- "**Handoff** — only after approval, complete the stage and point to `/cc-next`."
54
+ "**Handoff** — only after approval, hand scope: upstream decisions used, explicit drift, confidence level, unresolved questions, next-stage risk hints, and non-goals."
53
55
  ],
54
56
  interactionProtocol: [
55
57
  "Start from observed project context; if the idea is vague, first narrow the project type with **one** structured question, then keep going.",
58
+ "Select depth explicitly: `lite`, `standard`, or `deep`; keep lite concise, but escalate when risk/ambiguity changes decisions.",
56
59
  "Lead with the premise check (right problem / direct path / what if nothing) and the `How Might We` reframing before approaches; both go in the artifact, not just the chat.",
57
60
  "Ask at most one question per turn, only when decision-changing; if using a structured question tool, send exactly one question object, not a multi-question form.",
58
61
  "Only non-critical preference/default assumptions may continue inline. STOP and ask when uncertainty affects scope, architecture, security, data loss, public API, migration, auth/pricing, or user approval.",
@@ -78,14 +81,17 @@ export const BRAINSTORM = {
78
81
  requiredEvidence: [
79
82
  "Artifact written to `.cclaw/artifacts/01-brainstorm-<slug>.md`.",
80
83
  "Project context was explored (files, docs, or recent activity referenced).",
81
- "Clarifying questions and their answers are captured.",
82
- "2-3 approaches with trade-offs are recorded, including one higher-upside challenger option.",
84
+ "Problem Decision Record includes product framing or technical-maintenance framing.",
85
+ "Clarity Gate records ambiguity score, decision boundaries, reaffirmed non-goals, and residual-risk handoff.",
86
+ "Clarifying questions are one-at-a-time and captured only when they change a decision or stop condition.",
87
+ "2-3 approaches with trade-offs are recorded, including one higher-upside challenger option and reference-pattern source/disposition when applicable.",
83
88
  "User reaction to approaches is captured before final recommendation.",
84
89
  "Final recommendation explicitly reflects user reaction.",
85
90
  "Selected Direction includes the handoff to the track-aware next stage: scope on standard, spec on medium when scope/design are skipped.",
86
91
  "When a promising option is parked, a seed file is created under `.cclaw/seeds/` and referenced in the artifact.",
87
92
  "Approved direction and approval marker are present.",
88
- "Assumptions and open questions are captured (or explicitly marked as none)."
93
+ "Assumptions and open questions are captured (or explicitly marked as none).",
94
+ "Scope handoff includes upstream decisions used, explicit drift, confidence, unresolved questions, next-stage risk hints, and non-goals."
89
95
  ],
90
96
  inputs: ["problem statement", "constraints", "success criteria"],
91
97
  requiredContext: [
@@ -124,16 +130,18 @@ export const BRAINSTORM = {
124
130
  },
125
131
  artifactValidation: [
126
132
  { section: "Context", required: true, validationRule: "Must reference project state and relevant existing code or patterns. A `Discovered context` subsection (or list) is recommended for downstream traceability." },
127
- { section: "Problem", required: true, validationRule: "Must define what we're solving, success criteria, and constraints." },
133
+ { section: "Problem Decision Record", required: true, validationRule: "Must include either product framing fields (persona/JTBD/pain/value/evidence/success/why-now/do-nothing/non-goals) or technical-maintenance fields (operator/developer, failure mode, operational improvement, verification signal, do-nothing cost, non-goals)." },
128
134
  { section: "Premise Check", required: false, validationRule: "Recommended: explicit answers to `Right problem?`, `Direct path?`, `What if we do nothing?` — take a position, do not hedge." },
129
135
  { section: "How Might We", required: false, validationRule: "Recommended: a single `How Might We …?` line naming the user, the outcome, and the binding constraint." },
130
- { section: "Sharpening Questions", required: false, validationRule: "Recommended: 3-5 question/answer pairs with explicit `Decision impact` so downstream stages see what each answer changed." },
136
+ { section: "Clarity Gate", required: false, validationRule: "Recommended before recommendation lock: include ambiguity score (0.00-1.00), decision boundaries, reaffirmed non-goals, and residual-risk handoff for scope." },
137
+ { section: "Sharpening Questions", required: false, validationRule: "Recommended only when needed: one decision-changing question per turn with explicit `Decision impact`; compact tasks may record `None - early exit` with rationale." },
131
138
  { section: "Clarifying Questions", required: false, validationRule: "Must capture question, answer, and decision impact for each clarifying question." },
132
- { section: "Approach Tier", required: true, validationRule: "Must classify depth as Lightweight/Standard/Deep and explain why." },
139
+ { section: "Approach Tier", required: true, validationRule: "Must classify depth as lite/standard/deep and explain the risk/uncertainty signal." },
133
140
  { 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." },
134
- { section: "Approaches", required: true, validationRule: "Must compare 2-3 distinct options with real trade-offs. Use the canonical `Role` column with `baseline` | `challenger` | `wild-card` and the `Upside` column with `low` | `modest` | `high` | `higher`; include exactly one challenger row with `high` or `higher` upside." },
141
+ { section: "Reference Pattern Candidates", required: false, validationRule: "Recommended when examples influence direction: list pattern/source, reusable invariant, accept/reject/defer disposition, and reason before approaches are finalized." },
142
+ { section: "Approaches", required: true, validationRule: "Must compare 2-3 distinct options with real trade-offs. Use the canonical `Role` column with `baseline` | `challenger` | `wild-card` and the `Upside` column with `low` | `modest` | `high` | `higher`; include exactly one challenger row with `high` or `higher` upside, and cite reference-pattern source/disposition when applicable." },
135
143
  { section: "Approach Reaction", required: true, validationRule: "Must appear before Selected Direction and summarize user reaction before recommendation, including `Closest option`, `Concerns`, and what changed after reaction." },
136
- { section: "Selected Direction", required: true, validationRule: "Must include the selected approach, an explicit approval marker, rationale traceable to the prior Approach Reaction, and a track-aware next-stage handoff." },
144
+ { section: "Selected Direction", required: true, validationRule: "Must include the selected approach, explicit approval marker, rationale traceable to Approach Reaction, and scope handoff with decisions, drift, confidence, unresolved questions, risk hints, and non-goals." },
137
145
  { section: "Not Doing", required: false, validationRule: "Recommended: 3-5 explicitly non-committed items (distinct from deferred). Protects scope from silent enlargement and the next stage from rework." },
138
146
  { section: "Design", required: false, validationRule: "Must cover architecture, key components, and data flow scaled to complexity." },
139
147
  { section: "Visual Companion", required: false, validationRule: "If architecture/data-flow complexity is medium+, include compact ASCII/Mermaid diagram or explicitly justify omission." },
@@ -142,7 +150,7 @@ export const BRAINSTORM = {
142
150
  ],
143
151
  trivialOverrideSections: [
144
152
  "Context",
145
- "Problem",
153
+ "Problem Decision Record",
146
154
  "Approach Tier",
147
155
  "Short-Circuit Decision",
148
156
  "Selected Direction"
@@ -150,7 +158,8 @@ export const BRAINSTORM = {
150
158
  },
151
159
  reviewLens: {
152
160
  outputs: [
153
- "approved design direction",
161
+ "Problem Decision Record",
162
+ "approved direction",
154
163
  "alternatives with trade-offs",
155
164
  "brainstorm artifact"
156
165
  ],