toon-memory 2.5.1 → 2.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.
package/README.md CHANGED
@@ -61,7 +61,7 @@ Read [How toon-memory Makes Your AI Agent Smarter](https://luiggival08.github.io
61
61
 
62
62
  ## Features
63
63
 
64
- - **14 MCP tools** — Full memory management via Model Context Protocol, including `memory_smart_recall` (unified recall) and `memory_sessions` for multi-session coordination
64
+ - **20 MCP tools** — Full memory management via Model Context Protocol, including `memory_smart_recall` (unified recall), `memory_sessions` for multi-session coordination, and `context_*` tools for one-call context generation (briefing, diff, focus, health audit, export)
65
65
  - **MCP Resources** — Read memory as context without tool invocations, including a System Primer (auto-generated knowledge map)
66
66
  - **15 agents supported** — OpenCode, VS Code, Claude Code, Cursor, Windsurf, Cline, Continue, Codex CLI, Gemini CLI, Zed, Antigravity, Aider, KiloCode, OpenClaw, Kiro
67
67
  - **Interactive installer** — Select which agents to configure from a menu
@@ -86,6 +86,7 @@ Read [How toon-memory Makes Your AI Agent Smarter](https://luiggival08.github.io
86
86
  - **Quality scoring** — Every entry gets a 0–1 quality score based on structure (tags, links, content specificity, recency); high-quality entries surface first
87
87
  - **Merge-dedup** — Saving with the same `key` merges attributes (union of tags, max confidence, latest date, combined links) instead of overwriting
88
88
  - **Confidence score** — Each entry tracks reliability: user-asserted = 1.0, inferred = 0.65–0.75
89
+ - **Context generation tools** — `context_generate` (full briefing), `context_diff` (incremental), `context_focus` (targeted), `context_health` (audit), `context_export` (markdown) — each replaces 5-6 manual tool calls. Zero LLM, pure deterministic aggregation
89
90
  - **System Primer** — Auto-generated knowledge map exposed as MCP resource; agents load it at session start for instant context
90
91
 
91
92
  ---
@@ -175,6 +176,12 @@ memory_remember # Save important decisions
175
176
  | `memory_captured` | List activity auto-captured by hooks (opt-in) or clear the log |
176
177
  | `memory_consolidate` | Merge-dedup entries: same-key entries are merged (tags union, max confidence, latest date), then exact-content duplicates removed (deterministic, no LLM) |
177
178
  | `memory_sessions` | Show active agent sessions (branch, files, last-seen) and soft conflicts for parallel work |
179
+ | `context_brief` | **One-call context briefing**: memory + sessions + health in compact markdown. Use instead of 5-6 separate memory_* calls. Zero LLM, pure deterministic aggregation |
180
+ | `context_generate` | **Full project briefing**: combines project structure, git state, memory entries, and active sessions in one call. Replaces 5-6 manual tool calls |
181
+ | `context_diff` | **Incremental briefing**: git commits + modified files + new/updated memory + active sessions since last session |
182
+ | `context_focus` | **Hyper-focused briefing**: only relevant memory + related source files + callers + test files for a query |
183
+ | `context_health` | **Memory health audit**: orphan links, duplicates, broken file refs, expired TTL, stale sessions, score 0–100 |
184
+ | `context_export` | **Export memory as markdown**: injectable context for system prompts (full or compact) |
178
185
 
179
186
  ### MCP Resources
180
187
 
@@ -322,6 +329,54 @@ memory_smart_recall({ intent: "diseño de base de datos para backend" })
322
329
 
323
330
  > **Tip:** Use `memory_smart_recall` at the START of every task. It combines BM25 + graph + decay + quality in one call — no need to guess what to search for.
324
331
 
332
+ #### Full project briefing (one call)
333
+
334
+ ```typescript
335
+ context_generate({})
336
+ // # Project Briefing (full)
337
+ //
338
+ // ## Project
339
+ // - Name: my-app
340
+ // - Root: /path/to/project
341
+ // - Package Manager: npm
342
+ // - TypeScript: ✓ (v5.3)
343
+ //
344
+ // ## Git Status
345
+ // - Branch: main
346
+ // - 3 uncommitted, 0 untracked
347
+ //
348
+ // ## Memory (42 entries, 12 patterns, 8 bugs)
349
+ // [1] decision/use-postgres
350
+ // Choose Postgres for ACID compliance
351
+ // tags: db;decision
352
+ //
353
+ // ## Sessions
354
+ // - egraterol (main, 2m ago): 42 files touched
355
+ ```
356
+
357
+ > **Tip:** Use `context_generate` at the start of a session to get full context in one call. Replaces 5-6 separate tool calls.
358
+
359
+ #### Memory health audit
360
+
361
+ ```typescript
362
+ context_health({})
363
+ // # Memory Health (score: 87/100)
364
+ //
365
+ // ## Summary
366
+ // - 42 entries (12 patterns, 8 bugs, 15 decisions, 7 knowledge)
367
+ // - 65.3% average quality
368
+ //
369
+ // ## Issues (3)
370
+ // - Orphan link: pattern/db-migrations → pattern/db-seed (key not found)
371
+ // - Duplicate: [bug] redis-pool-fix has identical content
372
+ // - Expired TTL: [knowledge] sprint-deadline (expired 2026-07-20)
373
+ //
374
+ // ## Stale Files (1)
375
+ // - src/legacy.ts (deleted, 2 refs)
376
+ ```
377
+
378
+ > **Tip:** Run `context_health` when memory feels cluttered. Shows orphan links, duplicates, expired TTL entries, and broken file references.
379
+
325
380
  #### Merge-dedup (automatic)
326
381
 
327
382
  When you save with the same `key`, attributes are merged instead of overwritten:
@@ -893,7 +948,7 @@ TOON (Token-Oriented Object Notation) is designed for LLMs:
893
948
 
894
949
  Measured with `gpt-tokenizer` (cl100k_base) over 16 representative memory entries — see `scripts/benchmark-toon.mjs` (`npm run bench`).
895
950
 
896
- 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).
951
+ 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). The full session benchmark (`npm run bench:full`) shows **80% fewer tool calls** and **47% fewer tokens** with context_* tools.
897
952
 
