@agentmemory/agentmemory 0.7.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.
Files changed (259) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/.github/workflows/ci.yml +22 -0
  3. package/.github/workflows/publish.yml +28 -0
  4. package/AGENTS.md +113 -0
  5. package/LICENSE +190 -0
  6. package/README.md +828 -0
  7. package/assets/banner.png +0 -0
  8. package/assets/demo.gif +0 -0
  9. package/assets/demo.mp4 +0 -0
  10. package/benchmark/QUALITY.md +73 -0
  11. package/benchmark/REAL-EMBEDDINGS.md +67 -0
  12. package/benchmark/SCALE.md +110 -0
  13. package/benchmark/dataset.ts +293 -0
  14. package/benchmark/quality-eval.ts +643 -0
  15. package/benchmark/real-embeddings-eval.ts +405 -0
  16. package/benchmark/scale-eval.ts +398 -0
  17. package/dist/cli.d.mts +1 -0
  18. package/dist/cli.mjs +137 -0
  19. package/dist/cli.mjs.map +1 -0
  20. package/dist/docker-compose.yml +14 -0
  21. package/dist/hooks/notification.d.mts +1 -0
  22. package/dist/hooks/notification.mjs +45 -0
  23. package/dist/hooks/notification.mjs.map +1 -0
  24. package/dist/hooks/post-tool-failure.d.mts +1 -0
  25. package/dist/hooks/post-tool-failure.mjs +45 -0
  26. package/dist/hooks/post-tool-failure.mjs.map +1 -0
  27. package/dist/hooks/post-tool-use.d.mts +1 -0
  28. package/dist/hooks/post-tool-use.mjs +53 -0
  29. package/dist/hooks/post-tool-use.mjs.map +1 -0
  30. package/dist/hooks/pre-compact.d.mts +1 -0
  31. package/dist/hooks/pre-compact.mjs +50 -0
  32. package/dist/hooks/pre-compact.mjs.map +1 -0
  33. package/dist/hooks/pre-tool-use.d.mts +1 -0
  34. package/dist/hooks/pre-tool-use.mjs +69 -0
  35. package/dist/hooks/pre-tool-use.mjs.map +1 -0
  36. package/dist/hooks/prompt-submit.d.mts +1 -0
  37. package/dist/hooks/prompt-submit.mjs +40 -0
  38. package/dist/hooks/prompt-submit.mjs.map +1 -0
  39. package/dist/hooks/session-end.d.mts +1 -0
  40. package/dist/hooks/session-end.mjs +61 -0
  41. package/dist/hooks/session-end.mjs.map +1 -0
  42. package/dist/hooks/session-start.d.mts +1 -0
  43. package/dist/hooks/session-start.mjs +42 -0
  44. package/dist/hooks/session-start.mjs.map +1 -0
  45. package/dist/hooks/stop.d.mts +1 -0
  46. package/dist/hooks/stop.mjs +33 -0
  47. package/dist/hooks/stop.mjs.map +1 -0
  48. package/dist/hooks/subagent-start.d.mts +1 -0
  49. package/dist/hooks/subagent-start.mjs +43 -0
  50. package/dist/hooks/subagent-start.mjs.map +1 -0
  51. package/dist/hooks/subagent-stop.d.mts +1 -0
  52. package/dist/hooks/subagent-stop.mjs +45 -0
  53. package/dist/hooks/subagent-stop.mjs.map +1 -0
  54. package/dist/hooks/task-completed.d.mts +1 -0
  55. package/dist/hooks/task-completed.mjs +46 -0
  56. package/dist/hooks/task-completed.mjs.map +1 -0
  57. package/dist/iii-config.yaml +51 -0
  58. package/dist/index.d.mts +2 -0
  59. package/dist/index.mjs +13776 -0
  60. package/dist/index.mjs.map +1 -0
  61. package/dist/src-QxitMPfJ.mjs +13775 -0
  62. package/dist/src-QxitMPfJ.mjs.map +1 -0
  63. package/dist/standalone.d.mts +1 -0
  64. package/dist/standalone.mjs +1155 -0
  65. package/dist/standalone.mjs.map +1 -0
  66. package/dist/transformers-BX_tgxdO.mjs +38684 -0
  67. package/dist/transformers-BX_tgxdO.mjs.map +1 -0
  68. package/dist/transformers-KMm1i9no.mjs +38683 -0
  69. package/dist/transformers-KMm1i9no.mjs.map +1 -0
  70. package/docker-compose.yml +14 -0
  71. package/iii-config.yaml +51 -0
  72. package/package.json +59 -0
  73. package/plugin/.claude-plugin/plugin.json +10 -0
  74. package/plugin/hooks/hooks.json +77 -0
  75. package/plugin/scripts/diagnostics.mjs +551 -0
  76. package/plugin/scripts/notification.mjs +45 -0
  77. package/plugin/scripts/post-tool-failure.mjs +45 -0
  78. package/plugin/scripts/post-tool-use.mjs +53 -0
  79. package/plugin/scripts/pre-compact.mjs +50 -0
  80. package/plugin/scripts/pre-tool-use.mjs +69 -0
  81. package/plugin/scripts/prompt-submit.mjs +40 -0
  82. package/plugin/scripts/session-end.mjs +61 -0
  83. package/plugin/scripts/session-start.mjs +42 -0
  84. package/plugin/scripts/stop.mjs +33 -0
  85. package/plugin/scripts/subagent-start.mjs +43 -0
  86. package/plugin/scripts/subagent-stop.mjs +45 -0
  87. package/plugin/scripts/task-completed.mjs +46 -0
  88. package/plugin/skills/forget/SKILL.md +32 -0
  89. package/plugin/skills/recall/SKILL.md +18 -0
  90. package/plugin/skills/remember/SKILL.md +25 -0
  91. package/plugin/skills/session-history/SKILL.md +17 -0
  92. package/src/auth.ts +12 -0
  93. package/src/cli.ts +159 -0
  94. package/src/config.ts +221 -0
  95. package/src/eval/metrics-store.ts +65 -0
  96. package/src/eval/quality.ts +51 -0
  97. package/src/eval/schemas.ts +124 -0
  98. package/src/eval/self-correct.ts +28 -0
  99. package/src/eval/validator.ts +31 -0
  100. package/src/functions/actions.ts +288 -0
  101. package/src/functions/audit.ts +61 -0
  102. package/src/functions/auto-forget.ts +169 -0
  103. package/src/functions/branch-aware.ts +169 -0
  104. package/src/functions/cascade.ts +80 -0
  105. package/src/functions/checkpoints.ts +209 -0
  106. package/src/functions/claude-bridge.ts +161 -0
  107. package/src/functions/compress.ts +194 -0
  108. package/src/functions/consolidate.ts +212 -0
  109. package/src/functions/consolidation-pipeline.ts +258 -0
  110. package/src/functions/context.ts +169 -0
  111. package/src/functions/crystallize.ts +293 -0
  112. package/src/functions/dedup.ts +57 -0
  113. package/src/functions/diagnostics.ts +785 -0
  114. package/src/functions/enrich.ts +132 -0
  115. package/src/functions/evict.ts +163 -0
  116. package/src/functions/export-import.ts +508 -0
  117. package/src/functions/facets.ts +248 -0
  118. package/src/functions/file-index.ts +106 -0
  119. package/src/functions/flow-compress.ts +214 -0
  120. package/src/functions/frontier.ts +196 -0
  121. package/src/functions/governance.ts +131 -0
  122. package/src/functions/graph-retrieval.ts +277 -0
  123. package/src/functions/graph.ts +275 -0
  124. package/src/functions/leases.ts +216 -0
  125. package/src/functions/lessons.ts +253 -0
  126. package/src/functions/mesh.ts +434 -0
  127. package/src/functions/migrate.ts +165 -0
  128. package/src/functions/observe.ts +144 -0
  129. package/src/functions/obsidian-export.ts +310 -0
  130. package/src/functions/patterns.ts +138 -0
  131. package/src/functions/privacy.ts +39 -0
  132. package/src/functions/profile.ts +155 -0
  133. package/src/functions/query-expansion.ts +186 -0
  134. package/src/functions/relations.ts +237 -0
  135. package/src/functions/remember.ts +162 -0
  136. package/src/functions/retention.ts +235 -0
  137. package/src/functions/routines.ts +289 -0
  138. package/src/functions/search.ts +80 -0
  139. package/src/functions/sentinels.ts +417 -0
  140. package/src/functions/signals.ts +186 -0
  141. package/src/functions/sketches.ts +274 -0
  142. package/src/functions/sliding-window.ts +257 -0
  143. package/src/functions/smart-search.ts +115 -0
  144. package/src/functions/snapshot.ts +219 -0
  145. package/src/functions/summarize.ts +155 -0
  146. package/src/functions/team.ts +147 -0
  147. package/src/functions/temporal-graph.ts +476 -0
  148. package/src/functions/timeline.ts +138 -0
  149. package/src/functions/verify.ts +117 -0
  150. package/src/health/monitor.ts +110 -0
  151. package/src/health/thresholds.ts +73 -0
  152. package/src/hooks/notification.ts +52 -0
  153. package/src/hooks/post-tool-failure.ts +58 -0
  154. package/src/hooks/post-tool-use.ts +62 -0
  155. package/src/hooks/pre-compact.ts +60 -0
  156. package/src/hooks/pre-tool-use.ts +72 -0
  157. package/src/hooks/prompt-submit.ts +46 -0
  158. package/src/hooks/session-end.ts +71 -0
  159. package/src/hooks/session-start.ts +48 -0
  160. package/src/hooks/stop.ts +39 -0
  161. package/src/hooks/subagent-start.ts +49 -0
  162. package/src/hooks/subagent-stop.ts +54 -0
  163. package/src/hooks/task-completed.ts +54 -0
  164. package/src/index.ts +342 -0
  165. package/src/mcp/in-memory-kv.ts +61 -0
  166. package/src/mcp/server.ts +1455 -0
  167. package/src/mcp/standalone.ts +177 -0
  168. package/src/mcp/tools-registry.ts +769 -0
  169. package/src/mcp/transport.ts +91 -0
  170. package/src/prompts/compression.ts +67 -0
  171. package/src/prompts/consolidation.ts +48 -0
  172. package/src/prompts/graph-extraction.ts +35 -0
  173. package/src/prompts/summary.ts +38 -0
  174. package/src/prompts/xml.ts +26 -0
  175. package/src/providers/agent-sdk.ts +34 -0
  176. package/src/providers/anthropic.ts +35 -0
  177. package/src/providers/circuit-breaker.ts +82 -0
  178. package/src/providers/embedding/cohere.ts +46 -0
  179. package/src/providers/embedding/gemini.ts +54 -0
  180. package/src/providers/embedding/index.ts +39 -0
  181. package/src/providers/embedding/local.ts +52 -0
  182. package/src/providers/embedding/openai.ts +45 -0
  183. package/src/providers/embedding/openrouter.ts +51 -0
  184. package/src/providers/embedding/voyage.ts +46 -0
  185. package/src/providers/fallback-chain.ts +31 -0
  186. package/src/providers/index.ts +84 -0
  187. package/src/providers/openrouter.ts +71 -0
  188. package/src/providers/resilient.ts +37 -0
  189. package/src/state/hybrid-search.ts +295 -0
  190. package/src/state/index-persistence.ts +63 -0
  191. package/src/state/keyed-mutex.ts +18 -0
  192. package/src/state/kv.ts +33 -0
  193. package/src/state/schema.ts +71 -0
  194. package/src/state/search-index.ts +245 -0
  195. package/src/state/stemmer.ts +104 -0
  196. package/src/state/synonyms.ts +63 -0
  197. package/src/state/vector-index.ts +130 -0
  198. package/src/telemetry/setup.ts +116 -0
  199. package/src/triggers/api.ts +1904 -0
  200. package/src/triggers/events.ts +71 -0
  201. package/src/types.ts +769 -0
  202. package/src/version.ts +1 -0
  203. package/src/viewer/index.html +2497 -0
  204. package/src/viewer/server.ts +207 -0
  205. package/src/xenova.d.ts +3 -0
  206. package/test/actions.test.ts +490 -0
  207. package/test/audit.test.ts +108 -0
  208. package/test/auto-forget.test.ts +188 -0
  209. package/test/cascade.test.ts +277 -0
  210. package/test/checkpoints.test.ts +493 -0
  211. package/test/circuit-breaker.test.ts +107 -0
  212. package/test/claude-bridge.test.ts +178 -0
  213. package/test/confidence.test.ts +247 -0
  214. package/test/consistency.test.ts +61 -0
  215. package/test/consolidation-pipeline.test.ts +251 -0
  216. package/test/crystallize.test.ts +521 -0
  217. package/test/diagnostics.test.ts +638 -0
  218. package/test/embedding-provider.test.ts +49 -0
  219. package/test/enrich.test.ts +209 -0
  220. package/test/eval.test.ts +300 -0
  221. package/test/export-import.test.ts +251 -0
  222. package/test/facets.test.ts +448 -0
  223. package/test/fallback-chain.test.ts +93 -0
  224. package/test/frontier.test.ts +485 -0
  225. package/test/governance.test.ts +147 -0
  226. package/test/graph-retrieval.test.ts +186 -0
  227. package/test/graph.test.ts +160 -0
  228. package/test/helpers/mocks.ts +40 -0
  229. package/test/hybrid-search.test.ts +145 -0
  230. package/test/index-persistence.test.ts +124 -0
  231. package/test/integration.test.ts +265 -0
  232. package/test/leases.test.ts +399 -0
  233. package/test/mcp-prompts.test.ts +218 -0
  234. package/test/mcp-resources.test.ts +286 -0
  235. package/test/mcp-standalone.test.ts +113 -0
  236. package/test/mesh.test.ts +700 -0
  237. package/test/privacy.test.ts +87 -0
  238. package/test/profile.test.ts +161 -0
  239. package/test/query-expansion.test.ts +154 -0
  240. package/test/relations.test.ts +198 -0
  241. package/test/retention.test.ts +245 -0
  242. package/test/routines.test.ts +497 -0
  243. package/test/schema-fingerprint.test.ts +81 -0
  244. package/test/schema.test.ts +42 -0
  245. package/test/search-index.test.ts +128 -0
  246. package/test/sentinels.test.ts +626 -0
  247. package/test/signals.test.ts +410 -0
  248. package/test/sketches.test.ts +549 -0
  249. package/test/sliding-window.test.ts +199 -0
  250. package/test/smart-search.test.ts +169 -0
  251. package/test/snapshot.test.ts +165 -0
  252. package/test/team.test.ts +156 -0
  253. package/test/temporal-graph.test.ts +378 -0
  254. package/test/timeline.test.ts +148 -0
  255. package/test/vector-index.test.ts +79 -0
  256. package/test/verify.test.ts +209 -0
  257. package/test/xml.test.ts +65 -0
  258. package/tsconfig.json +22 -0
  259. package/tsdown.config.ts +62 -0
