context-mode 2.0.0-next.17 → 2.0.0-next.20
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/SHA256SUMS +15 -15
- package/cli.mjs +59 -43
- package/copilot/plugin.json +1 -1
- package/fixtures/hook-roundtrip.json +20 -3
- package/gemini-extension.json +1 -1
- package/hook.mjs +92 -88
- package/opencode/plugin.js +583 -111
- package/package.json +5 -1
- package/pi/index.js +583 -138
- package/qwen-extension.json +1 -1
- package/run.mjs +371 -23
- package/search.mjs +371 -23
- package/server.mjs +172 -71
package/opencode/plugin.js
CHANGED
|
@@ -277,6 +277,9 @@ var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
|
277
277
|
function D5_LAST_HOOK_ERROR(ts, stage, label) {
|
|
278
278
|
return `; last hook error ${ts} at ${stage} (${label}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
279
279
|
}
|
|
280
|
+
function D5_PAST_HOOK_ERROR(ts, stage, label) {
|
|
281
|
+
return `; past hook error ${ts} at ${stage} (${label}), before this run, stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
282
|
+
}
|
|
280
283
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
281
284
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
282
285
|
var VERSION_PROBE_FLAGS = Object.freeze(["--version", "-v"]);
|
|
@@ -359,7 +362,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
359
362
|
var DECISION_LABEL_JOIN = " | ";
|
|
360
363
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
361
364
|
var RELEASE_BRANCH = "release";
|
|
362
|
-
var BUNDLE_SHA = true ? "
|
|
365
|
+
var BUNDLE_SHA = true ? "efe519b1d2f8b002ada6ef542af2df61e2abc20f" : void 0;
|
|
363
366
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
364
367
|
var DOCTOR_LABEL = Object.freeze({
|
|
365
368
|
D1: "version",
|
|
@@ -547,7 +550,7 @@ var REGEX_ESCAPE = "\\";
|
|
|
547
550
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
548
551
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
549
552
|
function D5_SLOW_DETAIL(ms) {
|
|
550
|
-
return `hook round trip took ${ms} ms, over ${HOOK_P95_MS} ms`;
|
|
553
|
+
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
551
554
|
}
|
|
552
555
|
var D5_FIX = "run ctx_upgrade";
|
|
553
556
|
var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
@@ -1067,7 +1070,8 @@ var RESULT_SUCCESS = "success";
|
|
|
1067
1070
|
function isRecord(v) {
|
|
1068
1071
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1069
1072
|
}
|
|
1070
|
-
var
|
|
1073
|
+
var SHELL_TOOL_NAMES = Object.freeze(["bash", "powershell"]);
|
|
1074
|
+
var NATIVE_TO_CANONICAL3 = Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"]));
|
|
1071
1075
|
function canonicalName3(name) {
|
|
1072
1076
|
if (name.startsWith(TOOL_NAME_PREFIX5)) return name.slice(TOOL_NAME_PREFIX5.length);
|
|
1073
1077
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
@@ -1148,11 +1152,11 @@ var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostTool
|
|
|
1148
1152
|
var MCP_PREFIX2 = "mcp_";
|
|
1149
1153
|
var MCP_SEP2 = "_";
|
|
1150
1154
|
var SESSION_START_NEW = "new";
|
|
1151
|
-
var
|
|
1155
|
+
var SHELL_TOOL_NAMES2 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
|
|
1152
1156
|
var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
|
|
1153
1157
|
var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
|
|
1154
1158
|
var NATIVE_TO_CANONICAL4 = Object.fromEntries([
|
|
1155
|
-
...
|
|
1159
|
+
...SHELL_TOOL_NAMES2.map((n) => [n, "Bash"]),
|
|
1156
1160
|
...READ_TOOL_NAMES.map((n) => [n, "Read"]),
|
|
1157
1161
|
...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
|
|
1158
1162
|
]);
|
|
@@ -1280,8 +1284,8 @@ var KIRO_EVENTS = {
|
|
|
1280
1284
|
};
|
|
1281
1285
|
var PROMPT_ENV = "USER_PROMPT";
|
|
1282
1286
|
var MCP_PREFIX3 = "mcp_";
|
|
1283
|
-
var
|
|
1284
|
-
var NATIVE_TO_CANONICAL5 = Object.fromEntries(
|
|
1287
|
+
var SHELL_TOOL_NAMES3 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
1288
|
+
var NATIVE_TO_CANONICAL5 = Object.fromEntries(SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]));
|
|
1285
1289
|
var MCP_SEP3 = "_";
|
|
1286
1290
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1287
1291
|
function canonicalName5(name) {
|
|
@@ -1423,7 +1427,8 @@ var OPENCODE_EVENTS = {
|
|
|
1423
1427
|
"step-finish": "Usage"
|
|
1424
1428
|
};
|
|
1425
1429
|
var SHELL_TOOL_NAME = "bash";
|
|
1426
|
-
var
|
|
1430
|
+
var SHELL_TOOL_NAMES4 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1431
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES4.map((n) => [n, "Bash"])) };
|
|
1427
1432
|
function toCanonicalTool(name) {
|
|
1428
1433
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1429
1434
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -1553,8 +1558,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1553
1558
|
installMode: "plugin",
|
|
1554
1559
|
projectSource: "arg:--agent+cwd",
|
|
1555
1560
|
toolNamePrefix: TOOL_NAME_PREFIX5,
|
|
1556
|
-
nativeTools: { shell: [
|
|
1561
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES] },
|
|
1557
1562
|
execReadOnlyHint: false,
|
|
1563
|
+
// D-PWSH-DUMP-1
|
|
1558
1564
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
1559
1565
|
compactDelivery: "pending-flag",
|
|
1560
1566
|
compactSummary: "none",
|
|
@@ -1572,7 +1578,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1572
1578
|
projectSource: "arg:workspaceFolder",
|
|
1573
1579
|
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
1574
1580
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
1575
|
-
nativeTools: { shell: [...
|
|
1581
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES2], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
1576
1582
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
1577
1583
|
execReadOnlyHint: false,
|
|
1578
1584
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -1591,7 +1597,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1591
1597
|
installMode: "mcp-entry",
|
|
1592
1598
|
projectSource: "arg:--agent+cwd",
|
|
1593
1599
|
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
1594
|
-
nativeTools: { shell: [...
|
|
1600
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
|
|
1595
1601
|
execReadOnlyHint: false,
|
|
1596
1602
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
1597
1603
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -1683,7 +1689,7 @@ function getAdapter(id2) {
|
|
|
1683
1689
|
}
|
|
1684
1690
|
|
|
1685
1691
|
// src/core/policy/decide.ts
|
|
1686
|
-
import { resolve } from "node:path";
|
|
1692
|
+
import { resolve as resolve2 } from "node:path";
|
|
1687
1693
|
|
|
1688
1694
|
// src/core/policy/lexer.ts
|
|
1689
1695
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -2624,6 +2630,343 @@ function parseShell(cmd) {
|
|
|
2624
2630
|
return { ok: true, commands };
|
|
2625
2631
|
}
|
|
2626
2632
|
|
|
2633
|
+
// src/core/policy/powershell.ts
|
|
2634
|
+
import { resolve } from "node:path";
|
|
2635
|
+
var SQ = "'";
|
|
2636
|
+
var DQ = '"';
|
|
2637
|
+
var TICK = "`";
|
|
2638
|
+
var SPACES = " \r";
|
|
2639
|
+
var OPENERS = "([{";
|
|
2640
|
+
var CLOSERS = ")]}";
|
|
2641
|
+
var GLUE_END = " \r\n|;>";
|
|
2642
|
+
var FD_STAR = "*";
|
|
2643
|
+
var STDOUT_FD = "1";
|
|
2644
|
+
var METHOD_MARK = "::";
|
|
2645
|
+
var PAIR = METHOD_MARK.length;
|
|
2646
|
+
var MIN_STATIC_CALL = PAIR;
|
|
2647
|
+
function quoteEnd(text, at2) {
|
|
2648
|
+
const q = text.charAt(at2);
|
|
2649
|
+
for (let j = at2 + 1; j < text.length; j++) {
|
|
2650
|
+
const c = text.charAt(j);
|
|
2651
|
+
if (q === DQ && c === TICK) {
|
|
2652
|
+
j++;
|
|
2653
|
+
continue;
|
|
2654
|
+
}
|
|
2655
|
+
if (c !== q) continue;
|
|
2656
|
+
if (text.charAt(j + 1) === q) {
|
|
2657
|
+
j++;
|
|
2658
|
+
continue;
|
|
2659
|
+
}
|
|
2660
|
+
return j;
|
|
2661
|
+
}
|
|
2662
|
+
return -1;
|
|
2663
|
+
}
|
|
2664
|
+
function unquote(body, q) {
|
|
2665
|
+
let out = "";
|
|
2666
|
+
for (let j = 0; j < body.length; j++) {
|
|
2667
|
+
const c = body.charAt(j);
|
|
2668
|
+
if (q === DQ && c === TICK && j + 1 < body.length) {
|
|
2669
|
+
out += body.charAt(++j);
|
|
2670
|
+
continue;
|
|
2671
|
+
}
|
|
2672
|
+
if (c === q && body.charAt(j + 1) === q) j++;
|
|
2673
|
+
out += c;
|
|
2674
|
+
}
|
|
2675
|
+
return out;
|
|
2676
|
+
}
|
|
2677
|
+
function closeOf(text, at2) {
|
|
2678
|
+
let depth = 0;
|
|
2679
|
+
for (let j = at2; j < text.length; j++) {
|
|
2680
|
+
const c = text.charAt(j);
|
|
2681
|
+
if (c === SQ || c === DQ) {
|
|
2682
|
+
const e = quoteEnd(text, j);
|
|
2683
|
+
if (e < 0) return -1;
|
|
2684
|
+
j = e;
|
|
2685
|
+
continue;
|
|
2686
|
+
}
|
|
2687
|
+
if (c === TICK) {
|
|
2688
|
+
j++;
|
|
2689
|
+
continue;
|
|
2690
|
+
}
|
|
2691
|
+
if (OPENERS.includes(c)) depth++;
|
|
2692
|
+
else if (CLOSERS.includes(c) && --depth === 0) return j;
|
|
2693
|
+
}
|
|
2694
|
+
return -1;
|
|
2695
|
+
}
|
|
2696
|
+
function glueEnd(text, from) {
|
|
2697
|
+
let depth = 0;
|
|
2698
|
+
for (let j = from; j < text.length; j++) {
|
|
2699
|
+
const c = text.charAt(j);
|
|
2700
|
+
if (c === SQ || c === DQ) {
|
|
2701
|
+
const e = quoteEnd(text, j);
|
|
2702
|
+
if (e < 0) return text.length;
|
|
2703
|
+
j = e;
|
|
2704
|
+
continue;
|
|
2705
|
+
}
|
|
2706
|
+
if (OPENERS.includes(c)) depth++;
|
|
2707
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
2708
|
+
else if (depth <= 0 && GLUE_END.includes(c)) return j;
|
|
2709
|
+
}
|
|
2710
|
+
return text.length;
|
|
2711
|
+
}
|
|
2712
|
+
function splitArgs(inner) {
|
|
2713
|
+
const parts = [];
|
|
2714
|
+
let depth = 0;
|
|
2715
|
+
let from = 0;
|
|
2716
|
+
for (let j = 0; j < inner.length; j++) {
|
|
2717
|
+
const c = inner.charAt(j);
|
|
2718
|
+
if (c === SQ || c === DQ) {
|
|
2719
|
+
const e = quoteEnd(inner, j);
|
|
2720
|
+
if (e < 0) break;
|
|
2721
|
+
j = e;
|
|
2722
|
+
continue;
|
|
2723
|
+
}
|
|
2724
|
+
if (OPENERS.includes(c)) depth++;
|
|
2725
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
2726
|
+
else if (c === "," && depth === 0) {
|
|
2727
|
+
parts.push(inner.slice(from, j));
|
|
2728
|
+
from = j + 1;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
parts.push(inner.slice(from));
|
|
2732
|
+
return parts;
|
|
2733
|
+
}
|
|
2734
|
+
var isFd = (w) => w !== "" && (w === FD_STAR || [...w].every((ch) => ch >= "0" && ch <= "9"));
|
|
2735
|
+
var fresh = () => ({ words: [], toFile: false, chained: false });
|
|
2736
|
+
function psParse(text) {
|
|
2737
|
+
const statements = [];
|
|
2738
|
+
let stages = [];
|
|
2739
|
+
let stage = fresh();
|
|
2740
|
+
let word = "";
|
|
2741
|
+
let has3 = false;
|
|
2742
|
+
let bare2 = true;
|
|
2743
|
+
let target = null;
|
|
2744
|
+
const n = text.length;
|
|
2745
|
+
const endWord = () => {
|
|
2746
|
+
if (!has3) return;
|
|
2747
|
+
if (target !== null) {
|
|
2748
|
+
if (target === "file") stage.toFile = true;
|
|
2749
|
+
target = null;
|
|
2750
|
+
} else stage.words.push(word);
|
|
2751
|
+
word = "";
|
|
2752
|
+
has3 = false;
|
|
2753
|
+
bare2 = true;
|
|
2754
|
+
};
|
|
2755
|
+
const endStage = () => {
|
|
2756
|
+
endWord();
|
|
2757
|
+
if (stage.words.length > 0 || stage.toFile) stages.push(stage);
|
|
2758
|
+
stage = fresh();
|
|
2759
|
+
};
|
|
2760
|
+
const endStatement = () => {
|
|
2761
|
+
endStage();
|
|
2762
|
+
if (stages.length > 0) statements.push(stages);
|
|
2763
|
+
stages = [];
|
|
2764
|
+
};
|
|
2765
|
+
const grow = (s, quoted) => {
|
|
2766
|
+
word += s;
|
|
2767
|
+
has3 = true;
|
|
2768
|
+
if (quoted) bare2 = false;
|
|
2769
|
+
};
|
|
2770
|
+
let i = 0;
|
|
2771
|
+
while (i < n) {
|
|
2772
|
+
const c = text.charAt(i);
|
|
2773
|
+
const next = text.charAt(i + 1);
|
|
2774
|
+
if (c === SQ || c === DQ) {
|
|
2775
|
+
const e = quoteEnd(text, i);
|
|
2776
|
+
grow(unquote(text.slice(i + 1, e < 0 ? n : e), c), true);
|
|
2777
|
+
i = e < 0 ? n : e + 1;
|
|
2778
|
+
} else if (c === TICK) {
|
|
2779
|
+
if (next !== "\n" && next !== "") grow(next, false);
|
|
2780
|
+
i += PAIR;
|
|
2781
|
+
} else if (c === "\n") {
|
|
2782
|
+
endStatement();
|
|
2783
|
+
i++;
|
|
2784
|
+
} else if (SPACES.includes(c)) {
|
|
2785
|
+
endWord();
|
|
2786
|
+
i++;
|
|
2787
|
+
} else if (c === ";") {
|
|
2788
|
+
endStatement();
|
|
2789
|
+
i++;
|
|
2790
|
+
} else if (c === "|") {
|
|
2791
|
+
if (next === "|") {
|
|
2792
|
+
endStatement();
|
|
2793
|
+
i += PAIR;
|
|
2794
|
+
} else {
|
|
2795
|
+
endStage();
|
|
2796
|
+
i++;
|
|
2797
|
+
}
|
|
2798
|
+
} else if (c === "&") {
|
|
2799
|
+
if (next === "&") {
|
|
2800
|
+
endStatement();
|
|
2801
|
+
i += PAIR;
|
|
2802
|
+
} else {
|
|
2803
|
+
if (has3 || stage.words.length > 0) grow(c, false);
|
|
2804
|
+
i++;
|
|
2805
|
+
}
|
|
2806
|
+
} else if (c === "#" && !has3) {
|
|
2807
|
+
while (i < n && text.charAt(i) !== "\n") i++;
|
|
2808
|
+
} else if (c === ">") {
|
|
2809
|
+
let fd = STDOUT_FD;
|
|
2810
|
+
if (has3 && bare2 && isFd(word)) {
|
|
2811
|
+
fd = word;
|
|
2812
|
+
word = "";
|
|
2813
|
+
has3 = false;
|
|
2814
|
+
} else if (has3) endWord();
|
|
2815
|
+
let j = i + 1;
|
|
2816
|
+
if (text.charAt(j) === ">") j++;
|
|
2817
|
+
if (text.charAt(j) === "&") {
|
|
2818
|
+
j++;
|
|
2819
|
+
while (j < n && !GLUE_END.includes(text.charAt(j))) j++;
|
|
2820
|
+
} else target = fd === STDOUT_FD || fd === FD_STAR ? "file" : "skip";
|
|
2821
|
+
i = j;
|
|
2822
|
+
} else if (c === "(" && has3 && bare2 && word.includes(METHOD_MARK)) {
|
|
2823
|
+
const e = closeOf(text, i);
|
|
2824
|
+
const inner = text.slice(i + 1, e < 0 ? n : e);
|
|
2825
|
+
endWord();
|
|
2826
|
+
for (const a of inner.trim() === "" ? [] : splitArgs(inner)) {
|
|
2827
|
+
const first = psParse(a)[0]?.[0]?.words[0];
|
|
2828
|
+
stage.words.push(first ?? a.trim());
|
|
2829
|
+
}
|
|
2830
|
+
i = e < 0 ? n : e + 1;
|
|
2831
|
+
if (i < n && !GLUE_END.includes(text.charAt(i))) {
|
|
2832
|
+
stage.chained = true;
|
|
2833
|
+
i = glueEnd(text, i);
|
|
2834
|
+
}
|
|
2835
|
+
} else if (c === "[" && !has3 && text.startsWith(METHOD_MARK, closeOf(text, i) + 1) && closeOf(text, i) >= 0) {
|
|
2836
|
+
const e = closeOf(text, i);
|
|
2837
|
+
grow(text.slice(i, e + 1), false);
|
|
2838
|
+
i = e + 1;
|
|
2839
|
+
} else if (OPENERS.includes(c) && (c !== "[" || !has3) || (c === "$" || c === "@") && OPENERS.includes(next) && next !== "[") {
|
|
2840
|
+
const open = c === "$" || c === "@" ? i + 1 : i;
|
|
2841
|
+
const e = closeOf(text, open);
|
|
2842
|
+
grow(text.slice(i, e < 0 ? n : e + 1), true);
|
|
2843
|
+
i = e < 0 ? n : e + 1;
|
|
2844
|
+
} else {
|
|
2845
|
+
grow(c, false);
|
|
2846
|
+
i++;
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
endStatement();
|
|
2850
|
+
return statements;
|
|
2851
|
+
}
|
|
2852
|
+
var READ_COMMANDS = ["get-content", "gc", "cat", "type"];
|
|
2853
|
+
var FILE_CLASSES = ["[io.file]::", "[system.io.file]::"];
|
|
2854
|
+
var FILE_READS = ["readalltext", "readalllines", "readallbytes", "readlines"];
|
|
2855
|
+
var PATH_PARAMS = ["path", "literalpath"];
|
|
2856
|
+
var BOUND_PARAMS = ["totalcount", "head", "first", "tail", "last"];
|
|
2857
|
+
var VALUE_PARAMS = [...PATH_PARAMS, ...BOUND_PARAMS, "encoding", "readcount", "delimiter", "filter", "include", "exclude", "stream", "credential"];
|
|
2858
|
+
var SWITCH_PARAMS = ["raw", "wait", "force", "asbytestream"];
|
|
2859
|
+
var ALL_PARAMS = [...VALUE_PARAMS, ...SWITCH_PARAMS];
|
|
2860
|
+
var PASS_THROUGH = ["out-string", "write-output", "echo", "write", "out-host", "write-host", "out-default", "tee-object"];
|
|
2861
|
+
var CD_COMMANDS = ["cd", "chdir", "sl", "set-location", "pushd", "push-location"];
|
|
2862
|
+
var POWERSHELLS = ["powershell", "powershell.exe", "pwsh", "pwsh.exe"];
|
|
2863
|
+
var CMDS = ["cmd", "cmd.exe"];
|
|
2864
|
+
var CMD_RUN_FLAGS = ["/c", "/k", "/r"];
|
|
2865
|
+
var COMMAND_PARAM = "command";
|
|
2866
|
+
var DASH = "-";
|
|
2867
|
+
function cmdName(word) {
|
|
2868
|
+
const k = Math.max(word.lastIndexOf("\\"), word.lastIndexOf("/"));
|
|
2869
|
+
return (k >= 0 && k < word.length - 1 ? word.slice(k + 1) : word).toLowerCase();
|
|
2870
|
+
}
|
|
2871
|
+
function param(word, names) {
|
|
2872
|
+
const body = word.slice(DASH.length);
|
|
2873
|
+
const colon = body.indexOf(":");
|
|
2874
|
+
const name = (colon < 0 ? body : body.slice(0, colon)).toLowerCase();
|
|
2875
|
+
const inline = colon < 0 ? void 0 : body.slice(colon + 1);
|
|
2876
|
+
if (name === "") return { full: void 0, inline };
|
|
2877
|
+
if (names.includes(name)) return { full: name, inline };
|
|
2878
|
+
const hits = names.filter((p) => p.startsWith(name));
|
|
2879
|
+
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
2880
|
+
}
|
|
2881
|
+
function psDump(words) {
|
|
2882
|
+
if (words.length === 0) return null;
|
|
2883
|
+
const name = cmdName(words[0]);
|
|
2884
|
+
if (!READ_COMMANDS.includes(name)) {
|
|
2885
|
+
const lower = words[0].toLowerCase();
|
|
2886
|
+
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
2887
|
+
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words.length < MIN_STATIC_CALL) return null;
|
|
2888
|
+
return { file: words[1], bounded: false };
|
|
2889
|
+
}
|
|
2890
|
+
const files = [];
|
|
2891
|
+
let bounded = false;
|
|
2892
|
+
for (let k = 1; k < words.length; k++) {
|
|
2893
|
+
const a = words[k];
|
|
2894
|
+
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
2895
|
+
files.push(a);
|
|
2896
|
+
continue;
|
|
2897
|
+
}
|
|
2898
|
+
const p = param(a, ALL_PARAMS);
|
|
2899
|
+
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
2900
|
+
const value = p.inline ?? words[++k];
|
|
2901
|
+
if (value === void 0) return null;
|
|
2902
|
+
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
2903
|
+
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
2904
|
+
}
|
|
2905
|
+
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
2906
|
+
}
|
|
2907
|
+
function nestedScript(name, words) {
|
|
2908
|
+
if (POWERSHELLS.includes(name)) {
|
|
2909
|
+
for (let k = 1; k < words.length; k++) {
|
|
2910
|
+
const w = words[k];
|
|
2911
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
2912
|
+
const p = param(w, [COMMAND_PARAM]);
|
|
2913
|
+
if (p.full === void 0) continue;
|
|
2914
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words.slice(k + 1)].join(" ");
|
|
2915
|
+
}
|
|
2916
|
+
return null;
|
|
2917
|
+
}
|
|
2918
|
+
if (CMDS.includes(name)) {
|
|
2919
|
+
for (let k = 1; k < words.length; k++) {
|
|
2920
|
+
if (CMD_RUN_FLAGS.includes(words[k].toLowerCase())) return words.slice(k + 1).join(" ");
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
return null;
|
|
2924
|
+
}
|
|
2925
|
+
function cdTarget(words) {
|
|
2926
|
+
for (let k = 1; k < words.length; k++) {
|
|
2927
|
+
const w = words[k];
|
|
2928
|
+
if (w.toLowerCase() === "/d") continue;
|
|
2929
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
2930
|
+
const p = param(w, PATH_PARAMS);
|
|
2931
|
+
if (p.full !== void 0) return p.inline ?? words[k + 1] ?? null;
|
|
2932
|
+
}
|
|
2933
|
+
return null;
|
|
2934
|
+
}
|
|
2935
|
+
function walk(script, cwd, depth, found) {
|
|
2936
|
+
let dir = cwd;
|
|
2937
|
+
for (const stages of psParse(script)) {
|
|
2938
|
+
const head = stages[0];
|
|
2939
|
+
if (head.words.length === 0) continue;
|
|
2940
|
+
const name = cmdName(head.words[0]);
|
|
2941
|
+
if (stages.length === 1 && CD_COMMANDS.includes(name)) {
|
|
2942
|
+
const t = cdTarget(head.words);
|
|
2943
|
+
if (t !== null) dir = resolve(dir, t);
|
|
2944
|
+
continue;
|
|
2945
|
+
}
|
|
2946
|
+
const inner = depth < MAX_NEST_DEPTH ? nestedScript(name, head.words) : null;
|
|
2947
|
+
if (inner !== null) {
|
|
2948
|
+
walk(inner, dir, depth + 1, found);
|
|
2949
|
+
continue;
|
|
2950
|
+
}
|
|
2951
|
+
if (head.toFile || head.chained) continue;
|
|
2952
|
+
const d = psDump(head.words);
|
|
2953
|
+
if (d === null || d.bounded) continue;
|
|
2954
|
+
let shown2 = true;
|
|
2955
|
+
for (let k = 1; k < stages.length; k++) {
|
|
2956
|
+
if (stages[k].toFile || !PASS_THROUGH.includes(cmdName(stages[k].words[0] ?? ""))) {
|
|
2957
|
+
shown2 = false;
|
|
2958
|
+
break;
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
if (shown2) found.push(resolve(dir, d.file));
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
function psDumpFiles(script, cwd) {
|
|
2965
|
+
const found = [];
|
|
2966
|
+
walk(script, cwd, 0, found);
|
|
2967
|
+
return found;
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2627
2970
|
// src/core/policy/subagent.ts
|
|
2628
2971
|
import { join as join2 } from "node:path";
|
|
2629
2972
|
|
|
@@ -2835,16 +3178,16 @@ function readList(body, key) {
|
|
|
2835
3178
|
for (let j = i + 1; j < body.length; j++) {
|
|
2836
3179
|
const t = body[j].trim();
|
|
2837
3180
|
if (!t.startsWith("-")) break;
|
|
2838
|
-
items.push(
|
|
3181
|
+
items.push(unquote2(t.slice(1).trim()));
|
|
2839
3182
|
}
|
|
2840
3183
|
return items.filter((s) => s !== "");
|
|
2841
3184
|
}
|
|
2842
3185
|
if (value.startsWith("[") && value.endsWith("]")) value = value.slice(1, -1);
|
|
2843
|
-
return value.split(",").map((s) =>
|
|
3186
|
+
return value.split(",").map((s) => unquote2(s.trim())).filter((s) => s !== "");
|
|
2844
3187
|
}
|
|
2845
3188
|
return null;
|
|
2846
3189
|
}
|
|
2847
|
-
function
|
|
3190
|
+
function unquote2(s) {
|
|
2848
3191
|
if (s.length > 1 && (s[0] === '"' || s[0] === "'") && s.endsWith(s[0])) return s.slice(1, -1);
|
|
2849
3192
|
return s;
|
|
2850
3193
|
}
|
|
@@ -3246,7 +3589,7 @@ function readPath(input) {
|
|
|
3246
3589
|
}
|
|
3247
3590
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
3248
3591
|
if (rules.length === 0) return null;
|
|
3249
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
3592
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve2(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
3250
3593
|
if (canonical === BASH) {
|
|
3251
3594
|
const cmd = str(input.command);
|
|
3252
3595
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -3298,7 +3641,7 @@ function webFetch(input, row5) {
|
|
|
3298
3641
|
function bash(ev, row5, input, rules) {
|
|
3299
3642
|
const cmd = str(input.command) ?? "";
|
|
3300
3643
|
const parsed = parseShell(cmd);
|
|
3301
|
-
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : ALLOW;
|
|
3644
|
+
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
|
|
3302
3645
|
const cmds = unwrap(parsed.commands);
|
|
3303
3646
|
for (const c of cmds) {
|
|
3304
3647
|
const h = segmentHit(c, rules);
|
|
@@ -3310,7 +3653,7 @@ function bash(ev, row5, input, rules) {
|
|
|
3310
3653
|
if (kind !== null) return deny(denyMessage(kind, cmd, row5, str(input.description)));
|
|
3311
3654
|
}
|
|
3312
3655
|
}
|
|
3313
|
-
return shellDump(cmds, ev.cwd, row5) ?? ALLOW;
|
|
3656
|
+
return shellDump(cmds, ev.cwd, row5) ?? psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
|
|
3314
3657
|
}
|
|
3315
3658
|
function denyKind(c) {
|
|
3316
3659
|
const name = c.argv0.toLowerCase();
|
|
@@ -3357,7 +3700,7 @@ function read(ev, row5, input) {
|
|
|
3357
3700
|
if (!present(input.offset) && !present(input.limit)) {
|
|
3358
3701
|
const p = readPath(input);
|
|
3359
3702
|
if (p !== void 0) {
|
|
3360
|
-
const abs =
|
|
3703
|
+
const abs = resolve2(ev.cwd, p);
|
|
3361
3704
|
const size = fileSize(abs);
|
|
3362
3705
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3363
3706
|
}
|
|
@@ -3370,7 +3713,7 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3370
3713
|
let verdict = null;
|
|
3371
3714
|
for (const c of cmds) {
|
|
3372
3715
|
const name = c.argv0.toLowerCase();
|
|
3373
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
3716
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve2(dir, c.args[0]);
|
|
3374
3717
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
3375
3718
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
3376
3719
|
const d = dumpTarget(name, c.args);
|
|
@@ -3379,12 +3722,20 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3379
3722
|
verdict = ALLOW;
|
|
3380
3723
|
continue;
|
|
3381
3724
|
}
|
|
3382
|
-
const abs =
|
|
3725
|
+
const abs = resolve2(dir, d.file);
|
|
3383
3726
|
const size = fileSize(abs);
|
|
3384
3727
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3385
3728
|
}
|
|
3386
3729
|
return verdict;
|
|
3387
3730
|
}
|
|
3731
|
+
function psShellDump(cmd, cwd, row5) {
|
|
3732
|
+
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
3733
|
+
for (const abs of psDumpFiles(cmd, cwd)) {
|
|
3734
|
+
const size = fileSize(abs);
|
|
3735
|
+
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3736
|
+
}
|
|
3737
|
+
return null;
|
|
3738
|
+
}
|
|
3388
3739
|
var allDigits2 = (s) => s !== "" && [...s].every((ch) => ch >= "0" && ch <= "9");
|
|
3389
3740
|
function countFlag(a) {
|
|
3390
3741
|
if (has(DUMP_COUNT_FLAGS, a)) return 1;
|
|
@@ -3442,7 +3793,7 @@ function dumpTarget(name, args) {
|
|
|
3442
3793
|
}
|
|
3443
3794
|
|
|
3444
3795
|
// src/core/project/resolve.ts
|
|
3445
|
-
import { basename, dirname as dirname2, join as join4, resolve as
|
|
3796
|
+
import { basename, dirname as dirname2, join as join4, resolve as resolve3 } from "node:path";
|
|
3446
3797
|
|
|
3447
3798
|
// src/core/project/contain.ts
|
|
3448
3799
|
import { dirname, sep as sep2 } from "node:path";
|
|
@@ -3649,7 +4000,7 @@ function gitDirs(dir) {
|
|
|
3649
4000
|
const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
|
|
3650
4001
|
if (gitDir !== null) {
|
|
3651
4002
|
const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
|
|
3652
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
4003
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve3(gitDir, common)), worktree: cur, start };
|
|
3653
4004
|
}
|
|
3654
4005
|
const up = dirname2(cur);
|
|
3655
4006
|
if (up === cur) return { commonDir: null, start };
|
|
@@ -3664,7 +4015,7 @@ function gitDirAt(dotGit) {
|
|
|
3664
4015
|
} else {
|
|
3665
4016
|
const line = firstLine(dotGit);
|
|
3666
4017
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
3667
|
-
gitDir =
|
|
4018
|
+
gitDir = resolve3(dirname2(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
3668
4019
|
}
|
|
3669
4020
|
} catch {
|
|
3670
4021
|
return null;
|
|
@@ -7605,7 +7956,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
7605
7956
|
}
|
|
7606
7957
|
|
|
7607
7958
|
// src/core/hooks/fallback.ts
|
|
7608
|
-
import { join as join5, resolve as
|
|
7959
|
+
import { join as join5, resolve as resolve4 } from "node:path";
|
|
7609
7960
|
var fs = process.getBuiltinModule("node:fs");
|
|
7610
7961
|
function isRec(v) {
|
|
7611
7962
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -7720,7 +8071,7 @@ function bigRead(input, cwd) {
|
|
|
7720
8071
|
const p = firstString(input, READ_PATH_KEYS);
|
|
7721
8072
|
if (p === "") return false;
|
|
7722
8073
|
try {
|
|
7723
|
-
const st = fs.statSync(
|
|
8074
|
+
const st = fs.statSync(resolve4(cwd, p));
|
|
7724
8075
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
7725
8076
|
} catch {
|
|
7726
8077
|
return false;
|
|
@@ -19472,10 +19823,10 @@ function startArgv(argv) {
|
|
|
19472
19823
|
return sh === null ? null : [sh, ...argv];
|
|
19473
19824
|
}
|
|
19474
19825
|
function runProcess(argv, o) {
|
|
19475
|
-
return new Promise((
|
|
19826
|
+
return new Promise((resolve7) => {
|
|
19476
19827
|
const isWin2 = process.platform === "win32";
|
|
19477
19828
|
const start = startArgv(argv);
|
|
19478
|
-
if (start === null) return
|
|
19829
|
+
if (start === null) return resolve7(NOT_STARTED);
|
|
19479
19830
|
let child;
|
|
19480
19831
|
try {
|
|
19481
19832
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -19489,7 +19840,7 @@ function runProcess(argv, o) {
|
|
|
19489
19840
|
windowsHide: true
|
|
19490
19841
|
});
|
|
19491
19842
|
} catch {
|
|
19492
|
-
return
|
|
19843
|
+
return resolve7(NOT_STARTED);
|
|
19493
19844
|
}
|
|
19494
19845
|
const stdoutChunks = [];
|
|
19495
19846
|
const stderrChunks = [];
|
|
@@ -19514,7 +19865,7 @@ function runProcess(argv, o) {
|
|
|
19514
19865
|
settled = true;
|
|
19515
19866
|
clearTimeout(timer);
|
|
19516
19867
|
o.signal.removeEventListener("abort", onAbort);
|
|
19517
|
-
|
|
19868
|
+
resolve7({
|
|
19518
19869
|
stdout: Buffer.concat(stdoutChunks),
|
|
19519
19870
|
stderr: Buffer.concat(stderrChunks),
|
|
19520
19871
|
exitCode,
|
|
@@ -19981,10 +20332,11 @@ var ctxBatch = Object.freeze({
|
|
|
19981
20332
|
});
|
|
19982
20333
|
|
|
19983
20334
|
// src/core/tools/doctor.ts
|
|
19984
|
-
import { readdirSync as
|
|
20335
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync11 } from "node:fs";
|
|
19985
20336
|
import { basename as basename3, dirname as dirname6, join as join13 } from "node:path";
|
|
19986
20337
|
|
|
19987
20338
|
// src/core/ops/doctor-config.ts
|
|
20339
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
19988
20340
|
import { join as join11 } from "node:path";
|
|
19989
20341
|
|
|
19990
20342
|
// src/core/ops/detect-v1.ts
|
|
@@ -22475,7 +22827,7 @@ function ownMcpValue(agent, node, server2) {
|
|
|
22475
22827
|
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server2, AGENT_ARG, agent, ...tail] };
|
|
22476
22828
|
}
|
|
22477
22829
|
function opencodePluginFile() {
|
|
22478
|
-
return
|
|
22830
|
+
return dirname4(process.argv[1] ?? "");
|
|
22479
22831
|
}
|
|
22480
22832
|
function listTarget(key, own2, v1, alt = []) {
|
|
22481
22833
|
return {
|
|
@@ -23019,7 +23371,47 @@ function mcpFile(row5, home, env) {
|
|
|
23019
23371
|
}
|
|
23020
23372
|
return null;
|
|
23021
23373
|
}
|
|
23374
|
+
var CODEX_PLUGIN_KEY = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
23375
|
+
var CODEX_PLUGIN_SUBDIR = ".codex-plugin";
|
|
23376
|
+
var CODEX_PLUGIN_MCP_FILE = "mcp.json";
|
|
23377
|
+
var CODEX_PLUGIN_HOOKS_FILE = "hooks.json";
|
|
23378
|
+
var MCP_SERVERS_FIELD = "mcpServers";
|
|
23379
|
+
function codexNativeDir(env, home) {
|
|
23380
|
+
const codexDir = codexDirOf(env, home);
|
|
23381
|
+
let enabled;
|
|
23382
|
+
try {
|
|
23383
|
+
enabled = hostConfigValueAt(readParsed("codex", join11(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
23384
|
+
} catch {
|
|
23385
|
+
return null;
|
|
23386
|
+
}
|
|
23387
|
+
if (enabled !== true) return null;
|
|
23388
|
+
const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
23389
|
+
if (!existsSync6(cache)) return null;
|
|
23390
|
+
const found = [];
|
|
23391
|
+
for (const market of readdirSync3(cache)) {
|
|
23392
|
+
const plugin = join11(cache, market, SERVER_KEY);
|
|
23393
|
+
if (!existsSync6(plugin)) continue;
|
|
23394
|
+
for (const version2 of readdirSync3(plugin).sort()) {
|
|
23395
|
+
const dir = join11(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
23396
|
+
if (existsSync6(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
23397
|
+
}
|
|
23398
|
+
}
|
|
23399
|
+
return found.length === 0 ? null : found[found.length - 1];
|
|
23400
|
+
}
|
|
23401
|
+
function nativeMcpWrong(dir, row5) {
|
|
23402
|
+
try {
|
|
23403
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join11(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
23404
|
+
if (!isObject4(entry)) return true;
|
|
23405
|
+
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
23406
|
+
const script = args[0];
|
|
23407
|
+
return entry.command !== HOST_NODE_COMMAND || typeof script !== "string" || !script.endsWith(SERVER_ENTRY_FILE) || args[1] !== AGENT_ARG || args[2] !== row5.id || args.length !== 3;
|
|
23408
|
+
} catch {
|
|
23409
|
+
return true;
|
|
23410
|
+
}
|
|
23411
|
+
}
|
|
23022
23412
|
function mcpWrong(row5, home, env) {
|
|
23413
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23414
|
+
if (native !== null) return nativeMcpWrong(native, row5);
|
|
23023
23415
|
const file2 = mcpFile(row5, home, env);
|
|
23024
23416
|
try {
|
|
23025
23417
|
if (file2 === null) {
|
|
@@ -23038,7 +23430,8 @@ function hookParts(row5, home, env, worktree) {
|
|
|
23038
23430
|
let block;
|
|
23039
23431
|
try {
|
|
23040
23432
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
|
|
23041
|
-
const
|
|
23433
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23434
|
+
const file2 = native !== null ? join11(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join11(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join11(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join11(kiroDirOf(env, home), ...spec.file.slice(1)) : join11(root, ...spec.file);
|
|
23042
23435
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
23043
23436
|
if (row5.id === "codex") {
|
|
23044
23437
|
const config2 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -23101,7 +23494,7 @@ function checkDoubleFire(agent, worktree) {
|
|
|
23101
23494
|
}
|
|
23102
23495
|
|
|
23103
23496
|
// src/core/ops/doctor-db.ts
|
|
23104
|
-
import { existsSync as
|
|
23497
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
23105
23498
|
var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
23106
23499
|
var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
23107
23500
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -23141,7 +23534,7 @@ function failsOnCorrupt(step) {
|
|
|
23141
23534
|
}
|
|
23142
23535
|
async function checkDb(project) {
|
|
23143
23536
|
const clean = { schemaStale: false, integrityFailed: false };
|
|
23144
|
-
if (!
|
|
23537
|
+
if (!existsSync7(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
23145
23538
|
const sqlite = await loadSqlite2();
|
|
23146
23539
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
23147
23540
|
let raw = null;
|
|
@@ -23167,7 +23560,7 @@ async function checkDb(project) {
|
|
|
23167
23560
|
}
|
|
23168
23561
|
}
|
|
23169
23562
|
async function checkIndex(project) {
|
|
23170
|
-
if (!
|
|
23563
|
+
if (!existsSync7(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
23171
23564
|
const sqlite = await loadSqlite2();
|
|
23172
23565
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
23173
23566
|
let raw = null;
|
|
@@ -23184,7 +23577,7 @@ async function checkIndex(project) {
|
|
|
23184
23577
|
}
|
|
23185
23578
|
|
|
23186
23579
|
// src/core/ops/doctor-env.ts
|
|
23187
|
-
import { existsSync as
|
|
23580
|
+
import { existsSync as existsSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
23188
23581
|
import { isAbsolute as isAbsolute3, relative as relative2 } from "node:path";
|
|
23189
23582
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
23190
23583
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
@@ -23242,7 +23635,7 @@ function checkMcp(ctx) {
|
|
|
23242
23635
|
return named || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
23243
23636
|
}
|
|
23244
23637
|
function piCwdInside(worktree, piCwd) {
|
|
23245
|
-
if (piCwd === void 0 || !
|
|
23638
|
+
if (piCwd === void 0 || !existsSync8(piCwd)) return false;
|
|
23246
23639
|
const rel = relative2(worktree, realpathSync5.native(piCwd));
|
|
23247
23640
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
23248
23641
|
}
|
|
@@ -23263,15 +23656,17 @@ function checkShell(env) {
|
|
|
23263
23656
|
}
|
|
23264
23657
|
|
|
23265
23658
|
// src/core/ops/doctor-hook.ts
|
|
23266
|
-
import { existsSync as
|
|
23659
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9 } from "node:fs";
|
|
23267
23660
|
import path4 from "node:path";
|
|
23661
|
+
var D5_MIN_PAIRS = 3;
|
|
23662
|
+
var D5_MAX_PAIRS = 9;
|
|
23268
23663
|
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 };
|
|
23269
23664
|
function isObject5(v) {
|
|
23270
23665
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23271
23666
|
}
|
|
23272
23667
|
function loadFixture(bundleDir2, agent) {
|
|
23273
23668
|
const file2 = path4.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
23274
|
-
if (!
|
|
23669
|
+
if (!existsSync9(file2)) return null;
|
|
23275
23670
|
let all;
|
|
23276
23671
|
try {
|
|
23277
23672
|
all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
|
|
@@ -23283,6 +23678,9 @@ function loadFixture(bundleDir2, agent) {
|
|
|
23283
23678
|
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) return null;
|
|
23284
23679
|
return { event: e.event, payload: e.payload };
|
|
23285
23680
|
}
|
|
23681
|
+
function payloadFor(payload, worktree) {
|
|
23682
|
+
return worktree !== void 0 && isObject5(payload) ? { ...payload, cwd: worktree } : payload;
|
|
23683
|
+
}
|
|
23286
23684
|
function isNativeShape(stdout, exitCode, killed, event) {
|
|
23287
23685
|
if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
|
|
23288
23686
|
if (stdout.length === 0) return true;
|
|
@@ -23299,31 +23697,47 @@ function codexHookJournaled(db) {
|
|
|
23299
23697
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
23300
23698
|
}
|
|
23301
23699
|
async function checkHookRoundTrip(i) {
|
|
23302
|
-
if (i.agent === "codex" &&
|
|
23700
|
+
if (i.agent === "codex" && existsSync9(path4.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
23303
23701
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
23304
23702
|
}
|
|
23305
23703
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
23306
23704
|
if (fixture === null) return row("UNKNOWN", D5_NO_FIXTURE_DETAIL(i.agent));
|
|
23307
23705
|
const now = i.now ?? (() => performance.now());
|
|
23308
|
-
const
|
|
23309
|
-
const
|
|
23310
|
-
|
|
23311
|
-
|
|
23312
|
-
|
|
23313
|
-
timeoutMs: HOOK_TIMEOUT_MS
|
|
23314
|
-
|
|
23706
|
+
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
23707
|
+
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
23708
|
+
const minPairs = fixed ?? D5_MIN_PAIRS;
|
|
23709
|
+
const bareMs = i.bareMs ?? (async () => {
|
|
23710
|
+
const t = performance.now();
|
|
23711
|
+
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs: HOOK_TIMEOUT_MS });
|
|
23712
|
+
return performance.now() - t;
|
|
23315
23713
|
});
|
|
23316
|
-
const
|
|
23317
|
-
|
|
23714
|
+
const hookWalls = [];
|
|
23715
|
+
const bareWalls = [];
|
|
23716
|
+
let ms = 0;
|
|
23717
|
+
for (let n = 1; n <= maxPairs; n++) {
|
|
23718
|
+
const start = now();
|
|
23719
|
+
const r = await runProcess([process.execPath, path4.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
23720
|
+
cwd: i.bundleDir,
|
|
23721
|
+
env: i.env,
|
|
23722
|
+
signal: i.signal,
|
|
23723
|
+
timeoutMs: HOOK_TIMEOUT_MS,
|
|
23724
|
+
stdin: JSON.stringify(payloadFor(fixture.payload, i.worktree))
|
|
23725
|
+
});
|
|
23726
|
+
hookWalls.push(now() - start);
|
|
23727
|
+
if (!isNativeShape(r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
23728
|
+
bareWalls.push(await bareMs());
|
|
23729
|
+
ms = Math.max(0, Math.round(Math.min(...hookWalls) - Math.min(...bareWalls)));
|
|
23730
|
+
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
23731
|
+
}
|
|
23318
23732
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
23319
23733
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
23320
23734
|
}
|
|
23321
23735
|
|
|
23322
23736
|
// src/core/ops/db-heal.ts
|
|
23323
|
-
import { existsSync as
|
|
23737
|
+
import { existsSync as existsSync10, rmSync as rmSync3 } from "node:fs";
|
|
23324
23738
|
|
|
23325
23739
|
// src/core/store/owners.ts
|
|
23326
|
-
import { mkdirSync as mkdirSync4, readdirSync as
|
|
23740
|
+
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23327
23741
|
import { basename as basename2, join as join12 } from "node:path";
|
|
23328
23742
|
function ownersDir(configDir, projectKey) {
|
|
23329
23743
|
return join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -23346,7 +23760,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
23346
23760
|
const dir = ownersDir(configDir, projectKey);
|
|
23347
23761
|
let names;
|
|
23348
23762
|
try {
|
|
23349
|
-
names =
|
|
23763
|
+
names = readdirSync4(dir);
|
|
23350
23764
|
} catch (err) {
|
|
23351
23765
|
if (errCode2(err) === "ENOENT") return [];
|
|
23352
23766
|
throw err;
|
|
@@ -23403,7 +23817,7 @@ function renameAside(dbPath) {
|
|
|
23403
23817
|
const ts = String(Date.now());
|
|
23404
23818
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
23405
23819
|
const file2 = dbPath + suffix;
|
|
23406
|
-
if (
|
|
23820
|
+
if (existsSync10(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
23407
23821
|
}
|
|
23408
23822
|
return ts;
|
|
23409
23823
|
}
|
|
@@ -23484,7 +23898,7 @@ async function guard(id2, run) {
|
|
|
23484
23898
|
}
|
|
23485
23899
|
}
|
|
23486
23900
|
async function codexDb(ctx, adapter) {
|
|
23487
|
-
if (adapter.id !== "codex" || !
|
|
23901
|
+
if (adapter.id !== "codex" || !existsSync11(ctx.project.dbPath)) return null;
|
|
23488
23902
|
try {
|
|
23489
23903
|
return await openDb(ctx.project, { readOnly: true });
|
|
23490
23904
|
} catch {
|
|
@@ -23493,8 +23907,10 @@ async function codexDb(ctx, adapter) {
|
|
|
23493
23907
|
}
|
|
23494
23908
|
async function hookRow(ctx, adapter, host) {
|
|
23495
23909
|
const db = await codexDb(ctx, adapter);
|
|
23910
|
+
const runStart = Date.now();
|
|
23496
23911
|
try {
|
|
23497
23912
|
const row5 = await checkHookRoundTrip({
|
|
23913
|
+
worktree: ctx.project.worktree,
|
|
23498
23914
|
agent: adapter.id,
|
|
23499
23915
|
bundleDir: host.bundleDir,
|
|
23500
23916
|
env: buildChildEnv(host.env),
|
|
@@ -23504,15 +23920,17 @@ async function hookRow(ctx, adapter, host) {
|
|
|
23504
23920
|
db
|
|
23505
23921
|
});
|
|
23506
23922
|
const last2 = lastHookError(host.env);
|
|
23507
|
-
|
|
23923
|
+
if (last2 === null) return row5;
|
|
23924
|
+
const text = Date.parse(last2.ts) >= runStart ? D5_LAST_HOOK_ERROR : D5_PAST_HOOK_ERROR;
|
|
23925
|
+
return { ...row5, detail: row5.detail + text(last2.ts, last2.stage, last2.label) };
|
|
23508
23926
|
} finally {
|
|
23509
23927
|
if (db !== null) closeDb(db);
|
|
23510
23928
|
}
|
|
23511
23929
|
}
|
|
23512
23930
|
function ownServerId(configDir, projectKey) {
|
|
23513
23931
|
const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23514
|
-
if (!
|
|
23515
|
-
for (const name of
|
|
23932
|
+
if (!existsSync11(dir)) return "";
|
|
23933
|
+
for (const name of readdirSync5(dir)) {
|
|
23516
23934
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
23517
23935
|
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
|
|
23518
23936
|
}
|
|
@@ -23586,9 +24004,9 @@ var ctxDoctor = Object.freeze({
|
|
|
23586
24004
|
});
|
|
23587
24005
|
|
|
23588
24006
|
// src/core/tools/execute.ts
|
|
23589
|
-
import { existsSync as
|
|
24007
|
+
import { existsSync as existsSync12, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
23590
24008
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
23591
|
-
import { dirname as dirname7, join as join14, parse as parse3, resolve as
|
|
24009
|
+
import { dirname as dirname7, join as join14, parse as parse3, resolve as resolve5 } from "node:path";
|
|
23592
24010
|
|
|
23593
24011
|
// src/core/sandbox/win-build.ts
|
|
23594
24012
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -23672,7 +24090,7 @@ function schemaLine(issue2) {
|
|
|
23672
24090
|
}
|
|
23673
24091
|
function fileError(given, abs, root) {
|
|
23674
24092
|
let dir = abs;
|
|
23675
|
-
while (!
|
|
24093
|
+
while (!existsSync12(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
|
|
23676
24094
|
if (isInside(root, dir)) return null;
|
|
23677
24095
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
23678
24096
|
}
|
|
@@ -23734,7 +24152,7 @@ async function handler3(raw, ctx) {
|
|
|
23734
24152
|
const cwd = ctx.project.worktree;
|
|
23735
24153
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
23736
24154
|
if (input.file !== void 0) {
|
|
23737
|
-
const abs =
|
|
24155
|
+
const abs = resolve5(cwd, input.file);
|
|
23738
24156
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
23739
24157
|
if (bad !== null) return fail5(bad);
|
|
23740
24158
|
extra.CTX_FILE = abs;
|
|
@@ -23787,11 +24205,11 @@ var ctxExecute = {
|
|
|
23787
24205
|
};
|
|
23788
24206
|
|
|
23789
24207
|
// src/core/tools/index.ts
|
|
23790
|
-
import { existsSync as
|
|
23791
|
-
import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as
|
|
24208
|
+
import { existsSync as existsSync13, readFileSync as readFileSync13, statSync as statSync6 } from "node:fs";
|
|
24209
|
+
import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as resolve6 } from "node:path";
|
|
23792
24210
|
|
|
23793
24211
|
// src/core/index/walk.ts
|
|
23794
|
-
import { readdirSync as
|
|
24212
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync6, statSync as statSync5 } from "node:fs";
|
|
23795
24213
|
import { join as join15 } from "node:path";
|
|
23796
24214
|
var GITIGNORE = ".gitignore";
|
|
23797
24215
|
var GIT_DIR = ".git";
|
|
@@ -23806,7 +24224,7 @@ function walkDir(root, containmentRoot) {
|
|
|
23806
24224
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
23807
24225
|
let entries;
|
|
23808
24226
|
try {
|
|
23809
|
-
entries =
|
|
24227
|
+
entries = readdirSync6(abs, { withFileTypes: true });
|
|
23810
24228
|
} catch {
|
|
23811
24229
|
return;
|
|
23812
24230
|
}
|
|
@@ -24030,18 +24448,18 @@ function request(u, conn, proxy, signal) {
|
|
|
24030
24448
|
const host = bare(u.hostname);
|
|
24031
24449
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
24032
24450
|
const path5 = u.pathname + u.search;
|
|
24033
|
-
return new Promise((
|
|
24451
|
+
return new Promise((resolve7, reject) => {
|
|
24034
24452
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
24035
24453
|
if (proxy === void 0) {
|
|
24036
24454
|
const mod = u.protocol === "https:" ? https : http;
|
|
24037
24455
|
const req = mod.request({ host: conn.address, port, path: path5, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
24038
|
-
req.on("response",
|
|
24456
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24039
24457
|
return;
|
|
24040
24458
|
}
|
|
24041
24459
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
24042
24460
|
if (u.protocol === "http:") {
|
|
24043
24461
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
24044
|
-
req.on("response",
|
|
24462
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24045
24463
|
return;
|
|
24046
24464
|
}
|
|
24047
24465
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -24061,16 +24479,16 @@ function request(u, conn, proxy, signal) {
|
|
|
24061
24479
|
headers: { host: u.host },
|
|
24062
24480
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
24063
24481
|
});
|
|
24064
|
-
req.on("response",
|
|
24482
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24065
24483
|
});
|
|
24066
24484
|
tunnel.end();
|
|
24067
24485
|
});
|
|
24068
24486
|
}
|
|
24069
24487
|
function readBody(res) {
|
|
24070
|
-
return new Promise((
|
|
24488
|
+
return new Promise((resolve7, reject) => {
|
|
24071
24489
|
const parts = [];
|
|
24072
24490
|
res.on("data", (b) => parts.push(b));
|
|
24073
|
-
res.on("end", () =>
|
|
24491
|
+
res.on("end", () => resolve7(Buffer.concat(parts)));
|
|
24074
24492
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
24075
24493
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
24076
24494
|
});
|
|
@@ -27792,17 +28210,17 @@ function list3(st, el) {
|
|
|
27792
28210
|
n += 1;
|
|
27793
28211
|
st.w.line();
|
|
27794
28212
|
st.w.push(marker, " ".repeat(marker.length));
|
|
27795
|
-
for (const k of c.children)
|
|
28213
|
+
for (const k of c.children) walk2(st, k);
|
|
27796
28214
|
st.w.pop();
|
|
27797
28215
|
st.w.line();
|
|
27798
28216
|
} else {
|
|
27799
|
-
|
|
28217
|
+
walk2(st, c);
|
|
27800
28218
|
}
|
|
27801
28219
|
}
|
|
27802
28220
|
if (st.w.depth() === 0) st.w.block();
|
|
27803
28221
|
else st.w.line();
|
|
27804
28222
|
}
|
|
27805
|
-
function
|
|
28223
|
+
function walk2(st, node) {
|
|
27806
28224
|
if (isText2(node)) {
|
|
27807
28225
|
st.w.text(collapse(node.data));
|
|
27808
28226
|
return;
|
|
@@ -27842,7 +28260,7 @@ function walk(st, node) {
|
|
|
27842
28260
|
case "blockquote":
|
|
27843
28261
|
st.w.block();
|
|
27844
28262
|
st.w.push("> ", "> ");
|
|
27845
|
-
for (const c of node.children)
|
|
28263
|
+
for (const c of node.children) walk2(st, c);
|
|
27846
28264
|
st.w.pop();
|
|
27847
28265
|
st.w.block();
|
|
27848
28266
|
return;
|
|
@@ -27865,7 +28283,7 @@ function walk(st, node) {
|
|
|
27865
28283
|
const line = LINE.has(name);
|
|
27866
28284
|
if (para) st.w.block();
|
|
27867
28285
|
else if (line) st.w.line();
|
|
27868
|
-
for (const c of node.children)
|
|
28286
|
+
for (const c of node.children) walk2(st, c);
|
|
27869
28287
|
if (para) st.w.block();
|
|
27870
28288
|
else if (line) st.w.line();
|
|
27871
28289
|
}
|
|
@@ -27903,7 +28321,7 @@ function htmlToReadable(html, baseUrl) {
|
|
|
27903
28321
|
base = void 0;
|
|
27904
28322
|
}
|
|
27905
28323
|
const st = { w: new Writer(), base, sawH1: false };
|
|
27906
|
-
for (const n of contentRoot(doc.children))
|
|
28324
|
+
for (const n of contentRoot(doc.children)) walk2(st, n);
|
|
27907
28325
|
const body = st.w.result();
|
|
27908
28326
|
const words = wordCount(body);
|
|
27909
28327
|
const text = !st.sawH1 && title !== "" && words > 0 ? "# " + title + "\n\n" + body : body;
|
|
@@ -27943,12 +28361,12 @@ function readUtf8(absPath) {
|
|
|
27943
28361
|
}
|
|
27944
28362
|
function missingOrOutside(given, abs, root) {
|
|
27945
28363
|
let dir = abs;
|
|
27946
|
-
while (!
|
|
28364
|
+
while (!existsSync13(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
27947
28365
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
27948
28366
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
27949
28367
|
}
|
|
27950
28368
|
function pathItems(input, project) {
|
|
27951
|
-
const abs =
|
|
28369
|
+
const abs = resolve6(project.worktree, input.path);
|
|
27952
28370
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
27953
28371
|
const base = relative3(project.worktree, abs);
|
|
27954
28372
|
if (statSync6(abs).isDirectory()) {
|
|
@@ -28210,11 +28628,11 @@ var ctxStats = Object.freeze({
|
|
|
28210
28628
|
});
|
|
28211
28629
|
|
|
28212
28630
|
// src/core/tools/upgrade.ts
|
|
28213
|
-
import { existsSync as
|
|
28631
|
+
import { existsSync as existsSync19, realpathSync as realpathSync7, rmSync as rmSync9 } from "node:fs";
|
|
28214
28632
|
import { basename as basename5, dirname as dirname10, join as join22 } from "node:path";
|
|
28215
28633
|
|
|
28216
28634
|
// src/core/ops/host-write.ts
|
|
28217
|
-
import { copyFileSync, existsSync as
|
|
28635
|
+
import { copyFileSync, existsSync as existsSync14, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28218
28636
|
import { dirname as dirname9, join as join17 } from "node:path";
|
|
28219
28637
|
function defaultWrite(file2, text) {
|
|
28220
28638
|
writeFileSync4(file2, text, "utf8");
|
|
@@ -28243,7 +28661,7 @@ function toRow(file2, edit) {
|
|
|
28243
28661
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
28244
28662
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
28245
28663
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
28246
|
-
const had =
|
|
28664
|
+
const had = existsSync14(file2);
|
|
28247
28665
|
mkdirSync5(dirname9(file2), { recursive: true });
|
|
28248
28666
|
if (had) copyFileSync(file2, trash);
|
|
28249
28667
|
try {
|
|
@@ -28273,7 +28691,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28273
28691
|
if (requested === null) return [];
|
|
28274
28692
|
const current = readHostConfig(row5.id, requested);
|
|
28275
28693
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
28276
|
-
const exists =
|
|
28694
|
+
const exists = existsSync14(current.path);
|
|
28277
28695
|
if (exists && result.text === current.text) return [];
|
|
28278
28696
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
28279
28697
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -28281,7 +28699,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28281
28699
|
}
|
|
28282
28700
|
|
|
28283
28701
|
// src/core/ops/plugin-swap.ts
|
|
28284
|
-
import { existsSync as
|
|
28702
|
+
import { existsSync as existsSync15, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
28285
28703
|
import { basename as basename4, join as join18, win32 as win322 } from "node:path";
|
|
28286
28704
|
function linkTarget(path5, win) {
|
|
28287
28705
|
if (!isLink(path5)) return null;
|
|
@@ -28292,7 +28710,7 @@ function isLink(path5) {
|
|
|
28292
28710
|
return lstatSync(path5, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
28293
28711
|
}
|
|
28294
28712
|
function generations(agentDir) {
|
|
28295
|
-
return
|
|
28713
|
+
return readdirSync7(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
|
|
28296
28714
|
}
|
|
28297
28715
|
function settleLinks(link, tmp, old, opts) {
|
|
28298
28716
|
if (isLink(tmp)) unlinkSync2(tmp);
|
|
@@ -28302,7 +28720,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
28302
28720
|
}
|
|
28303
28721
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
28304
28722
|
const next = join18(agentDir, sha);
|
|
28305
|
-
if (!
|
|
28723
|
+
if (!existsSync15(next) || !lstatSync(next).isDirectory()) {
|
|
28306
28724
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
|
|
28307
28725
|
}
|
|
28308
28726
|
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
@@ -28322,12 +28740,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
28322
28740
|
if (before !== null) keep.add(before);
|
|
28323
28741
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
|
|
28324
28742
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
28325
|
-
const previous = before !== null &&
|
|
28743
|
+
const previous = before !== null && existsSync15(join18(agentDir, before)) ? join18(agentDir, before) : null;
|
|
28326
28744
|
return { current: next, previous, removed };
|
|
28327
28745
|
}
|
|
28328
28746
|
|
|
28329
28747
|
// src/core/ops/release-fetch.ts
|
|
28330
|
-
import { existsSync as
|
|
28748
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
|
|
28331
28749
|
import { join as join19 } from "node:path";
|
|
28332
28750
|
function failed(r) {
|
|
28333
28751
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -28351,7 +28769,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
28351
28769
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
28352
28770
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
28353
28771
|
const dir = join19(agentDir, sha);
|
|
28354
|
-
if (
|
|
28772
|
+
if (existsSync16(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
28355
28773
|
else renameWithRetry(fetchDir, dir, opts);
|
|
28356
28774
|
return { sha, dir };
|
|
28357
28775
|
} catch (e) {
|
|
@@ -28361,7 +28779,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
28361
28779
|
}
|
|
28362
28780
|
|
|
28363
28781
|
// src/core/ops/uninstall.ts
|
|
28364
|
-
import { existsSync as
|
|
28782
|
+
import { existsSync as existsSync17, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28365
28783
|
import { join as join20 } from "node:path";
|
|
28366
28784
|
function row2(area, before, after) {
|
|
28367
28785
|
return { area, before, after };
|
|
@@ -28391,7 +28809,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
28391
28809
|
}
|
|
28392
28810
|
case "plugin": {
|
|
28393
28811
|
const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
28394
|
-
if (!
|
|
28812
|
+
if (!existsSync17(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
28395
28813
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
28396
28814
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
28397
28815
|
}
|
|
@@ -28471,9 +28889,9 @@ function removeOwnEntries(agent, env) {
|
|
|
28471
28889
|
function removeProjectData(configDir, projectKey) {
|
|
28472
28890
|
const projects = join20(configDir, PROJECTS_DIR_NAME);
|
|
28473
28891
|
const dir = join20(projects, projectKey);
|
|
28474
|
-
if (!
|
|
28892
|
+
if (!existsSync17(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
28475
28893
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
28476
|
-
for (const name of
|
|
28894
|
+
for (const name of readdirSync8(dir)) {
|
|
28477
28895
|
if (name !== OWNERS_DIR_NAME) rmSync7(join20(dir, name), { recursive: true, force: true });
|
|
28478
28896
|
}
|
|
28479
28897
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
@@ -28487,7 +28905,7 @@ function runUninstall(input) {
|
|
|
28487
28905
|
}
|
|
28488
28906
|
|
|
28489
28907
|
// src/core/ops/v1-remove.ts
|
|
28490
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
28908
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync18, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
|
|
28491
28909
|
var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
28492
28910
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
28493
28911
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -28568,14 +28986,14 @@ function removeV1(agent, findings) {
|
|
|
28568
28986
|
for (const f of findings) {
|
|
28569
28987
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
28570
28988
|
else if (f.path === "") {
|
|
28571
|
-
if (
|
|
28989
|
+
if (existsSync18(f.file)) {
|
|
28572
28990
|
moveAside(f.file, undo);
|
|
28573
28991
|
done.set(f, UPGRADE_REMOVED);
|
|
28574
28992
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
28575
28993
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
28576
28994
|
}
|
|
28577
28995
|
for (const [file2, list4] of entries) {
|
|
28578
|
-
if (!
|
|
28996
|
+
if (!existsSync18(file2)) {
|
|
28579
28997
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
28580
28998
|
continue;
|
|
28581
28999
|
}
|
|
@@ -28608,7 +29026,7 @@ function removeV1(agent, findings) {
|
|
|
28608
29026
|
},
|
|
28609
29027
|
rollback() {
|
|
28610
29028
|
for (const u of undo.splice(0).reverse()) {
|
|
28611
|
-
if (!
|
|
29029
|
+
if (!existsSync18(u.trash)) continue;
|
|
28612
29030
|
rmSync8(u.target, { recursive: true, force: true });
|
|
28613
29031
|
renameWithRetry(u.trash, u.target);
|
|
28614
29032
|
}
|
|
@@ -28618,7 +29036,7 @@ function removeV1(agent, findings) {
|
|
|
28618
29036
|
|
|
28619
29037
|
// src/core/ops/verify-sums.ts
|
|
28620
29038
|
import { createHash } from "node:crypto";
|
|
28621
|
-
import { lstatSync as lstatSync2, readdirSync as
|
|
29039
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync15 } from "node:fs";
|
|
28622
29040
|
import { join as join21 } from "node:path";
|
|
28623
29041
|
function mismatch() {
|
|
28624
29042
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
@@ -28636,12 +29054,12 @@ function parseSums(text) {
|
|
|
28636
29054
|
}
|
|
28637
29055
|
return sums;
|
|
28638
29056
|
}
|
|
28639
|
-
function
|
|
28640
|
-
for (const entry of
|
|
29057
|
+
function walk3(dir, prefix, out) {
|
|
29058
|
+
for (const entry of readdirSync9(dir, { withFileTypes: true })) {
|
|
28641
29059
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
28642
29060
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
28643
29061
|
const abs = join21(dir, entry.name);
|
|
28644
|
-
if (entry.isDirectory())
|
|
29062
|
+
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
28645
29063
|
else if (entry.isFile()) out.set(rel, abs);
|
|
28646
29064
|
else throw mismatch();
|
|
28647
29065
|
}
|
|
@@ -28652,7 +29070,7 @@ function verifySums(dir) {
|
|
|
28652
29070
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
28653
29071
|
const sums = parseSums(readFileSync15(sumsPath, "utf8"));
|
|
28654
29072
|
const files = /* @__PURE__ */ new Map();
|
|
28655
|
-
|
|
29073
|
+
walk3(dir, "", files);
|
|
28656
29074
|
if (files.size !== sums.size) throw mismatch();
|
|
28657
29075
|
for (const [rel, abs] of files) {
|
|
28658
29076
|
const want = sums.get(rel);
|
|
@@ -28686,7 +29104,7 @@ function pluginRootRow(adapter, env) {
|
|
|
28686
29104
|
}
|
|
28687
29105
|
function isCurrent(agentDir, dir) {
|
|
28688
29106
|
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
28689
|
-
return
|
|
29107
|
+
return existsSync19(link) && realpathSync7.native(link) === realpathSync7.native(dir);
|
|
28690
29108
|
}
|
|
28691
29109
|
async function checkout(adapter, deps) {
|
|
28692
29110
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -28807,14 +29225,14 @@ function checkCall(tool, input) {
|
|
|
28807
29225
|
// src/entries/opencode.ts
|
|
28808
29226
|
var AGENT = "opencode";
|
|
28809
29227
|
var id = PLUGIN_ID;
|
|
28810
|
-
async function
|
|
29228
|
+
async function setupLegacy(app) {
|
|
28811
29229
|
const cwd = app.directory;
|
|
28812
29230
|
const env = process.env;
|
|
28813
29231
|
const turns = /* @__PURE__ */ new Map();
|
|
28814
29232
|
const payloads = /* @__PURE__ */ new Map();
|
|
28815
29233
|
const call = (raw) => handleHook(AGENT, { ...raw, directory: cwd }, env);
|
|
28816
29234
|
const turnOf = (sessionId) => turns.get(sessionId) ?? 0;
|
|
28817
|
-
function
|
|
29235
|
+
function payloadFor2(sessionId) {
|
|
28818
29236
|
let p = payloads.get(sessionId);
|
|
28819
29237
|
if (p === void 0) {
|
|
28820
29238
|
p = call({ type: "context", sessionID: sessionId, turn: turnOf(sessionId) }).then((out) => [out.stdout, INSTRUCTIONS].filter((s) => s !== "").join("\n\n"));
|
|
@@ -28867,7 +29285,7 @@ async function setup(app) {
|
|
|
28867
29285
|
// §4.4. Deny (exit 2) throws with the reason; the reason carries any rewritten command (Q3, D-M5-P2-3).
|
|
28868
29286
|
"tool.execute.before": async (input, output) => {
|
|
28869
29287
|
const sessionId = input.sessionID ?? "";
|
|
28870
|
-
await
|
|
29288
|
+
await payloadFor2(sessionId);
|
|
28871
29289
|
const out = await call({
|
|
28872
29290
|
type: "execute.before",
|
|
28873
29291
|
sessionID: sessionId,
|
|
@@ -28881,7 +29299,7 @@ async function setup(app) {
|
|
|
28881
29299
|
// §4.5. OpenCode's encode has no replace field (impl/10 §11), so output.output is never changed here.
|
|
28882
29300
|
"tool.execute.after": async (input, output) => {
|
|
28883
29301
|
const sessionId = input.sessionID ?? "";
|
|
28884
|
-
await
|
|
29302
|
+
await payloadFor2(sessionId);
|
|
28885
29303
|
await call({
|
|
28886
29304
|
type: "execute.after",
|
|
28887
29305
|
sessionID: sessionId,
|
|
@@ -28889,13 +29307,14 @@ async function setup(app) {
|
|
|
28889
29307
|
callID: input.callID,
|
|
28890
29308
|
args: input.args,
|
|
28891
29309
|
output: output.output,
|
|
29310
|
+
isError: output.isError,
|
|
28892
29311
|
turn: turnOf(sessionId)
|
|
28893
29312
|
});
|
|
28894
29313
|
},
|
|
28895
29314
|
// §4.6: one system entry per session, the same bytes on every request (#1085, Q12). A second
|
|
28896
29315
|
// transform on the same array finds the entry and adds nothing.
|
|
28897
29316
|
"experimental.chat.system.transform": async (input, output) => {
|
|
28898
|
-
const payload = await
|
|
29317
|
+
const payload = await payloadFor2(input.sessionID ?? "");
|
|
28899
29318
|
if (!output.system.includes(payload)) output.system.push(payload);
|
|
28900
29319
|
},
|
|
28901
29320
|
// PreCompact: handleHook sets the pending-compact marker the next session payload reads (§4.6 step 2).
|
|
@@ -28912,9 +29331,61 @@ async function setup(app) {
|
|
|
28912
29331
|
}
|
|
28913
29332
|
};
|
|
28914
29333
|
}
|
|
29334
|
+
function oc2Text(content) {
|
|
29335
|
+
if (typeof content === "string") return content;
|
|
29336
|
+
return (content ?? []).filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n");
|
|
29337
|
+
}
|
|
29338
|
+
async function setup(ctx) {
|
|
29339
|
+
const tools = /* @__PURE__ */ new Map();
|
|
29340
|
+
const hooks = await setupLegacy({
|
|
29341
|
+
directory: ctx.location.directory,
|
|
29342
|
+
tool(name, def) {
|
|
29343
|
+
tools.set(name, {
|
|
29344
|
+
name,
|
|
29345
|
+
description: def.description,
|
|
29346
|
+
input: external_exports.toJSONSchema(def.args, { target: "draft-2020-12", io: "input" }),
|
|
29347
|
+
options: { codemode: false },
|
|
29348
|
+
// a ctx_* tool is listed to the model by name, not behind the host's code tool
|
|
29349
|
+
async execute(input, context) {
|
|
29350
|
+
return { content: await def.execute(input, { sessionID: context.sessionID, abort: context.signal }) };
|
|
29351
|
+
}
|
|
29352
|
+
});
|
|
29353
|
+
}
|
|
29354
|
+
});
|
|
29355
|
+
await ctx.tool.transform((editor) => {
|
|
29356
|
+
for (const t of tools.values()) editor.add(t);
|
|
29357
|
+
});
|
|
29358
|
+
await ctx.tool.hook("execute.before", async (i) => {
|
|
29359
|
+
await hooks["tool.execute.before"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id }, { args: i.input });
|
|
29360
|
+
});
|
|
29361
|
+
await ctx.tool.hook("execute.after", async (i) => {
|
|
29362
|
+
const failed2 = i.status === "error";
|
|
29363
|
+
const output = failed2 ? i.error?.message ?? "" : oc2Text(i.result?.content);
|
|
29364
|
+
await hooks["tool.execute.after"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, args: i.input }, { output, isError: failed2 });
|
|
29365
|
+
});
|
|
29366
|
+
await ctx.session.hook("prompt", async (p) => {
|
|
29367
|
+
await hooks["chat.message"]({ sessionID: p.sessionID }, { parts: [{ type: "text", text: p.prompt?.text ?? "" }] });
|
|
29368
|
+
});
|
|
29369
|
+
await ctx.session.hook("context", async (c) => {
|
|
29370
|
+
const system = [];
|
|
29371
|
+
await hooks["experimental.chat.system.transform"]({ sessionID: c.sessionID }, { system });
|
|
29372
|
+
for (const text of system) if (!c.system.some((p) => p.text === text)) c.system.push({ type: "text", text });
|
|
29373
|
+
});
|
|
29374
|
+
await ctx.session.hook("compaction", async (c) => {
|
|
29375
|
+
await hooks["experimental.session.compacting"]({ sessionID: c.sessionID });
|
|
29376
|
+
});
|
|
29377
|
+
const stop = new AbortController();
|
|
29378
|
+
void (async () => {
|
|
29379
|
+
for await (const e of ctx.event.subscribe({ types: ["session.step.ended"], signal: stop.signal })) {
|
|
29380
|
+
await hooks.event({ event: { type: "message.part.updated", properties: { part: { type: "step-finish", sessionID: e.data?.sessionID } } } });
|
|
29381
|
+
}
|
|
29382
|
+
})().catch(() => {
|
|
29383
|
+
});
|
|
29384
|
+
return () => stop.abort();
|
|
29385
|
+
}
|
|
28915
29386
|
async function server(input, _options) {
|
|
28916
29387
|
const tool = {};
|
|
28917
|
-
const hooks = await
|
|
29388
|
+
const hooks = await setupLegacy({
|
|
28918
29389
|
directory: input.directory,
|
|
28919
29390
|
tool(name, def) {
|
|
28920
29391
|
const shape = def.args.shape;
|
|
@@ -28928,5 +29399,6 @@ export {
|
|
|
28928
29399
|
opencode_default as default,
|
|
28929
29400
|
id,
|
|
28930
29401
|
server,
|
|
28931
|
-
setup
|
|
29402
|
+
setup,
|
|
29403
|
+
setupLegacy
|
|
28932
29404
|
};
|