context-mode 2.0.0-next.23 → 2.0.0-next.25

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,8 +7,8 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/entries/server.ts
9
9
  import { randomUUID } from "node:crypto";
10
- import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync11 } from "node:fs";
11
- import { dirname as dirname10, join as join21 } from "node:path";
10
+ import { existsSync as existsSync22, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
11
+ import { dirname as dirname11, join as join21 } from "node:path";
12
12
  import { fileURLToPath as fileURLToPath2 } from "node:url";
13
13
 
14
14
  // node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
@@ -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, path5) {
309
- if (!path5)
308
+ function getElementAtPath(obj, path7) {
309
+ if (!path7)
310
310
  return obj;
311
- return path5.reduce((acc, key) => acc?.[key], obj);
311
+ return path7.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(path5, issues) {
651
+ function prefixIssues(path7, issues) {
652
652
  return issues.map((iss) => {
653
653
  var _a5;
654
654
  (_a5 = iss).path ?? (_a5.path = []);
655
- iss.path.unshift(path5);
655
+ iss.path.unshift(path7);
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, path5 = []) => {
1116
+ const processError = (error43, path7 = []) => {
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 }, [...path5, ...issue4.path]));
1119
+ issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
1120
1120
  } else if (issue4.code === "invalid_key") {
1121
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
1121
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
1122
1122
  } else if (issue4.code === "invalid_element") {
1123
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
1123
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
1124
1124
  } else {
1125
- const fullpath = [...path5, ...issue4.path];
1125
+ const fullpath = [...path7, ...issue4.path];
1126
1126
  if (fullpath.length === 0) {
1127
1127
  fieldErrors._errors.push(mapper(issue4));
1128
1128
  } else {
@@ -3487,7 +3487,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
3487
3487
  var NONE = 0;
3488
3488
  var ASSUMED = 1;
3489
3489
  var PROVEN = 2;
3490
- function isRecursive(inst, stack, resolve5) {
3490
+ function isRecursive(inst, stack, resolve6) {
3491
3491
  const cached4 = recursive.get(inst);
3492
3492
  if (cached4 !== void 0)
3493
3493
  return cached4 ? PROVEN : NONE;
@@ -3497,7 +3497,7 @@ function isRecursive(inst, stack, resolve5) {
3497
3497
  let result = NONE;
3498
3498
  const check2 = (child) => {
3499
3499
  if (result !== PROVEN && child?._zod) {
3500
- const answer2 = isRecursive(child, stack, resolve5);
3500
+ const answer2 = isRecursive(child, stack, resolve6);
3501
3501
  if (answer2 > result)
3502
3502
  result = answer2;
3503
3503
  }
@@ -3508,7 +3508,7 @@ function isRecursive(inst, stack, resolve5) {
3508
3508
  const desc = Object.getOwnPropertyDescriptor(sh, key);
3509
3509
  if (spread && !desc.enumerable)
3510
3510
  continue;
3511
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve5) : NONE;
3511
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve6) : NONE;
3512
3512
  if (child > answer2)
3513
3513
  answer2 = child;
3514
3514
  }
@@ -3572,7 +3572,7 @@ function isRecursive(inst, stack, resolve5) {
3572
3572
  break;
3573
3573
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
3574
3574
  case "lazy": {
3575
- const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
3575
+ const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
3576
3576
  merge5(inner ? isRecursive(inner, stack, false) : ASSUMED);
3577
3577
  break;
3578
3578
  }
@@ -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, path5) {
7890
- if (!path5)
7889
+ function getElementAtPath2(obj, path7) {
7890
+ if (!path7)
7891
7891
  return obj;
7892
- return path5.reduce((acc, key) => acc?.[key], obj);
7892
+ return path7.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(path5, issues) {
8232
+ function prefixIssues2(path7, issues) {
8233
8233
  return issues.map((iss) => {
8234
8234
  var _a5;
8235
8235
  (_a5 = iss).path ?? (_a5.path = []);
8236
- iss.path.unshift(path5);
8236
+ iss.path.unshift(path7);
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, path5 = []) => {
8694
+ const processError = (error43, path7 = []) => {
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 }, [...path5, ...issue4.path]));
8697
+ issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
8698
8698
  } else if (issue4.code === "invalid_key") {
8699
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
8699
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
8700
8700
  } else if (issue4.code === "invalid_element") {
8701
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
8701
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
8702
8702
  } else {
8703
- const fullpath = [...path5, ...issue4.path];
8703
+ const fullpath = [...path7, ...issue4.path];
8704
8704
  if (fullpath.length === 0) {
8705
8705
  fieldErrors._errors.push(mapper(issue4));
8706
8706
  } else {
@@ -11016,7 +11016,7 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
11016
11016
  var NONE2 = 0;
11017
11017
  var ASSUMED2 = 1;
11018
11018
  var PROVEN2 = 2;
11019
- function isRecursive2(inst, stack, resolve5) {
11019
+ function isRecursive2(inst, stack, resolve6) {
11020
11020
  const cached4 = recursive2.get(inst);
11021
11021
  if (cached4 !== void 0)
11022
11022
  return cached4 ? PROVEN2 : NONE2;
@@ -11026,7 +11026,7 @@ function isRecursive2(inst, stack, resolve5) {
11026
11026
  let result = NONE2;
11027
11027
  const check2 = (child) => {
11028
11028
  if (result !== PROVEN2 && child?._zod) {
11029
- const answer2 = isRecursive2(child, stack, resolve5);
11029
+ const answer2 = isRecursive2(child, stack, resolve6);
11030
11030
  if (answer2 > result)
11031
11031
  result = answer2;
11032
11032
  }
@@ -11037,7 +11037,7 @@ function isRecursive2(inst, stack, resolve5) {
11037
11037
  const desc = Object.getOwnPropertyDescriptor(sh, key);
11038
11038
  if (spread && !desc.enumerable)
11039
11039
  continue;
11040
- const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve5) : NONE2;
11040
+ const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve6) : NONE2;
11041
11041
  if (child > answer2)
11042
11042
  answer2 = child;
11043
11043
  }
@@ -11101,7 +11101,7 @@ function isRecursive2(inst, stack, resolve5) {
11101
11101
  break;
11102
11102
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
11103
11103
  case "lazy": {
11104
- const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
11104
+ const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
11105
11105
  merge5(inner ? isRecursive2(inner, stack, false) : ASSUMED2);
11106
11106
  break;
11107
11107
  }
@@ -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 path5 = issue4.path.map(String);
16920
- const key = path5.length > 0 ? path5.join(".") : "_meta";
16921
- if (path5.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
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;
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, path5, reachable) => {
17248
+ const visit2 = (node3, path7, 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 || path5.length === 0) return `${pathName(path5)}: 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 || 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)`;
17253
17253
  const raw = schema[X_MCP_HEADER_KEY];
17254
- if (typeof raw !== "string" || raw.length === 0) return `${pathName(path5)}: x-mcp-header MUST be a non-empty string`;
17255
- if (!RFC9110_TOKEN.test(raw)) return `${pathName(path5)}: 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(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)`;
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(path5)}: 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(path7)}: 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: path5,
17263
+ path: path7,
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, [...path5, key], reachable);
17270
+ const fault$1 = visit2(child, [...path7, 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, [...path5, `<${k}>`], false);
17278
+ const fault$1 = visit2(branch, [...path7, `<${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(path5) {
17319
- return path5.length === 0 ? "<root>" : path5.join(".");
17318
+ function pathName(path7) {
17319
+ return path7.length === 0 ? "<root>" : path7.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, path5, vendor, unsupported) {
17608
+ function walkProperty(node3, path7, 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, path5, 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(`${path5}.${key}`);
17617
- } else unsupported.push(`${path5}.${key}`);
17616
+ else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path7}.${key}`);
17617
+ } else unsupported.push(`${path7}.${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, path5 = "") {
17635
- if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path5}[${index}]`));
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}]`));
17636
17636
  if (!isJsonObject(original) || !isJsonObject(parsed)) return [];
17637
17637
  return Object.entries(original).flatMap(([key, value]) => {
17638
- const childPath = path5 ? `${path5}.${key}` : key;
17638
+ const childPath = path7 ? `${path7}.${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
  });
@@ -17705,14 +17705,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
17705
17705
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
17706
17706
  }
17707
17707
  function sleep(ms, signal) {
17708
- return new Promise((resolve5, reject) => {
17708
+ return new Promise((resolve6, reject) => {
17709
17709
  if (signal?.aborted) {
17710
17710
  reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
17711
17711
  return;
17712
17712
  }
17713
17713
  const timer = setTimeout(() => {
17714
17714
  signal?.removeEventListener("abort", onAbort);
17715
- resolve5();
17715
+ resolve6();
17716
17716
  }, ms);
17717
17717
  const onAbort = () => {
17718
17718
  clearTimeout(timer);
@@ -18511,7 +18511,7 @@ var Protocol = class {
18511
18511
  const flowStartedAt = Date.now();
18512
18512
  let onAbort;
18513
18513
  let cleanupMessageId;
18514
- return new Promise((resolve5, reject) => {
18514
+ return new Promise((resolve6, reject) => {
18515
18515
  const earlyReject = (error42) => {
18516
18516
  reject(error42);
18517
18517
  };
@@ -18580,7 +18580,7 @@ var Protocol = class {
18580
18580
  }
18581
18581
  if (decoded.kind === "invalid") return reject(decoded.error);
18582
18582
  if (decoded.kind === "input_required") {
18583
- if (options?.allowInputRequired === true) return resolve5(manualInputRequiredValue(decoded));
18583
+ if (options?.allowInputRequired === true) return resolve6(manualInputRequiredValue(decoded));
18584
18584
  const flow = {
18585
18585
  codec,
18586
18586
  request: request2,
@@ -18592,11 +18592,11 @@ var Protocol = class {
18592
18592
  params
18593
18593
  }, resultSchema, legOptions)
18594
18594
  };
18595
- return resolve5(this._resolveNonCompleteResult(decoded, flow));
18595
+ return resolve6(this._resolveNonCompleteResult(decoded, flow));
18596
18596
  }
18597
18597
  const result = decoded.result;
18598
18598
  validateStandardSchema(resultSchema, result).then((parseResult) => {
18599
- if (parseResult.success) resolve5(parseResult.data);
18599
+ if (parseResult.success) resolve6(parseResult.data);
18600
18600
  else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request2.method}: ${parseResult.error}`));
18601
18601
  }, reject);
18602
18602
  });
@@ -21512,7 +21512,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
21512
21512
  ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
21513
21513
  const schOrFunc = root.refs[ref];
21514
21514
  if (schOrFunc) return schOrFunc;
21515
- let _sch = resolve5.call(this, root, ref);
21515
+ let _sch = resolve6.call(this, root, ref);
21516
21516
  if (_sch === void 0) {
21517
21517
  const schema = (_a5 = root.localRefs) === null || _a5 === void 0 ? void 0 : _a5[ref];
21518
21518
  const { schemaId } = this.opts;
@@ -21538,7 +21538,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
21538
21538
  function sameSchemaEnv(s1, s2) {
21539
21539
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
21540
21540
  }
21541
- function resolve5(root, ref) {
21541
+ function resolve6(root, ref) {
21542
21542
  let sch;
21543
21543
  while (typeof (sch = this.refs[ref]) == "string") ref = sch;
21544
21544
  return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
@@ -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(path5) {
21727
- let input = path5;
21726
+ function removeDotSegments(path7) {
21727
+ let input = path7;
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 [path5, query] = wsComponent.resourceName.split("?");
21881
- wsComponent.path = path5 && path5 !== "/" ? path5 : void 0;
21880
+ const [path7, query] = wsComponent.resourceName.split("?");
21881
+ wsComponent.path = path7 && path7 !== "/" ? path7 : void 0;
21882
21882
  wsComponent.query = query;
21883
21883
  wsComponent.resourceName = void 0;
21884
21884
  }
@@ -21988,7 +21988,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
21988
21988
  else if (typeof uri === "object") uri = parse6(serialize(uri, options), options);
21989
21989
  return uri;
21990
21990
  }
21991
- function resolve5(baseURI, relativeURI, options) {
21991
+ function resolve6(baseURI, relativeURI, options) {
21992
21992
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
21993
21993
  const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
21994
21994
  schemelessOptions.skipEscape = true;
@@ -22162,7 +22162,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
22162
22162
  const fastUri = {
22163
22163
  SCHEMES,
22164
22164
  normalize: normalize2,
22165
- resolve: resolve5,
22165
+ resolve: resolve6,
22166
22166
  resolveComponent,
22167
22167
  equal,
22168
22168
  serialize,
@@ -27627,7 +27627,7 @@ var StdioServerTransport = class {
27627
27627
  }
27628
27628
  send(message2) {
27629
27629
  if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
27630
- return new Promise((resolve5, reject) => {
27630
+ return new Promise((resolve6, reject) => {
27631
27631
  const json2 = serializeMessage(message2);
27632
27632
  let settled = false;
27633
27633
  const onError = (error42) => {
@@ -27642,14 +27642,14 @@ var StdioServerTransport = class {
27642
27642
  settled = true;
27643
27643
  this._stdout.off("error", onError);
27644
27644
  this._stdout.off("drain", onDrain);
27645
- resolve5();
27645
+ resolve6();
27646
27646
  };
27647
27647
  this._stdout.once("error", onError);
27648
27648
  if (this._stdout.write(json2)) {
27649
27649
  if (settled) return;
27650
27650
  settled = true;
27651
27651
  this._stdout.off("error", onError);
27652
- resolve5();
27652
+ resolve6();
27653
27653
  } else if (!settled) this._stdout.once("drain", onDrain);
27654
27654
  });
27655
27655
  }
@@ -27703,14 +27703,14 @@ var StdioConnectionChannel = class {
27703
27703
  */
27704
27704
  async whenRequestsAnswered(timeoutMs) {
27705
27705
  if (this._closed || this._pendingRequests.size === 0) return true;
27706
- return await new Promise((resolve5) => {
27706
+ return await new Promise((resolve6) => {
27707
27707
  const waiter = () => {
27708
27708
  clearTimeout(timer);
27709
- resolve5(true);
27709
+ resolve6(true);
27710
27710
  };
27711
27711
  const timer = setTimeout(() => {
27712
27712
  this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
27713
- resolve5(false);
27713
+ resolve6(false);
27714
27714
  }, timeoutMs);
27715
27715
  this._drainWaiters.push(waiter);
27716
27716
  });
@@ -28058,6 +28058,7 @@ var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscod
28058
28058
  var SERVER_KEY = "context-mode";
28059
28059
  var TOOL_ORDER = Object.freeze(["ctx_execute", "ctx_batch", "ctx_index", "ctx_search", "ctx_resume", "ctx_stats", "ctx_doctor", "ctx_upgrade", "ctx_purge"]);
28060
28060
  var OUTPUT_CAP = 16384;
28061
+ var EXEC_PREVIEW_BYTES = 4096;
28061
28062
  var STATE_BUDGET = 2048;
28062
28063
  var RESUME_CAP = 2048;
28063
28064
  var REPORT_CAP = 4096;
@@ -28224,7 +28225,7 @@ var TOOLS_TTL_MS = 36e5;
28224
28225
  var IN_PROCESS_TIMEOUT_MS = 0;
28225
28226
  var MS_PER_DAY = 864e5;
28226
28227
  var PROJECT_KEY_HEX_LEN = 16;
28227
- var SCHEMA_VERSION = 5;
28228
+ var SCHEMA_VERSION = 6;
28228
28229
  var RETENTION_IDLE_DAYS = 30;
28229
28230
  var RETENTION_SIZE_CAP_BYTES = 524288e3;
28230
28231
  var PROJECT_DEAD_IDLE_DAYS = 14;
@@ -28254,6 +28255,13 @@ var HOST_CONFIG_DIR_NAME = ".claude";
28254
28255
  var HOST_PLUGINS_DIR_NAME = "plugins";
28255
28256
  var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
28256
28257
  var PLUGIN_KEY_SEPARATOR = "@";
28258
+ var CLAUDE_PLUGIN_ROOT_ENV = "CLAUDE_PLUGIN_ROOT";
28259
+ var CLAUDE_PROJECT_DIR_ENV = "CLAUDE_PROJECT_DIR";
28260
+ var ENABLED_PLUGINS_KEY = "enabledPlugins";
28261
+ var SETTINGS_LOCAL_FILE = "settings.local.json";
28262
+ var DEFAULT_PLUGIN_SCOPE = "user";
28263
+ var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
28264
+ var PLUGIN_SCOPE_RANK = Object.freeze({ local: 0, project: 1, user: 2, managed: 2 });
28257
28265
  var MCP_HINT_EVERY_DEFAULT = 10;
28258
28266
  function readHintEvery(raw) {
28259
28267
  if (raw === void 0 || raw.trim() === "") return MCP_HINT_EVERY_DEFAULT;
@@ -28343,7 +28351,7 @@ var DECISION_SOURCE = "decision";
28343
28351
  var DECISION_USER_LABEL = "decision (user)";
28344
28352
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
28345
28353
  var RELEASE_BRANCH = "release";
28346
- var BUNDLE_SHA = true ? "68e0af5aafeaa4c61af68ee8d8e347cddb887f81" : void 0;
28354
+ var BUNDLE_SHA = true ? "58d6b744f8c640e9f43f03516d8bc50dc1292ae0" : void 0;
28347
28355
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
28348
28356
  var DOCTOR_LABEL = Object.freeze({
28349
28357
  D1: "version",
@@ -28500,6 +28508,13 @@ var D3_PART_JOIN = ", ";
28500
28508
  function D3_DETAIL(parts) {
28501
28509
  return `wrong: ${parts.join(D3_PART_JOIN)}`;
28502
28510
  }
28511
+ function D3_ROOT_DETAIL(paths) {
28512
+ return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
28513
+ }
28514
+ var D3_ROOT_FIX_JOIN = " or ";
28515
+ function D3_ROOT_FIX(installs) {
28516
+ return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
28517
+ }
28503
28518
  var HOOK_HOST_FILE = Object.freeze({
28504
28519
  "claude-code": { root: "plugin", file: ["hooks", "claude-code.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
28505
28520
  codex: { root: "home", file: [".codex", "hooks.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
@@ -28868,12 +28883,16 @@ CREATE VIRTUAL TABLE line_units USING fts5(
28868
28883
  ${FTS_TOKENIZE}
28869
28884
  );
28870
28885
  `;
28886
+ var DDL_V6 = `
28887
+ UPDATE sources SET label = replace(label, char(92), '/') WHERE kind = 'path' AND instr(label, char(92)) > 0;
28888
+ `;
28871
28889
  var MIGRATIONS = [
28872
28890
  { version: 1, sql: DDL },
28873
28891
  { version: 2, sql: DDL_V2 },
28874
28892
  { version: 3, sql: DDL_V3 },
28875
28893
  { version: 4, sql: DDL_V4 },
28876
- { version: 5, sql: DDL_V5 }
28894
+ { version: 5, sql: DDL_V5 },
28895
+ { version: 6, sql: DDL_V6 }
28877
28896
  ];
28878
28897
  function applyMigrations(db, fromVersion) {
28879
28898
  if (fromVersion === SCHEMA_VERSION2) return;
@@ -28927,9 +28946,9 @@ function readUserVersion(raw) {
28927
28946
  const row5 = raw.prepare("PRAGMA user_version").get();
28928
28947
  return row5.user_version;
28929
28948
  }
28930
- function createAtomically(sqlite, path5) {
28949
+ function createAtomically(sqlite, path7) {
28931
28950
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
28932
- const tmp = path5 + "." + randomUUID2() + DB_TMP_SUFFIX;
28951
+ const tmp = path7 + "." + randomUUID2() + DB_TMP_SUFFIX;
28933
28952
  try {
28934
28953
  const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
28935
28954
  try {
@@ -28938,7 +28957,7 @@ function createAtomically(sqlite, path5) {
28938
28957
  raw.close();
28939
28958
  }
28940
28959
  try {
28941
- linkSync(tmp, path5);
28960
+ linkSync(tmp, path7);
28942
28961
  } catch (err) {
28943
28962
  if (err.code !== "EEXIST") throw err;
28944
28963
  }
@@ -28946,11 +28965,11 @@ function createAtomically(sqlite, path5) {
28946
28965
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
28947
28966
  }
28948
28967
  }
28949
- function openWritable(sqlite, path5) {
28968
+ function openWritable(sqlite, path7) {
28950
28969
  let raw = null;
28951
28970
  try {
28952
- if (!existsSync(path5)) createAtomically(sqlite, path5);
28953
- raw = new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS });
28971
+ if (!existsSync(path7)) createAtomically(sqlite, path7);
28972
+ raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
28954
28973
  applyMigrations(raw, readUserVersion(raw));
28955
28974
  return raw;
28956
28975
  } catch (err) {
@@ -28958,8 +28977,8 @@ function openWritable(sqlite, path5) {
28958
28977
  throw err;
28959
28978
  }
28960
28979
  }
28961
- function openReadOnly(sqlite, path5) {
28962
- const raw = new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS, readOnly: true });
28980
+ function openReadOnly(sqlite, path7) {
28981
+ const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
28963
28982
  try {
28964
28983
  const found = readUserVersion(raw);
28965
28984
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -28973,20 +28992,20 @@ async function openDb(project, opts) {
28973
28992
  if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
28974
28993
  const sqlite = await loadSqlite();
28975
28994
  mkdirSync(project.projectDir, { recursive: true });
28976
- const path5 = project.dbPath;
28977
- const sibling = existsSync(path5 + DB_WAL_SUFFIX) || existsSync(path5 + DB_SHM_SUFFIX);
28978
- if (sibling && !existsSync(path5)) {
28995
+ const path7 = project.dbPath;
28996
+ const sibling = existsSync(path7 + DB_WAL_SUFFIX) || existsSync(path7 + DB_SHM_SUFFIX);
28997
+ if (sibling && !existsSync(path7)) {
28979
28998
  throw new CtxError("DB_GONE");
28980
28999
  }
28981
29000
  try {
28982
29001
  let raw;
28983
29002
  if (opts?.readOnly === true) {
28984
- if (!existsSync(path5)) openWritable(sqlite, path5).close();
28985
- raw = openReadOnly(sqlite, path5);
29003
+ if (!existsSync(path7)) openWritable(sqlite, path7).close();
29004
+ raw = openReadOnly(sqlite, path7);
28986
29005
  } else {
28987
- raw = openWritable(sqlite, path5);
29006
+ raw = openWritable(sqlite, path7);
28988
29007
  }
28989
- return { raw, projectKey: project.projectKey, path: path5, ...opts?.readOnly === true ? { readOnly: true } : {} };
29008
+ return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
28990
29009
  } catch (err) {
28991
29010
  if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
28992
29011
  throw err;
@@ -29118,7 +29137,7 @@ function installExitGuard(opts) {
29118
29137
  }
29119
29138
 
29120
29139
  // src/core/project/config-dir.ts
29121
- import { join, posix, win32 } from "node:path";
29140
+ import { basename, dirname, join, posix, resolve, win32 } from "node:path";
29122
29141
  var { mkdirSync: mkdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
29123
29142
  function homeDirOf(env, platform = process.platform) {
29124
29143
  const set3 = (v) => v !== void 0 && v !== "";
@@ -29134,6 +29153,20 @@ function codexDirOf(env, home) {
29134
29153
  const dir = env[CODEX_HOME_ENV];
29135
29154
  return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR.codex);
29136
29155
  }
29156
+ function codexPluginHomeOf(bundleDir2) {
29157
+ let dir = resolve(bundleDir2);
29158
+ while (dirname(dir) !== dir) {
29159
+ const up = dirname(dir);
29160
+ if (basename(dir) === PLUGIN_CACHE_DIR_NAME && basename(up) === HOST_PLUGINS_DIR_NAME) return dirname(up);
29161
+ dir = up;
29162
+ }
29163
+ return null;
29164
+ }
29165
+ function codexRunDirOf(env, home, bundleDir2) {
29166
+ const dir = env[CODEX_HOME_ENV];
29167
+ if (dir !== void 0 && dir !== "") return dir;
29168
+ return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
29169
+ }
29137
29170
  function copilotDirOf(env, home) {
29138
29171
  const dir = env[COPILOT_HOME_ENV];
29139
29172
  return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
@@ -29188,10 +29221,10 @@ function resolveConfigDir(env) {
29188
29221
  }
29189
29222
 
29190
29223
  // src/core/project/resolve.ts
29191
- import { basename, dirname as dirname2, join as join2, resolve } from "node:path";
29224
+ import { basename as basename2, dirname as dirname3, join as join2, resolve as resolve2 } from "node:path";
29192
29225
 
29193
29226
  // src/core/project/contain.ts
29194
- import { dirname, sep } from "node:path";
29227
+ import { dirname as dirname2, sep } from "node:path";
29195
29228
  var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
29196
29229
  function real(p) {
29197
29230
  try {
@@ -29228,7 +29261,7 @@ function commonRoot(paths) {
29228
29261
  n = i;
29229
29262
  }
29230
29263
  let q = first;
29231
- while (components(q).length > n && dirname(q) !== q) q = dirname(q);
29264
+ while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
29232
29265
  return q;
29233
29266
  }
29234
29267
 
@@ -29395,9 +29428,9 @@ function gitDirs(dir) {
29395
29428
  const gitDir = gitDirAt(join2(cur, GIT_DIR_NAME));
29396
29429
  if (gitDir !== null) {
29397
29430
  const common = firstLine(join2(gitDir, GIT_COMMONDIR_FILE));
29398
- return { commonDir: realpathSync3.native(common === null ? gitDir : resolve(gitDir, common)), worktree: cur, start };
29431
+ return { commonDir: realpathSync3.native(common === null ? gitDir : resolve2(gitDir, common)), worktree: cur, start };
29399
29432
  }
29400
- const up = dirname2(cur);
29433
+ const up = dirname3(cur);
29401
29434
  if (up === cur) return { commonDir: null, start };
29402
29435
  cur = up;
29403
29436
  }
@@ -29410,7 +29443,7 @@ function gitDirAt(dotGit) {
29410
29443
  } else {
29411
29444
  const line = firstLine(dotGit);
29412
29445
  if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
29413
- gitDir = resolve(dirname2(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
29446
+ gitDir = resolve2(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
29414
29447
  }
29415
29448
  } catch {
29416
29449
  return null;
@@ -29429,15 +29462,15 @@ function firstLine(file2) {
29429
29462
  return line === "" ? null : line;
29430
29463
  }
29431
29464
  function git(dir, args) {
29432
- const { spawnSync } = process.getBuiltinModule("node:child_process");
29433
- const r = spawnSync("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
29465
+ const { spawnSync: spawnSync3 } = process.getBuiltinModule("node:child_process");
29466
+ const r = spawnSync3("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
29434
29467
  if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
29435
29468
  return r.stdout.split("\n").filter((l) => l !== "");
29436
29469
  }
29437
29470
  function containmentRootOf(dir, commonDir) {
29438
- const repoDir = basename(commonDir) === GIT_DIR_NAME ? dirname2(commonDir) : commonDir;
29471
+ const repoDir = basename2(commonDir) === GIT_DIR_NAME ? dirname3(commonDir) : commonDir;
29439
29472
  const worktrees = git(dir, ["worktree", "list", "--porcelain"]).filter((l) => l.startsWith(GIT_WORKTREE_LINE_PREFIX)).map((l) => l.slice(GIT_WORKTREE_LINE_PREFIX.length));
29440
- return commonRoot([dirname2(repoDir), ...worktrees]);
29473
+ return commonRoot([dirname3(repoDir), ...worktrees]);
29441
29474
  }
29442
29475
  function resolveProject(agent, src) {
29443
29476
  const source = sourceOf(agent);
@@ -31727,7 +31760,7 @@ function ftsQuery(db, q, scope, ctx, sessionId, limit, offset, source) {
31727
31760
  }
31728
31761
  return page2.map((e) => {
31729
31762
  const r = rows.get(Number(e.r.rid));
31730
- return { sourceId: Number(r.source_id), label: r.label, ord: Number(r.ord), snippet: highlight(r.body, q, SNIPPET_MAX_BYTES), score: e.s };
31763
+ return { sourceId: Number(r.source_id), label: r.label, ord: Number(r.ord), snippet: highlight(r.body, q, SNIPPET_MAX_BYTES), score: e.s, full: e.full === 1 };
31731
31764
  });
31732
31765
  }
31733
31766
  var LIST = `
@@ -31896,17 +31929,29 @@ function parseSourceHandle(s) {
31896
31929
  }
31897
31930
  return n > 0 && sourceHandle(n) === s ? n : null;
31898
31931
  }
31932
+ function pathLabel(p) {
31933
+ return p.includes("\\") ? p.split("\\").join("/") : p;
31934
+ }
31935
+ function labelStored(db, label) {
31936
+ return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label) !== void 0;
31937
+ }
31938
+ function storedLabel(db, source) {
31939
+ if (labelStored(db, source)) return source;
31940
+ const canon = pathLabel(source);
31941
+ return canon !== source && labelStored(db, canon) ? canon : source;
31942
+ }
31899
31943
  function resolveSourceLabel(db, source) {
31900
31944
  const id = parseSourceHandle(source);
31901
31945
  if (id !== null) {
31902
31946
  const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = ?").get(id);
31903
31947
  if (row5 !== void 0) return row5.label;
31904
31948
  }
31905
- if (stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(source) !== void 0) return source;
31906
- const prefix = source + LABEL_SUFFIX_SEP;
31949
+ const named = storedLabel(db, source);
31950
+ if (labelStored(db, named)) return named;
31951
+ const prefix = named + LABEL_SUFFIX_SEP;
31907
31952
  const rows = stmt(db.raw, "SELECT label FROM sources WHERE substr(label, 1, ?) = ? ORDER BY id DESC").all(prefix.length, prefix);
31908
31953
  for (const r of rows) {
31909
- if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === source.length) return r.label;
31954
+ if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named.length) return r.label;
31910
31955
  }
31911
31956
  return source;
31912
31957
  }
@@ -31928,7 +31973,7 @@ function queryUnits(db, sessionId, q, limit) {
31928
31973
 
31929
31974
  // src/core/store/owners.ts
31930
31975
  import { mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync2, rmSync as rmSync2, writeFileSync } from "node:fs";
31931
- import { basename as basename2, join as join3 } from "node:path";
31976
+ import { basename as basename3, join as join3 } from "node:path";
31932
31977
  function ownersDir(configDir, projectKey) {
31933
31978
  return join3(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
31934
31979
  }
@@ -31976,7 +32021,7 @@ function listLiveOwners(configDir, projectKey) {
31976
32021
  if (errCode(err) === "ENOENT") continue;
31977
32022
  throw err;
31978
32023
  }
31979
- const serverId = basename2(name, OWNER_PID_EXT);
32024
+ const serverId = basename3(name, OWNER_PID_EXT);
31980
32025
  if (isLive(Number(text.trim()))) live.push(serverId);
31981
32026
  else rmSync2(file2, { force: true });
31982
32027
  }
@@ -32723,10 +32768,10 @@ function assignProp3(target, prop, value) {
32723
32768
  configurable: true
32724
32769
  });
32725
32770
  }
32726
- function getElementAtPath3(obj, path5) {
32727
- if (!path5)
32771
+ function getElementAtPath3(obj, path7) {
32772
+ if (!path7)
32728
32773
  return obj;
32729
- return path5.reduce((acc, key) => acc?.[key], obj);
32774
+ return path7.reduce((acc, key) => acc?.[key], obj);
32730
32775
  }
32731
32776
  function promiseAllObject3(promisesObj) {
32732
32777
  const keys = Object.keys(promisesObj);
@@ -33046,11 +33091,11 @@ function aborted3(x, startIndex = 0) {
33046
33091
  }
33047
33092
  return false;
33048
33093
  }
33049
- function prefixIssues3(path5, issues) {
33094
+ function prefixIssues3(path7, issues) {
33050
33095
  return issues.map((iss) => {
33051
33096
  var _a5;
33052
33097
  (_a5 = iss).path ?? (_a5.path = []);
33053
- iss.path.unshift(path5);
33098
+ iss.path.unshift(path7);
33054
33099
  return iss;
33055
33100
  });
33056
33101
  }
@@ -33187,7 +33232,7 @@ function treeifyError2(error42, _mapper) {
33187
33232
  return issue4.message;
33188
33233
  };
33189
33234
  const result = { errors: [] };
33190
- const processError = (error43, path5 = []) => {
33235
+ const processError = (error43, path7 = []) => {
33191
33236
  var _a5, _b;
33192
33237
  for (const issue4 of error43.issues) {
33193
33238
  if (issue4.code === "invalid_union" && issue4.errors.length) {
@@ -33197,7 +33242,7 @@ function treeifyError2(error42, _mapper) {
33197
33242
  } else if (issue4.code === "invalid_element") {
33198
33243
  processError({ issues: issue4.issues }, issue4.path);
33199
33244
  } else {
33200
- const fullpath = [...path5, ...issue4.path];
33245
+ const fullpath = [...path7, ...issue4.path];
33201
33246
  if (fullpath.length === 0) {
33202
33247
  result.errors.push(mapper(issue4));
33203
33248
  continue;
@@ -33227,9 +33272,9 @@ function treeifyError2(error42, _mapper) {
33227
33272
  processError(error42);
33228
33273
  return result;
33229
33274
  }
33230
- function toDotPath(path5) {
33275
+ function toDotPath(path7) {
33231
33276
  const segs = [];
33232
- for (const seg of path5) {
33277
+ for (const seg of path7) {
33233
33278
  if (typeof seg === "number")
33234
33279
  segs.push(`[${seg}]`);
33235
33280
  else if (typeof seg === "symbol")
@@ -43718,10 +43763,10 @@ function startArgv(argv) {
43718
43763
  return sh === null ? null : [sh, ...argv];
43719
43764
  }
43720
43765
  function runProcess(argv, o) {
43721
- return new Promise((resolve5) => {
43766
+ return new Promise((resolve6) => {
43722
43767
  const isWin2 = process.platform === "win32";
43723
43768
  const start = startArgv(argv);
43724
- if (start === null) return resolve5(NOT_STARTED);
43769
+ if (start === null) return resolve6(NOT_STARTED);
43725
43770
  let child;
43726
43771
  try {
43727
43772
  child = spawn(start[0], start.slice(1), {
@@ -43735,7 +43780,7 @@ function runProcess(argv, o) {
43735
43780
  windowsHide: true
43736
43781
  });
43737
43782
  } catch {
43738
- return resolve5(NOT_STARTED);
43783
+ return resolve6(NOT_STARTED);
43739
43784
  }
43740
43785
  const stdoutChunks = [];
43741
43786
  const stderrChunks = [];
@@ -43760,7 +43805,7 @@ function runProcess(argv, o) {
43760
43805
  settled = true;
43761
43806
  clearTimeout(timer);
43762
43807
  o.signal.removeEventListener("abort", onAbort);
43763
- resolve5({
43808
+ resolve6({
43764
43809
  stdout: Buffer.concat(stdoutChunks),
43765
43810
  stderr: Buffer.concat(stderrChunks),
43766
43811
  exitCode,
@@ -43792,19 +43837,19 @@ function readAutoMemory(project) {
43792
43837
  if (project.agent !== "claude-code") return [];
43793
43838
  const rows = [];
43794
43839
  for (const segs of CLAUDE_CODE_MEMORY_FILES) {
43795
- const path5 = join5(project.worktree, ...segs);
43796
- if (!isInside(project.worktree, path5)) continue;
43840
+ const path7 = join5(project.worktree, ...segs);
43841
+ if (!isInside(project.worktree, path7)) continue;
43797
43842
  try {
43798
- const st = statSync3(path5);
43843
+ const st = statSync3(path7);
43799
43844
  if (!st.isFile()) continue;
43800
43845
  rows.push({
43801
43846
  origin: "memory",
43802
43847
  ts: Math.trunc(st.mtimeMs),
43803
43848
  seq: null,
43804
43849
  sourceId: null,
43805
- path: path5,
43850
+ path: path7,
43806
43851
  label: segs.join("/"),
43807
- text: readFileSync3(path5, "utf8")
43852
+ text: readFileSync3(path7, "utf8")
43808
43853
  });
43809
43854
  } catch {
43810
43855
  }
@@ -43974,12 +44019,20 @@ function sourceBytes(db, ids) {
43974
44019
  }
43975
44020
  return out;
43976
44021
  }
44022
+ var LEAN_HITS = 3;
44023
+ function replyHits(hits, size) {
44024
+ if (hits.length === 0 || hits[0].full !== true) return Math.min(size, hits.length);
44025
+ let n = Math.min(LEAN_HITS, size, hits.length);
44026
+ while (n < size && n < hits.length && hits[n].full === true) n++;
44027
+ return n;
44028
+ }
43977
44029
  function relevance(db, given, scope, ctx) {
43978
44030
  const input = { ...given, queries: decisionQueries(given) };
43979
44031
  const offset = input.offset ?? 0;
43980
44032
  const size = pageSize(input);
43981
44033
  const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
43982
- const pages = fetched.map((h) => h.slice(0, size));
44034
+ const take = fetched.map((h) => replyHits(h, size));
44035
+ const pages = fetched.map((h, i) => h.slice(0, take[i]));
43983
44036
  if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
43984
44037
  const moreLine3 = (q, pos) => "More: " + callText([q], scope, input.source, "offset:" + pos);
43985
44038
  let reserve = 0;
@@ -43994,7 +44047,7 @@ function relevance(db, given, scope, ctx) {
43994
44047
  input.queries.forEach((q, qi) => {
43995
44048
  const hits = pages[qi];
43996
44049
  if (stopped) {
43997
- more.push(moreLine3(q, offset));
44050
+ more.push({ q, pos: offset });
43998
44051
  return;
43999
44052
  }
44000
44053
  const head = "Query " + JSON.stringify(q) + ":";
@@ -44032,10 +44085,14 @@ function relevance(db, given, scope, ctx) {
44032
44085
  lines.push(line);
44033
44086
  used += bytes2(line) + 1;
44034
44087
  }
44035
- if (cut >= 0) more.push(moreLine3(q, cut));
44036
- else if (fetched[qi].length > size) more.push(moreLine3(q, offset + size));
44088
+ if (cut >= 0) more.push({ q, pos: cut });
44089
+ else if (fetched[qi].length > take[qi]) more.push({ q, pos: offset + take[qi] });
44037
44090
  });
44038
- return reply(lines.concat(more).join("\n"), false);
44091
+ const moreLines = [];
44092
+ const byPos = /* @__PURE__ */ new Map();
44093
+ for (const m of more) byPos.set(m.pos, [...byPos.get(m.pos) ?? [], m.q]);
44094
+ for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope, input.source, "offset:" + pos));
44095
+ return reply(lines.concat(moreLines).join("\n"), false);
44039
44096
  }
44040
44097
  function timelineLine(r) {
44041
44098
  const nl = r.text.indexOf("\n");
@@ -44175,6 +44232,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
44175
44232
  const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
44176
44233
  const display = shown(chunks, ran.map((r) => r.head));
44177
44234
  const bodies = /* @__PURE__ */ new Map();
44235
+ const raw = /* @__PURE__ */ new Map();
44178
44236
  let total = 0;
44179
44237
  for (const c of chunks) total += c.bytes;
44180
44238
  let indexed = 0;
@@ -44195,7 +44253,10 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
44195
44253
  chunkCount: group.length,
44196
44254
  createdAt: Date.now()
44197
44255
  }, group);
44198
- for (const c of group) bodies.set(chunkKey(id, c.ord), display[c.ord]);
44256
+ for (const c of group) {
44257
+ bodies.set(chunkKey(id, c.ord), display[c.ord]);
44258
+ raw.set(chunkKey(id, c.ord), c.text);
44259
+ }
44199
44260
  indexed += groupBytes;
44200
44261
  group = [];
44201
44262
  groupBytes = 0;
@@ -44204,15 +44265,15 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
44204
44265
  for (const c of chunks) {
44205
44266
  if (queued + c.bytes > budgetBytes) {
44206
44267
  const stop2 = flush() ? "budget" : "deadline";
44207
- return { bodies, indexed, total, stop: stop2 };
44268
+ return { bodies, raw, indexed, total, stop: stop2 };
44208
44269
  }
44209
- if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, indexed, total, stop: "deadline" };
44270
+ if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, indexed, total, stop: "deadline" };
44210
44271
  group.push(c);
44211
44272
  groupBytes += c.bytes;
44212
44273
  queued += c.bytes;
44213
44274
  }
44214
44275
  const stop = flush() ? null : "deadline";
44215
- return { bodies, indexed, total, stop };
44276
+ return { bodies, raw, indexed, total, stop };
44216
44277
  }
44217
44278
  function bytes3(s) {
44218
44279
  return Buffer.byteLength(s, "utf8");
@@ -44245,7 +44306,7 @@ function answer(db, ctx, label, queries, share, own4) {
44245
44306
  else if (body.length === 0) body.push("No new section.");
44246
44307
  lines.push(head, ...body);
44247
44308
  }
44248
- return lines;
44309
+ return { lines, seen };
44249
44310
  }
44250
44311
  async function runBatch(input, ctx, boundMs, budgetBytes) {
44251
44312
  const parsed = ctxBatchSchema.safeParse(input);
@@ -44266,9 +44327,10 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
44266
44327
  const db = await openDb(ctx.project);
44267
44328
  let sections;
44268
44329
  let idx;
44269
- const summary = commands.length + " command(s), " + queries.length + " querie(s), exit " + last2.exitCode;
44330
+ const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
44270
44331
  const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label) + "})";
44271
44332
  let notice;
44333
+ let showMore;
44272
44334
  try {
44273
44335
  idx = indexCombined(db, ctx, label, ran, deadline, budgetBytes);
44274
44336
  const stop = last2.error;
@@ -44276,13 +44338,21 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
44276
44338
  const timeout = formatError3("TIMEOUT", { ms: boundMs });
44277
44339
  const cause = stop ?? (ctx.signal.aborted ? CANCELLED_LINE : idx.stop === "deadline" ? timeout : null);
44278
44340
  notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
44279
- const fixed = bytes3(summary) + 1 + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
44341
+ const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
44280
44342
  const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
44281
- sections = answer(db, ctx, label, queries, share, idx.bodies);
44343
+ const answered = answer(db, ctx, label, queries, share, idx.bodies);
44344
+ sections = answered.lines;
44345
+ const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
44346
+ const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
44347
+ if (unseen.length === 0 && cut === null) showMore = false;
44348
+ else if (cut === null && unseenBytes <= bytes3(footer) + 1) {
44349
+ showMore = false;
44350
+ sections = [...sections, ...unseen.map((t) => t.endsWith(LINE_SEP) ? t.slice(0, -1) : t)];
44351
+ } else showMore = true;
44282
44352
  } finally {
44283
44353
  closeDb(db);
44284
44354
  }
44285
- const lines = [summary, ...notice === null ? [] : [notice], ...sections, footer];
44355
+ const lines = [...exitLine === null ? [] : [exitLine], ...notice === null ? [] : [notice], ...sections, ...showMore ? [footer] : []];
44286
44356
  return {
44287
44357
  text: capBytes(lines.join(LINE_SEP), OUTPUT_CAP).text,
44288
44358
  // step 10: final bound (D-M2-6)
@@ -44306,8 +44376,8 @@ var ctxBatch = Object.freeze({
44306
44376
  });
44307
44377
 
44308
44378
  // src/core/tools/doctor.ts
44309
- import { readdirSync as readdirSync6, readFileSync as readFileSync8, existsSync as existsSync12 } from "node:fs";
44310
- import { basename as basename3, dirname as dirname5, join as join11 } from "node:path";
44379
+ import { readdirSync as readdirSync6, readFileSync as readFileSync8, existsSync as existsSync13 } from "node:fs";
44380
+ import { basename as basename4, dirname as dirname6, join as join11 } from "node:path";
44311
44381
 
44312
44382
  // src/adapters/claude-code.ts
44313
44383
  var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
@@ -45206,7 +45276,7 @@ import { join as join7 } from "node:path";
45206
45276
 
45207
45277
  // src/core/ops/host-config.ts
45208
45278
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
45209
- import { dirname as dirname3, join as join6 } from "node:path";
45279
+ import { dirname as dirname4, join as join6 } from "node:path";
45210
45280
 
45211
45281
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
45212
45282
  var KEYS2 = {
@@ -47338,15 +47408,15 @@ function withLayout(text, layout) {
47338
47408
  }
47339
47409
 
47340
47410
  // src/core/ops/host-config.ts
47341
- function formatOf(path5) {
47342
- if (path5.endsWith(JSONC_EXT)) return "jsonc";
47343
- if (path5.endsWith(TOML_EXT)) return "toml";
47411
+ function formatOf(path7) {
47412
+ if (path7.endsWith(JSONC_EXT)) return "jsonc";
47413
+ if (path7.endsWith(TOML_EXT)) return "toml";
47344
47414
  return "json";
47345
47415
  }
47346
- function readHostConfig(agent, path5) {
47347
- let file2 = path5;
47416
+ function readHostConfig(agent, path7) {
47417
+ let file2 = path7;
47348
47418
  if (agent === "opencode") {
47349
- const jsonc = join6(dirname3(path5), OPENCODE_CONFIG_FILES[0]);
47419
+ const jsonc = join6(dirname4(path7), OPENCODE_CONFIG_FILES[0]);
47350
47420
  if (existsSync4(jsonc)) file2 = jsonc;
47351
47421
  }
47352
47422
  const raw = existsSync4(file2) ? readFileSync4(file2, "utf8") : "";
@@ -47510,14 +47580,14 @@ function scanToml(text) {
47510
47580
  continue;
47511
47581
  }
47512
47582
  if (!node3.resolvedKey.every((seg) => typeof seg === "string")) continue;
47513
- const path5 = node3.resolvedKey;
47514
- for (const kv of node3.body) addKey(path5, kv);
47583
+ const path7 = node3.resolvedKey;
47584
+ for (const kv of node3.body) addKey(path7, kv);
47515
47585
  if (node3.kind !== "standard") continue;
47516
47586
  const start = lineStartOf(text, node3.range[0]);
47517
47587
  const headEnd = lineEndOf(text, node3.key.range[1]);
47518
47588
  const last2 = node3.body[node3.body.length - 1];
47519
47589
  tables.push({
47520
- path: path5,
47590
+ path: path7,
47521
47591
  header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
47522
47592
  start,
47523
47593
  end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
@@ -47528,16 +47598,16 @@ function scanToml(text) {
47528
47598
  function tomlTableSpans(text) {
47529
47599
  return scanToml(text).tables;
47530
47600
  }
47531
- function parseHostConfig(agent, path5, text, format) {
47601
+ function parseHostConfig(agent, path7, text, format) {
47532
47602
  try {
47533
47603
  return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
47534
47604
  } catch {
47535
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path5, format });
47605
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
47536
47606
  }
47537
47607
  }
47538
- function hostConfigValueAt(value, path5) {
47608
+ function hostConfigValueAt(value, path7) {
47539
47609
  let cur = value;
47540
- for (const seg of path5) {
47610
+ for (const seg of path7) {
47541
47611
  if (!isPlainObject6(cur)) return void 0;
47542
47612
  cur = cur[seg];
47543
47613
  }
@@ -47570,32 +47640,32 @@ function indentUnit(root, clean) {
47570
47640
  function render(value, unit, base) {
47571
47641
  return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
47572
47642
  }
47573
- function nest(path5, value) {
47643
+ function nest(path7, value) {
47574
47644
  let out = value;
47575
- for (let k = path5.length - 1; k >= 0; k -= 1) out = { [path5[k]]: out };
47645
+ for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
47576
47646
  return out;
47577
47647
  }
47578
- function setJsonText(text, format, path5, value) {
47648
+ function setJsonText(text, format, path7, value) {
47579
47649
  const doc = scanJson(text, format);
47580
47650
  const unit = indentUnit(doc.root, doc.clean);
47581
- if (doc.root === null) return render(nest(path5, value), unit, "") + "\n";
47651
+ if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
47582
47652
  let node3 = doc.root;
47583
47653
  let depth = 0;
47584
- while (depth < path5.length && node3.kind === "object") {
47585
- const hit = node3.members.find((m) => m.key === path5[depth]);
47654
+ while (depth < path7.length && node3.kind === "object") {
47655
+ const hit = node3.members.find((m) => m.key === path7[depth]);
47586
47656
  if (hit === void 0) break;
47587
47657
  node3 = hit.node;
47588
47658
  depth += 1;
47589
47659
  }
47590
- if (depth === path5.length) {
47660
+ if (depth === path7.length) {
47591
47661
  return text.slice(0, node3.start) + render(value, unit, lineIndent(doc.clean, node3.start)) + text.slice(node3.end);
47592
47662
  }
47593
- if (node3.kind !== "object") throw new SyntaxError("not an object at " + path5.slice(0, depth).join("."));
47594
- const rest = nest(path5.slice(depth + 1), value);
47663
+ if (node3.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
47664
+ const rest = nest(path7.slice(depth + 1), value);
47595
47665
  const last2 = node3.members[node3.members.length - 1];
47596
47666
  if (last2 === void 0) {
47597
47667
  const base2 = lineIndent(doc.clean, node3.start);
47598
- const member2 = "\n" + base2 + unit + JSON.stringify(path5[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
47668
+ const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
47599
47669
  return text.slice(0, node3.start + 1) + member2 + text.slice(node3.end - 1);
47600
47670
  }
47601
47671
  const base = lineIndent(doc.clean, last2.keyStart);
@@ -47603,7 +47673,7 @@ function setJsonText(text, format, path5, value) {
47603
47673
  while (" \r\n".includes(doc.clean[at])) at += 1;
47604
47674
  const trailing = doc.clean[at] === ",";
47605
47675
  const insertAt = trailing ? at + 1 : last2.node.end;
47606
- const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path5[depth]) + ": " + render(rest, unit, base);
47676
+ const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
47607
47677
  return text.slice(0, insertAt) + member + text.slice(insertAt);
47608
47678
  }
47609
47679
  function tomlScalar(v) {
@@ -47621,17 +47691,17 @@ function tomlHeaderKey(seg) {
47621
47691
  }
47622
47692
  return seg;
47623
47693
  }
47624
- function tomlBlock(path5, value) {
47625
- let out = "[" + path5.map(tomlHeaderKey).join(".") + "]\n";
47694
+ function tomlBlock(path7, value) {
47695
+ let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
47626
47696
  const subs = [];
47627
47697
  for (const [k, v] of Object.entries(value)) {
47628
- if (isPlainObject6(v)) subs.push(tomlBlock([...path5, k], v));
47698
+ if (isPlainObject6(v)) subs.push(tomlBlock([...path7, k], v));
47629
47699
  else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
47630
47700
  }
47631
47701
  return [out, ...subs].join("\n");
47632
47702
  }
47633
- function under(path5, prefix) {
47634
- return path5.length >= prefix.length && prefix.every((seg, k) => path5[k] === seg);
47703
+ function under(path7, prefix) {
47704
+ return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
47635
47705
  }
47636
47706
  function keyLineRange(text, k) {
47637
47707
  const ls = lineStartOf(text, k.start);
@@ -47648,10 +47718,10 @@ function withValueAt(root, rel, value) {
47648
47718
  else base[rel[0]] = next;
47649
47719
  return base;
47650
47720
  }
47651
- function replaceToml(text, doc, path5, value) {
47652
- const block = value === void 0 ? "" : tomlBlock(path5, value);
47653
- const owned = doc.tables.filter((t) => under(t.path, path5));
47654
- const cuts = doc.keys.filter((k) => under(k.full, path5) && !under(k.base, path5)).map((k) => [...keyLineRange(text, k), ""]);
47721
+ function replaceToml(text, doc, path7, value) {
47722
+ const block = value === void 0 ? "" : tomlBlock(path7, value);
47723
+ const owned = doc.tables.filter((t) => under(t.path, path7));
47724
+ const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
47655
47725
  owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
47656
47726
  cuts.sort((a, b) => b[0] - a[0]);
47657
47727
  let out = text;
@@ -47661,27 +47731,27 @@ function replaceToml(text, doc, path5, value) {
47661
47731
  return out + sep3 + block;
47662
47732
  }
47663
47733
  var tableLike = (v) => v === void 0 || isPlainObject6(v);
47664
- function setTomlText(text, path5, value) {
47734
+ function setTomlText(text, path7, value) {
47665
47735
  if (value !== void 0 && !isPlainObject6(value)) throw new SyntaxError("TOML edits replace a whole table");
47666
47736
  const doc = scanToml(text);
47667
- const cur = hostConfigValueAt(doc.value, path5);
47737
+ const cur = hostConfigValueAt(doc.value, path7);
47668
47738
  if (sameValue(cur, value)) return text;
47669
- const inline = doc.keys.find((k) => k.inline && k.full.length < path5.length && under(path5, k.full));
47739
+ const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
47670
47740
  if (inline !== void 0) {
47671
- const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path5.slice(inline.full.length), value);
47741
+ const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
47672
47742
  return replaceToml(text, doc, inline.full, whole);
47673
47743
  }
47674
47744
  if (isPlainObject6(cur) && isPlainObject6(value)) {
47675
47745
  const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
47676
47746
  if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
47677
47747
  let out = text;
47678
- for (const k of names) out = setTomlText(out, [...path5, k], value[k]);
47748
+ for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
47679
47749
  return out;
47680
47750
  }
47681
47751
  }
47682
- return replaceToml(text, doc, path5, value);
47752
+ return replaceToml(text, doc, path7, value);
47683
47753
  }
47684
- function setText(agent, path5, text, format, key, value) {
47754
+ function setText(agent, path7, text, format, key, value) {
47685
47755
  try {
47686
47756
  if (format !== "toml") return setJsonText(text, format, key, value);
47687
47757
  const out = setTomlText(text, key, value);
@@ -47690,11 +47760,11 @@ function setText(agent, path5, text, format, key, value) {
47690
47760
  if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
47691
47761
  return out;
47692
47762
  } catch {
47693
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path5, format });
47763
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
47694
47764
  }
47695
47765
  }
47696
47766
  function serverScript() {
47697
- return join6(dirname3(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
47767
+ return join6(dirname4(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
47698
47768
  }
47699
47769
  function isNodeCommand(command) {
47700
47770
  if (typeof command !== "string") return false;
@@ -47710,7 +47780,7 @@ function ownMcpValue(agent, node3, server) {
47710
47780
  return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
47711
47781
  }
47712
47782
  function opencodePluginFile() {
47713
- return dirname3(process.argv[1] ?? "");
47783
+ return dirname4(process.argv[1] ?? "");
47714
47784
  }
47715
47785
  function listTarget(key, own4, v1, alt = []) {
47716
47786
  return {
@@ -47737,14 +47807,14 @@ function ownTargets(agent, accept) {
47737
47807
  if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
47738
47808
  return [];
47739
47809
  }
47740
- function applyEdits(agent, path5, text, format, wanted) {
47741
- const parsed = parseHostConfig(agent, path5, text, format);
47810
+ function applyEdits(agent, path7, text, format, wanted) {
47811
+ const parsed = parseHostConfig(agent, path7, text, format);
47742
47812
  let out = text;
47743
47813
  const edits = [];
47744
47814
  for (const [key, after] of wanted) {
47745
47815
  const before = hostConfigValueAt(parsed, key);
47746
47816
  if (sameValue(before, after)) continue;
47747
- out = setText(agent, path5, out, format, key, after);
47817
+ out = setText(agent, path7, out, format, key, after);
47748
47818
  edits.push({ path: key.join("."), before, after });
47749
47819
  }
47750
47820
  return { text: out, format, edits };
@@ -47765,7 +47835,7 @@ function writeHostConfigEdit(_requested, current, patch) {
47765
47835
  // src/core/ops/detect-v1.ts
47766
47836
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
47767
47837
  var keyPath = (...parts) => parts.join(".");
47768
- var finding = (file2, path5, reason) => ({ file: file2, path: path5, reason });
47838
+ var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
47769
47839
  function stripJsonc(text) {
47770
47840
  let out = "";
47771
47841
  let inStr = false;
@@ -48070,20 +48140,23 @@ function detectV1(agent, home, scope = {}) {
48070
48140
 
48071
48141
  // src/core/ops/plugin-root.ts
48072
48142
  import { existsSync as existsSync6, readdirSync as readdirSync4, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
48073
- import { dirname as dirname4, isAbsolute, join as join8, sep as sep2 } from "node:path";
48143
+ import { dirname as dirname5, isAbsolute, join as join8, sep as sep2 } from "node:path";
48074
48144
  import { fileURLToPath } from "node:url";
48075
- function missing(agent, path5) {
48076
- return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path5 });
48145
+ function missing(agent, path7) {
48146
+ return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
48077
48147
  }
48078
- function recordedInstallPaths(text) {
48079
- let parsed;
48148
+ var parseOrNull = (text) => {
48080
48149
  try {
48081
- parsed = JSON.parse(hostText(text));
48150
+ return JSON.parse(hostText(text));
48082
48151
  } catch {
48083
- return [];
48152
+ return null;
48084
48153
  }
48085
- const plugins = parsed?.plugins;
48086
- if (plugins === null || typeof plugins !== "object") return [];
48154
+ };
48155
+ var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
48156
+ function recordedInstalls(text) {
48157
+ const parsed = parseOrNull(text);
48158
+ const plugins = isRecord3(parsed) ? parsed.plugins : void 0;
48159
+ if (!isRecord3(plugins)) return [];
48087
48160
  const out = [];
48088
48161
  for (const key of Object.keys(plugins)) {
48089
48162
  const at = key.indexOf(PLUGIN_KEY_SEPARATOR);
@@ -48091,39 +48164,77 @@ function recordedInstallPaths(text) {
48091
48164
  const entries = plugins[key];
48092
48165
  if (!Array.isArray(entries)) continue;
48093
48166
  for (const e of entries) {
48094
- const dir = e?.installPath;
48095
- if (typeof dir === "string" && dir !== "" && !out.includes(dir)) out.push(dir);
48167
+ if (!isRecord3(e) || typeof e.installPath !== "string" || e.installPath === "") continue;
48168
+ const scope = typeof e.scope === "string" ? e.scope : DEFAULT_PLUGIN_SCOPE;
48169
+ const projectPath = typeof e.projectPath === "string" ? e.projectPath : void 0;
48170
+ out.push({ key, scope, projectPath, installPath: e.installPath });
48096
48171
  }
48097
48172
  }
48098
48173
  return out;
48099
48174
  }
48100
- var realOrNull = (path5) => {
48175
+ var realOrNull = (path7) => {
48101
48176
  try {
48102
- return realpathSync4.native(path5);
48177
+ return realpathSync4.native(path7);
48103
48178
  } catch {
48104
48179
  return null;
48105
48180
  }
48106
48181
  };
48107
- function marketplaceRoot(adapter, env) {
48108
- const claudeDir = claudeDirOf(env, requireHomeDir(env));
48109
- const plugins = join8(claudeDir, HOST_PLUGINS_DIR_NAME);
48110
- const cache = join8(plugins, PLUGIN_CACHE_DIR_NAME);
48111
- const script = process.argv[1];
48112
- const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname4(script));
48113
- let record6 = null;
48182
+ var readOrNull = (file2) => {
48114
48183
  try {
48115
- record6 = readFileSync6(join8(plugins, INSTALLED_PLUGINS_FILE), "utf8");
48184
+ return readFileSync6(file2, "utf8");
48116
48185
  } catch {
48117
- record6 = null;
48186
+ return null;
48118
48187
  }
48119
- const recorded = record6 === null ? [] : recordedInstallPaths(record6);
48120
- if (recorded.length > 0) {
48121
- const live = recorded.filter((dir) => existsSync6(dir));
48122
- const mine = live.find((dir) => realOrNull(dir) === ownReal);
48123
- if (mine !== void 0) return mine;
48124
- if (live.length === 1) return live[0];
48125
- throw missing(adapter.id, recorded.join(", "));
48188
+ };
48189
+ var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
48190
+ function enabledPlugins(claudeDir, project) {
48191
+ const files = [join8(claudeDir, SETTINGS_FILE)];
48192
+ if (project !== void 0) files.push(join8(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join8(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
48193
+ const out = {};
48194
+ for (const file2 of files) {
48195
+ const text = readOrNull(file2);
48196
+ const doc = text === null ? null : parseOrNull(text);
48197
+ const on = isRecord3(doc) ? doc[ENABLED_PLUGINS_KEY] : void 0;
48198
+ if (isRecord3(on)) Object.assign(out, on);
48126
48199
  }
48200
+ return out;
48201
+ }
48202
+ function marketplaceChoice(env, worktree) {
48203
+ const claudeDir = claudeDirOf(env, requireHomeDir(env));
48204
+ const script = process.argv[1];
48205
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
48206
+ const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
48207
+ if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
48208
+ const record6 = readOrNull(join8(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
48209
+ const recorded = record6 === null ? [] : recordedInstalls(record6);
48210
+ if (recorded.length === 0) return { record: false };
48211
+ const live = recorded.filter((r) => existsSync6(r.installPath));
48212
+ const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
48213
+ if (mine !== void 0) return { root: mine.installPath };
48214
+ const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
48215
+ if (dirs.length === 1) return { root: dirs[0].installPath };
48216
+ const projectEnv = env[CLAUDE_PROJECT_DIR_ENV];
48217
+ const project = worktree ?? (projectEnv === void 0 || projectEnv === "" ? void 0 : projectEnv);
48218
+ const on = enabledPlugins(claudeDir, project);
48219
+ const applies = (r) => !PROJECT_PLUGIN_SCOPES.includes(r.scope) || project !== void 0 && r.projectPath !== void 0 && samePath(r.projectPath, project);
48220
+ const rank = (r) => PLUGIN_SCOPE_RANK[r.scope] ?? PLUGIN_SCOPE_RANK[DEFAULT_PLUGIN_SCOPE];
48221
+ const used = live.filter((r) => on[r.key] === true && applies(r));
48222
+ if (used.length > 0) {
48223
+ const best = Math.min(...used.map(rank));
48224
+ const top = used.filter((r) => rank(r) === best);
48225
+ if (top.every((r) => samePath(r.installPath, top[0].installPath))) return { root: top[0].installPath };
48226
+ }
48227
+ return { installs: live.length === 0 ? recorded : live };
48228
+ }
48229
+ function marketplaceRoot(adapter, env, worktree) {
48230
+ const claudeDir = claudeDirOf(env, requireHomeDir(env));
48231
+ const plugins = join8(claudeDir, HOST_PLUGINS_DIR_NAME);
48232
+ const cache = join8(plugins, PLUGIN_CACHE_DIR_NAME);
48233
+ const script = process.argv[1];
48234
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
48235
+ const choice = marketplaceChoice(env, worktree);
48236
+ if ("root" in choice) return choice.root;
48237
+ if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
48127
48238
  const cacheReal = realOrNull(cache);
48128
48239
  if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync6(join8(ownReal, SERVER_ENTRY_FILE))) return ownReal;
48129
48240
  const pattern = join8(cache, "*", PLUGIN_NAME);
@@ -48142,12 +48253,12 @@ function configEntryRoot(adapter, env) {
48142
48253
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
48143
48254
  const script = Array.isArray(args) ? args[0] : void 0;
48144
48255
  if (typeof script !== "string" || !isAbsolute(script)) throw missing(adapter.id, file2);
48145
- return dirname4(script);
48256
+ return dirname5(script);
48146
48257
  }
48147
- function candidate(adapter, env) {
48258
+ function candidate(adapter, env, worktree) {
48148
48259
  switch (adapter.installMode) {
48149
48260
  case "marketplace":
48150
- return marketplaceRoot(adapter, env);
48261
+ return marketplaceRoot(adapter, env, worktree);
48151
48262
  case "config-mcp":
48152
48263
  case "mcp-entry":
48153
48264
  case "hooks+mcp":
@@ -48157,15 +48268,15 @@ function candidate(adapter, env) {
48157
48268
  case "plugin":
48158
48269
  return join8(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
48159
48270
  case "in-process":
48160
- return dirname4(fileURLToPath(import.meta.url));
48271
+ return dirname5(fileURLToPath(import.meta.url));
48161
48272
  }
48162
48273
  }
48163
- function resolvePluginRoot(adapter, env) {
48164
- const path5 = candidate(adapter, env);
48274
+ function resolvePluginRoot(adapter, env, worktree) {
48275
+ const path7 = candidate(adapter, env, worktree);
48165
48276
  try {
48166
- return realpathSync4.native(path5);
48277
+ return realpathSync4.native(path7);
48167
48278
  } catch {
48168
- throw missing(adapter.id, path5);
48279
+ throw missing(adapter.id, path7);
48169
48280
  }
48170
48281
  }
48171
48282
 
@@ -48292,13 +48403,13 @@ function nativeMcpWrong(dir, row5) {
48292
48403
  return true;
48293
48404
  }
48294
48405
  }
48295
- function mcpWrong(row5, home, env) {
48406
+ function mcpWrong(row5, home, env, worktree) {
48296
48407
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
48297
48408
  if (native !== null) return nativeMcpWrong(native, row5);
48298
48409
  const file2 = mcpFile(row5, home, env);
48299
48410
  try {
48300
48411
  if (file2 === null) {
48301
- resolvePluginRoot(row5, env);
48412
+ resolvePluginRoot(row5, env, worktree);
48302
48413
  return false;
48303
48414
  }
48304
48415
  const cur = readHostConfig(row5.id, file2);
@@ -48312,7 +48423,7 @@ function hookParts(row5, home, env, worktree) {
48312
48423
  if (spec === null) return [];
48313
48424
  let block;
48314
48425
  try {
48315
- const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
48426
+ const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
48316
48427
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
48317
48428
  const file2 = native !== null ? join9(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join9(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join9(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join9(kiroDirOf(env, home), ...spec.file.slice(1)) : join9(root, ...spec.file);
48318
48429
  block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
@@ -48347,7 +48458,11 @@ function hookParts(row5, home, env, worktree) {
48347
48458
  function checkHostConfig(row5, env, worktree) {
48348
48459
  const home = homeDirOf(env);
48349
48460
  if (home === null) return fail("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
48350
- const parts = [...mcpWrong(row5, home, env) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
48461
+ if (row5.installMode === "marketplace") {
48462
+ const choice = marketplaceChoice(env, worktree);
48463
+ if ("installs" in choice) return fail("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
48464
+ }
48465
+ const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
48351
48466
  const read = row5.id === "pi" ? mcpFile(row5, home, env) : null;
48352
48467
  if (parts.length === 0) return read === null ? pass("D3") : { ...pass("D3"), detail: read };
48353
48468
  const detail = D3_DETAIL(parts);
@@ -48396,8 +48511,8 @@ async function loadSqlite2() {
48396
48511
  return null;
48397
48512
  }
48398
48513
  }
48399
- function openRead(sqlite, path5) {
48400
- return new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS, readOnly: true });
48514
+ function openRead(sqlite, path7) {
48515
+ return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
48401
48516
  }
48402
48517
  var cell = (row5) => Object.values(row5)[0];
48403
48518
  function readSchema(raw) {
@@ -48539,17 +48654,229 @@ function checkShell(env) {
48539
48654
  }
48540
48655
 
48541
48656
  // src/core/ops/doctor-hook.ts
48542
- import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
48657
+ import { existsSync as existsSync11, readFileSync as readFileSync7, realpathSync as realpathSync7 } from "node:fs";
48658
+ import path6 from "node:path";
48659
+
48660
+ // src/setup/codex-trust.ts
48661
+ import { createHash } from "node:crypto";
48662
+ import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
48663
+ import path5 from "node:path";
48664
+ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
48665
+
48666
+ // src/setup/spawn-bin.ts
48667
+ import { spawnSync } from "node:child_process";
48668
+ import { accessSync as accessSync2, constants as fsc, statSync as statSync4 } from "node:fs";
48543
48669
  import path4 from "node:path";
48670
+ var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
48671
+ var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
48672
+ var DEFAULT_COMSPEC = "cmd.exe";
48673
+ function envGet(env, k) {
48674
+ return env[Object.keys(env).find((x) => x.toUpperCase() === k) ?? k];
48675
+ }
48676
+ function whichBin(bin, env, platform = process.platform) {
48677
+ const get = (k) => envGet(env, k);
48678
+ const win = platform === "win32";
48679
+ const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
48680
+ const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
48681
+ for (const dir of pathEntries(get("PATH") ?? "", platform)) {
48682
+ for (const n of names) {
48683
+ const f = path4.join(dir, n);
48684
+ try {
48685
+ accessSync2(f, fsc.X_OK);
48686
+ if (statSync4(f).isFile()) return f;
48687
+ } catch {
48688
+ }
48689
+ }
48690
+ }
48691
+ return void 0;
48692
+ }
48693
+ var CMD_QUOTE_CHARS = '"&|<>^()!';
48694
+ var CMD_PERCENT = "%";
48695
+ var CMD_SUBSTRING_MARK = ":";
48696
+ var CMD_DYNAMIC_VARS = Object.freeze(["CD", "DATE", "TIME", "RANDOM", "ERRORLEVEL", "CMDEXTVERSION", "CMDCMDLINE", "HIGHESTNUMANODENUMBER"]);
48697
+ function needsCmdQuotes(a) {
48698
+ if (a === "") return true;
48699
+ for (const c of a) if (c.trim() === "" || CMD_QUOTE_CHARS.includes(c)) return true;
48700
+ return false;
48701
+ }
48702
+ function expandablePercent(text, env) {
48703
+ const names = new Set(CMD_DYNAMIC_VARS);
48704
+ for (const k of Object.keys(env)) names.add(k.toUpperCase());
48705
+ for (let i = text.indexOf(CMD_PERCENT); i >= 0; i = text.indexOf(CMD_PERCENT, i + 1)) {
48706
+ for (let j = text.indexOf(CMD_PERCENT, i + 1); j >= 0; j = text.indexOf(CMD_PERCENT, j + 1)) {
48707
+ const inner = text.slice(i + 1, j);
48708
+ const cut = inner.indexOf(CMD_SUBSTRING_MARK);
48709
+ const name = cut < 0 ? inner : inner.slice(0, cut);
48710
+ if (name !== "" && names.has(name.toUpperCase())) return `${CMD_PERCENT}${inner}${CMD_PERCENT}`;
48711
+ }
48712
+ }
48713
+ return void 0;
48714
+ }
48715
+ function winCmdLine(file2, args, env = {}) {
48716
+ for (const a of [file2, ...args]) {
48717
+ const hit = expandablePercent(a, env);
48718
+ if (hit !== void 0) throw new Error(`cannot run ${file2} through cmd.exe: cmd.exe expands ${hit} inside quotes, so the value ${JSON.stringify(a)} would change. Use a path and arguments without it`);
48719
+ }
48720
+ const q = (a) => needsCmdQuotes(a) ? `"${a.split('"').join('""')}"` : a;
48721
+ return `"${[file2, ...args].map(q).join(" ")}"`;
48722
+ }
48723
+ function spawnForm(file2, args, env, platform = process.platform) {
48724
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
48725
+ return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
48726
+ }
48727
+ return { command: file2, args, windowsVerbatimArguments: false };
48728
+ }
48729
+
48730
+ // src/setup/codex-trust.ts
48731
+ var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
48732
+ var TRUST_KEY = ["hooks", "state"];
48733
+ var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
48734
+ var WIN_VERBATIM_PREFIX = "\\\\?\\";
48735
+ function codexHomeFromReply(out) {
48736
+ for (const line of out.split("\n")) {
48737
+ let m;
48738
+ try {
48739
+ m = JSON.parse(line);
48740
+ } catch {
48741
+ continue;
48742
+ }
48743
+ if (isObj2(m) && isObj2(m.result) && typeof m.result.codexHome === "string" && m.result.codexHome !== "") return m.result.codexHome;
48744
+ }
48745
+ return void 0;
48746
+ }
48747
+ function sameDir(a, b, platform = process.platform) {
48748
+ if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
48749
+ const norm = (p) => {
48750
+ const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
48751
+ const n = path5.win32.normalize(bare2).toLowerCase();
48752
+ return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
48753
+ };
48754
+ return norm(a) === norm(b);
48755
+ }
48756
+ var LIST_TIMEOUT_MS = 15e3;
48757
+ var EXIT_GRACE_MS = 5e3;
48758
+ var PLUGIN_SOURCE = "plugin";
48759
+ var TRUSTED = "trusted";
48760
+ function pluginHooksFromReply(m, pluginId) {
48761
+ const out = [];
48762
+ if (!isObj2(m) || !isObj2(m.result) || !Array.isArray(m.result.data)) return out;
48763
+ for (const d of m.result.data) {
48764
+ if (!isObj2(d) || !Array.isArray(d.hooks)) continue;
48765
+ for (const h of d.hooks) {
48766
+ if (!isObj2(h) || h.source !== PLUGIN_SOURCE || h.pluginId !== pluginId) continue;
48767
+ if (typeof h.key !== "string" || typeof h.currentHash !== "string") continue;
48768
+ if (out.some((x) => x.key === h.key)) continue;
48769
+ out.push({ key: h.key, hash: h.currentHash, trusted: h.trustStatus === TRUSTED });
48770
+ }
48771
+ }
48772
+ return out;
48773
+ }
48774
+ function askPluginHooks(env, pluginId, cwd) {
48775
+ const bin = whichBin("codex", env);
48776
+ if (!bin) return Promise.resolve({ kind: "absent" });
48777
+ return new Promise((resolve6) => {
48778
+ let asked;
48779
+ const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
48780
+ let f;
48781
+ try {
48782
+ f = spawnForm(bin, ["app-server"], env);
48783
+ } catch {
48784
+ resolve6({ kind: "silent" });
48785
+ return;
48786
+ }
48787
+ const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
48788
+ let buf = "";
48789
+ let done = false;
48790
+ let exited = false;
48791
+ let result;
48792
+ const settle3 = () => {
48793
+ clearTimeout(grace);
48794
+ resolve6(done_(result));
48795
+ };
48796
+ let grace;
48797
+ const finish2 = (v) => {
48798
+ if (done) return;
48799
+ done = true;
48800
+ clearTimeout(timer);
48801
+ result = v;
48802
+ child.stdin.destroy();
48803
+ if (exited) {
48804
+ settle3();
48805
+ return;
48806
+ }
48807
+ grace = setTimeout(settle3, EXIT_GRACE_MS);
48808
+ stopTree(child.pid, () => child.kill());
48809
+ };
48810
+ const timer = setTimeout(() => finish2(void 0), LIST_TIMEOUT_MS);
48811
+ const send = (o) => {
48812
+ try {
48813
+ child.stdin.write(JSON.stringify(o) + "\n");
48814
+ } catch {
48815
+ finish2(void 0);
48816
+ }
48817
+ };
48818
+ child.on("error", () => finish2(void 0));
48819
+ child.on("close", () => {
48820
+ exited = true;
48821
+ if (done) settle3();
48822
+ else finish2(void 0);
48823
+ });
48824
+ child.stdin.on("error", () => finish2(void 0));
48825
+ child.stdout.setEncoding("utf8");
48826
+ child.stdout.on("data", (d) => {
48827
+ buf += d;
48828
+ const lines = buf.split("\n");
48829
+ buf = lines.pop() ?? "";
48830
+ for (const line of lines) {
48831
+ let m;
48832
+ try {
48833
+ m = JSON.parse(line);
48834
+ } catch {
48835
+ continue;
48836
+ }
48837
+ if (!isObj2(m)) continue;
48838
+ if (m.id === 1) {
48839
+ asked = codexHomeFromReply(line);
48840
+ send({ method: "initialized" });
48841
+ send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
48842
+ } else if (m.id === 2) finish2(pluginHooksFromReply(m, pluginId));
48843
+ }
48844
+ });
48845
+ send({ id: 1, method: "initialize", params: { clientInfo: { name: "context-mode-setup", version: "2.0.0" } } });
48846
+ });
48847
+ }
48848
+ function stopTree(pid, kill) {
48849
+ if (process.platform === "win32" && pid !== void 0) {
48850
+ try {
48851
+ spawnSync2("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
48852
+ } catch {
48853
+ }
48854
+ }
48855
+ kill();
48856
+ }
48857
+ var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
48858
+ var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
48859
+ function untrustedPluginHooksDetail(hooks) {
48860
+ const bad = hooks.filter((h) => !h.trusted);
48861
+ if (!bad.length) return void 0;
48862
+ return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
48863
+ }
48864
+
48865
+ // src/core/ops/doctor-hook.ts
48544
48866
  var D5_MIN_PAIRS = 3;
48545
48867
  var D5_MAX_PAIRS = 9;
48868
+ var D5_CODEX_TRUST_FIX = "context-mode setup --agents codex";
48869
+ var D5_CODEX_ABSENT_DETAIL = (home) => `codex is not on PATH, so the trust of the context-mode plugin hooks in ${home} is not known`;
48870
+ var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answer for ${home} in time, so the context-mode plugin hooks are not known to run`;
48871
+ var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
48872
+ var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
48546
48873
  var row = (status, detail, fixCommand) => fixCommand === void 0 ? { id: "D5", label: DOCTOR_LABEL.D5, status, detail } : { id: "D5", label: DOCTOR_LABEL.D5, status, detail, fixCommand };
48547
48874
  function isObject5(v) {
48548
48875
  return typeof v === "object" && v !== null && !Array.isArray(v);
48549
48876
  }
48550
48877
  function loadFixture(bundleDir2, agent) {
48551
- const file2 = path4.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
48552
- if (!existsSync10(file2)) return null;
48878
+ const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
48879
+ if (!existsSync11(file2)) return null;
48553
48880
  let all;
48554
48881
  try {
48555
48882
  all = JSON.parse(hostText(readFileSync7(file2, "utf8")));
@@ -48579,8 +48906,36 @@ function codexHookJournaled(db) {
48579
48906
  if (db === null) return false;
48580
48907
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
48581
48908
  }
48909
+ function realDir(p) {
48910
+ try {
48911
+ return realpathSync7(p);
48912
+ } catch {
48913
+ return p;
48914
+ }
48915
+ }
48916
+ async function codexPluginTrust(i) {
48917
+ const home = i.codexConfigDir;
48918
+ const plugin = codexPluginHomeOf(i.bundleDir) !== null;
48919
+ const reply4 = await askPluginHooks({ ...i.env, CODEX_HOME: home }, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
48920
+ if (reply4.kind === "list") {
48921
+ const detail = untrustedPluginHooksDetail(reply4.hooks);
48922
+ if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
48923
+ }
48924
+ if (!plugin) return null;
48925
+ if (reply4.kind === "absent") return row("UNKNOWN", D5_CODEX_ABSENT_DETAIL(home), D5_CODEX_TRUST_FIX);
48926
+ if (reply4.kind === "silent") return row("FAIL", D5_CODEX_SILENT_DETAIL(home), D5_CODEX_TRUST_FIX);
48927
+ if (reply4.codexHome !== void 0 && !sameDir(realDir(reply4.codexHome), realDir(home))) {
48928
+ return row("FAIL", D5_CODEX_OTHER_HOME_DETAIL(reply4.codexHome, home), D5_CODEX_TRUST_FIX);
48929
+ }
48930
+ if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
48931
+ return null;
48932
+ }
48582
48933
  async function checkHookRoundTrip(i) {
48583
- if (i.agent === "codex" && existsSync10(path4.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
48934
+ if (i.agent === "codex") {
48935
+ const trust = await codexPluginTrust(i);
48936
+ if (trust !== null) return trust;
48937
+ }
48938
+ if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
48584
48939
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
48585
48940
  }
48586
48941
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -48599,7 +48954,7 @@ async function checkHookRoundTrip(i) {
48599
48954
  let ms = 0;
48600
48955
  for (let n = 1; n <= maxPairs; n++) {
48601
48956
  const start = now();
48602
- const r = await runProcess([process.execPath, path4.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
48957
+ const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
48603
48958
  cwd: i.bundleDir,
48604
48959
  env: i.env,
48605
48960
  signal: i.signal,
@@ -48617,7 +48972,7 @@ async function checkHookRoundTrip(i) {
48617
48972
  }
48618
48973
 
48619
48974
  // src/core/hooks/fallback.ts
48620
- import { join as join10, resolve as resolve2 } from "node:path";
48975
+ import { join as join10, resolve as resolve3 } from "node:path";
48621
48976
  var fs = process.getBuiltinModule("node:fs");
48622
48977
  function homeOf(env) {
48623
48978
  return env.HOME ?? env.USERPROFILE ?? "";
@@ -48654,7 +49009,7 @@ function lastHookError(env) {
48654
49009
  }
48655
49010
 
48656
49011
  // src/core/ops/db-heal.ts
48657
- import { existsSync as existsSync11, rmSync as rmSync4 } from "node:fs";
49012
+ import { existsSync as existsSync12, rmSync as rmSync4 } from "node:fs";
48658
49013
  function integrityOk2(rows) {
48659
49014
  return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
48660
49015
  }
@@ -48688,7 +49043,7 @@ function renameAside(dbPath) {
48688
49043
  const ts = String(Date.now());
48689
49044
  for (const suffix of DB_SIBLING_SUFFIXES) {
48690
49045
  const file2 = dbPath + suffix;
48691
- if (existsSync11(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
49046
+ if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
48692
49047
  }
48693
49048
  return ts;
48694
49049
  }
@@ -48788,7 +49143,7 @@ async function guard(id, run) {
48788
49143
  }
48789
49144
  }
48790
49145
  async function codexDb(ctx, adapter) {
48791
- if (adapter.id !== "codex" || !existsSync12(ctx.project.dbPath)) return null;
49146
+ if (adapter.id !== "codex" || !existsSync13(ctx.project.dbPath)) return null;
48792
49147
  try {
48793
49148
  return await openDb(ctx.project, { readOnly: true });
48794
49149
  } catch {
@@ -48806,7 +49161,7 @@ async function hookRow(ctx, adapter, host) {
48806
49161
  env: buildChildEnv(host.env),
48807
49162
  signal: ctx.signal,
48808
49163
  codexConfigDir: codexDirOf(host.env, requireHomeDir(host.env)),
48809
- // same Codex dir D3 reads (D-N6-CODEX-HOME-2)
49164
+ // = codexRunDirOf: runDoctorChecks sets CODEX_HOME for codex (D-CODEX-HOME-RUN-1)
48810
49165
  db
48811
49166
  });
48812
49167
  const last2 = lastHookError(host.env);
@@ -48819,14 +49174,15 @@ async function hookRow(ctx, adapter, host) {
48819
49174
  }
48820
49175
  function ownServerId(configDir, projectKey) {
48821
49176
  const dir = join11(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
48822
- if (!existsSync12(dir)) return "";
49177
+ if (!existsSync13(dir)) return "";
48823
49178
  for (const name of readdirSync6(dir)) {
48824
49179
  if (!name.endsWith(OWNER_PID_EXT)) continue;
48825
- if (readFileSync8(join11(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
49180
+ if (readFileSync8(join11(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
48826
49181
  }
48827
49182
  return "";
48828
49183
  }
48829
- async function runDoctorChecks(ctx, adapter, host) {
49184
+ async function runDoctorChecks(ctx, adapter, host0) {
49185
+ const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
48830
49186
  const env = host.env;
48831
49187
  const project = ctx.project;
48832
49188
  let integrityFailed = false;
@@ -48868,7 +49224,7 @@ function reportEnv(env) {
48868
49224
  }
48869
49225
  async function handler2(_input, ctx) {
48870
49226
  const adapter = getAdapter(ctx.project.agent);
48871
- const host = { env: process.env, bundleDir: dirname5(process.argv[1]), piCwd: void 0 };
49227
+ const host = { env: process.env, bundleDir: dirname6(process.argv[1]), piCwd: void 0 };
48872
49228
  const rows = await runDoctorChecks(ctx, adapter, host);
48873
49229
  const command = `context-mode ${rows.some((r) => r.status === "FAIL") ? "setup" : "doctor"} --agents ${adapter.id}`;
48874
49230
  const input = { agent: adapter.id, rows, env: reportEnv(process.env), command };
@@ -48894,9 +49250,9 @@ var ctxDoctor = Object.freeze({
48894
49250
  });
48895
49251
 
48896
49252
  // src/core/tools/execute.ts
48897
- import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
49253
+ import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
48898
49254
  import { tmpdir as tmpdir2 } from "node:os";
48899
- import { dirname as dirname6, join as join12, parse as parse5, resolve as resolve3 } from "node:path";
49255
+ import { dirname as dirname7, join as join12, parse as parse5, resolve as resolve4 } from "node:path";
48900
49256
 
48901
49257
  // src/core/index/select.ts
48902
49258
  var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
@@ -49019,7 +49375,7 @@ function schemaLine(issue4) {
49019
49375
  }
49020
49376
  function fileError(given, abs, root) {
49021
49377
  let dir = abs;
49022
- while (!existsSync13(dir) && dirname6(dir) !== dir) dir = dirname6(dir);
49378
+ while (!existsSync14(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
49023
49379
  if (isInside(root, dir)) return null;
49024
49380
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
49025
49381
  }
@@ -49057,12 +49413,14 @@ async function finish(input, ctx, r, exitCode, journal) {
49057
49413
  const fullBytes = Buffer.byteLength(combined, "utf8");
49058
49414
  const head = summaryLine(exitCode, fullBytes);
49059
49415
  const intent = input.intent ?? "";
49060
- const direct = head + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
49061
- if (intent === "" && Buffer.byteLength(direct, "utf8") <= OUTPUT_CAP) {
49416
+ const bare2 = exitCode === 0 && input.summary !== true && combined !== "";
49417
+ const direct = (bare2 ? "" : head + "\n") + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
49418
+ const fits = Buffer.byteLength(head + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined, "utf8") <= OUTPUT_CAP;
49419
+ if (intent === "" && fits) {
49062
49420
  return { text: direct, isError, sandboxBytes: fullBytes, journal };
49063
49421
  }
49064
49422
  const label = sourceLabel(input.code);
49065
- const budget = OUTPUT_CAP - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
49423
+ const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
49066
49424
  const db = await openDb(ctx.project);
49067
49425
  let picked;
49068
49426
  try {
@@ -49081,7 +49439,7 @@ async function handler3(raw, ctx) {
49081
49439
  const cwd = ctx.project.worktree;
49082
49440
  const extra = { ...PLAIN_OUTPUT_ENV2 };
49083
49441
  if (input.file !== void 0) {
49084
- const abs = resolve3(cwd, input.file);
49442
+ const abs = resolve4(cwd, input.file);
49085
49443
  const bad = fileError(input.file, abs, ctx.project.containmentRoot);
49086
49444
  if (bad !== null) return fail4(bad);
49087
49445
  extra.CTX_FILE = abs;
@@ -49134,16 +49492,16 @@ var ctxExecute = {
49134
49492
  };
49135
49493
 
49136
49494
  // src/core/tools/index.ts
49137
- import { existsSync as existsSync14, readFileSync as readFileSync10, statSync as statSync5 } from "node:fs";
49138
- import { dirname as dirname7, extname, join as join14, relative as relative2, resolve as resolve4 } from "node:path";
49495
+ import { existsSync as existsSync15, readFileSync as readFileSync10, statSync as statSync6 } from "node:fs";
49496
+ import { dirname as dirname8, extname, join as join14, relative as relative2, resolve as resolve5 } from "node:path";
49139
49497
 
49140
49498
  // src/core/index/walk.ts
49141
- import { readdirSync as readdirSync7, readFileSync as readFileSync9, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
49499
+ import { readdirSync as readdirSync7, readFileSync as readFileSync9, realpathSync as realpathSync8, statSync as statSync5 } from "node:fs";
49142
49500
  import { join as join13 } from "node:path";
49143
49501
  var GITIGNORE = ".gitignore";
49144
49502
  var GIT_DIR = ".git";
49145
49503
  function walkDir(root, containmentRoot) {
49146
- const real2 = realpathSync6(root);
49504
+ const real2 = realpathSync8(root);
49147
49505
  if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
49148
49506
  const found = [];
49149
49507
  visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
@@ -49160,19 +49518,19 @@ function visit(abs, rel, parent, contain, seen, found) {
49160
49518
  const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join13(abs, GITIGNORE), rel)) : parent;
49161
49519
  for (const e of entries) {
49162
49520
  if (e.name === GIT_DIR) continue;
49163
- const path5 = join13(abs, e.name);
49521
+ const path7 = join13(abs, e.name);
49164
49522
  let isDir = e.isDirectory();
49165
49523
  let isFile = e.isFile();
49166
- let target = path5;
49524
+ let target = path7;
49167
49525
  if (e.isSymbolicLink()) {
49168
49526
  let resolved;
49169
49527
  try {
49170
- resolved = realpathSync6(path5);
49528
+ resolved = realpathSync8(path7);
49171
49529
  } catch {
49172
49530
  continue;
49173
49531
  }
49174
49532
  if (!isInside(contain, resolved)) continue;
49175
- const st = statSync4(resolved);
49533
+ const st = statSync5(resolved);
49176
49534
  isDir = st.isDirectory();
49177
49535
  isFile = st.isFile();
49178
49536
  target = resolved;
@@ -49180,12 +49538,12 @@ function visit(abs, rel, parent, contain, seen, found) {
49180
49538
  const segs = rel.concat(e.name);
49181
49539
  if (ignored(rules, segs, isDir)) continue;
49182
49540
  if (isFile) {
49183
- found.push({ dir: rel, name: e.name, absPath: path5 });
49541
+ found.push({ dir: rel, name: e.name, absPath: path7 });
49184
49542
  } else if (isDir) {
49185
- const key = e.isSymbolicLink() ? target : realpathSync6(path5);
49543
+ const key = e.isSymbolicLink() ? target : realpathSync8(path7);
49186
49544
  if (seen.has(key)) continue;
49187
49545
  seen.add(key);
49188
- visit(path5, segs, rules, contain, seen, found);
49546
+ visit(path7, segs, rules, contain, seen, found);
49189
49547
  }
49190
49548
  }
49191
49549
  }
@@ -49376,19 +49734,19 @@ function tlsName(host) {
49376
49734
  function request(u, conn, proxy, signal) {
49377
49735
  const host = bare(u.hostname);
49378
49736
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
49379
- const path5 = u.pathname + u.search;
49380
- return new Promise((resolve5, reject) => {
49737
+ const path7 = u.pathname + u.search;
49738
+ return new Promise((resolve6, reject) => {
49381
49739
  const onErr = (err) => reject(fail5(causeCode(err)));
49382
49740
  if (proxy === void 0) {
49383
49741
  const mod = u.protocol === "https:" ? https : http;
49384
- const req = mod.request({ host: conn.address, port, path: path5, signal, servername: tlsName(host), headers: { host: u.host } });
49385
- req.on("response", resolve5).on("error", onErr).end();
49742
+ const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
49743
+ req.on("response", resolve6).on("error", onErr).end();
49386
49744
  return;
49387
49745
  }
49388
49746
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
49389
49747
  if (u.protocol === "http:") {
49390
49748
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
49391
- req.on("response", resolve5).on("error", onErr).end();
49749
+ req.on("response", resolve6).on("error", onErr).end();
49392
49750
  return;
49393
49751
  }
49394
49752
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -49403,21 +49761,21 @@ function request(u, conn, proxy, signal) {
49403
49761
  const req = https.request({
49404
49762
  host,
49405
49763
  port,
49406
- path: path5,
49764
+ path: path7,
49407
49765
  signal,
49408
49766
  headers: { host: u.host },
49409
49767
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
49410
49768
  });
49411
- req.on("response", resolve5).on("error", onErr).end();
49769
+ req.on("response", resolve6).on("error", onErr).end();
49412
49770
  });
49413
49771
  tunnel.end();
49414
49772
  });
49415
49773
  }
49416
49774
  function readBody(res) {
49417
- return new Promise((resolve5, reject) => {
49775
+ return new Promise((resolve6, reject) => {
49418
49776
  const parts = [];
49419
49777
  res.on("data", (b) => parts.push(b));
49420
- res.on("end", () => resolve5(Buffer.concat(parts)));
49778
+ res.on("end", () => resolve6(Buffer.concat(parts)));
49421
49779
  res.on("error", (err) => reject(fail5(causeCode(err))));
49422
49780
  res.on("aborted", () => reject(fail5("ECONNRESET")));
49423
49781
  });
@@ -53290,23 +53648,23 @@ function readUtf8(absPath) {
53290
53648
  }
53291
53649
  function missingOrOutside(given, abs, root) {
53292
53650
  let dir = abs;
53293
- while (!existsSync14(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
53651
+ while (!existsSync15(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
53294
53652
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
53295
53653
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
53296
53654
  }
53297
53655
  function pathItems(input, project) {
53298
- const abs = resolve4(project.worktree, input.path);
53656
+ const abs = resolve5(project.worktree, input.path);
53299
53657
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
53300
53658
  const base = relative2(project.worktree, abs);
53301
- if (statSync5(abs).isDirectory()) {
53659
+ if (statSync6(abs).isDirectory()) {
53302
53660
  return walkDir(abs, project.containmentRoot).map((f) => ({
53303
53661
  sourceKind: "path",
53304
- label: join14(base, f.relPath),
53662
+ label: pathLabel(join14(base, f.relPath)),
53305
53663
  kind: kindOfPath(f.relPath),
53306
53664
  read: () => readUtf8(f.absPath)
53307
53665
  }));
53308
53666
  }
53309
- return [{ sourceKind: "path", label: base === "" ? input.path : base, kind: kindOfPath(abs), read: () => readUtf8(abs) }];
53667
+ return [{ sourceKind: "path", label: pathLabel(base === "" ? input.path : base), kind: kindOfPath(abs), read: () => readUtf8(abs) }];
53310
53668
  }
53311
53669
  async function itemsOf(input, ctx) {
53312
53670
  if (input.content !== void 0) {
@@ -53317,7 +53675,7 @@ async function itemsOf(input, ctx) {
53317
53675
  }
53318
53676
  if (input.path !== void 0) {
53319
53677
  const items = pathItems({ ...input, path: input.path }, ctx.project);
53320
- return { items, from: items.length === 1 ? items[0].label : input.path };
53678
+ return { items, from: items.length === 1 ? items[0].label : pathLabel(input.path) };
53321
53679
  }
53322
53680
  const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
53323
53681
  const text = res.body.toString("utf8");
@@ -53414,10 +53772,11 @@ function scopesOf(input) {
53414
53772
  function changes(raw, sql, ...args) {
53415
53773
  return Number(raw.prepare(sql).run(...args).changes);
53416
53774
  }
53417
- function purgeScope(raw, scope, input) {
53775
+ function purgeScope(db, scope, input) {
53776
+ const raw = db.raw;
53418
53777
  if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
53419
53778
  if (scope === "source") {
53420
- const label = input.source;
53779
+ const label = storedLabel(db, input.source);
53421
53780
  return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?", label);
53422
53781
  }
53423
53782
  const chunks = deleteChunkRows(raw, "all");
@@ -53435,7 +53794,7 @@ async function handler5(input, ctx) {
53435
53794
  try {
53436
53795
  const db = await openDb(ctx.project);
53437
53796
  try {
53438
- const rows = withWrite(db, (h) => purgeScope(h.raw, scope, input));
53797
+ const rows = withWrite(db, (h) => purgeScope(h, scope, input));
53439
53798
  return reply2(PURGE_SUMMARY(rows, scope), false);
53440
53799
  } finally {
53441
53800
  closeDb(db);
@@ -53499,8 +53858,8 @@ function buildCandidates(rows, sessionId) {
53499
53858
  edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
53500
53859
  }
53501
53860
  const changedFiles = [];
53502
- for (const [path5, e] of edits) {
53503
- const c = make("changed_files", e.row, "edited " + path5 + " x" + e.count, e.count, path5);
53861
+ for (const [path7, e] of edits) {
53862
+ const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
53504
53863
  changedFiles.push({ ...c, editCount: e.count });
53505
53864
  }
53506
53865
  changedFiles.sort((a, b) => a.seq - b.seq);
@@ -53822,12 +54181,12 @@ var ctxStats = Object.freeze({
53822
54181
  });
53823
54182
 
53824
54183
  // src/core/tools/upgrade.ts
53825
- import { existsSync as existsSync20, realpathSync as realpathSync7, rmSync as rmSync10 } from "node:fs";
53826
- import { basename as basename5, dirname as dirname9, join as join20 } from "node:path";
54184
+ import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync10 } from "node:fs";
54185
+ import { basename as basename6, dirname as dirname10, join as join20 } from "node:path";
53827
54186
 
53828
54187
  // src/core/ops/host-write.ts
53829
- import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
53830
- import { dirname as dirname8, join as join15 } from "node:path";
54188
+ import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
54189
+ import { dirname as dirname9, join as join15 } from "node:path";
53831
54190
  function defaultWrite(file2, text) {
53832
54191
  writeFileSync4(file2, text, "utf8");
53833
54192
  }
@@ -53855,8 +54214,8 @@ function toRow(file2, edit) {
53855
54214
  function writeWithRollback(file2, text, write, atomic) {
53856
54215
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
53857
54216
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
53858
- const had = existsSync15(file2);
53859
- mkdirSync5(dirname8(file2), { recursive: true });
54217
+ const had = existsSync16(file2);
54218
+ mkdirSync5(dirname9(file2), { recursive: true });
53860
54219
  if (had) copyFileSync(file2, trash);
53861
54220
  try {
53862
54221
  write(tmp, text);
@@ -53885,7 +54244,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
53885
54244
  if (requested === null) return [];
53886
54245
  const current = readHostConfig(row5.id, requested);
53887
54246
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
53888
- const exists = existsSync15(current.path);
54247
+ const exists = existsSync16(current.path);
53889
54248
  if (exists && result.text === current.text) return [];
53890
54249
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
53891
54250
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -53893,15 +54252,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
53893
54252
  }
53894
54253
 
53895
54254
  // src/core/ops/plugin-swap.ts
53896
- import { existsSync as existsSync16, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
53897
- import { basename as basename4, join as join16, win32 as win322 } from "node:path";
53898
- function linkTarget(path5, win) {
53899
- if (!isLink(path5)) return null;
53900
- const target = readlinkSync(path5);
54255
+ import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
54256
+ import { basename as basename5, join as join16, win32 as win322 } from "node:path";
54257
+ function linkTarget(path7, win) {
54258
+ if (!isLink(path7)) return null;
54259
+ const target = readlinkSync(path7);
53901
54260
  return win ? win322.basename(target) : target;
53902
54261
  }
53903
- function isLink(path5) {
53904
- return lstatSync(path5, { throwIfNoEntry: false })?.isSymbolicLink() === true;
54262
+ function isLink(path7) {
54263
+ return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
53905
54264
  }
53906
54265
  function generations(agentDir) {
53907
54266
  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();
@@ -53914,8 +54273,8 @@ function settleLinks(link, tmp, old, opts) {
53914
54273
  }
53915
54274
  function swapPluginCurrent(agentDir, sha, opts = {}) {
53916
54275
  const next = join16(agentDir, sha);
53917
- if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
53918
- throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
54276
+ if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
54277
+ throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
53919
54278
  }
53920
54279
  const link = join16(agentDir, PLUGIN_CURRENT_LINK);
53921
54280
  const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
@@ -53934,12 +54293,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
53934
54293
  if (before !== null) keep.add(before);
53935
54294
  const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join16(agentDir, name));
53936
54295
  for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
53937
- const previous = before !== null && existsSync16(join16(agentDir, before)) ? join16(agentDir, before) : null;
54296
+ const previous = before !== null && existsSync17(join16(agentDir, before)) ? join16(agentDir, before) : null;
53938
54297
  return { current: next, previous, removed };
53939
54298
  }
53940
54299
 
53941
54300
  // src/core/ops/release-fetch.ts
53942
- import { existsSync as existsSync17, mkdirSync as mkdirSync6, rmSync as rmSync7 } from "node:fs";
54301
+ import { existsSync as existsSync18, mkdirSync as mkdirSync6, rmSync as rmSync7 } from "node:fs";
53943
54302
  import { join as join17 } from "node:path";
53944
54303
  function failed(r) {
53945
54304
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -53963,7 +54322,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
53963
54322
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
53964
54323
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
53965
54324
  const dir = join17(agentDir, sha);
53966
- if (existsSync17(dir)) rmSync7(fetchDir, { recursive: true, force: true });
54325
+ if (existsSync18(dir)) rmSync7(fetchDir, { recursive: true, force: true });
53967
54326
  else renameWithRetry(fetchDir, dir, opts);
53968
54327
  return { sha, dir };
53969
54328
  } catch (e) {
@@ -53973,7 +54332,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
53973
54332
  }
53974
54333
 
53975
54334
  // src/core/ops/uninstall.ts
53976
- import { existsSync as existsSync18, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync5 } from "node:fs";
54335
+ import { existsSync as existsSync19, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync5 } from "node:fs";
53977
54336
  import { join as join18 } from "node:path";
53978
54337
  function row2(area, before, after) {
53979
54338
  return { area, before, after };
@@ -53998,12 +54357,16 @@ function removeCache(adapter, env, configDir) {
53998
54357
  case "extension": {
53999
54358
  const root = rootOrNull(adapter, env);
54000
54359
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
54360
+ if (adapter.installMode === "marketplace") {
54361
+ const cache = join18(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
54362
+ if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
54363
+ }
54001
54364
  rmSync8(root, { recursive: true, force: true });
54002
54365
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
54003
54366
  }
54004
54367
  case "plugin": {
54005
54368
  const agentDir = join18(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
54006
- if (!existsSync18(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
54369
+ if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
54007
54370
  rmSync8(agentDir, { recursive: true, force: true });
54008
54371
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
54009
54372
  }
@@ -54016,11 +54379,11 @@ function removeCache(adapter, env, configDir) {
54016
54379
  }
54017
54380
  }
54018
54381
  }
54019
- function isObj2(v) {
54382
+ function isObj3(v) {
54020
54383
  return typeof v === "object" && v !== null && !Array.isArray(v);
54021
54384
  }
54022
54385
  function piSource(entry) {
54023
- return isObj2(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
54386
+ return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
54024
54387
  }
54025
54388
  function ownEntries(agent, env) {
54026
54389
  const home = requireHomeDir(env);
@@ -54029,11 +54392,11 @@ function ownEntries(agent, env) {
54029
54392
  const top = mcp.key[0];
54030
54393
  const inner = mcp.key.slice(1, -1);
54031
54394
  const own4 = mcp.key[mcp.key.length - 1];
54032
- const holder = (v) => inner.reduce((cur, k) => isObj2(cur) ? cur[k] : void 0, v);
54033
- const without = (v, path5) => {
54395
+ const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
54396
+ const without = (v, path7) => {
54034
54397
  const o = v;
54035
- if (path5.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
54036
- return { ...o, [path5[0]]: without(o[path5[0]], path5.slice(1)) };
54398
+ if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
54399
+ return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
54037
54400
  };
54038
54401
  return [{
54039
54402
  file: ownMcpFileOf(agent, mcp.file, env, home),
@@ -54041,7 +54404,7 @@ function ownEntries(agent, env) {
54041
54404
  shown: mcp.key.join(V1_KEY_PATH_SEP),
54042
54405
  has: (v) => {
54043
54406
  const h = holder(v);
54044
- return isObj2(h) && Object.hasOwn(h, own4);
54407
+ return isObj3(h) && Object.hasOwn(h, own4);
54045
54408
  },
54046
54409
  drop: (v) => without(v, inner)
54047
54410
  }];
@@ -54083,7 +54446,7 @@ function removeOwnEntries(agent, env) {
54083
54446
  function removeProjectData(configDir, projectKey) {
54084
54447
  const projects = join18(configDir, PROJECTS_DIR_NAME);
54085
54448
  const dir = join18(projects, projectKey);
54086
- if (!existsSync18(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
54449
+ if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
54087
54450
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
54088
54451
  for (const name of readdirSync9(dir)) {
54089
54452
  if (name !== OWNERS_DIR_NAME) rmSync8(join18(dir, name), { recursive: true, force: true });
@@ -54099,8 +54462,8 @@ function runUninstall(input) {
54099
54462
  }
54100
54463
 
54101
54464
  // src/core/ops/v1-remove.ts
54102
- import { copyFileSync as copyFileSync2, existsSync as existsSync19, readFileSync as readFileSync11, rmSync as rmSync9 } from "node:fs";
54103
- var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
54465
+ import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync11, rmSync as rmSync9 } from "node:fs";
54466
+ var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
54104
54467
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
54105
54468
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
54106
54469
  function moveAside(target, undo) {
@@ -54129,17 +54492,17 @@ function cutTomlTable(text, header) {
54129
54492
  function writeAtomic(file2, text) {
54130
54493
  atomicWriteFile(file2, text);
54131
54494
  }
54132
- function locate(doc, path5) {
54133
- const segs = path5.split(V1_KEY_PATH_SEP);
54495
+ function locate(doc, path7) {
54496
+ const segs = path7.split(V1_KEY_PATH_SEP);
54134
54497
  let cur = doc;
54135
54498
  for (const seg of segs.slice(0, -1)) {
54136
54499
  if (Array.isArray(cur)) cur = cur[Number(seg)];
54137
- else if (isObj3(cur)) cur = cur[seg];
54500
+ else if (isObj4(cur)) cur = cur[seg];
54138
54501
  else return null;
54139
54502
  }
54140
54503
  const last2 = segs[segs.length - 1];
54141
54504
  if (Array.isArray(cur)) return Number(last2) < cur.length ? [cur, last2] : null;
54142
- if (isObj3(cur)) return Object.hasOwn(cur, last2) ? [cur, last2] : null;
54505
+ if (isObj4(cur)) return Object.hasOwn(cur, last2) ? [cur, last2] : null;
54143
54506
  return null;
54144
54507
  }
54145
54508
  function stripJsonEntries(agent, file2, findings, kept, undo) {
@@ -54180,14 +54543,14 @@ function removeV1(agent, findings) {
54180
54543
  for (const f of findings) {
54181
54544
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
54182
54545
  else if (f.path === "") {
54183
- if (existsSync19(f.file)) {
54546
+ if (existsSync20(f.file)) {
54184
54547
  moveAside(f.file, undo);
54185
54548
  done.set(f, UPGRADE_REMOVED);
54186
54549
  } else done.set(f, UPGRADE_NOT_FOUND);
54187
54550
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
54188
54551
  }
54189
54552
  for (const [file2, list3] of entries) {
54190
- if (!existsSync19(file2)) {
54553
+ if (!existsSync20(file2)) {
54191
54554
  for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
54192
54555
  continue;
54193
54556
  }
@@ -54220,7 +54583,7 @@ function removeV1(agent, findings) {
54220
54583
  },
54221
54584
  rollback() {
54222
54585
  for (const u of undo.splice(0).reverse()) {
54223
- if (!existsSync19(u.trash)) continue;
54586
+ if (!existsSync20(u.trash)) continue;
54224
54587
  rmSync9(u.target, { recursive: true, force: true });
54225
54588
  renameWithRetry(u.trash, u.target);
54226
54589
  }
@@ -54229,7 +54592,7 @@ function removeV1(agent, findings) {
54229
54592
  }
54230
54593
 
54231
54594
  // src/core/ops/verify-sums.ts
54232
- import { createHash } from "node:crypto";
54595
+ import { createHash as createHash2 } from "node:crypto";
54233
54596
  import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync12 } from "node:fs";
54234
54597
  import { join as join19 } from "node:path";
54235
54598
  function mismatch() {
@@ -54269,7 +54632,7 @@ function verifySums(dir) {
54269
54632
  for (const [rel, abs] of files) {
54270
54633
  const want = sums.get(rel);
54271
54634
  if (want === void 0) throw mismatch();
54272
- const got = createHash(SUMS_HASH_ALGORITHM).update(readFileSync12(abs)).digest(HASH_ENCODING);
54635
+ const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync12(abs)).digest(HASH_ENCODING);
54273
54636
  if (got !== want) throw mismatch();
54274
54637
  }
54275
54638
  }
@@ -54283,7 +54646,7 @@ function row4(area, before, after) {
54283
54646
  return { area, before, after };
54284
54647
  }
54285
54648
  function bundleDir() {
54286
- return dirname9(process.argv[1] ?? "");
54649
+ return dirname10(process.argv[1] ?? "");
54287
54650
  }
54288
54651
  function pluginRootRow(adapter, env) {
54289
54652
  const own4 = bundleDir();
@@ -54298,11 +54661,11 @@ function pluginRootRow(adapter, env) {
54298
54661
  }
54299
54662
  function isCurrent(agentDir, dir) {
54300
54663
  const link = join20(agentDir, PLUGIN_CURRENT_LINK);
54301
- return existsSync20(link) && realpathSync7.native(link) === realpathSync7.native(dir);
54664
+ return existsSync21(link) && realpathSync9.native(link) === realpathSync9.native(dir);
54302
54665
  }
54303
54666
  async function checkout(adapter, deps) {
54304
54667
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
54305
- const agentDir = dirname9(fetched.dir);
54668
+ const agentDir = dirname10(fetched.dir);
54306
54669
  try {
54307
54670
  verifySums(fetched.dir);
54308
54671
  } catch (err) {
@@ -54330,7 +54693,7 @@ async function upgrade(adapter, deps, home) {
54330
54693
  return rows;
54331
54694
  } catch (err) {
54332
54695
  removal?.rollback();
54333
- if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename5(done.swap.previous));
54696
+ if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename6(done.swap.previous));
54334
54697
  throw err;
54335
54698
  }
54336
54699
  }
@@ -54417,12 +54780,12 @@ function checkCall(tool, input) {
54417
54780
  }
54418
54781
 
54419
54782
  // src/entries/is-entry.ts
54420
- import { realpathSync as realpathSync8 } from "node:fs";
54783
+ import { realpathSync as realpathSync10 } from "node:fs";
54421
54784
  function isEntry(main, argv1, self) {
54422
54785
  if (main !== void 0) return main;
54423
54786
  if (argv1 === void 0 || argv1 === "") return false;
54424
54787
  try {
54425
- return realpathSync8(argv1) === realpathSync8(self);
54788
+ return realpathSync10(argv1) === realpathSync10(self);
54426
54789
  } catch {
54427
54790
  return false;
54428
54791
  }
@@ -54498,7 +54861,7 @@ function workspaceFromMeta(meta3) {
54498
54861
  }
54499
54862
  function realOrSame(p) {
54500
54863
  try {
54501
- return realpathSync9.native(p);
54864
+ return realpathSync11.native(p);
54502
54865
  } catch {
54503
54866
  return p;
54504
54867
  }
@@ -54507,7 +54870,7 @@ function workspaceCwdOf(meta3, spawnCwd, script) {
54507
54870
  const fromHost = workspaceFromMeta(meta3);
54508
54871
  if (fromHost !== void 0) return fromHost;
54509
54872
  if (script === void 0 || script === "") return spawnCwd;
54510
- return realOrSame(spawnCwd) === realOrSame(dirname10(script)) ? "" : spawnCwd;
54873
+ return realOrSame(spawnCwd) === realOrSame(dirname11(script)) ? "" : spawnCwd;
54511
54874
  }
54512
54875
  function errorReply(err) {
54513
54876
  if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
@@ -54546,7 +54909,7 @@ async function startServer(argv, env) {
54546
54909
  opening.catch(() => pending.delete(project.dbPath));
54547
54910
  }
54548
54911
  const db = await opening;
54549
- if (!existsSync21(db.path)) throw new CtxError("DB_GONE");
54912
+ if (!existsSync22(db.path)) throw new CtxError("DB_GONE");
54550
54913
  return db;
54551
54914
  }
54552
54915
  function stopMarker(configDir, projectKey) {
@@ -54554,7 +54917,7 @@ async function startServer(argv, env) {
54554
54917
  }
54555
54918
  function stopRequested() {
54556
54919
  const configDir = resolveConfigDir(process.env);
54557
- return held.some((db) => existsSync21(stopMarker(configDir, db.projectKey)));
54920
+ return held.some((db) => existsSync22(stopMarker(configDir, db.projectKey)));
54558
54921
  }
54559
54922
  async function journal(project, ctx, name, reply4) {
54560
54923
  const db = await ownDb(project);
@@ -54661,7 +55024,7 @@ async function startServer(argv, env) {
54661
55024
  }
54662
55025
  installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
54663
55026
  handle = serveStdio(createServer);
54664
- await new Promise((resolve5) => process.once("exit", () => resolve5()));
55027
+ await new Promise((resolve6) => process.once("exit", () => resolve6()));
54665
55028
  }
54666
55029
  if (isEntry(import.meta.main, process.argv[1], fileURLToPath2(import.meta.url))) {
54667
55030
  const [, , ...cliArgs] = process.argv;