context-mode 2.0.0-next.22 → 2.0.0-next.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/server.mjs CHANGED
@@ -7,7 +7,7 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/entries/server.ts
9
9
  import { randomUUID } from "node:crypto";
10
- import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync11 } from "node:fs";
10
+ import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync11 } from "node:fs";
11
11
  import { dirname as dirname10, join as join21 } from "node:path";
12
12
  import { fileURLToPath as fileURLToPath2 } from "node:url";
13
13
 
@@ -305,10 +305,10 @@ function mergeDefs(...defs) {
305
305
  function cloneDef(schema) {
306
306
  return mergeDefs(schema._zod.def);
307
307
  }
308
- function getElementAtPath(obj, 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 {
@@ -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 {
@@ -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
  });
@@ -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
  }
@@ -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;
@@ -28343,7 +28344,7 @@ var DECISION_SOURCE = "decision";
28343
28344
  var DECISION_USER_LABEL = "decision (user)";
28344
28345
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
28345
28346
  var RELEASE_BRANCH = "release";
28346
- var BUNDLE_SHA = true ? "a31ac1245e4994b18efe99e363e9a86409abb025" : void 0;
28347
+ var BUNDLE_SHA = true ? "baaa3149e881980288944e90179895fa6a2be13e" : void 0;
28347
28348
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
28348
28349
  var DOCTOR_LABEL = Object.freeze({
28349
28350
  D1: "version",
@@ -28868,12 +28869,16 @@ CREATE VIRTUAL TABLE line_units USING fts5(
28868
28869
  ${FTS_TOKENIZE}
28869
28870
  );
28870
28871
  `;
28872
+ var DDL_V6 = `
28873
+ UPDATE sources SET label = replace(label, char(92), '/') WHERE kind = 'path' AND instr(label, char(92)) > 0;
28874
+ `;
28871
28875
  var MIGRATIONS = [
28872
28876
  { version: 1, sql: DDL },
28873
28877
  { version: 2, sql: DDL_V2 },
28874
28878
  { version: 3, sql: DDL_V3 },
28875
28879
  { version: 4, sql: DDL_V4 },
28876
- { version: 5, sql: DDL_V5 }
28880
+ { version: 5, sql: DDL_V5 },
28881
+ { version: 6, sql: DDL_V6 }
28877
28882
  ];
28878
28883
  function applyMigrations(db, fromVersion) {
28879
28884
  if (fromVersion === SCHEMA_VERSION2) return;
@@ -28927,9 +28932,9 @@ function readUserVersion(raw) {
28927
28932
  const row5 = raw.prepare("PRAGMA user_version").get();
28928
28933
  return row5.user_version;
28929
28934
  }
28930
- function createAtomically(sqlite, path5) {
28935
+ function createAtomically(sqlite, path7) {
28931
28936
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
28932
- const tmp = path5 + "." + randomUUID2() + DB_TMP_SUFFIX;
28937
+ const tmp = path7 + "." + randomUUID2() + DB_TMP_SUFFIX;
28933
28938
  try {
28934
28939
  const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
28935
28940
  try {
@@ -28938,7 +28943,7 @@ function createAtomically(sqlite, path5) {
28938
28943
  raw.close();
28939
28944
  }
28940
28945
  try {
28941
- linkSync(tmp, path5);
28946
+ linkSync(tmp, path7);
28942
28947
  } catch (err) {
28943
28948
  if (err.code !== "EEXIST") throw err;
28944
28949
  }
@@ -28946,11 +28951,11 @@ function createAtomically(sqlite, path5) {
28946
28951
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
28947
28952
  }
28948
28953
  }
28949
- function openWritable(sqlite, path5) {
28954
+ function openWritable(sqlite, path7) {
28950
28955
  let raw = null;
28951
28956
  try {
28952
- if (!existsSync(path5)) createAtomically(sqlite, path5);
28953
- raw = new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS });
28957
+ if (!existsSync(path7)) createAtomically(sqlite, path7);
28958
+ raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
28954
28959
  applyMigrations(raw, readUserVersion(raw));
28955
28960
  return raw;
28956
28961
  } catch (err) {
@@ -28958,8 +28963,8 @@ function openWritable(sqlite, path5) {
28958
28963
  throw err;
28959
28964
  }
28960
28965
  }
28961
- function openReadOnly(sqlite, path5) {
28962
- const raw = new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS, readOnly: true });
28966
+ function openReadOnly(sqlite, path7) {
28967
+ const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
28963
28968
  try {
28964
28969
  const found = readUserVersion(raw);
28965
28970
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -28973,20 +28978,20 @@ async function openDb(project, opts) {
28973
28978
  if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
28974
28979
  const sqlite = await loadSqlite();
28975
28980
  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)) {
28981
+ const path7 = project.dbPath;
28982
+ const sibling = existsSync(path7 + DB_WAL_SUFFIX) || existsSync(path7 + DB_SHM_SUFFIX);
28983
+ if (sibling && !existsSync(path7)) {
28979
28984
  throw new CtxError("DB_GONE");
28980
28985
  }
28981
28986
  try {
28982
28987
  let raw;
28983
28988
  if (opts?.readOnly === true) {
28984
- if (!existsSync(path5)) openWritable(sqlite, path5).close();
28985
- raw = openReadOnly(sqlite, path5);
28989
+ if (!existsSync(path7)) openWritable(sqlite, path7).close();
28990
+ raw = openReadOnly(sqlite, path7);
28986
28991
  } else {
28987
- raw = openWritable(sqlite, path5);
28992
+ raw = openWritable(sqlite, path7);
28988
28993
  }
28989
- return { raw, projectKey: project.projectKey, path: path5, ...opts?.readOnly === true ? { readOnly: true } : {} };
28994
+ return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
28990
28995
  } catch (err) {
28991
28996
  if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
28992
28997
  throw err;
@@ -29429,8 +29434,8 @@ function firstLine(file2) {
29429
29434
  return line === "" ? null : line;
29430
29435
  }
29431
29436
  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 });
29437
+ const { spawnSync: spawnSync3 } = process.getBuiltinModule("node:child_process");
29438
+ const r = spawnSync3("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
29434
29439
  if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
29435
29440
  return r.stdout.split("\n").filter((l) => l !== "");
29436
29441
  }
@@ -31727,7 +31732,7 @@ function ftsQuery(db, q, scope, ctx, sessionId, limit, offset, source) {
31727
31732
  }
31728
31733
  return page2.map((e) => {
31729
31734
  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 };
31735
+ 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
31736
  });
31732
31737
  }
31733
31738
  var LIST = `
@@ -31896,17 +31901,29 @@ function parseSourceHandle(s) {
31896
31901
  }
31897
31902
  return n > 0 && sourceHandle(n) === s ? n : null;
31898
31903
  }
31904
+ function pathLabel(p) {
31905
+ return p.includes("\\") ? p.split("\\").join("/") : p;
31906
+ }
31907
+ function labelStored(db, label) {
31908
+ return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label) !== void 0;
31909
+ }
31910
+ function storedLabel(db, source) {
31911
+ if (labelStored(db, source)) return source;
31912
+ const canon = pathLabel(source);
31913
+ return canon !== source && labelStored(db, canon) ? canon : source;
31914
+ }
31899
31915
  function resolveSourceLabel(db, source) {
31900
31916
  const id = parseSourceHandle(source);
31901
31917
  if (id !== null) {
31902
31918
  const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = ?").get(id);
31903
31919
  if (row5 !== void 0) return row5.label;
31904
31920
  }
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;
31921
+ const named = storedLabel(db, source);
31922
+ if (labelStored(db, named)) return named;
31923
+ const prefix = named + LABEL_SUFFIX_SEP;
31907
31924
  const rows = stmt(db.raw, "SELECT label FROM sources WHERE substr(label, 1, ?) = ? ORDER BY id DESC").all(prefix.length, prefix);
31908
31925
  for (const r of rows) {
31909
- if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === source.length) return r.label;
31926
+ if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named.length) return r.label;
31910
31927
  }
31911
31928
  return source;
31912
31929
  }
@@ -32723,10 +32740,10 @@ function assignProp3(target, prop, value) {
32723
32740
  configurable: true
32724
32741
  });
32725
32742
  }
