@aman_asmuei/amem 0.3.0 → 0.4.1

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,637 +1,426 @@
1
- <div align="center">
2
-
3
- # amem
4
-
5
- ### Give your AI a memory it never forgets
6
-
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>
1
+ <p align="center">
2
+ <img src="assets/logo.png" alt="amem" width="160" />
3
+ </p>
4
+
5
+ <h1 align="center">amem</h1>
6
+
7
+ <p align="center">
8
+ <strong>Give your AI a memory it never forgets.</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@aman_asmuei/amem"><img src="https://img.shields.io/npm/v/@aman_asmuei/amem?style=for-the-badge&logo=npm&logoColor=white&color=cb3837" alt="npm version" /></a>
13
+ &nbsp;
14
+ <a href="https://github.com/amanasmuei/amem/actions"><img src="https://img.shields.io/github/actions/workflow/status/amanasmuei/amem/ci.yml?style=for-the-badge&logo=github&label=CI" alt="CI status" /></a>
15
+ &nbsp;
16
+ <a href="https://github.com/amanasmuei/amem/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=for-the-badge" alt="MIT License" /></a>
17
+ &nbsp;
18
+ <img src="https://img.shields.io/badge/MCP-compatible-8A2BE2?style=for-the-badge" alt="MCP compatible" />
19
+ &nbsp;
20
+ <img src="https://img.shields.io/badge/node-%E2%89%A518-brightgreen?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js 18+" />
21
+ </p>
22
+
23
+ <p align="center">
24
+ <b>amem</b> (<b>A</b>man's <b>Mem</b>ory) is a persistent memory layer for AI coding tools.<br/>
25
+ Local-first &middot; Semantic &middot; Lossless &middot; Works with Claude Code, Cursor, Windsurf &amp; any MCP client.
26
+ </p>
27
+
28
+ <p align="center">
29
+ <a href="#-quick-start">Quick Start</a> &bull;
30
+ <a href="#-features">Features</a> &bull;
31
+ <a href="#-tools-reference">Tools</a> &bull;
32
+ <a href="#-usage-examples">Examples</a> &bull;
33
+ <a href="#-architecture">Architecture</a> &bull;
34
+ <a href="#-contributing">Contributing</a>
35
+ </p>
19
36
 
20
37
  ---
21
38
 
22
39
  ## The Problem
23
40
 
24
- Every time you start a new conversation with an AI coding assistant, it starts from zero. It doesn't know:
41
+ Every time you start a new conversation with an AI coding assistant, it starts from zero.
25
42
 
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
43
+ > *"Don't use `any` in TypeScript"* — told it **three times**, still does it.
44
+ >
45
+ > *"We chose PostgreSQL over MongoDB"* doesn't remember why.
46
+ >
47
+ > *"I prefer early returns and pnpm"* — explained again. And again.
48
+ >
49
+ > A critical decision from **last week**? Gone.
30
50
 
31
- You end up repeating yourself. Every. Single. Time.
51
+ **You repeat yourself. Every. Single. Session.**
32
52
 
33
53
  ## The Solution
34
54
 
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.
55
+ **amem** plugs into any MCP-compatible AI tool and gives it persistent, searchable, lossless memory.
36
56
 
37
57
  ```
38
58
  You: "Don't use any type in TypeScript"
39
59
 
40
- amem saves this as a correction (highest priority).
41
- Next conversation — or next month your AI already knows.
60
+ amem stores this as a correction (priority 1.0)
61
+ next session, your AI already knows
42
62
  ```
43
63
 
44
- ---
45
-
46
- ## What Gets Remembered
47
-
48
- amem organizes memories into six types, ranked by importance:
49
-
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
-
59
- Corrections always surface first. They're the "never do this" rules your AI should always follow.
64
+ No cloud. No API keys. Everything stays on your machine.
60
65
 
61
66
  ---
62
67
 
63
- ## Get Started
64
-
65
- ### Step 1: Install
68
+ ## Quick Start
66
69
 
67
- You need [Node.js](https://nodejs.org) 18 or higher. Then:
70
+ ### 1. Install
68
71
 
69
72
  ```bash
70
73
  npm install -g @aman_asmuei/amem
71
74
  ```
72
75
 
73
- That's it. amem is now installed on your machine.
76
+ ### 2. Connect
74
77
 
75
- ### Step 2: Connect your AI tool
78
+ <details open>
79
+ <summary><strong>Claude Code</strong> (one command)</summary>
76
80
 
77
- <details>
78
- <summary><strong>Claude Code</strong></summary>
79
-
80
- Add to `~/.claude/settings.json`:
81
-
82
- ```json
83
- {
84
- "mcpServers": {
85
- "amem": {
86
- "command": "amem"
87
- }
88
- }
89
- }
81
+ ```bash
82
+ claude mcp add amem -- npx -y @aman_asmuei/amem
90
83
  ```
91
84
 
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:
85
+ Or add to `~/.claude/settings.json`:
100
86
 
101
87
  ```json
102
88
  {
103
89
  "mcpServers": {
104
90
  "amem": {
105
- "command": "amem"
91
+ "command": "npx",
92
+ "args": ["-y", "@aman_asmuei/amem"]
106
93
  }
107
94
  }
108
95
  }
109
96
  ```
110
97
 
111
- Restart Cursor.
112
-
113
98
  </details>
114
99
 
115
100
  <details>
116
- <summary><strong>Windsurf</strong></summary>
117
-
118
- Add to your MCP configuration:
101
+ <summary><strong>Cursor / Windsurf / Other MCP Clients</strong></summary>
119
102
 
120
103
  ```json
121
104
  {
122
105
  "mcpServers": {
123
- "amem": {
124
- "command": "amem"
125
- }
106
+ "amem": { "command": "amem" }
126
107
  }
127
108
  }
128
109
  ```
129
110
 
130
111
  </details>
131
112
 
132
- <details>
133
- <summary><strong>Any other MCP client</strong></summary>
113
+ ### 3. Use
134
114
 
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.
115
+ Restart your AI tool you'll see **15 tools**, **6 resources**, and **2 prompts** ready to go.
154
116
 
155
117
  ---
156
118
 
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
- ```
181
-
182
- **Everything stays on your machine.** No cloud. No API keys. No data leaving your laptop.
183
-
184
- ### Smart ranking
119
+ ## Features
185
120
 
186
- Every memory gets a composite score:
187
-
188
- ```
189
- score = relevance × recency × confidence × importance
190
- ```
121
+ ### v0.4.0
191
122
 
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)
123
+ | | Feature | Description |
124
+ |---|---|---|
125
+ | **NEW** | Lossless conversation log | `memory_log` / `memory_log_recall` append-only raw turns, nothing summarized or lost |
126
+ | **NEW** | Patch system | `memory_patch` surgical field-level edits with auto-versioning |
127
+ | **NEW** | Version history | `memory_versions` — immutable snapshots, restore any past state |
128
+ | **NEW** | Knowledge graph | `memory_relate` — typed bidirectional relations between memories |
129
+ | **NEW** | Temporal queries | `memory_since` — natural language time ranges (`7d`, `2w`, `1h`) |
130
+ | **NEW** | Full-text search | `memory_search` — FTS5 exact match, auto-synced on every write |
196
131
 
197
- ### Conflict detection
132
+ <details>
133
+ <summary><strong>View all features across versions</strong></summary>
198
134
 
199
- Store a memory that contradicts an existing one? amem catches it:
135
+ ### v0.3.0
200
136
 
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
137
+ - Memory consolidation engine (merge, prune, promote)
138
+ - Project detection and scope-aware filtering
139
+ - Auto-migration for scope fields
205
140
 
206
- ### Memory evolution
141
+ ### v0.2.0
207
142
 
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.
143
+ - Structured output with Zod schemas
144
+ - `memory_inject` for proactive context surfacing
145
+ - Evaluation suite
209
146
 
210
- ### Memory consolidation
147
+ ### v0.1.0
211
148
 
212
- Over time, memories accumulate — duplicates, stale facts, forgotten preferences. amem is the first MCP memory server with built-in consolidation:
149
+ - Core memory store/recall with semantic search
150
+ - Local embeddings (HuggingFace all-MiniLM-L6-v2)
151
+ - SQLite persistence with WAL mode
152
+ - MCP resources and prompts
213
153
 
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).
154
+ </details>
218
155
 
