context-mode 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/hooks.json +50 -0
- package/.zcode-plugin/plugin.json +20 -0
- package/README.md +78 -79
- package/SHA256SUMS +17 -15
- package/cli.mjs +326 -148
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +99 -97
- package/opencode/plugin.js +680 -521
- package/package.json +2 -1
- package/pi/index.js +769 -589
- package/qwen-extension.json +1 -1
- package/run.mjs +256 -99
- package/search.mjs +256 -99
- package/server.mjs +536 -447
package/opencode/plugin.js
CHANGED
|
@@ -24,6 +24,8 @@ var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
|
24
24
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
25
25
|
var SYNC_INDEX_MAX_BYTES = 65536;
|
|
26
26
|
var REPLACE_TRIGGER_BYTES = 4096;
|
|
27
|
+
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
28
|
+
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
27
29
|
var REPLACE_RETURN_BYTES = 96;
|
|
28
30
|
var SHAPE_RETURN_BYTES = 256;
|
|
29
31
|
var REPLACE_CHUNK_BYTES = 48;
|
|
@@ -204,6 +206,7 @@ var GIT_COMMONDIR_FILE = "commondir";
|
|
|
204
206
|
var GIT_HEAD_FILE = "HEAD";
|
|
205
207
|
var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
|
|
206
208
|
var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
|
|
209
|
+
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
207
210
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
208
211
|
var FETCH_MAX_HOPS = 5;
|
|
209
212
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
@@ -214,6 +217,7 @@ var RUN_LABEL_PREFIX = "run.mjs:";
|
|
|
214
217
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
215
218
|
var NODE_MIN = "24.15.0";
|
|
216
219
|
var DATA_ROOT = "~/.context-mode";
|
|
220
|
+
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
217
221
|
var INTERNAL_ERROR_LINE = "Internal error. Fix: run ctx_doctor.";
|
|
218
222
|
var REQUIRE_SECURITY_ENV = "CONTEXT_MODE_REQUIRE_SECURITY";
|
|
219
223
|
var HOST_CONFIG_DIR_NAME = ".claude";
|
|
@@ -316,7 +320,8 @@ var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
|
316
320
|
var SED_COMMAND = "sed";
|
|
317
321
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
318
322
|
var JQ_COMMAND = "jq";
|
|
319
|
-
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path"]);
|
|
323
|
+
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
|
|
324
|
+
var READ_PATH_LIST_KEY = "filePaths";
|
|
320
325
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
321
326
|
var SHELL_TOOL = "Bash";
|
|
322
327
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
@@ -332,6 +337,7 @@ var RECALL_MIN_SCORE = 5;
|
|
|
332
337
|
var RECALL_MAX_ROWS = 340;
|
|
333
338
|
var COMPACTED_META_PREFIX = "compacted:";
|
|
334
339
|
var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
|
|
340
|
+
var UNITS_ANCESTOR_FACTOR = 8;
|
|
335
341
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
336
342
|
var RECALL_SEEN_META_PREFIX = "recall_seen:";
|
|
337
343
|
var RECALL_OPEN_TAG = "<context_mode_recall>";
|
|
@@ -425,8 +431,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
425
431
|
var DECISION_OPTION_KEY = "option";
|
|
426
432
|
var DECISION_LABEL_JOIN = " | ";
|
|
427
433
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
428
|
-
var
|
|
429
|
-
var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
|
|
434
|
+
var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
|
|
430
435
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
431
436
|
var DOCTOR_LABEL = Object.freeze({
|
|
432
437
|
D1: "version",
|
|
@@ -566,7 +571,6 @@ function D9_INDEX_DETAIL(sources, chunks) {
|
|
|
566
571
|
var PLUGIN_CACHE_DIR_NAME = "cache";
|
|
567
572
|
var DATA_PLUGINS_DIR_NAME = "plugins";
|
|
568
573
|
var PLUGIN_CURRENT_LINK = "current";
|
|
569
|
-
var RELEASE_SUMS_FILE = "SHA256SUMS";
|
|
570
574
|
var EXTENSIONS_DIR_NAME = "extensions";
|
|
571
575
|
var AGENT_HOME_DIR = Object.freeze({
|
|
572
576
|
"claude-code": [".claude"],
|
|
@@ -589,7 +593,6 @@ var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
|
589
593
|
var UPGRADE_TABLE_HEADER = "| Area | Before | After |";
|
|
590
594
|
var UPGRADE_TABLE_RULE = "|---|---|---|";
|
|
591
595
|
var UPGRADE_PLUGIN_ROOT_AREA = "plugin root";
|
|
592
|
-
var UPGRADE_CHECKOUT_AREA = "plugin checkout";
|
|
593
596
|
var UPGRADE_SERVER_AREA = "server";
|
|
594
597
|
var UPGRADE_SERVER_RUNNING = "running";
|
|
595
598
|
var UPGRADE_SERVER_STOPPED = "stopped after this reply";
|
|
@@ -599,25 +602,21 @@ var UPGRADE_DATA_AREA = "user data";
|
|
|
599
602
|
var UPGRADE_REPORT_ONLY = "report only: remove it by hand if you no longer use it";
|
|
600
603
|
var UPGRADE_AREA_KEY_SEP = ": ";
|
|
601
604
|
var V1_KEY_PATH_SEP = ".";
|
|
602
|
-
var UPGRADE_GIT_TIMEOUT_MS = 12e4;
|
|
603
605
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
604
606
|
var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
|
|
605
|
-
var UPGRADE_FETCH_DIR_PREFIX = ".fetch-";
|
|
606
|
-
var SUMS_LINE_SEP = " ";
|
|
607
|
-
var SUMS_HASH_ALGORITHM = "sha256";
|
|
608
|
-
var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
|
|
609
|
-
var UPGRADE_HOST_MANUAL = "update with the host's own install command, then restart";
|
|
610
607
|
var UPGRADE_CONFIG_AREA = "host config";
|
|
611
608
|
var UPGRADE_OWN_ENTRY = "context-mode entry";
|
|
612
609
|
var UPGRADE_CACHE_BY_HAND = "remove the release dir by hand: its place is your choice";
|
|
613
610
|
var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
|
|
614
611
|
var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
|
|
615
|
-
var GIT_NOT_STARTED = "git did not start";
|
|
616
612
|
var GIT_BIN = "git";
|
|
617
613
|
var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
|
|
618
614
|
var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
|
|
619
|
-
var GIT_EXIT_LABEL = "git exit ";
|
|
620
615
|
var UPGRADE_TRASH_SUFFIX = ".ctx-upgrade-removing";
|
|
616
|
+
var UPGRADE_ASIDE_SUFFIX = ".ctx-v1-old";
|
|
617
|
+
var UPGRADE_MOVED_ASIDE = "moved aside to ";
|
|
618
|
+
var CLAUDE_TOOL_RESULTS_DIR_NAME = "tool-results";
|
|
619
|
+
var PERSISTED_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
|
|
621
620
|
var TABLE_ROW_START = "| ";
|
|
622
621
|
var TABLE_CELL_SEP = " | ";
|
|
623
622
|
var TABLE_ROW_END = " |";
|
|
@@ -629,7 +628,6 @@ var OPS_SPLIT_FILES = Object.freeze([
|
|
|
629
628
|
"doctor-hook.ts",
|
|
630
629
|
"doctor-db.ts",
|
|
631
630
|
"doctor-heal.ts",
|
|
632
|
-
"release-fetch.ts",
|
|
633
631
|
"verify-sums.ts",
|
|
634
632
|
"plugin-swap.ts",
|
|
635
633
|
"host-write.ts",
|
|
@@ -685,6 +683,7 @@ var REGEX_SPECIAL_CHARS = ".*+?^${}()|[]\\";
|
|
|
685
683
|
var REGEX_ESCAPE = "\\";
|
|
686
684
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
687
685
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
686
|
+
var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
|
|
688
687
|
var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
|
|
689
688
|
function D5_SLOW_DETAIL(ms) {
|
|
690
689
|
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
@@ -704,19 +703,19 @@ function D11_PASS_DETAIL(shell, win) {
|
|
|
704
703
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
705
704
|
var HEAL_TMP_SUFFIX = ".heal";
|
|
706
705
|
var HEAL_TS_SEP = ".";
|
|
707
|
-
var SUMS_LINE_END = "\n";
|
|
708
|
-
var HASH_ENCODING = "hex";
|
|
709
|
-
var PLUGIN_LINK_TMP_SUFFIX = ".swap";
|
|
710
|
-
var PLUGIN_LINK_OLD_SUFFIX = ".old";
|
|
711
|
-
var PLUGIN_LINK_TYPE = "dir";
|
|
712
|
-
var PLUGIN_LINK_TYPE_WIN32 = "junction";
|
|
713
706
|
var OWNER_STOP_EXT = ".stop";
|
|
714
707
|
var UPGRADE_DATA_DELETED = "user data deleted";
|
|
715
708
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
716
709
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
717
|
-
codex: "
|
|
718
|
-
gemini: "gemini extensions
|
|
719
|
-
qwen: "qwen extensions
|
|
710
|
+
codex: "codex plugin marketplace upgrade context-mode",
|
|
711
|
+
gemini: "gemini extensions update context-mode",
|
|
712
|
+
qwen: "qwen extensions update context-mode",
|
|
713
|
+
pi: "pi update --extensions",
|
|
714
|
+
opencode: "opencode plugin update",
|
|
715
|
+
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
716
|
+
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
717
|
+
kiro: "npm i -g context-mode && context-mode setup --agents kiro",
|
|
718
|
+
zcode: "npm i -g context-mode && context-mode setup --agents zcode"
|
|
720
719
|
});
|
|
721
720
|
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
722
721
|
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
@@ -758,6 +757,7 @@ var HOOKS_JSON_FILE = "hooks.json";
|
|
|
758
757
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
759
758
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
760
759
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
760
|
+
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
761
761
|
var KIRO_HOME_ENV = "KIRO_HOME";
|
|
762
762
|
var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
|
|
763
763
|
var APPDATA_ENV = "APPDATA";
|
|
@@ -786,8 +786,12 @@ var STATUS_LINE_KEY = "statusLine";
|
|
|
786
786
|
var PI_PACKAGES_KEY = "packages";
|
|
787
787
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
788
788
|
var OPENCODE_PLUGINS_KEY = "plugins";
|
|
789
|
+
var OPENCODE_MCP_COMMAND_FIELD = "command";
|
|
789
790
|
var OPENCODE_PACKAGE_FIELD = "package";
|
|
790
791
|
var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
|
|
792
|
+
var NPM_VERSION_SEP = "@";
|
|
793
|
+
var OPENCODE_NPM_LATEST = `${OPENCODE_NPM_SPEC_PREFIX}latest`;
|
|
794
|
+
var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
|
|
791
795
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
792
796
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
793
797
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -816,18 +820,21 @@ var V1_REASON = Object.freeze({
|
|
|
816
820
|
kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
|
|
817
821
|
piNpm: "old context-mode Pi package npm:context-mode",
|
|
818
822
|
opencodePlugin: "old context-mode OpenCode plugin spec context-mode",
|
|
823
|
+
piGit: "old context-mode Pi entry git:github.com/mksglu/context-mode@release: ctx_upgrade replaces it with npm:context-mode@latest",
|
|
824
|
+
opencodeGit: "old context-mode OpenCode entry git+https://github.com/mksglu/context-mode.git#release: ctx_upgrade replaces it with context-mode@latest",
|
|
819
825
|
zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
|
|
820
826
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
821
827
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
822
828
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
823
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
829
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep",
|
|
830
|
+
projectLink: "context-mode path in the project reached through a link: report only, upgrade keeps it as is and never follows a link"
|
|
824
831
|
});
|
|
825
|
-
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
832
|
+
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering, V1_REASON.piGit, V1_REASON.opencodeGit, V1_REASON.projectLink]);
|
|
833
|
+
var UPGRADE_KEEP_ASIDE_REASONS = Object.freeze([V1_REASON.dataDir, V1_REASON.dataRoot]);
|
|
826
834
|
var PLUGIN_ID = SERVER_KEY;
|
|
827
835
|
var PLUGIN_NAME = SERVER_KEY;
|
|
828
836
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
829
837
|
var SERVER_ENTRY_FILE = "server.mjs";
|
|
830
|
-
var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
|
|
831
838
|
var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
|
|
832
839
|
var HOST_NODE_COMMAND = "node";
|
|
833
840
|
var EXE_SUFFIX = ".exe";
|
|
@@ -950,7 +957,7 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
950
957
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
951
958
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
952
959
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
953
|
-
zcode: ["
|
|
960
|
+
zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
|
|
954
961
|
});
|
|
955
962
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
956
963
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
@@ -1028,7 +1035,7 @@ var CtxError = class extends Error {
|
|
|
1028
1035
|
};
|
|
1029
1036
|
|
|
1030
1037
|
// src/core/hooks/dispatch.ts
|
|
1031
|
-
import { dirname as dirname4, join as
|
|
1038
|
+
import { dirname as dirname4, join as join7, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
|
|
1032
1039
|
|
|
1033
1040
|
// src/core/contracts/agents.ts
|
|
1034
1041
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -1046,9 +1053,9 @@ function canonicalName(name, ownPrefix) {
|
|
|
1046
1053
|
if (name.startsWith(ownPrefix)) return name.slice(ownPrefix.length);
|
|
1047
1054
|
if (!name.startsWith(MCP_PREFIX)) return name;
|
|
1048
1055
|
const rest = name.slice(MCP_PREFIX.length);
|
|
1049
|
-
const
|
|
1050
|
-
if (
|
|
1051
|
-
return "mcp:" + rest.slice(0,
|
|
1056
|
+
const sep5 = rest.indexOf(MCP_SEP);
|
|
1057
|
+
if (sep5 < 0) return name;
|
|
1058
|
+
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP.length);
|
|
1052
1059
|
}
|
|
1053
1060
|
function outputOf(resp) {
|
|
1054
1061
|
if (resp === void 0) return "";
|
|
@@ -1248,6 +1255,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
|
1248
1255
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
1249
1256
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
1250
1257
|
var EMPTY = { stdout: "", exitCode: 0 };
|
|
1258
|
+
var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its full output, and this is the part that answers the call:\n";
|
|
1251
1259
|
function own(p, key) {
|
|
1252
1260
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
1253
1261
|
}
|
|
@@ -1267,13 +1275,67 @@ function canonicalName2(name, mcp) {
|
|
|
1267
1275
|
if (typeof server2 !== "string" || typeof tool !== "string") return name;
|
|
1268
1276
|
return "mcp:" + server2 + ":" + tool;
|
|
1269
1277
|
}
|
|
1278
|
+
function partsText(llm) {
|
|
1279
|
+
if (!Array.isArray(llm) || llm.length === 0) return void 0;
|
|
1280
|
+
const out = [];
|
|
1281
|
+
for (const part of llm) {
|
|
1282
|
+
if (typeof part === "string") {
|
|
1283
|
+
out.push(part);
|
|
1284
|
+
continue;
|
|
1285
|
+
}
|
|
1286
|
+
if (typeof part !== "object" || part === null) return void 0;
|
|
1287
|
+
const t = own(part, "text");
|
|
1288
|
+
if (typeof t !== "string") return void 0;
|
|
1289
|
+
out.push(t);
|
|
1290
|
+
}
|
|
1291
|
+
return out.join("");
|
|
1292
|
+
}
|
|
1270
1293
|
function readResult2(resp) {
|
|
1271
1294
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
1272
1295
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
1273
|
-
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : JSON.stringify(resp);
|
|
1296
|
+
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
1274
1297
|
const err = obj === void 0 ? void 0 : own(obj, "error");
|
|
1275
1298
|
return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
|
|
1276
1299
|
}
|
|
1300
|
+
var URL_STARTS = ["https://", "http://"];
|
|
1301
|
+
var URL_TRAIL = `.,;:!?)]}>'"`;
|
|
1302
|
+
var SPACE = " \n\r\f\v";
|
|
1303
|
+
function words(text) {
|
|
1304
|
+
const out = [];
|
|
1305
|
+
let cur = "";
|
|
1306
|
+
for (const ch of text) {
|
|
1307
|
+
if (SPACE.includes(ch)) {
|
|
1308
|
+
if (cur !== "") out.push(cur);
|
|
1309
|
+
cur = "";
|
|
1310
|
+
} else cur += ch;
|
|
1311
|
+
}
|
|
1312
|
+
if (cur !== "") out.push(cur);
|
|
1313
|
+
return out;
|
|
1314
|
+
}
|
|
1315
|
+
function firstUrl(prompt) {
|
|
1316
|
+
if (typeof prompt !== "string") return void 0;
|
|
1317
|
+
for (const word of words(prompt)) {
|
|
1318
|
+
const lower = word.toLowerCase();
|
|
1319
|
+
const at2 = URL_STARTS.map((s) => lower.indexOf(s)).filter((i) => i >= 0).sort((a, b) => a - b)[0];
|
|
1320
|
+
if (at2 === void 0) continue;
|
|
1321
|
+
let url2 = word.slice(at2);
|
|
1322
|
+
while (url2.length > 0 && URL_TRAIL.includes(url2[url2.length - 1])) url2 = url2.slice(0, -1);
|
|
1323
|
+
return url2;
|
|
1324
|
+
}
|
|
1325
|
+
return void 0;
|
|
1326
|
+
}
|
|
1327
|
+
function nativeInput(name, input) {
|
|
1328
|
+
if (name === "web_fetch" && own(input, "url") === void 0) {
|
|
1329
|
+
const url2 = firstUrl(own(input, "prompt"));
|
|
1330
|
+
return url2 === void 0 ? input : { ...input, url: url2 };
|
|
1331
|
+
}
|
|
1332
|
+
if (name === "read_many_files" && own(input, "file_path") === void 0) {
|
|
1333
|
+
const inc = own(input, "include");
|
|
1334
|
+
const list4 = Array.isArray(inc) ? inc.filter((v) => typeof v === "string") : [];
|
|
1335
|
+
return list4.length === 0 ? input : { ...input, file_path: list4.join(" ") };
|
|
1336
|
+
}
|
|
1337
|
+
return input;
|
|
1338
|
+
}
|
|
1277
1339
|
function decode3(raw) {
|
|
1278
1340
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
1279
1341
|
const p = raw;
|
|
@@ -1291,7 +1353,7 @@ function decode3(raw) {
|
|
|
1291
1353
|
ev.tool = {
|
|
1292
1354
|
name,
|
|
1293
1355
|
canonicalName: canonicalName2(name, own(p, "mcp_context")),
|
|
1294
|
-
input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
1356
|
+
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
1295
1357
|
};
|
|
1296
1358
|
}
|
|
1297
1359
|
if (event === "PostToolUse") ev.result = readResult2(own(p, "tool_response"));
|
|
@@ -1309,7 +1371,7 @@ function encode3(ev, d, _extra) {
|
|
|
1309
1371
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
1310
1372
|
case "replace":
|
|
1311
1373
|
if (ev.event !== "PostToolUse") return EMPTY;
|
|
1312
|
-
return { stdout: JSON.stringify({ decision: "deny", reason: d.output }), exitCode: 0 };
|
|
1374
|
+
return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
|
|
1313
1375
|
}
|
|
1314
1376
|
}
|
|
1315
1377
|
|
|
@@ -1370,6 +1432,14 @@ function canonicalName3(name) {
|
|
|
1370
1432
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
1371
1433
|
return name;
|
|
1372
1434
|
}
|
|
1435
|
+
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1436
|
+
function viewRange(name, input) {
|
|
1437
|
+
const r = input.view_range;
|
|
1438
|
+
if (name !== "view" || !Array.isArray(r) || !isNum(r[0])) return input;
|
|
1439
|
+
const out = { ...input, offset: r[0] };
|
|
1440
|
+
if (isNum(r[1]) && r[1] >= r[0]) out.limit = r[1] - r[0] + 1;
|
|
1441
|
+
return out;
|
|
1442
|
+
}
|
|
1373
1443
|
function readArgs(v) {
|
|
1374
1444
|
if (isRecord(v)) return v;
|
|
1375
1445
|
if (typeof v !== "string") return {};
|
|
@@ -1414,7 +1484,7 @@ function decode5(raw) {
|
|
|
1414
1484
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
1415
1485
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
1416
1486
|
const toolName2 = String(raw[k.tool] ?? "");
|
|
1417
|
-
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
1487
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
|
|
1418
1488
|
ev.tool = tool;
|
|
1419
1489
|
}
|
|
1420
1490
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
@@ -1458,22 +1528,22 @@ function canonicalName4(name) {
|
|
|
1458
1528
|
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
1459
1529
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
1460
1530
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
1461
|
-
const
|
|
1462
|
-
if (
|
|
1463
|
-
return "mcp:" + rest.slice(0,
|
|
1531
|
+
const sep5 = rest.indexOf(MCP_SEP2);
|
|
1532
|
+
if (sep5 <= 0 || sep5 === rest.length - 1) return name;
|
|
1533
|
+
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP2.length);
|
|
1464
1534
|
}
|
|
1465
|
-
var
|
|
1535
|
+
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1466
1536
|
function policyInput(name, canonical, input) {
|
|
1467
1537
|
if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
|
|
1468
1538
|
const out = { ...input };
|
|
1469
1539
|
if (name === "read_file") {
|
|
1470
1540
|
if (typeof input.filePath === "string") out.file_path = input.filePath;
|
|
1471
|
-
if (
|
|
1472
|
-
if (
|
|
1473
|
-
} else if (Array.isArray(input.view_range) &&
|
|
1541
|
+
if (isNum2(input.startLine)) out.offset = input.startLine;
|
|
1542
|
+
if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
|
|
1543
|
+
} else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
|
|
1474
1544
|
out.offset = input.view_range[0];
|
|
1475
1545
|
const end = input.view_range[1];
|
|
1476
|
-
if (
|
|
1546
|
+
if (isNum2(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
|
|
1477
1547
|
}
|
|
1478
1548
|
return out;
|
|
1479
1549
|
}
|
|
@@ -1589,9 +1659,9 @@ function canonicalName5(name) {
|
|
|
1589
1659
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1590
1660
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1591
1661
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
1592
|
-
const
|
|
1593
|
-
if (
|
|
1594
|
-
return "mcp:" + rest.slice(0,
|
|
1662
|
+
const sep5 = rest.indexOf(MCP_SEP3);
|
|
1663
|
+
if (sep5 <= 0 || sep5 === rest.length - 1) return name;
|
|
1664
|
+
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP3.length);
|
|
1595
1665
|
}
|
|
1596
1666
|
function readResult5(resp) {
|
|
1597
1667
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
@@ -1634,6 +1704,7 @@ function encode7(ev, d, _extra) {
|
|
|
1634
1704
|
|
|
1635
1705
|
// src/adapters/zcode.ts
|
|
1636
1706
|
var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
|
|
1707
|
+
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1637
1708
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1638
1709
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1639
1710
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
@@ -1643,7 +1714,9 @@ function decode8(raw) {
|
|
|
1643
1714
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
1644
1715
|
const failure = p.hook_event_name === FAILURE_EVENT2;
|
|
1645
1716
|
if (failure) p.hook_event_name = "PostToolUse";
|
|
1646
|
-
const
|
|
1717
|
+
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
1718
|
+
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
|
|
1719
|
+
const ev = decodeClaudeShape(p, "zcode", prefix, ZCODE_SOURCES);
|
|
1647
1720
|
if (failure) {
|
|
1648
1721
|
const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
|
|
1649
1722
|
ev.result = { isError: true, bytes: Buffer.byteLength(text), text };
|
|
@@ -1724,8 +1797,9 @@ var OPENCODE_EVENTS = {
|
|
|
1724
1797
|
"step-finish": "Usage"
|
|
1725
1798
|
};
|
|
1726
1799
|
var SHELL_TOOL_NAME = "bash";
|
|
1800
|
+
var READ_TOOL_NAME = "read";
|
|
1727
1801
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1728
|
-
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
1802
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
1729
1803
|
function toCanonicalTool(name) {
|
|
1730
1804
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1731
1805
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -1953,9 +2027,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1953
2027
|
installMode: "in-process",
|
|
1954
2028
|
projectSource: "spawn-cwd",
|
|
1955
2029
|
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
1956
|
-
nativeTools: { shell: [SHELL_TOOL_NAME] },
|
|
2030
|
+
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
1957
2031
|
execReadOnlyHint: false,
|
|
1958
|
-
// D-HF-OPENCODE-SHELL-1
|
|
2032
|
+
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
1959
2033
|
// Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
|
|
1960
2034
|
eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
|
|
1961
2035
|
compactDelivery: "opencode-cache",
|
|
@@ -2519,6 +2593,9 @@ var SUBSHELL_CLOSE = ")";
|
|
|
2519
2593
|
var CASE_BREAK = ";;";
|
|
2520
2594
|
var FUNC_PARENS = ["(", ")"];
|
|
2521
2595
|
var NOT = "!";
|
|
2596
|
+
function append(out, items) {
|
|
2597
|
+
for (const x of items) out.push(x);
|
|
2598
|
+
}
|
|
2522
2599
|
var KW = Object.freeze({
|
|
2523
2600
|
group: "{",
|
|
2524
2601
|
groupEnd: "}",
|
|
@@ -2698,12 +2775,12 @@ function ifBody(p) {
|
|
|
2698
2775
|
const t = at(p);
|
|
2699
2776
|
if (isWord(t, KW.then) || isWord(t, KW.else)) {
|
|
2700
2777
|
p.i++;
|
|
2701
|
-
out
|
|
2778
|
+
append(out, list(p, [KW.elif, KW.else, KW.fi]));
|
|
2702
2779
|
continue;
|
|
2703
2780
|
}
|
|
2704
2781
|
if (isWord(t, KW.elif)) {
|
|
2705
2782
|
p.i++;
|
|
2706
|
-
out
|
|
2783
|
+
append(out, list(p, [KW.then]));
|
|
2707
2784
|
continue;
|
|
2708
2785
|
}
|
|
2709
2786
|
if (isWord(t, KW.fi)) p.i++;
|
|
@@ -2714,7 +2791,7 @@ function ifBody(p) {
|
|
|
2714
2791
|
function loopBody(p) {
|
|
2715
2792
|
p.i++;
|
|
2716
2793
|
const out = list(p, [KW.do]);
|
|
2717
|
-
out
|
|
2794
|
+
append(out, doBlock(p));
|
|
2718
2795
|
return out;
|
|
2719
2796
|
}
|
|
2720
2797
|
function forBody(p) {
|
|
@@ -2728,10 +2805,10 @@ function forBody(p) {
|
|
|
2728
2805
|
p.i++;
|
|
2729
2806
|
const from = p.i;
|
|
2730
2807
|
while ((at(p)?.kind === "word" || at(p)?.kind === "unhandled") && !isWord(at(p), KW.do)) p.i++;
|
|
2731
|
-
out
|
|
2808
|
+
append(out, carrierOf(p, from, p.i));
|
|
2732
2809
|
}
|
|
2733
2810
|
}
|
|
2734
|
-
out
|
|
2811
|
+
append(out, doBlock(p));
|
|
2735
2812
|
return out;
|
|
2736
2813
|
}
|
|
2737
2814
|
function caseBody(p) {
|
|
@@ -2740,7 +2817,7 @@ function caseBody(p) {
|
|
|
2740
2817
|
const subject = at(p);
|
|
2741
2818
|
if (subject !== void 0 && subject.kind !== "op" && subject.kind !== "io") {
|
|
2742
2819
|
p.i++;
|
|
2743
|
-
out
|
|
2820
|
+
append(out, carrierOf(p, p.i - 1, p.i));
|
|
2744
2821
|
}
|
|
2745
2822
|
if (isWord(at(p), KW.in)) p.i++;
|
|
2746
2823
|
while (p.i < p.toks.length && p.err === null) {
|
|
@@ -2763,7 +2840,7 @@ function caseBody(p) {
|
|
|
2763
2840
|
p.i++;
|
|
2764
2841
|
const body = list(p, [KW.esac]);
|
|
2765
2842
|
tag(body, KW.case);
|
|
2766
|
-
out
|
|
2843
|
+
append(out, body);
|
|
2767
2844
|
}
|
|
2768
2845
|
return out;
|
|
2769
2846
|
}
|
|
@@ -2778,7 +2855,7 @@ function hasFuncParens(p, from) {
|
|
|
2778
2855
|
}
|
|
2779
2856
|
function simple(p) {
|
|
2780
2857
|
const first = p.i;
|
|
2781
|
-
const
|
|
2858
|
+
const words2 = [];
|
|
2782
2859
|
let toFile = false;
|
|
2783
2860
|
while (p.i < p.toks.length) {
|
|
2784
2861
|
const t = p.toks[p.i];
|
|
@@ -2787,7 +2864,7 @@ function simple(p) {
|
|
|
2787
2864
|
toFile = ioRedirect(p) || toFile;
|
|
2788
2865
|
continue;
|
|
2789
2866
|
}
|
|
2790
|
-
if (
|
|
2867
|
+
if (words2.length === 0 && t.kind === "word" && isAssignment(t.text)) {
|
|
2791
2868
|
p.i++;
|
|
2792
2869
|
const open = at(p);
|
|
2793
2870
|
if (t.text.endsWith(OPT_VALUE) && open !== void 0 && isOp(open, SUBSHELL_OPEN) && open.start === t.end) {
|
|
@@ -2801,15 +2878,15 @@ function simple(p) {
|
|
|
2801
2878
|
}
|
|
2802
2879
|
continue;
|
|
2803
2880
|
}
|
|
2804
|
-
|
|
2881
|
+
words2.push(t);
|
|
2805
2882
|
p.i++;
|
|
2806
2883
|
}
|
|
2807
2884
|
if (p.i === first) return EMPTY3();
|
|
2808
2885
|
const raw = p.src.slice(p.toks[first].start, p.toks[p.i - 1].end);
|
|
2809
|
-
if (
|
|
2886
|
+
if (words2.length === 0) return { cmds: carrier(raw), simple: null };
|
|
2810
2887
|
const text = (t) => t.kind === "word" ? dequote(t.text) : t.text;
|
|
2811
|
-
const argv0 = baseName(text(
|
|
2812
|
-
const args =
|
|
2888
|
+
const argv0 = baseName(text(words2[0]));
|
|
2889
|
+
const args = words2.slice(1).map(text);
|
|
2813
2890
|
const cmd = { argv0, args, redirectsToFile: toFile || writesFile(argv0, args), endsInBoundedSink: false, raw };
|
|
2814
2891
|
return { cmds: [cmd], simple: cmd };
|
|
2815
2892
|
}
|
|
@@ -2880,7 +2957,7 @@ function pipeline(p) {
|
|
|
2880
2957
|
let last2 = EMPTY3();
|
|
2881
2958
|
while (p.err === null) {
|
|
2882
2959
|
last2 = element(p);
|
|
2883
|
-
all
|
|
2960
|
+
append(all, last2.cmds);
|
|
2884
2961
|
const t = at(p);
|
|
2885
2962
|
if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
|
|
2886
2963
|
for (const c of last2.cmds) c.pipesOut = true;
|
|
@@ -2909,7 +2986,7 @@ function list(p, stop) {
|
|
|
2909
2986
|
}
|
|
2910
2987
|
if (t.kind === "word" && stop.includes(t.text)) return out;
|
|
2911
2988
|
const before = p.i;
|
|
2912
|
-
out
|
|
2989
|
+
append(out, pipeline(p));
|
|
2913
2990
|
if (p.i === before && p.err === null) p.i++;
|
|
2914
2991
|
}
|
|
2915
2992
|
return out;
|
|
@@ -2922,7 +2999,7 @@ function parseShell(cmd) {
|
|
|
2922
2999
|
const p = { toks: s.tokens, src: cmd, bodies: new Set(s.heredocBodies), i: 0, depth: 0, err: null };
|
|
2923
3000
|
const commands = [];
|
|
2924
3001
|
while (p.i < p.toks.length && p.err === null) {
|
|
2925
|
-
commands
|
|
3002
|
+
append(commands, list(p, NO_STOP));
|
|
2926
3003
|
if (p.i < p.toks.length) p.i++;
|
|
2927
3004
|
}
|
|
2928
3005
|
if (p.err !== null) return { ok: false, construct: p.err };
|
|
@@ -3177,57 +3254,57 @@ function param(word, names) {
|
|
|
3177
3254
|
const hits = names.filter((p) => p.startsWith(name));
|
|
3178
3255
|
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
3179
3256
|
}
|
|
3180
|
-
function psDump(
|
|
3181
|
-
if (
|
|
3182
|
-
const name = cmdName(
|
|
3257
|
+
function psDump(words2) {
|
|
3258
|
+
if (words2.length === 0) return null;
|
|
3259
|
+
const name = cmdName(words2[0]);
|
|
3183
3260
|
if (!READ_COMMANDS.includes(name)) {
|
|
3184
|
-
const lower =
|
|
3261
|
+
const lower = words2[0].toLowerCase();
|
|
3185
3262
|
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
3186
|
-
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) ||
|
|
3187
|
-
return { file:
|
|
3263
|
+
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words2.length < MIN_STATIC_CALL) return null;
|
|
3264
|
+
return { file: words2[1], bounded: false };
|
|
3188
3265
|
}
|
|
3189
3266
|
const files = [];
|
|
3190
3267
|
let bounded = false;
|
|
3191
|
-
for (let k = 1; k <
|
|
3192
|
-
const a =
|
|
3268
|
+
for (let k = 1; k < words2.length; k++) {
|
|
3269
|
+
const a = words2[k];
|
|
3193
3270
|
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
3194
3271
|
files.push(a);
|
|
3195
3272
|
continue;
|
|
3196
3273
|
}
|
|
3197
3274
|
const p = param(a, ALL_PARAMS);
|
|
3198
3275
|
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
3199
|
-
const value = p.inline ??
|
|
3276
|
+
const value = p.inline ?? words2[++k];
|
|
3200
3277
|
if (value === void 0) return null;
|
|
3201
3278
|
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
3202
3279
|
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
3203
3280
|
}
|
|
3204
3281
|
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
3205
3282
|
}
|
|
3206
|
-
function nestedScript(name,
|
|
3283
|
+
function nestedScript(name, words2) {
|
|
3207
3284
|
if (POWERSHELLS.includes(name)) {
|
|
3208
|
-
for (let k = 1; k <
|
|
3209
|
-
const w =
|
|
3285
|
+
for (let k = 1; k < words2.length; k++) {
|
|
3286
|
+
const w = words2[k];
|
|
3210
3287
|
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
3211
3288
|
const p = param(w, [COMMAND_PARAM]);
|
|
3212
3289
|
if (p.full === void 0) continue;
|
|
3213
|
-
return [...p.inline === void 0 ? [] : [p.inline], ...
|
|
3290
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words2.slice(k + 1)].join(" ");
|
|
3214
3291
|
}
|
|
3215
3292
|
return null;
|
|
3216
3293
|
}
|
|
3217
3294
|
if (CMDS.includes(name)) {
|
|
3218
|
-
for (let k = 1; k <
|
|
3219
|
-
if (CMD_RUN_FLAGS.includes(
|
|
3295
|
+
for (let k = 1; k < words2.length; k++) {
|
|
3296
|
+
if (CMD_RUN_FLAGS.includes(words2[k].toLowerCase())) return words2.slice(k + 1).join(" ");
|
|
3220
3297
|
}
|
|
3221
3298
|
}
|
|
3222
3299
|
return null;
|
|
3223
3300
|
}
|
|
3224
|
-
function cdTarget(
|
|
3225
|
-
for (let k = 1; k <
|
|
3226
|
-
const w =
|
|
3301
|
+
function cdTarget(words2) {
|
|
3302
|
+
for (let k = 1; k < words2.length; k++) {
|
|
3303
|
+
const w = words2[k];
|
|
3227
3304
|
if (w.toLowerCase() === "/d") continue;
|
|
3228
3305
|
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
3229
3306
|
const p = param(w, PATH_PARAMS);
|
|
3230
|
-
if (p.full !== void 0) return p.inline ??
|
|
3307
|
+
if (p.full !== void 0) return p.inline ?? words2[k + 1] ?? null;
|
|
3231
3308
|
}
|
|
3232
3309
|
return null;
|
|
3233
3310
|
}
|
|
@@ -3327,6 +3404,10 @@ function copilotDirOf(env, home) {
|
|
|
3327
3404
|
const dir = env[COPILOT_HOME_ENV];
|
|
3328
3405
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
3329
3406
|
}
|
|
3407
|
+
function geminiDirOf(env, home) {
|
|
3408
|
+
const dir = env[GEMINI_CLI_HOME_ENV];
|
|
3409
|
+
return join(dir !== void 0 && dir !== "" ? dir : home, ...AGENT_HOME_DIR.gemini);
|
|
3410
|
+
}
|
|
3330
3411
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
3331
3412
|
const p = platform === "win32" ? win32 : posix;
|
|
3332
3413
|
const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
|
|
@@ -3385,8 +3466,13 @@ function requireHomeDir(env, platform = process.platform) {
|
|
|
3385
3466
|
if (home !== null) return home;
|
|
3386
3467
|
throw new CtxError("NO_HOME", { name: platform === "win32" ? "USERPROFILE" : "HOME" });
|
|
3387
3468
|
}
|
|
3469
|
+
function dataRootOf(env, home) {
|
|
3470
|
+
const dir = env[DATA_DIR_ENV];
|
|
3471
|
+
return dir !== void 0 && dir !== "" ? resolve2(dir) : join(home, DATA_ROOT.slice(1));
|
|
3472
|
+
}
|
|
3388
3473
|
function resolveConfigDir(env) {
|
|
3389
|
-
const
|
|
3474
|
+
const set3 = env[DATA_DIR_ENV];
|
|
3475
|
+
const dir = dataRootOf(env, set3 !== void 0 && set3 !== "" ? "" : requireHomeDir(env));
|
|
3390
3476
|
mkdirSync(dir, { recursive: true });
|
|
3391
3477
|
return realpathSync.native(dir);
|
|
3392
3478
|
}
|
|
@@ -3758,14 +3844,13 @@ function tokenize(glob, path8) {
|
|
|
3758
3844
|
}
|
|
3759
3845
|
return toks;
|
|
3760
3846
|
}
|
|
3761
|
-
function
|
|
3762
|
-
const toks = tokenize(glob, path8);
|
|
3847
|
+
function matchStarts(toks, text, path8, ends) {
|
|
3763
3848
|
const n = text.length;
|
|
3764
|
-
let next =
|
|
3765
|
-
|
|
3849
|
+
let next = ends;
|
|
3850
|
+
let cur = new Uint8Array(n + 1);
|
|
3766
3851
|
for (let i = toks.length - 1; i >= 0; i--) {
|
|
3767
3852
|
const tok = toks[i];
|
|
3768
|
-
|
|
3853
|
+
if (next === ends) next = Uint8Array.from(ends);
|
|
3769
3854
|
let acc = 0;
|
|
3770
3855
|
for (let j = n; j >= 0; j--) {
|
|
3771
3856
|
const has3 = j < n;
|
|
@@ -3789,9 +3874,19 @@ function globMatch(glob, text, path8) {
|
|
|
3789
3874
|
break;
|
|
3790
3875
|
}
|
|
3791
3876
|
}
|
|
3792
|
-
|
|
3877
|
+
const done = cur;
|
|
3878
|
+
cur = next;
|
|
3879
|
+
next = done;
|
|
3793
3880
|
}
|
|
3794
|
-
return next
|
|
3881
|
+
return next;
|
|
3882
|
+
}
|
|
3883
|
+
function globMatch(glob, text, path8) {
|
|
3884
|
+
const toks = tokenize(glob, path8);
|
|
3885
|
+
const first = toks[0];
|
|
3886
|
+
if (first !== void 0 && first.t === "lit" && text[0] !== first.c) return false;
|
|
3887
|
+
const ends = new Uint8Array(text.length + 1);
|
|
3888
|
+
ends[text.length] = 1;
|
|
3889
|
+
return matchStarts(toks, text, path8, ends)[0] === 1;
|
|
3795
3890
|
}
|
|
3796
3891
|
function parsePattern(pattern) {
|
|
3797
3892
|
const open = pattern.indexOf("(");
|
|
@@ -3799,14 +3894,25 @@ function parsePattern(pattern) {
|
|
|
3799
3894
|
const glob = pattern.slice(open + 1, pattern.length - ")".length);
|
|
3800
3895
|
return glob === "" ? null : { tool: pattern.slice(0, open), glob };
|
|
3801
3896
|
}
|
|
3897
|
+
function commandStarts(glob, text) {
|
|
3898
|
+
const n = text.length;
|
|
3899
|
+
const ends = new Uint8Array(n + 1);
|
|
3900
|
+
ends[n] = 1;
|
|
3901
|
+
if (!glob.endsWith(PREFIX_RULE)) return matchStarts(tokenize(glob, false), text, false, ends);
|
|
3902
|
+
for (let k = 0; k < n; k++) if (WHITESPACE.includes(text[k])) ends[k] = 1;
|
|
3903
|
+
return matchStarts(tokenize(glob.slice(0, glob.length - PREFIX_RULE.length), false), text, false, ends);
|
|
3904
|
+
}
|
|
3802
3905
|
function matchCommand(glob, text) {
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
for (
|
|
3807
|
-
|
|
3906
|
+
return commandStarts(glob, text)[0] === 1;
|
|
3907
|
+
}
|
|
3908
|
+
function denyPatternFromAny(text, patterns, from) {
|
|
3909
|
+
for (const pattern of patterns) {
|
|
3910
|
+
const p = parsePattern(pattern);
|
|
3911
|
+
if (p === null || p.tool !== BASH_TOOL) continue;
|
|
3912
|
+
const starts = commandStarts(p.glob, text);
|
|
3913
|
+
for (let j = 0; j <= text.length; j++) if (from[j] === 1 && starts[j] === 1) return pattern;
|
|
3808
3914
|
}
|
|
3809
|
-
return
|
|
3915
|
+
return null;
|
|
3810
3916
|
}
|
|
3811
3917
|
var DRIVE_PREFIX = /^[A-Za-z]:(?=\/)/;
|
|
3812
3918
|
function toSlash(p) {
|
|
@@ -3878,6 +3984,7 @@ var HOST_SEP = ".";
|
|
|
3878
3984
|
var SED_RANGE_SEP = ",";
|
|
3879
3985
|
var SED_PRINT = "p";
|
|
3880
3986
|
var SED_SCRIPT_FLAGS = ["-e", "--expression"];
|
|
3987
|
+
var EXE_SUFFIX2 = ".exe";
|
|
3881
3988
|
var COMMAND_STARTS = ";&|(`\n\r";
|
|
3882
3989
|
var ALLOW = Object.freeze({ kind: "allow" });
|
|
3883
3990
|
var deny = (reason) => ({ kind: "deny", reason });
|
|
@@ -3915,6 +4022,11 @@ function readPath(input) {
|
|
|
3915
4022
|
}
|
|
3916
4023
|
return void 0;
|
|
3917
4024
|
}
|
|
4025
|
+
function readPaths(input) {
|
|
4026
|
+
const one = readPath(input);
|
|
4027
|
+
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((p) => typeof p === "string" && p !== "") : [];
|
|
4028
|
+
return one === void 0 ? many : [one, ...many];
|
|
4029
|
+
}
|
|
3918
4030
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
3919
4031
|
if (rules.length === 0) return null;
|
|
3920
4032
|
const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
@@ -3923,35 +4035,65 @@ function userDenyHit(canonical, input, cwd, rules) {
|
|
|
3923
4035
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
3924
4036
|
}
|
|
3925
4037
|
if (canonical === READ) {
|
|
3926
|
-
const p
|
|
3927
|
-
|
|
4038
|
+
for (const p of readPaths(input)) {
|
|
4039
|
+
const h = readRule(p);
|
|
4040
|
+
if (h !== null) return h;
|
|
4041
|
+
}
|
|
4042
|
+
return null;
|
|
3928
4043
|
}
|
|
3929
4044
|
if (canonical === CTX_EXECUTE) {
|
|
3930
4045
|
const file2 = str(input.file);
|
|
3931
4046
|
const byFile = file2 === void 0 || file2 === "" ? null : readRule(file2);
|
|
3932
4047
|
if (byFile !== null) return byFile;
|
|
3933
4048
|
const code = str(input.code);
|
|
3934
|
-
return input.language
|
|
4049
|
+
return isShellLanguage(input.language) && code !== void 0 ? shellHit(code, rules) : null;
|
|
3935
4050
|
}
|
|
3936
4051
|
if (canonical === CTX_BATCH && Array.isArray(input.commands)) {
|
|
3937
4052
|
for (const c of input.commands) {
|
|
3938
|
-
const h = typeof c === "string" ?
|
|
4053
|
+
const h = typeof c === "string" ? shellHit(c, rules) : null;
|
|
3939
4054
|
if (h !== null) return h;
|
|
3940
4055
|
}
|
|
3941
4056
|
}
|
|
3942
4057
|
return null;
|
|
3943
4058
|
}
|
|
4059
|
+
function isShellLanguage(language) {
|
|
4060
|
+
if (typeof language !== "string") return false;
|
|
4061
|
+
let name = language.toLowerCase();
|
|
4062
|
+
const slash = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
|
|
4063
|
+
if (slash >= 0) name = name.slice(slash + 1);
|
|
4064
|
+
if (name.endsWith(EXE_SUFFIX2)) name = name.slice(0, name.length - EXE_SUFFIX2.length);
|
|
4065
|
+
return name === SHELL_LANGUAGE || has(SHELL_FAMILY, name);
|
|
4066
|
+
}
|
|
4067
|
+
function shellHit(cmd, rules) {
|
|
4068
|
+
const whole2 = matchesAnyDenyPattern(cmd, rules);
|
|
4069
|
+
if (whole2 !== null) return whole2;
|
|
4070
|
+
const parsed = parseShell(cmd);
|
|
4071
|
+
if (!parsed.ok) return couldMatchRule(cmd, rules);
|
|
4072
|
+
for (const c of unwrap(parsed.commands)) {
|
|
4073
|
+
const h = segmentHit(c, rules);
|
|
4074
|
+
if (h !== null) return h;
|
|
4075
|
+
}
|
|
4076
|
+
return null;
|
|
4077
|
+
}
|
|
3944
4078
|
function segmentHit(c, rules) {
|
|
3945
4079
|
if (rules.length === 0) return null;
|
|
3946
4080
|
return matchesAnyDenyPattern([c.argv0, ...c.args].join(" "), rules) ?? matchesAnyDenyPattern(c.raw, rules);
|
|
3947
4081
|
}
|
|
3948
|
-
function
|
|
3949
|
-
if (rules.length === 0) return
|
|
4082
|
+
function couldMatchRule(text, rules) {
|
|
4083
|
+
if (rules.length === 0) return null;
|
|
4084
|
+
const from = new Uint8Array(text.length + 1);
|
|
4085
|
+
let pending = false;
|
|
3950
4086
|
for (let k = 0; k <= text.length; k++) {
|
|
3951
|
-
if (k
|
|
3952
|
-
if (
|
|
4087
|
+
if (k === 0 || COMMAND_STARTS.includes(text.charAt(k - 1))) pending = true;
|
|
4088
|
+
if (pending && (k === text.length || text.charAt(k).trim() !== "")) {
|
|
4089
|
+
from[k] = 1;
|
|
4090
|
+
pending = false;
|
|
4091
|
+
}
|
|
3953
4092
|
}
|
|
3954
|
-
return
|
|
4093
|
+
return denyPatternFromAny(text, rules, from);
|
|
4094
|
+
}
|
|
4095
|
+
function couldMatch(text, rules) {
|
|
4096
|
+
return couldMatchRule(text, rules) !== null;
|
|
3955
4097
|
}
|
|
3956
4098
|
function neverDenied(url2) {
|
|
3957
4099
|
let host;
|
|
@@ -4026,8 +4168,7 @@ function fileSize(abs) {
|
|
|
4026
4168
|
}
|
|
4027
4169
|
function read(ev, row5, input) {
|
|
4028
4170
|
if (!present(input.offset) && !present(input.limit)) {
|
|
4029
|
-
const p
|
|
4030
|
-
if (p !== void 0) {
|
|
4171
|
+
for (const p of readPaths(input)) {
|
|
4031
4172
|
const abs = resolve3(ev.cwd, p);
|
|
4032
4173
|
const size = fileSize(abs);
|
|
4033
4174
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
@@ -4121,11 +4262,11 @@ function dumpTarget(name, args) {
|
|
|
4121
4262
|
}
|
|
4122
4263
|
|
|
4123
4264
|
// src/core/project/resolve.ts
|
|
4124
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
4265
|
+
import { basename as basename2, dirname as dirname3, join as join5, resolve as resolve4 } from "node:path";
|
|
4125
4266
|
|
|
4126
4267
|
// src/core/project/contain.ts
|
|
4127
|
-
import { dirname as dirname2, sep as sep2 } from "node:path";
|
|
4128
|
-
var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4268
|
+
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
4269
|
+
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4129
4270
|
function real(p) {
|
|
4130
4271
|
try {
|
|
4131
4272
|
return realpathSync2.native(p);
|
|
@@ -4164,6 +4305,21 @@ function commonRoot(paths) {
|
|
|
4164
4305
|
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
4165
4306
|
return q;
|
|
4166
4307
|
}
|
|
4308
|
+
function reachedThroughLink(root, p) {
|
|
4309
|
+
const rel = relative2(root, p);
|
|
4310
|
+
const steps = components(rel);
|
|
4311
|
+
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
4312
|
+
let at2 = root;
|
|
4313
|
+
for (const step of steps) {
|
|
4314
|
+
at2 = join4(at2, step);
|
|
4315
|
+
try {
|
|
4316
|
+
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
4317
|
+
} catch {
|
|
4318
|
+
return false;
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4321
|
+
return false;
|
|
4322
|
+
}
|
|
4167
4323
|
|
|
4168
4324
|
// src/core/project/sha256.ts
|
|
4169
4325
|
var K = new Uint32Array([
|
|
@@ -4325,9 +4481,9 @@ function gitDirs(dir) {
|
|
|
4325
4481
|
}
|
|
4326
4482
|
const start = cur;
|
|
4327
4483
|
for (; ; ) {
|
|
4328
|
-
const gitDir = gitDirAt(
|
|
4484
|
+
const gitDir = gitDirAt(join5(cur, GIT_DIR_NAME));
|
|
4329
4485
|
if (gitDir !== null) {
|
|
4330
|
-
const common = firstLine(
|
|
4486
|
+
const common = firstLine(join5(gitDir, GIT_COMMONDIR_FILE));
|
|
4331
4487
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
4332
4488
|
}
|
|
4333
4489
|
const up = dirname3(cur);
|
|
@@ -4348,7 +4504,7 @@ function gitDirAt(dotGit) {
|
|
|
4348
4504
|
} catch {
|
|
4349
4505
|
return null;
|
|
4350
4506
|
}
|
|
4351
|
-
return existsSync(
|
|
4507
|
+
return existsSync(join5(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
4352
4508
|
}
|
|
4353
4509
|
function firstLine(file2) {
|
|
4354
4510
|
let text;
|
|
@@ -4389,11 +4545,11 @@ function resolveProject(agent, src) {
|
|
|
4389
4545
|
return key;
|
|
4390
4546
|
},
|
|
4391
4547
|
get projectDir() {
|
|
4392
|
-
pdir ??=
|
|
4548
|
+
pdir ??= join5(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
4393
4549
|
return pdir;
|
|
4394
4550
|
},
|
|
4395
4551
|
get dbPath() {
|
|
4396
|
-
return
|
|
4552
|
+
return join5(this.projectDir, DB_FILE_NAME);
|
|
4397
4553
|
},
|
|
4398
4554
|
worktree,
|
|
4399
4555
|
get containmentRoot() {
|
|
@@ -4534,6 +4690,15 @@ function applyMigrations(db, fromVersion) {
|
|
|
4534
4690
|
}
|
|
4535
4691
|
}
|
|
4536
4692
|
|
|
4693
|
+
// src/core/store/open-read.ts
|
|
4694
|
+
function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
4695
|
+
const bun = "bun" in opts ? opts.bun : process.versions.bun;
|
|
4696
|
+
if (bun === void 0) return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
4697
|
+
const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
4698
|
+
if (opts.queryOnly !== false) raw.exec("PRAGMA query_only = ON");
|
|
4699
|
+
return raw;
|
|
4700
|
+
}
|
|
4701
|
+
|
|
4537
4702
|
// src/core/store/db.ts
|
|
4538
4703
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4539
4704
|
function versionParts(v) {
|
|
@@ -4599,7 +4764,7 @@ function openWritable(sqlite, path8) {
|
|
|
4599
4764
|
}
|
|
4600
4765
|
}
|
|
4601
4766
|
function openReadOnly(sqlite, path8) {
|
|
4602
|
-
const raw =
|
|
4767
|
+
const raw = openReadOnlyHandle(sqlite, path8);
|
|
4603
4768
|
try {
|
|
4604
4769
|
const found = readUserVersion(raw);
|
|
4605
4770
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -4819,14 +4984,14 @@ function identParts(w) {
|
|
|
4819
4984
|
if (cur !== "") parts.push(cur);
|
|
4820
4985
|
return parts;
|
|
4821
4986
|
}
|
|
4822
|
-
function snippetTerms(
|
|
4987
|
+
function snippetTerms(words2) {
|
|
4823
4988
|
const out = /* @__PURE__ */ new Map();
|
|
4824
4989
|
const add = (text, weight, symbol2) => {
|
|
4825
4990
|
if (text === "") return;
|
|
4826
4991
|
const prev = out.get(text);
|
|
4827
4992
|
if (!prev || prev.weight < weight) out.set(text, { text, weight, symbol: symbol2 });
|
|
4828
4993
|
};
|
|
4829
|
-
for (const raw of
|
|
4994
|
+
for (const raw of words2) {
|
|
4830
4995
|
let a = 0;
|
|
4831
4996
|
let b = raw.length;
|
|
4832
4997
|
while (a < b && !isAlnum(raw.charCodeAt(a))) a++;
|
|
@@ -6832,18 +6997,18 @@ function deleteChunkRows(raw, scope) {
|
|
|
6832
6997
|
return Number(raw.prepare("DELETE FROM chunks WHERE " + where).run(arg).changes);
|
|
6833
6998
|
}
|
|
6834
6999
|
function toMatch(q) {
|
|
6835
|
-
const
|
|
7000
|
+
const words2 = [];
|
|
6836
7001
|
let cur = "";
|
|
6837
7002
|
for (const ch of q) {
|
|
6838
7003
|
if (ch.trim() === "" || ch === "\0") {
|
|
6839
|
-
if (cur !== "")
|
|
7004
|
+
if (cur !== "") words2.push(cur);
|
|
6840
7005
|
cur = "";
|
|
6841
7006
|
} else {
|
|
6842
7007
|
cur += ch === '"' ? '""' : ch;
|
|
6843
7008
|
}
|
|
6844
7009
|
}
|
|
6845
|
-
if (cur !== "")
|
|
6846
|
-
return
|
|
7010
|
+
if (cur !== "") words2.push(cur);
|
|
7011
|
+
return words2.map((w) => `"${w}"*`).join(" ");
|
|
6847
7012
|
}
|
|
6848
7013
|
function toMatchAny(q) {
|
|
6849
7014
|
const terms = new Set(toMatch(q).split(" ").filter((t) => t !== ""));
|
|
@@ -6940,11 +7105,11 @@ function searchTerms(q) {
|
|
|
6940
7105
|
return kept.length > 0 ? kept : all;
|
|
6941
7106
|
}
|
|
6942
7107
|
function trigramMatch(q) {
|
|
6943
|
-
const
|
|
6944
|
-
const kept =
|
|
6945
|
-
const parts = new Set((kept.length > 0 ? kept :
|
|
6946
|
-
const whole2 =
|
|
6947
|
-
if (
|
|
7108
|
+
const words2 = blankTokens(q);
|
|
7109
|
+
const kept = words2.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
7110
|
+
const parts = new Set((kept.length > 0 ? kept : words2).filter((w) => [...w].length >= 3));
|
|
7111
|
+
const whole2 = words2.join(" ");
|
|
7112
|
+
if (words2.length > 1 && [...whole2].length >= 3) parts.add(whole2);
|
|
6948
7113
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
6949
7114
|
}
|
|
6950
7115
|
function editDistance(a, b, max) {
|
|
@@ -6991,10 +7156,10 @@ function queryStems(q) {
|
|
|
6991
7156
|
}
|
|
6992
7157
|
var TYPO_MIN_LEN = 5;
|
|
6993
7158
|
var TYPO_MAX_DIST = 2;
|
|
6994
|
-
function typoTerms(db,
|
|
7159
|
+
function typoTerms(db, words2) {
|
|
6995
7160
|
const has3 = stmt(db.raw, "SELECT 1 AS x FROM chunks_vocab WHERE term = ?");
|
|
6996
7161
|
const near = stmt(db.raw, "SELECT term, doc, length(term) AS n FROM chunks_vocab WHERE length(term) BETWEEN ? AND ?");
|
|
6997
|
-
const stems = queryStems(
|
|
7162
|
+
const stems = queryStems(words2.join(" "));
|
|
6998
7163
|
const miss = stems.map((stem) => has3.get(stem) === void 0 && [...stem].length >= TYPO_MIN_LEN);
|
|
6999
7164
|
if (!miss.includes(true)) return null;
|
|
7000
7165
|
const lens = stems.filter((_, i) => miss[i]).map((stem) => stem.length);
|
|
@@ -7097,9 +7262,9 @@ function ftsListSource(db, source, scope, ctx, sessionId, limit, offset) {
|
|
|
7097
7262
|
}));
|
|
7098
7263
|
}
|
|
7099
7264
|
function highlight(row5, terms, maxBytes = SNIPPET_MAX_BYTES) {
|
|
7100
|
-
const
|
|
7101
|
-
const kept =
|
|
7102
|
-
return buildSnippet(row5, snippetTerms(kept.length > 0 ? kept :
|
|
7265
|
+
const words2 = blankTokens(terms);
|
|
7266
|
+
const kept = words2.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
7267
|
+
return buildSnippet(row5, snippetTerms(kept.length > 0 ? kept : words2), maxBytes);
|
|
7103
7268
|
}
|
|
7104
7269
|
var TL_SCOPE = `
|
|
7105
7270
|
AND (:scope <> 'session' OR session_id = :session_id)
|
|
@@ -7365,13 +7530,24 @@ function buildUnits(text) {
|
|
|
7365
7530
|
const lines = text.split("\n");
|
|
7366
7531
|
const stack2 = [];
|
|
7367
7532
|
const out = [];
|
|
7533
|
+
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
7368
7534
|
for (let i = 0; i < lines.length; i++) {
|
|
7369
7535
|
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
7370
7536
|
const indent = indentOf(line);
|
|
7371
7537
|
if (indent === line.length) continue;
|
|
7372
7538
|
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
7373
|
-
|
|
7374
|
-
|
|
7539
|
+
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
7540
|
+
let size = bytes5;
|
|
7541
|
+
let from = stack2.length;
|
|
7542
|
+
while (from > 0) {
|
|
7543
|
+
const add = stack2[from - 1].bytes + 1;
|
|
7544
|
+
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
7545
|
+
size += add;
|
|
7546
|
+
from--;
|
|
7547
|
+
}
|
|
7548
|
+
left -= size - bytes5;
|
|
7549
|
+
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
7550
|
+
stack2.push({ indent, line, bytes: bytes5 });
|
|
7375
7551
|
}
|
|
7376
7552
|
return out;
|
|
7377
7553
|
}
|
|
@@ -7510,7 +7686,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
7510
7686
|
const pool = cands.filter((u) => !seen.has(unitKey(u)) && u.score >= RECALL_MIN_SCORE);
|
|
7511
7687
|
if (pool.length === 0) return [];
|
|
7512
7688
|
const top = Math.max(...pool.map((u) => u.score));
|
|
7513
|
-
const
|
|
7689
|
+
const words2 = pool.map((u) => wordsOf(u.body));
|
|
7514
7690
|
const taken = [];
|
|
7515
7691
|
const left = new Set(pool.map((_, i) => i));
|
|
7516
7692
|
let used = 0;
|
|
@@ -7519,7 +7695,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
7519
7695
|
let bestVal = -Infinity;
|
|
7520
7696
|
for (const i of left) {
|
|
7521
7697
|
let sim = 0;
|
|
7522
|
-
for (const j of taken) sim = Math.max(sim, overlap(
|
|
7698
|
+
for (const j of taken) sim = Math.max(sim, overlap(words2[i], words2[j]));
|
|
7523
7699
|
const val = MMR_RELEVANCE_WEIGHT * (pool[i].score / top) - MMR_REDUNDANCY_WEIGHT * sim;
|
|
7524
7700
|
if (val > bestVal) {
|
|
7525
7701
|
bestVal = val;
|
|
@@ -7922,7 +8098,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
7922
8098
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
7923
8099
|
return { end: start + r.read, written: r.written };
|
|
7924
8100
|
}
|
|
7925
|
-
function merge(src, blocks,
|
|
8101
|
+
function merge(src, blocks, join24, cap, lineCut) {
|
|
7926
8102
|
const out = [];
|
|
7927
8103
|
const scratch = new Uint8Array(cap);
|
|
7928
8104
|
let wide;
|
|
@@ -7932,7 +8108,7 @@ function merge(src, blocks, join27, cap, lineCut) {
|
|
|
7932
8108
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
7933
8109
|
};
|
|
7934
8110
|
for (const b of blocks) {
|
|
7935
|
-
if (cur !== void 0 && !
|
|
8111
|
+
if (cur !== void 0 && !join24) {
|
|
7936
8112
|
emit(cur.start, cur.end, curBytes);
|
|
7937
8113
|
cur = void 0;
|
|
7938
8114
|
}
|
|
@@ -8050,11 +8226,11 @@ function shapeDigest(text, query, budget) {
|
|
|
8050
8226
|
const picked = [];
|
|
8051
8227
|
let used = 0;
|
|
8052
8228
|
for (const i of order) {
|
|
8053
|
-
const
|
|
8054
|
-
const r = shape.units[i].render(budget - used -
|
|
8055
|
-
if (r === null || used +
|
|
8229
|
+
const sep5 = picked.length > 0 ? bytes(SEP2) : 0;
|
|
8230
|
+
const r = shape.units[i].render(budget - used - sep5);
|
|
8231
|
+
if (r === null || used + sep5 + bytes(r) > budget) continue;
|
|
8056
8232
|
picked.push({ pos: shape.units[i].pos, text: r });
|
|
8057
|
-
used +=
|
|
8233
|
+
used += sep5 + bytes(r);
|
|
8058
8234
|
}
|
|
8059
8235
|
if (picked.length === 0) return null;
|
|
8060
8236
|
picked.sort((a, b) => a.pos - b.pos);
|
|
@@ -8374,7 +8550,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
8374
8550
|
}
|
|
8375
8551
|
|
|
8376
8552
|
// src/core/hooks/fallback.ts
|
|
8377
|
-
import { join as
|
|
8553
|
+
import { join as join6, resolve as resolve5 } from "node:path";
|
|
8378
8554
|
var fs = process.getBuiltinModule("node:fs");
|
|
8379
8555
|
function isRec(v) {
|
|
8380
8556
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8401,8 +8577,10 @@ function homeOf(env) {
|
|
|
8401
8577
|
return env.HOME ?? env.USERPROFILE ?? "";
|
|
8402
8578
|
}
|
|
8403
8579
|
function hookLogPath(env) {
|
|
8580
|
+
const dir = env[DATA_DIR_ENV];
|
|
8581
|
+
if (dir !== void 0 && dir !== "") return join6(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
8404
8582
|
const home = homeOf(env);
|
|
8405
|
-
return home === "" ? "" :
|
|
8583
|
+
return home === "" ? "" : join6(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
8406
8584
|
}
|
|
8407
8585
|
function errorLabel(err) {
|
|
8408
8586
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -8413,7 +8591,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
8413
8591
|
try {
|
|
8414
8592
|
const file2 = hookLogPath(env);
|
|
8415
8593
|
if (file2 === "") return;
|
|
8416
|
-
fs.mkdirSync(
|
|
8594
|
+
fs.mkdirSync(join6(file2, ".."), { recursive: true });
|
|
8417
8595
|
const line = JSON.stringify({
|
|
8418
8596
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8419
8597
|
agent,
|
|
@@ -8484,17 +8662,19 @@ function isPreTool(row5, event) {
|
|
|
8484
8662
|
const e = event.toLowerCase();
|
|
8485
8663
|
return HOOK_FAIL_PRE_EVENTS.includes(e) || (row5.eventMap.PreToolUse ?? "").toLowerCase() === e;
|
|
8486
8664
|
}
|
|
8487
|
-
function
|
|
8488
|
-
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
8489
|
-
const p = firstString(input, READ_PATH_KEYS);
|
|
8490
|
-
if (p === "") return false;
|
|
8665
|
+
function bigFile(abs) {
|
|
8491
8666
|
try {
|
|
8492
|
-
const st = fs.statSync(
|
|
8667
|
+
const st = fs.statSync(abs);
|
|
8493
8668
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
8494
8669
|
} catch {
|
|
8495
8670
|
return false;
|
|
8496
8671
|
}
|
|
8497
8672
|
}
|
|
8673
|
+
function bigRead(input, cwd) {
|
|
8674
|
+
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
8675
|
+
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
|
|
8676
|
+
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)));
|
|
8677
|
+
}
|
|
8498
8678
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
8499
8679
|
const row5 = getAdapter(agent);
|
|
8500
8680
|
const allow = () => row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
@@ -8519,7 +8699,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
8519
8699
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
8520
8700
|
|
|
8521
8701
|
// src/core/hooks/dispatch.ts
|
|
8522
|
-
var { readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
8702
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
8523
8703
|
var ALLOW2 = { kind: "allow" };
|
|
8524
8704
|
var EMPTY4 = { stdout: "", exitCode: 0 };
|
|
8525
8705
|
var DIGIT_0 = 48;
|
|
@@ -8780,7 +8960,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
8780
8960
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
8781
8961
|
const command = tool.input.command;
|
|
8782
8962
|
if (typeof command !== "string") return d0;
|
|
8783
|
-
const wrapper = '"' +
|
|
8963
|
+
const wrapper = '"' + join7(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
8784
8964
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
8785
8965
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
8786
8966
|
}
|
|
@@ -8821,7 +9001,7 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
8821
9001
|
const tool = ev.tool;
|
|
8822
9002
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
8823
9003
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
8824
|
-
const text = wholeOutput(result);
|
|
9004
|
+
const text = wholeOutput(result, ev.sessionId, env);
|
|
8825
9005
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
8826
9006
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
8827
9007
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -8859,6 +9039,7 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
8859
9039
|
}
|
|
8860
9040
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
8861
9041
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
9042
|
+
if (boundedRead(tool)) return ALLOW2;
|
|
8862
9043
|
if (result.keep === true) return ALLOW2;
|
|
8863
9044
|
if (!hasReplace(row5)) return ALLOW2;
|
|
8864
9045
|
let label2;
|
|
@@ -8890,16 +9071,32 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
8890
9071
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
8891
9072
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, handleLine) : selected.text };
|
|
8892
9073
|
}
|
|
9074
|
+
function boundedRead(tool) {
|
|
9075
|
+
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
9076
|
+
}
|
|
8893
9077
|
function replaceOutput(body, handleLine) {
|
|
8894
9078
|
return body === "" ? handleLine : body + "\n" + handleLine;
|
|
8895
9079
|
}
|
|
8896
9080
|
function replaceBudget(handleLine, more) {
|
|
8897
9081
|
return Math.max(0, REPLACE_RETURN_BYTES + Buffer.byteLength("\n" + more) - 1 - Buffer.byteLength(handleLine));
|
|
8898
9082
|
}
|
|
8899
|
-
function
|
|
9083
|
+
function hostToolResult(file2, sessionId, env) {
|
|
9084
|
+
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
9085
|
+
const projects = join7(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
9086
|
+
const steps = relative3(projects, resolve6(file2)).split(sep3);
|
|
9087
|
+
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
9088
|
+
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
9089
|
+
const st = lstatSync2(file2);
|
|
9090
|
+
return st.isFile() && st.size <= PERSISTED_OUTPUT_MAX_BYTES && isInside(projects, file2);
|
|
9091
|
+
}
|
|
9092
|
+
function wholeOutput(result, sessionId, env) {
|
|
8900
9093
|
const head = result.text ?? "";
|
|
8901
9094
|
if (result.persistedPath === void 0) return head;
|
|
8902
9095
|
try {
|
|
9096
|
+
if (!hostToolResult(result.persistedPath, sessionId, env)) {
|
|
9097
|
+
logHookError(env, "claude-code", "persisted-output", new Error("persisted output path is outside this session's tool-results dir or too large; kept the head"));
|
|
9098
|
+
return head;
|
|
9099
|
+
}
|
|
8903
9100
|
return readFileSync4(result.persistedPath, "utf8");
|
|
8904
9101
|
} catch {
|
|
8905
9102
|
return head;
|
|
@@ -20218,10 +20415,10 @@ function findRuntime(lang, env = process.env) {
|
|
|
20218
20415
|
return shim;
|
|
20219
20416
|
}
|
|
20220
20417
|
function findGitBash(env) {
|
|
20221
|
-
const
|
|
20222
|
-
if (
|
|
20418
|
+
const git2 = findRuntime(GIT_BIN, env);
|
|
20419
|
+
if (git2 === null) return null;
|
|
20223
20420
|
for (const rel of GIT_BASH_RELATIVE) {
|
|
20224
|
-
const full = path.resolve(path.dirname(
|
|
20421
|
+
const full = path.resolve(path.dirname(git2), ...rel);
|
|
20225
20422
|
if (isRunnable(full)) return full;
|
|
20226
20423
|
}
|
|
20227
20424
|
return null;
|
|
@@ -20262,10 +20459,10 @@ function startArgv(argv) {
|
|
|
20262
20459
|
return sh === null ? null : [sh, ...argv];
|
|
20263
20460
|
}
|
|
20264
20461
|
function runProcess(argv, o) {
|
|
20265
|
-
return new Promise((
|
|
20462
|
+
return new Promise((resolve9) => {
|
|
20266
20463
|
const isWin2 = process.platform === "win32";
|
|
20267
20464
|
const start = startArgv(argv);
|
|
20268
|
-
if (start === null) return
|
|
20465
|
+
if (start === null) return resolve9(NOT_STARTED);
|
|
20269
20466
|
let child;
|
|
20270
20467
|
try {
|
|
20271
20468
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -20279,7 +20476,7 @@ function runProcess(argv, o) {
|
|
|
20279
20476
|
windowsHide: true
|
|
20280
20477
|
});
|
|
20281
20478
|
} catch {
|
|
20282
|
-
return
|
|
20479
|
+
return resolve9(NOT_STARTED);
|
|
20283
20480
|
}
|
|
20284
20481
|
const stdoutChunks = [];
|
|
20285
20482
|
const stderrChunks = [];
|
|
@@ -20304,7 +20501,7 @@ function runProcess(argv, o) {
|
|
|
20304
20501
|
settled = true;
|
|
20305
20502
|
clearTimeout(timer);
|
|
20306
20503
|
o.signal.removeEventListener("abort", onAbort);
|
|
20307
|
-
|
|
20504
|
+
resolve9({
|
|
20308
20505
|
stdout: Buffer.concat(stdoutChunks),
|
|
20309
20506
|
stderr: Buffer.concat(stderrChunks),
|
|
20310
20507
|
exitCode,
|
|
@@ -20326,7 +20523,7 @@ function runProcess(argv, o) {
|
|
|
20326
20523
|
|
|
20327
20524
|
// src/core/index/auto-memory.ts
|
|
20328
20525
|
import { readdirSync, readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
|
|
20329
|
-
import { join as
|
|
20526
|
+
import { join as join8 } from "node:path";
|
|
20330
20527
|
var MEMORY_FILES = Object.freeze([
|
|
20331
20528
|
Object.freeze(["CLAUDE.md"]),
|
|
20332
20529
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -20340,7 +20537,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20340
20537
|
var MD = ".md";
|
|
20341
20538
|
function steeringFiles(worktree) {
|
|
20342
20539
|
try {
|
|
20343
|
-
return readdirSync(
|
|
20540
|
+
return readdirSync(join8(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20344
20541
|
} catch {
|
|
20345
20542
|
return [];
|
|
20346
20543
|
}
|
|
@@ -20348,7 +20545,7 @@ function steeringFiles(worktree) {
|
|
|
20348
20545
|
function readAutoMemory(project) {
|
|
20349
20546
|
const rows = [];
|
|
20350
20547
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20351
|
-
const path8 =
|
|
20548
|
+
const path8 = join8(project.worktree, ...segs);
|
|
20352
20549
|
if (!isInside(project.worktree, path8)) continue;
|
|
20353
20550
|
try {
|
|
20354
20551
|
const st = statSync4(path8);
|
|
@@ -20931,18 +21128,18 @@ var ctxBatch = Object.freeze({
|
|
|
20931
21128
|
|
|
20932
21129
|
// src/core/tools/doctor.ts
|
|
20933
21130
|
import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
|
|
20934
|
-
import { basename as basename5, join as
|
|
21131
|
+
import { basename as basename5, join as join18 } from "node:path";
|
|
20935
21132
|
|
|
20936
21133
|
// src/core/ops/bundle-dir.ts
|
|
20937
21134
|
import { existsSync as existsSync3 } from "node:fs";
|
|
20938
|
-
import { dirname as dirname5, join as
|
|
21135
|
+
import { dirname as dirname5, join as join9 } from "node:path";
|
|
20939
21136
|
import { fileURLToPath } from "node:url";
|
|
20940
21137
|
function bundleDirOf(argv1, moduleFile) {
|
|
20941
21138
|
const own2 = dirname5(argv1);
|
|
20942
|
-
if (existsSync3(
|
|
21139
|
+
if (existsSync3(join9(own2, SERVER_ENTRY_FILE))) return own2;
|
|
20943
21140
|
let dir = dirname5(moduleFile);
|
|
20944
21141
|
for (; ; ) {
|
|
20945
|
-
if (existsSync3(
|
|
21142
|
+
if (existsSync3(join9(dir, SERVER_ENTRY_FILE))) return dir;
|
|
20946
21143
|
const up = dirname5(dir);
|
|
20947
21144
|
if (up === dir) return own2;
|
|
20948
21145
|
dir = up;
|
|
@@ -20957,16 +21154,16 @@ function ownBundleDir() {
|
|
|
20957
21154
|
|
|
20958
21155
|
// src/core/ops/doctor-config.ts
|
|
20959
21156
|
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
20960
|
-
import { join as
|
|
21157
|
+
import { join as join13 } from "node:path";
|
|
20961
21158
|
|
|
20962
21159
|
// src/core/ops/detect-v1.ts
|
|
20963
21160
|
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
|
|
20964
21161
|
import { tmpdir } from "node:os";
|
|
20965
|
-
import { join as
|
|
21162
|
+
import { join as join11 } from "node:path";
|
|
20966
21163
|
|
|
20967
21164
|
// src/core/ops/host-config.ts
|
|
20968
21165
|
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
20969
|
-
import { dirname as dirname6, join as
|
|
21166
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
20970
21167
|
|
|
20971
21168
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
20972
21169
|
var KEYS2 = {
|
|
@@ -23083,7 +23280,7 @@ function formatOf(path8) {
|
|
|
23083
23280
|
function readHostConfig(agent, path8) {
|
|
23084
23281
|
let file2 = path8;
|
|
23085
23282
|
if (agent === "opencode") {
|
|
23086
|
-
const jsonc =
|
|
23283
|
+
const jsonc = join10(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23087
23284
|
if (existsSync4(jsonc)) file2 = jsonc;
|
|
23088
23285
|
}
|
|
23089
23286
|
const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -23394,8 +23591,8 @@ function replaceToml(text, doc, path8, value) {
|
|
|
23394
23591
|
let out = text;
|
|
23395
23592
|
for (const [s, e, put] of cuts) out = out.slice(0, s) + put + out.slice(e);
|
|
23396
23593
|
if (owned.length > 0 || block === "") return out;
|
|
23397
|
-
const
|
|
23398
|
-
return out +
|
|
23594
|
+
const sep5 = out === "" ? "" : out.endsWith("\n\n") ? "" : out.endsWith("\n") ? "\n" : "\n\n";
|
|
23595
|
+
return out + sep5 + block;
|
|
23399
23596
|
}
|
|
23400
23597
|
var tableLike = (v) => v === void 0 || isPlainObject3(v);
|
|
23401
23598
|
function setTomlText(text, path8, value) {
|
|
@@ -23431,33 +23628,39 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
23431
23628
|
}
|
|
23432
23629
|
}
|
|
23433
23630
|
function serverScript() {
|
|
23434
|
-
return
|
|
23631
|
+
return join10(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23435
23632
|
}
|
|
23436
23633
|
function isNodeCommand(command) {
|
|
23437
23634
|
if (typeof command !== "string") return false;
|
|
23438
23635
|
let at2 = -1;
|
|
23439
|
-
for (const
|
|
23636
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, command.lastIndexOf(sep5));
|
|
23440
23637
|
const exe = command.slice(at2 + 1).toLowerCase();
|
|
23441
23638
|
return exe === HOST_NODE_COMMAND || exe === HOST_NODE_COMMAND + EXE_SUFFIX;
|
|
23442
23639
|
}
|
|
23443
23640
|
function ownMcpValue(agent, node, server2) {
|
|
23444
23641
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23445
23642
|
if (mcp === void 0) return void 0;
|
|
23446
|
-
|
|
23447
|
-
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server2, AGENT_ARG, agent, ...tail] };
|
|
23643
|
+
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server2, AGENT_ARG, agent] };
|
|
23448
23644
|
}
|
|
23449
23645
|
function opencodePluginFile() {
|
|
23450
23646
|
return ownBundleDir();
|
|
23451
23647
|
}
|
|
23452
|
-
function listTarget(key,
|
|
23648
|
+
function listTarget(key, legacy, swap, isNative) {
|
|
23453
23649
|
return {
|
|
23454
23650
|
key: [key],
|
|
23455
23651
|
next(current) {
|
|
23456
|
-
|
|
23457
|
-
|
|
23652
|
+
if (!Array.isArray(current) || !current.some(legacy)) return current;
|
|
23653
|
+
const keep = current.filter((x) => !legacy(x));
|
|
23654
|
+
if (keep.some(isNative)) return keep;
|
|
23655
|
+
const at2 = current.findIndex(legacy);
|
|
23656
|
+
return current.flatMap((x, i) => i === at2 ? [swap(x)] : legacy(x) ? [] : [x]);
|
|
23458
23657
|
}
|
|
23459
23658
|
};
|
|
23460
23659
|
}
|
|
23660
|
+
var piSource = (x) => isPlainObject3(x) ? x[PI_PACKAGE_SOURCE_KEY] : x;
|
|
23661
|
+
var opencodeSpec = (x) => isPlainObject3(x) ? x[OPENCODE_PACKAGE_FIELD] : x;
|
|
23662
|
+
var isNpmOf = (bare2) => (s) => typeof s === "string" && (s === bare2 || s.startsWith(bare2 + NPM_VERSION_SEP));
|
|
23663
|
+
var swapField = (field, spec) => (x) => isPlainObject3(x) ? { ...x, [field]: spec } : spec;
|
|
23461
23664
|
function ownTargets(agent, accept) {
|
|
23462
23665
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23463
23666
|
if (mcp !== void 0) {
|
|
@@ -23470,8 +23673,18 @@ function ownTargets(agent, accept) {
|
|
|
23470
23673
|
}
|
|
23471
23674
|
}, ...(mcp.also ?? []).map(([key, value]) => ({ key, next: () => value }))];
|
|
23472
23675
|
}
|
|
23473
|
-
if (agent === "opencode")
|
|
23474
|
-
|
|
23676
|
+
if (agent === "opencode") {
|
|
23677
|
+
const alt = accept.listEntries ?? [];
|
|
23678
|
+
const native = (x) => {
|
|
23679
|
+
const s = opencodeSpec(x);
|
|
23680
|
+
return typeof s === "string" && (s.startsWith(OPENCODE_NPM_SPEC_PREFIX) || alt.includes(s));
|
|
23681
|
+
};
|
|
23682
|
+
return [listTarget(OPENCODE_PLUGIN_KEY, (x) => opencodeSpec(x) === OPENCODE_GIT_SPEC, swapField(OPENCODE_PACKAGE_FIELD, OPENCODE_NPM_LATEST), native)];
|
|
23683
|
+
}
|
|
23684
|
+
if (agent === "pi") {
|
|
23685
|
+
const npm = isNpmOf(V1_PI_PACKAGE);
|
|
23686
|
+
return [listTarget(PI_PACKAGES_KEY, (x) => piSource(x) === PI_GIT_PACKAGE, swapField(PI_PACKAGE_SOURCE_KEY, PI_NPM_LATEST), (x) => npm(piSource(x)))];
|
|
23687
|
+
}
|
|
23475
23688
|
return [];
|
|
23476
23689
|
}
|
|
23477
23690
|
function applyEdits(agent, path8, text, format, wanted) {
|
|
@@ -23573,7 +23786,7 @@ function isV2McpTable(v) {
|
|
|
23573
23786
|
const first = Array.isArray(v[MCP_ARGS_FIELD]) ? v[MCP_ARGS_FIELD][0] : void 0;
|
|
23574
23787
|
if (typeof first !== "string") return false;
|
|
23575
23788
|
let at2 = -1;
|
|
23576
|
-
for (const
|
|
23789
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, first.lastIndexOf(sep5));
|
|
23577
23790
|
return first.slice(at2 + 1) === SERVER_ENTRY_FILE;
|
|
23578
23791
|
}
|
|
23579
23792
|
var listOf = (v) => Array.isArray(v) ? v : [];
|
|
@@ -23604,7 +23817,7 @@ function flatCommands(events, prefix) {
|
|
|
23604
23817
|
return out;
|
|
23605
23818
|
}
|
|
23606
23819
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23607
|
-
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((
|
|
23820
|
+
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep5) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5));
|
|
23608
23821
|
function dataDir(dir, reason, out) {
|
|
23609
23822
|
if (existsSync5(dir)) out.push(finding(dir, "", reason));
|
|
23610
23823
|
}
|
|
@@ -23614,7 +23827,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23614
23827
|
}
|
|
23615
23828
|
}
|
|
23616
23829
|
function claudeShapeSettings(agentHome, out) {
|
|
23617
|
-
const file2 =
|
|
23830
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23618
23831
|
const doc = readJson(file2);
|
|
23619
23832
|
for (const c of nestedCommands(doc)) {
|
|
23620
23833
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23634,49 +23847,50 @@ function v1HookFile(file2, out) {
|
|
|
23634
23847
|
function scanClaudeCode(home, agentHome, out) {
|
|
23635
23848
|
claudeShapeSettings(agentHome, out);
|
|
23636
23849
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23637
|
-
const file2 =
|
|
23850
|
+
const file2 = join11(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
23638
23851
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23639
23852
|
}
|
|
23640
|
-
const userFile =
|
|
23853
|
+
const userFile = join11(home, CLAUDE_USER_CONFIG_FILE);
|
|
23641
23854
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23642
|
-
dataDir(
|
|
23855
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23643
23856
|
}
|
|
23644
23857
|
function scanCodex(agentHome, out) {
|
|
23645
|
-
const hooksFile =
|
|
23858
|
+
const hooksFile = join11(agentHome, HOOKS_JSON_FILE);
|
|
23646
23859
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23647
23860
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23648
23861
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23649
23862
|
}
|
|
23650
23863
|
}
|
|
23651
|
-
const tomlFile =
|
|
23864
|
+
const tomlFile = join11(agentHome, CONFIG_TOML_FILE);
|
|
23652
23865
|
const config2 = readTomlValue(tomlFile);
|
|
23653
23866
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23654
23867
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23655
23868
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
|
|
23656
23869
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23657
23870
|
}
|
|
23658
|
-
dataDir(
|
|
23871
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23659
23872
|
}
|
|
23660
23873
|
function scanGemini(agentHome, out) {
|
|
23661
|
-
const file2 =
|
|
23874
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23662
23875
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23663
23876
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23664
23877
|
}
|
|
23665
|
-
dataDir(
|
|
23878
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23666
23879
|
}
|
|
23667
23880
|
function scanVscode(agentHome, project, out) {
|
|
23668
23881
|
if (project !== void 0) {
|
|
23669
|
-
v1HookFile(
|
|
23670
|
-
const mcpFile2 =
|
|
23882
|
+
v1HookFile(join11(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
23883
|
+
const mcpFile2 = join11(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
23671
23884
|
const doc = readJson(mcpFile2);
|
|
23672
23885
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23673
23886
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23674
23887
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23675
23888
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23676
23889
|
}
|
|
23677
|
-
|
|
23890
|
+
const sessions = join11(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
23891
|
+
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
23678
23892
|
}
|
|
23679
|
-
dataDir(
|
|
23893
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23680
23894
|
}
|
|
23681
23895
|
function jsonFiles(dir) {
|
|
23682
23896
|
try {
|
|
@@ -23686,10 +23900,10 @@ function jsonFiles(dir) {
|
|
|
23686
23900
|
}
|
|
23687
23901
|
}
|
|
23688
23902
|
function scanKiro(agentHome, project, out) {
|
|
23689
|
-
const agentsDir =
|
|
23690
|
-
const defaultFile =
|
|
23903
|
+
const agentsDir = join11(agentHome, KIRO_AGENTS_DIR);
|
|
23904
|
+
const defaultFile = join11(agentHome, ...KIRO_AGENT_FILE);
|
|
23691
23905
|
for (const name of jsonFiles(agentsDir)) {
|
|
23692
|
-
const file2 =
|
|
23906
|
+
const file2 = join11(agentsDir, name);
|
|
23693
23907
|
const doc = readJson(file2);
|
|
23694
23908
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23695
23909
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23700,46 +23914,48 @@ function scanKiro(agentHome, project, out) {
|
|
|
23700
23914
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23701
23915
|
}
|
|
23702
23916
|
}
|
|
23703
|
-
const steeringDocs = [
|
|
23704
|
-
if (project !== void 0) steeringDocs.push(
|
|
23917
|
+
const steeringDocs = [join11(agentHome, ...KIRO_STEERING_FILE)];
|
|
23918
|
+
if (project !== void 0) steeringDocs.push(join11(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
23705
23919
|
for (const file2 of steeringDocs) {
|
|
23706
23920
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
23707
23921
|
}
|
|
23708
|
-
dataDir(
|
|
23922
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23709
23923
|
}
|
|
23710
23924
|
function piNpmIsCurrent(piAgentDir) {
|
|
23711
|
-
const doc = readJson(
|
|
23925
|
+
const doc = readJson(join11(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23712
23926
|
const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23713
23927
|
return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
|
|
23714
23928
|
}
|
|
23715
23929
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23716
|
-
const file2 =
|
|
23930
|
+
const file2 = join11(piAgentDir, SETTINGS_FILE);
|
|
23717
23931
|
const doc = readJson(file2);
|
|
23718
23932
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23719
23933
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23720
23934
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23935
|
+
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
23721
23936
|
});
|
|
23722
|
-
dataDir(
|
|
23937
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23723
23938
|
}
|
|
23724
23939
|
function scanOpencode(agentHome, out) {
|
|
23725
23940
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
23726
|
-
const file2 =
|
|
23941
|
+
const file2 = join11(agentHome, name);
|
|
23727
23942
|
const doc = readJson(file2);
|
|
23728
23943
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
23729
23944
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
23730
23945
|
if (spec === V1_OPENCODE_PLUGIN_SPEC) out.push(finding(file2, keyPath(OPENCODE_PLUGIN_KEY, i), V1_REASON.opencodePlugin));
|
|
23946
|
+
if (spec === OPENCODE_GIT_SPEC) out.push(finding(file2, keyPath(OPENCODE_PLUGIN_KEY, i), V1_REASON.opencodeGit));
|
|
23731
23947
|
});
|
|
23732
23948
|
return;
|
|
23733
23949
|
}
|
|
23734
23950
|
}
|
|
23735
23951
|
function scanZcode(agentHome, out) {
|
|
23736
|
-
const configFile =
|
|
23952
|
+
const configFile = join11(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
23737
23953
|
const config2 = readJson(configFile);
|
|
23738
23954
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
23739
23955
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
23740
23956
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
23741
23957
|
}
|
|
23742
|
-
const hooksFile =
|
|
23958
|
+
const hooksFile = join11(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
23743
23959
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23744
23960
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
23745
23961
|
}
|
|
@@ -23763,14 +23979,14 @@ function firstTmpMatch(dir) {
|
|
|
23763
23979
|
}
|
|
23764
23980
|
}
|
|
23765
23981
|
function scanAll(home, tmp, out) {
|
|
23766
|
-
const root =
|
|
23767
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
23982
|
+
const root = join11(home, DATA_ROOT.slice(1));
|
|
23983
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join11(root, name), V1_REASON.dataRoot, out);
|
|
23768
23984
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
23769
23985
|
}
|
|
23770
23986
|
function detectV1(agent, home, scope = {}) {
|
|
23771
23987
|
const out = [];
|
|
23772
23988
|
const project = scope.project;
|
|
23773
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
23989
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join11(home, ...AGENT_HOME_DIR[agent]);
|
|
23774
23990
|
switch (agent) {
|
|
23775
23991
|
case "claude-code":
|
|
23776
23992
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -23783,11 +23999,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23783
23999
|
break;
|
|
23784
24000
|
case "qwen":
|
|
23785
24001
|
claudeShapeSettings(agentHome, out);
|
|
23786
|
-
dataDir(
|
|
24002
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23787
24003
|
break;
|
|
23788
24004
|
case "copilot-cli":
|
|
23789
|
-
v1HookFile(
|
|
23790
|
-
dataDir(
|
|
24005
|
+
v1HookFile(join11(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24006
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23791
24007
|
break;
|
|
23792
24008
|
case "vscode":
|
|
23793
24009
|
scanVscode(agentHome, project, out);
|
|
@@ -23796,7 +24012,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23796
24012
|
scanKiro(agentHome, project, out);
|
|
23797
24013
|
break;
|
|
23798
24014
|
case "pi":
|
|
23799
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24015
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join11(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
23800
24016
|
break;
|
|
23801
24017
|
// D-WIN-PIDIR-1: empty is unset
|
|
23802
24018
|
case "opencode":
|
|
@@ -23812,7 +24028,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23812
24028
|
|
|
23813
24029
|
// src/core/ops/plugin-root.ts
|
|
23814
24030
|
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23815
|
-
import { dirname as dirname7, isAbsolute as isAbsolute2, join as
|
|
24031
|
+
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join12, sep as sep4 } from "node:path";
|
|
23816
24032
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23817
24033
|
function missing(agent, path8) {
|
|
23818
24034
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -23860,8 +24076,8 @@ var readOrNull = (file2) => {
|
|
|
23860
24076
|
};
|
|
23861
24077
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
23862
24078
|
function enabledPlugins(claudeDir, project) {
|
|
23863
|
-
const files = [
|
|
23864
|
-
if (project !== void 0) files.push(
|
|
24079
|
+
const files = [join12(claudeDir, SETTINGS_FILE)];
|
|
24080
|
+
if (project !== void 0) files.push(join12(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join12(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
23865
24081
|
const out = {};
|
|
23866
24082
|
for (const file2 of files) {
|
|
23867
24083
|
const text = readOrNull(file2);
|
|
@@ -23877,7 +24093,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
23877
24093
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23878
24094
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
23879
24095
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
23880
|
-
const record4 = readOrNull(
|
|
24096
|
+
const record4 = readOrNull(join12(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
23881
24097
|
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
23882
24098
|
if (recorded.length === 0) return { record: false };
|
|
23883
24099
|
const live = recorded.filter((r) => existsSync6(r.installPath));
|
|
@@ -23900,18 +24116,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
23900
24116
|
}
|
|
23901
24117
|
function marketplaceRoot(adapter, env, worktree) {
|
|
23902
24118
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23903
|
-
const plugins =
|
|
23904
|
-
const cache =
|
|
24119
|
+
const plugins = join12(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24120
|
+
const cache = join12(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23905
24121
|
const script = process.argv[1];
|
|
23906
24122
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23907
24123
|
const choice = marketplaceChoice(env, worktree);
|
|
23908
24124
|
if ("root" in choice) return choice.root;
|
|
23909
24125
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
23910
24126
|
const cacheReal = realOrNull(cache);
|
|
23911
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal +
|
|
23912
|
-
const pattern =
|
|
24127
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync6(join12(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24128
|
+
const pattern = join12(cache, "*", PLUGIN_NAME);
|
|
23913
24129
|
if (!existsSync6(cache)) throw missing(adapter.id, pattern);
|
|
23914
|
-
const found = readdirSync3(cache).sort().map((marketplace) =>
|
|
24130
|
+
const found = readdirSync3(cache).sort().map((marketplace) => join12(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
|
|
23915
24131
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
23916
24132
|
return found[0];
|
|
23917
24133
|
}
|
|
@@ -23936,9 +24152,9 @@ function candidate(adapter, env, worktree) {
|
|
|
23936
24152
|
case "hooks+mcp":
|
|
23937
24153
|
return configEntryRoot(adapter, env);
|
|
23938
24154
|
case "extension":
|
|
23939
|
-
return
|
|
24155
|
+
return join12(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join12(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
23940
24156
|
case "plugin":
|
|
23941
|
-
return
|
|
24157
|
+
return join12(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
23942
24158
|
case "in-process":
|
|
23943
24159
|
return dirname7(fileURLToPath2(import.meta.url));
|
|
23944
24160
|
}
|
|
@@ -24045,7 +24261,7 @@ function composeMatcher(row5, event) {
|
|
|
24045
24261
|
}
|
|
24046
24262
|
var lastSegment = (p) => {
|
|
24047
24263
|
let at2 = -1;
|
|
24048
|
-
for (const
|
|
24264
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, p.lastIndexOf(sep5));
|
|
24049
24265
|
return p.slice(at2 + 1);
|
|
24050
24266
|
};
|
|
24051
24267
|
function splitHead(command) {
|
|
@@ -24067,7 +24283,7 @@ function isOwnCommand(command, agent) {
|
|
|
24067
24283
|
if (!split.rest.endsWith(tail) || split.rest.length <= tail.length) return false;
|
|
24068
24284
|
let script = split.rest.slice(0, split.rest.length - tail.length);
|
|
24069
24285
|
if (script.startsWith(SHELL_QUOTE) && script.endsWith(SHELL_QUOTE) && script.length > 1) script = script.slice(1, -1);
|
|
24070
|
-
return script === HOOK_ENTRY_FILE || HOOK_SCRIPT_SEPS.some((
|
|
24286
|
+
return script === HOOK_ENTRY_FILE || HOOK_SCRIPT_SEPS.some((sep5) => script.endsWith(sep5 + HOOK_ENTRY_FILE));
|
|
24071
24287
|
}
|
|
24072
24288
|
function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
24073
24289
|
const out = [];
|
|
@@ -24098,11 +24314,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24098
24314
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24099
24315
|
function mcpFile(row5, home, env) {
|
|
24100
24316
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24101
|
-
if (row5.id === "codex") return
|
|
24317
|
+
if (row5.id === "codex") return join13(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24102
24318
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24103
|
-
if (row5.id === "opencode") return
|
|
24319
|
+
if (row5.id === "opencode") return join13(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24104
24320
|
if (row5.id === "pi") {
|
|
24105
|
-
return
|
|
24321
|
+
return join13(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24106
24322
|
}
|
|
24107
24323
|
return null;
|
|
24108
24324
|
}
|
|
@@ -24115,27 +24331,27 @@ function codexNativeDir(env, home) {
|
|
|
24115
24331
|
const codexDir = codexDirOf(env, home);
|
|
24116
24332
|
let enabled;
|
|
24117
24333
|
try {
|
|
24118
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24334
|
+
enabled = hostConfigValueAt(readParsed("codex", join13(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24119
24335
|
} catch {
|
|
24120
24336
|
return null;
|
|
24121
24337
|
}
|
|
24122
24338
|
if (enabled !== true) return null;
|
|
24123
|
-
const cache =
|
|
24339
|
+
const cache = join13(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24124
24340
|
if (!existsSync8(cache)) return null;
|
|
24125
24341
|
const found = [];
|
|
24126
24342
|
for (const market of readdirSync4(cache)) {
|
|
24127
|
-
const plugin =
|
|
24343
|
+
const plugin = join13(cache, market, SERVER_KEY);
|
|
24128
24344
|
if (!existsSync8(plugin)) continue;
|
|
24129
24345
|
for (const version2 of readdirSync4(plugin).sort()) {
|
|
24130
|
-
const dir =
|
|
24131
|
-
if (existsSync8(
|
|
24346
|
+
const dir = join13(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24347
|
+
if (existsSync8(join13(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24132
24348
|
}
|
|
24133
24349
|
}
|
|
24134
24350
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24135
24351
|
}
|
|
24136
24352
|
function nativeMcpWrong(dir, row5) {
|
|
24137
24353
|
try {
|
|
24138
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
24354
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join13(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
24139
24355
|
if (!isObject4(entry)) return true;
|
|
24140
24356
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24141
24357
|
const script = args[0];
|
|
@@ -24150,10 +24366,19 @@ function isOwnOpencodeEntry(entry, key, own2) {
|
|
|
24150
24366
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own2.includes(spec)) return true;
|
|
24151
24367
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
24152
24368
|
}
|
|
24369
|
+
function opencodeMcpOwn(entry) {
|
|
24370
|
+
if (!isObject4(entry)) return false;
|
|
24371
|
+
const cmd = Array.isArray(entry[OPENCODE_MCP_COMMAND_FIELD]) ? entry[OPENCODE_MCP_COMMAND_FIELD] : [entry[MCP_COMMAND_FIELD], ...list2(entry[MCP_ARGS_FIELD])];
|
|
24372
|
+
const [node, script, flag, agent] = cmd;
|
|
24373
|
+
return isNodeCommand(node) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
24374
|
+
}
|
|
24153
24375
|
function opencodeListed(file2) {
|
|
24154
24376
|
const { value } = readParsed("opencode", file2);
|
|
24155
|
-
const
|
|
24156
|
-
|
|
24377
|
+
const bundle = opencodePluginFile();
|
|
24378
|
+
const own2 = [bundle, join13(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
24379
|
+
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
|
|
24380
|
+
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
24381
|
+
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
24157
24382
|
}
|
|
24158
24383
|
function mcpWrong(row5, home, env, worktree) {
|
|
24159
24384
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
@@ -24174,7 +24399,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24174
24399
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24175
24400
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24176
24401
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24177
|
-
const file2 = native !== null ?
|
|
24402
|
+
const file2 = native !== null ? join13(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join13(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join13(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join13(kiroDirOf(env, home), ...spec.file.slice(1)) : join13(root, ...spec.file);
|
|
24178
24403
|
return file2;
|
|
24179
24404
|
}
|
|
24180
24405
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24185,7 +24410,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24185
24410
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24186
24411
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24187
24412
|
if (row5.id === "codex") {
|
|
24188
|
-
const config2 = readParsed(row5.id,
|
|
24413
|
+
const config2 = readParsed(row5.id, join13(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24189
24414
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24190
24415
|
}
|
|
24191
24416
|
} catch {
|
|
@@ -24229,7 +24454,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24229
24454
|
function checkPiInstall(env, home, worktree) {
|
|
24230
24455
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24231
24456
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24232
|
-
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
24457
|
+
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join13(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
24233
24458
|
}
|
|
24234
24459
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24235
24460
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24248,10 +24473,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24248
24473
|
}
|
|
24249
24474
|
function checkDoubleFire(agent, worktree) {
|
|
24250
24475
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24251
|
-
const claude = parsedOrNull(agent,
|
|
24476
|
+
const claude = parsedOrNull(agent, join13(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24252
24477
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24253
24478
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24254
|
-
const vscode = parsedOrNull(agent,
|
|
24479
|
+
const vscode = parsedOrNull(agent, join13(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24255
24480
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24256
24481
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24257
24482
|
}
|
|
@@ -24262,7 +24487,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24262
24487
|
const mcp = mcpFile(row5, home, env);
|
|
24263
24488
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24264
24489
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24265
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
24490
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join13(native, CODEX_PLUGIN_MCP_FILE) });
|
|
24266
24491
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24267
24492
|
if (spec !== null) {
|
|
24268
24493
|
try {
|
|
@@ -24302,7 +24527,7 @@ async function loadSqlite2() {
|
|
|
24302
24527
|
}
|
|
24303
24528
|
}
|
|
24304
24529
|
function openRead(sqlite, path8) {
|
|
24305
|
-
return
|
|
24530
|
+
return openReadOnlyHandle(sqlite, path8);
|
|
24306
24531
|
}
|
|
24307
24532
|
var cell = (row5) => Object.values(row5)[0];
|
|
24308
24533
|
function readSchema(raw) {
|
|
@@ -24376,7 +24601,7 @@ async function checkIndex(project) {
|
|
|
24376
24601
|
|
|
24377
24602
|
// src/core/ops/doctor-env.ts
|
|
24378
24603
|
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
24379
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24604
|
+
import { isAbsolute as isAbsolute3, join as join14, relative as relative4 } from "node:path";
|
|
24380
24605
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24381
24606
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24382
24607
|
}
|
|
@@ -24388,7 +24613,7 @@ function fail4(id2, detail, fixCommand) {
|
|
|
24388
24613
|
}
|
|
24389
24614
|
function bundleVersion(bundleDir2) {
|
|
24390
24615
|
try {
|
|
24391
|
-
const v = JSON.parse(readFileSync10(
|
|
24616
|
+
const v = JSON.parse(readFileSync10(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24392
24617
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24393
24618
|
} catch {
|
|
24394
24619
|
return void 0;
|
|
@@ -24483,12 +24708,12 @@ async function checkVersion(i) {
|
|
|
24483
24708
|
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24484
24709
|
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24485
24710
|
const tag2 = channelOf(i.version);
|
|
24486
|
-
const
|
|
24711
|
+
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24487
24712
|
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24488
24713
|
if (npm.ok) return versionRow(head, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
24489
24714
|
let cause = D1_GIT_MISSING;
|
|
24490
|
-
if (
|
|
24491
|
-
const r = await runProcess([
|
|
24715
|
+
if (git2 !== null) {
|
|
24716
|
+
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
24492
24717
|
cwd: i.cwd,
|
|
24493
24718
|
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
24494
24719
|
signal: i.signal,
|
|
@@ -24502,7 +24727,7 @@ async function checkVersion(i) {
|
|
|
24502
24727
|
cause = gitCause(r, i.timeoutMs);
|
|
24503
24728
|
}
|
|
24504
24729
|
}
|
|
24505
|
-
return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause,
|
|
24730
|
+
return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
24506
24731
|
}
|
|
24507
24732
|
function numbers(v) {
|
|
24508
24733
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -24539,7 +24764,7 @@ function checkMcp(ctx) {
|
|
|
24539
24764
|
}
|
|
24540
24765
|
function piCwdInside(worktree, piCwd) {
|
|
24541
24766
|
if (piCwd === void 0 || !existsSync10(piCwd)) return false;
|
|
24542
|
-
const rel =
|
|
24767
|
+
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24543
24768
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24544
24769
|
}
|
|
24545
24770
|
function checkProject(i) {
|
|
@@ -24563,6 +24788,15 @@ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11
|
|
|
24563
24788
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24564
24789
|
import path7 from "node:path";
|
|
24565
24790
|
|
|
24791
|
+
// src/core/sandbox/host-node.ts
|
|
24792
|
+
var BUN_BE_BUN_ENV = "BUN_BE_BUN";
|
|
24793
|
+
function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
|
|
24794
|
+
if (host.bun === void 0) return { file: host.execPath, env };
|
|
24795
|
+
const node = find2("javascript", env);
|
|
24796
|
+
if (node !== null) return { file: node, env };
|
|
24797
|
+
return { file: host.execPath, env: { ...env, [BUN_BE_BUN_ENV]: "1" } };
|
|
24798
|
+
}
|
|
24799
|
+
|
|
24566
24800
|
// src/setup/codex-trust.ts
|
|
24567
24801
|
import { createHash } from "node:crypto";
|
|
24568
24802
|
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
@@ -24682,14 +24916,14 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
24682
24916
|
function askPluginHooks(env, pluginId, cwd) {
|
|
24683
24917
|
const bin = whichBin("codex", env);
|
|
24684
24918
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
24685
|
-
return new Promise((
|
|
24919
|
+
return new Promise((resolve9) => {
|
|
24686
24920
|
let asked;
|
|
24687
24921
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
24688
24922
|
let f;
|
|
24689
24923
|
try {
|
|
24690
24924
|
f = spawnForm(bin, ["app-server"], env);
|
|
24691
24925
|
} catch {
|
|
24692
|
-
|
|
24926
|
+
resolve9({ kind: "silent" });
|
|
24693
24927
|
return;
|
|
24694
24928
|
}
|
|
24695
24929
|
const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -24699,7 +24933,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
24699
24933
|
let result;
|
|
24700
24934
|
const settle = () => {
|
|
24701
24935
|
clearTimeout(grace);
|
|
24702
|
-
|
|
24936
|
+
resolve9(done_(result));
|
|
24703
24937
|
};
|
|
24704
24938
|
let grace;
|
|
24705
24939
|
const finish2 = (v) => {
|
|
@@ -24769,8 +25003,8 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
24769
25003
|
if (!bad.length) return void 0;
|
|
24770
25004
|
const counts = /* @__PURE__ */ new Map();
|
|
24771
25005
|
for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
|
|
24772
|
-
const
|
|
24773
|
-
const state =
|
|
25006
|
+
const words2 = [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1));
|
|
25007
|
+
const state = words2.length === 1 ? words2[0][0] : `${words2.map(([w]) => w).join(" or ")} (${words2.map(([w, n]) => `${n} ${w}`).join(", ")})`;
|
|
24774
25008
|
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
24775
25009
|
}
|
|
24776
25010
|
|
|
@@ -24851,7 +25085,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
|
24851
25085
|
}
|
|
24852
25086
|
}
|
|
24853
25087
|
var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
|
|
24854
|
-
function readProbePayload(cwd) {
|
|
25088
|
+
function readProbePayload(cwd, ranged) {
|
|
24855
25089
|
const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
|
|
24856
25090
|
const filePath = path7.join(cwd, "d5-read-probe.txt");
|
|
24857
25091
|
return {
|
|
@@ -24861,7 +25095,7 @@ function readProbePayload(cwd) {
|
|
|
24861
25095
|
hook_event_name: "PostToolUse",
|
|
24862
25096
|
tool_name: "Read",
|
|
24863
25097
|
tool_use_id: "toolu_d5_read_probe",
|
|
24864
|
-
tool_input: { file_path: filePath },
|
|
25098
|
+
tool_input: ranged ? { file_path: filePath, offset: 1, limit: READ_PROBE_LINES } : { file_path: filePath },
|
|
24865
25099
|
tool_response: { type: "text", file: { filePath, content, numLines: READ_PROBE_LINES, startLine: 1, totalLines: READ_PROBE_LINES } }
|
|
24866
25100
|
};
|
|
24867
25101
|
}
|
|
@@ -24879,21 +25113,37 @@ function isReadShape(stdout) {
|
|
|
24879
25113
|
const f = r.file;
|
|
24880
25114
|
return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
|
|
24881
25115
|
}
|
|
24882
|
-
async function
|
|
25116
|
+
async function readProbe(i, timeoutMs, ranged) {
|
|
24883
25117
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
24884
25118
|
try {
|
|
24885
|
-
const
|
|
25119
|
+
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
25120
|
+
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24886
25121
|
cwd: i.bundleDir,
|
|
24887
|
-
env:
|
|
25122
|
+
env: node.env,
|
|
24888
25123
|
signal: i.signal,
|
|
24889
25124
|
timeoutMs,
|
|
24890
|
-
stdin: JSON.stringify(readProbePayload(i.worktree ?? home))
|
|
25125
|
+
stdin: JSON.stringify(readProbePayload(i.worktree ?? home, ranged))
|
|
24891
25126
|
});
|
|
24892
|
-
return
|
|
25127
|
+
return r.stdout.toString("utf8");
|
|
24893
25128
|
} finally {
|
|
24894
25129
|
rmSync2(home, { recursive: true, force: true });
|
|
24895
25130
|
}
|
|
24896
25131
|
}
|
|
25132
|
+
function isPassThrough(stdout) {
|
|
25133
|
+
if (stdout.trim() === "") return true;
|
|
25134
|
+
let out;
|
|
25135
|
+
try {
|
|
25136
|
+
out = JSON.parse(stdout);
|
|
25137
|
+
} catch {
|
|
25138
|
+
return false;
|
|
25139
|
+
}
|
|
25140
|
+
return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
|
|
25141
|
+
}
|
|
25142
|
+
async function readProbeDetail(i, timeoutMs) {
|
|
25143
|
+
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
25144
|
+
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
25145
|
+
return null;
|
|
25146
|
+
}
|
|
24897
25147
|
function codexHookJournaled(db) {
|
|
24898
25148
|
if (db === null) return false;
|
|
24899
25149
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -24939,7 +25189,8 @@ async function checkHookRoundTrip(i) {
|
|
|
24939
25189
|
const timeoutMs = i.timeoutMs ?? HOOK_TIMEOUT_MS;
|
|
24940
25190
|
const bareMs = i.bareMs ?? (async () => {
|
|
24941
25191
|
const t = performance.now();
|
|
24942
|
-
|
|
25192
|
+
const node = nodeLaunch(i.env);
|
|
25193
|
+
await runProcess([node.file, "-e", ""], { cwd: i.bundleDir, env: node.env, signal: i.signal, timeoutMs });
|
|
24943
25194
|
return performance.now() - t;
|
|
24944
25195
|
});
|
|
24945
25196
|
const hookWalls = [];
|
|
@@ -24947,9 +25198,10 @@ async function checkHookRoundTrip(i) {
|
|
|
24947
25198
|
let ms = 0;
|
|
24948
25199
|
for (let n = 1; n <= maxPairs; n++) {
|
|
24949
25200
|
const start = now();
|
|
24950
|
-
const
|
|
25201
|
+
const node = nodeLaunch(i.env);
|
|
25202
|
+
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24951
25203
|
cwd: i.bundleDir,
|
|
24952
|
-
env:
|
|
25204
|
+
env: node.env,
|
|
24953
25205
|
signal: i.signal,
|
|
24954
25206
|
timeoutMs,
|
|
24955
25207
|
stdin: JSON.stringify(payloadFor(i.agent, fixture.payload, i.worktree))
|
|
@@ -24961,19 +25213,20 @@ async function checkHookRoundTrip(i) {
|
|
|
24961
25213
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
24962
25214
|
}
|
|
24963
25215
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
24964
|
-
|
|
25216
|
+
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
|
|
25217
|
+
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
24965
25218
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
24966
25219
|
}
|
|
24967
25220
|
|
|
24968
25221
|
// src/core/ops/db-heal.ts
|
|
24969
25222
|
import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
24970
|
-
import { basename as basename4, dirname as dirname8, join as
|
|
25223
|
+
import { basename as basename4, dirname as dirname8, join as join16 } from "node:path";
|
|
24971
25224
|
|
|
24972
25225
|
// src/core/store/owners.ts
|
|
24973
25226
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24974
|
-
import { basename as basename3, join as
|
|
25227
|
+
import { basename as basename3, join as join15 } from "node:path";
|
|
24975
25228
|
function ownersDir(configDir, projectKey) {
|
|
24976
|
-
return
|
|
25229
|
+
return join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24977
25230
|
}
|
|
24978
25231
|
function errCode2(err) {
|
|
24979
25232
|
return err.code;
|
|
@@ -25001,7 +25254,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
25001
25254
|
const live = [];
|
|
25002
25255
|
for (const name of names) {
|
|
25003
25256
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25004
|
-
const file2 =
|
|
25257
|
+
const file2 = join15(dir, name);
|
|
25005
25258
|
let text;
|
|
25006
25259
|
try {
|
|
25007
25260
|
text = readFileSync12(file2, "utf8");
|
|
@@ -25025,7 +25278,7 @@ async function healLossless(dbPath) {
|
|
|
25025
25278
|
const tmp = dbPath + HEAL_TMP_SUFFIX;
|
|
25026
25279
|
rmSync4(tmp, { force: true });
|
|
25027
25280
|
try {
|
|
25028
|
-
const src =
|
|
25281
|
+
const src = openReadOnlyHandle({ DatabaseSync }, dbPath, { queryOnly: false });
|
|
25029
25282
|
try {
|
|
25030
25283
|
src.prepare("VACUUM INTO ?").run(tmp);
|
|
25031
25284
|
} finally {
|
|
@@ -25073,7 +25326,7 @@ function utcStamp(now) {
|
|
|
25073
25326
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
25074
25327
|
}
|
|
25075
25328
|
function makeOrphanDir(projectDir) {
|
|
25076
|
-
const base =
|
|
25329
|
+
const base = join16(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
25077
25330
|
for (let n = 1; ; n += 1) {
|
|
25078
25331
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
25079
25332
|
try {
|
|
@@ -25090,7 +25343,7 @@ async function healOrphan(project, files, row5) {
|
|
|
25090
25343
|
try {
|
|
25091
25344
|
dir = makeOrphanDir(dirname8(project.dbPath));
|
|
25092
25345
|
for (const f of files) {
|
|
25093
|
-
const to =
|
|
25346
|
+
const to = join16(dir, basename4(f.path));
|
|
25094
25347
|
renameWithRetry(f.path, to);
|
|
25095
25348
|
moved.push({ path: to, bytes: f.bytes });
|
|
25096
25349
|
}
|
|
@@ -25158,7 +25411,7 @@ function buildReportHead(input) {
|
|
|
25158
25411
|
// src/core/ops/doctor-issue.ts
|
|
25159
25412
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
25160
25413
|
import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25161
|
-
import { delimiter, join as
|
|
25414
|
+
import { delimiter, join as join17 } from "node:path";
|
|
25162
25415
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
25163
25416
|
function tildeOf(env) {
|
|
25164
25417
|
const home = homeDirOf(env);
|
|
@@ -25199,8 +25452,8 @@ function onPath(env, tool) {
|
|
|
25199
25452
|
const out = [];
|
|
25200
25453
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25201
25454
|
if (dir === "") continue;
|
|
25202
|
-
for (const n of names) if (existsSync14(
|
|
25203
|
-
out.push(
|
|
25455
|
+
for (const n of names) if (existsSync14(join17(dir, n))) {
|
|
25456
|
+
out.push(join17(dir, n));
|
|
25204
25457
|
break;
|
|
25205
25458
|
}
|
|
25206
25459
|
}
|
|
@@ -25246,8 +25499,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25246
25499
|
const home = homeDirOf(env);
|
|
25247
25500
|
const files = configPaths(adapter, env, worktree);
|
|
25248
25501
|
if (home !== null) {
|
|
25249
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
25250
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
25502
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join17(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
25503
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join17(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
25251
25504
|
}
|
|
25252
25505
|
const out = [];
|
|
25253
25506
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -25330,9 +25583,9 @@ async function buildIssueBody(i) {
|
|
|
25330
25583
|
async function writeIssueReport(i) {
|
|
25331
25584
|
const tilde = tildeOf(i.env);
|
|
25332
25585
|
const body = await buildIssueBody(i);
|
|
25333
|
-
const dir =
|
|
25586
|
+
const dir = join17(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
25334
25587
|
mkdirSync6(dir, { recursive: true });
|
|
25335
|
-
const file2 =
|
|
25588
|
+
const file2 = join17(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
25336
25589
|
writeFileSync3(file2, body);
|
|
25337
25590
|
const shown2 = tilde(file2);
|
|
25338
25591
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -25389,11 +25642,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25389
25642
|
}
|
|
25390
25643
|
}
|
|
25391
25644
|
function ownServerId(configDir, projectKey) {
|
|
25392
|
-
const dir =
|
|
25645
|
+
const dir = join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25393
25646
|
if (!existsSync15(dir)) return "";
|
|
25394
25647
|
for (const name of readdirSync6(dir)) {
|
|
25395
25648
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25396
|
-
if (readFileSync14(
|
|
25649
|
+
if (readFileSync14(join18(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25397
25650
|
}
|
|
25398
25651
|
return "";
|
|
25399
25652
|
}
|
|
@@ -25407,7 +25660,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
25407
25660
|
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
25408
25661
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
25409
25662
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
25410
|
-
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
25663
|
+
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), geminiDir: geminiDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
25411
25664
|
D5: () => hookRow(ctx, adapter, host),
|
|
25412
25665
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
25413
25666
|
D6: () => checkMcp(ctx),
|
|
@@ -25448,13 +25701,13 @@ function reportEnv(env) {
|
|
|
25448
25701
|
async function doctorReply(ctx, host) {
|
|
25449
25702
|
const adapter = getAdapter(ctx.project.agent);
|
|
25450
25703
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
25451
|
-
const
|
|
25452
|
-
const command = adapter.id === "pi" ?
|
|
25704
|
+
const failed = rows.some((r) => r.status === "FAIL");
|
|
25705
|
+
const command = adapter.id === "pi" ? failed ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
25453
25706
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
25454
25707
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
25455
25708
|
const table3 = buildReport(input);
|
|
25456
25709
|
let notes = [];
|
|
25457
|
-
if (
|
|
25710
|
+
if (failed) {
|
|
25458
25711
|
try {
|
|
25459
25712
|
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
25460
25713
|
} catch (err) {
|
|
@@ -25490,7 +25743,7 @@ var ctxDoctor = Object.freeze({
|
|
|
25490
25743
|
// src/core/tools/execute.ts
|
|
25491
25744
|
import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25492
25745
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25493
|
-
import { dirname as dirname10, join as
|
|
25746
|
+
import { dirname as dirname10, join as join19, parse as parse3, resolve as resolve7 } from "node:path";
|
|
25494
25747
|
|
|
25495
25748
|
// src/core/sandbox/win-build.ts
|
|
25496
25749
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -25536,7 +25789,6 @@ var ctxExecuteSchema = external_exports.object({
|
|
|
25536
25789
|
background: external_exports.boolean().optional(),
|
|
25537
25790
|
summary: external_exports.boolean().optional()
|
|
25538
25791
|
}, { error: unknownField }).strict();
|
|
25539
|
-
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
25540
25792
|
var SCRIPT_EXT = Object.freeze({
|
|
25541
25793
|
javascript: ".js",
|
|
25542
25794
|
typescript: ".ts",
|
|
@@ -25555,7 +25807,7 @@ var LAUNCHER = [
|
|
|
25555
25807
|
'const { rmSync } = require("node:fs");',
|
|
25556
25808
|
"const [mode, dir, ...argv] = process.argv.slice(1);",
|
|
25557
25809
|
'if (mode === "start") {',
|
|
25558
|
-
' const b = spawn(process.execPath, [...process.execArgv, "--", "run", dir, ...argv], { detached: true, stdio: "ignore", windowsHide: true });',
|
|
25810
|
+
' const b = spawn(process.execPath, [...process.execArgv.filter((a) => a !== "--"), "--", "run", dir, ...argv], { detached: true, stdio: "ignore", windowsHide: true });',
|
|
25559
25811
|
" b.unref();",
|
|
25560
25812
|
" process.stdout.write(String(b.pid));",
|
|
25561
25813
|
"} else {",
|
|
@@ -25638,7 +25890,7 @@ async function handler3(raw, ctx) {
|
|
|
25638
25890
|
const cwd = ctx.project.worktree;
|
|
25639
25891
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
25640
25892
|
if (input.file !== void 0) {
|
|
25641
|
-
const abs =
|
|
25893
|
+
const abs = resolve7(cwd, input.file);
|
|
25642
25894
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
25643
25895
|
if (bad !== null) return fail5(bad);
|
|
25644
25896
|
extra.CTX_FILE = abs;
|
|
@@ -25655,13 +25907,14 @@ async function handler3(raw, ctx) {
|
|
|
25655
25907
|
if (takesDashC(input.language, runtime)) {
|
|
25656
25908
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
25657
25909
|
} else {
|
|
25658
|
-
tmpDir = mkdtempSync2(
|
|
25659
|
-
const file2 =
|
|
25910
|
+
tmpDir = mkdtempSync2(join19(tmpdir3(), TMP_PREFIX));
|
|
25911
|
+
const file2 = join19(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25660
25912
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
25661
25913
|
argv = scriptArgv(input.language, runtime, file2);
|
|
25662
25914
|
}
|
|
25663
25915
|
if (input.background === true) {
|
|
25664
|
-
const
|
|
25916
|
+
const node = nodeLaunch(env);
|
|
25917
|
+
const r2 = await runProcess([node.file, "-e", LAUNCHER, "--", "start", tmpDir ?? "", ...argv], { cwd, env: node.env, signal: ctx.signal, timeoutMs });
|
|
25665
25918
|
const pid = r2.stdout.toString("utf8");
|
|
25666
25919
|
if (r2.exitCode !== 0 || pid === "" || !Number.isSafeInteger(Number(pid))) return fail5(spawnFailed(argv[0], cwd), journal);
|
|
25667
25920
|
handedOff = true;
|
|
@@ -25692,11 +25945,11 @@ var ctxExecute = {
|
|
|
25692
25945
|
|
|
25693
25946
|
// src/core/tools/index.ts
|
|
25694
25947
|
import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
|
|
25695
|
-
import { dirname as dirname11, extname, join as
|
|
25948
|
+
import { dirname as dirname11, extname, join as join21, relative as relative5, resolve as resolve8 } from "node:path";
|
|
25696
25949
|
|
|
25697
25950
|
// src/core/index/walk.ts
|
|
25698
25951
|
import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
25699
|
-
import { join as
|
|
25952
|
+
import { join as join20 } from "node:path";
|
|
25700
25953
|
var GITIGNORE = ".gitignore";
|
|
25701
25954
|
var GIT_DIR = ".git";
|
|
25702
25955
|
function walkDir(root, containmentRoot) {
|
|
@@ -25705,7 +25958,7 @@ function walkDir(root, containmentRoot) {
|
|
|
25705
25958
|
const found = [];
|
|
25706
25959
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
25707
25960
|
found.sort(compareFound);
|
|
25708
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25961
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join20(...f.dir, f.name) }));
|
|
25709
25962
|
}
|
|
25710
25963
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
25711
25964
|
let entries;
|
|
@@ -25714,10 +25967,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25714
25967
|
} catch {
|
|
25715
25968
|
return;
|
|
25716
25969
|
}
|
|
25717
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
25970
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join20(abs, GITIGNORE), rel)) : parent;
|
|
25718
25971
|
for (const e of entries) {
|
|
25719
25972
|
if (e.name === GIT_DIR) continue;
|
|
25720
|
-
const path8 =
|
|
25973
|
+
const path8 = join20(abs, e.name);
|
|
25721
25974
|
let isDir = e.isDirectory();
|
|
25722
25975
|
let isFile = e.isFile();
|
|
25723
25976
|
let target = path8;
|
|
@@ -25851,11 +26104,24 @@ var PRIVATE_RANGES = [
|
|
|
25851
26104
|
["172.16.0.0", 12, "ipv4"],
|
|
25852
26105
|
["192.168.0.0", 16, "ipv4"],
|
|
25853
26106
|
["169.254.0.0", 16, "ipv4"],
|
|
25854
|
-
["0.0.0.0",
|
|
26107
|
+
["0.0.0.0", 8, "ipv4"],
|
|
26108
|
+
// D-SSRF-RANGES-1: "this network", not only 0.0.0.0
|
|
26109
|
+
["100.64.0.0", 10, "ipv4"],
|
|
26110
|
+
// D-SSRF-RANGES-1: shared address space (RFC 6598), cloud metadata lives here
|
|
26111
|
+
["198.18.0.0", 15, "ipv4"],
|
|
26112
|
+
// D-SSRF-RANGES-1: benchmark networks (RFC 2544)
|
|
26113
|
+
["240.0.0.0", 4, "ipv4"],
|
|
26114
|
+
// D-SSRF-RANGES-1: reserved and broadcast
|
|
25855
26115
|
["::1", 128, "ipv6"],
|
|
25856
26116
|
["::", 128, "ipv6"],
|
|
26117
|
+
["::", 96, "ipv6"],
|
|
26118
|
+
// D-SSRF-RANGES-1: IPv4-compatible (::a.b.c.d), deprecated, never a public origin
|
|
26119
|
+
["64:ff9b:1::", 48, "ipv6"],
|
|
26120
|
+
// D-SSRF-RANGES-1: local-use NAT64 (RFC 8215)
|
|
25857
26121
|
["fc00::", 7, "ipv6"],
|
|
25858
|
-
["fe80::", 10, "ipv6"]
|
|
26122
|
+
["fe80::", 10, "ipv6"],
|
|
26123
|
+
["fec0::", 10, "ipv6"]
|
|
26124
|
+
// D-SSRF-RANGES-1: site-local (RFC 3879)
|
|
25859
26125
|
];
|
|
25860
26126
|
var BLOCKED = new BlockList();
|
|
25861
26127
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
@@ -25908,9 +26174,41 @@ function pickProxy(u) {
|
|
|
25908
26174
|
const auth = p.username === "" ? void 0 : "Basic " + Buffer.from(decodeURIComponent(p.username) + ":" + decodeURIComponent(p.password)).toString("base64");
|
|
25909
26175
|
return { url: p, auth };
|
|
25910
26176
|
}
|
|
26177
|
+
function ipv6Words(address) {
|
|
26178
|
+
const zone = address.indexOf("%");
|
|
26179
|
+
const a = zone < 0 ? address : address.slice(0, zone);
|
|
26180
|
+
const words2 = (part) => {
|
|
26181
|
+
if (part === "") return [];
|
|
26182
|
+
const out = [];
|
|
26183
|
+
for (const w of part.split(":")) {
|
|
26184
|
+
if (w.includes(".")) {
|
|
26185
|
+
const q = w.split(".").map(Number);
|
|
26186
|
+
out.push(q[0] * 256 + q[1], q[2] * 256 + q[3]);
|
|
26187
|
+
} else out.push(parseInt(w, 16));
|
|
26188
|
+
}
|
|
26189
|
+
return out;
|
|
26190
|
+
};
|
|
26191
|
+
const gap = a.indexOf("::");
|
|
26192
|
+
if (gap < 0) return words2(a);
|
|
26193
|
+
const head = words2(a.slice(0, gap));
|
|
26194
|
+
const tail = words2(a.slice(gap + 2));
|
|
26195
|
+
return [...head, ...new Array(8 - head.length - tail.length).fill(0), ...tail];
|
|
26196
|
+
}
|
|
26197
|
+
function dotted(hi, lo) {
|
|
26198
|
+
return [hi >> 8, hi & 255, lo >> 8, lo & 255].join(".");
|
|
26199
|
+
}
|
|
26200
|
+
function embeddedIpv4(address) {
|
|
26201
|
+
const w = ipv6Words(address);
|
|
26202
|
+
if (w[0] === 100 && w[1] === 65435 && w[2] === 0 && w[3] === 0 && w[4] === 0 && w[5] === 0) {
|
|
26203
|
+
return dotted(w[6], w[7]);
|
|
26204
|
+
}
|
|
26205
|
+
if (w[0] === 8194) return dotted(w[1], w[2]);
|
|
26206
|
+
return void 0;
|
|
26207
|
+
}
|
|
25911
26208
|
function checkAddress(hostname2, address) {
|
|
25912
26209
|
const family = isIP(address);
|
|
25913
|
-
|
|
26210
|
+
const inner = family === 6 ? embeddedIpv4(address) : void 0;
|
|
26211
|
+
if (family === 0 || BLOCKED.check(address, family === 4 ? "ipv4" : "ipv6") || inner !== void 0 && BLOCKED.check(inner, "ipv4")) {
|
|
25914
26212
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
25915
26213
|
}
|
|
25916
26214
|
}
|
|
@@ -25934,18 +26232,18 @@ function request(u, conn, proxy, signal) {
|
|
|
25934
26232
|
const host = bare(u.hostname);
|
|
25935
26233
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
25936
26234
|
const path8 = u.pathname + u.search;
|
|
25937
|
-
return new Promise((
|
|
26235
|
+
return new Promise((resolve9, reject) => {
|
|
25938
26236
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
25939
26237
|
if (proxy === void 0) {
|
|
25940
26238
|
const mod = u.protocol === "https:" ? https : http;
|
|
25941
26239
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
25942
|
-
req.on("response",
|
|
26240
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25943
26241
|
return;
|
|
25944
26242
|
}
|
|
25945
26243
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
25946
26244
|
if (u.protocol === "http:") {
|
|
25947
26245
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
25948
|
-
req.on("response",
|
|
26246
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25949
26247
|
return;
|
|
25950
26248
|
}
|
|
25951
26249
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -25965,16 +26263,16 @@ function request(u, conn, proxy, signal) {
|
|
|
25965
26263
|
headers: { host: u.host },
|
|
25966
26264
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
25967
26265
|
});
|
|
25968
|
-
req.on("response",
|
|
26266
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25969
26267
|
});
|
|
25970
26268
|
tunnel.end();
|
|
25971
26269
|
});
|
|
25972
26270
|
}
|
|
25973
26271
|
function readBody(res) {
|
|
25974
|
-
return new Promise((
|
|
26272
|
+
return new Promise((resolve9, reject) => {
|
|
25975
26273
|
const parts = [];
|
|
25976
26274
|
res.on("data", (b) => parts.push(b));
|
|
25977
|
-
res.on("end", () =>
|
|
26275
|
+
res.on("end", () => resolve9(Buffer.concat(parts)));
|
|
25978
26276
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
25979
26277
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
25980
26278
|
});
|
|
@@ -28645,7 +28943,7 @@ var DomHandler = class {
|
|
|
28645
28943
|
var dist_exports2 = {};
|
|
28646
28944
|
__export(dist_exports2, {
|
|
28647
28945
|
DocumentPosition: () => DocumentPosition,
|
|
28648
|
-
append: () =>
|
|
28946
|
+
append: () => append2,
|
|
28649
28947
|
appendChild: () => appendChild,
|
|
28650
28948
|
compareDocumentPosition: () => compareDocumentPosition,
|
|
28651
28949
|
existsOne: () => existsOne,
|
|
@@ -29236,11 +29534,11 @@ function compareDocumentPosition(nodeA, nodeB) {
|
|
|
29236
29534
|
function uniqueSort(nodes) {
|
|
29237
29535
|
nodes = nodes.filter((node, index, array2) => !array2.includes(node, index + 1));
|
|
29238
29536
|
nodes.sort((a, b) => {
|
|
29239
|
-
const
|
|
29240
|
-
if (
|
|
29537
|
+
const relative6 = compareDocumentPosition(a, b);
|
|
29538
|
+
if (relative6 & DocumentPosition.PRECEDING) {
|
|
29241
29539
|
return -1;
|
|
29242
29540
|
}
|
|
29243
|
-
if (
|
|
29541
|
+
if (relative6 & DocumentPosition.FOLLOWING) {
|
|
29244
29542
|
return 1;
|
|
29245
29543
|
}
|
|
29246
29544
|
return 0;
|
|
@@ -29297,7 +29595,7 @@ function appendChild(parent, child) {
|
|
|
29297
29595
|
child.prev = null;
|
|
29298
29596
|
}
|
|
29299
29597
|
}
|
|
29300
|
-
function
|
|
29598
|
+
function append2(element2, next) {
|
|
29301
29599
|
removeElement(next);
|
|
29302
29600
|
const { parent } = element2;
|
|
29303
29601
|
const currentNext = element2.next;
|
|
@@ -29809,10 +30107,10 @@ function htmlToReadable(html, baseUrl) {
|
|
|
29809
30107
|
const st = { w: new Writer(), base, sawH1: false };
|
|
29810
30108
|
for (const n of contentRoot(doc.children)) walk2(st, n);
|
|
29811
30109
|
const body = st.w.result();
|
|
29812
|
-
const
|
|
29813
|
-
const text = !st.sawH1 && title !== "" &&
|
|
29814
|
-
const sparse =
|
|
29815
|
-
return { text: text === "" ? "" : text + "\n", title, words, sparse };
|
|
30110
|
+
const words2 = wordCount(body);
|
|
30111
|
+
const text = !st.sawH1 && title !== "" && words2 > 0 ? "# " + title + "\n\n" + body : body;
|
|
30112
|
+
const sparse = words2 < SPARSE_MAX_WORDS && html.length > SPARSE_RATIO * Math.max(text.length, 1);
|
|
30113
|
+
return { text: text === "" ? "" : text + "\n", title, words: words2, sparse };
|
|
29816
30114
|
}
|
|
29817
30115
|
|
|
29818
30116
|
// src/core/tools/index.ts
|
|
@@ -29852,13 +30150,13 @@ function missingOrOutside(given, abs, root) {
|
|
|
29852
30150
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29853
30151
|
}
|
|
29854
30152
|
function pathItems(input, project) {
|
|
29855
|
-
const abs =
|
|
30153
|
+
const abs = resolve8(project.worktree, input.path);
|
|
29856
30154
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
29857
|
-
const base =
|
|
30155
|
+
const base = relative5(project.worktree, abs);
|
|
29858
30156
|
if (statSync8(abs).isDirectory()) {
|
|
29859
30157
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
29860
30158
|
sourceKind: "path",
|
|
29861
|
-
label: pathLabel(
|
|
30159
|
+
label: pathLabel(join21(base, f.relPath)),
|
|
29862
30160
|
kind: kindOfPath(f.relPath),
|
|
29863
30161
|
read: () => readUtf8(f.absPath)
|
|
29864
30162
|
}));
|
|
@@ -30397,13 +30695,9 @@ var ctxStats = Object.freeze({
|
|
|
30397
30695
|
handler: handler7
|
|
30398
30696
|
});
|
|
30399
30697
|
|
|
30400
|
-
// src/core/tools/upgrade.ts
|
|
30401
|
-
import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
|
|
30402
|
-
import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
|
|
30403
|
-
|
|
30404
30698
|
// src/core/ops/host-write.ts
|
|
30405
30699
|
import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30406
|
-
import { dirname as dirname12, join as
|
|
30700
|
+
import { dirname as dirname12, join as join22 } from "node:path";
|
|
30407
30701
|
function defaultWrite(file2, text) {
|
|
30408
30702
|
writeFileSync5(file2, text, "utf8");
|
|
30409
30703
|
}
|
|
@@ -30412,14 +30706,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
30412
30706
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
30413
30707
|
switch (agent) {
|
|
30414
30708
|
case "opencode":
|
|
30415
|
-
return
|
|
30709
|
+
return join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
30416
30710
|
// D-WIN-OPENCODE-DIR-1
|
|
30417
30711
|
case "pi":
|
|
30418
|
-
return
|
|
30712
|
+
return join22(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
30713
|
+
case "gemini":
|
|
30714
|
+
return join22(geminiDirOf(env, home), SETTINGS_FILE);
|
|
30715
|
+
// D-R38-GEMINI-HOME-1
|
|
30419
30716
|
case "copilot-cli":
|
|
30420
30717
|
return null;
|
|
30421
30718
|
default:
|
|
30422
|
-
return
|
|
30719
|
+
return join22(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
30423
30720
|
}
|
|
30424
30721
|
}
|
|
30425
30722
|
function cell3(value) {
|
|
@@ -30468,96 +30765,16 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30468
30765
|
return result.edits.map((e) => toRow(current.path, e));
|
|
30469
30766
|
}
|
|
30470
30767
|
|
|
30471
|
-
// src/core/ops/plugin-swap.ts
|
|
30472
|
-
import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
30473
|
-
import { basename as basename6, join as join22, win32 as win322 } from "node:path";
|
|
30474
|
-
function linkTarget(path8, win) {
|
|
30475
|
-
if (!isLink(path8)) return null;
|
|
30476
|
-
const target = readlinkSync(path8);
|
|
30477
|
-
return win ? win322.basename(target) : target;
|
|
30478
|
-
}
|
|
30479
|
-
function isLink(path8) {
|
|
30480
|
-
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
30481
|
-
}
|
|
30482
|
-
function generations(agentDir) {
|
|
30483
|
-
return readdirSync8(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();
|
|
30484
|
-
}
|
|
30485
|
-
function settleLinks(link, tmp, old, opts) {
|
|
30486
|
-
if (isLink(tmp)) unlinkSync2(tmp);
|
|
30487
|
-
if (!isLink(old)) return;
|
|
30488
|
-
if (isLink(link)) unlinkSync2(old);
|
|
30489
|
-
else renameWithRetry(old, link, opts);
|
|
30490
|
-
}
|
|
30491
|
-
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
30492
|
-
const next = join22(agentDir, sha);
|
|
30493
|
-
if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
|
|
30494
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
30495
|
-
}
|
|
30496
|
-
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
30497
|
-
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
30498
|
-
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
30499
|
-
settleLinks(link, tmp, old, opts);
|
|
30500
|
-
const win = (opts.platform ?? process.platform) === "win32";
|
|
30501
|
-
const before = linkTarget(link, win);
|
|
30502
|
-
if (before === sha) return { current: next, previous: null, removed: [] };
|
|
30503
|
-
const symlink = opts.symlink ?? symlinkSync;
|
|
30504
|
-
if (win) symlink(next, tmp, PLUGIN_LINK_TYPE_WIN32);
|
|
30505
|
-
else symlink(sha, tmp, PLUGIN_LINK_TYPE);
|
|
30506
|
-
if (before !== null) renameWithRetry(link, old, opts);
|
|
30507
|
-
renameWithRetry(tmp, link, opts);
|
|
30508
|
-
if (before !== null) unlinkSync2(old);
|
|
30509
|
-
const keep = /* @__PURE__ */ new Set([sha]);
|
|
30510
|
-
if (before !== null) keep.add(before);
|
|
30511
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
|
|
30512
|
-
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
30513
|
-
const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
|
|
30514
|
-
return { current: next, previous, removed };
|
|
30515
|
-
}
|
|
30516
|
-
|
|
30517
|
-
// src/core/ops/release-fetch.ts
|
|
30518
|
-
import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
30519
|
-
import { join as join23 } from "node:path";
|
|
30520
|
-
function failed(r) {
|
|
30521
|
-
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30522
|
-
const status = r.killed ?? String(r.exitCode);
|
|
30523
|
-
return new CtxError("FETCH_FAILED", { code: GIT_EXIT_LABEL + status + UPGRADE_AREA_KEY_SEP + r.stderr.toString().trim() });
|
|
30524
|
-
}
|
|
30525
|
-
async function git2(bin, args, cwd, env, signal) {
|
|
30526
|
-
const r = await runProcess([bin, ...args], { cwd, env, signal, timeoutMs: UPGRADE_GIT_TIMEOUT_MS });
|
|
30527
|
-
if (r.exitCode !== 0 || r.killed !== null) throw failed(r);
|
|
30528
|
-
return r.stdout.toString().trim();
|
|
30529
|
-
}
|
|
30530
|
-
async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
30531
|
-
const agentDir = join23(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
30532
|
-
mkdirSync8(agentDir, { recursive: true });
|
|
30533
|
-
const fetchDir = join23(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
30534
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30535
|
-
const gitBin = findRuntime(GIT_BIN, env);
|
|
30536
|
-
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30537
|
-
const childEnv = buildChildEnv(env, { ...GIT_NO_PROMPT_ENV, ...GIT_NO_CRLF_ENV });
|
|
30538
|
-
try {
|
|
30539
|
-
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
30540
|
-
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
30541
|
-
const dir = join23(agentDir, sha);
|
|
30542
|
-
if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
30543
|
-
else renameWithRetry(fetchDir, dir, opts);
|
|
30544
|
-
return { sha, dir };
|
|
30545
|
-
} catch (e) {
|
|
30546
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30547
|
-
throw e;
|
|
30548
|
-
}
|
|
30549
|
-
}
|
|
30550
|
-
|
|
30551
30768
|
// src/core/ops/uninstall.ts
|
|
30552
|
-
import { existsSync as
|
|
30553
|
-
import { join as
|
|
30769
|
+
import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
30770
|
+
import { join as join23 } from "node:path";
|
|
30554
30771
|
function row2(area, before, after) {
|
|
30555
30772
|
return { area, before, after };
|
|
30556
30773
|
}
|
|
30557
30774
|
function stopServers(configDir, projectKey) {
|
|
30558
30775
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
30559
|
-
const dir =
|
|
30560
|
-
for (const serverId of stopped) writeFileSync6(
|
|
30776
|
+
const dir = join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
30777
|
+
for (const serverId of stopped) writeFileSync6(join23(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
30561
30778
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
30562
30779
|
}
|
|
30563
30780
|
function rootOrNull(adapter, env) {
|
|
@@ -30575,16 +30792,16 @@ function removeCache(adapter, env, configDir) {
|
|
|
30575
30792
|
const root = rootOrNull(adapter, env);
|
|
30576
30793
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30577
30794
|
if (adapter.installMode === "marketplace") {
|
|
30578
|
-
const cache =
|
|
30795
|
+
const cache = join23(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
30579
30796
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
30580
30797
|
}
|
|
30581
|
-
|
|
30798
|
+
rmSync6(root, { recursive: true, force: true });
|
|
30582
30799
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
30583
30800
|
}
|
|
30584
30801
|
case "plugin": {
|
|
30585
|
-
const agentDir =
|
|
30586
|
-
if (!
|
|
30587
|
-
|
|
30802
|
+
const agentDir = join23(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
30803
|
+
if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30804
|
+
rmSync6(agentDir, { recursive: true, force: true });
|
|
30588
30805
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30589
30806
|
}
|
|
30590
30807
|
case "config-mcp":
|
|
@@ -30599,7 +30816,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
30599
30816
|
function isObj3(v) {
|
|
30600
30817
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30601
30818
|
}
|
|
30602
|
-
function
|
|
30819
|
+
function piSource2(entry) {
|
|
30603
30820
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
30604
30821
|
}
|
|
30605
30822
|
function ownEntries2(agent, env) {
|
|
@@ -30628,7 +30845,7 @@ function ownEntries2(agent, env) {
|
|
|
30628
30845
|
}
|
|
30629
30846
|
if (agent === "opencode") {
|
|
30630
30847
|
return [{
|
|
30631
|
-
file:
|
|
30848
|
+
file: join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
30632
30849
|
// D-WIN-OPENCODE-DIR-1
|
|
30633
30850
|
key: OPENCODE_PLUGIN_KEY,
|
|
30634
30851
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -30639,11 +30856,11 @@ function ownEntries2(agent, env) {
|
|
|
30639
30856
|
if (agent === "pi") {
|
|
30640
30857
|
const agentDir = piAgentDirOf(env, home);
|
|
30641
30858
|
return [{
|
|
30642
|
-
file:
|
|
30859
|
+
file: join23(agentDir, SETTINGS_FILE),
|
|
30643
30860
|
key: PI_PACKAGES_KEY,
|
|
30644
30861
|
shown: PI_PACKAGES_KEY,
|
|
30645
|
-
has: (v) => Array.isArray(v) && v.some((x) =>
|
|
30646
|
-
drop: (v) => v.filter((x) =>
|
|
30862
|
+
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
30863
|
+
drop: (v) => v.filter((x) => piSource2(x) !== PI_GIT_PACKAGE)
|
|
30647
30864
|
}];
|
|
30648
30865
|
}
|
|
30649
30866
|
return [];
|
|
@@ -30661,12 +30878,12 @@ function removeOwnEntries(agent, env) {
|
|
|
30661
30878
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
30662
30879
|
}
|
|
30663
30880
|
function removeProjectData(configDir, projectKey) {
|
|
30664
|
-
const projects =
|
|
30665
|
-
const dir =
|
|
30666
|
-
if (!
|
|
30881
|
+
const projects = join23(configDir, PROJECTS_DIR_NAME);
|
|
30882
|
+
const dir = join23(projects, projectKey);
|
|
30883
|
+
if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
30667
30884
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30668
|
-
for (const name of
|
|
30669
|
-
if (name !== OWNERS_DIR_NAME)
|
|
30885
|
+
for (const name of readdirSync8(dir)) {
|
|
30886
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join23(dir, name), { recursive: true, force: true });
|
|
30670
30887
|
}
|
|
30671
30888
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
30672
30889
|
}
|
|
@@ -30674,25 +30891,32 @@ function runUninstall(input) {
|
|
|
30674
30891
|
const configDir = resolveConfigDir(input.env);
|
|
30675
30892
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
30676
30893
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
30677
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
30894
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join23(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
30678
30895
|
return { rows, stopped: stop.stopped };
|
|
30679
30896
|
}
|
|
30680
30897
|
|
|
30681
30898
|
// src/core/ops/v1-remove.ts
|
|
30682
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30899
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync17, rmSync as rmSync7 } from "node:fs";
|
|
30683
30900
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30684
30901
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30685
30902
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
30686
30903
|
function moveAside(target, undo) {
|
|
30687
30904
|
const trash = target + UPGRADE_TRASH_SUFFIX;
|
|
30688
|
-
|
|
30905
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30689
30906
|
renameWithRetry(target, trash);
|
|
30690
30907
|
undo.push({ trash, target });
|
|
30691
30908
|
}
|
|
30909
|
+
function keepAside(target, undo) {
|
|
30910
|
+
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
30911
|
+
for (let n = 2; existsSync20(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
30912
|
+
renameWithRetry(target, aside);
|
|
30913
|
+
undo.push({ trash: aside, target, keep: true });
|
|
30914
|
+
return aside;
|
|
30915
|
+
}
|
|
30692
30916
|
function keepOriginal(file2, kept, undo) {
|
|
30693
30917
|
if (kept.has(file2)) return;
|
|
30694
30918
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30695
|
-
|
|
30919
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30696
30920
|
copyFileSync2(file2, trash);
|
|
30697
30921
|
kept.add(file2);
|
|
30698
30922
|
undo.push({ trash, target: file2 });
|
|
@@ -30752,7 +30976,7 @@ function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
|
30752
30976
|
writeHostConfigEdit(file2, { agent, text, format: "jsonc", path: file2, layout }, patch);
|
|
30753
30977
|
return hit;
|
|
30754
30978
|
}
|
|
30755
|
-
function removeV1(agent, findings) {
|
|
30979
|
+
function removeV1(agent, findings, project) {
|
|
30756
30980
|
const undo = [];
|
|
30757
30981
|
const kept = /* @__PURE__ */ new Set();
|
|
30758
30982
|
const done = /* @__PURE__ */ new Map();
|
|
@@ -30760,14 +30984,16 @@ function removeV1(agent, findings) {
|
|
|
30760
30984
|
for (const f of findings) {
|
|
30761
30985
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30762
30986
|
else if (f.path === "") {
|
|
30763
|
-
if (
|
|
30987
|
+
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30988
|
+
else if (existsSync20(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
30989
|
+
else if (existsSync20(f.file)) {
|
|
30764
30990
|
moveAside(f.file, undo);
|
|
30765
30991
|
done.set(f, UPGRADE_REMOVED);
|
|
30766
30992
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30767
30993
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30768
30994
|
}
|
|
30769
30995
|
for (const [file2, list4] of entries) {
|
|
30770
|
-
if (!
|
|
30996
|
+
if (!existsSync20(file2)) {
|
|
30771
30997
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30772
30998
|
continue;
|
|
30773
30999
|
}
|
|
@@ -30796,64 +31022,18 @@ function removeV1(agent, findings) {
|
|
|
30796
31022
|
return {
|
|
30797
31023
|
rows: findings.map((f) => row3(f, done.get(f) ?? UPGRADE_NOT_FOUND)),
|
|
30798
31024
|
commit() {
|
|
30799
|
-
for (const u of undo.splice(0))
|
|
31025
|
+
for (const u of undo.splice(0)) if (u.keep !== true) rmSync7(u.trash, { recursive: true, force: true });
|
|
30800
31026
|
},
|
|
30801
31027
|
rollback() {
|
|
30802
31028
|
for (const u of undo.splice(0).reverse()) {
|
|
30803
|
-
if (!
|
|
30804
|
-
|
|
31029
|
+
if (!existsSync20(u.trash)) continue;
|
|
31030
|
+
rmSync7(u.target, { recursive: true, force: true });
|
|
30805
31031
|
renameWithRetry(u.trash, u.target);
|
|
30806
31032
|
}
|
|
30807
31033
|
}
|
|
30808
31034
|
};
|
|
30809
31035
|
}
|
|
30810
31036
|
|
|
30811
|
-
// src/core/ops/verify-sums.ts
|
|
30812
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
30813
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
|
|
30814
|
-
import { join as join25 } from "node:path";
|
|
30815
|
-
function mismatch() {
|
|
30816
|
-
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
30817
|
-
}
|
|
30818
|
-
function parseSums(text) {
|
|
30819
|
-
const lines = text.split(SUMS_LINE_END);
|
|
30820
|
-
if (lines[lines.length - 1] === "") lines.pop();
|
|
30821
|
-
const sums = /* @__PURE__ */ new Map();
|
|
30822
|
-
for (const line of lines) {
|
|
30823
|
-
const at2 = line.indexOf(SUMS_LINE_SEP);
|
|
30824
|
-
if (at2 < 0) throw mismatch();
|
|
30825
|
-
const rel = line.slice(at2 + SUMS_LINE_SEP.length);
|
|
30826
|
-
if (rel === "" || sums.has(rel)) throw mismatch();
|
|
30827
|
-
sums.set(rel, line.slice(0, at2));
|
|
30828
|
-
}
|
|
30829
|
-
return sums;
|
|
30830
|
-
}
|
|
30831
|
-
function walk3(dir, prefix, out) {
|
|
30832
|
-
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
30833
|
-
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
30834
|
-
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
30835
|
-
const abs = join25(dir, entry.name);
|
|
30836
|
-
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
30837
|
-
else if (entry.isFile()) out.set(rel, abs);
|
|
30838
|
-
else throw mismatch();
|
|
30839
|
-
}
|
|
30840
|
-
}
|
|
30841
|
-
function verifySums(dir) {
|
|
30842
|
-
const sumsPath = join25(dir, RELEASE_SUMS_FILE);
|
|
30843
|
-
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30844
|
-
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30845
|
-
const sums = parseSums(readFileSync18(sumsPath, "utf8"));
|
|
30846
|
-
const files = /* @__PURE__ */ new Map();
|
|
30847
|
-
walk3(dir, "", files);
|
|
30848
|
-
if (files.size !== sums.size) throw mismatch();
|
|
30849
|
-
for (const [rel, abs] of files) {
|
|
30850
|
-
const want = sums.get(rel);
|
|
30851
|
-
if (want === void 0) throw mismatch();
|
|
30852
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
|
|
30853
|
-
if (got !== want) throw mismatch();
|
|
30854
|
-
}
|
|
30855
|
-
}
|
|
30856
|
-
|
|
30857
31037
|
// src/core/tools/upgrade.ts
|
|
30858
31038
|
var ctxUpgradeSchema = external_exports.object({
|
|
30859
31039
|
mode: external_exports.enum(UPGRADE_MODES).optional(),
|
|
@@ -30876,41 +31056,20 @@ function pluginRootRow(adapter, env) {
|
|
|
30876
31056
|
}
|
|
30877
31057
|
return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
|
|
30878
31058
|
}
|
|
30879
|
-
function isCurrent(agentDir, dir) {
|
|
30880
|
-
const link = join26(agentDir, PLUGIN_CURRENT_LINK);
|
|
30881
|
-
return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
30882
|
-
}
|
|
30883
|
-
async function checkout(adapter, deps) {
|
|
30884
|
-
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
30885
|
-
const agentDir = dirname13(fetched.dir);
|
|
30886
|
-
try {
|
|
30887
|
-
verifySums(fetched.dir);
|
|
30888
|
-
} catch (err) {
|
|
30889
|
-
if (!isCurrent(agentDir, fetched.dir)) rmSync10(fetched.dir, { recursive: true, force: true });
|
|
30890
|
-
throw err;
|
|
30891
|
-
}
|
|
30892
|
-
const swap = swapPluginCurrent(agentDir, fetched.sha);
|
|
30893
|
-
const rows = [row4(UPGRADE_CHECKOUT_AREA, swap.previous ?? "", swap.current)];
|
|
30894
|
-
for (const dir of swap.removed) rows.push(row4(UPGRADE_CACHE_AREA, dir, UPGRADE_REMOVED));
|
|
30895
|
-
return { rows, agentDir, swap };
|
|
30896
|
-
}
|
|
30897
31059
|
function hostRow(adapter) {
|
|
30898
|
-
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]
|
|
31060
|
+
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]);
|
|
30899
31061
|
}
|
|
30900
|
-
|
|
30901
|
-
let done = null;
|
|
31062
|
+
function upgrade(adapter, deps, home) {
|
|
30902
31063
|
let removal = null;
|
|
30903
31064
|
try {
|
|
30904
|
-
const step4 = UPGRADE_GIT_CHECKOUT_AGENTS.includes(adapter.id) ? (done = await checkout(adapter, deps)).rows : [hostRow(adapter)];
|
|
30905
31065
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
30906
|
-
const findings = detectV1(adapter.id, home, { project: deps.project.worktree, piAgentDir: piAgentDirOf(deps.env, home), claudeDir: claudeDirOf(deps.env, home), copilotDir: copilotDirOf(deps.env, home), kiroDir: kiroDirOf(deps.env, home), opencodeDir: opencodeDirOf(deps.env, home) });
|
|
30907
|
-
removal = removeV1(adapter.id, findings);
|
|
30908
|
-
const rows = [
|
|
31066
|
+
const findings = detectV1(adapter.id, home, { project: deps.project.worktree, piAgentDir: piAgentDirOf(deps.env, home), claudeDir: claudeDirOf(deps.env, home), geminiDir: geminiDirOf(deps.env, home), copilotDir: copilotDirOf(deps.env, home), kiroDir: kiroDirOf(deps.env, home), opencodeDir: opencodeDirOf(deps.env, home) });
|
|
31067
|
+
removal = removeV1(adapter.id, findings, deps.project.worktree);
|
|
31068
|
+
const rows = [hostRow(adapter), ...step5, ...removal.rows];
|
|
30909
31069
|
removal.commit();
|
|
30910
31070
|
return rows;
|
|
30911
31071
|
} catch (err) {
|
|
30912
31072
|
removal?.rollback();
|
|
30913
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename7(done.swap.previous));
|
|
30914
31073
|
throw err;
|
|
30915
31074
|
}
|
|
30916
31075
|
}
|
|
@@ -30930,12 +31089,12 @@ async function runUpgrade(input, deps) {
|
|
|
30930
31089
|
const result = runUninstall({ adapter, project: deps.project, env: deps.env, confirmDelete: input.confirmDelete === true });
|
|
30931
31090
|
rows.push(...result.rows);
|
|
30932
31091
|
} else {
|
|
30933
|
-
rows.push(...
|
|
31092
|
+
rows.push(...upgrade(adapter, deps, home));
|
|
30934
31093
|
}
|
|
30935
31094
|
return { text: renderTable(rows) + "\n\n" + UPGRADE_RESTART_LINE, isError: false, sandboxBytes: 0 };
|
|
30936
31095
|
}
|
|
30937
31096
|
async function handler8(input, ctx) {
|
|
30938
|
-
return runUpgrade(input, { project: ctx.project, env: process.env, signal: ctx.signal
|
|
31097
|
+
return runUpgrade(input, { project: ctx.project, env: process.env, signal: ctx.signal });
|
|
30939
31098
|
}
|
|
30940
31099
|
var ctxUpgrade = Object.freeze({
|
|
30941
31100
|
name: "ctx_upgrade",
|
|
@@ -31133,9 +31292,9 @@ async function setup(ctx) {
|
|
|
31133
31292
|
await hooks["tool.execute.before"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id }, { args: i.input });
|
|
31134
31293
|
});
|
|
31135
31294
|
await ctx.tool.hook("execute.after", async (i) => {
|
|
31136
|
-
const
|
|
31137
|
-
const output =
|
|
31138
|
-
await hooks["tool.execute.after"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, args: i.input }, { output, isError:
|
|
31295
|
+
const failed = i.status === "error";
|
|
31296
|
+
const output = failed ? i.error?.message ?? "" : oc2Text(i.result?.content);
|
|
31297
|
+
await hooks["tool.execute.after"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id, args: i.input }, { output, isError: failed });
|
|
31139
31298
|
});
|
|
31140
31299
|
await ctx.session.hook("prompt", async (p) => {
|
|
31141
31300
|
await hooks["chat.message"]({ sessionID: p.sessionID }, { parts: [{ type: "text", text: p.prompt?.text ?? "" }] });
|