toon-memory 2.7.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/cli/capture.js +41 -10
- package/dist/cli/session-start.js +6 -6
- package/dist/cli/setup.js +36 -33
- package/mcp/server.js +324 -325
- package/package.json +2 -6
- package/src/cli/agents.ts +8 -5
- package/src/cli/capture-toggle.ts +4 -4
- package/src/cli/capture.ts +5 -0
- package/src/cli/commands.ts +15 -15
- package/src/cli/constants.ts +1 -1
- package/src/cli/session-start.ts +6 -6
- package/src/cli/setup.ts +8 -8
- package/src/lib/context.ts +83 -83
- package/src/lib/git.ts +10 -11
- package/src/lib/graph.ts +2 -20
- package/src/lib/quality.ts +17 -31
- package/src/lib/utils.ts +25 -0
- package/src/mcp/archive.ts +5 -4
- package/src/mcp/config.ts +9 -1
- package/src/mcp/entries.ts +1 -1
- package/src/mcp/observations.ts +28 -1
- package/src/mcp/resources.ts +3 -3
- package/src/mcp/scoring.ts +3 -6
- package/src/mcp/tools.ts +191 -190
package/mcp/server.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
var __export = (target, all) => {
|
|
3
9
|
for (var name in all)
|
|
4
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16506,8 +16512,8 @@ var require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
16506
16512
|
}
|
|
16507
16513
|
return count;
|
|
16508
16514
|
}
|
|
16509
|
-
function getFullPath(resolver, id = "",
|
|
16510
|
-
if (
|
|
16515
|
+
function getFullPath(resolver, id = "", normalize2) {
|
|
16516
|
+
if (normalize2 !== false) id = normalizeId(id);
|
|
16511
16517
|
return _getFullPath(resolver, resolver.parse(id));
|
|
16512
16518
|
}
|
|
16513
16519
|
exports.getFullPath = getFullPath;
|
|
@@ -17602,7 +17608,7 @@ var require_schemes = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
17602
17608
|
var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
17603
17609
|
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require_utils();
|
|
17604
17610
|
const { SCHEMES, getSchemeHandler } = require_schemes();
|
|
17605
|
-
function
|
|
17611
|
+
function normalize2(uri, options) {
|
|
17606
17612
|
if (typeof uri === "string") uri = serialize(parse3(uri, options), options);
|
|
17607
17613
|
else if (typeof uri === "object") uri = parse3(serialize(uri, options), options);
|
|
17608
17614
|
return uri;
|
|
@@ -17780,7 +17786,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
17780
17786
|
}
|
|
17781
17787
|
const fastUri = {
|
|
17782
17788
|
SCHEMES,
|
|
17783
|
-
normalize:
|
|
17789
|
+
normalize: normalize2,
|
|
17784
17790
|
resolve,
|
|
17785
17791
|
resolveComponent,
|
|
17786
17792
|
equal,
|
|
@@ -27639,7 +27645,8 @@ var StdioServerTransport = class {
|
|
|
27639
27645
|
};
|
|
27640
27646
|
|
|
27641
27647
|
// src/mcp/tools.ts
|
|
27642
|
-
import {
|
|
27648
|
+
import { writeFileSync as writeFileSync5, existsSync as existsSync10, copyFileSync, mkdirSync as mkdirSync3, readdirSync as readdirSync5 } from "fs";
|
|
27649
|
+
import { join as join7, basename } from "path";
|
|
27643
27650
|
|
|
27644
27651
|
// src/lib/lock.ts
|
|
27645
27652
|
import { openSync, closeSync, writeFileSync, readFileSync, unlinkSync, existsSync, statSync, renameSync } from "fs";
|
|
@@ -27743,7 +27750,10 @@ var MEMORY_FILE = join(MEMORY_DIR, "data.toon");
|
|
|
27743
27750
|
var ARCHIVE_FILE = join(MEMORY_DIR, "archive.toon");
|
|
27744
27751
|
var OBSERVATIONS_FILE = join(MEMORY_DIR, "observations.toon");
|
|
27745
27752
|
var CONFIG_FILE = join(MEMORY_DIR, "config.json");
|
|
27746
|
-
|
|
27753
|
+
function getMaxEntries() {
|
|
27754
|
+
const config2 = loadConfig();
|
|
27755
|
+
return config2.maxEntries || 100;
|
|
27756
|
+
}
|
|
27747
27757
|
var ARCHIVE_DAYS = 30;
|
|
27748
27758
|
var ALGORITHM = "aes-256-gcm";
|
|
27749
27759
|
function loadConfig() {
|
|
@@ -27842,6 +27852,24 @@ function writeMemory(content) {
|
|
|
27842
27852
|
|
|
27843
27853
|
// src/mcp/entries.ts
|
|
27844
27854
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
27855
|
+
|
|
27856
|
+
// src/lib/utils.ts
|
|
27857
|
+
var normalize = (s) => s.toLowerCase().replace(/[-_]/g, " ").replace(/\s+/g, " ").trim();
|
|
27858
|
+
var isExpiredLocal = (ttl) => {
|
|
27859
|
+
if (!ttl) return false;
|
|
27860
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
27861
|
+
return ttl <= today;
|
|
27862
|
+
};
|
|
27863
|
+
function importance(e) {
|
|
27864
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
27865
|
+
const days = (Date.now() - (/* @__PURE__ */ new Date(`${e.date || today}T00:00:00`)).getTime()) / 864e5;
|
|
27866
|
+
const recency = Math.max(0, 30 - days) / 30;
|
|
27867
|
+
const freq = Math.min(1, e.accessed / 5);
|
|
27868
|
+
return recency * 0.6 + freq * 0.4;
|
|
27869
|
+
}
|
|
27870
|
+
var tokenize = (s) => normalize(s).split(" ").filter(Boolean);
|
|
27871
|
+
|
|
27872
|
+
// src/mcp/entries.ts
|
|
27845
27873
|
function generateId() {
|
|
27846
27874
|
return randomBytes2(4).toString("hex");
|
|
27847
27875
|
}
|
|
@@ -27921,14 +27949,10 @@ function parseRelativeDate(since) {
|
|
|
27921
27949
|
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
27922
27950
|
return today;
|
|
27923
27951
|
}
|
|
27924
|
-
var normalize = (s) => s.toLowerCase().replace(/[-_]/g, " ").replace(/\s+/g, " ").trim();
|
|
27925
27952
|
|
|
27926
27953
|
// src/mcp/scoring.ts
|
|
27927
27954
|
function entryScore(dateStr, accessed) {
|
|
27928
|
-
|
|
27929
|
-
const recency = Math.max(0, 30 - days) / 30;
|
|
27930
|
-
const freq = Math.min(1, accessed / 5);
|
|
27931
|
-
return recency * 0.6 + freq * 0.4;
|
|
27955
|
+
return importance({ date: dateStr, accessed });
|
|
27932
27956
|
}
|
|
27933
27957
|
function entryScoreForLine(line) {
|
|
27934
27958
|
const parts = line.trim().split("|");
|
|
@@ -27978,7 +28002,7 @@ function bumpAccessed(ids) {
|
|
|
27978
28002
|
}
|
|
27979
28003
|
|
|
27980
28004
|
// src/mcp/observations.ts
|
|
27981
|
-
import { readFileSync as readFileSync3, existsSync as existsSync3 } from "fs";
|
|
28005
|
+
import { readFileSync as readFileSync3, existsSync as existsSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
27982
28006
|
function readObservations() {
|
|
27983
28007
|
if (!existsSync3(OBSERVATIONS_FILE)) return [];
|
|
27984
28008
|
return readFileSync3(OBSERVATIONS_FILE, "utf-8").split("\n").filter((l) => l.startsWith(" ") && l.includes("|")).map((l) => {
|
|
@@ -28009,8 +28033,9 @@ function archiveOldEntries(opts = {}) {
|
|
|
28009
28033
|
});
|
|
28010
28034
|
if (opts.trimToMax) {
|
|
28011
28035
|
const remaining = entryLines2.length - toArchive.size;
|
|
28012
|
-
|
|
28013
|
-
|
|
28036
|
+
const maxEntries = getMaxEntries();
|
|
28037
|
+
if (remaining > maxEntries) {
|
|
28038
|
+
const need = remaining - maxEntries;
|
|
28014
28039
|
const candidates = entryLines2.map((line, idx) => ({ idx, score: entryScoreForLine(line) })).filter((c) => !toArchive.has(c.idx)).sort((a, b) => a.score - b.score);
|
|
28015
28040
|
for (let i = 0; i < need && i < candidates.length; i++) toArchive.add(candidates[i].idx);
|
|
28016
28041
|
}
|
|
@@ -28029,7 +28054,7 @@ archived:
|
|
|
28029
28054
|
const archiveLines = archiveContent.split("\n");
|
|
28030
28055
|
let archiveHeaderIdx = archiveLines.findIndex((l) => l.startsWith("archived["));
|
|
28031
28056
|
if (archiveHeaderIdx === -1) {
|
|
28032
|
-
archiveLines.push(`archived[0|]{id|category|key|content|file|tags|date}:`);
|
|
28057
|
+
archiveLines.push(`archived[0|]{id|category|key|content|file|tags|date|ttl|accessed|links|quality|confidence}:`);
|
|
28033
28058
|
archiveHeaderIdx = archiveLines.length - 1;
|
|
28034
28059
|
}
|
|
28035
28060
|
const archiveMatch = archiveLines[archiveHeaderIdx].match(/archived\[(\d+)\|/);
|
|
@@ -28082,12 +28107,6 @@ function pruneExpiredEntries() {
|
|
|
28082
28107
|
}
|
|
28083
28108
|
|
|
28084
28109
|
// src/lib/graph.ts
|
|
28085
|
-
var isExpiredLocal = (ttl) => {
|
|
28086
|
-
if (!ttl) return false;
|
|
28087
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
28088
|
-
return ttl <= today;
|
|
28089
|
-
};
|
|
28090
|
-
var normalize2 = (s) => s.toLowerCase().replace(/[-_]/g, " ").replace(/\s+/g, " ").trim();
|
|
28091
28110
|
var entryLines = (data) => data.split("\n").filter(
|
|
28092
28111
|
(l) => l.startsWith(" ") && l.includes("|") && !l.startsWith(" summaries:")
|
|
28093
28112
|
);
|
|
@@ -28135,14 +28154,6 @@ function buildGraph(entries) {
|
|
|
28135
28154
|
for (const [k, v] of adj) adjacency.set(k, [...v]);
|
|
28136
28155
|
return { adjacency, byKey };
|
|
28137
28156
|
}
|
|
28138
|
-
var importance = (e) => {
|
|
28139
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
28140
|
-
const days = (Date.now() - (/* @__PURE__ */ new Date(`${e.date || today}T00:00:00`)).getTime()) / 864e5;
|
|
28141
|
-
const recency = Math.max(0, 30 - days) / 30;
|
|
28142
|
-
const freq = Math.min(1, e.accessed / 5);
|
|
28143
|
-
return recency * 0.6 + freq * 0.4;
|
|
28144
|
-
};
|
|
28145
|
-
var tokenize = (s) => normalize2(s).split(" ").filter(Boolean);
|
|
28146
28157
|
function bm25Scores(entries, query) {
|
|
28147
28158
|
const N = entries.length;
|
|
28148
28159
|
const scores = /* @__PURE__ */ new Map();
|
|
@@ -28204,7 +28215,7 @@ function graphRecallDetailed(data, query, opts = {}) {
|
|
|
28204
28215
|
if (from_date && e.date < from_date) continue;
|
|
28205
28216
|
if (to_date && e.date > to_date) continue;
|
|
28206
28217
|
if (e.ttl && isExpiredLocal(e.ttl)) continue;
|
|
28207
|
-
const text =
|
|
28218
|
+
const text = normalize(
|
|
28208
28219
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
28209
28220
|
);
|
|
28210
28221
|
if (qTokens.length > 0 && !qTokens.every((t) => text.includes(t))) continue;
|
|
@@ -28276,20 +28287,6 @@ function renderCompact(entries, opts = {}) {
|
|
|
28276
28287
|
}
|
|
28277
28288
|
|
|
28278
28289
|
// src/lib/quality.ts
|
|
28279
|
-
var normalize3 = (s) => s.toLowerCase().replace(/[-_]/g, " ").replace(/\s+/g, " ").trim();
|
|
28280
|
-
var tokenize2 = (s) => normalize3(s).split(" ").filter(Boolean);
|
|
28281
|
-
var isExpiredLocal2 = (ttl) => {
|
|
28282
|
-
if (!ttl) return false;
|
|
28283
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
28284
|
-
return ttl <= today;
|
|
28285
|
-
};
|
|
28286
|
-
var importance2 = (e) => {
|
|
28287
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
28288
|
-
const days = (Date.now() - (/* @__PURE__ */ new Date(`${e.date || today}T00:00:00`)).getTime()) / 864e5;
|
|
28289
|
-
const recency = Math.max(0, 30 - days) / 30;
|
|
28290
|
-
const freq = Math.min(1, e.accessed / 5);
|
|
28291
|
-
return recency * 0.6 + freq * 0.4;
|
|
28292
|
-
};
|
|
28293
28290
|
function qualityScore(tags, links, content, date5) {
|
|
28294
28291
|
let score = 0;
|
|
28295
28292
|
if (tags) {
|
|
@@ -28333,6 +28330,9 @@ function mergeEntries(existingLine, newLine) {
|
|
|
28333
28330
|
const existingTtl = ep[7] || "";
|
|
28334
28331
|
const newTtl = np[7] || "";
|
|
28335
28332
|
const ttl = newTtl || existingTtl;
|
|
28333
|
+
const existingAccessed = ep.length > 8 ? parseInt(ep[8]) || 0 : 0;
|
|
28334
|
+
const newAccessed = np.length > 8 ? parseInt(np[8]) || 0 : 0;
|
|
28335
|
+
const accessed = Math.max(existingAccessed, newAccessed);
|
|
28336
28336
|
const existingConf = ep.length > 11 ? parseFloat(ep[11]) || 0 : 0;
|
|
28337
28337
|
const newConf = np.length > 11 ? parseFloat(np[11]) || 0 : 0;
|
|
28338
28338
|
const confidence = Math.max(existingConf, newConf);
|
|
@@ -28340,35 +28340,35 @@ function mergeEntries(existingLine, newLine) {
|
|
|
28340
28340
|
const newLinks = (np[9] || "").split(/[\s;]+/).filter(Boolean);
|
|
28341
28341
|
const mergedLinks = [.../* @__PURE__ */ new Set([...existingLinks, ...newLinks])].join(" ");
|
|
28342
28342
|
const quality = qualityScore(mergedTags, mergedLinks, content, date5);
|
|
28343
|
-
return `${id}|${category}|${key}|${content}|${file2}|${mergedTags}|${date5}|${ttl}
|
|
28343
|
+
return `${id}|${category}|${key}|${content}|${file2}|${mergedTags}|${date5}|${ttl}|${accessed}|${mergedLinks}|${quality.toFixed(2)}|${confidence}`;
|
|
28344
28344
|
}
|
|
28345
28345
|
function generateSmartRecall(data, intent, opts = {}) {
|
|
28346
28346
|
const entries = parseEntries(data);
|
|
28347
|
-
if (entries.length === 0) return "
|
|
28347
|
+
if (entries.length === 0) return "Empty memory.";
|
|
28348
28348
|
const { adjacency } = buildGraph(entries);
|
|
28349
28349
|
const bm25 = bm25Scores(entries, intent);
|
|
28350
28350
|
const cent = centrality(adjacency);
|
|
28351
28351
|
const limit = opts.limit ?? 8;
|
|
28352
28352
|
const category = opts.category || "";
|
|
28353
|
-
const qTokens =
|
|
28353
|
+
const qTokens = tokenize(intent);
|
|
28354
28354
|
const scored = entries.filter((e) => {
|
|
28355
28355
|
if (category && e.category !== category) return false;
|
|
28356
|
-
if (e.ttl &&
|
|
28356
|
+
if (e.ttl && isExpiredLocal(e.ttl)) return false;
|
|
28357
28357
|
return true;
|
|
28358
28358
|
}).map((e) => {
|
|
28359
|
-
const text =
|
|
28359
|
+
const text = normalize(
|
|
28360
28360
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
28361
28361
|
);
|
|
28362
28362
|
const matchesQuery = qTokens.length === 0 || qTokens.some((t) => text.includes(t));
|
|
28363
28363
|
const bm25Score = bm25.get(e.key) || 0;
|
|
28364
28364
|
const centScore = cent.get(e.key) || 0;
|
|
28365
|
-
const impScore =
|
|
28365
|
+
const impScore = importance(e);
|
|
28366
28366
|
const combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0);
|
|
28367
28367
|
return { entry: e, score: combined, matchesQuery };
|
|
28368
28368
|
}).filter((x) => x.score > 0 || x.matchesQuery).sort((a, b) => b.score - a.score).slice(0, limit);
|
|
28369
28369
|
if (scored.length === 0) {
|
|
28370
|
-
const top = entries.filter((e) => !category || e.category === category).sort((a, b) =>
|
|
28371
|
-
if (top.length === 0) return "No
|
|
28370
|
+
const top = entries.filter((e) => !category || e.category === category).sort((a, b) => importance(b) - importance(a)).slice(0, limit);
|
|
28371
|
+
if (top.length === 0) return "No entries in memory.";
|
|
28372
28372
|
return renderCompact(top);
|
|
28373
28373
|
}
|
|
28374
28374
|
if (opts.bumpAccess) opts.bumpAccess(scored.map((x) => x.entry.id));
|
|
@@ -28376,7 +28376,7 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
28376
28376
|
}
|
|
28377
28377
|
function generateSystemPrimer(data) {
|
|
28378
28378
|
const entries = parseEntries(data);
|
|
28379
|
-
if (entries.length === 0) return "
|
|
28379
|
+
if (entries.length === 0) return "Empty memory. No entries saved.";
|
|
28380
28380
|
const byCategory = {};
|
|
28381
28381
|
for (const e of entries) {
|
|
28382
28382
|
if (!byCategory[e.category]) byCategory[e.category] = [];
|
|
@@ -28384,11 +28384,11 @@ function generateSystemPrimer(data) {
|
|
|
28384
28384
|
}
|
|
28385
28385
|
const lines = [
|
|
28386
28386
|
"=== System Primer ===",
|
|
28387
|
-
`
|
|
28387
|
+
`Entries: ${entries.length}`,
|
|
28388
28388
|
""
|
|
28389
28389
|
];
|
|
28390
|
-
const top = [...entries].sort((a, b) =>
|
|
28391
|
-
lines.push("Top
|
|
28390
|
+
const top = [...entries].sort((a, b) => importance(b) - importance(a)).slice(0, 5);
|
|
28391
|
+
lines.push("Top memories:");
|
|
28392
28392
|
for (const e of top) {
|
|
28393
28393
|
const quality = qualityScore(
|
|
28394
28394
|
e.tags.join(";"),
|
|
@@ -28396,20 +28396,20 @@ function generateSystemPrimer(data) {
|
|
|
28396
28396
|
e.content,
|
|
28397
28397
|
e.date
|
|
28398
28398
|
);
|
|
28399
|
-
const conf = quality >= 0.5 ? "
|
|
28399
|
+
const conf = quality >= 0.5 ? "high" : quality >= 0.3 ? "medium" : "low";
|
|
28400
28400
|
lines.push(
|
|
28401
|
-
` [${e.category}] ${e.key} \u2014 ${e.content.slice(0, 80)} (
|
|
28401
|
+
` [${e.category}] ${e.key} \u2014 ${e.content.slice(0, 80)} (quality: ${conf})`
|
|
28402
28402
|
);
|
|
28403
28403
|
}
|
|
28404
28404
|
lines.push("");
|
|
28405
|
-
lines.push("
|
|
28405
|
+
lines.push("Categories:");
|
|
28406
28406
|
for (const [cat, items] of Object.entries(byCategory)) {
|
|
28407
28407
|
lines.push(` ${cat}: ${items.length}`);
|
|
28408
28408
|
}
|
|
28409
28409
|
lines.push("");
|
|
28410
28410
|
const patterns = entries.filter((e) => e.category === "pattern");
|
|
28411
28411
|
if (patterns.length > 0) {
|
|
28412
|
-
lines.push("
|
|
28412
|
+
lines.push("Established patterns:");
|
|
28413
28413
|
for (const p of patterns.slice(0, 5)) {
|
|
28414
28414
|
lines.push(` \u2022 ${p.key}: ${p.content.slice(0, 100)}`);
|
|
28415
28415
|
}
|
|
@@ -28476,7 +28476,7 @@ import { existsSync as existsSync9 } from "fs";
|
|
|
28476
28476
|
import { join as join6 } from "path";
|
|
28477
28477
|
|
|
28478
28478
|
// src/lib/sessions.ts
|
|
28479
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as
|
|
28479
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync4, readdirSync, unlinkSync as unlinkSync2, statSync as statSync2 } from "fs";
|
|
28480
28480
|
import { join as join2 } from "path";
|
|
28481
28481
|
var SESSION_TTL_MS = 10 * 60 * 1e3;
|
|
28482
28482
|
var PRUNE_STALE_MS = 10 * 60 * 1e3;
|
|
@@ -28645,8 +28645,12 @@ function parseIndex(dir) {
|
|
|
28645
28645
|
const size = buf.readUInt32BE(offset + 28);
|
|
28646
28646
|
const sha = buf.slice(offset + 32, offset + 52).toString("hex");
|
|
28647
28647
|
const flags = buf.readUInt16BE(offset + 52);
|
|
28648
|
+
let nameOffset = 62;
|
|
28649
|
+
if (version2 >= 3) {
|
|
28650
|
+
nameOffset += 4;
|
|
28651
|
+
}
|
|
28648
28652
|
const nameLen = flags & 4095;
|
|
28649
|
-
const nameStart = entryStart +
|
|
28653
|
+
const nameStart = entryStart + nameOffset;
|
|
28650
28654
|
let name;
|
|
28651
28655
|
if (nameLen > 0 && nameStart + nameLen <= buf.length) {
|
|
28652
28656
|
name = buf.toString("utf-8", nameStart, nameStart + nameLen);
|
|
@@ -28654,9 +28658,7 @@ function parseIndex(dir) {
|
|
|
28654
28658
|
const end = buf.indexOf(0, nameStart);
|
|
28655
28659
|
name = end >= 0 ? buf.toString("utf-8", nameStart, end) : buf.toString("utf-8", nameStart);
|
|
28656
28660
|
}
|
|
28657
|
-
|
|
28658
|
-
}
|
|
28659
|
-
const rawLen = 62 + name.length;
|
|
28661
|
+
const rawLen = nameOffset + name.length;
|
|
28660
28662
|
const paddedLen = Math.ceil(rawLen / 8) * 8;
|
|
28661
28663
|
offset = entryStart + paddedLen;
|
|
28662
28664
|
entries.push({ mtimeSec, mtimeNsec, dev, ino, mode, uid, gid, size, sha, flags, name });
|
|
@@ -29024,32 +29026,18 @@ function findCallers(root, symbol2) {
|
|
|
29024
29026
|
}
|
|
29025
29027
|
|
|
29026
29028
|
// src/lib/context.ts
|
|
29027
|
-
var normalize4 = (s) => s.toLowerCase().replace(/[-_]/g, " ").replace(/\s+/g, " ").trim();
|
|
29028
|
-
var tokenize3 = (s) => normalize4(s).split(" ").filter(Boolean);
|
|
29029
|
-
var isExpiredLocal3 = (ttl) => {
|
|
29030
|
-
if (!ttl) return false;
|
|
29031
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
29032
|
-
return ttl <= today;
|
|
29033
|
-
};
|
|
29034
|
-
var importance3 = (e) => {
|
|
29035
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
29036
|
-
const days = (Date.now() - (/* @__PURE__ */ new Date(`${e.date || today}T00:00:00`)).getTime()) / 864e5;
|
|
29037
|
-
const recency = Math.max(0, 30 - days) / 30;
|
|
29038
|
-
const freq = Math.min(1, e.accessed / 5);
|
|
29039
|
-
return recency * 0.6 + freq * 0.4;
|
|
29040
|
-
};
|
|
29041
29029
|
function formatOverview(data) {
|
|
29042
29030
|
const entries = parseEntries(data);
|
|
29043
|
-
if (entries.length === 0) return "
|
|
29031
|
+
if (entries.length === 0) return "Memory: empty";
|
|
29044
29032
|
const byCategory = {};
|
|
29045
29033
|
let expired = 0;
|
|
29046
29034
|
for (const e of entries) {
|
|
29047
29035
|
byCategory[e.category] = (byCategory[e.category] || 0) + 1;
|
|
29048
|
-
if (e.ttl &&
|
|
29036
|
+
if (e.ttl && isExpiredLocal(e.ttl)) expired++;
|
|
29049
29037
|
}
|
|
29050
29038
|
const cats = Object.entries(byCategory).map(([k, v]) => `${k}:${v}`).join(" ");
|
|
29051
|
-
const ttlNote = expired > 0 ? ` | ${expired}
|
|
29052
|
-
return `##
|
|
29039
|
+
const ttlNote = expired > 0 ? ` | ${expired} expired` : "";
|
|
29040
|
+
return `## Memory (${entries.length} entries)${ttlNote}
|
|
29053
29041
|
${cats}`;
|
|
29054
29042
|
}
|
|
29055
29043
|
function formatRelevantEntries(data, task, limit = 6) {
|
|
@@ -29058,15 +29046,15 @@ function formatRelevantEntries(data, task, limit = 6) {
|
|
|
29058
29046
|
const { adjacency, byKey } = buildGraph(entries);
|
|
29059
29047
|
const bm25 = bm25Scores(entries, task);
|
|
29060
29048
|
const cent = centrality(adjacency);
|
|
29061
|
-
const qTokens =
|
|
29062
|
-
const scored = entries.filter((e) => !(e.ttl &&
|
|
29063
|
-
const text =
|
|
29049
|
+
const qTokens = tokenize(task);
|
|
29050
|
+
const scored = entries.filter((e) => !(e.ttl && isExpiredLocal(e.ttl))).map((e) => {
|
|
29051
|
+
const text = normalize(
|
|
29064
29052
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
29065
29053
|
);
|
|
29066
29054
|
const matchesQuery = qTokens.length === 0 || qTokens.some((t) => text.includes(t));
|
|
29067
29055
|
const bm25Score = bm25.get(e.key) || 0;
|
|
29068
29056
|
const centScore = cent.get(e.key) || 0;
|
|
29069
|
-
const impScore =
|
|
29057
|
+
const impScore = importance(e);
|
|
29070
29058
|
const combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0);
|
|
29071
29059
|
return { entry: e, score: combined, matchesQuery };
|
|
29072
29060
|
}).filter((x) => x.score > 0 || x.matchesQuery).sort((a, b) => b.score - a.score).slice(0, limit);
|
|
@@ -29082,17 +29070,17 @@ function formatRelevantEntries(data, task, limit = 6) {
|
|
|
29082
29070
|
scored.map((x) => x.entry),
|
|
29083
29071
|
{ adjacency: subAdj, seeds, snippetLen: 80 }
|
|
29084
29072
|
);
|
|
29085
|
-
return `##
|
|
29073
|
+
return `## Relevant entries
|
|
29086
29074
|
${rendered}`;
|
|
29087
29075
|
}
|
|
29088
29076
|
function formatPatterns(data) {
|
|
29089
29077
|
const entries = parseEntries(data);
|
|
29090
|
-
const patterns = entries.filter((e) => e.category === "pattern").sort((a, b) =>
|
|
29078
|
+
const patterns = entries.filter((e) => e.category === "pattern").sort((a, b) => importance(b) - importance(a)).slice(0, 5);
|
|
29091
29079
|
if (patterns.length === 0) return "";
|
|
29092
29080
|
const lines = patterns.map(
|
|
29093
29081
|
(e) => `- **${e.key}**: ${e.content.slice(0, 120)}`
|
|
29094
29082
|
);
|
|
29095
|
-
return `##
|
|
29083
|
+
return `## Established patterns
|
|
29096
29084
|
${lines.join("\n")}`;
|
|
29097
29085
|
}
|
|
29098
29086
|
function formatSessions() {
|
|
@@ -29100,17 +29088,17 @@ function formatSessions() {
|
|
|
29100
29088
|
const { active, conflicts } = coordinationView();
|
|
29101
29089
|
const branch = currentBranch();
|
|
29102
29090
|
if (active.length === 0 && conflicts.length === 0) {
|
|
29103
|
-
return `##
|
|
29104
|
-
|
|
29091
|
+
return `## Sessions
|
|
29092
|
+
Branch: ${branch} | No other active sessions`;
|
|
29105
29093
|
}
|
|
29106
|
-
const lines = [`##
|
|
29094
|
+
const lines = [`## Sessions (${active.length} active) \u2014 branch: ${branch}`];
|
|
29107
29095
|
for (const s of active.slice(0, 5)) {
|
|
29108
29096
|
const mins = Math.max(0, Math.round(s.ageMs / 6e4));
|
|
29109
29097
|
const files = Object.keys(s.files).length;
|
|
29110
|
-
lines.push(`- ${s.agent}@${s.branch} (${mins}min, ${files}
|
|
29098
|
+
lines.push(`- ${s.agent}@${s.branch} (${mins}min, ${files} files)`);
|
|
29111
29099
|
}
|
|
29112
29100
|
if (conflicts.length > 0) {
|
|
29113
|
-
lines.push("", `**
|
|
29101
|
+
lines.push("", `**Soft conflicts (${conflicts.length}):**`);
|
|
29114
29102
|
for (const c of conflicts.slice(0, 3)) {
|
|
29115
29103
|
const who = c.sessions.map((s) => s.agent).join(" + ");
|
|
29116
29104
|
lines.push(`- ${c.file} \u2194 ${who}`);
|
|
@@ -29121,19 +29109,19 @@ Rama: ${branch} | Sin otras sesiones activas`;
|
|
|
29121
29109
|
function formatHealth(data) {
|
|
29122
29110
|
const entries = parseEntries(data);
|
|
29123
29111
|
const warnings = [];
|
|
29124
|
-
const expired = entries.filter((e) => e.ttl &&
|
|
29112
|
+
const expired = entries.filter((e) => e.ttl && isExpiredLocal(e.ttl));
|
|
29125
29113
|
if (expired.length > 0) {
|
|
29126
|
-
warnings.push(`${expired.length}
|
|
29114
|
+
warnings.push(`${expired.length} entries with expired TTL (run memory_archive)`);
|
|
29127
29115
|
}
|
|
29128
29116
|
if (entries.length > 80) {
|
|
29129
|
-
warnings.push(`${entries.length}
|
|
29117
|
+
warnings.push(`${entries.length} entries (near limit of 100, auto-archive will trigger)`);
|
|
29130
29118
|
}
|
|
29131
29119
|
const orphanLinks = findOrphanLinks(entries);
|
|
29132
29120
|
if (orphanLinks.length > 0) {
|
|
29133
|
-
warnings.push(`${orphanLinks.length} links
|
|
29121
|
+
warnings.push(`${orphanLinks.length} orphan links: ${orphanLinks.slice(0, 3).join(", ")}`);
|
|
29134
29122
|
}
|
|
29135
29123
|
if (warnings.length === 0) return "";
|
|
29136
|
-
return `##
|
|
29124
|
+
return `## Health
|
|
29137
29125
|
\u26A0\uFE0F ${warnings.join("\n\u26A0\uFE0F ")}`;
|
|
29138
29126
|
}
|
|
29139
29127
|
function findOrphanLinks(entries) {
|
|
@@ -29164,19 +29152,19 @@ function generateContextBrief(data, opts = {}) {
|
|
|
29164
29152
|
function formatTopEntries(data, limit) {
|
|
29165
29153
|
const entries = parseEntries(data);
|
|
29166
29154
|
if (entries.length === 0) return "";
|
|
29167
|
-
const top = [...entries].filter((e) => !(e.ttl &&
|
|
29155
|
+
const top = [...entries].filter((e) => !(e.ttl && isExpiredLocal(e.ttl))).sort((a, b) => importance(b) - importance(a)).slice(0, limit);
|
|
29168
29156
|
if (top.length === 0) return "";
|
|
29169
29157
|
const rendered = renderCompact(top);
|
|
29170
|
-
return `## Top
|
|
29158
|
+
return `## Top memories
|
|
29171
29159
|
${rendered}`;
|
|
29172
29160
|
}
|
|
29173
29161
|
function generateContextGenerate(data, root, opts = {}) {
|
|
29174
29162
|
const sections = [];
|
|
29175
29163
|
const manifest = readManifest(root);
|
|
29176
29164
|
if (manifest) {
|
|
29177
|
-
const deps = manifest.deps.length > 0 ? manifest.deps.slice(0, 15).join(", ") : "
|
|
29165
|
+
const deps = manifest.deps.length > 0 ? manifest.deps.slice(0, 15).join(", ") : "none";
|
|
29178
29166
|
const version2 = manifest.version ? ` v${manifest.version}` : "";
|
|
29179
|
-
sections.push(`##
|
|
29167
|
+
sections.push(`## Project
|
|
29180
29168
|
${manifest.name}${version2} (${manifest.language})
|
|
29181
29169
|
Deps: ${deps}`);
|
|
29182
29170
|
}
|
|
@@ -29185,9 +29173,9 @@ Deps: ${deps}`);
|
|
|
29185
29173
|
const dirs = structure.dirs.length > 0 ? `Dirs: ${structure.dirs.join(", ")}` : "";
|
|
29186
29174
|
const files = structure.rootFiles.length > 0 ? `Root: ${structure.rootFiles.slice(0, 10).join(", ")}` : "";
|
|
29187
29175
|
const exts = Object.entries(structure.extensions).sort((a, b) => b[1] - a[1]).slice(0, 5).map(([k, v]) => `${k}:${v}`).join(" ");
|
|
29188
|
-
const src = `${structure.sourceFileCount}
|
|
29176
|
+
const src = `${structure.sourceFileCount} source files`;
|
|
29189
29177
|
const parts = [dirs, files, `${src} ${exts ? `(${exts})` : ""}`].filter(Boolean);
|
|
29190
|
-
if (parts.length > 0) sections.push(`##
|
|
29178
|
+
if (parts.length > 0) sections.push(`## Structure
|
|
29191
29179
|
${parts.join("\n")}`);
|
|
29192
29180
|
}
|
|
29193
29181
|
const envVars = readEnvExample(root);
|
|
@@ -29200,8 +29188,8 @@ ${envLines.join("\n")}`);
|
|
|
29200
29188
|
if (git.branch !== "unknown") {
|
|
29201
29189
|
const recent = git.recentCommits.slice(0, 3);
|
|
29202
29190
|
const commitLines = recent.map((c) => `- ${c.shortHash} ${c.subject}`);
|
|
29203
|
-
const parts = [`
|
|
29204
|
-
if (commitLines.length > 0) parts.push(
|
|
29191
|
+
const parts = [`Branch: ${git.branch}`, `Tracked files: ${git.trackedFiles}`];
|
|
29192
|
+
if (commitLines.length > 0) parts.push(`Recent commits:
|
|
29205
29193
|
${commitLines.join("\n")}`);
|
|
29206
29194
|
sections.push(`## Git
|
|
29207
29195
|
${parts.join("\n")}`);
|
|
@@ -29233,7 +29221,7 @@ ${lines.join("\n")}`);
|
|
|
29233
29221
|
}
|
|
29234
29222
|
const tracked = readGitIndex(root);
|
|
29235
29223
|
if (tracked.length > 0) {
|
|
29236
|
-
sections.push(`##
|
|
29224
|
+
sections.push(`## Tracked files (${tracked.length})
|
|
29237
29225
|
${tracked.slice(0, 20).join("\n")}`);
|
|
29238
29226
|
}
|
|
29239
29227
|
const entries = parseEntries(data);
|
|
@@ -29244,18 +29232,31 @@ ${tracked.slice(0, 20).join("\n")}`);
|
|
|
29244
29232
|
const created = recentEntries.filter((e) => e.date === today);
|
|
29245
29233
|
const updated = recentEntries.filter((e) => e.date !== today);
|
|
29246
29234
|
const parts = [];
|
|
29247
|
-
if (created.length > 0) parts.push(`
|
|
29248
|
-
if (updated.length > 0) parts.push(`
|
|
29249
|
-
if (parts.length > 0) sections.push(`##
|
|
29235
|
+
if (created.length > 0) parts.push(`New: ${created.map((e) => e.key).join(", ")}`);
|
|
29236
|
+
if (updated.length > 0) parts.push(`Updated: ${updated.map((e) => e.key).join(", ")}`);
|
|
29237
|
+
if (parts.length > 0) sections.push(`## Memory (${recentEntries.length} changes)
|
|
29250
29238
|
${parts.join("\n")}`);
|
|
29251
29239
|
}
|
|
29252
|
-
const
|
|
29253
|
-
if (
|
|
29254
|
-
const lines =
|
|
29255
|
-
|
|
29240
|
+
const { active, conflicts } = coordinationView();
|
|
29241
|
+
if (active.length > 0) {
|
|
29242
|
+
const lines = active.slice(0, 5).map((s) => {
|
|
29243
|
+
const mins = Math.max(0, Math.round(s.ageMs / 6e4));
|
|
29244
|
+
const files = Object.keys(s.files);
|
|
29245
|
+
const fileList = files.length > 0 ? ` \u2014 ${files.slice(0, 3).join(", ")}${files.length > 3 ? ` +${files.length - 3}` : ""}` : "";
|
|
29246
|
+
return `- ${s.agent}@${s.branch} (${mins}min ago)${fileList}`;
|
|
29247
|
+
});
|
|
29248
|
+
sections.push(`## Active sessions (${active.length})
|
|
29249
|
+
${lines.join("\n")}`);
|
|
29250
|
+
}
|
|
29251
|
+
if (conflicts.length > 0) {
|
|
29252
|
+
const lines = conflicts.slice(0, 3).map((c) => {
|
|
29253
|
+
const who = c.sessions.map((s) => s.agent).join(" + ");
|
|
29254
|
+
return `- ${c.file} \u2194 ${who}`;
|
|
29255
|
+
});
|
|
29256
|
+
sections.push(`## Session conflicts (${conflicts.length})
|
|
29256
29257
|
${lines.join("\n")}`);
|
|
29257
29258
|
}
|
|
29258
|
-
if (sections.length === 0) return "
|
|
29259
|
+
if (sections.length === 0) return "No recent changes.";
|
|
29259
29260
|
return sections.filter(Boolean).join("\n\n");
|
|
29260
29261
|
}
|
|
29261
29262
|
function generateContextFocus(data, root, task, opts = {}) {
|
|
@@ -29264,34 +29265,38 @@ function generateContextFocus(data, root, task, opts = {}) {
|
|
|
29264
29265
|
const relevant = formatRelevantEntries(data, task, limit);
|
|
29265
29266
|
if (relevant) sections.push(relevant);
|
|
29266
29267
|
const keywords = task.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
29268
|
+
const filePatterns = task.toLowerCase().match(/[\w/.-]+\.[a-z]{1,4}/g) || [];
|
|
29269
|
+
const pathPatterns = task.toLowerCase().match(/[\w/.-]+\/[\w/.-]+/g) || [];
|
|
29267
29270
|
const allFiles = [];
|
|
29268
|
-
|
|
29271
|
+
const searchTerms = [...keywords, ...filePatterns, ...pathPatterns];
|
|
29272
|
+
for (const kw of searchTerms) {
|
|
29269
29273
|
allFiles.push(...findFilesByPattern(root, kw));
|
|
29270
29274
|
}
|
|
29271
29275
|
const uniqueFiles = [...new Set(allFiles)].slice(0, 10);
|
|
29272
29276
|
if (uniqueFiles.length > 0) {
|
|
29273
|
-
sections.push(`##
|
|
29277
|
+
sections.push(`## Related files
|
|
29274
29278
|
${uniqueFiles.join("\n")}`);
|
|
29275
29279
|
}
|
|
29276
29280
|
for (const kw of keywords.slice(0, 3)) {
|
|
29277
29281
|
const callers = findCallers(root, kw);
|
|
29278
29282
|
if (callers.length > 0) {
|
|
29279
29283
|
const lines = callers.slice(0, 5).map((c) => `${c.file}:${c.line} \u2014 ${c.content.slice(0, 80)}`);
|
|
29280
|
-
sections.push(`##
|
|
29284
|
+
sections.push(`## References: ${kw}
|
|
29281
29285
|
${lines.join("\n")}`);
|
|
29282
29286
|
}
|
|
29283
29287
|
}
|
|
29284
29288
|
const testFiles = [];
|
|
29285
|
-
|
|
29289
|
+
const testSearchTerms = [...keywords.slice(0, 2), ...filePatterns];
|
|
29290
|
+
for (const kw of testSearchTerms) {
|
|
29286
29291
|
const tests = findFilesByPattern(root, ".test.").filter((f) => f.toLowerCase().includes(kw));
|
|
29287
29292
|
testFiles.push(...tests);
|
|
29288
29293
|
}
|
|
29289
29294
|
const uniqueTests = [...new Set(testFiles)].slice(0, 5);
|
|
29290
29295
|
if (uniqueTests.length > 0) {
|
|
29291
|
-
sections.push(`##
|
|
29296
|
+
sections.push(`## Existing tests
|
|
29292
29297
|
${uniqueTests.join("\n")}`);
|
|
29293
29298
|
}
|
|
29294
|
-
if (sections.length === 0) return `
|
|
29299
|
+
if (sections.length === 0) return `No context found for "${task}".`;
|
|
29295
29300
|
return sections.filter(Boolean).join("\n\n");
|
|
29296
29301
|
}
|
|
29297
29302
|
function generateContextHealth(data, root) {
|
|
@@ -29308,7 +29313,7 @@ function generateContextHealth(data, root) {
|
|
|
29308
29313
|
}
|
|
29309
29314
|
}
|
|
29310
29315
|
if (orphanLinks.length > 0) {
|
|
29311
|
-
warnings.push(`${orphanLinks.length} links
|
|
29316
|
+
warnings.push(`${orphanLinks.length} orphan links: ${orphanLinks.slice(0, 5).join(", ")}`);
|
|
29312
29317
|
score -= 5;
|
|
29313
29318
|
}
|
|
29314
29319
|
const contentMap = /* @__PURE__ */ new Map();
|
|
@@ -29322,19 +29327,18 @@ function generateContextHealth(data, root) {
|
|
|
29322
29327
|
if (keys2.length > 1) duplicates.push(keys2.join(" = "));
|
|
29323
29328
|
}
|
|
29324
29329
|
if (duplicates.length > 0) {
|
|
29325
|
-
warnings.push(`${duplicates.length}
|
|
29330
|
+
warnings.push(`${duplicates.length} duplicate entries: ${duplicates.slice(0, 3).join("; ")}`);
|
|
29326
29331
|
score -= 5;
|
|
29327
29332
|
}
|
|
29328
|
-
const
|
|
29329
|
-
|
|
29330
|
-
|
|
29331
|
-
|
|
29332
|
-
info.push(`${missingQuality.length} entradas sin quality score`);
|
|
29333
|
+
const weekAgo = new Date(Date.now() - 7 * 864e5).toISOString().split("T")[0];
|
|
29334
|
+
const staleNeverAccessed = entries.filter((e) => e.accessed === 0 && e.date < weekAgo);
|
|
29335
|
+
if (staleNeverAccessed.length > 0) {
|
|
29336
|
+
info.push(`${staleNeverAccessed.length} old entries never recalled (possibly stale)`);
|
|
29333
29337
|
score -= 2;
|
|
29334
29338
|
}
|
|
29335
|
-
const expired = entries.filter((e) => e.ttl &&
|
|
29339
|
+
const expired = entries.filter((e) => e.ttl && isExpiredLocal(e.ttl));
|
|
29336
29340
|
if (expired.length > 0) {
|
|
29337
|
-
info.push(`${expired.length}
|
|
29341
|
+
info.push(`${expired.length} entries with expired TTL (auto-prune on next startup)`);
|
|
29338
29342
|
score -= 3;
|
|
29339
29343
|
}
|
|
29340
29344
|
const brokenFiles = [];
|
|
@@ -29347,25 +29351,25 @@ function generateContextHealth(data, root) {
|
|
|
29347
29351
|
}
|
|
29348
29352
|
}
|
|
29349
29353
|
if (brokenFiles.length > 0) {
|
|
29350
|
-
warnings.push(`${brokenFiles.length} refs
|
|
29354
|
+
warnings.push(`${brokenFiles.length} refs to non-existent files: ${brokenFiles.slice(0, 3).join("; ")}`);
|
|
29351
29355
|
score -= 5;
|
|
29352
29356
|
}
|
|
29353
29357
|
const sessions = listSessions();
|
|
29354
29358
|
const stale = sessions.filter((s) => !s.active && !s.ended);
|
|
29355
29359
|
if (stale.length > 0) {
|
|
29356
|
-
info.push(`${stale.length}
|
|
29360
|
+
info.push(`${stale.length} stale sessions (will be pruned automatically)`);
|
|
29357
29361
|
}
|
|
29358
29362
|
if (entries.length > 80) {
|
|
29359
|
-
warnings.push(`${entries.length}
|
|
29363
|
+
warnings.push(`${entries.length} entries (near limit of 100)`);
|
|
29360
29364
|
score -= 3;
|
|
29361
29365
|
} else if (entries.length === 0) {
|
|
29362
|
-
info.push("
|
|
29366
|
+
info.push("Empty memory");
|
|
29363
29367
|
}
|
|
29364
29368
|
score = Math.max(0, score);
|
|
29365
29369
|
const report = { score, warnings, info, critical };
|
|
29366
29370
|
const parts = [`## Memory Health: ${score >= 90 ? "\u2705" : score >= 70 ? "\u26A0\uFE0F" : "\u274C"} ${score}/100`];
|
|
29367
29371
|
if (critical.length > 0) {
|
|
29368
|
-
parts.push("", "###
|
|
29372
|
+
parts.push("", "### Critical", ...critical.map((w) => `- ${w}`));
|
|
29369
29373
|
}
|
|
29370
29374
|
if (warnings.length > 0) {
|
|
29371
29375
|
parts.push("", "### Warnings", ...warnings.map((w) => `- ${w}`));
|
|
@@ -29380,10 +29384,10 @@ function generateContextExport(data, format = "full") {
|
|
|
29380
29384
|
const sections = [];
|
|
29381
29385
|
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
29382
29386
|
sections.push(`# toon-memory export
|
|
29383
|
-
|
|
29387
|
+
Date: ${today} | Entries: ${entries.length}
|
|
29384
29388
|
`);
|
|
29385
29389
|
if (entries.length === 0) {
|
|
29386
|
-
sections.push("
|
|
29390
|
+
sections.push("Empty memory.");
|
|
29387
29391
|
return sections.join("\n");
|
|
29388
29392
|
}
|
|
29389
29393
|
const byCategory = {};
|
|
@@ -29392,10 +29396,10 @@ Fecha: ${today} | Entradas: ${entries.length}
|
|
|
29392
29396
|
byCategory[e.category].push(e);
|
|
29393
29397
|
}
|
|
29394
29398
|
const categoryLabels = {
|
|
29395
|
-
decision: "
|
|
29396
|
-
pattern: "
|
|
29399
|
+
decision: "Decisions",
|
|
29400
|
+
pattern: "Patterns",
|
|
29397
29401
|
bug: "Bugs",
|
|
29398
|
-
knowledge: "
|
|
29402
|
+
knowledge: "Knowledge"
|
|
29399
29403
|
};
|
|
29400
29404
|
for (const [cat, items] of Object.entries(byCategory)) {
|
|
29401
29405
|
const label = categoryLabels[cat] || cat;
|
|
@@ -29424,7 +29428,7 @@ _${e.date}${tags}${file2}${links}_`);
|
|
|
29424
29428
|
}
|
|
29425
29429
|
}
|
|
29426
29430
|
if (edges.length > 0) {
|
|
29427
|
-
sections.push(`##
|
|
29431
|
+
sections.push(`## Graph (${edges.length} edges)`);
|
|
29428
29432
|
sections.push(edges.slice(0, 20).join("\n"));
|
|
29429
29433
|
}
|
|
29430
29434
|
}
|
|
@@ -29432,7 +29436,7 @@ _${e.date}${tags}${file2}${links}_`);
|
|
|
29432
29436
|
const sessions = listSessions();
|
|
29433
29437
|
if (sessions.length > 0) {
|
|
29434
29438
|
const active = sessions.filter((s) => s.active);
|
|
29435
|
-
sections.push(`##
|
|
29439
|
+
sections.push(`## Sessions (${active.length} active / ${sessions.length} total)`);
|
|
29436
29440
|
for (const s of sessions.slice(0, 5)) {
|
|
29437
29441
|
const status = s.active ? "\u{1F7E2}" : "\u26AA";
|
|
29438
29442
|
sections.push(`- ${status} ${s.agent}@${s.branch} (${s.id})`);
|
|
@@ -29442,21 +29446,20 @@ _${e.date}${tags}${file2}${links}_`);
|
|
|
29442
29446
|
}
|
|
29443
29447
|
|
|
29444
29448
|
// src/mcp/tools.ts
|
|
29445
|
-
var normalize5 = (s) => s.toLowerCase().replace(/[-_]/g, " ").replace(/\s+/g, " ").trim();
|
|
29446
29449
|
function registerTools(server2) {
|
|
29447
29450
|
server2.registerTool(
|
|
29448
29451
|
"memory_remember",
|
|
29449
29452
|
{
|
|
29450
29453
|
title: "Save to Memory",
|
|
29451
|
-
description: "
|
|
29454
|
+
description: "Save a fact to the project's persistent memory (decisions, patterns, bugs, knowledge). Persists between sessions.",
|
|
29452
29455
|
inputSchema: {
|
|
29453
|
-
category: external_exports.enum(["decision", "pattern", "bug", "knowledge"]).describe("
|
|
29454
|
-
key: external_exports.string().describe("
|
|
29455
|
-
content: external_exports.string().describe("
|
|
29456
|
-
file: external_exports.string().optional().default("").describe("
|
|
29457
|
-
tags: external_exports.string().optional().default("").describe("
|
|
29458
|
-
ttl: external_exports.string().optional().default("").describe("Time to live (
|
|
29459
|
-
links: external_exports.string().optional().default("").describe("
|
|
29456
|
+
category: external_exports.enum(["decision", "pattern", "bug", "knowledge"]).describe("Category of the fact"),
|
|
29457
|
+
key: external_exports.string().describe("Short title in kebab-case (e.g. risk-engine-priority)"),
|
|
29458
|
+
content: external_exports.string().describe("Detailed content of the fact"),
|
|
29459
|
+
file: external_exports.string().optional().default("").describe("Related file or line (e.g. spec.md:145)"),
|
|
29460
|
+
tags: external_exports.string().optional().default("").describe("Semicolon-separated tags (e.g. risk;spec)"),
|
|
29461
|
+
ttl: external_exports.string().optional().default("").describe("Time to live (e.g. 7d, 2026-07-17). Empty = no expiration"),
|
|
29462
|
+
links: external_exports.string().optional().default("").describe("Related entry keys, separated by space or ';' (e.g. risk-spec engine-arch). Builds graph edges.")
|
|
29460
29463
|
}
|
|
29461
29464
|
},
|
|
29462
29465
|
async ({ category, key, content, file: file2, tags, ttl, links }) => {
|
|
@@ -29488,14 +29491,14 @@ function registerTools(server2) {
|
|
|
29488
29491
|
const existingParts = existingIdx !== -1 ? lines[existingIdx].trim().split("|") : [];
|
|
29489
29492
|
const resolvedLinks = links ? links.split(/[\s;]+/).filter(Boolean).join(" ") : existingParts[9] || "";
|
|
29490
29493
|
let newEntry = `${entryId}|${category}|${key}|${content}|${file2 || ""}|${resolvedTags}|${date5}|${resolvedTtl}|0|${resolvedLinks}`;
|
|
29491
|
-
let action = "
|
|
29494
|
+
let action = "Saved";
|
|
29492
29495
|
let mergeInfo = "";
|
|
29493
29496
|
const tagsInferred = !tags && resolvedTags ? true : false;
|
|
29494
29497
|
if (existingIdx !== -1) {
|
|
29495
29498
|
newEntry = mergeEntries(lines[existingIdx].trim(), newEntry);
|
|
29496
29499
|
lines[existingIdx] = ` ${newEntry}`;
|
|
29497
|
-
action = "
|
|
29498
|
-
mergeInfo = "\
|
|
29500
|
+
action = "Updated";
|
|
29501
|
+
mergeInfo = "\nMerge: tags combined, date and links updated";
|
|
29499
29502
|
} else {
|
|
29500
29503
|
const quality = qualityScore(resolvedTags, resolvedLinks, content, date5);
|
|
29501
29504
|
const confidence = 1;
|
|
@@ -29509,7 +29512,7 @@ function registerTools(server2) {
|
|
|
29509
29512
|
const headerMatch = lines[headerIdx].match(/\[(\d+)\|/);
|
|
29510
29513
|
const entryCount = headerMatch ? parseInt(headerMatch[1]) : 0;
|
|
29511
29514
|
let archiveMsg = "";
|
|
29512
|
-
if (entryCount >
|
|
29515
|
+
if (entryCount > getMaxEntries()) {
|
|
29513
29516
|
const result = archiveOldEntries({ trimToMax: true });
|
|
29514
29517
|
if (result.archived > 0) {
|
|
29515
29518
|
archiveMsg = `
|
|
@@ -29519,14 +29522,14 @@ function registerTools(server2) {
|
|
|
29519
29522
|
const ttlMsg = resolvedTtl ? `
|
|
29520
29523
|
\u23F0 TTL: ${resolvedTtl}` : "";
|
|
29521
29524
|
const inferredMsg = tagsInferred ? `
|
|
29522
|
-
\u{1F3F7}\uFE0F
|
|
29525
|
+
\u{1F3F7}\uFE0F Inferred tags: ${resolvedTags}` : "";
|
|
29523
29526
|
const related = findRelatedEntries(`${key} ${content} ${resolvedTags}`, key, 3);
|
|
29524
29527
|
let relatedMsg = "";
|
|
29525
29528
|
if (related.length > 0) {
|
|
29526
29529
|
const items = related.map((r) => ` [${r.cat}] ${r.key} \u2014 ${r.content.slice(0, 80)}`).join("\n");
|
|
29527
29530
|
relatedMsg = `
|
|
29528
29531
|
|
|
29529
|
-
\u{1F517}
|
|
29532
|
+
\u{1F517} Related entries:
|
|
29530
29533
|
${items}`;
|
|
29531
29534
|
}
|
|
29532
29535
|
return {
|
|
@@ -29539,88 +29542,39 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29539
29542
|
"memory_recall",
|
|
29540
29543
|
{
|
|
29541
29544
|
title: "Search Memory",
|
|
29542
|
-
description: "
|
|
29545
|
+
description: "Search the project's persistent memory. Returns relevant entries. Use BEFORE reading files.",
|
|
29543
29546
|
inputSchema: {
|
|
29544
|
-
query: external_exports.string().describe("
|
|
29545
|
-
category: external_exports.string().optional().default("").describe("
|
|
29546
|
-
from_date: external_exports.string().optional().default("").describe("
|
|
29547
|
-
to_date: external_exports.string().optional().default("").describe("
|
|
29548
|
-
mode: external_exports.enum(["flat", "graph"]).optional().default("flat").describe("'flat' =
|
|
29549
|
-
hops: external_exports.number().optional().default(1).describe("
|
|
29550
|
-
compact: external_exports.boolean().optional().default(false).describe("
|
|
29547
|
+
query: external_exports.string().describe("Text to search for"),
|
|
29548
|
+
category: external_exports.string().optional().default("").describe("Filter by category (empty = all)"),
|
|
29549
|
+
from_date: external_exports.string().optional().default("").describe("Start date filter (YYYY-MM-DD)"),
|
|
29550
|
+
to_date: external_exports.string().optional().default("").describe("End date filter (YYYY-MM-DD)"),
|
|
29551
|
+
mode: external_exports.enum(["flat", "graph"]).optional().default("flat").describe("'flat' = keyword search (default). 'graph' = graph-based recall: expands the related-entry subgraph from matches (more precise, fewer tokens)."),
|
|
29552
|
+
hops: external_exports.number().optional().default(1).describe("Graph depth in 'graph' mode (1 or 2). Default 1."),
|
|
29553
|
+
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.")
|
|
29551
29554
|
}
|
|
29552
29555
|
},
|
|
29553
29556
|
async ({ query, category, from_date, to_date, mode, hops, compact }) => {
|
|
29554
29557
|
const data = readMemory();
|
|
29555
|
-
const
|
|
29556
|
-
|
|
29557
|
-
|
|
29558
|
-
const trimmed = line.trim();
|
|
29559
|
-
const parts = trimmed.split("|");
|
|
29560
|
-
if (parts.length < 7) return null;
|
|
29561
|
-
const [id, cat, key, content, file2, tags, date5, ttl, accessedRaw] = parts;
|
|
29562
|
-
const qualityRaw = parts[10] || "";
|
|
29563
|
-
const confidenceRaw = parts[11] || "";
|
|
29564
|
-
if (category && cat !== category) return null;
|
|
29565
|
-
if (from_date && date5 < from_date) return null;
|
|
29566
|
-
if (to_date && date5 > to_date) return null;
|
|
29567
|
-
if (ttl && isExpired(ttl)) return null;
|
|
29568
|
-
const searchStr = normalize5(`${id} ${cat} ${key} ${content} ${file2} ${tags} ${qualityRaw} ${confidenceRaw}`);
|
|
29569
|
-
if (!queryTokens.every((token) => searchStr.includes(token))) return null;
|
|
29570
|
-
const accessed = accessedRaw ? parseInt(accessedRaw) || 0 : 0;
|
|
29571
|
-
return { id, cat, key, content, file: file2, tags, date: date5, accessed, qualityRaw, confidenceRaw };
|
|
29572
|
-
}).filter(Boolean);
|
|
29573
|
-
if (results.length === 0) {
|
|
29574
|
-
return { content: [{ type: "text", text: `No se encontraron resultados para "${query}"` }] };
|
|
29575
|
-
}
|
|
29576
|
-
if (mode === "graph") {
|
|
29577
|
-
const detail = graphRecallDetailed(data, query, { category, from_date, to_date, hops });
|
|
29578
|
-
if (detail.entries.length === 0) {
|
|
29579
|
-
return { content: [{ type: "text", text: `No se encontraron resultados para "${query}"` }] };
|
|
29580
|
-
}
|
|
29581
|
-
bumpAccessed(detail.entries.map((e) => e.id));
|
|
29582
|
-
if (compact) {
|
|
29583
|
-
const formatted3 = renderCompact(detail.entries, {
|
|
29584
|
-
adjacency: detail.adjacency,
|
|
29585
|
-
seeds: detail.seeds,
|
|
29586
|
-
snippetLen: 90
|
|
29587
|
-
});
|
|
29588
|
-
return { content: [{ type: "text", text: formatted3 }] };
|
|
29589
|
-
}
|
|
29590
|
-
const formatted2 = detail.entries.map((r) => {
|
|
29591
|
-
const links = r.links.length ? `
|
|
29592
|
-
links: ${r.links.join(", ")}` : "";
|
|
29593
|
-
return `[${r.category}] ${r.key} (${r.id})
|
|
29594
|
-
${r.content}
|
|
29595
|
-
File: ${r.file} | Tags: ${r.tags.join(";")} | Date: ${r.date}${links}`;
|
|
29596
|
-
}).join("\n\n");
|
|
29597
|
-
return { content: [{ type: "text", text: formatted2 }] };
|
|
29558
|
+
const detail = graphRecallDetailed(data, query, { category, from_date, to_date, hops });
|
|
29559
|
+
if (detail.entries.length === 0) {
|
|
29560
|
+
return { content: [{ type: "text", text: `No results found for "${query}"` }] };
|
|
29598
29561
|
}
|
|
29599
|
-
|
|
29600
|
-
const quality = r.qualityRaw ? parseFloat(r.qualityRaw) || 0 : 0;
|
|
29601
|
-
const qualityBoost = quality * 0.15;
|
|
29602
|
-
return { ...r, score: entryScore(r.date, r.accessed) + qualityBoost };
|
|
29603
|
-
}).sort((a, b) => b.score - a.score);
|
|
29604
|
-
bumpAccessed(ranked.map((r) => r.id));
|
|
29562
|
+
bumpAccessed(detail.entries.map((e) => e.id));
|
|
29605
29563
|
if (compact) {
|
|
29606
|
-
const
|
|
29607
|
-
|
|
29608
|
-
|
|
29609
|
-
|
|
29610
|
-
|
|
29611
|
-
file: r.file,
|
|
29612
|
-
tags: r.tags ? r.tags.split(";").filter(Boolean) : [],
|
|
29613
|
-
date: r.date,
|
|
29614
|
-
ttl: "",
|
|
29615
|
-
accessed: r.accessed,
|
|
29616
|
-
links: []
|
|
29617
|
-
}));
|
|
29618
|
-
const formatted2 = renderCompact(entries);
|
|
29564
|
+
const formatted2 = renderCompact(detail.entries, {
|
|
29565
|
+
adjacency: detail.adjacency,
|
|
29566
|
+
seeds: detail.seeds,
|
|
29567
|
+
snippetLen: 90
|
|
29568
|
+
});
|
|
29619
29569
|
return { content: [{ type: "text", text: formatted2 }] };
|
|
29620
29570
|
}
|
|
29621
|
-
const formatted =
|
|
29571
|
+
const formatted = detail.entries.map((r) => {
|
|
29572
|
+
const links = r.links.length ? `
|
|
29573
|
+
links: ${r.links.join(", ")}` : "";
|
|
29574
|
+
return `[${r.category}] ${r.key} (${r.id})
|
|
29622
29575
|
${r.content}
|
|
29623
|
-
File: ${r.file} | Tags: ${r.tags} | Date: ${r.date}
|
|
29576
|
+
File: ${r.file} | Tags: ${r.tags.join(";")} | Date: ${r.date}${links}`;
|
|
29577
|
+
}).join("\n\n");
|
|
29624
29578
|
return { content: [{ type: "text", text: formatted }] };
|
|
29625
29579
|
}
|
|
29626
29580
|
);
|
|
@@ -29628,9 +29582,9 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29628
29582
|
"memory_forget",
|
|
29629
29583
|
{
|
|
29630
29584
|
title: "Delete from Memory",
|
|
29631
|
-
description: "
|
|
29585
|
+
description: "Delete a memory entry by its key or id.",
|
|
29632
29586
|
inputSchema: {
|
|
29633
|
-
key: external_exports.string().describe("Key
|
|
29587
|
+
key: external_exports.string().describe("Key or id of the entry to delete")
|
|
29634
29588
|
}
|
|
29635
29589
|
},
|
|
29636
29590
|
async ({ key }) => {
|
|
@@ -29638,7 +29592,7 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29638
29592
|
const lines = data.split("\n");
|
|
29639
29593
|
const headerIdx = lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l));
|
|
29640
29594
|
if (headerIdx === -1) {
|
|
29641
|
-
return { content: [{ type: "text", text: "No
|
|
29595
|
+
return { content: [{ type: "text", text: "No entries in memory" }] };
|
|
29642
29596
|
}
|
|
29643
29597
|
const entryLines2 = lines.slice(headerIdx + 1).filter((l) => l.trim().length > 0 && !l.startsWith(" summaries:"));
|
|
29644
29598
|
const filtered = entryLines2.filter((l) => {
|
|
@@ -29651,8 +29605,13 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29651
29605
|
lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count - removed}|`);
|
|
29652
29606
|
lines.splice(headerIdx + 1, entryLines2.length, ...filtered.map((l) => ` ${l.trim()}`));
|
|
29653
29607
|
writeMemory(lines.join("\n"));
|
|
29608
|
+
if (removed === 0) {
|
|
29609
|
+
return {
|
|
29610
|
+
content: [{ type: "text", text: `"${key}" not found in memory.` }]
|
|
29611
|
+
};
|
|
29612
|
+
}
|
|
29654
29613
|
return {
|
|
29655
|
-
content: [{ type: "text", text: `"${key}"
|
|
29614
|
+
content: [{ type: "text", text: `"${key}" deleted. ${count - removed} entries remaining.` }]
|
|
29656
29615
|
};
|
|
29657
29616
|
}
|
|
29658
29617
|
);
|
|
@@ -29660,7 +29619,7 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29660
29619
|
"memory_stats",
|
|
29661
29620
|
{
|
|
29662
29621
|
title: "Memory Stats",
|
|
29663
|
-
description: "
|
|
29622
|
+
description: "Show project memory statistics.",
|
|
29664
29623
|
inputSchema: {}
|
|
29665
29624
|
},
|
|
29666
29625
|
async () => {
|
|
@@ -29680,16 +29639,16 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29680
29639
|
const avgQuality = withQuality > 0 ? (entries.reduce((sum, e) => sum + (e.quality ? parseFloat(e.quality) : 0), 0) / withQuality).toFixed(2) : "N/A";
|
|
29681
29640
|
const summaryLines = data.split("\n").filter((l) => l.includes(":") && !l.startsWith(" ") && !l.startsWith("version") && !l.startsWith("entries") && !/^\[\d+\|]/.test(l));
|
|
29682
29641
|
const stats = [
|
|
29683
|
-
`
|
|
29684
|
-
`
|
|
29642
|
+
`Total entries: ${entries.length}`,
|
|
29643
|
+
`File summaries: ${summaryLines.length}`,
|
|
29685
29644
|
"",
|
|
29686
|
-
"
|
|
29645
|
+
"By category:",
|
|
29687
29646
|
...Object.entries(byCategory).map(([k, v]) => ` ${k}: ${v}`),
|
|
29688
29647
|
"",
|
|
29689
|
-
`TTL: ${withTtl}
|
|
29690
|
-
`
|
|
29648
|
+
`TTL: ${withTtl} with expiration, ${expired} expired`,
|
|
29649
|
+
`Average quality: ${avgQuality} (${withQuality} with score)`,
|
|
29691
29650
|
"",
|
|
29692
|
-
|
|
29651
|
+
`Last 5 entries:`,
|
|
29693
29652
|
...lines.slice(-5).map((l) => {
|
|
29694
29653
|
const parts = l.trim().split("|");
|
|
29695
29654
|
const ttlInfo = parts[7] ? ` | TTL: ${parts[7]}` : "";
|
|
@@ -29704,10 +29663,10 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29704
29663
|
"memory_diff",
|
|
29705
29664
|
{
|
|
29706
29665
|
title: "Memory Diff",
|
|
29707
|
-
description: "
|
|
29666
|
+
description: "Show what changed in memory since a date. Useful for seeing what was learned since the last session.",
|
|
29708
29667
|
inputSchema: {
|
|
29709
|
-
since: external_exports.string().describe("
|
|
29710
|
-
type: external_exports.enum(["all", "created", "updated"]).optional().default("all").describe("
|
|
29668
|
+
since: external_exports.string().describe("Show changes since (e.g. 24h, 7d, 2026-07-10)"),
|
|
29669
|
+
type: external_exports.enum(["all", "created", "updated"]).optional().default("all").describe("Filter by change type")
|
|
29711
29670
|
}
|
|
29712
29671
|
},
|
|
29713
29672
|
async ({ since, type }) => {
|
|
@@ -29726,13 +29685,13 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29726
29685
|
return { id, cat, key, content, file: file2, tags, date: date5, changeType };
|
|
29727
29686
|
}).filter(Boolean);
|
|
29728
29687
|
if (results.length === 0) {
|
|
29729
|
-
return { content: [{ type: "text", text: `No
|
|
29688
|
+
return { content: [{ type: "text", text: `No changes since ${sinceDate}` }] };
|
|
29730
29689
|
}
|
|
29731
29690
|
const created = results.filter((r) => r.changeType === "created");
|
|
29732
29691
|
const updated = results.filter((r) => r.changeType === "updated");
|
|
29733
|
-
const sections = [`\u{1F4CB}
|
|
29692
|
+
const sections = [`\u{1F4CB} Changes since ${sinceDate}:`, ""];
|
|
29734
29693
|
if (created.length > 0 && (type === "all" || type === "created")) {
|
|
29735
|
-
sections.push(`\u2795
|
|
29694
|
+
sections.push(`\u2795 New (${created.length}):`);
|
|
29736
29695
|
for (const r of created) {
|
|
29737
29696
|
sections.push(` [${r.cat}] ${r.key} (${r.id})
|
|
29738
29697
|
${r.content}`);
|
|
@@ -29740,7 +29699,7 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29740
29699
|
sections.push("");
|
|
29741
29700
|
}
|
|
29742
29701
|
if (updated.length > 0 && (type === "all" || type === "updated")) {
|
|
29743
|
-
sections.push(`\u270F\uFE0F
|
|
29702
|
+
sections.push(`\u270F\uFE0F Updated (${updated.length}):`);
|
|
29744
29703
|
for (const r of updated) {
|
|
29745
29704
|
sections.push(` [${r.cat}] ${r.key} (${r.id}) \u2014 ${r.date}`);
|
|
29746
29705
|
}
|
|
@@ -29753,21 +29712,21 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29753
29712
|
"memory_suggest",
|
|
29754
29713
|
{
|
|
29755
29714
|
title: "Suggest Related Memories",
|
|
29756
|
-
description: "
|
|
29715
|
+
description: "Suggest memory entries related to a given context. Useful for gathering context before a task.",
|
|
29757
29716
|
inputSchema: {
|
|
29758
|
-
context: external_exports.string().describe("
|
|
29759
|
-
limit: external_exports.number().optional().default(5).describe("
|
|
29717
|
+
context: external_exports.string().describe("Text or context to search for suggestions"),
|
|
29718
|
+
limit: external_exports.number().optional().default(5).describe("Maximum suggestions")
|
|
29760
29719
|
}
|
|
29761
29720
|
},
|
|
29762
29721
|
async ({ context, limit }) => {
|
|
29763
29722
|
const related = findRelatedEntries(context, "", limit);
|
|
29764
29723
|
if (related.length === 0) {
|
|
29765
|
-
return { content: [{ type: "text", text: `No
|
|
29724
|
+
return { content: [{ type: "text", text: `No related entries found for "${context}"` }] };
|
|
29766
29725
|
}
|
|
29767
29726
|
const formatted = related.map((r) => `[${r.cat}] ${r.key} (${r.id})
|
|
29768
29727
|
${r.content}
|
|
29769
29728
|
File: ${r.file} | Tags: ${r.tags} | Date: ${r.date}`).join("\n\n");
|
|
29770
|
-
return { content: [{ type: "text", text: `\u{1F50D}
|
|
29729
|
+
return { content: [{ type: "text", text: `\u{1F50D} Suggestions for "${context}":
|
|
29771
29730
|
|
|
29772
29731
|
${formatted}` }] };
|
|
29773
29732
|
}
|
|
@@ -29776,11 +29735,11 @@ ${formatted}` }] };
|
|
|
29776
29735
|
"memory_smart_recall",
|
|
29777
29736
|
{
|
|
29778
29737
|
title: "Smart Recall (Unified)",
|
|
29779
|
-
description: "
|
|
29738
|
+
description: "Unified retrieval: combines BM25 + graph + decay + quality in a single call. Use at the START of each task to get all relevant memory context.",
|
|
29780
29739
|
inputSchema: {
|
|
29781
|
-
intent: external_exports.string().describe("Describe
|
|
29782
|
-
limit: external_exports.number().optional().default(8).describe("
|
|
29783
|
-
category: external_exports.string().optional().default("").describe("
|
|
29740
|
+
intent: external_exports.string().describe("Describe what you need to know (e.g. 'database schema for backend')"),
|
|
29741
|
+
limit: external_exports.number().optional().default(8).describe("Maximum entries to return"),
|
|
29742
|
+
category: external_exports.string().optional().default("").describe("Filter by category (empty = all)")
|
|
29784
29743
|
}
|
|
29785
29744
|
},
|
|
29786
29745
|
async ({ intent, limit, category }) => {
|
|
@@ -29793,11 +29752,11 @@ ${formatted}` }] };
|
|
|
29793
29752
|
"memory_summary",
|
|
29794
29753
|
{
|
|
29795
29754
|
title: "File Summary",
|
|
29796
|
-
description: "
|
|
29755
|
+
description: "Save or retrieve a summary of a large file to save tokens.",
|
|
29797
29756
|
inputSchema: {
|
|
29798
|
-
action: external_exports.enum(["get", "set"]).describe("get
|
|
29799
|
-
file: external_exports.string().describe("
|
|
29800
|
-
summary: external_exports.string().optional().default("").describe("
|
|
29757
|
+
action: external_exports.enum(["get", "set"]).describe("get to read, set to save"),
|
|
29758
|
+
file: external_exports.string().describe("File path"),
|
|
29759
|
+
summary: external_exports.string().optional().default("").describe("File summary (only for set)")
|
|
29801
29760
|
}
|
|
29802
29761
|
},
|
|
29803
29762
|
async ({ action, file: file2, summary }) => {
|
|
@@ -29806,12 +29765,12 @@ ${formatted}` }] };
|
|
|
29806
29765
|
const lines2 = data.split("\n");
|
|
29807
29766
|
const summaryIdx2 = lines2.findIndex((l) => l.trim().startsWith("summaries:"));
|
|
29808
29767
|
if (summaryIdx2 === -1) {
|
|
29809
|
-
return { content: [{ type: "text", text: `No
|
|
29768
|
+
return { content: [{ type: "text", text: `No summaries saved for "${file2}"` }] };
|
|
29810
29769
|
}
|
|
29811
29770
|
const summaryLines2 = lines2.slice(summaryIdx2 + 1).filter((l) => l.includes(":"));
|
|
29812
29771
|
const match = summaryLines2.find((l) => l.startsWith(` ${file2}:`));
|
|
29813
29772
|
if (!match) {
|
|
29814
|
-
return { content: [{ type: "text", text: `No
|
|
29773
|
+
return { content: [{ type: "text", text: `No summary for "${file2}"` }] };
|
|
29815
29774
|
}
|
|
29816
29775
|
const summaryText = match.replace(` ${file2}: `, "");
|
|
29817
29776
|
return { content: [{ type: "text", text: summaryText }] };
|
|
@@ -29832,7 +29791,7 @@ ${formatted}` }] };
|
|
|
29832
29791
|
lines.splice(summaryIdx + 1, lines.length - summaryIdx - 1, ...summaryLines);
|
|
29833
29792
|
writeMemory(lines.join("\n"));
|
|
29834
29793
|
return {
|
|
29835
|
-
content: [{ type: "text", text: `\u{1F4DD}
|
|
29794
|
+
content: [{ type: "text", text: `\u{1F4DD} Summary saved for ${file2}` }]
|
|
29836
29795
|
};
|
|
29837
29796
|
}
|
|
29838
29797
|
);
|
|
@@ -29840,19 +29799,19 @@ ${formatted}` }] };
|
|
|
29840
29799
|
"memory_archive",
|
|
29841
29800
|
{
|
|
29842
29801
|
title: "Archive Old Entries",
|
|
29843
|
-
description: "
|
|
29802
|
+
description: "Move old entries (>30 days) to archive.toon to keep memory clean.",
|
|
29844
29803
|
inputSchema: {}
|
|
29845
29804
|
},
|
|
29846
29805
|
async () => {
|
|
29847
29806
|
const result = archiveOldEntries();
|
|
29848
29807
|
if (result.archived === 0) {
|
|
29849
|
-
return { content: [{ type: "text", text: "No
|
|
29808
|
+
return { content: [{ type: "text", text: "No old entries to archive" }] };
|
|
29850
29809
|
}
|
|
29851
29810
|
return {
|
|
29852
29811
|
content: [{
|
|
29853
29812
|
type: "text",
|
|
29854
|
-
text: `\u{1F4E6}
|
|
29855
|
-
\u{1F4CB}
|
|
29813
|
+
text: `\u{1F4E6} Archived ${result.archived} old entries
|
|
29814
|
+
\u{1F4CB} ${result.kept} active entries remaining`
|
|
29856
29815
|
}]
|
|
29857
29816
|
};
|
|
29858
29817
|
}
|
|
@@ -29861,24 +29820,24 @@ ${formatted}` }] };
|
|
|
29861
29820
|
"memory_encrypt",
|
|
29862
29821
|
{
|
|
29863
29822
|
title: "Enable Encryption",
|
|
29864
|
-
description: "
|
|
29823
|
+
description: "Enable AES-256-GCM encryption for memory. Requires TOON_MEMORY_KEY in environment.",
|
|
29865
29824
|
inputSchema: {}
|
|
29866
29825
|
},
|
|
29867
29826
|
async () => {
|
|
29868
29827
|
const config2 = loadConfig();
|
|
29869
29828
|
if (config2.encrypted) {
|
|
29870
|
-
return { content: [{ type: "text", text: "
|
|
29829
|
+
return { content: [{ type: "text", text: "Encryption is already enabled" }] };
|
|
29871
29830
|
}
|
|
29872
29831
|
const key = getKey();
|
|
29873
29832
|
if (!key) {
|
|
29874
|
-
return { content: [{ type: "text", text: "\u274C
|
|
29833
|
+
return { content: [{ type: "text", text: "\u274C Set TOON_MEMORY_KEY in environment before encrypting" }] };
|
|
29875
29834
|
}
|
|
29876
|
-
const data =
|
|
29835
|
+
const data = readUnderLock(MEMORY_FILE);
|
|
29877
29836
|
const encrypted = encrypt(data, key);
|
|
29878
|
-
|
|
29837
|
+
safeWrite(MEMORY_FILE, encrypted);
|
|
29879
29838
|
saveConfig({ encrypted: true });
|
|
29880
29839
|
return {
|
|
29881
|
-
content: [{ type: "text", text: "\u{1F510}
|
|
29840
|
+
content: [{ type: "text", text: "\u{1F510} Encryption enabled" }]
|
|
29882
29841
|
};
|
|
29883
29842
|
}
|
|
29884
29843
|
);
|
|
@@ -29886,30 +29845,30 @@ ${formatted}` }] };
|
|
|
29886
29845
|
"memory_decrypt",
|
|
29887
29846
|
{
|
|
29888
29847
|
title: "Disable Encryption",
|
|
29889
|
-
description: "
|
|
29848
|
+
description: "Disable encryption and decode memory.",
|
|
29890
29849
|
inputSchema: {
|
|
29891
|
-
key: external_exports.string().describe("
|
|
29850
|
+
key: external_exports.string().describe("Encryption key")
|
|
29892
29851
|
}
|
|
29893
29852
|
},
|
|
29894
29853
|
async ({ key }) => {
|
|
29895
29854
|
const config2 = loadConfig();
|
|
29896
29855
|
if (!config2.encrypted) {
|
|
29897
|
-
return { content: [{ type: "text", text: "
|
|
29856
|
+
return { content: [{ type: "text", text: "Encryption is not enabled" }] };
|
|
29898
29857
|
}
|
|
29899
29858
|
const resolvedKey = key || getKey() || "";
|
|
29900
29859
|
if (!resolvedKey) {
|
|
29901
|
-
return { content: [{ type: "text", text: "\u274C No
|
|
29860
|
+
return { content: [{ type: "text", text: "\u274C No key provided. Pass as argument or set in .env file" }] };
|
|
29902
29861
|
}
|
|
29903
29862
|
try {
|
|
29904
|
-
const data =
|
|
29863
|
+
const data = readUnderLock(MEMORY_FILE);
|
|
29905
29864
|
const decrypted = decrypt(data, resolvedKey);
|
|
29906
|
-
|
|
29865
|
+
safeWrite(MEMORY_FILE, decrypted);
|
|
29907
29866
|
saveConfig({ encrypted: false });
|
|
29908
29867
|
return {
|
|
29909
|
-
content: [{ type: "text", text: "\u{1F513}
|
|
29868
|
+
content: [{ type: "text", text: "\u{1F513} Encryption disabled" }]
|
|
29910
29869
|
};
|
|
29911
29870
|
} catch {
|
|
29912
|
-
return { content: [{ type: "text", text: "\u274C
|
|
29871
|
+
return { content: [{ type: "text", text: "\u274C Wrong key or corrupted data" }] };
|
|
29913
29872
|
}
|
|
29914
29873
|
}
|
|
29915
29874
|
);
|
|
@@ -29917,20 +29876,20 @@ ${formatted}` }] };
|
|
|
29917
29876
|
"memory_captured",
|
|
29918
29877
|
{
|
|
29919
29878
|
title: "List Captured Activity",
|
|
29920
|
-
description: "
|
|
29879
|
+
description: "Show activity log captured automatically by hooks (only if capture is enabled). Useful for promoting observations to memory with memory_remember.",
|
|
29921
29880
|
inputSchema: {
|
|
29922
|
-
limit: external_exports.number().optional().default(20).describe("
|
|
29923
|
-
tool: external_exports.string().optional().default("").describe("
|
|
29924
|
-
file: external_exports.string().optional().default("").describe("
|
|
29925
|
-
clear: external_exports.boolean().optional().default(false).describe("
|
|
29881
|
+
limit: external_exports.number().optional().default(20).describe("Maximum observations to show"),
|
|
29882
|
+
tool: external_exports.string().optional().default("").describe("Filter by tool name"),
|
|
29883
|
+
file: external_exports.string().optional().default("").describe("Filter by file"),
|
|
29884
|
+
clear: external_exports.boolean().optional().default(false).describe("If true, clears the capture log")
|
|
29926
29885
|
}
|
|
29927
29886
|
},
|
|
29928
29887
|
async ({ limit, tool, file: file2, clear }) => {
|
|
29929
29888
|
if (clear) {
|
|
29930
29889
|
if (existsSync10(OBSERVATIONS_FILE)) {
|
|
29931
|
-
|
|
29890
|
+
writeFileSync5(OBSERVATIONS_FILE, "version: 1\nobservations[0|]{ts|session|agent|branch|tool|hash|file|summary}:\n");
|
|
29932
29891
|
}
|
|
29933
|
-
return { content: [{ type: "text", text: "\u{1F9F9}
|
|
29892
|
+
return { content: [{ type: "text", text: "\u{1F9F9} Capture log cleared" }] };
|
|
29934
29893
|
}
|
|
29935
29894
|
let obs = readObservations();
|
|
29936
29895
|
if (tool) obs = obs.filter((o) => o.tool.toLowerCase().includes(tool.toLowerCase()));
|
|
@@ -29940,13 +29899,13 @@ ${formatted}` }] };
|
|
|
29940
29899
|
return {
|
|
29941
29900
|
content: [{
|
|
29942
29901
|
type: "text",
|
|
29943
|
-
text: "No
|
|
29902
|
+
text: "No captured activity. Capture is disabled by default; enable with `toon-memory capture on`."
|
|
29944
29903
|
}]
|
|
29945
29904
|
};
|
|
29946
29905
|
}
|
|
29947
29906
|
const formatted = obs.map((o) => `[${o.ts}] ${o.agent}@${o.branch}/${o.tool}${o.file ? ` (${o.file})` : ""}
|
|
29948
29907
|
${o.summary}`).join("\n\n");
|
|
29949
|
-
return { content: [{ type: "text", text: `\u{1F50D}
|
|
29908
|
+
return { content: [{ type: "text", text: `\u{1F50D} Captured activity (${obs.length}):
|
|
29950
29909
|
|
|
29951
29910
|
${formatted}` }] };
|
|
29952
29911
|
}
|
|
@@ -29955,20 +29914,20 @@ ${formatted}` }] };
|
|
|
29955
29914
|
"memory_consolidate",
|
|
29956
29915
|
{
|
|
29957
29916
|
title: "Consolidate Memory",
|
|
29958
|
-
description: "
|
|
29917
|
+
description: "Consolidate memory by removing entries with identical content (keeps the first). Deterministic, no LLM.",
|
|
29959
29918
|
inputSchema: {}
|
|
29960
29919
|
},
|
|
29961
29920
|
async () => {
|
|
29962
29921
|
const result = consolidateEntries();
|
|
29963
29922
|
if (result.removed === 0) {
|
|
29964
|
-
return { content: [{ type: "text", text: `\u2705
|
|
29923
|
+
return { content: [{ type: "text", text: `\u2705 Memory already consolidated (${result.kept} entries, 0 duplicates)` }] };
|
|
29965
29924
|
}
|
|
29966
29925
|
return {
|
|
29967
29926
|
content: [{
|
|
29968
29927
|
type: "text",
|
|
29969
|
-
text: `\u{1F9F9}
|
|
29970
|
-
|
|
29971
|
-
|
|
29928
|
+
text: `\u{1F9F9} Consolidated ${result.removed} duplicate entries.
|
|
29929
|
+
${result.kept} active entries remaining.
|
|
29930
|
+
Duplicates: ${result.duplicates.join(", ")}`
|
|
29972
29931
|
}]
|
|
29973
29932
|
};
|
|
29974
29933
|
}
|
|
@@ -29977,9 +29936,9 @@ Duplicados: ${result.duplicates.join(", ")}`
|
|
|
29977
29936
|
"memory_sessions",
|
|
29978
29937
|
{
|
|
29979
29938
|
title: "Active Sessions & Conflicts",
|
|
29980
|
-
description: "
|
|
29939
|
+
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.",
|
|
29981
29940
|
inputSchema: {
|
|
29982
|
-
conflictsOnly: external_exports.boolean().optional().default(false).describe("
|
|
29941
|
+
conflictsOnly: external_exports.boolean().optional().default(false).describe("If true, only show soft conflicts")
|
|
29983
29942
|
}
|
|
29984
29943
|
},
|
|
29985
29944
|
async ({ conflictsOnly }) => {
|
|
@@ -29987,7 +29946,7 @@ Duplicados: ${result.duplicates.join(", ")}`
|
|
|
29987
29946
|
const { active, conflicts } = coordinationView(selfId);
|
|
29988
29947
|
if (conflictsOnly) {
|
|
29989
29948
|
if (conflicts.length === 0) {
|
|
29990
|
-
return { content: [{ type: "text", text: "\u2705 No
|
|
29949
|
+
return { content: [{ type: "text", text: "\u2705 No soft conflicts between active sessions." }] };
|
|
29991
29950
|
}
|
|
29992
29951
|
const lines = conflicts.map((c) => {
|
|
29993
29952
|
const who = c.sessions.map((s) => `${s.agent}@${s.branch} (${s.id})`).join(", ");
|
|
@@ -29995,7 +29954,7 @@ Duplicados: ${result.duplicates.join(", ")}`
|
|
|
29995
29954
|
\u2194 ${who}`;
|
|
29996
29955
|
});
|
|
29997
29956
|
return {
|
|
29998
|
-
content: [{ type: "text", text: `\u{1F525}
|
|
29957
|
+
content: [{ type: "text", text: `\u{1F525} Soft conflicts (${conflicts.length}):
|
|
29999
29958
|
|
|
30000
29959
|
${lines.join("\n\n")}` }]
|
|
30001
29960
|
};
|
|
@@ -30004,36 +29963,36 @@ ${lines.join("\n\n")}` }]
|
|
|
30004
29963
|
return {
|
|
30005
29964
|
content: [{
|
|
30006
29965
|
type: "text",
|
|
30007
|
-
text: "\u{1F7E2} No
|
|
29966
|
+
text: "\u{1F7E2} No other active sessions in this project.\n(This session: " + selfId + " @ " + currentBranch() + ")"
|
|
30008
29967
|
}]
|
|
30009
29968
|
};
|
|
30010
29969
|
}
|
|
30011
29970
|
const ttlMin = Math.round(SESSION_TTL_MS / 6e4);
|
|
30012
29971
|
const section = (s) => {
|
|
30013
29972
|
const mins = Math.max(0, Math.round(s.ageMs / 6e4));
|
|
30014
|
-
const tag = s.id === selfId ? " (
|
|
29973
|
+
const tag = s.id === selfId ? " (you)" : "";
|
|
30015
29974
|
const ended = s.ended ? " \u{1F3C1}" : "";
|
|
30016
29975
|
const files = Object.keys(s.files).slice(0, 8).map((f) => ` \u2022 ${f}`).join("\n");
|
|
30017
29976
|
const fileBlock = files ? `
|
|
30018
|
-
|
|
29977
|
+
Files:
|
|
30019
29978
|
${files}` : "";
|
|
30020
29979
|
return `\u2022 ${s.agent} @ ${s.branch}${tag}${ended}
|
|
30021
29980
|
id: ${s.id}
|
|
30022
|
-
|
|
29981
|
+
${mins} min ago${fileBlock}`;
|
|
30023
29982
|
};
|
|
30024
29983
|
const parts = [
|
|
30025
|
-
`\u{1F9ED}
|
|
29984
|
+
`\u{1F9ED} Active sessions (${active.length}) \u2014 window ${ttlMin} min:`,
|
|
30026
29985
|
"",
|
|
30027
29986
|
...active.map(section)
|
|
30028
29987
|
];
|
|
30029
29988
|
if (conflicts.length > 0) {
|
|
30030
|
-
parts.push("", `\u{1F525}
|
|
29989
|
+
parts.push("", `\u{1F525} Soft conflicts (${conflicts.length}):`);
|
|
30031
29990
|
for (const c of conflicts) {
|
|
30032
29991
|
const who = c.sessions.map((s) => `${s.agent}@${s.branch}`).join(", ");
|
|
30033
29992
|
parts.push(` \u26A0\uFE0F ${c.file} \u2194 ${who}`);
|
|
30034
29993
|
}
|
|
30035
29994
|
} else {
|
|
30036
|
-
parts.push("", "\u2705
|
|
29995
|
+
parts.push("", "\u2705 No soft conflicts detected.");
|
|
30037
29996
|
}
|
|
30038
29997
|
return { content: [{ type: "text", text: parts.join("\n") }] };
|
|
30039
29998
|
}
|
|
@@ -30042,10 +30001,10 @@ ${files}` : "";
|
|
|
30042
30001
|
"context_brief",
|
|
30043
30002
|
{
|
|
30044
30003
|
title: "Context Briefing",
|
|
30045
|
-
description: "
|
|
30004
|
+
description: "Generate a compact context briefing: relevant memory + active sessions + project health. Single call instead of 5-6 separate calls. Zero LLM, pure deterministic logic.",
|
|
30046
30005
|
inputSchema: {
|
|
30047
|
-
task: external_exports.string().optional().default("").describe("
|
|
30048
|
-
limit: external_exports.number().optional().default(6).describe("
|
|
30006
|
+
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."),
|
|
30007
|
+
limit: external_exports.number().optional().default(6).describe("Maximum relevant entries to show")
|
|
30049
30008
|
}
|
|
30050
30009
|
},
|
|
30051
30010
|
async ({ task, limit }) => {
|
|
@@ -30058,9 +30017,9 @@ ${files}` : "";
|
|
|
30058
30017
|
"context_generate",
|
|
30059
30018
|
{
|
|
30060
30019
|
title: "Generate Full Context",
|
|
30061
|
-
description: "
|
|
30020
|
+
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.",
|
|
30062
30021
|
inputSchema: {
|
|
30063
|
-
task: external_exports.string().optional().default("").describe("
|
|
30022
|
+
task: external_exports.string().optional().default("").describe("Agent task. If provided, ranks entries by relevance to this task.")
|
|
30064
30023
|
}
|
|
30065
30024
|
},
|
|
30066
30025
|
async ({ task }) => {
|
|
@@ -30074,9 +30033,9 @@ ${files}` : "";
|
|
|
30074
30033
|
"context_diff",
|
|
30075
30034
|
{
|
|
30076
30035
|
title: "Context Diff",
|
|
30077
|
-
description: "
|
|
30036
|
+
description: "What changed since the last session: git commits + modified files + new/updated memory entries. Zero LLM.",
|
|
30078
30037
|
inputSchema: {
|
|
30079
|
-
since: external_exports.string().optional().default("").describe("
|
|
30038
|
+
since: external_exports.string().optional().default("").describe("Start date (YYYY-MM-DD or relative like '7d'). Empty = last visible changes.")
|
|
30080
30039
|
}
|
|
30081
30040
|
},
|
|
30082
30041
|
async ({ since }) => {
|
|
@@ -30090,10 +30049,10 @@ ${files}` : "";
|
|
|
30090
30049
|
"context_focus",
|
|
30091
30050
|
{
|
|
30092
30051
|
title: "Focus Context for Task",
|
|
30093
|
-
description: "
|
|
30052
|
+
description: "Hyper-focused context for a specific task: relevant entries + related files + code referencing the symbol + existing tests. Zero LLM.",
|
|
30094
30053
|
inputSchema: {
|
|
30095
|
-
task: external_exports.string().describe("
|
|
30096
|
-
limit: external_exports.number().optional().default(6).describe("
|
|
30054
|
+
task: external_exports.string().describe("Task or symbol to search context for (e.g. 'fix auth bug', 'authenticate')"),
|
|
30055
|
+
limit: external_exports.number().optional().default(6).describe("Maximum memory entries to include")
|
|
30097
30056
|
}
|
|
30098
30057
|
},
|
|
30099
30058
|
async ({ task, limit }) => {
|
|
@@ -30107,7 +30066,7 @@ ${files}` : "";
|
|
|
30107
30066
|
"context_health",
|
|
30108
30067
|
{
|
|
30109
30068
|
title: "Memory Health Audit",
|
|
30110
|
-
description: "
|
|
30069
|
+
description: "Full memory health audit: orphan links, duplicates, broken refs, expired TTL, quality, stale sessions. Includes score 0-100. Zero LLM.",
|
|
30111
30070
|
inputSchema: {}
|
|
30112
30071
|
},
|
|
30113
30072
|
async () => {
|
|
@@ -30121,9 +30080,9 @@ ${files}` : "";
|
|
|
30121
30080
|
"context_export",
|
|
30122
30081
|
{
|
|
30123
30082
|
title: "Export Memory as Markdown",
|
|
30124
|
-
description: "
|
|
30083
|
+
description: "Export all memory as markdown injectable for other agents or sessions. Full (detailed) or compact format. Zero LLM.",
|
|
30125
30084
|
inputSchema: {
|
|
30126
|
-
format: external_exports.enum(["full", "compact"]).optional().default("full").describe("full =
|
|
30085
|
+
format: external_exports.enum(["full", "compact"]).optional().default("full").describe("full = detailed with graph, compact = summarized without edges")
|
|
30127
30086
|
}
|
|
30128
30087
|
},
|
|
30129
30088
|
async ({ format }) => {
|
|
@@ -30132,6 +30091,46 @@ ${files}` : "";
|
|
|
30132
30091
|
return { content: [{ type: "text", text: exported }] };
|
|
30133
30092
|
}
|
|
30134
30093
|
);
|
|
30094
|
+
server2.registerTool(
|
|
30095
|
+
"memory_backup",
|
|
30096
|
+
{
|
|
30097
|
+
title: "Backup Memory",
|
|
30098
|
+
description: "Create a timestamped backup of the memory file. Use before major operations or to preserve state.",
|
|
30099
|
+
inputSchema: {}
|
|
30100
|
+
},
|
|
30101
|
+
async () => {
|
|
30102
|
+
if (!existsSync10(MEMORY_FILE)) {
|
|
30103
|
+
return { content: [{ type: "text", text: "No memory file to backup" }] };
|
|
30104
|
+
}
|
|
30105
|
+
const backupDir = join7(MEMORY_DIR, "backups");
|
|
30106
|
+
if (!existsSync10(backupDir)) mkdirSync3(backupDir, { recursive: true });
|
|
30107
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
30108
|
+
const backupFile = join7(backupDir, `memory-${timestamp}.toon`);
|
|
30109
|
+
copyFileSync(MEMORY_FILE, backupFile);
|
|
30110
|
+
let archiveBackup = "";
|
|
30111
|
+
if (existsSync10(ARCHIVE_FILE)) {
|
|
30112
|
+
const archiveBackupFile = join7(backupDir, `archive-${timestamp}.toon`);
|
|
30113
|
+
copyFileSync(ARCHIVE_FILE, archiveBackupFile);
|
|
30114
|
+
archiveBackup = `
|
|
30115
|
+
\u{1F4E6} Archive backed up`;
|
|
30116
|
+
}
|
|
30117
|
+
const backups = readdirSync5(backupDir).filter((f) => f.startsWith("memory-") && f.endsWith(".toon")).sort().reverse();
|
|
30118
|
+
for (const old of backups.slice(10)) {
|
|
30119
|
+
try {
|
|
30120
|
+
const { unlinkSync: unlinkSync3 } = __require("fs");
|
|
30121
|
+
unlinkSync3(join7(backupDir, old));
|
|
30122
|
+
} catch {
|
|
30123
|
+
}
|
|
30124
|
+
}
|
|
30125
|
+
return {
|
|
30126
|
+
content: [{
|
|
30127
|
+
type: "text",
|
|
30128
|
+
text: `\u{1F4BE} Memory backed up to ${basename(backupFile)}${archiveBackup}
|
|
30129
|
+
\u{1F4E6} ${backups.length} backup(s) retained`
|
|
30130
|
+
}]
|
|
30131
|
+
};
|
|
30132
|
+
}
|
|
30133
|
+
);
|
|
30135
30134
|
}
|
|
30136
30135
|
|
|
30137
30136
|
// src/mcp/resources.ts
|
|
@@ -30163,9 +30162,9 @@ function registerResources(server2) {
|
|
|
30163
30162
|
const withTtl = entries.filter((e) => e.ttl).length;
|
|
30164
30163
|
const expired = entries.filter((e) => e.ttl && isExpired(e.ttl)).length;
|
|
30165
30164
|
const text = [
|
|
30166
|
-
`
|
|
30167
|
-
`TTL: ${withTtl}
|
|
30168
|
-
"
|
|
30165
|
+
`Total entries: ${entries.length}`,
|
|
30166
|
+
`TTL: ${withTtl} with expiration, ${expired} expired`,
|
|
30167
|
+
"By category:",
|
|
30169
30168
|
...Object.entries(byCategory).map(([k, v]) => ` ${k}: ${v}`)
|
|
30170
30169
|
].join("\n");
|
|
30171
30170
|
return { contents: [{ uri: uri.href, text }] };
|
|
@@ -30185,7 +30184,7 @@ function registerResources(server2) {
|
|
|
30185
30184
|
|
|
30186
30185
|
// src/mcp/server.ts
|
|
30187
30186
|
var server = new McpServer(
|
|
30188
|
-
{ name: "toon-memory", version: "2.
|
|
30187
|
+
{ name: "toon-memory", version: "2.9.0" },
|
|
30189
30188
|
{ capabilities: { tools: { listChanged: true }, resources: { listChanged: true } } }
|
|
30190
30189
|
);
|
|
30191
30190
|
registerResources(server);
|