toon-memory 2.1.0 → 2.3.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
@@ -18,6 +18,7 @@
18
18
  - [Supported Agents](#supported-agents)
19
19
  - [MCP Tools](#mcp-tools)
20
20
  - [Coordinación multi-sesión](#coordinación-multi-sesión)
21
+ - [Memory Graph (recall basado en grafo)](#memory-graph-recall-basado-en-grafo)
21
22
  - [Tips & Best Practices](#tips--best-practices)
22
23
  - [CLI Commands](#cli-commands)
23
24
  - [Configuration](#configuration)
@@ -74,9 +75,13 @@ Read [How toon-memory Makes Your AI Agent Smarter](https://luiggival08.github.io
74
75
  - **Encryption** — AES-256-GCM encryption for sensitive data
75
76
  - **Watch mode** — Auto-backup every N minutes
76
77
  - **Memory TTL** — Configurable per-entry expiration (7d, 30d, or exact dates)
77
- - **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)
78
79
  - **Memory diff** — See what changed since your last session
79
80
  - **Related entries** — Auto-suggest related memories when saving
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
80
85
 
81
86
  ---
82
87
 
@@ -151,8 +156,8 @@ memory_remember # Save important decisions
151
156
 
152
157
  | Tool | Description |
153
158
  |------|-------------|
154
- | `memory_remember` | Save a decision, pattern, bug, or knowledge (with optional TTL and auto-tag inference) |
155
- | `memory_recall` | Search memory (use BEFORE reading files, filters expired TTL entries) |
159
+ | `memory_remember` | Save a decision, pattern, bug, or knowledge (optional TTL, auto-tag inference, and `links` to build the memory graph) |
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 |
156
161
  | `memory_forget` | Remove an entry by key or id |
157
162
  | `memory_stats` | View memory state (including TTL stats) |
158
163
  | `memory_summary` | Save/retrieve file summaries |
@@ -222,7 +227,7 @@ memory_remember({
222
227
  // 🏷️ Tags inferidos: redis
223
228
  ```
224
229
 
225
- > **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`.
226
231
 
227
232
  #### Search memory
228
233
 
@@ -354,6 +359,117 @@ memory_sessions({ conflictsOnly: false })
354
359
 
355
360
  ---
356
361
 
362
+ ## Memory Graph (recall basado en grafo)
363
+
364
+ When your memory grows, a flat keyword search can return either too much (every match) or the wrong context (no relationships). toon-memory can treat memory as a **lightweight knowledge graph** so recall returns the *right* entries with fewer tokens.
365
+
366
+ It's fully **deterministic and offline** — no embeddings, no vector DB, no LLM, no server. Edges come from two sources:
367
+
368
+ - **Explicit `links`** — keys you declare when saving an entry.
369
+ - **Implicit `[[key]]` refs** — any `[[some-key]]` mention inside the content.
370
+
371
+ ### How it works
372
+
373
+ 1. `memory_remember` stores `links` on the entry (space- or `;`-separated keys).
374
+ 2. `memory_recall({ mode: "graph" })` finds keyword matches (seeds), then expands the **ego-subgraph** up to `hops` (1 or 2) along the edges.
375
+ 3. Relevance propagates from the seeds to their neighbors, so a related decision or spec surfaces even if it doesn't contain the query word.
376
+ 4. The result set is capped (`limit`, default 6) → **smaller, more precise context** for the agent.
377
+
378
+ ### Remember with links
379
+
380
+ ```typescript
381
+ memory_remember({
382
+ category: "decision",
383
+ key: "risk-engine-priority",
384
+ content: "The engine prioritizes risk over speed (see [[risk-spec]]).",
385
+ file: "spec.md:10",
386
+ tags: "risk;spec",
387
+ links: "engine-arch" // explicit edge to another entry
388
+ })
389
+ // 🧠 Guardado: decision/risk-engine-priority (a1b2c3d4)
390
+ ```
391
+
392
+ ### Recall with graph mode
393
+
394
+ ```typescript
395
+ memory_recall({ query: "riesgo", mode: "graph", hops: 2 })
396
+ // [decision] risk-engine-priority (a1b2c3d4)
397
+ // The engine prioritizes risk over speed (see [[risk-spec]]).
398
+ // File: spec.md:10 | Tags: risk;spec | Date: 2026-07-01
399
+ // links: engine-arch
400
+ //
401
+ // [knowledge] risk-spec (a2b3c4d5)
402
+ // Risk specification for the engine.
403
+ // links: risk-engine-priority;engine-arch
404
+ //
405
+ // [pattern] engine-arch (e6f7g8h9)
406
+ // Engine architecture.
407
+ // links: risk-spec
408
+ ```
409
+
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.
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
+
471
+ ---
472
+
357
473
  ## Tips & Best Practices
358
474
 
359
475
  Here are some patterns that work well with toon-memory:
@@ -624,10 +740,10 @@ Add to `~/.config/zed/settings.json`:
624
740
 
625
741
  ```
626
742
  version: 1
627
- entries[3|]{id|category|key|content|file|tags|date|ttl}:
628
- a1b2c3d4|decision|use-zod|Use Zod for validation|src/types.ts|validation;types|2026-07-10|
629
- e5f6g7h8|pattern|pydantic-configs|Project uses Pydantic v2|config.py|python;patterns|2026-07-10|
630
- i9j0k1l2|bug|redis-pool-fix|Added max_connections=20|redis.ts|redis;fix|2026-07-10|7d
743
+ entries[3|]{id|category|key|content|file|tags|date|ttl|accessed|links}:
744
+ a1b2c3d4|decision|use-zod|Use Zod for validation|src/types.ts|validation;types|2026-07-10||0|
745
+ e5f6g7h8|pattern|pydantic-configs|Project uses Pydantic v2|config.py|python;patterns|2026-07-10||0|
746
+ i9j0k1l2|bug|redis-pool-fix|Added max_connections=20 (see [[use-zod]])|redis.ts|redis;fix|2026-07-10|7d|0|use-zod
631
747
  summaries:
632
748
  src/services/redis.ts: Redis connection pool with retry logic
633
749
  ```
@@ -760,11 +876,18 @@ toon-memory/
760
876
  │ │ ├── setup.ts # CLI commands
761
877
  │ │ └── toon-memory.ts # CLI runner
762
878
  │ ├── mcp/
763
- │ │ └── server.ts # MCP server (11 tools + 3 resources)
879
+ │ │ └── server.ts # MCP server (13 tools + 3 resources)
880
+ │ ├── lib/
881
+ │ │ ├── lock.ts # Advisory file lock + atomic write
882
+ │ │ ├── sessions.ts # Multi-session coordination
883
+ │ │ ├── graph.ts # Memory graph (parse, build, BM25, centrality, compact render)
884
+ │ │ └── vocab.ts # Project-vocabulary discovery from dependencies
764
885
  │ └── memory.ts # Custom tool (OpenCode)
765
886
  ├── tests/
766
887
  │ ├── cli.test.ts # CLI tests
767
- │ └── memory.test.ts # Memory tests
888
+ │ ├── memory.test.ts # Memory tests
889
+ │ ├── sessions.test.ts # Multi-session tests
890
+ │ └── graph.test.ts # Memory graph tests
768
891
  ├── .github/workflows/
769
892
  │ ├── ci.yml # CI (Node.js 20/22)
770
893
  │ └── publish.yml # Auto-publish on release