cclaw-cli 0.5.4 → 0.5.5

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.
@@ -2,10 +2,6 @@ import { RUNTIME_ROOT } from "../constants.js";
2
2
  import { stageExamples } from "./examples.js";
3
3
  import { selfImprovementBlock } from "./learnings.js";
4
4
  import { QUESTION_FORMAT_SPEC, ERROR_BUDGET_SPEC, stageAutoSubagentDispatch, stageSchema } from "./stage-schema.js";
5
- function artifactFileName(artifactPath) {
6
- const parts = artifactPath.split("/");
7
- return parts[parts.length - 1] ?? artifactPath;
8
- }
9
5
  function rationalizationTable(stage) {
10
6
  const schema = stageSchema(stage);
11
7
  return `| Rationalization | Reality |
@@ -75,20 +71,17 @@ function contextLoadingBlock(stage) {
75
71
  const trace = stageSchema(stage).crossStageTrace;
76
72
  const readLines = trace.readsFrom.length > 0
77
73
  ? trace.readsFrom
78
- .map((value) => {
79
- const fileName = artifactFileName(value);
80
- return `- Canonical: \`.cclaw/runs/<activeRunId>/artifacts/${fileName}\` (fallback: \`${value}\`)`;
81
- })
74
+ .map((value) => `- \`${value}\``)
82
75
  .join("\n")
83
76
  : "- (first stage — no upstream artifacts)";
84
77
  return `## Context Loading
85
78
 
86
79
  Before starting stage execution:
87
- 1. Read \`.cclaw/state/flow-state.json\` and capture \`activeRunId\`.
88
- 2. Resolve canonical run artifact root: \`.cclaw/runs/<activeRunId>/artifacts/\`.
80
+ 1. Read \`.cclaw/state/flow-state.json\`.
81
+ 2. Resolve active artifact root: \`.cclaw/artifacts/\`.
89
82
  3. Load upstream artifacts required by this stage:
90
83
  ${readLines}
91
- 4. If canonical run artifact is missing, fallback to the \`.cclaw/artifacts/\` mirror and record that fallback.
84
+ 4. Read \`.cclaw/knowledge.md\` and apply relevant entries before making decisions.
92
85
  `;
93
86
  }
