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.
@@ -322,6 +322,31 @@ var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
322
322
  var JQ_COMMAND = "jq";
323
323
  var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
324
324
  var READ_PATH_LIST_KEY = "filePaths";
325
+ var READ_MEDIA_TYPES = Object.freeze({
326
+ png: { exts: [".png"], sig: [{ at: 0, bytes: [137, 80, 78, 71, 13, 10, 26, 10] }] },
327
+ jpeg: { exts: [".jpg", ".jpeg"], sig: [{ at: 0, bytes: [255, 216, 255] }] },
328
+ gif: { exts: [".gif"], sig: [{ at: 0, bytes: [71, 73, 70, 56] }] },
329
+ // "GIF8"
330
+ webp: { exts: [".webp"], sig: [{ at: 0, bytes: [82, 73, 70, 70] }, { at: 8, bytes: [87, 69, 66, 80] }] },
331
+ // "RIFF" .... "WEBP"
332
+ pdf: { exts: [".pdf"], sig: [{ at: 0, bytes: [37, 80, 68, 70, 45] }] }
333
+ // "%PDF-"
334
+ });
335
+ var READ_MEDIA_SNIFF_BYTES = 12;
336
+ var READ_IMAGES = Object.freeze(["png", "jpeg", "gif", "webp"]);
337
+ var READ_IMAGES_AND_PDF = Object.freeze([...READ_IMAGES, "pdf"]);
338
+ var READ_MEDIA_BY_AGENT = Object.freeze({
339
+ "claude-code": READ_IMAGES_AND_PDF,
340
+ gemini: READ_IMAGES_AND_PDF,
341
+ qwen: READ_IMAGES_AND_PDF,
342
+ opencode: READ_IMAGES_AND_PDF,
343
+ pi: READ_IMAGES,
344
+ vscode: READ_IMAGES,
345
+ "copilot-cli": [],
346
+ codex: [],
347
+ kiro: [],
348
+ zcode: []
349
+ });
325
350
  var OWN_TOOL_PREFIX = "ctx_";
326
351
  var SHELL_TOOL = "Bash";
327
352
  var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
@@ -431,7 +456,7 @@ var DECISION_ANSWERS_KEY = "answers";
431
456
  var DECISION_OPTION_KEY = "option";
432
457
  var DECISION_LABEL_JOIN = " | ";
433
458
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
434
- var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
459
+ var BUNDLE_SHA = true ? "f75e51d580374d518a8ceefc1422a009ffe67311" : void 0;
435
460
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
436
461
  var DOCTOR_LABEL = Object.freeze({
437
462
  D1: "version",
@@ -684,10 +709,12 @@ var REGEX_ESCAPE = "\\";
684
709
  var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
685
710
  var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
686
711
  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";
712
+ 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)";
687
713
  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`;
688
714
  function D5_SLOW_DETAIL(ms) {
689
715
  return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
690
716
  }
717
+ var D5_STOP_DETAIL = "Codex Stop event: the hook did not give an empty or Codex Stop reply, or it logged a hook error";
691
718
  var D5_FIX = "run ctx_upgrade";
692
719
  var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
693
720
  function D10_DETAIL(mode) {
@@ -1235,10 +1262,17 @@ function encode(ev, d, _extra) {
1235
1262
  // src/adapters/codex.ts
1236
1263
  var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
1237
1264
  var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
1265
+ var STOP_EVENT = "Stop";
1266
+ var EMPTY = { stdout: "", exitCode: 0 };
1238
1267
  function decode2(raw) {
1268
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
1269
+ const p = raw;
1270
+ return { event: STOP_EVENT, agent: "codex", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
1271
+ }
1239
1272
  return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
1240
1273
  }
1241
1274
  function encode2(ev, d, _extra) {
1275
+ if (ev.event === STOP_EVENT) return EMPTY;
1242
1276
  return encodeClaudeShape(ev, d, false);
1243
1277
  }
1244
1278
 
@@ -1254,7 +1288,7 @@ var GEMINI_EVENTS = {
1254
1288
  var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
1255
1289
  var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
1256
1290
  var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
1257
- var EMPTY = { stdout: "", exitCode: 0 };
1291
+ var EMPTY2 = { stdout: "", exitCode: 0 };
1258
1292
  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";
1259
1293
  function own(p, key) {
1260
1294
  return Object.hasOwn(p, key) ? p[key] : void 0;
@@ -1295,7 +1329,13 @@ function readResult2(resp) {
1295
1329
  const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
1296
1330
  const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
1297
1331
  const err = obj === void 0 ? void 0 : own(obj, "error");
1298
- return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
1332
+ const info = { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
1333
+ if (hasMediaPart(llm)) info.keep = true;
1334
+ return info;
1335
+ }
1336
+ function hasMediaPart(llm) {
1337
+ const parts = Array.isArray(llm) ? llm : [llm];
1338
+ return parts.some((p) => typeof p === "object" && p !== null && (Object.hasOwn(p, "inlineData") || Object.hasOwn(p, "fileData")));
1299
1339
  }
1300
1340
  var URL_STARTS = ["https://", "http://"];
1301
1341
  var URL_TRAIL = `.,;:!?)]}>'"`;
@@ -1362,15 +1402,15 @@ function decode3(raw) {
1362
1402
  function encode3(ev, d, _extra) {
1363
1403
  switch (d.kind) {
1364
1404
  case "allow":
1365
- return EMPTY;
1405
+ return EMPTY2;
1366
1406
  case "hint":
1367
- if (!HINT_EVENTS.includes(ev.event)) return EMPTY;
1407
+ if (!HINT_EVENTS.includes(ev.event)) return EMPTY2;
1368
1408
  return { stdout: JSON.stringify({ hookSpecificOutput: { additionalContext: d.text } }), exitCode: 0 };
1369
1409
  case "deny":
1370
- if (!DENY_EVENTS.includes(ev.event)) return EMPTY;
1410
+ if (!DENY_EVENTS.includes(ev.event)) return EMPTY2;
1371
1411
  return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
1372
1412
  case "replace":
1373
- if (ev.event !== "PostToolUse") return EMPTY;
1413
+ if (ev.event !== "PostToolUse") return EMPTY2;
1374
1414
  return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
1375
1415
  }
1376
1416
  }
@@ -1490,21 +1530,21 @@ function decode5(raw) {
1490
1530
  if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
1491
1531
  return ev;
1492
1532
  }
1493
- var EMPTY2 = { stdout: "", exitCode: 0 };
1533
+ var EMPTY3 = { stdout: "", exitCode: 0 };
1494
1534
  function encode5(ev, d, _extra) {
1495
1535
  switch (d.kind) {
1496
1536
  case "allow":
1497
- return EMPTY2;
1537
+ return EMPTY3;
1498
1538
  case "hint":
1499
- return ev.event === "PostToolUse" ? EMPTY2 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
1539
+ return ev.event === "PostToolUse" ? EMPTY3 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
1500
1540
  case "deny":
1501
- if (ev.event !== "PreToolUse") return EMPTY2;
1541
+ if (ev.event !== "PreToolUse") return EMPTY3;
1502
1542
  return {
1503
1543
  stdout: JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }),
1504
1544
  exitCode: 0
1505
1545
  };
1506
1546
  case "replace":
1507
- if (ev.event !== "PostToolUse") return EMPTY2;
1547
+ if (ev.event !== "PostToolUse") return EMPTY3;
1508
1548
  return { stdout: JSON.stringify({ modifiedResult: { resultType: RESULT_SUCCESS, textResultForLlm: d.output } }), exitCode: 0 };
1509
1549
  }
1510
1550
  }
@@ -2636,7 +2676,7 @@ var HEAD_BYTES = "-c";
2636
2676
  var HEAD_BYTES_LONG = "--bytes";
2637
2677
  var GREP_COUNT_SHORT = "c";
2638
2678
  var GREP_COUNT_LONG = "--count";
2639
- var EMPTY3 = () => ({ cmds: [], simple: null });
2679
+ var EMPTY4 = () => ({ cmds: [], simple: null });
2640
2680
  var at = (p, k = 0) => p.toks[p.i + k];
2641
2681
  var isOp = (t, text) => t !== void 0 && t.kind === "op" && t.text === text;
2642
2682
  var isWord = (t, text) => t !== void 0 && t.kind === "word" && t.text === text;
