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/CHANGELOG.md ADDED
@@ -0,0 +1,412 @@
1
+ # Changelog
2
+
3
+ > **Note**: This project was renamed from **learning-agent** (CLI: `lna`) to **compound-agent** (CLI: `ca`) as part of the compound-agent rename. Historical entries below use the original name.
4
+
5
+ All notable changes to this project will be documented in this file.
6
+
7
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
8
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
+
10
+ ## [Unreleased]
11
+
12
+ ### Added
13
+
14
+ - **Unified memory types**: lesson, solution, pattern, preference -- all share one store, schema, and search mechanism
15
+ - **5-phase compound workflow**: brainstorm, plan, work, review, compound -- each with dedicated slash commands, SKILL.md files, and agent definitions
16
+ - **`/compound:lfg` command**: Chains all 5 phases sequentially for end-to-end workflow
17
+ - **Agent teams with inter-communication**: Specialized agents (reviewers, researchers, analysts) collaborate at each phase
18
+ - **MCP server**: `memory_search` and `memory_capture` tools, `memory://prime` resource for workflow context
19
+ - **Rule engine**: Config-driven validation for memory item quality via `ca rules check`
20
+ - **Audit system**: `ca audit` command runs pattern, rule, and lesson quality checks against the codebase
21
+ - **Test summary**: `ca test-summary` command runs tests and outputs a compact pass/fail summary
22
+ - **Intelligent compounding**: CCT pattern detection with similarity clustering and automatic synthesis
23
+ - **Embedding model**: EmbeddingGemma-300M via node-llama-cpp for local semantic search
24
+ - **Full-cycle integration tests**: 41 tests covering the complete compound workflow
25
+ - **Setup command (`ca setup`)**: One-shot configuration of hooks, MCP server, agents, commands, and skills
26
+ - **Setup update**: `ca setup --update` regenerates generated files while preserving user customizations
27
+ - **Setup status**: `ca setup --status` shows installation status of all components
28
+
29
+ ### Changed
30
+
31
+ - **Renamed** from learning-agent (CLI: `lna`) to compound-agent (CLI: `ca`)
32
+ - **Architecture**: 3-layer design (Beads foundation, Semantic Memory, Workflows)
33
+ - **MCP-first integration**: MCP tools are the primary interface; CLI serves as fallback
34
+ - **Memory storage**: Items stored in `.claude/lessons/index.jsonl` (backward compatible with v0.x lessons)
35
+ - **Hook system**: UserPromptSubmit and PostToolUse hooks for context-aware memory injection
36
+ - **MCP `memory_capture`**: Supports all memory types (lesson, solution, pattern, preference), severity, confirmation, supersedes, and related fields
37
+
38
+ ### Fixed
39
+
40
+ - **Version state**: VERSION now reads from package.json at runtime
41
+ - **Model names**: Embedding model references use consistent naming
42
+ - **DB isolation**: Test suites use isolated database instances
43
+ - **Error visibility**: Structured error format with codes across all CLI commands
44
+
45
+ ## [0.2.9] - 2026-02-07
46
+
47
+ ### Fixed
48
+
49
+ - **Race conditions**: Embedding singleton init and TOCTOU in compaction
50
+ - **Score inflation**: Clamp combined boost multiplier in ranking
51
+ - **MCP resource cleanup**: Signal handlers for clean shutdown
52
+ - **Hook patterns**: Tighter matching and simplified failure tracking
53
+ - **Input validation**: Zod discriminated union for parseInputFile data shape
54
+ - **Version source**: Read from package.json instead of hardcoding
55
+
56
+ ### Changed
57
+
58
+ - **Tombstone simplification**: Replaced tombstone records with `deleted` flag on Lesson
59
+ - **Command structure**: Flattened `setup/` and `management/` into `commands/`
60
+ - **Exports cleanup**: Removed unnecessary barrel re-exports
61
+ - **SQLite**: Removed graceful degradation layer and deprecated shim
62
+ - **MCP**: Deduplicated tool handlers into shared logic
63
+ - **Tests**: Consolidated three test utility files into `test-utils.ts`
64
+
65
+ ## [0.2.8] - 2026-02-04
66
+
67
+ ### Added
68
+
69
+ - **UserPromptSubmit Hook**: Detects correction and planning language in user messages
70
+ - Correction detection: "actually", "wrong", "use X instead", "you forgot", etc.
71
+ - Planning detection: "implement", "build", "create", "refactor", etc.
72
+ - Injects gentle reminders to use `lesson_capture` and `lesson_search` MCP tools
73
+
74
+ - **PostToolUseFailure Hook**: Smart failure detection for Bash/Edit/Write tools
75
+ - Triggers after 2 failures on same file/command OR 3 total failures
76
+ - Suggests using `lesson_search` to find relevant lessons
77
+ - State tracked per session, resets on success
78
+
79
+ - **PostToolUse Hook**: Resets failure tracking state after successful tool use
80
+
81
+ ### Changed
82
+
83
+ - **Pre-commit prompt redesigned** with checklist format for better reflection
84
+ - "LESSON CAPTURE CHECKPOINT" header
85
+ - Explicit checkboxes for self-reflection
86
+ - Clearer call-to-action
87
+
88
+ - **HookInstallResult discriminated union** for clear status messages
89
+ - `installed`, `already_installed`, `not_git_repo`, `appended` statuses
90
+ - No more ambiguous "Already installed or not a git repo" messages
91
+
92
+ ### Fixed
93
+
94
+ - Git hook installation now provides specific status messages
95
+
96
+ ## [0.2.7] - 2026-02-04
97
+
98
+ ### Fixed
99
+
100
+ - **Prime Context MCP Alignment**: Updated trust language template to prioritize MCP tools
101
+ - "MCP Tools (ALWAYS USE THESE)" section at top of prime output
102
+ - `lesson_search` and `lesson_capture` as primary methods
103
+ - CLI commands moved to "fallback only" section
104
+ - Now consistent with AGENTS.md MCP-first approach
105
+
106
+ ## [0.2.6] - 2026-02-04
107
+
108
+ ### Fixed
109
+
110
+ - **MCP Config Location**: Write to `.mcp.json` (project scope) instead of `.claude/settings.json`
111
+ - Per Claude Code docs, MCP servers should be in `.mcp.json` at project root
112
+ - Hooks remain correctly in `.claude/settings.json`
113
+ - `setup claude --status` now checks both files
114
+
115
+ - **AGENTS.md MCP Priority**: Updated template to clearly prioritize MCP tools
116
+ - "MCP Tools (ALWAYS USE THESE)" section at top
117
+ - CLI commands clearly marked as "fallback only"
118
+ - Claude will now prefer `lesson_search`/`lesson_capture` over CLI
119
+
120
+ ### Changed
121
+
122
+ - Architecture diagram in README updated to show `.mcp.json` location
123
+ - Simplified AGENTS.md structure: MCP tools first, mandatory recall, capture protocol
124
+
125
+ ## [0.2.5] - 2026-02-03
126
+
127
+ ### Fixed
128
+
129
+ - Remove invalid `PreCommit` Claude Code hook (not a valid hook type)
130
+ - Remind-capture now uses git pre-commit hook instead of Claude Code hook
131
+ - Fix `setup claude --status` to check for `/search` instead of `/check-plan`
132
+
133
+ ## [0.2.4] - 2026-02-03
134
+
135
+ ### Added
136
+
137
+ - **MCP Server Integration**
138
+ - Native Claude tools via Model Context Protocol (MCP)
139
+ - `lesson_search` tool for semantic lesson retrieval
140
+ - `lesson_capture` tool for capturing new lessons
141
+ - Auto-registered in Claude Code settings during setup
142
+
143
+ - **One-Shot Setup Command**
144
+ - `lna setup` combines init, hooks, MCP, and model download
145
+ - `--skip-model` flag to skip embedding model download
146
+ - Idempotent: safe to run multiple times
147
+
148
+ - **Two-Hook System** (Claude Code hooks)
149
+ - `SessionStart`: Loads workflow context via `lna prime`
150
+ - `PreCompact`: Reloads context before compaction via `lna prime`
151
+ - Git pre-commit hook: Reminds to capture lessons via `lna remind-capture`
152
+
153
+ - **Remind-Capture Command**
154
+ - `lna remind-capture` prompts for lesson capture before commits
155
+ - Checks for uncommitted corrections that could become lessons
156
+
157
+ ### Changed
158
+
159
+ - **Hook Configuration**
160
+ - Hooks now use `lna prime` instead of `load-session` for trust language
161
+ - Removed `check-plan` hook in favor of `lesson_search` MCP tool
162
+ - Updated AGENTS.md with "Mandatory Recall" section for compliance
163
+
164
+ - **AGENTS.md Template**
165
+ - Now focuses on MCP tools (`lesson_search`, `lesson_capture`)
166
+ - Trust language patterns: "MUST", "NEVER", "Mandatory Recall"
167
+ - Clearer workflow instructions for Claude integration
168
+
169
+ - **Slash Commands**
170
+ - Replaced `/check-plan` with `/search` for lesson search
171
+ - Added `/prime` for context recovery
172
+
173
+ ### Removed
174
+
175
+ - `check-plan` command (replaced by `lesson_search` MCP tool)
176
+ - Auto-invoke triggers (replaced by MCP-based workflow)
177
+
178
+ ## [0.2.3] - 2026-02-01
179
+
180
+ ### Added
181
+
182
+ - **SQLite Graceful Degradation** (2f0)
183
+ - Works as dev dependency without native bindings failing
184
+ - JSONL-only mode when SQLite unavailable
185
+ - Keyword search falls back gracefully
186
+ - Warning displayed in degraded mode
187
+
188
+ - **Claude Code Integration** (ctv, 8lp, 6nw, 501, 2jp, lfy)
189
+ - Claude Plugin structure (`.claude-plugin/`) with manifest and commands
190
+ - `/learn` slash command for quick lesson capture
191
+ - `/check-plan` slash command for plan-time retrieval
192
+ - Auto-invoke triggers for lesson capture patterns
193
+ - Detection triggers wired to Claude Code workflow
194
+ - AGENTS.md includes reference to CLAUDE.md
195
+
196
+ - **Context Recovery** (gpv)
197
+ - `lna prime` command for context recovery after compaction/clear
198
+ - Outputs workflow rules, commands, and quality gates
199
+
200
+ - **Diagnostics** (qi0)
201
+ - `setup claude --status` shows integration health
202
+ - Displays settings file, hook status, slash command availability
203
+ - JSON output with `--json` flag
204
+
205
+ ### Changed
206
+
207
+ - **Architecture Refactoring** (e73, zpl)
208
+ - Split sqlite.ts (644 lines) into focused modules (<200 lines each)
209
+ - Module imports now use barrel exports (Parnas principles)
210
+ - Cleaner internal boundaries and improved maintainability
211
+
212
+ - **CLI Improvements** (79k, e2r)
213
+ - CLI releases database resources on SIGINT/SIGTERM signals
214
+ - `setup claude --uninstall` removes AGENTS.md section and CLAUDE.md reference
215
+ - Clean uninstall preserves other content
216
+
217
+ ### Fixed
218
+
219
+ - Claude now uses CLI commands instead of editing JSONL directly (0p5)
220
+ - Plan-time lessons now appear via check-plan hook integration (6nw)
221
+
222
+ ## [0.2.2] - 2026-02-01
223
+
224
+ ### Added
225
+
226
+ - **Age-based Temporal Validity** (LANDSCAPE.md: eik)
227
+ - `CompactionLevelSchema` for lesson lifecycle (0=active, 1=flagged, 2=archived)
228
+ - Age distribution display in `stats` command (<30d, 30-90d, >90d)
229
+ - Age warnings in `load-session` for lessons older than 90 days
230
+ - New schema fields: `compactionLevel`, `compactedAt`, `lastRetrieved`
231
+
232
+ - **Manual Invalidation** (LANDSCAPE.md: mov)
233
+ - `learning-agent wrong <id>` - Mark a lesson as invalid/wrong
234
+ - `learning-agent validate <id>` - Re-enable a previously invalidated lesson
235
+ - `list --invalidated` flag to show only invalidated lessons
236
+ - New schema fields: `invalidatedAt`, `invalidationReason`
237
+
238
+ - **Optional Citation Field** (LANDSCAPE.md: tn3)
239
+ - `CitationSchema` for lesson provenance tracking
240
+ - Store file path, line number, and git commit with lessons
241
+ - `learn --citation <file:line>` and `--citation-commit <hash>` flags
242
+
243
+ - **Count Warning** (LANDSCAPE.md: qp9)
244
+ - Warning in `stats` when lesson count exceeds 20 (context pollution prevention)
245
+ - Note in `load-session` when total lessons may degrade retrieval quality
246
+
247
+ ### Changed
248
+
249
+ - Lesson schema now includes optional fields for citation, age-tracking, and invalidation
250
+ - `list` command shows `[INVALID]` marker for invalidated lessons
251
+ - `load-session` JSON output includes `totalCount` field
252
+ - CLI refactored into command modules (`src/commands/`) for maintainability
253
+ - Age calculation logic centralized in `src/utils.ts`
254
+
255
+ ### Fixed
256
+
257
+ - **SQLite schema now stores v0.2.2 fields** (x9y)
258
+ - Added columns: `invalidated_at`, `invalidation_reason`, `citation_*`, `compaction_level`, `compacted_at`
259
+ - `rebuildIndex` preserves all v0.2.2 fields during cache rebuild
260
+ - `rowToLesson` correctly maps all fields back to Lesson objects
261
+
262
+ - **Retrieval paths filter out invalidated lessons** (z8k)
263
+ - `searchKeyword` excludes lessons with `invalidated_at` set
264
+ - `searchVector` skips invalidated lessons during scoring
265
+ - `loadSessionLessons` filters out invalidated high-severity lessons
266
+
267
+ ## [0.2.1] - 2026-02-01
268
+
269
+ ### Added
270
+
271
+ - **CLI Commands**
272
+ - `lna` short alias for `learning-agent` CLI
273
+ - `show <id>` - Display lesson details
274
+ - `update <id>` - Modify lesson fields (insight, severity, tags, confirmed)
275
+ - `delete <id>` - Create tombstone for lesson removal
276
+ - `download-model` - Download embedding model (~278MB)
277
+ - `--severity` flag for `learn` command to set lesson severity
278
+
279
+ - **Documentation**
280
+ - Complete lesson schema documentation in README
281
+ - Required vs optional fields explained
282
+ - Session-start loading requirements (type=full + severity=high + confirmed=true)
283
+ - "Never Edit JSONL Directly" warning in AGENTS.md template
284
+
285
+ ### Changed
286
+
287
+ - `setup claude` now defaults to project-local (was global)
288
+ - `setup claude --global` required for global installation
289
+ - `init` now includes `setup claude` step by default
290
+ - Auto-sync SQLite after every CLI mutation (learn, update, delete, import)
291
+
292
+ ### Fixed
293
+
294
+ - Pre-commit hook now inserted before exit statements (not appended after)
295
+ - JSONL edits properly sync to SQLite index
296
+ - High-severity lessons load correctly at session start
297
+
298
+ ## [0.2.0] - 2026-01-31
299
+
300
+ ### Added
301
+
302
+ - **Claude Code Integration**
303
+ - `learning-agent setup claude` - Install SessionStart hooks into Claude Code settings
304
+ - `--project` flag for project-level hooks (vs global)
305
+ - `--uninstall` to remove hooks
306
+ - `--dry-run` to preview changes
307
+ - Automatic lesson injection at session start, resume, and compact events
308
+
309
+ - **Storage Enhancements**
310
+ - Compaction system for archiving old lessons and removing tombstones
311
+ - Smart sync: rebuild index only when JSONL changes
312
+ - Retrieval count tracking for lesson usage statistics
313
+
314
+ - **CLI Commands**
315
+ - `learning-agent import <file>` - Import lessons from JSONL file
316
+ - `learning-agent stats` - Show database health statistics
317
+ - `learning-agent compact` - Archive old lessons
318
+ - `learning-agent export` - Export lessons as JSON
319
+ - Global flags: `--verbose`, `--quiet`
320
+ - Colored output with chalk
321
+
322
+ - **Embeddings**
323
+ - Switched to EmbeddingGemma-300M (~278MB, down from ~500MB)
324
+ - Simplified model download using node-llama-cpp resolveModelFile
325
+
326
+ - **Testing**
327
+ - 501 tests with property-based testing (fast-check)
328
+ - Integration tests for capture workflows
329
+
330
+ ### Changed
331
+
332
+ - Unified QuickLesson and FullLesson into single Lesson type
333
+ - Removed deprecated type exports
334
+ - `check-plan` now hard-fails on embedding errors (exit non-zero with actionable message)
335
+ - `capture` and `detect --save` now require `--yes` flag for saves
336
+ - `learn` command always saves with `confirmed: true`
337
+ - Hook installation is non-destructive (appends to existing hooks)
338
+ - Hook installation respects `core.hooksPath` git configuration
339
+
340
+ ### Fixed
341
+
342
+ - Embedding errors no longer masked as "no relevant lessons" in check-plan
343
+ - Git hooks no longer overwrite existing pre-commit hooks
344
+ - AGENTS.md template now includes explicit plan-time instructions
345
+
346
+ ## [0.1.0] - 2025-01-30
347
+
348
+ ### Added
349
+
350
+ - **Core Storage**
351
+ - JSONL storage for lessons with atomic append operations
352
+ - SQLite index with FTS5 full-text search support
353
+ - Automatic index rebuild from JSONL source of truth
354
+ - Hybrid storage model: git-tracked JSONL + rebuildable SQLite cache
355
+
356
+ - **Embeddings**
357
+ - Local semantic embeddings via node-llama-cpp
358
+ - EmbeddingGemma-300M model (768 dimensions)
359
+ - Manual model download via CLI (~278MB)
360
+ - Model stored in `~/.node-llama-cpp/models/`
361
+
362
+ - **Search & Retrieval**
363
+ - Vector similarity search using cosine distance
364
+ - Ranking with configurable boosts (severity, recency, confirmation)
365
+ - Session-start retrieval for high-severity lessons
366
+ - Plan-time retrieval with semantic relevance
367
+
368
+ - **Capture System**
369
+ - User correction detection patterns
370
+ - Self-correction detection (edit-fail-re-edit cycles)
371
+ - Test failure detection and fix tracking
372
+ - Quality filter: novel, specific, and actionable checks
373
+
374
+ - **Lesson Types**
375
+ - Quick lessons for fast capture
376
+ - Full lessons with evidence and severity levels
377
+ - Tombstone records for deletions/edits
378
+ - Metadata: source, context, supersedes, related
379
+
380
+ - **Public API**
381
+ - `appendLesson()` - Store new lessons
382
+ - `readLessons()` - Read lessons with pagination
383
+ - `searchKeyword()` - FTS5 keyword search
384
+ - `searchVector()` - Semantic vector search
385
+ - `loadSessionLessons()` - Session-start high-severity lessons
386
+ - `retrieveForPlan()` - Plan-time relevant lesson retrieval
387
+ - Detection triggers: `detectUserCorrection()`, `detectSelfCorrection()`, `detectTestFailure()`
388
+ - Quality filters: `shouldPropose()`, `isNovel()`, `isSpecific()`, `isActionable()`
389
+
390
+ - **CLI**
391
+ - `pnpm learn` - Capture a lesson manually
392
+ - `learning-agent search` - Search lessons
393
+ - `learning-agent rebuild` - Rebuild SQLite index
394
+
395
+ - **Developer Experience**
396
+ - TypeScript with ESM modules
397
+ - Zod schemas for runtime validation
398
+ - Vitest test suite
399
+ - tsup build configuration
400
+
401
+ [Unreleased]: https://github.com/Nathandela/learning_agent/compare/v0.2.9...HEAD
402
+ [0.2.9]: https://github.com/Nathandela/learning_agent/compare/v0.2.8...v0.2.9
403
+ [0.2.8]: https://github.com/Nathandela/learning_agent/compare/v0.2.7...v0.2.8
404
+ [0.2.7]: https://github.com/Nathandela/learning_agent/compare/v0.2.6...v0.2.7
405
+ [0.2.6]: https://github.com/Nathandela/learning_agent/compare/v0.2.5...v0.2.6
406
+ [0.2.5]: https://github.com/Nathandela/learning_agent/compare/v0.2.4...v0.2.5
407
+ [0.2.4]: https://github.com/Nathandela/learning_agent/compare/v0.2.3...v0.2.4
408
+ [0.2.3]: https://github.com/Nathandela/learning_agent/compare/v0.2.2...v0.2.3
409
+ [0.2.2]: https://github.com/Nathandela/learning_agent/compare/v0.2.1...v0.2.2
410
+ [0.2.1]: https://github.com/Nathandela/learning_agent/compare/v0.2.0...v0.2.1
411
+ [0.2.0]: https://github.com/Nathandela/learning_agent/compare/v0.1.0...v0.2.0
412
+ [0.1.0]: https://github.com/Nathandela/learning_agent/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Nathan Delacrétaz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.