context-mode 2.1.4 → 2.1.6
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 +277 -163
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +2670 -517
- package/package.json +1 -1
- package/pi/index.js +2813 -739
- package/qwen-extension.json +1 -1
- package/run.mjs +300 -97
- package/search.mjs +300 -97
- package/server.mjs +2261 -268
package/opencode/plugin.js
CHANGED
|
@@ -23,7 +23,14 @@ var POINTER_MIN = 640;
|
|
|
23
23
|
var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
24
24
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
25
25
|
var SYNC_INDEX_MAX_BYTES = 65536;
|
|
26
|
-
var
|
|
26
|
+
var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
|
|
27
|
+
var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
|
|
28
|
+
function readReplaceTrigger(raw) {
|
|
29
|
+
if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
30
|
+
const n = Number(raw);
|
|
31
|
+
return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
32
|
+
}
|
|
33
|
+
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
27
34
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
28
35
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
29
36
|
var REPLACE_RETURN_BYTES = 96;
|
|
@@ -249,6 +256,7 @@ function readHintEvery(raw) {
|
|
|
249
256
|
}
|
|
250
257
|
var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
|
|
251
258
|
var MAX_NEST_DEPTH = 32;
|
|
259
|
+
var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
|
|
252
260
|
var DENY_PREFIX = "context-mode: ";
|
|
253
261
|
var DENY_WHAT = Object.freeze({
|
|
254
262
|
curl: "This curl/wget call",
|
|
@@ -322,6 +330,31 @@ var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
|
322
330
|
var JQ_COMMAND = "jq";
|
|
323
331
|
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
|
|
324
332
|
var READ_PATH_LIST_KEY = "filePaths";
|
|
333
|
+
var READ_MEDIA_TYPES = Object.freeze({
|
|
334
|
+
png: { exts: [".png"], sig: [{ at: 0, bytes: [137, 80, 78, 71, 13, 10, 26, 10] }] },
|
|
335
|
+
jpeg: { exts: [".jpg", ".jpeg"], sig: [{ at: 0, bytes: [255, 216, 255] }] },
|
|
336
|
+
gif: { exts: [".gif"], sig: [{ at: 0, bytes: [71, 73, 70, 56] }] },
|
|
337
|
+
// "GIF8"
|
|
338
|
+
webp: { exts: [".webp"], sig: [{ at: 0, bytes: [82, 73, 70, 70] }, { at: 8, bytes: [87, 69, 66, 80] }] },
|
|
339
|
+
// "RIFF" .... "WEBP"
|
|
340
|
+
pdf: { exts: [".pdf"], sig: [{ at: 0, bytes: [37, 80, 68, 70, 45] }] }
|
|
341
|
+
// "%PDF-"
|
|
342
|
+
});
|
|
343
|
+
var READ_MEDIA_SNIFF_BYTES = 12;
|
|
344
|
+
var READ_IMAGES = Object.freeze(["png", "jpeg", "gif", "webp"]);
|
|
345
|
+
var READ_IMAGES_AND_PDF = Object.freeze([...READ_IMAGES, "pdf"]);
|
|
346
|
+
var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
347
|
+
"claude-code": READ_IMAGES_AND_PDF,
|
|
348
|
+
gemini: READ_IMAGES_AND_PDF,
|
|
349
|
+
qwen: READ_IMAGES_AND_PDF,
|
|
350
|
+
opencode: READ_IMAGES_AND_PDF,
|
|
351
|
+
pi: READ_IMAGES,
|
|
352
|
+
vscode: READ_IMAGES,
|
|
353
|
+
zcode: READ_IMAGES,
|
|
354
|
+
"copilot-cli": [],
|
|
355
|
+
codex: [],
|
|
356
|
+
kiro: []
|
|
357
|
+
});
|
|
325
358
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
326
359
|
var SHELL_TOOL = "Bash";
|
|
327
360
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
@@ -338,6 +371,7 @@ var RECALL_MAX_ROWS = 340;
|
|
|
338
371
|
var COMPACTED_META_PREFIX = "compacted:";
|
|
339
372
|
var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
|
|
340
373
|
var UNITS_ANCESTOR_FACTOR = 8;
|
|
374
|
+
var RECALL_QUERY_MAX_TERMS = 64;
|
|
341
375
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
342
376
|
var RECALL_SEEN_META_PREFIX = "recall_seen:";
|
|
343
377
|
var RECALL_OPEN_TAG = "<context_mode_recall>";
|
|
@@ -431,7 +465,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
431
465
|
var DECISION_OPTION_KEY = "option";
|
|
432
466
|
var DECISION_LABEL_JOIN = " | ";
|
|
433
467
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
434
|
-
var BUNDLE_SHA = true ? "
|
|
468
|
+
var BUNDLE_SHA = true ? "ee0a1f6058f6abdb5af70b05f825a997bb15615d" : void 0;
|
|
435
469
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
436
470
|
var DOCTOR_LABEL = Object.freeze({
|
|
437
471
|
D1: "version",
|
|
@@ -517,9 +551,9 @@ var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-ta
|
|
|
517
551
|
var D1_PRERELEASE_SEP = "-";
|
|
518
552
|
var D1_DEFAULT_TAG = "latest";
|
|
519
553
|
var GIT_LS_REMOTE = "ls-remote";
|
|
520
|
-
var D2_NODE_FIX = `install
|
|
554
|
+
var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
|
|
521
555
|
function D2_NODE_DETAIL(version2) {
|
|
522
|
-
return `Node ${
|
|
556
|
+
return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version2}`;
|
|
523
557
|
}
|
|
524
558
|
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
525
559
|
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
@@ -684,15 +718,28 @@ var REGEX_ESCAPE = "\\";
|
|
|
684
718
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
685
719
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
686
720
|
var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
|
|
721
|
+
var D5_READ_OWN_DETAIL = "PreToolUse Read of a skill file over the one-read limit under the agent's own config dir came back denied: skill and rule files must reach the model whole (#1326)";
|
|
722
|
+
var D5_READ_MEDIA_DETAIL = "PreToolUse Read of a PNG over the one-read limit came back denied: an image Read must reach the model as an image block (#1321)";
|
|
687
723
|
var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
|
|
688
724
|
function D5_SLOW_DETAIL(ms) {
|
|
689
725
|
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
690
726
|
}
|
|
727
|
+
var D5_STOP_DETAIL = "Codex Stop event: the hook did not give an empty or Codex Stop reply, or it logged a hook error";
|
|
691
728
|
var D5_FIX = "run ctx_upgrade";
|
|
692
729
|
var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
693
730
|
function D10_DETAIL(mode) {
|
|
694
731
|
return `enforcement mode: ${mode}`;
|
|
695
732
|
}
|
|
733
|
+
function D10_PERMISSION_DETAIL(mode) {
|
|
734
|
+
return `enforcement mode: ${mode}; OpenCode permission rules apply to ctx_* tools`;
|
|
735
|
+
}
|
|
736
|
+
var D10_PERMISSION_MISSING_DETAIL = "this OpenCode build gives plugins no permission check (ctx.permission.assert), so ctx_* tools cannot follow OpenCode permission rules";
|
|
737
|
+
var D10_PERMISSION_FIX = "opencode upgrade";
|
|
738
|
+
var OC_SHELL_ACTION = "shell";
|
|
739
|
+
var OC_LEGACY_SHELL_ACTION = "bash";
|
|
740
|
+
var OC_READ_ACTION = "read";
|
|
741
|
+
var OC_WEBFETCH_ACTION = "webfetch";
|
|
742
|
+
var OC_ANY_RESOURCE = "*";
|
|
696
743
|
var D11_WIN_DETAIL = "Git Bash not found";
|
|
697
744
|
var D11_WIN_FIX = "install Git for Windows";
|
|
698
745
|
var D11_POSIX_DETAIL = "no sh on PATH";
|
|
@@ -755,6 +802,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
755
802
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
756
803
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
757
804
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
805
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
806
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
758
807
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
759
808
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
760
809
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -848,6 +897,7 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
|
|
|
848
897
|
var JSON_INDENT_UNIT = " ";
|
|
849
898
|
var MCP_COMMAND_FIELD = "command";
|
|
850
899
|
var MCP_ARGS_FIELD = "args";
|
|
900
|
+
var MCP_ENV_FIELD = "env";
|
|
851
901
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
852
902
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
853
903
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -965,7 +1015,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
|
965
1015
|
|
|
966
1016
|
// src/core/contracts/errors.ts
|
|
967
1017
|
var ERROR_TEXT = Object.freeze({
|
|
968
|
-
NODE_TOO_OLD: "
|
|
1018
|
+
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.",
|
|
1019
|
+
// #1328 D-NODE-OLD-1
|
|
969
1020
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
970
1021
|
DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
|
|
971
1022
|
// D-ORPHAN-WAL-1
|
|
@@ -1035,7 +1086,7 @@ var CtxError = class extends Error {
|
|
|
1035
1086
|
};
|
|
1036
1087
|
|
|
1037
1088
|
// src/core/hooks/dispatch.ts
|
|
1038
|
-
import { dirname as dirname4, join as
|
|
1089
|
+
import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
|
|
1039
1090
|
|
|
1040
1091
|
// src/core/contracts/agents.ts
|
|
1041
1092
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -1235,10 +1286,17 @@ function encode(ev, d, _extra) {
|
|
|
1235
1286
|
// src/adapters/codex.ts
|
|
1236
1287
|
var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
|
|
1237
1288
|
var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
|
|
1289
|
+
var STOP_EVENT = "Stop";
|
|
1290
|
+
var EMPTY = { stdout: "", exitCode: 0 };
|
|
1238
1291
|
function decode2(raw) {
|
|
1292
|
+
if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
|
|
1293
|
+
const p = raw;
|
|
1294
|
+
return { event: STOP_EVENT, agent: "codex", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
|
|
1295
|
+
}
|
|
1239
1296
|
return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
|
|
1240
1297
|
}
|
|
1241
1298
|
function encode2(ev, d, _extra) {
|
|
1299
|
+
if (ev.event === STOP_EVENT) return EMPTY;
|
|
1242
1300
|
return encodeClaudeShape(ev, d, false);
|
|
1243
1301
|
}
|
|
1244
1302
|
|
|
@@ -1254,7 +1312,7 @@ var GEMINI_EVENTS = {
|
|
|
1254
1312
|
var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
1255
1313
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
1256
1314
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
1257
|
-
var
|
|
1315
|
+
var EMPTY2 = { stdout: "", exitCode: 0 };
|
|
1258
1316
|
var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its full output, and this is the part that answers the call:\n";
|
|
1259
1317
|
function own(p, key) {
|
|
1260
1318
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
@@ -1295,7 +1353,13 @@ function readResult2(resp) {
|
|
|
1295
1353
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
1296
1354
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
1297
1355
|
const err = obj === void 0 ? void 0 : own(obj, "error");
|
|
1298
|
-
|
|
1356
|
+
const info = { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
|
|
1357
|
+
if (hasMediaPart(llm)) info.keep = true;
|
|
1358
|
+
return info;
|
|
1359
|
+
}
|
|
1360
|
+
function hasMediaPart(llm) {
|
|
1361
|
+
const parts = Array.isArray(llm) ? llm : [llm];
|
|
1362
|
+
return parts.some((p) => typeof p === "object" && p !== null && (Object.hasOwn(p, "inlineData") || Object.hasOwn(p, "fileData")));
|
|
1299
1363
|
}
|
|
1300
1364
|
var URL_STARTS = ["https://", "http://"];
|
|
1301
1365
|
var URL_TRAIL = `.,;:!?)]}>'"`;
|
|
@@ -1362,15 +1426,15 @@ function decode3(raw) {
|
|
|
1362
1426
|
function encode3(ev, d, _extra) {
|
|
1363
1427
|
switch (d.kind) {
|
|
1364
1428
|
case "allow":
|
|
1365
|
-
return
|
|
1429
|
+
return EMPTY2;
|
|
1366
1430
|
case "hint":
|
|
1367
|
-
if (!HINT_EVENTS.includes(ev.event)) return
|
|
1431
|
+
if (!HINT_EVENTS.includes(ev.event)) return EMPTY2;
|
|
1368
1432
|
return { stdout: JSON.stringify({ hookSpecificOutput: { additionalContext: d.text } }), exitCode: 0 };
|
|
1369
1433
|
case "deny":
|
|
1370
|
-
if (!DENY_EVENTS.includes(ev.event)) return
|
|
1434
|
+
if (!DENY_EVENTS.includes(ev.event)) return EMPTY2;
|
|
1371
1435
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
1372
1436
|
case "replace":
|
|
1373
|
-
if (ev.event !== "PostToolUse") return
|
|
1437
|
+
if (ev.event !== "PostToolUse") return EMPTY2;
|
|
1374
1438
|
return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
|
|
1375
1439
|
}
|
|
1376
1440
|
}
|
|
@@ -1490,21 +1554,21 @@ function decode5(raw) {
|
|
|
1490
1554
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
1491
1555
|
return ev;
|
|
1492
1556
|
}
|
|
1493
|
-
var
|
|
1557
|
+
var EMPTY3 = { stdout: "", exitCode: 0 };
|
|
1494
1558
|
function encode5(ev, d, _extra) {
|
|
1495
1559
|
switch (d.kind) {
|
|
1496
1560
|
case "allow":
|
|
1497
|
-
return
|
|
1561
|
+
return EMPTY3;
|
|
1498
1562
|
case "hint":
|
|
1499
|
-
return ev.event === "PostToolUse" ?
|
|
1563
|
+
return ev.event === "PostToolUse" ? EMPTY3 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
|
|
1500
1564
|
case "deny":
|
|
1501
|
-
if (ev.event !== "PreToolUse") return
|
|
1565
|
+
if (ev.event !== "PreToolUse") return EMPTY3;
|
|
1502
1566
|
return {
|
|
1503
1567
|
stdout: JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }),
|
|
1504
1568
|
exitCode: 0
|
|
1505
1569
|
};
|
|
1506
1570
|
case "replace":
|
|
1507
|
-
if (ev.event !== "PostToolUse") return
|
|
1571
|
+
if (ev.event !== "PostToolUse") return EMPTY3;
|
|
1508
1572
|
return { stdout: JSON.stringify({ modifiedResult: { resultType: RESULT_SUCCESS, textResultForLlm: d.output } }), exitCode: 0 };
|
|
1509
1573
|
}
|
|
1510
1574
|
}
|
|
@@ -2636,7 +2700,7 @@ var HEAD_BYTES = "-c";
|
|
|
2636
2700
|
var HEAD_BYTES_LONG = "--bytes";
|
|
2637
2701
|
var GREP_COUNT_SHORT = "c";
|
|
2638
2702
|
var GREP_COUNT_LONG = "--count";
|
|
2639
|
-
var
|
|
2703
|
+
var EMPTY4 = () => ({ cmds: [], simple: null });
|
|
2640
2704
|
var at = (p, k = 0) => p.toks[p.i + k];
|
|
2641
2705
|
var isOp = (t, text) => t !== void 0 && t.kind === "op" && t.text === text;
|
|
2642
2706
|
var isWord = (t, text) => t !== void 0 && t.kind === "word" && t.text === text;
|
|
@@ -2753,7 +2817,7 @@ function compound(p, body) {
|
|
|
2753
2817
|
p.depth++;
|
|
2754
2818
|
if (p.depth > MAX_NEST_DEPTH) {
|
|
2755
2819
|
p.err = "nesting-too-deep";
|
|
2756
|
-
return
|
|
2820
|
+
return EMPTY4();
|
|
2757
2821
|
}
|
|
2758
2822
|
const cmds = body();
|
|
2759
2823
|
p.depth--;
|
|
@@ -2881,7 +2945,7 @@ function simple(p) {
|
|
|
2881
2945
|
words2.push(t);
|
|
2882
2946
|
p.i++;
|
|
2883
2947
|
}
|
|
2884
|
-
if (p.i === first) return
|
|
2948
|
+
if (p.i === first) return EMPTY4();
|
|
2885
2949
|
const raw = p.src.slice(p.toks[first].start, p.toks[p.i - 1].end);
|
|
2886
2950
|
if (words2.length === 0) return { cmds: carrier(raw), simple: null };
|
|
2887
2951
|
const text = (t) => t.kind === "word" ? dequote(t.text) : t.text;
|
|
@@ -2892,9 +2956,9 @@ function simple(p) {
|
|
|
2892
2956
|
}
|
|
2893
2957
|
function element(p) {
|
|
2894
2958
|
const t = at(p);
|
|
2895
|
-
if (t === void 0) return
|
|
2959
|
+
if (t === void 0) return EMPTY4();
|
|
2896
2960
|
if (t.kind === "op") {
|
|
2897
|
-
if (t.text !== SUBSHELL_OPEN) return
|
|
2961
|
+
if (t.text !== SUBSHELL_OPEN) return EMPTY4();
|
|
2898
2962
|
return compound(p, () => {
|
|
2899
2963
|
p.i++;
|
|
2900
2964
|
const body = list(p, NO_STOP);
|
|
@@ -2927,10 +2991,10 @@ function element(p) {
|
|
|
2927
2991
|
return compound(p, () => caseBody(p));
|
|
2928
2992
|
case KW.coproc:
|
|
2929
2993
|
p.err = "coproc";
|
|
2930
|
-
return
|
|
2994
|
+
return EMPTY4();
|
|
2931
2995
|
case KW.select:
|
|
2932
2996
|
p.err = "select";
|
|
2933
|
-
return
|
|
2997
|
+
return EMPTY4();
|
|
2934
2998
|
case KW.function: {
|
|
2935
2999
|
p.i++;
|
|
2936
3000
|
const nameTok = at(p);
|
|
@@ -2954,7 +3018,7 @@ function element(p) {
|
|
|
2954
3018
|
function pipeline(p) {
|
|
2955
3019
|
if (isWord(at(p), NOT)) p.i++;
|
|
2956
3020
|
const all = [];
|
|
2957
|
-
let last2 =
|
|
3021
|
+
let last2 = EMPTY4();
|
|
2958
3022
|
while (p.err === null) {
|
|
2959
3023
|
last2 = element(p);
|
|
2960
3024
|
append(all, last2.cmds);
|
|
@@ -3311,21 +3375,21 @@ function cdTarget(words2) {
|
|
|
3311
3375
|
function walk(script, cwd, depth, found) {
|
|
3312
3376
|
let dir = cwd;
|
|
3313
3377
|
for (const stages of psParse(script)) {
|
|
3314
|
-
const
|
|
3315
|
-
if (
|
|
3316
|
-
const name = cmdName(
|
|
3378
|
+
const head2 = stages[0];
|
|
3379
|
+
if (head2.words.length === 0) continue;
|
|
3380
|
+
const name = cmdName(head2.words[0]);
|
|
3317
3381
|
if (stages.length === 1 && CD_COMMANDS.includes(name)) {
|
|
3318
|
-
const t = cdTarget(
|
|
3382
|
+
const t = cdTarget(head2.words);
|
|
3319
3383
|
if (t !== null) dir = resolve(dir, t);
|
|
3320
3384
|
continue;
|
|
3321
3385
|
}
|
|
3322
|
-
const inner = depth < MAX_NEST_DEPTH ? nestedScript(name,
|
|
3386
|
+
const inner = depth < MAX_NEST_DEPTH ? nestedScript(name, head2.words) : null;
|
|
3323
3387
|
if (inner !== null) {
|
|
3324
3388
|
walk(inner, dir, depth + 1, found);
|
|
3325
3389
|
continue;
|
|
3326
3390
|
}
|
|
3327
|
-
if (
|
|
3328
|
-
const d = psDump(
|
|
3391
|
+
if (head2.toFile || head2.chained) continue;
|
|
3392
|
+
const d = psDump(head2.words);
|
|
3329
3393
|
if (d === null || d.bounded) continue;
|
|
3330
3394
|
let shown2 = true;
|
|
3331
3395
|
for (let k = 1; k < stages.length; k++) {
|
|
@@ -3371,7 +3435,7 @@ function withLayout(text, layout) {
|
|
|
3371
3435
|
|
|
3372
3436
|
// src/core/project/config-dir.ts
|
|
3373
3437
|
import { basename, dirname, join, posix, resolve as resolve2, win32 } from "node:path";
|
|
3374
|
-
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
3438
|
+
var { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
3375
3439
|
function homeDirOf(env, platform = process.platform) {
|
|
3376
3440
|
const set3 = (v) => v !== void 0 && v !== "";
|
|
3377
3441
|
if (platform === "win32") {
|
|
@@ -3398,7 +3462,34 @@ function codexPluginHomeOf(bundleDir2) {
|
|
|
3398
3462
|
function codexRunDirOf(env, home, bundleDir2) {
|
|
3399
3463
|
const dir = env[CODEX_HOME_ENV];
|
|
3400
3464
|
if (dir !== void 0 && dir !== "") return dir;
|
|
3401
|
-
return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
|
|
3465
|
+
return codexPluginHomeOf(bundleDir2) ?? codexSetupHomeOf(env, home) ?? codexDirOf(env, home);
|
|
3466
|
+
}
|
|
3467
|
+
function codexSetupHomeOf(env, home) {
|
|
3468
|
+
if (home === "" && !env[DATA_DIR_ENV]) return null;
|
|
3469
|
+
const base = join(dataRootOf(env, home), SETUP_BACKUP_DIR_NAME);
|
|
3470
|
+
let runs;
|
|
3471
|
+
try {
|
|
3472
|
+
runs = readdirSync(base).sort().reverse();
|
|
3473
|
+
} catch {
|
|
3474
|
+
return null;
|
|
3475
|
+
}
|
|
3476
|
+
for (const run of runs) {
|
|
3477
|
+
const file2 = join(base, run, SETUP_MANIFEST_FILE);
|
|
3478
|
+
if (!existsSync(file2)) continue;
|
|
3479
|
+
let entries;
|
|
3480
|
+
try {
|
|
3481
|
+
entries = JSON.parse(readFileSync(file2, "utf8")).entries;
|
|
3482
|
+
} catch {
|
|
3483
|
+
continue;
|
|
3484
|
+
}
|
|
3485
|
+
if (!Array.isArray(entries)) continue;
|
|
3486
|
+
for (const e of entries) {
|
|
3487
|
+
if (e?.agent !== "codex" || typeof e.file !== "string") continue;
|
|
3488
|
+
const p = e.file.includes(win32.sep) ? win32 : posix;
|
|
3489
|
+
if (p.basename(e.file) === CONFIG_TOML_FILE) return p.dirname(e.file);
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
return null;
|
|
3402
3493
|
}
|
|
3403
3494
|
function copilotDirOf(env, home) {
|
|
3404
3495
|
const dir = env[COPILOT_HOME_ENV];
|
|
@@ -3478,7 +3569,7 @@ function resolveConfigDir(env) {
|
|
|
3478
3569
|
}
|
|
3479
3570
|
|
|
3480
3571
|
// src/core/policy/subagent.ts
|
|
3481
|
-
var { readFileSync } = process.getBuiltinModule("node:fs");
|
|
3572
|
+
var { readFileSync: readFileSync2 } = process.getBuiltinModule("node:fs");
|
|
3482
3573
|
function isSubagentCall(ev) {
|
|
3483
3574
|
return ev.agentId !== void 0 && ev.agentId !== "";
|
|
3484
3575
|
}
|
|
@@ -3539,7 +3630,7 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3539
3630
|
if (agent.indexOf(PLUGIN_AGENT_SEPARATOR) >= 0) return null;
|
|
3540
3631
|
let parsed;
|
|
3541
3632
|
try {
|
|
3542
|
-
parsed = JSON.parse(hostText(
|
|
3633
|
+
parsed = JSON.parse(hostText(readFileSync2(join2(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE), "utf8")));
|
|
3543
3634
|
} catch {
|
|
3544
3635
|
return null;
|
|
3545
3636
|
}
|
|
@@ -3562,7 +3653,7 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3562
3653
|
function readAgentFile(path8) {
|
|
3563
3654
|
let text;
|
|
3564
3655
|
try {
|
|
3565
|
-
text =
|
|
3656
|
+
text = readFileSync2(path8, "utf8");
|
|
3566
3657
|
} catch {
|
|
3567
3658
|
return null;
|
|
3568
3659
|
}
|
|
@@ -3770,7 +3861,7 @@ function unwrap(commands) {
|
|
|
3770
3861
|
|
|
3771
3862
|
// src/core/policy/user-deny.ts
|
|
3772
3863
|
import { isAbsolute, join as join3, relative, sep } from "node:path";
|
|
3773
|
-
var { readFileSync:
|
|
3864
|
+
var { readFileSync: readFileSync3 } = process.getBuiltinModule("node:fs");
|
|
3774
3865
|
var CLAUDE_DIR = ".claude";
|
|
3775
3866
|
var LOCAL_SETTINGS = "settings.local.json";
|
|
3776
3867
|
var SETTINGS = "settings.json";
|
|
@@ -3797,7 +3888,7 @@ function isObject(v) {
|
|
|
3797
3888
|
function readOne(file2) {
|
|
3798
3889
|
let text;
|
|
3799
3890
|
try {
|
|
3800
|
-
text = hostText(
|
|
3891
|
+
text = hostText(readFileSync3(file2, "utf8"));
|
|
3801
3892
|
} catch (err) {
|
|
3802
3893
|
return err.code === "ENOENT" ? { kind: "absent" } : { kind: "bad" };
|
|
3803
3894
|
}
|
|
@@ -3960,6 +4051,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
3960
4051
|
ctx_purge: 'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'
|
|
3961
4052
|
});
|
|
3962
4053
|
var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limit. Run ctx_execute(language, code, file="{path}") and print only the answer.';
|
|
4054
|
+
var READ_DENY_RANGE_TEMPLATE = `context-mode: {size}-byte file, over the one-read limit. Read "{path}" in parts with offset and limit, or sed -n '1,200p'.`;
|
|
3963
4055
|
|
|
3964
4056
|
// src/core/policy/read-deny.ts
|
|
3965
4057
|
var SIZE = "{size}";
|
|
@@ -3967,6 +4059,129 @@ var PATH = "{path}";
|
|
|
3967
4059
|
function READ_DENY_MESSAGE(path8, size, prefix = "") {
|
|
3968
4060
|
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
3969
4061
|
}
|
|
4062
|
+
function READ_DENY_RANGE_MESSAGE(path8, size) {
|
|
4063
|
+
return READ_DENY_RANGE_TEMPLATE.split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
4064
|
+
}
|
|
4065
|
+
|
|
4066
|
+
// src/core/policy/own-file.ts
|
|
4067
|
+
import { extname, join as join5 } from "node:path";
|
|
4068
|
+
|
|
4069
|
+
// src/core/project/contain.ts
|
|
4070
|
+
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
4071
|
+
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4072
|
+
function real(p) {
|
|
4073
|
+
try {
|
|
4074
|
+
return realpathSync2.native(p);
|
|
4075
|
+
} catch {
|
|
4076
|
+
return void 0;
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
function components(p) {
|
|
4080
|
+
return p.split(sep2).filter((c) => c !== "");
|
|
4081
|
+
}
|
|
4082
|
+
function isInside(root, p) {
|
|
4083
|
+
const r = real(root);
|
|
4084
|
+
const q = real(p);
|
|
4085
|
+
if (r === void 0 || q === void 0) return false;
|
|
4086
|
+
const rc = components(r);
|
|
4087
|
+
const qc = components(q);
|
|
4088
|
+
if (qc.length < rc.length) return false;
|
|
4089
|
+
for (let i = 0; i < rc.length; i += 1) {
|
|
4090
|
+
if (rc[i] !== qc[i]) return false;
|
|
4091
|
+
}
|
|
4092
|
+
return true;
|
|
4093
|
+
}
|
|
4094
|
+
var rootReal = /* @__PURE__ */ new Map();
|
|
4095
|
+
function realRoot(root) {
|
|
4096
|
+
const hit = rootReal.get(root);
|
|
4097
|
+
if (hit !== void 0) return hit;
|
|
4098
|
+
const r = real(root);
|
|
4099
|
+
if (r !== void 0) rootReal.set(root, r);
|
|
4100
|
+
return r;
|
|
4101
|
+
}
|
|
4102
|
+
function isInsideAny(roots, p) {
|
|
4103
|
+
if (roots.length === 0) return false;
|
|
4104
|
+
const q = real(p);
|
|
4105
|
+
if (q === void 0) return false;
|
|
4106
|
+
const qc = components(q);
|
|
4107
|
+
return roots.some((root) => {
|
|
4108
|
+
const r = realRoot(root);
|
|
4109
|
+
if (r === void 0) return false;
|
|
4110
|
+
const rc = components(r);
|
|
4111
|
+
return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
|
|
4112
|
+
});
|
|
4113
|
+
}
|
|
4114
|
+
function commonRoot(paths) {
|
|
4115
|
+
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
4116
|
+
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
4117
|
+
const first = reals[0];
|
|
4118
|
+
let n = components(first).length;
|
|
4119
|
+
for (const r of reals) {
|
|
4120
|
+
const rc = components(r);
|
|
4121
|
+
const fc = components(first);
|
|
4122
|
+
let i = 0;
|
|
4123
|
+
while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
|
|
4124
|
+
n = i;
|
|
4125
|
+
}
|
|
4126
|
+
let q = first;
|
|
4127
|
+
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
4128
|
+
return q;
|
|
4129
|
+
}
|
|
4130
|
+
function reachedThroughLink(root, p) {
|
|
4131
|
+
const rel = relative2(root, p);
|
|
4132
|
+
const steps = components(rel);
|
|
4133
|
+
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
4134
|
+
let at2 = root;
|
|
4135
|
+
for (const step of steps) {
|
|
4136
|
+
at2 = join4(at2, step);
|
|
4137
|
+
try {
|
|
4138
|
+
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
4139
|
+
} catch {
|
|
4140
|
+
return false;
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
return false;
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
// src/core/policy/own-file.ts
|
|
4147
|
+
function ownDirsOf(agent, env) {
|
|
4148
|
+
const home = homeDirOf(env);
|
|
4149
|
+
if (home === null) return [];
|
|
4150
|
+
const shared = join5(home, ...SHARED_SKILLS_DIR);
|
|
4151
|
+
const own2 = agent === "claude-code" ? [claudeDirOf(env, home)] : agent === "codex" ? [codexDirOf(env, home)] : agent === "gemini" ? [geminiDirOf(env, home)] : agent === "copilot-cli" ? [copilotDirOf(env, home)] : agent === "kiro" ? [kiroDirOf(env, home)] : agent === "opencode" ? [opencodeDirOf(env, home)] : agent === "pi" ? [piAgentDirOf(env, home)] : agent === "vscode" ? [join5(home, ...AGENT_HOME_DIR.vscode), vscodeUserDirOf(env, home)] : [join5(home, ...AGENT_HOME_DIR[agent])];
|
|
4152
|
+
return [...own2, shared];
|
|
4153
|
+
}
|
|
4154
|
+
function isOwnFile(agent, abs, env = process.env) {
|
|
4155
|
+
if (extname(abs).toLowerCase() !== AGENT_FILE_EXT) return false;
|
|
4156
|
+
return isInsideAny(ownDirsOf(agent, env), abs);
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
// src/core/policy/read-media.ts
|
|
4160
|
+
import { extname as extname2 } from "node:path";
|
|
4161
|
+
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
4162
|
+
function head(abs) {
|
|
4163
|
+
let fd = null;
|
|
4164
|
+
try {
|
|
4165
|
+
fd = openSync(abs, "r");
|
|
4166
|
+
const buf = Buffer.alloc(READ_MEDIA_SNIFF_BYTES);
|
|
4167
|
+
const n = readSync(fd, buf, 0, READ_MEDIA_SNIFF_BYTES, 0);
|
|
4168
|
+
return buf.subarray(0, n);
|
|
4169
|
+
} catch {
|
|
4170
|
+
return null;
|
|
4171
|
+
} finally {
|
|
4172
|
+
if (fd !== null) closeSync(fd);
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
4175
|
+
function isMediaRead(agent, abs) {
|
|
4176
|
+
const types = READ_MEDIA_BY_AGENT[agent] ?? [];
|
|
4177
|
+
if (types.length === 0) return false;
|
|
4178
|
+
const ext = extname2(abs).toLowerCase();
|
|
4179
|
+
const named2 = types.filter((t) => READ_MEDIA_TYPES[t].exts.includes(ext));
|
|
4180
|
+
if (named2.length === 0) return false;
|
|
4181
|
+
const bytes5 = head(abs);
|
|
4182
|
+
if (bytes5 === null) return false;
|
|
4183
|
+
return named2.some((t) => READ_MEDIA_TYPES[t].sig.every((s) => s.bytes.every((b, i) => bytes5[s.at + i] === b)));
|
|
4184
|
+
}
|
|
3970
4185
|
|
|
3971
4186
|
// src/core/policy/decide.ts
|
|
3972
4187
|
var { statSync } = process.getBuiltinModule("node:fs");
|
|
@@ -3991,7 +4206,7 @@ var deny = (reason) => ({ kind: "deny", reason });
|
|
|
3991
4206
|
var str = (v) => typeof v === "string" ? v : void 0;
|
|
3992
4207
|
var present = (v) => v !== void 0 && v !== null;
|
|
3993
4208
|
var has = (list4, v) => list4.includes(v);
|
|
3994
|
-
function decide(ev, row5, userDeny) {
|
|
4209
|
+
function decide(ev, row5, userDeny, root = ev.cwd) {
|
|
3995
4210
|
const tool = ev.tool;
|
|
3996
4211
|
if (tool === void 0) return ALLOW;
|
|
3997
4212
|
const canonical = tool.canonicalName;
|
|
@@ -4005,8 +4220,8 @@ function decide(ev, row5, userDeny) {
|
|
|
4005
4220
|
const hit = userDenyHit(canonical, input, ev.cwd, rules);
|
|
4006
4221
|
if (hit !== null) return deny(USER_DENY_REASON_PREFIX + hit);
|
|
4007
4222
|
if (canonical === WEBFETCH) return webFetch(input, row5);
|
|
4008
|
-
if (canonical === BASH) return bash(ev, row5, input, rules);
|
|
4009
|
-
if (canonical === READ) return read(ev, row5, input);
|
|
4223
|
+
if (canonical === BASH) return bash(ev, row5, input, rules, root);
|
|
4224
|
+
if (canonical === READ) return read(ev, row5, input, root);
|
|
4010
4225
|
return ALLOW;
|
|
4011
4226
|
}
|
|
4012
4227
|
function denyMessage(kind, match, row5, intent) {
|
|
@@ -4059,8 +4274,8 @@ function userDenyHit(canonical, input, cwd, rules) {
|
|
|
4059
4274
|
function isShellLanguage(language) {
|
|
4060
4275
|
if (typeof language !== "string") return false;
|
|
4061
4276
|
let name = language.toLowerCase();
|
|
4062
|
-
const
|
|
4063
|
-
if (
|
|
4277
|
+
const slash2 = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
|
|
4278
|
+
if (slash2 >= 0) name = name.slice(slash2 + 1);
|
|
4064
4279
|
if (name.endsWith(EXE_SUFFIX2)) name = name.slice(0, name.length - EXE_SUFFIX2.length);
|
|
4065
4280
|
return name === SHELL_LANGUAGE || has(SHELL_FAMILY, name);
|
|
4066
4281
|
}
|
|
@@ -4108,10 +4323,10 @@ function webFetch(input, row5) {
|
|
|
4108
4323
|
const url2 = str(input.url) ?? "";
|
|
4109
4324
|
return neverDenied(url2) ? ALLOW : deny(denyMessage("webfetch", url2, row5));
|
|
4110
4325
|
}
|
|
4111
|
-
function bash(ev, row5, input, rules) {
|
|
4326
|
+
function bash(ev, row5, input, rules, root) {
|
|
4112
4327
|
const cmd = str(input.command) ?? "";
|
|
4113
4328
|
const parsed = parseShell(cmd);
|
|
4114
|
-
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(cmd,
|
|
4329
|
+
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(ev, cmd, row5, root) ?? ALLOW;
|
|
4115
4330
|
const cmds = unwrap(parsed.commands);
|
|
4116
4331
|
for (const c of cmds) {
|
|
4117
4332
|
const h = segmentHit(c, rules);
|
|
@@ -4123,7 +4338,7 @@ function bash(ev, row5, input, rules) {
|
|
|
4123
4338
|
if (kind !== null) return deny(denyMessage(kind, cmd, row5, str(input.description)));
|
|
4124
4339
|
}
|
|
4125
4340
|
}
|
|
4126
|
-
return shellDump(cmds,
|
|
4341
|
+
return shellDump(ev, cmds, row5, root) ?? psShellDump(ev, cmd, row5, root) ?? ALLOW;
|
|
4127
4342
|
}
|
|
4128
4343
|
function denyKind(c) {
|
|
4129
4344
|
const name = c.argv0.toLowerCase();
|
|
@@ -4166,19 +4381,35 @@ function fileSize(abs) {
|
|
|
4166
4381
|
return -1;
|
|
4167
4382
|
}
|
|
4168
4383
|
}
|
|
4169
|
-
function
|
|
4384
|
+
function bigDeny(ev, row5, abs, size, root) {
|
|
4385
|
+
if (size <= OUTPUT_CAP || isOwnFile(ev.agent, abs)) return null;
|
|
4386
|
+
return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
|
|
4387
|
+
}
|
|
4388
|
+
function executeCanOpen(root, abs) {
|
|
4389
|
+
if (typeof root === "string") return isInsideAny([root], abs);
|
|
4390
|
+
if (isInsideAny([root.worktree], abs)) return true;
|
|
4391
|
+
try {
|
|
4392
|
+
return isInsideAny([root.containmentRoot], abs);
|
|
4393
|
+
} catch {
|
|
4394
|
+
return false;
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
function read(ev, row5, input, root) {
|
|
4170
4398
|
if (!present(input.offset) && !present(input.limit)) {
|
|
4171
4399
|
for (const p of readPaths(input)) {
|
|
4172
4400
|
const abs = resolve3(ev.cwd, p);
|
|
4173
4401
|
const size = fileSize(abs);
|
|
4174
|
-
if (size > OUTPUT_CAP
|
|
4402
|
+
if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
|
|
4403
|
+
const d = bigDeny(ev, row5, abs, size, root);
|
|
4404
|
+
if (d !== null) return d;
|
|
4405
|
+
}
|
|
4175
4406
|
}
|
|
4176
4407
|
}
|
|
4177
4408
|
return ALLOW;
|
|
4178
4409
|
}
|
|
4179
|
-
function shellDump(cmds,
|
|
4410
|
+
function shellDump(ev, cmds, row5, root) {
|
|
4180
4411
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
4181
|
-
let dir = cwd;
|
|
4412
|
+
let dir = ev.cwd;
|
|
4182
4413
|
let verdict = null;
|
|
4183
4414
|
for (const c of cmds) {
|
|
4184
4415
|
const name = c.argv0.toLowerCase();
|
|
@@ -4192,16 +4423,16 @@ function shellDump(cmds, cwd, row5) {
|
|
|
4192
4423
|
continue;
|
|
4193
4424
|
}
|
|
4194
4425
|
const abs = resolve3(dir, d.file);
|
|
4195
|
-
const
|
|
4196
|
-
if (
|
|
4426
|
+
const big = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
4427
|
+
if (big !== null) return big;
|
|
4197
4428
|
}
|
|
4198
4429
|
return verdict;
|
|
4199
4430
|
}
|
|
4200
|
-
function psShellDump(cmd,
|
|
4431
|
+
function psShellDump(ev, cmd, row5, root) {
|
|
4201
4432
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
4202
|
-
for (const abs of psDumpFiles(cmd, cwd)) {
|
|
4203
|
-
const
|
|
4204
|
-
if (
|
|
4433
|
+
for (const abs of psDumpFiles(cmd, ev.cwd)) {
|
|
4434
|
+
const d = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
4435
|
+
if (d !== null) return d;
|
|
4205
4436
|
}
|
|
4206
4437
|
return null;
|
|
4207
4438
|
}
|
|
@@ -4262,64 +4493,7 @@ function dumpTarget(name, args) {
|
|
|
4262
4493
|
}
|
|
4263
4494
|
|
|
4264
4495
|
// src/core/project/resolve.ts
|
|
4265
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
4266
|
-
|
|
4267
|
-
// src/core/project/contain.ts
|
|
4268
|
-
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
4269
|
-
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4270
|
-
function real(p) {
|
|
4271
|
-
try {
|
|
4272
|
-
return realpathSync2.native(p);
|
|
4273
|
-
} catch {
|
|
4274
|
-
return void 0;
|
|
4275
|
-
}
|
|
4276
|
-
}
|
|
4277
|
-
function components(p) {
|
|
4278
|
-
return p.split(sep2).filter((c) => c !== "");
|
|
4279
|
-
}
|
|
4280
|
-
function isInside(root, p) {
|
|
4281
|
-
const r = real(root);
|
|
4282
|
-
const q = real(p);
|
|
4283
|
-
if (r === void 0 || q === void 0) return false;
|
|
4284
|
-
const rc = components(r);
|
|
4285
|
-
const qc = components(q);
|
|
4286
|
-
if (qc.length < rc.length) return false;
|
|
4287
|
-
for (let i = 0; i < rc.length; i += 1) {
|
|
4288
|
-
if (rc[i] !== qc[i]) return false;
|
|
4289
|
-
}
|
|
4290
|
-
return true;
|
|
4291
|
-
}
|
|
4292
|
-
function commonRoot(paths) {
|
|
4293
|
-
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
4294
|
-
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
4295
|
-
const first = reals[0];
|
|
4296
|
-
let n = components(first).length;
|
|
4297
|
-
for (const r of reals) {
|
|
4298
|
-
const rc = components(r);
|
|
4299
|
-
const fc = components(first);
|
|
4300
|
-
let i = 0;
|
|
4301
|
-
while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
|
|
4302
|
-
n = i;
|
|
4303
|
-
}
|
|
4304
|
-
let q = first;
|
|
4305
|
-
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
4306
|
-
return q;
|
|
4307
|
-
}
|
|
4308
|
-
function reachedThroughLink(root, p) {
|
|
4309
|
-
const rel = relative2(root, p);
|
|
4310
|
-
const steps = components(rel);
|
|
4311
|
-
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
4312
|
-
let at2 = root;
|
|
4313
|
-
for (const step of steps) {
|
|
4314
|
-
at2 = join4(at2, step);
|
|
4315
|
-
try {
|
|
4316
|
-
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
4317
|
-
} catch {
|
|
4318
|
-
return false;
|
|
4319
|
-
}
|
|
4320
|
-
}
|
|
4321
|
-
return false;
|
|
4322
|
-
}
|
|
4496
|
+
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve4 } from "node:path";
|
|
4323
4497
|
|
|
4324
4498
|
// src/core/project/sha256.ts
|
|
4325
4499
|
var K = new Uint32Array([
|
|
@@ -4434,7 +4608,7 @@ function sha256Hex(text) {
|
|
|
4434
4608
|
}
|
|
4435
4609
|
|
|
4436
4610
|
// src/core/project/resolve.ts
|
|
4437
|
-
var { existsSync, readFileSync:
|
|
4611
|
+
var { existsSync: existsSync2, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
|
|
4438
4612
|
function sourceOf(agent) {
|
|
4439
4613
|
switch (agent) {
|
|
4440
4614
|
case "claude-code":
|
|
@@ -4481,9 +4655,9 @@ function gitDirs(dir) {
|
|
|
4481
4655
|
}
|
|
4482
4656
|
const start = cur;
|
|
4483
4657
|
for (; ; ) {
|
|
4484
|
-
const gitDir = gitDirAt(
|
|
4658
|
+
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
4485
4659
|
if (gitDir !== null) {
|
|
4486
|
-
const common = firstLine(
|
|
4660
|
+
const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
|
|
4487
4661
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
4488
4662
|
}
|
|
4489
4663
|
const up = dirname3(cur);
|
|
@@ -4504,12 +4678,12 @@ function gitDirAt(dotGit) {
|
|
|
4504
4678
|
} catch {
|
|
4505
4679
|
return null;
|
|
4506
4680
|
}
|
|
4507
|
-
return
|
|
4681
|
+
return existsSync2(join6(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
4508
4682
|
}
|
|
4509
4683
|
function firstLine(file2) {
|
|
4510
4684
|
let text;
|
|
4511
4685
|
try {
|
|
4512
|
-
text =
|
|
4686
|
+
text = readFileSync4(file2, "utf8");
|
|
4513
4687
|
} catch {
|
|
4514
4688
|
return null;
|
|
4515
4689
|
}
|
|
@@ -4545,11 +4719,11 @@ function resolveProject(agent, src) {
|
|
|
4545
4719
|
return key;
|
|
4546
4720
|
},
|
|
4547
4721
|
get projectDir() {
|
|
4548
|
-
pdir ??=
|
|
4722
|
+
pdir ??= join6(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
4549
4723
|
return pdir;
|
|
4550
4724
|
},
|
|
4551
4725
|
get dbPath() {
|
|
4552
|
-
return
|
|
4726
|
+
return join6(this.projectDir, DB_FILE_NAME);
|
|
4553
4727
|
},
|
|
4554
4728
|
worktree,
|
|
4555
4729
|
get containmentRoot() {
|
|
@@ -4700,7 +4874,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
|
4700
4874
|
}
|
|
4701
4875
|
|
|
4702
4876
|
// src/core/store/db.ts
|
|
4703
|
-
var { existsSync:
|
|
4877
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4704
4878
|
function versionParts(v) {
|
|
4705
4879
|
const bare2 = v.startsWith("v") ? v.slice(1) : v;
|
|
4706
4880
|
return bare2.split(".").map((p) => Number.parseInt(p, 10));
|
|
@@ -4754,7 +4928,7 @@ function createAtomically(sqlite, path8) {
|
|
|
4754
4928
|
function openWritable(sqlite, path8) {
|
|
4755
4929
|
let raw = null;
|
|
4756
4930
|
try {
|
|
4757
|
-
if (!
|
|
4931
|
+
if (!existsSync3(path8)) createAtomically(sqlite, path8);
|
|
4758
4932
|
raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
4759
4933
|
applyMigrations(raw, readUserVersion(raw));
|
|
4760
4934
|
return raw;
|
|
@@ -4779,14 +4953,14 @@ async function openDb(project, opts) {
|
|
|
4779
4953
|
const sqlite = await loadSqlite();
|
|
4780
4954
|
mkdirSync2(project.projectDir, { recursive: true });
|
|
4781
4955
|
const path8 = project.dbPath;
|
|
4782
|
-
const sibling =
|
|
4783
|
-
if (sibling && !
|
|
4956
|
+
const sibling = existsSync3(path8 + DB_WAL_SUFFIX) || existsSync3(path8 + DB_SHM_SUFFIX);
|
|
4957
|
+
if (sibling && !existsSync3(path8)) {
|
|
4784
4958
|
throw new CtxError("DB_GONE");
|
|
4785
4959
|
}
|
|
4786
4960
|
try {
|
|
4787
4961
|
let raw;
|
|
4788
4962
|
if (opts?.readOnly === true) {
|
|
4789
|
-
if (!
|
|
4963
|
+
if (!existsSync3(path8)) openWritable(sqlite, path8).close();
|
|
4790
4964
|
raw = openReadOnly(sqlite, path8);
|
|
4791
4965
|
} else {
|
|
4792
4966
|
raw = openWritable(sqlite, path8);
|
|
@@ -4936,11 +5110,6 @@ function readLastPrompt(db, sessionId) {
|
|
|
4936
5110
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
4937
5111
|
return row5 === void 0 ? "" : row5.body;
|
|
4938
5112
|
}
|
|
4939
|
-
function readFirstPrompt(db, sessionId) {
|
|
4940
|
-
if (sessionId === "") return "";
|
|
4941
|
-
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq ASC LIMIT 1").get(sessionId);
|
|
4942
|
-
return row5 === void 0 ? "" : row5.body;
|
|
4943
|
-
}
|
|
4944
5113
|
function readRecallRows(db, sessionId, worktree, limit) {
|
|
4945
5114
|
if (sessionId === "") return [];
|
|
4946
5115
|
return db.raw.prepare("SELECT * FROM events WHERE kind <> 'cost' AND (session_id = ? OR worktree = ?) ORDER BY seq DESC LIMIT ?").all(sessionId, worktree, limit);
|
|
@@ -7508,8 +7677,25 @@ function insertUnits(db, sourceId, sessionId, units) {
|
|
|
7508
7677
|
start = end;
|
|
7509
7678
|
}
|
|
7510
7679
|
}
|
|
7511
|
-
function recallQueryText(prompt
|
|
7512
|
-
|
|
7680
|
+
function recallQueryText(prompt) {
|
|
7681
|
+
const kept = /* @__PURE__ */ new Set();
|
|
7682
|
+
const all = /* @__PURE__ */ new Set();
|
|
7683
|
+
const add = (w) => {
|
|
7684
|
+
if (all.size < RECALL_QUERY_MAX_TERMS) all.add(w);
|
|
7685
|
+
if (!STOPWORDS.has(w.toLowerCase())) kept.add(w);
|
|
7686
|
+
};
|
|
7687
|
+
let cur = "";
|
|
7688
|
+
for (const ch of prompt) {
|
|
7689
|
+
if (kept.size >= RECALL_QUERY_MAX_TERMS) break;
|
|
7690
|
+
if (ch.trim() === "" || ch === "\0") {
|
|
7691
|
+
if (cur !== "") add(cur);
|
|
7692
|
+
cur = "";
|
|
7693
|
+
} else {
|
|
7694
|
+
cur += ch;
|
|
7695
|
+
}
|
|
7696
|
+
}
|
|
7697
|
+
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
7698
|
+
return [...kept.size > 0 ? kept : all].join(" ");
|
|
7513
7699
|
}
|
|
7514
7700
|
function queryUnits(db, sessionId, q, limit) {
|
|
7515
7701
|
const match = searchTerms(q).join(" OR ");
|
|
@@ -7935,14 +8121,14 @@ function lineBlocks(src, md) {
|
|
|
7935
8121
|
close();
|
|
7936
8122
|
} else {
|
|
7937
8123
|
const opener = md ? fenceOf(line) : "";
|
|
7938
|
-
const
|
|
7939
|
-
const table3 = md && opener === "" &&
|
|
7940
|
-
if (md && start >= 0 && (table3 !== inTable || opener !== "" ||
|
|
8124
|
+
const head2 = md && opener === "" ? headingOf(line) : void 0;
|
|
8125
|
+
const table3 = md && opener === "" && head2 === void 0 && line.includes("|");
|
|
8126
|
+
if (md && start >= 0 && (table3 !== inTable || opener !== "" || head2 !== void 0)) close();
|
|
7941
8127
|
add(pos, eol, table3);
|
|
7942
8128
|
fence = opener;
|
|
7943
8129
|
if (opener !== "") fenceInfo = { fence: opener, openEnd: eol, closeStart: -1 };
|
|
7944
|
-
if (
|
|
7945
|
-
heading =
|
|
8130
|
+
if (head2 !== void 0) {
|
|
8131
|
+
heading = head2;
|
|
7946
8132
|
close();
|
|
7947
8133
|
}
|
|
7948
8134
|
}
|
|
@@ -8098,7 +8284,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
8098
8284
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
8099
8285
|
return { end: start + r.read, written: r.written };
|
|
8100
8286
|
}
|
|
8101
|
-
function merge(src, blocks,
|
|
8287
|
+
function merge(src, blocks, join25, cap, lineCut) {
|
|
8102
8288
|
const out = [];
|
|
8103
8289
|
const scratch = new Uint8Array(cap);
|
|
8104
8290
|
let wide;
|
|
@@ -8108,7 +8294,7 @@ function merge(src, blocks, join24, cap, lineCut) {
|
|
|
8108
8294
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
8109
8295
|
};
|
|
8110
8296
|
for (const b of blocks) {
|
|
8111
|
-
if (cur !== void 0 && !
|
|
8297
|
+
if (cur !== void 0 && !join25) {
|
|
8112
8298
|
emit(cur.start, cur.end, curBytes);
|
|
8113
8299
|
cur = void 0;
|
|
8114
8300
|
}
|
|
@@ -8374,9 +8560,9 @@ function hasDigit(t) {
|
|
|
8374
8560
|
return false;
|
|
8375
8561
|
}
|
|
8376
8562
|
function similarity(tpl, toks) {
|
|
8377
|
-
let
|
|
8378
|
-
for (let i = 0; i < tpl.length; i++) if (tpl[i] === toks[i] || tpl[i] === "<*>" || toks[i] === "<*>")
|
|
8379
|
-
return
|
|
8563
|
+
let same2 = 0;
|
|
8564
|
+
for (let i = 0; i < tpl.length; i++) if (tpl[i] === toks[i] || tpl[i] === "<*>" || toks[i] === "<*>") same2++;
|
|
8565
|
+
return same2 / tpl.length;
|
|
8380
8566
|
}
|
|
8381
8567
|
function lineShape(text) {
|
|
8382
8568
|
const all = text.split("\n");
|
|
@@ -8550,7 +8736,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
8550
8736
|
}
|
|
8551
8737
|
|
|
8552
8738
|
// src/core/hooks/fallback.ts
|
|
8553
|
-
import { join as
|
|
8739
|
+
import { join as join7, resolve as resolve5 } from "node:path";
|
|
8554
8740
|
var fs = process.getBuiltinModule("node:fs");
|
|
8555
8741
|
function isRec(v) {
|
|
8556
8742
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8578,9 +8764,9 @@ function homeOf(env) {
|
|
|
8578
8764
|
}
|
|
8579
8765
|
function hookLogPath(env) {
|
|
8580
8766
|
const dir = env[DATA_DIR_ENV];
|
|
8581
|
-
if (dir !== void 0 && dir !== "") return
|
|
8767
|
+
if (dir !== void 0 && dir !== "") return join7(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
8582
8768
|
const home = homeOf(env);
|
|
8583
|
-
return home === "" ? "" :
|
|
8769
|
+
return home === "" ? "" : join7(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
8584
8770
|
}
|
|
8585
8771
|
function errorLabel(err) {
|
|
8586
8772
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -8591,7 +8777,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
8591
8777
|
try {
|
|
8592
8778
|
const file2 = hookLogPath(env);
|
|
8593
8779
|
if (file2 === "") return;
|
|
8594
|
-
fs.mkdirSync(
|
|
8780
|
+
fs.mkdirSync(join7(file2, ".."), { recursive: true });
|
|
8595
8781
|
const line = JSON.stringify({
|
|
8596
8782
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8597
8783
|
agent,
|
|
@@ -8670,10 +8856,10 @@ function bigFile(abs) {
|
|
|
8670
8856
|
return false;
|
|
8671
8857
|
}
|
|
8672
8858
|
}
|
|
8673
|
-
function bigRead(input, cwd) {
|
|
8859
|
+
function bigRead(agent, input, cwd) {
|
|
8674
8860
|
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
8675
8861
|
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
|
|
8676
|
-
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)));
|
|
8862
|
+
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)) && !isOwnFile(agent, resolve5(cwd, p)));
|
|
8677
8863
|
}
|
|
8678
8864
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
8679
8865
|
const row5 = getAdapter(agent);
|
|
@@ -8686,7 +8872,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
8686
8872
|
const kind = kindOf(row5, name);
|
|
8687
8873
|
if (kind === null) return allow();
|
|
8688
8874
|
const cwd = firstString(raw, HOOK_FAIL_CWD_KEYS) || cwdFallback;
|
|
8689
|
-
if (kind === "read" && !bigRead(inputOf(raw), cwd)) return allow();
|
|
8875
|
+
if (kind === "read" && !bigRead(agent, inputOf(raw), cwd)) return allow();
|
|
8690
8876
|
const redirect = kind === "read" ? HOOK_FAIL_REDIRECT.read : HOOK_FAIL_REDIRECT[kind];
|
|
8691
8877
|
const reason = prefixToolNames(redirect, row5.toolNamePrefix) + "\n" + HOOK_FAIL_LINE(errorLabel(err), row5.toolNamePrefix);
|
|
8692
8878
|
return row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd, turn: 0 }, { kind: "deny", reason });
|
|
@@ -8699,9 +8885,9 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
8699
8885
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
8700
8886
|
|
|
8701
8887
|
// src/core/hooks/dispatch.ts
|
|
8702
|
-
var { lstatSync: lstatSync2, readFileSync:
|
|
8888
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync5 } = process.getBuiltinModule("node:fs");
|
|
8703
8889
|
var ALLOW2 = { kind: "allow" };
|
|
8704
|
-
var
|
|
8890
|
+
var EMPTY5 = { stdout: "", exitCode: 0 };
|
|
8705
8891
|
var DIGIT_0 = 48;
|
|
8706
8892
|
function isAgentId(s) {
|
|
8707
8893
|
return AGENT_IDS.includes(s);
|
|
@@ -8715,7 +8901,7 @@ function str2(v) {
|
|
|
8715
8901
|
async function handleHook(agent, raw, env) {
|
|
8716
8902
|
if (!isAgentId(agent)) {
|
|
8717
8903
|
process.stderr.write("hooks: unknown agent " + JSON.stringify(agent) + "\n");
|
|
8718
|
-
return
|
|
8904
|
+
return EMPTY5;
|
|
8719
8905
|
}
|
|
8720
8906
|
const row5 = getAdapter(agent);
|
|
8721
8907
|
const fail7 = (stage, err, line) => {
|
|
@@ -8731,6 +8917,7 @@ async function handleHook(agent, raw, env) {
|
|
|
8731
8917
|
} catch (err) {
|
|
8732
8918
|
return fail7("decode", err);
|
|
8733
8919
|
}
|
|
8920
|
+
if (ev.event === "Stop") return row5.encode(ev, ALLOW2);
|
|
8734
8921
|
let project;
|
|
8735
8922
|
try {
|
|
8736
8923
|
fault(env, "project");
|
|
@@ -8861,8 +9048,7 @@ async function recall(ev, row5, project, prompt) {
|
|
|
8861
9048
|
const seen = seenSeqs(metaGet(db, seenKey));
|
|
8862
9049
|
const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
|
|
8863
9050
|
const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
|
|
8864
|
-
const
|
|
8865
|
-
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt, goal), RECALL_UNIT_CANDIDATES);
|
|
9051
|
+
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
|
|
8866
9052
|
const picked = pickRecall(readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS), prompt, new Set(seen), units, new Set(seenUnits));
|
|
8867
9053
|
if (picked.text === "") return ALLOW2;
|
|
8868
9054
|
if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
|
|
@@ -8934,7 +9120,7 @@ function askDetached(ev, project, tool, text) {
|
|
|
8934
9120
|
}
|
|
8935
9121
|
async function preToolUse(ev, row5, project, env) {
|
|
8936
9122
|
const userDeny = readUserDeny(project.worktree, ev.agent);
|
|
8937
|
-
const decision0 = decide(ev, row5, userDeny);
|
|
9123
|
+
const decision0 = decide(ev, row5, userDeny, project);
|
|
8938
9124
|
let decision = decision0;
|
|
8939
9125
|
if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
|
|
8940
9126
|
const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
|
|
@@ -8960,7 +9146,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
8960
9146
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
8961
9147
|
const command = tool.input.command;
|
|
8962
9148
|
if (typeof command !== "string") return d0;
|
|
8963
|
-
const wrapper = '"' +
|
|
9149
|
+
const wrapper = '"' + join8(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
8964
9150
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
8965
9151
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
8966
9152
|
}
|
|
@@ -9037,9 +9223,15 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9037
9223
|
settle.run = (encoded) => journal(encoded && decided.kind === "replace" ? Buffer.byteLength(decided.output) : result.bytes);
|
|
9038
9224
|
return decision;
|
|
9039
9225
|
}
|
|
9226
|
+
function ownRead(ev, tool, env) {
|
|
9227
|
+
if (!RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
9228
|
+
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9229
|
+
return p !== void 0 && isOwnFile(ev.agent, resolve6(ev.cwd, p), env);
|
|
9230
|
+
}
|
|
9040
9231
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9041
9232
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
9042
9233
|
if (boundedRead(tool)) return ALLOW2;
|
|
9234
|
+
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
9043
9235
|
if (result.keep === true) return ALLOW2;
|
|
9044
9236
|
if (!hasReplace(row5)) return ALLOW2;
|
|
9045
9237
|
let label2;
|
|
@@ -9082,7 +9274,7 @@ function replaceBudget(handleLine, more) {
|
|
|
9082
9274
|
}
|
|
9083
9275
|
function hostToolResult(file2, sessionId, env) {
|
|
9084
9276
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
9085
|
-
const projects =
|
|
9277
|
+
const projects = join8(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
9086
9278
|
const steps = relative3(projects, resolve6(file2)).split(sep3);
|
|
9087
9279
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
9088
9280
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
@@ -9090,16 +9282,16 @@ function hostToolResult(file2, sessionId, env) {
|
|
|
9090
9282
|
return st.isFile() && st.size <= PERSISTED_OUTPUT_MAX_BYTES && isInside(projects, file2);
|
|
9091
9283
|
}
|
|
9092
9284
|
function wholeOutput(result, sessionId, env) {
|
|
9093
|
-
const
|
|
9094
|
-
if (result.persistedPath === void 0) return
|
|
9285
|
+
const head2 = result.text ?? "";
|
|
9286
|
+
if (result.persistedPath === void 0) return head2;
|
|
9095
9287
|
try {
|
|
9096
9288
|
if (!hostToolResult(result.persistedPath, sessionId, env)) {
|
|
9097
9289
|
logHookError(env, "claude-code", "persisted-output", new Error("persisted output path is outside this session's tool-results dir or too large; kept the head"));
|
|
9098
|
-
return
|
|
9290
|
+
return head2;
|
|
9099
9291
|
}
|
|
9100
|
-
return
|
|
9292
|
+
return readFileSync5(result.persistedPath, "utf8");
|
|
9101
9293
|
} catch {
|
|
9102
|
-
return
|
|
9294
|
+
return head2;
|
|
9103
9295
|
}
|
|
9104
9296
|
}
|
|
9105
9297
|
async function lastPrompt(project, sessionId) {
|
|
@@ -9112,8 +9304,8 @@ async function lastPrompt(project, sessionId) {
|
|
|
9112
9304
|
function mainLabel(tool, ev) {
|
|
9113
9305
|
const cmd = str2(tool.input.command) ?? str2(tool.input.file_path) ?? "";
|
|
9114
9306
|
const nl = cmd.indexOf("\n");
|
|
9115
|
-
const
|
|
9116
|
-
return
|
|
9307
|
+
const head2 = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
|
|
9308
|
+
return head2 + "#" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9117
9309
|
}
|
|
9118
9310
|
function indexDetached(project, sessionId, sourceId, label2, text, chunks) {
|
|
9119
9311
|
void openDb(project).then((db) => {
|
|
@@ -11830,7 +12022,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
11830
12022
|
return (payload, ctx) => fn(shape, payload, ctx);
|
|
11831
12023
|
};
|
|
11832
12024
|
let fastpass;
|
|
11833
|
-
const
|
|
12025
|
+
const isObject7 = isObject3;
|
|
11834
12026
|
const jit = !globalConfig.jitless;
|
|
11835
12027
|
const allowsEval2 = allowsEval;
|
|
11836
12028
|
const fastEnabled = jit && allowsEval2.value;
|
|
@@ -11839,7 +12031,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
11839
12031
|
inst._zod.parse = (payload, ctx) => {
|
|
11840
12032
|
value ?? (value = _normalized.value);
|
|
11841
12033
|
const input = payload.value;
|
|
11842
|
-
if (!
|
|
12034
|
+
if (!isObject7(input)) {
|
|
11843
12035
|
payload.issues.push({
|
|
11844
12036
|
expected: "object",
|
|
11845
12037
|
code: "invalid_type",
|
|
@@ -20459,10 +20651,10 @@ function startArgv(argv) {
|
|
|
20459
20651
|
return sh === null ? null : [sh, ...argv];
|
|
20460
20652
|
}
|
|
20461
20653
|
function runProcess(argv, o) {
|
|
20462
|
-
return new Promise((
|
|
20654
|
+
return new Promise((resolve11) => {
|
|
20463
20655
|
const isWin2 = process.platform === "win32";
|
|
20464
20656
|
const start = startArgv(argv);
|
|
20465
|
-
if (start === null) return
|
|
20657
|
+
if (start === null) return resolve11(NOT_STARTED);
|
|
20466
20658
|
let child;
|
|
20467
20659
|
try {
|
|
20468
20660
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -20476,7 +20668,7 @@ function runProcess(argv, o) {
|
|
|
20476
20668
|
windowsHide: true
|
|
20477
20669
|
});
|
|
20478
20670
|
} catch {
|
|
20479
|
-
return
|
|
20671
|
+
return resolve11(NOT_STARTED);
|
|
20480
20672
|
}
|
|
20481
20673
|
const stdoutChunks = [];
|
|
20482
20674
|
const stderrChunks = [];
|
|
@@ -20501,7 +20693,7 @@ function runProcess(argv, o) {
|
|
|
20501
20693
|
settled = true;
|
|
20502
20694
|
clearTimeout(timer);
|
|
20503
20695
|
o.signal.removeEventListener("abort", onAbort);
|
|
20504
|
-
|
|
20696
|
+
resolve11({
|
|
20505
20697
|
stdout: Buffer.concat(stdoutChunks),
|
|
20506
20698
|
stderr: Buffer.concat(stderrChunks),
|
|
20507
20699
|
exitCode,
|
|
@@ -20522,8 +20714,8 @@ function runProcess(argv, o) {
|
|
|
20522
20714
|
}
|
|
20523
20715
|
|
|
20524
20716
|
// src/core/index/auto-memory.ts
|
|
20525
|
-
import { readdirSync, readFileSync as
|
|
20526
|
-
import { join as
|
|
20717
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
|
|
20718
|
+
import { join as join9 } from "node:path";
|
|
20527
20719
|
var MEMORY_FILES = Object.freeze([
|
|
20528
20720
|
Object.freeze(["CLAUDE.md"]),
|
|
20529
20721
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -20537,7 +20729,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20537
20729
|
var MD = ".md";
|
|
20538
20730
|
function steeringFiles(worktree) {
|
|
20539
20731
|
try {
|
|
20540
|
-
return
|
|
20732
|
+
return readdirSync2(join9(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20541
20733
|
} catch {
|
|
20542
20734
|
return [];
|
|
20543
20735
|
}
|
|
@@ -20545,7 +20737,7 @@ function steeringFiles(worktree) {
|
|
|
20545
20737
|
function readAutoMemory(project) {
|
|
20546
20738
|
const rows = [];
|
|
20547
20739
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20548
|
-
const path8 =
|
|
20740
|
+
const path8 = join9(project.worktree, ...segs);
|
|
20549
20741
|
if (!isInside(project.worktree, path8)) continue;
|
|
20550
20742
|
try {
|
|
20551
20743
|
const st = statSync4(path8);
|
|
@@ -20557,7 +20749,7 @@ function readAutoMemory(project) {
|
|
|
20557
20749
|
sourceId: null,
|
|
20558
20750
|
path: path8,
|
|
20559
20751
|
label: segs.join("/"),
|
|
20560
|
-
text:
|
|
20752
|
+
text: readFileSync6(path8, "utf8")
|
|
20561
20753
|
});
|
|
20562
20754
|
} catch {
|
|
20563
20755
|
}
|
|
@@ -20775,9 +20967,9 @@ function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
|
20775
20967
|
more.push({ q, pos: offset });
|
|
20776
20968
|
return;
|
|
20777
20969
|
}
|
|
20778
|
-
const
|
|
20779
|
-
lines.push(
|
|
20780
|
-
used += bytes2(
|
|
20970
|
+
const head2 = "Query " + JSON.stringify(q) + ":";
|
|
20971
|
+
lines.push(head2);
|
|
20972
|
+
used += bytes2(head2) + 1;
|
|
20781
20973
|
const again = /* @__PURE__ */ new Map();
|
|
20782
20974
|
const mine = /* @__PURE__ */ new Set();
|
|
20783
20975
|
let cut = -1;
|
|
@@ -21035,8 +21227,8 @@ function answer2(db, ctx, ownIds, queries, share, own2) {
|
|
|
21035
21227
|
if (ctx.signal.aborted) break;
|
|
21036
21228
|
let hits = ownIds.length === 0 ? [] : ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, void 0, ownIds);
|
|
21037
21229
|
if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
|
|
21038
|
-
const
|
|
21039
|
-
let used = bytes3(
|
|
21230
|
+
const head2 = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
|
|
21231
|
+
let used = bytes3(head2) + 1;
|
|
21040
21232
|
const body = [];
|
|
21041
21233
|
for (const h of hits) {
|
|
21042
21234
|
const key = chunkKey(h.sourceId, h.ord);
|
|
@@ -21054,7 +21246,7 @@ function answer2(db, ctx, ownIds, queries, share, own2) {
|
|
|
21054
21246
|
}
|
|
21055
21247
|
if (hits.length === 0) body.push("No hits.");
|
|
21056
21248
|
else if (body.length === 0) body.push("No new section.");
|
|
21057
|
-
lines.push(
|
|
21249
|
+
lines.push(head2, ...body);
|
|
21058
21250
|
}
|
|
21059
21251
|
return { lines, seen };
|
|
21060
21252
|
}
|
|
@@ -21127,19 +21319,19 @@ var ctxBatch = Object.freeze({
|
|
|
21127
21319
|
});
|
|
21128
21320
|
|
|
21129
21321
|
// src/core/tools/doctor.ts
|
|
21130
|
-
import { readdirSync as
|
|
21131
|
-
import { basename as basename5, join as
|
|
21322
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync15, existsSync as existsSync16 } from "node:fs";
|
|
21323
|
+
import { basename as basename5, join as join19 } from "node:path";
|
|
21132
21324
|
|
|
21133
21325
|
// src/core/ops/bundle-dir.ts
|
|
21134
|
-
import { existsSync as
|
|
21135
|
-
import { dirname as dirname5, join as
|
|
21326
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
21327
|
+
import { dirname as dirname5, join as join10 } from "node:path";
|
|
21136
21328
|
import { fileURLToPath } from "node:url";
|
|
21137
21329
|
function bundleDirOf(argv1, moduleFile) {
|
|
21138
21330
|
const own2 = dirname5(argv1);
|
|
21139
|
-
if (
|
|
21331
|
+
if (existsSync4(join10(own2, SERVER_ENTRY_FILE))) return own2;
|
|
21140
21332
|
let dir = dirname5(moduleFile);
|
|
21141
21333
|
for (; ; ) {
|
|
21142
|
-
if (
|
|
21334
|
+
if (existsSync4(join10(dir, SERVER_ENTRY_FILE))) return dir;
|
|
21143
21335
|
const up = dirname5(dir);
|
|
21144
21336
|
if (up === dir) return own2;
|
|
21145
21337
|
dir = up;
|
|
@@ -21153,17 +21345,17 @@ function ownBundleDir() {
|
|
|
21153
21345
|
}
|
|
21154
21346
|
|
|
21155
21347
|
// src/core/ops/doctor-config.ts
|
|
21156
|
-
import { existsSync as
|
|
21157
|
-
import { join as
|
|
21348
|
+
import { existsSync as existsSync9, readdirSync as readdirSync5 } from "node:fs";
|
|
21349
|
+
import { join as join14 } from "node:path";
|
|
21158
21350
|
|
|
21159
21351
|
// src/core/ops/detect-v1.ts
|
|
21160
|
-
import { existsSync as
|
|
21352
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "node:fs";
|
|
21161
21353
|
import { tmpdir } from "node:os";
|
|
21162
|
-
import { join as
|
|
21354
|
+
import { join as join12 } from "node:path";
|
|
21163
21355
|
|
|
21164
21356
|
// src/core/ops/host-config.ts
|
|
21165
|
-
import { existsSync as
|
|
21166
|
-
import { dirname as dirname6, join as
|
|
21357
|
+
import { existsSync as existsSync5, readFileSync as readFileSync7 } from "node:fs";
|
|
21358
|
+
import { dirname as dirname6, join as join11 } from "node:path";
|
|
21167
21359
|
|
|
21168
21360
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
21169
21361
|
var KEYS2 = {
|
|
@@ -23280,10 +23472,10 @@ function formatOf(path8) {
|
|
|
23280
23472
|
function readHostConfig(agent, path8) {
|
|
23281
23473
|
let file2 = path8;
|
|
23282
23474
|
if (agent === "opencode") {
|
|
23283
|
-
const jsonc =
|
|
23284
|
-
if (
|
|
23475
|
+
const jsonc = join11(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23476
|
+
if (existsSync5(jsonc)) file2 = jsonc;
|
|
23285
23477
|
}
|
|
23286
|
-
const raw =
|
|
23478
|
+
const raw = existsSync5(file2) ? readFileSync7(file2, "utf8") : "";
|
|
23287
23479
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
23288
23480
|
}
|
|
23289
23481
|
function stripJsonComments(text) {
|
|
@@ -23628,7 +23820,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
23628
23820
|
}
|
|
23629
23821
|
}
|
|
23630
23822
|
function serverScript() {
|
|
23631
|
-
return
|
|
23823
|
+
return join11(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23632
23824
|
}
|
|
23633
23825
|
function isNodeCommand(command) {
|
|
23634
23826
|
if (typeof command !== "string") return false;
|
|
@@ -23755,14 +23947,14 @@ function stripJsonc(text) {
|
|
|
23755
23947
|
}
|
|
23756
23948
|
function readJson(file2) {
|
|
23757
23949
|
try {
|
|
23758
|
-
return JSON.parse(stripJsonc(hostText(
|
|
23950
|
+
return JSON.parse(stripJsonc(hostText(readFileSync8(file2, "utf8"))));
|
|
23759
23951
|
} catch {
|
|
23760
23952
|
return void 0;
|
|
23761
23953
|
}
|
|
23762
23954
|
}
|
|
23763
23955
|
function readText(file2) {
|
|
23764
23956
|
try {
|
|
23765
|
-
return hostText(
|
|
23957
|
+
return hostText(readFileSync8(file2, "utf8"));
|
|
23766
23958
|
} catch {
|
|
23767
23959
|
return "";
|
|
23768
23960
|
}
|
|
@@ -23819,7 +24011,7 @@ function flatCommands(events, prefix) {
|
|
|
23819
24011
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23820
24012
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep5) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5));
|
|
23821
24013
|
function dataDir(dir, reason, out) {
|
|
23822
|
-
if (
|
|
24014
|
+
if (existsSync6(dir)) out.push(finding(dir, "", reason));
|
|
23823
24015
|
}
|
|
23824
24016
|
function mcpEntry(file2, doc, out) {
|
|
23825
24017
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -23827,7 +24019,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23827
24019
|
}
|
|
23828
24020
|
}
|
|
23829
24021
|
function claudeShapeSettings(agentHome, out) {
|
|
23830
|
-
const file2 =
|
|
24022
|
+
const file2 = join12(agentHome, SETTINGS_FILE);
|
|
23831
24023
|
const doc = readJson(file2);
|
|
23832
24024
|
for (const c of nestedCommands(doc)) {
|
|
23833
24025
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23847,63 +24039,64 @@ function v1HookFile(file2, out) {
|
|
|
23847
24039
|
function scanClaudeCode(home, agentHome, out) {
|
|
23848
24040
|
claudeShapeSettings(agentHome, out);
|
|
23849
24041
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23850
|
-
const file2 =
|
|
23851
|
-
if (
|
|
24042
|
+
const file2 = join12(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
24043
|
+
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23852
24044
|
}
|
|
23853
|
-
const userFile =
|
|
24045
|
+
const userFile = join12(home, CLAUDE_USER_CONFIG_FILE);
|
|
23854
24046
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23855
|
-
dataDir(
|
|
24047
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23856
24048
|
}
|
|
23857
24049
|
function scanCodex(agentHome, out) {
|
|
23858
|
-
const hooksFile =
|
|
24050
|
+
const hooksFile = join12(agentHome, HOOKS_JSON_FILE);
|
|
23859
24051
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23860
24052
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23861
24053
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23862
24054
|
}
|
|
23863
24055
|
}
|
|
23864
|
-
const tomlFile =
|
|
24056
|
+
const tomlFile = join12(agentHome, CONFIG_TOML_FILE);
|
|
23865
24057
|
const config2 = readTomlValue(tomlFile);
|
|
23866
24058
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23867
24059
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23868
24060
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
|
|
24061
|
+
if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
|
|
23869
24062
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23870
24063
|
}
|
|
23871
|
-
dataDir(
|
|
24064
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23872
24065
|
}
|
|
23873
24066
|
function scanGemini(agentHome, out) {
|
|
23874
|
-
const file2 =
|
|
24067
|
+
const file2 = join12(agentHome, SETTINGS_FILE);
|
|
23875
24068
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23876
24069
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23877
24070
|
}
|
|
23878
|
-
dataDir(
|
|
24071
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23879
24072
|
}
|
|
23880
24073
|
function scanVscode(agentHome, project, out) {
|
|
23881
24074
|
if (project !== void 0) {
|
|
23882
|
-
v1HookFile(
|
|
23883
|
-
const mcpFile2 =
|
|
24075
|
+
v1HookFile(join12(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24076
|
+
const mcpFile2 = join12(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
23884
24077
|
const doc = readJson(mcpFile2);
|
|
23885
24078
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23886
24079
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23887
24080
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23888
24081
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23889
24082
|
}
|
|
23890
|
-
const sessions =
|
|
24083
|
+
const sessions = join12(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
23891
24084
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
23892
24085
|
}
|
|
23893
|
-
dataDir(
|
|
24086
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23894
24087
|
}
|
|
23895
24088
|
function jsonFiles(dir) {
|
|
23896
24089
|
try {
|
|
23897
|
-
return
|
|
24090
|
+
return readdirSync3(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
23898
24091
|
} catch {
|
|
23899
24092
|
return [];
|
|
23900
24093
|
}
|
|
23901
24094
|
}
|
|
23902
24095
|
function scanKiro(agentHome, project, out) {
|
|
23903
|
-
const agentsDir =
|
|
23904
|
-
const defaultFile =
|
|
24096
|
+
const agentsDir = join12(agentHome, KIRO_AGENTS_DIR);
|
|
24097
|
+
const defaultFile = join12(agentHome, ...KIRO_AGENT_FILE);
|
|
23905
24098
|
for (const name of jsonFiles(agentsDir)) {
|
|
23906
|
-
const file2 =
|
|
24099
|
+
const file2 = join12(agentsDir, name);
|
|
23907
24100
|
const doc = readJson(file2);
|
|
23908
24101
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23909
24102
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23914,31 +24107,31 @@ function scanKiro(agentHome, project, out) {
|
|
|
23914
24107
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23915
24108
|
}
|
|
23916
24109
|
}
|
|
23917
|
-
const steeringDocs = [
|
|
23918
|
-
if (project !== void 0) steeringDocs.push(
|
|
24110
|
+
const steeringDocs = [join12(agentHome, ...KIRO_STEERING_FILE)];
|
|
24111
|
+
if (project !== void 0) steeringDocs.push(join12(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
23919
24112
|
for (const file2 of steeringDocs) {
|
|
23920
|
-
if (
|
|
24113
|
+
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
23921
24114
|
}
|
|
23922
|
-
dataDir(
|
|
24115
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23923
24116
|
}
|
|
23924
24117
|
function piNpmIsCurrent(piAgentDir) {
|
|
23925
|
-
const doc = readJson(
|
|
24118
|
+
const doc = readJson(join12(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23926
24119
|
const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23927
24120
|
return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
|
|
23928
24121
|
}
|
|
23929
24122
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23930
|
-
const file2 =
|
|
24123
|
+
const file2 = join12(piAgentDir, SETTINGS_FILE);
|
|
23931
24124
|
const doc = readJson(file2);
|
|
23932
24125
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23933
24126
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23934
24127
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23935
24128
|
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
23936
24129
|
});
|
|
23937
|
-
dataDir(
|
|
24130
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23938
24131
|
}
|
|
23939
24132
|
function scanOpencode(agentHome, out) {
|
|
23940
24133
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
23941
|
-
const file2 =
|
|
24134
|
+
const file2 = join12(agentHome, name);
|
|
23942
24135
|
const doc = readJson(file2);
|
|
23943
24136
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
23944
24137
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -23949,13 +24142,13 @@ function scanOpencode(agentHome, out) {
|
|
|
23949
24142
|
}
|
|
23950
24143
|
}
|
|
23951
24144
|
function scanZcode(agentHome, out) {
|
|
23952
|
-
const configFile =
|
|
24145
|
+
const configFile = join12(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
23953
24146
|
const config2 = readJson(configFile);
|
|
23954
24147
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
23955
24148
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
23956
24149
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
23957
24150
|
}
|
|
23958
|
-
const hooksFile =
|
|
24151
|
+
const hooksFile = join12(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
23959
24152
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23960
24153
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
23961
24154
|
}
|
|
@@ -23979,14 +24172,14 @@ function firstTmpMatch(dir) {
|
|
|
23979
24172
|
}
|
|
23980
24173
|
}
|
|
23981
24174
|
function scanAll(home, tmp, out) {
|
|
23982
|
-
const root =
|
|
23983
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
24175
|
+
const root = join12(home, DATA_ROOT.slice(1));
|
|
24176
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join12(root, name), V1_REASON.dataRoot, out);
|
|
23984
24177
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
23985
24178
|
}
|
|
23986
24179
|
function detectV1(agent, home, scope = {}) {
|
|
23987
24180
|
const out = [];
|
|
23988
24181
|
const project = scope.project;
|
|
23989
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
24182
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join12(home, ...AGENT_HOME_DIR[agent]);
|
|
23990
24183
|
switch (agent) {
|
|
23991
24184
|
case "claude-code":
|
|
23992
24185
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -23999,11 +24192,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23999
24192
|
break;
|
|
24000
24193
|
case "qwen":
|
|
24001
24194
|
claudeShapeSettings(agentHome, out);
|
|
24002
|
-
dataDir(
|
|
24195
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24003
24196
|
break;
|
|
24004
24197
|
case "copilot-cli":
|
|
24005
|
-
v1HookFile(
|
|
24006
|
-
dataDir(
|
|
24198
|
+
v1HookFile(join12(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24199
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24007
24200
|
break;
|
|
24008
24201
|
case "vscode":
|
|
24009
24202
|
scanVscode(agentHome, project, out);
|
|
@@ -24012,7 +24205,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24012
24205
|
scanKiro(agentHome, project, out);
|
|
24013
24206
|
break;
|
|
24014
24207
|
case "pi":
|
|
24015
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24208
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join12(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
24016
24209
|
break;
|
|
24017
24210
|
// D-WIN-PIDIR-1: empty is unset
|
|
24018
24211
|
case "opencode":
|
|
@@ -24027,8 +24220,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24027
24220
|
}
|
|
24028
24221
|
|
|
24029
24222
|
// src/core/ops/plugin-root.ts
|
|
24030
|
-
import { existsSync as
|
|
24031
|
-
import { dirname as dirname7, isAbsolute as isAbsolute2, join as
|
|
24223
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
|
|
24224
|
+
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join13, sep as sep4 } from "node:path";
|
|
24032
24225
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24033
24226
|
function missing(agent, path8) {
|
|
24034
24227
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24069,15 +24262,15 @@ var realOrNull = (path8) => {
|
|
|
24069
24262
|
};
|
|
24070
24263
|
var readOrNull = (file2) => {
|
|
24071
24264
|
try {
|
|
24072
|
-
return
|
|
24265
|
+
return readFileSync9(file2, "utf8");
|
|
24073
24266
|
} catch {
|
|
24074
24267
|
return null;
|
|
24075
24268
|
}
|
|
24076
24269
|
};
|
|
24077
24270
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
24078
24271
|
function enabledPlugins(claudeDir, project) {
|
|
24079
|
-
const files = [
|
|
24080
|
-
if (project !== void 0) files.push(
|
|
24272
|
+
const files = [join13(claudeDir, SETTINGS_FILE)];
|
|
24273
|
+
if (project !== void 0) files.push(join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
24081
24274
|
const out = {};
|
|
24082
24275
|
for (const file2 of files) {
|
|
24083
24276
|
const text = readOrNull(file2);
|
|
@@ -24093,10 +24286,10 @@ function marketplaceChoice(env, worktree) {
|
|
|
24093
24286
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24094
24287
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
24095
24288
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
24096
|
-
const record4 = readOrNull(
|
|
24289
|
+
const record4 = readOrNull(join13(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
24097
24290
|
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
24098
24291
|
if (recorded.length === 0) return { record: false };
|
|
24099
|
-
const live = recorded.filter((r) =>
|
|
24292
|
+
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
24100
24293
|
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
24101
24294
|
if (mine !== void 0) return { root: mine.installPath };
|
|
24102
24295
|
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
@@ -24116,18 +24309,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
24116
24309
|
}
|
|
24117
24310
|
function marketplaceRoot(adapter, env, worktree) {
|
|
24118
24311
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
24119
|
-
const plugins =
|
|
24120
|
-
const cache =
|
|
24312
|
+
const plugins = join13(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24313
|
+
const cache = join13(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
24121
24314
|
const script = process.argv[1];
|
|
24122
24315
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24123
24316
|
const choice = marketplaceChoice(env, worktree);
|
|
24124
24317
|
if ("root" in choice) return choice.root;
|
|
24125
24318
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
24126
24319
|
const cacheReal = realOrNull(cache);
|
|
24127
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) &&
|
|
24128
|
-
const pattern =
|
|
24129
|
-
if (!
|
|
24130
|
-
const found =
|
|
24320
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join13(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24321
|
+
const pattern = join13(cache, "*", PLUGIN_NAME);
|
|
24322
|
+
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24323
|
+
const found = readdirSync4(cache).sort().map((marketplace) => join13(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24131
24324
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24132
24325
|
return found[0];
|
|
24133
24326
|
}
|
|
@@ -24135,7 +24328,7 @@ function configEntryRoot(adapter, env) {
|
|
|
24135
24328
|
const spec = OWN_MCP_ENTRY[adapter.id];
|
|
24136
24329
|
if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
|
|
24137
24330
|
const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
|
|
24138
|
-
if (!
|
|
24331
|
+
if (!existsSync7(file2)) throw missing(adapter.id, file2);
|
|
24139
24332
|
const current = readHostConfig(adapter.id, file2);
|
|
24140
24333
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24141
24334
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
@@ -24152,9 +24345,9 @@ function candidate(adapter, env, worktree) {
|
|
|
24152
24345
|
case "hooks+mcp":
|
|
24153
24346
|
return configEntryRoot(adapter, env);
|
|
24154
24347
|
case "extension":
|
|
24155
|
-
return
|
|
24348
|
+
return join13(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join13(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
24156
24349
|
case "plugin":
|
|
24157
|
-
return
|
|
24350
|
+
return join13(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24158
24351
|
case "in-process":
|
|
24159
24352
|
return dirname7(fileURLToPath2(import.meta.url));
|
|
24160
24353
|
}
|
|
@@ -24169,7 +24362,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
24169
24362
|
}
|
|
24170
24363
|
|
|
24171
24364
|
// src/setup/pi-gate.ts
|
|
24172
|
-
import { existsSync as
|
|
24365
|
+
import { existsSync as existsSync8, readFileSync as readFileSync10, realpathSync as realpathSync5 } from "node:fs";
|
|
24173
24366
|
import path4 from "node:path";
|
|
24174
24367
|
var EXTENSIONS_KEY = "extensions";
|
|
24175
24368
|
var PROJECT_DIR = ".pi";
|
|
@@ -24177,9 +24370,9 @@ var TRUST_FILE = "trust.json";
|
|
|
24177
24370
|
var ALWAYS = "always";
|
|
24178
24371
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
24179
24372
|
function load(file2) {
|
|
24180
|
-
if (!
|
|
24373
|
+
if (!existsSync8(file2)) return void 0;
|
|
24181
24374
|
try {
|
|
24182
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
24375
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync10(file2, "utf8")), "json") };
|
|
24183
24376
|
} catch {
|
|
24184
24377
|
return void 0;
|
|
24185
24378
|
}
|
|
@@ -24314,11 +24507,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24314
24507
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24315
24508
|
function mcpFile(row5, home, env) {
|
|
24316
24509
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24317
|
-
if (row5.id === "codex") return
|
|
24510
|
+
if (row5.id === "codex") return join14(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24318
24511
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24319
|
-
if (row5.id === "opencode") return
|
|
24512
|
+
if (row5.id === "opencode") return join14(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24320
24513
|
if (row5.id === "pi") {
|
|
24321
|
-
return
|
|
24514
|
+
return join14(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24322
24515
|
}
|
|
24323
24516
|
return null;
|
|
24324
24517
|
}
|
|
@@ -24331,27 +24524,27 @@ function codexNativeDir(env, home) {
|
|
|
24331
24524
|
const codexDir = codexDirOf(env, home);
|
|
24332
24525
|
let enabled;
|
|
24333
24526
|
try {
|
|
24334
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24527
|
+
enabled = hostConfigValueAt(readParsed("codex", join14(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24335
24528
|
} catch {
|
|
24336
24529
|
return null;
|
|
24337
24530
|
}
|
|
24338
24531
|
if (enabled !== true) return null;
|
|
24339
|
-
const cache =
|
|
24340
|
-
if (!
|
|
24532
|
+
const cache = join14(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24533
|
+
if (!existsSync9(cache)) return null;
|
|
24341
24534
|
const found = [];
|
|
24342
|
-
for (const market of
|
|
24343
|
-
const plugin =
|
|
24344
|
-
if (!
|
|
24345
|
-
for (const version2 of
|
|
24346
|
-
const dir =
|
|
24347
|
-
if (
|
|
24535
|
+
for (const market of readdirSync5(cache)) {
|
|
24536
|
+
const plugin = join14(cache, market, SERVER_KEY);
|
|
24537
|
+
if (!existsSync9(plugin)) continue;
|
|
24538
|
+
for (const version2 of readdirSync5(plugin).sort()) {
|
|
24539
|
+
const dir = join14(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24540
|
+
if (existsSync9(join14(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24348
24541
|
}
|
|
24349
24542
|
}
|
|
24350
24543
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24351
24544
|
}
|
|
24352
24545
|
function nativeMcpWrong(dir, row5) {
|
|
24353
24546
|
try {
|
|
24354
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
24547
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join14(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
24355
24548
|
if (!isObject4(entry)) return true;
|
|
24356
24549
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24357
24550
|
const script = args[0];
|
|
@@ -24375,7 +24568,7 @@ function opencodeMcpOwn(entry) {
|
|
|
24375
24568
|
function opencodeListed(file2) {
|
|
24376
24569
|
const { value } = readParsed("opencode", file2);
|
|
24377
24570
|
const bundle = opencodePluginFile();
|
|
24378
|
-
const own2 = [bundle,
|
|
24571
|
+
const own2 = [bundle, join14(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
24379
24572
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
|
|
24380
24573
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
24381
24574
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
@@ -24399,7 +24592,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24399
24592
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24400
24593
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24401
24594
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24402
|
-
const file2 = native !== null ?
|
|
24595
|
+
const file2 = native !== null ? join14(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join14(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join14(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join14(kiroDirOf(env, home), ...spec.file.slice(1)) : join14(root, ...spec.file);
|
|
24403
24596
|
return file2;
|
|
24404
24597
|
}
|
|
24405
24598
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24410,7 +24603,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24410
24603
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24411
24604
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24412
24605
|
if (row5.id === "codex") {
|
|
24413
|
-
const config2 = readParsed(row5.id,
|
|
24606
|
+
const config2 = readParsed(row5.id, join14(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24414
24607
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24415
24608
|
}
|
|
24416
24609
|
} catch {
|
|
@@ -24454,7 +24647,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24454
24647
|
function checkPiInstall(env, home, worktree) {
|
|
24455
24648
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24456
24649
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24457
|
-
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
24650
|
+
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join14(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
24458
24651
|
}
|
|
24459
24652
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24460
24653
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24473,10 +24666,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24473
24666
|
}
|
|
24474
24667
|
function checkDoubleFire(agent, worktree) {
|
|
24475
24668
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24476
|
-
const claude = parsedOrNull(agent,
|
|
24669
|
+
const claude = parsedOrNull(agent, join14(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24477
24670
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24478
24671
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24479
|
-
const vscode = parsedOrNull(agent,
|
|
24672
|
+
const vscode = parsedOrNull(agent, join14(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24480
24673
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24481
24674
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24482
24675
|
}
|
|
@@ -24487,7 +24680,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24487
24680
|
const mcp = mcpFile(row5, home, env);
|
|
24488
24681
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24489
24682
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24490
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
24683
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join14(native, CODEX_PLUGIN_MCP_FILE) });
|
|
24491
24684
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24492
24685
|
if (spec !== null) {
|
|
24493
24686
|
try {
|
|
@@ -24507,7 +24700,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24507
24700
|
}
|
|
24508
24701
|
|
|
24509
24702
|
// src/core/ops/doctor-db.ts
|
|
24510
|
-
import { existsSync as
|
|
24703
|
+
import { existsSync as existsSync10, statSync as statSync5 } from "node:fs";
|
|
24511
24704
|
var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
24512
24705
|
var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
24513
24706
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -24549,15 +24742,15 @@ function orphanFiles(dbPath) {
|
|
|
24549
24742
|
const files = [];
|
|
24550
24743
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
24551
24744
|
const path8 = dbPath + suffix;
|
|
24552
|
-
if (
|
|
24745
|
+
if (existsSync10(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
|
|
24553
24746
|
}
|
|
24554
|
-
return files.length > 0 && !
|
|
24747
|
+
return files.length > 0 && !existsSync10(dbPath) ? files : [];
|
|
24555
24748
|
}
|
|
24556
24749
|
async function checkDb(project) {
|
|
24557
24750
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
24558
24751
|
const orphan = orphanFiles(project.dbPath);
|
|
24559
24752
|
if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
24560
|
-
if (!
|
|
24753
|
+
if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
24561
24754
|
const sqlite = await loadSqlite2();
|
|
24562
24755
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
24563
24756
|
let raw = null;
|
|
@@ -24583,7 +24776,7 @@ async function checkDb(project) {
|
|
|
24583
24776
|
}
|
|
24584
24777
|
}
|
|
24585
24778
|
async function checkIndex(project) {
|
|
24586
|
-
if (!
|
|
24779
|
+
if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
24587
24780
|
const sqlite = await loadSqlite2();
|
|
24588
24781
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
24589
24782
|
let raw = null;
|
|
@@ -24600,8 +24793,8 @@ async function checkIndex(project) {
|
|
|
24600
24793
|
}
|
|
24601
24794
|
|
|
24602
24795
|
// src/core/ops/doctor-env.ts
|
|
24603
|
-
import { existsSync as
|
|
24604
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24796
|
+
import { existsSync as existsSync11, readFileSync as readFileSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
24797
|
+
import { isAbsolute as isAbsolute3, join as join15, relative as relative4 } from "node:path";
|
|
24605
24798
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24606
24799
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24607
24800
|
}
|
|
@@ -24613,7 +24806,7 @@ function fail4(id2, detail, fixCommand) {
|
|
|
24613
24806
|
}
|
|
24614
24807
|
function bundleVersion(bundleDir2) {
|
|
24615
24808
|
try {
|
|
24616
|
-
const v = JSON.parse(
|
|
24809
|
+
const v = JSON.parse(readFileSync11(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24617
24810
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24618
24811
|
} catch {
|
|
24619
24812
|
return void 0;
|
|
@@ -24697,20 +24890,20 @@ function highestTag(stdout, tag2) {
|
|
|
24697
24890
|
}
|
|
24698
24891
|
return best;
|
|
24699
24892
|
}
|
|
24700
|
-
function versionRow(
|
|
24893
|
+
function versionRow(head2, installed, tag2, source, latest, tail) {
|
|
24701
24894
|
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
24702
|
-
if (cmp === 0) return pass3("D1",
|
|
24703
|
-
if (cmp > 0) return pass3("D1",
|
|
24704
|
-
return fail4("D1",
|
|
24895
|
+
if (cmp === 0) return pass3("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
|
|
24896
|
+
if (cmp > 0) return pass3("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
|
|
24897
|
+
return fail4("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, DOCTOR_FIX_UPGRADE);
|
|
24705
24898
|
}
|
|
24706
24899
|
async function checkVersion(i) {
|
|
24707
24900
|
if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
|
|
24708
|
-
const
|
|
24709
|
-
if (i.version === void 0) return unknown3("D1",
|
|
24901
|
+
const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24902
|
+
if (i.version === void 0) return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24710
24903
|
const tag2 = channelOf(i.version);
|
|
24711
24904
|
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24712
24905
|
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24713
|
-
if (npm.ok) return versionRow(
|
|
24906
|
+
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
24714
24907
|
let cause = D1_GIT_MISSING;
|
|
24715
24908
|
if (git2 !== null) {
|
|
24716
24909
|
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
@@ -24721,13 +24914,13 @@ async function checkVersion(i) {
|
|
|
24721
24914
|
});
|
|
24722
24915
|
if (r.exitCode === 0 && r.killed === null) {
|
|
24723
24916
|
const latest = highestTag(r.stdout.toString("utf8"), tag2);
|
|
24724
|
-
if (latest !== void 0) return versionRow(
|
|
24917
|
+
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
|
|
24725
24918
|
cause = D1_GIT_NO_TAG(tag2);
|
|
24726
24919
|
} else {
|
|
24727
24920
|
cause = gitCause(r, i.timeoutMs);
|
|
24728
24921
|
}
|
|
24729
24922
|
}
|
|
24730
|
-
return unknown3("D1",
|
|
24923
|
+
return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
24731
24924
|
}
|
|
24732
24925
|
function numbers(v) {
|
|
24733
24926
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -24763,7 +24956,7 @@ function checkMcp(ctx) {
|
|
|
24763
24956
|
return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
24764
24957
|
}
|
|
24765
24958
|
function piCwdInside(worktree, piCwd) {
|
|
24766
|
-
if (piCwd === void 0 || !
|
|
24959
|
+
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
24767
24960
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24768
24961
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24769
24962
|
}
|
|
@@ -24773,7 +24966,9 @@ function checkProject(i) {
|
|
|
24773
24966
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
24774
24967
|
return pass3("D7");
|
|
24775
24968
|
}
|
|
24776
|
-
function checkMode(adapter) {
|
|
24969
|
+
function checkMode(adapter, hostPermission) {
|
|
24970
|
+
if (hostPermission === "missing") return fail4("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
24971
|
+
if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
24777
24972
|
return pass3("D10", D10_DETAIL(adapter.denyChannel));
|
|
24778
24973
|
}
|
|
24779
24974
|
function checkShell(env) {
|
|
@@ -24784,60 +24979,1871 @@ function checkShell(env) {
|
|
|
24784
24979
|
}
|
|
24785
24980
|
|
|
24786
24981
|
// src/core/ops/doctor-hook.ts
|
|
24787
|
-
import { existsSync as
|
|
24982
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync12, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24788
24983
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24789
24984
|
import path7 from "node:path";
|
|
24790
24985
|
|
|
24791
|
-
//
|
|
24792
|
-
var
|
|
24793
|
-
|
|
24794
|
-
|
|
24795
|
-
|
|
24796
|
-
|
|
24797
|
-
|
|
24798
|
-
|
|
24799
|
-
|
|
24800
|
-
|
|
24801
|
-
|
|
24802
|
-
|
|
24803
|
-
|
|
24804
|
-
|
|
24805
|
-
|
|
24806
|
-
|
|
24807
|
-
|
|
24808
|
-
|
|
24809
|
-
|
|
24810
|
-
|
|
24811
|
-
|
|
24812
|
-
|
|
24813
|
-
|
|
24814
|
-
|
|
24815
|
-
}
|
|
24816
|
-
|
|
24817
|
-
|
|
24818
|
-
|
|
24819
|
-
|
|
24820
|
-
|
|
24821
|
-
|
|
24822
|
-
|
|
24823
|
-
|
|
24824
|
-
|
|
24825
|
-
|
|
24826
|
-
|
|
24827
|
-
|
|
24986
|
+
// tests/fixtures/host-schemas/claude-code.json
|
|
24987
|
+
var claude_code_default = {
|
|
24988
|
+
host: "claude-code",
|
|
24989
|
+
source: "Claude Code 2.1.274 native binary, zod hook output schemas: top level eW, hookSpecificOutput union members xF (PreToolUse, permissionDecision enum FK), DF (UserPromptSubmit), UF (SessionStart), the PostToolUse member. zod drops keys it does not read, so each object lists only the keys the host reads.",
|
|
24990
|
+
output: {
|
|
24991
|
+
PreToolUse: {
|
|
24992
|
+
title: "Claude Code 2.1.274 PreToolUse reply",
|
|
24993
|
+
definitions: {
|
|
24994
|
+
Specific: {
|
|
24995
|
+
type: "object",
|
|
24996
|
+
additionalProperties: false,
|
|
24997
|
+
properties: {
|
|
24998
|
+
hookEventName: {
|
|
24999
|
+
type: "string",
|
|
25000
|
+
const: "PreToolUse"
|
|
25001
|
+
},
|
|
25002
|
+
permissionDecision: {
|
|
25003
|
+
type: "string",
|
|
25004
|
+
enum: [
|
|
25005
|
+
"allow",
|
|
25006
|
+
"deny",
|
|
25007
|
+
"ask",
|
|
25008
|
+
"defer"
|
|
25009
|
+
]
|
|
25010
|
+
},
|
|
25011
|
+
permissionDecisionReason: {
|
|
25012
|
+
type: "string"
|
|
25013
|
+
},
|
|
25014
|
+
updatedInput: {
|
|
25015
|
+
type: "object"
|
|
25016
|
+
},
|
|
25017
|
+
additionalContext: {
|
|
25018
|
+
type: "string"
|
|
25019
|
+
},
|
|
25020
|
+
permissionDisplay: {
|
|
25021
|
+
description: "@internal Desktop host only"
|
|
25022
|
+
}
|
|
25023
|
+
},
|
|
25024
|
+
required: [
|
|
25025
|
+
"hookEventName"
|
|
25026
|
+
]
|
|
25027
|
+
}
|
|
25028
|
+
},
|
|
25029
|
+
type: "object",
|
|
25030
|
+
additionalProperties: false,
|
|
25031
|
+
properties: {
|
|
25032
|
+
continue: {
|
|
25033
|
+
type: "boolean"
|
|
25034
|
+
},
|
|
25035
|
+
suppressOutput: {
|
|
25036
|
+
type: "boolean"
|
|
25037
|
+
},
|
|
25038
|
+
stopReason: {
|
|
25039
|
+
type: "string"
|
|
25040
|
+
},
|
|
25041
|
+
decision: {
|
|
25042
|
+
type: "string",
|
|
25043
|
+
enum: [
|
|
25044
|
+
"approve",
|
|
25045
|
+
"block"
|
|
25046
|
+
]
|
|
25047
|
+
},
|
|
25048
|
+
systemMessage: {
|
|
25049
|
+
type: "string"
|
|
25050
|
+
},
|
|
25051
|
+
terminalSequence: {
|
|
25052
|
+
type: "string"
|
|
25053
|
+
},
|
|
25054
|
+
reason: {
|
|
25055
|
+
type: "string"
|
|
25056
|
+
},
|
|
25057
|
+
hookSpecificOutput: {
|
|
25058
|
+
allOf: [
|
|
25059
|
+
{
|
|
25060
|
+
$ref: "#/definitions/Specific"
|
|
25061
|
+
}
|
|
25062
|
+
]
|
|
25063
|
+
}
|
|
24828
25064
|
}
|
|
24829
|
-
}
|
|
24830
|
-
|
|
24831
|
-
|
|
24832
|
-
|
|
24833
|
-
|
|
24834
|
-
|
|
24835
|
-
|
|
24836
|
-
|
|
24837
|
-
|
|
24838
|
-
|
|
24839
|
-
|
|
24840
|
-
|
|
25065
|
+
},
|
|
25066
|
+
PostToolUse: {
|
|
25067
|
+
title: "Claude Code 2.1.274 PostToolUse reply",
|
|
25068
|
+
definitions: {
|
|
25069
|
+
Specific: {
|
|
25070
|
+
type: "object",
|
|
25071
|
+
additionalProperties: false,
|
|
25072
|
+
properties: {
|
|
25073
|
+
hookEventName: {
|
|
25074
|
+
type: "string",
|
|
25075
|
+
const: "PostToolUse"
|
|
25076
|
+
},
|
|
25077
|
+
additionalContext: {
|
|
25078
|
+
type: "string"
|
|
25079
|
+
},
|
|
25080
|
+
classifierContext: {
|
|
25081
|
+
type: "string"
|
|
25082
|
+
},
|
|
25083
|
+
updatedToolOutput: {
|
|
25084
|
+
description: "the tool's own output object"
|
|
25085
|
+
},
|
|
25086
|
+
updatedMCPToolOutput: {
|
|
25087
|
+
description: "an MCP tool's own output"
|
|
25088
|
+
}
|
|
25089
|
+
},
|
|
25090
|
+
required: [
|
|
25091
|
+
"hookEventName"
|
|
25092
|
+
]
|
|
25093
|
+
}
|
|
25094
|
+
},
|
|
25095
|
+
type: "object",
|
|
25096
|
+
additionalProperties: false,
|
|
25097
|
+
properties: {
|
|
25098
|
+
continue: {
|
|
25099
|
+
type: "boolean"
|
|
25100
|
+
},
|
|
25101
|
+
suppressOutput: {
|
|
25102
|
+
type: "boolean"
|
|
25103
|
+
},
|
|
25104
|
+
stopReason: {
|
|
25105
|
+
type: "string"
|
|
25106
|
+
},
|
|
25107
|
+
decision: {
|
|
25108
|
+
type: "string",
|
|
25109
|
+
enum: [
|
|
25110
|
+
"approve",
|
|
25111
|
+
"block"
|
|
25112
|
+
]
|
|
25113
|
+
},
|
|
25114
|
+
systemMessage: {
|
|
25115
|
+
type: "string"
|
|
25116
|
+
},
|
|
25117
|
+
terminalSequence: {
|
|
25118
|
+
type: "string"
|
|
25119
|
+
},
|
|
25120
|
+
reason: {
|
|
25121
|
+
type: "string"
|
|
25122
|
+
},
|
|
25123
|
+
hookSpecificOutput: {
|
|
25124
|
+
allOf: [
|
|
25125
|
+
{
|
|
25126
|
+
$ref: "#/definitions/Specific"
|
|
25127
|
+
}
|
|
25128
|
+
]
|
|
25129
|
+
}
|
|
25130
|
+
}
|
|
25131
|
+
},
|
|
25132
|
+
UserPromptSubmit: {
|
|
25133
|
+
title: "Claude Code 2.1.274 UserPromptSubmit reply",
|
|
25134
|
+
definitions: {
|
|
25135
|
+
Specific: {
|
|
25136
|
+
type: "object",
|
|
25137
|
+
additionalProperties: false,
|
|
25138
|
+
properties: {
|
|
25139
|
+
hookEventName: {
|
|
25140
|
+
type: "string",
|
|
25141
|
+
const: "UserPromptSubmit"
|
|
25142
|
+
},
|
|
25143
|
+
additionalContext: {
|
|
25144
|
+
type: "string"
|
|
25145
|
+
},
|
|
25146
|
+
sessionTitle: {
|
|
25147
|
+
type: "string"
|
|
25148
|
+
},
|
|
25149
|
+
suppressOriginalPrompt: {
|
|
25150
|
+
type: "boolean"
|
|
25151
|
+
}
|
|
25152
|
+
},
|
|
25153
|
+
required: [
|
|
25154
|
+
"hookEventName"
|
|
25155
|
+
]
|
|
25156
|
+
}
|
|
25157
|
+
},
|
|
25158
|
+
type: "object",
|
|
25159
|
+
additionalProperties: false,
|
|
25160
|
+
properties: {
|
|
25161
|
+
continue: {
|
|
25162
|
+
type: "boolean"
|
|
25163
|
+
},
|
|
25164
|
+
suppressOutput: {
|
|
25165
|
+
type: "boolean"
|
|
25166
|
+
},
|
|
25167
|
+
stopReason: {
|
|
25168
|
+
type: "string"
|
|
25169
|
+
},
|
|
25170
|
+
decision: {
|
|
25171
|
+
type: "string",
|
|
25172
|
+
enum: [
|
|
25173
|
+
"approve",
|
|
25174
|
+
"block"
|
|
25175
|
+
]
|
|
25176
|
+
},
|
|
25177
|
+
systemMessage: {
|
|
25178
|
+
type: "string"
|
|
25179
|
+
},
|
|
25180
|
+
terminalSequence: {
|
|
25181
|
+
type: "string"
|
|
25182
|
+
},
|
|
25183
|
+
reason: {
|
|
25184
|
+
type: "string"
|
|
25185
|
+
},
|
|
25186
|
+
hookSpecificOutput: {
|
|
25187
|
+
allOf: [
|
|
25188
|
+
{
|
|
25189
|
+
$ref: "#/definitions/Specific"
|
|
25190
|
+
}
|
|
25191
|
+
]
|
|
25192
|
+
}
|
|
25193
|
+
}
|
|
25194
|
+
},
|
|
25195
|
+
SessionStart: {
|
|
25196
|
+
title: "Claude Code 2.1.274 SessionStart reply",
|
|
25197
|
+
definitions: {
|
|
25198
|
+
Specific: {
|
|
25199
|
+
type: "object",
|
|
25200
|
+
additionalProperties: false,
|
|
25201
|
+
properties: {
|
|
25202
|
+
hookEventName: {
|
|
25203
|
+
type: "string",
|
|
25204
|
+
const: "SessionStart"
|
|
25205
|
+
},
|
|
25206
|
+
additionalContext: {
|
|
25207
|
+
type: "string"
|
|
25208
|
+
},
|
|
25209
|
+
initialUserMessage: {
|
|
25210
|
+
type: "string"
|
|
25211
|
+
},
|
|
25212
|
+
sessionTitle: {
|
|
25213
|
+
type: "string"
|
|
25214
|
+
},
|
|
25215
|
+
watchPaths: {
|
|
25216
|
+
type: "array",
|
|
25217
|
+
items: {
|
|
25218
|
+
type: "string"
|
|
25219
|
+
}
|
|
25220
|
+
},
|
|
25221
|
+
reloadSkills: {
|
|
25222
|
+
type: "boolean"
|
|
25223
|
+
}
|
|
25224
|
+
},
|
|
25225
|
+
required: [
|
|
25226
|
+
"hookEventName"
|
|
25227
|
+
]
|
|
25228
|
+
}
|
|
25229
|
+
},
|
|
25230
|
+
type: "object",
|
|
25231
|
+
additionalProperties: false,
|
|
25232
|
+
properties: {
|
|
25233
|
+
continue: {
|
|
25234
|
+
type: "boolean"
|
|
25235
|
+
},
|
|
25236
|
+
suppressOutput: {
|
|
25237
|
+
type: "boolean"
|
|
25238
|
+
},
|
|
25239
|
+
stopReason: {
|
|
25240
|
+
type: "string"
|
|
25241
|
+
},
|
|
25242
|
+
decision: {
|
|
25243
|
+
type: "string",
|
|
25244
|
+
enum: [
|
|
25245
|
+
"approve",
|
|
25246
|
+
"block"
|
|
25247
|
+
]
|
|
25248
|
+
},
|
|
25249
|
+
systemMessage: {
|
|
25250
|
+
type: "string"
|
|
25251
|
+
},
|
|
25252
|
+
terminalSequence: {
|
|
25253
|
+
type: "string"
|
|
25254
|
+
},
|
|
25255
|
+
reason: {
|
|
25256
|
+
type: "string"
|
|
25257
|
+
},
|
|
25258
|
+
hookSpecificOutput: {
|
|
25259
|
+
allOf: [
|
|
25260
|
+
{
|
|
25261
|
+
$ref: "#/definitions/Specific"
|
|
25262
|
+
}
|
|
25263
|
+
]
|
|
25264
|
+
}
|
|
25265
|
+
}
|
|
25266
|
+
}
|
|
25267
|
+
}
|
|
25268
|
+
};
|
|
25269
|
+
|
|
25270
|
+
// tests/fixtures/host-schemas/codex.json
|
|
25271
|
+
var codex_default = {
|
|
25272
|
+
host: "codex",
|
|
25273
|
+
source: "github.com/openai/codex tag rust-v0.166.0 codex-rs/hooks/schema/generated/*.command.output.schema.json",
|
|
25274
|
+
output: {
|
|
25275
|
+
PreToolUse: {
|
|
25276
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
25277
|
+
additionalProperties: false,
|
|
25278
|
+
definitions: {
|
|
25279
|
+
PreToolUseDecisionWire: {
|
|
25280
|
+
enum: [
|
|
25281
|
+
"approve",
|
|
25282
|
+
"block"
|
|
25283
|
+
],
|
|
25284
|
+
type: "string"
|
|
25285
|
+
},
|
|
25286
|
+
PreToolUseHookSpecificOutputWire: {
|
|
25287
|
+
additionalProperties: false,
|
|
25288
|
+
properties: {
|
|
25289
|
+
additionalContext: {
|
|
25290
|
+
default: null,
|
|
25291
|
+
type: "string"
|
|
25292
|
+
},
|
|
25293
|
+
hookEventName: {
|
|
25294
|
+
const: "PreToolUse",
|
|
25295
|
+
type: "string"
|
|
25296
|
+
},
|
|
25297
|
+
permissionDecision: {
|
|
25298
|
+
allOf: [
|
|
25299
|
+
{
|
|
25300
|
+
$ref: "#/definitions/PreToolUsePermissionDecisionWire"
|
|
25301
|
+
}
|
|
25302
|
+
],
|
|
25303
|
+
default: null
|
|
25304
|
+
},
|
|
25305
|
+
permissionDecisionReason: {
|
|
25306
|
+
default: null,
|
|
25307
|
+
type: "string"
|
|
25308
|
+
},
|
|
25309
|
+
updatedInput: {
|
|
25310
|
+
default: null
|
|
25311
|
+
}
|
|
25312
|
+
},
|
|
25313
|
+
required: [
|
|
25314
|
+
"hookEventName"
|
|
25315
|
+
],
|
|
25316
|
+
type: "object"
|
|
25317
|
+
},
|
|
25318
|
+
PreToolUsePermissionDecisionWire: {
|
|
25319
|
+
enum: [
|
|
25320
|
+
"allow",
|
|
25321
|
+
"deny",
|
|
25322
|
+
"ask"
|
|
25323
|
+
],
|
|
25324
|
+
type: "string"
|
|
25325
|
+
}
|
|
25326
|
+
},
|
|
25327
|
+
properties: {
|
|
25328
|
+
continue: {
|
|
25329
|
+
default: true,
|
|
25330
|
+
type: "boolean"
|
|
25331
|
+
},
|
|
25332
|
+
decision: {
|
|
25333
|
+
allOf: [
|
|
25334
|
+
{
|
|
25335
|
+
$ref: "#/definitions/PreToolUseDecisionWire"
|
|
25336
|
+
}
|
|
25337
|
+
],
|
|
25338
|
+
default: null
|
|
25339
|
+
},
|
|
25340
|
+
hookSpecificOutput: {
|
|
25341
|
+
allOf: [
|
|
25342
|
+
{
|
|
25343
|
+
$ref: "#/definitions/PreToolUseHookSpecificOutputWire"
|
|
25344
|
+
}
|
|
25345
|
+
],
|
|
25346
|
+
default: null
|
|
25347
|
+
},
|
|
25348
|
+
reason: {
|
|
25349
|
+
default: null,
|
|
25350
|
+
type: "string"
|
|
25351
|
+
},
|
|
25352
|
+
stopReason: {
|
|
25353
|
+
default: null,
|
|
25354
|
+
type: "string"
|
|
25355
|
+
},
|
|
25356
|
+
suppressOutput: {
|
|
25357
|
+
default: false,
|
|
25358
|
+
type: "boolean"
|
|
25359
|
+
},
|
|
25360
|
+
systemMessage: {
|
|
25361
|
+
default: null,
|
|
25362
|
+
type: "string"
|
|
25363
|
+
}
|
|
25364
|
+
},
|
|
25365
|
+
title: "pre-tool-use.command.output",
|
|
25366
|
+
type: "object"
|
|
25367
|
+
},
|
|
25368
|
+
PostToolUse: {
|
|
25369
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
25370
|
+
additionalProperties: false,
|
|
25371
|
+
definitions: {
|
|
25372
|
+
BlockDecisionWire: {
|
|
25373
|
+
enum: [
|
|
25374
|
+
"block"
|
|
25375
|
+
],
|
|
25376
|
+
type: "string"
|
|
25377
|
+
},
|
|
25378
|
+
PostToolUseHookSpecificOutputWire: {
|
|
25379
|
+
additionalProperties: false,
|
|
25380
|
+
properties: {
|
|
25381
|
+
additionalContext: {
|
|
25382
|
+
default: null,
|
|
25383
|
+
type: "string"
|
|
25384
|
+
},
|
|
25385
|
+
hookEventName: {
|
|
25386
|
+
const: "PostToolUse",
|
|
25387
|
+
type: "string"
|
|
25388
|
+
},
|
|
25389
|
+
updatedMCPToolOutput: {
|
|
25390
|
+
default: null
|
|
25391
|
+
}
|
|
25392
|
+
},
|
|
25393
|
+
required: [
|
|
25394
|
+
"hookEventName"
|
|
25395
|
+
],
|
|
25396
|
+
type: "object"
|
|
25397
|
+
}
|
|
25398
|
+
},
|
|
25399
|
+
properties: {
|
|
25400
|
+
continue: {
|
|
25401
|
+
default: true,
|
|
25402
|
+
type: "boolean"
|
|
25403
|
+
},
|
|
25404
|
+
decision: {
|
|
25405
|
+
allOf: [
|
|
25406
|
+
{
|
|
25407
|
+
$ref: "#/definitions/BlockDecisionWire"
|
|
25408
|
+
}
|
|
25409
|
+
],
|
|
25410
|
+
default: null
|
|
25411
|
+
},
|
|
25412
|
+
hookSpecificOutput: {
|
|
25413
|
+
allOf: [
|
|
25414
|
+
{
|
|
25415
|
+
$ref: "#/definitions/PostToolUseHookSpecificOutputWire"
|
|
25416
|
+
}
|
|
25417
|
+
],
|
|
25418
|
+
default: null
|
|
25419
|
+
},
|
|
25420
|
+
reason: {
|
|
25421
|
+
default: null,
|
|
25422
|
+
type: "string"
|
|
25423
|
+
},
|
|
25424
|
+
stopReason: {
|
|
25425
|
+
default: null,
|
|
25426
|
+
type: "string"
|
|
25427
|
+
},
|
|
25428
|
+
suppressOutput: {
|
|
25429
|
+
default: false,
|
|
25430
|
+
type: "boolean"
|
|
25431
|
+
},
|
|
25432
|
+
systemMessage: {
|
|
25433
|
+
default: null,
|
|
25434
|
+
type: "string"
|
|
25435
|
+
}
|
|
25436
|
+
},
|
|
25437
|
+
title: "post-tool-use.command.output",
|
|
25438
|
+
type: "object"
|
|
25439
|
+
},
|
|
25440
|
+
SessionStart: {
|
|
25441
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
25442
|
+
additionalProperties: false,
|
|
25443
|
+
definitions: {
|
|
25444
|
+
SessionStartHookSpecificOutputWire: {
|
|
25445
|
+
additionalProperties: false,
|
|
25446
|
+
properties: {
|
|
25447
|
+
additionalContext: {
|
|
25448
|
+
default: null,
|
|
25449
|
+
type: "string"
|
|
25450
|
+
},
|
|
25451
|
+
hookEventName: {
|
|
25452
|
+
const: "SessionStart",
|
|
25453
|
+
type: "string"
|
|
25454
|
+
}
|
|
25455
|
+
},
|
|
25456
|
+
required: [
|
|
25457
|
+
"hookEventName"
|
|
25458
|
+
],
|
|
25459
|
+
type: "object"
|
|
25460
|
+
}
|
|
25461
|
+
},
|
|
25462
|
+
properties: {
|
|
25463
|
+
continue: {
|
|
25464
|
+
default: true,
|
|
25465
|
+
type: "boolean"
|
|
25466
|
+
},
|
|
25467
|
+
hookSpecificOutput: {
|
|
25468
|
+
allOf: [
|
|
25469
|
+
{
|
|
25470
|
+
$ref: "#/definitions/SessionStartHookSpecificOutputWire"
|
|
25471
|
+
}
|
|
25472
|
+
],
|
|
25473
|
+
default: null
|
|
25474
|
+
},
|
|
25475
|
+
stopReason: {
|
|
25476
|
+
default: null,
|
|
25477
|
+
type: "string"
|
|
25478
|
+
},
|
|
25479
|
+
suppressOutput: {
|
|
25480
|
+
default: false,
|
|
25481
|
+
type: "boolean"
|
|
25482
|
+
},
|
|
25483
|
+
systemMessage: {
|
|
25484
|
+
default: null,
|
|
25485
|
+
type: "string"
|
|
25486
|
+
}
|
|
25487
|
+
},
|
|
25488
|
+
title: "session-start.command.output",
|
|
25489
|
+
type: "object"
|
|
25490
|
+
},
|
|
25491
|
+
UserPromptSubmit: {
|
|
25492
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
25493
|
+
additionalProperties: false,
|
|
25494
|
+
definitions: {
|
|
25495
|
+
BlockDecisionWire: {
|
|
25496
|
+
enum: [
|
|
25497
|
+
"block"
|
|
25498
|
+
],
|
|
25499
|
+
type: "string"
|
|
25500
|
+
},
|
|
25501
|
+
UserPromptSubmitHookSpecificOutputWire: {
|
|
25502
|
+
additionalProperties: false,
|
|
25503
|
+
properties: {
|
|
25504
|
+
additionalContext: {
|
|
25505
|
+
default: null,
|
|
25506
|
+
type: "string"
|
|
25507
|
+
},
|
|
25508
|
+
hookEventName: {
|
|
25509
|
+
const: "UserPromptSubmit",
|
|
25510
|
+
type: "string"
|
|
25511
|
+
}
|
|
25512
|
+
},
|
|
25513
|
+
required: [
|
|
25514
|
+
"hookEventName"
|
|
25515
|
+
],
|
|
25516
|
+
type: "object"
|
|
25517
|
+
}
|
|
25518
|
+
},
|
|
25519
|
+
properties: {
|
|
25520
|
+
continue: {
|
|
25521
|
+
default: true,
|
|
25522
|
+
type: "boolean"
|
|
25523
|
+
},
|
|
25524
|
+
decision: {
|
|
25525
|
+
allOf: [
|
|
25526
|
+
{
|
|
25527
|
+
$ref: "#/definitions/BlockDecisionWire"
|
|
25528
|
+
}
|
|
25529
|
+
],
|
|
25530
|
+
default: null
|
|
25531
|
+
},
|
|
25532
|
+
hookSpecificOutput: {
|
|
25533
|
+
allOf: [
|
|
25534
|
+
{
|
|
25535
|
+
$ref: "#/definitions/UserPromptSubmitHookSpecificOutputWire"
|
|
25536
|
+
}
|
|
25537
|
+
],
|
|
25538
|
+
default: null
|
|
25539
|
+
},
|
|
25540
|
+
reason: {
|
|
25541
|
+
default: null,
|
|
25542
|
+
type: "string"
|
|
25543
|
+
},
|
|
25544
|
+
stopReason: {
|
|
25545
|
+
default: null,
|
|
25546
|
+
type: "string"
|
|
25547
|
+
},
|
|
25548
|
+
suppressOutput: {
|
|
25549
|
+
default: false,
|
|
25550
|
+
type: "boolean"
|
|
25551
|
+
},
|
|
25552
|
+
systemMessage: {
|
|
25553
|
+
default: null,
|
|
25554
|
+
type: "string"
|
|
25555
|
+
}
|
|
25556
|
+
},
|
|
25557
|
+
title: "user-prompt-submit.command.output",
|
|
25558
|
+
type: "object"
|
|
25559
|
+
},
|
|
25560
|
+
Stop: {
|
|
25561
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
25562
|
+
additionalProperties: false,
|
|
25563
|
+
definitions: {
|
|
25564
|
+
BlockDecisionWire: {
|
|
25565
|
+
enum: [
|
|
25566
|
+
"block"
|
|
25567
|
+
],
|
|
25568
|
+
type: "string"
|
|
25569
|
+
}
|
|
25570
|
+
},
|
|
25571
|
+
properties: {
|
|
25572
|
+
continue: {
|
|
25573
|
+
default: true,
|
|
25574
|
+
type: "boolean"
|
|
25575
|
+
},
|
|
25576
|
+
decision: {
|
|
25577
|
+
allOf: [
|
|
25578
|
+
{
|
|
25579
|
+
$ref: "#/definitions/BlockDecisionWire"
|
|
25580
|
+
}
|
|
25581
|
+
],
|
|
25582
|
+
default: null
|
|
25583
|
+
},
|
|
25584
|
+
reason: {
|
|
25585
|
+
default: null,
|
|
25586
|
+
description: "Claude requires `reason` when `decision` is `block`; we enforce that semantic rule during output parsing rather than in the JSON schema.",
|
|
25587
|
+
type: "string"
|
|
25588
|
+
},
|
|
25589
|
+
stopReason: {
|
|
25590
|
+
default: null,
|
|
25591
|
+
type: "string"
|
|
25592
|
+
},
|
|
25593
|
+
suppressOutput: {
|
|
25594
|
+
default: false,
|
|
25595
|
+
type: "boolean"
|
|
25596
|
+
},
|
|
25597
|
+
systemMessage: {
|
|
25598
|
+
default: null,
|
|
25599
|
+
type: "string"
|
|
25600
|
+
}
|
|
25601
|
+
},
|
|
25602
|
+
title: "stop.command.output",
|
|
25603
|
+
type: "object"
|
|
25604
|
+
}
|
|
25605
|
+
}
|
|
25606
|
+
};
|
|
25607
|
+
|
|
25608
|
+
// tests/fixtures/host-schemas/gemini.json
|
|
25609
|
+
var gemini_default = {
|
|
25610
|
+
host: "gemini",
|
|
25611
|
+
source: "@google/gemini-cli 0.67.0: bundle/docs/hooks/reference.md (Common output fields; BeforeTool, AfterTool, BeforeAgent, SessionStart output fields) and bundle/chunk-O7MGOE2I.js HookOutput (isBlockingDecision block|deny, isAskDecision ask). Keys are canonical events; each title names the native event.",
|
|
25612
|
+
output: {
|
|
25613
|
+
PreToolUse: {
|
|
25614
|
+
title: "Gemini CLI 0.67.0 BeforeTool reply",
|
|
25615
|
+
definitions: {
|
|
25616
|
+
Specific: {
|
|
25617
|
+
type: "object",
|
|
25618
|
+
additionalProperties: false,
|
|
25619
|
+
properties: {
|
|
25620
|
+
hookEventName: {
|
|
25621
|
+
type: "string"
|
|
25622
|
+
},
|
|
25623
|
+
tool_input: {
|
|
25624
|
+
type: "object"
|
|
25625
|
+
}
|
|
25626
|
+
}
|
|
25627
|
+
}
|
|
25628
|
+
},
|
|
25629
|
+
type: "object",
|
|
25630
|
+
additionalProperties: false,
|
|
25631
|
+
properties: {
|
|
25632
|
+
systemMessage: {
|
|
25633
|
+
type: "string"
|
|
25634
|
+
},
|
|
25635
|
+
suppressOutput: {
|
|
25636
|
+
type: "boolean"
|
|
25637
|
+
},
|
|
25638
|
+
continue: {
|
|
25639
|
+
type: "boolean"
|
|
25640
|
+
},
|
|
25641
|
+
stopReason: {
|
|
25642
|
+
type: "string"
|
|
25643
|
+
},
|
|
25644
|
+
decision: {
|
|
25645
|
+
type: "string",
|
|
25646
|
+
enum: [
|
|
25647
|
+
"allow",
|
|
25648
|
+
"deny",
|
|
25649
|
+
"block",
|
|
25650
|
+
"ask"
|
|
25651
|
+
]
|
|
25652
|
+
},
|
|
25653
|
+
reason: {
|
|
25654
|
+
type: "string"
|
|
25655
|
+
},
|
|
25656
|
+
hookSpecificOutput: {
|
|
25657
|
+
allOf: [
|
|
25658
|
+
{
|
|
25659
|
+
$ref: "#/definitions/Specific"
|
|
25660
|
+
}
|
|
25661
|
+
]
|
|
25662
|
+
}
|
|
25663
|
+
}
|
|
25664
|
+
},
|
|
25665
|
+
PostToolUse: {
|
|
25666
|
+
title: "Gemini CLI 0.67.0 AfterTool reply",
|
|
25667
|
+
definitions: {
|
|
25668
|
+
Specific: {
|
|
25669
|
+
type: "object",
|
|
25670
|
+
additionalProperties: false,
|
|
25671
|
+
properties: {
|
|
25672
|
+
hookEventName: {
|
|
25673
|
+
type: "string"
|
|
25674
|
+
},
|
|
25675
|
+
additionalContext: {
|
|
25676
|
+
type: "string"
|
|
25677
|
+
},
|
|
25678
|
+
tailToolCallRequest: {
|
|
25679
|
+
type: "object",
|
|
25680
|
+
additionalProperties: false,
|
|
25681
|
+
properties: {
|
|
25682
|
+
name: {
|
|
25683
|
+
type: "string"
|
|
25684
|
+
},
|
|
25685
|
+
args: {
|
|
25686
|
+
type: "object"
|
|
25687
|
+
}
|
|
25688
|
+
},
|
|
25689
|
+
required: [
|
|
25690
|
+
"name",
|
|
25691
|
+
"args"
|
|
25692
|
+
]
|
|
25693
|
+
}
|
|
25694
|
+
}
|
|
25695
|
+
}
|
|
25696
|
+
},
|
|
25697
|
+
type: "object",
|
|
25698
|
+
additionalProperties: false,
|
|
25699
|
+
properties: {
|
|
25700
|
+
systemMessage: {
|
|
25701
|
+
type: "string"
|
|
25702
|
+
},
|
|
25703
|
+
suppressOutput: {
|
|
25704
|
+
type: "boolean"
|
|
25705
|
+
},
|
|
25706
|
+
continue: {
|
|
25707
|
+
type: "boolean"
|
|
25708
|
+
},
|
|
25709
|
+
stopReason: {
|
|
25710
|
+
type: "string"
|
|
25711
|
+
},
|
|
25712
|
+
decision: {
|
|
25713
|
+
type: "string",
|
|
25714
|
+
enum: [
|
|
25715
|
+
"allow",
|
|
25716
|
+
"deny",
|
|
25717
|
+
"block",
|
|
25718
|
+
"ask"
|
|
25719
|
+
]
|
|
25720
|
+
},
|
|
25721
|
+
reason: {
|
|
25722
|
+
type: "string"
|
|
25723
|
+
},
|
|
25724
|
+
hookSpecificOutput: {
|
|
25725
|
+
allOf: [
|
|
25726
|
+
{
|
|
25727
|
+
$ref: "#/definitions/Specific"
|
|
25728
|
+
}
|
|
25729
|
+
]
|
|
25730
|
+
}
|
|
25731
|
+
}
|
|
25732
|
+
},
|
|
25733
|
+
UserPromptSubmit: {
|
|
25734
|
+
title: "Gemini CLI 0.67.0 BeforeAgent reply",
|
|
25735
|
+
definitions: {
|
|
25736
|
+
Specific: {
|
|
25737
|
+
type: "object",
|
|
25738
|
+
additionalProperties: false,
|
|
25739
|
+
properties: {
|
|
25740
|
+
hookEventName: {
|
|
25741
|
+
type: "string"
|
|
25742
|
+
},
|
|
25743
|
+
additionalContext: {
|
|
25744
|
+
type: "string"
|
|
25745
|
+
}
|
|
25746
|
+
}
|
|
25747
|
+
}
|
|
25748
|
+
},
|
|
25749
|
+
type: "object",
|
|
25750
|
+
additionalProperties: false,
|
|
25751
|
+
properties: {
|
|
25752
|
+
systemMessage: {
|
|
25753
|
+
type: "string"
|
|
25754
|
+
},
|
|
25755
|
+
suppressOutput: {
|
|
25756
|
+
type: "boolean"
|
|
25757
|
+
},
|
|
25758
|
+
continue: {
|
|
25759
|
+
type: "boolean"
|
|
25760
|
+
},
|
|
25761
|
+
stopReason: {
|
|
25762
|
+
type: "string"
|
|
25763
|
+
},
|
|
25764
|
+
decision: {
|
|
25765
|
+
type: "string",
|
|
25766
|
+
enum: [
|
|
25767
|
+
"allow",
|
|
25768
|
+
"deny",
|
|
25769
|
+
"block",
|
|
25770
|
+
"ask"
|
|
25771
|
+
]
|
|
25772
|
+
},
|
|
25773
|
+
reason: {
|
|
25774
|
+
type: "string"
|
|
25775
|
+
},
|
|
25776
|
+
hookSpecificOutput: {
|
|
25777
|
+
allOf: [
|
|
25778
|
+
{
|
|
25779
|
+
$ref: "#/definitions/Specific"
|
|
25780
|
+
}
|
|
25781
|
+
]
|
|
25782
|
+
}
|
|
25783
|
+
}
|
|
25784
|
+
},
|
|
25785
|
+
SessionStart: {
|
|
25786
|
+
title: "Gemini CLI 0.67.0 SessionStart reply",
|
|
25787
|
+
definitions: {
|
|
25788
|
+
Specific: {
|
|
25789
|
+
type: "object",
|
|
25790
|
+
additionalProperties: false,
|
|
25791
|
+
properties: {
|
|
25792
|
+
hookEventName: {
|
|
25793
|
+
type: "string"
|
|
25794
|
+
},
|
|
25795
|
+
additionalContext: {
|
|
25796
|
+
type: "string"
|
|
25797
|
+
}
|
|
25798
|
+
}
|
|
25799
|
+
}
|
|
25800
|
+
},
|
|
25801
|
+
type: "object",
|
|
25802
|
+
additionalProperties: false,
|
|
25803
|
+
properties: {
|
|
25804
|
+
systemMessage: {
|
|
25805
|
+
type: "string"
|
|
25806
|
+
},
|
|
25807
|
+
suppressOutput: {
|
|
25808
|
+
type: "boolean"
|
|
25809
|
+
},
|
|
25810
|
+
continue: {
|
|
25811
|
+
type: "boolean"
|
|
25812
|
+
},
|
|
25813
|
+
stopReason: {
|
|
25814
|
+
type: "string"
|
|
25815
|
+
},
|
|
25816
|
+
decision: {
|
|
25817
|
+
type: "string",
|
|
25818
|
+
enum: [
|
|
25819
|
+
"allow",
|
|
25820
|
+
"deny",
|
|
25821
|
+
"block",
|
|
25822
|
+
"ask"
|
|
25823
|
+
]
|
|
25824
|
+
},
|
|
25825
|
+
reason: {
|
|
25826
|
+
type: "string"
|
|
25827
|
+
},
|
|
25828
|
+
hookSpecificOutput: {
|
|
25829
|
+
allOf: [
|
|
25830
|
+
{
|
|
25831
|
+
$ref: "#/definitions/Specific"
|
|
25832
|
+
}
|
|
25833
|
+
]
|
|
25834
|
+
}
|
|
25835
|
+
}
|
|
25836
|
+
}
|
|
25837
|
+
}
|
|
25838
|
+
};
|
|
25839
|
+
|
|
25840
|
+
// tests/fixtures/host-schemas/qwen.json
|
|
25841
|
+
var qwen_default = {
|
|
25842
|
+
host: "qwen",
|
|
25843
|
+
source: "@qwen-code/qwen-code 0.26.7: bundled/qc-helper/docs/features/hooks.md (Hook Output Structure, per-event Output Options) and chunks/chunk-6GTPLW7K.js HookOutput (getPermissionDecision reads hookSpecificOutput.permissionDecision allow|deny|ask, then decision allow|approve|deny|block|ask; a missing permissionDecision is no decision).",
|
|
25844
|
+
output: {
|
|
25845
|
+
PreToolUse: {
|
|
25846
|
+
title: "Qwen Code 0.26.7 PreToolUse reply",
|
|
25847
|
+
definitions: {
|
|
25848
|
+
Specific: {
|
|
25849
|
+
type: "object",
|
|
25850
|
+
additionalProperties: false,
|
|
25851
|
+
properties: {
|
|
25852
|
+
hookEventName: {
|
|
25853
|
+
type: "string",
|
|
25854
|
+
const: "PreToolUse"
|
|
25855
|
+
},
|
|
25856
|
+
permissionDecision: {
|
|
25857
|
+
type: "string",
|
|
25858
|
+
enum: [
|
|
25859
|
+
"allow",
|
|
25860
|
+
"deny",
|
|
25861
|
+
"ask"
|
|
25862
|
+
]
|
|
25863
|
+
},
|
|
25864
|
+
permissionDecisionReason: {
|
|
25865
|
+
type: "string"
|
|
25866
|
+
},
|
|
25867
|
+
updatedInput: {
|
|
25868
|
+
type: "object"
|
|
25869
|
+
},
|
|
25870
|
+
additionalContext: {
|
|
25871
|
+
type: "string"
|
|
25872
|
+
}
|
|
25873
|
+
},
|
|
25874
|
+
required: [
|
|
25875
|
+
"hookEventName"
|
|
25876
|
+
]
|
|
25877
|
+
}
|
|
25878
|
+
},
|
|
25879
|
+
type: "object",
|
|
25880
|
+
additionalProperties: false,
|
|
25881
|
+
properties: {
|
|
25882
|
+
continue: {
|
|
25883
|
+
type: "boolean"
|
|
25884
|
+
},
|
|
25885
|
+
stopReason: {
|
|
25886
|
+
type: "string"
|
|
25887
|
+
},
|
|
25888
|
+
suppressOutput: {
|
|
25889
|
+
type: "boolean"
|
|
25890
|
+
},
|
|
25891
|
+
systemMessage: {
|
|
25892
|
+
type: "string"
|
|
25893
|
+
},
|
|
25894
|
+
decision: {
|
|
25895
|
+
type: "string",
|
|
25896
|
+
enum: [
|
|
25897
|
+
"allow",
|
|
25898
|
+
"approve",
|
|
25899
|
+
"deny",
|
|
25900
|
+
"block",
|
|
25901
|
+
"ask"
|
|
25902
|
+
]
|
|
25903
|
+
},
|
|
25904
|
+
reason: {
|
|
25905
|
+
type: "string"
|
|
25906
|
+
},
|
|
25907
|
+
hookSpecificOutput: {
|
|
25908
|
+
allOf: [
|
|
25909
|
+
{
|
|
25910
|
+
$ref: "#/definitions/Specific"
|
|
25911
|
+
}
|
|
25912
|
+
]
|
|
25913
|
+
}
|
|
25914
|
+
}
|
|
25915
|
+
},
|
|
25916
|
+
PostToolUse: {
|
|
25917
|
+
title: "Qwen Code 0.26.7 PostToolUse reply",
|
|
25918
|
+
definitions: {
|
|
25919
|
+
Specific: {
|
|
25920
|
+
type: "object",
|
|
25921
|
+
additionalProperties: false,
|
|
25922
|
+
properties: {
|
|
25923
|
+
hookEventName: {
|
|
25924
|
+
type: "string",
|
|
25925
|
+
const: "PostToolUse"
|
|
25926
|
+
},
|
|
25927
|
+
additionalContext: {
|
|
25928
|
+
type: "string"
|
|
25929
|
+
}
|
|
25930
|
+
},
|
|
25931
|
+
required: [
|
|
25932
|
+
"hookEventName"
|
|
25933
|
+
]
|
|
25934
|
+
}
|
|
25935
|
+
},
|
|
25936
|
+
type: "object",
|
|
25937
|
+
additionalProperties: false,
|
|
25938
|
+
properties: {
|
|
25939
|
+
continue: {
|
|
25940
|
+
type: "boolean"
|
|
25941
|
+
},
|
|
25942
|
+
stopReason: {
|
|
25943
|
+
type: "string"
|
|
25944
|
+
},
|
|
25945
|
+
suppressOutput: {
|
|
25946
|
+
type: "boolean"
|
|
25947
|
+
},
|
|
25948
|
+
systemMessage: {
|
|
25949
|
+
type: "string"
|
|
25950
|
+
},
|
|
25951
|
+
decision: {
|
|
25952
|
+
type: "string",
|
|
25953
|
+
enum: [
|
|
25954
|
+
"allow",
|
|
25955
|
+
"approve",
|
|
25956
|
+
"deny",
|
|
25957
|
+
"block",
|
|
25958
|
+
"ask"
|
|
25959
|
+
]
|
|
25960
|
+
},
|
|
25961
|
+
reason: {
|
|
25962
|
+
type: "string"
|
|
25963
|
+
},
|
|
25964
|
+
hookSpecificOutput: {
|
|
25965
|
+
allOf: [
|
|
25966
|
+
{
|
|
25967
|
+
$ref: "#/definitions/Specific"
|
|
25968
|
+
}
|
|
25969
|
+
]
|
|
25970
|
+
}
|
|
25971
|
+
}
|
|
25972
|
+
},
|
|
25973
|
+
UserPromptSubmit: {
|
|
25974
|
+
title: "Qwen Code 0.26.7 UserPromptSubmit reply",
|
|
25975
|
+
definitions: {
|
|
25976
|
+
Specific: {
|
|
25977
|
+
type: "object",
|
|
25978
|
+
additionalProperties: false,
|
|
25979
|
+
properties: {
|
|
25980
|
+
hookEventName: {
|
|
25981
|
+
type: "string",
|
|
25982
|
+
const: "UserPromptSubmit"
|
|
25983
|
+
},
|
|
25984
|
+
additionalContext: {
|
|
25985
|
+
type: "string"
|
|
25986
|
+
}
|
|
25987
|
+
},
|
|
25988
|
+
required: [
|
|
25989
|
+
"hookEventName"
|
|
25990
|
+
]
|
|
25991
|
+
}
|
|
25992
|
+
},
|
|
25993
|
+
type: "object",
|
|
25994
|
+
additionalProperties: false,
|
|
25995
|
+
properties: {
|
|
25996
|
+
continue: {
|
|
25997
|
+
type: "boolean"
|
|
25998
|
+
},
|
|
25999
|
+
stopReason: {
|
|
26000
|
+
type: "string"
|
|
26001
|
+
},
|
|
26002
|
+
suppressOutput: {
|
|
26003
|
+
type: "boolean"
|
|
26004
|
+
},
|
|
26005
|
+
systemMessage: {
|
|
26006
|
+
type: "string"
|
|
26007
|
+
},
|
|
26008
|
+
decision: {
|
|
26009
|
+
type: "string",
|
|
26010
|
+
enum: [
|
|
26011
|
+
"allow",
|
|
26012
|
+
"approve",
|
|
26013
|
+
"deny",
|
|
26014
|
+
"block",
|
|
26015
|
+
"ask"
|
|
26016
|
+
]
|
|
26017
|
+
},
|
|
26018
|
+
reason: {
|
|
26019
|
+
type: "string"
|
|
26020
|
+
},
|
|
26021
|
+
hookSpecificOutput: {
|
|
26022
|
+
allOf: [
|
|
26023
|
+
{
|
|
26024
|
+
$ref: "#/definitions/Specific"
|
|
26025
|
+
}
|
|
26026
|
+
]
|
|
26027
|
+
}
|
|
26028
|
+
}
|
|
26029
|
+
},
|
|
26030
|
+
SessionStart: {
|
|
26031
|
+
title: "Qwen Code 0.26.7 SessionStart reply",
|
|
26032
|
+
definitions: {
|
|
26033
|
+
Specific: {
|
|
26034
|
+
type: "object",
|
|
26035
|
+
additionalProperties: false,
|
|
26036
|
+
properties: {
|
|
26037
|
+
hookEventName: {
|
|
26038
|
+
type: "string",
|
|
26039
|
+
const: "SessionStart"
|
|
26040
|
+
},
|
|
26041
|
+
additionalContext: {
|
|
26042
|
+
type: "string"
|
|
26043
|
+
}
|
|
26044
|
+
},
|
|
26045
|
+
required: [
|
|
26046
|
+
"hookEventName"
|
|
26047
|
+
]
|
|
26048
|
+
}
|
|
26049
|
+
},
|
|
26050
|
+
type: "object",
|
|
26051
|
+
additionalProperties: false,
|
|
26052
|
+
properties: {
|
|
26053
|
+
continue: {
|
|
26054
|
+
type: "boolean"
|
|
26055
|
+
},
|
|
26056
|
+
stopReason: {
|
|
26057
|
+
type: "string"
|
|
26058
|
+
},
|
|
26059
|
+
suppressOutput: {
|
|
26060
|
+
type: "boolean"
|
|
26061
|
+
},
|
|
26062
|
+
systemMessage: {
|
|
26063
|
+
type: "string"
|
|
26064
|
+
},
|
|
26065
|
+
decision: {
|
|
26066
|
+
type: "string",
|
|
26067
|
+
enum: [
|
|
26068
|
+
"allow",
|
|
26069
|
+
"approve",
|
|
26070
|
+
"deny",
|
|
26071
|
+
"block",
|
|
26072
|
+
"ask"
|
|
26073
|
+
]
|
|
26074
|
+
},
|
|
26075
|
+
reason: {
|
|
26076
|
+
type: "string"
|
|
26077
|
+
},
|
|
26078
|
+
hookSpecificOutput: {
|
|
26079
|
+
allOf: [
|
|
26080
|
+
{
|
|
26081
|
+
$ref: "#/definitions/Specific"
|
|
26082
|
+
}
|
|
26083
|
+
]
|
|
26084
|
+
}
|
|
26085
|
+
}
|
|
26086
|
+
}
|
|
26087
|
+
}
|
|
26088
|
+
};
|
|
26089
|
+
|
|
26090
|
+
// tests/fixtures/host-schemas/copilot-cli.json
|
|
26091
|
+
var copilot_cli_default = {
|
|
26092
|
+
host: "copilot-cli",
|
|
26093
|
+
source: "GitHub Copilot CLI 1.0.105 copilot-sdk/types.d.ts: PreToolUseHookOutput, PostToolUseHookOutput (modifiedResult: ToolResultObject, ToolResultType), UserPromptSubmittedHookOutput, SessionStartHookOutput. Replies are flat objects with no hookSpecificOutput.",
|
|
26094
|
+
output: {
|
|
26095
|
+
PreToolUse: {
|
|
26096
|
+
title: "Copilot CLI 1.0.105 preToolUse reply",
|
|
26097
|
+
type: "object",
|
|
26098
|
+
additionalProperties: false,
|
|
26099
|
+
properties: {
|
|
26100
|
+
permissionDecision: {
|
|
26101
|
+
type: "string",
|
|
26102
|
+
enum: [
|
|
26103
|
+
"allow",
|
|
26104
|
+
"deny",
|
|
26105
|
+
"ask"
|
|
26106
|
+
]
|
|
26107
|
+
},
|
|
26108
|
+
permissionDecisionReason: {
|
|
26109
|
+
type: "string"
|
|
26110
|
+
},
|
|
26111
|
+
modifiedArgs: {
|
|
26112
|
+
description: "unknown"
|
|
26113
|
+
},
|
|
26114
|
+
additionalContext: {
|
|
26115
|
+
type: "string"
|
|
26116
|
+
},
|
|
26117
|
+
suppressOutput: {
|
|
26118
|
+
type: "boolean"
|
|
26119
|
+
}
|
|
26120
|
+
}
|
|
26121
|
+
},
|
|
26122
|
+
PostToolUse: {
|
|
26123
|
+
title: "Copilot CLI 1.0.105 postToolUse reply",
|
|
26124
|
+
definitions: {
|
|
26125
|
+
ToolResultObject: {
|
|
26126
|
+
type: "object",
|
|
26127
|
+
additionalProperties: false,
|
|
26128
|
+
properties: {
|
|
26129
|
+
textResultForLlm: {
|
|
26130
|
+
type: "string"
|
|
26131
|
+
},
|
|
26132
|
+
binaryResultsForLlm: {
|
|
26133
|
+
type: "array",
|
|
26134
|
+
items: {
|
|
26135
|
+
type: "object"
|
|
26136
|
+
}
|
|
26137
|
+
},
|
|
26138
|
+
resultType: {
|
|
26139
|
+
type: "string",
|
|
26140
|
+
enum: [
|
|
26141
|
+
"success",
|
|
26142
|
+
"failure",
|
|
26143
|
+
"rejected",
|
|
26144
|
+
"denied",
|
|
26145
|
+
"timeout"
|
|
26146
|
+
]
|
|
26147
|
+
},
|
|
26148
|
+
error: {
|
|
26149
|
+
type: "string"
|
|
26150
|
+
},
|
|
26151
|
+
sessionLog: {
|
|
26152
|
+
type: "string"
|
|
26153
|
+
},
|
|
26154
|
+
toolTelemetry: {
|
|
26155
|
+
type: "object"
|
|
26156
|
+
},
|
|
26157
|
+
toolReferences: {
|
|
26158
|
+
type: "array",
|
|
26159
|
+
items: {
|
|
26160
|
+
type: "string"
|
|
26161
|
+
}
|
|
26162
|
+
}
|
|
26163
|
+
},
|
|
26164
|
+
required: [
|
|
26165
|
+
"textResultForLlm",
|
|
26166
|
+
"resultType"
|
|
26167
|
+
]
|
|
26168
|
+
}
|
|
26169
|
+
},
|
|
26170
|
+
type: "object",
|
|
26171
|
+
additionalProperties: false,
|
|
26172
|
+
properties: {
|
|
26173
|
+
modifiedResult: {
|
|
26174
|
+
allOf: [
|
|
26175
|
+
{
|
|
26176
|
+
$ref: "#/definitions/ToolResultObject"
|
|
26177
|
+
}
|
|
26178
|
+
]
|
|
26179
|
+
},
|
|
26180
|
+
additionalContext: {
|
|
26181
|
+
type: "string"
|
|
26182
|
+
},
|
|
26183
|
+
suppressOutput: {
|
|
26184
|
+
type: "boolean"
|
|
26185
|
+
}
|
|
26186
|
+
}
|
|
26187
|
+
},
|
|
26188
|
+
UserPromptSubmit: {
|
|
26189
|
+
title: "Copilot CLI 1.0.105 userPromptSubmitted reply",
|
|
26190
|
+
type: "object",
|
|
26191
|
+
additionalProperties: false,
|
|
26192
|
+
properties: {
|
|
26193
|
+
modifiedPrompt: {
|
|
26194
|
+
type: "string"
|
|
26195
|
+
},
|
|
26196
|
+
additionalContext: {
|
|
26197
|
+
type: "string"
|
|
26198
|
+
},
|
|
26199
|
+
suppressOutput: {
|
|
26200
|
+
type: "boolean"
|
|
26201
|
+
},
|
|
26202
|
+
decision: {
|
|
26203
|
+
type: "string",
|
|
26204
|
+
const: "block"
|
|
26205
|
+
},
|
|
26206
|
+
reason: {
|
|
26207
|
+
type: "string"
|
|
26208
|
+
}
|
|
26209
|
+
}
|
|
26210
|
+
},
|
|
26211
|
+
SessionStart: {
|
|
26212
|
+
title: "Copilot CLI 1.0.105 sessionStart reply",
|
|
26213
|
+
type: "object",
|
|
26214
|
+
additionalProperties: false,
|
|
26215
|
+
properties: {
|
|
26216
|
+
additionalContext: {
|
|
26217
|
+
type: "string"
|
|
26218
|
+
},
|
|
26219
|
+
modifiedConfig: {
|
|
26220
|
+
type: "object"
|
|
26221
|
+
}
|
|
26222
|
+
}
|
|
26223
|
+
}
|
|
26224
|
+
}
|
|
26225
|
+
};
|
|
26226
|
+
|
|
26227
|
+
// tests/fixtures/host-schemas/vscode.json
|
|
26228
|
+
var vscode_default = {
|
|
26229
|
+
host: "vscode",
|
|
26230
|
+
source: "VS Code Copilot Chat 0.44.0 (5863f5a) src/platform/chat/common/hookCommandTypes.ts (IPreToolUseHookSpecificCommandOutput, IPostToolUseHookSpecificCommandOutput) and chatHookService.ts (UserPromptSubmitHookOutput, SessionStartHookOutput, IPostToolUseHookResult decision 'block').",
|
|
26231
|
+
output: {
|
|
26232
|
+
PreToolUse: {
|
|
26233
|
+
title: "VS Code Copilot Chat 0.44.0 PreToolUse reply",
|
|
26234
|
+
definitions: {
|
|
26235
|
+
Specific: {
|
|
26236
|
+
type: "object",
|
|
26237
|
+
additionalProperties: false,
|
|
26238
|
+
properties: {
|
|
26239
|
+
hookEventName: {
|
|
26240
|
+
type: "string"
|
|
26241
|
+
},
|
|
26242
|
+
permissionDecision: {
|
|
26243
|
+
type: "string",
|
|
26244
|
+
enum: [
|
|
26245
|
+
"allow",
|
|
26246
|
+
"deny",
|
|
26247
|
+
"ask"
|
|
26248
|
+
]
|
|
26249
|
+
},
|
|
26250
|
+
permissionDecisionReason: {
|
|
26251
|
+
type: "string"
|
|
26252
|
+
},
|
|
26253
|
+
updatedInput: {
|
|
26254
|
+
type: "object"
|
|
26255
|
+
},
|
|
26256
|
+
additionalContext: {
|
|
26257
|
+
type: "string"
|
|
26258
|
+
}
|
|
26259
|
+
}
|
|
26260
|
+
}
|
|
26261
|
+
},
|
|
26262
|
+
type: "object",
|
|
26263
|
+
additionalProperties: false,
|
|
26264
|
+
properties: {
|
|
26265
|
+
hookSpecificOutput: {
|
|
26266
|
+
allOf: [
|
|
26267
|
+
{
|
|
26268
|
+
$ref: "#/definitions/Specific"
|
|
26269
|
+
}
|
|
26270
|
+
]
|
|
26271
|
+
}
|
|
26272
|
+
}
|
|
26273
|
+
},
|
|
26274
|
+
PostToolUse: {
|
|
26275
|
+
title: "VS Code Copilot Chat 0.44.0 PostToolUse reply",
|
|
26276
|
+
definitions: {
|
|
26277
|
+
Specific: {
|
|
26278
|
+
type: "object",
|
|
26279
|
+
additionalProperties: false,
|
|
26280
|
+
properties: {
|
|
26281
|
+
hookEventName: {
|
|
26282
|
+
type: "string"
|
|
26283
|
+
},
|
|
26284
|
+
additionalContext: {
|
|
26285
|
+
type: "string"
|
|
26286
|
+
}
|
|
26287
|
+
}
|
|
26288
|
+
}
|
|
26289
|
+
},
|
|
26290
|
+
type: "object",
|
|
26291
|
+
additionalProperties: false,
|
|
26292
|
+
properties: {
|
|
26293
|
+
decision: {
|
|
26294
|
+
type: "string",
|
|
26295
|
+
const: "block"
|
|
26296
|
+
},
|
|
26297
|
+
reason: {
|
|
26298
|
+
type: "string"
|
|
26299
|
+
},
|
|
26300
|
+
hookSpecificOutput: {
|
|
26301
|
+
allOf: [
|
|
26302
|
+
{
|
|
26303
|
+
$ref: "#/definitions/Specific"
|
|
26304
|
+
}
|
|
26305
|
+
]
|
|
26306
|
+
}
|
|
26307
|
+
}
|
|
26308
|
+
},
|
|
26309
|
+
UserPromptSubmit: {
|
|
26310
|
+
title: "VS Code Copilot Chat 0.44.0 UserPromptSubmit reply",
|
|
26311
|
+
definitions: {
|
|
26312
|
+
Specific: {
|
|
26313
|
+
type: "object",
|
|
26314
|
+
additionalProperties: false,
|
|
26315
|
+
properties: {
|
|
26316
|
+
hookEventName: {
|
|
26317
|
+
type: "string"
|
|
26318
|
+
},
|
|
26319
|
+
additionalContext: {
|
|
26320
|
+
type: "string"
|
|
26321
|
+
}
|
|
26322
|
+
}
|
|
26323
|
+
}
|
|
26324
|
+
},
|
|
26325
|
+
type: "object",
|
|
26326
|
+
additionalProperties: false,
|
|
26327
|
+
properties: {
|
|
26328
|
+
decision: {
|
|
26329
|
+
type: "string",
|
|
26330
|
+
const: "block"
|
|
26331
|
+
},
|
|
26332
|
+
reason: {
|
|
26333
|
+
type: "string"
|
|
26334
|
+
},
|
|
26335
|
+
hookSpecificOutput: {
|
|
26336
|
+
allOf: [
|
|
26337
|
+
{
|
|
26338
|
+
$ref: "#/definitions/Specific"
|
|
26339
|
+
}
|
|
26340
|
+
]
|
|
26341
|
+
}
|
|
26342
|
+
}
|
|
26343
|
+
},
|
|
26344
|
+
SessionStart: {
|
|
26345
|
+
title: "VS Code Copilot Chat 0.44.0 SessionStart reply",
|
|
26346
|
+
definitions: {
|
|
26347
|
+
Specific: {
|
|
26348
|
+
type: "object",
|
|
26349
|
+
additionalProperties: false,
|
|
26350
|
+
properties: {
|
|
26351
|
+
hookEventName: {
|
|
26352
|
+
type: "string"
|
|
26353
|
+
},
|
|
26354
|
+
additionalContext: {
|
|
26355
|
+
type: "string"
|
|
26356
|
+
}
|
|
26357
|
+
}
|
|
26358
|
+
}
|
|
26359
|
+
},
|
|
26360
|
+
type: "object",
|
|
26361
|
+
additionalProperties: false,
|
|
26362
|
+
properties: {
|
|
26363
|
+
hookSpecificOutput: {
|
|
26364
|
+
allOf: [
|
|
26365
|
+
{
|
|
26366
|
+
$ref: "#/definitions/Specific"
|
|
26367
|
+
}
|
|
26368
|
+
]
|
|
26369
|
+
}
|
|
26370
|
+
}
|
|
26371
|
+
}
|
|
26372
|
+
}
|
|
26373
|
+
};
|
|
26374
|
+
|
|
26375
|
+
// tests/fixtures/host-schemas/kiro.json
|
|
26376
|
+
var kiro_default = {
|
|
26377
|
+
host: "kiro",
|
|
26378
|
+
source: "kiro-cli 3.0.0 (BUILD_HASH 21067db0a7cc, 2026-11-02), V3 engine KAS 3.0.0-e315409f JS bundle (acp-server.js, unpacked by `kiro-cli serve`)",
|
|
26379
|
+
mcpToolId: {
|
|
26380
|
+
from: "function uel(server, tool): r = server + '_' + tool; r = r.replace(/[\\s-]/g, '_'); r = r.replace(/[^a-zA-Z0-9_]/g, ''); id = 'mcp_' + r.toLowerCase(); cut to 64 chars",
|
|
26381
|
+
prefix: "mcp_",
|
|
26382
|
+
join: "_",
|
|
26383
|
+
maxLength: 64
|
|
26384
|
+
},
|
|
26385
|
+
hookStdin: {
|
|
26386
|
+
from: "function sJn: {session_id, hook_event_name, cwd} plus per trigger fields",
|
|
26387
|
+
UserPromptSubmit: ["session_id", "hook_event_name", "cwd", "prompt"],
|
|
26388
|
+
PreToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input"],
|
|
26389
|
+
PostToolUse: ["session_id", "hook_event_name", "cwd", "tool_name", "tool_input", "tool_response"],
|
|
26390
|
+
SessionStart: ["session_id", "hook_event_name", "cwd"]
|
|
26391
|
+
},
|
|
26392
|
+
hookOutputCapChars: 3e3,
|
|
26393
|
+
windowsHookShell: "child_process.spawn(command, {shell: true}) in the V3 hook process runner (class tje): COMSPEC (cmd.exe /d /s /c) on win32",
|
|
26394
|
+
stdout: "text",
|
|
26395
|
+
output: {
|
|
26396
|
+
PreToolUse: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" },
|
|
26397
|
+
PostToolUse: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" },
|
|
26398
|
+
UserPromptSubmit: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" },
|
|
26399
|
+
SessionStart: { type: "string", description: "plain stdout added to the agent context (kiro-cli 3.0.0 V3 hook process runner, cut at hookOutputCapChars); exit 2 blocks with stderr as the reason" }
|
|
26400
|
+
}
|
|
26401
|
+
};
|
|
26402
|
+
|
|
26403
|
+
// tests/fixtures/host-schemas/zcode.json
|
|
26404
|
+
var zcode_default = {
|
|
26405
|
+
host: "zcode",
|
|
26406
|
+
source: "ZCode 0.17.1 (a9fe401e) apps/zcode-cli/packages/contracts/src/hooks/index.ts: HookJSONOutputSchema and HookSpecificOutputSchema (zod discriminatedUnion on hookEventName). zod drops keys it does not read, so each object lists only the keys the host reads.",
|
|
26407
|
+
output: {
|
|
26408
|
+
PreToolUse: {
|
|
26409
|
+
title: "ZCode 0.17.1 PreToolUse reply",
|
|
26410
|
+
definitions: {
|
|
26411
|
+
Specific: {
|
|
26412
|
+
type: "object",
|
|
26413
|
+
additionalProperties: false,
|
|
26414
|
+
properties: {
|
|
26415
|
+
additionalContext: {
|
|
26416
|
+
type: "string"
|
|
26417
|
+
},
|
|
26418
|
+
hookEventName: {
|
|
26419
|
+
type: "string",
|
|
26420
|
+
const: "PreToolUse"
|
|
26421
|
+
},
|
|
26422
|
+
permissionDecision: {
|
|
26423
|
+
type: "string",
|
|
26424
|
+
enum: [
|
|
26425
|
+
"allow",
|
|
26426
|
+
"ask",
|
|
26427
|
+
"deny"
|
|
26428
|
+
]
|
|
26429
|
+
},
|
|
26430
|
+
permissionDecisionReason: {
|
|
26431
|
+
type: "string"
|
|
26432
|
+
},
|
|
26433
|
+
updatedInput: {
|
|
26434
|
+
description: "z.unknown()"
|
|
26435
|
+
}
|
|
26436
|
+
},
|
|
26437
|
+
required: [
|
|
26438
|
+
"hookEventName"
|
|
26439
|
+
]
|
|
26440
|
+
}
|
|
26441
|
+
},
|
|
26442
|
+
type: "object",
|
|
26443
|
+
additionalProperties: false,
|
|
26444
|
+
properties: {
|
|
26445
|
+
additionalContext: {
|
|
26446
|
+
type: "string"
|
|
26447
|
+
},
|
|
26448
|
+
additional_context: {
|
|
26449
|
+
type: "string"
|
|
26450
|
+
},
|
|
26451
|
+
continue: {
|
|
26452
|
+
type: "boolean"
|
|
26453
|
+
},
|
|
26454
|
+
decision: {
|
|
26455
|
+
type: "string",
|
|
26456
|
+
enum: [
|
|
26457
|
+
"approve",
|
|
26458
|
+
"block"
|
|
26459
|
+
]
|
|
26460
|
+
},
|
|
26461
|
+
reason: {
|
|
26462
|
+
type: "string"
|
|
26463
|
+
},
|
|
26464
|
+
stopReason: {
|
|
26465
|
+
type: "string"
|
|
26466
|
+
},
|
|
26467
|
+
suppressOutput: {
|
|
26468
|
+
type: "boolean"
|
|
26469
|
+
},
|
|
26470
|
+
systemMessage: {
|
|
26471
|
+
type: "string"
|
|
26472
|
+
},
|
|
26473
|
+
hookSpecificOutput: {
|
|
26474
|
+
allOf: [
|
|
26475
|
+
{
|
|
26476
|
+
$ref: "#/definitions/Specific"
|
|
26477
|
+
}
|
|
26478
|
+
]
|
|
26479
|
+
}
|
|
26480
|
+
}
|
|
26481
|
+
},
|
|
26482
|
+
PostToolUse: {
|
|
26483
|
+
title: "ZCode 0.17.1 PostToolUse reply",
|
|
26484
|
+
definitions: {
|
|
26485
|
+
Specific: {
|
|
26486
|
+
type: "object",
|
|
26487
|
+
additionalProperties: false,
|
|
26488
|
+
properties: {
|
|
26489
|
+
additionalContext: {
|
|
26490
|
+
type: "string"
|
|
26491
|
+
},
|
|
26492
|
+
hookEventName: {
|
|
26493
|
+
type: "string",
|
|
26494
|
+
const: "PostToolUse"
|
|
26495
|
+
}
|
|
26496
|
+
},
|
|
26497
|
+
required: [
|
|
26498
|
+
"hookEventName"
|
|
26499
|
+
]
|
|
26500
|
+
}
|
|
26501
|
+
},
|
|
26502
|
+
type: "object",
|
|
26503
|
+
additionalProperties: false,
|
|
26504
|
+
properties: {
|
|
26505
|
+
additionalContext: {
|
|
26506
|
+
type: "string"
|
|
26507
|
+
},
|
|
26508
|
+
additional_context: {
|
|
26509
|
+
type: "string"
|
|
26510
|
+
},
|
|
26511
|
+
continue: {
|
|
26512
|
+
type: "boolean"
|
|
26513
|
+
},
|
|
26514
|
+
decision: {
|
|
26515
|
+
type: "string",
|
|
26516
|
+
enum: [
|
|
26517
|
+
"approve",
|
|
26518
|
+
"block"
|
|
26519
|
+
]
|
|
26520
|
+
},
|
|
26521
|
+
reason: {
|
|
26522
|
+
type: "string"
|
|
26523
|
+
},
|
|
26524
|
+
stopReason: {
|
|
26525
|
+
type: "string"
|
|
26526
|
+
},
|
|
26527
|
+
suppressOutput: {
|
|
26528
|
+
type: "boolean"
|
|
26529
|
+
},
|
|
26530
|
+
systemMessage: {
|
|
26531
|
+
type: "string"
|
|
26532
|
+
},
|
|
26533
|
+
hookSpecificOutput: {
|
|
26534
|
+
allOf: [
|
|
26535
|
+
{
|
|
26536
|
+
$ref: "#/definitions/Specific"
|
|
26537
|
+
}
|
|
26538
|
+
]
|
|
26539
|
+
}
|
|
26540
|
+
}
|
|
26541
|
+
},
|
|
26542
|
+
UserPromptSubmit: {
|
|
26543
|
+
title: "ZCode 0.17.1 UserPromptSubmit reply",
|
|
26544
|
+
definitions: {
|
|
26545
|
+
Specific: {
|
|
26546
|
+
type: "object",
|
|
26547
|
+
additionalProperties: false,
|
|
26548
|
+
properties: {
|
|
26549
|
+
additionalContext: {
|
|
26550
|
+
type: "string"
|
|
26551
|
+
},
|
|
26552
|
+
hookEventName: {
|
|
26553
|
+
type: "string",
|
|
26554
|
+
const: "UserPromptSubmit"
|
|
26555
|
+
}
|
|
26556
|
+
},
|
|
26557
|
+
required: [
|
|
26558
|
+
"hookEventName"
|
|
26559
|
+
]
|
|
26560
|
+
}
|
|
26561
|
+
},
|
|
26562
|
+
type: "object",
|
|
26563
|
+
additionalProperties: false,
|
|
26564
|
+
properties: {
|
|
26565
|
+
additionalContext: {
|
|
26566
|
+
type: "string"
|
|
26567
|
+
},
|
|
26568
|
+
additional_context: {
|
|
26569
|
+
type: "string"
|
|
26570
|
+
},
|
|
26571
|
+
continue: {
|
|
26572
|
+
type: "boolean"
|
|
26573
|
+
},
|
|
26574
|
+
decision: {
|
|
26575
|
+
type: "string",
|
|
26576
|
+
enum: [
|
|
26577
|
+
"approve",
|
|
26578
|
+
"block"
|
|
26579
|
+
]
|
|
26580
|
+
},
|
|
26581
|
+
reason: {
|
|
26582
|
+
type: "string"
|
|
26583
|
+
},
|
|
26584
|
+
stopReason: {
|
|
26585
|
+
type: "string"
|
|
26586
|
+
},
|
|
26587
|
+
suppressOutput: {
|
|
26588
|
+
type: "boolean"
|
|
26589
|
+
},
|
|
26590
|
+
systemMessage: {
|
|
26591
|
+
type: "string"
|
|
26592
|
+
},
|
|
26593
|
+
hookSpecificOutput: {
|
|
26594
|
+
allOf: [
|
|
26595
|
+
{
|
|
26596
|
+
$ref: "#/definitions/Specific"
|
|
26597
|
+
}
|
|
26598
|
+
]
|
|
26599
|
+
}
|
|
26600
|
+
}
|
|
26601
|
+
},
|
|
26602
|
+
SessionStart: {
|
|
26603
|
+
title: "ZCode 0.17.1 SessionStart reply",
|
|
26604
|
+
definitions: {
|
|
26605
|
+
Specific: {
|
|
26606
|
+
type: "object",
|
|
26607
|
+
additionalProperties: false,
|
|
26608
|
+
properties: {
|
|
26609
|
+
additionalContext: {
|
|
26610
|
+
type: "string"
|
|
26611
|
+
},
|
|
26612
|
+
hookEventName: {
|
|
26613
|
+
type: "string",
|
|
26614
|
+
const: "SessionStart"
|
|
26615
|
+
}
|
|
26616
|
+
},
|
|
26617
|
+
required: [
|
|
26618
|
+
"hookEventName"
|
|
26619
|
+
]
|
|
26620
|
+
}
|
|
26621
|
+
},
|
|
26622
|
+
type: "object",
|
|
26623
|
+
additionalProperties: false,
|
|
26624
|
+
properties: {
|
|
26625
|
+
additionalContext: {
|
|
26626
|
+
type: "string"
|
|
26627
|
+
},
|
|
26628
|
+
additional_context: {
|
|
26629
|
+
type: "string"
|
|
26630
|
+
},
|
|
26631
|
+
continue: {
|
|
26632
|
+
type: "boolean"
|
|
26633
|
+
},
|
|
26634
|
+
decision: {
|
|
26635
|
+
type: "string",
|
|
26636
|
+
enum: [
|
|
26637
|
+
"approve",
|
|
26638
|
+
"block"
|
|
26639
|
+
]
|
|
26640
|
+
},
|
|
26641
|
+
reason: {
|
|
26642
|
+
type: "string"
|
|
26643
|
+
},
|
|
26644
|
+
stopReason: {
|
|
26645
|
+
type: "string"
|
|
26646
|
+
},
|
|
26647
|
+
suppressOutput: {
|
|
26648
|
+
type: "boolean"
|
|
26649
|
+
},
|
|
26650
|
+
systemMessage: {
|
|
26651
|
+
type: "string"
|
|
26652
|
+
},
|
|
26653
|
+
hookSpecificOutput: {
|
|
26654
|
+
allOf: [
|
|
26655
|
+
{
|
|
26656
|
+
$ref: "#/definitions/Specific"
|
|
26657
|
+
}
|
|
26658
|
+
]
|
|
26659
|
+
}
|
|
26660
|
+
}
|
|
26661
|
+
}
|
|
26662
|
+
}
|
|
26663
|
+
};
|
|
26664
|
+
|
|
26665
|
+
// tests/fixtures/host-schemas/pi.json
|
|
26666
|
+
var pi_default = {
|
|
26667
|
+
host: "pi",
|
|
26668
|
+
source: "@earendil-works/pi-coding-agent 1.5.0 dist/core/extensions/types.d.ts (ToolCallEventResult {block, reason}, ToolResultEventResult content, BeforeAgentStartEventResult) and runner.js l.895-1010. The hook runs in process (src/entries/pi.ts): plain stdout becomes the reason, the replaced content or the added context; exit 2 blocks the tool call.",
|
|
26669
|
+
stdout: "text",
|
|
26670
|
+
output: {
|
|
26671
|
+
PreToolUse: {
|
|
26672
|
+
type: "string",
|
|
26673
|
+
description: "plain text read by src/entries/pi.ts"
|
|
26674
|
+
},
|
|
26675
|
+
PostToolUse: {
|
|
26676
|
+
type: "string",
|
|
26677
|
+
description: "plain text read by src/entries/pi.ts"
|
|
26678
|
+
},
|
|
26679
|
+
UserPromptSubmit: {
|
|
26680
|
+
type: "string",
|
|
26681
|
+
description: "plain text read by src/entries/pi.ts"
|
|
26682
|
+
},
|
|
26683
|
+
SessionStart: {
|
|
26684
|
+
type: "string",
|
|
26685
|
+
description: "plain text read by src/entries/pi.ts"
|
|
26686
|
+
}
|
|
26687
|
+
}
|
|
26688
|
+
};
|
|
26689
|
+
|
|
26690
|
+
// tests/fixtures/host-schemas/opencode.json
|
|
26691
|
+
var opencode_default = {
|
|
26692
|
+
host: "opencode",
|
|
26693
|
+
source: "@opencode/cli 2.2.5 plugin hooks (tool.execute.before throws to block, session hooks add text). The plugin runs the hook and reads plain stdout; exit 2 blocks the tool call with stdout as the reason.",
|
|
26694
|
+
stdout: "text",
|
|
26695
|
+
output: {
|
|
26696
|
+
PreToolUse: {
|
|
26697
|
+
type: "string",
|
|
26698
|
+
description: "plain text read by the context-mode OpenCode plugin"
|
|
26699
|
+
},
|
|
26700
|
+
PostToolUse: {
|
|
26701
|
+
type: "string",
|
|
26702
|
+
description: "plain text read by the context-mode OpenCode plugin"
|
|
26703
|
+
},
|
|
26704
|
+
UserPromptSubmit: {
|
|
26705
|
+
type: "string",
|
|
26706
|
+
description: "plain text read by the context-mode OpenCode plugin"
|
|
26707
|
+
},
|
|
26708
|
+
SessionStart: {
|
|
26709
|
+
type: "string",
|
|
26710
|
+
description: "plain text read by the context-mode OpenCode plugin"
|
|
26711
|
+
}
|
|
26712
|
+
}
|
|
26713
|
+
};
|
|
26714
|
+
|
|
26715
|
+
// src/core/ops/hook-shape.ts
|
|
26716
|
+
var HOST_SHAPES = {
|
|
26717
|
+
"claude-code": claude_code_default,
|
|
26718
|
+
codex: codex_default,
|
|
26719
|
+
gemini: gemini_default,
|
|
26720
|
+
qwen: qwen_default,
|
|
26721
|
+
"copilot-cli": copilot_cli_default,
|
|
26722
|
+
vscode: vscode_default,
|
|
26723
|
+
kiro: kiro_default,
|
|
26724
|
+
zcode: zcode_default,
|
|
26725
|
+
pi: pi_default,
|
|
26726
|
+
opencode: opencode_default
|
|
26727
|
+
};
|
|
26728
|
+
var NOTE_KEYS = /* @__PURE__ */ new Set(["$schema", "title", "description", "definitions", "default"]);
|
|
26729
|
+
var RULE_KEYS = /* @__PURE__ */ new Set(["type", "enum", "const", "required", "properties", "additionalProperties", "items", "allOf", "$ref"]);
|
|
26730
|
+
function isObject5(v) {
|
|
26731
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
26732
|
+
}
|
|
26733
|
+
function typeOf(v) {
|
|
26734
|
+
if (v === null) return "null";
|
|
26735
|
+
if (Array.isArray(v)) return "array";
|
|
26736
|
+
return typeof v;
|
|
26737
|
+
}
|
|
26738
|
+
function hasType(v, t) {
|
|
26739
|
+
if (t === "integer") return Number.isInteger(v);
|
|
26740
|
+
return typeOf(v) === t;
|
|
26741
|
+
}
|
|
26742
|
+
function same(a, b) {
|
|
26743
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
26744
|
+
}
|
|
26745
|
+
function resolve7(root, ref) {
|
|
26746
|
+
const parts = ref.split("/");
|
|
26747
|
+
if (parts[0] !== "#") throw new Error(`hook-shape: only local $ref is read, got ${ref}`);
|
|
26748
|
+
let at2 = root;
|
|
26749
|
+
for (const p of parts.slice(1)) at2 = isObject5(at2) ? at2[p] : void 0;
|
|
26750
|
+
if (!isObject5(at2)) throw new Error(`hook-shape: $ref ${ref} names nothing`);
|
|
26751
|
+
return at2;
|
|
26752
|
+
}
|
|
26753
|
+
function shapeErrors(schema, value, root = schema, at2 = "$") {
|
|
26754
|
+
for (const k of Object.keys(schema)) {
|
|
26755
|
+
if (!NOTE_KEYS.has(k) && !RULE_KEYS.has(k)) throw new Error(`hook-shape: keyword ${k} at ${at2} is not read by the checker`);
|
|
26756
|
+
}
|
|
26757
|
+
const errs = [];
|
|
26758
|
+
if (typeof schema.$ref === "string") errs.push(...shapeErrors(resolve7(root, schema.$ref), value, root, at2));
|
|
26759
|
+
if (Array.isArray(schema.allOf)) for (const s of schema.allOf) errs.push(...shapeErrors(s, value, root, at2));
|
|
26760
|
+
if (schema.type !== void 0) {
|
|
26761
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
26762
|
+
if (!types.some((t) => hasType(value, String(t)))) return [...errs, `${at2}: ${typeOf(value)} is not ${types.join(" or ")}`];
|
|
26763
|
+
}
|
|
26764
|
+
if (Array.isArray(schema.enum) && !schema.enum.some((e) => same(e, value))) errs.push(`${at2}: ${JSON.stringify(value)} is not one of ${JSON.stringify(schema.enum)}`);
|
|
26765
|
+
if (Object.hasOwn(schema, "const") && !same(schema.const, value)) errs.push(`${at2}: ${JSON.stringify(value)} is not ${JSON.stringify(schema.const)}`);
|
|
26766
|
+
if (isObject5(value)) {
|
|
26767
|
+
const props = isObject5(schema.properties) ? schema.properties : {};
|
|
26768
|
+
if (Array.isArray(schema.required)) {
|
|
26769
|
+
for (const r of schema.required) if (!Object.hasOwn(value, String(r))) errs.push(`${at2}: ${String(r)} is required`);
|
|
26770
|
+
}
|
|
26771
|
+
for (const [k, v] of Object.entries(value)) {
|
|
26772
|
+
if (Object.hasOwn(props, k)) errs.push(...shapeErrors(props[k], v, root, `${at2}.${k}`));
|
|
26773
|
+
else if (schema.additionalProperties === false) errs.push(`${at2}: ${k} is not a known key`);
|
|
26774
|
+
else if (isObject5(schema.additionalProperties)) errs.push(...shapeErrors(schema.additionalProperties, v, root, `${at2}.${k}`));
|
|
26775
|
+
}
|
|
26776
|
+
}
|
|
26777
|
+
if (Array.isArray(value) && isObject5(schema.items)) {
|
|
26778
|
+
const items = schema.items;
|
|
26779
|
+
value.forEach((v, n) => errs.push(...shapeErrors(items, v, root, `${at2}[${n}]`)));
|
|
26780
|
+
}
|
|
26781
|
+
return errs;
|
|
26782
|
+
}
|
|
26783
|
+
function replyErrors(agent, event, stdout) {
|
|
26784
|
+
const host = HOST_SHAPES[agent];
|
|
26785
|
+
const schema = host.output[event];
|
|
26786
|
+
if (schema === void 0) return [`${agent} has no ${event} reply schema`];
|
|
26787
|
+
if (host.stdout === "text") return shapeErrors(schema, stdout);
|
|
26788
|
+
let value;
|
|
26789
|
+
try {
|
|
26790
|
+
value = JSON.parse(stdout);
|
|
26791
|
+
} catch {
|
|
26792
|
+
return [`${agent} ${event}: stdout is not JSON`];
|
|
26793
|
+
}
|
|
26794
|
+
return shapeErrors(schema, value);
|
|
26795
|
+
}
|
|
26796
|
+
|
|
26797
|
+
// src/core/sandbox/host-node.ts
|
|
26798
|
+
var BUN_BE_BUN_ENV = "BUN_BE_BUN";
|
|
26799
|
+
function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
|
|
26800
|
+
if (host.bun === void 0) return { file: host.execPath, env };
|
|
26801
|
+
const node = find2("javascript", env);
|
|
26802
|
+
if (node !== null) return { file: node, env };
|
|
26803
|
+
return { file: host.execPath, env: { ...env, [BUN_BE_BUN_ENV]: "1" } };
|
|
26804
|
+
}
|
|
26805
|
+
|
|
26806
|
+
// src/setup/codex-trust.ts
|
|
26807
|
+
import { createHash } from "node:crypto";
|
|
26808
|
+
import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
|
|
26809
|
+
import path6 from "node:path";
|
|
26810
|
+
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
26811
|
+
|
|
26812
|
+
// src/setup/spawn-bin.ts
|
|
26813
|
+
import { spawnSync } from "node:child_process";
|
|
26814
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
|
|
26815
|
+
import path5 from "node:path";
|
|
26816
|
+
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
26817
|
+
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
26818
|
+
var DEFAULT_COMSPEC = "cmd.exe";
|
|
26819
|
+
function envGet(env, k) {
|
|
26820
|
+
return env[Object.keys(env).find((x) => x.toUpperCase() === k) ?? k];
|
|
26821
|
+
}
|
|
26822
|
+
function whichBin(bin, env, platform = process.platform) {
|
|
26823
|
+
const get = (k) => envGet(env, k);
|
|
26824
|
+
const win = platform === "win32";
|
|
26825
|
+
const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
|
|
26826
|
+
const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
|
|
26827
|
+
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
26828
|
+
for (const n of names) {
|
|
26829
|
+
const f = path5.join(dir, n);
|
|
26830
|
+
try {
|
|
26831
|
+
accessSync2(f, fsc.X_OK);
|
|
26832
|
+
if (statSync6(f).isFile()) return f;
|
|
26833
|
+
} catch {
|
|
26834
|
+
}
|
|
26835
|
+
}
|
|
26836
|
+
}
|
|
26837
|
+
return void 0;
|
|
26838
|
+
}
|
|
26839
|
+
var CMD_QUOTE_CHARS = '"&|<>^()!';
|
|
26840
|
+
var CMD_PERCENT = "%";
|
|
26841
|
+
var CMD_SUBSTRING_MARK = ":";
|
|
26842
|
+
var CMD_DYNAMIC_VARS = Object.freeze(["CD", "DATE", "TIME", "RANDOM", "ERRORLEVEL", "CMDEXTVERSION", "CMDCMDLINE", "HIGHESTNUMANODENUMBER"]);
|
|
26843
|
+
function needsCmdQuotes(a) {
|
|
26844
|
+
if (a === "") return true;
|
|
26845
|
+
for (const c of a) if (c.trim() === "" || CMD_QUOTE_CHARS.includes(c)) return true;
|
|
26846
|
+
return false;
|
|
24841
26847
|
}
|
|
24842
26848
|
function expandablePercent(text, env) {
|
|
24843
26849
|
const names = new Set(CMD_DYNAMIC_VARS);
|
|
@@ -24916,14 +26922,14 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
24916
26922
|
function askPluginHooks(env, pluginId, cwd) {
|
|
24917
26923
|
const bin = whichBin("codex", env);
|
|
24918
26924
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
24919
|
-
return new Promise((
|
|
26925
|
+
return new Promise((resolve11) => {
|
|
24920
26926
|
let asked;
|
|
24921
26927
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
24922
26928
|
let f;
|
|
24923
26929
|
try {
|
|
24924
26930
|
f = spawnForm(bin, ["app-server"], env);
|
|
24925
26931
|
} catch {
|
|
24926
|
-
|
|
26932
|
+
resolve11({ kind: "silent" });
|
|
24927
26933
|
return;
|
|
24928
26934
|
}
|
|
24929
26935
|
const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -24933,7 +26939,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
24933
26939
|
let result;
|
|
24934
26940
|
const settle = () => {
|
|
24935
26941
|
clearTimeout(grace);
|
|
24936
|
-
|
|
26942
|
+
resolve11(done_(result));
|
|
24937
26943
|
};
|
|
24938
26944
|
let grace;
|
|
24939
26945
|
const finish2 = (v) => {
|
|
@@ -25017,22 +27023,22 @@ var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answ
|
|
|
25017
27023
|
var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
|
|
25018
27024
|
var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
|
|
25019
27025
|
var row = (status, detail, fixCommand) => fixCommand === void 0 ? { id: "D5", label: DOCTOR_LABEL.D5, status, detail } : { id: "D5", label: DOCTOR_LABEL.D5, status, detail, fixCommand };
|
|
25020
|
-
function
|
|
27026
|
+
function isObject6(v) {
|
|
25021
27027
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
25022
27028
|
}
|
|
25023
27029
|
function loadFixture(bundleDir2, agent) {
|
|
25024
27030
|
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
25025
|
-
if (!
|
|
27031
|
+
if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
25026
27032
|
let all;
|
|
25027
27033
|
try {
|
|
25028
|
-
all = JSON.parse(hostText(
|
|
27034
|
+
all = JSON.parse(hostText(readFileSync12(file2, "utf8")));
|
|
25029
27035
|
} catch (err) {
|
|
25030
27036
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
25031
27037
|
}
|
|
25032
|
-
if (!
|
|
27038
|
+
if (!isObject6(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
|
|
25033
27039
|
if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
|
|
25034
27040
|
const e = all[agent];
|
|
25035
|
-
if (!
|
|
27041
|
+
if (!isObject6(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
|
|
25036
27042
|
return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
|
|
25037
27043
|
}
|
|
25038
27044
|
return { event: e.event, payload: e.payload };
|
|
@@ -25050,39 +27056,11 @@ var CWD_KEY = {
|
|
|
25050
27056
|
opencode: "directory"
|
|
25051
27057
|
};
|
|
25052
27058
|
function payloadFor(agent, payload, worktree) {
|
|
25053
|
-
return worktree !== void 0 &&
|
|
25054
|
-
}
|
|
25055
|
-
var SHAPE = {
|
|
25056
|
-
"claude-code": "claude",
|
|
25057
|
-
codex: "claude",
|
|
25058
|
-
qwen: "claude",
|
|
25059
|
-
vscode: "claude",
|
|
25060
|
-
zcode: "claude",
|
|
25061
|
-
gemini: "gemini",
|
|
25062
|
-
"copilot-cli": "copilot",
|
|
25063
|
-
kiro: "text",
|
|
25064
|
-
pi: "text",
|
|
25065
|
-
opencode: "text"
|
|
25066
|
-
};
|
|
25067
|
-
var COPILOT_KEYS = ["permissionDecision", "additionalContext", "modifiedResult"];
|
|
27059
|
+
return worktree !== void 0 && isObject6(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
|
|
27060
|
+
}
|
|
25068
27061
|
function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
25069
27062
|
if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
|
|
25070
|
-
|
|
25071
|
-
let out;
|
|
25072
|
-
try {
|
|
25073
|
-
out = JSON.parse(stdout);
|
|
25074
|
-
} catch {
|
|
25075
|
-
return false;
|
|
25076
|
-
}
|
|
25077
|
-
if (!isObject5(out)) return false;
|
|
25078
|
-
switch (SHAPE[agent]) {
|
|
25079
|
-
case "claude":
|
|
25080
|
-
return isObject5(out.hookSpecificOutput) && out.hookSpecificOutput.hookEventName === event;
|
|
25081
|
-
case "gemini":
|
|
25082
|
-
return typeof out.decision === "string" || isObject5(out.hookSpecificOutput);
|
|
25083
|
-
default:
|
|
25084
|
-
return COPILOT_KEYS.some((k) => Object.hasOwn(out, k));
|
|
25085
|
-
}
|
|
27063
|
+
return stdout.length === 0 || replyErrors(agent, event, stdout).length === 0;
|
|
25086
27064
|
}
|
|
25087
27065
|
var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
|
|
25088
27066
|
function readProbePayload(cwd, ranged) {
|
|
@@ -25107,9 +27085,9 @@ function isReadShape(stdout) {
|
|
|
25107
27085
|
} catch {
|
|
25108
27086
|
return false;
|
|
25109
27087
|
}
|
|
25110
|
-
if (!
|
|
27088
|
+
if (!isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
|
|
25111
27089
|
const r = out.hookSpecificOutput.updatedToolOutput;
|
|
25112
|
-
if (!
|
|
27090
|
+
if (!isObject6(r) || r.type !== "text" || !isObject6(r.file)) return false;
|
|
25113
27091
|
const f = r.file;
|
|
25114
27092
|
return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
|
|
25115
27093
|
}
|
|
@@ -25137,13 +27115,84 @@ function isPassThrough(stdout) {
|
|
|
25137
27115
|
} catch {
|
|
25138
27116
|
return false;
|
|
25139
27117
|
}
|
|
25140
|
-
return !
|
|
27118
|
+
return !isObject6(out) || !isObject6(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
|
|
27119
|
+
}
|
|
27120
|
+
var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
27121
|
+
async function mediaProbe(i, timeoutMs) {
|
|
27122
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-media-"));
|
|
27123
|
+
try {
|
|
27124
|
+
const filePath = path7.join(home, "d5-media-probe.png");
|
|
27125
|
+
writeFileSync2(filePath, Buffer.concat([PNG_SIGNATURE, Buffer.alloc(OUTPUT_CAP + 1)]));
|
|
27126
|
+
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
27127
|
+
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27128
|
+
cwd: i.bundleDir,
|
|
27129
|
+
env: node.env,
|
|
27130
|
+
signal: i.signal,
|
|
27131
|
+
timeoutMs,
|
|
27132
|
+
stdin: JSON.stringify({
|
|
27133
|
+
session_id: "d5-media-probe",
|
|
27134
|
+
transcript_path: "",
|
|
27135
|
+
cwd: home,
|
|
27136
|
+
hook_event_name: "PreToolUse",
|
|
27137
|
+
tool_name: "Read",
|
|
27138
|
+
tool_use_id: "toolu_d5_media_probe",
|
|
27139
|
+
tool_input: { file_path: filePath }
|
|
27140
|
+
})
|
|
27141
|
+
});
|
|
27142
|
+
return r.stdout.toString("utf8");
|
|
27143
|
+
} finally {
|
|
27144
|
+
rmSync2(home, { recursive: true, force: true });
|
|
27145
|
+
}
|
|
27146
|
+
}
|
|
27147
|
+
async function ownProbe(i, timeoutMs) {
|
|
27148
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-own-"));
|
|
27149
|
+
try {
|
|
27150
|
+
const cfg = path7.join(home, ".claude");
|
|
27151
|
+
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
27152
|
+
mkdirSync4(refs, { recursive: true });
|
|
27153
|
+
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
27154
|
+
writeFileSync2(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
27155
|
+
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
27156
|
+
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27157
|
+
cwd: i.bundleDir,
|
|
27158
|
+
env: node.env,
|
|
27159
|
+
signal: i.signal,
|
|
27160
|
+
timeoutMs,
|
|
27161
|
+
stdin: JSON.stringify({
|
|
27162
|
+
session_id: "d5-own-probe",
|
|
27163
|
+
transcript_path: "",
|
|
27164
|
+
cwd: home,
|
|
27165
|
+
hook_event_name: "PreToolUse",
|
|
27166
|
+
tool_name: "Read",
|
|
27167
|
+
tool_use_id: "toolu_d5_own_probe",
|
|
27168
|
+
tool_input: { file_path: filePath }
|
|
27169
|
+
})
|
|
27170
|
+
});
|
|
27171
|
+
return r.stdout.toString("utf8");
|
|
27172
|
+
} finally {
|
|
27173
|
+
rmSync2(home, { recursive: true, force: true });
|
|
27174
|
+
}
|
|
27175
|
+
}
|
|
27176
|
+
function isDeny(stdout) {
|
|
27177
|
+
if (stdout.trim() === "") return false;
|
|
27178
|
+
let out;
|
|
27179
|
+
try {
|
|
27180
|
+
out = JSON.parse(stdout);
|
|
27181
|
+
} catch {
|
|
27182
|
+
return false;
|
|
27183
|
+
}
|
|
27184
|
+
return isObject6(out) && isObject6(out.hookSpecificOutput) && out.hookSpecificOutput.permissionDecision === "deny";
|
|
25141
27185
|
}
|
|
25142
27186
|
async function readProbeDetail(i, timeoutMs) {
|
|
25143
27187
|
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
25144
27188
|
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
27189
|
+
if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
|
|
27190
|
+
if (isDeny(await ownProbe(i, timeoutMs))) return D5_READ_OWN_DETAIL;
|
|
25145
27191
|
return null;
|
|
25146
27192
|
}
|
|
27193
|
+
async function mediaProbeDetail(i, timeoutMs) {
|
|
27194
|
+
return isDeny(await mediaProbe(i, timeoutMs)) ? D5_READ_MEDIA_DETAIL : null;
|
|
27195
|
+
}
|
|
25147
27196
|
function codexHookJournaled(db) {
|
|
25148
27197
|
if (db === null) return false;
|
|
25149
27198
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -25172,12 +27221,42 @@ async function codexPluginTrust(i) {
|
|
|
25172
27221
|
if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
|
|
25173
27222
|
return null;
|
|
25174
27223
|
}
|
|
27224
|
+
function codexStopPayload(cwd) {
|
|
27225
|
+
return {
|
|
27226
|
+
session_id: "d5-stop-probe",
|
|
27227
|
+
turn_id: "d5-stop-turn",
|
|
27228
|
+
transcript_path: null,
|
|
27229
|
+
cwd,
|
|
27230
|
+
hook_event_name: "Stop",
|
|
27231
|
+
model: "d5-probe",
|
|
27232
|
+
permission_mode: "default",
|
|
27233
|
+
stop_hook_active: false,
|
|
27234
|
+
last_assistant_message: "d5 stop probe"
|
|
27235
|
+
};
|
|
27236
|
+
}
|
|
27237
|
+
async function codexStopDetail(i, timeoutMs) {
|
|
27238
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-stop-"));
|
|
27239
|
+
try {
|
|
27240
|
+
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, [DATA_DIR_ENV]: home });
|
|
27241
|
+
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27242
|
+
cwd: i.bundleDir,
|
|
27243
|
+
env: node.env,
|
|
27244
|
+
signal: i.signal,
|
|
27245
|
+
timeoutMs,
|
|
27246
|
+
stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
|
|
27247
|
+
});
|
|
27248
|
+
const logged = existsSync13(path7.join(home, HOOK_ERROR_LOG_FILE));
|
|
27249
|
+
return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
|
|
27250
|
+
} finally {
|
|
27251
|
+
rmSync2(home, { recursive: true, force: true });
|
|
27252
|
+
}
|
|
27253
|
+
}
|
|
25175
27254
|
async function checkHookRoundTrip(i) {
|
|
25176
27255
|
if (i.agent === "codex") {
|
|
25177
27256
|
const trust = await codexPluginTrust(i);
|
|
25178
27257
|
if (trust !== null) return trust;
|
|
25179
27258
|
}
|
|
25180
|
-
if (i.agent === "codex" &&
|
|
27259
|
+
if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
25181
27260
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
25182
27261
|
}
|
|
25183
27262
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -25213,20 +27292,20 @@ async function checkHookRoundTrip(i) {
|
|
|
25213
27292
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
25214
27293
|
}
|
|
25215
27294
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
25216
|
-
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
|
|
27295
|
+
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "zcode" ? await mediaProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
|
|
25217
27296
|
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
25218
27297
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
25219
27298
|
}
|
|
25220
27299
|
|
|
25221
27300
|
// src/core/ops/db-heal.ts
|
|
25222
|
-
import { existsSync as
|
|
25223
|
-
import { basename as basename4, dirname as dirname8, join as
|
|
27301
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
|
|
27302
|
+
import { basename as basename4, dirname as dirname8, join as join17 } from "node:path";
|
|
25224
27303
|
|
|
25225
27304
|
// src/core/store/owners.ts
|
|
25226
|
-
import { mkdirSync as
|
|
25227
|
-
import { basename as basename3, join as
|
|
27305
|
+
import { mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync13, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27306
|
+
import { basename as basename3, join as join16 } from "node:path";
|
|
25228
27307
|
function ownersDir(configDir, projectKey) {
|
|
25229
|
-
return
|
|
27308
|
+
return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25230
27309
|
}
|
|
25231
27310
|
function errCode2(err) {
|
|
25232
27311
|
return err.code;
|
|
@@ -25246,7 +27325,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
25246
27325
|
const dir = ownersDir(configDir, projectKey);
|
|
25247
27326
|
let names;
|
|
25248
27327
|
try {
|
|
25249
|
-
names =
|
|
27328
|
+
names = readdirSync6(dir);
|
|
25250
27329
|
} catch (err) {
|
|
25251
27330
|
if (errCode2(err) === "ENOENT") return [];
|
|
25252
27331
|
throw err;
|
|
@@ -25254,10 +27333,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
25254
27333
|
const live = [];
|
|
25255
27334
|
for (const name of names) {
|
|
25256
27335
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25257
|
-
const file2 =
|
|
27336
|
+
const file2 = join16(dir, name);
|
|
25258
27337
|
let text;
|
|
25259
27338
|
try {
|
|
25260
|
-
text =
|
|
27339
|
+
text = readFileSync13(file2, "utf8");
|
|
25261
27340
|
} catch (err) {
|
|
25262
27341
|
if (errCode2(err) === "ENOENT") continue;
|
|
25263
27342
|
throw err;
|
|
@@ -25303,7 +27382,7 @@ function renameAside(dbPath) {
|
|
|
25303
27382
|
const ts = String(Date.now());
|
|
25304
27383
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
25305
27384
|
const file2 = dbPath + suffix;
|
|
25306
|
-
if (
|
|
27385
|
+
if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
25307
27386
|
}
|
|
25308
27387
|
return ts;
|
|
25309
27388
|
}
|
|
@@ -25326,11 +27405,11 @@ function utcStamp(now) {
|
|
|
25326
27405
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
25327
27406
|
}
|
|
25328
27407
|
function makeOrphanDir(projectDir) {
|
|
25329
|
-
const base =
|
|
27408
|
+
const base = join17(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
25330
27409
|
for (let n = 1; ; n += 1) {
|
|
25331
27410
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
25332
27411
|
try {
|
|
25333
|
-
|
|
27412
|
+
mkdirSync6(dir);
|
|
25334
27413
|
return dir;
|
|
25335
27414
|
} catch (err) {
|
|
25336
27415
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -25343,7 +27422,7 @@ async function healOrphan(project, files, row5) {
|
|
|
25343
27422
|
try {
|
|
25344
27423
|
dir = makeOrphanDir(dirname8(project.dbPath));
|
|
25345
27424
|
for (const f of files) {
|
|
25346
|
-
const to =
|
|
27425
|
+
const to = join17(dir, basename4(f.path));
|
|
25347
27426
|
renameWithRetry(f.path, to);
|
|
25348
27427
|
moved.push({ path: to, bytes: f.bytes });
|
|
25349
27428
|
}
|
|
@@ -25410,8 +27489,8 @@ function buildReportHead(input) {
|
|
|
25410
27489
|
|
|
25411
27490
|
// src/core/ops/doctor-issue.ts
|
|
25412
27491
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
25413
|
-
import { closeSync, existsSync as
|
|
25414
|
-
import { delimiter, join as
|
|
27492
|
+
import { closeSync as closeSync2, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync14, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
|
|
27493
|
+
import { delimiter, join as join18 } from "node:path";
|
|
25415
27494
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
25416
27495
|
function tildeOf(env) {
|
|
25417
27496
|
const home = homeDirOf(env);
|
|
@@ -25423,8 +27502,8 @@ function tildeOf(env) {
|
|
|
25423
27502
|
} catch {
|
|
25424
27503
|
}
|
|
25425
27504
|
homes.sort((a, b) => b.length - a.length);
|
|
25426
|
-
const
|
|
25427
|
-
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece :
|
|
27505
|
+
const slash2 = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
|
|
27506
|
+
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash2(piece)).join("~"), t);
|
|
25428
27507
|
}
|
|
25429
27508
|
function maskLine(line) {
|
|
25430
27509
|
const lower = line.toLowerCase();
|
|
@@ -25452,8 +27531,8 @@ function onPath(env, tool) {
|
|
|
25452
27531
|
const out = [];
|
|
25453
27532
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25454
27533
|
if (dir === "") continue;
|
|
25455
|
-
for (const n of names) if (
|
|
25456
|
-
out.push(
|
|
27534
|
+
for (const n of names) if (existsSync15(join18(dir, n))) {
|
|
27535
|
+
out.push(join18(dir, n));
|
|
25457
27536
|
break;
|
|
25458
27537
|
}
|
|
25459
27538
|
}
|
|
@@ -25461,33 +27540,33 @@ function onPath(env, tool) {
|
|
|
25461
27540
|
}
|
|
25462
27541
|
function hookLogTail(env) {
|
|
25463
27542
|
const file2 = hookLogPath(env);
|
|
25464
|
-
if (file2 === "" || !
|
|
27543
|
+
if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
25465
27544
|
try {
|
|
25466
|
-
const fd =
|
|
27545
|
+
const fd = openSync2(file2, "r");
|
|
25467
27546
|
try {
|
|
25468
27547
|
const size = fstatSync(fd).size;
|
|
25469
27548
|
const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
|
|
25470
27549
|
const buf = Buffer.alloc(size - start);
|
|
25471
|
-
|
|
27550
|
+
readSync2(fd, buf, 0, buf.length, start);
|
|
25472
27551
|
const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
|
|
25473
27552
|
if (start > 0) lines.shift();
|
|
25474
27553
|
return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
|
|
25475
27554
|
} finally {
|
|
25476
|
-
|
|
27555
|
+
closeSync2(fd);
|
|
25477
27556
|
}
|
|
25478
27557
|
} catch (err) {
|
|
25479
27558
|
return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
|
|
25480
27559
|
}
|
|
25481
27560
|
}
|
|
25482
27561
|
async function journalRows(ctx) {
|
|
25483
|
-
const
|
|
25484
|
-
if (!
|
|
27562
|
+
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
27563
|
+
if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
25485
27564
|
try {
|
|
25486
27565
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
25487
27566
|
try {
|
|
25488
27567
|
const rows = db.raw.prepare(`SELECT kind, tool, bytes, ok, exit_code, created_at FROM events ORDER BY seq DESC LIMIT ${DOCTOR_JOURNAL_ROWS}`).all();
|
|
25489
27568
|
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
25490
|
-
return
|
|
27569
|
+
return head2.concat(rows.map((r) => `| ${cell5(r.kind)} | ${cell5(r.tool)} | ${cell5(r.bytes)} | ${cell5(r.ok)} | ${cell5(r.exit_code)} | ${typeof r.created_at === "number" ? new Date(r.created_at).toISOString() : cell5(r.created_at)} |`));
|
|
25491
27570
|
} finally {
|
|
25492
27571
|
closeDb(db);
|
|
25493
27572
|
}
|
|
@@ -25499,21 +27578,21 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25499
27578
|
const home = homeDirOf(env);
|
|
25500
27579
|
const files = configPaths(adapter, env, worktree);
|
|
25501
27580
|
if (home !== null) {
|
|
25502
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
25503
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
27581
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join18(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
27582
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join18(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
25504
27583
|
}
|
|
25505
27584
|
const out = [];
|
|
25506
27585
|
const seen = /* @__PURE__ */ new Set();
|
|
25507
27586
|
for (const f of files) {
|
|
25508
27587
|
if (seen.has(f.path)) continue;
|
|
25509
27588
|
seen.add(f.path);
|
|
25510
|
-
if (!
|
|
27589
|
+
if (!existsSync15(f.path)) {
|
|
25511
27590
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
25512
27591
|
continue;
|
|
25513
27592
|
}
|
|
25514
27593
|
let text = "";
|
|
25515
27594
|
try {
|
|
25516
|
-
text =
|
|
27595
|
+
text = readFileSync14(f.path, "utf8");
|
|
25517
27596
|
} catch (err) {
|
|
25518
27597
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
25519
27598
|
continue;
|
|
@@ -25583,10 +27662,10 @@ async function buildIssueBody(i) {
|
|
|
25583
27662
|
async function writeIssueReport(i) {
|
|
25584
27663
|
const tilde = tildeOf(i.env);
|
|
25585
27664
|
const body = await buildIssueBody(i);
|
|
25586
|
-
const dir =
|
|
25587
|
-
|
|
25588
|
-
const file2 =
|
|
25589
|
-
|
|
27665
|
+
const dir = join18(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
27666
|
+
mkdirSync7(dir, { recursive: true });
|
|
27667
|
+
const file2 = join18(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
27668
|
+
writeFileSync4(file2, body);
|
|
25590
27669
|
const shown2 = tilde(file2);
|
|
25591
27670
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
25592
27671
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
@@ -25612,7 +27691,7 @@ async function guard(id2, run) {
|
|
|
25612
27691
|
}
|
|
25613
27692
|
}
|
|
25614
27693
|
async function codexDb(ctx, adapter) {
|
|
25615
|
-
if (adapter.id !== "codex" || !
|
|
27694
|
+
if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
|
|
25616
27695
|
try {
|
|
25617
27696
|
return await openDb(ctx.project, { readOnly: true });
|
|
25618
27697
|
} catch {
|
|
@@ -25642,11 +27721,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25642
27721
|
}
|
|
25643
27722
|
}
|
|
25644
27723
|
function ownServerId(configDir, projectKey) {
|
|
25645
|
-
const dir =
|
|
25646
|
-
if (!
|
|
25647
|
-
for (const name of
|
|
27724
|
+
const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27725
|
+
if (!existsSync16(dir)) return "";
|
|
27726
|
+
for (const name of readdirSync7(dir)) {
|
|
25648
27727
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25649
|
-
if (
|
|
27728
|
+
if (readFileSync15(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25650
27729
|
}
|
|
25651
27730
|
return "";
|
|
25652
27731
|
}
|
|
@@ -25672,7 +27751,8 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
25672
27751
|
return r.row;
|
|
25673
27752
|
},
|
|
25674
27753
|
D9: () => checkIndex(project),
|
|
25675
|
-
D10: () => checkMode(adapter),
|
|
27754
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
27755
|
+
// D-1331-OC-PERM-1
|
|
25676
27756
|
D11: () => checkShell(env)
|
|
25677
27757
|
};
|
|
25678
27758
|
const rows = [];
|
|
@@ -25741,9 +27821,9 @@ var ctxDoctor = Object.freeze({
|
|
|
25741
27821
|
});
|
|
25742
27822
|
|
|
25743
27823
|
// src/core/tools/execute.ts
|
|
25744
|
-
import { existsSync as
|
|
27824
|
+
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
25745
27825
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25746
|
-
import { dirname as dirname10, join as
|
|
27826
|
+
import { dirname as dirname10, join as join20, parse as parse3, resolve as resolve8 } from "node:path";
|
|
25747
27827
|
|
|
25748
27828
|
// src/core/sandbox/win-build.ts
|
|
25749
27829
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -25826,7 +27906,7 @@ function schemaLine(issue2) {
|
|
|
25826
27906
|
}
|
|
25827
27907
|
function fileError(given, abs, root) {
|
|
25828
27908
|
let dir = abs;
|
|
25829
|
-
while (!
|
|
27909
|
+
while (!existsSync17(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
25830
27910
|
if (isInside(root, dir)) return null;
|
|
25831
27911
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
25832
27912
|
}
|
|
@@ -25862,16 +27942,16 @@ async function finish(input, ctx, r, exitCode, journal) {
|
|
|
25862
27942
|
const isError = exitCode !== 0 && !(input.language === "shell" && exitCode === SOFT_EXIT && r.stderr.length === 0);
|
|
25863
27943
|
const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "");
|
|
25864
27944
|
const fullBytes = Buffer.byteLength(combined, "utf8");
|
|
25865
|
-
const
|
|
27945
|
+
const head2 = summaryLine(exitCode, fullBytes);
|
|
25866
27946
|
const intent = input.intent ?? "";
|
|
25867
27947
|
const bare2 = exitCode === 0 && input.summary !== true && combined !== "";
|
|
25868
|
-
const direct = (bare2 ? "" :
|
|
25869
|
-
const fits = Buffer.byteLength(
|
|
27948
|
+
const direct = (bare2 ? "" : head2 + "\n") + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
|
|
27949
|
+
const fits = Buffer.byteLength(head2 + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined, "utf8") <= OUTPUT_CAP;
|
|
25870
27950
|
if (intent === "" && fits) {
|
|
25871
27951
|
return { text: direct, isError, sandboxBytes: fullBytes, journal };
|
|
25872
27952
|
}
|
|
25873
27953
|
const label2 = sourceLabel(input.code);
|
|
25874
|
-
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(
|
|
27954
|
+
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head2, "utf8") - 2 - moreReserve(intent, label2);
|
|
25875
27955
|
const db = await openDb(ctx.project);
|
|
25876
27956
|
let picked;
|
|
25877
27957
|
try {
|
|
@@ -25880,7 +27960,7 @@ async function finish(input, ctx, r, exitCode, journal) {
|
|
|
25880
27960
|
} finally {
|
|
25881
27961
|
closeDb(db);
|
|
25882
27962
|
}
|
|
25883
|
-
const text =
|
|
27963
|
+
const text = head2 + "\n" + picked.text + (picked.more === null ? "" : "\n" + picked.more);
|
|
25884
27964
|
return { text: capBytes(text, OUTPUT_CAP).text, isError, sandboxBytes: fullBytes, journal };
|
|
25885
27965
|
}
|
|
25886
27966
|
async function handler3(raw, ctx) {
|
|
@@ -25890,7 +27970,7 @@ async function handler3(raw, ctx) {
|
|
|
25890
27970
|
const cwd = ctx.project.worktree;
|
|
25891
27971
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
25892
27972
|
if (input.file !== void 0) {
|
|
25893
|
-
const abs =
|
|
27973
|
+
const abs = resolve8(cwd, input.file);
|
|
25894
27974
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
25895
27975
|
if (bad !== null) return fail5(bad);
|
|
25896
27976
|
extra.CTX_FILE = abs;
|
|
@@ -25907,9 +27987,9 @@ async function handler3(raw, ctx) {
|
|
|
25907
27987
|
if (takesDashC(input.language, runtime)) {
|
|
25908
27988
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
25909
27989
|
} else {
|
|
25910
|
-
tmpDir = mkdtempSync2(
|
|
25911
|
-
const file2 =
|
|
25912
|
-
|
|
27990
|
+
tmpDir = mkdtempSync2(join20(tmpdir3(), TMP_PREFIX));
|
|
27991
|
+
const file2 = join20(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
27992
|
+
writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
|
|
25913
27993
|
argv = scriptArgv(input.language, runtime, file2);
|
|
25914
27994
|
}
|
|
25915
27995
|
if (input.background === true) {
|
|
@@ -25944,12 +28024,12 @@ var ctxExecute = {
|
|
|
25944
28024
|
};
|
|
25945
28025
|
|
|
25946
28026
|
// src/core/tools/index.ts
|
|
25947
|
-
import { existsSync as
|
|
25948
|
-
import { dirname as dirname11, extname, join as
|
|
28027
|
+
import { existsSync as existsSync18, readFileSync as readFileSync17, statSync as statSync8 } from "node:fs";
|
|
28028
|
+
import { dirname as dirname11, extname as extname3, join as join22, relative as relative5, resolve as resolve9 } from "node:path";
|
|
25949
28029
|
|
|
25950
28030
|
// src/core/index/walk.ts
|
|
25951
|
-
import { readdirSync as
|
|
25952
|
-
import { join as
|
|
28031
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync16, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
28032
|
+
import { join as join21 } from "node:path";
|
|
25953
28033
|
var GITIGNORE = ".gitignore";
|
|
25954
28034
|
var GIT_DIR = ".git";
|
|
25955
28035
|
function walkDir(root, containmentRoot) {
|
|
@@ -25958,19 +28038,19 @@ function walkDir(root, containmentRoot) {
|
|
|
25958
28038
|
const found = [];
|
|
25959
28039
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
25960
28040
|
found.sort(compareFound);
|
|
25961
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
28041
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join21(...f.dir, f.name) }));
|
|
25962
28042
|
}
|
|
25963
28043
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
25964
28044
|
let entries;
|
|
25965
28045
|
try {
|
|
25966
|
-
entries =
|
|
28046
|
+
entries = readdirSync8(abs, { withFileTypes: true });
|
|
25967
28047
|
} catch {
|
|
25968
28048
|
return;
|
|
25969
28049
|
}
|
|
25970
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
28050
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join21(abs, GITIGNORE), rel)) : parent;
|
|
25971
28051
|
for (const e of entries) {
|
|
25972
28052
|
if (e.name === GIT_DIR) continue;
|
|
25973
|
-
const path8 =
|
|
28053
|
+
const path8 = join21(abs, e.name);
|
|
25974
28054
|
let isDir = e.isDirectory();
|
|
25975
28055
|
let isFile = e.isFile();
|
|
25976
28056
|
let target = path8;
|
|
@@ -26010,7 +28090,7 @@ function compareFound(a, b) {
|
|
|
26010
28090
|
function readRules(file2, base) {
|
|
26011
28091
|
let body;
|
|
26012
28092
|
try {
|
|
26013
|
-
body =
|
|
28093
|
+
body = readFileSync16(file2, "utf8");
|
|
26014
28094
|
} catch {
|
|
26015
28095
|
return [];
|
|
26016
28096
|
}
|
|
@@ -26190,9 +28270,9 @@ function ipv6Words(address) {
|
|
|
26190
28270
|
};
|
|
26191
28271
|
const gap = a.indexOf("::");
|
|
26192
28272
|
if (gap < 0) return words2(a);
|
|
26193
|
-
const
|
|
28273
|
+
const head2 = words2(a.slice(0, gap));
|
|
26194
28274
|
const tail = words2(a.slice(gap + 2));
|
|
26195
|
-
return [...
|
|
28275
|
+
return [...head2, ...new Array(8 - head2.length - tail.length).fill(0), ...tail];
|
|
26196
28276
|
}
|
|
26197
28277
|
function dotted(hi, lo) {
|
|
26198
28278
|
return [hi >> 8, hi & 255, lo >> 8, lo & 255].join(".");
|
|
@@ -26232,18 +28312,18 @@ function request(u, conn, proxy, signal) {
|
|
|
26232
28312
|
const host = bare(u.hostname);
|
|
26233
28313
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
26234
28314
|
const path8 = u.pathname + u.search;
|
|
26235
|
-
return new Promise((
|
|
28315
|
+
return new Promise((resolve11, reject) => {
|
|
26236
28316
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
26237
28317
|
if (proxy === void 0) {
|
|
26238
28318
|
const mod = u.protocol === "https:" ? https : http;
|
|
26239
28319
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
26240
|
-
req.on("response",
|
|
28320
|
+
req.on("response", resolve11).on("error", onErr).end();
|
|
26241
28321
|
return;
|
|
26242
28322
|
}
|
|
26243
28323
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
26244
28324
|
if (u.protocol === "http:") {
|
|
26245
28325
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
26246
|
-
req.on("response",
|
|
28326
|
+
req.on("response", resolve11).on("error", onErr).end();
|
|
26247
28327
|
return;
|
|
26248
28328
|
}
|
|
26249
28329
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -26263,16 +28343,16 @@ function request(u, conn, proxy, signal) {
|
|
|
26263
28343
|
headers: { host: u.host },
|
|
26264
28344
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
26265
28345
|
});
|
|
26266
|
-
req.on("response",
|
|
28346
|
+
req.on("response", resolve11).on("error", onErr).end();
|
|
26267
28347
|
});
|
|
26268
28348
|
tunnel.end();
|
|
26269
28349
|
});
|
|
26270
28350
|
}
|
|
26271
28351
|
function readBody(res) {
|
|
26272
|
-
return new Promise((
|
|
28352
|
+
return new Promise((resolve11, reject) => {
|
|
26273
28353
|
const parts = [];
|
|
26274
28354
|
res.on("data", (b) => parts.push(b));
|
|
26275
|
-
res.on("end", () =>
|
|
28355
|
+
res.on("end", () => resolve11(Buffer.concat(parts)));
|
|
26276
28356
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
26277
28357
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
26278
28358
|
});
|
|
@@ -30129,7 +32209,7 @@ function userLabel(label2) {
|
|
|
30129
32209
|
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
30130
32210
|
}
|
|
30131
32211
|
function kindOfPath(p) {
|
|
30132
|
-
return EXT_KIND[
|
|
32212
|
+
return EXT_KIND[extname3(p).toLowerCase()] ?? "text";
|
|
30133
32213
|
}
|
|
30134
32214
|
function kindOfType(contentType) {
|
|
30135
32215
|
const semi = contentType.indexOf(";");
|
|
@@ -30138,25 +32218,25 @@ function kindOfType(contentType) {
|
|
|
30138
32218
|
}
|
|
30139
32219
|
function readUtf8(absPath) {
|
|
30140
32220
|
try {
|
|
30141
|
-
return utf8.decode(
|
|
32221
|
+
return utf8.decode(readFileSync17(absPath));
|
|
30142
32222
|
} catch {
|
|
30143
32223
|
return void 0;
|
|
30144
32224
|
}
|
|
30145
32225
|
}
|
|
30146
32226
|
function missingOrOutside(given, abs, root) {
|
|
30147
32227
|
let dir = abs;
|
|
30148
|
-
while (!
|
|
32228
|
+
while (!existsSync18(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
|
|
30149
32229
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
30150
32230
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
30151
32231
|
}
|
|
30152
32232
|
function pathItems(input, project) {
|
|
30153
|
-
const abs =
|
|
32233
|
+
const abs = resolve9(project.worktree, input.path);
|
|
30154
32234
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
30155
32235
|
const base = relative5(project.worktree, abs);
|
|
30156
32236
|
if (statSync8(abs).isDirectory()) {
|
|
30157
32237
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
30158
32238
|
sourceKind: "path",
|
|
30159
|
-
label: pathLabel(
|
|
32239
|
+
label: pathLabel(join22(base, f.relPath)),
|
|
30160
32240
|
kind: kindOfPath(f.relPath),
|
|
30161
32241
|
read: () => readUtf8(f.absPath)
|
|
30162
32242
|
}));
|
|
@@ -30228,8 +32308,8 @@ async function handler4(input, ctx) {
|
|
|
30228
32308
|
} finally {
|
|
30229
32309
|
closeDb(db);
|
|
30230
32310
|
}
|
|
30231
|
-
const
|
|
30232
|
-
const first = sources === 1 && lastId > 0 ?
|
|
32311
|
+
const head2 = "Indexed " + sources + " source(s), " + chunks + " chunk(s) from ";
|
|
32312
|
+
const first = sources === 1 && lastId > 0 ? head2 + sourceHandle(lastId) + ". " + indexedLabelLine(from, lastId) : head2 + shownLabel(from, null) + ".";
|
|
30233
32313
|
const line = [first, ...notes].join("\n");
|
|
30234
32314
|
return {
|
|
30235
32315
|
text: capBytes(line, OUTPUT_CAP).text,
|
|
@@ -30335,9 +32415,8 @@ async function handler6(input, ctx) {
|
|
|
30335
32415
|
const newest = rows.at(-1);
|
|
30336
32416
|
if (newest === void 0) return reply3(RESUME_EMPTY_LINE, false);
|
|
30337
32417
|
const sources = listSessionSources(db, sessionId, MAX_CANDIDATES).map((r) => "source " + sourceHandle(r.id) + ": " + r.label + " (" + r.bytes + " B)");
|
|
30338
|
-
const goal = readFirstPrompt(db, sessionId);
|
|
30339
32418
|
const last2 = readLastPrompt(db, sessionId);
|
|
30340
|
-
const units = queryUnits(db, sessionId, recallQueryText(last2
|
|
32419
|
+
const units = queryUnits(db, sessionId, recallQueryText(last2), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
|
|
30341
32420
|
const block = renderState(rows, newest.turn, { sources, units });
|
|
30342
32421
|
if (Buffer.byteLength(block, "utf8") > RESUME_CAP) throw new Error("ctx_resume: state block over RESUME_CAP (render bug).");
|
|
30343
32422
|
return reply3(block, false);
|
|
@@ -30401,7 +32480,7 @@ function readWeek(raw, lastMs) {
|
|
|
30401
32480
|
}
|
|
30402
32481
|
return days;
|
|
30403
32482
|
}
|
|
30404
|
-
var
|
|
32483
|
+
var EMPTY6 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
|
|
30405
32484
|
function totals(r) {
|
|
30406
32485
|
const produced = Number(r.produced);
|
|
30407
32486
|
const returned = Number(r.returned);
|
|
@@ -30441,7 +32520,7 @@ function sum(groups) {
|
|
|
30441
32520
|
produced: t.produced + g.produced,
|
|
30442
32521
|
returned: t.returned + g.returned,
|
|
30443
32522
|
saved: t.saved + g.saved
|
|
30444
|
-
}),
|
|
32523
|
+
}), EMPTY6);
|
|
30445
32524
|
}
|
|
30446
32525
|
function reductionPct(t) {
|
|
30447
32526
|
if (t.calls === 0) return 0;
|
|
@@ -30499,8 +32578,8 @@ function plural(n, word) {
|
|
|
30499
32578
|
}
|
|
30500
32579
|
function table2(title, rows) {
|
|
30501
32580
|
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
30502
|
-
const
|
|
30503
|
-
return [
|
|
32581
|
+
const head2 = " " + title.padEnd(LABEL_W) + right("Calls", STATS_CALLS_W) + right("Made", NUM_W) + right("Sent", NUM_W) + right("Kept out", NUM_W) + right("%", PCT_W);
|
|
32582
|
+
return [head2, ...rows.map((r) => (" " + label(r.name) + right(count(r.calls), STATS_CALLS_W) + right(bytes4(r.produced), NUM_W) + right(bytes4(r.returned), NUM_W) + right(bytes4(r.saved), NUM_W) + right(pct(r), PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
|
|
30504
32583
|
}
|
|
30505
32584
|
function bySaved(a, b) {
|
|
30506
32585
|
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
@@ -30544,10 +32623,10 @@ function windowLine(saved) {
|
|
|
30544
32623
|
const t = saved / STATS_BYTES_PER_TOKEN;
|
|
30545
32624
|
const share = t / STATS_WINDOW_TOKENS;
|
|
30546
32625
|
const win = `a ${tokens(STATS_WINDOW_TOKENS)} window`;
|
|
30547
|
-
const
|
|
30548
|
-
if (share >= 1) return `${
|
|
32626
|
+
const head2 = ` about ${tokens(t)} tokens kept out`;
|
|
32627
|
+
if (share >= 1) return `${head2}, ${whole(share)} times ${win}`;
|
|
30549
32628
|
const p = share * PERCENT_SCALE;
|
|
30550
|
-
return p * STATS_WHOLE_FROM < 1 ?
|
|
32629
|
+
return p * STATS_WHOLE_FROM < 1 ? head2 : `${head2}, ${whole(p)}% of ${win}`;
|
|
30551
32630
|
}
|
|
30552
32631
|
function ymd(day) {
|
|
30553
32632
|
return new Date(day * MS_PER_DAY).toISOString().slice(0, "yyyy-mm-dd".length);
|
|
@@ -30578,14 +32657,14 @@ function lastDays(week, allCalls) {
|
|
|
30578
32657
|
const all = saved.reduce((a, b) => a + b, 0);
|
|
30579
32658
|
const calls = week.reduce((a, d) => a + d.calls, 0);
|
|
30580
32659
|
const max = Math.max(0, ...saved);
|
|
30581
|
-
const
|
|
32660
|
+
const head2 = `Last ${STATS_DAYS} days of use \xB7 ${ymd(week[0].day)} to ${ymd(week[week.length - 1].day)}`;
|
|
30582
32661
|
const card = calls < allCalls ? [
|
|
30583
32662
|
cards(["Kept out", "Tokens kept out", "Calls", "Kept out per call"]),
|
|
30584
32663
|
cards([bytes4(all), "about " + tokens(all / STATS_BYTES_PER_TOKEN), count(calls), bytes4(calls > 0 ? all / calls : 0)]),
|
|
30585
32664
|
""
|
|
30586
32665
|
] : [];
|
|
30587
32666
|
return [
|
|
30588
|
-
|
|
32667
|
+
head2,
|
|
30589
32668
|
...card,
|
|
30590
32669
|
...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + right(bytes4(saved[i]), NUM_W)] : []),
|
|
30591
32670
|
" " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
|
|
@@ -30604,15 +32683,15 @@ function fit(line) {
|
|
|
30604
32683
|
return chars.length <= STATS_WIDTH ? line : chars.slice(0, STATS_WIDTH - 1).join("") + "\u2026";
|
|
30605
32684
|
}
|
|
30606
32685
|
function report(f, sessionId, agent) {
|
|
30607
|
-
const
|
|
32686
|
+
const head2 = [STATS_REPORT_TITLE, "\u2500".repeat(STATS_WIDTH), ""];
|
|
30608
32687
|
const project = sum(f.groups);
|
|
30609
|
-
if (project.calls === 0) return [...
|
|
32688
|
+
if (project.calls === 0) return [...head2, ...STATS_EMPTY_LINES].join("\n");
|
|
30610
32689
|
const session = sum(f.groups.filter((g) => g.session === sessionId));
|
|
30611
32690
|
const [scopeName, focus] = session.calls > 0 ? ["This session", session] : ["This project", project];
|
|
30612
32691
|
const top = Math.max(focus.produced, focus.returned);
|
|
30613
32692
|
const extra = session.calls > 0 ? ` \xB7 ${span(f.span)} active` : "";
|
|
30614
32693
|
const lines = [
|
|
30615
|
-
...
|
|
32694
|
+
...head2,
|
|
30616
32695
|
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
30617
32696
|
` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
|
|
30618
32697
|
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + right(bytes4(focus.produced), NUM_W),
|
|
@@ -30635,8 +32714,8 @@ function report(f, sessionId, agent) {
|
|
|
30635
32714
|
] : []
|
|
30636
32715
|
];
|
|
30637
32716
|
const agents = /* @__PURE__ */ new Map();
|
|
30638
|
-
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ??
|
|
30639
|
-
if (!agents.has(agent)) agents.set(agent,
|
|
32717
|
+
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY6, g]));
|
|
32718
|
+
if (!agents.has(agent)) agents.set(agent, EMPTY6);
|
|
30640
32719
|
lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
30641
32720
|
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
30642
32721
|
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + right("Session", STATS_KIND_W) + right("Project", STATS_KIND_W));
|
|
@@ -30696,27 +32775,27 @@ var ctxStats = Object.freeze({
|
|
|
30696
32775
|
});
|
|
30697
32776
|
|
|
30698
32777
|
// src/core/ops/host-write.ts
|
|
30699
|
-
import { copyFileSync, existsSync as
|
|
30700
|
-
import { dirname as dirname12, join as
|
|
32778
|
+
import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
32779
|
+
import { dirname as dirname12, join as join23 } from "node:path";
|
|
30701
32780
|
function defaultWrite(file2, text) {
|
|
30702
|
-
|
|
32781
|
+
writeFileSync6(file2, text, "utf8");
|
|
30703
32782
|
}
|
|
30704
32783
|
function hostConfigPath(agent, home, env) {
|
|
30705
32784
|
const own2 = OWN_MCP_ENTRY[agent];
|
|
30706
32785
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
30707
32786
|
switch (agent) {
|
|
30708
32787
|
case "opencode":
|
|
30709
|
-
return
|
|
32788
|
+
return join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
30710
32789
|
// D-WIN-OPENCODE-DIR-1
|
|
30711
32790
|
case "pi":
|
|
30712
|
-
return
|
|
32791
|
+
return join23(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
30713
32792
|
case "gemini":
|
|
30714
|
-
return
|
|
32793
|
+
return join23(geminiDirOf(env, home), SETTINGS_FILE);
|
|
30715
32794
|
// D-R38-GEMINI-HOME-1
|
|
30716
32795
|
case "copilot-cli":
|
|
30717
32796
|
return null;
|
|
30718
32797
|
default:
|
|
30719
|
-
return
|
|
32798
|
+
return join23(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
30720
32799
|
}
|
|
30721
32800
|
}
|
|
30722
32801
|
function cell3(value) {
|
|
@@ -30728,8 +32807,8 @@ function toRow(file2, edit) {
|
|
|
30728
32807
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
30729
32808
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30730
32809
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
30731
|
-
const had =
|
|
30732
|
-
|
|
32810
|
+
const had = existsSync19(file2);
|
|
32811
|
+
mkdirSync8(dirname12(file2), { recursive: true });
|
|
30733
32812
|
if (had) copyFileSync(file2, trash);
|
|
30734
32813
|
try {
|
|
30735
32814
|
write2(tmp, text);
|
|
@@ -30758,7 +32837,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30758
32837
|
if (requested === null) return [];
|
|
30759
32838
|
const current = readHostConfig(row5.id, requested);
|
|
30760
32839
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
30761
|
-
const exists =
|
|
32840
|
+
const exists = existsSync19(current.path);
|
|
30762
32841
|
if (exists && result.text === current.text) return [];
|
|
30763
32842
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
30764
32843
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -30766,15 +32845,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30766
32845
|
}
|
|
30767
32846
|
|
|
30768
32847
|
// src/core/ops/uninstall.ts
|
|
30769
|
-
import { existsSync as
|
|
30770
|
-
import { join as
|
|
32848
|
+
import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
32849
|
+
import { join as join24 } from "node:path";
|
|
30771
32850
|
function row2(area, before, after) {
|
|
30772
32851
|
return { area, before, after };
|
|
30773
32852
|
}
|
|
30774
32853
|
function stopServers(configDir, projectKey) {
|
|
30775
32854
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
30776
|
-
const dir =
|
|
30777
|
-
for (const serverId of stopped)
|
|
32855
|
+
const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
32856
|
+
for (const serverId of stopped) writeFileSync7(join24(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
30778
32857
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
30779
32858
|
}
|
|
30780
32859
|
function rootOrNull(adapter, env) {
|
|
@@ -30792,15 +32871,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
30792
32871
|
const root = rootOrNull(adapter, env);
|
|
30793
32872
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30794
32873
|
if (adapter.installMode === "marketplace") {
|
|
30795
|
-
const cache =
|
|
32874
|
+
const cache = join24(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
30796
32875
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
30797
32876
|
}
|
|
30798
32877
|
rmSync6(root, { recursive: true, force: true });
|
|
30799
32878
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
30800
32879
|
}
|
|
30801
32880
|
case "plugin": {
|
|
30802
|
-
const agentDir =
|
|
30803
|
-
if (!
|
|
32881
|
+
const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
32882
|
+
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30804
32883
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
30805
32884
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30806
32885
|
}
|
|
@@ -30845,7 +32924,7 @@ function ownEntries2(agent, env) {
|
|
|
30845
32924
|
}
|
|
30846
32925
|
if (agent === "opencode") {
|
|
30847
32926
|
return [{
|
|
30848
|
-
file:
|
|
32927
|
+
file: join24(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
30849
32928
|
// D-WIN-OPENCODE-DIR-1
|
|
30850
32929
|
key: OPENCODE_PLUGIN_KEY,
|
|
30851
32930
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -30856,7 +32935,7 @@ function ownEntries2(agent, env) {
|
|
|
30856
32935
|
if (agent === "pi") {
|
|
30857
32936
|
const agentDir = piAgentDirOf(env, home);
|
|
30858
32937
|
return [{
|
|
30859
|
-
file:
|
|
32938
|
+
file: join24(agentDir, SETTINGS_FILE),
|
|
30860
32939
|
key: PI_PACKAGES_KEY,
|
|
30861
32940
|
shown: PI_PACKAGES_KEY,
|
|
30862
32941
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -30878,12 +32957,12 @@ function removeOwnEntries(agent, env) {
|
|
|
30878
32957
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
30879
32958
|
}
|
|
30880
32959
|
function removeProjectData(configDir, projectKey) {
|
|
30881
|
-
const projects =
|
|
30882
|
-
const dir =
|
|
30883
|
-
if (!
|
|
32960
|
+
const projects = join24(configDir, PROJECTS_DIR_NAME);
|
|
32961
|
+
const dir = join24(projects, projectKey);
|
|
32962
|
+
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
30884
32963
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30885
|
-
for (const name of
|
|
30886
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
32964
|
+
for (const name of readdirSync9(dir)) {
|
|
32965
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join24(dir, name), { recursive: true, force: true });
|
|
30887
32966
|
}
|
|
30888
32967
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
30889
32968
|
}
|
|
@@ -30891,12 +32970,12 @@ function runUninstall(input) {
|
|
|
30891
32970
|
const configDir = resolveConfigDir(input.env);
|
|
30892
32971
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
30893
32972
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
30894
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
32973
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join24(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
30895
32974
|
return { rows, stopped: stop.stopped };
|
|
30896
32975
|
}
|
|
30897
32976
|
|
|
30898
32977
|
// src/core/ops/v1-remove.ts
|
|
30899
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
32978
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync18, rmSync as rmSync7 } from "node:fs";
|
|
30900
32979
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30901
32980
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30902
32981
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -30908,7 +32987,7 @@ function moveAside(target, undo) {
|
|
|
30908
32987
|
}
|
|
30909
32988
|
function keepAside(target, undo) {
|
|
30910
32989
|
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
30911
|
-
for (let n = 2;
|
|
32990
|
+
for (let n = 2; existsSync21(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
30912
32991
|
renameWithRetry(target, aside);
|
|
30913
32992
|
undo.push({ trash: aside, target, keep: true });
|
|
30914
32993
|
return aside;
|
|
@@ -30947,8 +33026,8 @@ function locate(doc, path8) {
|
|
|
30947
33026
|
return null;
|
|
30948
33027
|
}
|
|
30949
33028
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
30950
|
-
const layout = hostLayout(
|
|
30951
|
-
const text = hostText(
|
|
33029
|
+
const layout = hostLayout(readFileSync18(file2, "utf8"));
|
|
33030
|
+
const text = hostText(readFileSync18(file2, "utf8"));
|
|
30952
33031
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
30953
33032
|
const hit = /* @__PURE__ */ new Set();
|
|
30954
33033
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -30985,20 +33064,20 @@ function removeV1(agent, findings, project) {
|
|
|
30985
33064
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30986
33065
|
else if (f.path === "") {
|
|
30987
33066
|
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30988
|
-
else if (
|
|
30989
|
-
else if (
|
|
33067
|
+
else if (existsSync21(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
33068
|
+
else if (existsSync21(f.file)) {
|
|
30990
33069
|
moveAside(f.file, undo);
|
|
30991
33070
|
done.set(f, UPGRADE_REMOVED);
|
|
30992
33071
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30993
33072
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30994
33073
|
}
|
|
30995
33074
|
for (const [file2, list4] of entries) {
|
|
30996
|
-
if (!
|
|
33075
|
+
if (!existsSync21(file2)) {
|
|
30997
33076
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30998
33077
|
continue;
|
|
30999
33078
|
}
|
|
31000
33079
|
if (file2.endsWith(TOML_EXT)) {
|
|
31001
|
-
const rawToml =
|
|
33080
|
+
const rawToml = readFileSync18(file2, "utf8");
|
|
31002
33081
|
const tomlLayout = hostLayout(rawToml);
|
|
31003
33082
|
let text = hostText(rawToml);
|
|
31004
33083
|
for (const f of list4) {
|
|
@@ -31026,7 +33105,7 @@ function removeV1(agent, findings, project) {
|
|
|
31026
33105
|
},
|
|
31027
33106
|
rollback() {
|
|
31028
33107
|
for (const u of undo.splice(0).reverse()) {
|
|
31029
|
-
if (!
|
|
33108
|
+
if (!existsSync21(u.trash)) continue;
|
|
31030
33109
|
rmSync7(u.target, { recursive: true, force: true });
|
|
31031
33110
|
renameWithRetry(u.trash, u.target);
|
|
31032
33111
|
}
|
|
@@ -31156,7 +33235,55 @@ function checkCall(tool, input) {
|
|
|
31156
33235
|
}
|
|
31157
33236
|
|
|
31158
33237
|
// src/entries/opencode.ts
|
|
33238
|
+
import { resolve as resolve10 } from "node:path";
|
|
31159
33239
|
var AGENT = "opencode";
|
|
33240
|
+
var slash = (p) => p.replaceAll("\\", "/");
|
|
33241
|
+
function shellRequest(commands) {
|
|
33242
|
+
const resources = [];
|
|
33243
|
+
for (const cmd of commands) {
|
|
33244
|
+
const parsed = parseShell(cmd);
|
|
33245
|
+
const raws = parsed.ok ? parsed.commands.map((c) => c.raw.trim()).filter((r) => r !== "") : [];
|
|
33246
|
+
resources.push(...raws.length > 0 ? raws : [cmd.trim()]);
|
|
33247
|
+
}
|
|
33248
|
+
return { action: OC_SHELL_ACTION, resources, save: resources };
|
|
33249
|
+
}
|
|
33250
|
+
function permissionRequests(tool, input, base) {
|
|
33251
|
+
const i = input ?? {};
|
|
33252
|
+
const str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
33253
|
+
const out = [];
|
|
33254
|
+
const read3 = (p) => {
|
|
33255
|
+
const abs = slash(resolve10(base, p));
|
|
33256
|
+
return { action: OC_READ_ACTION, resources: [abs], save: [abs] };
|
|
33257
|
+
};
|
|
33258
|
+
if (tool === "ctx_execute") {
|
|
33259
|
+
const language = str3(i.language) ?? OC_ANY_RESOURCE;
|
|
33260
|
+
out.push({ action: tool, resources: [language], save: [language] });
|
|
33261
|
+
if (isShellLanguage(language) && typeof i.code === "string") out.push(shellRequest([i.code]));
|
|
33262
|
+
const file2 = str3(i.file);
|
|
33263
|
+
if (file2 !== void 0) out.push(read3(file2));
|
|
33264
|
+
return out;
|
|
33265
|
+
}
|
|
33266
|
+
if (tool === "ctx_batch") {
|
|
33267
|
+
const commands = Array.isArray(i.commands) ? i.commands.filter((c) => typeof c === "string") : [];
|
|
33268
|
+
out.push({ action: tool, resources: commands, save: commands });
|
|
33269
|
+
if (commands.length > 0) out.push(shellRequest(commands));
|
|
33270
|
+
return out;
|
|
33271
|
+
}
|
|
33272
|
+
if (tool === "ctx_index") {
|
|
33273
|
+
const path8 = str3(i.path);
|
|
33274
|
+
const url2 = str3(i.url);
|
|
33275
|
+
const what = path8 ?? url2 ?? OC_ANY_RESOURCE;
|
|
33276
|
+
out.push({ action: tool, resources: [what], save: [what] });
|
|
33277
|
+
if (path8 !== void 0) out.push(read3(path8));
|
|
33278
|
+
if (url2 !== void 0) out.push({ action: OC_WEBFETCH_ACTION, resources: [url2], save: [OC_ANY_RESOURCE] });
|
|
33279
|
+
return out;
|
|
33280
|
+
}
|
|
33281
|
+
return [{ action: tool, resources: [OC_ANY_RESOURCE], save: [OC_ANY_RESOURCE] }];
|
|
33282
|
+
}
|
|
33283
|
+
async function legacyAsk(req, toolCtx) {
|
|
33284
|
+
const permission = req.action === OC_SHELL_ACTION ? OC_LEGACY_SHELL_ACTION : req.action;
|
|
33285
|
+
await toolCtx.ask?.({ permission, patterns: req.resources, always: req.save, metadata: {} });
|
|
33286
|
+
}
|
|
31160
33287
|
var id = PLUGIN_ID;
|
|
31161
33288
|
async function setupLegacy(app) {
|
|
31162
33289
|
const cwd = app.directory;
|
|
@@ -31196,6 +33323,17 @@ async function setupLegacy(app) {
|
|
|
31196
33323
|
signal: toolCtx.abort ?? new AbortController().signal,
|
|
31197
33324
|
protocolVersion: ""
|
|
31198
33325
|
};
|
|
33326
|
+
const permission = app.permission ?? (typeof toolCtx.ask === "function" ? "wired" : void 0);
|
|
33327
|
+
if (permission !== void 0) ctx.hostPermission = permission;
|
|
33328
|
+
if (permission === "wired") {
|
|
33329
|
+
let base = cwd ?? "";
|
|
33330
|
+
try {
|
|
33331
|
+
base = ctx.project.worktree;
|
|
33332
|
+
} catch {
|
|
33333
|
+
}
|
|
33334
|
+
const check2 = app.assert ?? legacyAsk;
|
|
33335
|
+
for (const req of permissionRequests(tool.name, checked.data, base)) await check2(req, toolCtx);
|
|
33336
|
+
}
|
|
31199
33337
|
let reply4;
|
|
31200
33338
|
try {
|
|
31201
33339
|
reply4 = await tool.handler(checked.data, ctx);
|
|
@@ -31270,8 +33408,21 @@ function oc2Text(content) {
|
|
|
31270
33408
|
}
|
|
31271
33409
|
async function setup(ctx) {
|
|
31272
33410
|
const tools = /* @__PURE__ */ new Map();
|
|
33411
|
+
const assert2 = ctx.permission?.assert;
|
|
31273
33412
|
const hooks = await setupLegacy({
|
|
31274
33413
|
directory: ctx.location.directory,
|
|
33414
|
+
// D-1331-OC-PERM-1: ctx.permission.assert is the 2.x plugin check (anomalyco/opencode#50652); "missing" feeds D10.
|
|
33415
|
+
permission: typeof assert2 === "function" ? "wired" : "missing",
|
|
33416
|
+
assert: async (req, t) => {
|
|
33417
|
+
await assert2?.({
|
|
33418
|
+
sessionID: t.sessionID ?? "",
|
|
33419
|
+
...t.agent === void 0 ? {} : { agent: t.agent },
|
|
33420
|
+
action: req.action,
|
|
33421
|
+
resources: req.resources,
|
|
33422
|
+
save: req.save,
|
|
33423
|
+
...t.messageID === void 0 || t.callID === void 0 ? {} : { source: { type: "tool", messageID: t.messageID, id: t.callID } }
|
|
33424
|
+
});
|
|
33425
|
+
},
|
|
31275
33426
|
tool(name, def) {
|
|
31276
33427
|
tools.set(name, {
|
|
31277
33428
|
name,
|
|
@@ -31280,7 +33431,8 @@ async function setup(ctx) {
|
|
|
31280
33431
|
options: { codemode: false },
|
|
31281
33432
|
// a ctx_* tool is listed to the model by name, not behind the host's code tool
|
|
31282
33433
|
async execute(input, context) {
|
|
31283
|
-
|
|
33434
|
+
const t = { sessionID: context.sessionID, abort: context.signal, agent: context.agent, messageID: context.messageID, callID: context.id };
|
|
33435
|
+
return { content: await def.execute(input, t) };
|
|
31284
33436
|
}
|
|
31285
33437
|
});
|
|
31286
33438
|
}
|
|
@@ -31327,10 +33479,11 @@ async function server(input, _options) {
|
|
|
31327
33479
|
});
|
|
31328
33480
|
return { ...hooks, tool };
|
|
31329
33481
|
}
|
|
31330
|
-
var
|
|
33482
|
+
var opencode_default2 = { id: PLUGIN_ID, server, setup };
|
|
31331
33483
|
export {
|
|
31332
|
-
|
|
33484
|
+
opencode_default2 as default,
|
|
31333
33485
|
id,
|
|
33486
|
+
permissionRequests,
|
|
31334
33487
|
server,
|
|
31335
33488
|
setup,
|
|
31336
33489
|
setupLegacy
|