@cortexkit/magic-context 0.20.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 +353 -253
  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");
@@ -27529,7 +27558,7 @@ function migrateLegacyExperimental(rawConfig, warnings) {
27529
27558
  patched.dreamer = dreamer;
27530
27559
  return patched;
27531
27560
  }
27532
- function parsePluginConfig(rawConfig) {
27561
+ function parsePluginConfig(rawConfig, recoveredTopLevelKeys = []) {
27533
27562
  const preMigrationWarnings = [];
27534
27563
  const migrated = migrateLegacyExperimental(rawConfig, preMigrationWarnings);
27535
27564
  const parsed = MagicContextConfigSchema.safeParse(migrated);
@@ -27554,6 +27583,7 @@ function parsePluginConfig(rawConfig) {
27554
27583
  }
27555
27584
  const patched = { ...rawConfig };
27556
27585
  for (const key of errorPaths) {
27586
+ recoveredTopLevelKeys.push(key);
27557
27587
  const isAgentConfig = key === "historian" || key === "dreamer" || key === "sidekick";
27558
27588
  if (isAgentConfig) {
27559
27589
  delete patched[key];
@@ -27584,7 +27614,7 @@ function parsePluginConfig(rawConfig) {
27584
27614
  }
27585
27615
  function loadPluginConfig(directory) {
27586
27616
  const userDetected = detectConfigFile(getUserConfigBasePath());
27587
- const rootDetected = detectConfigFile(join10(directory, CONFIG_FILE_BASENAME));
27617
+ const rootDetected = detectConfigFile(join11(directory, CONFIG_FILE_BASENAME));
27588
27618
  const dotOpenCodeDetected = detectConfigFile(getProjectConfigBasePath(directory));
27589
27619
  const projectDetected = rootDetected.format !== "none" ? rootDetected : dotOpenCodeDetected;
27590
27620
  const userLoaded = userDetected.format === "none" ? null : loadConfigFile(userDetected.path);
@@ -27632,11 +27662,11 @@ var init_config = __esm(() => {
27632
27662
  });
27633
27663
 
27634
27664
  // ../plugin/src/features/magic-context/key-files/aft-availability.ts
27635
- import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
27665
+ import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
27636
27666
  import { homedir as homedir9 } from "node:os";
27637
- import { join as join11 } from "node:path";
27667
+ import { join as join12 } from "node:path";
27638
27668
  function parseConfig(path4) {
27639
- if (!existsSync13(path4))
27669
+ if (!existsSync14(path4))
27640
27670
  return null;
27641
27671
  return import_comment_json6.parse(readFileSync9(path4, "utf-8"));
27642
27672
  }
@@ -27660,10 +27690,10 @@ function hasAftAtKeys(value, keys) {
27660
27690
  function getAftAvailability() {
27661
27691
  const home = process.env.HOME || homedir9();
27662
27692
  const opencodePaths = [
27663
- join11(home, ".config", "opencode", "opencode.jsonc"),
27664
- join11(home, ".config", "opencode", "opencode.json")
27693
+ join12(home, ".config", "opencode", "opencode.jsonc"),
27694
+ join12(home, ".config", "opencode", "opencode.json")
27665
27695
  ];
27666
- const piPaths = [join11(home, ".pi", "agent", "settings.json")];
27696
+ const piPaths = [join12(home, ".pi", "agent", "settings.json")];
27667
27697
  const checkedPaths = [...opencodePaths, ...piPaths];
27668
27698
  let opencode = false;
27669
27699
  for (const path4 of opencodePaths) {
@@ -27808,8 +27838,8 @@ function truncate(text2) {
27808
27838
  var DEFAULT_TIMEOUT_MS = 1e4, MAX_PREVIEW_CHARS = 240;
27809
27839
 
27810
27840
  // ../plugin/src/shared/tui-config.ts
27811
- import { existsSync as existsSync14, mkdirSync as mkdirSync6, readFileSync as readFileSync10, writeFileSync as writeFileSync8 } from "node:fs";
27812
- 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";
27813
27843
  function isMagicContextEntry(entry) {
27814
27844
  if (!entry)
27815
27845
  return false;
@@ -27823,11 +27853,11 @@ function isMagicContextEntry(entry) {
27823
27853
  }
27824
27854
  function resolveTuiConfigPath() {
27825
27855
  const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
27826
- const jsoncPath = join12(configDir, "tui.jsonc");
27827
- const jsonPath = join12(configDir, "tui.json");
27828
- if (existsSync14(jsoncPath))
27856
+ const jsoncPath = join13(configDir, "tui.jsonc");
27857
+ const jsonPath = join13(configDir, "tui.json");
27858
+ if (existsSync15(jsoncPath))
27829
27859
  return jsoncPath;
27830
- if (existsSync14(jsonPath))
27860
+ if (existsSync15(jsonPath))
27831
27861
  return jsonPath;
27832
27862
  return jsonPath;
27833
27863
  }
@@ -27835,7 +27865,7 @@ function ensureTuiPluginEntry() {
27835
27865
  try {
27836
27866
  const configPath = resolveTuiConfigPath();
27837
27867
  let config2 = {};
27838
- if (existsSync14(configPath)) {
27868
+ if (existsSync15(configPath)) {
27839
27869
  const raw = readFileSync10(configPath, "utf-8");
27840
27870
  config2 = import_comment_json7.parse(raw) ?? {};
27841
27871
  }
@@ -28039,10 +28069,10 @@ var init_redaction = __esm(() => {
28039
28069
  });
28040
28070
 
28041
28071
  // src/lib/diagnostics-opencode.ts
28042
- 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";
28043
28073
  import { createRequire as createRequire3 } from "node:module";
28044
28074
  import { homedir as homedir11 } from "node:os";
28045
- import { join as join13 } from "node:path";
28075
+ import { join as join14 } from "node:path";
28046
28076
  function getSelfVersion() {
28047
28077
  const require2 = createRequire3(import.meta.url);
28048
28078
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -28056,11 +28086,11 @@ function getSelfVersion() {
28056
28086
  return "unknown";
28057
28087
  }
28058
28088
  function getPluginCacheInfo() {
28059
- const path4 = join13(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION);
28089
+ const path4 = join14(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION);
28060
28090
  let cached2;
28061
28091
  try {
28062
- const installedPkgPath = join13(path4, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28063
- if (existsSync15(installedPkgPath)) {
28092
+ const installedPkgPath = join14(path4, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28093
+ if (existsSync16(installedPkgPath)) {
28064
28094
  const pkg = JSON.parse(readFileSync11(installedPkgPath, "utf-8"));
28065
28095
  cached2 = typeof pkg.version === "string" ? pkg.version : undefined;
28066
28096
  }
@@ -28070,12 +28100,12 @@ function getPluginCacheInfo() {
28070
28100
  return { path: path4, cached: cached2, latest: getSelfVersion() };
28071
28101
  }
28072
28102
  function getStorageDir() {
28073
- const dataHome = process.env.XDG_DATA_HOME || join13(homedir11(), ".local", "share");
28074
- 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");
28075
28105
  }
28076
28106
  function fileSize(path4) {
28077
28107
  try {
28078
- return existsSync15(path4) ? statSync2(path4).size : 0;
28108
+ return existsSync16(path4) ? statSync3(path4).size : 0;
28079
28109
  } catch {
28080
28110
  return 0;
28081
28111
  }
@@ -28087,7 +28117,7 @@ function sanitizeValue(value) {
28087
28117
  return sanitizeConfigValue(value);
28088
28118
  }
28089
28119
  function readConfig2(path4) {
28090
- if (!existsSync15(path4))
28120
+ if (!existsSync16(path4))
28091
28121
  return { value: null };
28092
28122
  try {
28093
28123
  const raw = readFileSync11(path4, "utf-8");
@@ -28146,11 +28176,11 @@ function parseHistorianDumpMeta(path4) {
28146
28176
  }
28147
28177
  }
28148
28178
  function listDumpsInDir(dir, limit) {
28149
- if (!existsSync15(dir))
28179
+ if (!existsSync16(dir))
28150
28180
  return { count: 0, recent: [] };
28151
28181
  try {
28152
28182
  const entries = readdirSync2(dir).filter((name) => name.endsWith(".xml")).map((name) => {
28153
- const stat = statSync2(join13(dir, name));
28183
+ const stat = statSync3(join14(dir, name));
28154
28184
  return {
28155
28185
  name,
28156
28186
  mtime: stat.mtimeMs,
@@ -28159,7 +28189,7 @@ function listDumpsInDir(dir, limit) {
28159
28189
  }).sort((a, b2) => b2.mtime - a.mtime);
28160
28190
  const now = Date.now();
28161
28191
  const recent = entries.slice(0, limit).map((entry) => {
28162
- const meta3 = parseHistorianDumpMeta(join13(dir, entry.name));
28192
+ const meta3 = parseHistorianDumpMeta(join14(dir, entry.name));
28163
28193
  const summary = {
28164
28194
  name: entry.name,
28165
28195
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -28214,8 +28244,8 @@ function collectHistorianDumps(recentSessions) {
28214
28244
  };
28215
28245
  }
28216
28246
  async function collectRecentSessions() {
28217
- const opencodeDbPath = join13(homedir11(), ".local", "share", "opencode", "opencode.db");
28218
- if (!existsSync15(opencodeDbPath))
28247
+ const opencodeDbPath = join14(homedir11(), ".local", "share", "opencode", "opencode.db");
28248
+ if (!existsSync16(opencodeDbPath))
28219
28249
  return [];
28220
28250
  if (typeof globalThis.Bun === "undefined") {
28221
28251
  return [];
@@ -28249,8 +28279,8 @@ async function collectRecentSessions() {
28249
28279
  }
28250
28280
  }
28251
28281
  async function collectHistorianFailures(storageDirPath) {
28252
- const contextDbPath = join13(storageDirPath, "context.db");
28253
- if (!existsSync15(contextDbPath))
28282
+ const contextDbPath = join14(storageDirPath, "context.db");
28283
+ if (!existsSync16(contextDbPath))
28254
28284
  return [];
28255
28285
  if (typeof globalThis.Bun === "undefined") {
28256
28286
  return [];
@@ -28289,9 +28319,9 @@ async function collectDiagnostics() {
28289
28319
  const tuiConfig = readConfig2(configPaths.tuiConfig);
28290
28320
  const magicContextConfig = readConfig2(configPaths.magicContextConfig);
28291
28321
  const storageDirPath = getStorageDir();
28292
- const contextDbPath = join13(storageDirPath, "context.db");
28322
+ const contextDbPath = join14(storageDirPath, "context.db");
28293
28323
  const logPath = getMagicContextLogPath2("opencode");
28294
- const logFileSize = existsSync15(logPath) ? statSync2(logPath).size : 0;
28324
+ const logFileSize = existsSync16(logPath) ? statSync3(logPath).size : 0;
28295
28325
  const conflictResult = detectConflicts(process.cwd());
28296
28326
  const recentSessions = await collectRecentSessions();
28297
28327
  return {
@@ -28306,7 +28336,7 @@ async function collectDiagnostics() {
28306
28336
  opencodeConfigHasPlugin: configHasPluginEntry(opencodeConfig.value),
28307
28337
  tuiConfigHasPlugin: configHasPluginEntry(tuiConfig.value),
28308
28338
  magicContextConfig: {
28309
- exists: existsSync15(configPaths.magicContextConfig),
28339
+ exists: existsSync16(configPaths.magicContextConfig),
28310
28340
  ...magicContextConfig.error ? { parseError: magicContextConfig.error } : {},
28311
28341
  flags: sanitizeValue(magicContextConfig.value ?? {}) ?? {}
28312
28342
  },
@@ -28314,7 +28344,7 @@ async function collectDiagnostics() {
28314
28344
  pluginCache: getPluginCacheInfo(),
28315
28345
  storageDir: {
28316
28346
  path: storageDirPath,
28317
- exists: existsSync15(storageDirPath),
28347
+ exists: existsSync16(storageDirPath),
28318
28348
  contextDbSizeBytes: fileSize(contextDbPath)
28319
28349
  },
28320
28350
  conflicts: {
@@ -28323,7 +28353,7 @@ async function collectDiagnostics() {
28323
28353
  },
28324
28354
  logFile: {
28325
28355
  path: logPath,
28326
- exists: existsSync15(logPath),
28356
+ exists: existsSync16(logPath),
28327
28357
  sizeKb: Math.round(logFileSize / 1024)
28328
28358
  },
28329
28359
  recentSessions,
@@ -28454,7 +28484,7 @@ var init_diagnostics_opencode = __esm(() => {
28454
28484
  // src/lib/logs-opencode.ts
28455
28485
  import { readFileSync as readFileSync12, writeFileSync as writeFileSync9 } from "node:fs";
28456
28486
  import { homedir as homedir12 } from "node:os";
28457
- import { join as join14 } from "node:path";
28487
+ import { join as join15 } from "node:path";
28458
28488
  function sanitizeLogContent(content) {
28459
28489
  return sanitizeDiagnosticText(content);
28460
28490
  }
@@ -28535,7 +28565,7 @@ async function bundleIssueReport(report, description, _title, sessionFilter = nu
28535
28565
  "```"
28536
28566
  ].join(`
28537
28567
  `);
28538
- 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`);
28539
28569
  writeFileSync9(path4, `${bodyMarkdown}
28540
28570
  `);
28541
28571
  return { path: path4, bodyMarkdown };
@@ -28557,10 +28587,10 @@ var init_logs_opencode = __esm(() => {
28557
28587
 
28558
28588
  // src/commands/doctor-opencode.ts
28559
28589
  import { execSync as execSync2, spawnSync as spawnSync2 } from "node:child_process";
28560
- 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";
28561
28591
  import { createRequire as createRequire4 } from "node:module";
28562
28592
  import { homedir as homedir13 } from "node:os";
28563
- import { join as join15 } from "node:path";
28593
+ import { join as join16 } from "node:path";
28564
28594
  async function fetchNpmLatest(pkg, timeoutMs = 5000) {
28565
28595
  try {
28566
28596
  const controller = new AbortController;
@@ -28610,14 +28640,14 @@ function compareVersions(a, b2) {
28610
28640
  }
28611
28641
  async function clearPluginCache(force = false) {
28612
28642
  const cacheDir = getOpenCodeCacheDir();
28613
- const pluginCacheDir = join15(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
28614
- if (!existsSync16(pluginCacheDir)) {
28643
+ const pluginCacheDir = join16(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
28644
+ if (!existsSync17(pluginCacheDir)) {
28615
28645
  return { action: "not_found", path: pluginCacheDir };
28616
28646
  }
28617
28647
  let cachedVersion;
28618
28648
  try {
28619
- const installedPkgPath = join15(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28620
- if (existsSync16(installedPkgPath)) {
28649
+ const installedPkgPath = join16(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
28650
+ if (existsSync17(installedPkgPath)) {
28621
28651
  const pkg = JSON.parse(readFileSync13(installedPkgPath, "utf-8"));
28622
28652
  if (typeof pkg?.version === "string") {
28623
28653
  cachedVersion = pkg.version;
@@ -28750,7 +28780,7 @@ async function runIssueFlow() {
28750
28780
  }
28751
28781
  }
28752
28782
  async function checkEmbeddingConfig(magicContextConfigPath) {
28753
- if (!existsSync16(magicContextConfigPath)) {
28783
+ if (!existsSync17(magicContextConfigPath)) {
28754
28784
  return { issues: 0 };
28755
28785
  }
28756
28786
  let rawText;
@@ -28884,6 +28914,8 @@ async function runDoctor(options = {}) {
28884
28914
  };
28885
28915
  if (!isOpenCodeInstalled()) {
28886
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.");
28887
28919
  outro("Doctor failed — install OpenCode first");
28888
28920
  return 1;
28889
28921
  }
@@ -28903,7 +28935,7 @@ async function runDoctor(options = {}) {
28903
28935
  } else {
28904
28936
  pass(`OpenCode config: ${paths.opencodeConfig}`);
28905
28937
  }
28906
- if (existsSync16(paths.magicContextConfig)) {
28938
+ if (existsSync17(paths.magicContextConfig)) {
28907
28939
  pass(`Magic Context config: ${paths.magicContextConfig}`);
28908
28940
  try {
28909
28941
  const raw = readFileSync13(paths.magicContextConfig, "utf-8");
@@ -28931,7 +28963,7 @@ async function runDoctor(options = {}) {
28931
28963
  warn(`No magic-context.jsonc found — using defaults`);
28932
28964
  log.info(" Run 'setup' to create one with model recommendations");
28933
28965
  }
28934
- if (existsSync16(paths.magicContextConfig)) {
28966
+ if (existsSync17(paths.magicContextConfig)) {
28935
28967
  try {
28936
28968
  const mcRaw = readFileSync13(paths.magicContextConfig, "utf-8");
28937
28969
  const mcConfig = import_comment_json9.parse(mcRaw);
@@ -29090,7 +29122,7 @@ async function runDoctor(options = {}) {
29090
29122
  pass("Added TUI sidebar plugin to tui.json");
29091
29123
  warn("Restart OpenCode to see the sidebar");
29092
29124
  fixed++;
29093
- } else if (existsSync16(paths.tuiConfig)) {
29125
+ } else if (existsSync17(paths.tuiConfig)) {
29094
29126
  try {
29095
29127
  const tuiRaw = readFileSync13(paths.tuiConfig, "utf-8");
29096
29128
  const tuiConfig = import_comment_json9.parse(tuiRaw);
@@ -29138,7 +29170,7 @@ async function runDoctor(options = {}) {
29138
29170
  } else {
29139
29171
  pass("TUI sidebar plugin configured (tui.json created)");
29140
29172
  }
29141
- if (existsSync16(paths.magicContextConfig)) {
29173
+ if (existsSync17(paths.magicContextConfig)) {
29142
29174
  try {
29143
29175
  const mcRaw = readFileSync13(paths.magicContextConfig, "utf-8");
29144
29176
  const mcConfig = import_comment_json9.parse(mcRaw);
@@ -29167,8 +29199,8 @@ async function runDoctor(options = {}) {
29167
29199
  failCount += embeddingCheck.issues;
29168
29200
  else
29169
29201
  passCount++;
29170
- const dbPath = join15(getMagicContextStorageDir(), "context.db");
29171
- if (!existsSync16(dbPath)) {
29202
+ const dbPath = join16(getMagicContextStorageDir(), "context.db");
29203
+ if (!existsSync17(dbPath)) {
29172
29204
  log.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
29173
29205
  } else {
29174
29206
  pass(`Shared context DB exists at ${dbPath}`);
@@ -29229,8 +29261,8 @@ async function runDoctor(options = {}) {
29229
29261
  }
29230
29262
  {
29231
29263
  const ageWarnings = [];
29232
- const npmrcPath = join15(homedir13(), ".npmrc");
29233
- if (existsSync16(npmrcPath)) {
29264
+ const npmrcPath = join16(homedir13(), ".npmrc");
29265
+ if (existsSync17(npmrcPath)) {
29234
29266
  try {
29235
29267
  const npmrc = readFileSync13(npmrcPath, "utf-8");
29236
29268
  for (const line of npmrc.split(`
@@ -29256,8 +29288,8 @@ async function runDoctor(options = {}) {
29256
29288
  }
29257
29289
  }
29258
29290
  const logPath = getMagicContextLogPath2("opencode");
29259
- if (existsSync16(logPath)) {
29260
- const logStat = statSync3(logPath);
29291
+ if (existsSync17(logPath)) {
29292
+ const logStat = statSync4(logPath);
29261
29293
  const sizeKb = (logStat.size / 1024).toFixed(0);
29262
29294
  log.info(`Log file: ${logPath} (${sizeKb} KB)`);
29263
29295
  } else {
@@ -161906,7 +161938,7 @@ function getErrorMessage(error51) {
161906
161938
  }
161907
161939
 
161908
161940
  // ../plugin/src/features/magic-context/key-files/project-key-files.ts
161909
- import { existsSync as existsSync17, readFileSync as readFileSync14, realpathSync } from "node:fs";
161941
+ import { existsSync as existsSync18, readFileSync as readFileSync14, realpathSync } from "node:fs";
161910
161942
  function deleteOrphanProjectKeyFiles(db, now = Date.now()) {
161911
161943
  const cutoff = now - ORPHAN_GRACE_MS;
161912
161944
  const rows = db.prepare(`SELECT project_path AS projectPath, MAX(generated_at) AS lastGen
@@ -161915,7 +161947,7 @@ function deleteOrphanProjectKeyFiles(db, now = Date.now()) {
161915
161947
  HAVING lastGen < ?`).all(cutoff);
161916
161948
  let deletedProjects = 0;
161917
161949
  for (const row of rows) {
161918
- if (existsSync17(row.projectPath))
161950
+ if (existsSync18(row.projectPath))
161919
161951
  continue;
161920
161952
  try {
161921
161953
  db.prepare("DELETE FROM project_key_files WHERE project_path = ?").run(row.projectPath);
@@ -162340,6 +162372,52 @@ var init_migrations = __esm(async () => {
162340
162372
  db.exec("ALTER TABLE session_meta ADD COLUMN deferred_execute_state TEXT");
162341
162373
  }
162342
162374
  }
162375
+ },
162376
+ {
162377
+ version: 16,
162378
+ description: "Add context-limit cache regression sentinels",
162379
+ up: (db) => {
162380
+ const cols = db.prepare("PRAGMA table_info(session_meta)").all();
162381
+ if (!cols.some((c2) => c2.name === "observed_safe_input_tokens")) {
162382
+ db.exec("ALTER TABLE session_meta ADD COLUMN observed_safe_input_tokens INTEGER NOT NULL DEFAULT 0");
162383
+ }
162384
+ if (!cols.some((c2) => c2.name === "cache_alert_sent")) {
162385
+ db.exec("ALTER TABLE session_meta ADD COLUMN cache_alert_sent INTEGER NOT NULL DEFAULT 0");
162386
+ }
162387
+ }
162388
+ },
162389
+ {
162390
+ version: 17,
162391
+ description: "Multi-anchor JSON storage for note-nudge and auto-search-hint persistence",
162392
+ up: (db) => {
162393
+ const cols = db.prepare("PRAGMA table_info(session_meta)").all();
162394
+ if (!cols.some((c2) => c2.name === "note_nudge_anchors")) {
162395
+ db.exec("ALTER TABLE session_meta ADD COLUMN note_nudge_anchors TEXT NOT NULL DEFAULT '[]'");
162396
+ }
162397
+ if (!cols.some((c2) => c2.name === "auto_search_hint_decisions")) {
162398
+ db.exec("ALTER TABLE session_meta ADD COLUMN auto_search_hint_decisions TEXT NOT NULL DEFAULT '[]'");
162399
+ }
162400
+ db.exec(`
162401
+ UPDATE session_meta
162402
+ SET note_nudge_anchors = json_array(
162403
+ json_object(
162404
+ 'messageId', note_nudge_sticky_message_id,
162405
+ 'text', note_nudge_sticky_text
162406
+ )
162407
+ )
162408
+ WHERE COALESCE(note_nudge_sticky_text, '') != ''
162409
+ AND COALESCE(note_nudge_sticky_message_id, '') != ''
162410
+ AND (note_nudge_anchors IS NULL OR note_nudge_anchors = '[]')
162411
+ `);
162412
+ db.exec(`
162413
+ UPDATE session_meta SET note_nudge_anchors = '[]'
162414
+ WHERE note_nudge_anchors IS NULL
162415
+ `);
162416
+ db.exec(`
162417
+ UPDATE session_meta SET auto_search_hint_decisions = '[]'
162418
+ WHERE auto_search_hint_decisions IS NULL
162419
+ `);
162420
+ }
162343
162421
  }
162344
162422
  ];
162345
162423
  });
@@ -162377,10 +162455,10 @@ var init_tool_definition_tokens = __esm(() => {
162377
162455
  });
162378
162456
 
162379
162457
  // ../plugin/src/features/magic-context/tool-owner-backfill.ts
162380
- import { existsSync as existsSync18 } from "node:fs";
162381
- import { join as join16 } from "node:path";
162458
+ import { existsSync as existsSync19 } from "node:fs";
162459
+ import { join as join17 } from "node:path";
162382
162460
  function resolveOpencodeDbPath() {
162383
- return join16(getDataDir(), "opencode", "opencode.db");
162461
+ return join17(getDataDir(), "opencode", "opencode.db");
162384
162462
  }
162385
162463
  function ensureBackfillStateTable(db) {
162386
162464
  db.exec(`
@@ -162415,7 +162493,7 @@ function runToolOwnerBackfill(db) {
162415
162493
  return result;
162416
162494
  }
162417
162495
  const opencodeDbPath = resolveOpencodeDbPath();
162418
- if (!existsSync18(opencodeDbPath)) {
162496
+ if (!existsSync19(opencodeDbPath)) {
162419
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.`);
162420
162498
  markAllUnbackfilledSessionsSkipped(db);
162421
162499
  result.sessionsSkippedNoOcDb = countSessionsByStatus(db, "skipped");
@@ -162625,25 +162703,25 @@ var init_tool_owner_backfill = __esm(() => {
162625
162703
  });
162626
162704
 
162627
162705
  // ../plugin/src/features/magic-context/storage-db.ts
162628
- import { copyFileSync, cpSync, existsSync as existsSync19, mkdirSync as mkdirSync7 } from "node:fs";
162629
- 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";
162630
162708
  function resolveDatabasePath() {
162631
162709
  const dbDir = getMagicContextStorageDir();
162632
- return { dbDir, dbPath: join17(dbDir, "context.db") };
162710
+ return { dbDir, dbPath: join18(dbDir, "context.db") };
162633
162711
  }
162634
162712
  function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
162635
- if (existsSync19(targetDbPath))
162713
+ if (existsSync20(targetDbPath))
162636
162714
  return;
162637
162715
  const legacyDir = getLegacyOpenCodeMagicContextStorageDir();
162638
- const legacyDbPath = join17(legacyDir, "context.db");
162639
- if (!existsSync19(legacyDbPath))
162716
+ const legacyDbPath = join18(legacyDir, "context.db");
162717
+ if (!existsSync20(legacyDbPath))
162640
162718
  return;
162641
162719
  log2(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
162642
162720
  mkdirSync7(targetDbDir, { recursive: true });
162643
162721
  for (const suffix of ["", "-wal", "-shm"]) {
162644
162722
  const src = `${legacyDbPath}${suffix}`;
162645
- const dst = join17(targetDbDir, `context.db${suffix}`);
162646
- if (existsSync19(src)) {
162723
+ const dst = join18(targetDbDir, `context.db${suffix}`);
162724
+ if (existsSync20(src)) {
162647
162725
  try {
162648
162726
  copyFileSync(src, dst);
162649
162727
  } catch (error51) {
@@ -162651,9 +162729,9 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
162651
162729
  }
162652
162730
  }
162653
162731
  }
162654
- const legacyModelsDir = join17(legacyDir, "models");
162655
- const targetModelsDir = join17(targetDbDir, "models");
162656
- if (existsSync19(legacyModelsDir) && !existsSync19(targetModelsDir)) {
162732
+ const legacyModelsDir = join18(legacyDir, "models");
162733
+ const targetModelsDir = join18(targetDbDir, "models");
162734
+ if (existsSync20(legacyModelsDir) && !existsSync20(targetModelsDir)) {
162657
162735
  try {
162658
162736
  cpSync(legacyModelsDir, targetModelsDir, { recursive: true });
162659
162737
  } catch (error51) {
@@ -162877,6 +162955,8 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
162877
162955
  note_nudge_trigger_message_id TEXT DEFAULT '',
162878
162956
  note_nudge_sticky_text TEXT DEFAULT '',
162879
162957
  note_nudge_sticky_message_id TEXT DEFAULT '',
162958
+ note_nudge_anchors TEXT NOT NULL DEFAULT '[]',
162959
+ auto_search_hint_decisions TEXT NOT NULL DEFAULT '[]',
162880
162960
  last_todo_state TEXT DEFAULT '',
162881
162961
  todo_synthetic_call_id TEXT DEFAULT '',
162882
162962
  todo_synthetic_anchor_message_id TEXT DEFAULT '',
@@ -162884,6 +162964,8 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
162884
162964
  is_subagent INTEGER DEFAULT 0,
162885
162965
  last_context_percentage REAL DEFAULT 0,
162886
162966
  last_input_tokens INTEGER DEFAULT 0,
162967
+ observed_safe_input_tokens INTEGER NOT NULL DEFAULT 0,
162968
+ cache_alert_sent INTEGER NOT NULL DEFAULT 0,
162887
162969
  times_execute_threshold_reached INTEGER DEFAULT 0,
162888
162970
  compartment_in_progress INTEGER DEFAULT 0,
162889
162971
  historian_failure_count INTEGER DEFAULT 0,
@@ -162955,12 +163037,16 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
162955
163037
  ensureColumn(db, "session_meta", "note_nudge_trigger_message_id", "TEXT DEFAULT ''");
162956
163038
  ensureColumn(db, "session_meta", "note_nudge_sticky_text", "TEXT DEFAULT ''");
162957
163039
  ensureColumn(db, "session_meta", "note_nudge_sticky_message_id", "TEXT DEFAULT ''");
163040
+ ensureColumn(db, "session_meta", "note_nudge_anchors", "TEXT NOT NULL DEFAULT '[]'");
163041
+ ensureColumn(db, "session_meta", "auto_search_hint_decisions", "TEXT NOT NULL DEFAULT '[]'");
162958
163042
  ensureColumn(db, "session_meta", "last_todo_state", "TEXT DEFAULT ''");
162959
163043
  ensureColumn(db, "session_meta", "todo_synthetic_call_id", "TEXT DEFAULT ''");
162960
163044
  ensureColumn(db, "session_meta", "todo_synthetic_anchor_message_id", "TEXT DEFAULT ''");
162961
163045
  ensureColumn(db, "session_meta", "todo_synthetic_state_json", "TEXT DEFAULT ''");
162962
163046
  ensureColumn(db, "session_meta", "note_last_read_at", "INTEGER DEFAULT 0");
162963
163047
  ensureColumn(db, "session_meta", "times_execute_threshold_reached", "INTEGER DEFAULT 0");
163048
+ ensureColumn(db, "session_meta", "observed_safe_input_tokens", "INTEGER NOT NULL DEFAULT 0");
163049
+ ensureColumn(db, "session_meta", "cache_alert_sent", "INTEGER NOT NULL DEFAULT 0");
162964
163050
  ensureColumn(db, "session_meta", "compartment_in_progress", "INTEGER DEFAULT 0");
162965
163051
  ensureColumn(db, "session_meta", "historian_failure_count", "INTEGER DEFAULT 0");
162966
163052
  ensureColumn(db, "session_meta", "historian_last_error", "TEXT DEFAULT NULL");
@@ -163052,7 +163138,9 @@ function healNullIntegerColumns(db) {
163052
163138
  ["system_prompt_tokens", 0],
163053
163139
  ["conversation_tokens", 0],
163054
163140
  ["tool_call_tokens", 0],
163055
- ["note_nudge_trigger_pending", 0]
163141
+ ["note_nudge_trigger_pending", 0],
163142
+ ["observed_safe_input_tokens", 0],
163143
+ ["cache_alert_sent", 0]
163056
163144
  ];
163057
163145
  for (const [column, fallback] of columns) {
163058
163146
  try {
@@ -163061,7 +163149,7 @@ function healNullIntegerColumns(db) {
163061
163149
  }
163062
163150
  }
163063
163151
  function ensureColumn(db, table, column, definition) {
163064
- if (!/^[a-z_]+$/.test(table) || !/^[a-z_]+$/.test(column) || !/^[A-Z0-9_'(),\s]+$/i.test(definition)) {
163152
+ if (!/^[a-z_]+$/.test(table) || !/^[a-z_]+$/.test(column) || !/^[A-Z0-9_'(),[\]\s]+$/i.test(definition)) {
163065
163153
  throw new Error(`Unsafe schema identifier: ${table}.${column} ${definition}`);
163066
163154
  }
163067
163155
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
@@ -163148,13 +163236,22 @@ var init_storage_db = __esm(async () => {
163148
163236
  // ../plugin/src/features/magic-context/storage-meta-shared.ts
163149
163237
  var BOOLEAN_META_KEYS;
163150
163238
  var init_storage_meta_shared = __esm(() => {
163151
- BOOLEAN_META_KEYS = new Set(["isSubagent", "compartmentInProgress"]);
163239
+ BOOLEAN_META_KEYS = new Set(["isSubagent", "compartmentInProgress", "cacheAlertSent"]);
163152
163240
  });
163153
163241
 
163154
163242
  // ../plugin/src/features/magic-context/storage-meta-persisted.ts
163243
+ var AUTO_SEARCH_NO_HINT_REASONS;
163155
163244
  var init_storage_meta_persisted = __esm(() => {
163156
163245
  init_logger();
163157
163246
  init_storage_meta_shared();
163247
+ AUTO_SEARCH_NO_HINT_REASONS = new Set([
163248
+ "below-threshold",
163249
+ "timeout",
163250
+ "empty",
163251
+ "error",
163252
+ "stacked",
163253
+ "too-short"
163254
+ ]);
163158
163255
  });
163159
163256
 
163160
163257
  // ../plugin/src/features/magic-context/resolve-subagent-fallback.ts
@@ -163237,20 +163334,20 @@ var init_storage = __esm(async () => {
163237
163334
  });
163238
163335
 
163239
163336
  // ../pi-plugin/src/config/index.ts
163240
- import { existsSync as existsSync20, readFileSync as readFileSync15 } from "node:fs";
163337
+ import { existsSync as existsSync21, readFileSync as readFileSync15 } from "node:fs";
163241
163338
  import { homedir as homedir14 } from "node:os";
163242
- import { join as join18 } from "node:path";
163339
+ import { join as join19 } from "node:path";
163243
163340
  function getProjectConfigPaths(cwd) {
163244
- const basePath = join18(cwd, ".pi", CONFIG_FILE_NAME);
163341
+ const basePath = join19(cwd, ".pi", CONFIG_FILE_NAME);
163245
163342
  return [`${basePath}.jsonc`, `${basePath}.json`];
163246
163343
  }
163247
163344
  function getUserConfigPaths() {
163248
163345
  const home = process.env.HOME ?? homedir14();
163249
- const basePath = join18(home, ".pi", "agent", CONFIG_FILE_NAME);
163346
+ const basePath = join19(home, ".pi", "agent", CONFIG_FILE_NAME);
163250
163347
  return [`${basePath}.jsonc`, `${basePath}.json`];
163251
163348
  }
163252
163349
  function resolveFirstExisting(paths) {
163253
- return paths.find((path4) => existsSync20(path4));
163350
+ return paths.find((path4) => existsSync21(path4));
163254
163351
  }
163255
163352
  function loadConfigFile2(path4, scope) {
163256
163353
  try {
@@ -163263,7 +163360,8 @@ function loadConfigFile2(path4, scope) {
163263
163360
  path: path4,
163264
163361
  scope,
163265
163362
  config: import_comment_json10.parse(substituted.text),
163266
- warnings: substituted.warnings.map((warning) => `${path4}: ${warning}`)
163363
+ warnings: substituted.warnings.map((warning) => `${path4}: ${warning}`),
163364
+ loadOutcome: substituted.warnings.length > 0 ? "substitution-failure" : "ok"
163267
163365
  };
163268
163366
  } catch (error51) {
163269
163367
  const message = error51 instanceof Error ? error51.message : String(error51);
@@ -163273,7 +163371,8 @@ function loadConfigFile2(path4, scope) {
163273
163371
  config: {},
163274
163372
  warnings: [
163275
163373
  `${path4}: failed to load config: ${message}; using defaults for this file.`
163276
- ]
163374
+ ],
163375
+ loadOutcome: typeof error51.code === "string" ? "project-file-io-error" : "project-file-parse-error"
163277
163376
  };
163278
163377
  }
163279
163378
  }
@@ -163308,7 +163407,7 @@ function mergeRawConfigs(base, override) {
163308
163407
  }
163309
163408
  return merged;
163310
163409
  }
163311
- function parsePiConfig(rawConfig) {
163410
+ function parsePiConfig(rawConfig, recoveredTopLevelKeys = []) {
163312
163411
  const parsed = MagicContextConfigSchema.safeParse(rawConfig);
163313
163412
  if (parsed.success) {
163314
163413
  return { config: parsed.data, warnings: [] };
@@ -163324,6 +163423,7 @@ function parsePiConfig(rawConfig) {
163324
163423
  const patched = { ...rawConfig };
163325
163424
  const warnings = [];
163326
163425
  for (const key of errorPaths) {
163426
+ recoveredTopLevelKeys.push(key);
163327
163427
  const isAgentConfig = key === "historian" || key === "dreamer" || key === "sidekick";
163328
163428
  delete patched[key];
163329
163429
  if (isAgentConfig) {
@@ -163384,10 +163484,10 @@ var init_config2 = __esm(() => {
163384
163484
 
163385
163485
  // src/lib/diagnostics-pi.ts
163386
163486
  import { createHash } from "node:crypto";
163387
- 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";
163388
163488
  import { createRequire as createRequire5 } from "node:module";
163389
163489
  import { homedir as homedir15, userInfo as userInfo2 } from "node:os";
163390
- import { join as join19 } from "node:path";
163490
+ import { join as join20 } from "node:path";
163391
163491
  function getSelfVersion3() {
163392
163492
  const req = createRequire5(import.meta.url);
163393
163493
  for (const relPath of ["../../package.json", "../package.json"]) {
@@ -163402,7 +163502,7 @@ function getSelfVersion3() {
163402
163502
  }
163403
163503
  function fileSize2(path4) {
163404
163504
  try {
163405
- return existsSync21(path4) ? statSync4(path4).size : 0;
163505
+ return existsSync22(path4) ? statSync5(path4).size : 0;
163406
163506
  } catch {
163407
163507
  return 0;
163408
163508
  }
@@ -163452,7 +163552,7 @@ function sanitizeValue2(value, key = "") {
163452
163552
  return value;
163453
163553
  }
163454
163554
  function readJsonc3(path4) {
163455
- if (!existsSync21(path4))
163555
+ if (!existsSync22(path4))
163456
163556
  return { value: {} };
163457
163557
  try {
163458
163558
  return {
@@ -163466,13 +163566,13 @@ function readJsonc3(path4) {
163466
163566
  }
163467
163567
  }
163468
163568
  function getProjectConfigPath(cwd) {
163469
- return join19(cwd, ".pi", "magic-context.jsonc");
163569
+ return join20(cwd, ".pi", "magic-context.jsonc");
163470
163570
  }
163471
163571
  function readConfigDiagnostic(path4) {
163472
163572
  const parsed = readJsonc3(path4);
163473
163573
  return {
163474
163574
  path: path4,
163475
- exists: existsSync21(path4),
163575
+ exists: existsSync22(path4),
163476
163576
  ...parsed.parseError ? { parseError: parsed.parseError } : {},
163477
163577
  flags: sanitizeValue2(parsed.value)
163478
163578
  };
@@ -163489,8 +163589,8 @@ function reverseSlugToDirectory(slug) {
163489
163589
  return `/${inner.replace(/-/g, "/")}`;
163490
163590
  }
163491
163591
  function collectPiRecentSessions() {
163492
- const sessionsRoot = join19(homedir15(), ".pi", "agent", "sessions");
163493
- if (!existsSync21(sessionsRoot))
163592
+ const sessionsRoot = join20(homedir15(), ".pi", "agent", "sessions");
163593
+ if (!existsSync22(sessionsRoot))
163494
163594
  return [];
163495
163595
  try {
163496
163596
  const slugs = readdirSync3(sessionsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
@@ -163499,7 +163599,7 @@ function collectPiRecentSessions() {
163499
163599
  const directory = reverseSlugToDirectory(slug);
163500
163600
  if (!directory)
163501
163601
  continue;
163502
- const slugDir = join19(sessionsRoot, slug);
163602
+ const slugDir = join20(sessionsRoot, slug);
163503
163603
  let files;
163504
163604
  try {
163505
163605
  files = readdirSync3(slugDir).filter((name2) => name2.endsWith(".jsonl"));
@@ -163508,7 +163608,7 @@ function collectPiRecentSessions() {
163508
163608
  }
163509
163609
  for (const file2 of files) {
163510
163610
  try {
163511
- const mtime = statSync4(join19(slugDir, file2)).mtimeMs;
163611
+ const mtime = statSync5(join20(slugDir, file2)).mtimeMs;
163512
163612
  const sessionId = file2.replace(/\.jsonl$/, "");
163513
163613
  candidates.push({ sessionId, directory, mtime });
163514
163614
  } catch {}
@@ -163559,11 +163659,11 @@ function parseHistorianDumpMeta2(path4) {
163559
163659
  }
163560
163660
  }
163561
163661
  function listDumpsInDir2(dir, limit) {
163562
- if (!existsSync21(dir))
163662
+ if (!existsSync22(dir))
163563
163663
  return { count: 0, recent: [] };
163564
163664
  try {
163565
163665
  const entries = readdirSync3(dir).filter((name2) => name2.endsWith(".xml")).map((name2) => {
163566
- const stat = statSync4(join19(dir, name2));
163666
+ const stat = statSync5(join20(dir, name2));
163567
163667
  return {
163568
163668
  name: name2,
163569
163669
  mtime: stat.mtimeMs,
@@ -163572,7 +163672,7 @@ function listDumpsInDir2(dir, limit) {
163572
163672
  }).sort((a, b2) => b2.mtime - a.mtime);
163573
163673
  const now = Date.now();
163574
163674
  const recent = entries.slice(0, limit).map((entry) => {
163575
- const meta3 = parseHistorianDumpMeta2(join19(dir, entry.name));
163675
+ const meta3 = parseHistorianDumpMeta2(join20(dir, entry.name));
163576
163676
  const summary = {
163577
163677
  name: entry.name,
163578
163678
  ageMinutes: Math.round((now - entry.mtime) / 60000),
@@ -163635,9 +163735,9 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163635
163735
  const projectConfigPath = getProjectConfigPath(cwd);
163636
163736
  const loaded = loadPiConfig({ cwd });
163637
163737
  const storageDirPath = getMagicContextStorageDir();
163638
- const dbPath = join19(storageDirPath, "context.db");
163738
+ const dbPath = join20(storageDirPath, "context.db");
163639
163739
  const logPath = getMagicContextLogPath2("pi");
163640
- const logFileSize = existsSync21(logPath) ? statSync4(logPath).size : 0;
163740
+ const logFileSize = existsSync22(logPath) ? statSync5(logPath).size : 0;
163641
163741
  const otherPiExtensions = packages.filter((entry) => !isPiMagicContextPackageEntry(entry)).map(describePiPackageEntry);
163642
163742
  const recentSessions = collectPiRecentSessions();
163643
163743
  const historianDumps = collectPiHistorianDumps(recentSessions);
@@ -163652,7 +163752,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163652
163752
  piVersion: pi ? getPiVersion(pi.path) : null,
163653
163753
  settings: {
163654
163754
  path: settingsPath,
163655
- exists: existsSync21(settingsPath),
163755
+ exists: existsSync22(settingsPath),
163656
163756
  ...settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {},
163657
163757
  hasMagicContextPackage: hasPiMagicContextPackage(packages),
163658
163758
  packages: sanitizeValue2(packages)
@@ -163668,7 +163768,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163668
163768
  loadWarnings: loaded.warnings.map(sanitizeString2),
163669
163769
  storageDir: {
163670
163770
  path: storageDirPath,
163671
- exists: existsSync21(storageDirPath),
163771
+ exists: existsSync22(storageDirPath),
163672
163772
  contextDbSizeBytes: fileSize2(dbPath)
163673
163773
  },
163674
163774
  conflicts: {
@@ -163677,7 +163777,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
163677
163777
  },
163678
163778
  logFile: {
163679
163779
  path: logPath,
163680
- exists: existsSync21(logPath),
163780
+ exists: existsSync22(logPath),
163681
163781
  sizeKb: Math.round(logFileSize / 1024)
163682
163782
  },
163683
163783
  recentSessions,
@@ -163771,7 +163871,7 @@ var init_diagnostics_pi = __esm(() => {
163771
163871
 
163772
163872
  // src/lib/logs-pi.ts
163773
163873
  import { readFileSync as readFileSync17, writeFileSync as writeFileSync11 } from "node:fs";
163774
- import { join as join20 } from "node:path";
163874
+ import { join as join21 } from "node:path";
163775
163875
  function sanitizeLogContent2(content) {
163776
163876
  return sanitizeString2(content);
163777
163877
  }
@@ -163827,7 +163927,7 @@ async function bundleIssueReport2(report, description, title, options = {}) {
163827
163927
  ].join(`
163828
163928
  `);
163829
163929
  const cwd = options.cwd ?? process.cwd();
163830
- 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`);
163831
163931
  writeFileSync11(path4, `${bodyMarkdown}
163832
163932
  `);
163833
163933
  return { path: path4, bodyMarkdown };
@@ -163837,19 +163937,19 @@ var init_logs_pi = __esm(() => {
163837
163937
  });
163838
163938
 
163839
163939
  // src/commands/doctor-pi.ts
163840
- import { execFileSync as execFileSync4, spawnSync as spawnSync3 } from "node:child_process";
163940
+ import { execFileSync as execFileSync3, spawnSync as spawnSync3 } from "node:child_process";
163841
163941
  import {
163842
- existsSync as existsSync22,
163942
+ existsSync as existsSync23,
163843
163943
  mkdirSync as mkdirSync8,
163844
163944
  readdirSync as readdirSync4,
163845
163945
  readFileSync as readFileSync18,
163846
163946
  rmSync as rmSync2,
163847
- statSync as statSync5,
163947
+ statSync as statSync6,
163848
163948
  writeFileSync as writeFileSync12
163849
163949
  } from "node:fs";
163850
163950
  import { createRequire as createRequire6 } from "node:module";
163851
163951
  import { homedir as homedir16 } from "node:os";
163852
- import { dirname as dirname9, join as join21 } from "node:path";
163952
+ import { dirname as dirname9, join as join22 } from "node:path";
163853
163953
  function depsFrom(options) {
163854
163954
  return {
163855
163955
  ...DEFAULT_DEPS,
@@ -163882,7 +163982,7 @@ function selfVersion() {
163882
163982
  }
163883
163983
  function getLatestNpmVersion(packageName) {
163884
163984
  try {
163885
- return execFileSync4("npm", ["view", packageName, "version"], {
163985
+ return execFileSync3("npm", ["view", packageName, "version"], {
163886
163986
  encoding: "utf-8",
163887
163987
  stdio: ["ignore", "pipe", "ignore"],
163888
163988
  timeout: 1e4
@@ -163949,10 +164049,10 @@ function packagesFrom(settings) {
163949
164049
  return Array.isArray(settings.packages) ? settings.packages : [];
163950
164050
  }
163951
164051
  function projectConfigPath(cwd) {
163952
- return join21(cwd, ".pi", "magic-context.jsonc");
164052
+ return join22(cwd, ".pi", "magic-context.jsonc");
163953
164053
  }
163954
164054
  function readConfigForEmbedding(path4) {
163955
- if (!existsSync22(path4))
164055
+ if (!existsSync23(path4))
163956
164056
  return null;
163957
164057
  try {
163958
164058
  const rawText = readFileSync18(path4, "utf-8");
@@ -164014,30 +164114,30 @@ function countTable(db, table) {
164014
164114
  }
164015
164115
  function cacheRoots() {
164016
164116
  const home = homedir16();
164017
- const cacheHome = process.env.XDG_CACHE_HOME || join21(home, ".cache");
164117
+ const cacheHome = process.env.XDG_CACHE_HOME || join22(home, ".cache");
164018
164118
  return [
164019
- join21(home, ".pi", "cache", "extensions"),
164020
- join21(home, ".pi", "cache", "packages"),
164021
- join21(cacheHome, "pi", "extensions"),
164022
- join21(cacheHome, "pi", "packages"),
164023
- 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")
164024
164124
  ];
164025
164125
  }
164026
164126
  function findPiMagicContextCacheDirs(self, force = false) {
164027
164127
  const found = new Map;
164028
164128
  const visit = (path4, depth) => {
164029
- if (depth < 0 || !existsSync22(path4))
164129
+ if (depth < 0 || !existsSync23(path4))
164030
164130
  return;
164031
164131
  let stat;
164032
164132
  try {
164033
- stat = statSync5(path4);
164133
+ stat = statSync6(path4);
164034
164134
  } catch {
164035
164135
  return;
164036
164136
  }
164037
164137
  if (!stat.isDirectory())
164038
164138
  return;
164039
- const packageJson = join21(path4, "package.json");
164040
- if (existsSync22(packageJson)) {
164139
+ const packageJson = join22(path4, "package.json");
164140
+ if (existsSync23(packageJson)) {
164041
164141
  try {
164042
164142
  const pkg = JSON.parse(readFileSync18(packageJson, "utf-8"));
164043
164143
  const name2 = typeof pkg.name === "string" ? pkg.name : "";
@@ -164058,7 +164158,7 @@ function findPiMagicContextCacheDirs(self, force = false) {
164058
164158
  return;
164059
164159
  }
164060
164160
  for (const entry of entries)
164061
- visit(join21(path4, entry), depth - 1);
164161
+ visit(join22(path4, entry), depth - 1);
164062
164162
  };
164063
164163
  for (const root of cacheRoots())
164064
164164
  visit(root, 5);
@@ -164095,7 +164195,7 @@ async function runHealthChecks(options) {
164095
164195
  }
164096
164196
  const settingsPath = getPiUserExtensionsPath();
164097
164197
  let packages = [];
164098
- if (!existsSync22(settingsPath)) {
164198
+ if (!existsSync23(settingsPath)) {
164099
164199
  add(results, "warn", `Pi settings not found at ${settingsPath}`);
164100
164200
  repairPlan.addPackageEntry = true;
164101
164201
  } else {
@@ -164119,7 +164219,7 @@ async function runHealthChecks(options) {
164119
164219
  ["user", userConfigPath, true],
164120
164220
  ["project", projectPath, false]
164121
164221
  ]) {
164122
- if (!existsSync22(path4)) {
164222
+ if (!existsSync23(path4)) {
164123
164223
  if (required2) {
164124
164224
  add(results, "warn", `No ${label} magic-context.jsonc found at ${path4}`);
164125
164225
  repairPlan.writeUserConfig = true;
@@ -164152,8 +164252,8 @@ async function runHealthChecks(options) {
164152
164252
  add(results, "pass", `historian.model "${historianModel}" has thinking_level "${historianThinkingLevel}" configured`);
164153
164253
  }
164154
164254
  const storageDir = getMagicContextStorageDir();
164155
- const dbPath = join21(storageDir, "context.db");
164156
- const existedBeforeOpen = existsSync22(dbPath);
164255
+ const dbPath = join22(storageDir, "context.db");
164256
+ const existedBeforeOpen = existsSync23(dbPath);
164157
164257
  if (existedBeforeOpen)
164158
164258
  add(results, "pass", `Shared context DB exists at ${dbPath}`);
164159
164259
  else
@@ -164230,8 +164330,8 @@ async function runHealthChecks(options) {
164230
164330
  add(results, "pass", "Pi extension cache clean (no stale cached package found)");
164231
164331
  }
164232
164332
  const logPath = getMagicContextLogPath2("pi");
164233
- if (existsSync22(logPath)) {
164234
- const stat = statSync5(logPath);
164333
+ if (existsSync23(logPath)) {
164334
+ const stat = statSync6(logPath);
164235
164335
  const sizeKb = (stat.size / 1024).toFixed(0);
164236
164336
  const lines = readFileSync18(logPath, "utf-8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
164237
164337
  add(results, "info", `Log file: ${logPath} (${sizeKb} KB)`);
@@ -164289,7 +164389,7 @@ function repair(plan, prompts) {
164289
164389
  }
164290
164390
  if (plan.writeUserConfig) {
164291
164391
  const configPath = getPiUserConfigPath();
164292
- if (!existsSync22(configPath)) {
164392
+ if (!existsSync23(configPath)) {
164293
164393
  try {
164294
164394
  writeDefaultMagicContextConfig(configPath);
164295
164395
  prompts.log.success(`Wrote default Magic Context config to ${configPath}`);
@@ -164458,7 +164558,7 @@ var init_doctor_pi = __esm(async () => {
164458
164558
  isDatabasePersisted,
164459
164559
  closeDatabase,
164460
164560
  now: () => new Date,
164461
- execFileSync: execFileSync4,
164561
+ execFileSync: execFileSync3,
164462
164562
  spawnSync: spawnSync3
164463
164563
  };
164464
164564
  });
@@ -164468,7 +164568,7 @@ var exports_doctor = {};
164468
164568
  __export(exports_doctor, {
164469
164569
  runDoctor: () => runDoctor3
164470
164570
  });
164471
- import { existsSync as existsSync23, rmSync as rmSync3 } from "node:fs";
164571
+ import { existsSync as existsSync24, rmSync as rmSync3 } from "node:fs";
164472
164572
  async function runDoctor3(options) {
164473
164573
  if (options.clear)
164474
164574
  return runClear();
@@ -164552,7 +164652,7 @@ async function runClear() {
164552
164652
  const s = spinner();
164553
164653
  s.start(`Clearing ${item.path}`);
164554
164654
  try {
164555
- if (existsSync23(item.path)) {
164655
+ if (existsSync24(item.path)) {
164556
164656
  rmSync3(item.path, { recursive: true, force: true });
164557
164657
  }
164558
164658
  s.stop(`Cleared ${item.path}`);