cclaw-cli 3.0.0 → 5.0.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 (41) hide show
  1. package/dist/artifact-linter/brainstorm.js +51 -2
  2. package/dist/artifact-linter/design.js +14 -3
  3. package/dist/artifact-linter/review-army.d.ts +25 -0
  4. package/dist/artifact-linter/review-army.js +155 -0
  5. package/dist/artifact-linter/review.js +13 -0
  6. package/dist/artifact-linter/scope.js +27 -48
  7. package/dist/artifact-linter/shared.d.ts +98 -11
  8. package/dist/artifact-linter/shared.js +280 -113
  9. package/dist/artifact-linter.d.ts +12 -2
  10. package/dist/artifact-linter.js +29 -13
  11. package/dist/content/core-agents.js +6 -1
  12. package/dist/content/examples.js +8 -0
  13. package/dist/content/hooks.js +2 -1
  14. package/dist/content/idea.js +14 -2
  15. package/dist/content/review-prompts.js +3 -3
  16. package/dist/content/skills-elicitation.js +61 -20
  17. package/dist/content/skills.js +19 -6
  18. package/dist/content/stage-schema.js +46 -18
  19. package/dist/content/stages/_lint-metadata/index.js +1 -2
  20. package/dist/content/stages/brainstorm.js +6 -3
  21. package/dist/content/stages/design.js +13 -12
  22. package/dist/content/stages/plan.js +1 -1
  23. package/dist/content/stages/review.js +21 -21
  24. package/dist/content/stages/schema-types.d.ts +9 -0
  25. package/dist/content/stages/scope.js +22 -20
  26. package/dist/content/stages/spec.js +3 -3
  27. package/dist/content/stages/tdd.js +1 -0
  28. package/dist/content/templates.d.ts +8 -1
  29. package/dist/content/templates.js +115 -43
  30. package/dist/flow-state.d.ts +12 -0
  31. package/dist/gate-evidence.d.ts +37 -1
  32. package/dist/gate-evidence.js +37 -3
  33. package/dist/harness-adapters.js +8 -0
  34. package/dist/install.js +22 -11
  35. package/dist/internal/advance-stage/advance.d.ts +1 -0
  36. package/dist/internal/advance-stage/advance.js +5 -2
  37. package/dist/internal/advance-stage/parsers.d.ts +8 -0
  38. package/dist/internal/advance-stage/parsers.js +27 -1
  39. package/dist/internal/advance-stage/start-flow.js +13 -0
  40. package/dist/run-persistence.js +14 -2
  41. package/package.json +1 -1
@@ -32,14 +32,15 @@ export const REVIEW = {
32
32
  },
