@agentmemory/agentmemory 0.9.21 → 0.9.22

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 (47) hide show
  1. package/README.md +150 -7
  2. package/dist/cli.d.mts +5 -1
  3. package/dist/cli.d.mts.map +1 -0
  4. package/dist/cli.mjs +103 -692
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/connect-BQQXpyDS.mjs +763 -0
  7. package/dist/connect-BQQXpyDS.mjs.map +1 -0
  8. package/dist/hooks/post-tool-use.mjs +1 -1
  9. package/dist/hooks/post-tool-use.mjs.map +1 -1
  10. package/dist/hooks/stop.mjs +8 -0
  11. package/dist/hooks/stop.mjs.map +1 -1
  12. package/dist/{image-refs-R3tin9MR.mjs → image-refs-CJS5B9Gq.mjs} +2 -2
  13. package/dist/{image-refs-R3tin9MR.mjs.map → image-refs-CJS5B9Gq.mjs.map} +1 -1
  14. package/dist/{image-store-DyrKZKqZ.mjs → image-store-CdE0amb1.mjs} +1 -1
  15. package/dist/index.mjs +450 -242
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/logger-xlVlvCWX.mjs +43 -0
  18. package/dist/logger-xlVlvCWX.mjs.map +1 -0
  19. package/dist/schema-BkALl7Z_.mjs +74 -0
  20. package/dist/schema-BkALl7Z_.mjs.map +1 -0
  21. package/dist/{src-D5arboxc.mjs → src-gpTAJuBy.mjs} +428 -243
  22. package/dist/src-gpTAJuBy.mjs.map +1 -0
  23. package/dist/{standalone-C7BgzzIN.mjs → standalone-C4i7ktpn.mjs} +18 -6
  24. package/dist/standalone-C4i7ktpn.mjs.map +1 -0
  25. package/dist/standalone.d.mts.map +1 -1
  26. package/dist/standalone.mjs +15 -4
  27. package/dist/standalone.mjs.map +1 -1
  28. package/dist/{tools-registry-CRTWUFw9.mjs → tools-registry-B7Y6nJsr.mjs} +36 -11
  29. package/dist/tools-registry-B7Y6nJsr.mjs.map +1 -0
  30. package/dist/version-DvQMNbEH.mjs +6 -0
  31. package/dist/version-DvQMNbEH.mjs.map +1 -0
  32. package/dist/viewer/index.html +77 -9
  33. package/package.json +6 -4
  34. package/plugin/.claude-plugin/plugin.json +1 -1
  35. package/plugin/.codex-plugin/plugin.json +1 -1
  36. package/plugin/.mcp.json +3 -2
  37. package/plugin/opencode/agentmemory-capture.ts +34 -9
  38. package/plugin/scripts/diagnostics.d.mts +17 -0
  39. package/plugin/scripts/diagnostics.d.mts.map +1 -0
  40. package/plugin/scripts/diagnostics.mjs.map +1 -0
  41. package/plugin/scripts/post-tool-use.mjs +1 -1
  42. package/plugin/scripts/post-tool-use.mjs.map +1 -1
  43. package/plugin/scripts/stop.mjs +8 -0
  44. package/plugin/scripts/stop.mjs.map +1 -1
  45. package/dist/src-D5arboxc.mjs.map +0 -1
  46. package/dist/standalone-C7BgzzIN.mjs.map +0 -1
  47. package/dist/tools-registry-CRTWUFw9.mjs.map +0 -1
package/README.md CHANGED
@@ -73,10 +73,12 @@
73
73
  ## Install
74
74
 
75
75
  ```bash
76
- npm install -g @agentmemory/agentmemory # once — bare `agentmemory` on PATH
77
- agentmemory # start the memory server on :3111
78
- agentmemory demo # seed sample sessions + prove recall
79
- agentmemory connect claude-code # wire your agent (also: codex, cursor, gemini-cli, ...)
76
+ npm install -g @agentmemory/agentmemory # once — bare `agentmemory` on PATH
77
+ # If you hit EACCES on macOS/Linux system Node installs, retry with:
78
+ # sudo npm install -g @agentmemory/agentmemory
79
+ agentmemory # start the memory server on :3111
80
+ agentmemory demo # seed sample sessions + prove recall
81
+ agentmemory connect claude-code # wire your agent (also: codex, cursor, gemini-cli, ...)
80
82
  ```