32726
- function getElementAtPath3(obj, path5) {
32727
- if (!path5)
32743
+ function getElementAtPath3(obj, path7) {
32744
+ if (!path7)
32728
32745
  return obj;
32729
- return path5.reduce((acc, key) => acc?.[key], obj);
32746
+ return path7.reduce((acc, key) => acc?.[key], obj);
32730
32747
  }
32731
32748
  function promiseAllObject3(promisesObj) {
32732
32749
  const keys = Object.keys(promisesObj);
@@ -33046,11 +33063,11 @@ function aborted3(x, startIndex = 0) {
33046
33063
  }
33047
33064
  return false;
33048
33065
  }
33049
- function prefixIssues3(path5, issues) {
33066
+ function prefixIssues3(path7, issues) {
33050
33067
  return issues.map((iss) => {
33051
33068
  var _a5;
33052
33069
  (_a5 = iss).path ?? (_a5.path = []);
33053
- iss.path.unshift(path5);
33070
+ iss.path.unshift(path7);
33054
33071
  return iss;
33055
33072
  });
33056
33073
  }
@@ -33187,7 +33204,7 @@ function treeifyError2(error42, _mapper) {
33187
33204
  return issue4.message;
33188
33205
  };
33189
33206
  const result = { errors: [] };
33190
- const processError = (error43, path5 = []) => {
33207
+ const processError = (error43, path7 = []) => {
33191
33208
  var _a5, _b;
33192
33209
  for (const issue4 of error43.issues) {
33193
33210
  if (issue4.code === "invalid_union" && issue4.errors.length) {
@@ -33197,7 +33214,7 @@ function treeifyError2(error42, _mapper) {
33197
33214
  } else if (issue4.code === "invalid_element") {
33198
33215
  processError({ issues: issue4.issues }, issue4.path);
33199
33216
  } else {
33200
- const fullpath = [...path5, ...issue4.path];
33217
+ const fullpath = [...path7, ...issue4.path];
33201
33218
  if (fullpath.length === 0) {
33202
33219
  result.errors.push(mapper(issue4));
33203
33220
  continue;
@@ -33227,9 +33244,9 @@ function treeifyError2(error42, _mapper) {
33227
33244
  processError(error42);
33228
33245
  return result;
33229
33246
  }
33230
- function toDotPath(path5) {
33247
+ function toDotPath(path7) {
33231
33248
  const segs = [];
33232
- for (const seg of path5) {
33249
+ for (const seg of path7) {
33233
33250
  if (typeof seg === "number")
33234
33251
  segs.push(`[${seg}]`);
33235
33252
  else if (typeof seg === "symbol")
@@ -43792,19 +43809,19 @@ function readAutoMemory(project) {
43792
43809
  if (project.agent !== "claude-code") return [];
43793
43810
  const rows = [];
43794
43811
  for (const segs of CLAUDE_CODE_MEMORY_FILES) {
43795
- const path5 = join5(project.worktree, ...segs);
43796
- if (!isInside(project.worktree, path5)) continue;
43812
+ const path7 = join5(project.worktree, ...segs);
43813
+ if (!isInside(project.worktree, path7)) continue;
43797
43814
  try {
43798
- const st = statSync3(path5);
43815
+ const st = statSync3(path7);
43799
43816
  if (!st.isFile()) continue;
43800
43817
  rows.push({
43801
43818
  origin: "memory",
43802
43819
  ts: Math.trunc(st.mtimeMs),
43803
43820
  seq: null,
43804
43821
  sourceId: null,
43805
- path: path5,
43822
+ path: path7,
43806
43823
  label: segs.join("/"),
43807
- text: readFileSync3(path5, "utf8")
43824
+ text: readFileSync3(path7, "utf8")
43808
43825
  });
43809
43826
  } catch {
43810
43827
  }
@@ -43974,12 +43991,20 @@ function sourceBytes(db, ids) {
43974
43991
  }
43975
43992
  return out;
43976
43993
  }
43994
+ var LEAN_HITS = 3;
43995
+ function replyHits(hits, size) {
43996
+ if (hits.length === 0 || hits[0].full !== true) return Math.min(size, hits.length);
43997
+ let n = Math.min(LEAN_HITS, size, hits.length);
43998
+ while (n < size && n < hits.length && hits[n].full === true) n++;
43999
+ return n;
44000
+ }
43977
44001
  function relevance(db, given, scope, ctx) {
43978
44002
  const input = { ...given, queries: decisionQueries(given) };
43979
44003
  const offset = input.offset ?? 0;
43980
44004
  const size = pageSize(input);
43981
44005
  const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
43982
- const pages = fetched.map((h) => h.slice(0, size));
44006
+ const take = fetched.map((h) => replyHits(h, size));
44007
+ const pages = fetched.map((h, i) => h.slice(0, take[i]));
43983
44008
  if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
43984
44009
  const moreLine3 = (q, pos) => "More: " + callText([q], scope, input.source, "offset:" + pos);
43985
44010
  let reserve = 0;
@@ -43994,7 +44019,7 @@ function relevance(db, given, scope, ctx) {
43994
44019
  input.queries.forEach((q, qi) => {
43995
44020
  const hits = pages[qi];
43996
44021
  if (stopped) {
43997
- more.push(moreLine3(q, offset));
44022
+ more.push({ q, pos: offset });
43998
44023
  return;
43999
44024
  }
44000
44025
  const head = "Query " + JSON.stringify(q) + ":";
@@ -44032,10 +44057,14 @@ function relevance(db, given, scope, ctx) {
44032
44057
  lines.push(line);
44033
44058
  used += bytes2(line) + 1;
44034
44059
  }
44035
- if (cut >= 0) more.push(moreLine3(q, cut));
44036
- else if (fetched[qi].length > size) more.push(moreLine3(q, offset + size));
44060
+ if (cut >= 0) more.push({ q, pos: cut });
44061
+ else if (fetched[qi].length > take[qi]) more.push({ q, pos: offset + take[qi] });
44037
44062
  });
44038
- return reply(lines.concat(more).join("\n"), false);
44063
+ const moreLines = [];
44064
+ const byPos = /* @__PURE__ */ new Map();
44065
+ for (const m of more) byPos.set(m.pos, [...byPos.get(m.pos) ?? [], m.q]);
44066
+ for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope, input.source, "offset:" + pos));
44067
+ return reply(lines.concat(moreLines).join("\n"), false);
44039
44068
  }
44040
44069
  function timelineLine(r) {
44041
44070
  const nl = r.text.indexOf("\n");
@@ -44175,6 +44204,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
44175
44204
  const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
44176
44205
  const display = shown(chunks, ran.map((r) => r.head));
44177
44206
  const bodies = /* @__PURE__ */ new Map();
44207
+ const raw = /* @__PURE__ */ new Map();
44178
44208
  let total = 0;
44179
44209
  for (const c of chunks) total += c.bytes;
44180
44210
  let indexed = 0;
@@ -44195,7 +44225,10 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
44195
44225
  chunkCount: group.length,
44196
44226
  createdAt: Date.now()
44197
44227
  }, group);
44198
- for (const c of group) bodies.set(chunkKey(id, c.ord), display[c.ord]);
44228
+ for (const c of group) {
44229
+ bodies.set(chunkKey(id, c.ord), display[c.ord]);
44230
+ raw.set(chunkKey(id, c.ord), c.text);
44231
+ }
44199
44232
  indexed += groupBytes;
44200
44233
  group = [];
44201
44234
  groupBytes = 0;
@@ -44204,15 +44237,15 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
44204
44237
  for (const c of chunks) {
44205
44238
  if (queued + c.bytes > budgetBytes) {
44206
44239
  const stop2 = flush() ? "budget" : "deadline";
44207
- return { bodies, indexed, total, stop: stop2 };
44240
+ return { bodies, raw, indexed, total, stop: stop2 };
44208
44241
  }
44209
- if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, indexed, total, stop: "deadline" };
44242
+ if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, indexed, total, stop: "deadline" };
44210
44243
  group.push(c);
44211
44244
  groupBytes += c.bytes;
44212
44245
  queued += c.bytes;
44213
44246
  }
44214
44247
  const stop = flush() ? null : "deadline";
44215
- return { bodies, indexed, total, stop };
44248
+ return { bodies, raw, indexed, total, stop };
44216
44249
  }
44217
44250
  function bytes3(s) {
44218
44251
  return Buffer.byteLength(s, "utf8");
@@ -44245,7 +44278,7 @@ function answer(db, ctx, label, queries, share, own4) {
44245
44278
  else if (body.length === 0) body.push("No new section.");
44246
44279
  lines.push(head, ...body);
44247
44280
  }
44248
- return lines;
44281
+ return { lines, seen };
44249
44282
  }
44250
44283
  async function runBatch(input, ctx, boundMs, budgetBytes) {
44251
44284
  const parsed = ctxBatchSchema.safeParse(input);
@@ -44266,9 +44299,10 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
44266
44299
  const db = await openDb(ctx.project);
44267
44300
  let sections;
44268
44301
  let idx;
44269
- const summary = commands.length + " command(s), " + queries.length + " querie(s), exit " + last2.exitCode;
44302
+ const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
44270
44303
  const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label) + "})";
44271
44304
  let notice;
44305
+ let showMore;
44272
44306
  try {
44273
44307
  idx = indexCombined(db, ctx, label, ran, deadline, budgetBytes);
44274
44308
  const stop = last2.error;
@@ -44276,13 +44310,21 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
44276
44310
  const timeout = formatError3("TIMEOUT", { ms: boundMs });
44277
44311
  const cause = stop ?? (ctx.signal.aborted ? CANCELLED_LINE : idx.stop === "deadline" ? timeout : null);
44278
44312
  notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
44279
- const fixed = bytes3(summary) + 1 + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
44313
+ const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
44280
44314
  const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
44281
- sections = answer(db, ctx, label, queries, share, idx.bodies);
44315
+ const answered = answer(db, ctx, label, queries, share, idx.bodies);
44316
+ sections = answered.lines;
44317
+ const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
44318
+ const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
44319
+ if (unseen.length === 0 && cut === null) showMore = false;
44320
+ else if (cut === null && unseenBytes <= bytes3(footer) + 1) {
44321
+ showMore = false;
44322
+ sections = [...sections, ...unseen.map((t) => t.endsWith(LINE_SEP) ? t.slice(0, -1) : t)];
44323
+ } else showMore = true;
44282
44324
  } finally {
44283
44325
  closeDb(db);
44284
44326
  }
44285
- const lines = [summary, ...notice === null ? [] : [notice], ...sections, footer];
44327
+ const lines = [...exitLine === null ? [] : [exitLine], ...notice === null ? [] : [notice], ...sections, ...showMore ? [footer] : []];
44286
44328
  return {
44287
44329
  text: capBytes(lines.join(LINE_SEP), OUTPUT_CAP).text,
44288
44330
  // step 10: final bound (D-M2-6)
@@ -44306,7 +44348,7 @@ var ctxBatch = Object.freeze({
44306
44348
  });
44307
44349
 
44308
44350
  // src/core/tools/doctor.ts
44309
- import { readdirSync as readdirSync6, readFileSync as readFileSync8, existsSync as existsSync12 } from "node:fs";
44351
+ import { readdirSync as readdirSync6, readFileSync as readFileSync8, existsSync as existsSync13 } from "node:fs";
44310
44352
  import { basename as basename3, dirname as dirname5, join as join11 } from "node:path";
44311
44353
 
44312
44354
  // src/adapters/claude-code.ts
@@ -47338,15 +47380,15 @@ function withLayout(text, layout) {
47338
47380
  }
47339
47381
 
47340
47382
  // 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";
47383
+ function formatOf(path7) {
47384
+ if (path7.endsWith(JSONC_EXT)) return "jsonc";
47385
+ if (path7.endsWith(TOML_EXT)) return "toml";
47344
47386
  return "json";
47345
47387
  }
47346
- function readHostConfig(agent, path5) {
47347
- let file2 = path5;
47388
+ function readHostConfig(agent, path7) {
47389
+ let file2 = path7;
47348
47390
  if (agent === "opencode") {
47349
- const jsonc = join6(dirname3(path5), OPENCODE_CONFIG_FILES[0]);
47391
+ const jsonc = join6(dirname3(path7), OPENCODE_CONFIG_FILES[0]);
47350
47392
  if (existsSync4(jsonc)) file2 = jsonc;
47351
47393
  }
47352
47394
  const raw = existsSync4(file2) ? readFileSync4(file2, "utf8") : "";
@@ -47510,14 +47552,14 @@ function scanToml(text) {
47510
47552
  continue;
47511
47553
  }
47512
47554
  if (!node3.resolvedKey.every((seg) => typeof seg === "string")) continue;
47513
- const path5 = node3.resolvedKey;
47514
- for (const kv of node3.body) addKey(path5, kv);
47555
+ const path7 = node3.resolvedKey;
47556
+ for (const kv of node3.body) addKey(path7, kv);
47515
47557
  if (node3.kind !== "standard") continue;
47516
47558
  const start = lineStartOf(text, node3.range[0]);
47517
47559
  const headEnd = lineEndOf(text, node3.key.range[1]);
47518
47560
  const last2 = node3.body[node3.body.length - 1];
47519
47561
  tables.push({
47520
- path: path5,
47562
+ path: path7,
47521
47563
  header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
47522
47564
  start,
47523
47565
  end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
@@ -47528,16 +47570,16 @@ function scanToml(text) {
47528
47570
  function tomlTableSpans(text) {
47529
47571
  return scanToml(text).tables;
47530
47572
  }
47531
- function parseHostConfig(agent, path5, text, format) {
47573
+ function parseHostConfig(agent, path7, text, format) {
47532
47574
  try {
47533
47575
  return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
47534
47576
  } catch {
47535
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path5, format });
47577
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
47536
47578
  }
47537
47579
  }
47538
- function hostConfigValueAt(value, path5) {
47580
+ function hostConfigValueAt(value, path7) {
47539
47581
  let cur = value;
47540
- for (const seg of path5) {
47582
+ for (const seg of path7) {
47541
47583
  if (!isPlainObject6(cur)) return void 0;
47542
47584
  cur = cur[seg];
47543
47585
  }
@@ -47570,32 +47612,32 @@ function indentUnit(root, clean) {
47570
47612
  function render(value, unit, base) {
47571
47613
  return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
47572
47614
  }
47573
- function nest(path5, value) {
47615
+ function nest(path7, value) {
47574
47616
  let out = value;
47575
- for (let k = path5.length - 1; k >= 0; k -= 1) out = { [path5[k]]: out };
47617
+ for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
47576
47618
  return out;
47577
47619
  }
47578
- function setJsonText(text, format, path5, value) {
47620
+ function setJsonText(text, format, path7, value) {
47579
47621
  const doc = scanJson(text, format);
47580
47622
  const unit = indentUnit(doc.root, doc.clean);
47581
- if (doc.root === null) return render(nest(path5, value), unit, "") + "\n";
47623
+ if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
47582
47624
  let node3 = doc.root;
47583
47625
  let depth = 0;
47584
- while (depth < path5.length && node3.kind === "object") {
47585
- const hit = node3.members.find((m) => m.key === path5[depth]);
47626
+ while (depth < path7.length && node3.kind === "object") {
47627
+ const hit = node3.members.find((m) => m.key === path7[depth]);
47586
47628
  if (hit === void 0) break;
47587
47629
  node3 = hit.node;
47588
47630
  depth += 1;
47589
47631
  }
47590
- if (depth === path5.length) {
47632
+ if (depth === path7.length) {
47591
47633
  return text.slice(0, node3.start) + render(value, unit, lineIndent(doc.clean, node3.start)) + text.slice(node3.end);
47592
47634
  }
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);
47635
+ if (node3.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
47636
+ const rest = nest(path7.slice(depth + 1), value);
47595
47637
  const last2 = node3.members[node3.members.length - 1];
47596
47638
  if (last2 === void 0) {
47597
47639
  const base2 = lineIndent(doc.clean, node3.start);
47598
- const member2 = "\n" + base2 + unit + JSON.stringify(path5[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
47640
+ const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
47599
47641
  return text.slice(0, node3.start + 1) + member2 + text.slice(node3.end - 1);
47600
47642
  }
47601
47643
  const base = lineIndent(doc.clean, last2.keyStart);
@@ -47603,7 +47645,7 @@ function setJsonText(text, format, path5, value) {
47603
47645
  while (" \r\n".includes(doc.clean[at])) at += 1;
47604
47646
  const trailing = doc.clean[at] === ",";
47605
47647
  const insertAt = trailing ? at + 1 : last2.node.end;
47606
- const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path5[depth]) + ": " + render(rest, unit, base);
47648
+ const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
47607
47649
  return text.slice(0, insertAt) + member + text.slice(insertAt);
47608
47650
  }
47609
47651
  function tomlScalar(v) {
@@ -47621,17 +47663,17 @@ function tomlHeaderKey(seg) {
47621
47663
  }
47622
47664
  return seg;
47623
47665
  }
47624
- function tomlBlock(path5, value) {
47625
- let out = "[" + path5.map(tomlHeaderKey).join(".") + "]\n";
47666
+ function tomlBlock(path7, value) {
47667
+ let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
47626
47668
  const subs = [];
47627
47669
  for (const [k, v] of Object.entries(value)) {
47628
- if (isPlainObject6(v)) subs.push(tomlBlock([...path5, k], v));
47670
+ if (isPlainObject6(v)) subs.push(tomlBlock([...path7, k], v));
47629
47671
  else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
47630
47672
  }
47631
47673
  return [out, ...subs].join("\n");
47632
47674
  }
47633
- function under(path5, prefix) {
47634
- return path5.length >= prefix.length && prefix.every((seg, k) => path5[k] === seg);
47675
+ function under(path7, prefix) {
47676
+ return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
47635
47677
  }
47636
47678
  function keyLineRange(text, k) {
47637
47679
  const ls = lineStartOf(text, k.start);
@@ -47648,10 +47690,10 @@ function withValueAt(root, rel, value) {
47648
47690
  else base[rel[0]] = next;
47649
47691
  return base;
47650
47692
  }
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), ""]);
47693
+ function replaceToml(text, doc, path7, value) {
47694
+ const block = value === void 0 ? "" : tomlBlock(path7, value);
47695
+ const owned = doc.tables.filter((t) => under(t.path, path7));
47696
+ const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
47655
47697
  owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
47656
47698
  cuts.sort((a, b) => b[0] - a[0]);
47657
47699
  let out = text;
@@ -47661,27 +47703,27 @@ function replaceToml(text, doc, path5, value) {
47661
47703
  return out + sep3 + block;
47662
47704
  }
47663
47705
  var tableLike = (v) => v === void 0 || isPlainObject6(v);
47664
- function setTomlText(text, path5, value) {
47706
+ function setTomlText(text, path7, value) {
47665
47707
  if (value !== void 0 && !isPlainObject6(value)) throw new SyntaxError("TOML edits replace a whole table");
47666
47708
  const doc = scanToml(text);
47667
- const cur = hostConfigValueAt(doc.value, path5);
47709
+ const cur = hostConfigValueAt(doc.value, path7);
47668
47710
  if (sameValue(cur, value)) return text;
47669
- const inline = doc.keys.find((k) => k.inline && k.full.length < path5.length && under(path5, k.full));
47711
+ const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
47670
47712
  if (inline !== void 0) {
47671
- const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path5.slice(inline.full.length), value);
47713
+ const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
47672
47714
  return replaceToml(text, doc, inline.full, whole);
47673
47715
  }
47674
47716
  if (isPlainObject6(cur) && isPlainObject6(value)) {
47675
47717
  const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
47676
47718
  if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
47677
47719
  let out = text;
47678
- for (const k of names) out = setTomlText(out, [...path5, k], value[k]);
47720
+ for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
47679
47721
  return out;
47680
47722
  }
47681
47723
  }
47682
- return replaceToml(text, doc, path5, value);
47724
+ return replaceToml(text, doc, path7, value);
47683
47725
  }
47684
- function setText(agent, path5, text, format, key, value) {
47726
+ function setText(agent, path7, text, format, key, value) {
47685
47727
  try {
47686
47728
  if (format !== "toml") return setJsonText(text, format, key, value);
47687
47729
  const out = setTomlText(text, key, value);
@@ -47690,7 +47732,7 @@ function setText(agent, path5, text, format, key, value) {
47690
47732
  if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
47691
47733
  return out;
47692
47734
  } catch {
47693
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path5, format });
47735
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
47694
47736
  }
47695
47737
  }
47696
47738
  function serverScript() {
@@ -47737,14 +47779,14 @@ function ownTargets(agent, accept) {
47737
47779
  if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
47738
47780
  return [];
47739
47781
  }
47740
- function applyEdits(agent, path5, text, format, wanted) {
47741
- const parsed = parseHostConfig(agent, path5, text, format);
47782
+ function applyEdits(agent, path7, text, format, wanted) {
47783
+ const parsed = parseHostConfig(agent, path7, text, format);
47742
47784
  let out = text;
47743
47785
  const edits = [];
47744
47786
  for (const [key, after] of wanted) {
47745
47787
  const before = hostConfigValueAt(parsed, key);
47746
47788
  if (sameValue(before, after)) continue;
47747
- out = setText(agent, path5, out, format, key, after);
47789
+ out = setText(agent, path7, out, format, key, after);
47748
47790
  edits.push({ path: key.join("."), before, after });
47749
47791
  }
47750
47792
  return { text: out, format, edits };
@@ -47765,7 +47807,7 @@ function writeHostConfigEdit(_requested, current, patch) {
47765
47807
  // src/core/ops/detect-v1.ts
47766
47808
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
47767
47809
  var keyPath = (...parts) => parts.join(".");
47768
- var finding = (file2, path5, reason) => ({ file: file2, path: path5, reason });
47810
+ var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
47769
47811
  function stripJsonc(text) {
47770
47812
  let out = "";
47771
47813
  let inStr = false;
@@ -48072,8 +48114,8 @@ function detectV1(agent, home, scope = {}) {
48072
48114
  import { existsSync as existsSync6, readdirSync as readdirSync4, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
48073
48115
  import { dirname as dirname4, isAbsolute, join as join8, sep as sep2 } from "node:path";
48074
48116
  import { fileURLToPath } from "node:url";
48075
- function missing(agent, path5) {
48076
- return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path5 });
48117
+ function missing(agent, path7) {
48118
+ return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
48077
48119
  }
48078
48120
  function recordedInstallPaths(text) {
48079
48121
  let parsed;
@@ -48097,9 +48139,9 @@ function recordedInstallPaths(text) {
48097
48139
  }
48098
48140
  return out;
48099
48141
  }
48100
- var realOrNull = (path5) => {
48142
+ var realOrNull = (path7) => {
48101
48143
  try {
48102
- return realpathSync4.native(path5);
48144
+ return realpathSync4.native(path7);
48103
48145
  } catch {
48104
48146
  return null;
48105
48147
  }
@@ -48161,11 +48203,11 @@ function candidate(adapter, env) {
48161
48203
  }
48162
48204
  }
48163
48205
  function resolvePluginRoot(adapter, env) {
48164
- const path5 = candidate(adapter, env);
48206
+ const path7 = candidate(adapter, env);
48165
48207
  try {
48166
- return realpathSync4.native(path5);
48208
+ return realpathSync4.native(path7);
48167
48209
  } catch {
48168
- throw missing(adapter.id, path5);
48210
+ throw missing(adapter.id, path7);
48169
48211
  }
48170
48212
  }
48171
48213
 
@@ -48396,8 +48438,8 @@ async function loadSqlite2() {
48396
48438
  return null;
48397
48439
  }
48398
48440
  }
48399
- function openRead(sqlite, path5) {
48400
- return new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS, readOnly: true });
48441
+ function openRead(sqlite, path7) {
48442
+ return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
48401
48443
  }
48402
48444
  var cell = (row5) => Object.values(row5)[0];
48403
48445
  function readSchema(raw) {
@@ -48539,17 +48581,200 @@ function checkShell(env) {
48539
48581
  }
48540
48582
 
48541
48583
  // src/core/ops/doctor-hook.ts
48542
- import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
48584
+ import { existsSync as existsSync11, readFileSync as readFileSync7 } from "node:fs";
48585
+ import path6 from "node:path";
48586
+
48587
+ // src/setup/codex-trust.ts
48588
+ import { createHash } from "node:crypto";
48589
+ import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
48590
+ import path5 from "node:path";
48591
+ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
48592
+
48593
+ // src/setup/spawn-bin.ts
48594
+ import { spawnSync } from "node:child_process";
48595
+ import { accessSync as accessSync2, constants as fsc, statSync as statSync4 } from "node:fs";
48543
48596
  import path4 from "node:path";
48597
+ var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
48598
+ var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
48599
+ var DEFAULT_COMSPEC = "cmd.exe";
48600
+ function envGet(env, k) {
48601
+ return env[Object.keys(env).find((x) => x.toUpperCase() === k) ?? k];
48602
+ }
48603
+ function whichBin(bin, env, platform = process.platform) {
48604
+ const get = (k) => envGet(env, k);
48605
+ const win = platform === "win32";
48606
+ const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
48607
+ const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
48608
+ for (const dir of pathEntries(get("PATH") ?? "", platform)) {
48609
+ for (const n of names) {
48610
+ const f = path4.join(dir, n);
48611
+ try {
48612
+ accessSync2(f, fsc.X_OK);
48613
+ if (statSync4(f).isFile()) return f;
48614
+ } catch {
48615
+ }
48616
+ }
48617
+ }
48618
+ return void 0;
48619
+ }
48620
+ var CMD_QUOTE_CHARS = '"&|<>^()!';
48621
+ var CMD_PERCENT = "%";
48622
+ var CMD_SUBSTRING_MARK = ":";
48623
+ var CMD_DYNAMIC_VARS = Object.freeze(["CD", "DATE", "TIME", "RANDOM", "ERRORLEVEL", "CMDEXTVERSION", "CMDCMDLINE", "HIGHESTNUMANODENUMBER"]);
48624
+ function needsCmdQuotes(a) {
48625
+ if (a === "") return true;
48626
+ for (const c of a) if (c.trim() === "" || CMD_QUOTE_CHARS.includes(c)) return true;
48627
+ return false;
48628
+ }
48629
+ function expandablePercent(text, env) {
48630
+ const names = new Set(CMD_DYNAMIC_VARS);
48631
+ for (const k of Object.keys(env)) names.add(k.toUpperCase());
48632
+ for (let i = text.indexOf(CMD_PERCENT); i >= 0; i = text.indexOf(CMD_PERCENT, i + 1)) {
48633
+ for (let j = text.indexOf(CMD_PERCENT, i + 1); j >= 0; j = text.indexOf(CMD_PERCENT, j + 1)) {
48634
+ const inner = text.slice(i + 1, j);
48635
+ const cut = inner.indexOf(CMD_SUBSTRING_MARK);
48636
+ const name = cut < 0 ? inner : inner.slice(0, cut);
48637
+ if (name !== "" && names.has(name.toUpperCase())) return `${CMD_PERCENT}${inner}${CMD_PERCENT}`;
48638
+ }
48639
+ }
48640
+ return void 0;
48641
+ }
48642
+ function winCmdLine(file2, args, env = {}) {
48643
+ for (const a of [file2, ...args]) {
48644
+ const hit = expandablePercent(a, env);
48645
+ 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`);
48646
+ }
48647
+ const q = (a) => needsCmdQuotes(a) ? `"${a.split('"').join('""')}"` : a;
48648
+ return `"${[file2, ...args].map(q).join(" ")}"`;
48649
+ }
48650
+ function spawnForm(file2, args, env, platform = process.platform) {
48651
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
48652
+ return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
48653
+ }
48654
+ return { command: file2, args, windowsVerbatimArguments: false };
48655
+ }
48656
+
48657
+ // src/setup/codex-trust.ts
48658
+ var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
48659
+ var TRUST_KEY = ["hooks", "state"];
48660
+ var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
48661
+ var LIST_TIMEOUT_MS = 15e3;
48662
+ var EXIT_GRACE_MS = 5e3;
48663
+ var PLUGIN_SOURCE = "plugin";
48664
+ var TRUSTED = "trusted";
48665
+ function pluginHooksFromReply(m, pluginId) {
48666
+ const out = [];
48667
+ if (!isObj2(m) || !isObj2(m.result) || !Array.isArray(m.result.data)) return out;
48668
+ for (const d of m.result.data) {
48669
+ if (!isObj2(d) || !Array.isArray(d.hooks)) continue;
48670
+ for (const h of d.hooks) {
48671
+ if (!isObj2(h) || h.source !== PLUGIN_SOURCE || h.pluginId !== pluginId) continue;
48672
+ if (typeof h.key !== "string" || typeof h.currentHash !== "string") continue;
48673
+ if (out.some((x) => x.key === h.key)) continue;
48674
+ out.push({ key: h.key, hash: h.currentHash, trusted: h.trustStatus === TRUSTED });
48675
+ }
48676
+ }
48677
+ return out;
48678
+ }
48679
+ function listPluginHooks(env, pluginId, cwd) {
48680
+ const bin = whichBin("codex", env);
48681
+ if (!bin) return Promise.resolve(void 0);
48682
+ return new Promise((resolve5) => {
48683
+ let f;
48684
+ try {
48685
+ f = spawnForm(bin, ["app-server"], env);
48686
+ } catch {
48687
+ resolve5(void 0);
48688
+ return;
48689
+ }
48690
+ const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
48691
+ let buf = "";
48692
+ let done = false;
48693
+ let exited = false;
48694
+ let result;
48695
+ const settle3 = () => {
48696
+ clearTimeout(grace);
48697
+ resolve5(result);
48698
+ };
48699
+ let grace;
48700
+ const finish2 = (v) => {
48701
+ if (done) return;
48702
+ done = true;
48703
+ clearTimeout(timer);
48704
+ result = v;
48705
+ child.stdin.destroy();
48706
+ if (exited) {
48707
+ settle3();
48708
+ return;
48709
+ }
48710
+ grace = setTimeout(settle3, EXIT_GRACE_MS);
48711
+ stopTree(child.pid, () => child.kill());
48712
+ };
48713
+ const timer = setTimeout(() => finish2(void 0), LIST_TIMEOUT_MS);
48714
+ const send = (o) => {
48715
+ try {
48716
+ child.stdin.write(JSON.stringify(o) + "\n");
48717
+ } catch {
48718
+ finish2(void 0);
48719
+ }
48720
+ };
48721
+ child.on("error", () => finish2(void 0));
48722
+ child.on("close", () => {
48723
+ exited = true;
48724
+ if (done) settle3();
48725
+ else finish2(void 0);
48726
+ });
48727
+ child.stdin.on("error", () => finish2(void 0));
48728
+ child.stdout.setEncoding("utf8");
48729
+ child.stdout.on("data", (d) => {
48730
+ buf += d;
48731
+ const lines = buf.split("\n");
48732
+ buf = lines.pop() ?? "";
48733
+ for (const line of lines) {
48734
+ let m;
48735
+ try {
48736
+ m = JSON.parse(line);
48737
+ } catch {
48738
+ continue;
48739
+ }
48740
+ if (!isObj2(m)) continue;
48741
+ if (m.id === 1) {
48742
+ send({ method: "initialized" });
48743
+ send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
48744
+ } else if (m.id === 2) finish2(pluginHooksFromReply(m, pluginId));
48745
+ }
48746
+ });
48747
+ send({ id: 1, method: "initialize", params: { clientInfo: { name: "context-mode-setup", version: "2.0.0" } } });
48748
+ });
48749
+ }
48750
+ function stopTree(pid, kill) {
48751
+ if (process.platform === "win32" && pid !== void 0) {
48752
+ try {
48753
+ spawnSync2("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
48754
+ } catch {
48755
+ }
48756
+ }
48757
+ kill();
48758
+ }
48759
+ var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
48760
+ var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
48761
+ function untrustedPluginHooksDetail(hooks) {
48762
+ const bad = hooks.filter((h) => !h.trusted);
48763
+ if (!bad.length) return void 0;
48764
+ return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
48765
+ }
48766
+
48767
+ // src/core/ops/doctor-hook.ts
48544
48768
  var D5_MIN_PAIRS = 3;
48545
48769
  var D5_MAX_PAIRS = 9;
48770
+ var D5_CODEX_TRUST_FIX = "context-mode setup --agents codex";
48546
48771
  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
48772
  function isObject5(v) {
48548
48773
  return typeof v === "object" && v !== null && !Array.isArray(v);
48549
48774
  }
48550
48775
  function loadFixture(bundleDir2, agent) {
48551
- const file2 = path4.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
48552
- if (!existsSync10(file2)) return null;
48776
+ const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
48777
+ if (!existsSync11(file2)) return null;
48553
48778
  let all;
48554
48779
  try {
48555
48780
  all = JSON.parse(hostText(readFileSync7(file2, "utf8")));
@@ -48580,7 +48805,12 @@ function codexHookJournaled(db) {
48580
48805
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
48581
48806
  }
48582
48807
  async function checkHookRoundTrip(i) {
48583
- if (i.agent === "codex" && existsSync10(path4.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
48808
+ if (i.agent === "codex") {
48809
+ const hooks = await listPluginHooks(i.env, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
48810
+ const detail = hooks === void 0 ? void 0 : untrustedPluginHooksDetail(hooks);
48811
+ if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
48812
+ }
48813
+ if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
48584
48814
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
48585
48815
  }
48586
48816
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -48599,7 +48829,7 @@ async function checkHookRoundTrip(i) {
48599
48829
  let ms = 0;
48600
48830
  for (let n = 1; n <= maxPairs; n++) {
48601
48831
  const start = now();
48602
- const r = await runProcess([process.execPath, path4.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
48832
+ const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
48603
48833
  cwd: i.bundleDir,
48604
48834
  env: i.env,
48605
48835
  signal: i.signal,
@@ -48654,7 +48884,7 @@ function lastHookError(env) {
48654
48884
  }
48655
48885
 
48656
48886
  // src/core/ops/db-heal.ts
48657
- import { existsSync as existsSync11, rmSync as rmSync4 } from "node:fs";
48887
+ import { existsSync as existsSync12, rmSync as rmSync4 } from "node:fs";
48658
48888
  function integrityOk2(rows) {
48659
48889
  return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
48660
48890
  }
@@ -48688,7 +48918,7 @@ function renameAside(dbPath) {
48688
48918
  const ts = String(Date.now());
48689
48919
  for (const suffix of DB_SIBLING_SUFFIXES) {
48690
48920
  const file2 = dbPath + suffix;
48691
- if (existsSync11(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
48921
+ if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
48692
48922
  }
48693
48923
  return ts;
48694
48924
  }
@@ -48788,7 +49018,7 @@ async function guard(id, run) {
48788
49018
  }
48789
49019
  }
48790
49020
  async function codexDb(ctx, adapter) {
48791
- if (adapter.id !== "codex" || !existsSync12(ctx.project.dbPath)) return null;
49021
+ if (adapter.id !== "codex" || !existsSync13(ctx.project.dbPath)) return null;
48792
49022
  try {
48793
49023
  return await openDb(ctx.project, { readOnly: true });
48794
49024
  } catch {
@@ -48819,7 +49049,7 @@ async function hookRow(ctx, adapter, host) {
48819
49049
  }
48820
49050
  function ownServerId(configDir, projectKey) {
48821
49051
  const dir = join11(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
48822
- if (!existsSync12(dir)) return "";
49052
+ if (!existsSync13(dir)) return "";
48823
49053
  for (const name of readdirSync6(dir)) {
48824
49054
  if (!name.endsWith(OWNER_PID_EXT)) continue;
48825
49055
  if (readFileSync8(join11(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
@@ -48894,7 +49124,7 @@ var ctxDoctor = Object.freeze({
48894
49124
  });
48895
49125
 
48896
49126
  // src/core/tools/execute.ts
48897
- import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
49127
+ import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
48898
49128
  import { tmpdir as tmpdir2 } from "node:os";
48899
49129
  import { dirname as dirname6, join as join12, parse as parse5, resolve as resolve3 } from "node:path";
48900
49130
 
@@ -49019,7 +49249,7 @@ function schemaLine(issue4) {
49019
49249
  }
49020
49250
  function fileError(given, abs, root) {
49021
49251
  let dir = abs;
49022
- while (!existsSync13(dir) && dirname6(dir) !== dir) dir = dirname6(dir);
49252
+ while (!existsSync14(dir) && dirname6(dir) !== dir) dir = dirname6(dir);
49023
49253
  if (isInside(root, dir)) return null;
49024
49254
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
49025
49255
  }
@@ -49057,12 +49287,14 @@ async function finish(input, ctx, r, exitCode, journal) {
49057
49287
  const fullBytes = Buffer.byteLength(combined, "utf8");
49058
49288
  const head = summaryLine(exitCode, fullBytes);
49059
49289
  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) {
49290
+ const bare2 = exitCode === 0 && input.summary !== true && combined !== "";
49291
+ const direct = (bare2 ? "" : head + "\n") + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
49292
+ const fits = Buffer.byteLength(head + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined, "utf8") <= OUTPUT_CAP;
49293
+ if (intent === "" && fits) {
49062
49294
  return { text: direct, isError, sandboxBytes: fullBytes, journal };
49063
49295
  }
49064
49296
  const label = sourceLabel(input.code);
49065
- const budget = OUTPUT_CAP - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
49297
+ const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
49066
49298
  const db = await openDb(ctx.project);
49067
49299
  let picked;
49068
49300
  try {
@@ -49134,16 +49366,16 @@ var ctxExecute = {
49134
49366
  };
49135
49367
 
49136
49368
  // src/core/tools/index.ts
49137
- import { existsSync as existsSync14, readFileSync as readFileSync10, statSync as statSync5 } from "node:fs";
49369
+ import { existsSync as existsSync15, readFileSync as readFileSync10, statSync as statSync6 } from "node:fs";
49138
49370
  import { dirname as dirname7, extname, join as join14, relative as relative2, resolve as resolve4 } from "node:path";
49139
49371
 
49140
49372
  // src/core/index/walk.ts
49141
- import { readdirSync as readdirSync7, readFileSync as readFileSync9, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
49373
+ import { readdirSync as readdirSync7, readFileSync as readFileSync9, realpathSync as realpathSync7, statSync as statSync5 } from "node:fs";
49142
49374
  import { join as join13 } from "node:path";
49143
49375
  var GITIGNORE = ".gitignore";
49144
49376
  var GIT_DIR = ".git";
49145
49377
  function walkDir(root, containmentRoot) {
49146
- const real2 = realpathSync6(root);
49378
+ const real2 = realpathSync7(root);
49147
49379
  if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
49148
49380
  const found = [];
49149
49381
  visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
@@ -49160,19 +49392,19 @@ function visit(abs, rel, parent, contain, seen, found) {
49160
49392
  const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join13(abs, GITIGNORE), rel)) : parent;
49161
49393
  for (const e of entries) {
49162
49394
  if (e.name === GIT_DIR) continue;
49163
- const path5 = join13(abs, e.name);
49395
+ const path7 = join13(abs, e.name);
49164
49396
  let isDir = e.isDirectory();
49165
49397
  let isFile = e.isFile();
49166
- let target = path5;
49398
+ let target = path7;
49167
49399
  if (e.isSymbolicLink()) {
49168
49400
  let resolved;
49169
49401
  try {
49170
- resolved = realpathSync6(path5);
49402
+ resolved = realpathSync7(path7);
49171
49403
  } catch {
49172
49404
  continue;
49173
49405
  }
49174
49406
  if (!isInside(contain, resolved)) continue;
49175
- const st = statSync4(resolved);
49407
+ const st = statSync5(resolved);
49176
49408
  isDir = st.isDirectory();
49177
49409
  isFile = st.isFile();
49178
49410
  target = resolved;
@@ -49180,12 +49412,12 @@ function visit(abs, rel, parent, contain, seen, found) {
49180
49412
  const segs = rel.concat(e.name);
49181
49413
  if (ignored(rules, segs, isDir)) continue;
49182
49414
  if (isFile) {
49183
- found.push({ dir: rel, name: e.name, absPath: path5 });
49415
+ found.push({ dir: rel, name: e.name, absPath: path7 });
49184
49416
  } else if (isDir) {
49185
- const key = e.isSymbolicLink() ? target : realpathSync6(path5);
49417
+ const key = e.isSymbolicLink() ? target : realpathSync7(path7);
49186
49418
  if (seen.has(key)) continue;
49187
49419
  seen.add(key);
49188
- visit(path5, segs, rules, contain, seen, found);
49420
+ visit(path7, segs, rules, contain, seen, found);
49189
49421
  }
49190
49422
  }
49191
49423
  }
@@ -49376,12 +49608,12 @@ function tlsName(host) {
49376
49608
  function request(u, conn, proxy, signal) {
49377
49609
  const host = bare(u.hostname);
49378
49610
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
49379
- const path5 = u.pathname + u.search;
49611
+ const path7 = u.pathname + u.search;
49380
49612
  return new Promise((resolve5, reject) => {
49381
49613
  const onErr = (err) => reject(fail5(causeCode(err)));
49382
49614
  if (proxy === void 0) {
49383
49615
  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 } });
49616
+ const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
49385
49617
  req.on("response", resolve5).on("error", onErr).end();
49386
49618
  return;
49387
49619
  }
@@ -49403,7 +49635,7 @@ function request(u, conn, proxy, signal) {
49403
49635
  const req = https.request({
49404
49636
  host,
49405
49637
  port,
49406
- path: path5,
49638
+ path: path7,
49407
49639
  signal,
49408
49640
  headers: { host: u.host },
49409
49641
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
@@ -53290,7 +53522,7 @@ function readUtf8(absPath) {
53290
53522
  }
53291
53523
  function missingOrOutside(given, abs, root) {
53292
53524
  let dir = abs;
53293
- while (!existsSync14(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
53525
+ while (!existsSync15(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
53294
53526
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
53295
53527
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
53296
53528
  }
@@ -53298,15 +53530,15 @@ function pathItems(input, project) {
53298
53530
  const abs = resolve4(project.worktree, input.path);
53299
53531
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
53300
53532
  const base = relative2(project.worktree, abs);
53301
- if (statSync5(abs).isDirectory()) {
53533
+ if (statSync6(abs).isDirectory()) {
53302
53534
  return walkDir(abs, project.containmentRoot).map((f) => ({
53303
53535
  sourceKind: "path",
53304
- label: join14(base, f.relPath),
53536
+ label: pathLabel(join14(base, f.relPath)),
53305
53537
  kind: kindOfPath(f.relPath),
53306
53538
  read: () => readUtf8(f.absPath)
53307
53539
  }));
53308
53540
  }
53309
- return [{ sourceKind: "path", label: base === "" ? input.path : base, kind: kindOfPath(abs), read: () => readUtf8(abs) }];
53541
+ return [{ sourceKind: "path", label: pathLabel(base === "" ? input.path : base), kind: kindOfPath(abs), read: () => readUtf8(abs) }];
53310
53542
  }
53311
53543
  async function itemsOf(input, ctx) {
53312
53544
  if (input.content !== void 0) {
@@ -53317,7 +53549,7 @@ async function itemsOf(input, ctx) {
53317
53549
  }
53318
53550
  if (input.path !== void 0) {
53319
53551
  const items = pathItems({ ...input, path: input.path }, ctx.project);
53320
- return { items, from: items.length === 1 ? items[0].label : input.path };
53552
+ return { items, from: items.length === 1 ? items[0].label : pathLabel(input.path) };
53321
53553
  }
53322
53554
  const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
53323
53555
  const text = res.body.toString("utf8");
@@ -53414,10 +53646,11 @@ function scopesOf(input) {
53414
53646
  function changes(raw, sql, ...args) {
53415
53647
  return Number(raw.prepare(sql).run(...args).changes);
53416
53648
  }
53417
- function purgeScope(raw, scope, input) {
53649
+ function purgeScope(db, scope, input) {
53650
+ const raw = db.raw;
53418
53651
  if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
53419
53652
  if (scope === "source") {
53420
- const label = input.source;
53653
+ const label = storedLabel(db, input.source);
53421
53654
  return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?", label);
53422
53655
  }
53423
53656
  const chunks = deleteChunkRows(raw, "all");
@@ -53435,7 +53668,7 @@ async function handler5(input, ctx) {
53435
53668
  try {
53436
53669
  const db = await openDb(ctx.project);
53437
53670
  try {
53438
- const rows = withWrite(db, (h) => purgeScope(h.raw, scope, input));
53671
+ const rows = withWrite(db, (h) => purgeScope(h, scope, input));
53439
53672
  return reply2(PURGE_SUMMARY(rows, scope), false);
53440
53673
  } finally {
53441
53674
  closeDb(db);
@@ -53499,8 +53732,8 @@ function buildCandidates(rows, sessionId) {
53499
53732
  edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
53500
53733
  }
53501
53734
  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);
53735
+ for (const [path7, e] of edits) {
53736
+ const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
53504
53737
  changedFiles.push({ ...c, editCount: e.count });
53505
53738
  }
53506
53739
  changedFiles.sort((a, b) => a.seq - b.seq);
@@ -53822,11 +54055,11 @@ var ctxStats = Object.freeze({
53822
54055
  });
53823
54056
 
53824
54057
  // src/core/tools/upgrade.ts
53825
- import { existsSync as existsSync20, realpathSync as realpathSync7, rmSync as rmSync10 } from "node:fs";
54058
+ import { existsSync as existsSync21, realpathSync as realpathSync8, rmSync as rmSync10 } from "node:fs";
53826
54059
  import { basename as basename5, dirname as dirname9, join as join20 } from "node:path";
53827
54060
 
53828
54061
  // src/core/ops/host-write.ts
53829
- import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
54062
+ import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
53830
54063
  import { dirname as dirname8, join as join15 } from "node:path";
53831
54064
  function defaultWrite(file2, text) {
53832
54065
  writeFileSync4(file2, text, "utf8");
@@ -53855,7 +54088,7 @@ function toRow(file2, edit) {
53855
54088
  function writeWithRollback(file2, text, write, atomic) {
53856
54089
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
53857
54090
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
53858
- const had = existsSync15(file2);
54091
+ const had = existsSync16(file2);
53859
54092
  mkdirSync5(dirname8(file2), { recursive: true });
53860
54093
  if (had) copyFileSync(file2, trash);
53861
54094
  try {
@@ -53885,7 +54118,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
53885
54118
  if (requested === null) return [];
53886
54119
  const current = readHostConfig(row5.id, requested);
53887
54120
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
53888
- const exists = existsSync15(current.path);
54121
+ const exists = existsSync16(current.path);
53889
54122
  if (exists && result.text === current.text) return [];
53890
54123
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
53891
54124
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -53893,15 +54126,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
53893
54126
  }
53894
54127
 
53895
54128
  // 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";
54129
+ import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
53897
54130
  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);
54131
+ function linkTarget(path7, win) {
54132
+ if (!isLink(path7)) return null;
54133
+ const target = readlinkSync(path7);
53901
54134
  return win ? win322.basename(target) : target;
53902
54135
  }
53903
- function isLink(path5) {
53904
- return lstatSync(path5, { throwIfNoEntry: false })?.isSymbolicLink() === true;
54136
+ function isLink(path7) {
54137
+ return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
53905
54138
  }
53906
54139
  function generations(agentDir) {
53907
54140
  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,7 +54147,7 @@ function settleLinks(link, tmp, old, opts) {
53914
54147
  }
53915
54148
  function swapPluginCurrent(agentDir, sha, opts = {}) {
53916
54149
  const next = join16(agentDir, sha);
53917
- if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
54150
+ if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
53918
54151
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
53919
54152
  }
53920
54153
  const link = join16(agentDir, PLUGIN_CURRENT_LINK);
@@ -53934,12 +54167,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
53934
54167
  if (before !== null) keep.add(before);
53935
54168
  const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join16(agentDir, name));
53936
54169
  for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
53937
- const previous = before !== null && existsSync16(join16(agentDir, before)) ? join16(agentDir, before) : null;
54170
+ const previous = before !== null && existsSync17(join16(agentDir, before)) ? join16(agentDir, before) : null;
53938
54171
  return { current: next, previous, removed };
53939
54172
  }
53940
54173
 
53941
54174
  // src/core/ops/release-fetch.ts
53942
- import { existsSync as existsSync17, mkdirSync as mkdirSync6, rmSync as rmSync7 } from "node:fs";
54175
+ import { existsSync as existsSync18, mkdirSync as mkdirSync6, rmSync as rmSync7 } from "node:fs";
53943
54176
  import { join as join17 } from "node:path";
53944
54177
  function failed(r) {
53945
54178
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -53963,7 +54196,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
53963
54196
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
53964
54197
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
53965
54198
  const dir = join17(agentDir, sha);
53966
- if (existsSync17(dir)) rmSync7(fetchDir, { recursive: true, force: true });
54199
+ if (existsSync18(dir)) rmSync7(fetchDir, { recursive: true, force: true });
53967
54200
  else renameWithRetry(fetchDir, dir, opts);
53968
54201
  return { sha, dir };
53969
54202
  } catch (e) {
@@ -53973,7 +54206,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
53973
54206
  }
53974
54207
 
53975
54208
  // src/core/ops/uninstall.ts
53976
- import { existsSync as existsSync18, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync5 } from "node:fs";
54209
+ import { existsSync as existsSync19, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync5 } from "node:fs";
53977
54210
  import { join as join18 } from "node:path";
53978
54211
  function row2(area, before, after) {
53979
54212
  return { area, before, after };
@@ -54003,7 +54236,7 @@ function removeCache(adapter, env, configDir) {
54003
54236
  }
54004
54237
  case "plugin": {
54005
54238
  const agentDir = join18(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
54006
- if (!existsSync18(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
54239
+ if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
54007
54240
  rmSync8(agentDir, { recursive: true, force: true });
54008
54241
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
54009
54242
  }
@@ -54016,11 +54249,11 @@ function removeCache(adapter, env, configDir) {
54016
54249
  }
54017
54250
  }
54018
54251
  }
54019
- function isObj2(v) {
54252
+ function isObj3(v) {
54020
54253
  return typeof v === "object" && v !== null && !Array.isArray(v);
54021
54254
  }
54022
54255
  function piSource(entry) {
54023
- return isObj2(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
54256
+ return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
54024
54257
  }
54025
54258
  function ownEntries(agent, env) {
54026
54259
  const home = requireHomeDir(env);
@@ -54029,11 +54262,11 @@ function ownEntries(agent, env) {
54029
54262
  const top = mcp.key[0];
54030
54263
  const inner = mcp.key.slice(1, -1);
54031
54264
  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) => {
54265
+ const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
54266
+ const without = (v, path7) => {
54034
54267
  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)) };
54268
+ if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
54269
+ return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
54037
54270
  };
54038
54271
  return [{
54039
54272
  file: ownMcpFileOf(agent, mcp.file, env, home),
@@ -54041,7 +54274,7 @@ function ownEntries(agent, env) {
54041
54274
  shown: mcp.key.join(V1_KEY_PATH_SEP),
54042
54275
  has: (v) => {
54043
54276
  const h = holder(v);
54044
- return isObj2(h) && Object.hasOwn(h, own4);
54277
+ return isObj3(h) && Object.hasOwn(h, own4);
54045
54278
  },
54046
54279
  drop: (v) => without(v, inner)
54047
54280
  }];
@@ -54083,7 +54316,7 @@ function removeOwnEntries(agent, env) {
54083
54316
  function removeProjectData(configDir, projectKey) {
54084
54317
  const projects = join18(configDir, PROJECTS_DIR_NAME);
54085
54318
  const dir = join18(projects, projectKey);
54086
- if (!existsSync18(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
54319
+ if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
54087
54320
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
54088
54321
  for (const name of readdirSync9(dir)) {
54089
54322
  if (name !== OWNERS_DIR_NAME) rmSync8(join18(dir, name), { recursive: true, force: true });
@@ -54099,8 +54332,8 @@ function runUninstall(input) {
54099
54332
  }
54100
54333
 
54101
54334
  // 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);
54335
+ import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync11, rmSync as rmSync9 } from "node:fs";
54336
+ var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
54104
54337
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
54105
54338
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
54106
54339
  function moveAside(target, undo) {
@@ -54129,17 +54362,17 @@ function cutTomlTable(text, header) {
54129
54362
  function writeAtomic(file2, text) {
54130
54363
  atomicWriteFile(file2, text);
54131
54364
  }
54132
- function locate(doc, path5) {
54133
- const segs = path5.split(V1_KEY_PATH_SEP);
54365
+ function locate(doc, path7) {
54366
+ const segs = path7.split(V1_KEY_PATH_SEP);
54134
54367
  let cur = doc;
54135
54368
  for (const seg of segs.slice(0, -1)) {
54136
54369
  if (Array.isArray(cur)) cur = cur[Number(seg)];
54137
- else if (isObj3(cur)) cur = cur[seg];
54370
+ else if (isObj4(cur)) cur = cur[seg];
54138
54371
  else return null;
54139
54372
  }
54140
54373
  const last2 = segs[segs.length - 1];
54141
54374
  if (Array.isArray(cur)) return Number(last2) < cur.length ? [cur, last2] : null;
54142
- if (isObj3(cur)) return Object.hasOwn(cur, last2) ? [cur, last2] : null;
54375
+ if (isObj4(cur)) return Object.hasOwn(cur, last2) ? [cur, last2] : null;
54143
54376
  return null;
54144
54377
  }
54145
54378
  function stripJsonEntries(agent, file2, findings, kept, undo) {
@@ -54180,14 +54413,14 @@ function removeV1(agent, findings) {
54180
54413
  for (const f of findings) {
54181
54414
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
54182
54415
  else if (f.path === "") {
54183
- if (existsSync19(f.file)) {
54416
+ if (existsSync20(f.file)) {
54184
54417
  moveAside(f.file, undo);
54185
54418
  done.set(f, UPGRADE_REMOVED);
54186
54419
  } else done.set(f, UPGRADE_NOT_FOUND);
54187
54420
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
54188
54421
  }
54189
54422
  for (const [file2, list3] of entries) {
54190
- if (!existsSync19(file2)) {
54423
+ if (!existsSync20(file2)) {
54191
54424
  for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
54192
54425
  continue;
54193
54426
  }
@@ -54220,7 +54453,7 @@ function removeV1(agent, findings) {
54220
54453
  },
54221
54454
  rollback() {
54222
54455
  for (const u of undo.splice(0).reverse()) {
54223
- if (!existsSync19(u.trash)) continue;
54456
+ if (!existsSync20(u.trash)) continue;
54224
54457
  rmSync9(u.target, { recursive: true, force: true });
54225
54458
  renameWithRetry(u.trash, u.target);
54226
54459
  }
@@ -54229,7 +54462,7 @@ function removeV1(agent, findings) {
54229
54462
  }
54230
54463
 
54231
54464
  // src/core/ops/verify-sums.ts
54232
- import { createHash } from "node:crypto";
54465
+ import { createHash as createHash2 } from "node:crypto";
54233
54466
  import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync12 } from "node:fs";
54234
54467
  import { join as join19 } from "node:path";
54235
54468
  function mismatch() {
@@ -54269,7 +54502,7 @@ function verifySums(dir) {
54269
54502
  for (const [rel, abs] of files) {
54270
54503
  const want = sums.get(rel);
54271
54504
  if (want === void 0) throw mismatch();
54272
- const got = createHash(SUMS_HASH_ALGORITHM).update(readFileSync12(abs)).digest(HASH_ENCODING);
54505
+ const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync12(abs)).digest(HASH_ENCODING);
54273
54506
  if (got !== want) throw mismatch();
54274
54507
  }
54275
54508
  }
@@ -54298,7 +54531,7 @@ function pluginRootRow(adapter, env) {
54298
54531
  }
54299
54532
  function isCurrent(agentDir, dir) {
54300
54533
  const link = join20(agentDir, PLUGIN_CURRENT_LINK);
54301
- return existsSync20(link) && realpathSync7.native(link) === realpathSync7.native(dir);
54534
+ return existsSync21(link) && realpathSync8.native(link) === realpathSync8.native(dir);
54302
54535
  }
54303
54536
  async function checkout(adapter, deps) {
54304
54537
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
@@ -54417,12 +54650,12 @@ function checkCall(tool, input) {
54417
54650
  }
54418
54651
 
54419
54652
  // src/entries/is-entry.ts
54420
- import { realpathSync as realpathSync8 } from "node:fs";
54653
+ import { realpathSync as realpathSync9 } from "node:fs";
54421
54654
  function isEntry(main, argv1, self) {
54422
54655
  if (main !== void 0) return main;
54423
54656
  if (argv1 === void 0 || argv1 === "") return false;
54424
54657
  try {
54425
- return realpathSync8(argv1) === realpathSync8(self);
54658
+ return realpathSync9(argv1) === realpathSync9(self);
54426
54659
  } catch {
54427
54660
  return false;
54428
54661
  }
@@ -54498,7 +54731,7 @@ function workspaceFromMeta(meta3) {
54498
54731
  }
54499
54732
  function realOrSame(p) {
54500
54733
  try {
54501
- return realpathSync9.native(p);
54734
+ return realpathSync10.native(p);
54502
54735
  } catch {
54503
54736
  return p;
54504
54737
  }
@@ -54546,7 +54779,7 @@ async function startServer(argv, env) {
54546
54779
  opening.catch(() => pending.delete(project.dbPath));
54547
54780
  }
54548
54781
  const db = await opening;
54549
- if (!existsSync21(db.path)) throw new CtxError("DB_GONE");
54782
+ if (!existsSync22(db.path)) throw new CtxError("DB_GONE");
54550
54783
  return db;
54551
54784
  }
54552
54785
  function stopMarker(configDir, projectKey) {
@@ -54554,7 +54787,7 @@ async function startServer(argv, env) {
54554
54787
  }
54555
54788
  function stopRequested() {
54556
54789
  const configDir = resolveConfigDir(process.env);
54557
- return held.some((db) => existsSync21(stopMarker(configDir, db.projectKey)));
54790
+ return held.some((db) => existsSync22(stopMarker(configDir, db.projectKey)));
54558
54791
  }
54559
54792
  async function journal(project, ctx, name, reply4) {
54560
54793
  const db = await ownDb(project);