toon-memory 2.2.0 → 2.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,6 +1,6 @@
1
1
  # toon-memory
2
2
 
3
- > Persistent memory for AI coding agents — remember decisions, patterns, and bugs between sessions.
3
+ > MCP memory server for AI coding agents — remember decisions, patterns, and bugs between sessions.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/toon-memory.svg)](https://www.npmjs.com/package/toon-memory)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -75,10 +75,13 @@ Read [How toon-memory Makes Your AI Agent Smarter](https://luiggival08.github.io
75
75
  - **Encryption** — AES-256-GCM encryption for sensitive data
76
76
  - **Watch mode** — Auto-backup every N minutes
77
77
  - **Memory TTL** — Configurable per-entry expiration (7d, 30d, or exact dates)
78
- - **Tag inference** — Auto-detect tags from content when tags are empty
78
+ - **Tag inference** — Auto-detect tags from content when tags are empty (built-in vocabulary + project dependencies)
79
79
  - **Memory diff** — See what changed since your last session
80
80
  - **Related entries** — Auto-suggest related memories when saving
81
81
  - **Memory graph** — Connect entries with `links`/`[[key]]` refs; `memory_recall` can expand a relationship-aware subgraph for more precise, lower-token recall (no embeddings, no LLM)
82
+ - **Token-efficient recall** — `memory_recall({ compact: true })` returns numeric-indexed entries, drops `id`/`date`/`file`, renders graph edges as `->2`, and truncates graph neighbors to snippets
83
+ - **BM25 + centrality ranking** — Recall re-ranks by BM25 relevance and graph centrality (hubs surface even without the query word); per-hop decay keeps distant nodes low
84
+ - **Auto-tag from dependencies** — `toon-memory init` scans `package.json`/`Cargo.toml`/`requirements.txt`/`go.mod` and writes a project vocabulary so entries mentioning a dependency get auto-tagged with it
82
85
 
83
86
  ---
84
87
 
@@ -129,17 +132,17 @@ memory_remember # Save important decisions
129
132
 
130
133
  | Agent | Config Location | Format | Hooks | Auto-Setup |
131
134
  |-------|-----------------|--------|-------|------------|
132
- | **OpenCode** | `.opencode/opencode.json` | JSON | — | ✅ |
135
+ | **OpenCode** | `.opencode/opencode.json` + `.opencode/plugins/toon-memory.ts` | Plugin | SessionStart (plugin, no top-level `hooks`) | ✅ |
133
136
  | **VS Code / Copilot** | `.vscode/mcp.json` | JSON | — | ✅ |
134
- | **Claude Code** | `.claude/settings.json` | JSON | SessionStart | ✅ |
137
+ | **Claude Code** | `.claude/settings.json` | JSON | SessionStart + PostToolUse + Stop | ✅ |
135
138
  | **Cursor** | `.cursor/mcp.json` | JSON | — | ✅ |
136
139
  | **Windsurf** | `~/.codeium/windsurf/mcp_config.json` | JSON | — | ✅ |
137
140
  | **Cline** | `.cline/mcp.json` | JSON | — | ✅ |
138
141
  | **Continue** | `.continue/config.json` | JSON | — | ✅ |
139
- | **Codex CLI** | `.codex/config.toml` | TOML | SessionStart | ✅ |
140
- | **Gemini CLI** | `.gemini/settings.json` | JSON | SessionStart | ✅ |
142
+ | **Codex CLI** | `.codex/config.toml` | TOML | SessionStart + PostToolUse + Stop (`[[hooks]] event=`) | ✅ |
143
+ | **Gemini CLI** | `.gemini/settings.json` | JSON | SessionStart + PostToolUse + Stop (`hooks.*`) | ✅ |
141
144
  | **Zed** | `~/.config/zed/settings.json` | JSONC | — | ✅ |
142
- | **Antigravity** | `.gemini/config/mcp_config.json` | JSON | SessionStart | ✅ |
145
+ | **Antigravity** | `.gemini/config/mcp_config.json` + `.gemini/config/hooks.json` | hooks.json | PreInvocation + PostToolUse + Stop (no SessionStart event) | ✅ |
143
146
  | **Aider** | — | — | — | 📝 Instructions |
144
147
  | **KiloCode** | `~/.kilocode/mcp_settings.json` | JSON | — | ✅ |
145
148
  | **OpenClaw** | `.openclaw.json` | JSON | — | ✅ |
@@ -154,7 +157,7 @@ memory_remember # Save important decisions
154
157
  | Tool | Description |
155
158
  |------|-------------|
156
159
  | `memory_remember` | Save a decision, pattern, bug, or knowledge (optional TTL, auto-tag inference, and `links` to build the memory graph) |
157
- | `memory_recall` | Search memory (use BEFORE reading files, filters expired TTL). `mode: "graph"` expands a relationship-aware subgraph for higher precision |
160
+ | `memory_recall` | Search memory (use BEFORE reading files, filters expired TTL). `mode: "graph"` expands a relationship-aware subgraph for higher precision. `compact: true` returns a token-efficient, numeric-indexed format |
158
161
  | `memory_forget` | Remove an entry by key or id |
159
162
  | `memory_stats` | View memory state (including TTL stats) |
160
163
  | `memory_summary` | Save/retrieve file summaries |
@@ -224,7 +227,7 @@ memory_remember({
224
227
  // 🏷️ Tags inferidos: redis
225
228
  ```
226
229
 
227
- > **Tip:** Leave `tags` empty and the system will infer them from your content using a vocabulary of 20+ categories (redis, auth, api, db, security, etc.).
230
+ > **Tip:** Leave `tags` empty and the system will infer them from your content using a built-in vocabulary of 20+ categories (redis, auth, api, db, security, etc.) **plus** a project vocabulary derived from your dependencies at `init` time. So if your project depends on `redis`, any entry mentioning "redis" gets auto-tagged `redis`.
228
231
 
229
232
  #### Search memory
230
233
 
@@ -406,6 +409,65 @@ memory_recall({ query: "riesgo", mode: "graph", hops: 2 })
406
409
 
407
410
  > **Tip:** Use `mode: "graph"` when a decision ripples across several entries (architecture, specs, related bugs). For isolated facts, the default `flat` mode is enough. The graph is built on read, so there's no extra index file to maintain.
408
411
 
412
+ ### Token-efficient recall (`compact`)
413
+
414
+ When every token counts, pass `compact: true` to get a denser output:
415
+
416
+ ```typescript
417
+ memory_recall({ query: "riesgo", mode: "graph", hops: 2, compact: true })
418
+ // [1] decision/risk-engine-priority
419
+ // The engine prioritizes risk over speed (see [[risk-spec]]).
420
+ // tags: risk;spec · edges: ->2, ->3
421
+ //
422
+ // [2] knowledge/risk-spec
423
+ // Risk specification for the engine.
424
+ // tags: risk · edges: ->1
425
+ //
426
+ // [3] pattern/engine-arch
427
+ // Engine architecture.
428
+ // tags: engine · edges: ->1
429
+ ```
430
+
431
+ How `compact` changes the output:
432
+
433
+ - Each entry gets a stable numeric index (`[1]`, `[2]`, …) in score order.
434
+ - `id`, `date`, and `file` are dropped — only `tags` is kept.
435
+ - In `graph` mode, edges render as `->2` (numeric, not key names).
436
+ - Neighbors reached via the graph (non-seeds) are truncated to a short snippet with an ellipsis, while directly-matched seeds keep their full content.
437
+ - The stored `.toon` file is **never** mutated — `compact` only reshapes the response.
438
+
439
+ > **Tip:** Combine `compact: true` with `mode: "graph"` for the smallest possible context window when recalling from a large, interconnected memory.
440
+
441
+ ### How recall ranks results
442
+
443
+ Recall is deterministic and offline (no embeddings, no LLM). Each candidate entry gets a combined score:
444
+
445
+ - **BM25 relevance** — classic probabilistic term-frequency score against the query, using `id` + `category` + `key` + `content` + `file` + `tags`.
446
+ - **Graph centrality** — degree-normalized (0..1); a hub connected to many entries scores near 1, so it surfaces even without the query word.
447
+ - **Importance** — recency + access frequency (same signal used elsewhere).
448
+ - **Seed bonus** — entries that directly match the query get a flat boost.
449
+ - **Per-hop decay** — nodes `d` hops from a seed are multiplied by `0.5^d`, so distant context ranks below nearby context.
450
+
451
+ In `graph` mode, recall seeds on keyword matches, expands the ego-subgraph up to `hops`, and returns the top `limit` (default 6) by combined score.
452
+
453
+ ### Auto-tag from project dependencies
454
+
455
+ On `toon-memory init`, the CLI scans your dependency manifests and writes a `vocab` table into `.toon-memory/memory/config.json`:
456
+
457
+ ```json
458
+ {
459
+ "vocab": {
460
+ "react": ["react"],
461
+ "zod": ["zod"],
462
+ "redis": ["redis"]
463
+ }
464
+ }
465
+ ```
466
+
467
+ `memory_remember` then matches new entries against this vocabulary on top of the built-in one, so mentioning a dependency in your content auto-attaches its tag. Supported manifests: `package.json`, `Cargo.toml`, `requirements.txt`, `pyproject.toml`, `go.mod`.
468
+
469
+ > **Tip:** Re-run `toon-memory init` after adding major dependencies to refresh the vocabulary. The `vocab` key is merged (never clobbered) with the `encrypted`/`capture` flags in `config.json`.
470
+
409
471
  ---
410
472
 
411
473
  ## Tips & Best Practices
@@ -571,11 +633,17 @@ Press Ctrl+C to stop
571
633
  npx toon-memory
572
634
  ```
573
635
 
574
- The installer will:
575
- 1. Show all 15 supported agents with detection status
576
- 2. Let you select which ones to configure (comma-separated, `all`, or Enter)
577
- 3. Ask for local or global installation scope
578
- 4. Configure MCP server, instruction files, and hooks automatically
636
+ The installer (requires a terminal) will:
637
+ 1. Show all 15 supported agents with detection status (`✓` config found) and their supported scope (`local/global` or `solo local`)
638
+ 2. Let you select which ones to configure — by number (`1,3,5`), by name (`claude,codex`), `all`, Enter for all, or `q` to quit
639
+ 3. Ask for the installation scope: **(1) Local** (project: `.toon-memory` + agent configs in the repo) or **(2) Global** (`~home` configs)
640
+ 4. Show a confirmation summary (`agent → scope → path (MCP/plugin/hooks/instrucciones)`) and ask `¿Proceder? [Y/n]`
641
+ 5. Configure MCP server, instruction files, and hooks automatically
642
+
643
+ > Sin una terminal (CI/pipes) `npx toon-memory` imprime la ayuda de instalación no interactiva. Usa `npx toon-memory init [local|global]` para instalar sin preguntas. Unknown commands print usage and exit with an error.
644
+
645
+
646
+
579
647
 
580
648
  ### OpenCode
581
649
 
@@ -593,6 +661,8 @@ Add to `.opencode/opencode.json` or `~/.config/opencode/opencode.json`:
593
661
  }
594
662
  ```
595
663
 
664
+ > **Hooks are delivered via a plugin**, not a top-level `hooks` key. OpenCode 1.17+ rejects `"Unrecognized key: hooks"` in its config — `toon-memory init` writes `.opencode/plugins/toon-memory.ts` instead. Do not add `hooks` to `opencode.json`.
665
+
596
666
  ### Claude Code
597
667
 
598
668
  Add to `.claude/settings.json`:
@@ -717,6 +787,8 @@ TOON (Token-Oriented Object Notation) is designed for LLMs:
717
787
 
718
788
  Measured with `gpt-tokenizer` (cl100k_base) over 16 representative memory entries — see `scripts/benchmark-toon.mjs` (`npm run bench`).
719
789
 
790
+ The token savings compound at session time: `npm run bench:impact` simulates retrieving context **with vs without** memory and measures ~68% fewer tokens to get the same context (recall `compact` instead of re-reading source files).
791
+
720
792
  - **22.5% fewer tokens** than JSON at file level (up to 30.5% on a single entry)
721
793
  - **Lossless roundtrip** — No data loss
722
794
  - **Better LLM comprehension** — Structured for AI consumption
@@ -818,8 +890,8 @@ toon-memory/
818
890
  │ ├── lib/
819
891
  │ │ ├── lock.ts # Advisory file lock + atomic write
820
892
  │ │ ├── sessions.ts # Multi-session coordination
821
- │ │ └── graph.ts # Memory graph (parse, build, graph recall)
822
- │ └── memory.ts # Custom tool (OpenCode)
893
+ │ │ ├── graph.ts # Memory graph (parse, build, BM25, centrality, compact render)
894
+ │ │ └── vocab.ts # Project-vocabulary discovery from dependencies
823
895
  ├── tests/
824
896
  │ ├── cli.test.ts # CLI tests
825
897
  │ ├── memory.test.ts # Memory tests
@@ -1,8 +1,48 @@
1
1
  #!/usr/bin/env node
2
2
  import { dirname, join } from "path";
3
+ import { readFileSync } from "fs";
3
4
  import { fileURLToPath } from "url";
4
5
  const __dirname = dirname(fileURLToPath(import.meta.url));
5
6
  const args = process.argv.slice(2);
7
+ function getVersion() {
8
+ try {
9
+ const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
10
+ return pkg.version || "unknown";
11
+ } catch {
12
+ return "unknown";
13
+ }
14
+ }
15
+ const HELP = `toon-memory \u2014 MCP memory server for AI coding agents
16
+
17
+ Usage:
18
+ toon-memory <command> [scope]
19
+
20
+ Commands:
21
+ init [local|global] Install memory tools + hooks for detected agents
22
+ status Show version, memory count, and agent config status
23
+ stats Show memory statistics
24
+ export [file] Export memory to a TOON/JSON file
25
+ import <file> Import memory from a TOON/JSON file
26
+ watch Watch memory file and re-render on change
27
+ uninstall Remove toon-memory from all agents
28
+ capture <on|off> Enable/disable activity capture hooks
29
+ upgrade Upgrade to the latest version
30
+
31
+ Options:
32
+ -v, --version Show version
33
+ -h, --help Show this help
34
+
35
+ MCP mode:
36
+ toon-memory mcp Run as an MCP server (stdio)
37
+ `;
38
+ if (args[0] === "-v" || args[0] === "--version") {
39
+ console.log(getVersion());
40
+ process.exit(0);
41
+ }
42
+ if (args[0] === "-h" || args[0] === "--help") {
43
+ console.log(HELP);
44
+ process.exit(0);
45
+ }
6
46
  if (args[0] === "mcp") {
7
47
  await import(join(__dirname, "..", "mcp", "server.js"));
8
48
  } else {