@aman_asmuei/amem 0.2.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,243 +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.
74
-
75
- ### Step 2: Connect your AI tool
88
+ Node.js 18+ required. No cloud accounts, no API keys.
76
89
 
77
- <details>
78
- <summary><strong>Claude Code</strong></summary>
90
+ ### Connect your AI tool
79
91
 
80
- Add to `~/.claude/settings.json`:
92
+ **Claude Code**
81
93
 
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 8 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
- │ 8 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.
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"* |
183
135
 
184
- ### Smart ranking
136
+ Corrections always surface first. They are your AI's hard constraints.
185
137
 
186
- Every memory gets a composite score:
138
+ ---
187
139
 
188
- ```
189
- score = relevance × recency × confidence × importance
190
- ```
140
+ ## Tools Reference
191
141
 
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)
142
+ ### Core Memory
196
143
 
197
- ### Conflict detection
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 |
198
152
 
199
- Store a memory that contradicts an existing one? amem catches it:
153
+ ### Precision & History
200
154
 
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
155
+ | Tool | What it does |
156
+ |---|---|
157
+ | `memory_patch` | Surgical field-level editauto-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 |
205
162
 
206
- ### Memory evolution
163
+ ### Log & Maintenance
207
164
 
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.
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 |
209
172
 
210
173
  ---
211
174
 
212
- ## Tools
213
-
214
- amem gives your AI **8 tools** it can use during conversation. All tools include:
215
-
216
- - **Strict input validation** with Zod schemas (invalid inputs are rejected with clear error messages)
217
- - **Tool annotations** (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) so clients understand tool behavior
218
- - **Structured error handling** — errors return `isError: true` with actionable suggestions
175
+ ## Usage Examples
219
176
 
220
- ### Core tools
221
-
222
- | Tool | What it does | Annotations |
223
- |------|-------------|-------------|
224
- | `memory_store` | Save a single memory with type, tags, and confidence | write, non-destructive |
225
- | `memory_recall` | Search memories by meaning (semantic + keyword fallback) | read-only, idempotent |
226
- | `memory_context` | Load all relevant context for a topic, organized by type | read-only, idempotent |
227
- | `memory_extract` | Batch-save multiple memories from a conversation | write, non-destructive |
228
- | `memory_forget` | Delete outdated or incorrect memories (with confirmation) | write, destructive |
229
- | `memory_inject` | Proactively inject corrections + decisions for a topic (use before coding) | read-only, idempotent |
230
-
231
- ### Utility tools
232
-
233
- | Tool | What it does | Annotations |
234
- |------|-------------|-------------|
235
- | `memory_stats` | Memory count, type breakdown, confidence distribution, embedding coverage | read-only, idempotent |
236
- | `memory_export` | Export all memories as markdown (truncates at 50K chars) | read-only, idempotent |
237
-
238
- All tools return both human-readable text (`content`) and machine-readable JSON (`structuredContent`) with validated `outputSchema`.
239
-
240
- ### Example: Storing a memory
177
+ ### Store and recall
241
178
 
242
179
  ```
243
180
  memory_store({
@@ -246,361 +183,177 @@ memory_store({
246
183
  tags: ["typescript", "types"],
247
184
  confidence: 1.0
248
185
  })
249
- ```
250
186
 
251
- > Stored correction memory (a1b2c3d4). Confidence: 1. Tags: [typescript, types]. Total memories: 42.
187
+ memory_recall({ query: "TypeScript best practices", limit: 5 })
188
+ ```
252
189
 
253
- ### Example: Recalling memories
190
+ ### Patch a memory (surgical, versioned)
254
191
 
255
192
  ```
256
- 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
+ })
257
199
  ```
258
200
 
259
- ```
260
- Found 2 memories for "TypeScript best practices":
201
+ Every patch auto-snapshots the previous state. Use `memory_versions` to restore.
261
202
 
262
- 1. [correction] Never use 'any' type — always define proper interfaces
263
- Score: 0.892 | Confidence: 100% | Age: 2d ago | Tags: [typescript, types]
203
+ ### Lossless conversation log
264
204
 
265
- 2. [pattern] User prefers strict TypeScript with no implicit any
266
- Score: 0.756 | Confidence: 85% | Age: 5d ago | Tags: [typescript]
267
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…" })
268
209
 
269
- ### Example: Loading context for a task
210
+ # Replay a session
211
+ memory_log_recall({ session_id: "2025-03-25" })
270
212
 
