context-mode 2.1.6 → 2.1.8

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.
@@ -188,6 +188,8 @@ var RRF_K = 60;
188
188
  var SOURCE_HANDLE_MAX_DIGITS = 10;
189
189
  var EXEC_TIMEOUT_MS = 6e5;
190
190
  var KILL_GRACE_MS = 1e3;
191
+ var PIPE_EOF_GRACE_MS = 250;
192
+ var PIPE_DRAIN_MAX_MS = 2e3;
191
193
  var DB_TIMEOUT_MS = 5e3;
192
194
  var DB_WAL_SUFFIX = "-wal";
193
195
  var DB_SHM_SUFFIX = "-shm";
@@ -217,6 +219,7 @@ var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
217
219
  var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
218
220
  var FETCH_MAX_HOPS = 5;
219
221
  var SOURCE_LABEL_MAX_CHARS = 80;
222
+ var BACKGROUND_HOLD_NOTE = "note: the command ended while a background process still held its output; that process was stopped, so output it would write later does not exist.";
220
223
  var CANCELLED_LINE = "Cancelled.";
221
224
  var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
222
225
  var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
@@ -465,7 +468,7 @@ var DECISION_ANSWERS_KEY = "answers";
465
468
  var DECISION_OPTION_KEY = "option";
466
469
  var DECISION_LABEL_JOIN = " | ";
