claude_memory 0.6.0 → 0.7.1

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/CLAUDE.md +1 -1
  3. data/.claude/memory.sqlite3 +0 -0
  4. data/.claude/memory.sqlite3-shm +0 -0
  5. data/.claude/memory.sqlite3-wal +0 -0
  6. data/.claude/settings.local.json +13 -1
  7. data/.claude-plugin/marketplace.json +1 -1
  8. data/.claude-plugin/plugin.json +1 -2
  9. data/.gitattributes +1 -0
  10. data/CHANGELOG.md +61 -0
  11. data/CLAUDE.md +4 -2
  12. data/README.md +1 -1
  13. data/docs/improvements.md +164 -22
  14. data/docs/influence/lossless-claw.md +409 -0
  15. data/docs/influence/qmd.md +201 -130
  16. data/docs/quality_review.md +344 -56
  17. data/lib/claude_memory/commands/checks/database_check.rb +7 -0
  18. data/lib/claude_memory/commands/compact_command.rb +10 -0
  19. data/lib/claude_memory/commands/export_command.rb +14 -6
  20. data/lib/claude_memory/commands/git_lfs_command.rb +117 -0
  21. data/lib/claude_memory/commands/index_command.rb +30 -2
  22. data/lib/claude_memory/commands/registry.rb +2 -1
  23. data/lib/claude_memory/commands/serve_mcp_command.rb +10 -1
  24. data/lib/claude_memory/commands/stats_command.rb +12 -1
  25. data/lib/claude_memory/configuration.rb +40 -1
  26. data/lib/claude_memory/core/snippet_extractor.rb +21 -19
  27. data/lib/claude_memory/index/lexical_fts.rb +88 -16
  28. data/lib/claude_memory/ingest/ingester.rb +1 -1
  29. data/lib/claude_memory/mcp/error_classifier.rb +171 -0
  30. data/lib/claude_memory/mcp/instructions_builder.rb +62 -4
  31. data/lib/claude_memory/mcp/query_guide.rb +41 -22
  32. data/lib/claude_memory/mcp/response_formatter.rb +3 -1
  33. data/lib/claude_memory/mcp/server.rb +1 -0
  34. data/lib/claude_memory/mcp/text_summary.rb +2 -1
  35. data/lib/claude_memory/mcp/tool_definitions.rb +54 -23
  36. data/lib/claude_memory/mcp/tools.rb +33 -16
  37. data/lib/claude_memory/recall.rb +51 -5
  38. data/lib/claude_memory/resolve/resolver.rb +22 -18
  39. data/lib/claude_memory/store/store_manager.rb +19 -24
  40. data/lib/claude_memory/sweep/maintenance.rb +126 -0
  41. data/lib/claude_memory/sweep/sweeper.rb +82 -67
  42. data/lib/claude_memory/version.rb +1 -1
  43. data/lib/claude_memory.rb +8 -0
  44. data/v0.6.0.ANNOUNCE +32 -0
  45. metadata +10 -1
