toon-memory 2.8.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/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 +269 -252
- package/package.json +2 -2
- 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 +78 -57
- package/src/lib/quality.ts +16 -11
- package/src/mcp/archive.ts +5 -4
- package/src/mcp/config.ts +9 -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 +179 -187
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 });
|
|
@@ -27639,7 +27645,8 @@ var StdioServerTransport = class {
|
|
|
27639
27645
|
};
|
|
27640
27646
|
|
|
27641
27647
|
// src/mcp/tools.ts
|
|
27642
|
-
import { writeFileSync as
|
|
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() {
|
|
@@ -27942,10 +27952,7 @@ function parseRelativeDate(since) {
|
|
|
27942
27952
|
|
|
27943
27953
|
// src/mcp/scoring.ts
|
|
27944
27954
|
function entryScore(dateStr, accessed) {
|
|
27945
|
-
|
|
27946
|
-
const recency = Math.max(0, 30 - days) / 30;
|
|
27947
|
-
const freq = Math.min(1, accessed / 5);
|
|
27948
|
-
return recency * 0.6 + freq * 0.4;
|
|
27955
|
+
return importance({ date: dateStr, accessed });
|
|
27949
27956
|
}
|
|
27950
27957
|
function entryScoreForLine(line) {
|
|
27951
27958
|
const parts = line.trim().split("|");
|
|
@@ -27995,7 +28002,7 @@ function bumpAccessed(ids) {
|
|
|
27995
28002
|
}
|
|
27996
28003
|
|
|
27997
28004
|
// src/mcp/observations.ts
|
|
27998
|
-
import { readFileSync as readFileSync3, existsSync as existsSync3 } from "fs";
|
|
28005
|
+
import { readFileSync as readFileSync3, existsSync as existsSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
27999
28006
|
function readObservations() {
|
|
28000
28007
|
if (!existsSync3(OBSERVATIONS_FILE)) return [];
|
|
28001
28008
|
return readFileSync3(OBSERVATIONS_FILE, "utf-8").split("\n").filter((l) => l.startsWith(" ") && l.includes("|")).map((l) => {
|
|
@@ -28026,8 +28033,9 @@ function archiveOldEntries(opts = {}) {
|
|
|
28026
28033
|
});
|
|
28027
28034
|
if (opts.trimToMax) {
|
|
28028
28035
|
const remaining = entryLines2.length - toArchive.size;
|
|
28029
|
-
|
|
28030
|
-
|
|
28036
|
+
const maxEntries = getMaxEntries();
|
|
28037
|
+
if (remaining > maxEntries) {
|
|
28038
|
+
const need = remaining - maxEntries;
|
|
28031
28039
|
const candidates = entryLines2.map((line, idx) => ({ idx, score: entryScoreForLine(line) })).filter((c) => !toArchive.has(c.idx)).sort((a, b) => a.score - b.score);
|
|
28032
28040
|
for (let i = 0; i < need && i < candidates.length; i++) toArchive.add(candidates[i].idx);
|
|
28033
28041
|
}
|
|
@@ -28046,7 +28054,7 @@ archived:
|
|
|
28046
28054
|
const archiveLines = archiveContent.split("\n");
|
|
28047
28055
|
let archiveHeaderIdx = archiveLines.findIndex((l) => l.startsWith("archived["));
|
|
28048
28056
|
if (archiveHeaderIdx === -1) {
|
|
28049
|
-
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}:`);
|
|
28050
28058
|
archiveHeaderIdx = archiveLines.length - 1;
|
|
28051
28059
|
}
|
|
28052
28060
|
const archiveMatch = archiveLines[archiveHeaderIdx].match(/archived\[(\d+)\|/);
|
|
@@ -28322,6 +28330,9 @@ function mergeEntries(existingLine, newLine) {
|
|
|
28322
28330
|
const existingTtl = ep[7] || "";
|
|
28323
28331
|
const newTtl = np[7] || "";
|
|
28324
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);
|
|
28325
28336
|
const existingConf = ep.length > 11 ? parseFloat(ep[11]) || 0 : 0;
|
|
28326
28337
|
const newConf = np.length > 11 ? parseFloat(np[11]) || 0 : 0;
|
|
28327
28338
|
const confidence = Math.max(existingConf, newConf);
|
|
@@ -28329,11 +28340,11 @@ function mergeEntries(existingLine, newLine) {
|
|
|
28329
28340
|
const newLinks = (np[9] || "").split(/[\s;]+/).filter(Boolean);
|
|
28330
28341
|
const mergedLinks = [.../* @__PURE__ */ new Set([...existingLinks, ...newLinks])].join(" ");
|
|
28331
28342
|
const quality = qualityScore(mergedTags, mergedLinks, content, date5);
|
|
28332
|
-
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}`;
|
|
28333
28344
|
}
|
|
28334
28345
|
function generateSmartRecall(data, intent, opts = {}) {
|
|
28335
28346
|
const entries = parseEntries(data);
|
|
28336
|
-
if (entries.length === 0) return "
|
|
28347
|
+
if (entries.length === 0) return "Empty memory.";
|
|
28337
28348
|
const { adjacency } = buildGraph(entries);
|
|
28338
28349
|
const bm25 = bm25Scores(entries, intent);
|
|
28339
28350
|
const cent = centrality(adjacency);
|
|
@@ -28357,7 +28368,7 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
28357
28368
|
}).filter((x) => x.score > 0 || x.matchesQuery).sort((a, b) => b.score - a.score).slice(0, limit);
|
|
28358
28369
|
if (scored.length === 0) {
|
|
28359
28370
|
const top = entries.filter((e) => !category || e.category === category).sort((a, b) => importance(b) - importance(a)).slice(0, limit);
|
|
28360
|
-
if (top.length === 0) return "No
|
|
28371
|
+
if (top.length === 0) return "No entries in memory.";
|
|
28361
28372
|
return renderCompact(top);
|
|
28362
28373
|
}
|
|
28363
28374
|
if (opts.bumpAccess) opts.bumpAccess(scored.map((x) => x.entry.id));
|
|
@@ -28365,7 +28376,7 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
28365
28376
|
}
|
|
28366
28377
|
function generateSystemPrimer(data) {
|
|
28367
28378
|
const entries = parseEntries(data);
|
|
28368
|
-
if (entries.length === 0) return "
|
|
28379
|
+
if (entries.length === 0) return "Empty memory. No entries saved.";
|
|
28369
28380
|
const byCategory = {};
|
|
28370
28381
|
for (const e of entries) {
|
|
28371
28382
|
if (!byCategory[e.category]) byCategory[e.category] = [];
|
|
@@ -28373,11 +28384,11 @@ function generateSystemPrimer(data) {
|
|
|
28373
28384
|
}
|
|
28374
28385
|
const lines = [
|
|
28375
28386
|
"=== System Primer ===",
|
|
28376
|
-
`
|
|
28387
|
+
`Entries: ${entries.length}`,
|
|
28377
28388
|
""
|
|
28378
28389
|
];
|
|
28379
28390
|
const top = [...entries].sort((a, b) => importance(b) - importance(a)).slice(0, 5);
|
|
28380
|
-
lines.push("Top
|
|
28391
|
+
lines.push("Top memories:");
|
|
28381
28392
|
for (const e of top) {
|
|
28382
28393
|
const quality = qualityScore(
|
|
28383
28394
|
e.tags.join(";"),
|
|
@@ -28385,20 +28396,20 @@ function generateSystemPrimer(data) {
|
|
|
28385
28396
|
e.content,
|
|
28386
28397
|
e.date
|
|
28387
28398
|
);
|
|
28388
|
-
const conf = quality >= 0.5 ? "
|
|
28399
|
+
const conf = quality >= 0.5 ? "high" : quality >= 0.3 ? "medium" : "low";
|
|
28389
28400
|
lines.push(
|
|
28390
|
-
` [${e.category}] ${e.key} \u2014 ${e.content.slice(0, 80)} (
|
|
28401
|
+
` [${e.category}] ${e.key} \u2014 ${e.content.slice(0, 80)} (quality: ${conf})`
|
|
28391
28402
|
);
|
|
28392
28403
|
}
|
|
28393
28404
|
lines.push("");
|
|
28394
|
-
lines.push("
|
|
28405
|
+
lines.push("Categories:");
|
|
28395
28406
|
for (const [cat, items] of Object.entries(byCategory)) {
|
|
28396
28407
|
lines.push(` ${cat}: ${items.length}`);
|
|
28397
28408
|
}
|
|
28398
28409
|
lines.push("");
|
|
28399
28410
|
const patterns = entries.filter((e) => e.category === "pattern");
|
|
28400
28411
|
if (patterns.length > 0) {
|
|
28401
|
-
lines.push("
|
|
28412
|
+
lines.push("Established patterns:");
|
|
28402
28413
|
for (const p of patterns.slice(0, 5)) {
|
|
28403
28414
|
lines.push(` \u2022 ${p.key}: ${p.content.slice(0, 100)}`);
|
|
28404
28415
|
}
|
|
@@ -28465,7 +28476,7 @@ import { existsSync as existsSync9 } from "fs";
|
|
|
28465
28476
|
import { join as join6 } from "path";
|
|
28466
28477
|
|
|
28467
28478
|
// src/lib/sessions.ts
|
|
28468
|
-
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";
|
|
28469
28480
|
import { join as join2 } from "path";
|
|
28470
28481
|
var SESSION_TTL_MS = 10 * 60 * 1e3;
|
|
28471
28482
|
var PRUNE_STALE_MS = 10 * 60 * 1e3;
|
|
@@ -29017,7 +29028,7 @@ function findCallers(root, symbol2) {
|
|
|
29017
29028
|
// src/lib/context.ts
|
|
29018
29029
|
function formatOverview(data) {
|
|
29019
29030
|
const entries = parseEntries(data);
|
|
29020
|
-
if (entries.length === 0) return "
|
|
29031
|
+
if (entries.length === 0) return "Memory: empty";
|
|
29021
29032
|
const byCategory = {};
|
|
29022
29033
|
let expired = 0;
|
|
29023
29034
|
for (const e of entries) {
|
|
@@ -29025,8 +29036,8 @@ function formatOverview(data) {
|
|
|
29025
29036
|
if (e.ttl && isExpiredLocal(e.ttl)) expired++;
|
|
29026
29037
|
}
|
|
29027
29038
|
const cats = Object.entries(byCategory).map(([k, v]) => `${k}:${v}`).join(" ");
|
|
29028
|
-
const ttlNote = expired > 0 ? ` | ${expired}
|
|
29029
|
-
return `##
|
|
29039
|
+
const ttlNote = expired > 0 ? ` | ${expired} expired` : "";
|
|
29040
|
+
return `## Memory (${entries.length} entries)${ttlNote}
|
|
29030
29041
|
${cats}`;
|
|
29031
29042
|
}
|
|
29032
29043
|
function formatRelevantEntries(data, task, limit = 6) {
|
|
@@ -29059,7 +29070,7 @@ function formatRelevantEntries(data, task, limit = 6) {
|
|
|
29059
29070
|
scored.map((x) => x.entry),
|
|
29060
29071
|
{ adjacency: subAdj, seeds, snippetLen: 80 }
|
|
29061
29072
|
);
|
|
29062
|
-
return `##
|
|
29073
|
+
return `## Relevant entries
|
|
29063
29074
|
${rendered}`;
|
|
29064
29075
|
}
|
|
29065
29076
|
function formatPatterns(data) {
|
|
@@ -29069,7 +29080,7 @@ function formatPatterns(data) {
|
|
|
29069
29080
|
const lines = patterns.map(
|
|
29070
29081
|
(e) => `- **${e.key}**: ${e.content.slice(0, 120)}`
|
|
29071
29082
|
);
|
|
29072
|
-
return `##
|
|
29083
|
+
return `## Established patterns
|
|
29073
29084
|
${lines.join("\n")}`;
|
|
29074
29085
|
}
|
|
29075
29086
|
function formatSessions() {
|
|
@@ -29077,17 +29088,17 @@ function formatSessions() {
|
|
|
29077
29088
|
const { active, conflicts } = coordinationView();
|
|
29078
29089
|
const branch = currentBranch();
|
|
29079
29090
|
if (active.length === 0 && conflicts.length === 0) {
|
|
29080
|
-
return `##
|
|
29081
|
-
|
|
29091
|
+
return `## Sessions
|
|
29092
|
+
Branch: ${branch} | No other active sessions`;
|
|
29082
29093
|
}
|
|
29083
|
-
const lines = [`##
|
|
29094
|
+
const lines = [`## Sessions (${active.length} active) \u2014 branch: ${branch}`];
|
|
29084
29095
|
for (const s of active.slice(0, 5)) {
|
|
29085
29096
|
const mins = Math.max(0, Math.round(s.ageMs / 6e4));
|
|
29086
29097
|
const files = Object.keys(s.files).length;
|
|
29087
|
-
lines.push(`- ${s.agent}@${s.branch} (${mins}min, ${files}
|
|
29098
|
+
lines.push(`- ${s.agent}@${s.branch} (${mins}min, ${files} files)`);
|
|
29088
29099
|
}
|
|
29089
29100
|
if (conflicts.length > 0) {
|
|
29090
|
-
lines.push("", `**
|
|
29101
|
+
lines.push("", `**Soft conflicts (${conflicts.length}):**`);
|
|
29091
29102
|
for (const c of conflicts.slice(0, 3)) {
|
|
29092
29103
|
const who = c.sessions.map((s) => s.agent).join(" + ");
|
|
29093
29104
|
lines.push(`- ${c.file} \u2194 ${who}`);
|
|
@@ -29100,17 +29111,17 @@ function formatHealth(data) {
|
|
|
29100
29111
|
const warnings = [];
|
|
29101
29112
|
const expired = entries.filter((e) => e.ttl && isExpiredLocal(e.ttl));
|
|
29102
29113
|
if (expired.length > 0) {
|
|
29103
|
-
warnings.push(`${expired.length}
|
|
29114
|
+
warnings.push(`${expired.length} entries with expired TTL (run memory_archive)`);
|
|
29104
29115
|
}
|
|
29105
29116
|
if (entries.length > 80) {
|
|
29106
|
-
warnings.push(`${entries.length}
|
|
29117
|
+
warnings.push(`${entries.length} entries (near limit of 100, auto-archive will trigger)`);
|
|
29107
29118
|
}
|
|
29108
29119
|
const orphanLinks = findOrphanLinks(entries);
|
|
29109
29120
|
if (orphanLinks.length > 0) {
|
|
29110
|
-
warnings.push(`${orphanLinks.length} links
|
|
29121
|
+
warnings.push(`${orphanLinks.length} orphan links: ${orphanLinks.slice(0, 3).join(", ")}`);
|
|
29111
29122
|
}
|
|
29112
29123
|
if (warnings.length === 0) return "";
|
|
29113
|
-
return `##
|
|
29124
|
+
return `## Health
|
|
29114
29125
|
\u26A0\uFE0F ${warnings.join("\n\u26A0\uFE0F ")}`;
|
|
29115
29126
|
}
|
|
29116
29127
|
function findOrphanLinks(entries) {
|
|
@@ -29144,16 +29155,16 @@ function formatTopEntries(data, limit) {
|
|
|
29144
29155
|
const top = [...entries].filter((e) => !(e.ttl && isExpiredLocal(e.ttl))).sort((a, b) => importance(b) - importance(a)).slice(0, limit);
|
|
29145
29156
|
if (top.length === 0) return "";
|
|
29146
29157
|
const rendered = renderCompact(top);
|
|
29147
|
-
return `## Top
|
|
29158
|
+
return `## Top memories
|
|
29148
29159
|
${rendered}`;
|
|
29149
29160
|
}
|
|
29150
29161
|
function generateContextGenerate(data, root, opts = {}) {
|
|
29151
29162
|
const sections = [];
|
|
29152
29163
|
const manifest = readManifest(root);
|
|
29153
29164
|
if (manifest) {
|
|
29154
|
-
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";
|
|
29155
29166
|
const version2 = manifest.version ? ` v${manifest.version}` : "";
|
|
29156
|
-
sections.push(`##
|
|
29167
|
+
sections.push(`## Project
|
|
29157
29168
|
${manifest.name}${version2} (${manifest.language})
|
|
29158
29169
|
Deps: ${deps}`);
|
|
29159
29170
|
}
|
|
@@ -29162,9 +29173,9 @@ Deps: ${deps}`);
|
|
|
29162
29173
|
const dirs = structure.dirs.length > 0 ? `Dirs: ${structure.dirs.join(", ")}` : "";
|
|
29163
29174
|
const files = structure.rootFiles.length > 0 ? `Root: ${structure.rootFiles.slice(0, 10).join(", ")}` : "";
|
|
29164
29175
|
const exts = Object.entries(structure.extensions).sort((a, b) => b[1] - a[1]).slice(0, 5).map(([k, v]) => `${k}:${v}`).join(" ");
|
|
29165
|
-
const src = `${structure.sourceFileCount}
|
|
29176
|
+
const src = `${structure.sourceFileCount} source files`;
|
|
29166
29177
|
const parts = [dirs, files, `${src} ${exts ? `(${exts})` : ""}`].filter(Boolean);
|
|
29167
|
-
if (parts.length > 0) sections.push(`##
|
|
29178
|
+
if (parts.length > 0) sections.push(`## Structure
|
|
29168
29179
|
${parts.join("\n")}`);
|
|
29169
29180
|
}
|
|
29170
29181
|
const envVars = readEnvExample(root);
|
|
@@ -29177,8 +29188,8 @@ ${envLines.join("\n")}`);
|
|
|
29177
29188
|
if (git.branch !== "unknown") {
|
|
29178
29189
|
const recent = git.recentCommits.slice(0, 3);
|
|
29179
29190
|
const commitLines = recent.map((c) => `- ${c.shortHash} ${c.subject}`);
|
|
29180
|
-
const parts = [`
|
|
29181
|
-
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:
|
|
29182
29193
|
${commitLines.join("\n")}`);
|
|
29183
29194
|
sections.push(`## Git
|
|
29184
29195
|
${parts.join("\n")}`);
|
|
@@ -29210,7 +29221,7 @@ ${lines.join("\n")}`);
|
|
|
29210
29221
|
}
|
|
29211
29222
|
const tracked = readGitIndex(root);
|
|
29212
29223
|
if (tracked.length > 0) {
|
|
29213
|
-
sections.push(`##
|
|
29224
|
+
sections.push(`## Tracked files (${tracked.length})
|
|
29214
29225
|
${tracked.slice(0, 20).join("\n")}`);
|
|
29215
29226
|
}
|
|
29216
29227
|
const entries = parseEntries(data);
|
|
@@ -29221,18 +29232,31 @@ ${tracked.slice(0, 20).join("\n")}`);
|
|
|
29221
29232
|
const created = recentEntries.filter((e) => e.date === today);
|
|
29222
29233
|
const updated = recentEntries.filter((e) => e.date !== today);
|
|
29223
29234
|
const parts = [];
|
|
29224
|
-
if (created.length > 0) parts.push(`
|
|
29225
|
-
if (updated.length > 0) parts.push(`
|
|
29226
|
-
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)
|
|
29227
29238
|
${parts.join("\n")}`);
|
|
29228
29239
|
}
|
|
29229
|
-
const
|
|
29230
|
-
if (
|
|
29231
|
-
const lines =
|
|
29232
|
-
|
|
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})
|
|
29233
29257
|
${lines.join("\n")}`);
|
|
29234
29258
|
}
|
|
29235
|
-
if (sections.length === 0) return "
|
|
29259
|
+
if (sections.length === 0) return "No recent changes.";
|
|
29236
29260
|
return sections.filter(Boolean).join("\n\n");
|
|
29237
29261
|
}
|
|
29238
29262
|
function generateContextFocus(data, root, task, opts = {}) {
|
|
@@ -29241,34 +29265,38 @@ function generateContextFocus(data, root, task, opts = {}) {
|
|
|
29241
29265
|
const relevant = formatRelevantEntries(data, task, limit);
|
|
29242
29266
|
if (relevant) sections.push(relevant);
|
|
29243
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) || [];
|
|
29244
29270
|
const allFiles = [];
|
|
29245
|
-
|
|
29271
|
+
const searchTerms = [...keywords, ...filePatterns, ...pathPatterns];
|
|
29272
|
+
for (const kw of searchTerms) {
|
|
29246
29273
|
allFiles.push(...findFilesByPattern(root, kw));
|
|
29247
29274
|
}
|
|
29248
29275
|
const uniqueFiles = [...new Set(allFiles)].slice(0, 10);
|
|
29249
29276
|
if (uniqueFiles.length > 0) {
|
|
29250
|
-
sections.push(`##
|
|
29277
|
+
sections.push(`## Related files
|
|
29251
29278
|
${uniqueFiles.join("\n")}`);
|
|
29252
29279
|
}
|
|
29253
29280
|
for (const kw of keywords.slice(0, 3)) {
|
|
29254
29281
|
const callers = findCallers(root, kw);
|
|
29255
29282
|
if (callers.length > 0) {
|
|
29256
29283
|
const lines = callers.slice(0, 5).map((c) => `${c.file}:${c.line} \u2014 ${c.content.slice(0, 80)}`);
|
|
29257
|
-
sections.push(`##
|
|
29284
|
+
sections.push(`## References: ${kw}
|
|
29258
29285
|
${lines.join("\n")}`);
|
|
29259
29286
|
}
|
|
29260
29287
|
}
|
|
29261
29288
|
const testFiles = [];
|
|
29262
|
-
|
|
29289
|
+
const testSearchTerms = [...keywords.slice(0, 2), ...filePatterns];
|
|
29290
|
+
for (const kw of testSearchTerms) {
|
|
29263
29291
|
const tests = findFilesByPattern(root, ".test.").filter((f) => f.toLowerCase().includes(kw));
|
|
29264
29292
|
testFiles.push(...tests);
|
|
29265
29293
|
}
|
|
29266
29294
|
const uniqueTests = [...new Set(testFiles)].slice(0, 5);
|
|
29267
29295
|
if (uniqueTests.length > 0) {
|
|
29268
|
-
sections.push(`##
|
|
29296
|
+
sections.push(`## Existing tests
|
|
29269
29297
|
${uniqueTests.join("\n")}`);
|
|
29270
29298
|
}
|
|
29271
|
-
if (sections.length === 0) return `
|
|
29299
|
+
if (sections.length === 0) return `No context found for "${task}".`;
|
|
29272
29300
|
return sections.filter(Boolean).join("\n\n");
|
|
29273
29301
|
}
|
|
29274
29302
|
function generateContextHealth(data, root) {
|
|
@@ -29285,7 +29313,7 @@ function generateContextHealth(data, root) {
|
|
|
29285
29313
|
}
|
|
29286
29314
|
}
|
|
29287
29315
|
if (orphanLinks.length > 0) {
|
|
29288
|
-
warnings.push(`${orphanLinks.length} links
|
|
29316
|
+
warnings.push(`${orphanLinks.length} orphan links: ${orphanLinks.slice(0, 5).join(", ")}`);
|
|
29289
29317
|
score -= 5;
|
|
29290
29318
|
}
|
|
29291
29319
|
const contentMap = /* @__PURE__ */ new Map();
|
|
@@ -29299,18 +29327,18 @@ function generateContextHealth(data, root) {
|
|
|
29299
29327
|
if (keys2.length > 1) duplicates.push(keys2.join(" = "));
|
|
29300
29328
|
}
|
|
29301
29329
|
if (duplicates.length > 0) {
|
|
29302
|
-
warnings.push(`${duplicates.length}
|
|
29330
|
+
warnings.push(`${duplicates.length} duplicate entries: ${duplicates.slice(0, 3).join("; ")}`);
|
|
29303
29331
|
score -= 5;
|
|
29304
29332
|
}
|
|
29305
29333
|
const weekAgo = new Date(Date.now() - 7 * 864e5).toISOString().split("T")[0];
|
|
29306
29334
|
const staleNeverAccessed = entries.filter((e) => e.accessed === 0 && e.date < weekAgo);
|
|
29307
29335
|
if (staleNeverAccessed.length > 0) {
|
|
29308
|
-
info.push(`${staleNeverAccessed.length}
|
|
29336
|
+
info.push(`${staleNeverAccessed.length} old entries never recalled (possibly stale)`);
|
|
29309
29337
|
score -= 2;
|
|
29310
29338
|
}
|
|
29311
29339
|
const expired = entries.filter((e) => e.ttl && isExpiredLocal(e.ttl));
|
|
29312
29340
|
if (expired.length > 0) {
|
|
29313
|
-
info.push(`${expired.length}
|
|
29341
|
+
info.push(`${expired.length} entries with expired TTL (auto-prune on next startup)`);
|
|
29314
29342
|
score -= 3;
|
|
29315
29343
|
}
|
|
29316
29344
|
const brokenFiles = [];
|
|
@@ -29323,25 +29351,25 @@ function generateContextHealth(data, root) {
|
|
|
29323
29351
|
}
|
|
29324
29352
|
}
|
|
29325
29353
|
if (brokenFiles.length > 0) {
|
|
29326
|
-
warnings.push(`${brokenFiles.length} refs
|
|
29354
|
+
warnings.push(`${brokenFiles.length} refs to non-existent files: ${brokenFiles.slice(0, 3).join("; ")}`);
|
|
29327
29355
|
score -= 5;
|
|
29328
29356
|
}
|
|
29329
29357
|
const sessions = listSessions();
|
|
29330
29358
|
const stale = sessions.filter((s) => !s.active && !s.ended);
|
|
29331
29359
|
if (stale.length > 0) {
|
|
29332
|
-
info.push(`${stale.length}
|
|
29360
|
+
info.push(`${stale.length} stale sessions (will be pruned automatically)`);
|
|
29333
29361
|
}
|
|
29334
29362
|
if (entries.length > 80) {
|
|
29335
|
-
warnings.push(`${entries.length}
|
|
29363
|
+
warnings.push(`${entries.length} entries (near limit of 100)`);
|
|
29336
29364
|
score -= 3;
|
|
29337
29365
|
} else if (entries.length === 0) {
|
|
29338
|
-
info.push("
|
|
29366
|
+
info.push("Empty memory");
|
|
29339
29367
|
}
|
|
29340
29368
|
score = Math.max(0, score);
|
|
29341
29369
|
const report = { score, warnings, info, critical };
|
|
29342
29370
|
const parts = [`## Memory Health: ${score >= 90 ? "\u2705" : score >= 70 ? "\u26A0\uFE0F" : "\u274C"} ${score}/100`];
|
|
29343
29371
|
if (critical.length > 0) {
|
|
29344
|
-
parts.push("", "###
|
|
29372
|
+
parts.push("", "### Critical", ...critical.map((w) => `- ${w}`));
|
|
29345
29373
|
}
|
|
29346
29374
|
if (warnings.length > 0) {
|
|
29347
29375
|
parts.push("", "### Warnings", ...warnings.map((w) => `- ${w}`));
|
|
@@ -29356,10 +29384,10 @@ function generateContextExport(data, format = "full") {
|
|
|
29356
29384
|
const sections = [];
|
|
29357
29385
|
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
29358
29386
|
sections.push(`# toon-memory export
|
|
29359
|
-
|
|
29387
|
+
Date: ${today} | Entries: ${entries.length}
|
|
29360
29388
|
`);
|
|
29361
29389
|
if (entries.length === 0) {
|
|
29362
|
-
sections.push("
|
|
29390
|
+
sections.push("Empty memory.");
|
|
29363
29391
|
return sections.join("\n");
|
|
29364
29392
|
}
|
|
29365
29393
|
const byCategory = {};
|
|
@@ -29368,10 +29396,10 @@ Fecha: ${today} | Entradas: ${entries.length}
|
|
|
29368
29396
|
byCategory[e.category].push(e);
|
|
29369
29397
|
}
|
|
29370
29398
|
const categoryLabels = {
|
|
29371
|
-
decision: "
|
|
29372
|
-
pattern: "
|
|
29399
|
+
decision: "Decisions",
|
|
29400
|
+
pattern: "Patterns",
|
|
29373
29401
|
bug: "Bugs",
|
|
29374
|
-
knowledge: "
|
|
29402
|
+
knowledge: "Knowledge"
|
|
29375
29403
|
};
|
|
29376
29404
|
for (const [cat, items] of Object.entries(byCategory)) {
|
|
29377
29405
|
const label = categoryLabels[cat] || cat;
|
|
@@ -29400,7 +29428,7 @@ _${e.date}${tags}${file2}${links}_`);
|
|
|
29400
29428
|
}
|
|
29401
29429
|
}
|
|
29402
29430
|
if (edges.length > 0) {
|
|
29403
|
-
sections.push(`##
|
|
29431
|
+
sections.push(`## Graph (${edges.length} edges)`);
|
|
29404
29432
|
sections.push(edges.slice(0, 20).join("\n"));
|
|
29405
29433
|
}
|
|
29406
29434
|
}
|
|
@@ -29408,7 +29436,7 @@ _${e.date}${tags}${file2}${links}_`);
|
|
|
29408
29436
|
const sessions = listSessions();
|
|
29409
29437
|
if (sessions.length > 0) {
|
|
29410
29438
|
const active = sessions.filter((s) => s.active);
|
|
29411
|
-
sections.push(`##
|
|
29439
|
+
sections.push(`## Sessions (${active.length} active / ${sessions.length} total)`);
|
|
29412
29440
|
for (const s of sessions.slice(0, 5)) {
|
|
29413
29441
|
const status = s.active ? "\u{1F7E2}" : "\u26AA";
|
|
29414
29442
|
sections.push(`- ${status} ${s.agent}@${s.branch} (${s.id})`);
|
|
@@ -29423,15 +29451,15 @@ function registerTools(server2) {
|
|
|
29423
29451
|
"memory_remember",
|
|
29424
29452
|
{
|
|
29425
29453
|
title: "Save to Memory",
|
|
29426
|
-
description: "
|
|
29454
|
+
description: "Save a fact to the project's persistent memory (decisions, patterns, bugs, knowledge). Persists between sessions.",
|
|
29427
29455
|
inputSchema: {
|
|
29428
|
-
category: external_exports.enum(["decision", "pattern", "bug", "knowledge"]).describe("
|
|
29429
|
-
key: external_exports.string().describe("
|
|
29430
|
-
content: external_exports.string().describe("
|
|
29431
|
-
file: external_exports.string().optional().default("").describe("
|
|
29432
|
-
tags: external_exports.string().optional().default("").describe("
|
|
29433
|
-
ttl: external_exports.string().optional().default("").describe("Time to live (
|
|
29434
|
-
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.")
|
|
29435
29463
|
}
|
|
29436
29464
|
},
|
|
29437
29465
|
async ({ category, key, content, file: file2, tags, ttl, links }) => {
|
|
@@ -29463,14 +29491,14 @@ function registerTools(server2) {
|
|
|
29463
29491
|
const existingParts = existingIdx !== -1 ? lines[existingIdx].trim().split("|") : [];
|
|
29464
29492
|
const resolvedLinks = links ? links.split(/[\s;]+/).filter(Boolean).join(" ") : existingParts[9] || "";
|
|
29465
29493
|
let newEntry = `${entryId}|${category}|${key}|${content}|${file2 || ""}|${resolvedTags}|${date5}|${resolvedTtl}|0|${resolvedLinks}`;
|
|
29466
|
-
let action = "
|
|
29494
|
+
let action = "Saved";
|
|
29467
29495
|
let mergeInfo = "";
|
|
29468
29496
|
const tagsInferred = !tags && resolvedTags ? true : false;
|
|
29469
29497
|
if (existingIdx !== -1) {
|
|
29470
29498
|
newEntry = mergeEntries(lines[existingIdx].trim(), newEntry);
|
|
29471
29499
|
lines[existingIdx] = ` ${newEntry}`;
|
|
29472
|
-
action = "
|
|
29473
|
-
mergeInfo = "\
|
|
29500
|
+
action = "Updated";
|
|
29501
|
+
mergeInfo = "\nMerge: tags combined, date and links updated";
|
|
29474
29502
|
} else {
|
|
29475
29503
|
const quality = qualityScore(resolvedTags, resolvedLinks, content, date5);
|
|
29476
29504
|
const confidence = 1;
|
|
@@ -29484,7 +29512,7 @@ function registerTools(server2) {
|
|
|
29484
29512
|
const headerMatch = lines[headerIdx].match(/\[(\d+)\|/);
|
|
29485
29513
|
const entryCount = headerMatch ? parseInt(headerMatch[1]) : 0;
|
|
29486
29514
|
let archiveMsg = "";
|
|
29487
|
-
if (entryCount >
|
|
29515
|
+
if (entryCount > getMaxEntries()) {
|
|
29488
29516
|
const result = archiveOldEntries({ trimToMax: true });
|
|
29489
29517
|
if (result.archived > 0) {
|
|
29490
29518
|
archiveMsg = `
|
|
@@ -29494,14 +29522,14 @@ function registerTools(server2) {
|
|
|
29494
29522
|
const ttlMsg = resolvedTtl ? `
|
|
29495
29523
|
\u23F0 TTL: ${resolvedTtl}` : "";
|
|
29496
29524
|
const inferredMsg = tagsInferred ? `
|
|
29497
|
-
\u{1F3F7}\uFE0F
|
|
29525
|
+
\u{1F3F7}\uFE0F Inferred tags: ${resolvedTags}` : "";
|
|
29498
29526
|
const related = findRelatedEntries(`${key} ${content} ${resolvedTags}`, key, 3);
|
|
29499
29527
|
let relatedMsg = "";
|
|
29500
29528
|
if (related.length > 0) {
|
|
29501
29529
|
const items = related.map((r) => ` [${r.cat}] ${r.key} \u2014 ${r.content.slice(0, 80)}`).join("\n");
|
|
29502
29530
|
relatedMsg = `
|
|
29503
29531
|
|
|
29504
|
-
\u{1F517}
|
|
29532
|
+
\u{1F517} Related entries:
|
|
29505
29533
|
${items}`;
|
|
29506
29534
|
}
|
|
29507
29535
|
return {
|
|
@@ -29514,90 +29542,39 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29514
29542
|
"memory_recall",
|
|
29515
29543
|
{
|
|
29516
29544
|
title: "Search Memory",
|
|
29517
|
-
description: "
|
|
29545
|
+
description: "Search the project's persistent memory. Returns relevant entries. Use BEFORE reading files.",
|
|
29518
29546
|
inputSchema: {
|
|
29519
|
-
query: external_exports.string().describe("
|
|
29520
|
-
category: external_exports.string().optional().default("").describe("
|
|
29521
|
-
from_date: external_exports.string().optional().default("").describe("
|
|
29522
|
-
to_date: external_exports.string().optional().default("").describe("
|
|
29523
|
-
mode: external_exports.enum(["flat", "graph"]).optional().default("flat").describe("'flat' =
|
|
29524
|
-
hops: external_exports.number().optional().default(1).describe("
|
|
29525
|
-
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.")
|
|
29526
29554
|
}
|
|
29527
29555
|
},
|
|
29528
29556
|
async ({ query, category, from_date, to_date, mode, hops, compact }) => {
|
|
29529
29557
|
const data = readMemory();
|
|
29530
|
-
const
|
|
29531
|
-
|
|
29532
|
-
|
|
29533
|
-
const trimmed = line.trim();
|
|
29534
|
-
const parts = trimmed.split("|");
|
|
29535
|
-
if (parts.length < 7) return null;
|
|
29536
|
-
const [id, cat, key, content, file2, tags, date5, ttl, accessedRaw] = parts;
|
|
29537
|
-
const qualityRaw = parts[10] || "";
|
|
29538
|
-
const confidenceRaw = parts[11] || "";
|
|
29539
|
-
if (category && cat !== category) return null;
|
|
29540
|
-
if (from_date && date5 < from_date) return null;
|
|
29541
|
-
if (to_date && date5 > to_date) return null;
|
|
29542
|
-
if (ttl && isExpired(ttl)) return null;
|
|
29543
|
-
const searchStr = normalize(`${id} ${cat} ${key} ${content} ${file2} ${tags} ${qualityRaw} ${confidenceRaw}`);
|
|
29544
|
-
if (!queryTokens.every((token) => searchStr.includes(token))) return null;
|
|
29545
|
-
const accessed = accessedRaw ? parseInt(accessedRaw) || 0 : 0;
|
|
29546
|
-
return { id, cat, key, content, file: file2, tags, date: date5, accessed, qualityRaw, confidenceRaw };
|
|
29547
|
-
}).filter(Boolean);
|
|
29548
|
-
if (results.length === 0) {
|
|
29549
|
-
return { content: [{ type: "text", text: `No se encontraron resultados para "${query}"` }] };
|
|
29550
|
-
}
|
|
29551
|
-
if (mode === "graph") {
|
|
29552
|
-
const detail = graphRecallDetailed(data, query, { category, from_date, to_date, hops });
|
|
29553
|
-
if (detail.entries.length === 0) {
|
|
29554
|
-
return { content: [{ type: "text", text: `No se encontraron resultados para "${query}"` }] };
|
|
29555
|
-
}
|
|
29556
|
-
bumpAccessed(detail.entries.map((e) => e.id));
|
|
29557
|
-
if (compact) {
|
|
29558
|
-
const formatted3 = renderCompact(detail.entries, {
|
|
29559
|
-
adjacency: detail.adjacency,
|
|
29560
|
-
seeds: detail.seeds,
|
|
29561
|
-
snippetLen: 90
|
|
29562
|
-
});
|
|
29563
|
-
return { content: [{ type: "text", text: formatted3 }] };
|
|
29564
|
-
}
|
|
29565
|
-
const formatted2 = detail.entries.map((r) => {
|
|
29566
|
-
const links = r.links.length ? `
|
|
29567
|
-
links: ${r.links.join(", ")}` : "";
|
|
29568
|
-
return `[${r.category}] ${r.key} (${r.id})
|
|
29569
|
-
${r.content}
|
|
29570
|
-
File: ${r.file} | Tags: ${r.tags.join(";")} | Date: ${r.date}${links}`;
|
|
29571
|
-
}).join("\n\n");
|
|
29572
|
-
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}"` }] };
|
|
29573
29561
|
}
|
|
29574
|
-
|
|
29575
|
-
const ranked = results.map((r) => {
|
|
29576
|
-
const quality = r.qualityRaw ? parseFloat(r.qualityRaw) || 0 : 0;
|
|
29577
|
-
const qualityBoost = quality * 0.15;
|
|
29578
|
-
const bm25Score = bm25.get(r.key) || 0;
|
|
29579
|
-
return { ...r, score: bm25Score + entryScore(r.date, r.accessed) + qualityBoost };
|
|
29580
|
-
}).sort((a, b) => b.score - a.score);
|
|
29581
|
-
bumpAccessed(ranked.map((r) => r.id));
|
|
29562
|
+
bumpAccessed(detail.entries.map((e) => e.id));
|
|
29582
29563
|
if (compact) {
|
|
29583
|
-
const
|
|
29584
|
-
|
|
29585
|
-
|
|
29586
|
-
|
|
29587
|
-
|
|
29588
|
-
file: r.file,
|
|
29589
|
-
tags: r.tags ? r.tags.split(";").filter(Boolean) : [],
|
|
29590
|
-
date: r.date,
|
|
29591
|
-
ttl: "",
|
|
29592
|
-
accessed: r.accessed,
|
|
29593
|
-
links: []
|
|
29594
|
-
}));
|
|
29595
|
-
const formatted2 = renderCompact(entries);
|
|
29564
|
+
const formatted2 = renderCompact(detail.entries, {
|
|
29565
|
+
adjacency: detail.adjacency,
|
|
29566
|
+
seeds: detail.seeds,
|
|
29567
|
+
snippetLen: 90
|
|
29568
|
+
});
|
|
29596
29569
|
return { content: [{ type: "text", text: formatted2 }] };
|
|
29597
29570
|
}
|
|
29598
|
-
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})
|
|
29599
29575
|
${r.content}
|
|
29600
|
-
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");
|
|
29601
29578
|
return { content: [{ type: "text", text: formatted }] };
|
|
29602
29579
|
}
|
|
29603
29580
|
);
|
|
@@ -29605,9 +29582,9 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29605
29582
|
"memory_forget",
|
|
29606
29583
|
{
|
|
29607
29584
|
title: "Delete from Memory",
|
|
29608
|
-
description: "
|
|
29585
|
+
description: "Delete a memory entry by its key or id.",
|
|
29609
29586
|
inputSchema: {
|
|
29610
|
-
key: external_exports.string().describe("Key
|
|
29587
|
+
key: external_exports.string().describe("Key or id of the entry to delete")
|
|
29611
29588
|
}
|
|
29612
29589
|
},
|
|
29613
29590
|
async ({ key }) => {
|
|
@@ -29615,7 +29592,7 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29615
29592
|
const lines = data.split("\n");
|
|
29616
29593
|
const headerIdx = lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l));
|
|
29617
29594
|
if (headerIdx === -1) {
|
|
29618
|
-
return { content: [{ type: "text", text: "No
|
|
29595
|
+
return { content: [{ type: "text", text: "No entries in memory" }] };
|
|
29619
29596
|
}
|
|
29620
29597
|
const entryLines2 = lines.slice(headerIdx + 1).filter((l) => l.trim().length > 0 && !l.startsWith(" summaries:"));
|
|
29621
29598
|
const filtered = entryLines2.filter((l) => {
|
|
@@ -29630,11 +29607,11 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29630
29607
|
writeMemory(lines.join("\n"));
|
|
29631
29608
|
if (removed === 0) {
|
|
29632
29609
|
return {
|
|
29633
|
-
content: [{ type: "text", text: `
|
|
29610
|
+
content: [{ type: "text", text: `"${key}" not found in memory.` }]
|
|
29634
29611
|
};
|
|
29635
29612
|
}
|
|
29636
29613
|
return {
|
|
29637
|
-
content: [{ type: "text", text: `"${key}"
|
|
29614
|
+
content: [{ type: "text", text: `"${key}" deleted. ${count - removed} entries remaining.` }]
|
|
29638
29615
|
};
|
|
29639
29616
|
}
|
|
29640
29617
|
);
|
|
@@ -29642,7 +29619,7 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29642
29619
|
"memory_stats",
|
|
29643
29620
|
{
|
|
29644
29621
|
title: "Memory Stats",
|
|
29645
|
-
description: "
|
|
29622
|
+
description: "Show project memory statistics.",
|
|
29646
29623
|
inputSchema: {}
|
|
29647
29624
|
},
|
|
29648
29625
|
async () => {
|
|
@@ -29662,16 +29639,16 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29662
29639
|
const avgQuality = withQuality > 0 ? (entries.reduce((sum, e) => sum + (e.quality ? parseFloat(e.quality) : 0), 0) / withQuality).toFixed(2) : "N/A";
|
|
29663
29640
|
const summaryLines = data.split("\n").filter((l) => l.includes(":") && !l.startsWith(" ") && !l.startsWith("version") && !l.startsWith("entries") && !/^\[\d+\|]/.test(l));
|
|
29664
29641
|
const stats = [
|
|
29665
|
-
`
|
|
29666
|
-
`
|
|
29642
|
+
`Total entries: ${entries.length}`,
|
|
29643
|
+
`File summaries: ${summaryLines.length}`,
|
|
29667
29644
|
"",
|
|
29668
|
-
"
|
|
29645
|
+
"By category:",
|
|
29669
29646
|
...Object.entries(byCategory).map(([k, v]) => ` ${k}: ${v}`),
|
|
29670
29647
|
"",
|
|
29671
|
-
`TTL: ${withTtl}
|
|
29672
|
-
`
|
|
29648
|
+
`TTL: ${withTtl} with expiration, ${expired} expired`,
|
|
29649
|
+
`Average quality: ${avgQuality} (${withQuality} with score)`,
|
|
29673
29650
|
"",
|
|
29674
|
-
|
|
29651
|
+
`Last 5 entries:`,
|
|
29675
29652
|
...lines.slice(-5).map((l) => {
|
|
29676
29653
|
const parts = l.trim().split("|");
|
|
29677
29654
|
const ttlInfo = parts[7] ? ` | TTL: ${parts[7]}` : "";
|
|
@@ -29686,10 +29663,10 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29686
29663
|
"memory_diff",
|
|
29687
29664
|
{
|
|
29688
29665
|
title: "Memory Diff",
|
|
29689
|
-
description: "
|
|
29666
|
+
description: "Show what changed in memory since a date. Useful for seeing what was learned since the last session.",
|
|
29690
29667
|
inputSchema: {
|
|
29691
|
-
since: external_exports.string().describe("
|
|
29692
|
-
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")
|
|
29693
29670
|
}
|
|
29694
29671
|
},
|
|
29695
29672
|
async ({ since, type }) => {
|
|
@@ -29708,13 +29685,13 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29708
29685
|
return { id, cat, key, content, file: file2, tags, date: date5, changeType };
|
|
29709
29686
|
}).filter(Boolean);
|
|
29710
29687
|
if (results.length === 0) {
|
|
29711
|
-
return { content: [{ type: "text", text: `No
|
|
29688
|
+
return { content: [{ type: "text", text: `No changes since ${sinceDate}` }] };
|
|
29712
29689
|
}
|
|
29713
29690
|
const created = results.filter((r) => r.changeType === "created");
|
|
29714
29691
|
const updated = results.filter((r) => r.changeType === "updated");
|
|
29715
|
-
const sections = [`\u{1F4CB}
|
|
29692
|
+
const sections = [`\u{1F4CB} Changes since ${sinceDate}:`, ""];
|
|
29716
29693
|
if (created.length > 0 && (type === "all" || type === "created")) {
|
|
29717
|
-
sections.push(`\u2795
|
|
29694
|
+
sections.push(`\u2795 New (${created.length}):`);
|
|
29718
29695
|
for (const r of created) {
|
|
29719
29696
|
sections.push(` [${r.cat}] ${r.key} (${r.id})
|
|
29720
29697
|
${r.content}`);
|
|
@@ -29722,7 +29699,7 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29722
29699
|
sections.push("");
|
|
29723
29700
|
}
|
|
29724
29701
|
if (updated.length > 0 && (type === "all" || type === "updated")) {
|
|
29725
|
-
sections.push(`\u270F\uFE0F
|
|
29702
|
+
sections.push(`\u270F\uFE0F Updated (${updated.length}):`);
|
|
29726
29703
|
for (const r of updated) {
|
|
29727
29704
|
sections.push(` [${r.cat}] ${r.key} (${r.id}) \u2014 ${r.date}`);
|
|
29728
29705
|
}
|
|
@@ -29735,21 +29712,21 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29735
29712
|
"memory_suggest",
|
|
29736
29713
|
{
|
|
29737
29714
|
title: "Suggest Related Memories",
|
|
29738
|
-
description: "
|
|
29715
|
+
description: "Suggest memory entries related to a given context. Useful for gathering context before a task.",
|
|
29739
29716
|
inputSchema: {
|
|
29740
|
-
context: external_exports.string().describe("
|
|
29741
|
-
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")
|
|
29742
29719
|
}
|
|
29743
29720
|
},
|
|
29744
29721
|
async ({ context, limit }) => {
|
|
29745
29722
|
const related = findRelatedEntries(context, "", limit);
|
|
29746
29723
|
if (related.length === 0) {
|
|
29747
|
-
return { content: [{ type: "text", text: `No
|
|
29724
|
+
return { content: [{ type: "text", text: `No related entries found for "${context}"` }] };
|
|
29748
29725
|
}
|
|
29749
29726
|
const formatted = related.map((r) => `[${r.cat}] ${r.key} (${r.id})
|
|
29750
29727
|
${r.content}
|
|
29751
29728
|
File: ${r.file} | Tags: ${r.tags} | Date: ${r.date}`).join("\n\n");
|
|
29752
|
-
return { content: [{ type: "text", text: `\u{1F50D}
|
|
29729
|
+
return { content: [{ type: "text", text: `\u{1F50D} Suggestions for "${context}":
|
|
29753
29730
|
|
|
29754
29731
|
${formatted}` }] };
|
|
29755
29732
|
}
|
|
@@ -29758,11 +29735,11 @@ ${formatted}` }] };
|
|
|
29758
29735
|
"memory_smart_recall",
|
|
29759
29736
|
{
|
|
29760
29737
|
title: "Smart Recall (Unified)",
|
|
29761
|
-
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.",
|
|
29762
29739
|
inputSchema: {
|
|
29763
|
-
intent: external_exports.string().describe("Describe
|
|
29764
|
-
limit: external_exports.number().optional().default(8).describe("
|
|
29765
|
-
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)")
|
|
29766
29743
|
}
|
|
29767
29744
|
},
|
|
29768
29745
|
async ({ intent, limit, category }) => {
|
|
@@ -29775,11 +29752,11 @@ ${formatted}` }] };
|
|
|
29775
29752
|
"memory_summary",
|
|
29776
29753
|
{
|
|
29777
29754
|
title: "File Summary",
|
|
29778
|
-
description: "
|
|
29755
|
+
description: "Save or retrieve a summary of a large file to save tokens.",
|
|
29779
29756
|
inputSchema: {
|
|
29780
|
-
action: external_exports.enum(["get", "set"]).describe("get
|
|
29781
|
-
file: external_exports.string().describe("
|
|
29782
|
-
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)")
|
|
29783
29760
|
}
|
|
29784
29761
|
},
|
|
29785
29762
|
async ({ action, file: file2, summary }) => {
|
|
@@ -29788,12 +29765,12 @@ ${formatted}` }] };
|
|
|
29788
29765
|
const lines2 = data.split("\n");
|
|
29789
29766
|
const summaryIdx2 = lines2.findIndex((l) => l.trim().startsWith("summaries:"));
|
|
29790
29767
|
if (summaryIdx2 === -1) {
|
|
29791
|
-
return { content: [{ type: "text", text: `No
|
|
29768
|
+
return { content: [{ type: "text", text: `No summaries saved for "${file2}"` }] };
|
|
29792
29769
|
}
|
|
29793
29770
|
const summaryLines2 = lines2.slice(summaryIdx2 + 1).filter((l) => l.includes(":"));
|
|
29794
29771
|
const match = summaryLines2.find((l) => l.startsWith(` ${file2}:`));
|
|
29795
29772
|
if (!match) {
|
|
29796
|
-
return { content: [{ type: "text", text: `No
|
|
29773
|
+
return { content: [{ type: "text", text: `No summary for "${file2}"` }] };
|
|
29797
29774
|
}
|
|
29798
29775
|
const summaryText = match.replace(` ${file2}: `, "");
|
|
29799
29776
|
return { content: [{ type: "text", text: summaryText }] };
|
|
@@ -29814,7 +29791,7 @@ ${formatted}` }] };
|
|
|
29814
29791
|
lines.splice(summaryIdx + 1, lines.length - summaryIdx - 1, ...summaryLines);
|
|
29815
29792
|
writeMemory(lines.join("\n"));
|
|
29816
29793
|
return {
|
|
29817
|
-
content: [{ type: "text", text: `\u{1F4DD}
|
|
29794
|
+
content: [{ type: "text", text: `\u{1F4DD} Summary saved for ${file2}` }]
|
|
29818
29795
|
};
|
|
29819
29796
|
}
|
|
29820
29797
|
);
|
|
@@ -29822,19 +29799,19 @@ ${formatted}` }] };
|
|
|
29822
29799
|
"memory_archive",
|
|
29823
29800
|
{
|
|
29824
29801
|
title: "Archive Old Entries",
|
|
29825
|
-
description: "
|
|
29802
|
+
description: "Move old entries (>30 days) to archive.toon to keep memory clean.",
|
|
29826
29803
|
inputSchema: {}
|
|
29827
29804
|
},
|
|
29828
29805
|
async () => {
|
|
29829
29806
|
const result = archiveOldEntries();
|
|
29830
29807
|
if (result.archived === 0) {
|
|
29831
|
-
return { content: [{ type: "text", text: "No
|
|
29808
|
+
return { content: [{ type: "text", text: "No old entries to archive" }] };
|
|
29832
29809
|
}
|
|
29833
29810
|
return {
|
|
29834
29811
|
content: [{
|
|
29835
29812
|
type: "text",
|
|
29836
|
-
text: `\u{1F4E6}
|
|
29837
|
-
\u{1F4CB}
|
|
29813
|
+
text: `\u{1F4E6} Archived ${result.archived} old entries
|
|
29814
|
+
\u{1F4CB} ${result.kept} active entries remaining`
|
|
29838
29815
|
}]
|
|
29839
29816
|
};
|
|
29840
29817
|
}
|
|
@@ -29843,24 +29820,24 @@ ${formatted}` }] };
|
|
|
29843
29820
|
"memory_encrypt",
|
|
29844
29821
|
{
|
|
29845
29822
|
title: "Enable Encryption",
|
|
29846
|
-
description: "
|
|
29823
|
+
description: "Enable AES-256-GCM encryption for memory. Requires TOON_MEMORY_KEY in environment.",
|
|
29847
29824
|
inputSchema: {}
|
|
29848
29825
|
},
|
|
29849
29826
|
async () => {
|
|
29850
29827
|
const config2 = loadConfig();
|
|
29851
29828
|
if (config2.encrypted) {
|
|
29852
|
-
return { content: [{ type: "text", text: "
|
|
29829
|
+
return { content: [{ type: "text", text: "Encryption is already enabled" }] };
|
|
29853
29830
|
}
|
|
29854
29831
|
const key = getKey();
|
|
29855
29832
|
if (!key) {
|
|
29856
|
-
return { content: [{ type: "text", text: "\u274C
|
|
29833
|
+
return { content: [{ type: "text", text: "\u274C Set TOON_MEMORY_KEY in environment before encrypting" }] };
|
|
29857
29834
|
}
|
|
29858
29835
|
const data = readUnderLock(MEMORY_FILE);
|
|
29859
29836
|
const encrypted = encrypt(data, key);
|
|
29860
29837
|
safeWrite(MEMORY_FILE, encrypted);
|
|
29861
29838
|
saveConfig({ encrypted: true });
|
|
29862
29839
|
return {
|
|
29863
|
-
content: [{ type: "text", text: "\u{1F510}
|
|
29840
|
+
content: [{ type: "text", text: "\u{1F510} Encryption enabled" }]
|
|
29864
29841
|
};
|
|
29865
29842
|
}
|
|
29866
29843
|
);
|
|
@@ -29868,19 +29845,19 @@ ${formatted}` }] };
|
|
|
29868
29845
|
"memory_decrypt",
|
|
29869
29846
|
{
|
|
29870
29847
|
title: "Disable Encryption",
|
|
29871
|
-
description: "
|
|
29848
|
+
description: "Disable encryption and decode memory.",
|
|
29872
29849
|
inputSchema: {
|
|
29873
|
-
key: external_exports.string().describe("
|
|
29850
|
+
key: external_exports.string().describe("Encryption key")
|
|
29874
29851
|
}
|
|
29875
29852
|
},
|
|
29876
29853
|
async ({ key }) => {
|
|
29877
29854
|
const config2 = loadConfig();
|
|
29878
29855
|
if (!config2.encrypted) {
|
|
29879
|
-
return { content: [{ type: "text", text: "
|
|
29856
|
+
return { content: [{ type: "text", text: "Encryption is not enabled" }] };
|
|
29880
29857
|
}
|
|
29881
29858
|
const resolvedKey = key || getKey() || "";
|
|
29882
29859
|
if (!resolvedKey) {
|
|
29883
|
-
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" }] };
|
|
29884
29861
|
}
|
|
29885
29862
|
try {
|
|
29886
29863
|
const data = readUnderLock(MEMORY_FILE);
|
|
@@ -29888,10 +29865,10 @@ ${formatted}` }] };
|
|
|
29888
29865
|
safeWrite(MEMORY_FILE, decrypted);
|
|
29889
29866
|
saveConfig({ encrypted: false });
|
|
29890
29867
|
return {
|
|
29891
|
-
content: [{ type: "text", text: "\u{1F513}
|
|
29868
|
+
content: [{ type: "text", text: "\u{1F513} Encryption disabled" }]
|
|
29892
29869
|
};
|
|
29893
29870
|
} catch {
|
|
29894
|
-
return { content: [{ type: "text", text: "\u274C
|
|
29871
|
+
return { content: [{ type: "text", text: "\u274C Wrong key or corrupted data" }] };
|
|
29895
29872
|
}
|
|
29896
29873
|
}
|
|
29897
29874
|
);
|
|
@@ -29899,20 +29876,20 @@ ${formatted}` }] };
|
|
|
29899
29876
|
"memory_captured",
|
|
29900
29877
|
{
|
|
29901
29878
|
title: "List Captured Activity",
|
|
29902
|
-
description: "
|
|
29879
|
+
description: "Show activity log captured automatically by hooks (only if capture is enabled). Useful for promoting observations to memory with memory_remember.",
|
|
29903
29880
|
inputSchema: {
|
|
29904
|
-
limit: external_exports.number().optional().default(20).describe("
|
|
29905
|
-
tool: external_exports.string().optional().default("").describe("
|
|
29906
|
-
file: external_exports.string().optional().default("").describe("
|
|
29907
|
-
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")
|
|
29908
29885
|
}
|
|
29909
29886
|
},
|
|
29910
29887
|
async ({ limit, tool, file: file2, clear }) => {
|
|
29911
29888
|
if (clear) {
|
|
29912
29889
|
if (existsSync10(OBSERVATIONS_FILE)) {
|
|
29913
|
-
|
|
29890
|
+
writeFileSync5(OBSERVATIONS_FILE, "version: 1\nobservations[0|]{ts|session|agent|branch|tool|hash|file|summary}:\n");
|
|
29914
29891
|
}
|
|
29915
|
-
return { content: [{ type: "text", text: "\u{1F9F9}
|
|
29892
|
+
return { content: [{ type: "text", text: "\u{1F9F9} Capture log cleared" }] };
|
|
29916
29893
|
}
|
|
29917
29894
|
let obs = readObservations();
|
|
29918
29895
|
if (tool) obs = obs.filter((o) => o.tool.toLowerCase().includes(tool.toLowerCase()));
|
|
@@ -29922,13 +29899,13 @@ ${formatted}` }] };
|
|
|
29922
29899
|
return {
|
|
29923
29900
|
content: [{
|
|
29924
29901
|
type: "text",
|
|
29925
|
-
text: "No
|
|
29902
|
+
text: "No captured activity. Capture is disabled by default; enable with `toon-memory capture on`."
|
|
29926
29903
|
}]
|
|
29927
29904
|
};
|
|
29928
29905
|
}
|
|
29929
29906
|
const formatted = obs.map((o) => `[${o.ts}] ${o.agent}@${o.branch}/${o.tool}${o.file ? ` (${o.file})` : ""}
|
|
29930
29907
|
${o.summary}`).join("\n\n");
|
|
29931
|
-
return { content: [{ type: "text", text: `\u{1F50D}
|
|
29908
|
+
return { content: [{ type: "text", text: `\u{1F50D} Captured activity (${obs.length}):
|
|
29932
29909
|
|
|
29933
29910
|
${formatted}` }] };
|
|
29934
29911
|
}
|
|
@@ -29937,20 +29914,20 @@ ${formatted}` }] };
|
|
|
29937
29914
|
"memory_consolidate",
|
|
29938
29915
|
{
|
|
29939
29916
|
title: "Consolidate Memory",
|
|
29940
|
-
description: "
|
|
29917
|
+
description: "Consolidate memory by removing entries with identical content (keeps the first). Deterministic, no LLM.",
|
|
29941
29918
|
inputSchema: {}
|
|
29942
29919
|
},
|
|
29943
29920
|
async () => {
|
|
29944
29921
|
const result = consolidateEntries();
|
|
29945
29922
|
if (result.removed === 0) {
|
|
29946
|
-
return { content: [{ type: "text", text: `\u2705
|
|
29923
|
+
return { content: [{ type: "text", text: `\u2705 Memory already consolidated (${result.kept} entries, 0 duplicates)` }] };
|
|
29947
29924
|
}
|
|
29948
29925
|
return {
|
|
29949
29926
|
content: [{
|
|
29950
29927
|
type: "text",
|
|
29951
|
-
text: `\u{1F9F9}
|
|
29952
|
-
|
|
29953
|
-
|
|
29928
|
+
text: `\u{1F9F9} Consolidated ${result.removed} duplicate entries.
|
|
29929
|
+
${result.kept} active entries remaining.
|
|
29930
|
+
Duplicates: ${result.duplicates.join(", ")}`
|
|
29954
29931
|
}]
|
|
29955
29932
|
};
|
|
29956
29933
|
}
|
|
@@ -29959,9 +29936,9 @@ Duplicados: ${result.duplicates.join(", ")}`
|
|
|
29959
29936
|
"memory_sessions",
|
|
29960
29937
|
{
|
|
29961
29938
|
title: "Active Sessions & Conflicts",
|
|
29962
|
-
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.",
|
|
29963
29940
|
inputSchema: {
|
|
29964
|
-
conflictsOnly: external_exports.boolean().optional().default(false).describe("
|
|
29941
|
+
conflictsOnly: external_exports.boolean().optional().default(false).describe("If true, only show soft conflicts")
|
|
29965
29942
|
}
|
|
29966
29943
|
},
|
|
29967
29944
|
async ({ conflictsOnly }) => {
|
|
@@ -29969,7 +29946,7 @@ Duplicados: ${result.duplicates.join(", ")}`
|
|
|
29969
29946
|
const { active, conflicts } = coordinationView(selfId);
|
|
29970
29947
|
if (conflictsOnly) {
|
|
29971
29948
|
if (conflicts.length === 0) {
|
|
29972
|
-
return { content: [{ type: "text", text: "\u2705 No
|
|
29949
|
+
return { content: [{ type: "text", text: "\u2705 No soft conflicts between active sessions." }] };
|
|
29973
29950
|
}
|
|
29974
29951
|
const lines = conflicts.map((c) => {
|
|
29975
29952
|
const who = c.sessions.map((s) => `${s.agent}@${s.branch} (${s.id})`).join(", ");
|
|
@@ -29977,7 +29954,7 @@ Duplicados: ${result.duplicates.join(", ")}`
|
|
|
29977
29954
|
\u2194 ${who}`;
|
|
29978
29955
|
});
|
|
29979
29956
|
return {
|
|
29980
|
-
content: [{ type: "text", text: `\u{1F525}
|
|
29957
|
+
content: [{ type: "text", text: `\u{1F525} Soft conflicts (${conflicts.length}):
|
|
29981
29958
|
|
|
29982
29959
|
${lines.join("\n\n")}` }]
|
|
29983
29960
|
};
|
|
@@ -29986,36 +29963,36 @@ ${lines.join("\n\n")}` }]
|
|
|
29986
29963
|
return {
|
|
29987
29964
|
content: [{
|
|
29988
29965
|
type: "text",
|
|
29989
|
-
text: "\u{1F7E2} No
|
|
29966
|
+
text: "\u{1F7E2} No other active sessions in this project.\n(This session: " + selfId + " @ " + currentBranch() + ")"
|
|
29990
29967
|
}]
|
|
29991
29968
|
};
|
|
29992
29969
|
}
|
|
29993
29970
|
const ttlMin = Math.round(SESSION_TTL_MS / 6e4);
|
|
29994
29971
|
const section = (s) => {
|
|
29995
29972
|
const mins = Math.max(0, Math.round(s.ageMs / 6e4));
|
|
29996
|
-
const tag = s.id === selfId ? " (
|
|
29973
|
+
const tag = s.id === selfId ? " (you)" : "";
|
|
29997
29974
|
const ended = s.ended ? " \u{1F3C1}" : "";
|
|
29998
29975
|
const files = Object.keys(s.files).slice(0, 8).map((f) => ` \u2022 ${f}`).join("\n");
|
|
29999
29976
|
const fileBlock = files ? `
|
|
30000
|
-
|
|
29977
|
+
Files:
|
|
30001
29978
|
${files}` : "";
|
|
30002
29979
|
return `\u2022 ${s.agent} @ ${s.branch}${tag}${ended}
|
|
30003
29980
|
id: ${s.id}
|
|
30004
|
-
|
|
29981
|
+
${mins} min ago${fileBlock}`;
|
|
30005
29982
|
};
|
|
30006
29983
|
const parts = [
|
|
30007
|
-
`\u{1F9ED}
|
|
29984
|
+
`\u{1F9ED} Active sessions (${active.length}) \u2014 window ${ttlMin} min:`,
|
|
30008
29985
|
"",
|
|
30009
29986
|
...active.map(section)
|
|
30010
29987
|
];
|
|
30011
29988
|
if (conflicts.length > 0) {
|
|
30012
|
-
parts.push("", `\u{1F525}
|
|
29989
|
+
parts.push("", `\u{1F525} Soft conflicts (${conflicts.length}):`);
|
|
30013
29990
|
for (const c of conflicts) {
|
|
30014
29991
|
const who = c.sessions.map((s) => `${s.agent}@${s.branch}`).join(", ");
|
|
30015
29992
|
parts.push(` \u26A0\uFE0F ${c.file} \u2194 ${who}`);
|
|
30016
29993
|
}
|
|
30017
29994
|
} else {
|
|
30018
|
-
parts.push("", "\u2705
|
|
29995
|
+
parts.push("", "\u2705 No soft conflicts detected.");
|
|
30019
29996
|
}
|
|
30020
29997
|
return { content: [{ type: "text", text: parts.join("\n") }] };
|
|
30021
29998
|
}
|
|
@@ -30024,10 +30001,10 @@ ${files}` : "";
|
|
|
30024
30001
|
"context_brief",
|
|
30025
30002
|
{
|
|
30026
30003
|
title: "Context Briefing",
|
|
30027
|
-
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.",
|
|
30028
30005
|
inputSchema: {
|
|
30029
|
-
task: external_exports.string().optional().default("").describe("
|
|
30030
|
-
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")
|
|
30031
30008
|
}
|
|
30032
30009
|
},
|
|
30033
30010
|
async ({ task, limit }) => {
|
|
@@ -30040,9 +30017,9 @@ ${files}` : "";
|
|
|
30040
30017
|
"context_generate",
|
|
30041
30018
|
{
|
|
30042
30019
|
title: "Generate Full Context",
|
|
30043
|
-
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.",
|
|
30044
30021
|
inputSchema: {
|
|
30045
|
-
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.")
|
|
30046
30023
|
}
|
|
30047
30024
|
},
|
|
30048
30025
|
async ({ task }) => {
|
|
@@ -30056,9 +30033,9 @@ ${files}` : "";
|
|
|
30056
30033
|
"context_diff",
|
|
30057
30034
|
{
|
|
30058
30035
|
title: "Context Diff",
|
|
30059
|
-
description: "
|
|
30036
|
+
description: "What changed since the last session: git commits + modified files + new/updated memory entries. Zero LLM.",
|
|
30060
30037
|
inputSchema: {
|
|
30061
|
-
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.")
|
|
30062
30039
|
}
|
|
30063
30040
|
},
|
|
30064
30041
|
async ({ since }) => {
|
|
@@ -30072,10 +30049,10 @@ ${files}` : "";
|
|
|
30072
30049
|
"context_focus",
|
|
30073
30050
|
{
|
|
30074
30051
|
title: "Focus Context for Task",
|
|
30075
|
-
description: "
|
|
30052
|
+
description: "Hyper-focused context for a specific task: relevant entries + related files + code referencing the symbol + existing tests. Zero LLM.",
|
|
30076
30053
|
inputSchema: {
|
|
30077
|
-
task: external_exports.string().describe("
|
|
30078
|
-
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")
|
|
30079
30056
|
}
|
|
30080
30057
|
},
|
|
30081
30058
|
async ({ task, limit }) => {
|
|
@@ -30089,7 +30066,7 @@ ${files}` : "";
|
|
|
30089
30066
|
"context_health",
|
|
30090
30067
|
{
|
|
30091
30068
|
title: "Memory Health Audit",
|
|
30092
|
-
description: "
|
|
30069
|
+
description: "Full memory health audit: orphan links, duplicates, broken refs, expired TTL, quality, stale sessions. Includes score 0-100. Zero LLM.",
|
|
30093
30070
|
inputSchema: {}
|
|
30094
30071
|
},
|
|
30095
30072
|
async () => {
|
|
@@ -30103,9 +30080,9 @@ ${files}` : "";
|
|
|
30103
30080
|
"context_export",
|
|
30104
30081
|
{
|
|
30105
30082
|
title: "Export Memory as Markdown",
|
|
30106
|
-
description: "
|
|
30083
|
+
description: "Export all memory as markdown injectable for other agents or sessions. Full (detailed) or compact format. Zero LLM.",
|
|
30107
30084
|
inputSchema: {
|
|
30108
|
-
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")
|
|
30109
30086
|
}
|
|
30110
30087
|
},
|
|
30111
30088
|
async ({ format }) => {
|
|
@@ -30114,6 +30091,46 @@ ${files}` : "";
|
|
|
30114
30091
|
return { content: [{ type: "text", text: exported }] };
|
|
30115
30092
|
}
|
|
30116
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
|
+
);
|
|
30117
30134
|
}
|
|
30118
30135
|
|
|
30119
30136
|
// src/mcp/resources.ts
|
|
@@ -30145,9 +30162,9 @@ function registerResources(server2) {
|
|
|
30145
30162
|
const withTtl = entries.filter((e) => e.ttl).length;
|
|
30146
30163
|
const expired = entries.filter((e) => e.ttl && isExpired(e.ttl)).length;
|
|
30147
30164
|
const text = [
|
|
30148
|
-
`
|
|
30149
|
-
`TTL: ${withTtl}
|
|
30150
|
-
"
|
|
30165
|
+
`Total entries: ${entries.length}`,
|
|
30166
|
+
`TTL: ${withTtl} with expiration, ${expired} expired`,
|
|
30167
|
+
"By category:",
|
|
30151
30168
|
...Object.entries(byCategory).map(([k, v]) => ` ${k}: ${v}`)
|
|
30152
30169
|
].join("\n");
|
|
30153
30170
|
return { contents: [{ uri: uri.href, text }] };
|
|
@@ -30167,7 +30184,7 @@ function registerResources(server2) {
|
|
|
30167
30184
|
|
|
30168
30185
|
// src/mcp/server.ts
|
|
30169
30186
|
var server = new McpServer(
|
|
30170
|
-
{ name: "toon-memory", version: "2.
|
|
30187
|
+
{ name: "toon-memory", version: "2.9.0" },
|
|
30171
30188
|
{ capabilities: { tools: { listChanged: true }, resources: { listChanged: true } } }
|
|
30172
30189
|
);
|
|
30173
30190
|
registerResources(server);
|