context-mode 2.1.1 → 2.1.3

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.
@@ -24,6 +24,8 @@ var STATE_CLOSE_TAG = "</context_mode_state>";
24
24
  var INDEX_WRITE_CHUNK = 1048576;
25
25
  var SYNC_INDEX_MAX_BYTES = 65536;
26
26
  var REPLACE_TRIGGER_BYTES = 4096;
27
+ var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
28
+ var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
27
29
  var REPLACE_RETURN_BYTES = 96;
28
30
  var SHAPE_RETURN_BYTES = 256;
29
31
  var REPLACE_CHUNK_BYTES = 48;
@@ -426,7 +428,7 @@ var DECISION_OPTION_KEY = "option";
426
428
  var DECISION_LABEL_JOIN = " | ";
427
429
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
428
430
  var RELEASE_BRANCH = "release";
429
- var BUNDLE_SHA = true ? "2652fe27fc5d4e368fdc38eda49d3011d38e631e" : void 0;
431
+ var BUNDLE_SHA = true ? "83f2da691359eaaf61f7baba841dea1942d3ccc1" : void 0;
430
432
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
431
433
  var DOCTOR_LABEL = Object.freeze({
432
434
  D1: "version",
@@ -685,6 +687,7 @@ var REGEX_SPECIAL_CHARS = ".*+?^${}()|[]\\";
685
687
  var REGEX_ESCAPE = "\\";
686
688
  var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
687
689
  var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
690
+ var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
688
691
  var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
689
692
  function D5_SLOW_DETAIL(ms) {
690
693
  return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
@@ -743,6 +746,11 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
743
746
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
744
747
  var V1_STATUSLINE_COMMAND = "context-mode statusline";
745
748
  var V1_PI_PACKAGE = "npm:context-mode";
749
+ var PI_NPM_DIR = "npm";
750
+ var PI_NODE_MODULES_DIR = "node_modules";
751
+ var PI_PACKAGE_JSON_FILE = "package.json";
752
+ var PI_LIST_COMMAND = "pi list";
753
+ var PI_CURRENT_MAJOR = 2;
746
754
  var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
747
755
  var V1_TMP_PREFIX = "context-mode-";
748
756
  var V1_TOML_SECTION_ROOT = "mcp_servers";
@@ -1365,6 +1373,14 @@ function canonicalName3(name) {
1365
1373
  if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
1366
1374
  return name;
1367
1375
  }
1376
+ var isNum = (v) => typeof v === "number" && Number.isFinite(v);
1377
+ function viewRange(name, input) {
1378
+ const r = input.view_range;
1379
+ if (name !== "view" || !Array.isArray(r) || !isNum(r[0])) return input;
1380
+ const out = { ...input, offset: r[0] };
1381
+ if (isNum(r[1]) && r[1] >= r[0]) out.limit = r[1] - r[0] + 1;
1382
+ return out;
1383
+ }
1368
1384
  function readArgs(v) {
1369
1385
  if (isRecord(v)) return v;
1370
1386
  if (typeof v !== "string") return {};
@@ -1409,7 +1425,7 @@ function decode5(raw) {
1409
1425
  if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
1410
1426
  if (event === "PreToolUse" || event === "PostToolUse") {
1411
1427
  const toolName2 = String(raw[k.tool] ?? "");
1412
- const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
1428
+ const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
1413
1429
  ev.tool = tool;
1414
1430
  }
1415
1431
  if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
@@ -1457,18 +1473,18 @@ function canonicalName4(name) {
1457
1473
  if (sep4 <= 0 || sep4 === rest.length - 1) return name;
1458
1474
  return "mcp:" + rest.slice(0, sep4) + ":" + rest.slice(sep4 + MCP_SEP2.length);
1459
1475
  }
1460
- var isNum = (v) => typeof v === "number" && Number.isFinite(v);
1476
+ var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
1461
1477
  function policyInput(name, canonical, input) {
1462
1478
  if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
1463
1479
  const out = { ...input };
1464
1480
  if (name === "read_file") {
1465
1481
  if (typeof input.filePath === "string") out.file_path = input.filePath;
1466
- if (isNum(input.startLine)) out.offset = input.startLine;
1467
- if (isNum(input.startLine) && isNum(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
1468
- } else if (Array.isArray(input.view_range) && isNum(input.view_range[0])) {
1482
+ if (isNum2(input.startLine)) out.offset = input.startLine;
1483
+ if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
1484
+ } else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
1469
1485
  out.offset = input.view_range[0];
1470
1486
  const end = input.view_range[1];
1471
- if (isNum(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
1487
+ if (isNum2(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
1472
1488
  }
1473
1489
  return out;
1474
1490
  }
@@ -1658,7 +1674,7 @@ var PI_EVENTS = {
1658
1674
  tool_call: { event: "PreToolUse" },
1659
1675
  tool_result: { event: "PostToolUse" }
1660
1676
  };
1661
- var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
1677
+ var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
1662
1678
  function record(v) {
1663
1679
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
1664
1680
  }
@@ -1928,8 +1944,9 @@ var ADAPTERS = Object.freeze([
1928
1944
  installMode: "in-process",
1929
1945
  projectSource: "pi:ctx.cwd",
1930
1946
  toolNamePrefix: TOOL_NAME_PREFIX9,
1931
- nativeTools: { shell: ["bash"], read: ["read"] },
1947
+ nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
1932
1948
  execReadOnlyHint: false,
1949
+ // D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
1933
1950
  eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
1934
1951
  compactDelivery: "pi-flag",
1935
1952
  compactSummary: "none",
@@ -3328,21 +3345,21 @@ function kiroDirOf(env, home, platform = process.platform) {
3328
3345
  if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
3329
3346
  if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
3330
3347
  const abs = p.resolve(dir);
3331
- const real2 = platform === process.platform ? realOrSelf : (x) => x;
3332
- const target = real2(abs);
3348
+ const real3 = platform === process.platform ? realOrSelf : (x) => x;
3349
+ const target = real3(abs);
3333
3350
  if (p.parse(target).root === target) return fallback;
3334
- const up = p.relative(target, real2(p.resolve(home)));
3351
+ const up = p.relative(target, real3(p.resolve(home)));
3335
3352
  if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
3336
3353
  return abs;
3337
3354
  }
3338
- function realOrSelf(path7) {
3355
+ function realOrSelf(path8) {
3339
3356
  const tail = [];
3340
- for (let at2 = path7; ; ) {
3357
+ for (let at2 = path8; ; ) {
3341
3358
  try {
3342
3359
  return join(realpathSync.native(at2), ...tail.reverse());
3343
3360
  } catch {
3344
3361
  const up = dirname(at2);
3345
- if (up === at2) return path7;
3362
+ if (up === at2) return path8;
3346
3363
  tail.push(basename(at2));
3347
3364
  at2 = up;
3348
3365
  }
@@ -3467,10 +3484,10 @@ function readPluginAgent(claudeDir, type) {
3467
3484
  }
3468
3485
  return null;
3469
3486
  }
3470
- function readAgentFile(path7) {
3487
+ function readAgentFile(path8) {
3471
3488
  let text;
3472
3489
  try {
3473
- text = readFileSync(path7, "utf8");
3490
+ text = readFileSync(path8, "utf8");
3474
3491
  } catch {
3475
3492
  return null;
3476
3493
  }
@@ -3733,12 +3750,12 @@ function readUserDeny(projectDir, agent) {
3733
3750
  }
3734
3751
  return out;
3735
3752
  }
3736
- function tokenize(glob, path7) {
3753
+ function tokenize(glob, path8) {
3737
3754
  const toks = [];
3738
3755
  let i = 0;
3739
3756
  while (i < glob.length) {
3740
3757
  const c = glob[i];
3741
- if (c === "*" && path7 && glob[i + 1] === "*") {
3758
+ if (c === "*" && path8 && glob[i + 1] === "*") {
3742
3759
  const dir = glob[i + "**".length] === "/";
3743
3760
  toks.push({ t: dir ? "globstarDir" : "globstar" });
3744
3761
  i += dir ? "**/".length : "**".length;
@@ -3752,8 +3769,8 @@ function tokenize(glob, path7) {
3752
3769
  }
3753
3770
  return toks;
3754
3771
  }
3755
- function globMatch(glob, text, path7) {
3756
- const toks = tokenize(glob, path7);
3772
+ function globMatch(glob, text, path8) {
3773
+ const toks = tokenize(glob, path8);
3757
3774
  const n = text.length;
3758
3775
  let next = new Uint8Array(n + 1);
3759
3776
  next[n] = 1;
@@ -3769,10 +3786,10 @@ function globMatch(glob, text, path7) {
3769
3786
  cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
3770
3787
  break;
3771
3788
  case "any1":
3772
- cur[j] = has3 && !(path7 && ch === "/") ? next[j + 1] : 0;
3789
+ cur[j] = has3 && !(path8 && ch === "/") ? next[j + 1] : 0;
3773
3790
  break;
3774
3791
  case "star":
3775
- cur[j] = next[j] || (has3 && !(path7 && ch === "/") ? cur[j + 1] : 0);
3792
+ cur[j] = next[j] || (has3 && !(path8 && ch === "/") ? cur[j + 1] : 0);
3776
3793
  break;
3777
3794
  case "globstar":
3778
3795
  cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
@@ -3852,8 +3869,8 @@ var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limi
3852
3869
  // src/core/policy/read-deny.ts
3853
3870
  var SIZE = "{size}";
3854
3871
  var PATH = "{path}";
3855
- function READ_DENY_MESSAGE(path7, size, prefix = "") {
3856
- return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path7);
3872
+ function READ_DENY_MESSAGE(path8, size, prefix = "") {
3873
+ return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
3857
3874
  }
3858
3875
 
3859
3876
  // src/core/policy/decide.ts
@@ -4561,9 +4578,9 @@ function readUserVersion(raw) {
4561
4578
  const row5 = raw.prepare("PRAGMA user_version").get();
4562
4579
  return row5.user_version;
4563
4580
  }
4564
- function createAtomically(sqlite, path7) {
4581
+ function createAtomically(sqlite, path8) {
4565
4582
  const { randomUUID } = process.getBuiltinModule("node:crypto");
4566
- const tmp = path7 + "." + randomUUID() + DB_TMP_SUFFIX;
4583
+ const tmp = path8 + "." + randomUUID() + DB_TMP_SUFFIX;
4567
4584
  try {
4568
4585
  const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
4569
4586
  try {
@@ -4572,7 +4589,7 @@ function createAtomically(sqlite, path7) {
4572
4589
  raw.close();
4573
4590
  }
4574
4591
  try {
4575
- linkSync(tmp, path7);
4592
+ linkSync(tmp, path8);
4576
4593
  } catch (err) {
4577
4594
  if (err.code !== "EEXIST") throw err;
4578
4595
  }
@@ -4580,11 +4597,11 @@ function createAtomically(sqlite, path7) {
4580
4597
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
4581
4598
  }
4582
4599
  }
4583
- function openWritable(sqlite, path7) {
4600
+ function openWritable(sqlite, path8) {
4584
4601
  let raw = null;
4585
4602
  try {
4586
- if (!existsSync2(path7)) createAtomically(sqlite, path7);
4587
- raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
4603
+ if (!existsSync2(path8)) createAtomically(sqlite, path8);
4604
+ raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
4588
4605
  applyMigrations(raw, readUserVersion(raw));
4589
4606
  return raw;
4590
4607
  } catch (err) {
@@ -4592,8 +4609,8 @@ function openWritable(sqlite, path7) {
4592
4609
  throw err;
4593
4610
  }
4594
4611
  }
4595
- function openReadOnly(sqlite, path7) {
4596
- const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
4612
+ function openReadOnly(sqlite, path8) {
4613
+ const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
4597
4614
  try {
4598
4615
  const found = readUserVersion(raw);
4599
4616
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -4607,20 +4624,20 @@ async function openDb(project, opts) {
4607
4624
  if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
4608
4625
  const sqlite = await loadSqlite();
4609
4626
  mkdirSync2(project.projectDir, { recursive: true });
4610
- const path7 = project.dbPath;
4611
- const sibling = existsSync2(path7 + DB_WAL_SUFFIX) || existsSync2(path7 + DB_SHM_SUFFIX);
4612
- if (sibling && !existsSync2(path7)) {
4627
+ const path8 = project.dbPath;
4628
+ const sibling = existsSync2(path8 + DB_WAL_SUFFIX) || existsSync2(path8 + DB_SHM_SUFFIX);
4629
+ if (sibling && !existsSync2(path8)) {
4613
4630
  throw new CtxError("DB_GONE");
4614
4631
  }
4615
4632
  try {
4616
4633
  let raw;
4617
4634
  if (opts?.readOnly === true) {
4618
- if (!existsSync2(path7)) openWritable(sqlite, path7).close();
4619
- raw = openReadOnly(sqlite, path7);
4635
+ if (!existsSync2(path8)) openWritable(sqlite, path8).close();
4636
+ raw = openReadOnly(sqlite, path8);
4620
4637
  } else {
4621
- raw = openWritable(sqlite, path7);
4638
+ raw = openWritable(sqlite, path8);
4622
4639
  }
4623
- return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
4640
+ return { raw, projectKey: project.projectKey, path: path8, ...opts?.readOnly === true ? { readOnly: true } : {} };
4624
4641
  } catch (err) {
4625
4642
  if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
4626
4643
  throw err;
@@ -7415,8 +7432,8 @@ function buildCandidates(rows, sessionId) {
7415
7432
  edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
7416
7433
  }
7417
7434
  const changedFiles = [];
7418
- for (const [path7, e] of edits) {
7419
- const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
7435
+ for (const [path8, e] of edits) {
7436
+ const c = make("changed_files", e.row, "edited " + path8 + " x" + e.count, e.count, path8);
7420
7437
  changedFiles.push({ ...c, editCount: e.count });
7421
7438
  }
7422
7439
  changedFiles.sort((a, b) => a.seq - b.seq);
@@ -8750,9 +8767,13 @@ async function preToolUse(ev, row5, project, env) {
8750
8767
  const userDeny = readUserDeny(project.worktree, ev.agent);
8751
8768
  const decision0 = decide(ev, row5, userDeny);
8752
8769
  let decision = decision0;
8753
- if (decision0.kind === "deny" && isSubagentCall(ev)) {
8754
- const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
8755
- if (subCase === "B") decision = caseB(ev, row5, decision0, userDeny);
8770
+ if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
8771
+ const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
8772
+ const subCase = pickSubagentCase(ev, set3);
8773
+ const tool = ev.tool;
8774
+ const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
8775
+ if (subCase === "B" && tool !== void 0 && isShell(tool, row5)) decision = caseB(ev, row5, decision0, userDeny);
8776
+ else if (subCase !== "A" && runs) decision = ALLOW2;
8756
8777
  }
8757
8778
  return decision;
8758
8779
  }
@@ -8849,6 +8870,7 @@ async function postToolUse(ev, row5, project, env, settle) {
8849
8870
  }
8850
8871
  async function postReplace(ev, row5, project, env, tool, result, text) {
8851
8872
  if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
8873
+ if (boundedRead(tool)) return ALLOW2;
8852
8874
  if (result.keep === true) return ALLOW2;
8853
8875
  if (!hasReplace(row5)) return ALLOW2;
8854
8876
  let label2;
@@ -8880,6 +8902,9 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
8880
8902
  const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
8881
8903
  return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, handleLine) : selected.text };
8882
8904
  }
8905
+ function boundedRead(tool) {
8906
+ return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
8907
+ }
8883
8908
  function replaceOutput(body, handleLine) {
8884
8909
  return body === "" ? handleLine : body + "\n" + handleLine;
8885
8910
  }
@@ -9614,10 +9639,10 @@ function assignProp(target, prop, value) {
9614
9639
  configurable: true
9615
9640
  });
9616
9641
  }
9617
- function getElementAtPath(obj, path7) {
9618
- if (!path7)
9642
+ function getElementAtPath(obj, path8) {
9643
+ if (!path8)
9619
9644
  return obj;
9620
- return path7.reduce((acc, key) => acc?.[key], obj);
9645
+ return path8.reduce((acc, key) => acc?.[key], obj);
9621
9646
  }
9622
9647
  function promiseAllObject(promisesObj) {
9623
9648
  const keys = Object.keys(promisesObj);
@@ -9937,11 +9962,11 @@ function aborted(x, startIndex = 0) {
9937
9962
  }
9938
9963
  return false;
9939
9964
  }
9940
- function prefixIssues(path7, issues) {
9965
+ function prefixIssues(path8, issues) {
9941
9966
  return issues.map((iss) => {
9942
9967
  var _a;
9943
9968
  (_a = iss).path ?? (_a.path = []);
9944
- iss.path.unshift(path7);
9969
+ iss.path.unshift(path8);
9945
9970
  return iss;
9946
9971
  });
9947
9972
  }
@@ -10078,7 +10103,7 @@ function treeifyError(error40, _mapper) {
10078
10103
  return issue2.message;
10079
10104
  };
10080
10105
  const result = { errors: [] };
10081
- const processError = (error41, path7 = []) => {
10106
+ const processError = (error41, path8 = []) => {
10082
10107
  var _a, _b;
10083
10108
  for (const issue2 of error41.issues) {
10084
10109
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -10088,7 +10113,7 @@ function treeifyError(error40, _mapper) {
10088
10113
  } else if (issue2.code === "invalid_element") {
10089
10114
  processError({ issues: issue2.issues }, issue2.path);
10090
10115
  } else {
10091
- const fullpath = [...path7, ...issue2.path];
10116
+ const fullpath = [...path8, ...issue2.path];
10092
10117
  if (fullpath.length === 0) {
10093
10118
  result.errors.push(mapper(issue2));
10094
10119
  continue;
@@ -10118,9 +10143,9 @@ function treeifyError(error40, _mapper) {
10118
10143
  processError(error40);
10119
10144
  return result;
10120
10145
  }
10121
- function toDotPath(path7) {
10146
+ function toDotPath(path8) {
10122
10147
  const segs = [];
10123
- for (const seg of path7) {
10148
+ for (const seg of path8) {
10124
10149
  if (typeof seg === "number")
10125
10150
  segs.push(`[${seg}]`);
10126
10151
  else if (typeof seg === "symbol")
@@ -20338,19 +20363,19 @@ function steeringFiles(worktree) {
20338
20363
  function readAutoMemory(project) {
20339
20364
  const rows = [];
20340
20365
  for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
20341
- const path7 = join7(project.worktree, ...segs);
20342
- if (!isInside(project.worktree, path7)) continue;
20366
+ const path8 = join7(project.worktree, ...segs);
20367
+ if (!isInside(project.worktree, path8)) continue;
20343
20368
  try {
20344
- const st = statSync4(path7);
20369
+ const st = statSync4(path8);
20345
20370
  if (!st.isFile()) continue;
20346
20371
  rows.push({
20347
20372
  origin: "memory",
20348
20373
  ts: Math.trunc(st.mtimeMs),
20349
20374
  seq: null,
20350
20375
  sourceId: null,
20351
- path: path7,
20376
+ path: path8,
20352
20377
  label: segs.join("/"),
20353
- text: readFileSync5(path7, "utf8")
20378
+ text: readFileSync5(path8, "utf8")
20354
20379
  });
20355
20380
  } catch {
20356
20381
  }
@@ -20920,7 +20945,7 @@ var ctxBatch = Object.freeze({
20920
20945
  });
20921
20946
 
20922
20947
  // src/core/tools/doctor.ts
20923
- import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as existsSync14 } from "node:fs";
20948
+ import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
20924
20949
  import { basename as basename5, join as join17 } from "node:path";
20925
20950
 
20926
20951
  // src/core/ops/bundle-dir.ts
@@ -20946,7 +20971,7 @@ function ownBundleDir() {
20946
20971
  }
20947
20972
 
20948
20973
  // src/core/ops/doctor-config.ts
20949
- import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
20974
+ import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
20950
20975
  import { join as join12 } from "node:path";
20951
20976
 
20952
20977
  // src/core/ops/detect-v1.ts
@@ -23065,15 +23090,15 @@ function atomicWriteFile(file2, text, opts = {}) {
23065
23090
  }
23066
23091
 
23067
23092
  // src/core/ops/host-config.ts
23068
- function formatOf(path7) {
23069
- if (path7.endsWith(JSONC_EXT)) return "jsonc";
23070
- if (path7.endsWith(TOML_EXT)) return "toml";
23093
+ function formatOf(path8) {
23094
+ if (path8.endsWith(JSONC_EXT)) return "jsonc";
23095
+ if (path8.endsWith(TOML_EXT)) return "toml";
23071
23096
  return "json";
23072
23097
  }
23073
- function readHostConfig(agent, path7) {
23074
- let file2 = path7;
23098
+ function readHostConfig(agent, path8) {
23099
+ let file2 = path8;
23075
23100
  if (agent === "opencode") {
23076
- const jsonc = join9(dirname6(path7), OPENCODE_CONFIG_FILES[0]);
23101
+ const jsonc = join9(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
23077
23102
  if (existsSync4(jsonc)) file2 = jsonc;
23078
23103
  }
23079
23104
  const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
@@ -23237,14 +23262,14 @@ function scanToml(text) {
23237
23262
  continue;
23238
23263
  }
23239
23264
  if (!node.resolvedKey.every((seg) => typeof seg === "string")) continue;
23240
- const path7 = node.resolvedKey;
23241
- for (const kv of node.body) addKey(path7, kv);
23265
+ const path8 = node.resolvedKey;
23266
+ for (const kv of node.body) addKey(path8, kv);
23242
23267
  if (node.kind !== "standard") continue;
23243
23268
  const start = lineStartOf(text, node.range[0]);
23244
23269
  const headEnd = lineEndOf(text, node.key.range[1]);
23245
23270
  const last2 = node.body[node.body.length - 1];
23246
23271
  tables.push({
23247
- path: path7,
23272
+ path: path8,
23248
23273
  header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
23249
23274
  start,
23250
23275
  end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
@@ -23255,16 +23280,16 @@ function scanToml(text) {
23255
23280
  function tomlTableSpans(text) {
23256
23281
  return scanToml(text).tables;
23257
23282
  }
23258
- function parseHostConfig(agent, path7, text, format) {
23283
+ function parseHostConfig(agent, path8, text, format) {
23259
23284
  try {
23260
23285
  return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
23261
23286
  } catch {
23262
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
23287
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
23263
23288
  }
23264
23289
  }
23265
- function hostConfigValueAt(value, path7) {
23290
+ function hostConfigValueAt(value, path8) {
23266
23291
  let cur = value;
23267
- for (const seg of path7) {
23292
+ for (const seg of path8) {
23268
23293
  if (!isPlainObject3(cur)) return void 0;
23269
23294
  cur = cur[seg];
23270
23295
  }
@@ -23297,32 +23322,32 @@ function indentUnit(root, clean) {
23297
23322
  function render(value, unit, base) {
23298
23323
  return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
23299
23324
  }
23300
- function nest(path7, value) {
23325
+ function nest(path8, value) {
23301
23326
  let out = value;
23302
- for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
23327
+ for (let k = path8.length - 1; k >= 0; k -= 1) out = { [path8[k]]: out };
23303
23328
  return out;
23304
23329
  }
23305
- function setJsonText(text, format, path7, value) {
23330
+ function setJsonText(text, format, path8, value) {
23306
23331
  const doc = scanJson(text, format);
23307
23332
  const unit = indentUnit(doc.root, doc.clean);
23308
- if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
23333
+ if (doc.root === null) return render(nest(path8, value), unit, "") + "\n";
23309
23334
  let node = doc.root;
23310
23335
  let depth = 0;
23311
- while (depth < path7.length && node.kind === "object") {
23312
- const hit = node.members.find((m) => m.key === path7[depth]);
23336
+ while (depth < path8.length && node.kind === "object") {
23337
+ const hit = node.members.find((m) => m.key === path8[depth]);
23313
23338
  if (hit === void 0) break;
23314
23339
  node = hit.node;
23315
23340
  depth += 1;
23316
23341
  }
23317
- if (depth === path7.length) {
23342
+ if (depth === path8.length) {
23318
23343
  return text.slice(0, node.start) + render(value, unit, lineIndent(doc.clean, node.start)) + text.slice(node.end);
23319
23344
  }
23320
- if (node.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
23321
- const rest = nest(path7.slice(depth + 1), value);
23345
+ if (node.kind !== "object") throw new SyntaxError("not an object at " + path8.slice(0, depth).join("."));
23346
+ const rest = nest(path8.slice(depth + 1), value);
23322
23347
  const last2 = node.members[node.members.length - 1];
23323
23348
  if (last2 === void 0) {
23324
23349
  const base2 = lineIndent(doc.clean, node.start);
23325
- const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
23350
+ const member2 = "\n" + base2 + unit + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
23326
23351
  return text.slice(0, node.start + 1) + member2 + text.slice(node.end - 1);
23327
23352
  }
23328
23353
  const base = lineIndent(doc.clean, last2.keyStart);
@@ -23330,7 +23355,7 @@ function setJsonText(text, format, path7, value) {
23330
23355
  while (" \r\n".includes(doc.clean[at2])) at2 += 1;
23331
23356
  const trailing = doc.clean[at2] === ",";
23332
23357
  const insertAt = trailing ? at2 + 1 : last2.node.end;
23333
- const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
23358
+ const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base);
23334
23359
  return text.slice(0, insertAt) + member + text.slice(insertAt);
23335
23360
  }
23336
23361
  function tomlScalar(v) {
@@ -23348,17 +23373,17 @@ function tomlHeaderKey(seg) {
23348
23373
  }
23349
23374
  return seg;
23350
23375
  }
23351
- function tomlBlock(path7, value) {
23352
- let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
23376
+ function tomlBlock(path8, value) {
23377
+ let out = "[" + path8.map(tomlHeaderKey).join(".") + "]\n";
23353
23378
  const subs = [];
23354
23379
  for (const [k, v] of Object.entries(value)) {
23355
- if (isPlainObject3(v)) subs.push(tomlBlock([...path7, k], v));
23380
+ if (isPlainObject3(v)) subs.push(tomlBlock([...path8, k], v));
23356
23381
  else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
23357
23382
  }
23358
23383
  return [out, ...subs].join("\n");
23359
23384
  }
23360
- function under(path7, prefix) {
23361
- return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
23385
+ function under(path8, prefix) {
23386
+ return path8.length >= prefix.length && prefix.every((seg, k) => path8[k] === seg);
23362
23387
  }
23363
23388
  function keyLineRange(text, k) {
23364
23389
  const ls = lineStartOf(text, k.start);
@@ -23375,10 +23400,10 @@ function withValueAt(root, rel, value) {
23375
23400
  else base[rel[0]] = next;
23376
23401
  return base;
23377
23402
  }
23378
- function replaceToml(text, doc, path7, value) {
23379
- const block = value === void 0 ? "" : tomlBlock(path7, value);
23380
- const owned = doc.tables.filter((t) => under(t.path, path7));
23381
- const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
23403
+ function replaceToml(text, doc, path8, value) {
23404
+ const block = value === void 0 ? "" : tomlBlock(path8, value);
23405
+ const owned = doc.tables.filter((t) => under(t.path, path8));
23406
+ const cuts = doc.keys.filter((k) => under(k.full, path8) && !under(k.base, path8)).map((k) => [...keyLineRange(text, k), ""]);
23382
23407
  owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
23383
23408
  cuts.sort((a, b) => b[0] - a[0]);
23384
23409
  let out = text;
@@ -23388,27 +23413,27 @@ function replaceToml(text, doc, path7, value) {
23388
23413
  return out + sep4 + block;
23389
23414
  }
23390
23415
  var tableLike = (v) => v === void 0 || isPlainObject3(v);
23391
- function setTomlText(text, path7, value) {
23416
+ function setTomlText(text, path8, value) {
23392
23417
  if (value !== void 0 && !isPlainObject3(value)) throw new SyntaxError("TOML edits replace a whole table");
23393
23418
  const doc = scanToml(text);
23394
- const cur = hostConfigValueAt(doc.value, path7);
23419
+ const cur = hostConfigValueAt(doc.value, path8);
23395
23420
  if (sameValue(cur, value)) return text;
23396
- const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
23421
+ const inline = doc.keys.find((k) => k.inline && k.full.length < path8.length && under(path8, k.full));
23397
23422
  if (inline !== void 0) {
23398
- const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
23423
+ const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path8.slice(inline.full.length), value);
23399
23424
  return replaceToml(text, doc, inline.full, whole2);
23400
23425
  }
23401
23426
  if (isPlainObject3(cur) && isPlainObject3(value)) {
23402
23427
  const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
23403
23428
  if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
23404
23429
  let out = text;
23405
- for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
23430
+ for (const k of names) out = setTomlText(out, [...path8, k], value[k]);
23406
23431
  return out;
23407
23432
  }
23408
23433
  }
23409
- return replaceToml(text, doc, path7, value);
23434
+ return replaceToml(text, doc, path8, value);
23410
23435
  }
23411
- function setText(agent, path7, text, format, key, value) {
23436
+ function setText(agent, path8, text, format, key, value) {
23412
23437
  try {
23413
23438
  if (format !== "toml") return setJsonText(text, format, key, value);
23414
23439
  const out = setTomlText(text, key, value);
@@ -23417,7 +23442,7 @@ function setText(agent, path7, text, format, key, value) {
23417
23442
  if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
23418
23443
  return out;
23419
23444
  } catch {
23420
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
23445
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
23421
23446
  }
23422
23447
  }
23423
23448
  function serverScript() {
@@ -23464,14 +23489,14 @@ function ownTargets(agent, accept) {
23464
23489
  if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
23465
23490
  return [];
23466
23491
  }
23467
- function applyEdits(agent, path7, text, format, wanted) {
23468
- const parsed = parseHostConfig(agent, path7, text, format);
23492
+ function applyEdits(agent, path8, text, format, wanted) {
23493
+ const parsed = parseHostConfig(agent, path8, text, format);
23469
23494
  let out = text;
23470
23495
  const edits = [];
23471
23496
  for (const [key, after] of wanted) {
23472
23497
  const before = hostConfigValueAt(parsed, key);
23473
23498
  if (sameValue(before, after)) continue;
23474
- out = setText(agent, path7, out, format, key, after);
23499
+ out = setText(agent, path8, out, format, key, after);
23475
23500
  edits.push({ path: key.join("."), before, after });
23476
23501
  }
23477
23502
  return { text: out, format, edits };
@@ -23492,7 +23517,7 @@ function writeHostConfigEdit(_requested, current, patch) {
23492
23517
  // src/core/ops/detect-v1.ts
23493
23518
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23494
23519
  var keyPath = (...parts) => parts.join(".");
23495
- var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
23520
+ var finding = (file2, path8, reason) => ({ file: file2, path: path8, reason });
23496
23521
  function stripJsonc(text) {
23497
23522
  let out = "";
23498
23523
  let inStr = false;
@@ -23697,12 +23722,17 @@ function scanKiro(agentHome, project, out) {
23697
23722
  }
23698
23723
  dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23699
23724
  }
23725
+ function piNpmIsCurrent(piAgentDir) {
23726
+ const doc = readJson(join10(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
23727
+ const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
23728
+ return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
23729
+ }
23700
23730
  function scanPi(piAgentDir, agentHome, out) {
23701
23731
  const file2 = join10(piAgentDir, SETTINGS_FILE);
23702
23732
  const doc = readJson(file2);
23703
23733
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
23704
23734
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
23705
- if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
23735
+ if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
23706
23736
  });
23707
23737
  dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23708
23738
  }
@@ -23799,8 +23829,8 @@ function detectV1(agent, home, scope = {}) {
23799
23829
  import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23800
23830
  import { dirname as dirname7, isAbsolute as isAbsolute2, join as join11, sep as sep3 } from "node:path";
23801
23831
  import { fileURLToPath as fileURLToPath2 } from "node:url";
23802
- function missing(agent, path7) {
23803
- return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
23832
+ function missing(agent, path8) {
23833
+ return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
23804
23834
  }
23805
23835
  var parseOrNull = (text) => {
23806
23836
  try {
@@ -23829,9 +23859,9 @@ function recordedInstalls(text) {
23829
23859
  }
23830
23860
  return out;
23831
23861
  }
23832
- var realOrNull = (path7) => {
23862
+ var realOrNull = (path8) => {
23833
23863
  try {
23834
- return realpathSync4.native(path7);
23864
+ return realpathSync4.native(path8);
23835
23865
  } catch {
23836
23866
  return null;
23837
23867
  }
@@ -23929,12 +23959,81 @@ function candidate(adapter, env, worktree) {
23929
23959
  }
23930
23960
  }
23931
23961
  function resolvePluginRoot(adapter, env, worktree) {
23932
- const path7 = candidate(adapter, env, worktree);
23962
+ const path8 = candidate(adapter, env, worktree);
23963
+ try {
23964
+ return realpathSync4.native(path8);
23965
+ } catch {
23966
+ throw missing(adapter.id, path8);
23967
+ }
23968
+ }
23969
+
23970
+ // src/setup/pi-gate.ts
23971
+ import { existsSync as existsSync7, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
23972
+ import path4 from "node:path";
23973
+ var EXTENSIONS_KEY = "extensions";
23974
+ var PROJECT_DIR = ".pi";
23975
+ var TRUST_FILE = "trust.json";
23976
+ var ALWAYS = "always";
23977
+ var SOURCE_PREFIXES = ["npm:", "git:"];
23978
+ function load(file2) {
23979
+ if (!existsSync7(file2)) return void 0;
23933
23980
  try {
23934
- return realpathSync4.native(path7);
23981
+ return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync9(file2, "utf8")), "json") };
23935
23982
  } catch {
23936
- throw missing(adapter.id, path7);
23983
+ return void 0;
23984
+ }
23985
+ }
23986
+ var real2 = (p) => {
23987
+ try {
23988
+ return realpathSync5(p);
23989
+ } catch {
23990
+ return path4.resolve(p);
23991
+ }
23992
+ };
23993
+ function sourceName(source) {
23994
+ let s = source;
23995
+ for (const p of SOURCE_PREFIXES) if (s.startsWith(p)) s = s.slice(p.length);
23996
+ const last2 = s.split("/").pop() ?? "";
23997
+ const at2 = last2.indexOf("@", 1);
23998
+ const name = at2 > 0 ? last2.slice(0, at2) : last2;
23999
+ return name.endsWith(".git") ? name.slice(0, -4) : name;
24000
+ }
24001
+ function isOwn(source, pkgDir) {
24002
+ if (typeof source !== "string") return false;
24003
+ return real2(source) === real2(pkgDir) || sourceName(source) === SERVER_KEY;
24004
+ }
24005
+ function ownEntries(src, pkgDir) {
24006
+ const list4 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
24007
+ if (!Array.isArray(list4)) return [];
24008
+ const out = [];
24009
+ for (const e of list4) {
24010
+ const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
24011
+ if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
24012
+ const ext = obj?.[EXTENSIONS_KEY];
24013
+ out.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x) => typeof x === "string") : void 0 });
24014
+ }
24015
+ return out;
24016
+ }
24017
+ function projectTrusted(agentDir, userDoc, cwd) {
24018
+ const trust = load(path4.join(agentDir, TRUST_FILE));
24019
+ const entries = /* @__PURE__ */ new Map();
24020
+ if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real2(k), v);
24021
+ let dir = real2(cwd);
24022
+ for (; ; ) {
24023
+ const v = entries.get(dir);
24024
+ if (v === true || v === false) return v;
24025
+ const up = path4.dirname(dir);
24026
+ if (up === dir) break;
24027
+ dir = up;
23937
24028
  }
24029
+ return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
24030
+ }
24031
+ function piInstalledIn(env, home, pkgDir, cwd) {
24032
+ const agentDir = piAgentDirOf(env, home);
24033
+ const user = load(path4.join(agentDir, SETTINGS_FILE));
24034
+ const project = load(path4.join(cwd, PROJECT_DIR, SETTINGS_FILE));
24035
+ if (project && projectTrusted(agentDir, user?.doc, cwd) && ownEntries(project, pkgDir).length > 0) return project.file;
24036
+ return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
23938
24037
  }
23939
24038
 
23940
24039
  // src/core/ops/doctor-config.ts
@@ -24037,14 +24136,14 @@ function codexNativeDir(env, home) {
24037
24136
  }
24038
24137
  if (enabled !== true) return null;
24039
24138
  const cache = join12(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
24040
- if (!existsSync7(cache)) return null;
24139
+ if (!existsSync8(cache)) return null;
24041
24140
  const found = [];
24042
24141
  for (const market of readdirSync4(cache)) {
24043
24142
  const plugin = join12(cache, market, SERVER_KEY);
24044
- if (!existsSync7(plugin)) continue;
24143
+ if (!existsSync8(plugin)) continue;
24045
24144
  for (const version2 of readdirSync4(plugin).sort()) {
24046
24145
  const dir = join12(plugin, version2, CODEX_PLUGIN_SUBDIR);
24047
- if (existsSync7(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24146
+ if (existsSync8(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24048
24147
  }
24049
24148
  }
24050
24149
  return found.length === 0 ? null : found[found.length - 1];
@@ -24135,12 +24234,17 @@ function checkHostConfig(row5, env, worktree) {
24135
24234
  const choice = marketplaceChoice(env, worktree);
24136
24235
  if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
24137
24236
  }
24237
+ if (row5.id === "pi") return checkPiInstall(env, home, worktree);
24138
24238
  const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
24139
- const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
24140
- if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
24239
+ if (parts.length === 0) return pass("D3");
24141
24240
  const detail = D3_DETAIL(parts);
24142
24241
  const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
24143
- return fail2("D3", read3 === null ? detail : detail + D4_REASON_JOIN + read3, fix);
24242
+ return fail2("D3", detail, fix);
24243
+ }
24244
+ function checkPiInstall(env, home, worktree) {
24245
+ const found = piInstalledIn(env, home, ownBundleDir(), worktree);
24246
+ if (found !== void 0) return { ...pass("D3"), detail: found };
24247
+ return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join12(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
24144
24248
  }
24145
24249
  function checkV1Leftovers(agent, home, scope = {}) {
24146
24250
  const findings = detectV1(agent, home, scope);
@@ -24193,7 +24297,7 @@ function configPaths(row5, env, worktree) {
24193
24297
  }
24194
24298
 
24195
24299
  // src/core/ops/doctor-db.ts
24196
- import { existsSync as existsSync8, statSync as statSync5 } from "node:fs";
24300
+ import { existsSync as existsSync9, statSync as statSync5 } from "node:fs";
24197
24301
  var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
24198
24302
  var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
24199
24303
  var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -24212,8 +24316,8 @@ async function loadSqlite2() {
24212
24316
  return null;
24213
24317
  }
24214
24318
  }
24215
- function openRead(sqlite, path7) {
24216
- return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
24319
+ function openRead(sqlite, path8) {
24320
+ return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
24217
24321
  }
24218
24322
  var cell = (row5) => Object.values(row5)[0];
24219
24323
  function readSchema(raw) {
@@ -24234,16 +24338,16 @@ function failsOnCorrupt(step) {
24234
24338
  function orphanFiles(dbPath) {
24235
24339
  const files = [];
24236
24340
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
24237
- const path7 = dbPath + suffix;
24238
- if (existsSync8(path7)) files.push({ path: path7, bytes: statSync5(path7).size });
24341
+ const path8 = dbPath + suffix;
24342
+ if (existsSync9(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
24239
24343
  }
24240
- return files.length > 0 && !existsSync8(dbPath) ? files : [];
24344
+ return files.length > 0 && !existsSync9(dbPath) ? files : [];
24241
24345
  }
24242
24346
  async function checkDb(project) {
24243
24347
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
24244
24348
  const orphan = orphanFiles(project.dbPath);
24245
24349
  if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
24246
- if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24350
+ if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24247
24351
  const sqlite = await loadSqlite2();
24248
24352
  if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
24249
24353
  let raw = null;
@@ -24269,7 +24373,7 @@ async function checkDb(project) {
24269
24373
  }
24270
24374
  }
24271
24375
  async function checkIndex(project) {
24272
- if (!existsSync8(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24376
+ if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24273
24377
  const sqlite = await loadSqlite2();
24274
24378
  if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
24275
24379
  let raw = null;
@@ -24286,7 +24390,7 @@ async function checkIndex(project) {
24286
24390
  }
24287
24391
 
24288
24392
  // src/core/ops/doctor-env.ts
24289
- import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
24393
+ import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
24290
24394
  import { isAbsolute as isAbsolute3, join as join13, relative as relative2 } from "node:path";
24291
24395
  function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
24292
24396
  return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
@@ -24299,7 +24403,7 @@ function fail4(id2, detail, fixCommand) {
24299
24403
  }
24300
24404
  function bundleVersion(bundleDir2) {
24301
24405
  try {
24302
- const v = JSON.parse(readFileSync9(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24406
+ const v = JSON.parse(readFileSync10(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24303
24407
  return typeof v === "string" && v !== "" ? v : void 0;
24304
24408
  } catch {
24305
24409
  return void 0;
@@ -24449,8 +24553,8 @@ function checkMcp(ctx) {
24449
24553
  return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
24450
24554
  }
24451
24555
  function piCwdInside(worktree, piCwd) {
24452
- if (piCwd === void 0 || !existsSync9(piCwd)) return false;
24453
- const rel = relative2(worktree, realpathSync5.native(piCwd));
24556
+ if (piCwd === void 0 || !existsSync10(piCwd)) return false;
24557
+ const rel = relative2(worktree, realpathSync6.native(piCwd));
24454
24558
  return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
24455
24559
  }
24456
24560
  function checkProject(i) {
@@ -24470,20 +24574,20 @@ function checkShell(env) {
24470
24574
  }
24471
24575
 
24472
24576
  // src/core/ops/doctor-hook.ts
24473
- import { existsSync as existsSync11, mkdtempSync, readFileSync as readFileSync10, realpathSync as realpathSync7, rmSync as rmSync2 } from "node:fs";
24577
+ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2 } from "node:fs";
24474
24578
  import { tmpdir as tmpdir2 } from "node:os";
24475
- import path6 from "node:path";
24579
+ import path7 from "node:path";
24476
24580
 
24477
24581
  // src/setup/codex-trust.ts
24478
24582
  import { createHash } from "node:crypto";
24479
- import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
24480
- import path5 from "node:path";
24583
+ import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
24584
+ import path6 from "node:path";
24481
24585
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
24482
24586
 
24483
24587
  // src/setup/spawn-bin.ts
24484
24588
  import { spawnSync } from "node:child_process";
24485
24589
  import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
24486
- import path4 from "node:path";
24590
+ import path5 from "node:path";
24487
24591
  var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
24488
24592
  var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
24489
24593
  var DEFAULT_COMSPEC = "cmd.exe";
@@ -24494,10 +24598,10 @@ function whichBin(bin, env, platform = process.platform) {
24494
24598
  const get = (k) => envGet(env, k);
24495
24599
  const win = platform === "win32";
24496
24600
  const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
24497
- const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
24601
+ const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
24498
24602
  for (const dir of pathEntries(get("PATH") ?? "", platform)) {
24499
24603
  for (const n of names) {
24500
- const f = path4.join(dir, n);
24604
+ const f = path5.join(dir, n);
24501
24605
  try {
24502
24606
  accessSync2(f, fsc.X_OK);
24503
24607
  if (statSync6(f).isFile()) return f;
@@ -24538,7 +24642,7 @@ function winCmdLine(file2, args, env = {}) {
24538
24642
  return `"${[file2, ...args].map(q).join(" ")}"`;
24539
24643
  }
24540
24644
  function spawnForm(file2, args, env, platform = process.platform) {
24541
- if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
24645
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
24542
24646
  return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
24543
24647
  }
24544
24648
  return { command: file2, args, windowsVerbatimArguments: false };
@@ -24562,10 +24666,10 @@ function codexHomeFromReply(out) {
24562
24666
  return void 0;
24563
24667
  }
24564
24668
  function sameDir(a, b, platform = process.platform) {
24565
- if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
24669
+ if (platform !== "win32") return path6.posix.normalize(a) === path6.posix.normalize(b);
24566
24670
  const norm2 = (p) => {
24567
24671
  const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
24568
- const n = path5.win32.normalize(bare2).toLowerCase();
24672
+ const n = path6.win32.normalize(bare2).toLowerCase();
24569
24673
  return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
24570
24674
  };
24571
24675
  return norm2(a) === norm2(b);
@@ -24698,11 +24802,11 @@ function isObject5(v) {
24698
24802
  return typeof v === "object" && v !== null && !Array.isArray(v);
24699
24803
  }
24700
24804
  function loadFixture(bundleDir2, agent) {
24701
- const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
24702
- if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24805
+ const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
24806
+ if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24703
24807
  let all;
24704
24808
  try {
24705
- all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
24809
+ all = JSON.parse(hostText(readFileSync11(file2, "utf8")));
24706
24810
  } catch (err) {
24707
24811
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
24708
24812
  }
@@ -24762,9 +24866,9 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
24762
24866
  }
24763
24867
  }
24764
24868
  var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
24765
- function readProbePayload(cwd) {
24869
+ function readProbePayload(cwd, ranged) {
24766
24870
  const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
24767
- const filePath = path6.join(cwd, "d5-read-probe.txt");
24871
+ const filePath = path7.join(cwd, "d5-read-probe.txt");
24768
24872
  return {
24769
24873
  session_id: "d5-read-probe",
24770
24874
  transcript_path: "",
@@ -24772,7 +24876,7 @@ function readProbePayload(cwd) {
24772
24876
  hook_event_name: "PostToolUse",
24773
24877
  tool_name: "Read",
24774
24878
  tool_use_id: "toolu_d5_read_probe",
24775
- tool_input: { file_path: filePath },
24879
+ tool_input: ranged ? { file_path: filePath, offset: 1, limit: READ_PROBE_LINES } : { file_path: filePath },
24776
24880
  tool_response: { type: "text", file: { filePath, content, numLines: READ_PROBE_LINES, startLine: 1, totalLines: READ_PROBE_LINES } }
24777
24881
  };
24778
24882
  }
@@ -24790,28 +24894,43 @@ function isReadShape(stdout) {
24790
24894
  const f = r.file;
24791
24895
  return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
24792
24896
  }
24793
- async function readProbeOk(i, timeoutMs) {
24794
- const home = mkdtempSync(path6.join(tmpdir2(), "cm-d5-read-"));
24897
+ async function readProbe(i, timeoutMs, ranged) {
24898
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
24795
24899
  try {
24796
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24900
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24797
24901
  cwd: i.bundleDir,
24798
24902
  env: { ...i.env, HOME: home, USERPROFILE: home },
24799
24903
  signal: i.signal,
24800
24904
  timeoutMs,
24801
- stdin: JSON.stringify(readProbePayload(i.worktree ?? home))
24905
+ stdin: JSON.stringify(readProbePayload(i.worktree ?? home, ranged))
24802
24906
  });
24803
- return isReadShape(r.stdout.toString("utf8"));
24907
+ return r.stdout.toString("utf8");
24804
24908
  } finally {
24805
24909
  rmSync2(home, { recursive: true, force: true });
24806
24910
  }
24807
24911
  }
24912
+ function isPassThrough(stdout) {
24913
+ if (stdout.trim() === "") return true;
24914
+ let out;
24915
+ try {
24916
+ out = JSON.parse(stdout);
24917
+ } catch {
24918
+ return false;
24919
+ }
24920
+ return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
24921
+ }
24922
+ async function readProbeDetail(i, timeoutMs) {
24923
+ if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
24924
+ if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
24925
+ return null;
24926
+ }
24808
24927
  function codexHookJournaled(db) {
24809
24928
  if (db === null) return false;
24810
24929
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
24811
24930
  }
24812
24931
  function realDir(p) {
24813
24932
  try {
24814
- return realpathSync7(p);
24933
+ return realpathSync8(p);
24815
24934
  } catch {
24816
24935
  return p;
24817
24936
  }
@@ -24838,7 +24957,7 @@ async function checkHookRoundTrip(i) {
24838
24957
  const trust = await codexPluginTrust(i);
24839
24958
  if (trust !== null) return trust;
24840
24959
  }
24841
- if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24960
+ if (i.agent === "codex" && existsSync12(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24842
24961
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
24843
24962
  }
24844
24963
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -24858,7 +24977,7 @@ async function checkHookRoundTrip(i) {
24858
24977
  let ms = 0;
24859
24978
  for (let n = 1; n <= maxPairs; n++) {
24860
24979
  const start = now();
24861
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24980
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24862
24981
  cwd: i.bundleDir,
24863
24982
  env: i.env,
24864
24983
  signal: i.signal,
@@ -24872,16 +24991,17 @@ async function checkHookRoundTrip(i) {
24872
24991
  if (n >= minPairs && ms <= HOOK_P95_MS) break;
24873
24992
  }
24874
24993
  if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
24875
- if (i.agent === "claude-code" && !await readProbeOk(i, timeoutMs)) return row("FAIL", D5_READ_SHAPE_DETAIL, D5_FIX);
24994
+ const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
24995
+ if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
24876
24996
  return row("PASS", DOCTOR_PASS_DETAIL);
24877
24997
  }
24878
24998
 
24879
24999
  // src/core/ops/db-heal.ts
24880
- import { existsSync as existsSync12, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
25000
+ import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
24881
25001
  import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
24882
25002
 
24883
25003
  // src/core/store/owners.ts
24884
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync11, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
25004
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
24885
25005
  import { basename as basename3, join as join14 } from "node:path";
24886
25006
  function ownersDir(configDir, projectKey) {
24887
25007
  return join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
@@ -24915,7 +25035,7 @@ function listLiveOwners(configDir, projectKey) {
24915
25035
  const file2 = join14(dir, name);
24916
25036
  let text;
24917
25037
  try {
24918
- text = readFileSync11(file2, "utf8");
25038
+ text = readFileSync12(file2, "utf8");
24919
25039
  } catch (err) {
24920
25040
  if (errCode2(err) === "ENOENT") continue;
24921
25041
  throw err;
@@ -24961,7 +25081,7 @@ function renameAside(dbPath) {
24961
25081
  const ts = String(Date.now());
24962
25082
  for (const suffix of DB_SIBLING_SUFFIXES) {
24963
25083
  const file2 = dbPath + suffix;
24964
- if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
25084
+ if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
24965
25085
  }
24966
25086
  return ts;
24967
25087
  }
@@ -25068,7 +25188,7 @@ function buildReportHead(input) {
25068
25188
 
25069
25189
  // src/core/ops/doctor-issue.ts
25070
25190
  import { spawnSync as spawnSync3 } from "node:child_process";
25071
- import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
25191
+ import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
25072
25192
  import { delimiter, join as join16 } from "node:path";
25073
25193
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
25074
25194
  function tildeOf(env) {
@@ -25076,8 +25196,8 @@ function tildeOf(env) {
25076
25196
  if (home === null || home === "") return (t) => t;
25077
25197
  const homes = [home];
25078
25198
  try {
25079
- const real2 = realpathSync8.native(home);
25080
- if (real2 !== home) homes.push(real2);
25199
+ const real3 = realpathSync9.native(home);
25200
+ if (real3 !== home) homes.push(real3);
25081
25201
  } catch {
25082
25202
  }
25083
25203
  homes.sort((a, b) => b.length - a.length);
@@ -25110,7 +25230,7 @@ function onPath(env, tool) {
25110
25230
  const out = [];
25111
25231
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
25112
25232
  if (dir === "") continue;
25113
- for (const n of names) if (existsSync13(join16(dir, n))) {
25233
+ for (const n of names) if (existsSync14(join16(dir, n))) {
25114
25234
  out.push(join16(dir, n));
25115
25235
  break;
25116
25236
  }
@@ -25119,7 +25239,7 @@ function onPath(env, tool) {
25119
25239
  }
25120
25240
  function hookLogTail(env) {
25121
25241
  const file2 = hookLogPath(env);
25122
- if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25242
+ if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25123
25243
  try {
25124
25244
  const fd = openSync(file2, "r");
25125
25245
  try {
@@ -25139,7 +25259,7 @@ function hookLogTail(env) {
25139
25259
  }
25140
25260
  async function journalRows(ctx) {
25141
25261
  const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
25142
- if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25262
+ if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25143
25263
  try {
25144
25264
  const db = await openDb(ctx.project, { readOnly: true });
25145
25265
  try {
@@ -25165,13 +25285,13 @@ function agentConfig(adapter, env, worktree) {
25165
25285
  for (const f of files) {
25166
25286
  if (seen.has(f.path)) continue;
25167
25287
  seen.add(f.path);
25168
- if (!existsSync13(f.path)) {
25288
+ if (!existsSync14(f.path)) {
25169
25289
  out.push(`${f.label}: ${f.path} (absent)`);
25170
25290
  continue;
25171
25291
  }
25172
25292
  let text = "";
25173
25293
  try {
25174
- text = readFileSync12(f.path, "utf8");
25294
+ text = readFileSync13(f.path, "utf8");
25175
25295
  } catch (err) {
25176
25296
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
25177
25297
  continue;
@@ -25270,7 +25390,7 @@ async function guard(id2, run) {
25270
25390
  }
25271
25391
  }
25272
25392
  async function codexDb(ctx, adapter) {
25273
- if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
25393
+ if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
25274
25394
  try {
25275
25395
  return await openDb(ctx.project, { readOnly: true });
25276
25396
  } catch {
@@ -25301,10 +25421,10 @@ async function hookRow(ctx, adapter, host) {
25301
25421
  }
25302
25422
  function ownServerId(configDir, projectKey) {
25303
25423
  const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
25304
- if (!existsSync14(dir)) return "";
25424
+ if (!existsSync15(dir)) return "";
25305
25425
  for (const name of readdirSync6(dir)) {
25306
25426
  if (!name.endsWith(OWNER_PID_EXT)) continue;
25307
- if (readFileSync13(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25427
+ if (readFileSync14(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25308
25428
  }
25309
25429
  return "";
25310
25430
  }
@@ -25360,7 +25480,7 @@ async function doctorReply(ctx, host) {
25360
25480
  const adapter = getAdapter(ctx.project.agent);
25361
25481
  const rows = await runDoctorChecks(ctx, adapter, host);
25362
25482
  const failed2 = rows.some((r) => r.status === "FAIL");
25363
- const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
25483
+ const command = adapter.id === "pi" ? failed2 ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
25364
25484
  const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
25365
25485
  const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
25366
25486
  const table3 = buildReport(input);
@@ -25387,7 +25507,7 @@ async function doctorReply(ctx, host) {
25387
25507
  return { text, isError: false, sandboxBytes: bytes5 };
25388
25508
  }
25389
25509
  async function handler2(_input, ctx) {
25390
- return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: void 0 });
25510
+ return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
25391
25511
  }
25392
25512
  var ctxDoctor = Object.freeze({
25393
25513
  name: "ctx_doctor",
@@ -25399,7 +25519,7 @@ var ctxDoctor = Object.freeze({
25399
25519
  });
25400
25520
 
25401
25521
  // src/core/tools/execute.ts
25402
- import { existsSync as existsSync15, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
25522
+ import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
25403
25523
  import { tmpdir as tmpdir3 } from "node:os";
25404
25524
  import { dirname as dirname10, join as join18, parse as parse3, resolve as resolve6 } from "node:path";
25405
25525
 
@@ -25485,7 +25605,7 @@ function schemaLine(issue2) {
25485
25605
  }
25486
25606
  function fileError(given, abs, root) {
25487
25607
  let dir = abs;
25488
- while (!existsSync15(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
25608
+ while (!existsSync16(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
25489
25609
  if (isInside(root, dir)) return null;
25490
25610
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
25491
25611
  }
@@ -25602,19 +25722,19 @@ var ctxExecute = {
25602
25722
  };
25603
25723
 
25604
25724
  // src/core/tools/index.ts
25605
- import { existsSync as existsSync16, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
25725
+ import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
25606
25726
  import { dirname as dirname11, extname, join as join20, relative as relative3, resolve as resolve7 } from "node:path";
25607
25727
 
25608
25728
  // src/core/index/walk.ts
25609
- import { readdirSync as readdirSync7, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
25729
+ import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
25610
25730
  import { join as join19 } from "node:path";
25611
25731
  var GITIGNORE = ".gitignore";
25612
25732
  var GIT_DIR = ".git";
25613
25733
  function walkDir(root, containmentRoot) {
25614
- const real2 = realpathSync9(root);
25615
- if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
25734
+ const real3 = realpathSync10(root);
25735
+ if (!isInside(containmentRoot, real3)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
25616
25736
  const found = [];
25617
- visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
25737
+ visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
25618
25738
  found.sort(compareFound);
25619
25739
  return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
25620
25740
  }
@@ -25628,14 +25748,14 @@ function visit(abs, rel, parent, contain, seen, found) {
25628
25748
  const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
25629
25749
  for (const e of entries) {
25630
25750
  if (e.name === GIT_DIR) continue;
25631
- const path7 = join19(abs, e.name);
25751
+ const path8 = join19(abs, e.name);
25632
25752
  let isDir = e.isDirectory();
25633
25753
  let isFile = e.isFile();
25634
- let target = path7;
25754
+ let target = path8;
25635
25755
  if (e.isSymbolicLink()) {
25636
25756
  let resolved;
25637
25757
  try {
25638
- resolved = realpathSync9(path7);
25758
+ resolved = realpathSync10(path8);
25639
25759
  } catch {
25640
25760
  continue;
25641
25761
  }
@@ -25648,12 +25768,12 @@ function visit(abs, rel, parent, contain, seen, found) {
25648
25768
  const segs = rel.concat(e.name);
25649
25769
  if (ignored(rules, segs, isDir)) continue;
25650
25770
  if (isFile) {
25651
- found.push({ dir: rel, name: e.name, absPath: path7 });
25771
+ found.push({ dir: rel, name: e.name, absPath: path8 });
25652
25772
  } else if (isDir) {
25653
- const key = e.isSymbolicLink() ? target : realpathSync9(path7);
25773
+ const key = e.isSymbolicLink() ? target : realpathSync10(path8);
25654
25774
  if (seen.has(key)) continue;
25655
25775
  seen.add(key);
25656
- visit(path7, segs, rules, contain, seen, found);
25776
+ visit(path8, segs, rules, contain, seen, found);
25657
25777
  }
25658
25778
  }
25659
25779
  }
@@ -25668,7 +25788,7 @@ function compareFound(a, b) {
25668
25788
  function readRules(file2, base) {
25669
25789
  let body;
25670
25790
  try {
25671
- body = readFileSync14(file2, "utf8");
25791
+ body = readFileSync15(file2, "utf8");
25672
25792
  } catch {
25673
25793
  return [];
25674
25794
  }
@@ -25844,12 +25964,12 @@ function tlsName(host) {
25844
25964
  function request(u, conn, proxy, signal) {
25845
25965
  const host = bare(u.hostname);
25846
25966
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
25847
- const path7 = u.pathname + u.search;
25967
+ const path8 = u.pathname + u.search;
25848
25968
  return new Promise((resolve8, reject) => {
25849
25969
  const onErr = (err) => reject(fail6(causeCode(err)));
25850
25970
  if (proxy === void 0) {
25851
25971
  const mod = u.protocol === "https:" ? https : http;
25852
- const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
25972
+ const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
25853
25973
  req.on("response", resolve8).on("error", onErr).end();
25854
25974
  return;
25855
25975
  }
@@ -25871,7 +25991,7 @@ function request(u, conn, proxy, signal) {
25871
25991
  const req = https.request({
25872
25992
  host,
25873
25993
  port,
25874
- path: path7,
25994
+ path: path8,
25875
25995
  signal,
25876
25996
  headers: { host: u.host },
25877
25997
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
@@ -29751,14 +29871,14 @@ function kindOfType(contentType) {
29751
29871
  }
29752
29872
  function readUtf8(absPath) {
29753
29873
  try {
29754
- return utf8.decode(readFileSync15(absPath));
29874
+ return utf8.decode(readFileSync16(absPath));
29755
29875
  } catch {
29756
29876
  return void 0;
29757
29877
  }
29758
29878
  }
29759
29879
  function missingOrOutside(given, abs, root) {
29760
29880
  let dir = abs;
29761
- while (!existsSync16(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
29881
+ while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
29762
29882
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
29763
29883
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
29764
29884
  }
@@ -30309,11 +30429,11 @@ var ctxStats = Object.freeze({
30309
30429
  });
30310
30430
 
30311
30431
  // src/core/tools/upgrade.ts
30312
- import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
30432
+ import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
30313
30433
  import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
30314
30434
 
30315
30435
  // src/core/ops/host-write.ts
30316
- import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30436
+ import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30317
30437
  import { dirname as dirname12, join as join21 } from "node:path";
30318
30438
  function defaultWrite(file2, text) {
30319
30439
  writeFileSync5(file2, text, "utf8");
@@ -30342,7 +30462,7 @@ function toRow(file2, edit) {
30342
30462
  function writeWithRollback(file2, text, write2, atomic) {
30343
30463
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
30344
30464
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
30345
- const had = existsSync17(file2);
30465
+ const had = existsSync18(file2);
30346
30466
  mkdirSync7(dirname12(file2), { recursive: true });
30347
30467
  if (had) copyFileSync(file2, trash);
30348
30468
  try {
@@ -30372,7 +30492,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
30372
30492
  if (requested === null) return [];
30373
30493
  const current = readHostConfig(row5.id, requested);
30374
30494
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
30375
- const exists = existsSync17(current.path);
30495
+ const exists = existsSync18(current.path);
30376
30496
  if (exists && result.text === current.text) return [];
30377
30497
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
30378
30498
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -30380,15 +30500,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
30380
30500
  }
30381
30501
 
30382
30502
  // src/core/ops/plugin-swap.ts
30383
- import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30503
+ import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30384
30504
  import { basename as basename6, join as join22, win32 as win322 } from "node:path";
30385
- function linkTarget(path7, win) {
30386
- if (!isLink(path7)) return null;
30387
- const target = readlinkSync(path7);
30505
+ function linkTarget(path8, win) {
30506
+ if (!isLink(path8)) return null;
30507
+ const target = readlinkSync(path8);
30388
30508
  return win ? win322.basename(target) : target;
30389
30509
  }
30390
- function isLink(path7) {
30391
- return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
30510
+ function isLink(path8) {
30511
+ return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
30392
30512
  }
30393
30513
  function generations(agentDir) {
30394
30514
  return readdirSync8(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
@@ -30401,7 +30521,7 @@ function settleLinks(link, tmp, old, opts) {
30401
30521
  }
30402
30522
  function swapPluginCurrent(agentDir, sha, opts = {}) {
30403
30523
  const next = join22(agentDir, sha);
30404
- if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
30524
+ if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
30405
30525
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
30406
30526
  }
30407
30527
  const link = join22(agentDir, PLUGIN_CURRENT_LINK);
@@ -30421,12 +30541,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
30421
30541
  if (before !== null) keep.add(before);
30422
30542
  const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
30423
30543
  for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
30424
- const previous = before !== null && existsSync18(join22(agentDir, before)) ? join22(agentDir, before) : null;
30544
+ const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
30425
30545
  return { current: next, previous, removed };
30426
30546
  }
30427
30547
 
30428
30548
  // src/core/ops/release-fetch.ts
30429
- import { existsSync as existsSync19, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
30549
+ import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
30430
30550
  import { join as join23 } from "node:path";
30431
30551
  function failed(r) {
30432
30552
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -30450,7 +30570,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
30450
30570
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
30451
30571
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
30452
30572
  const dir = join23(agentDir, sha);
30453
- if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
30573
+ if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
30454
30574
  else renameWithRetry(fetchDir, dir, opts);
30455
30575
  return { sha, dir };
30456
30576
  } catch (e) {
@@ -30460,7 +30580,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
30460
30580
  }
30461
30581
 
30462
30582
  // src/core/ops/uninstall.ts
30463
- import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
30583
+ import { existsSync as existsSync21, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
30464
30584
  import { join as join24 } from "node:path";
30465
30585
  function row2(area, before, after) {
30466
30586
  return { area, before, after };
@@ -30494,7 +30614,7 @@ function removeCache(adapter, env, configDir) {
30494
30614
  }
30495
30615
  case "plugin": {
30496
30616
  const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
30497
- if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30617
+ if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30498
30618
  rmSync8(agentDir, { recursive: true, force: true });
30499
30619
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
30500
30620
  }
@@ -30513,7 +30633,7 @@ function isObj3(v) {
30513
30633
  function piSource(entry) {
30514
30634
  return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
30515
30635
  }
30516
- function ownEntries(agent, env) {
30636
+ function ownEntries2(agent, env) {
30517
30637
  const home = requireHomeDir(env);
30518
30638
  const mcp = OWN_MCP_ENTRY[agent];
30519
30639
  if (mcp !== void 0) {
@@ -30521,10 +30641,10 @@ function ownEntries(agent, env) {
30521
30641
  const inner = mcp.key.slice(1, -1);
30522
30642
  const own2 = mcp.key[mcp.key.length - 1];
30523
30643
  const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
30524
- const without = (v, path7) => {
30644
+ const without = (v, path8) => {
30525
30645
  const o = v;
30526
- if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own2));
30527
- return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
30646
+ if (path8.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own2));
30647
+ return { ...o, [path8[0]]: without(o[path8[0]], path8.slice(1)) };
30528
30648
  };
30529
30649
  return [{
30530
30650
  file: ownMcpFileOf(agent, mcp.file, env, home),
@@ -30561,7 +30681,7 @@ function ownEntries(agent, env) {
30561
30681
  }
30562
30682
  function removeOwnEntries(agent, env) {
30563
30683
  const rows = [];
30564
- for (const entry of ownEntries(agent, env)) {
30684
+ for (const entry of ownEntries2(agent, env)) {
30565
30685
  const current = readHostConfig(agent, entry.file);
30566
30686
  if (current.text === "") continue;
30567
30687
  const value = hostConfigValueAt(parseHostConfig(agent, current.path, current.text, current.format), [entry.key]);
@@ -30574,7 +30694,7 @@ function removeOwnEntries(agent, env) {
30574
30694
  function removeProjectData(configDir, projectKey) {
30575
30695
  const projects = join24(configDir, PROJECTS_DIR_NAME);
30576
30696
  const dir = join24(projects, projectKey);
30577
- if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30697
+ if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30578
30698
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
30579
30699
  for (const name of readdirSync9(dir)) {
30580
30700
  if (name !== OWNERS_DIR_NAME) rmSync8(join24(dir, name), { recursive: true, force: true });
@@ -30590,7 +30710,7 @@ function runUninstall(input) {
30590
30710
  }
30591
30711
 
30592
30712
  // src/core/ops/v1-remove.ts
30593
- import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync16, rmSync as rmSync9 } from "node:fs";
30713
+ import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync17, rmSync as rmSync9 } from "node:fs";
30594
30714
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
30595
30715
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
30596
30716
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -30620,8 +30740,8 @@ function cutTomlTable(text, header) {
30620
30740
  function writeAtomic(file2, text) {
30621
30741
  atomicWriteFile(file2, text);
30622
30742
  }
30623
- function locate(doc, path7) {
30624
- const segs = path7.split(V1_KEY_PATH_SEP);
30743
+ function locate(doc, path8) {
30744
+ const segs = path8.split(V1_KEY_PATH_SEP);
30625
30745
  let cur = doc;
30626
30746
  for (const seg of segs.slice(0, -1)) {
30627
30747
  if (Array.isArray(cur)) cur = cur[Number(seg)];
@@ -30634,8 +30754,8 @@ function locate(doc, path7) {
30634
30754
  return null;
30635
30755
  }
30636
30756
  function stripJsonEntries(agent, file2, findings, kept, undo) {
30637
- const layout = hostLayout(readFileSync16(file2, "utf8"));
30638
- const text = hostText(readFileSync16(file2, "utf8"));
30757
+ const layout = hostLayout(readFileSync17(file2, "utf8"));
30758
+ const text = hostText(readFileSync17(file2, "utf8"));
30639
30759
  const doc = parseHostConfig(agent, file2, text, "jsonc");
30640
30760
  const hit = /* @__PURE__ */ new Set();
30641
30761
  const byContainer = /* @__PURE__ */ new Map();
@@ -30671,19 +30791,19 @@ function removeV1(agent, findings) {
30671
30791
  for (const f of findings) {
30672
30792
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
30673
30793
  else if (f.path === "") {
30674
- if (existsSync21(f.file)) {
30794
+ if (existsSync22(f.file)) {
30675
30795
  moveAside(f.file, undo);
30676
30796
  done.set(f, UPGRADE_REMOVED);
30677
30797
  } else done.set(f, UPGRADE_NOT_FOUND);
30678
30798
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
30679
30799
  }
30680
30800
  for (const [file2, list4] of entries) {
30681
- if (!existsSync21(file2)) {
30801
+ if (!existsSync22(file2)) {
30682
30802
  for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
30683
30803
  continue;
30684
30804
  }
30685
30805
  if (file2.endsWith(TOML_EXT)) {
30686
- const rawToml = readFileSync16(file2, "utf8");
30806
+ const rawToml = readFileSync17(file2, "utf8");
30687
30807
  const tomlLayout = hostLayout(rawToml);
30688
30808
  let text = hostText(rawToml);
30689
30809
  for (const f of list4) {
@@ -30711,7 +30831,7 @@ function removeV1(agent, findings) {
30711
30831
  },
30712
30832
  rollback() {
30713
30833
  for (const u of undo.splice(0).reverse()) {
30714
- if (!existsSync21(u.trash)) continue;
30834
+ if (!existsSync22(u.trash)) continue;
30715
30835
  rmSync9(u.target, { recursive: true, force: true });
30716
30836
  renameWithRetry(u.trash, u.target);
30717
30837
  }
@@ -30721,7 +30841,7 @@ function removeV1(agent, findings) {
30721
30841
 
30722
30842
  // src/core/ops/verify-sums.ts
30723
30843
  import { createHash as createHash2 } from "node:crypto";
30724
- import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync17 } from "node:fs";
30844
+ import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
30725
30845
  import { join as join25 } from "node:path";
30726
30846
  function mismatch() {
30727
30847
  return new CtxError("BUNDLE_HASH_MISMATCH");
@@ -30753,14 +30873,14 @@ function verifySums(dir) {
30753
30873
  const sumsPath = join25(dir, RELEASE_SUMS_FILE);
30754
30874
  const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
30755
30875
  if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
30756
- const sums = parseSums(readFileSync17(sumsPath, "utf8"));
30876
+ const sums = parseSums(readFileSync18(sumsPath, "utf8"));
30757
30877
  const files = /* @__PURE__ */ new Map();
30758
30878
  walk3(dir, "", files);
30759
30879
  if (files.size !== sums.size) throw mismatch();
30760
30880
  for (const [rel, abs] of files) {
30761
30881
  const want = sums.get(rel);
30762
30882
  if (want === void 0) throw mismatch();
30763
- const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync17(abs)).digest(HASH_ENCODING);
30883
+ const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
30764
30884
  if (got !== want) throw mismatch();
30765
30885
  }
30766
30886
  }
@@ -30789,7 +30909,7 @@ function pluginRootRow(adapter, env) {
30789
30909
  }
30790
30910
  function isCurrent(agentDir, dir) {
30791
30911
  const link = join26(agentDir, PLUGIN_CURRENT_LINK);
30792
- return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
30912
+ return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
30793
30913
  }
30794
30914
  async function checkout(adapter, deps) {
30795
30915
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);