@@ -2753,7 +2793,7 @@ function compound(p, body) {
2753
2793
  p.depth++;
2754
2794
  if (p.depth > MAX_NEST_DEPTH) {
2755
2795
  p.err = "nesting-too-deep";
2756
- return EMPTY3();
2796
+ return EMPTY4();
2757
2797
  }
2758
2798
  const cmds = body();
2759
2799
  p.depth--;
@@ -2881,7 +2921,7 @@ function simple(p) {
2881
2921
  words2.push(t);
2882
2922
  p.i++;
2883
2923
  }
2884
- if (p.i === first) return EMPTY3();
2924
+ if (p.i === first) return EMPTY4();
2885
2925
  const raw = p.src.slice(p.toks[first].start, p.toks[p.i - 1].end);
2886
2926
  if (words2.length === 0) return { cmds: carrier(raw), simple: null };
2887
2927
  const text = (t) => t.kind === "word" ? dequote(t.text) : t.text;
@@ -2892,9 +2932,9 @@ function simple(p) {
2892
2932
  }
2893
2933
  function element(p) {
2894
2934
  const t = at(p);
2895
- if (t === void 0) return EMPTY3();
2935
+ if (t === void 0) return EMPTY4();
2896
2936
  if (t.kind === "op") {
2897
- if (t.text !== SUBSHELL_OPEN) return EMPTY3();
2937
+ if (t.text !== SUBSHELL_OPEN) return EMPTY4();
2898
2938
  return compound(p, () => {
2899
2939
  p.i++;
2900
2940
  const body = list(p, NO_STOP);
@@ -2927,10 +2967,10 @@ function element(p) {
2927
2967
  return compound(p, () => caseBody(p));
2928
2968
  case KW.coproc:
2929
2969
  p.err = "coproc";
2930
- return EMPTY3();
2970
+ return EMPTY4();
2931
2971
  case KW.select:
2932
2972
  p.err = "select";
2933
- return EMPTY3();
2973
+ return EMPTY4();
2934
2974
  case KW.function: {
2935
2975
  p.i++;
2936
2976
  const nameTok = at(p);
@@ -2954,7 +2994,7 @@ function element(p) {
2954
2994
  function pipeline(p) {
2955
2995
  if (isWord(at(p), NOT)) p.i++;
2956
2996
  const all = [];
2957
- let last2 = EMPTY3();
2997
+ let last2 = EMPTY4();
2958
2998
  while (p.err === null) {
2959
2999
  last2 = element(p);
2960
3000
  append(all, last2.cmds);
@@ -3311,21 +3351,21 @@ function cdTarget(words2) {
3311
3351
  function walk(script, cwd, depth, found) {
3312
3352
  let dir = cwd;
3313
3353
  for (const stages of psParse(script)) {
3314
- const head = stages[0];
3315
- if (head.words.length === 0) continue;
3316
- const name = cmdName(head.words[0]);
3354
+ const head2 = stages[0];
3355
+ if (head2.words.length === 0) continue;
3356
+ const name = cmdName(head2.words[0]);
3317
3357
  if (stages.length === 1 && CD_COMMANDS.includes(name)) {
3318
- const t = cdTarget(head.words);
3358
+ const t = cdTarget(head2.words);
3319
3359
  if (t !== null) dir = resolve(dir, t);
3320
3360
  continue;
3321
3361
  }
3322
- const inner = depth < MAX_NEST_DEPTH ? nestedScript(name, head.words) : null;
3362
+ const inner = depth < MAX_NEST_DEPTH ? nestedScript(name, head2.words) : null;
3323
3363
  if (inner !== null) {
3324
3364
  walk(inner, dir, depth + 1, found);
3325
3365
  continue;
3326
3366
  }
3327
- if (head.toFile || head.chained) continue;
3328
- const d = psDump(head.words);
3367
+ if (head2.toFile || head2.chained) continue;
3368
+ const d = psDump(head2.words);
3329
3369
  if (d === null || d.bounded) continue;
3330
3370
  let shown2 = true;
3331
3371
  for (let k = 1; k < stages.length; k++) {
@@ -3968,6 +4008,33 @@ function READ_DENY_MESSAGE(path8, size, prefix = "") {
3968
4008
  return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
3969
4009
  }
3970
4010
 
4011
+ // src/core/policy/read-media.ts
4012
+ import { extname } from "node:path";
4013
+ var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
4014
+ function head(abs) {
4015
+ let fd = null;
4016
+ try {
4017
+ fd = openSync(abs, "r");
4018
+ const buf = Buffer.alloc(READ_MEDIA_SNIFF_BYTES);
4019
+ const n = readSync(fd, buf, 0, READ_MEDIA_SNIFF_BYTES, 0);
4020
+ return buf.subarray(0, n);
4021
+ } catch {
4022
+ return null;
4023
+ } finally {
4024
+ if (fd !== null) closeSync(fd);
4025
+ }
4026
+ }
4027
+ function isMediaRead(agent, abs) {
4028
+ const types = READ_MEDIA_BY_AGENT[agent] ?? [];
4029
+ if (types.length === 0) return false;
4030
+ const ext = extname(abs).toLowerCase();
4031
+ const named2 = types.filter((t) => READ_MEDIA_TYPES[t].exts.includes(ext));
4032
+ if (named2.length === 0) return false;
4033
+ const bytes5 = head(abs);
4034
+ if (bytes5 === null) return false;
4035
+ return named2.some((t) => READ_MEDIA_TYPES[t].sig.every((s) => s.bytes.every((b, i) => bytes5[s.at + i] === b)));
4036
+ }
4037
+
3971
4038
  // src/core/policy/decide.ts
3972
4039
  var { statSync } = process.getBuiltinModule("node:fs");
3973
4040
  var BASH = "Bash";
@@ -4171,7 +4238,7 @@ function read(ev, row5, input) {
4171
4238
  for (const p of readPaths(input)) {
4172
4239
  const abs = resolve3(ev.cwd, p);
4173
4240
  const size = fileSize(abs);
4174
- if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
4241
+ if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
4175
4242
  }
4176
4243
  }
4177
4244
  return ALLOW;
@@ -7935,14 +8002,14 @@ function lineBlocks(src, md) {
7935
8002
  close();
7936
8003
  } else {
7937
8004
  const opener = md ? fenceOf(line) : "";
7938
- const head = md && opener === "" ? headingOf(line) : void 0;
7939
- const table3 = md && opener === "" && head === void 0 && line.includes("|");
7940
- if (md && start >= 0 && (table3 !== inTable || opener !== "" || head !== void 0)) close();
8005
+ const head2 = md && opener === "" ? headingOf(line) : void 0;
8006
+ const table3 = md && opener === "" && head2 === void 0 && line.includes("|");
8007
+ if (md && start >= 0 && (table3 !== inTable || opener !== "" || head2 !== void 0)) close();
7941
8008
  add(pos, eol, table3);
7942
8009
  fence = opener;
7943
8010
  if (opener !== "") fenceInfo = { fence: opener, openEnd: eol, closeStart: -1 };
7944
- if (head !== void 0) {
7945
- heading = head;
8011
+ if (head2 !== void 0) {
8012
+ heading = head2;
7946
8013
  close();
7947
8014
  }
7948
8015
  }
@@ -8374,9 +8441,9 @@ function hasDigit(t) {
8374
8441
  return false;
8375
8442
  }
8376
8443
  function similarity(tpl, toks) {
8377
- let same = 0;
8378
- for (let i = 0; i < tpl.length; i++) if (tpl[i] === toks[i] || tpl[i] === "<*>" || toks[i] === "<*>") same++;
8379
- return same / tpl.length;
8444
+ let same2 = 0;
8445
+ for (let i = 0; i < tpl.length; i++) if (tpl[i] === toks[i] || tpl[i] === "<*>" || toks[i] === "<*>") same2++;
8446
+ return same2 / tpl.length;
8380
8447
  }
8381
8448
  function lineShape(text) {
8382
8449
  const all = text.split("\n");
@@ -8670,10 +8737,10 @@ function bigFile(abs) {
8670
8737
  return false;
8671
8738
  }
8672
8739
  }
8673
- function bigRead(input, cwd) {
8740
+ function bigRead(agent, input, cwd) {
8674
8741
  if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
8675
8742
  const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
8676
- return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)));
8743
+ return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)));
8677
8744
  }
8678
8745
  function failureOutput(agent, raw, err, cwdFallback = "") {
8679
8746
  const row5 = getAdapter(agent);
@@ -8686,7 +8753,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
8686
8753
  const kind = kindOf(row5, name);
8687
8754
  if (kind === null) return allow();
8688
8755
  const cwd = firstString(raw, HOOK_FAIL_CWD_KEYS) || cwdFallback;
8689
- if (kind === "read" && !bigRead(inputOf(raw), cwd)) return allow();
8756
+ if (kind === "read" && !bigRead(agent, inputOf(raw), cwd)) return allow();
8690
8757
  const redirect = kind === "read" ? HOOK_FAIL_REDIRECT.read : HOOK_FAIL_REDIRECT[kind];
8691
8758
  const reason = prefixToolNames(redirect, row5.toolNamePrefix) + "\n" + HOOK_FAIL_LINE(errorLabel(err), row5.toolNamePrefix);
8692
8759
  return row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd, turn: 0 }, { kind: "deny", reason });
@@ -8701,7 +8768,7 @@ var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
8701
8768
  // src/core/hooks/dispatch.ts
8702
8769
  var { lstatSync: lstatSync2, readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
8703
8770
  var ALLOW2 = { kind: "allow" };
8704
- var EMPTY4 = { stdout: "", exitCode: 0 };
8771
+ var EMPTY5 = { stdout: "", exitCode: 0 };
8705
8772
  var DIGIT_0 = 48;
8706
8773
  function isAgentId(s) {
8707
8774
  return AGENT_IDS.includes(s);
@@ -8715,7 +8782,7 @@ function str2(v) {
8715
8782
  async function handleHook(agent, raw, env) {
8716
8783
  if (!isAgentId(agent)) {
8717
8784
  process.stderr.write("hooks: unknown agent " + JSON.stringify(agent) + "\n");
8718
- return EMPTY4;
8785
+ return EMPTY5;
8719
8786
  }
8720
8787
  const row5 = getAdapter(agent);
8721
8788
  const fail7 = (stage, err, line) => {
@@ -8731,6 +8798,7 @@ async function handleHook(agent, raw, env) {
8731
8798
  } catch (err) {
8732
8799
  return fail7("decode", err);
8733
8800
  }
8801
+ if (ev.event === "Stop") return row5.encode(ev, ALLOW2);
8734
8802
  let project;
8735
8803
  try {
8736
8804
  fault(env, "project");
@@ -9090,16 +9158,16 @@ function hostToolResult(file2, sessionId, env) {
9090
9158
  return st.isFile() && st.size <= PERSISTED_OUTPUT_MAX_BYTES && isInside(projects, file2);
9091
9159
  }
9092
9160
  function wholeOutput(result, sessionId, env) {
9093
- const head = result.text ?? "";
9094
- if (result.persistedPath === void 0) return head;
9161
+ const head2 = result.text ?? "";
9162
+ if (result.persistedPath === void 0) return head2;
9095
9163
  try {
9096
9164
  if (!hostToolResult(result.persistedPath, sessionId, env)) {
9097
9165
  logHookError(env, "claude-code", "persisted-output", new Error("persisted output path is outside this session's tool-results dir or too large; kept the head"));
9098
- return head;
9166
+ return head2;
9099
9167
  }
9100
9168
  return readFileSync4(result.persistedPath, "utf8");
9101
9169
  } catch {
9102
- return head;
9170
+ return head2;
9103
9171
  }
9104
9172
  }
9105
9173
  async function lastPrompt(project, sessionId) {
@@ -9112,8 +9180,8 @@ async function lastPrompt(project, sessionId) {
9112
9180
  function mainLabel(tool, ev) {
9113
9181
  const cmd = str2(tool.input.command) ?? str2(tool.input.file_path) ?? "";
9114
9182
  const nl = cmd.indexOf("\n");
9115
- const head = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
9116
- return head + "#" + (tool.callId ?? String(ev.turn ?? 0));
9183
+ const head2 = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
9184
+ return head2 + "#" + (tool.callId ?? String(ev.turn ?? 0));
9117
9185
  }
9118
9186
  function indexDetached(project, sessionId, sourceId, label2, text, chunks) {
9119
9187
  void openDb(project).then((db) => {
@@ -11830,7 +11898,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
11830
11898
  return (payload, ctx) => fn(shape, payload, ctx);
11831
11899
  };
11832
11900
  let fastpass;
11833
- const isObject6 = isObject3;
11901
+ const isObject7 = isObject3;
11834
11902
  const jit = !globalConfig.jitless;
11835
11903
  const allowsEval2 = allowsEval;
11836
11904
  const fastEnabled = jit && allowsEval2.value;
@@ -11839,7 +11907,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
11839
11907
  inst._zod.parse = (payload, ctx) => {
11840
11908
  value ?? (value = _normalized.value);
11841
11909
  const input = payload.value;
11842
- if (!isObject6(input)) {
11910
+ if (!isObject7(input)) {
11843
11911
  payload.issues.push({
11844
11912
  expected: "object",
11845
11913
  code: "invalid_type",
@@ -20459,10 +20527,10 @@ function startArgv(argv) {
20459
20527
  return sh === null ? null : [sh, ...argv];
20460
20528
  }
20461
20529
  function runProcess(argv, o) {
20462
- return new Promise((resolve9) => {
20530
+ return new Promise((resolve10) => {
20463
20531
  const isWin2 = process.platform === "win32";
20464
20532
  const start = startArgv(argv);
20465
- if (start === null) return resolve9(NOT_STARTED);
20533
+ if (start === null) return resolve10(NOT_STARTED);
20466
20534
  let child;
20467
20535
  try {
20468
20536
  child = spawn(start[0], start.slice(1), {
@@ -20476,7 +20544,7 @@ function runProcess(argv, o) {
20476
20544
  windowsHide: true
20477
20545
  });
20478
20546
  } catch {
20479
- return resolve9(NOT_STARTED);
20547
+ return resolve10(NOT_STARTED);
20480
20548
  }
20481
20549
  const stdoutChunks = [];
20482
20550
  const stderrChunks = [];
@@ -20501,7 +20569,7 @@ function runProcess(argv, o) {
20501
20569
  settled = true;
20502
20570
  clearTimeout(timer);
20503
20571
  o.signal.removeEventListener("abort", onAbort);
20504
- resolve9({
20572
+ resolve10({
20505
20573
  stdout: Buffer.concat(stdoutChunks),
20506
20574
  stderr: Buffer.concat(stderrChunks),
20507
20575
  exitCode,
@@ -20775,9 +20843,9 @@ function relevance(db, given, scope, ctx, nm, ms, indexed) {
20775
20843
  more.push({ q, pos: offset });
20776
20844
  return;
20777
20845
  }
20778
- const head = "Query " + JSON.stringify(q) + ":";
20779
- lines.push(head);
20780
- used += bytes2(head) + 1;
20846
+ const head2 = "Query " + JSON.stringify(q) + ":";
20847
+ lines.push(head2);
20848
+ used += bytes2(head2) + 1;
20781
20849
  const again = /* @__PURE__ */ new Map();
20782
20850
  const mine = /* @__PURE__ */ new Set();
20783
20851
  let cut = -1;
@@ -21035,8 +21103,8 @@ function answer2(db, ctx, ownIds, queries, share, own2) {
21035
21103
  if (ctx.signal.aborted) break;
21036
21104
  let hits = ownIds.length === 0 ? [] : ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, void 0, ownIds);
21037
21105
  if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
21038
- const head = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
21039
- let used = bytes3(head) + 1;
21106
+ const head2 = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
21107
+ let used = bytes3(head2) + 1;
21040
21108
  const body = [];
21041
21109
  for (const h of hits) {
21042
21110
  const key = chunkKey(h.sourceId, h.ord);
@@ -21054,7 +21122,7 @@ function answer2(db, ctx, ownIds, queries, share, own2) {
21054
21122
  }
21055
21123
  if (hits.length === 0) body.push("No hits.");
21056
21124
  else if (body.length === 0) body.push("No new section.");
21057
- lines.push(head, ...body);
21125
+ lines.push(head2, ...body);
21058
21126
  }
21059
21127
  return { lines, seen };
21060
21128
  }
@@ -24697,20 +24765,20 @@ function highestTag(stdout, tag2) {
24697
24765
  }
24698
24766
  return best;
24699
24767
  }
24700
- function versionRow(head, installed, tag2, source, latest, tail) {
24768
+ function versionRow(head2, installed, tag2, source, latest, tail) {
24701
24769
  const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
24702
- if (cmp === 0) return pass3("D1", head + D1_LATEST_PASS(tag2, source) + tail);
24703
- if (cmp > 0) return pass3("D1", head + D1_LATEST_AHEAD(tag2, source, latest) + tail);
24704
- return fail4("D1", head + D1_LATEST_UPDATE(tag2, source, latest) + tail, DOCTOR_FIX_UPGRADE);
24770
+ if (cmp === 0) return pass3("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
24771
+ if (cmp > 0) return pass3("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
24772
+ return fail4("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, DOCTOR_FIX_UPGRADE);
24705
24773
  }
24706
24774
  async function checkVersion(i) {
24707
24775
  if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
24708
- const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
24709
- if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
24776
+ const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
24777
+ if (i.version === void 0) return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
24710
24778
  const tag2 = channelOf(i.version);
24711
24779
  const git2 = findRuntime(GIT_BIN, i.env);
24712
24780
  const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
24713
- if (npm.ok) return versionRow(head, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
24781
+ if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
24714
24782
  let cause = D1_GIT_MISSING;
24715
24783
  if (git2 !== null) {
24716
24784
  const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
@@ -24721,13 +24789,13 @@ async function checkVersion(i) {
24721
24789
  });
24722
24790
  if (r.exitCode === 0 && r.killed === null) {
24723
24791
  const latest = highestTag(r.stdout.toString("utf8"), tag2);
24724
- if (latest !== void 0) return versionRow(head, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
24792
+ if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
24725
24793
  cause = D1_GIT_NO_TAG(tag2);
24726
24794
  } else {
24727
24795
  cause = gitCause(r, i.timeoutMs);
24728
24796
  }
24729
24797
  }
24730
- return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
24798
+ return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
24731
24799
  }
24732
24800
  function numbers(v) {
24733
24801
  const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
@@ -24784,87 +24852,1898 @@ function checkShell(env) {
24784
24852
  }
24785
24853
 
24786
24854
  // src/core/ops/doctor-hook.ts
24787
- import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2 } from "node:fs";
24855
+ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24788
24856
  import { tmpdir as tmpdir2 } from "node:os";
24789
24857
  import path7 from "node:path";
24790
24858
 
24791
- // src/core/sandbox/host-node.ts
24792
- var BUN_BE_BUN_ENV = "BUN_BE_BUN";
24793
- function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
24794
- if (host.bun === void 0) return { file: host.execPath, env };
24795
- const node = find2("javascript", env);
24796
- if (node !== null) return { file: node, env };
24797
- return { file: host.execPath, env: { ...env, [BUN_BE_BUN_ENV]: "1" } };
24798
- }
24799
-
24800
- // src/setup/codex-trust.ts
24801
- import { createHash } from "node:crypto";
24802
- import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
24803
- import path6 from "node:path";
24804
- import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
24805
-
24806
- // src/setup/spawn-bin.ts
24807
- import { spawnSync } from "node:child_process";
24808
- import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
24809
- import path5 from "node:path";
24810
- var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
24811
- var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
24812
- var DEFAULT_COMSPEC = "cmd.exe";
24813
- function envGet(env, k) {
24814
- return env[Object.keys(env).find((x) => x.toUpperCase() === k) ?? k];
24815
- }
24816
- function whichBin(bin, env, platform = process.platform) {
24817
- const get = (k) => envGet(env, k);
24818
- const win = platform === "win32";
24819
- const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
24820
- const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
24821
- for (const dir of pathEntries(get("PATH") ?? "", platform)) {
24822
- for (const n of names) {
24823
- const f = path5.join(dir, n);
24824
- try {
24825
- accessSync2(f, fsc.X_OK);
24826
- if (statSync6(f).isFile()) return f;
24827
- } catch {
24859
+ // tests/fixtures/host-schemas/claude-code.json
24860
+ var claude_code_default = {
24861
+ host: "claude-code",
24862
+ 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.",
24863
+ output: {
24864
+ PreToolUse: {
24865
+ title: "Claude Code 2.1.274 PreToolUse reply",
24866
+ definitions: {
24867
+ Specific: {
24868
+ type: "object",
24869
+ additionalProperties: false,
24870
+ properties: {
24871
+ hookEventName: {
24872
+ type: "string",
24873
+ const: "PreToolUse"
24874
+ },
24875
+ permissionDecision: {
24876
+ type: "string",
24877
+ enum: [
24878
+ "allow",
24879
+ "deny",
24880
+ "ask",
24881
+ "defer"
24882
+ ]
24883
+ },
24884
+ permissionDecisionReason: {
24885
+ type: "string"
24886
+ },
24887
+ updatedInput: {
24888
+ type: "object"
24889
+ },
24890
+ additionalContext: {
24891
+ type: "string"
24892
+ },
24893
+ permissionDisplay: {
24894
+ description: "@internal Desktop host only"
24895
+ }
24896
+ },
24897
+ required: [
24898
+ "hookEventName"
24899
+ ]
24900
+ }
24901
+ },
24902
+ type: "object",
24903
+ additionalProperties: false,
24904
+ properties: {
24905
+ continue: {
24906
+ type: "boolean"
24907
+ },
24908
+ suppressOutput: {
24909
+ type: "boolean"
24910
+ },
24911
+ stopReason: {
24912
+ type: "string"
24913
+ },
24914
+ decision: {
24915
+ type: "string",
24916
+ enum: [
24917
+ "approve",
24918
+ "block"
24919
+ ]
24920
+ },
24921
+ systemMessage: {
24922
+ type: "string"
24923
+ },
24924
+ terminalSequence: {
24925
+ type: "string"
24926
+ },
24927
+ reason: {
24928
+ type: "string"
24929
+ },
24930
+ hookSpecificOutput: {
24931
+ allOf: [
24932
+ {
24933
+ $ref: "#/definitions/Specific"
24934
+ }
24935
+ ]
24936
+ }
24937
+ }
24938
+ },
24939
+ PostToolUse: {
24940
+ title: "Claude Code 2.1.274 PostToolUse reply",
24941
+ definitions: {
24942
+ Specific: {
24943
+ type: "object",
24944
+ additionalProperties: false,
24945
+ properties: {
24946
+ hookEventName: {
24947
+ type: "string",
24948
+ const: "PostToolUse"
24949
+ },
24950
+ additionalContext: {
24951
+ type: "string"
24952
+ },
24953
+ classifierContext: {
24954
+ type: "string"
24955
+ },
24956
+ updatedToolOutput: {
24957
+ description: "the tool's own output object"
24958
+ },
24959
+ updatedMCPToolOutput: {
24960
+ description: "an MCP tool's own output"
24961
+ }
24962
+ },
24963
+ required: [
24964
+ "hookEventName"
24965
+ ]
24966
+ }
24967
+ },
24968
+ type: "object",
24969
+ additionalProperties: false,
24970
+ properties: {
24971
+ continue: {
24972
+ type: "boolean"
24973
+ },
24974
+ suppressOutput: {
24975
+ type: "boolean"
24976
+ },
24977
+ stopReason: {
24978
+ type: "string"
24979
+ },
24980
+ decision: {
24981
+ type: "string",
24982
+ enum: [
24983
+ "approve",
24984
+ "block"
24985
+ ]
24986
+ },
24987
+ systemMessage: {
24988
+ type: "string"
24989
+ },
24990
+ terminalSequence: {
24991
+ type: "string"
24992
+ },
24993
+ reason: {
24994
+ type: "string"
24995
+ },
24996
+ hookSpecificOutput: {
24997
+ allOf: [
24998
+ {
24999
+ $ref: "#/definitions/Specific"
25000
+ }
25001
+ ]
25002
+ }
25003
+ }
25004
+ },
25005
+ UserPromptSubmit: {
25006
+ title: "Claude Code 2.1.274 UserPromptSubmit reply",
25007
+ definitions: {
25008
+ Specific: {
25009
+ type: "object",
25010
+ additionalProperties: false,
25011
+ properties: {
25012
+ hookEventName: {
25013
+ type: "string",
25014
+ const: "UserPromptSubmit"
25015
+ },
25016
+ additionalContext: {
25017
+ type: "string"
25018
+ },
25019
+ sessionTitle: {
25020
+ type: "string"
25021
+ },
25022
+ suppressOriginalPrompt: {
25023
+ type: "boolean"
25024
+ }
25025
+ },
25026
+ required: [
25027
+ "hookEventName"
25028
+ ]
25029
+ }
25030
+ },
25031
+ type: "object",
25032
+ additionalProperties: false,
25033
+ properties: {
25034
+ continue: {
25035
+ type: "boolean"
25036
+ },
25037
+ suppressOutput: {
25038
+ type: "boolean"
25039
+ },
25040
+ stopReason: {
25041
+ type: "string"
25042
+ },
25043
+ decision: {
25044
+ type: "string",
25045
+ enum: [
25046
+ "approve",
25047
+ "block"
25048
+ ]
25049
+ },
25050
+ systemMessage: {
25051
+ type: "string"
25052
+ },
25053
+ terminalSequence: {
25054
+ type: "string"
25055
+ },
25056
+ reason: {
25057
+ type: "string"
25058
+ },
25059
+ hookSpecificOutput: {
25060
+ allOf: [
25061
+ {
25062
+ $ref: "#/definitions/Specific"
25063
+ }
25064
+ ]
25065
+ }
25066
+ }
25067
+ },
25068
+ SessionStart: {
25069
+ title: "Claude Code 2.1.274 SessionStart reply",
25070
+ definitions: {
25071
+ Specific: {
25072
+ type: "object",
25073
+ additionalProperties: false,
25074
+ properties: {
25075
+ hookEventName: {
25076
+ type: "string",
25077
+ const: "SessionStart"
25078
+ },
25079
+ additionalContext: {
25080
+ type: "string"
25081
+ },
25082
+ initialUserMessage: {
25083
+ type: "string"
25084
+ },
25085
+ sessionTitle: {
25086
+ type: "string"
25087
+ },
25088
+ watchPaths: {
25089
+ type: "array",
25090
+ items: {
25091
+ type: "string"
25092
+ }
25093
+ },
25094
+ reloadSkills: {
25095
+ type: "boolean"
25096
+ }
25097
+ },
25098
+ required: [
25099
+ "hookEventName"
25100
+ ]
25101
+ }
25102
+ },
25103
+ type: "object",
25104
+ additionalProperties: false,
25105
+ properties: {
25106
+ continue: {
25107
+ type: "boolean"
25108
+ },
25109
+ suppressOutput: {
25110
+ type: "boolean"
25111
+ },
25112
+ stopReason: {
25113
+ type: "string"
25114
+ },
25115
+ decision: {
25116
+ type: "string",
25117
+ enum: [
25118
+ "approve",
25119
+ "block"
25120
+ ]
25121
+ },
25122
+ systemMessage: {
25123
+ type: "string"
25124
+ },
25125
+ terminalSequence: {
25126
+ type: "string"
25127
+ },
25128
+ reason: {
25129
+ type: "string"
25130
+ },
25131
+ hookSpecificOutput: {
25132
+ allOf: [
25133
+ {
25134
+ $ref: "#/definitions/Specific"
25135
+ }
25136
+ ]
25137
+ }
24828
25138
  }
24829
25139
  }
24830
25140
  }
24831
- return void 0;
24832
- }
24833
- var CMD_QUOTE_CHARS = '"&|<>^()!';
24834
- var CMD_PERCENT = "%";
24835
- var CMD_SUBSTRING_MARK = ":";
24836
- var CMD_DYNAMIC_VARS = Object.freeze(["CD", "DATE", "TIME", "RANDOM", "ERRORLEVEL", "CMDEXTVERSION", "CMDCMDLINE", "HIGHESTNUMANODENUMBER"]);
24837
- function needsCmdQuotes(a) {
24838
- if (a === "") return true;
24839
- for (const c of a) if (c.trim() === "" || CMD_QUOTE_CHARS.includes(c)) return true;
24840
- return false;
24841
- }
24842
- function expandablePercent(text, env) {
24843
- const names = new Set(CMD_DYNAMIC_VARS);
24844
- for (const k of Object.keys(env)) names.add(k.toUpperCase());
24845
- for (let i = text.indexOf(CMD_PERCENT); i >= 0; i = text.indexOf(CMD_PERCENT, i + 1)) {
24846
- for (let j = text.indexOf(CMD_PERCENT, i + 1); j >= 0; j = text.indexOf(CMD_PERCENT, j + 1)) {
24847
- const inner = text.slice(i + 1, j);
24848
- const cut = inner.indexOf(CMD_SUBSTRING_MARK);
24849
- const name = cut < 0 ? inner : inner.slice(0, cut);
24850
- if (name !== "" && names.has(name.toUpperCase())) return `${CMD_PERCENT}${inner}${CMD_PERCENT}`;
25141
+ };
25142
+
25143
+ // tests/fixtures/host-schemas/codex.json
25144
+ var codex_default = {
25145
+ host: "codex",
25146
+ source: "github.com/openai/codex tag rust-v0.166.0 codex-rs/hooks/schema/generated/*.command.output.schema.json",
25147
+ output: {
25148
+ PreToolUse: {
25149
+ $schema: "http://json-schema.org/draft-07/schema#",
25150
+ additionalProperties: false,
25151
+ definitions: {
25152
+ PreToolUseDecisionWire: {
25153
+ enum: [
25154
+ "approve",
25155
+ "block"
25156
+ ],
25157
+ type: "string"
25158
+ },
25159
+ PreToolUseHookSpecificOutputWire: {
25160
+ additionalProperties: false,
25161
+ properties: {
25162
+ additionalContext: {
25163
+ default: null,
25164
+ type: "string"
25165
+ },
25166
+ hookEventName: {
25167
+ const: "PreToolUse",
25168
+ type: "string"
25169
+ },
25170
+ permissionDecision: {
25171
+ allOf: [
25172
+ {
25173
+ $ref: "#/definitions/PreToolUsePermissionDecisionWire"
25174
+ }
25175
+ ],
25176
+ default: null
25177
+ },
25178
+ permissionDecisionReason: {
25179
+ default: null,
25180
+ type: "string"
25181
+ },
25182
+ updatedInput: {
25183
+ default: null
25184
+ }
25185
+ },
25186
+ required: [
25187
+ "hookEventName"
25188
+ ],
25189
+ type: "object"
25190
+ },
25191
+ PreToolUsePermissionDecisionWire: {
25192
+ enum: [
25193
+ "allow",
25194
+ "deny",
25195
+ "ask"
25196
+ ],
25197
+ type: "string"
25198
+ }
25199
+ },
25200
+ properties: {
25201
+ continue: {
25202
+ default: true,
25203
+ type: "boolean"
25204
+ },
25205
+ decision: {
25206
+ allOf: [
25207
+ {
25208
+ $ref: "#/definitions/PreToolUseDecisionWire"
25209
+ }
25210
+ ],
25211
+ default: null
25212
+ },
25213
+ hookSpecificOutput: {
25214
+ allOf: [
25215
+ {
25216
+ $ref: "#/definitions/PreToolUseHookSpecificOutputWire"
25217
+ }
25218
+ ],
25219
+ default: null
25220
+ },
25221
+ reason: {
25222
+ default: null,
25223
+ type: "string"
25224
+ },
25225
+ stopReason: {
25226
+ default: null,
25227
+ type: "string"
25228
+ },
25229
+ suppressOutput: {
25230
+ default: false,
25231
+ type: "boolean"
25232
+ },
25233
+ systemMessage: {
25234
+ default: null,
25235
+ type: "string"
25236
+ }
25237
+ },
25238
+ title: "pre-tool-use.command.output",
25239
+ type: "object"
25240
+ },
25241
+ PostToolUse: {
25242
+ $schema: "http://json-schema.org/draft-07/schema#",
25243
+ additionalProperties: false,
25244
+ definitions: {
25245
+ BlockDecisionWire: {
25246
+ enum: [
25247
+ "block"
25248
+ ],
25249
+ type: "string"
25250
+ },
25251
+ PostToolUseHookSpecificOutputWire: {
25252
+ additionalProperties: false,
25253
+ properties: {
25254
+ additionalContext: {
25255
+ default: null,
25256
+ type: "string"
25257
+ },
25258
+ hookEventName: {
25259
+ const: "PostToolUse",
25260
+ type: "string"
25261
+ },
25262
+ updatedMCPToolOutput: {
25263
+ default: null
25264
+ }
25265
+ },
25266
+ required: [
25267
+ "hookEventName"
25268
+ ],
25269
+ type: "object"
25270
+ }
25271
+ },
25272
+ properties: {
25273
+ continue: {
25274
+ default: true,
25275
+ type: "boolean"
25276
+ },
25277
+ decision: {
25278
+ allOf: [
25279
+ {
25280
+ $ref: "#/definitions/BlockDecisionWire"
25281
+ }
25282
+ ],
25283
+ default: null
25284
+ },
25285
+ hookSpecificOutput: {
25286
+ allOf: [
25287
+ {
25288
+ $ref: "#/definitions/PostToolUseHookSpecificOutputWire"
25289
+ }
25290
+ ],
25291
+ default: null
25292
+ },
25293
+ reason: {
25294
+ default: null,
25295
+ type: "string"
25296
+ },
25297
+ stopReason: {
25298
+ default: null,
25299
+ type: "string"
25300
+ },
25301
+ suppressOutput: {
25302
+ default: false,
25303
+ type: "boolean"
25304
+ },
25305
+ systemMessage: {
25306
+ default: null,
25307
+ type: "string"
25308
+ }
25309
+ },
25310
+ title: "post-tool-use.command.output",
25311
+ type: "object"
25312
+ },
25313
+ SessionStart: {
25314
+ $schema: "http://json-schema.org/draft-07/schema#",
25315
+ additionalProperties: false,
25316
+ definitions: {
25317
+ SessionStartHookSpecificOutputWire: {
25318
+ additionalProperties: false,
25319
+ properties: {
25320
+ additionalContext: {
25321
+ default: null,
25322
+ type: "string"
25323
+ },
25324
+ hookEventName: {
25325
+ const: "SessionStart",
25326
+ type: "string"
25327
+ }
25328
+ },
25329
+ required: [
25330
+ "hookEventName"
25331
+ ],
25332
+ type: "object"
25333
+ }
25334
+ },
25335
+ properties: {
25336
+ continue: {
25337
+ default: true,
25338
+ type: "boolean"
25339
+ },
25340
+ hookSpecificOutput: {
25341
+ allOf: [
25342
+ {
25343
+ $ref: "#/definitions/SessionStartHookSpecificOutputWire"
25344
+ }
25345
+ ],
25346
+ default: null
25347
+ },
25348
+ stopReason: {
25349
+ default: null,
25350
+ type: "string"
25351
+ },
25352
+ suppressOutput: {
25353
+ default: false,
25354
+ type: "boolean"
25355
+ },
25356
+ systemMessage: {
25357
+ default: null,
25358
+ type: "string"
25359
+ }
25360
+ },
25361
+ title: "session-start.command.output",
25362
+ type: "object"
25363
+ },
25364
+ UserPromptSubmit: {
25365
+ $schema: "http://json-schema.org/draft-07/schema#",
25366
+ additionalProperties: false,
25367
+ definitions: {
25368
+ BlockDecisionWire: {
25369
+ enum: [
25370
+ "block"
25371
+ ],
25372
+ type: "string"
25373
+ },
25374
+ UserPromptSubmitHookSpecificOutputWire: {
25375
+ additionalProperties: false,
25376
+ properties: {
25377
+ additionalContext: {
25378
+ default: null,
25379
+ type: "string"
25380
+ },
25381
+ hookEventName: {
25382
+ const: "UserPromptSubmit",
25383
+ type: "string"
25384
+ }
25385
+ },
25386
+ required: [
25387
+ "hookEventName"
25388
+ ],
25389
+ type: "object"
25390
+ }
25391
+ },
25392
+ properties: {
25393
+ continue: {
25394
+ default: true,
25395
+ type: "boolean"
25396
+ },
25397
+ decision: {
25398
+ allOf: [
25399
+ {
25400
+ $ref: "#/definitions/BlockDecisionWire"
25401
+ }
25402
+ ],
25403
+ default: null
25404
+ },
25405
+ hookSpecificOutput: {
25406
+ allOf: [
25407
+ {
25408
+ $ref: "#/definitions/UserPromptSubmitHookSpecificOutputWire"
25409
+ }
25410
+ ],
25411
+ default: null
25412
+ },
25413
+ reason: {
25414
+ default: null,
25415
+ type: "string"
25416
+ },
25417
+ stopReason: {
25418
+ default: null,
25419
+ type: "string"
25420
+ },
25421
+ suppressOutput: {
25422
+ default: false,
25423
+ type: "boolean"
25424
+ },
25425
+ systemMessage: {
25426
+ default: null,
25427
+ type: "string"
25428
+ }
25429
+ },
25430
+ title: "user-prompt-submit.command.output",
25431
+ type: "object"
25432
+ },
25433
+ Stop: {
25434
+ $schema: "http://json-schema.org/draft-07/schema#",
25435
+ additionalProperties: false,
25436
+ definitions: {
25437
+ BlockDecisionWire: {
25438
+ enum: [
25439
+ "block"
25440
+ ],
25441
+ type: "string"
25442
+ }
25443
+ },
25444
+ properties: {
25445
+ continue: {
25446
+ default: true,
25447
+ type: "boolean"
25448
+ },
25449
+ decision: {
25450
+ allOf: [
25451
+ {
25452
+ $ref: "#/definitions/BlockDecisionWire"
25453
+ }
25454
+ ],
25455
+ default: null
25456
+ },
25457
+ reason: {
25458
+ default: null,
25459
+ description: "Claude requires `reason` when `decision` is `block`; we enforce that semantic rule during output parsing rather than in the JSON schema.",
25460
+ type: "string"
25461
+ },
25462
+ stopReason: {
25463
+ default: null,
25464
+ type: "string"
25465
+ },
25466
+ suppressOutput: {
25467
+ default: false,
25468
+ type: "boolean"
25469
+ },
25470
+ systemMessage: {
25471
+ default: null,
25472
+ type: "string"
25473
+ }
25474
+ },
25475
+ title: "stop.command.output",
25476
+ type: "object"
24851
25477
  }
24852
25478
  }
24853
- return void 0;
24854
- }
24855
- function winCmdLine(file2, args, env = {}) {
24856
- for (const a of [file2, ...args]) {
24857
- const hit = expandablePercent(a, env);
24858
- if (hit !== void 0) throw new Error(`cannot run ${file2} through cmd.exe: cmd.exe expands ${hit} inside quotes, so the value ${JSON.stringify(a)} would change. Use a path and arguments without it`);
24859
- }
24860
- const q = (a) => needsCmdQuotes(a) ? `"${a.split('"').join('""')}"` : a;
24861
- return `"${[file2, ...args].map(q).join(" ")}"`;
24862
- }
24863
- function spawnForm(file2, args, env, platform = process.platform) {
24864
- if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
24865
- return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
24866
- }
24867
- return { command: file2, args, windowsVerbatimArguments: false };
25479
+ };
25480
+
25481
+ // tests/fixtures/host-schemas/gemini.json
25482
+ var gemini_default = {
25483
+ host: "gemini",
25484
+ 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.",
25485
+ output: {
25486
+ PreToolUse: {
25487
+ title: "Gemini CLI 0.67.0 BeforeTool reply",
25488
+ definitions: {
25489
+ Specific: {
25490
+ type: "object",
25491
+ additionalProperties: false,
25492
+ properties: {
25493
+ hookEventName: {
25494
+ type: "string"
25495
+ },
25496
+ tool_input: {
25497
+ type: "object"
25498
+ }
25499
+ }
25500
+ }
25501
+ },
25502
+ type: "object",
25503
+ additionalProperties: false,
25504
+ properties: {
25505
+ systemMessage: {
25506
+ type: "string"
25507
+ },
25508
+ suppressOutput: {
25509
+ type: "boolean"
25510
+ },
25511
+ continue: {
25512
+ type: "boolean"
25513
+ },
25514
+ stopReason: {
25515
+ type: "string"
25516
+ },
25517
+ decision: {
25518
+ type: "string",
25519
+ enum: [
25520
+ "allow",
25521
+ "deny",
25522
+ "block",
25523
+ "ask"
25524
+ ]
25525
+ },
25526
+ reason: {
25527
+ type: "string"
25528
+ },
25529
+ hookSpecificOutput: {
25530
+ allOf: [
25531
+ {
25532
+ $ref: "#/definitions/Specific"
25533
+ }
25534
+ ]
25535
+ }
25536
+ }
25537
+ },
25538
+ PostToolUse: {
25539
+ title: "Gemini CLI 0.67.0 AfterTool reply",
25540
+ definitions: {
25541
+ Specific: {
25542
+ type: "object",
25543
+ additionalProperties: false,
25544
+ properties: {
25545
+ hookEventName: {
25546
+ type: "string"
25547
+ },
25548
+ additionalContext: {
25549
+ type: "string"
25550
+ },
25551
+ tailToolCallRequest: {
25552
+ type: "object",
25553
+ additionalProperties: false,
25554
+ properties: {
25555
+ name: {
25556
+ type: "string"
25557
+ },
25558
+ args: {
25559
+ type: "object"
25560
+ }
25561
+ },
25562
+ required: [
25563
+ "name",
25564
+ "args"
25565
+ ]
25566
+ }
25567
+ }
25568
+ }
25569
+ },
25570
+ type: "object",
25571
+ additionalProperties: false,
25572
+ properties: {
25573
+ systemMessage: {
25574
+ type: "string"
25575
+ },
25576
+ suppressOutput: {
25577
+ type: "boolean"
25578
+ },
25579
+ continue: {
25580
+ type: "boolean"
25581
+ },
25582
+ stopReason: {
25583
+ type: "string"
25584
+ },
25585
+ decision: {
25586
+ type: "string",
25587
+ enum: [
25588
+ "allow",
25589
+ "deny",
25590
+ "block",
25591
+ "ask"
25592
+ ]
25593
+ },
25594
+ reason: {
25595
+ type: "string"
25596
+ },
25597
+ hookSpecificOutput: {
25598
+ allOf: [
25599
+ {
25600
+ $ref: "#/definitions/Specific"
25601
+ }
25602
+ ]
25603
+ }
25604
+ }
25605
+ },
25606
+ UserPromptSubmit: {
25607
+ title: "Gemini CLI 0.67.0 BeforeAgent reply",
25608
+ definitions: {
25609
+ Specific: {
25610
+ type: "object",
25611
+ additionalProperties: false,
25612
+ properties: {
25613
+ hookEventName: {
25614
+ type: "string"
25615
+ },
25616
+ additionalContext: {
25617
+ type: "string"
25618
+ }
25619
+ }
25620
+ }
25621
+ },
25622
+ type: "object",
25623
+ additionalProperties: false,
25624
+ properties: {
25625
+ systemMessage: {
25626
+ type: "string"
25627
+ },
25628
+ suppressOutput: {
25629
+ type: "boolean"
25630
+ },
25631
+ continue: {
25632
+ type: "boolean"
25633
+ },
25634
+ stopReason: {
25635
+ type: "string"
25636
+ },
25637
+ decision: {
25638
+ type: "string",
25639
+ enum: [
25640
+ "allow",
25641
+ "deny",
25642
+ "block",
25643
+ "ask"
25644
+ ]
25645
+ },
25646
+ reason: {
25647
+ type: "string"
25648
+ },
25649
+ hookSpecificOutput: {
25650
+ allOf: [
25651
+ {
25652
+ $ref: "#/definitions/Specific"
25653
+ }
25654
+ ]
25655
+ }
25656
+ }
25657
+ },
25658
+ SessionStart: {
25659
+ title: "Gemini CLI 0.67.0 SessionStart reply",
25660
+ definitions: {
25661
+ Specific: {
25662
+ type: "object",
25663
+ additionalProperties: false,
25664
+ properties: {
25665
+ hookEventName: {
25666
+ type: "string"
25667
+ },
25668
+ additionalContext: {
25669
+ type: "string"
25670
+ }
25671
+ }
25672
+ }
25673
+ },
25674
+ type: "object",
25675
+ additionalProperties: false,
25676
+ properties: {
25677
+ systemMessage: {
25678
+ type: "string"
25679
+ },
25680
+ suppressOutput: {
25681
+ type: "boolean"
25682
+ },
25683
+ continue: {
25684
+ type: "boolean"
25685
+ },
25686
+ stopReason: {
25687
+ type: "string"
25688
+ },
25689
+ decision: {
25690
+ type: "string",
25691
+ enum: [
25692
+ "allow",
25693
+ "deny",
25694
+ "block",
25695
+ "ask"
25696
+ ]
25697
+ },
25698
+ reason: {
25699
+ type: "string"
25700
+ },
25701
+ hookSpecificOutput: {
25702
+ allOf: [
25703
+ {
25704
+ $ref: "#/definitions/Specific"
25705
+ }
25706
+ ]
25707
+ }
25708
+ }
25709
+ }
25710
+ }
25711
+ };
25712
+
25713
+ // tests/fixtures/host-schemas/qwen.json
25714
+ var qwen_default = {
25715
+ host: "qwen",
25716
+ 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).",
25717
+ output: {
25718
+ PreToolUse: {
25719
+ title: "Qwen Code 0.26.7 PreToolUse reply",
25720
+ definitions: {
25721
+ Specific: {
25722
+ type: "object",
25723
+ additionalProperties: false,
25724
+ properties: {
25725
+ hookEventName: {
25726
+ type: "string",
25727
+ const: "PreToolUse"
25728
+ },
25729
+ permissionDecision: {
25730
+ type: "string",
25731
+ enum: [
25732
+ "allow",
25733
+ "deny",
25734
+ "ask"
25735
+ ]
25736
+ },
25737
+ permissionDecisionReason: {
25738
+ type: "string"
25739
+ },
25740
+ updatedInput: {
25741
+ type: "object"
25742
+ },
25743
+ additionalContext: {
25744
+ type: "string"
25745
+ }
25746
+ },
25747
+ required: [
25748
+ "hookEventName"
25749
+ ]
25750
+ }
25751
+ },
25752
+ type: "object",
25753
+ additionalProperties: false,
25754
+ properties: {
25755
+ continue: {
25756
+ type: "boolean"
25757
+ },
25758
+ stopReason: {
25759
+ type: "string"
25760
+ },
25761
+ suppressOutput: {
25762
+ type: "boolean"
25763
+ },
25764
+ systemMessage: {
25765
+ type: "string"
25766
+ },
25767
+ decision: {
25768
+ type: "string",
25769
+ enum: [
25770
+ "allow",
25771
+ "approve",
25772
+ "deny",
25773
+ "block",
25774
+ "ask"
25775
+ ]
25776
+ },
25777
+ reason: {
25778
+ type: "string"
25779
+ },
25780
+ hookSpecificOutput: {
25781
+ allOf: [
25782
+ {
25783
+ $ref: "#/definitions/Specific"
25784
+ }
25785
+ ]
25786
+ }
25787
+ }
25788
+ },
25789
+ PostToolUse: {
25790
+ title: "Qwen Code 0.26.7 PostToolUse reply",
25791
+ definitions: {
25792
+ Specific: {
25793
+ type: "object",
25794
+ additionalProperties: false,
25795
+ properties: {
25796
+ hookEventName: {
25797
+ type: "string",
25798
+ const: "PostToolUse"
25799
+ },
25800
+ additionalContext: {
25801
+ type: "string"
25802
+ }
25803
+ },
25804
+ required: [
25805
+ "hookEventName"
25806
+ ]
25807
+ }
25808
+ },
25809
+ type: "object",
25810
+ additionalProperties: false,
25811
+ properties: {
25812
+ continue: {
25813
+ type: "boolean"
25814
+ },
25815
+ stopReason: {
25816
+ type: "string"
25817
+ },
25818
+ suppressOutput: {
25819
+ type: "boolean"
25820
+ },
25821
+ systemMessage: {
25822
+ type: "string"
25823
+ },
25824
+ decision: {
25825
+ type: "string",
25826
+ enum: [
25827
+ "allow",
25828
+ "approve",
25829
+ "deny",
25830
+ "block",
25831
+ "ask"
25832
+ ]
25833
+ },
25834
+ reason: {
25835
+ type: "string"
25836
+ },
25837
+ hookSpecificOutput: {
25838
+ allOf: [
25839
+ {
25840
+ $ref: "#/definitions/Specific"
25841
+ }
25842
+ ]
25843
+ }
25844
+ }
25845
+ },
25846
+ UserPromptSubmit: {
25847
+ title: "Qwen Code 0.26.7 UserPromptSubmit reply",
25848
+ definitions: {
25849
+ Specific: {
25850
+ type: "object",
25851
+ additionalProperties: false,
25852
+ properties: {
25853
+ hookEventName: {
25854
+ type: "string",
25855
+ const: "UserPromptSubmit"
25856
+ },
25857
+ additionalContext: {
25858
+ type: "string"
25859
+ }
25860
+ },
25861
+ required: [
25862
+ "hookEventName"
25863
+ ]
25864
+ }
25865
+ },
25866
+ type: "object",
25867
+ additionalProperties: false,
25868
+ properties: {
25869
+ continue: {
25870
+ type: "boolean"
25871
+ },
25872
+ stopReason: {
25873
+ type: "string"
25874
+ },
25875
+ suppressOutput: {
25876
+ type: "boolean"
25877
+ },
25878
+ systemMessage: {
25879
+ type: "string"
25880
+ },
25881
+ decision: {
25882
+ type: "string",
25883
+ enum: [
25884
+ "allow",
25885
+ "approve",
25886
+ "deny",
25887
+ "block",
25888
+ "ask"
25889
+ ]
25890
+ },
25891
+ reason: {
25892
+ type: "string"
25893
+ },
25894
+ hookSpecificOutput: {
25895
+ allOf: [
25896
+ {
25897
+ $ref: "#/definitions/Specific"
25898
+ }
25899
+ ]
25900
+ }
25901
+ }
25902
+ },
25903
+ SessionStart: {
25904
+ title: "Qwen Code 0.26.7 SessionStart reply",
25905
+ definitions: {
25906
+ Specific: {
25907
+ type: "object",
25908
+ additionalProperties: false,
25909
+ properties: {
25910
+ hookEventName: {
25911
+ type: "string",
25912
+ const: "SessionStart"
25913
+ },
25914
+ additionalContext: {
25915
+ type: "string"
25916
+ }
25917
+ },
25918
+ required: [
25919
+ "hookEventName"
25920
+ ]
25921
+ }
25922
+ },
25923
+ type: "object",
25924
+ additionalProperties: false,
25925
+ properties: {
25926
+ continue: {
25927
+ type: "boolean"
25928
+ },
25929
+ stopReason: {
25930
+ type: "string"
25931
+ },
25932
+ suppressOutput: {
25933
+ type: "boolean"
25934
+ },
25935
+ systemMessage: {
25936
+ type: "string"
25937
+ },
25938
+ decision: {
25939
+ type: "string",
25940
+ enum: [
25941
+ "allow",
25942
+ "approve",
25943
+ "deny",
25944
+ "block",
25945
+ "ask"
25946
+ ]
25947
+ },
25948
+ reason: {
25949
+ type: "string"
25950
+ },
25951
+ hookSpecificOutput: {
25952
+ allOf: [
25953
+ {
25954
+ $ref: "#/definitions/Specific"
25955
+ }
25956
+ ]
25957
+ }
25958
+ }
25959
+ }
25960
+ }
25961
+ };
25962
+
25963
+ // tests/fixtures/host-schemas/copilot-cli.json
25964
+ var copilot_cli_default = {
25965
+ host: "copilot-cli",
25966
+ 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.",
25967
+ output: {
25968
+ PreToolUse: {
25969
+ title: "Copilot CLI 1.0.105 preToolUse reply",
25970
+ type: "object",
25971
+ additionalProperties: false,
25972
+ properties: {
25973
+ permissionDecision: {
25974
+ type: "string",
25975
+ enum: [
25976
+ "allow",
25977
+ "deny",
25978
+ "ask"
25979
+ ]
25980
+ },
25981
+ permissionDecisionReason: {
25982
+ type: "string"
25983
+ },
25984
+ modifiedArgs: {
25985
+ description: "unknown"
25986
+ },
25987
+ additionalContext: {
25988
+ type: "string"
25989
+ },
25990
+ suppressOutput: {
25991
+ type: "boolean"
25992
+ }
25993
+ }
25994
+ },
25995
+ PostToolUse: {
25996
+ title: "Copilot CLI 1.0.105 postToolUse reply",
25997
+ definitions: {
25998
+ ToolResultObject: {
25999
+ type: "object",
26000
+ additionalProperties: false,
26001
+ properties: {
26002
+ textResultForLlm: {
26003
+ type: "string"
26004
+ },
26005
+ binaryResultsForLlm: {
26006
+ type: "array",
26007
+ items: {
26008
+ type: "object"
26009
+ }
26010
+ },
26011
+ resultType: {
26012
+ type: "string",
26013
+ enum: [
26014
+ "success",
26015
+ "failure",
26016
+ "rejected",
26017
+ "denied",
26018
+ "timeout"
26019
+ ]
26020
+ },
26021
+ error: {
26022
+ type: "string"
26023
+ },
26024
+ sessionLog: {
26025
+ type: "string"
26026
+ },
26027
+ toolTelemetry: {
26028
+ type: "object"
26029
+ },
26030
+ toolReferences: {
26031
+ type: "array",
26032
+ items: {
26033
+ type: "string"
26034
+ }
26035
+ }
26036
+ },
26037
+ required: [
26038
+ "textResultForLlm",
26039
+ "resultType"
26040
+ ]
26041
+ }
26042
+ },
26043
+ type: "object",
26044
+ additionalProperties: false,
26045
+ properties: {
26046
+ modifiedResult: {
26047
+ allOf: [
26048
+ {
26049
+ $ref: "#/definitions/ToolResultObject"
26050
+ }
26051
+ ]
26052
+ },
26053
+ additionalContext: {
26054
+ type: "string"
26055
+ },
26056
+ suppressOutput: {
26057
+ type: "boolean"
26058
+ }
26059
+ }
26060
+ },
26061
+ UserPromptSubmit: {
26062
+ title: "Copilot CLI 1.0.105 userPromptSubmitted reply",
26063
+ type: "object",
26064
+ additionalProperties: false,
26065
+ properties: {
26066
+ modifiedPrompt: {
26067
+ type: "string"
26068
+ },
26069
+ additionalContext: {
26070
+ type: "string"
26071
+ },
26072
+ suppressOutput: {
26073
+ type: "boolean"
26074
+ },
26075
+ decision: {
26076
+ type: "string",
26077
+ const: "block"
26078
+ },
26079
+ reason: {
26080
+ type: "string"
26081
+ }
26082
+ }
26083
+ },
26084
+ SessionStart: {
26085
+ title: "Copilot CLI 1.0.105 sessionStart reply",
26086
+ type: "object",
26087
+ additionalProperties: false,
26088
+ properties: {
26089
+ additionalContext: {
26090
+ type: "string"
26091
+ },
26092
+ modifiedConfig: {
26093
+ type: "object"
26094
+ }
26095
+ }
26096
+ }
26097
+ }
26098
+ };
26099
+
26100
+ // tests/fixtures/host-schemas/vscode.json
26101
+ var vscode_default = {
26102
+ host: "vscode",
26103
+ 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').",
26104
+ output: {
26105
+ PreToolUse: {
26106
+ title: "VS Code Copilot Chat 0.44.0 PreToolUse reply",
26107
+ definitions: {
26108
+ Specific: {
26109
+ type: "object",
26110
+ additionalProperties: false,
26111
+ properties: {
26112
+ hookEventName: {
26113
+ type: "string"
26114
+ },
26115
+ permissionDecision: {
26116
+ type: "string",
26117
+ enum: [
26118
+ "allow",
26119
+ "deny",
26120
+ "ask"
26121
+ ]
26122
+ },
26123
+ permissionDecisionReason: {
26124
+ type: "string"
26125
+ },
26126
+ updatedInput: {
26127
+ type: "object"
26128
+ },
26129
+ additionalContext: {
26130
+ type: "string"
26131
+ }
26132
+ }
26133
+ }
26134
+ },
26135
+ type: "object",
26136
+ additionalProperties: false,
26137
+ properties: {
26138
+ hookSpecificOutput: {
26139
+ allOf: [
26140
+ {
26141
+ $ref: "#/definitions/Specific"
26142
+ }
26143
+ ]
26144
+ }
26145
+ }
26146
+ },
26147
+ PostToolUse: {
26148
+ title: "VS Code Copilot Chat 0.44.0 PostToolUse reply",
26149
+ definitions: {
26150
+ Specific: {
26151
+ type: "object",
26152
+ additionalProperties: false,
26153
+ properties: {
26154
+ hookEventName: {
26155
+ type: "string"
26156
+ },
26157
+ additionalContext: {
26158
+ type: "string"
26159
+ }
26160
+ }
26161
+ }
26162
+ },
26163
+ type: "object",
26164
+ additionalProperties: false,
26165
+ properties: {
26166
+ decision: {
26167
+ type: "string",
26168
+ const: "block"
26169
+ },
26170
+ reason: {
26171
+ type: "string"
26172
+ },
26173
+ hookSpecificOutput: {
26174
+ allOf: [
26175
+ {
26176
+ $ref: "#/definitions/Specific"
26177
+ }
26178
+ ]
26179
+ }
26180
+ }
26181
+ },
26182
+ UserPromptSubmit: {
26183
+ title: "VS Code Copilot Chat 0.44.0 UserPromptSubmit reply",
26184
+ definitions: {
26185
+ Specific: {
26186
+ type: "object",
26187
+ additionalProperties: false,
26188
+ properties: {
26189
+ hookEventName: {
26190
+ type: "string"
26191
+ },
26192
+ additionalContext: {
26193
+ type: "string"
26194
+ }
26195
+ }
26196
+ }
26197
+ },
26198
+ type: "object",
26199
+ additionalProperties: false,
26200
+ properties: {
26201
+ decision: {
26202
+ type: "string",
26203
+ const: "block"
26204
+ },
26205
+ reason: {
26206
+ type: "string"
26207
+ },
26208
+ hookSpecificOutput: {
26209
+ allOf: [
26210
+ {
26211
+ $ref: "#/definitions/Specific"
26212
+ }
26213
+ ]
26214
+ }
26215
+ }
26216
+ },
26217
+ SessionStart: {
26218
+ title: "VS Code Copilot Chat 0.44.0 SessionStart reply",
26219
+ definitions: {
26220
+ Specific: {
26221
+ type: "object",
26222
+ additionalProperties: false,
26223
+ properties: {
26224
+ hookEventName: {
26225
+ type: "string"
26226
+ },
26227
+ additionalContext: {
26228
+ type: "string"
26229
+ }
26230
+ }
26231
+ }
26232
+ },
26233
+ type: "object",
26234
+ additionalProperties: false,
26235
+ properties: {
26236
+ hookSpecificOutput: {
26237
+ allOf: [
26238
+ {
26239
+ $ref: "#/definitions/Specific"
26240
+ }
26241
+ ]
26242
+ }
26243
+ }
26244
+ }
26245
+ }
26246
+ };
26247
+
26248
+ // tests/fixtures/host-schemas/kiro.json
26249
+ var kiro_default = {
26250
+ host: "kiro",
26251
+ 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`)",
26252
+ mcpToolId: {
26253
+ 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",
26254
+ prefix: "mcp_",
26255
+ join: "_",
26256
+ maxLength: 64
26257
+ },
26258
+ hookStdin: {
26259
+ from: "function sJn: {session_id, hook_event_name, cwd} plus per trigger fields",
26260
+ UserPromptSubmit: ["session_id", "hook_event_name", "cwd", "prompt"],
26261
+ PreToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input"],
26262
+ PostToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input", "tool_response"],
26263
+ SessionStart: ["session_id", "hook_event_name", "cwd"]
26264
+ },
26265
+ hookOutputCapChars: 3e3,
26266
+ windowsHookShell: "child_process.spawn(command, {shell: true}) in the V3 hook process runner (class tje): COMSPEC (cmd.exe /d /s /c) on win32",
26267
+ stdout: "text",
26268
+ output: {
26269
+ 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" },
26270
+ 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" },
26271
+ 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" },
26272
+ 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" }
26273
+ }
26274
+ };
26275
+
26276
+ // tests/fixtures/host-schemas/zcode.json
26277
+ var zcode_default = {
26278
+ host: "zcode",
26279
+ 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.",
26280
+ output: {
26281
+ PreToolUse: {
26282
+ title: "ZCode 0.17.1 PreToolUse reply",
26283
+ definitions: {
26284
+ Specific: {
26285
+ type: "object",
26286
+ additionalProperties: false,
26287
+ properties: {
26288
+ additionalContext: {
26289
+ type: "string"
26290
+ },
26291
+ hookEventName: {
26292
+ type: "string",
26293
+ const: "PreToolUse"
26294
+ },
26295
+ permissionDecision: {
26296
+ type: "string",
26297
+ enum: [
26298
+ "allow",
26299
+ "ask",
26300
+ "deny"
26301
+ ]
26302
+ },
26303
+ permissionDecisionReason: {
26304
+ type: "string"
26305
+ },
26306
+ updatedInput: {
26307
+ description: "z.unknown()"
26308
+ }
26309
+ },
26310
+ required: [
26311
+ "hookEventName"
26312
+ ]
26313
+ }
26314
+ },
26315
+ type: "object",
26316
+ additionalProperties: false,
26317
+ properties: {
26318
+ additionalContext: {
26319
+ type: "string"
26320
+ },
26321
+ additional_context: {
26322
+ type: "string"
26323
+ },
26324
+ continue: {
26325
+ type: "boolean"
26326
+ },
26327
+ decision: {
26328
+ type: "string",
26329
+ enum: [
26330
+ "approve",
26331
+ "block"
26332
+ ]
26333
+ },
26334
+ reason: {
26335
+ type: "string"
26336
+ },
26337
+ stopReason: {
26338
+ type: "string"
26339
+ },
26340
+ suppressOutput: {
26341
+ type: "boolean"
26342
+ },
26343
+ systemMessage: {
26344
+ type: "string"
26345
+ },
26346
+ hookSpecificOutput: {
26347
+ allOf: [
26348
+ {
26349
+ $ref: "#/definitions/Specific"
26350
+ }
26351
+ ]
26352
+ }
26353
+ }
26354
+ },
26355
+ PostToolUse: {
26356
+ title: "ZCode 0.17.1 PostToolUse reply",
26357
+ definitions: {
26358
+ Specific: {
26359
+ type: "object",
26360
+ additionalProperties: false,
26361
+ properties: {
26362
+ additionalContext: {
26363
+ type: "string"
26364
+ },
26365
+ hookEventName: {
26366
+ type: "string",
26367
+ const: "PostToolUse"
26368
+ }
26369
+ },
26370
+ required: [
26371
+ "hookEventName"
26372
+ ]
26373
+ }
26374
+ },
26375
+ type: "object",
26376
+ additionalProperties: false,
26377
+ properties: {
26378
+ additionalContext: {
26379
+ type: "string"
26380
+ },
26381
+ additional_context: {
26382
+ type: "string"
26383
+ },
26384
+ continue: {
26385
+ type: "boolean"
26386
+ },
26387
+ decision: {
26388
+ type: "string",
26389
+ enum: [
26390
+ "approve",
26391
+ "block"
26392
+ ]
26393
+ },
26394
+ reason: {
26395
+ type: "string"
26396
+ },
26397
+ stopReason: {
26398
+ type: "string"
26399
+ },
26400
+ suppressOutput: {
26401
+ type: "boolean"
26402
+ },
26403
+ systemMessage: {
26404
+ type: "string"
26405
+ },
26406
+ hookSpecificOutput: {
26407
+ allOf: [
26408
+ {
26409
+ $ref: "#/definitions/Specific"
26410
+ }
26411
+ ]
26412
+ }
26413
+ }
26414
+ },
26415
+ UserPromptSubmit: {
26416
+ title: "ZCode 0.17.1 UserPromptSubmit reply",
26417
+ definitions: {
26418
+ Specific: {
26419
+ type: "object",
26420
+ additionalProperties: false,
26421
+ properties: {
26422
+ additionalContext: {
26423
+ type: "string"
26424
+ },
26425
+ hookEventName: {
26426
+ type: "string",
26427
+ const: "UserPromptSubmit"
26428
+ }
26429
+ },
26430
+ required: [
26431
+ "hookEventName"
26432
+ ]
26433
+ }
26434
+ },
26435
+ type: "object",
26436
+ additionalProperties: false,
26437
+ properties: {
26438
+ additionalContext: {
26439
+ type: "string"
26440
+ },
26441
+ additional_context: {
26442
+ type: "string"
26443
+ },
26444
+ continue: {
26445
+ type: "boolean"
26446
+ },
26447
+ decision: {
26448
+ type: "string",
26449
+ enum: [
26450
+ "approve",
26451
+ "block"
26452
+ ]
26453
+ },
26454
+ reason: {
26455
+ type: "string"
26456
+ },
26457
+ stopReason: {
26458
+ type: "string"
26459
+ },
26460
+ suppressOutput: {
26461
+ type: "boolean"
26462
+ },
26463
+ systemMessage: {
26464
+ type: "string"
26465
+ },
26466
+ hookSpecificOutput: {
26467
+ allOf: [
26468
+ {
26469
+ $ref: "#/definitions/Specific"
26470
+ }
26471
+ ]
26472
+ }
26473
+ }
26474
+ },
26475
+ SessionStart: {
26476
+ title: "ZCode 0.17.1 SessionStart reply",
26477
+ definitions: {
26478
+ Specific: {
26479
+ type: "object",
26480
+ additionalProperties: false,
26481
+ properties: {
26482
+ additionalContext: {
26483
+ type: "string"
26484
+ },
26485
+ hookEventName: {
26486
+ type: "string",
26487
+ const: "SessionStart"
26488
+ }
26489
+ },
26490
+ required: [
26491
+ "hookEventName"
26492
+ ]
26493
+ }
26494
+ },
26495
+ type: "object",
26496
+ additionalProperties: false,
26497
+ properties: {
26498
+ additionalContext: {
26499
+ type: "string"
26500
+ },
26501
+ additional_context: {
26502
+ type: "string"
26503
+ },
26504
+ continue: {
26505
+ type: "boolean"
26506
+ },
26507
+ decision: {
26508
+ type: "string",
26509
+ enum: [
26510
+ "approve",
26511
+ "block"
26512
+ ]
26513
+ },
26514
+ reason: {
26515
+ type: "string"
26516
+ },
26517
+ stopReason: {
26518
+ type: "string"
26519
+ },
26520
+ suppressOutput: {
26521
+ type: "boolean"
26522
+ },
26523
+ systemMessage: {
26524
+ type: "string"
26525
+ },
26526
+ hookSpecificOutput: {
26527
+ allOf: [
26528
+ {
26529
+ $ref: "#/definitions/Specific"
26530
+ }
26531
+ ]
26532
+ }
26533
+ }
26534
+ }
26535
+ }
26536
+ };
26537
+
26538
+ // tests/fixtures/host-schemas/pi.json
26539
+ var pi_default = {
26540
+ host: "pi",
26541
+ 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.",
26542
+ stdout: "text",
26543
+ output: {
26544
+ PreToolUse: {
26545
+ type: "string",
26546
+ description: "plain text read by src/entries/pi.ts"
26547
+ },
26548
+ PostToolUse: {
26549
+ type: "string",
26550
+ description: "plain text read by src/entries/pi.ts"
26551
+ },
26552
+ UserPromptSubmit: {
26553
+ type: "string",
26554
+ description: "plain text read by src/entries/pi.ts"
26555
+ },
26556
+ SessionStart: {
26557
+ type: "string",
26558
+ description: "plain text read by src/entries/pi.ts"
26559
+ }
26560
+ }
26561
+ };
26562
+
26563
+ // tests/fixtures/host-schemas/opencode.json
26564
+ var opencode_default = {
26565
+ host: "opencode",
26566
+ 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.",
26567
+ stdout: "text",
26568
+ output: {
26569
+ PreToolUse: {
26570
+ type: "string",
26571
+ description: "plain text read by the context-mode OpenCode plugin"
26572
+ },
26573
+ PostToolUse: {
26574
+ type: "string",
26575
+ description: "plain text read by the context-mode OpenCode plugin"
26576
+ },
26577
+ UserPromptSubmit: {
26578
+ type: "string",
26579
+ description: "plain text read by the context-mode OpenCode plugin"
26580
+ },
26581
+ SessionStart: {
26582
+ type: "string",
26583
+ description: "plain text read by the context-mode OpenCode plugin"
26584
+ }
26585
+ }
26586
+ };
26587
+
26588
+ // src/core/ops/hook-shape.ts
26589
+ var HOST_SHAPES = {
26590
+ "claude-code": claude_code_default,
26591
+ codex: codex_default,
26592
+ gemini: gemini_default,
26593
+ qwen: qwen_default,
26594
+ "copilot-cli": copilot_cli_default,
26595
+ vscode: vscode_default,
26596
+ kiro: kiro_default,
26597
+ zcode: zcode_default,
26598
+ pi: pi_default,
26599
+ opencode: opencode_default
26600
+ };
26601
+ var NOTE_KEYS = /* @__PURE__ */ new Set(["$schema", "title", "description", "definitions", "default"]);
26602
+ var RULE_KEYS = /* @__PURE__ */ new Set(["type", "enum", "const", "required", "properties", "additionalProperties", "items", "allOf", "$ref"]);
26603
+ function isObject5(v) {
26604
+ return typeof v === "object" && v !== null && !Array.isArray(v);
26605
+ }
26606
+ function typeOf(v) {
26607
+ if (v === null) return "null";
26608
+ if (Array.isArray(v)) return "array";
26609
+ return typeof v;
26610
+ }
26611
+ function hasType(v, t) {
26612
+ if (t === "integer") return Number.isInteger(v);
26613
+ return typeOf(v) === t;
26614
+ }
26615
+ function same(a, b) {
26616
+ return JSON.stringify(a) === JSON.stringify(b);
26617
+ }
26618
+ function resolve7(root, ref) {
26619
+ const parts = ref.split("/");
26620
+ if (parts[0] !== "#") throw new Error(`hook-shape: only local $ref is read, got ${ref}`);
26621
+ let at2 = root;
26622
+ for (const p of parts.slice(1)) at2 = isObject5(at2) ? at2[p] : void 0;
26623
+ if (!isObject5(at2)) throw new Error(`hook-shape: $ref ${ref} names nothing`);
26624
+ return at2;
26625
+ }
26626
+ function shapeErrors(schema, value, root = schema, at2 = "$") {
26627
+ for (const k of Object.keys(schema)) {
26628
+ if (!NOTE_KEYS.has(k) && !RULE_KEYS.has(k)) throw new Error(`hook-shape: keyword ${k} at ${at2} is not read by the checker`);
26629
+ }
26630
+ const errs = [];
26631
+ if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve7(root, schema.$ref), value, root, at2));
26632
+ if (Array.isArray(schema.allOf)) for (const s of schema.allOf) errs.push(...shapeErrors(s, value, root, at2));
26633
+ if (schema.type !== void 0) {
26634
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
26635
+ if (!types.some((t) => hasType(value, String(t)))) return [...errs, `${at2}: ${typeOf(value)} is not ${types.join(" or ")}`];
26636
+ }
26637
+ if (Array.isArray(schema.enum) && !schema.enum.some((e) => same(e, value))) errs.push(`${at2}: ${JSON.stringify(value)} is not one of ${JSON.stringify(schema.enum)}`);
26638
+ if (Object.hasOwn(schema, "const") && !same(schema.const, value)) errs.push(`${at2}: ${JSON.stringify(value)} is not ${JSON.stringify(schema.const)}`);
26639
+ if (isObject5(value)) {
26640
+ const props = isObject5(schema.properties) ? schema.properties : {};
26641
+ if (Array.isArray(schema.required)) {
26642
+ for (const r of schema.required) if (!Object.hasOwn(value, String(r))) errs.push(`${at2}: ${String(r)} is required`);
26643
+ }
26644
+ for (const [k, v] of Object.entries(value)) {
26645
+ if (Object.hasOwn(props, k)) errs.push(...shapeErrors(props[k], v, root, `${at2}.${k}`));
26646
+ else if (schema.additionalProperties === false) errs.push(`${at2}: ${k} is not a known key`);
26647
+ else if (isObject5(schema.additionalProperties)) errs.push(...shapeErrors(schema.additionalProperties, v, root, `${at2}.${k}`));
26648
+ }
26649
+ }
26650
+ if (Array.isArray(value) && isObject5(schema.items)) {
26651
+ const items = schema.items;
26652
+ value.forEach((v, n) => errs.push(...shapeErrors(items, v, root, `${at2}[${n}]`)));
26653
+ }
26654
+ return errs;
26655
+ }
26656
+ function replyErrors(agent, event, stdout) {
26657
+ const host = HOST_SHAPES[agent];
26658
+ const schema = host.output[event];
26659
+ if (schema === void 0) return [`${agent} has no ${event} reply schema`];
26660
+ if (host.stdout === "text") return shapeErrors(schema, stdout);
26661
+ let value;
26662
+ try {
26663
+ value = JSON.parse(stdout);
26664
+ } catch {
26665
+ return [`${agent} ${event}: stdout is not JSON`];
26666
+ }
26667
+ return shapeErrors(schema, value);
26668
+ }
26669
+
26670
+ // src/core/sandbox/host-node.ts
26671
+ var BUN_BE_BUN_ENV = "BUN_BE_BUN";
26672
+ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
26673
+ if (host.bun === void 0) return { file: host.execPath, env };
26674
+ const node = find2("javascript", env);
26675
+ if (node !== null) return { file: node, env };
26676
+ return { file: host.execPath, env: { ...env, [BUN_BE_BUN_ENV]: "1" } };
26677
+ }
26678
+
26679
+ // src/setup/codex-trust.ts
26680
+ import { createHash } from "node:crypto";
26681
+ import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
26682
+ import path6 from "node:path";
26683
+ import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
26684
+
26685
+ // src/setup/spawn-bin.ts
26686
+ import { spawnSync } from "node:child_process";
26687
+ import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
26688
+ import path5 from "node:path";
26689
+ var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
26690
+ var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
26691
+ var DEFAULT_COMSPEC = "cmd.exe";
26692
+ function envGet(env, k) {
26693
+ return env[Object.keys(env).find((x) => x.toUpperCase() === k) ?? k];
26694
+ }
26695
+ function whichBin(bin, env, platform = process.platform) {
26696
+ const get = (k) => envGet(env, k);
26697
+ const win = platform === "win32";
26698
+ const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
26699
+ const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
26700
+ for (const dir of pathEntries(get("PATH") ?? "", platform)) {
26701
+ for (const n of names) {
26702
+ const f = path5.join(dir, n);
26703
+ try {
26704
+ accessSync2(f, fsc.X_OK);
26705
+ if (statSync6(f).isFile()) return f;
26706
+ } catch {
26707
+ }
26708
+ }
26709
+ }
26710
+ return void 0;
26711
+ }
26712
+ var CMD_QUOTE_CHARS = '"&|<>^()!';
26713
+ var CMD_PERCENT = "%";
26714
+ var CMD_SUBSTRING_MARK = ":";
26715
+ var CMD_DYNAMIC_VARS = Object.freeze(["CD", "DATE", "TIME", "RANDOM", "ERRORLEVEL", "CMDEXTVERSION", "CMDCMDLINE", "HIGHESTNUMANODENUMBER"]);
26716
+ function needsCmdQuotes(a) {
26717
+ if (a === "") return true;
26718
+ for (const c of a) if (c.trim() === "" || CMD_QUOTE_CHARS.includes(c)) return true;
26719
+ return false;
26720
+ }
26721
+ function expandablePercent(text, env) {
26722
+ const names = new Set(CMD_DYNAMIC_VARS);
26723
+ for (const k of Object.keys(env)) names.add(k.toUpperCase());
26724
+ for (let i = text.indexOf(CMD_PERCENT); i >= 0; i = text.indexOf(CMD_PERCENT, i + 1)) {
26725
+ for (let j = text.indexOf(CMD_PERCENT, i + 1); j >= 0; j = text.indexOf(CMD_PERCENT, j + 1)) {
26726
+ const inner = text.slice(i + 1, j);
26727
+ const cut = inner.indexOf(CMD_SUBSTRING_MARK);
26728
+ const name = cut < 0 ? inner : inner.slice(0, cut);
26729
+ if (name !== "" && names.has(name.toUpperCase())) return `${CMD_PERCENT}${inner}${CMD_PERCENT}`;
26730
+ }
26731
+ }
26732
+ return void 0;
26733
+ }
26734
+ function winCmdLine(file2, args, env = {}) {
26735
+ for (const a of [file2, ...args]) {
26736
+ const hit = expandablePercent(a, env);
26737
+ if (hit !== void 0) throw new Error(`cannot run ${file2} through cmd.exe: cmd.exe expands ${hit} inside quotes, so the value ${JSON.stringify(a)} would change. Use a path and arguments without it`);
26738
+ }
26739
+ const q = (a) => needsCmdQuotes(a) ? `"${a.split('"').join('""')}"` : a;
26740
+ return `"${[file2, ...args].map(q).join(" ")}"`;
26741
+ }
26742
+ function spawnForm(file2, args, env, platform = process.platform) {
26743
+ if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
26744
+ return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
26745
+ }
26746
+ return { command: file2, args, windowsVerbatimArguments: false };
24868
26747
  }
24869
26748
 
24870
26749
  // src/setup/codex-trust.ts
@@ -24916,14 +26795,14 @@ function pluginHooksFromReply(m, pluginId) {
24916
26795
  function askPluginHooks(env, pluginId, cwd) {
24917
26796
  const bin = whichBin("codex", env);
24918
26797
  if (!bin) return Promise.resolve({ kind: "absent" });
24919
- return new Promise((resolve9) => {
26798
+ return new Promise((resolve10) => {
24920
26799
  let asked;
24921
26800
  const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
24922
26801
  let f;
24923
26802
  try {
24924
26803
  f = spawnForm(bin, ["app-server"], env);
24925
26804
  } catch {
24926
- resolve9({ kind: "silent" });
26805
+ resolve10({ kind: "silent" });
24927
26806
  return;
24928
26807
  }
24929
26808
  const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
@@ -24933,7 +26812,7 @@ function askPluginHooks(env, pluginId, cwd) {
24933
26812
  let result;
24934
26813
  const settle = () => {
24935
26814
  clearTimeout(grace);
24936
- resolve9(done_(result));
26815
+ resolve10(done_(result));
24937
26816
  };
24938
26817
  let grace;
24939
26818
  const finish2 = (v) => {
@@ -25017,7 +26896,7 @@ var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answ
25017
26896
  var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
25018
26897
  var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
25019
26898
  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 };
25020
- function isObject5(v) {
26899
+ function isObject6(v) {
25021
26900
  return typeof v === "object" && v !== null && !Array.isArray(v);
25022
26901
  }
25023
26902
  function loadFixture(bundleDir2, agent) {
@@ -25029,10 +26908,10 @@ function loadFixture(bundleDir2, agent) {
25029
26908
  } catch (err) {
25030
26909
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
25031
26910
  }
25032
- if (!isObject5(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
26911
+ if (!isObject6(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
25033
26912
  if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
25034
26913
  const e = all[agent];
25035
- if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
26914
+ if (!isObject6(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
25036
26915
  return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
25037
26916
  }
25038
26917
  return { event: e.event, payload: e.payload };
@@ -25050,39 +26929,11 @@ var CWD_KEY = {
25050
26929
  opencode: "directory"
25051
26930
  };
25052
26931
  function payloadFor(agent, payload, worktree) {
25053
- return worktree !== void 0 && isObject5(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
25054
- }
25055
- var SHAPE = {
25056
- "claude-code": "claude",
25057
- codex: "claude",
25058
- qwen: "claude",
25059
- vscode: "claude",
25060
- zcode: "claude",
25061
- gemini: "gemini",
25062
- "copilot-cli": "copilot",
25063
- kiro: "text",
25064
- pi: "text",
25065
- opencode: "text"
25066
- };
25067
- var COPILOT_KEYS = ["permissionDecision", "additionalContext", "modifiedResult"];
26932
+ return worktree !== void 0 && isObject6(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
26933
+ }
25068
26934
  function isNativeShape(agent, stdout, exitCode, killed, event) {
25069
26935
  if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
25070
- if (stdout.length === 0 || SHAPE[agent] === "text") return true;
25071
- let out;
25072
- try {
25073
- out = JSON.parse(stdout);
25074
- } catch {
25075
- return false;
25076
- }
25077
- if (!isObject5(out)) return false;
25078
- switch (SHAPE[agent]) {
25079
- case "claude":
25080
- return isObject5(out.hookSpecificOutput) && out.hookSpecificOutput.hookEventName === event;
25081
- case "gemini":
25082
- return typeof out.decision === "string" || isObject5(out.hookSpecificOutput);
25083
- default:
25084
- return COPILOT_KEYS.some((k) => Object.hasOwn(out, k));
25085
- }
26936
+ return stdout.length === 0 || replyErrors(agent, event, stdout).length === 0;
25086
26937
  }
25087
26938
  var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
25088
26939
  function readProbePayload(cwd, ranged) {
@@ -25107,9 +26958,9 @@ function isReadShape(stdout) {
25107
26958
  } catch {
25108
26959
  return false;
25109
26960
  }
25110
- if (!isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
26961
+ if (!isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
25111
26962
  const r = out.hookSpecificOutput.updatedToolOutput;
25112
- if (!isObject5(r) || r.type !== "text" || !isObject5(r.file)) return false;
26963
+ if (!isObject6(r) || r.type !== "text" || !isObject6(r.file)) return false;
25113
26964
  const f = r.file;
25114
26965
  return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
25115
26966
  }
@@ -25137,11 +26988,49 @@ function isPassThrough(stdout) {
25137
26988
  } catch {
25138
26989
  return false;
25139
26990
  }
25140
- return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
26991
+ return !isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
26992
+ }
26993
+ var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
26994
+ async function mediaProbe(i, timeoutMs) {
26995
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
26996
+ try {
26997
+ const filePath = path7.join(home, "d5-media-probe.png");
26998
+ writeFileSync2(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
26999
+ const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
27000
+ const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
27001
+ cwd: i.bundleDir,
27002
+ env: node.env,
27003
+ signal: i.signal,
27004
+ timeoutMs,
27005
+ stdin: JSON.stringify({
27006
+ session_id: "d5-media-probe",
27007
+ transcript_path: "",
27008
+ cwd: home,
27009
+ hook_event_name: "PreToolUse",
27010
+ tool_name: "Read",
27011
+ tool_use_id: "toolu_d5_media_probe",
27012
+ tool_input: { file_path: filePath }
27013
+ })
27014
+ });
27015
+ return r.stdout.toString("utf8");
27016
+ } finally {
27017
+ rmSync2(home, { recursive: true, force: true });
27018
+ }
27019
+ }
27020
+ function isDeny(stdout) {
27021
+ if (stdout.trim() === "") return false;
27022
+ let out;
27023
+ try {
27024
+ out = JSON.parse(stdout);
27025
+ } catch {
27026
+ return false;
27027
+ }
27028
+ return isObject6(out) && isObject6(out.hookSpecificOutput) && out.hookSpecificOutput.permissionDecision === "deny";
25141
27029
  }
25142
27030
  async function readProbeDetail(i, timeoutMs) {
25143
27031
  if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
25144
27032
  if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
27033
+ if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
25145
27034
  return null;
25146
27035
  }
25147
27036
  function codexHookJournaled(db) {
@@ -25172,6 +27061,36 @@ async function codexPluginTrust(i) {
25172
27061
  if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
25173
27062
  return null;
25174
27063
  }
27064
+ function codexStopPayload(cwd) {
27065
+ return {
27066
+ session_id: "d5-stop-probe",
27067
+ turn_id: "d5-stop-turn",
27068
+ transcript_path: null,
27069
+ cwd,
27070
+ hook_event_name: "Stop",
27071
+ model: "d5-probe",
27072
+ permission_mode: "default",
27073
+ stop_hook_active: false,
27074
+ last_assistant_message: "d5 stop probe"
27075
+ };
27076
+ }
27077
+ async function codexStopDetail(i, timeoutMs) {
27078
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-stop-"));
27079
+ try {
27080
+ const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, [DATA_DIR_ENV]: home });
27081
+ const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
27082
+ cwd: i.bundleDir,
27083
+ env: node.env,
27084
+ signal: i.signal,
27085
+ timeoutMs,
27086
+ stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
27087
+ });
27088
+ const logged = existsSync12(path7.join(home, HOOK_ERROR_LOG_FILE));
27089
+ return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
27090
+ } finally {
27091
+ rmSync2(home, { recursive: true, force: true });
27092
+ }
27093
+ }
25175
27094
  async function checkHookRoundTrip(i) {
25176
27095
  if (i.agent === "codex") {
25177
27096
  const trust = await codexPluginTrust(i);
@@ -25213,7 +27132,7 @@ async function checkHookRoundTrip(i) {
25213
27132
  if (n >= minPairs && ms <= HOOK_P95_MS) break;
25214
27133
  }
25215
27134
  if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
25216
- const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
27135
+ const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
25217
27136
  if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
25218
27137
  return row("PASS", DOCTOR_PASS_DETAIL);
25219
27138
  }
@@ -25223,7 +27142,7 @@ import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4
25223
27142
  import { basename as basename4, dirname as dirname8, join as join16 } from "node:path";
25224
27143
 
25225
27144
  // src/core/store/owners.ts
25226
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
27145
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
25227
27146
  import { basename as basename3, join as join15 } from "node:path";
25228
27147
  function ownersDir(configDir, projectKey) {
25229
27148
  return join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
@@ -25410,7 +27329,7 @@ function buildReportHead(input) {
25410
27329
 
25411
27330
  // src/core/ops/doctor-issue.ts
25412
27331
  import { spawnSync as spawnSync3 } from "node:child_process";
25413
- import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
27332
+ import { closeSync as closeSync2, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync as openSync2, readFileSync as readFileSync13, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
25414
27333
  import { delimiter, join as join17 } from "node:path";
25415
27334
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
25416
27335
  function tildeOf(env) {
@@ -25463,31 +27382,31 @@ function hookLogTail(env) {
25463
27382
  const file2 = hookLogPath(env);
25464
27383
  if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25465
27384
  try {
25466
- const fd = openSync(file2, "r");
27385
+ const fd = openSync2(file2, "r");
25467
27386
  try {
25468
27387
  const size = fstatSync(fd).size;
25469
27388
  const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
25470
27389
  const buf = Buffer.alloc(size - start);
25471
- readSync(fd, buf, 0, buf.length, start);
27390
+ readSync2(fd, buf, 0, buf.length, start);
25472
27391
  const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
25473
27392
  if (start > 0) lines.shift();
25474
27393
  return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
25475
27394
  } finally {
25476
- closeSync(fd);
27395
+ closeSync2(fd);
25477
27396
  }
25478
27397
  } catch (err) {
25479
27398
  return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
25480
27399
  }
25481
27400
  }
25482
27401
  async function journalRows(ctx) {
25483
- const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
27402
+ const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
25484
27403
  if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25485
27404
  try {
25486
27405
  const db = await openDb(ctx.project, { readOnly: true });
25487
27406
  try {
25488
27407
  const rows = db.raw.prepare(`SELECT kind, tool, bytes, ok, exit_code, created_at FROM events ORDER BY seq DESC LIMIT ${DOCTOR_JOURNAL_ROWS}`).all();
25489
27408
  const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
25490
- return head.concat(rows.map((r) => `| ${cell5(r.kind)} | ${cell5(r.tool)} | ${cell5(r.bytes)} | ${cell5(r.ok)} | ${cell5(r.exit_code)} | ${typeof r.created_at === "number" ? new Date(r.created_at).toISOString() : cell5(r.created_at)} |`));
27409
+ return head2.concat(rows.map((r) => `| ${cell5(r.kind)} | ${cell5(r.tool)} | ${cell5(r.bytes)} | ${cell5(r.ok)} | ${cell5(r.exit_code)} | ${typeof r.created_at === "number" ? new Date(r.created_at).toISOString() : cell5(r.created_at)} |`));
25491
27410
  } finally {
25492
27411
  closeDb(db);
25493
27412
  }
@@ -25586,7 +27505,7 @@ async function writeIssueReport(i) {
25586
27505
  const dir = join17(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
25587
27506
  mkdirSync6(dir, { recursive: true });
25588
27507
  const file2 = join17(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
25589
- writeFileSync3(file2, body);
27508
+ writeFileSync4(file2, body);
25590
27509
  const shown2 = tilde(file2);
25591
27510
  const title = issueTitle(i.adapter.id, i.rows);
25592
27511
  const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
@@ -25741,9 +27660,9 @@ var ctxDoctor = Object.freeze({
25741
27660
  });
25742
27661
 
25743
27662
  // src/core/tools/execute.ts
25744
- import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
27663
+ import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
25745
27664
  import { tmpdir as tmpdir3 } from "node:os";
25746
- import { dirname as dirname10, join as join19, parse as parse3, resolve as resolve7 } from "node:path";
27665
+ import { dirname as dirname10, join as join19, parse as parse3, resolve as resolve8 } from "node:path";
25747
27666
 
25748
27667
  // src/core/sandbox/win-build.ts
25749
27668
  var SEPARATORS2 = ";&|(\n";
@@ -25862,16 +27781,16 @@ async function finish(input, ctx, r, exitCode, journal) {
25862
27781
  const isError = exitCode !== 0 && !(input.language === "shell" && exitCode === SOFT_EXIT && r.stderr.length === 0);
25863
27782
  const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "");
25864
27783
  const fullBytes = Buffer.byteLength(combined, "utf8");
25865
- const head = summaryLine(exitCode, fullBytes);
27784
+ const head2 = summaryLine(exitCode, fullBytes);
25866
27785
  const intent = input.intent ?? "";
25867
27786
  const bare2 = exitCode === 0 && input.summary !== true && combined !== "";
25868
- const direct = (bare2 ? "" : head + "\n") + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
25869
- const fits = Buffer.byteLength(head + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined, "utf8") <= OUTPUT_CAP;
27787
+ const direct = (bare2 ? "" : head2 + "\n") + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
27788
+ const fits = Buffer.byteLength(head2 + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined, "utf8") <= OUTPUT_CAP;
25870
27789
  if (intent === "" && fits) {
25871
27790
  return { text: direct, isError, sandboxBytes: fullBytes, journal };
25872
27791
  }
25873
27792
  const label2 = sourceLabel(input.code);
25874
- const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label2);
27793
+ const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head2, "utf8") - 2 - moreReserve(intent, label2);
25875
27794
  const db = await openDb(ctx.project);
25876
27795
  let picked;
25877
27796
  try {
@@ -25880,7 +27799,7 @@ async function finish(input, ctx, r, exitCode, journal) {
25880
27799
  } finally {
25881
27800
  closeDb(db);
25882
27801
  }
25883
- const text = head + "\n" + picked.text + (picked.more === null ? "" : "\n" + picked.more);
27802
+ const text = head2 + "\n" + picked.text + (picked.more === null ? "" : "\n" + picked.more);
25884
27803
  return { text: capBytes(text, OUTPUT_CAP).text, isError, sandboxBytes: fullBytes, journal };
25885
27804
  }
25886
27805
  async function handler3(raw, ctx) {
@@ -25890,7 +27809,7 @@ async function handler3(raw, ctx) {
25890
27809
  const cwd = ctx.project.worktree;
25891
27810
  const extra = { ...PLAIN_OUTPUT_ENV2 };
25892
27811
  if (input.file !== void 0) {
25893
- const abs = resolve7(cwd, input.file);
27812
+ const abs = resolve8(cwd, input.file);
25894
27813
  const bad = fileError(input.file, abs, ctx.project.containmentRoot);
25895
27814
  if (bad !== null) return fail5(bad);
25896
27815
  extra.CTX_FILE = abs;
@@ -25909,7 +27828,7 @@ async function handler3(raw, ctx) {
25909
27828
  } else {
25910
27829
  tmpDir = mkdtempSync2(join19(tmpdir3(), TMP_PREFIX));
25911
27830
  const file2 = join19(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
25912
- writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
27831
+ writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
25913
27832
  argv = scriptArgv(input.language, runtime, file2);
25914
27833
  }
25915
27834
  if (input.background === true) {
@@ -25945,7 +27864,7 @@ var ctxExecute = {
25945
27864
 
25946
27865
  // src/core/tools/index.ts
25947
27866
  import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
25948
- import { dirname as dirname11, extname, join as join21, relative as relative5, resolve as resolve8 } from "node:path";
27867
+ import { dirname as dirname11, extname as extname2, join as join21, relative as relative5, resolve as resolve9 } from "node:path";
25949
27868
 
25950
27869
  // src/core/index/walk.ts
25951
27870
  import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
@@ -26190,9 +28109,9 @@ function ipv6Words(address) {
26190
28109
  };
26191
28110
  const gap = a.indexOf("::");
26192
28111
  if (gap < 0) return words2(a);
26193
- const head = words2(a.slice(0, gap));
28112
+ const head2 = words2(a.slice(0, gap));
26194
28113
  const tail = words2(a.slice(gap + 2));
26195
- return [...head, ...new Array(8 - head.length - tail.length).fill(0), ...tail];
28114
+ return [...head2, ...new Array(8 - head2.length - tail.length).fill(0), ...tail];
26196
28115
  }
26197
28116
  function dotted(hi, lo) {
26198
28117
  return [hi >> 8, hi & 255, lo >> 8, lo & 255].join(".");
@@ -26232,18 +28151,18 @@ function request(u, conn, proxy, signal) {
26232
28151
  const host = bare(u.hostname);
26233
28152
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
26234
28153
  const path8 = u.pathname + u.search;
26235
- return new Promise((resolve9, reject) => {
28154
+ return new Promise((resolve10, reject) => {
26236
28155
  const onErr = (err) => reject(fail6(causeCode(err)));
26237
28156
  if (proxy === void 0) {
26238
28157
  const mod = u.protocol === "https:" ? https : http;
26239
28158
  const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
26240
- req.on("response", resolve9).on("error", onErr).end();
28159
+ req.on("response", resolve10).on("error", onErr).end();
26241
28160
  return;
26242
28161
  }
26243
28162
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
26244
28163
  if (u.protocol === "http:") {
26245
28164
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
26246
- req.on("response", resolve9).on("error", onErr).end();
28165
+ req.on("response", resolve10).on("error", onErr).end();
26247
28166
  return;
26248
28167
  }
26249
28168
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -26263,16 +28182,16 @@ function request(u, conn, proxy, signal) {
26263
28182
  headers: { host: u.host },
26264
28183
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
26265
28184
  });
26266
- req.on("response", resolve9).on("error", onErr).end();
28185
+ req.on("response", resolve10).on("error", onErr).end();
26267
28186
  });
26268
28187
  tunnel.end();
26269
28188
  });
26270
28189
  }
26271
28190
  function readBody(res) {
26272
- return new Promise((resolve9, reject) => {
28191
+ return new Promise((resolve10, reject) => {
26273
28192
  const parts = [];
26274
28193
  res.on("data", (b) => parts.push(b));
26275
- res.on("end", () => resolve9(Buffer.concat(parts)));
28194
+ res.on("end", () => resolve10(Buffer.concat(parts)));
26276
28195
  res.on("error", (err) => reject(fail6(causeCode(err))));
26277
28196
  res.on("aborted", () => reject(fail6("ECONNRESET")));
26278
28197
  });
@@ -30129,7 +32048,7 @@ function userLabel(label2) {
30129
32048
  return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
30130
32049
  }
30131
32050
  function kindOfPath(p) {
30132
- return EXT_KIND[extname(p).toLowerCase()] ?? "text";
32051
+ return EXT_KIND[extname2(p).toLowerCase()] ?? "text";
30133
32052
  }
30134
32053
  function kindOfType(contentType) {
30135
32054
  const semi = contentType.indexOf(";");
@@ -30150,7 +32069,7 @@ function missingOrOutside(given, abs, root) {
30150
32069
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
30151
32070
  }
30152
32071
  function pathItems(input, project) {
30153
- const abs = resolve8(project.worktree, input.path);
32072
+ const abs = resolve9(project.worktree, input.path);
30154
32073
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
30155
32074
  const base = relative5(project.worktree, abs);
30156
32075
  if (statSync8(abs).isDirectory()) {
@@ -30228,8 +32147,8 @@ async function handler4(input, ctx) {
30228
32147
  } finally {
30229
32148
  closeDb(db);
30230
32149
  }
30231
- const head = "Indexed " + sources + " source(s), " + chunks + " chunk(s) from ";
30232
- const first = sources === 1 && lastId > 0 ? head + sourceHandle(lastId) + ". " + indexedLabelLine(from, lastId) : head + shownLabel(from, null) + ".";
32150
+ const head2 = "Indexed " + sources + " source(s), " + chunks + " chunk(s) from ";
32151
+ const first = sources === 1 && lastId > 0 ? head2 + sourceHandle(lastId) + ". " + indexedLabelLine(from, lastId) : head2 + shownLabel(from, null) + ".";
30233
32152
  const line = [first, ...notes].join("\n");
30234
32153
  return {
30235
32154
  text: capBytes(line, OUTPUT_CAP).text,
@@ -30401,7 +32320,7 @@ function readWeek(raw, lastMs) {
30401
32320
  }
30402
32321
  return days;
30403
32322
  }
30404
- var EMPTY5 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
32323
+ var EMPTY6 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
30405
32324
  function totals(r) {
30406
32325
  const produced = Number(r.produced);
30407
32326
  const returned = Number(r.returned);
@@ -30441,7 +32360,7 @@ function sum(groups) {
30441
32360
  produced: t.produced + g.produced,
30442
32361
  returned: t.returned + g.returned,
30443
32362
  saved: t.saved + g.saved
30444
- }), EMPTY5);
32363
+ }), EMPTY6);
30445
32364
  }
30446
32365
  function reductionPct(t) {
30447
32366
  if (t.calls === 0) return 0;
@@ -30499,8 +32418,8 @@ function plural(n, word) {
30499
32418
  }
30500
32419
  function table2(title, rows) {
30501
32420
  const max = Math.max(0, ...rows.map((r) => r.saved));
30502
- const head = " " + title.padEnd(LABEL_W) + right("Calls", STATS_CALLS_W) + right("Made", NUM_W) + right("Sent", NUM_W) + right("Kept out", NUM_W) + right("%", PCT_W);
30503
- return [head, ...rows.map((r) => (" " + label(r.name) + right(count(r.calls), STATS_CALLS_W) + right(bytes4(r.produced), NUM_W) + right(bytes4(r.returned), NUM_W) + right(bytes4(r.saved), NUM_W) + right(pct(r), PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
32421
+ const head2 = " " + title.padEnd(LABEL_W) + right("Calls", STATS_CALLS_W) + right("Made", NUM_W) + right("Sent", NUM_W) + right("Kept out", NUM_W) + right("%", PCT_W);
32422
+ return [head2, ...rows.map((r) => (" " + label(r.name) + right(count(r.calls), STATS_CALLS_W) + right(bytes4(r.produced), NUM_W) + right(bytes4(r.returned), NUM_W) + right(bytes4(r.saved), NUM_W) + right(pct(r), PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
30504
32423
  }
30505
32424
  function bySaved(a, b) {
30506
32425
  return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
@@ -30544,10 +32463,10 @@ function windowLine(saved) {
30544
32463
  const t = saved / STATS_BYTES_PER_TOKEN;
30545
32464
  const share = t / STATS_WINDOW_TOKENS;
30546
32465
  const win = `a ${tokens(STATS_WINDOW_TOKENS)} window`;
30547
- const head = ` about ${tokens(t)} tokens kept out`;
30548
- if (share >= 1) return `${head}, ${whole(share)} times ${win}`;
32466
+ const head2 = ` about ${tokens(t)} tokens kept out`;
32467
+ if (share >= 1) return `${head2}, ${whole(share)} times ${win}`;
30549
32468
  const p = share * PERCENT_SCALE;
30550
- return p * STATS_WHOLE_FROM < 1 ? head : `${head}, ${whole(p)}% of ${win}`;
32469
+ return p * STATS_WHOLE_FROM < 1 ? head2 : `${head2}, ${whole(p)}% of ${win}`;
30551
32470
  }
30552
32471
  function ymd(day) {
30553
32472
  return new Date(day * MS_PER_DAY).toISOString().slice(0, "yyyy-mm-dd".length);
@@ -30578,14 +32497,14 @@ function lastDays(week, allCalls) {
30578
32497
  const all = saved.reduce((a, b) => a + b, 0);
30579
32498
  const calls = week.reduce((a, d) => a + d.calls, 0);
30580
32499
  const max = Math.max(0, ...saved);
30581
- const head = `Last ${STATS_DAYS} days of use \xB7 ${ymd(week[0].day)} to ${ymd(week[week.length - 1].day)}`;
32500
+ const head2 = `Last ${STATS_DAYS} days of use \xB7 ${ymd(week[0].day)} to ${ymd(week[week.length - 1].day)}`;
30582
32501
  const card = calls < allCalls ? [
30583
32502
  cards(["Kept out", "Tokens kept out", "Calls", "Kept out per call"]),
30584
32503
  cards([bytes4(all), "about " + tokens(all / STATS_BYTES_PER_TOKEN), count(calls), bytes4(calls > 0 ? all / calls : 0)]),
30585
32504
  ""
30586
32505
  ] : [];
30587
32506
  return [
30588
- head,
32507
+ head2,
30589
32508
  ...card,
30590
32509
  ...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + right(bytes4(saved[i]), NUM_W)] : []),
30591
32510
  " " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
@@ -30604,15 +32523,15 @@ function fit(line) {
30604
32523
  return chars.length <= STATS_WIDTH ? line : chars.slice(0, STATS_WIDTH - 1).join("") + "\u2026";
30605
32524
  }
30606
32525
  function report(f, sessionId, agent) {
30607
- const head = [STATS_REPORT_TITLE, "\u2500".repeat(STATS_WIDTH), ""];
32526
+ const head2 = [STATS_REPORT_TITLE, "\u2500".repeat(STATS_WIDTH), ""];
30608
32527
  const project = sum(f.groups);
30609
- if (project.calls === 0) return [...head, ...STATS_EMPTY_LINES].join("\n");
32528
+ if (project.calls === 0) return [...head2, ...STATS_EMPTY_LINES].join("\n");
30610
32529
  const session = sum(f.groups.filter((g) => g.session === sessionId));
30611
32530
  const [scopeName, focus] = session.calls > 0 ? ["This session", session] : ["This project", project];
30612
32531
  const top = Math.max(focus.produced, focus.returned);
30613
32532
  const extra = session.calls > 0 ? ` \xB7 ${span(f.span)} active` : "";
30614
32533
  const lines = [
30615
- ...head,
32534
+ ...head2,
30616
32535
  `${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
30617
32536
  ` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
30618
32537
  " " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + right(bytes4(focus.produced), NUM_W),
@@ -30635,8 +32554,8 @@ function report(f, sessionId, agent) {
30635
32554
  ] : []
30636
32555
  ];
30637
32556
  const agents = /* @__PURE__ */ new Map();
30638
- for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY5, g]));
30639
- if (!agents.has(agent)) agents.set(agent, EMPTY5);
32557
+ for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY6, g]));
32558
+ if (!agents.has(agent)) agents.set(agent, EMPTY6);
30640
32559
  lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
30641
32560
  const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
30642
32561
  lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + right("Session", STATS_KIND_W) + right("Project", STATS_KIND_W));
@@ -30696,10 +32615,10 @@ var ctxStats = Object.freeze({
30696
32615
  });
30697
32616
 
30698
32617
  // src/core/ops/host-write.ts
30699
- import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
32618
+ import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync6 } from "node:fs";
30700
32619
  import { dirname as dirname12, join as join22 } from "node:path";
30701
32620
  function defaultWrite(file2, text) {
30702
- writeFileSync5(file2, text, "utf8");
32621
+ writeFileSync6(file2, text, "utf8");
30703
32622
  }
30704
32623
  function hostConfigPath(agent, home, env) {
30705
32624
  const own2 = OWN_MCP_ENTRY[agent];
@@ -30766,7 +32685,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
30766
32685
  }
30767
32686
 
30768
32687
  // src/core/ops/uninstall.ts
30769
- import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync6, writeFileSync as writeFileSync6 } from "node:fs";
32688
+ import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
30770
32689
  import { join as join23 } from "node:path";
30771
32690
  function row2(area, before, after) {
30772
32691
  return { area, before, after };
@@ -30774,7 +32693,7 @@ function row2(area, before, after) {
30774
32693
  function stopServers(configDir, projectKey) {
30775
32694
  const stopped = listLiveOwners(configDir, projectKey);
30776
32695
  const dir = join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
30777
- for (const serverId of stopped) writeFileSync6(join23(dir, serverId + OWNER_STOP_EXT), "", "utf8");
32696
+ for (const serverId of stopped) writeFileSync7(join23(dir, serverId + OWNER_STOP_EXT), "", "utf8");
30778
32697
  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 };
30779
32698
  }
30780
32699
  function rootOrNull(adapter, env) {
@@ -31327,9 +33246,9 @@ async function server(input, _options) {
31327
33246
  });
31328
33247
  return { ...hooks, tool };
31329
33248
  }
31330
- var opencode_default = { id: PLUGIN_ID, server, setup };
33249
+ var opencode_default2 = { id: PLUGIN_ID, server, setup };
31331
33250
  export {
31332
- opencode_default as default,
33251
+ opencode_default2 as default,
31333
33252
  id,
31334
33253
  server,
31335
33254
  setup,