toon-memory 4.3.1 → 4.3.2
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 +9 -7
- package/mcp/server.js +14 -8
- package/package.json +1 -1
- package/src/cli/commands.ts +5 -3
- package/src/cli/constants.ts +7 -4
- package/src/mcp/archive.ts +16 -6
package/dist/cli/setup.js
CHANGED
|
@@ -3,10 +3,11 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
|
3
3
|
|
|
4
4
|
// src/cli/constants.ts
|
|
5
5
|
import { dirname, join } from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
6
7
|
var projectRoot = process.cwd();
|
|
7
8
|
var HOME = process.env.HOME || process.env.USERPROFILE || "~";
|
|
8
9
|
var MEMORY_DIR = join(projectRoot, ".toon-memory", "memory");
|
|
9
|
-
var scriptDir = dirname(
|
|
10
|
+
var scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
10
11
|
var CAPTURE_JS = join(scriptDir, "capture.js");
|
|
11
12
|
var SESSION_START_JS = join(scriptDir, "session-start.js");
|
|
12
13
|
var CAPTURE_CONFIG = join(MEMORY_DIR, "config.json");
|
|
@@ -1329,14 +1330,15 @@ function importMemory() {
|
|
|
1329
1330
|
if (existsSync9(memoryFile)) {
|
|
1330
1331
|
const existing = readFileSync9(memoryFile, "utf-8");
|
|
1331
1332
|
const existingCount = existing.split("\n").filter((l) => l.startsWith(" ") && l.includes("|")).length;
|
|
1333
|
+
const newCount = existingCount + newEntries.length;
|
|
1332
1334
|
const updated = existing.replace(
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
+
/^(version: 1\n)?(entries)?\[(\d+)\|/,
|
|
1336
|
+
(m, _v, prefix) => `${m.startsWith("version: 1\n") ? "version: 1\n" : ""}${prefix || ""}[${newCount}|`
|
|
1335
1337
|
) + "\n" + newLines;
|
|
1336
1338
|
writeFileSync7(memoryFile, updated);
|
|
1337
1339
|
} else {
|
|
1338
1340
|
writeFileSync7(memoryFile, `version: 1
|
|
1339
|
-
|
|
1341
|
+
[${newEntries.length}|]{id|category|key|content|file|tags|date}:
|
|
1340
1342
|
${newLines}
|
|
1341
1343
|
`);
|
|
1342
1344
|
}
|
|
@@ -1888,14 +1890,14 @@ function buildViewerData() {
|
|
|
1888
1890
|
// src/viewer/html.ts
|
|
1889
1891
|
import { readFileSync as readFileSync13 } from "fs";
|
|
1890
1892
|
import { resolve, dirname as dirname8 } from "path";
|
|
1891
|
-
import { fileURLToPath } from "url";
|
|
1893
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1892
1894
|
var d3Src = (() => {
|
|
1893
1895
|
try {
|
|
1894
|
-
const dir = dirname8(
|
|
1896
|
+
const dir = dirname8(fileURLToPath2(import.meta.url));
|
|
1895
1897
|
return readFileSync13(resolve(dir, "../src/viewer/d3.v7.min.js"), "utf-8");
|
|
1896
1898
|
} catch {
|
|
1897
1899
|
try {
|
|
1898
|
-
const dir = dirname8(
|
|
1900
|
+
const dir = dirname8(fileURLToPath2(import.meta.url));
|
|
1899
1901
|
return readFileSync13(resolve(dir, "d3.v7.min.js"), "utf-8");
|
|
1900
1902
|
} catch {
|
|
1901
1903
|
return null;
|
package/mcp/server.js
CHANGED
|
@@ -33218,10 +33218,16 @@ function readObservations() {
|
|
|
33218
33218
|
// src/mcp/archive.ts
|
|
33219
33219
|
import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
|
|
33220
33220
|
init_utils();
|
|
33221
|
+
function findHeaderIdx(lines) {
|
|
33222
|
+
return lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l));
|
|
33223
|
+
}
|
|
33224
|
+
function bumpHeaderCount(line, count) {
|
|
33225
|
+
return line.replace(/^([a-z]+)?\[(\d+)\|/, (_m2, pre) => `${pre || ""}[${count}|`);
|
|
33226
|
+
}
|
|
33221
33227
|
function archiveOldEntries(opts = {}) {
|
|
33222
33228
|
const data = readMemory();
|
|
33223
33229
|
const lines = data.split("\n");
|
|
33224
|
-
const headerIdx = lines
|
|
33230
|
+
const headerIdx = findHeaderIdx(lines);
|
|
33225
33231
|
if (headerIdx === -1) return { archived: 0, kept: 0 };
|
|
33226
33232
|
const today = /* @__PURE__ */ new Date();
|
|
33227
33233
|
const cutoff = new Date(today);
|
|
@@ -33262,14 +33268,14 @@ archived:
|
|
|
33262
33268
|
archiveLines.push(`archived[0|]{id|category|key|content|file|tags|date|ttl|accessed|links|quality|confidence}:`);
|
|
33263
33269
|
archiveHeaderIdx = archiveLines.length - 1;
|
|
33264
33270
|
}
|
|
33265
|
-
const archiveMatch = archiveLines[archiveHeaderIdx].match(
|
|
33271
|
+
const archiveMatch = archiveLines[archiveHeaderIdx].match(/\[(\d+)\|/);
|
|
33266
33272
|
const archiveCount = archiveMatch ? parseInt(archiveMatch[1]) : 0;
|
|
33267
33273
|
for (const entry of toArchiveLines) {
|
|
33268
33274
|
archiveLines.splice(archiveHeaderIdx + 1, 0, ` ${entry}`);
|
|
33269
33275
|
}
|
|
33270
|
-
archiveLines[archiveHeaderIdx] = archiveLines[archiveHeaderIdx]
|
|
33276
|
+
archiveLines[archiveHeaderIdx] = bumpHeaderCount(archiveLines[archiveHeaderIdx], archiveCount + toArchiveLines.length);
|
|
33271
33277
|
safeWrite(ARCHIVE_FILE, archiveLines.join("\n"));
|
|
33272
|
-
lines[headerIdx] = lines[headerIdx]
|
|
33278
|
+
lines[headerIdx] = bumpHeaderCount(lines[headerIdx], toKeepLines.length);
|
|
33273
33279
|
const keepSet = new Set(toKeepLines);
|
|
33274
33280
|
const allEntryLines = lines.slice(headerIdx + 1);
|
|
33275
33281
|
const newEntryLines = allEntryLines.filter((l) => {
|
|
@@ -33287,7 +33293,7 @@ function pruneExpiredEntries() {
|
|
|
33287
33293
|
withLockSync(MEMORY_FILE, () => {
|
|
33288
33294
|
const data = readMemory();
|
|
33289
33295
|
const lines = data.split("\n");
|
|
33290
|
-
const headerIdx = lines
|
|
33296
|
+
const headerIdx = findHeaderIdx(lines);
|
|
33291
33297
|
if (headerIdx === -1) return;
|
|
33292
33298
|
const entryLines2 = lines.slice(headerIdx + 1).filter((l) => l.trim().length > 0 && !l.startsWith(" summaries:"));
|
|
33293
33299
|
const kept = entryLines2.filter((l) => {
|
|
@@ -33301,7 +33307,7 @@ function pruneExpiredEntries() {
|
|
|
33301
33307
|
return true;
|
|
33302
33308
|
});
|
|
33303
33309
|
if (pruned === 0) return;
|
|
33304
|
-
lines[headerIdx] = lines[headerIdx]
|
|
33310
|
+
lines[headerIdx] = bumpHeaderCount(lines[headerIdx], kept.length);
|
|
33305
33311
|
const keepSet = new Set(kept.map((l) => l.trim()));
|
|
33306
33312
|
const allEntryLines = lines.slice(headerIdx + 1);
|
|
33307
33313
|
const newLines = allEntryLines.filter((l) => l.trim().length === 0 || keepSet.has(l.trim()));
|
|
@@ -48300,7 +48306,7 @@ function registerResources(server2) {
|
|
|
48300
48306
|
|
|
48301
48307
|
// src/mcp/server.ts
|
|
48302
48308
|
var server = new McpServer(
|
|
48303
|
-
{ name: "toon-memory", version: "4.3.
|
|
48309
|
+
{ name: "toon-memory", version: "4.3.2" },
|
|
48304
48310
|
{ capabilities: { tools: { listChanged: true }, resources: { listChanged: true }, experimental: { "io.modelcontextprotocol/ui": {} } } }
|
|
48305
48311
|
);
|
|
48306
48312
|
var s = server.server;
|
|
@@ -48312,7 +48318,7 @@ s.setRequestHandler(InitializeRequestSchema, async (request) => {
|
|
|
48312
48318
|
return {
|
|
48313
48319
|
protocolVersion,
|
|
48314
48320
|
capabilities: s.getCapabilities(),
|
|
48315
|
-
serverInfo: { name: "toon-memory", version: "4.3.
|
|
48321
|
+
serverInfo: { name: "toon-memory", version: "4.3.2" },
|
|
48316
48322
|
...s._instructions && { instructions: s._instructions }
|
|
48317
48323
|
};
|
|
48318
48324
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toon-memory",
|
|
3
3
|
"mcpName": "io.github.LuiggiVal08/toon-memory",
|
|
4
|
-
"version": "4.3.
|
|
4
|
+
"version": "4.3.2",
|
|
5
5
|
"description": "The Continuity Layer for AI Agents — an MCP memory server that preserves project knowledge, decisions, and conventions across sessions so every session starts where the last one ended. Offline, token-efficient, no LLM, no server; works with 15+ agents.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
package/src/cli/commands.ts
CHANGED
|
@@ -469,13 +469,15 @@ export function importMemory(): void {
|
|
|
469
469
|
const existing = readFileSync(memoryFile, "utf-8")
|
|
470
470
|
const existingCount = existing.split("\n")
|
|
471
471
|
.filter((l: string) => l.startsWith(" ") && l.includes("|")).length
|
|
472
|
+
const newCount = existingCount + newEntries.length
|
|
473
|
+
// Match either `entries[N|]` (MCP writers) or `[N|]` (CLI init) and keep the prefix.
|
|
472
474
|
const updated = existing.replace(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
+
/^(version: 1\n)?(entries)?\[(\d+)\|/,
|
|
476
|
+
(m, _v: string, prefix: string) => `${m.startsWith("version: 1\n") ? "version: 1\n" : ""}${prefix || ""}[${newCount}|`
|
|
475
477
|
) + "\n" + newLines
|
|
476
478
|
writeFileSync(memoryFile, updated)
|
|
477
479
|
} else {
|
|
478
|
-
writeFileSync(memoryFile, `version: 1\
|
|
480
|
+
writeFileSync(memoryFile, `version: 1\n[${newEntries.length}|]{id|category|key|content|file|tags|date}:\n${newLines}\n`)
|
|
479
481
|
}
|
|
480
482
|
|
|
481
483
|
console.log(`Imported ${newEntries.length} new entries`)
|
package/src/cli/constants.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, mkdirSync, writeFileSync } from "fs"
|
|
2
2
|
import { dirname, join } from "path"
|
|
3
|
+
import { fileURLToPath } from "url"
|
|
3
4
|
|
|
4
5
|
export const projectRoot = process.cwd()
|
|
5
6
|
export const HOME = process.env.HOME || process.env.USERPROFILE || "~"
|
|
@@ -8,11 +9,13 @@ export const HOME = process.env.HOME || process.env.USERPROFILE || "~"
|
|
|
8
9
|
export const MEMORY_DIR = join(projectRoot, ".toon-memory", "memory")
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* Directory containing the running CLI
|
|
12
|
-
* Derived from process.argv[1]
|
|
13
|
-
*
|
|
12
|
+
* Directory containing the running CLI bundle.
|
|
13
|
+
* Derived from import.meta.url (NOT process.argv[1], which the entry points
|
|
14
|
+
* overwrite with "toon-memory" — that made the paths resolve relative to the
|
|
15
|
+
* hook's CWD). Every CLI bundle lives in dist/cli/, so this resolves to an
|
|
16
|
+
* absolute path in the installed package.
|
|
14
17
|
*/
|
|
15
|
-
const scriptDir = dirname(
|
|
18
|
+
const scriptDir = dirname(fileURLToPath(import.meta.url))
|
|
16
19
|
|
|
17
20
|
/** Path to the compiled capture script (dist/cli/capture.js) */
|
|
18
21
|
export const CAPTURE_JS = join(scriptDir, "capture.js")
|
package/src/mcp/archive.ts
CHANGED
|
@@ -6,6 +6,16 @@ import { isExpired } from "./entries"
|
|
|
6
6
|
import { entryScoreForLine } from "./scoring"
|
|
7
7
|
import { parseToonLine } from "../lib/utils"
|
|
8
8
|
|
|
9
|
+
/** Match both header conventions: `entries[N|]` (MCP writers) and `[N|]` (CLI init). */
|
|
10
|
+
function findHeaderIdx(lines: string[]): number {
|
|
11
|
+
return lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Bump the entry count in a header line, preserving its `entries`/`archived` prefix if present. */
|
|
15
|
+
function bumpHeaderCount(line: string, count: number): string {
|
|
16
|
+
return line.replace(/^([a-z]+)?\[(\d+)\|/, (_m, pre: string) => `${pre || ""}[${count}|`)
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
/**
|
|
10
20
|
* Archive entries older than ARCHIVE_DAYS or with expired TTL.
|
|
11
21
|
* When `trimToMax` is set, also archive the lowest-importance entries
|
|
@@ -14,7 +24,7 @@ import { parseToonLine } from "../lib/utils"
|
|
|
14
24
|
export function archiveOldEntries(opts: { trimToMax?: boolean } = {}): { archived: number; kept: number } {
|
|
15
25
|
const data = readMemory()
|
|
16
26
|
const lines = data.split("\n")
|
|
17
|
-
const headerIdx = lines
|
|
27
|
+
const headerIdx = findHeaderIdx(lines)
|
|
18
28
|
|
|
19
29
|
if (headerIdx === -1) return { archived: 0, kept: 0 }
|
|
20
30
|
|
|
@@ -67,18 +77,18 @@ export function archiveOldEntries(opts: { trimToMax?: boolean } = {}): { archive
|
|
|
67
77
|
archiveHeaderIdx = archiveLines.length - 1
|
|
68
78
|
}
|
|
69
79
|
|
|
70
|
-
const archiveMatch = archiveLines[archiveHeaderIdx].match(
|
|
80
|
+
const archiveMatch = archiveLines[archiveHeaderIdx].match(/\[(\d+)\|/)
|
|
71
81
|
const archiveCount = archiveMatch ? parseInt(archiveMatch[1]) : 0
|
|
72
82
|
|
|
73
83
|
for (const entry of toArchiveLines) {
|
|
74
84
|
archiveLines.splice(archiveHeaderIdx + 1, 0, ` ${entry}`)
|
|
75
85
|
}
|
|
76
|
-
archiveLines[archiveHeaderIdx] = archiveLines[archiveHeaderIdx]
|
|
86
|
+
archiveLines[archiveHeaderIdx] = bumpHeaderCount(archiveLines[archiveHeaderIdx], archiveCount + toArchiveLines.length)
|
|
77
87
|
|
|
78
88
|
safeWrite(ARCHIVE_FILE, archiveLines.join("\n"))
|
|
79
89
|
|
|
80
90
|
// Update main file
|
|
81
|
-
lines[headerIdx] = lines[headerIdx]
|
|
91
|
+
lines[headerIdx] = bumpHeaderCount(lines[headerIdx], toKeepLines.length)
|
|
82
92
|
const keepSet = new Set(toKeepLines)
|
|
83
93
|
const allEntryLines = lines.slice(headerIdx + 1)
|
|
84
94
|
const newEntryLines = allEntryLines.filter((l) => {
|
|
@@ -104,7 +114,7 @@ export function pruneExpiredEntries(): number {
|
|
|
104
114
|
withLockSync(MEMORY_FILE, () => {
|
|
105
115
|
const data = readMemory()
|
|
106
116
|
const lines = data.split("\n")
|
|
107
|
-
const headerIdx = lines
|
|
117
|
+
const headerIdx = findHeaderIdx(lines)
|
|
108
118
|
if (headerIdx === -1) return
|
|
109
119
|
|
|
110
120
|
const entryLines = lines.slice(headerIdx + 1).filter((l) => l.trim().length > 0 && !l.startsWith(" summaries:"))
|
|
@@ -120,7 +130,7 @@ export function pruneExpiredEntries(): number {
|
|
|
120
130
|
})
|
|
121
131
|
if (pruned === 0) return
|
|
122
132
|
|
|
123
|
-
lines[headerIdx] = lines[headerIdx]
|
|
133
|
+
lines[headerIdx] = bumpHeaderCount(lines[headerIdx], kept.length)
|
|
124
134
|
const keepSet = new Set(kept.map((l) => l.trim()))
|
|
125
135
|
const allEntryLines = lines.slice(headerIdx + 1)
|
|
126
136
|
const newLines = allEntryLines.filter((l) => l.trim().length === 0 || keepSet.has(l.trim()))
|