@@ -0,0 +1,409 @@
1
+ # Lossless Claw Analysis
2
+
3
+ *Analysis Date: 2026-03-16*
4
+ *Repository: https://github.com/martian-engineering/lossless-claw*
5
+ *Version: 0.3.0 (commit 49949fb)*
6
+
7
+ ---
8
+
9
+ ## Executive Summary
10
+
11
+ **Lossless Claw** is a TypeScript plugin for OpenClaw that implements **Lossless Context Management (LCM)** — a DAG-based summarization system that replaces sliding-window context compaction. Instead of discarding old messages, it compresses them into a hierarchy of summaries while preserving every original message in SQLite.
12
+
13
+ **Key Innovation**: Depth-aware summarization DAG with three-level escalation (normal → aggressive → deterministic fallback), ensuring compaction always succeeds. Agents can drill into any summary to recover original detail via `lcm_expand_query`.
14
+
15
+ | Aspect | Detail |
16
+ |--------|--------|
17
+ | Language | TypeScript (~34K LOC) + Go TUI |
18
+ | Storage | SQLite (WAL mode, optional FTS5) |
19
+ | Framework | OpenClaw plugin (ContextEngine interface) |
20
+ | Testing | Vitest, 20 test files, ~153K lines |
21
+ | Author | Josh Lehman / Martian Engineering |
22
+ | License | MIT |
23
+ | Maturity | Pre-1.0 but production-quality |
24
+ | Docs | 5 detailed guides + 6 design specs |
25
+
26
+ **Production Readiness**: High. Comprehensive test suite, extensive documentation, structured release process (Changesets + GitHub Actions), depth-aware prompts, crash recovery via session reconciliation.
27
+
28
+ ---
29
+
30
+ ## Architecture Overview
31
+
32
+ ### Data Model
33
+
34
+ **Conversations → Messages → Summaries (DAG)**
35
+
36
+ ```
37
+ messages (raw, with message_parts)
38
+ ↓ leaf compaction
39
+ summaries (depth 0, kind="leaf")
40
+ ↓ condensation
41
+ summaries (depth 1+, kind="condensed")
42
+ ↓ condensation
43
+ summaries (depth 2+, ...)
44
+ ```
45
+
46
+ - **conversations**: session_id, title, bootstrapped_at
47
+ - **messages**: role, content, token_count, seq (monotonic)
48
+ - **message_parts**: 10 columns for polymorphic content (text, tool calls, reasoning, patches, files)
49
+ - **summaries**: summaryId (SHA-256), kind, depth, token_count, earliest_at/latest_at, descendant_count, file_ids
50
+ - **summary_parents**: DAG edges (parent-child relationships)
51
+ - **context_items**: Ordered list of what model sees (references messages or summaries)
52
+ - **large_files**: Intercepted files >25K tokens with exploration summaries
53
+
54
+ ### Design Patterns
55
+
56
+ | Pattern | Location | Purpose |
57
+ |---------|----------|---------|
58
+ | Dependency Injection | `src/types.ts:92-149` | LcmDependencies interface decouples from OpenClaw |
59
+ | Factory Methods | `src/tools/*.ts` (createLcmXxxTool) | Dynamic tool construction |
60
+ | Strategy | `src/expansion-policy.ts` | Route-vs-delegate decision matrix |
61
+ | Decorator | `src/expansion-auth.ts` | AuthorizedOrchestrator wraps base for budgets |
62
+ | Reference Counting | `src/db/connection.ts:29-52` | SQLite connection pool |
63
+ | DAG Traversal | `src/expansion.ts:116-165` | Token-budgeted graph walk |
64
+ | Three-Level Escalation | `src/summarize.ts` | Normal → aggressive → fallback truncation |
65
+
66
+ ### Module Organization
67
+
68
+ ```
69
+ index.ts # Plugin registration + multi-tier auth (1325 lines)
70
+ src/
71
+ ├── engine.ts # ContextEngine lifecycle (1825 lines)
72
+ ├── assembler.ts # Context reconstruction
73
+ ├── compaction.ts # CompactionEngine with leaf + condensation passes
74
+ ├── summarize.ts # Depth-aware prompts + LLM summarization
75
+ ├── expansion.ts # DAG expansion orchestrator
76
+ ├── expansion-auth.ts # Delegation grants with token caps + TTL
77
+ ├── expansion-policy.ts # Route-vs-delegate decision matrix
78
+ ├── retrieval.ts # grep/describe/expand query interface
79
+ ├── large-files.ts # File interception (>25K tokens)
80
+ ├── integrity.ts # DAG repair
81
+ ├── transcript-repair.ts # Tool-use/result pairing sanitization
82
+ ├── types.ts # DI contracts
83
+ ├── db/
84
+ │ ├── connection.ts # Ref-counted SQLite pooling
85
+ │ ├── config.ts # 13 env vars with 3-tier precedence
86
+ │ ├── migration.ts # Schema migrations with cycle protection
87
+ │ └── features.ts # Runtime FTS5 detection + caching
88
+ ├── store/
89
+ │ ├── conversation-store.ts # Message CRUD + search
90
+ │ ├── summary-store.ts # DAG persistence + lineage queries
91
+ │ ├── fts5-sanitize.ts # FTS5 query sanitization
92
+ │ └── full-text-fallback.ts # LIKE-based fallback
93
+ └── tools/
94
+ ├── lcm-grep-tool.ts # Regex + full-text search
95
+ ├── lcm-describe-tool.ts # Summary/file metadata inspection
96
+ ├── lcm-expand-tool.ts # Low-level DAG expansion (sub-agent)
97
+ └── lcm-expand-query-tool.ts # Main agent expansion wrapper
98
+ ```
99
+
100
+ ### Comparison vs ClaudeMemory
101
+
102
+ | Aspect | Lossless Claw | ClaudeMemory |
103
+ |--------|---------------|--------------|
104
+ | **Domain** | Context management (conversation compression) | Knowledge management (fact extraction) |
105
+ | **Storage Model** | Messages + summary DAG | SPO triples with provenance |
106
+ | **Compaction** | Depth-aware DAG summarization | Sweep (prune expired/superseded facts) |
107
+ | **Search** | FTS5 + regex on messages/summaries | FTS5 + sqlite-vec on facts |
108
+ | **Recall** | grep → describe → expand_query escalation | recall → explain → fact_graph |
109
+ | **Scope** | Per-conversation | Global + project dual-database |
110
+ | **Language** | TypeScript | Ruby |
111
+ | **LLM Integration** | Heavy (summarization on every compaction) | Light (NullDistiller, future extraction) |
112
+ | **Plugin Format** | OpenClaw ContextEngine | Claude Code plugin + MCP |
113
+ | **Truth Maintenance** | Summaries supersede messages | Resolver with predicate policies |
114
+ | **Sub-agents** | Delegation grants for expansion | None (MCP tools only) |
115
+
116
+ ---
117
+
118
+ ## Key Components Deep-Dive
119
+
120
+ ### 1. Compaction Engine (`src/compaction.ts`)
121
+
122
+ The heart of LCM. Implements incremental and full-sweep compaction:
123
+
124
+ **Leaf Pass** (lines 222-400):
125
+ - Protects "fresh tail" (default 32 recent messages)
126
+ - Chunks messages up to `leafChunkTokens` (20K default)
127
+ - Summarizes with leaf-specific prompt
128
+ - Three-level escalation ensures progress
129
+
130
+ **Condensation Pass** (lines 400-600):
131
+ - Merges same-depth summaries into higher-level nodes
132
+ - Minimum fanout: 8 for leaves, 4 for condensed
133
+ - Hard minimum: 2 (for forced compaction under pressure)
134
+ - Depth-appropriate prompts (d1, d2, d3+)
135
+
136
+ **Token Budget Management** (lines 170-222):
137
+ - Threshold-based triggering (default 75% of context window)
138
+ - `compactUntilUnder()`: Repeated sweeps until budget met
139
+
140
+ ### 2. Depth-Aware Prompts (`tui/prompts/`)
141
+
142
+ Different summarization strategies per DAG level:
143
+
144
+ - **leaf.tmpl** (d0): Narrative preservation with timestamps, file tracking
145
+ - **condensed-d1.tmpl** (d1): Chronological narrative, delta-oriented
146
+ - **condensed-d2.tmpl** (d2): Arc-focused (goal → outcome → what carries forward)
147
+ - **condensed-d3.tmpl** (d3+): Maximum abstraction, durable context only
148
+
149
+ This is the most novel pattern — summaries at different depths serve different purposes.
150
+
151
+ ### 3. Expansion Policy (`src/expansion-policy.ts:39-303`)
152
+
153
+ Intelligent routing for recall queries:
154
+
155
+ **Decision Matrix** (lines 215-303):
156
+ - `answer_directly`: No candidates or low-complexity probe
157
+ - `expand_shallow`: Direct expansion (depth ≤ 2, 1 candidate, low token risk)
158
+ - `delegate_traversal`: Sub-agent for deep/broad queries
159
+
160
+ **Token Risk Classification** (lines 189-205):
161
+ - Low: ratio < 0.35
162
+ - Moderate: 0.35–0.70
163
+ - High: ≥ 0.70
164
+
165
+ **Indicators** (lines 95-146):
166
+ - Broad time range detection via regex + year span
167
+ - Multi-hop detection via query language + depth/breadth heuristics
168
+
169
+ ### 4. Context Assembly (`src/assembler.ts:206+`)
170
+
171
+ Reconstructs model context from DAG:
172
+
173
+ 1. Fetch all context_items ordered by ordinal
174
+ 2. Resolve each (summaries → XML user messages; messages → reconstructed from parts)
175
+ 3. Split into evictable prefix + protected fresh tail
176
+ 4. Fill remaining budget from evictable set (newest first)
177
+ 5. Normalize assistant content to array blocks
178
+ 6. Sanitize tool-use/result pairing
179
+
180
+ **XML Summary Format**:
181
+ ```xml
182
+ <summary id="sum_abc123" kind="leaf" depth="0" descendant_count="5"
183
+ earliest_at="2026-02-17T07:37:00" latest_at="2026-02-17T08:23:00">
184
+ <content>...summary text...</content>
185
+ </summary>
186
+ ```
187
+
188
+ ### 5. Sub-Agent Delegation (`src/expansion-auth.ts`, `src/tools/lcm-expand-tool.delegation.ts`)
189
+
190
+ Secure sub-agent spawning for deep recall:
191
+
192
+ - **Delegation grants**: Token budget + conversation scope + TTL per sub-agent
193
+ - **Session key parsing**: `agent:<agentId>:<subagent|suffix...>`
194
+ - **Recursion guard**: Prevents recursive sub-agent spawning
195
+ - **Multi-pass execution**: Round-based with pass tracking and budget enforcement
196
+ - **Observability**: Status (ok/timeout/error) with runId collection
197
+
198
+ ### 6. Large File Handling (`src/large-files.ts`)
199
+
200
+ Files >25K tokens intercepted at ingestion:
201
+ - Stored separately with lightweight exploration summaries (~200 tokens)
202
+ - Replaced with compact reference in context
203
+ - Accessible via `lcm_describe` tool
204
+ - MIME type inference from extension
205
+
206
+ ### 7. Go TUI (`tui/`)
207
+
208
+ Interactive terminal built with Bubbletea for database inspection:
209
+ - Browse agents → sessions → conversations → DAG/context/files
210
+ - **Rewrite**: Re-summarize with current prompts
211
+ - **Dissolve**: Undo condensation, restore parent summaries
212
+ - **Repair**: Fix corrupted summaries (fallback markers)
213
+ - **Transplant**: Copy DAG across conversations
214
+ - **Backfill**: Import pre-LCM sessions
215
+
216
+ ---
217
+
218
+ ## Comparative Analysis
219
+
220
+ ### What They Do Well
221
+
222
+ 1. **Depth-aware summarization** — Different prompts per DAG level is brilliant. Leaf summaries preserve detail; high-depth condensations abstract to durable themes. We have no analogous graduated abstraction.
223
+
224
+ 2. **Three-level escalation** — Ensures compaction always succeeds. Normal → aggressive → deterministic fallback prevents infinite loops or stalled compaction. Robust production pattern.
225
+
226
+ 3. **Sub-agent delegation for deep recall** — Token-budgeted sub-agents for deep DAG traversal. Keeps main agent context lean while enabling arbitrary depth exploration.
227
+
228
+ 4. **Context assembly pipeline** — Sophisticated reconstruction with fresh tail protection, budget-aware eviction, tool-use pairing sanitization. We don't manage context assembly at all.
229
+
230
+ 5. **Session reconciliation** — Handles crashes by comparing JSONL ground truth with database state. Resilient to interrupted operations.
231
+
232
+ 6. **TUI for debugging** — Interactive inspection of the entire summary DAG, with ability to rewrite, dissolve, and repair summaries. We have CLI commands but no interactive debugging.
233
+
234
+ ### What We Do Well
235
+
236
+ 1. **Structured knowledge extraction** — SPO triples with provenance vs raw message compression. Our facts are queryable, scopable, and support truth maintenance. Their summaries are opaque text.
237
+
238
+ 2. **Dual-database scope system** — Global vs project separation. They operate per-conversation only.
239
+
240
+ 3. **Truth maintenance** — Resolver with predicate policies, supersession, and conflict detection. They have no equivalent — new summaries just replace old ones.
241
+
242
+ 4. **Semantic search** — sqlite-vec with fastembed-rb for embedding-based retrieval. They rely on FTS5/LIKE only.
243
+
244
+ 5. **Lightweight architecture** — No LLM calls in the hot path (retrieval). Their every compaction requires LLM summarization ($$$).
245
+
246
+ 6. **Entity extraction** — Named entity tracking with aliases. They store raw conversation content with no entity model.
247
+
248
+ ### Trade-offs
249
+
250
+ | Trade-off | Lossless Claw | ClaudeMemory |
251
+ |-----------|---------------|--------------|
252
+ | LLM cost | High (summarization per compaction) | Low (no LLM in recall) |
253
+ | Information loss | Very low (DAG preserves originals) | Some (fact distillation is lossy) |
254
+ | Query flexibility | Strong (grep + expand into originals) | Strong (FTS + vector + hybrid) |
255
+ | Context quality | Excellent (assembled with summaries) | Good (published snapshot) |
256
+ | Scope model | Per-conversation | Global + project |
257
+ | Maintenance | Complex (DAG integrity, repair) | Simple (sweep expired/superseded) |
258
+ | Startup cost | High (bootstrap + reconciliation) | Low (read-only at startup) |
259
+
260
+ ---
261
+
262
+ ## Adoption Opportunities
263
+
264
+ ### High Priority ⭐
265
+
266
+ #### 1. Depth-Aware Prompt Templates for Distiller ⭐
267
+
268
+ - **Value**: When we build a real distiller (replacing NullDistiller), use graduated extraction prompts based on context depth. Fresh conversations get detailed extraction; well-established facts get consolidation prompts. Parallels their leaf/d1/d2/d3+ prompt hierarchy.
269
+ - **Evidence**: `tui/prompts/leaf.tmpl`, `tui/prompts/condensed-d1.tmpl`, `tui/prompts/condensed-d2.tmpl`, `tui/prompts/condensed-d3.tmpl` — four distinct prompt templates with increasing abstraction
270
+ - **Implementation**: Create prompt templates for distiller stages: initial extraction (detailed), re-extraction (consolidation), contradiction resolution (focused). Use depth/freshness to select template.
271
+ - **Effort**: 1-2 days (when building real distiller)
272
+ - **Trade-off**: Complexity in managing multiple prompt variants
273
+ - **Recommendation**: ADOPT — core insight for distiller design
274
+
275
+ #### 2. Three-Level Escalation for Sweep/Maintenance ⭐
276
+
277
+ - **Value**: Our sweep operations can stall on edge cases (large datasets, locked databases). A normal → aggressive → fallback escalation pattern ensures maintenance always completes. Prevents stuck states.
278
+ - **Evidence**: `src/summarize.ts` — three escalation levels with deterministic fallback; `src/compaction.ts:170-222` — budget-targeted sweeps
279
+ - **Implementation**: Apply to Sweep module: normal sweep (time-bounded) → aggressive sweep (wider scope, less selective) → fallback (force-expire oldest, skip integrity checks). Return status indicating which level was needed.
280
+ - **Effort**: 1-2 days
281
+ - **Trade-off**: Aggressive/fallback modes may be too aggressive
282
+ - **Recommendation**: ADOPT — robustness pattern
283
+
284
+ #### 3. Tool Escalation Workflow in MCP Instructions ⭐
285
+
286
+ - **Value**: Their `lcm_grep → lcm_describe → lcm_expand_query` escalation pattern is explicitly documented in assembler system prompts, teaching agents when to use cheap vs expensive tools. Our MCP guide prompt could adopt this pattern.
287
+ - **Evidence**: `src/assembler.ts:51-112` — system prompt additions with tool escalation hierarchy and precision checklist
288
+ - **Implementation**: Update QueryGuide module to include explicit tool escalation: `memory.recall` (fast, broad) → `memory.recall_details` (targeted) → `memory.explain` (deep provenance) → `memory.fact_graph` (relationship exploration). Add cost/speed annotations per tool.
289
+ - **Effort**: 0.5 days
290
+ - **Trade-off**: None — pure documentation improvement
291
+ - **Recommendation**: ADOPT — immediate win
292
+
293
+ ### Medium Priority
294
+
295
+ #### 4. Connection Health Probing
296
+
297
+ - **Value**: Their connection pooling includes health checks before reuse (`src/db/connection.ts:12-19`). Our StoreManager creates connections but doesn't verify they're healthy before returning them.
298
+ - **Evidence**: `src/db/connection.ts:5-52` — reference-counted pooling with probe query
299
+ - **Implementation**: Add `db.execute("SELECT 1")` health check to StoreManager before returning connections. Cache healthy connections, recreate on failure.
300
+ - **Effort**: 0.5 days
301
+ - **Trade-off**: Slight overhead per connection acquisition
302
+ - **Recommendation**: CONSIDER — defensive measure
303
+
304
+ #### 5. Token Budget Tracking for Recall
305
+
306
+ - **Value**: Their expansion system tracks token budgets meticulously — remaining tokens, cost per operation, budget enforcement. Could apply to our recall to prevent oversized responses.
307
+ - **Evidence**: `src/expansion-auth.ts` — grant-based budgeting; `src/expansion-policy.ts:189-205` — token risk classification
308
+ - **Implementation**: Add optional `max_tokens` param to recall tools. Track response size, truncate gracefully with "more results available" indicator.
309
+ - **Effort**: 1-2 days
310
+ - **Trade-off**: Additional parameter complexity
311
+ - **Recommendation**: CONSIDER — useful for large databases
312
+
313
+ #### 6. Conversation-Scoped Context Injection
314
+
315
+ - **Value**: Their assembler adds depth-aware guidance to system prompts when conversations are heavily compacted. We could inject similar context about fact density/recency in our SessionStart hook.
316
+ - **Evidence**: `src/assembler.ts:62-112` — conditional system prompt additions based on compaction depth
317
+ - **Implementation**: In hook context injection, include metadata: fact count, recent changes count, conflict count. When conflicts > 0, add advisory note.
318
+ - **Effort**: 1 day
319
+ - **Trade-off**: Slightly larger context injection
320
+ - **Recommendation**: CONSIDER — enhances existing hook context
321
+
322
+ ### Low Priority
323
+
324
+ #### 7. Interactive DAG/Fact Browser TUI
325
+
326
+ - **Value**: Their Go TUI with Bubbletea is impressive for debugging. A similar interactive fact browser could help users understand their knowledge graph.
327
+ - **Evidence**: `tui/main.go` + `tui/data.go` — full Bubbletea application
328
+ - **Implementation**: Would require a Go or Ruby TUI library (e.g., tty-prompt, pastel)
329
+ - **Effort**: 3-5 days
330
+ - **Trade-off**: Significant new dependency, maintenance burden
331
+ - **Recommendation**: DEFER — CLI commands are sufficient for now
332
+
333
+ #### 8. Large Content Interception
334
+
335
+ - **Value**: Their large file processor intercepts >25K token files and replaces them with compact summaries. Could apply to our ingester for very large transcript segments.
336
+ - **Evidence**: `src/large-files.ts` — file interception with exploration summaries
337
+ - **Implementation**: During ingest, if a content item exceeds threshold, store a summary reference instead of full content.
338
+ - **Effort**: 2 days
339
+ - **Trade-off**: Requires LLM call for summarization
340
+ - **Recommendation**: DEFER — our transcripts are already chunked
341
+
342
+ ### Features to Avoid
343
+
344
+ - **DAG-Based Compaction** — Fundamentally different paradigm from fact extraction. Their approach compresses conversations; ours distills knowledge. These are complementary, not competing.
345
+ - **Per-Conversation Scoping** — Our dual-database (global/project) is more useful for knowledge that spans conversations.
346
+ - **LLM-Heavy Pipeline** — Every compaction requires LLM calls. Our lightweight retrieval path (no LLM) is a significant advantage.
347
+ - **Go TUI** — Adding a second language (Go) for a debugging tool is over-engineering for our use case.
348
+ - **Message Parts Polymorphism** — Their 10-column message_parts table handles tool calls, reasoning, patches, etc. We don't store raw messages, so this is irrelevant.
349
+ - **OpenClaw ContextEngine Interface** — Tight coupling to their framework. Our MCP + hooks approach is more portable.
350
+ - **Sub-Agent Delegation for Recall** — Spawning sub-agents adds latency and complexity. Our MCP tools return results directly, which is simpler and faster. (Note: we already have #8 Search Agent Delegation in improvements.md for a lighter-weight version.)
351
+ - **Session Reconciliation** — Crash recovery by comparing JSONL with DB. We use atomic transactions and don't need recovery logic.
352
+ - **OAuth Refresh for API Keys** — Multi-provider auth chain is OpenClaw-specific complexity we don't need.
353
+
354
+ ---
355
+
356
+ ## Implementation Recommendations
357
+
358
+ ### Phase 1: Quick Wins (1-2 days)
359
+
360
+ 1. **Tool Escalation Workflow** (#3) — Update QueryGuide with explicit tool hierarchy and cost annotations
361
+ 2. **Connection Health Probing** (#4) — Add health check to StoreManager
362
+
363
+ ### Phase 2: Robustness (2-3 days)
364
+
365
+ 3. **Three-Level Escalation for Sweep** (#2) — Add escalation pattern to maintenance operations
366
+ 4. **Token Budget Tracking** (#5) — Optional max_tokens for recall
367
+
368
+ ### Phase 3: Future Distiller Design (when building distiller)
369
+
370
+ 5. **Depth-Aware Prompt Templates** (#1) — Graduated extraction prompts based on context
371
+ 6. **Conversation-Scoped Context** (#6) — Dynamic metadata in hook injection
372
+
373
+ ---
374
+
375
+ ## Architecture Decisions
376
+
377
+ ### What to Preserve (Our Advantages)
378
+ - SPO triple model with provenance — more structured than opaque summaries
379
+ - Dual-database scope system — more flexible than per-conversation
380
+ - No-LLM retrieval path — cheaper and faster
381
+ - Truth maintenance with predicate policies — they have no equivalent
382
+ - sqlite-vec semantic search — they only have FTS5/LIKE
383
+
384
+ ### What to Adopt
385
+ - Three-level escalation pattern for operations that must succeed
386
+ - Tool escalation documentation in MCP instructions
387
+ - Depth-aware prompts when building real distiller
388
+ - Connection health probing as defensive measure
389
+
390
+ ### What to Reject
391
+ - DAG-based conversation compaction (different paradigm)
392
+ - LLM-heavy pipeline (cost and latency)
393
+ - Go TUI (wrong trade-off for our project)
394
+ - OpenClaw-specific patterns (framework coupling)
395
+ - Sub-agent delegation (complexity vs benefit for our use case)
396
+
397
+ ---
398
+
399
+ ## Key Takeaways
400
+
401
+ 1. **Different problem, different solution**: LCM compresses conversations; we extract knowledge. Both are valid approaches to "memory" but serve fundamentally different purposes. There's no architectural adoption to make — the patterns worth adopting are tactical, not structural.
402
+
403
+ 2. **Depth-aware prompts are the key insight**: Their graduated prompt strategy (detail at leaves, abstraction at depth) is the most transferable concept. When we build a real distiller, this should inform prompt design.
404
+
405
+ 3. **Escalation patterns ensure robustness**: Their three-level escalation (normal → aggressive → fallback) is a production-quality pattern we should adopt for any operation that must succeed.
406
+
407
+ 4. **Tool escalation workflow is immediately actionable**: Documenting cheap-to-expensive tool progression in our MCP instructions is a zero-cost improvement.
408
+
409
+ 5. **Our approach has clear advantages**: Structured facts, semantic search, no-LLM retrieval, and truth maintenance are strengths we should preserve. Their LLM-heavy pipeline is a significant cost/complexity trade-off.