context-mode 2.1.7 → 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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/plugin.json +1 -1
- package/README.md +72 -72
- package/SHA256SUMS +16 -16
- package/cli.mjs +771 -577
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +89 -89
- package/opencode/plugin.js +442 -229
- package/package.json +1 -1
- package/pi/index.js +298 -123
- package/qwen-extension.json +1 -1
- package/run.mjs +65 -25
- package/search.mjs +65 -25
- package/server.mjs +202 -74
package/opencode/plugin.js
CHANGED
|
@@ -468,7 +468,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
468
468
|
var DECISION_OPTION_KEY = "option";
|
|
469
469
|
var DECISION_LABEL_JOIN = " | ";
|
|
470
470
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
471
|
-
var BUNDLE_SHA = true ? "
|
|
471
|
+
var BUNDLE_SHA = true ? "92c1ad26d57b45e786a3dc9149549c416badca09" : void 0;
|
|
472
472
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
473
473
|
var DOCTOR_LABEL = Object.freeze({
|
|
474
474
|
D1: "version",
|
|
@@ -873,6 +873,14 @@ var V1_SCRIPT_NAMES = Object.freeze([
|
|
|
873
873
|
var V1_HOOK_COMMAND = "context-mode hook";
|
|
874
874
|
var V1_CODEX_HOOK_COMMAND = "context-mode hook codex";
|
|
875
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
|
+
]);
|
|
876
884
|
var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
|
|
877
885
|
var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
|
|
878
886
|
var V1_STATUSLINE_COMMAND = "context-mode statusline";
|
|
@@ -932,7 +940,6 @@ var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
|
|
|
932
940
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
933
941
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
934
942
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
935
|
-
var V1_SCRIPT_EXT = ".mjs";
|
|
936
943
|
var V1_BIN_COMMAND = SERVER_KEY;
|
|
937
944
|
var VSCODE_MCP_SERVERS_KEY = "servers";
|
|
938
945
|
var ZCODE_EVENTS_KEY = "events";
|
|
@@ -948,7 +955,7 @@ var V1_REASON = Object.freeze({
|
|
|
948
955
|
cacheHealFile: "old context-mode cache-heal script file",
|
|
949
956
|
statusLine: "old context-mode statusLine (context-mode statusline): report only, never removed",
|
|
950
957
|
mcpEntry: "old context-mode MCP entry mcpServers.context-mode",
|
|
951
|
-
codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex
|
|
958
|
+
codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/<event>.mjs",
|
|
952
959
|
codexToml: "old context-mode config.toml [mcp_servers.context-mode*] section",
|
|
953
960
|
hookFile: "old context-mode hook file context-mode.json (runs context-mode hook)",
|
|
954
961
|
vscodeMcp: "old context-mode MCP entry servers.context-mode in .vscode/mcp.json: report only, never removed",
|
|
@@ -985,7 +992,6 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
|
|
|
985
992
|
var JSON_INDENT_UNIT = " ";
|
|
986
993
|
var MCP_COMMAND_FIELD = "command";
|
|
987
994
|
var MCP_ARGS_FIELD = "args";
|
|
988
|
-
var MCP_ENV_FIELD = "env";
|
|
989
995
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
990
996
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
991
997
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -1101,6 +1107,70 @@ var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=
|
|
|
1101
1107
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
1102
1108
|
var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
1103
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
|
+
|
|
1104
1174
|
// src/core/contracts/errors.ts
|
|
1105
1175
|
var ERROR_TEXT = Object.freeze({
|
|
1106
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.",
|
|
@@ -1174,14 +1244,14 @@ var CtxError = class extends Error {
|
|
|
1174
1244
|
};
|
|
1175
1245
|
|
|
1176
1246
|
// src/core/hooks/dispatch.ts
|
|
1177
|
-
import { dirname as dirname4, join as join8, relative as relative3, resolve as
|
|
1247
|
+
import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
1178
1248
|
|
|
1179
1249
|
// src/core/contracts/agents.ts
|
|
1180
1250
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
1181
1251
|
|
|
1182
1252
|
// src/adapters/claude-code.ts
|
|
1183
|
-
var
|
|
1184
|
-
var
|
|
1253
|
+
var TOOL_NAME_PREFIX2 = "mcp__plugin_context-mode_context-mode__";
|
|
1254
|
+
var SHELL_TOOL_NAMES2 = Object.freeze(["Bash", "PowerShell"]);
|
|
1185
1255
|
var POWERSHELL_TOOL = "PowerShell";
|
|
1186
1256
|
var SHELL_CANONICAL = "Bash";
|
|
1187
1257
|
var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
|
|
@@ -1266,7 +1336,7 @@ function blocksOf(resp) {
|
|
|
1266
1336
|
}
|
|
1267
1337
|
return { text: parts.join("\n"), keep };
|
|
1268
1338
|
}
|
|
1269
|
-
function
|
|
1339
|
+
function readResult2(resp) {
|
|
1270
1340
|
const text = outputOf(resp);
|
|
1271
1341
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
1272
1342
|
const info = { isError, bytes: Buffer.byteLength(text), text };
|
|
@@ -1306,7 +1376,7 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
|
|
|
1306
1376
|
if (typeof p.tool_use_id === "string" && p.tool_use_id !== "") tool.callId = p.tool_use_id;
|
|
1307
1377
|
ev.tool = tool;
|
|
1308
1378
|
}
|
|
1309
|
-
if (event === "PostToolUse") ev.result =
|
|
1379
|
+
if (event === "PostToolUse") ev.result = readResult2(p.tool_response);
|
|
1310
1380
|
return ev;
|
|
1311
1381
|
}
|
|
1312
1382
|
function replaceShape(ev, output) {
|
|
@@ -1356,9 +1426,9 @@ function requireFields(raw) {
|
|
|
1356
1426
|
if (p[f] === void 0) throw new Error("claude-code: missing required field " + f);
|
|
1357
1427
|
}
|
|
1358
1428
|
}
|
|
1359
|
-
function
|
|
1429
|
+
function decode2(raw) {
|
|
1360
1430
|
requireFields(raw);
|
|
1361
|
-
const ev = decodeClaudeShape(raw, "claude-code",
|
|
1431
|
+
const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX2, CLAUDE_SOURCES);
|
|
1362
1432
|
if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
|
|
1363
1433
|
if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
1364
1434
|
if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
|
|
@@ -1367,29 +1437,29 @@ function decode(raw) {
|
|
|
1367
1437
|
}
|
|
1368
1438
|
return ev;
|
|
1369
1439
|
}
|
|
1370
|
-
function
|
|
1440
|
+
function encode2(ev, d, _extra) {
|
|
1371
1441
|
return encodeClaudeShape(ev, d, true);
|
|
1372
1442
|
}
|
|
1373
1443
|
|
|
1374
1444
|
// src/adapters/codex.ts
|
|
1375
|
-
var
|
|
1445
|
+
var TOOL_NAME_PREFIX3 = "mcp__context_mode__";
|
|
1376
1446
|
var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
|
|
1377
1447
|
var STOP_EVENT = "Stop";
|
|
1378
1448
|
var EMPTY = { stdout: "", exitCode: 0 };
|
|
1379
|
-
function
|
|
1449
|
+
function decode3(raw) {
|
|
1380
1450
|
if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
|
|
1381
1451
|
const p = raw;
|
|
1382
1452
|
return { event: STOP_EVENT, agent: "codex", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
|
|
1383
1453
|
}
|
|
1384
|
-
return decodeClaudeShape(raw, "codex",
|
|
1454
|
+
return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX3, CODEX_SOURCES);
|
|
1385
1455
|
}
|
|
1386
|
-
function
|
|
1456
|
+
function encode3(ev, d, _extra) {
|
|
1387
1457
|
if (ev.event === STOP_EVENT) return EMPTY;
|
|
1388
1458
|
return encodeClaudeShape(ev, d, false);
|
|
1389
1459
|
}
|
|
1390
1460
|
|
|
1391
1461
|
// src/adapters/gemini.ts
|
|
1392
|
-
var
|
|
1462
|
+
var TOOL_NAME_PREFIX4 = "mcp_context-mode_";
|
|
1393
1463
|
var GEMINI_EVENTS = {
|
|
1394
1464
|
SessionStart: "SessionStart",
|
|
1395
1465
|
BeforeAgent: "UserPromptSubmit",
|
|
@@ -1405,15 +1475,15 @@ var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its
|
|
|
1405
1475
|
function own(p, key) {
|
|
1406
1476
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
1407
1477
|
}
|
|
1408
|
-
var
|
|
1478
|
+
var NATIVE_TO_CANONICAL2 = {
|
|
1409
1479
|
run_shell_command: "Bash",
|
|
1410
1480
|
read_file: "Read",
|
|
1411
1481
|
grep_search: "Grep",
|
|
1412
1482
|
web_fetch: "WebFetch"
|
|
1413
1483
|
};
|
|
1414
1484
|
function canonicalName2(name, mcp) {
|
|
1415
|
-
if (name.startsWith(
|
|
1416
|
-
if (Object.hasOwn(
|
|
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];
|
|
1417
1487
|
if (typeof mcp !== "object" || mcp === null) return name;
|
|
1418
1488
|
const m = mcp;
|
|
1419
1489
|
const server2 = own(m, "server_name");
|
|
@@ -1436,7 +1506,7 @@ function partsText(llm) {
|
|
|
1436
1506
|
}
|
|
1437
1507
|
return out.join("");
|
|
1438
1508
|
}
|
|
1439
|
-
function
|
|
1509
|
+
function readResult3(resp) {
|
|
1440
1510
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
1441
1511
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
1442
1512
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
@@ -1488,7 +1558,7 @@ function nativeInput(name, input) {
|
|
|
1488
1558
|
}
|
|
1489
1559
|
return input;
|
|
1490
1560
|
}
|
|
1491
|
-
function
|
|
1561
|
+
function decode4(raw) {
|
|
1492
1562
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
1493
1563
|
const p = raw;
|
|
1494
1564
|
const native = own(p, "hook_event_name");
|
|
@@ -1508,10 +1578,10 @@ function decode3(raw) {
|
|
|
1508
1578
|
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
1509
1579
|
};
|
|
1510
1580
|
}
|
|
1511
|
-
if (event === "PostToolUse") ev.result =
|
|
1581
|
+
if (event === "PostToolUse") ev.result = readResult3(own(p, "tool_response"));
|
|
1512
1582
|
return ev;
|
|
1513
1583
|
}
|
|
1514
|
-
function
|
|
1584
|
+
function encode4(ev, d, _extra) {
|
|
1515
1585
|
switch (d.kind) {
|
|
1516
1586
|
case "allow":
|
|
1517
1587
|
return EMPTY2;
|
|
@@ -1528,9 +1598,9 @@ function encode3(ev, d, _extra) {
|
|
|
1528
1598
|
}
|
|
1529
1599
|
|
|
1530
1600
|
// src/adapters/qwen.ts
|
|
1531
|
-
var
|
|
1601
|
+
var TOOL_NAME_PREFIX5 = "mcp__context-mode__";
|
|
1532
1602
|
var QWEN_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1533
|
-
var
|
|
1603
|
+
var NATIVE_TO_CANONICAL3 = {
|
|
1534
1604
|
run_shell_command: "Bash",
|
|
1535
1605
|
Shell: "Bash",
|
|
1536
1606
|
read_file: "Read",
|
|
@@ -1538,11 +1608,11 @@ var NATIVE_TO_CANONICAL2 = {
|
|
|
1538
1608
|
web_fetch: "WebFetch"
|
|
1539
1609
|
};
|
|
1540
1610
|
var FAILURE_EVENT = "PostToolUseFailure";
|
|
1541
|
-
function
|
|
1611
|
+
function decode5(raw) {
|
|
1542
1612
|
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
|
|
1543
1613
|
const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
1544
|
-
const ev = decodeClaudeShape(payload, "qwen",
|
|
1545
|
-
if (ev.tool !== void 0 && Object.hasOwn(
|
|
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];
|
|
1546
1616
|
if (failure) {
|
|
1547
1617
|
const error40 = raw.error;
|
|
1548
1618
|
const text = typeof error40 === "string" ? error40 : error40 === void 0 ? "" : JSON.stringify(error40);
|
|
@@ -1550,12 +1620,12 @@ function decode4(raw) {
|
|
|
1550
1620
|
}
|
|
1551
1621
|
return ev;
|
|
1552
1622
|
}
|
|
1553
|
-
function
|
|
1623
|
+
function encode5(ev, d, _extra) {
|
|
1554
1624
|
return encodeClaudeShape(ev, d, false);
|
|
1555
1625
|
}
|
|
1556
1626
|
|
|
1557
1627
|
// src/adapters/copilot-cli.ts
|
|
1558
|
-
var
|
|
1628
|
+
var TOOL_NAME_PREFIX6 = "context-mode-";
|
|
1559
1629
|
var NATIVE_EVENTS = {
|
|
1560
1630
|
sessionStart: { event: "SessionStart", casing: "camel", failure: false },
|
|
1561
1631
|
userPromptSubmitted: { event: "UserPromptSubmit", casing: "camel", failure: false },
|
|
@@ -1577,11 +1647,11 @@ var RESULT_SUCCESS = "success";
|
|
|
1577
1647
|
function isRecord(v) {
|
|
1578
1648
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1579
1649
|
}
|
|
1580
|
-
var
|
|
1581
|
-
var
|
|
1650
|
+
var SHELL_TOOL_NAMES3 = Object.freeze(["bash", "powershell"]);
|
|
1651
|
+
var NATIVE_TO_CANONICAL4 = Object.fromEntries(SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]));
|
|
1582
1652
|
function canonicalName3(name) {
|
|
1583
|
-
if (name.startsWith(
|
|
1584
|
-
if (Object.hasOwn(
|
|
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];
|
|
1585
1655
|
return name;
|
|
1586
1656
|
}
|
|
1587
1657
|
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
@@ -1606,7 +1676,7 @@ var RESULT_KEYS = {
|
|
|
1606
1676
|
camel: { type: "resultType", text: "textResultForLlm" },
|
|
1607
1677
|
snake: { type: "result_type", text: "text_result_for_llm" }
|
|
1608
1678
|
};
|
|
1609
|
-
function
|
|
1679
|
+
function readResult4(v, casing, failure) {
|
|
1610
1680
|
const k = RESULT_KEYS[casing];
|
|
1611
1681
|
const r = isRecord(v) ? v : {};
|
|
1612
1682
|
const text = typeof r[k.text] === "string" ? r[k.text] : "";
|
|
@@ -1624,7 +1694,7 @@ function eventName(raw) {
|
|
|
1624
1694
|
if (raw.hook_event_name !== void 0) return raw.hook_event_name;
|
|
1625
1695
|
return EVENT_BY_KEY.find(([key]) => Object.hasOwn(raw, key))?.[1];
|
|
1626
1696
|
}
|
|
1627
|
-
function
|
|
1697
|
+
function decode6(raw) {
|
|
1628
1698
|
if (!isRecord(raw)) throw new Error("copilot-cli: hook payload is not a JSON object");
|
|
1629
1699
|
const name = eventName(raw);
|
|
1630
1700
|
const native = typeof name === "string" ? NATIVE_EVENTS[name] : void 0;
|
|
@@ -1639,11 +1709,11 @@ function decode5(raw) {
|
|
|
1639
1709
|
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
|
|
1640
1710
|
ev.tool = tool;
|
|
1641
1711
|
}
|
|
1642
|
-
if (event === "PostToolUse") ev.result =
|
|
1712
|
+
if (event === "PostToolUse") ev.result = readResult4(raw[k.result], native.casing, native.failure);
|
|
1643
1713
|
return ev;
|
|
1644
1714
|
}
|
|
1645
1715
|
var EMPTY3 = { stdout: "", exitCode: 0 };
|
|
1646
|
-
function
|
|
1716
|
+
function encode6(ev, d, _extra) {
|
|
1647
1717
|
switch (d.kind) {
|
|
1648
1718
|
case "allow":
|
|
1649
1719
|
return EMPTY3;
|
|
@@ -1662,22 +1732,22 @@ function encode5(ev, d, _extra) {
|
|
|
1662
1732
|
}
|
|
1663
1733
|
|
|
1664
1734
|
// src/adapters/vscode.ts
|
|
1665
|
-
var
|
|
1735
|
+
var TOOL_NAME_PREFIX7 = "mcp_context-mode_";
|
|
1666
1736
|
var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PreCompact"];
|
|
1667
1737
|
var MCP_PREFIX2 = "mcp_";
|
|
1668
1738
|
var MCP_SEP2 = "_";
|
|
1669
1739
|
var SESSION_START_NEW = "new";
|
|
1670
|
-
var
|
|
1740
|
+
var SHELL_TOOL_NAMES4 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
|
|
1671
1741
|
var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
|
|
1672
1742
|
var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
|
|
1673
|
-
var
|
|
1674
|
-
...
|
|
1743
|
+
var NATIVE_TO_CANONICAL5 = Object.fromEntries([
|
|
1744
|
+
...SHELL_TOOL_NAMES4.map((n) => [n, "Bash"]),
|
|
1675
1745
|
...READ_TOOL_NAMES.map((n) => [n, "Read"]),
|
|
1676
1746
|
...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
|
|
1677
1747
|
]);
|
|
1678
1748
|
function canonicalName4(name) {
|
|
1679
|
-
if (name.startsWith(
|
|
1680
|
-
if (Object.hasOwn(
|
|
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];
|
|
1681
1751
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
1682
1752
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
1683
1753
|
const sep5 = rest.indexOf(MCP_SEP2);
|
|
@@ -1704,7 +1774,7 @@ function policyInput(name, canonical, input) {
|
|
|
1704
1774
|
}
|
|
1705
1775
|
return input;
|
|
1706
1776
|
}
|
|
1707
|
-
function
|
|
1777
|
+
function readResult5(resp) {
|
|
1708
1778
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
1709
1779
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
1710
1780
|
return { isError, bytes: Buffer.byteLength(text), text };
|
|
@@ -1757,7 +1827,7 @@ function decodeCamel(p, name) {
|
|
|
1757
1827
|
if (event === "PostToolUse") ev.result = readCamelResult(p.toolResult);
|
|
1758
1828
|
return ev;
|
|
1759
1829
|
}
|
|
1760
|
-
function
|
|
1830
|
+
function decode7(raw) {
|
|
1761
1831
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("vscode: hook payload is not a JSON object");
|
|
1762
1832
|
const p = raw;
|
|
1763
1833
|
if (p.hookEventName !== void 0) return decodeCamel(p, p.hookEventName);
|
|
@@ -1777,15 +1847,15 @@ function decode6(raw) {
|
|
|
1777
1847
|
const canonical = canonicalName4(name);
|
|
1778
1848
|
ev.tool = { name, canonicalName: canonical, input: policyInput(name, canonical, input) };
|
|
1779
1849
|
}
|
|
1780
|
-
if (event === "PostToolUse") ev.result =
|
|
1850
|
+
if (event === "PostToolUse") ev.result = readResult5(p.tool_response);
|
|
1781
1851
|
return ev;
|
|
1782
1852
|
}
|
|
1783
|
-
function
|
|
1853
|
+
function encode7(ev, d, _extra) {
|
|
1784
1854
|
return encodeClaudeShape(ev, d, false);
|
|
1785
1855
|
}
|
|
1786
1856
|
|
|
1787
1857
|
// src/adapters/kiro.ts
|
|
1788
|
-
var
|
|
1858
|
+
var TOOL_NAME_PREFIX8 = "mcp_context_mode_";
|
|
1789
1859
|
var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
|
|
1790
1860
|
var KIRO_EVENTS = {
|
|
1791
1861
|
SessionStart: "SessionStart",
|
|
@@ -1801,25 +1871,25 @@ var KIRO_EVENTS = {
|
|
|
1801
1871
|
var PROMPT_FIELD = "prompt";
|
|
1802
1872
|
var PROMPT_ENV = "USER_PROMPT";
|
|
1803
1873
|
var MCP_PREFIX3 = "mcp_";
|
|
1804
|
-
var
|
|
1805
|
-
var
|
|
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"]));
|
|
1806
1876
|
var MCP_SEP3 = "_";
|
|
1807
1877
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1808
1878
|
function canonicalName5(name) {
|
|
1809
|
-
if (name.startsWith(
|
|
1879
|
+
if (name.startsWith(TOOL_NAME_PREFIX8)) return name.slice(TOOL_NAME_PREFIX8.length);
|
|
1810
1880
|
if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
|
|
1811
|
-
if (Object.hasOwn(
|
|
1881
|
+
if (Object.hasOwn(NATIVE_TO_CANONICAL6, name)) return NATIVE_TO_CANONICAL6[name];
|
|
1812
1882
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1813
1883
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
1814
1884
|
const sep5 = rest.indexOf(MCP_SEP3);
|
|
1815
1885
|
if (sep5 <= 0 || sep5 === rest.length - 1) return name;
|
|
1816
1886
|
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP3.length);
|
|
1817
1887
|
}
|
|
1818
|
-
function
|
|
1888
|
+
function readResult6(resp) {
|
|
1819
1889
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
1820
1890
|
return { isError: false, bytes: Buffer.byteLength(text), text };
|
|
1821
1891
|
}
|
|
1822
|
-
function
|
|
1892
|
+
function decode8(raw) {
|
|
1823
1893
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("kiro: hook payload is not a JSON object");
|
|
1824
1894
|
const p = raw;
|
|
1825
1895
|
const native = typeof p.hook_event_name === "string" ? p.hook_event_name : "";
|
|
@@ -1837,10 +1907,10 @@ function decode7(raw) {
|
|
|
1837
1907
|
const input = typeof p.tool_input === "object" && p.tool_input !== null && !Array.isArray(p.tool_input) ? p.tool_input : {};
|
|
1838
1908
|
ev.tool = { name, canonicalName: canonicalName5(name), input };
|
|
1839
1909
|
}
|
|
1840
|
-
if (event === "PostToolUse") ev.result =
|
|
1910
|
+
if (event === "PostToolUse") ev.result = readResult6(p.tool_response);
|
|
1841
1911
|
return ev;
|
|
1842
1912
|
}
|
|
1843
|
-
function
|
|
1913
|
+
function encode8(ev, d, _extra) {
|
|
1844
1914
|
if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
|
|
1845
1915
|
switch (d.kind) {
|
|
1846
1916
|
case "allow":
|
|
@@ -1855,19 +1925,19 @@ function encode7(ev, d, _extra) {
|
|
|
1855
1925
|
}
|
|
1856
1926
|
|
|
1857
1927
|
// src/adapters/zcode.ts
|
|
1858
|
-
var
|
|
1928
|
+
var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
1859
1929
|
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1860
1930
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1861
1931
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1862
1932
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
1863
|
-
function
|
|
1933
|
+
function decode9(raw) {
|
|
1864
1934
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
|
|
1865
1935
|
const p = { ...raw };
|
|
1866
1936
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
1867
1937
|
const failure = p.hook_event_name === FAILURE_EVENT2;
|
|
1868
1938
|
if (failure) p.hook_event_name = "PostToolUse";
|
|
1869
1939
|
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
1870
|
-
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX :
|
|
1940
|
+
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
|
|
1871
1941
|
const ev = decodeClaudeShape(p, "zcode", prefix, ZCODE_SOURCES);
|
|
1872
1942
|
if (failure) {
|
|
1873
1943
|
const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
|
|
@@ -1875,12 +1945,12 @@ function decode8(raw) {
|
|
|
1875
1945
|
}
|
|
1876
1946
|
return ev;
|
|
1877
1947
|
}
|
|
1878
|
-
function
|
|
1948
|
+
function encode9(ev, d, _extra) {
|
|
1879
1949
|
return encodeClaudeShape(ev, d, false);
|
|
1880
1950
|
}
|
|
1881
1951
|
|
|
1882
1952
|
// src/adapters/pi.ts
|
|
1883
|
-
var
|
|
1953
|
+
var TOOL_NAME_PREFIX10 = "";
|
|
1884
1954
|
var PI_EVENTS = {
|
|
1885
1955
|
session_start: { event: "SessionStart", source: "startup" },
|
|
1886
1956
|
session_compact: { event: "SessionStart", source: "compact" },
|
|
@@ -1888,17 +1958,18 @@ var PI_EVENTS = {
|
|
|
1888
1958
|
tool_call: { event: "PreToolUse" },
|
|
1889
1959
|
tool_result: { event: "PostToolUse" }
|
|
1890
1960
|
};
|
|
1891
|
-
var
|
|
1892
|
-
function
|
|
1961
|
+
var NATIVE_TO_CANONICAL7 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
1962
|
+
function record2(v) {
|
|
1893
1963
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1894
1964
|
}
|
|
1895
|
-
function
|
|
1965
|
+
function readResult7(p) {
|
|
1896
1966
|
const text = p.content === void 0 ? "" : typeof p.content === "string" ? p.content : JSON.stringify(p.content);
|
|
1897
1967
|
const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
|
|
1898
1968
|
if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
|
|
1969
|
+
if (p.keep === true) info.keep = true;
|
|
1899
1970
|
return info;
|
|
1900
1971
|
}
|
|
1901
|
-
function
|
|
1972
|
+
function decode10(raw) {
|
|
1902
1973
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("pi: hook payload is not an object");
|
|
1903
1974
|
const p = raw;
|
|
1904
1975
|
const native = typeof p.type === "string" ? p.type : "";
|
|
@@ -1909,10 +1980,10 @@ function decode9(raw) {
|
|
|
1909
1980
|
if (row5.event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
|
|
1910
1981
|
if (row5.event === "PreToolUse" || row5.event === "PostToolUse") {
|
|
1911
1982
|
const name = String(p.toolName ?? "");
|
|
1912
|
-
ev.tool = { name, canonicalName: Object.hasOwn(
|
|
1983
|
+
ev.tool = { name, canonicalName: Object.hasOwn(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name, input: record2(p.input) };
|
|
1913
1984
|
if (typeof p.toolCallId === "string") ev.tool.callId = p.toolCallId;
|
|
1914
1985
|
}
|
|
1915
|
-
if (row5.event === "PostToolUse") ev.result =
|
|
1986
|
+
if (row5.event === "PostToolUse") ev.result = readResult7(p);
|
|
1916
1987
|
if (typeof p.turn === "number") ev.turn = p.turn;
|
|
1917
1988
|
return ev;
|
|
1918
1989
|
}
|
|
@@ -1928,7 +1999,7 @@ function stdoutFor(ev, d) {
|
|
|
1928
1999
|
}
|
|
1929
2000
|
return { stdout: "", exitCode: 0 };
|
|
1930
2001
|
}
|
|
1931
|
-
function
|
|
2002
|
+
function encode10(ev, d, _extra) {
|
|
1932
2003
|
const out = stdoutFor(ev, d);
|
|
1933
2004
|
if (d?.kind === "allow") return out;
|
|
1934
2005
|
return { stdout: out.stdout, exitCode: out.exitCode, role: PI_ROLE, content: out.stdout, timestamp: Date.now() };
|
|
@@ -1937,75 +2008,16 @@ function checkPermission(out) {
|
|
|
1937
2008
|
return out.exitCode === 2 ? { block: true, reason: out.stdout } : void 0;
|
|
1938
2009
|
}
|
|
1939
2010
|
|
|
1940
|
-
// src/adapters/opencode.ts
|
|
1941
|
-
var TOOL_NAME_PREFIX10 = "";
|
|
1942
|
-
var OWN_WIRE_PREFIX = SERVER_KEY + "_";
|
|
1943
|
-
var OPENCODE_EVENTS = {
|
|
1944
|
-
context: "SessionStart",
|
|
1945
|
-
prompt: "UserPromptSubmit",
|
|
1946
|
-
"execute.before": "PreToolUse",
|
|
1947
|
-
"execute.after": "PostToolUse",
|
|
1948
|
-
compaction: "PreCompact",
|
|
1949
|
-
"step-finish": "Usage"
|
|
1950
|
-
};
|
|
1951
|
-
var SHELL_TOOL_NAME = "bash";
|
|
1952
|
-
var READ_TOOL_NAME = "read";
|
|
1953
|
-
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1954
|
-
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
1955
|
-
function toCanonicalTool(name) {
|
|
1956
|
-
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1957
|
-
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
1958
|
-
}
|
|
1959
|
-
function record2(v) {
|
|
1960
|
-
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1961
|
-
}
|
|
1962
|
-
function readResult7(p) {
|
|
1963
|
-
const text = p.output === void 0 ? "" : typeof p.output === "string" ? p.output : JSON.stringify(p.output);
|
|
1964
|
-
const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
|
|
1965
|
-
if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
|
|
1966
|
-
return info;
|
|
1967
|
-
}
|
|
1968
|
-
function decode10(raw) {
|
|
1969
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("opencode: hook payload is not an object");
|
|
1970
|
-
const p = raw;
|
|
1971
|
-
const native = typeof p.type === "string" ? p.type : "";
|
|
1972
|
-
const event = Object.prototype.hasOwnProperty.call(OPENCODE_EVENTS, native) ? OPENCODE_EVENTS[native] : void 0;
|
|
1973
|
-
if (event === void 0) throw new Error("opencode: unknown hook event " + String(p.type));
|
|
1974
|
-
const ev = { event, agent: "opencode", sessionId: String(p.sessionID ?? ""), cwd: String(p.directory ?? "") };
|
|
1975
|
-
if (event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
|
|
1976
|
-
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
1977
|
-
const name = String(p.tool ?? "");
|
|
1978
|
-
ev.tool = { name, canonicalName: toCanonicalTool(name), input: record2(p.args) };
|
|
1979
|
-
if (typeof p.callID === "string") ev.tool.callId = p.callID;
|
|
1980
|
-
}
|
|
1981
|
-
if (event === "PostToolUse") ev.result = readResult7(p);
|
|
1982
|
-
if (typeof p.turn === "number") ev.turn = p.turn;
|
|
1983
|
-
return ev;
|
|
1984
|
-
}
|
|
1985
|
-
function encode10(ev, d, _extra) {
|
|
1986
|
-
switch (d.kind) {
|
|
1987
|
-
case "allow":
|
|
1988
|
-
return { stdout: "", exitCode: 0 };
|
|
1989
|
-
case "hint":
|
|
1990
|
-
return { stdout: ev.event === "SessionStart" ? d.text : "", exitCode: 0 };
|
|
1991
|
-
case "deny":
|
|
1992
|
-
if (ev.event !== "PreToolUse") return { stdout: "", exitCode: 0 };
|
|
1993
|
-
return { stdout: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason, exitCode: 2 };
|
|
1994
|
-
case "replace":
|
|
1995
|
-
return { stdout: "", exitCode: 0 };
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
|
|
1999
2011
|
// src/adapters/table.ts
|
|
2000
2012
|
var CLAUDE_EVENTS = { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" };
|
|
2001
2013
|
var CLAUDE_TOOLS = { shell: ["Bash"], read: ["Read"], grep: ["Grep"], webfetch: ["WebFetch"], edit: ["Write", "Edit", "NotebookEdit"] };
|
|
2002
|
-
var CLAUDE_CODE_TOOLS = { ...CLAUDE_TOOLS, shell: [...
|
|
2014
|
+
var CLAUDE_CODE_TOOLS = { ...CLAUDE_TOOLS, shell: [...SHELL_TOOL_NAMES2] };
|
|
2003
2015
|
var ADAPTERS = Object.freeze([
|
|
2004
2016
|
{
|
|
2005
2017
|
id: "claude-code",
|
|
2006
2018
|
installMode: "marketplace",
|
|
2007
2019
|
projectSource: "env:CLAUDE_PROJECT_DIR",
|
|
2008
|
-
toolNamePrefix:
|
|
2020
|
+
toolNamePrefix: TOOL_NAME_PREFIX2,
|
|
2009
2021
|
nativeTools: CLAUDE_CODE_TOOLS,
|
|
2010
2022
|
execReadOnlyHint: false,
|
|
2011
2023
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2016,14 +2028,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2016
2028
|
hookChannel: { kind: "package", path: "hooks/claude-code.json" },
|
|
2017
2029
|
skillChannel: { kind: "package", path: "skills" },
|
|
2018
2030
|
// ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
|
|
2019
|
-
decode,
|
|
2020
|
-
encode
|
|
2031
|
+
decode: decode2,
|
|
2032
|
+
encode: encode2
|
|
2021
2033
|
},
|
|
2022
2034
|
{
|
|
2023
2035
|
id: "codex",
|
|
2024
2036
|
installMode: "config-mcp",
|
|
2025
2037
|
projectSource: "arg:--agent+cwd",
|
|
2026
|
-
toolNamePrefix:
|
|
2038
|
+
toolNamePrefix: TOOL_NAME_PREFIX3,
|
|
2027
2039
|
nativeTools: { shell: ["Bash"], edit: ["apply_patch"] },
|
|
2028
2040
|
execReadOnlyHint: true,
|
|
2029
2041
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2034,14 +2046,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2034
2046
|
hookChannel: { kind: "home-file", path: ".codex/hooks.json" },
|
|
2035
2047
|
skillChannel: { kind: "home-dir", path: ".codex/skills" },
|
|
2036
2048
|
// ADR-0020
|
|
2037
|
-
decode:
|
|
2038
|
-
encode:
|
|
2049
|
+
decode: decode3,
|
|
2050
|
+
encode: encode3
|
|
2039
2051
|
},
|
|
2040
2052
|
{
|
|
2041
2053
|
id: "gemini",
|
|
2042
2054
|
installMode: "extension",
|
|
2043
2055
|
projectSource: "spawn-cwd",
|
|
2044
|
-
toolNamePrefix:
|
|
2056
|
+
toolNamePrefix: TOOL_NAME_PREFIX4,
|
|
2045
2057
|
// D-HA-GEMINI-NAMES-1: gemini-cli 0.65.0 *_TOOL_NAME constants.
|
|
2046
2058
|
nativeTools: { shell: ["run_shell_command"], read: ["read_file"], grep: ["grep_search"], webfetch: ["web_fetch"] },
|
|
2047
2059
|
execReadOnlyHint: false,
|
|
@@ -2056,14 +2068,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2056
2068
|
hookChannel: { kind: "package", path: "hooks/hooks.json" },
|
|
2057
2069
|
skillChannel: { kind: "package", path: "skills" },
|
|
2058
2070
|
// ADR-0020
|
|
2059
|
-
decode:
|
|
2060
|
-
encode:
|
|
2071
|
+
decode: decode4,
|
|
2072
|
+
encode: encode4
|
|
2061
2073
|
},
|
|
2062
2074
|
{
|
|
2063
2075
|
id: "qwen",
|
|
2064
2076
|
installMode: "extension",
|
|
2065
2077
|
projectSource: "spawn-cwd",
|
|
2066
|
-
toolNamePrefix:
|
|
2078
|
+
toolNamePrefix: TOOL_NAME_PREFIX5,
|
|
2067
2079
|
nativeTools: { shell: ["run_shell_command", "Shell"], read: ["read_file"], grep: ["grep_search"], webfetch: ["web_fetch"] },
|
|
2068
2080
|
execReadOnlyHint: false,
|
|
2069
2081
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2074,15 +2086,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2074
2086
|
hookChannel: { kind: "package", path: "hooks/qwen.json" },
|
|
2075
2087
|
skillChannel: { kind: "package", path: "skills" },
|
|
2076
2088
|
// ADR-0020, D-HQ-SKILLS-3: qwen loads <extension>/skills, shared with gemini
|
|
2077
|
-
decode:
|
|
2078
|
-
encode:
|
|
2089
|
+
decode: decode5,
|
|
2090
|
+
encode: encode5
|
|
2079
2091
|
},
|
|
2080
2092
|
{
|
|
2081
2093
|
id: "copilot-cli",
|
|
2082
2094
|
installMode: "plugin",
|
|
2083
2095
|
projectSource: "arg:--agent+cwd",
|
|
2084
|
-
toolNamePrefix:
|
|
2085
|
-
nativeTools: { shell: [...
|
|
2096
|
+
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
2097
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
|
|
2086
2098
|
execReadOnlyHint: false,
|
|
2087
2099
|
// D-PWSH-DUMP-1
|
|
2088
2100
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
@@ -2093,16 +2105,16 @@ var ADAPTERS = Object.freeze([
|
|
|
2093
2105
|
hookChannel: { kind: "home-file", path: ".copilot/hooks/context-mode.json" },
|
|
2094
2106
|
skillChannel: { kind: "home-dir", path: ".copilot/skills" },
|
|
2095
2107
|
// ADR-0020
|
|
2096
|
-
decode:
|
|
2097
|
-
encode:
|
|
2108
|
+
decode: decode6,
|
|
2109
|
+
encode: encode6
|
|
2098
2110
|
},
|
|
2099
2111
|
{
|
|
2100
2112
|
id: "vscode",
|
|
2101
2113
|
installMode: "mcp-entry",
|
|
2102
2114
|
projectSource: "arg:workspaceFolder",
|
|
2103
|
-
toolNamePrefix:
|
|
2115
|
+
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
2104
2116
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
2105
|
-
nativeTools: { shell: [...
|
|
2117
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES4], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
2106
2118
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
2107
2119
|
execReadOnlyHint: false,
|
|
2108
2120
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -2113,15 +2125,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2113
2125
|
hookChannel: { kind: "home-file", path: ".copilot/hooks/context-mode-vscode.json" },
|
|
2114
2126
|
skillChannel: { kind: "home-dir", path: ".agents/skills" },
|
|
2115
2127
|
// ADR-0020, D-HQ-COPILOT-NAMES-3: Copilot CLI owns ~/.copilot/skills
|
|
2116
|
-
decode:
|
|
2117
|
-
encode:
|
|
2128
|
+
decode: decode7,
|
|
2129
|
+
encode: encode7
|
|
2118
2130
|
},
|
|
2119
2131
|
{
|
|
2120
2132
|
id: "kiro",
|
|
2121
2133
|
installMode: "mcp-entry",
|
|
2122
2134
|
projectSource: "arg:--agent+cwd",
|
|
2123
|
-
toolNamePrefix:
|
|
2124
|
-
nativeTools: { shell: [...
|
|
2135
|
+
toolNamePrefix: TOOL_NAME_PREFIX8,
|
|
2136
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES5] },
|
|
2125
2137
|
execReadOnlyHint: false,
|
|
2126
2138
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
2127
2139
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -2132,15 +2144,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2132
2144
|
hookChannel: { kind: "home-file", path: ".kiro/hooks/context-mode.json" },
|
|
2133
2145
|
skillChannel: { kind: "home-dir", path: ".kiro/skills" },
|
|
2134
2146
|
// ADR-0020
|
|
2135
|
-
decode:
|
|
2136
|
-
encode:
|
|
2147
|
+
decode: decode8,
|
|
2148
|
+
encode: encode8
|
|
2137
2149
|
},
|
|
2138
2150
|
{
|
|
2139
2151
|
// toolNamePrefix is the documented ZCode name mcp__<server>__<tool> (D-N7-ZCODE-NAMES-1); nativeTools are Claude names.
|
|
2140
2152
|
id: "zcode",
|
|
2141
2153
|
installMode: "hooks+mcp",
|
|
2142
2154
|
projectSource: "spawn-cwd",
|
|
2143
|
-
toolNamePrefix:
|
|
2155
|
+
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
2144
2156
|
nativeTools: CLAUDE_TOOLS,
|
|
2145
2157
|
execReadOnlyHint: false,
|
|
2146
2158
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2151,14 +2163,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2151
2163
|
hookChannel: { kind: "home-file", path: ".zcode/cli/config.json" },
|
|
2152
2164
|
skillChannel: { kind: "home-dir", path: ".zcode/skills" },
|
|
2153
2165
|
// ADR-0020
|
|
2154
|
-
decode:
|
|
2155
|
-
encode:
|
|
2166
|
+
decode: decode9,
|
|
2167
|
+
encode: encode9
|
|
2156
2168
|
},
|
|
2157
2169
|
{
|
|
2158
2170
|
id: "pi",
|
|
2159
2171
|
installMode: "in-process",
|
|
2160
2172
|
projectSource: "pi:ctx.cwd",
|
|
2161
|
-
toolNamePrefix:
|
|
2173
|
+
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
2162
2174
|
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
2163
2175
|
execReadOnlyHint: false,
|
|
2164
2176
|
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
@@ -2170,15 +2182,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2170
2182
|
hookChannel: { kind: "in-process", path: "pi/index.js" },
|
|
2171
2183
|
skillChannel: { kind: "package", path: "pi/skills" },
|
|
2172
2184
|
// ADR-0020
|
|
2173
|
-
decode:
|
|
2174
|
-
encode:
|
|
2185
|
+
decode: decode10,
|
|
2186
|
+
encode: encode10,
|
|
2175
2187
|
checkPermission
|
|
2176
2188
|
},
|
|
2177
2189
|
{
|
|
2178
2190
|
id: "opencode",
|
|
2179
2191
|
installMode: "in-process",
|
|
2180
2192
|
projectSource: "spawn-cwd",
|
|
2181
|
-
toolNamePrefix:
|
|
2193
|
+
toolNamePrefix: TOOL_NAME_PREFIX,
|
|
2182
2194
|
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
2183
2195
|
execReadOnlyHint: false,
|
|
2184
2196
|
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
@@ -2191,13 +2203,13 @@ var ADAPTERS = Object.freeze([
|
|
|
2191
2203
|
hookChannel: { kind: "in-process", path: "opencode/plugin.js" },
|
|
2192
2204
|
skillChannel: { kind: "home-dir", path: ".config/opencode/skills" },
|
|
2193
2205
|
// ADR-0020
|
|
2194
|
-
decode
|
|
2195
|
-
encode
|
|
2206
|
+
decode,
|
|
2207
|
+
encode,
|
|
2196
2208
|
toCanonicalTool
|
|
2197
2209
|
}
|
|
2198
2210
|
]);
|
|
2199
2211
|
var BY_ID = new Map(ADAPTERS.map((r) => [r.id, r]));
|
|
2200
|
-
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"]);
|
|
2201
2213
|
function hasReplace(row5) {
|
|
2202
2214
|
return REPLACE_ROWS.has(row5.id);
|
|
2203
2215
|
}
|
|
@@ -2214,7 +2226,7 @@ function getAdapter(id2) {
|
|
|
2214
2226
|
}
|
|
2215
2227
|
|
|
2216
2228
|
// src/core/policy/decide.ts
|
|
2217
|
-
import { resolve as
|
|
2229
|
+
import { resolve as resolve5 } from "node:path";
|
|
2218
2230
|
|
|
2219
2231
|
// src/core/policy/lexer.ts
|
|
2220
2232
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -4163,10 +4175,10 @@ function READ_DENY_RANGE_MESSAGE(path8, size) {
|
|
|
4163
4175
|
}
|
|
4164
4176
|
|
|
4165
4177
|
// src/core/policy/own-file.ts
|
|
4166
|
-
import { extname, join as join5 } from "node:path";
|
|
4178
|
+
import { extname, join as join5, resolve as resolve4 } from "node:path";
|
|
4167
4179
|
|
|
4168
4180
|
// src/core/project/contain.ts
|
|
4169
|
-
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";
|
|
4170
4182
|
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4171
4183
|
function real(p) {
|
|
4172
4184
|
try {
|
|
@@ -4210,6 +4222,29 @@ function isInsideAny(roots, p) {
|
|
|
4210
4222
|
return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
|
|
4211
4223
|
});
|
|
4212
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
|
+
}
|
|
4213
4248
|
function commonRoot(paths) {
|
|
4214
4249
|
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
4215
4250
|
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
@@ -4250,9 +4285,11 @@ function ownDirsOf(agent, env) {
|
|
|
4250
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])];
|
|
4251
4286
|
return [...own2, shared];
|
|
4252
4287
|
}
|
|
4253
|
-
function isOwnFile(agent,
|
|
4254
|
-
if (extname(
|
|
4255
|
-
|
|
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);
|
|
4256
4293
|
}
|
|
4257
4294
|
|
|
4258
4295
|
// src/core/policy/read-media.ts
|
|
@@ -4343,7 +4380,7 @@ function readPaths(input) {
|
|
|
4343
4380
|
}
|
|
4344
4381
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
4345
4382
|
if (rules.length === 0) return null;
|
|
4346
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
4383
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve5(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
4347
4384
|
if (canonical === BASH) {
|
|
4348
4385
|
const cmd = str(input.command);
|
|
4349
4386
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -4480,8 +4517,9 @@ function fileSize(abs) {
|
|
|
4480
4517
|
return -1;
|
|
4481
4518
|
}
|
|
4482
4519
|
}
|
|
4483
|
-
function bigDeny(ev, row5,
|
|
4484
|
-
|
|
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;
|
|
4485
4523
|
return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
|
|
4486
4524
|
}
|
|
4487
4525
|
function executeCanOpen(root, abs) {
|
|
@@ -4496,10 +4534,10 @@ function executeCanOpen(root, abs) {
|
|
|
4496
4534
|
function read(ev, row5, input, root) {
|
|
4497
4535
|
if (!present(input.offset) && !present(input.limit)) {
|
|
4498
4536
|
for (const p of readPaths(input)) {
|
|
4499
|
-
const abs =
|
|
4537
|
+
const abs = resolve5(ev.cwd, p);
|
|
4500
4538
|
const size = fileSize(abs);
|
|
4501
4539
|
if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
|
|
4502
|
-
const d = bigDeny(ev, row5,
|
|
4540
|
+
const d = bigDeny(ev, row5, ev.cwd, p, size, root);
|
|
4503
4541
|
if (d !== null) return d;
|
|
4504
4542
|
}
|
|
4505
4543
|
}
|
|
@@ -4512,7 +4550,7 @@ function shellDump(ev, cmds, row5, root) {
|
|
|
4512
4550
|
let verdict = null;
|
|
4513
4551
|
for (const c of cmds) {
|
|
4514
4552
|
const name = c.argv0.toLowerCase();
|
|
4515
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
4553
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve5(dir, c.args[0]);
|
|
4516
4554
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
4517
4555
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
4518
4556
|
const d = dumpTarget(name, c.args);
|
|
@@ -4521,8 +4559,8 @@ function shellDump(ev, cmds, row5, root) {
|
|
|
4521
4559
|
verdict = ALLOW;
|
|
4522
4560
|
continue;
|
|
4523
4561
|
}
|
|
4524
|
-
const abs =
|
|
4525
|
-
const big = bigDeny(ev, row5,
|
|
4562
|
+
const abs = resolve5(dir, d.file);
|
|
4563
|
+
const big = bigDeny(ev, row5, dir, d.file, fileSize(abs), root);
|
|
4526
4564
|
if (big !== null) return big;
|
|
4527
4565
|
}
|
|
4528
4566
|
return verdict;
|
|
@@ -4530,7 +4568,7 @@ function shellDump(ev, cmds, row5, root) {
|
|
|
4530
4568
|
function psShellDump(ev, cmd, row5, root) {
|
|
4531
4569
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
4532
4570
|
for (const abs of psDumpFiles(cmd, ev.cwd)) {
|
|
4533
|
-
const d = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
4571
|
+
const d = bigDeny(ev, row5, ev.cwd, abs, fileSize(abs), root);
|
|
4534
4572
|
if (d !== null) return d;
|
|
4535
4573
|
}
|
|
4536
4574
|
return null;
|
|
@@ -4592,7 +4630,7 @@ function dumpTarget(name, args) {
|
|
|
4592
4630
|
}
|
|
4593
4631
|
|
|
4594
4632
|
// src/core/project/resolve.ts
|
|
4595
|
-
import { basename as basename2, dirname as dirname3, join as join6, resolve as
|
|
4633
|
+
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
|
|
4596
4634
|
|
|
4597
4635
|
// src/core/project/sha256.ts
|
|
4598
4636
|
var K = new Uint32Array([
|
|
@@ -4757,7 +4795,7 @@ function gitDirs(dir) {
|
|
|
4757
4795
|
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
4758
4796
|
if (gitDir !== null) {
|
|
4759
4797
|
const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
|
|
4760
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
4798
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve6(gitDir, common)), worktree: cur, start };
|
|
4761
4799
|
}
|
|
4762
4800
|
const up = dirname3(cur);
|
|
4763
4801
|
if (up === cur) return { commonDir: null, start };
|
|
@@ -4772,7 +4810,7 @@ function gitDirAt(dotGit) {
|
|
|
4772
4810
|
} else {
|
|
4773
4811
|
const line = firstLine(dotGit);
|
|
4774
4812
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
4775
|
-
gitDir =
|
|
4813
|
+
gitDir = resolve6(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
4776
4814
|
}
|
|
4777
4815
|
} catch {
|
|
4778
4816
|
return null;
|
|
@@ -8835,7 +8873,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
8835
8873
|
}
|
|
8836
8874
|
|
|
8837
8875
|
// src/core/hooks/fallback.ts
|
|
8838
|
-
import { join as join7, resolve as
|
|
8876
|
+
import { join as join7, resolve as resolve7 } from "node:path";
|
|
8839
8877
|
var fs = process.getBuiltinModule("node:fs");
|
|
8840
8878
|
function isRec(v) {
|
|
8841
8879
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8958,7 +8996,7 @@ function bigFile(abs) {
|
|
|
8958
8996
|
function bigRead(agent, input, cwd) {
|
|
8959
8997
|
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
8960
8998
|
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
|
|
8961
|
-
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(
|
|
8999
|
+
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve7(cwd, p)) && !isMediaRead(agent, resolve7(cwd, p)) && !isOwnFile(agent, cwd, p));
|
|
8962
9000
|
}
|
|
8963
9001
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
8964
9002
|
const row5 = getAdapter(agent);
|
|
@@ -9217,12 +9255,17 @@ function askDetached(ev, project, tool, text) {
|
|
|
9217
9255
|
process.stderr.write("hooks: decision write failed: " + message(err) + "\n");
|
|
9218
9256
|
});
|
|
9219
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
|
+
}
|
|
9220
9263
|
async function preToolUse(ev, row5, project, env) {
|
|
9221
9264
|
const userDeny = readUserDeny(project.worktree, ev.agent);
|
|
9222
9265
|
const decision0 = decide(ev, row5, userDeny, project);
|
|
9223
9266
|
let decision = decision0;
|
|
9224
9267
|
if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
|
|
9225
|
-
const set3 = toolSetForAgentType(ev,
|
|
9268
|
+
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
9226
9269
|
const subCase = pickSubagentCase(ev, set3);
|
|
9227
9270
|
const tool = ev.tool;
|
|
9228
9271
|
const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
|
|
@@ -9325,7 +9368,7 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9325
9368
|
function ownRead(ev, tool, env) {
|
|
9326
9369
|
if (!RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
9327
9370
|
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9328
|
-
return p !== void 0 && isOwnFile(ev.agent,
|
|
9371
|
+
return p !== void 0 && isOwnFile(ev.agent, ev.cwd, p, env);
|
|
9329
9372
|
}
|
|
9330
9373
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9331
9374
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
@@ -9335,7 +9378,7 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9335
9378
|
if (!hasReplace(row5)) return ALLOW2;
|
|
9336
9379
|
let label2;
|
|
9337
9380
|
if (isSubagentCall(ev)) {
|
|
9338
|
-
const subCase = pickSubagentCase(ev, toolSetForAgentType(ev,
|
|
9381
|
+
const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, toolSetSources(ev, project, env)));
|
|
9339
9382
|
if (subCase === "A") return ALLOW2;
|
|
9340
9383
|
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + String(ev.turn ?? 0);
|
|
9341
9384
|
} else {
|
|
@@ -9374,7 +9417,7 @@ function replaceBudget(handleLine, more) {
|
|
|
9374
9417
|
function hostToolResult(file2, sessionId, env) {
|
|
9375
9418
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
9376
9419
|
const projects = join8(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
9377
|
-
const steps = relative3(projects,
|
|
9420
|
+
const steps = relative3(projects, resolve8(file2)).split(sep3);
|
|
9378
9421
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
9379
9422
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
9380
9423
|
const st = lstatSync2(file2);
|
|
@@ -20753,10 +20796,10 @@ function startArgv(argv) {
|
|
|
20753
20796
|
return sh === null ? null : [sh, ...argv];
|
|
20754
20797
|
}
|
|
20755
20798
|
function runProcess(argv, o) {
|
|
20756
|
-
return new Promise((
|
|
20799
|
+
return new Promise((resolve14) => {
|
|
20757
20800
|
const isWin2 = process.platform === "win32";
|
|
20758
20801
|
const start = startArgv(argv);
|
|
20759
|
-
if (start === null) return
|
|
20802
|
+
if (start === null) return resolve14(NOT_STARTED);
|
|
20760
20803
|
let child;
|
|
20761
20804
|
try {
|
|
20762
20805
|
child = spawn2(start[0], start.slice(1), {
|
|
@@ -20770,7 +20813,7 @@ function runProcess(argv, o) {
|
|
|
20770
20813
|
windowsHide: true
|
|
20771
20814
|
});
|
|
20772
20815
|
} catch {
|
|
20773
|
-
return
|
|
20816
|
+
return resolve14(NOT_STARTED);
|
|
20774
20817
|
}
|
|
20775
20818
|
const stdoutChunks = [];
|
|
20776
20819
|
const stderrChunks = [];
|
|
@@ -20804,7 +20847,7 @@ function runProcess(argv, o) {
|
|
|
20804
20847
|
clearTimeout(drainTimer);
|
|
20805
20848
|
clearTimeout(stopTimer);
|
|
20806
20849
|
o.signal.removeEventListener("abort", onAbort);
|
|
20807
|
-
|
|
20850
|
+
resolve14({
|
|
20808
20851
|
stdout: Buffer.concat(stdoutChunks),
|
|
20809
20852
|
stderr: Buffer.concat(stderrChunks),
|
|
20810
20853
|
exitCode,
|
|
@@ -21197,12 +21240,16 @@ function answer(db, input, scope, ctx, nm, ms, indexed, sort, pick2) {
|
|
|
21197
21240
|
}
|
|
21198
21241
|
async function handler(input, ctx) {
|
|
21199
21242
|
const sort = input.sort ?? "relevance";
|
|
21200
|
-
if (sort === "timeline" && input.offset !==
|
|
21243
|
+
if (sort === "timeline" && (input.offset ?? 0) !== 0) {
|
|
21201
21244
|
return invalid("offset", 'drop offset; page a timeline with "after"');
|
|
21202
21245
|
}
|
|
21203
|
-
if (sort === "relevance" && input.after !==
|
|
21246
|
+
if (sort === "relevance" && (input.after ?? 0) !== 0) {
|
|
21204
21247
|
return invalid("after", 'drop after, or pass sort:"timeline"');
|
|
21205
21248
|
}
|
|
21249
|
+
if (input.source !== void 0 && input.source.trim() === "") {
|
|
21250
|
+
const { source: _blank, ...rest } = input;
|
|
21251
|
+
input = rest;
|
|
21252
|
+
}
|
|
21206
21253
|
const scope = input.scope ?? "worktree";
|
|
21207
21254
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
21208
21255
|
try {
|
|
@@ -21483,7 +21530,7 @@ function ownBundleDir() {
|
|
|
21483
21530
|
|
|
21484
21531
|
// src/core/ops/doctor-config.ts
|
|
21485
21532
|
import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "node:fs";
|
|
21486
|
-
import { dirname as dirname8, join as join14 } from "node:path";
|
|
21533
|
+
import { dirname as dirname8, isAbsolute as isAbsolute4, join as join14, resolve as resolve9 } from "node:path";
|
|
21487
21534
|
|
|
21488
21535
|
// src/core/ops/detect-v1.ts
|
|
21489
21536
|
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "node:fs";
|
|
@@ -24146,7 +24193,7 @@ function flatCommands(events, prefix) {
|
|
|
24146
24193
|
return out;
|
|
24147
24194
|
}
|
|
24148
24195
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
24149
|
-
var isCodexScript = (cmd) =>
|
|
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)));
|
|
24150
24197
|
function dataDir(dir, reason, out) {
|
|
24151
24198
|
if (existsSync6(dir)) out.push(finding(dir, "", reason));
|
|
24152
24199
|
}
|
|
@@ -24194,8 +24241,7 @@ function scanCodex(agentHome, out) {
|
|
|
24194
24241
|
const config2 = readTomlValue(tomlFile);
|
|
24195
24242
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
24196
24243
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
24197
|
-
if (
|
|
24198
|
-
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;
|
|
24199
24245
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
24200
24246
|
}
|
|
24201
24247
|
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
@@ -24358,7 +24404,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24358
24404
|
|
|
24359
24405
|
// src/core/ops/plugin-root.ts
|
|
24360
24406
|
import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
|
|
24361
|
-
import { dirname as dirname7, isAbsolute as
|
|
24407
|
+
import { dirname as dirname7, isAbsolute as isAbsolute3, join as join13, sep as sep4 } from "node:path";
|
|
24362
24408
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24363
24409
|
function missing(agent, path8) {
|
|
24364
24410
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24470,7 +24516,7 @@ function configEntryRoot(adapter, env) {
|
|
|
24470
24516
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24471
24517
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
24472
24518
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
24473
|
-
if (typeof script !== "string" || !
|
|
24519
|
+
if (typeof script !== "string" || !isAbsolute3(script)) throw missing(adapter.id, file2);
|
|
24474
24520
|
return dirname7(script);
|
|
24475
24521
|
}
|
|
24476
24522
|
function candidate(adapter, env, worktree) {
|
|
@@ -24690,11 +24736,122 @@ function nativeMcpWrong(dir, row5) {
|
|
|
24690
24736
|
return true;
|
|
24691
24737
|
}
|
|
24692
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
|
+
}
|
|
24693
24747
|
function isOwnOpencodeEntry(entry, key, own2) {
|
|
24694
|
-
const spec =
|
|
24748
|
+
const spec = opencodeEntrySpec(entry);
|
|
24695
24749
|
if (typeof spec !== "string") return false;
|
|
24696
|
-
|
|
24697
|
-
|
|
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;
|
|
24698
24855
|
}
|
|
24699
24856
|
function opencodeMcpOwn(entry) {
|
|
24700
24857
|
if (!isObject4(entry)) return false;
|
|
@@ -24715,7 +24872,8 @@ function opencodeValueListed(value) {
|
|
|
24715
24872
|
}
|
|
24716
24873
|
function opencodeListed(file2, worktree) {
|
|
24717
24874
|
const dirs = [dirname8(file2), worktree];
|
|
24718
|
-
|
|
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;
|
|
24719
24877
|
}
|
|
24720
24878
|
function mcpWrong(row5, home, env, worktree) {
|
|
24721
24879
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
@@ -24938,7 +25096,7 @@ async function checkIndex(project) {
|
|
|
24938
25096
|
|
|
24939
25097
|
// src/core/ops/doctor-env.ts
|
|
24940
25098
|
import { existsSync as existsSync11, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
24941
|
-
import { isAbsolute as
|
|
25099
|
+
import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
|
|
24942
25100
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24943
25101
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24944
25102
|
}
|
|
@@ -25107,7 +25265,7 @@ function checkMcp(ctx, adapter) {
|
|
|
25107
25265
|
function piCwdInside(worktree, piCwd) {
|
|
25108
25266
|
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
25109
25267
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
25110
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
25268
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
25111
25269
|
}
|
|
25112
25270
|
function checkProject(i) {
|
|
25113
25271
|
const bad = fail4("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
@@ -26891,7 +27049,7 @@ function hasType(v, t) {
|
|
|
26891
27049
|
function same(a, b) {
|
|
26892
27050
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
26893
27051
|
}
|
|
26894
|
-
function
|
|
27052
|
+
function resolve10(root, ref) {
|
|
26895
27053
|
const parts = ref.split("/");
|
|
26896
27054
|
if (parts[0] !== "#") throw new Error(`hook-shape: only local $ref is read, got ${ref}`);
|
|
26897
27055
|
let at2 = root;
|
|
@@ -26904,7 +27062,7 @@ function shapeErrors(schema, value, root = schema, at2 = "$") {
|
|
|
26904
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`);
|
|
26905
27063
|
}
|
|
26906
27064
|
const errs = [];
|
|
26907
|
-
if (typeof schema.$ref === "string") errs.push(...shapeErrors(
|
|
27065
|
+
if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve10(root, schema.$ref), value, root, at2));
|
|
26908
27066
|
if (Array.isArray(schema.allOf)) for (const s of schema.allOf) errs.push(...shapeErrors(s, value, root, at2));
|
|
26909
27067
|
if (schema.type !== void 0) {
|
|
26910
27068
|
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
@@ -27071,14 +27229,14 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
27071
27229
|
function askPluginHooks(env, pluginId, cwd) {
|
|
27072
27230
|
const bin = whichBin("codex", env);
|
|
27073
27231
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
27074
|
-
return new Promise((
|
|
27232
|
+
return new Promise((resolve14) => {
|
|
27075
27233
|
let asked;
|
|
27076
27234
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
27077
27235
|
let f;
|
|
27078
27236
|
try {
|
|
27079
27237
|
f = spawnForm(bin, ["app-server"], env);
|
|
27080
27238
|
} catch {
|
|
27081
|
-
|
|
27239
|
+
resolve14({ kind: "silent" });
|
|
27082
27240
|
return;
|
|
27083
27241
|
}
|
|
27084
27242
|
const child = spawn3(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -27088,7 +27246,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
27088
27246
|
let result;
|
|
27089
27247
|
const settle = () => {
|
|
27090
27248
|
clearTimeout(grace);
|
|
27091
|
-
|
|
27249
|
+
resolve14(done_(result));
|
|
27092
27250
|
};
|
|
27093
27251
|
let grace;
|
|
27094
27252
|
const finish2 = (v) => {
|
|
@@ -28012,7 +28170,7 @@ var ctxDoctor = Object.freeze({
|
|
|
28012
28170
|
// src/core/tools/execute.ts
|
|
28013
28171
|
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28014
28172
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28015
|
-
import { dirname as dirname11, join as join20, parse as parse3, resolve as
|
|
28173
|
+
import { dirname as dirname11, join as join20, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28016
28174
|
|
|
28017
28175
|
// src/core/sandbox/win-build.ts
|
|
28018
28176
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28159,7 +28317,7 @@ async function handler3(raw, ctx) {
|
|
|
28159
28317
|
const cwd = ctx.project.worktree;
|
|
28160
28318
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
28161
28319
|
if (input.file !== void 0) {
|
|
28162
|
-
const abs =
|
|
28320
|
+
const abs = resolve11(cwd, input.file);
|
|
28163
28321
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
28164
28322
|
if (bad !== null) return fail5(bad);
|
|
28165
28323
|
extra.CTX_FILE = abs;
|
|
@@ -28214,7 +28372,7 @@ var ctxExecute = {
|
|
|
28214
28372
|
|
|
28215
28373
|
// src/core/tools/index.ts
|
|
28216
28374
|
import { existsSync as existsSync18, readFileSync as readFileSync18, statSync as statSync8 } from "node:fs";
|
|
28217
|
-
import { dirname as dirname12, extname as extname3, join as join22, relative as relative5, resolve as
|
|
28375
|
+
import { dirname as dirname12, extname as extname3, join as join22, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28218
28376
|
|
|
28219
28377
|
// src/core/index/walk.ts
|
|
28220
28378
|
import { readdirSync as readdirSync8, readFileSync as readFileSync17, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
@@ -28501,18 +28659,18 @@ function request(u, conn, proxy, signal) {
|
|
|
28501
28659
|
const host = bare(u.hostname);
|
|
28502
28660
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
28503
28661
|
const path8 = u.pathname + u.search;
|
|
28504
|
-
return new Promise((
|
|
28662
|
+
return new Promise((resolve14, reject) => {
|
|
28505
28663
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
28506
28664
|
if (proxy === void 0) {
|
|
28507
28665
|
const mod = u.protocol === "https:" ? https : http;
|
|
28508
28666
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
28509
|
-
req.on("response",
|
|
28667
|
+
req.on("response", resolve14).on("error", onErr).end();
|
|
28510
28668
|
return;
|
|
28511
28669
|
}
|
|
28512
28670
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
28513
28671
|
if (u.protocol === "http:") {
|
|
28514
28672
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
28515
|
-
req.on("response",
|
|
28673
|
+
req.on("response", resolve14).on("error", onErr).end();
|
|
28516
28674
|
return;
|
|
28517
28675
|
}
|
|
28518
28676
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -28532,16 +28690,16 @@ function request(u, conn, proxy, signal) {
|
|
|
28532
28690
|
headers: { host: u.host },
|
|
28533
28691
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
28534
28692
|
});
|
|
28535
|
-
req.on("response",
|
|
28693
|
+
req.on("response", resolve14).on("error", onErr).end();
|
|
28536
28694
|
});
|
|
28537
28695
|
tunnel.end();
|
|
28538
28696
|
});
|
|
28539
28697
|
}
|
|
28540
28698
|
function readBody(res) {
|
|
28541
|
-
return new Promise((
|
|
28699
|
+
return new Promise((resolve14, reject) => {
|
|
28542
28700
|
const parts = [];
|
|
28543
28701
|
res.on("data", (b) => parts.push(b));
|
|
28544
|
-
res.on("end", () =>
|
|
28702
|
+
res.on("end", () => resolve14(Buffer.concat(parts)));
|
|
28545
28703
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
28546
28704
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
28547
28705
|
});
|
|
@@ -32419,7 +32577,7 @@ function missingOrOutside(given, abs, root) {
|
|
|
32419
32577
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
32420
32578
|
}
|
|
32421
32579
|
function pathItems(input, project) {
|
|
32422
|
-
const abs =
|
|
32580
|
+
const abs = resolve12(project.worktree, input.path);
|
|
32423
32581
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
32424
32582
|
const base = relative5(project.worktree, abs);
|
|
32425
32583
|
if (statSync8(abs).isDirectory()) {
|
|
@@ -32591,7 +32749,8 @@ function reply3(text, isError) {
|
|
|
32591
32749
|
return { text, isError, sandboxBytes: 0 };
|
|
32592
32750
|
}
|
|
32593
32751
|
async function handler6(input, ctx) {
|
|
32594
|
-
const
|
|
32752
|
+
const given = input.session !== void 0 && input.session.trim() !== "" ? input.session : void 0;
|
|
32753
|
+
const sessionId = given ?? ctx.sessionId;
|
|
32595
32754
|
if (sessionId === "") return reply3(RESUME_NO_SESSION_LINE, true);
|
|
32596
32755
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
32597
32756
|
try {
|
|
@@ -33424,7 +33583,7 @@ function checkCall(tool, input) {
|
|
|
33424
33583
|
}
|
|
33425
33584
|
|
|
33426
33585
|
// src/entries/opencode.ts
|
|
33427
|
-
import { resolve as
|
|
33586
|
+
import { resolve as resolve13 } from "node:path";
|
|
33428
33587
|
var AGENT = "opencode";
|
|
33429
33588
|
var slash = (p) => p.replaceAll("\\", "/");
|
|
33430
33589
|
function shellRequest(commands) {
|
|
@@ -33441,7 +33600,7 @@ function permissionRequests(tool, input, base) {
|
|
|
33441
33600
|
const str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
33442
33601
|
const out = [];
|
|
33443
33602
|
const read3 = (p) => {
|
|
33444
|
-
const abs = slash(
|
|
33603
|
+
const abs = slash(resolve13(base, p));
|
|
33445
33604
|
return { action: OC_READ_ACTION, resources: [abs], save: [abs] };
|
|
33446
33605
|
};
|
|
33447
33606
|
if (tool === "ctx_execute") {
|
|
@@ -33552,15 +33711,18 @@ async function setupLegacy(app) {
|
|
|
33552
33711
|
tool: input.tool,
|
|
33553
33712
|
callID: input.callID,
|
|
33554
33713
|
args: output.args,
|
|
33714
|
+
agentID: input.agentID,
|
|
33715
|
+
agentTools: input.agentTools,
|
|
33555
33716
|
turn: turnOf(sessionId)
|
|
33556
33717
|
});
|
|
33557
33718
|
if (out.exitCode === 2) throw new Error(out.stdout);
|
|
33558
33719
|
},
|
|
33559
|
-
// §4.5
|
|
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).
|
|
33560
33722
|
"tool.execute.after": async (input, output) => {
|
|
33561
33723
|
const sessionId = input.sessionID ?? "";
|
|
33562
33724
|
await payloadFor2(sessionId);
|
|
33563
|
-
await call({
|
|
33725
|
+
const out = await call({
|
|
33564
33726
|
type: "execute.after",
|
|
33565
33727
|
sessionID: sessionId,
|
|
33566
33728
|
tool: input.tool,
|
|
@@ -33568,8 +33730,11 @@ async function setupLegacy(app) {
|
|
|
33568
33730
|
args: input.args,
|
|
33569
33731
|
output: output.output,
|
|
33570
33732
|
isError: output.isError,
|
|
33733
|
+
agentID: input.agentID,
|
|
33734
|
+
agentTools: input.agentTools,
|
|
33571
33735
|
turn: turnOf(sessionId)
|
|
33572
33736
|
});
|
|
33737
|
+
if (out.stdout !== "") output.output = out.stdout;
|
|
33573
33738
|
},
|
|
33574
33739
|
// §4.6: one system entry per session, the same bytes on every request (#1085, Q12). A second
|
|
33575
33740
|
// transform on the same array finds the entry and adds nothing.
|
|
@@ -33595,6 +33760,47 @@ function oc2Text(content) {
|
|
|
33595
33760
|
if (typeof content === "string") return content;
|
|
33596
33761
|
return (content ?? []).filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n");
|
|
33597
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
|
+
}
|
|
33598
33804
|
async function setup(ctx) {
|
|
33599
33805
|
const tools = /* @__PURE__ */ new Map();
|
|
33600
33806
|
const assert2 = ctx.permission?.assert;
|
|
@@ -33629,13 +33835,20 @@ async function setup(ctx) {
|
|
|
33629
33835
|
await ctx.tool.transform((editor) => {
|
|
33630
33836
|
for (const t of tools.values()) editor.add(t);
|
|
33631
33837
|
});
|
|
33838
|
+
const subagentOf = agentResolver(ctx, [...tools.keys()]);
|
|
33632
33839
|
await ctx.tool.hook("execute.before", async (i) => {
|
|
33633
|
-
|
|
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 });
|
|
33634
33842
|
});
|
|
33635
33843
|
await ctx.tool.hook("execute.after", async (i) => {
|
|
33636
33844
|
const failed = i.status === "error";
|
|
33637
|
-
const
|
|
33638
|
-
|
|
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
|
+
}
|
|
33639
33852
|
});
|
|
33640
33853
|
await ctx.session.hook("prompt", async (p) => {
|
|
33641
33854
|
await hooks["chat.message"]({ sessionID: p.sessionID }, { parts: [{ type: "text", text: p.prompt?.text ?? "" }] });
|