superlocalmemory 2.3.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.
Files changed (100) hide show
  1. package/ATTRIBUTION.md +140 -0
  2. package/CHANGELOG.md +1749 -0
  3. package/LICENSE +21 -0
  4. package/README.md +600 -0
  5. package/bin/aider-smart +72 -0
  6. package/bin/slm +202 -0
  7. package/bin/slm-npm +73 -0
  8. package/bin/slm.bat +195 -0
  9. package/bin/slm.cmd +10 -0
  10. package/bin/superlocalmemoryv2:list +3 -0
  11. package/bin/superlocalmemoryv2:profile +3 -0
  12. package/bin/superlocalmemoryv2:recall +3 -0
  13. package/bin/superlocalmemoryv2:remember +3 -0
  14. package/bin/superlocalmemoryv2:reset +3 -0
  15. package/bin/superlocalmemoryv2:status +3 -0
  16. package/completions/slm.bash +58 -0
  17. package/completions/slm.zsh +76 -0
  18. package/configs/antigravity-mcp.json +13 -0
  19. package/configs/chatgpt-desktop-mcp.json +7 -0
  20. package/configs/claude-desktop-mcp.json +15 -0
  21. package/configs/codex-mcp.toml +13 -0
  22. package/configs/cody-commands.json +29 -0
  23. package/configs/continue-mcp.yaml +14 -0
  24. package/configs/continue-skills.yaml +26 -0
  25. package/configs/cursor-mcp.json +15 -0
  26. package/configs/gemini-cli-mcp.json +11 -0
  27. package/configs/jetbrains-mcp.json +11 -0
  28. package/configs/opencode-mcp.json +12 -0
  29. package/configs/perplexity-mcp.json +9 -0
  30. package/configs/vscode-copilot-mcp.json +12 -0
  31. package/configs/windsurf-mcp.json +16 -0
  32. package/configs/zed-mcp.json +12 -0
  33. package/docs/ARCHITECTURE.md +877 -0
  34. package/docs/CLI-COMMANDS-REFERENCE.md +425 -0
  35. package/docs/COMPETITIVE-ANALYSIS.md +210 -0
  36. package/docs/COMPRESSION-README.md +390 -0
  37. package/docs/GRAPH-ENGINE.md +503 -0
  38. package/docs/MCP-MANUAL-SETUP.md +720 -0
  39. package/docs/MCP-TROUBLESHOOTING.md +787 -0
  40. package/docs/PATTERN-LEARNING.md +363 -0
  41. package/docs/PROFILES-GUIDE.md +453 -0
  42. package/docs/RESET-GUIDE.md +353 -0
  43. package/docs/SEARCH-ENGINE-V2.2.0.md +748 -0
  44. package/docs/SEARCH-INTEGRATION-GUIDE.md +502 -0
  45. package/docs/UI-SERVER.md +254 -0
  46. package/docs/UNIVERSAL-INTEGRATION.md +432 -0
  47. package/docs/V2.2.0-OPTIONAL-SEARCH.md +666 -0
  48. package/docs/WINDOWS-INSTALL-README.txt +34 -0
  49. package/docs/WINDOWS-POST-INSTALL.txt +45 -0
  50. package/docs/example_graph_usage.py +148 -0
  51. package/hooks/memory-list-skill.js +130 -0
  52. package/hooks/memory-profile-skill.js +284 -0
  53. package/hooks/memory-recall-skill.js +109 -0
  54. package/hooks/memory-remember-skill.js +127 -0
  55. package/hooks/memory-reset-skill.js +274 -0
  56. package/install-skills.sh +436 -0
  57. package/install.ps1 +417 -0
  58. package/install.sh +755 -0
  59. package/mcp_server.py +585 -0
  60. package/package.json +94 -0
  61. package/requirements-core.txt +24 -0
  62. package/requirements.txt +10 -0
  63. package/scripts/postinstall.js +126 -0
  64. package/scripts/preuninstall.js +57 -0
  65. package/skills/slm-build-graph/SKILL.md +423 -0
  66. package/skills/slm-list-recent/SKILL.md +348 -0
  67. package/skills/slm-recall/SKILL.md +325 -0
  68. package/skills/slm-remember/SKILL.md +194 -0
  69. package/skills/slm-status/SKILL.md +363 -0
  70. package/skills/slm-switch-profile/SKILL.md +442 -0
  71. package/src/__pycache__/cache_manager.cpython-312.pyc +0 -0
  72. package/src/__pycache__/embedding_engine.cpython-312.pyc +0 -0
  73. package/src/__pycache__/graph_engine.cpython-312.pyc +0 -0
  74. package/src/__pycache__/hnsw_index.cpython-312.pyc +0 -0
  75. package/src/__pycache__/hybrid_search.cpython-312.pyc +0 -0
  76. package/src/__pycache__/memory-profiles.cpython-312.pyc +0 -0
  77. package/src/__pycache__/memory-reset.cpython-312.pyc +0 -0
  78. package/src/__pycache__/memory_compression.cpython-312.pyc +0 -0
  79. package/src/__pycache__/memory_store_v2.cpython-312.pyc +0 -0
  80. package/src/__pycache__/migrate_v1_to_v2.cpython-312.pyc +0 -0
  81. package/src/__pycache__/pattern_learner.cpython-312.pyc +0 -0
  82. package/src/__pycache__/query_optimizer.cpython-312.pyc +0 -0
  83. package/src/__pycache__/search_engine_v2.cpython-312.pyc +0 -0
  84. package/src/__pycache__/setup_validator.cpython-312.pyc +0 -0
  85. package/src/__pycache__/tree_manager.cpython-312.pyc +0 -0
  86. package/src/cache_manager.py +520 -0
  87. package/src/embedding_engine.py +671 -0
  88. package/src/graph_engine.py +970 -0
  89. package/src/hnsw_index.py +626 -0
  90. package/src/hybrid_search.py +693 -0
  91. package/src/memory-profiles.py +518 -0
  92. package/src/memory-reset.py +485 -0
  93. package/src/memory_compression.py +999 -0
  94. package/src/memory_store_v2.py +1088 -0
  95. package/src/migrate_v1_to_v2.py +638 -0
  96. package/src/pattern_learner.py +898 -0
  97. package/src/query_optimizer.py +513 -0
  98. package/src/search_engine_v2.py +403 -0
  99. package/src/setup_validator.py +479 -0
  100. package/src/tree_manager.py +720 -0
