toon-memory 1.6.2 → 1.6.3

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/mcp/server.js CHANGED
@@ -27801,14 +27801,31 @@ server.registerTool(
27801
27801
  lines.push(`[0|]`);
27802
27802
  headerIdx = lines.length - 1;
27803
27803
  }
27804
- const match = lines[headerIdx].match(/\[(\d+)\|/);
27805
- const count = match ? parseInt(match[1]) : 0;
27804
+ let existingIdx = -1;
27805
+ for (let i = headerIdx + 1; i < lines.length; i++) {
27806
+ const line = lines[i];
27807
+ if (!line.startsWith(" ") || !line.includes("|")) continue;
27808
+ if (line.startsWith(" summaries:")) break;
27809
+ const parts = line.trim().split("|");
27810
+ if (parts[2] === key) {
27811
+ existingIdx = i;
27812
+ break;
27813
+ }
27814
+ }
27806
27815
  const newEntry = `${id}|${category}|${key}|${content}|${file2 || ""}|${tags || ""}|${date5}`;
27807
- lines.splice(headerIdx + 1, 0, ` ${newEntry}`);
27808
- lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count + 1}|`);
27816
+ let action = "Guardado";
27817
+ if (existingIdx !== -1) {
27818
+ lines[existingIdx] = ` ${newEntry}`;
27819
+ action = "Actualizado";
27820
+ } else {
27821
+ const match = lines[headerIdx].match(/\[(\d+)\|/);
27822
+ const count = match ? parseInt(match[1]) : 0;
27823
+ lines.splice(headerIdx + 1, 0, ` ${newEntry}`);
27824
+ lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count + 1}|`);
27825
+ }
27809
27826
  writeMemory(lines.join("\n"));
27810
27827
  return {
27811
- content: [{ type: "text", text: `\u{1F9E0} Guardado: ${category}/${key} (${id})
27828
+ content: [{ type: "text", text: `\u{1F9E0} ${action}: ${category}/${key} (${id})
27812
27829
  ${content}` }]
27813
27830
  };
27814
27831
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toon-memory",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Persistent memory system for AI coding agents using TOON format (40% fewer tokens than JSON)",
5
5
  "type": "module",
6
6
  "bin": {
package/src/mcp/server.ts CHANGED
@@ -316,16 +316,37 @@ server.registerTool(
316
316
  headerIdx = lines.length - 1
317
317
  }
318
318
 
319
- const match = lines[headerIdx].match(/\[(\d+)\|/)
320
- const count = match ? parseInt(match[1]) : 0
319
+ // Find existing entry with same key (upsert)
320
+ let existingIdx = -1
321
+ for (let i = headerIdx + 1; i < lines.length; i++) {
322
+ const line = lines[i]
323
+ if (!line.startsWith(" ") || !line.includes("|")) continue
324
+ if (line.startsWith(" summaries:")) break
325
+ const parts = line.trim().split("|")
326
+ if (parts[2] === key) {
327
+ existingIdx = i
328
+ break
329
+ }
330
+ }
331
+
321
332
  const newEntry = `${id}|${category}|${key}|${content}|${file || ""}|${tags || ""}|${date}`
333
+ let action = "Guardado"
322
334
 
323
- lines.splice(headerIdx + 1, 0, ` ${newEntry}`)
324
- lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count + 1}|`)
335
+ if (existingIdx !== -1) {
336
+ // Update existing entry
337
+ lines[existingIdx] = ` ${newEntry}`
338
+ action = "Actualizado"
339
+ } else {
340
+ // Create new entry
341
+ const match = lines[headerIdx].match(/\[(\d+)\|/)
342
+ const count = match ? parseInt(match[1]) : 0
343
+ lines.splice(headerIdx + 1, 0, ` ${newEntry}`)
344
+ lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count + 1}|`)
345
+ }
325
346
 
326
347
  writeMemory(lines.join("\n"))
327
348
  return {
328
- content: [{ type: "text" as const, text: `🧠 Guardado: ${category}/${key} (${id})\n${content}` }],
349
+ content: [{ type: "text" as const, text: `🧠 ${action}: ${category}/${key} (${id})\n${content}` }],
329
350
  }
330
351
  }
331
352
  )