context-mode 2.1.4 → 2.1.5

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
@@ -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
  });
@@ -28326,6 +28326,30 @@ var DUMP_COUNT_COMMANDS = Object.freeze(["head", "tail"]);
28326
28326
  var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
28327
28327
  var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
28328
28328
  var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
28329
+ var READ_MEDIA_TYPES = Object.freeze({
28330
+ png: { exts: [".png"], sig: [{ at: 0, bytes: [137, 80, 78, 71, 13, 10, 26, 10] }] },
28331
+ jpeg: { exts: [".jpg", ".jpeg"], sig: [{ at: 0, bytes: [255, 216, 255] }] },
28332
+ gif: { exts: [".gif"], sig: [{ at: 0, bytes: [71, 73, 70, 56] }] },
28333
+ // "GIF8"
28334
+ webp: { exts: [".webp"], sig: [{ at: 0, bytes: [82, 73, 70, 70] }, { at: 8, bytes: [87, 69, 66, 80] }] },
28335
+ // "RIFF" .... "WEBP"
28336
+ pdf: { exts: [".pdf"], sig: [{ at: 0, bytes: [37, 80, 68, 70, 45] }] }
28337
+ // "%PDF-"
28338
+ });
28339
+ var READ_IMAGES = Object.freeze(["png", "jpeg", "gif", "webp"]);
28340
+ var READ_IMAGES_AND_PDF = Object.freeze([...READ_IMAGES, "pdf"]);
28341
+ var READ_MEDIA_BY_AGENT = Object.freeze({
28342
+ "claude-code": READ_IMAGES_AND_PDF,
28343
+ gemini: READ_IMAGES_AND_PDF,
28344
+ qwen: READ_IMAGES_AND_PDF,
28345
+ opencode: READ_IMAGES_AND_PDF,
28346
+ pi: READ_IMAGES,
28347
+ vscode: READ_IMAGES,
28348
+ "copilot-cli": [],
28349
+ codex: [],
28350
+ kiro: [],
28351
+ zcode: []
28352
+ });
28329
28353
  var OWN_TOOL_PREFIX = "ctx_";
28330
28354
  var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
28331
28355
  var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
