@cortexkit/magic-context 0.49.48 → 0.49.49

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 +534 -580
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1733,6 +1733,7 @@ import {
1733
1733
  readFileSync as readFileSync2,
1734
1734
  readlinkSync,
1735
1735
  realpathSync,
1736
+ unlinkSync,
1736
1737
  writeFileSync
1737
1738
  } from "node:fs";
1738
1739
  import * as os from "node:os";
@@ -1832,6 +1833,7 @@ function getLegacyOpenCodeMagicContextStorageDir() {
1832
1833
  }
1833
1834
  var STORAGE_BACKUP_WARNING_CHECKED;
1834
1835
  var init_data_path = __esm(() => {
1836
+ init_logger();
1835
1837
  init_test_temp_dir();
1836
1838
  STORAGE_BACKUP_WARNING_CHECKED = Symbol.for("magic-context.storage-backup-warning-checked");
1837
1839
  });
@@ -2872,7 +2874,7 @@ var init_jsonc_edit = __esm(() => {
2872
2874
  });
2873
2875
 
2874
2876
  // ../plugin/src/config/migrate-config-location.ts
2875
- import { existsSync as existsSync3, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync2, unlinkSync } from "node:fs";
2877
+ import { existsSync as existsSync3, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync2, unlinkSync as unlinkSync2 } from "node:fs";
2876
2878
  import { homedir as homedir3 } from "node:os";
2877
2879
  import { basename as basename2, dirname as dirname4, isAbsolute as isAbsolute2, join as join3 } from "node:path";
2878
2880
  function homeDir() {
@@ -3100,7 +3102,7 @@ function markLegacySourcesMovedAside(sources, targetPath, logger) {
3100
3102
  try {
3101
3103
  const original = readFileSync3(source.path, "utf-8");
3102
3104
  atomicWriteConfigFile(markerPath, movedMarkerContent(targetPath, basename2(source.path), original));
3103
- unlinkSync(source.path);
3105
+ unlinkSync2(source.path);
3104
3106
  info?.(`Moved legacy Magic Context config ${source.path} aside to ${markerPath}; now reading ${targetPath}`);
3105
3107
  } catch (err) {
3106
3108
  const msg = err instanceof Error ? err.message : String(err);
@@ -11472,7 +11474,7 @@ import {
11472
11474
  realpathSync as realpathSync2,
11473
11475
  renameSync as renameSync2,
11474
11476
  statSync as statSync3,
11475
- unlinkSync as unlinkSync2,
11477
+ unlinkSync as unlinkSync3,
11476
11478
  writeFileSync as writeFileSync3
11477
11479
  } from "node:fs";
11478
11480
  import { basename as basename3, dirname as dirname5, join as join4 } from "node:path";
@@ -11678,7 +11680,7 @@ function writeExclusiveBackup(backupPath, bytes, mode) {
11678
11680
  }
11679
11681
  } finally {
11680
11682
  try {
11681
- unlinkSync2(temporaryPath);
11683
+ unlinkSync3(temporaryPath);
11682
11684
  } catch {}
11683
11685
  }
11684
11686
  }
@@ -11701,7 +11703,7 @@ function writeTemporaryCandidate(configPath, bytes, mode) {
11701
11703
  } catch {}
11702
11704
  }
11703
11705
  try {
11704
- unlinkSync2(path);
11706
+ unlinkSync3(path);
11705
11707
  } catch {}
11706
11708
  if (error.code !== "EEXIST")
11707
11709
  throw error;
