@aman_asmuei/amem 0.3.0 → 0.4.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 CHANGED
@@ -1,264 +1,180 @@
1
- <div align="center">
1
+ <p align="center">
2
+ <img src="assets/logo.png" alt="amem" width="180" />
3
+ </p>
2
4
 
3
- # amem
5
+ <h3 align="center">Give your AI a memory it never forgets</h3>
4
6
 
5
- ### Give your AI a memory it never forgets
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/@aman_asmuei/amem"><img src="https://img.shields.io/npm/v/@aman_asmuei/amem.svg?style=flat-square&color=cb3837" /></a>
9
+ <a href="https://github.com/amanasmuei/amem/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square" /></a>
10
+ <a href="https://github.com/amanasmuei/amem/actions"><img src="https://img.shields.io/github/actions/workflow/status/amanasmuei/amem/ci.yml?style=flat-square&label=tests" /></a>
11
+ <img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=flat-square" />
12
+ <img src="https://img.shields.io/badge/MCP-compatible-8A2BE2?style=flat-square" />
13
+ </p>
6
14
 
7
- Your AI assistant forgets everything the moment a conversation ends.<br/>
8
- **amem** gives it persistent memory so it remembers your preferences, decisions, and corrections forever.
9
-
10
- [![npm version](https://img.shields.io/npm/v/@aman_asmuei/amem.svg?style=flat-square&color=cb3837)](https://www.npmjs.com/package/@aman_asmuei/amem)
11
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](LICENSE)
12
- [![CI](https://img.shields.io/github/actions/workflow/status/amanasmuei/amem/ci.yml?style=flat-square&label=tests)](https://github.com/amanasmuei/amem/actions)
13
- [![Node](https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=flat-square)](https://nodejs.org)
14
- [![MCP](https://img.shields.io/badge/MCP-compatible-8A2BE2?style=flat-square)](https://modelcontextprotocol.io)
15
-
16
- [Get Started](#get-started) · [How It Works](#how-it-works) · [Tools](#tools) · [Resources & Prompts](#resources--prompts) · [CLI](#cli) · [FAQ](#faq) · [Contributing](#contributing)
17
-
18
- </div>
15
+ <p align="center">
16
+ <b>amem</b> (<b>A</b>man's <b>Mem</b>ory) is the memory layer for AI coding tools.<br/>
17
+ Local-first · Semantic · Lossless · Works with Claude Code, Cursor, Windsurf &amp; any MCP client.
18
+ </p>
19
19
 
20
20
  ---
21
21
 
22
22
  ## The Problem
23
23
 
24
- Every time you start a new conversation with an AI coding assistant, it starts from zero. It doesn't know:
24
+ Every time you start a new conversation with an AI coding assistant, it starts from zero:
25
25
 
26
- - That you told it **three times** not to use `any` in TypeScript
27
- - That your team **chose PostgreSQL** over MongoDB last month (and why)
28
- - That you **prefer** functional style, early returns, and pnpm
29
- - Where your auth module lives, or how your project is structured
26
+ - You told it **three times** not to use `any` in TypeScript — it still does
27
+ - Your team **chose PostgreSQL** over MongoDB last month it doesn't know why
28
+ - You **prefer** functional style, early returns, and pnpm — explained again and again
29
+ - A critical decision was made **last week** now it's gone forever
30
30
 
31
- You end up repeating yourself. Every. Single. Time.
31
+ You repeat yourself. Every. Single. Session.
32
32
 
33
33
  ## The Solution
34
34
 
35
- **amem** is a memory layer that plugs into any AI tool Claude Code, Cursor, Windsurf, or anything that speaks MCP. It remembers what matters and surfaces it automatically.
35
+ **amem** is a persistent memory layer that plugs into any MCP-compatible AI tool. It remembers what matters, surfaces it automatically, and never loses anything from distilled memories to raw conversation history.
36
36
 
37
37
  ```
38
38
  You: "Don't use any type in TypeScript"
39
39
 
40
- amem saves this as a correction (highest priority).
41
- Next conversation — or next month your AI already knows.
40
+ amem stores this as a correction (priority 1.0)
41
+ next session, your AI already knows — and won't forget
42
42
  ```
43
43
 
44
44
  ---
45
45
 
46
- ## What Gets Remembered
46
+ ## What's New in v0.4.0
47
47
 
48
- amem organizes memories into six types, ranked by importance:
48
+ | Feature | Description |
49
+ |---|---|
50
+ | 🗒️ **Lossless conversation log** | `memory_log` / `memory_log_recall` — append-only raw turns, nothing ever summarized or lost |
51
+ | 🔧 **Patch system** | `memory_patch` — surgical field-level edits, auto-versioned before every change |
52
+ | 📜 **Version history** | `memory_versions` — full edit history, restore any past snapshot |
53
+ | 🕸️ **Knowledge graph** | `memory_relate` — typed relations between memories (supports, causes, implements…) |
54
+ | ⏱️ **Temporal queries** | `memory_since` — "what changed last week?" in natural language |
55
+ | 🔍 **Full-text search** | `memory_search` — exact FTS5 keyword search, complements semantic recall |
56
+ | ⚡ **FTS5 auto-sync** | SQLite triggers keep the index in sync on every insert, update, delete |
49
57
 
50
- | Priority | Type | What it captures | Example |
51
- |:--------:|------|-----------------|---------|
52
- | 1.0 | **Correction** | Mistakes to never repeat | *"Don't mock the database in integration tests"* |
53
- | 0.85 | **Decision** | Architectural choices + why | *"Chose Postgres over MongoDB for ACID compliance"* |
54
- | 0.7 | **Pattern** | Coding style & habits | *"Prefers early returns over nested conditionals"* |
55
- | 0.7 | **Preference** | Tool & workflow choices | *"Uses pnpm, not npm"* |
56
- | 0.5 | **Topology** | Where things are | *"Auth module lives in src/auth/, uses JWT"* |
57
- | 0.4 | **Fact** | General project knowledge | *"API uses REST, launched January 2025"* |
58
+ ---
58
59
 
59
- Corrections always surface first. They're the "never do this" rules your AI should always follow.
60
+ ## Feature Comparison
61
+
62
+ | Feature | amem v0.4 | Claude Code |
63
+ |---|---|---|
64
+ | Session memory | ✅ SQLite — persists across sessions | ✅ Context window only |
65
+ | Persistent identity | ✅ `~/.amem/memory.db` | ✅ `CLAUDE.md` |
66
+ | Auto accumulation | ✅ `memory_extract` batch | ✅ `MEMORY.md` auto |
67
+ | Memory consolidation | ✅ Merge · prune · promote | ✅ Auto-dream |
68
+ | Semantic recall | ✅ Cosine similarity + keyword | ✅ Chat search |
69
+ | Per-project scope | ✅ Auto git-detected | ✅ `./CLAUDE.md` |
70
+ | Memory export | ✅ Markdown + CLI | 🟡 "Write verbatim" |
71
+ | **Lossless history** | ✅ Append-only conversation log | 🔴 Lossy summarization |
72
+ | **Patch system** | ✅ Field-level, auto-versioned | 🔴 None |
73
+ | **Version history** | ✅ Full edit history + restore | 🔴 None |
74
+ | **Knowledge graph** | ✅ Typed memory relations | 🔴 None |
75
+ | **Temporal queries** | ✅ "since 7d", date ranges | 🔴 None |
76
+ | **Full-text search** | ✅ FTS5 exact match | 🔴 None |
60
77
 
61
78
  ---
62
79
 
63
80
  ## Get Started
64
81
 
65
- ### Step 1: Install
66
-
67
- You need [Node.js](https://nodejs.org) 18 or higher. Then:
82
+ ### Install
68
83
 
69
84
  ```bash
70
85
  npm install -g @aman_asmuei/amem
71
86
  ```
72
87
 
73
- That's it. amem is now installed on your machine.
88
+ Node.js 18+ required. No cloud accounts, no API keys.
74
89
 
75
- ### Step 2: Connect your AI tool
90
+ ### Connect your AI tool
76
91
 
77
- <details>
78
- <summary><strong>Claude Code</strong></summary>
92
+ **Claude Code**
79
93
 
80
- Add to `~/.claude/settings.json`:
81
-
82
- ```json
83
- {
84
- "mcpServers": {
85
- "amem": {
86
- "command": "amem"
87
- }
88
- }
89
- }
94
+ ```bash
95
+ claude mcp add amem -- npx -y @aman_asmuei/amem
90
96
  ```
91
97
 
92
- Restart Claude Code. You'll see 9 memory tools, 4 resources, and 2 prompts available.
93
-
94
- </details>
95
-
96
- <details>
97
- <summary><strong>Cursor</strong></summary>
98
-
99
- Add to `.cursor/mcp.json` in your project:
98
+ Or manually in `~/.claude/settings.json`:
100
99
 
101
100
  ```json
102
101
  {
103
102
  "mcpServers": {
104
103
  "amem": {
105
- "command": "amem"
104
+ "command": "npx",
105
+ "args": ["-y", "@aman_asmuei/amem"]
106
106
  }
107
107
  }
108
108
  }
109
109
  ```
110
110
 
111
- Restart Cursor.
112
-
113
- </details>
114
-
115
- <details>
116
- <summary><strong>Windsurf</strong></summary>
117
-
118
- Add to your MCP configuration:
111
+ **Cursor / Windsurf / any MCP client**
119
112
 
120
113
  ```json
121
114
  {
122
115
  "mcpServers": {
123
- "amem": {
124
- "command": "amem"
125
- }
116
+ "amem": { "command": "amem" }
126
117
  }
127
118
  }
128
119
  ```
129
120
 
130
- </details>
131
-
132
- <details>
133
- <summary><strong>Any other MCP client</strong></summary>
134
-
135
- amem speaks standard [Model Context Protocol](https://modelcontextprotocol.io/) over stdio. Point your client to:
136
-
137
- ```bash
138
- npx @aman_asmuei/amem
139
- ```
140
-
141
- </details>
142
-
143
- ### Step 3: Start talking
144
-
145
- That's it. Your AI now has memory tools. Ask it to remember something:
146
-
147
- > *"Remember that we use Tailwind with a custom theme in this project."*
148
-
149
- Next conversation, ask:
150
-
151
- > *"What CSS framework do we use?"*
152
-
153
- It knows.
121
+ Restart your AI tool. You'll see **15 tools**, **6 resources**, and **2 prompts** available.
154
122
 
155
123
  ---
156
124
 
157
- ## How It Works
158
-
159
- ```
160
- ┌──────────────────────────────────┐
161
- │ Your AI Tool │
162
- │ Claude · Cursor · Windsurf │
163
- └──────────┬───────────────────────┘
164
-
165
- MCP Protocol (stdio)
166
-
167
- ┌──────────▼───────────────────────┐
168
- │ amem-mcp-server │
169
- │ │
170
- │ 9 Tools · 4 Resources · 2 Prompts
171
- │ │
172
- │ Store → Score → Deduplicate │
173
- │ Recall → Rank → Surface │
174
- │ │
175
- │ ┌────────────────────────────┐ │
176
- │ │ SQLite + Local Embeddings │ │
177
- │ │ ~/.amem/memory.db │ │
178
- │ └────────────────────────────┘ │
179
- └──────────────────────────────────┘
180
- ```
125
+ ## Memory Types
181
126
 
182
- **Everything stays on your machine.** No cloud. No API keys. No data leaving your laptop.
183
-
184
- ### Smart ranking
185
-
186
- Every memory gets a composite score:
187
-
188
- ```
189
- score = relevance × recency × confidence × importance
190
- ```
191
-
192
- - **Relevance** — How closely the memory matches what you're working on (cosine similarity via local embeddings, with keyword fallback)
193
- - **Recency** — Exponential decay (0.995^hours) — recent memories score higher, old ones gradually fade
194
- - **Confidence** — Memories confirmed multiple times score higher (0.0 to 1.0)
195
- - **Importance** — Type-based weight: Corrections (1.0) > Decisions (0.85) > Patterns (0.7) > Facts (0.4)
196
-
197
- ### Conflict detection
198
-
199
- Store a memory that contradicts an existing one? amem catches it:
200
-
201
- - **>85% similar but different** — Flags the conflict, updates the existing memory's confidence
202
- - **>80% similar and agreeing** — Reinforces the existing memory (+0.1 confidence)
203
- - **60-80% related** — Touches related memories to keep them fresh
204
- - **No match** — Stores as new
205
-
206
- ### Memory evolution
127
+ | Priority | Type | What it captures | Example |
128
+ |---|---|---|---|
129
+ | 1.0 | **correction** | Rules that must never be broken | *"Don't mock the DB in integration tests"* |
130
+ | 0.85 | **decision** | Architectural choices + rationale | *"Chose Postgres over Mongo for ACID compliance"* |
131
+ | 0.7 | **pattern** | Coding style and habits | *"Prefers early returns over nested conditionals"* |
132
+ | 0.7 | **preference** | Tool and workflow choices | *"Uses pnpm, not npm"* |
133
+ | 0.5 | **topology** | Where things are in the codebase | *"Auth module lives in src/auth/, uses JWT"* |
134
+ | 0.4 | **fact** | General project knowledge | *"API uses REST, launched January 2025"* |
207
135
 
208
- When you store a new memory, related existing memories (60-80% similarity) get reinforced automatically — their access timestamps update, keeping your knowledge base connected and current.
136
+ Corrections always surface first. They are your AI's hard constraints.
209
137
 
210
- ### Memory consolidation
138
+ ---
211
139
 
212
- Over time, memories accumulate — duplicates, stale facts, forgotten preferences. amem is the first MCP memory server with built-in consolidation:
140
+ ## Tools Reference
213
141
 
214
- - **Merge** — Near-duplicate memories (>85% similarity) are combined. The higher-confidence version is kept and boosted.
215
- - **Prune** — Stale memories (>60 days inactive, low confidence, rarely accessed) are removed. Corrections are **never** pruned.
216
- - **Promote** — Memories accessed 5+ times with low confidence get promoted to 90% confidence.
217
- - **Health score** — After consolidation, you get a 0-100 health score (signal-to-noise ratio).
142
+ ### Core Memory
218
143
 
219
- Use `memory_consolidate` with `confirm: false` to preview, then `confirm: true` to execute.
144
+ | Tool | What it does |
145
+ |---|---|
146
+ | `memory_store` | Store a single memory with type, tags, confidence |
147
+ | `memory_recall` | Semantic search — natural language, ranked by relevance |
148
+ | `memory_context` | Load all relevant context for a topic, organized by type |
149
+ | `memory_extract` | Batch-save multiple memories from a conversation |
150
+ | `memory_forget` | Delete memories by ID or query (confirmation required) |
151
+ | `memory_inject` | Proactively surface corrections + decisions before coding |
220
152
 
221
- ### Project scoping
153
+ ### Precision & History
222
154
 
223
- Memories know where they apply:
155
+ | Tool | What it does |
156
+ |---|---|
157
+ | `memory_patch` | Surgical field-level edit — auto-snapshots before every change |
158
+ | `memory_versions` | View full edit history or restore any past version |
159
+ | `memory_search` | Exact full-text search (FTS5) — complements semantic recall |
160
+ | `memory_since` | Temporal query — "what changed in the last 7 days?" |
161
+ | `memory_relate` | Build knowledge graph — link memories with typed relations |
224
162
 
225
- - **Global** Corrections, preferences, and patterns follow you everywhere (e.g., "Don't use `any` in TypeScript")
226
- - **Project-scoped** — Decisions, topology, and facts stay with their project (e.g., "Auth module is in src/auth/")
163
+ ### Log & Maintenance
227
164
 
228
- Project is auto-detected from `AMEM_PROJECT` env var or your git repo name. When recalling, amem returns global memories + current project memories — never leaking another project's context.
165
+ | Tool | What it does |
166
+ |---|---|
167
+ | `memory_log` | Append raw conversation turns — lossless, append-only |
168
+ | `memory_log_recall` | Search or replay log — by session, keyword, or recency |
169
+ | `memory_stats` | Memory count, type breakdown, confidence, embedding coverage |
170
+ | `memory_export` | Export all memories as markdown |
171
+ | `memory_consolidate` | Merge duplicates · prune stale · promote frequently-used |
229
172
 
230
173
  ---
231
174
 
232
- ## Tools
233
-
234
- amem gives your AI **9 tools** it can use during conversation. All tools include:
235
-
236
- - **Strict input validation** with Zod schemas (invalid inputs are rejected with clear error messages)
237
- - **Tool annotations** (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) so clients understand tool behavior
238
- - **Structured error handling** — errors return `isError: true` with actionable suggestions
239
-
240
- ### Core tools
175
+ ## Usage Examples
241
176
 
242
- | Tool | What it does | Annotations |
243
- |------|-------------|-------------|
244
- | `memory_store` | Save a single memory with type, tags, and confidence | write, non-destructive |
245
- | `memory_recall` | Search memories by meaning (semantic + keyword fallback) | read-only, idempotent |
246
- | `memory_context` | Load all relevant context for a topic, organized by type | read-only, idempotent |
247
- | `memory_extract` | Batch-save multiple memories from a conversation | write, non-destructive |
248
- | `memory_forget` | Delete outdated or incorrect memories (with confirmation) | write, destructive |
249
- | `memory_inject` | Proactively inject corrections + decisions for a topic (use before coding) | read-only, idempotent |
250
-
251
- ### Maintenance tools
252
-
253
- | Tool | What it does | Annotations |
254
- |------|-------------|-------------|
255
- | `memory_stats` | Memory count, type breakdown, confidence distribution, embedding coverage | read-only, idempotent |
256
- | `memory_export` | Export all memories as markdown (truncates at 50K chars) | read-only, idempotent |
257
- | `memory_consolidate` | Merge duplicates, prune stale memories, promote frequent ones (preview or execute) | write, destructive |
258
-
259
- All tools return both human-readable text (`content`) and machine-readable JSON (`structuredContent`) with validated `outputSchema`.
260
-
261
- ### Example: Storing a memory
177
+ ### Store and recall
262
178
 
263
179
  ```
264
180
  memory_store({
@@ -267,371 +183,177 @@ memory_store({
267
183
  tags: ["typescript", "types"],
268
184
  confidence: 1.0
269
185
  })
270
- ```
271
186
 
272
- > Stored correction memory (a1b2c3d4). Confidence: 1. Tags: [typescript, types]. Total memories: 42.
187
+ memory_recall({ query: "TypeScript best practices", limit: 5 })
188
+ ```
273
189
 
274
- ### Example: Recalling memories
190
+ ### Patch a memory (surgical, versioned)
275
191
 
276
192
  ```
277
- memory_recall({ query: "TypeScript best practices", limit: 5 })
193
+ memory_patch({
194
+ id: "a1b2c3d4",
195
+ field: "content",
196
+ value: "Never use 'any' — define interfaces, use 'unknown' for unknown types",
197
+ reason: "added unknown guidance"
198
+ })
278
199
  ```
279
200
 
280
- ```
281
- Found 2 memories for "TypeScript best practices":
201
+ Every patch auto-snapshots the previous state. Use `memory_versions` to restore.
282
202
 
283
- 1. [correction] Never use 'any' type — always define proper interfaces
284
- Score: 0.892 | Confidence: 100% | Age: 2d ago | Tags: [typescript, types]
203
+ ### Lossless conversation log
285
204
 
286
- 2. [pattern] User prefers strict TypeScript with no implicit any
287
- Score: 0.756 | Confidence: 85% | Age: 5d ago | Tags: [typescript]
288
205
  ```
206
+ # Preserve raw turns verbatim
207
+ memory_log({ session_id: "2025-03-25", role: "user", content: "Let's use OAuth2 with PKCE" })
208
+ memory_log({ session_id: "2025-03-25", role: "assistant", content: "Good call — removes token storage risk…" })
289
209
 
290
- ### Example: Loading context for a task
210
+ # Replay a session
211
+ memory_log_recall({ session_id: "2025-03-25" })
291
212
 
213
+ # Search across all sessions
214
+ memory_log_recall({ query: "OAuth PKCE", limit: 10 })
292
215
  ```
293
- memory_context({ topic: "authentication system", max_tokens: 2000 })
294
- ```
295
-
296
- ```markdown
297
- ## Context for: authentication system
298
216
 
299
- ### Corrections
300
- - Never store JWT secrets in environment variables (100% confidence)
217
+ ### Build a knowledge graph
301
218
 
302
- ### Decisions
303
- - Chose OAuth2 + PKCE for the auth flow (90% confidence)
219
+ ```
220
+ memory_relate({
221
+ action: "relate",
222
+ from_id: "decision-abc",
223
+ to_id: "pattern-xyz",
224
+ relation_type: "supports",
225
+ strength: 0.9
226
+ })
304
227
 
305
- ### Topology
306
- - Auth module is in src/auth/, middleware in src/middleware/auth.ts (85% confidence)
228
+ memory_relate({ action: "graph", memory_id: "decision-abc" })
307
229
  ```
308
230
 
309
- ### Example: Batch extraction
231
+ Relation types: `supports`, `contradicts`, `depends_on`, `supersedes`, `related_to`, `caused_by`, `implements` — or define your own.
310
232
 
311
- Your AI can extract multiple memories from a single conversation:
233
+ ### Query by time
312
234
 
313
235
  ```
314
- memory_extract({
315
- memories: [
316
- { content: "Don't mock the DB in integration tests", type: "correction", tags: ["testing"], confidence: 1.0 },
317
- { content: "Chose event sourcing for audit trail", type: "decision", tags: ["architecture"], confidence: 0.9 }
318
- ]
319
- })
236
+ memory_since({ since: "7d" }) # last 7 days
237
+ memory_since({ since: "1w", type: "decision" }) # decisions this week
238
+ memory_since({ since: "2025-03-01", until: "2025-03-15" }) # date range
320
239
  ```
321
240
 
322
- ```
323
- Extraction complete: 2 stored, 0 reinforced.
324
- Total memories: 44.
241
+ ### Exact full-text search
325
242
 
326
- + Stored [correction]: "Don't mock the DB in integration tests" (a1b2c3d4)
327
- + Stored [decision]: "Chose event sourcing for audit trail" (e5f6g7h8)
243
+ ```
244
+ memory_search({ query: "OAuth PKCE" }) # exact terms
245
+ memory_search({ query: '"event sourcing"' }) # phrase match
246
+ memory_search({ query: "auth* NOT legacy" }) # FTS5 syntax
328
247
  ```
329
248
 
330
- ### Example: Forgetting memories
249
+ ---
331
250
 
332
- Delete by ID or by query (with a safety confirmation step):
251
+ ## How It Works
333
252
 
334
253
  ```
335
- memory_forget({ query: "old project", confirm: false })
336
- ```
254
+ ┌──────────────────────────────────────────┐
255
+ │ Your AI Tool │
256
+ │ Claude · Cursor · Windsurf · any │
257
+ └──────────────┬───────────────────────────┘
258
+ │ MCP Protocol (stdio)
259
+ ┌──────────────▼───────────────────────────┐
260
+ │ amem-mcp-server │
261
+ │ │
262
+ │ 15 Tools · 6 Resources · 2 Prompts │
263
+ │ │
264
+ │ ┌──────────────────────────────────┐ │
265
+ │ │ SQLite + FTS5 + Local Embeddings│ │
266
+ │ │ ~/.amem/memory.db │ │
267
+ │ │ │ │
268
+ │ │ memories (scored) │ │
269
+ │ │ conversation_log (lossless) │ │
270
+ │ │ memory_versions (history) │ │
271
+ │ │ memory_relations (graph) │ │
272
+ │ │ memories_fts (FTS5 index) │ │
273
+ │ └──────────────────────────────────┘ │
274
+ └──────────────────────────────────────────┘
275
+ ```
276
+
277
+ Everything stays on your machine. No cloud. No API keys.
337
278
 
338
- ```
339
- Found 3 memories matching "old project". Preview:
340
- 1. [a1b2c3d4] Old project used Express.js
341
- 2. [e5f6g7h8] Old project had no tests
279
+ ### Smart ranking
342
280
 
343
- Call again with confirm=true to delete these.
281
+ ```
282
+ score = relevance × recency × confidence × importance
344
283
  ```
345
284
 
346
- ---
347
-
348
- ## Resources & Prompts
285
+ - **Relevance** — cosine similarity via local embeddings, keyword fallback
286
+ - **Recency** — exponential decay (`0.995^hours`)
287
+ - **Confidence** reinforced by repeated confirmation
288
+ - **Importance** — type-based: corrections 1.0 → facts 0.4
349
289
 
350
- ### MCP Resources
290
+ ---
351
291
 
352
- amem exposes **4 resources** that AI clients can read proactively at the start of a conversation:
292
+ ## MCP Resources
353
293
 
354
294
  | Resource URI | What it provides |
355
- |-------------|-----------------|
356
- | `amem://corrections` | All active corrections — hard rules the AI should always follow |
357
- | `amem://decisions` | Past architectural decisions and their rationale |
295
+ |---|---|
296
+ | `amem://corrections` | All active corrections — hard constraints |
297
+ | `amem://decisions` | Past architectural decisions |
358
298
  | `amem://profile` | Your preferences and coding patterns |
359
- | `amem://summary` | Quick overview: memory count and breakdown by type |
360
-
361
- ### MCP Prompts
362
-
363
- amem provides **2 prompts** that teach AI clients how to use the memory system effectively:
364
-
365
- | Prompt | Purpose |
366
- |--------|---------|
367
- | `extraction-guide` | Guidelines for *what* to extract from conversations — when to save corrections vs. decisions vs. facts, how often, and what to avoid |
368
- | `session-start` | How to load relevant context at the beginning of a conversation — load topic context, apply corrections as hard constraints, reference memories naturally |
299
+ | `amem://summary` | Memory count and type breakdown |
300
+ | `amem://log/recent` | Last 50 raw conversation log entries |
301
+ | `amem://graph` | Knowledge graph — all explicit relations |
369
302
 
370
303
  ---
371
304
 
372
305
  ## CLI
373
306
 
374
- amem includes a standalone command-line interface for managing memories directly:
375
-
376
307
  ```bash
377
- amem-cli recall "authentication" # Search memories semantically
378
- amem-cli stats # Show statistics with visual bars
379
- amem-cli list # List all memories
380
- amem-cli list --type correction # Filter by type
381
- amem-cli export # Export to stdout as markdown
382
- amem-cli export --file memories.md # Export to file
383
- amem-cli forget abc12345 # Delete by ID (short IDs supported)
308
+ amem-cli recall "authentication" # Semantic search
309
+ amem-cli stats # Statistics
310
+ amem-cli list # List all memories
311
+ amem-cli list --type correction # Filter by type
312
+ amem-cli export --file memories.md # Export to file
313
+ amem-cli forget abc12345 # Delete by short ID
384
314
  ```
385
315
 
386
316
  ---
387
317
 
388
318
  ## Configuration
389
319
 
390
- amem works out of the box with zero configuration. For advanced use:
391
-
392
- | Environment Variable | Default | Description |
393
- |---------------------|---------|-------------|
394
- | `AMEM_DIR` | `~/.amem` | Where amem stores data |
395
- | `AMEM_DB` | `~/.amem/memory.db` | Database file path |
396
- | `AMEM_PROJECT` | *(auto-detected from git)* | Project name for scoping (e.g., `my-app`) |
397
-
398
- Project scoping is automatic — amem detects your git repo name. Override with `AMEM_PROJECT`:
399
-
400
- ```json
401
- {
402
- "mcpServers": {
403
- "amem": {
404
- "command": "amem",
405
- "env": { "AMEM_PROJECT": "my-project" }
406
- }
407
- }
408
- }
409
- ```
320
+ | Variable | Default | Description |
321
+ |---|---|---|
322
+ | `AMEM_DIR` | `~/.amem` | Storage directory |
323
+ | `AMEM_DB` | `~/.amem/memory.db` | Database path |
324
+ | `AMEM_PROJECT` | *(auto from git)* | Project scope |
410
325
 
411
326
  ---
412
327
 
413
- ## Technical Details
414
-
415
- ### Stack
328
+ ## Technical Stack
416
329
 
417
330
  | Layer | Technology |
418
- |-------|------------|
419
- | Protocol | [MCP](https://modelcontextprotocol.io/) SDK ^1.25 (modern `registerTool`/`registerResource`/`registerPrompt` APIs) |
420
- | Language | TypeScript 5.6+ (strict mode, ES2022, zero `any` types) |
421
- | Database | SQLite via better-sqlite3 (WAL mode, prepared statements, indexed) |
422
- | Embeddings | HuggingFace Transformers — Xenova/all-MiniLM-L6-v2 (384-dim, local, optional) |
423
- | Validation | Zod 3.25+ (`.strict()` on all schemas, `.min()` constraints, descriptive errors) |
424
- | Testing | Vitest — 33 tests across 4 suites |
331
+ |---|---|
332
+ | Protocol | MCP SDK ^1.25 |
333
+ | Language | TypeScript 5.6+ strict, zero `any` |
334
+ | Database | SQLite + WAL + FTS5 |
335
+ | Embeddings | HuggingFace Xenova/all-MiniLM-L6-v2 (local, 80MB) |
336
+ | Validation | Zod 3.25+ `.strict()` schemas |
337
+ | Testing | Vitest — 92 tests, 7 suites |
425
338
  | CI/CD | GitHub Actions — Node 18/20/22 |
426
339
 
427
- ### MCP Best Practices
428
-
429
- amem follows the [MCP best practices](https://modelcontextprotocol.io/) checklist:
430
-
431
- - All 9 tools use `server.registerTool()` with `title`, `description`, `inputSchema`, `outputSchema`, and `annotations`
432
- - All tool handlers wrapped in `try-catch` with `isError: true` on failures
433
- - All Zod schemas use `.strict()` to reject unknown fields
434
- - All error messages are actionable (suggest next steps)
435
- - Server name follows convention: `amem-mcp-server`
436
- - Transport: stdio (correct for local-first tool)
437
- - Logging to stderr (not stdout)
438
- - Graceful shutdown on SIGINT/SIGTERM
439
-
440
- ### Architecture
441
-
442
- ```
443
- src/
444
- ├── index.ts Entry point — server, prompts, resources, transport
445
- ├── tools.ts 10 MCP tools with annotations, validation, structured output
446
- ├── schemas.ts Zod output schemas for structuredContent responses
447
- ├── memory.ts Scoring engine, conflict detection, recall algorithm
448
- ├── database.ts SQLite schema, prepared statements, CRUD interface
449
- ├── embeddings.ts Local embedding pipeline + cosine similarity
450
- └── cli.ts Standalone CLI for direct memory management
451
- ```
452
-
453
- **~1,300 lines of TypeScript.** Clean separation of concerns, no circular dependencies.
454
-
455
- ---
456
-
457
- ## FAQ
458
-
459
- <details>
460
- <summary><strong>Is my data sent to the cloud?</strong></summary>
461
-
462
- No. Everything stays on your machine. amem uses a local SQLite database at `~/.amem/memory.db` and generates embeddings locally using an 80MB model that runs on your CPU. No internet connection required after the first model download.
463
-
464
- </details>
465
-
466
- <details>
467
- <summary><strong>Does it work offline?</strong></summary>
468
-
469
- Yes. After the first run (which downloads the embedding model), amem works completely offline. If the model isn't available, amem falls back to keyword matching — it never crashes.
470
-
471
- </details>
472
-
473
- <details>
474
- <summary><strong>What AI tools does it work with?</strong></summary>
475
-
476
- Any tool that supports the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) — including Claude Code, Cursor, Windsurf, and many others. The list is growing rapidly.
477
-
478
- </details>
479
-
480
- <details>
481
- <summary><strong>How much memory/disk does it use?</strong></summary>
482
-
483
- The embedding model is ~80MB (downloaded once, cached locally). The SQLite database grows with your memories — typically a few MB even after months of use. CPU usage is minimal; the server idles at near-zero when not processing requests.
484
-
485
- </details>
486
-
487
- <details>
488
- <summary><strong>Can I see what's stored?</strong></summary>
489
-
490
- Yes! Use `amem-cli list` to see all memories, `amem-cli stats` for a visual overview, or `amem-cli export --file backup.md` to export everything as readable markdown. You can also ask your AI to call `memory_stats` or `memory_export`.
491
-
492
- </details>
493
-
494
- <details>
495
- <summary><strong>Can I delete specific memories?</strong></summary>
496
-
497
- Yes. Use `amem-cli forget <id>` (short IDs work — just the first 8 characters) or ask your AI to call `memory_forget`. Query-based deletion requires a confirmation step to prevent accidents: `memory_forget({ query: "old project", confirm: true })`.
498
-
499
- </details>
500
-
501
- <details>
502
- <summary><strong>Does it slow down my AI?</strong></summary>
503
-
504
- No. Memory operations typically take under 50ms. Embedding generation for new memories takes ~200ms. The server runs as a lightweight background process over stdio.
505
-
506
- </details>
507
-
508
- <details>
509
- <summary><strong>Can I use it across multiple projects?</strong></summary>
510
-
511
- Yes. By default, amem stores memories globally at `~/.amem/memory.db` — all your AI conversations across all projects share the same memory. Set `AMEM_DB` per-project for isolated memories.
512
-
513
- </details>
514
-
515
- <details>
516
- <summary><strong>What happens if the embedding model isn't available?</strong></summary>
517
-
518
- amem gracefully falls back to keyword-based matching. Semantic search won't work, but storing, recalling (by keyword), and all other operations continue normally. The server never crashes due to missing embeddings.
519
-
520
- </details>
521
-
522
- <details>
523
- <summary><strong>How does conflict detection work?</strong></summary>
524
-
525
- When you store a new memory, amem computes cosine similarity against all existing memories. If a match exceeds 85% similarity but the content is different, it flags a conflict and updates the existing memory's confidence instead of creating a duplicate. You get a clear message explaining what happened and how to rephrase if the memories are genuinely different.
526
-
527
- </details>
528
-
529
340
  ---
530
341
 
531
342
  ## Contributing
532
343
 
533
- Contributions are welcome! Here's how to get involved.
534
-
535
- ### Development setup
536
-
537
344
  ```bash
538
345
  git clone https://github.com/amanasmuei/amem.git
539
- cd amem
540
- npm install
541
- npm run build
542
- npm test
543
- ```
544
-
545
- ### Scripts
546
-
547
- | Script | What it does |
548
- |--------|-------------|
549
- | `npm run build` | Compile TypeScript to `dist/` |
550
- | `npm run dev` | Watch mode — recompile on save |
551
- | `npm test` | Run all 33 tests with Vitest |
552
- | `npm run test:watch` | Run tests in watch mode |
553
- | `npm start` | Start the MCP server (`node dist/index.js`) |
554
-
555
- ### Project structure
556
-
557
- ```
558
- amem/
559
- ├── src/
560
- │ ├── index.ts # MCP server entry point, prompts, resources
561
- │ ├── tools.ts # 7 tool definitions with validation & error handling
562
- │ ├── memory.ts # Scoring engine, conflict detection, recall
563
- │ ├── database.ts # SQLite schema, prepared statements, CRUD
564
- │ ├── embeddings.ts # Local embedding pipeline + cosine similarity
565
- │ └── cli.ts # Standalone CLI
566
- ├── tests/
567
- │ ├── database.test.ts
568
- │ ├── embeddings.test.ts
569
- │ ├── memory.test.ts
570
- │ └── tools.test.ts
571
- ├── .github/
572
- │ └── workflows/
573
- │ ├── ci.yml # Test on push/PR (Node 18/20/22)
574
- │ └── publish.yml # Publish to npm on GitHub Release
575
- ├── package.json
576
- ├── tsconfig.json
577
- └── vitest.config.ts
346
+ cd amem && npm install
347
+ npm run build # zero TS errors
348
+ npm test # 92 tests pass
578
349
  ```
579
350
 
580
- ### Making changes
581
-
582
- 1. Fork the repository
583
- 2. Create a feature branch: `git checkout -b feature/your-feature`
584
- 3. Make your changes
585
- 4. Ensure the build is clean: `npm run build`
586
- 5. Ensure all tests pass: `npm test`
587
- 6. Commit and push your branch
588
- 7. Open a Pull Request against `main`
589
-
590
- ### CI/CD
591
-
592
- **GitHub Actions** runs automatically on every push and pull request:
593
-
594
- - **CI workflow** (`ci.yml`) — builds and tests against Node.js 18, 20, and 22 on Ubuntu
595
- - **Publish workflow** (`publish.yml`) — triggered on GitHub Release, builds, tests, and publishes to npm with `--access public`
596
-
597
- All PRs must pass the CI pipeline before merging.
598
-
599
- ### Reporting issues
600
-
601
- Found a bug or have a feature idea?
602
-
603
- - **Bug reports**: [Open an issue](https://github.com/amanasmuei/amem/issues/new) with steps to reproduce, expected vs. actual behavior, and your Node.js version
604
- - **Feature requests**: [Open an issue](https://github.com/amanasmuei/amem/issues/new) describing the use case and how it would improve the memory system
605
- - **Questions**: [Start a discussion](https://github.com/amanasmuei/amem/discussions) (or open an issue)
351
+ PRs must pass CI before merge.
606
352
 
607
353
  ---
608
354
 
609
- ## Roadmap
610
-
611
- - [x] 8 MCP tools with full annotations, validation, and error handling
612
- - [x] Semantic search with local embeddings (graceful fallback to keywords)
613
- - [x] Smart conflict detection and deduplication
614
- - [x] Memory evolution (related memories reinforce each other)
615
- - [x] CLI for direct memory management
616
- - [x] MCP prompts and resources for proactive context
617
- - [x] Published on npm
618
- - [x] `outputSchema` + `structuredContent` for machine-readable tool responses
619
- - [x] Proactive context injection (`memory_inject` tool)
620
- - [x] Evaluation suite (10 standardized eval questions)
621
- - [x] Memory consolidation — merge, prune, promote (the first MCP memory server with this)
622
- - [x] Project scoping — auto-detect project, scope memories global vs project
623
- - [ ] Memory verification against filesystem
624
- - [ ] Knowledge graph with entity relationships
625
- - [ ] Team memory (shared context across developers)
626
-
627
- ---
628
-
629
- <div align="center">
630
-
631
355
  **Built by [Aman Asmuei](https://github.com/amanasmuei)**
632
356
 
633
- [GitHub](https://github.com/amanasmuei/amem) · [npm](https://www.npmjs.com/package/@aman_asmuei/amem) · [Report Bug](https://github.com/amanasmuei/amem/issues) · [Request Feature](https://github.com/amanasmuei/amem/issues)
357
+ [GitHub](https://github.com/amanasmuei/amem) · [npm](https://www.npmjs.com/package/@aman_asmuei/amem) · [Issues](https://github.com/amanasmuei/amem/issues)
634
358
 
635
359
  MIT License
636
-
637
- </div>