@rlabs-inc/memory 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -33
- package/dist/index.js +803 -179
- package/dist/index.mjs +803 -179
- package/dist/server/index.js +36774 -2643
- package/dist/server/index.mjs +1034 -185
- package/package.json +3 -2
- package/skills/memory-management.md +686 -0
- package/src/cli/commands/migrate.ts +423 -0
- package/src/cli/commands/serve.ts +88 -0
- package/src/cli/index.ts +21 -0
- package/src/core/curator.ts +151 -17
- package/src/core/engine.ts +159 -11
- package/src/core/manager.ts +484 -0
- package/src/core/retrieval.ts +547 -420
- package/src/core/store.ts +383 -8
- package/src/server/index.ts +108 -8
- package/src/types/memory.ts +142 -0
- package/src/types/schema.ts +80 -7
- package/src/utils/logger.ts +310 -46
package/README.md
CHANGED
|
@@ -55,25 +55,76 @@ Uses `all-MiniLM-L6-v2` for 384-dimensional embeddings. Memories are retrieved b
|
|
|
55
55
|
Sub-microsecond vector search via fsdb
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
###
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
|
69
|
-
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
58
|
+
### Activation Signal Retrieval Algorithm
|
|
59
|
+
|
|
60
|
+
The retrieval system uses an activation signal approach. Philosophy: **quality over quantity, silence over noise**.
|
|
61
|
+
|
|
62
|
+
A memory is relevant if **multiple signals agree** it should activate. Not coincidence - intentionally crafted metadata matching intentional queries.
|
|
63
|
+
|
|
64
|
+
**Phase 0 - Pre-Filter**: Exclude inactive, superseded, or wrong-scope memories
|
|
65
|
+
|
|
66
|
+
**Phase 1 - Activation Signals** (6 binary signals, need ≥2 to proceed)
|
|
67
|
+
|
|
68
|
+
| Signal | Description |
|
|
69
|
+
|--------|-------------|
|
|
70
|
+
| Trigger | Trigger phrase matched (≥50% word match) |
|
|
71
|
+
| Tags | 2+ semantic tags found in message |
|
|
72
|
+
| Domain | Domain word found in message |
|
|
73
|
+
| Feature | Feature word found in message |
|
|
74
|
+
| Content | 3+ significant content words overlap |
|
|
75
|
+
| Vector | Semantic similarity ≥ 40% |
|
|
76
|
+
|
|
77
|
+
**Phase 2 - Importance Ranking** (among relevant memories)
|
|
78
|
+
|
|
79
|
+
| Bonus | Amount | Condition |
|
|
80
|
+
|-------|--------|-----------|
|
|
81
|
+
| Base | 0-1 | `importance_weight` from curator |
|
|
82
|
+
| Signal boost | +0.2 / +0.1 | 4+ or 3 signals fired |
|
|
83
|
+
| Awaiting | +0.15 / +0.1 | `awaiting_implementation` / `awaiting_decision` |
|
|
84
|
+
| Temporal | +0.1 / +0.05 | `eternal` / `long_term` temporal class |
|
|
85
|
+
| Context match | +0.1 | User intent matches memory type |
|
|
86
|
+
| Problem/solution | +0.1 | User has problem words + memory is pair |
|
|
87
|
+
| Confidence penalty | -0.1 | `confidence_score` < 0.5 |
|
|
88
|
+
|
|
89
|
+
**Selection**: Sort by signal count (DESC) → importance score (DESC). Max 2 global memories (tech prioritized), project memories fill remaining slots.
|
|
90
|
+
|
|
91
|
+
### Global vs Project Memories
|
|
92
|
+
|
|
93
|
+
Memories are stored in two scopes:
|
|
94
|
+
|
|
95
|
+
- **Global**: Personal memories, philosophy, preferences, cross-project breakthroughs - shared across ALL projects
|
|
96
|
+
- **Project**: Technical details, debugging insights, project-specific decisions - isolated per project
|
|
97
|
+
|
|
98
|
+
Global memories are retrieved alongside project memories, with a maximum of 2 globals per retrieval (technical types prioritized).
|
|
73
99
|
|
|
74
100
|
### Smart Curation
|
|
75
101
|
At session end (or before context compaction), the same Claude instance reviews the conversation and extracts memories. No API key needed—uses Claude Code's `--resume` flag.
|
|
76
102
|
|
|
103
|
+
### Memory Manager Agent
|
|
104
|
+
|
|
105
|
+
After curation, an autonomous manager agent organizes the memory store:
|
|
106
|
+
|
|
107
|
+
- **Supersedes** outdated memories when new information replaces old
|
|
108
|
+
- **Resolves** unresolved/todo memories when solutions emerge
|
|
109
|
+
- **Links** related memories via relationship fields
|
|
110
|
+
- **Updates** personal primer with new personal context
|
|
111
|
+
|
|
112
|
+
The manager runs in a sandboxed environment with access only to memory storage directories.
|
|
113
|
+
|
|
114
|
+
### Personal Memories Control
|
|
115
|
+
|
|
116
|
+
Personal memory extraction can be disabled for shared or professional environments:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Via environment variable
|
|
120
|
+
MEMORY_PERSONAL_ENABLED=0 memory serve
|
|
121
|
+
|
|
122
|
+
# Or in configuration
|
|
123
|
+
personalMemoriesEnabled: false
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
When disabled, the curator skips personal/relationship context extraction.
|
|
127
|
+
|
|
77
128
|
### Session Primer
|
|
78
129
|
First message of each session receives temporal context:
|
|
79
130
|
|
|
@@ -128,9 +179,14 @@ Compact visual representation for efficient parsing:
|
|
|
128
179
|
│ ┌─────────────┐ ┌──────────────┐ ┌───────────────┐ │
|
|
129
180
|
│ │ Engine │ │ Embeddings │ │ Curator │ │
|
|
130
181
|
│ │ (context) │ │ (MiniLM) │ │ (CLI resume) │ │
|
|
131
|
-
│ └──────┬──────┘ └──────────────┘
|
|
132
|
-
│ │
|
|
133
|
-
│ ▼
|
|
182
|
+
│ └──────┬──────┘ └──────────────┘ └───────┬───────┘ │
|
|
183
|
+
│ │ │ │
|
|
184
|
+
│ │ ▼ │
|
|
185
|
+
│ │ ┌───────────────┐ │
|
|
186
|
+
│ │ │ Manager │ │
|
|
187
|
+
│ │ │ (CLI sandbox) │ │
|
|
188
|
+
│ │ └───────┬───────┘ │
|
|
189
|
+
│ ▼ │ │
|
|
134
190
|
│ ┌─────────────────────────────────────────────────┐ │
|
|
135
191
|
│ │ fsdb │ │
|
|
136
192
|
│ │ (markdown files + parallel arrays) │ │
|
|
@@ -139,9 +195,12 @@ Compact visual representation for efficient parsing:
|
|
|
139
195
|
│
|
|
140
196
|
▼
|
|
141
197
|
~/.local/share/memory/
|
|
142
|
-
├──
|
|
143
|
-
|
|
144
|
-
└──
|
|
198
|
+
├── global/
|
|
199
|
+
│ └── memories/ # Personal, philosophy (shared)
|
|
200
|
+
└── {project-id}/
|
|
201
|
+
├── memories/ # Project-specific memories
|
|
202
|
+
├── sessions/ # Session metadata
|
|
203
|
+
└── summaries/ # Session summaries
|
|
145
204
|
```
|
|
146
205
|
|
|
147
206
|
## Storage Format
|
|
@@ -150,17 +209,33 @@ Memories are stored as human-readable markdown with YAML frontmatter:
|
|
|
150
209
|
|
|
151
210
|
```markdown
|
|
152
211
|
---
|
|
212
|
+
# Core fields (v1)
|
|
153
213
|
importance_weight: 0.9
|
|
214
|
+
confidence_score: 0.85
|
|
154
215
|
context_type: technical
|
|
155
216
|
temporal_relevance: persistent
|
|
156
|
-
semantic_tags:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
217
|
+
semantic_tags: [embeddings, vectors, memory-system]
|
|
218
|
+
trigger_phrases: [working with embeddings, vector search]
|
|
219
|
+
question_types: [how, what]
|
|
220
|
+
knowledge_domain: architecture
|
|
221
|
+
emotional_resonance: discovery
|
|
222
|
+
|
|
223
|
+
# Lifecycle fields (v2)
|
|
224
|
+
schema_version: 2
|
|
225
|
+
status: active # active, pending, superseded, deprecated, archived
|
|
226
|
+
scope: project # global or project
|
|
227
|
+
temporal_class: long_term # eternal, long_term, medium_term, short_term, ephemeral
|
|
228
|
+
fade_rate: 0.02 # decay per session (0 = no decay)
|
|
229
|
+
domain: embeddings
|
|
230
|
+
feature: vector-search
|
|
231
|
+
|
|
232
|
+
# Relationships
|
|
233
|
+
related_to: [memory-xyz, memory-abc]
|
|
234
|
+
supersedes: memory-old-id
|
|
235
|
+
superseded_by: null
|
|
236
|
+
|
|
237
|
+
# Embedding (384 dimensions)
|
|
238
|
+
embedding: [0.023, -0.041, 0.087, ...]
|
|
164
239
|
---
|
|
165
240
|
|
|
166
241
|
Embeddings are 384-dimensional vectors generated by all-MiniLM-L6-v2.
|
|
@@ -179,15 +254,20 @@ Benefits:
|
|
|
179
254
|
memory serve # Start memory server (default port 8765)
|
|
180
255
|
memory serve --port 9000 # Custom port
|
|
181
256
|
memory serve --verbose # Detailed logging
|
|
257
|
+
memory serve --quiet # Minimal output
|
|
182
258
|
|
|
183
259
|
memory install # Set up Claude Code hooks
|
|
184
260
|
memory install --force # Overwrite existing hooks
|
|
261
|
+
memory install --gemini # Install for Gemini CLI instead
|
|
185
262
|
|
|
186
263
|
memory doctor # Health check
|
|
187
264
|
memory doctor --verbose # Detailed diagnostics
|
|
188
265
|
|
|
189
266
|
memory stats # Show memory statistics
|
|
190
267
|
memory stats --project x # Project-specific stats
|
|
268
|
+
|
|
269
|
+
memory migrate # Upgrade memories to latest schema (v1 → v2)
|
|
270
|
+
memory migrate --dry-run # Preview changes without applying
|
|
191
271
|
```
|
|
192
272
|
|
|
193
273
|
## Environment Variables
|
|
@@ -197,6 +277,13 @@ MEMORY_PORT=8765 # Server port
|
|
|
197
277
|
MEMORY_HOST=localhost # Server host
|
|
198
278
|
MEMORY_STORAGE_MODE=central # 'central' or 'local'
|
|
199
279
|
MEMORY_API_URL=http://localhost:8765 # For hooks
|
|
280
|
+
|
|
281
|
+
# Feature toggles
|
|
282
|
+
MEMORY_MANAGER_ENABLED=1 # Enable/disable memory manager agent (default: 1)
|
|
283
|
+
MEMORY_PERSONAL_ENABLED=1 # Enable/disable personal memory extraction (default: 1)
|
|
284
|
+
|
|
285
|
+
# Optional: for SDK curation mode (alternative to CLI mode)
|
|
286
|
+
ANTHROPIC_API_KEY=sk-... # Uses SDK instead of CLI for curation
|
|
200
287
|
```
|
|
201
288
|
|
|
202
289
|
## How It Works
|
|
@@ -206,21 +293,30 @@ When you start Claude Code, the `SessionStart` hook injects a primer with:
|
|
|
206
293
|
- Time since last session
|
|
207
294
|
- Previous session summary
|
|
208
295
|
- Project status
|
|
296
|
+
- Personal primer (relationship context, injected every session)
|
|
209
297
|
- Current datetime for temporal awareness
|
|
210
298
|
|
|
211
299
|
### 2. Every Message
|
|
212
300
|
The `UserPromptSubmit` hook:
|
|
213
301
|
1. Embeds your message (~5ms)
|
|
214
|
-
2. Searches
|
|
215
|
-
3.
|
|
216
|
-
4. Injects top matches
|
|
302
|
+
2. Searches both global and project memories
|
|
303
|
+
3. Applies two-phase scoring with dual gatekeepers
|
|
304
|
+
4. Injects top matches (max 5 by default, max 2 global)
|
|
217
305
|
|
|
218
306
|
### 3. Session End
|
|
219
307
|
The `PreCompact` or `SessionEnd` hook triggers curation:
|
|
220
308
|
1. Resumes the same Claude session via CLI
|
|
221
309
|
2. Claude reviews the conversation
|
|
222
|
-
3. Extracts important memories with rich metadata
|
|
310
|
+
3. Extracts important memories with rich metadata (v2 lifecycle fields)
|
|
223
311
|
4. Stores as markdown files with embeddings
|
|
312
|
+
5. Determines scope: global (personal/philosophy) vs project (technical)
|
|
313
|
+
|
|
314
|
+
### 4. Memory Management (Async)
|
|
315
|
+
After curation completes, the manager agent:
|
|
316
|
+
1. Scans for outdated memories to supersede
|
|
317
|
+
2. Resolves unresolved/todo items when solutions appear
|
|
318
|
+
3. Links related memories together
|
|
319
|
+
4. Updates the personal primer with new relationship context
|
|
224
320
|
|
|
225
321
|
## Requirements
|
|
226
322
|
|