context-mode 2.0.0-next.16 → 2.0.0-next.18
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 +55 -44
- 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 +518 -106
- package/package.json +1 -1
- package/pi/index.js +575 -136
- package/qwen-extension.json +1 -1
- package/run.mjs +369 -22
- package/search.mjs +369 -22
- package/server.mjs +164 -69
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 ? "ea4179fd9a2c4c55eadc9184a295a7f974df90bd" : 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) {
|
|
@@ -1553,8 +1557,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1553
1557
|
installMode: "plugin",
|
|
1554
1558
|
projectSource: "arg:--agent+cwd",
|
|
1555
1559
|
toolNamePrefix: TOOL_NAME_PREFIX5,
|
|
1556
|
-
nativeTools: { shell: [
|
|
1560
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES] },
|
|
1557
1561
|
execReadOnlyHint: false,
|
|
1562
|
+
// D-PWSH-DUMP-1
|
|
1558
1563
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
1559
1564
|
compactDelivery: "pending-flag",
|
|
1560
1565
|
compactSummary: "none",
|
|
@@ -1572,7 +1577,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1572
1577
|
projectSource: "arg:workspaceFolder",
|
|
1573
1578
|
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
1574
1579
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
1575
|
-
nativeTools: { shell: [...
|
|
1580
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES2], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
1576
1581
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
1577
1582
|
execReadOnlyHint: false,
|
|
1578
1583
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -1591,7 +1596,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1591
1596
|
installMode: "mcp-entry",
|
|
1592
1597
|
projectSource: "arg:--agent+cwd",
|
|
1593
1598
|
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
1594
|
-
nativeTools: { shell: [...
|
|
1599
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
|
|
1595
1600
|
execReadOnlyHint: false,
|
|
1596
1601
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
1597
1602
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -1683,7 +1688,7 @@ function getAdapter(id2) {
|
|
|
1683
1688
|
}
|
|
1684
1689
|
|
|
1685
1690
|
// src/core/policy/decide.ts
|
|
1686
|
-
import { resolve } from "node:path";
|
|
1691
|
+
import { resolve as resolve2 } from "node:path";
|
|
1687
1692
|
|
|
1688
1693
|
// src/core/policy/lexer.ts
|
|
1689
1694
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -2624,6 +2629,343 @@ function parseShell(cmd) {
|
|
|
2624
2629
|
return { ok: true, commands };
|
|
2625
2630
|
}
|
|
2626
2631
|
|
|
2632
|
+
// src/core/policy/powershell.ts
|
|
2633
|
+
import { resolve } from "node:path";
|
|
2634
|
+
var SQ = "'";
|
|
2635
|
+
var DQ = '"';
|
|
2636
|
+
var TICK = "`";
|
|
2637
|
+
var SPACES = " \r";
|
|
2638
|
+
var OPENERS = "([{";
|
|
2639
|
+
var CLOSERS = ")]}";
|
|
2640
|
+
var GLUE_END = " \r\n|;>";
|
|
2641
|
+
var FD_STAR = "*";
|
|
2642
|
+
var STDOUT_FD = "1";
|
|
2643
|
+
var METHOD_MARK = "::";
|
|
2644
|
+
var PAIR = METHOD_MARK.length;
|
|
2645
|
+
var MIN_STATIC_CALL = PAIR;
|
|
2646
|
+
function quoteEnd(text, at2) {
|
|
2647
|
+
const q = text.charAt(at2);
|
|
2648
|
+
for (let j = at2 + 1; j < text.length; j++) {
|
|
2649
|
+
const c = text.charAt(j);
|
|
2650
|
+
if (q === DQ && c === TICK) {
|
|
2651
|
+
j++;
|
|
2652
|
+
continue;
|
|
2653
|
+
}
|
|
2654
|
+
if (c !== q) continue;
|
|
2655
|
+
if (text.charAt(j + 1) === q) {
|
|
2656
|
+
j++;
|
|
2657
|
+
continue;
|
|
2658
|
+
}
|
|
2659
|
+
return j;
|
|
2660
|
+
}
|
|
2661
|
+
return -1;
|
|
2662
|
+
}
|
|
2663
|
+
function unquote(body, q) {
|
|
2664
|
+
let out = "";
|
|
2665
|
+
for (let j = 0; j < body.length; j++) {
|
|
2666
|
+
const c = body.charAt(j);
|
|
2667
|
+
if (q === DQ && c === TICK && j + 1 < body.length) {
|
|
2668
|
+
out += body.charAt(++j);
|
|
2669
|
+
continue;
|
|
2670
|
+
}
|
|
2671
|
+
if (c === q && body.charAt(j + 1) === q) j++;
|
|
2672
|
+
out += c;
|
|
2673
|
+
}
|
|
2674
|
+
return out;
|
|
2675
|
+
}
|
|
2676
|
+
function closeOf(text, at2) {
|
|
2677
|
+
let depth = 0;
|
|
2678
|
+
for (let j = at2; j < text.length; j++) {
|
|
2679
|
+
const c = text.charAt(j);
|
|
2680
|
+
if (c === SQ || c === DQ) {
|
|
2681
|
+
const e = quoteEnd(text, j);
|
|
2682
|
+
if (e < 0) return -1;
|
|
2683
|
+
j = e;
|
|
2684
|
+
continue;
|
|
2685
|
+
}
|
|
2686
|
+
if (c === TICK) {
|
|
2687
|
+
j++;
|
|
2688
|
+
continue;
|
|
2689
|
+
}
|
|
2690
|
+
if (OPENERS.includes(c)) depth++;
|
|
2691
|
+
else if (CLOSERS.includes(c) && --depth === 0) return j;
|
|
2692
|
+
}
|
|
2693
|
+
return -1;
|
|
2694
|
+
}
|
|
2695
|
+
function glueEnd(text, from) {
|
|
2696
|
+
let depth = 0;
|
|
2697
|
+
for (let j = from; j < text.length; j++) {
|
|
2698
|
+
const c = text.charAt(j);
|
|
2699
|
+
if (c === SQ || c === DQ) {
|
|
2700
|
+
const e = quoteEnd(text, j);
|
|
2701
|
+
if (e < 0) return text.length;
|
|
2702
|
+
j = e;
|
|
2703
|
+
continue;
|
|
2704
|
+
}
|
|
2705
|
+
if (OPENERS.includes(c)) depth++;
|
|
2706
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
2707
|
+
else if (depth <= 0 && GLUE_END.includes(c)) return j;
|
|
2708
|
+
}
|
|
2709
|
+
return text.length;
|
|
2710
|
+
}
|
|
2711
|
+
function splitArgs(inner) {
|
|
2712
|
+
const parts = [];
|
|
2713
|
+
let depth = 0;
|
|
2714
|
+
let from = 0;
|
|
2715
|
+
for (let j = 0; j < inner.length; j++) {
|
|
2716
|
+
const c = inner.charAt(j);
|
|
2717
|
+
if (c === SQ || c === DQ) {
|
|
2718
|
+
const e = quoteEnd(inner, j);
|
|
2719
|
+
if (e < 0) break;
|
|
2720
|
+
j = e;
|
|
2721
|
+
continue;
|
|
2722
|
+
}
|
|
2723
|
+
if (OPENERS.includes(c)) depth++;
|
|
2724
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
2725
|
+
else if (c === "," && depth === 0) {
|
|
2726
|
+
parts.push(inner.slice(from, j));
|
|
2727
|
+
from = j + 1;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
parts.push(inner.slice(from));
|
|
2731
|
+
return parts;
|
|
2732
|
+
}
|
|
2733
|
+
var isFd = (w) => w !== "" && (w === FD_STAR || [...w].every((ch) => ch >= "0" && ch <= "9"));
|
|
2734
|
+
var fresh = () => ({ words: [], toFile: false, chained: false });
|
|
2735
|
+
function psParse(text) {
|
|
2736
|
+
const statements = [];
|
|
2737
|
+
let stages = [];
|
|
2738
|
+
let stage = fresh();
|
|
2739
|
+
let word = "";
|
|
2740
|
+
let has3 = false;
|
|
2741
|
+
let bare2 = true;
|
|
2742
|
+
let target = null;
|
|
2743
|
+
const n = text.length;
|
|
2744
|
+
const endWord = () => {
|
|
2745
|
+
if (!has3) return;
|
|
2746
|
+
if (target !== null) {
|
|
2747
|
+
if (target === "file") stage.toFile = true;
|
|
2748
|
+
target = null;
|
|
2749
|
+
} else stage.words.push(word);
|
|
2750
|
+
word = "";
|
|
2751
|
+
has3 = false;
|
|
2752
|
+
bare2 = true;
|
|
2753
|
+
};
|
|
2754
|
+
const endStage = () => {
|
|
2755
|
+
endWord();
|
|
2756
|
+
if (stage.words.length > 0 || stage.toFile) stages.push(stage);
|
|
2757
|
+
stage = fresh();
|
|
2758
|
+
};
|
|
2759
|
+
const endStatement = () => {
|
|
2760
|
+
endStage();
|
|
2761
|
+
if (stages.length > 0) statements.push(stages);
|
|
2762
|
+
stages = [];
|
|
2763
|
+
};
|
|
2764
|
+
const grow = (s, quoted) => {
|
|
2765
|
+
word += s;
|
|
2766
|
+
has3 = true;
|
|
2767
|
+
if (quoted) bare2 = false;
|
|
2768
|
+
};
|
|
2769
|
+
let i = 0;
|
|
2770
|
+
while (i < n) {
|
|
2771
|
+
const c = text.charAt(i);
|
|
2772
|
+
const next = text.charAt(i + 1);
|
|
2773
|
+
if (c === SQ || c === DQ) {
|
|
2774
|
+
const e = quoteEnd(text, i);
|
|
2775
|
+
grow(unquote(text.slice(i + 1, e < 0 ? n : e), c), true);
|
|
2776
|
+
i = e < 0 ? n : e + 1;
|
|
2777
|
+
} else if (c === TICK) {
|
|
2778
|
+
if (next !== "\n" && next !== "") grow(next, false);
|
|
2779
|
+
i += PAIR;
|
|
2780
|
+
} else if (c === "\n") {
|
|
2781
|
+
endStatement();
|
|
2782
|
+
i++;
|
|
2783
|
+
} else if (SPACES.includes(c)) {
|
|
2784
|
+
endWord();
|
|
2785
|
+
i++;
|
|
2786
|
+
} else if (c === ";") {
|
|
2787
|
+
endStatement();
|
|
2788
|
+
i++;
|
|
2789
|
+
} else if (c === "|") {
|
|
2790
|
+
if (next === "|") {
|
|
2791
|
+
endStatement();
|
|
2792
|
+
i += PAIR;
|
|
2793
|
+
} else {
|
|
2794
|
+
endStage();
|
|
2795
|
+
i++;
|
|
2796
|
+
}
|
|
2797
|
+
} else if (c === "&") {
|
|
2798
|
+
if (next === "&") {
|
|
2799
|
+
endStatement();
|
|
2800
|
+
i += PAIR;
|
|
2801
|
+
} else {
|
|
2802
|
+
if (has3 || stage.words.length > 0) grow(c, false);
|
|
2803
|
+
i++;
|
|
2804
|
+
}
|
|
2805
|
+
} else if (c === "#" && !has3) {
|
|
2806
|
+
while (i < n && text.charAt(i) !== "\n") i++;
|
|
2807
|
+
} else if (c === ">") {
|
|
2808
|
+
let fd = STDOUT_FD;
|
|
2809
|
+
if (has3 && bare2 && isFd(word)) {
|
|
2810
|
+
fd = word;
|
|
2811
|
+
word = "";
|
|
2812
|
+
has3 = false;
|
|
2813
|
+
} else if (has3) endWord();
|
|
2814
|
+
let j = i + 1;
|
|
2815
|
+
if (text.charAt(j) === ">") j++;
|
|
2816
|
+
if (text.charAt(j) === "&") {
|
|
2817
|
+
j++;
|
|
2818
|
+
while (j < n && !GLUE_END.includes(text.charAt(j))) j++;
|
|
2819
|
+
} else target = fd === STDOUT_FD || fd === FD_STAR ? "file" : "skip";
|
|
2820
|
+
i = j;
|
|
2821
|
+
} else if (c === "(" && has3 && bare2 && word.includes(METHOD_MARK)) {
|
|
2822
|
+
const e = closeOf(text, i);
|
|
2823
|
+
const inner = text.slice(i + 1, e < 0 ? n : e);
|
|
2824
|
+
endWord();
|
|
2825
|
+
for (const a of inner.trim() === "" ? [] : splitArgs(inner)) {
|
|
2826
|
+
const first = psParse(a)[0]?.[0]?.words[0];
|
|
2827
|
+
stage.words.push(first ?? a.trim());
|
|
2828
|
+
}
|
|
2829
|
+
i = e < 0 ? n : e + 1;
|
|
2830
|
+
if (i < n && !GLUE_END.includes(text.charAt(i))) {
|
|
2831
|
+
stage.chained = true;
|
|
2832
|
+
i = glueEnd(text, i);
|
|
2833
|
+
}
|
|
2834
|
+
} else if (c === "[" && !has3 && text.startsWith(METHOD_MARK, closeOf(text, i) + 1) && closeOf(text, i) >= 0) {
|
|
2835
|
+
const e = closeOf(text, i);
|
|
2836
|
+
grow(text.slice(i, e + 1), false);
|
|
2837
|
+
i = e + 1;
|
|
2838
|
+
} else if (OPENERS.includes(c) && (c !== "[" || !has3) || (c === "$" || c === "@") && OPENERS.includes(next) && next !== "[") {
|
|
2839
|
+
const open = c === "$" || c === "@" ? i + 1 : i;
|
|
2840
|
+
const e = closeOf(text, open);
|
|
2841
|
+
grow(text.slice(i, e < 0 ? n : e + 1), true);
|
|
2842
|
+
i = e < 0 ? n : e + 1;
|
|
2843
|
+
} else {
|
|
2844
|
+
grow(c, false);
|
|
2845
|
+
i++;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
endStatement();
|
|
2849
|
+
return statements;
|
|
2850
|
+
}
|
|
2851
|
+
var READ_COMMANDS = ["get-content", "gc", "cat", "type"];
|
|
2852
|
+
var FILE_CLASSES = ["[io.file]::", "[system.io.file]::"];
|
|
2853
|
+
var FILE_READS = ["readalltext", "readalllines", "readallbytes", "readlines"];
|
|
2854
|
+
var PATH_PARAMS = ["path", "literalpath"];
|
|
2855
|
+
var BOUND_PARAMS = ["totalcount", "head", "first", "tail", "last"];
|
|
2856
|
+
var VALUE_PARAMS = [...PATH_PARAMS, ...BOUND_PARAMS, "encoding", "readcount", "delimiter", "filter", "include", "exclude", "stream", "credential"];
|
|
2857
|
+
var SWITCH_PARAMS = ["raw", "wait", "force", "asbytestream"];
|
|
2858
|
+
var ALL_PARAMS = [...VALUE_PARAMS, ...SWITCH_PARAMS];
|
|
2859
|
+
var PASS_THROUGH = ["out-string", "write-output", "echo", "write", "out-host", "write-host", "out-default", "tee-object"];
|
|
2860
|
+
var CD_COMMANDS = ["cd", "chdir", "sl", "set-location", "pushd", "push-location"];
|
|
2861
|
+
var POWERSHELLS = ["powershell", "powershell.exe", "pwsh", "pwsh.exe"];
|
|
2862
|
+
var CMDS = ["cmd", "cmd.exe"];
|
|
2863
|
+
var CMD_RUN_FLAGS = ["/c", "/k", "/r"];
|
|
2864
|
+
var COMMAND_PARAM = "command";
|
|
2865
|
+
var DASH = "-";
|
|
2866
|
+
function cmdName(word) {
|
|
2867
|
+
const k = Math.max(word.lastIndexOf("\\"), word.lastIndexOf("/"));
|
|
2868
|
+
return (k >= 0 && k < word.length - 1 ? word.slice(k + 1) : word).toLowerCase();
|
|
2869
|
+
}
|
|
2870
|
+
function param(word, names) {
|
|
2871
|
+
const body = word.slice(DASH.length);
|
|
2872
|
+
const colon = body.indexOf(":");
|
|
2873
|
+
const name = (colon < 0 ? body : body.slice(0, colon)).toLowerCase();
|
|
2874
|
+
const inline = colon < 0 ? void 0 : body.slice(colon + 1);
|
|
2875
|
+
if (name === "") return { full: void 0, inline };
|
|
2876
|
+
if (names.includes(name)) return { full: name, inline };
|
|
2877
|
+
const hits = names.filter((p) => p.startsWith(name));
|
|
2878
|
+
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
2879
|
+
}
|
|
2880
|
+
function psDump(words) {
|
|
2881
|
+
if (words.length === 0) return null;
|
|
2882
|
+
const name = cmdName(words[0]);
|
|
2883
|
+
if (!READ_COMMANDS.includes(name)) {
|
|
2884
|
+
const lower = words[0].toLowerCase();
|
|
2885
|
+
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
2886
|
+
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words.length < MIN_STATIC_CALL) return null;
|
|
2887
|
+
return { file: words[1], bounded: false };
|
|
2888
|
+
}
|
|
2889
|
+
const files = [];
|
|
2890
|
+
let bounded = false;
|
|
2891
|
+
for (let k = 1; k < words.length; k++) {
|
|
2892
|
+
const a = words[k];
|
|
2893
|
+
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
2894
|
+
files.push(a);
|
|
2895
|
+
continue;
|
|
2896
|
+
}
|
|
2897
|
+
const p = param(a, ALL_PARAMS);
|
|
2898
|
+
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
2899
|
+
const value = p.inline ?? words[++k];
|
|
2900
|
+
if (value === void 0) return null;
|
|
2901
|
+
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
2902
|
+
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
2903
|
+
}
|
|
2904
|
+
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
2905
|
+
}
|
|
2906
|
+
function nestedScript(name, words) {
|
|
2907
|
+
if (POWERSHELLS.includes(name)) {
|
|
2908
|
+
for (let k = 1; k < words.length; k++) {
|
|
2909
|
+
const w = words[k];
|
|
2910
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
2911
|
+
const p = param(w, [COMMAND_PARAM]);
|
|
2912
|
+
if (p.full === void 0) continue;
|
|
2913
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words.slice(k + 1)].join(" ");
|
|
2914
|
+
}
|
|
2915
|
+
return null;
|
|
2916
|
+
}
|
|
2917
|
+
if (CMDS.includes(name)) {
|
|
2918
|
+
for (let k = 1; k < words.length; k++) {
|
|
2919
|
+
if (CMD_RUN_FLAGS.includes(words[k].toLowerCase())) return words.slice(k + 1).join(" ");
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
return null;
|
|
2923
|
+
}
|
|
2924
|
+
function cdTarget(words) {
|
|
2925
|
+
for (let k = 1; k < words.length; k++) {
|
|
2926
|
+
const w = words[k];
|
|
2927
|
+
if (w.toLowerCase() === "/d") continue;
|
|
2928
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
2929
|
+
const p = param(w, PATH_PARAMS);
|
|
2930
|
+
if (p.full !== void 0) return p.inline ?? words[k + 1] ?? null;
|
|
2931
|
+
}
|
|
2932
|
+
return null;
|
|
2933
|
+
}
|
|
2934
|
+
function walk(script, cwd, depth, found) {
|
|
2935
|
+
let dir = cwd;
|
|
2936
|
+
for (const stages of psParse(script)) {
|
|
2937
|
+
const head = stages[0];
|
|
2938
|
+
if (head.words.length === 0) continue;
|
|
2939
|
+
const name = cmdName(head.words[0]);
|
|
2940
|
+
if (stages.length === 1 && CD_COMMANDS.includes(name)) {
|
|
2941
|
+
const t = cdTarget(head.words);
|
|
2942
|
+
if (t !== null) dir = resolve(dir, t);
|
|
2943
|
+
continue;
|
|
2944
|
+
}
|
|
2945
|
+
const inner = depth < MAX_NEST_DEPTH ? nestedScript(name, head.words) : null;
|
|
2946
|
+
if (inner !== null) {
|
|
2947
|
+
walk(inner, dir, depth + 1, found);
|
|
2948
|
+
continue;
|
|
2949
|
+
}
|
|
2950
|
+
if (head.toFile || head.chained) continue;
|
|
2951
|
+
const d = psDump(head.words);
|
|
2952
|
+
if (d === null || d.bounded) continue;
|
|
2953
|
+
let shown2 = true;
|
|
2954
|
+
for (let k = 1; k < stages.length; k++) {
|
|
2955
|
+
if (stages[k].toFile || !PASS_THROUGH.includes(cmdName(stages[k].words[0] ?? ""))) {
|
|
2956
|
+
shown2 = false;
|
|
2957
|
+
break;
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
if (shown2) found.push(resolve(dir, d.file));
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
function psDumpFiles(script, cwd) {
|
|
2964
|
+
const found = [];
|
|
2965
|
+
walk(script, cwd, 0, found);
|
|
2966
|
+
return found;
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2627
2969
|
// src/core/policy/subagent.ts
|
|
2628
2970
|
import { join as join2 } from "node:path";
|
|
2629
2971
|
|
|
@@ -2835,16 +3177,16 @@ function readList(body, key) {
|
|
|
2835
3177
|
for (let j = i + 1; j < body.length; j++) {
|
|
2836
3178
|
const t = body[j].trim();
|
|
2837
3179
|
if (!t.startsWith("-")) break;
|
|
2838
|
-
items.push(
|
|
3180
|
+
items.push(unquote2(t.slice(1).trim()));
|
|
2839
3181
|
}
|
|
2840
3182
|
return items.filter((s) => s !== "");
|
|
2841
3183
|
}
|
|
2842
3184
|
if (value.startsWith("[") && value.endsWith("]")) value = value.slice(1, -1);
|
|
2843
|
-
return value.split(",").map((s) =>
|
|
3185
|
+
return value.split(",").map((s) => unquote2(s.trim())).filter((s) => s !== "");
|
|
2844
3186
|
}
|
|
2845
3187
|
return null;
|
|
2846
3188
|
}
|
|
2847
|
-
function
|
|
3189
|
+
function unquote2(s) {
|
|
2848
3190
|
if (s.length > 1 && (s[0] === '"' || s[0] === "'") && s.endsWith(s[0])) return s.slice(1, -1);
|
|
2849
3191
|
return s;
|
|
2850
3192
|
}
|
|
@@ -3246,7 +3588,7 @@ function readPath(input) {
|
|
|
3246
3588
|
}
|
|
3247
3589
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
3248
3590
|
if (rules.length === 0) return null;
|
|
3249
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
3591
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve2(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
3250
3592
|
if (canonical === BASH) {
|
|
3251
3593
|
const cmd = str(input.command);
|
|
3252
3594
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -3298,7 +3640,7 @@ function webFetch(input, row5) {
|
|
|
3298
3640
|
function bash(ev, row5, input, rules) {
|
|
3299
3641
|
const cmd = str(input.command) ?? "";
|
|
3300
3642
|
const parsed = parseShell(cmd);
|
|
3301
|
-
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : ALLOW;
|
|
3643
|
+
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
|
|
3302
3644
|
const cmds = unwrap(parsed.commands);
|
|
3303
3645
|
for (const c of cmds) {
|
|
3304
3646
|
const h = segmentHit(c, rules);
|
|
@@ -3310,7 +3652,7 @@ function bash(ev, row5, input, rules) {
|
|
|
3310
3652
|
if (kind !== null) return deny(denyMessage(kind, cmd, row5, str(input.description)));
|
|
3311
3653
|
}
|
|
3312
3654
|
}
|
|
3313
|
-
return shellDump(cmds, ev.cwd, row5) ?? ALLOW;
|
|
3655
|
+
return shellDump(cmds, ev.cwd, row5) ?? psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
|
|
3314
3656
|
}
|
|
3315
3657
|
function denyKind(c) {
|
|
3316
3658
|
const name = c.argv0.toLowerCase();
|
|
@@ -3357,7 +3699,7 @@ function read(ev, row5, input) {
|
|
|
3357
3699
|
if (!present(input.offset) && !present(input.limit)) {
|
|
3358
3700
|
const p = readPath(input);
|
|
3359
3701
|
if (p !== void 0) {
|
|
3360
|
-
const abs =
|
|
3702
|
+
const abs = resolve2(ev.cwd, p);
|
|
3361
3703
|
const size = fileSize(abs);
|
|
3362
3704
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3363
3705
|
}
|
|
@@ -3370,7 +3712,7 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3370
3712
|
let verdict = null;
|
|
3371
3713
|
for (const c of cmds) {
|
|
3372
3714
|
const name = c.argv0.toLowerCase();
|
|
3373
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
3715
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve2(dir, c.args[0]);
|
|
3374
3716
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
3375
3717
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
3376
3718
|
const d = dumpTarget(name, c.args);
|
|
@@ -3379,12 +3721,20 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3379
3721
|
verdict = ALLOW;
|
|
3380
3722
|
continue;
|
|
3381
3723
|
}
|
|
3382
|
-
const abs =
|
|
3724
|
+
const abs = resolve2(dir, d.file);
|
|
3383
3725
|
const size = fileSize(abs);
|
|
3384
3726
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3385
3727
|
}
|
|
3386
3728
|
return verdict;
|
|
3387
3729
|
}
|
|
3730
|
+
function psShellDump(cmd, cwd, row5) {
|
|
3731
|
+
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
3732
|
+
for (const abs of psDumpFiles(cmd, cwd)) {
|
|
3733
|
+
const size = fileSize(abs);
|
|
3734
|
+
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3735
|
+
}
|
|
3736
|
+
return null;
|
|
3737
|
+
}
|
|
3388
3738
|
var allDigits2 = (s) => s !== "" && [...s].every((ch) => ch >= "0" && ch <= "9");
|
|
3389
3739
|
function countFlag(a) {
|
|
3390
3740
|
if (has(DUMP_COUNT_FLAGS, a)) return 1;
|
|
@@ -3442,7 +3792,7 @@ function dumpTarget(name, args) {
|
|
|
3442
3792
|
}
|
|
3443
3793
|
|
|
3444
3794
|
// src/core/project/resolve.ts
|
|
3445
|
-
import { basename, dirname as dirname2, join as join4, resolve as
|
|
3795
|
+
import { basename, dirname as dirname2, join as join4, resolve as resolve3 } from "node:path";
|
|
3446
3796
|
|
|
3447
3797
|
// src/core/project/contain.ts
|
|
3448
3798
|
import { dirname, sep as sep2 } from "node:path";
|
|
@@ -3649,7 +3999,7 @@ function gitDirs(dir) {
|
|
|
3649
3999
|
const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
|
|
3650
4000
|
if (gitDir !== null) {
|
|
3651
4001
|
const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
|
|
3652
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
4002
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve3(gitDir, common)), worktree: cur, start };
|
|
3653
4003
|
}
|
|
3654
4004
|
const up = dirname2(cur);
|
|
3655
4005
|
if (up === cur) return { commonDir: null, start };
|
|
@@ -3664,7 +4014,7 @@ function gitDirAt(dotGit) {
|
|
|
3664
4014
|
} else {
|
|
3665
4015
|
const line = firstLine(dotGit);
|
|
3666
4016
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
3667
|
-
gitDir =
|
|
4017
|
+
gitDir = resolve3(dirname2(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
3668
4018
|
}
|
|
3669
4019
|
} catch {
|
|
3670
4020
|
return null;
|
|
@@ -7605,7 +7955,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
7605
7955
|
}
|
|
7606
7956
|
|
|
7607
7957
|
// src/core/hooks/fallback.ts
|
|
7608
|
-
import { join as join5, resolve as
|
|
7958
|
+
import { join as join5, resolve as resolve4 } from "node:path";
|
|
7609
7959
|
var fs = process.getBuiltinModule("node:fs");
|
|
7610
7960
|
function isRec(v) {
|
|
7611
7961
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -7720,7 +8070,7 @@ function bigRead(input, cwd) {
|
|
|
7720
8070
|
const p = firstString(input, READ_PATH_KEYS);
|
|
7721
8071
|
if (p === "") return false;
|
|
7722
8072
|
try {
|
|
7723
|
-
const st = fs.statSync(
|
|
8073
|
+
const st = fs.statSync(resolve4(cwd, p));
|
|
7724
8074
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
7725
8075
|
} catch {
|
|
7726
8076
|
return false;
|
|
@@ -19472,10 +19822,10 @@ function startArgv(argv) {
|
|
|
19472
19822
|
return sh === null ? null : [sh, ...argv];
|
|
19473
19823
|
}
|
|
19474
19824
|
function runProcess(argv, o) {
|
|
19475
|
-
return new Promise((
|
|
19825
|
+
return new Promise((resolve7) => {
|
|
19476
19826
|
const isWin2 = process.platform === "win32";
|
|
19477
19827
|
const start = startArgv(argv);
|
|
19478
|
-
if (start === null) return
|
|
19828
|
+
if (start === null) return resolve7(NOT_STARTED);
|
|
19479
19829
|
let child;
|
|
19480
19830
|
try {
|
|
19481
19831
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -19489,7 +19839,7 @@ function runProcess(argv, o) {
|
|
|
19489
19839
|
windowsHide: true
|
|
19490
19840
|
});
|
|
19491
19841
|
} catch {
|
|
19492
|
-
return
|
|
19842
|
+
return resolve7(NOT_STARTED);
|
|
19493
19843
|
}
|
|
19494
19844
|
const stdoutChunks = [];
|
|
19495
19845
|
const stderrChunks = [];
|
|
@@ -19514,7 +19864,7 @@ function runProcess(argv, o) {
|
|
|
19514
19864
|
settled = true;
|
|
19515
19865
|
clearTimeout(timer);
|
|
19516
19866
|
o.signal.removeEventListener("abort", onAbort);
|
|
19517
|
-
|
|
19867
|
+
resolve7({
|
|
19518
19868
|
stdout: Buffer.concat(stdoutChunks),
|
|
19519
19869
|
stderr: Buffer.concat(stderrChunks),
|
|
19520
19870
|
exitCode,
|
|
@@ -19981,10 +20331,11 @@ var ctxBatch = Object.freeze({
|
|
|
19981
20331
|
});
|
|
19982
20332
|
|
|
19983
20333
|
// src/core/tools/doctor.ts
|
|
19984
|
-
import { readdirSync as
|
|
20334
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync11 } from "node:fs";
|
|
19985
20335
|
import { basename as basename3, dirname as dirname6, join as join13 } from "node:path";
|
|
19986
20336
|
|
|
19987
20337
|
// src/core/ops/doctor-config.ts
|
|
20338
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
19988
20339
|
import { join as join11 } from "node:path";
|
|
19989
20340
|
|
|
19990
20341
|
// src/core/ops/detect-v1.ts
|
|
@@ -23019,7 +23370,47 @@ function mcpFile(row5, home, env) {
|
|
|
23019
23370
|
}
|
|
23020
23371
|
return null;
|
|
23021
23372
|
}
|
|
23373
|
+
var CODEX_PLUGIN_KEY = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
23374
|
+
var CODEX_PLUGIN_SUBDIR = ".codex-plugin";
|
|
23375
|
+
var CODEX_PLUGIN_MCP_FILE = "mcp.json";
|
|
23376
|
+
var CODEX_PLUGIN_HOOKS_FILE = "hooks.json";
|
|
23377
|
+
var MCP_SERVERS_FIELD = "mcpServers";
|
|
23378
|
+
function codexNativeDir(env, home) {
|
|
23379
|
+
const codexDir = codexDirOf(env, home);
|
|
23380
|
+
let enabled;
|
|
23381
|
+
try {
|
|
23382
|
+
enabled = hostConfigValueAt(readParsed("codex", join11(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
23383
|
+
} catch {
|
|
23384
|
+
return null;
|
|
23385
|
+
}
|
|
23386
|
+
if (enabled !== true) return null;
|
|
23387
|
+
const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
23388
|
+
if (!existsSync6(cache)) return null;
|
|
23389
|
+
const found = [];
|
|
23390
|
+
for (const market of readdirSync3(cache)) {
|
|
23391
|
+
const plugin = join11(cache, market, SERVER_KEY);
|
|
23392
|
+
if (!existsSync6(plugin)) continue;
|
|
23393
|
+
for (const version2 of readdirSync3(plugin).sort()) {
|
|
23394
|
+
const dir = join11(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
23395
|
+
if (existsSync6(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
23396
|
+
}
|
|
23397
|
+
}
|
|
23398
|
+
return found.length === 0 ? null : found[found.length - 1];
|
|
23399
|
+
}
|
|
23400
|
+
function nativeMcpWrong(dir, row5) {
|
|
23401
|
+
try {
|
|
23402
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join11(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
23403
|
+
if (!isObject4(entry)) return true;
|
|
23404
|
+
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
23405
|
+
const script = args[0];
|
|
23406
|
+
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;
|
|
23407
|
+
} catch {
|
|
23408
|
+
return true;
|
|
23409
|
+
}
|
|
23410
|
+
}
|
|
23022
23411
|
function mcpWrong(row5, home, env) {
|
|
23412
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23413
|
+
if (native !== null) return nativeMcpWrong(native, row5);
|
|
23023
23414
|
const file2 = mcpFile(row5, home, env);
|
|
23024
23415
|
try {
|
|
23025
23416
|
if (file2 === null) {
|
|
@@ -23038,7 +23429,8 @@ function hookParts(row5, home, env, worktree) {
|
|
|
23038
23429
|
let block;
|
|
23039
23430
|
try {
|
|
23040
23431
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
|
|
23041
|
-
const
|
|
23432
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23433
|
+
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
23434
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
23043
23435
|
if (row5.id === "codex") {
|
|
23044
23436
|
const config2 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -23101,7 +23493,7 @@ function checkDoubleFire(agent, worktree) {
|
|
|
23101
23493
|
}
|
|
23102
23494
|
|
|
23103
23495
|
// src/core/ops/doctor-db.ts
|
|
23104
|
-
import { existsSync as
|
|
23496
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
23105
23497
|
var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
23106
23498
|
var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
23107
23499
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -23141,7 +23533,7 @@ function failsOnCorrupt(step) {
|
|
|
23141
23533
|
}
|
|
23142
23534
|
async function checkDb(project) {
|
|
23143
23535
|
const clean = { schemaStale: false, integrityFailed: false };
|
|
23144
|
-
if (!
|
|
23536
|
+
if (!existsSync7(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
23145
23537
|
const sqlite = await loadSqlite2();
|
|
23146
23538
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
23147
23539
|
let raw = null;
|
|
@@ -23167,7 +23559,7 @@ async function checkDb(project) {
|
|
|
23167
23559
|
}
|
|
23168
23560
|
}
|
|
23169
23561
|
async function checkIndex(project) {
|
|
23170
|
-
if (!
|
|
23562
|
+
if (!existsSync7(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
23171
23563
|
const sqlite = await loadSqlite2();
|
|
23172
23564
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
23173
23565
|
let raw = null;
|
|
@@ -23184,7 +23576,7 @@ async function checkIndex(project) {
|
|
|
23184
23576
|
}
|
|
23185
23577
|
|
|
23186
23578
|
// src/core/ops/doctor-env.ts
|
|
23187
|
-
import { existsSync as
|
|
23579
|
+
import { existsSync as existsSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
23188
23580
|
import { isAbsolute as isAbsolute3, relative as relative2 } from "node:path";
|
|
23189
23581
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
23190
23582
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
@@ -23242,7 +23634,7 @@ function checkMcp(ctx) {
|
|
|
23242
23634
|
return named || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
23243
23635
|
}
|
|
23244
23636
|
function piCwdInside(worktree, piCwd) {
|
|
23245
|
-
if (piCwd === void 0 || !
|
|
23637
|
+
if (piCwd === void 0 || !existsSync8(piCwd)) return false;
|
|
23246
23638
|
const rel = relative2(worktree, realpathSync5.native(piCwd));
|
|
23247
23639
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
23248
23640
|
}
|
|
@@ -23263,15 +23655,16 @@ function checkShell(env) {
|
|
|
23263
23655
|
}
|
|
23264
23656
|
|
|
23265
23657
|
// src/core/ops/doctor-hook.ts
|
|
23266
|
-
import { existsSync as
|
|
23658
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9 } from "node:fs";
|
|
23267
23659
|
import path4 from "node:path";
|
|
23660
|
+
var D5_SAMPLES = 3;
|
|
23268
23661
|
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
23662
|
function isObject5(v) {
|
|
23270
23663
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23271
23664
|
}
|
|
23272
23665
|
function loadFixture(bundleDir2, agent) {
|
|
23273
23666
|
const file2 = path4.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
23274
|
-
if (!
|
|
23667
|
+
if (!existsSync9(file2)) return null;
|
|
23275
23668
|
let all;
|
|
23276
23669
|
try {
|
|
23277
23670
|
all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
|
|
@@ -23283,6 +23676,9 @@ function loadFixture(bundleDir2, agent) {
|
|
|
23283
23676
|
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) return null;
|
|
23284
23677
|
return { event: e.event, payload: e.payload };
|
|
23285
23678
|
}
|
|
23679
|
+
function payloadFor(payload, worktree) {
|
|
23680
|
+
return worktree !== void 0 && isObject5(payload) ? { ...payload, cwd: worktree } : payload;
|
|
23681
|
+
}
|
|
23286
23682
|
function isNativeShape(stdout, exitCode, killed, event) {
|
|
23287
23683
|
if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
|
|
23288
23684
|
if (stdout.length === 0) return true;
|
|
@@ -23299,31 +23695,43 @@ function codexHookJournaled(db) {
|
|
|
23299
23695
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
23300
23696
|
}
|
|
23301
23697
|
async function checkHookRoundTrip(i) {
|
|
23302
|
-
if (i.agent === "codex" &&
|
|
23698
|
+
if (i.agent === "codex" && existsSync9(path4.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
23303
23699
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
23304
23700
|
}
|
|
23305
23701
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
23306
23702
|
if (fixture === null) return row("UNKNOWN", D5_NO_FIXTURE_DETAIL(i.agent));
|
|
23307
23703
|
const now = i.now ?? (() => performance.now());
|
|
23308
|
-
const
|
|
23309
|
-
const
|
|
23310
|
-
|
|
23311
|
-
env: i.env,
|
|
23312
|
-
|
|
23313
|
-
timeoutMs: HOOK_TIMEOUT_MS,
|
|
23314
|
-
stdin: JSON.stringify(fixture.payload)
|
|
23704
|
+
const samples = Math.max(1, i.samples ?? D5_SAMPLES);
|
|
23705
|
+
const bareMs = i.bareMs ?? (async () => {
|
|
23706
|
+
const t = performance.now();
|
|
23707
|
+
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs: HOOK_TIMEOUT_MS });
|
|
23708
|
+
return performance.now() - t;
|
|
23315
23709
|
});
|
|
23316
|
-
const
|
|
23317
|
-
|
|
23710
|
+
const hookWalls = [];
|
|
23711
|
+
const bareWalls = [];
|
|
23712
|
+
for (let n = 0; n < samples; n++) {
|
|
23713
|
+
const start = now();
|
|
23714
|
+
const r = await runProcess([process.execPath, path4.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
23715
|
+
cwd: i.bundleDir,
|
|
23716
|
+
env: i.env,
|
|
23717
|
+
signal: i.signal,
|
|
23718
|
+
timeoutMs: HOOK_TIMEOUT_MS,
|
|
23719
|
+
stdin: JSON.stringify(payloadFor(fixture.payload, i.worktree))
|
|
23720
|
+
});
|
|
23721
|
+
hookWalls.push(now() - start);
|
|
23722
|
+
if (!isNativeShape(r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
23723
|
+
bareWalls.push(await bareMs());
|
|
23724
|
+
}
|
|
23725
|
+
const ms = Math.max(0, Math.round(Math.min(...hookWalls) - Math.min(...bareWalls)));
|
|
23318
23726
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
23319
23727
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
23320
23728
|
}
|
|
23321
23729
|
|
|
23322
23730
|
// src/core/ops/db-heal.ts
|
|
23323
|
-
import { existsSync as
|
|
23731
|
+
import { existsSync as existsSync10, rmSync as rmSync3 } from "node:fs";
|
|
23324
23732
|
|
|
23325
23733
|
// src/core/store/owners.ts
|
|
23326
|
-
import { mkdirSync as mkdirSync4, readdirSync as
|
|
23734
|
+
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23327
23735
|
import { basename as basename2, join as join12 } from "node:path";
|
|
23328
23736
|
function ownersDir(configDir, projectKey) {
|
|
23329
23737
|
return join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -23346,7 +23754,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
23346
23754
|
const dir = ownersDir(configDir, projectKey);
|
|
23347
23755
|
let names;
|
|
23348
23756
|
try {
|
|
23349
|
-
names =
|
|
23757
|
+
names = readdirSync4(dir);
|
|
23350
23758
|
} catch (err) {
|
|
23351
23759
|
if (errCode2(err) === "ENOENT") return [];
|
|
23352
23760
|
throw err;
|
|
@@ -23403,7 +23811,7 @@ function renameAside(dbPath) {
|
|
|
23403
23811
|
const ts = String(Date.now());
|
|
23404
23812
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
23405
23813
|
const file2 = dbPath + suffix;
|
|
23406
|
-
if (
|
|
23814
|
+
if (existsSync10(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
23407
23815
|
}
|
|
23408
23816
|
return ts;
|
|
23409
23817
|
}
|
|
@@ -23484,7 +23892,7 @@ async function guard(id2, run) {
|
|
|
23484
23892
|
}
|
|
23485
23893
|
}
|
|
23486
23894
|
async function codexDb(ctx, adapter) {
|
|
23487
|
-
if (adapter.id !== "codex" || !
|
|
23895
|
+
if (adapter.id !== "codex" || !existsSync11(ctx.project.dbPath)) return null;
|
|
23488
23896
|
try {
|
|
23489
23897
|
return await openDb(ctx.project, { readOnly: true });
|
|
23490
23898
|
} catch {
|
|
@@ -23493,8 +23901,10 @@ async function codexDb(ctx, adapter) {
|
|
|
23493
23901
|
}
|
|
23494
23902
|
async function hookRow(ctx, adapter, host) {
|
|
23495
23903
|
const db = await codexDb(ctx, adapter);
|
|
23904
|
+
const runStart = Date.now();
|
|
23496
23905
|
try {
|
|
23497
23906
|
const row5 = await checkHookRoundTrip({
|
|
23907
|
+
worktree: ctx.project.worktree,
|
|
23498
23908
|
agent: adapter.id,
|
|
23499
23909
|
bundleDir: host.bundleDir,
|
|
23500
23910
|
env: buildChildEnv(host.env),
|
|
@@ -23504,15 +23914,17 @@ async function hookRow(ctx, adapter, host) {
|
|
|
23504
23914
|
db
|
|
23505
23915
|
});
|
|
23506
23916
|
const last2 = lastHookError(host.env);
|
|
23507
|
-
|
|
23917
|
+
if (last2 === null) return row5;
|
|
23918
|
+
const text = Date.parse(last2.ts) >= runStart ? D5_LAST_HOOK_ERROR : D5_PAST_HOOK_ERROR;
|
|
23919
|
+
return { ...row5, detail: row5.detail + text(last2.ts, last2.stage, last2.label) };
|
|
23508
23920
|
} finally {
|
|
23509
23921
|
if (db !== null) closeDb(db);
|
|
23510
23922
|
}
|
|
23511
23923
|
}
|
|
23512
23924
|
function ownServerId(configDir, projectKey) {
|
|
23513
23925
|
const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23514
|
-
if (!
|
|
23515
|
-
for (const name of
|
|
23926
|
+
if (!existsSync11(dir)) return "";
|
|
23927
|
+
for (const name of readdirSync5(dir)) {
|
|
23516
23928
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
23517
23929
|
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
|
|
23518
23930
|
}
|
|
@@ -23586,9 +23998,9 @@ var ctxDoctor = Object.freeze({
|
|
|
23586
23998
|
});
|
|
23587
23999
|
|
|
23588
24000
|
// src/core/tools/execute.ts
|
|
23589
|
-
import { existsSync as
|
|
24001
|
+
import { existsSync as existsSync12, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
23590
24002
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
23591
|
-
import { dirname as dirname7, join as join14, parse as parse3, resolve as
|
|
24003
|
+
import { dirname as dirname7, join as join14, parse as parse3, resolve as resolve5 } from "node:path";
|
|
23592
24004
|
|
|
23593
24005
|
// src/core/sandbox/win-build.ts
|
|
23594
24006
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -23672,7 +24084,7 @@ function schemaLine(issue2) {
|
|
|
23672
24084
|
}
|
|
23673
24085
|
function fileError(given, abs, root) {
|
|
23674
24086
|
let dir = abs;
|
|
23675
|
-
while (!
|
|
24087
|
+
while (!existsSync12(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
|
|
23676
24088
|
if (isInside(root, dir)) return null;
|
|
23677
24089
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
23678
24090
|
}
|
|
@@ -23734,7 +24146,7 @@ async function handler3(raw, ctx) {
|
|
|
23734
24146
|
const cwd = ctx.project.worktree;
|
|
23735
24147
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
23736
24148
|
if (input.file !== void 0) {
|
|
23737
|
-
const abs =
|
|
24149
|
+
const abs = resolve5(cwd, input.file);
|
|
23738
24150
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
23739
24151
|
if (bad !== null) return fail5(bad);
|
|
23740
24152
|
extra.CTX_FILE = abs;
|
|
@@ -23787,11 +24199,11 @@ var ctxExecute = {
|
|
|
23787
24199
|
};
|
|
23788
24200
|
|
|
23789
24201
|
// src/core/tools/index.ts
|
|
23790
|
-
import { existsSync as
|
|
23791
|
-
import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as
|
|
24202
|
+
import { existsSync as existsSync13, readFileSync as readFileSync13, statSync as statSync6 } from "node:fs";
|
|
24203
|
+
import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as resolve6 } from "node:path";
|
|
23792
24204
|
|
|
23793
24205
|
// src/core/index/walk.ts
|
|
23794
|
-
import { readdirSync as
|
|
24206
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync6, statSync as statSync5 } from "node:fs";
|
|
23795
24207
|
import { join as join15 } from "node:path";
|
|
23796
24208
|
var GITIGNORE = ".gitignore";
|
|
23797
24209
|
var GIT_DIR = ".git";
|
|
@@ -23806,7 +24218,7 @@ function walkDir(root, containmentRoot) {
|
|
|
23806
24218
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
23807
24219
|
let entries;
|
|
23808
24220
|
try {
|
|
23809
|
-
entries =
|
|
24221
|
+
entries = readdirSync6(abs, { withFileTypes: true });
|
|
23810
24222
|
} catch {
|
|
23811
24223
|
return;
|
|
23812
24224
|
}
|
|
@@ -24030,18 +24442,18 @@ function request(u, conn, proxy, signal) {
|
|
|
24030
24442
|
const host = bare(u.hostname);
|
|
24031
24443
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
24032
24444
|
const path5 = u.pathname + u.search;
|
|
24033
|
-
return new Promise((
|
|
24445
|
+
return new Promise((resolve7, reject) => {
|
|
24034
24446
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
24035
24447
|
if (proxy === void 0) {
|
|
24036
24448
|
const mod = u.protocol === "https:" ? https : http;
|
|
24037
24449
|
const req = mod.request({ host: conn.address, port, path: path5, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
24038
|
-
req.on("response",
|
|
24450
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24039
24451
|
return;
|
|
24040
24452
|
}
|
|
24041
24453
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
24042
24454
|
if (u.protocol === "http:") {
|
|
24043
24455
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
24044
|
-
req.on("response",
|
|
24456
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24045
24457
|
return;
|
|
24046
24458
|
}
|
|
24047
24459
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -24061,16 +24473,16 @@ function request(u, conn, proxy, signal) {
|
|
|
24061
24473
|
headers: { host: u.host },
|
|
24062
24474
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
24063
24475
|
});
|
|
24064
|
-
req.on("response",
|
|
24476
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24065
24477
|
});
|
|
24066
24478
|
tunnel.end();
|
|
24067
24479
|
});
|
|
24068
24480
|
}
|
|
24069
24481
|
function readBody(res) {
|
|
24070
|
-
return new Promise((
|
|
24482
|
+
return new Promise((resolve7, reject) => {
|
|
24071
24483
|
const parts = [];
|
|
24072
24484
|
res.on("data", (b) => parts.push(b));
|
|
24073
|
-
res.on("end", () =>
|
|
24485
|
+
res.on("end", () => resolve7(Buffer.concat(parts)));
|
|
24074
24486
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
24075
24487
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
24076
24488
|
});
|
|
@@ -27792,17 +28204,17 @@ function list3(st, el) {
|
|
|
27792
28204
|
n += 1;
|
|
27793
28205
|
st.w.line();
|
|
27794
28206
|
st.w.push(marker, " ".repeat(marker.length));
|
|
27795
|
-
for (const k of c.children)
|
|
28207
|
+
for (const k of c.children) walk2(st, k);
|
|
27796
28208
|
st.w.pop();
|
|
27797
28209
|
st.w.line();
|
|
27798
28210
|
} else {
|
|
27799
|
-
|
|
28211
|
+
walk2(st, c);
|
|
27800
28212
|
}
|
|
27801
28213
|
}
|
|
27802
28214
|
if (st.w.depth() === 0) st.w.block();
|
|
27803
28215
|
else st.w.line();
|
|
27804
28216
|
}
|
|
27805
|
-
function
|
|
28217
|
+
function walk2(st, node) {
|
|
27806
28218
|
if (isText2(node)) {
|
|
27807
28219
|
st.w.text(collapse(node.data));
|
|
27808
28220
|
return;
|
|
@@ -27842,7 +28254,7 @@ function walk(st, node) {
|
|
|
27842
28254
|
case "blockquote":
|
|
27843
28255
|
st.w.block();
|
|
27844
28256
|
st.w.push("> ", "> ");
|
|
27845
|
-
for (const c of node.children)
|
|
28257
|
+
for (const c of node.children) walk2(st, c);
|
|
27846
28258
|
st.w.pop();
|
|
27847
28259
|
st.w.block();
|
|
27848
28260
|
return;
|
|
@@ -27865,7 +28277,7 @@ function walk(st, node) {
|
|
|
27865
28277
|
const line = LINE.has(name);
|
|
27866
28278
|
if (para) st.w.block();
|
|
27867
28279
|
else if (line) st.w.line();
|
|
27868
|
-
for (const c of node.children)
|
|
28280
|
+
for (const c of node.children) walk2(st, c);
|
|
27869
28281
|
if (para) st.w.block();
|
|
27870
28282
|
else if (line) st.w.line();
|
|
27871
28283
|
}
|
|
@@ -27903,7 +28315,7 @@ function htmlToReadable(html, baseUrl) {
|
|
|
27903
28315
|
base = void 0;
|
|
27904
28316
|
}
|
|
27905
28317
|
const st = { w: new Writer(), base, sawH1: false };
|
|
27906
|
-
for (const n of contentRoot(doc.children))
|
|
28318
|
+
for (const n of contentRoot(doc.children)) walk2(st, n);
|
|
27907
28319
|
const body = st.w.result();
|
|
27908
28320
|
const words = wordCount(body);
|
|
27909
28321
|
const text = !st.sawH1 && title !== "" && words > 0 ? "# " + title + "\n\n" + body : body;
|
|
@@ -27943,12 +28355,12 @@ function readUtf8(absPath) {
|
|
|
27943
28355
|
}
|
|
27944
28356
|
function missingOrOutside(given, abs, root) {
|
|
27945
28357
|
let dir = abs;
|
|
27946
|
-
while (!
|
|
28358
|
+
while (!existsSync13(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
27947
28359
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
27948
28360
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
27949
28361
|
}
|
|
27950
28362
|
function pathItems(input, project) {
|
|
27951
|
-
const abs =
|
|
28363
|
+
const abs = resolve6(project.worktree, input.path);
|
|
27952
28364
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
27953
28365
|
const base = relative3(project.worktree, abs);
|
|
27954
28366
|
if (statSync6(abs).isDirectory()) {
|
|
@@ -28210,11 +28622,11 @@ var ctxStats = Object.freeze({
|
|
|
28210
28622
|
});
|
|
28211
28623
|
|
|
28212
28624
|
// src/core/tools/upgrade.ts
|
|
28213
|
-
import { existsSync as
|
|
28625
|
+
import { existsSync as existsSync19, realpathSync as realpathSync7, rmSync as rmSync9 } from "node:fs";
|
|
28214
28626
|
import { basename as basename5, dirname as dirname10, join as join22 } from "node:path";
|
|
28215
28627
|
|
|
28216
28628
|
// src/core/ops/host-write.ts
|
|
28217
|
-
import { copyFileSync, existsSync as
|
|
28629
|
+
import { copyFileSync, existsSync as existsSync14, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28218
28630
|
import { dirname as dirname9, join as join17 } from "node:path";
|
|
28219
28631
|
function defaultWrite(file2, text) {
|
|
28220
28632
|
writeFileSync4(file2, text, "utf8");
|
|
@@ -28243,7 +28655,7 @@ function toRow(file2, edit) {
|
|
|
28243
28655
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
28244
28656
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
28245
28657
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
28246
|
-
const had =
|
|
28658
|
+
const had = existsSync14(file2);
|
|
28247
28659
|
mkdirSync5(dirname9(file2), { recursive: true });
|
|
28248
28660
|
if (had) copyFileSync(file2, trash);
|
|
28249
28661
|
try {
|
|
@@ -28273,7 +28685,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28273
28685
|
if (requested === null) return [];
|
|
28274
28686
|
const current = readHostConfig(row5.id, requested);
|
|
28275
28687
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
28276
|
-
const exists =
|
|
28688
|
+
const exists = existsSync14(current.path);
|
|
28277
28689
|
if (exists && result.text === current.text) return [];
|
|
28278
28690
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
28279
28691
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -28281,7 +28693,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28281
28693
|
}
|
|
28282
28694
|
|
|
28283
28695
|
// src/core/ops/plugin-swap.ts
|
|
28284
|
-
import { existsSync as
|
|
28696
|
+
import { existsSync as existsSync15, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
28285
28697
|
import { basename as basename4, join as join18, win32 as win322 } from "node:path";
|
|
28286
28698
|
function linkTarget(path5, win) {
|
|
28287
28699
|
if (!isLink(path5)) return null;
|
|
@@ -28292,7 +28704,7 @@ function isLink(path5) {
|
|
|
28292
28704
|
return lstatSync(path5, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
28293
28705
|
}
|
|
28294
28706
|
function generations(agentDir) {
|
|
28295
|
-
return
|
|
28707
|
+
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
28708
|
}
|
|
28297
28709
|
function settleLinks(link, tmp, old, opts) {
|
|
28298
28710
|
if (isLink(tmp)) unlinkSync2(tmp);
|
|
@@ -28302,7 +28714,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
28302
28714
|
}
|
|
28303
28715
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
28304
28716
|
const next = join18(agentDir, sha);
|
|
28305
|
-
if (!
|
|
28717
|
+
if (!existsSync15(next) || !lstatSync(next).isDirectory()) {
|
|
28306
28718
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
|
|
28307
28719
|
}
|
|
28308
28720
|
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
@@ -28322,12 +28734,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
28322
28734
|
if (before !== null) keep.add(before);
|
|
28323
28735
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
|
|
28324
28736
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
28325
|
-
const previous = before !== null &&
|
|
28737
|
+
const previous = before !== null && existsSync15(join18(agentDir, before)) ? join18(agentDir, before) : null;
|
|
28326
28738
|
return { current: next, previous, removed };
|
|
28327
28739
|
}
|
|
28328
28740
|
|
|
28329
28741
|
// src/core/ops/release-fetch.ts
|
|
28330
|
-
import { existsSync as
|
|
28742
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
|
|
28331
28743
|
import { join as join19 } from "node:path";
|
|
28332
28744
|
function failed(r) {
|
|
28333
28745
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -28351,7 +28763,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
28351
28763
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
28352
28764
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
28353
28765
|
const dir = join19(agentDir, sha);
|
|
28354
|
-
if (
|
|
28766
|
+
if (existsSync16(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
28355
28767
|
else renameWithRetry(fetchDir, dir, opts);
|
|
28356
28768
|
return { sha, dir };
|
|
28357
28769
|
} catch (e) {
|
|
@@ -28361,7 +28773,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
28361
28773
|
}
|
|
28362
28774
|
|
|
28363
28775
|
// src/core/ops/uninstall.ts
|
|
28364
|
-
import { existsSync as
|
|
28776
|
+
import { existsSync as existsSync17, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28365
28777
|
import { join as join20 } from "node:path";
|
|
28366
28778
|
function row2(area, before, after) {
|
|
28367
28779
|
return { area, before, after };
|
|
@@ -28391,7 +28803,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
28391
28803
|
}
|
|
28392
28804
|
case "plugin": {
|
|
28393
28805
|
const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
28394
|
-
if (!
|
|
28806
|
+
if (!existsSync17(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
28395
28807
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
28396
28808
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
28397
28809
|
}
|
|
@@ -28471,9 +28883,9 @@ function removeOwnEntries(agent, env) {
|
|
|
28471
28883
|
function removeProjectData(configDir, projectKey) {
|
|
28472
28884
|
const projects = join20(configDir, PROJECTS_DIR_NAME);
|
|
28473
28885
|
const dir = join20(projects, projectKey);
|
|
28474
|
-
if (!
|
|
28886
|
+
if (!existsSync17(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
28475
28887
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
28476
|
-
for (const name of
|
|
28888
|
+
for (const name of readdirSync8(dir)) {
|
|
28477
28889
|
if (name !== OWNERS_DIR_NAME) rmSync7(join20(dir, name), { recursive: true, force: true });
|
|
28478
28890
|
}
|
|
28479
28891
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
@@ -28487,7 +28899,7 @@ function runUninstall(input) {
|
|
|
28487
28899
|
}
|
|
28488
28900
|
|
|
28489
28901
|
// src/core/ops/v1-remove.ts
|
|
28490
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
28902
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync18, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
|
|
28491
28903
|
var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
28492
28904
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
28493
28905
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -28568,14 +28980,14 @@ function removeV1(agent, findings) {
|
|
|
28568
28980
|
for (const f of findings) {
|
|
28569
28981
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
28570
28982
|
else if (f.path === "") {
|
|
28571
|
-
if (
|
|
28983
|
+
if (existsSync18(f.file)) {
|
|
28572
28984
|
moveAside(f.file, undo);
|
|
28573
28985
|
done.set(f, UPGRADE_REMOVED);
|
|
28574
28986
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
28575
28987
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
28576
28988
|
}
|
|
28577
28989
|
for (const [file2, list4] of entries) {
|
|
28578
|
-
if (!
|
|
28990
|
+
if (!existsSync18(file2)) {
|
|
28579
28991
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
28580
28992
|
continue;
|
|
28581
28993
|
}
|
|
@@ -28608,7 +29020,7 @@ function removeV1(agent, findings) {
|
|
|
28608
29020
|
},
|
|
28609
29021
|
rollback() {
|
|
28610
29022
|
for (const u of undo.splice(0).reverse()) {
|
|
28611
|
-
if (!
|
|
29023
|
+
if (!existsSync18(u.trash)) continue;
|
|
28612
29024
|
rmSync8(u.target, { recursive: true, force: true });
|
|
28613
29025
|
renameWithRetry(u.trash, u.target);
|
|
28614
29026
|
}
|
|
@@ -28618,7 +29030,7 @@ function removeV1(agent, findings) {
|
|
|
28618
29030
|
|
|
28619
29031
|
// src/core/ops/verify-sums.ts
|
|
28620
29032
|
import { createHash } from "node:crypto";
|
|
28621
|
-
import { lstatSync as lstatSync2, readdirSync as
|
|
29033
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync15 } from "node:fs";
|
|
28622
29034
|
import { join as join21 } from "node:path";
|
|
28623
29035
|
function mismatch() {
|
|
28624
29036
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
@@ -28636,12 +29048,12 @@ function parseSums(text) {
|
|
|
28636
29048
|
}
|
|
28637
29049
|
return sums;
|
|
28638
29050
|
}
|
|
28639
|
-
function
|
|
28640
|
-
for (const entry of
|
|
29051
|
+
function walk3(dir, prefix, out) {
|
|
29052
|
+
for (const entry of readdirSync9(dir, { withFileTypes: true })) {
|
|
28641
29053
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
28642
29054
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
28643
29055
|
const abs = join21(dir, entry.name);
|
|
28644
|
-
if (entry.isDirectory())
|
|
29056
|
+
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
28645
29057
|
else if (entry.isFile()) out.set(rel, abs);
|
|
28646
29058
|
else throw mismatch();
|
|
28647
29059
|
}
|
|
@@ -28652,7 +29064,7 @@ function verifySums(dir) {
|
|
|
28652
29064
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
28653
29065
|
const sums = parseSums(readFileSync15(sumsPath, "utf8"));
|
|
28654
29066
|
const files = /* @__PURE__ */ new Map();
|
|
28655
|
-
|
|
29067
|
+
walk3(dir, "", files);
|
|
28656
29068
|
if (files.size !== sums.size) throw mismatch();
|
|
28657
29069
|
for (const [rel, abs] of files) {
|
|
28658
29070
|
const want = sums.get(rel);
|
|
@@ -28686,7 +29098,7 @@ function pluginRootRow(adapter, env) {
|
|
|
28686
29098
|
}
|
|
28687
29099
|
function isCurrent(agentDir, dir) {
|
|
28688
29100
|
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
28689
|
-
return
|
|
29101
|
+
return existsSync19(link) && realpathSync7.native(link) === realpathSync7.native(dir);
|
|
28690
29102
|
}
|
|
28691
29103
|
async function checkout(adapter, deps) {
|
|
28692
29104
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -28814,7 +29226,7 @@ async function setup(app) {
|
|
|
28814
29226
|
const payloads = /* @__PURE__ */ new Map();
|
|
28815
29227
|
const call = (raw) => handleHook(AGENT, { ...raw, directory: cwd }, env);
|
|
28816
29228
|
const turnOf = (sessionId) => turns.get(sessionId) ?? 0;
|
|
28817
|
-
function
|
|
29229
|
+
function payloadFor2(sessionId) {
|
|
28818
29230
|
let p = payloads.get(sessionId);
|
|
28819
29231
|
if (p === void 0) {
|
|
28820
29232
|
p = call({ type: "context", sessionID: sessionId, turn: turnOf(sessionId) }).then((out) => [out.stdout, INSTRUCTIONS].filter((s) => s !== "").join("\n\n"));
|
|
@@ -28867,7 +29279,7 @@ async function setup(app) {
|
|
|
28867
29279
|
// §4.4. Deny (exit 2) throws with the reason; the reason carries any rewritten command (Q3, D-M5-P2-3).
|
|
28868
29280
|
"tool.execute.before": async (input, output) => {
|
|
28869
29281
|
const sessionId = input.sessionID ?? "";
|
|
28870
|
-
await
|
|
29282
|
+
await payloadFor2(sessionId);
|
|
28871
29283
|
const out = await call({
|
|
28872
29284
|
type: "execute.before",
|
|
28873
29285
|
sessionID: sessionId,
|
|
@@ -28881,7 +29293,7 @@ async function setup(app) {
|
|
|
28881
29293
|
// §4.5. OpenCode's encode has no replace field (impl/10 §11), so output.output is never changed here.
|
|
28882
29294
|
"tool.execute.after": async (input, output) => {
|
|
28883
29295
|
const sessionId = input.sessionID ?? "";
|
|
28884
|
-
await
|
|
29296
|
+
await payloadFor2(sessionId);
|
|
28885
29297
|
await call({
|
|
28886
29298
|
type: "execute.after",
|
|
28887
29299
|
sessionID: sessionId,
|
|
@@ -28895,7 +29307,7 @@ async function setup(app) {
|
|
|
28895
29307
|
// §4.6: one system entry per session, the same bytes on every request (#1085, Q12). A second
|
|
28896
29308
|
// transform on the same array finds the entry and adds nothing.
|
|
28897
29309
|
"experimental.chat.system.transform": async (input, output) => {
|
|
28898
|
-
const payload = await
|
|
29310
|
+
const payload = await payloadFor2(input.sessionID ?? "");
|
|
28899
29311
|
if (!output.system.includes(payload)) output.system.push(payload);
|
|
28900
29312
|
},
|
|
28901
29313
|
// PreCompact: handleHook sets the pending-compact marker the next session payload reads (§4.6 step 2).
|