anvil-dev-framework 0.1.6

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 (190) hide show
  1. package/README.md +719 -0
  2. package/VERSION +1 -0
  3. package/docs/ANVIL-REPO-IMPLEMENTATION-PLAN.md +441 -0
  4. package/docs/FIRST-SKILL-TUTORIAL.md +408 -0
  5. package/docs/INSTALLATION-RETRO-NOTES.md +458 -0
  6. package/docs/INSTALLATION.md +984 -0
  7. package/docs/anvil-hud.md +469 -0
  8. package/docs/anvil-init.md +255 -0
  9. package/docs/anvil-state.md +210 -0
  10. package/docs/boris-cherny-ralph-wiggum-insights.md +608 -0
  11. package/docs/command-reference.md +2022 -0
  12. package/docs/hooks-tts.md +368 -0
  13. package/docs/implementation-guide.md +810 -0
  14. package/docs/linear-github-integration.md +247 -0
  15. package/docs/local-issues.md +677 -0
  16. package/docs/patterns/README.md +419 -0
  17. package/docs/planning-responsibilities.md +139 -0
  18. package/docs/session-workflow.md +573 -0
  19. package/docs/simplification-plan-template.md +297 -0
  20. package/docs/simplification-principles.md +129 -0
  21. package/docs/specifications/CCS-RALPH-INTEGRATION-DESIGN.md +633 -0
  22. package/docs/specifications/CCS-RESEARCH-REPORT.md +169 -0
  23. package/docs/specifications/PLAN-ANV-verification-ralph-wiggum.md +403 -0
  24. package/docs/specifications/PLAN-parallel-tracks-anvil-memory-ccs.md +494 -0
  25. package/docs/specifications/SPEC-ANV-VRW/component-01-verify.md +208 -0
  26. package/docs/specifications/SPEC-ANV-VRW/component-02-stop-gate.md +226 -0
  27. package/docs/specifications/SPEC-ANV-VRW/component-03-posttooluse.md +209 -0
  28. package/docs/specifications/SPEC-ANV-VRW/component-04-ralph-wiggum.md +604 -0
  29. package/docs/specifications/SPEC-ANV-VRW/component-05-atomic-actions.md +311 -0
  30. package/docs/specifications/SPEC-ANV-VRW/component-06-verify-subagent.md +264 -0
  31. package/docs/specifications/SPEC-ANV-VRW/component-07-claude-md.md +363 -0
  32. package/docs/specifications/SPEC-ANV-VRW/index.md +182 -0
  33. package/docs/specifications/SPEC-ANV-anvil-memory.md +573 -0
  34. package/docs/specifications/SPEC-ANV-context-checkpoints.md +781 -0
  35. package/docs/specifications/SPEC-ANV-verification-ralph-wiggum.md +789 -0
  36. package/docs/sync.md +122 -0
  37. package/global/CLAUDE.md +140 -0
  38. package/global/agents/verify-app.md +164 -0
  39. package/global/commands/anvil-settings.md +527 -0
  40. package/global/commands/anvil-sync.md +121 -0
  41. package/global/commands/change.md +197 -0
  42. package/global/commands/clarify.md +252 -0
  43. package/global/commands/cleanup.md +292 -0
  44. package/global/commands/commit-push-pr.md +207 -0
  45. package/global/commands/decay-review.md +127 -0
  46. package/global/commands/discover.md +158 -0
  47. package/global/commands/doc-coverage.md +122 -0
  48. package/global/commands/evidence.md +307 -0
  49. package/global/commands/explore.md +121 -0
  50. package/global/commands/force-exit.md +135 -0
  51. package/global/commands/handoff.md +191 -0
  52. package/global/commands/healthcheck.md +302 -0
  53. package/global/commands/hud.md +84 -0
  54. package/global/commands/insights.md +319 -0
  55. package/global/commands/linear-setup.md +184 -0
  56. package/global/commands/lint-fix.md +198 -0
  57. package/global/commands/orient.md +510 -0
  58. package/global/commands/plan.md +228 -0
  59. package/global/commands/ralph.md +346 -0
  60. package/global/commands/ready.md +182 -0
  61. package/global/commands/release.md +305 -0
  62. package/global/commands/retro.md +96 -0
  63. package/global/commands/shard.md +166 -0
  64. package/global/commands/spec.md +227 -0
  65. package/global/commands/sprint.md +184 -0
  66. package/global/commands/tasks.md +228 -0
  67. package/global/commands/test-and-commit.md +151 -0
  68. package/global/commands/validate.md +132 -0
  69. package/global/commands/verify.md +251 -0
  70. package/global/commands/weekly-review.md +156 -0
  71. package/global/hooks/__pycache__/ralph_context_monitor.cpython-314.pyc +0 -0
  72. package/global/hooks/__pycache__/statusline_agent_sync.cpython-314.pyc +0 -0
  73. package/global/hooks/anvil_memory_observe.ts +322 -0
  74. package/global/hooks/anvil_memory_session.ts +166 -0
  75. package/global/hooks/anvil_memory_stop.ts +187 -0
  76. package/global/hooks/parse_transcript.py +116 -0
  77. package/global/hooks/post_merge_cleanup.sh +132 -0
  78. package/global/hooks/post_tool_format.sh +215 -0
  79. package/global/hooks/ralph_context_monitor.py +240 -0
  80. package/global/hooks/ralph_stop.sh +502 -0
  81. package/global/hooks/statusline.sh +1110 -0
  82. package/global/hooks/statusline_agent_sync.py +224 -0
  83. package/global/hooks/stop_gate.sh +250 -0
  84. package/global/lib/.claude/anvil-state.json +21 -0
  85. package/global/lib/__pycache__/agent_registry.cpython-314.pyc +0 -0
  86. package/global/lib/__pycache__/claim_service.cpython-314.pyc +0 -0
  87. package/global/lib/__pycache__/coderabbit_service.cpython-314.pyc +0 -0
  88. package/global/lib/__pycache__/config_service.cpython-314.pyc +0 -0
  89. package/global/lib/__pycache__/coordination_service.cpython-314.pyc +0 -0
  90. package/global/lib/__pycache__/doc_coverage_service.cpython-314.pyc +0 -0
  91. package/global/lib/__pycache__/gate_logger.cpython-314.pyc +0 -0
  92. package/global/lib/__pycache__/github_service.cpython-314.pyc +0 -0
  93. package/global/lib/__pycache__/hygiene_service.cpython-314.pyc +0 -0
  94. package/global/lib/__pycache__/issue_models.cpython-314.pyc +0 -0
  95. package/global/lib/__pycache__/issue_provider.cpython-314.pyc +0 -0
  96. package/global/lib/__pycache__/linear_data_service.cpython-314.pyc +0 -0
  97. package/global/lib/__pycache__/linear_provider.cpython-314.pyc +0 -0
  98. package/global/lib/__pycache__/local_provider.cpython-314.pyc +0 -0
  99. package/global/lib/__pycache__/quality_service.cpython-314.pyc +0 -0
  100. package/global/lib/__pycache__/ralph_state.cpython-314.pyc +0 -0
  101. package/global/lib/__pycache__/state_manager.cpython-314.pyc +0 -0
  102. package/global/lib/__pycache__/transcript_parser.cpython-314.pyc +0 -0
  103. package/global/lib/__pycache__/verification_runner.cpython-314.pyc +0 -0
  104. package/global/lib/__pycache__/verify_iteration.cpython-314.pyc +0 -0
  105. package/global/lib/__pycache__/verify_subagent.cpython-314.pyc +0 -0
  106. package/global/lib/agent_registry.py +995 -0
  107. package/global/lib/anvil-state.sh +435 -0
  108. package/global/lib/claim_service.py +515 -0
  109. package/global/lib/coderabbit_service.py +314 -0
  110. package/global/lib/config_service.py +423 -0
  111. package/global/lib/coordination_service.py +331 -0
  112. package/global/lib/doc_coverage_service.py +1305 -0
  113. package/global/lib/gate_logger.py +316 -0
  114. package/global/lib/github_service.py +310 -0
  115. package/global/lib/handoff_generator.py +775 -0
  116. package/global/lib/hygiene_service.py +712 -0
  117. package/global/lib/issue_models.py +257 -0
  118. package/global/lib/issue_provider.py +339 -0
  119. package/global/lib/linear_data_service.py +210 -0
  120. package/global/lib/linear_provider.py +987 -0
  121. package/global/lib/linear_provider.py.backup +671 -0
  122. package/global/lib/local_provider.py +486 -0
  123. package/global/lib/orient_fast.py +457 -0
  124. package/global/lib/quality_service.py +470 -0
  125. package/global/lib/ralph_prompt_generator.py +563 -0
  126. package/global/lib/ralph_state.py +1202 -0
  127. package/global/lib/state_manager.py +417 -0
  128. package/global/lib/transcript_parser.py +597 -0
  129. package/global/lib/verification_runner.py +557 -0
  130. package/global/lib/verify_iteration.py +490 -0
  131. package/global/lib/verify_subagent.py +250 -0
  132. package/global/skills/README.md +155 -0
  133. package/global/skills/quality-gates/SKILL.md +252 -0
  134. package/global/skills/skill-template/SKILL.md +109 -0
  135. package/global/skills/testing-strategies/SKILL.md +337 -0
  136. package/global/templates/CHANGE-template.md +105 -0
  137. package/global/templates/HANDOFF-template.md +63 -0
  138. package/global/templates/PLAN-template.md +111 -0
  139. package/global/templates/SPEC-template.md +93 -0
  140. package/global/templates/ralph/PROMPT.md.template +89 -0
  141. package/global/templates/ralph/fix_plan.md.template +31 -0
  142. package/global/templates/ralph/progress.txt.template +23 -0
  143. package/global/tests/__pycache__/test_doc_coverage.cpython-314.pyc +0 -0
  144. package/global/tests/test_doc_coverage.py +520 -0
  145. package/global/tests/test_issue_models.py +299 -0
  146. package/global/tests/test_local_provider.py +323 -0
  147. package/global/tools/README.md +178 -0
  148. package/global/tools/__pycache__/anvil-hud.cpython-314.pyc +0 -0
  149. package/global/tools/anvil-hud.py +3622 -0
  150. package/global/tools/anvil-hud.py.bak +3318 -0
  151. package/global/tools/anvil-issue.py +432 -0
  152. package/global/tools/anvil-memory/CLAUDE.md +49 -0
  153. package/global/tools/anvil-memory/README.md +42 -0
  154. package/global/tools/anvil-memory/bun.lock +25 -0
  155. package/global/tools/anvil-memory/bunfig.toml +9 -0
  156. package/global/tools/anvil-memory/package.json +23 -0
  157. package/global/tools/anvil-memory/src/__tests__/ccs/context-monitor.test.ts +535 -0
  158. package/global/tools/anvil-memory/src/__tests__/ccs/edge-cases.test.ts +645 -0
  159. package/global/tools/anvil-memory/src/__tests__/ccs/fixtures.ts +363 -0
  160. package/global/tools/anvil-memory/src/__tests__/ccs/index.ts +8 -0
  161. package/global/tools/anvil-memory/src/__tests__/ccs/integration.test.ts +417 -0
  162. package/global/tools/anvil-memory/src/__tests__/ccs/prompt-generator.test.ts +571 -0
  163. package/global/tools/anvil-memory/src/__tests__/ccs/ralph-stop.test.ts +440 -0
  164. package/global/tools/anvil-memory/src/__tests__/ccs/test-utils.ts +252 -0
  165. package/global/tools/anvil-memory/src/__tests__/commands.test.ts +657 -0
  166. package/global/tools/anvil-memory/src/__tests__/db.test.ts +641 -0
  167. package/global/tools/anvil-memory/src/__tests__/hooks.test.ts +272 -0
  168. package/global/tools/anvil-memory/src/__tests__/performance.test.ts +427 -0
  169. package/global/tools/anvil-memory/src/__tests__/test-utils.ts +113 -0
  170. package/global/tools/anvil-memory/src/commands/checkpoint.ts +197 -0
  171. package/global/tools/anvil-memory/src/commands/get.ts +115 -0
  172. package/global/tools/anvil-memory/src/commands/init.ts +94 -0
  173. package/global/tools/anvil-memory/src/commands/observe.ts +163 -0
  174. package/global/tools/anvil-memory/src/commands/search.ts +112 -0
  175. package/global/tools/anvil-memory/src/db.ts +638 -0
  176. package/global/tools/anvil-memory/src/index.ts +205 -0
  177. package/global/tools/anvil-memory/src/types.ts +122 -0
  178. package/global/tools/anvil-memory/tsconfig.json +29 -0
  179. package/global/tools/ralph-loop.sh +359 -0
  180. package/package.json +45 -0
  181. package/scripts/anvil +822 -0
  182. package/scripts/extract_patterns.py +222 -0
  183. package/scripts/init-project.sh +541 -0
  184. package/scripts/install.sh +229 -0
  185. package/scripts/postinstall.js +41 -0
  186. package/scripts/rollback.sh +188 -0
  187. package/scripts/sync.sh +623 -0
  188. package/scripts/test-statusline.sh +248 -0
  189. package/scripts/update_claude_md.py +224 -0
  190. package/scripts/verify.sh +255 -0