219
- Use `memory_consolidate` with `confirm: false` to preview, then `confirm: true` to execute.
156
+ ---
220
157
 
221
- ### Project scoping
158
+ ## Memory Types
222
159
 
223
- Memories know where they apply:
160
+ Memories are scored and prioritized automatically:
224
161
 
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/")
162
+ | Priority | Type | Example |
163
+ |:---:|---|---|
164
+ | `1.0` | **correction** | *"Don't mock the DB in integration tests"* |
165
+ | `0.85` | **decision** | *"Chose Postgres over Mongo for ACID compliance"* |
166
+ | `0.7` | **pattern** | *"Prefers early returns over nested conditionals"* |
167
+ | `0.7` | **preference** | *"Uses pnpm, not npm"* |
168
+ | `0.5` | **topology** | *"Auth module lives in src/auth/, uses JWT"* |
169
+ | `0.4` | **fact** | *"API uses REST, launched January 2025"* |
227
170
 
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.
171
+ > **Corrections always surface first.** They are your AI's hard constraints.
229
172
 
230
173
  ---
231
174
 
232
- ## Tools
175
+ ## Tools Reference
233
176
 
234
- amem gives your AI **9 tools** it can use during conversation. All tools include:
177
+ ### Core Memory
235
178
 
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
179
+ | Tool | Description |
180
+ |---|---|
181
+ | `memory_store` | Store a memory with type, tags, and confidence |
182
+ | `memory_recall` | Semantic search — natural language, ranked by relevance |
183
+ | `memory_context` | Load all relevant context for a topic, organized by type |
184
+ | `memory_extract` | Batch-save multiple memories from a conversation |
185
+ | `memory_forget` | Delete memories by ID or query (confirmation required) |
186
+ | `memory_inject` | Proactively surface corrections + decisions before coding |
239
187
 