81
83
 
82
84
  Or via `npx` (no install):
@@ -208,6 +210,15 @@ npx @agentmemory/agentmemory
208
210
 
209
211
  ### Retrieval Accuracy
210
212
 
213
+ **coding-agent-life-v1** (in-house corpus, sandbox-reproducible)
214
+
215
+ | Adapter | P@5 | R@5 | Top-5 hit rate | p50 latency |
216
+ |---|---|---|---|---|
217
+ | **agentmemory hybrid** | **0.578** | **0.967** | **15 / 15** | 14 ms |
218
+ | grep baseline | 0.267 | 0.967 | 15 / 15 | 0 ms |
219
+
220
+ 100% top-5 hit rate. **2.2×** better precision than the grep baseline on identical input. Full per-type breakdown: [`docs/benchmarks/2026-05-20-coding-agent-life-v1.md`](docs/benchmarks/2026-05-20-coding-agent-life-v1.md).
221
+
211
222
  **LongMemEval-S** (ICLR 2025, 500 questions)
212
223
 
213
224
  | System | R@5 | R@10 | MRR |
@@ -233,6 +244,10 @@ npx @agentmemory/agentmemory
233
244
 
234
245
  > Embedding model: `all-MiniLM-L6-v2` (local, free, no API key). Full reports: [`benchmark/LONGMEMEVAL.md`](benchmark/LONGMEMEVAL.md), [`benchmark/QUALITY.md`](benchmark/QUALITY.md), [`benchmark/SCALE.md`](benchmark/SCALE.md). Competitor comparison: [`benchmark/COMPARISON.md`](benchmark/COMPARISON.md) — agentmemory vs mem0, Letta, Khoj, claude-mem, Hippo.
235
246
 
