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,363 @@
1
+ # Pattern Learner - Identity Profile Extraction
2
+
3
+ ## Overview
4
+
5
+ The Pattern Learner is Layer 4 of the SuperLocalMemory system. It automatically learns user preferences, coding style, and terminology from stored memories using local TF-IDF and heuristic analysis.
6
+
7
+ **No external APIs. All processing is local.**
8
+
9
+ ## Architecture
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────────────────────┐
13
+ │ PatternLearner │
14
+ │ │
15
+ │ ┌──────────────────┐ ┌──────────────────┐ │
16
+ │ │ Frequency │ │ Context │ │
17
+ │ │ Analyzer │ │ Analyzer │ │
18
+ │ └──────────────────┘ └──────────────────┘ │
19
+ │ │
20
+ │ ┌──────────────────┐ ┌──────────────────┐ │
21
+ │ │ Terminology │ │ Confidence │ │
22
+ │ │ Learner │ │ Scorer │ │
23
+ │ └──────────────────┘ └──────────────────┘ │
24
+ │ │
25
+ │ ┌──────────────────┐ │
26
+ │ │ Pattern Store │ │
27
+ │ └──────────────────┘ │
28
+ └─────────────────────────────────────────────────────────┘
29
+ ```
30
+
31
+ ## Components
32
+
33
+ ### 1. FrequencyAnalyzer
34
+ **Purpose:** Detect technology preferences via frequency counting
35
+
36
+ **Categories tracked:**
37
+ - Frontend frameworks (React, Next.js, Vue, Angular, Svelte)
38
+ - Backend frameworks (Express, FastAPI, Django, Flask)
39
+ - Databases (PostgreSQL, MySQL, MongoDB, Redis)
40
+ - State management (Redux, Context, Zustand)
41
+ - Styling (Tailwind, CSS Modules, Styled Components)
42
+ - Languages (Python, JavaScript, TypeScript, Go, Rust)
43
+ - Deployment (Docker, Kubernetes, Vercel, AWS)
44
+ - Testing (Jest, Pytest, Vitest, Cypress)
45
+
46
+ **Algorithm:**
47
+ 1. Count keyword mentions across all memories
48
+ 2. Calculate relative frequency (top choice vs others)
49
+ 3. Create pattern if confidence > 60% and count >= 3
50
+
51
+ **Example output:**
52
+ ```
53
+ Pattern: frontend_framework
54
+ Value: "Next.js over React"
55
+ Confidence: 85%
56
+ Evidence: 12 memories
57
+ ```
58
+
59
+ ### 2. ContextAnalyzer
60
+ **Purpose:** Detect coding style patterns from context
61
+
62
+ **Patterns tracked:**
63
+ - **Optimization priority:** Performance vs Readability
64
+ - **Error handling:** Explicit vs Permissive
65
+ - **Testing approach:** Comprehensive vs Minimal
66
+ - **Code organization:** Modular vs Monolithic
67
+
68
+ **Algorithm:**
69
+ 1. Define indicator keywords for each style dimension
70
+ 2. Count mentions in memory contexts
71
+ 3. Determine dominant style if confidence > 65%
72
+
73
+ **Example output:**
74
+ ```
75
+ Pattern: optimization_priority
76
+ Value: "Performance over readability"
77
+ Confidence: 90%
78
+ Evidence: 15 memories
79
+ ```
80
+
81
+ ### 3. TerminologyLearner
82
+ **Purpose:** Learn user-specific definitions of ambiguous terms
83
+
84
+ **Terms tracked:**
85
+ - optimize, refactor, clean, simple
86
+ - mvp, prototype, scale, production-ready
87
+ - fix, improve, update, enhance
88
+
89
+ **Algorithm:**
90
+ 1. Extract 100-char context window around each term mention
91
+ 2. Analyze co-occurring words across contexts
92
+ 3. Apply heuristic rules to determine meaning
93
+ 4. Require 3+ examples for confidence
94
+
95
+ **Example output:**
96
+ ```
97
+ Pattern: optimize
98
+ Value: "Performance optimization (speed/latency)"
99
+ Confidence: 90%
100
+ Evidence: 15 memories
101
+ ```
102
+
103
+ ### 4. ConfidenceScorer
104
+ **Purpose:** Calculate reliability scores for patterns
105
+
106
+ **Formula:**
107
+ ```python
108
+ confidence = (evidence_count / total_memories) * recency_bonus * distribution_factor
109
+
110
+ Where:
111
+ - evidence_count: Number of memories supporting pattern
112
+ - total_memories: Total memories in database
113
+ - recency_bonus: 1.2 if >50% evidence is from last 30 days, else 1.0
114
+ - distribution_factor: 1.1 if memories span >7 days, 0.8 if <3 memories
115
+ ```
116
+
117
+ **Conservative by design:** Low confidence with small datasets is correct behavior.
118
+
119
+ ### 5. PatternStore
120
+ **Purpose:** Persist patterns to database
121
+
122
+ **Tables:**
123
+ - `identity_patterns`: Pattern definitions with confidence scores
124
+ - `pattern_examples`: Representative excerpts showing patterns
125
+
126
+ ## Usage
127
+
128
+ ### Command Line Interface
129
+
130
+ ```bash
131
+ # Full pattern update (run weekly)
132
+ python pattern_learner.py update
133
+
134
+ # List learned patterns
135
+ python pattern_learner.py list [min_confidence]
136
+ # Example: python pattern_learner.py list 0.7 # Show patterns with >70% confidence
137
+
138
+ # Get context for Claude injection
139
+ python pattern_learner.py context [min_confidence]
140
+ # Example: python pattern_learner.py context 0.6
141
+
142
+ # Show statistics
143
+ python pattern_learner.py stats
144
+ ```
145
+
146
+ ### Python API
147
+
148
+ ```python
149
+ from pattern_learner import PatternLearner
150
+
151
+ learner = PatternLearner()
152
+
153
+ # Full pattern analysis
154
+ counts = learner.weekly_pattern_update()
155
+ # Returns: {'preferences': 5, 'styles': 3, 'terminology': 4}
156
+
157
+ # Incremental update for new memory
158
+ learner.on_new_memory(memory_id=42)
159
+
160
+ # Query patterns
161
+ patterns = learner.get_patterns(min_confidence=0.7)
162
+
163
+ # Get formatted context for Claude
164
+ context = learner.get_identity_context(min_confidence=0.7)
165
+ ```
166
+
167
+ ## Example Output
168
+
169
+ ### Pattern List
170
+ ```
171
+ Type Category Pattern Confidence Evidence
172
+ -----------------------------------------------------------------------------------------------
173
+ style general Optimization Priority: Perfo... 90% 15
174
+ preference frontend Frontend Framework: Next.js... 85% 12
175
+ preference backend Database: PostgreSQL 72% 8
176
+ terminology general Optimize: Performance optimi... 90% 15
177
+ style general Error Handling: Explicit err... 78% 9
178
+ ```
179
+
180
+ ### Claude Context Injection
181
+ ```markdown
182
+ ## Working with User - Learned Patterns
183
+
184
+ **Technology Preferences:**
185
+ - **Frontend Framework:** Next.js over React (confidence: 85%, 12 examples)
186
+ - **Database:** PostgreSQL (confidence: 72%, 8 examples)
187
+ - **State Management:** Redux for complex, Context for simple (confidence: 68%, 7 examples)
188
+
189
+ **Coding Style:**
190
+ - **Optimization Priority:** Performance over readability (confidence: 90%, 15 examples)
191
+ - **Error Handling:** Explicit error boundaries (confidence: 78%, 9 examples)
192
+ - **Code Organization:** Modular organization (confidence: 75%, 11 examples)
193
+
194
+ **Terminology:**
195
+ - **Optimize:** Performance optimization (speed/latency) (confidence: 90%, 15 examples)
196
+ - **Refactor:** Architecture change, not just renaming (confidence: 82%, 10 examples)
197
+ - **MVP:** Core features only, no polish (confidence: 85%, 8 examples)
198
+ ```
199
+
200
+ ## Confidence Calibration
201
+
202
+ ### Small Datasets (<20 memories)
203
+ - **Expected confidence:** 10-40%
204
+ - **Reason:** Limited evidence means low certainty
205
+ - **Recommendation:** Use min_confidence=0.1 for exploration
206
+
207
+ ### Medium Datasets (20-100 memories)
208
+ - **Expected confidence:** 40-70%
209
+ - **Reason:** Patterns emerging but still developing
210
+ - **Recommendation:** Use min_confidence=0.5 for reliable patterns
211
+
212
+ ### Large Datasets (>100 memories)
213
+ - **Expected confidence:** 70-95%
214
+ - **Reason:** Strong evidence across time
215
+ - **Recommendation:** Use min_confidence=0.7 for high-confidence patterns
216
+
217
+ **Note:** The system is designed to be conservative. Low confidence with small datasets is correct behavior, not a bug.
218
+
219
+ ## Pattern Update Schedule
220
+
221
+ ### Incremental (on `/remember`)
222
+ - Quick check for pattern updates
223
+ - For datasets >50 memories, defers to weekly update
224
+ - For small datasets, triggers full update
225
+
226
+ ### Weekly Consolidation
227
+ - Full re-analysis of all memories
228
+ - Recommended cron job:
229
+ ```bash
230
+ # Every Sunday at 2 AM
231
+ 0 2 * * 0 cd ~/.claude-memory && python3 pattern_learner.py update >> pattern_updates.log 2>&1
232
+ ```
233
+
234
+ ## Integration with AI Assistants
235
+
236
+ ### Context Injection
237
+ The `get_identity_context()` method formats patterns for any AI assistant's context window:
238
+
239
+ ```python
240
+ # In your AI assistant integration:
241
+ learner = PatternLearner()
242
+ identity_context = learner.get_identity_context(min_confidence=0.7)
243
+
244
+ # Inject into system prompt or context (works with Claude, GPT, or any assistant)
245
+ prompt = f"""
246
+ {identity_context}
247
+
248
+ [Rest of your prompt...]
249
+ """
250
+ ```
251
+
252
+ ### Benefits
253
+ 1. **Personalized responses:** AI understands your technology preferences
254
+ 2. **Consistent terminology:** AI uses terms the way you define them
255
+ 3. **Style matching:** AI respects your coding style priorities
256
+ 4. **Efficient communication:** No need to repeat preferences
257
+
258
+ **Works with:** Claude CLI, GPT, local LLMs, or any AI assistant that accepts context.
259
+
260
+ ## Implementation Details
261
+
262
+ ### Technology Stack
263
+ - **Language:** Python 3.8+
264
+ - **Database:** SQLite3 (local)
265
+ - **NLP:** sklearn TfidfVectorizer (optional, local)
266
+ - **No external APIs**
267
+
268
+ ### Files
269
+ - `pattern_learner.py` - Main implementation (850 lines)
270
+ - `memory.db` - SQLite database (includes pattern tables)
271
+ - Schema tables:
272
+ - `identity_patterns` - Pattern definitions
273
+ - `pattern_examples` - Representative excerpts
274
+
275
+ ### Performance
276
+ - **Full analysis (100 memories):** ~2-3 seconds
277
+ - **Query patterns:** <10ms
278
+ - **Database size:** ~1KB per pattern
279
+
280
+ ## Security & Privacy
281
+
282
+ ✅ **No external API calls**
283
+ ✅ **All data stays local** (~/.claude-memory/)
284
+ ✅ **SQL injection protected** (parameterized queries)
285
+ ✅ **No credentials stored**
286
+ ✅ **No network access required**
287
+
288
+ ## Limitations
289
+
290
+ 1. **English-only:** Pattern detection optimized for English text
291
+ 2. **Technical domains:** Works best with technical/coding memories
292
+ 3. **Minimum memories:** Requires 3+ mentions for pattern detection
293
+ 4. **Confidence calibration:** Conservative scoring (by design)
294
+
295
+ ## Troubleshooting
296
+
297
+ ### "No patterns learned yet"
298
+ - **Cause:** Not enough memories or technical content
299
+ - **Solution:** Add 10-20 memories with technical details
300
+
301
+ ### Low confidence scores
302
+ - **Cause:** Small dataset or mixed evidence
303
+ - **Solution:** Normal behavior. Use lower threshold (0.1-0.3) or add more memories
304
+
305
+ ### Wrong preference detected
306
+ - **Cause:** More mentions of alternative technology
307
+ - **Solution:** Add more memories showing correct preference
308
+
309
+ ### Pattern not updating
310
+ - **Cause:** Weekly update not run
311
+ - **Solution:** Run `python pattern_learner.py update` manually
312
+
313
+ ## Testing
314
+
315
+ Sample memories for testing pattern detection:
316
+
317
+ ```bash
318
+ # Add sample memories
319
+ python memory_store.py add "Built with Next.js for better performance" --tags nextjs
320
+ python memory_store.py add "Using Next.js on all new projects" --tags nextjs
321
+ python memory_store.py add "Optimized API from 200ms to 50ms" --tags performance
322
+ python memory_store.py add "Performance is critical for UX" --tags performance
323
+ python memory_store.py add "When I say optimize, I mean make it faster" --tags terminology
324
+
325
+ # Run pattern learning
326
+ python pattern_learner.py update
327
+
328
+ # Check results
329
+ python pattern_learner.py list 0.1
330
+ python pattern_learner.py context 0.1
331
+ ```
332
+
333
+ ## Future Enhancements
334
+
335
+ Potential improvements (not yet implemented):
336
+
337
+ 1. **True incremental updates:** Update only affected patterns
338
+ 2. **Pattern decay:** Reduce confidence over time if not reinforced
339
+ 3. **Conflict detection:** Identify contradicting patterns
340
+ 4. **Cross-project patterns:** Detect project-specific vs global preferences
341
+ 5. **Multi-language support:** Extend beyond English
342
+ 6. **Pattern visualization:** Web UI for pattern exploration
343
+
344
+ ## References
345
+
346
+ Architecture documentation:
347
+ - `docs/architecture/05-pattern-learner.md` - Detailed algorithm specification
348
+ - `docs/architecture/01-database-schema.md` - Pattern table schemas
349
+ - `docs/ARCHITECTURE.md` - System overview
350
+
351
+ Research inspiration:
352
+ - xMemory (arxiv.org/abs/2602.02007) - Semantic memory components
353
+ - A-RAG - Agentic multi-level retrieval
354
+
355
+ ## License
356
+
357
+ Part of SuperLocalMemory system. See main project LICENSE.
358
+
359
+ ---
360
+
361
+ **Implementation Status:** ✅ Complete and tested
362
+
363
+ **Last Updated:** 2026-02-05