toon-memory 2.8.0 → 2.9.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.
@@ -1,6 +1,6 @@
1
1
  // src/cli/capture.ts
2
- import { readFileSync as readFileSync3, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "fs";
3
- import { join as join2 } from "path";
2
+ import { readFileSync as readFileSync4, existsSync as existsSync4, mkdirSync as mkdirSync2 } from "fs";
3
+ import { join as join3 } from "path";
4
4
  import { createHash } from "crypto";
5
5
 
6
6
  // src/lib/lock.ts
@@ -171,15 +171,45 @@ function endSession(agent, sessionId) {
171
171
  heartbeat(agent, sessionId, { ended: true });
172
172
  }
173
173
 
174
- // src/cli/capture.ts
174
+ // src/mcp/observations.ts
175
+ import { readFileSync as readFileSync3, existsSync as existsSync3, writeFileSync as writeFileSync3 } from "fs";
176
+
177
+ // src/mcp/config.ts
178
+ import { join as join2 } from "path";
175
179
  var MEMORY_DIR = join2(process.cwd(), ".toon-memory", "memory");
180
+ var MEMORY_FILE = join2(MEMORY_DIR, "data.toon");
181
+ var ARCHIVE_FILE = join2(MEMORY_DIR, "archive.toon");
176
182
  var OBSERVATIONS_FILE = join2(MEMORY_DIR, "observations.toon");
177
183
  var CONFIG_FILE = join2(MEMORY_DIR, "config.json");
184
+
185
+ // src/mcp/observations.ts
186
+ var MAX_OBSERVATIONS = 500;
187
+ function pruneObservations() {
188
+ if (!existsSync3(OBSERVATIONS_FILE)) return 0;
189
+ const data = readFileSync3(OBSERVATIONS_FILE, "utf-8");
190
+ const lines = data.split("\n");
191
+ const headerIdx = lines.findIndex((l) => l.startsWith("observations["));
192
+ if (headerIdx === -1) return 0;
193
+ const entryLines = lines.slice(headerIdx + 1).filter((l) => l.trim().length > 0);
194
+ if (entryLines.length <= MAX_OBSERVATIONS) return 0;
195
+ const toRemove = entryLines.length - MAX_OBSERVATIONS;
196
+ const pruned = entryLines.slice(toRemove);
197
+ const kept = entryLines.slice(0, MAX_OBSERVATIONS);
198
+ lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${kept.length}|`);
199
+ lines.splice(headerIdx + 1, lines.length - headerIdx - 1, ...kept.map((l) => ` ${l.trim()}`));
200
+ writeFileSync3(OBSERVATIONS_FILE, lines.join("\n"));
201
+ return toRemove;
202
+ }
203
+
204
+ // src/cli/capture.ts
205
+ var MEMORY_DIR2 = join3(process.cwd(), ".toon-memory", "memory");
206
+ var OBSERVATIONS_FILE2 = join3(MEMORY_DIR2, "observations.toon");
207
+ var CONFIG_FILE2 = join3(MEMORY_DIR2, "config.json");
178
208
  var DEDUP_WINDOW_MS = 5 * 60 * 1e3;
179
209
  function captureEnabled() {
180
210
  if (process.env.TOON_MEMORY_CAPTURE) return true;
181
211
  try {
182
- const cfg = JSON.parse(readFileSync3(CONFIG_FILE, "utf-8"));
212
+ const cfg = JSON.parse(readFileSync4(CONFIG_FILE2, "utf-8"));
183
213
  if (cfg && cfg.capture) return true;
184
214
  } catch {
185
215
  }
@@ -218,11 +248,11 @@ function derive(tool, input) {
218
248
  return { file: String(file || "").trim(), summary };
219
249
  }
220
250
  function ensureMemoryDir() {
221
- if (!existsSync3(MEMORY_DIR)) mkdirSync2(MEMORY_DIR, { recursive: true });
251
+ if (!existsSync4(MEMORY_DIR2)) mkdirSync2(MEMORY_DIR2, { recursive: true });
222
252
  }
223
253
  function appendObservation(row) {
224
254
  ensureMemoryDir();
225
- let data = existsSync3(OBSERVATIONS_FILE) ? readFileSync3(OBSERVATIONS_FILE, "utf-8") : "version: 1\nobservations[0|]{ts|session|agent|branch|tool|hash|file|summary}:\n";
255
+ let data = existsSync4(OBSERVATIONS_FILE2) ? readFileSync4(OBSERVATIONS_FILE2, "utf-8") : "version: 1\nobservations[0|]{ts|session|agent|branch|tool|hash|file|summary}:\n";
226
256
  const lines = data.split("\n");
227
257
  let headerIdx = lines.findIndex((l) => l.startsWith("observations["));
228
258
  if (headerIdx === -1) {
@@ -235,13 +265,13 @@ function appendObservation(row) {
235
265
  const count = match ? parseInt(match[1]) : 0;
236
266
  lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count + 1}|`);
237
267
  lines.splice(headerIdx + 1, lines.length - headerIdx - 1, ...entryLines.map((l) => ` ${l}`));
238
- withLockSync(OBSERVATIONS_FILE, () => atomicWrite(OBSERVATIONS_FILE, lines.join("\n")));
268
+ withLockSync(OBSERVATIONS_FILE2, () => atomicWrite(OBSERVATIONS_FILE2, lines.join("\n")));
239
269
  }
