toon-memory 2.3.0 → 2.4.1
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 +21 -12
- package/bin/toon-memory.js +40 -0
- package/dist/cli/setup.js +294 -79
- package/mcp/server.js +1 -1
- package/package.json +3 -2
- package/skills/toon-memory.md +5 -5
- package/src/bin/toon-memory.ts +44 -0
- package/src/cli/setup.ts +328 -60
- package/src/mcp/server.ts +1 -1
- package/src/memory.ts +0 -237
package/src/bin/toon-memory.ts
CHANGED
|
@@ -1,10 +1,54 @@
|
|
|
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
|
|
|
5
6
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
6
7
|
const args = process.argv.slice(2)
|
|
7
8
|
|
|
9
|
+
function getVersion(): string {
|
|
10
|
+
try {
|
|
11
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"))
|
|
12
|
+
return pkg.version || "unknown"
|
|
13
|
+
} catch {
|
|
14
|
+
return "unknown"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const HELP = `toon-memory — MCP memory server for AI coding agents
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
toon-memory <command> [scope]
|
|
22
|
+
|
|
23
|
+
Commands:
|
|
24
|
+
init [local|global] Install memory tools + hooks for detected agents
|
|
25
|
+
status Show version, memory count, and agent config status
|
|
26
|
+
stats Show memory statistics
|
|
27
|
+
export [file] Export memory to a TOON/JSON file
|
|
28
|
+
import <file> Import memory from a TOON/JSON file
|
|
29
|
+
watch Watch memory file and re-render on change
|
|
30
|
+
uninstall Remove toon-memory from all agents
|
|
31
|
+
capture <on|off> Enable/disable activity capture hooks
|
|
32
|
+
upgrade Upgrade to the latest version
|
|
33
|
+
|
|
34
|
+
Options:
|
|
35
|
+
-v, --version Show version
|
|
36
|
+
-h, --help Show this help
|
|
37
|
+
|
|
38
|
+
MCP mode:
|
|
39
|
+
toon-memory mcp Run as an MCP server (stdio)
|
|
40
|
+
`
|
|
41
|
+
|
|
42
|
+
if (args[0] === "-v" || args[0] === "--version") {
|
|
43
|
+
console.log(getVersion())
|
|
44
|
+
process.exit(0)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (args[0] === "-h" || args[0] === "--help") {
|
|
48
|
+
console.log(HELP)
|
|
49
|
+
process.exit(0)
|
|
50
|
+
}
|
|
51
|
+
|
|
8
52
|
if (args[0] === "mcp") {
|
|
9
53
|
await import(join(__dirname, "..", "mcp", "server.js"))
|
|
10
54
|
} else {
|
package/src/cli/setup.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, cpSync, unlinkSync, readdirSync, statSync, chmodSync, rmSync } from "fs"
|
|
2
2
|
import { basename, dirname, join } from "path"
|
|
3
3
|
import { fileURLToPath } from "url"
|
|
4
|
-
import { createInterface } from "readline"
|
|
4
|
+
import { createInterface, emitKeypressEvents, type Key } from "readline"
|
|
5
5
|
import { gzipSync, gunzipSync } from "zlib"
|
|
6
6
|
import { extractProjectDeps } from "../lib/vocab"
|
|
7
7
|
|
|
@@ -30,6 +30,8 @@ interface Agent {
|
|
|
30
30
|
captureJson?: string[]
|
|
31
31
|
/** Codex TOML hook events for activity capture (e.g. post_tool_use, stop) */
|
|
32
32
|
captureToml?: string[]
|
|
33
|
+
/** OpenCode: install the toon-memory plugin instead of a `hooks` config key */
|
|
34
|
+
needsPlugin?: boolean
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/** Path to the compiled capture script (dist/cli/capture.js) */
|
|
@@ -102,10 +104,10 @@ function detectAgents(): Agent[] {
|
|
|
102
104
|
local: join(projectRoot, ".opencode", "opencode.json"),
|
|
103
105
|
mcpKey: "mcp",
|
|
104
106
|
format: "json",
|
|
105
|
-
needsHooks:
|
|
107
|
+
needsHooks: false,
|
|
108
|
+
needsPlugin: true,
|
|
106
109
|
needsInstructions: true,
|
|
107
|
-
instructionFile: join(projectRoot, "AGENTS.md")
|
|
108
|
-
captureJson: ["PostToolUse", "Stop"]
|
|
110
|
+
instructionFile: join(projectRoot, "AGENTS.md")
|
|
109
111
|
})
|
|
110
112
|
|
|
111
113
|
// VS Code / GitHub Copilot
|
|
@@ -180,7 +182,7 @@ function detectAgents(): Agent[] {
|
|
|
180
182
|
needsHooks: true,
|
|
181
183
|
needsInstructions: true,
|
|
182
184
|
instructionFile: join(projectRoot, ".codex", "AGENTS.md"),
|
|
183
|
-
captureToml: ["
|
|
185
|
+
captureToml: ["PostToolUse", "Stop"]
|
|
184
186
|
})
|
|
185
187
|
|
|
186
188
|
// Gemini CLI
|
|
@@ -517,37 +519,137 @@ function registerCaptureHookJSON(agent: Agent, scriptPath: string): void {
|
|
|
517
519
|
console.log(` Capture hooks registered in ${configPath}`)
|
|
518
520
|
}
|
|
519
521
|
|
|
520
|
-
/** Register activity-capture hooks (
|
|
522
|
+
/** Register activity-capture hooks (PostToolUse/Stop) in a Codex TOML config. */
|
|
521
523
|
function registerCaptureHookTOML(agent: Agent, scriptPath: string): void {
|
|
522
524
|
const configPath = agent.local
|
|
523
525
|
if (!configPath || !existsSync(configPath)) return
|
|
524
526
|
|
|
525
527
|
let content = readFileSync(configPath, "utf-8")
|
|
526
528
|
for (const event of agent.captureToml || []) {
|
|
527
|
-
if (content.includes(`
|
|
528
|
-
content += `\n[hooks
|
|
529
|
+
if (content.includes(`event = "${event}"`)) continue
|
|
530
|
+
content += `\n[[hooks]]\nevent = "${event}"\ncommand = "${scriptPath}"\n`
|
|
529
531
|
}
|
|
530
532
|
|
|
531
533
|
writeFileSync(configPath, content)
|
|
532
534
|
console.log(` Capture hooks registered in ${configPath}`)
|
|
533
535
|
}
|
|
534
536
|
|
|
535
|
-
/** Register SessionStart hook in TOML config (Codex CLI) */
|
|
537
|
+
/** Register SessionStart hook in TOML config (Codex CLI, stable [[hooks]] format). */
|
|
536
538
|
function registerHookTOML(agent: Agent, hookPath: string): void {
|
|
537
539
|
const configPath = agent.local
|
|
538
540
|
if (!configPath || !existsSync(configPath)) return
|
|
539
541
|
|
|
540
542
|
let content = readFileSync(configPath, "utf-8")
|
|
541
|
-
if (content.includes("
|
|
543
|
+
if (content.includes('event = "SessionStart"')) {
|
|
542
544
|
console.log(` Hook already registered in ${configPath}`)
|
|
543
545
|
return
|
|
544
546
|
}
|
|
545
547
|
|
|
546
|
-
content += `\n[hooks
|
|
548
|
+
content += `\n[[hooks]]\nevent = "SessionStart"\ncommand = "${hookPath}"\n`
|
|
547
549
|
writeFileSync(configPath, content)
|
|
548
550
|
console.log(` Hook registered in ${configPath}`)
|
|
549
551
|
}
|
|
550
552
|
|
|
553
|
+
/**
|
|
554
|
+
* OpenCode plugin source (hooks only). OpenCode 1.17+ delivers hooks via
|
|
555
|
+
* plugins, not a top-level `hooks` config key, so `init` writes this file into
|
|
556
|
+
* `.opencode/plugins/`. It reuses the compiled CLI commands for the actual logic.
|
|
557
|
+
*/
|
|
558
|
+
function opencodePluginContent(): string {
|
|
559
|
+
return `export const ToonMemory = async ({ $, directory }) => {
|
|
560
|
+
const ss = directory + "/bin/cli/session-start.js"
|
|
561
|
+
const cap = directory + "/bin/cli/capture.js"
|
|
562
|
+
return {
|
|
563
|
+
"session.created": async () => {
|
|
564
|
+
try { await $\`node \${ss} opencode\`.quiet() } catch {}
|
|
565
|
+
},
|
|
566
|
+
"tool.execute.after": async (input) => {
|
|
567
|
+
if (!process.env.TOON_MEMORY_CAPTURE) return
|
|
568
|
+
try {
|
|
569
|
+
const payload = JSON.stringify({
|
|
570
|
+
session_id: input?.session?.id ?? "",
|
|
571
|
+
tool_name: input?.tool ?? "",
|
|
572
|
+
tool_input: input?.args ?? {},
|
|
573
|
+
})
|
|
574
|
+
await $\`node \${cap} opencode\`.stdin(payload).quiet()
|
|
575
|
+
} catch {}
|
|
576
|
+
},
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
`
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Install the toon-memory OpenCode plugin (auto-capture via hooks) and remove
|
|
584
|
+
* any stale top-level `hooks` key left by older versions.
|
|
585
|
+
*/
|
|
586
|
+
function installOpenCodePlugin(agent: Agent): void {
|
|
587
|
+
const pluginsDir = join(projectRoot, ".opencode", "plugins")
|
|
588
|
+
if (!existsSync(pluginsDir)) mkdirSync(pluginsDir, { recursive: true })
|
|
589
|
+
|
|
590
|
+
const dest = join(pluginsDir, "toon-memory.ts")
|
|
591
|
+
writeFileSync(dest, opencodePluginContent())
|
|
592
|
+
console.log(` Plugin created at ${dest}`)
|
|
593
|
+
|
|
594
|
+
const configPath = agent.local || agent.global
|
|
595
|
+
if (configPath && existsSync(configPath)) {
|
|
596
|
+
try {
|
|
597
|
+
const config = JSON.parse(readFileSync(configPath, "utf-8"))
|
|
598
|
+
if (config.hooks) {
|
|
599
|
+
delete config.hooks
|
|
600
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2))
|
|
601
|
+
console.log(` Removed stale "hooks" key from ${configPath}`)
|
|
602
|
+
}
|
|
603
|
+
} catch {}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Install Antigravity hooks. Antigravity keeps hooks in a separate `hooks.json`
|
|
609
|
+
* (under .gemini/config/). The official schema maps arbitrary hook NAMES to
|
|
610
|
+
* event configs; each event wraps handlers in `hooks: [{ type, command }]`.
|
|
611
|
+
* Supported events: PreToolUse, PostToolUse, PreInvocation, PostInvocation, Stop.
|
|
612
|
+
* There is no SessionStart event (issue #180 open), so the session-start
|
|
613
|
+
* reminder runs on PreInvocation (fires before the model is called).
|
|
614
|
+
*/
|
|
615
|
+
const ANTIGRAVITY_HOOK_NAME = "toon-memory"
|
|
616
|
+
function registerAntigravityHooks(agent: Agent): void {
|
|
617
|
+
const hookDir = join(projectRoot, ".toon-memory", "hooks")
|
|
618
|
+
if (!existsSync(hookDir)) mkdirSync(hookDir, { recursive: true })
|
|
619
|
+
|
|
620
|
+
const sessionPath = join(hookDir, "session-start-antigravity.sh")
|
|
621
|
+
writeFileSync(sessionPath, sessionStartHookContent("antigravity"))
|
|
622
|
+
chmodSync(sessionPath, 0o755)
|
|
623
|
+
console.log(` Hook script created at ${sessionPath}`)
|
|
624
|
+
|
|
625
|
+
const capPath = join(hookDir, "capture-antigravity.sh")
|
|
626
|
+
writeFileSync(capPath, captureHookContent("antigravity"))
|
|
627
|
+
chmodSync(capPath, 0o755)
|
|
628
|
+
console.log(` Capture hook created at ${capPath}`)
|
|
629
|
+
|
|
630
|
+
const base = agent.local ? dirname(agent.local) : projectRoot
|
|
631
|
+
const hooksFile = join(base, "hooks.json")
|
|
632
|
+
mkdirSync(base, { recursive: true })
|
|
633
|
+
|
|
634
|
+
let cfg: Record<string, any> = {}
|
|
635
|
+
if (existsSync(hooksFile)) {
|
|
636
|
+
try {
|
|
637
|
+
cfg = JSON.parse(readFileSync(hooksFile, "utf-8"))
|
|
638
|
+
} catch {
|
|
639
|
+
cfg = {}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
cfg[ANTIGRAVITY_HOOK_NAME] = {
|
|
644
|
+
PreInvocation: [{ type: "command", command: sessionPath }],
|
|
645
|
+
PostToolUse: [{ matcher: "*", hooks: [{ type: "command", command: capPath }] }],
|
|
646
|
+
Stop: [{ type: "command", command: capPath }],
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
writeFileSync(hooksFile, JSON.stringify(cfg, null, 2))
|
|
650
|
+
console.log(` Antigravity hooks registered in ${hooksFile}`)
|
|
651
|
+
}
|
|
652
|
+
|
|
551
653
|
/** Register SessionStart hook in JSON config */
|
|
552
654
|
function registerHookJSON(agent: Agent, hookPath: string): void {
|
|
553
655
|
const configPath = agent.format === "jsonc" ? agent.global : (agent.local || agent.global)
|
|
@@ -571,8 +673,9 @@ function registerHookJSON(agent: Agent, hookPath: string): void {
|
|
|
571
673
|
}
|
|
572
674
|
}
|
|
573
675
|
|
|
574
|
-
// Claude Code /
|
|
575
|
-
|
|
676
|
+
// Claude Code / Gemini CLI format: `hooks.SessionStart` object
|
|
677
|
+
// (OpenCode uses a plugin instead; Antigravity uses its own hooks.json)
|
|
678
|
+
if (agent.name === "claude" || agent.name === "gemini") {
|
|
576
679
|
if (!config.hooks) config.hooks = {}
|
|
577
680
|
if (!config.hooks.SessionStart) config.hooks.SessionStart = []
|
|
578
681
|
if (!config.hooks.SessionStart.some((h: any) => h.command === hookPath)) {
|
|
@@ -582,14 +685,6 @@ function registerHookJSON(agent: Agent, hookPath: string): void {
|
|
|
582
685
|
}
|
|
583
686
|
return
|
|
584
687
|
}
|
|
585
|
-
|
|
586
|
-
// Gemini CLI / Antigravity format
|
|
587
|
-
if (!config.session_start_hooks) config.session_start_hooks = []
|
|
588
|
-
if (!config.session_start_hooks.includes(hookPath)) {
|
|
589
|
-
config.session_start_hooks.push(hookPath)
|
|
590
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2))
|
|
591
|
-
console.log(` Hook registered in ${configPath}`)
|
|
592
|
-
}
|
|
593
688
|
}
|
|
594
689
|
|
|
595
690
|
/**
|
|
@@ -599,7 +694,9 @@ function installForAgent(agent: Agent, scope: string): void {
|
|
|
599
694
|
console.log(`${agent.name}:`)
|
|
600
695
|
installMCPConfig(agent, scope)
|
|
601
696
|
installInstructions(agent)
|
|
602
|
-
|
|
697
|
+
if (agent.needsPlugin) installOpenCodePlugin(agent)
|
|
698
|
+
else if (agent.name === "antigravity") registerAntigravityHooks(agent)
|
|
699
|
+
else installHooks(agent)
|
|
603
700
|
}
|
|
604
701
|
|
|
605
702
|
/**
|
|
@@ -728,6 +825,34 @@ function uninstall(): void {
|
|
|
728
825
|
console.log(" Removed .opencode/tools/memory.ts")
|
|
729
826
|
}
|
|
730
827
|
|
|
828
|
+
// Remove OpenCode plugin
|
|
829
|
+
const ocPlugin = join(projectRoot, ".opencode", "plugins", "toon-memory.ts")
|
|
830
|
+
if (existsSync(ocPlugin)) {
|
|
831
|
+
unlinkSync(ocPlugin)
|
|
832
|
+
console.log(" Removed .opencode/plugins/toon-memory.ts")
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// Remove toon-memory hook from Antigravity hooks.json (leave other hooks intact)
|
|
836
|
+
const agyHooks = join(projectRoot, ".gemini", "config", "hooks.json")
|
|
837
|
+
if (existsSync(agyHooks)) {
|
|
838
|
+
try {
|
|
839
|
+
const agyCfg = JSON.parse(readFileSync(agyHooks, "utf-8"))
|
|
840
|
+
if (agyCfg[ANTIGRAVITY_HOOK_NAME]) {
|
|
841
|
+
delete agyCfg[ANTIGRAVITY_HOOK_NAME]
|
|
842
|
+
if (Object.keys(agyCfg).length === 0) {
|
|
843
|
+
unlinkSync(agyHooks)
|
|
844
|
+
console.log(" Removed .gemini/config/hooks.json")
|
|
845
|
+
} else {
|
|
846
|
+
writeFileSync(agyHooks, JSON.stringify(agyCfg, null, 2))
|
|
847
|
+
console.log(" Removed toon-memory hook from .gemini/config/hooks.json")
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
} catch {
|
|
851
|
+
unlinkSync(agyHooks)
|
|
852
|
+
console.log(" Removed .gemini/config/hooks.json")
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
731
856
|
console.log("\n✅ toon-memory uninstalled from all agents\n")
|
|
732
857
|
}
|
|
733
858
|
|
|
@@ -808,16 +933,19 @@ function status(): void {
|
|
|
808
933
|
// Check instructions
|
|
809
934
|
const hasInstructions = agent.instructionFile ? existsSync(agent.instructionFile) : false
|
|
810
935
|
|
|
811
|
-
// Check hooks
|
|
936
|
+
// Check hooks / plugin
|
|
812
937
|
const hookPath = join(projectRoot, ".toon-memory", "hooks", `session-start-${agent.name}.sh`)
|
|
813
|
-
|
|
938
|
+
let hasHooks = existsSync(hookPath)
|
|
939
|
+
if (agent.needsPlugin) {
|
|
940
|
+
hasHooks = existsSync(join(projectRoot, ".opencode", "plugins", "toon-memory.ts"))
|
|
941
|
+
}
|
|
814
942
|
|
|
815
943
|
if (agent.format === "none") {
|
|
816
944
|
console.log(` ${hasInstructions ? "✅" : "❌"} ${agent.name} (instructions only)`)
|
|
817
945
|
} else {
|
|
818
946
|
const mcpStatus = configured ? "✅" : "❌"
|
|
819
947
|
const instrStatus = agent.needsInstructions ? (hasInstructions ? " 📝" : "") : ""
|
|
820
|
-
const hookStatus = agent.needsHooks ? (hasHooks ? " 🪝" : "") : ""
|
|
948
|
+
const hookStatus = (agent.needsHooks || agent.needsPlugin) ? (hasHooks ? " 🪝" : "") : ""
|
|
821
949
|
console.log(` ${mcpStatus} ${agent.name}${instrStatus}${hookStatus}`)
|
|
822
950
|
}
|
|
823
951
|
}
|
|
@@ -1255,56 +1383,196 @@ if (args[0] === "watch") {
|
|
|
1255
1383
|
process.exit(0)
|
|
1256
1384
|
}
|
|
1257
1385
|
|
|
1258
|
-
// Interactive installer
|
|
1259
|
-
|
|
1260
|
-
|
|
1386
|
+
// Interactive installer when no command is given; otherwise report unknown command.
|
|
1387
|
+
if (args.length === 0) {
|
|
1388
|
+
await interactiveInstall()
|
|
1389
|
+
process.exit(0)
|
|
1390
|
+
}
|
|
1261
1391
|
|
|
1262
|
-
console.log(
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
const indicator = hasConfig ? "✓" : "·"
|
|
1266
|
-
console.log(` ${indicator} ${i + 1}. ${a.name}`)
|
|
1267
|
-
})
|
|
1268
|
-
console.log("")
|
|
1392
|
+
console.log(`Comando desconocido: '${args[0]}'\n`)
|
|
1393
|
+
printUsage()
|
|
1394
|
+
process.exit(1)
|
|
1269
1395
|
|
|
1270
|
-
|
|
1396
|
+
/** Minimal usage string for unknown commands (full help lives in the entry point). */
|
|
1397
|
+
function printUsage(): void {
|
|
1398
|
+
console.log(`Uso: toon-memory <comando> [alcance]
|
|
1399
|
+
Comandos: init, status, stats, export, import, watch, uninstall, capture, upgrade, mcp
|
|
1400
|
+
Opciones: -v/--version, -h/--help
|
|
1401
|
+
Sin argumentos inicia el instalador interactivo.`)
|
|
1402
|
+
}
|
|
1271
1403
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1404
|
+
/** Promise wrapper around readline question. */
|
|
1405
|
+
function ask(rl: ReturnType<typeof createInterface>, prompt: string): Promise<string> {
|
|
1406
|
+
return new Promise((resolve) => rl.question(prompt, resolve))
|
|
1407
|
+
}
|
|
1274
1408
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1409
|
+
/**
|
|
1410
|
+
* Guided interactive installer: pick agents, choose local vs global scope,
|
|
1411
|
+
* confirm, then install. Requires a TTY; otherwise prints a non-interactive hint.
|
|
1412
|
+
*/
|
|
1413
|
+
async function interactiveInstall(): Promise<void> {
|
|
1414
|
+
if (!process.stdin.isTTY) {
|
|
1415
|
+
console.log("\n🧠 toon-memory — la instalación interactiva requiere una terminal.")
|
|
1416
|
+
console.log("Ejecuta 'toon-memory init [local|global]' para instalación no interactiva.\n")
|
|
1417
|
+
return
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
const agents = detectAgents()
|
|
1421
|
+
const selected = await runAgentChecklist(agents)
|
|
1422
|
+
if (selected === null) {
|
|
1423
|
+
console.log("\nInstalación cancelada.\n")
|
|
1424
|
+
return
|
|
1283
1425
|
}
|
|
1284
1426
|
|
|
1285
1427
|
if (selected.length === 0) {
|
|
1286
|
-
console.log("\nNo
|
|
1428
|
+
console.log("\nNo se seleccionaron agentes. Nada instalado.\n")
|
|
1429
|
+
return
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
console.log(`\nSeleccionados: ${selected.map((a) => a.name).join(", ")}\n`)
|
|
1433
|
+
|
|
1434
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
1435
|
+
|
|
1436
|
+
// 2) Scope
|
|
1437
|
+
let scope = "local"
|
|
1438
|
+
while (true) {
|
|
1439
|
+
const scopeAnswer = (await ask(rl, "Alcance — (1) Local (proyecto) o (2) Global (~home)? [1/2]: ")).trim()
|
|
1440
|
+
if (scopeAnswer === "" || scopeAnswer === "1") {
|
|
1441
|
+
scope = "local"
|
|
1442
|
+
break
|
|
1443
|
+
}
|
|
1444
|
+
if (scopeAnswer === "2") {
|
|
1445
|
+
scope = "global"
|
|
1446
|
+
break
|
|
1447
|
+
}
|
|
1448
|
+
console.log("Escribe 1 (local) o 2 (global).\n")
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// 3) Confirmation summary
|
|
1452
|
+
console.log("\nSe instalará:")
|
|
1453
|
+
for (const a of selected) {
|
|
1454
|
+
const resolved = scope === "global" && a.global ? "global" : "local"
|
|
1455
|
+
const parts: string[] = []
|
|
1456
|
+
if (a.format !== "none") parts.push("MCP")
|
|
1457
|
+
if (a.needsPlugin) parts.push("plugin")
|
|
1458
|
+
else if (a.needsHooks) parts.push("hooks")
|
|
1459
|
+
if (a.needsInstructions) parts.push("instrucciones")
|
|
1460
|
+
const target = resolved === "global" && a.global ? a.global : a.local || "(instrucciones)"
|
|
1461
|
+
console.log(` • ${a.name} [${resolved}] → ${target}${parts.length ? ` (${parts.join(", ")})` : ""}`)
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
const confirm = (await ask(rl, "\n¿Proceder? [Y/n]: ")).trim().toLowerCase()
|
|
1465
|
+
if (confirm === "n" || confirm === "no") {
|
|
1466
|
+
console.log("\nInstalación cancelada.\n")
|
|
1287
1467
|
rl.close()
|
|
1288
1468
|
return
|
|
1289
1469
|
}
|
|
1290
1470
|
|
|
1291
|
-
console.log(`\
|
|
1471
|
+
console.log(`\nInstalando (${scope})...\n`)
|
|
1472
|
+
installMemoryDir()
|
|
1473
|
+
|
|
1474
|
+
const deps = extractProjectDeps(projectRoot)
|
|
1475
|
+
if (Object.keys(deps).length > 0) {
|
|
1476
|
+
updateMemoryConfig({ vocab: deps })
|
|
1477
|
+
console.log(` Detected ${Object.keys(deps).length} dependencies → auto-tag vocabulary written to config.json`)
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
for (const agent of selected) {
|
|
1481
|
+
installForAgent(agent, scope)
|
|
1482
|
+
console.log("")
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
ensureGitignore()
|
|
1486
|
+
|
|
1487
|
+
console.log("Done! Restart your agent to use memory tools.")
|
|
1488
|
+
console.log("Run 'npx toon-memory uninstall' to remove.\n")
|
|
1489
|
+
rl.close()
|
|
1490
|
+
}
|
|
1292
1491
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1492
|
+
/**
|
|
1493
|
+
* Navigable multi-select checklist rendered in the terminal (no dependencies).
|
|
1494
|
+
* ↑/↓ (or k/j) move the cursor, space toggles a selection, 'a' toggles all,
|
|
1495
|
+
* Enter confirms, 'q'/'c'/Ctrl-C aborts. Requires a TTY.
|
|
1496
|
+
*/
|
|
1497
|
+
async function runAgentChecklist(agents: Agent[]): Promise<Agent[] | null> {
|
|
1498
|
+
const n = agents.length
|
|
1499
|
+
let cursor = 0
|
|
1500
|
+
const selected = new Set<number>()
|
|
1501
|
+
let prevLines = 0
|
|
1502
|
+
|
|
1503
|
+
const render = (): void => {
|
|
1504
|
+
let out = ""
|
|
1505
|
+
if (prevLines > 0) out += `\x1b[${prevLines}A\x1b[J`
|
|
1506
|
+
const lines: string[] = []
|
|
1507
|
+
lines.push("\n🧠 toon-memory installer")
|
|
1508
|
+
lines.push("")
|
|
1509
|
+
lines.push("Agentes detectados:")
|
|
1510
|
+
agents.forEach((a: Agent, i: number) => {
|
|
1511
|
+
const isCursor = i === cursor
|
|
1512
|
+
const isSel = selected.has(i)
|
|
1513
|
+
const box = isSel ? "[x]" : "[ ]"
|
|
1514
|
+
const cur = isCursor ? ">" : " "
|
|
1515
|
+
const hasConfig = a.format !== "none" && ((a.local && existsSync(a.local)) || (a.global && existsSync(a.global)))
|
|
1516
|
+
const indicator = hasConfig ? "✓" : "·"
|
|
1517
|
+
const scopeNote = a.format === "none" ? "(instrucciones)" : a.global ? "(local/global)" : "(solo local)"
|
|
1518
|
+
lines.push(` ${cur} ${box} ${indicator} ${i + 1}. ${a.name} ${scopeNote}`)
|
|
1519
|
+
})
|
|
1520
|
+
lines.push("")
|
|
1521
|
+
lines.push(" ↑/↓ mover · espacio marcar · 'a' todos · Enter confirmar · 'q' salir")
|
|
1522
|
+
process.stdout.write(out + lines.join("\n") + "\n")
|
|
1523
|
+
prevLines = lines.length
|
|
1524
|
+
}
|
|
1296
1525
|
|
|
1297
|
-
|
|
1526
|
+
return new Promise<Agent[] | null>((resolve) => {
|
|
1527
|
+
emitKeypressEvents(process.stdin)
|
|
1528
|
+
process.stdin.setRawMode(true)
|
|
1529
|
+
process.stdin.resume()
|
|
1298
1530
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1531
|
+
const finish = (result: Agent[] | null): void => {
|
|
1532
|
+
process.stdin.setRawMode(false)
|
|
1533
|
+
process.stdin.removeListener("keypress", onKey)
|
|
1534
|
+
process.stdout.write("\n")
|
|
1535
|
+
resolve(result)
|
|
1302
1536
|
}
|
|
1303
1537
|
|
|
1304
|
-
|
|
1538
|
+
const onKey = (_str: string, key: Key | undefined): void => {
|
|
1539
|
+
if (!key) return
|
|
1540
|
+
if (key.ctrl && key.name === "c") {
|
|
1541
|
+
finish(null)
|
|
1542
|
+
return
|
|
1543
|
+
}
|
|
1544
|
+
switch (key.name) {
|
|
1545
|
+
case "up":
|
|
1546
|
+
case "k":
|
|
1547
|
+
cursor = (cursor - 1 + n) % n
|
|
1548
|
+
break
|
|
1549
|
+
case "down":
|
|
1550
|
+
case "j":
|
|
1551
|
+
cursor = (cursor + 1) % n
|
|
1552
|
+
break
|
|
1553
|
+
case "space":
|
|
1554
|
+
if (selected.has(cursor)) selected.delete(cursor)
|
|
1555
|
+
else selected.add(cursor)
|
|
1556
|
+
break
|
|
1557
|
+
case "a":
|
|
1558
|
+
if (selected.size === n) selected.clear()
|
|
1559
|
+
else for (let i = 0; i < n; i++) selected.add(i)
|
|
1560
|
+
break
|
|
1561
|
+
case "return":
|
|
1562
|
+
finish(agents.filter((_: Agent, i: number) => selected.has(i)))
|
|
1563
|
+
return
|
|
1564
|
+
case "q":
|
|
1565
|
+
case "c":
|
|
1566
|
+
finish(null)
|
|
1567
|
+
return
|
|
1568
|
+
default:
|
|
1569
|
+
render()
|
|
1570
|
+
return
|
|
1571
|
+
}
|
|
1572
|
+
render()
|
|
1573
|
+
}
|
|
1305
1574
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
rl.close()
|
|
1575
|
+
process.stdin.on("keypress", onKey)
|
|
1576
|
+
render()
|
|
1309
1577
|
})
|
|
1310
|
-
}
|
|
1578
|
+
}
|
package/src/mcp/server.ts
CHANGED
|
@@ -599,7 +599,7 @@ function consolidateEntries(): { removed: number; kept: number; duplicates: stri
|
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
const server = new McpServer(
|
|
602
|
-
{ name: "toon-memory", version: "2.
|
|
602
|
+
{ name: "toon-memory", version: "2.4.1" },
|
|
603
603
|
{ capabilities: { tools: { listChanged: true }, resources: { listChanged: true } } }
|
|
604
604
|
)
|
|
605
605
|
|