toon-memory 2.3.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)
@@ -132,17 +132,17 @@ memory_remember # Save important decisions
132
132
 
133
133
  | Agent | Config Location | Format | Hooks | Auto-Setup |
134
134
  |-------|-----------------|--------|-------|------------|
135
- | **OpenCode** | `.opencode/opencode.json` | JSON | — | ✅ |
135
+ | **OpenCode** | `.opencode/opencode.json` + `.opencode/plugins/toon-memory.ts` | Plugin | SessionStart (plugin, no top-level `hooks`) | ✅ |
136
136
  | **VS Code / Copilot** | `.vscode/mcp.json` | JSON | — | ✅ |
137
- | **Claude Code** | `.claude/settings.json` | JSON | SessionStart | ✅ |
137
+ | **Claude Code** | `.claude/settings.json` | JSON | SessionStart + PostToolUse + Stop | ✅ |
138
138
  | **Cursor** | `.cursor/mcp.json` | JSON | — | ✅ |
139
139
  | **Windsurf** | `~/.codeium/windsurf/mcp_config.json` | JSON | — | ✅ |
140
140
  | **Cline** | `.cline/mcp.json` | JSON | — | ✅ |
141
141
  | **Continue** | `.continue/config.json` | JSON | — | ✅ |
142
- | **Codex CLI** | `.codex/config.toml` | TOML | SessionStart | ✅ |
143
- | **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.*`) | ✅ |
144
144
  | **Zed** | `~/.config/zed/settings.json` | JSONC | — | ✅ |
145
- | **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) | ✅ |
146
146
  | **Aider** | — | — | — | 📝 Instructions |
147
147
  | **KiloCode** | `~/.kilocode/mcp_settings.json` | JSON | — | ✅ |
148
148
  | **OpenClaw** | `.openclaw.json` | JSON | — | ✅ |
@@ -633,11 +633,17 @@ Press Ctrl+C to stop
633
633
  npx toon-memory
634
634
  ```
635
635
 
636
- The installer will:
637
- 1. Show all 15 supported agents with detection status
638
- 2. Let you select which ones to configure (comma-separated, `all`, or Enter)
639
- 3. Ask for local or global installation scope
640
- 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
+
641
647
 
642
648
  ### OpenCode
643
649
 
@@ -655,6 +661,8 @@ Add to `.opencode/opencode.json` or `~/.config/opencode/opencode.json`:
655
661
  }
656
662
  ```
657
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
+
658
666
  ### Claude Code
659
667
 
660
668
  Add to `.claude/settings.json`:
@@ -779,6 +787,8 @@ TOON (Token-Oriented Object Notation) is designed for LLMs:
779
787
 
780
788
  Measured with `gpt-tokenizer` (cl100k_base) over 16 representative memory entries — see `scripts/benchmark-toon.mjs` (`npm run bench`).
781
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
+
782
792
  - **22.5% fewer tokens** than JSON at file level (up to 30.5% on a single entry)
783
793
  - **Lossless roundtrip** — No data loss
784
794
  - **Better LLM comprehension** — Structured for AI consumption
@@ -882,7 +892,6 @@ toon-memory/
882
892
  │ │ ├── sessions.ts # Multi-session coordination
883
893
  │ │ ├── graph.ts # Memory graph (parse, build, BM25, centrality, compact render)
884
894
  │ │ └── vocab.ts # Project-vocabulary discovery from dependencies
885
- │ └── memory.ts # Custom tool (OpenCode)
886
895
  ├── tests/
887
896
  │ ├── cli.test.ts # CLI tests
888
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 {
package/dist/cli/setup.js CHANGED
@@ -111,19 +111,19 @@ Persistent memory for this project. Use it to avoid re-investigating things.
111
111
  - Save important decisions, bugs resolved, and patterns observed.
112
112
  `;
