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/pi/index.js CHANGED
@@ -657,10 +657,10 @@ function assignProp(target, prop, value) {
657
657
  configurable: true
658
658
  });
659
659
  }
660
- function getElementAtPath(obj, path5) {
661
- if (!path5)
660
+ function getElementAtPath(obj, path7) {
661
+ if (!path7)
662
662
  return obj;
663
- return path5.reduce((acc, key) => acc?.[key], obj);
663
+ return path7.reduce((acc, key) => acc?.[key], obj);
664
664
  }
665
665
  function promiseAllObject(promisesObj) {
666
666
  const keys = Object.keys(promisesObj);
@@ -980,11 +980,11 @@ function aborted(x, startIndex = 0) {
980
980
  }
981
981
  return false;
982
982
  }
983
- function prefixIssues(path5, issues) {
983
+ function prefixIssues(path7, issues) {
984
984
  return issues.map((iss) => {
985
985
  var _a5;
986
986
  (_a5 = iss).path ?? (_a5.path = []);
987
- iss.path.unshift(path5);
987
+ iss.path.unshift(path7);
988
988
  return iss;
989
989
  });
990
990
  }
@@ -1121,7 +1121,7 @@ function treeifyError(error42, _mapper) {
1121
1121
  return issue4.message;
1122
1122
  };
1123
1123
  const result = { errors: [] };
1124
- const processError = (error43, path5 = []) => {
1124
+ const processError = (error43, path7 = []) => {
1125
1125
  var _a5, _b;
1126
1126
  for (const issue4 of error43.issues) {
1127
1127
  if (issue4.code === "invalid_union" && issue4.errors.length) {
@@ -1131,7 +1131,7 @@ function treeifyError(error42, _mapper) {
1131
1131
  } else if (issue4.code === "invalid_element") {
1132
1132
  processError({ issues: issue4.issues }, issue4.path);
1133
1133
  } else {
1134
- const fullpath = [...path5, ...issue4.path];
1134
+ const fullpath = [...path7, ...issue4.path];
1135
1135
  if (fullpath.length === 0) {
1136
1136
  result.errors.push(mapper(issue4));
1137
1137
  continue;
@@ -1161,9 +1161,9 @@ function treeifyError(error42, _mapper) {
1161
1161
  processError(error42);
1162
1162
  return result;
1163
1163
  }
1164
- function toDotPath(path5) {
1164
+ function toDotPath(path7) {
1165
1165
  const segs = [];
1166
- for (const seg of path5) {
1166
+ for (const seg of path7) {
1167
1167
  if (typeof seg === "number")
1168
1168
  segs.push(`[${seg}]`);
1169
1169
  else if (typeof seg === "symbol")
@@ -11154,6 +11154,7 @@ function prefixToolNames(text, prefix) {
11154
11154
  return out;
11155
11155
  }
11156
11156
  var OUTPUT_CAP = 16384;
11157
+ var EXEC_PREVIEW_BYTES = 4096;
11157
11158
  var STATE_BUDGET = 2048;
11158
11159
  var RESUME_CAP = 2048;
11159
11160
  var REPORT_CAP = 4096;
@@ -11331,7 +11332,7 @@ var TOOLS_TTL_MS = 36e5;
11331
11332
  var IN_PROCESS_TIMEOUT_MS = 0;
11332
11333
  var MS_PER_DAY = 864e5;
11333
11334
  var PROJECT_KEY_HEX_LEN = 16;
11334
- var SCHEMA_VERSION = 5;
11335
+ var SCHEMA_VERSION = 6;
11335
11336
  var RETENTION_IDLE_DAYS = 30;
11336
11337
  var RETENTION_SIZE_CAP_BYTES = 524288e3;
11337
11338
  var PROJECT_DEAD_IDLE_DAYS = 14;
@@ -11508,7 +11509,7 @@ var DECISION_OPTION_KEY = "option";
11508
11509
  var DECISION_LABEL_JOIN = " | ";
11509
11510
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
11510
11511
  var RELEASE_BRANCH = "release";
11511
- var BUNDLE_SHA = true ? "a31ac1245e4994b18efe99e363e9a86409abb025" : void 0;
11512
+ var BUNDLE_SHA = true ? "baaa3149e881980288944e90179895fa6a2be13e" : void 0;
11512
11513
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
11513
11514
  var DOCTOR_LABEL = Object.freeze({
11514
11515
  D1: "version",
@@ -14291,10 +14292,10 @@ function readPluginAgent(claudeDir, type) {
14291
14292
  }
14292
14293
  return null;
14293
14294
  }
14294
- function readAgentFile(path5) {
14295
+ function readAgentFile(path7) {
14295
14296
  let text;
14296
14297
  try {
14297
- text = readFileSync(path5, "utf8");
14298
+ text = readFileSync(path7, "utf8");
14298
14299
  } catch {
14299
14300
  return null;
14300
14301
  }
@@ -14557,12 +14558,12 @@ function readUserDeny(projectDir, agent) {
14557
14558
  }
14558
14559
  return out;
14559
14560
  }
14560
- function tokenize(glob, path5) {
14561
+ function tokenize(glob, path7) {
14561
14562
  const toks = [];
14562
14563
  let i = 0;
14563
14564
  while (i < glob.length) {
14564
14565
  const c = glob[i];
14565
- if (c === "*" && path5 && glob[i + 1] === "*") {
14566
+ if (c === "*" && path7 && glob[i + 1] === "*") {
14566
14567
  const dir = glob[i + "**".length] === "/";
14567
14568
  toks.push({ t: dir ? "globstarDir" : "globstar" });
14568
14569
  i += dir ? "**/".length : "**".length;
@@ -14576,8 +14577,8 @@ function tokenize(glob, path5) {
14576
14577
  }
14577
14578
  return toks;
14578
14579
  }
14579
- function globMatch(glob, text, path5) {
14580
- const toks = tokenize(glob, path5);
14580
+ function globMatch(glob, text, path7) {
14581
+ const toks = tokenize(glob, path7);
14581
14582
  const n = text.length;
14582
14583
  let next = new Uint8Array(n + 1);
14583
14584
  next[n] = 1;
@@ -14593,10 +14594,10 @@ function globMatch(glob, text, path5) {
14593
14594
  cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
14594
14595
  break;
14595
14596
  case "any1":
14596
- cur[j] = has3 && !(path5 && ch === "/") ? next[j + 1] : 0;
14597
+ cur[j] = has3 && !(path7 && ch === "/") ? next[j + 1] : 0;
14597
14598
  break;
14598
14599
  case "star":
14599
- cur[j] = next[j] || (has3 && !(path5 && ch === "/") ? cur[j + 1] : 0);
14600
+ cur[j] = next[j] || (has3 && !(path7 && ch === "/") ? cur[j + 1] : 0);
14600
14601
  break;
14601
14602
  case "globstar":
14602
14603
  cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
@@ -14676,8 +14677,8 @@ var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limi
14676
14677
  // src/core/policy/read-deny.ts
14677
14678
  var SIZE = "{size}";
14678
14679
  var PATH = "{path}";
14679
- function READ_DENY_MESSAGE(path5, size, prefix = "") {
14680
- return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path5);
14680
+ function READ_DENY_MESSAGE(path7, size, prefix = "") {
14681
+ return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path7);
14681
14682
  }
14682
14683
 
14683
14684
  // src/core/policy/decide.ts
@@ -15180,8 +15181,8 @@ function firstLine(file2) {
15180
15181
  return line === "" ? null : line;
15181
15182
  }
15182
15183
  function git(dir, args) {
15183
- const { spawnSync } = process.getBuiltinModule("node:child_process");
15184
- const r = spawnSync("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
15184
+ const { spawnSync: spawnSync3 } = process.getBuiltinModule("node:child_process");
15185
+ const r = spawnSync3("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
15185
15186
  if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
15186
15187
  return r.stdout.split("\n").filter((l) => l !== "");
15187
15188
  }
@@ -15322,12 +15323,16 @@ CREATE VIRTUAL TABLE line_units USING fts5(
15322
15323
  ${FTS_TOKENIZE}
15323
15324
  );
15324
15325
  `;
15326
+ var DDL_V6 = `
15327
+ UPDATE sources SET label = replace(label, char(92), '/') WHERE kind = 'path' AND instr(label, char(92)) > 0;
15328
+ `;
15325
15329
  var MIGRATIONS = [
15326
15330
  { version: 1, sql: DDL },
15327
15331
  { version: 2, sql: DDL_V2 },
15328
15332
  { version: 3, sql: DDL_V3 },
15329
15333
  { version: 4, sql: DDL_V4 },
15330
- { version: 5, sql: DDL_V5 }
15334
+ { version: 5, sql: DDL_V5 },
15335
+ { version: 6, sql: DDL_V6 }
15331
15336
  ];
15332
15337
  function applyMigrations(db, fromVersion) {
15333
15338
  if (fromVersion === SCHEMA_VERSION2) return;
@@ -15381,9 +15386,9 @@ function readUserVersion(raw) {
15381
15386
  const row5 = raw.prepare("PRAGMA user_version").get();
15382
15387
  return row5.user_version;
15383
15388
  }
15384
- function createAtomically(sqlite, path5) {
15389
+ function createAtomically(sqlite, path7) {
15385
15390
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
15386
- const tmp = path5 + "." + randomUUID2() + DB_TMP_SUFFIX;
15391
+ const tmp = path7 + "." + randomUUID2() + DB_TMP_SUFFIX;
15387
15392
  try {
15388
15393
  const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
15389
15394
  try {
@@ -15392,7 +15397,7 @@ function createAtomically(sqlite, path5) {
15392
15397
  raw.close();
15393
15398
  }
15394
15399
  try {
15395
- linkSync(tmp, path5);
15400
+ linkSync(tmp, path7);
15396
15401
  } catch (err) {
15397
15402
  if (err.code !== "EEXIST") throw err;
15398
15403
  }
@@ -15400,11 +15405,11 @@ function createAtomically(sqlite, path5) {
15400
15405
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
15401
15406
  }
15402
15407
  }
15403
- function openWritable(sqlite, path5) {
15408
+ function openWritable(sqlite, path7) {
15404
15409
  let raw = null;
15405
15410
  try {
15406
- if (!existsSync2(path5)) createAtomically(sqlite, path5);
15407
- raw = new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS });
15411
+ if (!existsSync2(path7)) createAtomically(sqlite, path7);
15412
+ raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
15408
15413
  applyMigrations(raw, readUserVersion(raw));
15409
15414
  return raw;
15410
15415
  } catch (err) {
@@ -15412,8 +15417,8 @@ function openWritable(sqlite, path5) {
15412
15417
  throw err;
15413
15418
  }
15414
15419
  }
15415
- function openReadOnly(sqlite, path5) {
15416
- const raw = new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS, readOnly: true });
15420
+ function openReadOnly(sqlite, path7) {
15421
+ const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
15417
15422
  try {
15418
15423
  const found = readUserVersion(raw);
15419
15424
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -15427,20 +15432,20 @@ async function openDb(project, opts) {
15427
15432
  if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
15428
15433
  const sqlite = await loadSqlite();
15429
15434
  mkdirSync2(project.projectDir, { recursive: true });
15430
- const path5 = project.dbPath;
15431
- const sibling = existsSync2(path5 + DB_WAL_SUFFIX) || existsSync2(path5 + DB_SHM_SUFFIX);
15432
- if (sibling && !existsSync2(path5)) {
15435
+ const path7 = project.dbPath;
15436
+ const sibling = existsSync2(path7 + DB_WAL_SUFFIX) || existsSync2(path7 + DB_SHM_SUFFIX);
15437
+ if (sibling && !existsSync2(path7)) {
15433
15438
  throw new CtxError("DB_GONE");
15434
15439
  }
15435
15440
  try {
15436
15441
  let raw;
15437
15442
  if (opts?.readOnly === true) {
15438
- if (!existsSync2(path5)) openWritable(sqlite, path5).close();
15439
- raw = openReadOnly(sqlite, path5);
15443
+ if (!existsSync2(path7)) openWritable(sqlite, path7).close();
15444
+ raw = openReadOnly(sqlite, path7);
15440
15445
  } else {
15441
- raw = openWritable(sqlite, path5);
15446
+ raw = openWritable(sqlite, path7);
15442
15447
  }
15443
- return { raw, projectKey: project.projectKey, path: path5, ...opts?.readOnly === true ? { readOnly: true } : {} };
15448
+ return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
15444
15449
  } catch (err) {
15445
15450
  if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
15446
15451
  throw err;
@@ -17864,7 +17869,7 @@ function ftsQuery(db, q, scope, ctx, sessionId, limit, offset, source) {
17864
17869
  }
17865
17870
  return page2.map((e) => {
17866
17871
  const r = rows.get(Number(e.r.rid));
17867
- return { sourceId: Number(r.source_id), label: r.label, ord: Number(r.ord), snippet: highlight(r.body, q, SNIPPET_MAX_BYTES), score: e.s };
17872
+ 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 };
17868
17873
  });
17869
17874
  }
17870
17875
  var LIST = `
@@ -18033,17 +18038,29 @@ function parseSourceHandle(s) {
18033
18038
  }
18034
18039
  return n > 0 && sourceHandle(n) === s ? n : null;
18035
18040
  }
18041
+ function pathLabel(p) {
18042
+ return p.includes("\\") ? p.split("\\").join("/") : p;
18043
+ }
18044
+ function labelStored(db, label) {
18045
+ return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label) !== void 0;
18046
+ }
18047
+ function storedLabel(db, source) {
18048
+ if (labelStored(db, source)) return source;
18049
+ const canon = pathLabel(source);
18050
+ return canon !== source && labelStored(db, canon) ? canon : source;
18051
+ }
18036
18052
  function resolveSourceLabel(db, source) {
18037
18053
  const id = parseSourceHandle(source);
18038
18054
  if (id !== null) {
18039
18055
  const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = ?").get(id);
18040
18056
  if (row5 !== void 0) return row5.label;
18041
18057
  }
18042
- if (stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(source) !== void 0) return source;
18043
- const prefix = source + LABEL_SUFFIX_SEP;
18058
+ const named = storedLabel(db, source);
18059
+ if (labelStored(db, named)) return named;
18060
+ const prefix = named + LABEL_SUFFIX_SEP;
18044
18061
  const rows = stmt(db.raw, "SELECT label FROM sources WHERE substr(label, 1, ?) = ? ORDER BY id DESC").all(prefix.length, prefix);
18045
18062
  for (const r of rows) {
18046
- if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === source.length) return r.label;
18063
+ if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named.length) return r.label;
18047
18064
  }
18048
18065
  return source;
18049
18066
  }
@@ -18149,8 +18166,8 @@ function buildCandidates(rows, sessionId) {
18149
18166
  edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
18150
18167
  }
18151
18168
  const changedFiles = [];
18152
- for (const [path5, e] of edits) {
18153
- const c = make("changed_files", e.row, "edited " + path5 + " x" + e.count, e.count, path5);
18169
+ for (const [path7, e] of edits) {
18170
+ const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
18154
18171
  changedFiles.push({ ...c, editCount: e.count });
18155
18172
  }
18156
18173
  changedFiles.sort((a, b) => a.seq - b.seq);
@@ -19904,19 +19921,19 @@ function readAutoMemory(project) {
19904
19921
  if (project.agent !== "claude-code") return [];
19905
19922
  const rows = [];
19906
19923
  for (const segs of CLAUDE_CODE_MEMORY_FILES) {
19907
- const path5 = join7(project.worktree, ...segs);
19908
- if (!isInside(project.worktree, path5)) continue;
19924
+ const path7 = join7(project.worktree, ...segs);
19925
+ if (!isInside(project.worktree, path7)) continue;
19909
19926
  try {
19910
- const st = statSync4(path5);
19927
+ const st = statSync4(path7);
19911
19928
  if (!st.isFile()) continue;
19912
19929
  rows.push({
19913
19930
  origin: "memory",
19914
19931
  ts: Math.trunc(st.mtimeMs),
19915
19932
  seq: null,
19916
19933
  sourceId: null,
19917
- path: path5,
19934
+ path: path7,
19918
19935
  label: segs.join("/"),
19919
- text: readFileSync5(path5, "utf8")
19936
+ text: readFileSync5(path7, "utf8")
19920
19937
  });
19921
19938
  } catch {
19922
19939
  }
@@ -20032,12 +20049,20 @@ function sourceBytes(db, ids) {
20032
20049
  }
20033
20050
  return out;
20034
20051
  }
20052
+ var LEAN_HITS = 3;
20053
+ function replyHits(hits, size) {
20054
+ if (hits.length === 0 || hits[0].full !== true) return Math.min(size, hits.length);
20055
+ let n = Math.min(LEAN_HITS, size, hits.length);
20056
+ while (n < size && n < hits.length && hits[n].full === true) n++;
20057
+ return n;
20058
+ }
20035
20059
  function relevance(db, given, scope, ctx) {
20036
20060
  const input = { ...given, queries: decisionQueries(given) };
20037
20061
  const offset = input.offset ?? 0;
20038
20062
  const size = pageSize(input);
20039
20063
  const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
20040
- const pages = fetched.map((h) => h.slice(0, size));
20064
+ const take = fetched.map((h) => replyHits(h, size));
20065
+ const pages = fetched.map((h, i) => h.slice(0, take[i]));
20041
20066
  if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
20042
20067
  const moreLine3 = (q, pos) => "More: " + callText([q], scope, input.source, "offset:" + pos);
20043
20068
  let reserve = 0;
@@ -20052,7 +20077,7 @@ function relevance(db, given, scope, ctx) {
20052
20077
  input.queries.forEach((q, qi) => {
20053
20078
  const hits = pages[qi];
20054
20079
  if (stopped) {
20055
- more.push(moreLine3(q, offset));
20080
+ more.push({ q, pos: offset });
20056
20081
  return;
20057
20082
  }
20058
20083
  const head = "Query " + JSON.stringify(q) + ":";
@@ -20090,10 +20115,14 @@ function relevance(db, given, scope, ctx) {
20090
20115
  lines.push(line);
20091
20116
  used += bytes2(line) + 1;
20092
20117
  }
20093
- if (cut >= 0) more.push(moreLine3(q, cut));
20094
- else if (fetched[qi].length > size) more.push(moreLine3(q, offset + size));
20118
+ if (cut >= 0) more.push({ q, pos: cut });
20119
+ else if (fetched[qi].length > take[qi]) more.push({ q, pos: offset + take[qi] });
20095
20120
  });
20096
- return reply(lines.concat(more).join("\n"), false);
20121
+ const moreLines = [];
20122
+ const byPos = /* @__PURE__ */ new Map();
20123
+ for (const m of more) byPos.set(m.pos, [...byPos.get(m.pos) ?? [], m.q]);
20124
+ for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope, input.source, "offset:" + pos));
20125
+ return reply(lines.concat(moreLines).join("\n"), false);
20097
20126
  }
20098
20127
  function timelineLine(r) {
20099
20128
  const nl = r.text.indexOf("\n");
@@ -20233,6 +20262,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
20233
20262
  const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
20234
20263
  const display = shown(chunks, ran.map((r) => r.head));
20235
20264
  const bodies = /* @__PURE__ */ new Map();
20265
+ const raw = /* @__PURE__ */ new Map();
20236
20266
  let total = 0;
20237
20267
  for (const c of chunks) total += c.bytes;
20238
20268
  let indexed = 0;
@@ -20253,7 +20283,10 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
20253
20283
  chunkCount: group.length,
20254
20284
  createdAt: Date.now()
20255
20285
  }, group);
20256
- for (const c of group) bodies.set(chunkKey(id, c.ord), display[c.ord]);
20286
+ for (const c of group) {
20287
+ bodies.set(chunkKey(id, c.ord), display[c.ord]);
20288
+ raw.set(chunkKey(id, c.ord), c.text);
20289
+ }
20257
20290
  indexed += groupBytes;
20258
20291
  group = [];
20259
20292
  groupBytes = 0;
@@ -20262,15 +20295,15 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
20262
20295
  for (const c of chunks) {
20263
20296
  if (queued + c.bytes > budgetBytes) {
20264
20297
  const stop2 = flush() ? "budget" : "deadline";
20265
- return { bodies, indexed, total, stop: stop2 };
20298
+ return { bodies, raw, indexed, total, stop: stop2 };
20266
20299
  }
20267
- if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, indexed, total, stop: "deadline" };
20300
+ if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, indexed, total, stop: "deadline" };
20268
20301
  group.push(c);
20269
20302
  groupBytes += c.bytes;
20270
20303
  queued += c.bytes;
20271
20304
  }
20272
20305
  const stop = flush() ? null : "deadline";
20273
- return { bodies, indexed, total, stop };
20306
+ return { bodies, raw, indexed, total, stop };
20274
20307
  }
20275
20308
  function bytes3(s) {
20276
20309
  return Buffer.byteLength(s, "utf8");
@@ -20303,7 +20336,7 @@ function answer(db, ctx, label, queries, share, own4) {
20303
20336
  else if (body.length === 0) body.push("No new section.");
20304
20337
  lines.push(head, ...body);
20305
20338
  }
20306
- return lines;
20339
+ return { lines, seen };
20307
20340
  }
20308
20341
  async function runBatch(input, ctx, boundMs, budgetBytes) {
20309
20342
  const parsed = ctxBatchSchema.safeParse(input);
@@ -20324,9 +20357,10 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
20324
20357
  const db = await openDb(ctx.project);
20325
20358
  let sections;
20326
20359
  let idx;
20327
- const summary = commands.length + " command(s), " + queries.length + " querie(s), exit " + last2.exitCode;
20360
+ const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
20328
20361
  const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label) + "})";
20329
20362
  let notice;
20363
+ let showMore;
20330
20364
  try {
20331
20365
  idx = indexCombined(db, ctx, label, ran, deadline, budgetBytes);
20332
20366
  const stop = last2.error;
@@ -20334,13 +20368,21 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
20334
20368
  const timeout = formatError2("TIMEOUT", { ms: boundMs });
20335
20369
  const cause = stop ?? (ctx.signal.aborted ? CANCELLED_LINE : idx.stop === "deadline" ? timeout : null);
20336
20370
  notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
20337
- const fixed = bytes3(summary) + 1 + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
20371
+ const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
20338
20372
  const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
20339
- sections = answer(db, ctx, label, queries, share, idx.bodies);
20373
+ const answered = answer(db, ctx, label, queries, share, idx.bodies);
20374
+ sections = answered.lines;
20375
+ const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
20376
+ const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
20377
+ if (unseen.length === 0 && cut === null) showMore = false;
20378
+ else if (cut === null && unseenBytes <= bytes3(footer) + 1) {
20379
+ showMore = false;
20380
+ sections = [...sections, ...unseen.map((t) => t.endsWith(LINE_SEP) ? t.slice(0, -1) : t)];
20381
+ } else showMore = true;
20340
20382
  } finally {
20341
20383
  closeDb(db);
20342
20384
  }
20343
- const lines = [summary, ...notice === null ? [] : [notice], ...sections, footer];
20385
+ const lines = [...exitLine === null ? [] : [exitLine], ...notice === null ? [] : [notice], ...sections, ...showMore ? [footer] : []];
20344
20386
  return {
20345
20387
  text: capBytes(lines.join(LINE_SEP), OUTPUT_CAP).text,
20346
20388
  // step 10: final bound (D-M2-6)
@@ -20364,7 +20406,7 @@ var ctxBatch = Object.freeze({
20364
20406
  });
20365
20407
 
20366
20408
  // src/core/tools/doctor.ts
20367
- import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync11 } from "node:fs";
20409
+ import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync12 } from "node:fs";
20368
20410
  import { basename as basename3, dirname as dirname6, join as join13 } from "node:path";
20369
20411
 
20370
20412
  // src/core/ops/doctor-config.ts
@@ -22487,15 +22529,15 @@ function atomicWriteFile(file2, text, opts = {}) {
22487
22529
  }
22488
22530
 
22489
22531
  // src/core/ops/host-config.ts
22490
- function formatOf(path5) {
22491
- if (path5.endsWith(JSONC_EXT)) return "jsonc";
22492
- if (path5.endsWith(TOML_EXT)) return "toml";
22532
+ function formatOf(path7) {
22533
+ if (path7.endsWith(JSONC_EXT)) return "jsonc";
22534
+ if (path7.endsWith(TOML_EXT)) return "toml";
22493
22535
  return "json";
22494
22536
  }
22495
- function readHostConfig(agent, path5) {
22496
- let file2 = path5;
22537
+ function readHostConfig(agent, path7) {
22538
+ let file2 = path7;
22497
22539
  if (agent === "opencode") {
22498
- const jsonc = join8(dirname4(path5), OPENCODE_CONFIG_FILES[0]);
22540
+ const jsonc = join8(dirname4(path7), OPENCODE_CONFIG_FILES[0]);
22499
22541
  if (existsSync3(jsonc)) file2 = jsonc;
22500
22542
  }
22501
22543
  const raw = existsSync3(file2) ? readFileSync6(file2, "utf8") : "";
@@ -22659,14 +22701,14 @@ function scanToml(text) {
22659
22701
  continue;
22660
22702
  }
22661
22703
  if (!node3.resolvedKey.every((seg) => typeof seg === "string")) continue;
22662
- const path5 = node3.resolvedKey;
22663
- for (const kv of node3.body) addKey(path5, kv);
22704
+ const path7 = node3.resolvedKey;
22705
+ for (const kv of node3.body) addKey(path7, kv);
22664
22706
  if (node3.kind !== "standard") continue;
22665
22707
  const start = lineStartOf(text, node3.range[0]);
22666
22708
  const headEnd = lineEndOf(text, node3.key.range[1]);
22667
22709
  const last2 = node3.body[node3.body.length - 1];
22668
22710
  tables.push({
22669
- path: path5,
22711
+ path: path7,
22670
22712
  header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
22671
22713
  start,
22672
22714
  end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
@@ -22677,16 +22719,16 @@ function scanToml(text) {
22677
22719
  function tomlTableSpans(text) {
22678
22720
  return scanToml(text).tables;
22679
22721
  }
22680
- function parseHostConfig(agent, path5, text, format) {
22722
+ function parseHostConfig(agent, path7, text, format) {
22681
22723
  try {
22682
22724
  return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
22683
22725
  } catch {
22684
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path5, format });
22726
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
22685
22727
  }
22686
22728
  }
22687
- function hostConfigValueAt(value, path5) {
22729
+ function hostConfigValueAt(value, path7) {
22688
22730
  let cur = value;
22689
- for (const seg of path5) {
22731
+ for (const seg of path7) {
22690
22732
  if (!isPlainObject3(cur)) return void 0;
22691
22733
  cur = cur[seg];
22692
22734
  }
@@ -22719,32 +22761,32 @@ function indentUnit(root, clean) {
22719
22761
  function render(value, unit, base) {
22720
22762
  return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
22721
22763
  }
22722
- function nest(path5, value) {
22764
+ function nest(path7, value) {
22723
22765
  let out = value;
22724
- for (let k = path5.length - 1; k >= 0; k -= 1) out = { [path5[k]]: out };
22766
+ for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
22725
22767
  return out;
22726
22768
  }
22727
- function setJsonText(text, format, path5, value) {
22769
+ function setJsonText(text, format, path7, value) {
22728
22770
  const doc = scanJson(text, format);
22729
22771
  const unit = indentUnit(doc.root, doc.clean);
22730
- if (doc.root === null) return render(nest(path5, value), unit, "") + "\n";
22772
+ if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
22731
22773
  let node3 = doc.root;
22732
22774
  let depth = 0;
22733
- while (depth < path5.length && node3.kind === "object") {
22734
- const hit = node3.members.find((m) => m.key === path5[depth]);
22775
+ while (depth < path7.length && node3.kind === "object") {
22776
+ const hit = node3.members.find((m) => m.key === path7[depth]);
22735
22777
  if (hit === void 0) break;
22736
22778
  node3 = hit.node;
22737
22779
  depth += 1;
22738
22780
  }
22739
- if (depth === path5.length) {
22781
+ if (depth === path7.length) {
22740
22782
  return text.slice(0, node3.start) + render(value, unit, lineIndent(doc.clean, node3.start)) + text.slice(node3.end);
22741
22783
  }
22742
- if (node3.kind !== "object") throw new SyntaxError("not an object at " + path5.slice(0, depth).join("."));
22743
- const rest = nest(path5.slice(depth + 1), value);
22784
+ if (node3.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
22785
+ const rest = nest(path7.slice(depth + 1), value);
22744
22786
  const last2 = node3.members[node3.members.length - 1];
22745
22787
  if (last2 === void 0) {
22746
22788
  const base2 = lineIndent(doc.clean, node3.start);
22747
- const member2 = "\n" + base2 + unit + JSON.stringify(path5[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
22789
+ const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
22748
22790
  return text.slice(0, node3.start + 1) + member2 + text.slice(node3.end - 1);
22749
22791
  }
22750
22792
  const base = lineIndent(doc.clean, last2.keyStart);
@@ -22752,7 +22794,7 @@ function setJsonText(text, format, path5, value) {
22752
22794
  while (" \r\n".includes(doc.clean[at2])) at2 += 1;
22753
22795
  const trailing = doc.clean[at2] === ",";
22754
22796
  const insertAt = trailing ? at2 + 1 : last2.node.end;
22755
- const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path5[depth]) + ": " + render(rest, unit, base);
22797
+ const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
22756
22798
  return text.slice(0, insertAt) + member + text.slice(insertAt);
22757
22799
  }
22758
22800
  function tomlScalar(v) {
@@ -22770,17 +22812,17 @@ function tomlHeaderKey(seg) {
22770
22812
  }
22771
22813
  return seg;
22772
22814
  }
22773
- function tomlBlock(path5, value) {
22774
- let out = "[" + path5.map(tomlHeaderKey).join(".") + "]\n";
22815
+ function tomlBlock(path7, value) {
22816
+ let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
22775
22817
  const subs = [];
22776
22818
  for (const [k, v] of Object.entries(value)) {
22777
- if (isPlainObject3(v)) subs.push(tomlBlock([...path5, k], v));
22819
+ if (isPlainObject3(v)) subs.push(tomlBlock([...path7, k], v));
22778
22820
  else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
22779
22821
  }
22780
22822
  return [out, ...subs].join("\n");
22781
22823
  }
22782
- function under(path5, prefix) {
22783
- return path5.length >= prefix.length && prefix.every((seg, k) => path5[k] === seg);
22824
+ function under(path7, prefix) {
22825
+ return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
22784
22826
  }
22785
22827
  function keyLineRange(text, k) {
22786
22828
  const ls = lineStartOf(text, k.start);
@@ -22797,10 +22839,10 @@ function withValueAt(root, rel, value) {
22797
22839
  else base[rel[0]] = next;
22798
22840
  return base;
22799
22841
  }
22800
- function replaceToml(text, doc, path5, value) {
22801
- const block = value === void 0 ? "" : tomlBlock(path5, value);
22802
- const owned = doc.tables.filter((t) => under(t.path, path5));
22803
- const cuts = doc.keys.filter((k) => under(k.full, path5) && !under(k.base, path5)).map((k) => [...keyLineRange(text, k), ""]);
22842
+ function replaceToml(text, doc, path7, value) {
22843
+ const block = value === void 0 ? "" : tomlBlock(path7, value);
22844
+ const owned = doc.tables.filter((t) => under(t.path, path7));
22845
+ const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
22804
22846
  owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
22805
22847
  cuts.sort((a, b) => b[0] - a[0]);
22806
22848
  let out = text;
@@ -22810,27 +22852,27 @@ function replaceToml(text, doc, path5, value) {
22810
22852
  return out + sep4 + block;
22811
22853
  }
22812
22854
  var tableLike = (v) => v === void 0 || isPlainObject3(v);
22813
- function setTomlText(text, path5, value) {
22855
+ function setTomlText(text, path7, value) {
22814
22856
  if (value !== void 0 && !isPlainObject3(value)) throw new SyntaxError("TOML edits replace a whole table");
22815
22857
  const doc = scanToml(text);
22816
- const cur = hostConfigValueAt(doc.value, path5);
22858
+ const cur = hostConfigValueAt(doc.value, path7);
22817
22859
  if (sameValue(cur, value)) return text;
22818
- const inline = doc.keys.find((k) => k.inline && k.full.length < path5.length && under(path5, k.full));
22860
+ const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
22819
22861
  if (inline !== void 0) {
22820
- const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path5.slice(inline.full.length), value);
22862
+ const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
22821
22863
  return replaceToml(text, doc, inline.full, whole);
22822
22864
  }
22823
22865
  if (isPlainObject3(cur) && isPlainObject3(value)) {
22824
22866
  const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
22825
22867
  if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
22826
22868
  let out = text;
22827
- for (const k of names) out = setTomlText(out, [...path5, k], value[k]);
22869
+ for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
22828
22870
  return out;
22829
22871
  }
22830
22872
  }
22831
- return replaceToml(text, doc, path5, value);
22873
+ return replaceToml(text, doc, path7, value);
22832
22874
  }
22833
- function setText(agent, path5, text, format, key, value) {
22875
+ function setText(agent, path7, text, format, key, value) {
22834
22876
  try {
22835
22877
  if (format !== "toml") return setJsonText(text, format, key, value);
22836
22878
  const out = setTomlText(text, key, value);
@@ -22839,7 +22881,7 @@ function setText(agent, path5, text, format, key, value) {
22839
22881
  if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
22840
22882
  return out;
22841
22883
  } catch {
22842
- throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path5, format });
22884
+ throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
22843
22885
  }
22844
22886
  }
22845
22887
  function serverScript() {
@@ -22886,14 +22928,14 @@ function ownTargets(agent, accept) {
22886
22928
  if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
22887
22929
  return [];
22888
22930
  }
22889
- function applyEdits(agent, path5, text, format, wanted) {
22890
- const parsed = parseHostConfig(agent, path5, text, format);
22931
+ function applyEdits(agent, path7, text, format, wanted) {
22932
+ const parsed = parseHostConfig(agent, path7, text, format);
22891
22933
  let out = text;
22892
22934
  const edits = [];
22893
22935
  for (const [key, after] of wanted) {
22894
22936
  const before = hostConfigValueAt(parsed, key);
22895
22937
  if (sameValue(before, after)) continue;
22896
- out = setText(agent, path5, out, format, key, after);
22938
+ out = setText(agent, path7, out, format, key, after);
22897
22939
  edits.push({ path: key.join("."), before, after });
22898
22940
  }
22899
22941
  return { text: out, format, edits };
@@ -22914,7 +22956,7 @@ function writeHostConfigEdit(_requested, current, patch) {
22914
22956
  // src/core/ops/detect-v1.ts
22915
22957
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
22916
22958
  var keyPath = (...parts) => parts.join(".");
22917
- var finding = (file2, path5, reason) => ({ file: file2, path: path5, reason });
22959
+ var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
22918
22960
  function stripJsonc(text) {
22919
22961
  let out = "";
22920
22962
  let inStr = false;
@@ -23221,8 +23263,8 @@ function detectV1(agent, home, scope = {}) {
23221
23263
  import { existsSync as existsSync5, readdirSync as readdirSync2, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23222
23264
  import { dirname as dirname5, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
23223
23265
  import { fileURLToPath } from "node:url";
23224
- function missing(agent, path5) {
23225
- return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path5 });
23266
+ function missing(agent, path7) {
23267
+ return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
23226
23268
  }
23227
23269
  function recordedInstallPaths(text) {
23228
23270
  let parsed;
@@ -23246,9 +23288,9 @@ function recordedInstallPaths(text) {
23246
23288
  }
23247
23289
  return out;
23248
23290
  }
23249
- var realOrNull = (path5) => {
23291
+ var realOrNull = (path7) => {
23250
23292
  try {
23251
- return realpathSync4.native(path5);
23293
+ return realpathSync4.native(path7);
23252
23294
  } catch {
23253
23295
  return null;
23254
23296
  }
@@ -23310,11 +23352,11 @@ function candidate(adapter, env) {
23310
23352
  }
23311
23353
  }
23312
23354
  function resolvePluginRoot(adapter, env) {
23313
- const path5 = candidate(adapter, env);
23355
+ const path7 = candidate(adapter, env);
23314
23356
  try {
23315
- return realpathSync4.native(path5);
23357
+ return realpathSync4.native(path7);
23316
23358
  } catch {
23317
- throw missing(adapter.id, path5);
23359
+ throw missing(adapter.id, path7);
23318
23360
  }
23319
23361
  }
23320
23362
 
@@ -23545,8 +23587,8 @@ async function loadSqlite2() {
23545
23587
  return null;
23546
23588
  }
23547
23589
  }
23548
- function openRead(sqlite, path5) {
23549
- return new sqlite.DatabaseSync(path5, { timeout: DB_TIMEOUT_MS, readOnly: true });
23590
+ function openRead(sqlite, path7) {
23591
+ return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
23550
23592
  }
23551
23593
  var cell = (row5) => Object.values(row5)[0];
23552
23594
  function readSchema(raw) {
@@ -23688,17 +23730,200 @@ function checkShell(env) {
23688
23730
  }
23689
23731
 
23690
23732
  // src/core/ops/doctor-hook.ts
23691
- import { existsSync as existsSync9, readFileSync as readFileSync9 } from "node:fs";
23733
+ import { existsSync as existsSync10, readFileSync as readFileSync9 } from "node:fs";
23734
+ import path6 from "node:path";
23735
+
23736
+ // src/setup/codex-trust.ts
23737
+ import { createHash } from "node:crypto";
23738
+ import { existsSync as existsSync9, realpathSync as realpathSync6 } from "node:fs";
23739
+ import path5 from "node:path";
23740
+ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
23741
+
23742
+ // src/setup/spawn-bin.ts
23743
+ import { spawnSync } from "node:child_process";
23744
+ import { accessSync as accessSync2, constants as fsc, statSync as statSync5 } from "node:fs";
23692
23745
  import path4 from "node:path";
23746
+ var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
23747
+ var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
23748
+ var DEFAULT_COMSPEC = "cmd.exe";
23749
+ function envGet(env, k) {
23750
+ return env[Object.keys(env).find((x) => x.toUpperCase() === k) ?? k];
23751
+ }
23752
+ function whichBin(bin, env, platform = process.platform) {
23753
+ const get = (k) => envGet(env, k);
23754
+ const win = platform === "win32";
23755
+ const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
23756
+ const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
23757
+ for (const dir of pathEntries(get("PATH") ?? "", platform)) {
23758
+ for (const n of names) {
23759
+ const f = path4.join(dir, n);
23760
+ try {
23761
+ accessSync2(f, fsc.X_OK);
23762
+ if (statSync5(f).isFile()) return f;
23763
+ } catch {
23764
+ }
23765
+ }
23766
+ }
23767
+ return void 0;
23768
+ }
23769
+ var CMD_QUOTE_CHARS = '"&|<>^()!';
23770
+ var CMD_PERCENT = "%";
23771
+ var CMD_SUBSTRING_MARK = ":";
23772
+ var CMD_DYNAMIC_VARS = Object.freeze(["CD", "DATE", "TIME", "RANDOM", "ERRORLEVEL", "CMDEXTVERSION", "CMDCMDLINE", "HIGHESTNUMANODENUMBER"]);
23773
+ function needsCmdQuotes(a) {
23774
+ if (a === "") return true;
23775
+ for (const c of a) if (c.trim() === "" || CMD_QUOTE_CHARS.includes(c)) return true;
23776
+ return false;
23777
+ }
23778
+ function expandablePercent(text, env) {
23779
+ const names = new Set(CMD_DYNAMIC_VARS);
23780
+ for (const k of Object.keys(env)) names.add(k.toUpperCase());
23781
+ for (let i = text.indexOf(CMD_PERCENT); i >= 0; i = text.indexOf(CMD_PERCENT, i + 1)) {
23782
+ for (let j = text.indexOf(CMD_PERCENT, i + 1); j >= 0; j = text.indexOf(CMD_PERCENT, j + 1)) {
23783
+ const inner = text.slice(i + 1, j);
23784
+ const cut = inner.indexOf(CMD_SUBSTRING_MARK);
23785
+ const name = cut < 0 ? inner : inner.slice(0, cut);
23786
+ if (name !== "" && names.has(name.toUpperCase())) return `${CMD_PERCENT}${inner}${CMD_PERCENT}`;
23787
+ }
23788
+ }
23789
+ return void 0;
23790
+ }
23791
+ function winCmdLine(file2, args, env = {}) {
23792
+ for (const a of [file2, ...args]) {
23793
+ const hit = expandablePercent(a, env);
23794
+ 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`);
23795
+ }
23796
+ const q = (a) => needsCmdQuotes(a) ? `"${a.split('"').join('""')}"` : a;
23797
+ return `"${[file2, ...args].map(q).join(" ")}"`;
23798
+ }
23799
+ function spawnForm(file2, args, env, platform = process.platform) {
23800
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
23801
+ return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
23802
+ }
23803
+ return { command: file2, args, windowsVerbatimArguments: false };
23804
+ }
23805
+
23806
+ // src/setup/codex-trust.ts
23807
+ var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23808
+ var TRUST_KEY = ["hooks", "state"];
23809
+ var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
23810
+ var LIST_TIMEOUT_MS = 15e3;
23811
+ var EXIT_GRACE_MS = 5e3;
23812
+ var PLUGIN_SOURCE = "plugin";
23813
+ var TRUSTED = "trusted";
23814
+ function pluginHooksFromReply(m, pluginId) {
23815
+ const out = [];
23816
+ if (!isObj2(m) || !isObj2(m.result) || !Array.isArray(m.result.data)) return out;
23817
+ for (const d of m.result.data) {
23818
+ if (!isObj2(d) || !Array.isArray(d.hooks)) continue;
23819
+ for (const h of d.hooks) {
23820
+ if (!isObj2(h) || h.source !== PLUGIN_SOURCE || h.pluginId !== pluginId) continue;
23821
+ if (typeof h.key !== "string" || typeof h.currentHash !== "string") continue;
23822
+ if (out.some((x) => x.key === h.key)) continue;
23823
+ out.push({ key: h.key, hash: h.currentHash, trusted: h.trustStatus === TRUSTED });
23824
+ }
23825
+ }
23826
+ return out;
23827
+ }
23828
+ function listPluginHooks(env, pluginId, cwd) {
23829
+ const bin = whichBin("codex", env);
23830
+ if (!bin) return Promise.resolve(void 0);
23831
+ return new Promise((resolve7) => {
23832
+ let f;
23833
+ try {
23834
+ f = spawnForm(bin, ["app-server"], env);
23835
+ } catch {
23836
+ resolve7(void 0);
23837
+ return;
23838
+ }
23839
+ const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
23840
+ let buf = "";
23841
+ let done = false;
23842
+ let exited = false;
23843
+ let result;
23844
+ const settle3 = () => {
23845
+ clearTimeout(grace);
23846
+ resolve7(result);
23847
+ };
23848
+ let grace;
23849
+ const finish2 = (v) => {
23850
+ if (done) return;
23851
+ done = true;
23852
+ clearTimeout(timer);
23853
+ result = v;
23854
+ child.stdin.destroy();
23855
+ if (exited) {
23856
+ settle3();
23857
+ return;
23858
+ }
23859
+ grace = setTimeout(settle3, EXIT_GRACE_MS);
23860
+ stopTree(child.pid, () => child.kill());
23861
+ };
23862
+ const timer = setTimeout(() => finish2(void 0), LIST_TIMEOUT_MS);
23863
+ const send = (o) => {
23864
+ try {
23865
+ child.stdin.write(JSON.stringify(o) + "\n");
23866
+ } catch {
23867
+ finish2(void 0);
23868
+ }
23869
+ };
23870
+ child.on("error", () => finish2(void 0));
23871
+ child.on("close", () => {
23872
+ exited = true;
23873
+ if (done) settle3();
23874
+ else finish2(void 0);
23875
+ });
23876
+ child.stdin.on("error", () => finish2(void 0));
23877
+ child.stdout.setEncoding("utf8");
23878
+ child.stdout.on("data", (d) => {
23879
+ buf += d;
23880
+ const lines = buf.split("\n");
23881
+ buf = lines.pop() ?? "";
23882
+ for (const line of lines) {
23883
+ let m;
23884
+ try {
23885
+ m = JSON.parse(line);
23886
+ } catch {
23887
+ continue;
23888
+ }
23889
+ if (!isObj2(m)) continue;
23890
+ if (m.id === 1) {
23891
+ send({ method: "initialized" });
23892
+ send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
23893
+ } else if (m.id === 2) finish2(pluginHooksFromReply(m, pluginId));
23894
+ }
23895
+ });
23896
+ send({ id: 1, method: "initialize", params: { clientInfo: { name: "context-mode-setup", version: "2.0.0" } } });
23897
+ });
23898
+ }
23899
+ function stopTree(pid, kill) {
23900
+ if (process.platform === "win32" && pid !== void 0) {
23901
+ try {
23902
+ spawnSync2("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
23903
+ } catch {
23904
+ }
23905
+ }
23906
+ kill();
23907
+ }
23908
+ var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
23909
+ var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
23910
+ function untrustedPluginHooksDetail(hooks) {
23911
+ const bad = hooks.filter((h) => !h.trusted);
23912
+ if (!bad.length) return void 0;
23913
+ return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
23914
+ }
23915
+
23916
+ // src/core/ops/doctor-hook.ts
23693
23917
  var D5_MIN_PAIRS = 3;
23694
23918
  var D5_MAX_PAIRS = 9;
23919
+ var D5_CODEX_TRUST_FIX = "context-mode setup --agents codex";
23695
23920
  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 };
23696
23921
  function isObject5(v) {
23697
23922
  return typeof v === "object" && v !== null && !Array.isArray(v);
23698
23923
  }
23699
23924
  function loadFixture(bundleDir2, agent) {
23700
- const file2 = path4.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
23701
- if (!existsSync9(file2)) return null;
23925
+ const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
23926
+ if (!existsSync10(file2)) return null;
23702
23927
  let all;
23703
23928
  try {
23704
23929
  all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
@@ -23729,7 +23954,12 @@ function codexHookJournaled(db) {
23729
23954
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
23730
23955
  }
23731
23956
  async function checkHookRoundTrip(i) {
23732
- if (i.agent === "codex" && existsSync9(path4.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
23957
+ if (i.agent === "codex") {
23958
+ const hooks = await listPluginHooks(i.env, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
23959
+ const detail = hooks === void 0 ? void 0 : untrustedPluginHooksDetail(hooks);
23960
+ if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
23961
+ }
23962
+ if (i.agent === "codex" && existsSync10(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
23733
23963
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
23734
23964
  }
23735
23965
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -23748,7 +23978,7 @@ async function checkHookRoundTrip(i) {
23748
23978
  let ms = 0;
23749
23979
  for (let n = 1; n <= maxPairs; n++) {
23750
23980
  const start = now();
23751
- const r = await runProcess([process.execPath, path4.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
23981
+ const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
23752
23982
  cwd: i.bundleDir,
23753
23983
  env: i.env,
23754
23984
  signal: i.signal,
@@ -23766,7 +23996,7 @@ async function checkHookRoundTrip(i) {
23766
23996
  }
23767
23997
 
23768
23998
  // src/core/ops/db-heal.ts
23769
- import { existsSync as existsSync10, rmSync as rmSync3 } from "node:fs";
23999
+ import { existsSync as existsSync11, rmSync as rmSync3 } from "node:fs";
23770
24000
 
23771
24001
  // src/core/store/owners.ts
23772
24002
  import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
@@ -23859,7 +24089,7 @@ function renameAside(dbPath) {
23859
24089
  const ts = String(Date.now());
23860
24090
  for (const suffix of DB_SIBLING_SUFFIXES) {
23861
24091
  const file2 = dbPath + suffix;
23862
- if (existsSync10(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
24092
+ if (existsSync11(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
23863
24093
  }
23864
24094
  return ts;
23865
24095
  }
@@ -23940,7 +24170,7 @@ async function guard(id, run) {
23940
24170
  }
23941
24171
  }
23942
24172
  async function codexDb(ctx, adapter) {
23943
- if (adapter.id !== "codex" || !existsSync11(ctx.project.dbPath)) return null;
24173
+ if (adapter.id !== "codex" || !existsSync12(ctx.project.dbPath)) return null;
23944
24174
  try {
23945
24175
  return await openDb(ctx.project, { readOnly: true });
23946
24176
  } catch {
@@ -23971,7 +24201,7 @@ async function hookRow(ctx, adapter, host) {
23971
24201
  }
23972
24202
  function ownServerId(configDir, projectKey) {
23973
24203
  const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
23974
- if (!existsSync11(dir)) return "";
24204
+ if (!existsSync12(dir)) return "";
23975
24205
  for (const name of readdirSync5(dir)) {
23976
24206
  if (!name.endsWith(OWNER_PID_EXT)) continue;
23977
24207
  if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
@@ -24046,7 +24276,7 @@ var ctxDoctor = Object.freeze({
24046
24276
  });
24047
24277
 
24048
24278
  // src/core/tools/execute.ts
24049
- import { existsSync as existsSync12, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
24279
+ import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
24050
24280
  import { tmpdir as tmpdir2 } from "node:os";
24051
24281
  import { dirname as dirname7, join as join14, parse as parse3, resolve as resolve5 } from "node:path";
24052
24282
 
@@ -24132,7 +24362,7 @@ function schemaLine(issue4) {
24132
24362
  }
24133
24363
  function fileError(given, abs, root) {
24134
24364
  let dir = abs;
24135
- while (!existsSync12(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
24365
+ while (!existsSync13(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
24136
24366
  if (isInside(root, dir)) return null;
24137
24367
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
24138
24368
  }
@@ -24170,12 +24400,14 @@ async function finish(input, ctx, r, exitCode, journal) {
24170
24400
  const fullBytes = Buffer.byteLength(combined, "utf8");
24171
24401
  const head = summaryLine(exitCode, fullBytes);
24172
24402
  const intent = input.intent ?? "";
24173
- const direct = head + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
24174
- if (intent === "" && Buffer.byteLength(direct, "utf8") <= OUTPUT_CAP) {
24403
+ const bare2 = exitCode === 0 && input.summary !== true && combined !== "";
24404
+ const direct = (bare2 ? "" : head + "\n") + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
24405
+ const fits = Buffer.byteLength(head + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined, "utf8") <= OUTPUT_CAP;
24406
+ if (intent === "" && fits) {
24175
24407
  return { text: direct, isError, sandboxBytes: fullBytes, journal };
24176
24408
  }
24177
24409
  const label = sourceLabel(input.code);
24178
- const budget = OUTPUT_CAP - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
24410
+ const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
24179
24411
  const db = await openDb(ctx.project);
24180
24412
  let picked;
24181
24413
  try {
@@ -24247,16 +24479,16 @@ var ctxExecute = {
24247
24479
  };
24248
24480
 
24249
24481
  // src/core/tools/index.ts
24250
- import { existsSync as existsSync13, readFileSync as readFileSync13, statSync as statSync6 } from "node:fs";
24482
+ import { existsSync as existsSync14, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
24251
24483
  import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as resolve6 } from "node:path";
24252
24484
 
24253
24485
  // src/core/index/walk.ts
24254
- import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync6, statSync as statSync5 } from "node:fs";
24486
+ import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync7, statSync as statSync6 } from "node:fs";
24255
24487
  import { join as join15 } from "node:path";
24256
24488
  var GITIGNORE = ".gitignore";
24257
24489
  var GIT_DIR = ".git";
24258
24490
  function walkDir(root, containmentRoot) {
24259
- const real2 = realpathSync6(root);
24491
+ const real2 = realpathSync7(root);
24260
24492
  if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
24261
24493
  const found = [];
24262
24494
  visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
@@ -24273,19 +24505,19 @@ function visit(abs, rel, parent, contain, seen, found) {
24273
24505
  const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join15(abs, GITIGNORE), rel)) : parent;
24274
24506
  for (const e of entries) {
24275
24507
  if (e.name === GIT_DIR) continue;
24276
- const path5 = join15(abs, e.name);
24508
+ const path7 = join15(abs, e.name);
24277
24509
  let isDir = e.isDirectory();
24278
24510
  let isFile = e.isFile();
24279
- let target = path5;
24511
+ let target = path7;
24280
24512
  if (e.isSymbolicLink()) {
24281
24513
  let resolved;
24282
24514
  try {
24283
- resolved = realpathSync6(path5);
24515
+ resolved = realpathSync7(path7);
24284
24516
  } catch {
24285
24517
  continue;
24286
24518
  }
24287
24519
  if (!isInside(contain, resolved)) continue;
24288
- const st = statSync5(resolved);
24520
+ const st = statSync6(resolved);
24289
24521
  isDir = st.isDirectory();
24290
24522
  isFile = st.isFile();
24291
24523
  target = resolved;
@@ -24293,12 +24525,12 @@ function visit(abs, rel, parent, contain, seen, found) {
24293
24525
  const segs = rel.concat(e.name);
24294
24526
  if (ignored(rules, segs, isDir)) continue;
24295
24527
  if (isFile) {
24296
- found.push({ dir: rel, name: e.name, absPath: path5 });
24528
+ found.push({ dir: rel, name: e.name, absPath: path7 });
24297
24529
  } else if (isDir) {
24298
- const key = e.isSymbolicLink() ? target : realpathSync6(path5);
24530
+ const key = e.isSymbolicLink() ? target : realpathSync7(path7);
24299
24531
  if (seen.has(key)) continue;
24300
24532
  seen.add(key);
24301
- visit(path5, segs, rules, contain, seen, found);
24533
+ visit(path7, segs, rules, contain, seen, found);
24302
24534
  }
24303
24535
  }
24304
24536
  }
@@ -24489,12 +24721,12 @@ function tlsName(host) {
24489
24721
  function request(u, conn, proxy, signal) {
24490
24722
  const host = bare(u.hostname);
24491
24723
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
24492
- const path5 = u.pathname + u.search;
24724
+ const path7 = u.pathname + u.search;
24493
24725
  return new Promise((resolve7, reject) => {
24494
24726
  const onErr = (err) => reject(fail6(causeCode(err)));
24495
24727
  if (proxy === void 0) {
24496
24728
  const mod = u.protocol === "https:" ? https : http;
24497
- const req = mod.request({ host: conn.address, port, path: path5, signal, servername: tlsName(host), headers: { host: u.host } });
24729
+ const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
24498
24730
  req.on("response", resolve7).on("error", onErr).end();
24499
24731
  return;
24500
24732
  }
@@ -24516,7 +24748,7 @@ function request(u, conn, proxy, signal) {
24516
24748
  const req = https.request({
24517
24749
  host,
24518
24750
  port,
24519
- path: path5,
24751
+ path: path7,
24520
24752
  signal,
24521
24753
  headers: { host: u.host },
24522
24754
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
@@ -28403,7 +28635,7 @@ function readUtf8(absPath) {
28403
28635
  }
28404
28636
  function missingOrOutside(given, abs, root) {
28405
28637
  let dir = abs;
28406
- while (!existsSync13(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
28638
+ while (!existsSync14(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
28407
28639
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
28408
28640
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
28409
28641
  }
@@ -28411,15 +28643,15 @@ function pathItems(input, project) {
28411
28643
  const abs = resolve6(project.worktree, input.path);
28412
28644
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
28413
28645
  const base = relative3(project.worktree, abs);
28414
- if (statSync6(abs).isDirectory()) {
28646
+ if (statSync7(abs).isDirectory()) {
28415
28647
  return walkDir(abs, project.containmentRoot).map((f) => ({
28416
28648
  sourceKind: "path",
28417
- label: join16(base, f.relPath),
28649
+ label: pathLabel(join16(base, f.relPath)),
28418
28650
  kind: kindOfPath(f.relPath),
28419
28651
  read: () => readUtf8(f.absPath)
28420
28652
  }));
28421
28653
  }
28422
- return [{ sourceKind: "path", label: base === "" ? input.path : base, kind: kindOfPath(abs), read: () => readUtf8(abs) }];
28654
+ return [{ sourceKind: "path", label: pathLabel(base === "" ? input.path : base), kind: kindOfPath(abs), read: () => readUtf8(abs) }];
28423
28655
  }
28424
28656
  async function itemsOf(input, ctx) {
28425
28657
  if (input.content !== void 0) {
@@ -28430,7 +28662,7 @@ async function itemsOf(input, ctx) {
28430
28662
  }
28431
28663
  if (input.path !== void 0) {
28432
28664
  const items = pathItems({ ...input, path: input.path }, ctx.project);
28433
- return { items, from: items.length === 1 ? items[0].label : input.path };
28665
+ return { items, from: items.length === 1 ? items[0].label : pathLabel(input.path) };
28434
28666
  }
28435
28667
  const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
28436
28668
  const text = res.body.toString("utf8");
@@ -28527,10 +28759,11 @@ function scopesOf(input) {
28527
28759
  function changes(raw, sql, ...args) {
28528
28760
  return Number(raw.prepare(sql).run(...args).changes);
28529
28761
  }
28530
- function purgeScope(raw, scope, input) {
28762
+ function purgeScope(db, scope, input) {
28763
+ const raw = db.raw;
28531
28764
  if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
28532
28765
  if (scope === "source") {
28533
- const label = input.source;
28766
+ const label = storedLabel(db, input.source);
28534
28767
  return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?", label);
28535
28768
  }
28536
28769
  const chunks = deleteChunkRows(raw, "all");
@@ -28548,7 +28781,7 @@ async function handler5(input, ctx) {
28548
28781
  try {
28549
28782
  const db = await openDb(ctx.project);
28550
28783
  try {
28551
- const rows = withWrite(db, (h) => purgeScope(h.raw, scope, input));
28784
+ const rows = withWrite(db, (h) => purgeScope(h, scope, input));
28552
28785
  return reply2(PURGE_SUMMARY(rows, scope), false);
28553
28786
  } finally {
28554
28787
  closeDb(db);
@@ -28670,11 +28903,11 @@ var ctxStats = Object.freeze({
28670
28903
  });
28671
28904
 
28672
28905
  // src/core/tools/upgrade.ts
28673
- import { existsSync as existsSync19, realpathSync as realpathSync7, rmSync as rmSync9 } from "node:fs";
28906
+ import { existsSync as existsSync20, realpathSync as realpathSync8, rmSync as rmSync9 } from "node:fs";
28674
28907
  import { basename as basename5, dirname as dirname10, join as join22 } from "node:path";
28675
28908
 
28676
28909
  // src/core/ops/host-write.ts
28677
- import { copyFileSync, existsSync as existsSync14, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
28910
+ import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
28678
28911
  import { dirname as dirname9, join as join17 } from "node:path";
28679
28912
  function defaultWrite(file2, text) {
28680
28913
  writeFileSync4(file2, text, "utf8");
@@ -28703,7 +28936,7 @@ function toRow(file2, edit) {
28703
28936
  function writeWithRollback(file2, text, write2, atomic) {
28704
28937
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
28705
28938
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
28706
- const had = existsSync14(file2);
28939
+ const had = existsSync15(file2);
28707
28940
  mkdirSync5(dirname9(file2), { recursive: true });
28708
28941
  if (had) copyFileSync(file2, trash);
28709
28942
  try {
@@ -28733,7 +28966,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
28733
28966
  if (requested === null) return [];
28734
28967
  const current = readHostConfig(row5.id, requested);
28735
28968
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
28736
- const exists = existsSync14(current.path);
28969
+ const exists = existsSync15(current.path);
28737
28970
  if (exists && result.text === current.text) return [];
28738
28971
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
28739
28972
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -28741,15 +28974,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
28741
28974
  }
28742
28975
 
28743
28976
  // src/core/ops/plugin-swap.ts
28744
- import { existsSync as existsSync15, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
28977
+ import { existsSync as existsSync16, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
28745
28978
  import { basename as basename4, join as join18, win32 as win322 } from "node:path";
28746
- function linkTarget(path5, win) {
28747
- if (!isLink(path5)) return null;
28748
- const target = readlinkSync(path5);
28979
+ function linkTarget(path7, win) {
28980
+ if (!isLink(path7)) return null;
28981
+ const target = readlinkSync(path7);
28749
28982
  return win ? win322.basename(target) : target;
28750
28983
  }
28751
- function isLink(path5) {
28752
- return lstatSync(path5, { throwIfNoEntry: false })?.isSymbolicLink() === true;
28984
+ function isLink(path7) {
28985
+ return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
28753
28986
  }
28754
28987
  function generations(agentDir) {
28755
28988
  return readdirSync7(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();
@@ -28762,7 +28995,7 @@ function settleLinks(link, tmp, old, opts) {
28762
28995
  }
28763
28996
  function swapPluginCurrent(agentDir, sha, opts = {}) {
28764
28997
  const next = join18(agentDir, sha);
28765
- if (!existsSync15(next) || !lstatSync(next).isDirectory()) {
28998
+ if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
28766
28999
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
28767
29000
  }
28768
29001
  const link = join18(agentDir, PLUGIN_CURRENT_LINK);
@@ -28782,12 +29015,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
28782
29015
  if (before !== null) keep.add(before);
28783
29016
  const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
28784
29017
  for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
28785
- const previous = before !== null && existsSync15(join18(agentDir, before)) ? join18(agentDir, before) : null;
29018
+ const previous = before !== null && existsSync16(join18(agentDir, before)) ? join18(agentDir, before) : null;
28786
29019
  return { current: next, previous, removed };
28787
29020
  }
28788
29021
 
28789
29022
  // src/core/ops/release-fetch.ts
28790
- import { existsSync as existsSync16, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
29023
+ import { existsSync as existsSync17, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
28791
29024
  import { join as join19 } from "node:path";
28792
29025
  function failed(r) {
28793
29026
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -28811,7 +29044,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
28811
29044
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
28812
29045
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
28813
29046
  const dir = join19(agentDir, sha);
28814
- if (existsSync16(dir)) rmSync6(fetchDir, { recursive: true, force: true });
29047
+ if (existsSync17(dir)) rmSync6(fetchDir, { recursive: true, force: true });
28815
29048
  else renameWithRetry(fetchDir, dir, opts);
28816
29049
  return { sha, dir };
28817
29050
  } catch (e) {
@@ -28821,7 +29054,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
28821
29054
  }
28822
29055
 
28823
29056
  // src/core/ops/uninstall.ts
28824
- import { existsSync as existsSync17, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
29057
+ import { existsSync as existsSync18, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
28825
29058
  import { join as join20 } from "node:path";
28826
29059
  function row2(area, before, after) {
28827
29060
  return { area, before, after };
@@ -28851,7 +29084,7 @@ function removeCache(adapter, env, configDir) {
28851
29084
  }
28852
29085
  case "plugin": {
28853
29086
  const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
28854
- if (!existsSync17(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
29087
+ if (!existsSync18(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
28855
29088
  rmSync7(agentDir, { recursive: true, force: true });
28856
29089
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
28857
29090
  }
@@ -28864,11 +29097,11 @@ function removeCache(adapter, env, configDir) {
28864
29097
  }
28865
29098
  }
28866
29099
  }
28867
- function isObj2(v) {
29100
+ function isObj3(v) {
28868
29101
  return typeof v === "object" && v !== null && !Array.isArray(v);
28869
29102
  }
28870
29103
  function piSource(entry) {
28871
- return isObj2(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
29104
+ return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
28872
29105
  }
28873
29106
  function ownEntries(agent, env) {
28874
29107
  const home = requireHomeDir(env);
@@ -28877,11 +29110,11 @@ function ownEntries(agent, env) {
28877
29110
  const top = mcp.key[0];
28878
29111
  const inner = mcp.key.slice(1, -1);
28879
29112
  const own4 = mcp.key[mcp.key.length - 1];
28880
- const holder = (v) => inner.reduce((cur, k) => isObj2(cur) ? cur[k] : void 0, v);
28881
- const without = (v, path5) => {
29113
+ const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
29114
+ const without = (v, path7) => {
28882
29115
  const o = v;
28883
- if (path5.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
28884
- return { ...o, [path5[0]]: without(o[path5[0]], path5.slice(1)) };
29116
+ if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
29117
+ return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
28885
29118
  };
28886
29119
  return [{
28887
29120
  file: ownMcpFileOf(agent, mcp.file, env, home),
@@ -28889,7 +29122,7 @@ function ownEntries(agent, env) {
28889
29122
  shown: mcp.key.join(V1_KEY_PATH_SEP),
28890
29123
  has: (v) => {
28891
29124
  const h = holder(v);
28892
- return isObj2(h) && Object.hasOwn(h, own4);
29125
+ return isObj3(h) && Object.hasOwn(h, own4);
28893
29126
  },
28894
29127
  drop: (v) => without(v, inner)
28895
29128
  }];
@@ -28931,7 +29164,7 @@ function removeOwnEntries(agent, env) {
28931
29164
  function removeProjectData(configDir, projectKey) {
28932
29165
  const projects = join20(configDir, PROJECTS_DIR_NAME);
28933
29166
  const dir = join20(projects, projectKey);
28934
- if (!existsSync17(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
29167
+ if (!existsSync18(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
28935
29168
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
28936
29169
  for (const name of readdirSync8(dir)) {
28937
29170
  if (name !== OWNERS_DIR_NAME) rmSync7(join20(dir, name), { recursive: true, force: true });
@@ -28947,8 +29180,8 @@ function runUninstall(input) {
28947
29180
  }
28948
29181
 
28949
29182
  // src/core/ops/v1-remove.ts
28950
- import { copyFileSync as copyFileSync2, existsSync as existsSync18, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
28951
- var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
29183
+ import { copyFileSync as copyFileSync2, existsSync as existsSync19, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
29184
+ var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
28952
29185
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
28953
29186
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
28954
29187
  function moveAside(target, undo) {
@@ -28977,17 +29210,17 @@ function cutTomlTable(text, header) {
28977
29210
  function writeAtomic(file2, text) {
28978
29211
  atomicWriteFile(file2, text);
28979
29212
  }
28980
- function locate(doc, path5) {
28981
- const segs = path5.split(V1_KEY_PATH_SEP);
29213
+ function locate(doc, path7) {
29214
+ const segs = path7.split(V1_KEY_PATH_SEP);
28982
29215
  let cur = doc;
28983
29216
  for (const seg of segs.slice(0, -1)) {
28984
29217
  if (Array.isArray(cur)) cur = cur[Number(seg)];
28985
- else if (isObj3(cur)) cur = cur[seg];
29218
+ else if (isObj4(cur)) cur = cur[seg];
28986
29219
  else return null;
28987
29220
  }
28988
29221
  const last2 = segs[segs.length - 1];
28989
29222
  if (Array.isArray(cur)) return Number(last2) < cur.length ? [cur, last2] : null;
28990
- if (isObj3(cur)) return Object.hasOwn(cur, last2) ? [cur, last2] : null;
29223
+ if (isObj4(cur)) return Object.hasOwn(cur, last2) ? [cur, last2] : null;
28991
29224
  return null;
28992
29225
  }
28993
29226
  function stripJsonEntries(agent, file2, findings, kept, undo) {
@@ -29028,14 +29261,14 @@ function removeV1(agent, findings) {
29028
29261
  for (const f of findings) {
29029
29262
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
29030
29263
  else if (f.path === "") {
29031
- if (existsSync18(f.file)) {
29264
+ if (existsSync19(f.file)) {
29032
29265
  moveAside(f.file, undo);
29033
29266
  done.set(f, UPGRADE_REMOVED);
29034
29267
  } else done.set(f, UPGRADE_NOT_FOUND);
29035
29268
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
29036
29269
  }
29037
29270
  for (const [file2, list4] of entries) {
29038
- if (!existsSync18(file2)) {
29271
+ if (!existsSync19(file2)) {
29039
29272
  for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
29040
29273
  continue;
29041
29274
  }
@@ -29068,7 +29301,7 @@ function removeV1(agent, findings) {
29068
29301
  },
29069
29302
  rollback() {
29070
29303
  for (const u of undo.splice(0).reverse()) {
29071
- if (!existsSync18(u.trash)) continue;
29304
+ if (!existsSync19(u.trash)) continue;
29072
29305
  rmSync8(u.target, { recursive: true, force: true });
29073
29306
  renameWithRetry(u.trash, u.target);
29074
29307
  }
@@ -29077,7 +29310,7 @@ function removeV1(agent, findings) {
29077
29310
  }
29078
29311
 
29079
29312
  // src/core/ops/verify-sums.ts
29080
- import { createHash } from "node:crypto";
29313
+ import { createHash as createHash2 } from "node:crypto";
29081
29314
  import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync15 } from "node:fs";
29082
29315
  import { join as join21 } from "node:path";
29083
29316
  function mismatch() {
@@ -29117,7 +29350,7 @@ function verifySums(dir) {
29117
29350
  for (const [rel, abs] of files) {
29118
29351
  const want = sums.get(rel);
29119
29352
  if (want === void 0) throw mismatch();
29120
- const got = createHash(SUMS_HASH_ALGORITHM).update(readFileSync15(abs)).digest(HASH_ENCODING);
29353
+ const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync15(abs)).digest(HASH_ENCODING);
29121
29354
  if (got !== want) throw mismatch();
29122
29355
  }
29123
29356
  }
@@ -29146,7 +29379,7 @@ function pluginRootRow(adapter, env) {
29146
29379
  }
29147
29380
  function isCurrent(agentDir, dir) {
29148
29381
  const link = join22(agentDir, PLUGIN_CURRENT_LINK);
29149
- return existsSync19(link) && realpathSync7.native(link) === realpathSync7.native(dir);
29382
+ return existsSync20(link) && realpathSync8.native(link) === realpathSync8.native(dir);
29150
29383
  }
29151
29384
  async function checkout(adapter, deps) {
29152
29385
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
@@ -29266,7 +29499,7 @@ function checkCall(tool, input) {
29266
29499
 
29267
29500
  // src/entries/server.ts
29268
29501
  import { randomUUID } from "node:crypto";
29269
- import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync11 } from "node:fs";
29502
+ import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync11 } from "node:fs";
29270
29503
  import { dirname as dirname11, join as join24 } from "node:path";
29271
29504
  import { fileURLToPath as fileURLToPath2 } from "node:url";
29272
29505
 
@@ -29564,10 +29797,10 @@ function mergeDefs(...defs) {
29564
29797
  function cloneDef(schema) {
29565
29798
  return mergeDefs(schema._zod.def);
29566
29799
  }
29567
- function getElementAtPath2(obj, path5) {
29568
- if (!path5)
29800
+ function getElementAtPath2(obj, path7) {
29801
+ if (!path7)
29569
29802
  return obj;
29570
- return path5.reduce((acc, key) => acc?.[key], obj);
29803
+ return path7.reduce((acc, key) => acc?.[key], obj);
29571
29804
  }
29572
29805
  function promiseAllObject2(promisesObj) {
29573
29806
  const keys = Object.keys(promisesObj);
@@ -29907,11 +30140,11 @@ function explicitlyAborted(x, startIndex = 0) {
29907
30140
  }
29908
30141
  return false;
29909
30142
  }
29910
- function prefixIssues2(path5, issues) {
30143
+ function prefixIssues2(path7, issues) {
29911
30144
  return issues.map((iss) => {
29912
30145
  var _a5;
29913
30146
  (_a5 = iss).path ?? (_a5.path = []);
29914
- iss.path.unshift(path5);
30147
+ iss.path.unshift(path7);
29915
30148
  return iss;
29916
30149
  });
29917
30150
  }
@@ -30372,16 +30605,16 @@ function flattenError2(error42, mapper = (issue4) => issue4.message) {
30372
30605
  }
30373
30606
  function formatError3(error42, mapper = (issue4) => issue4.message) {
30374
30607
  const fieldErrors = { _errors: [] };
30375
- const processError = (error43, path5 = []) => {
30608
+ const processError = (error43, path7 = []) => {
30376
30609
  for (const issue4 of error43.issues) {
30377
30610
  if (issue4.code === "invalid_union" && issue4.errors.length) {
30378
- issue4.errors.map((issues) => processError({ issues }, [...path5, ...issue4.path]));
30611
+ issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
30379
30612
  } else if (issue4.code === "invalid_key") {
30380
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
30613
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
30381
30614
  } else if (issue4.code === "invalid_element") {
30382
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
30615
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
30383
30616
  } else {
30384
- const fullpath = [...path5, ...issue4.path];
30617
+ const fullpath = [...path7, ...issue4.path];
30385
30618
  if (fullpath.length === 0) {
30386
30619
  fieldErrors._errors.push(mapper(issue4));
30387
30620
  } else {
@@ -37145,10 +37378,10 @@ function mergeDefs2(...defs) {
37145
37378
  function cloneDef2(schema) {
37146
37379
  return mergeDefs2(schema._zod.def);
37147
37380
  }
37148
- function getElementAtPath3(obj, path5) {
37149
- if (!path5)
37381
+ function getElementAtPath3(obj, path7) {
37382
+ if (!path7)
37150
37383
  return obj;
37151
- return path5.reduce((acc, key) => acc?.[key], obj);
37384
+ return path7.reduce((acc, key) => acc?.[key], obj);
37152
37385
  }
37153
37386
  function promiseAllObject3(promisesObj) {
37154
37387
  const keys = Object.keys(promisesObj);
@@ -37488,11 +37721,11 @@ function explicitlyAborted2(x, startIndex = 0) {
37488
37721
  }
37489
37722
  return false;
37490
37723
  }
37491
- function prefixIssues3(path5, issues) {
37724
+ function prefixIssues3(path7, issues) {
37492
37725
  return issues.map((iss) => {
37493
37726
  var _a5;
37494
37727
  (_a5 = iss).path ?? (_a5.path = []);
37495
- iss.path.unshift(path5);
37728
+ iss.path.unshift(path7);
37496
37729
  return iss;
37497
37730
  });
37498
37731
  }
@@ -37950,16 +38183,16 @@ function flattenError3(error42, mapper = (issue4) => issue4.message) {
37950
38183
  }
37951
38184
  function formatError4(error42, mapper = (issue4) => issue4.message) {
37952
38185
  const fieldErrors = { _errors: [] };
37953
- const processError = (error43, path5 = []) => {
38186
+ const processError = (error43, path7 = []) => {
37954
38187
  for (const issue4 of error43.issues) {
37955
38188
  if (issue4.code === "invalid_union" && issue4.errors.length) {
37956
- issue4.errors.map((issues) => processError({ issues }, [...path5, ...issue4.path]));
38189
+ issue4.errors.map((issues) => processError({ issues }, [...path7, ...issue4.path]));
37957
38190
  } else if (issue4.code === "invalid_key") {
37958
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
38191
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
37959
38192
  } else if (issue4.code === "invalid_element") {
37960
- processError({ issues: issue4.issues }, [...path5, ...issue4.path]);
38193
+ processError({ issues: issue4.issues }, [...path7, ...issue4.path]);
37961
38194
  } else {
37962
- const fullpath = [...path5, ...issue4.path];
38195
+ const fullpath = [...path7, ...issue4.path];
37963
38196
  if (fullpath.length === 0) {
37964
38197
  fieldErrors._errors.push(mapper(issue4));
37965
38198
  } else {
@@ -46175,9 +46408,9 @@ var rev2026Codec = {
46175
46408
  });
46176
46409
  const parsed = buildSchemas2026().RequestMetaEnvelopeSchema.safeParse(meta3);
46177
46410
  if (!parsed.success) for (const issue4 of parsed.error.issues) {
46178
- const path5 = issue4.path.map(String);
46179
- const key = path5.length > 0 ? path5.join(".") : "_meta";
46180
- if (path5.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
46411
+ const path7 = issue4.path.map(String);
46412
+ const key = path7.length > 0 ? path7.join(".") : "_meta";
46413
+ if (path7.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
46181
46414
  issues.push({
46182
46415
  key,
46183
46416
  problem: issue4.message
@@ -46504,29 +46737,29 @@ var PERMITTED_X_MCP_HEADER_TYPES = /* @__PURE__ */ new Set([
46504
46737
  function scanXMcpHeaderDeclarations(inputSchema) {
46505
46738
  const declarations = [];
46506
46739
  const seenLower = /* @__PURE__ */ new Map();
46507
- const visit2 = (node3, path5, reachable) => {
46740
+ const visit2 = (node3, path7, reachable) => {
46508
46741
  if (node3 === null || typeof node3 !== "object") return void 0;
46509
46742
  const schema = node3;
46510
46743
  if (X_MCP_HEADER_KEY in schema) {
46511
- 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)`;
46744
+ 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)`;
46512
46745
  const raw = schema[X_MCP_HEADER_KEY];
46513
- if (typeof raw !== "string" || raw.length === 0) return `${pathName(path5)}: x-mcp-header MUST be a non-empty string`;
46514
- 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)`;
46746
+ if (typeof raw !== "string" || raw.length === 0) return `${pathName(path7)}: x-mcp-header MUST be a non-empty string`;
46747
+ 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)`;
46515
46748
  const type = typeof schema.type === "string" ? schema.type : void 0;
46516
- 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>"}`;
46749
+ 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>"}`;
46517
46750
  const lower = raw.toLowerCase();
46518
46751
  const prior = seenLower.get(lower);
46519
46752
  if (prior !== void 0) return `x-mcp-header '${raw}' is not case-insensitively unique (also declared as '${prior}')`;
46520
46753
  seenLower.set(lower, raw);
46521
46754
  declarations.push({
46522
- path: path5,
46755
+ path: path7,
46523
46756
  headerName: raw,
46524
46757
  type
46525
46758
  });
46526
46759
  }
46527
46760
  const properties = schema.properties;
46528
46761
  if (properties !== null && typeof properties === "object") for (const [key, child] of Object.entries(properties)) {
46529
- const fault$1 = visit2(child, [...path5, key], reachable);
46762
+ const fault$1 = visit2(child, [...path7, key], reachable);
46530
46763
  if (fault$1 !== void 0) return fault$1;
46531
46764
  }
46532
46765
  for (const k of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
@@ -46534,7 +46767,7 @@ function scanXMcpHeaderDeclarations(inputSchema) {
46534
46767
  if (sub === void 0) continue;
46535
46768
  const branches = Array.isArray(sub) ? sub : sub !== null && typeof sub === "object" && OBJECT_VALUED_SUBSCHEMA_KEYWORDS.has(k) ? Object.values(sub) : [sub];
46536
46769
  for (const branch of branches) {
46537
- const fault$1 = visit2(branch, [...path5, `<${k}>`], false);
46770
+ const fault$1 = visit2(branch, [...path7, `<${k}>`], false);
46538
46771
  if (fault$1 !== void 0) return fault$1;
46539
46772
  }
46540
46773
  }
@@ -46574,8 +46807,8 @@ var OBJECT_VALUED_SUBSCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
46574
46807
  "$defs",
46575
46808
  "definitions"
46576
46809
  ]);
46577
- function pathName(path5) {
46578
- return path5.length === 0 ? "<root>" : path5.join(".");
46810
+ function pathName(path7) {
46811
+ return path7.length === 0 ? "<root>" : path7.join(".");
46579
46812
  }
46580
46813
  var HEADER_MISMATCH_ERROR_CODE = -32020;
46581
46814
  var INBOUND_VALIDATION_LADDER = [
@@ -46864,7 +47097,7 @@ var PROPERTY_KEYS_BY_TYPE = {
46864
47097
  array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
46865
47098
  };
46866
47099
  var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
46867
- function walkProperty(node3, path5, vendor, unsupported) {
47100
+ function walkProperty(node3, path7, vendor, unsupported) {
46868
47101
  if (!isJsonObject(node3)) return node3;
46869
47102
  const allowedKeys = typeof node3.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node3.type) ? PROPERTY_KEYS_BY_TYPE[node3.type] : void 0;
46870
47103
  if (allowedKeys === void 0) return node3;
@@ -46872,8 +47105,8 @@ function walkProperty(node3, path5, vendor, unsupported) {
46872
47105
  for (const [key, value] of Object.entries(node3)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
46873
47106
  else if (key === "pattern" && node3.type === "string" && typeof node3.format === "string") {
46874
47107
  if (!SUPPORTED_STRING_FORMATS.has(node3.format)) pruned[key] = value;
46875
- else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path5}.${key}`);
46876
- } else unsupported.push(`${path5}.${key}`);
47108
+ else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path7}.${key}`);
47109
+ } else unsupported.push(`${path7}.${key}`);
46877
47110
  return pruned;
46878
47111
  }
46879
47112
  function walkRequestedSchema(converted, vendor) {
@@ -46890,11 +47123,11 @@ function describeUnsupportedProperties(pruned, fallback) {
46890
47123
  const offenders = Object.entries(pruned.properties).filter(([, node3]) => !parseSchema(PrimitiveSchemaDefinitionSchema, node3).success).map(([name]) => `properties.${name}`);
46891
47124
  return offenders.length > 0 ? offenders.join(", ") : fallback;
46892
47125
  }
46893
- function findDroppedConstraintPaths(original, parsed, path5 = "") {
46894
- if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path5}[${index}]`));
47126
+ function findDroppedConstraintPaths(original, parsed, path7 = "") {
47127
+ if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path7}[${index}]`));
46895
47128
  if (!isJsonObject(original) || !isJsonObject(parsed)) return [];
46896
47129
  return Object.entries(original).flatMap(([key, value]) => {
46897
- const childPath = path5 ? `${path5}.${key}` : key;
47130
+ const childPath = path7 ? `${path7}.${key}` : key;
46898
47131
  if (!Object.prototype.hasOwnProperty.call(parsed, key)) return isAnnotationOnlyJsonSchemaKeyword(key) ? [] : [childPath];
46899
47132
  return findDroppedConstraintPaths(value, parsed[key], childPath);
46900
47133
  });
@@ -50982,8 +51215,8 @@ var require_utils = /* @__PURE__ */ __commonJSMin((exports, module) => {
50982
51215
  for (let i = 0; i < str4.length; i++) if (str4[i] === token) ind++;
50983
51216
  return ind;
50984
51217
  }
50985
- function removeDotSegments(path5) {
50986
- let input = path5;
51218
+ function removeDotSegments(path7) {
51219
+ let input = path7;
50987
51220
  const output = [];
50988
51221
  let nextSlash = -1;
50989
51222
  let len = 0;
@@ -51136,8 +51369,8 @@ var require_schemes = /* @__PURE__ */ __commonJSMin((exports, module) => {
51136
51369
  wsComponent.secure = void 0;
51137
51370
  }
51138
51371
  if (wsComponent.resourceName) {
51139
- const [path5, query] = wsComponent.resourceName.split("?");
51140
- wsComponent.path = path5 && path5 !== "/" ? path5 : void 0;
51372
+ const [path7, query] = wsComponent.resourceName.split("?");
51373
+ wsComponent.path = path7 && path7 !== "/" ? path7 : void 0;
51141
51374
  wsComponent.query = query;
51142
51375
  wsComponent.resourceName = void 0;
51143
51376
  }
@@ -57332,7 +57565,7 @@ function installExitGuard(opts) {
57332
57565
  }
57333
57566
 
57334
57567
  // src/core/store/cleanup.ts
57335
- import { existsSync as existsSync20, readdirSync as readdirSync10, rmSync as rmSync10 } from "node:fs";
57568
+ import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync10 } from "node:fs";
57336
57569
  import { join as join23 } from "node:path";
57337
57570
  function deleteSource(raw, id) {
57338
57571
  raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
@@ -57368,7 +57601,7 @@ function userVersion(raw) {
57368
57601
  return raw.prepare("PRAGMA user_version").get().user_version;
57369
57602
  }
57370
57603
  function openForSweep(dbPath, projectKey) {
57371
- if (!existsSync20(dbPath) && (existsSync20(dbPath + DB_WAL_SUFFIX) || existsSync20(dbPath + DB_SHM_SUFFIX))) {
57604
+ if (!existsSync21(dbPath) && (existsSync21(dbPath + DB_WAL_SUFFIX) || existsSync21(dbPath + DB_SHM_SUFFIX))) {
57372
57605
  throw new CtxError("DB_GONE");
57373
57606
  }
57374
57607
  const sqlite = process.getBuiltinModule("node:sqlite");
@@ -57422,12 +57655,12 @@ function sweepDeadProjects(configDir) {
57422
57655
  }
57423
57656
 
57424
57657
  // src/entries/is-entry.ts
57425
- import { realpathSync as realpathSync8 } from "node:fs";
57658
+ import { realpathSync as realpathSync9 } from "node:fs";
57426
57659
  function isEntry(main, argv1, self) {
57427
57660
  if (main !== void 0) return main;
57428
57661
  if (argv1 === void 0 || argv1 === "") return false;
57429
57662
  try {
57430
- return realpathSync8(argv1) === realpathSync8(self);
57663
+ return realpathSync9(argv1) === realpathSync9(self);
57431
57664
  } catch {
57432
57665
  return false;
57433
57666
  }
@@ -57503,7 +57736,7 @@ function workspaceFromMeta(meta3) {
57503
57736
  }
57504
57737
  function realOrSame(p) {
57505
57738
  try {
57506
- return realpathSync9.native(p);
57739
+ return realpathSync10.native(p);
57507
57740
  } catch {
57508
57741
  return p;
57509
57742
  }
@@ -57551,7 +57784,7 @@ async function startServer(argv, env) {
57551
57784
  opening.catch(() => pending.delete(project.dbPath));
57552
57785
  }
57553
57786
  const db = await opening;
57554
- if (!existsSync21(db.path)) throw new CtxError("DB_GONE");
57787
+ if (!existsSync22(db.path)) throw new CtxError("DB_GONE");
57555
57788
  return db;
57556
57789
  }
57557
57790
  function stopMarker(configDir, projectKey) {
@@ -57559,7 +57792,7 @@ async function startServer(argv, env) {
57559
57792
  }
57560
57793
  function stopRequested() {
57561
57794
  const configDir = resolveConfigDir(process.env);
57562
- return held.some((db) => existsSync21(stopMarker(configDir, db.projectKey)));
57795
+ return held.some((db) => existsSync22(stopMarker(configDir, db.projectKey)));
57563
57796
  }
57564
57797
  async function journal(project, ctx, name, reply4) {
57565
57798
  const db = await ownDb(project);