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/dist/cli/setup.js CHANGED
@@ -1,23 +1,88 @@
1
1
  // src/cli/setup.ts
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, readdirSync, statSync, chmodSync, rmSync } from "fs";
3
- import { basename, dirname, join } from "path";
2
+ import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync, unlinkSync, readdirSync, statSync, chmodSync, rmSync } from "fs";
3
+ import { basename, dirname, join as join2 } from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  import { createInterface } from "readline";
6
6
  import { gzipSync } from "zlib";
7
+
8
+ // src/lib/vocab.ts
9
+ import { existsSync, readFileSync } from "fs";
10
+ import { join } from "path";
11
+ function extractProjectDeps(root) {
12
+ const vocab = {};
13
+ const pkgPath = join(root, "package.json");
14
+ if (existsSync(pkgPath)) {
15
+ try {
16
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
17
+ const deps = { ...pkg.dependencies || {}, ...pkg.devDependencies || {} };
18
+ for (const name of Object.keys(deps)) {
19
+ const tag = name.replace(/^@[^/]+\//, "").toLowerCase();
20
+ vocab[tag] = name.includes("/") ? [name.toLowerCase(), tag] : [name.toLowerCase()];
21
+ }
22
+ } catch {
23
+ }
24
+ }
25
+ const cargoPath = join(root, "Cargo.toml");
26
+ if (existsSync(cargoPath)) {
27
+ try {
28
+ const txt = readFileSync(cargoPath, "utf-8");
29
+ const block = txt.match(/\[dependencies\][\s\S]*?(?:\n\[|$)/)?.[0] || "";
30
+ for (const line of block.split("\n")) {
31
+ const m = line.match(/^\s*([A-Za-z0-9_-]+)\s*=/);
32
+ if (m) {
33
+ const tag = m[1].toLowerCase();
34
+ vocab[tag] = [tag];
35
+ }
36
+ }
37
+ } catch {
38
+ }
39
+ }
40
+ for (const file of ["requirements.txt", "pyproject.toml"]) {
41
+ const p = join(root, file);
42
+ if (!existsSync(p)) continue;
43
+ try {
44
+ const txt = readFileSync(p, "utf-8");
45
+ for (const raw of txt.split("\n")) {
46
+ const name = raw.trim().split(/[<>=!~ \[\]]/)[0].toLowerCase();
47
+ if (!name || name.startsWith("#") || name.includes("[")) continue;
48
+ vocab[name] = [name];
49
+ }
50
+ } catch {
51
+ }
52
+ }
53
+ const goPath = join(root, "go.mod");
54
+ if (existsSync(goPath)) {
55
+ try {
56
+ const txt = readFileSync(goPath, "utf-8");
57
+ for (const raw of txt.split("\n")) {
58
+ const m = raw.match(/^\s*([A-Za-z0-9_./-]+)\s+v[0-9]/);
59
+ if (m) {
60
+ const full = m[1];
61
+ const tag = full.split("/").pop().toLowerCase();
62
+ vocab[tag] = [tag, full.toLowerCase()];
63
+ }
64
+ }
65
+ } catch {
66
+ }
67
+ }
68
+ return vocab;
69
+ }
70
+
71
+ // src/cli/setup.ts
7
72
  var __dirname = dirname(fileURLToPath(import.meta.url));
8
73
  var projectRoot = process.cwd();
9
- var sourceDir = join(__dirname, "..", "..", "src");
74
+ var sourceDir = join2(__dirname, "..", "..", "src");
10
75
  var HOME = process.env.HOME || process.env.USERPROFILE || "~";
11
- var MEMORY_DIR = join(projectRoot, ".toon-memory", "memory");
12
- var CAPTURE_JS = join(__dirname, "capture.js");
13
- var SESSION_START_JS = join(__dirname, "session-start.js");
76
+ var MEMORY_DIR = join2(projectRoot, ".toon-memory", "memory");
77
+ var CAPTURE_JS = join2(__dirname, "capture.js");
78
+ var SESSION_START_JS = join2(__dirname, "session-start.js");
14
79
  function sessionStartHookContent(agentName) {
15
80
  return `#!/bin/bash
16
81
  node "${SESSION_START_JS}" ${agentName}
17
82
  exit 0
18
83
  `;
19
84
  }
20
- var CAPTURE_CONFIG = join(MEMORY_DIR, "config.json");
85
+ var CAPTURE_CONFIG = join2(MEMORY_DIR, "config.json");
21
86
  function captureHookContent(agentName) {
22
87
  return `#!/bin/bash
23
88
  CFG="${CAPTURE_CONFIG}"
@@ -46,158 +111,158 @@ Persistent memory for this project. Use it to avoid re-investigating things.
46
111
  - Save important decisions, bugs resolved, and patterns observed.
47
112
  `;
48
113
  function detectAgents() {
49
- const agents2 = [];
50
- agents2.push({
114
+ const agents = [];
115
+ agents.push({
51
116
  name: "opencode",
52
- global: join(HOME, ".config", "opencode", "opencode.json"),
53
- local: join(projectRoot, ".opencode", "opencode.json"),
117
+ global: join2(HOME, ".config", "opencode", "opencode.json"),
118
+ local: join2(projectRoot, ".opencode", "opencode.json"),
54
119
  mcpKey: "mcp",
55
120
  format: "json",
56
- needsHooks: true,
121
+ needsHooks: false,
122
+ needsPlugin: true,
57
123
  needsInstructions: true,
58
- instructionFile: join(projectRoot, "AGENTS.md"),
59
- captureJson: ["PostToolUse", "Stop"]
124
+ instructionFile: join2(projectRoot, "AGENTS.md")
60
125
  });
61
- agents2.push({
126
+ agents.push({
62
127
  name: "vscode/copilot",
63
- local: join(projectRoot, ".vscode", "mcp.json"),
128
+ local: join2(projectRoot, ".vscode", "mcp.json"),
64
129
  mcpKey: "servers",
65
130
  format: "json",
66
131
  needsHooks: false,
67
132
  needsInstructions: false
68
133
  });
69
- agents2.push({
134
+ agents.push({
70
135
  name: "claude",
71
- global: join(HOME, ".claude", "settings.json"),
72
- local: join(projectRoot, ".claude", "settings.json"),
136
+ global: join2(HOME, ".claude", "settings.json"),
137
+ local: join2(projectRoot, ".claude", "settings.json"),
73
138
  mcpKey: "mcpServers",
74
139
  format: "json",
75
140
  needsHooks: true,
76
141
  needsInstructions: true,
77
- instructionFile: join(projectRoot, ".claude", "AGENTS.md"),
142
+ instructionFile: join2(projectRoot, ".claude", "AGENTS.md"),
78
143
  captureJson: ["PostToolUse", "Stop"]
79
144
  });
80
- agents2.push({
145
+ agents.push({
81
146
  name: "cursor",
82
- local: join(projectRoot, ".cursor", "mcp.json"),
147
+ local: join2(projectRoot, ".cursor", "mcp.json"),
83
148
  mcpKey: "mcpServers",
84
149
  format: "json",
85
150
  needsHooks: false,
86
151
  needsInstructions: false
87
152
  });
88
- agents2.push({
153
+ agents.push({
89
154
  name: "windsurf",
90
- global: join(HOME, ".codeium", "windsurf", "mcp_config.json"),
155
+ global: join2(HOME, ".codeium", "windsurf", "mcp_config.json"),
91
156
  mcpKey: "mcpServers",
92
157
  format: "json",
93
158
  needsHooks: false,
94
159
  needsInstructions: false
95
160
  });
96
- agents2.push({
161
+ agents.push({
97
162
  name: "cline",
98
- local: join(projectRoot, ".cline", "mcp.json"),
163
+ local: join2(projectRoot, ".cline", "mcp.json"),
99
164
  mcpKey: "mcpServers",
100
165
  format: "json",
101
166
  needsHooks: false,
102
167
  needsInstructions: false
103
168
  });
104
- agents2.push({
169
+ agents.push({
105
170
  name: "continue",
106
- local: join(projectRoot, ".continue", "config.json"),
171
+ local: join2(projectRoot, ".continue", "config.json"),
107
172
  mcpKey: "mcpServers",
108
173
  format: "json",
109
174
  needsHooks: false,
110
175
  needsInstructions: false
111
176
  });
112
- agents2.push({
177
+ agents.push({
113
178
  name: "codex",
114
- local: join(projectRoot, ".codex", "config.toml"),
179
+ local: join2(projectRoot, ".codex", "config.toml"),
115
180
  mcpKey: "mcpServers",
116
181
  format: "toml",
117
182
  needsHooks: true,
118
183
  needsInstructions: true,
119
- instructionFile: join(projectRoot, ".codex", "AGENTS.md"),
120
- captureToml: ["post_tool_use", "stop"]
184
+ instructionFile: join2(projectRoot, ".codex", "AGENTS.md"),
185
+ captureToml: ["PostToolUse", "Stop"]
121
186
  });
122
- agents2.push({
187
+ agents.push({
123
188
  name: "gemini",
124
- local: join(projectRoot, ".gemini", "settings.json"),
189
+ local: join2(projectRoot, ".gemini", "settings.json"),
125
190
  mcpKey: "mcpServers",
126
191
  format: "json",
127
192
  needsHooks: true,
128
193
  needsInstructions: true,
129
- instructionFile: join(projectRoot, ".gemini", "GEMINI.md")
194
+ instructionFile: join2(projectRoot, ".gemini", "GEMINI.md")
130
195
  });
131
- agents2.push({
196
+ agents.push({
132
197
  name: "zed",
133
- global: join(HOME, ".config", "zed", "settings.json"),
198
+ global: join2(HOME, ".config", "zed", "settings.json"),
134
199
  mcpKey: "mcp_servers",
135
200
  format: "jsonc",
136
201
  needsHooks: false,
137
202
  needsInstructions: false
138
203
  });
139
- agents2.push({
204
+ agents.push({
140
205
  name: "antigravity",
141
- local: join(projectRoot, ".gemini", "config", "mcp_config.json"),
206
+ local: join2(projectRoot, ".gemini", "config", "mcp_config.json"),
142
207
  mcpKey: "mcpServers",
143
208
  format: "json",
144
209
  needsHooks: true,
145
210
  needsInstructions: true,
146
- instructionFile: join(projectRoot, "antigravity-cli", "AGENTS.md")
211
+ instructionFile: join2(projectRoot, "antigravity-cli", "AGENTS.md")
147
212
  });
148
- agents2.push({
213
+ agents.push({
149
214
  name: "aider",
150
215
  mcpKey: "",
151
216
  format: "none",
152
217
  needsHooks: false,
153
218
  needsInstructions: true,
154
- instructionFile: join(projectRoot, "CONVENTIONS.md")
219
+ instructionFile: join2(projectRoot, "CONVENTIONS.md")
155
220
  });
156
- agents2.push({
221
+ agents.push({
157
222
  name: "kilocode",
158
- global: join(HOME, ".kilocode", "mcp_settings.json"),
223
+ global: join2(HOME, ".kilocode", "mcp_settings.json"),
159
224
  mcpKey: "mcpServers",
160
225
  format: "json",
161
226
  needsHooks: false,
162
227
  needsInstructions: true,
163
- instructionFile: join(HOME, ".kilocode", "rules", "toon-memory.md")
228
+ instructionFile: join2(HOME, ".kilocode", "rules", "toon-memory.md")
164
229
  });
165
- agents2.push({
230
+ agents.push({
166
231
  name: "openclaw",
167
- local: join(projectRoot, ".openclaw.json"),
232
+ local: join2(projectRoot, ".openclaw.json"),
168
233
  mcpKey: "mcpServers",
169
234
  format: "json",
170
235
  needsHooks: false,
171
236
  needsInstructions: false
172
237
  });
173
- agents2.push({
238
+ agents.push({
174
239
  name: "kiro",
175
- local: join(projectRoot, ".kiro", "settings", "mcp.json"),
240
+ local: join2(projectRoot, ".kiro", "settings", "mcp.json"),
176
241
  mcpKey: "mcpServers",
177
242
  format: "json",
178
243
  needsHooks: false,
179
244
  needsInstructions: false
180
245
  });
181
- return agents2;
246
+ return agents;
182
247
  }
183
248
  function installMemoryDir() {
184
- const memoryFile = join(MEMORY_DIR, "data.toon");
185
- if (!existsSync(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
186
- if (!existsSync(memoryFile)) {
249
+ const memoryFile = join2(MEMORY_DIR, "data.toon");
250
+ if (!existsSync2(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
251
+ if (!existsSync2(memoryFile)) {
187
252
  writeFileSync(memoryFile, "version: 1\n[0|]\n");
188
253
  console.log(" Created .toon-memory/memory/data.toon");
189
254
  }
190
255
  }
191
256
  function ensureGitignore() {
192
- const gitignorePath = join(projectRoot, ".gitignore");
257
+ const gitignorePath = join2(projectRoot, ".gitignore");
193
258
  const entry = ".toon-memory/memory/";
194
- if (!existsSync(gitignorePath)) {
259
+ if (!existsSync2(gitignorePath)) {
195
260
  writeFileSync(gitignorePath, `${entry}
196
261
  `);
197
262
  console.log(" Created .gitignore with memory exclusion");
198
263
  return;
199
264
  }
200
- const content = readFileSync(gitignorePath, "utf-8");
265
+ const content = readFileSync2(gitignorePath, "utf-8");
201
266
  if (!content.includes(entry)) {
202
267
  writeFileSync(gitignorePath, `${content.trim()}
203
268
  ${entry}
@@ -212,11 +277,11 @@ function installJSONConfig(agent, scope) {
212
277
  return;
213
278
  }
214
279
  const configDir = dirname(configPath);
215
- if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
280
+ if (!existsSync2(configDir)) mkdirSync(configDir, { recursive: true });
216
281
  let config = {};
217
- if (existsSync(configPath)) {
282
+ if (existsSync2(configPath)) {
218
283
  try {
219
- config = JSON.parse(readFileSync(configPath, "utf-8"));
284
+ config = JSON.parse(readFileSync2(configPath, "utf-8"));
220
285
  } catch {
221
286
  config = {};
222
287
  }
@@ -242,7 +307,7 @@ function installTOMLConfig(agent) {
242
307
  const configPath = agent.local;
243
308
  if (!configPath) return;
244
309
  const configDir = dirname(configPath);
245
- if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
310
+ if (!existsSync2(configDir)) mkdirSync(configDir, { recursive: true });
246
311
  const toml = `[mcpServers.toon-memory]
247
312
  command = "npx"
248
313
  args = ["-y", "toon-memory", "mcp"]
@@ -254,11 +319,11 @@ function installZedConfig(agent) {
254
319
  const configPath = agent.global;
255
320
  if (!configPath) return;
256
321
  const configDir = dirname(configPath);
257
- if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
322
+ if (!existsSync2(configDir)) mkdirSync(configDir, { recursive: true });
258
323
  let config = {};
259
- if (existsSync(configPath)) {
324
+ if (existsSync2(configPath)) {
260
325
  try {
261
- const raw = readFileSync(configPath, "utf-8");
326
+ const raw = readFileSync2(configPath, "utf-8");
262
327
  const stripped = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
263
328
  config = JSON.parse(stripped);
264
329
  } catch {
@@ -290,9 +355,9 @@ function installInstructions(agent) {
290
355
  if (!agent.needsInstructions || !agent.instructionFile) return;
291
356
  const filePath = agent.instructionFile;
292
357
  const fileDir = dirname(filePath);
293
- if (!existsSync(fileDir)) mkdirSync(fileDir, { recursive: true });
294
- if (existsSync(filePath)) {
295
- const existing = readFileSync(filePath, "utf-8");
358
+ if (!existsSync2(fileDir)) mkdirSync(fileDir, { recursive: true });
359
+ if (existsSync2(filePath)) {
360
+ const existing = readFileSync2(filePath, "utf-8");
296
361
  if (existing.includes("toon-memory") || existing.includes("memory_recall")) {
297
362
  console.log(` Instructions already present in ${filePath}`);
298
363
  return;
@@ -308,9 +373,9 @@ ${INSTRUCTION_CONTENT}`);
308
373
  }
309
374
  function installHooks(agent) {
310
375
  if (!agent.needsHooks) return;
311
- const hookDir = join(projectRoot, ".toon-memory", "hooks");
312
- if (!existsSync(hookDir)) mkdirSync(hookDir, { recursive: true });
313
- const hookPath = join(hookDir, `session-start-${agent.name}.sh`);
376
+ const hookDir = join2(projectRoot, ".toon-memory", "hooks");
377
+ if (!existsSync2(hookDir)) mkdirSync(hookDir, { recursive: true });
378
+ const hookPath = join2(hookDir, `session-start-${agent.name}.sh`);
314
379
  writeFileSync(hookPath, sessionStartHookContent(agent.name));
315
380
  chmodSync(hookPath, 493);
316
381
  console.log(` Hook script created at ${hookPath}`);
@@ -320,14 +385,14 @@ function installHooks(agent) {
320
385
  registerHookJSON(agent, hookPath);
321
386
  }
322
387
  if (agent.captureJson && agent.format === "json") {
323
- const capPath = join(hookDir, `capture-${agent.name}.sh`);
388
+ const capPath = join2(hookDir, `capture-${agent.name}.sh`);
324
389
  writeFileSync(capPath, captureHookContent(agent.name));
325
390
  chmodSync(capPath, 493);
326
391
  console.log(` Capture hook created at ${capPath}`);
327
392
  registerCaptureHookJSON(agent, capPath);
328
393
  }
329
394
  if (agent.captureToml && agent.format === "toml" && agent.local) {
330
- const capPath = join(hookDir, `capture-${agent.name}.sh`);
395
+ const capPath = join2(hookDir, `capture-${agent.name}.sh`);
331
396
  writeFileSync(capPath, captureHookContent(agent.name));
332
397
  chmodSync(capPath, 493);
333
398
  console.log(` Capture hook created at ${capPath}`);
@@ -338,11 +403,11 @@ function registerCaptureHookJSON(agent, scriptPath) {
338
403
  const configPath = agent.local || agent.global;
339
404
  if (!configPath) return;
340
405
  const configDir = dirname(configPath);
341
- if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
406
+ if (!existsSync2(configDir)) mkdirSync(configDir, { recursive: true });
342
407
  let config = {};
343
- if (existsSync(configPath)) {
408
+ if (existsSync2(configPath)) {
344
409
  try {
345
- config = JSON.parse(readFileSync(configPath, "utf-8"));
410
+ config = JSON.parse(readFileSync2(configPath, "utf-8"));
346
411
  } catch {
347
412
  config = {};
348
413
  }
@@ -359,12 +424,13 @@ function registerCaptureHookJSON(agent, scriptPath) {
359
424
  }
360
425
  function registerCaptureHookTOML(agent, scriptPath) {
361
426
  const configPath = agent.local;
362
- if (!configPath || !existsSync(configPath)) return;
363
- let content = readFileSync(configPath, "utf-8");
427
+ if (!configPath || !existsSync2(configPath)) return;
428
+ let content = readFileSync2(configPath, "utf-8");
364
429
  for (const event of agent.captureToml || []) {
365
- if (content.includes(`[hooks.${event}]`)) continue;
430
+ if (content.includes(`event = "${event}"`)) continue;
366
431
  content += `
367
- [hooks.${event}]
432
+ [[hooks]]
433
+ event = "${event}"
368
434
  command = "${scriptPath}"
369
435
  `;
370
436
  }
@@ -373,39 +439,113 @@ command = "${scriptPath}"
373
439
  }
374
440
  function registerHookTOML(agent, hookPath) {
375
441
  const configPath = agent.local;
376
- if (!configPath || !existsSync(configPath)) return;
377
- let content = readFileSync(configPath, "utf-8");
378
- if (content.includes("session_start")) {
442
+ if (!configPath || !existsSync2(configPath)) return;
443
+ let content = readFileSync2(configPath, "utf-8");
444
+ if (content.includes('event = "SessionStart"')) {
379
445
  console.log(` Hook already registered in ${configPath}`);
380
446
  return;
381
447
  }
382
448
  content += `
383
- [hooks.session_start]
449
+ [[hooks]]
450
+ event = "SessionStart"
384
451
  command = "${hookPath}"
385
452
  `;
386
453
  writeFileSync(configPath, content);
387
454
  console.log(` Hook registered in ${configPath}`);
388
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
+ }
389
529
  function registerHookJSON(agent, hookPath) {
390
530
  const configPath = agent.format === "jsonc" ? agent.global : agent.local || agent.global;
391
531
  if (!configPath) return;
392
532
  const configDir = dirname(configPath);
393
- if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
533
+ if (!existsSync2(configDir)) mkdirSync(configDir, { recursive: true });
394
534
  let config = {};
395
- if (existsSync(configPath)) {
535
+ if (existsSync2(configPath)) {
396
536
  try {
397
537
  if (agent.format === "jsonc") {
398
- const raw = readFileSync(configPath, "utf-8");
538
+ const raw = readFileSync2(configPath, "utf-8");
399
539
  const stripped = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
400
540
  config = JSON.parse(stripped);
401
541
  } else {
402
- config = JSON.parse(readFileSync(configPath, "utf-8"));
542
+ config = JSON.parse(readFileSync2(configPath, "utf-8"));
403
543
  }
404
544
  } catch {
405
545
  config = {};
406
546
  }
407
547
  }
408
- if (agent.name === "claude" || agent.name === "opencode") {
548
+ if (agent.name === "claude" || agent.name === "gemini") {
409
549
  if (!config.hooks) config.hooks = {};
410
550
  if (!config.hooks.SessionStart) config.hooks.SessionStart = [];
411
551
  if (!config.hooks.SessionStart.some((h) => h.command === hookPath)) {
@@ -415,24 +555,39 @@ function registerHookJSON(agent, hookPath) {
415
555
  }
416
556
  return;
417
557
  }
418
- if (!config.session_start_hooks) config.session_start_hooks = [];
419
- if (!config.session_start_hooks.includes(hookPath)) {
420
- config.session_start_hooks.push(hookPath);
421
- writeFileSync(configPath, JSON.stringify(config, null, 2));
422
- console.log(` Hook registered in ${configPath}`);
423
- }
424
558
  }
425
559
  function installForAgent(agent, scope) {
426
560
  console.log(`${agent.name}:`);
427
561
  installMCPConfig(agent, scope);
428
562
  installInstructions(agent);
429
- installHooks(agent);
563
+ if (agent.needsPlugin) installOpenCodePlugin(agent);
564
+ else if (agent.name === "antigravity") registerAntigravityHooks(agent);
565
+ else installHooks(agent);
566
+ }
567
+ function updateMemoryConfig(patch) {
568
+ if (!existsSync2(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
569
+ let cfg = {};
570
+ if (existsSync2(CAPTURE_CONFIG)) {
571
+ try {
572
+ cfg = JSON.parse(readFileSync2(CAPTURE_CONFIG, "utf-8"));
573
+ } catch {
574
+ cfg = {};
575
+ }
576
+ }
577
+ Object.assign(cfg, patch);
578
+ writeFileSync(CAPTURE_CONFIG, JSON.stringify(cfg, null, 2));
430
579
  }
431
580
  function init(scope = "local") {
432
581
  console.log("\n\u{1F9E0} toon-memory init\n");
433
582
  installMemoryDir();
434
- const agents2 = detectAgents();
435
- for (const agent of agents2) {
583
+ const deps = extractProjectDeps(projectRoot);
584
+ const depCount = Object.keys(deps).length;
585
+ if (depCount > 0) {
586
+ updateMemoryConfig({ vocab: deps });
587
+ console.log(` Detected ${depCount} dependencies \u2192 auto-tag vocabulary written to config.json`);
588
+ }
589
+ const agents = detectAgents();
590
+ for (const agent of agents) {
436
591
  installForAgent(agent, scope);
437
592
  console.log("");
438
593
  }
@@ -441,20 +596,20 @@ function init(scope = "local") {
441
596
  }
442
597
  function uninstall() {
443
598
  console.log("\n\u{1F9E0} toon-memory uninstaller\n");
444
- const agents2 = detectAgents();
445
- for (const agent of agents2) {
599
+ const agents = detectAgents();
600
+ for (const agent of agents) {
446
601
  if (agent.format === "json" || agent.format === "jsonc") {
447
602
  const configs = [agent.global, agent.local].filter(Boolean);
448
603
  for (const configPath of configs) {
449
- if (!existsSync(configPath)) continue;
604
+ if (!existsSync2(configPath)) continue;
450
605
  try {
451
606
  let config;
452
607
  if (agent.format === "jsonc") {
453
- const raw = readFileSync(configPath, "utf-8");
608
+ const raw = readFileSync2(configPath, "utf-8");
454
609
  const stripped = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
455
610
  config = JSON.parse(stripped);
456
611
  } else {
457
- config = JSON.parse(readFileSync(configPath, "utf-8"));
612
+ config = JSON.parse(readFileSync2(configPath, "utf-8"));
458
613
  }
459
614
  const mcpKey = agent.mcpKey || "mcpServers";
460
615
  if (config[mcpKey]?.["toon-memory"]) {
@@ -466,9 +621,9 @@ function uninstall() {
466
621
  }
467
622
  }
468
623
  }
469
- if (agent.format === "toml" && agent.local && existsSync(agent.local)) {
624
+ if (agent.format === "toml" && agent.local && existsSync2(agent.local)) {
470
625
  try {
471
- let content = readFileSync(agent.local, "utf-8");
626
+ let content = readFileSync2(agent.local, "utf-8");
472
627
  content = content.replace(/\[mcpServers\.toon-memory\][\s\S]*?(?=\n\[|$)/, "").trim() + "\n";
473
628
  writeFileSync(agent.local, content);
474
629
  console.log(` Removed MCP from ${agent.name} (${agent.local})`);
@@ -476,10 +631,10 @@ function uninstall() {
476
631
  }
477
632
  }
478
633
  }
479
- for (const agent of agents2) {
480
- if (agent.instructionFile && existsSync(agent.instructionFile)) {
634
+ for (const agent of agents) {
635
+ if (agent.instructionFile && existsSync2(agent.instructionFile)) {
481
636
  try {
482
- const content = readFileSync(agent.instructionFile, "utf-8");
637
+ const content = readFileSync2(agent.instructionFile, "utf-8");
483
638
  if (content.includes(INSTRUCTION_CONTENT.trim()) && content.length < INSTRUCTION_CONTENT.length + 100) {
484
639
  unlinkSync(agent.instructionFile);
485
640
  console.log(` Removed ${agent.instructionFile}`);
@@ -488,29 +643,53 @@ function uninstall() {
488
643
  }
489
644
  }
490
645
  }
491
- const hookDir = join(projectRoot, ".toon-memory", "hooks");
492
- if (existsSync(hookDir)) {
646
+ const hookDir = join2(projectRoot, ".toon-memory", "hooks");
647
+ if (existsSync2(hookDir)) {
493
648
  rmSync(hookDir, { recursive: true, force: true });
494
649
  console.log(" Removed .toon-memory/hooks/");
495
650
  }
496
- const toolsFile = join(projectRoot, ".opencode", "tools", "memory.ts");
497
- if (existsSync(toolsFile)) {
651
+ const toolsFile = join2(projectRoot, ".opencode", "tools", "memory.ts");
652
+ if (existsSync2(toolsFile)) {
498
653
  unlinkSync(toolsFile);
499
654
  console.log(" Removed .opencode/tools/memory.ts");
500
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
+ }
501
680
  console.log("\n\u2705 toon-memory uninstalled from all agents\n");
502
681
  }
503
682
  function status() {
504
683
  console.log("\n\u{1F9E0} toon-memory status\n");
505
684
  try {
506
- const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
685
+ const pkg = JSON.parse(readFileSync2(join2(__dirname, "..", "package.json"), "utf-8"));
507
686
  console.log(`Version: ${pkg.version}`);
508
687
  } catch {
509
688
  console.log("Version: unknown");
510
689
  }
511
- const memoryFile = join(MEMORY_DIR, "data.toon");
512
- if (existsSync(memoryFile)) {
513
- const data = readFileSync(memoryFile, "utf-8");
690
+ const memoryFile = join2(MEMORY_DIR, "data.toon");
691
+ if (existsSync2(memoryFile)) {
692
+ const data = readFileSync2(memoryFile, "utf-8");
514
693
  const lines = data.split("\n").filter((l) => l.startsWith(" ") && l.includes("|"));
515
694
  console.log(`Memory: ${lines.length} entries`);
516
695
  } else {
@@ -518,30 +697,30 @@ function status() {
518
697
  }
519
698
  let capture = false;
520
699
  if (process.env.TOON_MEMORY_CAPTURE) capture = true;
521
- else if (existsSync(CAPTURE_CONFIG)) {
700
+ else if (existsSync2(CAPTURE_CONFIG)) {
522
701
  try {
523
- const c = JSON.parse(readFileSync(CAPTURE_CONFIG, "utf-8"));
702
+ const c = JSON.parse(readFileSync2(CAPTURE_CONFIG, "utf-8"));
524
703
  if (c.capture) capture = true;
525
704
  } catch {
526
705
  }
527
706
  }
528
707
  console.log(`Capture: ${capture ? "enabled" : "disabled (opt-in)"}`);
529
- const agents2 = detectAgents();
708
+ const agents = detectAgents();
530
709
  console.log("\nAgent configs:");
531
- for (const agent of agents2) {
710
+ for (const agent of agents) {
532
711
  let configured = false;
533
712
  if (agent.format === "json" || agent.format === "jsonc") {
534
713
  const configs = [agent.global, agent.local].filter(Boolean);
535
714
  for (const configPath of configs) {
536
- if (!existsSync(configPath)) continue;
715
+ if (!existsSync2(configPath)) continue;
537
716
  try {
538
717
  let config;
539
718
  if (agent.format === "jsonc") {
540
- const raw = readFileSync(configPath, "utf-8");
719
+ const raw = readFileSync2(configPath, "utf-8");
541
720
  const stripped = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
542
721
  config = JSON.parse(stripped);
543
722
  } else {
544
- config = JSON.parse(readFileSync(configPath, "utf-8"));
723
+ config = JSON.parse(readFileSync2(configPath, "utf-8"));
545
724
  }
546
725
  if (config[agent.mcpKey]?.["toon-memory"]) {
547
726
  configured = true;
@@ -550,19 +729,22 @@ function status() {
550
729
  }
551
730
  }
552
731
  }
553
- if (agent.format === "toml" && agent.local && existsSync(agent.local)) {
554
- const content = readFileSync(agent.local, "utf-8");
732
+ if (agent.format === "toml" && agent.local && existsSync2(agent.local)) {
733
+ const content = readFileSync2(agent.local, "utf-8");
555
734
  if (content.includes("toon-memory")) configured = true;
556
735
  }
557
- const hasInstructions = agent.instructionFile ? existsSync(agent.instructionFile) : false;
558
- const hookPath = join(projectRoot, ".toon-memory", "hooks", `session-start-${agent.name}.sh`);
559
- const hasHooks = existsSync(hookPath);
736
+ const hasInstructions = agent.instructionFile ? existsSync2(agent.instructionFile) : false;
737
+ const hookPath = join2(projectRoot, ".toon-memory", "hooks", `session-start-${agent.name}.sh`);
738
+ let hasHooks = existsSync2(hookPath);
739
+ if (agent.needsPlugin) {
740
+ hasHooks = existsSync2(join2(projectRoot, ".opencode", "plugins", "toon-memory.ts"));
741
+ }
560
742
  if (agent.format === "none") {
561
743
  console.log(` ${hasInstructions ? "\u2705" : "\u274C"} ${agent.name} (instructions only)`);
562
744
  } else {
563
745
  const mcpStatus = configured ? "\u2705" : "\u274C";
564
746
  const instrStatus = agent.needsInstructions ? hasInstructions ? " \u{1F4DD}" : "" : "";
565
- const hookStatus = agent.needsHooks ? hasHooks ? " \u{1FA9D}" : "" : "";
747
+ const hookStatus = agent.needsHooks || agent.needsPlugin ? hasHooks ? " \u{1FA9D}" : "" : "";
566
748
  console.log(` ${mcpStatus} ${agent.name}${instrStatus}${hookStatus}`);
567
749
  }
568
750
  }
@@ -571,7 +753,7 @@ function status() {
571
753
  function upgrade() {
572
754
  console.log("\n\u{1F9E0} toon-memory upgrade\n");
573
755
  try {
574
- const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
756
+ const pkg = JSON.parse(readFileSync2(join2(__dirname, "..", "package.json"), "utf-8"));
575
757
  const currentVersion = pkg.version;
576
758
  console.log(`Current version: ${currentVersion}`);
577
759
  console.log("\nTo upgrade, run:");
@@ -585,12 +767,12 @@ function upgrade() {
585
767
  }
586
768
  function stats() {
587
769
  console.log("\n\u{1F9E0} toon-memory stats\n");
588
- const memoryFile = join(MEMORY_DIR, "data.toon");
589
- if (!existsSync(memoryFile)) {
770
+ const memoryFile = join2(MEMORY_DIR, "data.toon");
771
+ if (!existsSync2(memoryFile)) {
590
772
  console.log("Memory not initialized. Run 'npx toon-memory init' first.\n");
591
773
  return;
592
774
  }
593
- const data = readFileSync(memoryFile, "utf-8");
775
+ const data = readFileSync2(memoryFile, "utf-8");
594
776
  const lines = data.split("\n").filter((l) => l.startsWith(" ") && l.includes("|"));
595
777
  const categories = {};
596
778
  let latestDate = "";
@@ -616,12 +798,12 @@ function stats() {
616
798
  }
617
799
  function exportMemory() {
618
800
  console.log("\n\u{1F9E0} toon-memory export\n");
619
- const memoryFile = join(MEMORY_DIR, "data.toon");
620
- if (!existsSync(memoryFile)) {
801
+ const memoryFile = join2(MEMORY_DIR, "data.toon");
802
+ if (!existsSync2(memoryFile)) {
621
803
  console.log("Memory not initialized. Run 'npx toon-memory init' first.\n");
622
804
  return;
623
805
  }
624
- const data = readFileSync(memoryFile, "utf-8");
806
+ const data = readFileSync2(memoryFile, "utf-8");
625
807
  const lines = data.split("\n").filter((l) => l.startsWith(" ") && l.includes("|"));
626
808
  const entries = lines.map((line) => {
627
809
  const parts = line.trim().split("|");
@@ -641,7 +823,7 @@ function exportMemory() {
641
823
  entries,
642
824
  summaries: {}
643
825
  };
644
- const outputPath = join(projectRoot, "toon-memory-export.json");
826
+ const outputPath = join2(projectRoot, "toon-memory-export.json");
645
827
  writeFileSync(outputPath, JSON.stringify(exportData, null, 2));
646
828
  console.log(`Exported ${entries.length} entries to:`);
647
829
  console.log(` ${outputPath}
@@ -654,15 +836,15 @@ function importMemory() {
654
836
  console.log("Usage: npx toon-memory import <file.json>\n");
655
837
  return;
656
838
  }
657
- const importPath = importFile.startsWith("/") ? importFile : join(projectRoot, importFile);
658
- if (!existsSync(importPath)) {
839
+ const importPath = importFile.startsWith("/") ? importFile : join2(projectRoot, importFile);
840
+ if (!existsSync2(importPath)) {
659
841
  console.log(`File not found: ${importPath}
660
842
  `);
661
843
  return;
662
844
  }
663
845
  let importData;
664
846
  try {
665
- importData = JSON.parse(readFileSync(importPath, "utf-8"));
847
+ importData = JSON.parse(readFileSync2(importPath, "utf-8"));
666
848
  } catch {
667
849
  console.log("Invalid JSON file\n");
668
850
  return;
@@ -671,11 +853,11 @@ function importMemory() {
671
853
  console.log("Invalid format: missing 'entries' array\n");
672
854
  return;
673
855
  }
674
- const memoryFile = join(MEMORY_DIR, "data.toon");
675
- if (!existsSync(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
856
+ const memoryFile = join2(MEMORY_DIR, "data.toon");
857
+ if (!existsSync2(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
676
858
  let existingKeys = [];
677
- if (existsSync(memoryFile)) {
678
- const existing = readFileSync(memoryFile, "utf-8");
859
+ if (existsSync2(memoryFile)) {
860
+ const existing = readFileSync2(memoryFile, "utf-8");
679
861
  existingKeys = existing.split("\n").filter((l) => l.startsWith(" ") && l.includes("|")).map((l) => l.trim().split("|")[2]);
680
862
  }
681
863
  const newEntries = importData.entries.filter((e) => !existingKeys.includes(e.key));
@@ -687,8 +869,8 @@ function importMemory() {
687
869
  const tags = Array.isArray(e.tags) ? e.tags.join(";") : e.tags || "";
688
870
  return ` ${e.id}|${e.category}|${e.key}|${e.content}|${e.file}|${tags}|${e.date}`;
689
871
  }).join("\n");
690
- if (existsSync(memoryFile)) {
691
- const existing = readFileSync(memoryFile, "utf-8");
872
+ if (existsSync2(memoryFile)) {
873
+ const existing = readFileSync2(memoryFile, "utf-8");
692
874
  const existingCount = existing.split("\n").filter((l) => l.startsWith(" ") && l.includes("|")).length;
693
875
  const updated = existing.replace(
694
876
  /entries\[\d+\|]/,
@@ -719,7 +901,7 @@ function parseWatchOptions(args2) {
719
901
  opts.compress = true;
720
902
  } else if (arg === "--log" || arg === "-l") {
721
903
  opts.logFile = true;
722
- opts.logPath = args2[++i] || join(MEMORY_DIR, "watch.log");
904
+ opts.logPath = args2[++i] || join2(MEMORY_DIR, "watch.log");
723
905
  } else if (arg === "--max-backups" || arg === "-m") {
724
906
  opts.maxBackups = parseInt(args2[++i]) || 10;
725
907
  } else if (!arg.startsWith("-")) {
@@ -736,8 +918,8 @@ function writeWatchLog(logPath, message) {
736
918
  writeFileSync(logPath, logLine, { flag: "a" });
737
919
  }
738
920
  function getBackupFiles(backupDir) {
739
- if (!existsSync(backupDir)) return [];
740
- return readdirSync(backupDir).filter((f) => f.startsWith("backup-") && (f.endsWith(".toon") || f.endsWith(".gz"))).map((f) => join(backupDir, f)).sort((a, b) => statSync(a).mtimeMs - statSync(b).mtimeMs);
921
+ if (!existsSync2(backupDir)) return [];
922
+ return readdirSync(backupDir).filter((f) => f.startsWith("backup-") && (f.endsWith(".toon") || f.endsWith(".gz"))).map((f) => join2(backupDir, f)).sort((a, b) => statSync(a).mtimeMs - statSync(b).mtimeMs);
741
923
  }
742
924
  function pruneBackups(backupDir, maxBackups) {
743
925
  if (maxBackups <= 0) return 0;
@@ -754,17 +936,17 @@ function compressData(data) {
754
936
  }
755
937
  function watch() {
756
938
  console.log("\n\u{1F9E0} toon-memory watch\n");
757
- const memoryFile = join(MEMORY_DIR, "data.toon");
758
- const backupDir = join(MEMORY_DIR, "backups");
759
- if (!existsSync(memoryFile)) {
939
+ const memoryFile = join2(MEMORY_DIR, "data.toon");
940
+ const backupDir = join2(MEMORY_DIR, "backups");
941
+ if (!existsSync2(memoryFile)) {
760
942
  console.log("Memory not initialized. Run 'npx toon-memory init' first.\n");
761
943
  return;
762
944
  }
763
- if (!existsSync(backupDir)) mkdirSync(backupDir, { recursive: true });
945
+ if (!existsSync2(backupDir)) mkdirSync(backupDir, { recursive: true });
764
946
  const opts = parseWatchOptions(args);
765
947
  if (opts.logFile) {
766
948
  const logDir = dirname(opts.logPath);
767
- if (!existsSync(logDir)) mkdirSync(logDir, { recursive: true });
949
+ if (!existsSync2(logDir)) mkdirSync(logDir, { recursive: true });
768
950
  }
769
951
  console.log(`Watching memory file every ${opts.interval} minutes...`);
770
952
  console.log(`Max backups: ${opts.maxBackups === 0 ? "unlimited" : opts.maxBackups}`);
@@ -772,18 +954,18 @@ function watch() {
772
954
  console.log(`Logging: ${opts.logFile ? `enabled (${opts.logPath})` : "disabled"}`);
773
955
  console.log(`Press Ctrl+C to stop
774
956
  `);
775
- let lastContent = readFileSync(memoryFile, "utf-8");
957
+ let lastContent = readFileSync2(memoryFile, "utf-8");
776
958
  let lastHash = hashContent(lastContent);
777
959
  let backupCount = 0;
778
960
  if (opts.logFile) writeWatchLog(opts.logPath, "Watch started");
779
961
  const backup = () => {
780
962
  try {
781
- const currentContent = readFileSync(memoryFile, "utf-8");
963
+ const currentContent = readFileSync2(memoryFile, "utf-8");
782
964
  const currentHash = hashContent(currentContent);
783
965
  if (currentHash !== lastHash) {
784
966
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
785
967
  const ext = opts.compress ? ".toon.gz" : ".toon";
786
- const backupFile = join(backupDir, `backup-${timestamp}${ext}`);
968
+ const backupFile = join2(backupDir, `backup-${timestamp}${ext}`);
787
969
  if (opts.compress) {
788
970
  writeFileSync(backupFile, compressData(currentContent));
789
971
  } else {
@@ -831,11 +1013,11 @@ function watch() {
831
1013
  });
832
1014
  }
833
1015
  function captureToggle(enable) {
834
- if (!existsSync(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
1016
+ if (!existsSync2(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
835
1017
  let config = {};
836
- if (existsSync(CAPTURE_CONFIG)) {
1018
+ if (existsSync2(CAPTURE_CONFIG)) {
837
1019
  try {
838
- config = JSON.parse(readFileSync(CAPTURE_CONFIG, "utf-8"));
1020
+ config = JSON.parse(readFileSync2(CAPTURE_CONFIG, "utf-8"));
839
1021
  } catch {
840
1022
  config = {};
841
1023
  }
@@ -887,48 +1069,132 @@ if (args[0] === "watch") {
887
1069
  watch();
888
1070
  process.exit(0);
889
1071
  }
890
- var agents = detectAgents();
891
- console.log("\n\u{1F9E0} toon-memory installer\n");
892
- console.log("Available agents:");
893
- agents.forEach((a, i) => {
894
- const hasConfig = a.format !== "none" && (a.local && existsSync(a.local) || a.global && existsSync(a.global));
895
- const indicator = hasConfig ? "\u2713" : "\xB7";
896
- console.log(` ${indicator} ${i + 1}. ${a.name}`);
897
- });
898
- console.log("");
899
- var rl = createInterface({ input: process.stdin, output: process.stdout });
900
- rl.question("Select agents (numbers separated by commas, 'all', or Enter for all): ", (answer) => {
901
- let selected;
902
- const trimmed = answer.trim().toLowerCase();
903
- if (trimmed === "all" || trimmed === "") {
904
- selected = agents;
905
- } else if (trimmed === "none") {
906
- selected = [];
907
- } else {
908
- const indices = trimmed.split(",").map((s) => parseInt(s.trim(), 10) - 1).filter((i) => i >= 0 && i < agents.length);
909
- 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");
910
1144
  }
911
1145
  if (selected.length === 0) {
912
- console.log("\nNo agents selected. Nothing installed.\n");
1146
+ console.log("\nNo se seleccionaron agentes. Nada instalado.\n");
913
1147
  rl.close();
914
1148
  return;
915
1149
  }
916
1150
  console.log(`
917
- Selected: ${selected.map((a) => a.name).join(", ")}
1151
+ Seleccionados: ${selected.map((a) => a.name).join(", ")}
918
1152
  `);
919
- rl.question("Installation scope \u2014 (1) Local or (2) Global? [1/2]: ", (scopeAnswer) => {
920
- const scope = scopeAnswer === "2" ? "global" : "local";
921
- console.log(`
922
- Installing ${scope}ly...
923
- `);
924
- installMemoryDir();
925
- for (const agent of selected) {
926
- installForAgent(agent, scope);
927
- console.log("");
928
- }
929
- ensureGitignore();
930
- console.log("Done! Restart your agent to use memory tools.");
931
- 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");
932
1180
  rl.close();
933
- });
934
- });
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
+ }