271
- ```
272
- memory_context({ topic: "authentication system", max_tokens: 2000 })
213
+ # Search across all sessions
214
+ memory_log_recall({ query: "OAuth PKCE", limit: 10 })
273
215
  ```
274
216
 
275
- ```markdown
276
- ## Context for: authentication system
217
+ ### Build a knowledge graph
277
218
 
278
- ### Corrections
279
- - Never store JWT secrets in environment variables (100% confidence)
280
-
281
- ### Decisions
282
- - 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
+ })
283
227
 
284
- ### Topology
285
- - Auth module is in src/auth/, middleware in src/middleware/auth.ts (85% confidence)
228
+ memory_relate({ action: "graph", memory_id: "decision-abc" })
286
229
  ```
287
230
 
288
- ### Example: Batch extraction
231
+ Relation types: `supports`, `contradicts`, `depends_on`, `supersedes`, `related_to`, `caused_by`, `implements` — or define your own.
289
232
 
290
- Your AI can extract multiple memories from a single conversation:
233
+ ### Query by time
291
234
 
292
235
  ```
293
- memory_extract({
294
- memories: [
295
- { content: "Don't mock the DB in integration tests", type: "correction", tags: ["testing"], confidence: 1.0 },
296
- { content: "Chose event sourcing for audit trail", type: "decision", tags: ["architecture"], confidence: 0.9 }
297
- ]
298
- })
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
299
239
  ```
300
240
 
301
- ```
302
- Extraction complete: 2 stored, 0 reinforced.
303
- Total memories: 44.
241
+ ### Exact full-text search
304
242
 
305
- + Stored [correction]: "Don't mock the DB in integration tests" (a1b2c3d4)
306
- + 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
307
247
  ```
308
248
 
309
- ### Example: Forgetting memories
249
+ ---
310
250
 
311
- Delete by ID or by query (with a safety confirmation step):
251
+ ## How It Works
312
252
 
313
253
  ```
314
- memory_forget({ query: "old project", confirm: false })
315
- ```
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.
316
278
 
317
- ```
318
- Found 3 memories matching "old project". Preview:
319
- 1. [a1b2c3d4] Old project used Express.js
320
- 2. [e5f6g7h8] Old project had no tests
279
+ ### Smart ranking
321
280
 
322
- Call again with confirm=true to delete these.
281
+ ```
282
+ score = relevance × recency × confidence × importance
323
283
  ```
324
284
 
325
- ---
326
-
327
- ## 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
328
289
 
329
- ### MCP Resources
290
+ ---
330
291
 
331
- amem exposes **4 resources** that AI clients can read proactively at the start of a conversation:
292
+ ## MCP Resources
332
293
 
333
294
  | Resource URI | What it provides |
334
- |-------------|-----------------|
335
- | `amem://corrections` | All active corrections — hard rules the AI should always follow |
336
- | `amem://decisions` | Past architectural decisions and their rationale |
295
+ |---|---|
296
+ | `amem://corrections` | All active corrections — hard constraints |
297
+ | `amem://decisions` | Past architectural decisions |
337
298
  | `amem://profile` | Your preferences and coding patterns |
338
- | `amem://summary` | Quick overview: memory count and breakdown by type |
339
-
340
- ### MCP Prompts
341
-
342
- amem provides **2 prompts** that teach AI clients how to use the memory system effectively:
343
-
344
- | Prompt | Purpose |
345
- |--------|---------|
346
- | `extraction-guide` | Guidelines for *what* to extract from conversations — when to save corrections vs. decisions vs. facts, how often, and what to avoid |
347
- | `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 |
348
302
 
349
303
  ---
350
304
 
351
305
  ## CLI
352
306
 
353
- amem includes a standalone command-line interface for managing memories directly:
354
-
355
307
  ```bash