113
113
  function detectAgents() {
114
- const agents2 = [];
115
- agents2.push({
114
+ const agents = [];
115
+ agents.push({
116
116
  name: "opencode",
117
117
  global: join2(HOME, ".config", "opencode", "opencode.json"),
118
118
  local: join2(projectRoot, ".opencode", "opencode.json"),
119
119
  mcpKey: "mcp",
120
120
  format: "json",
121
- needsHooks: true,
121
+ needsHooks: false,
122
+ needsPlugin: true,
122
123
  needsInstructions: true,
123
- instructionFile: join2(projectRoot, "AGENTS.md"),
124
- captureJson: ["PostToolUse", "Stop"]
124
+ instructionFile: join2(projectRoot, "AGENTS.md")
125
125
  });
126
- agents2.push({
126
+ agents.push({
127
127
  name: "vscode/copilot",
128
128
  local: join2(projectRoot, ".vscode", "mcp.json"),
129
129
  mcpKey: "servers",
@@ -131,7 +131,7 @@ function detectAgents() {
131
131
  needsHooks: false,
132
132
  needsInstructions: false
133
133
  });
134
- agents2.push({
134
+ agents.push({
135
135
  name: "claude",
136
136
  global: join2(HOME, ".claude", "settings.json"),
137
137
  local: join2(projectRoot, ".claude", "settings.json"),
@@ -142,7 +142,7 @@ function detectAgents() {
142
142
  instructionFile: join2(projectRoot, ".claude", "AGENTS.md"),
143
143
  captureJson: ["PostToolUse", "Stop"]
144
144
  });
145
- agents2.push({
145
+ agents.push({
146
146
  name: "cursor",
147
147
  local: join2(projectRoot, ".cursor", "mcp.json"),
148
148
  mcpKey: "mcpServers",
@@ -150,7 +150,7 @@ function detectAgents() {
150
150
  needsHooks: false,
151
151
  needsInstructions: false
152
152
  });
153
- agents2.push({
153
+ agents.push({
154
154
  name: "windsurf",
155
155
  global: join2(HOME, ".codeium", "windsurf", "mcp_config.json"),
156
156
  mcpKey: "mcpServers",
@@ -158,7 +158,7 @@ function detectAgents() {
158
158
  needsHooks: false,
159
159
  needsInstructions: false
160
160
  });
161
- agents2.push({
161
+ agents.push({
162
162
  name: "cline",
163
163
  local: join2(projectRoot, ".cline", "mcp.json"),
164
164
  mcpKey: "mcpServers",
@@ -166,7 +166,7 @@ function detectAgents() {
166
166
  needsHooks: false,
167
167
  needsInstructions: false
168
168
  });
169
- agents2.push({
169
+ agents.push({
170
170
  name: "continue",
171
171
  local: join2(projectRoot, ".continue", "config.json"),
172
172
  mcpKey: "mcpServers",
@@ -174,7 +174,7 @@ function detectAgents() {
174
174
  needsHooks: false,
175
175
  needsInstructions: false
176
176
  });
177
- agents2.push({
177
+ agents.push({
178
178
  name: "codex",
179
179
  local: join2(projectRoot, ".codex", "config.toml"),
180
180
  mcpKey: "mcpServers",
@@ -182,9 +182,9 @@ function detectAgents() {
182
182
  needsHooks: true,
183
183
  needsInstructions: true,
184
184
  instructionFile: join2(projectRoot, ".codex", "AGENTS.md"),
185
- captureToml: ["post_tool_use", "stop"]
185
+ captureToml: ["PostToolUse", "Stop"]
186
186
  });
187
- agents2.push({
187
+ agents.push({
188
188
  name: "gemini",
189
189
  local: join2(projectRoot, ".gemini", "settings.json"),
190
190
  mcpKey: "mcpServers",
@@ -193,7 +193,7 @@ function detectAgents() {
193
193
  needsInstructions: true,
194
194
  instructionFile: join2(projectRoot, ".gemini", "GEMINI.md")
195
195
  });
196
- agents2.push({
196
+ agents.push({
197
197
  name: "zed",
198
198
  global: join2(HOME, ".config", "zed", "settings.json"),
199
199
  mcpKey: "mcp_servers",
@@ -201,7 +201,7 @@ function detectAgents() {
201
201
  needsHooks: false,
202
202
  needsInstructions: false
203
203
  });
204
- agents2.push({
204
+ agents.push({
205
205
  name: "antigravity",
206
206
  local: join2(projectRoot, ".gemini", "config", "mcp_config.json"),
207
207
  mcpKey: "mcpServers",
@@ -210,7 +210,7 @@ function detectAgents() {
210
210
  needsInstructions: true,
211
211
  instructionFile: join2(projectRoot, "antigravity-cli", "AGENTS.md")
212
212
  });
213
- agents2.push({
213
+ agents.push({
214
214
  name: "aider",
215
215
  mcpKey: "",
216
216
  format: "none",
@@ -218,7 +218,7 @@ function detectAgents() {
218
218
  needsInstructions: true,
219
219
  instructionFile: join2(projectRoot, "CONVENTIONS.md")
220
220
  });
221
- agents2.push({
221
+ agents.push({
222
222
  name: "kilocode",
223
223
  global: join2(HOME, ".kilocode", "mcp_settings.json"),
224
224
  mcpKey: "mcpServers",
@@ -227,7 +227,7 @@ function detectAgents() {
227
227
  needsInstructions: true,
228
228
  instructionFile: join2(HOME, ".kilocode", "rules", "toon-memory.md")
229
229
  });
230
- agents2.push({
230
+ agents.push({
231
231
  name: "openclaw",
232
232
  local: join2(projectRoot, ".openclaw.json"),
233
233
  mcpKey: "mcpServers",
@@ -235,7 +235,7 @@ function detectAgents() {
235
235
  needsHooks: false,
236
236
  needsInstructions: false
237
237
  });
238
- agents2.push({
238
+ agents.push({
239
239
  name: "kiro",
240
240
  local: join2(projectRoot, ".kiro", "settings", "mcp.json"),
241
241
  mcpKey: "mcpServers",
@@ -243,7 +243,7 @@ function detectAgents() {
243
243
  needsHooks: false,
244
244
  needsInstructions: false
245
245
  });
246
- return agents2;
246
+ return agents;
247
247
  }
248
248
  function installMemoryDir() {
249
249
  const memoryFile = join2(MEMORY_DIR, "data.toon");
@@ -427,9 +427,10 @@ function registerCaptureHookTOML(agent, scriptPath) {
427
427
  if (!configPath || !existsSync2(configPath)) return;
428
428
  let content = readFileSync2(configPath, "utf-8");
429
429
  for (const event of agent.captureToml || []) {
430
- if (content.includes(`[hooks.${event}]`)) continue;
430
+ if (content.includes(`event = "${event}"`)) continue;
431
431
  content += `
432
- [hooks.${event}]
432
+ [[hooks]]
433
+ event = "${event}"
433
434
  command = "${scriptPath}"
434
435
  `;
435
436
  }
@@ -440,17 +441,91 @@ function registerHookTOML(agent, hookPath) {
440
441
  const configPath = agent.local;
441
442
  if (!configPath || !existsSync2(configPath)) return;
442
443
  let content = readFileSync2(configPath, "utf-8");
443
- if (content.includes("session_start")) {
444
+ if (content.includes('event = "SessionStart"')) {
444
445
  console.log(` Hook already registered in ${configPath}`);
445
446
  return;
446
447
  }
447
448
  content += `
448
- [hooks.session_start]
449
+ [[hooks]]
450
+ event = "SessionStart"
449
451
  command = "${hookPath}"
450
452
  `;
451
453
  writeFileSync(configPath, content);
452
454
  console.log(` Hook registered in ${configPath}`);
453
455
  }
456
+ function opencodePluginContent() {
457
+ return `export const ToonMemory = async ({ $, directory }) => {
458
+ const ss = directory + "/bin/cli/session-start.js"
459
+ const cap = directory + "/bin/cli/capture.js"
460
+ return {
461
+ "session.created": async () => {
462
+ try { await $\`node \${ss} opencode\`.quiet() } catch {}
463
+ },
464
+ "tool.execute.after": async (input) => {
465
+ if (!process.env.TOON_MEMORY_CAPTURE) return
466
+ try {
467
+ const payload = JSON.stringify({
468
+ session_id: input?.session?.id ?? "",
469
+ tool_name: input?.tool ?? "",
470
+ tool_input: input?.args ?? {},
471
+ })
472
+ await $\`node \${cap} opencode\`.stdin(payload).quiet()
473
+ } catch {}
474
+ },
475
+ }
476
+ }
477
+ `;
478
+ }
479
+ function installOpenCodePlugin(agent) {
480
+ const pluginsDir = join2(projectRoot, ".opencode", "plugins");
481
+ if (!existsSync2(pluginsDir)) mkdirSync(pluginsDir, { recursive: true });
482
+ const dest = join2(pluginsDir, "toon-memory.ts");
483
+ writeFileSync(dest, opencodePluginContent());
484
+ console.log(` Plugin created at ${dest}`);
485
+ const configPath = agent.local || agent.global;
486
+ if (configPath && existsSync2(configPath)) {
487
+ try {
488
+ const config = JSON.parse(readFileSync2(configPath, "utf-8"));
489
+ if (config.hooks) {
490
+ delete config.hooks;
491
+ writeFileSync(configPath, JSON.stringify(config, null, 2));
492
+ console.log(` Removed stale "hooks" key from ${configPath}`);
493
+ }
494
+ } catch {
495
+ }
496
+ }
497
+ }
498
+ var ANTIGRAVITY_HOOK_NAME = "toon-memory";
499
+ function registerAntigravityHooks(agent) {
500
+ const hookDir = join2(projectRoot, ".toon-memory", "hooks");
501
+ if (!existsSync2(hookDir)) mkdirSync(hookDir, { recursive: true });
502
+ const sessionPath = join2(hookDir, "session-start-antigravity.sh");
503
+ writeFileSync(sessionPath, sessionStartHookContent("antigravity"));
504
+ chmodSync(sessionPath, 493);
505
+ console.log(` Hook script created at ${sessionPath}`);
506
+ const capPath = join2(hookDir, "capture-antigravity.sh");
507
+ writeFileSync(capPath, captureHookContent("antigravity"));
508
+ chmodSync(capPath, 493);
509
+ console.log(` Capture hook created at ${capPath}`);
510
+ const base = agent.local ? dirname(agent.local) : projectRoot;
511
+ const hooksFile = join2(base, "hooks.json");
512
+ mkdirSync(base, { recursive: true });
513
+ let cfg = {};
514
+ if (existsSync2(hooksFile)) {
515
+ try {
516
+ cfg = JSON.parse(readFileSync2(hooksFile, "utf-8"));
517
+ } catch {
518
+ cfg = {};
519
+ }
520
+ }
521
+ cfg[ANTIGRAVITY_HOOK_NAME] = {
522
+ PreInvocation: [{ type: "command", command: sessionPath }],
523
+ PostToolUse: [{ matcher: "*", hooks: [{ type: "command", command: capPath }] }],
524
+ Stop: [{ type: "command", command: capPath }]
525
+ };
526
+ writeFileSync(hooksFile, JSON.stringify(cfg, null, 2));
527
+ console.log(` Antigravity hooks registered in ${hooksFile}`);
528
+ }
454
529
  function registerHookJSON(agent, hookPath) {
455
530
  const configPath = agent.format === "jsonc" ? agent.global : agent.local || agent.global;
456
531
  if (!configPath) return;
@@ -470,7 +545,7 @@ function registerHookJSON(agent, hookPath) {
470
545
  config = {};
471
546
  }
472
547
  }
473
- if (agent.name === "claude" || agent.name === "opencode") {
548
+ if (agent.name === "claude" || agent.name === "gemini") {
474
549
  if (!config.hooks) config.hooks = {};
475
550
  if (!config.hooks.SessionStart) config.hooks.SessionStart = [];
476
551
  if (!config.hooks.SessionStart.some((h) => h.command === hookPath)) {
@@ -480,18 +555,14 @@ function registerHookJSON(agent, hookPath) {
480
555
  }
481
556
  return;
482
557
  }
483
- if (!config.session_start_hooks) config.session_start_hooks = [];
484
- if (!config.session_start_hooks.includes(hookPath)) {
485
- config.session_start_hooks.push(hookPath);
486
- writeFileSync(configPath, JSON.stringify(config, null, 2));
487
- console.log(` Hook registered in ${configPath}`);
488
- }
489
558
  }
490
559
  function installForAgent(agent, scope) {
491
560
  console.log(`${agent.name}:`);
492
561
  installMCPConfig(agent, scope);
493
562
  installInstructions(agent);
494
- installHooks(agent);
563
+ if (agent.needsPlugin) installOpenCodePlugin(agent);
564
+ else if (agent.name === "antigravity") registerAntigravityHooks(agent);
565
+ else installHooks(agent);
495
566
  }
496
567
  function updateMemoryConfig(patch) {
497
568
  if (!existsSync2(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
@@ -515,8 +586,8 @@ function init(scope = "local") {
515
586
  updateMemoryConfig({ vocab: deps });
516
587
  console.log(` Detected ${depCount} dependencies \u2192 auto-tag vocabulary written to config.json`);
517
588
  }
518
- const agents2 = detectAgents();
519
- for (const agent of agents2) {
589
+ const agents = detectAgents();
590
+ for (const agent of agents) {
520
591
  installForAgent(agent, scope);
521
592
  console.log("");
522
593
  }
@@ -525,8 +596,8 @@ function init(scope = "local") {
525
596
  }
526
597
  function uninstall() {
527
598
  console.log("\n\u{1F9E0} toon-memory uninstaller\n");
528
- const agents2 = detectAgents();
529
- for (const agent of agents2) {
599
+ const agents = detectAgents();
600
+ for (const agent of agents) {
530
601
  if (agent.format === "json" || agent.format === "jsonc") {
531
602
  const configs = [agent.global, agent.local].filter(Boolean);
532
603
  for (const configPath of configs) {
@@ -560,7 +631,7 @@ function uninstall() {
560
631
  }
561
632
  }
562
633
  }
563
- for (const agent of agents2) {
634
+ for (const agent of agents) {
564
635
  if (agent.instructionFile && existsSync2(agent.instructionFile)) {
565
636
  try {
566
637
  const content = readFileSync2(agent.instructionFile, "utf-8");
@@ -582,6 +653,30 @@ function uninstall() {
582
653
  unlinkSync(toolsFile);
583
654
  console.log(" Removed .opencode/tools/memory.ts");
584
655
  }
656
+ const ocPlugin = join2(projectRoot, ".opencode", "plugins", "toon-memory.ts");
657
+ if (existsSync2(ocPlugin)) {
658
+ unlinkSync(ocPlugin);
659
+ console.log(" Removed .opencode/plugins/toon-memory.ts");
660
+ }
661
+ const agyHooks = join2(projectRoot, ".gemini", "config", "hooks.json");
662
+ if (existsSync2(agyHooks)) {
663
+ try {
664
+ const agyCfg = JSON.parse(readFileSync2(agyHooks, "utf-8"));
665
+ if (agyCfg[ANTIGRAVITY_HOOK_NAME]) {
666
+ delete agyCfg[ANTIGRAVITY_HOOK_NAME];
667
+ if (Object.keys(agyCfg).length === 0) {
668
+ unlinkSync(agyHooks);
669
+ console.log(" Removed .gemini/config/hooks.json");
670
+ } else {
671
+ writeFileSync(agyHooks, JSON.stringify(agyCfg, null, 2));
672
+ console.log(" Removed toon-memory hook from .gemini/config/hooks.json");
673
+ }
674
+ }
675
+ } catch {
676
+ unlinkSync(agyHooks);
677
+ console.log(" Removed .gemini/config/hooks.json");
678
+ }
679
+ }
585
680
  console.log("\n\u2705 toon-memory uninstalled from all agents\n");
586
681
  }
587
682
  function status() {
@@ -610,9 +705,9 @@ function status() {
610
705
  }
611
706
  }
612
707
  console.log(`Capture: ${capture ? "enabled" : "disabled (opt-in)"}`);
613
- const agents2 = detectAgents();
708
+ const agents = detectAgents();
614
709
  console.log("\nAgent configs:");
615
- for (const agent of agents2) {
710
+ for (const agent of agents) {
616
711
  let configured = false;
617
712
  if (agent.format === "json" || agent.format === "jsonc") {
618
713
  const configs = [agent.global, agent.local].filter(Boolean);
@@ -640,13 +735,16 @@ function status() {
640
735
  }
641
736
  const hasInstructions = agent.instructionFile ? existsSync2(agent.instructionFile) : false;
642
737
  const hookPath = join2(projectRoot, ".toon-memory", "hooks", `session-start-${agent.name}.sh`);
643
- const hasHooks = existsSync2(hookPath);
738
+ let hasHooks = existsSync2(hookPath);
739
+ if (agent.needsPlugin) {
740
+ hasHooks = existsSync2(join2(projectRoot, ".opencode", "plugins", "toon-memory.ts"));
741
+ }
644
742
  if (agent.format === "none") {
645
743
  console.log(` ${hasInstructions ? "\u2705" : "\u274C"} ${agent.name} (instructions only)`);
646
744
  } else {
647
745
  const mcpStatus = configured ? "\u2705" : "\u274C";
648
746
  const instrStatus = agent.needsInstructions ? hasInstructions ? " \u{1F4DD}" : "" : "";
649
- const hookStatus = agent.needsHooks ? hasHooks ? " \u{1FA9D}" : "" : "";
747
+ const hookStatus = agent.needsHooks || agent.needsPlugin ? hasHooks ? " \u{1FA9D}" : "" : "";
650
748
  console.log(` ${mcpStatus} ${agent.name}${instrStatus}${hookStatus}`);
651
749
  }
652
750
  }
@@ -971,48 +1069,132 @@ if (args[0] === "watch") {
971
1069
  watch();
972
1070
  process.exit(0);
973
1071
  }
974
- var agents = detectAgents();
975
- console.log("\n\u{1F9E0} toon-memory installer\n");
976
- console.log("Available agents:");
977
- agents.forEach((a, i) => {
978
- const hasConfig = a.format !== "none" && (a.local && existsSync2(a.local) || a.global && existsSync2(a.global));
979
- const indicator = hasConfig ? "\u2713" : "\xB7";
980
- console.log(` ${indicator} ${i + 1}. ${a.name}`);
981
- });
982
- console.log("");
983
- var rl = createInterface({ input: process.stdin, output: process.stdout });
984
- rl.question("Select agents (numbers separated by commas, 'all', or Enter for all): ", (answer) => {
985
- let selected;
986
- const trimmed = answer.trim().toLowerCase();
987
- if (trimmed === "all" || trimmed === "") {
988
- selected = agents;
989
- } else if (trimmed === "none") {
990
- selected = [];
991
- } else {
992
- const indices = trimmed.split(",").map((s) => parseInt(s.trim(), 10) - 1).filter((i) => i >= 0 && i < agents.length);
993
- selected = indices.map((i) => agents[i]);
1072
+ if (args.length === 0) {
1073
+ await interactiveInstall();
1074
+ process.exit(0);
1075
+ }
1076
+ console.log(`Comando desconocido: '${args[0]}'
1077
+ `);
1078
+ printUsage();
1079
+ process.exit(1);
1080
+ function printUsage() {
1081
+ console.log(`Uso: toon-memory <comando> [alcance]
1082
+ Comandos: init, status, stats, export, import, watch, uninstall, capture, upgrade, mcp
1083
+ Opciones: -v/--version, -h/--help
1084
+ Sin argumentos inicia el instalador interactivo.`);
1085
+ }
1086
+ function ask(rl, prompt) {
1087
+ return new Promise((resolve) => rl.question(prompt, resolve));
1088
+ }
1089
+ async function interactiveInstall() {
1090
+ if (!process.stdin.isTTY) {
1091
+ console.log("\n\u{1F9E0} toon-memory \u2014 la instalaci\xF3n interactiva requiere una terminal.");
1092
+ console.log("Ejecuta 'toon-memory init [local|global]' para instalaci\xF3n no interactiva.\n");
1093
+ return;
1094
+ }
1095
+ const agents = detectAgents();
1096
+ console.log("\n\u{1F9E0} toon-memory installer\n");
1097
+ console.log("Agentes detectados:");
1098
+ agents.forEach((a, i) => {
1099
+ const hasConfig = a.format !== "none" && (a.local && existsSync2(a.local) || a.global && existsSync2(a.global));
1100
+ const indicator = hasConfig ? "\u2713" : "\xB7";
1101
+ const scopeNote = a.format === "none" ? "(instrucciones)" : a.global ? "(local/global)" : "(solo local)";
1102
+ console.log(` ${indicator} ${i + 1}. ${a.name} ${scopeNote}`);
1103
+ });
1104
+ console.log("");
1105
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
1106
+ let selected = [];
1107
+ while (true) {
1108
+ const answer = (await ask(rl, "Selecciona agentes (n\xFAmeros separados por comas, nombres, 'all', o Enter para todos; 'q' para salir): ")).trim().toLowerCase();
1109
+ if (answer === "q") {
1110
+ console.log("\nInstalaci\xF3n cancelada.\n");
1111
+ rl.close();
1112
+ return;
1113
+ }
1114
+ if (answer === "all" || answer === "") {
1115
+ selected = agents;
1116
+ break;
1117
+ }
1118
+ if (answer === "none") {
1119
+ selected = [];
1120
+ break;
1121
+ }
1122
+ const tokens = answer.split(",").map((s) => s.trim()).filter(Boolean);
1123
+ const matched = [];
1124
+ let valid = true;
1125
+ for (const tok of tokens) {
1126
+ const num = parseInt(tok, 10);
1127
+ if (!isNaN(num) && num >= 1 && num <= agents.length) {
1128
+ matched.push(agents[num - 1]);
1129
+ } else {
1130
+ const found = agents.find((a) => a.name.toLowerCase() === tok);
1131
+ if (found) matched.push(found);
1132
+ else {
1133
+ console.log(` \u26A0\uFE0F '${tok}' no coincide con ning\xFAn agente.`);
1134
+ valid = false;
1135
+ break;
1136
+ }
1137
+ }
1138
+ }
1139
+ if (valid && matched.length > 0) {
1140
+ selected = matched;
1141
+ break;
1142
+ }
1143
+ console.log("Intenta de nuevo.\n");
994
1144
  }
995
1145
  if (selected.length === 0) {
996
- console.log("\nNo agents selected. Nothing installed.\n");
1146
+ console.log("\nNo se seleccionaron agentes. Nada instalado.\n");
997
1147
  rl.close();
998
1148
  return;
999
1149
  }
1000
1150
  console.log(`
1001
- Selected: ${selected.map((a) => a.name).join(", ")}
1002
- `);
1003
- rl.question("Installation scope \u2014 (1) Local or (2) Global? [1/2]: ", (scopeAnswer) => {
1004
- const scope = scopeAnswer === "2" ? "global" : "local";
1005
- console.log(`
1006
- Installing ${scope}ly...
1151
+ Seleccionados: ${selected.map((a) => a.name).join(", ")}
1007
1152
  `);
1008
- installMemoryDir();
1009
- for (const agent of selected) {
1010
- installForAgent(agent, scope);
1011
- console.log("");
1012
- }
1013
- ensureGitignore();
1014
- console.log("Done! Restart your agent to use memory tools.");
1015
- console.log("Run 'npx toon-memory uninstall' to remove.\n");
1153
+ let scope = "local";
1154
+ while (true) {
1155
+ const scopeAnswer = (await ask(rl, "Alcance \u2014 (1) Local (proyecto) o (2) Global (~home)? [1/2]: ")).trim();
1156
+ if (scopeAnswer === "" || scopeAnswer === "1") {
1157
+ scope = "local";
1158
+ break;
1159
+ }
1160
+ if (scopeAnswer === "2") {
1161
+ scope = "global";
1162
+ break;
1163
+ }
1164
+ console.log("Escribe 1 (local) o 2 (global).\n");
1165
+ }
1166
+ console.log("\nSe instalar\xE1:");
1167
+ for (const a of selected) {
1168
+ const resolved = scope === "global" && a.global ? "global" : "local";
1169
+ const parts = [];
1170
+ if (a.format !== "none") parts.push("MCP");
1171
+ if (a.needsPlugin) parts.push("plugin");
1172
+ else if (a.needsHooks) parts.push("hooks");
1173
+ if (a.needsInstructions) parts.push("instrucciones");
1174
+ const target = resolved === "global" && a.global ? a.global : a.local || "(instrucciones)";
1175
+ console.log(` \u2022 ${a.name} [${resolved}] \u2192 ${target}${parts.length ? ` (${parts.join(", ")})` : ""}`);
1176
+ }
1177
+ const confirm = (await ask(rl, "\n\xBFProceder? [Y/n]: ")).trim().toLowerCase();
1178
+ if (confirm === "n" || confirm === "no") {
1179
+ console.log("\nInstalaci\xF3n cancelada.\n");
1016
1180
  rl.close();
1017
- });
1018
- });
1181
+ return;
1182
+ }
1183
+ console.log(`
1184
+ Instalando (${scope})...
1185
+ `);
1186
+ installMemoryDir();
1187
+ const deps = extractProjectDeps(projectRoot);
1188
+ if (Object.keys(deps).length > 0) {
1189
+ updateMemoryConfig({ vocab: deps });
1190
+ console.log(` Detected ${Object.keys(deps).length} dependencies \u2192 auto-tag vocabulary written to config.json`);
1191
+ }
1192
+ for (const agent of selected) {
1193
+ installForAgent(agent, scope);
1194
+ console.log("");
1195
+ }
1196
+ ensureGitignore();
1197
+ console.log("Done! Restart your agent to use memory tools.");
1198
+ console.log("Run 'npx toon-memory uninstall' to remove.\n");
1199
+ rl.close();
1200
+ }