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/pi/index.js
CHANGED
|
@@ -11423,6 +11423,9 @@ var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
|
11423
11423
|
function D5_LAST_HOOK_ERROR(ts, stage, label) {
|
|
11424
11424
|
return `; last hook error ${ts} at ${stage} (${label}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
11425
11425
|
}
|
|
11426
|
+
function D5_PAST_HOOK_ERROR(ts, stage, label) {
|
|
11427
|
+
return `; past hook error ${ts} at ${stage} (${label}), before this run, stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
11428
|
+
}
|
|
11426
11429
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
11427
11430
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
11428
11431
|
var VERSION_PROBE_FLAGS = Object.freeze(["--version", "-v"]);
|
|
@@ -11505,7 +11508,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
11505
11508
|
var DECISION_LABEL_JOIN = " | ";
|
|
11506
11509
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11507
11510
|
var RELEASE_BRANCH = "release";
|
|
11508
|
-
var BUNDLE_SHA = true ? "
|
|
11511
|
+
var BUNDLE_SHA = true ? "ea4179fd9a2c4c55eadc9184a295a7f974df90bd" : void 0;
|
|
11509
11512
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11510
11513
|
var DOCTOR_LABEL = Object.freeze({
|
|
11511
11514
|
D1: "version",
|
|
@@ -11694,7 +11697,7 @@ var REGEX_ESCAPE = "\\";
|
|
|
11694
11697
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
11695
11698
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
11696
11699
|
function D5_SLOW_DETAIL(ms) {
|
|
11697
|
-
return `hook round trip took ${ms} ms, over ${HOOK_P95_MS} ms`;
|
|
11700
|
+
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
11698
11701
|
}
|
|
11699
11702
|
var D5_FIX = "run ctx_upgrade";
|
|
11700
11703
|
var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
@@ -12271,7 +12274,8 @@ var RESULT_SUCCESS = "success";
|
|
|
12271
12274
|
function isRecord(v) {
|
|
12272
12275
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
12273
12276
|
}
|
|
12274
|
-
var
|
|
12277
|
+
var SHELL_TOOL_NAMES = Object.freeze(["bash", "powershell"]);
|
|
12278
|
+
var NATIVE_TO_CANONICAL4 = Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"]));
|
|
12275
12279
|
function canonicalName3(name) {
|
|
12276
12280
|
if (name.startsWith(TOOL_NAME_PREFIX6)) return name.slice(TOOL_NAME_PREFIX6.length);
|
|
12277
12281
|
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
@@ -12352,11 +12356,11 @@ var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostTool
|
|
|
12352
12356
|
var MCP_PREFIX2 = "mcp_";
|
|
12353
12357
|
var MCP_SEP2 = "_";
|
|
12354
12358
|
var SESSION_START_NEW = "new";
|
|
12355
|
-
var
|
|
12359
|
+
var SHELL_TOOL_NAMES2 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
|
|
12356
12360
|
var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
|
|
12357
12361
|
var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
|
|
12358
12362
|
var NATIVE_TO_CANONICAL5 = Object.fromEntries([
|
|
12359
|
-
...
|
|
12363
|
+
...SHELL_TOOL_NAMES2.map((n) => [n, "Bash"]),
|
|
12360
12364
|
...READ_TOOL_NAMES.map((n) => [n, "Read"]),
|
|
12361
12365
|
...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
|
|
12362
12366
|
]);
|
|
@@ -12484,8 +12488,8 @@ var KIRO_EVENTS = {
|
|
|
12484
12488
|
};
|
|
12485
12489
|
var PROMPT_ENV = "USER_PROMPT";
|
|
12486
12490
|
var MCP_PREFIX3 = "mcp_";
|
|
12487
|
-
var
|
|
12488
|
-
var NATIVE_TO_CANONICAL6 = Object.fromEntries(
|
|
12491
|
+
var SHELL_TOOL_NAMES3 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
12492
|
+
var NATIVE_TO_CANONICAL6 = Object.fromEntries(SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]));
|
|
12489
12493
|
var MCP_SEP3 = "_";
|
|
12490
12494
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
12491
12495
|
function canonicalName5(name) {
|
|
@@ -12699,8 +12703,9 @@ var ADAPTERS = Object.freeze([
|
|
|
12699
12703
|
installMode: "plugin",
|
|
12700
12704
|
projectSource: "arg:--agent+cwd",
|
|
12701
12705
|
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
12702
|
-
nativeTools: { shell: [
|
|
12706
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES] },
|
|
12703
12707
|
execReadOnlyHint: false,
|
|
12708
|
+
// D-PWSH-DUMP-1
|
|
12704
12709
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
12705
12710
|
compactDelivery: "pending-flag",
|
|
12706
12711
|
compactSummary: "none",
|
|
@@ -12718,7 +12723,7 @@ var ADAPTERS = Object.freeze([
|
|
|
12718
12723
|
projectSource: "arg:workspaceFolder",
|
|
12719
12724
|
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
12720
12725
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
12721
|
-
nativeTools: { shell: [...
|
|
12726
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES2], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
12722
12727
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
12723
12728
|
execReadOnlyHint: false,
|
|
12724
12729
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -12737,7 +12742,7 @@ var ADAPTERS = Object.freeze([
|
|
|
12737
12742
|
installMode: "mcp-entry",
|
|
12738
12743
|
projectSource: "arg:--agent+cwd",
|
|
12739
12744
|
toolNamePrefix: TOOL_NAME_PREFIX8,
|
|
12740
|
-
nativeTools: { shell: [...
|
|
12745
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
|
|
12741
12746
|
execReadOnlyHint: false,
|
|
12742
12747
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
12743
12748
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -12829,7 +12834,7 @@ function getAdapter(id) {
|
|
|
12829
12834
|
}
|
|
12830
12835
|
|
|
12831
12836
|
// src/core/policy/decide.ts
|
|
12832
|
-
import { resolve } from "node:path";
|
|
12837
|
+
import { resolve as resolve2 } from "node:path";
|
|
12833
12838
|
|
|
12834
12839
|
// src/core/policy/lexer.ts
|
|
12835
12840
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -13770,6 +13775,343 @@ function parseShell(cmd) {
|
|
|
13770
13775
|
return { ok: true, commands };
|
|
13771
13776
|
}
|
|
13772
13777
|
|
|
13778
|
+
// src/core/policy/powershell.ts
|
|
13779
|
+
import { resolve } from "node:path";
|
|
13780
|
+
var SQ = "'";
|
|
13781
|
+
var DQ = '"';
|
|
13782
|
+
var TICK = "`";
|
|
13783
|
+
var SPACES = " \r";
|
|
13784
|
+
var OPENERS = "([{";
|
|
13785
|
+
var CLOSERS = ")]}";
|
|
13786
|
+
var GLUE_END = " \r\n|;>";
|
|
13787
|
+
var FD_STAR = "*";
|
|
13788
|
+
var STDOUT_FD = "1";
|
|
13789
|
+
var METHOD_MARK = "::";
|
|
13790
|
+
var PAIR = METHOD_MARK.length;
|
|
13791
|
+
var MIN_STATIC_CALL = PAIR;
|
|
13792
|
+
function quoteEnd(text, at2) {
|
|
13793
|
+
const q = text.charAt(at2);
|
|
13794
|
+
for (let j = at2 + 1; j < text.length; j++) {
|
|
13795
|
+
const c = text.charAt(j);
|
|
13796
|
+
if (q === DQ && c === TICK) {
|
|
13797
|
+
j++;
|
|
13798
|
+
continue;
|
|
13799
|
+
}
|
|
13800
|
+
if (c !== q) continue;
|
|
13801
|
+
if (text.charAt(j + 1) === q) {
|
|
13802
|
+
j++;
|
|
13803
|
+
continue;
|
|
13804
|
+
}
|
|
13805
|
+
return j;
|
|
13806
|
+
}
|
|
13807
|
+
return -1;
|
|
13808
|
+
}
|
|
13809
|
+
function unquote(body, q) {
|
|
13810
|
+
let out = "";
|
|
13811
|
+
for (let j = 0; j < body.length; j++) {
|
|
13812
|
+
const c = body.charAt(j);
|
|
13813
|
+
if (q === DQ && c === TICK && j + 1 < body.length) {
|
|
13814
|
+
out += body.charAt(++j);
|
|
13815
|
+
continue;
|
|
13816
|
+
}
|
|
13817
|
+
if (c === q && body.charAt(j + 1) === q) j++;
|
|
13818
|
+
out += c;
|
|
13819
|
+
}
|
|
13820
|
+
return out;
|
|
13821
|
+
}
|
|
13822
|
+
function closeOf(text, at2) {
|
|
13823
|
+
let depth = 0;
|
|
13824
|
+
for (let j = at2; j < text.length; j++) {
|
|
13825
|
+
const c = text.charAt(j);
|
|
13826
|
+
if (c === SQ || c === DQ) {
|
|
13827
|
+
const e = quoteEnd(text, j);
|
|
13828
|
+
if (e < 0) return -1;
|
|
13829
|
+
j = e;
|
|
13830
|
+
continue;
|
|
13831
|
+
}
|
|
13832
|
+
if (c === TICK) {
|
|
13833
|
+
j++;
|
|
13834
|
+
continue;
|
|
13835
|
+
}
|
|
13836
|
+
if (OPENERS.includes(c)) depth++;
|
|
13837
|
+
else if (CLOSERS.includes(c) && --depth === 0) return j;
|
|
13838
|
+
}
|
|
13839
|
+
return -1;
|
|
13840
|
+
}
|
|
13841
|
+
function glueEnd(text, from) {
|
|
13842
|
+
let depth = 0;
|
|
13843
|
+
for (let j = from; j < text.length; j++) {
|
|
13844
|
+
const c = text.charAt(j);
|
|
13845
|
+
if (c === SQ || c === DQ) {
|
|
13846
|
+
const e = quoteEnd(text, j);
|
|
13847
|
+
if (e < 0) return text.length;
|
|
13848
|
+
j = e;
|
|
13849
|
+
continue;
|
|
13850
|
+
}
|
|
13851
|
+
if (OPENERS.includes(c)) depth++;
|
|
13852
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
13853
|
+
else if (depth <= 0 && GLUE_END.includes(c)) return j;
|
|
13854
|
+
}
|
|
13855
|
+
return text.length;
|
|
13856
|
+
}
|
|
13857
|
+
function splitArgs(inner) {
|
|
13858
|
+
const parts = [];
|
|
13859
|
+
let depth = 0;
|
|
13860
|
+
let from = 0;
|
|
13861
|
+
for (let j = 0; j < inner.length; j++) {
|
|
13862
|
+
const c = inner.charAt(j);
|
|
13863
|
+
if (c === SQ || c === DQ) {
|
|
13864
|
+
const e = quoteEnd(inner, j);
|
|
13865
|
+
if (e < 0) break;
|
|
13866
|
+
j = e;
|
|
13867
|
+
continue;
|
|
13868
|
+
}
|
|
13869
|
+
if (OPENERS.includes(c)) depth++;
|
|
13870
|
+
else if (CLOSERS.includes(c)) depth--;
|
|
13871
|
+
else if (c === "," && depth === 0) {
|
|
13872
|
+
parts.push(inner.slice(from, j));
|
|
13873
|
+
from = j + 1;
|
|
13874
|
+
}
|
|
13875
|
+
}
|
|
13876
|
+
parts.push(inner.slice(from));
|
|
13877
|
+
return parts;
|
|
13878
|
+
}
|
|
13879
|
+
var isFd = (w) => w !== "" && (w === FD_STAR || [...w].every((ch) => ch >= "0" && ch <= "9"));
|
|
13880
|
+
var fresh = () => ({ words: [], toFile: false, chained: false });
|
|
13881
|
+
function psParse(text) {
|
|
13882
|
+
const statements = [];
|
|
13883
|
+
let stages = [];
|
|
13884
|
+
let stage = fresh();
|
|
13885
|
+
let word = "";
|
|
13886
|
+
let has3 = false;
|
|
13887
|
+
let bare2 = true;
|
|
13888
|
+
let target = null;
|
|
13889
|
+
const n = text.length;
|
|
13890
|
+
const endWord = () => {
|
|
13891
|
+
if (!has3) return;
|
|
13892
|
+
if (target !== null) {
|
|
13893
|
+
if (target === "file") stage.toFile = true;
|
|
13894
|
+
target = null;
|
|
13895
|
+
} else stage.words.push(word);
|
|
13896
|
+
word = "";
|
|
13897
|
+
has3 = false;
|
|
13898
|
+
bare2 = true;
|
|
13899
|
+
};
|
|
13900
|
+
const endStage = () => {
|
|
13901
|
+
endWord();
|
|
13902
|
+
if (stage.words.length > 0 || stage.toFile) stages.push(stage);
|
|
13903
|
+
stage = fresh();
|
|
13904
|
+
};
|
|
13905
|
+
const endStatement = () => {
|
|
13906
|
+
endStage();
|
|
13907
|
+
if (stages.length > 0) statements.push(stages);
|
|
13908
|
+
stages = [];
|
|
13909
|
+
};
|
|
13910
|
+
const grow = (s, quoted) => {
|
|
13911
|
+
word += s;
|
|
13912
|
+
has3 = true;
|
|
13913
|
+
if (quoted) bare2 = false;
|
|
13914
|
+
};
|
|
13915
|
+
let i = 0;
|
|
13916
|
+
while (i < n) {
|
|
13917
|
+
const c = text.charAt(i);
|
|
13918
|
+
const next = text.charAt(i + 1);
|
|
13919
|
+
if (c === SQ || c === DQ) {
|
|
13920
|
+
const e = quoteEnd(text, i);
|
|
13921
|
+
grow(unquote(text.slice(i + 1, e < 0 ? n : e), c), true);
|
|
13922
|
+
i = e < 0 ? n : e + 1;
|
|
13923
|
+
} else if (c === TICK) {
|
|
13924
|
+
if (next !== "\n" && next !== "") grow(next, false);
|
|
13925
|
+
i += PAIR;
|
|
13926
|
+
} else if (c === "\n") {
|
|
13927
|
+
endStatement();
|
|
13928
|
+
i++;
|
|
13929
|
+
} else if (SPACES.includes(c)) {
|
|
13930
|
+
endWord();
|
|
13931
|
+
i++;
|
|
13932
|
+
} else if (c === ";") {
|
|
13933
|
+
endStatement();
|
|
13934
|
+
i++;
|
|
13935
|
+
} else if (c === "|") {
|
|
13936
|
+
if (next === "|") {
|
|
13937
|
+
endStatement();
|
|
13938
|
+
i += PAIR;
|
|
13939
|
+
} else {
|
|
13940
|
+
endStage();
|
|
13941
|
+
i++;
|
|
13942
|
+
}
|
|
13943
|
+
} else if (c === "&") {
|
|
13944
|
+
if (next === "&") {
|
|
13945
|
+
endStatement();
|
|
13946
|
+
i += PAIR;
|
|
13947
|
+
} else {
|
|
13948
|
+
if (has3 || stage.words.length > 0) grow(c, false);
|
|
13949
|
+
i++;
|
|
13950
|
+
}
|
|
13951
|
+
} else if (c === "#" && !has3) {
|
|
13952
|
+
while (i < n && text.charAt(i) !== "\n") i++;
|
|
13953
|
+
} else if (c === ">") {
|
|
13954
|
+
let fd = STDOUT_FD;
|
|
13955
|
+
if (has3 && bare2 && isFd(word)) {
|
|
13956
|
+
fd = word;
|
|
13957
|
+
word = "";
|
|
13958
|
+
has3 = false;
|
|
13959
|
+
} else if (has3) endWord();
|
|
13960
|
+
let j = i + 1;
|
|
13961
|
+
if (text.charAt(j) === ">") j++;
|
|
13962
|
+
if (text.charAt(j) === "&") {
|
|
13963
|
+
j++;
|
|
13964
|
+
while (j < n && !GLUE_END.includes(text.charAt(j))) j++;
|
|
13965
|
+
} else target = fd === STDOUT_FD || fd === FD_STAR ? "file" : "skip";
|
|
13966
|
+
i = j;
|
|
13967
|
+
} else if (c === "(" && has3 && bare2 && word.includes(METHOD_MARK)) {
|
|
13968
|
+
const e = closeOf(text, i);
|
|
13969
|
+
const inner = text.slice(i + 1, e < 0 ? n : e);
|
|
13970
|
+
endWord();
|
|
13971
|
+
for (const a of inner.trim() === "" ? [] : splitArgs(inner)) {
|
|
13972
|
+
const first = psParse(a)[0]?.[0]?.words[0];
|
|
13973
|
+
stage.words.push(first ?? a.trim());
|
|
13974
|
+
}
|
|
13975
|
+
i = e < 0 ? n : e + 1;
|
|
13976
|
+
if (i < n && !GLUE_END.includes(text.charAt(i))) {
|
|
13977
|
+
stage.chained = true;
|
|
13978
|
+
i = glueEnd(text, i);
|
|
13979
|
+
}
|
|
13980
|
+
} else if (c === "[" && !has3 && text.startsWith(METHOD_MARK, closeOf(text, i) + 1) && closeOf(text, i) >= 0) {
|
|
13981
|
+
const e = closeOf(text, i);
|
|
13982
|
+
grow(text.slice(i, e + 1), false);
|
|
13983
|
+
i = e + 1;
|
|
13984
|
+
} else if (OPENERS.includes(c) && (c !== "[" || !has3) || (c === "$" || c === "@") && OPENERS.includes(next) && next !== "[") {
|
|
13985
|
+
const open3 = c === "$" || c === "@" ? i + 1 : i;
|
|
13986
|
+
const e = closeOf(text, open3);
|
|
13987
|
+
grow(text.slice(i, e < 0 ? n : e + 1), true);
|
|
13988
|
+
i = e < 0 ? n : e + 1;
|
|
13989
|
+
} else {
|
|
13990
|
+
grow(c, false);
|
|
13991
|
+
i++;
|
|
13992
|
+
}
|
|
13993
|
+
}
|
|
13994
|
+
endStatement();
|
|
13995
|
+
return statements;
|
|
13996
|
+
}
|
|
13997
|
+
var READ_COMMANDS = ["get-content", "gc", "cat", "type"];
|
|
13998
|
+
var FILE_CLASSES = ["[io.file]::", "[system.io.file]::"];
|
|
13999
|
+
var FILE_READS = ["readalltext", "readalllines", "readallbytes", "readlines"];
|
|
14000
|
+
var PATH_PARAMS = ["path", "literalpath"];
|
|
14001
|
+
var BOUND_PARAMS = ["totalcount", "head", "first", "tail", "last"];
|
|
14002
|
+
var VALUE_PARAMS = [...PATH_PARAMS, ...BOUND_PARAMS, "encoding", "readcount", "delimiter", "filter", "include", "exclude", "stream", "credential"];
|
|
14003
|
+
var SWITCH_PARAMS = ["raw", "wait", "force", "asbytestream"];
|
|
14004
|
+
var ALL_PARAMS = [...VALUE_PARAMS, ...SWITCH_PARAMS];
|
|
14005
|
+
var PASS_THROUGH = ["out-string", "write-output", "echo", "write", "out-host", "write-host", "out-default", "tee-object"];
|
|
14006
|
+
var CD_COMMANDS = ["cd", "chdir", "sl", "set-location", "pushd", "push-location"];
|
|
14007
|
+
var POWERSHELLS = ["powershell", "powershell.exe", "pwsh", "pwsh.exe"];
|
|
14008
|
+
var CMDS = ["cmd", "cmd.exe"];
|
|
14009
|
+
var CMD_RUN_FLAGS = ["/c", "/k", "/r"];
|
|
14010
|
+
var COMMAND_PARAM = "command";
|
|
14011
|
+
var DASH = "-";
|
|
14012
|
+
function cmdName(word) {
|
|
14013
|
+
const k = Math.max(word.lastIndexOf("\\"), word.lastIndexOf("/"));
|
|
14014
|
+
return (k >= 0 && k < word.length - 1 ? word.slice(k + 1) : word).toLowerCase();
|
|
14015
|
+
}
|
|
14016
|
+
function param(word, names) {
|
|
14017
|
+
const body = word.slice(DASH.length);
|
|
14018
|
+
const colon = body.indexOf(":");
|
|
14019
|
+
const name = (colon < 0 ? body : body.slice(0, colon)).toLowerCase();
|
|
14020
|
+
const inline = colon < 0 ? void 0 : body.slice(colon + 1);
|
|
14021
|
+
if (name === "") return { full: void 0, inline };
|
|
14022
|
+
if (names.includes(name)) return { full: name, inline };
|
|
14023
|
+
const hits = names.filter((p) => p.startsWith(name));
|
|
14024
|
+
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
14025
|
+
}
|
|
14026
|
+
function psDump(words) {
|
|
14027
|
+
if (words.length === 0) return null;
|
|
14028
|
+
const name = cmdName(words[0]);
|
|
14029
|
+
if (!READ_COMMANDS.includes(name)) {
|
|
14030
|
+
const lower = words[0].toLowerCase();
|
|
14031
|
+
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
14032
|
+
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words.length < MIN_STATIC_CALL) return null;
|
|
14033
|
+
return { file: words[1], bounded: false };
|
|
14034
|
+
}
|
|
14035
|
+
const files = [];
|
|
14036
|
+
let bounded = false;
|
|
14037
|
+
for (let k = 1; k < words.length; k++) {
|
|
14038
|
+
const a = words[k];
|
|
14039
|
+
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
14040
|
+
files.push(a);
|
|
14041
|
+
continue;
|
|
14042
|
+
}
|
|
14043
|
+
const p = param(a, ALL_PARAMS);
|
|
14044
|
+
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
14045
|
+
const value = p.inline ?? words[++k];
|
|
14046
|
+
if (value === void 0) return null;
|
|
14047
|
+
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
14048
|
+
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
14049
|
+
}
|
|
14050
|
+
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
14051
|
+
}
|
|
14052
|
+
function nestedScript(name, words) {
|
|
14053
|
+
if (POWERSHELLS.includes(name)) {
|
|
14054
|
+
for (let k = 1; k < words.length; k++) {
|
|
14055
|
+
const w = words[k];
|
|
14056
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
14057
|
+
const p = param(w, [COMMAND_PARAM]);
|
|
14058
|
+
if (p.full === void 0) continue;
|
|
14059
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words.slice(k + 1)].join(" ");
|
|
14060
|
+
}
|
|
14061
|
+
return null;
|
|
14062
|
+
}
|
|
14063
|
+
if (CMDS.includes(name)) {
|
|
14064
|
+
for (let k = 1; k < words.length; k++) {
|
|
14065
|
+
if (CMD_RUN_FLAGS.includes(words[k].toLowerCase())) return words.slice(k + 1).join(" ");
|
|
14066
|
+
}
|
|
14067
|
+
}
|
|
14068
|
+
return null;
|
|
14069
|
+
}
|
|
14070
|
+
function cdTarget(words) {
|
|
14071
|
+
for (let k = 1; k < words.length; k++) {
|
|
14072
|
+
const w = words[k];
|
|
14073
|
+
if (w.toLowerCase() === "/d") continue;
|
|
14074
|
+
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
14075
|
+
const p = param(w, PATH_PARAMS);
|
|
14076
|
+
if (p.full !== void 0) return p.inline ?? words[k + 1] ?? null;
|
|
14077
|
+
}
|
|
14078
|
+
return null;
|
|
14079
|
+
}
|
|
14080
|
+
function walk(script, cwd, depth, found) {
|
|
14081
|
+
let dir = cwd;
|
|
14082
|
+
for (const stages of psParse(script)) {
|
|
14083
|
+
const head = stages[0];
|
|
14084
|
+
if (head.words.length === 0) continue;
|
|
14085
|
+
const name = cmdName(head.words[0]);
|
|
14086
|
+
if (stages.length === 1 && CD_COMMANDS.includes(name)) {
|
|
14087
|
+
const t = cdTarget(head.words);
|
|
14088
|
+
if (t !== null) dir = resolve(dir, t);
|
|
14089
|
+
continue;
|
|
14090
|
+
}
|
|
14091
|
+
const inner = depth < MAX_NEST_DEPTH ? nestedScript(name, head.words) : null;
|
|
14092
|
+
if (inner !== null) {
|
|
14093
|
+
walk(inner, dir, depth + 1, found);
|
|
14094
|
+
continue;
|
|
14095
|
+
}
|
|
14096
|
+
if (head.toFile || head.chained) continue;
|
|
14097
|
+
const d = psDump(head.words);
|
|
14098
|
+
if (d === null || d.bounded) continue;
|
|
14099
|
+
let shown2 = true;
|
|
14100
|
+
for (let k = 1; k < stages.length; k++) {
|
|
14101
|
+
if (stages[k].toFile || !PASS_THROUGH.includes(cmdName(stages[k].words[0] ?? ""))) {
|
|
14102
|
+
shown2 = false;
|
|
14103
|
+
break;
|
|
14104
|
+
}
|
|
14105
|
+
}
|
|
14106
|
+
if (shown2) found.push(resolve(dir, d.file));
|
|
14107
|
+
}
|
|
14108
|
+
}
|
|
14109
|
+
function psDumpFiles(script, cwd) {
|
|
14110
|
+
const found = [];
|
|
14111
|
+
walk(script, cwd, 0, found);
|
|
14112
|
+
return found;
|
|
14113
|
+
}
|
|
14114
|
+
|
|
13773
14115
|
// src/core/policy/subagent.ts
|
|
13774
14116
|
import { join as join2 } from "node:path";
|
|
13775
14117
|
|
|
@@ -13981,16 +14323,16 @@ function readList(body, key) {
|
|
|
13981
14323
|
for (let j = i + 1; j < body.length; j++) {
|
|
13982
14324
|
const t = body[j].trim();
|
|
13983
14325
|
if (!t.startsWith("-")) break;
|
|
13984
|
-
items.push(
|
|
14326
|
+
items.push(unquote2(t.slice(1).trim()));
|
|
13985
14327
|
}
|
|
13986
14328
|
return items.filter((s) => s !== "");
|
|
13987
14329
|
}
|
|
13988
14330
|
if (value.startsWith("[") && value.endsWith("]")) value = value.slice(1, -1);
|
|
13989
|
-
return value.split(",").map((s) =>
|
|
14331
|
+
return value.split(",").map((s) => unquote2(s.trim())).filter((s) => s !== "");
|
|
13990
14332
|
}
|
|
13991
14333
|
return null;
|
|
13992
14334
|
}
|
|
13993
|
-
function
|
|
14335
|
+
function unquote2(s) {
|
|
13994
14336
|
if (s.length > 1 && (s[0] === '"' || s[0] === "'") && s.endsWith(s[0])) return s.slice(1, -1);
|
|
13995
14337
|
return s;
|
|
13996
14338
|
}
|
|
@@ -14392,7 +14734,7 @@ function readPath(input) {
|
|
|
14392
14734
|
}
|
|
14393
14735
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
14394
14736
|
if (rules.length === 0) return null;
|
|
14395
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
14737
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve2(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
14396
14738
|
if (canonical === BASH) {
|
|
14397
14739
|
const cmd = str(input.command);
|
|
14398
14740
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -14444,7 +14786,7 @@ function webFetch(input, row5) {
|
|
|
14444
14786
|
function bash(ev, row5, input, rules) {
|
|
14445
14787
|
const cmd = str(input.command) ?? "";
|
|
14446
14788
|
const parsed = parseShell(cmd);
|
|
14447
|
-
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : ALLOW;
|
|
14789
|
+
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
|
|
14448
14790
|
const cmds = unwrap(parsed.commands);
|
|
14449
14791
|
for (const c of cmds) {
|
|
14450
14792
|
const h = segmentHit(c, rules);
|
|
@@ -14456,7 +14798,7 @@ function bash(ev, row5, input, rules) {
|
|
|
14456
14798
|
if (kind !== null) return deny(denyMessage(kind, cmd, row5, str(input.description)));
|
|
14457
14799
|
}
|
|
14458
14800
|
}
|
|
14459
|
-
return shellDump(cmds, ev.cwd, row5) ?? ALLOW;
|
|
14801
|
+
return shellDump(cmds, ev.cwd, row5) ?? psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
|
|
14460
14802
|
}
|
|
14461
14803
|
function denyKind(c) {
|
|
14462
14804
|
const name = c.argv0.toLowerCase();
|
|
@@ -14503,7 +14845,7 @@ function read(ev, row5, input) {
|
|
|
14503
14845
|
if (!present(input.offset) && !present(input.limit)) {
|
|
14504
14846
|
const p = readPath(input);
|
|
14505
14847
|
if (p !== void 0) {
|
|
14506
|
-
const abs =
|
|
14848
|
+
const abs = resolve2(ev.cwd, p);
|
|
14507
14849
|
const size = fileSize(abs);
|
|
14508
14850
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
14509
14851
|
}
|
|
@@ -14516,7 +14858,7 @@ function shellDump(cmds, cwd, row5) {
|
|
|
14516
14858
|
let verdict = null;
|
|
14517
14859
|
for (const c of cmds) {
|
|
14518
14860
|
const name = c.argv0.toLowerCase();
|
|
14519
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
14861
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve2(dir, c.args[0]);
|
|
14520
14862
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
14521
14863
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
14522
14864
|
const d = dumpTarget(name, c.args);
|
|
@@ -14525,12 +14867,20 @@ function shellDump(cmds, cwd, row5) {
|
|
|
14525
14867
|
verdict = ALLOW;
|
|
14526
14868
|
continue;
|
|
14527
14869
|
}
|
|
14528
|
-
const abs =
|
|
14870
|
+
const abs = resolve2(dir, d.file);
|
|
14529
14871
|
const size = fileSize(abs);
|
|
14530
14872
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
14531
14873
|
}
|
|
14532
14874
|
return verdict;
|
|
14533
14875
|
}
|
|
14876
|
+
function psShellDump(cmd, cwd, row5) {
|
|
14877
|
+
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
14878
|
+
for (const abs of psDumpFiles(cmd, cwd)) {
|
|
14879
|
+
const size = fileSize(abs);
|
|
14880
|
+
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
14881
|
+
}
|
|
14882
|
+
return null;
|
|
14883
|
+
}
|
|
14534
14884
|
var allDigits2 = (s) => s !== "" && [...s].every((ch) => ch >= "0" && ch <= "9");
|
|
14535
14885
|
function countFlag(a) {
|
|
14536
14886
|
if (has(DUMP_COUNT_FLAGS, a)) return 1;
|
|
@@ -14588,7 +14938,7 @@ function dumpTarget(name, args) {
|
|
|
14588
14938
|
}
|
|
14589
14939
|
|
|
14590
14940
|
// src/core/project/resolve.ts
|
|
14591
|
-
import { basename, dirname as dirname2, join as join4, resolve as
|
|
14941
|
+
import { basename, dirname as dirname2, join as join4, resolve as resolve3 } from "node:path";
|
|
14592
14942
|
|
|
14593
14943
|
// src/core/project/contain.ts
|
|
14594
14944
|
import { dirname, sep as sep2 } from "node:path";
|
|
@@ -14795,7 +15145,7 @@ function gitDirs(dir) {
|
|
|
14795
15145
|
const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
|
|
14796
15146
|
if (gitDir !== null) {
|
|
14797
15147
|
const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
|
|
14798
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
15148
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve3(gitDir, common)), worktree: cur, start };
|
|
14799
15149
|
}
|
|
14800
15150
|
const up = dirname2(cur);
|
|
14801
15151
|
if (up === cur) return { commonDir: null, start };
|
|
@@ -14810,7 +15160,7 @@ function gitDirAt(dotGit) {
|
|
|
14810
15160
|
} else {
|
|
14811
15161
|
const line = firstLine(dotGit);
|
|
14812
15162
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
14813
|
-
gitDir =
|
|
15163
|
+
gitDir = resolve3(dirname2(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
14814
15164
|
}
|
|
14815
15165
|
} catch {
|
|
14816
15166
|
return null;
|
|
@@ -18751,7 +19101,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
18751
19101
|
}
|
|
18752
19102
|
|
|
18753
19103
|
// src/core/hooks/fallback.ts
|
|
18754
|
-
import { join as join5, resolve as
|
|
19104
|
+
import { join as join5, resolve as resolve4 } from "node:path";
|
|
18755
19105
|
var fs = process.getBuiltinModule("node:fs");
|
|
18756
19106
|
function isRec(v) {
|
|
18757
19107
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -18866,7 +19216,7 @@ function bigRead(input, cwd) {
|
|
|
18866
19216
|
const p = firstString(input, READ_PATH_KEYS);
|
|
18867
19217
|
if (p === "") return false;
|
|
18868
19218
|
try {
|
|
18869
|
-
const st = fs.statSync(
|
|
19219
|
+
const st = fs.statSync(resolve4(cwd, p));
|
|
18870
19220
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
18871
19221
|
} catch {
|
|
18872
19222
|
return false;
|
|
@@ -19479,10 +19829,10 @@ function startArgv(argv) {
|
|
|
19479
19829
|
return sh === null ? null : [sh, ...argv];
|
|
19480
19830
|
}
|
|
19481
19831
|
function runProcess(argv, o) {
|
|
19482
|
-
return new Promise((
|
|
19832
|
+
return new Promise((resolve7) => {
|
|
19483
19833
|
const isWin2 = process.platform === "win32";
|
|
19484
19834
|
const start = startArgv(argv);
|
|
19485
|
-
if (start === null) return
|
|
19835
|
+
if (start === null) return resolve7(NOT_STARTED);
|
|
19486
19836
|
let child;
|
|
19487
19837
|
try {
|
|
19488
19838
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -19496,7 +19846,7 @@ function runProcess(argv, o) {
|
|
|
19496
19846
|
windowsHide: true
|
|
19497
19847
|
});
|
|
19498
19848
|
} catch {
|
|
19499
|
-
return
|
|
19849
|
+
return resolve7(NOT_STARTED);
|
|
19500
19850
|
}
|
|
19501
19851
|
const stdoutChunks = [];
|
|
19502
19852
|
const stderrChunks = [];
|
|
@@ -19521,7 +19871,7 @@ function runProcess(argv, o) {
|
|
|
19521
19871
|
settled = true;
|
|
19522
19872
|
clearTimeout(timer);
|
|
19523
19873
|
o.signal.removeEventListener("abort", onAbort);
|
|
19524
|
-
|
|
19874
|
+
resolve7({
|
|
19525
19875
|
stdout: Buffer.concat(stdoutChunks),
|
|
19526
19876
|
stderr: Buffer.concat(stderrChunks),
|
|
19527
19877
|
exitCode,
|
|
@@ -19988,10 +20338,11 @@ var ctxBatch = Object.freeze({
|
|
|
19988
20338
|
});
|
|
19989
20339
|
|
|
19990
20340
|
// src/core/tools/doctor.ts
|
|
19991
|
-
import { readdirSync as
|
|
20341
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync11 } from "node:fs";
|
|
19992
20342
|
import { basename as basename3, dirname as dirname6, join as join13 } from "node:path";
|
|
19993
20343
|
|
|
19994
20344
|
// src/core/ops/doctor-config.ts
|
|
20345
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
19995
20346
|
import { join as join11 } from "node:path";
|
|
19996
20347
|
|
|
19997
20348
|
// src/core/ops/detect-v1.ts
|
|
@@ -23026,7 +23377,47 @@ function mcpFile(row5, home, env) {
|
|
|
23026
23377
|
}
|
|
23027
23378
|
return null;
|
|
23028
23379
|
}
|
|
23380
|
+
var CODEX_PLUGIN_KEY = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
23381
|
+
var CODEX_PLUGIN_SUBDIR = ".codex-plugin";
|
|
23382
|
+
var CODEX_PLUGIN_MCP_FILE = "mcp.json";
|
|
23383
|
+
var CODEX_PLUGIN_HOOKS_FILE = "hooks.json";
|
|
23384
|
+
var MCP_SERVERS_FIELD = "mcpServers";
|
|
23385
|
+
function codexNativeDir(env, home) {
|
|
23386
|
+
const codexDir = codexDirOf(env, home);
|
|
23387
|
+
let enabled;
|
|
23388
|
+
try {
|
|
23389
|
+
enabled = hostConfigValueAt(readParsed("codex", join11(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
23390
|
+
} catch {
|
|
23391
|
+
return null;
|
|
23392
|
+
}
|
|
23393
|
+
if (enabled !== true) return null;
|
|
23394
|
+
const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
23395
|
+
if (!existsSync6(cache)) return null;
|
|
23396
|
+
const found = [];
|
|
23397
|
+
for (const market of readdirSync3(cache)) {
|
|
23398
|
+
const plugin = join11(cache, market, SERVER_KEY);
|
|
23399
|
+
if (!existsSync6(plugin)) continue;
|
|
23400
|
+
for (const version4 of readdirSync3(plugin).sort()) {
|
|
23401
|
+
const dir = join11(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
23402
|
+
if (existsSync6(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
23403
|
+
}
|
|
23404
|
+
}
|
|
23405
|
+
return found.length === 0 ? null : found[found.length - 1];
|
|
23406
|
+
}
|
|
23407
|
+
function nativeMcpWrong(dir, row5) {
|
|
23408
|
+
try {
|
|
23409
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join11(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
23410
|
+
if (!isObject4(entry)) return true;
|
|
23411
|
+
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
23412
|
+
const script = args[0];
|
|
23413
|
+
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;
|
|
23414
|
+
} catch {
|
|
23415
|
+
return true;
|
|
23416
|
+
}
|
|
23417
|
+
}
|
|
23029
23418
|
function mcpWrong(row5, home, env) {
|
|
23419
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23420
|
+
if (native !== null) return nativeMcpWrong(native, row5);
|
|
23030
23421
|
const file2 = mcpFile(row5, home, env);
|
|
23031
23422
|
try {
|
|
23032
23423
|
if (file2 === null) {
|
|
@@ -23045,7 +23436,8 @@ function hookParts(row5, home, env, worktree) {
|
|
|
23045
23436
|
let block;
|
|
23046
23437
|
try {
|
|
23047
23438
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
|
|
23048
|
-
const
|
|
23439
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23440
|
+
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);
|
|
23049
23441
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
23050
23442
|
if (row5.id === "codex") {
|
|
23051
23443
|
const config4 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -23108,7 +23500,7 @@ function checkDoubleFire(agent, worktree) {
|
|
|
23108
23500
|
}
|
|
23109
23501
|
|
|
23110
23502
|
// src/core/ops/doctor-db.ts
|
|
23111
|
-
import { existsSync as
|
|
23503
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
23112
23504
|
var unknown2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
23113
23505
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
23114
23506
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -23148,7 +23540,7 @@ function failsOnCorrupt(step) {
|
|
|
23148
23540
|
}
|
|
23149
23541
|
async function checkDb(project) {
|
|
23150
23542
|
const clean = { schemaStale: false, integrityFailed: false };
|
|
23151
|
-
if (!
|
|
23543
|
+
if (!existsSync7(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
23152
23544
|
const sqlite = await loadSqlite2();
|
|
23153
23545
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
23154
23546
|
let raw = null;
|
|
@@ -23174,7 +23566,7 @@ async function checkDb(project) {
|
|
|
23174
23566
|
}
|
|
23175
23567
|
}
|
|
23176
23568
|
async function checkIndex(project) {
|
|
23177
|
-
if (!
|
|
23569
|
+
if (!existsSync7(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
23178
23570
|
const sqlite = await loadSqlite2();
|
|
23179
23571
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
23180
23572
|
let raw = null;
|
|
@@ -23191,7 +23583,7 @@ async function checkIndex(project) {
|
|
|
23191
23583
|
}
|
|
23192
23584
|
|
|
23193
23585
|
// src/core/ops/doctor-env.ts
|
|
23194
|
-
import { existsSync as
|
|
23586
|
+
import { existsSync as existsSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
23195
23587
|
import { isAbsolute as isAbsolute3, relative as relative2 } from "node:path";
|
|
23196
23588
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
23197
23589
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
@@ -23249,7 +23641,7 @@ function checkMcp(ctx) {
|
|
|
23249
23641
|
return named || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
23250
23642
|
}
|
|
23251
23643
|
function piCwdInside(worktree, piCwd) {
|
|
23252
|
-
if (piCwd === void 0 || !
|
|
23644
|
+
if (piCwd === void 0 || !existsSync8(piCwd)) return false;
|
|
23253
23645
|
const rel = relative2(worktree, realpathSync5.native(piCwd));
|
|
23254
23646
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
23255
23647
|
}
|
|
@@ -23270,15 +23662,16 @@ function checkShell(env) {
|
|
|
23270
23662
|
}
|
|
23271
23663
|
|
|
23272
23664
|
// src/core/ops/doctor-hook.ts
|
|
23273
|
-
import { existsSync as
|
|
23665
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9 } from "node:fs";
|
|
23274
23666
|
import path4 from "node:path";
|
|
23667
|
+
var D5_SAMPLES = 3;
|
|
23275
23668
|
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 };
|
|
23276
23669
|
function isObject5(v) {
|
|
23277
23670
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23278
23671
|
}
|
|
23279
23672
|
function loadFixture(bundleDir2, agent) {
|
|
23280
23673
|
const file2 = path4.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
23281
|
-
if (!
|
|
23674
|
+
if (!existsSync9(file2)) return null;
|
|
23282
23675
|
let all;
|
|
23283
23676
|
try {
|
|
23284
23677
|
all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
|
|
@@ -23290,6 +23683,9 @@ function loadFixture(bundleDir2, agent) {
|
|
|
23290
23683
|
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) return null;
|
|
23291
23684
|
return { event: e.event, payload: e.payload };
|
|
23292
23685
|
}
|
|
23686
|
+
function payloadFor(payload, worktree) {
|
|
23687
|
+
return worktree !== void 0 && isObject5(payload) ? { ...payload, cwd: worktree } : payload;
|
|
23688
|
+
}
|
|
23293
23689
|
function isNativeShape(stdout, exitCode, killed, event) {
|
|
23294
23690
|
if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
|
|
23295
23691
|
if (stdout.length === 0) return true;
|
|
@@ -23306,31 +23702,43 @@ function codexHookJournaled(db) {
|
|
|
23306
23702
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
23307
23703
|
}
|
|
23308
23704
|
async function checkHookRoundTrip(i) {
|
|
23309
|
-
if (i.agent === "codex" &&
|
|
23705
|
+
if (i.agent === "codex" && existsSync9(path4.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
23310
23706
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
23311
23707
|
}
|
|
23312
23708
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
23313
23709
|
if (fixture === null) return row("UNKNOWN", D5_NO_FIXTURE_DETAIL(i.agent));
|
|
23314
23710
|
const now = i.now ?? (() => performance.now());
|
|
23315
|
-
const
|
|
23316
|
-
const
|
|
23317
|
-
|
|
23318
|
-
env: i.env,
|
|
23319
|
-
|
|
23320
|
-
|
|
23321
|
-
|
|
23322
|
-
|
|
23323
|
-
|
|
23324
|
-
|
|
23711
|
+
const samples = Math.max(1, i.samples ?? D5_SAMPLES);
|
|
23712
|
+
const bareMs = i.bareMs ?? (async () => {
|
|
23713
|
+
const t = performance.now();
|
|
23714
|
+
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs: HOOK_TIMEOUT_MS });
|
|
23715
|
+
return performance.now() - t;
|
|
23716
|
+
});
|
|
23717
|
+
const hookWalls = [];
|
|
23718
|
+
const bareWalls = [];
|
|
23719
|
+
for (let n = 0; n < samples; n++) {
|
|
23720
|
+
const start = now();
|
|
23721
|
+
const r = await runProcess([process.execPath, path4.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
23722
|
+
cwd: i.bundleDir,
|
|
23723
|
+
env: i.env,
|
|
23724
|
+
signal: i.signal,
|
|
23725
|
+
timeoutMs: HOOK_TIMEOUT_MS,
|
|
23726
|
+
stdin: JSON.stringify(payloadFor(fixture.payload, i.worktree))
|
|
23727
|
+
});
|
|
23728
|
+
hookWalls.push(now() - start);
|
|
23729
|
+
if (!isNativeShape(r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
23730
|
+
bareWalls.push(await bareMs());
|
|
23731
|
+
}
|
|
23732
|
+
const ms = Math.max(0, Math.round(Math.min(...hookWalls) - Math.min(...bareWalls)));
|
|
23325
23733
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
23326
23734
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
23327
23735
|
}
|
|
23328
23736
|
|
|
23329
23737
|
// src/core/ops/db-heal.ts
|
|
23330
|
-
import { existsSync as
|
|
23738
|
+
import { existsSync as existsSync10, rmSync as rmSync3 } from "node:fs";
|
|
23331
23739
|
|
|
23332
23740
|
// src/core/store/owners.ts
|
|
23333
|
-
import { mkdirSync as mkdirSync4, readdirSync as
|
|
23741
|
+
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23334
23742
|
import { basename as basename2, join as join12 } from "node:path";
|
|
23335
23743
|
function ownersDir(configDir, projectKey) {
|
|
23336
23744
|
return join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -23363,7 +23771,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
23363
23771
|
const dir = ownersDir(configDir, projectKey);
|
|
23364
23772
|
let names;
|
|
23365
23773
|
try {
|
|
23366
|
-
names =
|
|
23774
|
+
names = readdirSync4(dir);
|
|
23367
23775
|
} catch (err) {
|
|
23368
23776
|
if (errCode2(err) === "ENOENT") return [];
|
|
23369
23777
|
throw err;
|
|
@@ -23420,7 +23828,7 @@ function renameAside(dbPath) {
|
|
|
23420
23828
|
const ts = String(Date.now());
|
|
23421
23829
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
23422
23830
|
const file2 = dbPath + suffix;
|
|
23423
|
-
if (
|
|
23831
|
+
if (existsSync10(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
23424
23832
|
}
|
|
23425
23833
|
return ts;
|
|
23426
23834
|
}
|
|
@@ -23501,7 +23909,7 @@ async function guard(id, run) {
|
|
|
23501
23909
|
}
|
|
23502
23910
|
}
|
|
23503
23911
|
async function codexDb(ctx, adapter) {
|
|
23504
|
-
if (adapter.id !== "codex" || !
|
|
23912
|
+
if (adapter.id !== "codex" || !existsSync11(ctx.project.dbPath)) return null;
|
|
23505
23913
|
try {
|
|
23506
23914
|
return await openDb(ctx.project, { readOnly: true });
|
|
23507
23915
|
} catch {
|
|
@@ -23510,8 +23918,10 @@ async function codexDb(ctx, adapter) {
|
|
|
23510
23918
|
}
|
|
23511
23919
|
async function hookRow(ctx, adapter, host) {
|
|
23512
23920
|
const db = await codexDb(ctx, adapter);
|
|
23921
|
+
const runStart = Date.now();
|
|
23513
23922
|
try {
|
|
23514
23923
|
const row5 = await checkHookRoundTrip({
|
|
23924
|
+
worktree: ctx.project.worktree,
|
|
23515
23925
|
agent: adapter.id,
|
|
23516
23926
|
bundleDir: host.bundleDir,
|
|
23517
23927
|
env: buildChildEnv(host.env),
|
|
@@ -23521,15 +23931,17 @@ async function hookRow(ctx, adapter, host) {
|
|
|
23521
23931
|
db
|
|
23522
23932
|
});
|
|
23523
23933
|
const last2 = lastHookError(host.env);
|
|
23524
|
-
|
|
23934
|
+
if (last2 === null) return row5;
|
|
23935
|
+
const text = Date.parse(last2.ts) >= runStart ? D5_LAST_HOOK_ERROR : D5_PAST_HOOK_ERROR;
|
|
23936
|
+
return { ...row5, detail: row5.detail + text(last2.ts, last2.stage, last2.label) };
|
|
23525
23937
|
} finally {
|
|
23526
23938
|
if (db !== null) closeDb(db);
|
|
23527
23939
|
}
|
|
23528
23940
|
}
|
|
23529
23941
|
function ownServerId(configDir, projectKey) {
|
|
23530
23942
|
const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23531
|
-
if (!
|
|
23532
|
-
for (const name of
|
|
23943
|
+
if (!existsSync11(dir)) return "";
|
|
23944
|
+
for (const name of readdirSync5(dir)) {
|
|
23533
23945
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
23534
23946
|
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
|
|
23535
23947
|
}
|
|
@@ -23603,9 +24015,9 @@ var ctxDoctor = Object.freeze({
|
|
|
23603
24015
|
});
|
|
23604
24016
|
|
|
23605
24017
|
// src/core/tools/execute.ts
|
|
23606
|
-
import { existsSync as
|
|
24018
|
+
import { existsSync as existsSync12, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
23607
24019
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
23608
|
-
import { dirname as dirname7, join as join14, parse as parse3, resolve as
|
|
24020
|
+
import { dirname as dirname7, join as join14, parse as parse3, resolve as resolve5 } from "node:path";
|
|
23609
24021
|
|
|
23610
24022
|
// src/core/sandbox/win-build.ts
|
|
23611
24023
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -23689,7 +24101,7 @@ function schemaLine(issue4) {
|
|
|
23689
24101
|
}
|
|
23690
24102
|
function fileError(given, abs, root) {
|
|
23691
24103
|
let dir = abs;
|
|
23692
|
-
while (!
|
|
24104
|
+
while (!existsSync12(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
|
|
23693
24105
|
if (isInside(root, dir)) return null;
|
|
23694
24106
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
23695
24107
|
}
|
|
@@ -23751,7 +24163,7 @@ async function handler3(raw, ctx) {
|
|
|
23751
24163
|
const cwd = ctx.project.worktree;
|
|
23752
24164
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
23753
24165
|
if (input.file !== void 0) {
|
|
23754
|
-
const abs =
|
|
24166
|
+
const abs = resolve5(cwd, input.file);
|
|
23755
24167
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
23756
24168
|
if (bad !== null) return fail5(bad);
|
|
23757
24169
|
extra.CTX_FILE = abs;
|
|
@@ -23804,11 +24216,11 @@ var ctxExecute = {
|
|
|
23804
24216
|
};
|
|
23805
24217
|
|
|
23806
24218
|
// src/core/tools/index.ts
|
|
23807
|
-
import { existsSync as
|
|
23808
|
-
import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as
|
|
24219
|
+
import { existsSync as existsSync13, readFileSync as readFileSync13, statSync as statSync6 } from "node:fs";
|
|
24220
|
+
import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as resolve6 } from "node:path";
|
|
23809
24221
|
|
|
23810
24222
|
// src/core/index/walk.ts
|
|
23811
|
-
import { readdirSync as
|
|
24223
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync6, statSync as statSync5 } from "node:fs";
|
|
23812
24224
|
import { join as join15 } from "node:path";
|
|
23813
24225
|
var GITIGNORE = ".gitignore";
|
|
23814
24226
|
var GIT_DIR = ".git";
|
|
@@ -23823,7 +24235,7 @@ function walkDir(root, containmentRoot) {
|
|
|
23823
24235
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
23824
24236
|
let entries;
|
|
23825
24237
|
try {
|
|
23826
|
-
entries =
|
|
24238
|
+
entries = readdirSync6(abs, { withFileTypes: true });
|
|
23827
24239
|
} catch {
|
|
23828
24240
|
return;
|
|
23829
24241
|
}
|
|
@@ -24047,18 +24459,18 @@ function request(u, conn, proxy, signal) {
|
|
|
24047
24459
|
const host = bare(u.hostname);
|
|
24048
24460
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
24049
24461
|
const path5 = u.pathname + u.search;
|
|
24050
|
-
return new Promise((
|
|
24462
|
+
return new Promise((resolve7, reject) => {
|
|
24051
24463
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
24052
24464
|
if (proxy === void 0) {
|
|
24053
24465
|
const mod = u.protocol === "https:" ? https : http;
|
|
24054
24466
|
const req = mod.request({ host: conn.address, port, path: path5, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
24055
|
-
req.on("response",
|
|
24467
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24056
24468
|
return;
|
|
24057
24469
|
}
|
|
24058
24470
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
24059
24471
|
if (u.protocol === "http:") {
|
|
24060
24472
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
24061
|
-
req.on("response",
|
|
24473
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24062
24474
|
return;
|
|
24063
24475
|
}
|
|
24064
24476
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -24078,16 +24490,16 @@ function request(u, conn, proxy, signal) {
|
|
|
24078
24490
|
headers: { host: u.host },
|
|
24079
24491
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
24080
24492
|
});
|
|
24081
|
-
req.on("response",
|
|
24493
|
+
req.on("response", resolve7).on("error", onErr).end();
|
|
24082
24494
|
});
|
|
24083
24495
|
tunnel.end();
|
|
24084
24496
|
});
|
|
24085
24497
|
}
|
|
24086
24498
|
function readBody(res) {
|
|
24087
|
-
return new Promise((
|
|
24499
|
+
return new Promise((resolve7, reject) => {
|
|
24088
24500
|
const parts = [];
|
|
24089
24501
|
res.on("data", (b) => parts.push(b));
|
|
24090
|
-
res.on("end", () =>
|
|
24502
|
+
res.on("end", () => resolve7(Buffer.concat(parts)));
|
|
24091
24503
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
24092
24504
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
24093
24505
|
});
|
|
@@ -27809,17 +28221,17 @@ function list3(st, el) {
|
|
|
27809
28221
|
n += 1;
|
|
27810
28222
|
st.w.line();
|
|
27811
28223
|
st.w.push(marker, " ".repeat(marker.length));
|
|
27812
|
-
for (const k of c.children)
|
|
28224
|
+
for (const k of c.children) walk2(st, k);
|
|
27813
28225
|
st.w.pop();
|
|
27814
28226
|
st.w.line();
|
|
27815
28227
|
} else {
|
|
27816
|
-
|
|
28228
|
+
walk2(st, c);
|
|
27817
28229
|
}
|
|
27818
28230
|
}
|
|
27819
28231
|
if (st.w.depth() === 0) st.w.block();
|
|
27820
28232
|
else st.w.line();
|
|
27821
28233
|
}
|
|
27822
|
-
function
|
|
28234
|
+
function walk2(st, node3) {
|
|
27823
28235
|
if (isText2(node3)) {
|
|
27824
28236
|
st.w.text(collapse(node3.data));
|
|
27825
28237
|
return;
|
|
@@ -27859,7 +28271,7 @@ function walk(st, node3) {
|
|
|
27859
28271
|
case "blockquote":
|
|
27860
28272
|
st.w.block();
|
|
27861
28273
|
st.w.push("> ", "> ");
|
|
27862
|
-
for (const c of node3.children)
|
|
28274
|
+
for (const c of node3.children) walk2(st, c);
|
|
27863
28275
|
st.w.pop();
|
|
27864
28276
|
st.w.block();
|
|
27865
28277
|
return;
|
|
@@ -27882,7 +28294,7 @@ function walk(st, node3) {
|
|
|
27882
28294
|
const line = LINE.has(name);
|
|
27883
28295
|
if (para) st.w.block();
|
|
27884
28296
|
else if (line) st.w.line();
|
|
27885
|
-
for (const c of node3.children)
|
|
28297
|
+
for (const c of node3.children) walk2(st, c);
|
|
27886
28298
|
if (para) st.w.block();
|
|
27887
28299
|
else if (line) st.w.line();
|
|
27888
28300
|
}
|
|
@@ -27920,7 +28332,7 @@ function htmlToReadable(html, baseUrl) {
|
|
|
27920
28332
|
base = void 0;
|
|
27921
28333
|
}
|
|
27922
28334
|
const st = { w: new Writer(), base, sawH1: false };
|
|
27923
|
-
for (const n of contentRoot(doc.children))
|
|
28335
|
+
for (const n of contentRoot(doc.children)) walk2(st, n);
|
|
27924
28336
|
const body = st.w.result();
|
|
27925
28337
|
const words = wordCount(body);
|
|
27926
28338
|
const text = !st.sawH1 && title !== "" && words > 0 ? "# " + title + "\n\n" + body : body;
|
|
@@ -27960,12 +28372,12 @@ function readUtf8(absPath) {
|
|
|
27960
28372
|
}
|
|
27961
28373
|
function missingOrOutside(given, abs, root) {
|
|
27962
28374
|
let dir = abs;
|
|
27963
|
-
while (!
|
|
28375
|
+
while (!existsSync13(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
27964
28376
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
27965
28377
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
27966
28378
|
}
|
|
27967
28379
|
function pathItems(input, project) {
|
|
27968
|
-
const abs =
|
|
28380
|
+
const abs = resolve6(project.worktree, input.path);
|
|
27969
28381
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
27970
28382
|
const base = relative3(project.worktree, abs);
|
|
27971
28383
|
if (statSync6(abs).isDirectory()) {
|
|
@@ -28227,11 +28639,11 @@ var ctxStats = Object.freeze({
|
|
|
28227
28639
|
});
|
|
28228
28640
|
|
|
28229
28641
|
// src/core/tools/upgrade.ts
|
|
28230
|
-
import { existsSync as
|
|
28642
|
+
import { existsSync as existsSync19, realpathSync as realpathSync7, rmSync as rmSync9 } from "node:fs";
|
|
28231
28643
|
import { basename as basename5, dirname as dirname10, join as join22 } from "node:path";
|
|
28232
28644
|
|
|
28233
28645
|
// src/core/ops/host-write.ts
|
|
28234
|
-
import { copyFileSync, existsSync as
|
|
28646
|
+
import { copyFileSync, existsSync as existsSync14, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28235
28647
|
import { dirname as dirname9, join as join17 } from "node:path";
|
|
28236
28648
|
function defaultWrite(file2, text) {
|
|
28237
28649
|
writeFileSync4(file2, text, "utf8");
|
|
@@ -28260,7 +28672,7 @@ function toRow(file2, edit) {
|
|
|
28260
28672
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
28261
28673
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
28262
28674
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
28263
|
-
const had =
|
|
28675
|
+
const had = existsSync14(file2);
|
|
28264
28676
|
mkdirSync5(dirname9(file2), { recursive: true });
|
|
28265
28677
|
if (had) copyFileSync(file2, trash);
|
|
28266
28678
|
try {
|
|
@@ -28290,7 +28702,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28290
28702
|
if (requested === null) return [];
|
|
28291
28703
|
const current = readHostConfig(row5.id, requested);
|
|
28292
28704
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
28293
|
-
const exists =
|
|
28705
|
+
const exists = existsSync14(current.path);
|
|
28294
28706
|
if (exists && result.text === current.text) return [];
|
|
28295
28707
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
28296
28708
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -28298,7 +28710,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28298
28710
|
}
|
|
28299
28711
|
|
|
28300
28712
|
// src/core/ops/plugin-swap.ts
|
|
28301
|
-
import { existsSync as
|
|
28713
|
+
import { existsSync as existsSync15, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
28302
28714
|
import { basename as basename4, join as join18, win32 as win322 } from "node:path";
|
|
28303
28715
|
function linkTarget(path5, win) {
|
|
28304
28716
|
if (!isLink(path5)) return null;
|
|
@@ -28309,7 +28721,7 @@ function isLink(path5) {
|
|
|
28309
28721
|
return lstatSync(path5, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
28310
28722
|
}
|
|
28311
28723
|
function generations(agentDir) {
|
|
28312
|
-
return
|
|
28724
|
+
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();
|
|
28313
28725
|
}
|
|
28314
28726
|
function settleLinks(link, tmp, old, opts) {
|
|
28315
28727
|
if (isLink(tmp)) unlinkSync2(tmp);
|
|
@@ -28319,7 +28731,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
28319
28731
|
}
|
|
28320
28732
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
28321
28733
|
const next = join18(agentDir, sha);
|
|
28322
|
-
if (!
|
|
28734
|
+
if (!existsSync15(next) || !lstatSync(next).isDirectory()) {
|
|
28323
28735
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
|
|
28324
28736
|
}
|
|
28325
28737
|
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
@@ -28339,12 +28751,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
28339
28751
|
if (before !== null) keep.add(before);
|
|
28340
28752
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
|
|
28341
28753
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
28342
|
-
const previous = before !== null &&
|
|
28754
|
+
const previous = before !== null && existsSync15(join18(agentDir, before)) ? join18(agentDir, before) : null;
|
|
28343
28755
|
return { current: next, previous, removed };
|
|
28344
28756
|
}
|
|
28345
28757
|
|
|
28346
28758
|
// src/core/ops/release-fetch.ts
|
|
28347
|
-
import { existsSync as
|
|
28759
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
|
|
28348
28760
|
import { join as join19 } from "node:path";
|
|
28349
28761
|
function failed(r) {
|
|
28350
28762
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -28368,7 +28780,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
28368
28780
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
28369
28781
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
28370
28782
|
const dir = join19(agentDir, sha);
|
|
28371
|
-
if (
|
|
28783
|
+
if (existsSync16(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
28372
28784
|
else renameWithRetry(fetchDir, dir, opts);
|
|
28373
28785
|
return { sha, dir };
|
|
28374
28786
|
} catch (e) {
|
|
@@ -28378,7 +28790,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
28378
28790
|
}
|
|
28379
28791
|
|
|
28380
28792
|
// src/core/ops/uninstall.ts
|
|
28381
|
-
import { existsSync as
|
|
28793
|
+
import { existsSync as existsSync17, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28382
28794
|
import { join as join20 } from "node:path";
|
|
28383
28795
|
function row2(area, before, after) {
|
|
28384
28796
|
return { area, before, after };
|
|
@@ -28408,7 +28820,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
28408
28820
|
}
|
|
28409
28821
|
case "plugin": {
|
|
28410
28822
|
const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
28411
|
-
if (!
|
|
28823
|
+
if (!existsSync17(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
28412
28824
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
28413
28825
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
28414
28826
|
}
|
|
@@ -28488,9 +28900,9 @@ function removeOwnEntries(agent, env) {
|
|
|
28488
28900
|
function removeProjectData(configDir, projectKey) {
|
|
28489
28901
|
const projects = join20(configDir, PROJECTS_DIR_NAME);
|
|
28490
28902
|
const dir = join20(projects, projectKey);
|
|
28491
|
-
if (!
|
|
28903
|
+
if (!existsSync17(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
28492
28904
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
28493
|
-
for (const name of
|
|
28905
|
+
for (const name of readdirSync8(dir)) {
|
|
28494
28906
|
if (name !== OWNERS_DIR_NAME) rmSync7(join20(dir, name), { recursive: true, force: true });
|
|
28495
28907
|
}
|
|
28496
28908
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
@@ -28504,7 +28916,7 @@ function runUninstall(input) {
|
|
|
28504
28916
|
}
|
|
28505
28917
|
|
|
28506
28918
|
// src/core/ops/v1-remove.ts
|
|
28507
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
28919
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync18, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
|
|
28508
28920
|
var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
28509
28921
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
28510
28922
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -28585,14 +28997,14 @@ function removeV1(agent, findings) {
|
|
|
28585
28997
|
for (const f of findings) {
|
|
28586
28998
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
28587
28999
|
else if (f.path === "") {
|
|
28588
|
-
if (
|
|
29000
|
+
if (existsSync18(f.file)) {
|
|
28589
29001
|
moveAside(f.file, undo);
|
|
28590
29002
|
done.set(f, UPGRADE_REMOVED);
|
|
28591
29003
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
28592
29004
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
28593
29005
|
}
|
|
28594
29006
|
for (const [file2, list4] of entries) {
|
|
28595
|
-
if (!
|
|
29007
|
+
if (!existsSync18(file2)) {
|
|
28596
29008
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
28597
29009
|
continue;
|
|
28598
29010
|
}
|
|
@@ -28625,7 +29037,7 @@ function removeV1(agent, findings) {
|
|
|
28625
29037
|
},
|
|
28626
29038
|
rollback() {
|
|
28627
29039
|
for (const u of undo.splice(0).reverse()) {
|
|
28628
|
-
if (!
|
|
29040
|
+
if (!existsSync18(u.trash)) continue;
|
|
28629
29041
|
rmSync8(u.target, { recursive: true, force: true });
|
|
28630
29042
|
renameWithRetry(u.trash, u.target);
|
|
28631
29043
|
}
|
|
@@ -28635,7 +29047,7 @@ function removeV1(agent, findings) {
|
|
|
28635
29047
|
|
|
28636
29048
|
// src/core/ops/verify-sums.ts
|
|
28637
29049
|
import { createHash } from "node:crypto";
|
|
28638
|
-
import { lstatSync as lstatSync2, readdirSync as
|
|
29050
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync15 } from "node:fs";
|
|
28639
29051
|
import { join as join21 } from "node:path";
|
|
28640
29052
|
function mismatch() {
|
|
28641
29053
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
@@ -28653,12 +29065,12 @@ function parseSums(text) {
|
|
|
28653
29065
|
}
|
|
28654
29066
|
return sums;
|
|
28655
29067
|
}
|
|
28656
|
-
function
|
|
28657
|
-
for (const entry of
|
|
29068
|
+
function walk3(dir, prefix, out) {
|
|
29069
|
+
for (const entry of readdirSync9(dir, { withFileTypes: true })) {
|
|
28658
29070
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
28659
29071
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
28660
29072
|
const abs = join21(dir, entry.name);
|
|
28661
|
-
if (entry.isDirectory())
|
|
29073
|
+
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
28662
29074
|
else if (entry.isFile()) out.set(rel, abs);
|
|
28663
29075
|
else throw mismatch();
|
|
28664
29076
|
}
|
|
@@ -28669,7 +29081,7 @@ function verifySums(dir) {
|
|
|
28669
29081
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
28670
29082
|
const sums = parseSums(readFileSync15(sumsPath, "utf8"));
|
|
28671
29083
|
const files = /* @__PURE__ */ new Map();
|
|
28672
|
-
|
|
29084
|
+
walk3(dir, "", files);
|
|
28673
29085
|
if (files.size !== sums.size) throw mismatch();
|
|
28674
29086
|
for (const [rel, abs] of files) {
|
|
28675
29087
|
const want = sums.get(rel);
|
|
@@ -28703,7 +29115,7 @@ function pluginRootRow(adapter, env) {
|
|
|
28703
29115
|
}
|
|
28704
29116
|
function isCurrent(agentDir, dir) {
|
|
28705
29117
|
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
28706
|
-
return
|
|
29118
|
+
return existsSync19(link) && realpathSync7.native(link) === realpathSync7.native(dir);
|
|
28707
29119
|
}
|
|
28708
29120
|
async function checkout(adapter, deps) {
|
|
28709
29121
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -28823,8 +29235,8 @@ function checkCall(tool, input) {
|
|
|
28823
29235
|
|
|
28824
29236
|
// src/entries/server.ts
|
|
28825
29237
|
import { randomUUID } from "node:crypto";
|
|
28826
|
-
import { existsSync as
|
|
28827
|
-
import { join as join24 } from "node:path";
|
|
29238
|
+
import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync11 } from "node:fs";
|
|
29239
|
+
import { dirname as dirname11, join as join24 } from "node:path";
|
|
28828
29240
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
28829
29241
|
|
|
28830
29242
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -32303,7 +32715,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
32303
32715
|
var NONE3 = 0;
|
|
32304
32716
|
var ASSUMED = 1;
|
|
32305
32717
|
var PROVEN = 2;
|
|
32306
|
-
function isRecursive(inst, stack,
|
|
32718
|
+
function isRecursive(inst, stack, resolve7) {
|
|
32307
32719
|
const cached4 = recursive.get(inst);
|
|
32308
32720
|
if (cached4 !== void 0)
|
|
32309
32721
|
return cached4 ? PROVEN : NONE3;
|
|
@@ -32313,7 +32725,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
32313
32725
|
let result = NONE3;
|
|
32314
32726
|
const check2 = (child) => {
|
|
32315
32727
|
if (result !== PROVEN && child?._zod) {
|
|
32316
|
-
const answer2 = isRecursive(child, stack,
|
|
32728
|
+
const answer2 = isRecursive(child, stack, resolve7);
|
|
32317
32729
|
if (answer2 > result)
|
|
32318
32730
|
result = answer2;
|
|
32319
32731
|
}
|
|
@@ -32324,7 +32736,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
32324
32736
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
32325
32737
|
if (spread && !desc.enumerable)
|
|
32326
32738
|
continue;
|
|
32327
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
32739
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve7) : NONE3;
|
|
32328
32740
|
if (child > answer2)
|
|
32329
32741
|
answer2 = child;
|
|
32330
32742
|
}
|
|
@@ -32388,7 +32800,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
32388
32800
|
break;
|
|
32389
32801
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
32390
32802
|
case "lazy": {
|
|
32391
|
-
const inner = def._cachedInner ?? (
|
|
32803
|
+
const inner = def._cachedInner ?? (resolve7 ? inst._zod.innerType : void 0);
|
|
32392
32804
|
merge5(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
32393
32805
|
break;
|
|
32394
32806
|
}
|
|
@@ -39832,7 +40244,7 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
|
|
|
39832
40244
|
var NONE4 = 0;
|
|
39833
40245
|
var ASSUMED2 = 1;
|
|
39834
40246
|
var PROVEN2 = 2;
|
|
39835
|
-
function isRecursive2(inst, stack,
|
|
40247
|
+
function isRecursive2(inst, stack, resolve7) {
|
|
39836
40248
|
const cached4 = recursive2.get(inst);
|
|
39837
40249
|
if (cached4 !== void 0)
|
|
39838
40250
|
return cached4 ? PROVEN2 : NONE4;
|
|
@@ -39842,7 +40254,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
39842
40254
|
let result = NONE4;
|
|
39843
40255
|
const check2 = (child) => {
|
|
39844
40256
|
if (result !== PROVEN2 && child?._zod) {
|
|
39845
|
-
const answer2 = isRecursive2(child, stack,
|
|
40257
|
+
const answer2 = isRecursive2(child, stack, resolve7);
|
|
39846
40258
|
if (answer2 > result)
|
|
39847
40259
|
result = answer2;
|
|
39848
40260
|
}
|
|
@@ -39853,7 +40265,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
39853
40265
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
39854
40266
|
if (spread && !desc.enumerable)
|
|
39855
40267
|
continue;
|
|
39856
|
-
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack,
|
|
40268
|
+
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve7) : NONE4;
|
|
39857
40269
|
if (child > answer2)
|
|
39858
40270
|
answer2 = child;
|
|
39859
40271
|
}
|
|
@@ -39917,7 +40329,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
39917
40329
|
break;
|
|
39918
40330
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
39919
40331
|
case "lazy": {
|
|
39920
|
-
const inner = def._cachedInner ?? (
|
|
40332
|
+
const inner = def._cachedInner ?? (resolve7 ? inst._zod.innerType : void 0);
|
|
39921
40333
|
merge5(inner ? isRecursive2(inner, stack, false) : ASSUMED2);
|
|
39922
40334
|
break;
|
|
39923
40335
|
}
|
|
@@ -46521,14 +46933,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
|
|
|
46521
46933
|
return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
|
|
46522
46934
|
}
|
|
46523
46935
|
function sleep(ms, signal) {
|
|
46524
|
-
return new Promise((
|
|
46936
|
+
return new Promise((resolve7, reject) => {
|
|
46525
46937
|
if (signal?.aborted) {
|
|
46526
46938
|
reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
|
|
46527
46939
|
return;
|
|
46528
46940
|
}
|
|
46529
46941
|
const timer = setTimeout(() => {
|
|
46530
46942
|
signal?.removeEventListener("abort", onAbort);
|
|
46531
|
-
|
|
46943
|
+
resolve7();
|
|
46532
46944
|
}, ms);
|
|
46533
46945
|
const onAbort = () => {
|
|
46534
46946
|
clearTimeout(timer);
|
|
@@ -47327,7 +47739,7 @@ var Protocol = class {
|
|
|
47327
47739
|
const flowStartedAt = Date.now();
|
|
47328
47740
|
let onAbort;
|
|
47329
47741
|
let cleanupMessageId;
|
|
47330
|
-
return new Promise((
|
|
47742
|
+
return new Promise((resolve7, reject) => {
|
|
47331
47743
|
const earlyReject = (error42) => {
|
|
47332
47744
|
reject(error42);
|
|
47333
47745
|
};
|
|
@@ -47396,7 +47808,7 @@ var Protocol = class {
|
|
|
47396
47808
|
}
|
|
47397
47809
|
if (decoded.kind === "invalid") return reject(decoded.error);
|
|
47398
47810
|
if (decoded.kind === "input_required") {
|
|
47399
|
-
if (options?.allowInputRequired === true) return
|
|
47811
|
+
if (options?.allowInputRequired === true) return resolve7(manualInputRequiredValue(decoded));
|
|
47400
47812
|
const flow = {
|
|
47401
47813
|
codec,
|
|
47402
47814
|
request: request2,
|
|
@@ -47408,11 +47820,11 @@ var Protocol = class {
|
|
|
47408
47820
|
params
|
|
47409
47821
|
}, resultSchema, legOptions)
|
|
47410
47822
|
};
|
|
47411
|
-
return
|
|
47823
|
+
return resolve7(this._resolveNonCompleteResult(decoded, flow));
|
|
47412
47824
|
}
|
|
47413
47825
|
const result = decoded.result;
|
|
47414
47826
|
validateStandardSchema(resultSchema, result).then((parseResult) => {
|
|
47415
|
-
if (parseResult.success)
|
|
47827
|
+
if (parseResult.success) resolve7(parseResult.data);
|
|
47416
47828
|
else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request2.method}: ${parseResult.error}`));
|
|
47417
47829
|
}, reject);
|
|
47418
47830
|
});
|
|
@@ -50328,7 +50740,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
50328
50740
|
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
|
|
50329
50741
|
const schOrFunc = root.refs[ref];
|
|
50330
50742
|
if (schOrFunc) return schOrFunc;
|
|
50331
|
-
let _sch =
|
|
50743
|
+
let _sch = resolve7.call(this, root, ref);
|
|
50332
50744
|
if (_sch === void 0) {
|
|
50333
50745
|
const schema = (_a5 = root.localRefs) === null || _a5 === void 0 ? void 0 : _a5[ref];
|
|
50334
50746
|
const { schemaId } = this.opts;
|
|
@@ -50354,7 +50766,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
50354
50766
|
function sameSchemaEnv(s1, s2) {
|
|
50355
50767
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
50356
50768
|
}
|
|
50357
|
-
function
|
|
50769
|
+
function resolve7(root, ref) {
|
|
50358
50770
|
let sch;
|
|
50359
50771
|
while (typeof (sch = this.refs[ref]) == "string") ref = sch;
|
|
50360
50772
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
@@ -50804,7 +51216,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
50804
51216
|
else if (typeof uri === "object") uri = parse6(serialize(uri, options), options);
|
|
50805
51217
|
return uri;
|
|
50806
51218
|
}
|
|
50807
|
-
function
|
|
51219
|
+
function resolve7(baseURI, relativeURI, options) {
|
|
50808
51220
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
50809
51221
|
const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
50810
51222
|
schemelessOptions.skipEscape = true;
|
|
@@ -50978,7 +51390,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
50978
51390
|
const fastUri = {
|
|
50979
51391
|
SCHEMES,
|
|
50980
51392
|
normalize: normalize2,
|
|
50981
|
-
resolve:
|
|
51393
|
+
resolve: resolve7,
|
|
50982
51394
|
resolveComponent,
|
|
50983
51395
|
equal,
|
|
50984
51396
|
serialize,
|
|
@@ -56443,7 +56855,7 @@ var StdioServerTransport = class {
|
|
|
56443
56855
|
}
|
|
56444
56856
|
send(message3) {
|
|
56445
56857
|
if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
|
|
56446
|
-
return new Promise((
|
|
56858
|
+
return new Promise((resolve7, reject) => {
|
|
56447
56859
|
const json2 = serializeMessage(message3);
|
|
56448
56860
|
let settled = false;
|
|
56449
56861
|
const onError = (error42) => {
|
|
@@ -56458,14 +56870,14 @@ var StdioServerTransport = class {
|
|
|
56458
56870
|
settled = true;
|
|
56459
56871
|
this._stdout.off("error", onError);
|
|
56460
56872
|
this._stdout.off("drain", onDrain);
|
|
56461
|
-
|
|
56873
|
+
resolve7();
|
|
56462
56874
|
};
|
|
56463
56875
|
this._stdout.once("error", onError);
|
|
56464
56876
|
if (this._stdout.write(json2)) {
|
|
56465
56877
|
if (settled) return;
|
|
56466
56878
|
settled = true;
|
|
56467
56879
|
this._stdout.off("error", onError);
|
|
56468
|
-
|
|
56880
|
+
resolve7();
|
|
56469
56881
|
} else if (!settled) this._stdout.once("drain", onDrain);
|
|
56470
56882
|
});
|
|
56471
56883
|
}
|
|
@@ -56519,14 +56931,14 @@ var StdioConnectionChannel = class {
|
|
|
56519
56931
|
*/
|
|
56520
56932
|
async whenRequestsAnswered(timeoutMs) {
|
|
56521
56933
|
if (this._closed || this._pendingRequests.size === 0) return true;
|
|
56522
|
-
return await new Promise((
|
|
56934
|
+
return await new Promise((resolve7) => {
|
|
56523
56935
|
const waiter = () => {
|
|
56524
56936
|
clearTimeout(timer);
|
|
56525
|
-
|
|
56937
|
+
resolve7(true);
|
|
56526
56938
|
};
|
|
56527
56939
|
const timer = setTimeout(() => {
|
|
56528
56940
|
this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
|
|
56529
|
-
|
|
56941
|
+
resolve7(false);
|
|
56530
56942
|
}, timeoutMs);
|
|
56531
56943
|
this._drainWaiters.push(waiter);
|
|
56532
56944
|
});
|
|
@@ -56889,7 +57301,7 @@ function installExitGuard(opts) {
|
|
|
56889
57301
|
}
|
|
56890
57302
|
|
|
56891
57303
|
// src/core/store/cleanup.ts
|
|
56892
|
-
import { existsSync as
|
|
57304
|
+
import { existsSync as existsSync20, readdirSync as readdirSync10, rmSync as rmSync10 } from "node:fs";
|
|
56893
57305
|
import { join as join23 } from "node:path";
|
|
56894
57306
|
function deleteSource(raw, id) {
|
|
56895
57307
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
@@ -56925,7 +57337,7 @@ function userVersion(raw) {
|
|
|
56925
57337
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
56926
57338
|
}
|
|
56927
57339
|
function openForSweep(dbPath, projectKey) {
|
|
56928
|
-
if (!
|
|
57340
|
+
if (!existsSync20(dbPath) && (existsSync20(dbPath + DB_WAL_SUFFIX) || existsSync20(dbPath + DB_SHM_SUFFIX))) {
|
|
56929
57341
|
throw new CtxError("DB_GONE");
|
|
56930
57342
|
}
|
|
56931
57343
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -56960,7 +57372,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
56960
57372
|
function sweepDeadProjects(configDir) {
|
|
56961
57373
|
let entries;
|
|
56962
57374
|
try {
|
|
56963
|
-
entries =
|
|
57375
|
+
entries = readdirSync10(join23(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
56964
57376
|
} catch (err) {
|
|
56965
57377
|
if (err.code === "ENOENT") return [];
|
|
56966
57378
|
throw err;
|
|
@@ -57045,6 +57457,32 @@ function sessionIdOf(meta3, agent, env, serverId) {
|
|
|
57045
57457
|
if (typeof fromHost === "string" && fromHost !== "") return fromHost;
|
|
57046
57458
|
return RUN_SESSION_PREFIX + serverId;
|
|
57047
57459
|
}
|
|
57460
|
+
var CODEX_SANDBOX_STATE_META = "codex/sandbox-state-meta";
|
|
57461
|
+
var FILE_URL_PREFIX = "file:";
|
|
57462
|
+
function workspaceFromMeta(meta3) {
|
|
57463
|
+
const state = meta3?.[CODEX_SANDBOX_STATE_META];
|
|
57464
|
+
const cwd = typeof state === "object" && state !== null ? state.sandboxCwd : void 0;
|
|
57465
|
+
if (typeof cwd !== "string" || cwd === "") return void 0;
|
|
57466
|
+
if (!cwd.startsWith(FILE_URL_PREFIX)) return cwd;
|
|
57467
|
+
try {
|
|
57468
|
+
return fileURLToPath2(cwd);
|
|
57469
|
+
} catch {
|
|
57470
|
+
return void 0;
|
|
57471
|
+
}
|
|
57472
|
+
}
|
|
57473
|
+
function realOrSame(p) {
|
|
57474
|
+
try {
|
|
57475
|
+
return realpathSync9.native(p);
|
|
57476
|
+
} catch {
|
|
57477
|
+
return p;
|
|
57478
|
+
}
|
|
57479
|
+
}
|
|
57480
|
+
function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
57481
|
+
const fromHost = workspaceFromMeta(meta3);
|
|
57482
|
+
if (fromHost !== void 0) return fromHost;
|
|
57483
|
+
if (script === void 0 || script === "") return spawnCwd;
|
|
57484
|
+
return realOrSame(spawnCwd) === realOrSame(dirname11(script)) ? "" : spawnCwd;
|
|
57485
|
+
}
|
|
57048
57486
|
function errorReply(err) {
|
|
57049
57487
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
57050
57488
|
console.error(err);
|
|
@@ -57082,7 +57520,7 @@ async function startServer(argv, env) {
|
|
|
57082
57520
|
opening.catch(() => pending.delete(project.dbPath));
|
|
57083
57521
|
}
|
|
57084
57522
|
const db = await opening;
|
|
57085
|
-
if (!
|
|
57523
|
+
if (!existsSync21(db.path)) throw new CtxError("DB_GONE");
|
|
57086
57524
|
return db;
|
|
57087
57525
|
}
|
|
57088
57526
|
function stopMarker(configDir, projectKey) {
|
|
@@ -57090,7 +57528,7 @@ async function startServer(argv, env) {
|
|
|
57090
57528
|
}
|
|
57091
57529
|
function stopRequested() {
|
|
57092
57530
|
const configDir = resolveConfigDir(process.env);
|
|
57093
|
-
return held.some((db) =>
|
|
57531
|
+
return held.some((db) => existsSync21(stopMarker(configDir, db.projectKey)));
|
|
57094
57532
|
}
|
|
57095
57533
|
async function journal(project, ctx, name, reply4) {
|
|
57096
57534
|
const db = await ownDb(project);
|
|
@@ -57103,7 +57541,7 @@ async function startServer(argv, env) {
|
|
|
57103
57541
|
let project;
|
|
57104
57542
|
const projectOf = () => {
|
|
57105
57543
|
if (agent === void 0) throw new CtxError("NO_PROJECT", { kind: "--agent" });
|
|
57106
|
-
project ??= resolveProject(agent, { env, argv, cwd: process.cwd(), piCwd: void 0 });
|
|
57544
|
+
project ??= resolveProject(agent, { env, argv, cwd: workspaceCwdOf(meta3, process.cwd(), process.argv[1]), piCwd: void 0 });
|
|
57107
57545
|
return project;
|
|
57108
57546
|
};
|
|
57109
57547
|
const ctx = {
|
|
@@ -57155,6 +57593,7 @@ async function startServer(argv, env) {
|
|
|
57155
57593
|
// DEVIATIONS: no version constant in contracts yet
|
|
57156
57594
|
{
|
|
57157
57595
|
instructions: INSTRUCTIONS,
|
|
57596
|
+
capabilities: { experimental: { [CODEX_SANDBOX_STATE_META]: {} } },
|
|
57158
57597
|
cacheHints: {
|
|
57159
57598
|
"tools/list": { ttlMs: TOOLS_TTL_MS, cacheScope: "public" },
|
|
57160
57599
|
"server/discover": { ttlMs: TOOLS_TTL_MS, cacheScope: "public" }
|
|
@@ -57196,7 +57635,7 @@ async function startServer(argv, env) {
|
|
|
57196
57635
|
}
|
|
57197
57636
|
installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
|
|
57198
57637
|
handle = serveStdio(createServer);
|
|
57199
|
-
await new Promise((
|
|
57638
|
+
await new Promise((resolve7) => process.once("exit", () => resolve7()));
|
|
57200
57639
|
}
|
|
57201
57640
|
if (isEntry(import.meta.main, process.argv[1], fileURLToPath2(import.meta.url))) {
|
|
57202
57641
|
const [, , ...cliArgs] = process.argv;
|