240
- ### Core tools
188
+ ### Precision & History
241
189
 
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 |
190
+ | Tool | Description |
191
+ |---|---|
192
+ | `memory_patch` | Surgical field-level edit with auto-snapshot |
193
+ | `memory_versions` | View full edit history or restore any version |
194
+ | `memory_search` | Exact full-text search via FTS5 |
195
+ | `memory_since` | Temporal query with natural language ranges |
196
+ | `memory_relate` | Build a knowledge graph between memories |
250
197
 
251
- ### Maintenance tools
198
+ ### Log & Maintenance
252
199
 
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 |
200
+ | Tool | Description |
201
+ |---|---|
202
+ | `memory_log` | Append raw conversation turns (lossless, append-only) |
203
+ | `memory_log_recall` | Search or replay log by session, keyword, or recency |
204
+ | `memory_stats` | Memory count, type breakdown, confidence stats |
205
+ | `memory_export` | Export all memories as Markdown |
206
+ | `memory_consolidate` | Merge duplicates, prune stale, promote frequent memories |
258
207
 
259
- All tools return both human-readable text (`content`) and machine-readable JSON (`structuredContent`) with validated `outputSchema`.
208
+ ---
260
209
 
261
- ### Example: Storing a memory
210
+ ## Usage Examples
262
211
 
263
- ```
212
+ <details open>
213
+ <summary><strong>Store & Recall</strong></summary>
214
+
215
+ ```js
216
+ // Store a correction — highest priority, always surfaces first
264
217
  memory_store({
265
218
  content: "Never use 'any' type — always define proper interfaces",
266
219
  type: "correction",
267
220
  tags: ["typescript", "types"],
268
221
  confidence: 1.0
269
222
  })
270
- ```
271
-
272
- > Stored correction memory (a1b2c3d4). Confidence: 1. Tags: [typescript, types]. Total memories: 42.
273
223
 
274
- ### Example: Recalling memories
275
-
276
- ```
224
+ // Semantic search
277
225
  memory_recall({ query: "TypeScript best practices", limit: 5 })
278
226
  ```
279
227
 
280
- ```
281
- Found 2 memories for "TypeScript best practices":
228
+ </details>
282
229
 
283
- 1. [correction] Never use 'any' type — always define proper interfaces
284
- Score: 0.892 | Confidence: 100% | Age: 2d ago | Tags: [typescript, types]
230
+ <details>
231
+ <summary><strong>Patch a memory (surgical, versioned)</strong></summary>
232
+
233
+ ```js
234
+ memory_patch({
235
+ id: "a1b2c3d4",
236
+ field: "content",
237
+ value: "Never use 'any' — define interfaces, use 'unknown' for unknown types",
238
+ reason: "added unknown guidance"
239
+ })
285
240
 
286
- 2. [pattern] User prefers strict TypeScript with no implicit any
287
- Score: 0.756 | Confidence: 85% | Age: 5d ago | Tags: [typescript]
241
+ // Every patch auto-snapshots. Restore any version:
242
+ memory_versions({ memory_id: "a1b2c3d4" })
288
243
  ```
289
244
 
290
- ### Example: Loading context for a task
291
-
292
- ```
293
- memory_context({ topic: "authentication system", max_tokens: 2000 })
294
- ```
245
+ </details>
295
246
 
