compound-agent 1.0.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/README.md ADDED
@@ -0,0 +1,331 @@
1
+ # Compound Agent
2
+
3
+ Semantically-intelligent workflow plugin for Claude Code. Every unit of work compounds -- mistakes become lessons, solutions become searchable knowledge, and each cycle makes subsequent work smarter.
4
+
5
+ ## Overview
6
+
7
+ Claude Code forgets everything between sessions. Compound Agent fixes this with a three-layer system: issue tracking (Beads) at the foundation, semantic memory with vector search in the middle, and structured workflow phases on top. It captures knowledge from corrections, discoveries, and completed work, then retrieves it precisely when relevant -- at session start, during planning, and before architectural decisions.
8
+
9
+ ## Architecture
10
+
11
+ ```
12
+ LAYER 3: WORKFLOWS
13
+ /compound:brainstorm, /compound:plan, /compound:work,
14
+ /compound:review, /compound:compound, /compound:lfg
15
+ Agent teams at each phase with inter-communication
16
+
17
+ LAYER 2: SEMANTIC MEMORY
18
+ 4 types: lesson | solution | pattern | preference
19
+ JSONL source of truth + SQLite FTS5 index + vector embeddings
20
+ Ranked retrieval: similarity * severity * recency * confirmation
21
+
22
+ LAYER 1: BEADS (Foundation)
23
+ Issue tracking + dependency graph
24
+ Git-backed persistence + distributed sync
25
+ ```
26
+
27
+ ### Storage Layout
28
+
29
+ ```
30
+ project_root/
31
+ +-- .mcp.json <- MCP server config
32
+ +-- AGENTS.md <- Workflow instructions for Claude
33
+ +-- .claude/
34
+ +-- settings.json <- Claude Code hooks
35
+ +-- lessons/
36
+ | +-- index.jsonl <- Source of truth (git-tracked)
37
+ | +-- archive/ <- Compacted old items
38
+ +-- .cache/
39
+ +-- lessons.sqlite <- Rebuildable index (.gitignore)
40
+ ```
41
+
42
+ ### The Compound Loop
43
+
44
+ ```
45
+ COMPOUND --> writes to --> MEMORY
46
+ |
47
+ searched by
48
+ |
49
+ PLAN --> creates context for --> WORK
50
+ |
51
+ produces for
52
+ |
53
+ REVIEW
54
+ |
55
+ generates for
56
+ |
57
+ COMPOUND
58
+ ```
59
+
60
+ Every cycle through the loop makes subsequent cycles smarter. A bug found in review becomes a lesson. That lesson surfaces during planning of similar work. The plan accounts for the known issue. Work avoids the mistake.
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ # Install as dev dependency
66
+ pnpm add -D compound-agent
67
+
68
+ # One-shot setup (creates dirs, hooks, MCP server, downloads model)
69
+ npx ca setup
70
+
71
+ # Skip the ~278MB model download (do it later)
72
+ npx ca setup --skip-model
73
+ ```
74
+
75
+ ### Requirements
76
+
77
+ - Node.js >= 20
78
+ - ~278MB disk space for the embedding model
79
+ - ~150MB RAM during embedding operations
80
+
81
+ ### pnpm Users
82
+
83
+ pnpm v9+ blocks native addon builds by default. Add to your `package.json`:
84
+
85
+ ```json
86
+ {
87
+ "pnpm": {
88
+ "onlyBuiltDependencies": ["better-sqlite3", "node-llama-cpp"]
89
+ }
90
+ }
91
+ ```
92
+
93
+ Then run `pnpm install`.
94
+
95
+ ### What `setup` Does
96
+
97
+ | Action | Location | Purpose |
98
+ |--------|----------|---------|
99
+ | Create lessons store | `.claude/lessons/` | JSONL + cache directory |
100
+ | Install AGENTS.md | project root | Workflow instructions for Claude |
101
+ | Configure hooks | `.claude/settings.json` | SessionStart, PreCompact, UserPromptSubmit, PostToolUse hooks |
102
+ | Register MCP server | `.mcp.json` | `memory_search`, `memory_capture` tools |
103
+ | Install workflow commands | `.claude/commands/compound/` | Slash commands for each phase |
104
+ | Install agent definitions | `.claude/agents/compound/` | Specialized agent roles |
105
+ | Install phase skills | `.claude/skills/compound/` | Process instructions per phase |
106
+ | Download embedding model | `~/.node-llama-cpp/models/` | First-use only, ~278MB |
107
+
108
+ ## Quick Start
109
+
110
+ The five-phase workflow:
111
+
112
+ ```
113
+ 1. /compound:brainstorm --> Explore the problem, clarify scope
114
+ 2. /compound:plan --> Create tasks enriched by memory search
115
+ 3. /compound:work --> Execute with agent teams + TDD
116
+ 4. /compound:review --> Multi-agent review with inter-communication
117
+ 5. /compound:compound --> Capture what was learned into memory
118
+ ```
119
+
120
+ Or run all phases sequentially:
121
+
122
+ ```
123
+ /compound:lfg "Add auth to API"
124
+ ```
125
+
126
+ Each phase searches memory for relevant past knowledge and injects it into agent context. The compound phase captures new knowledge, closing the loop.
127
+
128
+ ## CLI Reference
129
+
130
+ The CLI binary is `ca` (alias: `compound-agent`).
131
+
132
+ ### Capture
133
+
134
+ | Command | Description |
135
+ |---------|-------------|
136
+ | `ca learn "<insight>"` | Capture a memory item manually |
137
+ | `ca learn "<insight>" --trigger "<context>"` | Capture with trigger context |
138
+ | `ca learn "<insight>" --severity high` | Set severity level |
139
+ | `ca learn "<insight>" --citation src/api.ts:42` | Attach file provenance |
140
+ | `ca capture --input <file>` | Capture from structured input file |
141
+ | `ca detect --input <file>` | Detect correction patterns in input |
142
+
143
+ ### Retrieval
144
+
145
+ | Command | Description |
146
+ |---------|-------------|
147
+ | `ca search "<query>"` | Keyword search across memory (FTS5) |
148
+ | `ca list` | List all memory items |
149
+ | `ca list --invalidated` | List only invalidated items |
150
+ | `ca check-plan --plan "<text>"` | Semantic search for plan-time retrieval |
151
+ | `ca load-session` | Load high-severity items for session start |
152
+
153
+ ### Management
154
+
155
+ | Command | Description |
156
+ |---------|-------------|
157
+ | `ca show <id>` | Display item details |
158
+ | `ca update <id> --insight "..."` | Modify item fields |
159
+ | `ca delete <id>` | Soft-delete an item |
160
+ | `ca wrong <id>` | Mark item as invalid |
161
+ | `ca wrong <id> --reason "..."` | Mark invalid with reason |
162
+ | `ca validate <id>` | Re-enable an invalidated item |
163
+ | `ca stats` | Database health and age distribution |
164
+ | `ca rebuild` | Rebuild SQLite index from JSONL |
165
+ | `ca compact` | Archive old items, remove tombstones |
166
+ | `ca export` | Export items as JSON |
167
+ | `ca import <file>` | Import items from JSONL file |
168
+ | `ca prime` | Load workflow context (used by hooks) |
169
+ | `ca audit` | Run audit checks against the codebase |
170
+ | `ca rules check` | Run repository-defined rule checks |
171
+ | `ca test-summary` | Run tests and output a compact summary |
172
+
173
+ ### Setup
174
+
175
+ | Command | Description |
176
+ |---------|-------------|
177
+ | `ca setup` | One-shot setup (hooks + MCP + model) |
178
+ | `ca setup --skip-model` | Setup without model download |
179
+ | `ca setup --uninstall` | Remove all generated files |
180
+ | `ca setup --update` | Regenerate files (preserves user customizations) |
181
+ | `ca setup --status` | Show installation status |
182
+ | `ca setup --dry-run` | Show what would change without changing |
183
+ | `ca setup claude --status` | Check Claude Code integration health |
184
+ | `ca setup claude --uninstall` | Remove Claude hooks only |
185
+ | `ca download-model` | Download the embedding model |
186
+
187
+ ## MCP Tools
188
+
189
+ Compound Agent exposes three MCP endpoints. These are the primary interface for Claude -- preferred over CLI commands.
190
+
191
+ | Endpoint | Type | Purpose |
192
+ |----------|------|---------|
193
+ | `memory_search` | Tool | Search memory items by semantic similarity. Supports `query`, `maxResults`, and `type` filter. |
194
+ | `memory_capture` | Tool | Capture a new memory item. Accepts `insight`, `trigger`, `tags`, `type`, `severity`, `pattern`, and relationship fields. |
195
+ | `memory://prime` | Resource | Workflow context with high-severity memory items for session start. |
196
+
197
+ ## Workflow Commands
198
+
199
+ Installed to `.claude/commands/compound/` during setup. Invoked as slash commands in Claude Code.
200
+
201
+ | Command | Phase | Description |
202
+ |---------|-------|-------------|
203
+ | `/compound:brainstorm` | Brainstorm | Explore the problem, iterate with user, create beads epic |
204
+ | `/compound:plan` | Plan | Create detailed plan with memory retrieval + research agents |
205
+ | `/compound:work` | Work | Execute with agent teams, adaptive TDD per task complexity |
206
+ | `/compound:review` | Review | Multi-agent review (security, architecture, performance, tests, simplicity) |
207
+ | `/compound:compound` | Compound | Capture lessons, solutions, patterns into memory |
208
+ | `/compound:lfg` | All | Chain all phases sequentially |
209
+
210
+ ## Memory Types
211
+
212
+ All types share one store, one schema, one search mechanism. A query returns the most relevant items regardless of type.
213
+
214
+ | Type | Trigger means | Insight means | Example |
215
+ |------|---------------|---------------|---------|
216
+ | `lesson` | What happened | What was learned | "Polars 10x faster than pandas for large files" |
217
+ | `solution` | The problem | The resolution | "Auth 401 fix: add X-Request-ID header" |
218
+ | `pattern` | When it applies | Why it matters | `{ bad: "await in loop", good: "Promise.all" }` |
219
+ | `preference` | The context | The preference | "Use uv over pip in this project" |
220
+
221
+ ## Memory Item Schema
222
+
223
+ All memory items share a common schema with a discriminated union on the `type` field.
224
+
225
+ ### Required Fields
226
+
227
+ | Field | Type | Description |
228
+ |-------|------|-------------|
229
+ | `id` | string | Hash-based unique identifier |
230
+ | `type` | `"lesson"` \| `"solution"` \| `"pattern"` \| `"preference"` | Item type |
231
+ | `trigger` | string | What caused/prompted this |
232
+ | `insight` | string | What was learned |
233
+ | `tags` | string[] | Categorization tags |
234
+ | `source` | string | How captured: `user_correction`, `self_correction`, `test_failure`, `manual` |
235
+ | `context` | `{ tool, intent }` | Capture context |
236
+ | `created` | ISO string | Creation timestamp |
237
+ | `confirmed` | boolean | Whether user confirmed |
238
+ | `supersedes` | string[] | IDs of items this replaces |
239
+ | `related` | string[] | IDs of related items |
240
+
241
+ ### Optional Fields
242
+
243
+ | Field | Type | Description |
244
+ |-------|------|-------------|
245
+ | `evidence` | string | Supporting evidence |
246
+ | `severity` | `"high"` \| `"medium"` \| `"low"` | Importance level |
247
+ | `citation` | `{ file, line?, commit? }` | File/line provenance |
248
+ | `pattern` | `{ bad, good }` | Code pattern (required for `pattern` type) |
249
+
250
+ ### Retrieval Ranking
251
+
252
+ ```
253
+ boost = severity_boost * recency_boost * confirmation_boost
254
+ clamped to max 1.8
255
+ score = vector_similarity(query, item) * boost
256
+
257
+ severity_boost: high=1.5, medium=1.0, low=0.8
258
+ recency_boost: last 30d=1.2, older=1.0
259
+ confirmation_boost: confirmed=1.3, unconfirmed=1.0
260
+ ```
261
+
262
+ ### Example
263
+
264
+ ```json
265
+ {
266
+ "id": "Sa1b2c3d4",
267
+ "type": "solution",
268
+ "trigger": "API returned 401 despite valid JWT token",
269
+ "insight": "Auth API requires X-Request-ID header in all requests",
270
+ "evidence": "Traced in network tab, discovered missing header requirement",
271
+ "severity": "high",
272
+ "tags": ["api", "auth", "headers"],
273
+ "source": "test_failure",
274
+ "context": { "tool": "fetch", "intent": "API authentication" },
275
+ "created": "2026-01-15T10:30:00.000Z",
276
+ "confirmed": true,
277
+ "supersedes": [],
278
+ "related": [],
279
+ "citation": { "file": "src/api/client.ts", "line": 42 }
280
+ }
281
+ ```
282
+
283
+ ## Development
284
+
285
+ ```bash
286
+ pnpm install # Install dependencies
287
+ pnpm build # Build with tsup
288
+ pnpm dev # Watch mode (rebuild on changes)
289
+ pnpm lint # Type check + ESLint
290
+ ```
291
+
292
+ ### Test Scripts
293
+
294
+ | Script | Duration | Use Case |
295
+ |--------|----------|----------|
296
+ | `pnpm test:fast` | ~6s | Rapid feedback during development (skips CLI integration tests) |
297
+ | `pnpm test` | ~60s | Full suite before committing |
298
+ | `pnpm test:changed` | varies | Only tests affected by recent changes |
299
+ | `pnpm test:watch` | - | Watch mode for TDD workflow |
300
+ | `pnpm test:all` | ~60s | Full suite with model download |
301
+
302
+ **Recommended**: Use `pnpm test:fast` while coding, `pnpm test` before committing.
303
+
304
+ ## Technology Stack
305
+
306
+ | Component | Technology |
307
+ |-----------|------------|
308
+ | Language | TypeScript (ESM) |
309
+ | Package Manager | pnpm |
310
+ | Build | tsup |
311
+ | Testing | Vitest + fast-check (property tests) |
312
+ | Storage | better-sqlite3 + FTS5 |
313
+ | Embeddings | node-llama-cpp + EmbeddingGemma-300M |
314
+ | CLI | Commander.js |
315
+ | Schema | Zod |
316
+ | MCP | @modelcontextprotocol/sdk |
317
+ | Issue Tracking | Beads (bd) |
318
+
319
+ ## Documentation
320
+
321
+ | Document | Purpose |
322
+ |----------|---------|
323
+ | [docs/ARCHITECTURE-V2.md](docs/ARCHITECTURE-V2.md) | Three-layer architecture design |
324
+ | [docs/MIGRATION.md](docs/MIGRATION.md) | Migration guide from learning-agent |
325
+ | [CHANGELOG.md](CHANGELOG.md) | Version history |
326
+ | [AGENTS.md](AGENTS.md) | Agent workflow instructions |
327
+ | [.claude/CLAUDE.md](.claude/CLAUDE.md) | Claude Code project instructions |
328
+
329
+ ## License
330
+
331
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node