356
- amem-cli recall "authentication" # Search memories semantically
357
- amem-cli stats # Show statistics with visual bars
358
- amem-cli list # List all memories
359
- amem-cli list --type correction # Filter by type
360
- amem-cli export # Export to stdout as markdown
361
- amem-cli export --file memories.md # Export to file
362
- 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
363
314
  ```
364
315
 
365
316
  ---
366
317
 
367
318
  ## Configuration
368
319
 
369
- amem works out of the box with zero configuration. For advanced use:
370
-
371
- | Environment Variable | Default | Description |
372
- |---------------------|---------|-------------|
373
- | `AMEM_DIR` | `~/.amem` | Where amem stores data |
374
- | `AMEM_DB` | `~/.amem/memory.db` | Database file path |
375
-
376
- Set `AMEM_DB` per-project for isolated memories:
377
-
378
- ```bash
379
- AMEM_DB=./project-memories.db amem
380
- ```
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 |
381
325
 
382
326
  ---
383
327
 
384
- ## Technical Details
385
-
386
- ### Stack
328
+ ## Technical Stack
387
329
 
388
330
  | Layer | Technology |
389
- |-------|------------|
390
- | Protocol | [MCP](https://modelcontextprotocol.io/) SDK ^1.25 (modern `registerTool`/`registerResource`/`registerPrompt` APIs) |
391
- | Language | TypeScript 5.6+ (strict mode, ES2022, zero `any` types) |
392
- | Database | SQLite via better-sqlite3 (WAL mode, prepared statements, indexed) |
393
- | Embeddings | HuggingFace Transformers — Xenova/all-MiniLM-L6-v2 (384-dim, local, optional) |
394
- | Validation | Zod 3.25+ (`.strict()` on all schemas, `.min()` constraints, descriptive errors) |
395
- | 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 |
396
338
  | CI/CD | GitHub Actions — Node 18/20/22 |
397
339
 
398
- ### MCP Best Practices
399
-
400
- amem follows the [MCP best practices](https://modelcontextprotocol.io/) checklist:
401
-
402
- - All 8 tools use `server.registerTool()` with `title`, `description`, `inputSchema`, `outputSchema`, and `annotations`
403
- - All tool handlers wrapped in `try-catch` with `isError: true` on failures
404
- - All Zod schemas use `.strict()` to reject unknown fields
405
- - All error messages are actionable (suggest next steps)
406
- - Server name follows convention: `amem-mcp-server`
407
- - Transport: stdio (correct for local-first tool)
408
- - Logging to stderr (not stdout)
409
- - Graceful shutdown on SIGINT/SIGTERM
410
-
411
- ### Architecture
412
-
413
- ```
414
- src/
415
- ├── index.ts Entry point — server, prompts, resources, transport
416
- ├── tools.ts 8 MCP tools with annotations, validation, structured output
417
- ├── schemas.ts Zod output schemas for structuredContent responses
418
- ├── memory.ts Scoring engine, conflict detection, recall algorithm
419
- ├── database.ts SQLite schema, prepared statements, CRUD interface
420
- ├── embeddings.ts Local embedding pipeline + cosine similarity
421
- └── cli.ts Standalone CLI for direct memory management
422
- ```
423
-
424
- **~1,300 lines of TypeScript.** Clean separation of concerns, no circular dependencies.
425
-
426
- ---
427
-
428
- ## FAQ
429
-
430
- <details>
431
- <summary><strong>Is my data sent to the cloud?</strong></summary>
432
-
433
- 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.
434
-
435
- </details>
436
-
437
- <details>
438
- <summary><strong>Does it work offline?</strong></summary>
439
-
440
- 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.
441
-
442
- </details>
443
-
444
- <details>
445
- <summary><strong>What AI tools does it work with?</strong></summary>
446
-
447
- 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.
448
-
449
- </details>
450
-
451
- <details>
452
- <summary><strong>How much memory/disk does it use?</strong></summary>
453
-
454
- 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.
455
-
456
- </details>
457
-
458
- <details>
459
- <summary><strong>Can I see what's stored?</strong></summary>
460
-
461
- 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`.
462
-
463
- </details>
464
-
465
- <details>
466
- <summary><strong>Can I delete specific memories?</strong></summary>
467
-
468
- 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 })`.
469
-
470
- </details>
471
-
472
- <details>
473
- <summary><strong>Does it slow down my AI?</strong></summary>
474
-
475
- No. Memory operations typically take under 50ms. Embedding generation for new memories takes ~200ms. The server runs as a lightweight background process over stdio.
476
-
477
- </details>
478
-
479
- <details>
480
- <summary><strong>Can I use it across multiple projects?</strong></summary>
481
-
482
- 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.
483
-
484
- </details>
485
-
486
- <details>
487
- <summary><strong>What happens if the embedding model isn't available?</strong></summary>
488
-
489
- 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.
490
-
491
- </details>
492
-
493
- <details>
494
- <summary><strong>How does conflict detection work?</strong></summary>
495
-
496
- 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.
497
-
498
- </details>
499
-
500
340
  ---
501
341
 
502
342
  ## Contributing
503
343
 
504
- Contributions are welcome! Here's how to get involved.
505
-
506
- ### Development setup
507
-
508
344
  ```bash