467
470
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
468
- var BUNDLE_SHA = true ? "ee0a1f6058f6abdb5af70b05f825a997bb15615d" : void 0;
471
+ var BUNDLE_SHA = true ? "92c1ad26d57b45e786a3dc9149549c416badca09" : void 0;
469
472
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
470
473
  var DOCTOR_LABEL = Object.freeze({
471
474
  D1: "version",
@@ -571,6 +574,7 @@ var D5B_FIX = "disable chat.useClaudeHooks or the Claude Code hooks block";
571
574
  var VSCODE_CLAUDE_HOOKS_SETTING = "chat.useClaudeHooks";
572
575
  var VSCODE_SETTINGS_FILE = "settings.json";
573
576
  var D6_UNKNOWN_DETAIL = "no clientInfo or protocolVersion on the request";
577
+ var D6_IN_PROCESS_DETAIL = "in-process plugin: this call ran inside the agent, no MCP session to read";
574
578
  function D7_DETAIL(got) {
575
579
  return `resolved project source ${got} does not match the host's actual cwd`;
576
580
  }
@@ -682,6 +686,90 @@ function D3_DETAIL(parts) {
682
686
  function D3_ROOT_DETAIL(paths) {
683
687
  return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
684
688
  }
689
+ var unsupported = (h) => Object.freeze(h);
690
+ var UNSUPPORTED_HOSTS = Object.freeze([
691
+ unsupported({
692
+ id: "antigravity",
693
+ name: "Antigravity",
694
+ clientNames: ["antigravity", "antigravity-client", "antigravity-cli", "agy"],
695
+ envVars: ["ANTIGRAVITY_CLI_ALIAS"],
696
+ pluginPaths: [[".gemini", "config", "plugins"], [".gemini", "antigravity", "plugins"], [".gemini", "antigravity-cli", "plugins"], [".gemini", "antigravity-ide", "plugins"]],
697
+ configDirs: [".gemini/antigravity", ".gemini/antigravity-cli", ".gemini/config"],
698
+ binaries: ["agy"],
699
+ source: "v1.0.169:src/adapters/client-map.ts:15-17; detect.ts:156,481-483; #1340"
700
+ }),
701
+ unsupported({
702
+ id: "cursor",
703
+ name: "Cursor",
704
+ clientNames: ["cursor-vscode"],
705
+ envVars: ["CURSOR_TRACE_ID", "CURSOR_CLI", "CURSOR_CWD"],
706
+ pluginPaths: [],
707
+ configDirs: [".cursor"],
708
+ binaries: [],
709
+ source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
710
+ }),
711
+ unsupported({
712
+ id: "omp",
713
+ name: "OMP (oh-my-pi)",
714
+ clientNames: ["omp-coding-agent"],
715
+ envVars: [],
716
+ pluginPaths: [],
717
+ configDirs: [".omp"],
718
+ binaries: ["omp"],
719
+ source: "v1.0.169:src/adapters/client-map.ts:37; detect.ts:543 (PI_CODING_AGENT_DIR is not a signal: supported Pi reads it too)"
720
+ }),
721
+ unsupported({
722
+ id: "openclaw",
723
+ name: "OpenClaw",
724
+ clientNames: [],
725
+ envVars: [],
726
+ pluginPaths: [],
727
+ configDirs: [".openclaw"],
728
+ binaries: [],
729
+ source: "v1.0.169:src/adapters/detect.ts:252,575 (the runtime sets no env var)"
730
+ }),
731
+ unsupported({
732
+ id: "kimi",
733
+ name: "Kimi Code",
734
+ clientNames: ["kimi-code", "kimi"],
735
+ envVars: [],
736
+ pluginPaths: [],
737
+ configDirs: [".kimi-code"],
738
+ binaries: ["kimi"],
739
+ source: "v1.0.169:src/adapters/client-map.ts:42-44; detect.ts:567; adapters/kimi/index.ts:127"
740
+ }),
741
+ unsupported({
742
+ id: "kilo",
743
+ name: "Kilo Code",
744
+ clientNames: ["kilo code"],
745
+ envVars: ["KILO", "KILO_PID"],
746
+ pluginPaths: [],
747
+ configDirs: [".config/kilo"],
748
+ binaries: [],
749
+ source: "v1.0.169:src/adapters/client-map.ts:28; detect.ts:170-171,592"
750
+ }),
751
+ unsupported({
752
+ id: "zed",
753
+ name: "Zed",
754
+ clientNames: ["zed"],
755
+ envVars: ["ZED_SESSION_ID", "ZED_TERM"],
756
+ pluginPaths: [],
757
+ configDirs: [".config/zed"],
758
+ binaries: [],
759
+ source: "v1.0.169:src/adapters/client-map.ts:38-39; detect.ts:189-190,616"
760
+ }),
761
+ unsupported({
762
+ id: "jetbrains-copilot",
763
+ name: "JetBrains Copilot",
764
+ clientNames: ["jetbrains client", "intellij idea", "pycharm"],
765
+ envVars: ["IDEA_INITIAL_DIRECTORY"],
766
+ pluginPaths: [],
767
+ configDirs: [".config/JetBrains"],
768
+ binaries: [],
769
+ source: "v1.0.169:src/adapters/client-map.ts:23-25; detect.ts:213,600"
770
+ })
771
+ ]);
772
+ var SUPPORTED_AGENTS_DOCS_URL = "https://github.com/mksglu/context-mode/blob/main/docs/install/README.md";
685
773
  var D3_ROOT_FIX_JOIN = " or ";
686
774
  function D3_ROOT_FIX(installs) {
687
775
  return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
@@ -785,6 +873,14 @@ var V1_SCRIPT_NAMES = Object.freeze([
785
873
  var V1_HOOK_COMMAND = "context-mode hook";
786
874
  var V1_CODEX_HOOK_COMMAND = "context-mode hook codex";
787
875
  var V1_CODEX_HOOKS_DIR = Object.freeze(["hooks", "codex"]);
876
+ var V1_CODEX_SCRIPT_NAMES = Object.freeze([
877
+ "pretooluse.mjs",
878
+ "posttooluse.mjs",
879
+ "sessionstart.mjs",
880
+ "precompact.mjs",
881
+ "userpromptsubmit.mjs",
882
+ "stop.mjs"
883
+ ]);
788
884
  var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
789
885
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
790
886
  var V1_STATUSLINE_COMMAND = "context-mode statusline";
@@ -844,7 +940,6 @@ var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
844
940
  var V1_DATA_DIR_NAME = "context-mode";
845
941
  var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
846
942
  var V1_SESSIONS_DIR_NAME = "sessions";
847
- var V1_SCRIPT_EXT = ".mjs";
848
943
  var V1_BIN_COMMAND = SERVER_KEY;
849
944
  var VSCODE_MCP_SERVERS_KEY = "servers";
850
945
  var ZCODE_EVENTS_KEY = "events";
@@ -860,7 +955,7 @@ var V1_REASON = Object.freeze({
860
955
  cacheHealFile: "old context-mode cache-heal script file",
861
956
  statusLine: "old context-mode statusLine (context-mode statusline): report only, never removed",
862
957
  mcpEntry: "old context-mode MCP entry mcpServers.context-mode",
863
- codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/*.mjs",
958
+ codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/<event>.mjs",
864
959
  codexToml: "old context-mode config.toml [mcp_servers.context-mode*] section",
865
960
  hookFile: "old context-mode hook file context-mode.json (runs context-mode hook)",
866
961
  vscodeMcp: "old context-mode MCP entry servers.context-mode in .vscode/mcp.json: report only, never removed",
@@ -897,7 +992,6 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
897
992
  var JSON_INDENT_UNIT = " ";
898
993
  var MCP_COMMAND_FIELD = "command";
899
994
  var MCP_ARGS_FIELD = "args";
900
- var MCP_ENV_FIELD = "env";
901
995
  var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
902
996
  var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
903
997
  var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
@@ -1013,6 +1107,70 @@ var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=
1013
1107
  var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
1014
1108
  var DOCTOR_LOG_TAIL_BYTES = 262144;
1015
1109
 
1110
+ // src/adapters/opencode.ts
1111
+ var TOOL_NAME_PREFIX = "";
1112
+ var OWN_WIRE_PREFIX = SERVER_KEY + "_";
1113
+ var OPENCODE_EVENTS = {
1114
+ context: "SessionStart",
1115
+ prompt: "UserPromptSubmit",
1116
+ "execute.before": "PreToolUse",
1117
+ "execute.after": "PostToolUse",
1118
+ compaction: "PreCompact",
1119
+ "step-finish": "Usage"
1120
+ };
1121
+ var SHELL_TOOL_NAME = "bash";
1122
+ var READ_TOOL_NAME = "read";
1123
+ var SHELL_TOOL_NAMES = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1124
+ var NATIVE_TO_CANONICAL = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"])) };
1125
+ function toCanonicalTool(name) {
1126
+ if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1127
+ return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL, name) ? NATIVE_TO_CANONICAL[name] : name;
1128
+ }
1129
+ function record(v) {
1130
+ return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
1131
+ }
1132
+ function readResult(p) {
1133
+ const text = p.output === void 0 ? "" : typeof p.output === "string" ? p.output : JSON.stringify(p.output);
1134
+ const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
1135
+ if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
1136
+ return info;
1137
+ }
1138
+ function decode(raw) {
1139
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("opencode: hook payload is not an object");
1140
+ const p = raw;
1141
+ const native = typeof p.type === "string" ? p.type : "";
1142
+ const event = Object.prototype.hasOwnProperty.call(OPENCODE_EVENTS, native) ? OPENCODE_EVENTS[native] : void 0;
1143
+ if (event === void 0) throw new Error("opencode: unknown hook event " + String(p.type));
1144
+ const ev = { event, agent: "opencode", sessionId: String(p.sessionID ?? ""), cwd: String(p.directory ?? "") };
1145
+ if (typeof p.agentID === "string" && p.agentID !== "") {
1146
+ ev.agentId = p.agentID;
1147
+ ev.agentType = p.agentID;
1148
+ }
1149
+ if (Array.isArray(p.agentTools)) ev.agentTools = p.agentTools.filter((t) => typeof t === "string");
1150
+ if (event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
1151
+ if (event === "PreToolUse" || event === "PostToolUse") {
1152
+ const name = String(p.tool ?? "");
1153
+ ev.tool = { name, canonicalName: toCanonicalTool(name), input: record(p.args) };
1154
+ if (typeof p.callID === "string") ev.tool.callId = p.callID;
1155
+ }
1156
+ if (event === "PostToolUse") ev.result = readResult(p);
1157
+ if (typeof p.turn === "number") ev.turn = p.turn;
1158
+ return ev;
1159
+ }
1160
+ function encode(ev, d, _extra) {
1161
+ switch (d.kind) {
1162
+ case "allow":
1163
+ return { stdout: "", exitCode: 0 };
1164
+ case "hint":
1165
+ return { stdout: ev.event === "SessionStart" ? d.text : "", exitCode: 0 };
1166
+ case "deny":
1167
+ if (ev.event !== "PreToolUse") return { stdout: "", exitCode: 0 };
1168
+ return { stdout: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason, exitCode: 2 };
1169
+ case "replace":
1170
+ return { stdout: ev.event === "PostToolUse" ? d.output : "", exitCode: 0 };
1171
+ }
1172
+ }
1173
+
1016
1174
  // src/core/contracts/errors.ts
1017
1175
  var ERROR_TEXT = Object.freeze({
1018
1176
  NODE_TOO_OLD: "Context Mode needs Node 24.15.0 or newer; you have <v>. Fix: nvm install 24, or install it from https://nodejs.org.",
@@ -1086,14 +1244,14 @@ var CtxError = class extends Error {
1086
1244
  };
1087
1245
 
1088
1246
  // src/core/hooks/dispatch.ts
1089
- import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
1247
+ import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
1090
1248
 
1091
1249
  // src/core/contracts/agents.ts
1092
1250
  var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
1093
1251
 
1094
1252
  // src/adapters/claude-code.ts
1095
- var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1096
- var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
1253
+ var TOOL_NAME_PREFIX2 = "mcp__plugin_context-mode_context-mode__";
1254
+ var SHELL_TOOL_NAMES2 = Object.freeze(["Bash", "PowerShell"]);
1097
1255
  var POWERSHELL_TOOL = "PowerShell";
1098
1256
  var SHELL_CANONICAL = "Bash";
1099
1257
  var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
@@ -1178,7 +1336,7 @@ function blocksOf(resp) {
1178
1336
  }
1179
1337
  return { text: parts.join("\n"), keep };
1180
1338
  }
1181
- function readResult(resp) {
1339
+ function readResult2(resp) {
1182
1340
  const text = outputOf(resp);
1183
1341
  const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
1184
1342
  const info = { isError, bytes: Buffer.byteLength(text), text };
@@ -1218,7 +1376,7 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
1218
1376
  if (typeof p.tool_use_id === "string" && p.tool_use_id !== "") tool.callId = p.tool_use_id;
1219
1377
  ev.tool = tool;
1220
1378
  }
1221
- if (event === "PostToolUse") ev.result = readResult(p.tool_response);
1379
+ if (event === "PostToolUse") ev.result = readResult2(p.tool_response);
1222
1380
  return ev;
1223
1381
  }
1224
1382
  function replaceShape(ev, output) {
@@ -1268,9 +1426,9 @@ function requireFields(raw) {
1268
1426
  if (p[f] === void 0) throw new Error("claude-code: missing required field " + f);
1269
1427
  }
1270
1428
  }
1271
- function decode(raw) {
1429
+ function decode2(raw) {
1272
1430
  requireFields(raw);
1273
- const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
1431
+ const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX2, CLAUDE_SOURCES);
1274
1432
  if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
1275
1433
  if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
1276
1434
  if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
@@ -1279,29 +1437,29 @@ function decode(raw) {
1279
1437
  }
1280
1438
  return ev;
1281
1439
  }
1282
- function encode(ev, d, _extra) {
1440
+ function encode2(ev, d, _extra) {
1283
1441
  return encodeClaudeShape(ev, d, true);
1284
1442
  }
1285
1443
 
1286
1444
  // src/adapters/codex.ts
1287
- var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
1445
+ var TOOL_NAME_PREFIX3 = "mcp__context_mode__";
1288
1446
  var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
1289
1447
  var STOP_EVENT = "Stop";
1290
1448
  var EMPTY = { stdout: "", exitCode: 0 };
1291
- function decode2(raw) {
1449
+ function decode3(raw) {
1292
1450
  if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
1293
1451
  const p = raw;
1294
1452
  return { event: STOP_EVENT, agent: "codex", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
1295
1453
  }
1296
- return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
1454
+ return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX3, CODEX_SOURCES);
1297
1455
  }
1298
- function encode2(ev, d, _extra) {
1456
+ function encode3(ev, d, _extra) {
1299
1457
  if (ev.event === STOP_EVENT) return EMPTY;
1300
1458
  return encodeClaudeShape(ev, d, false);
1301
1459
  }
1302
1460
 
1303
1461
  // src/adapters/gemini.ts
1304
- var TOOL_NAME_PREFIX3 = "mcp_context-mode_";
1462
+ var TOOL_NAME_PREFIX4 = "mcp_context-mode_";
1305
1463
  var GEMINI_EVENTS = {
1306
1464
  SessionStart: "SessionStart",
1307
1465
  BeforeAgent: "UserPromptSubmit",
@@ -1317,15 +1475,15 @@ var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its
1317
1475
  function own(p, key) {
1318
1476
  return Object.hasOwn(p, key) ? p[key] : void 0;
1319
1477
  }
1320
- var NATIVE_TO_CANONICAL = {
1478
+ var NATIVE_TO_CANONICAL2 = {
1321
1479
  run_shell_command: "Bash",
1322
1480
  read_file: "Read",
1323
1481
  grep_search: "Grep",
1324
1482
  web_fetch: "WebFetch"
1325
1483
  };
1326
1484
  function canonicalName2(name, mcp) {
1327
- if (name.startsWith(TOOL_NAME_PREFIX3)) return name.slice(TOOL_NAME_PREFIX3.length);
1328
- if (Object.hasOwn(NATIVE_TO_CANONICAL, name)) return NATIVE_TO_CANONICAL[name];
1485
+ if (name.startsWith(TOOL_NAME_PREFIX4)) return name.slice(TOOL_NAME_PREFIX4.length);
1486
+ if (Object.hasOwn(NATIVE_TO_CANONICAL2, name)) return NATIVE_TO_CANONICAL2[name];
1329
1487
  if (typeof mcp !== "object" || mcp === null) return name;
1330
1488
  const m = mcp;
1331
1489
  const server2 = own(m, "server_name");
@@ -1348,7 +1506,7 @@ function partsText(llm) {
1348
1506
  }
1349
1507
  return out.join("");
1350
1508
  }
1351
- function readResult2(resp) {
1509
+ function readResult3(resp) {
1352
1510
  const obj = typeof resp === "object" && resp !== null ? resp : void 0;
1353
1511
  const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
1354
1512
  const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
@@ -1400,7 +1558,7 @@ function nativeInput(name, input) {
1400
1558
  }
1401
1559
  return input;
1402
1560
  }
1403
- function decode3(raw) {
1561
+ function decode4(raw) {
1404
1562
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
1405
1563
  const p = raw;
1406
1564
  const native = own(p, "hook_event_name");
@@ -1420,10 +1578,10 @@ function decode3(raw) {
1420
1578
  input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
1421
1579
  };
1422
1580
  }
1423
- if (event === "PostToolUse") ev.result = readResult2(own(p, "tool_response"));
1581
+ if (event === "PostToolUse") ev.result = readResult3(own(p, "tool_response"));
1424
1582
  return ev;
1425
1583
  }
1426
- function encode3(ev, d, _extra) {
1584
+ function encode4(ev, d, _extra) {
1427
1585
  switch (d.kind) {
1428
1586
  case "allow":
1429
1587
  return EMPTY2;
@@ -1440,9 +1598,9 @@ function encode3(ev, d, _extra) {
1440
1598
  }
1441
1599
 
1442
1600
  // src/adapters/qwen.ts
1443
- var TOOL_NAME_PREFIX4 = "mcp__context-mode__";
1601
+ var TOOL_NAME_PREFIX5 = "mcp__context-mode__";
1444
1602
  var QWEN_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1445
- var NATIVE_TO_CANONICAL2 = {
1603
+ var NATIVE_TO_CANONICAL3 = {
1446
1604
  run_shell_command: "Bash",
1447
1605
  Shell: "Bash",
1448
1606
  read_file: "Read",
@@ -1450,11 +1608,11 @@ var NATIVE_TO_CANONICAL2 = {
1450
1608
  web_fetch: "WebFetch"
1451
1609
  };
1452
1610
  var FAILURE_EVENT = "PostToolUseFailure";
1453
- function decode4(raw) {
1611
+ function decode5(raw) {
1454
1612
  const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
1455
1613
  const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
1456
- const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX4, QWEN_SOURCES);
1457
- if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL2, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL2[ev.tool.name];
1614
+ const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX5, QWEN_SOURCES);
1615
+ if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL3, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL3[ev.tool.name];
1458
1616
  if (failure) {
1459
1617
  const error40 = raw.error;
1460
1618
  const text = typeof error40 === "string" ? error40 : error40 === void 0 ? "" : JSON.stringify(error40);
@@ -1462,12 +1620,12 @@ function decode4(raw) {
1462
1620
  }
1463
1621
  return ev;
1464
1622
  }
1465
- function encode4(ev, d, _extra) {
1623
+ function encode5(ev, d, _extra) {
1466
1624
  return encodeClaudeShape(ev, d, false);
1467
1625
  }
1468
1626
 
1469
1627
  // src/adapters/copilot-cli.ts
1470
- var TOOL_NAME_PREFIX5 = "context-mode-";
1628
+ var TOOL_NAME_PREFIX6 = "context-mode-";
1471
1629
  var NATIVE_EVENTS = {
1472
1630
  sessionStart: { event: "SessionStart", casing: "camel", failure: false },
1473
1631
  userPromptSubmitted: { event: "UserPromptSubmit", casing: "camel", failure: false },
@@ -1489,11 +1647,11 @@ var RESULT_SUCCESS = "success";
1489
1647
  function isRecord(v) {
1490
1648
  return typeof v === "object" && v !== null && !Array.isArray(v);
1491
1649
  }
1492
- var SHELL_TOOL_NAMES2 = Object.freeze(["bash", "powershell"]);
1493
- var NATIVE_TO_CANONICAL3 = Object.fromEntries(SHELL_TOOL_NAMES2.map((n) => [n, "Bash"]));
1650
+ var SHELL_TOOL_NAMES3 = Object.freeze(["bash", "powershell"]);
1651
+ var NATIVE_TO_CANONICAL4 = Object.fromEntries(SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]));
1494
1652
  function canonicalName3(name) {
1495
- if (name.startsWith(TOOL_NAME_PREFIX5)) return name.slice(TOOL_NAME_PREFIX5.length);
1496
- if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
1653
+ if (name.startsWith(TOOL_NAME_PREFIX6)) return name.slice(TOOL_NAME_PREFIX6.length);
1654
+ if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
1497
1655
  return name;
1498
1656
  }
1499
1657
  var isNum = (v) => typeof v === "number" && Number.isFinite(v);
@@ -1518,7 +1676,7 @@ var RESULT_KEYS = {
1518
1676
  camel: { type: "resultType", text: "textResultForLlm" },
1519
1677
  snake: { type: "result_type", text: "text_result_for_llm" }
1520
1678
  };
1521
- function readResult3(v, casing, failure) {
1679
+ function readResult4(v, casing, failure) {
1522
1680
  const k = RESULT_KEYS[casing];
1523
1681
  const r = isRecord(v) ? v : {};
1524
1682
  const text = typeof r[k.text] === "string" ? r[k.text] : "";
@@ -1536,7 +1694,7 @@ function eventName(raw) {
1536
1694
  if (raw.hook_event_name !== void 0) return raw.hook_event_name;
1537
1695
  return EVENT_BY_KEY.find(([key]) => Object.hasOwn(raw, key))?.[1];
1538
1696
  }
1539
- function decode5(raw) {
1697
+ function decode6(raw) {
1540
1698
  if (!isRecord(raw)) throw new Error("copilot-cli: hook payload is not a JSON object");
1541
1699
  const name = eventName(raw);
1542
1700
  const native = typeof name === "string" ? NATIVE_EVENTS[name] : void 0;
@@ -1551,11 +1709,11 @@ function decode5(raw) {
1551
1709
  const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
1552
1710
  ev.tool = tool;
1553
1711
  }
1554
- if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
1712
+ if (event === "PostToolUse") ev.result = readResult4(raw[k.result], native.casing, native.failure);
1555
1713
  return ev;
1556
1714
  }
1557
1715
  var EMPTY3 = { stdout: "", exitCode: 0 };
1558
- function encode5(ev, d, _extra) {
1716
+ function encode6(ev, d, _extra) {
1559
1717
  switch (d.kind) {
1560
1718
  case "allow":
1561
1719
  return EMPTY3;
@@ -1574,22 +1732,22 @@ function encode5(ev, d, _extra) {
1574
1732
  }
1575
1733
 
1576
1734
  // src/adapters/vscode.ts
1577
- var TOOL_NAME_PREFIX6 = "mcp_context-mode_";
1735
+ var TOOL_NAME_PREFIX7 = "mcp_context-mode_";
1578
1736
  var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PreCompact"];
1579
1737
  var MCP_PREFIX2 = "mcp_";
1580
1738
  var MCP_SEP2 = "_";
1581
1739
  var SESSION_START_NEW = "new";
1582
- var SHELL_TOOL_NAMES3 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
1740
+ var SHELL_TOOL_NAMES4 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
1583
1741
  var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
1584
1742
  var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
1585
- var NATIVE_TO_CANONICAL4 = Object.fromEntries([
1586
- ...SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]),
1743
+ var NATIVE_TO_CANONICAL5 = Object.fromEntries([
1744
+ ...SHELL_TOOL_NAMES4.map((n) => [n, "Bash"]),
1587
1745
  ...READ_TOOL_NAMES.map((n) => [n, "Read"]),
1588
1746
  ...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
1589
1747
  ]);
1590
1748
  function canonicalName4(name) {
1591
- if (name.startsWith(TOOL_NAME_PREFIX6)) return name.slice(TOOL_NAME_PREFIX6.length);
1592
- if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
1749
+ if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
1750
+ if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
1593
1751
  if (!name.startsWith(MCP_PREFIX2)) return name;
1594
1752
  const rest = name.slice(MCP_PREFIX2.length);
1595
1753
  const sep5 = rest.indexOf(MCP_SEP2);
@@ -1616,7 +1774,7 @@ function policyInput(name, canonical, input) {
1616
1774
  }
1617
1775
  return input;
1618
1776
  }
1619
- function readResult4(resp) {
1777
+ function readResult5(resp) {
1620
1778
  const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
1621
1779
  const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
1622
1780
  return { isError, bytes: Buffer.byteLength(text), text };
@@ -1669,7 +1827,7 @@ function decodeCamel(p, name) {
1669
1827
  if (event === "PostToolUse") ev.result = readCamelResult(p.toolResult);
1670
1828
  return ev;
1671
1829
  }
1672
- function decode6(raw) {
1830
+ function decode7(raw) {
1673
1831
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("vscode: hook payload is not a JSON object");
1674
1832
  const p = raw;
1675
1833
  if (p.hookEventName !== void 0) return decodeCamel(p, p.hookEventName);
@@ -1689,15 +1847,15 @@ function decode6(raw) {
1689
1847
  const canonical = canonicalName4(name);
1690
1848
  ev.tool = { name, canonicalName: canonical, input: policyInput(name, canonical, input) };
1691
1849
  }
1692
- if (event === "PostToolUse") ev.result = readResult4(p.tool_response);
1850
+ if (event === "PostToolUse") ev.result = readResult5(p.tool_response);
1693
1851
  return ev;
1694
1852
  }
1695
- function encode6(ev, d, _extra) {
1853
+ function encode7(ev, d, _extra) {
1696
1854
  return encodeClaudeShape(ev, d, false);
1697
1855
  }
1698
1856
 
1699
1857
  // src/adapters/kiro.ts
1700
- var TOOL_NAME_PREFIX7 = "mcp_context_mode_";
1858
+ var TOOL_NAME_PREFIX8 = "mcp_context_mode_";
1701
1859
  var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
1702
1860
  var KIRO_EVENTS = {
1703
1861
  SessionStart: "SessionStart",
@@ -1713,25 +1871,25 @@ var KIRO_EVENTS = {
1713
1871
  var PROMPT_FIELD = "prompt";
1714
1872
  var PROMPT_ENV = "USER_PROMPT";
1715
1873
  var MCP_PREFIX3 = "mcp_";
1716
- var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
1717
- var NATIVE_TO_CANONICAL5 = Object.fromEntries(SHELL_TOOL_NAMES4.map((n) => [n, "Bash"]));
1874
+ var SHELL_TOOL_NAMES5 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
1875
+ var NATIVE_TO_CANONICAL6 = Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"]));
1718
1876
  var MCP_SEP3 = "_";
1719
1877
  var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1720
1878
  function canonicalName5(name) {
1721
- if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
1879
+ if (name.startsWith(TOOL_NAME_PREFIX8)) return name.slice(TOOL_NAME_PREFIX8.length);
1722
1880
  if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
1723
- if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
1881
+ if (Object.hasOwn(NATIVE_TO_CANONICAL6, name)) return NATIVE_TO_CANONICAL6[name];
1724
1882
  if (!name.startsWith(MCP_PREFIX3)) return name;
1725
1883
  const rest = name.slice(MCP_PREFIX3.length);
1726
1884
  const sep5 = rest.indexOf(MCP_SEP3);
1727
1885
  if (sep5 <= 0 || sep5 === rest.length - 1) return name;
1728
1886
  return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP3.length);
1729
1887
  }
1730
- function readResult5(resp) {
1888
+ function readResult6(resp) {
1731
1889
  const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
1732
1890
  return { isError: false, bytes: Buffer.byteLength(text), text };
1733
1891
  }
1734
- function decode7(raw) {
1892
+ function decode8(raw) {
1735
1893
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("kiro: hook payload is not a JSON object");
1736
1894
  const p = raw;
1737
1895
  const native = typeof p.hook_event_name === "string" ? p.hook_event_name : "";
@@ -1749,10 +1907,10 @@ function decode7(raw) {
1749
1907
  const input = typeof p.tool_input === "object" && p.tool_input !== null && !Array.isArray(p.tool_input) ? p.tool_input : {};
1750
1908
  ev.tool = { name, canonicalName: canonicalName5(name), input };
1751
1909
  }
1752
- if (event === "PostToolUse") ev.result = readResult5(p.tool_response);
1910
+ if (event === "PostToolUse") ev.result = readResult6(p.tool_response);
1753
1911
  return ev;
1754
1912
  }
1755
- function encode7(ev, d, _extra) {
1913
+ function encode8(ev, d, _extra) {
1756
1914
  if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
1757
1915
  switch (d.kind) {
1758
1916
  case "allow":
@@ -1767,19 +1925,19 @@ function encode7(ev, d, _extra) {
1767
1925
  }
1768
1926
 
1769
1927
  // src/adapters/zcode.ts
1770
- var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1928
+ var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
1771
1929
  var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1772
1930
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1773
1931
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1774
1932
  var FAILURE_EVENT2 = "PostToolUseFailure";
1775
- function decode8(raw) {
1933
+ function decode9(raw) {
1776
1934
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
1777
1935
  const p = { ...raw };
1778
1936
  for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
1779
1937
  const failure = p.hook_event_name === FAILURE_EVENT2;
1780
1938
  if (failure) p.hook_event_name = "PostToolUse";
1781
1939
  const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
1782
- const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
1940
+ const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
1783
1941
  const ev = decodeClaudeShape(p, "zcode", prefix, ZCODE_SOURCES);
1784
1942
  if (failure) {
1785
1943
  const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
@@ -1787,12 +1945,12 @@ function decode8(raw) {
1787
1945
  }
1788
1946
  return ev;
1789
1947
  }
1790
- function encode8(ev, d, _extra) {
1948
+ function encode9(ev, d, _extra) {
1791
1949
  return encodeClaudeShape(ev, d, false);
1792
1950
  }
1793
1951
 
1794
1952
  // src/adapters/pi.ts
1795
- var TOOL_NAME_PREFIX9 = "";
1953
+ var TOOL_NAME_PREFIX10 = "";
1796
1954
  var PI_EVENTS = {
1797
1955
  session_start: { event: "SessionStart", source: "startup" },
1798
1956
  session_compact: { event: "SessionStart", source: "compact" },
@@ -1800,17 +1958,18 @@ var PI_EVENTS = {
1800
1958
  tool_call: { event: "PreToolUse" },
1801
1959
  tool_result: { event: "PostToolUse" }
1802
1960
  };
1803
- var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
1804
- function record(v) {
1961
+ var NATIVE_TO_CANONICAL7 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
1962
+ function record2(v) {
1805
1963
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
1806
1964
  }
1807
- function readResult6(p) {
1965
+ function readResult7(p) {
1808
1966
  const text = p.content === void 0 ? "" : typeof p.content === "string" ? p.content : JSON.stringify(p.content);
1809
1967
  const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
1810
1968
  if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
1969
+ if (p.keep === true) info.keep = true;
1811
1970
  return info;
1812
1971
  }
1813
- function decode9(raw) {
1972
+ function decode10(raw) {
1814
1973
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("pi: hook payload is not an object");
1815
1974
  const p = raw;
1816
1975
  const native = typeof p.type === "string" ? p.type : "";
@@ -1821,10 +1980,10 @@ function decode9(raw) {
1821
1980
  if (row5.event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
1822
1981
  if (row5.event === "PreToolUse" || row5.event === "PostToolUse") {
1823
1982
  const name = String(p.toolName ?? "");
1824
- ev.tool = { name, canonicalName: Object.hasOwn(NATIVE_TO_CANONICAL6, name) ? NATIVE_TO_CANONICAL6[name] : name, input: record(p.input) };
1983
+ ev.tool = { name, canonicalName: Object.hasOwn(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name, input: record2(p.input) };
1825
1984
  if (typeof p.toolCallId === "string") ev.tool.callId = p.toolCallId;
1826
1985
  }
1827
- if (row5.event === "PostToolUse") ev.result = readResult6(p);
1986
+ if (row5.event === "PostToolUse") ev.result = readResult7(p);
1828
1987
  if (typeof p.turn === "number") ev.turn = p.turn;
1829
1988
  return ev;
1830
1989
  }
@@ -1840,7 +1999,7 @@ function stdoutFor(ev, d) {
1840
1999
  }
1841
2000
  return { stdout: "", exitCode: 0 };
1842
2001
  }
1843
- function encode9(ev, d, _extra) {
2002
+ function encode10(ev, d, _extra) {
1844
2003
  const out = stdoutFor(ev, d);
1845
2004
  if (d?.kind === "allow") return out;
1846
2005
  return { stdout: out.stdout, exitCode: out.exitCode, role: PI_ROLE, content: out.stdout, timestamp: Date.now() };
@@ -1849,75 +2008,16 @@ function checkPermission(out) {
1849
2008
  return out.exitCode === 2 ? { block: true, reason: out.stdout } : void 0;
1850
2009
  }
1851
2010
 
1852
- // src/adapters/opencode.ts
1853
- var TOOL_NAME_PREFIX10 = "";
1854
- var OWN_WIRE_PREFIX = SERVER_KEY + "_";
1855
- var OPENCODE_EVENTS = {
1856
- context: "SessionStart",
1857
- prompt: "UserPromptSubmit",
1858
- "execute.before": "PreToolUse",
1859
- "execute.after": "PostToolUse",
1860
- compaction: "PreCompact",
1861
- "step-finish": "Usage"
1862
- };
1863
- var SHELL_TOOL_NAME = "bash";
1864
- var READ_TOOL_NAME = "read";
1865
- var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1866
- var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1867
- function toCanonicalTool(name) {
1868
- if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1869
- return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
1870
- }
1871
- function record2(v) {
1872
- return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
1873
- }
1874
- function readResult7(p) {
1875
- const text = p.output === void 0 ? "" : typeof p.output === "string" ? p.output : JSON.stringify(p.output);
1876
- const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
1877
- if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
1878
- return info;
1879
- }
1880
- function decode10(raw) {
1881
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("opencode: hook payload is not an object");
1882
- const p = raw;
1883
- const native = typeof p.type === "string" ? p.type : "";
1884
- const event = Object.prototype.hasOwnProperty.call(OPENCODE_EVENTS, native) ? OPENCODE_EVENTS[native] : void 0;
1885
- if (event === void 0) throw new Error("opencode: unknown hook event " + String(p.type));
1886
- const ev = { event, agent: "opencode", sessionId: String(p.sessionID ?? ""), cwd: String(p.directory ?? "") };
1887
- if (event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
1888
- if (event === "PreToolUse" || event === "PostToolUse") {
1889
- const name = String(p.tool ?? "");
1890
- ev.tool = { name, canonicalName: toCanonicalTool(name), input: record2(p.args) };
1891
- if (typeof p.callID === "string") ev.tool.callId = p.callID;
1892
- }
1893
- if (event === "PostToolUse") ev.result = readResult7(p);
1894
- if (typeof p.turn === "number") ev.turn = p.turn;
1895
- return ev;
1896
- }
1897
- function encode10(ev, d, _extra) {
1898
- switch (d.kind) {
1899
- case "allow":
1900
- return { stdout: "", exitCode: 0 };
1901
- case "hint":
1902
- return { stdout: ev.event === "SessionStart" ? d.text : "", exitCode: 0 };
1903
- case "deny":
1904
- if (ev.event !== "PreToolUse") return { stdout: "", exitCode: 0 };
1905
- return { stdout: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason, exitCode: 2 };
1906
- case "replace":
1907
- return { stdout: "", exitCode: 0 };
1908
- }
1909
- }
1910
-
1911
2011
  // src/adapters/table.ts
1912
2012
  var CLAUDE_EVENTS = { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" };
1913
2013
  var CLAUDE_TOOLS = { shell: ["Bash"], read: ["Read"], grep: ["Grep"], webfetch: ["WebFetch"], edit: ["Write", "Edit", "NotebookEdit"] };
1914
- var CLAUDE_CODE_TOOLS = { ...CLAUDE_TOOLS, shell: [...SHELL_TOOL_NAMES] };
2014
+ var CLAUDE_CODE_TOOLS = { ...CLAUDE_TOOLS, shell: [...SHELL_TOOL_NAMES2] };
1915
2015
  var ADAPTERS = Object.freeze([
1916
2016
  {
1917
2017
  id: "claude-code",
1918
2018
  installMode: "marketplace",
1919
2019
  projectSource: "env:CLAUDE_PROJECT_DIR",
1920
- toolNamePrefix: TOOL_NAME_PREFIX,
2020
+ toolNamePrefix: TOOL_NAME_PREFIX2,
1921
2021
  nativeTools: CLAUDE_CODE_TOOLS,
1922
2022
  execReadOnlyHint: false,
1923
2023
  eventMap: CLAUDE_EVENTS,
@@ -1928,14 +2028,14 @@ var ADAPTERS = Object.freeze([
1928
2028
  hookChannel: { kind: "package", path: "hooks/claude-code.json" },
1929
2029
  skillChannel: { kind: "package", path: "skills" },
1930
2030
  // ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
1931
- decode,
1932
- encode
2031
+ decode: decode2,
2032
+ encode: encode2
1933
2033
  },
1934
2034
  {
1935
2035
  id: "codex",
1936
2036
  installMode: "config-mcp",
1937
2037
  projectSource: "arg:--agent+cwd",
1938
- toolNamePrefix: TOOL_NAME_PREFIX2,
2038
+ toolNamePrefix: TOOL_NAME_PREFIX3,
1939
2039
  nativeTools: { shell: ["Bash"], edit: ["apply_patch"] },
1940
2040
  execReadOnlyHint: true,
1941
2041
  eventMap: CLAUDE_EVENTS,
@@ -1946,14 +2046,14 @@ var ADAPTERS = Object.freeze([
1946
2046
  hookChannel: { kind: "home-file", path: ".codex/hooks.json" },
1947
2047
  skillChannel: { kind: "home-dir", path: ".codex/skills" },
1948
2048
  // ADR-0020
1949
- decode: decode2,
1950
- encode: encode2
2049
+ decode: decode3,
2050
+ encode: encode3
1951
2051
  },
1952
2052
  {
1953
2053
  id: "gemini",
1954
2054
  installMode: "extension",
1955
2055
  projectSource: "spawn-cwd",
1956
- toolNamePrefix: TOOL_NAME_PREFIX3,
2056
+ toolNamePrefix: TOOL_NAME_PREFIX4,
1957
2057
  // D-HA-GEMINI-NAMES-1: gemini-cli 0.65.0 *_TOOL_NAME constants.
1958
2058
  nativeTools: { shell: ["run_shell_command"], read: ["read_file"], grep: ["grep_search"], webfetch: ["web_fetch"] },
1959
2059
  execReadOnlyHint: false,
@@ -1968,14 +2068,14 @@ var ADAPTERS = Object.freeze([
1968
2068
  hookChannel: { kind: "package", path: "hooks/hooks.json" },
1969
2069
  skillChannel: { kind: "package", path: "skills" },
1970
2070
  // ADR-0020
1971
- decode: decode3,
1972
- encode: encode3
2071
+ decode: decode4,
2072
+ encode: encode4
1973
2073
  },
1974
2074
  {
1975
2075
  id: "qwen",
1976
2076
  installMode: "extension",
1977
2077
  projectSource: "spawn-cwd",
1978
- toolNamePrefix: TOOL_NAME_PREFIX4,
2078
+ toolNamePrefix: TOOL_NAME_PREFIX5,
1979
2079
  nativeTools: { shell: ["run_shell_command", "Shell"], read: ["read_file"], grep: ["grep_search"], webfetch: ["web_fetch"] },
1980
2080
  execReadOnlyHint: false,
1981
2081
  eventMap: CLAUDE_EVENTS,
@@ -1986,15 +2086,15 @@ var ADAPTERS = Object.freeze([
1986
2086
  hookChannel: { kind: "package", path: "hooks/qwen.json" },
1987
2087
  skillChannel: { kind: "package", path: "skills" },
1988
2088
  // ADR-0020, D-HQ-SKILLS-3: qwen loads <extension>/skills, shared with gemini
1989
- decode: decode4,
1990
- encode: encode4
2089
+ decode: decode5,
2090
+ encode: encode5
1991
2091
  },
1992
2092
  {
1993
2093
  id: "copilot-cli",
1994
2094
  installMode: "plugin",
1995
2095
  projectSource: "arg:--agent+cwd",
1996
- toolNamePrefix: TOOL_NAME_PREFIX5,
1997
- nativeTools: { shell: [...SHELL_TOOL_NAMES2] },
2096
+ toolNamePrefix: TOOL_NAME_PREFIX6,
2097
+ nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
1998
2098
  execReadOnlyHint: false,
1999
2099
  // D-PWSH-DUMP-1
2000
2100
  eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
@@ -2005,16 +2105,16 @@ var ADAPTERS = Object.freeze([
2005
2105
  hookChannel: { kind: "home-file", path: ".copilot/hooks/context-mode.json" },
2006
2106
  skillChannel: { kind: "home-dir", path: ".copilot/skills" },
2007
2107
  // ADR-0020
2008
- decode: decode5,
2009
- encode: encode5
2108
+ decode: decode6,
2109
+ encode: encode6
2010
2110
  },
2011
2111
  {
2012
2112
  id: "vscode",
2013
2113
  installMode: "mcp-entry",
2014
2114
  projectSource: "arg:workspaceFolder",
2015
- toolNamePrefix: TOOL_NAME_PREFIX6,
2115
+ toolNamePrefix: TOOL_NAME_PREFIX7,
2016
2116
  // PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
2017
- nativeTools: { shell: [...SHELL_TOOL_NAMES3], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
2117
+ nativeTools: { shell: [...SHELL_TOOL_NAMES4], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
2018
2118
  // D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
2019
2119
  execReadOnlyHint: false,
2020
2120
  eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
@@ -2025,15 +2125,15 @@ var ADAPTERS = Object.freeze([
2025
2125
  hookChannel: { kind: "home-file", path: ".copilot/hooks/context-mode-vscode.json" },
2026
2126
  skillChannel: { kind: "home-dir", path: ".agents/skills" },
2027
2127
  // ADR-0020, D-HQ-COPILOT-NAMES-3: Copilot CLI owns ~/.copilot/skills
2028
- decode: decode6,
2029
- encode: encode6
2128
+ decode: decode7,
2129
+ encode: encode7
2030
2130
  },
2031
2131
  {
2032
2132
  id: "kiro",
2033
2133
  installMode: "mcp-entry",
2034
2134
  projectSource: "arg:--agent+cwd",
2035
- toolNamePrefix: TOOL_NAME_PREFIX7,
2036
- nativeTools: { shell: [...SHELL_TOOL_NAMES4] },
2135
+ toolNamePrefix: TOOL_NAME_PREFIX8,
2136
+ nativeTools: { shell: [...SHELL_TOOL_NAMES5] },
2037
2137
  execReadOnlyHint: false,
2038
2138
  // D-HF-KIRO-SHELL-1, D-N7-KIRO-1
2039
2139
  eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
@@ -2044,15 +2144,15 @@ var ADAPTERS = Object.freeze([
2044
2144
  hookChannel: { kind: "home-file", path: ".kiro/hooks/context-mode.json" },
2045
2145
  skillChannel: { kind: "home-dir", path: ".kiro/skills" },
2046
2146
  // ADR-0020
2047
- decode: decode7,
2048
- encode: encode7
2147
+ decode: decode8,
2148
+ encode: encode8
2049
2149
  },
2050
2150
  {
2051
2151
  // toolNamePrefix is the documented ZCode name mcp__<server>__<tool> (D-N7-ZCODE-NAMES-1); nativeTools are Claude names.
2052
2152
  id: "zcode",
2053
2153
  installMode: "hooks+mcp",
2054
2154
  projectSource: "spawn-cwd",
2055
- toolNamePrefix: TOOL_NAME_PREFIX8,
2155
+ toolNamePrefix: TOOL_NAME_PREFIX9,
2056
2156
  nativeTools: CLAUDE_TOOLS,
2057
2157
  execReadOnlyHint: false,
2058
2158
  eventMap: CLAUDE_EVENTS,
@@ -2063,14 +2163,14 @@ var ADAPTERS = Object.freeze([
2063
2163
  hookChannel: { kind: "home-file", path: ".zcode/cli/config.json" },
2064
2164
  skillChannel: { kind: "home-dir", path: ".zcode/skills" },
2065
2165
  // ADR-0020
2066
- decode: decode8,
2067
- encode: encode8
2166
+ decode: decode9,
2167
+ encode: encode9
2068
2168
  },
2069
2169
  {
2070
2170
  id: "pi",
2071
2171
  installMode: "in-process",
2072
2172
  projectSource: "pi:ctx.cwd",
2073
- toolNamePrefix: TOOL_NAME_PREFIX9,
2173
+ toolNamePrefix: TOOL_NAME_PREFIX10,
2074
2174
  nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
2075
2175
  execReadOnlyHint: false,
2076
2176
  // D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
@@ -2082,15 +2182,15 @@ var ADAPTERS = Object.freeze([
2082
2182
  hookChannel: { kind: "in-process", path: "pi/index.js" },
2083
2183
  skillChannel: { kind: "package", path: "pi/skills" },
2084
2184
  // ADR-0020
2085
- decode: decode9,
2086
- encode: encode9,
2185
+ decode: decode10,
2186
+ encode: encode10,
2087
2187
  checkPermission
2088
2188
  },
2089
2189
  {
2090
2190
  id: "opencode",
2091
2191
  installMode: "in-process",
2092
2192
  projectSource: "spawn-cwd",
2093
- toolNamePrefix: TOOL_NAME_PREFIX10,
2193
+ toolNamePrefix: TOOL_NAME_PREFIX,
2094
2194
  nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
2095
2195
  execReadOnlyHint: false,
2096
2196
  // D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
@@ -2103,13 +2203,13 @@ var ADAPTERS = Object.freeze([
2103
2203
  hookChannel: { kind: "in-process", path: "opencode/plugin.js" },
2104
2204
  skillChannel: { kind: "home-dir", path: ".config/opencode/skills" },
2105
2205
  // ADR-0020
2106
- decode: decode10,
2107
- encode: encode10,
2206
+ decode,
2207
+ encode,
2108
2208
  toCanonicalTool
2109
2209
  }
2110
2210
  ]);
2111
2211
  var BY_ID = new Map(ADAPTERS.map((r) => [r.id, r]));
2112
- var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi"]);
2212
+ var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode"]);
2113
2213
  function hasReplace(row5) {
2114
2214
  return REPLACE_ROWS.has(row5.id);
2115
2215
  }
@@ -2126,7 +2226,7 @@ function getAdapter(id2) {
2126
2226
  }
2127
2227
 
2128
2228
  // src/core/policy/decide.ts
2129
- import { resolve as resolve3 } from "node:path";
2229
+ import { resolve as resolve5 } from "node:path";
2130
2230
 
2131
2231
  // src/core/policy/lexer.ts
2132
2232
  var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
@@ -3530,6 +3630,17 @@ function claudeDirOf(env, home) {
3530
3630
  const dir = env[CLAUDE_CONFIG_DIR_ENV];
3531
3631
  return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["claude-code"]);
3532
3632
  }
3633
+ function claudeProfileEnv(env, platform = process.platform) {
3634
+ const dir = env[CLAUDE_CONFIG_DIR_ENV];
3635
+ if (dir === void 0 || dir === "" || platform === "win32") return "";
3636
+ return `${CLAUDE_CONFIG_DIR_ENV}='${dir.split("'").join(`'"'"'`)}' `;
3637
+ }
3638
+ function hostUpdateCommand(agent, env, platform = process.platform) {
3639
+ const cmd = UPGRADE_HOST_COMMAND[agent];
3640
+ if (agent !== "claude-code") return cmd;
3641
+ const profile = claudeProfileEnv(env, platform);
3642
+ return profile === "" ? cmd : cmd.split(" && ").map((c) => profile + c).join(" && ");
3643
+ }
3533
3644
  function opencodeDirOf(env, home) {
3534
3645
  const own2 = env[OPENCODE_CONFIG_DIR_ENV];
3535
3646
  if (own2 !== void 0 && own2 !== "") return own2;
@@ -4064,10 +4175,10 @@ function READ_DENY_RANGE_MESSAGE(path8, size) {
4064
4175
  }
4065
4176
 
4066
4177
  // src/core/policy/own-file.ts
4067
- import { extname, join as join5 } from "node:path";
4178
+ import { extname, join as join5, resolve as resolve4 } from "node:path";
4068
4179
 
4069
4180
  // src/core/project/contain.ts
4070
- import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
4181
+ import { dirname as dirname2, isAbsolute as isAbsolute2, join as join4, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
4071
4182
  var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
4072
4183
  function real(p) {
4073
4184
  try {
@@ -4111,6 +4222,29 @@ function isInsideAny(roots, p) {
4111
4222
  return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
4112
4223
  });
4113
4224
  }
4225
+ function hasParentStep(cwd, p) {
4226
+ const parts = isAbsolute2(p) ? components(p) : [...components(cwd), ...components(p)];
4227
+ return parts.includes("..");
4228
+ }
4229
+ var rootParts = /* @__PURE__ */ new Map();
4230
+ function lexicalRoot(root) {
4231
+ let rc = rootParts.get(root);
4232
+ if (rc === void 0) {
4233
+ rc = components(resolve3(root));
4234
+ rootParts.set(root, rc);
4235
+ }
4236
+ return rc;
4237
+ }
4238
+ function isLexicallyInsideAny(roots, p) {
4239
+ if (roots.length === 0) return false;
4240
+ const raw = components(p);
4241
+ if (raw.includes("..")) return false;
4242
+ const qc = sep2 === "/" && isAbsolute2(p) ? raw.filter((c) => c !== ".") : components(resolve3(p));
4243
+ return roots.some((root) => {
4244
+ const rc = lexicalRoot(root);
4245
+ return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
4246
+ });
4247
+ }
4114
4248
  function commonRoot(paths) {
4115
4249
  const reals = paths.map(real).filter((r) => r !== void 0);
4116
4250
  if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
@@ -4151,9 +4285,11 @@ function ownDirsOf(agent, env) {
4151
4285
  const own2 = agent === "claude-code" ? [claudeDirOf(env, home)] : agent === "codex" ? [codexDirOf(env, home)] : agent === "gemini" ? [geminiDirOf(env, home)] : agent === "copilot-cli" ? [copilotDirOf(env, home)] : agent === "kiro" ? [kiroDirOf(env, home)] : agent === "opencode" ? [opencodeDirOf(env, home)] : agent === "pi" ? [piAgentDirOf(env, home)] : agent === "vscode" ? [join5(home, ...AGENT_HOME_DIR.vscode), vscodeUserDirOf(env, home)] : [join5(home, ...AGENT_HOME_DIR[agent])];
4152
4286
  return [...own2, shared];
4153
4287
  }
4154
- function isOwnFile(agent, abs, env = process.env) {
4155
- if (extname(abs).toLowerCase() !== AGENT_FILE_EXT) return false;
4156
- return isInsideAny(ownDirsOf(agent, env), abs);
4288
+ function isOwnFile(agent, cwd, p, env = process.env) {
4289
+ if (extname(p).toLowerCase() !== AGENT_FILE_EXT) return false;
4290
+ const dirs = ownDirsOf(agent, env);
4291
+ const abs = resolve4(cwd, p);
4292
+ return !hasParentStep(cwd, p) && isLexicallyInsideAny(dirs, abs) || isInsideAny(dirs, abs);
4157
4293
  }
4158
4294
 
4159
4295
  // src/core/policy/read-media.ts
@@ -4244,7 +4380,7 @@ function readPaths(input) {
4244
4380
  }
4245
4381
  function userDenyHit(canonical, input, cwd, rules) {
4246
4382
  if (rules.length === 0) return null;
4247
- const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
4383
+ const readRule = (p) => matchesAnyDenyPattern(resolve5(cwd, p), rules, { tool: READ, projectDir: cwd });
4248
4384
  if (canonical === BASH) {
4249
4385
  const cmd = str(input.command);
4250
4386
  return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
@@ -4381,8 +4517,9 @@ function fileSize(abs) {
4381
4517
  return -1;
4382
4518
  }
4383
4519
  }
4384
- function bigDeny(ev, row5, abs, size, root) {
4385
- if (size <= OUTPUT_CAP || isOwnFile(ev.agent, abs)) return null;
4520
+ function bigDeny(ev, row5, cwd, p, size, root) {
4521
+ const abs = resolve5(cwd, p);
4522
+ if (size <= OUTPUT_CAP || isOwnFile(ev.agent, cwd, p)) return null;
4386
4523
  return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
4387
4524
  }
4388
4525
  function executeCanOpen(root, abs) {
@@ -4397,10 +4534,10 @@ function executeCanOpen(root, abs) {
4397
4534
  function read(ev, row5, input, root) {
4398
4535
  if (!present(input.offset) && !present(input.limit)) {
4399
4536
  for (const p of readPaths(input)) {
4400
- const abs = resolve3(ev.cwd, p);
4537
+ const abs = resolve5(ev.cwd, p);
4401
4538
  const size = fileSize(abs);
4402
4539
  if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
4403
- const d = bigDeny(ev, row5, abs, size, root);
4540
+ const d = bigDeny(ev, row5, ev.cwd, p, size, root);
4404
4541
  if (d !== null) return d;
4405
4542
  }
4406
4543
  }
@@ -4413,7 +4550,7 @@ function shellDump(ev, cmds, row5, root) {
4413
4550
  let verdict = null;
4414
4551
  for (const c of cmds) {
4415
4552
  const name = c.argv0.toLowerCase();
4416
- if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve3(dir, c.args[0]);
4553
+ if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve5(dir, c.args[0]);
4417
4554
  if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
4418
4555
  if (!has(SHELL_DUMP_COMMANDS, name)) continue;
4419
4556
  const d = dumpTarget(name, c.args);
@@ -4422,8 +4559,8 @@ function shellDump(ev, cmds, row5, root) {
4422
4559
  verdict = ALLOW;
4423
4560
  continue;
4424
4561
  }
4425
- const abs = resolve3(dir, d.file);
4426
- const big = bigDeny(ev, row5, abs, fileSize(abs), root);
4562
+ const abs = resolve5(dir, d.file);
4563
+ const big = bigDeny(ev, row5, dir, d.file, fileSize(abs), root);
4427
4564
  if (big !== null) return big;
4428
4565
  }
4429
4566
  return verdict;
@@ -4431,7 +4568,7 @@ function shellDump(ev, cmds, row5, root) {
4431
4568
  function psShellDump(ev, cmd, row5, root) {
4432
4569
  if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
4433
4570
  for (const abs of psDumpFiles(cmd, ev.cwd)) {
4434
- const d = bigDeny(ev, row5, abs, fileSize(abs), root);
4571
+ const d = bigDeny(ev, row5, ev.cwd, abs, fileSize(abs), root);
4435
4572
  if (d !== null) return d;
4436
4573
  }
4437
4574
  return null;
@@ -4493,7 +4630,7 @@ function dumpTarget(name, args) {
4493
4630
  }
4494
4631
 
4495
4632
  // src/core/project/resolve.ts
4496
- import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve4 } from "node:path";
4633
+ import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
4497
4634
 
4498
4635
  // src/core/project/sha256.ts
4499
4636
  var K = new Uint32Array([
@@ -4658,7 +4795,7 @@ function gitDirs(dir) {
4658
4795
  const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
4659
4796
  if (gitDir !== null) {
4660
4797
  const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
4661
- return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
4798
+ return { commonDir: realpathSync3.native(common === null ? gitDir : resolve6(gitDir, common)), worktree: cur, start };
4662
4799
  }
4663
4800
  const up = dirname3(cur);
4664
4801
  if (up === cur) return { commonDir: null, start };
@@ -4673,7 +4810,7 @@ function gitDirAt(dotGit) {
4673
4810
  } else {
4674
4811
  const line = firstLine(dotGit);
4675
4812
  if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
4676
- gitDir = resolve4(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
4813
+ gitDir = resolve6(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
4677
4814
  }
4678
4815
  } catch {
4679
4816
  return null;
@@ -8736,7 +8873,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
8736
8873
  }
8737
8874
 
8738
8875
  // src/core/hooks/fallback.ts
8739
- import { join as join7, resolve as resolve5 } from "node:path";
8876
+ import { join as join7, resolve as resolve7 } from "node:path";
8740
8877
  var fs = process.getBuiltinModule("node:fs");
8741
8878
  function isRec(v) {
8742
8879
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -8859,7 +8996,7 @@ function bigFile(abs) {
8859
8996
  function bigRead(agent, input, cwd) {
8860
8997
  if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
8861
8998
  const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
8862
- return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)) && !isOwnFile(agent, resolve5(cwd, p)));
8999
+ return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve7(cwd, p)) && !isMediaRead(agent, resolve7(cwd, p)) && !isOwnFile(agent, cwd, p));
8863
9000
  }
8864
9001
  function failureOutput(agent, raw, err, cwdFallback = "") {
8865
9002
  const row5 = getAdapter(agent);
@@ -9118,12 +9255,17 @@ function askDetached(ev, project, tool, text) {
9118
9255
  process.stderr.write("hooks: decision write failed: " + message(err) + "\n");
9119
9256
  });
9120
9257
  }
9258
+ function toolSetSources(ev, project, env) {
9259
+ const src = { projectDir: project.worktree, env };
9260
+ if (ev.agentTools !== void 0) src.manifestTools = ev.agentTools;
9261
+ return src;
9262
+ }
9121
9263
  async function preToolUse(ev, row5, project, env) {
9122
9264
  const userDeny = readUserDeny(project.worktree, ev.agent);
9123
9265
  const decision0 = decide(ev, row5, userDeny, project);
9124
9266
  let decision = decision0;
9125
9267
  if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
9126
- const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
9268
+ const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
9127
9269
  const subCase = pickSubagentCase(ev, set3);
9128
9270
  const tool = ev.tool;
9129
9271
  const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
@@ -9226,7 +9368,7 @@ async function postToolUse(ev, row5, project, env, settle) {
9226
9368
  function ownRead(ev, tool, env) {
9227
9369
  if (!RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
9228
9370
  const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
9229
- return p !== void 0 && isOwnFile(ev.agent, resolve6(ev.cwd, p), env);
9371
+ return p !== void 0 && isOwnFile(ev.agent, ev.cwd, p, env);
9230
9372
  }
9231
9373
  async function postReplace(ev, row5, project, env, tool, result, text) {
9232
9374
  if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
@@ -9236,7 +9378,7 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
9236
9378
  if (!hasReplace(row5)) return ALLOW2;
9237
9379
  let label2;
9238
9380
  if (isSubagentCall(ev)) {
9239
- const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
9381
+ const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, toolSetSources(ev, project, env)));
9240
9382
  if (subCase === "A") return ALLOW2;
9241
9383
  label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + String(ev.turn ?? 0);
9242
9384
  } else {
@@ -9275,7 +9417,7 @@ function replaceBudget(handleLine, more) {
9275
9417
  function hostToolResult(file2, sessionId, env) {
9276
9418
  if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
9277
9419
  const projects = join8(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
9278
- const steps = relative3(projects, resolve6(file2)).split(sep3);
9420
+ const steps = relative3(projects, resolve8(file2)).split(sep3);
9279
9421
  if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
9280
9422
  if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
9281
9423
  const st = lstatSync2(file2);
@@ -20620,11 +20762,11 @@ function noRuntimeError(lang) {
20620
20762
  }
20621
20763
 
20622
20764
  // src/core/sandbox/spawn.ts
20623
- import { spawn } from "node:child_process";
20765
+ import { spawn as spawn2 } from "node:child_process";
20624
20766
  import path2 from "node:path";
20625
20767
 
20626
20768
  // src/core/sandbox/kill.ts
20627
- import { execFileSync } from "node:child_process";
20769
+ import { spawn } from "node:child_process";
20628
20770
  function signalGroup(pid, signal) {
20629
20771
  try {
20630
20772
  process.kill(-pid, signal);
@@ -20638,7 +20780,10 @@ function killTree(pid) {
20638
20780
  return;
20639
20781
  }
20640
20782
  try {
20641
- execFileSync("taskkill", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
20783
+ const t = spawn("taskkill", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
20784
+ t.on("error", () => {
20785
+ });
20786
+ t.unref();
20642
20787
  } catch {
20643
20788
  }
20644
20789
  }
@@ -20651,13 +20796,13 @@ function startArgv(argv) {
20651
20796
  return sh === null ? null : [sh, ...argv];
20652
20797
  }
20653
20798
  function runProcess(argv, o) {
20654
- return new Promise((resolve11) => {
20799
+ return new Promise((resolve14) => {
20655
20800
  const isWin2 = process.platform === "win32";
20656
20801
  const start = startArgv(argv);
20657
- if (start === null) return resolve11(NOT_STARTED);
20802
+ if (start === null) return resolve14(NOT_STARTED);
20658
20803
  let child;
20659
20804
  try {
20660
- child = spawn(start[0], start.slice(1), {
20805
+ child = spawn2(start[0], start.slice(1), {
20661
20806
  cwd: o.cwd,
20662
20807
  env: o.env,
20663
20808
  stdio: ["pipe", "pipe", "pipe"],
@@ -20668,14 +20813,20 @@ function runProcess(argv, o) {
20668
20813
  windowsHide: true
20669
20814
  });
20670
20815
  } catch {
20671
- return resolve11(NOT_STARTED);
20816
+ return resolve14(NOT_STARTED);
20672
20817
  }
20673
20818
  const stdoutChunks = [];
20674
20819
  const stderrChunks = [];
20675
20820
  let killedBy = null;
20676
20821
  let settled = false;
20822
+ let held = false;
20823
+ let exited = false;
20824
+ let graceTimer;
20825
+ let drainTimer;
20826
+ let stopTimer;
20677
20827
  const kill = () => {
20678
20828
  if (child.pid !== void 0) killTree(child.pid);
20829
+ if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(), KILL_GRACE_MS);
20679
20830
  };
20680
20831
  const onAbort = () => {
20681
20832
  if (killedBy !== null || settled) return;
@@ -20692,17 +20843,46 @@ function runProcess(argv, o) {
20692
20843
  if (settled) return;
20693
20844
  settled = true;
20694
20845
  clearTimeout(timer);
20846
+ clearTimeout(graceTimer);
20847
+ clearTimeout(drainTimer);
20848
+ clearTimeout(stopTimer);
20695
20849
  o.signal.removeEventListener("abort", onAbort);
20696
- resolve11({
20850
+ resolve14({
20697
20851
  stdout: Buffer.concat(stdoutChunks),
20698
20852
  stderr: Buffer.concat(stderrChunks),
20699
20853
  exitCode,
20700
- killed: killedBy
20854
+ killed: killedBy,
20855
+ ...held ? { held: true } : {}
20701
20856
  });
20702
20857
  };
20703
- child.stdout.on("data", (chunk) => stdoutChunks.push(chunk));
20704
- child.stderr.on("data", (chunk) => stderrChunks.push(chunk));
20858
+ const finishHeld = () => {
20859
+ if (settled) return;
20860
+ held = exited && killedBy === null;
20861
+ child.stdout.destroy();
20862
+ child.stderr.destroy();
20863
+ if (child.pid !== void 0) killTree(child.pid);
20864
+ settle(child.exitCode);
20865
+ };
20866
+ const bump = () => {
20867
+ if (!exited || settled) return;
20868
+ clearTimeout(graceTimer);
20869
+ graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
20870
+ };
20871
+ child.stdout.on("data", (chunk) => {
20872
+ stdoutChunks.push(chunk);
20873
+ bump();
20874
+ });
20875
+ child.stderr.on("data", (chunk) => {
20876
+ stderrChunks.push(chunk);
20877
+ bump();
20878
+ });
20705
20879
  child.on("close", (code) => settle(code));
20880
+ child.on("exit", () => {
20881
+ if (settled) return;
20882
+ exited = true;
20883
+ graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
20884
+ drainTimer = setTimeout(finishHeld, PIPE_DRAIN_MAX_MS);
20885
+ });
20706
20886
  child.on("error", () => settle(null));
20707
20887
  child.stdin.on("error", () => {
20708
20888
  });
@@ -21060,12 +21240,16 @@ function answer(db, input, scope, ctx, nm, ms, indexed, sort, pick2) {
21060
21240
  }
21061
21241
  async function handler(input, ctx) {
21062
21242
  const sort = input.sort ?? "relevance";
21063
- if (sort === "timeline" && input.offset !== void 0) {
21243
+ if (sort === "timeline" && (input.offset ?? 0) !== 0) {
21064
21244
  return invalid("offset", 'drop offset; page a timeline with "after"');
21065
21245
  }
21066
- if (sort === "relevance" && input.after !== void 0) {
21246
+ if (sort === "relevance" && (input.after ?? 0) !== 0) {
21067
21247
  return invalid("after", 'drop after, or pass sort:"timeline"');
21068
21248
  }
21249
+ if (input.source !== void 0 && input.source.trim() === "") {
21250
+ const { source: _blank, ...rest } = input;
21251
+ input = rest;
21252
+ }
21069
21253
  const scope = input.scope ?? "worktree";
21070
21254
  const db = await openDb(ctx.project, { readOnly: true });
21071
21255
  try {
@@ -21319,7 +21503,7 @@ var ctxBatch = Object.freeze({
21319
21503
  });
21320
21504
 
21321
21505
  // src/core/tools/doctor.ts
21322
- import { readdirSync as readdirSync7, readFileSync as readFileSync15, existsSync as existsSync16 } from "node:fs";
21506
+ import { readdirSync as readdirSync7, readFileSync as readFileSync16, existsSync as existsSync16 } from "node:fs";
21323
21507
  import { basename as basename5, join as join19 } from "node:path";
21324
21508
 
21325
21509
  // src/core/ops/bundle-dir.ts
@@ -21345,8 +21529,8 @@ function ownBundleDir() {
21345
21529
  }
21346
21530
 
21347
21531
  // src/core/ops/doctor-config.ts
21348
- import { existsSync as existsSync9, readdirSync as readdirSync5 } from "node:fs";
21349
- import { join as join14 } from "node:path";
21532
+ import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "node:fs";
21533
+ import { dirname as dirname8, isAbsolute as isAbsolute4, join as join14, resolve as resolve9 } from "node:path";
21350
21534
 
21351
21535
  // src/core/ops/detect-v1.ts
21352
21536
  import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "node:fs";
@@ -24009,7 +24193,7 @@ function flatCommands(events, prefix) {
24009
24193
  return out;
24010
24194
  }
24011
24195
  var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
24012
- var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep5) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5));
24196
+ var isCodexScript = (cmd) => V1_PATH_SEPS.some((sep5) => V1_CODEX_SCRIPT_NAMES.some((name) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5 + name)));
24013
24197
  function dataDir(dir, reason, out) {
24014
24198
  if (existsSync6(dir)) out.push(finding(dir, "", reason));
24015
24199
  }
@@ -24057,8 +24241,7 @@ function scanCodex(agentHome, out) {
24057
24241
  const config2 = readTomlValue(tomlFile);
24058
24242
  for (const span2 of readTomlTables(tomlFile)) {
24059
24243
  if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
24060
- if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
24061
- if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
24244
+ if (isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
24062
24245
  out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
24063
24246
  }
24064
24247
  dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
@@ -24221,7 +24404,7 @@ function detectV1(agent, home, scope = {}) {
24221
24404
 
24222
24405
  // src/core/ops/plugin-root.ts
24223
24406
  import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
24224
- import { dirname as dirname7, isAbsolute as isAbsolute2, join as join13, sep as sep4 } from "node:path";
24407
+ import { dirname as dirname7, isAbsolute as isAbsolute3, join as join13, sep as sep4 } from "node:path";
24225
24408
  import { fileURLToPath as fileURLToPath2 } from "node:url";
24226
24409
  function missing(agent, path8) {
24227
24410
  return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
@@ -24333,7 +24516,7 @@ function configEntryRoot(adapter, env) {
24333
24516
  const value = parseHostConfig(adapter.id, file2, current.text, current.format);
24334
24517
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
24335
24518
  const script = Array.isArray(args) ? args[0] : void 0;
24336
- if (typeof script !== "string" || !isAbsolute2(script)) throw missing(adapter.id, file2);
24519
+ if (typeof script !== "string" || !isAbsolute3(script)) throw missing(adapter.id, file2);
24337
24520
  return dirname7(script);
24338
24521
  }
24339
24522
  function candidate(adapter, env, worktree) {
@@ -24553,11 +24736,122 @@ function nativeMcpWrong(dir, row5) {
24553
24736
  return true;
24554
24737
  }
24555
24738
  }
24739
+ function opencodeEntrySpec(entry) {
24740
+ return isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : Array.isArray(entry) ? entry[0] : entry;
24741
+ }
24742
+ function isNativeOpencodeEntry(entry, key) {
24743
+ const spec = opencodeEntrySpec(entry);
24744
+ if (typeof spec !== "string") return false;
24745
+ return spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
24746
+ }
24556
24747
  function isOwnOpencodeEntry(entry, key, own2) {
24557
- const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : entry;
24748
+ const spec = opencodeEntrySpec(entry);
24558
24749
  if (typeof spec !== "string") return false;
24559
- if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own2.includes(spec)) return true;
24560
- return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
24750
+ return spec === OPENCODE_GIT_SPEC || own2.includes(spec) || isNativeOpencodeEntry(entry, key);
24751
+ }
24752
+ function stringLiterals(src) {
24753
+ const out = [];
24754
+ let i = 0;
24755
+ while (i < src.length) {
24756
+ const c = src[i];
24757
+ if (c === "/" && src[i + 1] === "/") {
24758
+ const n = src.indexOf("\n", i);
24759
+ i = n < 0 ? src.length : n;
24760
+ continue;
24761
+ }
24762
+ if (c === "/" && src[i + 1] === "*") {
24763
+ const n = src.indexOf("*/", i + 2);
24764
+ i = n < 0 ? src.length : n + 2;
24765
+ continue;
24766
+ }
24767
+ if (c === '"' || c === "'" || c === "`") {
24768
+ let j = i + 1;
24769
+ let s = "";
24770
+ while (j < src.length && src[j] !== c) {
24771
+ if (src[j] === "\\") {
24772
+ s += src[j + 1] ?? "";
24773
+ j += 2;
24774
+ continue;
24775
+ }
24776
+ s += src[j];
24777
+ j++;
24778
+ }
24779
+ out.push(s);
24780
+ i = j + 1;
24781
+ continue;
24782
+ }
24783
+ i++;
24784
+ }
24785
+ return out;
24786
+ }
24787
+ var OPENCODE_PLUGINS_DIR = "plugins";
24788
+ var OPENCODE_PROJECT_DIR = ".opencode";
24789
+ var OPENCODE_PLUGIN_EXTS = [".js", ".mjs", ".ts"];
24790
+ var OPENCODE_PLUGIN_INDEX = "index";
24791
+ var OPENCODE_DIR_FILE_MAX = 64 * 1024;
24792
+ var OWN_PLUGIN_MODULES = [SERVER_KEY, `${SERVER_KEY}/server`];
24793
+ var FILE_URL_PREFIX = "file://";
24794
+ var NODE_MODULES_DIR = "node_modules";
24795
+ var PACKAGE_JSON_FILE = "package.json";
24796
+ var OPENCODE_PACKAGE_DIR_HINT = `${NODE_MODULES_DIR}/${SERVER_KEY}`;
24797
+ function opencodePluginDirs(configDir, worktree) {
24798
+ return [configDir, opencodeProjectDir(worktree)];
24799
+ }
24800
+ function opencodeProjectDir(worktree) {
24801
+ return join14(worktree, OPENCODE_PROJECT_DIR);
24802
+ }
24803
+ function packageResolves(fromDir) {
24804
+ for (let d = fromDir; ; d = dirname8(d)) {
24805
+ if (existsSync9(join14(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
24806
+ if (dirname8(d) === d) return false;
24807
+ }
24808
+ }
24809
+ function opencodeDirPlugins(dirs) {
24810
+ const bundle = opencodePluginFile();
24811
+ const ownFile = join14(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
24812
+ const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
24813
+ const isPath = (p) => {
24814
+ if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
24815
+ const seg = p.split("/");
24816
+ const n = seg.length;
24817
+ return n >= 3 && seg[n - 1] === "plugin.js" && seg[n - 2] === "opencode" && seg[n - 3] === SERVER_KEY;
24818
+ };
24819
+ const out = [];
24820
+ for (const dir of dirs) {
24821
+ const pdir = join14(dir, OPENCODE_PLUGINS_DIR);
24822
+ let names;
24823
+ try {
24824
+ names = readdirSync5(pdir);
24825
+ } catch {
24826
+ continue;
24827
+ }
24828
+ for (const name of names) {
24829
+ const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join14(pdir, name)] : [];
24830
+ const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join14(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
24831
+ for (const f of files) {
24832
+ let text;
24833
+ try {
24834
+ const b = readFileSync11(f);
24835
+ if (b.length > OPENCODE_DIR_FILE_MAX) continue;
24836
+ text = b.toString("utf8");
24837
+ } catch {
24838
+ continue;
24839
+ }
24840
+ const lits = stringLiterals(text).map((s) => s.split("\\").join("/")).filter((p) => isModule(p) || isPath(p));
24841
+ if (!lits.length) continue;
24842
+ const loads = lits.some((p) => {
24843
+ if (isModule(p)) return packageResolves(dirname8(f));
24844
+ const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
24845
+ return existsSync9(isAbsolute4(bare2) ? bare2 : resolve9(dirname8(f), bare2));
24846
+ });
24847
+ out.push({ file: f, loads });
24848
+ }
24849
+ }
24850
+ }
24851
+ return out;
24852
+ }
24853
+ function opencodeDirPlugin(dirs) {
24854
+ return opencodeDirPlugins(dirs).find((p) => p.loads)?.file;
24561
24855
  }
24562
24856
  function opencodeMcpOwn(entry) {
24563
24857
  if (!isObject4(entry)) return false;
@@ -24565,14 +24859,22 @@ function opencodeMcpOwn(entry) {
24565
24859
  const [node, script, flag, agent] = cmd;
24566
24860
  return isNodeCommand(node) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
24567
24861
  }
24568
- function opencodeListed(file2) {
24569
- const { value } = readParsed("opencode", file2);
24862
+ function opencodeFileValue(file2) {
24863
+ if (!existsSync9(file2)) return {};
24864
+ return parseHostConfig("opencode", file2, hostText(readFileSync11(file2, "utf8")), "jsonc");
24865
+ }
24866
+ function opencodeValueListed(value) {
24570
24867
  const bundle = opencodePluginFile();
24571
24868
  const own2 = [bundle, join14(bundle, ...OPENCODE_PLUGIN_PATH)];
24572
24869
  if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
24573
24870
  const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
24574
24871
  return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
24575
24872
  }
24873
+ function opencodeListed(file2, worktree) {
24874
+ const dirs = [dirname8(file2), worktree];
24875
+ if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join14(dir, name)))))) return true;
24876
+ return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
24877
+ }
24576
24878
  function mcpWrong(row5, home, env, worktree) {
24577
24879
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
24578
24880
  if (native !== null) return nativeMcpWrong(native, row5);
@@ -24582,7 +24884,7 @@ function mcpWrong(row5, home, env, worktree) {
24582
24884
  resolvePluginRoot(row5, env, worktree);
24583
24885
  return false;
24584
24886
  }
24585
- if (row5.id === "opencode") return !opencodeListed(file2);
24887
+ if (row5.id === "opencode") return !opencodeListed(file2, worktree);
24586
24888
  const cur = readHostConfig(row5.id, file2);
24587
24889
  return mergeOwnEntries(row5.id, cur.text, cur.format, row5, { nodePath: true, listEntries: [opencodePluginFile()] }).edits.length > 0;
24588
24890
  } catch {
@@ -24793,8 +25095,8 @@ async function checkIndex(project) {
24793
25095
  }
24794
25096
 
24795
25097
  // src/core/ops/doctor-env.ts
24796
- import { existsSync as existsSync11, readFileSync as readFileSync11, realpathSync as realpathSync6 } from "node:fs";
24797
- import { isAbsolute as isAbsolute3, join as join15, relative as relative4 } from "node:path";
25098
+ import { existsSync as existsSync11, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
25099
+ import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
24798
25100
  function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
24799
25101
  return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
24800
25102
  }
@@ -24804,9 +25106,12 @@ function unknown3(id2, detail, fixCommand) {
24804
25106
  function fail4(id2, detail, fixCommand) {
24805
25107
  return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
24806
25108
  }
25109
+ function warn(id2, detail, fixCommand) {
25110
+ return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail, fixCommand };
25111
+ }
24807
25112
  function bundleVersion(bundleDir2) {
24808
25113
  try {
24809
- const v = JSON.parse(readFileSync11(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
25114
+ const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24810
25115
  return typeof v === "string" && v !== "" ? v : void 0;
24811
25116
  } catch {
24812
25117
  return void 0;
@@ -24890,20 +25195,21 @@ function highestTag(stdout, tag2) {
24890
25195
  }
24891
25196
  return best;
24892
25197
  }
24893
- function versionRow(head2, installed, tag2, source, latest, tail) {
25198
+ function versionRow(head2, installed, tag2, source, latest, tail, update) {
24894
25199
  const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
24895
25200
  if (cmp === 0) return pass3("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
24896
25201
  if (cmp > 0) return pass3("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
24897
- return fail4("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, DOCTOR_FIX_UPGRADE);
25202
+ return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
24898
25203
  }
24899
25204
  async function checkVersion(i) {
24900
25205
  if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
24901
25206
  const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
24902
25207
  if (i.version === void 0) return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
24903
25208
  const tag2 = channelOf(i.version);
25209
+ const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
24904
25210
  const git2 = findRuntime(GIT_BIN, i.env);
24905
25211
  const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
24906
- if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
25212
+ if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
24907
25213
  let cause = D1_GIT_MISSING;
24908
25214
  if (git2 !== null) {
24909
25215
  const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
@@ -24914,7 +25220,7 @@ async function checkVersion(i) {
24914
25220
  });
24915
25221
  if (r.exitCode === 0 && r.killed === null) {
24916
25222
  const latest = highestTag(r.stdout.toString("utf8"), tag2);
24917
- if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
25223
+ if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
24918
25224
  cause = D1_GIT_NO_TAG(tag2);
24919
25225
  } else {
24920
25226
  cause = gitCause(r, i.timeoutMs);
@@ -24950,15 +25256,16 @@ async function checkNode(i) {
24950
25256
  if (!await sqliteLoads()) return fail4("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
24951
25257
  return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
24952
25258
  }
24953
- function checkMcp(ctx) {
25259
+ function checkMcp(ctx, adapter) {
24954
25260
  const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
24955
25261
  const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
24956
- return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
25262
+ if (named2 || versioned) return pass3("D6");
25263
+ return adapter?.installMode === "in-process" ? pass3("D6", D6_IN_PROCESS_DETAIL) : unknown3("D6", D6_UNKNOWN_DETAIL);
24957
25264
  }
24958
25265
  function piCwdInside(worktree, piCwd) {
24959
25266
  if (piCwd === void 0 || !existsSync11(piCwd)) return false;
24960
25267
  const rel = relative4(worktree, realpathSync6.native(piCwd));
24961
- return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
25268
+ return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
24962
25269
  }
24963
25270
  function checkProject(i) {
24964
25271
  const bad = fail4("D7", D7_DETAIL(i.project.source), D7_FIX);
@@ -24979,7 +25286,7 @@ function checkShell(env) {
24979
25286
  }
24980
25287
 
24981
25288
  // src/core/ops/doctor-hook.ts
24982
- import { existsSync as existsSync13, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync12, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
25289
+ import { existsSync as existsSync13, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync13, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24983
25290
  import { tmpdir as tmpdir2 } from "node:os";
24984
25291
  import path7 from "node:path";
24985
25292
 
@@ -26742,7 +27049,7 @@ function hasType(v, t) {
26742
27049
  function same(a, b) {
26743
27050
  return JSON.stringify(a) === JSON.stringify(b);
26744
27051
  }
26745
- function resolve7(root, ref) {
27052
+ function resolve10(root, ref) {
26746
27053
  const parts = ref.split("/");
26747
27054
  if (parts[0] !== "#") throw new Error(`hook-shape: only local $ref is read, got ${ref}`);
26748
27055
  let at2 = root;
@@ -26755,7 +27062,7 @@ function shapeErrors(schema, value, root = schema, at2 = "$") {
26755
27062
  if (!NOTE_KEYS.has(k) && !RULE_KEYS.has(k)) throw new Error(`hook-shape: keyword ${k} at ${at2} is not read by the checker`);
26756
27063
  }
26757
27064
  const errs = [];
26758
- if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve7(root, schema.$ref), value, root, at2));
27065
+ if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve10(root, schema.$ref), value, root, at2));
26759
27066
  if (Array.isArray(schema.allOf)) for (const s of schema.allOf) errs.push(...shapeErrors(s, value, root, at2));
26760
27067
  if (schema.type !== void 0) {
26761
27068
  const types = Array.isArray(schema.type) ? schema.type : [schema.type];
@@ -26807,7 +27114,7 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
26807
27114
  import { createHash } from "node:crypto";
26808
27115
  import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
26809
27116
  import path6 from "node:path";
26810
- import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
27117
+ import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
26811
27118
 
26812
27119
  // src/setup/spawn-bin.ts
26813
27120
  import { spawnSync } from "node:child_process";
@@ -26922,24 +27229,24 @@ function pluginHooksFromReply(m, pluginId) {
26922
27229
  function askPluginHooks(env, pluginId, cwd) {
26923
27230
  const bin = whichBin("codex", env);
26924
27231
  if (!bin) return Promise.resolve({ kind: "absent" });
26925
- return new Promise((resolve11) => {
27232
+ return new Promise((resolve14) => {
26926
27233
  let asked;
26927
27234
  const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
26928
27235
  let f;
26929
27236
  try {
26930
27237
  f = spawnForm(bin, ["app-server"], env);
26931
27238
  } catch {
26932
- resolve11({ kind: "silent" });
27239
+ resolve14({ kind: "silent" });
26933
27240
  return;
26934
27241
  }
26935
- const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
27242
+ const child = spawn3(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
26936
27243
  let buf = "";
26937
27244
  let done = false;
26938
27245
  let exited = false;
26939
27246
  let result;
26940
27247
  const settle = () => {
26941
27248
  clearTimeout(grace);
26942
- resolve11(done_(result));
27249
+ resolve14(done_(result));
26943
27250
  };
26944
27251
  let grace;
26945
27252
  const finish2 = (v) => {
@@ -27031,7 +27338,7 @@ function loadFixture(bundleDir2, agent) {
27031
27338
  if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
27032
27339
  let all;
27033
27340
  try {
27034
- all = JSON.parse(hostText(readFileSync12(file2, "utf8")));
27341
+ all = JSON.parse(hostText(readFileSync13(file2, "utf8")));
27035
27342
  } catch (err) {
27036
27343
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
27037
27344
  }
@@ -27299,10 +27606,10 @@ async function checkHookRoundTrip(i) {
27299
27606
 
27300
27607
  // src/core/ops/db-heal.ts
27301
27608
  import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
27302
- import { basename as basename4, dirname as dirname8, join as join17 } from "node:path";
27609
+ import { basename as basename4, dirname as dirname9, join as join17 } from "node:path";
27303
27610
 
27304
27611
  // src/core/store/owners.ts
27305
- import { mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync13, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
27612
+ import { mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync14, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
27306
27613
  import { basename as basename3, join as join16 } from "node:path";
27307
27614
  function ownersDir(configDir, projectKey) {
27308
27615
  return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
@@ -27336,7 +27643,7 @@ function listLiveOwners(configDir, projectKey) {
27336
27643
  const file2 = join16(dir, name);
27337
27644
  let text;
27338
27645
  try {
27339
- text = readFileSync13(file2, "utf8");
27646
+ text = readFileSync14(file2, "utf8");
27340
27647
  } catch (err) {
27341
27648
  if (errCode2(err) === "ENOENT") continue;
27342
27649
  throw err;
@@ -27420,7 +27727,7 @@ async function healOrphan(project, files, row5) {
27420
27727
  const moved = [];
27421
27728
  let dir = "";
27422
27729
  try {
27423
- dir = makeOrphanDir(dirname8(project.dbPath));
27730
+ dir = makeOrphanDir(dirname9(project.dbPath));
27424
27731
  for (const f of files) {
27425
27732
  const to = join17(dir, basename4(f.path));
27426
27733
  renameWithRetry(f.path, to);
@@ -27487,9 +27794,40 @@ function buildReportHead(input) {
27487
27794
  return lines.concat(tail).join("\n");
27488
27795
  }
27489
27796
 
27797
+ // src/core/ops/unsupported-host.ts
27798
+ var SUPPORTED_AGENTS_LINE = `Supported agents: ${AGENT_IDS.join(", ")} (${SUPPORTED_AGENTS_DOCS_URL}).`;
27799
+ function UNSUPPORTED_HOST_LINE(name) {
27800
+ return `${name} is not a supported host today. The MCP server runs here; hooks are not checked. ${SUPPORTED_AGENTS_LINE}`;
27801
+ }
27802
+ function segmentsOf(dir) {
27803
+ let parts = [dir];
27804
+ for (const sep5 of V1_PATH_SEPS) parts = parts.flatMap((p) => p.split(sep5));
27805
+ return parts;
27806
+ }
27807
+ function hasRun(parts, run) {
27808
+ for (let i = 0; i + run.length <= parts.length; i++) if (run.every((seg, k) => parts[i + k] === seg)) return true;
27809
+ return false;
27810
+ }
27811
+ function unsupportedHostOf(sig) {
27812
+ if (sig.clientName !== void 0 && sig.clientName !== "") {
27813
+ const n = sig.clientName.toLowerCase();
27814
+ const hit = UNSUPPORTED_HOSTS.find((h) => h.clientNames.includes(n));
27815
+ if (hit !== void 0) return hit;
27816
+ }
27817
+ if (sig.bundleDir !== void 0) {
27818
+ const parts = segmentsOf(sig.bundleDir);
27819
+ const hit = UNSUPPORTED_HOSTS.find((h) => h.pluginPaths.some((p) => hasRun(parts, p)));
27820
+ if (hit !== void 0) return hit;
27821
+ }
27822
+ if (sig.clientName !== void 0 && sig.clientName !== "") return void 0;
27823
+ const env = sig.env;
27824
+ if (env === void 0) return void 0;
27825
+ return UNSUPPORTED_HOSTS.find((h) => h.envVars.some((v) => env[v] !== void 0 && env[v] !== ""));
27826
+ }
27827
+
27490
27828
  // src/core/ops/doctor-issue.ts
27491
27829
  import { spawnSync as spawnSync3 } from "node:child_process";
27492
- import { closeSync as closeSync2, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync14, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
27830
+ import { closeSync as closeSync2, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync15, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
27493
27831
  import { delimiter, join as join18 } from "node:path";
27494
27832
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
27495
27833
  function tildeOf(env) {
@@ -27592,7 +27930,7 @@ function agentConfig(adapter, env, worktree) {
27592
27930
  }
27593
27931
  let text = "";
27594
27932
  try {
27595
- text = readFileSync14(f.path, "utf8");
27933
+ text = readFileSync15(f.path, "utf8");
27596
27934
  } catch (err) {
27597
27935
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
27598
27936
  continue;
@@ -27606,12 +27944,13 @@ function agentConfig(adapter, env, worktree) {
27606
27944
  function failing(rows) {
27607
27945
  return rows.filter((r) => r.status === "FAIL");
27608
27946
  }
27609
- function issueTitle(agent, rows) {
27610
- return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
27947
+ function issueTitle(agent, rows, other) {
27948
+ return `ctx_doctor ${agent}${other === void 0 ? "" : ` (${other.name} is not a supported host today)`}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
27611
27949
  }
27612
- function summaryOf(agent, rows) {
27950
+ function summaryOf(agent, rows, other) {
27613
27951
  const f = failing(rows)[0];
27614
- return f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`;
27952
+ const tag2 = other === void 0 ? "" : `${other.name} is not a supported host today. `;
27953
+ return tag2 + (f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`);
27615
27954
  }
27616
27955
  async function buildIssueBody(i) {
27617
27956
  const tilde = tildeOf(i.env);
@@ -27621,7 +27960,7 @@ async function buildIssueBody(i) {
27621
27960
  const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
27622
27961
  const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
27623
27962
  const sections = {
27624
- "Summary": [summaryOf(agent, i.rows)],
27963
+ "Summary": [summaryOf(agent, i.rows, i.unsupported)],
27625
27964
  "ctx-report": [i.table],
27626
27965
  "What happened": [
27627
27966
  "Rows that need a look:",
@@ -27667,9 +28006,9 @@ async function writeIssueReport(i) {
27667
28006
  const file2 = join18(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
27668
28007
  writeFileSync4(file2, body);
27669
28008
  const shown2 = tilde(file2);
27670
- const title = issueTitle(i.adapter.id, i.rows);
28009
+ const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
27671
28010
  const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
27672
- return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows)), DOCTOR_RULES_LINE + ISSUE_GUIDE_URL];
28011
+ return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows, i.unsupported)), DOCTOR_RULES_LINE + ISSUE_GUIDE_URL];
27673
28012
  }
27674
28013
  function formUrl(title, summary) {
27675
28014
  const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
@@ -27698,6 +28037,12 @@ async function codexDb(ctx, adapter) {
27698
28037
  return null;
27699
28038
  }
27700
28039
  }
28040
+ function d1UpdateCommand(agent, env, other) {
28041
+ return other === void 0 ? hostUpdateCommand(agent, env) : UNSUPPORTED_HOST_LINE(other.name);
28042
+ }
28043
+ function unsupportedRow(id2, h) {
28044
+ return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
28045
+ }
27701
28046
  async function hookRow(ctx, adapter, host) {
27702
28047
  const db = await codexDb(ctx, adapter);
27703
28048
  const runStart = Date.now();
@@ -27725,7 +28070,7 @@ function ownServerId(configDir, projectKey) {
27725
28070
  if (!existsSync16(dir)) return "";
27726
28071
  for (const name of readdirSync7(dir)) {
27727
28072
  if (!name.endsWith(OWNER_PID_EXT)) continue;
27728
- if (readFileSync15(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
28073
+ if (readFileSync16(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
27729
28074
  }
27730
28075
  return "";
27731
28076
  }
@@ -27733,16 +28078,18 @@ async function runDoctorChecks(ctx, adapter, host0) {
27733
28078
  const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
27734
28079
  const env = host.env;
27735
28080
  const project = ctx.project;
28081
+ const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
27736
28082
  let integrityFailed = false;
27737
28083
  let orphan = [];
27738
28084
  const checks = {
27739
- D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
28085
+ D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal, updateCommand: d1UpdateCommand(adapter.id, env, other) }),
27740
28086
  D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
27741
- D3: () => checkHostConfig(adapter, env, project.worktree),
28087
+ D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
28088
+ // D-UNSUPPORTED-HOSTS-1
27742
28089
  D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), geminiDir: geminiDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
27743
- D5: () => hookRow(ctx, adapter, host),
28090
+ D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
27744
28091
  D5b: () => checkDoubleFire(adapter.id, project.worktree),
27745
- D6: () => checkMcp(ctx),
28092
+ D6: () => checkMcp(ctx, adapter),
27746
28093
  D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
27747
28094
  D8: async () => {
27748
28095
  const r = await checkDb(project);
@@ -27789,7 +28136,7 @@ async function doctorReply(ctx, host) {
27789
28136
  let notes = [];
27790
28137
  if (failed) {
27791
28138
  try {
27792
- notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
28139
+ notes = await writeIssueReport({ unsupported: adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env: host.env }), ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
27793
28140
  } catch (err) {
27794
28141
  notes = [`Report file: ${lineOf2(err)}`];
27795
28142
  }
@@ -27823,7 +28170,7 @@ var ctxDoctor = Object.freeze({
27823
28170
  // src/core/tools/execute.ts
27824
28171
  import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
27825
28172
  import { tmpdir as tmpdir3 } from "node:os";
27826
- import { dirname as dirname10, join as join20, parse as parse3, resolve as resolve8 } from "node:path";
28173
+ import { dirname as dirname11, join as join20, parse as parse3, resolve as resolve11 } from "node:path";
27827
28174
 
27828
28175
  // src/core/sandbox/win-build.ts
27829
28176
  var SEPARATORS2 = ";&|(\n";
@@ -27906,7 +28253,7 @@ function schemaLine(issue2) {
27906
28253
  }
27907
28254
  function fileError(given, abs, root) {
27908
28255
  let dir = abs;
27909
- while (!existsSync17(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
28256
+ while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
27910
28257
  if (isInside(root, dir)) return null;
27911
28258
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
27912
28259
  }
@@ -27940,7 +28287,7 @@ function spawnFailed(argv0, cwd) {
27940
28287
  }
27941
28288
  async function finish(input, ctx, r, exitCode, journal) {
27942
28289
  const isError = exitCode !== 0 && !(input.language === "shell" && exitCode === SOFT_EXIT && r.stderr.length === 0);
27943
- const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "");
28290
+ const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "") + (r.held === true ? "\n" + BACKGROUND_HOLD_NOTE + "\n" : "");
27944
28291
  const fullBytes = Buffer.byteLength(combined, "utf8");
27945
28292
  const head2 = summaryLine(exitCode, fullBytes);
27946
28293
  const intent = input.intent ?? "";
@@ -27970,7 +28317,7 @@ async function handler3(raw, ctx) {
27970
28317
  const cwd = ctx.project.worktree;
27971
28318
  const extra = { ...PLAIN_OUTPUT_ENV2 };
27972
28319
  if (input.file !== void 0) {
27973
- const abs = resolve8(cwd, input.file);
28320
+ const abs = resolve11(cwd, input.file);
27974
28321
  const bad = fileError(input.file, abs, ctx.project.containmentRoot);
27975
28322
  if (bad !== null) return fail5(bad);
27976
28323
  extra.CTX_FILE = abs;
@@ -28024,11 +28371,11 @@ var ctxExecute = {
28024
28371
  };
28025
28372
 
28026
28373
  // src/core/tools/index.ts
28027
- import { existsSync as existsSync18, readFileSync as readFileSync17, statSync as statSync8 } from "node:fs";
28028
- import { dirname as dirname11, extname as extname3, join as join22, relative as relative5, resolve as resolve9 } from "node:path";
28374
+ import { existsSync as existsSync18, readFileSync as readFileSync18, statSync as statSync8 } from "node:fs";
28375
+ import { dirname as dirname12, extname as extname3, join as join22, relative as relative5, resolve as resolve12 } from "node:path";
28029
28376
 
28030
28377
  // src/core/index/walk.ts
28031
- import { readdirSync as readdirSync8, readFileSync as readFileSync16, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
28378
+ import { readdirSync as readdirSync8, readFileSync as readFileSync17, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
28032
28379
  import { join as join21 } from "node:path";
28033
28380
  var GITIGNORE = ".gitignore";
28034
28381
  var GIT_DIR = ".git";
@@ -28090,7 +28437,7 @@ function compareFound(a, b) {
28090
28437
  function readRules(file2, base) {
28091
28438
  let body;
28092
28439
  try {
28093
- body = readFileSync16(file2, "utf8");
28440
+ body = readFileSync17(file2, "utf8");
28094
28441
  } catch {
28095
28442
  return [];
28096
28443
  }
@@ -28312,18 +28659,18 @@ function request(u, conn, proxy, signal) {
28312
28659
  const host = bare(u.hostname);
28313
28660
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
28314
28661
  const path8 = u.pathname + u.search;
28315
- return new Promise((resolve11, reject) => {
28662
+ return new Promise((resolve14, reject) => {
28316
28663
  const onErr = (err) => reject(fail6(causeCode(err)));
28317
28664
  if (proxy === void 0) {
28318
28665
  const mod = u.protocol === "https:" ? https : http;
28319
28666
  const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
28320
- req.on("response", resolve11).on("error", onErr).end();
28667
+ req.on("response", resolve14).on("error", onErr).end();
28321
28668
  return;
28322
28669
  }
28323
28670
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
28324
28671
  if (u.protocol === "http:") {
28325
28672
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
28326
- req.on("response", resolve11).on("error", onErr).end();
28673
+ req.on("response", resolve14).on("error", onErr).end();
28327
28674
  return;
28328
28675
  }
28329
28676
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -28343,16 +28690,16 @@ function request(u, conn, proxy, signal) {
28343
28690
  headers: { host: u.host },
28344
28691
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
28345
28692
  });
28346
- req.on("response", resolve11).on("error", onErr).end();
28693
+ req.on("response", resolve14).on("error", onErr).end();
28347
28694
  });
28348
28695
  tunnel.end();
28349
28696
  });
28350
28697
  }
28351
28698
  function readBody(res) {
28352
- return new Promise((resolve11, reject) => {
28699
+ return new Promise((resolve14, reject) => {
28353
28700
  const parts = [];
28354
28701
  res.on("data", (b) => parts.push(b));
28355
- res.on("end", () => resolve11(Buffer.concat(parts)));
28702
+ res.on("end", () => resolve14(Buffer.concat(parts)));
28356
28703
  res.on("error", (err) => reject(fail6(causeCode(err))));
28357
28704
  res.on("aborted", () => reject(fail6("ECONNRESET")));
28358
28705
  });
@@ -32218,19 +32565,19 @@ function kindOfType(contentType) {
32218
32565
  }
32219
32566
  function readUtf8(absPath) {
32220
32567
  try {
32221
- return utf8.decode(readFileSync17(absPath));
32568
+ return utf8.decode(readFileSync18(absPath));
32222
32569
  } catch {
32223
32570
  return void 0;
32224
32571
  }
32225
32572
  }
32226
32573
  function missingOrOutside(given, abs, root) {
32227
32574
  let dir = abs;
32228
- while (!existsSync18(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
32575
+ while (!existsSync18(dir) && dirname12(dir) !== dir) dir = dirname12(dir);
32229
32576
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
32230
32577
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
32231
32578
  }
32232
32579
  function pathItems(input, project) {
32233
- const abs = resolve9(project.worktree, input.path);
32580
+ const abs = resolve12(project.worktree, input.path);
32234
32581
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
32235
32582
  const base = relative5(project.worktree, abs);
32236
32583
  if (statSync8(abs).isDirectory()) {
@@ -32402,7 +32749,8 @@ function reply3(text, isError) {
32402
32749
  return { text, isError, sandboxBytes: 0 };
32403
32750
  }
32404
32751
  async function handler6(input, ctx) {
32405
- const sessionId = input.session ?? ctx.sessionId;
32752
+ const given = input.session !== void 0 && input.session.trim() !== "" ? input.session : void 0;
32753
+ const sessionId = given ?? ctx.sessionId;
32406
32754
  if (sessionId === "") return reply3(RESUME_NO_SESSION_LINE, true);
32407
32755
  const db = await openDb(ctx.project, { readOnly: true });
32408
32756
  try {
@@ -32776,7 +33124,7 @@ var ctxStats = Object.freeze({
32776
33124
 
32777
33125
  // src/core/ops/host-write.ts
32778
33126
  import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
32779
- import { dirname as dirname12, join as join23 } from "node:path";
33127
+ import { dirname as dirname13, join as join23 } from "node:path";
32780
33128
  function defaultWrite(file2, text) {
32781
33129
  writeFileSync6(file2, text, "utf8");
32782
33130
  }
@@ -32808,7 +33156,7 @@ function writeWithRollback(file2, text, write2, atomic) {
32808
33156
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
32809
33157
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
32810
33158
  const had = existsSync19(file2);
32811
- mkdirSync8(dirname12(file2), { recursive: true });
33159
+ mkdirSync8(dirname13(file2), { recursive: true });
32812
33160
  if (had) copyFileSync(file2, trash);
32813
33161
  try {
32814
33162
  write2(tmp, text);
@@ -32975,7 +33323,7 @@ function runUninstall(input) {
32975
33323
  }
32976
33324
 
32977
33325
  // src/core/ops/v1-remove.ts
32978
- import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync18, rmSync as rmSync7 } from "node:fs";
33326
+ import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync19, rmSync as rmSync7 } from "node:fs";
32979
33327
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
32980
33328
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
32981
33329
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -33026,8 +33374,8 @@ function locate(doc, path8) {
33026
33374
  return null;
33027
33375
  }
33028
33376
  function stripJsonEntries(agent, file2, findings, kept, undo) {
33029
- const layout = hostLayout(readFileSync18(file2, "utf8"));
33030
- const text = hostText(readFileSync18(file2, "utf8"));
33377
+ const layout = hostLayout(readFileSync19(file2, "utf8"));
33378
+ const text = hostText(readFileSync19(file2, "utf8"));
33031
33379
  const doc = parseHostConfig(agent, file2, text, "jsonc");
33032
33380
  const hit = /* @__PURE__ */ new Set();
33033
33381
  const byContainer = /* @__PURE__ */ new Map();
@@ -33077,7 +33425,7 @@ function removeV1(agent, findings, project) {
33077
33425
  continue;
33078
33426
  }
33079
33427
  if (file2.endsWith(TOML_EXT)) {
33080
- const rawToml = readFileSync18(file2, "utf8");
33428
+ const rawToml = readFileSync19(file2, "utf8");
33081
33429
  const tomlLayout = hostLayout(rawToml);
33082
33430
  let text = hostText(rawToml);
33083
33431
  for (const f of list4) {
@@ -33135,8 +33483,8 @@ function pluginRootRow(adapter, env) {
33135
33483
  }
33136
33484
  return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
33137
33485
  }
33138
- function hostRow(adapter) {
33139
- return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]);
33486
+ function hostRow(adapter, env) {
33487
+ return row4(UPGRADE_HOST_AREA, "", hostUpdateCommand(adapter.id, env));
33140
33488
  }
33141
33489
  function upgrade(adapter, deps, home) {
33142
33490
  let removal = null;
@@ -33144,7 +33492,7 @@ function upgrade(adapter, deps, home) {
33144
33492
  const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
33145
33493
  const findings = detectV1(adapter.id, home, { project: deps.project.worktree, piAgentDir: piAgentDirOf(deps.env, home), claudeDir: claudeDirOf(deps.env, home), geminiDir: geminiDirOf(deps.env, home), copilotDir: copilotDirOf(deps.env, home), kiroDir: kiroDirOf(deps.env, home), opencodeDir: opencodeDirOf(deps.env, home) });
33146
33494
  removal = removeV1(adapter.id, findings, deps.project.worktree);
33147
- const rows = [hostRow(adapter), ...step5, ...removal.rows];
33495
+ const rows = [hostRow(adapter, deps.env), ...step5, ...removal.rows];
33148
33496
  removal.commit();
33149
33497
  return rows;
33150
33498
  } catch (err) {
@@ -33235,7 +33583,7 @@ function checkCall(tool, input) {
33235
33583
  }
33236
33584
 
33237
33585
  // src/entries/opencode.ts
33238
- import { resolve as resolve10 } from "node:path";
33586
+ import { resolve as resolve13 } from "node:path";
33239
33587
  var AGENT = "opencode";
33240
33588
  var slash = (p) => p.replaceAll("\\", "/");
33241
33589
  function shellRequest(commands) {
@@ -33252,7 +33600,7 @@ function permissionRequests(tool, input, base) {
33252
33600
  const str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
33253
33601
  const out = [];
33254
33602
  const read3 = (p) => {
33255
- const abs = slash(resolve10(base, p));
33603
+ const abs = slash(resolve13(base, p));
33256
33604
  return { action: OC_READ_ACTION, resources: [abs], save: [abs] };
33257
33605
  };
33258
33606
  if (tool === "ctx_execute") {
@@ -33363,15 +33711,18 @@ async function setupLegacy(app) {
33363
33711
  tool: input.tool,
33364
33712
  callID: input.callID,
33365
33713
  args: output.args,
33714
+ agentID: input.agentID,
33715
+ agentTools: input.agentTools,
33366
33716
  turn: turnOf(sessionId)
33367
33717
  });
33368
33718
  if (out.exitCode === 2) throw new Error(out.stdout);
33369
33719
  },
33370
- // §4.5. OpenCode's encode has no replace field (impl/10 §11), so output.output is never changed here.
33720
+ // §4.5 step 3, case C: a replace comes back as stdout and is written into output.output in-process. OpenCode 1.19
33721
+ // returns this same object to the model after the trigger; the 2.x bridge copies it into result.content (#1347).
33371
33722
  "tool.execute.after": async (input, output) => {
33372
33723
  const sessionId = input.sessionID ?? "";
33373
33724
  await payloadFor2(sessionId);
33374
- await call({
33725
+ const out = await call({
33375
33726
  type: "execute.after",
33376
33727
  sessionID: sessionId,
33377
33728
  tool: input.tool,
@@ -33379,8 +33730,11 @@ async function setupLegacy(app) {
33379
33730
  args: input.args,
33380
33731
  output: output.output,
33381
33732
  isError: output.isError,
33733
+ agentID: input.agentID,
33734
+ agentTools: input.agentTools,
33382
33735
  turn: turnOf(sessionId)
33383
33736
  });
33737
+ if (out.stdout !== "") output.output = out.stdout;
33384
33738
  },
33385
33739
  // §4.6: one system entry per session, the same bytes on every request (#1085, Q12). A second
33386
33740
  // transform on the same array finds the entry and adds nothing.
@@ -33406,6 +33760,47 @@ function oc2Text(content) {
33406
33760
  if (typeof content === "string") return content;
33407
33761
  return (content ?? []).filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n");
33408
33762
  }
33763
+ function wildcard(pattern, text) {
33764
+ let row5 = new Uint8Array(text.length + 1);
33765
+ row5[0] = 1;
33766
+ for (const c of pattern) {
33767
+ const next = new Uint8Array(text.length + 1);
33768
+ for (let j = 0; j <= text.length; j++) {
33769
+ if (c === "*") next[j] = row5[j] === 1 || j > 0 && next[j - 1] === 1 ? 1 : 0;
33770
+ else if (j > 0 && row5[j - 1] === 1 && (c === "?" || c === text[j - 1])) next[j] = 1;
33771
+ }
33772
+ row5 = next;
33773
+ }
33774
+ return row5[text.length] === 1;
33775
+ }
33776
+ function toolOff(name, rules) {
33777
+ for (let k = rules.length - 1; k >= 0; k--) {
33778
+ const r = rules[k];
33779
+ if (typeof r.action === "string" && wildcard(r.action, name)) return r.resource === "*" && r.effect === "deny";
33780
+ }
33781
+ return false;
33782
+ }
33783
+ function agentResolver(ctx, ownTools) {
33784
+ const cache = /* @__PURE__ */ new Map();
33785
+ const known = [...SHELL_TOOL_NAMES, READ_TOOL_NAME, "webfetch", ...ownTools];
33786
+ const resolveOne = async (agent) => {
33787
+ const raw = await ctx.agent?.get?.({ agentID: agent, location: { directory: ctx.location.directory } });
33788
+ const box = raw !== null && typeof raw === "object" ? raw : {};
33789
+ const info = box.mode !== void 0 ? box : box.data;
33790
+ if (info?.mode !== "subagent") return {};
33791
+ const rules = info.permissions ?? [];
33792
+ return { agentID: agent, agentTools: known.filter((t) => !toolOff(t, rules)) };
33793
+ };
33794
+ return (agent) => {
33795
+ if (agent === void 0 || agent === "" || ctx.agent?.get === void 0) return Promise.resolve({});
33796
+ let p = cache.get(agent);
33797
+ if (p === void 0) {
33798
+ p = resolveOne(agent).catch(() => ({}));
33799
+ cache.set(agent, p);
33800
+ }
33801
+ return p;
33802
+ };
33803
+ }
33409
33804
  async function setup(ctx) {
33410
33805
  const tools = /* @__PURE__ */ new Map();
33411
33806
  const assert2 = ctx.permission?.assert;
@@ -33440,13 +33835,20 @@ async function setup(ctx) {
33440
33835
  await ctx.tool.transform((editor) => {
33441
33836
  for (const t of tools.values()) editor.add(t);
33442
33837
  });
33838
+ const subagentOf = agentResolver(ctx, [...tools.keys()]);
33443
33839
  await ctx.tool.hook("execute.before", async (i) => {
33444
- await hooks["tool.execute.before"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id }, { args: i.input });
33840
+ const sub = await subagentOf(i.agent);
33841
+ await hooks["tool.execute.before"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, ...sub }, { args: i.input });
33445
33842
  });
33446
33843
  await ctx.tool.hook("execute.after", async (i) => {
33447
33844
  const failed = i.status === "error";
33448
- const output = failed ? i.error?.message ?? "" : oc2Text(i.result?.content);
33449
- await hooks["tool.execute.after"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, args: i.input }, { output, isError: failed });
33845
+ const text = failed ? i.error?.message ?? "" : oc2Text(i.result?.content);
33846
+ const out = { output: text, isError: failed };
33847
+ const sub = await subagentOf(i.agent);
33848
+ await hooks["tool.execute.after"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, args: i.input, ...sub }, out);
33849
+ if (!failed && typeof out.output === "string" && out.output !== text) {
33850
+ i.result = { ...i.result, content: [{ type: "text", text: out.output }] };
33851
+ }
33450
33852
  });
33451
33853
  await ctx.session.hook("prompt", async (p) => {
33452
33854
  await hooks["chat.message"]({ sessionID: p.sessionID }, { parts: [{ type: "text", text: p.prompt?.text ?? "" }] });