context-mode 2.1.1 → 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.
package/pi/index.js CHANGED
@@ -657,10 +657,10 @@ function assignProp(target, prop, value) {
657
657
  configurable: true
658
658
  });
659
659
  }
660
- function getElementAtPath(obj, path7) {
661
- if (!path7)
660
+ function getElementAtPath(obj, path8) {
661
+ if (!path8)
662
662
  return obj;
663
- return path7.reduce((acc, key) => acc?.[key], obj);
663
+ return path8.reduce((acc, key) => acc?.[key], obj);
664
664
  }
665
665
  function promiseAllObject(promisesObj) {
666
666
  const keys = Object.keys(promisesObj);
@@ -980,11 +980,11 @@ function aborted(x, startIndex = 0) {
980
980
  }
981
981
  return false;
982
982
  }
983
- function prefixIssues(path7, issues) {
983
+ function prefixIssues(path8, issues) {
984
984
  return issues.map((iss) => {
985
985
  var _a5;
986
986
  (_a5 = iss).path ?? (_a5.path = []);
987
- iss.path.unshift(path7);
987
+ iss.path.unshift(path8);
988
988
  return iss;
989
989
  });
990
990
  }
@@ -1121,7 +1121,7 @@ function treeifyError(error42, _mapper) {
1121
1121
  return issue4.message;
1122
1122
  };
1123
1123
  const result = { errors: [] };
1124
- const processError = (error43, path7 = []) => {
1124
+ const processError = (error43, path8 = []) => {
1125
1125
  var _a5, _b;
1126
1126
  for (const issue4 of error43.issues) {
1127
1127
  if (issue4.code === "invalid_union" && issue4.errors.length) {
@@ -1131,7 +1131,7 @@ function treeifyError(error42, _mapper) {
1131
1131
  } else if (issue4.code === "invalid_element") {
1132
1132
  processError({ issues: issue4.issues }, issue4.path);
1133
1133
  } else {
1134
- const fullpath = [...path7, ...issue4.path];
1134
+ const fullpath = [...path8, ...issue4.path];
1135
1135
  if (fullpath.length === 0) {
1136
1136
  result.errors.push(mapper(issue4));
1137
1137
  continue;
@@ -1161,9 +1161,9 @@ function treeifyError(error42, _mapper) {
1161
1161
  processError(error42);
1162
1162
  return result;
1163
1163
  }
1164
- function toDotPath(path7) {
1164
+ function toDotPath(path8) {
1165
1165
  const segs = [];
1166
- for (const seg of path7) {
1166
+ for (const seg of path8) {
1167
1167
  if (typeof seg === "number")
1168
1168
  segs.push(`[${seg}]`);
1169
1169
  else if (typeof seg === "symbol")
@@ -11571,7 +11571,7 @@ var DECISION_OPTION_KEY = "option";
11571
11571
  var DECISION_LABEL_JOIN = " | ";
11572
11572
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
11573
11573
  var RELEASE_BRANCH = "release";
11574
- var BUNDLE_SHA = true ? "2652fe27fc5d4e368fdc38eda49d3011d38e631e" : void 0;
11574
+ var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
11575
11575
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
11576
11576
  var DOCTOR_LABEL = Object.freeze({
11577
11577
  D1: "version",
@@ -11893,6 +11893,11 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
11893
11893
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
11894
11894
  var V1_STATUSLINE_COMMAND = "context-mode statusline";
11895
11895
  var V1_PI_PACKAGE = "npm:context-mode";
11896
+ var PI_NPM_DIR = "npm";
11897
+ var PI_NODE_MODULES_DIR = "node_modules";
11898
+ var PI_PACKAGE_JSON_FILE = "package.json";
11899
+ var PI_LIST_COMMAND = "pi list";
11900
+ var PI_CURRENT_MAJOR = 2;
11896
11901
  var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
11897
11902
  var V1_TMP_PREFIX = "context-mode-";
11898
11903
  var V1_TOML_SECTION_ROOT = "mcp_servers";
@@ -12109,7 +12114,7 @@ var PI_EVENTS = {
12109
12114
  tool_call: { event: "PreToolUse" },
12110
12115
  tool_result: { event: "PostToolUse" }
12111
12116
  };
12112
- var NATIVE_TO_CANONICAL = { bash: "Bash", read: "Read" };
12117
+ var NATIVE_TO_CANONICAL = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
12113
12118
  function record2(v) {
12114
12119
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
12115
12120
  }
@@ -13077,8 +13082,9 @@ var ADAPTERS = Object.freeze([
13077
13082
  installMode: "in-process",
13078
13083
  projectSource: "pi:ctx.cwd",
13079
13084
  toolNamePrefix: TOOL_NAME_PREFIX,
13080
- nativeTools: { shell: ["bash"], read: ["read"] },
13085
+ nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
13081
13086
  execReadOnlyHint: false,
13087
+ // D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
13082
13088
  eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
13083
13089
  compactDelivery: "pi-flag",
13084
13090
  compactSummary: "none",
@@ -14477,21 +14483,21 @@ function kiroDirOf(env, home, platform = process.platform) {
14477
14483
  if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
14478
14484
  if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
14479
14485
  const abs = p.resolve(dir);
14480
- const real2 = platform === process.platform ? realOrSelf : (x) => x;
14481
- const target = real2(abs);
14486
+ const real3 = platform === process.platform ? realOrSelf : (x) => x;
14487
+ const target = real3(abs);
14482
14488
  if (p.parse(target).root === target) return fallback;
14483
- const up = p.relative(target, real2(p.resolve(home)));
14489
+ const up = p.relative(target, real3(p.resolve(home)));
14484
14490
  if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
14485
14491
  return abs;
14486
14492
  }
14487
- function realOrSelf(path7) {
14493
+ function realOrSelf(path8) {
14488
14494
  const tail = [];
14489
- for (let at2 = path7; ; ) {
14495
+ for (let at2 = path8; ; ) {
14490
14496
  try {
14491
14497
  return join(realpathSync.native(at2), ...tail.reverse());
14492
14498
  } catch {
14493
14499
  const up = dirname(at2);
14494
- if (up === at2) return path7;
14500
+ if (up === at2) return path8;
14495
14501
  tail.push(basename(at2));
14496
14502
  at2 = up;
14497
14503
  }
@@ -14616,10 +14622,10 @@ function readPluginAgent(claudeDir, type) {
14616
14622
  }
14617
14623
  return null;
14618
14624
  }
14619
- function readAgentFile(path7) {
14625
+ function readAgentFile(path8) {
14620
14626
  let text;
14621
14627
  try {
14622
- text = readFileSync(path7, "utf8");
14628
+ text = readFileSync(path8, "utf8");
14623
14629
  } catch {
14624
14630
  return null;
14625
14631
  }
@@ -14882,12 +14888,12 @@ function readUserDeny(projectDir, agent) {
14882
14888
  }
14883
14889
  return out;
14884
14890
  }
14885
- function tokenize(glob, path7) {
14891
+ function tokenize(glob, path8) {
14886
14892
  const toks = [];
14887
14893
  let i = 0;
14888
14894
  while (i < glob.length) {
14889
14895
  const c = glob[i];
14890
- if (c === "*" && path7 && glob[i + 1] === "*") {
14896
+ if (c === "*" && path8 && glob[i + 1] === "*") {
14891
14897
  const dir = glob[i + "**".length] === "/";
14892
14898
  toks.push({ t: dir ? "globstarDir" : "globstar" });
14893
14899
  i += dir ? "**/".length : "**".length;
@@ -14901,8 +14907,8 @@ function tokenize(glob, path7) {
14901
14907
  }
14902
14908
  return toks;
14903
14909
  }
14904
- function globMatch(glob, text, path7) {
14905
- const toks = tokenize(glob, path7);
14910
+ function globMatch(glob, text, path8) {
14911
+ const toks = tokenize(glob, path8);
14906
14912
  const n = text.length;
14907
14913
  let next = new Uint8Array(n + 1);
14908
14914
  next[n] = 1;
@@ -14918,10 +14924,10 @@ function globMatch(glob, text, path7) {
14918
14924
  cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
14919
14925
  break;
14920
14926
  case "any1":
14921
- cur[j] = has3 && !(path7 && ch === "/") ? next[j + 1] : 0;
14927
+ cur[j] = has3 && !(path8 && ch === "/") ? next[j + 1] : 0;
14922
14928
  break;
14923
14929
  case "star":
14924
- cur[j] = next[j] || (has3 && !(path7 && ch === "/") ? cur[j + 1] : 0);
14930
+ cur[j] = next[j] || (has3 && !(path8 && ch === "/") ? cur[j + 1] : 0);
14925
14931
  break;
14926
14932
  case "globstar":
14927
14933
  cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
@@ -15001,8 +15007,8 @@ var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limi
15001
15007
  // src/core/policy/read-deny.ts
15002
15008
  var SIZE = "{size}";
15003
15009
  var PATH = "{path}";
15004
- function READ_DENY_MESSAGE(path7, size, prefix = "") {
15005
- return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path7);
15010
+ function READ_DENY_MESSAGE(path8, size, prefix = "") {
15011
+ return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
15006
15012
  }
15007
15013
 
15008
15014
  // src/core/policy/decide.ts
@@ -15710,9 +15716,9 @@ function readUserVersion(raw) {
15710
15716
  const row5 = raw.prepare("PRAGMA user_version").get();
15711
15717
  return row5.user_version;
15712
15718
  }
15713
- function createAtomically(sqlite, path7) {
15719
+ function createAtomically(sqlite, path8) {
15714
15720
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
15715
- const tmp = path7 + "." + randomUUID2() + DB_TMP_SUFFIX;
15721
+ const tmp = path8 + "." + randomUUID2() + DB_TMP_SUFFIX;
15716
15722
  try {
15717
15723
  const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
15718
15724
  try {
@@ -15721,7 +15727,7 @@ function createAtomically(sqlite, path7) {
15721
15727
  raw.close();
15722
15728
  }
15723
15729
  try {
15724
- linkSync(tmp, path7);
15730
+ linkSync(tmp, path8);
15725
15731
  } catch (err) {
15726
15732
  if (err.code !== "EEXIST") throw err;
15727
15733
  }
@@ -15729,11 +15735,11 @@ function createAtomically(sqlite, path7) {
15729
15735
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
15730
15736
  }
15731
15737
  }
15732
- function openWritable(sqlite, path7) {
15738
+ function openWritable(sqlite, path8) {
15733
15739
  let raw = null;
15734
15740
  try {
15735
- if (!existsSync2(path7)) createAtomically(sqlite, path7);
15736
- raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
15741
+ if (!existsSync2(path8)) createAtomically(sqlite, path8);
15742
+ raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
15737
15743
  applyMigrations(raw, readUserVersion(raw));
15738
15744
  return raw;
15739
15745
  } catch (err) {
@@ -15741,8 +15747,8 @@ function openWritable(sqlite, path7) {
15741
15747
  throw err;
15742
15748
  }
15743
15749
  }
15744
- function openReadOnly(sqlite, path7) {
15745
- const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
15750
+ function openReadOnly(sqlite, path8) {
15751
+ const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
15746
15752
  try {
15747
15753
  const found = readUserVersion(raw);
15748
15754
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -15756,20 +15762,20 @@ async function openDb(project, opts) {
15756
15762
  if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
15757
15763
  const sqlite = await loadSqlite();
15758
15764
  mkdirSync2(project.projectDir, { recursive: true });
15759
- const path7 = project.dbPath;
15760
- const sibling = existsSync2(path7 + DB_WAL_SUFFIX) || existsSync2(path7 + DB_SHM_SUFFIX);
15761
- if (sibling && !existsSync2(path7)) {
15765
+ const path8 = project.dbPath;
15766
+ const sibling = existsSync2(path8 + DB_WAL_SUFFIX) || existsSync2(path8 + DB_SHM_SUFFIX);
15767
+ if (sibling && !existsSync2(path8)) {
15762
15768
  throw new CtxError("DB_GONE");
15763
15769
  }
15764
15770
  try {
15765
15771
  let raw;
15766
15772
  if (opts?.readOnly === true) {
15767
- if (!existsSync2(path7)) openWritable(sqlite, path7).close();
15768
- raw = openReadOnly(sqlite, path7);
15773
+ if (!existsSync2(path8)) openWritable(sqlite, path8).close();
15774
+ raw = openReadOnly(sqlite, path8);
15769
15775
  } else {
15770
- raw = openWritable(sqlite, path7);
15776
+ raw = openWritable(sqlite, path8);
15771
15777
  }
15772
- return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
15778
+ return { raw, projectKey: project.projectKey, path: path8, ...opts?.readOnly === true ? { readOnly: true } : {} };
15773
15779
  } catch (err) {
15774
15780
  if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
15775
15781
  throw err;
@@ -18564,8 +18570,8 @@ function buildCandidates(rows, sessionId) {
18564
18570
  edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
18565
18571
  }
18566
18572
  const changedFiles = [];
18567
- for (const [path7, e] of edits) {
18568
- const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
18573
+ for (const [path8, e] of edits) {
18574
+ const c = make("changed_files", e.row, "edited " + path8 + " x" + e.count, e.count, path8);
18569
18575
  changedFiles.push({ ...c, editCount: e.count });
18570
18576
  }
18571
18577
  changedFiles.sort((a, b) => a.seq - b.seq);
@@ -19899,9 +19905,13 @@ async function preToolUse(ev, row5, project, env) {
19899
19905
  const userDeny = readUserDeny(project.worktree, ev.agent);
19900
19906
  const decision0 = decide(ev, row5, userDeny);
19901
19907
  let decision = decision0;
19902
- if (decision0.kind === "deny" && isSubagentCall(ev)) {
19903
- const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
19904
- if (subCase === "B") decision = caseB(ev, row5, decision0, userDeny);
19908
+ if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
19909
+ const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
19910
+ const subCase = pickSubagentCase(ev, set3);
19911
+ const tool = ev.tool;
19912
+ const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
19913
+ if (subCase === "B" && tool !== void 0 && isShell(tool, row5)) decision = caseB(ev, row5, decision0, userDeny);
19914
+ else if (subCase !== "A" && runs) decision = ALLOW2;
19905
19915
  }
19906
19916
  return decision;
19907
19917
  }
@@ -20348,19 +20358,19 @@ function steeringFiles(worktree) {
20348
20358
  function readAutoMemory(project) {
20349
20359
  const rows = [];
20350
20360
  for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
20351
- const path7 = join7(project.worktree, ...segs);
20352
- if (!isInside(project.worktree, path7)) continue;
20361
+ const path8 = join7(project.worktree, ...segs);
20362
+ if (!isInside(project.worktree, path8)) continue;
20353
20363
  try {
20354
- const st = statSync4(path7);
20364
+ const st = statSync4(path8);
20355
20365
  if (!st.isFile()) continue;
20356
20366
  rows.push({
20357
20367
  origin: "memory",
20358
20368
  ts: Math.trunc(st.mtimeMs),
20359
20369
  seq: null,
20360
20370
  sourceId: null,
20361
- path: path7,
20371
+ path: path8,
20362
20372
  label: segs.join("/"),
20363
- text: readFileSync5(path7, "utf8")
20373
+ text: readFileSync5(path8, "utf8")
20364
20374
  });
20365
20375
  } catch {
20366
20376
  }
@@ -20930,7 +20940,7 @@ var ctxBatch = Object.freeze({
20930
20940
  });
20931
20941
 
20932
20942
  // src/core/tools/doctor.ts
20933
- import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as existsSync14 } from "node:fs";
20943
+ import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
20934
20944
  import { basename as basename5, join as join17 } from "node:path";
20935
20945
 
20936
20946
  // src/core/ops/bundle-dir.ts
@@ -20956,7 +20966,7 @@ function ownBundleDir() {
20956
20966
  }
20957
20967
 
20958
20968
  // src/core/ops/doctor-config.ts
20959
- import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
20969
+ import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
20960
20970
  import { join as join12 } from "node:path";
20961
20971
 
20962
20972
  // src/core/ops/detect-v1.ts
@@ -23075,15 +23085,15 @@ function atomicWriteFile(file2, text, opts = {}) {
23075
23085
  }
23076
23086
 
23077
23087
  // src/core/ops/host-config.ts
23078
- function formatOf(path7) {
23079
- if (path7.endsWith(JSONC_EXT)) return "jsonc";
23080
- if (path7.endsWith(TOML_EXT)) return "toml";
23088
+ function formatOf(path8) {
23089
+ if (path8.endsWith(JSONC_EXT)) return "jsonc";
23090
+ if (path8.endsWith(TOML_EXT)) return "toml";
23081
23091
  return "json";
23082
23092
  }
23083
- function readHostConfig(agent, path7) {
23084
- let file2 = path7;
23093
+ function readHostConfig(agent, path8) {
23094
+ let file2 = path8;
23085
23095
  if (agent === "opencode") {
23086
- const jsonc = join9(dirname6(path7), OPENCODE_CONFIG_FILES[0]);
23096
+ const jsonc = join9(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
23087
23097
  if (existsSync4(jsonc)) file2 = jsonc;
23088
23098
  }
23089
23099
  const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
@@ -23247,14 +23257,14 @@ function scanToml(text) {
23247
23257
  continue;
23248
23258
  }
23249
23259
  if (!node3.resolvedKey.every((seg) => typeof seg === "string")) continue;
23250
- const path7 = node3.resolvedKey;
23251
- for (const kv of node3.body) addKey(path7, kv);
23260
+ const path8 = node3.resolvedKey;
23261
+ for (const kv of node3.body) addKey(path8, kv);
23252
23262
  if (node3.kind !== "standard") continue;
23253
23263
  const start = lineStartOf(text, node3.range[0]);
23254
23264
  const headEnd = lineEndOf(text, node3.key.range[1]);
23255
23265
  const last2 = node3.body[node3.body.length - 1];
23256
23266
  tables.push({
23257
- path: path7,
23267
+ path: path8,
23258
23268
  header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
23259
23269
  start,
23260
23270
  end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
@@ -23265,16 +23275,16 @@ function scanToml(text) {
23265
23275
  function tomlTableSpans(text) {
23266
23276
  return scanToml(text).tables;
23267
23277
  }
23268
- function parseHostConfig(agent, path7, text, format) {
23278
+ function parseHostConfig(agent, path8, text, format) {
23269
23279
  try {
23270
23280
  return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
23271
23281
  } catch {
23272
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
23282
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
23273
23283
  }
23274
23284
  }
23275
- function hostConfigValueAt(value, path7) {
23285
+ function hostConfigValueAt(value, path8) {
23276
23286
  let cur = value;
23277
- for (const seg of path7) {
23287
+ for (const seg of path8) {
23278
23288
  if (!isPlainObject3(cur)) return void 0;
23279
23289
  cur = cur[seg];
23280
23290
  }
@@ -23307,32 +23317,32 @@ function indentUnit(root, clean) {
23307
23317
  function render(value, unit, base) {
23308
23318
  return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
23309
23319
  }
23310
- function nest(path7, value) {
23320
+ function nest(path8, value) {
23311
23321
  let out = value;
23312
- for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
23322
+ for (let k = path8.length - 1; k >= 0; k -= 1) out = { [path8[k]]: out };
23313
23323
  return out;
23314
23324
  }
23315
- function setJsonText(text, format, path7, value) {
23325
+ function setJsonText(text, format, path8, value) {
23316
23326
  const doc = scanJson(text, format);
23317
23327
  const unit = indentUnit(doc.root, doc.clean);
23318
- if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
23328
+ if (doc.root === null) return render(nest(path8, value), unit, "") + "\n";
23319
23329
  let node3 = doc.root;
23320
23330
  let depth = 0;
23321
- while (depth < path7.length && node3.kind === "object") {
23322
- const hit = node3.members.find((m) => m.key === path7[depth]);
23331
+ while (depth < path8.length && node3.kind === "object") {
23332
+ const hit = node3.members.find((m) => m.key === path8[depth]);
23323
23333
  if (hit === void 0) break;
23324
23334
  node3 = hit.node;
23325
23335
  depth += 1;
23326
23336
  }
23327
- if (depth === path7.length) {
23337
+ if (depth === path8.length) {
23328
23338
  return text.slice(0, node3.start) + render(value, unit, lineIndent(doc.clean, node3.start)) + text.slice(node3.end);
23329
23339
  }
23330
- if (node3.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
23331
- const rest = nest(path7.slice(depth + 1), value);
23340
+ if (node3.kind !== "object") throw new SyntaxError("not an object at " + path8.slice(0, depth).join("."));
23341
+ const rest = nest(path8.slice(depth + 1), value);
23332
23342
  const last2 = node3.members[node3.members.length - 1];
23333
23343
  if (last2 === void 0) {
23334
23344
  const base2 = lineIndent(doc.clean, node3.start);
23335
- const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
23345
+ const member2 = "\n" + base2 + unit + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
23336
23346
  return text.slice(0, node3.start + 1) + member2 + text.slice(node3.end - 1);
23337
23347
  }
23338
23348
  const base = lineIndent(doc.clean, last2.keyStart);
@@ -23340,7 +23350,7 @@ function setJsonText(text, format, path7, value) {
23340
23350
  while (" \r\n".includes(doc.clean[at2])) at2 += 1;
23341
23351
  const trailing = doc.clean[at2] === ",";
23342
23352
  const insertAt = trailing ? at2 + 1 : last2.node.end;
23343
- const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
23353
+ const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base);
23344
23354
  return text.slice(0, insertAt) + member + text.slice(insertAt);
23345
23355
  }
23346
23356
  function tomlScalar(v) {
@@ -23358,17 +23368,17 @@ function tomlHeaderKey(seg) {
23358
23368
  }
23359
23369
  return seg;
23360
23370
  }
23361
- function tomlBlock(path7, value) {
23362
- let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
23371
+ function tomlBlock(path8, value) {
23372
+ let out = "[" + path8.map(tomlHeaderKey).join(".") + "]\n";
23363
23373
  const subs = [];
23364
23374
  for (const [k, v] of Object.entries(value)) {
23365
- if (isPlainObject3(v)) subs.push(tomlBlock([...path7, k], v));
23375
+ if (isPlainObject3(v)) subs.push(tomlBlock([...path8, k], v));
23366
23376
  else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
23367
23377
  }
23368
23378
  return [out, ...subs].join("\n");
23369
23379
  }
23370
- function under(path7, prefix) {
23371
- return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
23380
+ function under(path8, prefix) {
23381
+ return path8.length >= prefix.length && prefix.every((seg, k) => path8[k] === seg);
23372
23382
  }
23373
23383
  function keyLineRange(text, k) {
23374
23384
  const ls = lineStartOf(text, k.start);
@@ -23385,10 +23395,10 @@ function withValueAt(root, rel, value) {
23385
23395
  else base[rel[0]] = next;
23386
23396
  return base;
23387
23397
  }
23388
- function replaceToml(text, doc, path7, value) {
23389
- const block = value === void 0 ? "" : tomlBlock(path7, value);
23390
- const owned = doc.tables.filter((t) => under(t.path, path7));
23391
- const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
23398
+ function replaceToml(text, doc, path8, value) {
23399
+ const block = value === void 0 ? "" : tomlBlock(path8, value);
23400
+ const owned = doc.tables.filter((t) => under(t.path, path8));
23401
+ const cuts = doc.keys.filter((k) => under(k.full, path8) && !under(k.base, path8)).map((k) => [...keyLineRange(text, k), ""]);
23392
23402
  owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
23393
23403
  cuts.sort((a, b) => b[0] - a[0]);
23394
23404
  let out = text;
@@ -23398,27 +23408,27 @@ function replaceToml(text, doc, path7, value) {
23398
23408
  return out + sep4 + block;
23399
23409
  }
23400
23410
  var tableLike = (v) => v === void 0 || isPlainObject3(v);
23401
- function setTomlText(text, path7, value) {
23411
+ function setTomlText(text, path8, value) {
23402
23412
  if (value !== void 0 && !isPlainObject3(value)) throw new SyntaxError("TOML edits replace a whole table");
23403
23413
  const doc = scanToml(text);
23404
- const cur = hostConfigValueAt(doc.value, path7);
23414
+ const cur = hostConfigValueAt(doc.value, path8);
23405
23415
  if (sameValue(cur, value)) return text;
23406
- const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
23416
+ const inline = doc.keys.find((k) => k.inline && k.full.length < path8.length && under(path8, k.full));
23407
23417
  if (inline !== void 0) {
23408
- const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
23418
+ const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path8.slice(inline.full.length), value);
23409
23419
  return replaceToml(text, doc, inline.full, whole2);
23410
23420
  }
23411
23421
  if (isPlainObject3(cur) && isPlainObject3(value)) {
23412
23422
  const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
23413
23423
  if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
23414
23424
  let out = text;
23415
- for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
23425
+ for (const k of names) out = setTomlText(out, [...path8, k], value[k]);
23416
23426
  return out;
23417
23427
  }
23418
23428
  }
23419
- return replaceToml(text, doc, path7, value);
23429
+ return replaceToml(text, doc, path8, value);
23420
23430
  }
23421
- function setText(agent, path7, text, format, key, value) {
23431
+ function setText(agent, path8, text, format, key, value) {
23422
23432
  try {
23423
23433
  if (format !== "toml") return setJsonText(text, format, key, value);
23424
23434
  const out = setTomlText(text, key, value);
@@ -23427,7 +23437,7 @@ function setText(agent, path7, text, format, key, value) {
23427
23437
  if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
23428
23438
  return out;
23429
23439
  } catch {
23430
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
23440
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
23431
23441
  }
23432
23442
  }
23433
23443
  function serverScript() {
@@ -23474,14 +23484,14 @@ function ownTargets(agent, accept) {
23474
23484
  if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
23475
23485
  return [];
23476
23486
  }
23477
- function applyEdits(agent, path7, text, format, wanted) {
23478
- const parsed = parseHostConfig(agent, path7, text, format);
23487
+ function applyEdits(agent, path8, text, format, wanted) {
23488
+ const parsed = parseHostConfig(agent, path8, text, format);
23479
23489
  let out = text;
23480
23490
  const edits = [];
23481
23491
  for (const [key, after] of wanted) {
23482
23492
  const before = hostConfigValueAt(parsed, key);
23483
23493
  if (sameValue(before, after)) continue;
23484
- out = setText(agent, path7, out, format, key, after);
23494
+ out = setText(agent, path8, out, format, key, after);
23485
23495
  edits.push({ path: key.join("."), before, after });
23486
23496
  }
23487
23497
  return { text: out, format, edits };
@@ -23502,7 +23512,7 @@ function writeHostConfigEdit(_requested, current, patch) {
23502
23512
  // src/core/ops/detect-v1.ts
23503
23513
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23504
23514
  var keyPath = (...parts) => parts.join(".");
23505
- var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
23515
+ var finding = (file2, path8, reason) => ({ file: file2, path: path8, reason });
23506
23516
  function stripJsonc(text) {
23507
23517
  let out = "";
23508
23518
  let inStr = false;
@@ -23707,12 +23717,17 @@ function scanKiro(agentHome, project, out) {
23707
23717
  }
23708
23718
  dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23709
23719
  }
23720
+ function piNpmIsCurrent(piAgentDir) {
23721
+ const doc = readJson(join10(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
23722
+ const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
23723
+ return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
23724
+ }
23710
23725
  function scanPi(piAgentDir, agentHome, out) {
23711
23726
  const file2 = join10(piAgentDir, SETTINGS_FILE);
23712
23727
  const doc = readJson(file2);
23713
23728
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
23714
23729
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
23715
- if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
23730
+ if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
23716
23731
  });
23717
23732
  dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23718
23733
  }
@@ -23809,8 +23824,8 @@ function detectV1(agent, home, scope = {}) {
23809
23824
  import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23810
23825
  import { dirname as dirname7, isAbsolute as isAbsolute2, join as join11, sep as sep3 } from "node:path";
23811
23826
  import { fileURLToPath as fileURLToPath2 } from "node:url";
23812
- function missing(agent, path7) {
23813
- return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
23827
+ function missing(agent, path8) {
23828
+ return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
23814
23829
  }
23815
23830
  var parseOrNull = (text) => {
23816
23831
  try {
@@ -23839,9 +23854,9 @@ function recordedInstalls(text) {
23839
23854
  }
23840
23855
  return out;
23841
23856
  }
23842
- var realOrNull = (path7) => {
23857
+ var realOrNull = (path8) => {
23843
23858
  try {
23844
- return realpathSync4.native(path7);
23859
+ return realpathSync4.native(path8);
23845
23860
  } catch {
23846
23861
  return null;
23847
23862
  }
@@ -23939,14 +23954,83 @@ function candidate(adapter, env, worktree) {
23939
23954
  }
23940
23955
  }
23941
23956
  function resolvePluginRoot(adapter, env, worktree) {
23942
- const path7 = candidate(adapter, env, worktree);
23957
+ const path8 = candidate(adapter, env, worktree);
23943
23958
  try {
23944
- return realpathSync4.native(path7);
23959
+ return realpathSync4.native(path8);
23945
23960
  } catch {
23946
- throw missing(adapter.id, path7);
23961
+ throw missing(adapter.id, path8);
23947
23962
  }
23948
23963
  }
23949
23964
 
23965
+ // src/setup/pi-gate.ts
23966
+ import { existsSync as existsSync7, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
23967
+ import path4 from "node:path";
23968
+ var EXTENSIONS_KEY = "extensions";
23969
+ var PROJECT_DIR = ".pi";
23970
+ var TRUST_FILE = "trust.json";
23971
+ var ALWAYS = "always";
23972
+ var SOURCE_PREFIXES = ["npm:", "git:"];
23973
+ function load(file2) {
23974
+ if (!existsSync7(file2)) return void 0;
23975
+ try {
23976
+ return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync9(file2, "utf8")), "json") };
23977
+ } catch {
23978
+ return void 0;
23979
+ }
23980
+ }
23981
+ var real2 = (p) => {
23982
+ try {
23983
+ return realpathSync5(p);
23984
+ } catch {
23985
+ return path4.resolve(p);
23986
+ }
23987
+ };
23988
+ function sourceName(source) {
23989
+ let s = source;
23990
+ for (const p of SOURCE_PREFIXES) if (s.startsWith(p)) s = s.slice(p.length);
23991
+ const last2 = s.split("/").pop() ?? "";
23992
+ const at2 = last2.indexOf("@", 1);
23993
+ const name = at2 > 0 ? last2.slice(0, at2) : last2;
23994
+ return name.endsWith(".git") ? name.slice(0, -4) : name;
23995
+ }
23996
+ function isOwn(source, pkgDir) {
23997
+ if (typeof source !== "string") return false;
23998
+ return real2(source) === real2(pkgDir) || sourceName(source) === SERVER_KEY;
23999
+ }
24000
+ function ownEntries(src, pkgDir) {
24001
+ const list4 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
24002
+ if (!Array.isArray(list4)) return [];
24003
+ const out = [];
24004
+ for (const e of list4) {
24005
+ const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
24006
+ if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
24007
+ const ext = obj?.[EXTENSIONS_KEY];
24008
+ out.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x) => typeof x === "string") : void 0 });
24009
+ }
24010
+ return out;
24011
+ }
24012
+ function projectTrusted(agentDir, userDoc, cwd) {
24013
+ const trust = load(path4.join(agentDir, TRUST_FILE));
24014
+ const entries = /* @__PURE__ */ new Map();
24015
+ if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real2(k), v);
24016
+ let dir = real2(cwd);
24017
+ for (; ; ) {
24018
+ const v = entries.get(dir);
24019
+ if (v === true || v === false) return v;
24020
+ const up = path4.dirname(dir);
24021
+ if (up === dir) break;
24022
+ dir = up;
24023
+ }
24024
+ return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
24025
+ }
24026
+ function piInstalledIn(env, home, pkgDir, cwd) {
24027
+ const agentDir = piAgentDirOf(env, home);
24028
+ const user = load(path4.join(agentDir, SETTINGS_FILE));
24029
+ const project = load(path4.join(cwd, PROJECT_DIR, SETTINGS_FILE));
24030
+ if (project && projectTrusted(agentDir, user?.doc, cwd) && ownEntries(project, pkgDir).length > 0) return project.file;
24031
+ return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
24032
+ }
24033
+
23950
24034
  // src/core/ops/doctor-config.ts
23951
24035
  var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
23952
24036
  var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
@@ -24047,14 +24131,14 @@ function codexNativeDir(env, home) {
24047
24131
  }
24048
24132
  if (enabled !== true) return null;
24049
24133
  const cache = join12(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
24050
- if (!existsSync7(cache)) return null;
24134
+ if (!existsSync8(cache)) return null;
24051
24135
  const found = [];
24052
24136
  for (const market of readdirSync4(cache)) {
24053
24137
  const plugin = join12(cache, market, SERVER_KEY);
24054
- if (!existsSync7(plugin)) continue;
24138
+ if (!existsSync8(plugin)) continue;
24055
24139
  for (const version4 of readdirSync4(plugin).sort()) {
24056
24140
  const dir = join12(plugin, version4, CODEX_PLUGIN_SUBDIR);
24057
- if (existsSync7(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24141
+ if (existsSync8(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24058
24142
  }
24059
24143
  }
24060
24144
  return found.length === 0 ? null : found[found.length - 1];
@@ -24145,12 +24229,17 @@ function checkHostConfig(row5, env, worktree) {
24145
24229
  const choice = marketplaceChoice(env, worktree);
24146
24230
  if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
24147
24231
  }
24232
+ if (row5.id === "pi") return checkPiInstall(env, home, worktree);
24148
24233
  const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
24149
- const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
24150
- if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
24234
+ if (parts.length === 0) return pass("D3");
24151
24235
  const detail = D3_DETAIL(parts);
24152
24236
  const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
24153
- return fail2("D3", read3 === null ? detail : detail + D4_REASON_JOIN + read3, fix);
24237
+ return fail2("D3", detail, fix);
24238
+ }
24239
+ function checkPiInstall(env, home, worktree) {
24240
+ const found = piInstalledIn(env, home, ownBundleDir(), worktree);
24241
+ if (found !== void 0) return { ...pass("D3"), detail: found };
24242
+ return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join12(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
24154
24243
  }
24155
24244
  function checkV1Leftovers(agent, home, scope = {}) {
24156
24245
  const findings = detectV1(agent, home, scope);
@@ -24203,7 +24292,7 @@ function configPaths(row5, env, worktree) {
24203
24292
  }
24204
24293
 
24205
24294
  // src/core/ops/doctor-db.ts
24206
- import { existsSync as existsSync8, statSync as statSync5 } from "node:fs";
24295
+ import { existsSync as existsSync9, statSync as statSync5 } from "node:fs";
24207
24296
  var unknown2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
24208
24297
  var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
24209
24298
  var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -24222,8 +24311,8 @@ async function loadSqlite2() {
24222
24311
  return null;
24223
24312
  }
24224
24313
  }
24225
- function openRead(sqlite, path7) {
24226
- return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
24314
+ function openRead(sqlite, path8) {
24315
+ return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
24227
24316
  }
24228
24317
  var cell = (row5) => Object.values(row5)[0];
24229
24318
  function readSchema(raw) {
@@ -24244,16 +24333,16 @@ function failsOnCorrupt(step) {
24244
24333
  function orphanFiles(dbPath) {
24245
24334
  const files = [];
24246
24335
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
24247
- const path7 = dbPath + suffix;
24248
- if (existsSync8(path7)) files.push({ path: path7, bytes: statSync5(path7).size });
24336
+ const path8 = dbPath + suffix;
24337
+ if (existsSync9(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
24249
24338
  }
24250
- return files.length > 0 && !existsSync8(dbPath) ? files : [];
24339
+ return files.length > 0 && !existsSync9(dbPath) ? files : [];
24251
24340
  }
24252
24341
  async function checkDb(project) {
24253
24342
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
24254
24343
  const orphan = orphanFiles(project.dbPath);
24255
24344
  if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
24256
- if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24345
+ if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24257
24346
  const sqlite = await loadSqlite2();
24258
24347
  if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
24259
24348
  let raw = null;
@@ -24279,7 +24368,7 @@ async function checkDb(project) {
24279
24368
  }
24280
24369
  }
24281
24370
  async function checkIndex(project) {
24282
- if (!existsSync8(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24371
+ if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24283
24372
  const sqlite = await loadSqlite2();
24284
24373
  if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
24285
24374
  let raw = null;
@@ -24296,7 +24385,7 @@ async function checkIndex(project) {
24296
24385
  }
24297
24386
 
24298
24387
  // src/core/ops/doctor-env.ts
24299
- import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
24388
+ import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
24300
24389
  import { isAbsolute as isAbsolute3, join as join13, relative as relative2 } from "node:path";
24301
24390
  function pass3(id, detail = DOCTOR_PASS_DETAIL) {
24302
24391
  return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
@@ -24309,7 +24398,7 @@ function fail4(id, detail, fixCommand) {
24309
24398
  }
24310
24399
  function bundleVersion(bundleDir2) {
24311
24400
  try {
24312
- const v = JSON.parse(readFileSync9(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24401
+ const v = JSON.parse(readFileSync10(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24313
24402
  return typeof v === "string" && v !== "" ? v : void 0;
24314
24403
  } catch {
24315
24404
  return void 0;
@@ -24459,8 +24548,8 @@ function checkMcp(ctx) {
24459
24548
  return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
24460
24549
  }
24461
24550
  function piCwdInside(worktree, piCwd) {
24462
- if (piCwd === void 0 || !existsSync9(piCwd)) return false;
24463
- const rel = relative2(worktree, realpathSync5.native(piCwd));
24551
+ if (piCwd === void 0 || !existsSync10(piCwd)) return false;
24552
+ const rel = relative2(worktree, realpathSync6.native(piCwd));
24464
24553
  return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
24465
24554
  }
24466
24555
  function checkProject(i) {
@@ -24480,20 +24569,20 @@ function checkShell(env) {
24480
24569
  }
24481
24570
 
24482
24571
  // src/core/ops/doctor-hook.ts
24483
- import { existsSync as existsSync11, mkdtempSync, readFileSync as readFileSync10, realpathSync as realpathSync7, rmSync as rmSync2 } from "node:fs";
24572
+ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2 } from "node:fs";
24484
24573
  import { tmpdir as tmpdir2 } from "node:os";
24485
- import path6 from "node:path";
24574
+ import path7 from "node:path";
24486
24575
 
24487
24576
  // src/setup/codex-trust.ts
24488
24577
  import { createHash } from "node:crypto";
24489
- import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
24490
- import path5 from "node:path";
24578
+ import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
24579
+ import path6 from "node:path";
24491
24580
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
24492
24581
 
24493
24582
  // src/setup/spawn-bin.ts
24494
24583
  import { spawnSync } from "node:child_process";
24495
24584
  import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
24496
- import path4 from "node:path";
24585
+ import path5 from "node:path";
24497
24586
  var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
24498
24587
  var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
24499
24588
  var DEFAULT_COMSPEC = "cmd.exe";
@@ -24504,10 +24593,10 @@ function whichBin(bin, env, platform = process.platform) {
24504
24593
  const get = (k) => envGet(env, k);
24505
24594
  const win = platform === "win32";
24506
24595
  const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
24507
- const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
24596
+ const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
24508
24597
  for (const dir of pathEntries(get("PATH") ?? "", platform)) {
24509
24598
  for (const n of names) {
24510
- const f = path4.join(dir, n);
24599
+ const f = path5.join(dir, n);
24511
24600
  try {
24512
24601
  accessSync2(f, fsc.X_OK);
24513
24602
  if (statSync6(f).isFile()) return f;
@@ -24548,7 +24637,7 @@ function winCmdLine(file2, args, env = {}) {
24548
24637
  return `"${[file2, ...args].map(q).join(" ")}"`;
24549
24638
  }
24550
24639
  function spawnForm(file2, args, env, platform = process.platform) {
24551
- if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
24640
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
24552
24641
  return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
24553
24642
  }
24554
24643
  return { command: file2, args, windowsVerbatimArguments: false };
@@ -24572,10 +24661,10 @@ function codexHomeFromReply(out) {
24572
24661
  return void 0;
24573
24662
  }
24574
24663
  function sameDir(a, b, platform = process.platform) {
24575
- if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
24664
+ if (platform !== "win32") return path6.posix.normalize(a) === path6.posix.normalize(b);
24576
24665
  const norm2 = (p) => {
24577
24666
  const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
24578
- const n = path5.win32.normalize(bare2).toLowerCase();
24667
+ const n = path6.win32.normalize(bare2).toLowerCase();
24579
24668
  return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
24580
24669
  };
24581
24670
  return norm2(a) === norm2(b);
@@ -24708,11 +24797,11 @@ function isObject5(v) {
24708
24797
  return typeof v === "object" && v !== null && !Array.isArray(v);
24709
24798
  }
24710
24799
  function loadFixture(bundleDir2, agent) {
24711
- const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
24712
- if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24800
+ const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
24801
+ if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24713
24802
  let all;
24714
24803
  try {
24715
- all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
24804
+ all = JSON.parse(hostText(readFileSync11(file2, "utf8")));
24716
24805
  } catch (err) {
24717
24806
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
24718
24807
  }
@@ -24774,7 +24863,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
24774
24863
  var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
24775
24864
  function readProbePayload(cwd) {
24776
24865
  const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
24777
- const filePath = path6.join(cwd, "d5-read-probe.txt");
24866
+ const filePath = path7.join(cwd, "d5-read-probe.txt");
24778
24867
  return {
24779
24868
  session_id: "d5-read-probe",
24780
24869
  transcript_path: "",
@@ -24801,9 +24890,9 @@ function isReadShape(stdout) {
24801
24890
  return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
24802
24891
  }
24803
24892
  async function readProbeOk(i, timeoutMs) {
24804
- const home = mkdtempSync(path6.join(tmpdir2(), "cm-d5-read-"));
24893
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
24805
24894
  try {
24806
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24895
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24807
24896
  cwd: i.bundleDir,
24808
24897
  env: { ...i.env, HOME: home, USERPROFILE: home },
24809
24898
  signal: i.signal,
@@ -24821,7 +24910,7 @@ function codexHookJournaled(db) {
24821
24910
  }
24822
24911
  function realDir(p) {
24823
24912
  try {
24824
- return realpathSync7(p);
24913
+ return realpathSync8(p);
24825
24914
  } catch {
24826
24915
  return p;
24827
24916
  }
@@ -24848,7 +24937,7 @@ async function checkHookRoundTrip(i) {
24848
24937
  const trust = await codexPluginTrust(i);
24849
24938
  if (trust !== null) return trust;
24850
24939
  }
24851
- if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24940
+ if (i.agent === "codex" && existsSync12(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24852
24941
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
24853
24942
  }
24854
24943
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -24868,7 +24957,7 @@ async function checkHookRoundTrip(i) {
24868
24957
  let ms = 0;
24869
24958
  for (let n = 1; n <= maxPairs; n++) {
24870
24959
  const start = now();
24871
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24960
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24872
24961
  cwd: i.bundleDir,
24873
24962
  env: i.env,
24874
24963
  signal: i.signal,
@@ -24887,11 +24976,11 @@ async function checkHookRoundTrip(i) {
24887
24976
  }
24888
24977
 
24889
24978
  // src/core/ops/db-heal.ts
24890
- import { existsSync as existsSync12, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
24979
+ import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
24891
24980
  import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
24892
24981
 
24893
24982
  // src/core/store/owners.ts
24894
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync11, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
24983
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
24895
24984
  import { basename as basename3, join as join14 } from "node:path";
24896
24985
  function ownersDir(configDir, projectKey) {
24897
24986
  return join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
@@ -24935,7 +25024,7 @@ function listLiveOwners(configDir, projectKey) {
24935
25024
  const file2 = join14(dir, name);
24936
25025
  let text;
24937
25026
  try {
24938
- text = readFileSync11(file2, "utf8");
25027
+ text = readFileSync12(file2, "utf8");
24939
25028
  } catch (err) {
24940
25029
  if (errCode2(err) === "ENOENT") continue;
24941
25030
  throw err;
@@ -24981,7 +25070,7 @@ function renameAside(dbPath) {
24981
25070
  const ts = String(Date.now());
24982
25071
  for (const suffix of DB_SIBLING_SUFFIXES) {
24983
25072
  const file2 = dbPath + suffix;
24984
- if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
25073
+ if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
24985
25074
  }
24986
25075
  return ts;
24987
25076
  }
@@ -25088,7 +25177,7 @@ function buildReportHead(input) {
25088
25177
 
25089
25178
  // src/core/ops/doctor-issue.ts
25090
25179
  import { spawnSync as spawnSync3 } from "node:child_process";
25091
- import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
25180
+ import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
25092
25181
  import { delimiter, join as join16 } from "node:path";
25093
25182
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
25094
25183
  function tildeOf(env) {
@@ -25096,8 +25185,8 @@ function tildeOf(env) {
25096
25185
  if (home === null || home === "") return (t) => t;
25097
25186
  const homes = [home];
25098
25187
  try {
25099
- const real2 = realpathSync8.native(home);
25100
- if (real2 !== home) homes.push(real2);
25188
+ const real3 = realpathSync9.native(home);
25189
+ if (real3 !== home) homes.push(real3);
25101
25190
  } catch {
25102
25191
  }
25103
25192
  homes.sort((a, b) => b.length - a.length);
@@ -25130,7 +25219,7 @@ function onPath(env, tool) {
25130
25219
  const out = [];
25131
25220
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
25132
25221
  if (dir === "") continue;
25133
- for (const n of names) if (existsSync13(join16(dir, n))) {
25222
+ for (const n of names) if (existsSync14(join16(dir, n))) {
25134
25223
  out.push(join16(dir, n));
25135
25224
  break;
25136
25225
  }
@@ -25139,7 +25228,7 @@ function onPath(env, tool) {
25139
25228
  }
25140
25229
  function hookLogTail(env) {
25141
25230
  const file2 = hookLogPath(env);
25142
- if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25231
+ if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25143
25232
  try {
25144
25233
  const fd = openSync(file2, "r");
25145
25234
  try {
@@ -25159,7 +25248,7 @@ function hookLogTail(env) {
25159
25248
  }
25160
25249
  async function journalRows(ctx) {
25161
25250
  const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
25162
- if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25251
+ if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25163
25252
  try {
25164
25253
  const db = await openDb(ctx.project, { readOnly: true });
25165
25254
  try {
@@ -25185,13 +25274,13 @@ function agentConfig(adapter, env, worktree) {
25185
25274
  for (const f of files) {
25186
25275
  if (seen.has(f.path)) continue;
25187
25276
  seen.add(f.path);
25188
- if (!existsSync13(f.path)) {
25277
+ if (!existsSync14(f.path)) {
25189
25278
  out.push(`${f.label}: ${f.path} (absent)`);
25190
25279
  continue;
25191
25280
  }
25192
25281
  let text = "";
25193
25282
  try {
25194
- text = readFileSync12(f.path, "utf8");
25283
+ text = readFileSync13(f.path, "utf8");
25195
25284
  } catch (err) {
25196
25285
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
25197
25286
  continue;
@@ -25290,7 +25379,7 @@ async function guard(id, run) {
25290
25379
  }
25291
25380
  }
25292
25381
  async function codexDb(ctx, adapter) {
25293
- if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
25382
+ if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
25294
25383
  try {
25295
25384
  return await openDb(ctx.project, { readOnly: true });
25296
25385
  } catch {
@@ -25321,10 +25410,10 @@ async function hookRow(ctx, adapter, host) {
25321
25410
  }
25322
25411
  function ownServerId(configDir, projectKey) {
25323
25412
  const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
25324
- if (!existsSync14(dir)) return "";
25413
+ if (!existsSync15(dir)) return "";
25325
25414
  for (const name of readdirSync6(dir)) {
25326
25415
  if (!name.endsWith(OWNER_PID_EXT)) continue;
25327
- if (readFileSync13(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25416
+ if (readFileSync14(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25328
25417
  }
25329
25418
  return "";
25330
25419
  }
@@ -25380,7 +25469,7 @@ async function doctorReply(ctx, host) {
25380
25469
  const adapter = getAdapter(ctx.project.agent);
25381
25470
  const rows = await runDoctorChecks(ctx, adapter, host);
25382
25471
  const failed2 = rows.some((r) => r.status === "FAIL");
25383
- const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
25472
+ const command = adapter.id === "pi" ? failed2 ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
25384
25473
  const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
25385
25474
  const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
25386
25475
  const table3 = buildReport(input);
@@ -25407,7 +25496,7 @@ async function doctorReply(ctx, host) {
25407
25496
  return { text, isError: false, sandboxBytes: bytes5 };
25408
25497
  }
25409
25498
  async function handler2(_input, ctx) {
25410
- return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: void 0 });
25499
+ return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
25411
25500
  }
25412
25501
  var ctxDoctor = Object.freeze({
25413
25502
  name: "ctx_doctor",
@@ -25419,7 +25508,7 @@ var ctxDoctor = Object.freeze({
25419
25508
  });
25420
25509
 
25421
25510
  // src/core/tools/execute.ts
25422
- import { existsSync as existsSync15, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
25511
+ import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
25423
25512
  import { tmpdir as tmpdir3 } from "node:os";
25424
25513
  import { dirname as dirname10, join as join18, parse as parse3, resolve as resolve6 } from "node:path";
25425
25514
 
@@ -25505,7 +25594,7 @@ function schemaLine(issue4) {
25505
25594
  }
25506
25595
  function fileError(given, abs, root) {
25507
25596
  let dir = abs;
25508
- while (!existsSync15(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
25597
+ while (!existsSync16(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
25509
25598
  if (isInside(root, dir)) return null;
25510
25599
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
25511
25600
  }
@@ -25622,19 +25711,19 @@ var ctxExecute = {
25622
25711
  };
25623
25712
 
25624
25713
  // src/core/tools/index.ts
25625
- import { existsSync as existsSync16, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
25714
+ import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
25626
25715
  import { dirname as dirname11, extname, join as join20, relative as relative3, resolve as resolve7 } from "node:path";
25627
25716
 
25628
25717
  // src/core/index/walk.ts
25629
- import { readdirSync as readdirSync7, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
25718
+ import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
25630
25719
  import { join as join19 } from "node:path";
25631
25720
  var GITIGNORE = ".gitignore";
25632
25721
  var GIT_DIR = ".git";
25633
25722
  function walkDir(root, containmentRoot) {
25634
- const real2 = realpathSync9(root);
25635
- if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
25723
+ const real3 = realpathSync10(root);
25724
+ if (!isInside(containmentRoot, real3)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
25636
25725
  const found = [];
25637
- visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
25726
+ visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
25638
25727
  found.sort(compareFound);
25639
25728
  return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
25640
25729
  }
@@ -25648,14 +25737,14 @@ function visit(abs, rel, parent, contain, seen, found) {
25648
25737
  const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
25649
25738
  for (const e of entries) {
25650
25739
  if (e.name === GIT_DIR) continue;
25651
- const path7 = join19(abs, e.name);
25740
+ const path8 = join19(abs, e.name);
25652
25741
  let isDir = e.isDirectory();
25653
25742
  let isFile = e.isFile();
25654
- let target = path7;
25743
+ let target = path8;
25655
25744
  if (e.isSymbolicLink()) {
25656
25745
  let resolved;
25657
25746
  try {
25658
- resolved = realpathSync9(path7);
25747
+ resolved = realpathSync10(path8);
25659
25748
  } catch {
25660
25749
  continue;
25661
25750
  }
@@ -25668,12 +25757,12 @@ function visit(abs, rel, parent, contain, seen, found) {
25668
25757
  const segs = rel.concat(e.name);
25669
25758
  if (ignored(rules, segs, isDir)) continue;
25670
25759
  if (isFile) {
25671
- found.push({ dir: rel, name: e.name, absPath: path7 });
25760
+ found.push({ dir: rel, name: e.name, absPath: path8 });
25672
25761
  } else if (isDir) {
25673
- const key = e.isSymbolicLink() ? target : realpathSync9(path7);
25762
+ const key = e.isSymbolicLink() ? target : realpathSync10(path8);
25674
25763
  if (seen.has(key)) continue;
25675
25764
  seen.add(key);
25676
- visit(path7, segs, rules, contain, seen, found);
25765
+ visit(path8, segs, rules, contain, seen, found);
25677
25766
  }
25678
25767
  }
25679
25768
  }
@@ -25688,7 +25777,7 @@ function compareFound(a, b) {
25688
25777
  function readRules(file2, base) {
25689
25778
  let body;
25690
25779
  try {
25691
- body = readFileSync14(file2, "utf8");
25780
+ body = readFileSync15(file2, "utf8");
25692
25781
  } catch {
25693
25782
  return [];
25694
25783
  }
@@ -25864,12 +25953,12 @@ function tlsName(host) {
25864
25953
  function request(u, conn, proxy, signal) {
25865
25954
  const host = bare(u.hostname);
25866
25955
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
25867
- const path7 = u.pathname + u.search;
25956
+ const path8 = u.pathname + u.search;
25868
25957
  return new Promise((resolve8, reject) => {
25869
25958
  const onErr = (err) => reject(fail6(causeCode(err)));
25870
25959
  if (proxy === void 0) {
25871
25960
  const mod = u.protocol === "https:" ? https : http;
25872
- const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
25961
+ const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
25873
25962
  req.on("response", resolve8).on("error", onErr).end();
25874
25963
  return;
25875
25964
  }
@@ -25891,7 +25980,7 @@ function request(u, conn, proxy, signal) {
25891
25980
  const req = https.request({
25892
25981
  host,
25893
25982
  port,
25894
- path: path7,
25983
+ path: path8,
25895
25984
  signal,
25896
25985
  headers: { host: u.host },
25897
25986
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
@@ -29771,14 +29860,14 @@ function kindOfType(contentType) {
29771
29860
  }
29772
29861
  function readUtf8(absPath) {
29773
29862
  try {
29774
- return utf8.decode(readFileSync15(absPath));
29863
+ return utf8.decode(readFileSync16(absPath));
29775
29864
  } catch {
29776
29865
  return void 0;
29777
29866
  }
29778
29867
  }
29779
29868
  function missingOrOutside(given, abs, root) {
29780
29869
  let dir = abs;
29781
- while (!existsSync16(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
29870
+ while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
29782
29871
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
29783
29872
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
29784
29873
  }
@@ -30329,11 +30418,11 @@ var ctxStats = Object.freeze({
30329
30418
  });
30330
30419
 
30331
30420
  // src/core/tools/upgrade.ts
30332
- import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
30421
+ import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
30333
30422
  import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
30334
30423
 
30335
30424
  // src/core/ops/host-write.ts
30336
- import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30425
+ import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30337
30426
  import { dirname as dirname12, join as join21 } from "node:path";
30338
30427
  function defaultWrite(file2, text) {
30339
30428
  writeFileSync5(file2, text, "utf8");
@@ -30362,7 +30451,7 @@ function toRow(file2, edit) {
30362
30451
  function writeWithRollback(file2, text, write2, atomic) {
30363
30452
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
30364
30453
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
30365
- const had = existsSync17(file2);
30454
+ const had = existsSync18(file2);
30366
30455
  mkdirSync7(dirname12(file2), { recursive: true });
30367
30456
  if (had) copyFileSync(file2, trash);
30368
30457
  try {
@@ -30392,7 +30481,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
30392
30481
  if (requested === null) return [];
30393
30482
  const current = readHostConfig(row5.id, requested);
30394
30483
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
30395
- const exists = existsSync17(current.path);
30484
+ const exists = existsSync18(current.path);
30396
30485
  if (exists && result.text === current.text) return [];
30397
30486
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
30398
30487
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -30400,15 +30489,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
30400
30489
  }
30401
30490
 
30402
30491
  // src/core/ops/plugin-swap.ts
30403
- import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30492
+ import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30404
30493
  import { basename as basename6, join as join22, win32 as win322 } from "node:path";
30405
- function linkTarget(path7, win) {
30406
- if (!isLink(path7)) return null;
30407
- const target = readlinkSync(path7);
30494
+ function linkTarget(path8, win) {
30495
+ if (!isLink(path8)) return null;
30496
+ const target = readlinkSync(path8);
30408
30497
  return win ? win322.basename(target) : target;
30409
30498
  }
30410
- function isLink(path7) {
30411
- return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
30499
+ function isLink(path8) {
30500
+ return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
30412
30501
  }
30413
30502
  function generations(agentDir) {
30414
30503
  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();
@@ -30421,7 +30510,7 @@ function settleLinks(link, tmp, old, opts) {
30421
30510
  }
30422
30511
  function swapPluginCurrent(agentDir, sha, opts = {}) {
30423
30512
  const next = join22(agentDir, sha);
30424
- if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
30513
+ if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
30425
30514
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
30426
30515
  }
30427
30516
  const link = join22(agentDir, PLUGIN_CURRENT_LINK);
@@ -30441,12 +30530,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
30441
30530
  if (before !== null) keep.add(before);
30442
30531
  const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
30443
30532
  for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
30444
- const previous = before !== null && existsSync18(join22(agentDir, before)) ? join22(agentDir, before) : null;
30533
+ const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
30445
30534
  return { current: next, previous, removed };
30446
30535
  }
30447
30536
 
30448
30537
  // src/core/ops/release-fetch.ts
30449
- import { existsSync as existsSync19, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
30538
+ import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
30450
30539
  import { join as join23 } from "node:path";
30451
30540
  function failed(r) {
30452
30541
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -30470,7 +30559,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
30470
30559
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
30471
30560
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
30472
30561
  const dir = join23(agentDir, sha);
30473
- if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
30562
+ if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
30474
30563
  else renameWithRetry(fetchDir, dir, opts);
30475
30564
  return { sha, dir };
30476
30565
  } catch (e) {
@@ -30480,7 +30569,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
30480
30569
  }
30481
30570
 
30482
30571
  // src/core/ops/uninstall.ts
30483
- import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
30572
+ import { existsSync as existsSync21, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
30484
30573
  import { join as join24 } from "node:path";
30485
30574
  function row2(area, before, after) {
30486
30575
  return { area, before, after };
@@ -30514,7 +30603,7 @@ function removeCache(adapter, env, configDir) {
30514
30603
  }
30515
30604
  case "plugin": {
30516
30605
  const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
30517
- if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30606
+ if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30518
30607
  rmSync8(agentDir, { recursive: true, force: true });
30519
30608
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
30520
30609
  }
@@ -30533,7 +30622,7 @@ function isObj3(v) {
30533
30622
  function piSource(entry) {
30534
30623
  return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
30535
30624
  }
30536
- function ownEntries(agent, env) {
30625
+ function ownEntries2(agent, env) {
30537
30626
  const home = requireHomeDir(env);
30538
30627
  const mcp = OWN_MCP_ENTRY[agent];
30539
30628
  if (mcp !== void 0) {
@@ -30541,10 +30630,10 @@ function ownEntries(agent, env) {
30541
30630
  const inner = mcp.key.slice(1, -1);
30542
30631
  const own4 = mcp.key[mcp.key.length - 1];
30543
30632
  const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
30544
- const without = (v, path7) => {
30633
+ const without = (v, path8) => {
30545
30634
  const o = v;
30546
- if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
30547
- return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
30635
+ if (path8.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
30636
+ return { ...o, [path8[0]]: without(o[path8[0]], path8.slice(1)) };
30548
30637
  };
30549
30638
  return [{
30550
30639
  file: ownMcpFileOf(agent, mcp.file, env, home),
@@ -30581,7 +30670,7 @@ function ownEntries(agent, env) {
30581
30670
  }
30582
30671
  function removeOwnEntries(agent, env) {
30583
30672
  const rows = [];
30584
- for (const entry of ownEntries(agent, env)) {
30673
+ for (const entry of ownEntries2(agent, env)) {
30585
30674
  const current = readHostConfig(agent, entry.file);
30586
30675
  if (current.text === "") continue;
30587
30676
  const value = hostConfigValueAt(parseHostConfig(agent, current.path, current.text, current.format), [entry.key]);
@@ -30594,7 +30683,7 @@ function removeOwnEntries(agent, env) {
30594
30683
  function removeProjectData(configDir, projectKey) {
30595
30684
  const projects = join24(configDir, PROJECTS_DIR_NAME);
30596
30685
  const dir = join24(projects, projectKey);
30597
- if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30686
+ if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30598
30687
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
30599
30688
  for (const name of readdirSync9(dir)) {
30600
30689
  if (name !== OWNERS_DIR_NAME) rmSync8(join24(dir, name), { recursive: true, force: true });
@@ -30610,7 +30699,7 @@ function runUninstall(input) {
30610
30699
  }
30611
30700
 
30612
30701
  // src/core/ops/v1-remove.ts
30613
- import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync16, rmSync as rmSync9 } from "node:fs";
30702
+ import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync17, rmSync as rmSync9 } from "node:fs";
30614
30703
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
30615
30704
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
30616
30705
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -30640,8 +30729,8 @@ function cutTomlTable(text, header) {
30640
30729
  function writeAtomic(file2, text) {
30641
30730
  atomicWriteFile(file2, text);
30642
30731
  }
30643
- function locate(doc, path7) {
30644
- const segs = path7.split(V1_KEY_PATH_SEP);
30732
+ function locate(doc, path8) {
30733
+ const segs = path8.split(V1_KEY_PATH_SEP);
30645
30734
  let cur = doc;
30646
30735
  for (const seg of segs.slice(0, -1)) {
30647
30736
  if (Array.isArray(cur)) cur = cur[Number(seg)];
@@ -30654,8 +30743,8 @@ function locate(doc, path7) {
30654
30743
  return null;
30655
30744
  }
30656
30745
  function stripJsonEntries(agent, file2, findings, kept, undo) {
30657
- const layout = hostLayout(readFileSync16(file2, "utf8"));
30658
- const text = hostText(readFileSync16(file2, "utf8"));
30746
+ const layout = hostLayout(readFileSync17(file2, "utf8"));
30747
+ const text = hostText(readFileSync17(file2, "utf8"));
30659
30748
  const doc = parseHostConfig(agent, file2, text, "jsonc");
30660
30749
  const hit = /* @__PURE__ */ new Set();
30661
30750
  const byContainer = /* @__PURE__ */ new Map();
@@ -30691,19 +30780,19 @@ function removeV1(agent, findings) {
30691
30780
  for (const f of findings) {
30692
30781
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
30693
30782
  else if (f.path === "") {
30694
- if (existsSync21(f.file)) {
30783
+ if (existsSync22(f.file)) {
30695
30784
  moveAside(f.file, undo);
30696
30785
  done.set(f, UPGRADE_REMOVED);
30697
30786
  } else done.set(f, UPGRADE_NOT_FOUND);
30698
30787
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
30699
30788
  }
30700
30789
  for (const [file2, list4] of entries) {
30701
- if (!existsSync21(file2)) {
30790
+ if (!existsSync22(file2)) {
30702
30791
  for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
30703
30792
  continue;
30704
30793
  }
30705
30794
  if (file2.endsWith(TOML_EXT)) {
30706
- const rawToml = readFileSync16(file2, "utf8");
30795
+ const rawToml = readFileSync17(file2, "utf8");
30707
30796
  const tomlLayout = hostLayout(rawToml);
30708
30797
  let text = hostText(rawToml);
30709
30798
  for (const f of list4) {
@@ -30731,7 +30820,7 @@ function removeV1(agent, findings) {
30731
30820
  },
30732
30821
  rollback() {
30733
30822
  for (const u of undo.splice(0).reverse()) {
30734
- if (!existsSync21(u.trash)) continue;
30823
+ if (!existsSync22(u.trash)) continue;
30735
30824
  rmSync9(u.target, { recursive: true, force: true });
30736
30825
  renameWithRetry(u.trash, u.target);
30737
30826
  }
@@ -30741,7 +30830,7 @@ function removeV1(agent, findings) {
30741
30830
 
30742
30831
  // src/core/ops/verify-sums.ts
30743
30832
  import { createHash as createHash2 } from "node:crypto";
30744
- import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync17 } from "node:fs";
30833
+ import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
30745
30834
  import { join as join25 } from "node:path";
30746
30835
  function mismatch() {
30747
30836
  return new CtxError("BUNDLE_HASH_MISMATCH");
@@ -30773,14 +30862,14 @@ function verifySums(dir) {
30773
30862
  const sumsPath = join25(dir, RELEASE_SUMS_FILE);
30774
30863
  const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
30775
30864
  if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
30776
- const sums = parseSums(readFileSync17(sumsPath, "utf8"));
30865
+ const sums = parseSums(readFileSync18(sumsPath, "utf8"));
30777
30866
  const files = /* @__PURE__ */ new Map();
30778
30867
  walk3(dir, "", files);
30779
30868
  if (files.size !== sums.size) throw mismatch();
30780
30869
  for (const [rel, abs] of files) {
30781
30870
  const want = sums.get(rel);
30782
30871
  if (want === void 0) throw mismatch();
30783
- const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync17(abs)).digest(HASH_ENCODING);
30872
+ const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
30784
30873
  if (got !== want) throw mismatch();
30785
30874
  }
30786
30875
  }
@@ -30809,7 +30898,7 @@ function pluginRootRow(adapter, env) {
30809
30898
  }
30810
30899
  function isCurrent(agentDir, dir) {
30811
30900
  const link = join26(agentDir, PLUGIN_CURRENT_LINK);
30812
- return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
30901
+ return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
30813
30902
  }
30814
30903
  async function checkout(adapter, deps) {
30815
30904
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
@@ -30929,7 +31018,7 @@ function checkCall(tool, input) {
30929
31018
 
30930
31019
  // src/entries/server.ts
30931
31020
  import { randomUUID } from "node:crypto";
30932
- import { existsSync as existsSync24, realpathSync as realpathSync12, rmSync as rmSync12 } from "node:fs";
31021
+ import { existsSync as existsSync25, realpathSync as realpathSync13, rmSync as rmSync12 } from "node:fs";
30933
31022
  import { dirname as dirname14, join as join28 } from "node:path";
30934
31023
  import { fileURLToPath as fileURLToPath3 } from "node:url";
30935
31024
 
@@ -31227,10 +31316,10 @@ function mergeDefs(...defs) {
31227
31316
  function cloneDef(schema) {
31228
31317
  return mergeDefs(schema._zod.def);
31229
31318
  }
31230
- function getElementAtPath2(obj, path7) {
31231
- if (!path7)
31319
+ function getElementAtPath2(obj, path8) {
31320
+ if (!path8)
31232
31321
  return obj;
31233
- return path7.reduce((acc, key) => acc?.[key], obj);
31322
+ return path8.reduce((acc, key) => acc?.[key], obj);
31234
31323
  }
31235
31324
  function promiseAllObject2(promisesObj) {
31236
31325
  const keys = Object.keys(promisesObj);
@@ -31570,11 +31659,11 @@ function explicitlyAborted(x, startIndex = 0) {
31570
31659
  }
31571
31660
  return false;
31572
31661
  }
31573
- function prefixIssues2(path7, issues) {
31662
+ function prefixIssues2(path8, issues) {
31574
31663
  return issues.map((iss) => {
31575
31664
  var _a5;
31576
31665
  (_a5 = iss).path ?? (_a5.path = []);
31577
- iss.path.unshift(path7);
31666
+ iss.path.unshift(path8);
31578
31667
  return iss;
31579
31668
  });
31580
31669
  }
@@ -32035,16 +32124,16 @@ function flattenError2(error42, mapper = (issue4) => issue4.message) {
32035
32124
  }
32036
32125
  function formatError3(error42, mapper = (issue4) => issue4.message) {
32037
32126
  const fieldErrors = { _errors: [] };
32038
- const processError = (error43, path7 = []) => {
32127
+ const processError = (error43, path8 = []) => {
32039
32128
  for (const issue4 of error43.issues) {
32040
32129
  if (issue4.code === "invalid_union" && issue4.errors.length) {
32041
- issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
32130
+ issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
32042
32131
  } else if (issue4.code === "invalid_key") {
32043
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
32132
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
32044
32133
  } else if (issue4.code === "invalid_element") {
32045
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
32134
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
32046
32135
  } else {
32047
- const fullpath = [...path7, ...issue4.path];
32136
+ const fullpath = [...path8, ...issue4.path];
32048
32137
  if (fullpath.length === 0) {
32049
32138
  fieldErrors._errors.push(mapper(issue4));
32050
32139
  } else {
@@ -38808,10 +38897,10 @@ function mergeDefs2(...defs) {
38808
38897
  function cloneDef2(schema) {
38809
38898
  return mergeDefs2(schema._zod.def);
38810
38899
  }
38811
- function getElementAtPath3(obj, path7) {
38812
- if (!path7)
38900
+ function getElementAtPath3(obj, path8) {
38901
+ if (!path8)
38813
38902
  return obj;
38814
- return path7.reduce((acc, key) => acc?.[key], obj);
38903
+ return path8.reduce((acc, key) => acc?.[key], obj);
38815
38904
  }
38816
38905
  function promiseAllObject3(promisesObj) {
38817
38906
  const keys = Object.keys(promisesObj);
@@ -39151,11 +39240,11 @@ function explicitlyAborted2(x, startIndex = 0) {
39151
39240
  }
39152
39241
  return false;
39153
39242
  }
39154
- function prefixIssues3(path7, issues) {
39243
+ function prefixIssues3(path8, issues) {
39155
39244
  return issues.map((iss) => {
39156
39245
  var _a5;
39157
39246
  (_a5 = iss).path ?? (_a5.path = []);
39158
- iss.path.unshift(path7);
39247
+ iss.path.unshift(path8);
39159
39248
  return iss;
39160
39249
  });
39161
39250
  }
@@ -39613,16 +39702,16 @@ function flattenError3(error42, mapper = (issue4) => issue4.message) {
39613
39702
  }
39614
39703
  function formatError4(error42, mapper = (issue4) => issue4.message) {
39615
39704
  const fieldErrors = { _errors: [] };
39616
- const processError = (error43, path7 = []) => {
39705
+ const processError = (error43, path8 = []) => {
39617
39706
  for (const issue4 of error43.issues) {
39618
39707
  if (issue4.code === "invalid_union" && issue4.errors.length) {
39619
- issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
39708
+ issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
39620
39709
  } else if (issue4.code === "invalid_key") {
39621
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
39710
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
39622
39711
  } else if (issue4.code === "invalid_element") {
39623
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
39712
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
39624
39713
  } else {
39625
- const fullpath = [...path7, ...issue4.path];
39714
+ const fullpath = [...path8, ...issue4.path];
39626
39715
  if (fullpath.length === 0) {
39627
39716
  fieldErrors._errors.push(mapper(issue4));
39628
39717
  } else {
@@ -47838,9 +47927,9 @@ var rev2026Codec = {
47838
47927
  });
47839
47928
  const parsed = buildSchemas2026().RequestMetaEnvelopeSchema.safeParse(meta3);
47840
47929
  if (!parsed.success) for (const issue4 of parsed.error.issues) {
47841
- const path7 = issue4.path.map(String);
47842
- const key = path7.length > 0 ? path7.join(".") : "_meta";
47843
- if (path7.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
47930
+ const path8 = issue4.path.map(String);
47931
+ const key = path8.length > 0 ? path8.join(".") : "_meta";
47932
+ if (path8.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
47844
47933
  issues.push({
47845
47934
  key,
47846
47935
  problem: issue4.message
@@ -48167,29 +48256,29 @@ var PERMITTED_X_MCP_HEADER_TYPES = /* @__PURE__ */ new Set([
48167
48256
  function scanXMcpHeaderDeclarations(inputSchema) {
48168
48257
  const declarations = [];
48169
48258
  const seenLower = /* @__PURE__ */ new Map();
48170
- const visit2 = (node3, path7, reachable) => {
48259
+ const visit2 = (node3, path8, reachable) => {
48171
48260
  if (node3 === null || typeof node3 !== "object") return void 0;
48172
48261
  const schema = node3;
48173
48262
  if (X_MCP_HEADER_KEY in schema) {
48174
- if (!reachable || path7.length === 0) return `${pathName(path7)}: x-mcp-header is only permitted on properties statically reachable via a chain of 'properties' keys (not under items, additionalProperties, oneOf/anyOf/allOf/not, if/then/else, or $ref)`;
48263
+ if (!reachable || path8.length === 0) return `${pathName(path8)}: x-mcp-header is only permitted on properties statically reachable via a chain of 'properties' keys (not under items, additionalProperties, oneOf/anyOf/allOf/not, if/then/else, or $ref)`;
48175
48264
  const raw = schema[X_MCP_HEADER_KEY];
48176
- if (typeof raw !== "string" || raw.length === 0) return `${pathName(path7)}: x-mcp-header MUST be a non-empty string`;
48177
- if (!RFC9110_TOKEN.test(raw)) return `${pathName(path7)}: x-mcp-header '${raw}' is not a valid RFC 9110 token (no spaces, control characters or HTTP delimiters)`;
48265
+ if (typeof raw !== "string" || raw.length === 0) return `${pathName(path8)}: x-mcp-header MUST be a non-empty string`;
48266
+ if (!RFC9110_TOKEN.test(raw)) return `${pathName(path8)}: x-mcp-header '${raw}' is not a valid RFC 9110 token (no spaces, control characters or HTTP delimiters)`;
48178
48267
  const type = typeof schema.type === "string" ? schema.type : void 0;
48179
- if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(path7)}: x-mcp-header is only permitted on primitive-typed properties (string, integer, boolean); got ${type ?? "<none>"}`;
48268
+ if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(path8)}: x-mcp-header is only permitted on primitive-typed properties (string, integer, boolean); got ${type ?? "<none>"}`;
48180
48269
  const lower = raw.toLowerCase();
48181
48270
  const prior = seenLower.get(lower);
48182
48271
  if (prior !== void 0) return `x-mcp-header '${raw}' is not case-insensitively unique (also declared as '${prior}')`;
48183
48272
  seenLower.set(lower, raw);
48184
48273
  declarations.push({
48185
- path: path7,
48274
+ path: path8,
48186
48275
  headerName: raw,
48187
48276
  type
48188
48277
  });
48189
48278
  }
48190
48279
  const properties = schema.properties;
48191
48280
  if (properties !== null && typeof properties === "object") for (const [key, child] of Object.entries(properties)) {
48192
- const fault$1 = visit2(child, [...path7, key], reachable);
48281
+ const fault$1 = visit2(child, [...path8, key], reachable);
48193
48282
  if (fault$1 !== void 0) return fault$1;
48194
48283
  }
48195
48284
  for (const k of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
@@ -48197,7 +48286,7 @@ function scanXMcpHeaderDeclarations(inputSchema) {
48197
48286
  if (sub === void 0) continue;
48198
48287
  const branches = Array.isArray(sub) ? sub : sub !== null && typeof sub === "object" && OBJECT_VALUED_SUBSCHEMA_KEYWORDS.has(k) ? Object.values(sub) : [sub];
48199
48288
  for (const branch of branches) {
48200
- const fault$1 = visit2(branch, [...path7, `<${k}>`], false);
48289
+ const fault$1 = visit2(branch, [...path8, `<${k}>`], false);
48201
48290
  if (fault$1 !== void 0) return fault$1;
48202
48291
  }
48203
48292
  }
@@ -48237,8 +48326,8 @@ var OBJECT_VALUED_SUBSCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
48237
48326
  "$defs",
48238
48327
  "definitions"
48239
48328
  ]);
48240
- function pathName(path7) {
48241
- return path7.length === 0 ? "<root>" : path7.join(".");
48329
+ function pathName(path8) {
48330
+ return path8.length === 0 ? "<root>" : path8.join(".");
48242
48331
  }
48243
48332
  var HEADER_MISMATCH_ERROR_CODE = -32020;
48244
48333
  var INBOUND_VALIDATION_LADDER = [
@@ -48527,7 +48616,7 @@ var PROPERTY_KEYS_BY_TYPE = {
48527
48616
  array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
48528
48617
  };
48529
48618
  var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
48530
- function walkProperty(node3, path7, vendor, unsupported) {
48619
+ function walkProperty(node3, path8, vendor, unsupported) {
48531
48620
  if (!isJsonObject(node3)) return node3;
48532
48621
  const allowedKeys = typeof node3.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node3.type) ? PROPERTY_KEYS_BY_TYPE[node3.type] : void 0;
48533
48622
  if (allowedKeys === void 0) return node3;
@@ -48535,8 +48624,8 @@ function walkProperty(node3, path7, vendor, unsupported) {
48535
48624
  for (const [key, value] of Object.entries(node3)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
48536
48625
  else if (key === "pattern" && node3.type === "string" && typeof node3.format === "string") {
48537
48626
  if (!SUPPORTED_STRING_FORMATS.has(node3.format)) pruned[key] = value;
48538
- else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path7}.${key}`);
48539
- } else unsupported.push(`${path7}.${key}`);
48627
+ else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path8}.${key}`);
48628
+ } else unsupported.push(`${path8}.${key}`);
48540
48629
  return pruned;
48541
48630
  }
48542
48631
  function walkRequestedSchema(converted, vendor) {
@@ -48553,11 +48642,11 @@ function describeUnsupportedProperties(pruned, fallback) {
48553
48642
  const offenders = Object.entries(pruned.properties).filter(([, node3]) => !parseSchema(PrimitiveSchemaDefinitionSchema, node3).success).map(([name]) => `properties.${name}`);
48554
48643
  return offenders.length > 0 ? offenders.join(", ") : fallback;
48555
48644
  }
48556
- function findDroppedConstraintPaths(original, parsed, path7 = "") {
48557
- if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path7}[${index}]`));
48645
+ function findDroppedConstraintPaths(original, parsed, path8 = "") {
48646
+ if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path8}[${index}]`));
48558
48647
  if (!isJsonObject(original) || !isJsonObject(parsed)) return [];
48559
48648
  return Object.entries(original).flatMap(([key, value]) => {
48560
- const childPath = path7 ? `${path7}.${key}` : key;
48649
+ const childPath = path8 ? `${path8}.${key}` : key;
48561
48650
  if (!Object.prototype.hasOwnProperty.call(parsed, key)) return isAnnotationOnlyJsonSchemaKeyword(key) ? [] : [childPath];
48562
48651
  return findDroppedConstraintPaths(value, parsed[key], childPath);
48563
48652
  });
@@ -52645,8 +52734,8 @@ var require_utils = /* @__PURE__ */ __commonJSMin((exports, module) => {
52645
52734
  for (let i = 0; i < str4.length; i++) if (str4[i] === token) ind++;
52646
52735
  return ind;
52647
52736
  }
52648
- function removeDotSegments(path7) {
52649
- let input = path7;
52737
+ function removeDotSegments(path8) {
52738
+ let input = path8;
52650
52739
  const output = [];
52651
52740
  let nextSlash = -1;
52652
52741
  let len = 0;
@@ -52799,8 +52888,8 @@ var require_schemes = /* @__PURE__ */ __commonJSMin((exports, module) => {
52799
52888
  wsComponent.secure = void 0;
52800
52889
  }
52801
52890
  if (wsComponent.resourceName) {
52802
- const [path7, query] = wsComponent.resourceName.split("?");
52803
- wsComponent.path = path7 && path7 !== "/" ? path7 : void 0;
52891
+ const [path8, query] = wsComponent.resourceName.split("?");
52892
+ wsComponent.path = path8 && path8 !== "/" ? path8 : void 0;
52804
52893
  wsComponent.query = query;
52805
52894
  wsComponent.resourceName = void 0;
52806
52895
  }
@@ -58995,7 +59084,7 @@ function installExitGuard(opts) {
58995
59084
  }
58996
59085
 
58997
59086
  // src/core/store/cleanup.ts
58998
- import { existsSync as existsSync23, readdirSync as readdirSync11, rmSync as rmSync11 } from "node:fs";
59087
+ import { existsSync as existsSync24, readdirSync as readdirSync11, rmSync as rmSync11 } from "node:fs";
58999
59088
  import { join as join27 } from "node:path";
59000
59089
  function deleteSource(raw, id) {
59001
59090
  raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
@@ -59031,7 +59120,7 @@ function userVersion(raw) {
59031
59120
  return raw.prepare("PRAGMA user_version").get().user_version;
59032
59121
  }
59033
59122
  function openForSweep(dbPath, projectKey) {
59034
- if (!existsSync23(dbPath) && (existsSync23(dbPath + DB_WAL_SUFFIX) || existsSync23(dbPath + DB_SHM_SUFFIX))) {
59123
+ if (!existsSync24(dbPath) && (existsSync24(dbPath + DB_WAL_SUFFIX) || existsSync24(dbPath + DB_SHM_SUFFIX))) {
59035
59124
  throw new CtxError("DB_GONE");
59036
59125
  }
59037
59126
  const sqlite = process.getBuiltinModule("node:sqlite");
@@ -59085,12 +59174,12 @@ function sweepDeadProjects(configDir) {
59085
59174
  }
59086
59175
 
59087
59176
  // src/entries/is-entry.ts
59088
- import { realpathSync as realpathSync11 } from "node:fs";
59177
+ import { realpathSync as realpathSync12 } from "node:fs";
59089
59178
  function isEntry(main, argv1, self) {
59090
59179
  if (main !== void 0) return main;
59091
59180
  if (argv1 === void 0 || argv1 === "") return false;
59092
59181
  try {
59093
- return realpathSync11(argv1) === realpathSync11(self);
59182
+ return realpathSync12(argv1) === realpathSync12(self);
59094
59183
  } catch {
59095
59184
  return false;
59096
59185
  }
@@ -59166,7 +59255,7 @@ function workspaceFromMeta(meta3) {
59166
59255
  }
59167
59256
  function realOrSame(p) {
59168
59257
  try {
59169
- return realpathSync12.native(p);
59258
+ return realpathSync13.native(p);
59170
59259
  } catch {
59171
59260
  return p;
59172
59261
  }
@@ -59214,7 +59303,7 @@ async function startServer(argv, env) {
59214
59303
  opening.catch(() => pending.delete(project.dbPath));
59215
59304
  }
59216
59305
  const db = await opening;
59217
- if (!existsSync24(db.path)) throw new CtxError("DB_GONE");
59306
+ if (!existsSync25(db.path)) throw new CtxError("DB_GONE");
59218
59307
  return db;
59219
59308
  }
59220
59309
  function stopMarker(configDir, projectKey) {
@@ -59222,7 +59311,7 @@ async function startServer(argv, env) {
59222
59311
  }
59223
59312
  function stopRequested() {
59224
59313
  const configDir = resolveConfigDir(process.env);
59225
- return held.some((db) => existsSync24(stopMarker(configDir, db.projectKey)));
59314
+ return held.some((db) => existsSync25(stopMarker(configDir, db.projectKey)));
59226
59315
  }
59227
59316
  async function journal(project, ctx, name, reply4) {
59228
59317
  const db = await ownDb(project);
@@ -59384,7 +59473,9 @@ function piExtension(pi) {
59384
59473
  turn,
59385
59474
  // #1182: Pi's abort signal reaches the handler, which kills the process tree and replies "Cancelled.".
59386
59475
  signal: signal ?? new AbortController().signal,
59387
- protocolVersion: ""
59476
+ protocolVersion: "",
59477
+ piCwd: cwd === "" ? void 0 : cwd
59478
+ // D-R38-PI-D7-1 (#1312): ctx_doctor D7 compares against Pi's live ctx.cwd
59388
59479
  };
59389
59480
  let reply4;
59390
59481
  try {