toon-memory 2.2.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
@@ -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
 
@@ -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
@@ -818,7 +880,8 @@ toon-memory/
818
880
  │ ├── lib/
819
881
  │ │ ├── lock.ts # Advisory file lock + atomic write
820
882
  │ │ ├── sessions.ts # Multi-session coordination
821
- │ │ └── graph.ts # Memory graph (parse, build, graph recall)
883
+ │ │ ├── graph.ts # Memory graph (parse, build, BM25, centrality, compact render)
884
+ │ │ └── vocab.ts # Project-vocabulary discovery from dependencies
822
885
  │ └── memory.ts # Custom tool (OpenCode)
823
886
  ├── tests/
824
887
  │ ├── cli.test.ts # CLI tests