context-mode 2.1.0 → 2.1.2

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.
@@ -426,7 +426,7 @@ var DECISION_OPTION_KEY = "option";
426
426
  var DECISION_LABEL_JOIN = " | ";
427
427
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
428
428
  var RELEASE_BRANCH = "release";
429
- var BUNDLE_SHA = true ? "d232ce4ddfb581a63a4c0d6ef894b64a0f8464f6" : void 0;
429
+ var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
430
430
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
431
431
  var DOCTOR_LABEL = Object.freeze({
432
432
  D1: "version",
@@ -743,6 +743,11 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
743
743
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
744
744
  var V1_STATUSLINE_COMMAND = "context-mode statusline";
745
745
  var V1_PI_PACKAGE = "npm:context-mode";
746
+ var PI_NPM_DIR = "npm";
747
+ var PI_NODE_MODULES_DIR = "node_modules";
748
+ var PI_PACKAGE_JSON_FILE = "package.json";
749
+ var PI_LIST_COMMAND = "pi list";
750
+ var PI_CURRENT_MAJOR = 2;
746
751
  var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
747
752
  var V1_TMP_PREFIX = "context-mode-";
748
753
  var V1_TOML_SECTION_ROOT = "mcp_servers";
@@ -1066,7 +1071,7 @@ function outputOf(resp) {
1066
1071
  function textSlot(r) {
1067
1072
  const file2 = r.file;
1068
1073
  if (r.type === "text" && typeof file2 === "object" && file2 !== null && typeof file2.content === "string") {
1069
- return { text: file2.content, put: (o, output) => ({ ...o, file: { ...o.file, content: output } }) };
1074
+ return { text: file2.content, put: (o, output) => ({ ...o, file: readFile(o.file, output) }) };
1070
1075
  }
1071
1076
  if (isGrepContent(r)) return { text: r.content, put: (o, output) => ({ ...o, content: output }) };
1072
1077
  if (Array.isArray(r.filenames) && r.filenames.every((f) => typeof f === "string")) {
@@ -1075,13 +1080,35 @@ function textSlot(r) {
1075
1080
  if (typeof r.result === "string") return { text: r.result, put: (o, output) => ({ ...o, result: output }) };
1076
1081
  return null;
1077
1082
  }
1083
+ function readFile(file2, output) {
1084
+ const start = typeof file2.startLine === "number" ? file2.startLine : 1;
1085
+ const lines = String(file2.content).split("\n");
1086
+ const read3 = typeof file2.numLines === "number" ? file2.numLines : lines.length;
1087
+ const out = output.split("\n");
1088
+ const run = firstRun(lines, out);
1089
+ if (run === null) return { ...file2, content: output, startLine: start + read3, numLines: out.length };
1090
+ const kept = out.slice(0, run.length);
1091
+ if (run.length < out.length) kept.push(out[out.length - 1]);
1092
+ return { ...file2, content: kept.join("\n"), startLine: start + run.at, numLines: kept.length };
1093
+ }
1094
+ function firstRun(lines, out) {
1095
+ let best = null;
1096
+ for (let i = 0; i < lines.length; i++) {
1097
+ if (lines[i] !== out[0]) continue;
1098
+ let n = 1;
1099
+ while (n < out.length && i + n < lines.length && lines[i + n] === out[n]) n++;
1100
+ if (best === null || n > best.length) best = { at: i, length: n };
1101
+ if (n === out.length) break;
1102
+ }
1103
+ return best;
1104
+ }
1078
1105
  function isShellShape(resp) {
1079
1106
  const r = resp;
1080
1107
  return typeof r.stdout === "string" || typeof r.stderr === "string";
1081
1108
  }
1082
1109
  function isGrepContent(resp) {
1083
1110
  const r = resp;
1084
- return r.mode === "content" && typeof r.content === "string";
1111
+ return (r.mode === "content" || r.mode === "count") && typeof r.content === "string";
1085
1112
  }
1086
1113
  function blocksOf(resp) {
1087
1114
  const parts = [];
@@ -1097,6 +1124,7 @@ function readResult(resp) {
1097
1124
  const text = outputOf(resp);
1098
1125
  const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
1099
1126
  const info = { isError, bytes: Buffer.byteLength(text), text };
1127
+ if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isShellShape(resp)) info.shape = resp;
1100
1128
  if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
1101
1129
  if (textSlot(resp) !== null) info.shape = resp;
1102
1130
  else info.keep = true;
@@ -1136,8 +1164,11 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
1136
1164
  return ev;
1137
1165
  }
1138
1166
  function replaceShape(ev, output) {
1139
- if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
1140
1167
  const shape = ev.result?.shape;
1168
+ if (ev.tool?.canonicalName === "Bash") {
1169
+ const { persistedOutputPath: _p, persistedOutputSize: _s, ...host } = shape ?? {};
1170
+ return { interrupted: false, ...host, stdout: output, stderr: "" };
1171
+ }
1141
1172
  const slot = shape === void 0 ? null : textSlot(shape);
1142
1173
  if (shape !== void 0 && slot !== null) return slot.put(shape, output);
1143
1174
  if (ev.result?.blocks === true) return [{ type: "text", text: output }];
@@ -1632,7 +1663,7 @@ var PI_EVENTS = {
1632
1663
  tool_call: { event: "PreToolUse" },
1633
1664
  tool_result: { event: "PostToolUse" }
1634
1665
  };
1635
- var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
1666
+ var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
1636
1667
  function record(v) {
1637
1668
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
1638
1669
  }
@@ -1757,8 +1788,8 @@ var ADAPTERS = Object.freeze([
1757
1788
  hookTimeoutMs: HOOK_TIMEOUT_MS,
1758
1789
  denyChannel: "deny-reason",
1759
1790
  hookChannel: { kind: "package", path: "hooks/claude-code.json" },
1760
- skillChannel: { kind: "package", path: "claude-code/skills" },
1761
- // ADR-0020, D-HQ-SKILLS-2
1791
+ skillChannel: { kind: "package", path: "skills" },
1792
+ // ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
1762
1793
  decode,
1763
1794
  encode
1764
1795
  },
@@ -1902,8 +1933,9 @@ var ADAPTERS = Object.freeze([
1902
1933
  installMode: "in-process",
1903
1934
  projectSource: "pi:ctx.cwd",
1904
1935
  toolNamePrefix: TOOL_NAME_PREFIX9,
1905
- nativeTools: { shell: ["bash"], read: ["read"] },
1936
+ nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
1906
1937
  execReadOnlyHint: false,
1938
+ // D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
1907
1939
  eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
1908
1940
  compactDelivery: "pi-flag",
1909
1941
  compactSummary: "none",
@@ -3302,21 +3334,21 @@ function kiroDirOf(env, home, platform = process.platform) {
3302
3334
  if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
3303
3335
  if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
3304
3336
  const abs = p.resolve(dir);
3305
- const real2 = platform === process.platform ? realOrSelf : (x) => x;
3306
- const target = real2(abs);
3337
+ const real3 = platform === process.platform ? realOrSelf : (x) => x;
3338
+ const target = real3(abs);
3307
3339
  if (p.parse(target).root === target) return fallback;
3308
- const up = p.relative(target, real2(p.resolve(home)));
3340
+ const up = p.relative(target, real3(p.resolve(home)));
3309
3341
  if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
3310
3342
  return abs;
3311
3343
  }
3312
- function realOrSelf(path7) {
3344
+ function realOrSelf(path8) {
3313
3345
  const tail = [];
3314
- for (let at2 = path7; ; ) {
3346
+ for (let at2 = path8; ; ) {
3315
3347
  try {
3316
3348
  return join(realpathSync.native(at2), ...tail.reverse());
3317
3349
  } catch {
3318
3350
  const up = dirname(at2);
3319
- if (up === at2) return path7;
3351
+ if (up === at2) return path8;
3320
3352
  tail.push(basename(at2));
3321
3353
  at2 = up;
3322
3354
  }
@@ -3441,10 +3473,10 @@ function readPluginAgent(claudeDir, type) {
3441
3473
  }
3442
3474
  return null;
3443
3475
  }
3444
- function readAgentFile(path7) {
3476
+ function readAgentFile(path8) {
3445
3477
  let text;
3446
3478
  try {
3447
- text = readFileSync(path7, "utf8");
3479
+ text = readFileSync(path8, "utf8");
3448
3480
  } catch {
3449
3481
  return null;
3450
3482
  }
@@ -3707,12 +3739,12 @@ function readUserDeny(projectDir, agent) {
3707
3739
  }
3708
3740
  return out;
3709
3741
  }
3710
- function tokenize(glob, path7) {
3742
+ function tokenize(glob, path8) {
3711
3743
  const toks = [];
3712
3744
  let i = 0;
3713
3745
  while (i < glob.length) {
3714
3746
  const c = glob[i];
3715
- if (c === "*" && path7 && glob[i + 1] === "*") {
3747
+ if (c === "*" && path8 && glob[i + 1] === "*") {
3716
3748
  const dir = glob[i + "**".length] === "/";
3717
3749
  toks.push({ t: dir ? "globstarDir" : "globstar" });
3718
3750
  i += dir ? "**/".length : "**".length;
@@ -3726,8 +3758,8 @@ function tokenize(glob, path7) {
3726
3758
  }
3727
3759
  return toks;
3728
3760
  }
3729
- function globMatch(glob, text, path7) {
3730
- const toks = tokenize(glob, path7);
3761
+ function globMatch(glob, text, path8) {
3762
+ const toks = tokenize(glob, path8);
3731
3763
  const n = text.length;
3732
3764
  let next = new Uint8Array(n + 1);
3733
3765
  next[n] = 1;
@@ -3743,10 +3775,10 @@ function globMatch(glob, text, path7) {
3743
3775
  cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
3744
3776
  break;
3745
3777
  case "any1":
3746
- cur[j] = has3 && !(path7 && ch === "/") ? next[j + 1] : 0;
3778
+ cur[j] = has3 && !(path8 && ch === "/") ? next[j + 1] : 0;
3747
3779
  break;
3748
3780
  case "star":
3749
- cur[j] = next[j] || (has3 && !(path7 && ch === "/") ? cur[j + 1] : 0);
3781
+ cur[j] = next[j] || (has3 && !(path8 && ch === "/") ? cur[j + 1] : 0);
3750
3782
  break;
3751
3783
  case "globstar":
3752
3784
  cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
@@ -3826,8 +3858,8 @@ var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limi
3826
3858
  // src/core/policy/read-deny.ts
3827
3859
  var SIZE = "{size}";
3828
3860
  var PATH = "{path}";
3829
- function READ_DENY_MESSAGE(path7, size, prefix = "") {
3830
- return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path7);
3861
+ function READ_DENY_MESSAGE(path8, size, prefix = "") {
3862
+ return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
3831
3863
  }
3832
3864
 
3833
3865
  // src/core/policy/decide.ts
@@ -4535,9 +4567,9 @@ function readUserVersion(raw) {
4535
4567
  const row5 = raw.prepare("PRAGMA user_version").get();
4536
4568
  return row5.user_version;
4537
4569
  }
4538
- function createAtomically(sqlite, path7) {
4570
+ function createAtomically(sqlite, path8) {
4539
4571
  const { randomUUID } = process.getBuiltinModule("node:crypto");
4540
- const tmp = path7 + "." + randomUUID() + DB_TMP_SUFFIX;
4572
+ const tmp = path8 + "." + randomUUID() + DB_TMP_SUFFIX;
4541
4573
  try {
4542
4574
  const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
4543
4575
  try {
@@ -4546,7 +4578,7 @@ function createAtomically(sqlite, path7) {
4546
4578
  raw.close();
4547
4579
  }
4548
4580
  try {
4549
- linkSync(tmp, path7);
4581
+ linkSync(tmp, path8);
4550
4582
  } catch (err) {
4551
4583
  if (err.code !== "EEXIST") throw err;
4552
4584
  }
@@ -4554,11 +4586,11 @@ function createAtomically(sqlite, path7) {
4554
4586
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
4555
4587
  }
4556
4588
  }
4557
- function openWritable(sqlite, path7) {
4589
+ function openWritable(sqlite, path8) {
4558
4590
  let raw = null;
4559
4591
  try {
4560
- if (!existsSync2(path7)) createAtomically(sqlite, path7);
4561
- raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
4592
+ if (!existsSync2(path8)) createAtomically(sqlite, path8);
4593
+ raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
4562
4594
  applyMigrations(raw, readUserVersion(raw));
4563
4595
  return raw;
4564
4596
  } catch (err) {
@@ -4566,8 +4598,8 @@ function openWritable(sqlite, path7) {
4566
4598
  throw err;
4567
4599
  }
4568
4600
  }
4569
- function openReadOnly(sqlite, path7) {
4570
- const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
4601
+ function openReadOnly(sqlite, path8) {
4602
+ const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
4571
4603
  try {
4572
4604
  const found = readUserVersion(raw);
4573
4605
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -4581,20 +4613,20 @@ async function openDb(project, opts) {
4581
4613
  if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
4582
4614
  const sqlite = await loadSqlite();
4583
4615
  mkdirSync2(project.projectDir, { recursive: true });
4584
- const path7 = project.dbPath;
4585
- const sibling = existsSync2(path7 + DB_WAL_SUFFIX) || existsSync2(path7 + DB_SHM_SUFFIX);
4586
- if (sibling && !existsSync2(path7)) {
4616
+ const path8 = project.dbPath;
4617
+ const sibling = existsSync2(path8 + DB_WAL_SUFFIX) || existsSync2(path8 + DB_SHM_SUFFIX);
4618
+ if (sibling && !existsSync2(path8)) {
4587
4619
  throw new CtxError("DB_GONE");
4588
4620
  }
4589
4621
  try {
4590
4622
  let raw;
4591
4623
  if (opts?.readOnly === true) {
4592
- if (!existsSync2(path7)) openWritable(sqlite, path7).close();
4593
- raw = openReadOnly(sqlite, path7);
4624
+ if (!existsSync2(path8)) openWritable(sqlite, path8).close();
4625
+ raw = openReadOnly(sqlite, path8);
4594
4626
  } else {
4595
- raw = openWritable(sqlite, path7);
4627
+ raw = openWritable(sqlite, path8);
4596
4628
  }
4597
- return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
4629
+ return { raw, projectKey: project.projectKey, path: path8, ...opts?.readOnly === true ? { readOnly: true } : {} };
4598
4630
  } catch (err) {
4599
4631
  if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
4600
4632
  throw err;
@@ -7389,8 +7421,8 @@ function buildCandidates(rows, sessionId) {
7389
7421
  edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
7390
7422
  }
7391
7423
  const changedFiles = [];
7392
- for (const [path7, e] of edits) {
7393
- const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
7424
+ for (const [path8, e] of edits) {
7425
+ const c = make("changed_files", e.row, "edited " + path8 + " x" + e.count, e.count, path8);
7394
7426
  changedFiles.push({ ...c, editCount: e.count });
7395
7427
  }
7396
7428
  changedFiles.sort((a, b) => a.seq - b.seq);
@@ -8724,9 +8756,13 @@ async function preToolUse(ev, row5, project, env) {
8724
8756
  const userDeny = readUserDeny(project.worktree, ev.agent);
8725
8757
  const decision0 = decide(ev, row5, userDeny);
8726
8758
  let decision = decision0;
8727
- if (decision0.kind === "deny" && isSubagentCall(ev)) {
8728
- const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
8729
- if (subCase === "B") decision = caseB(ev, row5, decision0, userDeny);
8759
+ if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
8760
+ const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
8761
+ const subCase = pickSubagentCase(ev, set3);
8762
+ const tool = ev.tool;
8763
+ const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
8764
+ if (subCase === "B" && tool !== void 0 && isShell(tool, row5)) decision = caseB(ev, row5, decision0, userDeny);
8765
+ else if (subCase !== "A" && runs) decision = ALLOW2;
8730
8766
  }
8731
8767
  return decision;
8732
8768
  }
@@ -9588,10 +9624,10 @@ function assignProp(target, prop, value) {
9588
9624
  configurable: true
9589
9625
  });
9590
9626
  }
9591
- function getElementAtPath(obj, path7) {
9592
- if (!path7)
9627
+ function getElementAtPath(obj, path8) {
9628
+ if (!path8)
9593
9629
  return obj;
9594
- return path7.reduce((acc, key) => acc?.[key], obj);
9630
+ return path8.reduce((acc, key) => acc?.[key], obj);
9595
9631
  }
9596
9632
  function promiseAllObject(promisesObj) {
9597
9633
  const keys = Object.keys(promisesObj);
@@ -9911,11 +9947,11 @@ function aborted(x, startIndex = 0) {
9911
9947
  }
9912
9948
  return false;
9913
9949
  }
9914
- function prefixIssues(path7, issues) {
9950
+ function prefixIssues(path8, issues) {
9915
9951
  return issues.map((iss) => {
9916
9952
  var _a;
9917
9953
  (_a = iss).path ?? (_a.path = []);
9918
- iss.path.unshift(path7);
9954
+ iss.path.unshift(path8);
9919
9955
  return iss;
9920
9956
  });
9921
9957
  }
@@ -10052,7 +10088,7 @@ function treeifyError(error40, _mapper) {
10052
10088
  return issue2.message;
10053
10089
  };
10054
10090
  const result = { errors: [] };
10055
- const processError = (error41, path7 = []) => {
10091
+ const processError = (error41, path8 = []) => {
10056
10092
  var _a, _b;
10057
10093
  for (const issue2 of error41.issues) {
10058
10094
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -10062,7 +10098,7 @@ function treeifyError(error40, _mapper) {
10062
10098
  } else if (issue2.code === "invalid_element") {
10063
10099
  processError({ issues: issue2.issues }, issue2.path);
10064
10100
  } else {
10065
- const fullpath = [...path7, ...issue2.path];
10101
+ const fullpath = [...path8, ...issue2.path];
10066
10102
  if (fullpath.length === 0) {
10067
10103
  result.errors.push(mapper(issue2));
10068
10104
  continue;
@@ -10092,9 +10128,9 @@ function treeifyError(error40, _mapper) {
10092
10128
  processError(error40);
10093
10129
  return result;
10094
10130
  }
10095
- function toDotPath(path7) {
10131
+ function toDotPath(path8) {
10096
10132
  const segs = [];
10097
- for (const seg of path7) {
10133
+ for (const seg of path8) {
10098
10134
  if (typeof seg === "number")
10099
10135
  segs.push(`[${seg}]`);
10100
10136
  else if (typeof seg === "symbol")
@@ -20312,19 +20348,19 @@ function steeringFiles(worktree) {
20312
20348
  function readAutoMemory(project) {
20313
20349
  const rows = [];
20314
20350
  for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
20315
- const path7 = join7(project.worktree, ...segs);
20316
- if (!isInside(project.worktree, path7)) continue;
20351
+ const path8 = join7(project.worktree, ...segs);
20352
+ if (!isInside(project.worktree, path8)) continue;
20317
20353
  try {
20318
- const st = statSync4(path7);
20354
+ const st = statSync4(path8);
20319
20355
  if (!st.isFile()) continue;
20320
20356
  rows.push({
20321
20357
  origin: "memory",
20322
20358
  ts: Math.trunc(st.mtimeMs),
20323
20359
  seq: null,
20324
20360
  sourceId: null,
20325
- path: path7,
20361
+ path: path8,
20326
20362
  label: segs.join("/"),
20327
- text: readFileSync5(path7, "utf8")
20363
+ text: readFileSync5(path8, "utf8")
20328
20364
  });
20329
20365
  } catch {
20330
20366
  }
@@ -20894,7 +20930,7 @@ var ctxBatch = Object.freeze({
20894
20930
  });
20895
20931
 
20896
20932
  // src/core/tools/doctor.ts
20897
- import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as existsSync14 } from "node:fs";
20933
+ import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
20898
20934
  import { basename as basename5, join as join17 } from "node:path";
20899
20935
 
20900
20936
  // src/core/ops/bundle-dir.ts
@@ -20920,7 +20956,7 @@ function ownBundleDir() {
20920
20956
  }
20921
20957
 
20922
20958
  // src/core/ops/doctor-config.ts
20923
- import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
20959
+ import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
20924
20960
  import { join as join12 } from "node:path";
20925
20961
 
20926
20962
  // src/core/ops/detect-v1.ts
@@ -23039,15 +23075,15 @@ function atomicWriteFile(file2, text, opts = {}) {
23039
23075
  }
23040
23076
 
23041
23077
  // src/core/ops/host-config.ts
23042
- function formatOf(path7) {
23043
- if (path7.endsWith(JSONC_EXT)) return "jsonc";
23044
- if (path7.endsWith(TOML_EXT)) return "toml";
23078
+ function formatOf(path8) {
23079
+ if (path8.endsWith(JSONC_EXT)) return "jsonc";
23080
+ if (path8.endsWith(TOML_EXT)) return "toml";
23045
23081
  return "json";
23046
23082
  }
23047
- function readHostConfig(agent, path7) {
23048
- let file2 = path7;
23083
+ function readHostConfig(agent, path8) {
23084
+ let file2 = path8;
23049
23085
  if (agent === "opencode") {
23050
- const jsonc = join9(dirname6(path7), OPENCODE_CONFIG_FILES[0]);
23086
+ const jsonc = join9(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
23051
23087
  if (existsSync4(jsonc)) file2 = jsonc;
23052
23088
  }
23053
23089
  const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
@@ -23211,14 +23247,14 @@ function scanToml(text) {
23211
23247
  continue;
23212
23248
  }
23213
23249
  if (!node.resolvedKey.every((seg) => typeof seg === "string")) continue;
23214
- const path7 = node.resolvedKey;
23215
- for (const kv of node.body) addKey(path7, kv);
23250
+ const path8 = node.resolvedKey;
23251
+ for (const kv of node.body) addKey(path8, kv);
23216
23252
  if (node.kind !== "standard") continue;
23217
23253
  const start = lineStartOf(text, node.range[0]);
23218
23254
  const headEnd = lineEndOf(text, node.key.range[1]);
23219
23255
  const last2 = node.body[node.body.length - 1];
23220
23256
  tables.push({
23221
- path: path7,
23257
+ path: path8,
23222
23258
  header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
23223
23259
  start,
23224
23260
  end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
@@ -23229,16 +23265,16 @@ function scanToml(text) {
23229
23265
  function tomlTableSpans(text) {
23230
23266
  return scanToml(text).tables;
23231
23267
  }
23232
- function parseHostConfig(agent, path7, text, format) {
23268
+ function parseHostConfig(agent, path8, text, format) {
23233
23269
  try {
23234
23270
  return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
23235
23271
  } catch {
23236
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
23272
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
23237
23273
  }
23238
23274
  }
23239
- function hostConfigValueAt(value, path7) {
23275
+ function hostConfigValueAt(value, path8) {
23240
23276
  let cur = value;
23241
- for (const seg of path7) {
23277
+ for (const seg of path8) {
23242
23278
  if (!isPlainObject3(cur)) return void 0;
23243
23279
  cur = cur[seg];
23244
23280
  }
@@ -23271,32 +23307,32 @@ function indentUnit(root, clean) {
23271
23307
  function render(value, unit, base) {
23272
23308
  return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
23273
23309
  }
23274
- function nest(path7, value) {
23310
+ function nest(path8, value) {
23275
23311
  let out = value;
23276
- for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
23312
+ for (let k = path8.length - 1; k >= 0; k -= 1) out = { [path8[k]]: out };
23277
23313
  return out;
23278
23314
  }
23279
- function setJsonText(text, format, path7, value) {
23315
+ function setJsonText(text, format, path8, value) {
23280
23316
  const doc = scanJson(text, format);
23281
23317
  const unit = indentUnit(doc.root, doc.clean);
23282
- if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
23318
+ if (doc.root === null) return render(nest(path8, value), unit, "") + "\n";
23283
23319
  let node = doc.root;
23284
23320
  let depth = 0;
23285
- while (depth < path7.length && node.kind === "object") {
23286
- const hit = node.members.find((m) => m.key === path7[depth]);
23321
+ while (depth < path8.length && node.kind === "object") {
23322
+ const hit = node.members.find((m) => m.key === path8[depth]);
23287
23323
  if (hit === void 0) break;
23288
23324
  node = hit.node;
23289
23325
  depth += 1;
23290
23326
  }
23291
- if (depth === path7.length) {
23327
+ if (depth === path8.length) {
23292
23328
  return text.slice(0, node.start) + render(value, unit, lineIndent(doc.clean, node.start)) + text.slice(node.end);
23293
23329
  }
23294
- if (node.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
23295
- const rest = nest(path7.slice(depth + 1), value);
23330
+ if (node.kind !== "object") throw new SyntaxError("not an object at " + path8.slice(0, depth).join("."));
23331
+ const rest = nest(path8.slice(depth + 1), value);
23296
23332
  const last2 = node.members[node.members.length - 1];
23297
23333
  if (last2 === void 0) {
23298
23334
  const base2 = lineIndent(doc.clean, node.start);
23299
- const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
23335
+ const member2 = "\n" + base2 + unit + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
23300
23336
  return text.slice(0, node.start + 1) + member2 + text.slice(node.end - 1);
23301
23337
  }
23302
23338
  const base = lineIndent(doc.clean, last2.keyStart);
@@ -23304,7 +23340,7 @@ function setJsonText(text, format, path7, value) {
23304
23340
  while (" \r\n".includes(doc.clean[at2])) at2 += 1;
23305
23341
  const trailing = doc.clean[at2] === ",";
23306
23342
  const insertAt = trailing ? at2 + 1 : last2.node.end;
23307
- const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
23343
+ const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base);
23308
23344
  return text.slice(0, insertAt) + member + text.slice(insertAt);
23309
23345
  }
23310
23346
  function tomlScalar(v) {
@@ -23322,17 +23358,17 @@ function tomlHeaderKey(seg) {
23322
23358
  }
23323
23359
  return seg;
23324
23360
  }
23325
- function tomlBlock(path7, value) {
23326
- let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
23361
+ function tomlBlock(path8, value) {
23362
+ let out = "[" + path8.map(tomlHeaderKey).join(".") + "]\n";
23327
23363
  const subs = [];
23328
23364
  for (const [k, v] of Object.entries(value)) {
23329
- if (isPlainObject3(v)) subs.push(tomlBlock([...path7, k], v));
23365
+ if (isPlainObject3(v)) subs.push(tomlBlock([...path8, k], v));
23330
23366
  else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
23331
23367
  }
23332
23368
  return [out, ...subs].join("\n");
23333
23369
  }
23334
- function under(path7, prefix) {
23335
- return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
23370
+ function under(path8, prefix) {
23371
+ return path8.length >= prefix.length && prefix.every((seg, k) => path8[k] === seg);
23336
23372
  }
23337
23373
  function keyLineRange(text, k) {
23338
23374
  const ls = lineStartOf(text, k.start);
@@ -23349,10 +23385,10 @@ function withValueAt(root, rel, value) {
23349
23385
  else base[rel[0]] = next;
23350
23386
  return base;
23351
23387
  }
23352
- function replaceToml(text, doc, path7, value) {
23353
- const block = value === void 0 ? "" : tomlBlock(path7, value);
23354
- const owned = doc.tables.filter((t) => under(t.path, path7));
23355
- const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
23388
+ function replaceToml(text, doc, path8, value) {
23389
+ const block = value === void 0 ? "" : tomlBlock(path8, value);
23390
+ const owned = doc.tables.filter((t) => under(t.path, path8));
23391
+ const cuts = doc.keys.filter((k) => under(k.full, path8) && !under(k.base, path8)).map((k) => [...keyLineRange(text, k), ""]);
23356
23392
  owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
23357
23393
  cuts.sort((a, b) => b[0] - a[0]);
23358
23394
  let out = text;
@@ -23362,27 +23398,27 @@ function replaceToml(text, doc, path7, value) {
23362
23398
  return out + sep4 + block;
23363
23399
  }
23364
23400
  var tableLike = (v) => v === void 0 || isPlainObject3(v);
23365
- function setTomlText(text, path7, value) {
23401
+ function setTomlText(text, path8, value) {
23366
23402
  if (value !== void 0 && !isPlainObject3(value)) throw new SyntaxError("TOML edits replace a whole table");
23367
23403
  const doc = scanToml(text);
23368
- const cur = hostConfigValueAt(doc.value, path7);
23404
+ const cur = hostConfigValueAt(doc.value, path8);
23369
23405
  if (sameValue(cur, value)) return text;
23370
- const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
23406
+ const inline = doc.keys.find((k) => k.inline && k.full.length < path8.length && under(path8, k.full));
23371
23407
  if (inline !== void 0) {
23372
- const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
23408
+ const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path8.slice(inline.full.length), value);
23373
23409
  return replaceToml(text, doc, inline.full, whole2);
23374
23410
  }
23375
23411
  if (isPlainObject3(cur) && isPlainObject3(value)) {
23376
23412
  const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
23377
23413
  if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
23378
23414
  let out = text;
23379
- for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
23415
+ for (const k of names) out = setTomlText(out, [...path8, k], value[k]);
23380
23416
  return out;
23381
23417
  }
23382
23418
  }
23383
- return replaceToml(text, doc, path7, value);
23419
+ return replaceToml(text, doc, path8, value);
23384
23420
  }
23385
- function setText(agent, path7, text, format, key, value) {
23421
+ function setText(agent, path8, text, format, key, value) {
23386
23422
  try {
23387
23423
  if (format !== "toml") return setJsonText(text, format, key, value);
23388
23424
  const out = setTomlText(text, key, value);
@@ -23391,7 +23427,7 @@ function setText(agent, path7, text, format, key, value) {
23391
23427
  if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
23392
23428
  return out;
23393
23429
  } catch {
23394
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
23430
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
23395
23431
  }
23396
23432
  }
23397
23433
  function serverScript() {
@@ -23438,14 +23474,14 @@ function ownTargets(agent, accept) {
23438
23474
  if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
23439
23475
  return [];
23440
23476
  }
23441
- function applyEdits(agent, path7, text, format, wanted) {
23442
- const parsed = parseHostConfig(agent, path7, text, format);
23477
+ function applyEdits(agent, path8, text, format, wanted) {
23478
+ const parsed = parseHostConfig(agent, path8, text, format);
23443
23479
  let out = text;
23444
23480
  const edits = [];
23445
23481
  for (const [key, after] of wanted) {
23446
23482
  const before = hostConfigValueAt(parsed, key);
23447
23483
  if (sameValue(before, after)) continue;
23448
- out = setText(agent, path7, out, format, key, after);
23484
+ out = setText(agent, path8, out, format, key, after);
23449
23485
  edits.push({ path: key.join("."), before, after });
23450
23486
  }
23451
23487
  return { text: out, format, edits };
@@ -23466,7 +23502,7 @@ function writeHostConfigEdit(_requested, current, patch) {
23466
23502
  // src/core/ops/detect-v1.ts
23467
23503
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23468
23504
  var keyPath = (...parts) => parts.join(".");
23469
- var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
23505
+ var finding = (file2, path8, reason) => ({ file: file2, path: path8, reason });
23470
23506
  function stripJsonc(text) {
23471
23507
  let out = "";
23472
23508
  let inStr = false;
@@ -23671,12 +23707,17 @@ function scanKiro(agentHome, project, out) {
23671
23707
  }
23672
23708
  dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23673
23709
  }
23710
+ function piNpmIsCurrent(piAgentDir) {
23711
+ const doc = readJson(join10(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
23712
+ const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
23713
+ return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
23714
+ }
23674
23715
  function scanPi(piAgentDir, agentHome, out) {
23675
23716
  const file2 = join10(piAgentDir, SETTINGS_FILE);
23676
23717
  const doc = readJson(file2);
23677
23718
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
23678
23719
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
23679
- if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
23720
+ if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
23680
23721
  });
23681
23722
  dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23682
23723
  }
@@ -23773,8 +23814,8 @@ function detectV1(agent, home, scope = {}) {
23773
23814
  import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23774
23815
  import { dirname as dirname7, isAbsolute as isAbsolute2, join as join11, sep as sep3 } from "node:path";
23775
23816
  import { fileURLToPath as fileURLToPath2 } from "node:url";
23776
- function missing(agent, path7) {
23777
- return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
23817
+ function missing(agent, path8) {
23818
+ return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
23778
23819
  }
23779
23820
  var parseOrNull = (text) => {
23780
23821
  try {
@@ -23803,9 +23844,9 @@ function recordedInstalls(text) {
23803
23844
  }
23804
23845
  return out;
23805
23846
  }
23806
- var realOrNull = (path7) => {
23847
+ var realOrNull = (path8) => {
23807
23848
  try {
23808
- return realpathSync4.native(path7);
23849
+ return realpathSync4.native(path8);
23809
23850
  } catch {
23810
23851
  return null;
23811
23852
  }
@@ -23903,14 +23944,83 @@ function candidate(adapter, env, worktree) {
23903
23944
  }
23904
23945
  }
23905
23946
  function resolvePluginRoot(adapter, env, worktree) {
23906
- const path7 = candidate(adapter, env, worktree);
23947
+ const path8 = candidate(adapter, env, worktree);
23907
23948
  try {
23908
- return realpathSync4.native(path7);
23949
+ return realpathSync4.native(path8);
23909
23950
  } catch {
23910
- throw missing(adapter.id, path7);
23951
+ throw missing(adapter.id, path8);
23911
23952
  }
23912
23953
  }
23913
23954
 
23955
+ // src/setup/pi-gate.ts
23956
+ import { existsSync as existsSync7, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
23957
+ import path4 from "node:path";
23958
+ var EXTENSIONS_KEY = "extensions";
23959
+ var PROJECT_DIR = ".pi";
23960
+ var TRUST_FILE = "trust.json";
23961
+ var ALWAYS = "always";
23962
+ var SOURCE_PREFIXES = ["npm:", "git:"];
23963
+ function load(file2) {
23964
+ if (!existsSync7(file2)) return void 0;
23965
+ try {
23966
+ return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync9(file2, "utf8")), "json") };
23967
+ } catch {
23968
+ return void 0;
23969
+ }
23970
+ }
23971
+ var real2 = (p) => {
23972
+ try {
23973
+ return realpathSync5(p);
23974
+ } catch {
23975
+ return path4.resolve(p);
23976
+ }
23977
+ };
23978
+ function sourceName(source) {
23979
+ let s = source;
23980
+ for (const p of SOURCE_PREFIXES) if (s.startsWith(p)) s = s.slice(p.length);
23981
+ const last2 = s.split("/").pop() ?? "";
23982
+ const at2 = last2.indexOf("@", 1);
23983
+ const name = at2 > 0 ? last2.slice(0, at2) : last2;
23984
+ return name.endsWith(".git") ? name.slice(0, -4) : name;
23985
+ }
23986
+ function isOwn(source, pkgDir) {
23987
+ if (typeof source !== "string") return false;
23988
+ return real2(source) === real2(pkgDir) || sourceName(source) === SERVER_KEY;
23989
+ }
23990
+ function ownEntries(src, pkgDir) {
23991
+ const list4 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
23992
+ if (!Array.isArray(list4)) return [];
23993
+ const out = [];
23994
+ for (const e of list4) {
23995
+ const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
23996
+ if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
23997
+ const ext = obj?.[EXTENSIONS_KEY];
23998
+ out.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x) => typeof x === "string") : void 0 });
23999
+ }
24000
+ return out;
24001
+ }
24002
+ function projectTrusted(agentDir, userDoc, cwd) {
24003
+ const trust = load(path4.join(agentDir, TRUST_FILE));
24004
+ const entries = /* @__PURE__ */ new Map();
24005
+ if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real2(k), v);
24006
+ let dir = real2(cwd);
24007
+ for (; ; ) {
24008
+ const v = entries.get(dir);
24009
+ if (v === true || v === false) return v;
24010
+ const up = path4.dirname(dir);
24011
+ if (up === dir) break;
24012
+ dir = up;
24013
+ }
24014
+ return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
24015
+ }
24016
+ function piInstalledIn(env, home, pkgDir, cwd) {
24017
+ const agentDir = piAgentDirOf(env, home);
24018
+ const user = load(path4.join(agentDir, SETTINGS_FILE));
24019
+ const project = load(path4.join(cwd, PROJECT_DIR, SETTINGS_FILE));
24020
+ if (project && projectTrusted(agentDir, user?.doc, cwd) && ownEntries(project, pkgDir).length > 0) return project.file;
24021
+ return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
24022
+ }
24023
+
23914
24024
  // src/core/ops/doctor-config.ts
23915
24025
  var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
23916
24026
  var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
@@ -24011,14 +24121,14 @@ function codexNativeDir(env, home) {
24011
24121
  }
24012
24122
  if (enabled !== true) return null;
24013
24123
  const cache = join12(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
24014
- if (!existsSync7(cache)) return null;
24124
+ if (!existsSync8(cache)) return null;
24015
24125
  const found = [];
24016
24126
  for (const market of readdirSync4(cache)) {
24017
24127
  const plugin = join12(cache, market, SERVER_KEY);
24018
- if (!existsSync7(plugin)) continue;
24128
+ if (!existsSync8(plugin)) continue;
24019
24129
  for (const version2 of readdirSync4(plugin).sort()) {
24020
24130
  const dir = join12(plugin, version2, CODEX_PLUGIN_SUBDIR);
24021
- if (existsSync7(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24131
+ if (existsSync8(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24022
24132
  }
24023
24133
  }
24024
24134
  return found.length === 0 ? null : found[found.length - 1];
@@ -24109,12 +24219,17 @@ function checkHostConfig(row5, env, worktree) {
24109
24219
  const choice = marketplaceChoice(env, worktree);
24110
24220
  if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
24111
24221
  }
24222
+ if (row5.id === "pi") return checkPiInstall(env, home, worktree);
24112
24223
  const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
24113
- const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
24114
- if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
24224
+ if (parts.length === 0) return pass("D3");
24115
24225
  const detail = D3_DETAIL(parts);
24116
24226
  const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
24117
- return fail2("D3", read3 === null ? detail : detail + D4_REASON_JOIN + read3, fix);
24227
+ return fail2("D3", detail, fix);
24228
+ }
24229
+ function checkPiInstall(env, home, worktree) {
24230
+ const found = piInstalledIn(env, home, ownBundleDir(), worktree);
24231
+ if (found !== void 0) return { ...pass("D3"), detail: found };
24232
+ return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join12(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
24118
24233
  }
24119
24234
  function checkV1Leftovers(agent, home, scope = {}) {
24120
24235
  const findings = detectV1(agent, home, scope);
@@ -24167,7 +24282,7 @@ function configPaths(row5, env, worktree) {
24167
24282
  }
24168
24283
 
24169
24284
  // src/core/ops/doctor-db.ts
24170
- import { existsSync as existsSync8, statSync as statSync5 } from "node:fs";
24285
+ import { existsSync as existsSync9, statSync as statSync5 } from "node:fs";
24171
24286
  var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
24172
24287
  var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
24173
24288
  var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -24186,8 +24301,8 @@ async function loadSqlite2() {
24186
24301
  return null;
24187
24302
  }
24188
24303
  }
24189
- function openRead(sqlite, path7) {
24190
- return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
24304
+ function openRead(sqlite, path8) {
24305
+ return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
24191
24306
  }
24192
24307
  var cell = (row5) => Object.values(row5)[0];
24193
24308
  function readSchema(raw) {
@@ -24208,16 +24323,16 @@ function failsOnCorrupt(step) {
24208
24323
  function orphanFiles(dbPath) {
24209
24324
  const files = [];
24210
24325
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
24211
- const path7 = dbPath + suffix;
24212
- if (existsSync8(path7)) files.push({ path: path7, bytes: statSync5(path7).size });
24326
+ const path8 = dbPath + suffix;
24327
+ if (existsSync9(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
24213
24328
  }
24214
- return files.length > 0 && !existsSync8(dbPath) ? files : [];
24329
+ return files.length > 0 && !existsSync9(dbPath) ? files : [];
24215
24330
  }
24216
24331
  async function checkDb(project) {
24217
24332
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
24218
24333
  const orphan = orphanFiles(project.dbPath);
24219
24334
  if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
24220
- if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24335
+ if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24221
24336
  const sqlite = await loadSqlite2();
24222
24337
  if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
24223
24338
  let raw = null;
@@ -24243,7 +24358,7 @@ async function checkDb(project) {
24243
24358
  }
24244
24359
  }
24245
24360
  async function checkIndex(project) {
24246
- if (!existsSync8(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24361
+ if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24247
24362
  const sqlite = await loadSqlite2();
24248
24363
  if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
24249
24364
  let raw = null;
@@ -24260,7 +24375,7 @@ async function checkIndex(project) {
24260
24375
  }
24261
24376
 
24262
24377
  // src/core/ops/doctor-env.ts
24263
- import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
24378
+ import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
24264
24379
  import { isAbsolute as isAbsolute3, join as join13, relative as relative2 } from "node:path";
24265
24380
  function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
24266
24381
  return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
@@ -24273,7 +24388,7 @@ function fail4(id2, detail, fixCommand) {
24273
24388
  }
24274
24389
  function bundleVersion(bundleDir2) {
24275
24390
  try {
24276
- const v = JSON.parse(readFileSync9(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24391
+ const v = JSON.parse(readFileSync10(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24277
24392
  return typeof v === "string" && v !== "" ? v : void 0;
24278
24393
  } catch {
24279
24394
  return void 0;
@@ -24423,8 +24538,8 @@ function checkMcp(ctx) {
24423
24538
  return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
24424
24539
  }
24425
24540
  function piCwdInside(worktree, piCwd) {
24426
- if (piCwd === void 0 || !existsSync9(piCwd)) return false;
24427
- const rel = relative2(worktree, realpathSync5.native(piCwd));
24541
+ if (piCwd === void 0 || !existsSync10(piCwd)) return false;
24542
+ const rel = relative2(worktree, realpathSync6.native(piCwd));
24428
24543
  return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
24429
24544
  }
24430
24545
  function checkProject(i) {
@@ -24444,20 +24559,20 @@ function checkShell(env) {
24444
24559
  }
24445
24560
 
24446
24561
  // src/core/ops/doctor-hook.ts
24447
- import { existsSync as existsSync11, mkdtempSync, readFileSync as readFileSync10, realpathSync as realpathSync7, rmSync as rmSync2 } from "node:fs";
24562
+ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2 } from "node:fs";
24448
24563
  import { tmpdir as tmpdir2 } from "node:os";
24449
- import path6 from "node:path";
24564
+ import path7 from "node:path";
24450
24565
 
24451
24566
  // src/setup/codex-trust.ts
24452
24567
  import { createHash } from "node:crypto";
24453
- import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
24454
- import path5 from "node:path";
24568
+ import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
24569
+ import path6 from "node:path";
24455
24570
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
24456
24571
 
24457
24572
  // src/setup/spawn-bin.ts
24458
24573
  import { spawnSync } from "node:child_process";
24459
24574
  import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
24460
- import path4 from "node:path";
24575
+ import path5 from "node:path";
24461
24576
  var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
24462
24577
  var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
24463
24578
  var DEFAULT_COMSPEC = "cmd.exe";
@@ -24468,10 +24583,10 @@ function whichBin(bin, env, platform = process.platform) {
24468
24583
  const get = (k) => envGet(env, k);
24469
24584
  const win = platform === "win32";
24470
24585
  const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
24471
- const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
24586
+ const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
24472
24587
  for (const dir of pathEntries(get("PATH") ?? "", platform)) {
24473
24588
  for (const n of names) {
24474
- const f = path4.join(dir, n);
24589
+ const f = path5.join(dir, n);
24475
24590
  try {
24476
24591
  accessSync2(f, fsc.X_OK);
24477
24592
  if (statSync6(f).isFile()) return f;
@@ -24512,7 +24627,7 @@ function winCmdLine(file2, args, env = {}) {
24512
24627
  return `"${[file2, ...args].map(q).join(" ")}"`;
24513
24628
  }
24514
24629
  function spawnForm(file2, args, env, platform = process.platform) {
24515
- if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
24630
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
24516
24631
  return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
24517
24632
  }
24518
24633
  return { command: file2, args, windowsVerbatimArguments: false };
@@ -24536,10 +24651,10 @@ function codexHomeFromReply(out) {
24536
24651
  return void 0;
24537
24652
  }
24538
24653
  function sameDir(a, b, platform = process.platform) {
24539
- if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
24654
+ if (platform !== "win32") return path6.posix.normalize(a) === path6.posix.normalize(b);
24540
24655
  const norm2 = (p) => {
24541
24656
  const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
24542
- const n = path5.win32.normalize(bare2).toLowerCase();
24657
+ const n = path6.win32.normalize(bare2).toLowerCase();
24543
24658
  return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
24544
24659
  };
24545
24660
  return norm2(a) === norm2(b);
@@ -24672,11 +24787,11 @@ function isObject5(v) {
24672
24787
  return typeof v === "object" && v !== null && !Array.isArray(v);
24673
24788
  }
24674
24789
  function loadFixture(bundleDir2, agent) {
24675
- const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
24676
- if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24790
+ const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
24791
+ if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24677
24792
  let all;
24678
24793
  try {
24679
- all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
24794
+ all = JSON.parse(hostText(readFileSync11(file2, "utf8")));
24680
24795
  } catch (err) {
24681
24796
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
24682
24797
  }
@@ -24738,7 +24853,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
24738
24853
  var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
24739
24854
  function readProbePayload(cwd) {
24740
24855
  const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
24741
- const filePath = path6.join(cwd, "d5-read-probe.txt");
24856
+ const filePath = path7.join(cwd, "d5-read-probe.txt");
24742
24857
  return {
24743
24858
  session_id: "d5-read-probe",
24744
24859
  transcript_path: "",
@@ -24765,9 +24880,9 @@ function isReadShape(stdout) {
24765
24880
  return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
24766
24881
  }
24767
24882
  async function readProbeOk(i, timeoutMs) {
24768
- const home = mkdtempSync(path6.join(tmpdir2(), "cm-d5-read-"));
24883
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
24769
24884
  try {
24770
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24885
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24771
24886
  cwd: i.bundleDir,
24772
24887
  env: { ...i.env, HOME: home, USERPROFILE: home },
24773
24888
  signal: i.signal,
@@ -24785,7 +24900,7 @@ function codexHookJournaled(db) {
24785
24900
  }
24786
24901
  function realDir(p) {
24787
24902
  try {
24788
- return realpathSync7(p);
24903
+ return realpathSync8(p);
24789
24904
  } catch {
24790
24905
  return p;
24791
24906
  }
@@ -24812,7 +24927,7 @@ async function checkHookRoundTrip(i) {
24812
24927
  const trust = await codexPluginTrust(i);
24813
24928
  if (trust !== null) return trust;
24814
24929
  }
24815
- if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24930
+ if (i.agent === "codex" && existsSync12(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24816
24931
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
24817
24932
  }
24818
24933
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -24832,7 +24947,7 @@ async function checkHookRoundTrip(i) {
24832
24947
  let ms = 0;
24833
24948
  for (let n = 1; n <= maxPairs; n++) {
24834
24949
  const start = now();
24835
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24950
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24836
24951
  cwd: i.bundleDir,
24837
24952
  env: i.env,
24838
24953
  signal: i.signal,
@@ -24851,11 +24966,11 @@ async function checkHookRoundTrip(i) {
24851
24966
  }
24852
24967
 
24853
24968
  // src/core/ops/db-heal.ts
24854
- import { existsSync as existsSync12, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
24969
+ import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
24855
24970
  import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
24856
24971
 
24857
24972
  // src/core/store/owners.ts
24858
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync11, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
24973
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
24859
24974
  import { basename as basename3, join as join14 } from "node:path";
24860
24975
  function ownersDir(configDir, projectKey) {
24861
24976
  return join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
@@ -24889,7 +25004,7 @@ function listLiveOwners(configDir, projectKey) {
24889
25004
  const file2 = join14(dir, name);
24890
25005
  let text;
24891
25006
  try {
24892
- text = readFileSync11(file2, "utf8");
25007
+ text = readFileSync12(file2, "utf8");
24893
25008
  } catch (err) {
24894
25009
  if (errCode2(err) === "ENOENT") continue;
24895
25010
  throw err;
@@ -24935,7 +25050,7 @@ function renameAside(dbPath) {
24935
25050
  const ts = String(Date.now());
24936
25051
  for (const suffix of DB_SIBLING_SUFFIXES) {
24937
25052
  const file2 = dbPath + suffix;
24938
- if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
25053
+ if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
24939
25054
  }
24940
25055
  return ts;
24941
25056
  }
@@ -25042,7 +25157,7 @@ function buildReportHead(input) {
25042
25157
 
25043
25158
  // src/core/ops/doctor-issue.ts
25044
25159
  import { spawnSync as spawnSync3 } from "node:child_process";
25045
- import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
25160
+ import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
25046
25161
  import { delimiter, join as join16 } from "node:path";
25047
25162
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
25048
25163
  function tildeOf(env) {
@@ -25050,8 +25165,8 @@ function tildeOf(env) {
25050
25165
  if (home === null || home === "") return (t) => t;
25051
25166
  const homes = [home];
25052
25167
  try {
25053
- const real2 = realpathSync8.native(home);
25054
- if (real2 !== home) homes.push(real2);
25168
+ const real3 = realpathSync9.native(home);
25169
+ if (real3 !== home) homes.push(real3);
25055
25170
  } catch {
25056
25171
  }
25057
25172
  homes.sort((a, b) => b.length - a.length);
@@ -25084,7 +25199,7 @@ function onPath(env, tool) {
25084
25199
  const out = [];
25085
25200
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
25086
25201
  if (dir === "") continue;
25087
- for (const n of names) if (existsSync13(join16(dir, n))) {
25202
+ for (const n of names) if (existsSync14(join16(dir, n))) {
25088
25203
  out.push(join16(dir, n));
25089
25204
  break;
25090
25205
  }
@@ -25093,7 +25208,7 @@ function onPath(env, tool) {
25093
25208
  }
25094
25209
  function hookLogTail(env) {
25095
25210
  const file2 = hookLogPath(env);
25096
- if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25211
+ if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25097
25212
  try {
25098
25213
  const fd = openSync(file2, "r");
25099
25214
  try {
@@ -25113,7 +25228,7 @@ function hookLogTail(env) {
25113
25228
  }
25114
25229
  async function journalRows(ctx) {
25115
25230
  const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
25116
- if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25231
+ if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25117
25232
  try {
25118
25233
  const db = await openDb(ctx.project, { readOnly: true });
25119
25234
  try {
@@ -25139,13 +25254,13 @@ function agentConfig(adapter, env, worktree) {
25139
25254
  for (const f of files) {
25140
25255
  if (seen.has(f.path)) continue;
25141
25256
  seen.add(f.path);
25142
- if (!existsSync13(f.path)) {
25257
+ if (!existsSync14(f.path)) {
25143
25258
  out.push(`${f.label}: ${f.path} (absent)`);
25144
25259
  continue;
25145
25260
  }
25146
25261
  let text = "";
25147
25262
  try {
25148
- text = readFileSync12(f.path, "utf8");
25263
+ text = readFileSync13(f.path, "utf8");
25149
25264
  } catch (err) {
25150
25265
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
25151
25266
  continue;
@@ -25244,7 +25359,7 @@ async function guard(id2, run) {
25244
25359
  }
25245
25360
  }
25246
25361
  async function codexDb(ctx, adapter) {
25247
- if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
25362
+ if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
25248
25363
  try {
25249
25364
  return await openDb(ctx.project, { readOnly: true });
25250
25365
  } catch {
@@ -25275,10 +25390,10 @@ async function hookRow(ctx, adapter, host) {
25275
25390
  }
25276
25391
  function ownServerId(configDir, projectKey) {
25277
25392
  const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
25278
- if (!existsSync14(dir)) return "";
25393
+ if (!existsSync15(dir)) return "";
25279
25394
  for (const name of readdirSync6(dir)) {
25280
25395
  if (!name.endsWith(OWNER_PID_EXT)) continue;
25281
- if (readFileSync13(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25396
+ if (readFileSync14(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25282
25397
  }
25283
25398
  return "";
25284
25399
  }
@@ -25334,7 +25449,7 @@ async function doctorReply(ctx, host) {
25334
25449
  const adapter = getAdapter(ctx.project.agent);
25335
25450
  const rows = await runDoctorChecks(ctx, adapter, host);
25336
25451
  const failed2 = rows.some((r) => r.status === "FAIL");
25337
- const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
25452
+ const command = adapter.id === "pi" ? failed2 ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
25338
25453
  const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
25339
25454
  const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
25340
25455
  const table3 = buildReport(input);
@@ -25361,7 +25476,7 @@ async function doctorReply(ctx, host) {
25361
25476
  return { text, isError: false, sandboxBytes: bytes5 };
25362
25477
  }
25363
25478
  async function handler2(_input, ctx) {
25364
- return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: void 0 });
25479
+ return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
25365
25480
  }
25366
25481
  var ctxDoctor = Object.freeze({
25367
25482
  name: "ctx_doctor",
@@ -25373,7 +25488,7 @@ var ctxDoctor = Object.freeze({
25373
25488
  });
25374
25489
 
25375
25490
  // src/core/tools/execute.ts
25376
- import { existsSync as existsSync15, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
25491
+ import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
25377
25492
  import { tmpdir as tmpdir3 } from "node:os";
25378
25493
  import { dirname as dirname10, join as join18, parse as parse3, resolve as resolve6 } from "node:path";
25379
25494
 
@@ -25459,7 +25574,7 @@ function schemaLine(issue2) {
25459
25574
  }
25460
25575
  function fileError(given, abs, root) {
25461
25576
  let dir = abs;
25462
- while (!existsSync15(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
25577
+ while (!existsSync16(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
25463
25578
  if (isInside(root, dir)) return null;
25464
25579
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
25465
25580
  }
@@ -25576,19 +25691,19 @@ var ctxExecute = {
25576
25691
  };
25577
25692
 
25578
25693
  // src/core/tools/index.ts
25579
- import { existsSync as existsSync16, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
25694
+ import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
25580
25695
  import { dirname as dirname11, extname, join as join20, relative as relative3, resolve as resolve7 } from "node:path";
25581
25696
 
25582
25697
  // src/core/index/walk.ts
25583
- import { readdirSync as readdirSync7, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
25698
+ import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
25584
25699
  import { join as join19 } from "node:path";
25585
25700
  var GITIGNORE = ".gitignore";
25586
25701
  var GIT_DIR = ".git";
25587
25702
  function walkDir(root, containmentRoot) {
25588
- const real2 = realpathSync9(root);
25589
- if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
25703
+ const real3 = realpathSync10(root);
25704
+ if (!isInside(containmentRoot, real3)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
25590
25705
  const found = [];
25591
- visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
25706
+ visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
25592
25707
  found.sort(compareFound);
25593
25708
  return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
25594
25709
  }
@@ -25602,14 +25717,14 @@ function visit(abs, rel, parent, contain, seen, found) {
25602
25717
  const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
25603
25718
  for (const e of entries) {
25604
25719
  if (e.name === GIT_DIR) continue;
25605
- const path7 = join19(abs, e.name);
25720
+ const path8 = join19(abs, e.name);
25606
25721
  let isDir = e.isDirectory();
25607
25722
  let isFile = e.isFile();
25608
- let target = path7;
25723
+ let target = path8;
25609
25724
  if (e.isSymbolicLink()) {
25610
25725
  let resolved;
25611
25726
  try {
25612
- resolved = realpathSync9(path7);
25727
+ resolved = realpathSync10(path8);
25613
25728
  } catch {
25614
25729
  continue;
25615
25730
  }
@@ -25622,12 +25737,12 @@ function visit(abs, rel, parent, contain, seen, found) {
25622
25737
  const segs = rel.concat(e.name);
25623
25738
  if (ignored(rules, segs, isDir)) continue;
25624
25739
  if (isFile) {
25625
- found.push({ dir: rel, name: e.name, absPath: path7 });
25740
+ found.push({ dir: rel, name: e.name, absPath: path8 });
25626
25741
  } else if (isDir) {
25627
- const key = e.isSymbolicLink() ? target : realpathSync9(path7);
25742
+ const key = e.isSymbolicLink() ? target : realpathSync10(path8);
25628
25743
  if (seen.has(key)) continue;
25629
25744
  seen.add(key);
25630
- visit(path7, segs, rules, contain, seen, found);
25745
+ visit(path8, segs, rules, contain, seen, found);
25631
25746
  }
25632
25747
  }
25633
25748
  }
@@ -25642,7 +25757,7 @@ function compareFound(a, b) {
25642
25757
  function readRules(file2, base) {
25643
25758
  let body;
25644
25759
  try {
25645
- body = readFileSync14(file2, "utf8");
25760
+ body = readFileSync15(file2, "utf8");
25646
25761
  } catch {
25647
25762
  return [];
25648
25763
  }
@@ -25818,12 +25933,12 @@ function tlsName(host) {
25818
25933
  function request(u, conn, proxy, signal) {
25819
25934
  const host = bare(u.hostname);
25820
25935
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
25821
- const path7 = u.pathname + u.search;
25936
+ const path8 = u.pathname + u.search;
25822
25937
  return new Promise((resolve8, reject) => {
25823
25938
  const onErr = (err) => reject(fail6(causeCode(err)));
25824
25939
  if (proxy === void 0) {
25825
25940
  const mod = u.protocol === "https:" ? https : http;
25826
- const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
25941
+ const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
25827
25942
  req.on("response", resolve8).on("error", onErr).end();
25828
25943
  return;
25829
25944
  }
@@ -25845,7 +25960,7 @@ function request(u, conn, proxy, signal) {
25845
25960
  const req = https.request({
25846
25961
  host,
25847
25962
  port,
25848
- path: path7,
25963
+ path: path8,
25849
25964
  signal,
25850
25965
  headers: { host: u.host },
25851
25966
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
@@ -29725,14 +29840,14 @@ function kindOfType(contentType) {
29725
29840
  }
29726
29841
  function readUtf8(absPath) {
29727
29842
  try {
29728
- return utf8.decode(readFileSync15(absPath));
29843
+ return utf8.decode(readFileSync16(absPath));
29729
29844
  } catch {
29730
29845
  return void 0;
29731
29846
  }
29732
29847
  }
29733
29848
  function missingOrOutside(given, abs, root) {
29734
29849
  let dir = abs;
29735
- while (!existsSync16(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
29850
+ while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
29736
29851
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
29737
29852
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
29738
29853
  }
@@ -30283,11 +30398,11 @@ var ctxStats = Object.freeze({
30283
30398
  });
30284
30399
 
30285
30400
  // src/core/tools/upgrade.ts
30286
- import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
30401
+ import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
30287
30402
  import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
30288
30403
 
30289
30404
  // src/core/ops/host-write.ts
30290
- import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30405
+ import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30291
30406
  import { dirname as dirname12, join as join21 } from "node:path";
30292
30407
  function defaultWrite(file2, text) {
30293
30408
  writeFileSync5(file2, text, "utf8");
@@ -30316,7 +30431,7 @@ function toRow(file2, edit) {
30316
30431
  function writeWithRollback(file2, text, write2, atomic) {
30317
30432
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
30318
30433
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
30319
- const had = existsSync17(file2);
30434
+ const had = existsSync18(file2);
30320
30435
  mkdirSync7(dirname12(file2), { recursive: true });
30321
30436
  if (had) copyFileSync(file2, trash);
30322
30437
  try {
@@ -30346,7 +30461,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
30346
30461
  if (requested === null) return [];
30347
30462
  const current = readHostConfig(row5.id, requested);
30348
30463
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
30349
- const exists = existsSync17(current.path);
30464
+ const exists = existsSync18(current.path);
30350
30465
  if (exists && result.text === current.text) return [];
30351
30466
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
30352
30467
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -30354,15 +30469,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
30354
30469
  }
30355
30470
 
30356
30471
  // src/core/ops/plugin-swap.ts
30357
- import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30472
+ import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30358
30473
  import { basename as basename6, join as join22, win32 as win322 } from "node:path";
30359
- function linkTarget(path7, win) {
30360
- if (!isLink(path7)) return null;
30361
- const target = readlinkSync(path7);
30474
+ function linkTarget(path8, win) {
30475
+ if (!isLink(path8)) return null;
30476
+ const target = readlinkSync(path8);
30362
30477
  return win ? win322.basename(target) : target;
30363
30478
  }
30364
- function isLink(path7) {
30365
- return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
30479
+ function isLink(path8) {
30480
+ return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
30366
30481
  }
30367
30482
  function generations(agentDir) {
30368
30483
  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();
@@ -30375,7 +30490,7 @@ function settleLinks(link, tmp, old, opts) {
30375
30490
  }
30376
30491
  function swapPluginCurrent(agentDir, sha, opts = {}) {
30377
30492
  const next = join22(agentDir, sha);
30378
- if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
30493
+ if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
30379
30494
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
30380
30495
  }
30381
30496
  const link = join22(agentDir, PLUGIN_CURRENT_LINK);
@@ -30395,12 +30510,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
30395
30510
  if (before !== null) keep.add(before);
30396
30511
  const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
30397
30512
  for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
30398
- const previous = before !== null && existsSync18(join22(agentDir, before)) ? join22(agentDir, before) : null;
30513
+ const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
30399
30514
  return { current: next, previous, removed };
30400
30515
  }
30401
30516
 
30402
30517
  // src/core/ops/release-fetch.ts
30403
- import { existsSync as existsSync19, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
30518
+ import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
30404
30519
  import { join as join23 } from "node:path";
30405
30520
  function failed(r) {
30406
30521
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -30424,7 +30539,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
30424
30539
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
30425
30540
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
30426
30541
  const dir = join23(agentDir, sha);
30427
- if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
30542
+ if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
30428
30543
  else renameWithRetry(fetchDir, dir, opts);
30429
30544
  return { sha, dir };
30430
30545
  } catch (e) {
@@ -30434,7 +30549,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
30434
30549
  }
30435
30550
 
30436
30551
  // src/core/ops/uninstall.ts
30437
- import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
30552
+ import { existsSync as existsSync21, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
30438
30553
  import { join as join24 } from "node:path";
30439
30554
  function row2(area, before, after) {
30440
30555
  return { area, before, after };
@@ -30468,7 +30583,7 @@ function removeCache(adapter, env, configDir) {
30468
30583
  }
30469
30584
  case "plugin": {
30470
30585
  const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
30471
- if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30586
+ if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30472
30587
  rmSync8(agentDir, { recursive: true, force: true });
30473
30588
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
30474
30589
  }
@@ -30487,7 +30602,7 @@ function isObj3(v) {
30487
30602
  function piSource(entry) {
30488
30603
  return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
30489
30604
  }
30490
- function ownEntries(agent, env) {
30605
+ function ownEntries2(agent, env) {
30491
30606
  const home = requireHomeDir(env);
30492
30607
  const mcp = OWN_MCP_ENTRY[agent];
30493
30608
  if (mcp !== void 0) {
@@ -30495,10 +30610,10 @@ function ownEntries(agent, env) {
30495
30610
  const inner = mcp.key.slice(1, -1);
30496
30611
  const own2 = mcp.key[mcp.key.length - 1];
30497
30612
  const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
30498
- const without = (v, path7) => {
30613
+ const without = (v, path8) => {
30499
30614
  const o = v;
30500
- if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own2));
30501
- return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
30615
+ if (path8.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own2));
30616
+ return { ...o, [path8[0]]: without(o[path8[0]], path8.slice(1)) };
30502
30617
  };
30503
30618
  return [{
30504
30619
  file: ownMcpFileOf(agent, mcp.file, env, home),
@@ -30535,7 +30650,7 @@ function ownEntries(agent, env) {
30535
30650
  }
30536
30651
  function removeOwnEntries(agent, env) {
30537
30652
  const rows = [];
30538
- for (const entry of ownEntries(agent, env)) {
30653
+ for (const entry of ownEntries2(agent, env)) {
30539
30654
  const current = readHostConfig(agent, entry.file);
30540
30655
  if (current.text === "") continue;
30541
30656
  const value = hostConfigValueAt(parseHostConfig(agent, current.path, current.text, current.format), [entry.key]);
@@ -30548,7 +30663,7 @@ function removeOwnEntries(agent, env) {
30548
30663
  function removeProjectData(configDir, projectKey) {
30549
30664
  const projects = join24(configDir, PROJECTS_DIR_NAME);
30550
30665
  const dir = join24(projects, projectKey);
30551
- if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30666
+ if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30552
30667
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
30553
30668
  for (const name of readdirSync9(dir)) {
30554
30669
  if (name !== OWNERS_DIR_NAME) rmSync8(join24(dir, name), { recursive: true, force: true });
@@ -30564,7 +30679,7 @@ function runUninstall(input) {
30564
30679
  }
30565
30680
 
30566
30681
  // src/core/ops/v1-remove.ts
30567
- import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync16, rmSync as rmSync9 } from "node:fs";
30682
+ import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync17, rmSync as rmSync9 } from "node:fs";
30568
30683
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
30569
30684
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
30570
30685
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -30594,8 +30709,8 @@ function cutTomlTable(text, header) {
30594
30709
  function writeAtomic(file2, text) {
30595
30710
  atomicWriteFile(file2, text);
30596
30711
  }
30597
- function locate(doc, path7) {
30598
- const segs = path7.split(V1_KEY_PATH_SEP);
30712
+ function locate(doc, path8) {
30713
+ const segs = path8.split(V1_KEY_PATH_SEP);
30599
30714
  let cur = doc;
30600
30715
  for (const seg of segs.slice(0, -1)) {
30601
30716
  if (Array.isArray(cur)) cur = cur[Number(seg)];
@@ -30608,8 +30723,8 @@ function locate(doc, path7) {
30608
30723
  return null;
30609
30724
  }
30610
30725
  function stripJsonEntries(agent, file2, findings, kept, undo) {
30611
- const layout = hostLayout(readFileSync16(file2, "utf8"));
30612
- const text = hostText(readFileSync16(file2, "utf8"));
30726
+ const layout = hostLayout(readFileSync17(file2, "utf8"));
30727
+ const text = hostText(readFileSync17(file2, "utf8"));
30613
30728
  const doc = parseHostConfig(agent, file2, text, "jsonc");
30614
30729
  const hit = /* @__PURE__ */ new Set();
30615
30730
  const byContainer = /* @__PURE__ */ new Map();
@@ -30645,19 +30760,19 @@ function removeV1(agent, findings) {
30645
30760
  for (const f of findings) {
30646
30761
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
30647
30762
  else if (f.path === "") {
30648
- if (existsSync21(f.file)) {
30763
+ if (existsSync22(f.file)) {
30649
30764
  moveAside(f.file, undo);
30650
30765
  done.set(f, UPGRADE_REMOVED);
30651
30766
  } else done.set(f, UPGRADE_NOT_FOUND);
30652
30767
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
30653
30768
  }
30654
30769
  for (const [file2, list4] of entries) {
30655
- if (!existsSync21(file2)) {
30770
+ if (!existsSync22(file2)) {
30656
30771
  for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
30657
30772
  continue;
30658
30773
  }
30659
30774
  if (file2.endsWith(TOML_EXT)) {
30660
- const rawToml = readFileSync16(file2, "utf8");
30775
+ const rawToml = readFileSync17(file2, "utf8");
30661
30776
  const tomlLayout = hostLayout(rawToml);
30662
30777
  let text = hostText(rawToml);
30663
30778
  for (const f of list4) {
@@ -30685,7 +30800,7 @@ function removeV1(agent, findings) {
30685
30800
  },
30686
30801
  rollback() {
30687
30802
  for (const u of undo.splice(0).reverse()) {
30688
- if (!existsSync21(u.trash)) continue;
30803
+ if (!existsSync22(u.trash)) continue;
30689
30804
  rmSync9(u.target, { recursive: true, force: true });
30690
30805
  renameWithRetry(u.trash, u.target);
30691
30806
  }
@@ -30695,7 +30810,7 @@ function removeV1(agent, findings) {
30695
30810
 
30696
30811
  // src/core/ops/verify-sums.ts
30697
30812
  import { createHash as createHash2 } from "node:crypto";
30698
- import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync17 } from "node:fs";
30813
+ import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
30699
30814
  import { join as join25 } from "node:path";
30700
30815
  function mismatch() {
30701
30816
  return new CtxError("BUNDLE_HASH_MISMATCH");
@@ -30727,14 +30842,14 @@ function verifySums(dir) {
30727
30842
  const sumsPath = join25(dir, RELEASE_SUMS_FILE);
30728
30843
  const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
30729
30844
  if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
30730
- const sums = parseSums(readFileSync17(sumsPath, "utf8"));
30845
+ const sums = parseSums(readFileSync18(sumsPath, "utf8"));
30731
30846
  const files = /* @__PURE__ */ new Map();
30732
30847
  walk3(dir, "", files);
30733
30848
  if (files.size !== sums.size) throw mismatch();
30734
30849
  for (const [rel, abs] of files) {
30735
30850
  const want = sums.get(rel);
30736
30851
  if (want === void 0) throw mismatch();
30737
- const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync17(abs)).digest(HASH_ENCODING);
30852
+ const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
30738
30853
  if (got !== want) throw mismatch();
30739
30854
  }
30740
30855
  }
@@ -30763,7 +30878,7 @@ function pluginRootRow(adapter, env) {
30763
30878
  }
30764
30879
  function isCurrent(agentDir, dir) {
30765
30880
  const link = join26(agentDir, PLUGIN_CURRENT_LINK);
30766
- return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
30881
+ return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
30767
30882
  }
30768
30883
  async function checkout(adapter, deps) {
30769
30884
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);