toon-memory 4.3.1 → 4.3.3

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 CHANGED
@@ -22258,6 +22258,59 @@ var init_fuzzy = __esm({
22258
22258
  }
22259
22259
  });
22260
22260
 
22261
+ // src/lib/evidence.ts
22262
+ import { existsSync as existsSync5 } from "fs";
22263
+ function contentJaccard(a, b2) {
22264
+ const sa2 = new Set(tokenize(a));
22265
+ const sb2 = new Set(tokenize(b2));
22266
+ if (sa2.size === 0 && sb2.size === 0) return 1;
22267
+ if (sa2.size === 0 || sb2.size === 0) return 0;
22268
+ let inter = 0;
22269
+ for (const t of sa2) if (sb2.has(t)) inter++;
22270
+ const union2 = sa2.size + sb2.size - inter;
22271
+ return union2 > 0 ? inter / union2 : 0;
22272
+ }
22273
+ function detectContradictions(entries, candidate) {
22274
+ const candText = `${candidate.key} ${candidate.content} ${candidate.tags.join(" ")}`;
22275
+ const hits = [];
22276
+ for (const e of entries) {
22277
+ if (e.status === "obsolete" || e.status === "draft") continue;
22278
+ if (e.key === candidate.key) continue;
22279
+ const strong = e.category === "warning" || e.importance === "critical" || e.importance === "high";
22280
+ if (!strong) continue;
22281
+ const sim = contentJaccard(candText, `${e.key} ${e.content} ${e.tags.join(" ")}`);
22282
+ if (e.category === "warning" && sim < 0.22) continue;
22283
+ if (e.category !== "warning" && sim < 0.3) continue;
22284
+ hits.push({
22285
+ key: e.key,
22286
+ category: e.category,
22287
+ similarity: Math.round(sim * 100),
22288
+ note: e.category === "warning" ? "overlaps a WARNING (negative memory) \u2014 possible landmine" : "may contradict an existing critical/high decision"
22289
+ });
22290
+ }
22291
+ return hits.sort((a, b2) => b2.similarity - a.similarity).slice(0, 3);
22292
+ }
22293
+ function evidenceFor(entries, candidate, file2) {
22294
+ const conflicts = detectContradictions(entries, candidate);
22295
+ if (conflicts.length > 0) return "conflict";
22296
+ if (!file2) return "";
22297
+ const filePath = file2.split(":")[0];
22298
+ return existsSync5(filePath) ? "verified" : "unverified";
22299
+ }
22300
+ var EVIDENCE_BOOST, evidenceBoost;
22301
+ var init_evidence = __esm({
22302
+ "src/lib/evidence.ts"() {
22303
+ "use strict";
22304
+ init_utils();
22305
+ EVIDENCE_BOOST = {
22306
+ conflict: 0.15,
22307
+ verified: 0.03,
22308
+ unverified: -0.02
22309
+ };
22310
+ evidenceBoost = (evidence) => EVIDENCE_BOOST[evidence] ?? 0;
22311
+ }
22312
+ });
22313
+
22261
22314
  // src/lib/graph.ts
