compound-agent 1.0.0 → 1.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.
package/dist/cli.js CHANGED
@@ -1530,11 +1530,11 @@ var SEVERITY_LABELS = {
1530
1530
  info: "INFO"
1531
1531
  };
1532
1532
  function loadRuleConfig(baseDir) {
1533
- const configPath = join(baseDir, ".claude", "rules.json");
1534
- if (!existsSync(configPath)) {
1533
+ const configPath2 = join(baseDir, ".claude", "rules.json");
1534
+ if (!existsSync(configPath2)) {
1535
1535
  return { rules: [] };
1536
1536
  }
1537
- const raw = readFileSync(configPath, "utf-8");
1537
+ const raw = readFileSync(configPath2, "utf-8");
1538
1538
  const json = JSON.parse(raw);
1539
1539
  return RuleConfigSchema.parse(json);
1540
1540
  }
@@ -1838,68 +1838,15 @@ CLI commands are for manual/terminal use when MCP is unavailable:
1838
1838
  See [documentation](https://github.com/Nathandela/compound_agent) for more details.
1839
1839
  ${AGENTS_SECTION_END_MARKER}
1840
1840
  `;
1841
- var SLASH_COMMANDS = {
1842
- "learn.md": `Capture a lesson from this session.
1843
-
1844
- Usage: /learn <insight>
1845
-
1846
- Examples:
1847
- - /learn "Always use Polars for large CSV files"
1848
- - /learn "API requires X-Request-ID header"
1849
-
1850
- \`\`\`bash
1851
- npx ca learn "$ARGUMENTS"
1852
- \`\`\`
1853
- `,
1854
- "search.md": `Search lessons for relevant context.
1855
-
1856
- Usage: /search <query>
1857
-
1858
- Examples:
1859
- - /search "API authentication"
1860
- - /search "data processing patterns"
1861
-
1862
- \`\`\`bash
1863
- npx ca search "$ARGUMENTS"
1864
- \`\`\`
1865
-
1866
- Note: You can also use the \`memory_search\` MCP tool directly.
1867
- `,
1868
- "list.md": `Show all stored lessons.
1869
-
1870
- \`\`\`bash
1871
- npx ca list
1872
- \`\`\`
1873
- `,
1874
- "prime.md": `Load compound-agent workflow context after compaction or context loss.
1875
-
1876
- \`\`\`bash
1877
- npx ca prime
1878
- \`\`\`
1879
- `,
1880
- "show.md": `Show details of a specific lesson.
1881
-
1882
- Usage: /show <lesson-id>
1883
-
1884
- \`\`\`bash
1885
- npx ca show "$ARGUMENTS"
1886
- \`\`\`
1887
- `,
1888
- "wrong.md": `Mark a lesson as incorrect or invalid.
1889
-
1890
- Usage: /wrong <lesson-id>
1891
-
1892
- \`\`\`bash
1893
- npx ca wrong "$ARGUMENTS"
1894
- \`\`\`
1895
- `,
1896
- "stats.md": `Show compound-agent database statistics and health.
1897
-
1898
- \`\`\`bash
1899
- npx ca stats
1900
- \`\`\`
1901
- `
1902
- };
1841
+ var LEGACY_ROOT_SLASH_COMMANDS = [
1842
+ "learn.md",
1843
+ "search.md",
1844
+ "list.md",
1845
+ "prime.md",
1846
+ "show.md",
1847
+ "wrong.md",
1848
+ "stats.md"
1849
+ ];
1903
1850
  var PLUGIN_MANIFEST = {
1904
1851
  name: "compound-agent",
1905
1852
  description: "Session memory for Claude Code - capture and retrieve lessons",
@@ -2165,6 +2112,128 @@ async function removeClaudeMdReference(repoRoot) {
2165
2112
  return true;
2166
2113
  }
2167
2114
 
2115
+ // src/setup/templates/agents-external.ts
2116
+ var EXTERNAL_AGENT_TEMPLATES = {
2117
+ "external-reviewer-gemini.md": `---
2118
+ name: External Reviewer (Gemini)
2119
+ description: Cross-model review using Gemini CLI in headless mode
2120
+ model: sonnet
2121
+ ---
2122
+
2123
+ # External Reviewer \u2014 Gemini
2124
+
2125
+ ## Role
2126
+ Run a cross-model code review by invoking the Gemini CLI in headless mode. Provides an independent perspective from a different LLM to catch issues Claude may miss.
2127
+
2128
+ ## Prerequisites
2129
+ - Gemini CLI installed (\`npm i -g @google/gemini-cli\`)
2130
+ - Authenticated (\`gemini auth login\`)
2131
+
2132
+ ## Instructions
2133
+ 1. **Check availability** \u2014 run \`command -v gemini\` via Bash. If not found, report "Gemini CLI not installed \u2014 skipping external review" and stop.
2134
+ 2. **Gather context**:
2135
+ - Get the beads issue being worked on: \`bd list --status=in_progress\` then \`bd show <id>\` to get the issue title and description.
2136
+ - Get the diff: \`git diff HEAD~1\` (or the appropriate range for this session's changes).
2137
+ 3. **Build the review prompt** combining beads context + diff:
2138
+ \`\`\`
2139
+ ISSUE: <title>
2140
+ DESCRIPTION: <description>
2141
+ DIFF:
2142
+ <git diff output>
2143
+
2144
+ Review these changes for:
2145
+ 1. Correctness bugs and logic errors
2146
+ 2. Security vulnerabilities
2147
+ 3. Missed edge cases
2148
+ 4. Code quality issues
2149
+ Output a numbered list of findings. Be concise and actionable. Skip praise.
2150
+ \`\`\`
2151
+ 4. **Call Gemini headless**:
2152
+ \`\`\`bash
2153
+ echo "<prompt>" | gemini -p "Review the following code changes" --output-format json
2154
+ \`\`\`
2155
+ 5. **Parse the response** \u2014 extract the \`.response\` field from the JSON output.
2156
+ 6. **Present findings** to the user as a numbered list with severity tags (P1/P2/P3).
2157
+ 7. **If Gemini returns an error** (auth failure, rate limit, timeout), report the error and skip gracefully. Never block the pipeline on external reviewer failure.
2158
+
2159
+ ## Output Format
2160
+ \`\`\`
2161
+ ## Gemini External Review
2162
+
2163
+ **Status**: Completed | Skipped (reason)
2164
+ **Findings**: N items
2165
+
2166
+ 1. [P2] <finding description> \u2014 <file:line>
2167
+ 2. [P3] <finding description> \u2014 <file:line>
2168
+ ...
2169
+ \`\`\`
2170
+
2171
+ ## Important
2172
+ - This is **advisory, not blocking**. Findings inform but do not gate the pipeline.
2173
+ - Do NOT retry more than once on failure.
2174
+ - Do NOT feed the entire codebase \u2014 only the diff and issue context.
2175
+ `,
2176
+ "external-reviewer-codex.md": `---
2177
+ name: External Reviewer (Codex)
2178
+ description: Cross-model review using OpenAI Codex CLI in headless mode
2179
+ model: sonnet
2180
+ ---
2181
+
2182
+ # External Reviewer \u2014 Codex
2183
+
2184
+ ## Role
2185
+ Run a cross-model code review by invoking the OpenAI Codex CLI in headless exec mode. Provides an independent perspective from OpenAI's reasoning models to catch issues Claude may miss.
2186
+
2187
+ ## Prerequisites
2188
+ - Codex CLI installed (\`npm i -g @openai/codex\`)
2189
+ - Authenticated (\`codex login --api-key\`)
2190
+
2191
+ ## Instructions
2192
+ 1. **Check availability** \u2014 run \`command -v codex\` via Bash. If not found, report "Codex CLI not installed \u2014 skipping external review" and stop.
2193
+ 2. **Gather context**:
2194
+ - Get the beads issue being worked on: \`bd list --status=in_progress\` then \`bd show <id>\` to get the issue title and description.
2195
+ - Get the diff: \`git diff HEAD~1\` (or the appropriate range for this session's changes).
2196
+ 3. **Build the review prompt** combining beads context + diff:
2197
+ \`\`\`
2198
+ ISSUE: <title>
2199
+ DESCRIPTION: <description>
2200
+ DIFF:
2201
+ <git diff output>
2202
+
2203
+ Review these changes for:
2204
+ 1. Correctness bugs and logic errors
2205
+ 2. Security vulnerabilities
2206
+ 3. Missed edge cases
2207
+ 4. Code quality issues
2208
+ Output a numbered list of findings. Be concise and actionable. Skip praise.
2209
+ \`\`\`
2210
+ 4. **Call Codex headless**:
2211
+ \`\`\`bash
2212
+ echo "<prompt>" | codex exec --quiet "Review the following code changes for bugs, security issues, and missed edge cases"
2213
+ \`\`\`
2214
+ 5. **Parse the response** \u2014 Codex exec prints the final answer to stdout.
2215
+ 6. **Present findings** to the user as a numbered list with severity tags (P1/P2/P3).
2216
+ 7. **If Codex returns an error** (auth failure, rate limit, timeout), report the error and skip gracefully. Never block the pipeline on external reviewer failure.
2217
+
2218
+ ## Output Format
2219
+ \`\`\`
2220
+ ## Codex External Review
2221
+
2222
+ **Status**: Completed | Skipped (reason)
2223
+ **Findings**: N items
2224
+
2225
+ 1. [P2] <finding description> \u2014 <file:line>
2226
+ 2. [P3] <finding description> \u2014 <file:line>
2227
+ ...
2228
+ \`\`\`
2229
+
2230
+ ## Important
2231
+ - This is **advisory, not blocking**. Findings inform but do not gate the pipeline.
2232
+ - Do NOT retry more than once on failure.
2233
+ - Do NOT feed the entire codebase \u2014 only the diff and issue context.
2234
+ `
2235
+ };
2236
+
2168
2237
  // src/setup/templates/agents-phase11.ts
2169
2238
  var PHASE11_AGENT_TEMPLATES = {
2170
2239
  "compounding.md": `---
@@ -2806,7 +2875,8 @@ Call \`memory_search\` with the task description for known patterns, solutions,
2806
2875
  var AGENT_TEMPLATES = {
2807
2876
  ...REVIEW_AGENT_TEMPLATES,
2808
2877
  ...WORKFLOW_AGENT_TEMPLATES,
2809
- ...PHASE11_AGENT_TEMPLATES
2878
+ ...PHASE11_AGENT_TEMPLATES,
2879
+ ...EXTERNAL_AGENT_TEMPLATES
2810
2880
  };
2811
2881
 
2812
2882
  // src/setup/templates/commands.ts
@@ -2821,9 +2891,15 @@ Explore requirements through collaborative dialogue before committing to a plan.
2821
2891
  ## Workflow
2822
2892
  1. Parse the topic from \`$ARGUMENTS\`. If empty, ask the user what to brainstorm.
2823
2893
  2. Call \`memory_search\` with the topic to surface relevant past lessons. Display retrieved items and incorporate them into exploration.
2824
- 3. Spawn Explore subagents to research existing context:
2825
- - **docs-explorer**: scan \`docs/\` for architecture docs, specs, research, standards, anti-patterns, and existing ADRs in \`docs/decisions/\`
2826
- - **code-explorer**: quick codebase research on areas relevant to the brainstorm
2894
+ 3. Create a research team and spawn explorers in parallel:
2895
+ \`\`\`
2896
+ TeamCreate: team_name="brainstorm-<topic-slug>"
2897
+ Task: name="docs-explorer", subagent_type="Explore", team_name="brainstorm-<topic-slug>"
2898
+ prompt: "Scan docs/ for architecture docs, specs, research, standards, anti-patterns, and existing ADRs in docs/decisions/"
2899
+ Task: name="code-explorer", subagent_type="Explore", team_name="brainstorm-<topic-slug>"
2900
+ prompt: "Research codebase areas relevant to: <topic>"
2901
+ \`\`\`
2902
+ Wait for both teammates to report findings, then synthesize.
2827
2903
  4. Use \`AskUserQuestion\` to clarify scope, constraints, and preferences through structured dialogue.
2828
2904
  5. Explore edge cases and failure modes.
2829
2905
  6. Propose 2-3 alternative approaches with tradeoffs.
@@ -2876,10 +2952,17 @@ Create a structured implementation plan enriched by semantic memory and existing
2876
2952
  1. Parse the goal from \`$ARGUMENTS\`. If empty, ask the user what to plan.
2877
2953
  2. Check for brainstorm output: run \`bd list\` to find a related brainstorm epic. If one exists, read its description for decisions and open questions.
2878
2954
  3. Call \`memory_search\` with the goal to retrieve relevant past lessons. Display retrieved memory items and incorporate them into planning context.
2879
- 4. Spawn research agent team:
2880
- - **Docs Analyst** (\`docs-analyst\`): scan \`docs/\` for specs, standards, anti-patterns, and ADRs in \`docs/decisions/\` that constrain the plan
2881
- - **Repo Analyst** (\`repo-analyst\`): explore codebase patterns, conventions, and architecture
2882
- - **Memory Analyst** (\`memory-analyst\`): deep dive into related memory items with multiple search queries
2955
+ 4. Create a research team and spawn analysts in parallel:
2956
+ \`\`\`
2957
+ TeamCreate: team_name="plan-<goal-slug>"
2958
+ Task: name="docs-analyst", subagent_type="Explore", team_name="plan-<goal-slug>"
2959
+ prompt: "Scan docs/ for specs, standards, anti-patterns, and ADRs in docs/decisions/ that constrain the plan for: <goal>"
2960
+ Task: name="repo-analyst", subagent_type="Explore", team_name="plan-<goal-slug>"
2961
+ prompt: "Explore codebase patterns, conventions, and architecture relevant to: <goal>"
2962
+ Task: name="memory-analyst", subagent_type="general-purpose", team_name="plan-<goal-slug>"
2963
+ prompt: "Deep dive into related memory items with multiple memory_search queries for: <goal>"
2964
+ \`\`\`
2965
+ Wait for all teammates to report findings, then synthesize.
2883
2966
  5. Synthesize research findings from all agents into a coherent plan. Flag any conflicts between ADRs and proposed approach.
2884
2967
  6. Use \`AskUserQuestion\` to resolve ambiguities: unclear requirements, conflicting ADRs, or priority trade-offs that need user input before decomposing.
2885
2968
  7. Break the goal into concrete, ordered tasks with clear acceptance criteria.
@@ -2918,21 +3001,30 @@ Execute implementation by delegating to an agent team. The lead coordinates and
2918
3001
  2. Mark task in progress: \`bd update <id> --status=in_progress\`.
2919
3002
  3. Call \`memory_search\` with the task description to retrieve relevant lessons. Run \`memory_search\` per agent/subtask so each gets targeted context.
2920
3003
  4. Assess complexity to determine team strategy.
2921
- 5. For non-trivial tasks, spawn a **test-analyst** agent before any code is written. The test-analyst:
2922
- - Analyzes the task requirements and acceptance criteria
2923
- - Identifies happy paths, edge cases, failure modes, boundary conditions, and invariants
2924
- - Produces a structured **test plan** (not code) listing concrete test cases to cover
2925
- - The test-writer then implements this plan as actual test code
2926
- 6. Execute based on assessed complexity:
2927
- - If **trivial** (config changes, typos, one-line fixes): handle directly with a single agent. No TDD pair needed. Proceed to verification and close.
2928
- - If **simple** (well-scoped feature or bug fix): sequential TDD \u2014 **test-analyst** produces test plan, then **test-writer** implements failing tests, then **implementer** makes them pass.
2929
- - If **complex** (cross-cutting or ambiguous scope): iterative TDD \u2014 **test-analyst** produces test plan, then **test-writer** and **implementer** alternate in ping-pong cycles until done.
2930
- 7. When agents work on overlapping areas, they communicate directly to coordinate and avoid conflicts.
2931
- 8. Lead coordinates the cycle: review agent outputs, resolve conflicts, verify tests pass. Do not write code directly.
2932
- 9. If blocked by ambiguity or conflicting agent outputs, use \`AskUserQuestion\` to get user direction before proceeding.
2933
- 10. Commit incrementally as tests pass \u2014 do not batch all commits to the end.
2934
- 11. Run the full test suite to check for regressions.
2935
- 12. Close the task: \`bd close <id>\`.
3004
+ 5. If **trivial** (config changes, typos, one-line fixes): handle directly with a single subagent. No AgentTeam needed. Proceed to step 10.
3005
+ 6. If **simple** or **complex**, create an AgentTeam:
3006
+ \`\`\`
3007
+ TeamCreate: team_name="work-<task-id>"
3008
+ \`\`\`
3009
+ 7. Spawn **test-analyst** as the first teammate (produces a test plan, not code):
3010
+ \`\`\`
3011
+ Task: name="test-analyst", subagent_type="general-purpose", team_name="work-<task-id>"
3012
+ prompt: "Analyze requirements for <task>. Identify happy paths, edge cases, failure modes, boundary conditions, invariants. Output a structured test plan."
3013
+ \`\`\`
3014
+ Wait for test-analyst to report the test plan via SendMessage.
3015
+ 8. If **simple**: spawn test-writer, wait for tests, then spawn implementer:
3016
+ \`\`\`
3017
+ Task: name="test-writer", subagent_type="general-purpose", team_name="work-<task-id>"
3018
+ Task: name="implementer", subagent_type="general-purpose", team_name="work-<task-id>"
3019
+ \`\`\`
3020
+ If **complex**: spawn both as teammates, coordinate via SendMessage for ping-pong cycles.
3021
+ 9. When agents work on overlapping areas, they communicate directly via SendMessage to coordinate and avoid conflicts.
3022
+ 10. Lead coordinates: review agent outputs, resolve conflicts, verify tests pass. Do not write code directly.
3023
+ 11. If blocked by ambiguity or conflicting agent outputs, use \`AskUserQuestion\` to get user direction.
3024
+ 12. Shut down the team when done: send \`shutdown_request\` to all teammates.
3025
+ 13. Commit incrementally as tests pass \u2014 do not batch all commits to the end.
3026
+ 14. Run the full test suite to check for regressions.
3027
+ 15. Close the task: \`bd close <id>\`.
2936
3028
 
2937
3029
  ## Verification Gate
2938
3030
  Before marking work complete, run the 8-step TDD verification pipeline:
@@ -2956,49 +3048,48 @@ Before marking work complete, run the 8-step TDD verification pipeline:
2956
3048
  Multi-agent code review with severity classification and a mandatory \`/implementation-reviewer\` gate.
2957
3049
 
2958
3050
  ## Workflow
2959
- 1. Run quality gates first: \`pnpm test && pnpm lint\` to catch easy failures before the full review.
2960
- 2. Identify what to review from \`$ARGUMENTS\` or recent changes (\`git diff\`).
2961
- 3. Call \`memory_search\` with the changed areas to surface relevant past lessons.
2962
- 4. Spawn the reviewer agent team in parallel \u2014 one agent per perspective:
2963
- - **security-reviewer**: injection risks, auth issues, data exposure
2964
- - **architecture-reviewer**: module boundaries, coupling, cohesion, API design
2965
- - **performance-reviewer**: unnecessary allocations, N+1 queries, blocking calls
2966
- - **test-coverage-reviewer**: missing edge cases, cargo-cult tests, mocked business logic
2967
- - **simplicity-reviewer**: over-engineering, dead code, unnecessary abstractions
2968
- - **docs-reviewer**: documentation alignment, ADR compliance, undocumented public APIs
2969
- - **consistency-reviewer**: naming conventions, code patterns, style consistency with existing codebase
2970
- - **error-handling-reviewer**: error messages quality, resilience, logging, observability
2971
- - **edge-case-reviewer**: boundary conditions, off-by-one, nil/undefined, empty inputs, type coercion traps
2972
- - **pattern-matcher**: search \`memory_search\` for recurring issues \u2014 if a finding matches a known pattern, auto-reinforce its severity via \`memory_capture\`
2973
- - **cct-reviewer**: check code against CCT patterns in \`.claude/lessons/cct-patterns.jsonl\` for known Claude mistakes from past sessions
2974
- 5. Reviewers communicate findings with each other via direct messages so cross-cutting issues (e.g., a security fix that impacts performance) are identified early.
2975
- 6. Collect all findings and classify by severity:
2976
- - **P1** (critical): security vulnerabilities, data loss, correctness bugs \u2014 P1 findings block completion
2977
- - **P2** (important): architectural violations, significant performance issues
2978
- - **P3** (minor): style nits, small improvements, non-urgent suggestions
2979
- 7. Synthesize and prioritize findings \u2014 deduplicate overlapping reports, consolidate related items, and rank by severity before creating issues.
2980
- 8. Use \`AskUserQuestion\` when severity classification is ambiguous (e.g., a finding could be P1 or P2) or when the fix approach has multiple valid options.
2981
- 9. For P1 and P2 findings, create beads issues:
2982
- \`\`\`bash
2983
- bd create --title="P1: <finding>" --type=bug --priority=1
3051
+ 1. Run quality gates first: \`pnpm test && pnpm lint\`.
3052
+ 2. Identify scope from \`$ARGUMENTS\` or \`git diff\`. Count changed lines.
3053
+ 3. Call \`memory_search\` with changed areas to surface past lessons.
3054
+ 4. **Select reviewer tier based on diff size:**
3055
+ - **Small** (<100 lines): 4 core reviewers \u2014 security, test-coverage, simplicity, cct-reviewer.
3056
+ - **Medium** (100-500 lines): add architecture, performance, edge-case (7 total).
3057
+ - **Large** (500+ lines): full team \u2014 all 11 reviewers including docs, consistency, error-handling, pattern-matcher.
3058
+ 5. Create team and spawn selected reviewers in parallel:
2984
3059
  \`\`\`
2985
- 10. Submit to **\`/implementation-reviewer\`** as the mandatory gate \u2014 it has final authority on whether the review passes. All P1 findings must be resolved before approval.
2986
- 11. Output a review summary with pass/fail per perspective and severity breakdown.
3060
+ TeamCreate: team_name="review-<scope-slug>"
3061
+ Task: name="security-reviewer", prompt: "Review for injection, auth, data exposure"
3062
+ Task: name="test-coverage-reviewer", prompt: "Review for missing edge cases, cargo-cult tests"
3063
+ Task: name="simplicity-reviewer", prompt: "Review for over-engineering, dead code"
3064
+ Task: name="cct-reviewer", prompt: "Check against CCT patterns in .claude/lessons/"
3065
+ (medium+) Task: name="architecture-reviewer", prompt: "Review module boundaries, coupling"
3066
+ (medium+) Task: name="performance-reviewer", prompt: "Review allocations, N+1, blocking calls"
3067
+ (medium+) Task: name="edge-case-reviewer", prompt: "Check boundary conditions, off-by-one"
3068
+ (large) Task: name="docs-reviewer", prompt: "Check doc alignment, ADR compliance"
3069
+ (large) Task: name="consistency-reviewer", prompt: "Check naming, patterns, style"
3070
+ (large) Task: name="error-handling-reviewer", prompt: "Review error messages, resilience"
3071
+ (large) Task: name="pattern-matcher", prompt: "Match findings to memory, reinforce via memory_capture"
3072
+ \`\`\`
3073
+ 6. Reviewers communicate cross-cutting findings via SendMessage.
3074
+ 7. Classify findings: **P1** (security, data loss, correctness \u2014 blocks completion), **P2** (architecture, performance), **P3** (style, minor).
3075
+ 8. Deduplicate and prioritize. Use \`AskUserQuestion\` for ambiguous severity.
3076
+ 9. For P1/P2 findings: \`bd create --title="P1: <finding>" --type=bug --priority=1\`
3077
+ 10. Submit to **\`/implementation-reviewer\`** \u2014 mandatory gate, final authority. All P1s must be resolved.
3078
+ 11. **External reviewers (optional)**: Check \`.claude/compound-agent.json\` for \`"externalReviewers"\`. Spawn configured reviewers. Advisory only, never blocks.
3079
+ 12. Output review summary with severity breakdown and external findings (if any).
2987
3080
 
2988
3081
  ## Memory Integration
2989
- - Call \`memory_search\` at the start for known issues in the changed areas.
2990
- - **pattern-matcher** auto-reinforces: when a review finding matches an existing memory item, call \`memory_capture\` to increase its severity (recurring issues become higher priority).
2991
- - **cct-reviewer** reads \`.claude/lessons/cct-patterns.jsonl\` for known Claude failure patterns.
2992
- - After the review, call \`memory_capture\` with \`type=solution\` to store the review report for future sessions.
3082
+ - Call \`memory_search\` at the start for known issues in changed areas.
3083
+ - **pattern-matcher** auto-reinforces recurring findings via \`memory_capture\`.
3084
+ - **cct-reviewer** reads \`.claude/lessons/cct-patterns.jsonl\` for known Claude mistakes.
3085
+ - After review, call \`memory_capture\` with \`type=solution\` to store the review report.
2993
3086
 
2994
3087
  ## Docs Integration
2995
- - **docs-reviewer** checks that code changes align with \`docs/\` content and existing ADRs.
2996
- - Flags if a public API was added without documentation.
2997
- - Flags if code contradicts an existing ADR in \`docs/decisions/\`.
3088
+ - **docs-reviewer** checks code changes align with \`docs/\` and existing ADRs.
3089
+ - Flags undocumented public APIs and ADR contradictions.
2998
3090
 
2999
3091
  ## Beads Integration
3000
3092
  - Create \`bd\` issues for P1 and P2 findings with \`bd create\`.
3001
- - Reference the reviewed code in issue descriptions.
3002
3093
  - Close related issues with \`bd close\` when findings are resolved.
3003
3094
  `,
3004
3095
  "compound.md": `$ARGUMENTS
@@ -3011,14 +3102,23 @@ Multi-agent analysis to capture high-quality lessons from completed work into th
3011
3102
  ## Workflow
3012
3103
  1. Parse what was done from \`$ARGUMENTS\` or recent git history (\`git diff\`, \`git log\`).
3013
3104
  2. Call \`memory_search\` with the topic to check what is already known (avoid duplicates).
3014
- 3. Spawn the compound analysis team in parallel:
3015
- - **context-analyzer**: summarize what happened (git diff, test results, plan context)
3016
- - **lesson-extractor**: identify mistakes, corrections, and discoveries
3017
- - **docs-reviewer**: scan \`docs/\` for docs that need updating based on what changed, and check if any ADR in \`docs/decisions/\` should be deprecated or superseded
3018
- - **pattern-matcher**: match against existing memory, classify New/Duplicate/Reinforcement/Contradiction
3019
- - **solution-writer**: formulate structured items typed as lesson, solution, pattern, or preference
3020
- - **compounding**: synthesize accumulated lessons into CCT patterns for test reuse
3021
- 4. Agents pass results to each other via direct messages so downstream agents build on upstream findings.
3105
+ 3. Create a compound team and spawn the 6 analysis agents in parallel:
3106
+ \`\`\`
3107
+ TeamCreate: team_name="compound-<topic-slug>"
3108
+ Task: name="context-analyzer", subagent_type="general-purpose", team_name="compound-<topic>"
3109
+ prompt: "Summarize what happened: git diff, test results, plan context for: <topic>"
3110
+ Task: name="lesson-extractor", subagent_type="general-purpose", team_name="compound-<topic>"
3111
+ prompt: "Identify mistakes, corrections, and discoveries from: <topic>"
3112
+ Task: name="docs-reviewer", subagent_type="Explore", team_name="compound-<topic>"
3113
+ prompt: "Scan docs/ for content that needs updating. Check if any ADR in docs/decisions/ should be deprecated."
3114
+ Task: name="pattern-matcher", subagent_type="general-purpose", team_name="compound-<topic>"
3115
+ prompt: "Match findings against existing memory via memory_search. Classify: New/Duplicate/Reinforcement/Contradiction."
3116
+ Task: name="solution-writer", subagent_type="general-purpose", team_name="compound-<topic>"
3117
+ prompt: "Formulate structured memory items typed as lesson, solution, pattern, or preference."
3118
+ Task: name="compounding", subagent_type="general-purpose", team_name="compound-<topic>"
3119
+ prompt: "Synthesize accumulated lessons into CCT patterns for test reuse."
3120
+ \`\`\`
3121
+ 4. Agents pass results to each other via SendMessage so downstream agents build on upstream findings. The lead coordinates the pipeline: context-analyzer and lesson-extractor feed pattern-matcher and solution-writer, which feed compounding.
3022
3122
  5. Apply quality filter on each candidate item:
3023
3123
  - **Novel**: skip if >0.85 similarity to existing memory
3024
3124
  - **Specific**: reject vague or generic advice
@@ -3057,38 +3157,43 @@ Chain all phases: brainstorm, plan, work, review, compound. End-to-end delivery.
3057
3157
  ## Workflow
3058
3158
  1. **Brainstorm phase**: Explore the goal from \`$ARGUMENTS\`.
3059
3159
  - Call \`memory_search\` with the goal.
3060
- - Spawn docs-explorer to scan \`docs/\` for relevant context and existing ADRs.
3160
+ - \`TeamCreate\` team "brainstorm-<slug>", spawn docs-explorer + code-explorer as parallel teammates.
3061
3161
  - Ask clarifying questions via \`AskUserQuestion\`, explore alternatives.
3062
3162
  - Auto-create ADRs for significant decisions in \`docs/decisions/\`.
3063
3163
  - Create a beads epic from conclusions with \`bd create --type=feature\`.
3164
+ - Shut down brainstorm team before next phase.
3064
3165
 
3065
3166
  2. **Plan phase**: Structure the work.
3066
3167
  - Check for brainstorm epic via \`bd list\`.
3067
- - Spawn docs-analyst to check specs, standards, and ADRs that constrain the plan.
3168
+ - \`TeamCreate\` team "plan-<slug>", spawn docs-analyst + repo-analyst + memory-analyst as parallel teammates.
3068
3169
  - Break into tasks with dependencies and acceptance criteria.
3069
3170
  - Create beads issues with \`bd create\` and map dependencies with \`bd dep add\`.
3171
+ - Shut down plan team before next phase.
3070
3172
 
3071
3173
  3. **Work phase**: Implement with adaptive TDD.
3072
- - Assess complexity (trivial/simple/complex) to choose team strategy.
3073
- - For non-trivial tasks: test-analyst produces test plan, then test-writer and implementer execute.
3174
+ - Assess complexity (trivial/simple/complex) to choose strategy.
3175
+ - Trivial: single subagent, no team. Simple/complex: \`TeamCreate\` team "work-<task-id>".
3176
+ - Spawn test-analyst first, then test-writer + implementer as teammates.
3074
3177
  - Call \`memory_search\` per subtask; \`memory_capture\` after corrections.
3075
3178
  - Commit incrementally. Close tasks as they complete.
3076
- - Run verification gate before marking complete.
3179
+ - Run verification gate before marking complete. Shut down work team.
3077
3180
 
3078
3181
  4. **Review phase**: 11-agent review with severity classification.
3079
3182
  - Run quality gates first: \`pnpm test && pnpm lint\`.
3080
- - Core (security, architecture, performance, test-coverage, simplicity), quality (docs, consistency, error-handling), intelligence (edge-case, pattern-matcher, cct-reviewer).
3183
+ - \`TeamCreate\` team "review-<slug>", spawn all 11 reviewers as parallel teammates.
3081
3184
  - Classify findings as P1 (critical/blocking), P2 (important), P3 (minor).
3082
3185
  - P1 findings must be fixed before proceeding \u2014 they block completion.
3083
- - Submit to \`/implementation-reviewer\` as the mandatory gate before moving on.
3084
- - Create beads issues for P1/P2 findings.
3186
+ - Submit to \`/implementation-reviewer\` as the mandatory gate. Shut down review team.
3085
3187
 
3086
3188
  5. **Compound phase**: Capture learnings.
3087
- - Spawn 6-agent analysis team: context-analyzer, lesson-extractor, docs-reviewer, pattern-matcher, solution-writer, compounding.
3189
+ - \`TeamCreate\` team "compound-<slug>", spawn 6 analysis agents as parallel teammates.
3088
3190
  - Search first with \`memory_search\` to avoid duplicates. Apply quality filters (novelty + specificity).
3089
3191
  - Store novel insights via \`memory_capture\` with supersedes/related links.
3090
3192
  - Update outdated docs and deprecate superseded ADRs.
3091
- - Use \`AskUserQuestion\` to confirm high-severity items before storing.
3193
+ - Use \`AskUserQuestion\` to confirm high-severity items. Shut down compound team.
3194
+
3195
+ ## Agent Team Pattern
3196
+ Each phase creates its own AgentTeam via \`TeamCreate\`, spawns teammates via \`Task\` tool with \`team_name\`, coordinates via \`SendMessage\`, and shuts down with \`shutdown_request\` before the next phase starts. Use subagents (Task without team_name) only for quick lookups like \`memory_search\` or \`bd\` commands.
3092
3197
 
3093
3198
  ## Phase Control
3094
3199
  - **Skip phases**: Parse \`$ARGUMENTS\` for "from <phase>" (e.g., "from plan"). Skip all phases before the named one.
@@ -3104,6 +3209,69 @@ Chain all phases: brainstorm, plan, work, review, compound. End-to-end delivery.
3104
3209
  ## Memory Integration
3105
3210
  - \`memory_search\` is called in brainstorm, work, and compound phases.
3106
3211
  - \`memory_capture\` is called in work and compound phases.
3212
+ `,
3213
+ // =========================================================================
3214
+ // Utility commands (CLI wrappers)
3215
+ // =========================================================================
3216
+ "learn.md": `Capture a lesson from this session.
3217
+
3218
+ Usage: /compound learn <insight>
3219
+
3220
+ Examples:
3221
+ - /compound learn "Always use Polars for large CSV files"
3222
+ - /compound learn "API requires X-Request-ID header"
3223
+
3224
+ \`\`\`bash
3225
+ npx ca learn "$ARGUMENTS"
3226
+ \`\`\`
3227
+ `,
3228
+ "search.md": `Search lessons for relevant context.
3229
+
3230
+ Usage: /compound search <query>
3231
+
3232
+ Examples:
3233
+ - /compound search "API authentication"
3234
+ - /compound search "data processing patterns"
3235
+
3236
+ \`\`\`bash
3237
+ npx ca search "$ARGUMENTS"
3238
+ \`\`\`
3239
+
3240
+ Note: You can also use the \`memory_search\` MCP tool directly.
3241
+ `,
3242
+ "list.md": `Show all stored lessons.
3243
+
3244
+ \`\`\`bash
3245
+ npx ca list
3246
+ \`\`\`
3247
+ `,
3248
+ "prime.md": `Load compound-agent workflow context after compaction or context loss.
3249
+
3250
+ \`\`\`bash
3251
+ npx ca prime
3252
+ \`\`\`
3253
+ `,
3254
+ "show.md": `Show details of a specific lesson.
3255
+
3256
+ Usage: /compound show <lesson-id>
3257
+
3258
+ \`\`\`bash
3259
+ npx ca show "$ARGUMENTS"
3260
+ \`\`\`
3261
+ `,
3262
+ "wrong.md": `Mark a lesson as incorrect or invalid.
3263
+
3264
+ Usage: /compound wrong <lesson-id>
3265
+
3266
+ \`\`\`bash
3267
+ npx ca wrong "$ARGUMENTS"
3268
+ \`\`\`
3269
+ `,
3270
+ "stats.md": `Show compound-agent database statistics and health.
3271
+
3272
+ \`\`\`bash
3273
+ npx ca stats
3274
+ \`\`\`
3107
3275
  `
3108
3276
  };
3109
3277
 
@@ -3122,7 +3290,7 @@ Explore the problem space before committing to a solution. This phase produces a
3122
3290
  ## Methodology
3123
3291
  1. Ask "why" before "how" -- understand the real problem
3124
3292
  2. Search memory with \`memory_search\` for similar past features and known constraints
3125
- 3. Spawn Explore subagents: docs-explorer for \`docs/\` (architecture, specs, research, standards, existing ADRs) and code-explorer for relevant codebase areas
3293
+ 3. Create an AgentTeam (\`TeamCreate\`) and spawn docs-explorer + code-explorer as parallel teammates via \`Task\` tool with \`team_name\`. Use subagents only for quick single lookups.
3126
3294
  4. Use \`AskUserQuestion\` to clarify scope, constraints, and preferences
3127
3295
  5. Divergent phase: generate multiple approaches without filtering
3128
3296
  6. Identify constraints and non-functional requirements (performance, security, etc.)
@@ -3136,7 +3304,7 @@ Explore the problem space before committing to a solution. This phase produces a
3136
3304
  - If the problem domain matches past work, review those lessons first
3137
3305
 
3138
3306
  ## Docs Integration
3139
- - Spawn docs-explorer to scan \`docs/\` for relevant architecture docs, research, and standards
3307
+ - Spawn docs-explorer as an AgentTeam teammate (not a subagent) to scan \`docs/\` for relevant architecture docs, research, and standards
3140
3308
  - Review existing ADRs in \`docs/decisions/\` -- prior decisions may constrain the brainstorm
3141
3309
  - Auto-create ADR for each significant decision made during convergence
3142
3310
 
@@ -3173,7 +3341,7 @@ Create a concrete implementation plan by decomposing work into small, testable t
3173
3341
  ## Methodology
3174
3342
  1. Review brainstorm output for decisions and open questions
3175
3343
  2. Search memory with \`memory_search\` for architectural patterns and past mistakes
3176
- 3. Spawn research agent team: docs-analyst for \`docs/\` (specs, standards, ADRs), repo-analyst for codebase, memory-analyst for deep memory search
3344
+ 3. Create an AgentTeam (\`TeamCreate\`) and spawn docs-analyst, repo-analyst, and memory-analyst as parallel teammates via \`Task\` tool with \`team_name\`
3177
3345
  4. Synthesize research findings into a coherent approach. Flag conflicts between ADRs and proposed plan.
3178
3346
  5. Use \`AskUserQuestion\` to resolve ambiguities, conflicting constraints, or priority trade-offs before decomposing
3179
3347
  6. Decompose into tasks small enough to verify individually
@@ -3187,7 +3355,7 @@ Create a concrete implementation plan by decomposing work into small, testable t
3187
3355
  - Check for preferred architectural patterns in this codebase
3188
3356
 
3189
3357
  ## Docs Integration
3190
- - Spawn docs-analyst to scan \`docs/\` for relevant specs, standards, and research
3358
+ - Spawn docs-analyst as an AgentTeam teammate to scan \`docs/\` for relevant specs, standards, and research
3191
3359
  - Check \`docs/decisions/\` for existing ADRs that constrain or inform the plan
3192
3360
  - If the plan contradicts an ADR, flag it for the user before proceeding
3193
3361
 
@@ -3232,24 +3400,12 @@ Execute implementation through an agent team using adaptive TDD. The lead coordi
3232
3400
  8. Commit incrementally as tests pass \u2014 do not batch all commits to the end
3233
3401
  9. Capture lessons with \`memory_capture\` after corrections or discoveries
3234
3402
 
3235
- ## Team Structure
3236
- Adaptive TDD model based on task complexity:
3237
- - **Trivial**: Single agent handles the change directly, no TDD ceremony
3238
- - **Simple**: test-analyst \u2192 test-writer \u2192 implementer (sequential)
3239
- - **Complex**: test-analyst \u2192 test-writer/implementer ping-pong (iterative)
3240
-
3241
- ## Complexity Assessment
3242
- - **Trivial**: Config changes, typos, renaming, one-line fixes. No new behavior.
3243
- - **Simple**: Well-scoped feature or bug fix. Clear inputs/outputs. One module affected.
3244
- - **Complex**: Cross-module changes, architectural decisions, ambiguous requirements.
3245
-
3246
- ## Agent Delegation
3247
- The lead coordinates but does not write code:
3248
- - Spawn **test-analyst** first for non-trivial tasks -- it produces the test plan that test-writer implements
3249
- - Spawn agents with task context, relevant memory items, and the test plan
3250
- - Review agent outputs for correctness and consistency
3251
- - Resolve conflicts between test expectations and implementation
3252
- - Use \`AskUserQuestion\` when blocked by ambiguity or conflicting agent outputs -- get user direction before proceeding
3403
+ ## Team Structure & Delegation
3404
+ The lead coordinates but does not write code. Use AgentTeam (\`TeamCreate\`) for non-trivial work, plain subagent for trivial fixes:
3405
+ - **Trivial**: Single subagent, no team. Config changes, typos, one-line fixes.
3406
+ - **Simple**: \`TeamCreate\` \u2192 test-analyst \u2192 test-writer \u2192 implementer (sequential teammates)
3407
+ - **Complex**: \`TeamCreate\` \u2192 test-analyst \u2192 test-writer/implementer ping-pong (iterative teammates)
3408
+ Spawn teammates via \`Task\` with \`team_name\`, coordinate via \`SendMessage\`, shut down with \`shutdown_request\` when done.
3253
3409
 
3254
3410
  ## Memory Integration
3255
3411
  - Call \`memory_search\` per delegated subtask with the subtask's specific description
@@ -3296,11 +3452,11 @@ Perform thorough code review by spawning specialized reviewers in parallel, cons
3296
3452
  ## Methodology
3297
3453
  1. Run quality gates first: \`pnpm test && pnpm lint\`
3298
3454
  2. Search memory with \`memory_search\` for known patterns and recurring issues
3299
- 3. Spawn 11 specialized reviewer agents in parallel:
3455
+ 3. Create an AgentTeam (\`TeamCreate\`) and spawn all 11 reviewers as parallel teammates via \`Task\` tool with \`team_name\`:
3300
3456
  - **Core**: security, architecture, performance, test-coverage, simplicity
3301
3457
  - **Quality**: docs-reviewer, consistency-reviewer, error-handling-reviewer
3302
3458
  - **Intelligence**: edge-case-reviewer, pattern-matcher (memory-backed), cct-reviewer (CCT patterns)
3303
- 4. Reviewers communicate findings to each other via direct messages
3459
+ 4. Reviewers communicate findings to each other via \`SendMessage\`
3304
3460
  5. Collect, consolidate, and deduplicate all findings
3305
3461
  6. Classify by severity: P1 (critical/blocking), P2 (important), P3 (minor)
3306
3462
  7. Use \`AskUserQuestion\` when severity is ambiguous or fix has multiple valid options
@@ -3350,14 +3506,14 @@ Extract and store lessons learned during the cycle, and update project documenta
3350
3506
 
3351
3507
  ## Methodology
3352
3508
  1. Review what happened during this cycle (git diff, test results, plan context)
3353
- 2. Spawn the compound analysis team in parallel:
3509
+ 2. Create an AgentTeam (\`TeamCreate\`) and spawn the 6 analysis agents as parallel teammates via \`Task\` tool with \`team_name\`:
3354
3510
  - context-analyzer: gathers cycle context (diffs, test output)
3355
3511
  - lesson-extractor: identifies corrections, surprises, discoveries
3356
3512
  - docs-reviewer: scans \`docs/\` for outdated content and ADRs that need updating
3357
3513
  - pattern-matcher: checks \`memory_search\` for duplicates and related items
3358
3514
  - solution-writer: drafts final memory items
3359
3515
  - compounding: synthesizes accumulated lessons into CCT patterns
3360
- 3. Agents pass results through the pipeline and share findings with each other
3516
+ 3. Agents pass results through the pipeline via \`SendMessage\`. The lead coordinates: context-analyzer and lesson-extractor feed pattern-matcher and solution-writer, which feed compounding.
3361
3517
  4. Apply quality filters: novelty check (>0.85 similarity = skip), specificity check
3362
3518
  5. Classify each item by type: lesson, solution, pattern, or preference
3363
3519
  6. Classify severity: high (data loss/security/contradictions), medium (workflow/patterns), low (style/optimizations)
@@ -3367,7 +3523,7 @@ Extract and store lessons learned during the cycle, and update project documenta
3367
3523
  10. Use \`AskUserQuestion\` to confirm high-severity items with the user before storing; medium/low items are auto-stored
3368
3524
 
3369
3525
  ## Docs Integration
3370
- - Spawn docs-reviewer to check if \`docs/\` content is outdated after the cycle
3526
+ - docs-reviewer runs as an AgentTeam teammate to check if \`docs/\` content is outdated after the cycle
3371
3527
  - Check \`docs/decisions/\` for ADRs contradicted by the work done
3372
3528
  - Set ADR status to \`deprecated\` if a decision was reversed, referencing the new ADR
3373
3529
 
@@ -3442,19 +3598,6 @@ async function createPluginManifest(repoRoot) {
3442
3598
  await writeFile(pluginPath, JSON.stringify(PLUGIN_MANIFEST, null, 2) + "\n", "utf-8");
3443
3599
  return true;
3444
3600
  }
3445
- async function createSlashCommands(repoRoot) {
3446
- const commandsDir = join(repoRoot, ".claude", "commands");
3447
- await mkdir(commandsDir, { recursive: true });
3448
- let created = false;
3449
- for (const [filename, content] of Object.entries(SLASH_COMMANDS)) {
3450
- const filePath = join(commandsDir, filename);
3451
- if (!existsSync(filePath)) {
3452
- await writeFile(filePath, content, "utf-8");
3453
- created = true;
3454
- }
3455
- }
3456
- return created;
3457
- }
3458
3601
  async function installAgentTemplates(repoRoot) {
3459
3602
  const agentsDir = join(repoRoot, ".claude", "agents", "compound");
3460
3603
  await mkdir(agentsDir, { recursive: true });
@@ -3529,7 +3672,6 @@ async function runSetup(options) {
3529
3672
  const agentsMdUpdated = await updateAgentsMd(repoRoot);
3530
3673
  await ensureClaudeMdReference(repoRoot);
3531
3674
  await createPluginManifest(repoRoot);
3532
- await createSlashCommands(repoRoot);
3533
3675
  await installAgentTemplates(repoRoot);
3534
3676
  await installWorkflowCommands(repoRoot);
3535
3677
  await installPhaseSkills(repoRoot);
@@ -3569,11 +3711,14 @@ async function runUninstall(repoRoot, dryRun) {
3569
3711
  actions.push(`Removed ${dir}`);
3570
3712
  }
3571
3713
  }
3572
- for (const filename of Object.keys(SLASH_COMMANDS)) {
3714
+ for (const filename of LEGACY_ROOT_SLASH_COMMANDS) {
3573
3715
  const filePath = join(repoRoot, ".claude", "commands", filename);
3574
3716
  if (existsSync(filePath)) {
3575
- if (!dryRun) await rm(filePath);
3576
- actions.push(`Removed ${filePath}`);
3717
+ const content = await readFile(filePath, "utf-8");
3718
+ if (content.startsWith(GENERATED_MARKER)) {
3719
+ if (!dryRun) await rm(filePath);
3720
+ actions.push(`Removed ${filePath}`);
3721
+ }
3577
3722
  }
3578
3723
  }
3579
3724
  const pluginPath = join(repoRoot, ".claude", "plugin.json");
@@ -3656,6 +3801,15 @@ async function runUpdate(repoRoot, dryRun) {
3656
3801
  for (const [phase, content] of Object.entries(PHASE_SKILLS)) {
3657
3802
  await processFile(join(repoRoot, ".claude", "skills", "compound", phase, "SKILL.md"), content);
3658
3803
  }
3804
+ for (const filename of LEGACY_ROOT_SLASH_COMMANDS) {
3805
+ const filePath = join(repoRoot, ".claude", "commands", filename);
3806
+ if (existsSync(filePath)) {
3807
+ const content = await readFile(filePath, "utf-8");
3808
+ if (content.startsWith(GENERATED_MARKER)) {
3809
+ if (!dryRun) await rm(filePath);
3810
+ }
3811
+ }
3812
+ }
3659
3813
  return { updated, added, skipped };
3660
3814
  }
3661
3815
  async function runStatus(repoRoot) {
@@ -4084,9 +4238,9 @@ async function getGitHooksDir(repoRoot) {
4084
4238
  if (!existsSync(gitDir)) {
4085
4239
  return null;
4086
4240
  }
4087
- const configPath = join(gitDir, "config");
4088
- if (existsSync(configPath)) {
4089
- const config = await readFile(configPath, "utf-8");
4241
+ const configPath2 = join(gitDir, "config");
4242
+ if (existsSync(configPath2)) {
4243
+ const config = await readFile(configPath2, "utf-8");
4090
4244
  const match = /hooksPath\s*=\s*(.+)$/m.exec(config);
4091
4245
  if (match?.[1]) {
4092
4246
  const hooksPath = match[1].trim();
@@ -4248,10 +4402,6 @@ async function initAction(cmd, options) {
4248
4402
  if (!options.skipAgents) {
4249
4403
  await ensureClaudeMdReference(repoRoot);
4250
4404
  }
4251
- let slashCommandsCreated = false;
4252
- if (!options.skipAgents) {
4253
- slashCommandsCreated = await createSlashCommands(repoRoot);
4254
- }
4255
4405
  if (!options.skipAgents) {
4256
4406
  await createPluginManifest(repoRoot);
4257
4407
  await installAgentTemplates(repoRoot);
@@ -4273,7 +4423,6 @@ async function initAction(cmd, options) {
4273
4423
  initialized: true,
4274
4424
  lessonsDir,
4275
4425
  agentsMd: agentsMdUpdated,
4276
- slashCommands: slashCommandsCreated || !options.skipAgents,
4277
4426
  hooks: hooksChanged,
4278
4427
  hookStatus: hookResult?.status ?? "skipped",
4279
4428
  claudeHooks: claudeHooksInstalled
@@ -4284,7 +4433,6 @@ async function initAction(cmd, options) {
4284
4433
  out.success("Compound agent initialized");
4285
4434
  console.log(` Lessons directory: ${lessonsDir}`);
4286
4435
  printAgentsMdStatus(agentsMdUpdated, options.skipAgents);
4287
- printSlashCommandsStatus(slashCommandsCreated, options.skipAgents);
4288
4436
  printHookStatus(hookResult, options.skipHooks);
4289
4437
  printClaudeHooksStatus(claudeHooksResult, options.skipClaude);
4290
4438
  }
@@ -4297,15 +4445,6 @@ function printAgentsMdStatus(updated, skipped) {
4297
4445
  console.log(" AGENTS.md: Already has Compound Agent section");
4298
4446
  }
4299
4447
  }
4300
- function printSlashCommandsStatus(created, skipped) {
4301
- if (created) {
4302
- console.log(" Slash commands: Created (/learn, /show, /wrong, /stats)");
4303
- } else if (skipped) {
4304
- console.log(" Slash commands: Skipped (--skip-agents)");
4305
- } else {
4306
- console.log(" Slash commands: Already exist");
4307
- }
4308
- }
4309
4448
  function printHookStatus(hookResult, skipped) {
4310
4449
  if (skipped) {
4311
4450
  console.log(" Git hooks: Skipped (--skip-hooks)");
@@ -4547,6 +4686,63 @@ function registerCrudCommands(program2) {
4547
4686
  await deleteAction(ids, options);
4548
4687
  });
4549
4688
  }
4689
+ async function runDoctor(repoRoot) {
4690
+ const checks = [];
4691
+ const claudeDir = join(repoRoot, ".claude");
4692
+ checks.push(existsSync(claudeDir) ? { name: ".claude directory", status: "pass" } : { name: ".claude directory", status: "fail", fix: "Run: npx ca setup" });
4693
+ const lessonsPath = join(repoRoot, LESSONS_PATH);
4694
+ checks.push(existsSync(lessonsPath) ? { name: "Lessons index", status: "pass" } : { name: "Lessons index", status: "warn", fix: "Run: npx ca setup" });
4695
+ const agentsDir = join(repoRoot, ".claude", "agents", "compound");
4696
+ checks.push(existsSync(agentsDir) ? { name: "Agent templates", status: "pass" } : { name: "Agent templates", status: "fail", fix: "Run: npx ca setup" });
4697
+ const commandsDir = join(repoRoot, ".claude", "commands", "compound");
4698
+ checks.push(existsSync(commandsDir) ? { name: "Workflow commands", status: "pass" } : { name: "Workflow commands", status: "fail", fix: "Run: npx ca setup" });
4699
+ const settingsPath = getClaudeSettingsPath(false);
4700
+ let hooksOk = false;
4701
+ try {
4702
+ const settings = await readClaudeSettings(settingsPath);
4703
+ hooksOk = hasClaudeHook(settings);
4704
+ } catch {
4705
+ }
4706
+ checks.push(hooksOk ? { name: "Claude hooks", status: "pass" } : { name: "Claude hooks", status: "fail", fix: "Run: npx ca setup" });
4707
+ const mcpOk = await hasMcpServerInMcpJson(repoRoot);
4708
+ checks.push(mcpOk ? { name: "MCP server", status: "pass" } : { name: "MCP server", status: "fail", fix: "Run: npx ca setup" });
4709
+ let modelOk = false;
4710
+ try {
4711
+ modelOk = isModelAvailable();
4712
+ } catch {
4713
+ }
4714
+ checks.push(modelOk ? { name: "Embedding model", status: "pass" } : { name: "Embedding model", status: "warn", fix: "Run: npx ca download-model" });
4715
+ return checks;
4716
+ }
4717
+ var STATUS_ICONS = {
4718
+ pass: "OK",
4719
+ fail: "FAIL",
4720
+ warn: "WARN"
4721
+ };
4722
+ function registerDoctorCommand(program2) {
4723
+ program2.command("doctor").description("Verify external dependencies and project health").action(async () => {
4724
+ const repoRoot = getRepoRoot();
4725
+ const checks = await runDoctor(repoRoot);
4726
+ console.log("Compound Agent Health Check:\n");
4727
+ for (const check of checks) {
4728
+ const icon = STATUS_ICONS[check.status];
4729
+ const line = ` [${icon}] ${check.name}`;
4730
+ console.log(line);
4731
+ if (check.fix) {
4732
+ console.log(` Fix: ${check.fix}`);
4733
+ }
4734
+ }
4735
+ const failures = checks.filter((c) => c.status === "fail");
4736
+ const warnings = checks.filter((c) => c.status === "warn");
4737
+ console.log("");
4738
+ if (failures.length === 0 && warnings.length === 0) {
4739
+ console.log("All checks passed.");
4740
+ } else {
4741
+ if (failures.length > 0) console.log(`${failures.length} check(s) failed.`);
4742
+ if (warnings.length > 0) console.log(`${warnings.length} warning(s).`);
4743
+ }
4744
+ });
4745
+ }
4550
4746
 
4551
4747
  // src/commands/management-invalidation.ts
4552
4748
  function registerInvalidationCommands(program2) {
@@ -4853,6 +5049,10 @@ function formatLessonForPrime(lesson) {
4853
5049
  }
4854
5050
  async function getPrimeContext(repoRoot) {
4855
5051
  const root = getRepoRoot();
5052
+ try {
5053
+ await syncIfNeeded(root);
5054
+ } catch {
5055
+ }
4856
5056
  const lessons = await loadSessionLessons(root, 5);
4857
5057
  let output = TRUST_LANGUAGE_TEMPLATE;
4858
5058
  if (lessons.length > 0) {
@@ -4927,6 +5127,106 @@ function registerAuditCommands(program2) {
4927
5127
  }
4928
5128
  });
4929
5129
  }
5130
+ var CONFIG_FILENAME = "compound-agent.json";
5131
+ var VALID_REVIEWERS = ["gemini", "codex"];
5132
+ function configPath(repoRoot) {
5133
+ return join(repoRoot, ".claude", CONFIG_FILENAME);
5134
+ }
5135
+ async function readConfig(repoRoot) {
5136
+ const path = configPath(repoRoot);
5137
+ if (!existsSync(path)) return {};
5138
+ try {
5139
+ const parsed = JSON.parse(await readFile(path, "utf-8"));
5140
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
5141
+ return parsed;
5142
+ } catch {
5143
+ return {};
5144
+ }
5145
+ }
5146
+ async function writeConfig(repoRoot, config) {
5147
+ await mkdir(join(repoRoot, ".claude"), { recursive: true });
5148
+ await writeFile(configPath(repoRoot), JSON.stringify(config, null, 2) + "\n", "utf-8");
5149
+ }
5150
+ function safeReviewerArray(config) {
5151
+ const raw = config.externalReviewers;
5152
+ if (!Array.isArray(raw)) return [];
5153
+ return raw;
5154
+ }
5155
+ async function getExternalReviewers(repoRoot) {
5156
+ const config = await readConfig(repoRoot);
5157
+ return safeReviewerArray(config).filter((r) => VALID_REVIEWERS.includes(r));
5158
+ }
5159
+ async function enableReviewer(repoRoot, name) {
5160
+ if (!VALID_REVIEWERS.includes(name)) {
5161
+ throw new Error(`Invalid reviewer: ${name}. Valid options: ${VALID_REVIEWERS.join(", ")}`);
5162
+ }
5163
+ const config = await readConfig(repoRoot);
5164
+ const reviewers = safeReviewerArray(config);
5165
+ if (reviewers.includes(name)) return false;
5166
+ config.externalReviewers = [...reviewers, name];
5167
+ await writeConfig(repoRoot, config);
5168
+ return true;
5169
+ }
5170
+ async function disableReviewer(repoRoot, name) {
5171
+ const config = await readConfig(repoRoot);
5172
+ const reviewers = safeReviewerArray(config);
5173
+ if (!reviewers.includes(name)) return false;
5174
+ config.externalReviewers = reviewers.filter((r) => r !== name);
5175
+ await writeConfig(repoRoot, config);
5176
+ return true;
5177
+ }
5178
+
5179
+ // src/commands/reviewer.ts
5180
+ function registerReviewerCommand(program2) {
5181
+ const reviewer = program2.command("reviewer").description("Manage external code reviewers (gemini, codex)");
5182
+ reviewer.command("enable <name>").description(`Enable an external reviewer (${VALID_REVIEWERS.join(", ")})`).action(async (name) => {
5183
+ const repoRoot = getRepoRoot();
5184
+ try {
5185
+ const added = await enableReviewer(repoRoot, name);
5186
+ if (added) {
5187
+ console.log(`Enabled external reviewer: ${name}`);
5188
+ } else {
5189
+ console.log(`${name} is already enabled`);
5190
+ }
5191
+ } catch (err) {
5192
+ console.error(err.message);
5193
+ process.exitCode = 1;
5194
+ }
5195
+ });
5196
+ reviewer.command("disable <name>").description("Disable an external reviewer").action(async (name) => {
5197
+ try {
5198
+ const repoRoot = getRepoRoot();
5199
+ const removed = await disableReviewer(repoRoot, name);
5200
+ if (removed) {
5201
+ console.log(`Disabled external reviewer: ${name}`);
5202
+ } else {
5203
+ console.log(`${name} is not enabled`);
5204
+ }
5205
+ } catch (err) {
5206
+ console.error(err.message);
5207
+ process.exitCode = 1;
5208
+ }
5209
+ });
5210
+ reviewer.command("list").description("List enabled external reviewers").action(async () => {
5211
+ try {
5212
+ const repoRoot = getRepoRoot();
5213
+ const reviewers = await getExternalReviewers(repoRoot);
5214
+ if (reviewers.length === 0) {
5215
+ console.log("No external reviewers enabled");
5216
+ console.log(`Available: ${VALID_REVIEWERS.join(", ")}`);
5217
+ console.log("Enable with: ca reviewer enable <name>");
5218
+ } else {
5219
+ console.log("Enabled external reviewers:");
5220
+ for (const r of reviewers) {
5221
+ console.log(` - ${r}`);
5222
+ }
5223
+ }
5224
+ } catch (err) {
5225
+ console.error(err.message);
5226
+ process.exitCode = 1;
5227
+ }
5228
+ });
5229
+ }
4930
5230
  function registerRulesCommands(program2) {
4931
5231
  const rulesCmd = program2.command("rules").description("Run repository-defined rule checks");
4932
5232
  rulesCmd.command("check").description("Check codebase against rules in .claude/rules.json").action(function() {
@@ -5568,6 +5868,8 @@ function registerManagementCommands(program2) {
5568
5868
  registerPrimeCommand(program2);
5569
5869
  registerCrudCommands(program2);
5570
5870
  registerAuditCommands(program2);
5871
+ registerDoctorCommand(program2);
5872
+ registerReviewerCommand(program2);
5571
5873
  registerRulesCommands(program2);
5572
5874
  registerTestSummaryCommand(program2);
5573
5875
  }