33
33
  executionModel: {
34
34
  checklist: [
35
+ "**Boundary with TDD (do NOT re-classify slice findings).** `tdd.Per-Slice Review` OWNS severity-classified findings WITHIN a single slice (correctness, edge cases, regression for that slice). `review` OWNS whole-diff Layer 1 (spec compliance) plus Layer 2 (cross-slice integration findings, security sweep, dependency/version audit, observability). When the same finding ID appears in both `06-tdd.md > Per-Slice Review` and `07-review.md` / `07-review-army.json`, the severity/disposition MUST match — the cross-artifact-duplication linter blocks otherwise.",
35
36
  "Diff Scope — Run `git diff` against base branch. If no diff, exit early with APPROVED (no changes to review). Scope the review to changed files unless blast-radius analysis requires wider inspection.",
36
37
  "Change-Size Check — ~100 lines = normal. ~300 lines = consider splitting. ~1000+ lines = strongly recommend stacked PRs. Flag large diffs to the user.",
37
38
  "Risk-Based Second Opinion — compute changed-line count, files-touched count, and trust-boundary movement. Dispatch an adversarial reviewer only when trust boundaries changed, Critical/Important ambiguity remains, or the diff is both large and high-risk; otherwise record `not triggered`.",
38
- "Load upstream evidence — read TDD artifact (RED + GREEN + REFACTOR), spec, and the active track's upstream source items.",
39
+ "Load upstream evidence — read TDD artifact (RED + GREEN + REFACTOR + per-slice reviews), spec, design (architecture lens carry-forward), and the active track's upstream source items.",
39
40
  "Confirm spec acceptance criteria and reproduction slices are covered directly in the review artifact evidence.",
40
41
  "Layer 1: Spec Compliance — check every acceptance criterion against implementation. Verdict: pass/fail per criterion.",
41
42
  "Review Evidence Scope — record base/head, files inspected, changed-file coverage, diagnostics run, dependency/version audit when relevant, and any files intentionally not inspected with explicit reason.",
42
- "Layer 2: Integrated findings — one structured pass tagged by category: correctness, security, performance, architecture, external-safety. Every finding uses file:line; if impossible, include an explicit no-line reason.",
43
+ "**Layer 2: Cross-slice integration findings — only findings that span >1 slice OR are not surfaced by per-slice tdd reviews.** Carry-forward: cite tdd per-slice review IDs already accepted; do not re-classify them. New categories owned by review Layer 2: cross-slice correctness, dependency/version audit, security sweep, observability gaps, external-safety. **Performance and architecture findings come from the design lens (cite `03-design-<slug>.md` Performance Budget / Architecture Decision Record); they are NOT re-derived in review.** Every finding uses file:line; if impossible, include an explicit no-line reason.",
43
44
  "Security sweep — mandatory dedicated security-reviewer pass across diff + touched modules. A zero-finding pass must include `NO_CHANGE_ATTESTATION` or `NO_SECURITY_IMPACT` with rationale and inspected surfaces.",
44
45
  "Incoming Feedback Intake — when human reviewer comments, bot findings, or CI annotations exist, keep a per-comment disposition queue and mirror outcomes into `07-review.md` + `07-review-army.json` before final verdict.",
45
46
  "Structured Review reconciliation — normalize findings into `07-review-army.json`, dedup by fingerprint, and mark multi-specialist confirmations when multiple lenses agree.",
@@ -81,7 +82,8 @@ export const REVIEW = {
81
82
  "Acceptance/reproduction coverage evidence recorded in the review artifact (AC and source-item/slice coverage snapshot).",
82
83
  "Layer 1 verdict captured with per-criterion pass/fail.",
83
84
  "Review Evidence Scope lists files inspected, changed-file coverage, diagnostics run, and omitted files with explicit reason.",
84
- "Layer 2 sections completed across correctness, security, performance, architecture, and external-safety findings.",
85
+ "Layer 2 cross-slice findings recorded for: cross-slice correctness, security sweep, dependency/version audit, observability, external-safety. Performance/architecture come from design lens carry-forward (`03-design-<slug>.md`) — do NOT re-derive them.",
86
+ "Per-slice tdd review findings cited (not re-classified): each `06-tdd.md > Per-Slice Review` ID accepted in review must keep matching severity/disposition (cross-artifact-duplication linter enforces this).",
85
87
  "Every finding cites `file:line`, or an explicit no-line reason is recorded.",
86
88
  "No-finding attestation is explicit when no issues are found.",
87
89
  "Dependency/version audit is recorded when manifests, lockfiles, generated clients, CI, runtime config, or external APIs are relevant.",
@@ -123,7 +125,7 @@ export const REVIEW = {
123
125
  { section: "Review Evidence Scope", required: true, validationRule: "Base/head, files inspected, changed-file coverage, diagnostics run, omitted files with reason, and reviewer/security-reviewer delegation evidence." },
124
126
  { section: "Changed-File Coverage", required: true, validationRule: "Each changed file is covered, intentionally omitted with no-impact reason, or linked to a broader inspected module." },
125
127
  { section: "Layer 1 Verdict", required: true, validationRule: "Per-criterion pass/fail with references." },
126
- { section: "Layer 2 Findings", required: false, validationRule: "Each finding has severity, category, file:line or explicit no-line reason, description, and resolution status across correctness/security/performance/architecture/external-safety. If there are no findings, include a no-finding attestation." },
128
+ { section: "Layer 2 Findings", required: false, validationRule: "Each finding has severity, category, file:line or explicit no-line reason, description, and resolution status. Wave 23 (v5.0.0): owned categories are cross-slice correctness, security, dependency/version, observability, and external-safety. Performance and architecture findings appear here only as carry-forward citations to `03-design-<slug>.md` (Performance Budget, ADR) — they are NOT re-derived. If there are no findings, include a no-finding attestation." },
127
129
  { section: "Lens Coverage", required: true, validationRule: "Reviewer must report inline lens outcomes: Performance/Compatibility/Observability as `NO_IMPACT` or `FOUND_<n>`, plus `Security: routed to security-reviewer`." },
128
130
  { section: "Security Sweep Attestation", required: false, validationRule: "Dedicated security-reviewer result: findings or `NO_CHANGE_ATTESTATION` / `NO_SECURITY_IMPACT` with inspected surfaces and rationale." },
129
131
  { section: "Dependency & Version Audit", required: false, validationRule: "Required when manifests, lockfiles, generated clients, CI, runtime config, or external APIs changed; otherwise record no-impact rationale." },
@@ -151,12 +153,12 @@ export const REVIEW = {
151
153
  stopGate: true
152
154
  },
153
155
  {
154
- title: "Layer 2: Integrated Correctness / Security / Performance / Architecture / External-Safety",
156
+ title: "Layer 2: Cross-slice Integration Findings",
155
157
  evaluationPoints: [
156
- "Logic errors and boundary violations",
157
- "Race conditions and concurrency issues",
158
- "Null/undefined handling",
159
- "Error propagation and recovery paths"
158
+ "Cross-slice correctness: logic errors and boundary violations that span >1 slice",
159
+ "Race conditions and concurrency issues across slice boundaries",
160
+ "Null/undefined handling in shared paths",
161
+ "Error propagation and recovery across module seams (single-slice findings stay in tdd Per-Slice Review)"
160
162
  ],
161
163
  stopGate: true
162
164
  },
@@ -171,24 +173,22 @@ export const REVIEW = {
171
173
  stopGate: true
172
174
  },
173
175
  {
174
- title: "Specialist Lens: Performance",
176
+ title: "Performance Lens: Carry-forward from Design",
175
177
  evaluationPoints: [
176
- "N+1 query patterns",
177
- "Memory leak potential",
178
- "Missing caching opportunities",
179
- "Hot path complexity analysis"
178
+ "Cite `03-design-<slug>.md > Performance Budget` per critical path",
179
+ "Surface DRIFT only when implementation diff measurably violates a budgeted threshold; do NOT re-derive performance findings from scratch",
180
+ "Hot path / N+1 / caching observations belong here only when they cross slice boundaries and were not flagged by tdd Per-Slice Review"
180
181
  ],
181
- stopGate: true
182
+ stopGate: false
182
183
  },
183
184
  {
184
- title: "Specialist Lens: Architecture Fit",
185
+ title: "Architecture Lens: Carry-forward from Design",
185
186
  evaluationPoints: [
186
- "Does implementation match the locked design?",
187
- "Coupling and cohesion assessment",
188
- "Interface contract compliance",
189
- "Unintended architectural drift"
187
+ "Cite `03-design-<slug>.md > Architecture Decision Record (ADR)` and `Engineering Lock`",
188
+ "Surface DRIFT only when the implementation departs from the locked architecture; do NOT re-derive boundary/coupling/interface analysis from scratch",
189
+ "Cross-slice architectural drift findings use `file:line` plus the violated ADR ID"
190
190
  ],
191
- stopGate: true
191
+ stopGate: false
192
192
  },
193
193
  {
194
194
  title: "Specialist Lens: External Safety Checklist",
@@ -38,6 +38,15 @@ export interface StageAutoSubagentDispatch {
38
38
  when: string;
39
39
  purpose: string;
40
40
  requiresUserGate: boolean;
41
+ /**
42
+ * When this delegation may run relative to the adaptive elicitation Q&A loop.
43
+ * - `pre-elicitation` — run before any user dialogue (rare; only for trivial info-gathering).
44
+ * - `post-elicitation` — run only after the Q&A loop converges (default for brainstorm/scope/design
45
+ * so subagents do not preempt the user dialogue).
46
+ * - `any` — no ordering constraint (default for stages that do not run elicitation:
47
+ * spec/plan/tdd/review/ship).
48
+ */
49
+ runPhase?: "pre-elicitation" | "post-elicitation" | "any";
41
50
  /** Role category used by generated routing tables and lifecycle checks. */
42
51
  dispatchClass?: StageSubagentDispatchClass;
43
52
  /** Strict status/evidence contract the dispatched agent must return. */
@@ -13,7 +13,7 @@ export const SCOPE = {
13
13
  philosophy: {
14
14
  hardGate: "Do NOT begin architecture, design, or code. This stage produces scope decisions only. Do not silently add or remove scope — every change is an explicit user opt-in.",
15
15
  ironLaw: "EVERY SCOPE CHANGE IS AN EXPLICIT USER OPT-IN — NEVER A SILENT ENLARGEMENT OR TRIM.",
16
- purpose: "Decide the right scope before technical lock-in using explicit mode selection and rigorous premise challenge.",
16
+ purpose: "Decide the right scope before technical lock-in using explicit mode selection and the brainstorm premise as carry-forward (not re-authored).",
17
17
  whenToUse: [
18
18
  "After brainstorm approval",
19
19
  "Before architecture/design lock-in",
@@ -28,7 +28,8 @@ export const SCOPE = {
28
28
  "Skipping pre-scope audit because the task looks small",
29
29
  "Scope silently expanded during discussion",
30
30
  "No explicit out-of-scope section",
31
- "Premise accepted without challenge",
31
+ "Re-authoring brainstorm's `## Premise Check` instead of citing it via Upstream Handoff (premise carry-forward only)",
32
+ "Enumerating Implementation Alternatives in scope (architecture-tier choice belongs to design)",
32
33
  "Sycophantic agreement without evidence-based pushback",
33
34
  "Hedged recommendations that avoid taking a position",
34
35
  "Batching multiple scope issues into one question",
@@ -45,15 +46,16 @@ export const SCOPE = {
45
46
  },
46
47
  executionModel: {
47
48
  checklist: [
48
- "**Adaptive elicitation loop (shared skill)** load `.cclaw/skills/adaptive-elicitation/SKILL.md` and run one decision-changing question per turn via harness-native tools. After each answer, append one row to `## Q&A Log` (`Turn | Question | User answer (1-line) | Decision impact`). Continue until scope clarity is sufficient or user signals to proceed.",
49
+ "**ADAPTIVE ELICITATION COMES FIRST (no exceptions, no subagent dispatch before).** Load `.cclaw/skills/adaptive-elicitation/SKILL.md`. Walk the scope forcing questions one-at-a-time via the harness-native question tool, append one row to `## Q&A Log` (`Turn | Question | User answer (1-line) | Decision impact`) after each user answer. Continue until forcing-questions converge (all answered/skipped/waived) OR Ralph-Loop convergence detector says no new decision-changing rows in last 2 iterations OR user records an explicit stop-signal row. Only then propose the scope contract draft, recommend a mode, or dispatch any delegations. The linter `qa_log_unconverged` rule will block `stage-complete` if convergence is not reached.",
49
50
  "**Scope forcing questions (must be covered or explicitly waived)** — what is definitely in/out, which upstream decisions are locked, and what rollback path protects users if scope assumptions fail.",
50
51
  "**Scope contract first** — read brainstorm handoff, name upstream decisions used, explicit drift, confidence, unresolved questions, and next-stage risk hints; draft the in-scope/out-of-scope/deferred/discretion contract before any design choice.",
51
- "**Premise and leverage check** — answer in the artifact: *Right problem? Direct path? What if nothing? Where can we leverage existing code? What is the reversibility cost?* Take a position; do not hedge.",
52
+ "**Premise carry-forward (do NOT re-author)** — brainstorm OWNS the premise check (right problem / direct path / what if nothing). Cite brainstorm's `## Premise Check` section in `## Upstream Handoff > Decisions carried forward`. Add a row to `## Premise Drift` only when the scope-stage Q&A surfaced NEW evidence that materially changes the brainstorm answer (e.g. new constraint, new user signal). Otherwise mark `Premise Drift: None` — do not duplicate the brainstorm premise table.",
52
53
  "**Conditional 10-star boundary** — for deep/high-risk/product-strategy work, show what would make the product meaningfully better, then explicitly choose what ships now, what is deferred, and what is excluded without vague `later/for now` placeholders. Skip this for straightforward repair work and record `not needed: compact scope`.",
53
54
  "**Pick one operational mode with the user** — HOLD SCOPE preserves focus; SELECTIVE EXPANSION cherry-picks high-leverage reference ideas; SCOPE EXPANSION explores ambitious alternatives; SCOPE REDUCTION cuts to the essential wedge. Recommend one, state why and what signal would change it, then keep elicitation focused until the user either approves or asks to proceed with draft boundaries.",
54
55
  "**Run mode-specific analysis only to needed depth** — lite keeps the selected-mode row compact; standard adds requirements/locked decisions/discretion; deep may add Landscape Check, Taste Calibration, Reference Pattern Registry, Reference Pull, Ambitious Alternatives, and Ruthless Minimum Slice evidence when mode/risk warrants it.",
55
56
  "**Decision-driver contract** — list weighted decision drivers (value, risk, reversibility, effort, timeline) and score candidate scope moves so the selected mode and boundaries are evidence-backed, not preference-led.",
56
- "**Compare implementation alternatives** — include minimum viable, product-grade, and ideal architecture options with effort (S/M/L/XL), risk (Low/Med/High), pros, cons, and reuses. Recommend one and tie it to mode.",
57
+ "**Architecture handoff (do NOT pick architecture tier here)** — design OWNS architecture choice (minimum-viable / product-grade / ideal). Scope only picks the SCOPE MODE (HOLD/SELECTIVE/EXPAND/REDUCE) and boundary; record in `## Scope Contract > Design handoff` what design must decide (e.g. `architecture-tier`, `framework`, `data-model`). Do NOT enumerate Implementation Alternatives in scope.",
58
+ "**Constraints (carry-forward from brainstorm/external sources)** — record explicit external/regulatory/system/integration constraints in `## Scope Contract > Constraints`. Spec OWNS testable assumptions (`## Assumptions Before Finalization`); do NOT duplicate constraint material as assumption material.",
57
59
  "**Run outside voice before final approval** — for simple/low-risk scope, record one concise adversarial self-check row; for complex/high-risk/configured scope, iterate until threshold. Record the loop summary in `## Scope Outside Voice Loop`, but do not treat it as user approval.",
58
60
  "**Run early Ralph loop discipline** — after each producer iteration, append a `Critic Pass` JSONL row to `.cclaw/state/early-loop-log.jsonl`, refresh `.cclaw/state/early-loop.json`, and iterate until open concerns clear or convergence guard escalates.",
59
61
  "**Ask only one decision-changing question** — if the user rejects the contract but is unsure, offer 3-4 concrete scope moves instead of open-ended interrogation.",
@@ -63,23 +65,23 @@ export const SCOPE = {
63
65
  "\"Strong success criteria let you loop independently. Weak criteria require constant clarification.\"",
64
66
  decisionProtocolInstruction("scope mode selection", "present expand/selective/hold/reduce as labeled options with trade-offs and mark one as (recommended)", "recommend the option that best covers the prime-directive failure modes, four data-flow paths, observability, and deferred handling for the in-scope set with the smallest blast radius. Base your recommendation on default heuristics: greenfield -> expand, enhancement -> selective, bugfix/hotfix/refactor -> hold, broad blast radius -> reduce"),
65
67
  "Run the shared adaptive elicitation cycle from `.cclaw/skills/adaptive-elicitation/SKILL.md`, including stop-signal handling (RU/EN/UA), smart-skip, conditional grilling triggers, and append-only `## Q&A Log` updates.",
66
- "Do not walk the full checklist by default. Lead with a proposed scope contract, selected depth (`lite`/`standard`/`deep`), and the one decision that matters most; label the mode as recommended, not selected, until the user answers.",
68
+ "**Lead with adaptive elicitation, not with a proposed contract.** First walk scope forcing questions one-at-a-time per `adaptive-elicitation` skill. Only AFTER the Q&A loop converges (forcing-Qs answered/waived OR user stop-signal row recorded) propose the scope contract draft for approval. Lite-tier may compress: ask the smallest forcing-Q set (>= linter floor for `lightweight`/`scope`), then propose contract.",
67
69
  "For low-risk concrete asks, keep the proposal compact but still explicit: recommend (do not auto-select) one mode, show exact in/out/deferred boundaries, and request explicit approval before finalizing the artifact or completing the stage.",
68
- "Challenge premise first, take a firm position, and name one concrete condition that would change it.",
70
+ "Cite brainstorm's premise via `## Upstream Handoff` and take a firm position on whether scope-stage Q&A surfaced any premise drift; do NOT re-author the brainstorm Premise Check table.",
69
71
  "Push back on weak framing: vague scope needs a specific user/problem, platform vision needs a narrow wedge, social proof needs behavioral evidence.",
70
72
  "Resolve one structural scope issue at a time. Only non-critical preference/default assumptions may continue; STOP on uncertainty about scope boundary, architecture commitment, security, data loss, public API, migration, auth/pricing, or required user approval.",
71
73
  "If the user says no but cannot name the change, offer concrete moves: keep scope, add one obvious adjacent capability, reduce to wedge, or re-open stack/product direction.",
72
74
  "Before final approval, record outside-voice findings and a `## Scope Outside Voice Loop` table per the Scope Outside Voice Loop policy above.",
73
75
  "**STOP.** Wait for explicit user approval of the scope mode and scope contract before writing final approval language or advancing.",
74
- "**STOP BEFORE ADVANCE.** Mandatory delegation `planner` must be completed or explicitly waived for a real blocker. If the active harness cannot isolate a planner, run a role-switch planner pass instead: announce `## cclaw role-switch: scope/planner (mandatory)`, write the planner output/evidence into the scope artifact, and append a completed delegation row with `fulfillmentMode: \"role-switch\"` plus non-empty `evidenceRefs`. Then close with `node .cclaw/hooks/stage-complete.mjs scope --passed=scope_mode_selected,scope_contract_written,scope_user_approved --evidence-json '{\"scope_mode_selected\":\"<user-approved mode + rationale>\",\"scope_contract_written\":\"<artifact path + sections>\",\"scope_user_approved\":\"<explicit user approval quote or summary>\"}'`. `scope_user_approved` must cite the user's approval; review-loop evidence alone is not approval."
76
+ "**STOP BEFORE ADVANCE.** Mandatory delegation `planner` runs **AFTER user approval of the scope contract**, not before Q&A. Sequence is: Q&A loop -> propose contract -> user approval -> `planner` delegation -> `stage-complete`. If you delegate `planner` before the Q&A loop converges, you violate the elicitation contract and the linter will block stage-complete via `qa_log_unconverged`. Legal fulfillment modes for `planner`: (a) **harness-native Task tool** — run the delegation, then record the lifecycle row via `node .cclaw/hooks/delegation-record.mjs --stage=scope --agent=planner --mode=mandatory --status=completed --span-id=<uuid> --dispatch-surface=cursor-task --agent-definition-path=<agent-md-path> --evidence-ref=<artifact#section>` (the helper sets `fulfillmentMode: \"generic-dispatch\"` automatically); (b) **role-switch** — announce `## cclaw role-switch: scope/planner (mandatory)`, write the planner output/evidence into the scope artifact, then record the row with `--dispatch-surface=role-switch --agent-definition-path=<artifact-anchor>` (helper sets `fulfillmentMode: \"role-switch\"` automatically); (c) **cclaw subagent helper** if available, with `--dispatch-surface=isolated`. Run `node .cclaw/hooks/stage-complete.mjs scope` from the tool layer (do not paste the command into chat); report only the resulting summary."
75
77
  ],
76
78
  process: [
77
- "Run pre-scope audit before premise challenge.",
78
- "Run the scope pass scaled to risk: default to job-to-be-done plus explicit scope contract; add premise challenge, 10-star upside, smallest useful wedge, and change conditions only for deep/high-risk scope.",
79
- "Compare minimum viable, product-grade, and ideal architecture scope alternatives with explicit reuse/effort/risk.",
80
- "Recommend a scope mode with explicit rationale, then ask for user opt-in before treating it as selected.",
79
+ "Run pre-scope system audit (git log/diff/stash + debt-marker scan) — scope OWNS the repo audit; design will only diff the blast radius since this scope baseline.",
80
+ "Cite brainstorm's premise check via Upstream Handoff; record `## Premise Drift` only when the scope-stage Q&A surfaced new evidence that materially changes brainstorm's answer.",
81
+ "Run the scope pass scaled to risk: default to job-to-be-done plus explicit scope contract; add 10-star upside, smallest useful wedge, and change conditions only for deep/high-risk scope.",
82
+ "Recommend a scope mode (HOLD/SELECTIVE/EXPAND/REDUCE) with explicit rationale, then ask for user opt-in before treating it as selected. Do NOT enumerate architecture alternatives — design owns architecture choice.",
81
83
  "Run outside voice / adversarial self-check before final approval and record a valid `## Scope Outside Voice Loop` table.",
82
- "Write explicit scope contract, discretion areas, deferred items, error/rescue registry, and D-XX locked decisions.",
84
+ "Write explicit scope contract, discretion areas, deferred items, error/rescue registry, constraints (external/regulatory/system), and D-XX locked decisions.",
83
85
  "Produce scope summary, completion dashboard, and exact next-stage handoff before asking final approval."
84
86
  ],
85
87
  requiredGates: [
@@ -97,8 +99,9 @@ export const SCOPE = {
97
99
  "Scope Contract captures requirements, locked decisions, discretion areas, accepted/rejected/deferred reference ideas from the Reference Pattern Registry, success definition, and design handoff.",
98
100
  "Decision Drivers section records weighted criteria and per-option scores used to choose mode and boundary moves.",
99
101
  "Scope Completeness Score is recorded (0.00-1.00) with the explicit blocker list for any remaining uncertainty.",
100
- "Locked Decisions section lists stable LD#hash anchors for non-negotiable boundaries.",
101
- "Premise challenge findings documented.",
102
+ "Locked Decisions section lists stable D-XX IDs for non-negotiable boundaries.",
103
+ "Premise carry-forward recorded: brainstorm `## Premise Check` cited in `## Upstream Handoff > Decisions carried forward`; `## Premise Drift` is `None` unless new scope-stage evidence materially changes brainstorm's answer.",
104
+ "Constraints (external/regulatory/system/integration) recorded in `## Scope Contract > Constraints` — spec must reference these in `## Constraints and Assumptions`, not restate them.",
102
105
  "Outside Voice findings and dispositions are recorded (accept/reject/defer with rationale) before final approval.",
103
106
  "Scope outside-voice loop summary includes a table with columns Iteration, Quality Score, Findings, plus Stop reason, Target score, Max iterations, and unresolved concerns. This is outside-voice evidence only; it does not satisfy user approval.",
104
107
  "Early-loop status is reflected via `Victory Detector` / `Critic Pass` sections and `.cclaw/state/early-loop.json` when concerns remain.",
@@ -148,10 +151,10 @@ export const SCOPE = {
148
151
  },
149
152
  artifactValidation: [
150
153
  { section: "Upstream Handoff", required: false, validationRule: "Summarizes brainstorm/idea decisions, constraints, open questions, and explicit drift before scope decisions." },
151
- { section: "Pre-Scope System Audit", required: true, validationRule: "Must capture git log -30, git diff --stat, git stash list, and debt-marker scan (TODO/FIXME/XXX/HACK) before premise challenge." },
154
+ { section: "Pre-Scope System Audit", required: true, validationRule: "Must capture git log -30, git diff --stat, git stash list, and debt-marker scan (TODO/FIXME/XXX/HACK). Scope OWNS the repo audit; design will only diff the blast radius since this scope baseline." },
152
155
  { section: "Prime Directives", required: false, validationRule: "For each scoped capability: named failure modes, explicit error surface, four data-flow paths, interaction edge cases, observability expectations, and deferred-item handling." },
153
- { section: "Premise Challenge", required: false, validationRule: "Must list at least 3 question/answer rows in a markdown table or bullet list (gstack default trio: right problem? direct path? what if we do nothing? extend with leverage and reversibility for richer scope). The linter enforces structure, not English wording answers may be in any language." },
154
- { section: "Scope Contract", required: true, validationRule: "Canonical contract: selected mode, in scope, out of scope, requirements, locked decisions, discretion areas, deferred ideas, accepted/rejected reference ideas, success definition, and design handoff." },
156
+ { section: "Premise Drift", required: false, validationRule: "Optional carry-forward marker: brainstorm OWNS the premise check. State `None` unless scope-stage Q&A surfaced new evidence (constraint, user signal, regulatory change) that materially changes brainstorm's `## Premise Check` answer; in that case record one or more drift rows citing the new evidence and the affected brainstorm question." },
157
+ { section: "Scope Contract", required: true, validationRule: "Canonical contract: selected mode, in scope, out of scope, requirements, locked decisions, discretion areas, deferred ideas, accepted/rejected reference ideas, constraints (external/regulatory/system/integration), success definition, and design handoff. Architecture choice is delegated to design — do NOT enumerate Implementation Alternatives here." },
155
158
  { section: "Decision Drivers", required: false, validationRule: "Recommended: weighted decision drivers (value, risk, reversibility, effort, timeline) with scored options and the selected boundary rationale." },
156
159
  { section: "Scope Completeness Score", required: false, validationRule: "Recommended: score 0.00-1.00 plus unresolved blockers and the escalation trigger when confidence is low." },
157
160
  { section: "Landscape Check", required: false, validationRule: "Optional evidence heading for EXPAND/SELECTIVE/deep modes: include reference insight and impact on scope, or omit for compact HOLD SCOPE." },
@@ -161,8 +164,7 @@ export const SCOPE = {
161
164
  { section: "Ambitious Alternatives", required: false, validationRule: "Optional evidence heading for SCOPE EXPANSION/SELECTIVE: list larger alternatives considered and their disposition." },
162
165
  { section: "Ruthless Minimum Slice", required: false, validationRule: "Optional evidence heading for SCOPE REDUCTION or high-risk scope: define the smallest useful wedge and what it proves." },
163
166
  { section: "Requirements", required: false, validationRule: "Table of stable requirement IDs (R1, R2, R3…) one per row with observable outcome, priority, and source. IDs are assigned once and never renumbered across scope/design/spec/plan/review; dropped requirements stay with Priority `DROPPED`." },
164
- { section: "Locked Decisions (LD#hash)", required: false, validationRule: "List of stable locked decisions with unique `LD#<sha8>` anchors. Each anchor is derived from the normalized Decision cell and is referenced downstream for cross-stage traceability." },
165
- { section: "Implementation Alternatives", required: false, validationRule: "2-3 options with Name, Summary, Effort, Risk, Pros, Cons, and Reuses. Must include minimal viable and ideal architecture options." },
167
+ { section: "Locked Decisions", required: false, validationRule: "List of stable locked decisions, each with a unique `D-XX` ID. IDs are stable across edits so downstream stages can reference them; renumbering or duplicating IDs breaks the cross-stage traceability check." },
166
168
  { section: "Scope Mode", required: true, validationRule: "Must state selected mode and rationale with default heuristic justification." },
167
169
  { section: "Mode-Specific Analysis", required: false, validationRule: "Default path: one selected-mode row with rationale. Deep/complex scope only: document the expanded analysis matching the selected mode." },
168
170
  { section: "In Scope / Out of Scope", required: true, validationRule: "Two separate explicit lists. Canonical form is one `## In Scope / Out of Scope` section with `### In Scope` and `### Out of Scope`; legacy split `## In Scope` and `## Out of Scope` headings are accepted. Out-of-scope must not be empty." },
@@ -39,8 +39,8 @@ export const SPEC = {
39
39
  "Read upstream — standard track loads design + scope; medium loads brainstorm/spec handoff; quick loads `00-idea.md` plus any reproduction context. Cross-reference only artifacts that exist on the active track.",
40
40
  "Define measurable acceptance criteria — each criterion must be observable and falsifiable. No vague adjectives.",
41
41
  "Capture edge cases — for each criterion, define at least one boundary condition and one error condition.",
42
- "Document constraints and assumptions regulatory, system, integration, and performance boundaries. Only non-critical preference/default assumptions may continue; STOP on uncertainty about scope, architecture, security, data loss, public API, migration, auth/pricing, or required user approval.",
43
- "Surface assumptions before finalization list each assumption with source/confidence, validation path, and whether it is accepted, rejected, or still open.",
42
+ "**Constraints carry-forward (do NOT re-author).** Scope OWNS external/regulatory/system/integration constraints in `## Scope Contract > Constraints`. Cite them in `## Constraints and Assumptions > Constraints` (or mark `See scope: <ref>`). Add a constraint here only when spec-stage analysis surfaced a NEW one not present in scope. Spec OWNS testable assumptions (next bullet). Only non-critical preference/default assumptions may continue; STOP on uncertainty about scope, architecture, security, data loss, public API, migration, auth/pricing, or required user approval.",
43
+ "**Assumptions Before Finalization (spec-only owner).** Spec OWNS testable assumptions: list each with source/confidence, validation path, and accepted/rejected/open disposition in `## Assumptions Before Finalization`. Do NOT duplicate scope's constraints here as assumptions.",
44
44
  "Build the Acceptance Mapping contract — for each AC, map upstream design decision, observable evidence, verification method, and likely test level. If any column is unclear, rewrite the criterion.",
45
45
  "Run Spec Self-Review — explicitly verify placeholder/consistency/scope/ambiguity checks before approval.",
46
46
  "Present acceptance criteria to the user in 3-5-item batches, pausing for explicit ACK between batches (see Interaction Protocol).",
@@ -119,7 +119,7 @@ export const SPEC = {
119
119
  { section: "Acceptance Criteria", required: true, validationRule: "Each criterion is observable, measurable, and falsifiable. Standard track should include Requirement Ref and Design Decision Ref columns; quick track may instead link each AC to the reproduction contract or bug slice. AC IDs (AC-1, AC-2…) are stable across revisions — dropped ACs stay with Priority `DROPPED`." },
120
120
  { section: "Quick Reproduction Contract", required: false, validationRule: "Quick bug-fix specs own the reproduction contract: symptom, repro steps, expected RED test behavior, and acceptance criterion." },
121
121
  { section: "Edge Cases", required: true, validationRule: "At least one boundary and one error condition per criterion." },
122
- { section: "Constraints and Assumptions", required: false, validationRule: "All implicit assumptions surfaced. Constraints have sources." },
122
+ { section: "Constraints and Assumptions", required: false, validationRule: "Constraints are CARRIED FORWARD from scope's `## Scope Contract > Constraints` (cite with `See scope: <ref>` or copy with attribution). New spec-stage constraints (rare) get a citation to the spec-stage Q&A row that surfaced them. Assumptions are owned by `## Assumptions Before Finalization` — do NOT duplicate them here. Section may be `- See scope: 02-scope.md#constraints.` for the common case." },
123
123
  { section: "Assumptions Before Finalization", required: true, validationRule: "Each assumption has source/confidence, validation path, and accepted/rejected/open disposition before the Approval section is finalized." },
124
124
  { section: "Acceptance Mapping", required: true, validationRule: "Each criterion maps to upstream design decision, observable evidence, verification method, likely test level (unit/integration/e2e/manual), and command or manual steps when known." },
125
125
  { section: "Non-Functional Requirements", required: false, validationRule: "If present: performance thresholds, security constraints, scalability limits, reliability targets with measurable values." },
@@ -52,6 +52,7 @@ export const TDD = {
52
52
  "REFACTOR: continue the `test-author` evidence cycle (or a dedicated refactor mode when available) to improve code quality without behavior changes. Set `CCLAW_ACTIVE_AGENT=tdd-refactor` when the harness supports phase labels.",
53
53
  "Record evidence — capture test discovery, system-wide impact check, RED failure, GREEN output, and REFACTOR notes in the TDD artifact. When logging a `green` row, attach the closed acceptance-criterion IDs in `acIds` so Ralph Loop status counts them.",
54
54
  "Annotate traceability — link to the active track's source: plan task ID + spec criterion on standard/medium, or spec acceptance item / bug reproduction slice on quick.",
55
+ "**Boundary with review (do NOT escalate single-slice findings to whole-diff review).** `tdd.Per-Slice Review` OWNS severity-classified findings WITHIN one slice (correctness, edge cases, regression). `review` OWNS whole-diff Layer 1 (spec compliance) plus Layer 2 (cross-slice integration, security sweep, dependency/version audit, observability). When a single-slice finding genuinely needs whole-diff escalation, surface it in `06-tdd.md > Per-Slice Review` first; review will cite it (not re-classify) and the cross-artifact-duplication linter requires matching severity/disposition.",
55
56
  "Per-Slice Review (conditional) — if the slice meets any trigger (touchCount >= filesChangedThreshold, touchPaths match touchTriggers, or highRisk=true), append a `## Per-Slice Review` entry for this slice before moving on (see the dedicated section below).",
56
57
  "Repeat for each slice — return to step 1 for the next plan slice."
57
58
  ],
@@ -1,4 +1,11 @@
1
1
  export declare const ARTIFACT_TEMPLATES: Record<string, string>;
2
2
  export declare const RULEBOOK_MARKDOWN = "# Cclaw Rulebook\n\n## MUST_ALWAYS\n- Follow flow order: brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship\n- Require explicit user confirmation after plan before TDD\n- Keep evidence artifacts in `.cclaw/artifacts/`\n- Enforce RED before GREEN in TDD\n- Run two-layer review (spec_compliance and code_quality) before ship\n- Validate all inputs before processing \u2014 never trust external data without sanitization\n- Prefer immutable data patterns and pure functions where the language supports them\n- Follow existing repo conventions, patterns, and directory structure \u2014 match the codebase\n- Verify claims with fresh evidence: \"tests pass\" requires running tests in this message\n- Use conventional commits: `type(scope): description` (feat, fix, refactor, test, docs, chore)\n\n## MUST_NEVER\n- Skip RED phase and jump directly to GREEN in TDD\n- Ship with critical review findings\n- Start implementation during /brainstorm\n- Modify generated cclaw files manually when CLI can regenerate them\n- Commit `.cclaw/` or generated shim files\n- Expose secrets, tokens, API keys, or absolute system paths in agent output\n- Duplicate existing functionality without explicit justification \u2014 search before building\n- Bypass security checks, linting hooks, or type checking to \"move faster\"\n- Claim success (\"Done,\" \"All good,\" \"Tests pass\") without running verification in this message\n- Make changes outside the blast radius of the current task without user consent\n\n## DELEGATION\nWhen a task requires specialist knowledge (security audit, performance profiling, database review),\ndelegate to a specialized agent or skill if the harness supports it. The primary agent should:\n1. Identify the specialist domain\n2. Provide focused context (relevant files, the specific concern)\n3. Evaluate the specialist output before acting on it \u2014 do not blindly apply recommendations\n";
3
- export declare const CURSOR_WORKFLOW_RULE_MDC = "---\ndescription: cclaw workflow guardrails for Cursor agent sessions\nglobs:\n - \"**/*\"\nalwaysApply: true\n---\n\n<!-- cclaw-managed-cursor-workflow-rule -->\n\n# Cclaw Workflow Guardrails\n\n## Activation Rule\n\nBefore responding to coding work:\n1. Read `.cclaw/state/flow-state.json`.\n2. Start with `/cc` or continue with `/cc`.\n3. If no software-stage flow applies, respond normally.\n\n## Stage Order\n\n`brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship`\n\nTrack-specific skips are allowed only when `flow-state.track` + `skippedStages` explicitly say so.\n\n## Task Classification\n\n| Class | Route |\n|---|---|\n| non-trivial software work | `/cc <idea>` |\n| trivial software fix | `/cc <idea>` (quick track) |\n| bugfix with repro | `/cc <idea>` and enforce RED-first in tdd |\n| pure question / non-software | direct answer (no stage flow) |\n\n## Command Surface\n\n- `/cc` = entry and resume.\n- `/cc` = only progression path.\n- Knowledge capture and recall use the `learnings` skill when requested.\n\n## Verification Discipline\n\n- No completion claim without fresh command evidence in this turn.\n- Do not mark gates passed from memory.\n- Keep evidence in `.cclaw/artifacts/`; archive through closeout via `/cc` or cancel early via `node .cclaw/hooks/cancel-run.mjs`.\n\n## Delegation And Approvals\n\n- Machine-only checks in design/plan/tdd/review/ship should auto-dispatch when tooling supports it.\n- Ask for user input only at explicit approval gates (scope mode, plan approval, challenge resolution, ship finalization).\n- If harness capabilities are partial, record waiver reasons in delegation logs.\n\n## Routing Source Of Truth\n\n- Primary router: `.cclaw/skills/using-cclaw/SKILL.md`.\n- Stage behavior: current stage skill plus `.cclaw/state/flow-state.json`.\n- Preamble budget: keep role/status announcements brief and avoid repeating\n them unless the stage or role changes.\n";
3
+ /**
4
+ * Always-on baseline rule materialized at `.cursor/rules/cclaw-guidelines.mdc`.
5
+ * Independent of skill activation — kicks in even when the agent skips
6
+ * loading skills. Three hard rules cover the most common Wave 22 regressions
7
+ * (premature draft, premature subagent dispatch, command-line echo to chat).
8
+ */
9
+ export declare const CURSOR_GUIDELINES_RULE_MDC = "---\ndescription: cclaw zero-install behavior baseline (always-on)\nglobs:\n - \"**/*\"\nalwaysApply: true\n---\n\n<!-- cclaw-managed-cursor-guidelines-rule -->\n\n# Cclaw Baseline Guidelines\n\nThese three rules apply to every Cursor agent session in this project,\nregardless of whether stage skills loaded.\n\n## 1. Q&A floor before drafting (brainstorm/scope/design)\n\nBefore drafting any `.cclaw/artifacts/01-brainstorm-*.md`,\n`02-scope-*.md`, or `03-design-*.md`, verify that the artifact's\n`## Q&A Log` table demonstrates Ralph-Loop convergence: forcing-question\ntopics are addressed (see the stage's forcing-questions checklist row),\nthe last 2 turns produce no new decision-changing impact, OR an explicit\nuser stop-signal row is recorded. Walk the stage forcing questions one at\na time via the `AskQuestion` tool. If you find yourself proposing a\ndraft after 1-2 questions while forcing topics remain unaddressed, STOP\nand continue the loop.\n\nThe `qa_log_unconverged` linter rule will block `stage-complete` when\nconvergence has not been reached.\n\n## 2. Mandatory subagents run after Q&A approval\n\nFor brainstorm / scope / design, mandatory subagents (\n`product-discovery`, `critic`, `planner`, `architect`,\n`test-author`) run **only AFTER the user approves the elicitation\noutcome**, never before the Q&A loop converges. Dispatching them early\npreempts the user dialogue and violates the elicitation contract \u2014 the\nlinter will block stage-complete.\n\nSee each stage's \"Run Phase: post-elicitation\" rows in the materialized\nAutomatic Subagent Dispatch table.\n\n## 3. Never echo cclaw command lines to chat\n\nThe user does not run cclaw helpers (`node .cclaw/hooks/...`) manually.\nNEVER paste full command lines, `--evidence-json '{...}'` payloads,\n`--waive-delegation=...`, or shell hash commands (`shasum`,\n`sha256sum`, `Get-FileHash`, `certutil`, etc.) into chat. Run the\nhelper via the tool layer and report only the resulting summary. On\nfailure, report a compact human-readable summary plus the helper JSON in\na single fenced `json` block.\n";
10
+ export declare const CURSOR_WORKFLOW_RULE_MDC = "---\ndescription: cclaw workflow guardrails for Cursor agent sessions\nglobs:\n - \"**/*\"\nalwaysApply: true\n---\n\n<!-- cclaw-managed-cursor-workflow-rule -->\n\n# Cclaw Workflow Guardrails\n\n## Activation Rule\n\nBefore responding to coding work:\n1. Read `.cclaw/state/flow-state.json`.\n2. Start with `/cc` or continue with `/cc`.\n3. If no software-stage flow applies, respond normally.\n\n## Stage Order\n\n`brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship`\n\nTrack-specific skips are allowed only when `flow-state.track` + `skippedStages` explicitly say so.\n\n## Task Classification\n\n| Class | Route |\n|---|---|\n| non-trivial software work | `/cc <idea>` |\n| trivial software fix | `/cc <idea>` (quick track) |\n| bugfix with repro | `/cc <idea>` and enforce RED-first in tdd |\n| pure question / non-software | direct answer (no stage flow) |\n\n## Command Surface\n\n- `/cc` = entry and resume.\n- `/cc` = only progression path.\n- Knowledge capture and recall use the `learnings` skill when requested.\n\n## Verification Discipline\n\n- No completion claim without fresh command evidence in this turn.\n- Do not mark gates passed from memory.\n- Keep evidence in `.cclaw/artifacts/`; archive through closeout via `/cc` or cancel early via `node .cclaw/hooks/cancel-run.mjs`.\n\n## Delegation And Approvals\n\n- Machine-only checks in design/plan/tdd/review/ship should auto-dispatch when tooling supports it.\n- **For brainstorm / scope / design stages**: ask user input continuously via adaptive elicitation (one question per turn through the harness-native question tool \u2014 `AskQuestion` in Cursor). Walk the stage forcing-questions list one-by-one. Do NOT batch and do NOT defer to a single approval gate at the end. The `qa_log_unconverged` linter rule will block `stage-complete` when convergence is not reached (forcing topics unaddressed AND last 2 turns still produce decision-changing rows AND no stop-signal).\n- **For other stages** (spec/plan/tdd/build/review/ship): ask user input only at explicit approval gates (scope mode, plan approval, challenge resolution, ship finalization), not for routine progress updates.\n- If you find yourself proposing a draft after 1-2 questions in brainstorm/scope/design, STOP \u2014 go back to the forcing-questions list and continue.\n- Mandatory subagents in brainstorm/scope/design run only AFTER the user approves the elicitation outcome (see each stage's \"Run Phase: post-elicitation\" rows). Dispatching them before the Q&A loop converges violates the contract.\n- Never echo cclaw command lines (`node .cclaw/hooks/...`, `--evidence-json '{...}'`) to chat \u2014 the user does not run cclaw manually. Run helpers via the tool layer; report only the resulting summary.\n- If harness capabilities are partial, record waiver reasons in delegation logs.\n\n## Routing Source Of Truth\n\n- Primary router: `.cclaw/skills/using-cclaw/SKILL.md`.\n- Stage behavior: current stage skill plus `.cclaw/state/flow-state.json`.\n- Preamble budget: keep role/status announcements brief and avoid repeating\n them unless the stage or role changes.\n";
4
11
  export declare function buildRulesJson(): Record<string, unknown>;
@@ -38,6 +38,13 @@ export const ARTIFACT_TEMPLATES = {
38
38
  |---|---|---|---|
39
39
  | | | | |
40
40
 
41
+ ## Idea Evidence Carry-forward
42
+ > Required only when this brainstorm started from \`/cc-ideate\` (\`flow-state.interactionHints.brainstorm.fromIdeaArtifact\` is set). Skip the section entirely otherwise.
43
+ - Source: \`<.cclaw/ideas/idea-YYYY-MM-DD-slug.md>\`
44
+ - Candidate: \`I-#\`
45
+ - Reused fields: Title, Why-now, Expected impact, Risk, Counter-argument
46
+ - Newly generated: challenger row(s) only — the idea candidate becomes the \`baseline\` row of \`## Approaches\` and the seed of \`## Selected Direction\`; do NOT regenerate divergent + critique + rank work that \`/cc-ideate\` already produced.
47
+
41
48
  ## Problem Decision Record
42
49
  - **Depth:** lite | standard | deep
43
50
  - **Frame type:** \`<free-form-label>\` (one short token that names how this work is framed; pick whatever fits — examples in commentary only: \`product\`, \`technical-maintenance\`, \`research-spike\`, \`ops-incident\`, \`infrastructure\`, \`library-extraction\`. Do NOT treat the examples as an enum.)
@@ -219,23 +226,14 @@ ${MARKDOWN_CODE_FENCE}
219
226
  - Every error has a name:
220
227
  - Four paths per data flow:
221
228
 
222
- ## Premise Challenge
223
- | Question | Answer (take a position) | Evidence / leverage |
224
- |---|---|---|
225
- | Right problem? | | |
226
- | Direct path? | | |
227
- | What if we do nothing? | | |
228
- | Existing-code leverage? | | |
229
- | Reversibility cost? | | |
230
-
231
- ## Implementation Alternatives
232
- | Option | Summary | Effort (S/M/L/XL) | Risk (Low/Med/High) | Pros | Cons | Reuses |
233
- |---|---|---|---|---|---|---|
234
- | A (minimum viable) | | | | | | |
235
- | B (ideal architecture) | | | | | | |
236
- | C (optional) | | | | | | |
229
+ ## Premise Drift
230
+ > Optional. Brainstorm OWNS the premise check. Record \`None\` unless scope-stage Q&A surfaced new evidence (constraint, user signal, regulatory change) that materially changes brainstorm's \`## Premise Check\` answer.
237
231
 
238
- RECOMMENDATION: <option letter one-line rationale tying back to premise challenge and existing-code leverage>
232
+ | Brainstorm question | New evidence (scope-stage) | Drift verdict (no-change / shift / reverse) | Action |
233
+ |---|---|---|---|
234
+ | (cite brainstorm Q) | | | |
235
+
236
+ - Default: \`Drift: None — brainstorm Premise Check stands.\`
239
237
 
240
238
  ## Scope Contract
241
239
  - **Selected mode:** HOLD SCOPE | SELECTIVE EXPANSION | SCOPE EXPANSION | SCOPE REDUCTION
@@ -247,8 +245,9 @@ RECOMMENDATION: <option letter — one-line rationale tying back to premise chal
247
245
  - **Deferred ideas:**
248
246
  - **Accepted reference ideas:**
249
247
  - **Rejected reference ideas:**
248
+ - **Constraints (external/regulatory/system/integration):** (spec carries these forward — do NOT restate as assumptions)
250
249
  - **Success definition:**
251
- - **Design handoff:**
250
+ - **Design handoff:** (name what design must decide: architecture-tier, framework, data-model, etc. — design OWNS the architecture choice)
252
251
 
253
252
  ## Decision Drivers
254
253
  | Driver | Weight (1-5) | Option A | Option B | Option C | Notes |
@@ -307,14 +306,18 @@ RECOMMENDATION: <option letter — one-line rationale tying back to premise chal
307
306
  > is later dropped, keep the row and mark Priority \`DROPPED\`; if a new one is
308
307
  > added mid-flow, append with the next free R-number — do NOT reuse numbers.
309
308
 
310
- ## Locked Decisions (LD#hash)
311
- | Decision Anchor | Decision | Why locked now | Downstream impact |
309
+ ## Locked Decisions
310
+ | ID | Decision | Why locked now | Downstream impact |
312
311
  |---|---|---|---|
313
- | LD#<sha8> | | | |
312
+ | D-1 | | | |
314
313
 
315
- > Decision Anchor is \`LD#\` + the first 8 lowercase hex chars of SHA-256 over
316
- > the normalized \`Decision\` cell (trim, collapse whitespace, lowercase). Downstream
317
- > design/spec/plan/review artifacts reference these anchors verbatim.
314
+ > Decision IDs are stable \`D-XX\` numbers. Assign once and never renumber across
315
+ > scope/design/spec/plan/review/ship; downstream artifacts reference these IDs
316
+ > verbatim. If a decision is later dropped, keep the row and mark it
317
+ > \`(superseded by D-Y)\`; if a new one is added mid-flow, append with the next
318
+ > free D-number. Wave 22 (v4.0.0) removed the legacy LD#<sha8> hash anchor —
319
+ > existing artifacts with LD# anchors remain valid markdown but the linter only
320
+ > tracks D-XX IDs.
318
321
 
319
322
  ## In Scope / Out of Scope
320
323
 
@@ -478,7 +481,7 @@ ${MARKDOWN_CODE_FENCE}
478
481
  > Default path: compact inline synthesis here. Deep/high-risk work may also write \`.cclaw/artifacts/02a-research.md\`.
479
482
 
480
483
  ## Architecture Boundaries
481
- | Component | Responsibility | Requirement Refs (R#) | Decision Refs (LD#hash) | Owner |
484
+ | Component | Responsibility | Requirement Refs (R#) | Decision Refs (D-XX) | Owner |
482
485
  |---|---|---|---|---|
483
486
  | | | | | |
484
487
 
@@ -524,8 +527,12 @@ ${MARKDOWN_CODE_FENCE}
524
527
  |---|---|---|---|---|
525
528
  | | | | clear/stale | |
526
529
 
527
- ## What Already Exists
528
- | Sub-problem | Existing code/library | Layer | Reuse decision |
530
+ ## Blast-radius Diff
531
+ > Diff since scope artifact baseline. Scope OWNS the full repo audit (\`## Pre-Scope System Audit\`); design only diffs touched paths.
532
+ >
533
+ > Suggested command: \`git diff <scope-artifact-head-sha>..HEAD -- <touched-paths>\`
534
+
535
+ | File | Change since scope (\`git diff\` summary) | Current responsibility | Reuse candidate / existing pattern |
529
536
  |---|---|---|---|
530
537
  | | | | |
531
538
 
@@ -540,11 +547,11 @@ ${MARKDOWN_CODE_FENCE}
540
547
  ### Interaction Edge Case Matrix
541
548
  | Edge case | Handled? | Design response | Deferred item (if not handled) |
542
549
  |---|---|---|---|
543
- | double-click | yes/no | | None / LD#hash |
544
- | nav-away-mid-request | yes/no | | None / LD#hash |
545
- | 10K-result dataset | yes/no | | None / LD#hash |
546
- | background-job abandonment | yes/no | | None / LD#hash |
547
- | zombie connection | yes/no | | None / LD#hash |
550
+ | double-click | yes/no | | None / D-XX |
551
+ | nav-away-mid-request | yes/no | | None / D-XX |
552
+ | 10K-result dataset | yes/no | | None / D-XX |
553
+ | background-job abandonment | yes/no | | None / D-XX |
554
+ | zombie connection | yes/no | | None / D-XX |
548
555
 
549
556
  ## Security & Threat Model
550
557
  | Boundary | Threat | Mitigation | Owner |
@@ -620,9 +627,6 @@ ${MARKDOWN_CODE_FENCE}
620
627
  - Max iterations: 3
621
628
  - Unresolved concerns:
622
629
 
623
- ## NOT in scope
624
- -
625
-
626
630
  ## Parallelization Strategy
627
631
  - Standard/Deep add-on when multi-module; omit for compact sequential work.
628
632
  - Parallel lanes:
@@ -699,7 +703,7 @@ ${MARKDOWN_CODE_FENCE}
699
703
  - Drift from upstream (or \`None\`):
700
704
 
701
705
  ## Acceptance Criteria
702
- | ID | Requirement Ref (R#) | Criterion (observable/measurable/falsifiable) | Design Decision Ref (LD#hash) |
706
+ | ID | Requirement Ref (R#) | Criterion (observable/measurable/falsifiable) | Design Decision Ref (D-XX) |
703
707
  |---|---|---|---|
704
708
  | AC-1 | R1 | | |
705
709
 
@@ -718,8 +722,10 @@ ${MARKDOWN_CODE_FENCE}
718
722
  | AC-1 | | |
719
723
 
720
724
  ## Constraints and Assumptions
721
- - Constraints:
722
- - Assumptions:
725
+ > Constraints are CARRIED FORWARD from scope's \`## Scope Contract > Constraints\`. Cite or copy with attribution; do NOT re-author. Spec OWNS testable assumptions in \`## Assumptions Before Finalization\` below.
726
+
727
+ - **Constraints (carry-forward):** See scope: \`02-scope-<slug>.md#scope-contract\` (or list new spec-stage constraints with citation to the Q&A row that surfaced them).
728
+ - **Assumptions:** See \`## Assumptions Before Finalization\` (spec-only owner).
723
729
 
724
730
  ## Assumptions Before Finalization
725
731
  | Assumption | Source / confidence | Validation path | Disposition |
@@ -845,9 +851,9 @@ Execution rule: complete and verify each batch before starting the next batch.
845
851
  - TDD checkpoint plan: RED commit/checkpoint -> GREEN commit/checkpoint -> REFACTOR commit/checkpoint (or deferred because: )
846
852
 
847
853
  ## Locked Decision Coverage
848
- | Decision Ref (LD#hash) | Source section | Plan tasks implementing decision | Status |
854
+ | Decision Ref (D-XX) | Source section | Plan tasks implementing decision | Status |
849
855
  |---|---|---|---|
850
- | LD#<sha8> | 02-scope.md > Locked Decisions | T-1 | covered |
856
+ | D-1 | 02-scope.md > Locked Decisions | T-1 | covered |
851
857
 
852
858
  ## Risk Assessment
853
859
  | Task/Batch | Risk | Likelihood | Impact | Mitigation |
@@ -870,7 +876,7 @@ Execution rule: complete and verify each batch before starting the next batch.
870
876
  - Create:
871
877
  - Modify:
872
878
  - Test:
873
- - **Approach:** (1-3 sentences; cite design decision DD-# or LD#hash)
879
+ - **Approach:** (1-3 sentences; cite design decision DD-# or scope D-XX)
874
880
  - **Patterns to follow:** (link existing files/modules to mirror, or \`- None applicable.\`)
875
881
  - **Test scenarios:**
876
882
  - Happy:
@@ -908,7 +914,7 @@ Execution rule: complete and verify each batch before starting the next batch.
908
914
  - Hits: 0 (required for WAIT_FOR_CONFIRM to resolve).
909
915
  - Scope reduction language scan:
910
916
  - Scanned phrases: \`v1\`, \`for now\`, \`later\`, \`temporary\`, \`placeholder\`, \`mock for now\`, \`hardcoded for now\`, \`will improve later\`.
911
- - Hits: 0 (required when Locked Decisions section is non-empty; use LD#hash anchors).
917
+ - Hits: 0 (required when Locked Decisions section is non-empty; reference D-XX IDs from scope).
912
918
 
913
919
  ## WAIT_FOR_CONFIRM
914
920
  - Status: pending
@@ -1180,9 +1186,14 @@ Execution rule: complete and verify each batch before starting the next batch.
1180
1186
  | AC-1 | PASS/FAIL | |
1181
1187
 
1182
1188
  ## Layer 2 Findings
1189
+ > Wave 23 (v5.0.0): Layer 2 categories OWNED by review = cross-slice correctness, security, dependency/version, observability, external-safety. Performance + architecture findings are CARRY-FORWARD from \`03-design-<slug>.md\` (Performance Budget, ADR) — cite, do NOT re-derive. Single-slice findings stay in \`06-tdd.md > Per-Slice Review\`; review may cite their IDs (severity/disposition must match — cross-artifact-duplication linter blocks otherwise).
1190
+
1183
1191
  | ID | Severity | Category | File:line / no-line reason | Description | Status |
1184
1192
  |---|---|---|---|---|---|
1185
- | R-1 | Critical/Important/Suggestion | correctness/security/performance/architecture/external-safety | path:line | | open/resolved |
1193
+ | R-1 | Critical/Important/Suggestion | cross-slice-correctness/security/dependency-version/observability/external-safety | path:line | | open/resolved |
1194
+ | R-2 | from-design | performance | cite \`03-design-<slug>.md > Performance Budget\` | | carry-forward |
1195
+ | R-3 | from-design | architecture | cite \`03-design-<slug>.md > ADR\` | | carry-forward |
1196
+ | R-4 | from-tdd | from-tdd | cite \`06-tdd.md > Per-Slice Review > F-<n>\` | | carry-forward |
1186
1197
  - NO_FINDINGS_ATTESTATION: <required when no findings are reported; cite inspected coverage>
1187
1198
 
1188
1199
  ## Lens Coverage
@@ -1449,6 +1460,63 @@ delegate to a specialized agent or skill if the harness supports it. The primary
1449
1460
  2. Provide focused context (relevant files, the specific concern)
1450
1461
  3. Evaluate the specialist output before acting on it — do not blindly apply recommendations
1451
1462
  `;
1463
+ /**
1464
+ * Always-on baseline rule materialized at `.cursor/rules/cclaw-guidelines.mdc`.
1465
+ * Independent of skill activation — kicks in even when the agent skips
1466
+ * loading skills. Three hard rules cover the most common Wave 22 regressions
1467
+ * (premature draft, premature subagent dispatch, command-line echo to chat).
1468
+ */
1469
+ export const CURSOR_GUIDELINES_RULE_MDC = `---
1470
+ description: cclaw zero-install behavior baseline (always-on)
1471
+ globs:
1472
+ - "**/*"
1473
+ alwaysApply: true
1474
+ ---
1475
+
1476
+ <!-- cclaw-managed-cursor-guidelines-rule -->
1477
+
1478
+ # Cclaw Baseline Guidelines
1479
+
1480
+ These three rules apply to every Cursor agent session in this project,
1481
+ regardless of whether stage skills loaded.
1482
+
1483
+ ## 1. Q&A floor before drafting (brainstorm/scope/design)
1484
+
1485
+ Before drafting any \`.cclaw/artifacts/01-brainstorm-*.md\`,
1486
+ \`02-scope-*.md\`, or \`03-design-*.md\`, verify that the artifact's
1487
+ \`## Q&A Log\` table demonstrates Ralph-Loop convergence: forcing-question
1488
+ topics are addressed (see the stage's forcing-questions checklist row),
1489
+ the last 2 turns produce no new decision-changing impact, OR an explicit
1490
+ user stop-signal row is recorded. Walk the stage forcing questions one at
1491
+ a time via the \`AskQuestion\` tool. If you find yourself proposing a
1492
+ draft after 1-2 questions while forcing topics remain unaddressed, STOP
1493
+ and continue the loop.
1494
+
1495
+ The \`qa_log_unconverged\` linter rule will block \`stage-complete\` when
1496
+ convergence has not been reached.
1497
+
1498
+ ## 2. Mandatory subagents run after Q&A approval
1499
+
1500
+ For brainstorm / scope / design, mandatory subagents (
1501
+ \`product-discovery\`, \`critic\`, \`planner\`, \`architect\`,
1502
+ \`test-author\`) run **only AFTER the user approves the elicitation
1503
+ outcome**, never before the Q&A loop converges. Dispatching them early
1504
+ preempts the user dialogue and violates the elicitation contract — the
1505
+ linter will block stage-complete.
1506
+
1507
+ See each stage's "Run Phase: post-elicitation" rows in the materialized
1508
+ Automatic Subagent Dispatch table.
1509
+
1510
+ ## 3. Never echo cclaw command lines to chat
1511
+
1512
+ The user does not run cclaw helpers (\`node .cclaw/hooks/...\`) manually.
1513
+ NEVER paste full command lines, \`--evidence-json '{...}'\` payloads,
1514
+ \`--waive-delegation=...\`, or shell hash commands (\`shasum\`,
1515
+ \`sha256sum\`, \`Get-FileHash\`, \`certutil\`, etc.) into chat. Run the
1516
+ helper via the tool layer and report only the resulting summary. On
1517
+ failure, report a compact human-readable summary plus the helper JSON in
1518
+ a single fenced \`json\` block.
1519
+ `;
1452
1520
  export const CURSOR_WORKFLOW_RULE_MDC = `---
1453
1521
  description: cclaw workflow guardrails for Cursor agent sessions
1454
1522
  globs:
@@ -1497,7 +1565,11 @@ Track-specific skips are allowed only when \`flow-state.track\` + \`skippedStage
1497
1565
  ## Delegation And Approvals
1498
1566
 
1499
1567
  - Machine-only checks in design/plan/tdd/review/ship should auto-dispatch when tooling supports it.
1500
- - Ask for user input only at explicit approval gates (scope mode, plan approval, challenge resolution, ship finalization).
1568
+ - **For brainstorm / scope / design stages**: ask user input continuously via adaptive elicitation (one question per turn through the harness-native question tool — \`AskQuestion\` in Cursor). Walk the stage forcing-questions list one-by-one. Do NOT batch and do NOT defer to a single approval gate at the end. The \`qa_log_unconverged\` linter rule will block \`stage-complete\` when convergence is not reached (forcing topics unaddressed AND last 2 turns still produce decision-changing rows AND no stop-signal).
1569
+ - **For other stages** (spec/plan/tdd/build/review/ship): ask user input only at explicit approval gates (scope mode, plan approval, challenge resolution, ship finalization), not for routine progress updates.
1570
+ - If you find yourself proposing a draft after 1-2 questions in brainstorm/scope/design, STOP — go back to the forcing-questions list and continue.
1571
+ - Mandatory subagents in brainstorm/scope/design run only AFTER the user approves the elicitation outcome (see each stage's "Run Phase: post-elicitation" rows). Dispatching them before the Q&A loop converges violates the contract.
1572
+ - Never echo cclaw command lines (\`node .cclaw/hooks/...\`, \`--evidence-json '{...}'\`) to chat — the user does not run cclaw manually. Run helpers via the tool layer; report only the resulting summary.
1501
1573
  - If harness capabilities are partial, record waiver reasons in delegation logs.
1502
1574
 
1503
1575
  ## Routing Source Of Truth