cclaw-cli 0.5.6 → 0.5.8

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.
@@ -49,8 +49,46 @@ Carry the no-new-dependency constraint and hard-block behavior directly into sco
49
49
  scope: `### Scope contract
50
50
 
51
51
  **Mode selected:** SELECTIVE EXPANSION
52
+ **Default heuristic used:** feature enhancement -> selective
53
+ **Mode-specific analysis result:** hold-scope baseline accepted first; one expansion accepted (degraded-state UX), one deferred (real-time channel upgrade).
52
54
 
53
- **Premise challenge result:** The original premise (“add notifications”) was reframed to **“ensure users know when an action requires follow-up”**, which expands the solution space beyond toast spam to include durable inbox items, empty states, and recovery paths when delivery fails.
55
+ ### Prime Directives (applied)
56
+
57
+ - Zero silent failures: every delivery failure maps to a visible degraded state.
58
+ - Named error surfaces: stream disconnect, auth drift, and publisher timeout are explicit.
59
+ - Four-path data flow mapped: happy, nil payload, empty payload, upstream publish error.
60
+ - Interaction edge cases in scope: double-open panel, reconnect after sleep, stale tab state.
61
+ - Observability in scope: stream error counter, publish-to-visible lag metric, and alert threshold.
62
+
63
+ ### Premise challenge result
64
+
65
+ The original premise (“add notifications”) was reframed to **“ensure users know when an action requires follow-up”**, which expands the solution space beyond toast spam to include durable inbox items, empty states, and recovery paths when delivery fails.
66
+
67
+ ### Dream State Mapping
68
+
69
+ | Stage | Statement |
70
+ | --- | --- |
71
+ | **CURRENT STATE** | Users miss time-sensitive follow-ups because alerts are ephemeral and not recoverable. |
72
+ | **THIS PLAN** | Introduce durable in-app feed + live updates + explicit degraded mode fallback. |
73
+ | **12-MONTH IDEAL** | Unified notification center with reliable multi-channel fan-out and user-level routing preferences. |
74
+ | **Alignment verdict** | Aligned: this scope builds the durability foundation without prematurely committing to channel expansion. |
75
+
76
+ ### Implementation Alternatives
77
+
78
+ | Option | Summary | Effort (S/M/L/XL) | Risk | Pros | Cons | Reuses |
79
+ | --- | --- | --- | --- | --- | --- | --- |
80
+ | **A (minimum viable)** | Polling-only feed with no live stream | S | Low | Fastest ship, low infra risk | Weaker UX, delayed visibility | Existing REST snapshot endpoint |
81
+ | **B (recommended)** | SSE live updates + REST fallback snapshot | M | Med | Better timeliness, graceful degradation | Requires reconnect handling | Existing event publisher + REST path |
82
+ | **C (ideal architecture)** | Event bus + WebSocket channel + feed projection | XL | High | Strong long-term scalability | Overbuilt for current demand | Partial reuse of publisher only |
83
+
84
+ ### Temporal Interrogation
85
+
86
+ | Time slice | Likely decision pressure | Lock now or defer? | Reason |
87
+ | --- | --- | --- | --- |
88
+ | **HOUR 1 (foundations)** | Canonical event schema and dedupe key policy | **Lock now** | Prevent downstream rework in storage and UI merge behavior |
89
+ | **HOUR 2-3 (core logic)** | Retry/backoff semantics for stream loss | **Lock now** | Impacts both backend signaling and client state machine |
90
+ | **HOUR 4-5 (integration)** | Handling gaps between snapshot and stream cursor | **Lock now** | Prevent silent data loss during reconnect windows |
91
+ | **HOUR 6+ (polish/tests)** | Banner copy tone and polling cadence tuning | **Defer** | Safe to iterate after baseline reliability is proven |
54
92
 
55
93
  ### In scope / out of scope / deferred
56
94
 
@@ -60,23 +98,40 @@ Carry the no-new-dependency constraint and hard-block behavior directly into sco
60
98
  | **Out of scope** | Email/SMS/push providers; marketing campaigns; per-user notification preferences beyond on/off |
61
99
  | **Deferred** | WebSocket channel; rich media attachments in notifications; full-text search across historical events |
62
100
 
101
+ ### Discretion Areas
102
+
103
+ - Client-side badge rendering strategy (optimistic vs server-confirmed) is implementation discretion.
104
+ - Polling fallback backoff curve is implementation discretion if degraded-state UX remains explicit.
105
+
63
106
  ### Error & Rescue Registry (sample entry)
64
107
 
65
108
  | Capability | Failure mode | Detection | Fallback |
66
109
  | --- | --- | --- | --- |
67
110
  | Event delivery | SSE connection drops mid-session | Client \`EventSource\` error event + heartbeat timeout | Fall back to REST polling every 30s until SSE reconnect succeeds; show subtle “live updates paused” banner |
68
111
 
69
- ### Non-goals (guardrails)
112
+ ### Completion Dashboard
113
+
114
+ - Checklist findings: 9/9 complete (complex path)
115
+ - Resolved decisions count: 7
116
+ - Unresolved decisions: None
70
117
 
71
- - No “infinite history” guarantee in v1; retention policy can be time-bounded.
72
- - No cross-tenant fan-out optimizations until multi-tenant load tests exist.
118
+ ### Scope Summary
73
119
 
74
- ### Owners & checkpoints
120
+ - Accepted scope: durable feed + SSE + explicit degraded UX.
121
+ - Deferred: WebSocket channel and rich-media/search enhancements.
122
+ - Explicitly excluded: outbound channels and marketing workflows for v1.`,
123
+ design: `### Codebase Investigation (blast-radius files)
124
+
125
+ | File | Current responsibility | Patterns discovered |
126
+ | --- | --- | --- |
127
+ | \`src/api/routes/user.ts\` | User CRUD endpoints | Express router, Zod validation, throws \`AppError\` |
128
+ | \`src/services/event-bus.ts\` | In-process pub/sub | EventEmitter wrapper, typed channels, no persistence |
129
+ | \`src/middleware/auth.ts\` | JWT verification | Extracts user from token, attaches to \`req.context\` |
130
+ | \`tests/integration/user.test.ts\` | User route tests | Supertest, factory helpers, \`beforeEach\` DB reset |
75
131
 
76
- - **Product:** confirms reframed premise and acceptance of deferred items.
77
- - **Engineering:** confirms SSE + REST snapshot split is feasible behind current gateway.
78
- - **Checkpoint:** scope sign-off happens before detailed component design changes land in the repo.`,
79
- design: `### Search Before Building (sample result)
132
+ Discovery: existing EventEmitter-based bus has no durability notifications must add persistence layer on top, not replace the bus.
133
+
134
+ ### Search Before Building (sample result)
80
135
 
81
136
  | Layer | Label | What to reuse first |
82
137
  | --- | --- | --- |
@@ -84,7 +139,7 @@ Carry the no-new-dependency constraint and hard-block behavior directly into sco
84
139
  | Layer 2 | existing codebase | Existing auth middleware, existing API client wrapper, existing feature flags helper |
85
140
  | Layer 3 | npm | A small, well-maintained SSE helper (only if Layer 1–2 cannot cover framing/reconnect ergonomics) |
86
141
 
87
- ### Minimal component diagram (ASCII)
142
+ ### Architecture Diagram (mandatory)
88
143
 
89
144
  \`\`\`
90
145
  ┌─────────────┐ ┌──────────────┐ ┌────────────────┐
@@ -98,18 +153,54 @@ Carry the no-new-dependency constraint and hard-block behavior directly into sco
98
153
  └──────────────┘
99
154
  \`\`\`
100
155
 
101
- ### Unresolved Decision (sample entry)
156
+ Data flow: Gateway → Service (validate + enrich) → Publisher (fan-out) → Queue (persist) → Read Model (project).
157
+
158
+ ### What Already Exists
159
+
160
+ | Sub-problem | Existing code/library | Layer | Reuse decision |
161
+ | --- | --- | --- | --- |
162
+ | Auth context extraction | \`src/middleware/auth.ts\` | Layer 1 | Reuse as-is |
163
+ | Event fan-out | \`src/services/event-bus.ts\` | Layer 2 | Wrap with persistence adapter |
164
+ | SSE framing | None | Layer 3 | Evaluate \`better-sse\` npm package |
165
+ | Notification schema | None | — | New: define in \`src/schemas/notification.ts\` |
166
+
167
+ ### Failure Mode Table
168
+
169
+ | Failure | Trigger | Detection | Mitigation | User impact |
170
+ | --- | --- | --- | --- | --- |
171
+ | SSE connection drop | Network interruption | Client heartbeat timeout (30s) | Auto-reconnect with exponential backoff + snapshot fallback | Brief delay (≤10s), no data loss |
172
+ | Duplicate publish | Retry after timeout | Dedupe key check in outbox | Upsert with idempotency key | None (transparent) |
173
+ | Queue backpressure | Spike >1000 events/s | Queue depth metric alarm | Back-pressure signal to publisher, shed non-critical events | Delayed delivery of low-priority notifications |
174
+
175
+ ### NOT in scope
102
176
 
103
- - **Decision:** Should the feed be modeled as append-only events or as CRUD “notification rows”?
104
- - **Status:** OPEN
105
- - **Options:** (A) append-only event log + projection, (B) mutable rows with status fields, (C) hybrid with compaction job
106
- - **Deadline:** Decide before implementation of persistence migrations (end of week)
177
+ - Outbound channels (email, push, SMS) deferred to v2.
178
+ - Admin notification management UI — separate workstream.
179
+ - Notification preferences / mute rules requires user settings redesign.
180
+
181
+ ### Unresolved Decisions
182
+
183
+ | Decision | Status | Options | Missing info | Default if unanswered |
184
+ | --- | --- | --- | --- | --- |
185
+ | Feed storage model | OPEN | (A) append-only event log, (B) mutable rows, (C) hybrid | Load testing results on read patterns | (A) append-only — safest for audit trail |
107
186
 
108
187
  ### Interface sketch (non-binding)
109
188
 
110
189
  - **Client → server:** \`GET /api/me/notifications/snapshot?limit=50\` plus optional cursor parameters (if adopted).
111
190
  - **Server → client:** \`GET /api/me/notifications/stream\` as SSE with periodic heartbeats.
112
191
 
192
+ ### Completion Dashboard
193
+
194
+ | Review Section | Status | Issues |
195
+ | --- | --- | --- |
196
+ | Architecture Review | issues-found-resolved | Decided on outbox pattern over direct pub/sub |
197
+ | Code Quality Review | clear | — |
198
+ | Test Review | issues-found-resolved | Added integration test gap for SSE reconnect |
199
+ | Performance Review | clear | — |
200
+ | Distribution & Delivery Review | clear | — |
201
+
202
+ **Decisions made:** 4 | **Unresolved:** 1 (feed storage model)
203
+
113
204
  ### Quality bar for this stage
114
205
 
115
206
  Design output should be **reviewable by someone who did not attend brainstorming**: they can trace from constraints → components → open decisions without reading code.`,