296
- ```markdown
297
- ## Context for: authentication system
247
+ <details>
248
+ <summary><strong>Lossless conversation log</strong></summary>
298
249
 
299
- ### Corrections
300
- - Never store JWT secrets in environment variables (100% confidence)
250
+ ```js
251
+ // Preserve raw turns verbatim
252
+ memory_log({ session_id: "2025-03-25", role: "user", content: "Let's use OAuth2 with PKCE" })
253
+ memory_log({ session_id: "2025-03-25", role: "assistant", content: "Good call — removes token storage risk..." })
301
254
 
302
- ### Decisions
303
- - Chose OAuth2 + PKCE for the auth flow (90% confidence)
255
+ // Replay a session
256
+ memory_log_recall({ session_id: "2025-03-25" })
304
257
 
305
- ### Topology
306
- - Auth module is in src/auth/, middleware in src/middleware/auth.ts (85% confidence)
258
+ // Search across all sessions
259
+ memory_log_recall({ query: "OAuth PKCE", limit: 10 })
307
260
  ```
308
261
 
309
- ### Example: Batch extraction
310
-
311
- Your AI can extract multiple memories from a single conversation:
262
+ </details>
312
263
 
313
- ```
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
- ]
264
+ <details>
265
+ <summary><strong>Knowledge graph</strong></summary>
266
+
267
+ ```js
268
+ memory_relate({
269
+ action: "relate",
270
+ from_id: "decision-abc",
271
+ to_id: "pattern-xyz",
272
+ relation_type: "supports",
273
+ strength: 0.9
319
274
  })
320
- ```
321
275
 
276
+ // View connections
277
+ memory_relate({ action: "graph", memory_id: "decision-abc" })
322
278
  ```
323
- Extraction complete: 2 stored, 0 reinforced.
324
- Total memories: 44.
325
279
 
326
- + Stored [correction]: "Don't mock the DB in integration tests" (a1b2c3d4)
327
- + Stored [decision]: "Chose event sourcing for audit trail" (e5f6g7h8)
328
- ```
280
+ Relation types: `supports`, `contradicts`, `depends_on`, `supersedes`, `related_to`, `caused_by`, `implements` — or define your own.
329
281
 
330
- ### Example: Forgetting memories
282
+ </details>
331
283
 
332
- Delete by ID or by query (with a safety confirmation step):
284
+ <details>
285
+ <summary><strong>Temporal queries</strong></summary>
333
286
 
334
- ```
335
- memory_forget({ query: "old project", confirm: false })
287
+ ```js
288
+ memory_since({ since: "7d" }) // last 7 days
289
+ memory_since({ since: "1w", type: "decision" }) // decisions this week
290
+ memory_since({ since: "2025-03-01", until: "2025-03-15" }) // date range
336
291
  ```
337
292
 
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
293
+ </details>
294
+
295
+ <details>
296
+ <summary><strong>Full-text search (FTS5)</strong></summary>
342
297
 
343
- Call again with confirm=true to delete these.
298
+ ```js
299
+ memory_search({ query: "OAuth PKCE" }) // exact terms
300
+ memory_search({ query: '"event sourcing"' }) // phrase match
301
+ memory_search({ query: "auth* NOT legacy" }) // FTS5 boolean syntax
344
302
  ```
345
303
 
346
- ---
304
+ </details>
347
305
 
348
- ## Resources & Prompts
306
+ ---
349
307
 
350
- ### MCP Resources
308
+ ## Architecture
309
+
310
+ ```
311
+ ┌──────────────────────────────────────────────┐
312
+ │ Your AI Tool │
313
+ │ Claude Code · Cursor · Windsurf · any │
314
+ └─────────────────┬────────────────────────────┘
315
+ │ MCP Protocol (stdio)
316
+ ┌─────────────────▼────────────────────────────┐
317
+ │ amem MCP Server │
318
+ │ │
319
+ │ 15 Tools · 6 Resources · 2 Prompts │
320
+ │ │
321
+ │ ┌────────────────────────────────────┐ │
322
+ │ │ SQLite + WAL + FTS5 │ │
323
+ │ │ ~/.amem/memory.db │ │
324
+ │ │ │ │
325
+ │ │ memories (scored) │ │
326
+ │ │ conversation_log (lossless) │ │
327
+ │ │ memory_versions (history) │ │
328
+ │ │ memory_relations (graph) │ │
329
+ │ │ memories_fts (FTS5 index) │ │
330
+ │ └────────────────────────────────────┘ │
331
+ │ │
332
+ │ Local Embeddings (all-MiniLM-L6-v2, 80MB) │
333
+ └──────────────────────────────────────────────┘
334
+ ```
335
+
336
+ ### Ranking Formula
351
337
 
352
- amem exposes **4 resources** that AI clients can read proactively at the start of a conversation:
338
+ ```
339
+ score = relevance × recency × confidence × importance
340
+ ```
353
341
 
354
- | 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 |
358
- | `amem://profile` | Your preferences and coding patterns |
359
- | `amem://summary` | Quick overview: memory count and breakdown by type |
342
+ | Factor | How it works |
343
+ |---|---|
344
+ | **Relevance** | Cosine similarity via local embeddings, keyword fallback |
345
+ | **Recency** | Exponential decay (`0.995^hours`) |
346
+ | **Confidence** | Reinforced by repeated confirmation |
347
+ | **Importance** | Type-based: corrections `1.0` facts `0.4` |
360
348
 
