memorix 1.8.1 → 1.8.2

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cli/index.js +326 -52
  3. package/dist/index.js +581 -315
  4. package/dist/maintenance-runner.js +31 -25
  5. package/dist/media-audio-runner.js +31 -25
  6. package/dist/media-video-runner.js +31 -25
  7. package/dist/memcode-runtime/CHANGELOG.md +20 -0
  8. package/dist/sdk.js +573 -314
  9. package/dist/vector-backfill-runner.js +31 -25
  10. package/docs/1.2.0-PROVIDER-QUALITY.md +15 -6
  11. package/docs/1.3.3-MULTIMODAL-MEDIA-AND-MCP-COMPAT.md +7 -6
  12. package/docs/1.8.0-RELEASE-CANDIDATE-SPEC.md +10 -8
  13. package/docs/API_REFERENCE.md +10 -8
  14. package/docs/CONFIGURATION.md +2 -2
  15. package/docs/DEVELOPMENT.md +2 -2
  16. package/docs/README.md +10 -7
  17. package/package.json +1 -1
  18. package/plugins/antigravity/memorix/plugin.json +2 -1
  19. package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
  20. package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
  21. package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
  22. package/plugins/copilot/memorix/plugin.json +1 -1
  23. package/plugins/gemini/memorix/gemini-extension.json +1 -1
  24. package/plugins/hermes/memorix/plugin.yaml +1 -1
  25. package/plugins/omp/memorix/package.json +1 -1
  26. package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
  27. package/plugins/pi/memorix/package.json +1 -1
  28. package/server.json +3 -3
  29. package/src/cli/commands/serve-http.ts +10 -2
  30. package/src/codegraph/external-provider.ts +299 -19
  31. package/src/config/dotenv-loader.ts +9 -4
  32. package/src/config.ts +16 -16
  33. package/src/dashboard/maintenance.ts +4 -1
  34. package/src/llm/provider.ts +17 -4
  35. package/src/server/mcp-compat.ts +82 -0
  36. package/src/server/mcp-diagnostics.ts +13 -4
  37. package/src/server.ts +5 -2
