@cortexkit/magic-context 0.49.10 → 0.49.11

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 (2) hide show
  1. package/dist/index.js +411 -176
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14483,16 +14483,19 @@ function getOmpPackageDir() {
14483
14483
  return resolve3(value);
14484
14484
  }
14485
14485
  function getOmpNonGlobalConfigSources(cwd = process.cwd()) {
14486
- const sources = process.env.PI_CONFIG_FILES?.split(delimiter2).map((entry) => entry.trim()).filter(Boolean).map((entry) => {
14486
+ const sources = getOmpConfigOverlayPaths(cwd);
14487
+ const projectConfig = resolve3(cwd, ".omp", "config.yml");
14488
+ if (existsSync9(projectConfig))
14489
+ sources.push(projectConfig);
14490
+ return [...new Set(sources)];
14491
+ }
14492
+ function getOmpConfigOverlayPaths(cwd = process.cwd()) {
14493
+ return process.env.PI_CONFIG_FILES?.split(delimiter2).map((entry) => entry.trim()).filter(Boolean).map((entry) => {
14487
14494
  if (entry === "~")
14488
14495
  return envFirstHomeDir();
14489
14496
  const expanded = entry.startsWith("~/") || entry.startsWith("~\\") ? join8(envFirstHomeDir(), entry.slice(2)) : entry;
14490
14497
  return resolve3(cwd, expanded);
14491
14498
  }) ?? [];
14492
- const projectConfig = resolve3(cwd, ".omp", "config.yml");
14493
- if (existsSync9(projectConfig))
14494
- sources.push(projectConfig);
14495
- return [...new Set(sources)];
14496
14499
  }
14497
14500
  function getOmpPluginsDir() {
14498
14501
  return resolveOmpPaths().pluginsDir;
@@ -32489,19 +32492,20 @@ var init_raw_ordinal_warmup = __esm(async () => {
32489
32492
  function openCodeDbExists() {
32490
32493
  return harnessOwnsOpenCodeStore() && openCodeDbPathExists(resolveOpenCodeDbPath());
32491
32494
  }
32492
- function closeCachedReadOnlyDb() {
32493
- if (!cachedReadOnlyDb) {
32495
+ function closeCachedReadOnlyDb(generation) {
32496
+ const cached = cachedReadOnlyDbs[generation];
32497
+ if (!cached) {
32494
32498
  return;
32495
32499
  }
32496
32500
  try {
32497
- closeQuietly(cachedReadOnlyDb.db);
32501
+ closeQuietly(cached.db);
32498
32502
  } catch (error) {
32499
32503
  log("[magic-context] failed to close cached OpenCode read-only DB:", error);
32500
32504
  } finally {
32501
- cachedReadOnlyDb = null;
32505
+ cachedReadOnlyDbs[generation] = null;
32502
32506
  }
32503
32507
  }
32504
- function getReadOnlySessionDb() {
32508
+ function getReadOnlySessionDb(generation = "v1") {
32505
32509
  if (!harnessOwnsOpenCodeStore()) {
32506
32510
  throw new Error("OpenCode session database is not readable from a Pi-compatible process; its history lives in Pi sessions");
32507
32511
  }
@@ -32510,18 +32514,19 @@ function getReadOnlySessionDb() {
32510
32514
  if (!openCodeDbPathExists(resolution)) {
32511
32515
  throw new Error(`OpenCode session database is unavailable at ${dbPath} (source=${resolution.source})`);
32512
32516
  }
32513
- if (cachedReadOnlyDb?.path === dbPath) {
32514
- return cachedReadOnlyDb.db;
32517
+ const cached = cachedReadOnlyDbs[generation];
32518
+ if (cached?.path === dbPath) {
32519
+ return cached.db;
32515
32520
  }
32516
- closeCachedReadOnlyDb();
32521
+ closeCachedReadOnlyDb(generation);
32517
32522
  const db = new Database(dbPath, { readonly: true });
32518
32523
  try {
32519
- assertOpenCodeStoreGeneration(db, "v1", dbPath);
32524
+ assertOpenCodeStoreGeneration(db, generation, dbPath);
32520
32525
  } catch (error) {
32521
32526
  closeQuietly(db);
32522
32527
  throw error;
32523
32528
  }
32524
- cachedReadOnlyDb = { path: dbPath, db };
32529
+ cachedReadOnlyDbs[generation] = { path: dbPath, db };
32525
32530
  clearOpenCodeDbReadFailure();
32526
32531
  return db;
32527
32532
  }
@@ -32547,21 +32552,20 @@ function getMessageTimesFromOpenCodeDb(sessionId, messageIds) {
32547
32552
  if (messageIds.length === 0 || !harnessOwnsOpenCodeStore())
32548
32553
  return result;
32549
32554
  try {
32550
- withReadOnlySessionDb((db) => {
32551
- const placeholders = messageIds.map(() => "?").join(",");
32552
- const rows = db.prepare(`SELECT id, time_created FROM message WHERE +session_id = ? AND id IN (${placeholders})`).all(sessionId, ...messageIds);
32553
- for (const row of rows) {
32554
- if (typeof row.id === "string" && typeof row.time_created === "number") {
32555
- result.set(row.id, row.time_created);
32556
- }
32555
+ const placeholders = messageIds.map(() => "?").join(",");
32556
+ const rows = getHarness() === "opencode2" ? getReadOnlySessionDb("v2").prepare(`SELECT id, COALESCE(time_created, json_extract(data, '$.time.created')) AS time_created
32557
+ FROM session_message WHERE +session_id = ? AND id IN (${placeholders})`).all(sessionId, ...messageIds) : withReadOnlySessionDb((db) => db.prepare(`SELECT id, time_created FROM message WHERE +session_id = ? AND id IN (${placeholders})`).all(sessionId, ...messageIds));
32558
+ for (const row of rows) {
32559
+ if (typeof row.id === "string" && typeof row.time_created === "number") {
32560
+ result.set(row.id, row.time_created);
32557
32561
  }
32558
- });
32562
+ }
32559
32563
  } catch (error) {
32560
32564
  logProbeFailureOnce(resolveOpenCodeDbPath(), error);
32561
32565
  }
32562
32566
  return result;
32563
32567
  }
32564
- var cachedReadOnlyDb = null, trackedSessions, pendingParts, probeLogObserverForTests;
32568
+ var cachedReadOnlyDbs, trackedSessions, pendingParts, probeLogObserverForTests;
32565
32569
  var init_read_session_db = __esm(async () => {
32566
32570
  init_logger();
32567
32571
  init_opencode_db_path();
@@ -32569,6 +32573,10 @@ var init_read_session_db = __esm(async () => {
32569
32573
  init_sqlite(),
32570
32574
  init_read_session_raw()
32571
32575
  ]);
32576
+ cachedReadOnlyDbs = {
32577
+ v1: null,
32578
+ v2: null
32579
+ };
32572
32580
  trackedSessions = new Map;
32573
32581
  pendingParts = new Map;
32574
32582
  });
@@ -46478,11 +46486,235 @@ var init_issue_body = __esm(() => {
46478
46486
  ];
46479
46487
  });
46480
46488
 
46489
+ // src/lib/omp-hide-secrets.ts
46490
+ import { existsSync as existsSync42, readdirSync as readdirSync9, readFileSync as readFileSync24, statSync as statSync22 } from "node:fs";
46491
+ import { join as join34, resolve as resolve17 } from "node:path";
46492
+ function stripYamlComment(line) {
46493
+ let quote = null;
46494
+ for (let index = 0;index < line.length; index += 1) {
46495
+ const char = line[index];
46496
+ if (quote) {
46497
+ if (char === quote)
46498
+ quote = null;
46499
+ } else if (char === '"' || char === "'") {
46500
+ quote = char;
46501
+ } else if (char === "#" && (index === 0 || /\s/.test(line[index - 1] ?? ""))) {
46502
+ return line.slice(0, index).trimEnd();
46503
+ }
46504
+ }
46505
+ return line.trimEnd();
46506
+ }
46507
+ function indentOf(line) {
46508
+ return line.length - line.trimStart().length;
46509
+ }
46510
+ function yamlBoolean(raw) {
46511
+ const value = raw.trim();
46512
+ if (value === "true" || value === "True" || value === "TRUE")
46513
+ return { kind: "on" };
46514
+ if (value === "false" || value === "False" || value === "FALSE")
46515
+ return { kind: "off" };
46516
+ if (value === "" || value === "~" || value === "null" || value === "Null" || value === "NULL")
46517
+ return { kind: "absent" };
46518
+ return UNRECOGNIZED;
46519
+ }
46520
+ function keyPattern(key) {
46521
+ return new RegExp(`^(?:${key}|"${key}"|'${key}')\\s*:(?:\\s+(.*))?$`);
46522
+ }
46523
+ function flowMapEnabled(flow) {
46524
+ if (!flow.endsWith("}"))
46525
+ return UNRECOGNIZED;
46526
+ const body = flow.slice(1, -1);
46527
+ if (/[{}[\]&*!]/.test(body))
46528
+ return UNRECOGNIZED;
46529
+ const matches = body.split(",").map((entry) => entry.trim().match(/^(?:enabled|"enabled"|'enabled')\s*:\s*(.*)$/)).filter((match) => match !== null);
46530
+ if (matches.length > 1)
46531
+ return UNRECOGNIZED;
46532
+ return matches.length === 0 ? { kind: "absent" } : yamlBoolean(matches[0]?.[1] ?? "");
46533
+ }
46534
+ function readHideSecretsFromYaml(text) {
46535
+ const lines = text.replace(/^\uFEFF/, "").split(/\r?\n/).map(stripYamlComment);
46536
+ const content = lines.filter((line) => line.trim() !== "");
46537
+ const first = content[0]?.trim();
46538
+ if (first?.startsWith("{") || first?.startsWith("["))
46539
+ return UNRECOGNIZED;
46540
+ if (content.some((line) => /^\s*\t/.test(line)))
46541
+ return UNRECOGNIZED;
46542
+ const starts = lines.flatMap((line, index) => indentOf(line) === 0 && SECRETS_KEY.test(line) ? [index] : []);
46543
+ if (starts.length === 0)
46544
+ return { kind: "absent" };
46545
+ if (starts.length > 1)
46546
+ return UNRECOGNIZED;
46547
+ const start = starts[0];
46548
+ const inline = (lines[start]?.match(SECRETS_KEY)?.[1] ?? "").trim();
46549
+ if (inline.startsWith("{"))
46550
+ return flowMapEnabled(inline);
46551
+ if (inline === "~" || inline === "null" || inline === "Null" || inline === "NULL")
46552
+ return { kind: "absent" };
46553
+ if (inline !== "")
46554
+ return UNRECOGNIZED;
46555
+ const children = [];
46556
+ for (const line of lines.slice(start + 1)) {
46557
+ if (line.trim() === "")
46558
+ continue;
46559
+ if (indentOf(line) === 0)
46560
+ break;
46561
+ children.push(line);
46562
+ }
46563
+ if (children.length === 0)
46564
+ return { kind: "absent" };
46565
+ const childIndent = indentOf(children[0]);
46566
+ if (children[0]?.trimStart().startsWith("-"))
46567
+ return UNRECOGNIZED;
46568
+ let found = null;
46569
+ for (let index = 0;index < children.length; index += 1) {
46570
+ const line = children[index];
46571
+ const indent = indentOf(line);
46572
+ if (indent < childIndent)
46573
+ return UNRECOGNIZED;
46574
+ if (indent > childIndent)
46575
+ continue;
46576
+ const match = line.trim().match(ENABLED_KEY);
46577
+ if (!match)
46578
+ continue;
46579
+ if (found)
46580
+ return UNRECOGNIZED;
46581
+ const nextIndent = children[index + 1] ? indentOf(children[index + 1]) : 0;
46582
+ if ((match[1] ?? "").trim() === "" && nextIndent > childIndent)
46583
+ return UNRECOGNIZED;
46584
+ found = yamlBoolean(match[1] ?? "");
46585
+ }
46586
+ return found ?? { kind: "absent" };
46587
+ }
46588
+ function readHideSecretsFromJson(text) {
46589
+ let parsed;
46590
+ try {
46591
+ parsed = JSON.parse(text);
46592
+ } catch {
46593
+ return { kind: "unreadable", reason: "file is not valid JSON" };
46594
+ }
46595
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
46596
+ return { kind: "absent" };
46597
+ const secrets = parsed.secrets;
46598
+ if (secrets === undefined || secrets === null)
46599
+ return { kind: "absent" };
46600
+ if (typeof secrets !== "object" || Array.isArray(secrets))
46601
+ return UNRECOGNIZED;
46602
+ const enabled = secrets.enabled;
46603
+ if (enabled === true)
46604
+ return { kind: "on" };
46605
+ if (enabled === false)
46606
+ return { kind: "off" };
46607
+ if (enabled === undefined || enabled === null)
46608
+ return { kind: "absent" };
46609
+ return UNRECOGNIZED;
46610
+ }
46611
+ function readSource(layer, path, format) {
46612
+ let text;
46613
+ try {
46614
+ text = readFileSync24(path, "utf-8");
46615
+ } catch (error) {
46616
+ const code = error.code;
46617
+ return {
46618
+ layer,
46619
+ path,
46620
+ value: {
46621
+ kind: "unreadable",
46622
+ reason: `file could not be read${code ? ` (${code})` : ""}`
46623
+ }
46624
+ };
46625
+ }
46626
+ return {
46627
+ layer,
46628
+ path,
46629
+ value: format === "json" ? readHideSecretsFromJson(text) : readHideSecretsFromYaml(text)
46630
+ };
46631
+ }
46632
+ function isNonEmptyDirectory(path) {
46633
+ try {
46634
+ return statSync22(path).isDirectory() && readdirSync9(path).length > 0;
46635
+ } catch {
46636
+ return false;
46637
+ }
46638
+ }
46639
+ function collectHideSecretsSources(cwd, home = envFirstHomeDir()) {
46640
+ const sources = [];
46641
+ const agentDir = getOmpAgentDir();
46642
+ const mainConfig = ["config.yml", "config.yaml"].map((name) => join34(agentDir, name)).find((path) => existsSync42(path));
46643
+ if (mainConfig)
46644
+ sources.push(readSource("user", mainConfig, "yaml"));
46645
+ const projectDir = join34(cwd, ".omp");
46646
+ if (resolve17(cwd) !== resolve17(home) && isNonEmptyDirectory(projectDir)) {
46647
+ for (const [name, format] of [
46648
+ ["settings.json", "json"],
46649
+ ["config.yml", "yaml"]
46650
+ ]) {
46651
+ const path = join34(projectDir, name);
46652
+ if (existsSync42(path))
46653
+ sources.push(readSource("project", path, format));
46654
+ }
46655
+ }
46656
+ for (const path of getOmpConfigOverlayPaths(cwd)) {
46657
+ if (existsSync42(path))
46658
+ sources.push(readSource("overlay", path, "yaml"));
46659
+ }
46660
+ return sources;
46661
+ }
46662
+ function checkOmpHideSecrets(sources) {
46663
+ let effective = null;
46664
+ let effectiveIndex = -1;
46665
+ for (const [index, source] of sources.entries()) {
46666
+ if (source.value.kind === "on" || source.value.kind === "off") {
46667
+ effective = source;
46668
+ effectiveIndex = index;
46669
+ }
46670
+ }
46671
+ if (effective?.value.kind === "on") {
46672
+ const explain = `OMP masks secrets after Magic Context prepares a turn, so some turns are refused; turn it off for Magic Context sessions, see ${OMP_HIDE_SECRETS_DOCS_URL} (${UNDETECTABLE})`;
46673
+ const label = LAYER_LABEL[effective.layer];
46674
+ return [
46675
+ {
46676
+ status: "warn",
46677
+ message: `${SETTING} is on in ${label} (${effective.path}): ${explain}`,
46678
+ issueMessage: `${SETTING} is on in ${label}: ${explain}`
46679
+ }
46680
+ ];
46681
+ }
46682
+ const unreadable = sources.flatMap((source, index) => index > effectiveIndex && source.value.kind === "unreadable" ? [{ source, reason: source.value.reason }] : []);
46683
+ if (unreadable.length > 0) {
46684
+ return unreadable.map(({ source, reason }) => {
46685
+ const tail = `${reason}; if Hide Secrets is on, see ${OMP_HIDE_SECRETS_DOCS_URL} (${UNDETECTABLE})`;
46686
+ const label = LAYER_LABEL[source.layer];
46687
+ return {
46688
+ status: "warn",
46689
+ message: `Could not check ${SETTING} in ${label} (${source.path}): ${tail}`,
46690
+ issueMessage: `Could not check ${SETTING} in ${label}: ${tail}`
46691
+ };
46692
+ });
46693
+ }
46694
+ const message = effective?.value.kind === "off" ? `${SETTING} is off in OMP settings files (${UNDETECTABLE})` : `${SETTING} is not set in OMP settings files; OMP's default is off (${UNDETECTABLE})`;
46695
+ return [{ status: "pass", message, issueMessage: message }];
46696
+ }
46697
+ var OMP_HIDE_SECRETS_DOCS_URL = "https://docs.cortexkit.io/magic-context/help/compatibility/#omp-hide-secrets", LAYER_LABEL, UNDETECTABLE = "CLI flags and live settings toggles can't be detected", SETTING = "OMP Hide Secrets (secrets.enabled)", UNRECOGNIZED, SECRETS_KEY, ENABLED_KEY;
46698
+ var init_omp_hide_secrets = __esm(() => {
46699
+ init_paths();
46700
+ LAYER_LABEL = {
46701
+ user: "OMP user settings",
46702
+ project: "OMP project settings",
46703
+ overlay: "an OMP config overlay (PI_CONFIG_FILES)"
46704
+ };
46705
+ UNRECOGNIZED = {
46706
+ kind: "unreadable",
46707
+ reason: "secrets.enabled could not be interpreted"
46708
+ };
46709
+ SECRETS_KEY = keyPattern("secrets");
46710
+ ENABLED_KEY = keyPattern("enabled");
46711
+ });
46712
+
46481
46713
  // src/commands/doctor-omp.ts
46482
46714
  import { execFileSync as execFileSync8, spawnSync as spawnSync8 } from "node:child_process";
46483
- import { existsSync as existsSync42, readFileSync as readFileSync24 } from "node:fs";
46715
+ import { existsSync as existsSync43, readFileSync as readFileSync25 } from "node:fs";
46484
46716
  import { createRequire as createRequire3 } from "node:module";
46485
- import { isAbsolute as isAbsolute8, join as join34, resolve as resolve17 } from "node:path";
46717
+ import { isAbsolute as isAbsolute8, join as join35, resolve as resolve18 } from "node:path";
46486
46718
  function parseSemver(value) {
46487
46719
  const match = value?.match(/(\d+)\.(\d+)\.(\d+)/);
46488
46720
  return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
@@ -46524,10 +46756,10 @@ function selfVersion() {
46524
46756
  return "unknown";
46525
46757
  }
46526
46758
  function readConfig2(path) {
46527
- if (!existsSync42(path))
46759
+ if (!existsSync43(path))
46528
46760
  return {};
46529
46761
  try {
46530
- const parsed = import_comment_json8.parse(readFileSync24(path, "utf-8"));
46762
+ const parsed = import_comment_json8.parse(readFileSync25(path, "utf-8"));
46531
46763
  return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? {} : { error: "top level is not an object" };
46532
46764
  } catch (error) {
46533
46765
  return { error: error instanceof Error ? error.message : String(error) };
@@ -46537,7 +46769,7 @@ function pluginDeclaresOmp(path) {
46537
46769
  if (!path)
46538
46770
  return null;
46539
46771
  try {
46540
- const pkg = JSON.parse(readFileSync24(join34(path, "package.json"), "utf-8"));
46772
+ const pkg = JSON.parse(readFileSync25(join35(path, "package.json"), "utf-8"));
46541
46773
  return Array.isArray(pkg.omp?.extensions) || Array.isArray(pkg.pi?.extensions);
46542
46774
  } catch {
46543
46775
  return null;
@@ -46604,6 +46836,8 @@ async function runHealthChecks(options) {
46604
46836
  repairPlan.disableMemory = true;
46605
46837
  } else
46606
46838
  add(results, "fail", "Could not read OMP memory.backend");
46839
+ for (const check of checkOmpHideSecrets(collectHideSecretsSources(options.cwd)))
46840
+ results.push(check);
46607
46841
  const nonGlobalSources = getOmpNonGlobalConfigSources(options.cwd);
46608
46842
  if (nonGlobalSources.length > 0 && (repairPlan.disableCompaction || repairPlan.disableMemory)) {
46609
46843
  add(results, "warn", "OMP project/overlay config owns effective conflicting settings; automatic global repair is disabled: " + nonGlobalSources.join(", "));
@@ -46612,8 +46846,8 @@ async function runHealthChecks(options) {
46612
46846
  if (!reportedAgentDir.ok) {
46613
46847
  add(results, "warn", "Could not verify OMP active agent directory");
46614
46848
  } else {
46615
- const reportedPath = resolve17(reportedAgentDir.stdout);
46616
- const expectedPath = resolve17(getOmpAgentDir());
46849
+ const reportedPath = resolve18(reportedAgentDir.stdout);
46850
+ const expectedPath = resolve18(getOmpAgentDir());
46617
46851
  if (reportedPath === expectedPath) {
46618
46852
  add(results, "pass", `OMP agent directory resolved to ${getOmpAgentDir()}`);
46619
46853
  } else {
@@ -46624,7 +46858,7 @@ async function runHealthChecks(options) {
46624
46858
  }
46625
46859
  }
46626
46860
  const userConfigPath = getOmpUserConfigPath();
46627
- if (!existsSync42(userConfigPath)) {
46861
+ if (!existsSync43(userConfigPath)) {
46628
46862
  add(results, "warn", `No Magic Context user config at ${userConfigPath}`);
46629
46863
  repairPlan.writeUserConfig = true;
46630
46864
  } else {
@@ -46641,9 +46875,9 @@ async function runHealthChecks(options) {
46641
46875
  for (const warning of loaded.warnings.slice(0, 5))
46642
46876
  add(results, "warn", warning);
46643
46877
  const storage = getMagicContextStorageResolution();
46644
- const dbPath = join34(storage.path, "context.db");
46878
+ const dbPath = join35(storage.path, "context.db");
46645
46879
  add(results, "info", `Shared storage: ${storage.path} (source: ${storage.source})`);
46646
- if (!existsSync42(dbPath))
46880
+ if (!existsSync43(dbPath))
46647
46881
  add(results, "info", `Shared context DB will be created at ${dbPath}`);
46648
46882
  else {
46649
46883
  let db = null;
@@ -46708,7 +46942,7 @@ function writeDefaultConfig(path) {
46708
46942
  }
46709
46943
  async function repair(plan, deps, prompts, cwd) {
46710
46944
  let fixed = 0;
46711
- if (plan.writeUserConfig && !existsSync42(getOmpUserConfigPath())) {
46945
+ if (plan.writeUserConfig && !existsSync43(getOmpUserConfigPath())) {
46712
46946
  writeDefaultConfig(getOmpUserConfigPath());
46713
46947
  prompts.log.success(`Wrote default Magic Context config to ${getOmpUserConfigPath()}`);
46714
46948
  fixed += 1;
@@ -46764,7 +46998,7 @@ function ompIssueBody(description, report, logLines, sessionFilter, cwd) {
46764
46998
  "",
46765
46999
  "## OMP diagnostics",
46766
47000
  `- Magic Context CLI: v${selfVersion()}`,
46767
- ...report.results.map((result) => `- ${result.status.toUpperCase()}: ${privacy.healthMessage(result.message)}`),
47001
+ ...report.results.map((result) => `- ${result.status.toUpperCase()}: ${result.issueMessage ?? privacy.healthMessage(result.message)}`),
46768
47002
  "",
46769
47003
  "## Recent errors (last 20, sanitized)",
46770
47004
  recentErrorLines.length === 0 ? "_No error-shaped log lines found in recent history._" : ["```", recentErrorLines.join(`
@@ -46821,7 +47055,7 @@ function runGhCommandWithDeps(deps, args) {
46821
47055
  async function runIssueFlow(options) {
46822
47056
  if (options.reportPath) {
46823
47057
  const report = await runHealthChecks({ ...options, quiet: true });
46824
- const path = isAbsolute8(options.reportPath) ? options.reportPath : join34(options.cwd, options.reportPath);
47058
+ const path = isAbsolute8(options.reportPath) ? options.reportPath : join35(options.cwd, options.reportPath);
46825
47059
  const bundle = writeOmpIssueReport(path, ompIssueBody("Generated non-interactively by `doctor --issue --report`.", report, readLogLines(report.logFiles), null, options.cwd));
46826
47060
  options.prompts.log.success(bundle.fullPath ? `Sanitized report written to ${bundle.path}; full report at ${bundle.fullPath}` : `Sanitized report written to ${bundle.path}`);
46827
47061
  return 0;
@@ -46848,7 +47082,7 @@ async function runIssueFlow(options) {
46848
47082
  ]);
46849
47083
  sessionFilter = choice === "__all__" ? null : choice;
46850
47084
  }
46851
- const path = join34(options.cwd, `magic-context-omp-issue-${timestamp2(options.deps.now())}.md`);
47085
+ const path = join35(options.cwd, `magic-context-omp-issue-${timestamp2(options.deps.now())}.md`);
46852
47086
  const bundle = writeOmpIssueReport(path, ompIssueBody(description, report, logLines, sessionFilter, options.cwd));
46853
47087
  options.prompts.log.success(bundle.fullPath ? `Sanitized report written to ${bundle.path}; full report at ${bundle.fullPath}` : `Sanitized report written to ${bundle.path}`);
46854
47088
  if (await options.prompts.confirm("Submit this issue on GitHub now?", false)) {
@@ -46903,6 +47137,7 @@ var init_doctor_omp = __esm(async () => {
46903
47137
  init_issue_body();
46904
47138
  init_log_lines();
46905
47139
  init_omp_helpers();
47140
+ init_omp_hide_secrets();
46906
47141
  init_paths();
46907
47142
  init_prompts();
46908
47143
  await init_database_access();
@@ -47819,12 +48054,12 @@ function listShadowBackfillStalls(db, projectIdentity) {
47819
48054
  var SHADOW_BACKFILL_PROVENANCE_KEY = "_magicContextShadowBackfill";
47820
48055
 
47821
48056
  // ../plugin/src/shared/auto-update-provenance.ts
47822
- import { existsSync as existsSync43, readFileSync as readFileSync25 } from "node:fs";
48057
+ import { existsSync as existsSync44, readFileSync as readFileSync26 } from "node:fs";
47823
48058
  function readAutoUpdateCheckState(path) {
47824
- if (!existsSync43(path))
48059
+ if (!existsSync44(path))
47825
48060
  return null;
47826
48061
  try {
47827
- const value = JSON.parse(readFileSync25(path, "utf-8"));
48062
+ const value = JSON.parse(readFileSync26(path, "utf-8"));
47828
48063
  if (!value || typeof value !== "object" || Array.isArray(value))
47829
48064
  return null;
47830
48065
  const raw = value;
@@ -47852,14 +48087,14 @@ var init_auto_update_provenance = () => {};
47852
48087
  // ../plugin/src/shared/tui-config.ts
47853
48088
  import {
47854
48089
  chmodSync as chmodSync4,
47855
- existsSync as existsSync44,
48090
+ existsSync as existsSync45,
47856
48091
  mkdirSync as mkdirSync7,
47857
- readFileSync as readFileSync26,
48092
+ readFileSync as readFileSync27,
47858
48093
  renameSync as renameSync8,
47859
- statSync as statSync22,
48094
+ statSync as statSync23,
47860
48095
  writeFileSync as writeFileSync7
47861
48096
  } from "node:fs";
47862
- import { dirname as dirname23, join as join35 } from "node:path";
48097
+ import { dirname as dirname23, join as join36 } from "node:path";
47863
48098
  function pluginEntryId(entry) {
47864
48099
  if (typeof entry === "string")
47865
48100
  return entry;
@@ -47892,19 +48127,19 @@ function writeTuiConfigAtomic(configPath, config) {
47892
48127
  const tmpPath = `${configPath}.tmp`;
47893
48128
  writeFileSync7(tmpPath, body);
47894
48129
  try {
47895
- if (statSync22(configPath, { throwIfNoEntry: false })?.isFile()) {
47896
- chmodSync4(tmpPath, statSync22(configPath).mode & 511);
48130
+ if (statSync23(configPath, { throwIfNoEntry: false })?.isFile()) {
48131
+ chmodSync4(tmpPath, statSync23(configPath).mode & 511);
47897
48132
  }
47898
48133
  } catch {}
47899
48134
  renameSync8(tmpPath, configPath);
47900
48135
  }
47901
48136
  function resolveTuiConfigPath(configDirOverride) {
47902
48137
  const configDir = configDirOverride ?? getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
47903
- const jsoncPath = join35(configDir, "tui.jsonc");
47904
- const jsonPath = join35(configDir, "tui.json");
47905
- if (existsSync44(jsoncPath))
48138
+ const jsoncPath = join36(configDir, "tui.jsonc");
48139
+ const jsonPath = join36(configDir, "tui.json");
48140
+ if (existsSync45(jsoncPath))
47906
48141
  return jsoncPath;
47907
- if (existsSync44(jsonPath))
48142
+ if (existsSync45(jsonPath))
47908
48143
  return jsonPath;
47909
48144
  return jsoncPath;
47910
48145
  }
@@ -47912,8 +48147,8 @@ function ensureTuiPluginEntry(options = {}) {
47912
48147
  try {
47913
48148
  const configPath = resolveTuiConfigPath(options.configDir);
47914
48149
  let config = {};
47915
- if (existsSync44(configPath)) {
47916
- const raw = readFileSync26(configPath, "utf-8");
48150
+ if (existsSync45(configPath)) {
48151
+ const raw = readFileSync27(configPath, "utf-8");
47917
48152
  config = import_comment_json9.parse(raw) ?? {};
47918
48153
  }
47919
48154
  const plugins = Array.isArray(config.plugin) ? [...config.plugin] : [];
@@ -47965,9 +48200,9 @@ var init_tui_config = __esm(() => {
47965
48200
  });
47966
48201
 
47967
48202
  // src/lib/diagnostics-opencode.ts
47968
- import { existsSync as existsSync45, readdirSync as readdirSync9, readFileSync as readFileSync27, statSync as statSync23 } from "node:fs";
48203
+ import { existsSync as existsSync46, readdirSync as readdirSync10, readFileSync as readFileSync28, statSync as statSync24 } from "node:fs";
47969
48204
  import { createRequire as createRequire4 } from "node:module";
47970
- import { join as join36 } from "node:path";
48205
+ import { join as join37 } from "node:path";
47971
48206
  function getSelfVersion() {
47972
48207
  const require2 = createRequire4(import.meta.url);
47973
48208
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -47982,7 +48217,7 @@ function getSelfVersion() {
47982
48217
  }
47983
48218
  function readLegacyCachedVersion(root) {
47984
48219
  try {
47985
- const pkg = JSON.parse(readFileSync27(getOpenCodePluginPackageJsonPath(root), "utf-8"));
48220
+ const pkg = JSON.parse(readFileSync28(getOpenCodePluginPackageJsonPath(root), "utf-8"));
47986
48221
  return typeof pkg.version === "string" ? pkg.version : undefined;
47987
48222
  } catch {
47988
48223
  return;
@@ -47991,7 +48226,7 @@ function readLegacyCachedVersion(root) {
47991
48226
  function collectOpenCodePluginCacheReport(hostGeneration, opencodeConfig) {
47992
48227
  const installs = [];
47993
48228
  for (const root of getOpenCodePluginCacheRoots()) {
47994
- if (!existsSync45(root))
48229
+ if (!existsSync46(root))
47995
48230
  continue;
47996
48231
  const spec = root.endsWith("@latest") ? "latest" : "(bare)";
47997
48232
  installs.push({
@@ -48025,7 +48260,7 @@ function getStorageResolution() {
48025
48260
  }
48026
48261
  function fileSize(path) {
48027
48262
  try {
48028
- return existsSync45(path) ? statSync23(path).size : 0;
48263
+ return existsSync46(path) ? statSync24(path).size : 0;
48029
48264
  } catch {
48030
48265
  return 0;
48031
48266
  }
@@ -48037,10 +48272,10 @@ function sanitizeValue(value) {
48037
48272
  return sanitizeConfigValue(value);
48038
48273
  }
48039
48274
  function readConfig3(path) {
48040
- if (!existsSync45(path))
48275
+ if (!existsSync46(path))
48041
48276
  return { value: null };
48042
48277
  try {
48043
- const raw = readFileSync27(path, "utf-8");
48278
+ const raw = readFileSync28(path, "utf-8");
48044
48279
  const value = import_comment_json10.parse(raw);
48045
48280
  return { value };
48046
48281
  } catch (error) {
@@ -48065,7 +48300,7 @@ function configHasPluginEntry(config) {
48065
48300
  }
48066
48301
  function parseHistorianDumpMeta(path) {
48067
48302
  try {
48068
- const xml = readFileSync27(path, "utf-8");
48303
+ const xml = readFileSync28(path, "utf-8");
48069
48304
  const parsed = parseCompartmentOutput(xml);
48070
48305
  const factCountByCategory = {};
48071
48306
  for (const fact of parsed.facts) {
@@ -48098,11 +48333,11 @@ function parseHistorianDumpMeta(path) {
48098
48333
  }
48099
48334
  }
48100
48335
  function listDumpsInDir(dir, limit) {
48101
- if (!existsSync45(dir))
48336
+ if (!existsSync46(dir))
48102
48337
  return { count: 0, recent: [] };
48103
48338
  try {
48104
- const entries = readdirSync9(dir).filter((name) => name.endsWith(".xml")).map((name) => {
48105
- const stat = statSync23(join36(dir, name));
48339
+ const entries = readdirSync10(dir).filter((name) => name.endsWith(".xml")).map((name) => {
48340
+ const stat = statSync24(join37(dir, name));
48106
48341
  return {
48107
48342
  name,
48108
48343
  mtime: stat.mtimeMs,
@@ -48111,7 +48346,7 @@ function listDumpsInDir(dir, limit) {
48111
48346
  }).sort((a, b) => b.mtime - a.mtime);
48112
48347
  const now = Date.now();
48113
48348
  const recent = entries.slice(0, limit).map((entry) => {
48114
- const meta = parseHistorianDumpMeta(join36(dir, entry.name));
48349
+ const meta = parseHistorianDumpMeta(join37(dir, entry.name));
48115
48350
  const summary = {
48116
48351
  name: entry.name,
48117
48352
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -48222,7 +48457,7 @@ function collectRecentSessionsFromDatabase(database) {
48222
48457
  });
48223
48458
  }
48224
48459
  async function collectDatabaseRows(path, read) {
48225
- if (!existsSync45(path))
48460
+ if (!existsSync46(path))
48226
48461
  return { available: false, reason: "path missing" };
48227
48462
  let backend;
48228
48463
  try {
@@ -48254,7 +48489,7 @@ async function collectRecentSessions(resolution, hostGeneration) {
48254
48489
  });
48255
48490
  }
48256
48491
  async function collectHistorianFailures(storageDirPath) {
48257
- return collectDatabaseRows(join36(storageDirPath, "context.db"), (db) => {
48492
+ return collectDatabaseRows(join37(storageDirPath, "context.db"), (db) => {
48258
48493
  const rows = db.prepare("SELECT session_id, historian_failure_count, historian_last_error, historian_last_failure_at FROM session_meta WHERE historian_failure_count > 0 ORDER BY historian_last_failure_at DESC LIMIT 10").all();
48259
48494
  return rows.map((row) => {
48260
48495
  const sessionId = typeof row.session_id === "string" ? row.session_id : "<unknown>";
@@ -48267,7 +48502,7 @@ async function collectHistorianFailures(storageDirPath) {
48267
48502
  });
48268
48503
  }
48269
48504
  async function collectHistorianRuns(storageDirPath) {
48270
- return collectDatabaseRows(join36(storageDirPath, "context.db"), (db) => {
48505
+ return collectDatabaseRows(join37(storageDirPath, "context.db"), (db) => {
48271
48506
  const aggRows = db.prepare(`SELECT session_id,
48272
48507
  COUNT(*) AS total,
48273
48508
  SUM(CASE WHEN status='success' THEN 1 ELSE 0 END) AS success,
@@ -48322,7 +48557,7 @@ async function collectDiagnostics() {
48322
48557
  const magicContextConfig = readConfig3(configPaths.magicContextConfig);
48323
48558
  const storageResolution = getStorageResolution();
48324
48559
  const storageDirPath = storageResolution.path;
48325
- const contextDbPath = join36(storageDirPath, "context.db");
48560
+ const contextDbPath = join37(storageDirPath, "context.db");
48326
48561
  let compactionEnabled = false;
48327
48562
  try {
48328
48563
  compactionEnabled = isCompactionEnabled(loadPluginConfig(process.cwd()));
@@ -48354,7 +48589,7 @@ async function collectDiagnostics() {
48354
48589
  opencodeConfigHasPlugin: configHasPluginEntry(opencodeConfig.value),
48355
48590
  tuiConfigHasPlugin: configHasPluginEntry(tuiConfig.value),
48356
48591
  magicContextConfig: {
48357
- exists: existsSync45(configPaths.magicContextConfig),
48592
+ exists: existsSync46(configPaths.magicContextConfig),
48358
48593
  ...magicContextConfig.error ? { parseError: magicContextConfig.error } : {},
48359
48594
  flags: sanitizeValue(magicContextConfig.value ?? {}) ?? {}
48360
48595
  },
@@ -48362,7 +48597,7 @@ async function collectDiagnostics() {
48362
48597
  storageDir: {
48363
48598
  path: storageDirPath,
48364
48599
  source: storageResolution.source,
48365
- exists: existsSync45(storageDirPath),
48600
+ exists: existsSync46(storageDirPath),
48366
48601
  contextDbSizeBytes: fileSize(contextDbPath)
48367
48602
  },
48368
48603
  openCodeDatabase: {
@@ -48616,9 +48851,9 @@ var init_embedding_local = __esm(async () => {
48616
48851
 
48617
48852
  // src/lib/embedding-runtime.ts
48618
48853
  import { spawnSync as spawnSync9 } from "node:child_process";
48619
- import { existsSync as existsSync46, readFileSync as readFileSync28 } from "node:fs";
48854
+ import { existsSync as existsSync47, readFileSync as readFileSync29 } from "node:fs";
48620
48855
  import { createRequire as createRequire5 } from "node:module";
48621
- import { dirname as dirname24, join as join37, sep } from "node:path";
48856
+ import { dirname as dirname24, join as join38, sep } from "node:path";
48622
48857
  function describeError(error) {
48623
48858
  const message = error instanceof Error ? error.message : String(error ?? "unknown error");
48624
48859
  const code = error?.code;
@@ -48760,11 +48995,11 @@ function expectedBinaryRelPath(platform, arch) {
48760
48995
  const supportedArch = arch === "x64" || arch === "arm64";
48761
48996
  if (!supportedPlatform || !supportedArch)
48762
48997
  return null;
48763
- return join37("bin", "napi-v6", platform, arch, "onnxruntime_binding.node");
48998
+ return join38("bin", "napi-v6", platform, arch, "onnxruntime_binding.node");
48764
48999
  }
48765
49000
  function onnxRuntimeNodeVersion(packageDir) {
48766
49001
  try {
48767
- const parsed = JSON.parse(readFileSync28(join37(packageDir, "package.json"), "utf8"));
49002
+ const parsed = JSON.parse(readFileSync29(join38(packageDir, "package.json"), "utf8"));
48768
49003
  return typeof parsed.version === "string" ? parsed.version : undefined;
48769
49004
  } catch {
48770
49005
  return;
@@ -48813,7 +49048,7 @@ function formatLocalEmbeddingRuntimeWasmSelected(status) {
48813
49048
  function requireNodeWasmBundle(probe, candidates) {
48814
49049
  if (probe.state === "failed")
48815
49050
  return probe;
48816
- const bundlePath = candidates.find((candidate) => existsSync46(candidate));
49051
+ const bundlePath = candidates.find((candidate) => existsSync47(candidate));
48817
49052
  return bundlePath ? probe : {
48818
49053
  state: "failed",
48819
49054
  reason: `functional Node WASM Transformers bundle is missing (checked ${candidates.join(", ")})`
@@ -48821,13 +49056,13 @@ function requireNodeWasmBundle(probe, candidates) {
48821
49056
  }
48822
49057
  function nodeWasmBundleCandidates(installRoot) {
48823
49058
  return [
48824
- join37(installRoot, "dist", "transformers-node-wasm.js"),
48825
- join37(installRoot, "node_modules", "@cortexkit", "opencode-magic-context", "dist", "transformers-node-wasm.js"),
48826
- join37(installRoot, "node_modules", "@cortexkit", "pi-magic-context", "dist", "transformers-node-wasm.js")
49059
+ join38(installRoot, "dist", "transformers-node-wasm.js"),
49060
+ join38(installRoot, "node_modules", "@cortexkit", "opencode-magic-context", "dist", "transformers-node-wasm.js"),
49061
+ join38(installRoot, "node_modules", "@cortexkit", "pi-magic-context", "dist", "transformers-node-wasm.js")
48827
49062
  ];
48828
49063
  }
48829
49064
  function probeWasmRuntimeAt(installRoot) {
48830
- const requireFn = createRequire5(join37(installRoot, "package.json"));
49065
+ const requireFn = createRequire5(join38(installRoot, "package.json"));
48831
49066
  return requireNodeWasmBundle(probeWasmRuntimeFromRequire(requireFn), nodeWasmBundleCandidates(installRoot));
48832
49067
  }
48833
49068
  function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
@@ -48836,9 +49071,9 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
48836
49071
  const wasm = probeWasmRuntimeAt(installRoot);
48837
49072
  return wasm.state === "ok" ? { state: "wasm-selected", wasmPath: wasm.wasmPath } : { state: "wasm-broken", wasmReason: wasm.reason };
48838
49073
  }
48839
- const packageDir = join37(installRoot, "node_modules", "onnxruntime-node");
49074
+ const packageDir = join38(installRoot, "node_modules", "onnxruntime-node");
48840
49075
  let native;
48841
- if (!existsSync46(join37(packageDir, "package.json"))) {
49076
+ if (!existsSync47(join38(packageDir, "package.json"))) {
48842
49077
  native = { state: "package-missing", packageDir };
48843
49078
  } else {
48844
49079
  const rel = expectedBinaryRelPath(platform, arch);
@@ -48848,8 +49083,8 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
48848
49083
  binaryPath: packageDir
48849
49084
  };
48850
49085
  } else {
48851
- const binaryPath = join37(packageDir, rel);
48852
- native = existsSync46(binaryPath) ? probeOnnxRuntimeNodeLoad(packageDir) ?? { state: "ok", binaryPath } : {
49086
+ const binaryPath = join38(packageDir, rel);
49087
+ native = existsSync47(binaryPath) ? probeOnnxRuntimeNodeLoad(packageDir) ?? { state: "ok", binaryPath } : {
48853
49088
  state: "binary-missing",
48854
49089
  packageDir,
48855
49090
  expectedBinary: binaryPath,
@@ -48860,7 +49095,7 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
48860
49095
  return withWasmFallback(native, () => probeWasmRuntimeAt(installRoot));
48861
49096
  }
48862
49097
  function checkLocalEmbeddingRuntime(installRoots, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
48863
- const existing = installRoots.filter((root) => existsSync46(root));
49098
+ const existing = installRoots.filter((root) => existsSync47(root));
48864
49099
  if (existing.length === 0) {
48865
49100
  return {
48866
49101
  state: "unknown",
@@ -48890,15 +49125,15 @@ function packageDirFromResolved(resolvedPath, packageName) {
48890
49125
  }
48891
49126
  function probeWasmRuntimeByResolution(pluginDir) {
48892
49127
  try {
48893
- const reqPlugin = createRequire5(join37(pluginDir, "package.json"));
49128
+ const reqPlugin = createRequire5(join38(pluginDir, "package.json"));
48894
49129
  const direct = probeWasmRuntimeFromRequire(reqPlugin);
48895
49130
  let probe = direct;
48896
49131
  if (direct.state === "failed" && direct.reason.startsWith("onnxruntime-web is not resolvable")) {
48897
49132
  const tfResolved = reqPlugin.resolve("@huggingface/transformers");
48898
49133
  const tfDir = packageDirFromResolved(tfResolved, "@huggingface/transformers");
48899
- probe = probeWasmRuntimeFromRequire(createRequire5(join37(tfDir, "package.json")));
49134
+ probe = probeWasmRuntimeFromRequire(createRequire5(join38(tfDir, "package.json")));
48900
49135
  }
48901
- return requireNodeWasmBundle(probe, [join37(pluginDir, "dist", "transformers-node-wasm.js")]);
49136
+ return requireNodeWasmBundle(probe, [join38(pluginDir, "dist", "transformers-node-wasm.js")]);
48902
49137
  } catch (error) {
48903
49138
  return {
48904
49139
  state: "failed",
@@ -48907,7 +49142,7 @@ function probeWasmRuntimeByResolution(pluginDir) {
48907
49142
  }
48908
49143
  }
48909
49144
  function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
48910
- if (!existsSync46(join37(pluginDir, "package.json"))) {
49145
+ if (!existsSync47(join38(pluginDir, "package.json"))) {
48911
49146
  return { state: "unknown", reason: "plugin package dir not found" };
48912
49147
  }
48913
49148
  const selectedRuntime = resolveLocalEmbeddingWorkerRuntime(runtimePreference, host);
@@ -48918,13 +49153,13 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
48918
49153
  let onnxDir = null;
48919
49154
  let resolveError;
48920
49155
  try {
48921
- const reqPlugin = createRequire5(join37(pluginDir, "package.json"));
49156
+ const reqPlugin = createRequire5(join38(pluginDir, "package.json"));
48922
49157
  try {
48923
49158
  onnxDir = packageDirFromResolved(reqPlugin.resolve("onnxruntime-node"), "onnxruntime-node");
48924
49159
  } catch {
48925
49160
  const tfResolved = reqPlugin.resolve("@huggingface/transformers");
48926
49161
  const tfDir = packageDirFromResolved(tfResolved, "@huggingface/transformers");
48927
- const reqTf = createRequire5(join37(tfDir, "package.json"));
49162
+ const reqTf = createRequire5(join38(tfDir, "package.json"));
48928
49163
  onnxDir = packageDirFromResolved(reqTf.resolve("onnxruntime-node"), "onnxruntime-node");
48929
49164
  }
48930
49165
  } catch (error) {
@@ -48932,7 +49167,7 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
48932
49167
  if (resolveError === "ERR_MODULE_NOT_FOUND" || resolveError === "MODULE_NOT_FOUND") {
48933
49168
  return withWasmFallback({
48934
49169
  state: "package-missing",
48935
- packageDir: join37(pluginDir, "node_modules", "onnxruntime-node")
49170
+ packageDir: join38(pluginDir, "node_modules", "onnxruntime-node")
48936
49171
  }, () => probeWasmRuntimeByResolution(pluginDir));
48937
49172
  }
48938
49173
  return {
@@ -48948,8 +49183,8 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
48948
49183
  if (rel === null) {
48949
49184
  native = probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath: onnxDir };
48950
49185
  } else {
48951
- const binaryPath = join37(onnxDir, rel);
48952
- native = existsSync46(binaryPath) ? probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath } : {
49186
+ const binaryPath = join38(onnxDir, rel);
49187
+ native = existsSync47(binaryPath) ? probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath } : {
48953
49188
  state: "binary-missing",
48954
49189
  packageDir: onnxDir,
48955
49190
  expectedBinary: binaryPath,
@@ -48985,7 +49220,7 @@ var init_embedding_runtime = __esm(async () => {
48985
49220
 
48986
49221
  // src/lib/logs-opencode.ts
48987
49222
  import { mkdirSync as mkdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
48988
- import { dirname as dirname25, join as join38 } from "node:path";
49223
+ import { dirname as dirname25, join as join39 } from "node:path";
48989
49224
  function formatTimestamp(date) {
48990
49225
  const pad = (value) => String(value).padStart(2, "0");
48991
49226
  return [
@@ -49074,11 +49309,11 @@ async function bundleIssueReport(report, description, title, sessionFilter = nul
49074
49309
  const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
49075
49310
  const truncated = bodyMarkdown !== rawBodyMarkdown;
49076
49311
  const timestamp = formatTimestamp(new Date);
49077
- const path = options.outputPath ?? join38(process.cwd(), `magic-context-issue-${timestamp}.md`);
49312
+ const path = options.outputPath ?? join39(process.cwd(), `magic-context-issue-${timestamp}.md`);
49078
49313
  mkdirSync8(dirname25(path), { recursive: true });
49079
49314
  writeFileSync8(path, `${bodyMarkdown}
49080
49315
  `);
49081
- const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join38(process.cwd(), `magic-context-issue-${timestamp}-full.md`) : undefined;
49316
+ const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join39(process.cwd(), `magic-context-issue-${timestamp}-full.md`) : undefined;
49082
49317
  if (fullPath)
49083
49318
  writeFileSync8(fullPath, `${rawBodyMarkdown}
49084
49319
  `);
@@ -49891,10 +50126,10 @@ function removeDeprecatedReasoningAge(config) {
49891
50126
 
49892
50127
  // src/commands/doctor-opencode.ts
49893
50128
  import { spawnSync as spawnSync10 } from "node:child_process";
49894
- import { existsSync as existsSync47, mkdtempSync as mkdtempSync4, readFileSync as readFileSync29, rmSync as rmSync9 } from "node:fs";
50129
+ import { existsSync as existsSync48, mkdtempSync as mkdtempSync4, readFileSync as readFileSync30, rmSync as rmSync9 } from "node:fs";
49895
50130
  import { createRequire as createRequire6 } from "node:module";
49896
50131
  import { homedir as homedir21, tmpdir as tmpdir4 } from "node:os";
49897
- import { dirname as dirname26, join as join39, resolve as resolve18 } from "node:path";
50132
+ import { dirname as dirname26, join as join40, resolve as resolve19 } from "node:path";
49898
50133
  function formatSharedDbRowCounts(db) {
49899
50134
  return SHARED_DB_ROW_COUNT_TABLES.map((table) => {
49900
50135
  try {
@@ -49965,7 +50200,7 @@ function checkConfiguredVariantCatalog(config, hostGeneration, warn, run = (args
49965
50200
  }
49966
50201
  if (models.length === 0)
49967
50202
  return;
49968
- const tempRoot = mkdtempSync4(join39(tmpdir4(), "magic-context-opencode-catalog-"));
50203
+ const tempRoot = mkdtempSync4(join40(tmpdir4(), "magic-context-opencode-catalog-"));
49969
50204
  try {
49970
50205
  const command = hostGeneration === "v2" ? ["api", "model.list", "--param", `directory=${projectDir}`] : ["models", "--verbose"];
49971
50206
  const guidance = `opencode ${command.join(" ")}`;
@@ -50141,7 +50376,7 @@ function getSelfVersion2() {
50141
50376
  function describeAutoUpdateStall(specifier, autoUpdateEnabled, storageDir = getMagicContextStorageDir()) {
50142
50377
  if (!autoUpdateEnabled || !isPinnedOpenCodePluginSpecifier(specifier))
50143
50378
  return null;
50144
- const state = readAutoUpdateCheckState(join39(storageDir, AUTO_UPDATE_CHECK_STATE_FILENAME));
50379
+ const state = readAutoUpdateCheckState(join40(storageDir, AUTO_UPDATE_CHECK_STATE_FILENAME));
50145
50380
  const owner = isUpdaterPinnedSpec(state, specifier) ? "updater" : "you";
50146
50381
  return `auto-update: stalled — config pinned to ${specifier} (by ${owner})`;
50147
50382
  }
@@ -50150,15 +50385,15 @@ function getUserNpmrcPath() {
50150
50385
  if (custom)
50151
50386
  return custom;
50152
50387
  const home = process.env.HOME?.trim();
50153
- return join39(home || homedir21(), ".npmrc");
50388
+ return join40(home || homedir21(), ".npmrc");
50154
50389
  }
50155
50390
  function collectNpmReleaseAgeWarnings() {
50156
50391
  const ageWarnings = [];
50157
50392
  const npmrcPath = getUserNpmrcPath();
50158
- if (!existsSync47(npmrcPath))
50393
+ if (!existsSync48(npmrcPath))
50159
50394
  return ageWarnings;
50160
50395
  try {
50161
- const npmrc = readFileSync29(npmrcPath, "utf-8");
50396
+ const npmrc = readFileSync30(npmrcPath, "utf-8");
50162
50397
  for (const line of npmrc.split(`
50163
50398
  `)) {
50164
50399
  const trimmed = line.trim();
@@ -50199,7 +50434,7 @@ async function runIssueFlow2(options = {}, deps = { collectDiagnostics }) {
50199
50434
  if (options.reportPath) {
50200
50435
  try {
50201
50436
  const report = await deps.collectDiagnostics();
50202
- const bundled = await bundleIssueReport(report, "Generated non-interactively by `doctor --issue --report`.", "Magic Context diagnostic report", null, { outputPath: resolve18(process.cwd(), options.reportPath) });
50437
+ const bundled = await bundleIssueReport(report, "Generated non-interactively by `doctor --issue --report`.", "Magic Context diagnostic report", null, { outputPath: resolve19(process.cwd(), options.reportPath) });
50203
50438
  log3.info(bundled.fullPath ? `Report written to ${bundled.path}; full bundle at ${bundled.fullPath}` : `Report written to ${bundled.path}`);
50204
50439
  return 0;
50205
50440
  } catch (error) {
@@ -50293,7 +50528,7 @@ function checkLocalEmbeddingRuntimeForDoctor(runtimePreference = "auto") {
50293
50528
  return { issues: 0 };
50294
50529
  }
50295
50530
  async function checkEmbeddingConfig(magicContextConfigPath) {
50296
- if (!existsSync47(magicContextConfigPath)) {
50531
+ if (!existsSync48(magicContextConfigPath)) {
50297
50532
  return checkLocalEmbeddingRuntimeForDoctor();
50298
50533
  }
50299
50534
  let rawText;
@@ -50468,7 +50703,7 @@ async function runDoctor2(options = {}) {
50468
50703
  const v22Result = await runV22BackfillCommands({
50469
50704
  name: "OpenCode",
50470
50705
  openDatabase: (readonly = true) => {
50471
- const dbPath = join39(getMagicContextStorageDir(), "context.db");
50706
+ const dbPath = join40(getMagicContextStorageDir(), "context.db");
50472
50707
  v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
50473
50708
  return v22Db;
50474
50709
  },
@@ -50500,7 +50735,7 @@ async function runDoctor2(options = {}) {
50500
50735
  failCount++;
50501
50736
  issues++;
50502
50737
  };
50503
- const authorityDbPath = join39(getMagicContextStorageDir(), "context.db");
50738
+ const authorityDbPath = join40(getMagicContextStorageDir(), "context.db");
50504
50739
  let authorityDb = null;
50505
50740
  try {
50506
50741
  authorityDb = openExistingContextDatabase(authorityDbPath, { readonly: true });
@@ -50539,7 +50774,7 @@ async function runDoctor2(options = {}) {
50539
50774
  let magicContextStatusKnown = paths.opencodeConfigFormat === "none";
50540
50775
  if (!magicContextStatusKnown) {
50541
50776
  try {
50542
- const config = import_comment_json11.parse(readFileSync29(paths.opencodeConfig, "utf-8"));
50777
+ const config = import_comment_json11.parse(readFileSync30(paths.opencodeConfig, "utf-8"));
50543
50778
  magicContextInstalled = isOpenCodePluginRegistered(config, dirname26(paths.opencodeConfig));
50544
50779
  magicContextStatusKnown = true;
50545
50780
  } catch {}
@@ -50675,7 +50910,7 @@ async function runDoctor2(options = {}) {
50675
50910
  pass(`OpenCode config: ${paths.opencodeConfig}`);
50676
50911
  }
50677
50912
  let autoUpdateEnabled = true;
50678
- if (existsSync47(paths.magicContextConfig)) {
50913
+ if (existsSync48(paths.magicContextConfig)) {
50679
50914
  pass(`Magic Context config: ${paths.magicContextConfig}`);
50680
50915
  try {
50681
50916
  const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
@@ -50711,7 +50946,7 @@ async function runDoctor2(options = {}) {
50711
50946
  warn(`No magic-context.jsonc found — using defaults`);
50712
50947
  log3.info(" Run 'setup' to create one with model recommendations");
50713
50948
  }
50714
- if (existsSync47(paths.magicContextConfig)) {
50949
+ if (existsSync48(paths.magicContextConfig)) {
50715
50950
  try {
50716
50951
  const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
50717
50952
  if (!raw)
@@ -50851,7 +51086,7 @@ async function runDoctor2(options = {}) {
50851
51086
  };
50852
51087
  if (paths.opencodeConfigFormat !== "none") {
50853
51088
  try {
50854
- const raw = readFileSync29(paths.opencodeConfig, "utf-8");
51089
+ const raw = readFileSync30(paths.opencodeConfig, "utf-8");
50855
51090
  const config = import_comment_json11.parse(raw);
50856
51091
  const configName = paths.opencodeConfigFormat === "jsonc" ? "opencode.jsonc" : "opencode.json";
50857
51092
  const configDir = dirname26(paths.opencodeConfig);
@@ -50944,9 +51179,9 @@ async function runDoctor2(options = {}) {
50944
51179
  pass("Added TUI sidebar plugin to tui.json");
50945
51180
  warn("Restart OpenCode to see the sidebar");
50946
51181
  fixed++;
50947
- } else if (existsSync47(paths.tuiConfig)) {
51182
+ } else if (existsSync48(paths.tuiConfig)) {
50948
51183
  try {
50949
- const tuiRaw = readFileSync29(paths.tuiConfig, "utf-8");
51184
+ const tuiRaw = readFileSync30(paths.tuiConfig, "utf-8");
50950
51185
  const tuiConfig = import_comment_json11.parse(tuiRaw);
50951
51186
  const tuiConfigDir = dirname26(paths.tuiConfig);
50952
51187
  const tuiRawPlugins = Array.isArray(tuiConfig?.plugin) ? tuiConfig.plugin : [];
@@ -50985,7 +51220,7 @@ async function runDoctor2(options = {}) {
50985
51220
  fail("Could not create or verify the TUI sidebar config");
50986
51221
  }
50987
51222
  }
50988
- if (existsSync47(paths.magicContextConfig)) {
51223
+ if (existsSync48(paths.magicContextConfig)) {
50989
51224
  try {
50990
51225
  const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
50991
51226
  if (!raw)
@@ -51007,9 +51242,9 @@ async function runDoctor2(options = {}) {
51007
51242
  else
51008
51243
  passCount++;
51009
51244
  const storage = getMagicContextStorageResolution();
51010
- const dbPath = join39(storage.path, "context.db");
51245
+ const dbPath = join40(storage.path, "context.db");
51011
51246
  log3.info(`Shared storage: ${storage.path} (source: ${storage.source})`);
51012
- if (!existsSync47(dbPath)) {
51247
+ if (!existsSync48(dbPath)) {
51013
51248
  log3.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
51014
51249
  } else {
51015
51250
  log3.info(`Shared context DB exists at ${dbPath}`);
@@ -51092,7 +51327,7 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
51092
51327
  let pluginConfigUse;
51093
51328
  if (paths.opencodeConfigFormat !== "none") {
51094
51329
  try {
51095
- pluginConfigUse = readOpenCodePluginConfigUse(import_comment_json11.parse(readFileSync29(paths.opencodeConfig, "utf-8")), dirname26(paths.opencodeConfig));
51330
+ pluginConfigUse = readOpenCodePluginConfigUse(import_comment_json11.parse(readFileSync30(paths.opencodeConfig, "utf-8")), dirname26(paths.opencodeConfig));
51096
51331
  } catch {}
51097
51332
  }
51098
51333
  const cacheResult = await clearPluginCache({
@@ -51144,7 +51379,7 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
51144
51379
  let v2DistTag;
51145
51380
  if (paths.opencodeConfigFormat !== "none") {
51146
51381
  try {
51147
- v2DistTag = configuredOpenCodeV2DistTag(import_comment_json11.parse(readFileSync29(paths.opencodeConfig, "utf-8")));
51382
+ v2DistTag = configuredOpenCodeV2DistTag(import_comment_json11.parse(readFileSync30(paths.opencodeConfig, "utf-8")));
51148
51383
  } catch {}
51149
51384
  }
51150
51385
  const v2Cache = reportOpenCodeV2PluginCache(checkOpenCodeV2PluginCache({
@@ -51525,9 +51760,9 @@ var init_model_chain_health = __esm(() => {
51525
51760
  });
51526
51761
 
51527
51762
  // src/lib/diagnostics-pi.ts
51528
- import { existsSync as existsSync48, readdirSync as readdirSync10, readFileSync as readFileSync30, statSync as statSync24 } from "node:fs";
51763
+ import { existsSync as existsSync49, readdirSync as readdirSync11, readFileSync as readFileSync31, statSync as statSync25 } from "node:fs";
51529
51764
  import { createRequire as createRequire7 } from "node:module";
51530
- import { join as join40 } from "node:path";
51765
+ import { join as join41 } from "node:path";
51531
51766
  function getSelfVersion3() {
51532
51767
  const req = createRequire7(import.meta.url);
51533
51768
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -51542,7 +51777,7 @@ function getSelfVersion3() {
51542
51777
  }
51543
51778
  function fileSize2(path) {
51544
51779
  try {
51545
- return existsSync48(path) ? statSync24(path).size : 0;
51780
+ return existsSync49(path) ? statSync25(path).size : 0;
51546
51781
  } catch {
51547
51782
  return 0;
51548
51783
  }
@@ -51554,11 +51789,11 @@ function sanitizeValue2(value) {
51554
51789
  return sanitizeConfigValue(value);
51555
51790
  }
51556
51791
  function readJsonc(path) {
51557
- if (!existsSync48(path))
51792
+ if (!existsSync49(path))
51558
51793
  return { value: {} };
51559
51794
  try {
51560
51795
  return {
51561
- value: import_comment_json12.parse(readFileSync30(path, "utf-8"))
51796
+ value: import_comment_json12.parse(readFileSync31(path, "utf-8"))
51562
51797
  };
51563
51798
  } catch (error) {
51564
51799
  return {
@@ -51574,7 +51809,7 @@ function readConfigDiagnostic(path) {
51574
51809
  const parsed = readJsonc(path);
51575
51810
  return {
51576
51811
  path,
51577
- exists: existsSync48(path),
51812
+ exists: existsSync49(path),
51578
51813
  ...parsed.parseError ? { parseError: parsed.parseError } : {},
51579
51814
  flags: sanitizeValue2(parsed.value)
51580
51815
  };
@@ -51592,25 +51827,25 @@ function reverseSlugToDirectory(slug) {
51592
51827
  }
51593
51828
  function collectPiRecentSessions() {
51594
51829
  const sessionsRoot = getPiSessionsRoot();
51595
- if (!existsSync48(sessionsRoot))
51830
+ if (!existsSync49(sessionsRoot))
51596
51831
  return [];
51597
51832
  try {
51598
- const slugs = readdirSync10(sessionsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
51833
+ const slugs = readdirSync11(sessionsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
51599
51834
  const candidates = [];
51600
51835
  for (const slug of slugs) {
51601
51836
  const directory = reverseSlugToDirectory(slug);
51602
51837
  if (!directory)
51603
51838
  continue;
51604
- const slugDir = join40(sessionsRoot, slug);
51839
+ const slugDir = join41(sessionsRoot, slug);
51605
51840
  let files;
51606
51841
  try {
51607
- files = readdirSync10(slugDir).filter((name) => name.endsWith(".jsonl"));
51842
+ files = readdirSync11(slugDir).filter((name) => name.endsWith(".jsonl"));
51608
51843
  } catch {
51609
51844
  continue;
51610
51845
  }
51611
51846
  for (const file of files) {
51612
51847
  try {
51613
- const mtime = statSync24(join40(slugDir, file)).mtimeMs;
51848
+ const mtime = statSync25(join41(slugDir, file)).mtimeMs;
51614
51849
  const sessionId = file.replace(/\.jsonl$/, "");
51615
51850
  candidates.push({ sessionId, directory, mtime });
51616
51851
  } catch {}
@@ -51628,7 +51863,7 @@ function collectPiRecentSessions() {
51628
51863
  }
51629
51864
  function parseHistorianDumpMeta2(path) {
51630
51865
  try {
51631
- const xml = readFileSync30(path, "utf-8");
51866
+ const xml = readFileSync31(path, "utf-8");
51632
51867
  const parsed = parseCompartmentOutput(xml);
51633
51868
  const factCountByCategory = {};
51634
51869
  for (const fact of parsed.facts) {
@@ -51661,11 +51896,11 @@ function parseHistorianDumpMeta2(path) {
51661
51896
  }
51662
51897
  }
51663
51898
  function listDumpsInDir2(dir, limit) {
51664
- if (!existsSync48(dir))
51899
+ if (!existsSync49(dir))
51665
51900
  return { count: 0, recent: [] };
51666
51901
  try {
51667
- const entries = readdirSync10(dir).filter((name) => name.endsWith(".xml")).map((name) => {
51668
- const stat = statSync24(join40(dir, name));
51902
+ const entries = readdirSync11(dir).filter((name) => name.endsWith(".xml")).map((name) => {
51903
+ const stat = statSync25(join41(dir, name));
51669
51904
  return {
51670
51905
  name,
51671
51906
  mtime: stat.mtimeMs,
@@ -51674,7 +51909,7 @@ function listDumpsInDir2(dir, limit) {
51674
51909
  }).sort((a, b) => b.mtime - a.mtime);
51675
51910
  const now = Date.now();
51676
51911
  const recent = entries.slice(0, limit).map((entry) => {
51677
- const meta = parseHistorianDumpMeta2(join40(dir, entry.name));
51912
+ const meta = parseHistorianDumpMeta2(join41(dir, entry.name));
51678
51913
  const summary = {
51679
51914
  name: entry.name,
51680
51915
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -51738,7 +51973,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
51738
51973
  const loaded = loadPiConfig({ cwd });
51739
51974
  const storageResolution = getMagicContextStorageResolution();
51740
51975
  const storageDirPath = storageResolution.path;
51741
- const dbPath = join40(storageDirPath, "context.db");
51976
+ const dbPath = join41(storageDirPath, "context.db");
51742
51977
  const logFiles = inspectMagicContextLogs("pi");
51743
51978
  const primaryLog = logFiles.find((file) => file.exists) ?? logFiles[0];
51744
51979
  const otherPiExtensions = packages.filter((entry) => !isPiMagicContextPackageEntry(entry)).map(describePiPackageEntry);
@@ -51755,7 +51990,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
51755
51990
  piVersion: pi ? getPiVersion(pi.path) : null,
51756
51991
  settings: {
51757
51992
  path: settingsPath,
51758
- exists: existsSync48(settingsPath),
51993
+ exists: existsSync49(settingsPath),
51759
51994
  ...settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {},
51760
51995
  hasMagicContextPackage: hasPiMagicContextPackage(packages),
51761
51996
  packages: sanitizeValue2(packages)
@@ -51772,7 +52007,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
51772
52007
  storageDir: {
51773
52008
  path: storageDirPath,
51774
52009
  source: storageResolution.source,
51775
- exists: existsSync48(storageDirPath),
52010
+ exists: existsSync49(storageDirPath),
51776
52011
  contextDbSizeBytes: fileSize2(dbPath)
51777
52012
  },
51778
52013
  conflicts: {
@@ -51878,7 +52113,7 @@ var init_diagnostics_pi = __esm(() => {
51878
52113
 
51879
52114
  // src/lib/logs-pi.ts
51880
52115
  import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync9 } from "node:fs";
51881
- import { dirname as dirname27, join as join41 } from "node:path";
52116
+ import { dirname as dirname27, join as join42 } from "node:path";
51882
52117
  function formatTimestamp2(date) {
51883
52118
  const pad = (value) => String(value).padStart(2, "0");
51884
52119
  return [
@@ -51932,11 +52167,11 @@ async function bundleIssueReport2(report, description, title, options = {}) {
51932
52167
  const truncated = bodyMarkdown !== rawBodyMarkdown;
51933
52168
  const cwd = options.cwd ?? process.cwd();
51934
52169
  const timestamp = formatTimestamp2(options.now ?? new Date);
51935
- const path = options.outputPath ?? join41(cwd, `magic-context-pi-issue-${timestamp}.md`);
52170
+ const path = options.outputPath ?? join42(cwd, `magic-context-pi-issue-${timestamp}.md`);
51936
52171
  mkdirSync9(dirname27(path), { recursive: true });
51937
52172
  writeFileSync9(path, `${bodyMarkdown}
51938
52173
  `);
51939
- const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join41(cwd, `magic-context-pi-issue-${timestamp}-full.md`) : undefined;
52174
+ const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join42(cwd, `magic-context-pi-issue-${timestamp}-full.md`) : undefined;
51940
52175
  if (fullPath)
51941
52176
  writeFileSync9(fullPath, `${rawBodyMarkdown}
51942
52177
  `);
@@ -51950,10 +52185,10 @@ var init_logs_pi = __esm(() => {
51950
52185
 
51951
52186
  // src/commands/doctor-pi.ts
51952
52187
  import { execFileSync as execFileSync9, spawnSync as spawnSync11 } from "node:child_process";
51953
- import { existsSync as existsSync49, readdirSync as readdirSync11, readFileSync as readFileSync31, rmSync as rmSync10, statSync as statSync25 } from "node:fs";
52188
+ import { existsSync as existsSync50, readdirSync as readdirSync12, readFileSync as readFileSync32, rmSync as rmSync10, statSync as statSync26 } from "node:fs";
51954
52189
  import { createRequire as createRequire8 } from "node:module";
51955
52190
  import { homedir as homedir22 } from "node:os";
51956
- import { isAbsolute as isAbsolute9, join as join42 } from "node:path";
52191
+ import { isAbsolute as isAbsolute9, join as join43 } from "node:path";
51957
52192
  function depsFrom(options) {
51958
52193
  return {
51959
52194
  ...DEFAULT_DEPS5,
@@ -52045,7 +52280,7 @@ function summarize(results) {
52045
52280
  function readJsonc2(path) {
52046
52281
  try {
52047
52282
  return {
52048
- value: import_comment_json13.parse(readFileSync31(path, "utf-8"))
52283
+ value: import_comment_json13.parse(readFileSync32(path, "utf-8"))
52049
52284
  };
52050
52285
  } catch (error) {
52051
52286
  return {
@@ -52095,15 +52330,15 @@ function piPluginDirCandidates(packages, cwd) {
52095
52330
  if (resolved)
52096
52331
  dirs.push(resolved);
52097
52332
  }
52098
- dirs.push(join42(agentDir, "npm", "node_modules", PACKAGE_NAME2));
52099
- dirs.push(join42(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2));
52100
- return dirs.filter((dir) => existsSync49(join42(dir, "package.json")));
52333
+ dirs.push(join43(agentDir, "npm", "node_modules", PACKAGE_NAME2));
52334
+ dirs.push(join43(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2));
52335
+ return dirs.filter((dir) => existsSync50(join43(dir, "package.json")));
52101
52336
  }
52102
52337
  function projectConfigPath(cwd) {
52103
52338
  return resolveCortexKitProjectConfigPath(cwd);
52104
52339
  }
52105
52340
  function readConfigForEmbedding(path, isProjectConfig) {
52106
- if (!existsSync49(path))
52341
+ if (!existsSync50(path))
52107
52342
  return null;
52108
52343
  try {
52109
52344
  const raw = loadRawConfigFile({
@@ -52189,35 +52424,35 @@ function pinnedVersionFromPackageSpecifier(specifier) {
52189
52424
  }
52190
52425
  function cacheRoots(cwd) {
52191
52426
  const home = process.env.HOME?.trim();
52192
- const cacheHome = process.env.XDG_CACHE_HOME || join42(home || homedir22(), ".cache");
52427
+ const cacheHome = process.env.XDG_CACHE_HOME || join43(home || homedir22(), ".cache");
52193
52428
  const piCacheRoot = getPiCacheRoot();
52194
52429
  return [
52195
- join42(piCacheRoot, "extensions"),
52196
- join42(piCacheRoot, "packages"),
52197
- join42(cacheHome, "pi", "extensions"),
52198
- join42(cacheHome, "pi", "packages"),
52199
- join42(getPiAgentConfigDir(), "cache", "extensions"),
52200
- join42(getPiAgentConfigDir(), "npm", "node_modules", PACKAGE_NAME2),
52201
- join42(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2)
52430
+ join43(piCacheRoot, "extensions"),
52431
+ join43(piCacheRoot, "packages"),
52432
+ join43(cacheHome, "pi", "extensions"),
52433
+ join43(cacheHome, "pi", "packages"),
52434
+ join43(getPiAgentConfigDir(), "cache", "extensions"),
52435
+ join43(getPiAgentConfigDir(), "npm", "node_modules", PACKAGE_NAME2),
52436
+ join43(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2)
52202
52437
  ];
52203
52438
  }
52204
52439
  function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
52205
52440
  const found = new Map;
52206
52441
  const visit = (path, depth) => {
52207
- if (depth < 0 || !existsSync49(path))
52442
+ if (depth < 0 || !existsSync50(path))
52208
52443
  return;
52209
52444
  let stat;
52210
52445
  try {
52211
- stat = statSync25(path);
52446
+ stat = statSync26(path);
52212
52447
  } catch {
52213
52448
  return;
52214
52449
  }
52215
52450
  if (!stat.isDirectory())
52216
52451
  return;
52217
- const packageJson = join42(path, "package.json");
52218
- if (existsSync49(packageJson)) {
52452
+ const packageJson = join43(path, "package.json");
52453
+ if (existsSync50(packageJson)) {
52219
52454
  try {
52220
- const pkg = JSON.parse(readFileSync31(packageJson, "utf-8"));
52455
+ const pkg = JSON.parse(readFileSync32(packageJson, "utf-8"));
52221
52456
  const name = typeof pkg.name === "string" ? pkg.name : "";
52222
52457
  const version = typeof pkg.version === "string" ? pkg.version : undefined;
52223
52458
  if (name === PACKAGE_NAME2) {
@@ -52232,12 +52467,12 @@ function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
52232
52467
  }
52233
52468
  let entries = [];
52234
52469
  try {
52235
- entries = readdirSync11(path);
52470
+ entries = readdirSync12(path);
52236
52471
  } catch {
52237
52472
  return;
52238
52473
  }
52239
52474
  for (const entry of entries)
52240
- visit(join42(path, entry), depth - 1);
52475
+ visit(join43(path, entry), depth - 1);
52241
52476
  };
52242
52477
  for (const root of cacheRoots(cwd))
52243
52478
  visit(root, 5);
@@ -52298,7 +52533,7 @@ async function runHealthChecks2(options) {
52298
52533
  const settingsPath = getPiUserExtensionsPath();
52299
52534
  let packages = [];
52300
52535
  let piPluginInstalled = false;
52301
- if (!existsSync49(settingsPath)) {
52536
+ if (!existsSync50(settingsPath)) {
52302
52537
  if (pi) {
52303
52538
  add2(results, "info", `${piVersion ? `Pi ${piVersion}` : "Pi"} found; Magic Context is not installed there (run setup to add it)`);
52304
52539
  }
@@ -52340,7 +52575,7 @@ async function runHealthChecks2(options) {
52340
52575
  ["user", userConfigPath, true],
52341
52576
  ["project", projectPath, false]
52342
52577
  ]) {
52343
- if (!existsSync49(path)) {
52578
+ if (!existsSync50(path)) {
52344
52579
  if (required) {
52345
52580
  add2(results, "warn", `No ${label} magic-context.jsonc found at ${path}`);
52346
52581
  if (userConfigMigrationRefused) {
@@ -52386,9 +52621,9 @@ async function runHealthChecks2(options) {
52386
52621
  checkPiModelChains(results, pi, loadedConfig.config, options.deps);
52387
52622
  const storage = getMagicContextStorageResolution();
52388
52623
  const storageDir = storage.path;
52389
- const dbPath = join42(storageDir, "context.db");
52624
+ const dbPath = join43(storageDir, "context.db");
52390
52625
  add2(results, "info", `Shared storage: ${storageDir} (source: ${storage.source})`);
52391
- const existedBeforeOpen = existsSync49(dbPath);
52626
+ const existedBeforeOpen = existsSync50(dbPath);
52392
52627
  if (existedBeforeOpen)
52393
52628
  add2(results, "pass", `Shared context DB exists at ${dbPath}`);
52394
52629
  else
@@ -52617,7 +52852,7 @@ function writeDefaultMagicContextConfig(path) {
52617
52852
  function repair2(plan, prompts) {
52618
52853
  let fixed = 0;
52619
52854
  for (const path of plan.reasoningAgeConfigPaths) {
52620
- const content = readFileSync31(path, "utf8");
52855
+ const content = readFileSync32(path, "utf8");
52621
52856
  const parsed = readJsonc2(path);
52622
52857
  if (parsed.error)
52623
52858
  continue;
@@ -52643,7 +52878,7 @@ function repair2(plan, prompts) {
52643
52878
  }
52644
52879
  if (plan.writeUserConfig) {
52645
52880
  const configPath = getPiUserConfigPath();
52646
- if (!existsSync49(configPath)) {
52881
+ if (!existsSync50(configPath)) {
52647
52882
  try {
52648
52883
  writeDefaultMagicContextConfig(configPath);
52649
52884
  prompts.log.success(`Wrote default Magic Context config to ${configPath}`);
@@ -52697,7 +52932,7 @@ async function runIssueFlow3(options) {
52697
52932
  if (options.reportPath) {
52698
52933
  try {
52699
52934
  const report = await options.deps.collectDiagnostics(options.cwd);
52700
- const outputPath = isAbsolute9(options.reportPath) ? options.reportPath : join42(options.cwd, options.reportPath);
52935
+ const outputPath = isAbsolute9(options.reportPath) ? options.reportPath : join43(options.cwd, options.reportPath);
52701
52936
  const bundled = await bundleIssueReport2(report, "Generated non-interactively by `doctor --issue --report`.", "Magic Context diagnostic report", { cwd: options.cwd, now: options.deps.now(), outputPath });
52702
52937
  options.prompts.log.info(`Report written to ${bundled.path}`);
52703
52938
  return 0;
@@ -52781,7 +53016,7 @@ async function runDoctor3(options = {}) {
52781
53016
  const v22Result = await runV22BackfillCommands({
52782
53017
  name: "Pi",
52783
53018
  openDatabase: (readonly = true) => {
52784
- const dbPath = join42(getMagicContextStorageDir(), "context.db");
53019
+ const dbPath = join43(getMagicContextStorageDir(), "context.db");
52785
53020
  v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
52786
53021
  return v22Db;
52787
53022
  },
@@ -52899,8 +53134,8 @@ var init_doctor_pi = __esm(async () => {
52899
53134
  });
52900
53135
 
52901
53136
  // src/commands/doctor.ts
52902
- import { existsSync as existsSync50, rmSync as rmSync11 } from "node:fs";
52903
- import { join as join43 } from "node:path";
53137
+ import { existsSync as existsSync51, rmSync as rmSync11 } from "node:fs";
53138
+ import { join as join44 } from "node:path";
52904
53139
  async function runDoctor4(options) {
52905
53140
  if (options.clear)
52906
53141
  return runClear();
@@ -52918,7 +53153,7 @@ async function runDoctor4(options) {
52918
53153
  const result = await runV22BackfillCommands({
52919
53154
  name: "Magic Context",
52920
53155
  openDatabase: (readonly = true) => {
52921
- const dbPath = join43(getMagicContextStorageDir(), "context.db");
53156
+ const dbPath = join44(getMagicContextStorageDir(), "context.db");
52922
53157
  v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
52923
53158
  return v22Db;
52924
53159
  },
@@ -52938,7 +53173,7 @@ async function runDoctor4(options) {
52938
53173
  log3.warn(`Identity split check unavailable: ${error instanceof Error ? error.message : String(error)}`);
52939
53174
  }
52940
53175
  await init_migrate();
52941
- const sweepDbPath = join43(getMagicContextStorageDir(), "context.db");
53176
+ const sweepDbPath = join44(getMagicContextStorageDir(), "context.db");
52942
53177
  let sweepDb = null;
52943
53178
  try {
52944
53179
  sweepDb = openExistingContextDatabaseForMutation(sweepDbPath);
@@ -53055,7 +53290,7 @@ async function runClear() {
53055
53290
  failed += 1;
53056
53291
  continue;
53057
53292
  }
53058
- } else if (existsSync50(item.path)) {
53293
+ } else if (existsSync51(item.path)) {
53059
53294
  rmSync11(item.path, { recursive: true, force: true });
53060
53295
  }
53061
53296
  s.stop(`Cleared ${item.path}`);