context-mode 2.1.4 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/server.mjs CHANGED
@@ -7,8 +7,8 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/entries/server.ts
9
9
  import { randomUUID } from "node:crypto";
10
- import { existsSync as existsSync22, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
11
- import { dirname as dirname12, join as join22 } from "node:path";
10
+ import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
11
+ import { dirname as dirname12, join as join23 } from "node:path";
12
12
  import { fileURLToPath as fileURLToPath3 } from "node:url";
13
13
 
14
14
  // node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
@@ -2556,7 +2556,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
2556
2556
  }
2557
2557
  return propValues;
2558
2558
  });
2559
- const isObject6 = isObject;
2559
+ const isObject7 = isObject;
2560
2560
  const catchall = def.catchall;
2561
2561
  let value;
2562
2562
  const memo5 = globalConfig.memoizer;
@@ -2564,7 +2564,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
2564
2564
  inst._zod.parse = (payload, ctx) => {
2565
2565
  value ?? (value = _normalized.value);
2566
2566
  const input = payload.value;
2567
- if (!isObject6(input)) {
2567
+ if (!isObject7(input)) {
2568
2568
  payload.issues.push({
2569
2569
  expected: "object",
2570
2570
  code: "invalid_type",
@@ -2700,7 +2700,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
2700
2700
  return doc.compile();
2701
2701
  };
2702
2702
  let fastpass;
2703
- const isObject6 = isObject;
2703
+ const isObject7 = isObject;
2704
2704
  const jit = !globalConfig.jitless;
2705
2705
  const allowsEval4 = allowsEval;
2706
2706
  const fastEnabled = jit && allowsEval4.value;
@@ -2709,7 +2709,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
2709
2709
  inst._zod.parse = (payload, ctx) => {
2710
2710
  value ?? (value = _normalized.value);
2711
2711
  const input = payload.value;
2712
- if (!isObject6(input)) {
2712
+ if (!isObject7(input)) {
2713
2713
  payload.issues.push({
2714
2714
  expected: "object",
2715
2715
  code: "invalid_type",
@@ -3487,7 +3487,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
3487
3487
  var NONE = 0;
3488
3488
  var ASSUMED = 1;
3489
3489
  var PROVEN = 2;
3490
- function isRecursive(inst, stack2, resolve6) {
3490
+ function isRecursive(inst, stack2, resolve7) {
3491
3491
  const cached4 = recursive.get(inst);
3492
3492
  if (cached4 !== void 0)
3493
3493
  return cached4 ? PROVEN : NONE;
@@ -3497,7 +3497,7 @@ function isRecursive(inst, stack2, resolve6) {
3497
3497
  let result = NONE;
3498
3498
  const check2 = (child) => {
3499
3499
  if (result !== PROVEN && child?._zod) {
3500
- const answer3 = isRecursive(child, stack2, resolve6);
3500
+ const answer3 = isRecursive(child, stack2, resolve7);
3501
3501
  if (answer3 > result)
3502
3502
  result = answer3;
3503
3503
  }
@@ -3508,7 +3508,7 @@ function isRecursive(inst, stack2, resolve6) {
3508
3508
  const desc = Object.getOwnPropertyDescriptor(sh, key);
3509
3509
  if (spread && !desc.enumerable)
3510
3510
  continue;
3511
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve6) : NONE;
3511
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve7) : NONE;
3512
3512
  if (child > answer3)
3513
3513
  answer3 = child;
3514
3514
  }
@@ -3572,7 +3572,7 @@ function isRecursive(inst, stack2, resolve6) {
3572
3572
  break;
3573
3573
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
3574
3574
  case "lazy": {
3575
- const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
3575
+ const inner = def._cachedInner ?? (resolve7 ? inst._zod.innerType : void 0);
3576
3576
  merge5(inner ? isRecursive(inner, stack2, false) : ASSUMED);
3577
3577
  break;
3578
3578
  }
@@ -10085,7 +10085,7 @@ var $ZodObject2 = /* @__PURE__ */ $constructor2("$ZodObject", (inst, def) => {
10085
10085
  }
10086
10086
  return propValues;
10087
10087
  });
10088
- const isObject6 = isObject2;
10088
+ const isObject7 = isObject2;
10089
10089
  const catchall = def.catchall;
10090
10090
  let value;
10091
10091
  const memo5 = globalConfig2.memoizer;
@@ -10093,7 +10093,7 @@ var $ZodObject2 = /* @__PURE__ */ $constructor2("$ZodObject", (inst, def) => {
10093
10093
  inst._zod.parse = (payload, ctx) => {
10094
10094
  value ?? (value = _normalized.value);
10095
10095
  const input = payload.value;
10096
- if (!isObject6(input)) {
10096
+ if (!isObject7(input)) {
10097
10097
  payload.issues.push({
10098
10098
  expected: "object",
10099
10099
  code: "invalid_type",
@@ -10229,7 +10229,7 @@ var $ZodObjectJIT2 = /* @__PURE__ */ $constructor2("$ZodObjectJIT", (inst, def)
10229
10229
  return doc.compile();
10230
10230
  };
10231
10231
  let fastpass;
10232
- const isObject6 = isObject2;
10232
+ const isObject7 = isObject2;
10233
10233
  const jit = !globalConfig2.jitless;
10234
10234
  const allowsEval4 = allowsEval2;
10235
10235
  const fastEnabled = jit && allowsEval4.value;
@@ -10238,7 +10238,7 @@ var $ZodObjectJIT2 = /* @__PURE__ */ $constructor2("$ZodObjectJIT", (inst, def)
10238
10238
  inst._zod.parse = (payload, ctx) => {
10239
10239
  value ?? (value = _normalized.value);
10240
10240
  const input = payload.value;
10241
- if (!isObject6(input)) {
10241
+ if (!isObject7(input)) {
10242
10242
  payload.issues.push({
10243
10243
  expected: "object",
10244
10244
  code: "invalid_type",
@@ -11016,7 +11016,7 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
11016
11016
  var NONE2 = 0;
11017
11017
  var ASSUMED2 = 1;
11018
11018
  var PROVEN2 = 2;
11019
- function isRecursive2(inst, stack2, resolve6) {
11019
+ function isRecursive2(inst, stack2, resolve7) {
11020
11020
  const cached4 = recursive2.get(inst);
11021
11021
  if (cached4 !== void 0)
11022
11022
  return cached4 ? PROVEN2 : NONE2;
@@ -11026,7 +11026,7 @@ function isRecursive2(inst, stack2, resolve6) {
11026
11026
  let result = NONE2;
11027
11027
  const check2 = (child) => {
11028
11028
  if (result !== PROVEN2 && child?._zod) {
11029
- const answer3 = isRecursive2(child, stack2, resolve6);
11029
+ const answer3 = isRecursive2(child, stack2, resolve7);
11030
11030
  if (answer3 > result)
11031
11031
  result = answer3;
11032
11032
  }
@@ -11037,7 +11037,7 @@ function isRecursive2(inst, stack2, resolve6) {
11037
11037
  const desc = Object.getOwnPropertyDescriptor(sh, key);
11038
11038
  if (spread && !desc.enumerable)
11039
11039
  continue;
11040
- const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve6) : NONE2;
11040
+ const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve7) : NONE2;
11041
11041
  if (child > answer3)
11042
11042
  answer3 = child;
11043
11043
  }
@@ -11101,7 +11101,7 @@ function isRecursive2(inst, stack2, resolve6) {
11101
11101
  break;
11102
11102
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
11103
11103
  case "lazy": {
11104
- const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
11104
+ const inner = def._cachedInner ?? (resolve7 ? inst._zod.innerType : void 0);
11105
11105
  merge5(inner ? isRecursive2(inner, stack2, false) : ASSUMED2);
11106
11106
  break;
11107
11107
  }
@@ -17705,14 +17705,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
17705
17705
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
17706
17706
  }
17707
17707
  function sleep(ms, signal) {
17708
- return new Promise((resolve6, reject) => {
17708
+ return new Promise((resolve7, reject) => {
17709
17709
  if (signal?.aborted) {
17710
17710
  reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
17711
17711
  return;
17712
17712
  }
17713
17713
  const timer = setTimeout(() => {
17714
17714
  signal?.removeEventListener("abort", onAbort);
17715
- resolve6();
17715
+ resolve7();
17716
17716
  }, ms);
17717
17717
  const onAbort = () => {
17718
17718
  clearTimeout(timer);
@@ -18511,7 +18511,7 @@ var Protocol = class {
18511
18511
  const flowStartedAt = Date.now();
18512
18512
  let onAbort;
18513
18513
  let cleanupMessageId;
18514
- return new Promise((resolve6, reject) => {
18514
+ return new Promise((resolve7, reject) => {
18515
18515
  const earlyReject = (error42) => {
18516
18516
  reject(error42);
18517
18517
  };
@@ -18580,7 +18580,7 @@ var Protocol = class {
18580
18580
  }
18581
18581
  if (decoded.kind === "invalid") return reject(decoded.error);
18582
18582
  if (decoded.kind === "input_required") {
18583
- if (options?.allowInputRequired === true) return resolve6(manualInputRequiredValue(decoded));
18583
+ if (options?.allowInputRequired === true) return resolve7(manualInputRequiredValue(decoded));
18584
18584
  const flow = {
18585
18585
  codec,
18586
18586
  request: request2,
@@ -18592,11 +18592,11 @@ var Protocol = class {
18592
18592
  params
18593
18593
  }, resultSchema, legOptions)
18594
18594
  };
18595
- return resolve6(this._resolveNonCompleteResult(decoded, flow));
18595
+ return resolve7(this._resolveNonCompleteResult(decoded, flow));
18596
18596
  }
18597
18597
  const result = decoded.result;
18598
18598
  validateStandardSchema(resultSchema, result).then((parseResult) => {
18599
- if (parseResult.success) resolve6(parseResult.data);
18599
+ if (parseResult.success) resolve7(parseResult.data);
18600
18600
  else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request2.method}: ${parseResult.error}`));
18601
18601
  }, reject);
18602
18602
  });
@@ -21512,7 +21512,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
21512
21512
  ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
21513
21513
  const schOrFunc = root.refs[ref];
21514
21514
  if (schOrFunc) return schOrFunc;
21515
- let _sch = resolve6.call(this, root, ref);
21515
+ let _sch = resolve7.call(this, root, ref);
21516
21516
  if (_sch === void 0) {
21517
21517
  const schema = (_a5 = root.localRefs) === null || _a5 === void 0 ? void 0 : _a5[ref];
21518
21518
  const { schemaId } = this.opts;
@@ -21538,7 +21538,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
21538
21538
  function sameSchemaEnv(s1, s2) {
21539
21539
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
21540
21540
  }
21541
- function resolve6(root, ref) {
21541
+ function resolve7(root, ref) {
21542
21542
  let sch;
21543
21543
  while (typeof (sch = this.refs[ref]) == "string") ref = sch;
21544
21544
  return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
@@ -21988,7 +21988,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
21988
21988
  else if (typeof uri === "object") uri = parse6(serialize(uri, options), options);
21989
21989
  return uri;
21990
21990
  }
21991
- function resolve6(baseURI, relativeURI, options) {
21991
+ function resolve7(baseURI, relativeURI, options) {
21992
21992
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
21993
21993
  const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
21994
21994
  schemelessOptions.skipEscape = true;
@@ -22162,7 +22162,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
22162
22162
  const fastUri = {
22163
22163
  SCHEMES,
22164
22164
  normalize: normalize2,
22165
- resolve: resolve6,
22165
+ resolve: resolve7,
22166
22166
  resolveComponent,
22167
22167
  equal,
22168
22168
  serialize,
@@ -27627,7 +27627,7 @@ var StdioServerTransport = class {
27627
27627
  }
27628
27628
  send(message2) {
27629
27629
  if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
27630
- return new Promise((resolve6, reject) => {
27630
+ return new Promise((resolve7, reject) => {
27631
27631
  const json2 = serializeMessage(message2);
27632
27632
  let settled = false;
27633
27633
  const onError = (error42) => {
@@ -27642,14 +27642,14 @@ var StdioServerTransport = class {
27642
27642
  settled = true;
27643
27643
  this._stdout.off("error", onError);
27644
27644
  this._stdout.off("drain", onDrain);
27645
- resolve6();
27645
+ resolve7();
27646
27646
  };
27647
27647
  this._stdout.once("error", onError);
27648
27648
  if (this._stdout.write(json2)) {
27649
27649
  if (settled) return;
27650
27650
  settled = true;
27651
27651
  this._stdout.off("error", onError);
27652
- resolve6();
27652
+ resolve7();
27653
27653
  } else if (!settled) this._stdout.once("drain", onDrain);
27654
27654
  });
27655
27655
  }
@@ -27703,14 +27703,14 @@ var StdioConnectionChannel = class {
27703
27703
  */
27704
27704
  async whenRequestsAnswered(timeoutMs) {
27705
27705
  if (this._closed || this._pendingRequests.size === 0) return true;
27706
- return await new Promise((resolve6) => {
27706
+ return await new Promise((resolve7) => {
27707
27707
  const waiter = () => {
27708
27708
  clearTimeout(timer);
27709
- resolve6(true);
27709
+ resolve7(true);
27710
27710
  };
27711
27711
  const timer = setTimeout(() => {
27712
27712
  this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
27713
- resolve6(false);
27713
+ resolve7(false);
27714
27714
  }, timeoutMs);
27715
27715
  this._drainWaiters.push(waiter);
27716
27716
  });
@@ -28065,7 +28065,14 @@ var REPORT_CAP = 4096;
28065
28065
  var POINTER_MIN = 640;
28066
28066
  var STATE_CLOSE_TAG = "</context_mode_state>";
28067
28067
  var INDEX_WRITE_CHUNK = 1048576;
28068
- var REPLACE_TRIGGER_BYTES = 4096;
28068
+ var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
28069
+ var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
28070
+ function readReplaceTrigger(raw) {
28071
+ if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
28072
+ const n = Number(raw);
28073
+ return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
28074
+ }
28075
+ var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
28069
28076
  var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
28070
28077
  var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
28071
28078
  var MAX_CHUNK_BYTES = 4096;
@@ -28276,6 +28283,7 @@ function readHintEvery(raw) {
28276
28283
  return Number.isSafeInteger(n) && n > 0 ? n : MCP_HINT_EVERY_DEFAULT;
28277
28284
  }
28278
28285
  var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
28286
+ var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
28279
28287
  var DENY_WHAT = Object.freeze({
28280
28288
  curl: "This curl/wget call",
28281
28289
  http: "This inline HTTP call",
@@ -28326,10 +28334,35 @@ var DUMP_COUNT_COMMANDS = Object.freeze(["head", "tail"]);
28326
28334
  var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
28327
28335
  var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
28328
28336
  var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
28337
+ var READ_MEDIA_TYPES = Object.freeze({
28338
+ png: { exts: [".png"], sig: [{ at: 0, bytes: [137, 80, 78, 71, 13, 10, 26, 10] }] },
28339
+ jpeg: { exts: [".jpg", ".jpeg"], sig: [{ at: 0, bytes: [255, 216, 255] }] },
28340
+ gif: { exts: [".gif"], sig: [{ at: 0, bytes: [71, 73, 70, 56] }] },
28341
+ // "GIF8"
28342
+ webp: { exts: [".webp"], sig: [{ at: 0, bytes: [82, 73, 70, 70] }, { at: 8, bytes: [87, 69, 66, 80] }] },
28343
+ // "RIFF" .... "WEBP"
28344
+ pdf: { exts: [".pdf"], sig: [{ at: 0, bytes: [37, 80, 68, 70, 45] }] }
28345
+ // "%PDF-"
28346
+ });
28347
+ var READ_IMAGES = Object.freeze(["png", "jpeg", "gif", "webp"]);
28348
+ var READ_IMAGES_AND_PDF = Object.freeze([...READ_IMAGES, "pdf"]);
28349
+ var READ_MEDIA_BY_AGENT = Object.freeze({
28350
+ "claude-code": READ_IMAGES_AND_PDF,
28351
+ gemini: READ_IMAGES_AND_PDF,
28352
+ qwen: READ_IMAGES_AND_PDF,
28353
+ opencode: READ_IMAGES_AND_PDF,
28354
+ pi: READ_IMAGES,
28355
+ vscode: READ_IMAGES,
28356
+ zcode: READ_IMAGES,
28357
+ "copilot-cli": [],
28358
+ codex: [],
28359
+ kiro: []
28360
+ });
28329
28361
  var OWN_TOOL_PREFIX = "ctx_";
28330
28362
  var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
28331
28363
  var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
28332
28364
  var RECALL_MIN_SCORE = 5;
28365
+ var RECALL_QUERY_MAX_TERMS = 64;
28333
28366
  var RECALL_UNIT_CANDIDATES = 64;
28334
28367
  var AGENT_ARG = "--agent";
28335
28368
  var DECAY_SCALE = 1e3;
@@ -28410,7 +28443,7 @@ function PURGE_SUMMARY(rows, scope) {
28410
28443
  var DECISION_SOURCE = "decision";
28411
28444
  var DECISION_USER_LABEL = "decision (user)";
28412
28445
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
28413
- var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
28446
+ var BUNDLE_SHA = true ? "ee0a1f6058f6abdb5af70b05f825a997bb15615d" : void 0;
28414
28447
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
28415
28448
  var DOCTOR_LABEL = Object.freeze({
28416
28449
  D1: "version",
@@ -28496,9 +28529,9 @@ var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-ta
28496
28529
  var D1_PRERELEASE_SEP = "-";
28497
28530
  var D1_DEFAULT_TAG = "latest";
28498
28531
  var GIT_LS_REMOTE = "ls-remote";
28499
- var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
28532
+ var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
28500
28533
  function D2_NODE_DETAIL(version4) {
28501
- return `Node ${version4} is below ${NODE_MIN}`;
28534
+ return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version4}`;
28502
28535
  }
28503
28536
  var D2_SQLITE_DETAIL = "node:sqlite failed to load";
28504
28537
  var D2_SQLITE_FIX = "run ctx_doctor";
@@ -28667,15 +28700,23 @@ var REGEX_ESCAPE = "\\";
28667
28700
  var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
28668
28701
  var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
28669
28702
  var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
28703
+ var D5_READ_OWN_DETAIL = "PreToolUse Read of a skill file over the one-read limit under the agent's own config dir came back denied: skill and rule files must reach the model whole (#1326)";
28704
+ var D5_READ_MEDIA_DETAIL = "PreToolUse Read of a PNG over the one-read limit came back denied: an image Read must reach the model as an image block (#1321)";
28670
28705
  var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
28671
28706
  function D5_SLOW_DETAIL(ms) {
28672
28707
  return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
28673
28708
  }
28709
+ var D5_STOP_DETAIL = "Codex Stop event: the hook did not give an empty or Codex Stop reply, or it logged a hook error";
28674
28710
  var D5_FIX = "run ctx_upgrade";
28675
28711
  var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
28676
28712
  function D10_DETAIL(mode) {
28677
28713
  return `enforcement mode: ${mode}`;
28678
28714
  }
28715
+ function D10_PERMISSION_DETAIL(mode) {
28716
+ return `enforcement mode: ${mode}; OpenCode permission rules apply to ctx_* tools`;
28717
+ }
28718
+ var D10_PERMISSION_MISSING_DETAIL = "this OpenCode build gives plugins no permission check (ctx.permission.assert), so ctx_* tools cannot follow OpenCode permission rules";
28719
+ var D10_PERMISSION_FIX = "opencode upgrade";
28679
28720
  var D11_WIN_DETAIL = "Git Bash not found";
28680
28721
  var D11_WIN_FIX = "install Git for Windows";
28681
28722
  var D11_POSIX_DETAIL = "no sh on PATH";
@@ -28738,6 +28779,8 @@ var SETTINGS_FILE = "settings.json";
28738
28779
  var CLAUDE_USER_CONFIG_FILE = ".claude.json";
28739
28780
  var HOOKS_JSON_FILE = "hooks.json";
28740
28781
  var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
28782
+ var SETUP_BACKUP_DIR_NAME = "backups";
28783
+ var SETUP_MANIFEST_FILE = "manifest.json";
28741
28784
  var CODEX_HOME_ENV = "CODEX_HOME";
28742
28785
  var COPILOT_HOME_ENV = "COPILOT_HOME";
28743
28786
  var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
@@ -28832,6 +28875,7 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
28832
28875
  var JSON_INDENT_UNIT = " ";
28833
28876
  var MCP_COMMAND_FIELD = "command";
28834
28877
  var MCP_ARGS_FIELD = "args";
28878
+ var MCP_ENV_FIELD = "env";
28835
28879
  var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
28836
28880
  var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
28837
28881
  var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
@@ -28949,7 +28993,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
28949
28993
 
28950
28994
  // src/core/contracts/errors.ts
28951
28995
  var ERROR_TEXT = Object.freeze({
28952
- NODE_TOO_OLD: "Node <v> is below 24.15.0. Fix: install Node 24.15.0 or later.",
28996
+ NODE_TOO_OLD: "Context Mode needs Node 24.15.0 or newer; you have <v>. Fix: nvm install 24, or install it from https://nodejs.org.",
28997
+ // #1328 D-NODE-OLD-1
28953
28998
  NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
28954
28999
  DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
28955
29000
  // D-ORPHAN-WAL-1
@@ -29381,7 +29426,7 @@ function installExitGuard(opts) {
29381
29426
 
29382
29427
  // src/core/project/config-dir.ts
29383
29428
  import { basename, dirname, join, posix, resolve, win32 } from "node:path";
29384
- var { mkdirSync: mkdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
29429
+ var { existsSync: existsSync2, mkdirSync: mkdirSync2, readFileSync, readdirSync, realpathSync } = process.getBuiltinModule("node:fs");
29385
29430
  function homeDirOf(env, platform = process.platform) {
29386
29431
  const set3 = (v) => v !== void 0 && v !== "";
29387
29432
  if (platform === "win32") {
@@ -29408,7 +29453,34 @@ function codexPluginHomeOf(bundleDir2) {
29408
29453
  function codexRunDirOf(env, home, bundleDir2) {
29409
29454
  const dir = env[CODEX_HOME_ENV];
29410
29455
  if (dir !== void 0 && dir !== "") return dir;
29411
- return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
29456
+ return codexPluginHomeOf(bundleDir2) ?? codexSetupHomeOf(env, home) ?? codexDirOf(env, home);
29457
+ }
29458
+ function codexSetupHomeOf(env, home) {
29459
+ if (home === "" && !env[DATA_DIR_ENV]) return null;
29460
+ const base = join(dataRootOf(env, home), SETUP_BACKUP_DIR_NAME);
29461
+ let runs;
29462
+ try {
29463
+ runs = readdirSync(base).sort().reverse();
29464
+ } catch {
29465
+ return null;
29466
+ }
29467
+ for (const run of runs) {
29468
+ const file2 = join(base, run, SETUP_MANIFEST_FILE);
29469
+ if (!existsSync2(file2)) continue;
29470
+ let entries;
29471
+ try {
29472
+ entries = JSON.parse(readFileSync(file2, "utf8")).entries;
29473
+ } catch {
29474
+ continue;
29475
+ }
29476
+ if (!Array.isArray(entries)) continue;
29477
+ for (const e of entries) {
29478
+ if (e?.agent !== "codex" || typeof e.file !== "string") continue;
29479
+ const p = e.file.includes(win32.sep) ? win32 : posix;
29480
+ if (p.basename(e.file) === CONFIG_TOML_FILE) return p.dirname(e.file);
29481
+ }
29482
+ }
29483
+ return null;
29412
29484
  }
29413
29485
  function copilotDirOf(env, home) {
29414
29486
  const dir = env[COPILOT_HOME_ENV];
@@ -29660,7 +29732,7 @@ function sha256Hex(text) {
29660
29732
  }
29661
29733
 
29662
29734
  // src/core/project/resolve.ts
29663
- var { existsSync: existsSync2, readFileSync, realpathSync: realpathSync3, statSync } = process.getBuiltinModule("node:fs");
29735
+ var { existsSync: existsSync3, readFileSync: readFileSync2, realpathSync: realpathSync3, statSync } = process.getBuiltinModule("node:fs");
29664
29736
  function sourceOf(agent) {
29665
29737
  switch (agent) {
29666
29738
  case "claude-code":
@@ -29730,12 +29802,12 @@ function gitDirAt(dotGit) {
29730
29802
  } catch {
29731
29803
  return null;
29732
29804
  }
29733
- return existsSync2(join3(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
29805
+ return existsSync3(join3(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
29734
29806
  }
29735
29807
  function firstLine(file2) {
29736
29808
  let text;
29737
29809
  try {
29738
- text = readFileSync(file2, "utf8");
29810
+ text = readFileSync2(file2, "utf8");
29739
29811
  } catch {
29740
29812
  return null;
29741
29813
  }
@@ -29788,7 +29860,7 @@ function resolveProject(agent, src) {
29788
29860
  }
29789
29861
 
29790
29862
  // src/core/store/cleanup.ts
29791
- import { existsSync as existsSync3, readdirSync as readdirSync2, rmSync as rmSync3 } from "node:fs";
29863
+ import { existsSync as existsSync4, readdirSync as readdirSync3, rmSync as rmSync3 } from "node:fs";
29792
29864
  import { join as join5 } from "node:path";
29793
29865
 
29794
29866
  // src/core/store/snippet.ts
@@ -32315,8 +32387,25 @@ function listSessionSources(db, sessionId, limit) {
32315
32387
  const rows = stmt(db.raw, "SELECT id, label, bytes_total FROM sources WHERE session_id = ? ORDER BY id DESC LIMIT ?").all(sessionId, limit);
32316
32388
  return rows.map((r) => ({ id: Number(r.id), label: r.label, bytes: Number(r.bytes_total) }));
32317
32389
  }
32318
- function recallQueryText(prompt, goal) {
32319
- return goal === prompt ? prompt : prompt + " " + goal;
32390
+ function recallQueryText(prompt) {
32391
+ const kept = /* @__PURE__ */ new Set();
32392
+ const all = /* @__PURE__ */ new Set();
32393
+ const add = (w) => {
32394
+ if (all.size < RECALL_QUERY_MAX_TERMS) all.add(w);
32395
+ if (!STOPWORDS.has(w.toLowerCase())) kept.add(w);
32396
+ };
32397
+ let cur = "";
32398
+ for (const ch of prompt) {
32399
+ if (kept.size >= RECALL_QUERY_MAX_TERMS) break;
32400
+ if (ch.trim() === "" || ch === "\0") {
32401
+ if (cur !== "") add(cur);
32402
+ cur = "";
32403
+ } else {
32404
+ cur += ch;
32405
+ }
32406
+ }
32407
+ if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
32408
+ return [...kept.size > 0 ? kept : all].join(" ");
32320
32409
  }
32321
32410
  function queryUnits(db, sessionId, q, limit) {
32322
32411
  const match = searchTerms(q).join(" OR ");
@@ -32328,7 +32417,7 @@ function queryUnits(db, sessionId, q, limit) {
32328
32417
  }
32329
32418
 
32330
32419
  // src/core/store/owners.ts
32331
- import { mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync2, rmSync as rmSync2, writeFileSync } from "node:fs";
32420
+ import { mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync } from "node:fs";
32332
32421
  import { basename as basename3, join as join4 } from "node:path";
32333
32422
  function ownersDir(configDir, projectKey) {
32334
32423
  return join4(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
@@ -32361,7 +32450,7 @@ function listLiveOwners(configDir, projectKey) {
32361
32450
  const dir = ownersDir(configDir, projectKey);
32362
32451
  let names;
32363
32452
  try {
32364
- names = readdirSync(dir);
32453
+ names = readdirSync2(dir);
32365
32454
  } catch (err) {
32366
32455
  if (errCode(err) === "ENOENT") return [];
32367
32456
  throw err;
@@ -32372,7 +32461,7 @@ function listLiveOwners(configDir, projectKey) {
32372
32461
  const file2 = join4(dir, name);
32373
32462
  let text;
32374
32463
  try {
32375
- text = readFileSync2(file2, "utf8");
32464
+ text = readFileSync3(file2, "utf8");
32376
32465
  } catch (err) {
32377
32466
  if (errCode(err) === "ENOENT") continue;
32378
32467
  throw err;
@@ -32419,7 +32508,7 @@ function userVersion(raw) {
32419
32508
  return raw.prepare("PRAGMA user_version").get().user_version;
32420
32509
  }
32421
32510
  function openForSweep(dbPath, projectKey) {
32422
- if (!existsSync3(dbPath) && (existsSync3(dbPath + DB_WAL_SUFFIX) || existsSync3(dbPath + DB_SHM_SUFFIX))) {
32511
+ if (!existsSync4(dbPath) && (existsSync4(dbPath + DB_WAL_SUFFIX) || existsSync4(dbPath + DB_SHM_SUFFIX))) {
32423
32512
  throw new CtxError("DB_GONE");
32424
32513
  }
32425
32514
  const sqlite = process.getBuiltinModule("node:sqlite");
@@ -32454,7 +32543,7 @@ function sweepOne(configDir, projectKey, cutoff) {
32454
32543
  function sweepDeadProjects(configDir) {
32455
32544
  let entries;
32456
32545
  try {
32457
- entries = readdirSync2(join5(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
32546
+ entries = readdirSync3(join5(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
32458
32547
  } catch (err) {
32459
32548
  if (err.code === "ENOENT") return [];
32460
32549
  throw err;
@@ -35133,7 +35222,7 @@ var $ZodObject3 = /* @__PURE__ */ $constructor3("$ZodObject", (inst, def) => {
35133
35222
  return (payload, ctx) => fn(shape, payload, ctx);
35134
35223
  };
35135
35224
  let fastpass;
35136
- const isObject6 = isObject3;
35225
+ const isObject7 = isObject3;
35137
35226
  const jit = !globalConfig3.jitless;
35138
35227
  const allowsEval4 = allowsEval3;
35139
35228
  const fastEnabled = jit && allowsEval4.value;
@@ -35142,7 +35231,7 @@ var $ZodObject3 = /* @__PURE__ */ $constructor3("$ZodObject", (inst, def) => {
35142
35231
  inst._zod.parse = (payload, ctx) => {
35143
35232
  value ?? (value = _normalized.value);
35144
35233
  const input = payload.value;
35145
- if (!isObject6(input)) {
35234
+ if (!isObject7(input)) {
35146
35235
  payload.issues.push({
35147
35236
  expected: "object",
35148
35237
  code: "invalid_type",
@@ -43903,7 +43992,7 @@ function cutPoint(src, start, end, scratch) {
43903
43992
  const r = encoder.encodeInto(src.slice(start, limit), scratch);
43904
43993
  return { end: start + r.read, written: r.written };
43905
43994
  }
43906
- function merge4(src, blocks, join23, cap, lineCut) {
43995
+ function merge4(src, blocks, join24, cap, lineCut) {
43907
43996
  const out = [];
43908
43997
  const scratch = new Uint8Array(cap);
43909
43998
  let wide;
@@ -43913,7 +44002,7 @@ function merge4(src, blocks, join23, cap, lineCut) {
43913
44002
  out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
43914
44003
  };
43915
44004
  for (const b of blocks) {
43916
- if (cur !== void 0 && !join23) {
44005
+ if (cur !== void 0 && !join24) {
43917
44006
  emit(cur.start, cur.end, curBytes);
43918
44007
  cur = void 0;
43919
44008
  }
@@ -44119,10 +44208,10 @@ function startArgv(argv) {
44119
44208
  return sh === null ? null : [sh, ...argv];
44120
44209
  }
44121
44210
  function runProcess(argv, o) {
44122
- return new Promise((resolve6) => {
44211
+ return new Promise((resolve7) => {
44123
44212
  const isWin2 = process.platform === "win32";
44124
44213
  const start = startArgv(argv);
44125
- if (start === null) return resolve6(NOT_STARTED);
44214
+ if (start === null) return resolve7(NOT_STARTED);
44126
44215
  let child;
44127
44216
  try {
44128
44217
  child = spawn(start[0], start.slice(1), {
@@ -44136,7 +44225,7 @@ function runProcess(argv, o) {
44136
44225
  windowsHide: true
44137
44226
  });
44138
44227
  } catch {
44139
- return resolve6(NOT_STARTED);
44228
+ return resolve7(NOT_STARTED);
44140
44229
  }
44141
44230
  const stdoutChunks = [];
44142
44231
  const stderrChunks = [];
@@ -44161,7 +44250,7 @@ function runProcess(argv, o) {
44161
44250
  settled = true;
44162
44251
  clearTimeout(timer);
44163
44252
  o.signal.removeEventListener("abort", onAbort);
44164
- resolve6({
44253
+ resolve7({
44165
44254
  stdout: Buffer.concat(stdoutChunks),
44166
44255
  stderr: Buffer.concat(stderrChunks),
44167
44256
  exitCode,
@@ -44182,7 +44271,7 @@ function runProcess(argv, o) {
44182
44271
  }
44183
44272
 
44184
44273
  // src/core/index/auto-memory.ts
44185
- import { readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
44274
+ import { readdirSync as readdirSync4, readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
44186
44275
  import { join as join6 } from "node:path";
44187
44276
  var MEMORY_FILES = Object.freeze([
44188
44277
  Object.freeze(["CLAUDE.md"]),
@@ -44197,7 +44286,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
44197
44286
  var MD = ".md";
44198
44287
  function steeringFiles(worktree) {
44199
44288
  try {
44200
- return readdirSync3(join6(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
44289
+ return readdirSync4(join6(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
44201
44290
  } catch {
44202
44291
  return [];
44203
44292
  }
@@ -44217,7 +44306,7 @@ function readAutoMemory(project) {
44217
44306
  sourceId: null,
44218
44307
  path: path8,
44219
44308
  label: segs.join("/"),
44220
- text: readFileSync3(path8, "utf8")
44309
+ text: readFileSync4(path8, "utf8")
44221
44310
  });
44222
44311
  } catch {
44223
44312
  }
@@ -44841,8 +44930,8 @@ var ctxBatch = Object.freeze({
44841
44930
  });
44842
44931
 
44843
44932
  // src/core/tools/doctor.ts
44844
- import { readdirSync as readdirSync7, readFileSync as readFileSync11, existsSync as existsSync16 } from "node:fs";
44845
- import { basename as basename5, join as join16 } from "node:path";
44933
+ import { readdirSync as readdirSync8, readFileSync as readFileSync12, existsSync as existsSync17 } from "node:fs";
44934
+ import { basename as basename5, join as join17 } from "node:path";
44846
44935
 
44847
44936
  // src/adapters/claude-code.ts
44848
44937
  var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
@@ -45039,10 +45128,17 @@ function encode3(ev, d, _extra) {
45039
45128
  // src/adapters/codex.ts
45040
45129
  var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
45041
45130
  var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
45131
+ var STOP_EVENT = "Stop";
45132
+ var EMPTY = { stdout: "", exitCode: 0 };
45042
45133
  function decode4(raw) {
45134
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
45135
+ const p = raw;
45136
+ return { event: STOP_EVENT, agent: "codex", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
45137
+ }
45043
45138
  return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
45044
45139
  }
45045
45140
  function encode4(ev, d, _extra) {
45141
+ if (ev.event === STOP_EVENT) return EMPTY;
45046
45142
  return encodeClaudeShape(ev, d, false);
45047
45143
  }
45048
45144
 
@@ -45058,7 +45154,7 @@ var GEMINI_EVENTS = {
45058
45154
  var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
45059
45155
  var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
45060
45156
  var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
45061
- var EMPTY = { stdout: "", exitCode: 0 };
45157
+ var EMPTY2 = { stdout: "", exitCode: 0 };
45062
45158
  var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its full output, and this is the part that answers the call:\n";
45063
45159
  function own3(p, key) {
45064
45160
  return Object.hasOwn(p, key) ? p[key] : void 0;
@@ -45099,7 +45195,13 @@ function readResult2(resp) {
45099
45195
  const llm = obj === void 0 ? void 0 : own3(obj, "llmContent");
45100
45196
  const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
45101
45197
  const err = obj === void 0 ? void 0 : own3(obj, "error");
45102
- return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
45198
+ const info = { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
45199
+ if (hasMediaPart(llm)) info.keep = true;
45200
+ return info;
45201
+ }
45202
+ function hasMediaPart(llm) {
45203
+ const parts = Array.isArray(llm) ? llm : [llm];
45204
+ return parts.some((p) => typeof p === "object" && p !== null && (Object.hasOwn(p, "inlineData") || Object.hasOwn(p, "fileData")));
45103
45205
  }
45104
45206
  var URL_STARTS = ["https://", "http://"];
45105
45207
  var URL_TRAIL = `.,;:!?)]}>'"`;
@@ -45166,15 +45268,15 @@ function decode5(raw) {
45166
45268
  function encode5(ev, d, _extra) {
45167
45269
  switch (d.kind) {
45168
45270
  case "allow":
45169
- return EMPTY;
45271
+ return EMPTY2;
45170
45272
  case "hint":
45171
- if (!HINT_EVENTS.includes(ev.event)) return EMPTY;
45273
+ if (!HINT_EVENTS.includes(ev.event)) return EMPTY2;
45172
45274
  return { stdout: JSON.stringify({ hookSpecificOutput: { additionalContext: d.text } }), exitCode: 0 };
45173
45275
  case "deny":
45174
- if (!DENY_EVENTS.includes(ev.event)) return EMPTY;
45276
+ if (!DENY_EVENTS.includes(ev.event)) return EMPTY2;
45175
45277
  return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
45176
45278
  case "replace":
45177
- if (ev.event !== "PostToolUse") return EMPTY;
45279
+ if (ev.event !== "PostToolUse") return EMPTY2;
45178
45280
  return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
45179
45281
  }
45180
45282
  }
@@ -45294,21 +45396,21 @@ function decode7(raw) {
45294
45396
  if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
45295
45397
  return ev;
45296
45398
  }
45297
- var EMPTY2 = { stdout: "", exitCode: 0 };
45399
+ var EMPTY3 = { stdout: "", exitCode: 0 };
45298
45400
  function encode7(ev, d, _extra) {
45299
45401
  switch (d.kind) {
45300
45402
  case "allow":
45301
- return EMPTY2;
45403
+ return EMPTY3;
45302
45404
  case "hint":
45303
- return ev.event === "PostToolUse" ? EMPTY2 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
45405
+ return ev.event === "PostToolUse" ? EMPTY3 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
45304
45406
  case "deny":
45305
- if (ev.event !== "PreToolUse") return EMPTY2;
45407
+ if (ev.event !== "PreToolUse") return EMPTY3;
45306
45408
  return {
45307
45409
  stdout: JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }),
45308
45410
  exitCode: 0
45309
45411
  };
45310
45412
  case "replace":
45311
- if (ev.event !== "PostToolUse") return EMPTY2;
45413
+ if (ev.event !== "PostToolUse") return EMPTY3;
45312
45414
  return { stdout: JSON.stringify({ modifiedResult: { resultType: RESULT_SUCCESS, textResultForLlm: d.output } }), exitCode: 0 };
45313
45415
  }
45314
45416
  }
@@ -45858,15 +45960,15 @@ function getAdapter(id) {
45858
45960
  }
45859
45961
 
45860
45962
  // src/core/ops/bundle-dir.ts
45861
- import { existsSync as existsSync4 } from "node:fs";
45963
+ import { existsSync as existsSync5 } from "node:fs";
45862
45964
  import { dirname as dirname4, join as join7 } from "node:path";
45863
45965
  import { fileURLToPath } from "node:url";
45864
45966
  function bundleDirOf(argv1, moduleFile) {
45865
45967
  const own4 = dirname4(argv1);
45866
- if (existsSync4(join7(own4, SERVER_ENTRY_FILE))) return own4;
45968
+ if (existsSync5(join7(own4, SERVER_ENTRY_FILE))) return own4;
45867
45969
  let dir = dirname4(moduleFile);
45868
45970
  for (; ; ) {
45869
- if (existsSync4(join7(dir, SERVER_ENTRY_FILE))) return dir;
45971
+ if (existsSync5(join7(dir, SERVER_ENTRY_FILE))) return dir;
45870
45972
  const up = dirname4(dir);
45871
45973
  if (up === dir) return own4;
45872
45974
  dir = up;
@@ -45880,16 +45982,16 @@ function ownBundleDir() {
45880
45982
  }
45881
45983
 
45882
45984
  // src/core/ops/doctor-config.ts
45883
- import { existsSync as existsSync9, readdirSync as readdirSync6 } from "node:fs";
45985
+ import { existsSync as existsSync10, readdirSync as readdirSync7 } from "node:fs";
45884
45986
  import { join as join11 } from "node:path";
45885
45987
 
45886
45988
  // src/core/ops/detect-v1.ts
45887
- import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync5 } from "node:fs";
45989
+ import { existsSync as existsSync7, opendirSync, readdirSync as readdirSync5, readFileSync as readFileSync6 } from "node:fs";
45888
45990
  import { tmpdir } from "node:os";
45889
45991
  import { join as join9 } from "node:path";
45890
45992
 
45891
45993
  // src/core/ops/host-config.ts
45892
- import { existsSync as existsSync5, readFileSync as readFileSync4 } from "node:fs";
45994
+ import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
45893
45995
  import { dirname as dirname5, join as join8 } from "node:path";
45894
45996
 
45895
45997
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
@@ -48031,9 +48133,9 @@ function readHostConfig(agent, path8) {
48031
48133
  let file2 = path8;
48032
48134
  if (agent === "opencode") {
48033
48135
  const jsonc = join8(dirname5(path8), OPENCODE_CONFIG_FILES[0]);
48034
- if (existsSync5(jsonc)) file2 = jsonc;
48136
+ if (existsSync6(jsonc)) file2 = jsonc;
48035
48137
  }
48036
- const raw = existsSync5(file2) ? readFileSync4(file2, "utf8") : "";
48138
+ const raw = existsSync6(file2) ? readFileSync5(file2, "utf8") : "";
48037
48139
  return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
48038
48140
  }
48039
48141
  function stripJsonComments(text) {
@@ -48505,14 +48607,14 @@ function stripJsonc(text) {
48505
48607
  }
48506
48608
  function readJson(file2) {
48507
48609
  try {
48508
- return JSON.parse(stripJsonc(hostText(readFileSync5(file2, "utf8"))));
48610
+ return JSON.parse(stripJsonc(hostText(readFileSync6(file2, "utf8"))));
48509
48611
  } catch {
48510
48612
  return void 0;
48511
48613
  }
48512
48614
  }
48513
48615
  function readText(file2) {
48514
48616
  try {
48515
- return hostText(readFileSync5(file2, "utf8"));
48617
+ return hostText(readFileSync6(file2, "utf8"));
48516
48618
  } catch {
48517
48619
  return "";
48518
48620
  }
@@ -48569,7 +48671,7 @@ function flatCommands(events, prefix) {
48569
48671
  var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
48570
48672
  var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
48571
48673
  function dataDir(dir, reason, out) {
48572
- if (existsSync6(dir)) out.push(finding(dir, "", reason));
48674
+ if (existsSync7(dir)) out.push(finding(dir, "", reason));
48573
48675
  }
48574
48676
  function mcpEntry(file2, doc, out) {
48575
48677
  if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
@@ -48598,7 +48700,7 @@ function scanClaudeCode(home, agentHome, out) {
48598
48700
  claudeShapeSettings(agentHome, out);
48599
48701
  for (const ext of V1_CACHE_HEAL_EXTS) {
48600
48702
  const file2 = join9(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
48601
- if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
48703
+ if (existsSync7(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
48602
48704
  }
48603
48705
  const userFile = join9(home, CLAUDE_USER_CONFIG_FILE);
48604
48706
  mcpEntry(userFile, readJson(userFile), out);
@@ -48616,6 +48718,7 @@ function scanCodex(agentHome, out) {
48616
48718
  for (const span2 of readTomlTables(tomlFile)) {
48617
48719
  if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
48618
48720
  if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
48721
+ if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config4, span2.path.slice(0, 2)))) continue;
48619
48722
  out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
48620
48723
  }
48621
48724
  dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
@@ -48644,7 +48747,7 @@ function scanVscode(agentHome, project, out) {
48644
48747
  }
48645
48748
  function jsonFiles(dir) {
48646
48749
  try {
48647
- return readdirSync4(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
48750
+ return readdirSync5(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
48648
48751
  } catch {
48649
48752
  return [];
48650
48753
  }
@@ -48667,7 +48770,7 @@ function scanKiro(agentHome, project, out) {
48667
48770
  const steeringDocs = [join9(agentHome, ...KIRO_STEERING_FILE)];
48668
48771
  if (project !== void 0) steeringDocs.push(join9(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
48669
48772
  for (const file2 of steeringDocs) {
48670
- if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
48773
+ if (existsSync7(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
48671
48774
  }
48672
48775
  dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48673
48776
  }
@@ -48777,7 +48880,7 @@ function detectV1(agent, home, scope = {}) {
48777
48880
  }
48778
48881
 
48779
48882
  // src/core/ops/plugin-root.ts
48780
- import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
48883
+ import { existsSync as existsSync8, readdirSync as readdirSync6, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
48781
48884
  import { dirname as dirname6, isAbsolute, join as join10, sep as sep2 } from "node:path";
48782
48885
  import { fileURLToPath as fileURLToPath2 } from "node:url";
48783
48886
  function missing(agent, path8) {
@@ -48819,7 +48922,7 @@ var realOrNull = (path8) => {
48819
48922
  };
48820
48923
  var readOrNull = (file2) => {
48821
48924
  try {
48822
- return readFileSync6(file2, "utf8");
48925
+ return readFileSync7(file2, "utf8");
48823
48926
  } catch {
48824
48927
  return null;
48825
48928
  }
@@ -48846,7 +48949,7 @@ function marketplaceChoice(env, worktree) {
48846
48949
  const record6 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
48847
48950
  const recorded = record6 === null ? [] : recordedInstalls(record6);
48848
48951
  if (recorded.length === 0) return { record: false };
48849
- const live = recorded.filter((r) => existsSync7(r.installPath));
48952
+ const live = recorded.filter((r) => existsSync8(r.installPath));
48850
48953
  const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
48851
48954
  if (mine !== void 0) return { root: mine.installPath };
48852
48955
  const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
@@ -48874,10 +48977,10 @@ function marketplaceRoot(adapter, env, worktree) {
48874
48977
  if ("root" in choice) return choice.root;
48875
48978
  if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
48876
48979
  const cacheReal = realOrNull(cache);
48877
- if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync7(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
48980
+ if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync8(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
48878
48981
  const pattern = join10(cache, "*", PLUGIN_NAME);
48879
- if (!existsSync7(cache)) throw missing(adapter.id, pattern);
48880
- const found = readdirSync5(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
48982
+ if (!existsSync8(cache)) throw missing(adapter.id, pattern);
48983
+ const found = readdirSync6(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync8(dir));
48881
48984
  if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
48882
48985
  return found[0];
48883
48986
  }
@@ -48885,7 +48988,7 @@ function configEntryRoot(adapter, env) {
48885
48988
  const spec = OWN_MCP_ENTRY[adapter.id];
48886
48989
  if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
48887
48990
  const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
48888
- if (!existsSync7(file2)) throw missing(adapter.id, file2);
48991
+ if (!existsSync8(file2)) throw missing(adapter.id, file2);
48889
48992
  const current = readHostConfig(adapter.id, file2);
48890
48993
  const value = parseHostConfig(adapter.id, file2, current.text, current.format);
48891
48994
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
@@ -48919,7 +49022,7 @@ function resolvePluginRoot(adapter, env, worktree) {
48919
49022
  }
48920
49023
 
48921
49024
  // src/setup/pi-gate.ts
48922
- import { existsSync as existsSync8, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
49025
+ import { existsSync as existsSync9, readFileSync as readFileSync8, realpathSync as realpathSync5 } from "node:fs";
48923
49026
  import path4 from "node:path";
48924
49027
  var EXTENSIONS_KEY = "extensions";
48925
49028
  var PROJECT_DIR = ".pi";
@@ -48927,9 +49030,9 @@ var TRUST_FILE = "trust.json";
48927
49030
  var ALWAYS = "always";
48928
49031
  var SOURCE_PREFIXES = ["npm:", "git:"];
48929
49032
  function load(file2) {
48930
- if (!existsSync8(file2)) return void 0;
49033
+ if (!existsSync9(file2)) return void 0;
48931
49034
  try {
48932
- return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync7(file2, "utf8")), "json") };
49035
+ return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync8(file2, "utf8")), "json") };
48933
49036
  } catch {
48934
49037
  return void 0;
48935
49038
  }
@@ -49087,14 +49190,14 @@ function codexNativeDir(env, home) {
49087
49190
  }
49088
49191
  if (enabled !== true) return null;
49089
49192
  const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
49090
- if (!existsSync9(cache)) return null;
49193
+ if (!existsSync10(cache)) return null;
49091
49194
  const found = [];
49092
- for (const market of readdirSync6(cache)) {
49195
+ for (const market of readdirSync7(cache)) {
49093
49196
  const plugin = join11(cache, market, SERVER_KEY);
49094
- if (!existsSync9(plugin)) continue;
49095
- for (const version4 of readdirSync6(plugin).sort()) {
49197
+ if (!existsSync10(plugin)) continue;
49198
+ for (const version4 of readdirSync7(plugin).sort()) {
49096
49199
  const dir = join11(plugin, version4, CODEX_PLUGIN_SUBDIR);
49097
- if (existsSync9(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
49200
+ if (existsSync10(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
49098
49201
  }
49099
49202
  }
49100
49203
  return found.length === 0 ? null : found[found.length - 1];
@@ -49257,7 +49360,7 @@ function configPaths(row5, env, worktree) {
49257
49360
  }
49258
49361
 
49259
49362
  // src/core/ops/doctor-db.ts
49260
- import { existsSync as existsSync10, statSync as statSync4 } from "node:fs";
49363
+ import { existsSync as existsSync11, statSync as statSync4 } from "node:fs";
49261
49364
  var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
49262
49365
  var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
49263
49366
  var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -49299,15 +49402,15 @@ function orphanFiles(dbPath) {
49299
49402
  const files = [];
49300
49403
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
49301
49404
  const path8 = dbPath + suffix;
49302
- if (existsSync10(path8)) files.push({ path: path8, bytes: statSync4(path8).size });
49405
+ if (existsSync11(path8)) files.push({ path: path8, bytes: statSync4(path8).size });
49303
49406
  }
49304
- return files.length > 0 && !existsSync10(dbPath) ? files : [];
49407
+ return files.length > 0 && !existsSync11(dbPath) ? files : [];
49305
49408
  }
49306
49409
  async function checkDb(project) {
49307
49410
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
49308
49411
  const orphan = orphanFiles(project.dbPath);
49309
49412
  if (orphan.length > 0) return { row: fail2(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
49310
- if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
49413
+ if (!existsSync11(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
49311
49414
  const sqlite = await loadSqlite2();
49312
49415
  if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
49313
49416
  let raw = null;
@@ -49333,7 +49436,7 @@ async function checkDb(project) {
49333
49436
  }
49334
49437
  }
49335
49438
  async function checkIndex(project) {
49336
- if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
49439
+ if (!existsSync11(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
49337
49440
  const sqlite = await loadSqlite2();
49338
49441
  if (sqlite === null) return unknown4("D9", D2_SQLITE_DETAIL);
49339
49442
  let raw = null;
@@ -49350,7 +49453,7 @@ async function checkIndex(project) {
49350
49453
  }
49351
49454
 
49352
49455
  // src/core/ops/doctor-env.ts
49353
- import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync6 } from "node:fs";
49456
+ import { existsSync as existsSync12, readFileSync as readFileSync9, realpathSync as realpathSync6 } from "node:fs";
49354
49457
  import { isAbsolute as isAbsolute2, join as join12, relative as relative2 } from "node:path";
49355
49458
  function pass3(id, detail = DOCTOR_PASS_DETAIL) {
49356
49459
  return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
@@ -49363,7 +49466,7 @@ function fail3(id, detail, fixCommand) {
49363
49466
  }
49364
49467
  function bundleVersion(bundleDir2) {
49365
49468
  try {
49366
- const v = JSON.parse(readFileSync8(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
49469
+ const v = JSON.parse(readFileSync9(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
49367
49470
  return typeof v === "string" && v !== "" ? v : void 0;
49368
49471
  } catch {
49369
49472
  return void 0;
@@ -49513,7 +49616,7 @@ function checkMcp(ctx) {
49513
49616
  return named2 || versioned ? pass3("D6") : unknown5("D6", D6_UNKNOWN_DETAIL);
49514
49617
  }
49515
49618
  function piCwdInside(worktree, piCwd) {
49516
- if (piCwd === void 0 || !existsSync11(piCwd)) return false;
49619
+ if (piCwd === void 0 || !existsSync12(piCwd)) return false;
49517
49620
  const rel = relative2(worktree, realpathSync6.native(piCwd));
49518
49621
  return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
49519
49622
  }
@@ -49523,7 +49626,9 @@ function checkProject(i) {
49523
49626
  if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
49524
49627
  return pass3("D7");
49525
49628
  }
49526
- function checkMode(adapter) {
49629
+ function checkMode(adapter, hostPermission) {
49630
+ if (hostPermission === "missing") return fail3("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
49631
+ if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
49527
49632
  return pass3("D10", D10_DETAIL(adapter.denyChannel));
49528
49633
  }
49529
49634
  function checkShell(env) {
@@ -49534,10 +49639,1821 @@ function checkShell(env) {
49534
49639
  }
49535
49640
 
49536
49641
  // src/core/ops/doctor-hook.ts
49537
- import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync9, realpathSync as realpathSync8, rmSync as rmSync4 } from "node:fs";
49642
+ import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync10, realpathSync as realpathSync8, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
49538
49643
  import { tmpdir as tmpdir2 } from "node:os";
49539
49644
  import path7 from "node:path";
49540
49645
 
49646
+ // tests/fixtures/host-schemas/claude-code.json
49647
+ var claude_code_default = {
49648
+ host: "claude-code",
49649
+ source: "Claude Code 2.1.274 native binary, zod hook output schemas: top level eW, hookSpecificOutput union members xF (PreToolUse, permissionDecision enum FK), DF (UserPromptSubmit), UF (SessionStart), the PostToolUse member. zod drops keys it does not read, so each object lists only the keys the host reads.",
49650
+ output: {
49651
+ PreToolUse: {
49652
+ title: "Claude Code 2.1.274 PreToolUse reply",
49653
+ definitions: {
49654
+ Specific: {
49655
+ type: "object",
49656
+ additionalProperties: false,
49657
+ properties: {
49658
+ hookEventName: {
49659
+ type: "string",
49660
+ const: "PreToolUse"
49661
+ },
49662
+ permissionDecision: {
49663
+ type: "string",
49664
+ enum: [
49665
+ "allow",
49666
+ "deny",
49667
+ "ask",
49668
+ "defer"
49669
+ ]
49670
+ },
49671
+ permissionDecisionReason: {
49672
+ type: "string"
49673
+ },
49674
+ updatedInput: {
49675
+ type: "object"
49676
+ },
49677
+ additionalContext: {
49678
+ type: "string"
49679
+ },
49680
+ permissionDisplay: {
49681
+ description: "@internal Desktop host only"
49682
+ }
49683
+ },
49684
+ required: [
49685
+ "hookEventName"
49686
+ ]
49687
+ }
49688
+ },
49689
+ type: "object",
49690
+ additionalProperties: false,
49691
+ properties: {
49692
+ continue: {
49693
+ type: "boolean"
49694
+ },
49695
+ suppressOutput: {
49696
+ type: "boolean"
49697
+ },
49698
+ stopReason: {
49699
+ type: "string"
49700
+ },
49701
+ decision: {
49702
+ type: "string",
49703
+ enum: [
49704
+ "approve",
49705
+ "block"
49706
+ ]
49707
+ },
49708
+ systemMessage: {
49709
+ type: "string"
49710
+ },
49711
+ terminalSequence: {
49712
+ type: "string"
49713
+ },
49714
+ reason: {
49715
+ type: "string"
49716
+ },
49717
+ hookSpecificOutput: {
49718
+ allOf: [
49719
+ {
49720
+ $ref: "#/definitions/Specific"
49721
+ }
49722
+ ]
49723
+ }
49724
+ }
49725
+ },
49726
+ PostToolUse: {
49727
+ title: "Claude Code 2.1.274 PostToolUse reply",
49728
+ definitions: {
49729
+ Specific: {
49730
+ type: "object",
49731
+ additionalProperties: false,
49732
+ properties: {
49733
+ hookEventName: {
49734
+ type: "string",
49735
+ const: "PostToolUse"
49736
+ },
49737
+ additionalContext: {
49738
+ type: "string"
49739
+ },
49740
+ classifierContext: {
49741
+ type: "string"
49742
+ },
49743
+ updatedToolOutput: {
49744
+ description: "the tool's own output object"
49745
+ },
49746
+ updatedMCPToolOutput: {
49747
+ description: "an MCP tool's own output"
49748
+ }
49749
+ },
49750
+ required: [
49751
+ "hookEventName"
49752
+ ]
49753
+ }
49754
+ },
49755
+ type: "object",
49756
+ additionalProperties: false,
49757
+ properties: {
49758
+ continue: {
49759
+ type: "boolean"
49760
+ },
49761
+ suppressOutput: {
49762
+ type: "boolean"
49763
+ },
49764
+ stopReason: {
49765
+ type: "string"
49766
+ },
49767
+ decision: {
49768
+ type: "string",
49769
+ enum: [
49770
+ "approve",
49771
+ "block"
49772
+ ]
49773
+ },
49774
+ systemMessage: {
49775
+ type: "string"
49776
+ },
49777
+ terminalSequence: {
49778
+ type: "string"
49779
+ },
49780
+ reason: {
49781
+ type: "string"
49782
+ },
49783
+ hookSpecificOutput: {
49784
+ allOf: [
49785
+ {
49786
+ $ref: "#/definitions/Specific"
49787
+ }
49788
+ ]
49789
+ }
49790
+ }
49791
+ },
49792
+ UserPromptSubmit: {
49793
+ title: "Claude Code 2.1.274 UserPromptSubmit reply",
49794
+ definitions: {
49795
+ Specific: {
49796
+ type: "object",
49797
+ additionalProperties: false,
49798
+ properties: {
49799
+ hookEventName: {
49800
+ type: "string",
49801
+ const: "UserPromptSubmit"
49802
+ },
49803
+ additionalContext: {
49804
+ type: "string"
49805
+ },
49806
+ sessionTitle: {
49807
+ type: "string"
49808
+ },
49809
+ suppressOriginalPrompt: {
49810
+ type: "boolean"
49811
+ }
49812
+ },
49813
+ required: [
49814
+ "hookEventName"
49815
+ ]
49816
+ }
49817
+ },
49818
+ type: "object",
49819
+ additionalProperties: false,
49820
+ properties: {
49821
+ continue: {
49822
+ type: "boolean"
49823
+ },
49824
+ suppressOutput: {
49825
+ type: "boolean"
49826
+ },
49827
+ stopReason: {
49828
+ type: "string"
49829
+ },
49830
+ decision: {
49831
+ type: "string",
49832
+ enum: [
49833
+ "approve",
49834
+ "block"
49835
+ ]
49836
+ },
49837
+ systemMessage: {
49838
+ type: "string"
49839
+ },
49840
+ terminalSequence: {
49841
+ type: "string"
49842
+ },
49843
+ reason: {
49844
+ type: "string"
49845
+ },
49846
+ hookSpecificOutput: {
49847
+ allOf: [
49848
+ {
49849
+ $ref: "#/definitions/Specific"
49850
+ }
49851
+ ]
49852
+ }
49853
+ }
49854
+ },
49855
+ SessionStart: {
49856
+ title: "Claude Code 2.1.274 SessionStart reply",
49857
+ definitions: {
49858
+ Specific: {
49859
+ type: "object",
49860
+ additionalProperties: false,
49861
+ properties: {
49862
+ hookEventName: {
49863
+ type: "string",
49864
+ const: "SessionStart"
49865
+ },
49866
+ additionalContext: {
49867
+ type: "string"
49868
+ },
49869
+ initialUserMessage: {
49870
+ type: "string"
49871
+ },
49872
+ sessionTitle: {
49873
+ type: "string"
49874
+ },
49875
+ watchPaths: {
49876
+ type: "array",
49877
+ items: {
49878
+ type: "string"
49879
+ }
49880
+ },
49881
+ reloadSkills: {
49882
+ type: "boolean"
49883
+ }
49884
+ },
49885
+ required: [
49886
+ "hookEventName"
49887
+ ]
49888
+ }
49889
+ },
49890
+ type: "object",
49891
+ additionalProperties: false,
49892
+ properties: {
49893
+ continue: {
49894
+ type: "boolean"
49895
+ },
49896
+ suppressOutput: {
49897
+ type: "boolean"
49898
+ },
49899
+ stopReason: {
49900
+ type: "string"
49901
+ },
49902
+ decision: {
49903
+ type: "string",
49904
+ enum: [
49905
+ "approve",
49906
+ "block"
49907
+ ]
49908
+ },
49909
+ systemMessage: {
49910
+ type: "string"
49911
+ },
49912
+ terminalSequence: {
49913
+ type: "string"
49914
+ },
49915
+ reason: {
49916
+ type: "string"
49917
+ },
49918
+ hookSpecificOutput: {
49919
+ allOf: [
49920
+ {
49921
+ $ref: "#/definitions/Specific"
49922
+ }
49923
+ ]
49924
+ }
49925
+ }
49926
+ }
49927
+ }
49928
+ };
49929
+
49930
+ // tests/fixtures/host-schemas/codex.json
49931
+ var codex_default = {
49932
+ host: "codex",
49933
+ source: "github.com/openai/codex tag rust-v0.166.0 codex-rs/hooks/schema/generated/*.command.output.schema.json",
49934
+ output: {
49935
+ PreToolUse: {
49936
+ $schema: "http://json-schema.org/draft-07/schema#",
49937
+ additionalProperties: false,
49938
+ definitions: {
49939
+ PreToolUseDecisionWire: {
49940
+ enum: [
49941
+ "approve",
49942
+ "block"
49943
+ ],
49944
+ type: "string"
49945
+ },
49946
+ PreToolUseHookSpecificOutputWire: {
49947
+ additionalProperties: false,
49948
+ properties: {
49949
+ additionalContext: {
49950
+ default: null,
49951
+ type: "string"
49952
+ },
49953
+ hookEventName: {
49954
+ const: "PreToolUse",
49955
+ type: "string"
49956
+ },
49957
+ permissionDecision: {
49958
+ allOf: [
49959
+ {
49960
+ $ref: "#/definitions/PreToolUsePermissionDecisionWire"
49961
+ }
49962
+ ],
49963
+ default: null
49964
+ },
49965
+ permissionDecisionReason: {
49966
+ default: null,
49967
+ type: "string"
49968
+ },
49969
+ updatedInput: {
49970
+ default: null
49971
+ }
49972
+ },
49973
+ required: [
49974
+ "hookEventName"
49975
+ ],
49976
+ type: "object"
49977
+ },
49978
+ PreToolUsePermissionDecisionWire: {
49979
+ enum: [
49980
+ "allow",
49981
+ "deny",
49982
+ "ask"
49983
+ ],
49984
+ type: "string"
49985
+ }
49986
+ },
49987
+ properties: {
49988
+ continue: {
49989
+ default: true,
49990
+ type: "boolean"
49991
+ },
49992
+ decision: {
49993
+ allOf: [
49994
+ {
49995
+ $ref: "#/definitions/PreToolUseDecisionWire"
49996
+ }
49997
+ ],
49998
+ default: null
49999
+ },
50000
+ hookSpecificOutput: {
50001
+ allOf: [
50002
+ {
50003
+ $ref: "#/definitions/PreToolUseHookSpecificOutputWire"
50004
+ }
50005
+ ],
50006
+ default: null
50007
+ },
50008
+ reason: {
50009
+ default: null,
50010
+ type: "string"
50011
+ },
50012
+ stopReason: {
50013
+ default: null,
50014
+ type: "string"
50015
+ },
50016
+ suppressOutput: {
50017
+ default: false,
50018
+ type: "boolean"
50019
+ },
50020
+ systemMessage: {
50021
+ default: null,
50022
+ type: "string"
50023
+ }
50024
+ },
50025
+ title: "pre-tool-use.command.output",
50026
+ type: "object"
50027
+ },
50028
+ PostToolUse: {
50029
+ $schema: "http://json-schema.org/draft-07/schema#",
50030
+ additionalProperties: false,
50031
+ definitions: {
50032
+ BlockDecisionWire: {
50033
+ enum: [
50034
+ "block"
50035
+ ],
50036
+ type: "string"
50037
+ },
50038
+ PostToolUseHookSpecificOutputWire: {
50039
+ additionalProperties: false,
50040
+ properties: {
50041
+ additionalContext: {
50042
+ default: null,
50043
+ type: "string"
50044
+ },
50045
+ hookEventName: {
50046
+ const: "PostToolUse",
50047
+ type: "string"
50048
+ },
50049
+ updatedMCPToolOutput: {
50050
+ default: null
50051
+ }
50052
+ },
50053
+ required: [
50054
+ "hookEventName"
50055
+ ],
50056
+ type: "object"
50057
+ }
50058
+ },
50059
+ properties: {
50060
+ continue: {
50061
+ default: true,
50062
+ type: "boolean"
50063
+ },
50064
+ decision: {
50065
+ allOf: [
50066
+ {
50067
+ $ref: "#/definitions/BlockDecisionWire"
50068
+ }
50069
+ ],
50070
+ default: null
50071
+ },
50072
+ hookSpecificOutput: {
50073
+ allOf: [
50074
+ {
50075
+ $ref: "#/definitions/PostToolUseHookSpecificOutputWire"
50076
+ }
50077
+ ],
50078
+ default: null
50079
+ },
50080
+ reason: {
50081
+ default: null,
50082
+ type: "string"
50083
+ },
50084
+ stopReason: {
50085
+ default: null,
50086
+ type: "string"
50087
+ },
50088
+ suppressOutput: {
50089
+ default: false,
50090
+ type: "boolean"
50091
+ },
50092
+ systemMessage: {
50093
+ default: null,
50094
+ type: "string"
50095
+ }
50096
+ },
50097
+ title: "post-tool-use.command.output",
50098
+ type: "object"
50099
+ },
50100
+ SessionStart: {
50101
+ $schema: "http://json-schema.org/draft-07/schema#",
50102
+ additionalProperties: false,
50103
+ definitions: {
50104
+ SessionStartHookSpecificOutputWire: {
50105
+ additionalProperties: false,
50106
+ properties: {
50107
+ additionalContext: {
50108
+ default: null,
50109
+ type: "string"
50110
+ },
50111
+ hookEventName: {
50112
+ const: "SessionStart",
50113
+ type: "string"
50114
+ }
50115
+ },
50116
+ required: [
50117
+ "hookEventName"
50118
+ ],
50119
+ type: "object"
50120
+ }
50121
+ },
50122
+ properties: {
50123
+ continue: {
50124
+ default: true,
50125
+ type: "boolean"
50126
+ },
50127
+ hookSpecificOutput: {
50128
+ allOf: [
50129
+ {
50130
+ $ref: "#/definitions/SessionStartHookSpecificOutputWire"
50131
+ }
50132
+ ],
50133
+ default: null
50134
+ },
50135
+ stopReason: {
50136
+ default: null,
50137
+ type: "string"
50138
+ },
50139
+ suppressOutput: {
50140
+ default: false,
50141
+ type: "boolean"
50142
+ },
50143
+ systemMessage: {
50144
+ default: null,
50145
+ type: "string"
50146
+ }
50147
+ },
50148
+ title: "session-start.command.output",
50149
+ type: "object"
50150
+ },
50151
+ UserPromptSubmit: {
50152
+ $schema: "http://json-schema.org/draft-07/schema#",
50153
+ additionalProperties: false,
50154
+ definitions: {
50155
+ BlockDecisionWire: {
50156
+ enum: [
50157
+ "block"
50158
+ ],
50159
+ type: "string"
50160
+ },
50161
+ UserPromptSubmitHookSpecificOutputWire: {
50162
+ additionalProperties: false,
50163
+ properties: {
50164
+ additionalContext: {
50165
+ default: null,
50166
+ type: "string"
50167
+ },
50168
+ hookEventName: {
50169
+ const: "UserPromptSubmit",
50170
+ type: "string"
50171
+ }
50172
+ },
50173
+ required: [
50174
+ "hookEventName"
50175
+ ],
50176
+ type: "object"
50177
+ }
50178
+ },
50179
+ properties: {
50180
+ continue: {
50181
+ default: true,
50182
+ type: "boolean"
50183
+ },
50184
+ decision: {
50185
+ allOf: [
50186
+ {
50187
+ $ref: "#/definitions/BlockDecisionWire"
50188
+ }
50189
+ ],
50190
+ default: null
50191
+ },
50192
+ hookSpecificOutput: {
50193
+ allOf: [
50194
+ {
50195
+ $ref: "#/definitions/UserPromptSubmitHookSpecificOutputWire"
50196
+ }
50197
+ ],
50198
+ default: null
50199
+ },
50200
+ reason: {
50201
+ default: null,
50202
+ type: "string"
50203
+ },
50204
+ stopReason: {
50205
+ default: null,
50206
+ type: "string"
50207
+ },
50208
+ suppressOutput: {
50209
+ default: false,
50210
+ type: "boolean"
50211
+ },
50212
+ systemMessage: {
50213
+ default: null,
50214
+ type: "string"
50215
+ }
50216
+ },
50217
+ title: "user-prompt-submit.command.output",
50218
+ type: "object"
50219
+ },
50220
+ Stop: {
50221
+ $schema: "http://json-schema.org/draft-07/schema#",
50222
+ additionalProperties: false,
50223
+ definitions: {
50224
+ BlockDecisionWire: {
50225
+ enum: [
50226
+ "block"
50227
+ ],
50228
+ type: "string"
50229
+ }
50230
+ },
50231
+ properties: {
50232
+ continue: {
50233
+ default: true,
50234
+ type: "boolean"
50235
+ },
50236
+ decision: {
50237
+ allOf: [
50238
+ {
50239
+ $ref: "#/definitions/BlockDecisionWire"
50240
+ }
50241
+ ],
50242
+ default: null
50243
+ },
50244
+ reason: {
50245
+ default: null,
50246
+ description: "Claude requires `reason` when `decision` is `block`; we enforce that semantic rule during output parsing rather than in the JSON schema.",
50247
+ type: "string"
50248
+ },
50249
+ stopReason: {
50250
+ default: null,
50251
+ type: "string"
50252
+ },
50253
+ suppressOutput: {
50254
+ default: false,
50255
+ type: "boolean"
50256
+ },
50257
+ systemMessage: {
50258
+ default: null,
50259
+ type: "string"
50260
+ }
50261
+ },
50262
+ title: "stop.command.output",
50263
+ type: "object"
50264
+ }
50265
+ }
50266
+ };
50267
+
50268
+ // tests/fixtures/host-schemas/gemini.json
50269
+ var gemini_default = {
50270
+ host: "gemini",
50271
+ source: "@google/gemini-cli 0.67.0: bundle/docs/hooks/reference.md (Common output fields; BeforeTool, AfterTool, BeforeAgent, SessionStart output fields) and bundle/chunk-O7MGOE2I.js HookOutput (isBlockingDecision block|deny, isAskDecision ask). Keys are canonical events; each title names the native event.",
50272
+ output: {
50273
+ PreToolUse: {
50274
+ title: "Gemini CLI 0.67.0 BeforeTool reply",
50275
+ definitions: {
50276
+ Specific: {
50277
+ type: "object",
50278
+ additionalProperties: false,
50279
+ properties: {
50280
+ hookEventName: {
50281
+ type: "string"
50282
+ },
50283
+ tool_input: {
50284
+ type: "object"
50285
+ }
50286
+ }
50287
+ }
50288
+ },
50289
+ type: "object",
50290
+ additionalProperties: false,
50291
+ properties: {
50292
+ systemMessage: {
50293
+ type: "string"
50294
+ },
50295
+ suppressOutput: {
50296
+ type: "boolean"
50297
+ },
50298
+ continue: {
50299
+ type: "boolean"
50300
+ },
50301
+ stopReason: {
50302
+ type: "string"
50303
+ },
50304
+ decision: {
50305
+ type: "string",
50306
+ enum: [
50307
+ "allow",
50308
+ "deny",
50309
+ "block",
50310
+ "ask"
50311
+ ]
50312
+ },
50313
+ reason: {
50314
+ type: "string"
50315
+ },
50316
+ hookSpecificOutput: {
50317
+ allOf: [
50318
+ {
50319
+ $ref: "#/definitions/Specific"
50320
+ }
50321
+ ]
50322
+ }
50323
+ }
50324
+ },
50325
+ PostToolUse: {
50326
+ title: "Gemini CLI 0.67.0 AfterTool reply",
50327
+ definitions: {
50328
+ Specific: {
50329
+ type: "object",
50330
+ additionalProperties: false,
50331
+ properties: {
50332
+ hookEventName: {
50333
+ type: "string"
50334
+ },
50335
+ additionalContext: {
50336
+ type: "string"
50337
+ },
50338
+ tailToolCallRequest: {
50339
+ type: "object",
50340
+ additionalProperties: false,
50341
+ properties: {
50342
+ name: {
50343
+ type: "string"
50344
+ },
50345
+ args: {
50346
+ type: "object"
50347
+ }
50348
+ },
50349
+ required: [
50350
+ "name",
50351
+ "args"
50352
+ ]
50353
+ }
50354
+ }
50355
+ }
50356
+ },
50357
+ type: "object",
50358
+ additionalProperties: false,
50359
+ properties: {
50360
+ systemMessage: {
50361
+ type: "string"
50362
+ },
50363
+ suppressOutput: {
50364
+ type: "boolean"
50365
+ },
50366
+ continue: {
50367
+ type: "boolean"
50368
+ },
50369
+ stopReason: {
50370
+ type: "string"
50371
+ },
50372
+ decision: {
50373
+ type: "string",
50374
+ enum: [
50375
+ "allow",
50376
+ "deny",
50377
+ "block",
50378
+ "ask"
50379
+ ]
50380
+ },
50381
+ reason: {
50382
+ type: "string"
50383
+ },
50384
+ hookSpecificOutput: {
50385
+ allOf: [
50386
+ {
50387
+ $ref: "#/definitions/Specific"
50388
+ }
50389
+ ]
50390
+ }
50391
+ }
50392
+ },
50393
+ UserPromptSubmit: {
50394
+ title: "Gemini CLI 0.67.0 BeforeAgent reply",
50395
+ definitions: {
50396
+ Specific: {
50397
+ type: "object",
50398
+ additionalProperties: false,
50399
+ properties: {
50400
+ hookEventName: {
50401
+ type: "string"
50402
+ },
50403
+ additionalContext: {
50404
+ type: "string"
50405
+ }
50406
+ }
50407
+ }
50408
+ },
50409
+ type: "object",
50410
+ additionalProperties: false,
50411
+ properties: {
50412
+ systemMessage: {
50413
+ type: "string"
50414
+ },
50415
+ suppressOutput: {
50416
+ type: "boolean"
50417
+ },
50418
+ continue: {
50419
+ type: "boolean"
50420
+ },
50421
+ stopReason: {
50422
+ type: "string"
50423
+ },
50424
+ decision: {
50425
+ type: "string",
50426
+ enum: [
50427
+ "allow",
50428
+ "deny",
50429
+ "block",
50430
+ "ask"
50431
+ ]
50432
+ },
50433
+ reason: {
50434
+ type: "string"
50435
+ },
50436
+ hookSpecificOutput: {
50437
+ allOf: [
50438
+ {
50439
+ $ref: "#/definitions/Specific"
50440
+ }
50441
+ ]
50442
+ }
50443
+ }
50444
+ },
50445
+ SessionStart: {
50446
+ title: "Gemini CLI 0.67.0 SessionStart reply",
50447
+ definitions: {
50448
+ Specific: {
50449
+ type: "object",
50450
+ additionalProperties: false,
50451
+ properties: {
50452
+ hookEventName: {
50453
+ type: "string"
50454
+ },
50455
+ additionalContext: {
50456
+ type: "string"
50457
+ }
50458
+ }
50459
+ }
50460
+ },
50461
+ type: "object",
50462
+ additionalProperties: false,
50463
+ properties: {
50464
+ systemMessage: {
50465
+ type: "string"
50466
+ },
50467
+ suppressOutput: {
50468
+ type: "boolean"
50469
+ },
50470
+ continue: {
50471
+ type: "boolean"
50472
+ },
50473
+ stopReason: {
50474
+ type: "string"
50475
+ },
50476
+ decision: {
50477
+ type: "string",
50478
+ enum: [
50479
+ "allow",
50480
+ "deny",
50481
+ "block",
50482
+ "ask"
50483
+ ]
50484
+ },
50485
+ reason: {
50486
+ type: "string"
50487
+ },
50488
+ hookSpecificOutput: {
50489
+ allOf: [
50490
+ {
50491
+ $ref: "#/definitions/Specific"
50492
+ }
50493
+ ]
50494
+ }
50495
+ }
50496
+ }
50497
+ }
50498
+ };
50499
+
50500
+ // tests/fixtures/host-schemas/qwen.json
50501
+ var qwen_default = {
50502
+ host: "qwen",
50503
+ source: "@qwen-code/qwen-code 0.26.7: bundled/qc-helper/docs/features/hooks.md (Hook Output Structure, per-event Output Options) and chunks/chunk-6GTPLW7K.js HookOutput (getPermissionDecision reads hookSpecificOutput.permissionDecision allow|deny|ask, then decision allow|approve|deny|block|ask; a missing permissionDecision is no decision).",
50504
+ output: {
50505
+ PreToolUse: {
50506
+ title: "Qwen Code 0.26.7 PreToolUse reply",
50507
+ definitions: {
50508
+ Specific: {
50509
+ type: "object",
50510
+ additionalProperties: false,
50511
+ properties: {
50512
+ hookEventName: {
50513
+ type: "string",
50514
+ const: "PreToolUse"
50515
+ },
50516
+ permissionDecision: {
50517
+ type: "string",
50518
+ enum: [
50519
+ "allow",
50520
+ "deny",
50521
+ "ask"
50522
+ ]
50523
+ },
50524
+ permissionDecisionReason: {
50525
+ type: "string"
50526
+ },
50527
+ updatedInput: {
50528
+ type: "object"
50529
+ },
50530
+ additionalContext: {
50531
+ type: "string"
50532
+ }
50533
+ },
50534
+ required: [
50535
+ "hookEventName"
50536
+ ]
50537
+ }
50538
+ },
50539
+ type: "object",
50540
+ additionalProperties: false,
50541
+ properties: {
50542
+ continue: {
50543
+ type: "boolean"
50544
+ },
50545
+ stopReason: {
50546
+ type: "string"
50547
+ },
50548
+ suppressOutput: {
50549
+ type: "boolean"
50550
+ },
50551
+ systemMessage: {
50552
+ type: "string"
50553
+ },
50554
+ decision: {
50555
+ type: "string",
50556
+ enum: [
50557
+ "allow",
50558
+ "approve",
50559
+ "deny",
50560
+ "block",
50561
+ "ask"
50562
+ ]
50563
+ },
50564
+ reason: {
50565
+ type: "string"
50566
+ },
50567
+ hookSpecificOutput: {
50568
+ allOf: [
50569
+ {
50570
+ $ref: "#/definitions/Specific"
50571
+ }
50572
+ ]
50573
+ }
50574
+ }
50575
+ },
50576
+ PostToolUse: {
50577
+ title: "Qwen Code 0.26.7 PostToolUse reply",
50578
+ definitions: {
50579
+ Specific: {
50580
+ type: "object",
50581
+ additionalProperties: false,
50582
+ properties: {
50583
+ hookEventName: {
50584
+ type: "string",
50585
+ const: "PostToolUse"
50586
+ },
50587
+ additionalContext: {
50588
+ type: "string"
50589
+ }
50590
+ },
50591
+ required: [
50592
+ "hookEventName"
50593
+ ]
50594
+ }
50595
+ },
50596
+ type: "object",
50597
+ additionalProperties: false,
50598
+ properties: {
50599
+ continue: {
50600
+ type: "boolean"
50601
+ },
50602
+ stopReason: {
50603
+ type: "string"
50604
+ },
50605
+ suppressOutput: {
50606
+ type: "boolean"
50607
+ },
50608
+ systemMessage: {
50609
+ type: "string"
50610
+ },
50611
+ decision: {
50612
+ type: "string",
50613
+ enum: [
50614
+ "allow",
50615
+ "approve",
50616
+ "deny",
50617
+ "block",
50618
+ "ask"
50619
+ ]
50620
+ },
50621
+ reason: {
50622
+ type: "string"
50623
+ },
50624
+ hookSpecificOutput: {
50625
+ allOf: [
50626
+ {
50627
+ $ref: "#/definitions/Specific"
50628
+ }
50629
+ ]
50630
+ }
50631
+ }
50632
+ },
50633
+ UserPromptSubmit: {
50634
+ title: "Qwen Code 0.26.7 UserPromptSubmit reply",
50635
+ definitions: {
50636
+ Specific: {
50637
+ type: "object",
50638
+ additionalProperties: false,
50639
+ properties: {
50640
+ hookEventName: {
50641
+ type: "string",
50642
+ const: "UserPromptSubmit"
50643
+ },
50644
+ additionalContext: {
50645
+ type: "string"
50646
+ }
50647
+ },
50648
+ required: [
50649
+ "hookEventName"
50650
+ ]
50651
+ }
50652
+ },
50653
+ type: "object",
50654
+ additionalProperties: false,
50655
+ properties: {
50656
+ continue: {
50657
+ type: "boolean"
50658
+ },
50659
+ stopReason: {
50660
+ type: "string"
50661
+ },
50662
+ suppressOutput: {
50663
+ type: "boolean"
50664
+ },
50665
+ systemMessage: {
50666
+ type: "string"
50667
+ },
50668
+ decision: {
50669
+ type: "string",
50670
+ enum: [
50671
+ "allow",
50672
+ "approve",
50673
+ "deny",
50674
+ "block",
50675
+ "ask"
50676
+ ]
50677
+ },
50678
+ reason: {
50679
+ type: "string"
50680
+ },
50681
+ hookSpecificOutput: {
50682
+ allOf: [
50683
+ {
50684
+ $ref: "#/definitions/Specific"
50685
+ }
50686
+ ]
50687
+ }
50688
+ }
50689
+ },
50690
+ SessionStart: {
50691
+ title: "Qwen Code 0.26.7 SessionStart reply",
50692
+ definitions: {
50693
+ Specific: {
50694
+ type: "object",
50695
+ additionalProperties: false,
50696
+ properties: {
50697
+ hookEventName: {
50698
+ type: "string",
50699
+ const: "SessionStart"
50700
+ },
50701
+ additionalContext: {
50702
+ type: "string"
50703
+ }
50704
+ },
50705
+ required: [
50706
+ "hookEventName"
50707
+ ]
50708
+ }
50709
+ },
50710
+ type: "object",
50711
+ additionalProperties: false,
50712
+ properties: {
50713
+ continue: {
50714
+ type: "boolean"
50715
+ },
50716
+ stopReason: {
50717
+ type: "string"
50718
+ },
50719
+ suppressOutput: {
50720
+ type: "boolean"
50721
+ },
50722
+ systemMessage: {
50723
+ type: "string"
50724
+ },
50725
+ decision: {
50726
+ type: "string",
50727
+ enum: [
50728
+ "allow",
50729
+ "approve",
50730
+ "deny",
50731
+ "block",
50732
+ "ask"
50733
+ ]
50734
+ },
50735
+ reason: {
50736
+ type: "string"
50737
+ },
50738
+ hookSpecificOutput: {
50739
+ allOf: [
50740
+ {
50741
+ $ref: "#/definitions/Specific"
50742
+ }
50743
+ ]
50744
+ }
50745
+ }
50746
+ }
50747
+ }
50748
+ };
50749
+
50750
+ // tests/fixtures/host-schemas/copilot-cli.json
50751
+ var copilot_cli_default = {
50752
+ host: "copilot-cli",
50753
+ source: "GitHub Copilot CLI 1.0.105 copilot-sdk/types.d.ts: PreToolUseHookOutput, PostToolUseHookOutput (modifiedResult: ToolResultObject, ToolResultType), UserPromptSubmittedHookOutput, SessionStartHookOutput. Replies are flat objects with no hookSpecificOutput.",
50754
+ output: {
50755
+ PreToolUse: {
50756
+ title: "Copilot CLI 1.0.105 preToolUse reply",
50757
+ type: "object",
50758
+ additionalProperties: false,
50759
+ properties: {
50760
+ permissionDecision: {
50761
+ type: "string",
50762
+ enum: [
50763
+ "allow",
50764
+ "deny",
50765
+ "ask"
50766
+ ]
50767
+ },
50768
+ permissionDecisionReason: {
50769
+ type: "string"
50770
+ },
50771
+ modifiedArgs: {
50772
+ description: "unknown"
50773
+ },
50774
+ additionalContext: {
50775
+ type: "string"
50776
+ },
50777
+ suppressOutput: {
50778
+ type: "boolean"
50779
+ }
50780
+ }
50781
+ },
50782
+ PostToolUse: {
50783
+ title: "Copilot CLI 1.0.105 postToolUse reply",
50784
+ definitions: {
50785
+ ToolResultObject: {
50786
+ type: "object",
50787
+ additionalProperties: false,
50788
+ properties: {
50789
+ textResultForLlm: {
50790
+ type: "string"
50791
+ },
50792
+ binaryResultsForLlm: {
50793
+ type: "array",
50794
+ items: {
50795
+ type: "object"
50796
+ }
50797
+ },
50798
+ resultType: {
50799
+ type: "string",
50800
+ enum: [
50801
+ "success",
50802
+ "failure",
50803
+ "rejected",
50804
+ "denied",
50805
+ "timeout"
50806
+ ]
50807
+ },
50808
+ error: {
50809
+ type: "string"
50810
+ },
50811
+ sessionLog: {
50812
+ type: "string"
50813
+ },
50814
+ toolTelemetry: {
50815
+ type: "object"
50816
+ },
50817
+ toolReferences: {
50818
+ type: "array",
50819
+ items: {
50820
+ type: "string"
50821
+ }
50822
+ }
50823
+ },
50824
+ required: [
50825
+ "textResultForLlm",
50826
+ "resultType"
50827
+ ]
50828
+ }
50829
+ },
50830
+ type: "object",
50831
+ additionalProperties: false,
50832
+ properties: {
50833
+ modifiedResult: {
50834
+ allOf: [
50835
+ {
50836
+ $ref: "#/definitions/ToolResultObject"
50837
+ }
50838
+ ]
50839
+ },
50840
+ additionalContext: {
50841
+ type: "string"
50842
+ },
50843
+ suppressOutput: {
50844
+ type: "boolean"
50845
+ }
50846
+ }
50847
+ },
50848
+ UserPromptSubmit: {
50849
+ title: "Copilot CLI 1.0.105 userPromptSubmitted reply",
50850
+ type: "object",
50851
+ additionalProperties: false,
50852
+ properties: {
50853
+ modifiedPrompt: {
50854
+ type: "string"
50855
+ },
50856
+ additionalContext: {
50857
+ type: "string"
50858
+ },
50859
+ suppressOutput: {
50860
+ type: "boolean"
50861
+ },
50862
+ decision: {
50863
+ type: "string",
50864
+ const: "block"
50865
+ },
50866
+ reason: {
50867
+ type: "string"
50868
+ }
50869
+ }
50870
+ },
50871
+ SessionStart: {
50872
+ title: "Copilot CLI 1.0.105 sessionStart reply",
50873
+ type: "object",
50874
+ additionalProperties: false,
50875
+ properties: {
50876
+ additionalContext: {
50877
+ type: "string"
50878
+ },
50879
+ modifiedConfig: {
50880
+ type: "object"
50881
+ }
50882
+ }
50883
+ }
50884
+ }
50885
+ };
50886
+
50887
+ // tests/fixtures/host-schemas/vscode.json
50888
+ var vscode_default = {
50889
+ host: "vscode",
50890
+ source: "VS Code Copilot Chat 0.44.0 (5863f5a) src/platform/chat/common/hookCommandTypes.ts (IPreToolUseHookSpecificCommandOutput, IPostToolUseHookSpecificCommandOutput) and chatHookService.ts (UserPromptSubmitHookOutput, SessionStartHookOutput, IPostToolUseHookResult decision 'block').",
50891
+ output: {
50892
+ PreToolUse: {
50893
+ title: "VS Code Copilot Chat 0.44.0 PreToolUse reply",
50894
+ definitions: {
50895
+ Specific: {
50896
+ type: "object",
50897
+ additionalProperties: false,
50898
+ properties: {
50899
+ hookEventName: {
50900
+ type: "string"
50901
+ },
50902
+ permissionDecision: {
50903
+ type: "string",
50904
+ enum: [
50905
+ "allow",
50906
+ "deny",
50907
+ "ask"
50908
+ ]
50909
+ },
50910
+ permissionDecisionReason: {
50911
+ type: "string"
50912
+ },
50913
+ updatedInput: {
50914
+ type: "object"
50915
+ },
50916
+ additionalContext: {
50917
+ type: "string"
50918
+ }
50919
+ }
50920
+ }
50921
+ },
50922
+ type: "object",
50923
+ additionalProperties: false,
50924
+ properties: {
50925
+ hookSpecificOutput: {
50926
+ allOf: [
50927
+ {
50928
+ $ref: "#/definitions/Specific"
50929
+ }
50930
+ ]
50931
+ }
50932
+ }
50933
+ },
50934
+ PostToolUse: {
50935
+ title: "VS Code Copilot Chat 0.44.0 PostToolUse reply",
50936
+ definitions: {
50937
+ Specific: {
50938
+ type: "object",
50939
+ additionalProperties: false,
50940
+ properties: {
50941
+ hookEventName: {
50942
+ type: "string"
50943
+ },
50944
+ additionalContext: {
50945
+ type: "string"
50946
+ }
50947
+ }
50948
+ }
50949
+ },
50950
+ type: "object",
50951
+ additionalProperties: false,
50952
+ properties: {
50953
+ decision: {
50954
+ type: "string",
50955
+ const: "block"
50956
+ },
50957
+ reason: {
50958
+ type: "string"
50959
+ },
50960
+ hookSpecificOutput: {
50961
+ allOf: [
50962
+ {
50963
+ $ref: "#/definitions/Specific"
50964
+ }
50965
+ ]
50966
+ }
50967
+ }
50968
+ },
50969
+ UserPromptSubmit: {
50970
+ title: "VS Code Copilot Chat 0.44.0 UserPromptSubmit reply",
50971
+ definitions: {
50972
+ Specific: {
50973
+ type: "object",
50974
+ additionalProperties: false,
50975
+ properties: {
50976
+ hookEventName: {
50977
+ type: "string"
50978
+ },
50979
+ additionalContext: {
50980
+ type: "string"
50981
+ }
50982
+ }
50983
+ }
50984
+ },
50985
+ type: "object",
50986
+ additionalProperties: false,
50987
+ properties: {
50988
+ decision: {
50989
+ type: "string",
50990
+ const: "block"
50991
+ },
50992
+ reason: {
50993
+ type: "string"
50994
+ },
50995
+ hookSpecificOutput: {
50996
+ allOf: [
50997
+ {
50998
+ $ref: "#/definitions/Specific"
50999
+ }
51000
+ ]
51001
+ }
51002
+ }
51003
+ },
51004
+ SessionStart: {
51005
+ title: "VS Code Copilot Chat 0.44.0 SessionStart reply",
51006
+ definitions: {
51007
+ Specific: {
51008
+ type: "object",
51009
+ additionalProperties: false,
51010
+ properties: {
51011
+ hookEventName: {
51012
+ type: "string"
51013
+ },
51014
+ additionalContext: {
51015
+ type: "string"
51016
+ }
51017
+ }
51018
+ }
51019
+ },
51020
+ type: "object",
51021
+ additionalProperties: false,
51022
+ properties: {
51023
+ hookSpecificOutput: {
51024
+ allOf: [
51025
+ {
51026
+ $ref: "#/definitions/Specific"
51027
+ }
51028
+ ]
51029
+ }
51030
+ }
51031
+ }
51032
+ }
51033
+ };
51034
+
51035
+ // tests/fixtures/host-schemas/kiro.json
51036
+ var kiro_default = {
51037
+ host: "kiro",
51038
+ source: "kiro-cli 3.0.0 (BUILD_HASH 21067db0a7cc, 2026-11-02), V3 engine KAS 3.0.0-e315409f JS bundle (acp-server.js, unpacked by `kiro-cli serve`)",
51039
+ mcpToolId: {
51040
+ from: "function uel(server, tool): r = server + '_' + tool; r = r.replace(/[\\s-]/g, '_'); r = r.replace(/[^a-zA-Z0-9_]/g, ''); id = 'mcp_' + r.toLowerCase(); cut to 64 chars",
51041
+ prefix: "mcp_",
51042
+ join: "_",
51043
+ maxLength: 64
51044
+ },
51045
+ hookStdin: {
51046
+ from: "function sJn: {session_id, hook_event_name, cwd} plus per trigger fields",
51047
+ UserPromptSubmit: ["session_id", "hook_event_name", "cwd", "prompt"],
51048
+ PreToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input"],
51049
+ PostToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input", "tool_response"],
51050
+ SessionStart: ["session_id", "hook_event_name", "cwd"]
51051
+ },
51052
+ hookOutputCapChars: 3e3,
51053
+ windowsHookShell: "child_process.spawn(command, {shell: true}) in the V3 hook process runner (class tje): COMSPEC (cmd.exe /d /s /c) on win32",
51054
+ stdout: "text",
51055
+ output: {
51056
+ PreToolUse: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" },
51057
+ PostToolUse: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" },
51058
+ UserPromptSubmit: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" },
51059
+ SessionStart: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" }
51060
+ }
51061
+ };
51062
+
51063
+ // tests/fixtures/host-schemas/zcode.json
51064
+ var zcode_default = {
51065
+ host: "zcode",
51066
+ source: "ZCode 0.17.1 (a9fe401e) apps/zcode-cli/packages/contracts/src/hooks/index.ts: HookJSONOutputSchema and HookSpecificOutputSchema (zod discriminatedUnion on hookEventName). zod drops keys it does not read, so each object lists only the keys the host reads.",
51067
+ output: {
51068
+ PreToolUse: {
51069
+ title: "ZCode 0.17.1 PreToolUse reply",
51070
+ definitions: {
51071
+ Specific: {
51072
+ type: "object",
51073
+ additionalProperties: false,
51074
+ properties: {
51075
+ additionalContext: {
51076
+ type: "string"
51077
+ },
51078
+ hookEventName: {
51079
+ type: "string",
51080
+ const: "PreToolUse"
51081
+ },
51082
+ permissionDecision: {
51083
+ type: "string",
51084
+ enum: [
51085
+ "allow",
51086
+ "ask",
51087
+ "deny"
51088
+ ]
51089
+ },
51090
+ permissionDecisionReason: {
51091
+ type: "string"
51092
+ },
51093
+ updatedInput: {
51094
+ description: "z.unknown()"
51095
+ }
51096
+ },
51097
+ required: [
51098
+ "hookEventName"
51099
+ ]
51100
+ }
51101
+ },
51102
+ type: "object",
51103
+ additionalProperties: false,
51104
+ properties: {
51105
+ additionalContext: {
51106
+ type: "string"
51107
+ },
51108
+ additional_context: {
51109
+ type: "string"
51110
+ },
51111
+ continue: {
51112
+ type: "boolean"
51113
+ },
51114
+ decision: {
51115
+ type: "string",
51116
+ enum: [
51117
+ "approve",
51118
+ "block"
51119
+ ]
51120
+ },
51121
+ reason: {
51122
+ type: "string"
51123
+ },
51124
+ stopReason: {
51125
+ type: "string"
51126
+ },
51127
+ suppressOutput: {
51128
+ type: "boolean"
51129
+ },
51130
+ systemMessage: {
51131
+ type: "string"
51132
+ },
51133
+ hookSpecificOutput: {
51134
+ allOf: [
51135
+ {
51136
+ $ref: "#/definitions/Specific"
51137
+ }
51138
+ ]
51139
+ }
51140
+ }
51141
+ },
51142
+ PostToolUse: {
51143
+ title: "ZCode 0.17.1 PostToolUse reply",
51144
+ definitions: {
51145
+ Specific: {
51146
+ type: "object",
51147
+ additionalProperties: false,
51148
+ properties: {
51149
+ additionalContext: {
51150
+ type: "string"
51151
+ },
51152
+ hookEventName: {
51153
+ type: "string",
51154
+ const: "PostToolUse"
51155
+ }
51156
+ },
51157
+ required: [
51158
+ "hookEventName"
51159
+ ]
51160
+ }
51161
+ },
51162
+ type: "object",
51163
+ additionalProperties: false,
51164
+ properties: {
51165
+ additionalContext: {
51166
+ type: "string"
51167
+ },
51168
+ additional_context: {
51169
+ type: "string"
51170
+ },
51171
+ continue: {
51172
+ type: "boolean"
51173
+ },
51174
+ decision: {
51175
+ type: "string",
51176
+ enum: [
51177
+ "approve",
51178
+ "block"
51179
+ ]
51180
+ },
51181
+ reason: {
51182
+ type: "string"
51183
+ },
51184
+ stopReason: {
51185
+ type: "string"
51186
+ },
51187
+ suppressOutput: {
51188
+ type: "boolean"
51189
+ },
51190
+ systemMessage: {
51191
+ type: "string"
51192
+ },
51193
+ hookSpecificOutput: {
51194
+ allOf: [
51195
+ {
51196
+ $ref: "#/definitions/Specific"
51197
+ }
51198
+ ]
51199
+ }
51200
+ }
51201
+ },
51202
+ UserPromptSubmit: {
51203
+ title: "ZCode 0.17.1 UserPromptSubmit reply",
51204
+ definitions: {
51205
+ Specific: {
51206
+ type: "object",
51207
+ additionalProperties: false,
51208
+ properties: {
51209
+ additionalContext: {
51210
+ type: "string"
51211
+ },
51212
+ hookEventName: {
51213
+ type: "string",
51214
+ const: "UserPromptSubmit"
51215
+ }
51216
+ },
51217
+ required: [
51218
+ "hookEventName"
51219
+ ]
51220
+ }
51221
+ },
51222
+ type: "object",
51223
+ additionalProperties: false,
51224
+ properties: {
51225
+ additionalContext: {
51226
+ type: "string"
51227
+ },
51228
+ additional_context: {
51229
+ type: "string"
51230
+ },
51231
+ continue: {
51232
+ type: "boolean"
51233
+ },
51234
+ decision: {
51235
+ type: "string",
51236
+ enum: [
51237
+ "approve",
51238
+ "block"
51239
+ ]
51240
+ },
51241
+ reason: {
51242
+ type: "string"
51243
+ },
51244
+ stopReason: {
51245
+ type: "string"
51246
+ },
51247
+ suppressOutput: {
51248
+ type: "boolean"
51249
+ },
51250
+ systemMessage: {
51251
+ type: "string"
51252
+ },
51253
+ hookSpecificOutput: {
51254
+ allOf: [
51255
+ {
51256
+ $ref: "#/definitions/Specific"
51257
+ }
51258
+ ]
51259
+ }
51260
+ }
51261
+ },
51262
+ SessionStart: {
51263
+ title: "ZCode 0.17.1 SessionStart reply",
51264
+ definitions: {
51265
+ Specific: {
51266
+ type: "object",
51267
+ additionalProperties: false,
51268
+ properties: {
51269
+ additionalContext: {
51270
+ type: "string"
51271
+ },
51272
+ hookEventName: {
51273
+ type: "string",
51274
+ const: "SessionStart"
51275
+ }
51276
+ },
51277
+ required: [
51278
+ "hookEventName"
51279
+ ]
51280
+ }
51281
+ },
51282
+ type: "object",
51283
+ additionalProperties: false,
51284
+ properties: {
51285
+ additionalContext: {
51286
+ type: "string"
51287
+ },
51288
+ additional_context: {
51289
+ type: "string"
51290
+ },
51291
+ continue: {
51292
+ type: "boolean"
51293
+ },
51294
+ decision: {
51295
+ type: "string",
51296
+ enum: [
51297
+ "approve",
51298
+ "block"
51299
+ ]
51300
+ },
51301
+ reason: {
51302
+ type: "string"
51303
+ },
51304
+ stopReason: {
51305
+ type: "string"
51306
+ },
51307
+ suppressOutput: {
51308
+ type: "boolean"
51309
+ },
51310
+ systemMessage: {
51311
+ type: "string"
51312
+ },
51313
+ hookSpecificOutput: {
51314
+ allOf: [
51315
+ {
51316
+ $ref: "#/definitions/Specific"
51317
+ }
51318
+ ]
51319
+ }
51320
+ }
51321
+ }
51322
+ }
51323
+ };
51324
+
51325
+ // tests/fixtures/host-schemas/pi.json
51326
+ var pi_default = {
51327
+ host: "pi",
51328
+ source: "@earendil-works/pi-coding-agent 1.5.0 dist/core/extensions/types.d.ts (ToolCallEventResult {block, reason}, ToolResultEventResult content, BeforeAgentStartEventResult) and runner.js l.895-1010. The hook runs in process (src/entries/pi.ts): plain stdout becomes the reason, the replaced content or the added context; exit 2 blocks the tool call.",
51329
+ stdout: "text",
51330
+ output: {
51331
+ PreToolUse: {
51332
+ type: "string",
51333
+ description: "plain text read by src/entries/pi.ts"
51334
+ },
51335
+ PostToolUse: {
51336
+ type: "string",
51337
+ description: "plain text read by src/entries/pi.ts"
51338
+ },
51339
+ UserPromptSubmit: {
51340
+ type: "string",
51341
+ description: "plain text read by src/entries/pi.ts"
51342
+ },
51343
+ SessionStart: {
51344
+ type: "string",
51345
+ description: "plain text read by src/entries/pi.ts"
51346
+ }
51347
+ }
51348
+ };
51349
+
51350
+ // tests/fixtures/host-schemas/opencode.json
51351
+ var opencode_default = {
51352
+ host: "opencode",
51353
+ source: "@opencode/cli 2.2.5 plugin hooks (tool.execute.before throws to block, session hooks add text). The plugin runs the hook and reads plain stdout; exit 2 blocks the tool call with stdout as the reason.",
51354
+ stdout: "text",
51355
+ output: {
51356
+ PreToolUse: {
51357
+ type: "string",
51358
+ description: "plain text read by the context-mode OpenCode plugin"
51359
+ },
51360
+ PostToolUse: {
51361
+ type: "string",
51362
+ description: "plain text read by the context-mode OpenCode plugin"
51363
+ },
51364
+ UserPromptSubmit: {
51365
+ type: "string",
51366
+ description: "plain text read by the context-mode OpenCode plugin"
51367
+ },
51368
+ SessionStart: {
51369
+ type: "string",
51370
+ description: "plain text read by the context-mode OpenCode plugin"
51371
+ }
51372
+ }
51373
+ };
51374
+
51375
+ // src/core/ops/hook-shape.ts
51376
+ var HOST_SHAPES = {
51377
+ "claude-code": claude_code_default,
51378
+ codex: codex_default,
51379
+ gemini: gemini_default,
51380
+ qwen: qwen_default,
51381
+ "copilot-cli": copilot_cli_default,
51382
+ vscode: vscode_default,
51383
+ kiro: kiro_default,
51384
+ zcode: zcode_default,
51385
+ pi: pi_default,
51386
+ opencode: opencode_default
51387
+ };
51388
+ var NOTE_KEYS = /* @__PURE__ */ new Set(["$schema", "title", "description", "definitions", "default"]);
51389
+ var RULE_KEYS = /* @__PURE__ */ new Set(["type", "enum", "const", "required", "properties", "additionalProperties", "items", "allOf", "$ref"]);
51390
+ function isObject5(v) {
51391
+ return typeof v === "object" && v !== null && !Array.isArray(v);
51392
+ }
51393
+ function typeOf(v) {
51394
+ if (v === null) return "null";
51395
+ if (Array.isArray(v)) return "array";
51396
+ return typeof v;
51397
+ }
51398
+ function hasType(v, t) {
51399
+ if (t === "integer") return Number.isInteger(v);
51400
+ return typeOf(v) === t;
51401
+ }
51402
+ function same(a, b) {
51403
+ return JSON.stringify(a) === JSON.stringify(b);
51404
+ }
51405
+ function resolve3(root, ref) {
51406
+ const parts = ref.split("/");
51407
+ if (parts[0] !== "#") throw new Error(`hook-shape: only local $ref is read, got ${ref}`);
51408
+ let at = root;
51409
+ for (const p of parts.slice(1)) at = isObject5(at) ? at[p] : void 0;
51410
+ if (!isObject5(at)) throw new Error(`hook-shape: $ref ${ref} names nothing`);
51411
+ return at;
51412
+ }
51413
+ function shapeErrors(schema, value, root = schema, at = "$") {
51414
+ for (const k of Object.keys(schema)) {
51415
+ if (!NOTE_KEYS.has(k) && !RULE_KEYS.has(k)) throw new Error(`hook-shape: keyword ${k} at ${at} is not read by the checker`);
51416
+ }
51417
+ const errs = [];
51418
+ if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve3(root, schema.$ref), value, root, at));
51419
+ if (Array.isArray(schema.allOf)) for (const s of schema.allOf) errs.push(...shapeErrors(s, value, root, at));
51420
+ if (schema.type !== void 0) {
51421
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
51422
+ if (!types.some((t) => hasType(value, String(t)))) return [...errs, `${at}: ${typeOf(value)} is not ${types.join(" or ")}`];
51423
+ }
51424
+ if (Array.isArray(schema.enum) && !schema.enum.some((e) => same(e, value))) errs.push(`${at}: ${JSON.stringify(value)} is not one of ${JSON.stringify(schema.enum)}`);
51425
+ if (Object.hasOwn(schema, "const") && !same(schema.const, value)) errs.push(`${at}: ${JSON.stringify(value)} is not ${JSON.stringify(schema.const)}`);
51426
+ if (isObject5(value)) {
51427
+ const props = isObject5(schema.properties) ? schema.properties : {};
51428
+ if (Array.isArray(schema.required)) {
51429
+ for (const r of schema.required) if (!Object.hasOwn(value, String(r))) errs.push(`${at}: ${String(r)} is required`);
51430
+ }
51431
+ for (const [k, v] of Object.entries(value)) {
51432
+ if (Object.hasOwn(props, k)) errs.push(...shapeErrors(props[k], v, root, `${at}.${k}`));
51433
+ else if (schema.additionalProperties === false) errs.push(`${at}: ${k} is not a known key`);
51434
+ else if (isObject5(schema.additionalProperties)) errs.push(...shapeErrors(schema.additionalProperties, v, root, `${at}.${k}`));
51435
+ }
51436
+ }
51437
+ if (Array.isArray(value) && isObject5(schema.items)) {
51438
+ const items = schema.items;
51439
+ value.forEach((v, n) => errs.push(...shapeErrors(items, v, root, `${at}[${n}]`)));
51440
+ }
51441
+ return errs;
51442
+ }
51443
+ function replyErrors(agent, event, stdout) {
51444
+ const host = HOST_SHAPES[agent];
51445
+ const schema = host.output[event];
51446
+ if (schema === void 0) return [`${agent} has no ${event} reply schema`];
51447
+ if (host.stdout === "text") return shapeErrors(schema, stdout);
51448
+ let value;
51449
+ try {
51450
+ value = JSON.parse(stdout);
51451
+ } catch {
51452
+ return [`${agent} ${event}: stdout is not JSON`];
51453
+ }
51454
+ return shapeErrors(schema, value);
51455
+ }
51456
+
49541
51457
  // src/core/sandbox/host-node.ts
49542
51458
  var BUN_BE_BUN_ENV = "BUN_BE_BUN";
49543
51459
  function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
@@ -49549,7 +51465,7 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
49549
51465
 
49550
51466
  // src/setup/codex-trust.ts
49551
51467
  import { createHash } from "node:crypto";
49552
- import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
51468
+ import { existsSync as existsSync13, realpathSync as realpathSync7 } from "node:fs";
49553
51469
  import path6 from "node:path";
49554
51470
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
49555
51471
 
@@ -49666,14 +51582,14 @@ function pluginHooksFromReply(m, pluginId) {
49666
51582
  function askPluginHooks(env, pluginId, cwd) {
49667
51583
  const bin = whichBin("codex", env);
49668
51584
  if (!bin) return Promise.resolve({ kind: "absent" });
49669
- return new Promise((resolve6) => {
51585
+ return new Promise((resolve7) => {
49670
51586
  let asked;
49671
51587
  const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
49672
51588
  let f;
49673
51589
  try {
49674
51590
  f = spawnForm(bin, ["app-server"], env);
49675
51591
  } catch {
49676
- resolve6({ kind: "silent" });
51592
+ resolve7({ kind: "silent" });
49677
51593
  return;
49678
51594
  }
49679
51595
  const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
@@ -49683,7 +51599,7 @@ function askPluginHooks(env, pluginId, cwd) {
49683
51599
  let result;
49684
51600
  const settle3 = () => {
49685
51601
  clearTimeout(grace);
49686
- resolve6(done_(result));
51602
+ resolve7(done_(result));
49687
51603
  };
49688
51604
  let grace;
49689
51605
  const finish2 = (v) => {
@@ -49767,22 +51683,22 @@ var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answ
49767
51683
  var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
49768
51684
  var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
49769
51685
  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 };
49770
- function isObject5(v) {
51686
+ function isObject6(v) {
49771
51687
  return typeof v === "object" && v !== null && !Array.isArray(v);
49772
51688
  }
49773
51689
  function loadFixture(bundleDir2, agent) {
49774
51690
  const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
49775
- if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
51691
+ if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
49776
51692
  let all;
49777
51693
  try {
49778
- all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
51694
+ all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
49779
51695
  } catch (err) {
49780
51696
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
49781
51697
  }
49782
- if (!isObject5(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
51698
+ if (!isObject6(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
49783
51699
  if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
49784
51700
  const e = all[agent];
49785
- if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
51701
+ if (!isObject6(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
49786
51702
  return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
49787
51703
  }
49788
51704
  return { event: e.event, payload: e.payload };
@@ -49800,39 +51716,11 @@ var CWD_KEY = {
49800
51716
  opencode: "directory"
49801
51717
  };
49802
51718
  function payloadFor(agent, payload, worktree) {
49803
- return worktree !== void 0 && isObject5(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
49804
- }
49805
- var SHAPE = {
49806
- "claude-code": "claude",
49807
- codex: "claude",
49808
- qwen: "claude",
49809
- vscode: "claude",
49810
- zcode: "claude",
49811
- gemini: "gemini",
49812
- "copilot-cli": "copilot",
49813
- kiro: "text",
49814
- pi: "text",
49815
- opencode: "text"
49816
- };
49817
- var COPILOT_KEYS = ["permissionDecision", "additionalContext", "modifiedResult"];
51719
+ return worktree !== void 0 && isObject6(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
51720
+ }
49818
51721
  function isNativeShape(agent, stdout, exitCode, killed, event) {
49819
51722
  if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
49820
- if (stdout.length === 0 || SHAPE[agent] === "text") return true;
49821
- let out;
49822
- try {
49823
- out = JSON.parse(stdout);
49824
- } catch {
49825
- return false;
49826
- }
49827
- if (!isObject5(out)) return false;
49828
- switch (SHAPE[agent]) {
49829
- case "claude":
49830
- return isObject5(out.hookSpecificOutput) && out.hookSpecificOutput.hookEventName === event;
49831
- case "gemini":
49832
- return typeof out.decision === "string" || isObject5(out.hookSpecificOutput);
49833
- default:
49834
- return COPILOT_KEYS.some((k) => Object.hasOwn(out, k));
49835
- }
51723
+ return stdout.length === 0 || replyErrors(agent, event, stdout).length === 0;
49836
51724
  }
49837
51725
  var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
49838
51726
  function readProbePayload(cwd, ranged) {
@@ -49857,9 +51745,9 @@ function isReadShape(stdout) {
49857
51745
  } catch {
49858
51746
  return false;
49859
51747
  }
49860
- if (!isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
51748
+ if (!isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
49861
51749
  const r = out.hookSpecificOutput.updatedToolOutput;
49862
- if (!isObject5(r) || r.type !== "text" || !isObject5(r.file)) return false;
51750
+ if (!isObject6(r) || r.type !== "text" || !isObject6(r.file)) return false;
49863
51751
  const f = r.file;
49864
51752
  return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
49865
51753
  }
@@ -49887,13 +51775,84 @@ function isPassThrough(stdout) {
49887
51775
  } catch {
49888
51776
  return false;
49889
51777
  }
49890
- return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
51778
+ return !isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
51779
+ }
51780
+ var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
51781
+ async function mediaProbe(i, timeoutMs) {
51782
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
51783
+ try {
51784
+ const filePath = path7.join(home, "d5-media-probe.png");
51785
+ writeFileSync3(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
51786
+ const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
51787
+ const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
51788
+ cwd: i.bundleDir,
51789
+ env: node3.env,
51790
+ signal: i.signal,
51791
+ timeoutMs,
51792
+ stdin: JSON.stringify({
51793
+ session_id: "d5-media-probe",
51794
+ transcript_path: "",
51795
+ cwd: home,
51796
+ hook_event_name: "PreToolUse",
51797
+ tool_name: "Read",
51798
+ tool_use_id: "toolu_d5_media_probe",
51799
+ tool_input: { file_path: filePath }
51800
+ })
51801
+ });
51802
+ return r.stdout.toString("utf8");
51803
+ } finally {
51804
+ rmSync4(home, { recursive: true, force: true });
51805
+ }
51806
+ }
51807
+ async function ownProbe(i, timeoutMs) {
51808
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-own-"));
51809
+ try {
51810
+ const cfg = path7.join(home, ".claude");
51811
+ const refs = path7.join(cfg, "skills", "d5-probe", "references");
51812
+ mkdirSync5(refs, { recursive: true });
51813
+ const filePath = path7.join(refs, "d5-own-probe.md");
51814
+ writeFileSync3(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
51815
+ const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
51816
+ const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
51817
+ cwd: i.bundleDir,
51818
+ env: node3.env,
51819
+ signal: i.signal,
51820
+ timeoutMs,
51821
+ stdin: JSON.stringify({
51822
+ session_id: "d5-own-probe",
51823
+ transcript_path: "",
51824
+ cwd: home,
51825
+ hook_event_name: "PreToolUse",
51826
+ tool_name: "Read",
51827
+ tool_use_id: "toolu_d5_own_probe",
51828
+ tool_input: { file_path: filePath }
51829
+ })
51830
+ });
51831
+ return r.stdout.toString("utf8");
51832
+ } finally {
51833
+ rmSync4(home, { recursive: true, force: true });
51834
+ }
51835
+ }
51836
+ function isDeny(stdout) {
51837
+ if (stdout.trim() === "") return false;
51838
+ let out;
51839
+ try {
51840
+ out = JSON.parse(stdout);
51841
+ } catch {
51842
+ return false;
51843
+ }
51844
+ return isObject6(out) && isObject6(out.hookSpecificOutput) && out.hookSpecificOutput.permissionDecision === "deny";
49891
51845
  }
49892
51846
  async function readProbeDetail(i, timeoutMs) {
49893
51847
  if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
49894
51848
  if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
51849
+ if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
51850
+ if (isDeny(await ownProbe(i, timeoutMs))) return D5_READ_OWN_DETAIL;
49895
51851
  return null;
49896
51852
  }
51853
+ async function mediaProbeDetail(i, timeoutMs) {
51854
+ return isDeny(await mediaProbe(i, timeoutMs)) ? D5_READ_MEDIA_DETAIL : null;
51855
+ }
49897
51856
  function codexHookJournaled(db) {
49898
51857
  if (db === null) return false;
49899
51858
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
@@ -49922,12 +51881,42 @@ async function codexPluginTrust(i) {
49922
51881
  if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
49923
51882
  return null;
49924
51883
  }
51884
+ function codexStopPayload(cwd) {
51885
+ return {
51886
+ session_id: "d5-stop-probe",
51887
+ turn_id: "d5-stop-turn",
51888
+ transcript_path: null,
51889
+ cwd,
51890
+ hook_event_name: "Stop",
51891
+ model: "d5-probe",
51892
+ permission_mode: "default",
51893
+ stop_hook_active: false,
51894
+ last_assistant_message: "d5 stop probe"
51895
+ };
51896
+ }
51897
+ async function codexStopDetail(i, timeoutMs) {
51898
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-stop-"));
51899
+ try {
51900
+ const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, [DATA_DIR_ENV]: home });
51901
+ const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
51902
+ cwd: i.bundleDir,
51903
+ env: node3.env,
51904
+ signal: i.signal,
51905
+ timeoutMs,
51906
+ stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
51907
+ });
51908
+ const logged = existsSync14(path7.join(home, HOOK_ERROR_LOG_FILE));
51909
+ return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
51910
+ } finally {
51911
+ rmSync4(home, { recursive: true, force: true });
51912
+ }
51913
+ }
49925
51914
  async function checkHookRoundTrip(i) {
49926
51915
  if (i.agent === "codex") {
49927
51916
  const trust = await codexPluginTrust(i);
49928
51917
  if (trust !== null) return trust;
49929
51918
  }
49930
- if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
51919
+ if (i.agent === "codex" && existsSync14(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
49931
51920
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
49932
51921
  }
49933
51922
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -49963,22 +51952,31 @@ async function checkHookRoundTrip(i) {
49963
51952
  if (n >= minPairs && ms <= HOOK_P95_MS) break;
49964
51953
  }
49965
51954
  if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
49966
- const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
51955
+ const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "zcode" ? await mediaProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
49967
51956
  if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
49968
51957
  return row("PASS", DOCTOR_PASS_DETAIL);
49969
51958
  }
49970
51959
 
49971
51960
  // src/core/hooks/fallback.ts
49972
- import { join as join13, resolve as resolve3 } from "node:path";
51961
+ import { join as join14, resolve as resolve4 } from "node:path";
51962
+
51963
+ // src/core/policy/read-media.ts
51964
+ import { extname } from "node:path";
51965
+ var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
51966
+
51967
+ // src/core/policy/own-file.ts
51968
+ import { extname as extname2, join as join13 } from "node:path";
51969
+
51970
+ // src/core/hooks/fallback.ts
49973
51971
  var fs = process.getBuiltinModule("node:fs");
49974
51972
  function homeOf(env) {
49975
51973
  return env.HOME ?? env.USERPROFILE ?? "";
49976
51974
  }
49977
51975
  function hookLogPath(env) {
49978
51976
  const dir = env[DATA_DIR_ENV];
49979
- if (dir !== void 0 && dir !== "") return join13(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
51977
+ if (dir !== void 0 && dir !== "") return join14(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
49980
51978
  const home = homeOf(env);
49981
- return home === "" ? "" : join13(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
51979
+ return home === "" ? "" : join14(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
49982
51980
  }
49983
51981
  function lastHookError(env) {
49984
51982
  try {
@@ -50008,8 +52006,8 @@ function lastHookError(env) {
50008
52006
  }
50009
52007
 
50010
52008
  // src/core/ops/db-heal.ts
50011
- import { existsSync as existsSync14, mkdirSync as mkdirSync5, rmSync as rmSync5 } from "node:fs";
50012
- import { basename as basename4, dirname as dirname7, join as join14 } from "node:path";
52009
+ import { existsSync as existsSync15, mkdirSync as mkdirSync6, rmSync as rmSync5 } from "node:fs";
52010
+ import { basename as basename4, dirname as dirname7, join as join15 } from "node:path";
50013
52011
  function integrityOk2(rows) {
50014
52012
  return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
50015
52013
  }
@@ -50043,7 +52041,7 @@ function renameAside(dbPath) {
50043
52041
  const ts = String(Date.now());
50044
52042
  for (const suffix of DB_SIBLING_SUFFIXES) {
50045
52043
  const file2 = dbPath + suffix;
50046
- if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
52044
+ if (existsSync15(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
50047
52045
  }
50048
52046
  return ts;
50049
52047
  }
@@ -50066,11 +52064,11 @@ function utcStamp(now) {
50066
52064
  return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
50067
52065
  }
50068
52066
  function makeOrphanDir(projectDir) {
50069
- const base = join14(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
52067
+ const base = join15(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
50070
52068
  for (let n = 1; ; n += 1) {
50071
52069
  const dir = n === 1 ? base : base + "-" + String(n);
50072
52070
  try {
50073
- mkdirSync5(dir);
52071
+ mkdirSync6(dir);
50074
52072
  return dir;
50075
52073
  } catch (err) {
50076
52074
  if (err.code !== "EEXIST") throw err;
@@ -50083,7 +52081,7 @@ async function healOrphan(project, files, row5) {
50083
52081
  try {
50084
52082
  dir = makeOrphanDir(dirname7(project.dbPath));
50085
52083
  for (const f of files) {
50086
- const to = join14(dir, basename4(f.path));
52084
+ const to = join15(dir, basename4(f.path));
50087
52085
  renameWithRetry(f.path, to);
50088
52086
  moved.push({ path: to, bytes: f.bytes });
50089
52087
  }
@@ -50150,8 +52148,8 @@ function buildReportHead(input) {
50150
52148
 
50151
52149
  // src/core/ops/doctor-issue.ts
50152
52150
  import { spawnSync as spawnSync3 } from "node:child_process";
50153
- import { closeSync, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync10, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
50154
- import { delimiter, join as join15 } from "node:path";
52151
+ import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync11, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
52152
+ import { delimiter, join as join16 } from "node:path";
50155
52153
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
50156
52154
  function tildeOf(env) {
50157
52155
  const home = homeDirOf(env);
@@ -50192,8 +52190,8 @@ function onPath(env, tool) {
50192
52190
  const out = [];
50193
52191
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
50194
52192
  if (dir === "") continue;
50195
- for (const n of names) if (existsSync15(join15(dir, n))) {
50196
- out.push(join15(dir, n));
52193
+ for (const n of names) if (existsSync16(join16(dir, n))) {
52194
+ out.push(join16(dir, n));
50197
52195
  break;
50198
52196
  }
50199
52197
  }
@@ -50201,19 +52199,19 @@ function onPath(env, tool) {
50201
52199
  }
50202
52200
  function hookLogTail(env) {
50203
52201
  const file2 = hookLogPath(env);
50204
- if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
52202
+ if (file2 === "" || !existsSync16(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
50205
52203
  try {
50206
- const fd = openSync(file2, "r");
52204
+ const fd = openSync2(file2, "r");
50207
52205
  try {
50208
52206
  const size = fstatSync(fd).size;
50209
52207
  const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
50210
52208
  const buf = Buffer.alloc(size - start);
50211
- readSync(fd, buf, 0, buf.length, start);
52209
+ readSync2(fd, buf, 0, buf.length, start);
50212
52210
  const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
50213
52211
  if (start > 0) lines.shift();
50214
52212
  return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
50215
52213
  } finally {
50216
- closeSync(fd);
52214
+ closeSync2(fd);
50217
52215
  }
50218
52216
  } catch (err) {
50219
52217
  return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
@@ -50221,7 +52219,7 @@ function hookLogTail(env) {
50221
52219
  }
50222
52220
  async function journalRows(ctx) {
50223
52221
  const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
50224
- if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
52222
+ if (!existsSync16(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
50225
52223
  try {
50226
52224
  const db = await openDb(ctx.project, { readOnly: true });
50227
52225
  try {
@@ -50239,21 +52237,21 @@ function agentConfig(adapter, env, worktree) {
50239
52237
  const home = homeDirOf(env);
50240
52238
  const files = configPaths(adapter, env, worktree);
50241
52239
  if (home !== null) {
50242
- if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join15(claudeDirOf(env, home), SETTINGS_FILE) });
50243
- if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join15(codexDirOf(env, home), CONFIG_TOML_FILE) });
52240
+ if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join16(claudeDirOf(env, home), SETTINGS_FILE) });
52241
+ if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join16(codexDirOf(env, home), CONFIG_TOML_FILE) });
50244
52242
  }
50245
52243
  const out = [];
50246
52244
  const seen = /* @__PURE__ */ new Set();
50247
52245
  for (const f of files) {
50248
52246
  if (seen.has(f.path)) continue;
50249
52247
  seen.add(f.path);
50250
- if (!existsSync15(f.path)) {
52248
+ if (!existsSync16(f.path)) {
50251
52249
  out.push(`${f.label}: ${f.path} (absent)`);
50252
52250
  continue;
50253
52251
  }
50254
52252
  let text = "";
50255
52253
  try {
50256
- text = readFileSync10(f.path, "utf8");
52254
+ text = readFileSync11(f.path, "utf8");
50257
52255
  } catch (err) {
50258
52256
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
50259
52257
  continue;
@@ -50323,10 +52321,10 @@ async function buildIssueBody(i) {
50323
52321
  async function writeIssueReport(i) {
50324
52322
  const tilde = tildeOf(i.env);
50325
52323
  const body = await buildIssueBody(i);
50326
- const dir = join15(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
50327
- mkdirSync6(dir, { recursive: true });
50328
- const file2 = join15(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
50329
- writeFileSync3(file2, body);
52324
+ const dir = join16(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
52325
+ mkdirSync7(dir, { recursive: true });
52326
+ const file2 = join16(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
52327
+ writeFileSync4(file2, body);
50330
52328
  const shown2 = tilde(file2);
50331
52329
  const title = issueTitle(i.adapter.id, i.rows);
50332
52330
  const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
@@ -50371,7 +52369,7 @@ async function guard(id, run) {
50371
52369
  }
50372
52370
  }
50373
52371
  async function codexDb(ctx, adapter) {
50374
- if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
52372
+ if (adapter.id !== "codex" || !existsSync17(ctx.project.dbPath)) return null;
50375
52373
  try {
50376
52374
  return await openDb(ctx.project, { readOnly: true });
50377
52375
  } catch {
@@ -50401,11 +52399,11 @@ async function hookRow(ctx, adapter, host) {
50401
52399
  }
50402
52400
  }
50403
52401
  function ownServerId(configDir, projectKey) {
50404
- const dir = join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
50405
- if (!existsSync16(dir)) return "";
50406
- for (const name of readdirSync7(dir)) {
52402
+ const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
52403
+ if (!existsSync17(dir)) return "";
52404
+ for (const name of readdirSync8(dir)) {
50407
52405
  if (!name.endsWith(OWNER_PID_EXT)) continue;
50408
- if (readFileSync11(join16(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
52406
+ if (readFileSync12(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
50409
52407
  }
50410
52408
  return "";
50411
52409
  }
@@ -50431,7 +52429,8 @@ async function runDoctorChecks(ctx, adapter, host0) {
50431
52429
  return r.row;
50432
52430
  },
50433
52431
  D9: () => checkIndex(project),
50434
- D10: () => checkMode(adapter),
52432
+ D10: () => checkMode(adapter, ctx.hostPermission),
52433
+ // D-1331-OC-PERM-1
50435
52434
  D11: () => checkShell(env)
50436
52435
  };
50437
52436
  const rows = [];
@@ -50500,9 +52499,9 @@ var ctxDoctor = Object.freeze({
50500
52499
  });
50501
52500
 
50502
52501
  // src/core/tools/execute.ts
50503
- import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
52502
+ import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "node:fs";
50504
52503
  import { tmpdir as tmpdir3 } from "node:os";
50505
- import { dirname as dirname9, join as join17, parse as parse5, resolve as resolve4 } from "node:path";
52504
+ import { dirname as dirname9, join as join18, parse as parse5, resolve as resolve5 } from "node:path";
50506
52505
 
50507
52506
  // src/core/index/select.ts
50508
52507
  var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
@@ -50624,7 +52623,7 @@ function schemaLine(issue4) {
50624
52623
  }
50625
52624
  function fileError(given, abs, root) {
50626
52625
  let dir = abs;
50627
- while (!existsSync17(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
52626
+ while (!existsSync18(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
50628
52627
  if (isInside(root, dir)) return null;
50629
52628
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
50630
52629
  }
@@ -50688,7 +52687,7 @@ async function handler3(raw, ctx) {
50688
52687
  const cwd = ctx.project.worktree;
50689
52688
  const extra = { ...PLAIN_OUTPUT_ENV2 };
50690
52689
  if (input.file !== void 0) {
50691
- const abs = resolve4(cwd, input.file);
52690
+ const abs = resolve5(cwd, input.file);
50692
52691
  const bad = fileError(input.file, abs, ctx.project.containmentRoot);
50693
52692
  if (bad !== null) return fail4(bad);
50694
52693
  extra.CTX_FILE = abs;
@@ -50705,9 +52704,9 @@ async function handler3(raw, ctx) {
50705
52704
  if (takesDashC(input.language, runtime)) {
50706
52705
  argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
50707
52706
  } else {
50708
- tmpDir = mkdtempSync2(join17(tmpdir3(), TMP_PREFIX));
50709
- const file2 = join17(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
50710
- writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
52707
+ tmpDir = mkdtempSync2(join18(tmpdir3(), TMP_PREFIX));
52708
+ const file2 = join18(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
52709
+ writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
50711
52710
  argv = scriptArgv(input.language, runtime, file2);
50712
52711
  }
50713
52712
  if (input.background === true) {
@@ -50742,12 +52741,12 @@ var ctxExecute = {
50742
52741
  };
50743
52742
 
50744
52743
  // src/core/tools/index.ts
50745
- import { existsSync as existsSync18, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
50746
- import { dirname as dirname10, extname, join as join19, relative as relative3, resolve as resolve5 } from "node:path";
52744
+ import { existsSync as existsSync19, readFileSync as readFileSync14, statSync as statSync7 } from "node:fs";
52745
+ import { dirname as dirname10, extname as extname3, join as join20, relative as relative3, resolve as resolve6 } from "node:path";
50747
52746
 
50748
52747
  // src/core/index/walk.ts
50749
- import { readdirSync as readdirSync8, readFileSync as readFileSync12, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
50750
- import { join as join18 } from "node:path";
52748
+ import { readdirSync as readdirSync9, readFileSync as readFileSync13, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
52749
+ import { join as join19 } from "node:path";
50751
52750
  var GITIGNORE = ".gitignore";
50752
52751
  var GIT_DIR = ".git";
50753
52752
  function walkDir(root, containmentRoot) {
@@ -50756,19 +52755,19 @@ function walkDir(root, containmentRoot) {
50756
52755
  const found = [];
50757
52756
  visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
50758
52757
  found.sort(compareFound);
50759
- return found.map((f) => ({ absPath: f.absPath, relPath: join18(...f.dir, f.name) }));
52758
+ return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
50760
52759
  }
50761
52760
  function visit(abs, rel, parent, contain, seen, found) {
50762
52761
  let entries;
50763
52762
  try {
50764
- entries = readdirSync8(abs, { withFileTypes: true });
52763
+ entries = readdirSync9(abs, { withFileTypes: true });
50765
52764
  } catch {
50766
52765
  return;
50767
52766
  }
50768
- const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join18(abs, GITIGNORE), rel)) : parent;
52767
+ const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
50769
52768
  for (const e of entries) {
50770
52769
  if (e.name === GIT_DIR) continue;
50771
- const path8 = join18(abs, e.name);
52770
+ const path8 = join19(abs, e.name);
50772
52771
  let isDir = e.isDirectory();
50773
52772
  let isFile = e.isFile();
50774
52773
  let target = path8;
@@ -50808,7 +52807,7 @@ function compareFound(a, b) {
50808
52807
  function readRules(file2, base) {
50809
52808
  let body;
50810
52809
  try {
50811
- body = readFileSync12(file2, "utf8");
52810
+ body = readFileSync13(file2, "utf8");
50812
52811
  } catch {
50813
52812
  return [];
50814
52813
  }
@@ -51030,18 +53029,18 @@ function request(u, conn, proxy, signal) {
51030
53029
  const host = bare(u.hostname);
51031
53030
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
51032
53031
  const path8 = u.pathname + u.search;
51033
- return new Promise((resolve6, reject) => {
53032
+ return new Promise((resolve7, reject) => {
51034
53033
  const onErr = (err) => reject(fail5(causeCode(err)));
51035
53034
  if (proxy === void 0) {
51036
53035
  const mod = u.protocol === "https:" ? https : http;
51037
53036
  const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
51038
- req.on("response", resolve6).on("error", onErr).end();
53037
+ req.on("response", resolve7).on("error", onErr).end();
51039
53038
  return;
51040
53039
  }
51041
53040
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
51042
53041
  if (u.protocol === "http:") {
51043
53042
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
51044
- req.on("response", resolve6).on("error", onErr).end();
53043
+ req.on("response", resolve7).on("error", onErr).end();
51045
53044
  return;
51046
53045
  }
51047
53046
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -51061,16 +53060,16 @@ function request(u, conn, proxy, signal) {
51061
53060
  headers: { host: u.host },
51062
53061
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
51063
53062
  });
51064
- req.on("response", resolve6).on("error", onErr).end();
53063
+ req.on("response", resolve7).on("error", onErr).end();
51065
53064
  });
51066
53065
  tunnel.end();
51067
53066
  });
51068
53067
  }
51069
53068
  function readBody(res) {
51070
- return new Promise((resolve6, reject) => {
53069
+ return new Promise((resolve7, reject) => {
51071
53070
  const parts = [];
51072
53071
  res.on("data", (b) => parts.push(b));
51073
- res.on("end", () => resolve6(Buffer.concat(parts)));
53072
+ res.on("end", () => resolve7(Buffer.concat(parts)));
51074
53073
  res.on("error", (err) => reject(fail5(causeCode(err))));
51075
53074
  res.on("aborted", () => reject(fail5("ECONNRESET")));
51076
53075
  });
@@ -54927,7 +56926,7 @@ function userLabel(label2) {
54927
56926
  return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
54928
56927
  }
54929
56928
  function kindOfPath(p) {
54930
- return EXT_KIND[extname(p).toLowerCase()] ?? "text";
56929
+ return EXT_KIND[extname3(p).toLowerCase()] ?? "text";
54931
56930
  }
54932
56931
  function kindOfType(contentType) {
54933
56932
  const semi = contentType.indexOf(";");
@@ -54936,25 +56935,25 @@ function kindOfType(contentType) {
54936
56935
  }
54937
56936
  function readUtf8(absPath) {
54938
56937
  try {
54939
- return utf8.decode(readFileSync13(absPath));
56938
+ return utf8.decode(readFileSync14(absPath));
54940
56939
  } catch {
54941
56940
  return void 0;
54942
56941
  }
54943
56942
  }
54944
56943
  function missingOrOutside(given, abs, root) {
54945
56944
  let dir = abs;
54946
- while (!existsSync18(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
56945
+ while (!existsSync19(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
54947
56946
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
54948
56947
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
54949
56948
  }
54950
56949
  function pathItems(input, project) {
54951
- const abs = resolve5(project.worktree, input.path);
56950
+ const abs = resolve6(project.worktree, input.path);
54952
56951
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
54953
56952
  const base = relative3(project.worktree, abs);
54954
56953
  if (statSync7(abs).isDirectory()) {
54955
56954
  return walkDir(abs, project.containmentRoot).map((f) => ({
54956
56955
  sourceKind: "path",
54957
- label: pathLabel(join19(base, f.relPath)),
56956
+ label: pathLabel(join20(base, f.relPath)),
54958
56957
  kind: kindOfPath(f.relPath),
54959
56958
  read: () => readUtf8(f.absPath)
54960
56959
  }));
@@ -55368,11 +57367,6 @@ function readLastPrompt(db, sessionId) {
55368
57367
  const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
55369
57368
  return row5 === void 0 ? "" : row5.body;
55370
57369
  }
55371
- function readFirstPrompt(db, sessionId) {
55372
- if (sessionId === "") return "";
55373
- const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq ASC LIMIT 1").get(sessionId);
55374
- return row5 === void 0 ? "" : row5.body;
55375
- }
55376
57370
 
55377
57371
  // src/core/tools/resume.ts
55378
57372
  var ctxResumeSchema = external_exports.object({
@@ -55398,9 +57392,8 @@ async function handler6(input, ctx) {
55398
57392
  const newest = rows.at(-1);
55399
57393
  if (newest === void 0) return reply3(RESUME_EMPTY_LINE, false);
55400
57394
  const sources = listSessionSources(db, sessionId, MAX_CANDIDATES).map((r) => "source " + sourceHandle(r.id) + ": " + r.label + " (" + r.bytes + " B)");
55401
- const goal = readFirstPrompt(db, sessionId);
55402
57395
  const last2 = readLastPrompt(db, sessionId);
55403
- const units = queryUnits(db, sessionId, recallQueryText(last2, goal), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
57396
+ const units = queryUnits(db, sessionId, recallQueryText(last2), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
55404
57397
  const block = renderState(rows, newest.turn, { sources, units });
55405
57398
  if (Buffer.byteLength(block, "utf8") > RESUME_CAP) throw new Error("ctx_resume: state block over RESUME_CAP (render bug).");
55406
57399
  return reply3(block, false);
@@ -55464,7 +57457,7 @@ function readWeek(raw, lastMs) {
55464
57457
  }
55465
57458
  return days;
55466
57459
  }
55467
- var EMPTY3 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
57460
+ var EMPTY4 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
55468
57461
  function totals(r) {
55469
57462
  const produced = Number(r.produced);
55470
57463
  const returned = Number(r.returned);
@@ -55504,7 +57497,7 @@ function sum(groups) {
55504
57497
  produced: t.produced + g.produced,
55505
57498
  returned: t.returned + g.returned,
55506
57499
  saved: t.saved + g.saved
55507
- }), EMPTY3);
57500
+ }), EMPTY4);
55508
57501
  }
55509
57502
  function reductionPct(t) {
55510
57503
  if (t.calls === 0) return 0;
@@ -55698,8 +57691,8 @@ function report(f, sessionId, agent) {
55698
57691
  ] : []
55699
57692
  ];
55700
57693
  const agents = /* @__PURE__ */ new Map();
55701
- for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY3, g]));
55702
- if (!agents.has(agent)) agents.set(agent, EMPTY3);
57694
+ for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY4, g]));
57695
+ if (!agents.has(agent)) agents.set(agent, EMPTY4);
55703
57696
  lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
55704
57697
  const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
55705
57698
  lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + right("Session", STATS_KIND_W) + right("Project", STATS_KIND_W));
@@ -55759,27 +57752,27 @@ var ctxStats = Object.freeze({
55759
57752
  });
55760
57753
 
55761
57754
  // src/core/ops/host-write.ts
55762
- import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
55763
- import { dirname as dirname11, join as join20 } from "node:path";
57755
+ import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
57756
+ import { dirname as dirname11, join as join21 } from "node:path";
55764
57757
  function defaultWrite(file2, text) {
55765
- writeFileSync5(file2, text, "utf8");
57758
+ writeFileSync6(file2, text, "utf8");
55766
57759
  }
55767
57760
  function hostConfigPath(agent, home, env) {
55768
57761
  const own4 = OWN_MCP_ENTRY[agent];
55769
57762
  if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
55770
57763
  switch (agent) {
55771
57764
  case "opencode":
55772
- return join20(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
57765
+ return join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
55773
57766
  // D-WIN-OPENCODE-DIR-1
55774
57767
  case "pi":
55775
- return join20(piAgentDirOf(env, home), SETTINGS_FILE);
57768
+ return join21(piAgentDirOf(env, home), SETTINGS_FILE);
55776
57769
  case "gemini":
55777
- return join20(geminiDirOf(env, home), SETTINGS_FILE);
57770
+ return join21(geminiDirOf(env, home), SETTINGS_FILE);
55778
57771
  // D-R38-GEMINI-HOME-1
55779
57772
  case "copilot-cli":
55780
57773
  return null;
55781
57774
  default:
55782
- return join20(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
57775
+ return join21(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
55783
57776
  }
55784
57777
  }
55785
57778
  function cell3(value) {
@@ -55791,8 +57784,8 @@ function toRow(file2, edit) {
55791
57784
  function writeWithRollback(file2, text, write, atomic) {
55792
57785
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
55793
57786
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
55794
- const had = existsSync19(file2);
55795
- mkdirSync7(dirname11(file2), { recursive: true });
57787
+ const had = existsSync20(file2);
57788
+ mkdirSync8(dirname11(file2), { recursive: true });
55796
57789
  if (had) copyFileSync(file2, trash);
55797
57790
  try {
55798
57791
  write(tmp, text);
@@ -55821,7 +57814,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
55821
57814
  if (requested === null) return [];
55822
57815
  const current = readHostConfig(row5.id, requested);
55823
57816
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
55824
- const exists = existsSync19(current.path);
57817
+ const exists = existsSync20(current.path);
55825
57818
  if (exists && result.text === current.text) return [];
55826
57819
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
55827
57820
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -55829,15 +57822,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
55829
57822
  }
55830
57823
 
55831
57824
  // src/core/ops/uninstall.ts
55832
- import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
55833
- import { join as join21 } from "node:path";
57825
+ import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync7, writeFileSync as writeFileSync7 } from "node:fs";
57826
+ import { join as join22 } from "node:path";
55834
57827
  function row2(area, before, after) {
55835
57828
  return { area, before, after };
55836
57829
  }
55837
57830
  function stopServers(configDir, projectKey) {
55838
57831
  const stopped = listLiveOwners(configDir, projectKey);
55839
- const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
55840
- for (const serverId of stopped) writeFileSync6(join21(dir, serverId + OWNER_STOP_EXT), "", "utf8");
57832
+ const dir = join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
57833
+ for (const serverId of stopped) writeFileSync7(join22(dir, serverId + OWNER_STOP_EXT), "", "utf8");
55841
57834
  return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
55842
57835
  }
55843
57836
  function rootOrNull(adapter, env) {
@@ -55855,15 +57848,15 @@ function removeCache(adapter, env, configDir) {
55855
57848
  const root = rootOrNull(adapter, env);
55856
57849
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
55857
57850
  if (adapter.installMode === "marketplace") {
55858
- const cache = join21(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
57851
+ const cache = join22(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
55859
57852
  if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
55860
57853
  }
55861
57854
  rmSync7(root, { recursive: true, force: true });
55862
57855
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
55863
57856
  }
55864
57857
  case "plugin": {
55865
- const agentDir = join21(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
55866
- if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
57858
+ const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
57859
+ if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
55867
57860
  rmSync7(agentDir, { recursive: true, force: true });
55868
57861
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
55869
57862
  }
@@ -55908,7 +57901,7 @@ function ownEntries2(agent, env) {
55908
57901
  }
55909
57902
  if (agent === "opencode") {
55910
57903
  return [{
55911
- file: join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
57904
+ file: join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
55912
57905
  // D-WIN-OPENCODE-DIR-1
55913
57906
  key: OPENCODE_PLUGIN_KEY,
55914
57907
  shown: OPENCODE_PLUGIN_KEY,
@@ -55919,7 +57912,7 @@ function ownEntries2(agent, env) {
55919
57912
  if (agent === "pi") {
55920
57913
  const agentDir = piAgentDirOf(env, home);
55921
57914
  return [{
55922
- file: join21(agentDir, SETTINGS_FILE),
57915
+ file: join22(agentDir, SETTINGS_FILE),
55923
57916
  key: PI_PACKAGES_KEY,
55924
57917
  shown: PI_PACKAGES_KEY,
55925
57918
  has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
@@ -55941,12 +57934,12 @@ function removeOwnEntries(agent, env) {
55941
57934
  return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
55942
57935
  }
55943
57936
  function removeProjectData(configDir, projectKey) {
55944
- const projects = join21(configDir, PROJECTS_DIR_NAME);
55945
- const dir = join21(projects, projectKey);
55946
- if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
57937
+ const projects = join22(configDir, PROJECTS_DIR_NAME);
57938
+ const dir = join22(projects, projectKey);
57939
+ if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
55947
57940
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
55948
- for (const name of readdirSync9(dir)) {
55949
- if (name !== OWNERS_DIR_NAME) rmSync7(join21(dir, name), { recursive: true, force: true });
57941
+ for (const name of readdirSync10(dir)) {
57942
+ if (name !== OWNERS_DIR_NAME) rmSync7(join22(dir, name), { recursive: true, force: true });
55950
57943
  }
55951
57944
  return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
55952
57945
  }
@@ -55954,12 +57947,12 @@ function runUninstall(input) {
55954
57947
  const configDir = resolveConfigDir(input.env);
55955
57948
  const stop = stopServers(configDir, input.project.projectKey);
55956
57949
  const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
55957
- rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join21(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
57950
+ rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join22(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
55958
57951
  return { rows, stopped: stop.stopped };
55959
57952
  }
55960
57953
 
55961
57954
  // src/core/ops/v1-remove.ts
55962
- import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
57955
+ import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync15, rmSync as rmSync8 } from "node:fs";
55963
57956
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
55964
57957
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
55965
57958
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -55971,7 +57964,7 @@ function moveAside(target, undo) {
55971
57964
  }
55972
57965
  function keepAside(target, undo) {
55973
57966
  let aside = target + UPGRADE_ASIDE_SUFFIX;
55974
- for (let n = 2; existsSync21(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
57967
+ for (let n = 2; existsSync22(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
55975
57968
  renameWithRetry(target, aside);
55976
57969
  undo.push({ trash: aside, target, keep: true });
55977
57970
  return aside;
@@ -56010,8 +58003,8 @@ function locate(doc, path8) {
56010
58003
  return null;
56011
58004
  }
56012
58005
  function stripJsonEntries(agent, file2, findings, kept, undo) {
56013
- const layout = hostLayout(readFileSync14(file2, "utf8"));
56014
- const text = hostText(readFileSync14(file2, "utf8"));
58006
+ const layout = hostLayout(readFileSync15(file2, "utf8"));
58007
+ const text = hostText(readFileSync15(file2, "utf8"));
56015
58008
  const doc = parseHostConfig(agent, file2, text, "jsonc");
56016
58009
  const hit = /* @__PURE__ */ new Set();
56017
58010
  const byContainer = /* @__PURE__ */ new Map();
@@ -56048,20 +58041,20 @@ function removeV1(agent, findings, project) {
56048
58041
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
56049
58042
  else if (f.path === "") {
56050
58043
  if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
56051
- else if (existsSync21(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
56052
- else if (existsSync21(f.file)) {
58044
+ else if (existsSync22(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
58045
+ else if (existsSync22(f.file)) {
56053
58046
  moveAside(f.file, undo);
56054
58047
  done.set(f, UPGRADE_REMOVED);
56055
58048
  } else done.set(f, UPGRADE_NOT_FOUND);
56056
58049
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
56057
58050
  }
56058
58051
  for (const [file2, list3] of entries) {
56059
- if (!existsSync21(file2)) {
58052
+ if (!existsSync22(file2)) {
56060
58053
  for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
56061
58054
  continue;
56062
58055
  }
56063
58056
  if (file2.endsWith(TOML_EXT)) {
56064
- const rawToml = readFileSync14(file2, "utf8");
58057
+ const rawToml = readFileSync15(file2, "utf8");
56065
58058
  const tomlLayout = hostLayout(rawToml);
56066
58059
  let text = hostText(rawToml);
56067
58060
  for (const f of list3) {
@@ -56089,7 +58082,7 @@ function removeV1(agent, findings, project) {
56089
58082
  },
56090
58083
  rollback() {
56091
58084
  for (const u of undo.splice(0).reverse()) {
56092
- if (!existsSync21(u.trash)) continue;
58085
+ if (!existsSync22(u.trash)) continue;
56093
58086
  rmSync8(u.target, { recursive: true, force: true });
56094
58087
  renameWithRetry(u.trash, u.target);
56095
58088
  }
@@ -56365,15 +58358,15 @@ async function startServer(argv, env) {
56365
58358
  opening.catch(() => pending.delete(project.dbPath));
56366
58359
  }
56367
58360
  const db = await opening;
56368
- if (!existsSync22(db.path)) throw new CtxError("DB_GONE");
58361
+ if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
56369
58362
  return db;
56370
58363
  }
56371
58364
  function stopMarker(configDir, projectKey) {
56372
- return join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
58365
+ return join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
56373
58366
  }
56374
58367
  function stopRequested() {
56375
58368
  const configDir = resolveConfigDir(process.env);
56376
- return held.some((db) => existsSync22(stopMarker(configDir, db.projectKey)));
58369
+ return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
56377
58370
  }
56378
58371
  async function journal(project, ctx, name, reply4) {
56379
58372
  const db = await ownDb(project);
@@ -56482,7 +58475,7 @@ async function startServer(argv, env) {
56482
58475
  }
56483
58476
  installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
56484
58477
  handle = serveStdio(createServer);
56485
- await new Promise((resolve6) => process.once("exit", () => resolve6()));
58478
+ await new Promise((resolve7) => process.once("exit", () => resolve7()));
56486
58479
  }
56487
58480
  if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) {
56488
58481
  const [, , ...cliArgs] = process.argv;