toon-memory 4.4.1 → 4.5.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.de.md +47 -9
- package/README.es.md +47 -9
- package/README.fr.md +47 -9
- package/README.ja.md +47 -9
- package/README.ko.md +47 -9
- package/README.md +9 -9
- package/README.pt-br.md +45 -9
- package/README.zh.md +47 -9
- package/bin/toon-memory.js +2 -0
- package/dist/cli/setup.js +261 -117
- package/mcp/server.js +114 -29
- package/package.json +5 -2
- package/src/bin/toon-memory.ts +2 -0
- package/src/cli/ambient.ts +4 -1
- package/src/cli/dense.ts +72 -18
- package/src/cli/setup.ts +1 -1
- package/src/lib/dense.ts +186 -25
- package/src/lib/quality.ts +5 -2
- package/src/mcp/config.ts +2 -0
- package/src/mcp/tools.ts +2 -1
package/mcp/server.js
CHANGED
|
@@ -23142,10 +23142,11 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
23142
23142
|
const ngBoost = ngMatch ? ngScore * 0.15 : 0;
|
|
23143
23143
|
let combined;
|
|
23144
23144
|
const utilityBoost = (opts.utility?.get(e.key) || 0) * 0.25;
|
|
23145
|
+
const denseBoost = (opts.dense?.get(e.key) || 0) * (opts.denseBoost ?? 0.25);
|
|
23145
23146
|
if (opts.rrf) {
|
|
23146
|
-
combined = (fused?.get(e.key) ?? 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost + evBoost + ngBoost + utilityBoost;
|
|
23147
|
+
combined = (fused?.get(e.key) ?? 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost + evBoost + ngBoost + utilityBoost + denseBoost;
|
|
23147
23148
|
} else {
|
|
23148
|
-
combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost + evBoost + utilityBoost;
|
|
23149
|
+
combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost + evBoost + utilityBoost + denseBoost;
|
|
23149
23150
|
}
|
|
23150
23151
|
return { entry: e, score: combined, matchesQuery, priority: e.priority, bm25Score };
|
|
23151
23152
|
}).filter((x) => x.score > 0 || x.matchesQuery).sort((a, b2) => {
|
|
@@ -35338,16 +35339,29 @@ function rebuildEdges(data, feedback = []) {
|
|
|
35338
35339
|
|
|
35339
35340
|
// src/lib/dense.ts
|
|
35340
35341
|
init_graph();
|
|
35342
|
+
import { createHash } from "crypto";
|
|
35341
35343
|
import { existsSync as existsSync14, mkdirSync as mkdirSync5, readFileSync as readFileSync12, writeFileSync as writeFileSync5 } from "fs";
|
|
35342
35344
|
import { dirname as dirname3 } from "path";
|
|
35343
|
-
|
|
35345
|
+
function activeEntries(data) {
|
|
35346
|
+
return parseEntries(data).filter((e) => e.status !== "obsolete" && e.status !== "draft");
|
|
35347
|
+
}
|
|
35348
|
+
function entryHash(entry) {
|
|
35349
|
+
return createHash("sha256").update(entry.key).update("\0").update(entry.content).digest("hex");
|
|
35350
|
+
}
|
|
35351
|
+
function sourceHash(entries) {
|
|
35352
|
+
const hash2 = createHash("sha256");
|
|
35353
|
+
for (const entry of entries) hash2.update(entry.key).update("\0").update(entry.content).update("\n");
|
|
35354
|
+
return hash2.digest("hex");
|
|
35355
|
+
}
|
|
35356
|
+
async function loadDenseModuleDetailed() {
|
|
35344
35357
|
const spec = process.env.TOON_MEMORY_DENSE_MODULE || "toon-memory-dense";
|
|
35345
35358
|
try {
|
|
35346
35359
|
const mod = await import(spec);
|
|
35347
35360
|
const embed = mod?.embed || mod?.default?.embed || mod?.default;
|
|
35348
|
-
|
|
35349
|
-
|
|
35350
|
-
|
|
35361
|
+
if (typeof embed !== "function") return { module: null, spec, error: "module does not export embed()" };
|
|
35362
|
+
return { module: { embed }, spec, error: "" };
|
|
35363
|
+
} catch (error51) {
|
|
35364
|
+
return { module: null, spec, error: error51 instanceof Error ? error51.message : String(error51) };
|
|
35351
35365
|
}
|
|
35352
35366
|
}
|
|
35353
35367
|
function cosine(a, b2) {
|
|
@@ -35372,67 +35386,138 @@ function readVectors() {
|
|
|
35372
35386
|
const buf = readFileSync12(VECTORS_FILE);
|
|
35373
35387
|
const newline = buf.indexOf(10);
|
|
35374
35388
|
if (newline === -1) return empty;
|
|
35375
|
-
const
|
|
35376
|
-
|
|
35377
|
-
const
|
|
35389
|
+
const header = buf.subarray(0, newline).toString("utf-8");
|
|
35390
|
+
const v1 = header.match(/^TMVEC1 (\d+)$/);
|
|
35391
|
+
const v22 = header.match(/^TMVEC2 (\d+)(?: (\S+))?(?: (\S+))?(?: (\S+))?$/);
|
|
35392
|
+
if (!v1 && !v22) return empty;
|
|
35393
|
+
const dim = Number((v1 || v22)[1]);
|
|
35378
35394
|
if (!Number.isFinite(dim) || dim <= 0) return empty;
|
|
35395
|
+
const version2 = v1 ? 1 : 2;
|
|
35396
|
+
const meta3 = v22 ? {
|
|
35397
|
+
model: v22[2] || "",
|
|
35398
|
+
builtAt: v22[3] || "",
|
|
35399
|
+
sourceHash: v22[4] || ""
|
|
35400
|
+
} : {};
|
|
35379
35401
|
let offset = newline + 1;
|
|
35380
35402
|
const vectors = /* @__PURE__ */ new Map();
|
|
35403
|
+
const hashes = /* @__PURE__ */ new Map();
|
|
35381
35404
|
while (offset + 2 <= buf.length) {
|
|
35382
35405
|
const len = buf.readUInt16BE(offset);
|
|
35383
35406
|
offset += 2;
|
|
35384
|
-
if (offset + len
|
|
35407
|
+
if (offset + len > buf.length) break;
|
|
35385
35408
|
const key = buf.subarray(offset, offset + len).toString("utf-8");
|
|
35386
35409
|
offset += len;
|
|
35410
|
+
if (version2 === 2) {
|
|
35411
|
+
if (offset + 2 > buf.length) break;
|
|
35412
|
+
const hashLen = buf.readUInt16BE(offset);
|
|
35413
|
+
offset += 2;
|
|
35414
|
+
if (offset + hashLen + dim * 4 > buf.length) break;
|
|
35415
|
+
hashes.set(key, buf.subarray(offset, offset + hashLen).toString("utf-8"));
|
|
35416
|
+
offset += hashLen;
|
|
35417
|
+
} else if (offset + dim * 4 > buf.length) break;
|
|
35387
35418
|
const vec = [];
|
|
35388
35419
|
for (let i = 0; i < dim; i++) vec.push(buf.readFloatLE(offset + i * 4));
|
|
35389
35420
|
offset += dim * 4;
|
|
35390
35421
|
vectors.set(key, vec);
|
|
35391
35422
|
}
|
|
35392
|
-
return { dim, vectors };
|
|
35423
|
+
return { dim, vectors, hashes, ...meta3 };
|
|
35393
35424
|
} catch {
|
|
35394
35425
|
return empty;
|
|
35395
35426
|
}
|
|
35396
35427
|
}
|
|
35397
|
-
function writeVectors(vectors, dim) {
|
|
35428
|
+
function writeVectors(vectors, dim, meta3 = {}) {
|
|
35398
35429
|
const dir = dirname3(VECTORS_FILE);
|
|
35399
35430
|
if (!existsSync14(dir)) mkdirSync5(dir, { recursive: true });
|
|
35400
|
-
const
|
|
35401
|
-
|
|
35431
|
+
const version2 = meta3.model || meta3.builtAt || meta3.sourceHash || meta3.hashes ? 2 : 1;
|
|
35432
|
+
const header = version2 === 2 ? `TMVEC2 ${dim} ${meta3.model || ""} ${meta3.builtAt || ""} ${meta3.sourceHash || ""}
|
|
35433
|
+
` : `TMVEC1 ${dim}
|
|
35434
|
+
`;
|
|
35435
|
+
const chunks = [Buffer.from(header, "utf-8")];
|
|
35402
35436
|
let written = 0;
|
|
35403
35437
|
for (const [key, vec] of vectors) {
|
|
35404
35438
|
if (vec.length !== dim) continue;
|
|
35405
35439
|
const keyBuf = Buffer.from(key, "utf-8");
|
|
35440
|
+
if (keyBuf.length > 65535) continue;
|
|
35406
35441
|
const lenBuf = Buffer.alloc(2);
|
|
35407
35442
|
lenBuf.writeUInt16BE(keyBuf.length);
|
|
35408
35443
|
const vecBuf = Buffer.alloc(dim * 4);
|
|
35409
35444
|
for (let i = 0; i < dim; i++) vecBuf.writeFloatLE(vec[i], i * 4);
|
|
35410
|
-
chunks.push(lenBuf, keyBuf
|
|
35445
|
+
chunks.push(lenBuf, keyBuf);
|
|
35446
|
+
if (version2 === 2) {
|
|
35447
|
+
const hashBuf = Buffer.from(meta3.hashes?.get(key) || "", "utf-8");
|
|
35448
|
+
const hashLenBuf = Buffer.alloc(2);
|
|
35449
|
+
hashLenBuf.writeUInt16BE(hashBuf.length);
|
|
35450
|
+
chunks.push(hashLenBuf, hashBuf);
|
|
35451
|
+
}
|
|
35452
|
+
chunks.push(vecBuf);
|
|
35411
35453
|
written++;
|
|
35412
35454
|
}
|
|
35413
35455
|
const out = Buffer.concat(chunks);
|
|
35414
35456
|
withLockSync(VECTORS_FILE, () => writeFileSync5(VECTORS_FILE, out));
|
|
35415
35457
|
return written;
|
|
35416
35458
|
}
|
|
35417
|
-
|
|
35418
|
-
const entries =
|
|
35459
|
+
function staleVectorCount(data, stored = readVectors()) {
|
|
35460
|
+
const entries = activeEntries(data);
|
|
35419
35461
|
if (entries.length === 0) return 0;
|
|
35420
|
-
|
|
35421
|
-
const
|
|
35422
|
-
|
|
35423
|
-
|
|
35424
|
-
|
|
35425
|
-
|
|
35462
|
+
let stale = 0;
|
|
35463
|
+
for (const entry of entries) {
|
|
35464
|
+
const vec = stored.vectors.get(entry.key);
|
|
35465
|
+
if (!vec || vec.length !== stored.dim) {
|
|
35466
|
+
stale++;
|
|
35467
|
+
continue;
|
|
35468
|
+
}
|
|
35469
|
+
const hash2 = stored.hashes?.get(entry.key);
|
|
35470
|
+
if (!hash2 || hash2 !== entryHash(entry)) stale++;
|
|
35471
|
+
}
|
|
35472
|
+
return stale;
|
|
35473
|
+
}
|
|
35474
|
+
async function rebuildVectors(data, module, model, opts = {}) {
|
|
35475
|
+
const entries = activeEntries(data);
|
|
35476
|
+
if (entries.length === 0) return { written: 0, reused: 0, removed: 0, stale: 0, dim: 0 };
|
|
35477
|
+
const stored = readVectors();
|
|
35478
|
+
const hashes = new Map(entries.map((entry) => [entry.key, entryHash(entry)]));
|
|
35479
|
+
const source = sourceHash(entries);
|
|
35480
|
+
const reused = /* @__PURE__ */ new Map();
|
|
35481
|
+
if (!opts.force && stored.model === (model || stored.model)) {
|
|
35482
|
+
for (const [key, hash2] of hashes) {
|
|
35483
|
+
const vec = stored.vectors.get(key);
|
|
35484
|
+
if (vec?.length === stored.dim && stored.hashes?.get(key) === hash2) reused.set(key, vec);
|
|
35485
|
+
}
|
|
35486
|
+
}
|
|
35487
|
+
const stale = entries.filter((entry) => !reused.has(entry.key));
|
|
35488
|
+
const embedded = stale.length ? await module.embed(stale.map((entry) => `${entry.key} ${entry.content}`), model) : [];
|
|
35489
|
+
const dim = reused.values().next().value?.length || embedded.find((vec) => vec?.length)?.length || stored.dim;
|
|
35490
|
+
if (!dim) return { written: 0, reused: 0, removed: 0, stale: stale.length, dim: 0 };
|
|
35491
|
+
const vectors = new Map(reused);
|
|
35492
|
+
let written = 0;
|
|
35493
|
+
stale.forEach((entry, i) => {
|
|
35494
|
+
const vec = embedded[i];
|
|
35495
|
+
if (vec?.length === dim) {
|
|
35496
|
+
vectors.set(entry.key, vec);
|
|
35497
|
+
written++;
|
|
35498
|
+
}
|
|
35499
|
+
});
|
|
35500
|
+
const removed = [...stored.vectors.keys()].filter((key) => !hashes.has(key)).length;
|
|
35501
|
+
for (const key of vectors.keys()) if (!hashes.has(key)) vectors.delete(key);
|
|
35502
|
+
writeVectors(vectors, dim, {
|
|
35503
|
+
model,
|
|
35504
|
+
hashes,
|
|
35505
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35506
|
+
sourceHash: source
|
|
35426
35507
|
});
|
|
35427
|
-
return
|
|
35508
|
+
return { written, reused: reused.size, removed, stale: stale.length, dim };
|
|
35428
35509
|
}
|
|
35429
35510
|
async function denseScores(query, data) {
|
|
35430
35511
|
const config2 = loadConfig();
|
|
35431
35512
|
if (!config2.dense?.enabled || !query.trim()) return /* @__PURE__ */ new Map();
|
|
35432
35513
|
try {
|
|
35433
|
-
const
|
|
35514
|
+
const detailed = await loadDenseModuleDetailed();
|
|
35515
|
+
const module = detailed.module;
|
|
35434
35516
|
if (!module) return /* @__PURE__ */ new Map();
|
|
35435
|
-
|
|
35517
|
+
const autoBuild = config2.dense.autoBuild !== false;
|
|
35518
|
+
if (autoBuild && (readVectors().vectors.size === 0 || staleVectorCount(data) > 0)) {
|
|
35519
|
+
await rebuildVectors(data, module, config2.dense.model);
|
|
35520
|
+
}
|
|
35436
35521
|
const stored = readVectors();
|
|
35437
35522
|
if (stored.vectors.size === 0) return /* @__PURE__ */ new Map();
|
|
35438
35523
|
const [queryVec] = await module.embed([query], config2.dense.model);
|
|
@@ -35491,7 +35576,7 @@ function registerTools(server2) {
|
|
|
35491
35576
|
return {
|
|
35492
35577
|
utility: utilityMap(),
|
|
35493
35578
|
...edges && edges.length ? { edges, activation: true } : {},
|
|
35494
|
-
...dense.size ? { dense } : {}
|
|
35579
|
+
...dense.size ? { dense, denseBoost: config2.dense?.boost ?? 0.25 } : {}
|
|
35495
35580
|
};
|
|
35496
35581
|
};
|
|
35497
35582
|
function softDelete(key) {
|
|
@@ -49734,7 +49819,7 @@ var INSTRUCTIONS = [
|
|
|
49734
49819
|
"Save decisions, directives and resolved bugs with memory_remember."
|
|
49735
49820
|
].join(" ");
|
|
49736
49821
|
var server = new McpServer(
|
|
49737
|
-
{ name: "toon-memory", version: "4.
|
|
49822
|
+
{ name: "toon-memory", version: "4.5.0" },
|
|
49738
49823
|
{
|
|
49739
49824
|
instructions: INSTRUCTIONS,
|
|
49740
49825
|
capabilities: { tools: { listChanged: true }, resources: { listChanged: true }, experimental: { "io.modelcontextprotocol/ui": {} } }
|
|
@@ -49749,7 +49834,7 @@ s.setRequestHandler(InitializeRequestSchema, async (request) => {
|
|
|
49749
49834
|
return {
|
|
49750
49835
|
protocolVersion,
|
|
49751
49836
|
capabilities: s.getCapabilities(),
|
|
49752
|
-
serverInfo: { name: "toon-memory", version: "4.
|
|
49837
|
+
serverInfo: { name: "toon-memory", version: "4.5.0" },
|
|
49753
49838
|
...s._instructions && { instructions: s._instructions }
|
|
49754
49839
|
};
|
|
49755
49840
|
});
|
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.
|
|
4
|
+
"version": "4.5.0",
|
|
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 20+ agents.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -35,7 +35,10 @@
|
|
|
35
35
|
"inspect": "npm run build && npx @modelcontextprotocol/inspector node bin/toon-memory.js mcp",
|
|
36
36
|
"prepublishOnly": "npm run build && npm test",
|
|
37
37
|
"bench:retrieval": "node scripts/bench-retrieval.mjs",
|
|
38
|
-
"bench:check": "node scripts/bench-check.mjs"
|
|
38
|
+
"bench:check": "node scripts/bench-check.mjs",
|
|
39
|
+
"bench:dense": "node scripts/bench-dense.mjs",
|
|
40
|
+
"bench:dense:check": "node scripts/bench-dense.mjs --check",
|
|
41
|
+
"doc:check": "node scripts/check-doc-metrics.mjs"
|
|
39
42
|
},
|
|
40
43
|
"dependencies": {
|
|
41
44
|
"@inquirer/checkbox": "^5.2.1",
|
package/src/bin/toon-memory.ts
CHANGED
|
@@ -39,6 +39,8 @@ Commands:
|
|
|
39
39
|
doctor Check memory path, signals and injection channel
|
|
40
40
|
signal --type <t> --summary <s> Append one deterministic signal
|
|
41
41
|
promote Promote high-confidence signals into memory
|
|
42
|
+
sleep Deterministic end-of-session consolidation (opt-in)
|
|
43
|
+
dense <status|enable|disable|build|install> Optional local embeddings (BM25 fallback)
|
|
42
44
|
upgrade Upgrade to the latest version
|
|
43
45
|
|
|
44
46
|
Options:
|
package/src/cli/ambient.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { readMemory, writeMemory } from "../mcp/memory-io"
|
|
|
15
15
|
import { MEMORY_DIR, MEMORY_FILE, CONFIG_FILE, GLOBAL_FILE } from "../mcp/config"
|
|
16
16
|
import { readSessionEntries, writeSessionEntry } from "../mcp/session-store"
|
|
17
17
|
import { parseEntries } from "../lib/graph"
|
|
18
|
+
import { denseDiagnostics } from "../lib/dense"
|
|
18
19
|
import { entryAgeDays, projectSlug } from "../lib/handoff"
|
|
19
20
|
|
|
20
21
|
function flag(args: string[], name: string): string {
|
|
@@ -75,7 +76,7 @@ export function runPromotion(args: string[]): void {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/** Read-only health check for the ambient loops. */
|
|
78
|
-
export function printDoctor(): void {
|
|
79
|
+
export async function printDoctor(): Promise<void> {
|
|
79
80
|
const root = process.cwd()
|
|
80
81
|
const lines: string[] = [
|
|
81
82
|
`toon-memory doctor — ${root}`,
|
|
@@ -112,6 +113,8 @@ export function printDoctor(): void {
|
|
|
112
113
|
lines.push("opencode plugin: absent")
|
|
113
114
|
}
|
|
114
115
|
lines.push(`injection: brief via 'toon-memory brief' (system.transform) | auto-write via 'signal' + 'promote'`)
|
|
116
|
+
const dense = await denseDiagnostics(readMemory())
|
|
117
|
+
lines.push(`dense: ${dense.enabled ? "enabled" : "disabled"} | module: ${dense.moduleLoaded ? "OK" : dense.error || "missing"} | vectors: ${dense.vectors}/${dense.stale} stale`)
|
|
115
118
|
lines.push(`catalog: ${process.env.TOON_MEMORY_EXPERT_TOOLS === "1" ? "expert" : "core"} (set TOON_MEMORY_EXPERT_TOOLS=1 for advanced tools)`)
|
|
116
119
|
console.log(lines.join("\n"))
|
|
117
120
|
}
|
package/src/cli/dense.ts
CHANGED
|
@@ -1,18 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawnSync } from "child_process"
|
|
2
|
+
import confirm from "@inquirer/confirm"
|
|
2
3
|
import { loadConfig, saveConfig, VECTORS_FILE } from "../mcp/config"
|
|
3
4
|
import { readMemory } from "../mcp/memory-io"
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
buildVectors,
|
|
7
|
+
denseDiagnostics,
|
|
8
|
+
loadDenseModuleDetailed,
|
|
9
|
+
rebuildVectors,
|
|
10
|
+
readVectors,
|
|
11
|
+
} from "../lib/dense"
|
|
5
12
|
|
|
6
13
|
export const DEFAULT_DENSE_MODEL = "multilingual-e5-small"
|
|
7
14
|
|
|
15
|
+
async function buildFromCurrent(args: string[]): Promise<void> {
|
|
16
|
+
const detailed = await loadDenseModuleDetailed()
|
|
17
|
+
if (!detailed.module) {
|
|
18
|
+
console.error(`Dense embedder not found (${detailed.spec}): ${detailed.error || "unavailable"}`)
|
|
19
|
+
console.error("Run 'toon-memory dense install' first.")
|
|
20
|
+
process.exitCode = 1
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
const config = loadConfig()
|
|
24
|
+
const stats = await rebuildVectors(readMemory(), detailed.module, config.dense?.model || DEFAULT_DENSE_MODEL, {
|
|
25
|
+
force: args.includes("--force"),
|
|
26
|
+
})
|
|
27
|
+
console.log(
|
|
28
|
+
`Vectors in ${VECTORS_FILE}: ${stats.written} built, ${stats.reused} reused, ${stats.removed} removed, dim ${stats.dim}.`
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
8
32
|
export async function runDense(args: string[]): Promise<void> {
|
|
9
33
|
const action = args[0] || "status"
|
|
10
34
|
const config = loadConfig()
|
|
11
35
|
const dense = config.dense || {}
|
|
12
36
|
|
|
13
37
|
if (action === "enable") {
|
|
14
|
-
|
|
15
|
-
|
|
38
|
+
const model = args[1] && !args[1].startsWith("--") ? args[1] : dense.model || DEFAULT_DENSE_MODEL
|
|
39
|
+
saveConfig({ ...config, dense: { ...dense, enabled: true, model } })
|
|
40
|
+
console.log(`Dense retrieval enabled (model: ${model}).`)
|
|
41
|
+
if (args.includes("--build")) await buildFromCurrent(args)
|
|
42
|
+
else console.log("Run 'toon-memory dense build' before relying on dense recall.")
|
|
16
43
|
return
|
|
17
44
|
}
|
|
18
45
|
|
|
@@ -23,28 +50,55 @@ export async function runDense(args: string[]): Promise<void> {
|
|
|
23
50
|
}
|
|
24
51
|
|
|
25
52
|
if (action === "install") {
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
const detailed = await loadDenseModuleDetailed()
|
|
54
|
+
if (detailed.module) {
|
|
55
|
+
console.log(`Dense embedder already available via ${detailed.spec}.`)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
const command = "npm install toon-memory-dense"
|
|
59
|
+
if (process.env.TOON_MEMORY_DENSE_MODULE) {
|
|
60
|
+
console.log(`TOON_MEMORY_DENSE_MODULE points to ${detailed.spec}; install that module manually.`)
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
if (args.includes("--dry-run") || (!args.includes("--yes") && !process.stdin.isTTY)) {
|
|
64
|
+
console.log(`Install the optional embedder locally: ${command}`)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
const ok = args.includes("--yes") || await confirm({ message: "Install toon-memory-dense in this project?", default: true })
|
|
68
|
+
if (!ok) {
|
|
69
|
+
console.log("Installation cancelled.")
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
const result = spawnSync("npm", ["install", "toon-memory-dense"], { stdio: "inherit" })
|
|
73
|
+
if (result.status !== 0) {
|
|
74
|
+
process.exitCode = 1
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
console.log("Embedder installed. Run 'toon-memory dense enable --build' to create vectors.")
|
|
28
78
|
return
|
|
29
79
|
}
|
|
30
80
|
|
|
31
81
|
if (action === "build") {
|
|
32
|
-
|
|
33
|
-
if (!module) {
|
|
34
|
-
console.error("Dense embedder not found. Run 'toon-memory dense install' first.")
|
|
35
|
-
process.exitCode = 1
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
const count = await buildVectors(readMemory(), module, dense.model || DEFAULT_DENSE_MODEL)
|
|
39
|
-
console.log(`Built vectors for ${count} entries in ${VECTORS_FILE}.`)
|
|
82
|
+
await buildFromCurrent(args)
|
|
40
83
|
return
|
|
41
84
|
}
|
|
42
85
|
|
|
86
|
+
const diagnostics = await denseDiagnostics(readMemory())
|
|
87
|
+
if (args.includes("--json")) {
|
|
88
|
+
console.log(JSON.stringify(diagnostics, null, 2))
|
|
89
|
+
return
|
|
90
|
+
}
|
|
43
91
|
const stored = readVectors()
|
|
44
92
|
console.log([
|
|
45
|
-
`dense: ${
|
|
46
|
-
`model: ${
|
|
47
|
-
`module: ${
|
|
48
|
-
`vectors: ${
|
|
93
|
+
`dense: ${diagnostics.enabled ? "enabled" : "disabled"}`,
|
|
94
|
+
`model: ${diagnostics.model || DEFAULT_DENSE_MODEL}`,
|
|
95
|
+
`module: ${diagnostics.moduleSpec} (${diagnostics.moduleLoaded ? "loaded" : diagnostics.error || "missing"})`,
|
|
96
|
+
`vectors: ${stored.vectors.size} entries, dim ${stored.dim}`,
|
|
97
|
+
`stale: ${diagnostics.stale}`,
|
|
98
|
+
`boost: ${diagnostics.boost}`,
|
|
99
|
+
`auto-build: ${diagnostics.autoBuild ? "on" : "off"}`,
|
|
100
|
+
`built: ${diagnostics.builtAt || "never"}`,
|
|
49
101
|
].join("\n"))
|
|
50
102
|
}
|
|
103
|
+
|
|
104
|
+
export { buildVectors }
|