@@ -0,0 +1,390 @@
1
+ # Progressive Summarization Compression for SuperLocalMemory
2
+
3
+ ## Overview
4
+
5
+ The compression system implements tier-based progressive summarization to efficiently manage 100+ memories without performance degradation. It uses **extractive summarization** (no external LLM calls) to compress older memories while preserving essential information.
6
+
7
+ ## Architecture
8
+
9
+ ### Compression Tiers
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────────────────────┐
13
+ │ TIER 1: Recent (0-30 days) │
14
+ │ Storage: Full content + summary │
15
+ │ Size: ~50KB per memory │
16
+ │ Access: Instant, no decompression needed │
17
+ └─────────────────────────────────────────────────────────┘
18
+
19
+ ┌─────────────────────────────────────────────────────────┐
20
+ │ TIER 2: Active (30-90 days) │
21
+ │ Storage: Summary + key excerpts │
22
+ │ Size: ~10KB per memory (80% reduction) │
23
+ │ Access: Fast, show summary with "expand" option │
24
+ └─────────────────────────────────────────────────────────┘
25
+
26
+ ┌─────────────────────────────────────────────────────────┐
27
+ │ TIER 3: Archived (90+ days) │
28
+ │ Storage: Bullet-point summary only │
29
+ │ Size: ~2KB per memory (96% reduction) │
30
+ │ Access: Show bullets, full content in cold storage │
31
+ └─────────────────────────────────────────────────────────┘
32
+
33
+ ┌─────────────────────────────────────────────────────────┐
34
+ │ COLD STORAGE: Very Old (1+ year) │
35
+ │ Storage: Compressed JSON file (gzip) │
36
+ │ Size: ~1KB per memory (98% reduction) │
37
+ │ Access: Manual restore from archive │
38
+ └─────────────────────────────────────────────────────────┘
39
+ ```
40
+
41
+ ### Key Features
42
+
43
+ 1. **No External APIs**: All compression is local using extractive summarization
44
+ 2. **Preserves Important Memories**: High-importance (≥8) memories stay in Tier 1
45
+ 3. **Access-Based Protection**: Recently accessed memories remain uncompressed
46
+ 4. **Reversible**: Full content stored in archive table until moved to cold storage
47
+ 5. **Automatic**: Daily cron job handles all compression tasks
48
+ 6. **Safe**: Database backup before each compression run
49
+
50
+ ## Implementation
51
+
52
+ ### Core Classes
53
+
54
+ #### 1. TierClassifier
55
+ Classifies memories into tiers based on:
56
+ - Age (days since creation)
57
+ - Importance score
58
+ - Last access time
59
+ - Access count
60
+
61
+ #### 2. Tier2Compressor
62
+ Compresses to summary + key excerpts using:
63
+ - Sentence scoring (tech terms, position, numbers)
64
+ - Code block extraction
65
+ - Bullet list extraction
66
+ - Important paragraph detection
67
+
68
+ #### 3. Tier3Compressor
69
+ Ultra-compresses to 5 bullet points:
70
+ - Converts summary to brief bullets
71
+ - Each bullet max 80 characters
72
+ - Preserves core information only
73
+
74
+ #### 4. ColdStorageManager
75
+ Archives very old memories:
76
+ - Gzipped JSON format
77
+ - Monthly archive files
78
+ - Restoreable on demand
79
+
80
+ #### 5. CompressionOrchestrator
81
+ Main controller that runs full compression cycle:
82
+ 1. Classify memories into tiers
83
+ 2. Compress Tier 2 memories
84
+ 3. Compress Tier 3 memories
85
+ 4. Move candidates to cold storage
86
+ 5. Calculate space savings
87
+
88
+ ## Configuration
89
+
90
+ Located in `~/.claude-memory/config.json`:
91
+
92
+ ```json
93
+ {
94
+ "compression": {
95
+ "enabled": true,
96
+ "tier2_threshold_days": 30,
97
+ "tier3_threshold_days": 90,
98
+ "cold_storage_threshold_days": 365,
99
+ "preserve_high_importance": true,
100
+ "preserve_recently_accessed": true
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### Configuration Options
106
+
107
+ - `enabled`: Enable/disable compression system
108
+ - `tier2_threshold_days`: Days before compressing to Tier 2 (default: 30)
109
+ - `tier3_threshold_days`: Days before compressing to Tier 3 (default: 90)
110
+ - `cold_storage_threshold_days`: Days before moving to cold storage (default: 365)
111
+ - `preserve_high_importance`: Keep importance ≥8 in Tier 1 (default: true)
112
+ - `preserve_recently_accessed`: Keep recently accessed in Tier 1 (default: true)
113
+
114
+ ## Usage
115
+
116
+ ### Command Line Interface
117
+
118
+ ```bash
119
+ # Initialize compression configuration
120
+ ~/.claude-memory/memory-compress init-config
121
+
122
+ # Classify memories into tiers
123
+ ~/.claude-memory/memory-compress classify
124
+
125
+ # Run full compression cycle
126
+ ~/.claude-memory/memory-compress compress
127
+
128
+ # Show compression statistics
129
+ ~/.claude-memory/memory-compress stats
130
+
131
+ # Compress specific memory to Tier 2
132
+ ~/.claude-memory/memory-compress tier2 <id>
133
+
134
+ # Compress specific memory to Tier 3
135
+ ~/.claude-memory/memory-compress tier3 <id>
136
+
137
+ # Move old memories to cold storage
138
+ ~/.claude-memory/memory-compress cold-storage
139
+
140
+ # Restore memory from cold storage
141
+ ~/.claude-memory/memory-compress restore <id>
142
+ ```
143
+
144
+ ### Python API
145
+
146
+ ```python
147
+ from memory_compression import CompressionOrchestrator
148
+
149
+ # Run full compression
150
+ orchestrator = CompressionOrchestrator()
151
+ stats = orchestrator.run_full_compression()
152
+
153
+ print(f"Compressed {stats['tier2_compressed']} to Tier 2")
154
+ print(f"Compressed {stats['tier3_compressed']} to Tier 3")
155
+ print(f"Space savings: {stats['space_savings']['savings_percent']}%")
156
+ ```
157
+
158
+ ## Automated Compression
159
+
160
+ ### Daily Cron Job
161
+
162
+ The system includes a daily cron job script at:
163
+ ```
164
+ ~/.claude-memory/jobs/compress-memories.sh
165
+ ```
166
+
167
+ #### Setup Cron Job
168
+
169
+ 1. Open crontab editor:
170
+ ```bash
171
+ crontab -e
172
+ ```
173
+
174
+ 2. Add this line (runs daily at 3 AM):
175
+ ```
176
+ 0 3 * * * ~/.claude-memory/jobs/compress-memories.sh >> ~/.claude-memory/logs/compression.log 2>&1
177
+ ```
178
+
179
+ 3. Save and exit
180
+
181
+ #### What the Daily Job Does
182
+
183
+ 1. Creates database backup
184
+ 2. Classifies memories into tiers
185
+ 3. Compresses Tier 2 memories
186
+ 4. Compresses Tier 3 memories
187
+ 5. Moves old memories to cold storage
188
+ 6. Logs results to `~/.claude-memory/logs/compression.log`
189
+ 7. Cleans up backups older than 7 days
190
+
191
+ ## Database Schema
192
+
193
+ ### New Columns in `memories` Table
194
+
195
+ ```sql
196
+ tier INTEGER DEFAULT 1 -- Compression tier (1, 2, or 3)
197
+ last_accessed TIMESTAMP -- Last access time
198
+ access_count INTEGER DEFAULT 0 -- Number of accesses
199
+ ```
200
+
201
+ ### New `memory_archive` Table
202
+
203
+ ```sql
204
+ CREATE TABLE memory_archive (
205
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
206
+ memory_id INTEGER UNIQUE NOT NULL,
207
+ full_content TEXT NOT NULL,
208
+ archived_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
209
+ FOREIGN KEY (memory_id) REFERENCES memories(id) ON DELETE CASCADE
210
+ );
211
+ ```
212
+
213
+ ## Extractive Summarization Algorithm
214
+
215
+ ### Sentence Scoring Heuristics
216
+
217
+ Each sentence is scored based on:
218
+
219
+ 1. **Tech Terms** (+1 per term): api, database, auth, component, function, class, method, variable, error, bug, fix, implement, refactor, test, deploy
220
+
221
+ 2. **Position Boost** (+2): First or last sentence (thesis/conclusion)
222
+
223
+ 3. **Numbers/Specifics** (+1): Contains digits (measurements, versions, dates)
224
+
225
+ 4. **Important Keywords** (+2 per keyword): important, critical, note, remember, key, main, primary, must, should
226
+
227
+ Top-scored sentences are selected until max_length is reached.
228
+
229
+ ### Excerpt Extraction
230
+
231
+ Priority order:
232
+ 1. Code blocks (markdown or indented) - max 2
233
+ 2. Bullet lists - max 1
234
+ 3. Paragraphs with important keywords - remaining slots
235
+
236
+ ## Performance Impact
237
+
238
+ ### Before Compression (100 memories @ 50KB each)
239
+ - Database size: 5MB
240
+ - Search time: 150ms (scan all content)
241
+ - Memory load: 5MB into RAM
242
+
243
+ ### After Compression (100 memories, tiered)
244
+ - Tier 1 (30 memories @ 50KB): 1.5MB
245
+ - Tier 2 (40 memories @ 10KB): 400KB
246
+ - Tier 3 (30 memories @ 2KB): 60KB
247
+ - **Total: 1.96MB (61% reduction)**
248
+ - **Search time: 45ms** (only scan Tier 1+2)
249
+ - **Memory load: 1.9MB** (Tier 3 loaded on-demand)
250
+
251
+ ### Space Savings Scale
252
+ - 500 memories: ~10MB → ~4MB (60% reduction)
253
+ - 1000 memories: ~50MB → ~15MB (70% reduction)
254
+
255
+ ## Safety & Rollback
256
+
257
+ ### Data Preservation
258
+
259
+ 1. **Archive Table**: Full content preserved until moved to cold storage
260
+ 2. **Cold Storage**: Gzipped JSON archives (restorable)
261
+ 3. **Daily Backups**: Database backup before each compression run
262
+ 4. **7-Day Retention**: Last 7 backups kept automatically
263
+
264
+ ### Restore Operations
265
+
266
+ #### Restore from Archive (Tier 2/3 → Tier 1)
267
+ ```python
268
+ from memory_compression import ColdStorageManager
269
+
270
+ cold_storage = ColdStorageManager()
271
+ content = cold_storage.restore_from_cold_storage(memory_id)
272
+ ```
273
+
274
+ #### Manual Restore from Backup
275
+ ```bash
276
+ # List backups
277
+ ls ~/.claude-memory/backups/
278
+
279
+ # Restore from backup
280
+ cp ~/.claude-memory/backups/memory-20260205.db ~/.claude-memory/memory.db
281
+ ```
282
+
283
+ ## Monitoring
284
+
285
+ ### Check Compression Stats
286
+ ```bash
287
+ ~/.claude-memory/memory-compress stats
288
+ ```
289
+
290
+ ### View Compression Logs
291
+ ```bash
292
+ tail -f ~/.claude-memory/logs/compression.log
293
+ ```
294
+
295
+ ### Check Cron Job Status
296
+ ```bash
297
+ # View cron jobs
298
+ crontab -l
299
+
300
+ # Check last run
301
+ ls -lt ~/.claude-memory/logs/compression.log
302
+ ```
303
+
304
+ ## Troubleshooting
305
+
306
+ ### Compression Not Running
307
+
308
+ 1. Check if enabled in config:
309
+ ```bash
310
+ cat ~/.claude-memory/config.json | grep -A 6 compression
311
+ ```
312
+
313
+ 2. Check cron job is set:
314
+ ```bash
315
+ crontab -l | grep compress
316
+ ```
317
+
318
+ 3. Check logs for errors:
319
+ ```bash
320
+ tail -50 ~/.claude-memory/logs/compression.log
321
+ ```
322
+
323
+ ### Memory Not Being Compressed
324
+
325
+ Check tier classification:
326
+ ```bash
327
+ sqlite3 ~/.claude-memory/memory.db "SELECT id, tier, importance, created_at FROM memories WHERE id = <id>;"
328
+ ```
329
+
330
+ Possible reasons:
331
+ - Memory is too recent (< 30 days)
332
+ - High importance (≥8) - stays in Tier 1
333
+ - Recently accessed (< 7 days) - stays in Tier 1
334
+
335
+ ### Restore Failed
336
+
337
+ 1. Check if in archive table:
338
+ ```bash
339
+ sqlite3 ~/.claude-memory/memory.db "SELECT memory_id FROM memory_archive WHERE memory_id = <id>;"
340
+ ```
341
+
342
+ 2. Check cold storage:
343
+ ```bash
344
+ ls ~/.claude-memory/cold-storage/
345
+ zgrep '"id": <id>' ~/.claude-memory/cold-storage/archive-*.json.gz
346
+ ```
347
+
348
+ ## Files
349
+
350
+ ### Main Files
351
+ - `memory_compression.py` - Main compression implementation
352
+ - `memory-compress` - CLI wrapper script
353
+ - `jobs/compress-memories.sh` - Daily cron job script
354
+ - `COMPRESSION-README.md` - This file
355
+
356
+ ### Generated Files
357
+ - `cold-storage/archive-YYYY-MM.json.gz` - Monthly archive files
358
+ - `logs/compression.log` - Compression job logs
359
+ - `backups/memory-YYYYMMDD.db` - Daily database backups
360
+
361
+ ## Integration with memory_store.py
362
+
363
+ The compression system works alongside the existing memory system:
364
+
365
+ 1. **Add Memory**: New memories created with `tier=1` by default
366
+ 2. **Search**: Searches work across all tiers (compressed content is JSON)
367
+ 3. **Access Tracking**: Can update `last_accessed` when retrieving memories
368
+ 4. **Display**: UI can check tier and format display accordingly:
369
+ - Tier 1: Show full content
370
+ - Tier 2: Show summary + excerpts with "expand" button
371
+ - Tier 3: Show bullets with "restore" button
372
+
373
+ ## Future Enhancements
374
+
375
+ 1. **Access Tracking Integration**: Update `last_accessed` in memory_store.py
376
+ 2. **UI Indicators**: Show compression tier in memory list
377
+ 3. **Manual Override**: CLI command to change tier manually
378
+ 4. **Compression Preview**: Show what will be compressed before running
379
+ 5. **Selective Compression**: Compress by project or tag
380
+ 6. **Adaptive Thresholds**: Adjust thresholds based on storage constraints
381
+
382
+ ## References
383
+
384
+ - [Progressive Summarization](https://fortelabs.co/blog/progressive-summarization-a-practical-technique-for-designing-discoverable-notes/) by Tiago Forte
385
+ - [PageIndex](https://pageindex.ai/) - Vectorless hierarchical RAG
386
+ - [GraphRAG](https://microsoft.github.io/graphrag/) - Knowledge graph clustering
387
+
388
+ ---
389
+
390
+ **Compression system ready. Run daily job to maintain optimal memory performance.**