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/README.md +88 -16
- package/bin/toon-memory.js +40 -0
- package/dist/cli/setup.js +461 -195
- package/mcp/server.js +168 -41
- 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 +318 -63
- package/src/lib/graph.ts +193 -39
- package/src/lib/vocab.ts +100 -0
- package/src/mcp/server.ts +56 -10
- package/src/memory.ts +0 -237
package/src/cli/setup.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { basename, dirname, join } from "path"
|
|
|
3
3
|
import { fileURLToPath } from "url"
|
|
4
4
|
import { createInterface } from "readline"
|
|
5
5
|
import { gzipSync, gunzipSync } from "zlib"
|
|
6
|
+
import { extractProjectDeps } from "../lib/vocab"
|
|
6
7
|
|
|
7
8
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
8
9
|
const projectRoot = process.cwd()
|
|
@@ -29,6 +30,8 @@ interface Agent {
|
|
|
29
30
|
captureJson?: string[]
|
|
30
31
|
/** Codex TOML hook events for activity capture (e.g. post_tool_use, stop) */
|
|
31
32
|
captureToml?: string[]
|
|
33
|
+
/** OpenCode: install the toon-memory plugin instead of a `hooks` config key */
|
|
34
|
+
needsPlugin?: boolean
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/** Path to the compiled capture script (dist/cli/capture.js) */
|
|
@@ -101,10 +104,10 @@ function detectAgents(): Agent[] {
|
|
|
101
104
|
local: join(projectRoot, ".opencode", "opencode.json"),
|
|
102
105
|
mcpKey: "mcp",
|
|
103
106
|
format: "json",
|
|
104
|
-
needsHooks:
|
|
107
|
+
needsHooks: false,
|
|
108
|
+
needsPlugin: true,
|
|
105
109
|
needsInstructions: true,
|
|
106
|
-
instructionFile: join(projectRoot, "AGENTS.md")
|
|
107
|
-
captureJson: ["PostToolUse", "Stop"]
|
|
110
|
+
instructionFile: join(projectRoot, "AGENTS.md")
|
|
108
111
|
})
|
|
109
112
|
|
|
110
113
|
// VS Code / GitHub Copilot
|
|
@@ -179,7 +182,7 @@ function detectAgents(): Agent[] {
|
|
|
179
182
|
needsHooks: true,
|
|
180
183
|
needsInstructions: true,
|
|
181
184
|
instructionFile: join(projectRoot, ".codex", "AGENTS.md"),
|
|
182
|
-
captureToml: ["
|
|
185
|
+
captureToml: ["PostToolUse", "Stop"]
|
|
183
186
|
})
|
|
184
187
|
|
|
185
188
|
// Gemini CLI
|
|
@@ -516,37 +519,137 @@ function registerCaptureHookJSON(agent: Agent, scriptPath: string): void {
|
|
|
516
519
|
console.log(` Capture hooks registered in ${configPath}`)
|
|
517
520
|
}
|
|
518
521
|
|
|
519
|
-
/** Register activity-capture hooks (
|
|
522
|
+
/** Register activity-capture hooks (PostToolUse/Stop) in a Codex TOML config. */
|
|
520
523
|
function registerCaptureHookTOML(agent: Agent, scriptPath: string): void {
|
|
521
524
|
const configPath = agent.local
|
|
522
525
|
if (!configPath || !existsSync(configPath)) return
|
|
523
526
|
|
|
524
527
|
let content = readFileSync(configPath, "utf-8")
|
|
525
528
|
for (const event of agent.captureToml || []) {
|
|
526
|
-
if (content.includes(`
|
|
527
|
-
content += `\n[hooks
|
|
529
|
+
if (content.includes(`event = "${event}"`)) continue
|
|
530
|
+
content += `\n[[hooks]]\nevent = "${event}"\ncommand = "${scriptPath}"\n`
|
|
528
531
|
}
|
|
529
532
|
|
|
530
533
|
writeFileSync(configPath, content)
|
|
531
534
|
console.log(` Capture hooks registered in ${configPath}`)
|
|
532
535
|
}
|
|
533
536
|
|
|
534
|
-
/** Register SessionStart hook in TOML config (Codex CLI) */
|
|
537
|
+
/** Register SessionStart hook in TOML config (Codex CLI, stable [[hooks]] format). */
|
|
535
538
|
function registerHookTOML(agent: Agent, hookPath: string): void {
|
|
536
539
|
const configPath = agent.local
|
|
537
540
|
if (!configPath || !existsSync(configPath)) return
|
|
538
541
|
|
|
539
542
|
let content = readFileSync(configPath, "utf-8")
|
|
540
|
-
if (content.includes("
|
|
543
|
+
if (content.includes('event = "SessionStart"')) {
|
|
541
544
|
console.log(` Hook already registered in ${configPath}`)
|
|
542
545
|
return
|
|
543
546
|
}
|
|
544
547
|
|
|
545
|
-
content += `\n[hooks
|
|
548
|
+
content += `\n[[hooks]]\nevent = "SessionStart"\ncommand = "${hookPath}"\n`
|
|
546
549
|
writeFileSync(configPath, content)
|
|
547
550
|
console.log(` Hook registered in ${configPath}`)
|
|
548
551
|
}
|
|
549
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
|
+
|
|
550
653
|
/** Register SessionStart hook in JSON config */
|
|
551
654
|
function registerHookJSON(agent: Agent, hookPath: string): void {
|
|
552
655
|
const configPath = agent.format === "jsonc" ? agent.global : (agent.local || agent.global)
|
|
@@ -570,8 +673,9 @@ function registerHookJSON(agent: Agent, hookPath: string): void {
|
|
|
570
673
|
}
|
|
571
674
|
}
|
|
572
675
|
|
|
573
|
-
// Claude Code /
|
|
574
|
-
|
|
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") {
|
|
575
679
|
if (!config.hooks) config.hooks = {}
|
|
576
680
|
if (!config.hooks.SessionStart) config.hooks.SessionStart = []
|
|
577
681
|
if (!config.hooks.SessionStart.some((h: any) => h.command === hookPath)) {
|
|
@@ -581,14 +685,6 @@ function registerHookJSON(agent: Agent, hookPath: string): void {
|
|
|
581
685
|
}
|
|
582
686
|
return
|
|
583
687
|
}
|
|
584
|
-
|
|
585
|
-
// Gemini CLI / Antigravity format
|
|
586
|
-
if (!config.session_start_hooks) config.session_start_hooks = []
|
|
587
|
-
if (!config.session_start_hooks.includes(hookPath)) {
|
|
588
|
-
config.session_start_hooks.push(hookPath)
|
|
589
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2))
|
|
590
|
-
console.log(` Hook registered in ${configPath}`)
|
|
591
|
-
}
|
|
592
688
|
}
|
|
593
689
|
|
|
594
690
|
/**
|
|
@@ -598,20 +694,48 @@ function installForAgent(agent: Agent, scope: string): void {
|
|
|
598
694
|
console.log(`${agent.name}:`)
|
|
599
695
|
installMCPConfig(agent, scope)
|
|
600
696
|
installInstructions(agent)
|
|
601
|
-
|
|
697
|
+
if (agent.needsPlugin) installOpenCodePlugin(agent)
|
|
698
|
+
else if (agent.name === "antigravity") registerAntigravityHooks(agent)
|
|
699
|
+
else installHooks(agent)
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Read/write the shared memory config.json, preserving unknown keys
|
|
704
|
+
* (e.g. `encrypted`, `capture`) so we never clobber sibling settings.
|
|
705
|
+
*/
|
|
706
|
+
function updateMemoryConfig(patch: Record<string, any>): void {
|
|
707
|
+
if (!existsSync(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true })
|
|
708
|
+
let cfg: Record<string, any> = {}
|
|
709
|
+
if (existsSync(CAPTURE_CONFIG)) {
|
|
710
|
+
try {
|
|
711
|
+
cfg = JSON.parse(readFileSync(CAPTURE_CONFIG, "utf-8"))
|
|
712
|
+
} catch {
|
|
713
|
+
cfg = {}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
Object.assign(cfg, patch)
|
|
717
|
+
writeFileSync(CAPTURE_CONFIG, JSON.stringify(cfg, null, 2))
|
|
602
718
|
}
|
|
603
719
|
|
|
604
720
|
/**
|
|
605
721
|
* Initialize toon-memory for all detected agents (non-interactive).
|
|
606
722
|
*
|
|
607
|
-
* Installs MCP server configs, creates memory directory,
|
|
608
|
-
* updates `.gitignore`.
|
|
723
|
+
* Installs MCP server configs, creates memory directory, discovers project
|
|
724
|
+
* dependencies for tag inference, and updates `.gitignore`.
|
|
609
725
|
*/
|
|
610
726
|
function init(scope: string = "local"): void {
|
|
611
727
|
console.log("\n🧠 toon-memory init\n")
|
|
612
728
|
|
|
613
729
|
installMemoryDir()
|
|
614
730
|
|
|
731
|
+
// Hito 7 (B): derive a project-specific tag vocabulary from dependencies.
|
|
732
|
+
const deps = extractProjectDeps(projectRoot)
|
|
733
|
+
const depCount = Object.keys(deps).length
|
|
734
|
+
if (depCount > 0) {
|
|
735
|
+
updateMemoryConfig({ vocab: deps })
|
|
736
|
+
console.log(` Detected ${depCount} dependencies → auto-tag vocabulary written to config.json`)
|
|
737
|
+
}
|
|
738
|
+
|
|
615
739
|
const agents = detectAgents()
|
|
616
740
|
for (const agent of agents) {
|
|
617
741
|
installForAgent(agent, scope)
|
|
@@ -701,6 +825,34 @@ function uninstall(): void {
|
|
|
701
825
|
console.log(" Removed .opencode/tools/memory.ts")
|
|
702
826
|
}
|
|
703
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
|
+
|
|
704
856
|
console.log("\n✅ toon-memory uninstalled from all agents\n")
|
|
705
857
|
}
|
|
706
858
|
|
|
@@ -781,16 +933,19 @@ function status(): void {
|
|
|
781
933
|
// Check instructions
|
|
782
934
|
const hasInstructions = agent.instructionFile ? existsSync(agent.instructionFile) : false
|
|
783
935
|
|
|
784
|
-
// Check hooks
|
|
936
|
+
// Check hooks / plugin
|
|
785
937
|
const hookPath = join(projectRoot, ".toon-memory", "hooks", `session-start-${agent.name}.sh`)
|
|
786
|
-
|
|
938
|
+
let hasHooks = existsSync(hookPath)
|
|
939
|
+
if (agent.needsPlugin) {
|
|
940
|
+
hasHooks = existsSync(join(projectRoot, ".opencode", "plugins", "toon-memory.ts"))
|
|
941
|
+
}
|
|
787
942
|
|
|
788
943
|
if (agent.format === "none") {
|
|
789
944
|
console.log(` ${hasInstructions ? "✅" : "❌"} ${agent.name} (instructions only)`)
|
|
790
945
|
} else {
|
|
791
946
|
const mcpStatus = configured ? "✅" : "❌"
|
|
792
947
|
const instrStatus = agent.needsInstructions ? (hasInstructions ? " 📝" : "") : ""
|
|
793
|
-
const hookStatus = agent.needsHooks ? (hasHooks ? " 🪝" : "") : ""
|
|
948
|
+
const hookStatus = (agent.needsHooks || agent.needsPlugin) ? (hasHooks ? " 🪝" : "") : ""
|
|
794
949
|
console.log(` ${mcpStatus} ${agent.name}${instrStatus}${hookStatus}`)
|
|
795
950
|
}
|
|
796
951
|
}
|
|
@@ -1228,56 +1383,156 @@ if (args[0] === "watch") {
|
|
|
1228
1383
|
process.exit(0)
|
|
1229
1384
|
}
|
|
1230
1385
|
|
|
1231
|
-
// Interactive installer
|
|
1232
|
-
|
|
1233
|
-
|
|
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
|
+
}
|
|
1234
1391
|
|
|
1235
|
-
console.log(
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
const indicator = hasConfig ? "✓" : "·"
|
|
1239
|
-
console.log(` ${indicator} ${i + 1}. ${a.name}`)
|
|
1240
|
-
})
|
|
1241
|
-
console.log("")
|
|
1392
|
+
console.log(`Comando desconocido: '${args[0]}'\n`)
|
|
1393
|
+
printUsage()
|
|
1394
|
+
process.exit(1)
|
|
1242
1395
|
|
|
1243
|
-
|
|
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
|
+
}
|
|
1244
1403
|
|
|
1245
|
-
|
|
1246
|
-
|
|
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
|
+
}
|
|
1247
1408
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
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
|
+
console.log("\n🧠 toon-memory installer\n")
|
|
1422
|
+
console.log("Agentes detectados:")
|
|
1423
|
+
agents.forEach((a: Agent, i: number) => {
|
|
1424
|
+
const hasConfig = a.format !== "none" && ((a.local && existsSync(a.local)) || (a.global && existsSync(a.global)))
|
|
1425
|
+
const indicator = hasConfig ? "✓" : "·"
|
|
1426
|
+
const scopeNote = a.format === "none" ? "(instrucciones)" : a.global ? "(local/global)" : "(solo local)"
|
|
1427
|
+
console.log(` ${indicator} ${i + 1}. ${a.name} ${scopeNote}`)
|
|
1428
|
+
})
|
|
1429
|
+
console.log("")
|
|
1430
|
+
|
|
1431
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
1432
|
+
|
|
1433
|
+
// 1) Agent selection
|
|
1434
|
+
let selected: Agent[] = []
|
|
1435
|
+
while (true) {
|
|
1436
|
+
const answer = (await ask(rl, "Selecciona agentes (números separados por comas, nombres, 'all', o Enter para todos; 'q' para salir): "))
|
|
1437
|
+
.trim()
|
|
1438
|
+
.toLowerCase()
|
|
1439
|
+
if (answer === "q") {
|
|
1440
|
+
console.log("\nInstalación cancelada.\n")
|
|
1441
|
+
rl.close()
|
|
1442
|
+
return
|
|
1443
|
+
}
|
|
1444
|
+
if (answer === "all" || answer === "") {
|
|
1445
|
+
selected = agents
|
|
1446
|
+
break
|
|
1447
|
+
}
|
|
1448
|
+
if (answer === "none") {
|
|
1449
|
+
selected = []
|
|
1450
|
+
break
|
|
1451
|
+
}
|
|
1452
|
+
const tokens = answer.split(",").map((s) => s.trim()).filter(Boolean)
|
|
1453
|
+
const matched: Agent[] = []
|
|
1454
|
+
let valid = true
|
|
1455
|
+
for (const tok of tokens) {
|
|
1456
|
+
const num = parseInt(tok, 10)
|
|
1457
|
+
if (!isNaN(num) && num >= 1 && num <= agents.length) {
|
|
1458
|
+
matched.push(agents[num - 1])
|
|
1459
|
+
} else {
|
|
1460
|
+
const found = agents.find((a) => a.name.toLowerCase() === tok)
|
|
1461
|
+
if (found) matched.push(found)
|
|
1462
|
+
else {
|
|
1463
|
+
console.log(` ⚠️ '${tok}' no coincide con ningún agente.`)
|
|
1464
|
+
valid = false
|
|
1465
|
+
break
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
if (valid && matched.length > 0) {
|
|
1470
|
+
selected = matched
|
|
1471
|
+
break
|
|
1472
|
+
}
|
|
1473
|
+
console.log("Intenta de nuevo.\n")
|
|
1256
1474
|
}
|
|
1257
1475
|
|
|
1258
1476
|
if (selected.length === 0) {
|
|
1259
|
-
console.log("\nNo
|
|
1477
|
+
console.log("\nNo se seleccionaron agentes. Nada instalado.\n")
|
|
1260
1478
|
rl.close()
|
|
1261
1479
|
return
|
|
1262
1480
|
}
|
|
1263
1481
|
|
|
1264
|
-
console.log(`\
|
|
1265
|
-
|
|
1266
|
-
rl.question("Installation scope — (1) Local or (2) Global? [1/2]: ", (scopeAnswer: string) => {
|
|
1267
|
-
const scope = scopeAnswer === "2" ? "global" : "local"
|
|
1268
|
-
console.log(`\nInstalling ${scope}ly...\n`)
|
|
1482
|
+
console.log(`\nSeleccionados: ${selected.map((a) => a.name).join(", ")}\n`)
|
|
1269
1483
|
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1484
|
+
// 2) Scope
|
|
1485
|
+
let scope = "local"
|
|
1486
|
+
while (true) {
|
|
1487
|
+
const scopeAnswer = (await ask(rl, "Alcance — (1) Local (proyecto) o (2) Global (~home)? [1/2]: ")).trim()
|
|
1488
|
+
if (scopeAnswer === "" || scopeAnswer === "1") {
|
|
1489
|
+
scope = "local"
|
|
1490
|
+
break
|
|
1491
|
+
}
|
|
1492
|
+
if (scopeAnswer === "2") {
|
|
1493
|
+
scope = "global"
|
|
1494
|
+
break
|
|
1275
1495
|
}
|
|
1496
|
+
console.log("Escribe 1 (local) o 2 (global).\n")
|
|
1497
|
+
}
|
|
1276
1498
|
|
|
1277
|
-
|
|
1499
|
+
// 3) Confirmation summary
|
|
1500
|
+
console.log("\nSe instalará:")
|
|
1501
|
+
for (const a of selected) {
|
|
1502
|
+
const resolved = scope === "global" && a.global ? "global" : "local"
|
|
1503
|
+
const parts: string[] = []
|
|
1504
|
+
if (a.format !== "none") parts.push("MCP")
|
|
1505
|
+
if (a.needsPlugin) parts.push("plugin")
|
|
1506
|
+
else if (a.needsHooks) parts.push("hooks")
|
|
1507
|
+
if (a.needsInstructions) parts.push("instrucciones")
|
|
1508
|
+
const target = resolved === "global" && a.global ? a.global : a.local || "(instrucciones)"
|
|
1509
|
+
console.log(` • ${a.name} [${resolved}] → ${target}${parts.length ? ` (${parts.join(", ")})` : ""}`)
|
|
1510
|
+
}
|
|
1278
1511
|
|
|
1279
|
-
|
|
1280
|
-
|
|
1512
|
+
const confirm = (await ask(rl, "\n¿Proceder? [Y/n]: ")).trim().toLowerCase()
|
|
1513
|
+
if (confirm === "n" || confirm === "no") {
|
|
1514
|
+
console.log("\nInstalación cancelada.\n")
|
|
1281
1515
|
rl.close()
|
|
1282
|
-
|
|
1283
|
-
}
|
|
1516
|
+
return
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
console.log(`\nInstalando (${scope})...\n`)
|
|
1520
|
+
installMemoryDir()
|
|
1521
|
+
|
|
1522
|
+
const deps = extractProjectDeps(projectRoot)
|
|
1523
|
+
if (Object.keys(deps).length > 0) {
|
|
1524
|
+
updateMemoryConfig({ vocab: deps })
|
|
1525
|
+
console.log(` Detected ${Object.keys(deps).length} dependencies → auto-tag vocabulary written to config.json`)
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
for (const agent of selected) {
|
|
1529
|
+
installForAgent(agent, scope)
|
|
1530
|
+
console.log("")
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
ensureGitignore()
|
|
1534
|
+
|
|
1535
|
+
console.log("Done! Restart your agent to use memory tools.")
|
|
1536
|
+
console.log("Run 'npx toon-memory uninstall' to remove.\n")
|
|
1537
|
+
rl.close()
|
|
1538
|
+
}
|