@@ -11764,7 +11766,7 @@ function loadRawConfigFile(options) {
11764
11766
  options.afterTemporaryWrite?.();
11765
11767
  const currentBytes = readFileSync4(options.configPath);
11766
11768
  if (!hasFlatKeys(currentBytes)) {
11767
- unlinkSync2(temporaryPath);
11769
+ unlinkSync3(temporaryPath);
11768
11770
  return {
11769
11771
  configPath: options.configPath,
11770
11772
  bytes: currentBytes,
@@ -11774,7 +11776,7 @@ function loadRawConfigFile(options) {
11774
11776
  };
11775
11777
  }
11776
11778
  if (!currentBytes.equals(observedBytes)) {
11777
- unlinkSync2(temporaryPath);
11779
+ unlinkSync3(temporaryPath);
11778
11780
  observedBytes = currentBytes;
11779
11781
  continue;
11780
11782
  }
@@ -11792,7 +11794,7 @@ function loadRawConfigFile(options) {
11792
11794
  } catch (error) {
11793
11795
  if (temporaryPath) {
11794
11796
  try {
11795
- unlinkSync2(temporaryPath);
11797
+ unlinkSync3(temporaryPath);
11796
11798
  } catch {}
11797
11799
  }
11798
11800
  return {
@@ -15787,52 +15789,9 @@ var init_dashboard_install = __esm(() => {
15787
15789
  WINDOWS_UNINSTALL_KEY = `Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${DASHBOARD_PRODUCT_NAME}`;
15788
15790
  });
15789
15791
 
15790
- // src/lib/docs-proposal-gitignore.ts
15791
- import { appendFileSync as appendFileSync2, existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
15792
- import { join as join6 } from "node:path";
15793
- function coversProposalState(line) {
15794
- const rule = line.trim();
15795
- if (rule === "" || rule.startsWith("#") || rule.startsWith("!"))
15796
- return false;
15797
- const normalized = rule.replace(/^\//, "").replace(/^\*\*\//, "").replace(/\/(\*\*?)?$/, "");
15798
- return COVERING_PATHS.has(normalized);
15799
- }
15800
- function ensureDocsProposalGitignore(projectDir) {
15801
- if (!existsSync8(join6(projectDir, ".git")))
15802
- return { status: "not-a-repository" };
15803
- const path = join6(projectDir, ".gitignore");
15804
- try {
15805
- const text = existsSync8(path) ? readFileSync7(path, "utf8") : "";
15806
- if (text.split(/\r?\n/).some(coversProposalState))
15807
- return { status: "covered" };
15808
- const nestedPath = join6(projectDir, ".cortexkit", ".gitignore");
15809
- if (existsSync8(nestedPath)) {
15810
- const nested = readFileSync7(nestedPath, "utf8").split(/\r?\n/);
15811
- if (nested.some((line) => /^\/?magic-context(\/(\*\*?)?)?$/.test(line.trim()))) {
15812
- return { status: "covered" };
15813
- }
15814
- }
15815
- appendFileSync2(path, `${text && !text.endsWith(`
15816
- `) ? `
15817
- ` : ""}.cortexkit/magic-context/
15818
- `);
15819
- return { status: "added", path };
15820
- } catch (error) {
15821
- return {
15822
- status: "failed",
15823
- path,
15824
- error: error instanceof Error ? error.message : String(error)
15825
- };
15826
- }
15827
- }
15828
- var COVERING_PATHS;
15829
- var init_docs_proposal_gitignore = __esm(() => {
15830
- COVERING_PATHS = new Set([".cortexkit", ".cortexkit/magic-context"]);
15831
- });
15832
-
15833
15792
  // src/lib/find-on-path.ts
15834
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync9, statSync as statSync6 } from "node:fs";
15835
- import { delimiter, join as join7 } from "node:path";
15793
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync8, statSync as statSync6 } from "node:fs";
15794
+ import { delimiter, join as join6 } from "node:path";
15836
15795
  function findOnPath(binary) {
15837
15796
  const PATH = process.env.PATH;
15838
15797
  if (typeof PATH !== "string" || PATH.length === 0)
@@ -15844,7 +15803,7 @@ function findOnPath(binary) {
15844
15803
  if (!dir)
15845
15804
  continue;
15846
15805
  for (const candidate of candidates) {
15847
- const fullPath = join7(dir, candidate);
15806
+ const fullPath = join6(dir, candidate);
15848
15807
  if (isExecutableFile(fullPath, isWindows))
15849
15808
  return fullPath;
15850
15809
  }
@@ -15853,7 +15812,7 @@ function findOnPath(binary) {
15853
15812
  }
15854
15813
  function isExecutableFile(path, isWindows = process.platform === "win32") {
15855
15814
  try {
15856
- if (!existsSync9(path))
15815
+ if (!existsSync8(path))
15857
15816
  return false;
15858
15817
  const st = statSync6(path);
15859
15818
  if (!st.isFile())
@@ -15870,28 +15829,28 @@ function isExecutableFile(path, isWindows = process.platform === "win32") {
15870
15829
  var init_find_on_path = () => {};
15871
15830
 
15872
15831
  // src/lib/paths.ts
15873
- import { existsSync as existsSync10, readdirSync as readdirSync2, statSync as statSync7 } from "node:fs";
15832
+ import { existsSync as existsSync9, readdirSync as readdirSync2, statSync as statSync7 } from "node:fs";
15874
15833
  import { homedir as homedir7 } from "node:os";
15875
- import { delimiter as delimiter2, dirname as dirname8, join as join8, resolve as resolve3 } from "node:path";
15834
+ import { delimiter as delimiter2, dirname as dirname8, join as join7, resolve as resolve3 } from "node:path";
15876
15835
  function getOpenCodeConfigDir() {
15877
15836
  const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
15878
15837
  if (envDir)
15879
15838
  return envDir;
15880
15839
  if (process.platform === "win32") {
15881
- return join8(homedir7(), ".config", "opencode");
15840
+ return join7(homedir7(), ".config", "opencode");
15882
15841
  }
15883
- const xdgConfig = process.env.XDG_CONFIG_HOME || join8(homedir7(), ".config");
15884
- return join8(xdgConfig, "opencode");
15842
+ const xdgConfig = process.env.XDG_CONFIG_HOME || join7(homedir7(), ".config");
15843
+ return join7(xdgConfig, "opencode");
15885
15844
  }
15886
15845
  function findOmoConfig(configDir) {
15887
15846
  const locations = [
15888
- join8(configDir, "oh-my-openagent.jsonc"),
15889
- join8(configDir, "oh-my-openagent.json"),
15890
- join8(configDir, "oh-my-opencode.jsonc"),
15891
- join8(configDir, "oh-my-opencode.json")
15847
+ join7(configDir, "oh-my-openagent.jsonc"),
15848
+ join7(configDir, "oh-my-openagent.json"),
15849
+ join7(configDir, "oh-my-opencode.jsonc"),
15850
+ join7(configDir, "oh-my-opencode.json")
15892
15851
  ];
15893
15852
  for (const loc of locations) {
15894
- if (existsSync10(loc))
15853
+ if (existsSync9(loc))
15895
15854
  return loc;
15896
15855
  }
15897
15856
  return null;
@@ -15902,24 +15861,24 @@ function detectConfigPaths() {
15902
15861
  let opencodeConfigFormat;
15903
15862
  let tuiConfig;
15904
15863
  let tuiConfigFormat;
15905
- const jsoncPath = join8(configDir, "opencode.jsonc");
15906
- const jsonPath = join8(configDir, "opencode.json");
15907
- if (existsSync10(jsoncPath)) {
15864
+ const jsoncPath = join7(configDir, "opencode.jsonc");
15865
+ const jsonPath = join7(configDir, "opencode.json");
15866
+ if (existsSync9(jsoncPath)) {
15908
15867
  opencodeConfig = jsoncPath;
15909
15868
  opencodeConfigFormat = "jsonc";
15910
- } else if (existsSync10(jsonPath)) {
15869
+ } else if (existsSync9(jsonPath)) {
15911
15870
  opencodeConfig = jsonPath;
15912
15871
  opencodeConfigFormat = "json";
15913
15872
  } else {
15914
15873
  opencodeConfig = jsoncPath;
15915
15874
  opencodeConfigFormat = "none";
15916
15875
  }
15917
- const tuiJsoncPath = join8(configDir, "tui.jsonc");
15918
- const tuiJsonPath = join8(configDir, "tui.json");
15919
- if (existsSync10(tuiJsoncPath)) {
15876
+ const tuiJsoncPath = join7(configDir, "tui.jsonc");
15877
+ const tuiJsonPath = join7(configDir, "tui.json");
15878
+ if (existsSync9(tuiJsoncPath)) {
15920
15879
  tuiConfig = tuiJsoncPath;
15921
15880
  tuiConfigFormat = "jsonc";
15922
- } else if (existsSync10(tuiJsonPath)) {
15881
+ } else if (existsSync9(tuiJsonPath)) {
15923
15882
  tuiConfig = tuiJsonPath;
15924
15883
  tuiConfigFormat = "json";
15925
15884
  } else {
@@ -15944,31 +15903,31 @@ function getPiAgentDir() {
15944
15903
  const envDir = process.env.PI_CODING_AGENT_DIR?.trim();
15945
15904
  if (envDir)
15946
15905
  return envDir;
15947
- return join8(envFirstHomeDir(), ".pi", "agent");
15906
+ return join7(envFirstHomeDir(), ".pi", "agent");
15948
15907
  }
15949
15908
  function getPiAgentConfigDir() {
15950
15909
  return getPiAgentDir();
15951
15910
  }
15952
15911
  function getPiSessionsRoot() {
15953
- return join8(getPiAgentDir(), "sessions");
15912
+ return join7(getPiAgentDir(), "sessions");
15954
15913
  }
15955
15914
  function getPiCacheRoot() {
15956
- return join8(dirname8(getPiAgentDir()), "cache");
15915
+ return join7(dirname8(getPiAgentDir()), "cache");
15957
15916
  }
15958
15917
  function getPiUserConfigPath() {
15959
15918
  return resolveCortexKitUserConfigPath();
15960
15919
  }
15961
15920
  function getPiUserExtensionsPath() {
15962
- return join8(getPiAgentConfigDir(), "settings.json");
15921
+ return join7(getPiAgentConfigDir(), "settings.json");
15963
15922
  }
15964
15923
  function resolveOmpPaths() {
15965
15924
  const rawProfile = process.env.OMP_PROFILE ?? process.env.PI_PROFILE;
15966
15925
  const normalizedProfile = rawProfile?.trim();
15967
15926
  const profile = normalizedProfile && normalizedProfile !== "default" && /^[a-z0-9][a-z0-9._-]{0,63}$/.test(normalizedProfile) ? normalizedProfile : undefined;
15968
15927
  const configDirName = process.env.PI_CONFIG_DIR?.trim() || ".omp";
15969
- const baseConfigRoot = join8(envFirstHomeDir(), configDirName);
15970
- const configRoot = profile ? join8(baseConfigRoot, "profiles", profile) : baseConfigRoot;
15971
- const defaultAgentDir = join8(configRoot, "agent");
15928
+ const baseConfigRoot = join7(envFirstHomeDir(), configDirName);
15929
+ const configRoot = profile ? join7(baseConfigRoot, "profiles", profile) : baseConfigRoot;
15930
+ const defaultAgentDir = join7(configRoot, "agent");
15972
15931
  const override = profile ? undefined : process.env.PI_CODING_AGENT_DIR?.trim();
15973
15932
  const agentDir = override ? resolve3(override) : defaultAgentDir;
15974
15933
  const canUseXdg = (process.platform === "linux" || process.platform === "darwin") && agentDir === defaultAgentDir;
@@ -15976,9 +15935,9 @@ function resolveOmpPaths() {
15976
15935
  if (canUseXdg) {
15977
15936
  const xdgDataHome = process.env.XDG_DATA_HOME?.trim();
15978
15937
  if (xdgDataHome) {
15979
- const appRoot = join8(xdgDataHome, "omp");
15980
- const candidate = profile ? join8(appRoot, "profiles", profile) : appRoot;
15981
- if (existsSync10(candidate))
15938
+ const appRoot = join7(xdgDataHome, "omp");
15939
+ const candidate = profile ? join7(appRoot, "profiles", profile) : appRoot;
15940
+ if (existsSync9(candidate))
15982
15941
  dataRoot = candidate;
15983
15942
  }
15984
15943
  }
@@ -15988,8 +15947,8 @@ function resolveOmpPaths() {
15988
15947
  agentDir,
15989
15948
  dataRoot,
15990
15949
  dataAgentRoot,
15991
- pluginsDir: join8(dataRoot, "plugins"),
15992
- sessionsRoot: join8(dataAgentRoot, "sessions")
15950
+ pluginsDir: join7(dataRoot, "plugins"),
15951
+ sessionsRoot: join7(dataAgentRoot, "sessions")
15993
15952
  };
15994
15953
  }
15995
15954
  function getOmpAgentDir() {
@@ -15999,7 +15958,7 @@ function getOmpSessionsRoot() {
15999
15958
  return resolveOmpPaths().sessionsRoot;
16000
15959
  }
16001
15960
  function getOmpConfigPath() {
16002
- return join8(resolveOmpPaths().agentDir, "config.yml");
15961
+ return join7(resolveOmpPaths().agentDir, "config.yml");
16003
15962
  }
16004
15963
  function getOmpPackageDir() {
16005
15964
  const value = process.env.PI_PACKAGE_DIR?.trim();
@@ -16015,7 +15974,7 @@ function getOmpPackageDir() {
16015
15974
  function getOmpNonGlobalConfigSources(cwd = process.cwd()) {
16016
15975
  const sources = getOmpConfigOverlayPaths(cwd);
16017
15976
  const projectConfig = resolve3(cwd, ".omp", "config.yml");
16018
- if (existsSync10(projectConfig))
15977
+ if (existsSync9(projectConfig))
16019
15978
  sources.push(projectConfig);
16020
15979
  return [...new Set(sources)];
16021
15980
  }
@@ -16023,7 +15982,7 @@ function getOmpConfigOverlayPaths(cwd = process.cwd()) {
16023
15982
  return process.env.PI_CONFIG_FILES?.split(delimiter2).map((entry) => entry.trim()).filter(Boolean).map((entry) => {
16024
15983
  if (entry === "~")
16025
15984
  return envFirstHomeDir();
16026
- const expanded = entry.startsWith("~/") || entry.startsWith("~\\") ? join8(envFirstHomeDir(), entry.slice(2)) : entry;
15985
+ const expanded = entry.startsWith("~/") || entry.startsWith("~\\") ? join7(envFirstHomeDir(), entry.slice(2)) : entry;
16027
15986
  return resolve3(cwd, expanded);
16028
15987
  }) ?? [];
16029
15988
  }
@@ -16031,7 +15990,7 @@ function getOmpPluginsDir() {
16031
15990
  return resolveOmpPaths().pluginsDir;
16032
15991
  }
16033
15992
  function getOmpPluginsLockPath() {
16034
- return join8(resolveOmpPaths().pluginsDir, "omp-plugins.lock.json");
15993
+ return join7(resolveOmpPaths().pluginsDir, "omp-plugins.lock.json");
16035
15994
  }
16036
15995
  function getOmpUserConfigPath() {
16037
15996
  return resolveCortexKitUserConfigPath();
@@ -16043,12 +16002,12 @@ function getMagicContextHistorianDir2(harness) {
16043
16002
  return getMagicContextHistorianDir(harness);
16044
16003
  }
16045
16004
  function getOpenCodePluginCacheDir() {
16046
- const xdg = process.env.XDG_CACHE_HOME || join8(homedir7(), ".cache");
16047
- return join8(xdg, "opencode", "packages");
16005
+ const xdg = process.env.XDG_CACHE_HOME || join7(homedir7(), ".cache");
16006
+ return join7(xdg, "opencode", "packages");
16048
16007
  }
16049
16008
  function getOpenCodeV2NpmCacheDir() {
16050
- const xdg = process.env.XDG_CACHE_HOME || join8(homedir7(), ".cache");
16051
- return join8(xdg, "opencode", "npm");
16009
+ const xdg = process.env.XDG_CACHE_HOME || join7(homedir7(), ".cache");
16010
+ return join7(xdg, "opencode", "npm");
16052
16011
  }
16053
16012
  function isDir(path) {
16054
16013
  try {
@@ -16069,7 +16028,7 @@ function dirSizeBytes(path) {
16069
16028
  try {
16070
16029
  const entries = readdirSync2(cur, { withFileTypes: true });
16071
16030
  for (const entry of entries) {
16072
- const child = join8(cur, entry.name);
16031
+ const child = join7(cur, entry.name);
16073
16032
  if (entry.isDirectory()) {
16074
16033
  stack.push(child);
16075
16034
  } else if (entry.isFile()) {
@@ -16090,7 +16049,7 @@ var init_paths = __esm(() => {
16090
16049
  // src/lib/pi-helpers.ts
16091
16050
  import { execFileSync, spawnSync } from "node:child_process";
16092
16051
  import { homedir as homedir8 } from "node:os";
16093
- import { extname, join as join9 } from "node:path";
16052
+ import { extname, join as join8 } from "node:path";
16094
16053
  function getPiCommandInvocation(piPath, args) {
16095
16054
  const extension = extname(piPath).toLowerCase();
16096
16055
  if (extension !== ".cmd" && extension !== ".bat") {
@@ -16104,7 +16063,7 @@ function detectPiBinary() {
16104
16063
  if (fromPath)
16105
16064
  return { path: fromPath, source: "path" };
16106
16065
  const home = process.env.HOME?.trim() || homedir8();
16107
- const homeCandidate = process.platform === "win32" ? join9(home, ".pi", "bin", "pi.cmd") : join9(home, ".pi", "bin", "pi");
16066
+ const homeCandidate = process.platform === "win32" ? join8(home, ".pi", "bin", "pi.cmd") : join8(home, ".pi", "bin", "pi");
16108
16067
  if (isExecutableFile(homeCandidate))
16109
16068
  return { path: homeCandidate, source: "home" };
16110
16069
  return null;
@@ -16193,9 +16152,9 @@ var init_pi_helpers = __esm(() => {
16193
16152
 
16194
16153
  // src/lib/omp-helpers.ts
16195
16154
  import { spawnSync as spawnSync2 } from "node:child_process";
16196
- import { existsSync as existsSync11, readFileSync as readFileSync8 } from "node:fs";
16155
+ import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
16197
16156
  import { homedir as homedir9 } from "node:os";
16198
- import { extname as extname2, join as join10 } from "node:path";
16157
+ import { extname as extname2, join as join9 } from "node:path";
16199
16158
  function detectOmpPackageCli() {
16200
16159
  const packageDir = getOmpPackageDir();
16201
16160
  if (!packageDir)
@@ -16203,11 +16162,11 @@ function detectOmpPackageCli() {
16203
16162
  if (!findOnPath("bun"))
16204
16163
  return null;
16205
16164
  try {
16206
- const manifest = JSON.parse(readFileSync8(join10(packageDir, "package.json"), "utf-8"));
16165
+ const manifest = JSON.parse(readFileSync7(join9(packageDir, "package.json"), "utf-8"));
16207
16166
  if (manifest.name !== "@oh-my-pi/pi-coding-agent")
16208
16167
  return null;
16209
- const cli = join10(packageDir, "dist", "cli.js");
16210
- return existsSync11(cli) ? cli : null;
16168
+ const cli = join9(packageDir, "dist", "cli.js");
16169
+ return existsSync10(cli) ? cli : null;
16211
16170
  } catch {
16212
16171
  return null;
16213
16172
  }
@@ -16222,13 +16181,13 @@ function getOmpCommandInvocation(ompPath, args) {
16222
16181
  }
16223
16182
  function getOmpFallbackCandidates(platform, home, appData) {
16224
16183
  if (platform !== "win32") {
16225
- return [join10(home, ".bun", "bin", "omp"), join10(home, ".local", "bin", "omp")];
16184
+ return [join9(home, ".bun", "bin", "omp"), join9(home, ".local", "bin", "omp")];
16226
16185
  }
16227
16186
  const npmRoot = appData?.trim();
16228
16187
  return [
16229
- ...npmRoot ? [join10(npmRoot, "npm", "omp.cmd"), join10(npmRoot, "npm", "omp.exe")] : [],
16230
- join10(home, ".bun", "bin", "omp.exe"),
16231
- join10(home, ".bun", "bin", "omp.cmd")
16188
+ ...npmRoot ? [join9(npmRoot, "npm", "omp.cmd"), join9(npmRoot, "npm", "omp.exe")] : [],
16189
+ join9(home, ".bun", "bin", "omp.exe"),
16190
+ join9(home, ".bun", "bin", "omp.cmd")
16232
16191
  ];
16233
16192
  }
16234
16193
  function detectOmpBinary() {
@@ -16351,8 +16310,8 @@ var init_omp_helpers = __esm(() => {
16351
16310
  });
16352
16311
 
16353
16312
  // src/adapters/omp.ts
16354
- import { existsSync as existsSync12, readFileSync as readFileSync9 } from "node:fs";
16355
- import { join as join11 } from "node:path";
16313
+ import { existsSync as existsSync11, readFileSync as readFileSync8 } from "node:fs";
16314
+ import { join as join10 } from "node:path";
16356
16315
 
16357
16316
  class OmpAdapter {
16358
16317
  kind = "omp";
@@ -16452,8 +16411,8 @@ class OmpAdapter {
16452
16411
  return "Install OMP: https://omp.sh (npm: @oh-my-pi/pi-coding-agent)";
16453
16412
  }
16454
16413
  getPluginCacheInfo() {
16455
- const path = join11(getOmpPluginsDir(), "cache");
16456
- return [{ path, exists: existsSync12(path), sizeBytes: dirSizeBytes(path) }];
16414
+ const path = join10(getOmpPluginsDir(), "cache");
16415
+ return [{ path, exists: existsSync11(path), sizeBytes: dirSizeBytes(path) }];
16457
16416
  }
16458
16417
  getLogPath() {
16459
16418
  return getMagicContextLogPath2("omp");
@@ -16466,7 +16425,7 @@ class OmpAdapter {
16466
16425
  }
16467
16426
  readRuntimeEnabled(configPath) {
16468
16427
  try {
16469
- const lock = JSON.parse(readFileSync9(configPath, "utf-8"));
16428
+ const lock = JSON.parse(readFileSync8(configPath, "utf-8"));
16470
16429
  const enabled = lock.plugins?.[OMP_PLUGIN_PACKAGE]?.enabled;
16471
16430
  return typeof enabled === "boolean" ? enabled : undefined;
16472
16431
  } catch {
@@ -16494,9 +16453,9 @@ var init_omp = __esm(() => {
16494
16453
  });
16495
16454
 
16496
16455
  // ../plugin/src/shared/opencode-db-path.ts
16497
- import { existsSync as existsSync13, readdirSync as readdirSync3, statSync as statSync8 } from "node:fs";
16456
+ import { existsSync as existsSync12, readdirSync as readdirSync3, statSync as statSync8 } from "node:fs";
16498
16457
  import { homedir as homedir10 } from "node:os";
16499
- import { isAbsolute as isAbsolute4, join as join12, resolve as resolve4 } from "node:path";
16458
+ import { isAbsolute as isAbsolute4, join as join11, resolve as resolve4 } from "node:path";
16500
16459
  function openCodeHostGenerationFromVersion(version) {
16501
16460
  const text = version ?? "";
16502
16461
  if (/(?:^|\s|v)0\.0\.0-(?:beta|dev)-/.test(text))
@@ -16505,7 +16464,7 @@ function openCodeHostGenerationFromVersion(version) {
16505
16464
  return Number.isFinite(major) && major >= 2 ? "v2" : "v1";
16506
16465
  }
16507
16466
  function openCodeDataDir(env = process.env, dataHome) {
16508
- return join12(dataHome ?? env.XDG_DATA_HOME ?? join12(homedir10(), ".local", "share"), "opencode");
16467
+ return join11(dataHome ?? env.XDG_DATA_HOME ?? join11(homedir10(), ".local", "share"), "opencode");
16509
16468
  }
16510
16469
  function environmentKey(dataDir, hostGeneration, channel, env) {
16511
16470
  return [
@@ -16517,7 +16476,7 @@ function environmentKey(dataDir, hostGeneration, channel, env) {
16517
16476
  ].join("\x00");
16518
16477
  }
16519
16478
  function channelPath(dataDir, channel) {
16520
- return ["latest", "beta", "prod"].includes(channel) ? join12(dataDir, "opencode.db") : join12(dataDir, `opencode-${channel}.db`);
16479
+ return ["latest", "beta", "prod"].includes(channel) ? join11(dataDir, "opencode.db") : join11(dataDir, `opencode-${channel}.db`);
16521
16480
  }
16522
16481
  function discoveredCandidateNames(dataDir) {
16523
16482
  const names = ["opencode.db", "opencode-local.db", "opencode-dev.db"];
@@ -16529,7 +16488,7 @@ function discoveredCandidateNames(dataDir) {
16529
16488
  }
16530
16489
  function discoverOpenCodeDb(dataDir) {
16531
16490
  const candidates = discoveredCandidateNames(dataDir).map((name, order) => {
16532
- const path = join12(dataDir, name);
16491
+ const path = join11(dataDir, name);
16533
16492
  try {
16534
16493
  const metadata = statSync8(path);
16535
16494
  return metadata.isFile() ? { path, order, mtimeMs: metadata.mtimeMs } : null;
@@ -16539,7 +16498,7 @@ function discoverOpenCodeDb(dataDir) {
16539
16498
  });
16540
16499
  const existing = candidates.filter((candidate) => candidate !== null).sort((left, right) => right.mtimeMs - left.mtimeMs || left.order - right.order)[0];
16541
16500
  if (!existing) {
16542
- return { path: join12(dataDir, "opencode.db"), source: "default", channel: null };
16501
+ return { path: join11(dataDir, "opencode.db"), source: "default", channel: null };
16543
16502
  }
16544
16503
  const name = existing.path.slice(dataDir.length + 1);
16545
16504
  const channel = name === "opencode.db" ? null : name.slice("opencode-".length, -".db".length) || null;
@@ -16552,14 +16511,14 @@ function resolveV1Fresh(dataDir, env = process.env) {
16552
16511
  return { path: explicit, source: "OPENCODE_DB", channel: null };
16553
16512
  }
16554
16513
  return {
16555
- path: isAbsolute4(explicit) ? explicit : join12(dataDir, explicit),
16514
+ path: isAbsolute4(explicit) ? explicit : join11(dataDir, explicit),
16556
16515
  source: "OPENCODE_DB",
16557
16516
  channel: null
16558
16517
  };
16559
16518
  }
16560
16519
  const disableChannelDb = env.OPENCODE_DISABLE_CHANNEL_DB;
16561
16520
  if (disableChannelDb === "1" || disableChannelDb === "true") {
16562
- return { path: join12(dataDir, "opencode.db"), source: "default", channel: null };
16521
+ return { path: join11(dataDir, "opencode.db"), source: "default", channel: null };
16563
16522
  }
16564
16523
  const channel = env.OPENCODE_CHANNEL;
16565
16524
  if (channel !== undefined && channel.length > 0) {
@@ -16593,7 +16552,7 @@ function resolveOpenCodeDbPath(hostGeneration = "v1", options = {}) {
16593
16552
  const dataDir = openCodeDataDir(env, options.dataHome);
16594
16553
  const channel = options.channel ?? env.OPENCODE_CHANNEL;
16595
16554
  const key = environmentKey(dataDir, hostGeneration, channel, env);
16596
- if (cachedResolution?.key === key && (!cachedResolution.existed || existsSync13(cachedResolution.resolution.path))) {
16555
+ if (cachedResolution?.key === key && (!cachedResolution.existed || existsSync12(cachedResolution.resolution.path))) {
16597
16556
  if (cachedResolution.existed)
16598
16557
  return cachedResolution.resolution;
16599
16558
  }
@@ -16601,7 +16560,7 @@ function resolveOpenCodeDbPath(hostGeneration = "v1", options = {}) {
16601
16560
  cachedResolution = {
16602
16561
  key,
16603
16562
  resolution,
16604
- existed: resolution.path !== ":memory:" && existsSync13(resolution.path)
16563
+ existed: resolution.path !== ":memory:" && existsSync12(resolution.path)
16605
16564
  };
16606
16565
  return resolution;
16607
16566
  }
@@ -16641,7 +16600,7 @@ function assertOpenCodeStoreGeneration(db, expected, path, schema = "main") {
16641
16600
  throw new Error(`OpenCode store generation mismatch at ${path}: expected ${expected}, found ${actual}; refusing generation-specific database access`);
16642
16601
  }
16643
16602
  function openCodeDbPathExists(resolution = resolveOpenCodeDbPath()) {
16644
- return resolution.path !== ":memory:" && existsSync13(resolution.path);
16603
+ return resolution.path !== ":memory:" && existsSync12(resolution.path);
16645
16604
  }
16646
16605
  function getOpenCodeDbProbeDescriptions(resolution = resolveOpenCodeDbPath()) {
16647
16606
  if (resolution.source === "OPENCODE_DB")
@@ -16651,10 +16610,10 @@ function getOpenCodeDbProbeDescriptions(resolution = resolveOpenCodeDbPath()) {
16651
16610
  }
16652
16611
  const dataDir = openCodeDataDir();
16653
16612
  return [
16654
- join12(dataDir, "opencode.db"),
16655
- join12(dataDir, "opencode-local.db"),
16656
- join12(dataDir, "opencode-dev.db"),
16657
- join12(dataDir, "opencode-<channel>.db")
16613
+ join11(dataDir, "opencode.db"),
16614
+ join11(dataDir, "opencode-local.db"),
16615
+ join11(dataDir, "opencode-dev.db"),
16616
+ join11(dataDir, "opencode-<channel>.db")
16658
16617
  ];
16659
16618
  }
16660
16619
  function lookedForText(resolution) {
@@ -24560,7 +24519,7 @@ var init_project_directory_key = () => {};
24560
24519
 
24561
24520
  // ../plugin/src/shared/rpc-utils.ts
24562
24521
  import { execFile as execFile2, execFileSync as execFileSync2 } from "node:child_process";
24563
- import { readFileSync as readFileSync10 } from "node:fs";
24522
+ import { readFileSync as readFileSync9 } from "node:fs";
24564
24523
  function isOwnRpcServerRecord(record) {
24565
24524
  return record.pid === process.pid && record.instance_id !== undefined && ownRpcServerInstanceIds.has(record.instance_id);
24566
24525
  }
@@ -25155,7 +25114,7 @@ var init_rpc_utils = __esm(() => {
25155
25114
  "cljs/dist",
25156
25115
  "dist/bundle/cli"
25157
25116
  ];
25158
- rpcIdentityReadFileSync = readFileSync10;
25117
+ rpcIdentityReadFileSync = readFileSync9;
25159
25118
  rpcIdentityExecFileSync = execFileSync2;
25160
25119
  rpcIdentityProcessKill = process.kill;
25161
25120
  rpcProcessListExecFileSync = execFileSync2;
@@ -25196,23 +25155,23 @@ var init_opencode_plugin_registration = __esm(() => {
25196
25155
  });
25197
25156
 
25198
25157
  // src/lib/opencode-plugin-cache.ts
25199
- import { readdirSync as readdirSync4, readFileSync as readFileSync11 } from "node:fs";
25200
- import { join as join13 } from "node:path";
25158
+ import { readdirSync as readdirSync4, readFileSync as readFileSync10 } from "node:fs";
25159
+ import { join as join12 } from "node:path";
25201
25160
  function getOpenCodePluginCacheRoots() {
25202
25161
  const cacheDir = getOpenCodePluginCacheDir();
25203
25162
  return [
25204
- join13(cacheDir, OPENCODE_PLUGIN_ENTRY_WITH_VERSION),
25205
- join13(cacheDir, OPENCODE_PLUGIN_NAME)
25163
+ join12(cacheDir, OPENCODE_PLUGIN_ENTRY_WITH_VERSION),
25164
+ join12(cacheDir, OPENCODE_PLUGIN_NAME)
25206
25165
  ];
25207
25166
  }
25208
25167
  function getOpenCodePluginPackageJsonPath(pluginCacheRoot) {
25209
- return join13(pluginCacheRoot, "node_modules", ...OPENCODE_PLUGIN_NAME.split("/"), "package.json");
25168
+ return join12(pluginCacheRoot, "node_modules", ...OPENCODE_PLUGIN_NAME.split("/"), "package.json");
25210
25169
  }
25211
25170
  function getOpenCodePluginPackageJsonPaths() {
25212
25171
  return getOpenCodePluginCacheRoots().map(getOpenCodePluginPackageJsonPath);
25213
25172
  }
25214
25173
  function getOpenCodeV2PluginCacheSlot(npmCacheDir = getOpenCodeV2NpmCacheDir(), spec = "latest") {
25215
- return join13(npmCacheDir, ...`${OPENCODE_PLUGIN_NAME}@${spec}`.split("/"));
25174
+ return join12(npmCacheDir, ...`${OPENCODE_PLUGIN_NAME}@${spec}`.split("/"));
25216
25175
  }
25217
25176
  function openCodeV2PluginSpecOf(specifier) {
25218
25177
  if (specifier === OPENCODE_PLUGIN_NAME)
@@ -25265,7 +25224,7 @@ function pluginEntrySpecifier(entry) {
25265
25224
  }
25266
25225
  function listOpenCodeV2PluginCacheSlots(npmCacheDir = getOpenCodeV2NpmCacheDir()) {
25267
25226
  const [scope = "", name = ""] = OPENCODE_PLUGIN_NAME.split("/");
25268
- const scopeDir = join13(npmCacheDir, scope);
25227
+ const scopeDir = join12(npmCacheDir, scope);
25269
25228
  let names;
25270
25229
  try {
25271
25230
  names = readdirSync4(scopeDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.startsWith(`${name}@`)).map((entry) => entry.name);
@@ -25273,7 +25232,7 @@ function listOpenCodeV2PluginCacheSlots(npmCacheDir = getOpenCodeV2NpmCacheDir()
25273
25232
  return [];
25274
25233
  }
25275
25234
  return names.map((dirName) => {
25276
- const slot = join13(scopeDir, dirName);
25235
+ const slot = join12(scopeDir, dirName);
25277
25236
  return {
25278
25237
  spec: dirName.slice(name.length + 1),
25279
25238
  slot,
@@ -25289,7 +25248,7 @@ function getOpenCodeV2ActiveGeneration(slot) {
25289
25248
  try {
25290
25249
  const generations = readdirSync4(slot, { withFileTypes: true }).filter((entry) => entry.isDirectory() && /^\d+$/.test(entry.name)).map((entry) => entry.name).sort((a, b) => Number(a) - Number(b));
25291
25250
  const newest = generations.at(-1);
25292
- return newest === undefined ? undefined : join13(slot, newest);
25251
+ return newest === undefined ? undefined : join12(slot, newest);
25293
25252
  } catch {
25294
25253
  return;
25295
25254
  }
@@ -25322,7 +25281,7 @@ function readOpenCodeV2CachedPluginVersion(slot) {
25322
25281
  if (!generation)
25323
25282
  return;
25324
25283
  try {
25325
- const pkg = JSON.parse(readFileSync11(getOpenCodePluginPackageJsonPath(generation), "utf-8"));
25284
+ const pkg = JSON.parse(readFileSync10(getOpenCodePluginPackageJsonPath(generation), "utf-8"));
25326
25285
  return typeof pkg.version === "string" ? pkg.version : undefined;
25327
25286
  } catch {
25328
25287
  return;
@@ -25336,7 +25295,7 @@ var init_opencode_plugin_cache = __esm(() => {
25336
25295
  });
25337
25296
 
25338
25297
  // src/commands/doctor-windows-holders.ts
25339
- import { existsSync as existsSync14 } from "node:fs";
25298
+ import { existsSync as existsSync13 } from "node:fs";
25340
25299
  function fileName(path) {
25341
25300
  return path.toLowerCase().replaceAll("\\", "/").split("/").at(-1) ?? "";
25342
25301
  }
@@ -25429,7 +25388,7 @@ function assertWindowsStoresClosed(paths, processes) {
25429
25388
  if (blockers.length)
25430
25389
  throw new Error(`OpenCode, Pi or ck-mc process is running (${blockers.map(({ pid, imageName, commandLine }) => `${imageName ?? commandLine} PID ${pid}`).join(", ")})`);
25431
25390
  for (const path of [...new Set(paths)]) {
25432
- if (!existsSync14(path))
25391
+ if (!existsSync13(path))
25433
25392
  continue;
25434
25393
  let db;
25435
25394
  let locked = false;
@@ -25536,7 +25495,7 @@ var init_doctor_windows_holders = __esm(async () => {
25536
25495
 
25537
25496
  // src/commands/doctor-opencode2-cache.ts
25538
25497
  import { spawnSync as spawnSync3 } from "node:child_process";
25539
- import { existsSync as existsSync15, rmSync as rmSync4 } from "node:fs";
25498
+ import { existsSync as existsSync14, rmSync as rmSync4 } from "node:fs";
25540
25499
  function runLsof(args, spawn) {
25541
25500
  const result = spawn("lsof", args, { encoding: "utf-8", timeout: 15000, windowsHide: true });
25542
25501
  if (result.error)
@@ -25551,7 +25510,7 @@ function probeHostProcessesUsing(targets, spawn = spawnSync3) {
25551
25510
  if (process.platform === "win32") {
25552
25511
  try {
25553
25512
  assertWindowsStoresClosed(targets.files.filter((path) => !/-(?:wal|shm)$/.test(path)), inspectWindowsProcessesSync());
25554
- if (targets.directories.some(existsSync15))
25513
+ if (targets.directories.some(existsSync14))
25555
25514
  return {
25556
25515
  status: "unknown",
25557
25516
  reason: "Windows cannot rule out open files in plugin cache directories"
@@ -25564,8 +25523,8 @@ function probeHostProcessesUsing(targets, spawn = spawnSync3) {
25564
25523
  };
25565
25524
  }
25566
25525
  }
25567
- const files = targets.files.filter((file) => existsSync15(file));
25568
- const directories = targets.directories.filter((directory) => existsSync15(directory));
25526
+ const files = targets.files.filter((file) => existsSync14(file));
25527
+ const directories = targets.directories.filter((directory) => existsSync14(directory));
25569
25528
  const queries = [];
25570
25529
  if (files.length > 0)
25571
25530
  queries.push(["-w", "-t", "--", ...files]);
@@ -25660,9 +25619,9 @@ function checkOpenCodeV2PluginCache(options, deps = {}) {
25660
25619
  const slot = deps.slot ?? getOpenCodeV2PluginCacheSlot(undefined, distTag ?? "latest");
25661
25620
  const tagged = distTag ? { distTag } : {};
25662
25621
  if (options.referencedSpecs !== undefined && !options.referencedSpecs.has(distTag ?? "latest")) {
25663
- return existsSync15(slot) ? { action: "unused", slot, cached: readOpenCodeV2CachedPluginVersion(slot), ...tagged } : { action: "not_found", slot, unused: true, ...tagged };
25622
+ return existsSync14(slot) ? { action: "unused", slot, cached: readOpenCodeV2CachedPluginVersion(slot), ...tagged } : { action: "not_found", slot, unused: true, ...tagged };
25664
25623
  }
25665
- if (!existsSync15(slot))
25624
+ if (!existsSync14(slot))
25666
25625
  return { action: "not_found", slot, ...tagged };
25667
25626
  const cached = readOpenCodeV2CachedPluginVersion(slot);
25668
25627
  const latest = options.latestVersion ?? undefined;
@@ -25801,7 +25760,7 @@ var init_atomic_write = __esm(() => {
25801
25760
  });
25802
25761
 
25803
25762
  // src/lib/jsonc-config.ts
25804
- import { existsSync as existsSync16, readFileSync as readFileSync12 } from "node:fs";
25763
+ import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
25805
25764
  function parseErrorLocation(content, error) {
25806
25765
  const lines = content.split(`
25807
25766
  `);
@@ -25817,9 +25776,9 @@ function parseErrorLocation(content, error) {
25817
25776
  return { line: messageLine ? Number.parseInt(messageLine, 10) : 1, column: 1 };
25818
25777
  }
25819
25778
  function readJsoncConfig(path) {
25820
- if (!existsSync16(path))
25779
+ if (!existsSync15(path))
25821
25780
  return { kind: "missing" };
25822
- const content = readFileSync12(path, "utf-8");
25781
+ const content = readFileSync11(path, "utf-8");
25823
25782
  try {
25824
25783
  const rejectedKeyPaths = [];
25825
25784
  const parsed = sanitizeParsedJson(import_comment_json.parse(content), {
@@ -25845,7 +25804,7 @@ function readJsoncConfigForUpdate(path) {
25845
25804
  return result.value;
25846
25805
  }
25847
25806
  function readJsoncTextForEdit(configPath) {
25848
- const raw = readFileSync12(configPath, "utf-8");
25807
+ const raw = readFileSync11(configPath, "utf-8");
25849
25808
  return raw.startsWith(BYTE_ORDER_MARK) ? { bom: BYTE_ORDER_MARK, text: raw.slice(BYTE_ORDER_MARK.length) } : { bom: "", text: raw };
25850
25809
  }
25851
25810
  function assertJsoncConfigsParseable(paths) {
@@ -25934,13 +25893,13 @@ var init_jsonc_config = __esm(() => {
25934
25893
  });
25935
25894
 
25936
25895
  // src/lib/opencode-detect.ts
25937
- import { existsSync as existsSync17, realpathSync as realpathSync3 } from "node:fs";
25896
+ import { existsSync as existsSync16, realpathSync as realpathSync3 } from "node:fs";
25938
25897
  import { homedir as homedir11 } from "node:os";
25939
- import { join as join14 } from "node:path";
25898
+ import { join as join13 } from "node:path";
25940
25899
  function defaultDeps(overrides = {}) {
25941
25900
  const env = overrides.env ?? process.env;
25942
25901
  return {
25943
- exists: overrides.exists ?? existsSync17,
25902
+ exists: overrides.exists ?? existsSync16,
25944
25903
  isExecutable: overrides.isExecutable ?? isExecutableFile,
25945
25904
  home: overrides.home ?? (env.HOME?.trim() || homedir11()),
25946
25905
  platform: overrides.platform ?? process.platform,
@@ -25950,7 +25909,7 @@ function defaultDeps(overrides = {}) {
25950
25909
  };
25951
25910
  }
25952
25911
  function stockCliBinary(d) {
25953
- return d.platform === "win32" ? join14(d.home, ".opencode", "bin", "opencode.exe") : join14(d.home, ".opencode", "bin", "opencode");
25912
+ return d.platform === "win32" ? join13(d.home, ".opencode", "bin", "opencode.exe") : join13(d.home, ".opencode", "bin", "opencode");
25954
25913
  }
25955
25914
  function extraCliCandidates(d) {
25956
25915
  if (d.platform === "win32") {
@@ -25959,25 +25918,25 @@ function extraCliCandidates(d) {
25959
25918
  const userprofile = d.env.USERPROFILE ?? d.home;
25960
25919
  const out = [];
25961
25920
  if (appdata) {
25962
- out.push(join14(appdata, "npm", "opencode.cmd"));
25963
- out.push(join14(appdata, "npm", "opencode.exe"));
25921
+ out.push(join13(appdata, "npm", "opencode.cmd"));
25922
+ out.push(join13(appdata, "npm", "opencode.exe"));
25964
25923
  }
25965
25924
  if (localappdata) {
25966
- out.push(join14(localappdata, "Microsoft", "WinGet", "Links", "opencode.exe"));
25967
- out.push(join14(localappdata, "opencode", "bin", "opencode.exe"));
25925
+ out.push(join13(localappdata, "Microsoft", "WinGet", "Links", "opencode.exe"));
25926
+ out.push(join13(localappdata, "opencode", "bin", "opencode.exe"));
25968
25927
  }
25969
25928
  if (userprofile) {
25970
- out.push(join14(userprofile, "scoop", "shims", "opencode.exe"));
25929
+ out.push(join13(userprofile, "scoop", "shims", "opencode.exe"));
25971
25930
  }
25972
25931
  return out;
25973
25932
  }
25974
25933
  return [
25975
25934
  "/usr/local/bin/opencode",
25976
25935
  "/opt/homebrew/bin/opencode",
25977
- join14(d.home, ".local", "bin", "opencode"),
25978
- join14(d.home, ".local", "share", "mise", "shims", "opencode"),
25979
- join14(d.home, ".asdf", "shims", "opencode"),
25980
- join14(d.home, ".volta", "bin", "opencode")
25936
+ join13(d.home, ".local", "bin", "opencode"),
25937
+ join13(d.home, ".local", "share", "mise", "shims", "opencode"),
25938
+ join13(d.home, ".asdf", "shims", "opencode"),
25939
+ join13(d.home, ".volta", "bin", "opencode")
25981
25940
  ];
25982
25941
  }
25983
25942
  function openChamberCliCandidates(d) {
@@ -25985,8 +25944,8 @@ function openChamberCliCandidates(d) {
25985
25944
  return [];
25986
25945
  const bundled = ["Contents", "Resources", "opencode-cli", "opencode"];
25987
25946
  return [
25988
- join14("/Applications", "OpenChamber.app", ...bundled),
25989
- join14(d.home, "Applications", "OpenChamber.app", ...bundled)
25947
+ join13("/Applications", "OpenChamber.app", ...bundled),
25948
+ join13(d.home, "Applications", "OpenChamber.app", ...bundled)
25990
25949
  ];
25991
25950
  }
25992
25951
  function canonicalPath(d, path) {
@@ -26007,29 +25966,29 @@ function xdgConfigHome(d) {
26007
25966
  const xdg = d.env.XDG_CONFIG_HOME;
26008
25967
  if (xdg && xdg.length > 0)
26009
25968
  return xdg;
26010
- return join14(d.home, ".config");
25969
+ return join13(d.home, ".config");
26011
25970
  }
26012
25971
  function desktopUserDataDir(d, appId) {
26013
25972
  switch (d.platform) {
26014
25973
  case "darwin":
26015
- return join14(d.home, "Library", "Application Support", appId);
25974
+ return join13(d.home, "Library", "Application Support", appId);
26016
25975
  case "win32":
26017
- return join14(d.env.APPDATA ?? join14(d.home, "AppData", "Roaming"), appId);
25976
+ return join13(d.env.APPDATA ?? join13(d.home, "AppData", "Roaming"), appId);
26018
25977
  default:
26019
- return join14(xdgConfigHome(d), appId);
25978
+ return join13(xdgConfigHome(d), appId);
26020
25979
  }
26021
25980
  }
26022
25981
  function desktopAppPaths(d) {
26023
25982
  switch (d.platform) {
26024
25983
  case "darwin":
26025
- return ["/Applications/OpenCode.app", join14(d.home, "Applications", "OpenCode.app")];
25984
+ return ["/Applications/OpenCode.app", join13(d.home, "Applications", "OpenCode.app")];
26026
25985
  case "win32": {
26027
- const localappdata = d.env.LOCALAPPDATA ?? join14(d.home, "AppData", "Local");
26028
- return [join14(localappdata, "Programs", "OpenCode", "OpenCode.exe")];
25986
+ const localappdata = d.env.LOCALAPPDATA ?? join13(d.home, "AppData", "Local");
25987
+ return [join13(localappdata, "Programs", "OpenCode", "OpenCode.exe")];
26029
25988
  }
26030
25989
  default: {
26031
- const dataHome = d.env.XDG_DATA_HOME && d.env.XDG_DATA_HOME.length > 0 ? d.env.XDG_DATA_HOME : join14(d.home, ".local", "share");
26032
- return OPENCODE_DESKTOP_APP_IDS.map((appId) => join14(dataHome, "applications", `${appId}.desktop`));
25990
+ const dataHome = d.env.XDG_DATA_HOME && d.env.XDG_DATA_HOME.length > 0 ? d.env.XDG_DATA_HOME : join13(d.home, ".local", "share");
25991
+ return OPENCODE_DESKTOP_APP_IDS.map((appId) => join13(dataHome, "applications", `${appId}.desktop`));
26033
25992
  }
26034
25993
  }
26035
25994
  }
@@ -26056,7 +26015,7 @@ function detectOpenCodeInstallations(deps) {
26056
26015
  }
26057
26016
  }
26058
26017
  for (const appId of OPENCODE_DESKTOP_APP_IDS) {
26059
- const marker = join14(desktopUserDataDir(d, appId), OPENCODE_DESKTOP_SETTINGS_FILE);
26018
+ const marker = join13(desktopUserDataDir(d, appId), OPENCODE_DESKTOP_SETTINGS_FILE);
26060
26019
  if (d.exists(marker)) {
26061
26020
  addCandidate(installations, seenRealpaths, d, marker, "desktop", "desktop");
26062
26021
  }
@@ -26154,7 +26113,7 @@ var OPENCODE_BINARY_ENV = "MAGIC_CONTEXT_OPENCODE_BINARY", OPENCODE_VERSION_PROB
26154
26113
  var init_opencode_helpers = () => {};
26155
26114
 
26156
26115
  // src/adapters/opencode.ts
26157
- import { existsSync as existsSync18, readFileSync as readFileSync13, statSync as statSync10 } from "node:fs";
26116
+ import { existsSync as existsSync17, readFileSync as readFileSync12, statSync as statSync10 } from "node:fs";
26158
26117
  import { dirname as dirname10, isAbsolute as isAbsolute5, parse as parsePath, resolve as resolve6 } from "node:path";
26159
26118
  import { fileURLToPath as fileURLToPath2 } from "node:url";
26160
26119
 
@@ -26186,7 +26145,7 @@ class OpenCodeAdapter {
26186
26145
  if (paths.opencodeConfigFormat === "none")
26187
26146
  return false;
26188
26147
  try {
26189
- const raw = readFileSync13(paths.opencodeConfig, "utf-8");
26148
+ const raw = readFileSync12(paths.opencodeConfig, "utf-8");
26190
26149
  const cfg = import_comment_json2.parse(raw);
26191
26150
  return readPluginEntries(cfg).some(({ entry }) => matchesPluginEntry(entry, OPENCODE_PLUGIN_NAME));
26192
26151
  } catch {
@@ -26222,7 +26181,7 @@ class OpenCodeAdapter {
26222
26181
  configPath: target
26223
26182
  };
26224
26183
  }
26225
- const raw = readFileSync13(target, "utf-8");
26184
+ const raw = readFileSync12(target, "utf-8");
26226
26185
  const cfg = import_comment_json2.parse(raw);
26227
26186
  if (cfg === null || typeof cfg !== "object") {
26228
26187
  return {
@@ -26297,7 +26256,7 @@ class OpenCodeAdapter {
26297
26256
  };
26298
26257
  }
26299
26258
  try {
26300
- const raw = readFileSync13(target, "utf-8");
26259
+ const raw = readFileSync12(target, "utf-8");
26301
26260
  const cfg = import_comment_json2.parse(raw);
26302
26261
  if (cfg === null || typeof cfg !== "object") {
26303
26262
  return {
@@ -26348,9 +26307,9 @@ class OpenCodeAdapter {
26348
26307
  }
26349
26308
  getPluginCacheInfo() {
26350
26309
  const legacyPath = getOpenCodePluginCacheDir();
26351
- const legacyExists = existsSync18(legacyPath);
26310
+ const legacyExists = existsSync17(legacyPath);
26352
26311
  const slot = getOpenCodeV2PluginCacheSlot();
26353
- const slotExists = existsSync18(slot);
26312
+ const slotExists = existsSync17(slot);
26354
26313
  const caches = [];
26355
26314
  if (legacyExists || !slotExists) {
26356
26315
  caches.push({
@@ -26408,7 +26367,7 @@ class OpenCodeAdapter {
26408
26367
  if (paths.opencodeConfigFormat === "none")
26409
26368
  return "latest";
26410
26369
  try {
26411
- const cfg = import_comment_json2.parse(readFileSync13(paths.opencodeConfig, "utf-8"));
26370
+ const cfg = import_comment_json2.parse(readFileSync12(paths.opencodeConfig, "utf-8"));
26412
26371
  return readConfiguredOpenCodePluginSpec(cfg);
26413
26372
  } catch {
26414
26373
  return "latest";
@@ -26420,10 +26379,10 @@ class OpenCodeAdapter {
26420
26379
  return readOpenCodeV2CachedPluginVersion(slot) ?? null;
26421
26380
  }
26422
26381
  for (const candidate of getOpenCodePluginPackageJsonPaths()) {
26423
- if (!existsSync18(candidate))
26382
+ if (!existsSync17(candidate))
26424
26383
  continue;
26425
26384
  try {
26426
- const raw = readFileSync13(candidate, "utf-8");
26385
+ const raw = readFileSync12(candidate, "utf-8");
26427
26386
  const pkg = JSON.parse(raw);
26428
26387
  if (typeof pkg.version === "string")
26429
26388
  return pkg.version;
@@ -26466,8 +26425,8 @@ function isDevPathPluginEntry(entry, configDir) {
26466
26425
  const root = parsePath(localPath).root;
26467
26426
  while (localPath !== root) {
26468
26427
  const packagePath = resolve6(localPath, "package.json");
26469
- if (existsSync18(packagePath)) {
26470
- const pkg = JSON.parse(readFileSync13(packagePath, "utf8"));
26428
+ if (existsSync17(packagePath)) {
26429
+ const pkg = JSON.parse(readFileSync12(packagePath, "utf8"));
26471
26430
  return pkg.name === OPENCODE_PLUGIN_NAME;
26472
26431
  }
26473
26432
  localPath = dirname10(localPath);
@@ -26487,7 +26446,7 @@ function matchesPluginEntry(entry, pkgName) {
26487
26446
  }
26488
26447
  function ensureDir2(filePath) {
26489
26448
  const dir = dirname10(filePath);
26490
- if (!existsSync18(dir)) {
26449
+ if (!existsSync17(dir)) {
26491
26450
  const { mkdirSync } = __require("node:fs");
26492
26451
  mkdirSync(dir, { recursive: true });
26493
26452
  }
@@ -26508,8 +26467,8 @@ var init_opencode = __esm(async () => {
26508
26467
  });
26509
26468
 
26510
26469
  // src/lib/pi-package-entry.ts
26511
- import { existsSync as existsSync19, readFileSync as readFileSync14 } from "node:fs";
26512
- import { isAbsolute as isAbsolute6, join as join15 } from "node:path";
26470
+ import { existsSync as existsSync18, readFileSync as readFileSync13 } from "node:fs";
26471
+ import { isAbsolute as isAbsolute6, join as join14 } from "node:path";
26513
26472
  function stripNpmPrefix(value) {
26514
26473
  return value.startsWith("npm:") ? value.slice("npm:".length) : value;
26515
26474
  }
@@ -26564,11 +26523,11 @@ function hasPiMagicContextPackage(entries, agentDir = getPiAgentConfigDir()) {
26564
26523
  return entries.some((entry) => isConfiguredPiMagicContextEntry(entry, agentDir));
26565
26524
  }
26566
26525
  function isPiMagicContextPackageDir(dir) {
26567
- const packageJson = join15(dir, "package.json");
26568
- if (!existsSync19(packageJson))
26526
+ const packageJson = join14(dir, "package.json");
26527
+ if (!existsSync18(packageJson))
26569
26528
  return false;
26570
26529
  try {
26571
- const pkg = JSON.parse(readFileSync14(packageJson, "utf-8"));
26530
+ const pkg = JSON.parse(readFileSync13(packageJson, "utf-8"));
26572
26531
  return typeof pkg.name === "string" && pkg.name === PI_MAGIC_CONTEXT_PACKAGE_NAME;
26573
26532
  } catch {
26574
26533
  return false;
@@ -26580,7 +26539,7 @@ function localPiMagicContextPackageDir(entry, agentDir) {
26580
26539
  if (!spec || spec.startsWith("npm:"))
26581
26540
  return null;
26582
26541
  const path = spec.startsWith("file:") ? spec.slice("file:".length) : spec;
26583
- const dir = isAbsolute6(path) ? path : join15(agentDir, path);
26542
+ const dir = isAbsolute6(path) ? path : join14(agentDir, path);
26584
26543
  return isPiMagicContextPackageDir(dir) ? dir : null;
26585
26544
  }
26586
26545
  function isConfiguredPiMagicContextEntry(entry, agentDir) {
@@ -26604,7 +26563,7 @@ var init_pi_package_entry = __esm(() => {
26604
26563
  });
26605
26564
 
26606
26565
  // src/adapters/pi.ts
26607
- import { existsSync as existsSync20 } from "node:fs";
26566
+ import { existsSync as existsSync19 } from "node:fs";
26608
26567
  import { dirname as dirname11 } from "node:path";
26609
26568
 
26610
26569
  class PiAdapter {
@@ -26743,7 +26702,7 @@ function writePiSettings(settings) {
26743
26702
  }
26744
26703
  function ensureDir3(filePath) {
26745
26704
  const dir = dirname11(filePath);
26746
- if (!existsSync20(dir)) {
26705
+ if (!existsSync19(dir)) {
26747
26706
  const { mkdirSync } = __require("node:fs");
26748
26707
  mkdirSync(dir, { recursive: true });
26749
26708
  }
@@ -29851,7 +29810,7 @@ function installCompartmentHistoryVersions(db) {
29851
29810
 
29852
29811
  // ../plugin/src/features/magic-context/memory/project-identity-cache.ts
29853
29812
  import { createHash as createHash4 } from "node:crypto";
29854
- import { promises as fs2, readFileSync as readFileSync15 } from "node:fs";
29813
+ import { promises as fs2, readFileSync as readFileSync14 } from "node:fs";
29855
29814
  import path4 from "node:path";
29856
29815
  function cachePath(directory, storageDir = getMagicContextStorageDir()) {
29857
29816
  const hash = createHash4("sha256").update(projectDirectoryKey(directory)).digest("hex");
@@ -29865,7 +29824,7 @@ function rememberGitIdentity(directory, identity) {
29865
29824
  }
29866
29825
  function readRememberedGitIdentity(directory, storageDir) {
29867
29826
  try {
29868
- const record = JSON.parse(readFileSync15(cachePath(directory, storageDir), "utf8"));
29827
+ const record = JSON.parse(readFileSync14(cachePath(directory, storageDir), "utf8"));
29869
29828
  if (record.directory === projectDirectoryKey(directory) && /^git:[0-9a-f]{7,64}$/.test(record.identity))
29870
29829
  return record.identity;
29871
29830
  } catch {}
@@ -29878,7 +29837,7 @@ var init_project_identity_cache = __esm(() => {
29878
29837
  });
29879
29838
 
29880
29839
  // ../plugin/src/features/magic-context/memory/unborn-head.ts
29881
- import { readFileSync as readFileSync16, realpathSync as realpathSync4, statSync as statSync11 } from "node:fs";
29840
+ import { readFileSync as readFileSync15, realpathSync as realpathSync4, statSync as statSync11 } from "node:fs";
29882
29841
  import path5 from "node:path";
29883
29842
  function errorCode(error) {
29884
29843
  if (error === null || typeof error !== "object" || !("code" in error))
@@ -29888,7 +29847,7 @@ function errorCode(error) {
29888
29847
  }
29889
29848
  function readText(file) {
29890
29849
  try {
29891
- return { ok: true, text: readFileSync16(file, "utf8") };
29850
+ return { ok: true, text: readFileSync15(file, "utf8") };
29892
29851
  } catch (error) {
29893
29852
  return { ok: false, missing: errorCode(error) === "ENOENT" };
29894
29853
  }
@@ -30039,7 +29998,7 @@ var init_unborn_head = __esm(() => {
30039
29998
  // ../plugin/src/features/magic-context/memory/project-identity.ts
30040
29999
  import { execFileSync as execFileSync4 } from "node:child_process";
30041
30000
  import { createHash as createHash5 } from "node:crypto";
30042
- import { existsSync as existsSync21, realpathSync as realpathSync5, statSync as statSync12 } from "node:fs";
30001
+ import { existsSync as existsSync20, realpathSync as realpathSync5, statSync as statSync12 } from "node:fs";
30043
30002
  import { homedir as homedir12 } from "node:os";
30044
30003
  import path6 from "node:path";
30045
30004
  function asError(error) {
@@ -30223,7 +30182,7 @@ function nearestLastKnownGitIdentity(canonical) {
30223
30182
  const cached = lastKnownGitIdentity(current);
30224
30183
  if (cached !== undefined)
30225
30184
  return { identity: cached, source: current };
30226
- if (existsSync21(path6.join(current, ".git")))
30185
+ if (existsSync20(path6.join(current, ".git")))
30227
30186
  break;
30228
30187
  const parent = path6.dirname(current);
30229
30188
  if (parent === current)
@@ -30346,7 +30305,7 @@ function hasGitDir(canonical) {
30346
30305
  function gitRootInAncestorChain(startDirectory) {
30347
30306
  let current = startDirectory;
30348
30307
  while (true) {
30349
- if (existsSync21(path6.join(current, ".git"))) {
30308
+ if (existsSync20(path6.join(current, ".git"))) {
30350
30309
  try {
30351
30310
  return realpathSync5.native(current);
30352
30311
  } catch {
@@ -33818,7 +33777,7 @@ var init_tool_definition_tokens = __esm(() => {
33818
33777
  });
33819
33778
 
33820
33779
  // ../plugin/src/features/magic-context/tool-owner-backfill.ts
33821
- import { existsSync as existsSync22 } from "node:fs";
33780
+ import { existsSync as existsSync21 } from "node:fs";
33822
33781
  function resolveOpencodeDbPath() {
33823
33782
  return resolveOpenCodeDbPath().path;
33824
33783
  }
@@ -33855,7 +33814,7 @@ function runToolOwnerBackfill(db) {
33855
33814
  return result;
33856
33815
  }
33857
33816
  const opencodeDbPath = resolveOpencodeDbPath();
33858
- if (!existsSync22(opencodeDbPath)) {
33817
+ if (!existsSync21(opencodeDbPath)) {
33859
33818
  log(`[backfill] OpenCode DB not found at ${opencodeDbPath} — marking all unbackfilled sessions as skipped. Lazy adoption (defense-in-depth) handles legacy rows at runtime.`);
33860
33819
  markAllUnbackfilledSessionsSkipped(db);
33861
33820
  result.sessionsSkippedNoOcDb = countSessionsByStatus(db, "skipped");
@@ -36703,14 +36662,14 @@ var init_message_time_backfill = __esm(async () => {
36703
36662
 
36704
36663
  // ../plugin/src/features/magic-context/storage-db.ts
36705
36664
  import {
36706
- existsSync as existsSync23,
36665
+ existsSync as existsSync22,
36707
36666
  readdirSync as readdirSync5,
36708
- readFileSync as readFileSync17,
36667
+ readFileSync as readFileSync16,
36709
36668
  rmdirSync,
36710
36669
  statSync as statSync13,
36711
- unlinkSync as unlinkSync3
36670
+ unlinkSync as unlinkSync4
36712
36671
  } from "node:fs";
36713
- import { basename as basename4, dirname as dirname12, join as join16, resolve as resolve7 } from "node:path";
36672
+ import { basename as basename4, dirname as dirname12, join as join15, resolve as resolve7 } from "node:path";
36714
36673
  function ensureSecureStorageDir(dir) {
36715
36674
  ensureStorageDirectorySync(dir);
36716
36675
  }
@@ -36734,14 +36693,14 @@ function resolveDatabasePath(dbPathOverride) {
36734
36693
  return { dbDir: dirname12(dbPathOverride), dbPath: dbPathOverride };
36735
36694
  }
36736
36695
  const dbDir = getMagicContextStorageDir();
36737
- return { dbDir, dbPath: join16(dbDir, "context.db") };
36696
+ return { dbDir, dbPath: join15(dbDir, "context.db") };
36738
36697
  }
36739
36698
  function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
36740
- if (existsSync23(targetDbPath))
36699
+ if (existsSync22(targetDbPath))
36741
36700
  return;
36742
36701
  const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
36743
- const legacyDbPath = join16(legacyDir, "context.db");
36744
- if (!existsSync23(legacyDbPath))
36702
+ const legacyDbPath = join15(legacyDir, "context.db");
36703
+ if (!existsSync22(legacyDbPath))
36745
36704
  return;
36746
36705
  log(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
36747
36706
  ensureSecureStorageDir(targetDbDir);
@@ -36758,8 +36717,8 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
36758
36717
  }
36759
36718
  for (const suffix of ["", "-wal", "-shm"]) {
36760
36719
  const src = `${legacyDbPath}${suffix}`;
36761
- const dst = join16(targetDbDir, `context.db${suffix}`);
36762
- if (existsSync23(src)) {
36720
+ const dst = join15(targetDbDir, `context.db${suffix}`);
36721
+ if (existsSync22(src)) {
36763
36722
  try {
36764
36723
  copyStorageFileSync(src, dst);
36765
36724
  } catch (error) {
@@ -36767,9 +36726,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
36767
36726
  }
36768
36727
  }
36769
36728
  }
36770
- const legacyModelsDir = join16(legacyDir, "models");
36771
- const targetModelsDir = join16(targetDbDir, "models");
36772
- if (existsSync23(legacyModelsDir) && !existsSync23(targetModelsDir)) {
36729
+ const legacyModelsDir = join15(legacyDir, "models");
36730
+ const targetModelsDir = join15(targetDbDir, "models");
36731
+ if (existsSync22(legacyModelsDir) && !existsSync22(targetModelsDir)) {
36773
36732
  try {
36774
36733
  copyStorageTreeSync(legacyModelsDir, targetModelsDir);
36775
36734
  } catch (error) {
@@ -36877,7 +36836,7 @@ function classifyJunkDiscovery(portFile, raw, staleFiles) {
36877
36836
  function inspectRpcServerDiscovery(storageDir, processes, options) {
36878
36837
  const deadline = options?.deadlineMs === undefined ? Number.POSITIVE_INFINITY : Date.now() + options.deadlineMs;
36879
36838
  let progressAt = Date.now() + 3000;
36880
- const rpcRoot = join16(storageDir, "rpc");
36839
+ const rpcRoot = join15(storageDir, "rpc");
36881
36840
  let projectEntries;
36882
36841
  try {
36883
36842
  projectEntries = rpcDiscoveryFs.readdirSync(rpcRoot, { withFileTypes: true });
@@ -36891,7 +36850,7 @@ function inspectRpcServerDiscovery(storageDir, processes, options) {
36891
36850
  for (const projectEntry of projectEntries) {
36892
36851
  if (!projectEntry.isDirectory())
36893
36852
  continue;
36894
- const projectDir = join16(rpcRoot, projectEntry.name);
36853
+ const projectDir = join15(rpcRoot, projectEntry.name);
36895
36854
  let entries;
36896
36855
  try {
36897
36856
  entries = rpcDiscoveryFs.readdirSync(projectDir);
@@ -36902,7 +36861,7 @@ function inspectRpcServerDiscovery(storageDir, processes, options) {
36902
36861
  }
36903
36862
  for (const entry of entries) {
36904
36863
  if (entry === "port" || entry.startsWith("port-") && entry.endsWith(".json")) {
36905
- portFiles.push(join16(projectDir, entry));
36864
+ portFiles.push(join15(projectDir, entry));
36906
36865
  }
36907
36866
  }
36908
36867
  }
@@ -37005,7 +36964,7 @@ function inspectRpcServerDiscovery(storageDir, processes, options) {
37005
36964
  return { state: "stale", serverPids: [], staleFiles };
37006
36965
  }
37007
36966
  function pruneEmptyRpcDiscoveryDirs(storageDir) {
37008
- const rpcRoot = join16(storageDir, "rpc");
36967
+ const rpcRoot = join15(storageDir, "rpc");
37009
36968
  let entries;
37010
36969
  try {
37011
36970
  entries = rpcDiscoveryFs.readdirSync(rpcRoot, { withFileTypes: true });
@@ -37017,7 +36976,7 @@ function pruneEmptyRpcDiscoveryDirs(storageDir) {
37017
36976
  for (const entry of entries) {
37018
36977
  if (!entry.isDirectory())
37019
36978
  continue;
37020
- const projectDir = join16(rpcRoot, entry.name);
36979
+ const projectDir = join15(rpcRoot, entry.name);
37021
36980
  try {
37022
36981
  if (rpcDiscoveryFs.readdirSync(projectDir).length > 0)
37023
36982
  continue;
@@ -37031,7 +36990,7 @@ function pruneEmptyRpcDiscoveryDirs(storageDir) {
37031
36990
  return removed;
37032
36991
  }
37033
36992
  function removeRpcDiscoveryRecords(storageDir, files) {
37034
- const rpcRoot = resolve7(join16(storageDir, "rpc"));
36993
+ const rpcRoot = resolve7(join15(storageDir, "rpc"));
37035
36994
  const removed = [];
37036
36995
  const failed = [];
37037
36996
  for (const file of files) {
@@ -37083,7 +37042,7 @@ function isDefaultSharedDatabasePath(dbPath) {
37083
37042
  if (!process.env.XDG_DATA_HOME && (process.env.MAGIC_CONTEXT_TEST_DATA_DIR || false)) {
37084
37043
  return false;
37085
37044
  }
37086
- return resolve7(dbPath) === resolve7(join16(getMagicContextStorageDir(), "context.db"));
37045
+ return resolve7(dbPath) === resolve7(join15(getMagicContextStorageDir(), "context.db"));
37087
37046
  }
37088
37047
  function migrationBlockingPiPids(dbPath, discovery, discoveredPiPids) {
37089
37048
  if (isDefaultSharedDatabasePath(dbPath))
@@ -38499,7 +38458,7 @@ function openDatabase(dbPathOrOptions) {
38499
38458
  }
38500
38459
  ensureSecureStorageDir(dbDir);
38501
38460
  tightenStorageTree(dbDir);
38502
- if (!existsSync23(dbPath) && shouldEnforcePrivateStoragePermissions()) {
38461
+ if (!existsSync22(dbPath) && shouldEnforcePrivateStoragePermissions()) {
38503
38462
  try {
38504
38463
  writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
38505
38464
  } catch (error) {
@@ -38601,9 +38560,9 @@ var init_storage_db = __esm(async () => {
38601
38560
  RPC_DISCOVERY_PARSE_GRACE_MS = 10 * 60 * 1000;
38602
38561
  defaultRpcDiscoveryFs = {
38603
38562
  readdirSync: (path, options) => options?.withFileTypes ? readdirSync5(path, { withFileTypes: true }) : readdirSync5(path),
38604
- readFileSync: (path, encoding) => String(readFileSync17(path, encoding)),
38563
+ readFileSync: (path, encoding) => String(readFileSync16(path, encoding)),
38605
38564
  statSync: (path) => ({ mtimeMs: statSync13(path).mtimeMs }),
38606
- unlinkSync: (path) => unlinkSync3(path),
38565
+ unlinkSync: (path) => unlinkSync4(path),
38607
38566
  rmdirSync: (path) => rmdirSync(path)
38608
38567
  };
38609
38568
  rpcDiscoveryFs = defaultRpcDiscoveryFs;
@@ -38616,18 +38575,18 @@ var init_storage_db = __esm(async () => {
38616
38575
  });
38617
38576
 
38618
38577
  // src/lib/database-access.ts
38619
- import { existsSync as existsSync24, rmSync as rmSync6 } from "node:fs";
38578
+ import { existsSync as existsSync23, rmSync as rmSync6 } from "node:fs";
38620
38579
  import { basename as basename5, dirname as dirname13 } from "node:path";
38621
38580
  import { pathToFileURL as pathToFileURL2 } from "node:url";
38622
38581
  function getPersistedSchemaVersion2(db) {
38623
38582
  return getPersistedSchemaVersion(db);
38624
38583
  }
38625
38584
  function openExistingDatabase(path, options) {
38626
- if (!existsSync24(path))
38585
+ if (!existsSync23(path))
38627
38586
  return null;
38628
38587
  if (options.readonly) {
38629
38588
  const name = basename5(path);
38630
- if ((name === "context.db" || name === "store.db") && !existsSync24(`${path}-wal`) && !existsSync24(`${path}-shm`)) {
38589
+ if ((name === "context.db" || name === "store.db") && !existsSync23(`${path}-wal`) && !existsSync23(`${path}-shm`)) {
38631
38590
  const probe = probeHostProcessesUsing({
38632
38591
  files: [path, `${path}-wal`, `${path}-shm`],
38633
38592
  directories: []
@@ -38693,7 +38652,7 @@ async function backupDatabaseSnapshot(db, sourcePath, destination) {
38693
38652
  if (typeof sqlite.backup !== "function") {
38694
38653
  throw new Error("The active SQLite runtime does not provide a snapshot backup API");
38695
38654
  }
38696
- if (existsSync24(destination)) {
38655
+ if (existsSync23(destination)) {
38697
38656
  throw new Error(`Refusing to overwrite existing backup ${destination}`);
38698
38657
  }
38699
38658
  const reader = openExistingDatabase(sourcePath, { readonly: true });
@@ -38994,10 +38953,10 @@ var init_dreamer_setup = __esm(() => {
38994
38953
  });
38995
38954
 
38996
38955
  // src/commands/setup-pi.ts
38997
- import { existsSync as existsSync25, mkdirSync as mkdirSync6 } from "node:fs";
38956
+ import { existsSync as existsSync24, mkdirSync as mkdirSync6 } from "node:fs";
38998
38957
  import { dirname as dirname14 } from "node:path";
38999
38958
  function ensureDir4(path) {
39000
- if (!existsSync25(path))
38959
+ if (!existsSync24(path))
39001
38960
  mkdirSync6(path, { recursive: true });
39002
38961
  }
39003
38962
  async function getDefaultPrompts() {
@@ -39453,15 +39412,15 @@ var init_setup_omp = __esm(() => {
39453
39412
 
39454
39413
  // ../plugin/src/shared/opencode-config-dir.ts
39455
39414
  import { homedir as homedir13 } from "node:os";
39456
- import { join as join17, resolve as resolve8 } from "node:path";
39415
+ import { join as join16, resolve as resolve8 } from "node:path";
39457
39416
  function resolveHomeDir() {
39458
39417
  return process.env.HOME?.trim() || homedir13();
39459
39418
  }
39460
39419
  function getOpenCodeGlobalConfigDir() {
39461
39420
  if (process.platform === "win32") {
39462
- return join17(resolveHomeDir(), ".config", "opencode");
39421
+ return join16(resolveHomeDir(), ".config", "opencode");
39463
39422
  }
39464
- return join17(process.env.XDG_CONFIG_HOME || join17(resolveHomeDir(), ".config"), "opencode");
39423
+ return join16(process.env.XDG_CONFIG_HOME || join16(resolveHomeDir(), ".config"), "opencode");
39465
39424
  }
39466
39425
  function getEnvConfigDir() {
39467
39426
  const envConfigDir = process.env.OPENCODE_CONFIG_DIR?.trim();
@@ -39477,14 +39436,14 @@ function getOpenCodeConfigPaths(options) {
39477
39436
  const configDir = getOpenCodeConfigDir2(options);
39478
39437
  return {
39479
39438
  configDir,
39480
- configJson: join17(configDir, "opencode.json"),
39481
- configJsonc: join17(configDir, "opencode.jsonc"),
39482
- packageJson: join17(configDir, "package.json"),
39483
- omoConfig: join17(configDir, "magic-context.jsonc")
39439
+ configJson: join16(configDir, "opencode.json"),
39440
+ configJsonc: join16(configDir, "opencode.jsonc"),
39441
+ packageJson: join16(configDir, "package.json"),
39442
+ omoConfig: join16(configDir, "magic-context.jsonc")
39484
39443
  };
39485
39444
  }
39486
39445
  function getOpenCodeConfigDirs() {
39487
- const dirs = [getOpenCodeGlobalConfigDir(), join17(resolveHomeDir(), ".opencode")];
39446
+ const dirs = [getOpenCodeGlobalConfigDir(), join16(resolveHomeDir(), ".opencode")];
39488
39447
  const envDir = getEnvConfigDir();
39489
39448
  if (envDir)
39490
39449
  dirs.push(envDir);
@@ -39494,7 +39453,7 @@ var init_opencode_config_dir = () => {};
39494
39453
 
39495
39454
  // ../plugin/src/shared/conflict-detector.ts
39496
39455
  import { homedir as homedir14 } from "node:os";
39497
- import { join as join18 } from "node:path";
39456
+ import { join as join17 } from "node:path";
39498
39457
  function detectConflicts(directory, options) {
39499
39458
  const compactionEnabled = options?.compactionEnabled ?? true;
39500
39459
  const hostGeneration = options?.hostGeneration ?? "v1";
@@ -39561,19 +39520,19 @@ function checkCompaction(directory, hostGeneration) {
39561
39520
  function openCodeConfigFileChain(directory, hostGeneration) {
39562
39521
  const globalDir = getOpenCodeGlobalConfigDir();
39563
39522
  const wellKnown = [
39564
- join18(globalDir, "config.json"),
39565
- join18(globalDir, "opencode.json"),
39566
- join18(globalDir, "opencode.jsonc")
39523
+ join17(globalDir, "config.json"),
39524
+ join17(globalDir, "opencode.json"),
39525
+ join17(globalDir, "opencode.jsonc")
39567
39526
  ];
39568
- const globalSupplementary = getOpenCodeConfigDirs().filter((dir) => dir !== globalDir).flatMap((dir) => [join18(dir, "opencode.json"), join18(dir, "opencode.jsonc")]);
39527
+ const globalSupplementary = getOpenCodeConfigDirs().filter((dir) => dir !== globalDir).flatMap((dir) => [join17(dir, "opencode.json"), join17(dir, "opencode.jsonc")]);
39569
39528
  const explicitConfig = process.env.OPENCODE_CONFIG?.trim();
39570
39529
  const explicit = explicitConfig ? [explicitConfig] : [];
39571
39530
  const disableProjectConfig = process.env.OPENCODE_DISABLE_PROJECT_CONFIG?.toLowerCase();
39572
39531
  const skipProject = hostGeneration === "v1" && (disableProjectConfig === "true" || disableProjectConfig === "1");
39573
- const direct = skipProject ? [] : [join18(directory, "opencode.json"), join18(directory, "opencode.jsonc")];
39532
+ const direct = skipProject ? [] : [join17(directory, "opencode.json"), join17(directory, "opencode.jsonc")];
39574
39533
  const projectSupplementary = skipProject ? [] : [
39575
- join18(directory, ".opencode", "opencode.json"),
39576
- join18(directory, ".opencode", "opencode.jsonc")
39534
+ join17(directory, ".opencode", "opencode.json"),
39535
+ join17(directory, ".opencode", "opencode.jsonc")
39577
39536
  ];
39578
39537
  const files = hostGeneration === "v2" ? [
39579
39538
  ...wellKnown,
@@ -39660,10 +39619,10 @@ function collectPluginEntries(directory) {
39660
39619
  }
39661
39620
  };
39662
39621
  for (const configPath of [
39663
- join18(directory, ".opencode", "opencode.jsonc"),
39664
- join18(directory, ".opencode", "opencode.json"),
39665
- join18(directory, "opencode.jsonc"),
39666
- join18(directory, "opencode.json")
39622
+ join17(directory, ".opencode", "opencode.jsonc"),
39623
+ join17(directory, ".opencode", "opencode.json"),
39624
+ join17(directory, "opencode.jsonc"),
39625
+ join17(directory, "opencode.json")
39667
39626
  ]) {
39668
39627
  const config = readJsoncFile(configPath);
39669
39628
  pushFrom(config?.plugin);
@@ -39673,7 +39632,7 @@ function collectPluginEntries(directory) {
39673
39632
  for (const dir of getOpenCodeConfigDirs()) {
39674
39633
  const names = dir === globalDir ? ["config.json", "opencode.json", "opencode.jsonc"] : ["opencode.json", "opencode.jsonc"];
39675
39634
  for (const name of names) {
39676
- const config = readJsoncFile(join18(dir, name));
39635
+ const config = readJsoncFile(join17(dir, name));
39677
39636
  pushFrom(config?.plugin);
39678
39637
  }
39679
39638
  }
@@ -39707,7 +39666,7 @@ function readOmoDisabledHooks(directory) {
39707
39666
  try {
39708
39667
  for (const dir of getOpenCodeConfigDirs()) {
39709
39668
  for (const name of configNames) {
39710
- const config = readJsoncFile(join18(dir, name));
39669
+ const config = readJsoncFile(join17(dir, name));
39711
39670
  if (config?.disabled_hooks) {
39712
39671
  for (const hook of config.disabled_hooks) {
39713
39672
  disabled.add(hook);
@@ -39717,7 +39676,7 @@ function readOmoDisabledHooks(directory) {
39717
39676
  }
39718
39677
  } catch {}
39719
39678
  for (const name of configNames) {
39720
- const config = readJsoncFile(join18(directory, name));
39679
+ const config = readJsoncFile(join17(directory, name));
39721
39680
  if (config?.disabled_hooks) {
39722
39681
  for (const hook of config.disabled_hooks) {
39723
39682
  disabled.add(hook);
@@ -39725,9 +39684,9 @@ function readOmoDisabledHooks(directory) {
39725
39684
  }
39726
39685
  }
39727
39686
  const homeDir = process.env.HOME || homedir14();
39728
- const omoHomeDir = join18(homeDir, ".omo");
39687
+ const omoHomeDir = join17(homeDir, ".omo");
39729
39688
  for (const name of ["omo.jsonc", "omo.json"]) {
39730
- const config = readJsoncFile(join18(omoHomeDir, name));
39689
+ const config = readJsoncFile(join17(omoHomeDir, name));
39731
39690
  if (config?.["[opencode]"]?.disabled_hooks) {
39732
39691
  for (const hook of config["[opencode]"].disabled_hooks) {
39733
39692
  disabled.add(hook);
@@ -39735,7 +39694,7 @@ function readOmoDisabledHooks(directory) {
39735
39694
  }
39736
39695
  }
39737
39696
  for (const name of ["omo.jsonc", "omo.json"]) {
39738
- const config = readJsoncFile(join18(directory, ".omo", name));
39697
+ const config = readJsoncFile(join17(directory, ".omo", name));
39739
39698
  if (config?.["[opencode]"]?.disabled_hooks) {
39740
39699
  for (const hook of config["[opencode]"].disabled_hooks) {
39741
39700
  disabled.add(hook);
@@ -39754,9 +39713,9 @@ var init_conflict_detector = __esm(() => {
39754
39713
  });
39755
39714
 
39756
39715
  // ../plugin/src/shared/conflict-fixer.ts
39757
- import { existsSync as existsSync26, readFileSync as readFileSync18, writeFileSync as writeFileSync6 } from "node:fs";
39716
+ import { existsSync as existsSync25, readFileSync as readFileSync17, writeFileSync as writeFileSync6 } from "node:fs";
39758
39717
  import { homedir as homedir15 } from "node:os";
39759
- import { join as join19 } from "node:path";
39718
+ import { join as join18 } from "node:path";
39760
39719
  function isRecord3(value) {
39761
39720
  return typeof value === "object" && value !== null && !Array.isArray(value);
39762
39721
  }
@@ -39764,11 +39723,11 @@ function asStringArray(value) {
39764
39723
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
39765
39724
  }
39766
39725
  function readConfig(filePath) {
39767
- if (!existsSync26(filePath)) {
39726
+ if (!existsSync25(filePath)) {
39768
39727
  return null;
39769
39728
  }
39770
39729
  try {
39771
- const text = readFileSync18(filePath, "utf-8");
39730
+ const text = readFileSync17(filePath, "utf-8");
39772
39731
  const parsed = import_comment_json5.parse(text);
39773
39732
  return isRecord3(parsed) ? { config: parsed, text } : null;
39774
39733
  } catch {
@@ -39780,23 +39739,23 @@ function writeConfig(filePath, text) {
39780
39739
  }
39781
39740
  function resolveUserOpenCodeConfigPath() {
39782
39741
  const paths = getOpenCodeConfigPaths({ binary: "opencode" });
39783
- if (existsSync26(paths.configJsonc))
39742
+ if (existsSync25(paths.configJsonc))
39784
39743
  return paths.configJsonc;
39785
39744
  return paths.configJson;
39786
39745
  }
39787
39746
  function collectOpenCodeConfigPaths(directory) {
39788
39747
  const paths = new Set;
39789
39748
  const userConfig = resolveUserOpenCodeConfigPath();
39790
- if (existsSync26(userConfig)) {
39749
+ if (existsSync25(userConfig)) {
39791
39750
  paths.add(userConfig);
39792
39751
  }
39793
39752
  for (const filePath of [
39794
- join19(directory, ".opencode", "opencode.jsonc"),
39795
- join19(directory, ".opencode", "opencode.json"),
39796
- join19(directory, "opencode.jsonc"),
39797
- join19(directory, "opencode.json")
39753
+ join18(directory, ".opencode", "opencode.jsonc"),
39754
+ join18(directory, ".opencode", "opencode.json"),
39755
+ join18(directory, "opencode.jsonc"),
39756
+ join18(directory, "opencode.json")
39798
39757
  ]) {
39799
- if (existsSync26(filePath)) {
39758
+ if (existsSync25(filePath)) {
39800
39759
  paths.add(filePath);
39801
39760
  }
39802
39761
  }
@@ -39806,26 +39765,26 @@ function collectOmoConfigPaths(directory) {
39806
39765
  const paths = new Set;
39807
39766
  const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
39808
39767
  for (const fileName of OMO_CONFIG_NAMES) {
39809
- const userPath = join19(configDir, fileName);
39810
- const projectPath = join19(directory, fileName);
39811
- if (existsSync26(userPath)) {
39768
+ const userPath = join18(configDir, fileName);
39769
+ const projectPath = join18(directory, fileName);
39770
+ if (existsSync25(userPath)) {
39812
39771
  paths.add(userPath);
39813
39772
  }
39814
- if (existsSync26(projectPath)) {
39773
+ if (existsSync25(projectPath)) {
39815
39774
  paths.add(projectPath);
39816
39775
  }
39817
39776
  }
39818
39777
  const homeDir = process.env.HOME || homedir15();
39819
- const omoHomeDir = join19(homeDir, ".omo");
39778
+ const omoHomeDir = join18(homeDir, ".omo");
39820
39779
  for (const name of OMO_UNIFIED_NAMES) {
39821
- const userPath = join19(omoHomeDir, name);
39822
- if (existsSync26(userPath)) {
39780
+ const userPath = join18(omoHomeDir, name);
39781
+ if (existsSync25(userPath)) {
39823
39782
  paths.add(userPath);
39824
39783
  }
39825
39784
  }
39826
39785
  for (const name of OMO_UNIFIED_NAMES) {
39827
- const projectPath = join19(directory, ".omo", name);
39828
- if (existsSync26(projectPath)) {
39786
+ const projectPath = join18(directory, ".omo", name);
39787
+ if (existsSync25(projectPath)) {
39829
39788
  paths.add(projectPath);
39830
39789
  }
39831
39790
  }
@@ -39953,7 +39912,7 @@ var init_conflict_fixer = __esm(() => {
39953
39912
  });
39954
39913
 
39955
39914
  // src/commands/setup-opencode.ts
39956
- import { existsSync as existsSync27 } from "node:fs";
39915
+ import { existsSync as existsSync26 } from "node:fs";
39957
39916
  import { basename as basename6, dirname as dirname15 } from "node:path";
39958
39917
  function resolveCompactionEnabledForWriter() {
39959
39918
  try {
@@ -39969,7 +39928,7 @@ function isPlainObject5(value) {
39969
39928
  }
39970
39929
  function planOpenCodeConfigUpdate(configPath, removeDcp = false, compactionEnabled = true, hostGeneration = "v1") {
39971
39930
  const registrationKey = pluginConfigKeyFor(hostGeneration);
39972
- const existsAtCommit = existsSync27(configPath);
39931
+ const existsAtCommit = existsSync26(configPath);
39973
39932
  const existing = existsAtCommit ? readJsoncConfigForUpdate(configPath) : {};
39974
39933
  if (!existsAtCommit) {
39975
39934
  const created = { [registrationKey]: [OPENCODE_PLUGIN_ENTRY_WITH_VERSION] };
@@ -40025,7 +39984,7 @@ function planOpenCodeConfigUpdate(configPath, removeDcp = false, compactionEnabl
40025
39984
  return changed ? document.bom + text : null;
40026
39985
  }
40027
39986
  function planTuiConfigUpdate(configPath) {
40028
- const existsAtCommit = existsSync27(configPath);
39987
+ const existsAtCommit = existsSync26(configPath);
40029
39988
  const existing = existsAtCommit ? readJsoncConfigForUpdate(configPath) : {};
40030
39989
  if (!existsAtCommit) {
40031
39990
  return `${import_comment_json6.stringify({ plugin: [OPENCODE_PLUGIN_ENTRY_WITH_VERSION] }, null, 2)}
@@ -40152,7 +40111,7 @@ async function runSetup3(dryRun = false) {
40152
40111
  log3.warn("You can configure models manually in magic-context.jsonc later");
40153
40112
  }
40154
40113
  const paths = detectConfigPaths();
40155
- const hadExistingSetup = paths.opencodeConfigFormat !== "none" || existsSync27(paths.magicContextConfig) || paths.tuiConfigFormat !== "none";
40114
+ const hadExistingSetup = paths.opencodeConfigFormat !== "none" || existsSync26(paths.magicContextConfig) || paths.tuiConfigFormat !== "none";
40156
40115
  if (!dryRun) {
40157
40116
  try {
40158
40117
  assertJsoncConfigsParseable([
@@ -40379,12 +40338,6 @@ async function runSetup4(argv) {
40379
40338
  continue;
40380
40339
  }
40381
40340
  if (!dryRun) {
40382
- const ignore = ensureDocsProposalGitignore(process.cwd());
40383
- if (ignore.status === "added") {
40384
- log3.info(`Added .cortexkit/magic-context/ to ${ignore.path}`);
40385
- } else if (ignore.status === "failed") {
40386
- log3.warn(`Could not update ${ignore.path}: ${ignore.error}`);
40387
- }
40388
40341
  printNextSteps(adapter);
40389
40342
  }
40390
40343
  }
@@ -40433,7 +40386,6 @@ function printNextSteps(adapter) {
40433
40386
  }
40434
40387
  var init_setup = __esm(async () => {
40435
40388
  init_dashboard_install();
40436
- init_docs_proposal_gitignore();
40437
40389
  init_prompts();
40438
40390
  init_setup_omp();
40439
40391
  init_setup_pi();
@@ -40445,7 +40397,7 @@ var init_setup = __esm(async () => {
40445
40397
  });
40446
40398
 
40447
40399
  // src/lib/disk-space.ts
40448
- import { existsSync as existsSync28, statfsSync, statSync as statSync14 } from "node:fs";
40400
+ import { existsSync as existsSync27, statfsSync, statSync as statSync14 } from "node:fs";
40449
40401
  import { dirname as dirname16, resolve as resolve9 } from "node:path";
40450
40402
  function availableDiskBytes(path) {
40451
40403
  const filesystem = statfsSync(path);
@@ -40463,7 +40415,7 @@ function checkDiskSpace(path, bytes, freeBytes) {
40463
40415
  function existingDirectoryAncestor(path) {
40464
40416
  let current = resolve9(path);
40465
40417
  for (;; ) {
40466
- if (existsSync28(current) && statSync14(current).isDirectory())
40418
+ if (existsSync27(current) && statSync14(current).isDirectory())
40467
40419
  return current;
40468
40420
  const parent = dirname16(current);
40469
40421
  if (parent === current)
@@ -40475,24 +40427,24 @@ var init_disk_space = () => {};
40475
40427
 
40476
40428
  // ../plugin/src/hooks/auto-update-checker/constants.ts
40477
40429
  import { homedir as homedir16, platform } from "node:os";
40478
- import { join as join20 } from "node:path";
40430
+ import { join as join19 } from "node:path";
40479
40431
  function getOpenCodeCacheRoot() {
40480
40432
  if (platform() === "win32") {
40481
- return join20(process.env.LOCALAPPDATA ?? homedir16(), "opencode");
40433
+ return join19(process.env.LOCALAPPDATA ?? homedir16(), "opencode");
40482
40434
  }
40483
- return join20(homedir16(), ".cache", "opencode");
40435
+ return join19(homedir16(), ".cache", "opencode");
40484
40436
  }
40485
40437
  function getOpenCodeConfigRoot() {
40486
40438
  if (platform() === "win32") {
40487
- return join20(process.env.APPDATA ?? join20(homedir16(), "AppData", "Roaming"), "opencode");
40439
+ return join19(process.env.APPDATA ?? join19(homedir16(), "AppData", "Roaming"), "opencode");
40488
40440
  }
40489
- return join20(process.env.XDG_CONFIG_HOME ?? join20(homedir16(), ".config"), "opencode");
40441
+ return join19(process.env.XDG_CONFIG_HOME ?? join19(homedir16(), ".config"), "opencode");
40490
40442
  }
40491
40443
  var PACKAGE_NAME = "@cortexkit/opencode-magic-context", CACHE_DIR, USER_OPENCODE_CONFIG, USER_OPENCODE_CONFIG_JSONC;
40492
40444
  var init_constants2 = __esm(() => {
40493
- CACHE_DIR = join20(getOpenCodeCacheRoot(), "packages");
40494
- USER_OPENCODE_CONFIG = join20(getOpenCodeConfigRoot(), "opencode.json");
40495
- USER_OPENCODE_CONFIG_JSONC = join20(getOpenCodeConfigRoot(), "opencode.jsonc");
40445
+ CACHE_DIR = join19(getOpenCodeCacheRoot(), "packages");
40446
+ USER_OPENCODE_CONFIG = join19(getOpenCodeConfigRoot(), "opencode.json");
40447
+ USER_OPENCODE_CONFIG_JSONC = join19(getOpenCodeConfigRoot(), "opencode.jsonc");
40496
40448
  });
40497
40449
 
40498
40450
  // ../plugin/src/hooks/auto-update-checker/types.ts
@@ -40516,14 +40468,14 @@ var init_types = __esm(() => {
40516
40468
  // ../plugin/src/hooks/auto-update-checker/checker.ts
40517
40469
  import {
40518
40470
  accessSync as accessSync3,
40519
- existsSync as existsSync29,
40471
+ existsSync as existsSync28,
40520
40472
  constants as fsConstants,
40521
- readFileSync as readFileSync19,
40473
+ readFileSync as readFileSync18,
40522
40474
  renameSync as renameSync5,
40523
40475
  statSync as statSync15,
40524
40476
  writeFileSync as writeFileSync7
40525
40477
  } from "node:fs";
40526
- import { dirname as dirname17, isAbsolute as isAbsolute7, join as join21, resolve as resolve10 } from "node:path";
40478
+ import { dirname as dirname17, isAbsolute as isAbsolute7, join as join20, resolve as resolve10 } from "node:path";
40527
40479
  function warn(message) {
40528
40480
  log(`WARN: ${message}`);
40529
40481
  }
@@ -40553,13 +40505,13 @@ function getSurfaceConfigPaths(directory, surface) {
40553
40505
  const dirs = [
40554
40506
  globalDir,
40555
40507
  directory,
40556
- join21(directory, ".opencode"),
40508
+ join20(directory, ".opencode"),
40557
40509
  process.env.OPENCODE_CONFIG_DIR
40558
40510
  ].filter((value) => Boolean(value));
40559
40511
  const paths = [];
40560
40512
  for (const dir of dirs) {
40561
40513
  for (const extension of ["json", "jsonc"]) {
40562
- const path = join21(dir, `${name}.${extension}`);
40514
+ const path = join20(dir, `${name}.${extension}`);
40563
40515
  if (!paths.includes(path))
40564
40516
  paths.push(path);
40565
40517
  }
@@ -40570,9 +40522,9 @@ function getWinningConfig(directory, surface) {
40570
40522
  let winner = null;
40571
40523
  for (const path of getSurfaceConfigPaths(directory, surface)) {
40572
40524
  try {
40573
- if (!existsSync29(path))
40525
+ if (!existsSync28(path))
40574
40526
  continue;
40575
- const parsed = parseJsonConfig(readFileSync19(path, "utf-8"));
40527
+ const parsed = parseJsonConfig(readFileSync18(path, "utf-8"));
40576
40528
  const entries = getPluginEntries(parsed);
40577
40529
  if (entries.some((entry) => entry === PACKAGE_NAME || entry.startsWith(`${PACKAGE_NAME}@`))) {
40578
40530
  if (winner) {
@@ -40609,14 +40561,14 @@ var init_checker = __esm(async () => {
40609
40561
  });
40610
40562
 
40611
40563
  // src/lib/opencode-plugin-schema-fence.ts
40612
- import { existsSync as existsSync30, readdirSync as readdirSync6, readFileSync as readFileSync20 } from "node:fs";
40613
- import { join as join22 } from "node:path";
40564
+ import { existsSync as existsSync29, readdirSync as readdirSync6, readFileSync as readFileSync19 } from "node:fs";
40565
+ import { join as join21 } from "node:path";
40614
40566
  import { gunzipSync as gunzipSync2 } from "node:zlib";
40615
40567
  function readPackageVersion(packageJsonPath) {
40616
40568
  try {
40617
- if (!existsSync30(packageJsonPath))
40569
+ if (!existsSync29(packageJsonPath))
40618
40570
  return null;
40619
- const packageJson = JSON.parse(readFileSync20(packageJsonPath, "utf-8"));
40571
+ const packageJson = JSON.parse(readFileSync19(packageJsonPath, "utf-8"));
40620
40572
  if (packageJson.name !== OPENCODE_PLUGIN_NAME || typeof packageJson.version !== "string") {
40621
40573
  return null;
40622
40574
  }
@@ -40635,8 +40587,8 @@ function readFenceValue(text) {
40635
40587
  return values.size === 1 ? [...values][0] ?? null : null;
40636
40588
  }
40637
40589
  function readFenceFromDist(packageDirectory) {
40638
- const distDirectory = join22(packageDirectory, "dist");
40639
- if (!existsSync30(distDirectory))
40590
+ const distDirectory = join21(packageDirectory, "dist");
40591
+ if (!existsSync29(distDirectory))
40640
40592
  return null;
40641
40593
  const pending = [distDirectory];
40642
40594
  const fenceValues = new Set;
@@ -40646,14 +40598,14 @@ function readFenceFromDist(packageDirectory) {
40646
40598
  continue;
40647
40599
  try {
40648
40600
  for (const entry of readdirSync6(directory, { withFileTypes: true })) {
40649
- const path = join22(directory, entry.name);
40601
+ const path = join21(directory, entry.name);
40650
40602
  if (entry.isDirectory()) {
40651
40603
  pending.push(path);
40652
40604
  continue;
40653
40605
  }
40654
40606
  if (!entry.isFile() || !/\.(?:[cm]?js|ts)$/.test(entry.name))
40655
40607
  continue;
40656
- const fence = readFenceValue(readFileSync20(path, "utf-8"));
40608
+ const fence = readFenceValue(readFileSync19(path, "utf-8"));
40657
40609
  if (fence !== null)
40658
40610
  fenceValues.add(fence);
40659
40611
  }
@@ -40664,20 +40616,20 @@ function readFenceFromDist(packageDirectory) {
40664
40616
  return fenceValues.size === 1 ? [...fenceValues][0] ?? null : null;
40665
40617
  }
40666
40618
  function findInstalledPluginPackage(cacheDirectory, specifier, requestedVersion) {
40667
- const directCacheRoot = join22(cacheDirectory, specifier);
40619
+ const directCacheRoot = join21(cacheDirectory, specifier);
40668
40620
  const candidates = [directCacheRoot];
40669
40621
  try {
40670
40622
  for (const entry of readdirSync6(cacheDirectory, { withFileTypes: true })) {
40671
40623
  if (!entry.isDirectory())
40672
40624
  continue;
40673
- const candidate = join22(cacheDirectory, entry.name);
40625
+ const candidate = join21(cacheDirectory, entry.name);
40674
40626
  if (!candidates.includes(candidate))
40675
40627
  candidates.push(candidate);
40676
40628
  }
40677
40629
  } catch {}
40678
40630
  for (const cacheRoot of candidates) {
40679
- const directory = join22(cacheRoot, "node_modules", ...PACKAGE_PATH_SEGMENTS);
40680
- const version = readPackageVersion(join22(directory, "package.json"));
40631
+ const directory = join21(cacheRoot, "node_modules", ...PACKAGE_PATH_SEGMENTS);
40632
+ const version = readPackageVersion(join21(directory, "package.json"));
40681
40633
  if (!version)
40682
40634
  continue;
40683
40635
  if (cacheRoot === directCacheRoot || EXACT_VERSION_PATTERN.test(requestedVersion) && version === requestedVersion) {
@@ -40822,13 +40774,13 @@ var init_opencode_plugin_schema_fence = __esm(async () => {
40822
40774
  });
40823
40775
 
40824
40776
  // src/commands/doctor-opencode-cache.ts
40825
- import { existsSync as existsSync31, readFileSync as readFileSync21, rmSync as rmSync7 } from "node:fs";
40777
+ import { existsSync as existsSync30, readFileSync as readFileSync20, rmSync as rmSync7 } from "node:fs";
40826
40778
  function readCachedPluginVersion(pluginCacheDir) {
40827
40779
  try {
40828
40780
  const installedPkgPath = getOpenCodePluginPackageJsonPath(pluginCacheDir);
40829
- if (!existsSync31(installedPkgPath))
40781
+ if (!existsSync30(installedPkgPath))
40830
40782
  return;
40831
- const pkg = JSON.parse(readFileSync21(installedPkgPath, "utf-8"));
40783
+ const pkg = JSON.parse(readFileSync20(installedPkgPath, "utf-8"));
40832
40784
  return typeof pkg.version === "string" ? pkg.version : undefined;
40833
40785
  } catch {
40834
40786
  return;
@@ -40855,7 +40807,7 @@ function readOpenCodePluginConfigUse(config, configDir) {
40855
40807
  async function clearPluginCache(options = {}, deps = {}) {
40856
40808
  const remove = deps.remove ?? ((path) => rmSync7(path, { recursive: true, force: true }));
40857
40809
  const pluginCacheRoots = getOpenCodePluginCacheRoots();
40858
- const existingRoots = pluginCacheRoots.filter((root) => existsSync31(root));
40810
+ const existingRoots = pluginCacheRoots.filter((root) => existsSync30(root));
40859
40811
  if (existingRoots.length === 0) {
40860
40812
  return { action: "not_found", path: pluginCacheRoots[0] ?? "" };
40861
40813
  }
@@ -40952,7 +40904,7 @@ var init_doctor_opencode_cache = __esm(async () => {
40952
40904
  });
40953
40905
 
40954
40906
  // src/commands/doctor-cached-plugin-fence.ts
40955
- import { existsSync as existsSync32 } from "node:fs";
40907
+ import { existsSync as existsSync31 } from "node:fs";
40956
40908
  import { dirname as dirname18 } from "node:path";
40957
40909
  function isReferenced(sources, host, spec) {
40958
40910
  const specs = sources.referencedSpecs?.[host];
@@ -40963,7 +40915,7 @@ function listCachedOpenCodePluginFences(sources = {}) {
40963
40915
  const v1Referenced = isReferenced(sources, "opencode1", "latest");
40964
40916
  for (const root of v1Referenced ? sources.openCodeV1Roots ?? getOpenCodePluginCacheRoots() : []) {
40965
40917
  const packageJson = getOpenCodePluginPackageJsonPath(root);
40966
- if (!existsSync32(packageJson))
40918
+ if (!existsSync31(packageJson))
40967
40919
  continue;
40968
40920
  fences.push({
40969
40921
  host: "opencode1",
@@ -41168,8 +41120,8 @@ var init_doctor_prune_discovery = __esm(async () => {
41168
41120
 
41169
41121
  // src/commands/doctor-storage-holders.ts
41170
41122
  import { execFileSync as execFileSync5 } from "node:child_process";
41171
- import { readFileSync as readFileSync22, realpathSync as realpathSync6 } from "node:fs";
41172
- import { join as join23, resolve as resolve11 } from "node:path";
41123
+ import { readFileSync as readFileSync21, realpathSync as realpathSync6 } from "node:fs";
41124
+ import { join as join22, resolve as resolve11 } from "node:path";
41173
41125
  function canonicalStoragePath(path) {
41174
41126
  try {
41175
41127
  return realpathSync6(path);
@@ -41186,7 +41138,7 @@ function textReferencesStorage(text, storageDir) {
41186
41138
  continue;
41187
41139
  if (canonicalStoragePath(value) === target)
41188
41140
  return true;
41189
- if (token.startsWith("XDG_DATA_HOME=") && canonicalStoragePath(join23(value, "cortexkit", "magic-context")) === target)
41141
+ if (token.startsWith("XDG_DATA_HOME=") && canonicalStoragePath(join22(value, "cortexkit", "magic-context")) === target)
41190
41142
  return true;
41191
41143
  }
41192
41144
  return false;
@@ -41196,7 +41148,7 @@ function processReferencesStorage(pid, storageDir) {
41196
41148
  if (process.platform === "linux") {
41197
41149
  for (const name of ["cmdline", "environ"]) {
41198
41150
  try {
41199
- texts.push(readFileSync22(`/proc/${pid}/${name}`, "utf8"));
41151
+ texts.push(readFileSync21(`/proc/${pid}/${name}`, "utf8"));
41200
41152
  } catch {}
41201
41153
  }
41202
41154
  } else {
@@ -41218,12 +41170,12 @@ var init_doctor_storage_holders = () => {};
41218
41170
 
41219
41171
  // src/commands/doctor-repair-db.ts
41220
41172
  import { spawnSync as spawnSync4 } from "node:child_process";
41221
- import { closeSync as closeSync4, existsSync as existsSync33, openSync as openSync4, renameSync as renameSync6, rmSync as rmSync8, statSync as statSync16 } from "node:fs";
41173
+ import { closeSync as closeSync4, existsSync as existsSync32, openSync as openSync4, renameSync as renameSync6, rmSync as rmSync8, statSync as statSync16 } from "node:fs";
41222
41174
  import { homedir as homedir17 } from "node:os";
41223
- import { dirname as dirname19, join as join24 } from "node:path";
41175
+ import { dirname as dirname19, join as join23 } from "node:path";
41224
41176
  function defaultInspectHolders(storageDir, overrides = {}) {
41225
41177
  const deps = {
41226
- defaultStorageDir: join24(homedir17(), ".local", "share", "cortexkit", "magic-context"),
41178
+ defaultStorageDir: join23(homedir17(), ".local", "share", "cortexkit", "magic-context"),
41227
41179
  inspectRpc: inspectRpcServerDiscovery,
41228
41180
  inspectPi: inspectLivePiProcesses,
41229
41181
  probeFiles: probeHostProcessesUsing,
@@ -41240,7 +41192,7 @@ function defaultInspectHolders(storageDir, overrides = {}) {
41240
41192
  return {
41241
41193
  safe: false,
41242
41194
  blockers: [],
41243
- uncertainty: `RPC discovery ${rpc.unreadableFile ?? join24(storageDir, "rpc")} ${arm}`
41195
+ uncertainty: `RPC discovery ${rpc.unreadableFile ?? join23(storageDir, "rpc")} ${arm}`
41244
41196
  };
41245
41197
  }
41246
41198
  const blockers = rpc.state === "live" ? rpc.serverPids.map((pid) => `OpenCode server (PID ${pid})`) : [];
@@ -41253,7 +41205,7 @@ function defaultInspectHolders(storageDir, overrides = {}) {
41253
41205
  const pi = overrides.inspectPi ? deps.inspectPi() : processes?.pi ?? deps.inspectPi();
41254
41206
  if (canonicalStoragePath(storageDir) !== canonicalStoragePath(deps.defaultStorageDir)) {
41255
41207
  const holders = deps.probeFiles({
41256
- files: ["context.db", "store.db"].flatMap((name) => DATABASE_SUFFIXES.map((suffix) => join24(storageDir, `${name}${suffix}`))),
41208
+ files: ["context.db", "store.db"].flatMap((name) => DATABASE_SUFFIXES.map((suffix) => join23(storageDir, `${name}${suffix}`))),
41257
41209
  directories: []
41258
41210
  });
41259
41211
  if (holders.status === "unknown") {
@@ -41286,11 +41238,11 @@ function timestamp(date) {
41286
41238
  return date.toISOString().replaceAll("-", "").replaceAll(":", "").replace(".", "");
41287
41239
  }
41288
41240
  function uniqueBase(preferred) {
41289
- if (!DATABASE_SUFFIXES.some((suffix) => existsSync33(`${preferred}${suffix}`)))
41241
+ if (!DATABASE_SUFFIXES.some((suffix) => existsSync32(`${preferred}${suffix}`)))
41290
41242
  return preferred;
41291
41243
  for (let attempt = 1;attempt < 1e4; attempt++) {
41292
41244
  const candidate = `${preferred}-${attempt}`;
41293
- if (!DATABASE_SUFFIXES.some((suffix) => existsSync33(`${candidate}${suffix}`)))
41245
+ if (!DATABASE_SUFFIXES.some((suffix) => existsSync32(`${candidate}${suffix}`)))
41294
41246
  return candidate;
41295
41247
  }
41296
41248
  throw new Error(`Could not allocate a unique recovery path beside ${preferred}`);
@@ -41304,7 +41256,7 @@ function databaseBundleSizeBytes(sourceBase) {
41304
41256
  let size = 0;
41305
41257
  for (const suffix of DATABASE_SUFFIXES) {
41306
41258
  const source = `${sourceBase}${suffix}`;
41307
- if (existsSync33(source))
41259
+ if (existsSync32(source))
41308
41260
  size += statSync16(source).size;
41309
41261
  }
41310
41262
  return size;
@@ -41313,7 +41265,7 @@ function copyDatabaseBundle(sourceBase, destinationBase, forcePrivate = false) {
41313
41265
  const copiedPaths = [];
41314
41266
  for (const suffix of DATABASE_SUFFIXES) {
41315
41267
  const source = `${sourceBase}${suffix}`;
41316
- if (!existsSync33(source))
41268
+ if (!existsSync32(source))
41317
41269
  continue;
41318
41270
  const destination = `${destinationBase}${suffix}`;
41319
41271
  copyStorageFileSync(source, destination, forcePrivate);
@@ -41535,7 +41487,7 @@ function activateReplacement(dbPath, replacementPath, originalAsidePath) {
41535
41487
  try {
41536
41488
  for (const suffix of DATABASE_SUFFIXES) {
41537
41489
  const from = `${dbPath}${suffix}`;
41538
- if (!existsSync33(from))
41490
+ if (!existsSync32(from))
41539
41491
  continue;
41540
41492
  const to = `${originalAsidePath}${suffix}`;
41541
41493
  renameSync6(from, to);
@@ -41545,7 +41497,7 @@ function activateReplacement(dbPath, replacementPath, originalAsidePath) {
41545
41497
  return movedOriginals.map(({ to }) => to);
41546
41498
  } catch (error) {
41547
41499
  for (const moved of movedOriginals.reverse()) {
41548
- if (existsSync33(moved.to) && !existsSync33(moved.from))
41500
+ if (existsSync32(moved.to) && !existsSync32(moved.from))
41549
41501
  renameSync6(moved.to, moved.from);
41550
41502
  }
41551
41503
  throw error;
@@ -41576,12 +41528,12 @@ function printHelp() {
41576
41528
  async function runRepairDb(options = {}) {
41577
41529
  const prompts = options.prompts ?? promptIO;
41578
41530
  const deps = { ...DEFAULT_DEPS3, ...options.deps };
41579
- const storageDir = options.storageDir ?? dirname19(options.dbPath ?? join24(getMagicContextStorageDir(), "context.db"));
41580
- const dbPath = options.dbPath ?? join24(storageDir, "context.db");
41531
+ const storageDir = options.storageDir ?? dirname19(options.dbPath ?? join23(getMagicContextStorageDir(), "context.db"));
41532
+ const dbPath = options.dbPath ?? join23(storageDir, "context.db");
41581
41533
  const stamp = timestamp(deps.now());
41582
41534
  prompts.intro("Magic Context — Repair shared database");
41583
41535
  prompts.log.info(`Database: ${dbPath}`);
41584
- if (!existsSync33(dbPath)) {
41536
+ if (!existsSync32(dbPath)) {
41585
41537
  prompts.log.error(`Database not found: ${dbPath}`);
41586
41538
  prompts.log.info("Backup: not created (database does not exist)");
41587
41539
  prompts.outro("Database repair failed");
@@ -41791,12 +41743,12 @@ var init_doctor_repair_db = __esm(async () => {
41791
41743
 
41792
41744
  // src/commands/doctor-single-store-repair.ts
41793
41745
  import { spawnSync as spawnSync5 } from "node:child_process";
41794
- import { existsSync as existsSync34, statfsSync as statfsSync2, statSync as statSync17 } from "node:fs";
41746
+ import { existsSync as existsSync33, statfsSync as statfsSync2, statSync as statSync17 } from "node:fs";
41795
41747
  import { homedir as homedir18 } from "node:os";
41796
- import { dirname as dirname20, join as join25, resolve as resolve12 } from "node:path";
41748
+ import { dirname as dirname20, join as join24, resolve as resolve12 } from "node:path";
41797
41749
  function existingAncestor(path) {
41798
41750
  let current = resolve12(path);
41799
- while (!existsSync34(current))
41751
+ while (!existsSync33(current))
41800
41752
  current = dirname20(current);
41801
41753
  return current;
41802
41754
  }
@@ -41832,15 +41784,15 @@ function runDoctorSingleStoreRepair(options, overrides = {}) {
41832
41784
  };
41833
41785
  try {
41834
41786
  const { dbPath: context, dbDir: data } = resolveDatabasePath();
41835
- const store = join25(data, "store.db");
41836
- if (!existsSync34(context) || !existsSync34(store))
41787
+ const store = join24(data, "store.db");
41788
+ if (!existsSync33(context) || !existsSync33(store))
41837
41789
  return refuse("repair_missing_database", `Both ${context} and ${store} must exist.`);
41838
41790
  if (!options.fromBackup)
41839
41791
  return refuse("repair_usage", "--from-backup <dir> is required");
41840
41792
  const fromBackup = resolve12(options.fromBackup);
41841
41793
  for (const name of ["context.db", "store.db"])
41842
- if (!existsSync34(join25(fromBackup, name)))
41843
- return refuse("repair_backup_missing", `${join25(fromBackup, name)} does not exist`);
41794
+ if (!existsSync33(join24(fromBackup, name)))
41795
+ return refuse("repair_backup_missing", `${join24(fromBackup, name)} does not exist`);
41844
41796
  const sessions = options.sessions ?? [];
41845
41797
  if (options.live && sessions.length === 0)
41846
41798
  return refuse("repair_usage", "--live repairs named sessions only; pass --session <id>");
@@ -41867,16 +41819,16 @@ function runDoctorSingleStoreRepair(options, overrides = {}) {
41867
41819
  `));
41868
41820
  deps.print(`Repairing while hosts hold the stores (--live): ${blockers.join("; ") || "holders unknown"}`);
41869
41821
  }
41870
- const backupRoot = resolve12(options.backupRoot ?? join25(data, "backups"));
41822
+ const backupRoot = resolve12(options.backupRoot ?? join24(data, "backups"));
41871
41823
  const need = Math.ceil((statSync17(context).size + statSync17(store).size) * 1.1);
41872
41824
  const volume = existingAncestor(backupRoot);
41873
41825
  const have = deps.freeBytes(volume);
41874
41826
  if (have < need)
41875
41827
  return refuse("repair_disk_space", `the backup needs ${need} bytes; have ${have} bytes on ${volume}`);
41876
- backupDir = join25(backupRoot, `repair-history-${deps.now().toISOString().replaceAll(":", "-")}`);
41828
+ backupDir = join24(backupRoot, `repair-history-${deps.now().toISOString().replaceAll(":", "-")}`);
41877
41829
  deps.print(`Backing up the live stores to ${backupDir} before any write.`);
41878
41830
  }
41879
- const binary = options.ckMc ?? join25(homedir18(), ".local", "share", "cortexkit", "bin", "ck-mc");
41831
+ const binary = options.ckMc ?? join24(homedir18(), ".local", "share", "cortexkit", "bin", "ck-mc");
41880
41832
  const args = [
41881
41833
  "single-store-repair-history",
41882
41834
  "--context-db",
@@ -41964,22 +41916,22 @@ var init_doctor_single_store_repair = __esm(async () => {
41964
41916
 
41965
41917
  // src/commands/doctor-single-store.ts
41966
41918
  import { spawnSync as spawnSync6 } from "node:child_process";
41967
- import { existsSync as existsSync35, realpathSync as realpathSync7, statSync as statSync18 } from "node:fs";
41919
+ import { existsSync as existsSync34, realpathSync as realpathSync7, statSync as statSync18 } from "node:fs";
41968
41920
  import { homedir as homedir19 } from "node:os";
41969
- import { join as join26, resolve as resolve13 } from "node:path";
41921
+ import { join as join25, resolve as resolve13 } from "node:path";
41970
41922
  function engineContextPath() {
41971
41923
  const value = (key) => process.env[key]?.trim() || undefined;
41972
41924
  const test = value("MAGIC_CONTEXT_TEST_DATA_DIR");
41973
41925
  const xdg = value("XDG_DATA_HOME");
41974
- const dir = test ? join26(xdg && xdg !== test ? xdg : test, "cortexkit", "magic-context") : value("MAGIC_CONTEXT_STORAGE_DIR") ?? join26(xdg ?? join26(value("HOME") ?? ".", ".local", "share"), "cortexkit", "magic-context");
41975
- return join26(dir, "context.db");
41926
+ const dir = test ? join25(xdg && xdg !== test ? xdg : test, "cortexkit", "magic-context") : value("MAGIC_CONTEXT_STORAGE_DIR") ?? join25(xdg ?? join25(value("HOME") ?? ".", ".local", "share"), "cortexkit", "magic-context");
41927
+ return join25(dir, "context.db");
41976
41928
  }
41977
41929
  function undo(backup, data, print) {
41978
41930
  const quote = (s) => `'${s.replaceAll("'", "'\\''")}'`;
41979
41931
  print(`Backup: ${backup}`);
41980
41932
  print("To undo: quit every host, then");
41981
- print(` rm -f ${["context.db-wal", "context.db-shm", "store.db-wal", "store.db-shm"].map((name) => quote(join26(data, name))).join(" ")}`);
41982
- print(` cp ${quote(join26(backup, "context.db"))} ${quote(join26(backup, "store.db"))} ${quote(data + "/")}`);
41933
+ print(` rm -f ${["context.db-wal", "context.db-shm", "store.db-wal", "store.db-shm"].map((name) => quote(join25(data, name))).join(" ")}`);
41934
+ print(` cp ${quote(join25(backup, "context.db"))} ${quote(join25(backup, "store.db"))} ${quote(data + "/")}`);
41983
41935
  print("This restores the unmigrated stores. Keep the current plugin and ck-mc: TypeScript mode works as before, and Rust mode will refuse with MC-C14 until you run this command again.");
41984
41936
  }
41985
41937
  function runDoctorSingleStore(options = {}, overrides = {}) {
@@ -41997,8 +41949,8 @@ function runDoctorSingleStore(options = {}, overrides = {}) {
41997
41949
  };
41998
41950
  try {
41999
41951
  const { dbPath: context, dbDir: data } = resolveDatabasePath();
42000
- const store = join26(data, "store.db");
42001
- if (!existsSync35(context) || !existsSync35(store))
41952
+ const store = join25(data, "store.db");
41953
+ if (!existsSync34(context) || !existsSync34(store))
42002
41954
  return refuse("single_store_missing_database", `Both ${context} and ${store} must exist.`);
42003
41955
  const probe = probeHostProcessesUsing({ files: [context, store].flatMap((p) => SUFFIXES2.map((s) => p + s)), directories: [] }, deps.lsofSpawn);
42004
41956
  const holders = deps.inspectHolders(data);
@@ -42013,9 +41965,9 @@ function runDoctorSingleStore(options = {}, overrides = {}) {
42013
41965
  return refuse("single_store_files_in_use", [...lines, STOP].join(`
42014
41966
  `));
42015
41967
  }
42016
- if (!existsSync35(engineContextPath()) || realpathSync7(context) !== realpathSync7(engineContextPath()))
41968
+ if (!existsSync34(engineContextPath()) || realpathSync7(context) !== realpathSync7(engineContextPath()))
42017
41969
  return refuse("single_store_path_mismatch", `CLI ${context}; engine ${engineContextPath()}`);
42018
- const backupRoot = resolve13(options.backupRoot ?? join26(data, "backups"));
41970
+ const backupRoot = resolve13(options.backupRoot ?? join25(data, "backups"));
42019
41971
  const contextDb = openExistingDatabase(context, { readonly: true });
42020
41972
  if (!contextDb)
42021
41973
  return refuse("single_store_missing_database", `Database disappeared: ${context}`);
@@ -42057,7 +42009,7 @@ function runDoctorSingleStore(options = {}, overrides = {}) {
42057
42009
  const backupSpace = sameVolume ? undefined : checkDiskSpace(backupVolume, backupBytes, deps.freeBytes);
42058
42010
  if (backupSpace && !backupSpace.sufficient)
42059
42011
  return refuse("single_store_disk_space", `backup needs ${backupSpace.requiredBytes} bytes; have ${backupSpace.availableBytes} bytes on ${backupVolume}`);
42060
- const backupDir = join26(backupRoot, `single-store-${deps.now().toISOString().replaceAll(":", "-")}`);
42012
+ const backupDir = join25(backupRoot, `single-store-${deps.now().toISOString().replaceAll(":", "-")}`);
42061
42013
  undo(backupDir, data, deps.print);
42062
42014
  const opened = openDatabase(context);
42063
42015
  if (!opened)
@@ -42069,7 +42021,7 @@ function runDoctorSingleStore(options = {}, overrides = {}) {
42069
42021
  }
42070
42022
  if (contextVersion !== LATEST_SUPPORTED_VERSION)
42071
42023
  return refuse("single_store_version_mismatch", `context.db v${contextVersion}; store.db v${storeVersion}`);
42072
- const binary = options.ckMc ?? join26(homedir19(), ".local", "share", "cortexkit", "bin", "ck-mc");
42024
+ const binary = options.ckMc ?? join25(homedir19(), ".local", "share", "cortexkit", "bin", "ck-mc");
42073
42025
  const args = [
42074
42026
  "single-store-migrate",
42075
42027
  "--context-db",
@@ -42561,15 +42513,15 @@ var init_storage_identity_merge = __esm(() => {
42561
42513
  // src/commands/doctor-identity-splits.ts
42562
42514
  import { execFileSync as execFileSync6 } from "node:child_process";
42563
42515
  import { createHash as createHash6 } from "node:crypto";
42564
- import { existsSync as existsSync36, readdirSync as readdirSync7, realpathSync as realpathSync8, statSync as statSync19 } from "node:fs";
42565
- import { dirname as dirname21, join as join27, resolve as resolve14 } from "node:path";
42516
+ import { existsSync as existsSync35, readdirSync as readdirSync7, realpathSync as realpathSync8, statSync as statSync19 } from "node:fs";
42517
+ import { dirname as dirname21, join as join26, resolve as resolve14 } from "node:path";
42566
42518
  function tableExists5(db, table) {
42567
42519
  return !!db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table);
42568
42520
  }
42569
42521
  function hasGitMetadataInAncestors(directory) {
42570
42522
  let current = resolve14(directory);
42571
42523
  while (true) {
42572
- if (existsSync36(join27(current, ".git")))
42524
+ if (existsSync35(join26(current, ".git")))
42573
42525
  return true;
42574
42526
  const parent = dirname21(current);
42575
42527
  if (parent === current)
@@ -42724,7 +42676,7 @@ function identityLines(split) {
42724
42676
  return split.identities.map((row) => ` ${row.identity}: ${row.sessions} sessions, ${row.memories} memories, ${row.notes} notes, ${row.dreamer} dreamer rows (identity-wide counts)`);
42725
42677
  }
42726
42678
  function diagnoseIdentitySplits() {
42727
- const db = openExistingContextDatabase(join27(getMagicContextStorageDir(), "context.db"), {
42679
+ const db = openExistingContextDatabase(join26(getMagicContextStorageDir(), "context.db"), {
42728
42680
  readonly: true
42729
42681
  });
42730
42682
  if (!db)
@@ -42750,8 +42702,8 @@ var init_doctor_identity_splits = __esm(async () => {
42750
42702
  // src/commands/doctor-merge-identity.ts
42751
42703
  import { execFileSync as execFileSync7 } from "node:child_process";
42752
42704
  import { createHash as createHash7 } from "node:crypto";
42753
- import { existsSync as existsSync37, mkdtempSync as mkdtempSync2, readdirSync as readdirSync8, readFileSync as readFileSync23, statSync as statSync20 } from "node:fs";
42754
- import { dirname as dirname22, join as join28, resolve as resolve15 } from "node:path";
42705
+ import { existsSync as existsSync36, mkdtempSync as mkdtempSync2, readdirSync as readdirSync8, readFileSync as readFileSync22, statSync as statSync20 } from "node:fs";
42706
+ import { dirname as dirname22, join as join27, resolve as resolve15 } from "node:path";
42755
42707
  function parseMergeIdentityArgs(args) {
42756
42708
  const values = {};
42757
42709
  const switches = new Set(["--apply", "--force", "--dry-run", "--yes", "--verbose"]);
@@ -42801,7 +42753,7 @@ function printReport(report) {
42801
42753
  console.log(" No writes. Review this preview, then repeat with --apply to confirm.");
42802
42754
  }
42803
42755
  function resolveReadOnly(directory) {
42804
- if (!existsSync37(directory))
42756
+ if (!existsSync36(directory))
42805
42757
  return;
42806
42758
  try {
42807
42759
  const roots = execFileSync7("git", ["rev-list", "--max-parents=0", "HEAD"], {
@@ -42957,13 +42909,13 @@ function observations(db, hostPath, storageDir) {
42957
42909
  if (!row.identities.some((item) => item.identity === identity))
42958
42910
  row.identities.push({ identity, sessions: 0, memories: 0, notes: 0, dreamer: 0 });
42959
42911
  };
42960
- const sidecars = join28(storageDir, "project-identities");
42961
- if (existsSync37(sidecars))
42912
+ const sidecars = join27(storageDir, "project-identities");
42913
+ if (existsSync36(sidecars))
42962
42914
  for (const file of readdirSync8(sidecars)) {
42963
42915
  if (!file.endsWith(".json"))
42964
42916
  continue;
42965
42917
  try {
42966
- const record = JSON.parse(readFileSync23(join28(sidecars, file), "utf8"));
42918
+ const record = JSON.parse(readFileSync22(join27(sidecars, file), "utf8"));
42967
42919
  if (typeof record.directory === "string" && typeof record.identity === "string")
42968
42920
  add(record.directory, record.identity);
42969
42921
  } catch {}
@@ -42974,9 +42926,9 @@ function observations(db, hostPath, storageDir) {
42974
42926
  }
42975
42927
  function runMergeIdentityCli(args, deps = {}) {
42976
42928
  const options = parseMergeIdentityArgs(args);
42977
- const dbPath = options.dbPath ?? join28(getMagicContextStorageDir(), "context.db");
42929
+ const dbPath = options.dbPath ?? join27(getMagicContextStorageDir(), "context.db");
42978
42930
  const storageDir = dirname22(dbPath);
42979
- const hostPath = options.hostPath ?? (options.dbPath ? join28(storageDir, "host.db") : resolveOpenCodeDbPath().path);
42931
+ const hostPath = options.hostPath ?? (options.dbPath ? join27(storageDir, "host.db") : resolveOpenCodeDbPath().path);
42980
42932
  let db = openExistingContextDatabase(dbPath, {
42981
42933
  readonly: true,
42982
42934
  minimumSupportedVersion: CLI_SCHEMA_FLOOR_VERSION
@@ -43029,27 +42981,27 @@ function runMergeIdentityCli(args, deps = {}) {
43029
42981
  throw new Error(`Refusing merge: close OpenCode, Pi, OpenCode 2 and ck-mc. ${holders.blockers.join(", ")} ${holders.uncertainty ?? ""} ${probe.status === "in_use" ? `context.db holders: ${probe.pids.join(", ")}` : probe.status === "unknown" ? probe.reason : ""}`);
43030
42982
  const backupRoot = resolve15(options.backupRoot ?? storageDir);
43031
42983
  const backupVolume = existingDirectoryAncestor(backupRoot);
43032
- const sidecarRoot = join28(storageDir, "project-identities");
43033
- const sidecarEntries = existsSync37(sidecarRoot) ? readdirSync8(sidecarRoot).filter((entry) => entry.endsWith(".json")) : [];
43034
- const sidecarBytes = sidecarEntries.reduce((size, entry) => size + statSync20(join28(sidecarRoot, entry)).size, 0);
42984
+ const sidecarRoot = join27(storageDir, "project-identities");
42985
+ const sidecarEntries = existsSync36(sidecarRoot) ? readdirSync8(sidecarRoot).filter((entry) => entry.endsWith(".json")) : [];
42986
+ const sidecarBytes = sidecarEntries.reduce((size, entry) => size + statSync20(join27(sidecarRoot, entry)).size, 0);
43035
42987
  const diskSpace = checkDiskSpace(backupVolume, databaseBundleSizeBytes(dbPath) + sidecarBytes, deps.freeBytes ?? availableDiskBytes);
43036
42988
  if (!diskSpace.sufficient)
43037
42989
  throw new Error(`merge_identity_disk_space: refusing identity merge: backup needs ${diskSpace.requiredBytes} bytes; have ${diskSpace.availableBytes} bytes on ${backupVolume}. Use --backup-root <dir> to choose a volume with enough free space.`);
43038
42990
  ensureStorageDirectorySync(backupRoot, true);
43039
- const backup = mkdtempSync2(join28(backupRoot, "identity-merge-backup-"));
42991
+ const backup = mkdtempSync2(join27(backupRoot, "identity-merge-backup-"));
43040
42992
  const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
43041
42993
  console.log(`Backup directory: ${backup}`);
43042
- console.log(`Restore with hosts closed: rm -f ${quote(`${dbPath}-wal`)} ${quote(`${dbPath}-shm`)}; cp ${quote(join28(backup, "context.db"))} ${quote(dbPath)}; if test -f ${quote(join28(backup, "context.db-wal"))}; then cp ${quote(join28(backup, "context.db-wal"))} ${quote(`${dbPath}-wal`)}; fi`);
43043
- const sidecarBackup = join28(backup, "project-identities");
42994
+ console.log(`Restore with hosts closed: rm -f ${quote(`${dbPath}-wal`)} ${quote(`${dbPath}-shm`)}; cp ${quote(join27(backup, "context.db"))} ${quote(dbPath)}; if test -f ${quote(join27(backup, "context.db-wal"))}; then cp ${quote(join27(backup, "context.db-wal"))} ${quote(`${dbPath}-wal`)}; fi`);
42995
+ const sidecarBackup = join27(backup, "project-identities");
43044
42996
  ensureStorageDirectorySync(sidecarBackup, true);
43045
42997
  let backupBytes = 0;
43046
42998
  for (const entry of sidecarEntries) {
43047
- const content = readFileSync23(join28(sidecarRoot, entry));
43048
- writeStorageFileAtomicSync(join28(sidecarBackup, entry), content, true);
42999
+ const content = readFileSync22(join27(sidecarRoot, entry));
43000
+ writeStorageFileAtomicSync(join27(sidecarBackup, entry), content, true);
43049
43001
  backupBytes += content.byteLength;
43050
43002
  }
43051
43003
  console.log(`Restore identity sidecars too: rm -rf ${quote(sidecarRoot)}; cp -R ${quote(sidecarBackup)} ${quote(sidecarRoot)}`);
43052
- const copiedDatabaseFiles = copyDatabaseBundle(dbPath, join28(backup, "context.db"), true);
43004
+ const copiedDatabaseFiles = copyDatabaseBundle(dbPath, join27(backup, "context.db"), true);
43053
43005
  backupBytes += copiedDatabaseFiles.reduce((size, path) => size + statSync20(path).size, 0);
43054
43006
  db = openExistingDatabase(dbPath, { readonly: false });
43055
43007
  if (!db)
@@ -43068,9 +43020,9 @@ function runMergeIdentityCli(args, deps = {}) {
43068
43020
  }
43069
43021
  if (to.startsWith("git:"))
43070
43022
  for (const directory of directories) {
43071
- const root = join28(storageDir, "project-identities");
43023
+ const root = join27(storageDir, "project-identities");
43072
43024
  ensureStorageDirectorySync(root);
43073
- const path = join28(root, `${createHash7("sha256").update(projectDirectoryKey(directory)).digest("hex")}.json`);
43025
+ const path = join27(root, `${createHash7("sha256").update(projectDirectoryKey(directory)).digest("hex")}.json`);
43074
43026
  writeStorageFileAtomicSync(path, JSON.stringify({ directory: projectDirectoryKey(directory), identity: options.to }));
43075
43027
  }
43076
43028
  console.log(`Backup: ${backup} (${backupBytes} bytes)`);
@@ -43094,8 +43046,8 @@ var init_doctor_merge_identity = __esm(async () => {
43094
43046
  });
43095
43047
 
43096
43048
  // src/commands/doctor-git-fts-map.ts
43097
- import { existsSync as existsSync38, mkdtempSync as mkdtempSync3, statSync as statSync21 } from "node:fs";
43098
- import { join as join29, resolve as resolve16 } from "node:path";
43049
+ import { existsSync as existsSync37, mkdtempSync as mkdtempSync3, statSync as statSync21 } from "node:fs";
43050
+ import { join as join28, resolve as resolve16 } from "node:path";
43099
43051
  function inspectGitFtsMap(db) {
43100
43052
  const has = (name) => Boolean(db.prepare("SELECT 1 FROM sqlite_master WHERE name=? AND type='table'").get(name));
43101
43053
  const indexed = has("git_commits_fts");
@@ -43148,8 +43100,8 @@ function runDoctorGitFtsMap(options = {}, overrides = {}) {
43148
43100
  verify: verifyInventory,
43149
43101
  ...overrides
43150
43102
  };
43151
- const context = join29(deps.storageDir, "context.db");
43152
- const store = join29(deps.storageDir, "store.db");
43103
+ const context = join28(deps.storageDir, "context.db");
43104
+ const store = join28(deps.storageDir, "store.db");
43153
43105
  let db = null, storeDb = null;
43154
43106
  let contextLocked = false, storeLocked = false;
43155
43107
  try {
@@ -43171,7 +43123,7 @@ function runDoctorGitFtsMap(options = {}, overrides = {}) {
43171
43123
  deps.print(`Stop every host, then run \`${GIT_FTS_MAP_REPAIR_COMMAND}\`. The repair backs up context.db and store.db first.`);
43172
43124
  return damaged ? 1 : 0;
43173
43125
  }
43174
- if (!existsSync38(context) || !existsSync38(store))
43126
+ if (!existsSync37(context) || !existsSync37(store))
43175
43127
  throw new Error("Both context.db and store.db must exist before paired-backup repair; no replacement store will be created");
43176
43128
  const cstat = statSync21(context), sstat = statSync21(store);
43177
43129
  if (cstat.dev === sstat.dev && cstat.ino === sstat.ino)
@@ -43201,12 +43153,12 @@ function runDoctorGitFtsMap(options = {}, overrides = {}) {
43201
43153
  const stillFree = deps.inspectHolders(deps.storageDir);
43202
43154
  if (!stillFree.safe)
43203
43155
  throw new Error(`A host appeared before backup: ${[...stillFree.blockers, stillFree.uncertainty].filter(Boolean).join("; ")}`);
43204
- const backupRoot = resolve16(options.backupRoot ?? join29(deps.storageDir, "backups"));
43156
+ const backupRoot = resolve16(options.backupRoot ?? join28(deps.storageDir, "backups"));
43205
43157
  ensureStorageDirectorySync(backupRoot, true);
43206
- const backup = mkdtempSync3(join29(backupRoot, "git-fts-map-"));
43207
- snapshot(context, join29(backup, "context.db"));
43208
- snapshot(store, join29(backup, "store.db"));
43209
- writeStorageFileSync(join29(backup, "manifest.json"), JSON.stringify({
43158
+ const backup = mkdtempSync3(join28(backupRoot, "git-fts-map-"));
43159
+ snapshot(context, join28(backup, "context.db"));
43160
+ snapshot(store, join28(backup, "store.db"));
43161
+ writeStorageFileSync(join28(backup, "manifest.json"), JSON.stringify({
43210
43162
  contextVersion: version,
43211
43163
  createdAt: new Date().toISOString(),
43212
43164
  repair: "git-fts-map",
@@ -43374,19 +43326,19 @@ var SINGLE_STORE_REQUIRED = "Magic Context's Rust mode needs a one-time migratio
43374
43326
 
43375
43327
  // src/commands/migrate.ts
43376
43328
  import { createHash as createHash8, randomBytes as randomBytes3 } from "node:crypto";
43377
- import { existsSync as existsSync39, mkdirSync as mkdirSync7, renameSync as renameSync7, unlinkSync as unlinkSync4 } from "node:fs";
43378
- import { dirname as dirname23, join as join30 } from "node:path";
43329
+ import { existsSync as existsSync38, mkdirSync as mkdirSync7, renameSync as renameSync7, unlinkSync as unlinkSync5 } from "node:fs";
43330
+ import { dirname as dirname23, join as join29 } from "node:path";
43379
43331
  function defaultOpenCodeDbPath() {
43380
43332
  return getOpenCodeDatabasePath();
43381
43333
  }
43382
43334
  function defaultCortexkitDbPath() {
43383
- return join30(getMagicContextStorageDir(), "context.db");
43335
+ return join29(getMagicContextStorageDir(), "context.db");
43384
43336
  }
43385
43337
  function defaultPiSessionsRoot() {
43386
43338
  return getPiSessionsRoot();
43387
43339
  }
43388
43340
  function defaultFs() {
43389
- return { writeFileAtomic, unlinkSync: unlinkSync4, existsSync: existsSync39, renameSync: renameSync7, mkdirSync: mkdirSync7 };
43341
+ return { writeFileAtomic, unlinkSync: unlinkSync5, existsSync: existsSync38, renameSync: renameSync7, mkdirSync: mkdirSync7 };
43390
43342
  }
43391
43343
  function stmt(db, sql) {
43392
43344
  return db.prepare(sql);
@@ -43470,7 +43422,7 @@ function claimJournalIdentity(args) {
43470
43422
  migration_key, source_session_id, target_harness, pi_session_id,
43471
43423
  final_path, stage_path, content_sha256, phase, created_at
43472
43424
  ) VALUES (?, ?, ?, ?, ?, ?, '', 'staged', ?)
43473
- ON CONFLICT(migration_key) DO NOTHING`).run(args.migrationKey, args.sourceSessionId, args.targetHarness, piSessionId, args.finalPathFor(piSessionId), join30(args.stageDir, `${args.migrationKey}.jsonl`), args.now);
43425
+ ON CONFLICT(migration_key) DO NOTHING`).run(args.migrationKey, args.sourceSessionId, args.targetHarness, piSessionId, args.finalPathFor(piSessionId), join29(args.stageDir, `${args.migrationKey}.jsonl`), args.now);
43474
43426
  const row = readPendingMigration(args.db, args.migrationKey);
43475
43427
  if (!row) {
43476
43428
  throw new Error("migration journal row disappeared during insert; aborting migration");
@@ -43978,7 +43930,7 @@ function migrateOpenCodeSessionToPi(opts) {
43978
43930
  const provider = opts.provider ?? model.provider;
43979
43931
  const modelId = opts.modelId ?? model.modelId;
43980
43932
  const cwd = session.directory ?? session.path ?? process.cwd();
43981
- const outputDir = join30(piSessionsRoot, projectPathToPiDirSlug(cwd));
43933
+ const outputDir = join29(piSessionsRoot, projectPathToPiDirSlug(cwd));
43982
43934
  const targetHarness = opts.targetHarness ?? "pi";
43983
43935
  if (cortexkitDb !== null) {
43984
43936
  assertNoUnmigratedAuthority(cortexkitDb);
@@ -44005,8 +43957,8 @@ function migrateOpenCodeSessionToPi(opts) {
44005
43957
  migrationKey,
44006
43958
  sourceSessionId: session.id,
44007
43959
  targetHarness,
44008
- finalPathFor: (id) => join30(outputDir, `${formatPiFilenameTimestamp(now)}_${id}.jsonl`),
44009
- stageDir: join30(dirname23(piSessionsRoot), MIGRATION_STAGE_DIRNAME),
43960
+ finalPathFor: (id) => join29(outputDir, `${formatPiFilenameTimestamp(now)}_${id}.jsonl`),
43961
+ stageDir: join29(dirname23(piSessionsRoot), MIGRATION_STAGE_DIRNAME),
44010
43962
  now: now.getTime()
44011
43963
  });
44012
43964
  piSessionId = claimed.row.pi_session_id;
@@ -44015,7 +43967,7 @@ function migrateOpenCodeSessionToPi(opts) {
44015
43967
  journalResumed = claimed.resumed;
44016
43968
  } else {
44017
43969
  piSessionId = generateUuidV7(now);
44018
- finalPath = join30(outputDir, `${formatPiFilenameTimestamp(now)}_${piSessionId}.jsonl`);
43970
+ finalPath = join29(outputDir, `${formatPiFilenameTimestamp(now)}_${piSessionId}.jsonl`);
44019
43971
  stagePath = "";
44020
43972
  }
44021
43973
  const buildResult = buildPiEntries({
@@ -46364,12 +46316,12 @@ var init_store_ahead_refusal = __esm(() => {
46364
46316
 
46365
46317
  // ../plugin/src/hooks/magic-context/module-transport.ts
46366
46318
  import { realpathSync as realpathSync9 } from "node:fs";
46367
- import { join as join31 } from "node:path";
46319
+ import { join as join30 } from "node:path";
46368
46320
  function monotonicNow() {
46369
46321
  return monotonicClockForTests?.() ?? performance.now();
46370
46322
  }
46371
46323
  function getDefaultSubcConnectionFile() {
46372
- return join31(getDataDir(), "cortexkit", "run", "subc-connection.json");
46324
+ return join30(getDataDir(), "cortexkit", "run", "subc-connection.json");
46373
46325
  }
46374
46326
  function errorChainSome(error, predicate) {
46375
46327
  let current = error;
@@ -46978,9 +46930,9 @@ var init_module_transport = __esm(async () => {
46978
46930
  });
46979
46931
 
46980
46932
  // src/commands/migrate-session.ts
46981
- import { existsSync as existsSync40, realpathSync as realpathSync10 } from "node:fs";
46933
+ import { existsSync as existsSync39, realpathSync as realpathSync10 } from "node:fs";
46982
46934
  import { homedir as homedir20 } from "node:os";
46983
- import path7, { join as join32 } from "node:path";
46935
+ import path7, { join as join31 } from "node:path";
46984
46936
  function existingSessionColumns(db) {
46985
46937
  const rows = db.prepare("PRAGMA table_info(session)").all();
46986
46938
  return new Set(rows.map((r) => r.name).filter((n) => typeof n === "string"));
@@ -47161,14 +47113,14 @@ function defaultOpenCodeDbPath2() {
47161
47113
  return getOpenCodeDatabasePath();
47162
47114
  }
47163
47115
  function defaultContextDbPath() {
47164
- return join32(getMagicContextStorageDir(), "context.db");
47116
+ return join31(getMagicContextStorageDir(), "context.db");
47165
47117
  }
47166
47118
  function realDeps(opencodeDb, contextDb) {
47167
47119
  return {
47168
47120
  opencodeDb,
47169
47121
  contextDb,
47170
47122
  resolveIdentity: resolveProjectIdentity,
47171
- hasGitDir: (dir) => existsSync40(join32(dir, ".git")),
47123
+ hasGitDir: (dir) => existsSync39(join31(dir, ".git")),
47172
47124
  realpath: (p) => realpathSync10(p)
47173
47125
  };
47174
47126
  }
@@ -47246,8 +47198,8 @@ async function runMigrateSessionCli(args) {
47246
47198
  printMigrateSessionHelp();
47247
47199
  return 1;
47248
47200
  }
47249
- const expandedTo = toDir.startsWith("~") ? join32(homedir20(), toDir.slice(1).replace(/^[/\\]/, "")) : toDir;
47250
- if (!existsSync40(expandedTo)) {
47201
+ const expandedTo = toDir.startsWith("~") ? join31(homedir20(), toDir.slice(1).replace(/^[/\\]/, "")) : toDir;
47202
+ if (!existsSync39(expandedTo)) {
47251
47203
  console.error(`Target directory does not exist: ${expandedTo}`);
47252
47204
  return 1;
47253
47205
  }
@@ -47670,7 +47622,7 @@ var init_tick_failure = __esm(() => {
47670
47622
  });
47671
47623
 
47672
47624
  // ../pi-plugin/src/config/index.ts
47673
- import { existsSync as existsSync41 } from "node:fs";
47625
+ import { existsSync as existsSync40 } from "node:fs";
47674
47626
  function getProjectConfigPaths(cwd) {
47675
47627
  const basePath = cortexKitProjectConfigBasePath(cwd);
47676
47628
  return [`${basePath}.jsonc`, `${basePath}.json`];
@@ -47680,10 +47632,10 @@ function getUserConfigPaths() {
47680
47632
  return [`${basePath}.jsonc`, `${basePath}.json`];
47681
47633
  }
47682
47634
  function resolveFirstExisting(paths) {
47683
- return paths.find((path) => existsSync41(path));
47635
+ return paths.find((path) => existsSync40(path));
47684
47636
  }
47685
47637
  function resolvePiLegacyFallback(sources) {
47686
- return sources.find((source) => existsSync41(source.path)) ?? null;
47638
+ return sources.find((source) => existsSync40(source.path)) ?? null;
47687
47639
  }
47688
47640
  function loadConfigFile(path, scope) {
47689
47641
  let raw;
@@ -47997,7 +47949,7 @@ function loadPiConfigDetailed(opts = {}, applyRuntimeGlobals = true) {
47997
47949
  if (loaded)
47998
47950
  loadedFiles.push(loaded);
47999
47951
  }
48000
- const legacyProjectUnmigrated = !projectPath && !projectLegacyFallback && legacySources.project.some((source) => existsSync41(source.path));
47952
+ const legacyProjectUnmigrated = !projectPath && !projectLegacyFallback && legacySources.project.some((source) => existsSync40(source.path));
48001
47953
  const userPath = resolveFirstExisting(getUserConfigPaths());
48002
47954
  const userLegacyFallback = userPath ? null : resolvePiLegacyFallback(harnessLegacy.user);
48003
47955
  const userReadPath = userPath ?? userLegacyFallback?.path;
@@ -48006,7 +47958,7 @@ function loadPiConfigDetailed(opts = {}, applyRuntimeGlobals = true) {
48006
47958
  if (loaded)
48007
47959
  loadedFiles.push(loaded);
48008
47960
  }
48009
- const legacyUserUnmigrated = !userPath && !userLegacyFallback && legacySources.user.some((source) => existsSync41(source.path));
47961
+ const legacyUserUnmigrated = !userPath && !userLegacyFallback && legacySources.user.some((source) => existsSync40(source.path));
48010
47962
  if (userLegacyFallback) {
48011
47963
  warnings.push(`[user config] reading legacy config from ${userLegacyFallback.path} until migration completes; run \`npx @cortexkit/magic-context doctor\` to consolidate into the shared CortexKit location.`);
48012
47964
  } else if (legacyUserUnmigrated) {
@@ -48151,7 +48103,7 @@ var DATABASE_REPAIR_COMMAND = "bunx @cortexkit/magic-context@latest doctor repai
48151
48103
 
48152
48104
  // src/lib/github-issue.ts
48153
48105
  import { spawnSync as spawnSync7 } from "node:child_process";
48154
- import { readFileSync as readFileSync24 } from "node:fs";
48106
+ import { readFileSync as readFileSync23 } from "node:fs";
48155
48107
  function runGhCommand(args) {
48156
48108
  try {
48157
48109
  const result = spawnSync7("gh", args, {
@@ -48178,7 +48130,7 @@ function failed(result) {
48178
48130
  function submitGithubIssue(title, bodyPath, runner = runGhCommand) {
48179
48131
  let body;
48180
48132
  try {
48181
- body = readFileSync24(bodyPath, "utf-8");
48133
+ body = readFileSync23(bodyPath, "utf-8");
48182
48134
  } catch (error) {
48183
48135
  return {
48184
48136
  ok: false,
@@ -48591,7 +48543,6 @@ var init_issue_log_templates_generated = __esm(() => {
48591
48543
  "[magic-context] host stall profiler enabled: threshold \x01ms, sample interval \x01ms, backend v8, rotation \x01ms, reports in \x01",
48592
48544
  "rust transform deferred; the module is still applying an earlier transform of this session; attempting LKG replay: \x01",
48593
48545
  "[magic-context] WARN: workspace member has no workspace share_categories row; sharing no foreign memory categories",
48594
- "compartment trigger: force_band skipped — raw exists but protected head genuinely empty after emergency tail scale",
48595
48546
  "rust transform deferred; the module is still applying an earlier transform of this session; attempting LKG replay:",
48596
48547
  "prefix trim: boundary \x01; pass=defer; no in-pass trim applied (Hidden child first step requires a registered marker)",
48597
48548
  "[magic-context] [ERROR] compaction-marker: candidate worker unavailable \x01: \x01; marker unchanged, advancement deferred\x020p",
@@ -48632,6 +48583,7 @@ var init_issue_log_templates_generated = __esm(() => {
48632
48583
  "compartment injection entering degraded mode: boundary \x01 not in visible messages (consecutive degraded passes: \x01)\x021s",
48633
48584
  "auto-search: decision outcome=timeout lanes=\x01 nearMisses=\x01 threshold=\x01 pool=\x01 rows=\x01 workerStarted=\x01 peek=\x01 elapsedMs=\x01",
48634
48585
  "[auto-update-checker] Explicit @latest leaves the active package unpinned; OpenCode may delete it mid-session.",
48586
+ "compartment trigger: force_band skipped — no protected head meets summary admission after emergency tail scale",
48635
48587
  "historian: refusing to publish over a stale protected-tail snapshot (was: \x01); ending the run without publishing",
48636
48588
  "ERROR: compaction marker disabled: incompatible host binding harness=\x01 arity=\x01 getEntry=\x01; leaving marker pending",
48637
48589
  "heuristic cleanup: dropped \x01 tool tags, stale ctx_reduce=\x01, deduplicated \x01 tool calls, dropped \x01 system injections",
@@ -50409,6 +50361,7 @@ var init_issue_log_templates_generated = __esm(() => {
50409
50361
  "channel2 delivery wrapper failed (ignored): \x01",
50410
50362
  "channel2 fold-cycle reset failed (ignored): \x01",
50411
50363
  "channel2 U-collapse reset failed (ignored): \x01",
50364
+ "Failed to ensure project artifact gitignore \x01",
50412
50365
  "lkg_fit_basis=provider_input measured_input=\x01",
50413
50366
  "mc-module: aborting historian trigger for \x01: \x01",
50414
50367
  "Pi note-nudge delivery skipped wire append: \x01",
@@ -50424,6 +50377,7 @@ var init_issue_log_templates_generated = __esm(() => {
50424
50377
  "channel2 delivery wrapper failed (ignored):",
50425
50378
  "channel2 fold-cycle reset failed (ignored):",
50426
50379
  "channel2 U-collapse reset failed (ignored):",
50380
+ "Failed to ensure project artifact gitignore",
50427
50381
  "historian skip: internal drain budget spent",
50428
50382
  "historian trigger eval: in-flight, skipping",
50429
50383
  "historian two-pass: running editor on draft",
@@ -51221,9 +51175,9 @@ var init_issue_log_templates_generated = __esm(() => {
51221
51175
  });
51222
51176
 
51223
51177
  // src/lib/log-lines.ts
51224
- import { existsSync as existsSync42, readFileSync as readFileSync25, statSync as statSync22 } from "node:fs";
51178
+ import { existsSync as existsSync41, readFileSync as readFileSync24, statSync as statSync22 } from "node:fs";
51225
51179
  import { tmpdir as tmpdir3 } from "node:os";
51226
- import { join as join33 } from "node:path";
51180
+ import { join as join32 } from "node:path";
51227
51181
  function tokenize(input, limit = Number.POSITIVE_INFINITY) {
51228
51182
  const tokens = [];
51229
51183
  let index = 0;
@@ -51509,20 +51463,20 @@ function parseLogLine(line) {
51509
51463
  }
51510
51464
  function getMagicContextLogPaths(harness, options = {}) {
51511
51465
  const override = options.override === undefined ? process.env.MAGIC_CONTEXT_LOG_PATH?.trim() : options.override?.trim();
51512
- const storageLogs = join33(options.storageDir ?? getMagicContextStorageDir(), "logs");
51466
+ const storageLogs = join32(options.storageDir ?? getMagicContextStorageDir(), "logs");
51513
51467
  return [
51514
51468
  ...override ? [override] : [],
51515
- join33(options.tempDir ?? tmpdir3(), harness, "magic-context", "magic-context.log"),
51516
- join33(storageLogs, `magic-context.${harness}.log`),
51517
- join33(storageLogs, "magic-context.log")
51469
+ join32(options.tempDir ?? tmpdir3(), harness, "magic-context", "magic-context.log"),
51470
+ join32(storageLogs, `magic-context.${harness}.log`),
51471
+ join32(storageLogs, "magic-context.log")
51518
51472
  ].filter((path, index, paths) => paths.indexOf(path) === index);
51519
51473
  }
51520
51474
  function inspectLogFile(path) {
51521
- if (!existsSync42(path)) {
51475
+ if (!existsSync41(path)) {
51522
51476
  return { path, exists: false, sizeKb: 0, lineCount: 0, grammar: "unknown" };
51523
51477
  }
51524
51478
  try {
51525
- const content = readFileSync25(path, "utf8");
51479
+ const content = readFileSync24(path, "utf8");
51526
51480
  const lines = content.split(/\r?\n/).filter((line) => line.length > 0);
51527
51481
  const grammars = new Set(lines.flatMap((line) => {
51528
51482
  const parsed = parseLogLine(line);
@@ -51549,7 +51503,7 @@ function readLogLines(files) {
51549
51503
  return [];
51550
51504
  try {
51551
51505
  let precedingTimestamp = "";
51552
- return readFileSync25(file.path, "utf8").split(/\r?\n/).filter((line) => line.length > 0).map((line, lineIndex) => {
51506
+ return readFileSync24(file.path, "utf8").split(/\r?\n/).filter((line) => line.length > 0).map((line, lineIndex) => {
51553
51507
  precedingTimestamp = parseLogLine(line)?.ts ?? precedingTimestamp;
51554
51508
  return { line, timestamp: precedingTimestamp, fileIndex, lineIndex };
51555
51509
  });
@@ -52157,8 +52111,8 @@ var init_issue_body = __esm(() => {
52157
52111
  });
52158
52112
 
52159
52113
  // src/lib/omp-hide-secrets.ts
52160
- import { existsSync as existsSync43, readdirSync as readdirSync9, readFileSync as readFileSync26, statSync as statSync23 } from "node:fs";
52161
- import { join as join34, resolve as resolve17 } from "node:path";
52114
+ import { existsSync as existsSync42, readdirSync as readdirSync9, readFileSync as readFileSync25, statSync as statSync23 } from "node:fs";
52115
+ import { join as join33, resolve as resolve17 } from "node:path";
52162
52116
  function stripYamlComment(line) {
52163
52117
  let quote = null;
52164
52118
  for (let index = 0;index < line.length; index += 1) {
@@ -52281,7 +52235,7 @@ function readHideSecretsFromJson(text) {
52281
52235
  function readSource(layer, path, format) {
52282
52236
  let text;
52283
52237
  try {
52284
- text = readFileSync26(path, "utf-8");
52238
+ text = readFileSync25(path, "utf-8");
52285
52239
  } catch (error) {
52286
52240
  const code = error.code;
52287
52241
  return {
@@ -52309,22 +52263,22 @@ function isNonEmptyDirectory(path) {
52309
52263
  function collectHideSecretsSources(cwd, home = envFirstHomeDir()) {
52310
52264
  const sources = [];
52311
52265
  const agentDir = getOmpAgentDir();
52312
- const mainConfig = ["config.yml", "config.yaml"].map((name) => join34(agentDir, name)).find((path) => existsSync43(path));
52266
+ const mainConfig = ["config.yml", "config.yaml"].map((name) => join33(agentDir, name)).find((path) => existsSync42(path));
52313
52267
  if (mainConfig)
52314
52268
  sources.push(readSource("user", mainConfig, "yaml"));
52315
- const projectDir = join34(cwd, ".omp");
52269
+ const projectDir = join33(cwd, ".omp");
52316
52270
  if (resolve17(cwd) !== resolve17(home) && isNonEmptyDirectory(projectDir)) {
52317
52271
  for (const [name, format] of [
52318
52272
  ["settings.json", "json"],
52319
52273
  ["config.yml", "yaml"]
52320
52274
  ]) {
52321
- const path = join34(projectDir, name);
52322
- if (existsSync43(path))
52275
+ const path = join33(projectDir, name);
52276
+ if (existsSync42(path))
52323
52277
  sources.push(readSource("project", path, format));
52324
52278
  }
52325
52279
  }
52326
52280
  for (const path of getOmpConfigOverlayPaths(cwd)) {
52327
- if (existsSync43(path))
52281
+ if (existsSync42(path))
52328
52282
  sources.push(readSource("overlay", path, "yaml"));
52329
52283
  }
52330
52284
  return sources;
@@ -52382,9 +52336,9 @@ var init_omp_hide_secrets = __esm(() => {
52382
52336
 
52383
52337
  // src/commands/doctor-omp.ts
52384
52338
  import { execFileSync as execFileSync8, spawnSync as spawnSync8 } from "node:child_process";
52385
- import { existsSync as existsSync44, readFileSync as readFileSync27 } from "node:fs";
52339
+ import { existsSync as existsSync43, readFileSync as readFileSync26 } from "node:fs";
52386
52340
  import { createRequire as createRequire3 } from "node:module";
52387
- import { isAbsolute as isAbsolute8, join as join35, resolve as resolve18 } from "node:path";
52341
+ import { isAbsolute as isAbsolute8, join as join34, resolve as resolve18 } from "node:path";
52388
52342
  function parseSemver(value) {
52389
52343
  const match = value?.match(/(\d+)\.(\d+)\.(\d+)/);
52390
52344
  return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
@@ -52426,10 +52380,10 @@ function selfVersion() {
52426
52380
  return "unknown";
52427
52381
  }
52428
52382
  function readConfig2(path) {
52429
- if (!existsSync44(path))
52383
+ if (!existsSync43(path))
52430
52384
  return {};
52431
52385
  try {
52432
- const parsed = import_comment_json8.parse(readFileSync27(path, "utf-8"));
52386
+ const parsed = import_comment_json8.parse(readFileSync26(path, "utf-8"));
52433
52387
  return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? {} : { error: "top level is not an object" };
52434
52388
  } catch (error) {
52435
52389
  return { error: error instanceof Error ? error.message : String(error) };
@@ -52439,7 +52393,7 @@ function pluginDeclaresOmp(path) {
52439
52393
  if (!path)
52440
52394
  return null;
52441
52395
  try {
52442
- const pkg = JSON.parse(readFileSync27(join35(path, "package.json"), "utf-8"));
52396
+ const pkg = JSON.parse(readFileSync26(join34(path, "package.json"), "utf-8"));
52443
52397
  return Array.isArray(pkg.omp?.extensions) || Array.isArray(pkg.pi?.extensions);
52444
52398
  } catch {
52445
52399
  return null;
@@ -52528,7 +52482,7 @@ async function runHealthChecks(options) {
52528
52482
  }
52529
52483
  }
52530
52484
  const userConfigPath = getOmpUserConfigPath();
52531
- if (!existsSync44(userConfigPath)) {
52485
+ if (!existsSync43(userConfigPath)) {
52532
52486
  add(results, "warn", `No Magic Context user config at ${userConfigPath}`);
52533
52487
  repairPlan.writeUserConfig = true;
52534
52488
  } else {
@@ -52545,12 +52499,12 @@ async function runHealthChecks(options) {
52545
52499
  for (const warning of loaded.warnings.slice(0, 5))
52546
52500
  add(results, "warn", warning);
52547
52501
  const storage = getMagicContextStorageResolution();
52548
- const dbPath = join35(storage.path, "context.db");
52502
+ const dbPath = join34(storage.path, "context.db");
52549
52503
  if (isMagicContextStorageOutsideEngram(storage.path)) {
52550
52504
  add(results, "warn", `Magic Context storage is at ${storage.path}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
52551
52505
  }
52552
52506
  add(results, "info", `Shared storage: ${storage.path} (source: ${storage.source})`);
52553
- if (!existsSync44(dbPath))
52507
+ if (!existsSync43(dbPath))
52554
52508
  add(results, "info", `Shared context DB will be created at ${dbPath}`);
52555
52509
  else {
52556
52510
  let db = null;
@@ -52615,7 +52569,7 @@ function writeDefaultConfig(path) {
52615
52569
  }
52616
52570
  async function repair(plan, deps, prompts, cwd) {
52617
52571
  let fixed = 0;
52618
- if (plan.writeUserConfig && !existsSync44(getOmpUserConfigPath())) {
52572
+ if (plan.writeUserConfig && !existsSync43(getOmpUserConfigPath())) {
52619
52573
  writeDefaultConfig(getOmpUserConfigPath());
52620
52574
  prompts.log.success(`Wrote default Magic Context config to ${getOmpUserConfigPath()}`);
52621
52575
  fixed += 1;
@@ -52728,7 +52682,7 @@ function runGhCommandWithDeps(deps, args) {
52728
52682
  async function runIssueFlow(options) {
52729
52683
  if (options.reportPath) {
52730
52684
  const report = await runHealthChecks({ ...options, quiet: true });
52731
- const path = isAbsolute8(options.reportPath) ? options.reportPath : join35(options.cwd, options.reportPath);
52685
+ const path = isAbsolute8(options.reportPath) ? options.reportPath : join34(options.cwd, options.reportPath);
52732
52686
  const bundle = writeOmpIssueReport(path, ompIssueBody("Generated non-interactively by `doctor --issue --report`.", report, readLogLines(report.logFiles), null, options.cwd));
52733
52687
  options.prompts.log.success(bundle.fullPath ? `Sanitized report written to ${bundle.path}; full report at ${bundle.fullPath}` : `Sanitized report written to ${bundle.path}`);
52734
52688
  return 0;
@@ -52755,7 +52709,7 @@ async function runIssueFlow(options) {
52755
52709
  ]);
52756
52710
  sessionFilter = choice === "__all__" ? null : choice;
52757
52711
  }
52758
- const path = join35(options.cwd, `magic-context-omp-issue-${timestamp2(options.deps.now())}.md`);
52712
+ const path = join34(options.cwd, `magic-context-omp-issue-${timestamp2(options.deps.now())}.md`);
52759
52713
  const bundle = writeOmpIssueReport(path, ompIssueBody(description, report, logLines, sessionFilter, options.cwd));
52760
52714
  options.prompts.log.success(bundle.fullPath ? `Sanitized report written to ${bundle.path}; full report at ${bundle.fullPath}` : `Sanitized report written to ${bundle.path}`);
52761
52715
  if (await options.prompts.confirm("Submit this issue on GitHub now?", false)) {
@@ -53725,12 +53679,12 @@ function listShadowBackfillStalls(db, projectIdentity) {
53725
53679
  var SHADOW_BACKFILL_PROVENANCE_KEY = "_magicContextShadowBackfill";
53726
53680
 
53727
53681
  // ../plugin/src/shared/auto-update-provenance.ts
53728
- import { existsSync as existsSync45, readFileSync as readFileSync28 } from "node:fs";
53682
+ import { existsSync as existsSync44, readFileSync as readFileSync27 } from "node:fs";
53729
53683
  function readAutoUpdateCheckState(path) {
53730
- if (!existsSync45(path))
53684
+ if (!existsSync44(path))
53731
53685
  return null;
53732
53686
  try {
53733
- const value = JSON.parse(readFileSync28(path, "utf-8"));
53687
+ const value = JSON.parse(readFileSync27(path, "utf-8"));
53734
53688
  if (!value || typeof value !== "object" || Array.isArray(value))
53735
53689
  return null;
53736
53690
  const raw = value;
@@ -53758,14 +53712,14 @@ var init_auto_update_provenance = () => {};
53758
53712
  // ../plugin/src/shared/tui-config.ts
53759
53713
  import {
53760
53714
  chmodSync as chmodSync4,
53761
- existsSync as existsSync46,
53715
+ existsSync as existsSync45,
53762
53716
  mkdirSync as mkdirSync8,
53763
- readFileSync as readFileSync29,
53717
+ readFileSync as readFileSync28,
53764
53718
  renameSync as renameSync8,
53765
53719
  statSync as statSync24,
53766
53720
  writeFileSync as writeFileSync8
53767
53721
  } from "node:fs";
53768
- import { dirname as dirname24, join as join36 } from "node:path";
53722
+ import { dirname as dirname24, join as join35 } from "node:path";
53769
53723
  function pluginEntryId(entry) {
53770
53724
  if (typeof entry === "string")
53771
53725
  return entry;
@@ -53806,11 +53760,11 @@ function writeTuiConfigAtomic(configPath, config) {
53806
53760
  }
53807
53761
  function resolveTuiConfigPath(configDirOverride) {
53808
53762
  const configDir = configDirOverride ?? getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
53809
- const jsoncPath = join36(configDir, "tui.jsonc");
53810
- const jsonPath = join36(configDir, "tui.json");
53811
- if (existsSync46(jsoncPath))
53763
+ const jsoncPath = join35(configDir, "tui.jsonc");
53764
+ const jsonPath = join35(configDir, "tui.json");
53765
+ if (existsSync45(jsoncPath))
53812
53766
  return jsoncPath;
53813
- if (existsSync46(jsonPath))
53767
+ if (existsSync45(jsonPath))
53814
53768
  return jsonPath;
53815
53769
  return jsoncPath;
53816
53770
  }
@@ -53818,8 +53772,8 @@ function ensureTuiPluginEntry(options = {}) {
53818
53772
  try {
53819
53773
  const configPath = resolveTuiConfigPath(options.configDir);
53820
53774
  let config = {};
53821
- if (existsSync46(configPath)) {
53822
- const raw = readFileSync29(configPath, "utf-8");
53775
+ if (existsSync45(configPath)) {
53776
+ const raw = readFileSync28(configPath, "utf-8");
53823
53777
  config = import_comment_json9.parse(raw) ?? {};
53824
53778
  }
53825
53779
  const plugins = Array.isArray(config.plugin) ? [...config.plugin] : [];
@@ -53871,9 +53825,9 @@ var init_tui_config = __esm(() => {
53871
53825
  });
53872
53826
 
53873
53827
  // src/lib/diagnostics-opencode.ts
53874
- import { existsSync as existsSync47, readdirSync as readdirSync10, readFileSync as readFileSync30, statSync as statSync25 } from "node:fs";
53828
+ import { existsSync as existsSync46, readdirSync as readdirSync10, readFileSync as readFileSync29, statSync as statSync25 } from "node:fs";
53875
53829
  import { createRequire as createRequire4 } from "node:module";
53876
- import { join as join37 } from "node:path";
53830
+ import { join as join36 } from "node:path";
53877
53831
  function getSelfVersion() {
53878
53832
  const require2 = createRequire4(import.meta.url);
53879
53833
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -53888,7 +53842,7 @@ function getSelfVersion() {
53888
53842
  }
53889
53843
  function readLegacyCachedVersion(root) {
53890
53844
  try {
53891
- const pkg = JSON.parse(readFileSync30(getOpenCodePluginPackageJsonPath(root), "utf-8"));
53845
+ const pkg = JSON.parse(readFileSync29(getOpenCodePluginPackageJsonPath(root), "utf-8"));
53892
53846
  return typeof pkg.version === "string" ? pkg.version : undefined;
53893
53847
  } catch {
53894
53848
  return;
@@ -53897,7 +53851,7 @@ function readLegacyCachedVersion(root) {
53897
53851
  function collectOpenCodePluginCacheReport(hostGeneration, opencodeConfig) {
53898
53852
  const installs = [];
53899
53853
  for (const root of getOpenCodePluginCacheRoots()) {
53900
- if (!existsSync47(root))
53854
+ if (!existsSync46(root))
53901
53855
  continue;
53902
53856
  const spec = root.endsWith("@latest") ? "latest" : "(bare)";
53903
53857
  installs.push({
@@ -53931,7 +53885,7 @@ function getStorageResolution() {
53931
53885
  }
53932
53886
  function fileSize(path) {
53933
53887
  try {
53934
- return existsSync47(path) ? statSync25(path).size : 0;
53888
+ return existsSync46(path) ? statSync25(path).size : 0;
53935
53889
  } catch {
53936
53890
  return 0;
53937
53891
  }
@@ -53943,10 +53897,10 @@ function sanitizeValue(value) {
53943
53897
  return sanitizeConfigValue(value);
53944
53898
  }
53945
53899
  function readConfig3(path) {
53946
- if (!existsSync47(path))
53900
+ if (!existsSync46(path))
53947
53901
  return { value: null };
53948
53902
  try {
53949
- const raw = readFileSync30(path, "utf-8");
53903
+ const raw = readFileSync29(path, "utf-8");
53950
53904
  const value = import_comment_json10.parse(raw);
53951
53905
  return { value };
53952
53906
  } catch (error) {
@@ -53971,7 +53925,7 @@ function configHasPluginEntry(config) {
53971
53925
  }
53972
53926
  function parseHistorianDumpMeta(path) {
53973
53927
  try {
53974
- const xml = readFileSync30(path, "utf-8");
53928
+ const xml = readFileSync29(path, "utf-8");
53975
53929
  const parsed = parseCompartmentOutput(xml);
53976
53930
  const factCountByCategory = {};
53977
53931
  for (const fact of parsed.facts) {
@@ -54004,11 +53958,11 @@ function parseHistorianDumpMeta(path) {
54004
53958
  }
54005
53959
  }
54006
53960
  function listDumpsInDir(dir, limit) {
54007
- if (!existsSync47(dir))
53961
+ if (!existsSync46(dir))
54008
53962
  return { count: 0, recent: [] };
54009
53963
  try {
54010
53964
  const entries = readdirSync10(dir).filter((name) => name.endsWith(".xml")).map((name) => {
54011
- const stat = statSync25(join37(dir, name));
53965
+ const stat = statSync25(join36(dir, name));
54012
53966
  return {
54013
53967
  name,
54014
53968
  mtime: stat.mtimeMs,
@@ -54017,7 +53971,7 @@ function listDumpsInDir(dir, limit) {
54017
53971
  }).sort((a, b) => b.mtime - a.mtime);
54018
53972
  const now = Date.now();
54019
53973
  const recent = entries.slice(0, limit).map((entry) => {
54020
- const meta = parseHistorianDumpMeta(join37(dir, entry.name));
53974
+ const meta = parseHistorianDumpMeta(join36(dir, entry.name));
54021
53975
  const summary = {
54022
53976
  name: entry.name,
54023
53977
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -54128,7 +54082,7 @@ function collectRecentSessionsFromDatabase(database) {
54128
54082
  });
54129
54083
  }
54130
54084
  async function collectDatabaseRows(path, read) {
54131
- if (!existsSync47(path))
54085
+ if (!existsSync46(path))
54132
54086
  return { available: false, reason: "path missing" };
54133
54087
  let backend;
54134
54088
  try {
@@ -54160,7 +54114,7 @@ async function collectRecentSessions(resolution, hostGeneration) {
54160
54114
  });
54161
54115
  }
54162
54116
  async function collectHistorianFailures(storageDirPath) {
54163
- return collectDatabaseRows(join37(storageDirPath, "context.db"), (db) => {
54117
+ return collectDatabaseRows(join36(storageDirPath, "context.db"), (db) => {
54164
54118
  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();
54165
54119
  return rows.map((row) => {
54166
54120
  const sessionId = typeof row.session_id === "string" ? row.session_id : "<unknown>";
@@ -54173,7 +54127,7 @@ async function collectHistorianFailures(storageDirPath) {
54173
54127
  });
54174
54128
  }
54175
54129
  async function collectHistorianRuns(storageDirPath) {
54176
- return collectDatabaseRows(join37(storageDirPath, "context.db"), (db) => {
54130
+ return collectDatabaseRows(join36(storageDirPath, "context.db"), (db) => {
54177
54131
  const aggRows = db.prepare(`SELECT session_id,
54178
54132
  COUNT(*) AS total,
54179
54133
  SUM(CASE WHEN status='success' THEN 1 ELSE 0 END) AS success,
@@ -54228,7 +54182,7 @@ async function collectDiagnostics() {
54228
54182
  const magicContextConfig = readConfig3(configPaths.magicContextConfig);
54229
54183
  const storageResolution = getStorageResolution();
54230
54184
  const storageDirPath = storageResolution.path;
54231
- const contextDbPath = join37(storageDirPath, "context.db");
54185
+ const contextDbPath = join36(storageDirPath, "context.db");
54232
54186
  let compactionEnabled = false;
54233
54187
  try {
54234
54188
  compactionEnabled = isCompactionEnabled(loadPluginConfig(process.cwd()));
@@ -54260,7 +54214,7 @@ async function collectDiagnostics() {
54260
54214
  opencodeConfigHasPlugin: configHasPluginEntry(opencodeConfig.value),
54261
54215
  tuiConfigHasPlugin: configHasPluginEntry(tuiConfig.value),
54262
54216
  magicContextConfig: {
54263
- exists: existsSync47(configPaths.magicContextConfig),
54217
+ exists: existsSync46(configPaths.magicContextConfig),
54264
54218
  ...magicContextConfig.error ? { parseError: magicContextConfig.error } : {},
54265
54219
  flags: sanitizeValue(magicContextConfig.value ?? {}) ?? {}
54266
54220
  },
@@ -54268,7 +54222,7 @@ async function collectDiagnostics() {
54268
54222
  storageDir: {
54269
54223
  path: storageDirPath,
54270
54224
  source: storageResolution.source,
54271
- exists: existsSync47(storageDirPath),
54225
+ exists: existsSync46(storageDirPath),
54272
54226
  contextDbSizeBytes: fileSize(contextDbPath)
54273
54227
  },
54274
54228
  openCodeDatabase: {
@@ -54538,9 +54492,9 @@ var init_embedding_local = __esm(async () => {
54538
54492
 
54539
54493
  // src/lib/embedding-runtime.ts
54540
54494
  import { spawnSync as spawnSync9 } from "node:child_process";
54541
- import { existsSync as existsSync48, readFileSync as readFileSync31 } from "node:fs";
54495
+ import { existsSync as existsSync47, readFileSync as readFileSync30 } from "node:fs";
54542
54496
  import { createRequire as createRequire5 } from "node:module";
54543
- import { dirname as dirname25, join as join38, sep as sep2 } from "node:path";
54497
+ import { dirname as dirname25, join as join37, sep as sep2 } from "node:path";
54544
54498
  function describeError(error) {
54545
54499
  const message = error instanceof Error ? error.message : String(error ?? "unknown error");
54546
54500
  const code = error?.code;
@@ -54682,11 +54636,11 @@ function expectedBinaryRelPath(platform, arch) {
54682
54636
  const supportedArch = arch === "x64" || arch === "arm64";
54683
54637
  if (!supportedPlatform || !supportedArch)
54684
54638
  return null;
54685
- return join38("bin", "napi-v6", platform, arch, "onnxruntime_binding.node");
54639
+ return join37("bin", "napi-v6", platform, arch, "onnxruntime_binding.node");
54686
54640
  }
54687
54641
  function onnxRuntimeNodeVersion(packageDir) {
54688
54642
  try {
54689
- const parsed = JSON.parse(readFileSync31(join38(packageDir, "package.json"), "utf8"));
54643
+ const parsed = JSON.parse(readFileSync30(join37(packageDir, "package.json"), "utf8"));
54690
54644
  return typeof parsed.version === "string" ? parsed.version : undefined;
54691
54645
  } catch {
54692
54646
  return;
@@ -54735,7 +54689,7 @@ function formatLocalEmbeddingRuntimeWasmSelected(status) {
54735
54689
  function requireNodeWasmBundle(probe, candidates) {
54736
54690
  if (probe.state === "failed")
54737
54691
  return probe;
54738
- const bundlePath = candidates.find((candidate) => existsSync48(candidate));
54692
+ const bundlePath = candidates.find((candidate) => existsSync47(candidate));
54739
54693
  return bundlePath ? probe : {
54740
54694
  state: "failed",
54741
54695
  reason: `functional Node WASM Transformers bundle is missing (checked ${candidates.join(", ")})`
@@ -54743,13 +54697,13 @@ function requireNodeWasmBundle(probe, candidates) {
54743
54697
  }
54744
54698
  function nodeWasmBundleCandidates(installRoot) {
54745
54699
  return [
54746
- join38(installRoot, "dist", "transformers-node-wasm.js"),
54747
- join38(installRoot, "node_modules", "@cortexkit", "opencode-magic-context", "dist", "transformers-node-wasm.js"),
54748
- join38(installRoot, "node_modules", "@cortexkit", "pi-magic-context", "dist", "transformers-node-wasm.js")
54700
+ join37(installRoot, "dist", "transformers-node-wasm.js"),
54701
+ join37(installRoot, "node_modules", "@cortexkit", "opencode-magic-context", "dist", "transformers-node-wasm.js"),
54702
+ join37(installRoot, "node_modules", "@cortexkit", "pi-magic-context", "dist", "transformers-node-wasm.js")
54749
54703
  ];
54750
54704
  }
54751
54705
  function probeWasmRuntimeAt(installRoot) {
54752
- const requireFn = createRequire5(join38(installRoot, "package.json"));
54706
+ const requireFn = createRequire5(join37(installRoot, "package.json"));
54753
54707
  return requireNodeWasmBundle(probeWasmRuntimeFromRequire(requireFn), nodeWasmBundleCandidates(installRoot));
54754
54708
  }
54755
54709
  function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
@@ -54758,9 +54712,9 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
54758
54712
  const wasm = probeWasmRuntimeAt(installRoot);
54759
54713
  return wasm.state === "ok" ? { state: "wasm-selected", wasmPath: wasm.wasmPath } : { state: "wasm-broken", wasmReason: wasm.reason };
54760
54714
  }
54761
- const packageDir = join38(installRoot, "node_modules", "onnxruntime-node");
54715
+ const packageDir = join37(installRoot, "node_modules", "onnxruntime-node");
54762
54716
  let native;
54763
- if (!existsSync48(join38(packageDir, "package.json"))) {
54717
+ if (!existsSync47(join37(packageDir, "package.json"))) {
54764
54718
  native = { state: "package-missing", packageDir };
54765
54719
  } else {
54766
54720
  const rel = expectedBinaryRelPath(platform, arch);
@@ -54770,8 +54724,8 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
54770
54724
  binaryPath: packageDir
54771
54725
  };
54772
54726
  } else {
54773
- const binaryPath = join38(packageDir, rel);
54774
- native = existsSync48(binaryPath) ? probeOnnxRuntimeNodeLoad(packageDir) ?? { state: "ok", binaryPath } : {
54727
+ const binaryPath = join37(packageDir, rel);
54728
+ native = existsSync47(binaryPath) ? probeOnnxRuntimeNodeLoad(packageDir) ?? { state: "ok", binaryPath } : {
54775
54729
  state: "binary-missing",
54776
54730
  packageDir,
54777
54731
  expectedBinary: binaryPath,
@@ -54782,7 +54736,7 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
54782
54736
  return withWasmFallback(native, () => probeWasmRuntimeAt(installRoot));
54783
54737
  }
54784
54738
  function checkLocalEmbeddingRuntime(installRoots, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
54785
- const existing = installRoots.filter((root) => existsSync48(root));
54739
+ const existing = installRoots.filter((root) => existsSync47(root));
54786
54740
  if (existing.length === 0) {
54787
54741
  return {
54788
54742
  state: "unknown",
@@ -54812,15 +54766,15 @@ function packageDirFromResolved(resolvedPath, packageName) {
54812
54766
  }
54813
54767
  function probeWasmRuntimeByResolution(pluginDir) {
54814
54768
  try {
54815
- const reqPlugin = createRequire5(join38(pluginDir, "package.json"));
54769
+ const reqPlugin = createRequire5(join37(pluginDir, "package.json"));
54816
54770
  const direct = probeWasmRuntimeFromRequire(reqPlugin);
54817
54771
  let probe = direct;
54818
54772
  if (direct.state === "failed" && direct.reason.startsWith("onnxruntime-web is not resolvable")) {
54819
54773
  const tfResolved = reqPlugin.resolve("@huggingface/transformers");
54820
54774
  const tfDir = packageDirFromResolved(tfResolved, "@huggingface/transformers");
54821
- probe = probeWasmRuntimeFromRequire(createRequire5(join38(tfDir, "package.json")));
54775
+ probe = probeWasmRuntimeFromRequire(createRequire5(join37(tfDir, "package.json")));
54822
54776
  }
54823
- return requireNodeWasmBundle(probe, [join38(pluginDir, "dist", "transformers-node-wasm.js")]);
54777
+ return requireNodeWasmBundle(probe, [join37(pluginDir, "dist", "transformers-node-wasm.js")]);
54824
54778
  } catch (error) {
54825
54779
  return {
54826
54780
  state: "failed",
@@ -54829,7 +54783,7 @@ function probeWasmRuntimeByResolution(pluginDir) {
54829
54783
  }
54830
54784
  }
54831
54785
  function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
54832
- if (!existsSync48(join38(pluginDir, "package.json"))) {
54786
+ if (!existsSync47(join37(pluginDir, "package.json"))) {
54833
54787
  return { state: "unknown", reason: "plugin package dir not found" };
54834
54788
  }
54835
54789
  const selectedRuntime = resolveLocalEmbeddingWorkerRuntime(runtimePreference, host);
@@ -54840,13 +54794,13 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
54840
54794
  let onnxDir = null;
54841
54795
  let resolveError;
54842
54796
  try {
54843
- const reqPlugin = createRequire5(join38(pluginDir, "package.json"));
54797
+ const reqPlugin = createRequire5(join37(pluginDir, "package.json"));
54844
54798
  try {
54845
54799
  onnxDir = packageDirFromResolved(reqPlugin.resolve("onnxruntime-node"), "onnxruntime-node");
54846
54800
  } catch {
54847
54801
  const tfResolved = reqPlugin.resolve("@huggingface/transformers");
54848
54802
  const tfDir = packageDirFromResolved(tfResolved, "@huggingface/transformers");
54849
- const reqTf = createRequire5(join38(tfDir, "package.json"));
54803
+ const reqTf = createRequire5(join37(tfDir, "package.json"));
54850
54804
  onnxDir = packageDirFromResolved(reqTf.resolve("onnxruntime-node"), "onnxruntime-node");
54851
54805
  }
54852
54806
  } catch (error) {
@@ -54854,7 +54808,7 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
54854
54808
  if (resolveError === "ERR_MODULE_NOT_FOUND" || resolveError === "MODULE_NOT_FOUND") {
54855
54809
  return withWasmFallback({
54856
54810
  state: "package-missing",
54857
- packageDir: join38(pluginDir, "node_modules", "onnxruntime-node")
54811
+ packageDir: join37(pluginDir, "node_modules", "onnxruntime-node")
54858
54812
  }, () => probeWasmRuntimeByResolution(pluginDir));
54859
54813
  }
54860
54814
  return {
@@ -54870,8 +54824,8 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
54870
54824
  if (rel === null) {
54871
54825
  native = probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath: onnxDir };
54872
54826
  } else {
54873
- const binaryPath = join38(onnxDir, rel);
54874
- native = existsSync48(binaryPath) ? probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath } : {
54827
+ const binaryPath = join37(onnxDir, rel);
54828
+ native = existsSync47(binaryPath) ? probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath } : {
54875
54829
  state: "binary-missing",
54876
54830
  packageDir: onnxDir,
54877
54831
  expectedBinary: binaryPath,
@@ -54907,7 +54861,7 @@ var init_embedding_runtime = __esm(async () => {
54907
54861
 
54908
54862
  // src/lib/logs-opencode.ts
54909
54863
  import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync9 } from "node:fs";
54910
- import { dirname as dirname26, join as join39 } from "node:path";
54864
+ import { dirname as dirname26, join as join38 } from "node:path";
54911
54865
  function formatTimestamp(date) {
54912
54866
  const pad = (value) => String(value).padStart(2, "0");
54913
54867
  return [
@@ -54996,11 +54950,11 @@ async function bundleIssueReport(report, description, title, sessionFilter = nul
54996
54950
  const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
54997
54951
  const truncated = bodyMarkdown !== rawBodyMarkdown;
54998
54952
  const timestamp = formatTimestamp(new Date);
54999
- const path = options.outputPath ?? join39(process.cwd(), `magic-context-issue-${timestamp}.md`);
54953
+ const path = options.outputPath ?? join38(process.cwd(), `magic-context-issue-${timestamp}.md`);
55000
54954
  mkdirSync9(dirname26(path), { recursive: true });
55001
54955
  writeFileSync9(path, `${bodyMarkdown}
55002
54956
  `);
55003
- const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join39(process.cwd(), `magic-context-issue-${timestamp}-full.md`) : undefined;
54957
+ const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join38(process.cwd(), `magic-context-issue-${timestamp}-full.md`) : undefined;
55004
54958
  if (fullPath)
55005
54959
  writeFileSync9(fullPath, `${rawBodyMarkdown}
55006
54960
  `);
@@ -55821,10 +55775,10 @@ function removeDeprecatedReasoningAge(config) {
55821
55775
 
55822
55776
  // src/commands/doctor-opencode.ts
55823
55777
  import { spawnSync as spawnSync10 } from "node:child_process";
55824
- import { existsSync as existsSync49, mkdtempSync as mkdtempSync4, readFileSync as readFileSync32, rmSync as rmSync9 } from "node:fs";
55778
+ import { existsSync as existsSync48, mkdtempSync as mkdtempSync4, readFileSync as readFileSync31, rmSync as rmSync9 } from "node:fs";
55825
55779
  import { createRequire as createRequire6 } from "node:module";
55826
55780
  import { homedir as homedir21, tmpdir as tmpdir4 } from "node:os";
55827
- import { dirname as dirname27, join as join40, resolve as resolve19 } from "node:path";
55781
+ import { dirname as dirname27, join as join39, resolve as resolve19 } from "node:path";
55828
55782
  function formatSharedDbRowCounts(db) {
55829
55783
  return SHARED_DB_ROW_COUNT_TABLES.map((table) => {
55830
55784
  try {
@@ -55895,7 +55849,7 @@ function checkConfiguredVariantCatalog(config, hostGeneration, warn, run = (args
55895
55849
  }
55896
55850
  if (models.length === 0)
55897
55851
  return;
55898
- const tempRoot = mkdtempSync4(join40(tmpdir4(), "magic-context-opencode-catalog-"));
55852
+ const tempRoot = mkdtempSync4(join39(tmpdir4(), "magic-context-opencode-catalog-"));
55899
55853
  try {
55900
55854
  const command = hostGeneration === "v2" ? ["api", "model.list", "--param", `directory=${projectDir}`] : ["models", "--verbose"];
55901
55855
  const guidance = `opencode ${command.join(" ")}`;
@@ -56071,7 +56025,7 @@ function getSelfVersion2() {
56071
56025
  function describeAutoUpdateStall(specifier, autoUpdateEnabled, storageDir = getMagicContextStorageDir()) {
56072
56026
  if (!autoUpdateEnabled || !isPinnedOpenCodePluginSpecifier(specifier))
56073
56027
  return null;
56074
- const state = readAutoUpdateCheckState(join40(storageDir, AUTO_UPDATE_CHECK_STATE_FILENAME));
56028
+ const state = readAutoUpdateCheckState(join39(storageDir, AUTO_UPDATE_CHECK_STATE_FILENAME));
56075
56029
  const owner = isUpdaterPinnedSpec(state, specifier) ? "updater" : "you";
56076
56030
  return `auto-update: stalled — config pinned to ${specifier} (by ${owner})`;
56077
56031
  }
@@ -56080,15 +56034,15 @@ function getUserNpmrcPath() {
56080
56034
  if (custom)
56081
56035
  return custom;
56082
56036
  const home = process.env.HOME?.trim();
56083
- return join40(home || homedir21(), ".npmrc");
56037
+ return join39(home || homedir21(), ".npmrc");
56084
56038
  }
56085
56039
  function collectNpmReleaseAgeWarnings() {
56086
56040
  const ageWarnings = [];
56087
56041
  const npmrcPath = getUserNpmrcPath();
56088
- if (!existsSync49(npmrcPath))
56042
+ if (!existsSync48(npmrcPath))
56089
56043
  return ageWarnings;
56090
56044
  try {
56091
- const npmrc = readFileSync32(npmrcPath, "utf-8");
56045
+ const npmrc = readFileSync31(npmrcPath, "utf-8");
56092
56046
  for (const line of npmrc.split(`
56093
56047
  `)) {
56094
56048
  const trimmed = line.trim();
@@ -56223,7 +56177,7 @@ function checkLocalEmbeddingRuntimeForDoctor(installRoots, runtimePreference = "
56223
56177
  return { issues: 0 };
56224
56178
  }
56225
56179
  async function checkEmbeddingConfig(magicContextConfigPath, installRoots) {
56226
- if (!existsSync49(magicContextConfigPath)) {
56180
+ if (!existsSync48(magicContextConfigPath)) {
56227
56181
  return checkLocalEmbeddingRuntimeForDoctor(installRoots);
56228
56182
  }
56229
56183
  let rawText;
@@ -56398,7 +56352,7 @@ async function runDoctor2(options = {}) {
56398
56352
  const v22Result = await runV22BackfillCommands({
56399
56353
  name: "OpenCode",
56400
56354
  openDatabase: (readonly = true) => {
56401
- const dbPath = join40(getMagicContextStorageDir(), "context.db");
56355
+ const dbPath = join39(getMagicContextStorageDir(), "context.db");
56402
56356
  v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
56403
56357
  return v22Db;
56404
56358
  },
@@ -56434,7 +56388,7 @@ async function runDoctor2(options = {}) {
56434
56388
  if (isMagicContextStorageOutsideEngram(storageDir)) {
56435
56389
  warn(`Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
56436
56390
  }
56437
- const authorityDbPath = join40(getMagicContextStorageDir(), "context.db");
56391
+ const authorityDbPath = join39(getMagicContextStorageDir(), "context.db");
56438
56392
  let authorityDb = null;
56439
56393
  try {
56440
56394
  authorityDb = openExistingContextDatabase(authorityDbPath, { readonly: true });
@@ -56473,7 +56427,7 @@ async function runDoctor2(options = {}) {
56473
56427
  let magicContextStatusKnown = paths.opencodeConfigFormat === "none";
56474
56428
  if (!magicContextStatusKnown) {
56475
56429
  try {
56476
- const config = import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8"));
56430
+ const config = import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8"));
56477
56431
  magicContextInstalled = isOpenCodePluginRegistered(config, dirname27(paths.opencodeConfig));
56478
56432
  magicContextStatusKnown = true;
56479
56433
  } catch {}
@@ -56609,7 +56563,7 @@ async function runDoctor2(options = {}) {
56609
56563
  pass(`OpenCode config: ${paths.opencodeConfig}`);
56610
56564
  }
56611
56565
  let autoUpdateEnabled = true;
56612
- if (existsSync49(paths.magicContextConfig)) {
56566
+ if (existsSync48(paths.magicContextConfig)) {
56613
56567
  pass(`Magic Context config: ${paths.magicContextConfig}`);
56614
56568
  try {
56615
56569
  const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
@@ -56647,7 +56601,7 @@ async function runDoctor2(options = {}) {
56647
56601
  log3.info(rerankConfigSummary());
56648
56602
  log3.info(" Run 'setup' to create one with model recommendations");
56649
56603
  }
56650
- if (existsSync49(paths.magicContextConfig)) {
56604
+ if (existsSync48(paths.magicContextConfig)) {
56651
56605
  try {
56652
56606
  const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
56653
56607
  if (!raw)
@@ -56787,7 +56741,7 @@ async function runDoctor2(options = {}) {
56787
56741
  };
56788
56742
  if (paths.opencodeConfigFormat !== "none") {
56789
56743
  try {
56790
- const raw = readFileSync32(paths.opencodeConfig, "utf-8");
56744
+ const raw = readFileSync31(paths.opencodeConfig, "utf-8");
56791
56745
  const config = import_comment_json11.parse(raw);
56792
56746
  const configName = paths.opencodeConfigFormat === "jsonc" ? "opencode.jsonc" : "opencode.json";
56793
56747
  const configDir = dirname27(paths.opencodeConfig);
@@ -56880,9 +56834,9 @@ async function runDoctor2(options = {}) {
56880
56834
  pass("Added TUI sidebar plugin to tui.json");
56881
56835
  warn("Restart OpenCode to see the sidebar");
56882
56836
  fixed++;
56883
- } else if (existsSync49(paths.tuiConfig)) {
56837
+ } else if (existsSync48(paths.tuiConfig)) {
56884
56838
  try {
56885
- const tuiRaw = readFileSync32(paths.tuiConfig, "utf-8");
56839
+ const tuiRaw = readFileSync31(paths.tuiConfig, "utf-8");
56886
56840
  const tuiConfig = import_comment_json11.parse(tuiRaw);
56887
56841
  const tuiConfigDir = dirname27(paths.tuiConfig);
56888
56842
  const tuiRawPlugins = Array.isArray(tuiConfig?.plugin) ? tuiConfig.plugin : [];
@@ -56921,7 +56875,7 @@ async function runDoctor2(options = {}) {
56921
56875
  fail("Could not create or verify the TUI sidebar config");
56922
56876
  }
56923
56877
  }
56924
- if (existsSync49(paths.magicContextConfig)) {
56878
+ if (existsSync48(paths.magicContextConfig)) {
56925
56879
  try {
56926
56880
  const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
56927
56881
  if (!raw)
@@ -56937,10 +56891,10 @@ async function runDoctor2(options = {}) {
56937
56891
  let embeddingHostConfig = null;
56938
56892
  try {
56939
56893
  if (paths.opencodeConfigFormat !== "none")
56940
- embeddingHostConfig = import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8"));
56894
+ embeddingHostConfig = import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8"));
56941
56895
  } catch {}
56942
56896
  const embeddingInstalls = getOpenCodeLoadedPluginInstallRoots(hostGeneration, embeddingHostConfig);
56943
- const unusedInstalls = embeddingInstalls.others.filter((root) => existsSync49(root));
56897
+ const unusedInstalls = embeddingInstalls.others.filter((root) => existsSync48(root));
56944
56898
  if (unusedInstalls.length > 0)
56945
56899
  log3.info(`Local embedding runtime: checked only the copy ${hostGeneration === "v2" ? "OpenCode 2" : "OpenCode 1"} loads; other installed copies (not loaded, not checked): ${unusedInstalls.join(", ")}`);
56946
56900
  const embeddingCheck = await checkEmbeddingConfig(paths.magicContextConfig, embeddingInstalls.loaded);
@@ -56952,9 +56906,9 @@ async function runDoctor2(options = {}) {
56952
56906
  else
56953
56907
  passCount++;
56954
56908
  const storage = getMagicContextStorageResolution();
56955
- const dbPath = join40(storage.path, "context.db");
56909
+ const dbPath = join39(storage.path, "context.db");
56956
56910
  log3.info(`Shared storage: ${storage.path} (source: ${storage.source})`);
56957
- if (!existsSync49(dbPath)) {
56911
+ if (!existsSync48(dbPath)) {
56958
56912
  log3.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
56959
56913
  } else {
56960
56914
  log3.info(`Shared context DB exists at ${dbPath}`);
@@ -57037,7 +56991,7 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
57037
56991
  let pluginConfigUse;
57038
56992
  if (paths.opencodeConfigFormat !== "none") {
57039
56993
  try {
57040
- pluginConfigUse = readOpenCodePluginConfigUse(import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8")), dirname27(paths.opencodeConfig));
56994
+ pluginConfigUse = readOpenCodePluginConfigUse(import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8")), dirname27(paths.opencodeConfig));
57041
56995
  } catch {}
57042
56996
  }
57043
56997
  const cacheResult = await clearPluginCache({
@@ -57089,7 +57043,7 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
57089
57043
  let v2DistTag;
57090
57044
  if (paths.opencodeConfigFormat !== "none") {
57091
57045
  try {
57092
- v2DistTag = configuredOpenCodeV2DistTag(import_comment_json11.parse(readFileSync32(paths.opencodeConfig, "utf-8")));
57046
+ v2DistTag = configuredOpenCodeV2DistTag(import_comment_json11.parse(readFileSync31(paths.opencodeConfig, "utf-8")));
57093
57047
  } catch {}
57094
57048
  }
57095
57049
  const v2Cache = reportOpenCodeV2PluginCache(checkOpenCodeV2PluginCache({
@@ -57491,9 +57445,9 @@ var init_model_chain_health = __esm(() => {
57491
57445
  });
57492
57446
 
57493
57447
  // src/lib/diagnostics-pi.ts
57494
- import { existsSync as existsSync50, readdirSync as readdirSync11, readFileSync as readFileSync33, statSync as statSync26 } from "node:fs";
57448
+ import { existsSync as existsSync49, readdirSync as readdirSync11, readFileSync as readFileSync32, statSync as statSync26 } from "node:fs";
57495
57449
  import { createRequire as createRequire7 } from "node:module";
57496
- import { join as join41 } from "node:path";
57450
+ import { join as join40 } from "node:path";
57497
57451
  function getSelfVersion3() {
57498
57452
  const req = createRequire7(import.meta.url);
57499
57453
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -57508,7 +57462,7 @@ function getSelfVersion3() {
57508
57462
  }
57509
57463
  function fileSize2(path) {
57510
57464
  try {
57511
- return existsSync50(path) ? statSync26(path).size : 0;
57465
+ return existsSync49(path) ? statSync26(path).size : 0;
57512
57466
  } catch {
57513
57467
  return 0;
57514
57468
  }
@@ -57520,11 +57474,11 @@ function sanitizeValue2(value) {
57520
57474
  return sanitizeConfigValue(value);
57521
57475
  }
57522
57476
  function readJsonc(path) {
57523
- if (!existsSync50(path))
57477
+ if (!existsSync49(path))
57524
57478
  return { value: {} };
57525
57479
  try {
57526
57480
  return {
57527
- value: import_comment_json12.parse(readFileSync33(path, "utf-8"))
57481
+ value: import_comment_json12.parse(readFileSync32(path, "utf-8"))
57528
57482
  };
57529
57483
  } catch (error) {
57530
57484
  return {
@@ -57540,7 +57494,7 @@ function readConfigDiagnostic(path) {
57540
57494
  const parsed = readJsonc(path);
57541
57495
  return {
57542
57496
  path,
57543
- exists: existsSync50(path),
57497
+ exists: existsSync49(path),
57544
57498
  ...parsed.parseError ? { parseError: parsed.parseError } : {},
57545
57499
  flags: sanitizeValue2(parsed.value)
57546
57500
  };
@@ -57558,7 +57512,7 @@ function reverseSlugToDirectory(slug) {
57558
57512
  }
57559
57513
  function collectPiRecentSessions() {
57560
57514
  const sessionsRoot = getPiSessionsRoot();
57561
- if (!existsSync50(sessionsRoot))
57515
+ if (!existsSync49(sessionsRoot))
57562
57516
  return [];
57563
57517
  try {
57564
57518
  const slugs = readdirSync11(sessionsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
@@ -57567,7 +57521,7 @@ function collectPiRecentSessions() {
57567
57521
  const directory = reverseSlugToDirectory(slug);
57568
57522
  if (!directory)
57569
57523
  continue;
57570
- const slugDir = join41(sessionsRoot, slug);
57524
+ const slugDir = join40(sessionsRoot, slug);
57571
57525
  let files;
57572
57526
  try {
57573
57527
  files = readdirSync11(slugDir).filter((name) => name.endsWith(".jsonl"));
@@ -57576,7 +57530,7 @@ function collectPiRecentSessions() {
57576
57530
  }
57577
57531
  for (const file of files) {
57578
57532
  try {
57579
- const mtime = statSync26(join41(slugDir, file)).mtimeMs;
57533
+ const mtime = statSync26(join40(slugDir, file)).mtimeMs;
57580
57534
  const sessionId = file.replace(/\.jsonl$/, "");
57581
57535
  candidates.push({ sessionId, directory, mtime });
57582
57536
  } catch {}
@@ -57594,7 +57548,7 @@ function collectPiRecentSessions() {
57594
57548
  }
57595
57549
  function parseHistorianDumpMeta2(path) {
57596
57550
  try {
57597
- const xml = readFileSync33(path, "utf-8");
57551
+ const xml = readFileSync32(path, "utf-8");
57598
57552
  const parsed = parseCompartmentOutput(xml);
57599
57553
  const factCountByCategory = {};
57600
57554
  for (const fact of parsed.facts) {
@@ -57627,11 +57581,11 @@ function parseHistorianDumpMeta2(path) {
57627
57581
  }
57628
57582
  }
57629
57583
  function listDumpsInDir2(dir, limit) {
57630
- if (!existsSync50(dir))
57584
+ if (!existsSync49(dir))
57631
57585
  return { count: 0, recent: [] };
57632
57586
  try {
57633
57587
  const entries = readdirSync11(dir).filter((name) => name.endsWith(".xml")).map((name) => {
57634
- const stat = statSync26(join41(dir, name));
57588
+ const stat = statSync26(join40(dir, name));
57635
57589
  return {
57636
57590
  name,
57637
57591
  mtime: stat.mtimeMs,
@@ -57640,7 +57594,7 @@ function listDumpsInDir2(dir, limit) {
57640
57594
  }).sort((a, b) => b.mtime - a.mtime);
57641
57595
  const now = Date.now();
57642
57596
  const recent = entries.slice(0, limit).map((entry) => {
57643
- const meta = parseHistorianDumpMeta2(join41(dir, entry.name));
57597
+ const meta = parseHistorianDumpMeta2(join40(dir, entry.name));
57644
57598
  const summary = {
57645
57599
  name: entry.name,
57646
57600
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -57704,7 +57658,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
57704
57658
  const loaded = loadPiConfig({ cwd });
57705
57659
  const storageResolution = getMagicContextStorageResolution();
57706
57660
  const storageDirPath = storageResolution.path;
57707
- const dbPath = join41(storageDirPath, "context.db");
57661
+ const dbPath = join40(storageDirPath, "context.db");
57708
57662
  const logFiles = inspectMagicContextLogs("pi");
57709
57663
  const primaryLog = logFiles.find((file) => file.exists) ?? logFiles[0];
57710
57664
  const otherPiExtensions = packages.filter((entry) => !isPiMagicContextPackageEntry(entry)).map(describePiPackageEntry);
@@ -57721,7 +57675,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
57721
57675
  piVersion: pi ? getPiVersion(pi.path) : null,
57722
57676
  settings: {
57723
57677
  path: settingsPath,
57724
- exists: existsSync50(settingsPath),
57678
+ exists: existsSync49(settingsPath),
57725
57679
  ...settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {},
57726
57680
  hasMagicContextPackage: hasPiMagicContextPackage(packages),
57727
57681
  packages: sanitizeValue2(packages)
@@ -57738,7 +57692,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
57738
57692
  storageDir: {
57739
57693
  path: storageDirPath,
57740
57694
  source: storageResolution.source,
57741
- exists: existsSync50(storageDirPath),
57695
+ exists: existsSync49(storageDirPath),
57742
57696
  contextDbSizeBytes: fileSize2(dbPath)
57743
57697
  },
57744
57698
  conflicts: {
@@ -57846,7 +57800,7 @@ var init_diagnostics_pi = __esm(() => {
57846
57800
 
57847
57801
  // src/lib/logs-pi.ts
57848
57802
  import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync10 } from "node:fs";
57849
- import { dirname as dirname28, join as join42 } from "node:path";
57803
+ import { dirname as dirname28, join as join41 } from "node:path";
57850
57804
  function formatTimestamp2(date) {
57851
57805
  const pad = (value) => String(value).padStart(2, "0");
57852
57806
  return [
@@ -57900,11 +57854,11 @@ async function bundleIssueReport2(report, description, title, options = {}) {
57900
57854
  const truncated = bodyMarkdown !== rawBodyMarkdown;
57901
57855
  const cwd = options.cwd ?? process.cwd();
57902
57856
  const timestamp = formatTimestamp2(options.now ?? new Date);
57903
- const path = options.outputPath ?? join42(cwd, `magic-context-pi-issue-${timestamp}.md`);
57857
+ const path = options.outputPath ?? join41(cwd, `magic-context-pi-issue-${timestamp}.md`);
57904
57858
  mkdirSync10(dirname28(path), { recursive: true });
57905
57859
  writeFileSync10(path, `${bodyMarkdown}
57906
57860
  `);
57907
- const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join42(cwd, `magic-context-pi-issue-${timestamp}-full.md`) : undefined;
57861
+ const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join41(cwd, `magic-context-pi-issue-${timestamp}-full.md`) : undefined;
57908
57862
  if (fullPath)
57909
57863
  writeFileSync10(fullPath, `${rawBodyMarkdown}
57910
57864
  `);
@@ -57918,10 +57872,10 @@ var init_logs_pi = __esm(() => {
57918
57872
 
57919
57873
  // src/commands/doctor-pi.ts
57920
57874
  import { execFileSync as execFileSync9, spawnSync as spawnSync11 } from "node:child_process";
57921
- import { existsSync as existsSync51, readdirSync as readdirSync12, readFileSync as readFileSync34, rmSync as rmSync10, statSync as statSync27 } from "node:fs";
57875
+ import { existsSync as existsSync50, readdirSync as readdirSync12, readFileSync as readFileSync33, rmSync as rmSync10, statSync as statSync27 } from "node:fs";
57922
57876
  import { createRequire as createRequire8 } from "node:module";
57923
57877
  import { homedir as homedir22 } from "node:os";
57924
- import { isAbsolute as isAbsolute9, join as join43 } from "node:path";
57878
+ import { isAbsolute as isAbsolute9, join as join42 } from "node:path";
57925
57879
  function depsFrom(options) {
57926
57880
  return {
57927
57881
  ...DEFAULT_DEPS5,
@@ -58013,7 +57967,7 @@ function summarize(results) {
58013
57967
  function readJsonc2(path) {
58014
57968
  try {
58015
57969
  return {
58016
- value: import_comment_json13.parse(readFileSync34(path, "utf-8"))
57970
+ value: import_comment_json13.parse(readFileSync33(path, "utf-8"))
58017
57971
  };
58018
57972
  } catch (error) {
58019
57973
  return {
@@ -58063,15 +58017,15 @@ function piPluginDirCandidates(packages, cwd) {
58063
58017
  if (resolved)
58064
58018
  dirs.push(resolved);
58065
58019
  }
58066
- dirs.push(join43(agentDir, "npm", "node_modules", PACKAGE_NAME2));
58067
- dirs.push(join43(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2));
58068
- return dirs.filter((dir) => existsSync51(join43(dir, "package.json")));
58020
+ dirs.push(join42(agentDir, "npm", "node_modules", PACKAGE_NAME2));
58021
+ dirs.push(join42(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2));
58022
+ return dirs.filter((dir) => existsSync50(join42(dir, "package.json")));
58069
58023
  }
58070
58024
  function projectConfigPath(cwd) {
58071
58025
  return resolveCortexKitProjectConfigPath(cwd);
58072
58026
  }
58073
58027
  function readConfigForEmbedding(path, isProjectConfig) {
58074
- if (!existsSync51(path))
58028
+ if (!existsSync50(path))
58075
58029
  return null;
58076
58030
  try {
58077
58031
  const raw = loadRawConfigFile({
@@ -58157,22 +58111,22 @@ function pinnedVersionFromPackageSpecifier(specifier) {
58157
58111
  }
58158
58112
  function cacheRoots(cwd) {
58159
58113
  const home = process.env.HOME?.trim();
58160
- const cacheHome = process.env.XDG_CACHE_HOME || join43(home || homedir22(), ".cache");
58114
+ const cacheHome = process.env.XDG_CACHE_HOME || join42(home || homedir22(), ".cache");
58161
58115
  const piCacheRoot = getPiCacheRoot();
58162
58116
  return [
58163
- join43(piCacheRoot, "extensions"),
58164
- join43(piCacheRoot, "packages"),
58165
- join43(cacheHome, "pi", "extensions"),
58166
- join43(cacheHome, "pi", "packages"),
58167
- join43(getPiAgentConfigDir(), "cache", "extensions"),
58168
- join43(getPiAgentConfigDir(), "npm", "node_modules", PACKAGE_NAME2),
58169
- join43(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2)
58117
+ join42(piCacheRoot, "extensions"),
58118
+ join42(piCacheRoot, "packages"),
58119
+ join42(cacheHome, "pi", "extensions"),
58120
+ join42(cacheHome, "pi", "packages"),
58121
+ join42(getPiAgentConfigDir(), "cache", "extensions"),
58122
+ join42(getPiAgentConfigDir(), "npm", "node_modules", PACKAGE_NAME2),
58123
+ join42(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2)
58170
58124
  ];
58171
58125
  }
58172
58126
  function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
58173
58127
  const found = new Map;
58174
58128
  const visit = (path, depth) => {
58175
- if (depth < 0 || !existsSync51(path))
58129
+ if (depth < 0 || !existsSync50(path))
58176
58130
  return;
58177
58131
  let stat;
58178
58132
  try {
@@ -58182,10 +58136,10 @@ function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
58182
58136
  }
58183
58137
  if (!stat.isDirectory())
58184
58138
  return;
58185
- const packageJson = join43(path, "package.json");
58186
- if (existsSync51(packageJson)) {
58139
+ const packageJson = join42(path, "package.json");
58140
+ if (existsSync50(packageJson)) {
58187
58141
  try {
58188
- const pkg = JSON.parse(readFileSync34(packageJson, "utf-8"));
58142
+ const pkg = JSON.parse(readFileSync33(packageJson, "utf-8"));
58189
58143
  const name = typeof pkg.name === "string" ? pkg.name : "";
58190
58144
  const version = typeof pkg.version === "string" ? pkg.version : undefined;
58191
58145
  if (name === PACKAGE_NAME2) {
@@ -58205,7 +58159,7 @@ function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
58205
58159
  return;
58206
58160
  }
58207
58161
  for (const entry of entries)
58208
- visit(join43(path, entry), depth - 1);
58162
+ visit(join42(path, entry), depth - 1);
58209
58163
  };
58210
58164
  for (const root of cacheRoots(cwd))
58211
58165
  visit(root, 5);
@@ -58266,7 +58220,7 @@ async function runHealthChecks2(options) {
58266
58220
  const settingsPath = getPiUserExtensionsPath();
58267
58221
  let packages = [];
58268
58222
  let piPluginInstalled = false;
58269
- if (!existsSync51(settingsPath)) {
58223
+ if (!existsSync50(settingsPath)) {
58270
58224
  if (pi) {
58271
58225
  add2(results, "info", `${piVersion ? `Pi ${piVersion}` : "Pi"} found; Magic Context is not installed there (run setup to add it)`);
58272
58226
  }
@@ -58308,7 +58262,7 @@ async function runHealthChecks2(options) {
58308
58262
  ["user", userConfigPath, true],
58309
58263
  ["project", projectPath, false]
58310
58264
  ]) {
58311
- if (!existsSync51(path)) {
58265
+ if (!existsSync50(path)) {
58312
58266
  if (required) {
58313
58267
  add2(results, "warn", `No ${label} magic-context.jsonc found at ${path}`);
58314
58268
  if (userConfigMigrationRefused) {
@@ -58355,12 +58309,12 @@ async function runHealthChecks2(options) {
58355
58309
  checkPiModelChains(results, pi, loadedConfig.config, options.deps);
58356
58310
  const storage = getMagicContextStorageResolution();
58357
58311
  const storageDir = storage.path;
58358
- const dbPath = join43(storageDir, "context.db");
58312
+ const dbPath = join42(storageDir, "context.db");
58359
58313
  if (isMagicContextStorageOutsideEngram(storageDir)) {
58360
58314
  add2(results, "warn", `Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
58361
58315
  }
58362
58316
  add2(results, "info", `Shared storage: ${storageDir} (source: ${storage.source})`);
58363
- const existedBeforeOpen = existsSync51(dbPath);
58317
+ const existedBeforeOpen = existsSync50(dbPath);
58364
58318
  if (existedBeforeOpen)
58365
58319
  add2(results, "pass", `Shared context DB exists at ${dbPath}`);
58366
58320
  else
@@ -58589,7 +58543,7 @@ function writeDefaultMagicContextConfig(path) {
58589
58543
  function repair2(plan, prompts) {
58590
58544
  let fixed = 0;
58591
58545
  for (const path of plan.reasoningAgeConfigPaths) {
58592
- const content = readFileSync34(path, "utf8");
58546
+ const content = readFileSync33(path, "utf8");
58593
58547
  const parsed = readJsonc2(path);
58594
58548
  if (parsed.error)
58595
58549
  continue;
@@ -58615,7 +58569,7 @@ function repair2(plan, prompts) {
58615
58569
  }
58616
58570
  if (plan.writeUserConfig) {
58617
58571
  const configPath = getPiUserConfigPath();
58618
- if (!existsSync51(configPath)) {
58572
+ if (!existsSync50(configPath)) {
58619
58573
  try {
58620
58574
  writeDefaultMagicContextConfig(configPath);
58621
58575
  prompts.log.success(`Wrote default Magic Context config to ${configPath}`);
@@ -58669,7 +58623,7 @@ async function runIssueFlow3(options) {
58669
58623
  if (options.reportPath) {
58670
58624
  try {
58671
58625
  const report = await options.deps.collectDiagnostics(options.cwd);
58672
- const outputPath = isAbsolute9(options.reportPath) ? options.reportPath : join43(options.cwd, options.reportPath);
58626
+ const outputPath = isAbsolute9(options.reportPath) ? options.reportPath : join42(options.cwd, options.reportPath);
58673
58627
  const bundled = await bundleIssueReport2(report, "Generated non-interactively by `doctor --issue --report`.", "Magic Context diagnostic report", { cwd: options.cwd, now: options.deps.now(), outputPath });
58674
58628
  options.prompts.log.info(`Report written to ${bundled.path}`);
58675
58629
  return 0;
@@ -58753,7 +58707,7 @@ async function runDoctor3(options = {}) {
58753
58707
  const v22Result = await runV22BackfillCommands({
58754
58708
  name: "Pi",
58755
58709
  openDatabase: (readonly = true) => {
58756
- const dbPath = join43(getMagicContextStorageDir(), "context.db");
58710
+ const dbPath = join42(getMagicContextStorageDir(), "context.db");
58757
58711
  v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
58758
58712
  return v22Db;
58759
58713
  },
@@ -58871,8 +58825,8 @@ var init_doctor_pi = __esm(async () => {
58871
58825
  });
58872
58826
 
58873
58827
  // src/commands/doctor.ts
58874
- import { existsSync as existsSync52, rmSync as rmSync11 } from "node:fs";
58875
- import { join as join44 } from "node:path";
58828
+ import { existsSync as existsSync51, rmSync as rmSync11 } from "node:fs";
58829
+ import { join as join43 } from "node:path";
58876
58830
  async function runDoctor4(options) {
58877
58831
  if (options.clear)
58878
58832
  return runClear();
@@ -58890,7 +58844,7 @@ async function runDoctor4(options) {
58890
58844
  const result = await runV22BackfillCommands({
58891
58845
  name: "Magic Context",
58892
58846
  openDatabase: (readonly = true) => {
58893
- const dbPath = join44(getMagicContextStorageDir(), "context.db");
58847
+ const dbPath = join43(getMagicContextStorageDir(), "context.db");
58894
58848
  v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
58895
58849
  return v22Db;
58896
58850
  },
@@ -58910,7 +58864,7 @@ async function runDoctor4(options) {
58910
58864
  log3.warn(`Identity split check unavailable: ${error instanceof Error ? error.message : String(error)}`);
58911
58865
  }
58912
58866
  await init_migrate();
58913
- const sweepDbPath = join44(getMagicContextStorageDir(), "context.db");
58867
+ const sweepDbPath = join43(getMagicContextStorageDir(), "context.db");
58914
58868
  let sweepDb = null;
58915
58869
  try {
58916
58870
  sweepDb = openExistingContextDatabaseForMutation(sweepDbPath);
@@ -59027,7 +58981,7 @@ async function runClear() {
59027
58981
  failed += 1;
59028
58982
  continue;
59029
58983
  }
59030
- } else if (existsSync52(item.path)) {
58984
+ } else if (existsSync51(item.path)) {
59031
58985
  rmSync11(item.path, { recursive: true, force: true });
59032
58986
  }
59033
58987
  s.stop(`Cleared ${item.path}`);