94
87
  function whenNotToUseBlock(stage) {
@@ -113,7 +106,7 @@ function autoSubagentDispatchBlock(stage) {
113
106
  .join("\n");
114
107
  const mandatory = stageSchema(stage).mandatoryDelegations;
115
108
  const mandatoryList = mandatory.length > 0 ? mandatory.map((a) => `\`${a}\``).join(", ") : "(none — only proactive dispatch applies)";
116
- const delegationLogRel = `${RUNTIME_ROOT}/runs/<activeRunId>/delegation-log.json`;
109
+ const delegationLogRel = `${RUNTIME_ROOT}/state/delegation-log.json`;
117
110
  return `## Automatic Subagent Dispatch
118
111
 
119
112
  Machine-only work should be delegated to specialist agents automatically according to the matrix below.
@@ -174,7 +167,7 @@ When all required gates are satisfied and the artifact is written:
174
167
  1. **Update \`${RUNTIME_ROOT}/state/flow-state.json\`:**
175
168
  ${stateUpdate}
176
169
  - For each passed gate, add an entry to \`guardEvidence\`: \`"<gate_id>": "<artifact path or excerpt proving the gate>"\`. Do NOT leave \`guardEvidence\` empty.
177
- 2. **Persist artifact** at \`${RUNTIME_ROOT}/artifacts/${schema.artifactFile}\`. Do NOT manually copy into run directories; cclaw sync/runtime keeps \`${RUNTIME_ROOT}/runs/<activeRunId>/artifacts/\` aligned.
170
+ 2. **Persist artifact** at \`${RUNTIME_ROOT}/artifacts/${schema.artifactFile}\`. Do NOT manually copy into \`${RUNTIME_ROOT}/runs/\`; archival is handled by \`cclaw archive\`.
178
171
  ${nextAction}
179
172
 
180
173
  **STOP.** Do not load the next stage skill yourself. The user will run \`/cc-next\` when ready (same session or new session).
@@ -231,7 +224,7 @@ function progressiveDisclosureBlock(stage) {
231
224
  - Primary stage procedure (this file): \`.cclaw/skills/${schema.skillFolder}/SKILL.md\`
232
225
  - Orchestrator contract (gate language and handoff): \`.cclaw/commands/${stage}.md\`
233
226
  - Artifact structure baseline: \`.cclaw/templates/${schema.artifactFile}\`
234
- - Runtime state truth source: \`.cclaw/state/flow-state.json\` + \`.cclaw/runs/<activeRunId>/\`
227
+ - Runtime state truth source: \`.cclaw/state/flow-state.json\` + \`.cclaw/artifacts/\` + \`.cclaw/knowledge.md\`
235
228
 
236
229
  ### See also
237
230
  - Meta routing and activation rules: \`.cclaw/skills/using-cclaw/SKILL.md\`
@@ -287,7 +280,7 @@ function quickStartBlock(stage) {
287
280
 
288
281
  > **Even if you read nothing else, do these 3 things:**
289
282
  > 1. Obey the HARD-GATE below — violating it invalidates the entire stage.
290
- > 2. Complete every checklist step in order and write the artifact to \`.cclaw/artifacts/${schema.artifactFile}\`. Run snapshots in \`.cclaw/runs/<activeRunId>/artifacts/\` are synchronized by cclaw runtime.
283
+ > 2. Complete every checklist step in order and write the artifact to \`.cclaw/artifacts/${schema.artifactFile}\`.
291
284
  > 3. Do not claim completion without satisfying gates: ${topGates}${schema.requiredGates.length > 3 ? ` (+${schema.requiredGates.length - 3} more)` : ""}.
292
285
  >
293
286
  > **After this stage:** update \`flow-state.json\` and tell the user to run \`/cc-next\`.
@@ -385,7 +378,7 @@ ${progressiveDisclosureBlock(stage)}
385
378
  ${selfImprovementBlock(stage)}
386
379
  ## Handoff
387
380
  - Next command: \`/cc-next\` (loads whatever stage is current in flow-state)
388
- - Required artifact: \`.cclaw/artifacts/${schema.artifactFile}\` (run snapshot at \`.cclaw/runs/<activeRunId>/artifacts/${schema.artifactFile}\`, synchronized by cclaw runtime)
381
+ - Required artifact: \`.cclaw/artifacts/${schema.artifactFile}\`
389
382
  - Stage stays blocked if any required gate is unsatisfied
390
383
  `;
391
384
  }
@@ -22,185 +22,144 @@ const BRAINSTORM = {
22
22
  stage: "brainstorm",
23
23
  skillFolder: "brainstorming",
24
24
  skillName: "brainstorming",
25
- skillDescription: "Design-first stage. Clarify intent, compare options, and get explicit approval before implementation planning.",
26
- hardGate: "Do NOT invoke any implementation skill, write any code, scaffold any project, or take any implementation action until you have presented a design and the user has approved it. This applies to EVERY project regardless of perceived simplicity.",
27
- purpose: "Turn a rough request into an approved design direction with clear assumptions and boundaries.",
25
+ skillDescription: "Design-first stage. Route request complexity, run phased forcing questions, and lock an approved direction before scope/design work.",
26
+ hardGate: "Do NOT invoke implementation skills, write code, scaffold projects, or mutate product behavior until a concrete direction is approved by the user.",
27
+ purpose: "Turn an initial idea into an approved direction through routing, phased grounding, and decision-forcing questions.",
28
28
  whenToUse: [
29
29
  "Starting a new feature or behavior change",
30
- "Requirements are ambiguous or solution path is unclear",
31
- "Before any implementation-stage command"
30
+ "Requirements are ambiguous or trade-offs are unclear",
31
+ "Before any implementation-stage command or architecture commitment"
32
32
  ],
33
33
  whenNotToUse: [
34
- "An approved design, spec, and plan already exist and work is in execution stages",
35
- "The request is strictly branch finalization or release handoff work",
36
- "The task is purely retrospective after ship with no new design decisions needed"
34
+ "A valid approved direction already exists and only execution remains",
35
+ "The request is a pure release/finalization action with no new product decisions",
36
+ "The task is retrospective only (post-ship audit with no new solution choices)"
37
37
  ],
38
38
  checklist: [
39
- "Explore project context check files, docs, recent commits, existing behavior. Summarize what you found (even for seemingly simple projects).",
40
- "Assess scope if the request describes multiple independent subsystems, flag for decomposition before detailed questions.",
41
- "Restate the problem in a SEPARATE message (no questions in this message), summarize what you understood the user wants and why. The restatement message must contain zero clarifying questions and no option prompts. **STOP and wait** for user to confirm or correct before asking any clarifying questions.",
42
- "Ask clarifying questions — one at a time, one per message. Each clarification message must ask exactly one decision-seeking question (no bundled sub-questions). You MUST cover these categories before proposing approaches: (a) PURPOSE — why this project exists, who it serves; (b) SCOPE — what it must do, what it must NOT do; (c) BOUNDARIES — error handling, edge cases, failure modes; (d) ENVIRONMENT — how it runs, deploys, installs; (e) CONSTRAINTS — performance, compatibility, dependencies. Skip a category only if the user already provided that info. If user answers 'I don't know' / 'не знаю', convert it into explicit assumptions and ask for confirmation before moving on. Do NOT rush — 3 generic questions are never enough for a non-trivial project.",
43
- "Before proposing approaches, perform at least one premise-challenge question (\"Is this the right problem framing?\") and at least one boundary stress-test question (\"What should never happen even on failure?\").",
44
- "Propose 2-3 approaches with real trade-offs (not cosmetic differences) and your explicit recommendation with reasoning. Explain WHY you recommend this option over others.",
45
- "Present design in sections. After each section, explicitly state what you are asking the user to approve: 'Do you approve [specific thing]?' Never ask a bare 'одобряете?/approve?' without context.",
46
- "Write design doc — save to `.cclaw/artifacts/01-brainstorm.md`.",
47
- "Self-review scan for placeholders, TBDs, contradictions, ambiguity, scope creep. Fix inline.",
48
- "User reviews written artifact — ask user to review the written artifact (not the chat summary). **STOP.** Do NOT proceed until user responds.",
49
- "Stage complete — update `flow-state.json` per the Stage Completion Protocol. Tell user to run `/cc-next` to continue to scope."
39
+ "Principles (one line): one decision-forcing question at a time, grounding summary between rounds, and no implementation before approval.",
40
+ "Route the work: classify as Simple Route (single-surface, low-risk) or Complex Route (multi-surface, high-uncertainty); explain why.",
41
+ "Round 1 grounding: restate the problem, desired outcome, and success signal in your own words; get confirmation before deeper questioning.",
42
+ "Round 2 forcing questions: ask one decision-forcing question per turn about boundaries and constraints; each answer must change a concrete design decision.",
43
+ "Grounding checkpoint: summarize what is fixed vs still unknown after Round 2; confirm this summary before moving to solution options.",
44
+ "Round 3 forcing questions: ask trade-off questions that force prioritization (for example speed vs flexibility), then lock assumptions.",
45
+ "Propose multiple viable approaches with real trade-offs and one explicit recommendation tied to the forced decisions.",
46
+ "Write `.cclaw/artifacts/01-brainstorm.md` with route, grounding checkpoints, forcing-question log, options, and approved direction; run a contradiction pass.",
47
+ "Ask the user to review the written artifact and explicitly approve or request changes; only then complete stage and point to `/cc-next`."
50
48
  ],
51
49
  interactionProtocol: [
52
- "Explore context first (files, docs, existing behavior). Share a brief summary of what you found.",
53
- "Restate the problem in your own words in a SEPARATE message. Do NOT add any questions, options, or approval asks to this message. Wait for user to confirm or correct.",
54
- "Ask clarifying questions one per message. Cover mandatory categories: PURPOSE, SCOPE, BOUNDARIES, ENVIRONMENT, CONSTRAINTS. Do NOT combine questions. Do NOT propose approaches until all categories are addressed.",
55
- "Do not package multiple asks as bullet points in one message; split them into separate turns even if related.",
56
- "When user answer is ambiguous or unknown (for example: 'не знаю'), propose explicit defaults as assumptions and get a one-message confirmation before treating that category as closed.",
57
- "Include at least one premise-challenge and one boundary stress-test question before locking options. Do not accept 'simple demo' framing without challenge.",
58
- "For approach selection: use the Decision Protocol — present labeled options (A/B/C) with REAL trade-offs (not cosmetic) and mark one as (recommended) with clear reasoning. If AskQuestion/AskUserQuestion is available, send exactly ONE question per call, validate fields against runtime schema, and on schema error immediately fall back to plain-text question instead of retrying guessed payloads.",
59
- "Every approval question MUST state what exactly is being approved: 'Do you approve [the architecture / the API shape / the dependency choice]?' Never ask a bare 'approve?' or 'looks good?'.",
60
- "Get section-by-section approval before finalizing the design direction.",
61
- "Run a self-review pass (ambiguity, placeholders, contradictions) before handoff.",
62
- "**STOP.** Wait for explicit user approval after writing the artifact. Do NOT auto-advance to the next stage."
50
+ "Start with routing (Simple Route vs Complex Route) so question depth matches real complexity.",
51
+ "Use phased questioning: Round 1 grounding -> Round 2 constraints/boundaries -> grounding checkpoint -> Round 3 trade-off forcing.",
52
+ "Ask exactly one decision-forcing question per turn; avoid bundled or purely informational questions.",
53
+ "After each round, publish a short grounding summary (fixed decisions vs unknowns) before continuing.",
54
+ "Use the Decision Protocol for option selection, with explicit recommendation and rationale.",
55
+ "State explicitly what is being approved when requesting approval.",
56
+ "Run a brief contradiction and ambiguity pass before handoff.",
57
+ "**STOP.** Wait for explicit user approval after writing the artifact. Do NOT auto-advance."
63
58
  ],
64
59
  process: [
65
- "Explore project context files, docs, behavior, recent changes. Share findings.",
66
- "Restate the problem summarize what the user wants and why in a SEPARATE message. Keep this message declarative only; no questions. Wait for confirmation before questions.",
67
- "Clarify iteratively ask questions one at a time covering mandatory categories: PURPOSE, SCOPE, BOUNDARIES, ENVIRONMENT, CONSTRAINTS. Do not skip to approaches early.",
68
- "Convert unknown answers into explicit assumptions and confirm them before approaches.",
69
- "Identify whether request should be decomposed into smaller sub-problems.",
70
- "Offer 2-3 alternatives with real trade-offs and recommendation with rationale.",
71
- "Present design in sections. After each section explicitly name what you ask the user to approve.",
72
- "Write artifact to `.cclaw/artifacts/01-brainstorm.md`.",
73
- "Run self-review: placeholder scan, internal consistency, scope check, ambiguity check.",
74
- "Ask user to review the written artifact. Wait for changes or approval.",
75
- "Handoff to scope stage only after approval is explicit."
60
+ "Route request complexity (Simple Route or Complex Route) and capture rationale.",
61
+ "Round 1 grounding: restate problem, outcome, and success signal; confirm alignment.",
62
+ "Round 2 forcing questions: boundaries and constraints one question at a time.",
63
+ "Grounding checkpoint: summarize fixed decisions and remaining unknowns.",
64
+ "Round 3 forcing questions: trade-offs and priorities; lock explicit assumptions.",
65
+ "Offer multiple approaches with recommendation and rationale.",
66
+ "Capture approved direction in `.cclaw/artifacts/01-brainstorm.md`.",
67
+ "Run contradiction/ambiguity pass and request explicit user approval.",
68
+ "Handoff to scope only after approval is explicit."
76
69
  ],
77
70
  requiredGates: [
78
- { id: "brainstorm_discovery_purpose", description: "Discovery captured WHY this project exists and WHO it serves, with explicit user confirmation." },
79
- { id: "brainstorm_discovery_scope", description: "Discovery captured explicit in-scope and out-of-scope boundaries before approach selection." },
80
- { id: "brainstorm_discovery_boundaries", description: "Discovery captured failure modes, edge cases, and error-handling boundaries." },
81
- { id: "brainstorm_discovery_environment", description: "Discovery captured runtime/install/deployment environment assumptions." },
82
- { id: "brainstorm_discovery_constraints", description: "Discovery captured constraints (performance, compatibility, dependency limits) before deciding architecture." },
83
- {
84
- id: "brainstorm_problem_restated",
85
- description: "Problem was restated in agent's words in a standalone non-question message, and user confirmed the understanding."
86
- },
87
- { id: "brainstorm_options_compared", description: "At least two alternatives were compared with real trade-offs." },
88
- { id: "brainstorm_design_approved", description: "User approved a concrete design direction (with explicit statement of what was approved)." },
89
- { id: "brainstorm_self_review_passed", description: "Design doc passed placeholder/ambiguity/consistency checks." },
90
- { id: "brainstorm_user_reviewed_artifact", description: "User reviewed the written artifact and confirmed readiness." }
71
+ { id: "brainstorm_route_selected", description: "Simple vs Complex route was selected with explicit rationale." },
72
+ { id: "brainstorm_round1_grounded", description: "Round 1 grounding (problem, outcome, success signal) was confirmed by the user." },
73
+ { id: "brainstorm_round2_forcing_questions", description: "Round 2 forcing questions captured boundaries and constraints that changed real decisions." },
74
+ { id: "brainstorm_round3_tradeoff_decisions", description: "Round 3 forcing questions locked explicit trade-off priorities and assumptions." },
75
+ { id: "brainstorm_options_compared", description: "Multiple solution approaches were compared with real trade-offs and a recommendation." },
76
+ { id: "brainstorm_direction_approved", description: "User approved a concrete direction and what exactly was approved is stated." },
77
+ { id: "brainstorm_artifact_reviewed", description: "User reviewed the written brainstorm artifact and confirmed readiness." }
91
78
  ],
92
79
  requiredEvidence: [
93
80
  "Artifact written to `.cclaw/artifacts/01-brainstorm.md`.",
94
- "Clarification log explicitly records PURPOSE, SCOPE, BOUNDARIES, ENVIRONMENT, and CONSTRAINTS coverage.",
95
- "Clarification sequence evidence shows one explicit question per message (no bundled multi-question turns).",
96
- "Clarification log includes at least one premise-challenge question and one boundary stress-test question before approach selection.",
97
- "Unknown or ambiguous user answers are converted into explicit assumptions and confirmed (or explicitly waived) before closure.",
98
- "Discovery sections include explicit in-scope/out-of-scope boundaries and failure handling boundaries.",
99
- "Approved direction captured in artifact.",
100
- "Restatement evidence shows a standalone non-question restatement message before clarification Q&A.",
101
- "Open questions explicitly listed (if any).",
102
- "Self-review pass completed with no unresolved issues."
81
+ "Routing decision (`simple` or `complex`) with rationale is recorded.",
82
+ "Grounding checkpoints between rounds are recorded (fixed decisions vs unknowns).",
83
+ "Forcing-question log captures question, answer, and decision impact.",
84
+ "Approaches and recommendation are recorded with explicit trade-offs.",
85
+ "Approved direction and approval marker are present.",
86
+ "Assumptions and open questions are captured (or explicitly marked as none)."
103
87
  ],
104
88
  inputs: ["problem statement", "constraints", "success criteria"],
105
89
  requiredContext: [
106
- "existing project docs and patterns",
90
+ "existing project context and patterns",
107
91
  "current behavior of affected area",
108
92
  "business and delivery constraints"
109
93
  ],
110
94
  outputs: [
111
95
  "approved design direction",
112
- "alternatives and trade-off table",
96
+ "alternatives with trade-offs",
113
97
  "brainstorm artifact"
114
98
  ],
115
99
  blockers: [
116
100
  "no explicit approval",
117
101
  "critical ambiguity unresolved",
118
- "scope too broad and not decomposed"
102
+ "route cannot be determined due to missing context"
119
103
  ],
120
104
  exitCriteria: [
121
105
  "approved design direction documented",
122
106
  "required gates marked satisfied",
123
107
  "no implementation action taken",
124
- "self-review completed with fixes applied"
108
+ "artifact reviewed by user"
125
109
  ],
126
110
  antiPatterns: [
127
- "Skipping design because task seems simple",
128
- "Asking many questions in one message",
111
+ "Skipping route selection and treating all requests with the same question depth",
112
+ "Asking non-forcing or bundled questions",
113
+ "Skipping grounding checkpoints between rounds",
129
114
  "Jumping directly into implementation",
130
- "Combining visual companion offer with a clarifying question",
131
- "Invoking implementation skills before writing plans",
132
- "Appending clarifying questions to the restatement message instead of waiting for confirmation",
133
- "Packing multiple clarifying questions into one message (including bullet-list question bundles)",
134
- "Silently filling defaults after 'не знаю'/'I don't know' without explicit assumption confirmation",
135
- "Accepting 'simple/test/demo' framing without premise challenge or failure stress testing",
136
- "Asking bare 'approve?' or 'одобряете?' without stating WHAT is being approved",
137
- "Presenting a single summary and asking for blanket approval instead of section-by-section review",
138
- "Rushing through clarification — asking 1-2 generic questions then jumping to design",
139
- "Batching multiple gate confirmations in one message when resuming a session"
115
+ "Requesting approval without stating what decision is being approved"
140
116
  ],
141
117
  rationalizations: [
142
- { claim: "This is too simple for design.", reality: "Simple tasks fail fast when assumptions are wrong; a short design pass prevents rework." },
143
- { claim: "We can figure it out while coding.", reality: "Coding before alignment creates churn and hidden scope growth." },
144
- { claim: "There is only one obvious approach.", reality: "Without alternatives, trade-offs stay implicit and risk goes unexamined." },
145
- { claim: "The user already knows what they want.", reality: "Unstated assumptions diverge during implementation; explicit design surfaces them early." },
146
- { claim: "This is straightforward, 1-2 questions are enough.", reality: "Even simple projects have hidden constraints (error handling, edge cases, deployment). A few extra questions now prevent rework later." }
118
+ { claim: "This is straightforward so routing is unnecessary.", reality: "Explicit routing prevents under-questioning complex work and over-questioning simple work." },
119
+ { claim: "Any question is useful context.", reality: "Only forcing questions that change decisions improve design quality." },
120
+ { claim: "Grounding summaries slow us down.", reality: "Grounding checkpoints prevent hidden drift and reduce expensive rework later." }
147
121
  ],
148
122
  redFlags: [
149
- "No alternatives documented",
150
- "No explicit approval checkpoint",
151
- "Implementation-related actions before approval",
152
- "Self-review skipped or glossed over",
153
- "Artifact has TBD or placeholder sections",
154
- "Restatement step includes clarifying questions or option prompts",
155
- "Clarification turns repeatedly include multi-question bundles instead of single asks",
156
- "Unknown user answers are treated as settled requirements without explicit assumption confirmation",
157
- "No evidence of premise challenge or failure stress-test questions before options",
158
- "Fewer than 3 clarifying questions asked for any non-trivial project",
159
- "Approval requested without stating what exactly is being approved"
123
+ "Route is missing or unjustified",
124
+ "No grounding checkpoint between question rounds",
125
+ "Questions do not force concrete decisions",
126
+ "Approval requested without explicit decision context"
160
127
  ],
161
128
  policyNeedles: [
162
- "Restate problem before questions",
163
- "One clarifying question per message",
164
- "2-3 approaches with real trade-offs",
129
+ "Simple Route / Complex Route",
130
+ "One forcing question per message",
131
+ "Grounding checkpoint between rounds",
132
+ "Multiple approaches with trade-offs",
165
133
  "State what is being approved",
166
134
  "Do NOT implement, scaffold, or modify behavior"
167
135
  ],
168
136
  artifactFile: "01-brainstorm.md",
169
137
  next: "scope",
170
138
  cognitivePatterns: [
171
- { name: "Divergent-Convergent Thinking", description: "First expand the solution space widely, then converge on the strongest option. Do not skip the divergent phase." },
172
- { name: "YAGNI Ruthlessness", description: "Remove unnecessary features from all designs. Every feature must earn its place against the cost of complexity." },
173
- { name: "Decomposition Instinct", description: "When a request describes multiple independent subsystems, decompose before refining. Each sub-project gets its own cycle." },
174
- { name: "Isolation Preference", description: "Break the system into units that each have one clear purpose, communicate through well-defined interfaces, and can be understood and tested independently." }
139
+ { name: "Route Before Depth", description: "Choose question depth using simple-vs-complex routing before diving into details." },
140
+ { name: "Forcing Question Discipline", description: "Each question must force a concrete decision, not just gather trivia." },
141
+ { name: "Grounding Cadence", description: "After each question round, re-ground on fixed decisions vs unknowns before continuing." },
142
+ { name: "Diverge Then Commit", description: "Explore multiple viable options first, then commit only after explicit approval." }
175
143
  ],
176
144
  reviewSections: [],
177
145
  completionStatus: ["DONE", "DONE_WITH_CONCERNS", "BLOCKED"],
178
146
  crossStageTrace: {
179
147
  readsFrom: [],
180
148
  writesTo: [".cclaw/artifacts/01-brainstorm.md"],
181
- traceabilityRule: "Every approved direction must be traceable forward through scope and design. Downstream stages must reference brainstorm decisions."
149
+ traceabilityRule: "Scope and design decisions must trace back to routed question rounds and approved brainstorm direction."
182
150
  },
183
151
  artifactValidation: [
184
- { section: "Problem Statement", required: true, validationRule: "Must describe the user problem, not the solution. Include WHO and WHY and success signal." },
185
- { section: "Known Context", required: true, validationRule: "Files, patterns, constraints discovered during exploration. Evidence that context was actually explored." },
186
- {
187
- section: "Clarification Log",
188
- required: true,
189
- validationRule: "At least 5 rows covering PURPOSE, SCOPE, BOUNDARIES, ENVIRONMENT, CONSTRAINTS. Table must use 4 columns: Category, Question asked, User answer, Evidence note."
190
- },
191
- { section: "Purpose & Beneficiaries", required: true, validationRule: "At least 3 meaningful lines describing why this exists and who benefits." },
192
- { section: "Scope Boundaries", required: true, validationRule: "At least 2 scope items including explicit out-of-scope boundaries." },
193
- { section: "Failure Boundaries", required: true, validationRule: "At least 2 failure/edge-case expectations and error visibility behavior." },
194
- { section: "Runtime Environment", required: true, validationRule: "At least 2 lines describing runtime, install/distribution, and execution environment." },
195
- { section: "Constraints", required: true, validationRule: "At least 2 concrete constraints (performance, compatibility, dependency, or policy)." },
196
- { section: "Alternatives Table", required: true, validationRule: "At least 2 approaches with real trade-offs (not cosmetic) and recommendation with reasoning." },
197
- { section: "Approved Direction", required: true, validationRule: "Must contain explicit approval marker from user. State what was approved." },
198
- { section: "Assumptions & Risks", required: true, validationRule: "Explicit assumptions made during design. Known risks. If none, state 'None'." },
199
- { section: "Open Questions", required: true, validationRule: "If empty, state 'None' explicitly. Do not omit." }
152
+ { section: "Problem Framing", required: true, validationRule: "Must define the user problem, desired outcome, and success signal." },
153
+ { section: "Routing Decision", required: true, validationRule: "Must state simple vs complex route and explain why." },
154
+ { section: "Grounding Checkpoints", required: true, validationRule: "Must capture fixed decisions and remaining unknowns between rounds." },
155
+ { section: "Forcing Questions Log", required: true, validationRule: "Must capture question, answer, and decision impact for each forcing question." },
156
+ { section: "Options Comparison", required: true, validationRule: "Must compare multiple distinct options with real trade-offs and recommendation." },
157
+ { section: "Approved Direction", required: true, validationRule: "Must include explicit approval marker and what was approved." },
158
+ { section: "Assumptions and Open Questions", required: true, validationRule: "Must capture unresolved assumptions/open questions, or explicitly state none." }
200
159
  ],
201
160
  namedAntiPattern: {
202
- title: "This Is Too Simple To Need A Design",
203
- description: "Every project goes through this process. A todo list, a single-function utility, a config change all of them. 'Simple' projects are where unexamined assumptions cause the most wasted work. The design can be short (a few sentences for truly simple projects), but you MUST present it and get approval."
161
+ title: "This Is Too Simple To Brainstorm",
162
+ description: "Skipping routing and forcing questions because a task looks simple creates silent assumption debt. Even simple-route work needs explicit grounding and approval."
204
163
  }
205
164
  };
206
165
  // ---------------------------------------------------------------------------
@@ -1,4 +1,4 @@
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- Follow stage order: brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship.\n- Read `.cclaw/state/flow-state.json` before acting; continue from current stage when active.\n- Use `/cc-next` only after required gates pass; never bypass explicit pause/approval rules.\n- Keep evidence in `.cclaw/artifacts/`; cclaw sync/runtime maintains run snapshots in `.cclaw/runs/<activeRunId>/artifacts/`.\n- For machine-only checks in design/plan/tdd/review/ship, dispatch required specialists automatically when tooling supports it.\n- Ask for user input only at explicit approval gates (scope mode, plan approval, user challenge resolution, ship finalization).\n- Treat `.cclaw/skills/using-cclaw/SKILL.md` as routing source of truth; load contextual utility skills only when their triggers apply.\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- Follow stage order: brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship.\n- Read `.cclaw/state/flow-state.json` before acting; continue from current stage when active.\n- Use `/cc-next` only after required gates pass; never bypass explicit pause/approval rules.\n- Keep evidence in `.cclaw/artifacts/`; archive completed feature artifacts only via `cclaw archive`.\n- For machine-only checks in design/plan/tdd/review/ship, dispatch required specialists automatically when tooling supports it.\n- Ask for user input only at explicit approval gates (scope mode, plan approval, user challenge resolution, ship finalization).\n- Treat `.cclaw/skills/using-cclaw/SKILL.md` as routing source of truth; load contextual utility skills only when their triggers apply.\n";
4
4
  export declare function buildRulesJson(): Record<string, unknown>;
@@ -3,71 +3,50 @@ import { orderedStageSchemas } from "./stage-schema.js";
3
3
  export const ARTIFACT_TEMPLATES = {
4
4
  "01-brainstorm.md": `# Brainstorm Artifact
5
5
 
6
- ## Problem Statement
6
+ ## Problem Framing
7
7
  - **User problem:**
8
- - **Who benefits:**
9
- - **Why now:**
8
+ - **Desired outcome:**
10
9
  - **Success signal:**
11
10
 
12
- ## Known Context
13
- - **Explored files/patterns:**
14
- - **Existing behavior:**
15
- - **Relevant dependencies:**
11
+ ## Routing Decision
12
+ - **Route:** simple | complex
13
+ - **Reasoning:**
16
14
 
17
- ## Clarification Log
18
- | Category | Question asked | User answer | Evidence note |
19
- |---|---|---|---|
20
- | PURPOSE | | | |
21
- | SCOPE | | | |
22
- | BOUNDARIES | | | |
23
- | ENVIRONMENT | | | |
24
- | CONSTRAINTS | | | |
25
-
26
- ## Purpose & Beneficiaries
27
- - **Project purpose:**
28
- - **Primary users:**
29
- - **Value outcome:**
30
-
31
- ## Scope Boundaries
32
- ### In Scope
33
- -
15
+ ## Grounding Checkpoints
16
+ ### Round 1 grounding
17
+ - **What is fixed now:**
18
+ - **What is still unknown:**
34
19
 
35
- ### Out of Scope
36
- -
20
+ ### Round 2 grounding
21
+ - **What is fixed now:**
22
+ - **What is still unknown:**
37
23
 
38
- ## Failure Boundaries
39
- - **Edge cases to handle:**
40
- - **Expected failures and behavior:**
41
- - **Error visibility expectations:**
24
+ ### Round 3 grounding
25
+ - **What is fixed now:**
26
+ - **What is still unknown:**
42
27
 
43
- ## Runtime Environment
44
- - **Runtime/platform:**
45
- - **Install/distribution model:**
46
- - **Execution context (local/CI/deploy):**
47
-
48
- ## Constraints
49
- - **Performance constraints:**
50
- - **Compatibility constraints:**
51
- - **Dependency constraints:**
28
+ ## Forcing Questions Log
29
+ | Round | Question | User answer | Decision impact |
30
+ |---|---|---|---|
31
+ | 2 | | | |
32
+ | 2 | | | |
33
+ | 3 | | | |
52
34
 
53
- ## Alternatives Table
35
+ ## Options Comparison
54
36
  | Option | Summary | Trade-offs | Recommendation |
55
37
  |---|---|---|---|
56
38
  | A | | | |
57
39
  | B | | | |
58
- | C | | | |
59
40
 
60
41
  ## Approved Direction
61
42
  - **Selected option:**
62
43
  - **Why selected:**
63
- - **What was approved:** (state the specific decision)
44
+ - **What was approved:**
64
45
  - **Approval marker:**
65
46
 
66
- ## Assumptions & Risks
67
- -
68
-
69
- ## Open Questions
70
- - None
47
+ ## Assumptions and Open Questions
48
+ - **Assumptions:**
49
+ - **Open questions (or "None"):**
71
50
  `,
72
51
  "02-scope.md": `# Scope Artifact
73
52
 
@@ -382,7 +361,7 @@ alwaysApply: true
382
361
  - Follow stage order: brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship.
383
362
  - Read \`.cclaw/state/flow-state.json\` before acting; continue from current stage when active.
384
363
  - Use \`/cc-next\` only after required gates pass; never bypass explicit pause/approval rules.
385
- - Keep evidence in \`.cclaw/artifacts/\`; cclaw sync/runtime maintains run snapshots in \`.cclaw/runs/<activeRunId>/artifacts/\`.
364
+ - Keep evidence in \`.cclaw/artifacts/\`; archive completed feature artifacts only via \`cclaw archive\`.
386
365
  - For machine-only checks in design/plan/tdd/review/ship, dispatch required specialists automatically when tooling supports it.
387
366
  - Ask for user input only at explicit approval gates (scope mode, plan approval, user challenge resolution, ship finalization).
388
367
  - Treat \`.cclaw/skills/using-cclaw/SKILL.md\` as routing source of truth; load contextual utility skills only when their triggers apply.
@@ -4,11 +4,11 @@ import { RUNTIME_ROOT } from "./constants.js";
4
4
  import { exists, withDirectoryLock, writeFileSafe } from "./fs-utils.js";
5
5
  import { readFlowState } from "./runs.js";
6
6
  import { stageSchema } from "./content/stage-schema.js";
7
- function delegationLogPath(projectRoot, runId) {
8
- return path.join(projectRoot, RUNTIME_ROOT, "runs", runId, "delegation-log.json");
7
+ function delegationLogPath(projectRoot) {
8
+ return path.join(projectRoot, RUNTIME_ROOT, "state", "delegation-log.json");
9
9
  }
10
- function delegationLockPath(projectRoot, runId) {
11
- return path.join(projectRoot, RUNTIME_ROOT, "runs", runId, ".delegation.lock");
10
+ function delegationLockPath(projectRoot) {
11
+ return path.join(projectRoot, RUNTIME_ROOT, "state", ".delegation.lock");
12
12
  }
13
13
  function isDelegationEntry(value) {
14
14
  if (!value || typeof value !== "object" || Array.isArray(value))
@@ -45,7 +45,7 @@ function parseLedger(raw, runId) {
45
45
  }
46
46
  export async function readDelegationLedger(projectRoot) {
47
47
  const { activeRunId } = await readFlowState(projectRoot);
48
- const filePath = delegationLogPath(projectRoot, activeRunId);
48
+ const filePath = delegationLogPath(projectRoot);
49
49
  if (!(await exists(filePath))) {
50
50
  return { runId: activeRunId, entries: [] };
51
51
  }
@@ -60,8 +60,8 @@ export async function readDelegationLedger(projectRoot) {
60
60
  }
61
61
  export async function appendDelegation(projectRoot, entry) {
62
62
  const { activeRunId } = await readFlowState(projectRoot);
63
- await withDirectoryLock(delegationLockPath(projectRoot, activeRunId), async () => {
64
- const filePath = delegationLogPath(projectRoot, activeRunId);
63
+ await withDirectoryLock(delegationLockPath(projectRoot), async () => {
64
+ const filePath = delegationLogPath(projectRoot);
65
65
  const prior = await readDelegationLedger(projectRoot);
66
66
  const ledger = {
67
67
  runId: activeRunId,