240
270
  function main() {
241
271
  const agent = process.argv[2] || "agent";
242
272
  let raw = "";
243
273
  try {
244
- raw = readFileSync3(0, "utf-8");
274
+ raw = readFileSync4(0, "utf-8");
245
275
  } catch {
246
276
  process.exit(0);
247
277
  }
@@ -268,8 +298,8 @@ function main() {
268
298
  const hash = createHash("sha256").update(`${effectiveTool}|${normalized}`).digest("hex").slice(0, 16);
269
299
  const ts = (/* @__PURE__ */ new Date()).toISOString();
270
300
  const branch = currentBranch();
271
- if (existsSync3(OBSERVATIONS_FILE)) {
272
- const data = readFileSync3(OBSERVATIONS_FILE, "utf-8");
301
+ if (existsSync4(OBSERVATIONS_FILE2)) {
302
+ const data = readFileSync4(OBSERVATIONS_FILE2, "utf-8");
273
303
  for (const line of data.split("\n")) {
274
304
  if (!line.startsWith(" ")) continue;
275
305
  const p = line.trim().split("|");
@@ -281,6 +311,7 @@ function main() {
281
311
  }
282
312
  if (!isStop && !toolName) process.exit(0);
283
313
  appendObservation(`${ts}|${sessionId}|${agent}|${branch}|${effectiveTool}|${hash}|${file}|${summary}`);
314
+ pruneObservations();
284
315
  process.exit(0);
285
316
  }
286
317
  main();
@@ -177,25 +177,25 @@ function main() {
177
177
  const others = view.active.filter((s) => s.id !== sessionId && !s.ended);
178
178
  const lines = [];
179
179
  lines.push("toon-memory:");
180
- lines.push(` Esta sesi\xF3n: ${agent} @ ${currentBranch()} (ventana ${Math.round(SESSION_TTL_MS / 6e4)} min)`);
180
+ lines.push(` This session: ${agent} @ ${currentBranch()} (window ${Math.round(SESSION_TTL_MS / 6e4)} min)`);
181
181
  if (others.length > 0) {
182
- lines.push(` Otras sesiones activas (${others.length}):`);
182
+ lines.push(` Other active sessions (${others.length}):`);
183
183
  for (const s of others) {
184
184
  const files = Object.keys(s.files).slice(0, 5).join(", ") || "\u2014";
185
185
  lines.push(` \u2022 ${s.agent} @ ${s.branch} \u2014 ${files}`);
186
186
  }
187
187
  } else {
188
- lines.push(" Sin otras sesiones activas.");
188
+ lines.push(" No other active sessions.");
189
189
  }
190
190
  if (view.conflicts.length > 0) {
191
- lines.push(` \u26A0\uFE0F Conflictos suaves (${view.conflicts.length}): usa memory_sessions para ver detalle.`);
191
+ lines.push(` \u26A0\uFE0F Soft conflicts (${view.conflicts.length}): use memory_sessions for details.`);
192
192
  for (const c of view.conflicts) {
193
193
  lines.push(` \u2022 ${c.file}`);
194
194
  }
195
195
  } else {
196
- lines.push(" Sin conflictos de archivos detectados.");
196
+ lines.push(" No file conflicts detected.");
197
197
  }
198
- lines.push(" Usa memory_recall antes de leer archivos y memory_sessions para coordinar.");
198
+ lines.push(" Use memory_recall before reading files and memory_sessions to coordinate.");
199
199
  console.log(lines.join("\n"));
200
200
  process.exit(0);
201
201
  }
package/dist/cli/setup.js CHANGED
@@ -29,7 +29,7 @@ Persistent memory for this project. Use it to avoid re-investigating things.
29
29
  `;
30
30
  var OPENCODE_PASSIVE_INSTRUCTION = `# toon-memory
31
31
 
32
- La memoria se auto-inyecta v\xEDa .opencode/instructions/memory-autoload.md; usa memory_recall solo como fallback.
32
+ Memory auto-injects via .opencode/instructions/memory-autoload.md; use memory_recall only as fallback.
33
33
  `;
34
34
 
35
35
  // src/cli/capture-toggle.ts
@@ -46,11 +46,11 @@ function captureToggle(enable) {
46
46
  config.capture = enable;
47
47
  writeFileSync(CAPTURE_CONFIG, JSON.stringify(config, null, 2));
48
48
  if (enable) {
49
- console.log("\n\u{1F534} Captura de actividad HABILITADA.");
50
- console.log("Los hooks grabar\xE1n observaciones en .toon-memory/memory/observations.toon.");
51
- console.log("Revisa con `memory_captured` y promu\xE9velas con `memory_remember`.\n");
49
+ console.log("\n\u{1F534} Activity capture ENABLED.");
50
+ console.log("Hooks will write observations to .toon-memory/memory/observations.toon.");
51
+ console.log("Review with `memory_captured` and promote with `memory_remember`.\n");
52
52
  } else {
53
- console.log("\n\u26AA Captura de actividad DESHABILITADA.\n");
53
+ console.log("\n\u26AA Activity capture DISABLED.\n");
54
54
  }
55
55
  }
56
56
 
@@ -178,16 +178,18 @@ function detectAgents() {
178
178
  local: join3(projectRoot, ".cursor", "mcp.json"),
179
179
  mcpKey: "mcpServers",
180
180
  format: "json",
181
- needsHooks: false,
182
- needsInstructions: false
181
+ needsHooks: true,
182
+ needsInstructions: false,
183
+ captureJson: ["PostToolUse", "Stop"]
183
184
  });
184
185
  agents.push({
185
186
  name: "windsurf",
186
187
  global: join3(HOME, ".codeium", "windsurf", "mcp_config.json"),
187
188
  mcpKey: "mcpServers",
188
189
  format: "json",
189
- needsHooks: false,
190
- needsInstructions: false
190
+ needsHooks: true,
191
+ needsInstructions: false,
192
+ captureJson: ["PostToolUse", "Stop"]
191
193
  });
192
194
  agents.push({
193
195
  name: "cline",
@@ -222,7 +224,8 @@ function detectAgents() {
222
224
  format: "json",
223
225
  needsHooks: true,
224
226
  needsInstructions: true,
225
- instructionFile: join3(projectRoot, ".gemini", "GEMINI.md")
227
+ instructionFile: join3(projectRoot, ".gemini", "GEMINI.md"),
228
+ captureJson: ["PostToolUse", "Stop"]
226
229
  });
227
230
  agents.push({
228
231
  name: "zed",
@@ -721,9 +724,9 @@ var MEMORY_DIR2 = join7(projectRoot, ".toon-memory", "memory");
721
724
  var CAPTURE_CONFIG2 = join7(MEMORY_DIR2, "config.json");
722
725
  async function promptAgentSelection(agents) {
723
726
  return checkbox({
724
- message: "\xBFQu\xE9 agentes quieres configurar?",
727
+ message: "Which agents do you want to configure?",
725
728
  choices: agents.map((a) => ({
726
- name: `${a.name} (${a.format === "none" ? "instrucciones" : a.global ? "local/global" : "solo local"})`,
729
+ name: `${a.name} (${a.format === "none" ? "instructions" : a.global ? "local/global" : "local only"})`,
727
730
  value: a,
728
731
  checked: true
729
732
  }))
@@ -763,23 +766,23 @@ async function init(scope, agentFilter) {
763
766
  return;
764
767
  }
765
768
  finalScope = await select({
766
- message: "Alcance:",
769
+ message: "Scope:",
767
770
  choices: [
768
- { name: "Local (proyecto)", value: "local" },
771
+ { name: "Local (project)", value: "local" },
769
772
  { name: "Global (~home)", value: "global" }
770
773
  ],
771
774
  default: finalScope
772
775
  });
773
- const ok = await confirm({ message: "\xBFProceder?", default: true });
776
+ const ok = await confirm({ message: "Proceed?", default: true });
774
777
  if (!ok) {
775
- console.log("\nInstalaci\xF3n cancelada.\n");
778
+ console.log("\nInstallation cancelled.\n");
776
779
  return;
777
780
  }
778
781
  } else {
779
782
  selected = agents;
780
783
  }
781
784
  console.log(`
782
- Instalando (${finalScope}) \u2014 ${selected.map((a) => a.name).join(", ")}...
785
+ Installing (${finalScope}) \u2014 ${selected.map((a) => a.name).join(", ")}...
783
786
  `);
784
787
  for (const agent of selected) {
785
788
  installForAgent(agent, finalScope);
@@ -1089,30 +1092,30 @@ function dumpMemory() {
1089
1092
  }
1090
1093
  async function interactiveInstall() {
1091
1094
  if (!process.stdin.isTTY) {
1092
- console.log("\n\u{1F9E0} toon-memory \u2014 la instalaci\xF3n interactiva requiere una terminal.");
1093
- console.log("Ejecuta 'toon-memory init [--agent <nombre>]' para instalaci\xF3n no interactiva.\n");
1095
+ console.log("\n\u{1F9E0} toon-memory \u2014 interactive installation requires a terminal.");
1096
+ console.log("Run 'toon-memory init [--agent <name>]' for non-interactive installation.\n");
1094
1097
  return;
1095
1098
  }
1096
1099
  const agents = detectAgents();
1097
1100
  const selected = await promptAgentSelection(agents);
1098
1101
  if (selected.length === 0) {
1099
- console.log("\nNo se seleccionaron agentes. Nada instalado.\n");
1102
+ console.log("\nNo agents selected. Nothing installed.\n");
1100
1103
  return;
1101
1104
  }
1102
1105
  const scope = await select({
1103
- message: "Alcance:",
1106
+ message: "Scope:",
1104
1107
  choices: [
1105
- { name: "Local (proyecto)", value: "local" },
1108
+ { name: "Local (project)", value: "local" },
1106
1109
  { name: "Global (~home)", value: "global" }
1107
1110
  ]
1108
1111
  });
1109
- const ok = await confirm({ message: "\xBFProceder?", default: true });
1112
+ const ok = await confirm({ message: "Proceed?", default: true });
1110
1113
  if (!ok) {
1111
- console.log("\nInstalaci\xF3n cancelada.\n");
1114
+ console.log("\nInstallation cancelled.\n");
1112
1115
  return;
1113
1116
  }
1114
1117
  console.log(`
1115
- Instalando (${scope}) \u2014 ${selected.map((a) => a.name).join(", ")}...
1118
+ Installing (${scope}) \u2014 ${selected.map((a) => a.name).join(", ")}...
1116
1119
  `);
1117
1120
  installMemoryDir();
1118
1121
  const deps = extractProjectDeps(projectRoot);
@@ -1323,16 +1326,16 @@ if (args.length === 0) {
1323
1326
  await interactiveInstall();
1324
1327
  process.exit(0);
1325
1328
  }
1326
- console.log(`Comando desconocido: '${args[0]}'
1329
+ console.log(`Unknown command: '${args[0]}'
1327
1330
  `);
1328
1331
  printUsage();
1329
1332
  process.exit(1);
1330
1333
  function printUsage() {
1331
- console.log(`Uso: toon-memory <comando> [opciones]
1332
- Comandos: init, status, stats, export, import, watch, uninstall, capture, upgrade, mcp
1333
- Init: toon-memory init [--agent <nombre> --agent <nombre>...] [--scope local|global]
1334
- Sin --agent: selector interactivo de agentes y scope.
1335
- Con --agent: instalaci\xF3n no interactiva (default: scope local).
1336
- Opciones: -v/--version, -h/--help
1337
- Sin argumentos inicia el instalador interactivo.`);
1334
+ console.log(`Usage: toon-memory <command> [options]
1335
+ Commands: init, status, stats, export, import, watch, uninstall, capture, upgrade, mcp
1336
+ Init: toon-memory init [--agent <name> --agent <name>...] [--scope local|global]
1337
+ Without --agent: interactive agent and scope selector.
1338
+ With --agent: non-interactive installation (default: scope local).
1339
+ Options: -v/--version, -h/--help
1340
+ No arguments starts the interactive installer.`);
1338
1341
  }