898
953
  - **22.5% fewer tokens** than JSON at file level (up to 30.5% on a single entry)
899
954
  - **Lossless roundtrip** — No data loss
@@ -941,6 +996,71 @@ memory_recall (graph, compact) ~900 -70%
941
996
  memory_smart_recall ~850 -72%
942
997
  ```
943
998
 
999
+ ### Context tools benchmark (measured)
1000
+
1001
+ The `context_*` tools replace 3–6 separate tool calls with a single call, saving both tokens and tool-call overhead.
1002
+
1003
+ ```
1004
+ Scenario Without With Saved Tools
1005
+ ──────────────────────────────── ──────── ────── ─────── ──────
1006
+ context_generate (full briefing) 5,556 378 93.2% 6 → 1
1007
+ context_diff (incremental) 533 152 71.5% 4 → 1
1008
+ context_focus (targeted) 413 225 45.5% 4 → 1
1009
+ context_health (audit) 322 246 23.6% 5 → 1
1010
+ context_export (injectable md) 1,178 218 81.5% 3 → 1
1011
+ ──────────────────────────────── ──────── ────── ─────── ──────
1012
+ TOTAL 8,002 1,219 84.8% 22 → 5
1013
+ ```
1014
+
1015
+ **What each scenario measures:**
1016
+
1017
+ | Tool | Without (manual path) | With (single call) | Why it saves |
1018
+ |------|----------------------|-------------------|-------------|
1019
+ | `context_generate` | Read `package.json` + `README` + `tsconfig.json` + full memory dump + memory stats + sessions = 6 calls | One compact briefing with everything | Eliminates 5 redundant reads; output is deduplicated and compact |
1020
+ | `context_diff` | `git log` + `git diff --name-only` + `memory_diff` + sessions = 4 calls | One incremental diff | Combines git state + memory changes in one output; no overlap |
1021
+ | `context_focus` | `memory_recall` + `findCallers` + `findRelatedFiles` + `findTestFiles` = 4 calls | One targeted briefing | Only returns what's relevant; no full memory scan needed |
1022
+ | `context_health` | `memory_stats` + orphan scan + duplicate scan + file ref validation + stale sessions = 5 calls | One health report | Each check is done once and deduplicated; no redundant queries |
1023
+ | `context_export` | `memory_stats` + `memory_recall({ compact: true, mode: "graph" })` + manual formatting = 3 calls | One markdown export | Formats output directly; agent skips the "format as markdown" step |
1024
+
1025
+ > **Tip:** Use `context_generate` at session start (93% token savings). Use `context_diff` for "what changed since last time?" (72% savings). Use `context_focus` for deep dives on specific topics (45% savings).
1026
+
1027
+ Measured with `gpt-tokenizer` (cl100k_base) over realistic project scenarios — see `scripts/bench-context-tools.mjs` (`npm run bench:context`).
1028
+
1029
+ ### Full session impact (measured)
1030
+
1031
+ Simulates a complete 5-phase agent session (session start → debug → implement → review → wrap-up) across 3 approaches: without memory, with `memory_recall`, and with `context_*` tools.
1032
+
1033
+ ```
1034
+ Phase Without memory memory_recall context_* tools
1035
+ ────────────────────────────────────── ───────────────── ───────────────── ─────────────────
1036
+ Phase 1: Session Start 516 t / 6 c 409 t / 3 c 373 t / 1 c
1037
+ Phase 2: Debug Issue 176 t / 4 c 182 t / 2 c 252 t / 1 c
1038
+ Phase 3: Implement Feature 189 t / 6 c 183 t / 3 c 305 t / 1 c
1039
+ Phase 4: Code Review 316 t / 4 c 130 t / 2 c 243 t / 1 c
1040
+ Phase 5: Wrap-up 1,214 t / 5 c 68 t / 2 c 117 t / 1 c
1041
+ ────────────────────────────────────── ───────────────── ───────────────── ─────────────────
1042
+ TOTAL 2,411 t / 25 c 972 t / 12 c 1,290 t / 5 c
1043
+ ```
1044
+
1045
+ **Key findings:**
1046
+
1047
+ | Metric | Without memory | With memory_recall | With context_* tools |
1048
+ |--------|---------------|-------------------|---------------------|
1049
+ | Tokens per session | 2,411 | 972 (-60%) | 1,290 (-47%) |
1050
+ | Tool calls per session | 25 | 12 (-52%) | **5 (-80%)** |
1051
+ | Cost per session (GPT-4) | $0.072 | $0.029 | $0.039 |
1052
+
1053
+ **The trade-off:** `memory_recall` uses fewer tokens (972 vs 1,290) because it returns only matching entries. `context_*` tools return **richer context** (callers, related files, test files, health audit) — more tokens per call, but **80% fewer tool calls**. In practice, the agent avoids 3-4 follow-up "find related" calls that `context_focus` already includes.
1054
+
1055
+ **Where context_* wins big:**
1056
+ - **Session start** (Phase 1): 28% fewer tokens + 6→1 calls — one briefing replaces reading 6 files
1057
+ - **Wrap-up** (Phase 5): 90% fewer tokens — `context_health` replaces 5 manual scans
1058
+ - **Tool calls**: 25→5 calls = **80% less latency overhead** per session
1059
+
1060
+ > **Tip:** Use `memory_recall` when you need specific entries (fewer tokens). Use `context_*` when you need comprehensive context with fewer round-trips (fewer calls).
1061
+
1062
+ Measured with `gpt-tokenizer` (cl100k_base) — see `scripts/bench-full-impact.mjs` (`npm run bench:full`).
1063
+
944
1064
  > **Tip:** `memory_smart_recall` combines BM25 + graph + quality in one call, saving both tokens and tool-call overhead. Use it at the start of every task.
945
1065
 
946
1066
  ---
@@ -1035,12 +1155,13 @@ toon-memory/
1035
1155
  │ │ ├── setup.ts # CLI commands
1036
1156
  │ │ └── toon-memory.ts # CLI runner
1037
1157
  │ ├── mcp/
1038
- │ │ └── server.ts # MCP server (14 tools + 3 resources)
1158
+ │ │ └── server.ts # MCP server (20 tools + 3 resources)
1039
1159
  │ ├── lib/
1040
1160
  │ │ ├── lock.ts # Advisory file lock + atomic write
1041
1161
  │ │ ├── sessions.ts # Multi-session coordination
1042
1162
  │ │ ├── graph.ts # Memory graph (parse, build, BM25, centrality, compact render)
1043
1163
  │ │ ├── quality.ts # Quality scoring, merge-dedup, smart recall, system primer
1164
+ │ │ ├── context.ts # Context briefing generator (one-call context)
1044
1165
  │ │ └── vocab.ts # Project-vocabulary discovery from dependencies
1045
1166
  ├── tests/
1046
1167
  │ ├── cli.test.ts # CLI tests