package/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [1.8.2] - 2026-08-25
8
+
9
+ ### Fixed
10
+ - **Dashboard deduplication initialization (#248)** -- standalone and HTTP
11
+ maintenance previews now idempotently resolve the selected project's memory
12
+ LLM from TOML and `.env`, clear stale cross-project configuration, and keep
13
+ credentials out of responses.
14
+ - **CodeGraph capability fallback (#250)** -- a failed or invalid `context`
15
+ probe now tries the official `explore` CLI with bounded, shell-free spawning.
16
+ Only validated paths, symbols, and relationships can select the external
17
+ provider; separate context/explore diagnostics explain Lite fallback.
18
+
19
+ ### MCP Compatibility
20
+ - **Discovery adapter (#249)** -- the stdio server registers a real low-level
21
+ `server/discover` handler that returns the required 2026-07-28
22
+ `DiscoverResult` before `initialize`. Legacy 2025 initialize and versionless
23
+ `tools/list`/`tools/call` remain supported through the SDK's legacy envelopes.
24
+ Tasks, subscriptions, and list-response caching remain unsupported and are
25
+ not advertised.
26
+
7
27
  ## [1.8.1] - 2026-08-24
8
28
 
9
29
  ### Changed
package/dist/cli/index.js CHANGED
@@ -3232,7 +3232,7 @@ ${import_picocolors.default.gray(m3)} ${s4}
3232
3232
 
3233
3233
  // src/cli/version.ts
3234
3234
  function getCliVersion() {
3235
- return true ? "1.8.1" : pkg.version;
3235
+ return true ? "1.8.2" : pkg.version;
3236
3236
  }
3237
3237
  var init_version = __esm({
3238
3238
  "src/cli/version.ts"() {
@@ -21630,8 +21630,10 @@ function loadEnvFile(filePath) {
21630
21630
  loadedEnvFiles.push(filePath);
21631
21631
  }
21632
21632
  function loadDotenv(projectRoot, options = {}) {
21633
- if (dotenvLoaded && dotenvProjectRoot === (projectRoot ?? null)) return;
21634
- if (dotenvLoaded && dotenvProjectRoot !== (projectRoot ?? null)) {
21633
+ const userHomeDir = options.userHomeDir ?? homedir4();
21634
+ const normalizedProjectRoot = projectRoot ?? null;
21635
+ if (dotenvLoaded && dotenvProjectRoot === normalizedProjectRoot && dotenvHomeDir === userHomeDir) return;
21636
+ if (dotenvLoaded && (dotenvProjectRoot !== normalizedProjectRoot || dotenvHomeDir !== userHomeDir)) {
21635
21637
  resetDotenv();
21636
21638
  }
21637
21639
  loadedEnvFiles.length = 0;
@@ -21640,9 +21642,10 @@ function loadDotenv(projectRoot, options = {}) {
21640
21642
  if (projectRoot) {
21641
21643
  loadEnvFile(getProjectDotenvPath(projectRoot));
21642
21644
  }
21643
- loadEnvFile(getGlobalDotenvPath(options.userHomeDir ?? homedir4()));
21645
+ loadEnvFile(getGlobalDotenvPath(userHomeDir));
21644
21646
  dotenvLoaded = true;
21645
- dotenvProjectRoot = projectRoot ?? null;
21647
+ dotenvProjectRoot = normalizedProjectRoot;
21648
+ dotenvHomeDir = userHomeDir;
21646
21649
  }
21647
21650
  function resetDotenv() {
21648
21651
  for (const key of injectedKeys) {
@@ -21651,6 +21654,7 @@ function resetDotenv() {
21651
21654
  injectedKeys.clear();
21652
21655
  dotenvLoaded = false;
21653
21656
  dotenvProjectRoot = null;
21657
+ dotenvHomeDir = null;
21654
21658
  loadedEnvFiles.length = 0;
21655
21659
  loadedEnvKeys.clear();
21656
21660
  }
@@ -21663,7 +21667,7 @@ function getLoadedEnvKeys() {
21663
21667
  function getLoadedEnvValue(key) {
21664
21668
  return loadedEnvValues.get(key);
21665
21669
  }
21666
- var import_dotenv, dotenvLoaded, dotenvProjectRoot, loadedEnvFiles, loadedEnvKeys, loadedEnvValues, injectedKeys;
21670
+ var import_dotenv, dotenvLoaded, dotenvProjectRoot, dotenvHomeDir, loadedEnvFiles, loadedEnvKeys, loadedEnvValues, injectedKeys;
21667
21671
  var init_dotenv_loader = __esm({
21668
21672
  "src/config/dotenv-loader.ts"() {
21669
21673
  "use strict";
@@ -21672,6 +21676,7 @@ var init_dotenv_loader = __esm({
21672
21676
  init_config_paths();
21673
21677
  dotenvLoaded = false;
21674
21678
  dotenvProjectRoot = null;
21679
+ dotenvHomeDir = null;
21675
21680
  loadedEnvFiles = [];
21676
21681
  loadedEnvKeys = /* @__PURE__ */ new Set();
21677
21682
  loadedEnvValues = /* @__PURE__ */ new Map();
@@ -22023,33 +22028,33 @@ __export(config_exports, {
22023
22028
  resetConfigCache: () => resetConfigCache,
22024
22029
  resetDotenv: () => resetDotenv
22025
22030
  });
22026
- function getLLMApiKey() {
22027
- return getResolvedMemoryLane().llm.apiKey;
22031
+ function getLLMApiKey(options = {}) {
22032
+ return getResolvedMemoryLane(options).llm.apiKey;
22028
22033
  }
22029
- function getLLMProvider() {
22030
- const provider2 = getResolvedMemoryLane().llm.provider;
22034
+ function getLLMProvider(options = {}) {
22035
+ const provider2 = getResolvedMemoryLane(options).llm.provider;
22031
22036
  if (provider2) return provider2;
22032
22037
  if (process.env.ANTHROPIC_API_KEY && !process.env.OPENAI_API_KEY) return "anthropic";
22033
22038
  if (process.env.OPENROUTER_API_KEY && !process.env.OPENAI_API_KEY) return "openrouter";
22034
22039
  return "openai";
22035
22040
  }
22036
- function getLLMModel(providerDefault) {
22037
- return getResolvedMemoryLane().llm.model || providerDefault;
22041
+ function getLLMModel(providerDefault, options = {}) {
22042
+ return getResolvedMemoryLane(options).llm.model || providerDefault;
22038
22043
  }
22039
- function getLLMBaseUrl(providerDefault) {
22040
- return getResolvedMemoryLane().llm.baseUrl || providerDefault;
22044
+ function getLLMBaseUrl(providerDefault, options = {}) {
22045
+ return getResolvedMemoryLane(options).llm.baseUrl || providerDefault;
22041
22046
  }
22042
- function getAgentLLMApiKey() {
22043
- return getResolvedAgentLane().apiKey;
22047
+ function getAgentLLMApiKey(options = {}) {
22048
+ return getResolvedAgentLane(options).apiKey;
22044
22049
  }
22045
- function getAgentLLMProvider() {
22046
- return getResolvedAgentLane().provider || getLLMProvider();
22050
+ function getAgentLLMProvider(options = {}) {
22051
+ return getResolvedAgentLane(options).provider || getLLMProvider(options);
22047
22052
  }
22048
- function getAgentLLMModel(providerDefault) {
22049
- return getResolvedAgentLane().model || getLLMModel(providerDefault);
22053
+ function getAgentLLMModel(providerDefault, options = {}) {
22054
+ return getResolvedAgentLane(options).model || getLLMModel(providerDefault, options);
22050
22055
  }
22051
- function getAgentLLMBaseUrl(providerDefault) {
22052
- return getResolvedAgentLane().baseUrl || getLLMBaseUrl(providerDefault);
22056
+ function getAgentLLMBaseUrl(providerDefault, options = {}) {
22057
+ return getResolvedAgentLane(options).baseUrl || getLLMBaseUrl(providerDefault, options);
22053
22058
  }
22054
22059
  function getEmbeddingMode() {
22055
22060
  const provider2 = getResolvedEmbeddingLane().provider?.toLowerCase()?.trim();
@@ -24308,18 +24313,19 @@ async function* callLLMWithToolsStream(messages, tools) {
24308
24313
  }
24309
24314
  function initLLM(options = {}) {
24310
24315
  const scope = options.scope ?? "memory";
24311
- const apiKey = scope === "agent" ? getAgentLLMApiKey() : getLLMApiKey();
24316
+ const configOptions = { projectRoot: options.projectRoot, homeDir: options.homeDir };
24317
+ const apiKey = scope === "agent" ? getAgentLLMApiKey(configOptions) : getLLMApiKey(configOptions);
24312
24318
  if (!apiKey) {
24313
24319
  currentConfig = null;
24314
24320
  return null;
24315
24321
  }
24316
- const provider2 = scope === "agent" ? getAgentLLMProvider() : getLLMProvider();
24322
+ const provider2 = scope === "agent" ? getAgentLLMProvider(configOptions) : getLLMProvider(configOptions);
24317
24323
  const defaults2 = PROVIDER_DEFAULTS[provider2] ?? PROVIDER_DEFAULTS.openai;
24318
24324
  currentConfig = {
24319
24325
  provider: provider2,
24320
24326
  apiKey,
24321
- model: scope === "agent" ? getAgentLLMModel(defaults2.model) : getLLMModel(defaults2.model),
24322
- baseUrl: scope === "agent" ? getAgentLLMBaseUrl(defaults2.baseUrl) : getLLMBaseUrl(defaults2.baseUrl)
24327
+ model: scope === "agent" ? getAgentLLMModel(defaults2.model, configOptions) : getLLMModel(defaults2.model, configOptions),
24328
+ baseUrl: scope === "agent" ? getAgentLLMBaseUrl(defaults2.baseUrl, configOptions) : getLLMBaseUrl(defaults2.baseUrl, configOptions)
24323
24329
  };
24324
24330
  return currentConfig;
24325
24331
  }
@@ -197170,6 +197176,27 @@ function unavailableHealth(result) {
197170
197176
  if (result.outputLimited) return { state: "invalid", reason: "A local CodeGraph response exceeded the safety limit." };
197171
197177
  return { state: "unavailable", reason: "A local CodeGraph command did not complete." };
197172
197178
  }
197179
+ function notAttemptedDiagnostic(command) {
197180
+ return { command, attempted: false, outcome: "not-attempted" };
197181
+ }
197182
+ function commandDiagnostic(command, result, outcome, reason) {
197183
+ return {
197184
+ command,
197185
+ attempted: true,
197186
+ outcome,
197187
+ ...typeof result.exitCode === "number" ? { exitCode: result.exitCode } : {},
197188
+ ...reason ? { reason: sanitizeCredentials(reason).slice(0, 240) } : {}
197189
+ };
197190
+ }
197191
+ function failedCommandDiagnostic(command, result) {
197192
+ const outcome = result.timedOut ? "timed-out" : result.outputLimited ? "output-limited" : "failed";
197193
+ return commandDiagnostic(
197194
+ command,
197195
+ result,
197196
+ outcome,
197197
+ result.error || result.stderr || "CodeGraph command did not complete."
197198
+ );
197199
+ }
197173
197200
  async function runSafely(runner, input) {
197174
197201
  try {
197175
197202
  return await runner.run(input);
@@ -197319,6 +197346,7 @@ function parseOutline(value, projectRoot, exclude) {
197319
197346
  if (nodes.some((node) => !node)) return void 0;
197320
197347
  const byId = /* @__PURE__ */ new Map();
197321
197348
  for (const node of nodes) {
197349
+ if (byId.has(node.id)) return void 0;
197322
197350
  byId.set(node.id, externalSymbol(node));
197323
197351
  }
197324
197352
  const entryPoints = value.entryPoints.map((item) => parseNode(item, projectRoot, exclude)).filter((node) => Boolean(node)).map(externalSymbol).filter((node, index, items) => items.findIndex((item) => item.id === node.id) === index).slice(0, 5);
@@ -197332,7 +197360,7 @@ function parseOutline(value, projectRoot, exclude) {
197332
197360
  if (!source || !target || !kind || rawEdge.line !== void 0 && (!line || line < 1)) return void 0;
197333
197361
  const from = byId.get(source);
197334
197362
  const to2 = byId.get(target);
197335
- if (!from || !to2) continue;
197363
+ if (!from || !to2) return void 0;
197336
197364
  relations.push({ from, to: to2, kind, ...line ? { line } : {} });
197337
197365
  }
197338
197366
  const relatedFiles = value.relatedFiles.map((item) => safeRelativePath(projectRoot, item, exclude));
@@ -197350,45 +197378,234 @@ function parseOutline(value, projectRoot, exclude) {
197350
197378
  stats: { nodes: nodeCount, edges: edgeCount, files: fileCount }
197351
197379
  };
197352
197380
  }
197381
+ function parseTextLocation(value) {
197382
+ const match2 = value.trim().match(/^(.*?)(?::([1-9]\d*))?$/);
197383
+ if (!match2?.[1]) return void 0;
197384
+ return {
197385
+ filePath: match2[1].trim(),
197386
+ ...match2[2] ? { line: Number(match2[2]) } : {}
197387
+ };
197388
+ }
197389
+ function parseExploreText(value, projectRoot, exclude) {
197390
+ if (!value.trim() || Buffer.byteLength(value, "utf8") > MAX_EXTERNAL_CODEGRAPH_OUTPUT_BYTES) return void 0;
197391
+ const entryPoints = [];
197392
+ const nodes = [];
197393
+ const relatedFiles = /* @__PURE__ */ new Set();
197394
+ const byName = /* @__PURE__ */ new Map();
197395
+ let section2 = null;
197396
+ let relationKind = "references";
197397
+ const addNode = (node, entry) => {
197398
+ const key = `${node.filePath}\0${node.name}`;
197399
+ const existing = byName.get(key);
197400
+ if (existing) return;
197401
+ byName.set(key, node);
197402
+ relatedFiles.add(node.filePath);
197403
+ (entry ? entryPoints : nodes).push(node);
197404
+ };
197405
+ for (const rawLine of value.split(/\r?\n/)) {
197406
+ const line = rawLine.trim();
197407
+ const fileHeader = line.match(/^\*\*`([^`]+)`\*\*\s+(?:—|-)\s+(.+)$/);
197408
+ if (fileHeader) {
197409
+ const filePath = safeRelativePath(projectRoot, fileHeader[1], exclude);
197410
+ if (!filePath) return void 0;
197411
+ const symbolText = fileHeader[2].split(/\s+·\s+/, 1)[0] ?? "";
197412
+ const symbols = [...symbolText.matchAll(/([^,]+?)\(([^()]+)\)/g)];
197413
+ if (symbols.length === 0) return void 0;
197414
+ const isFirstFile = entryPoints.length === 0 && nodes.length === 0;
197415
+ for (const symbol2 of symbols.slice(0, MAX_EXTERNAL_NODE_COUNT)) {
197416
+ const name = symbol2[1]?.trim();
197417
+ const kind = symbol2[2]?.trim();
197418
+ if (!name || !kind) return void 0;
197419
+ addNode({
197420
+ id: `explore:${filePath}:${name}`,
197421
+ kind,
197422
+ name,
197423
+ filePath
197424
+ }, isFirstFile);
197425
+ }
197426
+ section2 = null;
197427
+ continue;
197428
+ }
197429
+ if (/^#{2,3}\s+Entry Points?\b/i.test(line)) {
197430
+ section2 = "entry";
197431
+ continue;
197432
+ }
197433
+ if (/^#{2,3}\s+Related Symbols?\b/i.test(line)) {
197434
+ section2 = "related";
197435
+ continue;
197436
+ }
197437
+ if (/^\*\*Relationships\*\*$/i.test(line)) {
197438
+ section2 = "relationships";
197439
+ continue;
197440
+ }
197441
+ if (/^\*\*(?:Source Code|Code)\*\*$/i.test(line) || /^#{2,3}\s+/i.test(line)) {
197442
+ section2 = null;
197443
+ continue;
197444
+ }
197445
+ if (section2 === "entry") {
197446
+ const match2 = line.match(/^-\s+\*\*(.+?)\*\*\s+\(([^)]+)\)\s+-\s+(.+)$/);
197447
+ if (!match2) continue;
197448
+ const location = parseTextLocation(match2[3]);
197449
+ if (!location) return void 0;
197450
+ const filePath = safeRelativePath(projectRoot, location.filePath, exclude);
197451
+ if (!filePath) return void 0;
197452
+ addNode({
197453
+ id: `explore:${filePath}:${match2[1]}`,
197454
+ kind: match2[2],
197455
+ name: match2[1],
197456
+ filePath,
197457
+ ...location.line ? { startLine: location.line, endLine: location.line } : {}
197458
+ }, true);
197459
+ continue;
197460
+ }
197461
+ if (section2 === "related") {
197462
+ const match2 = line.match(/^-\s+([^:]+):\s+(.+)$/);
197463
+ if (!match2) continue;
197464
+ const filePath = safeRelativePath(projectRoot, match2[1], exclude);
197465
+ if (!filePath) return void 0;
197466
+ relatedFiles.add(filePath);
197467
+ for (const rawSymbol of match2[2].split(",")) {
197468
+ const symbol2 = rawSymbol.trim().match(/^(.+?)(?::([1-9]\d*))?$/);
197469
+ if (!symbol2?.[1]) return void 0;
197470
+ addNode({
197471
+ id: `explore:${filePath}:${symbol2[1].trim()}`,
197472
+ kind: "unknown",
197473
+ name: symbol2[1].trim(),
197474
+ filePath,
197475
+ ...symbol2[2] ? { startLine: Number(symbol2[2]), endLine: Number(symbol2[2]) } : {}
197476
+ }, false);
197477
+ }
197478
+ continue;
197479
+ }
197480
+ if (section2 === "relationships") {
197481
+ const kind = line.match(/^\*\*([^*]+):\*\*$/);
197482
+ if (kind?.[1]) {
197483
+ relationKind = kind[1].trim();
197484
+ continue;
197485
+ }
197486
+ }
197487
+ }
197488
+ const bySymbolName = /* @__PURE__ */ new Map();
197489
+ for (const node of [...entryPoints, ...nodes]) {
197490
+ if (!bySymbolName.has(node.name)) bySymbolName.set(node.name, node);
197491
+ }
197492
+ const relations = [];
197493
+ if (section2 === "relationships") {
197494
+ for (const rawLine of value.split(/\r?\n/)) {
197495
+ const line = rawLine.trim();
197496
+ const match2 = line.match(/^-\s+(.+?)\s+(?:\u2192|->)\s+(.+)$/);
197497
+ if (!match2) continue;
197498
+ const from = bySymbolName.get(match2[1].trim());
197499
+ const to2 = bySymbolName.get(match2[2].trim());
197500
+ if (!from || !to2) continue;
197501
+ relations.push({
197502
+ from: externalSymbol(from),
197503
+ to: externalSymbol(to2),
197504
+ kind: relationKind
197505
+ });
197506
+ }
197507
+ } else {
197508
+ const relationshipStart = value.split(/\r?\n/).findIndex((line) => /^\s*\*\*Relationships\*\*\s*$/i.test(line));
197509
+ if (relationshipStart >= 0) {
197510
+ const relationshipLines = value.split(/\r?\n/).slice(relationshipStart + 1);
197511
+ for (const rawLine of relationshipLines) {
197512
+ const line = rawLine.trim();
197513
+ if (/^\*\*(?:Source Code|Code)\*\*$/i.test(line) || /^#{2,3}\s+/i.test(line)) break;
197514
+ const kind = line.match(/^\*\*([^*]+):\*\*$/);
197515
+ if (kind?.[1]) {
197516
+ relationKind = kind[1].trim();
197517
+ continue;
197518
+ }
197519
+ const match2 = line.match(/^-\s+(.+?)\s+(?:\u2192|->)\s+(.+)$/);
197520
+ if (!match2) continue;
197521
+ const from = bySymbolName.get(match2[1].trim());
197522
+ const to2 = bySymbolName.get(match2[2].trim());
197523
+ if (from && to2) relations.push({ from: externalSymbol(from), to: externalSymbol(to2), kind: relationKind });
197524
+ }
197525
+ }
197526
+ }
197527
+ const allNodes = [...entryPoints, ...nodes];
197528
+ if (allNodes.length === 0) return void 0;
197529
+ return {
197530
+ provider: "external",
197531
+ entryPoints: entryPoints.map(externalSymbol).slice(0, 5),
197532
+ relations: relations.slice(0, 6),
197533
+ relatedFiles: [...relatedFiles].slice(0, 5),
197534
+ stats: {
197535
+ nodes: allNodes.length,
197536
+ edges: relations.length,
197537
+ files: relatedFiles.size
197538
+ }
197539
+ };
197540
+ }
197541
+ function parseExplorePayload(value, projectRoot, exclude) {
197542
+ if (typeof value === "string") return parseExploreText(value, projectRoot, exclude);
197543
+ if (isRecord3(value) && isRecord3(value.result)) value = value.result;
197544
+ if (isRecord3(value) && Array.isArray(value.content)) {
197545
+ const text2 = value.content.filter((item) => isRecord3(item) && item.type === "text" && typeof item.text === "string").map((item) => item.text).join("\n");
197546
+ return parseExploreText(text2, projectRoot, exclude);
197547
+ }
197548
+ return parseOutline(value, projectRoot, exclude);
197549
+ }
197353
197550
  function fallbackCaution(health) {
197354
197551
  if (health.state === "disabled" || health.state === "not-detected" || health.state === "not-initialized" || health.state === "ready") return void 0;
197355
197552
  return "External semantic CodeGraph is " + health.state + "; using Lite structural evidence for this brief.";
197356
197553
  }
197554
+ function queryFallbackCaution(diagnostics) {
197555
+ return `External semantic CodeGraph context was unavailable (context: ${diagnostics.context.outcome}; explore: ${diagnostics.explore.outcome}); using Lite structural evidence.`;
197556
+ }
197357
197557
  async function getExternalCodeGraphContext(input) {
197358
197558
  const inspected = await inspectExternalCodeGraph(input);
197359
197559
  if (inspected.health.state !== "ready") {
197360
197560
  return { ...inspected, caution: fallbackCaution(inspected.health) };
197361
197561
  }
197362
197562
  const mode = input.mode ?? "auto";
197363
- const result = await runSafely(input.runner ?? defaultRunner, {
197563
+ const runner = input.runner ?? defaultRunner;
197564
+ const contextResult = await runSafely(runner, {
197364
197565
  command: input.command,
197365
197566
  args: ["context", "--path", input.projectRoot, "--format", "json", "--max-nodes", "8", "--no-code", input.task],
197366
197567
  cwd: input.projectRoot,
197367
197568
  timeoutMs: boundedTimeout(input.timeoutMs),
197368
197569
  maxOutputBytes: MAX_EXTERNAL_CODEGRAPH_OUTPUT_BYTES
197369
197570
  });
197370
- if (!result.ok) {
197371
- const health = unavailableHealth(result);
197571
+ const diagnostics = {
197572
+ context: contextResult.ok ? commandDiagnostic("context", contextResult, "success") : failedCommandDiagnostic("context", contextResult),
197573
+ explore: notAttemptedDiagnostic("explore")
197574
+ };
197575
+ const contextOutline = contextResult.ok ? parseOutline(parseJson2(contextResult.stdout), input.projectRoot, input.exclude) : void 0;
197576
+ if (contextOutline && (contextOutline.entryPoints.length > 0 || contextOutline.relations.length > 0 || contextOutline.relatedFiles.length > 0)) {
197372
197577
  return {
197373
- health,
197374
- quality: providerQuality({ mode, health }),
197375
- caution: fallbackCaution(health)
197578
+ ...inspected,
197579
+ outline: contextOutline,
197580
+ diagnostics,
197581
+ quality: providerQuality({ mode, health: inspected.health, selected: "external" })
197376
197582
  };
197377
197583
  }
197378
- const outline = parseOutline(parseJson2(result.stdout), input.projectRoot, input.exclude);
197379
- if (!outline) {
197380
- const health = { state: "invalid", reason: "The local CodeGraph context payload failed validation." };
197584
+ if (contextResult.ok) diagnostics.context = commandDiagnostic("context", contextResult, "invalid-output", "The context payload failed validation or contained no safe outline.");
197585
+ const exploreResult = await runSafely(runner, {
197586
+ command: input.command,
197587
+ args: ["explore", "--path", input.projectRoot, "--max-files", "4", input.task],
197588
+ cwd: input.projectRoot,
197589
+ timeoutMs: boundedTimeout(input.timeoutMs),
197590
+ maxOutputBytes: MAX_EXTERNAL_CODEGRAPH_OUTPUT_BYTES
197591
+ });
197592
+ diagnostics.explore = exploreResult.ok ? commandDiagnostic("explore", exploreResult, "success") : failedCommandDiagnostic("explore", exploreResult);
197593
+ const exploreOutline = exploreResult.ok ? parseExplorePayload(parseJson2(exploreResult.stdout) ?? exploreResult.stdout, input.projectRoot, input.exclude) : void 0;
197594
+ if (exploreOutline && (exploreOutline.entryPoints.length > 0 || exploreOutline.relations.length > 0 || exploreOutline.relatedFiles.length > 0)) {
197381
197595
  return {
197382
- health,
197383
- quality: providerQuality({ mode, health }),
197384
- caution: fallbackCaution(health)
197596
+ ...inspected,
197597
+ outline: exploreOutline,
197598
+ diagnostics,
197599
+ quality: providerQuality({ mode, health: inspected.health, selected: "external" })
197385
197600
  };
197386
197601
  }
197387
- const contributes = outline.entryPoints.length > 0 || outline.relations.length > 0 || outline.relatedFiles.length > 0;
197602
+ if (exploreResult.ok) diagnostics.explore = commandDiagnostic("explore", exploreResult, "invalid-output", "The explore payload failed validation or contained no safe outline.");
197603
+ const health = exploreResult.ok ? { state: "invalid", reason: "The local CodeGraph context and explore payloads failed validation." } : unavailableHealth(exploreResult);
197388
197604
  return {
197389
- ...inspected,
197390
- ...contributes ? { outline } : {},
197391
- quality: providerQuality({ mode, health: inspected.health, ...contributes ? { selected: "external" } : {} })
197605
+ health,
197606
+ quality: providerQuality({ mode, health }),
197607
+ diagnostics,
197608
+ caution: queryFallbackCaution(diagnostics)
197392
197609
  };
197393
197610
  }
197394
197611
  var DEFAULT_EXTERNAL_CODEGRAPH_TIMEOUT_MS, MAX_EXTERNAL_CODEGRAPH_TIMEOUT_MS, EXTERNAL_CODEGRAPH_LIFECYCLE_TIMEOUT_MS, MAX_EXTERNAL_CODEGRAPH_OUTPUT_BYTES, MAX_EXTERNAL_NODE_COUNT, MAX_EXTERNAL_EDGE_COUNT, MAX_EXTERNAL_FILE_COUNT, MAX_EXTERNAL_TEXT_LENGTH, LITE_SUPPORTED_LANGUAGES, defaultRunner;
@@ -197399,7 +197616,7 @@ var init_external_provider = __esm({
197399
197616
  init_secret_filter();
197400
197617
  init_exclude3();
197401
197618
  init_ids();
197402
- DEFAULT_EXTERNAL_CODEGRAPH_TIMEOUT_MS = 1200;
197619
+ DEFAULT_EXTERNAL_CODEGRAPH_TIMEOUT_MS = 3e3;
197403
197620
  MAX_EXTERNAL_CODEGRAPH_TIMEOUT_MS = 5e3;
197404
197621
  EXTERNAL_CODEGRAPH_LIFECYCLE_TIMEOUT_MS = 3e4;
197405
197622
  MAX_EXTERNAL_CODEGRAPH_OUTPUT_BYTES = 256 * 1024;
@@ -218992,6 +219209,51 @@ var init_request_context = __esm({
218992
219209
  }
218993
219210
  });
218994
219211
 
219212
+ // src/server/mcp-compat.ts
219213
+ function buildMcpDiscoverResult(server, serverInfo) {
219214
+ const getCapabilities = server.server.getCapabilities.bind(server.server);
219215
+ return {
219216
+ resultType: "complete",
219217
+ supportedVersions: [
219218
+ MCP_MODERN_PROTOCOL_VERSION,
219219
+ MCP_LEGACY_PROTOCOL_VERSION,
219220
+ MCP_OLDEST_LEGACY_PROTOCOL_VERSION
219221
+ ],
219222
+ capabilities: getCapabilities(),
219223
+ _meta: {
219224
+ [MCP_SERVER_INFO_META_KEY]: { ...serverInfo }
219225
+ },
219226
+ // v1 has no response-cache negotiation. A zero private TTL is the
219227
+ // conservative result and prevents clients from inventing a shared cache.
219228
+ ttlMs: 0,
219229
+ cacheScope: "private"
219230
+ };
219231
+ }
219232
+ function registerMcpDiscovery(server, serverInfo) {
219233
+ if (registeredServers.has(server)) return;
219234
+ server.server.setRequestHandler(ServerDiscoverRequestSchema, async () => buildMcpDiscoverResult(server, serverInfo));
219235
+ registeredServers.add(server);
219236
+ }
219237
+ var MCP_MODERN_PROTOCOL_VERSION, MCP_LEGACY_PROTOCOL_VERSION, MCP_OLDEST_LEGACY_PROTOCOL_VERSION, MCP_SERVER_DISCOVER_METHOD, MCP_SERVER_INFO_META_KEY, ServerDiscoverRequestSchema, registeredServers;
219238
+ var init_mcp_compat = __esm({
219239
+ "src/server/mcp-compat.ts"() {
219240
+ "use strict";
219241
+ init_esm_shims();
219242
+ init_types8();
219243
+ init_v4();
219244
+ MCP_MODERN_PROTOCOL_VERSION = "2026-07-28";
219245
+ MCP_LEGACY_PROTOCOL_VERSION = "2025-11-25";
219246
+ MCP_OLDEST_LEGACY_PROTOCOL_VERSION = "2024-11-05";
219247
+ MCP_SERVER_DISCOVER_METHOD = "server/discover";
219248
+ MCP_SERVER_INFO_META_KEY = "io.modelcontextprotocol/serverInfo";
219249
+ ServerDiscoverRequestSchema = RequestSchema.extend({
219250
+ method: external_exports.literal(MCP_SERVER_DISCOVER_METHOD),
219251
+ params: external_exports.looseObject({}).optional()
219252
+ });
219253
+ registeredServers = /* @__PURE__ */ new WeakSet();
219254
+ }
219255
+ });
219256
+
218995
219257
  // src/config/behavior.ts
218996
219258
  var behavior_exports = {};
218997
219259
  __export(behavior_exports, {
@@ -219278,6 +219540,7 @@ async function executeCleanup(context, payload, token) {
219278
219540
  return { action: "cleanup", projectId: context.projectId, ...result };
219279
219541
  }
219280
219542
  async function previewDeduplicate(context) {
219543
+ initLLM({ scope: "memory", projectRoot: context.projectRoot });
219281
219544
  if (!isLLMEnabled()) {
219282
219545
  return {
219283
219546
  action: "deduplicate",
@@ -261370,10 +261633,12 @@ The path should point to a directory containing a .git folder.`
261370
261633
  isError: true
261371
261634
  };
261372
261635
  };
261373
- const server = existingServer ?? new McpServer({
261636
+ const serverInfo = {
261374
261637
  name: "memorix",
261375
- version: true ? "1.8.1" : "1.0.1"
261376
- });
261638
+ version: true ? "1.8.2" : "1.0.1"
261639
+ };
261640
+ const server = existingServer ?? new McpServer(serverInfo);
261641
+ registerMcpDiscovery(server, serverInfo);
261377
261642
  const originalRegisterTool = server.registerTool.bind(server);
261378
261643
  server.registerTool = ((name, ...args) => {
261379
261644
  if (!isToolInProfile(name, toolProfile)) {
@@ -265751,6 +266016,7 @@ var init_server4 = __esm({
265751
266016
  init_secret_filter();
265752
266017
  init_surfaced_registry();
265753
266018
  init_request_context();
266019
+ init_mcp_compat();
265754
266020
  FORMATION_TIMEOUT_MS = parseFormationTimeoutMs(process.env.MEMORIX_FORMATION_TIMEOUT_MS);
265755
266021
  COMPACT_ON_WRITE_TIMEOUT_MS = 12e3;
265756
266022
  COMPRESSION_TIMEOUT_MS = 5e3;
@@ -266232,13 +266498,17 @@ function getMcpDiagnostics() {
266232
266498
  protocol: {
266233
266499
  current: CURRENT_MCP_PROTOCOL_VERSION,
266234
266500
  legacy: LEGACY_MCP_PROTOCOL_VERSION,
266235
- statelessRequests: "supported",
266501
+ discovery: "supported",
266502
+ versionlessRequests: "legacy-compatible",
266503
+ modernResultMetadata: "discovery-only",
266504
+ statelessRequests: "compatibility-only",
266236
266505
  statefulStreamableHttp: "supported"
266237
266506
  },
266238
266507
  capabilities: {
266239
266508
  tasks: "unsupported",
266240
266509
  polling: "unsupported",
266241
- listCache: "supported",
266510
+ subscriptions: "unsupported",
266511
+ listCache: "unsupported",
266242
266512
  explicitProjectHandle: "supported"
266243
266513
  }
266244
266514
  };
@@ -266249,7 +266519,7 @@ var init_mcp_diagnostics = __esm({
266249
266519
  "use strict";
266250
266520
  init_esm_shims();
266251
266521
  CURRENT_MCP_PROTOCOL_VERSION = "2026-07-28";
266252
- LEGACY_MCP_PROTOCOL_VERSION = "2024-11-05";
266522
+ LEGACY_MCP_PROTOCOL_VERSION = "2025-11-25";
266253
266523
  MCP_SERVER_NAME = "io.github.AVIDS2/memorix";
266254
266524
  }
266255
266525
  });
@@ -268493,9 +268763,13 @@ __export(serve_http_exports, {
268493
268763
  MCP_SDK_COMPAT_PROTOCOL_VERSION: () => MCP_SDK_COMPAT_PROTOCOL_VERSION,
268494
268764
  _testing: () => _testing2,
268495
268765
  default: () => serve_http_default,
268766
+ isServerDiscoverRequest: () => isServerDiscoverRequest,
268496
268767
  parseSessionTimeoutMs: () => parseSessionTimeoutMs,
268497
268768
  resolveServeHttpDefaults: () => resolveServeHttpDefaults
268498
268769
  });
268770
+ function isServerDiscoverRequest(body) {
268771
+ return Boolean(body && typeof body === "object" && !Array.isArray(body) && body.method === "server/discover");
268772
+ }
268499
268773
  function parseSessionTimeoutMs(raw) {
268500
268774
  const value = raw?.trim();
268501
268775
  if (!value) return DEFAULT_SESSION_TIMEOUT_MS;
@@ -268776,7 +269050,7 @@ var init_serve_http = __esm({
268776
269050
  }
268777
269051
  const requestedRoot = typeof req.headers["mcp-project-root"] === "string" ? req.headers["mcp-project-root"] : void 0;
268778
269052
  const root = persisted?.projectRoot ?? requestedRoot ?? projectRoot;
268779
- if (!persisted && !isInitializeRequest2(body)) {
269053
+ if (!persisted && !isInitializeRequest2(body) && !isServerDiscoverRequest(body)) {
268780
269054
  res.writeHead(400, { "Content-Type": "application/json" });
268781
269055
  res.end(JSON.stringify({ jsonrpc: "2.0", error: { code: -32e3, message: "Stateless MCP requests require Mcp-Project-Handle; initialize first." }, id: null }));
268782
269056
  return;
@@ -268840,7 +269114,7 @@ var init_serve_http = __esm({
268840
269114
  const sessionId = req.headers["mcp-session-id"];
268841
269115
  const body = await parseBody(req);
268842
269116
  const requestedProtocol = req.headers["mcp-protocol-version"];
268843
- const statelessRequested = req.headers["mcp-stateless"] === "true" || requestedProtocol === CURRENT_MCP_PROTOCOL_VERSION;
269117
+ const statelessRequested = req.headers["mcp-stateless"] === "true" || requestedProtocol === CURRENT_MCP_PROTOCOL_VERSION || typeof req.headers["mcp-project-handle"] === "string" || isServerDiscoverRequest(body);
268844
269118
  if (!sessionId && statelessRequested) {
268845
269119
  await handleStatelessPost(req, res, body);
268846
269120
  return;