context-mode 2.1.7 → 2.1.9
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 +787 -588
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +99 -99
- package/opencode/plugin.js +562 -271
- package/package.json +1 -1
- package/pi/index.js +416 -165
- package/qwen-extension.json +1 -1
- package/run.mjs +108 -33
- package/search.mjs +108 -33
- package/server.mjs +216 -81
package/opencode/plugin.js
CHANGED
|
@@ -40,6 +40,15 @@ function REPLACE_HANDLE_LINE(intent, handle, bytes5, prefix = "", asked = "") {
|
|
|
40
40
|
const queries = asked === "" ? [intent] : [intent, asked];
|
|
41
41
|
return prefix + "ctx_search({queries:[" + queries.map((q) => JSON.stringify(q)).join(",") + "], source:" + JSON.stringify(handle) + "}) searches the whole output (" + bytes5 + " B).";
|
|
42
42
|
}
|
|
43
|
+
function SUBAGENT_HANDLE_LINE(handle, bytes5, read3) {
|
|
44
|
+
return "The full output (" + bytes5 + " B) is stored as " + handle + "; above is the best-matching part." + (read3 ? " Read the file with offset and limit for other lines." : "");
|
|
45
|
+
}
|
|
46
|
+
function SEARCH_TWIN_LINE(searchPath, handle, terms, projectDir) {
|
|
47
|
+
return " Or run: node " + shellWord(searchPath) + " " + handle + " " + shellWord(terms) + " " + shellWord(projectDir);
|
|
48
|
+
}
|
|
49
|
+
function shellWord(s) {
|
|
50
|
+
return "'" + s.split("'").join("'\\''") + "'";
|
|
51
|
+
}
|
|
43
52
|
var HANDLE_PROMPT_WORDS = 3;
|
|
44
53
|
var MAX_CHUNK_BYTES = 4096;
|
|
45
54
|
var SEARCH_PAGE_SIZE = 20;
|
|
@@ -224,6 +233,8 @@ var CANCELLED_LINE = "Cancelled.";
|
|
|
224
233
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
225
234
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
226
235
|
var RUN_LABEL_PREFIX = "run.mjs:";
|
|
236
|
+
var SEARCH_WRAPPER_FILE = "search.mjs";
|
|
237
|
+
var RUN_WRAPPER_AGENT = "claude-code";
|
|
227
238
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
228
239
|
var NODE_MIN = "24.15.0";
|
|
229
240
|
var DATA_ROOT = "~/.context-mode";
|
|
@@ -233,6 +244,7 @@ var REQUIRE_SECURITY_ENV = "CONTEXT_MODE_REQUIRE_SECURITY";
|
|
|
233
244
|
var HOST_CONFIG_DIR_NAME = ".claude";
|
|
234
245
|
var AGENTS_DIR_NAME = "agents";
|
|
235
246
|
var AGENT_FILE_EXT = ".md";
|
|
247
|
+
var SYNCED_PLUGINS_DIR_NAME = "synced";
|
|
236
248
|
var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
237
249
|
var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
|
|
238
250
|
var PLUGIN_AGENT_SEPARATOR = ":";
|
|
@@ -468,7 +480,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
468
480
|
var DECISION_OPTION_KEY = "option";
|
|
469
481
|
var DECISION_LABEL_JOIN = " | ";
|
|
470
482
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
471
|
-
var BUNDLE_SHA = true ? "
|
|
483
|
+
var BUNDLE_SHA = true ? "9c0c8a6d580cf4a310ff2d3138ad3c24f6a1dcde" : void 0;
|
|
472
484
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
473
485
|
var DOCTOR_LABEL = Object.freeze({
|
|
474
486
|
D1: "version",
|
|
@@ -873,6 +885,14 @@ var V1_SCRIPT_NAMES = Object.freeze([
|
|
|
873
885
|
var V1_HOOK_COMMAND = "context-mode hook";
|
|
874
886
|
var V1_CODEX_HOOK_COMMAND = "context-mode hook codex";
|
|
875
887
|
var V1_CODEX_HOOKS_DIR = Object.freeze(["hooks", "codex"]);
|
|
888
|
+
var V1_CODEX_SCRIPT_NAMES = Object.freeze([
|
|
889
|
+
"pretooluse.mjs",
|
|
890
|
+
"posttooluse.mjs",
|
|
891
|
+
"sessionstart.mjs",
|
|
892
|
+
"precompact.mjs",
|
|
893
|
+
"userpromptsubmit.mjs",
|
|
894
|
+
"stop.mjs"
|
|
895
|
+
]);
|
|
876
896
|
var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
|
|
877
897
|
var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
|
|
878
898
|
var V1_STATUSLINE_COMMAND = "context-mode statusline";
|
|
@@ -932,7 +952,6 @@ var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
|
|
|
932
952
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
933
953
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
934
954
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
935
|
-
var V1_SCRIPT_EXT = ".mjs";
|
|
936
955
|
var V1_BIN_COMMAND = SERVER_KEY;
|
|
937
956
|
var VSCODE_MCP_SERVERS_KEY = "servers";
|
|
938
957
|
var ZCODE_EVENTS_KEY = "events";
|
|
@@ -948,7 +967,7 @@ var V1_REASON = Object.freeze({
|
|
|
948
967
|
cacheHealFile: "old context-mode cache-heal script file",
|
|
949
968
|
statusLine: "old context-mode statusLine (context-mode statusline): report only, never removed",
|
|
950
969
|
mcpEntry: "old context-mode MCP entry mcpServers.context-mode",
|
|
951
|
-
codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex
|
|
970
|
+
codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/<event>.mjs",
|
|
952
971
|
codexToml: "old context-mode config.toml [mcp_servers.context-mode*] section",
|
|
953
972
|
hookFile: "old context-mode hook file context-mode.json (runs context-mode hook)",
|
|
954
973
|
vscodeMcp: "old context-mode MCP entry servers.context-mode in .vscode/mcp.json: report only, never removed",
|
|
@@ -985,7 +1004,6 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
|
|
|
985
1004
|
var JSON_INDENT_UNIT = " ";
|
|
986
1005
|
var MCP_COMMAND_FIELD = "command";
|
|
987
1006
|
var MCP_ARGS_FIELD = "args";
|
|
988
|
-
var MCP_ENV_FIELD = "env";
|
|
989
1007
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
990
1008
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
991
1009
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -1101,6 +1119,70 @@ var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=
|
|
|
1101
1119
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
1102
1120
|
var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
1103
1121
|
|
|
1122
|
+
// src/adapters/opencode.ts
|
|
1123
|
+
var TOOL_NAME_PREFIX = "";
|
|
1124
|
+
var OWN_WIRE_PREFIX = SERVER_KEY + "_";
|
|
1125
|
+
var OPENCODE_EVENTS = {
|
|
1126
|
+
context: "SessionStart",
|
|
1127
|
+
prompt: "UserPromptSubmit",
|
|
1128
|
+
"execute.before": "PreToolUse",
|
|
1129
|
+
"execute.after": "PostToolUse",
|
|
1130
|
+
compaction: "PreCompact",
|
|
1131
|
+
"step-finish": "Usage"
|
|
1132
|
+
};
|
|
1133
|
+
var SHELL_TOOL_NAME = "bash";
|
|
1134
|
+
var READ_TOOL_NAME = "read";
|
|
1135
|
+
var SHELL_TOOL_NAMES = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1136
|
+
var NATIVE_TO_CANONICAL = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"])) };
|
|
1137
|
+
function toCanonicalTool(name) {
|
|
1138
|
+
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1139
|
+
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL, name) ? NATIVE_TO_CANONICAL[name] : name;
|
|
1140
|
+
}
|
|
1141
|
+
function record(v) {
|
|
1142
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1143
|
+
}
|
|
1144
|
+
function readResult(p) {
|
|
1145
|
+
const text = p.output === void 0 ? "" : typeof p.output === "string" ? p.output : JSON.stringify(p.output);
|
|
1146
|
+
const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
|
|
1147
|
+
if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
|
|
1148
|
+
return info;
|
|
1149
|
+
}
|
|
1150
|
+
function decode(raw) {
|
|
1151
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("opencode: hook payload is not an object");
|
|
1152
|
+
const p = raw;
|
|
1153
|
+
const native = typeof p.type === "string" ? p.type : "";
|
|
1154
|
+
const event = Object.prototype.hasOwnProperty.call(OPENCODE_EVENTS, native) ? OPENCODE_EVENTS[native] : void 0;
|
|
1155
|
+
if (event === void 0) throw new Error("opencode: unknown hook event " + String(p.type));
|
|
1156
|
+
const ev = { event, agent: "opencode", sessionId: String(p.sessionID ?? ""), cwd: String(p.directory ?? "") };
|
|
1157
|
+
if (typeof p.agentID === "string" && p.agentID !== "") {
|
|
1158
|
+
ev.agentId = p.agentID;
|
|
1159
|
+
ev.agentType = p.agentID;
|
|
1160
|
+
}
|
|
1161
|
+
if (Array.isArray(p.agentTools)) ev.agentTools = p.agentTools.filter((t) => typeof t === "string");
|
|
1162
|
+
if (event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
|
|
1163
|
+
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
1164
|
+
const name = String(p.tool ?? "");
|
|
1165
|
+
ev.tool = { name, canonicalName: toCanonicalTool(name), input: record(p.args) };
|
|
1166
|
+
if (typeof p.callID === "string") ev.tool.callId = p.callID;
|
|
1167
|
+
}
|
|
1168
|
+
if (event === "PostToolUse") ev.result = readResult(p);
|
|
1169
|
+
if (typeof p.turn === "number") ev.turn = p.turn;
|
|
1170
|
+
return ev;
|
|
1171
|
+
}
|
|
1172
|
+
function encode(ev, d, _extra) {
|
|
1173
|
+
switch (d.kind) {
|
|
1174
|
+
case "allow":
|
|
1175
|
+
return { stdout: "", exitCode: 0 };
|
|
1176
|
+
case "hint":
|
|
1177
|
+
return { stdout: ev.event === "SessionStart" ? d.text : "", exitCode: 0 };
|
|
1178
|
+
case "deny":
|
|
1179
|
+
if (ev.event !== "PreToolUse") return { stdout: "", exitCode: 0 };
|
|
1180
|
+
return { stdout: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason, exitCode: 2 };
|
|
1181
|
+
case "replace":
|
|
1182
|
+
return { stdout: ev.event === "PostToolUse" ? d.output : "", exitCode: 0 };
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1104
1186
|
// src/core/contracts/errors.ts
|
|
1105
1187
|
var ERROR_TEXT = Object.freeze({
|
|
1106
1188
|
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 +1256,14 @@ var CtxError = class extends Error {
|
|
|
1174
1256
|
};
|
|
1175
1257
|
|
|
1176
1258
|
// src/core/hooks/dispatch.ts
|
|
1177
|
-
import { dirname as dirname4, join as join8, relative as relative3, resolve as
|
|
1259
|
+
import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
1178
1260
|
|
|
1179
1261
|
// src/core/contracts/agents.ts
|
|
1180
1262
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
1181
1263
|
|
|
1182
1264
|
// src/adapters/claude-code.ts
|
|
1183
|
-
var
|
|
1184
|
-
var
|
|
1265
|
+
var TOOL_NAME_PREFIX2 = "mcp__plugin_context-mode_context-mode__";
|
|
1266
|
+
var SHELL_TOOL_NAMES2 = Object.freeze(["Bash", "PowerShell"]);
|
|
1185
1267
|
var POWERSHELL_TOOL = "PowerShell";
|
|
1186
1268
|
var SHELL_CANONICAL = "Bash";
|
|
1187
1269
|
var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
|
|
@@ -1266,7 +1348,7 @@ function blocksOf(resp) {
|
|
|
1266
1348
|
}
|
|
1267
1349
|
return { text: parts.join("\n"), keep };
|
|
1268
1350
|
}
|
|
1269
|
-
function
|
|
1351
|
+
function readResult2(resp) {
|
|
1270
1352
|
const text = outputOf(resp);
|
|
1271
1353
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
1272
1354
|
const info = { isError, bytes: Buffer.byteLength(text), text };
|
|
@@ -1306,7 +1388,7 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
|
|
|
1306
1388
|
if (typeof p.tool_use_id === "string" && p.tool_use_id !== "") tool.callId = p.tool_use_id;
|
|
1307
1389
|
ev.tool = tool;
|
|
1308
1390
|
}
|
|
1309
|
-
if (event === "PostToolUse") ev.result =
|
|
1391
|
+
if (event === "PostToolUse") ev.result = readResult2(p.tool_response);
|
|
1310
1392
|
return ev;
|
|
1311
1393
|
}
|
|
1312
1394
|
function replaceShape(ev, output) {
|
|
@@ -1356,9 +1438,9 @@ function requireFields(raw) {
|
|
|
1356
1438
|
if (p[f] === void 0) throw new Error("claude-code: missing required field " + f);
|
|
1357
1439
|
}
|
|
1358
1440
|
}
|
|
1359
|
-
function
|
|
1441
|
+
function decode2(raw) {
|
|
1360
1442
|
requireFields(raw);
|
|
1361
|
-
const ev = decodeClaudeShape(raw, "claude-code",
|
|
1443
|
+
const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX2, CLAUDE_SOURCES);
|
|
1362
1444
|
if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
|
|
1363
1445
|
if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
1364
1446
|
if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
|
|
@@ -1367,29 +1449,29 @@ function decode(raw) {
|
|
|
1367
1449
|
}
|
|
1368
1450
|
return ev;
|
|
1369
1451
|
}
|
|
1370
|
-
function
|
|
1452
|
+
function encode2(ev, d, _extra) {
|
|
1371
1453
|
return encodeClaudeShape(ev, d, true);
|
|
1372
1454
|
}
|
|
1373
1455
|
|
|
1374
1456
|
// src/adapters/codex.ts
|
|
1375
|
-
var
|
|
1457
|
+
var TOOL_NAME_PREFIX3 = "mcp__context_mode__";
|
|
1376
1458
|
var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
|
|
1377
1459
|
var STOP_EVENT = "Stop";
|
|
1378
1460
|
var EMPTY = { stdout: "", exitCode: 0 };
|
|
1379
|
-
function
|
|
1461
|
+
function decode3(raw) {
|
|
1380
1462
|
if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
|
|
1381
1463
|
const p = raw;
|
|
1382
1464
|
return { event: STOP_EVENT, agent: "codex", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
|
|
1383
1465
|
}
|
|
1384
|
-
return decodeClaudeShape(raw, "codex",
|
|
1466
|
+
return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX3, CODEX_SOURCES);
|
|
1385
1467
|
}
|
|
1386
|
-
function
|
|
1468
|
+
function encode3(ev, d, _extra) {
|
|
1387
1469
|
if (ev.event === STOP_EVENT) return EMPTY;
|
|
1388
1470
|
return encodeClaudeShape(ev, d, false);
|
|
1389
1471
|
}
|
|
1390
1472
|
|
|
1391
1473
|
// src/adapters/gemini.ts
|
|
1392
|
-
var
|
|
1474
|
+
var TOOL_NAME_PREFIX4 = "mcp_context-mode_";
|
|
1393
1475
|
var GEMINI_EVENTS = {
|
|
1394
1476
|
SessionStart: "SessionStart",
|
|
1395
1477
|
BeforeAgent: "UserPromptSubmit",
|
|
@@ -1405,15 +1487,15 @@ var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its
|
|
|
1405
1487
|
function own(p, key) {
|
|
1406
1488
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
1407
1489
|
}
|
|
1408
|
-
var
|
|
1490
|
+
var NATIVE_TO_CANONICAL2 = {
|
|
1409
1491
|
run_shell_command: "Bash",
|
|
1410
1492
|
read_file: "Read",
|
|
1411
1493
|
grep_search: "Grep",
|
|
1412
1494
|
web_fetch: "WebFetch"
|
|
1413
1495
|
};
|
|
1414
1496
|
function canonicalName2(name, mcp) {
|
|
1415
|
-
if (name.startsWith(
|
|
1416
|
-
if (Object.hasOwn(
|
|
1497
|
+
if (name.startsWith(TOOL_NAME_PREFIX4)) return name.slice(TOOL_NAME_PREFIX4.length);
|
|
1498
|
+
if (Object.hasOwn(NATIVE_TO_CANONICAL2, name)) return NATIVE_TO_CANONICAL2[name];
|
|
1417
1499
|
if (typeof mcp !== "object" || mcp === null) return name;
|
|
1418
1500
|
const m = mcp;
|
|
1419
1501
|
const server2 = own(m, "server_name");
|
|
@@ -1436,7 +1518,7 @@ function partsText(llm) {
|
|
|
1436
1518
|
}
|
|
1437
1519
|
return out.join("");
|
|
1438
1520
|
}
|
|
1439
|
-
function
|
|
1521
|
+
function readResult3(resp) {
|
|
1440
1522
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
1441
1523
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
1442
1524
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
@@ -1488,7 +1570,7 @@ function nativeInput(name, input) {
|
|
|
1488
1570
|
}
|
|
1489
1571
|
return input;
|
|
1490
1572
|
}
|
|
1491
|
-
function
|
|
1573
|
+
function decode4(raw) {
|
|
1492
1574
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
1493
1575
|
const p = raw;
|
|
1494
1576
|
const native = own(p, "hook_event_name");
|
|
@@ -1508,10 +1590,10 @@ function decode3(raw) {
|
|
|
1508
1590
|
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
1509
1591
|
};
|
|
1510
1592
|
}
|
|
1511
|
-
if (event === "PostToolUse") ev.result =
|
|
1593
|
+
if (event === "PostToolUse") ev.result = readResult3(own(p, "tool_response"));
|
|
1512
1594
|
return ev;
|
|
1513
1595
|
}
|
|
1514
|
-
function
|
|
1596
|
+
function encode4(ev, d, _extra) {
|
|
1515
1597
|
switch (d.kind) {
|
|
1516
1598
|
case "allow":
|
|
1517
1599
|
return EMPTY2;
|
|
@@ -1528,9 +1610,9 @@ function encode3(ev, d, _extra) {
|
|
|
1528
1610
|
}
|
|
1529
1611
|
|
|
1530
1612
|
// src/adapters/qwen.ts
|
|
1531
|
-
var
|
|
1613
|
+
var TOOL_NAME_PREFIX5 = "mcp__context-mode__";
|
|
1532
1614
|
var QWEN_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1533
|
-
var
|
|
1615
|
+
var NATIVE_TO_CANONICAL3 = {
|
|
1534
1616
|
run_shell_command: "Bash",
|
|
1535
1617
|
Shell: "Bash",
|
|
1536
1618
|
read_file: "Read",
|
|
@@ -1538,11 +1620,11 @@ var NATIVE_TO_CANONICAL2 = {
|
|
|
1538
1620
|
web_fetch: "WebFetch"
|
|
1539
1621
|
};
|
|
1540
1622
|
var FAILURE_EVENT = "PostToolUseFailure";
|
|
1541
|
-
function
|
|
1623
|
+
function decode5(raw) {
|
|
1542
1624
|
const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
|
|
1543
1625
|
const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
|
|
1544
|
-
const ev = decodeClaudeShape(payload, "qwen",
|
|
1545
|
-
if (ev.tool !== void 0 && Object.hasOwn(
|
|
1626
|
+
const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX5, QWEN_SOURCES);
|
|
1627
|
+
if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL3, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL3[ev.tool.name];
|
|
1546
1628
|
if (failure) {
|
|
1547
1629
|
const error40 = raw.error;
|
|
1548
1630
|
const text = typeof error40 === "string" ? error40 : error40 === void 0 ? "" : JSON.stringify(error40);
|
|
@@ -1550,12 +1632,12 @@ function decode4(raw) {
|
|
|
1550
1632
|
}
|
|
1551
1633
|
return ev;
|
|
1552
1634
|
}
|
|
1553
|
-
function
|
|
1635
|
+
function encode5(ev, d, _extra) {
|
|
1554
1636
|
return encodeClaudeShape(ev, d, false);
|
|
1555
1637
|
}
|
|
1556
1638
|
|
|
1557
1639
|
// src/adapters/copilot-cli.ts
|
|
1558
|
-
var
|
|
1640
|
+
var TOOL_NAME_PREFIX6 = "context-mode-";
|
|
1559
1641
|
var NATIVE_EVENTS = {
|
|
1560
1642
|
sessionStart: { event: "SessionStart", casing: "camel", failure: false },
|
|
1561
1643
|
userPromptSubmitted: { event: "UserPromptSubmit", casing: "camel", failure: false },
|
|
@@ -1577,11 +1659,11 @@ var RESULT_SUCCESS = "success";
|
|
|
1577
1659
|
function isRecord(v) {
|
|
1578
1660
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1579
1661
|
}
|
|
1580
|
-
var
|
|
1581
|
-
var
|
|
1662
|
+
var SHELL_TOOL_NAMES3 = Object.freeze(["bash", "powershell"]);
|
|
1663
|
+
var NATIVE_TO_CANONICAL4 = Object.fromEntries(SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]));
|
|
1582
1664
|
function canonicalName3(name) {
|
|
1583
|
-
if (name.startsWith(
|
|
1584
|
-
if (Object.hasOwn(
|
|
1665
|
+
if (name.startsWith(TOOL_NAME_PREFIX6)) return name.slice(TOOL_NAME_PREFIX6.length);
|
|
1666
|
+
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
1585
1667
|
return name;
|
|
1586
1668
|
}
|
|
1587
1669
|
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
@@ -1606,7 +1688,7 @@ var RESULT_KEYS = {
|
|
|
1606
1688
|
camel: { type: "resultType", text: "textResultForLlm" },
|
|
1607
1689
|
snake: { type: "result_type", text: "text_result_for_llm" }
|
|
1608
1690
|
};
|
|
1609
|
-
function
|
|
1691
|
+
function readResult4(v, casing, failure) {
|
|
1610
1692
|
const k = RESULT_KEYS[casing];
|
|
1611
1693
|
const r = isRecord(v) ? v : {};
|
|
1612
1694
|
const text = typeof r[k.text] === "string" ? r[k.text] : "";
|
|
@@ -1624,7 +1706,7 @@ function eventName(raw) {
|
|
|
1624
1706
|
if (raw.hook_event_name !== void 0) return raw.hook_event_name;
|
|
1625
1707
|
return EVENT_BY_KEY.find(([key]) => Object.hasOwn(raw, key))?.[1];
|
|
1626
1708
|
}
|
|
1627
|
-
function
|
|
1709
|
+
function decode6(raw) {
|
|
1628
1710
|
if (!isRecord(raw)) throw new Error("copilot-cli: hook payload is not a JSON object");
|
|
1629
1711
|
const name = eventName(raw);
|
|
1630
1712
|
const native = typeof name === "string" ? NATIVE_EVENTS[name] : void 0;
|
|
@@ -1639,11 +1721,11 @@ function decode5(raw) {
|
|
|
1639
1721
|
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
|
|
1640
1722
|
ev.tool = tool;
|
|
1641
1723
|
}
|
|
1642
|
-
if (event === "PostToolUse") ev.result =
|
|
1724
|
+
if (event === "PostToolUse") ev.result = readResult4(raw[k.result], native.casing, native.failure);
|
|
1643
1725
|
return ev;
|
|
1644
1726
|
}
|
|
1645
1727
|
var EMPTY3 = { stdout: "", exitCode: 0 };
|
|
1646
|
-
function
|
|
1728
|
+
function encode6(ev, d, _extra) {
|
|
1647
1729
|
switch (d.kind) {
|
|
1648
1730
|
case "allow":
|
|
1649
1731
|
return EMPTY3;
|
|
@@ -1662,22 +1744,22 @@ function encode5(ev, d, _extra) {
|
|
|
1662
1744
|
}
|
|
1663
1745
|
|
|
1664
1746
|
// src/adapters/vscode.ts
|
|
1665
|
-
var
|
|
1747
|
+
var TOOL_NAME_PREFIX7 = "mcp_context-mode_";
|
|
1666
1748
|
var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PreCompact"];
|
|
1667
1749
|
var MCP_PREFIX2 = "mcp_";
|
|
1668
1750
|
var MCP_SEP2 = "_";
|
|
1669
1751
|
var SESSION_START_NEW = "new";
|
|
1670
|
-
var
|
|
1752
|
+
var SHELL_TOOL_NAMES4 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
|
|
1671
1753
|
var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
|
|
1672
1754
|
var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
|
|
1673
|
-
var
|
|
1674
|
-
...
|
|
1755
|
+
var NATIVE_TO_CANONICAL5 = Object.fromEntries([
|
|
1756
|
+
...SHELL_TOOL_NAMES4.map((n) => [n, "Bash"]),
|
|
1675
1757
|
...READ_TOOL_NAMES.map((n) => [n, "Read"]),
|
|
1676
1758
|
...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
|
|
1677
1759
|
]);
|
|
1678
1760
|
function canonicalName4(name) {
|
|
1679
|
-
if (name.startsWith(
|
|
1680
|
-
if (Object.hasOwn(
|
|
1761
|
+
if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
|
|
1762
|
+
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1681
1763
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
1682
1764
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
1683
1765
|
const sep5 = rest.indexOf(MCP_SEP2);
|
|
@@ -1704,7 +1786,7 @@ function policyInput(name, canonical, input) {
|
|
|
1704
1786
|
}
|
|
1705
1787
|
return input;
|
|
1706
1788
|
}
|
|
1707
|
-
function
|
|
1789
|
+
function readResult5(resp) {
|
|
1708
1790
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
1709
1791
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
1710
1792
|
return { isError, bytes: Buffer.byteLength(text), text };
|
|
@@ -1757,7 +1839,7 @@ function decodeCamel(p, name) {
|
|
|
1757
1839
|
if (event === "PostToolUse") ev.result = readCamelResult(p.toolResult);
|
|
1758
1840
|
return ev;
|
|
1759
1841
|
}
|
|
1760
|
-
function
|
|
1842
|
+
function decode7(raw) {
|
|
1761
1843
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("vscode: hook payload is not a JSON object");
|
|
1762
1844
|
const p = raw;
|
|
1763
1845
|
if (p.hookEventName !== void 0) return decodeCamel(p, p.hookEventName);
|
|
@@ -1777,15 +1859,15 @@ function decode6(raw) {
|
|
|
1777
1859
|
const canonical = canonicalName4(name);
|
|
1778
1860
|
ev.tool = { name, canonicalName: canonical, input: policyInput(name, canonical, input) };
|
|
1779
1861
|
}
|
|
1780
|
-
if (event === "PostToolUse") ev.result =
|
|
1862
|
+
if (event === "PostToolUse") ev.result = readResult5(p.tool_response);
|
|
1781
1863
|
return ev;
|
|
1782
1864
|
}
|
|
1783
|
-
function
|
|
1865
|
+
function encode7(ev, d, _extra) {
|
|
1784
1866
|
return encodeClaudeShape(ev, d, false);
|
|
1785
1867
|
}
|
|
1786
1868
|
|
|
1787
1869
|
// src/adapters/kiro.ts
|
|
1788
|
-
var
|
|
1870
|
+
var TOOL_NAME_PREFIX8 = "mcp_context_mode_";
|
|
1789
1871
|
var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
|
|
1790
1872
|
var KIRO_EVENTS = {
|
|
1791
1873
|
SessionStart: "SessionStart",
|
|
@@ -1801,25 +1883,25 @@ var KIRO_EVENTS = {
|
|
|
1801
1883
|
var PROMPT_FIELD = "prompt";
|
|
1802
1884
|
var PROMPT_ENV = "USER_PROMPT";
|
|
1803
1885
|
var MCP_PREFIX3 = "mcp_";
|
|
1804
|
-
var
|
|
1805
|
-
var
|
|
1886
|
+
var SHELL_TOOL_NAMES5 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
1887
|
+
var NATIVE_TO_CANONICAL6 = Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"]));
|
|
1806
1888
|
var MCP_SEP3 = "_";
|
|
1807
1889
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1808
1890
|
function canonicalName5(name) {
|
|
1809
|
-
if (name.startsWith(
|
|
1891
|
+
if (name.startsWith(TOOL_NAME_PREFIX8)) return name.slice(TOOL_NAME_PREFIX8.length);
|
|
1810
1892
|
if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
|
|
1811
|
-
if (Object.hasOwn(
|
|
1893
|
+
if (Object.hasOwn(NATIVE_TO_CANONICAL6, name)) return NATIVE_TO_CANONICAL6[name];
|
|
1812
1894
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1813
1895
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
1814
1896
|
const sep5 = rest.indexOf(MCP_SEP3);
|
|
1815
1897
|
if (sep5 <= 0 || sep5 === rest.length - 1) return name;
|
|
1816
1898
|
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP3.length);
|
|
1817
1899
|
}
|
|
1818
|
-
function
|
|
1900
|
+
function readResult6(resp) {
|
|
1819
1901
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
1820
1902
|
return { isError: false, bytes: Buffer.byteLength(text), text };
|
|
1821
1903
|
}
|
|
1822
|
-
function
|
|
1904
|
+
function decode8(raw) {
|
|
1823
1905
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("kiro: hook payload is not a JSON object");
|
|
1824
1906
|
const p = raw;
|
|
1825
1907
|
const native = typeof p.hook_event_name === "string" ? p.hook_event_name : "";
|
|
@@ -1837,10 +1919,10 @@ function decode7(raw) {
|
|
|
1837
1919
|
const input = typeof p.tool_input === "object" && p.tool_input !== null && !Array.isArray(p.tool_input) ? p.tool_input : {};
|
|
1838
1920
|
ev.tool = { name, canonicalName: canonicalName5(name), input };
|
|
1839
1921
|
}
|
|
1840
|
-
if (event === "PostToolUse") ev.result =
|
|
1922
|
+
if (event === "PostToolUse") ev.result = readResult6(p.tool_response);
|
|
1841
1923
|
return ev;
|
|
1842
1924
|
}
|
|
1843
|
-
function
|
|
1925
|
+
function encode8(ev, d, _extra) {
|
|
1844
1926
|
if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
|
|
1845
1927
|
switch (d.kind) {
|
|
1846
1928
|
case "allow":
|
|
@@ -1855,19 +1937,19 @@ function encode7(ev, d, _extra) {
|
|
|
1855
1937
|
}
|
|
1856
1938
|
|
|
1857
1939
|
// src/adapters/zcode.ts
|
|
1858
|
-
var
|
|
1940
|
+
var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
1859
1941
|
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1860
1942
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1861
1943
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1862
1944
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
1863
|
-
function
|
|
1945
|
+
function decode9(raw) {
|
|
1864
1946
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
|
|
1865
1947
|
const p = { ...raw };
|
|
1866
1948
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
1867
1949
|
const failure = p.hook_event_name === FAILURE_EVENT2;
|
|
1868
1950
|
if (failure) p.hook_event_name = "PostToolUse";
|
|
1869
1951
|
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
1870
|
-
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX :
|
|
1952
|
+
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
|
|
1871
1953
|
const ev = decodeClaudeShape(p, "zcode", prefix, ZCODE_SOURCES);
|
|
1872
1954
|
if (failure) {
|
|
1873
1955
|
const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
|
|
@@ -1875,12 +1957,12 @@ function decode8(raw) {
|
|
|
1875
1957
|
}
|
|
1876
1958
|
return ev;
|
|
1877
1959
|
}
|
|
1878
|
-
function
|
|
1960
|
+
function encode9(ev, d, _extra) {
|
|
1879
1961
|
return encodeClaudeShape(ev, d, false);
|
|
1880
1962
|
}
|
|
1881
1963
|
|
|
1882
1964
|
// src/adapters/pi.ts
|
|
1883
|
-
var
|
|
1965
|
+
var TOOL_NAME_PREFIX10 = "";
|
|
1884
1966
|
var PI_EVENTS = {
|
|
1885
1967
|
session_start: { event: "SessionStart", source: "startup" },
|
|
1886
1968
|
session_compact: { event: "SessionStart", source: "compact" },
|
|
@@ -1888,17 +1970,18 @@ var PI_EVENTS = {
|
|
|
1888
1970
|
tool_call: { event: "PreToolUse" },
|
|
1889
1971
|
tool_result: { event: "PostToolUse" }
|
|
1890
1972
|
};
|
|
1891
|
-
var
|
|
1892
|
-
function
|
|
1973
|
+
var NATIVE_TO_CANONICAL7 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
1974
|
+
function record2(v) {
|
|
1893
1975
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
1894
1976
|
}
|
|
1895
|
-
function
|
|
1977
|
+
function readResult7(p) {
|
|
1896
1978
|
const text = p.content === void 0 ? "" : typeof p.content === "string" ? p.content : JSON.stringify(p.content);
|
|
1897
1979
|
const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
|
|
1898
1980
|
if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
|
|
1981
|
+
if (p.keep === true) info.keep = true;
|
|
1899
1982
|
return info;
|
|
1900
1983
|
}
|
|
1901
|
-
function
|
|
1984
|
+
function decode10(raw) {
|
|
1902
1985
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("pi: hook payload is not an object");
|
|
1903
1986
|
const p = raw;
|
|
1904
1987
|
const native = typeof p.type === "string" ? p.type : "";
|
|
@@ -1909,10 +1992,10 @@ function decode9(raw) {
|
|
|
1909
1992
|
if (row5.event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
|
|
1910
1993
|
if (row5.event === "PreToolUse" || row5.event === "PostToolUse") {
|
|
1911
1994
|
const name = String(p.toolName ?? "");
|
|
1912
|
-
ev.tool = { name, canonicalName: Object.hasOwn(
|
|
1995
|
+
ev.tool = { name, canonicalName: Object.hasOwn(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name, input: record2(p.input) };
|
|
1913
1996
|
if (typeof p.toolCallId === "string") ev.tool.callId = p.toolCallId;
|
|
1914
1997
|
}
|
|
1915
|
-
if (row5.event === "PostToolUse") ev.result =
|
|
1998
|
+
if (row5.event === "PostToolUse") ev.result = readResult7(p);
|
|
1916
1999
|
if (typeof p.turn === "number") ev.turn = p.turn;
|
|
1917
2000
|
return ev;
|
|
1918
2001
|
}
|
|
@@ -1928,7 +2011,7 @@ function stdoutFor(ev, d) {
|
|
|
1928
2011
|
}
|
|
1929
2012
|
return { stdout: "", exitCode: 0 };
|
|
1930
2013
|
}
|
|
1931
|
-
function
|
|
2014
|
+
function encode10(ev, d, _extra) {
|
|
1932
2015
|
const out = stdoutFor(ev, d);
|
|
1933
2016
|
if (d?.kind === "allow") return out;
|
|
1934
2017
|
return { stdout: out.stdout, exitCode: out.exitCode, role: PI_ROLE, content: out.stdout, timestamp: Date.now() };
|
|
@@ -1937,75 +2020,16 @@ function checkPermission(out) {
|
|
|
1937
2020
|
return out.exitCode === 2 ? { block: true, reason: out.stdout } : void 0;
|
|
1938
2021
|
}
|
|
1939
2022
|
|
|
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
2023
|
// src/adapters/table.ts
|
|
2000
2024
|
var CLAUDE_EVENTS = { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" };
|
|
2001
2025
|
var CLAUDE_TOOLS = { shell: ["Bash"], read: ["Read"], grep: ["Grep"], webfetch: ["WebFetch"], edit: ["Write", "Edit", "NotebookEdit"] };
|
|
2002
|
-
var CLAUDE_CODE_TOOLS = { ...CLAUDE_TOOLS, shell: [...
|
|
2026
|
+
var CLAUDE_CODE_TOOLS = { ...CLAUDE_TOOLS, shell: [...SHELL_TOOL_NAMES2] };
|
|
2003
2027
|
var ADAPTERS = Object.freeze([
|
|
2004
2028
|
{
|
|
2005
2029
|
id: "claude-code",
|
|
2006
2030
|
installMode: "marketplace",
|
|
2007
2031
|
projectSource: "env:CLAUDE_PROJECT_DIR",
|
|
2008
|
-
toolNamePrefix:
|
|
2032
|
+
toolNamePrefix: TOOL_NAME_PREFIX2,
|
|
2009
2033
|
nativeTools: CLAUDE_CODE_TOOLS,
|
|
2010
2034
|
execReadOnlyHint: false,
|
|
2011
2035
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2016,14 +2040,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2016
2040
|
hookChannel: { kind: "package", path: "hooks/claude-code.json" },
|
|
2017
2041
|
skillChannel: { kind: "package", path: "skills" },
|
|
2018
2042
|
// ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
|
|
2019
|
-
decode,
|
|
2020
|
-
encode
|
|
2043
|
+
decode: decode2,
|
|
2044
|
+
encode: encode2
|
|
2021
2045
|
},
|
|
2022
2046
|
{
|
|
2023
2047
|
id: "codex",
|
|
2024
2048
|
installMode: "config-mcp",
|
|
2025
2049
|
projectSource: "arg:--agent+cwd",
|
|
2026
|
-
toolNamePrefix:
|
|
2050
|
+
toolNamePrefix: TOOL_NAME_PREFIX3,
|
|
2027
2051
|
nativeTools: { shell: ["Bash"], edit: ["apply_patch"] },
|
|
2028
2052
|
execReadOnlyHint: true,
|
|
2029
2053
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2034,14 +2058,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2034
2058
|
hookChannel: { kind: "home-file", path: ".codex/hooks.json" },
|
|
2035
2059
|
skillChannel: { kind: "home-dir", path: ".codex/skills" },
|
|
2036
2060
|
// ADR-0020
|
|
2037
|
-
decode:
|
|
2038
|
-
encode:
|
|
2061
|
+
decode: decode3,
|
|
2062
|
+
encode: encode3
|
|
2039
2063
|
},
|
|
2040
2064
|
{
|
|
2041
2065
|
id: "gemini",
|
|
2042
2066
|
installMode: "extension",
|
|
2043
2067
|
projectSource: "spawn-cwd",
|
|
2044
|
-
toolNamePrefix:
|
|
2068
|
+
toolNamePrefix: TOOL_NAME_PREFIX4,
|
|
2045
2069
|
// D-HA-GEMINI-NAMES-1: gemini-cli 0.65.0 *_TOOL_NAME constants.
|
|
2046
2070
|
nativeTools: { shell: ["run_shell_command"], read: ["read_file"], grep: ["grep_search"], webfetch: ["web_fetch"] },
|
|
2047
2071
|
execReadOnlyHint: false,
|
|
@@ -2056,14 +2080,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2056
2080
|
hookChannel: { kind: "package", path: "hooks/hooks.json" },
|
|
2057
2081
|
skillChannel: { kind: "package", path: "skills" },
|
|
2058
2082
|
// ADR-0020
|
|
2059
|
-
decode:
|
|
2060
|
-
encode:
|
|
2083
|
+
decode: decode4,
|
|
2084
|
+
encode: encode4
|
|
2061
2085
|
},
|
|
2062
2086
|
{
|
|
2063
2087
|
id: "qwen",
|
|
2064
2088
|
installMode: "extension",
|
|
2065
2089
|
projectSource: "spawn-cwd",
|
|
2066
|
-
toolNamePrefix:
|
|
2090
|
+
toolNamePrefix: TOOL_NAME_PREFIX5,
|
|
2067
2091
|
nativeTools: { shell: ["run_shell_command", "Shell"], read: ["read_file"], grep: ["grep_search"], webfetch: ["web_fetch"] },
|
|
2068
2092
|
execReadOnlyHint: false,
|
|
2069
2093
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2074,15 +2098,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2074
2098
|
hookChannel: { kind: "package", path: "hooks/qwen.json" },
|
|
2075
2099
|
skillChannel: { kind: "package", path: "skills" },
|
|
2076
2100
|
// ADR-0020, D-HQ-SKILLS-3: qwen loads <extension>/skills, shared with gemini
|
|
2077
|
-
decode:
|
|
2078
|
-
encode:
|
|
2101
|
+
decode: decode5,
|
|
2102
|
+
encode: encode5
|
|
2079
2103
|
},
|
|
2080
2104
|
{
|
|
2081
2105
|
id: "copilot-cli",
|
|
2082
2106
|
installMode: "plugin",
|
|
2083
2107
|
projectSource: "arg:--agent+cwd",
|
|
2084
|
-
toolNamePrefix:
|
|
2085
|
-
nativeTools: { shell: [...
|
|
2108
|
+
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
2109
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
|
|
2086
2110
|
execReadOnlyHint: false,
|
|
2087
2111
|
// D-PWSH-DUMP-1
|
|
2088
2112
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
@@ -2093,16 +2117,16 @@ var ADAPTERS = Object.freeze([
|
|
|
2093
2117
|
hookChannel: { kind: "home-file", path: ".copilot/hooks/context-mode.json" },
|
|
2094
2118
|
skillChannel: { kind: "home-dir", path: ".copilot/skills" },
|
|
2095
2119
|
// ADR-0020
|
|
2096
|
-
decode:
|
|
2097
|
-
encode:
|
|
2120
|
+
decode: decode6,
|
|
2121
|
+
encode: encode6
|
|
2098
2122
|
},
|
|
2099
2123
|
{
|
|
2100
2124
|
id: "vscode",
|
|
2101
2125
|
installMode: "mcp-entry",
|
|
2102
2126
|
projectSource: "arg:workspaceFolder",
|
|
2103
|
-
toolNamePrefix:
|
|
2127
|
+
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
2104
2128
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
2105
|
-
nativeTools: { shell: [...
|
|
2129
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES4], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
2106
2130
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
2107
2131
|
execReadOnlyHint: false,
|
|
2108
2132
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -2113,15 +2137,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2113
2137
|
hookChannel: { kind: "home-file", path: ".copilot/hooks/context-mode-vscode.json" },
|
|
2114
2138
|
skillChannel: { kind: "home-dir", path: ".agents/skills" },
|
|
2115
2139
|
// ADR-0020, D-HQ-COPILOT-NAMES-3: Copilot CLI owns ~/.copilot/skills
|
|
2116
|
-
decode:
|
|
2117
|
-
encode:
|
|
2140
|
+
decode: decode7,
|
|
2141
|
+
encode: encode7
|
|
2118
2142
|
},
|
|
2119
2143
|
{
|
|
2120
2144
|
id: "kiro",
|
|
2121
2145
|
installMode: "mcp-entry",
|
|
2122
2146
|
projectSource: "arg:--agent+cwd",
|
|
2123
|
-
toolNamePrefix:
|
|
2124
|
-
nativeTools: { shell: [...
|
|
2147
|
+
toolNamePrefix: TOOL_NAME_PREFIX8,
|
|
2148
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES5] },
|
|
2125
2149
|
execReadOnlyHint: false,
|
|
2126
2150
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
2127
2151
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -2132,15 +2156,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2132
2156
|
hookChannel: { kind: "home-file", path: ".kiro/hooks/context-mode.json" },
|
|
2133
2157
|
skillChannel: { kind: "home-dir", path: ".kiro/skills" },
|
|
2134
2158
|
// ADR-0020
|
|
2135
|
-
decode:
|
|
2136
|
-
encode:
|
|
2159
|
+
decode: decode8,
|
|
2160
|
+
encode: encode8
|
|
2137
2161
|
},
|
|
2138
2162
|
{
|
|
2139
2163
|
// toolNamePrefix is the documented ZCode name mcp__<server>__<tool> (D-N7-ZCODE-NAMES-1); nativeTools are Claude names.
|
|
2140
2164
|
id: "zcode",
|
|
2141
2165
|
installMode: "hooks+mcp",
|
|
2142
2166
|
projectSource: "spawn-cwd",
|
|
2143
|
-
toolNamePrefix:
|
|
2167
|
+
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
2144
2168
|
nativeTools: CLAUDE_TOOLS,
|
|
2145
2169
|
execReadOnlyHint: false,
|
|
2146
2170
|
eventMap: CLAUDE_EVENTS,
|
|
@@ -2151,14 +2175,14 @@ var ADAPTERS = Object.freeze([
|
|
|
2151
2175
|
hookChannel: { kind: "home-file", path: ".zcode/cli/config.json" },
|
|
2152
2176
|
skillChannel: { kind: "home-dir", path: ".zcode/skills" },
|
|
2153
2177
|
// ADR-0020
|
|
2154
|
-
decode:
|
|
2155
|
-
encode:
|
|
2178
|
+
decode: decode9,
|
|
2179
|
+
encode: encode9
|
|
2156
2180
|
},
|
|
2157
2181
|
{
|
|
2158
2182
|
id: "pi",
|
|
2159
2183
|
installMode: "in-process",
|
|
2160
2184
|
projectSource: "pi:ctx.cwd",
|
|
2161
|
-
toolNamePrefix:
|
|
2185
|
+
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
2162
2186
|
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
2163
2187
|
execReadOnlyHint: false,
|
|
2164
2188
|
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
@@ -2170,15 +2194,15 @@ var ADAPTERS = Object.freeze([
|
|
|
2170
2194
|
hookChannel: { kind: "in-process", path: "pi/index.js" },
|
|
2171
2195
|
skillChannel: { kind: "package", path: "pi/skills" },
|
|
2172
2196
|
// ADR-0020
|
|
2173
|
-
decode:
|
|
2174
|
-
encode:
|
|
2197
|
+
decode: decode10,
|
|
2198
|
+
encode: encode10,
|
|
2175
2199
|
checkPermission
|
|
2176
2200
|
},
|
|
2177
2201
|
{
|
|
2178
2202
|
id: "opencode",
|
|
2179
2203
|
installMode: "in-process",
|
|
2180
2204
|
projectSource: "spawn-cwd",
|
|
2181
|
-
toolNamePrefix:
|
|
2205
|
+
toolNamePrefix: TOOL_NAME_PREFIX,
|
|
2182
2206
|
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
2183
2207
|
execReadOnlyHint: false,
|
|
2184
2208
|
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
@@ -2191,13 +2215,13 @@ var ADAPTERS = Object.freeze([
|
|
|
2191
2215
|
hookChannel: { kind: "in-process", path: "opencode/plugin.js" },
|
|
2192
2216
|
skillChannel: { kind: "home-dir", path: ".config/opencode/skills" },
|
|
2193
2217
|
// ADR-0020
|
|
2194
|
-
decode
|
|
2195
|
-
encode
|
|
2218
|
+
decode,
|
|
2219
|
+
encode,
|
|
2196
2220
|
toCanonicalTool
|
|
2197
2221
|
}
|
|
2198
2222
|
]);
|
|
2199
2223
|
var BY_ID = new Map(ADAPTERS.map((r) => [r.id, r]));
|
|
2200
|
-
var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi"]);
|
|
2224
|
+
var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode"]);
|
|
2201
2225
|
function hasReplace(row5) {
|
|
2202
2226
|
return REPLACE_ROWS.has(row5.id);
|
|
2203
2227
|
}
|
|
@@ -2214,7 +2238,7 @@ function getAdapter(id2) {
|
|
|
2214
2238
|
}
|
|
2215
2239
|
|
|
2216
2240
|
// src/core/policy/decide.ts
|
|
2217
|
-
import { resolve as
|
|
2241
|
+
import { resolve as resolve5 } from "node:path";
|
|
2218
2242
|
|
|
2219
2243
|
// src/core/policy/lexer.ts
|
|
2220
2244
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -3668,7 +3692,15 @@ function resolveConfigDir(env) {
|
|
|
3668
3692
|
}
|
|
3669
3693
|
|
|
3670
3694
|
// src/core/policy/subagent.ts
|
|
3671
|
-
var { readFileSync: readFileSync2 } = process.getBuiltinModule("node:fs");
|
|
3695
|
+
var { readFileSync: readFileSync2, readdirSync: readdirSync2 } = process.getBuiltinModule("node:fs");
|
|
3696
|
+
var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments", "ArtifactData", "ArtifactCheck", "ExitPlanMode", "Edit", "Write", "NotebookEdit"]);
|
|
3697
|
+
var CLAUDE_CODE_BUILT_INS = Object.freeze({
|
|
3698
|
+
"general-purpose": { tools: null, disallowed: [] },
|
|
3699
|
+
fork: { tools: null, disallowed: [] },
|
|
3700
|
+
Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3701
|
+
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
|
|
3702
|
+
});
|
|
3703
|
+
var BUILT_IN_AGENT = "claude-code";
|
|
3672
3704
|
function isSubagentCall(ev) {
|
|
3673
3705
|
return ev.agentId !== void 0 && ev.agentId !== "";
|
|
3674
3706
|
}
|
|
@@ -3685,7 +3717,7 @@ function toolSetForAgentType(ev, src) {
|
|
|
3685
3717
|
const row5 = getAdapter(ev.agent);
|
|
3686
3718
|
if (src.manifestTools !== void 0) return unique(src.manifestTools.map((n) => norm(row5, n)));
|
|
3687
3719
|
const type = ev.agentType ?? "";
|
|
3688
|
-
const def = findDef(type, src);
|
|
3720
|
+
const def = findDef(type, src) ?? builtIn(ev.agent, type);
|
|
3689
3721
|
if (def === null) return null;
|
|
3690
3722
|
const tools = (def.tools ?? allKnownToolNames(row5)).map((n) => norm(row5, n));
|
|
3691
3723
|
const deny2 = def.disallowed.map((n) => norm(row5, n));
|
|
@@ -3713,6 +3745,11 @@ function findDef(type, src) {
|
|
|
3713
3745
|
}
|
|
3714
3746
|
return null;
|
|
3715
3747
|
}
|
|
3748
|
+
function builtIn(agent, type) {
|
|
3749
|
+
if (agent !== BUILT_IN_AGENT || !Object.prototype.hasOwnProperty.call(CLAUDE_CODE_BUILT_INS, type)) return null;
|
|
3750
|
+
const d = CLAUDE_CODE_BUILT_INS[type];
|
|
3751
|
+
return { tools: d.tools, disallowed: [...d.disallowed] };
|
|
3752
|
+
}
|
|
3716
3753
|
function safeType(type) {
|
|
3717
3754
|
if (type === "" || type === "." || type === "..") return false;
|
|
3718
3755
|
if (type.indexOf("/") >= 0 || type.indexOf("\\") >= 0) return false;
|
|
@@ -3727,6 +3764,9 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3727
3764
|
const plugin = type.slice(0, cut);
|
|
3728
3765
|
const agent = type.slice(cut + PLUGIN_AGENT_SEPARATOR.length);
|
|
3729
3766
|
if (agent.indexOf(PLUGIN_AGENT_SEPARATOR) >= 0) return null;
|
|
3767
|
+
return installedPluginAgent(claudeDir, plugin, agent) ?? syncedPluginAgent(claudeDir, plugin, agent);
|
|
3768
|
+
}
|
|
3769
|
+
function installedPluginAgent(claudeDir, plugin, agent) {
|
|
3730
3770
|
let parsed;
|
|
3731
3771
|
try {
|
|
3732
3772
|
parsed = JSON.parse(hostText(readFileSync2(join2(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE), "utf8")));
|
|
@@ -3749,6 +3789,21 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3749
3789
|
}
|
|
3750
3790
|
return null;
|
|
3751
3791
|
}
|
|
3792
|
+
function syncedPluginAgent(claudeDir, plugin, agent) {
|
|
3793
|
+
const root = join2(claudeDir, HOST_PLUGINS_DIR_NAME, SYNCED_PLUGINS_DIR_NAME);
|
|
3794
|
+
let ids;
|
|
3795
|
+
try {
|
|
3796
|
+
ids = readdirSync2(root).sort();
|
|
3797
|
+
} catch {
|
|
3798
|
+
return null;
|
|
3799
|
+
}
|
|
3800
|
+
for (const id2 of ids) {
|
|
3801
|
+
if (id2.startsWith(".")) continue;
|
|
3802
|
+
const d = readAgentFile(join2(root, id2, plugin, AGENTS_DIR_NAME, agent + AGENT_FILE_EXT));
|
|
3803
|
+
if (d !== null) return d;
|
|
3804
|
+
}
|
|
3805
|
+
return null;
|
|
3806
|
+
}
|
|
3752
3807
|
function readAgentFile(path8) {
|
|
3753
3808
|
let text;
|
|
3754
3809
|
try {
|
|
@@ -4163,10 +4218,10 @@ function READ_DENY_RANGE_MESSAGE(path8, size) {
|
|
|
4163
4218
|
}
|
|
4164
4219
|
|
|
4165
4220
|
// src/core/policy/own-file.ts
|
|
4166
|
-
import { extname, join as join5 } from "node:path";
|
|
4221
|
+
import { extname, join as join5, resolve as resolve4 } from "node:path";
|
|
4167
4222
|
|
|
4168
4223
|
// src/core/project/contain.ts
|
|
4169
|
-
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
4224
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join4, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
|
|
4170
4225
|
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4171
4226
|
function real(p) {
|
|
4172
4227
|
try {
|
|
@@ -4210,6 +4265,29 @@ function isInsideAny(roots, p) {
|
|
|
4210
4265
|
return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
|
|
4211
4266
|
});
|
|
4212
4267
|
}
|
|
4268
|
+
function hasParentStep(cwd, p) {
|
|
4269
|
+
const parts = isAbsolute2(p) ? components(p) : [...components(cwd), ...components(p)];
|
|
4270
|
+
return parts.includes("..");
|
|
4271
|
+
}
|
|
4272
|
+
var rootParts = /* @__PURE__ */ new Map();
|
|
4273
|
+
function lexicalRoot(root) {
|
|
4274
|
+
let rc = rootParts.get(root);
|
|
4275
|
+
if (rc === void 0) {
|
|
4276
|
+
rc = components(resolve3(root));
|
|
4277
|
+
rootParts.set(root, rc);
|
|
4278
|
+
}
|
|
4279
|
+
return rc;
|
|
4280
|
+
}
|
|
4281
|
+
function isLexicallyInsideAny(roots, p) {
|
|
4282
|
+
if (roots.length === 0) return false;
|
|
4283
|
+
const raw = components(p);
|
|
4284
|
+
if (raw.includes("..")) return false;
|
|
4285
|
+
const qc = sep2 === "/" && isAbsolute2(p) ? raw.filter((c) => c !== ".") : components(resolve3(p));
|
|
4286
|
+
return roots.some((root) => {
|
|
4287
|
+
const rc = lexicalRoot(root);
|
|
4288
|
+
return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
|
|
4289
|
+
});
|
|
4290
|
+
}
|
|
4213
4291
|
function commonRoot(paths) {
|
|
4214
4292
|
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
4215
4293
|
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
@@ -4250,9 +4328,11 @@ function ownDirsOf(agent, env) {
|
|
|
4250
4328
|
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
4329
|
return [...own2, shared];
|
|
4252
4330
|
}
|
|
4253
|
-
function isOwnFile(agent,
|
|
4254
|
-
if (extname(
|
|
4255
|
-
|
|
4331
|
+
function isOwnFile(agent, cwd, p, env = process.env) {
|
|
4332
|
+
if (extname(p).toLowerCase() !== AGENT_FILE_EXT) return false;
|
|
4333
|
+
const dirs = ownDirsOf(agent, env);
|
|
4334
|
+
const abs = resolve4(cwd, p);
|
|
4335
|
+
return !hasParentStep(cwd, p) && isLexicallyInsideAny(dirs, abs) || isInsideAny(dirs, abs);
|
|
4256
4336
|
}
|
|
4257
4337
|
|
|
4258
4338
|
// src/core/policy/read-media.ts
|
|
@@ -4343,7 +4423,7 @@ function readPaths(input) {
|
|
|
4343
4423
|
}
|
|
4344
4424
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
4345
4425
|
if (rules.length === 0) return null;
|
|
4346
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
4426
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve5(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
4347
4427
|
if (canonical === BASH) {
|
|
4348
4428
|
const cmd = str(input.command);
|
|
4349
4429
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -4480,8 +4560,9 @@ function fileSize(abs) {
|
|
|
4480
4560
|
return -1;
|
|
4481
4561
|
}
|
|
4482
4562
|
}
|
|
4483
|
-
function bigDeny(ev, row5,
|
|
4484
|
-
|
|
4563
|
+
function bigDeny(ev, row5, cwd, p, size, root) {
|
|
4564
|
+
const abs = resolve5(cwd, p);
|
|
4565
|
+
if (size <= OUTPUT_CAP || isOwnFile(ev.agent, cwd, p)) return null;
|
|
4485
4566
|
return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
|
|
4486
4567
|
}
|
|
4487
4568
|
function executeCanOpen(root, abs) {
|
|
@@ -4496,10 +4577,10 @@ function executeCanOpen(root, abs) {
|
|
|
4496
4577
|
function read(ev, row5, input, root) {
|
|
4497
4578
|
if (!present(input.offset) && !present(input.limit)) {
|
|
4498
4579
|
for (const p of readPaths(input)) {
|
|
4499
|
-
const abs =
|
|
4580
|
+
const abs = resolve5(ev.cwd, p);
|
|
4500
4581
|
const size = fileSize(abs);
|
|
4501
4582
|
if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
|
|
4502
|
-
const d = bigDeny(ev, row5,
|
|
4583
|
+
const d = bigDeny(ev, row5, ev.cwd, p, size, root);
|
|
4503
4584
|
if (d !== null) return d;
|
|
4504
4585
|
}
|
|
4505
4586
|
}
|
|
@@ -4512,7 +4593,7 @@ function shellDump(ev, cmds, row5, root) {
|
|
|
4512
4593
|
let verdict = null;
|
|
4513
4594
|
for (const c of cmds) {
|
|
4514
4595
|
const name = c.argv0.toLowerCase();
|
|
4515
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
4596
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve5(dir, c.args[0]);
|
|
4516
4597
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
4517
4598
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
4518
4599
|
const d = dumpTarget(name, c.args);
|
|
@@ -4521,8 +4602,8 @@ function shellDump(ev, cmds, row5, root) {
|
|
|
4521
4602
|
verdict = ALLOW;
|
|
4522
4603
|
continue;
|
|
4523
4604
|
}
|
|
4524
|
-
const abs =
|
|
4525
|
-
const big = bigDeny(ev, row5,
|
|
4605
|
+
const abs = resolve5(dir, d.file);
|
|
4606
|
+
const big = bigDeny(ev, row5, dir, d.file, fileSize(abs), root);
|
|
4526
4607
|
if (big !== null) return big;
|
|
4527
4608
|
}
|
|
4528
4609
|
return verdict;
|
|
@@ -4530,7 +4611,7 @@ function shellDump(ev, cmds, row5, root) {
|
|
|
4530
4611
|
function psShellDump(ev, cmd, row5, root) {
|
|
4531
4612
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
4532
4613
|
for (const abs of psDumpFiles(cmd, ev.cwd)) {
|
|
4533
|
-
const d = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
4614
|
+
const d = bigDeny(ev, row5, ev.cwd, abs, fileSize(abs), root);
|
|
4534
4615
|
if (d !== null) return d;
|
|
4535
4616
|
}
|
|
4536
4617
|
return null;
|
|
@@ -4592,7 +4673,7 @@ function dumpTarget(name, args) {
|
|
|
4592
4673
|
}
|
|
4593
4674
|
|
|
4594
4675
|
// src/core/project/resolve.ts
|
|
4595
|
-
import { basename as basename2, dirname as dirname3, join as join6, resolve as
|
|
4676
|
+
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
|
|
4596
4677
|
|
|
4597
4678
|
// src/core/project/sha256.ts
|
|
4598
4679
|
var K = new Uint32Array([
|
|
@@ -4757,7 +4838,7 @@ function gitDirs(dir) {
|
|
|
4757
4838
|
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
4758
4839
|
if (gitDir !== null) {
|
|
4759
4840
|
const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
|
|
4760
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
4841
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve6(gitDir, common)), worktree: cur, start };
|
|
4761
4842
|
}
|
|
4762
4843
|
const up = dirname3(cur);
|
|
4763
4844
|
if (up === cur) return { commonDir: null, start };
|
|
@@ -4772,7 +4853,7 @@ function gitDirAt(dotGit) {
|
|
|
4772
4853
|
} else {
|
|
4773
4854
|
const line = firstLine(dotGit);
|
|
4774
4855
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
4775
|
-
gitDir =
|
|
4856
|
+
gitDir = resolve6(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
4776
4857
|
}
|
|
4777
4858
|
} catch {
|
|
4778
4859
|
return null;
|
|
@@ -8835,7 +8916,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
8835
8916
|
}
|
|
8836
8917
|
|
|
8837
8918
|
// src/core/hooks/fallback.ts
|
|
8838
|
-
import { join as join7, resolve as
|
|
8919
|
+
import { join as join7, resolve as resolve7 } from "node:path";
|
|
8839
8920
|
var fs = process.getBuiltinModule("node:fs");
|
|
8840
8921
|
function isRec(v) {
|
|
8841
8922
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8958,20 +9039,26 @@ function bigFile(abs) {
|
|
|
8958
9039
|
function bigRead(agent, input, cwd) {
|
|
8959
9040
|
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
8960
9041
|
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(
|
|
9042
|
+
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve7(cwd, p)) && !isMediaRead(agent, resolve7(cwd, p)) && !isOwnFile(agent, cwd, p));
|
|
9043
|
+
}
|
|
9044
|
+
function allowOutput(agent) {
|
|
9045
|
+
try {
|
|
9046
|
+
return getAdapter(agent).encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
9047
|
+
} catch {
|
|
9048
|
+
return { stdout: "", exitCode: 0 };
|
|
9049
|
+
}
|
|
8962
9050
|
}
|
|
8963
9051
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
8964
9052
|
const row5 = getAdapter(agent);
|
|
8965
|
-
const allow = () => row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
8966
9053
|
try {
|
|
8967
|
-
if (!isRec(raw)) return
|
|
8968
|
-
if (!isPreTool(row5, firstString(raw, HOOK_FAIL_EVENT_KEYS))) return
|
|
9054
|
+
if (!isRec(raw)) return allowOutput(agent);
|
|
9055
|
+
if (!isPreTool(row5, firstString(raw, HOOK_FAIL_EVENT_KEYS))) return allowOutput(agent);
|
|
8969
9056
|
const name = firstString(raw, HOOK_FAIL_TOOL_KEYS);
|
|
8970
|
-
if (name === "" || name.includes(OWN_TOOL_PREFIX)) return
|
|
9057
|
+
if (name === "" || name.includes(OWN_TOOL_PREFIX)) return allowOutput(agent);
|
|
8971
9058
|
const kind = kindOf(row5, name);
|
|
8972
|
-
if (kind === null) return
|
|
9059
|
+
if (kind === null) return allowOutput(agent);
|
|
8973
9060
|
const cwd = firstString(raw, HOOK_FAIL_CWD_KEYS) || cwdFallback;
|
|
8974
|
-
if (kind === "read" && !bigRead(agent, inputOf(raw), cwd)) return
|
|
9061
|
+
if (kind === "read" && !bigRead(agent, inputOf(raw), cwd)) return allowOutput(agent);
|
|
8975
9062
|
const redirect = kind === "read" ? HOOK_FAIL_REDIRECT.read : HOOK_FAIL_REDIRECT[kind];
|
|
8976
9063
|
const reason = prefixToolNames(redirect, row5.toolNamePrefix) + "\n" + HOOK_FAIL_LINE(errorLabel(err), row5.toolNamePrefix);
|
|
8977
9064
|
return row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd, turn: 0 }, { kind: "deny", reason });
|
|
@@ -9003,12 +9090,20 @@ async function handleHook(agent, raw, env) {
|
|
|
9003
9090
|
return EMPTY5;
|
|
9004
9091
|
}
|
|
9005
9092
|
const row5 = getAdapter(agent);
|
|
9006
|
-
const
|
|
9093
|
+
const report2 = (stage, err, line) => {
|
|
9007
9094
|
logHookError(env, agent, stage, err);
|
|
9008
9095
|
process.stderr.write(line ?? "hooks: " + stage + " failed: " + message(err) + "\n");
|
|
9096
|
+
};
|
|
9097
|
+
const fail7 = (stage, err, line) => {
|
|
9098
|
+
report2(stage, err, line);
|
|
9009
9099
|
return failureOutput(agent, raw, err);
|
|
9010
9100
|
};
|
|
9011
|
-
if (nodeTooOld(process.version))
|
|
9101
|
+
if (nodeTooOld(process.version)) {
|
|
9102
|
+
const err = new CtxError("NODE_TOO_OLD", { v: process.version });
|
|
9103
|
+
if (row5.installMode === "in-process") return fail7("node", err);
|
|
9104
|
+
report2("node", err);
|
|
9105
|
+
return allowOutput(agent);
|
|
9106
|
+
}
|
|
9012
9107
|
let ev;
|
|
9013
9108
|
try {
|
|
9014
9109
|
fault(env, "decode");
|
|
@@ -9217,12 +9312,17 @@ function askDetached(ev, project, tool, text) {
|
|
|
9217
9312
|
process.stderr.write("hooks: decision write failed: " + message(err) + "\n");
|
|
9218
9313
|
});
|
|
9219
9314
|
}
|
|
9315
|
+
function toolSetSources(ev, project, env) {
|
|
9316
|
+
const src = { projectDir: project.worktree, env };
|
|
9317
|
+
if (ev.agentTools !== void 0) src.manifestTools = ev.agentTools;
|
|
9318
|
+
return src;
|
|
9319
|
+
}
|
|
9220
9320
|
async function preToolUse(ev, row5, project, env) {
|
|
9221
9321
|
const userDeny = readUserDeny(project.worktree, ev.agent);
|
|
9222
9322
|
const decision0 = decide(ev, row5, userDeny, project);
|
|
9223
9323
|
let decision = decision0;
|
|
9224
9324
|
if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
|
|
9225
|
-
const set3 = toolSetForAgentType(ev,
|
|
9325
|
+
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
9226
9326
|
const subCase = pickSubagentCase(ev, set3);
|
|
9227
9327
|
const tool = ev.tool;
|
|
9228
9328
|
const runs = set3 !== null || (ev.agentType ?? "") !== "" && hasReplace(row5);
|
|
@@ -9325,7 +9425,7 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9325
9425
|
function ownRead(ev, tool, env) {
|
|
9326
9426
|
if (!RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
9327
9427
|
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9328
|
-
return p !== void 0 && isOwnFile(ev.agent,
|
|
9428
|
+
return p !== void 0 && isOwnFile(ev.agent, ev.cwd, p, env);
|
|
9329
9429
|
}
|
|
9330
9430
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9331
9431
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
@@ -9334,14 +9434,21 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9334
9434
|
if (result.keep === true) return ALLOW2;
|
|
9335
9435
|
if (!hasReplace(row5)) return ALLOW2;
|
|
9336
9436
|
let label2;
|
|
9437
|
+
let caller = { ctx: true, shell: true, read: false };
|
|
9337
9438
|
if (isSubagentCall(ev)) {
|
|
9338
|
-
const
|
|
9339
|
-
|
|
9340
|
-
|
|
9439
|
+
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
9440
|
+
const subCase = pickSubagentCase(ev, set3);
|
|
9441
|
+
const has3 = (names) => set3 !== null && names.some((n) => set3.includes(n));
|
|
9442
|
+
caller = {
|
|
9443
|
+
ctx: subCase === "A",
|
|
9444
|
+
shell: has3(row5.nativeTools.shell),
|
|
9445
|
+
read: RANGE_READ_TOOLS.includes(tool.canonicalName) && has3(row5.nativeTools.read ?? [])
|
|
9446
|
+
};
|
|
9447
|
+
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9341
9448
|
} else {
|
|
9342
9449
|
label2 = mainLabel(tool, ev);
|
|
9343
9450
|
}
|
|
9344
|
-
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url].map(str2).find((v) => v.trim() !== "") ??
|
|
9451
|
+
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url, tool.name].map(str2).find((v) => v.trim() !== "") ?? tool.canonicalName;
|
|
9345
9452
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
9346
9453
|
const db = await openDb(project);
|
|
9347
9454
|
let sourceId;
|
|
@@ -9355,12 +9462,17 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9355
9462
|
const handle = sourceHandle(sourceId);
|
|
9356
9463
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
9357
9464
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
9358
|
-
const handleLine = REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text));
|
|
9465
|
+
const handleLine = caller.ctx ? REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text)) : SUBAGENT_HANDLE_LINE(handle, result.bytes, caller.read);
|
|
9359
9466
|
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
9467
|
+
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT ? searchTwin(handle, intent, project) : "");
|
|
9360
9468
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
9361
|
-
if (digest !== null) return { kind: "replace", output: replaceOutput(digest,
|
|
9469
|
+
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, pointer) };
|
|
9362
9470
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
9363
|
-
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text,
|
|
9471
|
+
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, pointer) : selected.text };
|
|
9472
|
+
}
|
|
9473
|
+
function searchTwin(handle, intent, project) {
|
|
9474
|
+
const terms = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "" : intent;
|
|
9475
|
+
return SEARCH_TWIN_LINE(join8(dirname4(process.argv[1] ?? ""), SEARCH_WRAPPER_FILE), handle, terms, project.worktree);
|
|
9364
9476
|
}
|
|
9365
9477
|
function boundedRead(tool) {
|
|
9366
9478
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
@@ -9374,7 +9486,7 @@ function replaceBudget(handleLine, more) {
|
|
|
9374
9486
|
function hostToolResult(file2, sessionId, env) {
|
|
9375
9487
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
9376
9488
|
const projects = join8(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
9377
|
-
const steps = relative3(projects,
|
|
9489
|
+
const steps = relative3(projects, resolve8(file2)).split(sep3);
|
|
9378
9490
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
9379
9491
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
9380
9492
|
const st = lstatSync2(file2);
|
|
@@ -20646,6 +20758,13 @@ function pathEntries(value, platform = process.platform, delimiter2 = platform =
|
|
|
20646
20758
|
const win = platform === "win32";
|
|
20647
20759
|
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
20648
20760
|
}
|
|
20761
|
+
function envValue(env, name, platform = process.platform) {
|
|
20762
|
+
const exact = env[name];
|
|
20763
|
+
if (exact !== void 0 || platform !== "win32") return exact;
|
|
20764
|
+
const upper = name.toUpperCase();
|
|
20765
|
+
const key = Object.keys(env).find((k) => k.toUpperCase() === upper);
|
|
20766
|
+
return key === void 0 ? void 0 : env[key];
|
|
20767
|
+
}
|
|
20649
20768
|
|
|
20650
20769
|
// src/core/sandbox/runtimes.ts
|
|
20651
20770
|
var PATHEXT_SEPARATOR = ";";
|
|
@@ -20689,8 +20808,8 @@ function isRunnable(full) {
|
|
|
20689
20808
|
}
|
|
20690
20809
|
function findRuntime(lang, env = process.env) {
|
|
20691
20810
|
if (isWin() && WIN_SHELL_LANGS.includes(lang)) return findGitBash(env);
|
|
20692
|
-
const dirs = pathEntries(env
|
|
20693
|
-
const pathExt = isWin() ? (env
|
|
20811
|
+
const dirs = pathEntries(envValue(env, "PATH") ?? "", process.platform, path.delimiter);
|
|
20812
|
+
const pathExt = isWin() ? (envValue(env, "PATHEXT") ?? PATHEXT_DEFAULT).split(PATHEXT_SEPARATOR).filter((e) => e !== "") : [];
|
|
20694
20813
|
const names = candidates(lang);
|
|
20695
20814
|
let shim = null;
|
|
20696
20815
|
for (const dir of dirs) {
|
|
@@ -20753,10 +20872,10 @@ function startArgv(argv) {
|
|
|
20753
20872
|
return sh === null ? null : [sh, ...argv];
|
|
20754
20873
|
}
|
|
20755
20874
|
function runProcess(argv, o) {
|
|
20756
|
-
return new Promise((
|
|
20875
|
+
return new Promise((resolve14) => {
|
|
20757
20876
|
const isWin2 = process.platform === "win32";
|
|
20758
20877
|
const start = startArgv(argv);
|
|
20759
|
-
if (start === null) return
|
|
20878
|
+
if (start === null) return resolve14(NOT_STARTED);
|
|
20760
20879
|
let child;
|
|
20761
20880
|
try {
|
|
20762
20881
|
child = spawn2(start[0], start.slice(1), {
|
|
@@ -20770,7 +20889,7 @@ function runProcess(argv, o) {
|
|
|
20770
20889
|
windowsHide: true
|
|
20771
20890
|
});
|
|
20772
20891
|
} catch {
|
|
20773
|
-
return
|
|
20892
|
+
return resolve14(NOT_STARTED);
|
|
20774
20893
|
}
|
|
20775
20894
|
const stdoutChunks = [];
|
|
20776
20895
|
const stderrChunks = [];
|
|
@@ -20804,7 +20923,7 @@ function runProcess(argv, o) {
|
|
|
20804
20923
|
clearTimeout(drainTimer);
|
|
20805
20924
|
clearTimeout(stopTimer);
|
|
20806
20925
|
o.signal.removeEventListener("abort", onAbort);
|
|
20807
|
-
|
|
20926
|
+
resolve14({
|
|
20808
20927
|
stdout: Buffer.concat(stdoutChunks),
|
|
20809
20928
|
stderr: Buffer.concat(stderrChunks),
|
|
20810
20929
|
exitCode,
|
|
@@ -20851,7 +20970,7 @@ function runProcess(argv, o) {
|
|
|
20851
20970
|
}
|
|
20852
20971
|
|
|
20853
20972
|
// src/core/index/auto-memory.ts
|
|
20854
|
-
import { readdirSync as
|
|
20973
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
|
|
20855
20974
|
import { join as join9 } from "node:path";
|
|
20856
20975
|
var MEMORY_FILES = Object.freeze([
|
|
20857
20976
|
Object.freeze(["CLAUDE.md"]),
|
|
@@ -20866,7 +20985,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20866
20985
|
var MD = ".md";
|
|
20867
20986
|
function steeringFiles(worktree) {
|
|
20868
20987
|
try {
|
|
20869
|
-
return
|
|
20988
|
+
return readdirSync3(join9(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20870
20989
|
} catch {
|
|
20871
20990
|
return [];
|
|
20872
20991
|
}
|
|
@@ -21197,12 +21316,16 @@ function answer(db, input, scope, ctx, nm, ms, indexed, sort, pick2) {
|
|
|
21197
21316
|
}
|
|
21198
21317
|
async function handler(input, ctx) {
|
|
21199
21318
|
const sort = input.sort ?? "relevance";
|
|
21200
|
-
if (sort === "timeline" && input.offset !==
|
|
21319
|
+
if (sort === "timeline" && (input.offset ?? 0) !== 0) {
|
|
21201
21320
|
return invalid("offset", 'drop offset; page a timeline with "after"');
|
|
21202
21321
|
}
|
|
21203
|
-
if (sort === "relevance" && input.after !==
|
|
21322
|
+
if (sort === "relevance" && (input.after ?? 0) !== 0) {
|
|
21204
21323
|
return invalid("after", 'drop after, or pass sort:"timeline"');
|
|
21205
21324
|
}
|
|
21325
|
+
if (input.source !== void 0 && input.source.trim() === "") {
|
|
21326
|
+
const { source: _blank, ...rest } = input;
|
|
21327
|
+
input = rest;
|
|
21328
|
+
}
|
|
21206
21329
|
const scope = input.scope ?? "worktree";
|
|
21207
21330
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
21208
21331
|
try {
|
|
@@ -21456,7 +21579,7 @@ var ctxBatch = Object.freeze({
|
|
|
21456
21579
|
});
|
|
21457
21580
|
|
|
21458
21581
|
// src/core/tools/doctor.ts
|
|
21459
|
-
import { readdirSync as
|
|
21582
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync16, existsSync as existsSync16 } from "node:fs";
|
|
21460
21583
|
import { basename as basename5, join as join19 } from "node:path";
|
|
21461
21584
|
|
|
21462
21585
|
// src/core/ops/bundle-dir.ts
|
|
@@ -21482,11 +21605,11 @@ function ownBundleDir() {
|
|
|
21482
21605
|
}
|
|
21483
21606
|
|
|
21484
21607
|
// src/core/ops/doctor-config.ts
|
|
21485
|
-
import { existsSync as existsSync9, readdirSync as
|
|
21486
|
-
import { dirname as dirname8, join as join14 } from "node:path";
|
|
21608
|
+
import { existsSync as existsSync9, readdirSync as readdirSync6, readFileSync as readFileSync11 } from "node:fs";
|
|
21609
|
+
import { dirname as dirname8, isAbsolute as isAbsolute4, join as join14, resolve as resolve9 } from "node:path";
|
|
21487
21610
|
|
|
21488
21611
|
// src/core/ops/detect-v1.ts
|
|
21489
|
-
import { existsSync as existsSync6, opendirSync, readdirSync as
|
|
21612
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync8 } from "node:fs";
|
|
21490
21613
|
import { tmpdir } from "node:os";
|
|
21491
21614
|
import { join as join12 } from "node:path";
|
|
21492
21615
|
|
|
@@ -24146,7 +24269,7 @@ function flatCommands(events, prefix) {
|
|
|
24146
24269
|
return out;
|
|
24147
24270
|
}
|
|
24148
24271
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
24149
|
-
var isCodexScript = (cmd) =>
|
|
24272
|
+
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
24273
|
function dataDir(dir, reason, out) {
|
|
24151
24274
|
if (existsSync6(dir)) out.push(finding(dir, "", reason));
|
|
24152
24275
|
}
|
|
@@ -24194,8 +24317,7 @@ function scanCodex(agentHome, out) {
|
|
|
24194
24317
|
const config2 = readTomlValue(tomlFile);
|
|
24195
24318
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
24196
24319
|
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;
|
|
24320
|
+
if (isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
|
|
24199
24321
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
24200
24322
|
}
|
|
24201
24323
|
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
@@ -24224,7 +24346,7 @@ function scanVscode(agentHome, project, out) {
|
|
|
24224
24346
|
}
|
|
24225
24347
|
function jsonFiles(dir) {
|
|
24226
24348
|
try {
|
|
24227
|
-
return
|
|
24349
|
+
return readdirSync4(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
24228
24350
|
} catch {
|
|
24229
24351
|
return [];
|
|
24230
24352
|
}
|
|
@@ -24357,8 +24479,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24357
24479
|
}
|
|
24358
24480
|
|
|
24359
24481
|
// src/core/ops/plugin-root.ts
|
|
24360
|
-
import { existsSync as existsSync7, readdirSync as
|
|
24361
|
-
import { dirname as dirname7, isAbsolute as
|
|
24482
|
+
import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
|
|
24483
|
+
import { dirname as dirname7, isAbsolute as isAbsolute3, join as join13, sep as sep4 } from "node:path";
|
|
24362
24484
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24363
24485
|
function missing(agent, path8) {
|
|
24364
24486
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24457,7 +24579,7 @@ function marketplaceRoot(adapter, env, worktree) {
|
|
|
24457
24579
|
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join13(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24458
24580
|
const pattern = join13(cache, "*", PLUGIN_NAME);
|
|
24459
24581
|
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24460
|
-
const found =
|
|
24582
|
+
const found = readdirSync5(cache).sort().map((marketplace) => join13(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24461
24583
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24462
24584
|
return found[0];
|
|
24463
24585
|
}
|
|
@@ -24470,7 +24592,7 @@ function configEntryRoot(adapter, env) {
|
|
|
24470
24592
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24471
24593
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
24472
24594
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
24473
|
-
if (typeof script !== "string" || !
|
|
24595
|
+
if (typeof script !== "string" || !isAbsolute3(script)) throw missing(adapter.id, file2);
|
|
24474
24596
|
return dirname7(script);
|
|
24475
24597
|
}
|
|
24476
24598
|
function candidate(adapter, env, worktree) {
|
|
@@ -24669,10 +24791,10 @@ function codexNativeDir(env, home) {
|
|
|
24669
24791
|
const cache = join14(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24670
24792
|
if (!existsSync9(cache)) return null;
|
|
24671
24793
|
const found = [];
|
|
24672
|
-
for (const market of
|
|
24794
|
+
for (const market of readdirSync6(cache)) {
|
|
24673
24795
|
const plugin = join14(cache, market, SERVER_KEY);
|
|
24674
24796
|
if (!existsSync9(plugin)) continue;
|
|
24675
|
-
for (const version2 of
|
|
24797
|
+
for (const version2 of readdirSync6(plugin).sort()) {
|
|
24676
24798
|
const dir = join14(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24677
24799
|
if (existsSync9(join14(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24678
24800
|
}
|
|
@@ -24690,11 +24812,122 @@ function nativeMcpWrong(dir, row5) {
|
|
|
24690
24812
|
return true;
|
|
24691
24813
|
}
|
|
24692
24814
|
}
|
|
24815
|
+
function opencodeEntrySpec(entry) {
|
|
24816
|
+
return isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : Array.isArray(entry) ? entry[0] : entry;
|
|
24817
|
+
}
|
|
24818
|
+
function isNativeOpencodeEntry(entry, key) {
|
|
24819
|
+
const spec = opencodeEntrySpec(entry);
|
|
24820
|
+
if (typeof spec !== "string") return false;
|
|
24821
|
+
return spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
24822
|
+
}
|
|
24693
24823
|
function isOwnOpencodeEntry(entry, key, own2) {
|
|
24694
|
-
const spec =
|
|
24824
|
+
const spec = opencodeEntrySpec(entry);
|
|
24695
24825
|
if (typeof spec !== "string") return false;
|
|
24696
|
-
|
|
24697
|
-
|
|
24826
|
+
return spec === OPENCODE_GIT_SPEC || own2.includes(spec) || isNativeOpencodeEntry(entry, key);
|
|
24827
|
+
}
|
|
24828
|
+
function stringLiterals(src) {
|
|
24829
|
+
const out = [];
|
|
24830
|
+
let i = 0;
|
|
24831
|
+
while (i < src.length) {
|
|
24832
|
+
const c = src[i];
|
|
24833
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
24834
|
+
const n = src.indexOf("\n", i);
|
|
24835
|
+
i = n < 0 ? src.length : n;
|
|
24836
|
+
continue;
|
|
24837
|
+
}
|
|
24838
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
24839
|
+
const n = src.indexOf("*/", i + 2);
|
|
24840
|
+
i = n < 0 ? src.length : n + 2;
|
|
24841
|
+
continue;
|
|
24842
|
+
}
|
|
24843
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
24844
|
+
let j = i + 1;
|
|
24845
|
+
let s = "";
|
|
24846
|
+
while (j < src.length && src[j] !== c) {
|
|
24847
|
+
if (src[j] === "\\") {
|
|
24848
|
+
s += src[j + 1] ?? "";
|
|
24849
|
+
j += 2;
|
|
24850
|
+
continue;
|
|
24851
|
+
}
|
|
24852
|
+
s += src[j];
|
|
24853
|
+
j++;
|
|
24854
|
+
}
|
|
24855
|
+
out.push(s);
|
|
24856
|
+
i = j + 1;
|
|
24857
|
+
continue;
|
|
24858
|
+
}
|
|
24859
|
+
i++;
|
|
24860
|
+
}
|
|
24861
|
+
return out;
|
|
24862
|
+
}
|
|
24863
|
+
var OPENCODE_PLUGINS_DIR = "plugins";
|
|
24864
|
+
var OPENCODE_PROJECT_DIR = ".opencode";
|
|
24865
|
+
var OPENCODE_PLUGIN_EXTS = [".js", ".mjs", ".ts"];
|
|
24866
|
+
var OPENCODE_PLUGIN_INDEX = "index";
|
|
24867
|
+
var OPENCODE_DIR_FILE_MAX = 64 * 1024;
|
|
24868
|
+
var OWN_PLUGIN_MODULES = [SERVER_KEY, `${SERVER_KEY}/server`];
|
|
24869
|
+
var FILE_URL_PREFIX = "file://";
|
|
24870
|
+
var NODE_MODULES_DIR = "node_modules";
|
|
24871
|
+
var PACKAGE_JSON_FILE = "package.json";
|
|
24872
|
+
var OPENCODE_PACKAGE_DIR_HINT = `${NODE_MODULES_DIR}/${SERVER_KEY}`;
|
|
24873
|
+
function opencodePluginDirs(configDir, worktree) {
|
|
24874
|
+
return [configDir, opencodeProjectDir(worktree)];
|
|
24875
|
+
}
|
|
24876
|
+
function opencodeProjectDir(worktree) {
|
|
24877
|
+
return join14(worktree, OPENCODE_PROJECT_DIR);
|
|
24878
|
+
}
|
|
24879
|
+
function packageResolves(fromDir) {
|
|
24880
|
+
for (let d = fromDir; ; d = dirname8(d)) {
|
|
24881
|
+
if (existsSync9(join14(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
24882
|
+
if (dirname8(d) === d) return false;
|
|
24883
|
+
}
|
|
24884
|
+
}
|
|
24885
|
+
function opencodeDirPlugins(dirs) {
|
|
24886
|
+
const bundle = opencodePluginFile();
|
|
24887
|
+
const ownFile = join14(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
24888
|
+
const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
|
|
24889
|
+
const isPath = (p) => {
|
|
24890
|
+
if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
24891
|
+
const seg = p.split("/");
|
|
24892
|
+
const n = seg.length;
|
|
24893
|
+
return n >= 3 && seg[n - 1] === "plugin.js" && seg[n - 2] === "opencode" && seg[n - 3] === SERVER_KEY;
|
|
24894
|
+
};
|
|
24895
|
+
const out = [];
|
|
24896
|
+
for (const dir of dirs) {
|
|
24897
|
+
const pdir = join14(dir, OPENCODE_PLUGINS_DIR);
|
|
24898
|
+
let names;
|
|
24899
|
+
try {
|
|
24900
|
+
names = readdirSync6(pdir);
|
|
24901
|
+
} catch {
|
|
24902
|
+
continue;
|
|
24903
|
+
}
|
|
24904
|
+
for (const name of names) {
|
|
24905
|
+
const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join14(pdir, name)] : [];
|
|
24906
|
+
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join14(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
|
|
24907
|
+
for (const f of files) {
|
|
24908
|
+
let text;
|
|
24909
|
+
try {
|
|
24910
|
+
const b = readFileSync11(f);
|
|
24911
|
+
if (b.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
24912
|
+
text = b.toString("utf8");
|
|
24913
|
+
} catch {
|
|
24914
|
+
continue;
|
|
24915
|
+
}
|
|
24916
|
+
const lits = stringLiterals(text).map((s) => s.split("\\").join("/")).filter((p) => isModule(p) || isPath(p));
|
|
24917
|
+
if (!lits.length) continue;
|
|
24918
|
+
const loads = lits.some((p) => {
|
|
24919
|
+
if (isModule(p)) return packageResolves(dirname8(f));
|
|
24920
|
+
const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
|
|
24921
|
+
return existsSync9(isAbsolute4(bare2) ? bare2 : resolve9(dirname8(f), bare2));
|
|
24922
|
+
});
|
|
24923
|
+
out.push({ file: f, loads });
|
|
24924
|
+
}
|
|
24925
|
+
}
|
|
24926
|
+
}
|
|
24927
|
+
return out;
|
|
24928
|
+
}
|
|
24929
|
+
function opencodeDirPlugin(dirs) {
|
|
24930
|
+
return opencodeDirPlugins(dirs).find((p) => p.loads)?.file;
|
|
24698
24931
|
}
|
|
24699
24932
|
function opencodeMcpOwn(entry) {
|
|
24700
24933
|
if (!isObject4(entry)) return false;
|
|
@@ -24715,7 +24948,8 @@ function opencodeValueListed(value) {
|
|
|
24715
24948
|
}
|
|
24716
24949
|
function opencodeListed(file2, worktree) {
|
|
24717
24950
|
const dirs = [dirname8(file2), worktree];
|
|
24718
|
-
|
|
24951
|
+
if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join14(dir, name)))))) return true;
|
|
24952
|
+
return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
|
|
24719
24953
|
}
|
|
24720
24954
|
function mcpWrong(row5, home, env, worktree) {
|
|
24721
24955
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
@@ -24938,7 +25172,7 @@ async function checkIndex(project) {
|
|
|
24938
25172
|
|
|
24939
25173
|
// src/core/ops/doctor-env.ts
|
|
24940
25174
|
import { existsSync as existsSync11, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
24941
|
-
import { isAbsolute as
|
|
25175
|
+
import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
|
|
24942
25176
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24943
25177
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24944
25178
|
}
|
|
@@ -25107,7 +25341,7 @@ function checkMcp(ctx, adapter) {
|
|
|
25107
25341
|
function piCwdInside(worktree, piCwd) {
|
|
25108
25342
|
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
25109
25343
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
25110
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
25344
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
|
|
25111
25345
|
}
|
|
25112
25346
|
function checkProject(i) {
|
|
25113
25347
|
const bad = fail4("D7", D7_DETAIL(i.project.source), D7_FIX);
|
|
@@ -26891,7 +27125,7 @@ function hasType(v, t) {
|
|
|
26891
27125
|
function same(a, b) {
|
|
26892
27126
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
26893
27127
|
}
|
|
26894
|
-
function
|
|
27128
|
+
function resolve10(root, ref) {
|
|
26895
27129
|
const parts = ref.split("/");
|
|
26896
27130
|
if (parts[0] !== "#") throw new Error(`hook-shape: only local $ref is read, got ${ref}`);
|
|
26897
27131
|
let at2 = root;
|
|
@@ -26904,7 +27138,7 @@ function shapeErrors(schema, value, root = schema, at2 = "$") {
|
|
|
26904
27138
|
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
27139
|
}
|
|
26906
27140
|
const errs = [];
|
|
26907
|
-
if (typeof schema.$ref === "string") errs.push(...shapeErrors(
|
|
27141
|
+
if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve10(root, schema.$ref), value, root, at2));
|
|
26908
27142
|
if (Array.isArray(schema.allOf)) for (const s of schema.allOf) errs.push(...shapeErrors(s, value, root, at2));
|
|
26909
27143
|
if (schema.type !== void 0) {
|
|
26910
27144
|
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
@@ -26966,7 +27200,7 @@ var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
|
26966
27200
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
26967
27201
|
var DEFAULT_COMSPEC = "cmd.exe";
|
|
26968
27202
|
function envGet(env, k) {
|
|
26969
|
-
return
|
|
27203
|
+
return envValue(env, k, "win32");
|
|
26970
27204
|
}
|
|
26971
27205
|
function whichBin(bin, env, platform = process.platform) {
|
|
26972
27206
|
const get = (k) => envGet(env, k);
|
|
@@ -27071,14 +27305,14 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
27071
27305
|
function askPluginHooks(env, pluginId, cwd) {
|
|
27072
27306
|
const bin = whichBin("codex", env);
|
|
27073
27307
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
27074
|
-
return new Promise((
|
|
27308
|
+
return new Promise((resolve14) => {
|
|
27075
27309
|
let asked;
|
|
27076
27310
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
27077
27311
|
let f;
|
|
27078
27312
|
try {
|
|
27079
27313
|
f = spawnForm(bin, ["app-server"], env);
|
|
27080
27314
|
} catch {
|
|
27081
|
-
|
|
27315
|
+
resolve14({ kind: "silent" });
|
|
27082
27316
|
return;
|
|
27083
27317
|
}
|
|
27084
27318
|
const child = spawn3(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -27088,7 +27322,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
27088
27322
|
let result;
|
|
27089
27323
|
const settle = () => {
|
|
27090
27324
|
clearTimeout(grace);
|
|
27091
|
-
|
|
27325
|
+
resolve14(done_(result));
|
|
27092
27326
|
};
|
|
27093
27327
|
let grace;
|
|
27094
27328
|
const finish2 = (v) => {
|
|
@@ -27451,7 +27685,7 @@ import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4
|
|
|
27451
27685
|
import { basename as basename4, dirname as dirname9, join as join17 } from "node:path";
|
|
27452
27686
|
|
|
27453
27687
|
// src/core/store/owners.ts
|
|
27454
|
-
import { mkdirSync as mkdirSync5, readdirSync as
|
|
27688
|
+
import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as readFileSync14, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27455
27689
|
import { basename as basename3, join as join16 } from "node:path";
|
|
27456
27690
|
function ownersDir(configDir, projectKey) {
|
|
27457
27691
|
return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -27474,7 +27708,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27474
27708
|
const dir = ownersDir(configDir, projectKey);
|
|
27475
27709
|
let names;
|
|
27476
27710
|
try {
|
|
27477
|
-
names =
|
|
27711
|
+
names = readdirSync7(dir);
|
|
27478
27712
|
} catch (err) {
|
|
27479
27713
|
if (errCode2(err) === "ENOENT") return [];
|
|
27480
27714
|
throw err;
|
|
@@ -27709,7 +27943,7 @@ function gitVersion(env) {
|
|
|
27709
27943
|
function onPath(env, tool) {
|
|
27710
27944
|
const names = process.platform === "win32" ? [tool + EXE_SUFFIX, tool + ".cmd", tool] : [tool];
|
|
27711
27945
|
const out = [];
|
|
27712
|
-
for (const dir of (env
|
|
27946
|
+
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
27713
27947
|
if (dir === "") continue;
|
|
27714
27948
|
for (const n of names) if (existsSync15(join18(dir, n))) {
|
|
27715
27949
|
out.push(join18(dir, n));
|
|
@@ -27910,7 +28144,7 @@ async function hookRow(ctx, adapter, host) {
|
|
|
27910
28144
|
function ownServerId(configDir, projectKey) {
|
|
27911
28145
|
const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27912
28146
|
if (!existsSync16(dir)) return "";
|
|
27913
|
-
for (const name of
|
|
28147
|
+
for (const name of readdirSync8(dir)) {
|
|
27914
28148
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27915
28149
|
if (readFileSync16(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
27916
28150
|
}
|
|
@@ -28012,7 +28246,7 @@ var ctxDoctor = Object.freeze({
|
|
|
28012
28246
|
// src/core/tools/execute.ts
|
|
28013
28247
|
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28014
28248
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
28015
|
-
import { dirname as dirname11, join as join20, parse as parse3, resolve as
|
|
28249
|
+
import { dirname as dirname11, join as join20, parse as parse3, resolve as resolve11 } from "node:path";
|
|
28016
28250
|
|
|
28017
28251
|
// src/core/sandbox/win-build.ts
|
|
28018
28252
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -28159,7 +28393,7 @@ async function handler3(raw, ctx) {
|
|
|
28159
28393
|
const cwd = ctx.project.worktree;
|
|
28160
28394
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
28161
28395
|
if (input.file !== void 0) {
|
|
28162
|
-
const abs =
|
|
28396
|
+
const abs = resolve11(cwd, input.file);
|
|
28163
28397
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
28164
28398
|
if (bad !== null) return fail5(bad);
|
|
28165
28399
|
extra.CTX_FILE = abs;
|
|
@@ -28214,10 +28448,10 @@ var ctxExecute = {
|
|
|
28214
28448
|
|
|
28215
28449
|
// src/core/tools/index.ts
|
|
28216
28450
|
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
|
|
28451
|
+
import { dirname as dirname12, extname as extname3, join as join22, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28218
28452
|
|
|
28219
28453
|
// src/core/index/walk.ts
|
|
28220
|
-
import { readdirSync as
|
|
28454
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync17, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
28221
28455
|
import { join as join21 } from "node:path";
|
|
28222
28456
|
var GITIGNORE = ".gitignore";
|
|
28223
28457
|
var GIT_DIR = ".git";
|
|
@@ -28232,7 +28466,7 @@ function walkDir(root, containmentRoot) {
|
|
|
28232
28466
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28233
28467
|
let entries;
|
|
28234
28468
|
try {
|
|
28235
|
-
entries =
|
|
28469
|
+
entries = readdirSync9(abs, { withFileTypes: true });
|
|
28236
28470
|
} catch {
|
|
28237
28471
|
return;
|
|
28238
28472
|
}
|
|
@@ -28425,15 +28659,15 @@ function parseUrl(raw) {
|
|
|
28425
28659
|
if (u.protocol !== "http:" && u.protocol !== "https:") throw fail6("ERR_INVALID_PROTOCOL");
|
|
28426
28660
|
return u;
|
|
28427
28661
|
}
|
|
28428
|
-
function
|
|
28662
|
+
function envValue2(upper) {
|
|
28429
28663
|
const v = process.env[upper] ?? process.env[upper.toLowerCase()];
|
|
28430
28664
|
return v === void 0 || v.trim() === "" ? void 0 : v.trim();
|
|
28431
28665
|
}
|
|
28432
28666
|
function pickProxy(u) {
|
|
28433
|
-
const raw =
|
|
28667
|
+
const raw = envValue2(u.protocol === "https:" ? "HTTPS_PROXY" : "HTTP_PROXY");
|
|
28434
28668
|
if (raw === void 0) return void 0;
|
|
28435
28669
|
const host = bare(u.hostname).toLowerCase();
|
|
28436
|
-
for (const item of (
|
|
28670
|
+
for (const item of (envValue2("NO_PROXY") ?? "").split(",")) {
|
|
28437
28671
|
let entry = item.trim().toLowerCase();
|
|
28438
28672
|
if (entry.startsWith(".")) entry = entry.slice(1);
|
|
28439
28673
|
if (entry !== "" && (host === entry || host.endsWith("." + entry))) return void 0;
|
|
@@ -28501,18 +28735,18 @@ function request(u, conn, proxy, signal) {
|
|
|
28501
28735
|
const host = bare(u.hostname);
|
|
28502
28736
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
28503
28737
|
const path8 = u.pathname + u.search;
|
|
28504
|
-
return new Promise((
|
|
28738
|
+
return new Promise((resolve14, reject) => {
|
|
28505
28739
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
28506
28740
|
if (proxy === void 0) {
|
|
28507
28741
|
const mod = u.protocol === "https:" ? https : http;
|
|
28508
28742
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
28509
|
-
req.on("response",
|
|
28743
|
+
req.on("response", resolve14).on("error", onErr).end();
|
|
28510
28744
|
return;
|
|
28511
28745
|
}
|
|
28512
28746
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
28513
28747
|
if (u.protocol === "http:") {
|
|
28514
28748
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
28515
|
-
req.on("response",
|
|
28749
|
+
req.on("response", resolve14).on("error", onErr).end();
|
|
28516
28750
|
return;
|
|
28517
28751
|
}
|
|
28518
28752
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -28532,16 +28766,16 @@ function request(u, conn, proxy, signal) {
|
|
|
28532
28766
|
headers: { host: u.host },
|
|
28533
28767
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
28534
28768
|
});
|
|
28535
|
-
req.on("response",
|
|
28769
|
+
req.on("response", resolve14).on("error", onErr).end();
|
|
28536
28770
|
});
|
|
28537
28771
|
tunnel.end();
|
|
28538
28772
|
});
|
|
28539
28773
|
}
|
|
28540
28774
|
function readBody(res) {
|
|
28541
|
-
return new Promise((
|
|
28775
|
+
return new Promise((resolve14, reject) => {
|
|
28542
28776
|
const parts = [];
|
|
28543
28777
|
res.on("data", (b) => parts.push(b));
|
|
28544
|
-
res.on("end", () =>
|
|
28778
|
+
res.on("end", () => resolve14(Buffer.concat(parts)));
|
|
28545
28779
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
28546
28780
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
28547
28781
|
});
|
|
@@ -32419,7 +32653,7 @@ function missingOrOutside(given, abs, root) {
|
|
|
32419
32653
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
32420
32654
|
}
|
|
32421
32655
|
function pathItems(input, project) {
|
|
32422
|
-
const abs =
|
|
32656
|
+
const abs = resolve12(project.worktree, input.path);
|
|
32423
32657
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
32424
32658
|
const base = relative5(project.worktree, abs);
|
|
32425
32659
|
if (statSync8(abs).isDirectory()) {
|
|
@@ -32591,7 +32825,8 @@ function reply3(text, isError) {
|
|
|
32591
32825
|
return { text, isError, sandboxBytes: 0 };
|
|
32592
32826
|
}
|
|
32593
32827
|
async function handler6(input, ctx) {
|
|
32594
|
-
const
|
|
32828
|
+
const given = input.session !== void 0 && input.session.trim() !== "" ? input.session : void 0;
|
|
32829
|
+
const sessionId = given ?? ctx.sessionId;
|
|
32595
32830
|
if (sessionId === "") return reply3(RESUME_NO_SESSION_LINE, true);
|
|
32596
32831
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
32597
32832
|
try {
|
|
@@ -33034,7 +33269,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33034
33269
|
}
|
|
33035
33270
|
|
|
33036
33271
|
// src/core/ops/uninstall.ts
|
|
33037
|
-
import { existsSync as existsSync20, readdirSync as
|
|
33272
|
+
import { existsSync as existsSync20, readdirSync as readdirSync10, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33038
33273
|
import { join as join24 } from "node:path";
|
|
33039
33274
|
function row2(area, before, after) {
|
|
33040
33275
|
return { area, before, after };
|
|
@@ -33150,7 +33385,7 @@ function removeProjectData(configDir, projectKey) {
|
|
|
33150
33385
|
const dir = join24(projects, projectKey);
|
|
33151
33386
|
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33152
33387
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33153
|
-
for (const name of
|
|
33388
|
+
for (const name of readdirSync10(dir)) {
|
|
33154
33389
|
if (name !== OWNERS_DIR_NAME) rmSync6(join24(dir, name), { recursive: true, force: true });
|
|
33155
33390
|
}
|
|
33156
33391
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
@@ -33424,7 +33659,7 @@ function checkCall(tool, input) {
|
|
|
33424
33659
|
}
|
|
33425
33660
|
|
|
33426
33661
|
// src/entries/opencode.ts
|
|
33427
|
-
import { resolve as
|
|
33662
|
+
import { resolve as resolve13 } from "node:path";
|
|
33428
33663
|
var AGENT = "opencode";
|
|
33429
33664
|
var slash = (p) => p.replaceAll("\\", "/");
|
|
33430
33665
|
function shellRequest(commands) {
|
|
@@ -33441,7 +33676,7 @@ function permissionRequests(tool, input, base) {
|
|
|
33441
33676
|
const str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
33442
33677
|
const out = [];
|
|
33443
33678
|
const read3 = (p) => {
|
|
33444
|
-
const abs = slash(
|
|
33679
|
+
const abs = slash(resolve13(base, p));
|
|
33445
33680
|
return { action: OC_READ_ACTION, resources: [abs], save: [abs] };
|
|
33446
33681
|
};
|
|
33447
33682
|
if (tool === "ctx_execute") {
|
|
@@ -33552,15 +33787,18 @@ async function setupLegacy(app) {
|
|
|
33552
33787
|
tool: input.tool,
|
|
33553
33788
|
callID: input.callID,
|
|
33554
33789
|
args: output.args,
|
|
33790
|
+
agentID: input.agentID,
|
|
33791
|
+
agentTools: input.agentTools,
|
|
33555
33792
|
turn: turnOf(sessionId)
|
|
33556
33793
|
});
|
|
33557
33794
|
if (out.exitCode === 2) throw new Error(out.stdout);
|
|
33558
33795
|
},
|
|
33559
|
-
// §4.5
|
|
33796
|
+
// §4.5 step 3, case C: a replace comes back as stdout and is written into output.output in-process. OpenCode 1.19
|
|
33797
|
+
// returns this same object to the model after the trigger; the 2.x bridge copies it into result.content (#1347).
|
|
33560
33798
|
"tool.execute.after": async (input, output) => {
|
|
33561
33799
|
const sessionId = input.sessionID ?? "";
|
|
33562
33800
|
await payloadFor2(sessionId);
|
|
33563
|
-
await call({
|
|
33801
|
+
const out = await call({
|
|
33564
33802
|
type: "execute.after",
|
|
33565
33803
|
sessionID: sessionId,
|
|
33566
33804
|
tool: input.tool,
|
|
@@ -33568,8 +33806,11 @@ async function setupLegacy(app) {
|
|
|
33568
33806
|
args: input.args,
|
|
33569
33807
|
output: output.output,
|
|
33570
33808
|
isError: output.isError,
|
|
33809
|
+
agentID: input.agentID,
|
|
33810
|
+
agentTools: input.agentTools,
|
|
33571
33811
|
turn: turnOf(sessionId)
|
|
33572
33812
|
});
|
|
33813
|
+
if (out.stdout !== "") output.output = out.stdout;
|
|
33573
33814
|
},
|
|
33574
33815
|
// §4.6: one system entry per session, the same bytes on every request (#1085, Q12). A second
|
|
33575
33816
|
// transform on the same array finds the entry and adds nothing.
|
|
@@ -33595,6 +33836,47 @@ function oc2Text(content) {
|
|
|
33595
33836
|
if (typeof content === "string") return content;
|
|
33596
33837
|
return (content ?? []).filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n");
|
|
33597
33838
|
}
|
|
33839
|
+
function wildcard(pattern, text) {
|
|
33840
|
+
let row5 = new Uint8Array(text.length + 1);
|
|
33841
|
+
row5[0] = 1;
|
|
33842
|
+
for (const c of pattern) {
|
|
33843
|
+
const next = new Uint8Array(text.length + 1);
|
|
33844
|
+
for (let j = 0; j <= text.length; j++) {
|
|
33845
|
+
if (c === "*") next[j] = row5[j] === 1 || j > 0 && next[j - 1] === 1 ? 1 : 0;
|
|
33846
|
+
else if (j > 0 && row5[j - 1] === 1 && (c === "?" || c === text[j - 1])) next[j] = 1;
|
|
33847
|
+
}
|
|
33848
|
+
row5 = next;
|
|
33849
|
+
}
|
|
33850
|
+
return row5[text.length] === 1;
|
|
33851
|
+
}
|
|
33852
|
+
function toolOff(name, rules) {
|
|
33853
|
+
for (let k = rules.length - 1; k >= 0; k--) {
|
|
33854
|
+
const r = rules[k];
|
|
33855
|
+
if (typeof r.action === "string" && wildcard(r.action, name)) return r.resource === "*" && r.effect === "deny";
|
|
33856
|
+
}
|
|
33857
|
+
return false;
|
|
33858
|
+
}
|
|
33859
|
+
function agentResolver(ctx, ownTools) {
|
|
33860
|
+
const cache = /* @__PURE__ */ new Map();
|
|
33861
|
+
const known = [...SHELL_TOOL_NAMES, READ_TOOL_NAME, "webfetch", ...ownTools];
|
|
33862
|
+
const resolveOne = async (agent) => {
|
|
33863
|
+
const raw = await ctx.agent?.get?.({ agentID: agent, location: { directory: ctx.location.directory } });
|
|
33864
|
+
const box = raw !== null && typeof raw === "object" ? raw : {};
|
|
33865
|
+
const info = box.mode !== void 0 ? box : box.data;
|
|
33866
|
+
if (info?.mode !== "subagent") return {};
|
|
33867
|
+
const rules = info.permissions ?? [];
|
|
33868
|
+
return { agentID: agent, agentTools: known.filter((t) => !toolOff(t, rules)) };
|
|
33869
|
+
};
|
|
33870
|
+
return (agent) => {
|
|
33871
|
+
if (agent === void 0 || agent === "" || ctx.agent?.get === void 0) return Promise.resolve({});
|
|
33872
|
+
let p = cache.get(agent);
|
|
33873
|
+
if (p === void 0) {
|
|
33874
|
+
p = resolveOne(agent).catch(() => ({}));
|
|
33875
|
+
cache.set(agent, p);
|
|
33876
|
+
}
|
|
33877
|
+
return p;
|
|
33878
|
+
};
|
|
33879
|
+
}
|
|
33598
33880
|
async function setup(ctx) {
|
|
33599
33881
|
const tools = /* @__PURE__ */ new Map();
|
|
33600
33882
|
const assert2 = ctx.permission?.assert;
|
|
@@ -33629,22 +33911,31 @@ async function setup(ctx) {
|
|
|
33629
33911
|
await ctx.tool.transform((editor) => {
|
|
33630
33912
|
for (const t of tools.values()) editor.add(t);
|
|
33631
33913
|
});
|
|
33914
|
+
const subagentOf = agentResolver(ctx, [...tools.keys()]);
|
|
33632
33915
|
await ctx.tool.hook("execute.before", async (i) => {
|
|
33633
|
-
|
|
33916
|
+
const sub = await subagentOf(i.agent);
|
|
33917
|
+
await hooks["tool.execute.before"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, ...sub }, { args: i.input });
|
|
33634
33918
|
});
|
|
33635
33919
|
await ctx.tool.hook("execute.after", async (i) => {
|
|
33636
33920
|
const failed = i.status === "error";
|
|
33637
|
-
const
|
|
33638
|
-
|
|
33921
|
+
const text = failed ? i.error?.message ?? "" : oc2Text(i.result?.content);
|
|
33922
|
+
const out = { output: text, isError: failed };
|
|
33923
|
+
const sub = await subagentOf(i.agent);
|
|
33924
|
+
await hooks["tool.execute.after"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, args: i.input, ...sub }, out);
|
|
33925
|
+
if (!failed && typeof out.output === "string" && out.output !== text) {
|
|
33926
|
+
i.result = { ...i.result, content: [{ type: "text", text: out.output }] };
|
|
33927
|
+
}
|
|
33639
33928
|
});
|
|
33640
33929
|
await ctx.session.hook("prompt", async (p) => {
|
|
33641
33930
|
await hooks["chat.message"]({ sessionID: p.sessionID }, { parts: [{ type: "text", text: p.prompt?.text ?? "" }] });
|
|
33642
33931
|
});
|
|
33643
|
-
|
|
33932
|
+
const injectSystem = async (c) => {
|
|
33644
33933
|
const system = [];
|
|
33645
33934
|
await hooks["experimental.chat.system.transform"]({ sessionID: c.sessionID }, { system });
|
|
33646
33935
|
for (const text of system) if (!c.system.some((p) => p.text === text)) c.system.push({ type: "text", text });
|
|
33647
|
-
}
|
|
33936
|
+
};
|
|
33937
|
+
await ctx.session.hook("context", injectSystem);
|
|
33938
|
+
await ctx.session.hook("generate", injectSystem);
|
|
33648
33939
|
await ctx.session.hook("compaction", async (c) => {
|
|
33649
33940
|
await hooks["experimental.session.compacting"]({ sessionID: c.sessionID });
|
|
33650
33941
|
});
|