toon-memory 2.9.8 → 2.11.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/mcp/server.js +199 -14
- package/package.json +1 -1
- package/src/lib/context.ts +33 -9
- package/src/lib/fuzzy.ts +58 -0
- package/src/lib/git.ts +16 -0
- package/src/lib/graph.ts +7 -1
- package/src/lib/quality.ts +20 -4
- package/src/lib/synonyms.ts +118 -0
- package/src/lib/utils.ts +11 -1
- package/src/mcp/tools.ts +6 -4
package/mcp/server.js
CHANGED
|
@@ -28295,7 +28295,8 @@ function importance(e) {
|
|
|
28295
28295
|
const freq = Math.min(1, e.accessed / 5);
|
|
28296
28296
|
return recency * 0.6 + freq * 0.4;
|
|
28297
28297
|
}
|
|
28298
|
-
var tokenize = (s) =>
|
|
28298
|
+
var tokenize = (s) => s.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]/g, " ").toLowerCase().split(/\s+/).filter(Boolean);
|
|
28299
|
+
var isPrivate = (e) => e.tags.some((t) => t.toLowerCase() === "private");
|
|
28299
28300
|
|
|
28300
28301
|
// src/mcp/entries.ts
|
|
28301
28302
|
function generateId() {
|
|
@@ -28534,6 +28535,142 @@ function pruneExpiredEntries() {
|
|
|
28534
28535
|
return pruned;
|
|
28535
28536
|
}
|
|
28536
28537
|
|
|
28538
|
+
// src/lib/synonyms.ts
|
|
28539
|
+
var SYNONYMS = {
|
|
28540
|
+
// Infrastructure / networking
|
|
28541
|
+
"conexi\xF3n": ["timeout", "red", "conectar", "disconnect", "connection", "conn"],
|
|
28542
|
+
"conectar": ["timeout", "red", "conexi\xF3n", "connect", "connection"],
|
|
28543
|
+
"ca\xEDda": ["down", "crash", "fail", "error", "dropped", "falla"],
|
|
28544
|
+
"down": ["ca\xEDda", "crash", "fail", "caer", "offline"],
|
|
28545
|
+
"crash": ["ca\xEDda", "down", "fail", "error", "colapso"],
|
|
28546
|
+
"timeout": ["conexi\xF3n", "red", "expirar", "deadline", "exceed"],
|
|
28547
|
+
"red": ["network", "conexi\xF3n", "ip", "dns", "proxy", "gateway"],
|
|
28548
|
+
"network": ["red", "conexi\xF3n", "ip", "dns", "proxy"],
|
|
28549
|
+
"server": ["servidor", "backend", "api", "host"],
|
|
28550
|
+
"servidor": ["server", "backend", "api", "host"],
|
|
28551
|
+
"client": ["cliente", "frontend", "browser", "user-agent"],
|
|
28552
|
+
"cliente": ["client", "frontend", "browser"],
|
|
28553
|
+
// Data / storage
|
|
28554
|
+
"cache": ["redis", "memcached", "cached", "cach\xE9"],
|
|
28555
|
+
"redis": ["cache", "memcached", "session", "pubsub"],
|
|
28556
|
+
"pool": ["pool", "connection pool", "pooling", "concurrencia"],
|
|
28557
|
+
"database": ["db", "postgres", "mysql", "mongo", "sql", "base de datos"],
|
|
28558
|
+
"db": ["database", "postgres", "mysql", "mongo", "sql"],
|
|
28559
|
+
"session": ["sesi\xF3n", "cookie", "token", "auth"],
|
|
28560
|
+
// Errors / debugging
|
|
28561
|
+
"error": ["bug", "exception", "fail", "fallo", "error", "err"],
|
|
28562
|
+
"bug": ["error", "defect", "issue", "fallo", "problema"],
|
|
28563
|
+
"exception": ["error", "throw", "catch", "error"],
|
|
28564
|
+
"fail": ["error", "falla", "fallo", "crash", "fail"],
|
|
28565
|
+
"falla": ["error", "fail", "fallo", "bug", "crash"],
|
|
28566
|
+
"debug": ["debugging", "log", "trace", "diagn\xF3stico"],
|
|
28567
|
+
"log": ["logging", "debug", "trace", "registro"],
|
|
28568
|
+
"warning": ["warn", "advertencia", "alerta"],
|
|
28569
|
+
// Architecture
|
|
28570
|
+
"auth": ["authentication", "autenticaci\xF3n", "login", "jwt", "token", "oauth"],
|
|
28571
|
+
"autenticaci\xF3n": ["auth", "authentication", "login", "jwt", "oauth"],
|
|
28572
|
+
"api": ["endpoint", "route", "rest", "graphql", "rpc"],
|
|
28573
|
+
"endpoint": ["api", "route", "url", "path"],
|
|
28574
|
+
"config": ["configuraci\xF3n", "settings", "env", "environment"],
|
|
28575
|
+
"configuraci\xF3n": ["config", "settings", "env", "environment"],
|
|
28576
|
+
"deploy": ["deployment", "despliegue", "release", "ship", "ci/cd"],
|
|
28577
|
+
"despliegue": ["deploy", "deployment", "release", "publish"],
|
|
28578
|
+
"migration": ["migraci\xF3n", "migrate", "upgrade", "schema change"],
|
|
28579
|
+
"migraci\xF3n": ["migration", "migrate", "upgrade"],
|
|
28580
|
+
// Code / patterns
|
|
28581
|
+
"refactor": ["refactoring", "reorganizar", "reestructurar", "clean"],
|
|
28582
|
+
"reestructurar": ["refactor", "refactoring", "reorganizar", "restructure"],
|
|
28583
|
+
"pattern": ["patr\xF3n", "pattern", "convention", "norma", "est\xE1ndar"],
|
|
28584
|
+
"patr\xF3n": ["pattern", "convention", "norma", "est\xE1ndar"],
|
|
28585
|
+
"decision": ["decisi\xF3n", "decision", "elecci\xF3n", "choice", "acuerdo"],
|
|
28586
|
+
"decisi\xF3n": ["decision", "elecci\xF3n", "choice", "acuerdo"],
|
|
28587
|
+
"knowledge": ["conocimiento", "knowledge", "info", "informaci\xF3n"],
|
|
28588
|
+
"conocimiento": ["knowledge", "info", "informaci\xF3n"],
|
|
28589
|
+
// Performance
|
|
28590
|
+
"performance": ["rendimiento", "perf", "latency", "throughput", "speed"],
|
|
28591
|
+
"rendimiento": ["performance", "perf", "latency", "speed"],
|
|
28592
|
+
"latency": ["latencia", "delay", "response time", "rt"],
|
|
28593
|
+
"latencia": ["latency", "delay", "response time"],
|
|
28594
|
+
"memory": ["memoria", "ram", "heap", "leak"],
|
|
28595
|
+
"memoria": ["memory", "ram", "heap", "leak"],
|
|
28596
|
+
"leak": ["fuga", "memory leak", "memoria"],
|
|
28597
|
+
// Testing
|
|
28598
|
+
"test": ["testing", "prueba", "tests", "spec"],
|
|
28599
|
+
"prueba": ["test", "testing", "spec"],
|
|
28600
|
+
"mock": ["mocking", "stub", "fake", "doble"],
|
|
28601
|
+
"coverage": ["cobertura", "coverage", "tests"],
|
|
28602
|
+
// Git / VCS
|
|
28603
|
+
"commit": ["commits", "\u63D0\u4EA4", "checkpoint", "save"],
|
|
28604
|
+
"branch": ["rama", "branch", "feature branch", "checkout"],
|
|
28605
|
+
"rama": ["branch", "feature branch", "checkout"],
|
|
28606
|
+
"merge": ["mergear", "merge", "combine", "unir"],
|
|
28607
|
+
"conflict": ["conflicto", "conflict", "merge conflict", "clash"],
|
|
28608
|
+
"conflicto": ["conflict", "merge conflict", "clash"],
|
|
28609
|
+
"revert": ["rollback", "deshacer", "undo", "restore"],
|
|
28610
|
+
// UI / frontend
|
|
28611
|
+
"ui": ["interfaz", "interface", "gui", "frontend", "vista"],
|
|
28612
|
+
"interfaz": ["ui", "interface", "gui", "frontend"],
|
|
28613
|
+
"component": ["componente", "widget", "module", "pieza"],
|
|
28614
|
+
"componente": ["component", "widget", "module"],
|
|
28615
|
+
"responsive": ["responsive", "mobile", "adaptativo", "layout"],
|
|
28616
|
+
"layout": ["dise\xF1o", "design", "layout", "estructura"],
|
|
28617
|
+
// DevOps
|
|
28618
|
+
"docker": ["container", "contenedor", "image", "imagen"],
|
|
28619
|
+
"contenedor": ["docker", "container", "image"],
|
|
28620
|
+
"kubernetes": ["k8s", "cluster", "pods", "deployment"],
|
|
28621
|
+
"ci/cd": ["pipeline", "deploy", "continuous integration", "continuous deployment"],
|
|
28622
|
+
"monitoring": ["monitoreo", "observability", "metrics", "alerts"],
|
|
28623
|
+
"monitoreo": ["monitoring", "observability", "metrics"]
|
|
28624
|
+
};
|
|
28625
|
+
function expandSynonyms(queryTokens) {
|
|
28626
|
+
const expanded = new Set(queryTokens);
|
|
28627
|
+
for (const token of queryTokens) {
|
|
28628
|
+
const synonyms = SYNONYMS[token];
|
|
28629
|
+
if (synonyms) {
|
|
28630
|
+
for (const s of synonyms) expanded.add(s);
|
|
28631
|
+
}
|
|
28632
|
+
}
|
|
28633
|
+
return [...expanded];
|
|
28634
|
+
}
|
|
28635
|
+
|
|
28636
|
+
// src/lib/fuzzy.ts
|
|
28637
|
+
function levenshtein(a, b) {
|
|
28638
|
+
const al = a.length;
|
|
28639
|
+
const bl = b.length;
|
|
28640
|
+
if (al === 0) return bl;
|
|
28641
|
+
if (bl === 0) return al;
|
|
28642
|
+
let prev = new Array(bl + 1);
|
|
28643
|
+
let curr = new Array(bl + 1);
|
|
28644
|
+
for (let j = 0; j <= bl; j++) prev[j] = j;
|
|
28645
|
+
for (let i = 1; i <= al; i++) {
|
|
28646
|
+
curr[0] = i;
|
|
28647
|
+
for (let j = 1; j <= bl; j++) {
|
|
28648
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
28649
|
+
curr[j] = Math.min(
|
|
28650
|
+
prev[j] + 1,
|
|
28651
|
+
// deletion
|
|
28652
|
+
curr[j - 1] + 1,
|
|
28653
|
+
// insertion
|
|
28654
|
+
prev[j - 1] + cost
|
|
28655
|
+
// substitution
|
|
28656
|
+
);
|
|
28657
|
+
}
|
|
28658
|
+
;
|
|
28659
|
+
[prev, curr] = [curr, prev];
|
|
28660
|
+
}
|
|
28661
|
+
return prev[bl];
|
|
28662
|
+
}
|
|
28663
|
+
function fuzzyMatch(queryTokens, docTokens, maxDistance = 2) {
|
|
28664
|
+
for (const qt of queryTokens) {
|
|
28665
|
+
if (qt.length <= 2) continue;
|
|
28666
|
+
for (const dt of docTokens) {
|
|
28667
|
+
if (Math.abs(qt.length - dt.length) > maxDistance) continue;
|
|
28668
|
+
if (levenshtein(qt, dt) <= maxDistance) return true;
|
|
28669
|
+
}
|
|
28670
|
+
}
|
|
28671
|
+
return false;
|
|
28672
|
+
}
|
|
28673
|
+
|
|
28537
28674
|
// src/lib/graph.ts
|
|
28538
28675
|
var entryLines = (data) => data.split("\n").filter(
|
|
28539
28676
|
(l) => l.startsWith(" ") && l.includes("|") && !l.startsWith(" summaries:")
|
|
@@ -28635,6 +28772,7 @@ function graphRecallDetailed(data, query, opts = {}) {
|
|
|
28635
28772
|
const from_date = opts.from_date || "";
|
|
28636
28773
|
const to_date = opts.to_date || "";
|
|
28637
28774
|
const qTokens = tokenize(query);
|
|
28775
|
+
const expandedTokens = expandSynonyms(qTokens);
|
|
28638
28776
|
const bm25 = bm25Scores(entries, query);
|
|
28639
28777
|
const cent = centrality(adjacency);
|
|
28640
28778
|
const seedKeys = /* @__PURE__ */ new Set();
|
|
@@ -28646,7 +28784,10 @@ function graphRecallDetailed(data, query, opts = {}) {
|
|
|
28646
28784
|
const text = normalize(
|
|
28647
28785
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
28648
28786
|
);
|
|
28649
|
-
|
|
28787
|
+
const docTokens = text.split(" ");
|
|
28788
|
+
const exactMatch = expandedTokens.some((t) => text.includes(t));
|
|
28789
|
+
const fuzzy = !exactMatch && fuzzyMatch(qTokens, docTokens);
|
|
28790
|
+
if (qTokens.length > 0 && !exactMatch && !fuzzy) continue;
|
|
28650
28791
|
seedKeys.add(e.key);
|
|
28651
28792
|
}
|
|
28652
28793
|
let selected;
|
|
@@ -28778,7 +28919,9 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
28778
28919
|
const cent = centrality(adjacency);
|
|
28779
28920
|
const limit = opts.limit ?? 8;
|
|
28780
28921
|
const category = opts.category || "";
|
|
28922
|
+
const mtimes = opts.fileMtimes;
|
|
28781
28923
|
const qTokens = tokenize(intent);
|
|
28924
|
+
const expandedTokens = expandSynonyms(qTokens);
|
|
28782
28925
|
const scored = entries.filter((e) => {
|
|
28783
28926
|
if (category && e.category !== category) return false;
|
|
28784
28927
|
if (e.ttl && isExpiredLocal(e.ttl)) return false;
|
|
@@ -28787,11 +28930,20 @@ function generateSmartRecall(data, intent, opts = {}) {
|
|
|
28787
28930
|
const text = normalize(
|
|
28788
28931
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
28789
28932
|
);
|
|
28790
|
-
const
|
|
28933
|
+
const docTokens = text.split(" ");
|
|
28934
|
+
const exactMatch = qTokens.length === 0 || expandedTokens.some((t) => text.includes(t));
|
|
28935
|
+
const fuzzy = !exactMatch && qTokens.length > 0 && fuzzyMatch(qTokens, docTokens);
|
|
28936
|
+
const matchesQuery = exactMatch || fuzzy;
|
|
28791
28937
|
const bm25Score = bm25.get(e.key) || 0;
|
|
28792
28938
|
const centScore = cent.get(e.key) || 0;
|
|
28793
28939
|
const impScore = importance(e);
|
|
28794
|
-
|
|
28940
|
+
let drift = 0;
|
|
28941
|
+
if (mtimes && e.file) {
|
|
28942
|
+
const filePath = e.file.split(":")[0];
|
|
28943
|
+
const fileDate = mtimes.get(filePath);
|
|
28944
|
+
if (fileDate && e.date && fileDate > e.date) drift = 0.3;
|
|
28945
|
+
}
|
|
28946
|
+
const combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift;
|
|
28795
28947
|
return { entry: e, score: combined, matchesQuery };
|
|
28796
28948
|
}).filter((x) => x.score > 0 || x.matchesQuery).sort((a, b) => b.score - a.score).slice(0, limit);
|
|
28797
28949
|
if (scored.length === 0) {
|
|
@@ -28807,6 +28959,7 @@ function generateSystemPrimer(data) {
|
|
|
28807
28959
|
if (entries.length === 0) return "Empty memory. No entries saved.";
|
|
28808
28960
|
const byCategory = {};
|
|
28809
28961
|
for (const e of entries) {
|
|
28962
|
+
if (isPrivate(e)) continue;
|
|
28810
28963
|
if (!byCategory[e.category]) byCategory[e.category] = [];
|
|
28811
28964
|
byCategory[e.category].push(e);
|
|
28812
28965
|
}
|
|
@@ -28815,7 +28968,7 @@ function generateSystemPrimer(data) {
|
|
|
28815
28968
|
`Entries: ${entries.length}`,
|
|
28816
28969
|
""
|
|
28817
28970
|
];
|
|
28818
|
-
const top = [...entries].sort((a, b) => importance(b) - importance(a)).slice(0, 5);
|
|
28971
|
+
const top = [...entries].filter((e) => !isPrivate(e)).sort((a, b) => importance(b) - importance(a)).slice(0, 5);
|
|
28819
28972
|
lines.push("Top memories:");
|
|
28820
28973
|
for (const e of top) {
|
|
28821
28974
|
const quality = qualityScore(
|
|
@@ -29098,6 +29251,17 @@ function readGitIndex(cwd) {
|
|
|
29098
29251
|
if (!dir) return [];
|
|
29099
29252
|
return parseIndex(dir).map((e) => e.name);
|
|
29100
29253
|
}
|
|
29254
|
+
function fileMtimes(cwd) {
|
|
29255
|
+
const dir = gitDir(cwd);
|
|
29256
|
+
if (!dir) return /* @__PURE__ */ new Map();
|
|
29257
|
+
const entries = parseIndex(dir);
|
|
29258
|
+
const out = /* @__PURE__ */ new Map();
|
|
29259
|
+
for (const e of entries) {
|
|
29260
|
+
const date5 = new Date(e.mtimeSec * 1e3).toISOString().split("T")[0];
|
|
29261
|
+
out.set(e.name, date5);
|
|
29262
|
+
}
|
|
29263
|
+
return out;
|
|
29264
|
+
}
|
|
29101
29265
|
function readObject(sha, cwd) {
|
|
29102
29266
|
const dir = gitDir(cwd);
|
|
29103
29267
|
if (!dir) return null;
|
|
@@ -29475,11 +29639,15 @@ function formatRelevantEntries(data, task, limit = 6) {
|
|
|
29475
29639
|
const bm25 = bm25Scores(entries, task);
|
|
29476
29640
|
const cent = centrality(adjacency);
|
|
29477
29641
|
const qTokens = tokenize(task);
|
|
29478
|
-
const
|
|
29642
|
+
const expandedTokens = expandSynonyms(qTokens);
|
|
29643
|
+
const scored = entries.filter((e) => !(e.ttl && isExpiredLocal(e.ttl)) && !isPrivate(e)).map((e) => {
|
|
29479
29644
|
const text = normalize(
|
|
29480
29645
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
29481
29646
|
);
|
|
29482
|
-
const
|
|
29647
|
+
const docTokens = text.split(" ");
|
|
29648
|
+
const exactMatch = qTokens.length === 0 || expandedTokens.some((t) => text.includes(t));
|
|
29649
|
+
const fuzzy = !exactMatch && qTokens.length > 0 && fuzzyMatch(qTokens, docTokens);
|
|
29650
|
+
const matchesQuery = exactMatch || fuzzy;
|
|
29483
29651
|
const bm25Score = bm25.get(e.key) || 0;
|
|
29484
29652
|
const centScore = cent.get(e.key) || 0;
|
|
29485
29653
|
const impScore = importance(e);
|
|
@@ -29503,7 +29671,7 @@ ${rendered}`;
|
|
|
29503
29671
|
}
|
|
29504
29672
|
function formatPatterns(data) {
|
|
29505
29673
|
const entries = parseEntries(data);
|
|
29506
|
-
const patterns = entries.filter((e) => e.category === "pattern").sort((a, b) => importance(b) - importance(a)).slice(0, 5);
|
|
29674
|
+
const patterns = entries.filter((e) => e.category === "pattern" && !isPrivate(e)).sort((a, b) => importance(b) - importance(a)).slice(0, 5);
|
|
29507
29675
|
if (patterns.length === 0) return "";
|
|
29508
29676
|
const lines = patterns.map(
|
|
29509
29677
|
(e) => `- **${e.key}**: ${e.content.slice(0, 120)}`
|
|
@@ -29580,7 +29748,7 @@ function generateContextBrief(data, opts = {}) {
|
|
|
29580
29748
|
function formatTopEntries(data, limit) {
|
|
29581
29749
|
const entries = parseEntries(data);
|
|
29582
29750
|
if (entries.length === 0) return "";
|
|
29583
|
-
const top = [...entries].filter((e) => !(e.ttl && isExpiredLocal(e.ttl))).sort((a, b) => importance(b) - importance(a)).slice(0, limit);
|
|
29751
|
+
const top = [...entries].filter((e) => !(e.ttl && isExpiredLocal(e.ttl)) && !isPrivate(e)).sort((a, b) => importance(b) - importance(a)).slice(0, limit);
|
|
29584
29752
|
if (top.length === 0) return "";
|
|
29585
29753
|
const rendered = renderCompact(top);
|
|
29586
29754
|
return `## Top memories
|
|
@@ -29782,6 +29950,21 @@ function generateContextHealth(data, root) {
|
|
|
29782
29950
|
warnings.push(`${brokenFiles.length} refs to non-existent files: ${brokenFiles.slice(0, 3).join("; ")}`);
|
|
29783
29951
|
score -= 5;
|
|
29784
29952
|
}
|
|
29953
|
+
const mtimes = fileMtimes(root);
|
|
29954
|
+
const driftedEntries = [];
|
|
29955
|
+
for (const e of entries) {
|
|
29956
|
+
if (!e.file) continue;
|
|
29957
|
+
const filePath = e.file.split(":")[0];
|
|
29958
|
+
if (!filePath) continue;
|
|
29959
|
+
const fileDate = mtimes.get(filePath);
|
|
29960
|
+
if (fileDate && e.date && fileDate > e.date) {
|
|
29961
|
+
driftedEntries.push(`${e.key} (${e.file} modified ${fileDate})`);
|
|
29962
|
+
}
|
|
29963
|
+
}
|
|
29964
|
+
if (driftedEntries.length > 0) {
|
|
29965
|
+
warnings.push(`${driftedEntries.length} entries with stale file refs: ${driftedEntries.slice(0, 3).join("; ")}`);
|
|
29966
|
+
score -= 4;
|
|
29967
|
+
}
|
|
29785
29968
|
const sessions = listSessions();
|
|
29786
29969
|
const stale = sessions.filter((s) => !s.active && !s.ended);
|
|
29787
29970
|
if (stale.length > 0) {
|
|
@@ -29820,6 +30003,7 @@ Date: ${today} | Entries: ${entries.length}
|
|
|
29820
30003
|
}
|
|
29821
30004
|
const byCategory = {};
|
|
29822
30005
|
for (const e of entries) {
|
|
30006
|
+
if (isPrivate(e)) continue;
|
|
29823
30007
|
if (!byCategory[e.category]) byCategory[e.category] = [];
|
|
29824
30008
|
byCategory[e.category].push(e);
|
|
29825
30009
|
}
|
|
@@ -29879,7 +30063,7 @@ function registerTools(server2) {
|
|
|
29879
30063
|
"memory_remember",
|
|
29880
30064
|
{
|
|
29881
30065
|
title: "Save to Memory",
|
|
29882
|
-
description: "Save a fact to the project's persistent memory (decisions, patterns, bugs, knowledge). Persists between sessions.",
|
|
30066
|
+
description: "Save a fact to the project's persistent memory (decisions, patterns, bugs, knowledge). Persists between sessions. Tags: 'private' excludes from context injection; 'superseded' marks as obsolete.",
|
|
29883
30067
|
inputSchema: {
|
|
29884
30068
|
category: external_exports.enum(["decision", "pattern", "bug", "knowledge"]).describe("Category of the fact"),
|
|
29885
30069
|
key: external_exports.string().describe("Short title in kebab-case (e.g. risk-engine-priority)"),
|
|
@@ -29970,7 +30154,7 @@ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
|
|
|
29970
30154
|
"memory_recall",
|
|
29971
30155
|
{
|
|
29972
30156
|
title: "Search Memory",
|
|
29973
|
-
description: "Search the project's persistent memory. Returns relevant entries. Use BEFORE reading files.",
|
|
30157
|
+
description: "Search the project's persistent memory. Returns relevant entries. Use BEFORE reading files. Pattern: recall \u2192 context_diff for recent changes \u2192 capture to save observations.",
|
|
29974
30158
|
inputSchema: {
|
|
29975
30159
|
query: external_exports.string().describe("Text to search for"),
|
|
29976
30160
|
category: external_exports.string().optional().default("").describe("Filter by category (empty = all)"),
|
|
@@ -30163,7 +30347,7 @@ ${formatted}` }] };
|
|
|
30163
30347
|
"memory_smart_recall",
|
|
30164
30348
|
{
|
|
30165
30349
|
title: "Smart Recall (Unified)",
|
|
30166
|
-
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.",
|
|
30350
|
+
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. Then use context_diff for recent changes, context_focus for deep dives.",
|
|
30167
30351
|
inputSchema: {
|
|
30168
30352
|
intent: external_exports.string().describe("Describe what you need to know (e.g. 'database schema for backend')"),
|
|
30169
30353
|
limit: external_exports.number().optional().default(8).describe("Maximum entries to return"),
|
|
@@ -30172,7 +30356,8 @@ ${formatted}` }] };
|
|
|
30172
30356
|
},
|
|
30173
30357
|
async ({ intent, limit, category }) => {
|
|
30174
30358
|
const data = readMemory();
|
|
30175
|
-
const
|
|
30359
|
+
const mtimes = fileMtimes();
|
|
30360
|
+
const result = generateSmartRecall(data, intent, { limit, category, fileMtimes: mtimes });
|
|
30176
30361
|
return { content: [{ type: "text", text: result }] };
|
|
30177
30362
|
}
|
|
30178
30363
|
);
|
|
@@ -30612,7 +30797,7 @@ function registerResources(server2) {
|
|
|
30612
30797
|
|
|
30613
30798
|
// src/mcp/server.ts
|
|
30614
30799
|
var server = new McpServer(
|
|
30615
|
-
{ name: "toon-memory", version: "2.
|
|
30800
|
+
{ name: "toon-memory", version: "2.11.0" },
|
|
30616
30801
|
{ capabilities: { tools: { listChanged: true }, resources: { listChanged: true } } }
|
|
30617
30802
|
);
|
|
30618
30803
|
registerResources(server);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toon-memory",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "MCP server giving AI coding agents offline, token-efficient persistent memory — 21 tools, 80% fewer tool calls, recall decisions, patterns, and bugs across sessions. No LLM, no server; works with 15+ agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/lib/context.ts
CHANGED
|
@@ -17,9 +17,11 @@ import { existsSync, readFileSync } from "fs"
|
|
|
17
17
|
import { join } from "path"
|
|
18
18
|
import { parseEntries, buildGraph, bm25Scores, centrality, renderCompact, type GraphEntry } from "./graph"
|
|
19
19
|
import { qualityScore } from "./quality"
|
|
20
|
-
import { normalize, isExpiredLocal, tokenize, importance } from "./utils"
|
|
20
|
+
import { normalize, isExpiredLocal, tokenize, importance, isPrivate } from "./utils"
|
|
21
|
+
import { expandSynonyms } from "./synonyms"
|
|
22
|
+
import { fuzzyMatch } from "./fuzzy"
|
|
21
23
|
import { coordinationView, currentBranch, pruneSessions, listSessions } from "./sessions"
|
|
22
|
-
import { readRecentCommits, gitStatusSummary, readGitIndex } from "./git"
|
|
24
|
+
import { readRecentCommits, gitStatusSummary, readGitIndex, fileMtimes } from "./git"
|
|
23
25
|
import { scanProjectStructure, readManifest, readEnvExample } from "./project-scan"
|
|
24
26
|
import { findFilesByPattern, searchCode, findCallers } from "./code-search"
|
|
25
27
|
|
|
@@ -60,14 +62,18 @@ function formatRelevantEntries(data: string, task: string, limit: number = 6): s
|
|
|
60
62
|
const bm25 = bm25Scores(entries, task)
|
|
61
63
|
const cent = centrality(adjacency)
|
|
62
64
|
const qTokens = tokenize(task)
|
|
65
|
+
const expandedTokens = expandSynonyms(qTokens)
|
|
63
66
|
|
|
64
67
|
const scored = entries
|
|
65
|
-
.filter((e) => !(e.ttl && isExpiredLocal(e.ttl)))
|
|
68
|
+
.filter((e) => !(e.ttl && isExpiredLocal(e.ttl)) && !isPrivate(e))
|
|
66
69
|
.map((e) => {
|
|
67
70
|
const text = normalize(
|
|
68
71
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
69
72
|
)
|
|
70
|
-
const
|
|
73
|
+
const docTokens = text.split(" ")
|
|
74
|
+
const exactMatch = qTokens.length === 0 || expandedTokens.some((t) => text.includes(t))
|
|
75
|
+
const fuzzy = !exactMatch && qTokens.length > 0 && fuzzyMatch(qTokens, docTokens)
|
|
76
|
+
const matchesQuery = exactMatch || fuzzy
|
|
71
77
|
const bm25Score = bm25.get(e.key) || 0
|
|
72
78
|
const centScore = cent.get(e.key) || 0
|
|
73
79
|
const impScore = importance(e)
|
|
@@ -105,7 +111,7 @@ function formatRelevantEntries(data: string, task: string, limit: number = 6): s
|
|
|
105
111
|
function formatPatterns(data: string): string {
|
|
106
112
|
const entries = parseEntries(data)
|
|
107
113
|
const patterns = entries
|
|
108
|
-
.filter((e) => e.category === "pattern")
|
|
114
|
+
.filter((e) => e.category === "pattern" && !isPrivate(e))
|
|
109
115
|
.sort((a, b) => importance(b) - importance(a))
|
|
110
116
|
.slice(0, 5)
|
|
111
117
|
|
|
@@ -245,7 +251,7 @@ function formatTopEntries(data: string, limit: number): string {
|
|
|
245
251
|
if (entries.length === 0) return ""
|
|
246
252
|
|
|
247
253
|
const top = [...entries]
|
|
248
|
-
.filter((e) => !(e.ttl && isExpiredLocal(e.ttl)))
|
|
254
|
+
.filter((e) => !(e.ttl && isExpiredLocal(e.ttl)) && !isPrivate(e))
|
|
249
255
|
.sort((a, b) => importance(b) - importance(a))
|
|
250
256
|
.slice(0, limit)
|
|
251
257
|
|
|
@@ -539,14 +545,31 @@ export function generateContextHealth(data: string, root: string): { report: Hea
|
|
|
539
545
|
score -= 5
|
|
540
546
|
}
|
|
541
547
|
|
|
542
|
-
// 6.
|
|
548
|
+
// 6. Code drift detection: entries whose linked file changed after creation
|
|
549
|
+
const mtimes = fileMtimes(root)
|
|
550
|
+
const driftedEntries: string[] = []
|
|
551
|
+
for (const e of entries) {
|
|
552
|
+
if (!e.file) continue
|
|
553
|
+
const filePath = e.file.split(":")[0]
|
|
554
|
+
if (!filePath) continue
|
|
555
|
+
const fileDate = mtimes.get(filePath)
|
|
556
|
+
if (fileDate && e.date && fileDate > e.date) {
|
|
557
|
+
driftedEntries.push(`${e.key} (${e.file} modified ${fileDate})`)
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (driftedEntries.length > 0) {
|
|
561
|
+
warnings.push(`${driftedEntries.length} entries with stale file refs: ${driftedEntries.slice(0, 3).join("; ")}`)
|
|
562
|
+
score -= 4
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// 7. Stale sessions
|
|
543
566
|
const sessions = listSessions()
|
|
544
567
|
const stale = sessions.filter((s) => !s.active && !s.ended)
|
|
545
568
|
if (stale.length > 0) {
|
|
546
569
|
info.push(`${stale.length} stale sessions (will be pruned automatically)`)
|
|
547
570
|
}
|
|
548
571
|
|
|
549
|
-
//
|
|
572
|
+
// 8. Entry count
|
|
550
573
|
if (entries.length > 80) {
|
|
551
574
|
warnings.push(`${entries.length} entries (near limit of 100)`)
|
|
552
575
|
score -= 3
|
|
@@ -595,9 +618,10 @@ export function generateContextExport(data: string, format: ExportFormat = "full
|
|
|
595
618
|
return sections.join("\n")
|
|
596
619
|
}
|
|
597
620
|
|
|
598
|
-
// Group by category
|
|
621
|
+
// Group by category (exclude private entries)
|
|
599
622
|
const byCategory: Record<string, GraphEntry[]> = {}
|
|
600
623
|
for (const e of entries) {
|
|
624
|
+
if (isPrivate(e)) continue
|
|
601
625
|
if (!byCategory[e.category]) byCategory[e.category] = []
|
|
602
626
|
byCategory[e.category].push(e)
|
|
603
627
|
}
|
package/src/lib/fuzzy.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fuzzy token matching via Levenshtein distance.
|
|
3
|
+
*
|
|
4
|
+
* Handles typos and minor variations (e.g. "tiemout" ≈ "timeout").
|
|
5
|
+
* Pure JS — zero dependencies, ~20 lines of core logic.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Levenshtein edit distance between two strings.
|
|
10
|
+
* Classic DP approach, O(n*m) time, O(min(n,m)) space.
|
|
11
|
+
*/
|
|
12
|
+
export function levenshtein(a: string, b: string): number {
|
|
13
|
+
const al = a.length
|
|
14
|
+
const bl = b.length
|
|
15
|
+
if (al === 0) return bl
|
|
16
|
+
if (bl === 0) return al
|
|
17
|
+
|
|
18
|
+
// Optimization: only keep two rows at a time
|
|
19
|
+
let prev = new Array(bl + 1)
|
|
20
|
+
let curr = new Array(bl + 1)
|
|
21
|
+
for (let j = 0; j <= bl; j++) prev[j] = j
|
|
22
|
+
|
|
23
|
+
for (let i = 1; i <= al; i++) {
|
|
24
|
+
curr[0] = i
|
|
25
|
+
for (let j = 1; j <= bl; j++) {
|
|
26
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1
|
|
27
|
+
curr[j] = Math.min(
|
|
28
|
+
prev[j] + 1, // deletion
|
|
29
|
+
curr[j - 1] + 1, // insertion
|
|
30
|
+
prev[j - 1] + cost // substitution
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
;[prev, curr] = [curr, prev]
|
|
34
|
+
}
|
|
35
|
+
return prev[bl]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Check if any query token fuzzy-matches any document token
|
|
40
|
+
* within the given Levenshtein distance.
|
|
41
|
+
*
|
|
42
|
+
* Short-circuits on first match for speed.
|
|
43
|
+
*/
|
|
44
|
+
export function fuzzyMatch(
|
|
45
|
+
queryTokens: string[],
|
|
46
|
+
docTokens: string[],
|
|
47
|
+
maxDistance: number = 2
|
|
48
|
+
): boolean {
|
|
49
|
+
for (const qt of queryTokens) {
|
|
50
|
+
// Skip very short tokens (1-2 chars) — too many false positives
|
|
51
|
+
if (qt.length <= 2) continue
|
|
52
|
+
for (const dt of docTokens) {
|
|
53
|
+
if (Math.abs(qt.length - dt.length) > maxDistance) continue
|
|
54
|
+
if (levenshtein(qt, dt) <= maxDistance) return true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return false
|
|
58
|
+
}
|
package/src/lib/git.ts
CHANGED
|
@@ -149,6 +149,22 @@ export function readGitIndex(cwd?: string): string[] {
|
|
|
149
149
|
return parseIndex(dir).map((e) => e.name)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Return a map of file path → last-modified date (YYYY-MM-DD) from the git index.
|
|
154
|
+
* Used for drift detection: compare entry creation date against file mtime.
|
|
155
|
+
*/
|
|
156
|
+
export function fileMtimes(cwd?: string): Map<string, string> {
|
|
157
|
+
const dir = gitDir(cwd)
|
|
158
|
+
if (!dir) return new Map()
|
|
159
|
+
const entries = parseIndex(dir)
|
|
160
|
+
const out = new Map<string, string>()
|
|
161
|
+
for (const e of entries) {
|
|
162
|
+
const date = new Date(e.mtimeSec * 1000).toISOString().split("T")[0]
|
|
163
|
+
out.set(e.name, date)
|
|
164
|
+
}
|
|
165
|
+
return out
|
|
166
|
+
}
|
|
167
|
+
|
|
152
168
|
/**
|
|
153
169
|
* Parse a raw git object (decompressed with zlib).
|
|
154
170
|
* Returns the object type and content.
|
package/src/lib/graph.ts
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { normalize, isExpiredLocal, tokenize, importance } from "./utils"
|
|
18
|
+
import { expandSynonyms } from "./synonyms"
|
|
19
|
+
import { fuzzyMatch } from "./fuzzy"
|
|
18
20
|
|
|
19
21
|
export interface GraphEntry {
|
|
20
22
|
id: string
|
|
@@ -207,6 +209,7 @@ export function graphRecallDetailed(
|
|
|
207
209
|
const to_date = opts.to_date || ""
|
|
208
210
|
|
|
209
211
|
const qTokens = tokenize(query)
|
|
212
|
+
const expandedTokens = expandSynonyms(qTokens)
|
|
210
213
|
const bm25 = bm25Scores(entries, query)
|
|
211
214
|
const cent = centrality(adjacency)
|
|
212
215
|
|
|
@@ -219,7 +222,10 @@ export function graphRecallDetailed(
|
|
|
219
222
|
const text = normalize(
|
|
220
223
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
221
224
|
)
|
|
222
|
-
|
|
225
|
+
const docTokens = text.split(" ")
|
|
226
|
+
const exactMatch = expandedTokens.some((t) => text.includes(t))
|
|
227
|
+
const fuzzy = !exactMatch && fuzzyMatch(qTokens, docTokens)
|
|
228
|
+
if (qTokens.length > 0 && !exactMatch && !fuzzy) continue
|
|
223
229
|
seedKeys.add(e.key)
|
|
224
230
|
}
|
|
225
231
|
|
package/src/lib/quality.ts
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { parseEntries, buildGraph, bm25Scores, centrality, renderCompact, type GraphEntry } from "./graph"
|
|
11
|
-
import { normalize, isExpiredLocal, tokenize, importance } from "./utils"
|
|
11
|
+
import { normalize, isExpiredLocal, tokenize, importance, isPrivate } from "./utils"
|
|
12
|
+
import { expandSynonyms } from "./synonyms"
|
|
13
|
+
import { fuzzyMatch } from "./fuzzy"
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Quality score for an entry (0..1). Pure heuristics, no LLM.
|
|
@@ -100,7 +102,7 @@ export function mergeEntries(existingLine: string, newLine: string): string {
|
|
|
100
102
|
export function generateSmartRecall(
|
|
101
103
|
data: string,
|
|
102
104
|
intent: string,
|
|
103
|
-
opts: { limit?: number; category?: string; bumpAccess?: (ids: string[]) => void } = {}
|
|
105
|
+
opts: { limit?: number; category?: string; bumpAccess?: (ids: string[]) => void; fileMtimes?: Map<string, string> } = {}
|
|
104
106
|
): string {
|
|
105
107
|
const entries = parseEntries(data)
|
|
106
108
|
if (entries.length === 0) return "Empty memory."
|
|
@@ -110,8 +112,10 @@ export function generateSmartRecall(
|
|
|
110
112
|
const cent = centrality(adjacency)
|
|
111
113
|
const limit = opts.limit ?? 8
|
|
112
114
|
const category = opts.category || ""
|
|
115
|
+
const mtimes = opts.fileMtimes
|
|
113
116
|
|
|
114
117
|
const qTokens = tokenize(intent)
|
|
118
|
+
const expandedTokens = expandSynonyms(qTokens)
|
|
115
119
|
|
|
116
120
|
const scored = entries
|
|
117
121
|
.filter((e) => {
|
|
@@ -123,12 +127,22 @@ export function generateSmartRecall(
|
|
|
123
127
|
const text = normalize(
|
|
124
128
|
`${e.id} ${e.category} ${e.key} ${e.content} ${e.file} ${e.tags.join(" ")}`
|
|
125
129
|
)
|
|
126
|
-
const
|
|
130
|
+
const docTokens = text.split(" ")
|
|
131
|
+
const exactMatch = qTokens.length === 0 || expandedTokens.some((t) => text.includes(t))
|
|
132
|
+
const fuzzy = !exactMatch && qTokens.length > 0 && fuzzyMatch(qTokens, docTokens)
|
|
133
|
+
const matchesQuery = exactMatch || fuzzy
|
|
127
134
|
const bm25Score = bm25.get(e.key) || 0
|
|
128
135
|
const centScore = cent.get(e.key) || 0
|
|
129
136
|
const impScore = importance(e)
|
|
137
|
+
// Drift penalty: if the linked file was modified after the entry was created
|
|
138
|
+
let drift = 0
|
|
139
|
+
if (mtimes && e.file) {
|
|
140
|
+
const filePath = e.file.split(":")[0]
|
|
141
|
+
const fileDate = mtimes.get(filePath)
|
|
142
|
+
if (fileDate && e.date && fileDate > e.date) drift = 0.3
|
|
143
|
+
}
|
|
130
144
|
const combined =
|
|
131
|
-
bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0)
|
|
145
|
+
bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift
|
|
132
146
|
return { entry: e, score: combined, matchesQuery }
|
|
133
147
|
})
|
|
134
148
|
.filter((x) => x.score > 0 || x.matchesQuery)
|
|
@@ -158,6 +172,7 @@ export function generateSystemPrimer(data: string): string {
|
|
|
158
172
|
|
|
159
173
|
const byCategory: Record<string, GraphEntry[]> = {}
|
|
160
174
|
for (const e of entries) {
|
|
175
|
+
if (isPrivate(e)) continue
|
|
161
176
|
if (!byCategory[e.category]) byCategory[e.category] = []
|
|
162
177
|
byCategory[e.category].push(e)
|
|
163
178
|
}
|
|
@@ -170,6 +185,7 @@ export function generateSystemPrimer(data: string): string {
|
|
|
170
185
|
|
|
171
186
|
// Top entries by importance (global)
|
|
172
187
|
const top = [...entries]
|
|
188
|
+
.filter((e) => !isPrivate(e))
|
|
173
189
|
.sort((a, b) => importance(b) - importance(a))
|
|
174
190
|
.slice(0, 5)
|
|
175
191
|
lines.push("Top memories:")
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-specific synonym dictionary for toon-memory.
|
|
3
|
+
*
|
|
4
|
+
* Maps common coding/DevOps terms to their equivalents so that queries
|
|
5
|
+
* like "conexión caída" can find entries containing "timeout de red".
|
|
6
|
+
* Pure static map — zero LLM, zero network, zero embeddings.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const SYNONYMS: Record<string, string[]> = {
|
|
10
|
+
// Infrastructure / networking
|
|
11
|
+
"conexión": ["timeout", "red", "conectar", "disconnect", "connection", "conn"],
|
|
12
|
+
"conectar": ["timeout", "red", "conexión", "connect", "connection"],
|
|
13
|
+
"caída": ["down", "crash", "fail", "error", "dropped", "falla"],
|
|
14
|
+
"down": ["caída", "crash", "fail", "caer", "offline"],
|
|
15
|
+
"crash": ["caída", "down", "fail", "error", "colapso"],
|
|
16
|
+
"timeout": ["conexión", "red", "expirar", "deadline", "exceed"],
|
|
17
|
+
"red": ["network", "conexión", "ip", "dns", "proxy", "gateway"],
|
|
18
|
+
"network": ["red", "conexión", "ip", "dns", "proxy"],
|
|
19
|
+
"server": ["servidor", "backend", "api", "host"],
|
|
20
|
+
"servidor": ["server", "backend", "api", "host"],
|
|
21
|
+
"client": ["cliente", "frontend", "browser", "user-agent"],
|
|
22
|
+
"cliente": ["client", "frontend", "browser"],
|
|
23
|
+
|
|
24
|
+
// Data / storage
|
|
25
|
+
"cache": ["redis", "memcached", "cached", "caché"],
|
|
26
|
+
"redis": ["cache", "memcached", "session", "pubsub"],
|
|
27
|
+
"pool": ["pool", "connection pool", "pooling", "concurrencia"],
|
|
28
|
+
"database": ["db", "postgres", "mysql", "mongo", "sql", "base de datos"],
|
|
29
|
+
"db": ["database", "postgres", "mysql", "mongo", "sql"],
|
|
30
|
+
"session": ["sesión", "cookie", "token", "auth"],
|
|
31
|
+
|
|
32
|
+
// Errors / debugging
|
|
33
|
+
"error": ["bug", "exception", "fail", "fallo", "error", "err"],
|
|
34
|
+
"bug": ["error", "defect", "issue", "fallo", "problema"],
|
|
35
|
+
"exception": ["error", "throw", "catch", "error"],
|
|
36
|
+
"fail": ["error", "falla", "fallo", "crash", "fail"],
|
|
37
|
+
"falla": ["error", "fail", "fallo", "bug", "crash"],
|
|
38
|
+
"debug": ["debugging", "log", "trace", "diagnóstico"],
|
|
39
|
+
"log": ["logging", "debug", "trace", "registro"],
|
|
40
|
+
"warning": ["warn", "advertencia", "alerta"],
|
|
41
|
+
|
|
42
|
+
// Architecture
|
|
43
|
+
"auth": ["authentication", "autenticación", "login", "jwt", "token", "oauth"],
|
|
44
|
+
"autenticación": ["auth", "authentication", "login", "jwt", "oauth"],
|
|
45
|
+
"api": ["endpoint", "route", "rest", "graphql", "rpc"],
|
|
46
|
+
"endpoint": ["api", "route", "url", "path"],
|
|
47
|
+
"config": ["configuración", "settings", "env", "environment"],
|
|
48
|
+
"configuración": ["config", "settings", "env", "environment"],
|
|
49
|
+
"deploy": ["deployment", "despliegue", "release", "ship", "ci/cd"],
|
|
50
|
+
"despliegue": ["deploy", "deployment", "release", "publish"],
|
|
51
|
+
"migration": ["migración", "migrate", "upgrade", "schema change"],
|
|
52
|
+
"migración": ["migration", "migrate", "upgrade"],
|
|
53
|
+
|
|
54
|
+
// Code / patterns
|
|
55
|
+
"refactor": ["refactoring", "reorganizar", "reestructurar", "clean"],
|
|
56
|
+
"reestructurar": ["refactor", "refactoring", "reorganizar", "restructure"],
|
|
57
|
+
"pattern": ["patrón", "pattern", "convention", "norma", "estándar"],
|
|
58
|
+
"patrón": ["pattern", "convention", "norma", "estándar"],
|
|
59
|
+
"decision": ["decisión", "decision", "elección", "choice", "acuerdo"],
|
|
60
|
+
"decisión": ["decision", "elección", "choice", "acuerdo"],
|
|
61
|
+
"knowledge": ["conocimiento", "knowledge", "info", "información"],
|
|
62
|
+
"conocimiento": ["knowledge", "info", "información"],
|
|
63
|
+
|
|
64
|
+
// Performance
|
|
65
|
+
"performance": ["rendimiento", "perf", "latency", "throughput", "speed"],
|
|
66
|
+
"rendimiento": ["performance", "perf", "latency", "speed"],
|
|
67
|
+
"latency": ["latencia", "delay", "response time", "rt"],
|
|
68
|
+
"latencia": ["latency", "delay", "response time"],
|
|
69
|
+
"memory": ["memoria", "ram", "heap", "leak"],
|
|
70
|
+
"memoria": ["memory", "ram", "heap", "leak"],
|
|
71
|
+
"leak": ["fuga", "memory leak", "memoria"],
|
|
72
|
+
|
|
73
|
+
// Testing
|
|
74
|
+
"test": ["testing", "prueba", "tests", "spec"],
|
|
75
|
+
"prueba": ["test", "testing", "spec"],
|
|
76
|
+
"mock": ["mocking", "stub", "fake", "doble"],
|
|
77
|
+
"coverage": ["cobertura", "coverage", "tests"],
|
|
78
|
+
|
|
79
|
+
// Git / VCS
|
|
80
|
+
"commit": ["commits", "提交", "checkpoint", "save"],
|
|
81
|
+
"branch": ["rama", "branch", "feature branch", "checkout"],
|
|
82
|
+
"rama": ["branch", "feature branch", "checkout"],
|
|
83
|
+
"merge": ["mergear", "merge", "combine", "unir"],
|
|
84
|
+
"conflict": ["conflicto", "conflict", "merge conflict", "clash"],
|
|
85
|
+
"conflicto": ["conflict", "merge conflict", "clash"],
|
|
86
|
+
"revert": ["rollback", "deshacer", "undo", "restore"],
|
|
87
|
+
|
|
88
|
+
// UI / frontend
|
|
89
|
+
"ui": ["interfaz", "interface", "gui", "frontend", "vista"],
|
|
90
|
+
"interfaz": ["ui", "interface", "gui", "frontend"],
|
|
91
|
+
"component": ["componente", "widget", "module", "pieza"],
|
|
92
|
+
"componente": ["component", "widget", "module"],
|
|
93
|
+
"responsive": ["responsive", "mobile", "adaptativo", "layout"],
|
|
94
|
+
"layout": ["diseño", "design", "layout", "estructura"],
|
|
95
|
+
|
|
96
|
+
// DevOps
|
|
97
|
+
"docker": ["container", "contenedor", "image", "imagen"],
|
|
98
|
+
"contenedor": ["docker", "container", "image"],
|
|
99
|
+
"kubernetes": ["k8s", "cluster", "pods", "deployment"],
|
|
100
|
+
"ci/cd": ["pipeline", "deploy", "continuous integration", "continuous deployment"],
|
|
101
|
+
"monitoring": ["monitoreo", "observability", "metrics", "alerts"],
|
|
102
|
+
"monitoreo": ["monitoring", "observability", "metrics"],
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Expand query tokens with domain synonyms.
|
|
107
|
+
* Returns a deduplicated set containing the original tokens + their synonyms.
|
|
108
|
+
*/
|
|
109
|
+
export function expandSynonyms(queryTokens: string[]): string[] {
|
|
110
|
+
const expanded = new Set(queryTokens)
|
|
111
|
+
for (const token of queryTokens) {
|
|
112
|
+
const synonyms = SYNONYMS[token]
|
|
113
|
+
if (synonyms) {
|
|
114
|
+
for (const s of synonyms) expanded.add(s)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return [...expanded]
|
|
118
|
+
}
|
package/src/lib/utils.ts
CHANGED
|
@@ -22,4 +22,14 @@ export function importance(e: { date: string; accessed: number }): number {
|
|
|
22
22
|
return recency * 0.6 + freq * 0.4
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const tokenize = (s: string): string[] =>
|
|
25
|
+
export const tokenize = (s: string): string[] =>
|
|
26
|
+
s
|
|
27
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
28
|
+
.replace(/[-_]/g, " ")
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.split(/\s+/)
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
|
|
33
|
+
/** Check if an entry is marked as private (excluded from context injection). */
|
|
34
|
+
export const isPrivate = (e: { tags: string[] }): boolean =>
|
|
35
|
+
e.tags.some((t) => t.toLowerCase() === "private")
|
package/src/mcp/tools.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { graphRecallDetailed, renderCompact, parseEntries } from "../lib/graph"
|
|
|
15
15
|
import { qualityScore, mergeEntries, generateSmartRecall } from "../lib/quality"
|
|
16
16
|
import { generateContextBrief, generateContextGenerate, generateContextDiff, generateContextFocus, generateContextHealth, generateContextExport } from "../lib/context"
|
|
17
17
|
import { coordinationView, resolveSessionId, currentBranch, SESSION_TTL_MS } from "../lib/sessions"
|
|
18
|
+
import { fileMtimes } from "../lib/git"
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Register all 20 memory tools.
|
|
@@ -27,7 +28,7 @@ server.registerTool(
|
|
|
27
28
|
"memory_remember",
|
|
28
29
|
{
|
|
29
30
|
title: "Save to Memory",
|
|
30
|
-
description: "Save a fact to the project's persistent memory (decisions, patterns, bugs, knowledge). Persists between sessions.",
|
|
31
|
+
description: "Save a fact to the project's persistent memory (decisions, patterns, bugs, knowledge). Persists between sessions. Tags: 'private' excludes from context injection; 'superseded' marks as obsolete.",
|
|
31
32
|
inputSchema: {
|
|
32
33
|
category: z.enum(["decision", "pattern", "bug", "knowledge"]).describe("Category of the fact"),
|
|
33
34
|
key: z.string().describe("Short title in kebab-case (e.g. risk-engine-priority)"),
|
|
@@ -125,7 +126,7 @@ server.registerTool(
|
|
|
125
126
|
"memory_recall",
|
|
126
127
|
{
|
|
127
128
|
title: "Search Memory",
|
|
128
|
-
description: "Search the project's persistent memory. Returns relevant entries. Use BEFORE reading files.",
|
|
129
|
+
description: "Search the project's persistent memory. Returns relevant entries. Use BEFORE reading files. Pattern: recall → context_diff for recent changes → capture to save observations.",
|
|
129
130
|
inputSchema: {
|
|
130
131
|
query: z.string().describe("Text to search for"),
|
|
131
132
|
category: z.string().optional().default("").describe("Filter by category (empty = all)"),
|
|
@@ -356,7 +357,7 @@ server.registerTool(
|
|
|
356
357
|
"memory_smart_recall",
|
|
357
358
|
{
|
|
358
359
|
title: "Smart Recall (Unified)",
|
|
359
|
-
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.",
|
|
360
|
+
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. Then use context_diff for recent changes, context_focus for deep dives.",
|
|
360
361
|
inputSchema: {
|
|
361
362
|
intent: z.string().describe("Describe what you need to know (e.g. 'database schema for backend')"),
|
|
362
363
|
limit: z.number().optional().default(8).describe("Maximum entries to return"),
|
|
@@ -365,7 +366,8 @@ server.registerTool(
|
|
|
365
366
|
},
|
|
366
367
|
async ({ intent, limit, category }) => {
|
|
367
368
|
const data = readMemory()
|
|
368
|
-
const
|
|
369
|
+
const mtimes = fileMtimes()
|
|
370
|
+
const result = generateSmartRecall(data, intent, { limit, category, fileMtimes: mtimes })
|
|
369
371
|
return { content: [{ type: "text" as const, text: result }] }
|
|
370
372
|
}
|
|
371
373
|
)
|