toon-memory 3.6.1 → 3.7.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 +21 -3
- package/dist/cli/setup.js +14 -2
- package/mcp/server.js +527 -65
- package/package.json +3 -2
- package/src/lib/graph.ts +114 -11
- package/src/lib/quality.ts +44 -15
- package/src/mcp/tools.ts +458 -8
package/mcp/server.js
CHANGED
|
@@ -22158,6 +22158,22 @@ var init_fuzzy = __esm({
|
|
|
22158
22158
|
});
|
|
22159
22159
|
|
|
22160
22160
|
// src/lib/graph.ts
|
|
22161
|
+
function parseLinkToken(token) {
|
|
22162
|
+
const idx = token.lastIndexOf(":");
|
|
22163
|
+
if (idx === -1) return { type: DEFAULT_EDGE_TYPE, key: token };
|
|
22164
|
+
const type = token.slice(0, idx);
|
|
22165
|
+
const key = token.slice(idx + 1);
|
|
22166
|
+
return { type: type || DEFAULT_EDGE_TYPE, key: key || token };
|
|
22167
|
+
}
|
|
22168
|
+
function linkKey(token) {
|
|
22169
|
+
return parseLinkToken(token).key;
|
|
22170
|
+
}
|
|
22171
|
+
function formatLink(type, key) {
|
|
22172
|
+
return type && type !== DEFAULT_EDGE_TYPE ? `${type}:${key}` : key;
|
|
22173
|
+
}
|
|
22174
|
+
function typedLinks(links) {
|
|
22175
|
+
return links.map(parseLinkToken);
|
|
22176
|
+
}
|
|
22161
22177
|
function parseEntries(data) {
|
|
22162
22178
|
const out = [];
|
|
22163
22179
|
for (const line of entryLines(data)) {
|
|
@@ -22179,7 +22195,8 @@ function parseEntries(data) {
|
|
|
22179
22195
|
priority: parts.length > 13 ? parseInt(parts[13]) || 0 : 0,
|
|
22180
22196
|
path_scope: parts.length > 14 ? parts[14] || "" : "",
|
|
22181
22197
|
origin: parts.length > 15 && parts[15] ? parts[15] : "agent",
|
|
22182
|
-
status: parts.length > 16 && parts[16] ? parts[16] : "active"
|
|
22198
|
+
status: parts.length > 16 && parts[16] ? parts[16] : "active",
|
|
22199
|
+
supersededOn: parts.length > 17 ? parts[17] || "" : ""
|
|
22183
22200
|
});
|
|
22184
22201
|
}
|
|
22185
22202
|
return out;
|
|
@@ -22199,7 +22216,7 @@ function buildGraph(entries) {
|
|
|
22199
22216
|
adj.get(b2).add(a);
|
|
22200
22217
|
};
|
|
22201
22218
|
for (const e of entries) {
|
|
22202
|
-
for (const l of e.links) link(e.key, l);
|
|
22219
|
+
for (const l of e.links) link(e.key, linkKey(l));
|
|
22203
22220
|
const refs = e.content.match(/\[\[([\w-]+)\]\]/g) || [];
|
|
22204
22221
|
for (const r2 of refs) link(e.key, r2.slice(2, -2));
|
|
22205
22222
|
}
|
|
@@ -22221,6 +22238,23 @@ function buildGraph(entries) {
|
|
|
22221
22238
|
for (const [k3, v3] of adj) adjacency.set(k3, [...v3]);
|
|
22222
22239
|
return { adjacency, byKey };
|
|
22223
22240
|
}
|
|
22241
|
+
function rrfFuse(rankers, k3 = 60) {
|
|
22242
|
+
const out = /* @__PURE__ */ new Map();
|
|
22243
|
+
for (const ranker of rankers) {
|
|
22244
|
+
for (const [key, rank] of ranker) {
|
|
22245
|
+
out.set(key, (out.get(key) || 0) + 1 / (k3 + rank));
|
|
22246
|
+
}
|
|
22247
|
+
}
|
|
22248
|
+
return out;
|
|
22249
|
+
}
|
|
22250
|
+
function rrfK(candidateCount) {
|
|
22251
|
+
return Math.max(3, Math.min(60, Math.round(Math.sqrt(candidateCount))));
|
|
22252
|
+
}
|
|
22253
|
+
function rankBy(score) {
|
|
22254
|
+
const out = /* @__PURE__ */ new Map();
|
|
22255
|
+
[...score.entries()].sort((a, b2) => b2[1] - a[1]).forEach(([key], i) => out.set(key, i));
|
|
22256
|
+
return out;
|
|
22257
|
+
}
|
|
22224
22258
|
function bm25Scores(entries, query) {
|
|
22225
22259
|
const N = entries.length;
|
|
22226
22260
|
const scores = /* @__PURE__ */ new Map();
|
|
@@ -22275,8 +22309,12 @@ function graphRecallDetailed(data, query, opts = {}) {
|
|
|
22275
22309
|
const bm25 = bm25Scores(entries, query);
|
|
22276
22310
|
const cent = centrality(adjacency);
|
|
22277
22311
|
const seedKeys = /* @__PURE__ */ new Set();
|
|
22312
|
+
const asOf = opts.asOf || "";
|
|
22278
22313
|
for (const e of entries) {
|
|
22279
|
-
if (e.status === "obsolete")
|
|
22314
|
+
if (e.status === "obsolete" || e.status === "draft") {
|
|
22315
|
+
if (!(asOf && e.status === "obsolete" && e.supersededOn && e.supersededOn > asOf)) continue;
|
|
22316
|
+
}
|
|
22317
|
+
if (asOf && e.date && e.date > asOf) continue;
|
|
22280
22318
|
if (category && e.category !== category) continue;
|
|
22281
22319
|
if (tagsFilter.length > 0 && !tagsFilter.every((t) => e.tags.includes(t))) continue;
|
|
22282
22320
|
if (from_date && e.date < from_date) continue;
|
|
@@ -22294,9 +22332,16 @@ function graphRecallDetailed(data, query, opts = {}) {
|
|
|
22294
22332
|
}
|
|
22295
22333
|
let selected;
|
|
22296
22334
|
const scored = [];
|
|
22335
|
+
const visibleEntries = entries.filter((e) => {
|
|
22336
|
+
if (e.status === "obsolete" || e.status === "draft") {
|
|
22337
|
+
return !!(asOf && e.status === "obsolete" && e.supersededOn && e.supersededOn > asOf);
|
|
22338
|
+
}
|
|
22339
|
+
return !(asOf && e.date && e.date > asOf);
|
|
22340
|
+
});
|
|
22341
|
+
const isVisible = new Set(visibleEntries.map((e) => e.key));
|
|
22297
22342
|
if (seedKeys.size === 0) {
|
|
22298
22343
|
scored.push(
|
|
22299
|
-
...
|
|
22344
|
+
...visibleEntries.sort((a, b2) => {
|
|
22300
22345
|
if (a.priority !== b2.priority) return b2.priority - a.priority;
|
|
22301
22346
|
return importance(b2) - importance(a);
|
|
22302
22347
|
}).slice(0, opts.limit ?? 6).map((e) => ({ e, s: importance(e) }))
|
|
@@ -22311,16 +22356,21 @@ function graphRecallDetailed(data, query, opts = {}) {
|
|
|
22311
22356
|
best.set(key, dist);
|
|
22312
22357
|
if (dist >= hops) continue;
|
|
22313
22358
|
for (const nb2 of adjacency.get(key) || []) {
|
|
22359
|
+
if (!isVisible.has(nb2)) continue;
|
|
22314
22360
|
queue.push({ key: nb2, dist: dist + 1 });
|
|
22315
22361
|
}
|
|
22316
22362
|
}
|
|
22363
|
+
const sub = (m3) => new Map([...m3].filter(([k3]) => isVisible.has(k3)));
|
|
22364
|
+
const bm25Rank = rankBy(sub(bm25));
|
|
22365
|
+
const centRank = rankBy(sub(cent));
|
|
22366
|
+
const fused = opts.rrf ? rrfFuse([bm25Rank, bm25Rank, bm25Rank, centRank], rrfK(bm25Rank.size)) : null;
|
|
22317
22367
|
scored.push(
|
|
22318
22368
|
...[...best.keys()].map((k3) => {
|
|
22319
22369
|
const e = byKey.get(k3);
|
|
22320
22370
|
const dist = best.get(k3);
|
|
22321
22371
|
const decay = Math.pow(DECAY, dist);
|
|
22322
|
-
let s2 = (bm25.get(k3) || 0) + W_CENT * cent.get(k3) + W_IMP * importance(e);
|
|
22323
|
-
if (seedKeys.has(k3)) s2 += SEED_BONUS;
|
|
22372
|
+
let s2 = fused ? fused.get(k3) || 0 : (bm25.get(k3) || 0) + W_CENT * (cent.get(k3) || 0) + W_IMP * importance(e);
|
|
22373
|
+
if (!fused && seedKeys.has(k3)) s2 += SEED_BONUS;
|
|
22324
22374
|
if (opts.sessionFiles && opts.sessionFiles.length > 0 && e.file) {
|
|
22325
22375
|
const entryFile = e.file.split(":")[0];
|
|
22326
22376
|
if (opts.sessionFiles.some((f3) => f3 === entryFile)) {
|
|
@@ -22336,7 +22386,7 @@ function graphRecallDetailed(data, query, opts = {}) {
|
|
|
22336
22386
|
);
|
|
22337
22387
|
}
|
|
22338
22388
|
selected = scored.map((x) => x.e);
|
|
22339
|
-
const pinnedKeys = new Set(
|
|
22389
|
+
const pinnedKeys = new Set(visibleEntries.filter((e) => e.priority > 0).map((e) => e.key));
|
|
22340
22390
|
const inResult = new Set(selected.map((e) => e.key));
|
|
22341
22391
|
const toInject = [...pinnedKeys].filter((k3) => !inResult.has(k3) && byKey.has(k3)).map((k3) => byKey.get(k3)).sort((a, b2) => b2.priority - a.priority);
|
|
22342
22392
|
for (const e of toInject) {
|
|
@@ -22390,9 +22440,10 @@ function renderCompact(entries, opts = {}) {
|
|
|
22390
22440
|
const originInfo = e.origin !== "agent" ? ` \xB7 origin: ${e.origin}` : "";
|
|
22391
22441
|
const scopeInfo = e.path_scope ? ` \xB7 scope: ${e.path_scope}` : "";
|
|
22392
22442
|
const statusInfo = e.status !== "active" ? ` \xB7 status: ${e.status}` : "";
|
|
22443
|
+
const supersededInfo = e.supersededOn ? ` \xB7 superseded: ${e.supersededOn}` : "";
|
|
22393
22444
|
return `[${n}] ${e.category}/${e.key}${pin} (${e.id})
|
|
22394
22445
|
${e.content}
|
|
22395
|
-
File: ${e.file} | Tags: ${e.tags.join(";")} | Date: ${e.date}${ttlInfo}${accessInfo}${lastAccess}${originInfo}${scopeInfo}${statusInfo}${links}`;
|
|
22446
|
+
File: ${e.file} | Tags: ${e.tags.join(";")} | Date: ${e.date}${ttlInfo}${accessInfo}${lastAccess}${originInfo}${scopeInfo}${statusInfo}${supersededInfo}${links}`;
|
|
22396
22447
|
}
|
|
22397
22448
|
let body = e.content;
|
|
22398
22449
|
if (!isSeed && e.content.length > snippetLen) {
|
|
@@ -22409,13 +22460,14 @@ function renderCompact(entries, opts = {}) {
|
|
|
22409
22460
|
${body}${tags}${edges}`;
|
|
22410
22461
|
}).join("\n\n");
|
|
22411
22462
|
}
|
|
22412
|
-
var entryLines, W_CENT, W_IMP, SEED_BONUS, DECAY;
|
|
22463
|
+
var DEFAULT_EDGE_TYPE, entryLines, W_CENT, W_IMP, SEED_BONUS, DECAY;
|
|
22413
22464
|
var init_graph = __esm({
|
|
22414
22465
|
"src/lib/graph.ts"() {
|
|
22415
22466
|
"use strict";
|
|
22416
22467
|
init_utils();
|
|
22417
22468
|
init_synonyms();
|
|
22418
22469
|
init_fuzzy();
|
|
22470
|
+
DEFAULT_EDGE_TYPE = "related";
|
|
22419
22471
|
entryLines = (data) => data.split("\n").filter(
|
|
22420
22472
|
(l) => l.startsWith(" ") && l.includes("|") && !l.startsWith(" summaries:")
|
|
22421
22473
|
);
|
|
@@ -22522,7 +22574,8 @@ function mergeEntries(existingLine, newLine) {
|
|
|
22522
22574
|
const existingStatus = ep2.length > 16 ? ep2[16] || "" : "";
|
|
22523
22575
|
const newStatus = np2.length > 16 ? np2[16] || "" : "";
|
|
22524
22576
|
const status = newStatus === "active" || existingStatus === "active" ? "active" : newStatus || existingStatus || "active";
|
|
22525
|
-
|
|
22577
|
+
const existingSupersededOn = ep2.length > 17 ? ep2[17] || "" : "";
|
|
22578
|
+
return `${id2}|${category}|${key}|${content}|${file2}|${mergedTags}|${date5}|${ttl}|${accessed}|${mergedLinks}|${quality.toFixed(2)}|${confidence}|${lastAccessed}|${priority}|${path_scope}|${origin}|${status}|${existingSupersededOn}`;
|
|
22526
22579
|
}
|
|
22527
22580
|
function generateSmartRecall(data, intent, opts = {}) {
|
|
22528
22581
|
const entries = parseEntries(data);
|
|
@@ -22535,11 +22588,16 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
22535
22588
|
const mtimes = opts.fileMtimes;
|
|
22536
22589
|
const qTokens = tokenize(intent);
|
|
22537
22590
|
const expandedTokens = expandSynonyms(qTokens);
|
|
22538
|
-
const
|
|
22591
|
+
const eligible = entries.filter((e) => {
|
|
22539
22592
|
if (category && e.category !== category) return false;
|
|
22540
22593
|
if (e.ttl && isExpiredLocal(e.ttl)) return false;
|
|
22594
|
+
if (e.status === "obsolete" || e.status === "draft") return false;
|
|
22541
22595
|
return true;
|
|
22542
|
-
})
|
|
22596
|
+
});
|
|
22597
|
+
const bm25Rank = rankBy(new Map([...bm25].filter(([k3]) => eligible.some((e) => e.key === k3))));
|
|
22598
|
+
const centRank = rankBy(new Map([...cent].filter(([k3]) => eligible.some((e) => e.key === k3))));
|
|
22599
|
+
const fused = opts.rrf ? rrfFuse([bm25Rank, bm25Rank, bm25Rank, centRank], rrfK(bm25Rank.size)) : null;
|
|
22600
|
+
const scored = eligible.map((e) => {
|
|
22543
22601
|
const text = normalize(
|
|
22544
22602
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
22545
22603
|
);
|
|
@@ -22563,20 +22621,25 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
22563
22621
|
sessionBias = 0.15;
|
|
22564
22622
|
}
|
|
22565
22623
|
}
|
|
22566
|
-
|
|
22624
|
+
let combined;
|
|
22625
|
+
if (opts.rrf) {
|
|
22626
|
+
combined = (fused?.get(e.key) ?? 0) - drift + sessionBias;
|
|
22627
|
+
} else {
|
|
22628
|
+
combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift + sessionBias;
|
|
22629
|
+
}
|
|
22567
22630
|
return { entry: e, score: combined, matchesQuery, priority: e.priority };
|
|
22568
22631
|
}).filter((x) => x.score > 0 || x.matchesQuery).sort((a, b2) => {
|
|
22569
22632
|
if (a.priority !== b2.priority) return b2.priority - a.priority;
|
|
22570
22633
|
return b2.score - a.score;
|
|
22571
22634
|
}).slice(0, limit);
|
|
22572
|
-
const pinnedKeys = new Set(
|
|
22635
|
+
const pinnedKeys = new Set(eligible.filter((e) => e.priority > 0).map((e) => e.key));
|
|
22573
22636
|
const inResult = new Set(scored.map((x) => x.entry.key));
|
|
22574
|
-
const toInject = [...pinnedKeys].filter((k3) => !inResult.has(k3)).map((k3) =>
|
|
22637
|
+
const toInject = [...pinnedKeys].filter((k3) => !inResult.has(k3)).map((k3) => eligible.find((en2) => en2.key === k3)).filter(Boolean).sort((a, b2) => b2.priority - a.priority);
|
|
22575
22638
|
for (const e of toInject) {
|
|
22576
22639
|
scored.unshift({ entry: e, score: 999, matchesQuery: false, priority: e.priority });
|
|
22577
22640
|
}
|
|
22578
22641
|
if (scored.length === 0) {
|
|
22579
|
-
const top =
|
|
22642
|
+
const top = eligible.sort((a, b2) => {
|
|
22580
22643
|
if (a.priority !== b2.priority) return b2.priority - a.priority;
|
|
22581
22644
|
return importance(b2) - importance(a);
|
|
22582
22645
|
}).slice(0, limit);
|
|
@@ -33996,7 +34059,8 @@ function registerTools(server2) {
|
|
|
33996
34059
|
links: external_exports.string().optional().default("").describe("Related entry keys, separated by space or ';' (e.g. risk-spec engine-arch). Builds graph edges."),
|
|
33997
34060
|
path_scope: external_exports.string().optional().default("").describe("Glob pattern to scope this entry (e.g. src/**.ts). Empty = global."),
|
|
33998
34061
|
origin: external_exports.enum(["human", "agent", "inferred"]).optional().default("agent").describe("Who created this entry.")
|
|
33999
|
-
}
|
|
34062
|
+
},
|
|
34063
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
34000
34064
|
},
|
|
34001
34065
|
async ({ category, key, content, file: file2, tags, ttl, links, path_scope, origin }) => {
|
|
34002
34066
|
const data = readMemory();
|
|
@@ -34093,14 +34157,17 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
34093
34157
|
compact: external_exports.boolean().optional().default(false).describe("Token-efficient output: numeric indices (1, 2), omits id/date/file (keeps tags), edges as '->2', truncates graph neighbors to a snippet. Does not mutate .toon file."),
|
|
34094
34158
|
budget: external_exports.enum(["tiny", "normal", "deep"]).optional().default("deep").describe("'tiny': key+1 line (~50 tokens). 'normal': compact with tags/edges. 'deep': all fields (default). Overrides 'compact'."),
|
|
34095
34159
|
bias: external_exports.enum(["none", "session"]).optional().default("none").describe("'session': boost entries whose file matches current session files. 'none': no bias (default)."),
|
|
34096
|
-
path_scope: external_exports.string().optional().default("").describe("Glob pattern to filter entries by path scope (e.g. 'src/**.ts').")
|
|
34097
|
-
|
|
34160
|
+
path_scope: external_exports.string().optional().default("").describe("Glob pattern to filter entries by path scope (e.g. 'src/**.ts')."),
|
|
34161
|
+
rrf: external_exports.boolean().optional().default(false).describe("Use Reciprocal Rank Fusion (BM25x3 + centrality ranks, adaptive k=sqrtN) instead of weighted linear scoring. Weight-free: reaches parity with the tuned linear scorer on scripts/bench-rrf.mjs."),
|
|
34162
|
+
as_of: external_exports.string().optional().default("").describe("Temporal view (YYYY-MM-DD): return entries valid on that date. Superseded entries still appear if they were active then.")
|
|
34163
|
+
},
|
|
34164
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
34098
34165
|
},
|
|
34099
|
-
async ({ query, category, from_date, to_date, mode, hops, compact, bias, budget: budgetParam, path_scope }) => {
|
|
34166
|
+
async ({ query, category, from_date, to_date, mode, hops, compact, bias, budget: budgetParam, path_scope, rrf, as_of }) => {
|
|
34100
34167
|
const data = readMemory();
|
|
34101
34168
|
const sessionFiles = bias === "session" ? getCurrentSessionFiles() : void 0;
|
|
34102
34169
|
const resolvedBudget = budgetParam || (compact ? "normal" : "deep");
|
|
34103
|
-
const detail = graphRecallDetailed(data, query, { category, from_date, to_date, hops, sessionFiles, path_scope: path_scope || void 0 });
|
|
34170
|
+
const detail = graphRecallDetailed(data, query, { category, from_date, to_date, hops, sessionFiles, path_scope: path_scope || void 0, rrf, asOf: as_of || void 0 });
|
|
34104
34171
|
if (detail.entries.length === 0) {
|
|
34105
34172
|
return { content: [{ type: "text", text: `No results found for "${query}"` }] };
|
|
34106
34173
|
}
|
|
@@ -34121,9 +34188,10 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
34121
34188
|
const originInfo = r2.origin !== "agent" ? ` | origin: ${r2.origin}` : "";
|
|
34122
34189
|
const scopeInfo = r2.path_scope ? ` | scope: ${r2.path_scope}` : "";
|
|
34123
34190
|
const statusInfo = r2.status !== "active" ? ` | status: ${r2.status}` : "";
|
|
34191
|
+
const supersededInfo = r2.supersededOn ? ` | superseded: ${r2.supersededOn}` : "";
|
|
34124
34192
|
return `[${r2.category}] ${r2.key}${pin} (${r2.id})
|
|
34125
34193
|
${r2.content}
|
|
34126
|
-
File: ${r2.file} | Tags: ${r2.tags.join(";")} | Date: ${r2.date}${links}${originInfo}${scopeInfo}${statusInfo}`;
|
|
34194
|
+
File: ${r2.file} | Tags: ${r2.tags.join(";")} | Date: ${r2.date}${links}${originInfo}${scopeInfo}${statusInfo}${supersededInfo}`;
|
|
34127
34195
|
}).join("\n\n");
|
|
34128
34196
|
return { content: [{ type: "text", text: formatted }] };
|
|
34129
34197
|
}
|
|
@@ -34136,7 +34204,8 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
34136
34204
|
inputSchema: {
|
|
34137
34205
|
key: external_exports.string().describe("Key or id of the entry to delete"),
|
|
34138
34206
|
hard: external_exports.boolean().optional().default(false).describe("If true, permanently remove the entry. If false (default), softly marks as obsolete (status=obsolete) so it can be resolved or restored later.")
|
|
34139
|
-
}
|
|
34207
|
+
},
|
|
34208
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
34140
34209
|
},
|
|
34141
34210
|
async ({ key, hard }) => {
|
|
34142
34211
|
const data = readMemory();
|
|
@@ -34196,7 +34265,8 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
34196
34265
|
{
|
|
34197
34266
|
title: "Memory Stats",
|
|
34198
34267
|
description: "Show project memory statistics.",
|
|
34199
|
-
inputSchema: {}
|
|
34268
|
+
inputSchema: {},
|
|
34269
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34200
34270
|
},
|
|
34201
34271
|
async () => {
|
|
34202
34272
|
const data = readMemory();
|
|
@@ -34295,7 +34365,8 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
34295
34365
|
inputSchema: {
|
|
34296
34366
|
since: external_exports.string().describe("Show changes since (e.g. 24h, 7d, 2026-07-10)"),
|
|
34297
34367
|
type: external_exports.enum(["all", "created", "updated"]).optional().default("all").describe("Filter by change type")
|
|
34298
|
-
}
|
|
34368
|
+
},
|
|
34369
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34299
34370
|
},
|
|
34300
34371
|
async ({ since, type }) => {
|
|
34301
34372
|
const sinceDate = parseRelativeDate(since);
|
|
@@ -34344,7 +34415,8 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
34344
34415
|
inputSchema: {
|
|
34345
34416
|
context: external_exports.string().describe("Text or context to search for suggestions"),
|
|
34346
34417
|
limit: external_exports.number().optional().default(5).describe("Maximum suggestions")
|
|
34347
|
-
}
|
|
34418
|
+
},
|
|
34419
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34348
34420
|
},
|
|
34349
34421
|
async ({ context, limit }) => {
|
|
34350
34422
|
const related = findRelatedEntries(context, "", limit);
|
|
@@ -34368,14 +34440,16 @@ ${formatted}` }] };
|
|
|
34368
34440
|
intent: external_exports.string().describe("Describe what you need to know (e.g. 'database schema for backend')"),
|
|
34369
34441
|
limit: external_exports.number().optional().default(8).describe("Maximum entries to return"),
|
|
34370
34442
|
category: external_exports.string().optional().default("").describe("Filter by category (empty = all)"),
|
|
34371
|
-
bias: external_exports.enum(["none", "session"]).optional().default("none").describe("'session': boost entries whose file matches current session files. 'none': no bias (default).")
|
|
34372
|
-
|
|
34443
|
+
bias: external_exports.enum(["none", "session"]).optional().default("none").describe("'session': boost entries whose file matches current session files. 'none': no bias (default)."),
|
|
34444
|
+
rrf: external_exports.boolean().optional().default(false).describe("Use Reciprocal Rank Fusion (BM25x3 + centrality ranks, adaptive k=sqrtN) instead of weighted linear scoring. Weight-free: reaches parity with the tuned linear scorer on scripts/bench-rrf.mjs.")
|
|
34445
|
+
},
|
|
34446
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34373
34447
|
},
|
|
34374
|
-
async ({ intent, limit, category, bias }) => {
|
|
34448
|
+
async ({ intent, limit, category, bias, rrf }) => {
|
|
34375
34449
|
const data = readMemory();
|
|
34376
34450
|
const mtimes = fileMtimes();
|
|
34377
34451
|
const sessionFiles = bias === "session" ? getCurrentSessionFiles() : void 0;
|
|
34378
|
-
const result = generateSmartRecall(data, intent, { limit, category, fileMtimes: mtimes, sessionFiles });
|
|
34452
|
+
const result = generateSmartRecall(data, intent, { limit, category, fileMtimes: mtimes, sessionFiles, rrf });
|
|
34379
34453
|
return { content: [{ type: "text", text: result }] };
|
|
34380
34454
|
}
|
|
34381
34455
|
);
|
|
@@ -34388,7 +34462,8 @@ ${formatted}` }] };
|
|
|
34388
34462
|
action: external_exports.enum(["get", "set"]).describe("get to read, set to save"),
|
|
34389
34463
|
file: external_exports.string().describe("File path"),
|
|
34390
34464
|
summary: external_exports.string().optional().default("").describe("File summary (only for set)")
|
|
34391
|
-
}
|
|
34465
|
+
},
|
|
34466
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
34392
34467
|
},
|
|
34393
34468
|
async ({ action, file: file2, summary }) => {
|
|
34394
34469
|
const data = readMemory();
|
|
@@ -34431,7 +34506,8 @@ ${formatted}` }] };
|
|
|
34431
34506
|
{
|
|
34432
34507
|
title: "Archive Old Entries",
|
|
34433
34508
|
description: "Move old entries (>30 days) to archive.toon to keep memory clean.",
|
|
34434
|
-
inputSchema: {}
|
|
34509
|
+
inputSchema: {},
|
|
34510
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
34435
34511
|
},
|
|
34436
34512
|
async () => {
|
|
34437
34513
|
const result = archiveOldEntries();
|
|
@@ -34452,7 +34528,8 @@ ${formatted}` }] };
|
|
|
34452
34528
|
{
|
|
34453
34529
|
title: "Enable Encryption",
|
|
34454
34530
|
description: "Enable AES-256-GCM encryption for memory. Requires TOON_MEMORY_KEY in environment.",
|
|
34455
|
-
inputSchema: {}
|
|
34531
|
+
inputSchema: {},
|
|
34532
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true }
|
|
34456
34533
|
},
|
|
34457
34534
|
async () => {
|
|
34458
34535
|
const config2 = loadConfig();
|
|
@@ -34479,7 +34556,8 @@ ${formatted}` }] };
|
|
|
34479
34556
|
description: "Disable encryption and decode memory.",
|
|
34480
34557
|
inputSchema: {
|
|
34481
34558
|
key: external_exports.string().describe("Encryption key")
|
|
34482
|
-
}
|
|
34559
|
+
},
|
|
34560
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true }
|
|
34483
34561
|
},
|
|
34484
34562
|
async ({ key }) => {
|
|
34485
34563
|
const config2 = loadConfig();
|
|
@@ -34513,7 +34591,8 @@ ${formatted}` }] };
|
|
|
34513
34591
|
tool: external_exports.string().optional().default("").describe("Filter by tool name"),
|
|
34514
34592
|
file: external_exports.string().optional().default("").describe("Filter by file"),
|
|
34515
34593
|
clear: external_exports.boolean().optional().default(false).describe("If true, clears the capture log")
|
|
34516
|
-
}
|
|
34594
|
+
},
|
|
34595
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
|
|
34517
34596
|
},
|
|
34518
34597
|
async ({ limit, tool, file: file2, clear }) => {
|
|
34519
34598
|
if (clear) {
|
|
@@ -34546,7 +34625,8 @@ ${formatted}` }] };
|
|
|
34546
34625
|
{
|
|
34547
34626
|
title: "Consolidate Memory",
|
|
34548
34627
|
description: "Consolidate memory by removing entries with identical content (keeps the first). Deterministic, no LLM.",
|
|
34549
|
-
inputSchema: {}
|
|
34628
|
+
inputSchema: {},
|
|
34629
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true }
|
|
34550
34630
|
},
|
|
34551
34631
|
async () => {
|
|
34552
34632
|
const result = consolidateEntries();
|
|
@@ -34570,7 +34650,8 @@ Duplicates: ${result.duplicates.join(", ")}`
|
|
|
34570
34650
|
description: "Show active agent sessions in this project (git branch, files touched, last-seen) and detect soft conflicts (files touched by 2+ sessions). Use at startup to avoid overwriting other parallel sessions' work.",
|
|
34571
34651
|
inputSchema: {
|
|
34572
34652
|
conflictsOnly: external_exports.boolean().optional().default(false).describe("If true, only show soft conflicts")
|
|
34573
|
-
}
|
|
34653
|
+
},
|
|
34654
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34574
34655
|
},
|
|
34575
34656
|
async ({ conflictsOnly }) => {
|
|
34576
34657
|
const selfId = resolveSessionId();
|
|
@@ -34636,7 +34717,8 @@ ${files}` : "";
|
|
|
34636
34717
|
inputSchema: {
|
|
34637
34718
|
task: external_exports.string().optional().default("").describe("Current agent task. If provided, entries are ranked by relevance to this task. If empty, shows top entries by importance."),
|
|
34638
34719
|
limit: external_exports.number().optional().default(6).describe("Maximum relevant entries to show")
|
|
34639
|
-
}
|
|
34720
|
+
},
|
|
34721
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34640
34722
|
},
|
|
34641
34723
|
async ({ task, limit }) => {
|
|
34642
34724
|
const data = readMemory();
|
|
@@ -34651,7 +34733,8 @@ ${files}` : "";
|
|
|
34651
34733
|
description: "Generate a full system prompt: project (package.json, deps, framework) + git (branch, commits) + memory (relevant entries) + sessions. Single call to prepare the agent. Zero LLM.",
|
|
34652
34734
|
inputSchema: {
|
|
34653
34735
|
task: external_exports.string().optional().default("").describe("Agent task. If provided, ranks entries by relevance to this task.")
|
|
34654
|
-
}
|
|
34736
|
+
},
|
|
34737
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34655
34738
|
},
|
|
34656
34739
|
async ({ task }) => {
|
|
34657
34740
|
const data = readMemory();
|
|
@@ -34667,7 +34750,8 @@ ${files}` : "";
|
|
|
34667
34750
|
description: "What changed since the last session: git commits + modified files + new/updated memory entries. Zero LLM.",
|
|
34668
34751
|
inputSchema: {
|
|
34669
34752
|
since: external_exports.string().optional().default("").describe("Start date (YYYY-MM-DD or relative like '7d'). Empty = last visible changes.")
|
|
34670
|
-
}
|
|
34753
|
+
},
|
|
34754
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34671
34755
|
},
|
|
34672
34756
|
async ({ since }) => {
|
|
34673
34757
|
const data = readMemory();
|
|
@@ -34684,7 +34768,8 @@ ${files}` : "";
|
|
|
34684
34768
|
inputSchema: {
|
|
34685
34769
|
task: external_exports.string().describe("Task or symbol to search context for (e.g. 'fix auth bug', 'authenticate')"),
|
|
34686
34770
|
limit: external_exports.number().optional().default(6).describe("Maximum memory entries to include")
|
|
34687
|
-
}
|
|
34771
|
+
},
|
|
34772
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34688
34773
|
},
|
|
34689
34774
|
async ({ task, limit }) => {
|
|
34690
34775
|
const data = readMemory();
|
|
@@ -34698,7 +34783,8 @@ ${files}` : "";
|
|
|
34698
34783
|
{
|
|
34699
34784
|
title: "Memory Health Audit",
|
|
34700
34785
|
description: "Full memory health audit: orphan links, duplicates, broken refs, expired TTL, quality, stale sessions. Includes score 0-100. Zero LLM.",
|
|
34701
|
-
inputSchema: {}
|
|
34786
|
+
inputSchema: {},
|
|
34787
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34702
34788
|
},
|
|
34703
34789
|
async () => {
|
|
34704
34790
|
const data = readMemory();
|
|
@@ -34714,7 +34800,8 @@ ${files}` : "";
|
|
|
34714
34800
|
description: "Export all memory as markdown injectable for other agents or sessions. Full (detailed) or compact format. Zero LLM.",
|
|
34715
34801
|
inputSchema: {
|
|
34716
34802
|
format: external_exports.enum(["full", "compact"]).optional().default("full").describe("full = detailed with graph, compact = summarized without edges")
|
|
34717
|
-
}
|
|
34803
|
+
},
|
|
34804
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34718
34805
|
},
|
|
34719
34806
|
async ({ format }) => {
|
|
34720
34807
|
const data = readMemory();
|
|
@@ -34727,7 +34814,8 @@ ${files}` : "";
|
|
|
34727
34814
|
{
|
|
34728
34815
|
title: "Backup Memory",
|
|
34729
34816
|
description: "Create a timestamped backup of the memory file. Use before major operations or to preserve state.",
|
|
34730
|
-
inputSchema: {}
|
|
34817
|
+
inputSchema: {},
|
|
34818
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
|
|
34731
34819
|
},
|
|
34732
34820
|
async () => {
|
|
34733
34821
|
if (!existsSync10(MEMORY_FILE)) {
|
|
@@ -34767,7 +34855,8 @@ ${files}` : "";
|
|
|
34767
34855
|
{
|
|
34768
34856
|
title: "System Primer",
|
|
34769
34857
|
description: "Generate a compact system primer: always-current knowledge map for auto-injection into agent context. Excludes private entries, shows top memories by importance, categories, and patterns. Use at session start or when context feels stale.",
|
|
34770
|
-
inputSchema: {}
|
|
34858
|
+
inputSchema: {},
|
|
34859
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34771
34860
|
},
|
|
34772
34861
|
async () => {
|
|
34773
34862
|
const data = readMemory();
|
|
@@ -34785,7 +34874,8 @@ ${files}` : "";
|
|
|
34785
34874
|
query: external_exports.string().optional().default("").describe("Search query to find entries to compress (e.g. 'auth bug fixes'). Empty = show lowest-quality entries."),
|
|
34786
34875
|
count: external_exports.number().optional().default(3).describe("Number of entries to compress (2-10). Default: 3."),
|
|
34787
34876
|
category: external_exports.string().optional().default("").describe("Filter by category (empty = all).")
|
|
34788
|
-
}
|
|
34877
|
+
},
|
|
34878
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
34789
34879
|
},
|
|
34790
34880
|
async ({ query, count, category }) => {
|
|
34791
34881
|
const data = readMemory();
|
|
@@ -34855,7 +34945,8 @@ ${files}` : "";
|
|
|
34855
34945
|
inputSchema: {
|
|
34856
34946
|
minQuality: external_exports.number().optional().default(0.3).describe("Entries below this quality score are compression candidates (0-1). Default: 0.3."),
|
|
34857
34947
|
dryRun: external_exports.boolean().optional().default(false).describe("If true, show what would be compressed without making changes.")
|
|
34858
|
-
}
|
|
34948
|
+
},
|
|
34949
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
34859
34950
|
},
|
|
34860
34951
|
async ({ minQuality, dryRun }) => {
|
|
34861
34952
|
const data = readMemory();
|
|
@@ -34935,7 +35026,8 @@ ${files}` : "";
|
|
|
34935
35026
|
description: "Export memory to a private GitHub Gist for cloud sync. Requires GITHUB_TOKEN env var. Zero deps \u2014 uses Node's built-in fetch().",
|
|
34936
35027
|
inputSchema: {
|
|
34937
35028
|
description: external_exports.string().optional().default("").describe("Optional description for the Gist.")
|
|
34938
|
-
}
|
|
35029
|
+
},
|
|
35030
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
|
|
34939
35031
|
},
|
|
34940
35032
|
async ({ description }) => {
|
|
34941
35033
|
const token = process.env.GITHUB_TOKEN;
|
|
@@ -34996,7 +35088,8 @@ To import later: memory_import_gist(gist_id: "${gist.id}")`
|
|
|
34996
35088
|
inputSchema: {
|
|
34997
35089
|
gist_id: external_exports.string().describe("GitHub Gist ID or full URL (https://gist.github.com/user/id)."),
|
|
34998
35090
|
merge: external_exports.boolean().optional().default(true).describe("If true, merge with existing memory. If false, replace entirely.")
|
|
34999
|
-
}
|
|
35091
|
+
},
|
|
35092
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
35000
35093
|
},
|
|
35001
35094
|
async ({ gist_id, merge: merge2 }) => {
|
|
35002
35095
|
const token = process.env.GITHUB_TOKEN;
|
|
@@ -35097,7 +35190,8 @@ To import later: memory_import_gist(gist_id: "${gist.id}")`
|
|
|
35097
35190
|
inputSchema: {
|
|
35098
35191
|
since: external_exports.string().optional().default("24h").describe("Time window to merge (e.g. '24h', '7d', '2026-07-20'). Default: 24h."),
|
|
35099
35192
|
promote: external_exports.boolean().optional().default(false).describe("If true, auto-promote unique observations to memory entries.")
|
|
35100
|
-
}
|
|
35193
|
+
},
|
|
35194
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
|
|
35101
35195
|
},
|
|
35102
35196
|
async ({ since, promote }) => {
|
|
35103
35197
|
const { listSessions: listSessions2, pruneSessions: pruneSessions2 } = await Promise.resolve().then(() => (init_sessions(), sessions_exports));
|
|
@@ -35199,7 +35293,8 @@ To import later: memory_import_gist(gist_id: "${gist.id}")`
|
|
|
35199
35293
|
description: "Find entries with overlapping content (>50% word similarity) and merge them. Deterministic, no LLM. Keeps the longer content and combines tags.",
|
|
35200
35294
|
inputSchema: {
|
|
35201
35295
|
dryRun: external_exports.boolean().optional().default(false).describe("If true, show what would be merged without making changes.")
|
|
35202
|
-
}
|
|
35296
|
+
},
|
|
35297
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
35203
35298
|
},
|
|
35204
35299
|
async ({ dryRun }) => {
|
|
35205
35300
|
const data = readMemory();
|
|
@@ -35301,7 +35396,8 @@ ${mergeActions.join("\n")}`
|
|
|
35301
35396
|
inputSchema: {
|
|
35302
35397
|
from: external_exports.string().describe("Starting entry key"),
|
|
35303
35398
|
to: external_exports.string().describe("Target entry key")
|
|
35304
|
-
}
|
|
35399
|
+
},
|
|
35400
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
35305
35401
|
},
|
|
35306
35402
|
async ({ from, to: to2 }) => {
|
|
35307
35403
|
const data = readMemory();
|
|
@@ -35364,7 +35460,8 @@ ${mergeActions.join("\n")}`
|
|
|
35364
35460
|
description: "Save or update a session checkpoint with 7-day TTL. Creates a knowledge entry snapshot of the current session state. Same session = upsert (single checkpoint per session). Auto-expires.",
|
|
35365
35461
|
inputSchema: {
|
|
35366
35462
|
note: external_exports.string().optional().default("").describe("Optional summary of what was accomplished in this session.")
|
|
35367
|
-
}
|
|
35463
|
+
},
|
|
35464
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
35368
35465
|
},
|
|
35369
35466
|
async ({ note }) => {
|
|
35370
35467
|
const data = readMemory();
|
|
@@ -35446,7 +35543,8 @@ ${note}` : ""}`
|
|
|
35446
35543
|
inputSchema: {
|
|
35447
35544
|
key: external_exports.string().describe("Key or id of the entry to pin"),
|
|
35448
35545
|
priority: external_exports.number().optional().default(1).describe("Priority level 1-5 (5 = highest). Default: 1.")
|
|
35449
|
-
}
|
|
35546
|
+
},
|
|
35547
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
35450
35548
|
},
|
|
35451
35549
|
async ({ key, priority }) => {
|
|
35452
35550
|
const data = readMemory();
|
|
@@ -35484,7 +35582,8 @@ ${note}` : ""}`
|
|
|
35484
35582
|
description: "Remove the pin from a memory entry so it returns to normal ranking.",
|
|
35485
35583
|
inputSchema: {
|
|
35486
35584
|
key: external_exports.string().describe("Key or id of the entry to unpin")
|
|
35487
|
-
}
|
|
35585
|
+
},
|
|
35586
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
35488
35587
|
},
|
|
35489
35588
|
async ({ key }) => {
|
|
35490
35589
|
const data = readMemory();
|
|
@@ -35532,10 +35631,13 @@ ${note}` : ""}`
|
|
|
35532
35631
|
compact: external_exports.boolean().optional().default(false).describe("Token-efficient output"),
|
|
35533
35632
|
budget: external_exports.enum(["tiny", "normal", "deep"]).optional().default("deep").describe("'tiny': key+1 line (~50 tokens). 'normal': compact with tags/edges. 'deep': all fields (default). Overrides 'compact'."),
|
|
35534
35633
|
bias: external_exports.enum(["none", "session"]).optional().default("none").describe("'session': boost entries whose file matches current session files. 'none': no bias (default)."),
|
|
35535
|
-
path_scope: external_exports.string().optional().default("").describe("Glob pattern to filter entries by path scope (e.g. 'src/**.ts').")
|
|
35536
|
-
|
|
35634
|
+
path_scope: external_exports.string().optional().default("").describe("Glob pattern to filter entries by path scope (e.g. 'src/**.ts')."),
|
|
35635
|
+
rrf: external_exports.boolean().optional().default(false).describe("Use Reciprocal Rank Fusion (BM25x3 + centrality ranks, adaptive k=sqrtN) instead of weighted linear scoring. Weight-free: reaches parity with the tuned linear scorer on scripts/bench-rrf.mjs."),
|
|
35636
|
+
as_of: external_exports.string().optional().default("").describe("Temporal view (YYYY-MM-DD): return entries valid on that date.")
|
|
35637
|
+
},
|
|
35638
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
35537
35639
|
},
|
|
35538
|
-
async ({ query, category, tags, from_date, to_date, limit, mode, hops, compact, bias, budget: budgetParam, path_scope }) => {
|
|
35640
|
+
async ({ query, category, tags, from_date, to_date, limit, mode, hops, compact, bias, budget: budgetParam, path_scope, rrf, as_of }) => {
|
|
35539
35641
|
const data = readMemory();
|
|
35540
35642
|
const resolvedFrom = from_date ? parseRelativeDate(from_date) : "";
|
|
35541
35643
|
const sessionFiles = bias === "session" ? getCurrentSessionFiles() : void 0;
|
|
@@ -35548,7 +35650,9 @@ ${note}` : ""}`
|
|
|
35548
35650
|
hops,
|
|
35549
35651
|
limit,
|
|
35550
35652
|
sessionFiles,
|
|
35551
|
-
path_scope: path_scope || void 0
|
|
35653
|
+
path_scope: path_scope || void 0,
|
|
35654
|
+
rrf,
|
|
35655
|
+
asOf: as_of || void 0
|
|
35552
35656
|
});
|
|
35553
35657
|
if (detail.entries.length === 0) {
|
|
35554
35658
|
return { content: [{ type: "text", text: `No results found for "${query}"` }] };
|
|
@@ -35572,9 +35676,10 @@ ${formatted2}` }] };
|
|
|
35572
35676
|
const originInfo = r2.origin !== "agent" ? ` | origin: ${r2.origin}` : "";
|
|
35573
35677
|
const scopeInfo = r2.path_scope ? ` | scope: ${r2.path_scope}` : "";
|
|
35574
35678
|
const statusInfo = r2.status !== "active" ? ` | status: ${r2.status}` : "";
|
|
35679
|
+
const supersededInfo = r2.supersededOn ? ` | superseded: ${r2.supersededOn}` : "";
|
|
35575
35680
|
return `[${r2.category}] ${r2.key}${pin} (${r2.id})
|
|
35576
35681
|
${r2.content}
|
|
35577
|
-
File: ${r2.file} | Tags: ${r2.tags.join(";")} | Date: ${r2.date}${links}${originInfo}${scopeInfo}${statusInfo}`;
|
|
35682
|
+
File: ${r2.file} | Tags: ${r2.tags.join(";")} | Date: ${r2.date}${links}${originInfo}${scopeInfo}${statusInfo}${supersededInfo}`;
|
|
35578
35683
|
}).join("\n\n");
|
|
35579
35684
|
let filterInfo = "";
|
|
35580
35685
|
if (category) filterInfo += ` category: ${category}`;
|
|
@@ -35597,7 +35702,8 @@ ${formatted}` }]
|
|
|
35597
35702
|
action: external_exports.enum(["add", "remove", "set"]).describe("'add': merge tags (union). 'remove': remove specified tags. 'set': replace all tags."),
|
|
35598
35703
|
tags: external_exports.string().describe("Semicolon-separated tags to apply"),
|
|
35599
35704
|
ids: external_exports.string().describe("Comma or space-separated entry keys or IDs to modify")
|
|
35600
|
-
}
|
|
35705
|
+
},
|
|
35706
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
35601
35707
|
},
|
|
35602
35708
|
async ({ action, tags, ids }) => {
|
|
35603
35709
|
const data = readMemory();
|
|
@@ -35658,7 +35764,8 @@ ${formatted}` }]
|
|
|
35658
35764
|
description: "Restore an obsolete entry back to active status, or mark an entry as resolved. Reverses soft-delete.",
|
|
35659
35765
|
inputSchema: {
|
|
35660
35766
|
key: external_exports.string().describe("Key or id of the entry to resolve/restore")
|
|
35661
|
-
}
|
|
35767
|
+
},
|
|
35768
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
35662
35769
|
},
|
|
35663
35770
|
async ({ key }) => {
|
|
35664
35771
|
const data = readMemory();
|
|
@@ -35698,7 +35805,8 @@ ${formatted}` }]
|
|
|
35698
35805
|
description: "Suppress a memory entry so it's hidden from normal recalls. Sets status to 'obsolete'. Use memory_resolve to restore.",
|
|
35699
35806
|
inputSchema: {
|
|
35700
35807
|
key: external_exports.string().describe("Key or id of the entry to suppress")
|
|
35701
|
-
}
|
|
35808
|
+
},
|
|
35809
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
|
|
35702
35810
|
},
|
|
35703
35811
|
async ({ key }) => {
|
|
35704
35812
|
const data = readMemory();
|
|
@@ -35728,6 +35836,359 @@ ${formatted}` }]
|
|
|
35728
35836
|
return { content: [{ type: "text", text: `"${key}" suppressed. Use memory_resolve(key: "${key}") to restore.` }] };
|
|
35729
35837
|
}
|
|
35730
35838
|
);
|
|
35839
|
+
server2.registerTool(
|
|
35840
|
+
"memory_supersede",
|
|
35841
|
+
{
|
|
35842
|
+
title: "Supersede Entry",
|
|
35843
|
+
description: "Mark an entry as superseded (obsolete) by a newer entry, using typed graph edges (superseded_by / supersedes). The old entry stays in the file for history but is hidden from normal recalls. Use memory_recall(as_of: date) to see what was true at a point in time.",
|
|
35844
|
+
inputSchema: {
|
|
35845
|
+
old_key: external_exports.string().describe("Key or id of the entry being superseded"),
|
|
35846
|
+
new_key: external_exports.string().optional().default("").describe("Key or id of the replacement entry (can be empty if the topic is simply retired)."),
|
|
35847
|
+
reason: external_exports.string().optional().default("").describe("Optional note explaining why it was superseded. Appended to the old entry's content.")
|
|
35848
|
+
},
|
|
35849
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true }
|
|
35850
|
+
},
|
|
35851
|
+
async ({ old_key, new_key, reason }) => {
|
|
35852
|
+
const data = readMemory();
|
|
35853
|
+
const lines = data.split("\n");
|
|
35854
|
+
const headerIdx = lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l));
|
|
35855
|
+
if (headerIdx === -1) {
|
|
35856
|
+
return { content: [{ type: "text", text: "No entries in memory" }] };
|
|
35857
|
+
}
|
|
35858
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
35859
|
+
let oldIdx = -1;
|
|
35860
|
+
for (let i = headerIdx + 1; i < lines.length; i++) {
|
|
35861
|
+
const line = lines[i];
|
|
35862
|
+
if (!line.startsWith(" ") || !line.includes("|")) continue;
|
|
35863
|
+
if (line.startsWith(" summaries:")) break;
|
|
35864
|
+
const parts = line.trim().split("|");
|
|
35865
|
+
if (parts[0] === old_key || parts[2] === old_key) {
|
|
35866
|
+
oldIdx = i;
|
|
35867
|
+
break;
|
|
35868
|
+
}
|
|
35869
|
+
}
|
|
35870
|
+
if (oldIdx === -1) {
|
|
35871
|
+
return { content: [{ type: "text", text: `\u274C "${old_key}" not found in memory.` }] };
|
|
35872
|
+
}
|
|
35873
|
+
let newIdx = -1;
|
|
35874
|
+
let newKey = "";
|
|
35875
|
+
if (new_key) {
|
|
35876
|
+
for (let i = headerIdx + 1; i < lines.length; i++) {
|
|
35877
|
+
const line = lines[i];
|
|
35878
|
+
if (!line.startsWith(" ") || !line.includes("|")) continue;
|
|
35879
|
+
if (line.startsWith(" summaries:")) break;
|
|
35880
|
+
const parts = line.trim().split("|");
|
|
35881
|
+
if (parts[0] === new_key || parts[2] === new_key) {
|
|
35882
|
+
newIdx = i;
|
|
35883
|
+
newKey = parts[2];
|
|
35884
|
+
break;
|
|
35885
|
+
}
|
|
35886
|
+
}
|
|
35887
|
+
if (newIdx === -1) {
|
|
35888
|
+
return { content: [{ type: "text", text: `\u274C Replacement "${new_key}" not found in memory.` }] };
|
|
35889
|
+
}
|
|
35890
|
+
}
|
|
35891
|
+
const oldParts = lines[oldIdx].trim().split("|");
|
|
35892
|
+
const oldKey = oldParts[2];
|
|
35893
|
+
const tags = (oldParts[5] || "").split(";").map((t) => t.trim()).filter(Boolean);
|
|
35894
|
+
if (!tags.includes("superseded")) tags.push("superseded");
|
|
35895
|
+
const links = (oldParts[9] || "").split(/[\s;]+/).filter(Boolean);
|
|
35896
|
+
if (newKey) {
|
|
35897
|
+
const edge = formatLink("superseded_by", newKey);
|
|
35898
|
+
if (!links.includes(edge)) links.push(edge);
|
|
35899
|
+
}
|
|
35900
|
+
let content = oldParts[3] || "";
|
|
35901
|
+
if (reason && !content.includes(reason)) {
|
|
35902
|
+
const flat = reason.replace(/[\r\n]+/g, " ").trim();
|
|
35903
|
+
content = `${content} \u23F3 Superseded (${today}): ${flat}`;
|
|
35904
|
+
}
|
|
35905
|
+
while (oldParts.length < 18) oldParts.push("");
|
|
35906
|
+
oldParts[3] = content;
|
|
35907
|
+
oldParts[5] = tags.join(";");
|
|
35908
|
+
oldParts[9] = links.join(" ");
|
|
35909
|
+
oldParts[16] = "obsolete";
|
|
35910
|
+
oldParts[17] = today;
|
|
35911
|
+
lines[oldIdx] = ` ${oldParts.join("|")}`;
|
|
35912
|
+
if (newIdx !== -1) {
|
|
35913
|
+
const newParts = lines[newIdx].trim().split("|");
|
|
35914
|
+
const newLinks = (newParts[9] || "").split(/[\s;]+/).filter(Boolean);
|
|
35915
|
+
const edge = formatLink("supersedes", oldKey);
|
|
35916
|
+
if (!newLinks.includes(edge)) {
|
|
35917
|
+
newLinks.push(edge);
|
|
35918
|
+
newParts[9] = newLinks.join(" ");
|
|
35919
|
+
lines[newIdx] = ` ${newParts.join("|")}`;
|
|
35920
|
+
}
|
|
35921
|
+
}
|
|
35922
|
+
writeMemory(lines.join("\n"));
|
|
35923
|
+
const target = newKey ? ` by "${newKey}"` : " (retired)";
|
|
35924
|
+
return {
|
|
35925
|
+
content: [{
|
|
35926
|
+
type: "text",
|
|
35927
|
+
text: `\u23F3 "${oldKey}" superseded${target} on ${today}.
|
|
35928
|
+
|
|
35929
|
+
Old entry is now status=obsolete (hidden from normal recalls).
|
|
35930
|
+
\xB7 link: superseded_by${newKey ? `:${newKey}` : ""}
|
|
35931
|
+
\xB7 tag: superseded
|
|
35932
|
+
|
|
35933
|
+
To see what was true before: memory_recall(query: "${oldKey}", as_of: "${today}")
|
|
35934
|
+
To restore: memory_resolve(key: "${oldKey}")${reason ? `
|
|
35935
|
+
|
|
35936
|
+
Reason: ${reason}` : ""}`
|
|
35937
|
+
}]
|
|
35938
|
+
};
|
|
35939
|
+
}
|
|
35940
|
+
);
|
|
35941
|
+
server2.registerTool(
|
|
35942
|
+
"memory_reflect",
|
|
35943
|
+
{
|
|
35944
|
+
title: "Reflect on Memory",
|
|
35945
|
+
description: "Deterministic memory audit (no LLM): tag co-occurrence themes, hub/orphan entries, near-duplicates, contradiction candidates, stale entries, and superseded-but-active entries. Signals what to link, merge, or retire.",
|
|
35946
|
+
inputSchema: {
|
|
35947
|
+
category: external_exports.string().optional().default("").describe("Restrict analysis to one category (empty = all)."),
|
|
35948
|
+
limit: external_exports.number().optional().default(5).describe("Max items per section.")
|
|
35949
|
+
},
|
|
35950
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
35951
|
+
},
|
|
35952
|
+
async ({ category, limit }) => {
|
|
35953
|
+
const data = readMemory();
|
|
35954
|
+
const entries = parseEntries(data);
|
|
35955
|
+
const cap = Math.max(1, Math.min(20, limit || 5));
|
|
35956
|
+
if (entries.length === 0) {
|
|
35957
|
+
return { content: [{ type: "text", text: "Empty memory." }] };
|
|
35958
|
+
}
|
|
35959
|
+
const scope = entries.filter((e) => !category || e.category === category);
|
|
35960
|
+
const { adjacency } = buildGraph(entries);
|
|
35961
|
+
const sections = [`\u{1F9E0} Memory reflect (${scope.length}/${entries.length} entries)`];
|
|
35962
|
+
const degree = /* @__PURE__ */ new Map();
|
|
35963
|
+
for (const [k3, nbs] of adjacency) degree.set(k3, nbs.length);
|
|
35964
|
+
const hubs = [...degree.entries()].sort((a, b2) => b2[1] - a[1]).filter(([, d2]) => d2 >= 3);
|
|
35965
|
+
if (hubs.length > 0) {
|
|
35966
|
+
sections.push("", "\u{1F517} Hubs (connectors):");
|
|
35967
|
+
for (const [k3, d2] of hubs.slice(0, cap)) {
|
|
35968
|
+
const e = entries.find((x) => x.key === k3);
|
|
35969
|
+
sections.push(` ${k3} (deg ${d2}) \u2014 ${e ? e.content.slice(0, 70) : ""}`);
|
|
35970
|
+
}
|
|
35971
|
+
}
|
|
35972
|
+
const orphans = scope.filter((e) => e.status === "active" && !(degree.get(e.key) || 0) && e.tags.length === 0);
|
|
35973
|
+
if (orphans.length > 0) {
|
|
35974
|
+
sections.push("", "\u{1F573}\uFE0F Orphans (no links, no tags \u2014 consider linking):");
|
|
35975
|
+
for (const e of orphans.slice(0, cap)) {
|
|
35976
|
+
sections.push(` [${e.category}] ${e.key} \u2014 ${e.content.slice(0, 70)}`);
|
|
35977
|
+
}
|
|
35978
|
+
}
|
|
35979
|
+
const pairCount = /* @__PURE__ */ new Map();
|
|
35980
|
+
for (const e of scope) {
|
|
35981
|
+
if (e.tags.length < 2) continue;
|
|
35982
|
+
const t = [...e.tags].sort();
|
|
35983
|
+
for (let i = 0; i < t.length; i++) {
|
|
35984
|
+
for (let j3 = i + 1; j3 < t.length; j3++) {
|
|
35985
|
+
const pair = `${t[i]} + ${t[j3]}`;
|
|
35986
|
+
pairCount.set(pair, (pairCount.get(pair) || 0) + 1);
|
|
35987
|
+
}
|
|
35988
|
+
}
|
|
35989
|
+
}
|
|
35990
|
+
const themes = [...pairCount.entries()].sort((a, b2) => b2[1] - a[1]);
|
|
35991
|
+
if (themes.length > 0) {
|
|
35992
|
+
sections.push("", "\u{1F3F7}\uFE0F Latent themes (tag co-occurrence):");
|
|
35993
|
+
for (const [pair, n] of themes.slice(0, cap)) {
|
|
35994
|
+
sections.push(` ${pair} \u2014 ${n} entries`);
|
|
35995
|
+
}
|
|
35996
|
+
}
|
|
35997
|
+
const active = scope.filter((e) => e.status === "active");
|
|
35998
|
+
const wordSets = /* @__PURE__ */ new Map();
|
|
35999
|
+
for (const e of active) {
|
|
36000
|
+
wordSets.set(e.key, new Set(normalize(`${e.key} ${e.content} ${e.tags.join(" ")}`).split(" ").filter(Boolean)));
|
|
36001
|
+
}
|
|
36002
|
+
const dupes = [];
|
|
36003
|
+
const keysArr = active.map((e) => e.key);
|
|
36004
|
+
for (let i = 0; i < keysArr.length; i++) {
|
|
36005
|
+
for (let j3 = i + 1; j3 < keysArr.length; j3++) {
|
|
36006
|
+
const wa2 = wordSets.get(keysArr[i]);
|
|
36007
|
+
const wb2 = wordSets.get(keysArr[j3]);
|
|
36008
|
+
const inter = new Set([...wa2].filter((w3) => wb2.has(w3)));
|
|
36009
|
+
const union2 = /* @__PURE__ */ new Set([...wa2, ...wb2]);
|
|
36010
|
+
const sim = union2.size > 0 ? inter.size / union2.size : 0;
|
|
36011
|
+
if (sim > 0.5) dupes.push({ a: keysArr[i], b: keysArr[j3], sim });
|
|
36012
|
+
}
|
|
36013
|
+
}
|
|
36014
|
+
if (dupes.length > 0) {
|
|
36015
|
+
sections.push("", "\u267B\uFE0F Near-duplicates (merge candidates):");
|
|
36016
|
+
for (const d2 of dupes.sort((x, y2) => y2.sim - x.sim).slice(0, cap)) {
|
|
36017
|
+
sections.push(` ${d2.a} \u2194 ${d2.b} (${(d2.sim * 100).toFixed(0)}% overlap)`);
|
|
36018
|
+
}
|
|
36019
|
+
}
|
|
36020
|
+
const NEGATION = /\b(no longer|never|not|no|doesn'?t|don'?t|shouldn'?t|cannot|can'?t|instead of|contradicts|replaces|deprecated|broken|fails|wrong|incorrect)\b/i;
|
|
36021
|
+
const contradictions = [];
|
|
36022
|
+
for (let i = 0; i < active.length; i++) {
|
|
36023
|
+
for (let j3 = i + 1; j3 < active.length; j3++) {
|
|
36024
|
+
const a = active[i], b2 = active[j3];
|
|
36025
|
+
if (a.category !== b2.category) continue;
|
|
36026
|
+
const shared = a.tags.filter((t) => b2.tags.includes(t)).length;
|
|
36027
|
+
if (shared < 2) continue;
|
|
36028
|
+
const aNeg = NEGATION.test(a.content);
|
|
36029
|
+
const bNeg = NEGATION.test(b2.content);
|
|
36030
|
+
if (aNeg !== bNeg) {
|
|
36031
|
+
contradictions.push(`${a.key} \u2194 ${b2.key} [${a.category}] (${shared} shared tags, split polarity)`);
|
|
36032
|
+
}
|
|
36033
|
+
}
|
|
36034
|
+
}
|
|
36035
|
+
if (contradictions.length > 0) {
|
|
36036
|
+
sections.push("", "\u26A1 Contradiction candidates (verify):");
|
|
36037
|
+
for (const c2 of contradictions.slice(0, cap)) {
|
|
36038
|
+
sections.push(` ${c2}`);
|
|
36039
|
+
}
|
|
36040
|
+
}
|
|
36041
|
+
const now = Date.now();
|
|
36042
|
+
const stale = active.filter((e) => {
|
|
36043
|
+
if (e.tags.includes("private")) return false;
|
|
36044
|
+
if (e.ttl && isExpiredLocal(e.ttl)) return true;
|
|
36045
|
+
if (!e.date) return false;
|
|
36046
|
+
const ageDays = (now - (/* @__PURE__ */ new Date(`${e.date}T00:00:00`)).getTime()) / 864e5;
|
|
36047
|
+
const lastAccessDays = e.lastAccessed ? (now - new Date(e.lastAccessed).getTime()) / 864e5 : ageDays;
|
|
36048
|
+
return ageDays > 120 && lastAccessDays > 90 && e.accessed === 0;
|
|
36049
|
+
});
|
|
36050
|
+
if (stale.length > 0) {
|
|
36051
|
+
sections.push("", "\u{1F5C4}\uFE0F Stale (archive candidates):");
|
|
36052
|
+
for (const e of stale.sort((a, b2) => a.date.localeCompare(b2.date)).slice(0, cap)) {
|
|
36053
|
+
sections.push(` [${e.category}] ${e.key} \u2014 ${e.content.slice(0, 70)}`);
|
|
36054
|
+
}
|
|
36055
|
+
}
|
|
36056
|
+
const pending = entries.filter((e) => e.status === "active" && (e.tags.includes("superseded") || typedLinks(e.links).some((l) => l.type === "superseded_by")));
|
|
36057
|
+
if (pending.length > 0) {
|
|
36058
|
+
sections.push("", "\u{1F50E} Superseded tag but still active (fix with memory_supersede):");
|
|
36059
|
+
for (const e of pending.slice(0, cap)) {
|
|
36060
|
+
sections.push(` [${e.category}] ${e.key}`);
|
|
36061
|
+
}
|
|
36062
|
+
}
|
|
36063
|
+
const drafts = entries.filter((e) => e.status === "draft");
|
|
36064
|
+
if (drafts.length > 0) {
|
|
36065
|
+
sections.push("", "\u{1F4DD} Drafts pending review (promote with memory_promote / memory_resolve):");
|
|
36066
|
+
for (const e of drafts.slice(0, cap)) {
|
|
36067
|
+
sections.push(` [${e.category}] ${e.key} \u2014 ${e.content.slice(0, 70)}`);
|
|
36068
|
+
}
|
|
36069
|
+
}
|
|
36070
|
+
return { content: [{ type: "text", text: sections.join("\n") }] };
|
|
36071
|
+
}
|
|
36072
|
+
);
|
|
36073
|
+
server2.registerTool(
|
|
36074
|
+
"memory_promote",
|
|
36075
|
+
{
|
|
36076
|
+
title: "Promote Observations",
|
|
36077
|
+
description: "Heuristic auto-promote from the capture log (no LLM). Each observation gets a deterministic confidence score; high-confidence ones promote as active entries, low-confidence (\u2264 minConfidence) become reviewable drafts. Opt-in: run with dryRun: true first.",
|
|
36078
|
+
inputSchema: {
|
|
36079
|
+
dryRun: external_exports.boolean().optional().default(true).describe("If true, only preview what would be promoted (no writes)."),
|
|
36080
|
+
minConfidence: external_exports.number().optional().default(0.65).describe("Observations at or below this confidence become drafts; above it become active entries."),
|
|
36081
|
+
max: external_exports.number().optional().default(5).describe("Maximum observations to promote."),
|
|
36082
|
+
days: external_exports.number().optional().default(7).describe("Only consider observations from the last N days.")
|
|
36083
|
+
},
|
|
36084
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
|
|
36085
|
+
},
|
|
36086
|
+
async ({ dryRun, minConfidence, max, days }) => {
|
|
36087
|
+
const obs = readObservations();
|
|
36088
|
+
if (obs.length === 0) {
|
|
36089
|
+
return { content: [{ type: "text", text: "No captured activity. Enable with `toon-memory capture on`." }] };
|
|
36090
|
+
}
|
|
36091
|
+
const cutoff = Date.now() - (days || 7) * 864e5;
|
|
36092
|
+
const recent = obs.filter((o) => new Date(o.ts).getTime() >= cutoff);
|
|
36093
|
+
const data = readMemory();
|
|
36094
|
+
const existing = parseEntries(data);
|
|
36095
|
+
const existingKeys = new Set(existing.map((e) => e.key));
|
|
36096
|
+
const existingWords = existing.map((e) => new Set(normalize(`${e.key} ${e.content} ${e.tags.join(" ")}`).split(" ").filter(Boolean)));
|
|
36097
|
+
const confidence = (o) => {
|
|
36098
|
+
const summary = (o.summary || "").trim();
|
|
36099
|
+
if (!summary) return 0.1;
|
|
36100
|
+
let c2 = 0.5;
|
|
36101
|
+
const len = summary.length;
|
|
36102
|
+
if (len >= 40 && len <= 300) c2 += 0.1;
|
|
36103
|
+
else if (len < 40) c2 -= 0.1;
|
|
36104
|
+
if (o.file) c2 += 0.15;
|
|
36105
|
+
const tool = (o.tool || "").toLowerCase();
|
|
36106
|
+
if (["edit", "write", "create", "bash", "git", "npm"].includes(tool)) c2 += 0.1;
|
|
36107
|
+
else if (["read", "grep", "glob", "search", "ls", "list"].includes(tool)) c2 -= 0.15;
|
|
36108
|
+
if (/\b(error|fail|bug|fix|broken|fails|failed|cannot|crash)\b/i.test(summary)) c2 += 0.1;
|
|
36109
|
+
if (/\b(viewed|read|opened|inspected|browsed|listed|scanned)\b/i.test(summary)) c2 -= 0.1;
|
|
36110
|
+
return Math.max(0.05, Math.min(1, c2));
|
|
36111
|
+
};
|
|
36112
|
+
const alreadyKnown = (o) => {
|
|
36113
|
+
const words = new Set(normalize(`${o.tool} ${o.summary}`).split(" ").filter(Boolean));
|
|
36114
|
+
if (words.size === 0) return true;
|
|
36115
|
+
for (const set2 of existingWords) {
|
|
36116
|
+
const inter = new Set([...words].filter((w3) => set2.has(w3)));
|
|
36117
|
+
const union2 = /* @__PURE__ */ new Set([...words, ...set2]);
|
|
36118
|
+
if (inter.size / union2.size > 0.5) return true;
|
|
36119
|
+
}
|
|
36120
|
+
return false;
|
|
36121
|
+
};
|
|
36122
|
+
const seen = /* @__PURE__ */ new Set();
|
|
36123
|
+
const candidates = recent.filter((o) => {
|
|
36124
|
+
const dedupKey = `${o.tool}|${o.summary}`;
|
|
36125
|
+
if (seen.has(dedupKey)) return false;
|
|
36126
|
+
seen.add(dedupKey);
|
|
36127
|
+
return o.summary && !alreadyKnown(o);
|
|
36128
|
+
}).map((o) => ({ o, conf: confidence(o) })).sort((a, b2) => b2.conf - a.conf).slice(0, max || 5);
|
|
36129
|
+
if (candidates.length === 0) {
|
|
36130
|
+
return { content: [{ type: "text", text: "\u2705 Nothing new to promote \u2014 all recent observations are already covered by memory or below threshold." }] };
|
|
36131
|
+
}
|
|
36132
|
+
const preview = candidates.map(({ o, conf }) => {
|
|
36133
|
+
const kind = conf <= minConfidence ? "draft" : "active";
|
|
36134
|
+
return ` [${kind}] ${(o.summary || "").slice(0, 90)} (conf ${conf.toFixed(2)})${o.file ? ` @ ${o.file}` : ""}`;
|
|
36135
|
+
});
|
|
36136
|
+
const kindLabel = (conf) => conf <= minConfidence ? "draft" : "active";
|
|
36137
|
+
if (dryRun) {
|
|
36138
|
+
return {
|
|
36139
|
+
content: [{
|
|
36140
|
+
type: "text",
|
|
36141
|
+
text: `\u{1F50D} Dry run \u2014 ${candidates.length} candidate(s) from the last ${days || 7}d (threshold ${minConfidence}):
|
|
36142
|
+
|
|
36143
|
+
${preview.join("\n")}
|
|
36144
|
+
|
|
36145
|
+
Run with dryRun: false to promote.`
|
|
36146
|
+
}]
|
|
36147
|
+
};
|
|
36148
|
+
}
|
|
36149
|
+
const date5 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
36150
|
+
const lines = data.split("\n");
|
|
36151
|
+
let headerIdx = lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l));
|
|
36152
|
+
if (headerIdx === -1) {
|
|
36153
|
+
lines.push(`[0|]`);
|
|
36154
|
+
headerIdx = lines.length - 1;
|
|
36155
|
+
}
|
|
36156
|
+
const match = lines[headerIdx].match(/\[(\d+)\|/);
|
|
36157
|
+
let count = match ? parseInt(match[1]) : 0;
|
|
36158
|
+
let promoted = 0;
|
|
36159
|
+
let drafted = 0;
|
|
36160
|
+
const actions = [];
|
|
36161
|
+
for (const { o, conf } of candidates) {
|
|
36162
|
+
const key = o.summary.toLowerCase().replace(/[^a-z0-9\s]/g, "").split(/\s+/).filter(Boolean).slice(0, 4).join("-").slice(0, 40) || `observation-${Date.now().toString(36)}`;
|
|
36163
|
+
if (existingKeys.has(key)) continue;
|
|
36164
|
+
const newId = generateId();
|
|
36165
|
+
const status = kindLabel(conf);
|
|
36166
|
+
const tags = ["captured", `${o.agent || "agent"}`];
|
|
36167
|
+
if (status === "draft") tags.push("draft");
|
|
36168
|
+
const content = (o.summary || "").slice(0, 500);
|
|
36169
|
+
const quality = qualityScore(tags.join(";"), "", content, date5);
|
|
36170
|
+
const entry = `${newId}|knowledge|${key}|${content}|${o.file || ""}|${tags.join(";")}|${date5}||0||${quality.toFixed(2)}|${conf.toFixed(2)}|${date5}|0||inferred|${status}`;
|
|
36171
|
+
lines.splice(headerIdx + 1, 0, ` ${entry}`);
|
|
36172
|
+
count++;
|
|
36173
|
+
existingKeys.add(key);
|
|
36174
|
+
if (status === "draft") drafted++;
|
|
36175
|
+
else promoted++;
|
|
36176
|
+
actions.push(` [${status}] ${key} (conf ${conf.toFixed(2)})`);
|
|
36177
|
+
}
|
|
36178
|
+
lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count}|`);
|
|
36179
|
+
writeMemory(lines.join("\n"));
|
|
36180
|
+
return {
|
|
36181
|
+
content: [{
|
|
36182
|
+
type: "text",
|
|
36183
|
+
text: `\u{1F4E4} Promoted ${promoted} active + ${drafted} draft from the capture log.
|
|
36184
|
+
|
|
36185
|
+
${actions.join("\n")}
|
|
36186
|
+
|
|
36187
|
+
Drafts are hidden from recalls until promoted \u2014 use memory_resolve(key) to activate, or review with memory_reflect.`
|
|
36188
|
+
}]
|
|
36189
|
+
};
|
|
36190
|
+
}
|
|
36191
|
+
);
|
|
35731
36192
|
K3(
|
|
35732
36193
|
server2,
|
|
35733
36194
|
"memory_visualize",
|
|
@@ -35737,6 +36198,7 @@ ${formatted}` }]
|
|
|
35737
36198
|
inputSchema: {
|
|
35738
36199
|
query: external_exports.string().optional().default("").describe("Optional search query to highlight entries in the viewer")
|
|
35739
36200
|
},
|
|
36201
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
|
|
35740
36202
|
_meta: { ui: { resourceUri: "ui://viewer" } }
|
|
35741
36203
|
},
|
|
35742
36204
|
async ({ query }) => {
|
|
@@ -47391,7 +47853,7 @@ function registerResources(server2) {
|
|
|
47391
47853
|
|
|
47392
47854
|
// src/mcp/server.ts
|
|
47393
47855
|
var server = new McpServer(
|
|
47394
|
-
{ name: "toon-memory", version: "3.
|
|
47856
|
+
{ name: "toon-memory", version: "3.7.0" },
|
|
47395
47857
|
{ capabilities: { tools: { listChanged: true }, resources: { listChanged: true }, experimental: { "io.modelcontextprotocol/ui": {} } } }
|
|
47396
47858
|
);
|
|
47397
47859
|
var s = server.server;
|
|
@@ -47403,7 +47865,7 @@ s.setRequestHandler(InitializeRequestSchema, async (request) => {
|
|
|
47403
47865
|
return {
|
|
47404
47866
|
protocolVersion,
|
|
47405
47867
|
capabilities: s.getCapabilities(),
|
|
47406
|
-
serverInfo: { name: "toon-memory", version: "3.
|
|
47868
|
+
serverInfo: { name: "toon-memory", version: "3.7.0" },
|
|
47407
47869
|
...s._instructions && { instructions: s._instructions }
|
|
47408
47870
|
};
|
|
47409
47871
|
});
|