@@ -24,7 +24,7 @@ function reviewSectionsBlock(stage) {
24
24
  const sections = schema.reviewSections.map((sec) => {
25
25
  const points = sec.evaluationPoints.map((p) => `- ${p}`).join("\n");
26
26
  const stop = sec.stopGate
27
- ? "\n\n**STOP.** For each issue found in this section, present it ONE AT A TIME. Describe the problem concretely, present 2-3 options, state your recommendation, and explain WHY. Only proceed to the next section after ALL issues in this section are resolved."
27
+ ? "\n\n**STOP.** Present the most important question from this section to the user, even if your recommendation is clear. If no issues are found, state your assessment in one sentence and ask the user to confirm before moving on. If issues exist, present them ONE AT A TIME: describe the problem concretely, present 2-3 options, state your recommendation, and explain WHY."
28
28
  : "";
29
29
  return `### ${sec.title}\n\nEvaluate:\n${points}${stop}`;
30
30
  }).join("\n\n");
@@ -48,8 +48,10 @@ const BRAINSTORM = {
48
48
  ],
49
49
  interactionProtocol: [
50
50
  "Explore what exists before asking what to build — check project files first.",
51
+ "If the idea is vague or could mean many different things, your FIRST question narrows to a specific kind of project. Do not ask detail questions until the project type is clear.",
51
52
  "Ask exactly one question per turn. Prefer multiple choice. No bundled questions.",
52
- "Each question should change a concrete design decision. If a question only gathers trivia, skip it.",
53
+ "After 2-3 questions, summarize your emerging understanding before continuing so the user can correct course early.",
54
+ "Each question should change a concrete design decision. Litmus test: if the two most likely answers do not lead to different architectures, make the choice yourself and state it.",
53
55
  "Present design in sections scaled to their complexity — a few sentences for simple aspects, detailed for nuanced ones. Get approval after each section.",
54
56
  "When proposing approaches, lead with your recommendation and explain why.",
55
57
  "State explicitly what is being approved when requesting approval.",
@@ -136,7 +138,8 @@ const BRAINSTORM = {
136
138
  { name: "Context Before Questions", description: "Understand what exists before asking what to build." },
137
139
  { name: "Depth Matches Complexity", description: "Brief design for simple tasks, thorough exploration for complex ones." },
138
140
  { name: "Diverge Then Commit", description: "Explore multiple architecturally distinct options first, commit only after explicit approval." },
139
- { name: "Question Quality Over Quantity", description: "Each question should change what we build, not just gather trivia." }
141
+ { name: "Question Quality Over Quantity", description: "Each question should change what we build, not just gather trivia." },
142
+ { name: "Know When To Move On", description: "Stop asking when problem, constraints, and success criteria are clear enough to compare approaches." }
140
143
  ],
141
144
  reviewSections: [],
142
145
  completionStatus: ["DONE", "DONE_WITH_CONCERNS", "BLOCKED"],
@@ -180,18 +183,23 @@ const SCOPE = {
180
183
  "The work is a pure implementation or debugging pass within existing scope"
181
184
  ],
182
185
  checklist: [
183
- "Prime DirectivesZero silent failures (every failure mode visible). Every error has a name (not 'handle errors' name the exception). Every data flow has four paths: happy, nil input, upstream error, downstream timeout. Observability is a scope deliverable, not a post-launch add-on.",
184
- "Premise ChallengeIs this the right problem? Could a different framing yield a simpler or more impactful solution? What happens if we do nothing? What are we optimizing for speed, quality, cost, user experience?",
185
- "Existing Code Leverage Map every sub-problem to existing code. Run searches (grep, codebase exploration) BEFORE deciding to build new. If built-in or library solutions exist, default to them.",
186
- "Dream State MappingDescribe the ideal end state 12 months from now. Does this plan move toward that state or away from it?",
187
- "Implementation Alternatives (MANDATORY) Produce 2-3 distinct approaches. One must be 'minimal viable', one must be 'ideal architecture'. Include effort/risk/reversibility for each.",
188
- "Temporal InterrogationThink in time slices: HOUR 1 (foundation, what must exist first), HOURS 2-3 (core logic, what builds on foundation), HOURS 4-5 (integration, what connects the pieces), HOUR 6+ (polish, what can wait). What decisions must be locked NOW vs deferred to implementation?",
189
- "Mode Selection with Default Heuristic Present four options: SCOPE EXPANSION (dream big), SELECTIVE EXPANSION (hold scope + cherry-pick), HOLD SCOPE (maximum rigor), SCOPE REDUCTION (strip to essentials). Suggest default: greenfield EXPANSION, bug/hotfix HOLD, >15 files touched → suggest REDUCTION. Once selected, commit fully.",
190
- "Error & Rescue Registry For every new capability in scope: what breaks if it fails? How is the failure detected? What is the fallback? This is scope, not design — decide WHAT to protect, not HOW."
186
+ "**Assess complexity**Read the brainstorm artifact. If project is simple (single component, clear architecture, personal/prototype), run light-touch scope: mode selection, 3-5 key in/out boundaries, deferred items. Skip Dream State Mapping and Temporal Interrogation. If project is complex (multi-component, team delivery, production), run the full checklist.",
187
+ "**Prime Directives**Zero silent failures. For each in-scope capability, name concrete failure modes, the exact error surface, and trace all four data-flow paths (happy, nil, empty, upstream error). Include interaction edge cases (double-click, navigate-away, stale state), observability commitments, and explicit deferred-item logging.",
188
+ "**Premise Challenge**Is this the right problem? What if we do nothing? What are we optimizing for?",
189
+ "**Existing Code Leverage**Search for existing solutions before deciding to build new.",
190
+ "**Dream State Mapping** — (complex projects only) describe the ideal state 12 months out using `CURRENT STATE -> THIS PLAN -> 12-MONTH IDEAL`, then verify this scope moves toward that target.",
191
+ "**Implementation Alternatives**Produce 2-3 distinct approaches. For each: Name, Summary, Effort (S/M/L/XL), Risk (Low/Med/High), 2-3 Pros, 2-3 Cons, and explicit Reuses. One option must be minimal viable, one must be ideal architecture.",
192
+ "**Temporal Interrogation** (complex projects only) simulate implementation timeline: HOUR 1 foundations, HOUR 2-3 core logic, HOUR 4-5 integration surprises, HOUR 6+ polish/tests. Decide what must be locked now vs safely deferred.",
193
+ "**Mode Selection** Present expand/selective/hold/reduce with recommendation and default heuristic: greenfield -> expand, feature enhancement -> selective, bugfix/hotfix/refactor -> hold, broad blast radius (>15 files or multi-team impact) -> reduce.",
194
+ "**Mode-Specific Analysis** — After mode is selected, run the matching analysis: EXPAND (10x and delight opportunities), SELECTIVE (hold-scope rigor then cherry-picked expansions), HOLD (minimum-change-set hardening), REDUCE (ruthless cuts and follow-up split).",
195
+ "**Error and Rescue Registry** — For each capability: what breaks, how detected, what fallback."
191
196
  ],
192
197
  interactionProtocol: [
193
- "For scope mode selection: use the Decision Protocol — present expand/selective/hold/reduce as labeled options with trade-offs and mark one as (recommended). 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.",
198
+ "For scope mode selection: use the Decision Protocol — present expand/selective/hold/reduce as labeled options with trade-offs and mark one as (recommended). Base your recommendation on default heuristics: greenfield -> expand, enhancement -> selective, bugfix/hotfix/refactor -> hold, broad blast radius -> reduce. 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.",
199
+ "Walk through the scope checklist interactively. Each checklist item that surfaces a decision should be presented to the user as a question, not as a monologue. Do not dump all items at once.",
194
200
  "Challenge premise and verify the problem framing before anything else.",
201
+ "Take a position on every scope decision. Avoid hedging phrases like 'this could work' or 'there are many ways'; state your recommendation and one concrete condition that would change it.",
202
+ "Use pushback patterns when framing is weak: vague scope -> force a specific user/problem, platform vision -> force a narrowest viable wedge, social proof -> demand behavioral evidence.",
195
203
  "Present one structural scope issue at a time for decision. Do NOT batch. Use structured options for each scope boundary question.",
196
204
  "Record explicit in-scope and out-of-scope contract.",
197
205
  "Once the user accepts or rejects a recommendation, commit fully. Do not re-argue.",
@@ -200,25 +208,29 @@ const SCOPE = {
200
208
  ],
201
209
  process: [
202
210
  "Run premise challenge and existing-solution leverage check.",
203
- "Produce 2-3 scope alternatives (minimum viable + ideal included).",
211
+ "Produce 2-3 scope alternatives in a structured format (Name, Summary, Effort, Risk, Pros, Cons, Reuses) with minimum viable and ideal architecture options included.",
204
212
  "Choose scope mode with user approval.",
213
+ "Run mode-specific analysis that matches the selected scope mode.",
205
214
  "Walk through scope review sections one at a time.",
206
- "Write explicit scope contract and deferred items.",
207
- "Produce scope summary with mode, in-scope, out-of-scope, and deferred."
215
+ "Write explicit scope contract, discretion areas, and deferred items.",
216
+ "Produce scope summary plus completion dashboard (checklist findings, number of resolved decisions, unresolved items or `None`)."
208
217
  ],
209
218
  requiredGates: [
210
219
  { id: "scope_premise_challenged", description: "Problem framing and assumptions were challenged." },
211
- { id: "scope_alternatives_produced", description: "At least 2 implementation alternatives with effort/risk evaluated." },
220
+ { id: "scope_alternatives_produced", description: "At least 2 implementation alternatives were evaluated with explicit effort/risk and reuse fields." },
212
221
  { id: "scope_mode_selected", description: "One scope mode was explicitly selected." },
213
222
  { id: "scope_contract_written", description: "In-scope/out-of-scope contract is documented." },
223
+ { id: "scope_discretion_documented", description: "Discretion areas are documented (or explicitly marked as none)." },
214
224
  { id: "scope_user_approved", description: "User approved the final scope direction." }
215
225
  ],
216
226
  requiredEvidence: [
217
227
  "Artifact written to `.cclaw/artifacts/02-scope.md`.",
218
228
  "In-scope and out-of-scope lists are explicit.",
229
+ "Discretion areas are explicit (or marked as `None`).",
219
230
  "Selected mode and rationale are documented.",
220
231
  "Premise challenge findings documented.",
221
- "Deferred items list with one-line rationale for each."
232
+ "Deferred items list with one-line rationale for each.",
233
+ "Completion dashboard lists checklist findings, decision count, and unresolved items (or `None`)."
222
234
  ],
223
235
  inputs: ["brainstorm artifact", "timeline constraints", "product priorities"],
224
236
  requiredContext: [
@@ -226,22 +238,27 @@ const SCOPE = {
226
238
  "existing capabilities and reusable components",
227
239
  "delivery deadlines and risk tolerance"
228
240
  ],
229
- outputs: ["scope mode decision", "scope contract", "deferred scope list", "scope summary"],
241
+ outputs: ["scope mode decision", "scope contract", "discretion areas list", "deferred scope list", "scope summary", "scope completion dashboard"],
230
242
  blockers: [
231
243
  "scope mode not selected",
232
244
  "in/out boundaries ambiguous",
245
+ "discretion areas undefined",
233
246
  "critical premise disagreement unresolved"
234
247
  ],
235
248
  exitCriteria: [
236
249
  "scope contract approved by user",
250
+ "discretion areas recorded explicitly",
237
251
  "required gates marked satisfied",
238
252
  "deferred list recorded explicitly",
253
+ "completion dashboard produced",
239
254
  "scope summary produced"
240
255
  ],
241
256
  antiPatterns: [
242
257
  "Scope silently expanded during discussion",
243
258
  "No explicit out-of-scope section",
244
259
  "Premise accepted without challenge",
260
+ "Sycophantic agreement without evidence-based pushback",
261
+ "Hedged recommendations that avoid taking a position",
245
262
  "Batching multiple scope issues into one question",
246
263
  "Re-arguing for smaller scope after user rejects reduction"
247
264
  ],
@@ -249,19 +266,23 @@ const SCOPE = {
249
266
  { claim: "Scope can be finalized during implementation.", reality: "Late scope decisions create architecture churn and missed deadlines." },
250
267
  { claim: "Mode selection is unnecessary overhead.", reality: "Mode selection makes trade-offs explicit and prevents silent drift." },
251
268
  { claim: "Out-of-scope is obvious.", reality: "Unwritten exclusions return later as hidden requirements." },
252
- { claim: "We do not need alternatives for a clear request.", reality: "Even clear requests benefit from a minimal-viable vs ideal comparison." }
269
+ { claim: "We do not need alternatives for a clear request.", reality: "Even clear requests benefit from a minimal-viable vs ideal comparison." },
270
+ { claim: "Pushback risks sounding confrontational, so I should stay neutral.", reality: "Respectful pushback catches framing errors before they become expensive implementation mistakes." }
253
271
  ],
254
272
  redFlags: [
255
273
  "No selected mode in artifact",
274
+ "Mode selected without heuristic justification",
275
+ "No discretion section (or explicit `None`) in artifact",
256
276
  "No deferred/not-in-scope section",
257
277
  "No user approval marker",
258
278
  "Premise challenge missing or superficial",
259
279
  "No implementation alternatives evaluated"
260
280
  ],
261
- policyNeedles: ["Scope mode", "In Scope", "Out of Scope", "NOT in scope", "Premise Challenge"],
281
+ policyNeedles: ["Scope mode", "In Scope", "Out of Scope", "Discretion Areas", "NOT in scope", "Premise Challenge"],
262
282
  artifactFile: "02-scope.md",
263
283
  next: "design",
264
284
  cognitivePatterns: [
285
+ { name: "Depth Matches Complexity", description: "Scale each section to project complexity: concise for simple prototypes, deep for production systems." },
265
286
  { name: "Classification Instinct", description: "Categorize every decision by reversibility x magnitude. Most things are two-way doors — move fast. Only slow down for irreversible + high-magnitude decisions." },
266
287
  { name: "Inversion Reflex", description: "For every 'how do we win?' also ask 'what would make us fail?' Map failure modes before committing to scope." },
267
288
  { name: "Focus as Subtraction", description: "Primary value-add is what to NOT do. Default: do fewer things, better. Every feature must earn its place." },
@@ -327,12 +348,15 @@ const SCOPE = {
327
348
  traceabilityRule: "Every scope boundary must be traceable to a brainstorm decision. Every downstream design choice must stay within the scope contract."
328
349
  },
329
350
  artifactValidation: [
330
- { section: "Prime Directives", required: true, validationRule: "Named error modes for each capability. Four paths per data flow." },
351
+ { section: "Prime Directives", required: true, validationRule: "For each scoped capability: named failure modes, explicit error surface, four data-flow paths, interaction edge cases, observability expectations, and deferred-item handling." },
331
352
  { section: "Premise Challenge", required: true, validationRule: "Must contain explicit answers to: right problem? direct path? what if nothing?" },
353
+ { section: "Implementation Alternatives", required: true, validationRule: "2-3 options with Name, Summary, Effort, Risk, Pros, Cons, and Reuses. Must include minimal viable and ideal architecture options." },
332
354
  { section: "Scope Mode", required: true, validationRule: "Must state selected mode and rationale with default heuristic justification." },
333
355
  { section: "In Scope / Out of Scope", required: true, validationRule: "Two separate explicit lists. Out-of-scope must not be empty." },
356
+ { section: "Discretion Areas", required: true, validationRule: "Explicit list of implementer decision zones, or 'None' if scope is fully locked." },
334
357
  { section: "Deferred Items", required: true, validationRule: "Each item has one-line rationale. If empty, state 'None' explicitly." },
335
358
  { section: "Error & Rescue Registry", required: true, validationRule: "Each scoped capability has: failure mode, detection method, fallback decision." },
359
+ { section: "Completion Dashboard", required: true, validationRule: "Lists checklist findings, count of resolved decisions, and unresolved decisions (or 'None')." },
336
360
  { section: "Scope Summary", required: true, validationRule: "Clean summary: mode, strongest challenges, recommended path, accepted scope, deferred, excluded." }
337
361
  ],
338
362
  namedAntiPattern: {
@@ -361,28 +385,35 @@ const DESIGN = {
361
385
  "Implementation has already started and requires review instead of design lock"
362
386
  ],
363
387
  checklist: [
388
+ "Trivial-Change Escape Hatch — If scope artifact shows ≤3 files, zero new interfaces, and no cross-module data flow, skip full review sections. Produce a mini-design: one paragraph of rationale, list of changed files, one risk to watch. Proceed to spec.",
364
389
  "Design Doc Check — read existing design docs, scope artifact, brainstorm artifact. If a design doc exists that covers this area, check for 'Supersedes:' and use the latest. Use upstream artifacts as source of truth.",
390
+ "Codebase Investigation — Before any design decision, read the actual code in the blast radius. List every file that will be touched, its current responsibilities, and existing patterns (error handling, naming, test style). Design must conform to discovered patterns, not impose new ones without justification.",
365
391
  "Step 0: Scope Challenge — what existing code solves sub-problems? Minimum change set? Complexity check: 8+ files or 2+ new services = complexity smell → flag for possible scope reduction.",
366
392
  "Search Before Building — For each technical choice (library, pattern, architecture), search for existing solutions. Label findings: Layer 1 (exact match), Layer 2 (partial match, needs adaptation), Layer 3 (inspiration only), EUREKA (unexpected perfect solution). Default to existing before custom.",
367
- "Architecture Review — system design, component boundaries, data flow, scaling, security architecture. For each new codepath: one realistic production failure scenario.",
393
+ "Architecture Review — system design, component boundaries, data flow, scaling, security architecture. For each new codepath: one realistic production failure scenario. **Mandatory:** produce at least one architecture diagram (ASCII, Mermaid, or tool-generated) showing component boundaries and data flow direction.",
368
394
  "Code Quality Review — code organization, DRY violations, error handling patterns, over/under-engineering assessment.",
369
395
  "Test Review — diagram every new flow, data path, error path. For each: what test type covers it? Does one exist? What is the gap? Produce test plan artifact.",
370
396
  "Performance Review — N+1 queries, memory concerns, caching opportunities, slow code paths. What breaks at 10x load? At 100x?",
371
397
  "Parallelization Strategy — If multiple independent modules, produce dependency table: which can be built in parallel? Where are conflict risks? Flag shared-state modules.",
372
398
  "Unresolved Decisions — List any design decisions that could not be resolved in this session. For each: what information is missing? Who can provide it? What is the default if no answer comes?",
373
- "Distribution Check — If the plan creates new artifact types (packages, CLI tools, configs), document the build/publish story. How does it reach the user?"
399
+ "Distribution Check — If the plan creates new artifact types (packages, CLI tools, configs), document the build/publish story. How does it reach the user?",
400
+ "Deferred Items Cross-Reference — Collect every item explicitly deferred during design review. Each must appear in the Unresolved Decisions table or in the upstream scope artifact's deferred list. No deferred item may exist only in conversation — it must be written down."
374
401
  ],
375
402
  interactionProtocol: [
376
403
  "Review architecture decisions section-by-section.",
377
404
  "For EACH issue found in a review section, present it ONE AT A TIME. Do NOT batch multiple issues.",
378
- "For each issue: use the Decision Protocol — describe concretely with file/line references, present labeled options (A/B/C) with trade-offs and mark one as (recommended). 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.",
405
+ "For each issue: use the Decision Protocol — describe concretely with file/line references, present labeled options (A/B/C) with trade-offs, effort estimate (S/M/L/XL), risk level (Low/Med/High), and mark one as (recommended). 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.",
379
406
  "Only proceed to the next review section after ALL issues in the current section are resolved.",
380
407
  "If a section has no issues, say 'No issues found' and move on.",
381
408
  "Do not skip failure-mode mapping.",
382
- "For design baseline approval: present the full baseline. **STOP.** Do NOT proceed until user explicitly approves the design."
409
+ "For design baseline approval: present the full baseline. **STOP.** Do NOT proceed until user explicitly approves the design.",
410
+ "Take a firm position on every recommendation. Do NOT hedge with 'it depends' or 'you could do either'. State your opinion, then justify it.",
411
+ "Use pushback patterns for weak framing: if the user says 'it's just a small change', respond with 'small changes to shared interfaces have outsized blast radius — let's map it'. If 'we'll refactor later', respond with 'later never comes — show me the refactor ticket or do it now'.",
412
+ "When the user's proposed architecture is suboptimal, say so directly. Offer the alternative with concrete trade-offs, do not bury criticism in praise."
383
413
  ],
384
414
  process: [
385
415
  "Read upstream artifacts (brainstorm, scope).",
416
+ "Investigate codebase: read files in blast radius, catalogue current patterns and responsibilities.",
386
417
  "Run Step 0 scope challenge: existing code leverage, minimum change set, complexity check.",
387
418
  "Walk through each review section interactively.",
388
419
  "Define architecture boundaries and ownership.",
@@ -390,9 +421,11 @@ const DESIGN = {
390
421
  "Map failure modes and recovery strategy.",
391
422
  "Define test coverage strategy and performance budget.",
392
423
  "Produce required outputs: NOT-in-scope section, What-already-exists section, diagrams, failure mode table.",
424
+ "Produce completion dashboard: list every review section with status (clear / issues-found-resolved / issues-open), count of decisions made, and list of unresolved items.",
393
425
  "Write design lock artifact for downstream spec/plan."
394
426
  ],
395
427
  requiredGates: [
428
+ { id: "design_codebase_investigated", description: "Blast-radius files read and current patterns catalogued." },
396
429
  { id: "design_scope_challenge_done", description: "Step 0 scope challenge completed with existing-code mapping." },
397
430
  { id: "design_architecture_locked", description: "Architecture boundaries are explicit and approved." },
398
431
  { id: "design_data_flow_mapped", description: "Data/state flow includes edge-case paths." },
@@ -404,7 +437,8 @@ const DESIGN = {
404
437
  "Failure-mode table exists with mitigations.",
405
438
  "Test strategy includes unit/integration/e2e expectations.",
406
439
  "NOT-in-scope section produced.",
407
- "What-already-exists section produced."
440
+ "What-already-exists section produced.",
441
+ "Completion dashboard lists every review section status, decision count, and unresolved items (or 'None')."
408
442
  ],
409
443
  inputs: ["scope contract", "system constraints", "non-functional requirements"],
410
444
  requiredContext: [
@@ -417,7 +451,8 @@ const DESIGN = {
417
451
  "risk and failure map",
418
452
  "test and performance baseline",
419
453
  "NOT-in-scope section",
420
- "What-already-exists section"
454
+ "What-already-exists section",
455
+ "design completion dashboard"
421
456
  ],
422
457
  blockers: [
423
458
  "architecture ambiguity remains",
@@ -428,6 +463,7 @@ const DESIGN = {
428
463
  "design baseline approved",
429
464
  "all review sections completed",
430
465
  "required gates marked satisfied",
466
+ "completion dashboard present with all review-section statuses",
431
467
  "artifact complete for spec handoff"
432
468
  ],
433
469
  antiPatterns: [
@@ -435,20 +471,26 @@ const DESIGN = {
435
471
  "Missing data-flow edge cases",
436
472
  "No performance budget for critical path",
437
473
  "Batching multiple design issues into one question",
438
- "Skipping review sections because plan seems simple"
474
+ "Skipping review sections because plan seems simple",
475
+ "Agreeing with user's architecture choice without evaluating alternatives",
476
+ "Hedging every recommendation with 'it depends' instead of taking a position"
439
477
  ],
440
478
  rationalizations: [
441
479
  { claim: "Architecture can emerge incrementally while coding.", reality: "Unplanned architecture decisions cause incompatible module boundaries." },
442
480
  { claim: "Failure modes are edge cases we can ignore for now.", reality: "Production incidents usually come from unplanned edge paths." },
443
481
  { claim: "Performance can be optimized after launch.", reality: "Missing performance budgets make regressions invisible until late." },
444
- { claim: "This is a strategy doc so implementation sections do not apply.", reality: "Implementation details are where strategy breaks down. Every section must be evaluated." }
482
+ { claim: "This is a strategy doc so implementation sections do not apply.", reality: "Implementation details are where strategy breaks down. Every section must be evaluated." },
483
+ { claim: "The user preferred approach A, so we should go with it.", reality: "User preference is an input, not a conclusion. Evaluate on engineering merit. If approach B is objectively better, recommend B with evidence." },
484
+ { claim: "Both options are roughly equivalent.", reality: "Options are never equivalent once you quantify effort (S/M/L/XL) and risk (Low/Med/High). If you cannot distinguish them, you have not investigated deeply enough." }
445
485
  ],
446
486
  redFlags: [
447
487
  "No explicit architecture boundary section",
448
488
  "No failure recovery strategy",
449
489
  "No defined test/perf baseline",
450
490
  "Review sections skipped or condensed",
451
- "No NOT-in-scope output section"
491
+ "No NOT-in-scope output section",
492
+ "No What-already-exists output section",
493
+ "Design decisions made without reading the actual code first"
452
494
  ],
453
495
  policyNeedles: [
454
496
  "Architecture",
@@ -466,7 +508,10 @@ const DESIGN = {
466
508
  { name: "Essential vs Accidental Complexity", description: "Before adding anything: is this solving a real problem or one we created? Distinguish essential complexity from accidental." },
467
509
  { name: "Blast Radius Instinct", description: "Every decision evaluated through: what is the worst case and how many systems/people does it affect?" },
468
510
  { name: "Completeness Push", description: "AI effort is cheap. Push for completeness in plans: cover all files in blast radius, all edge cases in touched code, all affected tests. Favor doing it now over creating a TODO." },
469
- { name: "Owner Preference Alignment", description: "Every recommendation must align with project conventions (DRY, test style, minimal diff, edge-case rigor). Read existing patterns before recommending new ones." }
511
+ { name: "Owner Preference Alignment", description: "Every recommendation must align with project conventions (DRY, test style, minimal diff, edge-case rigor). Read existing patterns before recommending new ones." },
512
+ { name: "Failure Is Information", description: "A design that fails fast and visibly is better than one that silently degrades. Map every failure mode and make it observable. Undetected failures compound." },
513
+ { name: "Search Breadth Before Depth", description: "Before committing to a design path, survey the full solution space: stdlib, existing code, open-source, prior art. A 30-minute search can save a 30-hour custom build." },
514
+ { name: "Outside Voice", description: "When confidence is high and options seem obvious, that is exactly when to seek contradiction. Ask: what would a skeptical reviewer challenge here? What assumption am I not questioning?" }
470
515
  ],
471
516
  reviewSections: [
472
517
  {
@@ -531,12 +576,15 @@ const DESIGN = {
531
576
  },
532
577
  artifactValidation: [
533
578
  { section: "Architecture Boundaries", required: true, validationRule: "Must list component boundaries with ownership." },
579
+ { section: "Architecture Diagram", required: true, validationRule: "At least one diagram (ASCII, Mermaid, or image) showing component boundaries and data flow direction." },
534
580
  { section: "Data Flow", required: true, validationRule: "Must include happy path, nil input, empty input, upstream error paths." },
535
581
  { section: "Failure Mode Table", required: true, validationRule: "Each failure mode has: trigger, detection, mitigation, user impact." },
536
582
  { section: "Test Strategy", required: true, validationRule: "Must define unit/integration/e2e expectations with coverage targets." },
583
+ { section: "What Already Exists", required: true, validationRule: "For each sub-problem: existing code/library found (Layer 1-3/EUREKA label), reuse decision, and adaptation needed." },
537
584
  { section: "NOT in scope", required: true, validationRule: "Work considered and explicitly deferred with one-line rationale." },
538
585
  { section: "Parallelization Strategy", required: false, validationRule: "If multi-module: dependency table, parallel lanes, conflict flags." },
539
- { section: "Unresolved Decisions", required: false, validationRule: "If any: what info is missing, who provides it, default if unanswered." }
586
+ { section: "Unresolved Decisions", required: false, validationRule: "If any: what info is missing, who provides it, default if unanswered." },
587
+ { section: "Completion Dashboard", required: true, validationRule: "Lists every review section with status (clear / issues-found-resolved / issues-open), decision count, and unresolved items (or 'None')." }
540
588
  ],
541
589
  namedAntiPattern: {
542
590
  title: "Architecture Will Emerge While Coding",
@@ -49,6 +49,27 @@ export const ARTIFACT_TEMPLATES = {
49
49
  - Why this path?
50
50
  - What if we do nothing?
51
51
 
52
+ ## Dream State Mapping
53
+ - CURRENT STATE:
54
+ - THIS PLAN:
55
+ - 12-MONTH IDEAL:
56
+ - Alignment verdict:
57
+
58
+ ## Implementation Alternatives
59
+ | Option | Summary | Effort (S/M/L/XL) | Risk (Low/Med/High) | Pros | Cons | Reuses |
60
+ |---|---|---|---|---|---|---|
61
+ | A (minimum viable) | | | | | | |
62
+ | B (ideal architecture) | | | | | | |
63
+ | C (optional) | | | | | | |
64
+
65
+ ## Temporal Interrogation
66
+ | Time slice | Likely decision pressure | Lock now or defer? | Reason |
67
+ |---|---|---|---|
68
+ | HOUR 1 (foundations) | | | |
69
+ | HOUR 2-3 (core logic) | | | |
70
+ | HOUR 4-5 (integration) | | | |
71
+ | HOUR 6+ (polish/tests) | | | |
72
+
52
73
  ## Scope Mode
53
74
  - [ ] expand
54
75
  - [ ] selective
@@ -63,6 +84,9 @@ export const ARTIFACT_TEMPLATES = {
63
84
  ### Out of Scope
64
85
  -
65
86
 
87
+ ## Discretion Areas
88
+ - (or \`None\`)
89
+
66
90
  ## Deferred Items
67
91
  | Item | Rationale |
68
92
  |---|---|
@@ -73,6 +97,11 @@ export const ARTIFACT_TEMPLATES = {
73
97
  |---|---|---|---|
74
98
  | | | | |
75
99
 
100
+ ## Completion Dashboard
101
+ - Checklist findings:
102
+ - Resolved decisions count:
103
+ - Unresolved decisions (or \`None\`):
104
+
76
105
  ## Scope Summary
77
106
  - Selected mode:
78
107
  - Accepted scope:
@@ -81,11 +110,34 @@ export const ARTIFACT_TEMPLATES = {
81
110
  `,
82
111
  "03-design.md": `# Design Artifact
83
112
 
113
+ ## Codebase Investigation
114
+ | File | Current responsibility | Patterns discovered |
115
+ |---|---|---|
116
+ | | | |
117
+
118
+ ## Search Before Building
119
+ | Layer | Label | What to reuse first |
120
+ |---|---|---|
121
+ | Layer 1 | | |
122
+ | Layer 2 | | |
123
+ | Layer 3 | | |
124
+
84
125
  ## Architecture Boundaries
85
126
  | Component | Responsibility | Owner |
86
127
  |---|---|---|
87
128
  | | | |
88
129
 
130
+ ## Architecture Diagram
131
+
132
+ \\\`\\\`\\\`
133
+ (ASCII, Mermaid, or tool-generated diagram showing component boundaries and data flow direction)
134
+ \\\`\\\`\\\`
135
+
136
+ ## What Already Exists
137
+ | Sub-problem | Existing code/library | Layer | Reuse decision |
138
+ |---|---|---|---|
139
+ | | | | |
140
+
89
141
  ## Data Flow
90
142
  - Happy path:
91
143
  - Nil/empty input path:
@@ -113,6 +165,17 @@ export const ARTIFACT_TEMPLATES = {
113
165
  | Decision | Missing info | Owner | Default |
114
166
  |---|---|---|---|
115
167
  | | | | |
168
+
169
+ ## Completion Dashboard
170
+ | Review Section | Status | Issues |
171
+ |---|---|---|
172
+ | Architecture Review | | |
173
+ | Code Quality Review | | |
174
+ | Test Review | | |
175
+ | Performance Review | | |
176
+ | Distribution & Delivery Review | | |
177
+
178
+ **Decisions made:** 0 | **Unresolved:** 0
116
179
  `,
117
180
  "04-spec.md": `# Specification Artifact
118
181
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cclaw-cli",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "description": "Installer-first flow toolkit for coding agents",
5
5
  "type": "module",
6
6
  "bin": {