509
345
  git clone https://github.com/amanasmuei/amem.git
510
- cd amem
511
- npm install
512
- npm run build
513
- npm test
514
- ```
515
-
516
- ### Scripts
517
-
518
- | Script | What it does |
519
- |--------|-------------|
520
- | `npm run build` | Compile TypeScript to `dist/` |
521
- | `npm run dev` | Watch mode — recompile on save |
522
- | `npm test` | Run all 33 tests with Vitest |
523
- | `npm run test:watch` | Run tests in watch mode |
524
- | `npm start` | Start the MCP server (`node dist/index.js`) |
525
-
526
- ### Project structure
527
-
528
- ```
529
- amem/
530
- ├── src/
531
- │ ├── index.ts # MCP server entry point, prompts, resources
532
- │ ├── tools.ts # 7 tool definitions with validation & error handling
533
- │ ├── memory.ts # Scoring engine, conflict detection, recall
534
- │ ├── database.ts # SQLite schema, prepared statements, CRUD
535
- │ ├── embeddings.ts # Local embedding pipeline + cosine similarity
536
- │ └── cli.ts # Standalone CLI
537
- ├── tests/
538
- │ ├── database.test.ts
539
- │ ├── embeddings.test.ts
540
- │ ├── memory.test.ts
541
- │ └── tools.test.ts
542
- ├── .github/
543
- │ └── workflows/
544
- │ ├── ci.yml # Test on push/PR (Node 18/20/22)
545
- │ └── publish.yml # Publish to npm on GitHub Release
546
- ├── package.json
547
- ├── tsconfig.json
548
- └── vitest.config.ts
346
+ cd amem && npm install
347
+ npm run build # zero TS errors
348
+ npm test # 92 tests pass
549
349
  ```
550
350
 
551
- ### Making changes
552
-
553
- 1. Fork the repository
554
- 2. Create a feature branch: `git checkout -b feature/your-feature`
555
- 3. Make your changes
556
- 4. Ensure the build is clean: `npm run build`
557
- 5. Ensure all tests pass: `npm test`
558
- 6. Commit and push your branch
559
- 7. Open a Pull Request against `main`
560
-
561
- ### CI/CD
562
-
563
- **GitHub Actions** runs automatically on every push and pull request:
564
-
565
- - **CI workflow** (`ci.yml`) — builds and tests against Node.js 18, 20, and 22 on Ubuntu
566
- - **Publish workflow** (`publish.yml`) — triggered on GitHub Release, builds, tests, and publishes to npm with `--access public`
567
-
568
- All PRs must pass the CI pipeline before merging.
569
-
570
- ### Reporting issues
571
-
572
- Found a bug or have a feature idea?
573
-
574
- - **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
575
- - **Feature requests**: [Open an issue](https://github.com/amanasmuei/amem/issues/new) describing the use case and how it would improve the memory system
576
- - **Questions**: [Start a discussion](https://github.com/amanasmuei/amem/discussions) (or open an issue)
351
+ PRs must pass CI before merge.
577
352
 
578
353
  ---
579
354
 
580
- ## Roadmap
581
-
582
- - [x] 8 MCP tools with full annotations, validation, and error handling
583
- - [x] Semantic search with local embeddings (graceful fallback to keywords)
584
- - [x] Smart conflict detection and deduplication
585
- - [x] Memory evolution (related memories reinforce each other)
586
- - [x] CLI for direct memory management
587
- - [x] MCP prompts and resources for proactive context
588
- - [x] Published on npm
589
- - [x] `outputSchema` + `structuredContent` for machine-readable tool responses
590
- - [x] Proactive context injection (`memory_inject` tool)
591
- - [x] Evaluation suite (10 standardized eval questions)
592
- - [ ] Memory verification against filesystem
593
- - [ ] Knowledge graph with entity relationships
594
- - [ ] Team memory (shared context across developers)
595
-
596
- ---
597
-
598
- <div align="center">
599
-
600
355
  **Built by [Aman Asmuei](https://github.com/amanasmuei)**
601
356
 
602
- [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)
603
358
 
604
359
  MIT License
605
-
606
- </div>