cclaw-cli 0.10.1 → 0.12.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 (55) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.d.ts +6 -0
  3. package/dist/cli.js +297 -9
  4. package/dist/config.js +83 -3
  5. package/dist/content/core-agents.d.ts +44 -0
  6. package/dist/content/core-agents.js +225 -0
  7. package/dist/content/doctor-references.d.ts +2 -0
  8. package/dist/content/doctor-references.js +144 -0
  9. package/dist/content/examples.js +1 -1
  10. package/dist/content/harnesses-doc.d.ts +1 -0
  11. package/dist/content/harnesses-doc.js +95 -0
  12. package/dist/content/hook-events.d.ts +4 -0
  13. package/dist/content/hook-events.js +42 -0
  14. package/dist/content/hooks.js +81 -11
  15. package/dist/content/meta-skill.d.ts +0 -8
  16. package/dist/content/meta-skill.js +51 -341
  17. package/dist/content/next-command.js +2 -1
  18. package/dist/content/protocols.d.ts +7 -0
  19. package/dist/content/protocols.js +123 -0
  20. package/dist/content/research-playbooks.d.ts +8 -0
  21. package/dist/content/research-playbooks.js +135 -0
  22. package/dist/content/skills.js +202 -312
  23. package/dist/content/stage-common-guidance.d.ts +2 -0
  24. package/dist/content/stage-common-guidance.js +71 -0
  25. package/dist/content/stage-schema.d.ts +11 -1
  26. package/dist/content/stage-schema.js +155 -52
  27. package/dist/content/start-command.js +19 -13
  28. package/dist/content/subagents.d.ts +1 -1
  29. package/dist/content/subagents.js +23 -38
  30. package/dist/content/templates.d.ts +1 -1
  31. package/dist/content/templates.js +49 -11
  32. package/dist/delegation.d.ts +1 -0
  33. package/dist/delegation.js +27 -1
  34. package/dist/doctor-registry.d.ts +8 -0
  35. package/dist/doctor-registry.js +127 -0
  36. package/dist/doctor.d.ts +5 -0
  37. package/dist/doctor.js +133 -27
  38. package/dist/flow-state.d.ts +4 -0
  39. package/dist/flow-state.js +4 -1
  40. package/dist/gate-evidence.d.ts +9 -1
  41. package/dist/gate-evidence.js +121 -17
  42. package/dist/harness-adapters.d.ts +7 -0
  43. package/dist/harness-adapters.js +53 -9
  44. package/dist/init-detect.d.ts +2 -0
  45. package/dist/init-detect.js +45 -0
  46. package/dist/install.js +73 -1
  47. package/dist/policy.js +21 -13
  48. package/dist/runs.js +21 -4
  49. package/dist/track-heuristics.d.ts +12 -0
  50. package/dist/track-heuristics.js +144 -0
  51. package/dist/types.d.ts +26 -3
  52. package/dist/types.js +6 -3
  53. package/package.json +2 -1
  54. package/dist/content/agents.d.ts +0 -48
  55. package/dist/content/agents.js +0 -411
@@ -5,16 +5,10 @@
5
5
  */
6
6
  const SUBAGENT_AGENT_NAMES = [
7
7
  "planner",
8
- "spec-reviewer",
9
- "code-reviewer",
8
+ "reviewer",
10
9
  "security-reviewer",
11
10
  "test-author",
12
- "doc-updater",
13
- "repo-research-analyst",
14
- "learnings-researcher",
15
- "framework-docs-researcher",
16
- "best-practices-researcher",
17
- "git-history-analyzer",
11
+ "doc-updater"
18
12
  ];
