@cortexkit/magic-context 0.21.0 → 0.21.1

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 +277 -246
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7805,6 +7805,45 @@ var require_src2 = __commonJS((exports, module) => {
7805
7805
  };
7806
7806
  });
7807
7807
 
7808
+ // src/lib/find-on-path.ts
7809
+ import { accessSync, constants, existsSync, statSync } from "node:fs";
7810
+ import { delimiter, join } from "node:path";
7811
+ function findOnPath(binary) {
7812
+ const PATH = process.env.PATH;
7813
+ if (typeof PATH !== "string" || PATH.length === 0)
7814
+ return null;
7815
+ const isWindows = process.platform === "win32";
7816
+ const dirs = PATH.split(delimiter);
7817
+ const candidates = isWindows ? [`${binary}.exe`, `${binary}.cmd`, `${binary}.bat`, `${binary}.com`] : [binary];
7818
+ for (const dir of dirs) {
7819
+ if (!dir)
7820
+ continue;
7821
+ for (const candidate of candidates) {
7822
+ const fullPath = join(dir, candidate);
7823
+ if (isExecutable(fullPath, isWindows))
7824
+ return fullPath;
7825
+ }
7826
+ }
7827
+ return null;
7828
+ }
7829
+ function isExecutable(path, isWindows) {
7830
+ try {
7831
+ if (!existsSync(path))
7832
+ return false;
7833
+ const st = statSync(path);
7834
+ if (!st.isFile())
7835
+ return false;
7836
+ if (isWindows) {
7837
+ return true;
7838
+ }
7839
+ accessSync(path, constants.X_OK);
7840
+ return true;
7841
+ } catch {
7842
+ return false;
7843
+ }
7844
+ }
7845
+ var init_find_on_path = () => {};
7846
+
7808
7847
  // ../plugin/src/shared/harness.ts
