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/server.mjs CHANGED
@@ -7,7 +7,7 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/entries/server.ts
9
9
  import { randomUUID } from "node:crypto";
10
- import { existsSync as existsSync24, realpathSync as realpathSync12, rmSync as rmSync12 } from "node:fs";
10
+ import { existsSync as existsSync25, realpathSync as realpathSync13, rmSync as rmSync12 } from "node:fs";
11
11
  import { dirname as dirname13, join as join25 } from "node:path";
12
12
  import { fileURLToPath as fileURLToPath3 } from "node:url";
13
13
 
@@ -305,10 +305,10 @@ function mergeDefs(...defs) {
305
305
  function cloneDef(schema) {
306
306
  return mergeDefs(schema._zod.def);
307
307
  }
308
- function getElementAtPath(obj, path7) {
309
- if (!path7)
308
+ function getElementAtPath(obj, path8) {
309
+ if (!path8)
310
310
  return obj;
311
- return path7.reduce((acc, key) => acc?.[key], obj);
311
+ return path8.reduce((acc, key) => acc?.[key], obj);
312
312
  }
313
313
  function promiseAllObject(promisesObj) {
314
314
  const keys = Object.keys(promisesObj);
@@ -648,11 +648,11 @@ function explicitlyAborted(x, startIndex = 0) {
648
648
  }
649
649
  return false;
650
650
  }
651
- function prefixIssues(path7, issues) {
651
+ function prefixIssues(path8, issues) {
652
652
  return issues.map((iss) => {
653
653
  var _a5;
654
654
  (_a5 = iss).path ?? (_a5.path = []);
655
- iss.path.unshift(path7);
655
+ iss.path.unshift(path8);
656
656
  return iss;
657
657
  });
658
658
  }
@@ -1113,16 +1113,16 @@ function flattenError(error42, mapper = (issue4) => issue4.message) {
1113
1113
  }
1114
1114
  function formatError(error42, mapper = (issue4) => issue4.message) {
1115
1115
  const fieldErrors = { _errors: [] };
1116
- const processError = (error43, path7 = []) => {
1116
+ const processError = (error43, path8 = []) => {
1117
1117
  for (const issue4 of error43.issues) {
1118
1118
  if (issue4.code === "invalid_union" && issue4.errors.length) {
1119
- issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
1119
+ issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
1120
1120
  } else if (issue4.code === "invalid_key") {
1121
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
1121
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
1122
1122
  } else if (issue4.code === "invalid_element") {
1123
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
1123
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
1124
1124
  } else {
1125
- const fullpath = [...path7, ...issue4.path];
1125
+ const fullpath = [...path8, ...issue4.path];
1126
1126
  if (fullpath.length === 0) {
1127
1127
  fieldErrors._errors.push(mapper(issue4));
1128
1128
  } else {
@@ -7886,10 +7886,10 @@ function mergeDefs2(...defs) {
7886
7886
  function cloneDef2(schema) {
7887
7887
  return mergeDefs2(schema._zod.def);
7888
7888
  }
7889
- function getElementAtPath2(obj, path7) {
7890
- if (!path7)
7889
+ function getElementAtPath2(obj, path8) {
7890
+ if (!path8)
7891
7891
  return obj;
7892
- return path7.reduce((acc, key) => acc?.[key], obj);
7892
+ return path8.reduce((acc, key) => acc?.[key], obj);
7893
7893
  }
7894
7894
  function promiseAllObject2(promisesObj) {
7895
7895
  const keys = Object.keys(promisesObj);
@@ -8229,11 +8229,11 @@ function explicitlyAborted2(x, startIndex = 0) {
8229
8229
  }
8230
8230
  return false;
8231
8231
  }
8232
- function prefixIssues2(path7, issues) {
8232
+ function prefixIssues2(path8, issues) {
8233
8233
  return issues.map((iss) => {
8234
8234
  var _a5;
8235
8235
  (_a5 = iss).path ?? (_a5.path = []);
8236
- iss.path.unshift(path7);
8236
+ iss.path.unshift(path8);
8237
8237
  return iss;
8238
8238
  });
8239
8239
  }
@@ -8691,16 +8691,16 @@ function flattenError2(error42, mapper = (issue4) => issue4.message) {
8691
8691
  }
8692
8692
  function formatError2(error42, mapper = (issue4) => issue4.message) {
8693
8693
  const fieldErrors = { _errors: [] };
8694
- const processError = (error43, path7 = []) => {
8694
+ const processError = (error43, path8 = []) => {
8695
8695
  for (const issue4 of error43.issues) {
8696
8696
  if (issue4.code === "invalid_union" && issue4.errors.length) {
8697
- issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
8697
+ issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
8698
8698
  } else if (issue4.code === "invalid_key") {
8699
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
8699
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
8700
8700
  } else if (issue4.code === "invalid_element") {
8701
- processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
8701
+ processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
8702
8702
  } else {
8703
- const fullpath = [...path7, ...issue4.path];
8703
+ const fullpath = [...path8, ...issue4.path];
8704
8704
  if (fullpath.length === 0) {
8705
8705
  fieldErrors._errors.push(mapper(issue4));
8706
8706
  } else {
@@ -16916,9 +16916,9 @@ var rev2026Codec = {
16916
16916
  });
16917
16917
  const parsed = buildSchemas2026().RequestMetaEnvelopeSchema.safeParse(meta3);
16918
16918
  if (!parsed.success) for (const issue4 of parsed.error.issues) {
16919
- const path7 = issue4.path.map(String);
16920
- const key = path7.length > 0 ? path7.join(".") : "_meta";
16921
- if (path7.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
16919
+ const path8 = issue4.path.map(String);
16920
+ const key = path8.length > 0 ? path8.join(".") : "_meta";
16921
+ if (path8.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
16922
16922
  issues.push({
16923
16923
  key,
16924
16924
  problem: issue4.message
@@ -17245,29 +17245,29 @@ var PERMITTED_X_MCP_HEADER_TYPES = /* @__PURE__ */ new Set([
17245
17245
  function scanXMcpHeaderDeclarations(inputSchema) {
17246
17246
  const declarations = [];
17247
17247
  const seenLower = /* @__PURE__ */ new Map();
17248
- const visit2 = (node3, path7, reachable) => {
17248
+ const visit2 = (node3, path8, reachable) => {
17249
17249
  if (node3 === null || typeof node3 !== "object") return void 0;
17250
17250
  const schema = node3;
17251
17251
  if (X_MCP_HEADER_KEY in schema) {
17252
- 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)`;
17252
+ 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)`;
17253
17253
  const raw = schema[X_MCP_HEADER_KEY];
17254
- if (typeof raw !== "string" || raw.length === 0) return `${pathName(path7)}: x-mcp-header MUST be a non-empty string`;
17255
- 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)`;
17254
+ if (typeof raw !== "string" || raw.length === 0) return `${pathName(path8)}: x-mcp-header MUST be a non-empty string`;
17255
+ 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)`;
17256
17256
  const type = typeof schema.type === "string" ? schema.type : void 0;
17257
- 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>"}`;
17257
+ 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>"}`;
17258
17258
  const lower = raw.toLowerCase();
17259
17259
  const prior = seenLower.get(lower);
17260
17260
  if (prior !== void 0) return `x-mcp-header '${raw}' is not case-insensitively unique (also declared as '${prior}')`;
17261
17261
  seenLower.set(lower, raw);
17262
17262
  declarations.push({
17263
- path: path7,
17263
+ path: path8,
17264
17264
  headerName: raw,
17265
17265
  type
17266
17266
  });
17267
17267
  }
17268
17268
  const properties = schema.properties;
17269
17269
  if (properties !== null && typeof properties === "object") for (const [key, child] of Object.entries(properties)) {
17270
- const fault$1 = visit2(child, [...path7, key], reachable);
17270
+ const fault$1 = visit2(child, [...path8, key], reachable);
17271
17271
  if (fault$1 !== void 0) return fault$1;
17272
17272
  }
17273
17273
  for (const k of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
@@ -17275,7 +17275,7 @@ function scanXMcpHeaderDeclarations(inputSchema) {
17275
17275
  if (sub === void 0) continue;
17276
17276
  const branches = Array.isArray(sub) ? sub : sub !== null && typeof sub === "object" && OBJECT_VALUED_SUBSCHEMA_KEYWORDS.has(k) ? Object.values(sub) : [sub];
17277
17277
  for (const branch of branches) {
17278
- const fault$1 = visit2(branch, [...path7, `<${k}>`], false);
17278
+ const fault$1 = visit2(branch, [...path8, `<${k}>`], false);
17279
17279
  if (fault$1 !== void 0) return fault$1;
17280
17280
  }
17281
17281
  }
@@ -17315,8 +17315,8 @@ var OBJECT_VALUED_SUBSCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
17315
17315
  "$defs",
17316
17316
  "definitions"
17317
17317
  ]);
17318
- function pathName(path7) {
17319
- return path7.length === 0 ? "<root>" : path7.join(".");
17318
+ function pathName(path8) {
17319
+ return path8.length === 0 ? "<root>" : path8.join(".");
17320
17320
  }
17321
17321
  var HEADER_MISMATCH_ERROR_CODE = -32020;
17322
17322
  var INBOUND_VALIDATION_LADDER = [
@@ -17605,7 +17605,7 @@ var PROPERTY_KEYS_BY_TYPE = {
17605
17605
  array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
17606
17606
  };
17607
17607
  var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
17608
- function walkProperty(node3, path7, vendor, unsupported) {
17608
+ function walkProperty(node3, path8, vendor, unsupported) {
17609
17609
  if (!isJsonObject(node3)) return node3;
17610
17610
  const allowedKeys = typeof node3.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node3.type) ? PROPERTY_KEYS_BY_TYPE[node3.type] : void 0;
17611
17611
  if (allowedKeys === void 0) return node3;
@@ -17613,8 +17613,8 @@ function walkProperty(node3, path7, vendor, unsupported) {
17613
17613
  for (const [key, value] of Object.entries(node3)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
17614
17614
  else if (key === "pattern" && node3.type === "string" && typeof node3.format === "string") {
17615
17615
  if (!SUPPORTED_STRING_FORMATS.has(node3.format)) pruned[key] = value;
17616
- else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path7}.${key}`);
17617
- } else unsupported.push(`${path7}.${key}`);
17616
+ else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path8}.${key}`);
17617
+ } else unsupported.push(`${path8}.${key}`);
17618
17618
  return pruned;
17619
17619
  }
17620
17620
  function walkRequestedSchema(converted, vendor) {
@@ -17631,11 +17631,11 @@ function describeUnsupportedProperties(pruned, fallback) {
17631
17631
  const offenders = Object.entries(pruned.properties).filter(([, node3]) => !parseSchema(PrimitiveSchemaDefinitionSchema, node3).success).map(([name]) => `properties.${name}`);
17632
17632
  return offenders.length > 0 ? offenders.join(", ") : fallback;
17633
17633
  }
17634
- function findDroppedConstraintPaths(original, parsed, path7 = "") {
17635
- if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path7}[${index}]`));
17634
+ function findDroppedConstraintPaths(original, parsed, path8 = "") {
17635
+ if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path8}[${index}]`));
17636
17636
  if (!isJsonObject(original) || !isJsonObject(parsed)) return [];
17637
17637
  return Object.entries(original).flatMap(([key, value]) => {
17638
- const childPath = path7 ? `${path7}.${key}` : key;
17638
+ const childPath = path8 ? `${path8}.${key}` : key;
17639
17639
  if (!Object.prototype.hasOwnProperty.call(parsed, key)) return isAnnotationOnlyJsonSchemaKeyword(key) ? [] : [childPath];
17640
17640
  return findDroppedConstraintPaths(value, parsed[key], childPath);
17641
17641
  });
@@ -21723,8 +21723,8 @@ var require_utils = /* @__PURE__ */ __commonJSMin((exports, module) => {
21723
21723
  for (let i = 0; i < str.length; i++) if (str[i] === token) ind++;
21724
21724
  return ind;
21725
21725
  }
21726
- function removeDotSegments(path7) {
21727
- let input = path7;
21726
+ function removeDotSegments(path8) {
21727
+ let input = path8;
21728
21728
  const output = [];
21729
21729
  let nextSlash = -1;
21730
21730
  let len = 0;
@@ -21877,8 +21877,8 @@ var require_schemes = /* @__PURE__ */ __commonJSMin((exports, module) => {
21877
21877
  wsComponent.secure = void 0;
21878
21878
  }
21879
21879
  if (wsComponent.resourceName) {
21880
- const [path7, query] = wsComponent.resourceName.split("?");
21881
- wsComponent.path = path7 && path7 !== "/" ? path7 : void 0;
21880
+ const [path8, query] = wsComponent.resourceName.split("?");
21881
+ wsComponent.path = path8 && path8 !== "/" ? path8 : void 0;
21882
21882
  wsComponent.query = query;
21883
21883
  wsComponent.resourceName = void 0;
21884
21884
  }
@@ -28407,7 +28407,7 @@ var DECISION_SOURCE = "decision";
28407
28407
  var DECISION_USER_LABEL = "decision (user)";
28408
28408
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
28409
28409
  var RELEASE_BRANCH = "release";
28410
- var BUNDLE_SHA = true ? "2652fe27fc5d4e368fdc38eda49d3011d38e631e" : void 0;
28410
+ var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
28411
28411
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
28412
28412
  var DOCTOR_LABEL = Object.freeze({
28413
28413
  D1: "version",
@@ -28729,6 +28729,11 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
28729
28729
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
28730
28730
  var V1_STATUSLINE_COMMAND = "context-mode statusline";
28731
28731
  var V1_PI_PACKAGE = "npm:context-mode";
28732
+ var PI_NPM_DIR = "npm";
28733
+ var PI_NODE_MODULES_DIR = "node_modules";
28734
+ var PI_PACKAGE_JSON_FILE = "package.json";
28735
+ var PI_LIST_COMMAND = "pi list";
28736
+ var PI_CURRENT_MAJOR = 2;
28732
28737
  var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
28733
28738
  var V1_TMP_PREFIX = "context-mode-";
28734
28739
  var V1_TOML_SECTION_ROOT = "mcp_servers";
@@ -29169,9 +29174,9 @@ function readUserVersion(raw) {
29169
29174
  const row5 = raw.prepare("PRAGMA user_version").get();
29170
29175
  return row5.user_version;
29171
29176
  }
29172
- function createAtomically(sqlite, path7) {
29177
+ function createAtomically(sqlite, path8) {
29173
29178
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
29174
- const tmp = path7 + "." + randomUUID2() + DB_TMP_SUFFIX;
29179
+ const tmp = path8 + "." + randomUUID2() + DB_TMP_SUFFIX;
29175
29180
  try {
29176
29181
  const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
29177
29182
  try {
@@ -29180,7 +29185,7 @@ function createAtomically(sqlite, path7) {
29180
29185
  raw.close();
29181
29186
  }
29182
29187
  try {
29183
- linkSync(tmp, path7);
29188
+ linkSync(tmp, path8);
29184
29189
  } catch (err) {
29185
29190
  if (err.code !== "EEXIST") throw err;
29186
29191
  }
@@ -29188,11 +29193,11 @@ function createAtomically(sqlite, path7) {
29188
29193
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
29189
29194
  }
29190
29195
  }
29191
- function openWritable(sqlite, path7) {
29196
+ function openWritable(sqlite, path8) {
29192
29197
  let raw = null;
29193
29198
  try {
29194
- if (!existsSync(path7)) createAtomically(sqlite, path7);
29195
- raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
29199
+ if (!existsSync(path8)) createAtomically(sqlite, path8);
29200
+ raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
29196
29201
  applyMigrations(raw, readUserVersion(raw));
29197
29202
  return raw;
29198
29203
  } catch (err) {
@@ -29200,8 +29205,8 @@ function openWritable(sqlite, path7) {
29200
29205
  throw err;
29201
29206
  }
29202
29207
  }
29203
- function openReadOnly(sqlite, path7) {
29204
- const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
29208
+ function openReadOnly(sqlite, path8) {
29209
+ const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
29205
29210
  try {
29206
29211
  const found = readUserVersion(raw);
29207
29212
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -29215,20 +29220,20 @@ async function openDb(project, opts) {
29215
29220
  if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
29216
29221
  const sqlite = await loadSqlite();
29217
29222
  mkdirSync(project.projectDir, { recursive: true });
29218
- const path7 = project.dbPath;
29219
- const sibling = existsSync(path7 + DB_WAL_SUFFIX) || existsSync(path7 + DB_SHM_SUFFIX);
29220
- if (sibling && !existsSync(path7)) {
29223
+ const path8 = project.dbPath;
29224
+ const sibling = existsSync(path8 + DB_WAL_SUFFIX) || existsSync(path8 + DB_SHM_SUFFIX);
29225
+ if (sibling && !existsSync(path8)) {
29221
29226
  throw new CtxError("DB_GONE");
29222
29227
  }
29223
29228
  try {
29224
29229
  let raw;
29225
29230
  if (opts?.readOnly === true) {
29226
- if (!existsSync(path7)) openWritable(sqlite, path7).close();
29227
- raw = openReadOnly(sqlite, path7);
29231
+ if (!existsSync(path8)) openWritable(sqlite, path8).close();
29232
+ raw = openReadOnly(sqlite, path8);
29228
29233
  } else {
29229
- raw = openWritable(sqlite, path7);
29234
+ raw = openWritable(sqlite, path8);
29230
29235
  }
29231
- return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
29236
+ return { raw, projectKey: project.projectKey, path: path8, ...opts?.readOnly === true ? { readOnly: true } : {} };
29232
29237
  } catch (err) {
29233
29238
  if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
29234
29239
  throw err;
@@ -29401,21 +29406,21 @@ function kiroDirOf(env, home, platform = process.platform) {
29401
29406
  if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
29402
29407
  if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
29403
29408
  const abs = p.resolve(dir);
29404
- const real2 = platform === process.platform ? realOrSelf : (x) => x;
29405
- const target = real2(abs);
29409
+ const real3 = platform === process.platform ? realOrSelf : (x) => x;
29410
+ const target = real3(abs);
29406
29411
  if (p.parse(target).root === target) return fallback;
29407
- const up = p.relative(target, real2(p.resolve(home)));
29412
+ const up = p.relative(target, real3(p.resolve(home)));
29408
29413
  if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
29409
29414
  return abs;
29410
29415
  }
29411
- function realOrSelf(path7) {
29416
+ function realOrSelf(path8) {
29412
29417
  const tail = [];
29413
- for (let at = path7; ; ) {
29418
+ for (let at = path8; ; ) {
29414
29419
  try {
29415
29420
  return join(realpathSync.native(at), ...tail.reverse());
29416
29421
  } catch {
29417
29422
  const up = dirname(at);
29418
- if (up === at) return path7;
29423
+ if (up === at) return path8;
29419
29424
  tail.push(basename(at));
29420
29425
  at = up;
29421
29426
  }
@@ -33080,10 +33085,10 @@ function assignProp3(target, prop, value) {
33080
33085
  configurable: true
33081
33086
  });
33082
33087
  }
33083
- function getElementAtPath3(obj, path7) {
33084
- if (!path7)
33088
+ function getElementAtPath3(obj, path8) {
33089
+ if (!path8)
33085
33090
  return obj;
33086
- return path7.reduce((acc, key) => acc?.[key], obj);
33091
+ return path8.reduce((acc, key) => acc?.[key], obj);
33087
33092
  }
33088
33093
  function promiseAllObject3(promisesObj) {
33089
33094
  const keys = Object.keys(promisesObj);
@@ -33403,11 +33408,11 @@ function aborted3(x, startIndex = 0) {
33403
33408
  }
33404
33409
  return false;
33405
33410
  }
33406
- function prefixIssues3(path7, issues) {
33411
+ function prefixIssues3(path8, issues) {
33407
33412
  return issues.map((iss) => {
33408
33413
  var _a5;
33409
33414
  (_a5 = iss).path ?? (_a5.path = []);
33410
- iss.path.unshift(path7);
33415
+ iss.path.unshift(path8);
33411
33416
  return iss;
33412
33417
  });
33413
33418
  }
@@ -33544,7 +33549,7 @@ function treeifyError2(error42, _mapper) {
33544
33549
  return issue4.message;
33545
33550
  };
33546
33551
  const result = { errors: [] };
33547
- const processError = (error43, path7 = []) => {
33552
+ const processError = (error43, path8 = []) => {
33548
33553
  var _a5, _b;
33549
33554
  for (const issue4 of error43.issues) {
33550
33555
  if (issue4.code === "invalid_union" && issue4.errors.length) {
@@ -33554,7 +33559,7 @@ function treeifyError2(error42, _mapper) {
33554
33559
  } else if (issue4.code === "invalid_element") {
33555
33560
  processError({ issues: issue4.issues }, issue4.path);
33556
33561
  } else {
33557
- const fullpath = [...path7, ...issue4.path];
33562
+ const fullpath = [...path8, ...issue4.path];
33558
33563
  if (fullpath.length === 0) {
33559
33564
  result.errors.push(mapper(issue4));
33560
33565
  continue;
@@ -33584,9 +33589,9 @@ function treeifyError2(error42, _mapper) {
33584
33589
  processError(error42);
33585
33590
  return result;
33586
33591
  }
33587
- function toDotPath(path7) {
33592
+ function toDotPath(path8) {
33588
33593
  const segs = [];
33589
- for (const seg of path7) {
33594
+ for (const seg of path8) {
33590
33595
  if (typeof seg === "number")
33591
33596
  segs.push(`[${seg}]`);
33592
33597
  else if (typeof seg === "symbol")
@@ -44161,19 +44166,19 @@ function steeringFiles(worktree) {
44161
44166
  function readAutoMemory(project) {
44162
44167
  const rows = [];
44163
44168
  for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
44164
- const path7 = join5(project.worktree, ...segs);
44165
- if (!isInside(project.worktree, path7)) continue;
44169
+ const path8 = join5(project.worktree, ...segs);
44170
+ if (!isInside(project.worktree, path8)) continue;
44166
44171
  try {
44167
- const st = statSync3(path7);
44172
+ const st = statSync3(path8);
44168
44173
  if (!st.isFile()) continue;
44169
44174
  rows.push({
44170
44175
  origin: "memory",
44171
44176
  ts: Math.trunc(st.mtimeMs),
44172
44177
  seq: null,
44173
44178
  sourceId: null,
44174
- path: path7,
44179
+ path: path8,
44175
44180
  label: segs.join("/"),
44176
- text: readFileSync3(path7, "utf8")
44181
+ text: readFileSync3(path8, "utf8")
44177
44182
  });
44178
44183
  } catch {
44179
44184
  }
@@ -44797,7 +44802,7 @@ var ctxBatch = Object.freeze({
44797
44802
  });
44798
44803
 
44799
44804
  // src/core/tools/doctor.ts
44800
- import { readdirSync as readdirSync7, readFileSync as readFileSync10, existsSync as existsSync15 } from "node:fs";
44805
+ import { readdirSync as readdirSync7, readFileSync as readFileSync11, existsSync as existsSync16 } from "node:fs";
44801
44806
  import { basename as basename5, join as join15 } from "node:path";
44802
44807
 
44803
44808
  // src/adapters/claude-code.ts
@@ -45430,7 +45435,7 @@ var PI_EVENTS = {
45430
45435
  tool_call: { event: "PreToolUse" },
45431
45436
  tool_result: { event: "PostToolUse" }
45432
45437
  };
45433
- var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
45438
+ var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
45434
45439
  function record4(v) {
45435
45440
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
45436
45441
  }
@@ -45700,8 +45705,9 @@ var ADAPTERS = Object.freeze([
45700
45705
  installMode: "in-process",
45701
45706
  projectSource: "pi:ctx.cwd",
45702
45707
  toolNamePrefix: TOOL_NAME_PREFIX9,
45703
- nativeTools: { shell: ["bash"], read: ["read"] },
45708
+ nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
45704
45709
  execReadOnlyHint: false,
45710
+ // D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
45705
45711
  eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
45706
45712
  compactDelivery: "pi-flag",
45707
45713
  compactSummary: "none",
@@ -45768,7 +45774,7 @@ function ownBundleDir() {
45768
45774
  }
45769
45775
 
45770
45776
  // src/core/ops/doctor-config.ts
45771
- import { existsSync as existsSync8, readdirSync as readdirSync6 } from "node:fs";
45777
+ import { existsSync as existsSync9, readdirSync as readdirSync6 } from "node:fs";
45772
45778
  import { join as join10 } from "node:path";
45773
45779
 
45774
45780
  // src/core/ops/detect-v1.ts
@@ -47910,15 +47916,15 @@ function withLayout(text, layout) {
47910
47916
  }
47911
47917
 
47912
47918
  // src/core/ops/host-config.ts
47913
- function formatOf(path7) {
47914
- if (path7.endsWith(JSONC_EXT)) return "jsonc";
47915
- if (path7.endsWith(TOML_EXT)) return "toml";
47919
+ function formatOf(path8) {
47920
+ if (path8.endsWith(JSONC_EXT)) return "jsonc";
47921
+ if (path8.endsWith(TOML_EXT)) return "toml";
47916
47922
  return "json";
47917
47923
  }
47918
- function readHostConfig(agent, path7) {
47919
- let file2 = path7;
47924
+ function readHostConfig(agent, path8) {
47925
+ let file2 = path8;
47920
47926
  if (agent === "opencode") {
47921
- const jsonc = join7(dirname5(path7), OPENCODE_CONFIG_FILES[0]);
47927
+ const jsonc = join7(dirname5(path8), OPENCODE_CONFIG_FILES[0]);
47922
47928
  if (existsSync5(jsonc)) file2 = jsonc;
47923
47929
  }
47924
47930
  const raw = existsSync5(file2) ? readFileSync4(file2, "utf8") : "";
@@ -48082,14 +48088,14 @@ function scanToml(text) {
48082
48088
  continue;
48083
48089
  }
48084
48090
  if (!node3.resolvedKey.every((seg) => typeof seg === "string")) continue;
48085
- const path7 = node3.resolvedKey;
48086
- for (const kv of node3.body) addKey(path7, kv);
48091
+ const path8 = node3.resolvedKey;
48092
+ for (const kv of node3.body) addKey(path8, kv);
48087
48093
  if (node3.kind !== "standard") continue;
48088
48094
  const start = lineStartOf(text, node3.range[0]);
48089
48095
  const headEnd = lineEndOf(text, node3.key.range[1]);
48090
48096
  const last2 = node3.body[node3.body.length - 1];
48091
48097
  tables.push({
48092
- path: path7,
48098
+ path: path8,
48093
48099
  header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
48094
48100
  start,
48095
48101
  end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
@@ -48100,16 +48106,16 @@ function scanToml(text) {
48100
48106
  function tomlTableSpans(text) {
48101
48107
  return scanToml(text).tables;
48102
48108
  }
48103
- function parseHostConfig(agent, path7, text, format) {
48109
+ function parseHostConfig(agent, path8, text, format) {
48104
48110
  try {
48105
48111
  return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
48106
48112
  } catch {
48107
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
48113
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
48108
48114
  }
48109
48115
  }
48110
- function hostConfigValueAt(value, path7) {
48116
+ function hostConfigValueAt(value, path8) {
48111
48117
  let cur = value;
48112
- for (const seg of path7) {
48118
+ for (const seg of path8) {
48113
48119
  if (!isPlainObject6(cur)) return void 0;
48114
48120
  cur = cur[seg];
48115
48121
  }
@@ -48142,32 +48148,32 @@ function indentUnit(root, clean) {
48142
48148
  function render(value, unit, base) {
48143
48149
  return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
48144
48150
  }
48145
- function nest(path7, value) {
48151
+ function nest(path8, value) {
48146
48152
  let out = value;
48147
- for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
48153
+ for (let k = path8.length - 1; k >= 0; k -= 1) out = { [path8[k]]: out };
48148
48154
  return out;
48149
48155
  }
48150
- function setJsonText(text, format, path7, value) {
48156
+ function setJsonText(text, format, path8, value) {
48151
48157
  const doc = scanJson(text, format);
48152
48158
  const unit = indentUnit(doc.root, doc.clean);
48153
- if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
48159
+ if (doc.root === null) return render(nest(path8, value), unit, "") + "\n";
48154
48160
  let node3 = doc.root;
48155
48161
  let depth = 0;
48156
- while (depth < path7.length && node3.kind === "object") {
48157
- const hit = node3.members.find((m) => m.key === path7[depth]);
48162
+ while (depth < path8.length && node3.kind === "object") {
48163
+ const hit = node3.members.find((m) => m.key === path8[depth]);
48158
48164
  if (hit === void 0) break;
48159
48165
  node3 = hit.node;
48160
48166
  depth += 1;
48161
48167
  }
48162
- if (depth === path7.length) {
48168
+ if (depth === path8.length) {
48163
48169
  return text.slice(0, node3.start) + render(value, unit, lineIndent(doc.clean, node3.start)) + text.slice(node3.end);
48164
48170
  }
48165
- if (node3.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
48166
- const rest = nest(path7.slice(depth + 1), value);
48171
+ if (node3.kind !== "object") throw new SyntaxError("not an object at " + path8.slice(0, depth).join("."));
48172
+ const rest = nest(path8.slice(depth + 1), value);
48167
48173
  const last2 = node3.members[node3.members.length - 1];
48168
48174
  if (last2 === void 0) {
48169
48175
  const base2 = lineIndent(doc.clean, node3.start);
48170
- const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
48176
+ const member2 = "\n" + base2 + unit + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
48171
48177
  return text.slice(0, node3.start + 1) + member2 + text.slice(node3.end - 1);
48172
48178
  }
48173
48179
  const base = lineIndent(doc.clean, last2.keyStart);
@@ -48175,7 +48181,7 @@ function setJsonText(text, format, path7, value) {
48175
48181
  while (" \r\n".includes(doc.clean[at])) at += 1;
48176
48182
  const trailing = doc.clean[at] === ",";
48177
48183
  const insertAt = trailing ? at + 1 : last2.node.end;
48178
- const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
48184
+ const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base);
48179
48185
  return text.slice(0, insertAt) + member + text.slice(insertAt);
48180
48186
  }
48181
48187
  function tomlScalar(v) {
@@ -48193,17 +48199,17 @@ function tomlHeaderKey(seg) {
48193
48199
  }
48194
48200
  return seg;
48195
48201
  }
48196
- function tomlBlock(path7, value) {
48197
- let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
48202
+ function tomlBlock(path8, value) {
48203
+ let out = "[" + path8.map(tomlHeaderKey).join(".") + "]\n";
48198
48204
  const subs = [];
48199
48205
  for (const [k, v] of Object.entries(value)) {
48200
- if (isPlainObject6(v)) subs.push(tomlBlock([...path7, k], v));
48206
+ if (isPlainObject6(v)) subs.push(tomlBlock([...path8, k], v));
48201
48207
  else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
48202
48208
  }
48203
48209
  return [out, ...subs].join("\n");
48204
48210
  }
48205
- function under(path7, prefix) {
48206
- return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
48211
+ function under(path8, prefix) {
48212
+ return path8.length >= prefix.length && prefix.every((seg, k) => path8[k] === seg);
48207
48213
  }
48208
48214
  function keyLineRange(text, k) {
48209
48215
  const ls = lineStartOf(text, k.start);
@@ -48220,10 +48226,10 @@ function withValueAt(root, rel, value) {
48220
48226
  else base[rel[0]] = next;
48221
48227
  return base;
48222
48228
  }
48223
- function replaceToml(text, doc, path7, value) {
48224
- const block = value === void 0 ? "" : tomlBlock(path7, value);
48225
- const owned = doc.tables.filter((t) => under(t.path, path7));
48226
- const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
48229
+ function replaceToml(text, doc, path8, value) {
48230
+ const block = value === void 0 ? "" : tomlBlock(path8, value);
48231
+ const owned = doc.tables.filter((t) => under(t.path, path8));
48232
+ const cuts = doc.keys.filter((k) => under(k.full, path8) && !under(k.base, path8)).map((k) => [...keyLineRange(text, k), ""]);
48227
48233
  owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
48228
48234
  cuts.sort((a, b) => b[0] - a[0]);
48229
48235
  let out = text;
@@ -48233,27 +48239,27 @@ function replaceToml(text, doc, path7, value) {
48233
48239
  return out + sep3 + block;
48234
48240
  }
48235
48241
  var tableLike = (v) => v === void 0 || isPlainObject6(v);
48236
- function setTomlText(text, path7, value) {
48242
+ function setTomlText(text, path8, value) {
48237
48243
  if (value !== void 0 && !isPlainObject6(value)) throw new SyntaxError("TOML edits replace a whole table");
48238
48244
  const doc = scanToml(text);
48239
- const cur = hostConfigValueAt(doc.value, path7);
48245
+ const cur = hostConfigValueAt(doc.value, path8);
48240
48246
  if (sameValue(cur, value)) return text;
48241
- const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
48247
+ const inline = doc.keys.find((k) => k.inline && k.full.length < path8.length && under(path8, k.full));
48242
48248
  if (inline !== void 0) {
48243
- const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
48249
+ const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path8.slice(inline.full.length), value);
48244
48250
  return replaceToml(text, doc, inline.full, whole2);
48245
48251
  }
48246
48252
  if (isPlainObject6(cur) && isPlainObject6(value)) {
48247
48253
  const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
48248
48254
  if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
48249
48255
  let out = text;
48250
- for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
48256
+ for (const k of names) out = setTomlText(out, [...path8, k], value[k]);
48251
48257
  return out;
48252
48258
  }
48253
48259
  }
48254
- return replaceToml(text, doc, path7, value);
48260
+ return replaceToml(text, doc, path8, value);
48255
48261
  }
48256
- function setText(agent, path7, text, format, key, value) {
48262
+ function setText(agent, path8, text, format, key, value) {
48257
48263
  try {
48258
48264
  if (format !== "toml") return setJsonText(text, format, key, value);
48259
48265
  const out = setTomlText(text, key, value);
@@ -48262,7 +48268,7 @@ function setText(agent, path7, text, format, key, value) {
48262
48268
  if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
48263
48269
  return out;
48264
48270
  } catch {
48265
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
48271
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
48266
48272
  }
48267
48273
  }
48268
48274
  function serverScript() {
@@ -48309,14 +48315,14 @@ function ownTargets(agent, accept) {
48309
48315
  if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
48310
48316
  return [];
48311
48317
  }
48312
- function applyEdits(agent, path7, text, format, wanted) {
48313
- const parsed = parseHostConfig(agent, path7, text, format);
48318
+ function applyEdits(agent, path8, text, format, wanted) {
48319
+ const parsed = parseHostConfig(agent, path8, text, format);
48314
48320
  let out = text;
48315
48321
  const edits = [];
48316
48322
  for (const [key, after] of wanted) {
48317
48323
  const before = hostConfigValueAt(parsed, key);
48318
48324
  if (sameValue(before, after)) continue;
48319
- out = setText(agent, path7, out, format, key, after);
48325
+ out = setText(agent, path8, out, format, key, after);
48320
48326
  edits.push({ path: key.join("."), before, after });
48321
48327
  }
48322
48328
  return { text: out, format, edits };
@@ -48337,7 +48343,7 @@ function writeHostConfigEdit(_requested, current, patch) {
48337
48343
  // src/core/ops/detect-v1.ts
48338
48344
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
48339
48345
  var keyPath = (...parts) => parts.join(".");
48340
- var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
48346
+ var finding = (file2, path8, reason) => ({ file: file2, path: path8, reason });
48341
48347
  function stripJsonc(text) {
48342
48348
  let out = "";
48343
48349
  let inStr = false;
@@ -48542,12 +48548,17 @@ function scanKiro(agentHome, project, out) {
48542
48548
  }
48543
48549
  dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48544
48550
  }
48551
+ function piNpmIsCurrent(piAgentDir) {
48552
+ const doc = readJson(join8(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
48553
+ const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
48554
+ return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
48555
+ }
48545
48556
  function scanPi(piAgentDir, agentHome, out) {
48546
48557
  const file2 = join8(piAgentDir, SETTINGS_FILE);
48547
48558
  const doc = readJson(file2);
48548
48559
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
48549
48560
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
48550
- if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
48561
+ if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
48551
48562
  });
48552
48563
  dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48553
48564
  }
@@ -48644,8 +48655,8 @@ function detectV1(agent, home, scope = {}) {
48644
48655
  import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
48645
48656
  import { dirname as dirname6, isAbsolute, join as join9, sep as sep2 } from "node:path";
48646
48657
  import { fileURLToPath as fileURLToPath2 } from "node:url";
48647
- function missing(agent, path7) {
48648
- return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
48658
+ function missing(agent, path8) {
48659
+ return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
48649
48660
  }
48650
48661
  var parseOrNull = (text) => {
48651
48662
  try {
@@ -48674,9 +48685,9 @@ function recordedInstalls(text) {
48674
48685
  }
48675
48686
  return out;
48676
48687
  }
48677
- var realOrNull = (path7) => {
48688
+ var realOrNull = (path8) => {
48678
48689
  try {
48679
- return realpathSync4.native(path7);
48690
+ return realpathSync4.native(path8);
48680
48691
  } catch {
48681
48692
  return null;
48682
48693
  }
@@ -48774,12 +48785,81 @@ function candidate(adapter, env, worktree) {
48774
48785
  }
48775
48786
  }
48776
48787
  function resolvePluginRoot(adapter, env, worktree) {
48777
- const path7 = candidate(adapter, env, worktree);
48788
+ const path8 = candidate(adapter, env, worktree);
48789
+ try {
48790
+ return realpathSync4.native(path8);
48791
+ } catch {
48792
+ throw missing(adapter.id, path8);
48793
+ }
48794
+ }
48795
+
48796
+ // src/setup/pi-gate.ts
48797
+ import { existsSync as existsSync8, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
48798
+ import path4 from "node:path";
48799
+ var EXTENSIONS_KEY = "extensions";
48800
+ var PROJECT_DIR = ".pi";
48801
+ var TRUST_FILE = "trust.json";
48802
+ var ALWAYS = "always";
48803
+ var SOURCE_PREFIXES = ["npm:", "git:"];
48804
+ function load(file2) {
48805
+ if (!existsSync8(file2)) return void 0;
48778
48806
  try {
48779
- return realpathSync4.native(path7);
48807
+ return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync7(file2, "utf8")), "json") };
48780
48808
  } catch {
48781
- throw missing(adapter.id, path7);
48809
+ return void 0;
48810
+ }
48811
+ }
48812
+ var real2 = (p) => {
48813
+ try {
48814
+ return realpathSync5(p);
48815
+ } catch {
48816
+ return path4.resolve(p);
48817
+ }
48818
+ };
48819
+ function sourceName(source) {
48820
+ let s = source;
48821
+ for (const p of SOURCE_PREFIXES) if (s.startsWith(p)) s = s.slice(p.length);
48822
+ const last2 = s.split("/").pop() ?? "";
48823
+ const at = last2.indexOf("@", 1);
48824
+ const name = at > 0 ? last2.slice(0, at) : last2;
48825
+ return name.endsWith(".git") ? name.slice(0, -4) : name;
48826
+ }
48827
+ function isOwn(source, pkgDir) {
48828
+ if (typeof source !== "string") return false;
48829
+ return real2(source) === real2(pkgDir) || sourceName(source) === SERVER_KEY;
48830
+ }
48831
+ function ownEntries(src, pkgDir) {
48832
+ const list3 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
48833
+ if (!Array.isArray(list3)) return [];
48834
+ const out = [];
48835
+ for (const e of list3) {
48836
+ const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
48837
+ if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
48838
+ const ext = obj?.[EXTENSIONS_KEY];
48839
+ out.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x) => typeof x === "string") : void 0 });
48840
+ }
48841
+ return out;
48842
+ }
48843
+ function projectTrusted(agentDir, userDoc, cwd) {
48844
+ const trust = load(path4.join(agentDir, TRUST_FILE));
48845
+ const entries = /* @__PURE__ */ new Map();
48846
+ if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real2(k), v);
48847
+ let dir = real2(cwd);
48848
+ for (; ; ) {
48849
+ const v = entries.get(dir);
48850
+ if (v === true || v === false) return v;
48851
+ const up = path4.dirname(dir);
48852
+ if (up === dir) break;
48853
+ dir = up;
48782
48854
  }
48855
+ return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
48856
+ }
48857
+ function piInstalledIn(env, home, pkgDir, cwd) {
48858
+ const agentDir = piAgentDirOf(env, home);
48859
+ const user = load(path4.join(agentDir, SETTINGS_FILE));
48860
+ const project = load(path4.join(cwd, PROJECT_DIR, SETTINGS_FILE));
48861
+ if (project && projectTrusted(agentDir, user?.doc, cwd) && ownEntries(project, pkgDir).length > 0) return project.file;
48862
+ return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
48783
48863
  }
48784
48864
 
48785
48865
  // src/core/ops/doctor-config.ts
@@ -48882,14 +48962,14 @@ function codexNativeDir(env, home) {
48882
48962
  }
48883
48963
  if (enabled !== true) return null;
48884
48964
  const cache = join10(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
48885
- if (!existsSync8(cache)) return null;
48965
+ if (!existsSync9(cache)) return null;
48886
48966
  const found = [];
48887
48967
  for (const market of readdirSync6(cache)) {
48888
48968
  const plugin = join10(cache, market, SERVER_KEY);
48889
- if (!existsSync8(plugin)) continue;
48969
+ if (!existsSync9(plugin)) continue;
48890
48970
  for (const version4 of readdirSync6(plugin).sort()) {
48891
48971
  const dir = join10(plugin, version4, CODEX_PLUGIN_SUBDIR);
48892
- if (existsSync8(join10(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
48972
+ if (existsSync9(join10(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
48893
48973
  }
48894
48974
  }
48895
48975
  return found.length === 0 ? null : found[found.length - 1];
@@ -48980,12 +49060,17 @@ function checkHostConfig(row5, env, worktree) {
48980
49060
  const choice = marketplaceChoice(env, worktree);
48981
49061
  if ("installs" in choice) return fail("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
48982
49062
  }
49063
+ if (row5.id === "pi") return checkPiInstall(env, home, worktree);
48983
49064
  const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
48984
- const read = row5.id === "pi" ? mcpFile(row5, home, env) : null;
48985
- if (parts.length === 0) return read === null ? pass("D3") : { ...pass("D3"), detail: read };
49065
+ if (parts.length === 0) return pass("D3");
48986
49066
  const detail = D3_DETAIL(parts);
48987
49067
  const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
48988
- return fail("D3", read === null ? detail : detail + D4_REASON_JOIN + read, fix);
49068
+ return fail("D3", detail, fix);
49069
+ }
49070
+ function checkPiInstall(env, home, worktree) {
49071
+ const found = piInstalledIn(env, home, ownBundleDir(), worktree);
49072
+ if (found !== void 0) return { ...pass("D3"), detail: found };
49073
+ return fail("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join10(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
48989
49074
  }
48990
49075
  function checkV1Leftovers(agent, home, scope = {}) {
48991
49076
  const findings = detectV1(agent, home, scope);
@@ -49038,7 +49123,7 @@ function configPaths(row5, env, worktree) {
49038
49123
  }
49039
49124
 
49040
49125
  // src/core/ops/doctor-db.ts
49041
- import { existsSync as existsSync9, statSync as statSync4 } from "node:fs";
49126
+ import { existsSync as existsSync10, statSync as statSync4 } from "node:fs";
49042
49127
  var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
49043
49128
  var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
49044
49129
  var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -49057,8 +49142,8 @@ async function loadSqlite2() {
49057
49142
  return null;
49058
49143
  }
49059
49144
  }
49060
- function openRead(sqlite, path7) {
49061
- return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
49145
+ function openRead(sqlite, path8) {
49146
+ return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
49062
49147
  }
49063
49148
  var cell = (row5) => Object.values(row5)[0];
49064
49149
  function readSchema(raw) {
@@ -49079,16 +49164,16 @@ function failsOnCorrupt(step) {
49079
49164
  function orphanFiles(dbPath) {
49080
49165
  const files = [];
49081
49166
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
49082
- const path7 = dbPath + suffix;
49083
- if (existsSync9(path7)) files.push({ path: path7, bytes: statSync4(path7).size });
49167
+ const path8 = dbPath + suffix;
49168
+ if (existsSync10(path8)) files.push({ path: path8, bytes: statSync4(path8).size });
49084
49169
  }
49085
- return files.length > 0 && !existsSync9(dbPath) ? files : [];
49170
+ return files.length > 0 && !existsSync10(dbPath) ? files : [];
49086
49171
  }
49087
49172
  async function checkDb(project) {
49088
49173
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
49089
49174
  const orphan = orphanFiles(project.dbPath);
49090
49175
  if (orphan.length > 0) return { row: fail2(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
49091
- if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
49176
+ if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
49092
49177
  const sqlite = await loadSqlite2();
49093
49178
  if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
49094
49179
  let raw = null;
@@ -49114,7 +49199,7 @@ async function checkDb(project) {
49114
49199
  }
49115
49200
  }
49116
49201
  async function checkIndex(project) {
49117
- if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
49202
+ if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
49118
49203
  const sqlite = await loadSqlite2();
49119
49204
  if (sqlite === null) return unknown4("D9", D2_SQLITE_DETAIL);
49120
49205
  let raw = null;
@@ -49131,7 +49216,7 @@ async function checkIndex(project) {
49131
49216
  }
49132
49217
 
49133
49218
  // src/core/ops/doctor-env.ts
49134
- import { existsSync as existsSync10, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
49219
+ import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync6 } from "node:fs";
49135
49220
  import { isAbsolute as isAbsolute2, join as join11, relative } from "node:path";
49136
49221
  function pass3(id, detail = DOCTOR_PASS_DETAIL) {
49137
49222
  return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
@@ -49144,7 +49229,7 @@ function fail3(id, detail, fixCommand) {
49144
49229
  }
49145
49230
  function bundleVersion(bundleDir2) {
49146
49231
  try {
49147
- const v = JSON.parse(readFileSync7(join11(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
49232
+ const v = JSON.parse(readFileSync8(join11(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
49148
49233
  return typeof v === "string" && v !== "" ? v : void 0;
49149
49234
  } catch {
49150
49235
  return void 0;
@@ -49294,8 +49379,8 @@ function checkMcp(ctx) {
49294
49379
  return named2 || versioned ? pass3("D6") : unknown5("D6", D6_UNKNOWN_DETAIL);
49295
49380
  }
49296
49381
  function piCwdInside(worktree, piCwd) {
49297
- if (piCwd === void 0 || !existsSync10(piCwd)) return false;
49298
- const rel = relative(worktree, realpathSync5.native(piCwd));
49382
+ if (piCwd === void 0 || !existsSync11(piCwd)) return false;
49383
+ const rel = relative(worktree, realpathSync6.native(piCwd));
49299
49384
  return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
49300
49385
  }
49301
49386
  function checkProject(i) {
@@ -49315,20 +49400,20 @@ function checkShell(env) {
49315
49400
  }
49316
49401
 
49317
49402
  // src/core/ops/doctor-hook.ts
49318
- import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync8, realpathSync as realpathSync7, rmSync as rmSync4 } from "node:fs";
49403
+ import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync9, realpathSync as realpathSync8, rmSync as rmSync4 } from "node:fs";
49319
49404
  import { tmpdir as tmpdir2 } from "node:os";
49320
- import path6 from "node:path";
49405
+ import path7 from "node:path";
49321
49406
 
49322
49407
  // src/setup/codex-trust.ts
49323
49408
  import { createHash } from "node:crypto";
49324
- import { existsSync as existsSync11, realpathSync as realpathSync6 } from "node:fs";
49325
- import path5 from "node:path";
49409
+ import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
49410
+ import path6 from "node:path";
49326
49411
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
49327
49412
 
49328
49413
  // src/setup/spawn-bin.ts
49329
49414
  import { spawnSync } from "node:child_process";
49330
49415
  import { accessSync as accessSync2, constants as fsc, statSync as statSync5 } from "node:fs";
49331
- import path4 from "node:path";
49416
+ import path5 from "node:path";
49332
49417
  var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
49333
49418
  var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
49334
49419
  var DEFAULT_COMSPEC = "cmd.exe";
@@ -49339,10 +49424,10 @@ function whichBin(bin, env, platform = process.platform) {
49339
49424
  const get = (k) => envGet(env, k);
49340
49425
  const win = platform === "win32";
49341
49426
  const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
49342
- const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
49427
+ const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
49343
49428
  for (const dir of pathEntries(get("PATH") ?? "", platform)) {
49344
49429
  for (const n of names) {
49345
- const f = path4.join(dir, n);
49430
+ const f = path5.join(dir, n);
49346
49431
  try {
49347
49432
  accessSync2(f, fsc.X_OK);
49348
49433
  if (statSync5(f).isFile()) return f;
@@ -49383,7 +49468,7 @@ function winCmdLine(file2, args, env = {}) {
49383
49468
  return `"${[file2, ...args].map(q).join(" ")}"`;
49384
49469
  }
49385
49470
  function spawnForm(file2, args, env, platform = process.platform) {
49386
- if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
49471
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
49387
49472
  return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
49388
49473
  }
49389
49474
  return { command: file2, args, windowsVerbatimArguments: false };
@@ -49407,10 +49492,10 @@ function codexHomeFromReply(out) {
49407
49492
  return void 0;
49408
49493
  }
49409
49494
  function sameDir(a, b, platform = process.platform) {
49410
- if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
49495
+ if (platform !== "win32") return path6.posix.normalize(a) === path6.posix.normalize(b);
49411
49496
  const norm = (p) => {
49412
49497
  const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
49413
- const n = path5.win32.normalize(bare2).toLowerCase();
49498
+ const n = path6.win32.normalize(bare2).toLowerCase();
49414
49499
  return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
49415
49500
  };
49416
49501
  return norm(a) === norm(b);
@@ -49543,11 +49628,11 @@ function isObject5(v) {
49543
49628
  return typeof v === "object" && v !== null && !Array.isArray(v);
49544
49629
  }
49545
49630
  function loadFixture(bundleDir2, agent) {
49546
- const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
49547
- if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
49631
+ const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
49632
+ if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
49548
49633
  let all;
49549
49634
  try {
49550
- all = JSON.parse(hostText(readFileSync8(file2, "utf8")));
49635
+ all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
49551
49636
  } catch (err) {
49552
49637
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
49553
49638
  }
@@ -49609,7 +49694,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
49609
49694
  var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
49610
49695
  function readProbePayload(cwd) {
49611
49696
  const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
49612
- const filePath = path6.join(cwd, "d5-read-probe.txt");
49697
+ const filePath = path7.join(cwd, "d5-read-probe.txt");
49613
49698
  return {
49614
49699
  session_id: "d5-read-probe",
49615
49700
  transcript_path: "",
@@ -49636,9 +49721,9 @@ function isReadShape(stdout) {
49636
49721
  return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
49637
49722
  }
49638
49723
  async function readProbeOk(i, timeoutMs) {
49639
- const home = mkdtempSync(path6.join(tmpdir2(), "cm-d5-read-"));
49724
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
49640
49725
  try {
49641
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
49726
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
49642
49727
  cwd: i.bundleDir,
49643
49728
  env: { ...i.env, HOME: home, USERPROFILE: home },
49644
49729
  signal: i.signal,
@@ -49656,7 +49741,7 @@ function codexHookJournaled(db) {
49656
49741
  }
49657
49742
  function realDir(p) {
49658
49743
  try {
49659
- return realpathSync7(p);
49744
+ return realpathSync8(p);
49660
49745
  } catch {
49661
49746
  return p;
49662
49747
  }
@@ -49683,7 +49768,7 @@ async function checkHookRoundTrip(i) {
49683
49768
  const trust = await codexPluginTrust(i);
49684
49769
  if (trust !== null) return trust;
49685
49770
  }
49686
- if (i.agent === "codex" && existsSync12(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
49771
+ if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
49687
49772
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
49688
49773
  }
49689
49774
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -49703,7 +49788,7 @@ async function checkHookRoundTrip(i) {
49703
49788
  let ms = 0;
49704
49789
  for (let n = 1; n <= maxPairs; n++) {
49705
49790
  const start = now();
49706
- const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
49791
+ const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
49707
49792
  cwd: i.bundleDir,
49708
49793
  env: i.env,
49709
49794
  signal: i.signal,
@@ -49759,7 +49844,7 @@ function lastHookError(env) {
49759
49844
  }
49760
49845
 
49761
49846
  // src/core/ops/db-heal.ts
49762
- import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync5 } from "node:fs";
49847
+ import { existsSync as existsSync14, mkdirSync as mkdirSync5, rmSync as rmSync5 } from "node:fs";
49763
49848
  import { basename as basename4, dirname as dirname7, join as join13 } from "node:path";
49764
49849
  function integrityOk2(rows) {
49765
49850
  return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
@@ -49794,7 +49879,7 @@ function renameAside(dbPath) {
49794
49879
  const ts = String(Date.now());
49795
49880
  for (const suffix of DB_SIBLING_SUFFIXES) {
49796
49881
  const file2 = dbPath + suffix;
49797
- if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
49882
+ if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
49798
49883
  }
49799
49884
  return ts;
49800
49885
  }
@@ -49901,7 +49986,7 @@ function buildReportHead(input) {
49901
49986
 
49902
49987
  // src/core/ops/doctor-issue.ts
49903
49988
  import { spawnSync as spawnSync3 } from "node:child_process";
49904
- import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync9, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
49989
+ import { closeSync, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync10, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
49905
49990
  import { delimiter, join as join14 } from "node:path";
49906
49991
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
49907
49992
  function tildeOf(env) {
@@ -49909,8 +49994,8 @@ function tildeOf(env) {
49909
49994
  if (home === null || home === "") return (t) => t;
49910
49995
  const homes = [home];
49911
49996
  try {
49912
- const real2 = realpathSync8.native(home);
49913
- if (real2 !== home) homes.push(real2);
49997
+ const real3 = realpathSync9.native(home);
49998
+ if (real3 !== home) homes.push(real3);
49914
49999
  } catch {
49915
50000
  }
49916
50001
  homes.sort((a, b) => b.length - a.length);
@@ -49943,7 +50028,7 @@ function onPath(env, tool) {
49943
50028
  const out = [];
49944
50029
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
49945
50030
  if (dir === "") continue;
49946
- for (const n of names) if (existsSync14(join14(dir, n))) {
50031
+ for (const n of names) if (existsSync15(join14(dir, n))) {
49947
50032
  out.push(join14(dir, n));
49948
50033
  break;
49949
50034
  }
@@ -49952,7 +50037,7 @@ function onPath(env, tool) {
49952
50037
  }
49953
50038
  function hookLogTail(env) {
49954
50039
  const file2 = hookLogPath(env);
49955
- if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
50040
+ if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
49956
50041
  try {
49957
50042
  const fd = openSync(file2, "r");
49958
50043
  try {
@@ -49972,7 +50057,7 @@ function hookLogTail(env) {
49972
50057
  }
49973
50058
  async function journalRows(ctx) {
49974
50059
  const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
49975
- if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
50060
+ if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
49976
50061
  try {
49977
50062
  const db = await openDb(ctx.project, { readOnly: true });
49978
50063
  try {
@@ -49998,13 +50083,13 @@ function agentConfig(adapter, env, worktree) {
49998
50083
  for (const f of files) {
49999
50084
  if (seen.has(f.path)) continue;
50000
50085
  seen.add(f.path);
50001
- if (!existsSync14(f.path)) {
50086
+ if (!existsSync15(f.path)) {
50002
50087
  out.push(`${f.label}: ${f.path} (absent)`);
50003
50088
  continue;
50004
50089
  }
50005
50090
  let text = "";
50006
50091
  try {
50007
- text = readFileSync9(f.path, "utf8");
50092
+ text = readFileSync10(f.path, "utf8");
50008
50093
  } catch (err) {
50009
50094
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
50010
50095
  continue;
@@ -50122,7 +50207,7 @@ async function guard(id, run) {
50122
50207
  }
50123
50208
  }
50124
50209
  async function codexDb(ctx, adapter) {
50125
- if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
50210
+ if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
50126
50211
  try {
50127
50212
  return await openDb(ctx.project, { readOnly: true });
50128
50213
  } catch {
@@ -50153,10 +50238,10 @@ async function hookRow(ctx, adapter, host) {
50153
50238
  }
50154
50239
  function ownServerId(configDir, projectKey) {
50155
50240
  const dir = join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
50156
- if (!existsSync15(dir)) return "";
50241
+ if (!existsSync16(dir)) return "";
50157
50242
  for (const name of readdirSync7(dir)) {
50158
50243
  if (!name.endsWith(OWNER_PID_EXT)) continue;
50159
- if (readFileSync10(join15(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
50244
+ if (readFileSync11(join15(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
50160
50245
  }
50161
50246
  return "";
50162
50247
  }
@@ -50212,7 +50297,7 @@ async function doctorReply(ctx, host) {
50212
50297
  const adapter = getAdapter(ctx.project.agent);
50213
50298
  const rows = await runDoctorChecks(ctx, adapter, host);
50214
50299
  const failed2 = rows.some((r) => r.status === "FAIL");
50215
- const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
50300
+ const command = adapter.id === "pi" ? failed2 ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
50216
50301
  const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
50217
50302
  const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
50218
50303
  const table3 = buildReport(input);
@@ -50239,7 +50324,7 @@ async function doctorReply(ctx, host) {
50239
50324
  return { text, isError: false, sandboxBytes: bytes5 };
50240
50325
  }
50241
50326
  async function handler2(_input, ctx) {
50242
- return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: void 0 });
50327
+ return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
50243
50328
  }
50244
50329
  var ctxDoctor = Object.freeze({
50245
50330
  name: "ctx_doctor",
@@ -50251,7 +50336,7 @@ var ctxDoctor = Object.freeze({
50251
50336
  });
50252
50337
 
50253
50338
  // src/core/tools/execute.ts
50254
- import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
50339
+ import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
50255
50340
  import { tmpdir as tmpdir3 } from "node:os";
50256
50341
  import { dirname as dirname9, join as join16, parse as parse5, resolve as resolve4 } from "node:path";
50257
50342
 
@@ -50376,7 +50461,7 @@ function schemaLine(issue4) {
50376
50461
  }
50377
50462
  function fileError(given, abs, root) {
50378
50463
  let dir = abs;
50379
- while (!existsSync16(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
50464
+ while (!existsSync17(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
50380
50465
  if (isInside(root, dir)) return null;
50381
50466
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
50382
50467
  }
@@ -50493,19 +50578,19 @@ var ctxExecute = {
50493
50578
  };
50494
50579
 
50495
50580
  // src/core/tools/index.ts
50496
- import { existsSync as existsSync17, readFileSync as readFileSync12, statSync as statSync7 } from "node:fs";
50581
+ import { existsSync as existsSync18, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
50497
50582
  import { dirname as dirname10, extname, join as join18, relative as relative2, resolve as resolve5 } from "node:path";
50498
50583
 
50499
50584
  // src/core/index/walk.ts
50500
- import { readdirSync as readdirSync8, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync6 } from "node:fs";
50585
+ import { readdirSync as readdirSync8, readFileSync as readFileSync12, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
50501
50586
  import { join as join17 } from "node:path";
50502
50587
  var GITIGNORE = ".gitignore";
50503
50588
  var GIT_DIR = ".git";
50504
50589
  function walkDir(root, containmentRoot) {
50505
- const real2 = realpathSync9(root);
50506
- if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
50590
+ const real3 = realpathSync10(root);
50591
+ if (!isInside(containmentRoot, real3)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
50507
50592
  const found = [];
50508
- visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
50593
+ visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
50509
50594
  found.sort(compareFound);
50510
50595
  return found.map((f) => ({ absPath: f.absPath, relPath: join17(...f.dir, f.name) }));
50511
50596
  }
@@ -50519,14 +50604,14 @@ function visit(abs, rel, parent, contain, seen, found) {
50519
50604
  const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join17(abs, GITIGNORE), rel)) : parent;
50520
50605
  for (const e of entries) {
50521
50606
  if (e.name === GIT_DIR) continue;
50522
- const path7 = join17(abs, e.name);
50607
+ const path8 = join17(abs, e.name);
50523
50608
  let isDir = e.isDirectory();
50524
50609
  let isFile = e.isFile();
50525
- let target = path7;
50610
+ let target = path8;
50526
50611
  if (e.isSymbolicLink()) {
50527
50612
  let resolved;
50528
50613
  try {
50529
- resolved = realpathSync9(path7);
50614
+ resolved = realpathSync10(path8);
50530
50615
  } catch {
50531
50616
  continue;
50532
50617
  }
@@ -50539,12 +50624,12 @@ function visit(abs, rel, parent, contain, seen, found) {
50539
50624
  const segs = rel.concat(e.name);
50540
50625
  if (ignored(rules, segs, isDir)) continue;
50541
50626
  if (isFile) {
50542
- found.push({ dir: rel, name: e.name, absPath: path7 });
50627
+ found.push({ dir: rel, name: e.name, absPath: path8 });
50543
50628
  } else if (isDir) {
50544
- const key = e.isSymbolicLink() ? target : realpathSync9(path7);
50629
+ const key = e.isSymbolicLink() ? target : realpathSync10(path8);
50545
50630
  if (seen.has(key)) continue;
50546
50631
  seen.add(key);
50547
- visit(path7, segs, rules, contain, seen, found);
50632
+ visit(path8, segs, rules, contain, seen, found);
50548
50633
  }
50549
50634
  }
50550
50635
  }
@@ -50559,7 +50644,7 @@ function compareFound(a, b) {
50559
50644
  function readRules(file2, base) {
50560
50645
  let body;
50561
50646
  try {
50562
- body = readFileSync11(file2, "utf8");
50647
+ body = readFileSync12(file2, "utf8");
50563
50648
  } catch {
50564
50649
  return [];
50565
50650
  }
@@ -50735,12 +50820,12 @@ function tlsName(host) {
50735
50820
  function request(u, conn, proxy, signal) {
50736
50821
  const host = bare(u.hostname);
50737
50822
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
50738
- const path7 = u.pathname + u.search;
50823
+ const path8 = u.pathname + u.search;
50739
50824
  return new Promise((resolve6, reject) => {
50740
50825
  const onErr = (err) => reject(fail5(causeCode(err)));
50741
50826
  if (proxy === void 0) {
50742
50827
  const mod = u.protocol === "https:" ? https : http;
50743
- const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
50828
+ const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
50744
50829
  req.on("response", resolve6).on("error", onErr).end();
50745
50830
  return;
50746
50831
  }
@@ -50762,7 +50847,7 @@ function request(u, conn, proxy, signal) {
50762
50847
  const req = https.request({
50763
50848
  host,
50764
50849
  port,
50765
- path: path7,
50850
+ path: path8,
50766
50851
  signal,
50767
50852
  headers: { host: u.host },
50768
50853
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
@@ -54642,14 +54727,14 @@ function kindOfType(contentType) {
54642
54727
  }
54643
54728
  function readUtf8(absPath) {
54644
54729
  try {
54645
- return utf8.decode(readFileSync12(absPath));
54730
+ return utf8.decode(readFileSync13(absPath));
54646
54731
  } catch {
54647
54732
  return void 0;
54648
54733
  }
54649
54734
  }
54650
54735
  function missingOrOutside(given, abs, root) {
54651
54736
  let dir = abs;
54652
- while (!existsSync17(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
54737
+ while (!existsSync18(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
54653
54738
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
54654
54739
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
54655
54740
  }
@@ -54860,8 +54945,8 @@ function buildCandidates(rows, sessionId) {
54860
54945
  edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
54861
54946
  }
54862
54947
  const changedFiles = [];
54863
- for (const [path7, e] of edits) {
54864
- const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
54948
+ for (const [path8, e] of edits) {
54949
+ const c = make("changed_files", e.row, "edited " + path8 + " x" + e.count, e.count, path8);
54865
54950
  changedFiles.push({ ...c, editCount: e.count });
54866
54951
  }
54867
54952
  changedFiles.sort((a, b) => a.seq - b.seq);
@@ -55465,11 +55550,11 @@ var ctxStats = Object.freeze({
55465
55550
  });
55466
55551
 
55467
55552
  // src/core/tools/upgrade.ts
55468
- import { existsSync as existsSync23, realpathSync as realpathSync10, rmSync as rmSync11 } from "node:fs";
55553
+ import { existsSync as existsSync24, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
55469
55554
  import { basename as basename7, dirname as dirname12, join as join24 } from "node:path";
55470
55555
 
55471
55556
  // src/core/ops/host-write.ts
55472
- import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
55557
+ import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
55473
55558
  import { dirname as dirname11, join as join19 } from "node:path";
55474
55559
  function defaultWrite(file2, text) {
55475
55560
  writeFileSync5(file2, text, "utf8");
@@ -55498,7 +55583,7 @@ function toRow(file2, edit) {
55498
55583
  function writeWithRollback(file2, text, write, atomic) {
55499
55584
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
55500
55585
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
55501
- const had = existsSync18(file2);
55586
+ const had = existsSync19(file2);
55502
55587
  mkdirSync7(dirname11(file2), { recursive: true });
55503
55588
  if (had) copyFileSync(file2, trash);
55504
55589
  try {
@@ -55528,7 +55613,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
55528
55613
  if (requested === null) return [];
55529
55614
  const current = readHostConfig(row5.id, requested);
55530
55615
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
55531
- const exists = existsSync18(current.path);
55616
+ const exists = existsSync19(current.path);
55532
55617
  if (exists && result.text === current.text) return [];
55533
55618
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
55534
55619
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -55536,15 +55621,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
55536
55621
  }
55537
55622
 
55538
55623
  // src/core/ops/plugin-swap.ts
55539
- import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync9, readlinkSync, rmSync as rmSync7, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
55624
+ import { existsSync as existsSync20, lstatSync, readdirSync as readdirSync9, readlinkSync, rmSync as rmSync7, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
55540
55625
  import { basename as basename6, join as join20, win32 as win322 } from "node:path";
55541
- function linkTarget(path7, win) {
55542
- if (!isLink(path7)) return null;
55543
- const target = readlinkSync(path7);
55626
+ function linkTarget(path8, win) {
55627
+ if (!isLink(path8)) return null;
55628
+ const target = readlinkSync(path8);
55544
55629
  return win ? win322.basename(target) : target;
55545
55630
  }
55546
- function isLink(path7) {
55547
- return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
55631
+ function isLink(path8) {
55632
+ return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
55548
55633
  }
55549
55634
  function generations(agentDir) {
55550
55635
  return readdirSync9(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();
@@ -55557,7 +55642,7 @@ function settleLinks(link, tmp, old, opts) {
55557
55642
  }
55558
55643
  function swapPluginCurrent(agentDir, sha, opts = {}) {
55559
55644
  const next = join20(agentDir, sha);
55560
- if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
55645
+ if (!existsSync20(next) || !lstatSync(next).isDirectory()) {
55561
55646
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
55562
55647
  }
55563
55648
  const link = join20(agentDir, PLUGIN_CURRENT_LINK);
@@ -55577,12 +55662,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
55577
55662
  if (before !== null) keep.add(before);
55578
55663
  const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join20(agentDir, name));
55579
55664
  for (const dir of removed) rmSync7(dir, { recursive: true, force: true });
55580
- const previous = before !== null && existsSync19(join20(agentDir, before)) ? join20(agentDir, before) : null;
55665
+ const previous = before !== null && existsSync20(join20(agentDir, before)) ? join20(agentDir, before) : null;
55581
55666
  return { current: next, previous, removed };
55582
55667
  }
55583
55668
 
55584
55669
  // src/core/ops/release-fetch.ts
55585
- import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync8 } from "node:fs";
55670
+ import { existsSync as existsSync21, mkdirSync as mkdirSync8, rmSync as rmSync8 } from "node:fs";
55586
55671
  import { join as join21 } from "node:path";
55587
55672
  function failed(r) {
55588
55673
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -55606,7 +55691,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
55606
55691
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
55607
55692
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
55608
55693
  const dir = join21(agentDir, sha);
55609
- if (existsSync20(dir)) rmSync8(fetchDir, { recursive: true, force: true });
55694
+ if (existsSync21(dir)) rmSync8(fetchDir, { recursive: true, force: true });
55610
55695
  else renameWithRetry(fetchDir, dir, opts);
55611
55696
  return { sha, dir };
55612
55697
  } catch (e) {
@@ -55616,7 +55701,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
55616
55701
  }
55617
55702
 
55618
55703
  // src/core/ops/uninstall.ts
55619
- import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
55704
+ import { existsSync as existsSync22, readdirSync as readdirSync10, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
55620
55705
  import { join as join22 } from "node:path";
55621
55706
  function row2(area, before, after) {
55622
55707
  return { area, before, after };
@@ -55650,7 +55735,7 @@ function removeCache(adapter, env, configDir) {
55650
55735
  }
55651
55736
  case "plugin": {
55652
55737
  const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
55653
- if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
55738
+ if (!existsSync22(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
55654
55739
  rmSync9(agentDir, { recursive: true, force: true });
55655
55740
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
55656
55741
  }
@@ -55669,7 +55754,7 @@ function isObj3(v) {
55669
55754
  function piSource(entry) {
55670
55755
  return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
55671
55756
  }
55672
- function ownEntries(agent, env) {
55757
+ function ownEntries2(agent, env) {
55673
55758
  const home = requireHomeDir(env);
55674
55759
  const mcp = OWN_MCP_ENTRY[agent];
55675
55760
  if (mcp !== void 0) {
@@ -55677,10 +55762,10 @@ function ownEntries(agent, env) {
55677
55762
  const inner = mcp.key.slice(1, -1);
55678
55763
  const own4 = mcp.key[mcp.key.length - 1];
55679
55764
  const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
55680
- const without = (v, path7) => {
55765
+ const without = (v, path8) => {
55681
55766
  const o = v;
55682
- if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
55683
- return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
55767
+ if (path8.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
55768
+ return { ...o, [path8[0]]: without(o[path8[0]], path8.slice(1)) };
55684
55769
  };
55685
55770
  return [{
55686
55771
  file: ownMcpFileOf(agent, mcp.file, env, home),
@@ -55717,7 +55802,7 @@ function ownEntries(agent, env) {
55717
55802
  }
55718
55803
  function removeOwnEntries(agent, env) {
55719
55804
  const rows = [];
55720
- for (const entry of ownEntries(agent, env)) {
55805
+ for (const entry of ownEntries2(agent, env)) {
55721
55806
  const current = readHostConfig(agent, entry.file);
55722
55807
  if (current.text === "") continue;
55723
55808
  const value = hostConfigValueAt(parseHostConfig(agent, current.path, current.text, current.format), [entry.key]);
@@ -55730,7 +55815,7 @@ function removeOwnEntries(agent, env) {
55730
55815
  function removeProjectData(configDir, projectKey) {
55731
55816
  const projects = join22(configDir, PROJECTS_DIR_NAME);
55732
55817
  const dir = join22(projects, projectKey);
55733
- if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
55818
+ if (!existsSync22(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
55734
55819
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
55735
55820
  for (const name of readdirSync10(dir)) {
55736
55821
  if (name !== OWNERS_DIR_NAME) rmSync9(join22(dir, name), { recursive: true, force: true });
@@ -55746,7 +55831,7 @@ function runUninstall(input) {
55746
55831
  }
55747
55832
 
55748
55833
  // src/core/ops/v1-remove.ts
55749
- import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync13, rmSync as rmSync10 } from "node:fs";
55834
+ import { copyFileSync as copyFileSync2, existsSync as existsSync23, readFileSync as readFileSync14, rmSync as rmSync10 } from "node:fs";
55750
55835
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
55751
55836
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
55752
55837
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -55776,8 +55861,8 @@ function cutTomlTable(text, header) {
55776
55861
  function writeAtomic(file2, text) {
55777
55862
  atomicWriteFile(file2, text);
55778
55863
  }
55779
- function locate(doc, path7) {
55780
- const segs = path7.split(V1_KEY_PATH_SEP);
55864
+ function locate(doc, path8) {
55865
+ const segs = path8.split(V1_KEY_PATH_SEP);
55781
55866
  let cur = doc;
55782
55867
  for (const seg of segs.slice(0, -1)) {
55783
55868
  if (Array.isArray(cur)) cur = cur[Number(seg)];
@@ -55790,8 +55875,8 @@ function locate(doc, path7) {
55790
55875
  return null;
55791
55876
  }
55792
55877
  function stripJsonEntries(agent, file2, findings, kept, undo) {
55793
- const layout = hostLayout(readFileSync13(file2, "utf8"));
55794
- const text = hostText(readFileSync13(file2, "utf8"));
55878
+ const layout = hostLayout(readFileSync14(file2, "utf8"));
55879
+ const text = hostText(readFileSync14(file2, "utf8"));
55795
55880
  const doc = parseHostConfig(agent, file2, text, "jsonc");
55796
55881
  const hit = /* @__PURE__ */ new Set();
55797
55882
  const byContainer = /* @__PURE__ */ new Map();
@@ -55827,19 +55912,19 @@ function removeV1(agent, findings) {
55827
55912
  for (const f of findings) {
55828
55913
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
55829
55914
  else if (f.path === "") {
55830
- if (existsSync22(f.file)) {
55915
+ if (existsSync23(f.file)) {
55831
55916
  moveAside(f.file, undo);
55832
55917
  done.set(f, UPGRADE_REMOVED);
55833
55918
  } else done.set(f, UPGRADE_NOT_FOUND);
55834
55919
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
55835
55920
  }
55836
55921
  for (const [file2, list3] of entries) {
55837
- if (!existsSync22(file2)) {
55922
+ if (!existsSync23(file2)) {
55838
55923
  for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
55839
55924
  continue;
55840
55925
  }
55841
55926
  if (file2.endsWith(TOML_EXT)) {
55842
- const rawToml = readFileSync13(file2, "utf8");
55927
+ const rawToml = readFileSync14(file2, "utf8");
55843
55928
  const tomlLayout = hostLayout(rawToml);
55844
55929
  let text = hostText(rawToml);
55845
55930
  for (const f of list3) {
@@ -55867,7 +55952,7 @@ function removeV1(agent, findings) {
55867
55952
  },
55868
55953
  rollback() {
55869
55954
  for (const u of undo.splice(0).reverse()) {
55870
- if (!existsSync22(u.trash)) continue;
55955
+ if (!existsSync23(u.trash)) continue;
55871
55956
  rmSync10(u.target, { recursive: true, force: true });
55872
55957
  renameWithRetry(u.trash, u.target);
55873
55958
  }
@@ -55877,7 +55962,7 @@ function removeV1(agent, findings) {
55877
55962
 
55878
55963
  // src/core/ops/verify-sums.ts
55879
55964
  import { createHash as createHash2 } from "node:crypto";
55880
- import { lstatSync as lstatSync2, readdirSync as readdirSync11, readFileSync as readFileSync14 } from "node:fs";
55965
+ import { lstatSync as lstatSync2, readdirSync as readdirSync11, readFileSync as readFileSync15 } from "node:fs";
55881
55966
  import { join as join23 } from "node:path";
55882
55967
  function mismatch() {
55883
55968
  return new CtxError("BUNDLE_HASH_MISMATCH");
@@ -55909,14 +55994,14 @@ function verifySums(dir) {
55909
55994
  const sumsPath = join23(dir, RELEASE_SUMS_FILE);
55910
55995
  const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
55911
55996
  if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
55912
- const sums = parseSums(readFileSync14(sumsPath, "utf8"));
55997
+ const sums = parseSums(readFileSync15(sumsPath, "utf8"));
55913
55998
  const files = /* @__PURE__ */ new Map();
55914
55999
  walk2(dir, "", files);
55915
56000
  if (files.size !== sums.size) throw mismatch();
55916
56001
  for (const [rel, abs] of files) {
55917
56002
  const want = sums.get(rel);
55918
56003
  if (want === void 0) throw mismatch();
55919
- const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync14(abs)).digest(HASH_ENCODING);
56004
+ const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync15(abs)).digest(HASH_ENCODING);
55920
56005
  if (got !== want) throw mismatch();
55921
56006
  }
55922
56007
  }
@@ -55945,7 +56030,7 @@ function pluginRootRow(adapter, env) {
55945
56030
  }
55946
56031
  function isCurrent(agentDir, dir) {
55947
56032
  const link = join24(agentDir, PLUGIN_CURRENT_LINK);
55948
- return existsSync23(link) && realpathSync10.native(link) === realpathSync10.native(dir);
56033
+ return existsSync24(link) && realpathSync11.native(link) === realpathSync11.native(dir);
55949
56034
  }
55950
56035
  async function checkout(adapter, deps) {
55951
56036
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
@@ -56064,12 +56149,12 @@ function checkCall(tool, input) {
56064
56149
  }
56065
56150
 
56066
56151
  // src/entries/is-entry.ts
56067
- import { realpathSync as realpathSync11 } from "node:fs";
56152
+ import { realpathSync as realpathSync12 } from "node:fs";
56068
56153
  function isEntry(main, argv1, self) {
56069
56154
  if (main !== void 0) return main;
56070
56155
  if (argv1 === void 0 || argv1 === "") return false;
56071
56156
  try {
56072
- return realpathSync11(argv1) === realpathSync11(self);
56157
+ return realpathSync12(argv1) === realpathSync12(self);
56073
56158
  } catch {
56074
56159
  return false;
56075
56160
  }
@@ -56145,7 +56230,7 @@ function workspaceFromMeta(meta3) {
56145
56230
  }
56146
56231
  function realOrSame(p) {
56147
56232
  try {
56148
- return realpathSync12.native(p);
56233
+ return realpathSync13.native(p);
56149
56234
  } catch {
56150
56235
  return p;
56151
56236
  }
@@ -56193,7 +56278,7 @@ async function startServer(argv, env) {
56193
56278
  opening.catch(() => pending.delete(project.dbPath));
56194
56279
  }
56195
56280
  const db = await opening;
56196
- if (!existsSync24(db.path)) throw new CtxError("DB_GONE");
56281
+ if (!existsSync25(db.path)) throw new CtxError("DB_GONE");
56197
56282
  return db;
56198
56283
  }
56199
56284
  function stopMarker(configDir, projectKey) {
@@ -56201,7 +56286,7 @@ async function startServer(argv, env) {
56201
56286
  }
56202
56287
  function stopRequested() {
56203
56288
  const configDir = resolveConfigDir(process.env);
56204
- return held.some((db) => existsSync24(stopMarker(configDir, db.projectKey)));
56289
+ return held.some((db) => existsSync25(stopMarker(configDir, db.projectKey)));
56205
56290
  }
56206
56291
  async function journal(project, ctx, name, reply4) {
56207
56292
  const db = await ownDb(project);