22262
22315
  function parseLinkToken(token) {
22263
22316
  const idx = token.lastIndexOf(":");
@@ -22279,7 +22332,7 @@ function parseEntries(data) {
22279
22332
  const out = [];
22280
22333
  for (const line of entryLines(data)) {
22281
22334
  const parts = parseToonLine(line);
22282
- if (parts.length < 7) continue;
22335
+ if (parts.length < 3) continue;
22283
22336
  const [id2, category, key, content, file2, tags, date5, ttl, accessedRaw, linksRaw] = parts;
22284
22337
  out.push({
22285
22338
  id: id2,
@@ -22298,7 +22351,8 @@ function parseEntries(data) {
22298
22351
  origin: parts.length > 15 && parts[15] ? parts[15] : "agent",
22299
22352
  status: parts.length > 16 && parts[16] ? parts[16] : "active",
22300
22353
  supersededOn: parts.length > 17 ? parts[17] || "" : "",
22301
- importance: parts.length > 18 ? parts[18] || "" : ""
22354
+ importance: parts.length > 18 ? parts[18] || "" : "",
22355
+ evidence: parts.length > 19 ? parts[19] || "" : ""
22302
22356
  });
22303
22357
  }
22304
22358
  return out;
@@ -22490,6 +22544,7 @@ function buildReason(e, bm25Score, bm25Max, impScore, today = (/* @__PURE__ */ n
22490
22544
  }
22491
22545
  parts.push(impScore >= 0.7 ? "importance HIGH" : impScore >= 0.4 ? "importance MED" : "importance LOW");
22492
22546
  if (e.importance) parts.push(`explicit ${e.importance}`);
22547
+ if (e.evidence) parts.push(`evidence ${e.evidence}`);
22493
22548
  return parts.join(" \xB7 ");
22494
22549
  }
22495
22550
  function graphRecallDetailed(data, query, opts = {}) {
@@ -22578,6 +22633,7 @@ function graphRecallDetailed(data, query, opts = {}) {
22578
22633
  }
22579
22634
  if (e.category === "warning") s2 += 0.2;
22580
22635
  s2 += importanceBoost(e.importance);
22636
+ s2 += evidenceBoost(e.evidence);
22581
22637
  s2 *= decay;
22582
22638
  return { e, s: s2, priority: e.priority };
22583
22639
  }).sort((a, b2) => {
@@ -22674,9 +22730,10 @@ function renderCompact(entries, opts = {}) {
22674
22730
  const statusInfo = e.status !== "active" ? ` \xB7 status: ${e.status}` : "";
22675
22731
  const supersededInfo = e.supersededOn ? ` \xB7 superseded: ${e.supersededOn}` : "";
22676
22732
  const impInfo = e.importance ? ` \xB7 importance: ${e.importance}` : "";
22733
+ const evInfo = e.evidence ? ` \xB7 evidence: ${e.evidence}` : "";
22677
22734
  block = `[${n}] ${e.category}/${e.key}${pin} (${e.id})
22678
22735
  ${e.content}
22679
- File: ${e.file} | Tags: ${e.tags.join(";")} | Date: ${e.date}${ttlInfo}${accessInfo}${lastAccess}${originInfo}${scopeInfo}${statusInfo}${supersededInfo}${impInfo}${links}`;
22736
+ File: ${e.file} | Tags: ${e.tags.join(";")} | Date: ${e.date}${ttlInfo}${accessInfo}${lastAccess}${originInfo}${scopeInfo}${statusInfo}${supersededInfo}${impInfo}${evInfo}${links}`;
22680
22737
  } else {
22681
22738
  let body = e.content;
22682
22739
  if (!isSeed && e.content.length > snippetLen) {
@@ -22730,6 +22787,7 @@ var init_graph = __esm({
22730
22787
  init_utils();
22731
22788
  init_synonyms();
22732
22789
  init_fuzzy();
22790
+ init_evidence();
22733
22791
  DEFAULT_EDGE_TYPE = "related";
22734
22792
  entryLines = (data) => data.split("\n").filter(
22735
22793
  (l) => l.startsWith(" ") && l.includes("|") && !l.startsWith(" summaries:")
@@ -22841,7 +22899,10 @@ function mergeEntries(existingLine, newLine) {
22841
22899
  const existingImportance = ep2.length > 18 ? ep2[18] || "" : "";
22842
22900
  const newImportance = np2.length > 18 ? np2[18] || "" : "";
22843
22901
  const importance2 = importanceRank(newImportance) >= importanceRank(existingImportance) ? newImportance : existingImportance;
22844
- return toToonLine([id2, category, key, content, file2, mergedTags, date5, ttl, String(accessed), mergedLinks, quality.toFixed(2), String(confidence), lastAccessed, String(priority), path_scope, origin, status, existingSupersededOn, importance2]);
22902
+ const existingEvidence = ep2.length > 19 ? ep2[19] || "" : "";
22903
+ const newEvidence = np2.length > 19 ? np2[19] || "" : "";
22904
+ const evidence = existingEvidence === "conflict" || newEvidence === "conflict" ? "conflict" : newEvidence || existingEvidence;
22905
+ return toToonLine([id2, category, key, content, file2, mergedTags, date5, ttl, String(accessed), mergedLinks, quality.toFixed(2), String(confidence), lastAccessed, String(priority), path_scope, origin, status, existingSupersededOn, importance2, evidence]);
22845
22906
  }
22846
22907
  function generateSmartRecall(data, intent, opts = {}) {
22847
22908
  const entries = parseEntries(data);
@@ -22897,11 +22958,12 @@ function generateSmartRecall(data, intent, opts = {}) {
22897
22958
  if (e.path_scope && globMatch(e.path_scope, ".")) folderBoost = 0.05;
22898
22959
  const warningBoost = e.category === "warning" ? 0.2 : 0;
22899
22960
  const impBoost = importanceBoost(e.importance);
22961
+ const evBoost = evidenceBoost(e.evidence);
22900
22962
  let combined;
22901
22963
  if (opts.rrf) {
22902
- combined = (fused?.get(e.key) ?? 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost;
22964
+ combined = (fused?.get(e.key) ?? 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost + evBoost;
22903
22965
  } else {
22904
- combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost;
22966
+ combined = bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift + sessionBias + langBoost + folderBoost + warningBoost + impBoost + evBoost;
22905
22967
  }
22906
22968
  return { entry: e, score: combined, matchesQuery, priority: e.priority, bm25Score };
22907
22969
  }).filter((x) => x.score > 0 || x.matchesQuery).sort((a, b2) => {
@@ -22995,6 +23057,7 @@ var init_quality = __esm({
22995
23057
  init_utils();
22996
23058
  init_synonyms();
22997
23059
  init_fuzzy();
23060
+ init_evidence();
22998
23061
  }
22999
23062
  });
23000
23063
 
@@ -23013,7 +23076,7 @@ __export(sessions_exports, {
23013
23076
  pruneSessions: () => pruneSessions,
23014
23077
  resolveSessionId: () => resolveSessionId
23015
23078
  });
23016
- import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync4, readdirSync, unlinkSync as unlinkSync2, statSync as statSync2 } from "fs";
23079
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync4, readdirSync, unlinkSync as unlinkSync2, statSync as statSync2 } from "fs";
23017
23080
  import { join as join2 } from "path";
23018
23081
  function isAlive2(pid) {
23019
23082
  if (!pid || pid <= 0) return false;
@@ -23032,7 +23095,7 @@ function sessionPath(id2) {
23032
23095
  }
23033
23096
  function ensureSessionDir() {
23034
23097
  const dir = sessionDir();
23035
- if (!existsSync5(dir)) mkdirSync2(dir, { recursive: true });
23098
+ if (!existsSync7(dir)) mkdirSync2(dir, { recursive: true });
23036
23099
  }
23037
23100
  function resolveSessionId(payload = {}) {
23038
23101
  const fromPayload = payload.session_id || payload.sessionId || payload.session_id_untruncated;
@@ -23048,7 +23111,7 @@ function currentBranch() {
23048
23111
  }
23049
23112
  try {
23050
23113
  let gitDir2 = join2(process.cwd(), ".git");
23051
- if (existsSync5(gitDir2) && !statSync2(gitDir2).isDirectory()) {
23114
+ if (existsSync7(gitDir2) && !statSync2(gitDir2).isDirectory()) {
23052
23115
  const pointer = readFileSync5(gitDir2, "utf-8").trim();
23053
23116
  if (pointer.startsWith("gitdir:")) {
23054
23117
  const target = pointer.slice(7).trim();
@@ -23056,7 +23119,7 @@ function currentBranch() {
23056
23119
  }
23057
23120
  }
23058
23121
  const headPath = join2(gitDir2, "HEAD");
23059
- if (!existsSync5(headPath)) return "unknown";
23122
+ if (!existsSync7(headPath)) return "unknown";
23060
23123
  const head = readFileSync5(headPath, "utf-8").trim();
23061
23124
  if (head.startsWith("ref:")) {
23062
23125
  const ref = head.slice(4).trim();
@@ -23070,7 +23133,7 @@ function currentBranch() {
23070
23133
  }
23071
23134
  function readRecord(id2) {
23072
23135
  const p2 = sessionPath(id2);
23073
- if (!existsSync5(p2)) return null;
23136
+ if (!existsSync7(p2)) return null;
23074
23137
  try {
23075
23138
  return JSON.parse(readFileSync5(p2, "utf-8"));
23076
23139
  } catch {
@@ -23105,7 +23168,7 @@ function recentIso(iso) {
23105
23168
  }
23106
23169
  function listSessions() {
23107
23170
  const dir = sessionDir();
23108
- if (!existsSync5(dir)) return [];
23171
+ if (!existsSync7(dir)) return [];
23109
23172
  return readdirSync(dir).filter((f3) => f3.endsWith(".json")).map((f3) => {
23110
23173
  try {
23111
23174
  return JSON.parse(readFileSync5(join2(dir, f3), "utf-8"));
@@ -23121,7 +23184,7 @@ function listSessions() {
23121
23184
  function pruneSessions() {
23122
23185
  const pruned = [];
23123
23186
  const dir = sessionDir();
23124
- if (!existsSync5(dir)) return pruned;
23187
+ if (!existsSync7(dir)) return pruned;
23125
23188
  for (const f3 of readdirSync(dir).filter((x) => x.endsWith(".json"))) {
23126
23189
  const p2 = join2(dir, f3);
23127
23190
  let rec = null;
@@ -32865,8 +32928,8 @@ function N3(Z, $2, J2, X2, V2) {
32865
32928
  }
32866
32929
 
32867
32930
  // src/mcp/tools.ts
32868
- import { readFileSync as readFileSync10, writeFileSync as writeFileSync5, existsSync as existsSync10, copyFileSync, mkdirSync as mkdirSync3, readdirSync as readdirSync5 } from "fs";
32869
- import { join as join7, basename } from "path";
32931
+ import { readFileSync as readFileSync10, writeFileSync as writeFileSync5, existsSync as existsSync12, copyFileSync, mkdirSync as mkdirSync3, readdirSync as readdirSync5 } from "fs";
32932
+ import { join as join7, basename, dirname } from "path";
32870
32933
 
32871
32934
  // src/lib/lock.ts
32872
32935
  import { openSync, closeSync, writeFileSync, readFileSync, unlinkSync, existsSync, statSync, renameSync } from "fs";
@@ -32965,10 +33028,13 @@ function readUnderLock(file2, encoding = "utf-8") {
32965
33028
  // src/mcp/config.ts
32966
33029
  import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync as existsSync2, mkdirSync } from "fs";
32967
33030
  import { join } from "path";
33031
+ import { homedir } from "os";
32968
33032
  var MEMORY_DIR = join(process.cwd(), ".toon-memory", "memory");
32969
33033
  var MEMORY_FILE = join(MEMORY_DIR, "data.toon");
32970
33034
  var ARCHIVE_FILE = join(MEMORY_DIR, "archive.toon");
32971
33035
  var OBSERVATIONS_FILE = join(MEMORY_DIR, "observations.toon");
33036
+ var SECRETS_FILE = join(MEMORY_DIR, "secrets.toon");
33037
+ var GLOBAL_FILE = process.env.TOON_MEMORY_GLOBAL_FILE || join(homedir(), ".toon-memory", "memory", "global.toon");
32972
33038
  var CONFIG_FILE = join(MEMORY_DIR, "config.json");
32973
33039
  function getMaxEntries() {
32974
33040
  const config2 = loadConfig();
@@ -33218,10 +33284,16 @@ function readObservations() {
33218
33284
  // src/mcp/archive.ts
33219
33285
  import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
33220
33286
  init_utils();
33287
+ function findHeaderIdx(lines) {
33288
+ return lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l));
33289
+ }
33290
+ function bumpHeaderCount(line, count) {
33291
+ return line.replace(/^([a-z]+)?\[(\d+)\|/, (_m2, pre) => `${pre || ""}[${count}|`);
33292
+ }
33221
33293
  function archiveOldEntries(opts = {}) {
33222
33294
  const data = readMemory();
33223
33295
  const lines = data.split("\n");
33224
- const headerIdx = lines.findIndex((l) => l.startsWith("entries["));
33296
+ const headerIdx = findHeaderIdx(lines);
33225
33297
  if (headerIdx === -1) return { archived: 0, kept: 0 };
33226
33298
  const today = /* @__PURE__ */ new Date();
33227
33299
  const cutoff = new Date(today);
@@ -33262,14 +33334,14 @@ archived:
33262
33334
  archiveLines.push(`archived[0|]{id|category|key|content|file|tags|date|ttl|accessed|links|quality|confidence}:`);
33263
33335
  archiveHeaderIdx = archiveLines.length - 1;
33264
33336
  }
33265
- const archiveMatch = archiveLines[archiveHeaderIdx].match(/archived\[(\d+)\|/);
33337
+ const archiveMatch = archiveLines[archiveHeaderIdx].match(/\[(\d+)\|/);
33266
33338
  const archiveCount = archiveMatch ? parseInt(archiveMatch[1]) : 0;
33267
33339
  for (const entry of toArchiveLines) {
33268
33340
  archiveLines.splice(archiveHeaderIdx + 1, 0, ` ${entry}`);
33269
33341
  }
33270
- archiveLines[archiveHeaderIdx] = archiveLines[archiveHeaderIdx].replace(/archived\[\d+\|/, `[${archiveCount + toArchiveLines.length}|`);
33342
+ archiveLines[archiveHeaderIdx] = bumpHeaderCount(archiveLines[archiveHeaderIdx], archiveCount + toArchiveLines.length);
33271
33343
  safeWrite(ARCHIVE_FILE, archiveLines.join("\n"));
33272
- lines[headerIdx] = lines[headerIdx].replace(/entries\[\d+\|/, `[${toKeepLines.length}|`);
33344
+ lines[headerIdx] = bumpHeaderCount(lines[headerIdx], toKeepLines.length);
33273
33345
  const keepSet = new Set(toKeepLines);
33274
33346
  const allEntryLines = lines.slice(headerIdx + 1);
33275
33347
  const newEntryLines = allEntryLines.filter((l) => {
@@ -33287,7 +33359,7 @@ function pruneExpiredEntries() {
33287
33359
  withLockSync(MEMORY_FILE, () => {
33288
33360
  const data = readMemory();
33289
33361
  const lines = data.split("\n");
33290
- const headerIdx = lines.findIndex((l) => l.startsWith("entries["));
33362
+ const headerIdx = findHeaderIdx(lines);
33291
33363
  if (headerIdx === -1) return;
33292
33364
  const entryLines2 = lines.slice(headerIdx + 1).filter((l) => l.trim().length > 0 && !l.startsWith(" summaries:"));
33293
33365
  const kept = entryLines2.filter((l) => {
@@ -33301,7 +33373,7 @@ function pruneExpiredEntries() {
33301
33373
  return true;
33302
33374
  });
33303
33375
  if (pruned === 0) return;
33304
- lines[headerIdx] = lines[headerIdx].replace(/entries\[\d+\|/, `[${kept.length}|`);
33376
+ lines[headerIdx] = bumpHeaderCount(lines[headerIdx], kept.length);
33305
33377
  const keepSet = new Set(kept.map((l) => l.trim()));
33306
33378
  const allEntryLines = lines.slice(headerIdx + 1);
33307
33379
  const newLines = allEntryLines.filter((l) => l.trim().length === 0 || keepSet.has(l.trim()));
@@ -33397,6 +33469,48 @@ function consolidateEntries() {
33397
33469
  writeMemory(lines.join("\n"));
33398
33470
  return { removed: totalRemoved, kept: order.length, duplicates };
33399
33471
  }
33472
+ function mergeMemoryFiles(localData, incomingData) {
33473
+ const isEntry = (l) => l.startsWith(" ") && l.includes("|") && !l.startsWith(" summaries:");
33474
+ const localLines = localData.split("\n");
33475
+ const headerIdx = localLines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l));
33476
+ let prefix;
33477
+ let summaries;
33478
+ let localEntryLines;
33479
+ if (headerIdx === -1) {
33480
+ prefix = ["version: 1"];
33481
+ summaries = [];
33482
+ localEntryLines = [];
33483
+ } else {
33484
+ prefix = localLines.slice(0, headerIdx);
33485
+ const body = localLines.slice(headerIdx + 1);
33486
+ localEntryLines = body.filter(isEntry);
33487
+ summaries = body.filter((l) => !isEntry(l));
33488
+ }
33489
+ const merged = /* @__PURE__ */ new Map();
33490
+ for (const line of localEntryLines) {
33491
+ const parts = parseToonLine(line);
33492
+ if (parts.length >= 3) merged.set(parts[2], line.trim());
33493
+ }
33494
+ let added = 0;
33495
+ let updated = 0;
33496
+ for (const line of incomingData.split("\n").filter(isEntry)) {
33497
+ const parts = parseToonLine(line);
33498
+ if (parts.length < 3) continue;
33499
+ const key = parts[2];
33500
+ const existing = merged.get(key);
33501
+ if (existing === void 0) {
33502
+ merged.set(key, line.trim());
33503
+ added++;
33504
+ } else {
33505
+ merged.set(key, mergeEntries(existing, line.trim()));
33506
+ updated++;
33507
+ }
33508
+ }
33509
+ const header = `[${merged.size}|]{id|category|key|content|file|tags|date|ttl|accessed|links|quality|confidence|lastAccessed}:`;
33510
+ const indented = [...merged.values()].map((l) => l.startsWith(" ") ? l : ` ${l}`);
33511
+ const data = [...prefix, header, ...indented, ...summaries].join("\n");
33512
+ return { data, added, updated };
33513
+ }
33400
33514
  function extractVersion(text) {
33401
33515
  const m3 = text.match(/([A-Za-z][A-Za-z0-9._-]*?)\s*(?:v)?(\d+)\.(\d+)(?:\.(\d+))?/);
33402
33516
  if (!m3) return null;
@@ -33465,6 +33579,121 @@ function consolidateVersions(dryRun) {
33465
33579
  return { removed: changed, proposals: groups.map((g) => `Replace ${g.losers.join(", ")} by ${g.winner}`), groups };
33466
33580
  }
33467
33581
 
33582
+ // src/mcp/vault.ts
33583
+ import { existsSync as existsSync6 } from "fs";
33584
+ init_utils();
33585
+ function vaultKey() {
33586
+ const key = getKey();
33587
+ if (!key) {
33588
+ throw new Error(
33589
+ `TOON_MEMORY_KEY is not set \u2014 the secrets vault needs it.
33590
+ export TOON_MEMORY_KEY=<64-hex-char-key>
33591
+ (generate one with: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))")`
33592
+ );
33593
+ }
33594
+ return key;
33595
+ }
33596
+ function readVault() {
33597
+ if (!existsSync6(SECRETS_FILE)) return "";
33598
+ const key = vaultKey();
33599
+ const raw = readUnderLock(SECRETS_FILE);
33600
+ try {
33601
+ return decrypt(raw, key);
33602
+ } catch {
33603
+ throw new Error("Failed to decrypt secrets.toon \u2014 wrong TOON_MEMORY_KEY or corrupted vault.");
33604
+ }
33605
+ }
33606
+ function writeVault(content) {
33607
+ const key = vaultKey();
33608
+ safeWrite(SECRETS_FILE, encrypt(content, key));
33609
+ }
33610
+ function vaultEntries(content) {
33611
+ const out = [];
33612
+ for (const line of content.split("\n")) {
33613
+ if (!line.startsWith(" ") || !line.includes("|")) continue;
33614
+ const parts = parseToonLine(line);
33615
+ if (parts.length < 7) continue;
33616
+ out.push({ id: parts[0], key: parts[2], value: parts[3] || "", file: parts[4] || "", tags: parts[5] || "", date: parts[6] || "", ttl: parts[7] || "" });
33617
+ }
33618
+ return out;
33619
+ }
33620
+ function rebuildVault(list) {
33621
+ const lines = [
33622
+ "version: 1",
33623
+ `[${list.length}|]{id|category|key|content|file|tags|date|ttl|accessed|links}:`,
33624
+ ...list.map(
33625
+ (s2) => toToonLine([s2.id, "secret", s2.key, s2.value, s2.file, s2.tags, s2.date, s2.ttl, "0", ""])
33626
+ )
33627
+ ];
33628
+ return lines.join("\n");
33629
+ }
33630
+ function storeSecret(key, value, opts = {}) {
33631
+ if (!value) throw new Error("A secret needs a non-empty value.");
33632
+ const vk2 = vaultKey();
33633
+ const encrypted = encrypt(value, vk2);
33634
+ const content = readVault();
33635
+ const list = vaultEntries(content);
33636
+ const date5 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
33637
+ const resolvedTtl = parseTTL(opts.ttl || "");
33638
+ const existing = list.find((s2) => s2.key === key);
33639
+ const id2 = existing ? existing.id : generateId();
33640
+ const merged = [];
33641
+ for (const s2 of list) {
33642
+ if (s2.key === key) {
33643
+ merged.push({ id: id2, key, value: encrypted, file: opts.file || s2.file, tags: opts.tags || s2.tags, date: date5, ttl: resolvedTtl || s2.ttl });
33644
+ } else {
33645
+ merged.push(s2);
33646
+ }
33647
+ }
33648
+ if (!existing) {
33649
+ merged.push({ id: id2, key, value: encrypted, file: opts.file || "", tags: opts.tags || "", date: date5, ttl: resolvedTtl });
33650
+ }
33651
+ writeVault(rebuildVault(merged));
33652
+ return { id: id2, date: date5 };
33653
+ }
33654
+ function getSecret(key) {
33655
+ const content = readVault();
33656
+ if (!content) return null;
33657
+ const hit = vaultEntries(content).find((s2) => s2.key === key);
33658
+ if (!hit) return null;
33659
+ const vk2 = vaultKey();
33660
+ let value;
33661
+ try {
33662
+ value = decrypt(hit.value, vk2);
33663
+ } catch {
33664
+ throw new Error(`Failed to decrypt secret "${key}" \u2014 wrong TOON_MEMORY_KEY or corrupted value.`);
33665
+ }
33666
+ return {
33667
+ key,
33668
+ value,
33669
+ file: hit.file,
33670
+ tags: hit.tags.split(";").map((t) => t.trim()).filter(Boolean),
33671
+ date: hit.date,
33672
+ ttl: hit.ttl
33673
+ };
33674
+ }
33675
+ function listSecrets() {
33676
+ const content = readVault();
33677
+ if (!content) return [];
33678
+ return vaultEntries(content).map((s2) => ({
33679
+ id: s2.id,
33680
+ key: s2.key,
33681
+ file: s2.file,
33682
+ tags: s2.tags.split(";").map((t) => t.trim()).filter(Boolean),
33683
+ date: s2.date,
33684
+ ttl: s2.ttl
33685
+ }));
33686
+ }
33687
+ function forgetSecret(key) {
33688
+ const content = readVault();
33689
+ if (!content) return false;
33690
+ const list = vaultEntries(content);
33691
+ const next = list.filter((s2) => s2.key !== key);
33692
+ if (next.length === list.length) return false;
33693
+ writeVault(rebuildVault(next));
33694
+ return true;
33695
+ }
33696
+
33468
33697
  // src/mcp/tools.ts
33469
33698
  init_graph();
33470
33699
  init_quality();
@@ -33474,18 +33703,18 @@ init_graph();
33474
33703
  init_utils();
33475
33704
  init_synonyms();
33476
33705
  init_fuzzy();
33477
- import { existsSync as existsSync9 } from "fs";
33706
+ import { existsSync as existsSync11 } from "fs";
33478
33707
  import { join as join6 } from "path";
33479
33708
  init_sessions();
33480
33709
 
33481
33710
  // src/lib/git.ts
33482
33711
  init_sessions();
33483
- import { existsSync as existsSync6, readFileSync as readFileSync6, statSync as statSync3 } from "fs";
33712
+ import { existsSync as existsSync8, readFileSync as readFileSync6, statSync as statSync3 } from "fs";
33484
33713
  import { join as join3 } from "path";
33485
33714
  import { inflateSync } from "zlib";
33486
33715
  function gitDir(cwd) {
33487
33716
  const dotgit = join3(cwd || process.cwd(), ".git");
33488
- if (!existsSync6(dotgit)) return null;
33717
+ if (!existsSync8(dotgit)) return null;
33489
33718
  if (statSync3(dotgit).isDirectory()) return dotgit;
33490
33719
  const pointer = readFileSync6(dotgit, "utf-8").trim();
33491
33720
  if (pointer.startsWith("gitdir:")) {
@@ -33498,18 +33727,18 @@ function resolveHead(cwd) {
33498
33727
  const dir = gitDir(cwd);
33499
33728
  if (!dir) return null;
33500
33729
  const headPath = join3(dir, "HEAD");
33501
- if (!existsSync6(headPath)) return null;
33730
+ if (!existsSync8(headPath)) return null;
33502
33731
  const head = readFileSync6(headPath, "utf-8").trim();
33503
33732
  if (head.startsWith("ref:")) {
33504
33733
  const refPath = join3(dir, head.slice(4).trim());
33505
- if (!existsSync6(refPath)) return null;
33734
+ if (!existsSync8(refPath)) return null;
33506
33735
  return readFileSync6(refPath, "utf-8").trim();
33507
33736
  }
33508
33737
  return head || null;
33509
33738
  }
33510
33739
  function parseIndex(dir) {
33511
33740
  const indexPath = join3(dir, "index");
33512
- if (!existsSync6(indexPath)) return [];
33741
+ if (!existsSync8(indexPath)) return [];
33513
33742
  const buf = readFileSync6(indexPath);
33514
33743
  if (buf.length < 12) return [];
33515
33744
  const sig = buf.toString("ascii", 0, 4);
@@ -33571,7 +33800,7 @@ function readObject(sha, cwd) {
33571
33800
  const dir = gitDir(cwd);
33572
33801
  if (!dir) return null;
33573
33802
  const objPath = join3(dir, "objects", sha.slice(0, 2), sha.slice(2));
33574
- if (!existsSync6(objPath)) return null;
33803
+ if (!existsSync8(objPath)) return null;
33575
33804
  try {
33576
33805
  const compressed = readFileSync6(objPath);
33577
33806
  const decompressed = inflateSync(compressed);
@@ -33635,12 +33864,12 @@ function gitStatusSummary(cwd) {
33635
33864
  const head = resolveHead(cwd);
33636
33865
  const trackedFiles = readGitIndex(cwd).length;
33637
33866
  const recentCommits = readRecentCommits(5, cwd);
33638
- const hasGitignore = existsSync6(join3(cwd || process.cwd(), ".gitignore"));
33867
+ const hasGitignore = existsSync8(join3(cwd || process.cwd(), ".gitignore"));
33639
33868
  return { branch, head, trackedFiles, recentCommits, hasGitignore };
33640
33869
  }
33641
33870
 
33642
33871
  // src/lib/project-scan.ts
33643
- import { existsSync as existsSync7, readFileSync as readFileSync7, readdirSync as readdirSync3, statSync as statSync4 } from "fs";
33872
+ import { existsSync as existsSync9, readFileSync as readFileSync7, readdirSync as readdirSync3, statSync as statSync4 } from "fs";
33644
33873
  import { join as join4, extname } from "path";
33645
33874
  var SKIP_DIRS = /* @__PURE__ */ new Set([
33646
33875
  "node_modules",
@@ -33698,7 +33927,7 @@ function readEnvExample(root) {
33698
33927
  const candidates = [".env.example", ".env.template", ".env.sample"];
33699
33928
  for (const name of candidates) {
33700
33929
  const p2 = join4(root, name);
33701
- if (existsSync7(p2)) {
33930
+ if (existsSync9(p2)) {
33702
33931
  try {
33703
33932
  const content = readFileSync7(p2, "utf-8");
33704
33933
  return parseEnvContent(content);
@@ -33727,7 +33956,7 @@ function parseEnvContent(content) {
33727
33956
  }
33728
33957
  function readManifest(root) {
33729
33958
  const pkgPath = join4(root, "package.json");
33730
- if (existsSync7(pkgPath)) {
33959
+ if (existsSync9(pkgPath)) {
33731
33960
  try {
33732
33961
  const pkg = JSON.parse(readFileSync7(pkgPath, "utf-8"));
33733
33962
  return {
@@ -33743,7 +33972,7 @@ function readManifest(root) {
33743
33972
  }
33744
33973
  }
33745
33974
  const cargoPath = join4(root, "Cargo.toml");
33746
- if (existsSync7(cargoPath)) {
33975
+ if (existsSync9(cargoPath)) {
33747
33976
  try {
33748
33977
  const txt = readFileSync7(cargoPath, "utf-8");
33749
33978
  const nameMatch = txt.match(/^name\s*=\s*"([^"]+)"/m);
@@ -33763,7 +33992,7 @@ function readManifest(root) {
33763
33992
  }
33764
33993
  }
33765
33994
  const pyPath = join4(root, "pyproject.toml");
33766
- if (existsSync7(pyPath)) {
33995
+ if (existsSync9(pyPath)) {
33767
33996
  try {
33768
33997
  const txt = readFileSync7(pyPath, "utf-8");
33769
33998
  const nameMatch = txt.match(/^name\s*=\s*"([^"]+)"/m);
@@ -33781,7 +34010,7 @@ function readManifest(root) {
33781
34010
  }
33782
34011
  }
33783
34012
  const goPath = join4(root, "go.mod");
33784
- if (existsSync7(goPath)) {
34013
+ if (existsSync9(goPath)) {
33785
34014
  try {
33786
34015
  const txt = readFileSync7(goPath, "utf-8");
33787
34016
  const moduleMatch = txt.match(/^module\s+(.+)$/m);
@@ -34275,7 +34504,7 @@ function generateContextHealth(data, root) {
34275
34504
  for (const e of entries) {
34276
34505
  if (e.file) {
34277
34506
  const filePath = e.file.split(":")[0];
34278
- if (filePath && !existsSync9(join6(root, filePath))) {
34507
+ if (filePath && !existsSync11(join6(root, filePath))) {
34279
34508
  brokenFiles.push(`${e.key}: ${e.file}`);
34280
34509
  }
34281
34510
  }
@@ -34422,6 +34651,7 @@ _${e.date}${tags}${file2}${links}_`);
34422
34651
  // src/mcp/tools.ts
34423
34652
  init_sessions();
34424
34653
  init_utils();
34654
+ init_evidence();
34425
34655
  init_synonyms();
34426
34656
  function registerTools(server2) {
34427
34657
  function softDelete(key) {
@@ -34847,7 +35077,16 @@ ${mergeActions.join("\n")}`
34847
35077
  const resolvedTags = tags ? tags : verbatim ? "" : inferTags(content, key, config2.vocab);
34848
35078
  const existingParts = existingIdx !== -1 ? parseToonLine(lines[existingIdx]) : [];
34849
35079
  const resolvedLinks = links ? links.split(/[\s;]+/).filter(Boolean).join(" ") : existingParts[9] || "";
34850
- let newEntry = toToonLine([entryId, category, key, content, file2 || "", resolvedTags, date5, resolvedTtl, "0", resolvedLinks, "", "", "", "0", path_scope || "", origin, "", "", importance2]);
35080
+ const tagList = resolvedTags.split(";").map((t) => t.trim()).filter(Boolean);
35081
+ const candidate = { key, content, category, tags: tagList };
35082
+ const existingEntries = parseEntries(data);
35083
+ const conflicts = detectContradictions(existingEntries, candidate);
35084
+ const evidence = evidenceFor(
35085
+ existingEntries,
35086
+ candidate,
35087
+ file2 || ""
35088
+ );
35089
+ let newEntry = toToonLine([entryId, category, key, content, file2 || "", resolvedTags, date5, resolvedTtl, "0", resolvedLinks, "", "", "", "0", path_scope || "", origin, "", "", importance2, evidence]);
34851
35090
  let action = "Saved";
34852
35091
  let mergeInfo = "";
34853
35092
  const tagsInferred = !tags && resolvedTags ? true : false;
@@ -34861,7 +35100,7 @@ ${mergeActions.join("\n")}`
34861
35100
  const lastAccessed = "";
34862
35101
  const quality = verbatim ? 0.5 : qualityScore(resolvedTags, resolvedLinks, content, date5, accessed, lastAccessed, origin);
34863
35102
  const confidence = 1;
34864
- newEntry = toToonLine([entryId, category, key, content, file2 || "", resolvedTags, date5, resolvedTtl, String(accessed), resolvedLinks, quality.toFixed(2), String(confidence), lastAccessed, "0", path_scope || "", origin, "active", "", importance2]);
35103
+ newEntry = toToonLine([entryId, category, key, content, file2 || "", resolvedTags, date5, resolvedTtl, String(accessed), resolvedLinks, quality.toFixed(2), String(confidence), lastAccessed, "0", path_scope || "", origin, "active", "", importance2, evidence]);
34865
35104
  const match = lines[headerIdx].match(/\[(\d+)\|/);
34866
35105
  const count = match ? parseInt(match[1]) : 0;
34867
35106
  lines.splice(headerIdx + 1, 0, newEntry);
@@ -34882,6 +35121,17 @@ ${mergeActions.join("\n")}`
34882
35121
  \u23F0 TTL: ${resolvedTtl}` : "";
34883
35122
  const inferredMsg = tagsInferred ? `
34884
35123
  \u{1F3F7}\uFE0F Inferred tags: ${resolvedTags}` : "";
35124
+ const evidenceMsg = evidence ? `
35125
+ \u{1F50E} Evidence: ${evidence}` : "";
35126
+ let conflictMsg = "";
35127
+ if (conflicts.length > 0) {
35128
+ const items = conflicts.map((c2) => ` \u26A0\uFE0F [${c2.category}] ${c2.key} (${c2.similarity}% overlap) \u2014 ${c2.note}`).join("\n");
35129
+ conflictMsg = `
35130
+
35131
+ \u26A0\uFE0F Potential CONTRADICTION with existing memory:
35132
+ ${items}
35133
+ \u2192 The new claim was saved but flagged (evidence: conflict). Re-check before trusting it over the existing entry.`;
35134
+ }
34885
35135
  const related = findRelatedEntries(`${key} ${content} ${resolvedTags}`, key, 3);
34886
35136
  let relatedMsg = "";
34887
35137
  if (related.length > 0) {
@@ -34893,7 +35143,7 @@ ${items}`;
34893
35143
  }
34894
35144
  return {
34895
35145
  content: [{ type: "text", text: `\u{1F9E0} ${action}: ${category}/${key} (${entryId})
34896
- ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${relatedMsg}` }]
35146
+ ${content}${ttlMsg}${inferredMsg}${archiveMsg}${mergeInfo}${evidenceMsg}${conflictMsg}${relatedMsg}` }]
34897
35147
  };
34898
35148
  }
34899
35149
  );
@@ -35390,6 +35640,74 @@ ${formatted}` }] };
35390
35640
  }
35391
35641
  }
35392
35642
  );
35643
+ server2.registerTool(
35644
+ "memory_secret",
35645
+ {
35646
+ title: "Encrypted Secrets Vault",
35647
+ description: "Store/retrieve secrets in the encrypted sidecar vault (secrets.toon, AES-256-GCM). Keeps data.toon readable and open while sensitive values stay encrypted at rest. Requires TOON_MEMORY_KEY. 'store' encrypts, 'get' decrypts, 'list' shows metadata only (no values), 'forget' removes.",
35648
+ inputSchema: {
35649
+ action: external_exports.enum(["store", "get", "list", "forget"]).describe("store = encrypt + save; get = decrypt + return; list = metadata only; forget = remove."),
35650
+ key: external_exports.string().optional().describe("Secret identifier (kebab-case). Required for store/get/forget."),
35651
+ value: external_exports.string().optional().describe("The secret value to encrypt (store only)."),
35652
+ file: external_exports.string().optional().default("").describe("Optional related file/line (e.g. .env, src/api.ts:40)."),
35653
+ tags: external_exports.string().optional().default("").describe("Semicolon-separated metadata tags (e.g. api;token)."),
35654
+ ttl: external_exports.string().optional().default("").describe("Time to live (e.g. 7d, 2026-07-17). Empty = no expiration.")
35655
+ },
35656
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
35657
+ },
35658
+ async ({ action, key, value, file: file2, tags, ttl }) => {
35659
+ try {
35660
+ if (action === "store") {
35661
+ if (!key || !value) {
35662
+ return { content: [{ type: "text", text: "\u274C 'store' needs both key and value." }] };
35663
+ }
35664
+ const { id: id2, date: date5 } = storeSecret(key, value, { file: file2 || "", tags: tags || "", ttl: ttl || "" });
35665
+ const ref = ` Reference it from memory with: memory_remember(category: "knowledge", key: "${key}", content: "Stored in secrets vault", file: "${file2 || "secrets.toon"}", tags: "secret;vault")`;
35666
+ return {
35667
+ content: [{ type: "text", text: `\u{1F510} Stored secret "${key}" (${id2}) on ${date5}
35668
+ Value is AES-256-GCM encrypted at rest in secrets.toon.
35669
+ ${ref}` }]
35670
+ };
35671
+ }
35672
+ if (action === "get") {
35673
+ if (!key) return { content: [{ type: "text", text: "\u274C 'get' needs a key." }] };
35674
+ const hit = getSecret(key);
35675
+ if (!hit) {
35676
+ return { content: [{ type: "text", text: `\u274C No secret "${key}" in the vault. Run memory_secret(action: "list") to see stored keys.` }] };
35677
+ }
35678
+ const meta3 = `Secret: ${key} \xB7 file: ${hit.file || "\u2014"} \xB7 tags: ${hit.tags.join(";") || "\u2014"} \xB7 date: ${hit.date}${hit.ttl ? ` \xB7 ttl: ${hit.ttl}` : ""}`;
35679
+ return {
35680
+ content: [{ type: "text", text: `${meta3}
35681
+
35682
+ ${hit.value}` }]
35683
+ };
35684
+ }
35685
+ if (action === "list") {
35686
+ const list = listSecrets();
35687
+ if (list.length === 0) {
35688
+ return { content: [{ type: "text", text: "\u{1F510} Vault is empty." }] };
35689
+ }
35690
+ const rows = list.map((s2) => ` \xB7 ${s2.key}${s2.file ? ` (${s2.file})` : ""} \u2014 saved ${s2.date}${s2.ttl ? ` \xB7 ttl ${s2.ttl}` : ""} [${s2.id}]`).join("\n");
35691
+ return {
35692
+ content: [{ type: "text", text: `\u{1F510} ${list.length} secret(s) in vault (values stay encrypted):
35693
+ ${rows}
35694
+
35695
+ Get a value with memory_secret(action: "get", key: "<key>")` }]
35696
+ };
35697
+ }
35698
+ if (action === "forget") {
35699
+ if (!key) return { content: [{ type: "text", text: "\u274C 'forget' needs a key." }] };
35700
+ const removed = forgetSecret(key);
35701
+ return {
35702
+ content: [{ type: "text", text: removed ? `\u{1F5D1}\uFE0F Removed secret "${key}" from the vault.` : `\u274C No secret "${key}" in the vault.` }]
35703
+ };
35704
+ }
35705
+ return { content: [{ type: "text", text: "\u274C Unknown action." }] };
35706
+ } catch (err) {
35707
+ return { content: [{ type: "text", text: `\u274C ${err instanceof Error ? err.message : String(err)}` }] };
35708
+ }
35709
+ }
35710
+ );
35393
35711
  server2.registerTool(
35394
35712
  "memory_captured",
35395
35713
  {
@@ -35405,7 +35723,7 @@ ${formatted}` }] };
35405
35723
  },
35406
35724
  async ({ limit, tool, file: file2, clear }) => {
35407
35725
  if (clear) {
35408
- if (existsSync10(OBSERVATIONS_FILE)) {
35726
+ if (existsSync12(OBSERVATIONS_FILE)) {
35409
35727
  writeFileSync5(OBSERVATIONS_FILE, "version: 1\nobservations[0|]{ts|session|agent|branch|tool|hash|file|summary}:\n");
35410
35728
  }
35411
35729
  return { content: [{ type: "text", text: "\u{1F9F9} Capture log cleared" }] };
@@ -35629,16 +35947,16 @@ ${files}` : "";
35629
35947
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
35630
35948
  },
35631
35949
  async () => {
35632
- if (!existsSync10(MEMORY_FILE)) {
35950
+ if (!existsSync12(MEMORY_FILE)) {
35633
35951
  return { content: [{ type: "text", text: "No memory file to backup" }] };
35634
35952
  }
35635
35953
  const backupDir = join7(MEMORY_DIR, "backups");
35636
- if (!existsSync10(backupDir)) mkdirSync3(backupDir, { recursive: true });
35954
+ if (!existsSync12(backupDir)) mkdirSync3(backupDir, { recursive: true });
35637
35955
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
35638
35956
  const backupFile = join7(backupDir, `memory-${timestamp}.toon`);
35639
35957
  copyFileSync(MEMORY_FILE, backupFile);
35640
35958
  let archiveBackup = "";
35641
- if (existsSync10(ARCHIVE_FILE)) {
35959
+ if (existsSync12(ARCHIVE_FILE)) {
35642
35960
  const archiveBackupFile = join7(backupDir, `archive-${timestamp}.toon`);
35643
35961
  copyFileSync(ARCHIVE_FILE, archiveBackupFile);
35644
35962
  archiveBackup = `
@@ -35768,7 +36086,7 @@ ${files}` : "";
35768
36086
  }]
35769
36087
  };
35770
36088
  }
35771
- if (!existsSync10(MEMORY_FILE)) {
36089
+ if (!existsSync12(MEMORY_FILE)) {
35772
36090
  return { content: [{ type: "text", text: "No memory file to export." }] };
35773
36091
  }
35774
36092
  const data = readFileSync10(MEMORY_FILE, "utf-8");
@@ -35859,7 +36177,7 @@ To import later: memory_import_gist(gist_id: "${gist.id}")`
35859
36177
  }]
35860
36178
  };
35861
36179
  }
35862
- const localData = existsSync10(MEMORY_FILE) ? readFileSync10(MEMORY_FILE, "utf-8") : "version: 1\nentries[0|]\n";
36180
+ const localData = existsSync12(MEMORY_FILE) ? readFileSync10(MEMORY_FILE, "utf-8") : "version: 1\nentries[0|]\n";
35863
36181
  const localEntries = parseEntries(localData);
35864
36182
  const remoteEntries = parseEntries(remoteData);
35865
36183
  const localByKey = new Map(localEntries.map((e) => [e.key, e]));
@@ -35911,6 +36229,71 @@ To import later: memory_import_gist(gist_id: "${gist.id}")`
35911
36229
  }
35912
36230
  }
35913
36231
  );
36232
+ server2.registerTool(
36233
+ "memory_export_global",
36234
+ {
36235
+ title: "Export to Global Memory",
36236
+ description: "Write the current project memory to the global memory file (~/.toon-memory/memory/global.toon, or TOON_MEMORY_GLOBAL_FILE). One-shot: the global file is a plain TOON document you curate and import into other projects with memory_import_global.",
36237
+ inputSchema: {
36238
+ target: external_exports.string().optional().describe("Override the global file path (defaults to TOON_MEMORY_GLOBAL_FILE or ~/.toon-memory/memory/global.toon).")
36239
+ },
36240
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
36241
+ },
36242
+ async ({ target }) => {
36243
+ const dest = target || GLOBAL_FILE;
36244
+ const data = readMemory();
36245
+ mkdirSync3(dirname(dest), { recursive: true });
36246
+ safeWrite(dest, data);
36247
+ const count = parseEntries(data).length;
36248
+ return {
36249
+ content: [{ type: "text", text: `\u{1F4E4} Exported ${count} entries to global memory:
36250
+ ${dest}
36251
+
36252
+ Import them elsewhere with memory_import_global.` }]
36253
+ };
36254
+ }
36255
+ );
36256
+ server2.registerTool(
36257
+ "memory_import_global",
36258
+ {
36259
+ title: "Import Global Memory",
36260
+ description: "Merge cross-project conventions from the global memory file (~/.toon-memory/memory/global.toon, or TOON_MEMORY_GLOBAL_FILE) into this project. One-shot merge by key: keeps newer dates, unions tags/links, preserves all fields. Deterministic and offline.",
36261
+ inputSchema: {
36262
+ merge: external_exports.boolean().optional().default(true).describe("If true, merge with existing memory (default). If false, replace entirely."),
36263
+ source: external_exports.string().optional().describe("Override the global file path (defaults to TOON_MEMORY_GLOBAL_FILE or ~/.toon-memory/memory/global.toon).")
36264
+ },
36265
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
36266
+ },
36267
+ async ({ merge: merge2, source }) => {
36268
+ const src = source || GLOBAL_FILE;
36269
+ if (!existsSync12(src)) {
36270
+ return {
36271
+ content: [{ type: "text", text: `\u274C No global memory at:
36272
+ ${src}
36273
+
36274
+ Export from another project with memory_export_global, or create the file with a few memory entries first.` }]
36275
+ };
36276
+ }
36277
+ const globalData = readFileSync10(src, "utf-8");
36278
+ if (!merge2) {
36279
+ safeWrite(MEMORY_FILE, globalData);
36280
+ const count = parseEntries(globalData).length;
36281
+ return {
36282
+ content: [{ type: "text", text: `\u{1F4E5} Memory replaced from global (${count} entries).` }]
36283
+ };
36284
+ }
36285
+ const localData = readMemory();
36286
+ const { data, added, updated } = mergeMemoryFiles(localData, globalData);
36287
+ writeMemory(data);
36288
+ const total = parseEntries(data).length;
36289
+ return {
36290
+ content: [{ type: "text", text: `\u{1F4E5} Global memory merged
36291
+ Added: ${added} new entries
36292
+ Updated: ${updated} existing entries
36293
+ Total: ${total} entries` }]
36294
+ };
36295
+ }
36296
+ );
35914
36297
  server2.registerTool(
35915
36298
  "memory_merge_sessions",
35916
36299
  {
@@ -35941,7 +36324,7 @@ To import later: memory_import_gist(gist_id: "${gist.id}")`
35941
36324
  }
35942
36325
  const sharedFiles = [...allFiles.entries()].filter(([_2, sessions2]) => sessions2.length >= 2).sort((a, b2) => b2[1].length - a[1].length);
35943
36326
  let observations = [];
35944
- if (existsSync10(OBSERVATIONS_FILE)) {
36327
+ if (existsSync12(OBSERVATIONS_FILE)) {
35945
36328
  const data = readFileSync10(OBSERVATIONS_FILE, "utf-8");
35946
36329
  const sessionIds = new Set(recentSessions.map((s2) => s2.id));
35947
36330
  observations = data.split("\n").filter((l) => l.startsWith(" ") && l.includes("|")).map((l) => {
@@ -47320,21 +47703,38 @@ function buildViewerData() {
47320
47703
 
47321
47704
  // src/viewer/html.ts
47322
47705
  import { readFileSync as readFileSync11 } from "fs";
47323
- import { resolve, dirname } from "path";
47706
+ import { resolve, dirname as dirname2 } from "path";
47324
47707
  import { fileURLToPath } from "url";
47325
47708
  var d3Src = (() => {
47326
47709
  try {
47327
- const dir = dirname(fileURLToPath(import.meta.url));
47710
+ const dir = dirname2(fileURLToPath(import.meta.url));
47328
47711
  return readFileSync11(resolve(dir, "../src/viewer/d3.v7.min.js"), "utf-8");
47329
47712
  } catch {
47330
47713
  try {
47331
- const dir = dirname(fileURLToPath(import.meta.url));
47714
+ const dir = dirname2(fileURLToPath(import.meta.url));
47332
47715
  return readFileSync11(resolve(dir, "d3.v7.min.js"), "utf-8");
47333
47716
  } catch {
47334
47717
  return null;
47335
47718
  }
47336
47719
  }
47337
47720
  })();
47721
+ function readViewerAsset(name) {
47722
+ const dir = dirname2(fileURLToPath(import.meta.url));
47723
+ const candidates = [
47724
+ resolve(dir, `../src/viewer/${name}`),
47725
+ resolve(dir, `../../src/viewer/${name}`),
47726
+ resolve(dir, name)
47727
+ ];
47728
+ for (const p2 of candidates) {
47729
+ try {
47730
+ return readFileSync11(p2, "utf-8");
47731
+ } catch {
47732
+ }
47733
+ }
47734
+ return "";
47735
+ }
47736
+ var logoSrc = readViewerAsset("logo.svg");
47737
+ var isologoSrc = readViewerAsset("logo-isologo.svg");
47338
47738
  function generateHtml(viewerData) {
47339
47739
  const jsonData = JSON.stringify(viewerData);
47340
47740
  const d3Tag = d3Src ? `<script>${d3Src}</script>` : `<script src="https://d3js.org/d3.v7.min.js"></script>`;
@@ -47349,123 +47749,133 @@ ${d3Tag}
47349
47749
  <style>
47350
47750
  *{box-sizing:border-box;margin:0;padding:0}
47351
47751
  :root{
47352
- --bg:#0a0a0f;--bg2:#12121a;--bg3:#1a1a26;--border:#2a2a3a;
47353
- --text:#e2e2ee;--muted:#8888a0;--brand:#a78bfa;--brand2:#c084fc;
47354
- --green:#22c55e;--red:#ef4444;--blue:#3b82f6;--amber:#f59e0b;
47355
- --pink:#ec4899;--cyan:#06b6d4;
47356
- }
47357
- html,body{height:100%;font-family:system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text);overflow:hidden}
47752
+ --bg:oklch(8% 0.02 270);--bg2:oklch(12% 0.02 270);--bg3:oklch(15% 0.02 270);--border:oklch(21% 0.02 270);
47753
+ --text:oklch(91% 0.01 270);--muted:oklch(56% 0.02 270);
47754
+ --brand:oklch(55% 0.25 280);--brand-light:oklch(68% 0.22 280);--brand2:oklch(59% 0.25 300);--lavender:oklch(65% 0.25 310);--pink:oklch(65% 0.26 340);
47755
+ --green:oklch(78% 0.2 155);--red:oklch(65% 0.24 25);--amber:oklch(85% 0.18 85);
47756
+ --brand-wash:oklch(55% 0.25 280 / 0.12);--brand-wash-soft:oklch(55% 0.25 280 / 0.06);
47757
+ --gradient:linear-gradient(135deg,var(--brand),var(--brand2),var(--lavender));
47758
+ --ease-out:cubic-bezier(0.16,1,0.3,1);
47759
+ --font-body:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;--font-mono:'JetBrains Mono','Fira Code','Consolas',monospace
47760
+ }
47761
+ html,body{height:100%;font-family:var(--font-body);background:var(--bg);color:var(--text);overflow:hidden}
47358
47762
  .app{display:grid;grid-template-rows:auto 1fr;height:100%}
47359
- header{display:flex;align-items:center;justify-content:space-between;padding:0.75rem 1.5rem;border-bottom:1px solid var(--border);background:var(--bg2)}
47360
- header h1{font-size:1.1rem;font-weight:700;background:linear-gradient(135deg,var(--brand),var(--pink));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
47361
- header .meta{display:flex;gap:1rem;font-size:0.8rem;color:var(--muted)}
47763
+ header{display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:0.65rem 1.25rem;border-bottom:1px solid var(--border);background:oklch(8% 0.02 270 / 0.85);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)}
47764
+ .brand{display:flex;align-items:center;gap:0.6rem}
47765
+ .brand-logo{display:flex;line-height:0}
47766
+ .brand-logo svg{width:26px;height:26px}
47767
+ .brand-word{display:flex;line-height:0}
47768
+ .brand-word svg{height:20px;width:auto}
47769
+ header .meta{display:flex;gap:0.6rem;font-size:0.78rem;color:var(--muted);align-items:center}
47362
47770
  header .meta span{display:flex;align-items:center;gap:0.3rem}
47363
47771
  .main{display:grid;grid-template-columns:var(--sidebar-w,320px) 1fr;overflow:hidden;position:relative}
47364
- .sidebar{display:flex;flex-direction:column;border-right:1px solid var(--border);overflow:hidden}
47772
+ .sidebar{display:flex;flex-direction:column;border-right:1px solid var(--border);overflow:hidden;background:oklch(10% 0.02 270 / 0.5)}
47365
47773
  .sidebar-resizer{width:4px;cursor:col-resize;background:transparent;position:absolute;left:var(--sidebar-w,320px);top:0;bottom:0;z-index:5;transition:background 0.15s}
47366
47774
  .sidebar-resizer:hover,.sidebar-resizer:active{background:var(--brand)}
47367
- .sidebar-header{padding:0.75rem 1rem;border-bottom:1px solid var(--border);background:var(--bg2)}
47775
+ .sidebar-header{padding:0.75rem 1rem;border-bottom:1px solid var(--border);background:oklch(8% 0.02 270 / 0.85);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)}
47368
47776
  .sidebar-header h2{font-size:0.85rem;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;color:var(--muted);margin-bottom:0.5rem}
47369
- .search-box{width:100%;padding:0.5rem 0.75rem;border:1px solid var(--border);border-radius:8px;background:var(--bg3);color:var(--text);font-size:0.85rem;outline:none}
47370
- .search-box:focus{border-color:var(--brand)}
47777
+ .search-box{width:100%;padding:0.5rem 0.75rem;border:1px solid var(--border);border-radius:8px;background:var(--bg3);color:var(--text);font-size:0.85rem;outline:none;transition:border-color 0.15s,box-shadow 0.15s}
47778
+ .search-box:focus{border-color:var(--brand);box-shadow:0 0 0 3px oklch(55% 0.25 280 / 0.12)}
47371
47779
  .filter-row{display:flex;gap:0.4rem;margin-top:0.5rem;flex-wrap:wrap}
47372
47780
  .filter-btn{padding:0.2rem 0.5rem;border:1px solid var(--border);border-radius:6px;background:transparent;color:var(--muted);font-size:0.7rem;cursor:pointer;transition:all 0.15s}
47373
- .filter-btn:hover,.filter-btn.active{border-color:var(--brand);color:var(--brand);background:rgba(167,139,250,0.1)}
47781
+ .filter-btn:hover,.filter-btn.active{border-color:var(--brand);color:var(--brand);background:var(--brand-wash)}
47374
47782
  .entries-list{flex:1;overflow-y:auto;padding:0.5rem}
47375
- .entry-item{padding:0.6rem 0.75rem;border:1px solid var(--border);border-radius:8px;margin-bottom:0.4rem;cursor:pointer;transition:all 0.15s}
47376
- .entry-item:hover{border-color:var(--brand);background:rgba(167,139,250,0.05)}
47377
- .entry-item.selected{border-color:var(--brand);background:rgba(167,139,250,0.1)}
47783
+ .entry-item{position:relative;overflow:hidden;padding:0.6rem 0.75rem;border:1px solid var(--border);border-radius:12px;margin-bottom:0.4rem;cursor:pointer;transition:all 0.15s;background:var(--bg2)}
47784
+ .entry-item::before{content:'';position:absolute;top:0;left:0;right:0;height:3px;background:var(--gradient);opacity:0;transform:scaleX(0.5);transition:opacity 0.35s var(--ease-out),transform 0.5s var(--ease-out);border-radius:3px 3px 0 0}
47785
+ .entry-item:hover{transform:translateY(-2px);border-color:oklch(28% 0.02 270);box-shadow:0 10px 30px -12px oklch(0% 0 0 / 0.7)}
47786
+ .entry-item:hover::before{opacity:1;transform:scaleX(1)}
47787
+ .entry-item.selected{border-color:var(--brand);background:var(--brand-wash)}
47788
+ .entry-item.selected::before{opacity:1;transform:scaleX(1)}
47378
47789
  .entry-cat{font-size:0.65rem;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;margin-bottom:0.2rem}
47379
- .entry-cat.decision{color:var(--brand)}
47380
- .entry-cat.bug{color:var(--red)}
47381
- .entry-cat.pattern{color:var(--green)}
47382
- .entry-cat.knowledge{color:var(--cyan)}
47383
- .entry-cat.architecture{color:var(--amber)}
47790
+ .entry-cat.decision{color:var(--brand)}.entry-cat.bug{color:var(--red)}.entry-cat.pattern{color:var(--green)}.entry-cat.knowledge{color:var(--lavender)}.entry-cat.architecture{color:var(--amber)}
47384
47791
  .entry-key{font-size:0.85rem;font-weight:600;margin-bottom:0.15rem}
47385
47792
  .entry-preview{font-size:0.75rem;color:var(--muted);line-height:1.4;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
47386
47793
  .entry-tags{display:flex;gap:0.25rem;margin-top:0.3rem;flex-wrap:wrap}
47387
- .entry-tag{font-size:0.6rem;padding:0.1em 0.35rem;border-radius:3px;background:var(--bg3);color:var(--muted);font-family:monospace}
47794
+ .entry-tag{font-size:0.6rem;padding:0.15em 0.4rem;border-radius:4px;background:oklch(55% 0.25 280 / 0.12);color:var(--brand-light);font-family:var(--font-mono)}
47388
47795
  .viewer-area{display:flex;flex-direction:column;overflow:hidden}
47389
- .tabs{display:flex;border-bottom:1px solid var(--border);background:var(--bg2);padding:0 1rem}
47390
- .tab{padding:0.6rem 1rem;font-size:0.8rem;font-weight:500;color:var(--muted);cursor:pointer;border-bottom:2px solid transparent;transition:all 0.15s}
47796
+ .tabs{display:flex;border-bottom:1px solid var(--border);background:oklch(8% 0.02 270 / 0.85);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);padding:0 1rem}
47797
+ .tab{position:relative;padding:0.65rem 1rem;font-size:0.7rem;font-weight:600;letter-spacing:0.08em;text-transform:uppercase;color:var(--muted);cursor:pointer;transition:color 0.15s}
47391
47798
  .tab:hover{color:var(--text)}
47392
- .tab.active{color:var(--brand);border-bottom-color:var(--brand)}
47799
+ .tab.active{color:var(--text)}
47800
+ .tab.active::after{content:'';position:absolute;left:0.6rem;right:0.6rem;bottom:0;height:2px;border-radius:2px;background:var(--gradient)}
47393
47801
  .tab-content{flex:1;overflow:hidden;position:relative}
47394
47802
  .tab-panel{display:none;width:100%;height:100%;overflow:auto}
47395
47803
  .tab-panel.active{display:block}
47396
47804
  .graph-container{width:100%;height:100%;min-height:300px;background:var(--bg);position:relative}
47397
- .graph-container::before{content:'';position:absolute;inset:0;background-image:radial-gradient(var(--border) 1px,transparent 1px);background-size:24px 24px;opacity:0.3;pointer-events:none;z-index:0}
47805
+ .graph-container::before{content:'';position:absolute;inset:0;background:radial-gradient(ellipse 60% 50% at 50% 0%,oklch(55% 0.25 280 / 0.07) 0%,transparent 70%);pointer-events:none;z-index:0}
47398
47806
  .graph-container svg{width:100%;height:100%;position:relative;z-index:1}
47399
- .node-circle{cursor:pointer;transition:r 0.2s ease,opacity 0.2s ease,filter 0.2s ease,stroke 0.2s ease}
47807
+ .node-circle{cursor:pointer;transition:r 0.2s var(--ease-out),opacity 0.2s var(--ease-out),filter 0.2s var(--ease-out),stroke 0.2s var(--ease-out)}
47400
47808
  .node-circle:hover{filter:brightness(1.3) drop-shadow(0 0 6px color-mix(in srgb,currentColor 60%,transparent))}
47401
47809
  .node-circle.glow{filter:drop-shadow(0 0 12px var(--brand)) brightness(1.5)}
47402
47810
  .node-circle.selected{stroke:var(--brand);stroke-width:3;filter:drop-shadow(0 0 14px var(--brand)) brightness(1.3)}
47403
- .node-label{font-size:9px;font-family:monospace;fill:var(--text);pointer-events:none;text-anchor:middle;transition:opacity 0.2s ease;font-weight:500;letter-spacing:0.02em}
47404
- .link{stroke:var(--border);stroke-opacity:0.4;transition:all 0.2s ease;cursor:pointer}
47811
+ .node-label{font-size:9px;font-family:var(--font-mono);fill:var(--text);pointer-events:none;text-anchor:middle;transition:opacity 0.2s var(--ease-out);font-weight:500;letter-spacing:0.02em}
47812
+ .link{stroke:var(--border);stroke-opacity:0.4;transition:all 0.2s var(--ease-out);cursor:pointer}
47405
47813
  .link:hover{stroke-opacity:0.9;stroke-width:3}
47406
47814
  .link.highlighted{stroke:var(--brand);stroke-opacity:0.9;stroke-width:2.5}
47407
47815
  .link.faded{stroke-opacity:0.04}
47408
47816
  .node-ring{fill:none;stroke-width:2;opacity:0;transition:opacity 0.3s ease,r 0.3s ease}
47409
47817
  .node-ring.visible{opacity:0.6}
47410
47818
  .stats-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:1rem;padding:1.5rem}
47411
- .stat-card{background:var(--bg2);border:1px solid var(--border);border-radius:12px;padding:1.25rem}
47819
+ .stat-card{position:relative;overflow:hidden;background:var(--bg2);border:1px solid var(--border);border-radius:14px;padding:1.25rem;transition:transform 0.3s var(--ease-out),box-shadow 0.3s var(--ease-out),border-color 0.3s}
47820
+ .stat-card::before{content:'';position:absolute;top:0;left:0;right:0;height:3px;background:var(--gradient);opacity:0;transform:scaleX(0.5);transition:opacity 0.35s var(--ease-out),transform 0.5s var(--ease-out)}
47821
+ .stat-card:hover{transform:translateY(-4px);box-shadow:0 18px 40px -16px oklch(0% 0 0 / 0.7),0 0 0 1px oklch(55% 0.25 280 / 0.06)}
47822
+ .stat-card:hover::before{opacity:1;transform:scaleX(1)}
47412
47823
  .stat-card h3{font-size:0.8rem;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;color:var(--muted);margin-bottom:0.75rem}
47413
- .stat-big{font-size:2rem;font-weight:800;background:linear-gradient(135deg,var(--brand),var(--pink));-webkit-background-clip:text;-webkit-text-fill-color:transparent}
47824
+ .stat-big{font-size:2rem;font-weight:800;background:var(--gradient);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;color:transparent}
47414
47825
  .bar-chart{display:flex;flex-direction:column;gap:0.4rem}
47415
47826
  .bar-row{display:flex;align-items:center;gap:0.5rem}
47416
47827
  .bar-label{font-size:0.75rem;color:var(--muted);width:80px;text-align:right;flex-shrink:0}
47417
47828
  .bar-track{flex:1;height:20px;background:var(--bg3);border-radius:4px;overflow:hidden}
47418
- .bar-fill{height:100%;border-radius:4px;transition:width 0.6s cubic-bezier(0.16,1,0.3,1)}
47829
+ .bar-fill{height:100%;border-radius:4px;width:0;transition:width 0.7s var(--ease-out)}
47419
47830
  .bar-value{font-size:0.7rem;color:var(--muted);width:30px}
47420
47831
  .tag-cloud{display:flex;flex-wrap:wrap;gap:0.4rem}
47421
- .tag-pill{padding:0.25rem 0.6rem;border-radius:6px;font-size:0.75rem;font-family:monospace;border:1px solid var(--border);color:var(--muted);transition:all 0.15s}
47832
+ .tag-pill{padding:0.25rem 0.6rem;border-radius:9999px;font-size:0.75rem;font-family:var(--font-mono);border:1px solid var(--border);color:var(--muted);transition:all 0.15s}
47422
47833
  .tag-pill:hover{border-color:var(--brand);color:var(--brand)}
47423
47834
  .detail-panel{padding:1.5rem;max-width:700px}
47424
- .detail-panel h2{font-size:1.2rem;font-weight:700;margin-bottom:0.5rem}
47835
+ .detail-panel h2{font-size:1.2rem;font-weight:800;margin-bottom:0.5rem;background:var(--gradient);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;color:transparent}
47425
47836
  .detail-panel .detail-cat{font-size:0.75rem;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;margin-bottom:1rem}
47426
47837
  .detail-field{margin-bottom:1rem}
47427
47838
  .detail-field label{display:block;font-size:0.75rem;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:0.05em;margin-bottom:0.3rem}
47428
47839
  .detail-field .value{font-size:0.9rem;line-height:1.6}
47429
- .detail-field .value.mono{font-family:monospace;background:var(--bg3);padding:0.5rem;border-radius:6px;display:block;overflow-x:auto;white-space:pre-wrap}
47840
+ .detail-field .value.mono{font-family:var(--font-mono);background:var(--bg3);padding:0.5rem;border-radius:8px;display:block;overflow-x:auto;white-space:pre-wrap}
47430
47841
  .detail-links{display:flex;gap:0.4rem;flex-wrap:wrap}
47431
- .detail-link{padding:0.2rem 0.5rem;border:1px solid var(--border);border-radius:6px;font-size:0.75rem;font-family:monospace;color:var(--brand);cursor:pointer;transition:all 0.15s}
47432
- .detail-link:hover{border-color:var(--brand);background:rgba(167,139,250,0.1)}
47842
+ .detail-link{padding:0.2rem 0.5rem;border:1px solid var(--border);border-radius:9999px;font-size:0.75rem;font-family:var(--font-mono);color:var(--brand-light);background:oklch(55% 0.25 280 / 0.08);cursor:pointer;transition:all 0.15s}
47843
+ .detail-link:hover{border-color:var(--brand);background:var(--brand-wash)}
47433
47844
  .empty-detail{display:flex;align-items:center;justify-content:center;height:100%;color:var(--muted);font-size:0.9rem}
47434
- .graph-legend{position:absolute;bottom:3.5rem;left:0.5rem;background:var(--bg2);border:1px solid var(--border);border-radius:8px;padding:0.75rem;font-size:0.7rem;z-index:10}
47845
+ .graph-legend{position:absolute;bottom:3.5rem;left:0.5rem;background:oklch(11% 0.02 270 / 0.9);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border:1px solid var(--border);border-radius:12px;padding:0.75rem;font-size:0.7rem;z-index:10}
47435
47846
  .legend-item{display:flex;align-items:center;gap:0.4rem;margin-bottom:0.25rem}
47436
47847
  .legend-dot{width:10px;height:10px;border-radius:50%}
47437
47848
  .graph-controls{position:absolute;top:1rem;right:1rem;display:flex;gap:0.4rem;z-index:10}
47438
- .graph-btn{width:32px;height:32px;border:1px solid var(--border);border-radius:6px;background:var(--bg2);color:var(--text);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:1rem;transition:all 0.15s}
47439
- .graph-btn:hover{border-color:var(--brand);color:var(--brand)}
47440
- .tooltip{position:fixed;pointer-events:none;background:rgba(18,18,26,0.92);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border:1px solid var(--border);border-radius:12px;padding:0.75rem 1rem;font-size:0.75rem;max-width:320px;z-index:1000;box-shadow:0 8px 32px rgba(0,0,0,0.5)}
47849
+ .graph-btn{width:32px;height:32px;border:1px solid var(--border);border-radius:8px;background:var(--bg2);color:var(--text);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:1rem;transition:all 0.15s}
47850
+ .graph-btn:hover{border-color:var(--brand);color:var(--brand);background:var(--brand-wash)}
47851
+ .tooltip{position:fixed;pointer-events:none;background:oklch(12% 0.02 270 / 0.92);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border:1px solid var(--border);border-radius:12px;padding:0.75rem 1rem;font-size:0.75rem;max-width:320px;z-index:1000;box-shadow:0 8px 32px rgba(0,0,0,0.5)}
47441
47852
  .tooltip .tt-cat{font-size:0.6rem;font-weight:600;text-transform:uppercase;margin-bottom:0.2rem}
47442
47853
  .tooltip .tt-key{font-weight:600;margin-bottom:0.2rem}
47443
47854
  .tooltip .tt-content{color:var(--muted);line-height:1.4;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
47444
47855
  .tooltip .tt-score{margin-top:0.3rem;font-size:0.65rem;color:var(--brand)}
47445
47856
  .tooltip .tt-edge{font-size:0.65rem;color:var(--muted);margin-top:0.3rem;padding-top:0.3rem;border-top:1px solid var(--border)}
47446
47857
  .timeline-container{padding:1.5rem;overflow-y:auto;height:100%}
47447
- .timeline-header{font-size:1rem;font-weight:700;margin-bottom:1rem;color:var(--text)}
47858
+ .timeline-header{font-size:1rem;font-weight:800;margin-bottom:1rem;background:var(--gradient);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;color:transparent}
47448
47859
  .timeline-track{position:relative;padding-left:2rem}
47449
47860
  .timeline-line{position:absolute;left:0.5rem;top:0;bottom:0;width:2px;background:var(--border)}
47450
- .timeline-entry{position:relative;margin-bottom:1rem;padding:0.6rem 0.8rem;border:1px solid var(--border);border-radius:8px;background:var(--bg2);transition:all 0.15s;cursor:pointer}
47451
- .timeline-entry:hover{border-color:var(--brand)}
47861
+ .timeline-entry{position:relative;margin-bottom:1rem;padding:0.6rem 0.8rem;border:1px solid var(--border);border-radius:12px;background:var(--bg2);transition:all 0.15s;cursor:pointer}
47862
+ .timeline-entry:hover{border-color:var(--brand);transform:translateY(-2px)}
47452
47863
  .timeline-entry::before{content:'';position:absolute;left:-1.75rem;top:0.8rem;width:10px;height:10px;border-radius:50%;border:2px solid var(--border);background:var(--bg)}
47453
47864
  .timeline-entry .tl-date{font-size:0.65rem;color:var(--muted);margin-bottom:0.2rem}
47454
47865
  .timeline-entry .tl-cat{font-size:0.6rem;font-weight:600;text-transform:uppercase}
47455
47866
  .timeline-entry .tl-key{font-size:0.85rem;font-weight:600}
47456
47867
  .timeline-entry .tl-content{font-size:0.75rem;color:var(--muted);margin-top:0.2rem}
47457
- .export-btn{padding:0.3rem 0.6rem;border:1px solid var(--border);border-radius:6px;background:var(--bg2);color:var(--text);font-size:0.7rem;cursor:pointer;transition:all 0.15s}
47868
+ .export-btn{padding:0.3rem 0.6rem;border:1px solid var(--border);border-radius:9999px;background:var(--bg2);color:var(--text);font-size:0.7rem;cursor:pointer;transition:all 0.15s}
47458
47869
  .export-btn:hover{border-color:var(--brand);color:var(--brand)}
47459
47870
  .export-bar{display:flex;gap:0.4rem}
47460
- .theme-toggle{background:none;border:1px solid var(--border);border-radius:6px;padding:0.3rem 0.6rem;color:var(--text);cursor:pointer;font-size:0.8rem;transition:all 0.15s}
47461
- .theme-toggle:hover{border-color:var(--brand);color:var(--brand)}
47462
- .reload-btn{background:none;border:1px solid var(--border);border-radius:6px;padding:0.3rem 0.6rem;color:var(--muted);cursor:pointer;font-size:0.9rem;transition:all 0.15s;line-height:1}
47463
- .reload-btn:hover{border-color:var(--brand);color:var(--brand)}
47871
+ .theme-toggle,.reload-btn{background:oklch(12% 0.02 270 / 0.5);border:1px solid var(--border);border-radius:9999px;padding:0.35rem 0.7rem;color:var(--text);cursor:pointer;font-size:0.8rem;line-height:1;transition:all 0.15s}
47872
+ .theme-toggle:hover,.reload-btn:hover{border-color:var(--brand);color:var(--brand)}
47873
+ .reload-btn{color:var(--muted);font-size:0.9rem}
47464
47874
  .minimap{width:150px;height:100px;background:var(--bg2);border:1px solid var(--border);border-radius:8px;overflow:hidden;box-shadow:0 4px 16px rgba(0,0,0,0.3);cursor:pointer}
47465
47875
  .minimap svg{width:100%;height:100%;display:block}
47466
- .minimap-viewport{fill:rgba(167,139,250,0.15);stroke:var(--brand);stroke-width:1.5}
47876
+ .minimap-viewport{fill:oklch(55% 0.25 280 / 0.15);stroke:oklch(55% 0.25 280);stroke-width:1.5}
47467
47877
  .graph-right{position:absolute;bottom:1rem;right:1rem;z-index:10;display:flex;flex-direction:column;align-items:flex-end;gap:0.4rem}
47468
- .physics-panel{position:absolute;top:2.8rem;left:0.5rem;background:var(--bg2);border:1px solid var(--border);border-radius:8px;padding:0.75rem;font-size:0.7rem;z-index:10;min-width:180px}
47878
+ .physics-panel{position:absolute;top:2.8rem;left:0.5rem;background:oklch(11% 0.02 270 / 0.9);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border:1px solid var(--border);border-radius:12px;padding:0.75rem;font-size:0.7rem;z-index:10;min-width:180px}
47469
47879
  .physics-panel h4{font-size:0.7rem;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;color:var(--muted);margin-bottom:0.5rem}
47470
47880
  .graph-toolbar{position:absolute;top:1rem;left:0.5rem;display:flex;gap:0.4rem;z-index:11}
47471
47881
  .physics-row{display:flex;align-items:center;gap:0.5rem;margin-bottom:0.4rem}
@@ -47475,17 +47885,22 @@ header .meta span{display:flex;align-items:center;gap:0.3rem}
47475
47885
  .physics-row .physics-val{font-size:0.6rem;color:var(--muted);width:30px;text-align:right}
47476
47886
  .node-circle.search-match{filter:drop-shadow(0 0 10px var(--brand)) brightness(1.4);animation:searchPulse 1.5s ease-in-out infinite}
47477
47887
  @keyframes searchPulse{0%,100%{filter:drop-shadow(0 0 8px var(--brand)) brightness(1.2)}50%{filter:drop-shadow(0 0 18px var(--brand)) brightness(1.7)}}
47478
- .path-btn.active{background:var(--brand);color:#fff;border-color:var(--brand)}
47479
- .path-info{position:absolute;bottom:0.5rem;left:0.5rem;background:var(--bg2);border:1px solid var(--border);border-radius:8px;padding:0.4rem 0.7rem;font-size:0.7rem;z-index:10;display:none;max-width:500px;word-break:break-all}
47888
+ .path-btn.active{background:var(--gradient);color:#fff;border-color:transparent;box-shadow:0 2px 14px -2px oklch(55% 0.25 280 / 0.5)}
47889
+ .path-info{position:absolute;bottom:0.5rem;left:0.5rem;background:oklch(11% 0.02 270 / 0.9);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border:1px solid var(--border);border-radius:12px;padding:0.4rem 0.7rem;font-size:0.7rem;z-index:10;display:none;max-width:500px;word-break:break-all}
47480
47890
  .node-circle.path-start{stroke:var(--green);stroke-width:3;filter:drop-shadow(0 0 12px var(--green))}
47481
47891
  .node-circle.path-end{stroke:var(--red);stroke-width:3;filter:drop-shadow(0 0 12px var(--red))}
47482
47892
  .node-circle.path-node{stroke:var(--brand);stroke-width:2.5;animation:pathNodePulse 1.2s ease-in-out infinite}
47483
47893
  @keyframes pathNodePulse{0%,100%{filter:drop-shadow(0 0 6px var(--brand))}50%{filter:drop-shadow(0 0 14px var(--brand))}}
47484
47894
  .link.path-edge{stroke:var(--brand);stroke-opacity:0.9;stroke-width:3}
47485
- .light{--bg:#f4f4f9;--bg2:#ffffff;--bg3:#e8e8f0;--border:#c8c8d8;--text:#1a1a2e;--muted:#666680;--brand:#7c3aed;--brand2:#9333ea}
47486
- .light .tooltip{background:rgba(255,255,255,0.95);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-color:#c8c8d8;box-shadow:0 8px 32px rgba(0,0,0,0.1)}
47487
- .light .timeline-entry{background:#fff}
47488
- .light .graph-btn,.light .export-btn,.light .theme-toggle{background:#fff}
47895
+ @keyframes riseIn{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
47896
+ .app{animation:riseIn 0.6s var(--ease-out) both}
47897
+ .reveal{opacity:0;transform:translateY(14px);animation:riseIn 0.6s var(--ease-out) forwards}
47898
+ @media(prefers-reduced-motion:reduce){.app,.reveal{animation:none}.reveal{opacity:1;transform:none}.bar-fill{transition:none}.entry-item,.stat-card,.timeline-entry{transition:none}}
47899
+ .light{--bg:oklch(96% 0.005 270);--bg2:oklch(100% 0 0);--bg3:oklch(93% 0.005 270);--border:oklch(88% 0.01 270);--text:oklch(22% 0.02 270);--muted:oklch(45% 0.01 260);--brand:oklch(50% 0.22 280);--brand-light:oklch(45% 0.22 280)}
47900
+ .light header,.light .sidebar-header,.light .tabs{background:rgba(255,255,255,0.85)}
47901
+ .light .tooltip{background:rgba(255,255,255,0.95);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-color:var(--border);box-shadow:0 8px 32px rgba(0,0,0,0.1)}
47902
+ .light .timeline-entry{background:var(--bg2)}
47903
+ .light .graph-btn,.light .export-btn,.light .theme-toggle,.light .reload-btn{background:var(--bg2)}
47489
47904
  .light .minimap{box-shadow:0 4px 16px rgba(0,0,0,0.08)}
47490
47905
  @media(max-width:768px){.main{grid-template-columns:1fr}.sidebar{display:none}}
47491
47906
  </style>
@@ -47493,7 +47908,10 @@ header .meta span{display:flex;align-items:center;gap:0.3rem}
47493
47908
  <body>
47494
47909
  <div class="app">
47495
47910
  <header>
47496
- <h1>toon-memory viewer</h1>
47911
+ <div class="brand">
47912
+ <span class="brand-logo">${logoSrc}</span>
47913
+ <span class="brand-word">${isologoSrc}</span>
47914
+ </div>
47497
47915
  <div class="meta">
47498
47916
  <span id="totalCount"></span>
47499
47917
  <span id="edgeCount"></span>
@@ -47567,10 +47985,7 @@ header .meta span{display:flex;align-items:center;gap:0.3rem}
47567
47985
  <script>
47568
47986
  const DATA = ${jsonData};
47569
47987
 
47570
- const COLORS = {
47571
- decision: '#a78bfa', bug: '#ef4444', pattern: '#22c55e',
47572
- knowledge: '#06b6d4', architecture: '#f59e0b'
47573
- };
47988
+ const COLORS = { decision: 'oklch(55% 0.25 280)', bug: 'oklch(65% 0.24 25)', pattern: 'oklch(78% 0.2 155)', knowledge: 'oklch(65% 0.25 310)', architecture: 'oklch(85% 0.18 85)' };
47574
47989
 
47575
47990
  let selectedEntry = null;
47576
47991
  let activeFilter = null;
@@ -47669,6 +48084,7 @@ document.getElementById('search').addEventListener('input', (e) => {
47669
48084
  });
47670
48085
 
47671
48086
  // --- Entries List ---
48087
+ let firstEntriesRender = true;
47672
48088
  function renderEntries() {
47673
48089
  const q = searchQuery;
47674
48090
  const list = document.getElementById('entriesList');
@@ -47676,9 +48092,10 @@ function renderEntries() {
47676
48092
  DATA.nodes
47677
48093
  .filter(e => !activeFilter || e.category === activeFilter)
47678
48094
  .filter(e => !q || e.id.toLowerCase().includes(q) || e.content.toLowerCase().includes(q) || e.tags.some(t => t.toLowerCase().includes(q)))
47679
- .forEach(e => {
48095
+ .forEach((e, i) => {
47680
48096
  const div = document.createElement('div');
47681
- div.className = 'entry-item' + (selectedEntry && selectedEntry.id === e.id ? ' selected' : '');
48097
+ div.className = 'entry-item' + (selectedEntry && selectedEntry.id === e.id ? ' selected' : '') + (firstEntriesRender ? ' reveal' : '');
48098
+ if (firstEntriesRender) div.style.animationDelay = Math.min(i * 0.03, 0.6) + 's';
47682
48099
  div.innerHTML =
47683
48100
  '<div class="entry-cat ' + e.category + '">' + e.category + '</div>' +
47684
48101
  '<div class="entry-key">' + escHtml(e.id) + '</div>' +
@@ -47687,6 +48104,7 @@ function renderEntries() {
47687
48104
  div.onclick = () => selectEntry(e);
47688
48105
  list.appendChild(div);
47689
48106
  });
48107
+ firstEntriesRender = false;
47690
48108
  }
47691
48109
 
47692
48110
  function escHtml(s) { return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
@@ -47735,22 +48153,29 @@ function renderStats() {
47735
48153
  const maxTag = Math.max(...topTags.map(t => t[1]));
47736
48154
  const avgQuality = DATA.nodes.reduce((s, n) => s + (n.quality || 0), 0) / DATA.nodes.length;
47737
48155
  const maxAccess = Math.max(...DATA.nodes.map(n => n.accessCount || 0));
48156
+ const card = (i, inner) => '<div class="stat-card reveal" style="animation-delay:' + (i * 0.07) + 's">' + inner + '</div>';
47738
48157
 
47739
48158
  grid.innerHTML =
47740
- '<div class="stat-card"><h3>Total Entries</h3><div class="stat-big">' + DATA.totalEntries + '</div></div>' +
47741
- '<div class="stat-card"><h3>Graph Edges</h3><div class="stat-big">' + DATA.edges.length + '</div></div>' +
47742
- '<div class="stat-card"><h3>Avg Quality</h3><div class="stat-big">' + avgQuality.toFixed(2) + '</div></div>' +
47743
- '<div class="stat-card"><h3>Max Access</h3><div class="stat-big">' + maxAccess + '</div></div>' +
47744
- '<div class="stat-card"><h3>Categories</h3><div class="bar-chart">' +
48159
+ card(0, '<h3>Total Entries</h3><div class="stat-big">' + DATA.totalEntries + '</div>') +
48160
+ card(1, '<h3>Graph Edges</h3><div class="stat-big">' + DATA.edges.length + '</div>') +
48161
+ card(2, '<h3>Avg Quality</h3><div class="stat-big">' + avgQuality.toFixed(2) + '</div>') +
48162
+ card(3, '<h3>Max Access</h3><div class="stat-big">' + maxAccess + '</div>') +
48163
+ card(4, '<h3>Categories</h3><div class="bar-chart">' +
47745
48164
  catEntries.map(([cat, count]) =>
47746
- '<div class="bar-row"><span class="bar-label">' + cat + '</span><div class="bar-track"><div class="bar-fill" style="width:' + (count/maxCat*100) + '%;background:' + (COLORS[cat] || 'var(--brand)') + '"></div></div><span class="bar-value">' + count + '</span></div>'
48165
+ '<div class="bar-row"><span class="bar-label">' + cat + '</span><div class="bar-track"><div class="bar-fill" data-w="' + (count/maxCat*100) + '" style="background:' + (COLORS[cat] || 'var(--brand)') + '"></div></div><span class="bar-value">' + count + '</span></div>'
47747
48166
  ).join('') +
47748
- '</div></div>' +
47749
- '<div class="stat-card"><h3>Top Tags</h3><div class="tag-cloud">' +
48167
+ '</div>') +
48168
+ card(5, '<h3>Top Tags</h3><div class="tag-cloud">' +
47750
48169
  topTags.map(([tag, count]) =>
47751
48170
  '<span class="tag-pill">' + escHtml(tag) + ' <small>(' + count + ')</small></span>'
47752
48171
  ).join('') +
47753
- '</div></div>';
48172
+ '</div>');
48173
+
48174
+ requestAnimationFrame(() => {
48175
+ grid.querySelectorAll('.bar-fill').forEach(b => {
48176
+ b.style.width = b.getAttribute('data-w') + '%';
48177
+ });
48178
+ });
47754
48179
  }
47755
48180
 
47756
48181
  function renderTimeline() {
@@ -47764,14 +48189,16 @@ function renderTimeline() {
47764
48189
  });
47765
48190
 
47766
48191
  let html = '<div class="timeline-header">Timeline (' + DATA.totalEntries + ' entries)</div><div class="timeline-track"><div class="timeline-line"></div>';
48192
+ let idx = 0;
47767
48193
  for (const [date, entries] of Object.entries(grouped)) {
47768
48194
  for (const e of entries) {
47769
- html += '<div class="timeline-entry" onclick="selectEntryById(\\'' + e.id + '\\')" style="border-left:3px solid ' + (COLORS[e.category] || 'var(--border)') + '">' +
48195
+ html += '<div class="timeline-entry reveal" style="border-left:3px solid ' + (COLORS[e.category] || 'var(--border)') + ';animation-delay:' + Math.min(idx * 0.02, 0.6) + 's" onclick="selectEntryById(\\'' + e.id + '\\')">' +
47770
48196
  '<div class="tl-date">' + escHtml(date) + '</div>' +
47771
48197
  '<div class="tl-cat" style="color:' + (COLORS[e.category] || 'var(--muted)') + '">' + e.category + '</div>' +
47772
48198
  '<div class="tl-key">' + escHtml(e.id) + '</div>' +
47773
48199
  '<div class="tl-content">' + escHtml(e.content.substring(0, 100)) + '</div>' +
47774
48200
  '</div>';
48201
+ idx++;
47775
48202
  }
47776
48203
  }
47777
48204
  html += '</div>';
@@ -47839,8 +48266,8 @@ const graph = (function() {
47839
48266
  const node = g.append('g').selectAll('circle').data(DATA.nodes).join('circle')
47840
48267
  .attr('class', 'node-circle')
47841
48268
  .attr('r', d => nodeRadius(d))
47842
- .attr('fill', d => COLORS[d.category] || '#888')
47843
- .attr('stroke', d => { const c = COLORS[d.category] || '#888'; return c; })
48269
+ .attr('fill', d => COLORS[d.category] || 'oklch(56% 0.02 270)')
48270
+ .attr('stroke', d => { const c = COLORS[d.category] || 'oklch(56% 0.02 270)'; return c; })
47844
48271
  .attr('stroke-width', 1.5)
47845
48272
  .attr('stroke-opacity', 0.6)
47846
48273
  .call(d3.drag()
@@ -48028,7 +48455,7 @@ const graph = (function() {
48028
48455
  const minimapG = minimapSvg.append('g');
48029
48456
  minimapG.append('g').attr('class', 'minimap-links');
48030
48457
  minimapG.append('g').attr('class', 'minimap-nodes');
48031
- const minimapViewport = minimapSvg.append('rect').attr('class', 'minimap-viewport').attr('fill', 'rgba(167,139,250,0.12)').attr('stroke', 'var(--brand)').attr('stroke-width', 1.5).attr('rx', 3);
48458
+ const minimapViewport = minimapSvg.append('rect').attr('class', 'minimap-viewport').attr('fill', 'oklch(55% 0.25 280 / 0.15)').attr('stroke', 'oklch(55% 0.25 280)').attr('stroke-width', 1.5).attr('rx', 3);
48032
48459
 
48033
48460
  function getGraphBounds() {
48034
48461
  const allX = DATA.nodes.map(n => n.x || 0);
@@ -48045,11 +48472,11 @@ const graph = (function() {
48045
48472
  .attr('y1', d => (d.source.y || 0) * minimapScale)
48046
48473
  .attr('x2', d => (d.target.x || 0) * minimapScale)
48047
48474
  .attr('y2', d => (d.target.y || 0) * minimapScale)
48048
- .attr('stroke', 'var(--border)').attr('stroke-width', 0.5).attr('stroke-opacity', 0.3);
48475
+ .attr('stroke', 'oklch(21% 0.02 270)').attr('stroke-width', 0.5).attr('stroke-opacity', 0.3);
48049
48476
 
48050
48477
  minimapG.select('.minimap-nodes').selectAll('circle').data(DATA.nodes).join('circle')
48051
48478
  .attr('cx', d => (d.x || 0) * minimapScale).attr('cy', d => (d.y || 0) * minimapScale)
48052
- .attr('r', 1.8).attr('fill', d => COLORS[d.category] || '#888').attr('stroke', 'none');
48479
+ .attr('r', 1.8).attr('fill', d => COLORS[d.category] || 'oklch(56% 0.02 270)').attr('stroke', 'none');
48053
48480
 
48054
48481
  const t = currentTransform;
48055
48482
  const containerW = container.clientWidth;
@@ -48300,7 +48727,7 @@ function registerResources(server2) {
48300
48727
 
48301
48728
  // src/mcp/server.ts
48302
48729
  var server = new McpServer(
48303
- { name: "toon-memory", version: "4.3.1" },
48730
+ { name: "toon-memory", version: "4.3.3" },
48304
48731
  { capabilities: { tools: { listChanged: true }, resources: { listChanged: true }, experimental: { "io.modelcontextprotocol/ui": {} } } }
48305
48732
  );
48306
48733
  var s = server.server;
@@ -48312,7 +48739,7 @@ s.setRequestHandler(InitializeRequestSchema, async (request) => {
48312
48739
  return {
48313
48740
  protocolVersion,
48314
48741
  capabilities: s.getCapabilities(),
48315
- serverInfo: { name: "toon-memory", version: "4.3.1" },
48742
+ serverInfo: { name: "toon-memory", version: "4.3.3" },
48316
48743
  ...s._instructions && { instructions: s._instructions }
48317
48744
  };
48318
48745
  });