package/README.md ADDED
@@ -0,0 +1,828 @@
1
+ <p align="center">
2
+ <img src="assets/banner.png" alt="agentmemory — Persistent memory for AI coding agents" width="720" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ <strong>Persistent memory for AI coding agents.</strong><br/>
7
+ Powered by <a href="https://iii.dev">iii-engine</a>.
8
+ </p>
9
+
10
+ <p align="center">
11
+ <img src="assets/demo.gif" alt="agentmemory demo" width="720" />
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="#quick-start">Quick Start</a> &bull;
16
+ <a href="#why-agentmemory">Why</a> &bull;
17
+ <a href="#supported-agents">Agents</a> &bull;
18
+ <a href="#how-it-works">How It Works</a> &bull;
19
+ <a href="#search">Search</a> &bull;
20
+ <a href="#memory-evolution">Memory Evolution</a> &bull;
21
+ <a href="#mcp-server">MCP</a> &bull;
22
+ <a href="#real-time-viewer">Viewer</a> &bull;
23
+ <a href="#configuration">Configuration</a> &bull;
24
+ <a href="#api">API</a>
25
+ </p>
26
+
27
+ ---
28
+
29
+ Every AI coding agent has the same blind spot. Session ends, memory vanishes. You re-explain architecture. You re-discover bugs. You re-teach preferences. Built-in memory files like CLAUDE.md and .cursorrules are 200-line sticky notes that overflow and go stale. agentmemory replaces that with a searchable, versioned, cross-agent database — 41 MCP tools, triple-stream retrieval (BM25 + vector + knowledge graph), 4-tier memory consolidation, provenance-tracked citations, and cascading staleness so retired facts never pollute your context again. One instance serves Claude Code, Cursor, Codex, Windsurf, and any MCP client simultaneously. 573 tests. Zero external DB dependencies.
30
+
31
+ The result is measurable. On 240 real observations across 30 sessions, agentmemory hits 64% Recall@10 and perfect MRR while using 92% fewer tokens than dumping everything into context. When an agent searches "database performance optimization," it finds the N+1 fix you made three weeks ago — something keyword grep literally cannot do. Memories version automatically, supersede each other, propagate staleness to related graph nodes, and sync across agent instances via P2P mesh. Your agents stop repeating mistakes. Your context stays clean. Your sessions start fast.
32
+
33
+ ```bash
34
+ git clone https://github.com/rohitg00/agentmemory.git && cd agentmemory
35
+ docker compose up -d && npm install && npm run build && npm start
36
+ curl http://localhost:3111/agentmemory/health
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Why agentmemory
42
+
43
+ AI coding agents forget everything between sessions. You explain the same architecture, re-discover the same patterns, and re-learn the same preferences every time. agentmemory fixes that.
44
+
45
+ ```
46
+ Session 1: "Add auth to the API"
47
+ Agent writes code, runs tests, fixes bugs
48
+ agentmemory silently captures every tool use
49
+ Session ends -> observations compressed into structured memory
50
+
51
+ Session 2: "Now add rate limiting"
52
+ agentmemory injects context from Session 1:
53
+ - Auth uses JWT middleware in src/middleware/auth.ts
54
+ - Tests in test/auth.test.ts cover token validation
55
+ - Decision: chose jose over jsonwebtoken for Edge compatibility
56
+ Agent starts with full project awareness
57
+ ```
58
+
59
+ No manual notes. No copy-pasting. The agent just *knows*.
60
+
61
+ ### What it gives you
62
+
63
+ | Capability | What it does |
64
+ |---|---|
65
+ | **Automatic capture** | Every tool use, file edit, test run, and error is silently recorded via hooks |
66
+ | **LLM compression** | Raw observations are compressed into structured facts, concepts, and narratives |
67
+ | **Context injection** | Past knowledge is injected at session start within a configurable token budget |
68
+ | **Semantic search** | Hybrid BM25 + vector search finds relevant memories even with different wording |
69
+ | **Memory evolution** | Memories version over time, supersede each other, and form relationship graphs |
70
+ | **Project profiles** | Aggregated per-project intelligence: top concepts, files, conventions, common errors |
71
+ | **Auto-forgetting** | TTL expiry, contradiction detection, and importance-based eviction keep memory clean |
72
+ | **Privacy first** | API keys, secrets, and `<private>` tags are stripped before anything is stored |
73
+ | **Self-healing** | Circuit breaker, provider fallback chain, self-correcting LLM output, health monitoring |
74
+ | **Claude Code bridge** | Bi-directional sync with `~/.claude/projects/*/memory/MEMORY.md` |
75
+ | **Cross-agent MCP** | Standalone MCP server for Cursor, Codex, Gemini CLI, Windsurf, any MCP client |
76
+ | **Citation provenance** | JIT verification traces any memory back to source observations and sessions |
77
+ | **Cascading staleness** | Superseded memories auto-flag related graph nodes, edges, and siblings as stale |
78
+ | **Knowledge graph** | Entity extraction + BFS traversal across files, functions, concepts, errors |
79
+ | **4-tier memory** | Working → episodic → semantic → procedural consolidation with strength decay |
80
+ | **Team memory** | Namespaced shared + private memory across team members |
81
+ | **Governance** | Edit, delete, bulk-delete, and audit trail for all memory operations |
82
+ | **Git snapshots** | Version, rollback, and diff memory state via git commits |
83
+
84
+ ### How it compares to built-in agent memory
85
+
86
+ Every AI coding agent now ships with built-in memory — Claude Code has `MEMORY.md`, Cursor has notepads, Windsurf has Cascade memories, Cline has memory bank. These work like sticky notes: fast, always-on, but fundamentally limited.
87
+
88
+ agentmemory is the searchable database behind the sticky notes.
89
+
90
+ | | Built-in (CLAUDE.md, .cursorrules) | agentmemory |
91
+ |---|---|---|
92
+ | Scale | 200-line cap (MEMORY.md) | Unlimited |
93
+ | Search | Loads everything into context | BM25 + vector + graph (returns top-K only) |
94
+ | Token cost | 22K+ tokens at 240 observations | ~1,900 tokens (92% less) |
95
+ | At 1K observations | 80% of memories invisible | 100% searchable |
96
+ | At 5K observations | Exceeds context window | Still ~2K tokens |
97
+ | Cross-session recall | Only within line cap | Full corpus search |
98
+ | Cross-agent | Per-agent files (no sharing) | MCP + REST API (any agent) |
99
+ | Multi-agent coordination | Impossible | Leases, signals, actions, routines |
100
+ | Cross-agent sync | No | P2P mesh (7 scopes: memories, actions, semantic, procedural, relations, graph) |
101
+ | Memory trust | No verification | Citation chain back to source observations with confidence scores |
102
+ | Semantic search | No (keyword grep) | Yes (Recall@10: 64% vs 56% for grep) |
103
+ | Memory lifecycle | Manual pruning | Ebbinghaus decay + tiered eviction |
104
+ | Knowledge graph | No | Entity extraction + temporal versioning |
105
+ | Observability | Read files manually | Real-time viewer on :3113 |
106
+
107
+ ### Benchmarks (measured, not projected)
108
+
109
+ Evaluated on 240 real-world coding observations across 30 sessions with 20 labeled queries:
110
+
111
+ | System | Recall@10 | NDCG@10 | MRR | Tokens/query |
112
+ |---|---|---|---|---|
113
+ | Built-in (grep all into context) | 55.8% | 80.3% | 82.5% | 19,462 |
114
+ | agentmemory BM25 (stemmed + synonyms) | 55.9% | 82.7% | 95.5% | 1,571 |
115
+ | agentmemory + Xenova embeddings | **64.1%** | **94.9%** | **100.0%** | **1,571** |
116
+
117
+ With real embeddings, agentmemory finds "N+1 query fix" when you search "database performance optimization" — something keyword matching literally cannot do.
118
+
119
+ Full benchmark reports: [`benchmark/QUALITY.md`](benchmark/QUALITY.md), [`benchmark/SCALE.md`](benchmark/SCALE.md), [`benchmark/REAL-EMBEDDINGS.md`](benchmark/REAL-EMBEDDINGS.md)
120
+
121
+ ## Supported Agents
122
+
123
+ agentmemory works with any agent that supports hooks, MCP, or via its REST API.
124
+
125
+ ### Native hook support (zero config)
126
+
127
+ These agents support hooks natively. agentmemory captures tool usage automatically via its 12 hooks.
128
+
129
+ | Agent | Integration | Setup |
130
+ |---|---|---|
131
+ | **Claude Code** | 12 hooks (all types) | `/plugin install agentmemory` or manual hook config |
132
+ | **Claude Code SDK** | Agent SDK provider | Built-in `AgentSDKProvider` uses your Claude subscription |
133
+
134
+ ### MCP support (any MCP-compatible agent)
135
+
136
+ Any agent that connects to MCP servers can use agentmemory's 41 tools, 6 resources, and 3 prompts. The agent actively queries and saves memory through MCP calls.
137
+
138
+ | Agent | How to connect |
139
+ |---|---|
140
+ | **Claude Desktop** | Add to `claude_desktop_config.json` MCP servers |
141
+ | **Cursor** | Add MCP server in settings |
142
+ | **Windsurf** | MCP server configuration |
143
+ | **Cline / Continue** | MCP server configuration |
144
+ | **Any MCP client** | Point to `http://localhost:3111/agentmemory/mcp/*` |
145
+
146
+ ### REST API (any agent, any language)
147
+
148
+ Agents without hooks or MCP can integrate via 100 REST endpoints directly. This works with any agent, language, or framework.
149
+
150
+ ```bash
151
+ POST /agentmemory/observe # Capture what the agent did
152
+ POST /agentmemory/smart-search # Find relevant memories
153
+ POST /agentmemory/context # Get context for injection
154
+ POST /agentmemory/enrich # Get enriched context (files + memories + bugs)
155
+ POST /agentmemory/remember # Save long-term memory
156
+ GET /agentmemory/profile # Get project intelligence
157
+ ```
158
+
159
+ ### Choosing an integration method
160
+
161
+ | Your situation | Use |
162
+ |---|---|
163
+ | Claude Code user | Plugin install (hooks + MCP + skills) |
164
+ | Building a custom agent with Claude SDK | AgentSDKProvider (zero config) |
165
+ | Using Cursor, Windsurf, or any MCP client | MCP server (38 tools + 6 resources + 3 prompts) |
166
+ | Building your own agent framework | REST API (93 endpoints) |
167
+ | Sharing memory across multiple agents | All agents point to the same iii-engine instance |
168
+
169
+ ## Quick Start
170
+
171
+ ### 1. Install the Plugin (Claude Code)
172
+
173
+ ```bash
174
+ /plugin marketplace add rohitg00/agentmemory
175
+ /plugin install agentmemory
176
+ ```
177
+
178
+ All 12 hooks, 4 skills, and MCP server are registered automatically.
179
+
180
+ ### 2. Start the Worker
181
+
182
+ ```bash
183
+ git clone https://github.com/rohitg00/agentmemory.git
184
+ cd agentmemory
185
+
186
+ docker compose up -d # Start iii-engine
187
+ npm install && npm run build && npm start
188
+ ```
189
+
190
+ ### 3. Verify
191
+
192
+ ```bash
193
+ curl http://localhost:3111/agentmemory/health
194
+
195
+ # Real-time viewer (auto-starts on port 3113)
196
+ open http://localhost:3113
197
+ ```
198
+
199
+ ```json
200
+ {
201
+ "status": "healthy",
202
+ "service": "agentmemory",
203
+ "version": "0.6.1",
204
+ "health": {
205
+ "memory": { "heapUsed": 42000000, "heapTotal": 67000000 },
206
+ "cpu": { "percent": 2.1 },
207
+ "eventLoopLagMs": 1.2,
208
+ "status": "healthy"
209
+ },
210
+ "circuitBreaker": { "state": "closed", "failures": 0 }
211
+ }
212
+ ```
213
+
214
+ ### Manual Hook Setup (alternative)
215
+
216
+ If you prefer not to use the plugin, add hooks directly to `~/.claude/settings.json`:
217
+
218
+ ```json
219
+ {
220
+ "hooks": {
221
+ "SessionStart": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/session-start.mjs" }],
222
+ "UserPromptSubmit": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/prompt-submit.mjs" }],
223
+ "PreToolUse": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/pre-tool-use.mjs" }],
224
+ "PostToolUse": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/post-tool-use.mjs" }],
225
+ "PostToolUseFailure": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/post-tool-failure.mjs" }],
226
+ "PreCompact": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/pre-compact.mjs" }],
227
+ "SubagentStart": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/subagent-start.mjs" }],
228
+ "SubagentStop": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/subagent-stop.mjs" }],
229
+ "Notification": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/notification.mjs" }],
230
+ "TaskCompleted": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/task-completed.mjs" }],
231
+ "Stop": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/stop.mjs" }],
232
+ "SessionEnd": [{ "type": "command", "command": "node ~/agentmemory/dist/hooks/session-end.mjs" }]
233
+ }
234
+ }
235
+ ```
236
+
237
+ ## How It Works
238
+
239
+ ### Observation Pipeline
240
+
241
+ ```
242
+ PostToolUse hook fires
243
+ -> Dedup check SHA-256 hash (5min window, no duplicates)
244
+ -> mem::privacy Strip secrets, API keys, <private> tags
245
+ -> mem::observe Store raw observation, push to real-time stream
246
+ -> mem::compress LLM extracts: type, facts, narrative, concepts, files
247
+ Validates with Zod, scores quality (0-100)
248
+ Self-corrects on validation failure (1 retry)
249
+ Generates vector embedding for semantic search
250
+ ```
251
+
252
+ ### Context Injection
253
+
254
+ ```
255
+ SessionStart hook fires
256
+ -> mem::context Load recent sessions for this project
257
+ Hybrid search (BM25 + vector) across observations
258
+ Inject project profile (top concepts, files, patterns)
259
+ Apply token budget (default: 2000 tokens)
260
+ -> stdout Agent receives context in the conversation
261
+ ```
262
+
263
+ ### What Gets Captured
264
+
265
+ | Hook | Captures |
266
+ |------|----------|
267
+ | `SessionStart` | Project path, session ID, working directory |
268
+ | `UserPromptSubmit` | User prompts (privacy-filtered) |
269
+ | `PreToolUse` | File access patterns + enriched context injection (Read, Write, Edit, Glob, Grep) |
270
+ | `PostToolUse` | Tool name, input, output |
271
+ | `PostToolUseFailure` | Failed tool invocations with error context |
272
+ | `PreCompact` | Re-injects memory context before context compaction |
273
+ | `SubagentStart/Stop` | Sub-agent lifecycle events |
274
+ | `Notification` | System notifications |
275
+ | `TaskCompleted` | Task completion events |
276
+ | `Stop` | Triggers end-of-session summary |
277
+ | `SessionEnd` | Marks session complete |
278
+
279
+ ## Search
280
+
281
+ agentmemory uses triple-stream retrieval combining three signals for maximum recall.
282
+
283
+ ### How search works
284
+
285
+ | Stream | What it does | When |
286
+ |---|---|---|
287
+ | **BM25** | Stemmed keyword matching with synonym expansion and binary-search prefix matching | Always on |
288
+ | **Vector** | Cosine similarity over dense embeddings (Xenova, OpenAI, Gemini, Voyage, Cohere, OpenRouter) | Any embedding provider configured |
289
+ | **Graph** | Knowledge graph traversal via entity matching and co-occurrence edges | Entities detected in query |
290
+
291
+ All three streams are fused with Reciprocal Rank Fusion (RRF, k=60) and session-diversified (max 3 results per session) to maximize coverage.
292
+
293
+ **BM25 enhancements (v0.6.0):** Porter stemmer normalizes word forms ("authentication" ↔ "authenticating"), coding-domain synonyms expand queries ("db" ↔ "database", "perf" ↔ "performance"), and binary-search prefix matching replaces O(n) scans.
294
+
295
+ ### Embedding providers
296
+
297
+ agentmemory auto-detects which provider to use. For best results, install local embeddings (no API key needed):
298
+
299
+ ```bash
300
+ npm install @xenova/transformers
301
+ ```
302
+
303
+ | Provider | Model | Dimensions | Env Var | Notes |
304
+ |---|---|---|---|---|
305
+ | **Local (recommended)** | `all-MiniLM-L6-v2` | 384 | `EMBEDDING_PROVIDER=local` | Free, offline, +8pp recall over BM25-only |
306
+ | Gemini | `text-embedding-004` | 768 | `GEMINI_API_KEY` | Free tier (1500 RPM) |
307
+ | OpenAI | `text-embedding-3-small` | 1536 | `OPENAI_API_KEY` | $0.02/1M tokens |
308
+ | Voyage AI | `voyage-code-3` | 1024 | `VOYAGE_API_KEY` | Optimized for code |
309
+ | Cohere | `embed-english-v3.0` | 1024 | `COHERE_API_KEY` | Free trial available |
310
+ | OpenRouter | Any embedding model | varies | `OPENROUTER_API_KEY` | Multi-model proxy |
311
+
312
+ No embedding provider? BM25-only mode with stemming and synonyms still outperforms built-in memory.
313
+
314
+ ### Progressive disclosure
315
+
316
+ Smart search returns compact results first (title, type, score, timestamp) to save tokens. Expand specific IDs to get full observation details.
317
+
318
+ ```bash
319
+ # Compact results (50-100 tokens each)
320
+ curl -X POST http://localhost:3111/agentmemory/smart-search \
321
+ -d '{"query": "database migration"}'
322
+
323
+ # Expand specific results (500-1000 tokens each)
324
+ curl -X POST http://localhost:3111/agentmemory/smart-search \
325
+ -d '{"expandIds": ["obs_abc123", "obs_def456"]}'
326
+ ```
327
+
328
+ ## Memory Evolution
329
+
330
+ Memories in agentmemory are not static. They version, evolve, and form relationships.
331
+
332
+ ### Versioning
333
+
334
+ When you save a memory that's similar to an existing one (Jaccard > 0.7), the old memory is superseded:
335
+
336
+ ```
337
+ v1: "Use Express for API routes"
338
+ v2: "Use Fastify instead of Express for API routes" (supersedes v1)
339
+ v3: "Use Hono instead of Fastify for Edge API routes" (supersedes v2)
340
+ ```
341
+
342
+ Only the latest version is returned in search results. The full chain is preserved for audit.
343
+
344
+ ### Relationships
345
+
346
+ Memories can be linked: `supersedes`, `extends`, `derives`, `contradicts`, `related`. Each relationship carries a confidence score (0-1) computed from co-occurrence, recency, and relation type. Traversal follows these links up to N hops, with optional `minConfidence` filtering.
347
+
348
+ ### Auto-forget
349
+
350
+ agentmemory automatically cleans itself:
351
+
352
+ | Mechanism | What it does |
353
+ |---|---|
354
+ | **TTL expiry** | Memories with `forgetAfter` date are deleted when expired |
355
+ | **Contradiction detection** | Near-duplicate memories (Jaccard > 0.9) — older one is demoted |
356
+ | **Low-value eviction** | Observations older than 90 days with importance < 3 are removed |
357
+ | **Per-project cap** | Projects are capped at 10,000 observations (lowest importance evicted first) |
358
+
359
+ Run `POST /agentmemory/auto-forget?dryRun=true` to preview what would be cleaned.
360
+
361
+ ### Project profiles
362
+
363
+ agentmemory aggregates observations into per-project intelligence:
364
+
365
+ ```bash
366
+ curl "http://localhost:3111/agentmemory/profile?project=/my/project"
367
+ ```
368
+
369
+ Returns top concepts, most-touched files, coding conventions, common errors, and a session count. This profile is automatically injected into session context.
370
+
371
+ ### Timeline
372
+
373
+ Navigate observations chronologically around any anchor point:
374
+
375
+ ```bash
376
+ curl -X POST http://localhost:3111/agentmemory/timeline \
377
+ -d '{"anchor": "2026-02-15", "before": 5, "after": 5}'
378
+ ```
379
+
380
+ ### Export / Import
381
+
382
+ Full data portability:
383
+
384
+ ```bash
385
+ # Export everything
386
+ curl http://localhost:3111/agentmemory/export > backup.json
387
+
388
+ # Import with merge strategy
389
+ curl -X POST http://localhost:3111/agentmemory/import \
390
+ -d '{"exportData": ..., "strategy": "merge"}'
391
+ ```
392
+
393
+ Strategies: `merge` (combine), `replace` (overwrite), `skip` (ignore duplicates).
394
+
395
+ ## Self-Evaluation
396
+
397
+ agentmemory monitors its own health and validates its own output.
398
+
399
+ ### Quality scoring
400
+
401
+ Every LLM compression is scored 0-100 based on structured facts, narrative quality, concept extraction, title quality, and importance range. Scores are tracked per-function and exposed via `/health`.
402
+
403
+ ### Self-correction
404
+
405
+ When LLM output fails Zod validation, agentmemory retries with a stricter prompt explaining the exact errors. This recovers from malformed JSON, missing fields, and out-of-range values.
406
+
407
+ ### Circuit breaker + fallback chain
408
+
409
+ ```
410
+ Primary provider fails
411
+ -> Circuit breaker opens (3 failures in 60s)
412
+ -> Falls back to next provider in FALLBACK_PROVIDERS chain
413
+ -> 30s cooldown -> half-open -> test call -> recovery
414
+ ```
415
+
416
+ Configure with `FALLBACK_PROVIDERS=anthropic,gemini,openrouter`. When all providers are down, observations are stored raw without compression. No data is lost.
417
+
418
+ ### Health monitor
419
+
420
+ Collects every 30 seconds: heap usage, CPU percentage (delta sampling), event loop lag, connection state. Alerts at warning (80% CPU, 100ms lag) and critical (90% CPU, 500ms lag) thresholds. `GET /agentmemory/health` returns HTTP 503 when critical.
421
+
422
+ ## MCP Server
423
+
424
+ ### Tools (38)
425
+
426
+ | Tool | Description |
427
+ |------|-------------|
428
+ | `memory_recall` | Search past observations by keyword |
429
+ | `memory_save` | Save an insight, decision, or pattern |
430
+ | `memory_file_history` | Get past observations about specific files |
431
+ | `memory_patterns` | Detect recurring patterns across sessions |
432
+ | `memory_sessions` | List recent sessions with status |
433
+ | `memory_smart_search` | Hybrid semantic + keyword search with progressive disclosure |
434
+ | `memory_timeline` | Chronological observations around an anchor point |
435
+ | `memory_profile` | Project profile with top concepts, files, patterns |
436
+ | `memory_export` | Export all memory data as JSON |
437
+ | `memory_relations` | Query memory relationship graph (with confidence filtering) |
438
+ | `memory_claude_bridge_sync` | Sync memory to/from Claude Code's native MEMORY.md |
439
+ | `memory_graph_query` | Query the knowledge graph for entities and relationships |
440
+ | `memory_consolidate` | Run 4-tier memory consolidation pipeline |
441
+ | `memory_team_share` | Share a memory or observation with team members |
442
+ | `memory_team_feed` | Get recent shared items from all team members |
443
+ | `memory_audit` | View the audit trail of memory operations |
444
+ | `memory_governance_delete` | Delete specific memories with audit trail |
445
+ | `memory_snapshot_create` | Create a git-versioned snapshot of memory state |
446
+ | `memory_action_create` | Create actionable work items with typed dependencies |
447
+ | `memory_action_update` | Update action status, priority, or details |
448
+ | `memory_frontier` | Get unblocked actions ranked by priority and urgency |
449
+ | `memory_next` | Get the single most important next action |
450
+ | `memory_lease` | Acquire, release, or renew exclusive action leases |
451
+ | `memory_routine_run` | Instantiate a frozen workflow routine into action chains |
452
+ | `memory_signal_send` | Send threaded messages between agents |
453
+ | `memory_signal_read` | Read messages for an agent with read receipts |
454
+ | `memory_checkpoint` | Create or resolve external condition gates (CI, approval, deploy) |
455
+ | `memory_mesh_sync` | Sync memories and actions with peer instances |
456
+ | `memory_sentinel_create` | Create event-driven condition watchers |
457
+ | `memory_sentinel_trigger` | Externally fire a sentinel to unblock gated actions |
458
+ | `memory_sketch_create` | Create ephemeral action graphs for exploratory work |
459
+ | `memory_sketch_promote` | Promote sketch actions to permanent actions |
460
+ | `memory_crystallize` | LLM-powered compaction of completed action chains |
461
+ | `memory_diagnose` | Health checks across all subsystems |
462
+ | `memory_heal` | Auto-fix stuck, orphaned, and inconsistent state |
463
+ | `memory_facet_tag` | Attach structured dimension:value tags to targets |
464
+ | `memory_facet_query` | Query targets by facet tags with AND/OR logic |
465
+ | `memory_verify` | Trace a memory's provenance back to source observations and sessions |
466
+
467
+ ### Resources (6)
468
+
469
+ | URI | Description |
470
+ |-----|-------------|
471
+ | `agentmemory://status` | Session count, memory count, health status |
472
+ | `agentmemory://project/{name}/profile` | Per-project intelligence (concepts, files, conventions) |
473
+ | `agentmemory://project/{name}/recent` | Last 5 session summaries for a project |
474
+ | `agentmemory://memories/latest` | Latest 10 active memories (id, title, type, strength) |
475
+ | `agentmemory://graph/stats` | Knowledge graph node and edge counts by type |
476
+ | `agentmemory://team/{id}/profile` | Team memory profile with shared concepts and patterns |
477
+
478
+ ### Prompts (3)
479
+
480
+ | Prompt | Arguments | Description |
481
+ |--------|-----------|-------------|
482
+ | `recall_context` | `task_description` | Searches observations + memories, returns context messages |
483
+ | `session_handoff` | `session_id` | Returns session data + summary for handoff between agents |
484
+ | `detect_patterns` | `project` (optional) | Analyzes recurring patterns across sessions |
485
+
486
+ ### Standalone MCP Server
487
+
488
+ Run agentmemory as a standalone MCP server for any MCP-compatible agent (Cursor, Codex, Gemini CLI, Windsurf):
489
+
490
+ ```bash
491
+ npx agentmemory-mcp
492
+ ```
493
+
494
+ Or add to your agent's MCP config:
495
+
496
+ ```json
497
+ {
498
+ "mcpServers": {
499
+ "agentmemory": {
500
+ "command": "npx",
501
+ "args": ["agentmemory-mcp"]
502
+ }
503
+ }
504
+ }
505
+ ```
506
+
507
+ The standalone server uses in-memory KV with optional JSON persistence (`STANDALONE_PERSIST_PATH`).
508
+
509
+ ### MCP Endpoints (embedded mode)
510
+
511
+ ```http
512
+ GET /agentmemory/mcp/tools — List available tools
513
+ POST /agentmemory/mcp/call — Execute a tool
514
+ GET /agentmemory/mcp/resources — List available resources
515
+ POST /agentmemory/mcp/resources/read — Read a resource by URI
516
+ GET /agentmemory/mcp/prompts — List available prompts
517
+ POST /agentmemory/mcp/prompts/get — Get a prompt with arguments
518
+ ```
519
+
520
+ ## Skills
521
+
522
+ Four slash commands for interacting with memory:
523
+
524
+ | Skill | Usage |
525
+ |-------|-------|
526
+ | `/recall` | Search memory for past context (`/recall auth middleware`) |
527
+ | `/remember` | Save something to long-term memory (`/remember always use jose for JWT`) |
528
+ | `/session-history` | Show recent session summaries |
529
+ | `/forget` | Delete specific observations or entire sessions |
530
+
531
+ ## Real-Time Viewer
532
+
533
+ agentmemory includes a real-time web dashboard that auto-starts on port `3113` (configurable via `III_REST_PORT + 2`).
534
+
535
+ - Live observation stream via WebSocket
536
+ - Session explorer with observation details
537
+ - Memory browser with search and filtering
538
+ - Knowledge graph visualization
539
+ - Health and metrics dashboard
540
+
541
+ Access at `http://localhost:3113` or via `GET /agentmemory/viewer` on the API port. Protected by `AGENTMEMORY_SECRET` when set. CSP headers applied to all HTML responses.
542
+
543
+ ## Configuration
544
+
545
+ ### LLM Providers
546
+
547
+ agentmemory needs an LLM for compressing observations and generating summaries. It auto-detects from your environment.
548
+
549
+ | Provider | Config | Notes |
550
+ |----------|--------|-------|
551
+ | **Claude subscription** (default) | No config needed | Uses `@anthropic-ai/claude-agent-sdk`. Zero cost beyond your Max/Pro plan |
552
+ | **Anthropic API** | `ANTHROPIC_API_KEY` | Direct API access, per-token billing |
553
+ | **Gemini** | `GEMINI_API_KEY` | Also enables Gemini embeddings (free tier) |
554
+ | **OpenRouter** | `OPENROUTER_API_KEY` | Access any model through one API |
555
+
556
+ No API key? agentmemory uses your Claude subscription automatically. Zero config.
557
+
558
+ ### Environment Variables
559
+
560
+ Create `~/.agentmemory/.env`:
561
+
562
+ ```env
563
+ # LLM provider (pick one, or leave empty for Claude subscription)
564
+ ANTHROPIC_API_KEY=sk-ant-...
565
+ # GEMINI_API_KEY=...
566
+ # OPENROUTER_API_KEY=...
567
+
568
+ # Embedding provider (auto-detected from LLM keys, or override)
569
+ # EMBEDDING_PROVIDER=voyage
570
+ # VOYAGE_API_KEY=...
571
+ # OPENAI_API_KEY=...
572
+ # COHERE_API_KEY=...
573
+
574
+ # Hybrid search weights (default: 0.4 BM25 + 0.6 vector)
575
+ # BM25_WEIGHT=0.4
576
+ # VECTOR_WEIGHT=0.6
577
+
578
+ # Provider fallback chain (comma-separated, tried in order)
579
+ # FALLBACK_PROVIDERS=anthropic,gemini,openrouter
580
+
581
+ # Bearer token for API auth
582
+ # AGENTMEMORY_SECRET=your-secret-here
583
+
584
+ # Engine connection
585
+ # III_ENGINE_URL=ws://localhost:49134
586
+ # III_REST_PORT=3111
587
+ # III_STREAMS_PORT=3112
588
+ # Viewer runs on III_REST_PORT + 2 (default: 3113)
589
+
590
+ # Memory tuning
591
+ # TOKEN_BUDGET=2000
592
+ # MAX_OBS_PER_SESSION=500
593
+
594
+ # Claude Code Memory Bridge (v0.5.0)
595
+ # CLAUDE_MEMORY_BRIDGE=false
596
+ # CLAUDE_MEMORY_LINE_BUDGET=200
597
+
598
+ # Standalone MCP Server (v0.5.0)
599
+ # STANDALONE_MCP=false
600
+ # STANDALONE_PERSIST_PATH=~/.agentmemory/standalone.json
601
+
602
+ # Knowledge Graph (v0.5.0)
603
+ # GRAPH_EXTRACTION_ENABLED=false
604
+ # GRAPH_EXTRACTION_BATCH_SIZE=10
605
+
606
+ # Consolidation Pipeline (v0.5.0)
607
+ # CONSOLIDATION_ENABLED=false
608
+ # CONSOLIDATION_DECAY_DAYS=30
609
+
610
+ # Team Memory (v0.5.0)
611
+ # TEAM_ID=
612
+ # USER_ID=
613
+ # TEAM_MODE=private
614
+
615
+ # Git Snapshots (v0.5.0)
616
+ # SNAPSHOT_ENABLED=false
617
+ # SNAPSHOT_INTERVAL=3600
618
+ # SNAPSHOT_DIR=~/.agentmemory/snapshots
619
+ ```
620
+
621
+ ## API
622
+
623
+ 106 endpoints on port `3111` (100 core + 6 MCP protocol). Protected endpoints require `Authorization: Bearer <secret>` when `AGENTMEMORY_SECRET` is set. The table below shows a representative subset; see `src/triggers/api.ts` for the full endpoint list.
624
+
625
+ | Method | Path | Description |
626
+ |--------|------|-------------|
627
+ | `GET` | `/agentmemory/health` | Health check with metrics (always public) |
628
+ | `GET` | `/agentmemory/livez` | Liveness probe (always public) |
629
+ | `POST` | `/agentmemory/session/start` | Start session + get context |
630
+ | `POST` | `/agentmemory/session/end` | Mark session complete |
631
+ | `POST` | `/agentmemory/observe` | Capture observation |
632
+ | `POST` | `/agentmemory/context` | Generate context |
633
+ | `POST` | `/agentmemory/search` | Search observations (BM25) |
634
+ | `POST` | `/agentmemory/smart-search` | Hybrid search with progressive disclosure |
635
+ | `POST` | `/agentmemory/summarize` | Generate session summary |
636
+ | `POST` | `/agentmemory/remember` | Save to long-term memory |
637
+ | `POST` | `/agentmemory/forget` | Delete observations/sessions |
638
+ | `POST` | `/agentmemory/consolidate` | Merge duplicate observations |
639
+ | `POST` | `/agentmemory/patterns` | Detect recurring patterns |
640
+ | `POST` | `/agentmemory/generate-rules` | Generate CLAUDE.md rules from patterns |
641
+ | `POST` | `/agentmemory/file-context` | Get file-specific history |
642
+ | `POST` | `/agentmemory/enrich` | Unified enrichment (file context + memories + bugs) |
643
+ | `POST` | `/agentmemory/evict` | Evict stale memories (`?dryRun=true`) |
644
+ | `POST` | `/agentmemory/migrate` | Import from SQLite |
645
+ | `POST` | `/agentmemory/timeline` | Chronological observations around anchor |
646
+ | `POST` | `/agentmemory/relations` | Create memory relationship (with confidence) |
647
+ | `POST` | `/agentmemory/evolve` | Evolve memory (new version) |
648
+ | `POST` | `/agentmemory/auto-forget` | Run auto-forget (`?dryRun=true`) |
649
+ | `POST` | `/agentmemory/import` | Import data from JSON |
650
+ | `GET` | `/agentmemory/profile` | Project profile (`?project=/path`) |
651
+ | `GET` | `/agentmemory/export` | Export all data as JSON |
652
+ | `GET` | `/agentmemory/sessions` | List all sessions |
653
+ | `GET` | `/agentmemory/observations` | Session observations (`?sessionId=X`) |
654
+ | `GET` | `/agentmemory/viewer` | Real-time web viewer (also at `http://localhost:3113`) |
655
+ | `GET` | `/agentmemory/claude-bridge/read` | Read Claude Code native MEMORY.md |
656
+ | `POST` | `/agentmemory/claude-bridge/sync` | Sync memories to MEMORY.md |
657
+ | `POST` | `/agentmemory/graph/query` | Query knowledge graph (BFS traversal) |
658
+ | `GET` | `/agentmemory/graph/stats` | Knowledge graph node/edge counts |
659
+ | `POST` | `/agentmemory/graph/extract` | Extract entities from observations |
660
+ | `POST` | `/agentmemory/consolidate-pipeline` | Run 4-tier consolidation pipeline |
661
+ | `POST` | `/agentmemory/team/share` | Share memory with team members |
662
+ | `GET` | `/agentmemory/team/feed` | Recent shared items from team |
663
+ | `GET` | `/agentmemory/team/profile` | Aggregated team memory profile |
664
+ | `GET` | `/agentmemory/audit` | Query audit trail (`?operation=X&limit=N`) |
665
+ | `DELETE` | `/agentmemory/governance/memories` | Delete specific memories with audit |
666
+ | `POST` | `/agentmemory/governance/bulk-delete` | Bulk delete by type/date/quality |
667
+ | `GET` | `/agentmemory/snapshots` | List git snapshots |
668
+ | `POST` | `/agentmemory/snapshot/create` | Create git-versioned snapshot |
669
+ | `POST` | `/agentmemory/snapshot/restore` | Restore from snapshot commit |
670
+ | `GET` | `/agentmemory/mcp/tools` | List MCP tools |
671
+ | `POST` | `/agentmemory/mcp/call` | Execute MCP tool |
672
+ | `GET` | `/agentmemory/mcp/resources` | List MCP resources |
673
+ | `POST` | `/agentmemory/mcp/resources/read` | Read MCP resource by URI |
674
+ | `GET` | `/agentmemory/mcp/prompts` | List MCP prompts |
675
+ | `POST` | `/agentmemory/mcp/prompts/get` | Get MCP prompt with arguments |
676
+
677
+ ## Plugin Install
678
+
679
+ ### From Marketplace (recommended)
680
+
681
+ ```bash
682
+ /plugin marketplace add rohitg00/agentmemory
683
+ /plugin install agentmemory
684
+ ```
685
+
686
+ Restart Claude Code. All 12 hooks, 4 skills, and 41 MCP tools are registered automatically.
687
+
688
+ ### Plugin Commands
689
+
690
+ ```bash
691
+ /plugin install agentmemory # Install
692
+ /plugin disable agentmemory # Disable without uninstalling
693
+ /plugin enable agentmemory # Re-enable
694
+ /plugin uninstall agentmemory # Remove
695
+ ```
696
+
697
+ ## Architecture
698
+
699
+ agentmemory is built on iii-engine's three primitives:
700
+
701
+ | What you'd normally need | What agentmemory uses |
702
+ |---|---|
703
+ | Express.js / Fastify | iii HTTP Triggers |
704
+ | SQLite / Postgres + pgvector | iii KV State + in-memory vector index |
705
+ | SSE / Socket.io | iii Streams (WebSocket) |
706
+ | pm2 / systemd | iii-engine worker management |
707
+ | Prometheus / Grafana | iii OTEL + built-in health monitor |
708
+ | Redis (circuit breaker) | In-process circuit breaker + fallback chain |
709
+
710
+ **105+ source files. ~16,000 LOC. 573 tests. Zero external DB dependencies.**
711
+
712
+ ### Functions (52)
713
+
714
+ | Function | Purpose |
715
+ |----------|---------|
716
+ | `mem::observe` | Store raw observation with dedup check |
717
+ | `mem::compress` | LLM compression with validation + quality scoring + embedding |
718
+ | `mem::search` | BM25-ranked full-text search |
719
+ | `mem::smart-search` | Hybrid search with progressive disclosure |
720
+ | `mem::context` | Build session context within token budget |
721
+ | `mem::summarize` | Generate validated session summaries |
722
+ | `mem::remember` | Save to long-term memory (auto-supersedes similar) |
723
+ | `mem::forget` | Delete observations, sessions, or memories |
724
+ | `mem::file-index` | File-specific observation lookup |
725
+ | `mem::consolidate` | Merge duplicate observations |
726
+ | `mem::patterns` | Detect recurring patterns |
727
+ | `mem::generate-rules` | Generate CLAUDE.md rules from patterns |
728
+ | `mem::migrate` | Import from SQLite |
729
+ | `mem::evict` | Age + importance + cap-based memory eviction |
730
+ | `mem::relate` | Create relationship between memories |
731
+ | `mem::evolve` | Create new version of a memory |
732
+ | `mem::get-related` | Traverse memory relationship graph |
733
+ | `mem::timeline` | Chronological observations around anchor |
734
+ | `mem::profile` | Aggregate project profile |
735
+ | `mem::auto-forget` | TTL expiry + contradiction detection |
736
+ | `mem::enrich` | Unified enrichment (file context + observations + bug memories) |
737
+ | `mem::export` / `mem::import` | Full JSON round-trip (v0.3.0 + v0.4.0 + v0.5.0 formats) |
738
+ | `mem::claude-bridge-read` | Read Claude Code native MEMORY.md |
739
+ | `mem::claude-bridge-sync` | Sync top memories back to MEMORY.md |
740
+ | `mem::graph-extract` | LLM-powered entity extraction from observations |
741
+ | `mem::graph-query` | BFS traversal of knowledge graph |
742
+ | `mem::graph-stats` | Node/edge counts by type |
743
+ | `mem::consolidate-pipeline` | 4-tier memory consolidation with strength decay |
744
+ | `mem::team-share` | Share memory/observation with team namespace |
745
+ | `mem::team-feed` | Fetch recent shared items from team |
746
+ | `mem::team-profile` | Aggregate team concepts, files, patterns |
747
+ | `mem::governance-delete` | Delete specific memories with audit trail |
748
+ | `mem::governance-bulk` | Bulk delete by type/date/quality filter |
749
+ | `mem::snapshot-create` | Git commit memory state |
750
+ | `mem::snapshot-list` | List all snapshots |
751
+ | `mem::snapshot-restore` | Restore memory from snapshot commit |
752
+ | `mem::action-create` / `action-update` | Dependency-aware work items with typed edges |
753
+ | `mem::frontier` / `mem::next` | Priority-ranked unblocked action queue |
754
+ | `mem::lease-acquire` / `release` / `renew` | TTL-based atomic agent claims |
755
+ | `mem::routine-create` / `run` / `status` | Frozen workflow templates instantiated into action chains |
756
+ | `mem::signal-send` / `read` / `threads` | Threaded inter-agent messaging with read receipts |
757
+ | `mem::checkpoint-create` / `resolve` | External condition gates (CI, approval, deploy) |
758
+ | `mem::flow-compress` | LLM-powered summarization of completed action chains |
759
+ | `mem::mesh-register` / `sync` / `receive` | P2P sync between agentmemory instances |
760
+ | `mem::detect-worktree` / `branch-sessions` | Git worktree detection for shared memory |
761
+ | `mem::sentinel-create` / `trigger` / `check` | Event-driven condition watchers (webhook, timer, threshold, pattern, approval) |
762
+ | `mem::sketch-create` / `add` / `promote` / `discard` | Ephemeral action graphs for exploratory work with auto-expiry |
763
+ | `mem::crystallize` / `auto-crystallize` | LLM-powered compaction of completed action chains into crystal digests |
764
+ | `mem::diagnose` / `heal` | Self-diagnosis across 8 categories with auto-fix for stuck/orphaned/stale state |
765
+ | `mem::facet-tag` / `query` / `stats` | Multi-dimensional tagging with AND/OR queries on actions, memories, observations |
766
+ | `mem::expand-query` | LLM-generated query reformulations for improved recall |
767
+ | `mem::sliding-window` | Context-window enrichment at ingestion (resolve pronouns, abbreviations) |
768
+ | `mem::temporal-graph` | Append-only versioned edges with point-in-time queries |
769
+ | `mem::retention-score` / `evict` | Ebbinghaus-inspired decay with tiered storage (hot/warm/cold/evictable) |
770
+ | `mem::graph-retrieval` | Entity search + chunk expansion + temporal queries via knowledge graph |
771
+ | `mem::verify` | JIT verification — trace memory provenance back to source observations |
772
+ | `mem::cascade-update` | Propagate staleness to graph nodes, edges, and sibling memories |
773
+
774
+ ### Data Model (33 KV scopes)
775
+
776
+ | Scope | Stores |
777
+ |-------|--------|
778
+ | `mem:sessions` | Session metadata, project, timestamps |
779
+ | `mem:obs:{session_id}` | Compressed observations with embeddings |
780
+ | `mem:summaries` | End-of-session summaries |
781
+ | `mem:memories` | Long-term memories (versioned, with relationships) |
782
+ | `mem:relations` | Memory relationship graph |
783
+ | `mem:profiles` | Aggregated project profiles |
784
+ | `mem:emb:{obs_id}` | Vector embeddings |
785
+ | `mem:index:bm25` | Persisted BM25 index |
786
+ | `mem:metrics` | Per-function metrics |
787
+ | `mem:health` | Health snapshots |
788
+ | `mem:config` | Runtime configuration overrides |
789
+ | `mem:confidence` | Confidence scores for memories |
790
+ | `mem:claude-bridge` | Claude Code MEMORY.md bridge state |
791
+ | `mem:graph:nodes` | Knowledge graph entities |
792
+ | `mem:graph:edges` | Knowledge graph relationships |
793
+ | `mem:semantic` | Semantic memories (consolidated facts) |
794
+ | `mem:procedural` | Procedural memories (extracted workflows) |
795
+ | `mem:team:{id}:shared` | Team shared items |
796
+ | `mem:team:{id}:users:{uid}` | Per-user team state |
797
+ | `mem:team:{id}:profile` | Aggregated team profile |
798
+ | `mem:audit` | Audit trail for all operations |
799
+ | `mem:actions` | Dependency-aware work items |
800
+ | `mem:action-edges` | Typed edges (requires, unlocks, gated_by, etc.) |
801
+ | `mem:leases` | TTL-based agent work claims |
802
+ | `mem:routines` | Frozen workflow templates |
803
+ | `mem:routine-runs` | Instantiated routine execution tracking |
804
+ | `mem:signals` | Inter-agent messages with threading |
805
+ | `mem:checkpoints` | External condition gates |
806
+ | `mem:mesh` | Registered P2P sync peers |
807
+ | `mem:sentinels` | Event-driven condition watchers |
808
+ | `mem:sketches` | Ephemeral action graphs |
809
+ | `mem:crystals` | Compacted action chain digests |
810
+ | `mem:facets` | Multi-dimensional tags |
811
+
812
+ ## Development
813
+
814
+ ```bash
815
+ npm run dev # Hot reload
816
+ npm run build # Production build (365KB)
817
+ npm test # Unit tests (573 tests, ~1.5s)
818
+ npm run test:integration # API tests (requires running services)
819
+ ```
820
+
821
+ ### Prerequisites
822
+
823
+ - Node.js >= 18
824
+ - Docker
825
+
826
+ ## License
827
+
828
+ [Apache-2.0](LICENSE)