cclaw-cli 0.1.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -0
  3. package/dist/cli.d.ts +10 -0
  4. package/dist/cli.js +101 -0
  5. package/dist/config.d.ts +5 -0
  6. package/dist/config.js +70 -0
  7. package/dist/constants.d.ts +12 -0
  8. package/dist/constants.js +50 -0
  9. package/dist/content/agents.d.ts +39 -0
  10. package/dist/content/agents.js +244 -0
  11. package/dist/content/autoplan.d.ts +7 -0
  12. package/dist/content/autoplan.js +297 -0
  13. package/dist/content/contracts.d.ts +2 -0
  14. package/dist/content/contracts.js +50 -0
  15. package/dist/content/examples.d.ts +2 -0
  16. package/dist/content/examples.js +327 -0
  17. package/dist/content/hooks.d.ts +16 -0
  18. package/dist/content/hooks.js +753 -0
  19. package/dist/content/learnings.d.ts +5 -0
  20. package/dist/content/learnings.js +265 -0
  21. package/dist/content/meta-skill.d.ts +10 -0
  22. package/dist/content/meta-skill.js +137 -0
  23. package/dist/content/observe.d.ts +21 -0
  24. package/dist/content/observe.js +1110 -0
  25. package/dist/content/session-hooks.d.ts +7 -0
  26. package/dist/content/session-hooks.js +137 -0
  27. package/dist/content/skills.d.ts +3 -0
  28. package/dist/content/skills.js +257 -0
  29. package/dist/content/stage-schema.d.ts +78 -0
  30. package/dist/content/stage-schema.js +1453 -0
  31. package/dist/content/subagents.d.ts +13 -0
  32. package/dist/content/subagents.js +616 -0
  33. package/dist/content/templates.d.ts +3 -0
  34. package/dist/content/templates.js +272 -0
  35. package/dist/content/utility-skills.d.ts +12 -0
  36. package/dist/content/utility-skills.js +467 -0
  37. package/dist/doctor.d.ts +7 -0
  38. package/dist/doctor.js +610 -0
  39. package/dist/flow-state.d.ts +19 -0
  40. package/dist/flow-state.js +41 -0
  41. package/dist/fs-utils.d.ts +5 -0
  42. package/dist/fs-utils.js +28 -0
  43. package/dist/gitignore.d.ts +3 -0
  44. package/dist/gitignore.js +43 -0
  45. package/dist/harness-adapters.d.ts +12 -0
  46. package/dist/harness-adapters.js +175 -0
  47. package/dist/install.d.ts +9 -0
  48. package/dist/install.js +562 -0
  49. package/dist/learnings-summarizer.d.ts +25 -0
  50. package/dist/learnings-summarizer.js +201 -0
  51. package/dist/logger.d.ts +3 -0
  52. package/dist/logger.js +6 -0
  53. package/dist/policy.d.ts +6 -0
  54. package/dist/policy.js +179 -0
  55. package/dist/runs.d.ts +18 -0
  56. package/dist/runs.js +446 -0
  57. package/dist/types.d.ts +19 -0
  58. package/dist/types.js +12 -0
  59. package/package.json +47 -0
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Markdown content generators for Cclaw’s subagent orchestration skills and enhanced
3
+ * specialist payloads. Cclaw materializes static instructions — this module does not
4
+ * execute orchestration logic at install time beyond string assembly.
5
+ */
6
+ export declare function subagentDrivenDevSkill(): string;
7
+ export declare function parallelAgentsSkill(): string;
8
+ /**
9
+ * Returns markdown fragments augmenting each specialist persona with Task tool
10
+ * delegation guidance. Combine with the existing `body` field from `agents.ts`.
11
+ */
12
+ export declare function enhancedAgentBody(agentName: string): string;
13
+ export declare function subagentsAgentsMdBlock(): string;
@@ -0,0 +1,616 @@
1
+ /**
2
+ * Markdown content generators for Cclaw’s subagent orchestration skills and enhanced
3
+ * specialist payloads. Cclaw materializes static instructions — this module does not
4
+ * execute orchestration logic at install time beyond string assembly.
5
+ */
6
+ const SUBAGENT_AGENT_NAMES = [
7
+ "planner",
8
+ "spec-reviewer",
9
+ "code-reviewer",
10
+ "security-reviewer",
11
+ "test-author",
12
+ "doc-updater",
13
+ ];
14
+ export function subagentDrivenDevSkill() {
15
+ return `---
16
+ name: subagent-driven-development
17
+ description: "Orchestrate implementation via isolated subagents — one fresh agent per task with two-stage review."
18
+ ---
19
+
20
+ # Subagent-Driven Development (SDD)
21
+
22
+ ## Overview
23
+
24
+ Use a **controller → implementer → reviewer** loop when building multi-step software work.
25
+
26
+ - **Controller (parent agent):** owns the plan, gating, sequencing, and dispatch decisions; never mixes deep implementation context with review evidence.
27
+ - **Implementer (subagent):** receives a **single self-contained task** and edits code within that scope; exits with a structured status contract.
28
+ - **Reviewer (subagent):** validates outputs against the specification **by reading code**, then hands findings back to the controller for the next dispatch.
29
+
30
+ This pattern is intentionally **Superpowers-style**: cheap parallelism where it doesn’t corrupt state, strict serialization where it would.
31
+
32
+ ## Automatic Stage Delegation in Cclaw
33
+
34
+ For cclaw flow stages, machine-only specialist work should auto-dispatch without waiting for a manual user request:
35
+
36
+ - **design/plan:** planner
37
+ - **test/build:** test-author
38
+ - **review:** spec-reviewer + code-reviewer (security-reviewer when trust boundaries moved)
39
+ - **ship:** doc-updater
40
+
41
+ Human input remains mandatory only at explicit approval gates (plan approval, user challenge resolution, release finalization mode).
42
+
43
+ ## HARD-GATE
44
+
45
+ **Never dispatch a subagent without a concrete, self-contained task description pasted into the prompt. Do not pass file references the subagent must read to understand its task.**
46
+
47
+ If you catch yourself writing “read PLAN.md Task 3” or “implement the next unchecked item,” stop: expand the work into explicit text in the Task body before dispatching.
48
+
49
+ ## When to Use
50
+
51
+ - Mid/large plans with multiple discrete tasks, dependencies, or risky overlap.
52
+ - Complex features where isolation prevents parent-session context pollution.
53
+ - Situations where **fresh tool context** is cheaper than incremental patching in one mega-thread.
54
+ - When reviews should be adversarial to claims (“show me the code”), not collegial summaries.
55
+
56
+ ## Full Protocol
57
+
58
+ 1. **Read plan, extract all tasks with full text**
59
+ - Copy each task verbatim into a working queue (checklist is fine).
60
+ - Normalize each task so it includes: goal, acceptance criteria, constraints, and explicit “out of scope.”
61
+
62
+ 2. **For each task sequentially (NEVER parallel implementation subagents — file conflicts):**
63
+ 1. **Dispatch implementer subagent** with the **full task text pasted in** (not a file reference).
64
+ 2. **Check return status:** \`DONE\` / \`DONE_WITH_CONCERNS\` / \`NEEDS_CONTEXT\` / \`BLOCKED\`
65
+ 3. If \`DONE\`: dispatch **spec-reviewer** subagent to verify actual code matches spec.
66
+ 4. If spec review **FAIL**: dispatch **fixer subagent** (a **new** agent — not an inline patch from the parent — to avoid context pollution).
67
+ 5. Dispatch **code-quality reviewer** (maintainability/PR hygiene).
68
+ 6. **Mark task complete** only after concerns are triaged or explicitly accepted with rationale.
69
+
70
+ 3. **After all tasks:** dispatch **final code reviewer** for a full-repo / full-surface pass (what escaped local task boundaries).
71
+
72
+ 4. **Transition to finishing workflow** (ship checklist, changelog, migration notes) once reviewers show no unresolved Criticals.
73
+
74
+ ## Status Contract
75
+
76
+ | Status | Meaning | Controller action |
77
+ |---|---|---|
78
+ | DONE | Implementation complete; tests orchestrated per prompt; no known material risks | Proceed to reviewers |
79
+ | DONE_WITH_CONCERNS | Shippable but with documented tradeoffs/risks | Proceed with reviewer + explicit notes; do not “hand-wave” concerns |
80
+ | NEEDS_CONTEXT | Missing authoritative information only the parent/user can supply | Parent gathers context, then re-dispatch implementer with augmented prompt |
81
+ | BLOCKED | Hard stop (permissions, tool failure, conflicting requirements, unsafe state) | Parent escalates to user; do not stack speculative guesses |
82
+
83
+ ## Implementer Prompt Template (paste into Task tool)
84
+
85
+ \`\`\`
86
+ You are implementing a single task from a development plan.
87
+
88
+ TASK: {paste full task text here}
89
+ CONTEXT: {paste relevant file paths, types, patterns}
90
+ CONSTRAINTS: {paste from spec — what NOT to do}
91
+
92
+ After implementation:
93
+ 1. Run the full test suite
94
+ 2. Report your status: DONE / DONE_WITH_CONCERNS / NEEDS_CONTEXT / BLOCKED
95
+ 3. If DONE_WITH_CONCERNS, list each concern
96
+ 4. If NEEDS_CONTEXT, specify exactly what you need
97
+ \`\`\`
98
+
99
+ ## Spec-Reviewer Prompt Template (paste into Task tool)
100
+
101
+ \`\`\`
102
+ Review the implementation against the specification.
103
+
104
+ SPEC CRITERIA: {paste acceptance criteria}
105
+ FILES CHANGED: {list files}
106
+
107
+ For each criterion: PASS / FAIL / PARTIAL with evidence (file:line).
108
+ Do NOT trust the implementer's self-report — read the actual code.
109
+ \`\`\`
110
+
111
+ ## Anti-patterns
112
+
113
+ - Launching **parallel implementation** subagents that may touch the same files or adjacent modules.
114
+ - Passing a **plan file path** instead of pasting the **exact task text** for the subagent.
115
+ - Accepting implementer “done” claims without **spec review evidence** grounded in code.
116
+ - **Patching inline** in the parent when review fails — instead of dispatching a **fresh fixer** subagent.
117
+
118
+ ## Critical Rules
119
+
120
+ - **Context isolation:** subagent receives crafted instructions only — **not** the parent session’s scratchpad/history.
121
+ - **Never trust the implementer:** reviewers verify against **code** and tests, not narrative self-report.
122
+ - **One task at a time:** sequential implementations prevent conflicting writes; keep parallelism for analysis/review patterns only (see \`dispatching-parallel-agents\`).
123
+ - **Fixer = new agent:** if spec review fails, dispatch a fresh fixer subagent; avoid “repair drift” in the parent context.
124
+
125
+ ## Common Rationalizations
126
+
127
+ | Rationalization | Reality |
128
+ |---|---|
129
+ | “They can read the plan file — it’s faster.” | File indirection hides scope and invites partial reads; paste task text. |
130
+ | “I'll spin up two implementers — they're independent.” | False independence causes merge conflicts and duplicated edits. |
131
+ | “The implementer ran tests and said PASS.” | Re-run or have reviewers demand fresh evidence; narratives lie by omission. |
132
+ | “I'll patch quickly myself; same outcome.” | Parent context fills with fix chatter, undermining later reviews. |
133
+
134
+ ## Red Flags
135
+
136
+ - Task prompts shorter than the acceptance criteria they are supposed to satisfy.
137
+ - Implementer returns PASS with **no** commands run or outputs excerpted.
138
+ - Multiple agents concurrently editing overlapping directories.
139
+ - Review summaries without \`file:line\` anchors for FAIL/PARTIAL.
140
+ - “Done” without a spec reviewer pass when requirements were non-trivial.
141
+
142
+ ## Controller Responsibilities (non-delegatable)
143
+
144
+ - Maintain the **authoritative task queue** and ensure each dispatch uses **verbatim** task text.
145
+ - Decide when concerns are **acceptable** vs require rework; record that decision explicitly for auditability.
146
+ - Keep parent-session narration **thin**: prefer pointers to artifacts (diffs, logs) over long prose.
147
+ - After any fixer pass, **re-run** spec review until PASS or explicit user acceptance of residual gaps.
148
+
149
+ ## Evidence Requirements
150
+
151
+ - **Tests:** implementer must name the command and show representative output (pass/fail excerpt).
152
+ - **Reviews:** every FAIL/PARTIAL cites \`file:line\` and quotes the smallest code span needed.
153
+ - **Fixers:** must restate the failing criterion and demonstrate closure with new evidence (not “trust me”).
154
+
155
+ ## Code-Quality Reviewer Prompt Template (paste into Task tool)
156
+
157
+ \`\`\`
158
+ You are a code-quality reviewer (subagent) after a single SDD task.
159
+
160
+ SCOPE: {files touched by this task}
161
+ RISK CONTEXT: {data sensitivity, concurrency, backwards compatibility notes}
162
+
163
+ Review for maintainability and ship hygiene across:
164
+ - correctness edges not covered by spec language
165
+ - readability and naming coherence with surrounding code
166
+ - architecture fit (layering, boundaries)
167
+ - obvious security/perf smells (deep dives belong elsewhere)
168
+
169
+ Output:
170
+ - FINDINGS: severity, file:line, issue, recommendation
171
+ - VERDICT: APPROVE | APPROVE_WITH_NITS | REWORK_REQUIRED
172
+ \`\`\`
173
+
174
+ ## Fixer Subagent Prompt Template (after spec review FAIL)
175
+
176
+ \`\`\`
177
+ You are a fixer subagent. You are NOT the original implementer.
178
+
179
+ FAILING CRITERION (verbatim): {paste failed criterion}
180
+ EVIDENCE: {reviewer citations: file:line + short quotes}
181
+ ALLOWED FILES: {explicit list — do not expand scope silently}
182
+ FORBIDDEN CHANGES: {compatibility / API stability constraints}
183
+
184
+ Process:
185
+ 1) Reproduce the gap with a test or minimal repro as appropriate.
186
+ 2) Implement the smallest fix that satisfies the criterion.
187
+ 3) Run the full test suite.
188
+ 4) Report STATUS: DONE / DONE_WITH_CONCERNS / NEEDS_CONTEXT / BLOCKED with evidence excerpts.
189
+ \`\`\`
190
+
191
+ ## Final Code Reviewer Prompt Template (post-queue sweep)
192
+
193
+ \`\`\`
194
+ You are the final code-quality reviewer after ALL SDD tasks completed.
195
+
196
+ ENTIRE CHANGESET: {summary + primary entrypoints}
197
+ INTEGRATION RISKS: {cross-module assumptions, migrations, rollout}
198
+
199
+ Goals:
200
+ - Find issues that only appear at integration scale (duplicated helpers, drift, inconsistent error handling).
201
+ - Confirm global invariants (build, types, lint policy) were not violated opportunistically.
202
+
203
+ Deliver:
204
+ - TOP_FINDINGS (merge blockers first)
205
+ - CONSISTENCY_PASS/FAIL with rationale
206
+ - SHIP_RECOMMENDATION: SHIP | SHIP_WITH_FOLLOWUPS | NO_SHIP
207
+ \`\`\`
208
+
209
+ ## Glossary
210
+
211
+ - **Controller:** parent agent orchestrating dispatches (this document assumes you).
212
+ - **Implementer:** single-task coding subagent.
213
+ - **Spec reviewer:** acceptance-criteria auditor over code.
214
+ - **Code-quality reviewer:** PR hygiene / maintainability auditor.
215
+ - **Fixer:** fresh subagent after failed spec review (never “parent hotfix” by default).
216
+ `;
217
+ }
218
+ export function parallelAgentsSkill() {
219
+ return `---
220
+ name: dispatching-parallel-agents
221
+ description: "Launch multiple investigation or review agents in parallel for independent problem domains."
222
+ ---
223
+
224
+ # Dispatching Parallel Agents
225
+
226
+ ## Overview
227
+
228
+ Parallel agents are a **fan-out / fan-in** tactic: split a problem into **independent lenses**, delegate each lens in **parallel**, then **reconcile** outputs into a single coherent decision record.
229
+
230
+ This document bridges **Superpowers-style task isolation** with the **gstack “Review Army”** pattern: many cheap specialists, structured outputs, and confidence-scored synthesis.
231
+
232
+ ## HARD-GATE
233
+
234
+ **Never dispatch parallel IMPLEMENTATION agents that write to the same codebase. Parallel agents are for investigation, analysis, and review ONLY.**
235
+
236
+ Implementation that touches shared source trees must remain **sequential** unless you have proven disjoint filesystem ownership (rare) and an explicit merge protocol.
237
+
238
+ ## When to Use
239
+
240
+ - **Independent investigations** (perf vs correctness vs dependency hygiene) with separated code neighborhoods.
241
+ - **Multi-specialist review** where reviewers must not contaminate each other’s first impressions.
242
+ - **Parallel test/log analysis** across unrelated failures (distinct subsystems).
243
+
244
+ ## Dispatch Protocol
245
+
246
+ 1. **Identify independent problem domains** (no file overlap; no shared mutable working assumptions).
247
+ 2. **Craft one prompt per domain** with **full context pasted** — same HARD-GATE as SDD: no “go read X to learn why.”
248
+ 3. **Launch ALL agents in a single controller message** (multiple Task tool calls) so they start with comparable timelines.
249
+ 4. **Wait for all to return** before synthesis (avoid incremental confirmation bias).
250
+ 5. **Reconcile results:** deduplicate findings, merge overlaps, and **conflict-check** contradictions explicitly.
251
+ 6. **Run the full test suite after any code changes** — parallel analysis may propose edits; verification stays mandatory.
252
+
253
+ ## Review Army Pattern (gstack)
254
+
255
+ - **Select specialists based on diff content** (security vs data model vs UX vs API compatibility).
256
+ - **Launch in parallel** via multiple Task tool calls (one specialist = one Task payload).
257
+ - **Collect findings as structured data** (severity, location, confidence, repro brief).
258
+ - **Fingerprint dedup:** if the same finding is reported by **two or more** independent specialists, mark it **MULTI-SPECIALIST CONFIRMED** and **+1** confidence vs a singleton.
259
+ - **Confidence bands (presentation):**
260
+ - **7+:** headline in the main report / merge-blocking if severity warrants
261
+ - **5–6:** headline with explicit caveat language (“single-lens evidence”)
262
+ - **3–4:** appendix / “worth tracking” section (not merge-blocking alone)
263
+ - **1–2:** suppress from primary narrative unless paired with stronger evidence
264
+
265
+ ### Review Army Artifact Contract (required in /cc-review)
266
+
267
+ Write a structured reconciliation artifact at \`.cclaw/artifacts/07-review-army.json\` using this schema:
268
+
269
+ \`\`\`json
270
+ {
271
+ "version": 1,
272
+ "generatedAt": "ISO timestamp",
273
+ "scope": { "base": "branch", "head": "branch", "files": ["..."] },
274
+ "findings": [
275
+ {
276
+ "id": "stable-id",
277
+ "severity": "Critical|Important|Suggestion",
278
+ "confidence": 1,
279
+ "fingerprint": "hash-or-stable-key",
280
+ "reportedBy": ["spec-reviewer", "code-reviewer"],
281
+ "status": "open|accepted|resolved",
282
+ "location": { "file": "path", "line": 123 },
283
+ "recommendation": "..."
284
+ }
285
+ ],
286
+ "reconciliation": {
287
+ "duplicatesCollapsed": 0,
288
+ "conflicts": [],
289
+ "multiSpecialistConfirmed": [],
290
+ "shipBlockers": []
291
+ }
292
+ }
293
+ \`\`\`
294
+
295
+ Contract rules:
296
+ - \`id\` and \`fingerprint\` must be stable between reruns if the finding is unchanged.
297
+ - \`reportedBy\` must include every specialist that independently flagged the issue.
298
+ - \`multiSpecialistConfirmed\` lists finding IDs confirmed by 2+ specialists.
299
+ - \`shipBlockers\` must include all unresolved \`Critical\` finding IDs.
300
+
301
+ ## Reconciliation Protocol
302
+
303
+ 1. **Normalize** each agent output into a finding list with stable IDs (hash of filepath + rule + message).
304
+ 2. **Merge duplicates** by fingerprint; annotate confirmations from multiple specialists.
305
+ 3. **Resolve conflicts** where agents disagree: prefer **evidence-backed** conclusions; if inconclusive, state **UNKNOWN** and propose a single follow-up measurement (bench, test, threat model detail).
306
+ 4. **Prioritize** by ship risk (data loss, authz, corruption) then by blast radius.
307
+ 5. **Emit** a single “Decision Record” the implementer can execute sequentially.
308
+
309
+ ## Anti-patterns
310
+
311
+ - Treating parallel Task launches as a **race to commit**.
312
+ - **Parallel implementation agents** sharing a repo without strict file partitioning.
313
+ - **Shared mutable state** between agents (scratchpads in the same artifact without merge rules).
314
+
315
+ ## When NOT to Use
316
+
317
+ - Any task that **implements** production behavior (use SDD sequential implementers instead).
318
+ - Workstreams with **hard file dependencies** (Agent B needs Agent A’s edits to compile).
319
+ - Small single-file tweaks where orchestration overhead exceeds benefit.
320
+
321
+ ## Quick Reference Table
322
+
323
+ | Mode | Parallel allowed? | Typical tooling |
324
+ |---|---|---|
325
+ | Investigation | Yes (disjoint) | Multiple Task calls |
326
+ | Review | Yes (disjoint lenses) | Multiple Task calls |
327
+ | Implementation | **No** (same codebase) | Sequential Task calls |
328
+
329
+ ## Controller Checklist (before parallel launch)
330
+
331
+ - Each prompt contains **all** needed instructions (no “read plan” indirection).
332
+ - Domains are **provably non-overlapping** in touched paths.
333
+ - You have a reconciliation plan (dedupe + conflict rules + confidence bands).
334
+
335
+ ## Task Payload Hygiene (parallel-safe)
336
+
337
+ - Start each payload with **ROLE + SCOPE + OUTPUT SCHEMA** (same order every time).
338
+ - Include **hard boundaries**: directories allowed/forbidden to read, max depth, and “do not edit.”
339
+ - Ask for **structured sections** (\`FINDINGS\`, \`CONFIDENCE\`, \`UNKNOWN\`) to simplify merging.
340
+ - Prefer **deterministic prompts** over creative prose — you are building evidence, not vibes.
341
+
342
+ ## Specialist Roster (examples — pick what matches the diff)
343
+
344
+ | Specialist lens | Looks for… | Typical inputs |
345
+ |---|---|---|
346
+ | Security | authz, injection, SSRF, secrets, trust boundaries | routes, parsers, middleware |
347
+ | Data model | invariants, migrations, idempotency, consistency | schema, repositories, jobs |
348
+ | API compatibility | breaking changes, versioning, error contracts | public types, OpenAPI, clients |
349
+ | Performance | hot loops, IO, caching mistakes | hotspots, benchmarks, traces |
350
+ | UX / a11y | state bugs, focus traps, i18n | components, flows |
351
+ | Observability | logs/metrics/traces correctness | instrumentation, alerts |
352
+
353
+ ## Confidence Scoring Rubric (0–10)
354
+
355
+ - **10:** reproduced locally with deterministic steps + code citation + multi-specialist confirmation.
356
+ - **8–9:** strong code citation + plausible exploit/bug class; single specialist but excellent evidence.
357
+ - **5–7:** plausible issue worth tracking; needs confirmation test or owner review.
358
+ - **3–4:** hypothesis-level; do not merge-block without corroboration.
359
+ - **0–2:** intuition / style; suppress unless paired with stronger evidence.
360
+
361
+ ## Merge-Blocking Rules (after reconciliation)
362
+
363
+ - Any **MULTI-SPECIALIST CONFIRMED** **Critical** is merge-blocking until resolved or explicitly waived by the user.
364
+ - Conflicting conclusions at **Critical** severity require a tie-break experiment (test/bench) — never guess.
365
+ - If reconciliation yields **UNKNOWN** for ship safety, treat as **BLOCKED** until measured.
366
+
367
+ ## Post-Reconcile Actions (controller)
368
+
369
+ 1. Publish a single **merged report** with headline / caveat / appendix bands applied.
370
+ 2. Convert findings into **sequential SDD tasks** if code changes are required.
371
+ 3. If no code changes: still run **sanity checks** appropriate to the repo (typecheck/lint spot).
372
+
373
+ ## Parallel Review Task Template (paste into Task tool)
374
+
375
+ \`\`\`
376
+ You are an independent review/investigation subagent.
377
+
378
+ LENS: {security|data|perf|api|ux|observability — pick one}
379
+ SCOPE: {explicit paths/modules}
380
+ QUESTION: {one primary question — falsifiable}
381
+ DELIVERABLE: structured findings with confidence 0–10 each
382
+
383
+ Rules:
384
+ - Do not edit files unless explicitly authorized in this prompt.
385
+ - Cite evidence as file:line for every finding.
386
+ - If uncertain, emit CONFIDENCE <= 4 and label as hypothesis.
387
+ \`\`\`
388
+
389
+ ## Worked Example (narrative)
390
+
391
+ A large refactor touches **auth middleware** and **repository queries**. The controller launches parallel reviewers: **security**, **data model**, **API compatibility**. Security finds a possible IDOR (confidence 6); data model finds a migration hazard (confidence 7); API finds a breaking error shape (confidence 8). Fingerprints show no duplicates. Reconciliation merge-blocks on the API break (single specialist but high confidence + citation). Security’s IDOR is downgraded to appendix until a second specialist confirms — later confirmed by **perf** reviewer noticing an extra query path — now **MULTI-SPECIALIST CONFIRMED**, confidence becomes **8** and moves to headline.
392
+
393
+ ## Relationship to SDD
394
+
395
+ - Parallel agents produce **evidence and prioritized tasks**.
396
+ - SDD **implements** those tasks **one at a time** with sequential implementers.
397
+ - Never parallelize **writers** on the same codebase; parallelize **readers/analysts** with disjoint scopes.
398
+ `;
399
+ }
400
+ function plannerEnhancedBody() {
401
+ return `
402
+
403
+ ## Task Tool Delegation
404
+
405
+ When a planning problem is too broad for one message, delegate **planning subtasks** via the Task tool — still without parallelizing conflicting file reads if your harness shares caches.
406
+
407
+ Paste the template below verbatim and fill \`{placeholders}\` in the parent before dispatching.
408
+
409
+ \`\`\`
410
+ You are a planning subagent for a larger Cclaw / engineering workflow.
411
+
412
+ PLANNING GOAL: {one sentence outcome — e.g., sequencing, risk register, dependency graph}
413
+ KNOWN CONSTRAINTS: {deadlines, compatibility, performance, compliance}
414
+ CONTEXT ARTIFACTS (read-only list, not instructions): {paths already agreed authoritative}
415
+ DELIVERABLES: {explicit outputs — e.g., ordered task list, risk table, decision questions}
416
+
417
+ Rules:
418
+ - Do NOT implement production code.
419
+ - Every task must include acceptance criteria copy-paste ready for SDD implementers.
420
+ - Flag UNKNOWN explicitly instead of guessing.
421
+ - Close with: OPEN_QUESTIONS: ... and NEXT_TASK_TEXT: ... (verbatim extractable queue item)
422
+ \`\`\`
423
+
424
+ `;
425
+ }
426
+ function specReviewerEnhancedBody() {
427
+ return `
428
+
429
+ ## Task Tool Delegation
430
+
431
+ For spec-compliance audits, use the Task tool with the following **spec-reviewer** payload (fill placeholders in the parent session).
432
+
433
+ \`\`\`
434
+ You are a specification compliance reviewer (subagent).
435
+
436
+ SPEC CRITERIA (verbatim): {acceptance criteria / invariants / non-goals}
437
+ CHANGE SURFACE: {files/commits/PR scope description}
438
+ CONTEXT: {domain notes — auth, idempotency, UX states, data contracts}
439
+
440
+ Instructions:
441
+ - For EACH criterion emit PASS / PARTIAL / FAIL with evidence as file:line.
442
+ - Read the code; ignore implementer claims unless backed by code citations.
443
+ - Close with SPEC_VERDICT: PASS | PASS_WITH_GAPS | FAIL plus GAPS/FAIL list.
444
+ \`\`\`
445
+
446
+ `;
447
+ }
448
+ function codeReviewerEnhancedBody() {
449
+ return `
450
+
451
+ ## Task Tool Delegation
452
+
453
+ Launch deep **code-quality** reviews using this five-axis template in the Task tool body:
454
+
455
+ \`\`\`
456
+ You are a code-quality reviewer (subagent). Review along ALL axes:
457
+
458
+ 1) Correctness — logic, data flow, error handling, boundary conditions
459
+ 2) Readability — naming, structure, comments worth keeping vs noise
460
+ 3) Architecture — boundaries, coupling, extensibility, layering
461
+ 4) Security (light touch) — trust boundaries, dangerous APIs; defer deep vulns to security specialist if needed
462
+ 5) Performance — hot paths, accidental complexity, IO pitfalls
463
+
464
+ SCOPE: {diff summary or file list}
465
+ BASELINE CONTEXT: {tests, deployment constraints, compatibility promises}
466
+
467
+ Output format (mandatory):
468
+ - FINDING: [Critical|Important|Suggestion] file:line — problem — recommendation
469
+ - Close with RISK_SUMMARY and SHIP_BLOCKERS (explicit list, possibly empty).
470
+ \`\`\`
471
+
472
+ `;
473
+ }
474
+ function securityReviewerEnhancedBody() {
475
+ return `
476
+
477
+ ## Task Tool Delegation
478
+
479
+ Use a dedicated Task tool invocation for CWE-focused review with reproducible narratives:
480
+
481
+ \`\`\`
482
+ You are a security reviewer (subagent). Perform a CWE-oriented review of the scoped change.
483
+
484
+ SCOPE: {files/commits/services touched}
485
+ THREAT CONTEXT: {exposure, persona, sensitive data classes, trust boundaries crossed}
486
+
487
+ Requirements:
488
+ - Map each finding to CWE-### when possible (else UNKNOWN).
489
+ - Provide severity (Critical|Important|Suggestion) tied to exploitability/impact.
490
+ - Include a short proof-of-concept attack vector (conceptual, no weaponization).
491
+ - Recommend concrete controls (validation, sandboxing, authz checks, safer APIs).
492
+ - Close with SECURITY_VERDICT: SHIP | SHIP_WITH_HOTFIXES | NO_SHIP and cite top 3 drivers.
493
+ \`\`\`
494
+
495
+ `;
496
+ }
497
+ function testAuthorEnhancedBody() {
498
+ return `
499
+
500
+ ## Task Tool Delegation
501
+
502
+ Delegate TDD loops carefully — one behavioral slice per subagent to avoid clobbering tests.
503
+ This agent runs in two explicit stage modes to respect cclaw hard-gates:
504
+ - \`TEST_RED_ONLY\` (only failing tests + evidence; no production edits)
505
+ - \`BUILD_GREEN_REFACTOR\` (implementation + full-suite green + refactor notes)
506
+
507
+ \`\`\`
508
+ You are a TDD implementer subagent.
509
+
510
+ STAGE_MODE: {TEST_RED_ONLY | BUILD_GREEN_REFACTOR}
511
+ FEATURE SLICE: {single behavior expressed as a user-observable outcome}
512
+ CURRENT TEST COMMANDS: {exact command names + cwd assumptions}
513
+ FIXTURES / PATTERNS: {links to helper modules by path + naming conventions}
514
+
515
+ Process (mandatory):
516
+ 1) If STAGE_MODE=TEST_RED_ONLY:
517
+ - RED only — add failing tests proving the gap (show failing output excerpt).
518
+ - Do NOT edit production code.
519
+ - Report: TESTS_ADDED, RED_COMMAND_RUN, RED_EVIDENCE, STATUS: DONE|BLOCKED.
520
+ 2) If STAGE_MODE=BUILD_GREEN_REFACTOR:
521
+ - GREEN — minimal production code to satisfy existing RED tests, rerun full suite.
522
+ - REFACTOR — only after full suite is green; preserve behavior.
523
+ - Report: FILES_EDITED, GREEN_COMMAND_RUN, REFACTOR_NOTES, STATUS: DONE|BLOCKED.
524
+ \`\`\`
525
+
526
+ `;
527
+ }
528
+ function docUpdaterEnhancedBody() {
529
+ return `
530
+
531
+ ## Task Tool Delegation
532
+
533
+ For documentation parallelism, still avoid conflicting writes — partition by artifact:
534
+
535
+ \`\`\`
536
+ You are a documentation updater subagent.
537
+
538
+ DOCS SCOPE: {README|API ref|runbook|changelog section}
539
+ SOURCE OF TRUTH: {code paths / flags / env vars that changed}
540
+
541
+ Tasks:
542
+ - Diff mental model vs reality; update only stale sections.
543
+ - Preserve tone/structure; no doc rewrite for its own sake.
544
+ - List FILES_UPDATED + SUMMARY + OPEN_DOC_QUESTIONS (if user input needed).
545
+ \`\`\`
546
+
547
+ `;
548
+ }
549
+ /**
550
+ * Returns markdown fragments augmenting each specialist persona with Task tool
551
+ * delegation guidance. Combine with the existing `body` field from `agents.ts`.
552
+ */
553
+ export function enhancedAgentBody(agentName) {
554
+ switch (agentName) {
555
+ case "planner":
556
+ return plannerEnhancedBody();
557
+ case "spec-reviewer":
558
+ return specReviewerEnhancedBody();
559
+ case "code-reviewer":
560
+ return codeReviewerEnhancedBody();
561
+ case "security-reviewer":
562
+ return securityReviewerEnhancedBody();
563
+ case "test-author":
564
+ return testAuthorEnhancedBody();
565
+ case "doc-updater":
566
+ return docUpdaterEnhancedBody();
567
+ default:
568
+ return `
569
+
570
+ ## Task Tool Delegation
571
+
572
+ _No enhanced Task template is defined for agent \`${agentName}\`._
573
+
574
+ `;
575
+ }
576
+ }
577
+ export function subagentsAgentsMdBlock() {
578
+ return `### Subagent Orchestration
579
+
580
+ Two patterns (skills under \`.cclaw/skills/\`):
581
+
582
+ - **SDD** (subagent-driven-development): sequential implementer→reviewer loops. Paste self-contained task text; never point subagents at plan files.
583
+ - **Parallel Agents** (dispatching-parallel-agents): parallel review/analysis lenses. Never parallelize implementers on same codebase.
584
+
585
+ Status contract: DONE | DONE_WITH_CONCERNS | NEEDS_CONTEXT | BLOCKED.
586
+
587
+ - Controller sequentially dispatches **implementer → reviewer** loops per task.
588
+ - HARD-GATE: paste **self-contained task text**; never point subagents at plan files to “discover” scope.
589
+ - **Spec fixers** are **fresh agents** after failed spec reviews — avoids parent-context pollution.
590
+ - **Machine-only flow checks auto-dispatch** by stage (design/plan/test/build/review/ship) without asking the user to trigger each specialist manually.
591
+
592
+ ### Parallel Agents (\`dispatching-parallel-agents\` skill)
593
+
594
+ - Parallelize **analysis and review lenses** with multiple Task tool calls in one controller turn.
595
+ - HARD-GATE: never run parallel **implementers** on the same codebase; reconcile structured findings afterward.
596
+
597
+ ### Status Contract (SDD)
598
+
599
+ | Status | Meaning |
600
+ |---|---|
601
+ | DONE | Complete; proceed to reviewers |
602
+ | DONE_WITH_CONCERNS | Proceed, but surface notes prominently |
603
+ | NEEDS_CONTEXT | Parent must gather missing info |
604
+ | BLOCKED | Escalate to user; do not improvise |
605
+
606
+ ### Choosing a mode
607
+
608
+ | Scenario | Preferred mode |
609
+ |---|---|
610
+ | Multi-task implementation plan | SDD sequential implementers |
611
+ | Cross-cutting audit with disjoint evidence | Parallel review / investigation agents |
612
+ | Code changes touching same module tree | SDD (single writer at a time) |
613
+
614
+ Use the exported helpers in \`src/content/subagents.ts\` to materialize SKILL bodies and AGENTS.md fragments during install.
615
+ `;
616
+ }
@@ -0,0 +1,3 @@
1
+ export declare const ARTIFACT_TEMPLATES: Record<string, string>;
2
+ export declare const RULEBOOK_MARKDOWN = "# Cclaw Rulebook\n\n## MUST_ALWAYS\n- Follow flow order: brainstorm -> scope -> design -> spec -> plan -> test -> build -> review -> ship\n- Require explicit user confirmation after /plan before /test or /build\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 /test and jump directly to /build\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 function buildRulesJson(): Record<string, unknown>;