19
13
  export function subagentDrivenDevSkill() {
20
14
  return `---
@@ -40,7 +34,7 @@ For cclaw flow stages, machine-only specialist work should auto-dispatch without
40
34
 
41
35
  - **design/plan:** planner
42
36
  - **tdd:** test-author
43
- - **review:** spec-reviewer + code-reviewer + security-reviewer (security-reviewer is always mandatory; produce an explicit no-change attestation when no trust boundaries moved)
37
+ - **review:** reviewer + security-reviewer (security-reviewer is always mandatory; produce an explicit no-change attestation when no trust boundaries moved)
44
38
  - **ship:** doc-updater
45
39
 
46
40
  Human input remains mandatory only at explicit approval gates (plan approval, user challenge resolution, release finalization mode).
@@ -69,8 +63,8 @@ If delegation tooling is unavailable in the active harness, run the same control
69
63
  | Tier | Use for | Example agents |
70
64
  |---|---|---|
71
65
  | \`deep\` | one heavy reasoning pass per stage (planner, final reconciliation) | planner |
72
- | \`balanced\` | spec compliance + code/security review with enough context | spec-reviewer, code-reviewer, security-reviewer, test-author |
73
- | \`fast\` | read-only research / narrow machine checks / docs updates safe to fan out | repo-research-analyst, learnings-researcher, framework-docs-researcher, best-practices-researcher, git-history-analyzer, doc-updater |
66
+ | \`balanced\` | spec compliance + code/security review with enough context | reviewer, security-reviewer, test-author |
67
+ | \`fast\` | bounded maintenance updates and doc hygiene | doc-updater |
74
68
 
75
69
  **Routing rules:**
76
70
  - At most ONE \`deep\` agent per stage (planner OR final reconciliation, not both).
@@ -84,14 +78,14 @@ Concrete per-stage rules so the controller does not have to guess which tier fit
84
78
 
85
79
  | Stage | Deep slot | Balanced slot(s) | Fast fan-out | Trigger to escalate |
86
80
  |---|---|---|---|---|
87
- | brainstorm | planner (only if ambiguity spans >1 module) | — | repo-research-analyst · learnings-researcher (2 in parallel) | promote to \`balanced\` spec-reviewer once direction locks |
88
- | scope | planner (always) | — | git-history-analyzer (if churn / recent regression on the surface) | promote to \`balanced\` planner if scope touches external contracts |
89
- | design | planner (always) | security-reviewer (if trust boundary touched) | framework-docs-researcher · best-practices-researcher (up to 2 in parallel) | escalate one specialist to \`deep\` only if a failure mode is Critical-severity |
90
- | spec | — | spec-reviewer (if spec > 200 lines or multiple ACs) | — | escalate to \`deep\` only for spec ↔ design contradictions |
81
+ | brainstorm | planner (only if ambiguity spans >1 module) | — | run in-thread research playbooks | promote to \`balanced\` reviewer once direction locks |
82
+ | scope | planner (always) | — | run \`research/git-history.md\` in-thread when churn is high | promote to \`balanced\` planner if scope touches external contracts |
83
+ | design | planner (always) | security-reviewer (if trust boundary touched) | run \`research/framework-docs-lookup.md\` + \`research/best-practices-lookup.md\` in-thread | escalate one specialist to \`deep\` only if a failure mode is Critical-severity |
84
+ | spec | — | reviewer (if spec > 200 lines or multiple ACs) | — | escalate to \`deep\` only for spec ↔ design contradictions |
91
85
  | plan | planner (solo, always) | — | — | never fan out at plan stage; one owner for dependency graph |
92
- | tdd | — | test-author (each slice) · code-reviewer (slice-local) | doc-updater (API surface changes) | escalate to \`deep\` only when a RED test cannot be expressed (design leak) |
93
- | review | — | spec-reviewer · code-reviewer · security-reviewer (all mandatory) | doc-updater + framework-docs-researcher for narrow lookups | escalate a \`balanced\` reviewer to \`deep\` only when two reviewers disagree on severity |
94
- | ship | — | | doc-updater (changelog/migration notes) | escalate to \`balanced\` code-reviewer only if preflight finds a regression |
86
+ | tdd | — | test-author (each slice) · reviewer (slice-local) | doc-updater (API surface changes) | escalate to \`deep\` only when a RED test cannot be expressed (design leak) |
87
+ | review | — | reviewer · security-reviewer (both mandatory) | doc-updater for release-note drift checks | escalate a \`balanced\` reviewer to \`deep\` only when two reviewers disagree on severity |
88
+ | ship | — | security-reviewer (if blast radius is high) | doc-updater (changelog/migration notes) | escalate to \`balanced\` reviewer only if preflight finds a regression |
95
89
 
96
90
  **De-escalation rules (avoid over-spending):**
97
91
  - If a \`deep\` planner run returns low-uncertainty output (single unambiguous plan), do **not** add a second \`deep\` pass in the same stage.
@@ -121,7 +115,7 @@ If you catch yourself writing “read PLAN.md Task 3” or “implement the next
121
115
  2. **For each task sequentially (NEVER parallel implementation subagents — file conflicts):**
122
116
  1. **Dispatch implementer subagent** with the **full task text pasted in** (not a file reference).
123
117
  2. **Check return status:** \`DONE\` / \`DONE_WITH_CONCERNS\` / \`NEEDS_CONTEXT\` / \`BLOCKED\`
124
- 3. If \`DONE\`: dispatch **spec-reviewer** subagent to verify actual code matches spec.
118
+ 3. If \`DONE\`: dispatch **reviewer** subagent to verify actual code matches spec and quality expectations.
125
119
  4. If spec review **FAIL**: dispatch **fixer subagent** (a **new** agent — not an inline patch from the parent — to avoid context pollution).
126
120
  5. Dispatch **code-quality reviewer** (maintainability/PR hygiene).
127
121
  6. **Mark task complete** only after concerns are triaged or explicitly accepted with rationale.
@@ -350,7 +344,7 @@ Write a structured reconciliation artifact at \`.cclaw/artifacts/07-review-army.
350
344
  "severity": "Critical|Important|Suggestion",
351
345
  "confidence": 1,
352
346
  "fingerprint": "hash-or-stable-key",
353
- "reportedBy": ["spec-reviewer", "code-reviewer"],
347
+ "reportedBy": ["reviewer", "security-reviewer"],
354
348
  "status": "open|accepted|resolved",
355
349
  "location": { "file": "path", "line": 123 },
356
350
  "recommendation": "..."
@@ -501,7 +495,7 @@ function specReviewerEnhancedBody() {
501
495
 
502
496
  ## Task Tool Delegation
503
497
 
504
- For spec-compliance audits, use the Task tool with the following **spec-reviewer** payload (fill placeholders in the parent session).
498
+ For review audits, use the Task tool with the following **reviewer** payload (fill placeholders in the parent session).
505
499
 
506
500
  \`\`\`
507
501
  You are a specification compliance reviewer (subagent).
@@ -544,6 +538,9 @@ Output format (mandatory):
544
538
 
545
539
  `;
546
540
  }