247
+ **Reproduce locally:** [`eval/README.md`](eval/README.md) — adapter-pluggable harness for LongMemEval `_s` (public 500-Q) + `coding-agent-life-v1` (in-house 15-session corpus). Grep / vector / agentmemory adapters score side-by-side, NDJSON output, published scorecards land in [`docs/benchmarks/`](docs/benchmarks/).
248
+
249
+ **Pairs with [codegraph](https://github.com/colbymchenry/codegraph), [Understand Anything](https://github.com/Lum1104/Understand-Anything), and [Graphify](https://github.com/safishamsi/graphify).** Code-graph indexing, multi-agent build pipelines, and broader knowledge graphs across docs / PDFs / images / videos. agentmemory remembers the work; those three projects light up the rest of the context layer. Recipes + question-routing table: [`docs/recipes/pairings.md`](docs/recipes/pairings.md).
250
+
236
251
  ---
237
252
 
238
253
  <h2 id="vs-competitors"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/tags/light/section-competitors.svg"><img src="assets/tags/section-competitors.svg" alt="vs Competitors" height="32" /></picture></h2>
@@ -350,6 +365,8 @@ Open `http://localhost:3113` to watch the memory build live.
350
365
 
351
366
  ```bash
352
367
  npm install -g @agentmemory/agentmemory
368
+ # If you hit EACCES on macOS/Linux system Node installs, retry with:
369
+ # sudo npm install -g @agentmemory/agentmemory
353
370
  agentmemory # start the server (same as the npx form)
354
371
  agentmemory stop # tear it down
355
372
  agentmemory remove # uninstall everything we created
@@ -400,6 +417,19 @@ Implementation details live in `src/cli.ts` (see `runUpgrade` around the `src/cl
400
417
  Install agentmemory: run `npx @agentmemory/agentmemory` in a separate terminal to start the memory server. Then run `/plugin marketplace add rohitg00/agentmemory` and `/plugin install agentmemory` — the plugin registers all 12 hooks, 4 skills, AND auto-wires the `@agentmemory/mcp` stdio server via its `.mcp.json`, so you get 53 MCP tools (memory_smart_search, memory_save, memory_sessions, memory_governance_delete, etc.) without any extra config step. Verify with `curl http://localhost:3111/agentmemory/health`. The real-time viewer is at http://localhost:3113.
401
418
  ```
402
419
 
420
+ #### Claude Code without the plugin install (MCP-standalone path)
421
+
422
+ If you wire agentmemory's MCP server through `~/.claude.json` directly instead of using `/plugin install`, Claude Code never resolves `${CLAUDE_PLUGIN_ROOT}` and you have to point hook scripts at absolute paths in `~/.claude/settings.json`. Those paths typically embed the agentmemory version (e.g. `~/.codex/plugins/cache/agentmemory/agentmemory/0.9.21/scripts/…`), so the next upgrade silently breaks every hook ([#508](https://github.com/rohitg00/agentmemory/issues/508)).
423
+
424
+ Workaround:
425
+
426
+ ```bash
427
+ agentmemory connect claude-code --with-hooks
428
+ ```
429
+
430
+ This merges the same hook commands into `~/.claude/settings.json` with absolute paths resolved to the bundled `plugin/` directory of the currently installed `@agentmemory/agentmemory` package. Re-run the command after upgrading agentmemory to refresh the paths. User entries in the same file are preserved; only previous agentmemory entries are replaced. Using the `/plugin install` path remains the recommended approach.
431
+ For remote or protected deployments, launch Claude Code with `AGENTMEMORY_URL` and `AGENTMEMORY_SECRET` set. The plugin passes both values through to its bundled MCP server; when `AGENTMEMORY_URL` is empty, the MCP shim uses `http://localhost:3111`.
432
+
403
433
  ### Codex CLI (Codex plugin platform)
404
434
 
405
435
  ```bash
@@ -408,7 +438,7 @@ npx @agentmemory/agentmemory
408
438
 
409
439
  # 2. register the agentmemory marketplace and install the plugin
410
440
  codex plugin marketplace add rohitg00/agentmemory
411
- codex plugin install agentmemory
441
+ codex plugin add agentmemory@agentmemory
412
442
  ```
413
443
 
414
444
  The Codex plugin ships from the same `plugin/` directory as the Claude Code plugin. It registers:
@@ -419,6 +449,18 @@ The Codex plugin ships from the same `plugin/` directory as the Claude Code plug
419
449
 
420
450
  Codex's hook engine injects `CLAUDE_PLUGIN_ROOT` into hook subprocesses (per [`codex-rs/hooks/src/engine/discovery.rs`](https://github.com/openai/codex/blob/main/codex-rs/hooks/src/engine/discovery.rs)), so the same hook scripts work across both hosts without duplication. Subagent / SessionEnd / Notification / TaskCompleted / PostToolUseFailure events are Claude-Code-only and are not registered for Codex.
421
451
 
452
+ #### Codex Desktop: plugin hooks currently silent (workaround available)
453
+
454
+ `CodexHooks` and `PluginHooks` are both stable + default-enabled in [`codex-rs/features/src/lib.rs`](https://github.com/openai/codex/blob/main/codex-rs/features/src/lib.rs), but Codex Desktop builds currently do not dispatch plugin-local `hooks.json` ([openai/codex#16430](https://github.com/openai/codex/issues/16430)). MCP tools still work; only the lifecycle observations are missing.
455
+
456
+ Until upstream lands the fix, mirror the same hook commands into the global `~/.codex/hooks.json`:
457
+
458
+ ```bash
459
+ agentmemory connect codex --with-hooks
460
+ ```
461
+
462
+ This adds an idempotent block to `~/.codex/hooks.json` referencing absolute paths to the bundled scripts (no `${CLAUDE_PLUGIN_ROOT}` expansion needed at user-scope). Re-run the same command after upgrading agentmemory to refresh paths. User entries in the same file are preserved; only previous agentmemory entries are replaced.
463
+
422
464
  <details>
423
465
  <summary><b>OpenClaw (paste this prompt)</b></summary>
424
466
 
@@ -493,11 +535,14 @@ The agentmemory entry is the **same MCP server block** across every host that us
493
535
  | **Gemini CLI** | `~/.gemini/settings.json` | `gemini mcp add agentmemory npx -y @agentmemory/mcp --scope user` (auto-merges). |
494
536
  | **OpenClaw** | OpenClaw MCP config | Same `mcpServers` block, or use the deeper [memory plugin](integrations/openclaw/). |
495
537
  | **Codex CLI (MCP only)** | `.codex/config.toml` | TOML shape: `codex mcp add agentmemory -- npx -y @agentmemory/mcp`, or add `[mcp_servers.agentmemory]` manually. |
496
- | **Codex CLI (full plugin)** | Codex plugin marketplace | `codex plugin marketplace add rohitg00/agentmemory` then `codex plugin install agentmemory`. Registers MCP + 6 lifecycle hooks (SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, PreCompact, Stop) + 4 skills. |
538
+ | **Codex CLI (full plugin)** | Codex plugin marketplace | `codex plugin marketplace add rohitg00/agentmemory` then `codex plugin add agentmemory@agentmemory`. Registers MCP + 6 lifecycle hooks (SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, PreCompact, Stop) + 4 skills. On Codex Desktop, also run `agentmemory connect codex --with-hooks` until [openai/codex#16430](https://github.com/openai/codex/issues/16430) lands — plugin hooks are currently silent there. |
497
539
  | **OpenCode (MCP only)** | `opencode.json` | Different shape — top-level `mcp` key, command as array: `{"mcp": {"agentmemory": {"type": "local", "command": ["npx", "-y", "@agentmemory/mcp"], "enabled": true}}}`. |
498
540
  | **OpenCode (full plugin)** | `plugin/opencode/` | 22 auto-capture hooks covering session lifecycle, messages, tools, errors. Two slash commands (`/recall`, `/remember`). Copy `plugin/opencode/` into your OpenCode workspace and add the plugin entry to `opencode.json`. See [`plugin/opencode/README.md`](plugin/opencode/README.md) for the full hook table + gap analysis. |
499
541
  | **pi** | `~/.pi/agent/extensions/agentmemory` | Copy [`integrations/pi`](integrations/pi/) and restart pi. |
500
542
  | **Hermes Agent** | `~/.hermes/config.yaml` | Use the deeper [memory provider plugin](integrations/hermes/) with `memory.provider: agentmemory`. |
543
+ | **Qwen Code** | `~/.qwen/settings.json` | `agentmemory connect qwen` writes the standard `mcpServers` block. Hook payload is field-compatible with Claude Code, so the existing 12-hook scripts work without modification — wire them via the `hooks` section in the same `settings.json`. |
544
+ | **Antigravity** (replaces Gemini CLI) | `mcp_config.json` (in Antigravity's User dir) | `agentmemory connect antigravity` writes the standard `mcpServers` block. macOS: `~/Library/Application Support/Antigravity/User/`. Linux: `~/.config/Antigravity/User/`. Use after the 2026-06-18 Gemini CLI sunset. |
545
+ | **Kiro** | `~/.kiro/settings/mcp.json` | `agentmemory connect kiro` writes the user-level config. Workspace overrides go in `.kiro/settings/mcp.json` next to your code. |
501
546
  | **Goose** | Goose MCP settings UI | Same `mcpServers` block. |
502
547
  | **Aider** | n/a | Talk to the REST API directly: `curl -X POST http://localhost:3111/agentmemory/smart-search -d '{"query": "auth"}'`. |
503
548
  | **Any agent (32+)** | n/a | `npx skillkit install agentmemory` auto-detects the host and merges. |
@@ -1036,7 +1081,7 @@ Full registry: [workers.iii.dev](https://workers.iii.dev). Every worker there co
1036
1081
 
1037
1082
  ### LLM Providers
1038
1083
 
1039
- agentmemory auto-detects from your environment. No API key needed if you have a Claude subscription.
1084
+ agentmemory auto-detects from your environment. By default, no LLM calls are made unless you configure a provider or explicitly opt in to the Claude subscription fallback.
1040
1085
 
1041
1086
  | Provider | Config | Notes |
1042
1087
  |----------|--------|-------|
@@ -1047,6 +1092,104 @@ agentmemory auto-detects from your environment. No API key needed if you have a
1047
1092
  | OpenRouter | `OPENROUTER_API_KEY` | Any model |
1048
1093
  | Claude subscription fallback | `AGENTMEMORY_ALLOW_AGENT_SDK=true` | Opt-in only. Spawns `@anthropic-ai/claude-agent-sdk` sessions — used to cause unbounded Stop-hook recursion (#149 follow-up) so it is no longer the default. |
1049
1094
 
1095
+ ### Cost-aware model selection
1096
+
1097
+ Background compression runs on every observation, so model choice meaningfully changes monthly spend. Captured workload data: 635 requests / 888K tokens / 35 hours of active use, run against three OpenRouter models at 2026-05-23 pricing.
1098
+
1099
+ | Tier | Model | Input / 1M | Output / 1M | Cost for the captured 35h | Notes |
1100
+ |------|-------|------------|-------------|---------------------------|-------|
1101
+ | Recommended | `deepseek/deepseek-v4-pro` | $0.435 | $0.87 | ~$0.46 | Solid compression + summarization quality at ~10× lower cost than Sonnet. |
1102
+ | Recommended | `deepseek/deepseek-chat` | $0.27 | $1.10 | ~$0.40 | Older but still fine for compression-only workloads. |
1103
+ | Recommended | `qwen/qwen3-coder` | $0.45 | $1.80 | ~$0.55 | Strong code reasoning if your sessions are heavily code-shaped. |
1104
+ | Premium | `anthropic/claude-sonnet-4.6` | $3.00 | $15.00 | ~$5.02 | High quality but expensive for always-on background work. |
1105
+ | Premium | `openai/gpt-4o` | $2.50 | $10.00 | ~$4.20 | Similar tier to Sonnet. |
1106
+ | Avoid | `anthropic/claude-opus-4.6` | $15.00 | $75.00 | ~$25+ | Reasoning-class model; massive overspend for compression. |
1107
+
1108
+ agentmemory prints a runtime warning when `OPENROUTER_MODEL` matches a premium-tier pattern. Set `AGENTMEMORY_SUPPRESS_COST_WARNING=1` to silence once you've made an informed choice.
1109
+
1110
+ Quality vs cost tradeoff for memory work: compression is a summarization task with relatively loose quality bars (the agent re-reads the summary, not the user). DeepSeek-V4-Pro / Qwen3-Coder land within rounding error of Sonnet on this task while costing ~10× less. Save the premium-tier models for queries you read directly.
1111
+
1112
+ Sources: [OpenRouter pricing for Sonnet 4.6](https://openrouter.ai/anthropic/claude-sonnet-4.6/pricing), [DeepSeek V4 Pro](https://openrouter.ai/deepseek/deepseek-v4-pro), [DeepSeek pricing notes](https://api-docs.deepseek.com/quick_start/pricing/).
1113
+
1114
+ ### Multi-agent memory (`AGENT_ID` + `AGENTMEMORY_AGENT_SCOPE`)
1115
+
1116
+ In multi-agent setups where several roles share one agentmemory server (architect / developer / reviewer / researcher / support-agent), `AGENT_ID` tags every write with the role that made it. `AGENTMEMORY_AGENT_SCOPE` controls whether recall filters by that tag.
1117
+
1118
+ ```env
1119
+ TEAM_ID=company
1120
+ USER_ID=engineering-team
1121
+ AGENT_ID=architect
1122
+ AGENTMEMORY_AGENT_SCOPE=isolated # optional; default "shared"
1123
+ ```
1124
+
1125
+ Two modes:
1126
+
1127
+ | Mode | Tag writes | Filter recall | When to use |
1128
+ |------|------------|---------------|-------------|
1129
+ | `shared` (default) | yes | no | Cross-agent context with audit trail. Architect can see what developer noted, but every row records who said it. |
1130
+ | `isolated` | yes | yes | Strict separation. Architect never sees developer's observations / memories / sessions. |
1131
+
1132
+ What gets tagged when `AGENT_ID` is set: `Session.agentId`, `RawObservation.agentId`, `CompressedObservation.agentId`, `Memory.agentId`. The role flows from `api::session::start` → `mem::observe` → `mem::compress` → KV.
1133
+
1134
+ What gets filtered in isolated mode: `mem::smart-search`, `/agentmemory/memories`, `/agentmemory/observations`, `/agentmemory/sessions`. Each endpoint accepts `?agentId=<role>` to override per-request, and `?agentId=*` to opt out of the env scope entirely. `/memories` also accepts `?includeOrphans=true` to surface pre-AGENT_ID memories whose `agentId` is undefined.
1135
+
1136
+ Per-call override at the SDK / REST layer: every mutating endpoint (`/session/start`, `/remember`) accepts an `agentId` field in the request body that wins over the env. Useful for runtimes routing many roles through one server process.
1137
+
1138
+ When `AGENT_ID` is unset, memory remains unscoped (legacy behavior, no tags, no filters).
1139
+
1140
+ ### Ports
1141
+
1142
+ agentmemory + iii-engine bind four ports by default. If a restart fails with `port in use`, this table tells you which process to look for.
1143
+
1144
+ | Port | Process | Purpose | Env override |
1145
+ |------|---------|---------|--------------|
1146
+ | `3111` | agentmemory | REST API + MCP HTTP + `/agentmemory/health` + `/agentmemory/livez` | `III_REST_PORT` |
1147
+ | `3112` | iii-engine | Internal streams worker (consumed by agentmemory + viewer) | `III_STREAMS_PORT` |
1148
+ | `3113` | agentmemory | Real-time viewer (`http://localhost:3113`) | `AGENTMEMORY_VIEWER_PORT` |
1149
+ | `49134` | iii-engine | WebSocket — workers register here, OTel telemetry flows over it | `III_ENGINE_URL` (full URL, default `ws://localhost:49134`) |
1150
+
1151
+ Stale-process cleanup when ports stay bound after a crashed run:
1152
+
1153
+ ```bash
1154
+ # macOS / Linux — find whatever is on each port and kill it
1155
+ lsof -i :3111,3112,3113,49134
1156
+ pkill -f agentmemory || true
1157
+ pkill -f 'iii ' || true
1158
+
1159
+ # Windows
1160
+ netstat -ano | findstr ":3111 :3112 :3113 :49134"
1161
+ taskkill /F /PID <pid>
1162
+ ```
1163
+
1164
+ `agentmemory stop` reaps both the worker and the engine pidfile cleanly on graceful shutdown (#640, #474). The manual cleanup above is only for the post-crash case where neither pidfile is left behind.
1165
+
1166
+ ### Config File
1167
+
1168
+ Put agentmemory runtime configuration in `~/.agentmemory/.env` instead of exporting variables in every shell. If the viewer shows a setup hint like `export ANTHROPIC_API_KEY=...`, copy it into this file as `ANTHROPIC_API_KEY=...` without the `export` prefix, then restart agentmemory.
1169
+
1170
+ Process environment variables still work and take precedence over values in the file.
1171
+
1172
+ On Windows, the same file lives at `%USERPROFILE%\.agentmemory\.env`:
1173
+
1174
+ ```powershell
1175
+ New-Item -ItemType Directory -Force $HOME\.agentmemory
1176
+ notepad $HOME\.agentmemory\.env
1177
+ ```
1178
+
1179
+ To test with a Claude Code Pro/Max subscription instead of an API key, opt in explicitly:
1180
+
1181
+ ```env
1182
+ AGENTMEMORY_ALLOW_AGENT_SDK=true
1183
+ AGENTMEMORY_AUTO_COMPRESS=true
1184
+ ```
1185
+
1186
+ Turn on graph or consolidation features in the same file if you want them:
1187
+
1188
+ ```env
1189
+ GRAPH_EXTRACTION_ENABLED=true
1190
+ CONSOLIDATION_ENABLED=true
1191
+ ```
1192
+
1050
1193
  ### Environment Variables
1051
1194
 
1052
1195
  Create `~/.agentmemory/.env`:
package/dist/cli.d.mts CHANGED
@@ -1 +1,5 @@
1
- export { };
1
+ //#region src/cli.d.ts
2
+ declare function discoverViewerPort(): Promise<void>;
3
+ //#endregion
4
+ export { discoverViewerPort };
5
+ //# sourceMappingURL=cli.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.mts","names":[],"sources":["../src/cli.ts"],"mappings":";iBAuMsB,kBAAA,CAAA,GAAsB,OAAA"}