@@ -0,0 +1,573 @@
1
+ ---
2
+ spec_id: SPEC-ANV-MEM
3
+ title: Anvil Memory System - Persistent Cross-Session Context
4
+ status: draft
5
+ created: 2026-01-07
6
+ updated: 2026-01-07
7
+ linear_issue: TBD
8
+ ---
9
+
10
+ # Anvil Memory System
11
+
12
+ ## Overview
13
+
14
+ Build a proprietary, ground-up persistent memory system for the Anvil framework. Anvil Memory provides cross-session context preservation, deeply integrated with the Context Checkpoint System (CCS), Ralph Wiggum autonomous execution, and Anvil workflows.
15
+
16
+ **This replaces Claude-Mem** with a purpose-built solution that:
17
+ - Uses per-project databases (no cross-contamination)
18
+ - Adds first-class CCS/Ralph observation types
19
+ - Integrates with Linear, sharding, and handoffs
20
+ - Uses Bun runtime (strategic alignment with Anthropic)
21
+
22
+ ## Background
23
+
24
+ ### Why Not Fork Claude-Mem?
25
+
26
+ | Factor | Claude-Mem | Anvil Memory |
27
+ |--------|------------|--------------|
28
+ | License | AGPL-3.0 (copyleft) | Proprietary |
29
+ | Database | Global (`~/.claude-mem/`) | Per-project (`.anvil/memory.db`) |
30
+ | Observation Types | Generic (6 types) | Extended for CCS/Ralph (10+ types) |
31
+ | Integration | Plugin-based | Native to Anvil |
32
+ | Control | External dependency | Full ownership |
33
+
34
+ ### Why Bun?
35
+
36
+ Anthropic acquired Bun (Oven) in December 2025:
37
+
38
+ - **Claude Code IS Bun** - Ships as Bun executable, users already have it
39
+ - **Strategic alignment** - Anthropic's chosen runtime for Claude tools
40
+ - **Native SQLite** - `bun:sqlite` is fast and synchronous
41
+ - **MIT licensed** - No licensing issues
42
+ - **Future-proof** - Claude Agent SDK and future tools are Bun-first
43
+
44
+ **Sources**:
45
+ - [Bun is joining Anthropic](https://bun.com/blog/bun-joins-anthropic)
46
+ - [Anthropic Acquires Bun](https://devops.com/anthropic-acquires-bun-to-accelerate-ai-coding-tools/)
47
+
48
+ ---
49
+
50
+ ## Design Decisions
51
+
52
+ ### Decision 1: Per-Project Databases
53
+
54
+ **Choice**: Each project gets its own SQLite database at `.anvil/memory.db`
55
+
56
+ **Rationale**:
57
+ - Users load Anvil framework into different projects
58
+ - No cross-contamination of memories between projects
59
+ - Portable - memory travels with project
60
+ - Simpler backup/restore per project
61
+ - Aligns with Anvil's project-centric model
62
+
63
+ **Trade-off**: Cannot search across projects (acceptable for isolation benefits)
64
+
65
+ ### Decision 2: Bun Runtime
66
+
67
+ **Choice**: Build with Bun (TypeScript)
68
+
69
+ **Rationale**:
70
+ - Claude Code users already have Bun installed
71
+ - Native SQLite support (`bun:sqlite`)
72
+ - Strategic alignment with Anthropic's tooling direction
73
+ - Fast startup and execution
74
+ - Single binary distribution possible
75
+
76
+ ### Decision 3: CLI Tool (Not Worker Service)
77
+
78
+ **Choice**: Direct CLI invocation, no background worker
79
+
80
+ **Rationale**:
81
+ - Simpler architecture (no port management, no daemon)
82
+ - Claude Code hooks can invoke directly
83
+ - `bun:sqlite` is synchronous - no worker needed
84
+ - Easier debugging and maintenance
85
+ - Lower resource footprint
86
+
87
+ **Trade-off**: Slightly slower per-invocation (acceptable for simplicity)
88
+
89
+ ### Decision 4: Proprietary License
90
+
91
+ **Choice**: Proprietary license (not open-source)
92
+
93
+ **Rationale**:
94
+ - User requirement
95
+ - Avoids AGPL copyleft obligations
96
+ - Full control over distribution and modifications
97
+
98
+ ---
99
+
100
+ ## Architecture
101
+
102
+ ### System Overview
103
+
104
+ ```
105
+ ┌─────────────────────────────────────────────────────────────────────┐
106
+ │ ANVIL MEMORY SYSTEM │
107
+ ├─────────────────────────────────────────────────────────────────────┤
108
+ │ │
109
+ │ CLI: anvil-memory (Bun executable) │
110
+ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
111
+ │ │ search │ │ timeline │ │ observe │ │ context │ │
112
+ │ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
113
+ │ │ │ │ │ │
114
+ │ └───────────────┴───────────────┴───────────────┘ │
115
+ │ │ │
116
+ │ ┌─────────▼─────────┐ │
117
+ │ │ AnvilMemory │ │
118
+ │ │ (Bun/TS lib) │ │
119
+ │ └─────────┬─────────┘ │
120
+ │ │ │
121
+ │ ┌─────────────────────────┼─────────────────────────┐ │
122
+ │ │ │ │ │
123
+ │ ┌──────▼──────┐ ┌───────────────▼───────────────┐ ┌──────▼─────┐│
124
+ │ │ Observation │ │ Checkpoint │ │ Ralph ││
125
+ │ │ Store │ │ Store │ │ Iteration ││
126
+ │ └─────────────┘ └───────────────────────────────┘ └────────────┘│
127
+ │ │ │
128
+ │ ┌─────────▼─────────┐ │
129
+ │ │ SQLite DB │ │
130
+ │ │ .anvil/memory.db │ │
131
+ │ └───────────────────┘ │
132
+ │ │
133
+ │ Hooks (Bun scripts in global/hooks/): │
134
+ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
135
+ │ │SessionStart│ │PostToolUse │ │ Stop │ │PreCompact │ │
136
+ │ │ (context) │ │ (observe) │ │ (summary) │ │(checkpoint)│ │
137
+ │ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
138
+ │ │
139
+ └─────────────────────────────────────────────────────────────────────┘
140
+ ```
141
+
142
+ ### Directory Structure
143
+
144
+ ```
145
+ anvil-dev-framework/
146
+ ├── global/
147
+ │ ├── tools/
148
+ │ │ └── anvil-memory/ # CLI tool
149
+ │ │ ├── src/
150
+ │ │ │ ├── index.ts # CLI entry point
151
+ │ │ │ ├── db.ts # SQLite operations
152
+ │ │ │ ├── types.ts # Type definitions
153
+ │ │ │ ├── observe.ts # Observation creation
154
+ │ │ │ ├── search.ts # Search operations
155
+ │ │ │ ├── timeline.ts # Timeline queries
156
+ │ │ │ └── context.ts # Context generation
157
+ │ │ ├── package.json
158
+ │ │ └── tsconfig.json
159
+ │ │
160
+ │ └── hooks/
161
+ │ ├── anvil_memory_session.ts # SessionStart hook
162
+ │ ├── anvil_memory_observe.ts # PostToolUse hook
163
+ │ ├── anvil_memory_stop.ts # Stop hook
164
+ │ └── anvil_memory_compact.ts # PreCompact hook
165
+
166
+ └── project/
167
+ └── .anvil/
168
+ └── memory.db # Per-project database
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Data Model
174
+
175
+ ### Database Schema
176
+
177
+ ```sql
178
+ -- Observations: Core records of work done
179
+ CREATE TABLE observations (
180
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
181
+ type TEXT NOT NULL, -- observation type
182
+ title TEXT NOT NULL, -- short title
183
+ subtitle TEXT, -- brief summary
184
+ content TEXT, -- full narrative/details
185
+ file_path TEXT, -- primary file affected
186
+ files TEXT, -- JSON array of files
187
+ concepts TEXT, -- JSON array of concept tags
188
+ project TEXT NOT NULL, -- project name
189
+ session_id INTEGER, -- FK to sessions
190
+ linear_issue TEXT, -- Linear issue key (e.g., "ANV-123")
191
+ tokens_read INTEGER DEFAULT 0, -- tokens to read this observation
192
+ tokens_work INTEGER DEFAULT 0, -- tokens spent creating this
193
+ created_at TEXT DEFAULT (datetime('now')),
194
+ created_at_epoch INTEGER DEFAULT (unixepoch() * 1000)
195
+ );
196
+
197
+ -- FTS5 for full-text search
198
+ CREATE VIRTUAL TABLE observations_fts USING fts5(
199
+ title, subtitle, content, file_path, concepts,
200
+ content='observations',
201
+ content_rowid='id'
202
+ );
203
+
204
+ -- Sessions: Conversation boundaries
205
+ CREATE TABLE sessions (
206
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
207
+ claude_session_id TEXT, -- Claude Code session ID
208
+ request TEXT, -- Initial user request
209
+ summary TEXT, -- AI-generated summary
210
+ project TEXT NOT NULL,
211
+ branch TEXT, -- Git branch
212
+ linear_issue TEXT, -- Primary issue worked on
213
+ context_peak_percent INTEGER, -- Highest context % reached
214
+ checkpoint_triggered BOOLEAN DEFAULT 0,
215
+ created_at TEXT DEFAULT (datetime('now')),
216
+ ended_at TEXT
217
+ );
218
+
219
+ CREATE VIRTUAL TABLE sessions_fts USING fts5(
220
+ request, summary,
221
+ content='sessions',
222
+ content_rowid='id'
223
+ );
224
+
225
+ -- Checkpoints: CCS checkpoint events
226
+ CREATE TABLE checkpoints (
227
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
228
+ session_id INTEGER NOT NULL,
229
+ level TEXT NOT NULL, -- L1, L2, L3
230
+ context_percent INTEGER NOT NULL,
231
+ trigger TEXT NOT NULL, -- "automatic", "manual", "ralph"
232
+ handoff_file TEXT, -- Path to handoff document
233
+ resume_summary TEXT, -- What to continue
234
+ files_in_progress TEXT, -- JSON array of {path, lines}
235
+ current_task TEXT, -- What was being worked on
236
+ task_progress TEXT, -- Percentage or description
237
+ linear_issue TEXT,
238
+ created_at TEXT DEFAULT (datetime('now')),
239
+ FOREIGN KEY (session_id) REFERENCES sessions(id)
240
+ );
241
+
242
+ -- Ralph Iterations: Ralph Wiggum loop tracking
243
+ CREATE TABLE ralph_iterations (
244
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
245
+ ralph_session_id TEXT NOT NULL, -- Ralph session identifier
246
+ iteration INTEGER NOT NULL,
247
+ context_peak_percent INTEGER,
248
+ checkpoint_triggered BOOLEAN DEFAULT 0,
249
+ todo_items_start INTEGER, -- Items remaining at start
250
+ todo_items_end INTEGER, -- Items remaining at end
251
+ items_completed TEXT, -- JSON array of completed items
252
+ status TEXT, -- "completed", "checkpoint", "error"
253
+ created_at TEXT DEFAULT (datetime('now')),
254
+ ended_at TEXT
255
+ );
256
+
257
+ -- Prompts: User messages (for conversation reconstruction)
258
+ CREATE TABLE prompts (
259
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
260
+ session_id INTEGER,
261
+ prompt TEXT NOT NULL,
262
+ project TEXT NOT NULL,
263
+ created_at TEXT DEFAULT (datetime('now')),
264
+ FOREIGN KEY (session_id) REFERENCES sessions(id)
265
+ );
266
+
267
+ CREATE VIRTUAL TABLE prompts_fts USING fts5(
268
+ prompt,
269
+ content='prompts',
270
+ content_rowid='id'
271
+ );
272
+
273
+ -- Indexes for common queries
274
+ CREATE INDEX idx_observations_type ON observations(type);
275
+ CREATE INDEX idx_observations_project ON observations(project);
276
+ CREATE INDEX idx_observations_session ON observations(session_id);
277
+ CREATE INDEX idx_observations_linear ON observations(linear_issue);
278
+ CREATE INDEX idx_observations_created ON observations(created_at_epoch DESC);
279
+ CREATE INDEX idx_sessions_project ON sessions(project);
280
+ CREATE INDEX idx_checkpoints_session ON checkpoints(session_id);
281
+ CREATE INDEX idx_ralph_session ON ralph_iterations(ralph_session_id);
282
+ ```
283
+
284
+ ### Observation Types
285
+
286
+ | Type | Source | Description |
287
+ |------|--------|-------------|
288
+ | `bugfix` | claude-mem | Bug fixes |
289
+ | `feature` | claude-mem | New features |
290
+ | `refactor` | claude-mem | Code restructuring |
291
+ | `discovery` | claude-mem | Things found during work |
292
+ | `decision` | claude-mem | Architectural/design choices |
293
+ | `change` | claude-mem | General changes |
294
+ | **`checkpoint`** | CCS | Context checkpoint event |
295
+ | **`ralph_iteration`** | Ralph | Autonomous loop iteration |
296
+ | **`handoff`** | Handoff | Session continuity document created |
297
+ | **`shard`** | Shard | Task breakdown event |
298
+ | **`linear_sync`** | Linear | Issue state change |
299
+
300
+ ### Concept Tags
301
+
302
+ | Concept | Description |
303
+ |---------|-------------|
304
+ | `how-it-works` | Technical explanation |
305
+ | `why-it-exists` | Rationale/motivation |
306
+ | `what-changed` | Diff/delta description |
307
+ | `problem-solution` | Problem and how it was solved |
308
+ | `gotcha` | Pitfall or non-obvious behavior |
309
+ | `pattern` | Reusable approach |
310
+ | `trade-off` | Decision with pros/cons |
311
+ | **`context-critical`** | Must preserve across checkpoints |
312
+ | **`ralph-continuation`** | Important for Ralph resume |
313
+
314
+ ---
315
+
316
+ ## CLI Interface
317
+
318
+ ### Commands
319
+
320
+ ```bash
321
+ # Initialize database for project
322
+ anvil-memory init
323
+
324
+ # Create observation
325
+ anvil-memory observe \
326
+ --type feature \
327
+ --title "Implemented OAuth callback" \
328
+ --content "Added OAuth callback handler..." \
329
+ --file src/auth/oauth.ts \
330
+ --linear ANV-123
331
+
332
+ # Search observations
333
+ anvil-memory search "authentication" --type bugfix --limit 10
334
+
335
+ # Get recent context (for session start)
336
+ anvil-memory context --limit 5 --format inject
337
+
338
+ # Timeline around observation
339
+ anvil-memory timeline --anchor 1234 --before 10 --after 10
340
+
341
+ # Record checkpoint
342
+ anvil-memory checkpoint \
343
+ --level L2 \
344
+ --percent 87 \
345
+ --handoff .claude/handoffs/2026-01-07-1145.md \
346
+ --task "Implementing OAuth callback" \
347
+ --progress "70%"
348
+
349
+ # Record Ralph iteration
350
+ anvil-memory ralph-iteration \
351
+ --session ralph-abc123 \
352
+ --iteration 5 \
353
+ --status completed \
354
+ --items-completed '["Fix test 1", "Fix test 2"]'
355
+
356
+ # Get session summary
357
+ anvil-memory session --current
358
+
359
+ # Export database
360
+ anvil-memory export --format json --output backup.json
361
+ ```
362
+
363
+ ### Hook Integration
364
+
365
+ **SessionStart Hook** (`anvil_memory_session.ts`):
366
+ ```typescript
367
+ // Loads recent context and injects into session
368
+ const context = await anvilMemory.getRecentContext({ limit: 5 });
369
+ return { additionalContext: context };
370
+ ```
371
+
372
+ **PostToolUse Hook** (`anvil_memory_observe.ts`):
373
+ ```typescript
374
+ // Analyzes tool output and creates observation if significant
375
+ if (shouldObserve(toolName, toolOutput)) {
376
+ await anvilMemory.observe({
377
+ type: classifyObservation(toolOutput),
378
+ title: extractTitle(toolOutput),
379
+ content: extractNarrative(toolOutput),
380
+ // ...
381
+ });
382
+ }
383
+ ```
384
+
385
+ **PreCompact Hook** (`anvil_memory_compact.ts`):
386
+ ```typescript
387
+ // Creates checkpoint before compaction
388
+ await anvilMemory.checkpoint({
389
+ level: 'L3',
390
+ trigger: 'auto-compact',
391
+ // ...
392
+ });
393
+ ```
394
+
395
+ ---
396
+
397
+ ## Integration Points
398
+
399
+ ### CCS Integration
400
+
401
+ Anvil Memory serves as the persistence layer for CCS:
402
+
403
+ | CCS Event | Anvil Memory Action |
404
+ |-----------|---------------------|
405
+ | L1 Warning | Log observation (type: `checkpoint`, level: L1) |
406
+ | L2 Handoff | Create checkpoint record + observation |
407
+ | L3 Emergency | Create checkpoint + handoff observation |
408
+ | Resume | Query `context` with checkpoint filter |
409
+
410
+ ### Ralph Integration
411
+
412
+ Anvil Memory tracks Ralph autonomous execution:
413
+
414
+ | Ralph Event | Anvil Memory Action |
415
+ |-------------|---------------------|
416
+ | Iteration start | Create ralph_iteration record |
417
+ | Iteration end | Update record with status |
418
+ | Checkpoint triggered | Link to checkpoints table |
419
+ | Task completed | Update items_completed |
420
+
421
+ ### Linear Integration
422
+
423
+ Observations link to Linear issues:
424
+
425
+ ```sql
426
+ -- Find all observations for an issue
427
+ SELECT * FROM observations WHERE linear_issue = 'ANV-123';
428
+
429
+ -- Get issue history timeline
430
+ SELECT * FROM observations
431
+ WHERE linear_issue = 'ANV-123'
432
+ ORDER BY created_at_epoch;
433
+ ```
434
+
435
+ ---
436
+
437
+ ## Requirements
438
+
439
+ ### Core Requirements
440
+
441
+ | ID | Requirement | Priority |
442
+ |----|-------------|----------|
443
+ | MEM-001 | Per-project SQLite database at `.anvil/memory.db` | P0 |
444
+ | MEM-002 | CLI tool `anvil-memory` built with Bun | P0 |
445
+ | MEM-003 | Full-text search via FTS5 | P0 |
446
+ | MEM-004 | SessionStart hook for context injection | P0 |
447
+ | MEM-005 | PostToolUse hook for observation capture | P0 |
448
+ | MEM-006 | Support all observation types (10+) | P0 |
449
+
450
+ ### CCS Integration Requirements
451
+
452
+ | ID | Requirement | Priority |
453
+ |----|-------------|----------|
454
+ | MEM-010 | Checkpoint records with level, percent, handoff | P0 |
455
+ | MEM-011 | Query checkpoints for resume context | P0 |
456
+ | MEM-012 | Link observations to checkpoints | P1 |
457
+
458
+ ### Ralph Integration Requirements
459
+
460
+ | ID | Requirement | Priority |
461
+ |----|-------------|----------|
462
+ | MEM-020 | Ralph iteration tracking table | P0 |
463
+ | MEM-021 | Link iterations to checkpoints | P0 |
464
+ | MEM-022 | Query iteration history for patterns | P1 |
465
+
466
+ ### Context Generation Requirements
467
+
468
+ | ID | Requirement | Priority |
469
+ |----|-------------|----------|
470
+ | MEM-030 | Generate context summary for session start | P0 |
471
+ | MEM-031 | Progressive disclosure (index → full) | P1 |
472
+ | MEM-032 | Token budget awareness in context | P1 |
473
+ | MEM-033 | Filter by type, date, file, concept | P1 |
474
+
475
+ ---
476
+
477
+ ## Implementation Phases
478
+
479
+ ### Phase 1: Core Database and CLI (Week 1)
480
+
481
+ 1. Set up Bun project structure
482
+ 2. Implement SQLite schema with migrations
483
+ 3. Create `anvil-memory` CLI with basic commands:
484
+ - `init` - Create database
485
+ - `observe` - Create observation
486
+ - `search` - Query observations
487
+ 4. Write unit tests
488
+
489
+ ### Phase 2: Hooks Integration (Week 2)
490
+
491
+ 1. Create SessionStart hook for context injection
492
+ 2. Create PostToolUse hook for observation capture
493
+ 3. Create Stop hook for session summary
494
+ 4. Integrate with existing Anvil hook system
495
+
496
+ ### Phase 3: CCS Integration (Week 2-3)
497
+
498
+ 1. Add checkpoints table and CLI commands
499
+ 2. Create PreCompact hook for checkpoint creation
500
+ 3. Implement checkpoint resume context generation
501
+ 4. Test CCS → Memory → Resume flow
502
+
503
+ ### Phase 4: Ralph Integration (Week 3)
504
+
505
+ 1. Add ralph_iterations table
506
+ 2. Integrate with `ralph_state.py` (or rewrite in TS)
507
+ 3. Link Ralph iterations to checkpoints
508
+ 4. Test full Ralph → Checkpoint → Resume cycle
509
+
510
+ ### Phase 5: Polish and Optimization (Week 4)
511
+
512
+ 1. Performance optimization (indexes, caching)
513
+ 2. Context budget management
514
+ 3. Export/import functionality
515
+ 4. Documentation and examples
516
+
517
+ ---
518
+
519
+ ## Migration from Claude-Mem
520
+
521
+ ### Coexistence Period
522
+
523
+ During development, both systems can coexist:
524
+ - Claude-Mem: Global `~/.claude-mem/`
525
+ - Anvil Memory: Per-project `.anvil/memory.db`
526
+
527
+ ### Migration Path
528
+
529
+ 1. **Phase 1**: Anvil Memory runs alongside Claude-Mem
530
+ 2. **Phase 2**: Anvil hooks replace Claude-Mem hooks in Anvil projects
531
+ 3. **Phase 3**: Claude-Mem can be uninstalled for Anvil users
532
+
533
+ ### Data Migration (Optional)
534
+
535
+ ```bash
536
+ # Export Claude-Mem data for project
537
+ anvil-memory import --from claude-mem --project my-project
538
+ ```
539
+
540
+ ---
541
+
542
+ ## Success Metrics
543
+
544
+ | Metric | Target |
545
+ |--------|--------|
546
+ | Session context load time | <500ms |
547
+ | Observation capture latency | <100ms |
548
+ | Search query time | <200ms |
549
+ | Database size per 1000 observations | <10MB |
550
+ | Context resume accuracy | >95% useful |
551
+
552
+ ---
553
+
554
+ ## Open Questions (Resolved)
555
+
556
+ | Question | Decision |
557
+ |----------|----------|
558
+ | Open-source or proprietary? | **Proprietary** |
559
+ | Coexist or replace Claude-Mem? | **Replace** |
560
+ | Worker service or direct CLI? | **CLI** (direct) |
561
+ | MCP server or CLI? | **CLI** |
562
+ | Global or per-project DB? | **Per-project** |
563
+ | Node.js or Bun? | **Bun** (Anthropic-owned) |
564
+
565
+ ---
566
+
567
+ ## References
568
+
569
+ - [Bun is joining Anthropic](https://bun.com/blog/bun-joins-anthropic)
570
+ - [Anthropic Acquires Bun](https://devops.com/anthropic-acquires-bun-to-accelerate-ai-coding-tools/)
571
+ - Claude-Mem architecture analysis (internal)
572
+ - CCS Specification: `docs/specifications/SPEC-ANV-context-checkpoints.md`
573
+ - Ralph Wiggum: `global/lib/ralph_state.py`, `global/commands/ralph.md`