@@ -28410,7 +28434,7 @@ function PURGE_SUMMARY(rows, scope) {
28410
28434
  var DECISION_SOURCE = "decision";
28411
28435
  var DECISION_USER_LABEL = "decision (user)";
28412
28436
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
28413
- var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
28437
+ var BUNDLE_SHA = true ? "f75e51d580374d518a8ceefc1422a009ffe67311" : void 0;
28414
28438
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
28415
28439
  var DOCTOR_LABEL = Object.freeze({
28416
28440
  D1: "version",
@@ -28667,10 +28691,12 @@ var REGEX_ESCAPE = "\\";
28667
28691
  var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
28668
28692
  var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
28669
28693
  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";
28694
+ 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
28695
  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
28696
  function D5_SLOW_DETAIL(ms) {
28672
28697
  return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
28673
28698
  }
28699
+ 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
28700
  var D5_FIX = "run ctx_upgrade";
28675
28701
  var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
28676
28702
  function D10_DETAIL(mode) {
@@ -35133,7 +35159,7 @@ var $ZodObject3 = /* @__PURE__ */ $constructor3("$ZodObject", (inst, def) => {
35133
35159
  return (payload, ctx) => fn(shape, payload, ctx);
35134
35160
  };
35135
35161
  let fastpass;
35136
- const isObject6 = isObject3;
35162
+ const isObject7 = isObject3;
35137
35163
  const jit = !globalConfig3.jitless;
35138
35164
  const allowsEval4 = allowsEval3;
35139
35165
  const fastEnabled = jit && allowsEval4.value;
@@ -35142,7 +35168,7 @@ var $ZodObject3 = /* @__PURE__ */ $constructor3("$ZodObject", (inst, def) => {
35142
35168
  inst._zod.parse = (payload, ctx) => {
35143
35169
  value ?? (value = _normalized.value);
35144
35170
  const input = payload.value;
35145
- if (!isObject6(input)) {
35171
+ if (!isObject7(input)) {
35146
35172
  payload.issues.push({
35147
35173
  expected: "object",
35148
35174
  code: "invalid_type",
@@ -44119,10 +44145,10 @@ function startArgv(argv) {
44119
44145
  return sh === null ? null : [sh, ...argv];
44120
44146
  }
44121
44147
  function runProcess(argv, o) {
44122
- return new Promise((resolve6) => {
44148
+ return new Promise((resolve7) => {
44123
44149
  const isWin2 = process.platform === "win32";
44124
44150
  const start = startArgv(argv);
44125
- if (start === null) return resolve6(NOT_STARTED);
44151
+ if (start === null) return resolve7(NOT_STARTED);
44126
44152
  let child;
44127
44153
  try {
44128
44154
  child = spawn(start[0], start.slice(1), {
@@ -44136,7 +44162,7 @@ function runProcess(argv, o) {
44136
44162
  windowsHide: true
44137
44163
  });
44138
44164
  } catch {
44139
- return resolve6(NOT_STARTED);
44165
+ return resolve7(NOT_STARTED);
44140
44166
  }
44141
44167
  const stdoutChunks = [];
44142
44168
  const stderrChunks = [];
@@ -44161,7 +44187,7 @@ function runProcess(argv, o) {
44161
44187
  settled = true;
44162
44188
  clearTimeout(timer);
44163
44189
  o.signal.removeEventListener("abort", onAbort);
44164
- resolve6({
44190
+ resolve7({
44165
44191
  stdout: Buffer.concat(stdoutChunks),
44166
44192
  stderr: Buffer.concat(stderrChunks),
44167
44193
  exitCode,
@@ -45039,10 +45065,17 @@ function encode3(ev, d, _extra) {
45039
45065
  // src/adapters/codex.ts
45040
45066
  var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
45041
45067
  var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
45068
+ var STOP_EVENT = "Stop";
45069
+ var EMPTY = { stdout: "", exitCode: 0 };
45042
45070
  function decode4(raw) {
45071
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
45072
+ const p = raw;
45073
+ return { event: STOP_EVENT, agent: "codex", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
45074
+ }
45043
45075
  return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
45044
45076
  }
45045
45077
  function encode4(ev, d, _extra) {
45078
+ if (ev.event === STOP_EVENT) return EMPTY;
45046
45079
  return encodeClaudeShape(ev, d, false);
45047
45080
  }
45048
45081
 
@@ -45058,7 +45091,7 @@ var GEMINI_EVENTS = {
45058
45091
  var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
45059
45092
  var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
45060
45093
  var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
45061
- var EMPTY = { stdout: "", exitCode: 0 };
45094
+ var EMPTY2 = { stdout: "", exitCode: 0 };
45062
45095
  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
45096
  function own3(p, key) {
45064
45097
  return Object.hasOwn(p, key) ? p[key] : void 0;
@@ -45099,7 +45132,13 @@ function readResult2(resp) {
45099
45132
  const llm = obj === void 0 ? void 0 : own3(obj, "llmContent");
45100
45133
  const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
45101
45134
  const err = obj === void 0 ? void 0 : own3(obj, "error");
45102
- return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
45135
+ const info = { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
45136
+ if (hasMediaPart(llm)) info.keep = true;
45137
+ return info;
45138
+ }
45139
+ function hasMediaPart(llm) {
45140
+ const parts = Array.isArray(llm) ? llm : [llm];
45141
+ return parts.some((p) => typeof p === "object" && p !== null && (Object.hasOwn(p, "inlineData") || Object.hasOwn(p, "fileData")));
45103
45142
  }
45104
45143
  var URL_STARTS = ["https://", "http://"];
45105
45144
  var URL_TRAIL = `.,;:!?)]}>'"`;
@@ -45166,15 +45205,15 @@ function decode5(raw) {
45166
45205
  function encode5(ev, d, _extra) {
45167
45206
  switch (d.kind) {
45168
45207
  case "allow":
45169
- return EMPTY;
45208
+ return EMPTY2;
45170
45209
  case "hint":
45171
- if (!HINT_EVENTS.includes(ev.event)) return EMPTY;
45210
+ if (!HINT_EVENTS.includes(ev.event)) return EMPTY2;
45172
45211
  return { stdout: JSON.stringify({ hookSpecificOutput: { additionalContext: d.text } }), exitCode: 0 };
45173
45212
  case "deny":
45174
- if (!DENY_EVENTS.includes(ev.event)) return EMPTY;
45213
+ if (!DENY_EVENTS.includes(ev.event)) return EMPTY2;
45175
45214
  return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
45176
45215
  case "replace":
45177
- if (ev.event !== "PostToolUse") return EMPTY;
45216
+ if (ev.event !== "PostToolUse") return EMPTY2;
45178
45217
  return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
45179
45218
  }
45180
45219
  }
@@ -45294,21 +45333,21 @@ function decode7(raw) {
45294
45333
  if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
45295
45334
  return ev;
45296
45335
  }
45297
- var EMPTY2 = { stdout: "", exitCode: 0 };
45336
+ var EMPTY3 = { stdout: "", exitCode: 0 };
45298
45337
  function encode7(ev, d, _extra) {
45299
45338
  switch (d.kind) {
45300
45339
  case "allow":
45301
- return EMPTY2;
45340
+ return EMPTY3;
45302
45341
  case "hint":
45303
- return ev.event === "PostToolUse" ? EMPTY2 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
45342
+ return ev.event === "PostToolUse" ? EMPTY3 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
45304
45343
  case "deny":
45305
- if (ev.event !== "PreToolUse") return EMPTY2;
45344
+ if (ev.event !== "PreToolUse") return EMPTY3;
45306
45345
  return {
45307
45346
  stdout: JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }),
45308
45347
  exitCode: 0
45309
45348
  };
45310
45349
  case "replace":
45311
- if (ev.event !== "PostToolUse") return EMPTY2;
45350
+ if (ev.event !== "PostToolUse") return EMPTY3;
45312
45351
  return { stdout: JSON.stringify({ modifiedResult: { resultType: RESULT_SUCCESS, textResultForLlm: d.output } }), exitCode: 0 };
45313
45352
  }
45314
45353
  }
@@ -49534,10 +49573,1821 @@ function checkShell(env) {
49534
49573
  }
49535
49574
 
49536
49575
  // src/core/ops/doctor-hook.ts
49537
- import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync9, realpathSync as realpathSync8, rmSync as rmSync4 } from "node:fs";
49576
+ import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync9, realpathSync as realpathSync8, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
49538
49577
  import { tmpdir as tmpdir2 } from "node:os";
49539
49578
  import path7 from "node:path";
49540
49579
 
49580
+ // tests/fixtures/host-schemas/claude-code.json
49581
+ var claude_code_default = {
49582
+ host: "claude-code",
49583
+ 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.",
49584
+ output: {
49585
+ PreToolUse: {
49586
+ title: "Claude Code 2.1.274 PreToolUse reply",
49587
+ definitions: {
49588
+ Specific: {
49589
+ type: "object",
49590
+ additionalProperties: false,
49591
+ properties: {
49592
+ hookEventName: {
49593
+ type: "string",
49594
+ const: "PreToolUse"
49595
+ },
49596
+ permissionDecision: {
49597
+ type: "string",
49598
+ enum: [
49599
+ "allow",
49600
+ "deny",
49601
+ "ask",
49602
+ "defer"
49603
+ ]
49604
+ },
49605
+ permissionDecisionReason: {
49606
+ type: "string"
49607
+ },
49608
+ updatedInput: {
49609
+ type: "object"
49610
+ },
49611
+ additionalContext: {
49612
+ type: "string"
49613
+ },
49614
+ permissionDisplay: {
49615
+ description: "@internal Desktop host only"
49616
+ }
49617
+ },
49618
+ required: [
49619
+ "hookEventName"
49620
+ ]
49621
+ }
49622
+ },
49623
+ type: "object",
49624
+ additionalProperties: false,
49625
+ properties: {
49626
+ continue: {
49627
+ type: "boolean"
49628
+ },
49629
+ suppressOutput: {
49630
+ type: "boolean"
49631
+ },
49632
+ stopReason: {
49633
+ type: "string"
49634
+ },
49635
+ decision: {
49636
+ type: "string",
49637
+ enum: [
49638
+ "approve",
49639
+ "block"
49640
+ ]
49641
+ },
49642
+ systemMessage: {
49643
+ type: "string"
49644
+ },
49645
+ terminalSequence: {
49646
+ type: "string"
49647
+ },
49648
+ reason: {
49649
+ type: "string"
49650
+ },
49651
+ hookSpecificOutput: {
49652
+ allOf: [
49653
+ {
49654
+ $ref: "#/definitions/Specific"
49655
+ }
49656
+ ]
49657
+ }
49658
+ }
49659
+ },
49660
+ PostToolUse: {
49661
+ title: "Claude Code 2.1.274 PostToolUse reply",
49662
+ definitions: {
49663
+ Specific: {
49664
+ type: "object",
49665
+ additionalProperties: false,
49666
+ properties: {
49667
+ hookEventName: {
49668
+ type: "string",
49669
+ const: "PostToolUse"
49670
+ },
49671
+ additionalContext: {
49672
+ type: "string"
49673
+ },
49674
+ classifierContext: {
49675
+ type: "string"
49676
+ },
49677
+ updatedToolOutput: {
49678
+ description: "the tool's own output object"
49679
+ },
49680
+ updatedMCPToolOutput: {
49681
+ description: "an MCP tool's own output"
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
+ UserPromptSubmit: {
49727
+ title: "Claude Code 2.1.274 UserPromptSubmit reply",
49728
+ definitions: {
49729
+ Specific: {
49730
+ type: "object",
49731
+ additionalProperties: false,
49732
+ properties: {
49733
+ hookEventName: {
49734
+ type: "string",
49735
+ const: "UserPromptSubmit"
49736
+ },
49737
+ additionalContext: {
49738
+ type: "string"
49739
+ },
49740
+ sessionTitle: {
49741
+ type: "string"
49742
+ },
49743
+ suppressOriginalPrompt: {
49744
+ type: "boolean"
49745
+ }
49746
+ },
49747
+ required: [
49748
+ "hookEventName"
49749
+ ]
49750
+ }
49751
+ },
49752
+ type: "object",
49753
+ additionalProperties: false,
49754
+ properties: {
49755
+ continue: {
49756
+ type: "boolean"
49757
+ },
49758
+ suppressOutput: {
49759
+ type: "boolean"
49760
+ },
49761
+ stopReason: {
49762
+ type: "string"
49763
+ },
49764
+ decision: {
49765
+ type: "string",
49766
+ enum: [
49767
+ "approve",
49768
+ "block"
49769
+ ]
49770
+ },
49771
+ systemMessage: {
49772
+ type: "string"
49773
+ },
49774
+ terminalSequence: {
49775
+ type: "string"
49776
+ },
49777
+ reason: {
49778
+ type: "string"
49779
+ },
49780
+ hookSpecificOutput: {
49781
+ allOf: [
49782
+ {
49783
+ $ref: "#/definitions/Specific"
49784
+ }
49785
+ ]
49786
+ }
49787
+ }
49788
+ },
49789
+ SessionStart: {
49790
+ title: "Claude Code 2.1.274 SessionStart reply",
49791
+ definitions: {
49792
+ Specific: {
49793
+ type: "object",
49794
+ additionalProperties: false,
49795
+ properties: {
49796
+ hookEventName: {
49797
+ type: "string",
49798
+ const: "SessionStart"
49799
+ },
49800
+ additionalContext: {
49801
+ type: "string"
49802
+ },
49803
+ initialUserMessage: {
49804
+ type: "string"
49805
+ },
49806
+ sessionTitle: {
49807
+ type: "string"
49808
+ },
49809
+ watchPaths: {
49810
+ type: "array",
49811
+ items: {
49812
+ type: "string"
49813
+ }
49814
+ },
49815
+ reloadSkills: {
49816
+ type: "boolean"
49817
+ }
49818
+ },
49819
+ required: [
49820
+ "hookEventName"
49821
+ ]
49822
+ }
49823
+ },
49824
+ type: "object",
49825
+ additionalProperties: false,
49826
+ properties: {
49827
+ continue: {
49828
+ type: "boolean"
49829
+ },
49830
+ suppressOutput: {
49831
+ type: "boolean"
49832
+ },
49833
+ stopReason: {
49834
+ type: "string"
49835
+ },
49836
+ decision: {
49837
+ type: "string",
49838
+ enum: [
49839
+ "approve",
49840
+ "block"
49841
+ ]
49842
+ },
49843
+ systemMessage: {
49844
+ type: "string"
49845
+ },
49846
+ terminalSequence: {
49847
+ type: "string"
49848
+ },
49849
+ reason: {
49850
+ type: "string"
49851
+ },
49852
+ hookSpecificOutput: {
49853
+ allOf: [
49854
+ {
49855
+ $ref: "#/definitions/Specific"
49856
+ }
49857
+ ]
49858
+ }
49859
+ }
49860
+ }
49861
+ }
49862
+ };
49863
+
49864
+ // tests/fixtures/host-schemas/codex.json
49865
+ var codex_default = {
49866
+ host: "codex",
49867
+ source: "github.com/openai/codex tag rust-v0.166.0 codex-rs/hooks/schema/generated/*.command.output.schema.json",
49868
+ output: {
49869
+ PreToolUse: {
49870
+ $schema: "http://json-schema.org/draft-07/schema#",
49871
+ additionalProperties: false,
49872
+ definitions: {
49873
+ PreToolUseDecisionWire: {
49874
+ enum: [
49875
+ "approve",
49876
+ "block"
49877
+ ],
49878
+ type: "string"
49879
+ },
49880
+ PreToolUseHookSpecificOutputWire: {
49881
+ additionalProperties: false,
49882
+ properties: {
49883
+ additionalContext: {
49884
+ default: null,
49885
+ type: "string"
49886
+ },
49887
+ hookEventName: {
49888
+ const: "PreToolUse",
49889
+ type: "string"
49890
+ },
49891
+ permissionDecision: {
49892
+ allOf: [
49893
+ {
49894
+ $ref: "#/definitions/PreToolUsePermissionDecisionWire"
49895
+ }
49896
+ ],
49897
+ default: null
49898
+ },
49899
+ permissionDecisionReason: {
49900
+ default: null,
49901
+ type: "string"
49902
+ },
49903
+ updatedInput: {
49904
+ default: null
49905
+ }
49906
+ },
49907
+ required: [
49908
+ "hookEventName"
49909
+ ],
49910
+ type: "object"
49911
+ },
49912
+ PreToolUsePermissionDecisionWire: {
49913
+ enum: [
49914
+ "allow",
49915
+ "deny",
49916
+ "ask"
49917
+ ],
49918
+ type: "string"
49919
+ }
49920
+ },
49921
+ properties: {
49922
+ continue: {
49923
+ default: true,
49924
+ type: "boolean"
49925
+ },
49926
+ decision: {
49927
+ allOf: [
49928
+ {
49929
+ $ref: "#/definitions/PreToolUseDecisionWire"
49930
+ }
49931
+ ],
49932
+ default: null
49933
+ },
49934
+ hookSpecificOutput: {
49935
+ allOf: [
49936
+ {
49937
+ $ref: "#/definitions/PreToolUseHookSpecificOutputWire"
49938
+ }
49939
+ ],
49940
+ default: null
49941
+ },
49942
+ reason: {
49943
+ default: null,
49944
+ type: "string"
49945
+ },
49946
+ stopReason: {
49947
+ default: null,
49948
+ type: "string"
49949
+ },
49950
+ suppressOutput: {
49951
+ default: false,
49952
+ type: "boolean"
49953
+ },
49954
+ systemMessage: {
49955
+ default: null,
49956
+ type: "string"
49957
+ }
49958
+ },
49959
+ title: "pre-tool-use.command.output",
49960
+ type: "object"
49961
+ },
49962
+ PostToolUse: {
49963
+ $schema: "http://json-schema.org/draft-07/schema#",
49964
+ additionalProperties: false,
49965
+ definitions: {
49966
+ BlockDecisionWire: {
49967
+ enum: [
49968
+ "block"
49969
+ ],
49970
+ type: "string"
49971
+ },
49972
+ PostToolUseHookSpecificOutputWire: {
49973
+ additionalProperties: false,
49974
+ properties: {
49975
+ additionalContext: {
49976
+ default: null,
49977
+ type: "string"
49978
+ },
49979
+ hookEventName: {
49980
+ const: "PostToolUse",
49981
+ type: "string"
49982
+ },
49983
+ updatedMCPToolOutput: {
49984
+ default: null
49985
+ }
49986
+ },
49987
+ required: [
49988
+ "hookEventName"
49989
+ ],
49990
+ type: "object"
49991
+ }
49992
+ },
49993
+ properties: {
49994
+ continue: {
49995
+ default: true,
49996
+ type: "boolean"
49997
+ },
49998
+ decision: {
49999
+ allOf: [
50000
+ {
50001
+ $ref: "#/definitions/BlockDecisionWire"
50002
+ }
50003
+ ],
50004
+ default: null
50005
+ },
50006
+ hookSpecificOutput: {
50007
+ allOf: [
50008
+ {
50009
+ $ref: "#/definitions/PostToolUseHookSpecificOutputWire"
50010
+ }
50011
+ ],
50012
+ default: null
50013
+ },
50014
+ reason: {
50015
+ default: null,
50016
+ type: "string"
50017
+ },
50018
+ stopReason: {
50019
+ default: null,
50020
+ type: "string"
50021
+ },
50022
+ suppressOutput: {
50023
+ default: false,
50024
+ type: "boolean"
50025
+ },
50026
+ systemMessage: {
50027
+ default: null,
50028
+ type: "string"
50029
+ }
50030
+ },
50031
+ title: "post-tool-use.command.output",
50032
+ type: "object"
50033
+ },
50034
+ SessionStart: {
50035
+ $schema: "http://json-schema.org/draft-07/schema#",
50036
+ additionalProperties: false,
50037
+ definitions: {
50038
+ SessionStartHookSpecificOutputWire: {
50039
+ additionalProperties: false,
50040
+ properties: {
50041
+ additionalContext: {
50042
+ default: null,
50043
+ type: "string"
50044
+ },
50045
+ hookEventName: {
50046
+ const: "SessionStart",
50047
+ type: "string"
50048
+ }
50049
+ },
50050
+ required: [
50051
+ "hookEventName"
50052
+ ],
50053
+ type: "object"
50054
+ }
50055
+ },
50056
+ properties: {
50057
+ continue: {
50058
+ default: true,
50059
+ type: "boolean"
50060
+ },
50061
+ hookSpecificOutput: {
50062
+ allOf: [
50063
+ {
50064
+ $ref: "#/definitions/SessionStartHookSpecificOutputWire"
50065
+ }
50066
+ ],
50067
+ default: null
50068
+ },
50069
+ stopReason: {
50070
+ default: null,
50071
+ type: "string"
50072
+ },
50073
+ suppressOutput: {
50074
+ default: false,
50075
+ type: "boolean"
50076
+ },
50077
+ systemMessage: {
50078
+ default: null,
50079
+ type: "string"
50080
+ }
50081
+ },
50082
+ title: "session-start.command.output",
50083
+ type: "object"
50084
+ },
50085
+ UserPromptSubmit: {
50086
+ $schema: "http://json-schema.org/draft-07/schema#",
50087
+ additionalProperties: false,
50088
+ definitions: {
50089
+ BlockDecisionWire: {
50090
+ enum: [
50091
+ "block"
50092
+ ],
50093
+ type: "string"
50094
+ },
50095
+ UserPromptSubmitHookSpecificOutputWire: {
50096
+ additionalProperties: false,
50097
+ properties: {
50098
+ additionalContext: {
50099
+ default: null,
50100
+ type: "string"
50101
+ },
50102
+ hookEventName: {
50103
+ const: "UserPromptSubmit",
50104
+ type: "string"
50105
+ }
50106
+ },
50107
+ required: [
50108
+ "hookEventName"
50109
+ ],
50110
+ type: "object"
50111
+ }
50112
+ },
50113
+ properties: {
50114
+ continue: {
50115
+ default: true,
50116
+ type: "boolean"
50117
+ },
50118
+ decision: {
50119
+ allOf: [
50120
+ {
50121
+ $ref: "#/definitions/BlockDecisionWire"
50122
+ }
50123
+ ],
50124
+ default: null
50125
+ },
50126
+ hookSpecificOutput: {
50127
+ allOf: [
50128
+ {
50129
+ $ref: "#/definitions/UserPromptSubmitHookSpecificOutputWire"
50130
+ }
50131
+ ],
50132
+ default: null
50133
+ },
50134
+ reason: {
50135
+ default: null,
50136
+ type: "string"
50137
+ },
50138
+ stopReason: {
50139
+ default: null,
50140
+ type: "string"
50141
+ },
50142
+ suppressOutput: {
50143
+ default: false,
50144
+ type: "boolean"
50145
+ },
50146
+ systemMessage: {
50147
+ default: null,
50148
+ type: "string"
50149
+ }
50150
+ },
50151
+ title: "user-prompt-submit.command.output",
50152
+ type: "object"
50153
+ },
50154
+ Stop: {
50155
+ $schema: "http://json-schema.org/draft-07/schema#",
50156
+ additionalProperties: false,
50157
+ definitions: {
50158
+ BlockDecisionWire: {
50159
+ enum: [
50160
+ "block"
50161
+ ],
50162
+ type: "string"
50163
+ }
50164
+ },
50165
+ properties: {
50166
+ continue: {
50167
+ default: true,
50168
+ type: "boolean"
50169
+ },
50170
+ decision: {
50171
+ allOf: [
50172
+ {
50173
+ $ref: "#/definitions/BlockDecisionWire"
50174
+ }
50175
+ ],
50176
+ default: null
50177
+ },
50178
+ reason: {
50179
+ default: null,
50180
+ description: "Claude requires `reason` when `decision` is `block`; we enforce that semantic rule during output parsing rather than in the JSON schema.",
50181
+ type: "string"
50182
+ },
50183
+ stopReason: {
50184
+ default: null,
50185
+ type: "string"
50186
+ },
50187
+ suppressOutput: {
50188
+ default: false,
50189
+ type: "boolean"
50190
+ },
50191
+ systemMessage: {
50192
+ default: null,
50193
+ type: "string"
50194
+ }
50195
+ },
50196
+ title: "stop.command.output",
50197
+ type: "object"
50198
+ }
50199
+ }
50200
+ };
50201
+
50202
+ // tests/fixtures/host-schemas/gemini.json
50203
+ var gemini_default = {
50204
+ host: "gemini",
50205
+ 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.",
50206
+ output: {
50207
+ PreToolUse: {
50208
+ title: "Gemini CLI 0.67.0 BeforeTool reply",
50209
+ definitions: {
50210
+ Specific: {
50211
+ type: "object",
50212
+ additionalProperties: false,
50213
+ properties: {
50214
+ hookEventName: {
50215
+ type: "string"
50216
+ },
50217
+ tool_input: {
50218
+ type: "object"
50219
+ }
50220
+ }
50221
+ }
50222
+ },
50223
+ type: "object",
50224
+ additionalProperties: false,
50225
+ properties: {
50226
+ systemMessage: {
50227
+ type: "string"
50228
+ },
50229
+ suppressOutput: {
50230
+ type: "boolean"
50231
+ },
50232
+ continue: {
50233
+ type: "boolean"
50234
+ },
50235
+ stopReason: {
50236
+ type: "string"
50237
+ },
50238
+ decision: {
50239
+ type: "string",
50240
+ enum: [
50241
+ "allow",
50242
+ "deny",
50243
+ "block",
50244
+ "ask"
50245
+ ]
50246
+ },
50247
+ reason: {
50248
+ type: "string"
50249
+ },
50250
+ hookSpecificOutput: {
50251
+ allOf: [
50252
+ {
50253
+ $ref: "#/definitions/Specific"
50254
+ }
50255
+ ]
50256
+ }
50257
+ }
50258
+ },
50259
+ PostToolUse: {
50260
+ title: "Gemini CLI 0.67.0 AfterTool reply",
50261
+ definitions: {
50262
+ Specific: {
50263
+ type: "object",
50264
+ additionalProperties: false,
50265
+ properties: {
50266
+ hookEventName: {
50267
+ type: "string"
50268
+ },
50269
+ additionalContext: {
50270
+ type: "string"
50271
+ },
50272
+ tailToolCallRequest: {
50273
+ type: "object",
50274
+ additionalProperties: false,
50275
+ properties: {
50276
+ name: {
50277
+ type: "string"
50278
+ },
50279
+ args: {
50280
+ type: "object"
50281
+ }
50282
+ },
50283
+ required: [
50284
+ "name",
50285
+ "args"
50286
+ ]
50287
+ }
50288
+ }
50289
+ }
50290
+ },
50291
+ type: "object",
50292
+ additionalProperties: false,
50293
+ properties: {
50294
+ systemMessage: {
50295
+ type: "string"
50296
+ },
50297
+ suppressOutput: {
50298
+ type: "boolean"
50299
+ },
50300
+ continue: {
50301
+ type: "boolean"
50302
+ },
50303
+ stopReason: {
50304
+ type: "string"
50305
+ },
50306
+ decision: {
50307
+ type: "string",
50308
+ enum: [
50309
+ "allow",
50310
+ "deny",
50311
+ "block",
50312
+ "ask"
50313
+ ]
50314
+ },
50315
+ reason: {
50316
+ type: "string"
50317
+ },
50318
+ hookSpecificOutput: {
50319
+ allOf: [
50320
+ {
50321
+ $ref: "#/definitions/Specific"
50322
+ }
50323
+ ]
50324
+ }
50325
+ }
50326
+ },
50327
+ UserPromptSubmit: {
50328
+ title: "Gemini CLI 0.67.0 BeforeAgent reply",
50329
+ definitions: {
50330
+ Specific: {
50331
+ type: "object",
50332
+ additionalProperties: false,
50333
+ properties: {
50334
+ hookEventName: {
50335
+ type: "string"
50336
+ },
50337
+ additionalContext: {
50338
+ type: "string"
50339
+ }
50340
+ }
50341
+ }
50342
+ },
50343
+ type: "object",
50344
+ additionalProperties: false,
50345
+ properties: {
50346
+ systemMessage: {
50347
+ type: "string"
50348
+ },
50349
+ suppressOutput: {
50350
+ type: "boolean"
50351
+ },
50352
+ continue: {
50353
+ type: "boolean"
50354
+ },
50355
+ stopReason: {
50356
+ type: "string"
50357
+ },
50358
+ decision: {
50359
+ type: "string",
50360
+ enum: [
50361
+ "allow",
50362
+ "deny",
50363
+ "block",
50364
+ "ask"
50365
+ ]
50366
+ },
50367
+ reason: {
50368
+ type: "string"
50369
+ },
50370
+ hookSpecificOutput: {
50371
+ allOf: [
50372
+ {
50373
+ $ref: "#/definitions/Specific"
50374
+ }
50375
+ ]
50376
+ }
50377
+ }
50378
+ },
50379
+ SessionStart: {
50380
+ title: "Gemini CLI 0.67.0 SessionStart reply",
50381
+ definitions: {
50382
+ Specific: {
50383
+ type: "object",
50384
+ additionalProperties: false,
50385
+ properties: {
50386
+ hookEventName: {
50387
+ type: "string"
50388
+ },
50389
+ additionalContext: {
50390
+ type: "string"
50391
+ }
50392
+ }
50393
+ }
50394
+ },
50395
+ type: "object",
50396
+ additionalProperties: false,
50397
+ properties: {
50398
+ systemMessage: {
50399
+ type: "string"
50400
+ },
50401
+ suppressOutput: {
50402
+ type: "boolean"
50403
+ },
50404
+ continue: {
50405
+ type: "boolean"
50406
+ },
50407
+ stopReason: {
50408
+ type: "string"
50409
+ },
50410
+ decision: {
50411
+ type: "string",
50412
+ enum: [
50413
+ "allow",
50414
+ "deny",
50415
+ "block",
50416
+ "ask"
50417
+ ]
50418
+ },
50419
+ reason: {
50420
+ type: "string"
50421
+ },
50422
+ hookSpecificOutput: {
50423
+ allOf: [
50424
+ {
50425
+ $ref: "#/definitions/Specific"
50426
+ }
50427
+ ]
50428
+ }
50429
+ }
50430
+ }
50431
+ }
50432
+ };
50433
+
50434
+ // tests/fixtures/host-schemas/qwen.json
50435
+ var qwen_default = {
50436
+ host: "qwen",
50437
+ 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).",
50438
+ output: {
50439
+ PreToolUse: {
50440
+ title: "Qwen Code 0.26.7 PreToolUse reply",
50441
+ definitions: {
50442
+ Specific: {
50443
+ type: "object",
50444
+ additionalProperties: false,
50445
+ properties: {
50446
+ hookEventName: {
50447
+ type: "string",
50448
+ const: "PreToolUse"
50449
+ },
50450
+ permissionDecision: {
50451
+ type: "string",
50452
+ enum: [
50453
+ "allow",
50454
+ "deny",
50455
+ "ask"
50456
+ ]
50457
+ },
50458
+ permissionDecisionReason: {
50459
+ type: "string"
50460
+ },
50461
+ updatedInput: {
50462
+ type: "object"
50463
+ },
50464
+ additionalContext: {
50465
+ type: "string"
50466
+ }
50467
+ },
50468
+ required: [
50469
+ "hookEventName"
50470
+ ]
50471
+ }
50472
+ },
50473
+ type: "object",
50474
+ additionalProperties: false,
50475
+ properties: {
50476
+ continue: {
50477
+ type: "boolean"
50478
+ },
50479
+ stopReason: {
50480
+ type: "string"
50481
+ },
50482
+ suppressOutput: {
50483
+ type: "boolean"
50484
+ },
50485
+ systemMessage: {
50486
+ type: "string"
50487
+ },
50488
+ decision: {
50489
+ type: "string",
50490
+ enum: [
50491
+ "allow",
50492
+ "approve",
50493
+ "deny",
50494
+ "block",
50495
+ "ask"
50496
+ ]
50497
+ },
50498
+ reason: {
50499
+ type: "string"
50500
+ },
50501
+ hookSpecificOutput: {
50502
+ allOf: [
50503
+ {
50504
+ $ref: "#/definitions/Specific"
50505
+ }
50506
+ ]
50507
+ }
50508
+ }
50509
+ },
50510
+ PostToolUse: {
50511
+ title: "Qwen Code 0.26.7 PostToolUse reply",
50512
+ definitions: {
50513
+ Specific: {
50514
+ type: "object",
50515
+ additionalProperties: false,
50516
+ properties: {
50517
+ hookEventName: {
50518
+ type: "string",
50519
+ const: "PostToolUse"
50520
+ },
50521
+ additionalContext: {
50522
+ type: "string"
50523
+ }
50524
+ },
50525
+ required: [
50526
+ "hookEventName"
50527
+ ]
50528
+ }
50529
+ },
50530
+ type: "object",
50531
+ additionalProperties: false,
50532
+ properties: {
50533
+ continue: {
50534
+ type: "boolean"
50535
+ },
50536
+ stopReason: {
50537
+ type: "string"
50538
+ },
50539
+ suppressOutput: {
50540
+ type: "boolean"
50541
+ },
50542
+ systemMessage: {
50543
+ type: "string"
50544
+ },
50545
+ decision: {
50546
+ type: "string",
50547
+ enum: [
50548
+ "allow",
50549
+ "approve",
50550
+ "deny",
50551
+ "block",
50552
+ "ask"
50553
+ ]
50554
+ },
50555
+ reason: {
50556
+ type: "string"
50557
+ },
50558
+ hookSpecificOutput: {
50559
+ allOf: [
50560
+ {
50561
+ $ref: "#/definitions/Specific"
50562
+ }
50563
+ ]
50564
+ }
50565
+ }
50566
+ },
50567
+ UserPromptSubmit: {
50568
+ title: "Qwen Code 0.26.7 UserPromptSubmit reply",
50569
+ definitions: {
50570
+ Specific: {
50571
+ type: "object",
50572
+ additionalProperties: false,
50573
+ properties: {
50574
+ hookEventName: {
50575
+ type: "string",
50576
+ const: "UserPromptSubmit"
50577
+ },
50578
+ additionalContext: {
50579
+ type: "string"
50580
+ }
50581
+ },
50582
+ required: [
50583
+ "hookEventName"
50584
+ ]
50585
+ }
50586
+ },
50587
+ type: "object",
50588
+ additionalProperties: false,
50589
+ properties: {
50590
+ continue: {
50591
+ type: "boolean"
50592
+ },
50593
+ stopReason: {
50594
+ type: "string"
50595
+ },
50596
+ suppressOutput: {
50597
+ type: "boolean"
50598
+ },
50599
+ systemMessage: {
50600
+ type: "string"
50601
+ },
50602
+ decision: {
50603
+ type: "string",
50604
+ enum: [
50605
+ "allow",
50606
+ "approve",
50607
+ "deny",
50608
+ "block",
50609
+ "ask"
50610
+ ]
50611
+ },
50612
+ reason: {
50613
+ type: "string"
50614
+ },
50615
+ hookSpecificOutput: {
50616
+ allOf: [
50617
+ {
50618
+ $ref: "#/definitions/Specific"
50619
+ }
50620
+ ]
50621
+ }
50622
+ }
50623
+ },
50624
+ SessionStart: {
50625
+ title: "Qwen Code 0.26.7 SessionStart reply",
50626
+ definitions: {
50627
+ Specific: {
50628
+ type: "object",
50629
+ additionalProperties: false,
50630
+ properties: {
50631
+ hookEventName: {
50632
+ type: "string",
50633
+ const: "SessionStart"
50634
+ },
50635
+ additionalContext: {
50636
+ type: "string"
50637
+ }
50638
+ },
50639
+ required: [
50640
+ "hookEventName"
50641
+ ]
50642
+ }
50643
+ },
50644
+ type: "object",
50645
+ additionalProperties: false,
50646
+ properties: {
50647
+ continue: {
50648
+ type: "boolean"
50649
+ },
50650
+ stopReason: {
50651
+ type: "string"
50652
+ },
50653
+ suppressOutput: {
50654
+ type: "boolean"
50655
+ },
50656
+ systemMessage: {
50657
+ type: "string"
50658
+ },
50659
+ decision: {
50660
+ type: "string",
50661
+ enum: [
50662
+ "allow",
50663
+ "approve",
50664
+ "deny",
50665
+ "block",
50666
+ "ask"
50667
+ ]
50668
+ },
50669
+ reason: {
50670
+ type: "string"
50671
+ },
50672
+ hookSpecificOutput: {
50673
+ allOf: [
50674
+ {
50675
+ $ref: "#/definitions/Specific"
50676
+ }
50677
+ ]
50678
+ }
50679
+ }
50680
+ }
50681
+ }
50682
+ };
50683
+
50684
+ // tests/fixtures/host-schemas/copilot-cli.json
50685
+ var copilot_cli_default = {
50686
+ host: "copilot-cli",
50687
+ 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.",
50688
+ output: {
50689
+ PreToolUse: {
50690
+ title: "Copilot CLI 1.0.105 preToolUse reply",
50691
+ type: "object",
50692
+ additionalProperties: false,
50693
+ properties: {
50694
+ permissionDecision: {
50695
+ type: "string",
50696
+ enum: [
50697
+ "allow",
50698
+ "deny",
50699
+ "ask"
50700
+ ]
50701
+ },
50702
+ permissionDecisionReason: {
50703
+ type: "string"
50704
+ },
50705
+ modifiedArgs: {
50706
+ description: "unknown"
50707
+ },
50708
+ additionalContext: {
50709
+ type: "string"
50710
+ },
50711
+ suppressOutput: {
50712
+ type: "boolean"
50713
+ }
50714
+ }
50715
+ },
50716
+ PostToolUse: {
50717
+ title: "Copilot CLI 1.0.105 postToolUse reply",
50718
+ definitions: {
50719
+ ToolResultObject: {
50720
+ type: "object",
50721
+ additionalProperties: false,
50722
+ properties: {
50723
+ textResultForLlm: {
50724
+ type: "string"
50725
+ },
50726
+ binaryResultsForLlm: {
50727
+ type: "array",
50728
+ items: {
50729
+ type: "object"
50730
+ }
50731
+ },
50732
+ resultType: {
50733
+ type: "string",
50734
+ enum: [
50735
+ "success",
50736
+ "failure",
50737
+ "rejected",
50738
+ "denied",
50739
+ "timeout"
50740
+ ]
50741
+ },
50742
+ error: {
50743
+ type: "string"
50744
+ },
50745
+ sessionLog: {
50746
+ type: "string"
50747
+ },
50748
+ toolTelemetry: {
50749
+ type: "object"
50750
+ },
50751
+ toolReferences: {
50752
+ type: "array",
50753
+ items: {
50754
+ type: "string"
50755
+ }
50756
+ }
50757
+ },
50758
+ required: [
50759
+ "textResultForLlm",
50760
+ "resultType"
50761
+ ]
50762
+ }
50763
+ },
50764
+ type: "object",
50765
+ additionalProperties: false,
50766
+ properties: {
50767
+ modifiedResult: {
50768
+ allOf: [
50769
+ {
50770
+ $ref: "#/definitions/ToolResultObject"
50771
+ }
50772
+ ]
50773
+ },
50774
+ additionalContext: {
50775
+ type: "string"
50776
+ },
50777
+ suppressOutput: {
50778
+ type: "boolean"
50779
+ }
50780
+ }
50781
+ },
50782
+ UserPromptSubmit: {
50783
+ title: "Copilot CLI 1.0.105 userPromptSubmitted reply",
50784
+ type: "object",
50785
+ additionalProperties: false,
50786
+ properties: {
50787
+ modifiedPrompt: {
50788
+ type: "string"
50789
+ },
50790
+ additionalContext: {
50791
+ type: "string"
50792
+ },
50793
+ suppressOutput: {
50794
+ type: "boolean"
50795
+ },
50796
+ decision: {
50797
+ type: "string",
50798
+ const: "block"
50799
+ },
50800
+ reason: {
50801
+ type: "string"
50802
+ }
50803
+ }
50804
+ },
50805
+ SessionStart: {
50806
+ title: "Copilot CLI 1.0.105 sessionStart reply",
50807
+ type: "object",
50808
+ additionalProperties: false,
50809
+ properties: {
50810
+ additionalContext: {
50811
+ type: "string"
50812
+ },
50813
+ modifiedConfig: {
50814
+ type: "object"
50815
+ }
50816
+ }
50817
+ }
50818
+ }
50819
+ };
50820
+
50821
+ // tests/fixtures/host-schemas/vscode.json
50822
+ var vscode_default = {
50823
+ host: "vscode",
50824
+ 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').",
50825
+ output: {
50826
+ PreToolUse: {
50827
+ title: "VS Code Copilot Chat 0.44.0 PreToolUse reply",
50828
+ definitions: {
50829
+ Specific: {
50830
+ type: "object",
50831
+ additionalProperties: false,
50832
+ properties: {
50833
+ hookEventName: {
50834
+ type: "string"
50835
+ },
50836
+ permissionDecision: {
50837
+ type: "string",
50838
+ enum: [
50839
+ "allow",
50840
+ "deny",
50841
+ "ask"
50842
+ ]
50843
+ },
50844
+ permissionDecisionReason: {
50845
+ type: "string"
50846
+ },
50847
+ updatedInput: {
50848
+ type: "object"
50849
+ },
50850
+ additionalContext: {
50851
+ type: "string"
50852
+ }
50853
+ }
50854
+ }
50855
+ },
50856
+ type: "object",
50857
+ additionalProperties: false,
50858
+ properties: {
50859
+ hookSpecificOutput: {
50860
+ allOf: [
50861
+ {
50862
+ $ref: "#/definitions/Specific"
50863
+ }
50864
+ ]
50865
+ }
50866
+ }
50867
+ },
50868
+ PostToolUse: {
50869
+ title: "VS Code Copilot Chat 0.44.0 PostToolUse reply",
50870
+ definitions: {
50871
+ Specific: {
50872
+ type: "object",
50873
+ additionalProperties: false,
50874
+ properties: {
50875
+ hookEventName: {
50876
+ type: "string"
50877
+ },
50878
+ additionalContext: {
50879
+ type: "string"
50880
+ }
50881
+ }
50882
+ }
50883
+ },
50884
+ type: "object",
50885
+ additionalProperties: false,
50886
+ properties: {
50887
+ decision: {
50888
+ type: "string",
50889
+ const: "block"
50890
+ },
50891
+ reason: {
50892
+ type: "string"
50893
+ },
50894
+ hookSpecificOutput: {
50895
+ allOf: [
50896
+ {
50897
+ $ref: "#/definitions/Specific"
50898
+ }
50899
+ ]
50900
+ }
50901
+ }
50902
+ },
50903
+ UserPromptSubmit: {
50904
+ title: "VS Code Copilot Chat 0.44.0 UserPromptSubmit reply",
50905
+ definitions: {
50906
+ Specific: {
50907
+ type: "object",
50908
+ additionalProperties: false,
50909
+ properties: {
50910
+ hookEventName: {
50911
+ type: "string"
50912
+ },
50913
+ additionalContext: {
50914
+ type: "string"
50915
+ }
50916
+ }
50917
+ }
50918
+ },
50919
+ type: "object",
50920
+ additionalProperties: false,
50921
+ properties: {
50922
+ decision: {
50923
+ type: "string",
50924
+ const: "block"
50925
+ },
50926
+ reason: {
50927
+ type: "string"
50928
+ },
50929
+ hookSpecificOutput: {
50930
+ allOf: [
50931
+ {
50932
+ $ref: "#/definitions/Specific"
50933
+ }
50934
+ ]
50935
+ }
50936
+ }
50937
+ },
50938
+ SessionStart: {
50939
+ title: "VS Code Copilot Chat 0.44.0 SessionStart reply",
50940
+ definitions: {
50941
+ Specific: {
50942
+ type: "object",
50943
+ additionalProperties: false,
50944
+ properties: {
50945
+ hookEventName: {
50946
+ type: "string"
50947
+ },
50948
+ additionalContext: {
50949
+ type: "string"
50950
+ }
50951
+ }
50952
+ }
50953
+ },
50954
+ type: "object",
50955
+ additionalProperties: false,
50956
+ properties: {
50957
+ hookSpecificOutput: {
50958
+ allOf: [
50959
+ {
50960
+ $ref: "#/definitions/Specific"
50961
+ }
50962
+ ]
50963
+ }
50964
+ }
50965
+ }
50966
+ }
50967
+ };
50968
+
50969
+ // tests/fixtures/host-schemas/kiro.json
50970
+ var kiro_default = {
50971
+ host: "kiro",
50972
+ 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`)",
50973
+ mcpToolId: {
50974
+ 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",
50975
+ prefix: "mcp_",
50976
+ join: "_",
50977
+ maxLength: 64
50978
+ },
50979
+ hookStdin: {
50980
+ from: "function sJn: {session_id, hook_event_name, cwd} plus per trigger fields",
50981
+ UserPromptSubmit: ["session_id", "hook_event_name", "cwd", "prompt"],
50982
+ PreToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input"],
50983
+ PostToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input", "tool_response"],
50984
+ SessionStart: ["session_id", "hook_event_name", "cwd"]
50985
+ },
50986
+ hookOutputCapChars: 3e3,
50987
+ windowsHookShell: "child_process.spawn(command, {shell: true}) in the V3 hook process runner (class tje): COMSPEC (cmd.exe /d /s /c) on win32",
50988
+ stdout: "text",
50989
+ output: {
50990
+ 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" },
50991
+ 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" },
50992
+ 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" },
50993
+ 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" }
50994
+ }
50995
+ };
50996
+
50997
+ // tests/fixtures/host-schemas/zcode.json
50998
+ var zcode_default = {
50999
+ host: "zcode",
51000
+ 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.",
51001
+ output: {
51002
+ PreToolUse: {
51003
+ title: "ZCode 0.17.1 PreToolUse reply",
51004
+ definitions: {
51005
+ Specific: {
51006
+ type: "object",
51007
+ additionalProperties: false,
51008
+ properties: {
51009
+ additionalContext: {
51010
+ type: "string"
51011
+ },
51012
+ hookEventName: {
51013
+ type: "string",
51014
+ const: "PreToolUse"
51015
+ },
51016
+ permissionDecision: {
51017
+ type: "string",
51018
+ enum: [
51019
+ "allow",
51020
+ "ask",
51021
+ "deny"
51022
+ ]
51023
+ },
51024
+ permissionDecisionReason: {
51025
+ type: "string"
51026
+ },
51027
+ updatedInput: {
51028
+ description: "z.unknown()"
51029
+ }
51030
+ },
51031
+ required: [
51032
+ "hookEventName"
51033
+ ]
51034
+ }
51035
+ },
51036
+ type: "object",
51037
+ additionalProperties: false,
51038
+ properties: {
51039
+ additionalContext: {
51040
+ type: "string"
51041
+ },
51042
+ additional_context: {
51043
+ type: "string"
51044
+ },
51045
+ continue: {
51046
+ type: "boolean"
51047
+ },
51048
+ decision: {
51049
+ type: "string",
51050
+ enum: [
51051
+ "approve",
51052
+ "block"
51053
+ ]
51054
+ },
51055
+ reason: {
51056
+ type: "string"
51057
+ },
51058
+ stopReason: {
51059
+ type: "string"
51060
+ },
51061
+ suppressOutput: {
51062
+ type: "boolean"
51063
+ },
51064
+ systemMessage: {
51065
+ type: "string"
51066
+ },
51067
+ hookSpecificOutput: {
51068
+ allOf: [
51069
+ {
51070
+ $ref: "#/definitions/Specific"
51071
+ }
51072
+ ]
51073
+ }
51074
+ }
51075
+ },
51076
+ PostToolUse: {
51077
+ title: "ZCode 0.17.1 PostToolUse reply",
51078
+ definitions: {
51079
+ Specific: {
51080
+ type: "object",
51081
+ additionalProperties: false,
51082
+ properties: {
51083
+ additionalContext: {
51084
+ type: "string"
51085
+ },
51086
+ hookEventName: {
51087
+ type: "string",
51088
+ const: "PostToolUse"
51089
+ }
51090
+ },
51091
+ required: [
51092
+ "hookEventName"
51093
+ ]
51094
+ }
51095
+ },
51096
+ type: "object",
51097
+ additionalProperties: false,
51098
+ properties: {
51099
+ additionalContext: {
51100
+ type: "string"
51101
+ },
51102
+ additional_context: {
51103
+ type: "string"
51104
+ },
51105
+ continue: {
51106
+ type: "boolean"
51107
+ },
51108
+ decision: {
51109
+ type: "string",
51110
+ enum: [
51111
+ "approve",
51112
+ "block"
51113
+ ]
51114
+ },
51115
+ reason: {
51116
+ type: "string"
51117
+ },
51118
+ stopReason: {
51119
+ type: "string"
51120
+ },
51121
+ suppressOutput: {
51122
+ type: "boolean"
51123
+ },
51124
+ systemMessage: {
51125
+ type: "string"
51126
+ },
51127
+ hookSpecificOutput: {
51128
+ allOf: [
51129
+ {
51130
+ $ref: "#/definitions/Specific"
51131
+ }
51132
+ ]
51133
+ }
51134
+ }
51135
+ },
51136
+ UserPromptSubmit: {
51137
+ title: "ZCode 0.17.1 UserPromptSubmit reply",
51138
+ definitions: {
51139
+ Specific: {
51140
+ type: "object",
51141
+ additionalProperties: false,
51142
+ properties: {
51143
+ additionalContext: {
51144
+ type: "string"
51145
+ },
51146
+ hookEventName: {
51147
+ type: "string",
51148
+ const: "UserPromptSubmit"
51149
+ }
51150
+ },
51151
+ required: [
51152
+ "hookEventName"
51153
+ ]
51154
+ }
51155
+ },
51156
+ type: "object",
51157
+ additionalProperties: false,
51158
+ properties: {
51159
+ additionalContext: {
51160
+ type: "string"
51161
+ },
51162
+ additional_context: {
51163
+ type: "string"
51164
+ },
51165
+ continue: {
51166
+ type: "boolean"
51167
+ },
51168
+ decision: {
51169
+ type: "string",
51170
+ enum: [
51171
+ "approve",
51172
+ "block"
51173
+ ]
51174
+ },
51175
+ reason: {
51176
+ type: "string"
51177
+ },
51178
+ stopReason: {
51179
+ type: "string"
51180
+ },
51181
+ suppressOutput: {
51182
+ type: "boolean"
51183
+ },
51184
+ systemMessage: {
51185
+ type: "string"
51186
+ },
51187
+ hookSpecificOutput: {
51188
+ allOf: [
51189
+ {
51190
+ $ref: "#/definitions/Specific"
51191
+ }
51192
+ ]
51193
+ }
51194
+ }
51195
+ },
51196
+ SessionStart: {
51197
+ title: "ZCode 0.17.1 SessionStart reply",
51198
+ definitions: {
51199
+ Specific: {
51200
+ type: "object",
51201
+ additionalProperties: false,
51202
+ properties: {
51203
+ additionalContext: {
51204
+ type: "string"
51205
+ },
51206
+ hookEventName: {
51207
+ type: "string",
51208
+ const: "SessionStart"
51209
+ }
51210
+ },
51211
+ required: [
51212
+ "hookEventName"
51213
+ ]
51214
+ }
51215
+ },
51216
+ type: "object",
51217
+ additionalProperties: false,
51218
+ properties: {
51219
+ additionalContext: {
51220
+ type: "string"
51221
+ },
51222
+ additional_context: {
51223
+ type: "string"
51224
+ },
51225
+ continue: {
51226
+ type: "boolean"
51227
+ },
51228
+ decision: {
51229
+ type: "string",
51230
+ enum: [
51231
+ "approve",
51232
+ "block"
51233
+ ]
51234
+ },
51235
+ reason: {
51236
+ type: "string"
51237
+ },
51238
+ stopReason: {
51239
+ type: "string"
51240
+ },
51241
+ suppressOutput: {
51242
+ type: "boolean"
51243
+ },
51244
+ systemMessage: {
51245
+ type: "string"
51246
+ },
51247
+ hookSpecificOutput: {
51248
+ allOf: [
51249
+ {
51250
+ $ref: "#/definitions/Specific"
51251
+ }
51252
+ ]
51253
+ }
51254
+ }
51255
+ }
51256
+ }
51257
+ };
51258
+
51259
+ // tests/fixtures/host-schemas/pi.json
51260
+ var pi_default = {
51261
+ host: "pi",
51262
+ 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.",
51263
+ stdout: "text",
51264
+ output: {
51265
+ PreToolUse: {
51266
+ type: "string",
51267
+ description: "plain text read by src/entries/pi.ts"
51268
+ },
51269
+ PostToolUse: {
51270
+ type: "string",
51271
+ description: "plain text read by src/entries/pi.ts"
51272
+ },
51273
+ UserPromptSubmit: {
51274
+ type: "string",
51275
+ description: "plain text read by src/entries/pi.ts"
51276
+ },
51277
+ SessionStart: {
51278
+ type: "string",
51279
+ description: "plain text read by src/entries/pi.ts"
51280
+ }
51281
+ }
51282
+ };
51283
+
51284
+ // tests/fixtures/host-schemas/opencode.json
51285
+ var opencode_default = {
51286
+ host: "opencode",
51287
+ 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.",
51288
+ stdout: "text",
51289
+ output: {
51290
+ PreToolUse: {
51291
+ type: "string",
51292
+ description: "plain text read by the context-mode OpenCode plugin"
51293
+ },
51294
+ PostToolUse: {
51295
+ type: "string",
51296
+ description: "plain text read by the context-mode OpenCode plugin"
51297
+ },
51298
+ UserPromptSubmit: {
51299
+ type: "string",
51300
+ description: "plain text read by the context-mode OpenCode plugin"
51301
+ },
51302
+ SessionStart: {
51303
+ type: "string",
51304
+ description: "plain text read by the context-mode OpenCode plugin"
51305
+ }
51306
+ }
51307
+ };
51308
+
51309
+ // src/core/ops/hook-shape.ts
51310
+ var HOST_SHAPES = {
51311
+ "claude-code": claude_code_default,
51312
+ codex: codex_default,
51313
+ gemini: gemini_default,
51314
+ qwen: qwen_default,
51315
+ "copilot-cli": copilot_cli_default,
51316
+ vscode: vscode_default,
51317
+ kiro: kiro_default,
51318
+ zcode: zcode_default,
51319
+ pi: pi_default,
51320
+ opencode: opencode_default
51321
+ };
51322
+ var NOTE_KEYS = /* @__PURE__ */ new Set(["$schema", "title", "description", "definitions", "default"]);
51323
+ var RULE_KEYS = /* @__PURE__ */ new Set(["type", "enum", "const", "required", "properties", "additionalProperties", "items", "allOf", "$ref"]);
51324
+ function isObject5(v) {
51325
+ return typeof v === "object" && v !== null && !Array.isArray(v);
51326
+ }
51327
+ function typeOf(v) {
51328
+ if (v === null) return "null";
51329
+ if (Array.isArray(v)) return "array";
51330
+ return typeof v;
51331
+ }
51332
+ function hasType(v, t) {
51333
+ if (t === "integer") return Number.isInteger(v);
51334
+ return typeOf(v) === t;
51335
+ }
51336
+ function same(a, b) {
51337
+ return JSON.stringify(a) === JSON.stringify(b);
51338
+ }
51339
+ function resolve3(root, ref) {
51340
+ const parts = ref.split("/");
51341
+ if (parts[0] !== "#") throw new Error(`hook-shape: only local $ref is read, got ${ref}`);
51342
+ let at = root;
51343
+ for (const p of parts.slice(1)) at = isObject5(at) ? at[p] : void 0;
51344
+ if (!isObject5(at)) throw new Error(`hook-shape: $ref ${ref} names nothing`);
51345
+ return at;
51346
+ }
51347
+ function shapeErrors(schema, value, root = schema, at = "$") {
51348
+ for (const k of Object.keys(schema)) {
51349
+ if (!NOTE_KEYS.has(k) && !RULE_KEYS.has(k)) throw new Error(`hook-shape: keyword ${k} at ${at} is not read by the checker`);
51350
+ }
51351
+ const errs = [];
51352
+ if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve3(root, schema.$ref), value, root, at));
51353
+ if (Array.isArray(schema.allOf)) for (const s of schema.allOf) errs.push(...shapeErrors(s, value, root, at));
51354
+ if (schema.type !== void 0) {
51355
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
51356
+ if (!types.some((t) => hasType(value, String(t)))) return [...errs, `${at}: ${typeOf(value)} is not ${types.join(" or ")}`];
51357
+ }
51358
+ 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)}`);
51359
+ if (Object.hasOwn(schema, "const") && !same(schema.const, value)) errs.push(`${at}: ${JSON.stringify(value)} is not ${JSON.stringify(schema.const)}`);
51360
+ if (isObject5(value)) {
51361
+ const props = isObject5(schema.properties) ? schema.properties : {};
51362
+ if (Array.isArray(schema.required)) {
51363
+ for (const r of schema.required) if (!Object.hasOwn(value, String(r))) errs.push(`${at}: ${String(r)} is required`);
51364
+ }
51365
+ for (const [k, v] of Object.entries(value)) {
51366
+ if (Object.hasOwn(props, k)) errs.push(...shapeErrors(props[k], v, root, `${at}.${k}`));
51367
+ else if (schema.additionalProperties === false) errs.push(`${at}: ${k} is not a known key`);
51368
+ else if (isObject5(schema.additionalProperties)) errs.push(...shapeErrors(schema.additionalProperties, v, root, `${at}.${k}`));
51369
+ }
51370
+ }
51371
+ if (Array.isArray(value) && isObject5(schema.items)) {
51372
+ const items = schema.items;
51373
+ value.forEach((v, n) => errs.push(...shapeErrors(items, v, root, `${at}[${n}]`)));
51374
+ }
51375
+ return errs;
51376
+ }
51377
+ function replyErrors(agent, event, stdout) {
51378
+ const host = HOST_SHAPES[agent];
51379
+ const schema = host.output[event];
51380
+ if (schema === void 0) return [`${agent} has no ${event} reply schema`];
51381
+ if (host.stdout === "text") return shapeErrors(schema, stdout);
51382
+ let value;
51383
+ try {
51384
+ value = JSON.parse(stdout);
51385
+ } catch {
51386
+ return [`${agent} ${event}: stdout is not JSON`];
51387
+ }
51388
+ return shapeErrors(schema, value);
51389
+ }
51390
+
49541
51391
  // src/core/sandbox/host-node.ts
49542
51392
  var BUN_BE_BUN_ENV = "BUN_BE_BUN";
49543
51393
  function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
@@ -49666,14 +51516,14 @@ function pluginHooksFromReply(m, pluginId) {
49666
51516
  function askPluginHooks(env, pluginId, cwd) {
49667
51517
  const bin = whichBin("codex", env);
49668
51518
  if (!bin) return Promise.resolve({ kind: "absent" });
49669
- return new Promise((resolve6) => {
51519
+ return new Promise((resolve7) => {
49670
51520
  let asked;
49671
51521
  const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
49672
51522
  let f;
49673
51523
  try {
49674
51524
  f = spawnForm(bin, ["app-server"], env);
49675
51525
  } catch {
49676
- resolve6({ kind: "silent" });
51526
+ resolve7({ kind: "silent" });
49677
51527
  return;
49678
51528
  }
49679
51529
  const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
@@ -49683,7 +51533,7 @@ function askPluginHooks(env, pluginId, cwd) {
49683
51533
  let result;
49684
51534
  const settle3 = () => {
49685
51535
  clearTimeout(grace);
49686
- resolve6(done_(result));
51536
+ resolve7(done_(result));
49687
51537
  };
49688
51538
  let grace;
49689
51539
  const finish2 = (v) => {
@@ -49767,7 +51617,7 @@ var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answ
49767
51617
  var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
49768
51618
  var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
49769
51619
  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) {
51620
+ function isObject6(v) {
49771
51621
  return typeof v === "object" && v !== null && !Array.isArray(v);
49772
51622
  }
49773
51623
  function loadFixture(bundleDir2, agent) {
@@ -49779,10 +51629,10 @@ function loadFixture(bundleDir2, agent) {
49779
51629
  } catch (err) {
49780
51630
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
49781
51631
  }
49782
- if (!isObject5(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
51632
+ if (!isObject6(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
49783
51633
  if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
49784
51634
  const e = all[agent];
49785
- if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
51635
+ if (!isObject6(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
49786
51636
  return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
49787
51637
  }
49788
51638
  return { event: e.event, payload: e.payload };
@@ -49800,39 +51650,11 @@ var CWD_KEY = {
49800
51650
  opencode: "directory"
49801
51651
  };
49802
51652
  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"];
51653
+ return worktree !== void 0 && isObject6(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
51654
+ }
49818
51655
  function isNativeShape(agent, stdout, exitCode, killed, event) {
49819
51656
  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
- }
51657
+ return stdout.length === 0 || replyErrors(agent, event, stdout).length === 0;
49836
51658
  }
49837
51659
  var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
49838
51660
  function readProbePayload(cwd, ranged) {
@@ -49857,9 +51679,9 @@ function isReadShape(stdout) {
49857
51679
  } catch {
49858
51680
  return false;
49859
51681
  }
49860
- if (!isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
51682
+ if (!isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
49861
51683
  const r = out.hookSpecificOutput.updatedToolOutput;
49862
- if (!isObject5(r) || r.type !== "text" || !isObject5(r.file)) return false;
51684
+ if (!isObject6(r) || r.type !== "text" || !isObject6(r.file)) return false;
49863
51685
  const f = r.file;
49864
51686
  return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
49865
51687
  }
@@ -49887,11 +51709,49 @@ function isPassThrough(stdout) {
49887
51709
  } catch {
49888
51710
  return false;
49889
51711
  }
49890
- return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
51712
+ return !isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
51713
+ }
51714
+ var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
51715
+ async function mediaProbe(i, timeoutMs) {
51716
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
51717
+ try {
51718
+ const filePath = path7.join(home, "d5-media-probe.png");
51719
+ writeFileSync3(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
51720
+ const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
51721
+ const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
51722
+ cwd: i.bundleDir,
51723
+ env: node3.env,
51724
+ signal: i.signal,
51725
+ timeoutMs,
51726
+ stdin: JSON.stringify({
51727
+ session_id: "d5-media-probe",
51728
+ transcript_path: "",
51729
+ cwd: home,
51730
+ hook_event_name: "PreToolUse",
51731
+ tool_name: "Read",
51732
+ tool_use_id: "toolu_d5_media_probe",
51733
+ tool_input: { file_path: filePath }
51734
+ })
51735
+ });
51736
+ return r.stdout.toString("utf8");
51737
+ } finally {
51738
+ rmSync4(home, { recursive: true, force: true });
51739
+ }
51740
+ }
51741
+ function isDeny(stdout) {
51742
+ if (stdout.trim() === "") return false;
51743
+ let out;
51744
+ try {
51745
+ out = JSON.parse(stdout);
51746
+ } catch {
51747
+ return false;
51748
+ }
51749
+ return isObject6(out) && isObject6(out.hookSpecificOutput) && out.hookSpecificOutput.permissionDecision === "deny";
49891
51750
  }
49892
51751
  async function readProbeDetail(i, timeoutMs) {
49893
51752
  if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
49894
51753
  if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
51754
+ if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
49895
51755
  return null;
49896
51756
  }
49897
51757
  function codexHookJournaled(db) {
@@ -49922,6 +51782,36 @@ async function codexPluginTrust(i) {
49922
51782
  if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
49923
51783
  return null;
49924
51784
  }
51785
+ function codexStopPayload(cwd) {
51786
+ return {
51787
+ session_id: "d5-stop-probe",
51788
+ turn_id: "d5-stop-turn",
51789
+ transcript_path: null,
51790
+ cwd,
51791
+ hook_event_name: "Stop",
51792
+ model: "d5-probe",
51793
+ permission_mode: "default",
51794
+ stop_hook_active: false,
51795
+ last_assistant_message: "d5 stop probe"
51796
+ };
51797
+ }
51798
+ async function codexStopDetail(i, timeoutMs) {
51799
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-stop-"));
51800
+ try {
51801
+ const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, [DATA_DIR_ENV]: home });
51802
+ const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
51803
+ cwd: i.bundleDir,
51804
+ env: node3.env,
51805
+ signal: i.signal,
51806
+ timeoutMs,
51807
+ stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
51808
+ });
51809
+ const logged = existsSync13(path7.join(home, HOOK_ERROR_LOG_FILE));
51810
+ return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
51811
+ } finally {
51812
+ rmSync4(home, { recursive: true, force: true });
51813
+ }
51814
+ }
49925
51815
  async function checkHookRoundTrip(i) {
49926
51816
  if (i.agent === "codex") {
49927
51817
  const trust = await codexPluginTrust(i);
@@ -49963,13 +51853,19 @@ async function checkHookRoundTrip(i) {
49963
51853
  if (n >= minPairs && ms <= HOOK_P95_MS) break;
49964
51854
  }
49965
51855
  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;
51856
+ const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
49967
51857
  if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
49968
51858
  return row("PASS", DOCTOR_PASS_DETAIL);
49969
51859
  }
49970
51860
 
49971
51861
  // src/core/hooks/fallback.ts
49972
- import { join as join13, resolve as resolve3 } from "node:path";
51862
+ import { join as join13, resolve as resolve4 } from "node:path";
51863
+
51864
+ // src/core/policy/read-media.ts
51865
+ import { extname } from "node:path";
51866
+ var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
51867
+
51868
+ // src/core/hooks/fallback.ts
49973
51869
  var fs = process.getBuiltinModule("node:fs");
49974
51870
  function homeOf(env) {
49975
51871
  return env.HOME ?? env.USERPROFILE ?? "";
@@ -50150,7 +52046,7 @@ function buildReportHead(input) {
50150
52046
 
50151
52047
  // src/core/ops/doctor-issue.ts
50152
52048
  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";
52049
+ import { closeSync as closeSync2, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync6, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
50154
52050
  import { delimiter, join as join15 } from "node:path";
50155
52051
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
50156
52052
  function tildeOf(env) {
@@ -50203,17 +52099,17 @@ function hookLogTail(env) {
50203
52099
  const file2 = hookLogPath(env);
50204
52100
  if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
50205
52101
  try {
50206
- const fd = openSync(file2, "r");
52102
+ const fd = openSync2(file2, "r");
50207
52103
  try {
50208
52104
  const size = fstatSync(fd).size;
50209
52105
  const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
50210
52106
  const buf = Buffer.alloc(size - start);
50211
- readSync(fd, buf, 0, buf.length, start);
52107
+ readSync2(fd, buf, 0, buf.length, start);
50212
52108
  const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
50213
52109
  if (start > 0) lines.shift();
50214
52110
  return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
50215
52111
  } finally {
50216
- closeSync(fd);
52112
+ closeSync2(fd);
50217
52113
  }
50218
52114
  } catch (err) {
50219
52115
  return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
@@ -50326,7 +52222,7 @@ async function writeIssueReport(i) {
50326
52222
  const dir = join15(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
50327
52223
  mkdirSync6(dir, { recursive: true });
50328
52224
  const file2 = join15(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
50329
- writeFileSync3(file2, body);
52225
+ writeFileSync4(file2, body);
50330
52226
  const shown2 = tilde(file2);
50331
52227
  const title = issueTitle(i.adapter.id, i.rows);
50332
52228
  const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
@@ -50500,9 +52396,9 @@ var ctxDoctor = Object.freeze({
50500
52396
  });
50501
52397
 
50502
52398
  // src/core/tools/execute.ts
50503
- import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
52399
+ import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "node:fs";
50504
52400
  import { tmpdir as tmpdir3 } from "node:os";
50505
- import { dirname as dirname9, join as join17, parse as parse5, resolve as resolve4 } from "node:path";
52401
+ import { dirname as dirname9, join as join17, parse as parse5, resolve as resolve5 } from "node:path";
50506
52402
 
50507
52403
  // src/core/index/select.ts
50508
52404
  var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
@@ -50688,7 +52584,7 @@ async function handler3(raw, ctx) {
50688
52584
  const cwd = ctx.project.worktree;
50689
52585
  const extra = { ...PLAIN_OUTPUT_ENV2 };
50690
52586
  if (input.file !== void 0) {
50691
- const abs = resolve4(cwd, input.file);
52587
+ const abs = resolve5(cwd, input.file);
50692
52588
  const bad = fileError(input.file, abs, ctx.project.containmentRoot);
50693
52589
  if (bad !== null) return fail4(bad);
50694
52590
  extra.CTX_FILE = abs;
@@ -50707,7 +52603,7 @@ async function handler3(raw, ctx) {
50707
52603
  } else {
50708
52604
  tmpDir = mkdtempSync2(join17(tmpdir3(), TMP_PREFIX));
50709
52605
  const file2 = join17(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
50710
- writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
52606
+ writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
50711
52607
  argv = scriptArgv(input.language, runtime, file2);
50712
52608
  }
50713
52609
  if (input.background === true) {
@@ -50743,7 +52639,7 @@ var ctxExecute = {
50743
52639
 
50744
52640
  // src/core/tools/index.ts
50745
52641
  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";
52642
+ import { dirname as dirname10, extname as extname2, join as join19, relative as relative3, resolve as resolve6 } from "node:path";
50747
52643
 
50748
52644
  // src/core/index/walk.ts
50749
52645
  import { readdirSync as readdirSync8, readFileSync as readFileSync12, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
@@ -51030,18 +52926,18 @@ function request(u, conn, proxy, signal) {
51030
52926
  const host = bare(u.hostname);
51031
52927
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
51032
52928
  const path8 = u.pathname + u.search;
51033
- return new Promise((resolve6, reject) => {
52929
+ return new Promise((resolve7, reject) => {
51034
52930
  const onErr = (err) => reject(fail5(causeCode(err)));
51035
52931
  if (proxy === void 0) {
51036
52932
  const mod = u.protocol === "https:" ? https : http;
51037
52933
  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();
52934
+ req.on("response", resolve7).on("error", onErr).end();
51039
52935
  return;
51040
52936
  }
51041
52937
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
51042
52938
  if (u.protocol === "http:") {
51043
52939
  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();
52940
+ req.on("response", resolve7).on("error", onErr).end();
51045
52941
  return;
51046
52942
  }
51047
52943
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -51061,16 +52957,16 @@ function request(u, conn, proxy, signal) {
51061
52957
  headers: { host: u.host },
51062
52958
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
51063
52959
  });
51064
- req.on("response", resolve6).on("error", onErr).end();
52960
+ req.on("response", resolve7).on("error", onErr).end();
51065
52961
  });
51066
52962
  tunnel.end();
51067
52963
  });
51068
52964
  }
51069
52965
  function readBody(res) {
51070
- return new Promise((resolve6, reject) => {
52966
+ return new Promise((resolve7, reject) => {
51071
52967
  const parts = [];
51072
52968
  res.on("data", (b) => parts.push(b));
51073
- res.on("end", () => resolve6(Buffer.concat(parts)));
52969
+ res.on("end", () => resolve7(Buffer.concat(parts)));
51074
52970
  res.on("error", (err) => reject(fail5(causeCode(err))));
51075
52971
  res.on("aborted", () => reject(fail5("ECONNRESET")));
51076
52972
  });
@@ -54927,7 +56823,7 @@ function userLabel(label2) {
54927
56823
  return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
54928
56824
  }
54929
56825
  function kindOfPath(p) {
54930
- return EXT_KIND[extname(p).toLowerCase()] ?? "text";
56826
+ return EXT_KIND[extname2(p).toLowerCase()] ?? "text";
54931
56827
  }
54932
56828
  function kindOfType(contentType) {
54933
56829
  const semi = contentType.indexOf(";");
@@ -54948,7 +56844,7 @@ function missingOrOutside(given, abs, root) {
54948
56844
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
54949
56845
  }
54950
56846
  function pathItems(input, project) {
54951
- const abs = resolve5(project.worktree, input.path);
56847
+ const abs = resolve6(project.worktree, input.path);
54952
56848
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
54953
56849
  const base = relative3(project.worktree, abs);
54954
56850
  if (statSync7(abs).isDirectory()) {
@@ -55464,7 +57360,7 @@ function readWeek(raw, lastMs) {
55464
57360
  }
55465
57361
  return days;
55466
57362
  }
55467
- var EMPTY3 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
57363
+ var EMPTY4 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
55468
57364
  function totals(r) {
55469
57365
  const produced = Number(r.produced);
55470
57366
  const returned = Number(r.returned);
@@ -55504,7 +57400,7 @@ function sum(groups) {
55504
57400
  produced: t.produced + g.produced,
55505
57401
  returned: t.returned + g.returned,
55506
57402
  saved: t.saved + g.saved
55507
- }), EMPTY3);
57403
+ }), EMPTY4);
55508
57404
  }
55509
57405
  function reductionPct(t) {
55510
57406
  if (t.calls === 0) return 0;
@@ -55698,8 +57594,8 @@ function report(f, sessionId, agent) {
55698
57594
  ] : []
55699
57595
  ];
55700
57596
  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);
57597
+ for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY4, g]));
57598
+ if (!agents.has(agent)) agents.set(agent, EMPTY4);
55703
57599
  lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
55704
57600
  const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
55705
57601
  lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + right("Session", STATS_KIND_W) + right("Project", STATS_KIND_W));
@@ -55759,10 +57655,10 @@ var ctxStats = Object.freeze({
55759
57655
  });
55760
57656
 
55761
57657
  // src/core/ops/host-write.ts
55762
- import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
57658
+ import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync7, writeFileSync as writeFileSync6 } from "node:fs";
55763
57659
  import { dirname as dirname11, join as join20 } from "node:path";
55764
57660
  function defaultWrite(file2, text) {
55765
- writeFileSync5(file2, text, "utf8");
57661
+ writeFileSync6(file2, text, "utf8");
55766
57662
  }
55767
57663
  function hostConfigPath(agent, home, env) {
55768
57664
  const own4 = OWN_MCP_ENTRY[agent];
@@ -55829,7 +57725,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
55829
57725
  }
55830
57726
 
55831
57727
  // src/core/ops/uninstall.ts
55832
- import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
57728
+ import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync7, writeFileSync as writeFileSync7 } from "node:fs";
55833
57729
  import { join as join21 } from "node:path";
55834
57730
  function row2(area, before, after) {
55835
57731
  return { area, before, after };
@@ -55837,7 +57733,7 @@ function row2(area, before, after) {
55837
57733
  function stopServers(configDir, projectKey) {
55838
57734
  const stopped = listLiveOwners(configDir, projectKey);
55839
57735
  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");
57736
+ for (const serverId of stopped) writeFileSync7(join21(dir, serverId + OWNER_STOP_EXT), "", "utf8");
55841
57737
  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
57738
  }
55843
57739
  function rootOrNull(adapter, env) {
@@ -56482,7 +58378,7 @@ async function startServer(argv, env) {
56482
58378
  }
56483
58379
  installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
56484
58380
  handle = serveStdio(createServer);
56485
- await new Promise((resolve6) => process.once("exit", () => resolve6()));
58381
+ await new Promise((resolve7) => process.once("exit", () => resolve7()));
56486
58382
  }
56487
58383
  if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) {
56488
58384
  const [, , ...cliArgs] = process.argv;