361
- ### MCP Prompts
349
+ ---
362
350
 
363
- amem provides **2 prompts** that teach AI clients how to use the memory system effectively:
351
+ ## MCP Resources
364
352
 
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 |
353
+ | URI | Description |
354
+ |---|---|
355
+ | `amem://corrections` | All active corrections (hard constraints) |
356
+ | `amem://decisions` | Architectural decisions |
357
+ | `amem://profile` | Preferences and coding patterns |
358
+ | `amem://summary` | Memory count and type breakdown |
359
+ | `amem://log/recent` | Last 50 raw conversation log entries |
360
+ | `amem://graph` | Knowledge graph overview |
369
361
 
370
362
  ---
371
363
 
372
364
  ## CLI
373
365
 
374
- amem includes a standalone command-line interface for managing memories directly:
375
-
376
366
  ```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)
367
+ amem-cli recall "authentication" # Semantic search
368
+ amem-cli stats # Statistics
369
+ amem-cli list # List all memories
370
+ amem-cli list --type correction # Filter by type
371
+ amem-cli export --file memories.md # Export to file
372
+ amem-cli forget abc12345 # Delete by short ID
384
373
  ```
385
374
 
386
375
  ---
387
376
 
388
377
  ## Configuration
389
378
 
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
- ```
379
+ | Variable | Default | Description |
380
+ |---|---|---|
381
+ | `AMEM_DIR` | `~/.amem` | Storage directory |
382
+ | `AMEM_DB` | `~/.amem/memory.db` | Database path |
383
+ | `AMEM_PROJECT` | *(auto from git)* | Project scope |
410
384
 
411
385
  ---
412
386
 
413
- ## Technical Details
414
-
415
- ### Stack
387
+ ## Tech Stack
416
388
 
417
389
  | 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 |
425
- | CI/CD | GitHub Actions Node 18/20/22 |
426
-
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>
390
+ |---|---|
391
+ | Protocol | MCP SDK ^1.25 |
392
+ | Language | TypeScript 5.6+, strict mode, zero `any` |
393
+ | Database | SQLite + WAL + FTS5 |
394
+ | Embeddings | HuggingFace Xenova/all-MiniLM-L6-v2 (local, 80MB) |
395
+ | Validation | Zod 3.25+ with `.strict()` schemas |
396
+ | Testing | Vitest — 92 tests across 7 suites |
397
+ | CI/CD | GitHub Actions npm publish on release |
528
398
 
529
399
  ---
530
400
 
531
401
  ## Contributing
532
402
 
533
- Contributions are welcome! Here's how to get involved.
534
-
535
- ### Development setup
536
-
537
403
  ```bash
538
404
  git clone https://github.com/amanasmuei/amem.git
539
- cd amem
540
- npm install
541
- npm run build
542
- npm test
405
+ cd amem && npm install
406
+ npm run build # zero TS errors
407
+ npm test # 92 tests pass
543
408
  ```
544
409
 
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
578
- ```
579
-
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)
410
+ PRs must pass CI before merge. See [Issues](https://github.com/amanasmuei/amem/issues) for open tasks.
606
411
 
607
412
  ---
608
413
 
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
- **Built by [Aman Asmuei](https://github.com/amanasmuei)**
632
-
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)
414
+ <p align="center">
415
+ Built by <a href="https://github.com/amanasmuei"><strong>Aman Asmuei</strong></a>
416
+ </p>
634
417
 
635
- MIT License
418
+ <p align="center">
419
+ <a href="https://github.com/amanasmuei/amem">GitHub</a> &middot;
420
+ <a href="https://www.npmjs.com/package/@aman_asmuei/amem">npm</a> &middot;
421
+ <a href="https://github.com/amanasmuei/amem/issues">Issues</a>
422
+ </p>
636
423
 
637
- </div>
424
+ <p align="center">
425
+ <sub>MIT License</sub>
426
+ </p>