7809
7848
  function getHarness() {
7810
7849
  return currentHarness;
@@ -7850,28 +7889,28 @@ function getOpenCodeCacheDir() {
7850
7889
  var init_data_path = () => {};
7851
7890
 
7852
7891
  // src/lib/paths.ts
7853
- import { existsSync, readdirSync, statSync } from "node:fs";
7892
+ import { existsSync as existsSync2, readdirSync, statSync as statSync2 } from "node:fs";
7854
7893
  import { homedir as homedir2 } from "node:os";
7855
- import { join as join2 } from "node:path";
7894
+ import { join as join3 } from "node:path";
7856
7895
  function getOpenCodeConfigDir() {
7857
7896
  const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
7858
7897
  if (envDir)
7859
7898
  return envDir;
7860
7899
  if (process.platform === "win32") {
7861
- return join2(homedir2(), ".config", "opencode");
7900
+ return join3(homedir2(), ".config", "opencode");
7862
7901
  }
7863
- const xdgConfig = process.env.XDG_CONFIG_HOME || join2(homedir2(), ".config");
7864
- return join2(xdgConfig, "opencode");
7902
+ const xdgConfig = process.env.XDG_CONFIG_HOME || join3(homedir2(), ".config");
7903
+ return join3(xdgConfig, "opencode");
7865
7904
  }
7866
7905
  function findOmoConfig(configDir) {
7867
7906
  const locations = [
7868
- join2(configDir, "oh-my-openagent.jsonc"),
7869
- join2(configDir, "oh-my-openagent.json"),
7870
- join2(configDir, "oh-my-opencode.jsonc"),
7871
- join2(configDir, "oh-my-opencode.json")
7907
+ join3(configDir, "oh-my-openagent.jsonc"),
7908
+ join3(configDir, "oh-my-openagent.json"),
7909
+ join3(configDir, "oh-my-opencode.jsonc"),
7910
+ join3(configDir, "oh-my-opencode.json")
7872
7911
  ];
7873
7912
  for (const loc of locations) {
7874
- if (existsSync(loc))
7913
+ if (existsSync2(loc))
7875
7914
  return loc;
7876
7915
  }
7877
7916
  return null;
@@ -7882,24 +7921,24 @@ function detectConfigPaths() {
7882
7921
  let opencodeConfigFormat;
7883
7922
  let tuiConfig;
7884
7923
  let tuiConfigFormat;
7885
- const jsoncPath = join2(configDir, "opencode.jsonc");
7886
- const jsonPath = join2(configDir, "opencode.json");
7887
- if (existsSync(jsoncPath)) {
7924
+ const jsoncPath = join3(configDir, "opencode.jsonc");
7925
+ const jsonPath = join3(configDir, "opencode.json");
7926
+ if (existsSync2(jsoncPath)) {
7888
7927
  opencodeConfig = jsoncPath;
7889
7928
  opencodeConfigFormat = "jsonc";
7890
- } else if (existsSync(jsonPath)) {
7929
+ } else if (existsSync2(jsonPath)) {
7891
7930
  opencodeConfig = jsonPath;
7892
7931
  opencodeConfigFormat = "json";
7893
7932
  } else {
7894
7933
  opencodeConfig = jsonPath;
7895
7934
  opencodeConfigFormat = "none";
7896
7935
  }
7897
- const tuiJsoncPath = join2(configDir, "tui.jsonc");
7898
- const tuiJsonPath = join2(configDir, "tui.json");
7899
- if (existsSync(tuiJsoncPath)) {
7936
+ const tuiJsoncPath = join3(configDir, "tui.jsonc");
7937
+ const tuiJsonPath = join3(configDir, "tui.json");
7938
+ if (existsSync2(tuiJsoncPath)) {
7900
7939
  tuiConfig = tuiJsoncPath;
7901
7940
  tuiConfigFormat = "jsonc";
7902
- } else if (existsSync(tuiJsonPath)) {
7941
+ } else if (existsSync2(tuiJsonPath)) {
7903
7942
  tuiConfig = tuiJsonPath;
7904
7943
  tuiConfigFormat = "json";
7905
7944
  } else {
@@ -7910,7 +7949,7 @@ function detectConfigPaths() {
7910
7949
  configDir,
7911
7950
  opencodeConfig,
7912
7951
  opencodeConfigFormat,
7913
- magicContextConfig: join2(configDir, "magic-context.jsonc"),
7952
+ magicContextConfig: join3(configDir, "magic-context.jsonc"),
7914
7953
  omoConfig: findOmoConfig(configDir),
7915
7954
  tuiConfig,
7916
7955
  tuiConfigFormat
@@ -7920,13 +7959,13 @@ function getPiAgentConfigDir() {
7920
7959
  const envDir = process.env.PI_CODING_AGENT_DIR?.trim();
7921
7960
  if (envDir)
7922
7961
  return envDir;
7923
- return join2(homedir2(), ".pi", "agent");
7962
+ return join3(homedir2(), ".pi", "agent");
7924
7963
  }
7925
7964
  function getPiUserConfigPath() {
7926
- return join2(getPiAgentConfigDir(), "magic-context.jsonc");
7965
+ return join3(getPiAgentConfigDir(), "magic-context.jsonc");
7927
7966
  }
7928
7967
  function getPiUserExtensionsPath() {
7929
- return join2(getPiAgentConfigDir(), "settings.json");
7968
+ return join3(getPiAgentConfigDir(), "settings.json");
7930
7969
  }
7931
7970
  function getMagicContextLogPath2(harness) {
7932
7971
  return getMagicContextLogPath(harness);
@@ -7935,12 +7974,12 @@ function getMagicContextHistorianDir2(harness) {
7935
7974
  return getMagicContextHistorianDir(harness);
7936
7975
  }
7937
7976
  function getOpenCodePluginCacheDir() {
7938
- const xdg = process.env.XDG_CACHE_HOME || join2(homedir2(), ".cache");
7939
- return join2(xdg, "opencode", "packages");
7977
+ const xdg = process.env.XDG_CACHE_HOME || join3(homedir2(), ".cache");
7978
+ return join3(xdg, "opencode", "packages");
7940
7979
  }
7941
7980
  function isDir(path2) {
7942
7981
  try {
7943
- return statSync(path2).isDirectory();
7982
+ return statSync2(path2).isDirectory();
7944
7983
  } catch {
7945
7984
  return false;
7946
7985
  }
@@ -7957,12 +7996,12 @@ function dirSizeBytes(path2) {
7957
7996
  try {
7958
7997
  const entries = readdirSync(cur, { withFileTypes: true });
7959
7998
  for (const entry of entries) {
7960
- const child = join2(cur, entry.name);
7999
+ const child = join3(cur, entry.name);
7961
8000
  if (entry.isDirectory()) {
7962
8001
  stack.push(child);
7963
8002
  } else if (entry.isFile()) {
7964
8003
  try {
7965
- total += statSync(child).size;
8004
+ total += statSync2(child).size;
7966
8005
  } catch {}
7967
8006
  }
7968
8007
  }
@@ -7975,10 +8014,9 @@ var init_paths = __esm(() => {
7975
8014
  });
7976
8015
 
7977
8016
  // src/adapters/opencode.ts
7978
- import { execFileSync } from "node:child_process";
7979
- import { existsSync as existsSync2, readFileSync, writeFileSync } from "node:fs";
8017
+ import { existsSync as existsSync3, readFileSync, writeFileSync } from "node:fs";
7980
8018
  import { homedir as homedir3 } from "node:os";
7981
- import { dirname, join as join3 } from "node:path";
8019
+ import { dirname, join as join4 } from "node:path";
7982
8020
 
7983
8021
  class OpenCodeAdapter {
7984
8022
  kind = "opencode";
@@ -7986,20 +8024,10 @@ class OpenCodeAdapter {
7986
8024
  pluginPackageName = PLUGIN_NAME;
7987
8025
  isInstalled() {
7988
8026
  const isWindows = process.platform === "win32";
7989
- const stockBin = isWindows ? join3(homedir3(), ".opencode", "bin", "opencode.exe") : join3(homedir3(), ".opencode", "bin", "opencode");
7990
- if (existsSync2(stockBin))
7991
- return true;
7992
- const probe = isWindows ? { cmd: "where", args: ["opencode"] } : { cmd: "command", args: ["-v", "opencode"] };
7993
- try {
7994
- if (!isWindows) {
7995
- execFileSync("which", ["opencode"], { stdio: "ignore" });
7996
- } else {
7997
- execFileSync(probe.cmd, probe.args, { stdio: "ignore" });
7998
- }
8027
+ const stockBin = isWindows ? join4(homedir3(), ".opencode", "bin", "opencode.exe") : join4(homedir3(), ".opencode", "bin", "opencode");
8028
+ if (existsSync3(stockBin))
7999
8029
  return true;
8000
- } catch {
8001
- return false;
8002
- }
8030
+ return findOnPath("opencode") !== null;
8003
8031
  }
8004
8032
  hasPluginEntry() {
8005
8033
  const paths = detectConfigPaths();
@@ -8164,7 +8192,7 @@ class OpenCodeAdapter {
8164
8192
  const path2 = getOpenCodePluginCacheDir();
8165
8193
  return {
8166
8194
  path: path2,
8167
- exists: existsSync2(path2),
8195
+ exists: existsSync3(path2),
8168
8196
  sizeBytes: dirSizeBytes(path2)
8169
8197
  };
8170
8198
  }
@@ -8178,7 +8206,7 @@ class OpenCodeAdapter {
8178
8206
  `${cacheDir}/${PLUGIN_NAME}/node_modules/${PLUGIN_NAME}/package.json`
8179
8207
  ];
8180
8208
  for (const candidate of candidates) {
8181
- if (!existsSync2(candidate))
8209
+ if (!existsSync3(candidate))
8182
8210
  continue;
8183
8211
  try {
8184
8212
  const raw = readFileSync(candidate, "utf-8");
@@ -8219,29 +8247,30 @@ function matchesPluginEntry(entry, pkgName) {
8219
8247
  }
8220
8248
  function ensureDir(filePath) {
8221
8249
  const dir = dirname(filePath);
8222
- if (!existsSync2(dir)) {
8250
+ if (!existsSync3(dir)) {
8223
8251
  const { mkdirSync } = __require("node:fs");
8224
8252
  mkdirSync(dir, { recursive: true });
8225
8253
  }
8226
8254
  }
8227
8255
  var import_comment_json, PLUGIN_NAME = "@cortexkit/opencode-magic-context", PLUGIN_ENTRY;
8228
8256
  var init_opencode = __esm(() => {
8257
+ init_find_on_path();
8229
8258
  init_paths();
8230
8259
  import_comment_json = __toESM(require_src2(), 1);
8231
8260
  PLUGIN_ENTRY = `${PLUGIN_NAME}@latest`;
8232
8261
  });
8233
8262
 
8234
8263
  // src/lib/pi-helpers.ts
8235
- import { execFileSync as execFileSync2, spawnSync } from "node:child_process";
8236
- import { existsSync as existsSync3 } from "node:fs";
8264
+ import { execFileSync, spawnSync } from "node:child_process";
8265
+ import { existsSync as existsSync4 } from "node:fs";
8237
8266
  import { homedir as homedir4 } from "node:os";
8238
- import { join as join4 } from "node:path";
8267
+ import { join as join5 } from "node:path";
8239
8268
  function getStaticModels() {
8240
8269
  return [...STATIC_MODELS];
8241
8270
  }
8242
8271
  function commandExists(command, args) {
8243
8272
  try {
8244
- const output = execFileSync2(command, args, {
8273
+ const output = execFileSync(command, args, {
8245
8274
  encoding: "utf-8",
8246
8275
  stdio: ["ignore", "pipe", "ignore"]
8247
8276
  }).trim();
@@ -8257,8 +8286,8 @@ function detectPiBinary() {
8257
8286
  if (first)
8258
8287
  return { path: first, source: "path" };
8259
8288
  }
8260
- const homeCandidate = process.platform === "win32" ? join4(homedir4(), ".pi", "bin", "pi.cmd") : join4(homedir4(), ".pi", "bin", "pi");
8261
- if (existsSync3(homeCandidate))
8289
+ const homeCandidate = process.platform === "win32" ? join5(homedir4(), ".pi", "bin", "pi.cmd") : join5(homedir4(), ".pi", "bin", "pi");
8290
+ if (existsSync4(homeCandidate))
8262
8291
  return { path: homeCandidate, source: "home" };
8263
8292
  return null;
8264
8293
  }
@@ -8281,7 +8310,7 @@ function getPiVersion(piPath) {
8281
8310
  }
8282
8311
  function runPi(piPath, args) {
8283
8312
  try {
8284
- return execFileSync2(piPath, args, {
8313
+ return execFileSync(piPath, args, {
8285
8314
  encoding: "utf-8",
8286
8315
  stdio: ["ignore", "pipe", "ignore"],
8287
8316
  timeout: 20000
@@ -8408,8 +8437,8 @@ var init_pi_helpers = __esm(() => {
8408
8437
  });
8409
8438
 
8410
8439
  // src/adapters/pi.ts
8411
- import { execFileSync as execFileSync3 } from "node:child_process";
8412
- import { existsSync as existsSync4, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
8440
+ import { execFileSync as execFileSync2 } from "node:child_process";
8441
+ import { existsSync as existsSync5, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
8413
8442
  import { dirname as dirname2 } from "node:path";
8414
8443
 
8415
8444
  class PiAdapter {
@@ -8519,7 +8548,7 @@ class PiAdapter {
8519
8548
  if (!piBin)
8520
8549
  return null;
8521
8550
  try {
8522
- const output = execFileSync3(piBin.path, ["list"], {
8551
+ const output = execFileSync2(piBin.path, ["list"], {
8523
8552
  encoding: "utf-8",
8524
8553
  stdio: ["ignore", "pipe", "ignore"],
8525
8554
  timeout: 5000
@@ -8534,7 +8563,7 @@ class PiAdapter {
8534
8563
  }
8535
8564
  function readPiSettings() {
8536
8565
  const settingsPath = getPiUserExtensionsPath();
8537
- if (!existsSync4(settingsPath))
8566
+ if (!existsSync5(settingsPath))
8538
8567
  return null;
8539
8568
  try {
8540
8569
  const raw = readFileSync2(settingsPath, "utf-8");
@@ -8568,7 +8597,7 @@ function matchesPiPackage(entry) {
8568
8597
  }
8569
8598
  function ensureDir2(filePath) {
8570
8599
  const dir = dirname2(filePath);
8571
- if (!existsSync4(dir)) {
8600
+ if (!existsSync5(dir)) {
8572
8601
  const { mkdirSync } = __require("node:fs");
8573
8602
  mkdirSync(dir, { recursive: true });
8574
8603
  }
@@ -10260,7 +10289,7 @@ var init_harness_select = __esm(() => {
10260
10289
  });
10261
10290
 
10262
10291
  // ../plugin/src/shared/jsonc-parser.ts
10263
- import { existsSync as existsSync5, readFileSync as readFileSync3 } from "node:fs";
10292
+ import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
10264
10293
  function stripJsonComments(content) {
10265
10294
  let result = "";
10266
10295
  let inString = false;
@@ -10365,10 +10394,10 @@ function readJsoncFile(filePath) {
10365
10394
  function detectConfigFile(basePath) {
10366
10395
  const jsoncPath = `${basePath}.jsonc`;
10367
10396
  const jsonPath = `${basePath}.json`;
10368
- if (existsSync5(jsoncPath)) {
10397
+ if (existsSync6(jsoncPath)) {
10369
10398
  return { format: "jsonc", path: jsoncPath };
10370
10399
  }
10371
- if (existsSync5(jsonPath)) {
10400
+ if (existsSync6(jsonPath)) {
10372
10401
  return { format: "json", path: jsonPath };
10373
10402
  }
10374
10403
  return { format: "none", path: jsoncPath };
@@ -10377,16 +10406,16 @@ var init_jsonc_parser = () => {};
10377
10406
 
10378
10407
  // ../plugin/src/shared/opencode-config-dir.ts
10379
10408
  import { homedir as homedir5 } from "node:os";
10380
- import { join as join5, resolve } from "node:path";
10409
+ import { join as join6, resolve } from "node:path";
10381
10410
  function getCliConfigDir() {
10382
10411
  const envConfigDir = process.env.OPENCODE_CONFIG_DIR?.trim();
10383
10412
  if (envConfigDir) {
10384
10413
  return resolve(envConfigDir);
10385
10414
  }
10386
10415
  if (process.platform === "win32") {
10387
- return join5(homedir5(), ".config", "opencode");
10416
+ return join6(homedir5(), ".config", "opencode");
10388
10417
  }
10389
- return join5(process.env.XDG_CONFIG_HOME || join5(homedir5(), ".config"), "opencode");
10418
+ return join6(process.env.XDG_CONFIG_HOME || join6(homedir5(), ".config"), "opencode");
10390
10419
  }
10391
10420
  function getOpenCodeConfigDir2(_options) {
10392
10421
  return getCliConfigDir();
@@ -10395,16 +10424,16 @@ function getOpenCodeConfigPaths(options) {
10395
10424
  const configDir = getOpenCodeConfigDir2(options);
10396
10425
  return {
10397
10426
  configDir,
10398
- configJson: join5(configDir, "opencode.json"),
10399
- configJsonc: join5(configDir, "opencode.jsonc"),
10400
- packageJson: join5(configDir, "package.json"),
10401
- omoConfig: join5(configDir, "magic-context.jsonc")
10427
+ configJson: join6(configDir, "opencode.json"),
10428
+ configJsonc: join6(configDir, "opencode.jsonc"),
10429
+ packageJson: join6(configDir, "package.json"),
10430
+ omoConfig: join6(configDir, "magic-context.jsonc")
10402
10431
  };
10403
10432
  }
10404
10433
  var init_opencode_config_dir = () => {};
10405
10434
 
10406
10435
  // ../plugin/src/shared/conflict-detector.ts
10407
- import { join as join6 } from "node:path";
10436
+ import { join as join7 } from "node:path";
10408
10437
  function detectConflicts(directory) {
10409
10438
  const conflicts = {
10410
10439
  compactionAuto: false,
@@ -10461,8 +10490,8 @@ function checkCompaction(directory) {
10461
10490
  return { auto: true, prune: false };
10462
10491
  }
10463
10492
  function readProjectCompaction(directory) {
10464
- const dotOcJsonc = join6(directory, ".opencode", "opencode.jsonc");
10465
- const dotOcJson = join6(directory, ".opencode", "opencode.json");
10493
+ const dotOcJsonc = join7(directory, ".opencode", "opencode.jsonc");
10494
+ const dotOcJson = join7(directory, ".opencode", "opencode.json");
10466
10495
  const dotOcConfig = readJsoncFile(dotOcJsonc) ?? readJsoncFile(dotOcJson);
10467
10496
  if (dotOcConfig?.compaction) {
10468
10497
  const c2 = dotOcConfig.compaction;
@@ -10470,8 +10499,8 @@ function readProjectCompaction(directory) {
10470
10499
  return { auto: c2.auto === true, prune: c2.prune === true, resolved: true };
10471
10500
  }
10472
10501
  }
10473
- const rootJsonc = join6(directory, "opencode.jsonc");
10474
- const rootJson = join6(directory, "opencode.json");
10502
+ const rootJsonc = join7(directory, "opencode.jsonc");
10503
+ const rootJson = join7(directory, "opencode.json");
10475
10504
  const rootConfig = readJsoncFile(rootJsonc) ?? readJsoncFile(rootJson);
10476
10505
  if (rootConfig?.compaction) {
10477
10506
  const c2 = rootConfig.compaction;
@@ -10525,10 +10554,10 @@ function collectPluginEntries(directory) {
10525
10554
  }
10526
10555
  };
10527
10556
  for (const configPath of [
10528
- join6(directory, ".opencode", "opencode.jsonc"),
10529
- join6(directory, ".opencode", "opencode.json"),
10530
- join6(directory, "opencode.jsonc"),
10531
- join6(directory, "opencode.json")
10557
+ join7(directory, ".opencode", "opencode.jsonc"),
10558
+ join7(directory, ".opencode", "opencode.json"),
10559
+ join7(directory, "opencode.jsonc"),
10560
+ join7(directory, "opencode.json")
10532
10561
  ]) {
10533
10562
  const config = readJsoncFile(configPath);
10534
10563
  pushFrom(config?.plugin);
@@ -10569,7 +10598,7 @@ function readOmoDisabledHooks(directory) {
10569
10598
  try {
10570
10599
  const paths = getOpenCodeConfigPaths({ binary: "opencode" });
10571
10600
  for (const name of configNames) {
10572
- const configPath = join6(paths.configDir, name);
10601
+ const configPath = join7(paths.configDir, name);
10573
10602
  const config = readJsoncFile(configPath);
10574
10603
  if (config?.disabled_hooks) {
10575
10604
  for (const hook of config.disabled_hooks) {
@@ -10579,7 +10608,7 @@ function readOmoDisabledHooks(directory) {
10579
10608
  }
10580
10609
  } catch {}
10581
10610
  for (const name of configNames) {
10582
- const config = readJsoncFile(join6(directory, name));
10611
+ const config = readJsoncFile(join7(directory, name));
10583
10612
  if (config?.disabled_hooks) {
10584
10613
  for (const hook of config.disabled_hooks) {
10585
10614
  disabled.add(hook);
@@ -10597,8 +10626,8 @@ var init_conflict_detector = __esm(() => {
10597
10626
  });
10598
10627
 
10599
10628
  // ../plugin/src/shared/conflict-fixer.ts
10600
- import { existsSync as existsSync6, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
10601
- import { join as join7 } from "node:path";
10629
+ import { existsSync as existsSync7, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
10630
+ import { join as join8 } from "node:path";
10602
10631
  function isRecord(value) {
10603
10632
  return typeof value === "object" && value !== null && !Array.isArray(value);
10604
10633
  }
@@ -10606,7 +10635,7 @@ function asStringArray(value) {
10606
10635
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
10607
10636
  }
10608
10637
  function readConfig(filePath) {
10609
- if (!existsSync6(filePath)) {
10638
+ if (!existsSync7(filePath)) {
10610
10639
  return null;
10611
10640
  }
10612
10641
  try {
@@ -10622,23 +10651,23 @@ function writeConfig(filePath, config) {
10622
10651
  }
10623
10652
  function resolveUserOpenCodeConfigPath() {
10624
10653
  const paths = getOpenCodeConfigPaths({ binary: "opencode" });
10625
- if (existsSync6(paths.configJsonc))
10654
+ if (existsSync7(paths.configJsonc))
10626
10655
  return paths.configJsonc;
10627
10656
  return paths.configJson;
10628
10657
  }
10629
10658
  function collectOpenCodeConfigPaths(directory) {
10630
10659
  const paths = new Set;
10631
10660
  const userConfig = resolveUserOpenCodeConfigPath();
10632
- if (existsSync6(userConfig)) {
10661
+ if (existsSync7(userConfig)) {
10633
10662
  paths.add(userConfig);
10634
10663
  }
10635
10664
  for (const filePath of [
10636
- join7(directory, ".opencode", "opencode.jsonc"),
10637
- join7(directory, ".opencode", "opencode.json"),
10638
- join7(directory, "opencode.jsonc"),
10639
- join7(directory, "opencode.json")
10665
+ join8(directory, ".opencode", "opencode.jsonc"),
10666
+ join8(directory, ".opencode", "opencode.json"),
10667
+ join8(directory, "opencode.jsonc"),
10668
+ join8(directory, "opencode.json")
10640
10669
  ]) {
10641
- if (existsSync6(filePath)) {
10670
+ if (existsSync7(filePath)) {
10642
10671
  paths.add(filePath);
10643
10672
  }
10644
10673
  }
@@ -10648,12 +10677,12 @@ function collectOmoConfigPaths(directory) {
10648
10677
  const paths = new Set;
10649
10678
  const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
10650
10679
  for (const fileName of OMO_CONFIG_NAMES) {
10651
- const userPath = join7(configDir, fileName);
10652
- const projectPath = join7(directory, fileName);
10653
- if (existsSync6(userPath)) {
10680
+ const userPath = join8(configDir, fileName);
10681
+ const projectPath = join8(directory, fileName);
10682
+ if (existsSync7(userPath)) {
10654
10683
  paths.add(userPath);
10655
10684
  }
10656
- if (existsSync6(projectPath)) {
10685
+ if (existsSync7(projectPath)) {
10657
10686
  paths.add(projectPath);
10658
10687
  }
10659
10688
  }
@@ -10847,10 +10876,10 @@ function buildModelSelection2(allModels, role) {
10847
10876
  var init_opencode_helpers = () => {};
10848
10877
 
10849
10878
  // src/commands/setup-opencode.ts
10850
- import { existsSync as existsSync7, mkdirSync, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
10879
+ import { existsSync as existsSync8, mkdirSync, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
10851
10880
  import { dirname as dirname3 } from "node:path";
10852
10881
  function ensureDir3(dir) {
10853
- if (!existsSync7(dir)) {
10882
+ if (!existsSync8(dir)) {
10854
10883
  mkdirSync(dir, { recursive: true });
10855
10884
  }
10856
10885
  }
@@ -10949,7 +10978,7 @@ async function resolveDcpConflictBeforeSetup(configPath, format) {
10949
10978
  }
10950
10979
  }
10951
10980
  function writeMagicContextConfig(configPath, options) {
10952
- const config = (existsSync7(configPath) ? readJsonc(configPath) : null) ?? {};
10981
+ const config = (existsSync8(configPath) ? readJsonc(configPath) : null) ?? {};
10953
10982
  if (!config.$schema) {
10954
10983
  config.$schema = "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json";
10955
10984
  }
@@ -11015,7 +11044,7 @@ async function runSetup() {
11015
11044
  log.warn("You can configure models manually in magic-context.jsonc later");
11016
11045
  }
11017
11046
  const paths = detectConfigPaths();
11018
- const hadExistingSetup = paths.opencodeConfigFormat !== "none" || existsSync7(paths.magicContextConfig) || paths.tuiConfigFormat !== "none";
11047
+ const hadExistingSetup = paths.opencodeConfigFormat !== "none" || existsSync8(paths.magicContextConfig) || paths.tuiConfigFormat !== "none";
11019
11048
  await resolveDcpConflictBeforeSetup(paths.opencodeConfig, paths.opencodeConfigFormat);
11020
11049
  addPluginToOpenCodeConfig(paths.opencodeConfig, paths.opencodeConfigFormat);
11021
11050
  log.success(`Plugin added to ${paths.opencodeConfig}`);
@@ -11216,10 +11245,10 @@ var init_pi_package_entry = __esm(() => {
11216
11245
  });
11217
11246
 
11218
11247
  // src/commands/setup-pi.ts
11219
- import { existsSync as existsSync8, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "node:fs";
11248
+ import { existsSync as existsSync9, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "node:fs";
11220
11249
  import { dirname as dirname4 } from "node:path";
11221
11250
  function ensureDir4(path2) {
11222
- if (!existsSync8(path2))
11251
+ if (!existsSync9(path2))
11223
11252
  mkdirSync2(path2, { recursive: true });
11224
11253
  }
11225
11254
  async function getDefaultPrompts() {
@@ -11261,7 +11290,7 @@ function comparePiVersion(a, b2) {
11261
11290
  }
11262
11291
  function writePiSettingsPackage(settingsPath, packageSource = PI_PACKAGE_SOURCE) {
11263
11292
  ensureDir4(dirname4(settingsPath));
11264
- const settings = existsSync8(settingsPath) ? readJsonc2(settingsPath) ?? {} : {};
11293
+ const settings = existsSync9(settingsPath) ? readJsonc2(settingsPath) ?? {} : {};
11265
11294
  const packages = Array.isArray(settings.packages) ? settings.packages : [];
11266
11295
  const hasPackage = hasPiMagicContextPackage(packages);
11267
11296
  if (!hasPackage)
@@ -11273,7 +11302,7 @@ function writePiSettingsPackage(settingsPath, packageSource = PI_PACKAGE_SOURCE)
11273
11302
  }
11274
11303
  function writeMagicContextConfig2(configPath, options) {
11275
11304
  ensureDir4(dirname4(configPath));
11276
- const config = existsSync8(configPath) ? readJsonc2(configPath) ?? {} : {};
11305
+ const config = existsSync9(configPath) ? readJsonc2(configPath) ?? {} : {};
11277
11306
  if (!config.$schema) {
11278
11307
  config.$schema = "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json";
11279
11308
  }
@@ -11752,7 +11781,7 @@ var exports_native_binding = {};
11752
11781
  __export(exports_native_binding, {
11753
11782
  resolveBetterSqliteNativeBinding: () => resolveBetterSqliteNativeBinding
11754
11783
  });
11755
- import { existsSync as existsSync9, mkdirSync as mkdirSync4, writeFileSync as writeFileSync6 } from "node:fs";
11784
+ import { existsSync as existsSync10, mkdirSync as mkdirSync4, writeFileSync as writeFileSync6 } from "node:fs";
11756
11785
  import { createRequire as createRequire2 } from "node:module";
11757
11786
  import * as path3 from "node:path";
11758
11787
  function logInfo(message) {
@@ -11833,7 +11862,7 @@ async function resolveBetterSqliteNativeBinding() {
11833
11862
  return null;
11834
11863
  }
11835
11864
  const { binaryPath: diskPath, pkgVersion } = resolved;
11836
- if (existsSync9(diskPath)) {
11865
+ if (existsSync10(diskPath)) {
11837
11866
  const diskProbe = probeAbi(diskPath);
11838
11867
  if (diskProbe.ok) {
11839
11868
  logInfo(`on-disk binary already matches Electron ABI v${expected}; using default bindings() lookup`);
@@ -11844,7 +11873,7 @@ async function resolveBetterSqliteNativeBinding() {
11844
11873
  logWarn(`expected better-sqlite3 binary not found at ${diskPath}; will fetch Electron prebuild anyway`);
11845
11874
  }
11846
11875
  const cachedPath = getCachedBinaryPath(pkgVersion, expected);
11847
- if (existsSync9(cachedPath)) {
11876
+ if (existsSync10(cachedPath)) {
11848
11877
  const cachedProbe = probeAbi(cachedPath);
11849
11878
  if (cachedProbe.ok) {
11850
11879
  logInfo(`using cached Electron prebuild at ${cachedPath}`);
@@ -11914,20 +11943,20 @@ __export(exports_migrate, {
11914
11943
  formatPiFilenameTimestamp: () => formatPiFilenameTimestamp
11915
11944
  });
11916
11945
  import { randomBytes } from "node:crypto";
11917
- import { existsSync as existsSync10, mkdirSync as mkdirSync5, writeFileSync as writeFileSync7 } from "node:fs";
11946
+ import { existsSync as existsSync11, mkdirSync as mkdirSync5, writeFileSync as writeFileSync7 } from "node:fs";
11918
11947
  import { homedir as homedir6 } from "node:os";
11919
- import { join as join9 } from "node:path";
11948
+ import { join as join10 } from "node:path";
11920
11949
  function defaultOpenCodeDbPath() {
11921
- return join9(homedir6(), ".local", "share", "opencode", "opencode.db");
11950
+ return join10(homedir6(), ".local", "share", "opencode", "opencode.db");
11922
11951
  }
11923
11952
  function defaultCortexkitDbPath() {
11924
- return join9(getMagicContextStorageDir(), "context.db");
11953
+ return join10(getMagicContextStorageDir(), "context.db");
11925
11954
  }
11926
11955
  function defaultPiSessionsRoot() {
11927
- return join9(homedir6(), ".pi", "agent", "sessions");
11956
+ return join10(homedir6(), ".pi", "agent", "sessions");
11928
11957
  }
11929
11958
  function defaultFs() {
11930
- return { existsSync: existsSync10, mkdirSync: mkdirSync5, writeFileSync: writeFileSync7 };
11959
+ return { existsSync: existsSync11, mkdirSync: mkdirSync5, writeFileSync: writeFileSync7 };
11931
11960
  }
11932
11961
  function stmt(db, sql) {
11933
11962
  return db.prepare(sql);
@@ -12350,7 +12379,7 @@ function migrateOpenCodeSessionToPi(opts) {
12350
12379
  const provider = opts.provider ?? model.provider;
12351
12380
  const modelId = opts.modelId ?? model.modelId;
12352
12381
  const cwd = session.directory ?? session.path ?? process.cwd();
12353
- const outputDir = join9(piSessionsRoot, projectPathToPiDirSlug(cwd));
12382
+ const outputDir = join10(piSessionsRoot, projectPathToPiDirSlug(cwd));
12354
12383
  const buildResult = buildPiEntries({
12355
12384
  session,
12356
12385
  messages,
@@ -12376,7 +12405,7 @@ function migrateOpenCodeSessionToPi(opts) {
12376
12405
  });
12377
12406
  }
12378
12407
  const compactionMarker = insertCompactionMarker(buildResult.entries, copyResult.lastCompartmentEndPiEntryId);
12379
- const outputPath = join9(outputDir, `${formatPiFilenameTimestamp(now)}_${buildResult.piSessionId}.jsonl`);
12408
+ const outputPath = join10(outputDir, `${formatPiFilenameTimestamp(now)}_${buildResult.piSessionId}.jsonl`);
12380
12409
  const jsonl = `${buildResult.entries.map((entry) => JSON.stringify(entry)).join(`
12381
12410
  `)}
12382
12411
  `;
@@ -13597,8 +13626,8 @@ var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, extendedDuration, guid, uui
13597
13626
  if (!version)
13598
13627
  return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
13599
13628
  return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
13600
- }, uuid4, uuid6, uuid7, email, html5Email, rfc5322Email, unicodeEmail, idnEmail, browserEmail, _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`, ipv4, ipv6, mac = (delimiter) => {
13601
- const escapedDelim = escapeRegex(delimiter ?? ":");
13629
+ }, uuid4, uuid6, uuid7, email, html5Email, rfc5322Email, unicodeEmail, idnEmail, browserEmail, _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`, ipv4, ipv6, mac = (delimiter2) => {
13630
+ const escapedDelim = escapeRegex(delimiter2 ?? ":");
13602
13631
  return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
13603
13632
  }, cidrv4, cidrv6, base64, base64url, hostname, domain, httpProtocol, e164, dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`, date, string = (params) => {
13604
13633
  const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
@@ -27344,7 +27373,7 @@ var init_magic_context = __esm(() => {
27344
27373
  });
27345
27374
 
27346
27375
  // ../plugin/src/config/variable.ts
27347
- import { existsSync as existsSync11, readFileSync as readFileSync7 } from "node:fs";
27376
+ import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
27348
27377
  import { homedir as homedir7 } from "node:os";
27349
27378
  import { dirname as dirname7, isAbsolute, resolve as resolve2 } from "node:path";
27350
27379
  function substituteConfigVariables(input) {
@@ -27385,7 +27414,7 @@ function substituteConfigVariables(input) {
27385
27414
  } else if (!isAbsolute(filePath)) {
27386
27415
  filePath = resolve2(configDir, filePath);
27387
27416
  }
27388
- if (!existsSync11(filePath)) {
27417
+ if (!existsSync12(filePath)) {
27389
27418
  warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
27390
27419
  continue;
27391
27420
  }
@@ -27409,19 +27438,19 @@ var init_variable = __esm(() => {
27409
27438
  });
27410
27439
 
27411
27440
  // ../plugin/src/config/index.ts
27412
- import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
27441
+ import { existsSync as existsSync13, readFileSync as readFileSync8 } from "node:fs";
27413
27442
  import { homedir as homedir8 } from "node:os";
27414
- import { join as join10 } from "node:path";
27443
+ import { join as join11 } from "node:path";
27415
27444
  function getUserConfigBasePath() {
27416
- const configRoot = process.env.XDG_CONFIG_HOME ?? join10(homedir8(), ".config");
27417
- return join10(configRoot, "opencode", CONFIG_FILE_BASENAME);
27445
+ const configRoot = process.env.XDG_CONFIG_HOME ?? join11(homedir8(), ".config");
27446
+ return join11(configRoot, "opencode", CONFIG_FILE_BASENAME);
27418
27447
  }
27419
27448
  function getProjectConfigBasePath(directory) {
27420
- return join10(directory, ".opencode", CONFIG_FILE_BASENAME);
27449
+ return join11(directory, ".opencode", CONFIG_FILE_BASENAME);
27421
27450
  }
27422
27451
  function loadConfigFile(configPath) {
27423
27452
  try {
27424
- if (!existsSync12(configPath)) {
27453
+ if (!existsSync13(configPath)) {
27425
27454
  return null;
27426
27455
  }
27427
27456
  const rawText = readFileSync8(configPath, "utf-8");
@@ -27585,7 +27614,7 @@ function parsePluginConfig(rawConfig, recoveredTopLevelKeys = []) {
27585
27614
  }
27586
27615
  function loadPluginConfig(directory) {
27587
27616
  const userDetected = detectConfigFile(getUserConfigBasePath());
27588
- const rootDetected = detectConfigFile(join10(directory, CONFIG_FILE_BASENAME));
27617
+ const rootDetected = detectConfigFile(join11(directory, CONFIG_FILE_BASENAME));
27589
27618
  const dotOpenCodeDetected = detectConfigFile(getProjectConfigBasePath(directory));
27590
27619
  const projectDetected = rootDetected.format !== "none" ? rootDetected : dotOpenCodeDetected;
27591
27620
  const userLoaded = userDetected.format === "none" ? null : loadConfigFile(userDetected.path);
@@ -27633,11 +27662,11 @@ var init_config = __esm(() => {
27633
27662
  });
27634
27663
 
27635
27664
  // ../plugin/src/features/magic-context/key-files/aft-availability.ts
27636
- import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
27665
+ import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
27637
27666
  import { homedir as homedir9 } from "node:os";
27638
- import { join as join11 } from "node:path";
27667
+ import { join as join12 } from "node:path";
27639
27668
  function parseConfig(path4) {
27640
- if (!existsSync13(path4))
27669
+ if (!existsSync14(path4))
27641
27670
  return null;
27642
27671
  return import_comment_json6.parse(readFileSync9(path4, "utf-8"));
27643
27672
  }
@@ -27661,10 +27690,10 @@ function hasAftAtKeys(value, keys) {
27661
27690
  function getAftAvailability() {
27662
27691
  const home = process.env.HOME || homedir9();
27663
27692
  const opencodePaths = [
27664
- join11(home, ".config", "opencode", "opencode.jsonc"),
27665
- join11(home, ".config", "opencode", "opencode.json")
27693
+ join12(home, ".config", "opencode", "opencode.jsonc"),
27694
+ join12(home, ".config", "opencode", "opencode.json")
27666
27695
  ];
27667
- const piPaths = [join11(home, ".pi", "agent", "settings.json")];
27696
+ const piPaths = [join12(home, ".pi", "agent", "settings.json")];
27668
27697
  const checkedPaths = [...opencodePaths, ...piPaths];
27669
27698
  let opencode = false;
27670
27699
  for (const path4 of opencodePaths) {
@@ -27809,8 +27838,8 @@ function truncate(text2) {
27809
27838
  var DEFAULT_TIMEOUT_MS = 1e4, MAX_PREVIEW_CHARS = 240;
27810
27839
 
27811
27840
  // ../plugin/src/shared/tui-config.ts
27812
- import { existsSync as existsSync14, mkdirSync as mkdirSync6, readFileSync as readFileSync10, writeFileSync as writeFileSync8 } from "node:fs";
27813
- import { dirname as dirname8, join as join12 } from "node:path";
27841
+ import { existsSync as existsSync15, mkdirSync as mkdirSync6, readFileSync as readFileSync10, writeFileSync as writeFileSync8 } from "node:fs";
27842
+ import { dirname as dirname8, join as join13 } from "node:path";
27814
27843
  function isMagicContextEntry(entry) {
27815
27844
  if (!entry)
27816
27845
  return false;
@@ -27824,11 +27853,11 @@ function isMagicContextEntry(entry) {
27824
27853
  }
27825
27854
  function resolveTuiConfigPath() {
27826
27855
  const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
27827
- const jsoncPath = join12(configDir, "tui.jsonc");
27828
- const jsonPath = join12(configDir, "tui.json");
27829
- if (existsSync14(jsoncPath))
27856
+ const jsoncPath = join13(configDir, "tui.jsonc");
27857
+ const jsonPath = join13(configDir, "tui.json");
27858
+ if (existsSync15(jsoncPath))
27830
27859
  return jsoncPath;
27831
- if (existsSync14(jsonPath))
27860
+ if (existsSync15(jsonPath))
27832
27861
  return jsonPath;
27833
27862
  return jsonPath;
27834
27863
  }
@@ -27836,7 +27865,7 @@ function ensureTuiPluginEntry() {
27836
27865
  try {
27837
27866
  const configPath = resolveTuiConfigPath();
27838
27867
  let config2 = {};
27839
- if (existsSync14(configPath)) {
27868
+ if (existsSync15(configPath)) {
27840
27869
  const raw = readFileSync10(configPath, "utf-8");
27841
27870
  config2 = import_comment_json7.parse(raw) ?? {};
27842
27871
  }
@@ -28040,10 +28069,10 @@ var init_redaction = __esm(() => {
28040
28069
  });
28041
28070
 
28042
28071
  // src/lib/diagnostics-opencode.ts
28043
- import { existsSync as existsSync15, readdirSync as readdirSync2, readFileSync as readFileSync11, statSync as statSync2 } from "node:fs";
28072
+ import { existsSync as existsSync16, readdirSync as readdirSync2, readFileSync as readFileSync11, statSync as statSync3 } from "node:fs";
28044
28073
  import { createRequire as createRequire3 } from "node:module";
28045
28074
  import { homedir as homedir11 } from "node:os";
28046
- import { join as join13 } from "node:path";
28075
+ import { join as join14 } from "node:path";
28047
28076
  function getSelfVersion() {
28048
28077
  const require2 = createRequire3(import.meta.url);
28049
28078
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -28057,11 +28086,11 @@ function getSelfVersion() {
28057
28086
  return "unknown";
28058
28087
  }
28059
28088
  function getPluginCacheInfo() {
28060
- const path4 = join13(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION);
28089
+ const path4 = join14(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION);
28061
28090
  let cached2;
28062
28091
  try {
28063
- const installedPkgPath = join13(path4, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28064
- if (existsSync15(installedPkgPath)) {
28092
+ const installedPkgPath = join14(path4, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28093
+ if (existsSync16(installedPkgPath)) {
28065
28094
  const pkg = JSON.parse(readFileSync11(installedPkgPath, "utf-8"));
28066
28095
  cached2 = typeof pkg.version === "string" ? pkg.version : undefined;
28067
28096
  }
@@ -28071,12 +28100,12 @@ function getPluginCacheInfo() {
28071
28100
  return { path: path4, cached: cached2, latest: getSelfVersion() };
28072
28101
  }
28073
28102
  function getStorageDir() {
28074
- const dataHome = process.env.XDG_DATA_HOME || join13(homedir11(), ".local", "share");
28075
- return join13(dataHome, "cortexkit", "magic-context");
28103
+ const dataHome = process.env.XDG_DATA_HOME || join14(homedir11(), ".local", "share");
28104
+ return join14(dataHome, "cortexkit", "magic-context");
28076
28105
  }
28077
28106
  function fileSize(path4) {
28078
28107
  try {
28079
- return existsSync15(path4) ? statSync2(path4).size : 0;
28108
+ return existsSync16(path4) ? statSync3(path4).size : 0;
28080
28109
  } catch {
28081
28110
  return 0;
28082
28111
  }
@@ -28088,7 +28117,7 @@ function sanitizeValue(value) {
28088
28117
  return sanitizeConfigValue(value);
28089
28118
  }
28090
28119
  function readConfig2(path4) {
28091
- if (!existsSync15(path4))
28120
+ if (!existsSync16(path4))
28092
28121
  return { value: null };
28093
28122
  try {
28094
28123
  const raw = readFileSync11(path4, "utf-8");
@@ -28147,11 +28176,11 @@ function parseHistorianDumpMeta(path4) {
28147
28176
  }
28148
28177
  }
28149
28178
  function listDumpsInDir(dir, limit) {
28150
- if (!existsSync15(dir))
28179
+ if (!existsSync16(dir))
28151
28180
  return { count: 0, recent: [] };
28152
28181
  try {
28153
28182
  const entries = readdirSync2(dir).filter((name) => name.endsWith(".xml")).map((name) => {
28154
- const stat = statSync2(join13(dir, name));
28183
+ const stat = statSync3(join14(dir, name));
28155
28184
  return {
28156
28185
  name,
28157
28186
  mtime: stat.mtimeMs,
@@ -28160,7 +28189,7 @@ function listDumpsInDir(dir, limit) {
28160
28189
  }).sort((a, b2) => b2.mtime - a.mtime);
28161
28190
  const now = Date.now();
28162
28191
  const recent = entries.slice(0, limit).map((entry) => {
28163
- const meta3 = parseHistorianDumpMeta(join13(dir, entry.name));
28192
+ const meta3 = parseHistorianDumpMeta(join14(dir, entry.name));
28164
28193
  const summary = {
28165
28194
  name: entry.name,
28166
28195
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -28215,8 +28244,8 @@ function collectHistorianDumps(recentSessions) {
28215
28244
  };
28216
28245
  }
28217
28246
  async function collectRecentSessions() {
28218
- const opencodeDbPath = join13(homedir11(), ".local", "share", "opencode", "opencode.db");
28219
- if (!existsSync15(opencodeDbPath))
28247
+ const opencodeDbPath = join14(homedir11(), ".local", "share", "opencode", "opencode.db");
28248
+ if (!existsSync16(opencodeDbPath))
28220
28249
  return [];
28221
28250
  if (typeof globalThis.Bun === "undefined") {
28222
28251
  return [];
@@ -28250,8 +28279,8 @@ async function collectRecentSessions() {
28250
28279
  }
28251
28280
  }
28252
28281
  async function collectHistorianFailures(storageDirPath) {
28253
- const contextDbPath = join13(storageDirPath, "context.db");
28254
- if (!existsSync15(contextDbPath))
28282
+ const contextDbPath = join14(storageDirPath, "context.db");
28283
+ if (!existsSync16(contextDbPath))
28255
28284
  return [];
28256
28285
  if (typeof globalThis.Bun === "undefined") {
28257
28286
  return [];
@@ -28290,9 +28319,9 @@ async function collectDiagnostics() {
28290
28319
  const tuiConfig = readConfig2(configPaths.tuiConfig);
28291
28320
  const magicContextConfig = readConfig2(configPaths.magicContextConfig);
28292
28321
  const storageDirPath = getStorageDir();
28293
- const contextDbPath = join13(storageDirPath, "context.db");
28322
+ const contextDbPath = join14(storageDirPath, "context.db");
28294
28323
  const logPath = getMagicContextLogPath2("opencode");
28295
- const logFileSize = existsSync15(logPath) ? statSync2(logPath).size : 0;
28324
+ const logFileSize = existsSync16(logPath) ? statSync3(logPath).size : 0;
28296
28325
  const conflictResult = detectConflicts(process.cwd());
28297
28326
  const recentSessions = await collectRecentSessions();
28298
28327
  return {
@@ -28307,7 +28336,7 @@ async function collectDiagnostics() {
28307
28336
  opencodeConfigHasPlugin: configHasPluginEntry(opencodeConfig.value),
28308
28337
  tuiConfigHasPlugin: configHasPluginEntry(tuiConfig.value),
28309
28338
  magicContextConfig: {
28310
- exists: existsSync15(configPaths.magicContextConfig),
28339
+ exists: existsSync16(configPaths.magicContextConfig),
28311
28340
  ...magicContextConfig.error ? { parseError: magicContextConfig.error } : {},
28312
28341
  flags: sanitizeValue(magicContextConfig.value ?? {}) ?? {}
28313
28342
  },
@@ -28315,7 +28344,7 @@ async function collectDiagnostics() {
28315
28344
  pluginCache: getPluginCacheInfo(),
28316
28345
  storageDir: {
28317
28346
  path: storageDirPath,
28318
- exists: existsSync15(storageDirPath),
28347
+ exists: existsSync16(storageDirPath),
28319
28348
  contextDbSizeBytes: fileSize(contextDbPath)
28320
28349
  },
28321
28350
  conflicts: {
@@ -28324,7 +28353,7 @@ async function collectDiagnostics() {
28324
28353
  },
28325
28354
  logFile: {
28326
28355
  path: logPath,
28327
- exists: existsSync15(logPath),
28356
+ exists: existsSync16(logPath),
28328
28357
  sizeKb: Math.round(logFileSize / 1024)
28329
28358
  },
28330
28359
  recentSessions,
@@ -28455,7 +28484,7 @@ var init_diagnostics_opencode = __esm(() => {
28455
28484
  // src/lib/logs-opencode.ts
28456
28485
  import { readFileSync as readFileSync12, writeFileSync as writeFileSync9 } from "node:fs";
28457
28486
  import { homedir as homedir12 } from "node:os";
28458
- import { join as join14 } from "node:path";
28487
+ import { join as join15 } from "node:path";
28459
28488
  function sanitizeLogContent(content) {
28460
28489
  return sanitizeDiagnosticText(content);
28461
28490
  }
@@ -28536,7 +28565,7 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
28536
28565
  "```"
28537
28566
  ].join(`
28538
28567
  `);
28539
- const path4 = join14(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
28568
+ const path4 = join15(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
28540
28569
  writeFileSync9(path4, `${bodyMarkdown}
28541
28570
  `);
28542
28571
  return { path: path4, bodyMarkdown };
@@ -28558,10 +28587,10 @@ var init_logs_opencode = __esm(() => {
28558
28587
 
28559
28588
  // src/commands/doctor-opencode.ts
28560
28589
  import { execSync as execSync2, spawnSync as spawnSync2 } from "node:child_process";
28561
- import { existsSync as existsSync16, readFileSync as readFileSync13, rmSync, statSync as statSync3, writeFileSync as writeFileSync10 } from "node:fs";
28590
+ import { existsSync as existsSync17, readFileSync as readFileSync13, rmSync, statSync as statSync4, writeFileSync as writeFileSync10 } from "node:fs";
28562
28591
  import { createRequire as createRequire4 } from "node:module";
28563
28592
  import { homedir as homedir13 } from "node:os";
28564
- import { join as join15 } from "node:path";
28593
+ import { join as join16 } from "node:path";
28565
28594
  async function fetchNpmLatest(pkg, timeoutMs = 5000) {
28566
28595
  try {
28567
28596
  const controller = new AbortController;
@@ -28611,14 +28640,14 @@ function compareVersions(a, b2) {
28611
28640
  }
28612
28641
  async function clearPluginCache(force = false) {
28613
28642
  const cacheDir = getOpenCodeCacheDir();
28614
- const pluginCacheDir = join15(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
28615
- if (!existsSync16(pluginCacheDir)) {
28643
+ const pluginCacheDir = join16(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
28644
+ if (!existsSync17(pluginCacheDir)) {
28616
28645
  return { action: "not_found", path: pluginCacheDir };
28617
28646
  }
28618
28647
  let cachedVersion;
28619
28648
  try {
28620
- const installedPkgPath = join15(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28621
- if (existsSync16(installedPkgPath)) {
28649
+ const installedPkgPath = join16(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28650
+ if (existsSync17(installedPkgPath)) {
28622
28651
  const pkg = JSON.parse(readFileSync13(installedPkgPath, "utf-8"));
28623
28652
  if (typeof pkg?.version === "string") {
28624
28653
  cachedVersion = pkg.version;
@@ -28751,7 +28780,7 @@ async function runIssueFlow() {
28751
28780
  }
28752
28781
  }
28753
28782
  async function checkEmbeddingConfig(magicContextConfigPath) {
28754
- if (!existsSync16(magicContextConfigPath)) {
28783
+ if (!existsSync17(magicContextConfigPath)) {
28755
28784
  return { issues: 0 };
28756
28785
  }
28757
28786
  let rawText;
@@ -28885,6 +28914,8 @@ async function runDoctor(options = {}) {
28885
28914
  };
28886
28915
  if (!isOpenCodeInstalled()) {
28887
28916
  fail("OpenCode is not installed or not in PATH");
28917
+ log.info("Doctor checked ~/.opencode/bin/opencode and each entry in $PATH.");
28918
+ log.info("If `which opencode` succeeds outside doctor, your wrapper or shim may not be readable by Node — please share that wrapper in the issue.");
28888
28919
  outro("Doctor failed — install OpenCode first");
28889
28920
  return 1;
28890
28921
  }
@@ -28904,7 +28935,7 @@ async function runDoctor(options = {}) {
28904
28935
  } else {
28905
28936
  pass(`OpenCode config: ${paths.opencodeConfig}`);
28906
28937
  }
28907
- if (existsSync16(paths.magicContextConfig)) {
28938
+ if (existsSync17(paths.magicContextConfig)) {
28908
28939
  pass(`Magic Context config: ${paths.magicContextConfig}`);
28909
28940
  try {
28910
28941
  const raw = readFileSync13(paths.magicContextConfig, "utf-8");
@@ -28932,7 +28963,7 @@ async function runDoctor(options = {}) {
28932
28963
  warn(`No magic-context.jsonc found — using defaults`);
28933
28964
  log.info(" Run 'setup' to create one with model recommendations");
28934
28965
  }
28935
- if (existsSync16(paths.magicContextConfig)) {
28966
+ if (existsSync17(paths.magicContextConfig)) {
28936
28967
  try {
28937
28968
  const mcRaw = readFileSync13(paths.magicContextConfig, "utf-8");
28938
28969
  const mcConfig = import_comment_json9.parse(mcRaw);
@@ -29091,7 +29122,7 @@ async function runDoctor(options = {}) {
29091
29122
  pass("Added TUI sidebar plugin to tui.json");
29092
29123
  warn("Restart OpenCode to see the sidebar");
29093
29124
  fixed++;
29094
- } else if (existsSync16(paths.tuiConfig)) {
29125
+ } else if (existsSync17(paths.tuiConfig)) {
29095
29126
  try {
29096
29127
  const tuiRaw = readFileSync13(paths.tuiConfig, "utf-8");
29097
29128
  const tuiConfig = import_comment_json9.parse(tuiRaw);
@@ -29139,7 +29170,7 @@ async function runDoctor(options = {}) {
29139
29170
  } else {
29140
29171
  pass("TUI sidebar plugin configured (tui.json created)");
29141
29172
  }
29142
- if (existsSync16(paths.magicContextConfig)) {
29173
+ if (existsSync17(paths.magicContextConfig)) {
29143
29174
  try {
29144
29175
  const mcRaw = readFileSync13(paths.magicContextConfig, "utf-8");
29145
29176
  const mcConfig = import_comment_json9.parse(mcRaw);
@@ -29168,8 +29199,8 @@ async function runDoctor(options = {}) {
29168
29199
  failCount += embeddingCheck.issues;
29169
29200
  else
29170
29201
  passCount++;
29171
- const dbPath = join15(getMagicContextStorageDir(), "context.db");
29172
- if (!existsSync16(dbPath)) {
29202
+ const dbPath = join16(getMagicContextStorageDir(), "context.db");
29203
+ if (!existsSync17(dbPath)) {
29173
29204
  log.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
29174
29205
  } else {
29175
29206
  pass(`Shared context DB exists at ${dbPath}`);
@@ -29230,8 +29261,8 @@ async function runDoctor(options = {}) {
29230
29261
  }
29231
29262
  {
29232
29263
  const ageWarnings = [];
29233
- const npmrcPath = join15(homedir13(), ".npmrc");
29234
- if (existsSync16(npmrcPath)) {
29264
+ const npmrcPath = join16(homedir13(), ".npmrc");
29265
+ if (existsSync17(npmrcPath)) {
29235
29266
  try {
29236
29267
  const npmrc = readFileSync13(npmrcPath, "utf-8");
29237
29268
  for (const line of npmrc.split(`
@@ -29257,8 +29288,8 @@ async function runDoctor(options = {}) {
29257
29288
  }
29258
29289
  }
29259
29290
  const logPath = getMagicContextLogPath2("opencode");
29260
- if (existsSync16(logPath)) {
29261
- const logStat = statSync3(logPath);
29291
+ if (existsSync17(logPath)) {
29292
+ const logStat = statSync4(logPath);
29262
29293
  const sizeKb = (logStat.size / 1024).toFixed(0);
29263
29294
  log.info(`Log file: ${logPath} (${sizeKb} KB)`);
29264
29295
  } else {
@@ -161907,7 +161938,7 @@ function getErrorMessage(error51) {
161907
161938
  }
161908
161939
 
161909
161940
  // ../plugin/src/features/magic-context/key-files/project-key-files.ts
161910
- import { existsSync as existsSync17, readFileSync as readFileSync14, realpathSync } from "node:fs";
161941
+ import { existsSync as existsSync18, readFileSync as readFileSync14, realpathSync } from "node:fs";
161911
161942
  function deleteOrphanProjectKeyFiles(db, now = Date.now()) {
161912
161943
  const cutoff = now - ORPHAN_GRACE_MS;
161913
161944
  const rows = db.prepare(`SELECT project_path AS projectPath, MAX(generated_at) AS lastGen
@@ -161916,7 +161947,7 @@ function deleteOrphanProjectKeyFiles(db, now = Date.now()) {
161916
161947
  HAVING lastGen < ?`).all(cutoff);
161917
161948
  let deletedProjects = 0;
161918
161949
  for (const row of rows) {
161919
- if (existsSync17(row.projectPath))
161950
+ if (existsSync18(row.projectPath))
161920
161951
  continue;
161921
161952
  try {
161922
161953
  db.prepare("DELETE FROM project_key_files WHERE project_path = ?").run(row.projectPath);
@@ -162424,10 +162455,10 @@ var init_tool_definition_tokens = __esm(() => {
162424
162455
  });
162425
162456
 
162426
162457
  // ../plugin/src/features/magic-context/tool-owner-backfill.ts
162427
- import { existsSync as existsSync18 } from "node:fs";
162428
- import { join as join16 } from "node:path";
162458
+ import { existsSync as existsSync19 } from "node:fs";
162459
+ import { join as join17 } from "node:path";
162429
162460
  function resolveOpencodeDbPath() {
162430
- return join16(getDataDir(), "opencode", "opencode.db");
162461
+ return join17(getDataDir(), "opencode", "opencode.db");
162431
162462
  }
162432
162463
  function ensureBackfillStateTable(db) {
162433
162464
  db.exec(`
@@ -162462,7 +162493,7 @@ function runToolOwnerBackfill(db) {
162462
162493
  return result;
162463
162494
  }
162464
162495
  const opencodeDbPath = resolveOpencodeDbPath();
162465
- if (!existsSync18(opencodeDbPath)) {
162496
+ if (!existsSync19(opencodeDbPath)) {
162466
162497
  log2(`[backfill] OpenCode DB not found at ${opencodeDbPath} — marking all unbackfilled sessions as skipped. Lazy adoption (defense-in-depth) handles legacy rows at runtime.`);
162467
162498
  markAllUnbackfilledSessionsSkipped(db);
162468
162499
  result.sessionsSkippedNoOcDb = countSessionsByStatus(db, "skipped");
@@ -162672,25 +162703,25 @@ var init_tool_owner_backfill = __esm(() => {
162672
162703
  });
162673
162704
 
162674
162705
  // ../plugin/src/features/magic-context/storage-db.ts
162675
- import { copyFileSync, cpSync, existsSync as existsSync19, mkdirSync as mkdirSync7 } from "node:fs";
162676
- import { join as join17 } from "node:path";
162706
+ import { copyFileSync, cpSync, existsSync as existsSync20, mkdirSync as mkdirSync7 } from "node:fs";
162707
+ import { join as join18 } from "node:path";
162677
162708
  function resolveDatabasePath() {
162678
162709
  const dbDir = getMagicContextStorageDir();
162679
- return { dbDir, dbPath: join17(dbDir, "context.db") };
162710
+ return { dbDir, dbPath: join18(dbDir, "context.db") };
162680
162711
  }
162681
162712
  function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
162682
- if (existsSync19(targetDbPath))
162713
+ if (existsSync20(targetDbPath))
162683
162714
  return;
162684
162715
  const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
162685
- const legacyDbPath = join17(legacyDir, "context.db");
162686
- if (!existsSync19(legacyDbPath))
162716
+ const legacyDbPath = join18(legacyDir, "context.db");
162717
+ if (!existsSync20(legacyDbPath))
162687
162718
  return;
162688
162719
  log2(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
162689
162720
  mkdirSync7(targetDbDir, { recursive: true });
162690
162721
  for (const suffix of ["", "-wal", "-shm"]) {
162691
162722
  const src = `${legacyDbPath}${suffix}`;
162692
- const dst = join17(targetDbDir, `context.db${suffix}`);
162693
- if (existsSync19(src)) {
162723
+ const dst = join18(targetDbDir, `context.db${suffix}`);
162724
+ if (existsSync20(src)) {
162694
162725
  try {
162695
162726
  copyFileSync(src, dst);
162696
162727
  } catch (error51) {
@@ -162698,9 +162729,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
162698
162729
  }
162699
162730
  }
162700
162731
  }
162701
- const legacyModelsDir = join17(legacyDir, "models");
162702
- const targetModelsDir = join17(targetDbDir, "models");
162703
- if (existsSync19(legacyModelsDir) && !existsSync19(targetModelsDir)) {
162732
+ const legacyModelsDir = join18(legacyDir, "models");
162733
+ const targetModelsDir = join18(targetDbDir, "models");
162734
+ if (existsSync20(legacyModelsDir) && !existsSync20(targetModelsDir)) {
162704
162735
  try {
162705
162736
  cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
162706
162737
  } catch (error51) {
@@ -163303,20 +163334,20 @@ var init_storage = __esm(async () => {
163303
163334
  });
163304
163335
 
163305
163336
  // ../pi-plugin/src/config/index.ts
163306
- import { existsSync as existsSync20, readFileSync as readFileSync15 } from "node:fs";
163337
+ import { existsSync as existsSync21, readFileSync as readFileSync15 } from "node:fs";
163307
163338
  import { homedir as homedir14 } from "node:os";
163308
- import { join as join18 } from "node:path";
163339
+ import { join as join19 } from "node:path";
163309
163340
  function getProjectConfigPaths(cwd) {
163310
- const basePath = join18(cwd, ".pi", CONFIG_FILE_NAME);
163341
+ const basePath = join19(cwd, ".pi", CONFIG_FILE_NAME);
163311
163342
  return [`${basePath}.jsonc`, `${basePath}.json`];
163312
163343
  }
163313
163344
  function getUserConfigPaths() {
163314
163345
  const home = process.env.HOME ?? homedir14();
163315
- const basePath = join18(home, ".pi", "agent", CONFIG_FILE_NAME);
163346
+ const basePath = join19(home, ".pi", "agent", CONFIG_FILE_NAME);
163316
163347
  return [`${basePath}.jsonc`, `${basePath}.json`];
163317
163348
  }
163318
163349
  function resolveFirstExisting(paths) {
163319
- return paths.find((path4) => existsSync20(path4));
163350
+ return paths.find((path4) => existsSync21(path4));
163320
163351
  }
163321
163352
  function loadConfigFile2(path4, scope) {
163322
163353
  try {
@@ -163453,10 +163484,10 @@ var init_config2 = __esm(() => {
163453
163484
 
163454
163485
  // src/lib/diagnostics-pi.ts
163455
163486
  import { createHash } from "node:crypto";
163456
- import { existsSync as existsSync21, readdirSync as readdirSync3, readFileSync as readFileSync16, statSync as statSync4 } from "node:fs";
163487
+ import { existsSync as existsSync22, readdirSync as readdirSync3, readFileSync as readFileSync16, statSync as statSync5 } from "node:fs";
163457
163488
  import { createRequire as createRequire5 } from "node:module";
163458
163489
  import { homedir as homedir15, userInfo as userInfo2 } from "node:os";
163459
- import { join as join19 } from "node:path";
163490
+ import { join as join20 } from "node:path";
163460
163491
  function getSelfVersion3() {
163461
163492
  const req = createRequire5(import.meta.url);
163462
163493
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -163471,7 +163502,7 @@ function getSelfVersion3() {
163471
163502
  }
163472
163503
  function fileSize2(path4) {
163473
163504
  try {
163474
- return existsSync21(path4) ? statSync4(path4).size : 0;
163505
+ return existsSync22(path4) ? statSync5(path4).size : 0;
163475
163506
  } catch {
163476
163507
  return 0;
163477
163508
  }
@@ -163521,7 +163552,7 @@ function sanitizeValue2(value, key = "") {
163521
163552
  return value;
163522
163553
  }
163523
163554
  function readJsonc3(path4) {
163524
- if (!existsSync21(path4))
163555
+ if (!existsSync22(path4))
163525
163556
  return { value: {} };
163526
163557
  try {
163527
163558
  return {
@@ -163535,13 +163566,13 @@ function readJsonc3(path4) {
163535
163566
  }
163536
163567
  }
163537
163568
  function getProjectConfigPath(cwd) {
163538
- return join19(cwd, ".pi", "magic-context.jsonc");
163569
+ return join20(cwd, ".pi", "magic-context.jsonc");
163539
163570
  }
163540
163571
  function readConfigDiagnostic(path4) {
163541
163572
  const parsed = readJsonc3(path4);
163542
163573
  return {
163543
163574
  path: path4,
163544
- exists: existsSync21(path4),
163575
+ exists: existsSync22(path4),
163545
163576
  ...parsed.parseError ? { parseError: parsed.parseError } : {},
163546
163577
  flags: sanitizeValue2(parsed.value)
163547
163578
  };
@@ -163558,8 +163589,8 @@ function reverseSlugToDirectory(slug) {
163558
163589
  return `/${inner.replace(/-/g, "/")}`;
163559
163590
  }
163560
163591
  function collectPiRecentSessions() {
163561
- const sessionsRoot = join19(homedir15(), ".pi", "agent", "sessions");
163562
- if (!existsSync21(sessionsRoot))
163592
+ const sessionsRoot = join20(homedir15(), ".pi", "agent", "sessions");
163593
+ if (!existsSync22(sessionsRoot))
163563
163594
  return [];
163564
163595
  try {
163565
163596
  const slugs = readdirSync3(sessionsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
@@ -163568,7 +163599,7 @@ function collectPiRecentSessions() {
163568
163599
  const directory = reverseSlugToDirectory(slug);
163569
163600
  if (!directory)
163570
163601
  continue;
163571
- const slugDir = join19(sessionsRoot, slug);
163602
+ const slugDir = join20(sessionsRoot, slug);
163572
163603
  let files;
163573
163604
  try {
163574
163605
  files = readdirSync3(slugDir).filter((name2) => name2.endsWith(".jsonl"));
@@ -163577,7 +163608,7 @@ function collectPiRecentSessions() {
163577
163608
  }
163578
163609
  for (const file2 of files) {
163579
163610
  try {
163580
- const mtime = statSync4(join19(slugDir, file2)).mtimeMs;
163611
+ const mtime = statSync5(join20(slugDir, file2)).mtimeMs;
163581
163612
  const sessionId = file2.replace(/\.jsonl$/, "");
163582
163613
  candidates.push({ sessionId, directory, mtime });
163583
163614
  } catch {}
@@ -163628,11 +163659,11 @@ function parseHistorianDumpMeta2(path4) {
163628
163659
  }
163629
163660
  }
163630
163661
  function listDumpsInDir2(dir, limit) {
163631
- if (!existsSync21(dir))
163662
+ if (!existsSync22(dir))
163632
163663
  return { count: 0, recent: [] };
163633
163664
  try {
163634
163665
  const entries = readdirSync3(dir).filter((name2) => name2.endsWith(".xml")).map((name2) => {
163635
- const stat = statSync4(join19(dir, name2));
163666
+ const stat = statSync5(join20(dir, name2));
163636
163667
  return {
163637
163668
  name: name2,
163638
163669
  mtime: stat.mtimeMs,
@@ -163641,7 +163672,7 @@ function listDumpsInDir2(dir, limit) {
163641
163672
  }).sort((a, b2) => b2.mtime - a.mtime);
163642
163673
  const now = Date.now();
163643
163674
  const recent = entries.slice(0, limit).map((entry) => {
163644
- const meta3 = parseHistorianDumpMeta2(join19(dir, entry.name));
163675
+ const meta3 = parseHistorianDumpMeta2(join20(dir, entry.name));
163645
163676
  const summary = {
163646
163677
  name: entry.name,
163647
163678
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -163704,9 +163735,9 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163704
163735
  const projectConfigPath = getProjectConfigPath(cwd);
163705
163736
  const loaded = loadPiConfig({ cwd });
163706
163737
  const storageDirPath = getMagicContextStorageDir();
163707
- const dbPath = join19(storageDirPath, "context.db");
163738
+ const dbPath = join20(storageDirPath, "context.db");
163708
163739
  const logPath = getMagicContextLogPath2("pi");
163709
- const logFileSize = existsSync21(logPath) ? statSync4(logPath).size : 0;
163740
+ const logFileSize = existsSync22(logPath) ? statSync5(logPath).size : 0;
163710
163741
  const otherPiExtensions = packages.filter((entry) => !isPiMagicContextPackageEntry(entry)).map(describePiPackageEntry);
163711
163742
  const recentSessions = collectPiRecentSessions();
163712
163743
  const historianDumps = collectPiHistorianDumps(recentSessions);
@@ -163721,7 +163752,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163721
163752
  piVersion: pi ? getPiVersion(pi.path) : null,
163722
163753
  settings: {
163723
163754
  path: settingsPath,
163724
- exists: existsSync21(settingsPath),
163755
+ exists: existsSync22(settingsPath),
163725
163756
  ...settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {},
163726
163757
  hasMagicContextPackage: hasPiMagicContextPackage(packages),
163727
163758
  packages: sanitizeValue2(packages)
@@ -163737,7 +163768,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163737
163768
  loadWarnings: loaded.warnings.map(sanitizeString2),
163738
163769
  storageDir: {
163739
163770
  path: storageDirPath,
163740
- exists: existsSync21(storageDirPath),
163771
+ exists: existsSync22(storageDirPath),
163741
163772
  contextDbSizeBytes: fileSize2(dbPath)
163742
163773
  },
163743
163774
  conflicts: {
@@ -163746,7 +163777,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163746
163777
  },
163747
163778
  logFile: {
163748
163779
  path: logPath,
163749
- exists: existsSync21(logPath),
163780
+ exists: existsSync22(logPath),
163750
163781
  sizeKb: Math.round(logFileSize / 1024)
163751
163782
  },
163752
163783
  recentSessions,
@@ -163840,7 +163871,7 @@ var init_diagnostics_pi = __esm(() => {
163840
163871
 
163841
163872
  // src/lib/logs-pi.ts
163842
163873
  import { readFileSync as readFileSync17, writeFileSync as writeFileSync11 } from "node:fs";
163843
- import { join as join20 } from "node:path";
163874
+ import { join as join21 } from "node:path";
163844
163875
  function sanitizeLogContent2(content) {
163845
163876
  return sanitizeString2(content);
163846
163877
  }
@@ -163896,7 +163927,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
163896
163927
  ].join(`
163897
163928
  `);
163898
163929
  const cwd = options.cwd ?? process.cwd();
163899
- const path4 = join20(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
163930
+ const path4 = join21(cwd, `magic-context-pi-issue-${formatTimestamp2(options.now ?? new Date)}.md`);
163900
163931
  writeFileSync11(path4, `${bodyMarkdown}
163901
163932
  `);
163902
163933
  return { path: path4, bodyMarkdown };
@@ -163906,19 +163937,19 @@ var init_logs_pi = __esm(() => {
163906
163937
  });
163907
163938
 
163908
163939
  // src/commands/doctor-pi.ts
163909
- import { execFileSync as execFileSync4, spawnSync as spawnSync3 } from "node:child_process";
163940
+ import { execFileSync as execFileSync3, spawnSync as spawnSync3 } from "node:child_process";
163910
163941
  import {
163911
- existsSync as existsSync22,
163942
+ existsSync as existsSync23,
163912
163943
  mkdirSync as mkdirSync8,
163913
163944
  readdirSync as readdirSync4,
163914
163945
  readFileSync as readFileSync18,
163915
163946
  rmSync as rmSync2,
163916
- statSync as statSync5,
163947
+ statSync as statSync6,
163917
163948
  writeFileSync as writeFileSync12
163918
163949
  } from "node:fs";
163919
163950
  import { createRequire as createRequire6 } from "node:module";
163920
163951
  import { homedir as homedir16 } from "node:os";
163921
- import { dirname as dirname9, join as join21 } from "node:path";
163952
+ import { dirname as dirname9, join as join22 } from "node:path";
163922
163953
  function depsFrom(options) {
163923
163954
  return {
163924
163955
  ...DEFAULT_DEPS,
@@ -163951,7 +163982,7 @@ function selfVersion() {
163951
163982
  }
163952
163983
  function getLatestNpmVersion(packageName) {
163953
163984
  try {
163954
- return execFileSync4("npm", ["view", packageName, "version"], {
163985
+ return execFileSync3("npm", ["view", packageName, "version"], {
163955
163986
  encoding: "utf-8",
163956
163987
  stdio: ["ignore", "pipe", "ignore"],
163957
163988
  timeout: 1e4
@@ -164018,10 +164049,10 @@ function packagesFrom(settings) {
164018
164049
  return Array.isArray(settings.packages) ? settings.packages : [];
164019
164050
  }
164020
164051
  function projectConfigPath(cwd) {
164021
- return join21(cwd, ".pi", "magic-context.jsonc");
164052
+ return join22(cwd, ".pi", "magic-context.jsonc");
164022
164053
  }
164023
164054
  function readConfigForEmbedding(path4) {
164024
- if (!existsSync22(path4))
164055
+ if (!existsSync23(path4))
164025
164056
  return null;
164026
164057
  try {
164027
164058
  const rawText = readFileSync18(path4, "utf-8");
@@ -164083,30 +164114,30 @@ function countTable(db, table) {
164083
164114
  }
164084
164115
  function cacheRoots() {
164085
164116
  const home = homedir16();
164086
- const cacheHome = process.env.XDG_CACHE_HOME || join21(home, ".cache");
164117
+ const cacheHome = process.env.XDG_CACHE_HOME || join22(home, ".cache");
164087
164118
  return [
164088
- join21(home, ".pi", "cache", "extensions"),
164089
- join21(home, ".pi", "cache", "packages"),
164090
- join21(cacheHome, "pi", "extensions"),
164091
- join21(cacheHome, "pi", "packages"),
164092
- join21(getPiAgentConfigDir(), "cache", "extensions")
164119
+ join22(home, ".pi", "cache", "extensions"),
164120
+ join22(home, ".pi", "cache", "packages"),
164121
+ join22(cacheHome, "pi", "extensions"),
164122
+ join22(cacheHome, "pi", "packages"),
164123
+ join22(getPiAgentConfigDir(), "cache", "extensions")
164093
164124
  ];
164094
164125
  }
164095
164126
  function findPiMagicContextCacheDirs(self, force = false) {
164096
164127
  const found = new Map;
164097
164128
  const visit = (path4, depth) => {
164098
- if (depth < 0 || !existsSync22(path4))
164129
+ if (depth < 0 || !existsSync23(path4))
164099
164130
  return;
164100
164131
  let stat;
164101
164132
  try {
164102
- stat = statSync5(path4);
164133
+ stat = statSync6(path4);
164103
164134
  } catch {
164104
164135
  return;
164105
164136
  }
164106
164137
  if (!stat.isDirectory())
164107
164138
  return;
164108
- const packageJson = join21(path4, "package.json");
164109
- if (existsSync22(packageJson)) {
164139
+ const packageJson = join22(path4, "package.json");
164140
+ if (existsSync23(packageJson)) {
164110
164141
  try {
164111
164142
  const pkg = JSON.parse(readFileSync18(packageJson, "utf-8"));
164112
164143
  const name2 = typeof pkg.name === "string" ? pkg.name : "";
@@ -164127,7 +164158,7 @@ function findPiMagicContextCacheDirs(self, force = false) {
164127
164158
  return;
164128
164159
  }
164129
164160
  for (const entry of entries)
164130
- visit(join21(path4, entry), depth - 1);
164161
+ visit(join22(path4, entry), depth - 1);
164131
164162
  };
164132
164163
  for (const root of cacheRoots())
164133
164164
  visit(root, 5);
@@ -164164,7 +164195,7 @@ async function runHealthChecks(options) {
164164
164195
  }
164165
164196
  const settingsPath = getPiUserExtensionsPath();
164166
164197
  let packages = [];
164167
- if (!existsSync22(settingsPath)) {
164198
+ if (!existsSync23(settingsPath)) {
164168
164199
  add(results, "warn", `Pi settings not found at ${settingsPath}`);
164169
164200
  repairPlan.addPackageEntry = true;
164170
164201
  } else {
@@ -164188,7 +164219,7 @@ async function runHealthChecks(options) {
164188
164219
  ["user", userConfigPath, true],
164189
164220
  ["project", projectPath, false]
164190
164221
  ]) {
164191
- if (!existsSync22(path4)) {
164222
+ if (!existsSync23(path4)) {
164192
164223
  if (required2) {
164193
164224
  add(results, "warn", `No ${label} magic-context.jsonc found at ${path4}`);
164194
164225
  repairPlan.writeUserConfig = true;
@@ -164221,8 +164252,8 @@ async function runHealthChecks(options) {
164221
164252
  add(results, "pass", `historian.model "${historianModel}" has thinking_level "${historianThinkingLevel}" configured`);
164222
164253
  }
164223
164254
  const storageDir = getMagicContextStorageDir();
164224
- const dbPath = join21(storageDir, "context.db");
164225
- const existedBeforeOpen = existsSync22(dbPath);
164255
+ const dbPath = join22(storageDir, "context.db");
164256
+ const existedBeforeOpen = existsSync23(dbPath);
164226
164257
  if (existedBeforeOpen)
164227
164258
  add(results, "pass", `Shared context DB exists at ${dbPath}`);
164228
164259
  else
@@ -164299,8 +164330,8 @@ async function runHealthChecks(options) {
164299
164330
  add(results, "pass", "Pi extension cache clean (no stale cached package found)");
164300
164331
  }
164301
164332
  const logPath = getMagicContextLogPath2("pi");
164302
- if (existsSync22(logPath)) {
164303
- const stat = statSync5(logPath);
164333
+ if (existsSync23(logPath)) {
164334
+ const stat = statSync6(logPath);
164304
164335
  const sizeKb = (stat.size / 1024).toFixed(0);
164305
164336
  const lines = readFileSync18(logPath, "utf-8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
164306
164337
  add(results, "info", `Log file: ${logPath} (${sizeKb} KB)`);
@@ -164358,7 +164389,7 @@ function repair(plan, prompts) {
164358
164389
  }
164359
164390
  if (plan.writeUserConfig) {
164360
164391
  const configPath = getPiUserConfigPath();
164361
- if (!existsSync22(configPath)) {
164392
+ if (!existsSync23(configPath)) {
164362
164393
  try {
164363
164394
  writeDefaultMagicContextConfig(configPath);
164364
164395
  prompts.log.success(`Wrote default Magic Context config to ${configPath}`);
@@ -164527,7 +164558,7 @@ var init_doctor_pi = __esm(async () => {
164527
164558
  isDatabasePersisted,
164528
164559
  closeDatabase,
164529
164560
  now: () => new Date,
164530
- execFileSync: execFileSync4,
164561
+ execFileSync: execFileSync3,
164531
164562
  spawnSync: spawnSync3
164532
164563
  };
164533
164564
  });
@@ -164537,7 +164568,7 @@ var exports_doctor = {};
164537
164568
  __export(exports_doctor, {
164538
164569
  runDoctor: () => runDoctor3
164539
164570
  });
164540
- import { existsSync as existsSync23, rmSync as rmSync3 } from "node:fs";
164571
+ import { existsSync as existsSync24, rmSync as rmSync3 } from "node:fs";
164541
164572
  async function runDoctor3(options) {
164542
164573
  if (options.clear)
164543
164574
  return runClear();
@@ -164621,7 +164652,7 @@ async function runClear() {
164621
164652
  const s = spinner();
164622
164653
  s.start(`Clearing ${item.path}`);
164623
164654
  try {
164624
- if (existsSync23(item.path)) {
164655
+ if (existsSync24(item.path)) {
164625
164656
  rmSync3(item.path, { recursive: true, force: true });
164626
164657
  }
164627
164658
  s.stop(`Cleared ${item.path}`);