musememory 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3577,6 +3577,16 @@ function isExpired(entry, now) {
3577
3577
  const t = Date.parse(entry.expires_at);
3578
3578
  return !Number.isNaN(t) && t <= now;
3579
3579
  }
3580
+ function graphSymbolOverlapBonus(entry, queryTokens) {
3581
+ const symbols = entry.graph?.symbol_names;
3582
+ if (!symbols || symbols.length === 0 || queryTokens.length === 0)
3583
+ return 0;
3584
+ const symSet = new Set(symbols.map((s) => s.toLowerCase()));
3585
+ const matches = queryTokens.filter((t) => symSet.has(t.toLowerCase())).length;
3586
+ if (matches === 0)
3587
+ return 0;
3588
+ return Math.min(0.2, matches / queryTokens.length * 0.2);
3589
+ }
3580
3590
  function scoreEntry(entry, queryTokens, now) {
3581
3591
  const app = applicability(entry, queryTokens);
3582
3592
  const statusPenalty = STATUS_PENALTY[entry.status] ?? 0;
@@ -3586,9 +3596,10 @@ function scoreEntry(entry, queryTokens, now) {
3586
3596
  const r = entry.reinforcement ?? 0;
3587
3597
  const reinforcementBonus = Math.sign(r) * 0.05 * Math.min(Math.abs(r), 5);
3588
3598
  const dueBonus = dueDateBonus(entry, now);
3599
+ const graphBonus = graphSymbolOverlapBonus(entry, queryTokens);
3589
3600
  const decayBase = entry.valid_from ?? entry.updated_at;
3590
3601
  const decay = 0.3 * Math.exp(-daysSince(decayBase, now) / 90);
3591
- return app + statusPenalty + verificationBonus + salienceBonus + reinforcementBonus + dueBonus + decay;
3602
+ return app + statusPenalty + verificationBonus + salienceBonus + reinforcementBonus + dueBonus + graphBonus + decay;
3592
3603
  }
3593
3604
  function sortCandidates(candidates, queryTokens, now) {
3594
3605
  return candidates.map((entry) => ({ entry, score: scoreEntry(entry, queryTokens, now) })).sort((a, b) => {
@@ -4747,8 +4758,212 @@ var init_harvest = __esm(() => {
4747
4758
  ];
4748
4759
  });
4749
4760
 
4761
+ // src/graph.ts
4762
+ import { existsSync as existsSync8, readdirSync, readFileSync as readFileSync7, writeFileSync as writeFileSync4, mkdirSync as mkdirSync5 } from "node:fs";
4763
+ import { join as join6 } from "node:path";
4764
+ function detectProvider(projectRoot) {
4765
+ if (!projectRoot || !existsSync8(projectRoot))
4766
+ return "none";
4767
+ if (existsSync8(join6(projectRoot, ".codegraph"))) {
4768
+ return "codegraph";
4769
+ }
4770
+ if (existsSync8(join6(projectRoot, ".graphify"))) {
4771
+ return "graphify";
4772
+ }
4773
+ return "none";
4774
+ }
4775
+ function getGraphStatus(projectRoot) {
4776
+ const provider = detectProvider(projectRoot);
4777
+ if (provider === "codegraph") {
4778
+ const codegraphDir = join6(projectRoot, ".codegraph");
4779
+ let symbolCount;
4780
+ let graphRevision;
4781
+ try {
4782
+ if (existsSync8(codegraphDir)) {
4783
+ const files = readdirSync(codegraphDir);
4784
+ symbolCount = files.length;
4785
+ const metaPath = join6(codegraphDir, "meta.json");
4786
+ if (existsSync8(metaPath)) {
4787
+ const meta = JSON.parse(readFileSync7(metaPath, "utf8"));
4788
+ graphRevision = meta.revision ?? meta.commit ?? meta.version;
4789
+ }
4790
+ }
4791
+ } catch {}
4792
+ return {
4793
+ provider: "codegraph",
4794
+ available: true,
4795
+ root: codegraphDir,
4796
+ graphRevision,
4797
+ symbolCount
4798
+ };
4799
+ }
4800
+ if (provider === "graphify") {
4801
+ const graphifyDir = join6(projectRoot, ".graphify");
4802
+ let symbolCount;
4803
+ let graphRevision;
4804
+ try {
4805
+ if (existsSync8(graphifyDir)) {
4806
+ const files = readdirSync(graphifyDir);
4807
+ symbolCount = files.length;
4808
+ const metaPath = join6(graphifyDir, "meta.json");
4809
+ if (existsSync8(metaPath)) {
4810
+ const meta = JSON.parse(readFileSync7(metaPath, "utf8"));
4811
+ graphRevision = meta.revision ?? meta.commit ?? meta.version;
4812
+ }
4813
+ }
4814
+ } catch {}
4815
+ return {
4816
+ provider: "graphify",
4817
+ available: true,
4818
+ root: graphifyDir,
4819
+ graphRevision,
4820
+ symbolCount
4821
+ };
4822
+ }
4823
+ return {
4824
+ provider: "none",
4825
+ available: false,
4826
+ root: projectRoot
4827
+ };
4828
+ }
4829
+ function graphSymbolsPath(memoryDir) {
4830
+ return join6(memoryDir, "graph-symbols.json");
4831
+ }
4832
+ function indexGraph(projectRoot, memoryDir) {
4833
+ const status = getGraphStatus(projectRoot);
4834
+ const symbols = {};
4835
+ if (status.provider === "codegraph") {
4836
+ const codegraphDir = join6(projectRoot, ".codegraph");
4837
+ try {
4838
+ const candidates = [
4839
+ join6(codegraphDir, "symbols.json"),
4840
+ join6(codegraphDir, "index.json"),
4841
+ join6(codegraphDir, "graph.json")
4842
+ ];
4843
+ for (const c of candidates) {
4844
+ if (existsSync8(c)) {
4845
+ const data = JSON.parse(readFileSync7(c, "utf8"));
4846
+ if (Array.isArray(data)) {
4847
+ for (const item of data) {
4848
+ if (item.name && item.path) {
4849
+ symbols[String(item.name)] = String(item.path);
4850
+ }
4851
+ }
4852
+ } else if (typeof data === "object" && data !== null) {
4853
+ if (data.symbols && typeof data.symbols === "object") {
4854
+ for (const [k, v] of Object.entries(data.symbols)) {
4855
+ symbols[k] = typeof v === "string" ? v : v?.path || "";
4856
+ }
4857
+ } else {
4858
+ for (const [k, v] of Object.entries(data)) {
4859
+ if (typeof v === "string")
4860
+ symbols[k] = v;
4861
+ }
4862
+ }
4863
+ }
4864
+ }
4865
+ }
4866
+ if (Object.keys(symbols).length === 0 && existsSync8(codegraphDir)) {
4867
+ const files = readdirSync(codegraphDir);
4868
+ for (const file of files) {
4869
+ if (file.endsWith(".json") && file !== "meta.json") {
4870
+ try {
4871
+ const content = JSON.parse(readFileSync7(join6(codegraphDir, file), "utf8"));
4872
+ if (content.name && content.path) {
4873
+ symbols[String(content.name)] = String(content.path);
4874
+ } else if (content.symbols && Array.isArray(content.symbols)) {
4875
+ for (const s of content.symbols) {
4876
+ if (s.name && (s.path || content.path)) {
4877
+ symbols[String(s.name)] = String(s.path || content.path);
4878
+ }
4879
+ }
4880
+ }
4881
+ } catch {}
4882
+ }
4883
+ }
4884
+ }
4885
+ } catch {}
4886
+ } else if (status.provider === "graphify") {
4887
+ const graphifyDir = join6(projectRoot, ".graphify");
4888
+ try {
4889
+ const candidates = [
4890
+ join6(graphifyDir, "graph.json"),
4891
+ join6(graphifyDir, "symbols.json")
4892
+ ];
4893
+ for (const c of candidates) {
4894
+ if (existsSync8(c)) {
4895
+ const data = JSON.parse(readFileSync7(c, "utf8"));
4896
+ if (data.nodes && Array.isArray(data.nodes)) {
4897
+ for (const node of data.nodes) {
4898
+ if (node.name && node.path) {
4899
+ symbols[String(node.name)] = String(node.path);
4900
+ }
4901
+ }
4902
+ }
4903
+ }
4904
+ }
4905
+ } catch {}
4906
+ }
4907
+ const index = {
4908
+ provider: status.provider,
4909
+ indexedAt: new Date().toISOString(),
4910
+ symbolCount: Object.keys(symbols).length,
4911
+ symbols
4912
+ };
4913
+ try {
4914
+ mkdirSync5(memoryDir, { recursive: true });
4915
+ writeFileSync4(graphSymbolsPath(memoryDir), JSON.stringify(index, null, 2), "utf8");
4916
+ } catch {}
4917
+ return index;
4918
+ }
4919
+ function loadGraphSymbolIndex(memoryDir) {
4920
+ const p = graphSymbolsPath(memoryDir);
4921
+ if (!existsSync8(p))
4922
+ return null;
4923
+ try {
4924
+ const raw = readFileSync7(p, "utf8");
4925
+ return JSON.parse(raw);
4926
+ } catch {
4927
+ return null;
4928
+ }
4929
+ }
4930
+ function extractReferencedSymbols(text, memoryDir) {
4931
+ const index = loadGraphSymbolIndex(memoryDir);
4932
+ if (!index || index.symbolCount === 0) {
4933
+ return { symbol_names: [], affected_paths: [], provider: "none" };
4934
+ }
4935
+ const matchedSymbols = new Set;
4936
+ const affectedPaths = new Set;
4937
+ const words = text.match(/[a-zA-Z_$][a-zA-Z0-9_$]*/g) || [];
4938
+ const wordSet = new Set(words);
4939
+ for (const [symbol, path] of Object.entries(index.symbols)) {
4940
+ if (wordSet.has(symbol)) {
4941
+ matchedSymbols.add(symbol);
4942
+ if (path)
4943
+ affectedPaths.add(path);
4944
+ }
4945
+ }
4946
+ return {
4947
+ symbol_names: Array.from(matchedSymbols),
4948
+ affected_paths: Array.from(affectedPaths),
4949
+ provider: index.provider
4950
+ };
4951
+ }
4952
+ function autoStampGraphMetadata(text, memoryDir) {
4953
+ const extracted = extractReferencedSymbols(text, memoryDir);
4954
+ if (extracted.symbol_names.length === 0)
4955
+ return;
4956
+ return {
4957
+ provider: extracted.provider,
4958
+ symbol_names: extracted.symbol_names,
4959
+ affected_paths: extracted.affected_paths,
4960
+ graph_verified_at: new Date().toISOString()
4961
+ };
4962
+ }
4963
+ var init_graph = () => {};
4964
+
4750
4965
  // src/sqlite.ts
4751
- import { existsSync as existsSync8, mkdirSync as mkdirSync5 } from "node:fs";
4966
+ import { existsSync as existsSync9, mkdirSync as mkdirSync6 } from "node:fs";
4752
4967
  import { dirname } from "node:path";
4753
4968
  function getDriver() {
4754
4969
  if (sqliteDriver !== "none")
@@ -4769,8 +4984,8 @@ function getDriver() {
4769
4984
  }
4770
4985
  function openDatabase(dbPath) {
4771
4986
  const dir = dirname(dbPath);
4772
- if (!existsSync8(dir)) {
4773
- mkdirSync5(dir, { recursive: true });
4987
+ if (!existsSync9(dir)) {
4988
+ mkdirSync6(dir, { recursive: true });
4774
4989
  }
4775
4990
  const driver = getDriver();
4776
4991
  let rawDb;
@@ -4980,29 +5195,29 @@ var init_sqlite = () => {};
4980
5195
 
4981
5196
  // src/store.ts
4982
5197
  import { resolve } from "node:path";
4983
- import { readdirSync, readFileSync as readFileSync7, writeFileSync as writeFileSync4, renameSync, unlinkSync, mkdirSync as mkdirSync6, existsSync as existsSync9 } from "node:fs";
4984
- import { join as join6 } from "node:path";
5198
+ import { readdirSync as readdirSync2, readFileSync as readFileSync8, writeFileSync as writeFileSync5, renameSync, unlinkSync, mkdirSync as mkdirSync7, existsSync as existsSync10 } from "node:fs";
5199
+ import { join as join7 } from "node:path";
4985
5200
  function getStorageLayout(memoryDir) {
4986
5201
  return {
4987
5202
  root: workspaceRootFor(memoryDir),
4988
5203
  memoryDir,
4989
- memoriesDir: join6(memoryDir, "memories"),
4990
- dbPath: join6(memoryDir, "memory.db"),
4991
- currentMd: join6(memoryDir, "CURRENT.md"),
4992
- userMd: join6(memoryDir, "USER.md"),
4993
- auditJsonl: join6(memoryDir, "audit.jsonl")
5204
+ memoriesDir: join7(memoryDir, "memories"),
5205
+ dbPath: join7(memoryDir, "memory.db"),
5206
+ currentMd: join7(memoryDir, "CURRENT.md"),
5207
+ userMd: join7(memoryDir, "USER.md"),
5208
+ auditJsonl: join7(memoryDir, "audit.jsonl")
4994
5209
  };
4995
5210
  }
4996
5211
  function openStore(memoryDir) {
4997
5212
  const layout = getStorageLayout(memoryDir);
4998
- mkdirSync6(layout.memoriesDir, { recursive: true });
4999
- mkdirSync6(memoryDir, { recursive: true });
5213
+ mkdirSync7(layout.memoriesDir, { recursive: true });
5214
+ mkdirSync7(memoryDir, { recursive: true });
5000
5215
  let db;
5001
5216
  try {
5002
5217
  db = openDatabase(layout.dbPath);
5003
5218
  } catch (err) {}
5004
5219
  const store = { dir: layout.memoriesDir, memoryDir, layout, db };
5005
- if (db && existsSync9(layout.memoriesDir)) {
5220
+ if (db && existsSync10(layout.memoriesDir)) {
5006
5221
  try {
5007
5222
  const yamlIds = listIds(store);
5008
5223
  for (const yId of yamlIds) {
@@ -5054,8 +5269,8 @@ function listIds(store) {
5054
5269
  ids.add(e.id);
5055
5270
  }
5056
5271
  }
5057
- if (existsSync9(store.dir)) {
5058
- for (const f of readdirSync(store.dir)) {
5272
+ if (existsSync10(store.dir)) {
5273
+ for (const f of readdirSync2(store.dir)) {
5059
5274
  if (f.endsWith(".yaml")) {
5060
5275
  ids.add(f.slice(0, -5));
5061
5276
  }
@@ -5065,10 +5280,10 @@ function listIds(store) {
5065
5280
  }
5066
5281
  function getFromYaml(store, id) {
5067
5282
  const file = fileForId(store, id);
5068
- if (!existsSync9(file))
5283
+ if (!existsSync10(file))
5069
5284
  return null;
5070
5285
  try {
5071
- const raw = readFileSync7(file, "utf8");
5286
+ const raw = readFileSync8(file, "utf8");
5072
5287
  const parsed = yaml.load(raw, { schema: yaml.JSON_SCHEMA });
5073
5288
  if (!parsed || typeof parsed !== "object")
5074
5289
  return null;
@@ -5079,7 +5294,7 @@ function getFromYaml(store, id) {
5079
5294
  }
5080
5295
  function get2(store, id) {
5081
5296
  const file = fileForId(store, id);
5082
- if (existsSync9(file)) {
5297
+ if (existsSync10(file)) {
5083
5298
  const fromYaml = getFromYaml(store, id);
5084
5299
  if (!fromYaml) {
5085
5300
  return null;
@@ -5129,7 +5344,7 @@ function save(store, entry, options = {}) {
5129
5344
  try {
5130
5345
  const file = fileForId(store, entry.id);
5131
5346
  const tmp = `${file}.tmp`;
5132
- writeFileSync4(tmp, yaml.dump(entry, { lineWidth: 120 }), "utf8");
5347
+ writeFileSync5(tmp, yaml.dump(entry, { lineWidth: 120 }), "utf8");
5133
5348
  renameSync(tmp, file);
5134
5349
  } catch {}
5135
5350
  }
@@ -5186,7 +5401,8 @@ function propose(store, opts) {
5186
5401
  due_at: opts.dueAt ?? opts.due_at,
5187
5402
  expires_at: opts.expiresAt ?? opts.expires_at,
5188
5403
  test_command: opts.test_command,
5189
- verification: opts.verification ?? (opts.confirmed ? { level: "user-confirmed", verified_at: now } : { level: "unverified" })
5404
+ verification: opts.verification ?? (opts.confirmed ? { level: "user-confirmed", verified_at: now } : { level: "unverified" }),
5405
+ graph: opts.graph ?? (store.memoryDir ? autoStampGraphMetadata(`${opts.title ?? ""} ${opts.content}`, store.memoryDir) : undefined)
5190
5406
  };
5191
5407
  if (opts.confirmed)
5192
5408
  entry.last_confirmed_at = now;
@@ -5395,7 +5611,7 @@ function deleteEntry(store, id, reason, actor) {
5395
5611
  deleted = deleteMemoryById(store.db, id) || deleted;
5396
5612
  }
5397
5613
  const file = fileForId(store, id);
5398
- if (existsSync9(file)) {
5614
+ if (existsSync10(file)) {
5399
5615
  unlinkSync(file);
5400
5616
  deleted = true;
5401
5617
  }
@@ -5440,6 +5656,7 @@ var init_store = __esm(() => {
5440
5656
  init_current();
5441
5657
  init_compiler();
5442
5658
  init_harvest();
5659
+ init_graph();
5443
5660
  init_root();
5444
5661
  init_sqlite();
5445
5662
  });
@@ -5539,8 +5756,8 @@ var init_cluster = __esm(() => {
5539
5756
  });
5540
5757
 
5541
5758
  // src/entities/extractor.ts
5542
- import { existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "node:fs";
5543
- import { join as join7 } from "node:path";
5759
+ import { existsSync as existsSync11, mkdirSync as mkdirSync8, readFileSync as readFileSync9, writeFileSync as writeFileSync6 } from "node:fs";
5760
+ import { join as join8 } from "node:path";
5544
5761
  function slugify(text) {
5545
5762
  return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
5546
5763
  }
@@ -5749,17 +5966,17 @@ function extractEntitiesFromText(text, config = {}) {
5749
5966
  return results;
5750
5967
  }
5751
5968
  function saveEntities(memoryDir, data) {
5752
- const filePath = join7(memoryDir, "entities.json");
5753
- mkdirSync7(memoryDir, { recursive: true });
5969
+ const filePath = join8(memoryDir, "entities.json");
5970
+ mkdirSync8(memoryDir, { recursive: true });
5754
5971
  const entities = Array.isArray(data) ? data : data.entities;
5755
- writeFileSync5(filePath, JSON.stringify(entities, null, 2), "utf8");
5972
+ writeFileSync6(filePath, JSON.stringify(entities, null, 2), "utf8");
5756
5973
  }
5757
5974
  function loadEntities(memoryDir) {
5758
- const filePath = join7(memoryDir, "entities.json");
5759
- if (!existsSync10(filePath))
5975
+ const filePath = join8(memoryDir, "entities.json");
5976
+ if (!existsSync11(filePath))
5760
5977
  return [];
5761
5978
  try {
5762
- return JSON.parse(readFileSync8(filePath, "utf8"));
5979
+ return JSON.parse(readFileSync9(filePath, "utf8"));
5763
5980
  } catch {
5764
5981
  return [];
5765
5982
  }
@@ -5961,8 +6178,8 @@ ${entries}
5961
6178
  }
5962
6179
 
5963
6180
  // src/wiki/compiler.ts
5964
- import { existsSync as existsSync11, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6, readFileSync as readFileSync9, readdirSync as readdirSync2 } from "node:fs";
5965
- import { join as join8 } from "node:path";
6181
+ import { existsSync as existsSync12, mkdirSync as mkdirSync9, writeFileSync as writeFileSync7, readFileSync as readFileSync10, readdirSync as readdirSync3 } from "node:fs";
6182
+ import { join as join9 } from "node:path";
5966
6183
  function compileWiki(store, memoryDir, options = {}) {
5967
6184
  const project = options.project;
5968
6185
  const dryRun = options.dryRun ?? false;
@@ -5986,12 +6203,12 @@ function compileWiki(store, memoryDir, options = {}) {
5986
6203
  }
5987
6204
  }
5988
6205
  const memories = project ? allMemories.filter((e) => e.project === project) : allMemories;
5989
- const wikiDir = join8(memoryDir, "wiki");
5990
- const conceptsDir = join8(wikiDir, "concepts");
5991
- const entitiesDir = join8(wikiDir, "entities");
6206
+ const wikiDir = join9(memoryDir, "wiki");
6207
+ const conceptsDir = join9(wikiDir, "concepts");
6208
+ const entitiesDir = join9(wikiDir, "entities");
5992
6209
  if (!dryRun) {
5993
- mkdirSync8(conceptsDir, { recursive: true });
5994
- mkdirSync8(entitiesDir, { recursive: true });
6210
+ mkdirSync9(conceptsDir, { recursive: true });
6211
+ mkdirSync9(entitiesDir, { recursive: true });
5995
6212
  }
5996
6213
  const result = { pagesCreated: [], pagesUpdated: [], logEntries: [], errors: [] };
5997
6214
  const existingConcepts = loadExistingConcepts(conceptsDir);
@@ -6244,14 +6461,14 @@ function stripFrontmatter(content) {
6244
6461
  }
6245
6462
  function loadExistingConcepts(dir) {
6246
6463
  const map2 = new Map;
6247
- if (!existsSync11(dir))
6464
+ if (!existsSync12(dir))
6248
6465
  return map2;
6249
- for (const file of readdirSync2(dir)) {
6466
+ for (const file of readdirSync3(dir)) {
6250
6467
  if (!file.endsWith(".md"))
6251
6468
  continue;
6252
6469
  const slug = file.slice(0, -3);
6253
6470
  try {
6254
- const content = readFileSync9(join8(dir, file), "utf8");
6471
+ const content = readFileSync10(join9(dir, file), "utf8");
6255
6472
  const frontmatter = parseFrontmatter(content);
6256
6473
  map2.set(slug, { ...frontmatter, slug, content: stripFrontmatter(content) });
6257
6474
  } catch {}
@@ -6260,14 +6477,14 @@ function loadExistingConcepts(dir) {
6260
6477
  }
6261
6478
  function loadExistingEntities(dir) {
6262
6479
  const map2 = new Map;
6263
- if (!existsSync11(dir))
6480
+ if (!existsSync12(dir))
6264
6481
  return map2;
6265
- for (const file of readdirSync2(dir)) {
6482
+ for (const file of readdirSync3(dir)) {
6266
6483
  if (!file.endsWith(".md"))
6267
6484
  continue;
6268
6485
  const slug = file.slice(0, -3);
6269
6486
  try {
6270
- const content = readFileSync9(join8(dir, file), "utf8");
6487
+ const content = readFileSync10(join9(dir, file), "utf8");
6271
6488
  const frontmatter = parseFrontmatter(content);
6272
6489
  map2.set(slug, { ...frontmatter, slug, content: stripFrontmatter(content) });
6273
6490
  } catch {}
@@ -6311,22 +6528,22 @@ function parseFrontmatter(content) {
6311
6528
  function writeConceptPages(map2, dir) {
6312
6529
  for (const [slug, page] of map2) {
6313
6530
  const content = renderConceptPage(page);
6314
- writeFileSync6(join8(dir, slug + ".md"), content, "utf8");
6531
+ writeFileSync7(join9(dir, slug + ".md"), content, "utf8");
6315
6532
  }
6316
6533
  }
6317
6534
  function writeEntityPages(map2, dir) {
6318
6535
  for (const [slug, page] of map2) {
6319
6536
  const content = renderEntityPage(page);
6320
- writeFileSync6(join8(dir, slug + ".md"), content, "utf8");
6537
+ writeFileSync7(join9(dir, slug + ".md"), content, "utf8");
6321
6538
  }
6322
6539
  }
6323
6540
  function writeIndexPage(page, dir) {
6324
6541
  const content = renderIndexPage(page);
6325
- writeFileSync6(join8(dir, "index.md"), content, "utf8");
6542
+ writeFileSync7(join9(dir, "index.md"), content, "utf8");
6326
6543
  }
6327
6544
  function writeLogPage(page, dir) {
6328
6545
  const content = renderLogPage(page);
6329
- writeFileSync6(join8(dir, "log.md"), content, "utf8");
6546
+ writeFileSync7(join9(dir, "log.md"), content, "utf8");
6330
6547
  }
6331
6548
  function applyDetailLevel(page, detailLevel) {
6332
6549
  if (detailLevel === "l1") {
@@ -6337,11 +6554,11 @@ function applyDetailLevel(page, detailLevel) {
6337
6554
  return page;
6338
6555
  }
6339
6556
  function listWikiPages(memoryDir, options = {}) {
6340
- const wikiDir = join8(memoryDir, "wiki");
6557
+ const wikiDir = join9(memoryDir, "wiki");
6341
6558
  const pages = [];
6342
6559
  const detailLevel = options.detailLevel ?? "full";
6343
6560
  if (options.type === undefined || options.type === "concept") {
6344
- const concepts = loadExistingConcepts(join8(wikiDir, "concepts"));
6561
+ const concepts = loadExistingConcepts(join9(wikiDir, "concepts"));
6345
6562
  for (const page of concepts.values()) {
6346
6563
  if (!options.project || page.project === options.project) {
6347
6564
  pages.push(applyDetailLevel(page, detailLevel));
@@ -6349,7 +6566,7 @@ function listWikiPages(memoryDir, options = {}) {
6349
6566
  }
6350
6567
  }
6351
6568
  if (options.type === undefined || options.type === "entity") {
6352
- const entities = loadExistingEntities(join8(wikiDir, "entities"));
6569
+ const entities = loadExistingEntities(join9(wikiDir, "entities"));
6353
6570
  for (const page of entities.values()) {
6354
6571
  if (!options.project || page.project === options.project) {
6355
6572
  pages.push(applyDetailLevel(page, detailLevel));
@@ -6357,20 +6574,20 @@ function listWikiPages(memoryDir, options = {}) {
6357
6574
  }
6358
6575
  }
6359
6576
  if (options.type === undefined || options.type === "index") {
6360
- const idxPath = join8(wikiDir, "index.md");
6361
- if (existsSync11(idxPath)) {
6577
+ const idxPath = join9(wikiDir, "index.md");
6578
+ if (existsSync12(idxPath)) {
6362
6579
  try {
6363
- const raw = readFileSync9(idxPath, "utf8");
6580
+ const raw = readFileSync10(idxPath, "utf8");
6364
6581
  const fm = parseFrontmatter(raw);
6365
6582
  pages.push(applyDetailLevel({ ...fm, slug: "index", type: "index", content: raw }, detailLevel));
6366
6583
  } catch {}
6367
6584
  }
6368
6585
  }
6369
6586
  if (options.type === undefined || options.type === "log") {
6370
- const logPath = join8(wikiDir, "log.md");
6371
- if (existsSync11(logPath)) {
6587
+ const logPath = join9(wikiDir, "log.md");
6588
+ if (existsSync12(logPath)) {
6372
6589
  try {
6373
- const raw = readFileSync9(logPath, "utf8");
6590
+ const raw = readFileSync10(logPath, "utf8");
6374
6591
  const fm = parseFrontmatter(raw);
6375
6592
  pages.push(applyDetailLevel({ ...fm, slug: "log", type: "log", content: raw }, detailLevel));
6376
6593
  } catch {}
@@ -6379,37 +6596,37 @@ function listWikiPages(memoryDir, options = {}) {
6379
6596
  return pages;
6380
6597
  }
6381
6598
  function getWikiPage(memoryDir, slug, type2, detailLevel = "full") {
6382
- const wikiDir = join8(memoryDir, "wiki");
6599
+ const wikiDir = join9(memoryDir, "wiki");
6383
6600
  if (slug === "index") {
6384
- const p = join8(wikiDir, "index.md");
6385
- if (existsSync11(p)) {
6386
- const raw = readFileSync9(p, "utf8");
6601
+ const p = join9(wikiDir, "index.md");
6602
+ if (existsSync12(p)) {
6603
+ const raw = readFileSync10(p, "utf8");
6387
6604
  const fm = parseFrontmatter(raw);
6388
6605
  return applyDetailLevel({ ...fm, slug: "index", type: "index", content: raw }, detailLevel);
6389
6606
  }
6390
6607
  return null;
6391
6608
  }
6392
6609
  if (slug === "log") {
6393
- const p = join8(wikiDir, "log.md");
6394
- if (existsSync11(p)) {
6395
- const raw = readFileSync9(p, "utf8");
6610
+ const p = join9(wikiDir, "log.md");
6611
+ if (existsSync12(p)) {
6612
+ const raw = readFileSync10(p, "utf8");
6396
6613
  const fm = parseFrontmatter(raw);
6397
6614
  return applyDetailLevel({ ...fm, slug: "log", type: "log", content: raw }, detailLevel);
6398
6615
  }
6399
6616
  return null;
6400
6617
  }
6401
6618
  if (!type2 || type2 === "concept") {
6402
- const p = join8(wikiDir, "concepts", `${slug}.md`);
6403
- if (existsSync11(p)) {
6404
- const raw = readFileSync9(p, "utf8");
6619
+ const p = join9(wikiDir, "concepts", `${slug}.md`);
6620
+ if (existsSync12(p)) {
6621
+ const raw = readFileSync10(p, "utf8");
6405
6622
  const fm = parseFrontmatter(raw);
6406
6623
  return applyDetailLevel({ ...fm, slug, type: "concept", content: raw }, detailLevel);
6407
6624
  }
6408
6625
  }
6409
6626
  if (!type2 || type2 === "entity") {
6410
- const p = join8(wikiDir, "entities", `${slug}.md`);
6411
- if (existsSync11(p)) {
6412
- const raw = readFileSync9(p, "utf8");
6627
+ const p = join9(wikiDir, "entities", `${slug}.md`);
6628
+ if (existsSync12(p)) {
6629
+ const raw = readFileSync10(p, "utf8");
6413
6630
  const fm = parseFrontmatter(raw);
6414
6631
  return applyDetailLevel({ ...fm, slug, type: "entity", content: raw }, detailLevel);
6415
6632
  }
@@ -6417,15 +6634,15 @@ function getWikiPage(memoryDir, slug, type2, detailLevel = "full") {
6417
6634
  return null;
6418
6635
  }
6419
6636
  function ensureWikiStructure(memoryDir) {
6420
- const wikiDir = join8(memoryDir, "wiki");
6421
- const conceptsDir = join8(wikiDir, "concepts");
6422
- const entitiesDir = join8(wikiDir, "entities");
6423
- if (!existsSync11(conceptsDir))
6424
- mkdirSync8(conceptsDir, { recursive: true });
6425
- if (!existsSync11(entitiesDir))
6426
- mkdirSync8(entitiesDir, { recursive: true });
6427
- const indexPath = join8(wikiDir, "index.md");
6428
- if (!existsSync11(indexPath)) {
6637
+ const wikiDir = join9(memoryDir, "wiki");
6638
+ const conceptsDir = join9(wikiDir, "concepts");
6639
+ const entitiesDir = join9(wikiDir, "entities");
6640
+ if (!existsSync12(conceptsDir))
6641
+ mkdirSync9(conceptsDir, { recursive: true });
6642
+ if (!existsSync12(entitiesDir))
6643
+ mkdirSync9(entitiesDir, { recursive: true });
6644
+ const indexPath = join9(wikiDir, "index.md");
6645
+ if (!existsSync12(indexPath)) {
6429
6646
  const defaultIndex = `# Knowledge Wiki Index
6430
6647
 
6431
6648
  > Compiled Obsidian-compatible concept and entity knowledge base.
@@ -6436,16 +6653,16 @@ function ensureWikiStructure(memoryDir) {
6436
6653
  ## Entities
6437
6654
  *(No named entities extracted yet)*
6438
6655
  `;
6439
- writeFileSync6(indexPath, defaultIndex, "utf8");
6656
+ writeFileSync7(indexPath, defaultIndex, "utf8");
6440
6657
  }
6441
- const logPath = join8(wikiDir, "log.md");
6442
- if (!existsSync11(logPath)) {
6658
+ const logPath = join9(wikiDir, "log.md");
6659
+ if (!existsSync12(logPath)) {
6443
6660
  const defaultLog = `# Wiki Compilation Log
6444
6661
 
6445
6662
  | Timestamp | Action | Page | Memories | Details |
6446
6663
  |---|---|---|---|---|
6447
6664
  `;
6448
- writeFileSync6(logPath, defaultLog, "utf8");
6665
+ writeFileSync7(logPath, defaultLog, "utf8");
6449
6666
  }
6450
6667
  }
6451
6668
  function autoCompileWiki(store, memoryDir, options = {}) {
@@ -6465,8 +6682,8 @@ var init_wiki = __esm(() => {
6465
6682
  });
6466
6683
 
6467
6684
  // src/root.ts
6468
- import { existsSync as existsSync12, mkdirSync as mkdirSync9, writeFileSync as writeFileSync7 } from "node:fs";
6469
- import { dirname as dirname3, join as join9 } from "node:path";
6685
+ import { existsSync as existsSync13, mkdirSync as mkdirSync10, writeFileSync as writeFileSync8 } from "node:fs";
6686
+ import { dirname as dirname3, join as join10 } from "node:path";
6470
6687
  import { homedir } from "node:os";
6471
6688
  function isMemoryDirPath(path) {
6472
6689
  return MEMORY_DIR_NAMES.some((n) => path.endsWith(n));
@@ -6479,20 +6696,20 @@ function getGlobalMemoryDir() {
6479
6696
  if (custom)
6480
6697
  return custom;
6481
6698
  const home = process.env.HOME || process.env.USERPROFILE || homedir();
6482
- return join9(home, ".memory");
6699
+ return join10(home, ".memory");
6483
6700
  }
6484
6701
  function ensureMemoryDirectory(memoryDir) {
6485
- const memoriesDir = join9(memoryDir, "memories");
6486
- if (!existsSync12(memoriesDir)) {
6487
- mkdirSync9(memoriesDir, { recursive: true });
6702
+ const memoriesDir = join10(memoryDir, "memories");
6703
+ if (!existsSync13(memoriesDir)) {
6704
+ mkdirSync10(memoriesDir, { recursive: true });
6488
6705
  }
6489
- const currentPath = join9(memoryDir, "CURRENT.md");
6490
- if (!existsSync12(currentPath)) {
6491
- writeFileSync7(currentPath, `# Active Project Constraints
6706
+ const currentPath = join10(memoryDir, "CURRENT.md");
6707
+ if (!existsSync13(currentPath)) {
6708
+ writeFileSync8(currentPath, `# Active Project Constraints
6492
6709
  `, "utf8");
6493
6710
  }
6494
6711
  const uPath = userFilePath(memoryDir);
6495
- if (!existsSync12(uPath)) {
6712
+ if (!existsSync13(uPath)) {
6496
6713
  const isGlobal = memoryDir === getGlobalMemoryDir();
6497
6714
  initUserProfile(memoryDir, "developer", false, !isGlobal);
6498
6715
  }
@@ -6509,19 +6726,19 @@ function findProjectRoot(startDir, options = {}) {
6509
6726
  }
6510
6727
  const ancestors = ancestorChain(startDir);
6511
6728
  for (const dir of ancestors) {
6512
- if (existsSync12(join9(dir, ".memory")))
6729
+ if (existsSync13(join10(dir, ".memory")))
6513
6730
  return { root: dir, marker: "memory", memoryDirName: ".memory" };
6514
- if (existsSync12(join9(dir, ".musememory")))
6731
+ if (existsSync13(join10(dir, ".musememory")))
6515
6732
  return { root: dir, marker: "memory", memoryDirName: ".musememory" };
6516
- if (existsSync12(join9(dir, ".muse-memory")))
6733
+ if (existsSync13(join10(dir, ".muse-memory")))
6517
6734
  return { root: dir, marker: "memory", memoryDirName: ".muse-memory" };
6518
6735
  }
6519
6736
  for (const dir of ancestors) {
6520
- if (existsSync12(join9(dir, ".git"))) {
6737
+ if (existsSync13(join10(dir, ".git"))) {
6521
6738
  let dirName = ".memory";
6522
- if (existsSync12(join9(dir, ".musememory")))
6739
+ if (existsSync13(join10(dir, ".musememory")))
6523
6740
  dirName = ".musememory";
6524
- else if (existsSync12(join9(dir, ".muse-memory")))
6741
+ else if (existsSync13(join10(dir, ".muse-memory")))
6525
6742
  dirName = ".muse-memory";
6526
6743
  return { root: dir, marker: "git", memoryDirName: dirName };
6527
6744
  }
@@ -6541,8 +6758,8 @@ function findOrCreateProjectRoot(startDir, options = {}) {
6541
6758
  return { root: memoryDir2, memoryDir: memoryDir2, marker: res.marker };
6542
6759
  }
6543
6760
  const root = res.root ?? startDir;
6544
- const memoryDirName = res.memoryDirName ?? MEMORY_DIR_NAMES.find((n) => existsSync12(join9(root, n))) ?? ".memory";
6545
- const memoryDir = join9(root, memoryDirName);
6761
+ const memoryDirName = res.memoryDirName ?? MEMORY_DIR_NAMES.find((n) => existsSync13(join10(root, n))) ?? ".memory";
6762
+ const memoryDir = join10(root, memoryDirName);
6546
6763
  const marker = res.marker ?? "auto";
6547
6764
  ensureMemoryDirectory(memoryDir);
6548
6765
  return { root, memoryDir, marker };
@@ -6552,7 +6769,7 @@ function ancestorChain(startDir) {
6552
6769
  let dir = startDir;
6553
6770
  for (;; ) {
6554
6771
  chain.push(dir);
6555
- const parent = join9(dir, "..");
6772
+ const parent = join10(dir, "..");
6556
6773
  if (parent === dir)
6557
6774
  break;
6558
6775
  dir = parent;
@@ -6657,12 +6874,12 @@ function normalizeMemoryType(raw) {
6657
6874
  }
6658
6875
 
6659
6876
  // src/migrator/detect.ts
6660
- import { existsSync as existsSync13 } from "node:fs";
6661
- import { join as join10, resolve as resolve2 } from "node:path";
6877
+ import { existsSync as existsSync14 } from "node:fs";
6878
+ import { join as join11, resolve as resolve2 } from "node:path";
6662
6879
  import { homedir as homedir2 } from "node:os";
6663
6880
  function expandPath(p, baseDir) {
6664
6881
  if (p.startsWith("~/") || p === "~") {
6665
- return join10(homedir2(), p.slice(1));
6882
+ return join11(homedir2(), p.slice(1));
6666
6883
  }
6667
6884
  if (p.startsWith("/")) {
6668
6885
  return p;
@@ -6673,7 +6890,7 @@ function detectProviders(baseDir = process.cwd()) {
6673
6890
  return PROVIDER_DEFINITIONS.map((def) => {
6674
6891
  const resolved = def.paths.map((p) => expandPath(p, baseDir)).filter((p) => {
6675
6892
  try {
6676
- return existsSync13(p);
6893
+ return existsSync14(p);
6677
6894
  } catch {
6678
6895
  return false;
6679
6896
  }
@@ -6964,8 +7181,8 @@ var init_detect = __esm(() => {
6964
7181
  });
6965
7182
 
6966
7183
  // src/migrator/adapters/agentmemory.ts
6967
- import { existsSync as existsSync14, readFileSync as readFileSync10, statSync } from "node:fs";
6968
- import { join as join11 } from "node:path";
7184
+ import { existsSync as existsSync15, readFileSync as readFileSync11, statSync } from "node:fs";
7185
+ import { join as join12 } from "node:path";
6969
7186
  var AgentMemoryAdapter;
6970
7187
  var init_agentmemory = __esm(() => {
6971
7188
  AgentMemoryAdapter = {
@@ -6973,23 +7190,23 @@ var init_agentmemory = __esm(() => {
6973
7190
  extract(sourcePath, options = {}) {
6974
7191
  const results = [];
6975
7192
  let jsonPath = sourcePath;
6976
- if (existsSync14(sourcePath) && statSync(sourcePath).isDirectory()) {
7193
+ if (existsSync15(sourcePath) && statSync(sourcePath).isDirectory()) {
6977
7194
  const candidates = [
6978
- join11(sourcePath, "standalone.json"),
6979
- join11(sourcePath, "engine-state.json")
7195
+ join12(sourcePath, "standalone.json"),
7196
+ join12(sourcePath, "engine-state.json")
6980
7197
  ];
6981
7198
  for (const cand of candidates) {
6982
- if (existsSync14(cand)) {
7199
+ if (existsSync15(cand)) {
6983
7200
  jsonPath = cand;
6984
7201
  break;
6985
7202
  }
6986
7203
  }
6987
7204
  }
6988
- if (!existsSync14(jsonPath) || statSync(jsonPath).isDirectory()) {
7205
+ if (!existsSync15(jsonPath) || statSync(jsonPath).isDirectory()) {
6989
7206
  return results;
6990
7207
  }
6991
7208
  try {
6992
- const raw = readFileSync10(jsonPath, "utf8");
7209
+ const raw = readFileSync11(jsonPath, "utf8");
6993
7210
  const parsed = JSON.parse(raw);
6994
7211
  const memObj = parsed["mem:memories"] || parsed["memories"] || parsed;
6995
7212
  const items = Array.isArray(memObj) ? memObj : Object.values(memObj);
@@ -7026,25 +7243,25 @@ var init_agentmemory = __esm(() => {
7026
7243
  });
7027
7244
 
7028
7245
  // src/migrator/adapters/beads.ts
7029
- import { existsSync as existsSync15, readFileSync as readFileSync11, readdirSync as readdirSync3, statSync as statSync2 } from "node:fs";
7030
- import { join as join12 } from "node:path";
7246
+ import { existsSync as existsSync16, readFileSync as readFileSync12, readdirSync as readdirSync4, statSync as statSync2 } from "node:fs";
7247
+ import { join as join13 } from "node:path";
7031
7248
  var BeadsAdapter;
7032
7249
  var init_beads = __esm(() => {
7033
7250
  BeadsAdapter = {
7034
7251
  id: "beads",
7035
7252
  extract(sourcePath, options = {}) {
7036
7253
  const results = [];
7037
- if (!existsSync15(sourcePath))
7254
+ if (!existsSync16(sourcePath))
7038
7255
  return results;
7039
7256
  let jsonPath = sourcePath;
7040
7257
  if (statSync2(sourcePath).isDirectory()) {
7041
- const p = join12(sourcePath, "beads.json");
7042
- if (existsSync15(p))
7258
+ const p = join13(sourcePath, "beads.json");
7259
+ if (existsSync16(p))
7043
7260
  jsonPath = p;
7044
7261
  }
7045
- if (existsSync15(jsonPath) && !statSync2(jsonPath).isDirectory()) {
7262
+ if (existsSync16(jsonPath) && !statSync2(jsonPath).isDirectory()) {
7046
7263
  try {
7047
- const raw = readFileSync11(jsonPath, "utf8");
7264
+ const raw = readFileSync12(jsonPath, "utf8");
7048
7265
  const parsed = JSON.parse(raw);
7049
7266
  const beads = Array.isArray(parsed) ? parsed : parsed.beads || Object.values(parsed);
7050
7267
  for (const b of beads) {
@@ -7075,12 +7292,12 @@ var init_beads = __esm(() => {
7075
7292
  }
7076
7293
  if (statSync2(sourcePath).isDirectory()) {
7077
7294
  try {
7078
- const files = readdirSync3(sourcePath);
7295
+ const files = readdirSync4(sourcePath);
7079
7296
  for (const file of files) {
7080
7297
  if (!file.endsWith(".md") && !file.endsWith(".markdown"))
7081
7298
  continue;
7082
- const fullPath = join12(sourcePath, file);
7083
- const content = readFileSync11(fullPath, "utf8");
7299
+ const fullPath = join13(sourcePath, file);
7300
+ const content = readFileSync12(fullPath, "utf8");
7084
7301
  const title = file.replace(/\.md$/, "").replace(/[-_]/g, " ");
7085
7302
  results.push({
7086
7303
  title,
@@ -7100,15 +7317,15 @@ var init_beads = __esm(() => {
7100
7317
  });
7101
7318
 
7102
7319
  // src/migrator/adapters/letta.ts
7103
- import { existsSync as existsSync16, readFileSync as readFileSync12, readdirSync as readdirSync4, statSync as statSync3 } from "node:fs";
7104
- import { join as join13 } from "node:path";
7320
+ import { existsSync as existsSync17, readFileSync as readFileSync13, readdirSync as readdirSync5, statSync as statSync3 } from "node:fs";
7321
+ import { join as join14 } from "node:path";
7105
7322
  var LettaAdapter;
7106
7323
  var init_letta = __esm(() => {
7107
7324
  LettaAdapter = {
7108
7325
  id: "letta",
7109
7326
  extract(sourcePath, options = {}) {
7110
7327
  const results = [];
7111
- if (!existsSync16(sourcePath))
7328
+ if (!existsSync17(sourcePath))
7112
7329
  return results;
7113
7330
  const processJson = (raw, filename) => {
7114
7331
  try {
@@ -7161,16 +7378,16 @@ var init_letta = __esm(() => {
7161
7378
  };
7162
7379
  if (statSync3(sourcePath).isDirectory()) {
7163
7380
  try {
7164
- const entries = readdirSync4(sourcePath);
7381
+ const entries = readdirSync5(sourcePath);
7165
7382
  for (const file of entries) {
7166
7383
  if (file.endsWith(".json")) {
7167
- const raw = readFileSync12(join13(sourcePath, file), "utf8");
7384
+ const raw = readFileSync13(join14(sourcePath, file), "utf8");
7168
7385
  processJson(raw, file);
7169
7386
  }
7170
7387
  }
7171
7388
  } catch {}
7172
7389
  } else {
7173
- processJson(readFileSync12(sourcePath, "utf8"), "letta.json");
7390
+ processJson(readFileSync13(sourcePath, "utf8"), "letta.json");
7174
7391
  }
7175
7392
  return results;
7176
7393
  }
@@ -7178,8 +7395,8 @@ var init_letta = __esm(() => {
7178
7395
  });
7179
7396
 
7180
7397
  // src/migrator/adapters/generic.ts
7181
- import { existsSync as existsSync17, readFileSync as readFileSync13, readdirSync as readdirSync5, statSync as statSync4 } from "node:fs";
7182
- import { join as join14 } from "node:path";
7398
+ import { existsSync as existsSync18, readFileSync as readFileSync14, readdirSync as readdirSync6, statSync as statSync4 } from "node:fs";
7399
+ import { join as join15 } from "node:path";
7183
7400
  var GenericAdapter;
7184
7401
  var init_generic = __esm(() => {
7185
7402
  init_js_yaml();
@@ -7187,11 +7404,11 @@ var init_generic = __esm(() => {
7187
7404
  id: "generic",
7188
7405
  extract(sourcePath, options = {}) {
7189
7406
  const results = [];
7190
- if (!existsSync17(sourcePath))
7407
+ if (!existsSync18(sourcePath))
7191
7408
  return results;
7192
7409
  const processFile = (filePath, filename) => {
7193
7410
  try {
7194
- const raw = readFileSync13(filePath, "utf8");
7411
+ const raw = readFileSync14(filePath, "utf8");
7195
7412
  if (filename.endsWith(".json") || filename.endsWith(".jsonl")) {
7196
7413
  try {
7197
7414
  const parsed = JSON.parse(raw);
@@ -7262,9 +7479,9 @@ var init_generic = __esm(() => {
7262
7479
  };
7263
7480
  if (statSync4(sourcePath).isDirectory()) {
7264
7481
  try {
7265
- const files = readdirSync5(sourcePath);
7482
+ const files = readdirSync6(sourcePath);
7266
7483
  for (const file of files) {
7267
- processFile(join14(sourcePath, file), file);
7484
+ processFile(join15(sourcePath, file), file);
7268
7485
  }
7269
7486
  } catch {}
7270
7487
  } else {
@@ -7432,50 +7649,6 @@ var init_migrator = __esm(() => {
7432
7649
  init_engine();
7433
7650
  });
7434
7651
 
7435
- // src/graph.ts
7436
- import { existsSync as existsSync18, readdirSync as readdirSync6, readFileSync as readFileSync14 } from "node:fs";
7437
- import { join as join15 } from "node:path";
7438
- function detectProvider(projectRoot) {
7439
- if (!projectRoot || !existsSync18(projectRoot))
7440
- return "none";
7441
- if (existsSync18(join15(projectRoot, ".codegraph"))) {
7442
- return "codegraph";
7443
- }
7444
- return "none";
7445
- }
7446
- function getGraphStatus(projectRoot) {
7447
- const provider = detectProvider(projectRoot);
7448
- if (provider === "codegraph") {
7449
- const codegraphDir = join15(projectRoot, ".codegraph");
7450
- let symbolCount;
7451
- let graphRevision;
7452
- try {
7453
- if (existsSync18(codegraphDir)) {
7454
- const files = readdirSync6(codegraphDir);
7455
- symbolCount = files.length;
7456
- const metaPath = join15(codegraphDir, "meta.json");
7457
- if (existsSync18(metaPath)) {
7458
- const meta = JSON.parse(readFileSync14(metaPath, "utf8"));
7459
- graphRevision = meta.revision ?? meta.commit ?? meta.version;
7460
- }
7461
- }
7462
- } catch {}
7463
- return {
7464
- provider: "codegraph",
7465
- available: true,
7466
- root: codegraphDir,
7467
- graphRevision,
7468
- symbolCount
7469
- };
7470
- }
7471
- return {
7472
- provider: "none",
7473
- available: false,
7474
- root: projectRoot
7475
- };
7476
- }
7477
- var init_graph = () => {};
7478
-
7479
7652
  // src/prompt.ts
7480
7653
  var exports_prompt = {};
7481
7654
  __export(exports_prompt, {
@@ -8239,7 +8412,7 @@ __export(exports_connect, {
8239
8412
  disconnectAllAgents: () => disconnectAllAgents,
8240
8413
  disconnectSingleAgent: () => disconnectSingleAgent
8241
8414
  });
8242
- import { existsSync as existsSync20, readFileSync as readFileSync16, writeFileSync as writeFileSync8, mkdirSync as mkdirSync10, statSync as statSync6 } from "node:fs";
8415
+ import { existsSync as existsSync20, readFileSync as readFileSync16, writeFileSync as writeFileSync9, mkdirSync as mkdirSync11, statSync as statSync6 } from "node:fs";
8243
8416
  import { join as join17, dirname as dirname4 } from "node:path";
8244
8417
  import { homedir as homedir4 } from "node:os";
8245
8418
  function safeReadJson(path) {
@@ -8257,8 +8430,8 @@ function safeWriteJson(path, data, dryRun = false) {
8257
8430
  return;
8258
8431
  const dir = dirname4(path);
8259
8432
  if (!existsSync20(dir))
8260
- mkdirSync10(dir, { recursive: true });
8261
- writeFileSync8(path, JSON.stringify(data, null, 2) + `
8433
+ mkdirSync11(dir, { recursive: true });
8434
+ writeFileSync9(path, JSON.stringify(data, null, 2) + `
8262
8435
  `, "utf8");
8263
8436
  }
8264
8437
  function safeReadYaml(path) {
@@ -8277,9 +8450,9 @@ function safeWriteYaml(path, data, dryRun = false) {
8277
8450
  return;
8278
8451
  const dir = dirname4(path);
8279
8452
  if (!existsSync20(dir))
8280
- mkdirSync10(dir, { recursive: true });
8453
+ mkdirSync11(dir, { recursive: true });
8281
8454
  const dumped = yaml.dump(data, { indent: 2, lineWidth: -1 });
8282
- writeFileSync8(path, dumped, "utf8");
8455
+ writeFileSync9(path, dumped, "utf8");
8283
8456
  }
8284
8457
  function resolveAgentConfigFile(agent, home, foundConfig) {
8285
8458
  if (foundConfig && existsSync20(foundConfig)) {
@@ -8669,8 +8842,8 @@ __export(exports_hook, {
8669
8842
  import {
8670
8843
  existsSync as existsSync21,
8671
8844
  readFileSync as readFileSync17,
8672
- writeFileSync as writeFileSync9,
8673
- mkdirSync as mkdirSync11,
8845
+ writeFileSync as writeFileSync10,
8846
+ mkdirSync as mkdirSync12,
8674
8847
  readdirSync as readdirSync7,
8675
8848
  statSync as statSync7,
8676
8849
  renameSync as renameSync2,
@@ -8687,8 +8860,8 @@ function installGitHook(workspaceRoot) {
8687
8860
  if (existsSync21(hookPath)) {
8688
8861
  return { installed: false, path: hookPath, message: `pre-commit hook already exists at ${hookPath} — leaving it untouched` };
8689
8862
  }
8690
- mkdirSync11(hooksDir, { recursive: true });
8691
- writeFileSync9(hookPath, HOOK_SCRIPT, "utf8");
8863
+ mkdirSync12(hooksDir, { recursive: true });
8864
+ writeFileSync10(hookPath, HOOK_SCRIPT, "utf8");
8692
8865
  chmodSync(hookPath, 493);
8693
8866
  return { installed: true, path: hookPath, message: `installed pre-commit hook at ${hookPath}` };
8694
8867
  }
@@ -8750,7 +8923,7 @@ function harvestAuto(store, workspaceRoot, memoryDir, options = {}) {
8750
8923
  confirmed: false,
8751
8924
  source: "harvest_auto"
8752
8925
  });
8753
- mkdirSync11(processedDir, { recursive: true });
8926
+ mkdirSync12(processedDir, { recursive: true });
8754
8927
  const base = file.split("/").pop() ?? "transcript.jsonl";
8755
8928
  let dest = join18(processedDir, base);
8756
8929
  if (existsSync21(dest)) {
@@ -15402,7 +15575,7 @@ var init_doctor = __esm(() => {
15402
15575
  });
15403
15576
 
15404
15577
  // src/retrieval/tree-index.ts
15405
- import { existsSync as existsSync24, readFileSync as readFileSync20, writeFileSync as writeFileSync10, mkdirSync as mkdirSync12, rmSync } from "node:fs";
15578
+ import { existsSync as existsSync24, readFileSync as readFileSync20, writeFileSync as writeFileSync11, mkdirSync as mkdirSync13, rmSync } from "node:fs";
15406
15579
  import { join as join21 } from "node:path";
15407
15580
  function tokenize2(text) {
15408
15581
  if (!text || typeof text !== "string")
@@ -15512,7 +15685,7 @@ function countNodes(node) {
15512
15685
  function buildTreeIndex(store, memoryDir, config = {}) {
15513
15686
  const cfg = { ...DEFAULT_CONFIG, ...config };
15514
15687
  const allMemories = list(store).filter((e) => e.status === "confirmed");
15515
- mkdirSync12(indexDir(memoryDir), { recursive: true });
15688
+ mkdirSync13(indexDir(memoryDir), { recursive: true });
15516
15689
  if (allMemories.length === 0) {
15517
15690
  const emptyIndex = {
15518
15691
  version: 1,
@@ -15521,7 +15694,7 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15521
15694
  totalMemories: 0,
15522
15695
  builtAt: nowIso3()
15523
15696
  };
15524
- writeFileSync10(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(emptyIndex, null, 2), "utf8");
15697
+ writeFileSync11(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(emptyIndex, null, 2), "utf8");
15525
15698
  return emptyIndex;
15526
15699
  }
15527
15700
  const groups = new Map;
@@ -15539,7 +15712,7 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15539
15712
  for (const [key, memories] of groups) {
15540
15713
  const [project, type2] = key.split("|");
15541
15714
  const pDir = partitionDir(indexDir(memoryDir), project, type2);
15542
- mkdirSync12(pDir, { recursive: true });
15715
+ mkdirSync13(pDir, { recursive: true });
15543
15716
  const maxShardSize = cfg.shardThreshold || 1e4;
15544
15717
  const finalShards = [];
15545
15718
  const memoryChunks = [];
@@ -15600,9 +15773,9 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15600
15773
  partitions[`${project}|${type2}`] = partition;
15601
15774
  totalIndexNodes += partitionNodes;
15602
15775
  totalIndexMemories += partitionMemories;
15603
- writeFileSync10(partitionIndexFilePath(pDir), JSON.stringify(partition, null, 2), "utf8");
15776
+ writeFileSync11(partitionIndexFilePath(pDir), JSON.stringify(partition, null, 2), "utf8");
15604
15777
  for (const shard of finalShards) {
15605
- writeFileSync10(shardFilePath(pDir, shard.id), JSON.stringify(shard, null, 2), "utf8");
15778
+ writeFileSync11(shardFilePath(pDir, shard.id), JSON.stringify(shard, null, 2), "utf8");
15606
15779
  }
15607
15780
  }
15608
15781
  const index = {
@@ -15612,7 +15785,7 @@ function buildTreeIndex(store, memoryDir, config = {}) {
15612
15785
  totalMemories: totalIndexMemories,
15613
15786
  builtAt: nowIso3()
15614
15787
  };
15615
- writeFileSync10(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(index, null, 2), "utf8");
15788
+ writeFileSync11(globalIndexFilePath(indexDir(memoryDir)), JSON.stringify(index, null, 2), "utf8");
15616
15789
  return index;
15617
15790
  }
15618
15791
  function loadTreeIndex(memoryDir) {
@@ -15765,7 +15938,7 @@ __export(exports_vector, {
15765
15938
  saveIndex: () => saveIndex,
15766
15939
  termFrequencies: () => termFrequencies
15767
15940
  });
15768
- import { existsSync as existsSync25, readFileSync as readFileSync21, writeFileSync as writeFileSync11, mkdirSync as mkdirSync13 } from "node:fs";
15941
+ import { existsSync as existsSync25, readFileSync as readFileSync21, writeFileSync as writeFileSync12, mkdirSync as mkdirSync14 } from "node:fs";
15769
15942
  import { join as join22 } from "node:path";
15770
15943
  function indexFilePath(memoryDir) {
15771
15944
  return join22(memoryDir, "index.json");
@@ -15816,8 +15989,8 @@ function rebuildIndex(store) {
15816
15989
  }
15817
15990
  function saveIndex(index, memoryDir) {
15818
15991
  if (!existsSync25(memoryDir))
15819
- mkdirSync13(memoryDir, { recursive: true });
15820
- writeFileSync11(indexFilePath(memoryDir), JSON.stringify(index), "utf8");
15992
+ mkdirSync14(memoryDir, { recursive: true });
15993
+ writeFileSync12(indexFilePath(memoryDir), JSON.stringify(index), "utf8");
15821
15994
  }
15822
15995
  function loadIndex(memoryDir) {
15823
15996
  const p = indexFilePath(memoryDir);
@@ -15896,7 +16069,7 @@ var init_vector = __esm(() => {
15896
16069
  });
15897
16070
 
15898
16071
  // src/pageindex/engine.ts
15899
- import { existsSync as existsSync26, mkdirSync as mkdirSync14, readFileSync as readFileSync22, writeFileSync as writeFileSync12, rmSync as rmSync2, readdirSync as readdirSync9 } from "node:fs";
16072
+ import { existsSync as existsSync26, mkdirSync as mkdirSync15, readFileSync as readFileSync22, writeFileSync as writeFileSync13, rmSync as rmSync2, readdirSync as readdirSync9 } from "node:fs";
15900
16073
  import { join as join23 } from "node:path";
15901
16074
  function slugify2(text) {
15902
16075
  return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 50);
@@ -15975,8 +16148,8 @@ function buildPageIndex(content, options) {
15975
16148
  };
15976
16149
  if (options.memoryDir && !options.dryRun) {
15977
16150
  const dir = join23(options.memoryDir, "pageindex", project);
15978
- mkdirSync14(dir, { recursive: true });
15979
- writeFileSync12(join23(dir, `${indexId}.json`), JSON.stringify(doc, null, 2), "utf8");
16151
+ mkdirSync15(dir, { recursive: true });
16152
+ writeFileSync13(join23(dir, `${indexId}.json`), JSON.stringify(doc, null, 2), "utf8");
15980
16153
  }
15981
16154
  return doc;
15982
16155
  }
@@ -25867,7 +26040,7 @@ var init_loops = __esm(() => {
25867
26040
  });
25868
26041
 
25869
26042
  // src/distill.ts
25870
- import { existsSync as existsSync28, mkdirSync as mkdirSync15, writeFileSync as writeFileSync13 } from "node:fs";
26043
+ import { existsSync as existsSync28, mkdirSync as mkdirSync16, writeFileSync as writeFileSync14 } from "node:fs";
25871
26044
  import { join as join25 } from "node:path";
25872
26045
  function fixTokens(e) {
25873
26046
  const bag = tokenBag(e.title, 2);
@@ -25899,8 +26072,8 @@ function distillSkills(store, workspaceRoot, options = {}) {
25899
26072
  throw new Error(`Secret detected in generated SKILL.md for '${slug}': ${secrets.join(", ")}`);
25900
26073
  }
25901
26074
  if (!options.dryRun) {
25902
- mkdirSync15(dir, { recursive: true });
25903
- writeFileSync13(join25(dir, "SKILL.md"), md, "utf8");
26075
+ mkdirSync16(dir, { recursive: true });
26076
+ writeFileSync14(join25(dir, "SKILL.md"), md, "utf8");
25904
26077
  }
25905
26078
  report.created.push({ slug, path: join25(dir, "SKILL.md"), members: memberIds });
25906
26079
  }
@@ -26240,7 +26413,7 @@ var init_schema2 = __esm(() => {
26240
26413
  });
26241
26414
 
26242
26415
  // src/settings/loader.ts
26243
- import { existsSync as existsSync29, mkdirSync as mkdirSync16, readFileSync as readFileSync23, writeFileSync as writeFileSync14 } from "node:fs";
26416
+ import { existsSync as existsSync29, mkdirSync as mkdirSync17, readFileSync as readFileSync23, writeFileSync as writeFileSync15 } from "node:fs";
26244
26417
  import { join as join26 } from "node:path";
26245
26418
  function getSettingsFilePath(memoryDir) {
26246
26419
  return join26(memoryDir, "settings.json");
@@ -26271,9 +26444,9 @@ function loadSettings(memoryDir) {
26271
26444
  }
26272
26445
  }
26273
26446
  function saveSettings(store, memoryDir) {
26274
- mkdirSync16(memoryDir, { recursive: true });
26447
+ mkdirSync17(memoryDir, { recursive: true });
26275
26448
  const filePath = getSettingsFilePath(memoryDir);
26276
- writeFileSync14(filePath, JSON.stringify(store, null, 2), "utf8");
26449
+ writeFileSync15(filePath, JSON.stringify(store, null, 2), "utf8");
26277
26450
  }
26278
26451
  function getSettings(memoryDir) {
26279
26452
  return loadSettings(memoryDir).global;
@@ -26832,6 +27005,14 @@ You are equipped with Muse Memory, an autonomous persistent cognitive memory sys
26832
27005
  properties: {}
26833
27006
  }
26834
27007
  },
27008
+ {
27009
+ name: "graph_index",
27010
+ description: "Index AST symbols from the project's CodeGraph/Graphify provider and cache in .memory/",
27011
+ inputSchema: {
27012
+ type: "object",
27013
+ properties: {}
27014
+ }
27015
+ },
26835
27016
  {
26836
27017
  name: "memory_tree_search",
26837
27018
  description: "Hierarchical tree-indexed reasoning search across partitioned memory shards",
@@ -27267,6 +27448,10 @@ Resolution: ${String(a.resolution)}`;
27267
27448
  const status = getGraphStatus(activeRoot);
27268
27449
  return toolResult(status);
27269
27450
  }
27451
+ case "graph_index": {
27452
+ const index = indexGraph(activeRoot, activeMemoryDir);
27453
+ return toolResult(index);
27454
+ }
27270
27455
  case "memory_detect_providers": {
27271
27456
  const detected = detectProviders(activeRoot);
27272
27457
  return toolResult(detected);
@@ -27628,7 +27813,7 @@ var init_daemon = () => {};
27628
27813
 
27629
27814
  // src/cli/ecosystem.ts
27630
27815
  import { join as join28 } from "node:path";
27631
- import { existsSync as existsSync31, mkdirSync as mkdirSync17, writeFileSync as writeFileSync15, readFileSync as readFileSync24 } from "node:fs";
27816
+ import { existsSync as existsSync31, mkdirSync as mkdirSync18, writeFileSync as writeFileSync16, readFileSync as readFileSync24 } from "node:fs";
27632
27817
  import { homedir as homedir6 } from "node:os";
27633
27818
  function ensureProjectAgentInstructions(targetDir) {
27634
27819
  const agentsMdPath = join28(targetDir, "AGENTS.md");
@@ -27637,9 +27822,9 @@ function ensureProjectAgentInstructions(targetDir) {
27637
27822
  const existing = readFileSync24(agentsMdPath, "utf8");
27638
27823
  if (existing.includes("<!-- agentmemory:start -->")) {
27639
27824
  const updated = existing.replace(/<!-- agentmemory:start -->[\s\S]*?<!-- agentmemory:end -->/, MUSE_MEMORY_DIRECTIVE);
27640
- writeFileSync15(agentsMdPath, updated, "utf8");
27825
+ writeFileSync16(agentsMdPath, updated, "utf8");
27641
27826
  } else if (!existing.includes("<!-- musememory:start -->") && !existing.includes("Muse Memory")) {
27642
- writeFileSync15(agentsMdPath, `${existing.trim()}
27827
+ writeFileSync16(agentsMdPath, `${existing.trim()}
27643
27828
 
27644
27829
  ${MUSE_MEMORY_DIRECTIVE}
27645
27830
  `, "utf8");
@@ -27650,7 +27835,7 @@ ${MUSE_MEMORY_DIRECTIVE}
27650
27835
 
27651
27836
  ${MUSE_MEMORY_DIRECTIVE}
27652
27837
  `;
27653
- writeFileSync15(agentsMdPath, initialContent, "utf8");
27838
+ writeFileSync16(agentsMdPath, initialContent, "utf8");
27654
27839
  }
27655
27840
  }
27656
27841
  async function handleInstallCommand({ positional, flags }) {
@@ -27658,11 +27843,11 @@ async function handleInstallCommand({ positional, flags }) {
27658
27843
  const targetDir = positional[0] ? join28(process.cwd(), positional[0]) : process.cwd();
27659
27844
  const memoryDir = isGlobal ? getGlobalMemoryDir() : join28(targetDir, ".memory");
27660
27845
  const globalDir = getGlobalMemoryDir();
27661
- mkdirSync17(join28(memoryDir, "memories"), { recursive: true });
27662
- mkdirSync17(join28(globalDir, "memories"), { recursive: true });
27846
+ mkdirSync18(join28(memoryDir, "memories"), { recursive: true });
27847
+ mkdirSync18(join28(globalDir, "memories"), { recursive: true });
27663
27848
  const currentPath = join28(memoryDir, "CURRENT.md");
27664
27849
  if (!existsSync31(currentPath)) {
27665
- writeFileSync15(currentPath, `# Active Project Constraints
27850
+ writeFileSync16(currentPath, `# Active Project Constraints
27666
27851
  `, "utf8");
27667
27852
  }
27668
27853
  const globalUserPath = userFilePath(globalDir);
@@ -27688,7 +27873,7 @@ async function handleInstallCommand({ positional, flags }) {
27688
27873
  const existing = readFileSync24(globalAgentsMd, "utf8");
27689
27874
  if (existing.includes("<!-- agentmemory:start -->")) {
27690
27875
  const updated = existing.replace(/<!-- agentmemory:start -->[\s\S]*?<!-- agentmemory:end -->/, MUSE_MEMORY_DIRECTIVE);
27691
- writeFileSync15(globalAgentsMd, updated, "utf8");
27876
+ writeFileSync16(globalAgentsMd, updated, "utf8");
27692
27877
  }
27693
27878
  } catch {}
27694
27879
  }
@@ -27780,10 +27965,10 @@ async function handleInitCommand({ positional, flags }) {
27780
27965
  const targetDir = positional[0] ? join28(process.cwd(), positional[0]) : process.cwd();
27781
27966
  const memoryDirName = flags["legacy"] === "true" ? ".musememory" : ".memory";
27782
27967
  const memoryDir = isGlobal ? getGlobalMemoryDir() : join28(targetDir, memoryDirName);
27783
- mkdirSync17(join28(memoryDir, "memories"), { recursive: true });
27968
+ mkdirSync18(join28(memoryDir, "memories"), { recursive: true });
27784
27969
  const currentPath = join28(memoryDir, "CURRENT.md");
27785
27970
  if (!existsSync31(currentPath)) {
27786
- writeFileSync15(currentPath, `# Active Project Constraints
27971
+ writeFileSync16(currentPath, `# Active Project Constraints
27787
27972
  `, "utf8");
27788
27973
  }
27789
27974
  if (!isGlobal) {
@@ -27974,7 +28159,7 @@ async function handleGraphCommand({ positional, flags }) {
27974
28159
  const ctx = requireRoot(flags);
27975
28160
  if (!ctx)
27976
28161
  return 1;
27977
- const sub = positional[0];
28162
+ const sub = positional[0] ?? "status";
27978
28163
  if (sub === "status") {
27979
28164
  const status = getGraphStatus(ctx.root);
27980
28165
  console.log(`graph provider: ${status.provider}`);
@@ -27986,7 +28171,13 @@ async function handleGraphCommand({ positional, flags }) {
27986
28171
  console.log(`symbols: ${status.symbolCount}`);
27987
28172
  return 0;
27988
28173
  }
27989
- return usageError("graph requires status");
28174
+ if (sub === "index") {
28175
+ const index = indexGraph(ctx.root, ctx.memoryDir);
28176
+ console.log(`[AST Graph] Indexed ${index.symbolCount} symbols from provider "${index.provider}"`);
28177
+ console.log(`Cached symbol index at: ${ctx.memoryDir}/graph-symbols.json`);
28178
+ return 0;
28179
+ }
28180
+ return usageError("graph requires 'status' or 'index'");
27990
28181
  }
27991
28182
  async function handleMcpCommand() {
27992
28183
  const { runMcpServer: runMcpServer2 } = await Promise.resolve().then(() => (init_mcp(), exports_mcp));
@@ -28670,7 +28861,7 @@ var init_entities2 = __esm(() => {
28670
28861
  });
28671
28862
 
28672
28863
  // src/cli/settings.ts
28673
- import { writeFileSync as writeFileSync16, readFileSync as readFileSync26 } from "node:fs";
28864
+ import { writeFileSync as writeFileSync17, readFileSync as readFileSync26 } from "node:fs";
28674
28865
  function handleSettingsCommand(parsed) {
28675
28866
  const ctx = requireRoot(parsed.flags);
28676
28867
  if (!ctx)
@@ -28752,7 +28943,7 @@ function handleSettingsCommand(parsed) {
28752
28943
  const out = parsed.flags.out;
28753
28944
  const json2 = exportSettings(memoryDir);
28754
28945
  if (out) {
28755
- writeFileSync16(out, json2, "utf8");
28946
+ writeFileSync17(out, json2, "utf8");
28756
28947
  console.log(`Exported settings to ${out}`);
28757
28948
  } else {
28758
28949
  console.log(json2);
@@ -28836,7 +29027,7 @@ var init_routines = __esm(() => {
28836
29027
  });
28837
29028
 
28838
29029
  // src/cli/lifecycle.ts
28839
- import { writeFileSync as writeFileSync17, readFileSync as readFileSync28, existsSync as existsSync35 } from "node:fs";
29030
+ import { writeFileSync as writeFileSync18, readFileSync as readFileSync28, existsSync as existsSync35 } from "node:fs";
28840
29031
  async function handleProposeCommand({ positional, flags }) {
28841
29032
  const ctx = requireRoot(flags);
28842
29033
  if (!ctx)
@@ -28985,7 +29176,7 @@ async function handleExportCommand({ flags }) {
28985
29176
  const snapshot = exportSnapshot(ctx.store);
28986
29177
  const outPath = flags["out"];
28987
29178
  if (outPath) {
28988
- writeFileSync17(outPath, JSON.stringify(snapshot, null, 2), "utf8");
29179
+ writeFileSync18(outPath, JSON.stringify(snapshot, null, 2), "utf8");
28989
29180
  console.log(`exported ${snapshot.total} memories to ${outPath}`);
28990
29181
  } else {
28991
29182
  console.log(JSON.stringify(snapshot, null, 2));
@@ -29540,7 +29731,7 @@ Ecosystem, Migration & Connectivity:
29540
29731
  export [--out file.json] Export portable JSON memory snapshot
29541
29732
  import <file.json> Import portable JSON memory snapshot
29542
29733
  validate [--dry-run] Validate YAML schemas and referential integrity
29543
- graph status Inspect CodeGraph AST provider status
29734
+ graph [status|index] Inspect or index CodeGraph/Graphify AST provider symbols
29544
29735
  ui / dashboard [--port 2222] Launch embedded visual knowledge graph UI
29545
29736
  daemon [--port N] Real-time agency hub (SSE event stream + publish API, default port 7878)
29546
29737
  mcp Run stdio MCP server for agent platforms