541
+ function reviewerEnhancedBody() {
542
+ return `${specReviewerEnhancedBody()}${codeReviewerEnhancedBody()}`;
543
+ }
547
544
  function securityReviewerEnhancedBody() {
548
545
  return `
549
546
 
@@ -603,7 +600,7 @@ function repoResearchAnalystEnhancedBody() {
603
600
 
604
601
  ## Task Tool Delegation
605
602
 
606
- Launch **read-only repo exploration** at the start of brainstorm/scope/design so the primary agent plans on a grounded map, not guesses. Run as a \`fast\` tier agent — cheap to fan out alongside learnings-researcher and best-practices-researcher.
603
+ Launch **read-only repo exploration** at the start of brainstorm/scope/design so the primary agent plans on a grounded map, not guesses. Use this as an in-thread research procedure.
607
604
 
608
605
  \`\`\`
609
606
  You are a repo research analyst subagent.
@@ -761,32 +758,20 @@ Tasks:
761
758
  }
762
759
  /**
763
760
  * Returns markdown fragments augmenting each specialist persona with Task tool
764
- * delegation guidance. Combine with the existing `body` field from `agents.ts`.
761
+ * delegation guidance. Combine with the existing `body` field from `core-agents.ts`.
765
762
  */
766
763
  export function enhancedAgentBody(agentName) {
767
764
  switch (agentName) {
768
765
  case "planner":
769
766
  return plannerEnhancedBody();
770
- case "spec-reviewer":
771
- return specReviewerEnhancedBody();
772
- case "code-reviewer":
773
- return codeReviewerEnhancedBody();
767
+ case "reviewer":
768
+ return reviewerEnhancedBody();
774
769
  case "security-reviewer":
775
770
  return securityReviewerEnhancedBody();
776
771
  case "test-author":
777
772
  return testAuthorEnhancedBody();
778
773
  case "doc-updater":
779
774
  return docUpdaterEnhancedBody();
780
- case "repo-research-analyst":
781
- return repoResearchAnalystEnhancedBody();
782
- case "learnings-researcher":
783
- return learningsResearcherEnhancedBody();
784
- case "framework-docs-researcher":
785
- return frameworkDocsResearcherEnhancedBody();
786
- case "best-practices-researcher":
787
- return bestPracticesResearcherEnhancedBody();
788
- case "git-history-analyzer":
789
- return gitHistoryAnalyzerEnhancedBody();
790
775
  default:
791
776
  return `
792
777
 
@@ -809,7 +794,7 @@ Status contract: DONE | DONE_WITH_CONCERNS | NEEDS_CONTEXT | BLOCKED.
809
794
 
810
795
  - Controller sequentially dispatches **implementer → reviewer** loops per task.
811
796
  - HARD-GATE: paste **self-contained task text**; never point subagents at plan files to “discover” scope.
812
- - **Spec fixers** are **fresh agents** after failed spec reviews — avoids parent-context pollution.
797
+ - **Review fixers** are **fresh agents** after failed review passes — avoids parent-context pollution.
813
798
  - **Machine-only flow checks auto-dispatch** by stage (design/plan/tdd/review/ship) without asking the user to trigger each specialist manually.
814
799
 
815
800
  ### Parallel Agents (\`dispatching-parallel-agents\` skill)
@@ -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/`; 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";
3
+ export declare const CURSOR_WORKFLOW_RULE_MDC = "---\ndescription: cclaw workflow guardrails for Cursor agent sessions\nglobs:\n - \"**/*\"\nalwaysApply: true\n---\n\n<!-- cclaw-managed-cursor-workflow-rule -->\n\n# Cclaw Workflow Guardrails\n\n## Activation Rule\n\nBefore responding to coding work:\n1. Read `.cclaw/state/flow-state.json`.\n2. Start with `/cc` or continue with `/cc-next`.\n3. If no software-stage flow applies, respond normally.\n\n## Stage Order\n\n`brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship`\n\nTrack-specific skips are allowed only when `flow-state.track` + `skippedStages` explicitly say so.\n\n## Task Classification\n\n| Class | Route |\n|---|---|\n| non-trivial software work | `/cc <idea>` |\n| trivial software fix | `/cc <idea>` (quick or medium track) |\n| bugfix with repro | `/cc <idea>` and enforce RED-first in tdd |\n| pure question / non-software | direct answer (no stage flow) |\n\n## Command Surface\n\n- `/cc` = entry and resume.\n- `/cc-next` = only progression path.\n- `/cc-learn` = knowledge capture and recall.\n\n## Verification Discipline\n\n- No completion claim without fresh command evidence in this turn.\n- Do not mark gates passed from memory.\n- Keep evidence in `.cclaw/artifacts/`; archive only via `cclaw archive`.\n\n## Delegation And Approvals\n\n- Machine-only checks in design/plan/tdd/review/ship should auto-dispatch when tooling supports it.\n- Ask for user input only at explicit approval gates (scope mode, plan approval, challenge resolution, ship finalization).\n- If harness capabilities are partial, record waiver reasons in delegation logs.\n\n## Routing Source Of Truth\n\n- Primary router: `.cclaw/skills/using-cclaw/SKILL.md`.\n- Protocols: `.cclaw/references/protocols/*.md`.\n- Preamble budget: `.cclaw/references/protocols/ethos.md`.\n";
4
4
  export declare function buildRulesJson(): Record<string, unknown>;
@@ -386,11 +386,11 @@ Execution rule: complete and verify each wave before starting the next wave.
386
386
 
387
387
  | Pass | Status | Completed at (UTC) | Reviewer / source | Commit at review | Drift vs HEAD |
388
388
  |---|---|---|---|---|---|
389
- | Layer 1 — spec compliance | pass / fail / pending | <ISO 8601> | spec-reviewer | <short sha> | <files changed since> |
390
- | Layer 2 — correctness | pass / fail / pending | <ISO 8601> | code-reviewer | <short sha> | <files changed since> |
389
+ | Layer 1 — spec compliance | pass / fail / pending | <ISO 8601> | reviewer | <short sha> | <files changed since> |
390
+ | Layer 2 — correctness | pass / fail / pending | <ISO 8601> | reviewer | <short sha> | <files changed since> |
391
391
  | Layer 2 — security | pass / fail / pending | <ISO 8601> | security-reviewer | <short sha> | <files changed since> |
392
- | Layer 2 — performance | pass / fail / pending | <ISO 8601> | code-reviewer | <short sha> | <files changed since> |
393
- | Layer 2 — architecture | pass / fail / pending | <ISO 8601> | code-reviewer | <short sha> | <files changed since> |
392
+ | Layer 2 — performance | pass / fail / pending | <ISO 8601> | reviewer | <short sha> | <files changed since> |
393
+ | Layer 2 — architecture | pass / fail / pending | <ISO 8601> | reviewer | <short sha> | <files changed since> |
394
394
  | Adversarial review | pass / fail / n/a | <ISO 8601 or —> | adversarial-review skill | <short sha or —> | <drift or —> |
395
395
  | Review army schema valid | pass / fail | <ISO 8601> | jsonschema | <short sha> | n/a |
396
396
 
@@ -531,13 +531,51 @@ alwaysApply: true
531
531
 
532
532
  # Cclaw Workflow Guardrails
533
533
 
534
- - Follow stage order: brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship.
535
- - Read \`.cclaw/state/flow-state.json\` before acting; continue from current stage when active.
536
- - Use \`/cc-next\` only after required gates pass; never bypass explicit pause/approval rules.
537
- - Keep evidence in \`.cclaw/artifacts/\`; archive completed feature artifacts only via \`cclaw archive\`.
538
- - For machine-only checks in design/plan/tdd/review/ship, dispatch required specialists automatically when tooling supports it.
539
- - Ask for user input only at explicit approval gates (scope mode, plan approval, user challenge resolution, ship finalization).
540
- - Treat \`.cclaw/skills/using-cclaw/SKILL.md\` as routing source of truth; load contextual utility skills only when their triggers apply.
534
+ ## Activation Rule
535
+
536
+ Before responding to coding work:
537
+ 1. Read \`.cclaw/state/flow-state.json\`.
538
+ 2. Start with \`/cc\` or continue with \`/cc-next\`.
539
+ 3. If no software-stage flow applies, respond normally.
540
+
541
+ ## Stage Order
542
+
543
+ \`brainstorm -> scope -> design -> spec -> plan -> tdd -> review -> ship\`
544
+
545
+ Track-specific skips are allowed only when \`flow-state.track\` + \`skippedStages\` explicitly say so.
546
+
547
+ ## Task Classification
548
+
549
+ | Class | Route |
550
+ |---|---|
551
+ | non-trivial software work | \`/cc <idea>\` |
552
+ | trivial software fix | \`/cc <idea>\` (quick or medium track) |
553
+ | bugfix with repro | \`/cc <idea>\` and enforce RED-first in tdd |
554
+ | pure question / non-software | direct answer (no stage flow) |
555
+
556
+ ## Command Surface
557
+
558
+ - \`/cc\` = entry and resume.
559
+ - \`/cc-next\` = only progression path.
560
+ - \`/cc-learn\` = knowledge capture and recall.
561
+
562
+ ## Verification Discipline
563
+
564
+ - No completion claim without fresh command evidence in this turn.
565
+ - Do not mark gates passed from memory.
566
+ - Keep evidence in \`.cclaw/artifacts/\`; archive only via \`cclaw archive\`.
567
+
568
+ ## Delegation And Approvals
569
+
570
+ - Machine-only checks in design/plan/tdd/review/ship should auto-dispatch when tooling supports it.
571
+ - Ask for user input only at explicit approval gates (scope mode, plan approval, challenge resolution, ship finalization).
572
+ - If harness capabilities are partial, record waiver reasons in delegation logs.
573
+
574
+ ## Routing Source Of Truth
575
+
576
+ - Primary router: \`.cclaw/skills/using-cclaw/SKILL.md\`.
577
+ - Protocols: \`.cclaw/references/protocols/*.md\`.
578
+ - Preamble budget: \`.cclaw/references/protocols/ethos.md\`.
541
579
  `;
542
580
  export function buildRulesJson() {
543
581
  return {
@@ -28,5 +28,6 @@ export declare function checkMandatoryDelegations(projectRoot: string, stage: Fl
28
28
  satisfied: boolean;
29
29
  missing: string[];
30
30
  waived: string[];
31
+ autoWaived: string[];
31
32
  staleIgnored: string[];
32
33
  }>;
@@ -1,7 +1,9 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { RUNTIME_ROOT } from "./constants.js";
4
+ import { readConfig } from "./config.js";
4
5
  import { exists, withDirectoryLock, writeFileSafe } from "./fs-utils.js";
6
+ import { HARNESS_ADAPTERS } from "./harness-adapters.js";
5
7
  import { readFlowState } from "./runs.js";
6
8
  import { stageSchema } from "./content/stage-schema.js";
7
9
  function delegationLogPath(projectRoot) {
@@ -84,11 +86,34 @@ export async function checkMandatoryDelegations(projectRoot, stage) {
84
86
  .map((e) => `${e.agent}(runId=${e.runId ?? "unknown"})`);
85
87
  const missing = [];
86
88
  const waived = [];
89
+ const autoWaived = [];
90
+ const config = await readConfig(projectRoot).catch(() => null);
91
+ const harnesses = config?.harnesses ?? [];
92
+ const nativeDelegationUnavailable = harnesses.length > 0 &&
93
+ harnesses.every((harness) => HARNESS_ADAPTERS[harness].capabilities.nativeSubagentDispatch === "none");
87
94
  for (const agent of mandatory) {
88
95
  const rows = forRun.filter((e) => e.agent === agent);
89
96
  const ok = rows.some((e) => e.status === "completed" || e.status === "waived");
90
97
  if (!ok) {
91
- missing.push(agent);
98
+ if (nativeDelegationUnavailable) {
99
+ const existingHarnessWaiver = rows.some((e) => e.status === "waived" && e.waiverReason === "harness_limitation");
100
+ if (!existingHarnessWaiver) {
101
+ await appendDelegation(projectRoot, {
102
+ stage,
103
+ agent,
104
+ mode: "mandatory",
105
+ status: "waived",
106
+ waiverReason: "harness_limitation",
107
+ ts: new Date().toISOString(),
108
+ runId: activeRunId
109
+ });
110
+ }
111
+ waived.push(agent);
112
+ autoWaived.push(agent);
113
+ }
114
+ else {
115
+ missing.push(agent);
116
+ }
92
117
  }
93
118
  else if (rows.some((e) => e.status === "waived")) {
94
119
  waived.push(agent);
@@ -98,6 +123,7 @@ export async function checkMandatoryDelegations(projectRoot, stage) {
98
123
  satisfied: missing.length === 0,
99
124
  missing,
100
125
  waived,
126
+ autoWaived,
101
127
  staleIgnored
102
128
  };
103
129
  }
@@ -0,0 +1,8 @@
1
+ export type DoctorSeverity = "error" | "warning" | "info";
2
+ export interface DoctorCheckMetadata {
3
+ severity: DoctorSeverity;
4
+ summary: string;
5
+ fix: string;
6
+ docRef?: string;
7
+ }
8
+ export declare function doctorCheckMetadata(checkName: string): DoctorCheckMetadata;
@@ -0,0 +1,127 @@
1
+ import { DOCTOR_REFERENCE_DIR } from "./content/doctor-references.js";
2
+ function ref(fileName) {
3
+ return `${DOCTOR_REFERENCE_DIR}/${fileName}`;
4
+ }
5
+ const RULES = [
6
+ {
7
+ test: /^gates:reconcile:writeback$/,
8
+ metadata: {
9
+ severity: "info",
10
+ summary: "Gate reconciliation status update.",
11
+ fix: "No action required unless subsequent gate checks fail.",
12
+ docRef: ref("state-and-gates.md")
13
+ }
14
+ },
15
+ {
16
+ test: /^warning:/,
17
+ metadata: {
18
+ severity: "warning",
19
+ summary: "Advisory signal; runtime can continue with caution.",
20
+ fix: "Address when possible to prevent future drift or degraded behavior.",
21
+ docRef: ref("README.md")
22
+ }
23
+ },
24
+ {
25
+ test: /^skill:.*:(max_lines|min_lines|canonical_sections)$/,
26
+ metadata: {
27
+ severity: "warning",
28
+ summary: "Stage skill quality guardrail check.",
29
+ fix: "Tune generated stage skill content and re-run `cclaw sync`.",
30
+ docRef: ref("runtime-layout.md")
31
+ }
32
+ },
33
+ {
34
+ test: /^capability:runtime:json_parser$/,
35
+ metadata: {
36
+ severity: "warning",
37
+ summary: "Optional JSON fallback parser availability.",
38
+ fix: "Install at least one of `python3` or `jq` for resilient fallback parsing.",
39
+ docRef: ref("tooling-capabilities.md")
40
+ }
41
+ },
42
+ {
43
+ test: /^capability:required:/,
44
+ metadata: {
45
+ severity: "error",
46
+ summary: "Required runtime tooling availability check.",
47
+ fix: "Install the missing required tool and re-run `cclaw doctor`.",
48
+ docRef: ref("tooling-capabilities.md")
49
+ }
50
+ },
51
+ {
52
+ test: /^(dir:|command:|utility_command:|skill:|utility_skill:|agent:|harness_tool_ref:|harness_ref:|stage_examples_ref:|doctor_ref:)/,
53
+ metadata: {
54
+ severity: "error",
55
+ summary: "Generated runtime surface presence check.",
56
+ fix: "Run `cclaw sync` to regenerate runtime files, then re-run doctor.",
57
+ docRef: ref("runtime-layout.md")
58
+ }
59
+ },
60
+ {
61
+ test: /^(hook:|lifecycle:|git_hooks:)/,
62
+ metadata: {
63
+ severity: "error",
64
+ summary: "Hook wiring and lifecycle integration check.",
65
+ fix: "Repair hook/plugin wiring (usually via `cclaw sync`) and validate harness config.",
66
+ docRef: ref("hooks-and-lifecycle.md")
67
+ }
68
+ },
69
+ {
70
+ test: /^(shim:|agents:cclaw_block|rules:cursor:workflow)/,
71
+ metadata: {
72
+ severity: "error",
73
+ summary: "Harness shim and routing file consistency check.",
74
+ fix: "Regenerate harness adapters via `cclaw sync`; confirm enabled harness list.",
75
+ docRef: ref("harness-and-routing.md")
76
+ }
77
+ },
78
+ {
79
+ test: /^(flow_state:|state:|contexts:|gates:)/,
80
+ metadata: {
81
+ severity: "error",
82
+ summary: "Flow state and gate evidence consistency check.",
83
+ fix: "Repair flow-state artifacts and gate evidence, then run `cclaw doctor --reconcile-gates`.",
84
+ docRef: ref("state-and-gates.md")
85
+ }
86
+ },
87
+ {
88
+ test: /^delegation:/,
89
+ metadata: {
90
+ severity: "error",
91
+ summary: "Mandatory delegation completion check.",
92
+ fix: "Complete or explicitly waive missing mandatory delegations in delegation log.",
93
+ docRef: ref("delegation-and-preamble.md")
94
+ }
95
+ },
96
+ {
97
+ test: /^trace:/,
98
+ metadata: {
99
+ severity: "error",
100
+ summary: "Cross-artifact traceability integrity check.",
101
+ fix: "Restore criterion/task/test ID mappings across spec, plan, and tdd artifacts.",
102
+ docRef: ref("traceability.md")
103
+ }
104
+ },
105
+ {
106
+ test: /^(config:|rules:policy_schema|language_rule_pack:|gitignore:|git:)/,
107
+ metadata: {
108
+ severity: "error",
109
+ summary: "Config or policy schema consistency check.",
110
+ fix: "Fix config/rules drift, then run `cclaw sync` and re-run doctor.",
111
+ docRef: ref("config-and-policy.md")
112
+ }
113
+ }
114
+ ];
115
+ export function doctorCheckMetadata(checkName) {
116
+ for (const rule of RULES) {
117
+ if (rule.test.test(checkName)) {
118
+ return { ...rule.metadata };
119
+ }
120
+ }
121
+ return {
122
+ severity: "error",
123
+ summary: "Doctor runtime integrity check.",
124
+ fix: "Inspect check details, apply the suggested remediation, and re-run `cclaw doctor`.",
125
+ docRef: ref("README.md")
126
+ };
127
+ }
package/dist/doctor.d.ts CHANGED
@@ -1,7 +1,12 @@
1
+ import type { DoctorSeverity } from "./doctor-registry.js";
1
2
  export interface DoctorCheck {
2
3
  name: string;
3
4
  ok: boolean;
4
5
  details: string;
6
+ severity: DoctorSeverity;
7
+ summary: string;
8
+ fix: string;
9
+ docRef?: string;
5
10
  }
6
11
  export interface DoctorOptions {
7
12
  /** When true, normalize current-stage gate catalog and persist reconciliation before checks. */