memory-forge 0.1.9 → 0.2.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.
- package/README.md +48 -65
- package/TECHNICAL.md +191 -190
- package/TUTORIAL.md +161 -165
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,93 +1,76 @@
|
|
|
1
1
|
# MemoryForge
|
|
2
2
|
|
|
3
|
-
> AI
|
|
3
|
+
> Persistent memory engine for AI agents. 8 MCP tools + 5 auto-engines. Free tier runs locally, Pro tier adds Shelby decentralized cloud sync.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npx memory-forge setup
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Auto-configures Claude Code hooks (SessionStart / Stop / PreCompact) and imports existing rules as memories.
|
|
12
12
|
|
|
13
|
-
Free
|
|
13
|
+
Free tier has no external service dependencies. Pro tier requires a `SHELBY_API_KEY` for Shelby cloud sync.
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Core Capabilities
|
|
16
16
|
|
|
17
|
-
**8
|
|
17
|
+
**8 MCP Tools (invoked by agent directly):**
|
|
18
18
|
|
|
19
|
-
|
|
|
19
|
+
| Tool | Description |
|
|
20
20
|
|---|---|
|
|
21
|
-
| `memory_store` |
|
|
22
|
-
| `memory_search` |
|
|
23
|
-
| `memory_recall` |
|
|
24
|
-
| `memory_list` |
|
|
25
|
-
| `memory_forget` |
|
|
26
|
-
| `memory_context` |
|
|
27
|
-
| `memory_export` |
|
|
28
|
-
| `memory_share` |
|
|
29
|
-
|
|
30
|
-
**5
|
|
31
|
-
|
|
32
|
-
|
|
|
21
|
+
| `memory_store` | Store memories with auto-embedding, naming, and dedup merge |
|
|
22
|
+
| `memory_search` | Semantic search (vector + keyword dual-mode) |
|
|
23
|
+
| `memory_recall` | Exact recall by memory ID |
|
|
24
|
+
| `memory_list` | List memories with category/tag filtering |
|
|
25
|
+
| `memory_forget` | Delete a memory (local + Shelby tombstone) |
|
|
26
|
+
| `memory_context` | Load current session context |
|
|
27
|
+
| `memory_export` | Export as JSON or Markdown |
|
|
28
|
+
| `memory_share` | Package a memory for teammate import |
|
|
29
|
+
|
|
30
|
+
**5 Auto-Engines (zero user awareness):**
|
|
31
|
+
|
|
32
|
+
| Engine | Description |
|
|
33
33
|
|---|---|
|
|
34
|
-
| autoName |
|
|
35
|
-
| autoMerge |
|
|
36
|
-
| autoPriority |
|
|
37
|
-
| autoDecay | 90
|
|
38
|
-
| autoCapture |
|
|
34
|
+
| autoName | Extract name from content automatically |
|
|
35
|
+
| autoMerge | Detect >80% overlap and merge duplicates |
|
|
36
|
+
| autoPriority | Priority scoring via access frequency + recency (Ebbinghaus curve) |
|
|
37
|
+
| autoDecay | Auto-archive at 90 days of inactivity |
|
|
38
|
+
| autoCapture | Session-end priority recalc + PreCompact save reminders |
|
|
39
39
|
|
|
40
|
-
##
|
|
40
|
+
## Pricing
|
|
41
41
|
|
|
42
|
-
|
|
|
42
|
+
| Tier | Description |
|
|
43
43
|
|---|---|
|
|
44
|
-
| **Free** | 8
|
|
45
|
-
| **Pro** | + Shelby
|
|
44
|
+
| **Free** | 8 tools, local storage, unlimited memories |
|
|
45
|
+
| **Pro** | + Shelby decentralized cloud sync, cross-device |
|
|
46
46
|
|
|
47
|
-
Pro
|
|
47
|
+
Pro is currently on Shelbynet testnet.
|
|
48
48
|
|
|
49
|
-
##
|
|
49
|
+
## Tech Stack
|
|
50
50
|
|
|
51
|
-
- **MCP
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
51
|
+
- **MCP Protocol**: `@modelcontextprotocol/sdk` (stdio transport)
|
|
52
|
+
- **Embeddings**: Transformers.js / Xenova all-MiniLM-L6-v2 (23MB, local, auto-fallback to keyword)
|
|
53
|
+
- **Cloud (Pro)**: `@shelby-protocol/sdk` (Shelbynet / Aptos)
|
|
54
|
+
- **Runtime**: Node.js 18+, TypeScript
|
|
55
55
|
|
|
56
|
-
##
|
|
56
|
+
## Docs
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
├── tsconfig.json
|
|
66
|
-
└── src/
|
|
67
|
-
├── index.ts # MCP Server 入口 + CLI 路由
|
|
68
|
-
├── store.ts # MemoryStore: LRU 缓存 + 向量/关键词搜索
|
|
69
|
-
├── embedding.ts # Transformers.js 嵌入引擎
|
|
70
|
-
├── setup.ts # 一键安装流程
|
|
71
|
-
├── pro.ts # Pro 激活 + Shelby 云同步
|
|
72
|
-
├── auto/
|
|
73
|
-
│ └── index.ts # 5 个自动化引擎
|
|
74
|
-
├── storage/
|
|
75
|
-
│ ├── local.ts # 本地 Markdown 存储
|
|
76
|
-
│ └── shelby.ts # Shelby 云存储
|
|
77
|
-
├── hooks/
|
|
78
|
-
│ └── install.ts # Claude Code hooks 配置
|
|
79
|
-
└── migrate/
|
|
80
|
-
└── import.ts # 规则导入 + 去重
|
|
81
|
-
```
|
|
58
|
+
| Document | Content |
|
|
59
|
+
|---|---|
|
|
60
|
+
| [TECHNICAL.md](TECHNICAL.md) | API reference, data model, architecture, security |
|
|
61
|
+
| [TUTORIAL.md](TUTORIAL.md) | Install guide, daily use, Pro setup, troubleshooting |
|
|
62
|
+
| [SPEC.md](SPEC.md) | Product specification and roadmap |
|
|
63
|
+
| [ARCHITECTURE.md](ARCHITECTURE.md) | System architecture and data flow |
|
|
64
|
+
| [MARKET.md](MARKET.md) | Competitive analysis |
|
|
82
65
|
|
|
83
|
-
##
|
|
66
|
+
## Security
|
|
84
67
|
|
|
85
|
-
- Free
|
|
86
|
-
- Pro
|
|
87
|
-
- API key
|
|
88
|
-
-
|
|
68
|
+
- Free tier is fully local — zero network requests (except one-time 23MB model download)
|
|
69
|
+
- Pro tier uploads to Shelby blockchain storage with Aptos transaction proofs
|
|
70
|
+
- API key via environment variable; secrets never stored in plaintext
|
|
71
|
+
- GDPR right-to-erasure via `memory_forget` (local + on-chain tombstone)
|
|
89
72
|
|
|
90
|
-
##
|
|
73
|
+
## Tests
|
|
91
74
|
|
|
92
75
|
```bash
|
|
93
76
|
npm test # 48 tests, 100% pass
|
package/TECHNICAL.md
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# MemoryForge
|
|
1
|
+
# MemoryForge — Technical Documentation
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Version 0.1.9 | 8 MCP Tools + 5 Auto-Engines | Free (local) + Pro (Shelby cloud)
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
1. [
|
|
8
|
-
2. [
|
|
9
|
-
3. [MCP
|
|
10
|
-
4. [
|
|
11
|
-
5. [Hook
|
|
12
|
-
6. [
|
|
13
|
-
7. [
|
|
14
|
-
8. [
|
|
15
|
-
9. [Pro
|
|
16
|
-
10. [
|
|
7
|
+
1. [System Architecture](#system-architecture)
|
|
8
|
+
2. [Data Model](#data-model)
|
|
9
|
+
3. [MCP Tool API Reference](#mcp-tool-api-reference)
|
|
10
|
+
4. [Auto-Engines](#auto-engines)
|
|
11
|
+
5. [Hook System](#hook-system)
|
|
12
|
+
6. [Storage Layer](#storage-layer)
|
|
13
|
+
7. [Embedding Engine](#embedding-engine)
|
|
14
|
+
8. [Security Model](#security-model)
|
|
15
|
+
9. [Pro Tier (Shelby Cloud)](#pro-tier-shelby-cloud)
|
|
16
|
+
10. [Error Handling & Degradation](#error-handling--degradation)
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## System Architecture
|
|
21
21
|
|
|
22
22
|
```
|
|
23
23
|
┌─────────────────────────────────────┐
|
|
24
|
-
│ AI Agent (Claude Code / Cursor) │ MCP stdio
|
|
24
|
+
│ AI Agent (Claude Code / Cursor) │ MCP stdio protocol
|
|
25
25
|
├─────────────────────────────────────┤
|
|
26
|
-
│ CLI
|
|
26
|
+
│ CLI Router (index.ts) │
|
|
27
27
|
│ setup / pro / hook / MCP Server │
|
|
28
28
|
├─────────────────────────────────────┤
|
|
29
29
|
│ 8 MCP Tools │
|
|
30
30
|
│ store / search / recall / list │
|
|
31
31
|
│ forget / context / export / share │
|
|
32
32
|
├──────────────┬──────────────────────┤
|
|
33
|
-
│ Free
|
|
34
|
-
│
|
|
33
|
+
│ Free Tier │ Pro Tier │
|
|
34
|
+
│ MemoryStore │ ShelbyNodeClient │
|
|
35
35
|
│ local .md │ upload/download/list │
|
|
36
36
|
├──────────────┴──────────────────────┤
|
|
37
|
-
│ 5 Auto
|
|
37
|
+
│ 5 Auto-Engines │
|
|
38
38
|
│ name → merge → priority → decay │
|
|
39
39
|
│ → contextSummary │
|
|
40
40
|
├─────────────────────────────────────┤
|
|
@@ -45,47 +45,47 @@
|
|
|
45
45
|
└─────────────────────────────────────┘
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### Source File Structure
|
|
49
49
|
|
|
50
50
|
```
|
|
51
51
|
agentvault/src/
|
|
52
|
-
├── index.ts #
|
|
53
|
-
├── store.ts # MemoryStore:
|
|
54
|
-
├── embedding.ts # Transformers.js
|
|
55
|
-
├── setup.ts #
|
|
56
|
-
├── pro.ts # Pro
|
|
57
|
-
├── auto/index.ts # 5
|
|
52
|
+
├── index.ts # Entry: CLI routing + MCP Server
|
|
53
|
+
├── store.ts # MemoryStore: in-memory index + search
|
|
54
|
+
├── embedding.ts # Transformers.js lazy-load engine
|
|
55
|
+
├── setup.ts # One-command install flow
|
|
56
|
+
├── pro.ts # Pro activation + bidirectional sync
|
|
57
|
+
├── auto/index.ts # 5 auto-engines
|
|
58
58
|
├── storage/
|
|
59
|
-
│ ├── local.ts # Markdown
|
|
60
|
-
│ └── shelby.ts # Shelby
|
|
61
|
-
├── hooks/install.ts # Claude Code hooks
|
|
62
|
-
└── migrate/import.ts #
|
|
59
|
+
│ ├── local.ts # Markdown file read/write
|
|
60
|
+
│ └── shelby.ts # Shelby cloud API wrapper
|
|
61
|
+
├── hooks/install.ts # Claude Code hooks configuration
|
|
62
|
+
└── migrate/import.ts # Rule import + dedup
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
---
|
|
66
66
|
|
|
67
|
-
##
|
|
67
|
+
## Data Model
|
|
68
68
|
|
|
69
|
-
### Memory
|
|
69
|
+
### Memory Interface
|
|
70
70
|
|
|
71
71
|
```typescript
|
|
72
72
|
interface Memory {
|
|
73
73
|
id: string; // UUID v4
|
|
74
|
-
name: string; //
|
|
75
|
-
content: string; //
|
|
76
|
-
category: string; //
|
|
77
|
-
tags: string[]; //
|
|
78
|
-
priority: number; // 1
|
|
79
|
-
vector: number[]; // 384-dim
|
|
80
|
-
created_at: string; // ISO-8601
|
|
81
|
-
access_count: number; //
|
|
82
|
-
last_accessed: string | null; //
|
|
74
|
+
name: string; // Human-readable name (autoName, max 40 chars)
|
|
75
|
+
content: string; // Raw content
|
|
76
|
+
category: string; // user-preference | project-context | decision-log | code-pattern
|
|
77
|
+
tags: string[]; // Tag list
|
|
78
|
+
priority: number; // 1–10, dynamically adjusted by autoPriority
|
|
79
|
+
vector: number[]; // 384-dim embedding vector
|
|
80
|
+
created_at: string; // ISO-8601 creation timestamp
|
|
81
|
+
access_count: number; // Touch count
|
|
82
|
+
last_accessed: string | null; // Last access timestamp
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
###
|
|
86
|
+
### Local Storage Format
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
Path: `~/.memory-forge/memories/{id}.md`
|
|
89
89
|
|
|
90
90
|
```markdown
|
|
91
91
|
# Memory Name
|
|
@@ -99,22 +99,22 @@ interface Memory {
|
|
|
99
99
|
User prefers camelCase naming, single quotes, and 2-space indent.
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
### MemoryStore
|
|
102
|
+
### MemoryStore Index
|
|
103
103
|
|
|
104
|
-
- `Map<string, Memory>`
|
|
105
|
-
- `Map<string, Float32Array>`
|
|
106
|
-
- LRU
|
|
107
|
-
-
|
|
104
|
+
- `Map<string, Memory>` primary store
|
|
105
|
+
- `Map<string, Float32Array>` vector cache
|
|
106
|
+
- LRU eviction: 5,000 entry cap, evicts lowest `access_count × priority`
|
|
107
|
+
- Dedup: Jaccard similarity > 0.8 triggers auto-merge
|
|
108
108
|
|
|
109
109
|
---
|
|
110
110
|
|
|
111
|
-
## MCP
|
|
111
|
+
## MCP Tool API Reference
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
All tools are invoked via the MCP stdio protocol. The agent receives them automatically — no manual invocation required.
|
|
114
114
|
|
|
115
115
|
### memory_store
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
Store a memory. Auto-embeds, names, and dedup-merges.
|
|
118
118
|
|
|
119
119
|
```typescript
|
|
120
120
|
// Input
|
|
@@ -122,37 +122,37 @@ User prefers camelCase naming, single quotes, and 2-space indent.
|
|
|
122
122
|
content: string; // required, min 1 char
|
|
123
123
|
category?: string; // "general" | "user-preference" | "project-context" | "decision-log" | "code-pattern"
|
|
124
124
|
tags?: string[]; // default: []
|
|
125
|
-
priority?: number; // 1
|
|
125
|
+
priority?: number; // 1–10, default: 5
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// Output (success)
|
|
129
129
|
{
|
|
130
130
|
success: true;
|
|
131
|
-
merged?: boolean; // true if merged with existing
|
|
131
|
+
merged?: boolean; // true if merged with existing (>80% overlap)
|
|
132
132
|
memory_id: string;
|
|
133
133
|
name: string;
|
|
134
134
|
preview: string; // first 200 chars
|
|
135
135
|
}
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
1. `embed(content)` → 384-dim vector (
|
|
140
|
-
2. `autoName(content)` →
|
|
141
|
-
3. `autoMerge(store, memory)` →
|
|
142
|
-
4. `saveMemory(memory)` →
|
|
143
|
-
5. `store.add(memory)` →
|
|
144
|
-
6. Pro: `uploadMemory(memory)` → Shelby
|
|
138
|
+
**Internal pipeline:**
|
|
139
|
+
1. `embed(content)` → 384-dim vector (null on failure)
|
|
140
|
+
2. `autoName(content)` → extract name from content
|
|
141
|
+
3. `autoMerge(store, memory)` → check existing, merge if Jaccard > 0.8
|
|
142
|
+
4. `saveMemory(memory)` → write local Markdown
|
|
143
|
+
5. `store.add(memory)` → update LRU cache
|
|
144
|
+
6. Pro: `uploadMemory(memory)` → Shelby cloud (async, fire-and-forget)
|
|
145
145
|
|
|
146
146
|
### memory_search
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
Semantic memory search. Vector-first, auto-fallback to keyword.
|
|
149
149
|
|
|
150
150
|
```typescript
|
|
151
151
|
// Input
|
|
152
152
|
{
|
|
153
|
-
query: string; // required,
|
|
154
|
-
limit?: number; // 1
|
|
155
|
-
min_similarity?: number; // 0
|
|
153
|
+
query: string; // required, natural language
|
|
154
|
+
limit?: number; // 1–20, default: 5
|
|
155
|
+
min_similarity?: number; // 0–1, default: 0.6
|
|
156
156
|
category?: string; // filter by category
|
|
157
157
|
tags?: string[]; // filter by tags (OR match)
|
|
158
158
|
}
|
|
@@ -172,21 +172,21 @@ User prefers camelCase naming, single quotes, and 2-space indent.
|
|
|
172
172
|
}
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
**Scoring formula (vector mode):**
|
|
176
176
|
```
|
|
177
177
|
score = cosineSimilarity(queryVec, memoryVec)
|
|
178
178
|
× (priority / 5)
|
|
179
179
|
× (1 + min(access_count, 10) × 0.05)
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
**Scoring formula (keyword mode):**
|
|
183
183
|
```
|
|
184
184
|
score = (contentHits × 2 + nameHits × 3) + priority
|
|
185
185
|
```
|
|
186
186
|
|
|
187
187
|
### memory_recall
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
Exact retrieval by memory ID.
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
192
|
// Input
|
|
@@ -204,21 +204,21 @@ score = (contentHits × 2 + nameHits × 3) + priority
|
|
|
204
204
|
|
|
205
205
|
### memory_list
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
List memories with pagination and filtering.
|
|
208
208
|
|
|
209
209
|
```typescript
|
|
210
210
|
// Input
|
|
211
211
|
{
|
|
212
212
|
category?: string; // filter
|
|
213
213
|
tags?: string[]; // filter (OR match)
|
|
214
|
-
limit?: number; // 1
|
|
214
|
+
limit?: number; // 1–100, default: 20
|
|
215
215
|
offset?: number; // default: 0
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// Output
|
|
219
219
|
{
|
|
220
|
-
total: number; //
|
|
221
|
-
count: number; //
|
|
220
|
+
total: number; // total memory count
|
|
221
|
+
count: number; // current page count
|
|
222
222
|
memories: [{
|
|
223
223
|
memory_id, name, category,
|
|
224
224
|
tags, priority,
|
|
@@ -229,7 +229,7 @@ score = (contentHits × 2 + nameHits × 3) + priority
|
|
|
229
229
|
|
|
230
230
|
### memory_forget
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
Delete a memory (local file + in-memory cache).
|
|
233
233
|
|
|
234
234
|
```typescript
|
|
235
235
|
// Input
|
|
@@ -245,30 +245,30 @@ score = (contentHits × 2 + nameHits × 3) + priority
|
|
|
245
245
|
|
|
246
246
|
### memory_context
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
Load current session context — returns top recently-accessed, high-priority memory summaries.
|
|
249
249
|
|
|
250
250
|
```typescript
|
|
251
251
|
// Input
|
|
252
|
-
{ limit?: number; // 1
|
|
252
|
+
{ limit?: number; // 1–20, default: 5 }
|
|
253
253
|
|
|
254
254
|
// Output
|
|
255
255
|
{
|
|
256
256
|
context_loaded: true;
|
|
257
257
|
memory_count: number;
|
|
258
|
-
context: string; //
|
|
258
|
+
context: string; // format: "- [name] preview..."
|
|
259
259
|
}
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
**Sort order:** `access_count` DESC, ties broken by `priority` DESC.
|
|
263
263
|
|
|
264
264
|
### memory_export
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
Export memories as JSON or Markdown.
|
|
267
267
|
|
|
268
268
|
```typescript
|
|
269
269
|
// Input
|
|
270
270
|
{
|
|
271
|
-
memory_ids?: string[]; //
|
|
271
|
+
memory_ids?: string[]; // omit to export all
|
|
272
272
|
format?: "json" | "markdown"; // default: "json"
|
|
273
273
|
}
|
|
274
274
|
|
|
@@ -289,7 +289,7 @@ score = (contentHits × 2 + nameHits × 3) + priority
|
|
|
289
289
|
|
|
290
290
|
### memory_share
|
|
291
291
|
|
|
292
|
-
|
|
292
|
+
Package a single memory for import by teammates.
|
|
293
293
|
|
|
294
294
|
```typescript
|
|
295
295
|
// Input
|
|
@@ -313,78 +313,78 @@ score = (contentHits × 2 + nameHits × 3) + priority
|
|
|
313
313
|
|
|
314
314
|
---
|
|
315
315
|
|
|
316
|
-
##
|
|
316
|
+
## Auto-Engines
|
|
317
317
|
|
|
318
|
-
|
|
318
|
+
All engines are located in `src/auto/index.ts`.
|
|
319
319
|
|
|
320
320
|
### autoName
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
Extracts a human-readable name from content.
|
|
323
323
|
|
|
324
324
|
```
|
|
325
|
-
|
|
326
|
-
1.
|
|
327
|
-
2.
|
|
328
|
-
3.
|
|
329
|
-
4.
|
|
325
|
+
Algorithm:
|
|
326
|
+
1. Strip code blocks (```...```)
|
|
327
|
+
2. Take first 40 chars
|
|
328
|
+
3. Replace newlines with spaces
|
|
329
|
+
4. Empty content → "memory"
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
### autoMerge
|
|
333
333
|
|
|
334
|
-
|
|
334
|
+
Detects and merges duplicate memories.
|
|
335
335
|
|
|
336
336
|
```
|
|
337
|
-
|
|
338
|
-
1. Jaccard
|
|
339
|
-
2.
|
|
340
|
-
3.
|
|
341
|
-
4.
|
|
337
|
+
Algorithm:
|
|
338
|
+
1. Jaccard similarity: |setA ∩ setB| / min(|setA|, |setB|)
|
|
339
|
+
2. Minimum word length: 3 chars
|
|
340
|
+
3. Threshold: > 0.8 → merge
|
|
341
|
+
4. Recompute embedding vector after merge
|
|
342
342
|
```
|
|
343
343
|
|
|
344
344
|
### autoPriority
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
Computes priority score (1–10) based on the Ebbinghaus forgetting curve.
|
|
347
347
|
|
|
348
348
|
```
|
|
349
|
-
|
|
350
|
-
freqWeight
|
|
351
|
-
recencyWeight = 1 - (daysSinceLastAccess / 90) // clamp 0
|
|
352
|
-
ageWeight
|
|
349
|
+
Formula:
|
|
350
|
+
freqWeight = min(access_count, 50) / 50
|
|
351
|
+
recencyWeight = 1 - (daysSinceLastAccess / 90) // clamp 0–1
|
|
352
|
+
ageWeight = 1 - min(ageDays, 365) / 365
|
|
353
353
|
|
|
354
354
|
priority = 1 + 9 × (freqWeight × 0.4 + recencyWeight × 0.4 + ageWeight × 0.2)
|
|
355
355
|
```
|
|
356
356
|
|
|
357
357
|
### autoDecay
|
|
358
358
|
|
|
359
|
-
|
|
359
|
+
Determines whether a memory should be archived.
|
|
360
360
|
|
|
361
361
|
```
|
|
362
|
-
|
|
|
363
|
-
|
|
364
|
-
| ≤1
|
|
365
|
-
| ≤7
|
|
366
|
-
| ≤30
|
|
367
|
-
| ≤90
|
|
368
|
-
| >90
|
|
362
|
+
| Days | Decay Value | Status |
|
|
363
|
+
|----------|-------------|-------------------|
|
|
364
|
+
| ≤1 | 1.0 | Active |
|
|
365
|
+
| ≤7 | 0.8 | Recent |
|
|
366
|
+
| ≤30 | 0.5 | Decaying |
|
|
367
|
+
| ≤90 | 0.2 | Weak |
|
|
368
|
+
| >90 | 0 | Archived (deleted) |
|
|
369
369
|
```
|
|
370
370
|
|
|
371
371
|
### generateContextSummary
|
|
372
372
|
|
|
373
|
-
|
|
373
|
+
Generates a context summary for agent injection.
|
|
374
374
|
|
|
375
375
|
```
|
|
376
|
-
|
|
377
|
-
1.
|
|
378
|
-
2.
|
|
379
|
-
3.
|
|
380
|
-
4.
|
|
376
|
+
Algorithm:
|
|
377
|
+
1. Sort all memories by access_count DESC, priority DESC
|
|
378
|
+
2. Truncate to top-N
|
|
379
|
+
3. Truncate each to 150 chars
|
|
380
|
+
4. Format: "- [name] content..."
|
|
381
381
|
```
|
|
382
382
|
|
|
383
383
|
---
|
|
384
384
|
|
|
385
|
-
## Hook
|
|
385
|
+
## Hook System
|
|
386
386
|
|
|
387
|
-
|
|
387
|
+
Configuration location: `~/.claude/settings.json`
|
|
388
388
|
|
|
389
389
|
```json
|
|
390
390
|
{
|
|
@@ -402,125 +402,126 @@ Ebbinghaus 遗忘曲线判定记忆是否归档。
|
|
|
402
402
|
}
|
|
403
403
|
```
|
|
404
404
|
|
|
405
|
-
###
|
|
405
|
+
### Lifecycle
|
|
406
406
|
|
|
407
407
|
```
|
|
408
|
-
SessionStart →
|
|
408
|
+
SessionStart → Load top-5 memories → Inject into agent context (stdout)
|
|
409
409
|
↓
|
|
410
|
-
Agent
|
|
410
|
+
Agent works → Calls memory_store / memory_search / etc.
|
|
411
411
|
↓
|
|
412
|
-
PreCompact →
|
|
412
|
+
PreCompact → Load top-8 memories + inject save instruction → Agent auto-saves
|
|
413
413
|
↓
|
|
414
|
-
Stop → autoPriority
|
|
414
|
+
Stop → autoPriority recalc + autoDecay check + archive expired
|
|
415
415
|
↓
|
|
416
|
-
(
|
|
416
|
+
(next) SessionStart → Memories preserved ✅
|
|
417
417
|
```
|
|
418
418
|
|
|
419
|
-
###
|
|
419
|
+
### Key Design Decision
|
|
420
420
|
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
**Why PreCompact instead of Stop for auto-capture?**
|
|
422
|
+
|
|
423
|
+
The Stop hook only fires on graceful exit. `kill`, closing the terminal window, or crashes will skip it. PreCompact always fires when the context window approaches its limit — the process is still alive and the agent can execute the save instruction.
|
|
423
424
|
|
|
424
425
|
---
|
|
425
426
|
|
|
426
|
-
##
|
|
427
|
+
## Storage Layer
|
|
427
428
|
|
|
428
|
-
### Free
|
|
429
|
+
### Free Tier (Local Markdown)
|
|
429
430
|
|
|
430
|
-
-
|
|
431
|
-
-
|
|
432
|
-
-
|
|
433
|
-
-
|
|
434
|
-
-
|
|
431
|
+
- Path: `~/.memory-forge/memories/{id}.md`
|
|
432
|
+
- Format: YAML-like frontmatter + Markdown body
|
|
433
|
+
- Encoding: UTF-8
|
|
434
|
+
- Permissions: user filesystem control
|
|
435
|
+
- Network: zero
|
|
435
436
|
|
|
436
|
-
### Pro
|
|
437
|
+
### Pro Tier (Shelby Cloud)
|
|
437
438
|
|
|
438
|
-
- SDK: `@shelby-protocol/sdk` ^0.3.1 (
|
|
439
|
-
-
|
|
440
|
-
-
|
|
441
|
-
- Blob
|
|
442
|
-
-
|
|
443
|
-
-
|
|
439
|
+
- SDK: `@shelby-protocol/sdk` ^0.3.1 (optionalDependency)
|
|
440
|
+
- Network: Shelbynet testnet
|
|
441
|
+
- Auth: API Key + Ed25519 on-chain account
|
|
442
|
+
- Blob format: `memories/{id}.json` (JSON)
|
|
443
|
+
- Expiry: 365 days
|
|
444
|
+
- Data flow: bidirectional sync (↓↑ on session start, ↑ on memory_store)
|
|
444
445
|
|
|
445
|
-
**Pro
|
|
446
|
+
**Pro data flow:**
|
|
446
447
|
```
|
|
447
448
|
SessionStart:
|
|
448
449
|
syncAll():
|
|
449
|
-
↓ listBlobs() →
|
|
450
|
-
↓ downloadMemory() →
|
|
451
|
-
↑ uploadMemory() →
|
|
452
|
-
→
|
|
450
|
+
↓ listBlobs() → fetch remote memory list
|
|
451
|
+
↓ downloadMemory() → download anything not local (30s timeout)
|
|
452
|
+
↑ uploadMemory() → upload local-only memories
|
|
453
|
+
→ Bidirectional sync complete
|
|
453
454
|
|
|
454
455
|
memory_store:
|
|
455
|
-
saveMemory() →
|
|
456
|
-
uploadMemory() → Shelby (fire-and-forget,
|
|
456
|
+
saveMemory() → local
|
|
457
|
+
uploadMemory() → Shelby (fire-and-forget, failure is non-blocking)
|
|
457
458
|
```
|
|
458
459
|
|
|
459
460
|
---
|
|
460
461
|
|
|
461
|
-
##
|
|
462
|
+
## Embedding Engine
|
|
462
463
|
|
|
463
|
-
###
|
|
464
|
+
### Tech Stack
|
|
464
465
|
|
|
465
|
-
-
|
|
466
|
-
-
|
|
467
|
-
-
|
|
468
|
-
-
|
|
469
|
-
-
|
|
466
|
+
- Library: `@huggingface/transformers` ^3.0.0
|
|
467
|
+
- Model: Xenova/all-MiniLM-L6-v2
|
|
468
|
+
- Size: ~23MB (one-time download, cached thereafter)
|
|
469
|
+
- Dimensions: 384
|
|
470
|
+
- Pooling: mean pooling + L2 normalization
|
|
470
471
|
|
|
471
|
-
###
|
|
472
|
+
### Degradation Strategy
|
|
472
473
|
|
|
473
474
|
```
|
|
474
|
-
|
|
475
|
-
→
|
|
476
|
-
→
|
|
477
|
-
+ 5
|
|
478
|
-
+ sleep(300s)
|
|
475
|
+
Load model
|
|
476
|
+
→ Success: cosine similarity search
|
|
477
|
+
→ Failure: keyword matching (Jaccard)
|
|
478
|
+
+ 5-minute auto-retry
|
|
479
|
+
+ sleep(300s) to prevent request storms
|
|
479
480
|
```
|
|
480
481
|
|
|
481
|
-
###
|
|
482
|
+
### Performance
|
|
482
483
|
|
|
483
|
-
-
|
|
484
|
-
-
|
|
485
|
-
-
|
|
486
|
-
-
|
|
484
|
+
- First load: 3–10s (depends on network; 23MB download)
|
|
485
|
+
- Subsequent inference: < 100ms
|
|
486
|
+
- Keyword fallback: < 10ms
|
|
487
|
+
- Model caching: Transformers.js built-in cache
|
|
487
488
|
|
|
488
489
|
---
|
|
489
490
|
|
|
490
|
-
##
|
|
491
|
+
## Security Model
|
|
491
492
|
|
|
492
|
-
### Free
|
|
493
|
+
### Free Tier
|
|
493
494
|
|
|
494
|
-
-
|
|
495
|
-
-
|
|
496
|
-
-
|
|
497
|
-
-
|
|
495
|
+
- All data in `~/.memory-forge/` directory
|
|
496
|
+
- Zero ongoing network requests
|
|
497
|
+
- Only network: one-time model download (HuggingFace CDN, 23MB)
|
|
498
|
+
- Model download failure → keyword fallback, zero functionality loss
|
|
498
499
|
|
|
499
|
-
### Pro
|
|
500
|
+
### Pro Tier
|
|
500
501
|
|
|
501
|
-
- API Key:
|
|
502
|
-
-
|
|
503
|
-
-
|
|
504
|
-
-
|
|
505
|
-
-
|
|
502
|
+
- API Key: `SHELBY_API_KEY` environment variable only — never written to disk
|
|
503
|
+
- Private Key: `~/.memory-forge/pro.json`, Ed25519 format
|
|
504
|
+
- Transport: HTTPS (Shelbynet API)
|
|
505
|
+
- On-chain: each memory → Aptos blob upload transaction
|
|
506
|
+
- Deletion: tombstone blob (marks deletion; chain is immutable)
|
|
506
507
|
|
|
507
|
-
###
|
|
508
|
+
### Memory Permissions
|
|
508
509
|
|
|
509
|
-
-
|
|
510
|
-
-
|
|
511
|
-
-
|
|
510
|
+
- Filesystem permissions = memory permissions (Free)
|
|
511
|
+
- On-chain account signature = memory permissions (Pro)
|
|
512
|
+
- No built-in auth layer (agent is already authenticated by Claude Code)
|
|
512
513
|
|
|
513
514
|
---
|
|
514
515
|
|
|
515
|
-
##
|
|
516
|
-
|
|
517
|
-
|
|
|
518
|
-
|
|
519
|
-
|
|
|
520
|
-
|
|
|
521
|
-
| Shelby
|
|
522
|
-
| Shelby
|
|
523
|
-
| Shelby
|
|
524
|
-
| parseMemoryFile
|
|
525
|
-
|
|
|
526
|
-
| LRU
|
|
516
|
+
## Error Handling & Degradation
|
|
517
|
+
|
|
518
|
+
| Scenario | Behavior | Impact |
|
|
519
|
+
|----------|----------|--------|
|
|
520
|
+
| Embedding model download fails | Keyword search, 5min retry | Lower search precision, functional |
|
|
521
|
+
| Embedding model inference fails | Return null, keyword fallback | Single query degraded |
|
|
522
|
+
| Shelby upload fails | console.error, non-blocking | Pro sync delayed, local intact |
|
|
523
|
+
| Shelby download timeout | 30s timeout, return null | That memory skipped, others OK |
|
|
524
|
+
| Shelby on-chain gas insufficient | Upload fails + error message | Pro unavailable, Free intact |
|
|
525
|
+
| parseMemoryFile corrupt | Skip file, return null | Corrupt file ignored |
|
|
526
|
+
| Disk write fails | Silent failure | Memory lost (extremely rare) |
|
|
527
|
+
| LRU at 5,000 limit | Evict lowest access_count × priority | Old memories evicted from cache, disk preserved |
|
package/TUTORIAL.md
CHANGED
|
@@ -1,353 +1,349 @@
|
|
|
1
|
-
# MemoryForge
|
|
1
|
+
# MemoryForge — Tutorial
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> One command. Zero config. Your AI agent now has persistent memory.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
1. [
|
|
8
|
-
2. [
|
|
9
|
-
3. [
|
|
10
|
-
4. [Pro
|
|
11
|
-
5. [
|
|
12
|
-
6. [
|
|
13
|
-
7. [
|
|
14
|
-
8. [
|
|
7
|
+
1. [Quick Start](#quick-start)
|
|
8
|
+
2. [How It Works](#how-it-works)
|
|
9
|
+
3. [Daily Use](#daily-use)
|
|
10
|
+
4. [Pro Tier (Cloud Sync)](#pro-tier-cloud-sync)
|
|
11
|
+
5. [Managing Memories](#managing-memories)
|
|
12
|
+
6. [Best Practices](#best-practices)
|
|
13
|
+
7. [Troubleshooting](#troubleshooting)
|
|
14
|
+
8. [Uninstall](#uninstall)
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Quick Start
|
|
19
19
|
|
|
20
|
-
###
|
|
20
|
+
### Install
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
npx memory-forge setup
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
26
|
+
This single command:
|
|
27
|
+
- Installs Claude Code hooks (SessionStart / Stop / PreCompact)
|
|
28
|
+
- Auto-imports existing rules (CLAUDE.md / .cursor/rules / .gitconfig)
|
|
29
|
+
- Preloads the embedding model (23MB, one-time, offline thereafter)
|
|
30
|
+
- Globally installs the `memory-forge` command
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
**Supported platforms:** Claude Code (all platforms), Cursor (via MCP), Windsurf, VS Code.
|
|
33
33
|
|
|
34
|
-
###
|
|
34
|
+
### Verify
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
Restart Claude Code. You should see:
|
|
37
37
|
|
|
38
38
|
```
|
|
39
39
|
- [Git User Info] Git user email: xxx
|
|
40
40
|
- [Claude Code Rules] For independent parallel tasks...
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
This means the SessionStart hook is active and the agent has loaded your memories.
|
|
44
44
|
|
|
45
45
|
---
|
|
46
46
|
|
|
47
|
-
##
|
|
47
|
+
## How It Works
|
|
48
48
|
|
|
49
|
-
###
|
|
49
|
+
### Automated Memory Lifecycle
|
|
50
50
|
|
|
51
51
|
```
|
|
52
|
-
|
|
53
|
-
→ Agent
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
→ Agent
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
→ Agent
|
|
60
|
-
→
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
→
|
|
64
|
-
→
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
→ Agent
|
|
52
|
+
You open Claude Code
|
|
53
|
+
→ Agent auto-loads your preferences and project context
|
|
54
|
+
|
|
55
|
+
You work...
|
|
56
|
+
→ Agent automatically remembers your coding style, technical decisions, project preferences
|
|
57
|
+
|
|
58
|
+
Context window nearly full (PreCompact)
|
|
59
|
+
→ Agent auto-saves critical information to the memory store
|
|
60
|
+
→ Even if you force-close the terminal, memories survive
|
|
61
|
+
|
|
62
|
+
You close Claude Code (Stop)
|
|
63
|
+
→ Auto-update memory priorities (frequently-used memories get higher weight)
|
|
64
|
+
→ Auto-archive memories unused for 90+ days
|
|
65
|
+
|
|
66
|
+
Next session
|
|
67
|
+
→ Agent remembers everything ✅
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
###
|
|
70
|
+
### You Do Nothing
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
72
|
+
The agent automatically:
|
|
73
|
+
- **Stores**: you mention preferences, decisions, lessons → agent calls `memory_store`
|
|
74
|
+
- **Searches**: needs to recall something → agent calls `memory_search`
|
|
75
|
+
- **Maintains**: priority adjustment, expiry cleanup → fully automatic
|
|
76
76
|
|
|
77
77
|
---
|
|
78
78
|
|
|
79
|
-
##
|
|
79
|
+
## Daily Use
|
|
80
80
|
|
|
81
|
-
###
|
|
81
|
+
### Basic Interaction
|
|
82
82
|
|
|
83
83
|
```
|
|
84
|
-
|
|
84
|
+
You: "I prefer camelCase naming, single quotes, 2-space indent"
|
|
85
85
|
|
|
86
|
-
Agent
|
|
87
|
-
|
|
86
|
+
Agent auto-calls memory_store → memory saved ✅
|
|
87
|
+
Next time you write code, the agent follows your preferences automatically.
|
|
88
88
|
|
|
89
89
|
---
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
You: "How did we fix that token refresh bug?"
|
|
92
92
|
|
|
93
|
-
Agent
|
|
94
|
-
"
|
|
93
|
+
Agent calls memory_search → finds relevant memory
|
|
94
|
+
"On June 15, you fixed auth.ts — the token expiry check was using < instead of <="
|
|
95
95
|
|
|
96
96
|
---
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
You: "Help me refactor the auth module"
|
|
99
99
|
|
|
100
|
-
Agent
|
|
101
|
-
"
|
|
100
|
+
Agent calls memory_context → loads context
|
|
101
|
+
"Got it. Based on prior records, this project uses React 19 + JWT + refresh token pattern. Start from auth.ts?"
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
###
|
|
104
|
+
### Explicit Commands
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
You can also tell the agent explicitly:
|
|
107
107
|
|
|
108
108
|
```
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
109
|
+
"Store a memory: production database uses PostgreSQL 16, connection string in .env.production"
|
|
110
|
+
"Search for memories about deployment"
|
|
111
|
+
"List all my memories"
|
|
112
|
+
"Export all memories as Markdown"
|
|
113
|
+
"Forget the memory with ID xxx"
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
---
|
|
117
117
|
|
|
118
|
-
## Pro
|
|
118
|
+
## Pro Tier (Cloud Sync)
|
|
119
119
|
|
|
120
|
-
###
|
|
120
|
+
### When You Need Pro
|
|
121
121
|
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
122
|
+
- You use multiple computers and want cross-device memory sync
|
|
123
|
+
- You're worried about disk failure losing your memories
|
|
124
|
+
- You want shared project memories with teammates
|
|
125
125
|
|
|
126
|
-
###
|
|
126
|
+
### Activating Pro
|
|
127
127
|
|
|
128
128
|
```bash
|
|
129
|
-
# 1.
|
|
130
|
-
#
|
|
129
|
+
# 1. Get an API Key
|
|
130
|
+
# Visit https://docs.shelby.xyz/sdks/typescript/acquire-api-keys
|
|
131
131
|
|
|
132
|
-
# 2.
|
|
132
|
+
# 2. Activate Pro
|
|
133
133
|
SHELBY_API_KEY="your-api-key" memory-forge pro
|
|
134
134
|
|
|
135
|
-
# 3.
|
|
136
|
-
#
|
|
135
|
+
# 3. First time: fund your account with APT + ShelbyUSD (testnet faucet)
|
|
136
|
+
# The address will be printed. Go to the faucet:
|
|
137
137
|
# APT: https://docs.shelby.xyz/apis/faucet/aptos
|
|
138
138
|
# ShelbyUSD: https://docs.shelby.xyz/apis/faucet/shelbyusd
|
|
139
139
|
|
|
140
|
-
# 4.
|
|
140
|
+
# 4. After claiming tokens, sync again
|
|
141
141
|
SHELBY_API_KEY="your-api-key" memory-forge pro
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
###
|
|
144
|
+
### Cross-Device Sync
|
|
145
145
|
|
|
146
146
|
```
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
→ Agent
|
|
147
|
+
Device A: Activate Pro → work → memories auto-upload
|
|
148
|
+
Device B: Set SHELBY_API_KEY env var → install → memories auto-download
|
|
149
|
+
→ Agent on device B remembers everything ✅
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
###
|
|
152
|
+
### Environment Variable
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
Add to your shell config for permanent setup:
|
|
155
155
|
|
|
156
156
|
```bash
|
|
157
|
-
# ~/.bashrc
|
|
157
|
+
# ~/.bashrc or ~/.zshrc
|
|
158
158
|
export SHELBY_API_KEY="your-api-key"
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
The agent will auto-sync on every session start.
|
|
162
162
|
|
|
163
163
|
---
|
|
164
164
|
|
|
165
|
-
##
|
|
165
|
+
## Managing Memories
|
|
166
166
|
|
|
167
|
-
###
|
|
167
|
+
### Viewing Memories
|
|
168
168
|
|
|
169
169
|
```bash
|
|
170
|
-
#
|
|
170
|
+
# List memory files
|
|
171
171
|
ls ~/.memory-forge/memories/
|
|
172
172
|
|
|
173
|
-
#
|
|
173
|
+
# Read a specific memory
|
|
174
174
|
cat ~/.memory-forge/memories/{id}.md
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
Memory files are human-readable Markdown. You can edit them directly.
|
|
178
178
|
|
|
179
|
-
###
|
|
179
|
+
### Exporting
|
|
180
180
|
|
|
181
181
|
```
|
|
182
|
-
#
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
|
|
186
|
-
# 命令行方式
|
|
187
|
-
# JSON 导出在 Agent 调用 memory_export 后获取
|
|
182
|
+
# Via agent
|
|
183
|
+
"Export all memories as JSON"
|
|
184
|
+
"Export auth-related memories as Markdown"
|
|
188
185
|
```
|
|
189
186
|
|
|
190
|
-
###
|
|
187
|
+
### Backup
|
|
191
188
|
|
|
192
189
|
```bash
|
|
193
|
-
#
|
|
190
|
+
# Local backup (Free tier)
|
|
194
191
|
cp -r ~/.memory-forge/memories/ ~/backup/
|
|
195
192
|
|
|
196
|
-
# Pro
|
|
193
|
+
# Pro tier auto-backs up to Shelby cloud
|
|
197
194
|
```
|
|
198
195
|
|
|
199
|
-
###
|
|
196
|
+
### Cleanup
|
|
200
197
|
|
|
201
198
|
```bash
|
|
202
|
-
#
|
|
199
|
+
# Delete all local memories
|
|
203
200
|
rm -rf ~/.memory-forge/memories/*.md
|
|
204
201
|
|
|
205
|
-
#
|
|
202
|
+
# Delete a single memory
|
|
206
203
|
rm ~/.memory-forge/memories/{id}.md
|
|
207
204
|
|
|
208
|
-
# Pro
|
|
205
|
+
# Reset Pro account
|
|
209
206
|
rm ~/.memory-forge/pro.json
|
|
210
207
|
```
|
|
211
208
|
|
|
212
209
|
---
|
|
213
210
|
|
|
214
|
-
##
|
|
211
|
+
## Best Practices
|
|
215
212
|
|
|
216
|
-
###
|
|
213
|
+
### What's Worth Remembering
|
|
217
214
|
|
|
218
|
-
|
|
|
219
|
-
|
|
220
|
-
|
|
|
221
|
-
|
|
|
222
|
-
|
|
|
223
|
-
|
|
|
224
|
-
|
|
|
215
|
+
| Worth It | Not Worth It |
|
|
216
|
+
|----------|--------------|
|
|
217
|
+
| Coding style preferences | One-off debug sessions |
|
|
218
|
+
| Project architecture decisions | Temporary experimental code |
|
|
219
|
+
| Team conventions | Outdated configuration |
|
|
220
|
+
| Frequently-used commands and workflows | Pure factual knowledge |
|
|
221
|
+
| Lessons learned and solutions found | One-time tasks |
|
|
225
222
|
|
|
226
|
-
###
|
|
223
|
+
### Memory Quality
|
|
227
224
|
|
|
228
225
|
```
|
|
229
|
-
✅
|
|
230
|
-
❌
|
|
226
|
+
✅ Good: "Project uses PostgreSQL 16 + Prisma ORM, connection pool limit 20"
|
|
227
|
+
❌ Bad: "database is pg"
|
|
231
228
|
|
|
232
|
-
✅
|
|
233
|
-
❌
|
|
229
|
+
✅ Good: "User prefers camelCase, single quotes, 2-space indent, React 19 + TypeScript strict"
|
|
230
|
+
❌ Bad: "uses camelCase"
|
|
234
231
|
|
|
235
|
-
✅
|
|
236
|
-
❌
|
|
232
|
+
✅ Good: "6/26 — decided to cache tokens in Redis because DB queries were >500ms"
|
|
233
|
+
❌ Bad: "added Redis"
|
|
237
234
|
```
|
|
238
235
|
|
|
239
|
-
###
|
|
236
|
+
### Periodic Maintenance
|
|
240
237
|
|
|
241
|
-
|
|
238
|
+
Do a memory cleanup once a month:
|
|
242
239
|
|
|
243
240
|
```
|
|
244
|
-
"
|
|
245
|
-
"
|
|
241
|
+
"Review all my memories and flag anything outdated or no longer needed"
|
|
242
|
+
"Forget memories related to projects I no longer work on"
|
|
246
243
|
```
|
|
247
244
|
|
|
248
245
|
---
|
|
249
246
|
|
|
250
|
-
##
|
|
247
|
+
## Troubleshooting
|
|
251
248
|
|
|
252
|
-
###
|
|
249
|
+
### Hooks Not Working
|
|
253
250
|
|
|
254
|
-
|
|
251
|
+
**Symptom:** Opening Claude Code shows no memory loading.
|
|
255
252
|
|
|
256
|
-
**解决:**
|
|
257
253
|
```bash
|
|
258
|
-
# 1.
|
|
254
|
+
# 1. Check hook configuration
|
|
259
255
|
memory-forge hook session-start
|
|
260
256
|
|
|
261
|
-
# 2.
|
|
257
|
+
# 2. Reinstall hooks
|
|
262
258
|
memory-forge setup
|
|
263
259
|
|
|
264
|
-
# 3.
|
|
260
|
+
# 3. Verify settings.json
|
|
265
261
|
cat ~/.claude/settings.json | grep memory-forge
|
|
266
262
|
|
|
267
|
-
# 4.
|
|
263
|
+
# 4. Restart Claude Code
|
|
268
264
|
```
|
|
269
265
|
|
|
270
|
-
### Stop
|
|
266
|
+
### Stop Hook Error
|
|
271
267
|
|
|
272
|
-
|
|
268
|
+
**Symptom:** "Stop hook error" on session close.
|
|
273
269
|
|
|
274
270
|
```bash
|
|
275
|
-
#
|
|
271
|
+
# Confirm global install
|
|
276
272
|
npm ls -g memory-forge
|
|
277
273
|
|
|
278
|
-
#
|
|
274
|
+
# If not latest
|
|
279
275
|
npm i -g memory-forge@latest
|
|
280
276
|
|
|
281
|
-
#
|
|
282
|
-
# settings.json
|
|
277
|
+
# Check hook command format
|
|
278
|
+
# settings.json should have "memory-forge hook stop", not "npx memory-forge hook stop"
|
|
283
279
|
```
|
|
284
280
|
|
|
285
|
-
###
|
|
281
|
+
### Inaccurate Search Results
|
|
286
282
|
|
|
287
|
-
|
|
283
|
+
**Symptom:** `memory_search` returns irrelevant results.
|
|
288
284
|
|
|
289
285
|
```bash
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
# →
|
|
286
|
+
# Check if embedding model downloaded successfully
|
|
287
|
+
# If you see "[MemoryForge] Falling back to keyword matching"
|
|
288
|
+
# → Model download failed; keyword mode is active
|
|
293
289
|
|
|
294
|
-
#
|
|
295
|
-
#
|
|
290
|
+
# Solution: wait 5 minutes for auto-retry, or trigger a retry manually
|
|
291
|
+
# Model size is 23MB — ensure network is working
|
|
296
292
|
```
|
|
297
293
|
|
|
298
|
-
### Pro
|
|
294
|
+
### Pro Sync Fails
|
|
299
295
|
|
|
300
|
-
|
|
296
|
+
**Symptom:** "Shelby upload failed: INSUFFICIENT_BALANCE_FOR_TRANSACTION_FEE"
|
|
301
297
|
|
|
302
298
|
```bash
|
|
303
|
-
#
|
|
304
|
-
#
|
|
305
|
-
#
|
|
299
|
+
# Check account balance
|
|
300
|
+
# Visit the faucet to claim APT + ShelbyUSD
|
|
301
|
+
# Then re-run pro
|
|
306
302
|
|
|
307
303
|
SHELBY_API_KEY="your-key" memory-forge pro
|
|
308
304
|
```
|
|
309
305
|
|
|
310
|
-
###
|
|
306
|
+
### Duplicate Memories
|
|
311
307
|
|
|
312
|
-
|
|
308
|
+
**Symptom:** `memory_list` shows repeated similar memories.
|
|
313
309
|
|
|
314
310
|
```bash
|
|
315
|
-
# 0.1.6+
|
|
316
|
-
# 1.
|
|
311
|
+
# 0.1.6+ has a root-cause fix. If you still see duplicates:
|
|
312
|
+
# 1. Upgrade to latest
|
|
317
313
|
npm i -g memory-forge@latest
|
|
318
314
|
memory-forge setup
|
|
319
315
|
|
|
320
|
-
# 2.
|
|
321
|
-
#
|
|
316
|
+
# 2. Manual cleanup
|
|
317
|
+
# Delete duplicate .md files in ~/.memory-forge/memories/
|
|
322
318
|
```
|
|
323
319
|
|
|
324
|
-
###
|
|
320
|
+
### Full Reset
|
|
325
321
|
|
|
326
322
|
```bash
|
|
327
|
-
# 1.
|
|
323
|
+
# 1. Delete memories
|
|
328
324
|
rm -rf ~/.memory-forge/memories/*.md
|
|
329
325
|
|
|
330
|
-
# 2.
|
|
326
|
+
# 2. Delete Pro account (optional)
|
|
331
327
|
rm -f ~/.memory-forge/pro.json
|
|
332
328
|
|
|
333
|
-
# 3.
|
|
334
|
-
#
|
|
329
|
+
# 3. Clear hooks
|
|
330
|
+
# Edit ~/.claude/settings.json, remove all entries containing "memory-forge"
|
|
335
331
|
|
|
336
|
-
# 4.
|
|
332
|
+
# 4. Reinstall
|
|
337
333
|
memory-forge setup
|
|
338
334
|
```
|
|
339
335
|
|
|
340
336
|
---
|
|
341
337
|
|
|
342
|
-
##
|
|
338
|
+
## Uninstall
|
|
343
339
|
|
|
344
340
|
```bash
|
|
345
|
-
#
|
|
341
|
+
# Remove all local data
|
|
346
342
|
rm -rf ~/.memory-forge/
|
|
347
343
|
|
|
348
|
-
#
|
|
349
|
-
#
|
|
344
|
+
# Edit ~/.claude/settings.json
|
|
345
|
+
# Remove all hook entries containing "memory-forge"
|
|
350
346
|
|
|
351
|
-
#
|
|
347
|
+
# Uninstall global command
|
|
352
348
|
npm uninstall -g memory-forge
|
|
353
349
|
```
|
package/dist/index.js
CHANGED
|
@@ -95,7 +95,7 @@ function startMcpServer() {
|
|
|
95
95
|
store.add(m);
|
|
96
96
|
}
|
|
97
97
|
preload();
|
|
98
|
-
const server = new McpServer({ name: "memory-forge", version: "0.
|
|
98
|
+
const server = new McpServer({ name: "memory-forge", version: "0.2.0" });
|
|
99
99
|
// ── memory_store ──────────────────────────────────────────
|
|
100
100
|
server.registerTool("memory_store", {
|
|
101
101
|
title: "存储记忆",
|
package/package.json
CHANGED