context-mode 2.1.3 → 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 +310 -142
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +99 -97
- package/opencode/plugin.js +637 -509
- package/package.json +2 -1
- package/pi/index.js +726 -577
- package/qwen-extension.json +1 -1
- package/run.mjs +240 -93
- package/search.mjs +240 -93
- package/server.mjs +497 -435
package/opencode/plugin.js
CHANGED
|
@@ -206,6 +206,7 @@ var GIT_COMMONDIR_FILE = "commondir";
|
|
|
206
206
|
var GIT_HEAD_FILE = "HEAD";
|
|
207
207
|
var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
|
|
208
208
|
var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
|
|
209
|
+
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
209
210
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
210
211
|
var FETCH_MAX_HOPS = 5;
|
|
211
212
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
@@ -216,6 +217,7 @@ var RUN_LABEL_PREFIX = "run.mjs:";
|
|
|
216
217
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
217
218
|
var NODE_MIN = "24.15.0";
|
|
218
219
|
var DATA_ROOT = "~/.context-mode";
|
|
220
|
+
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
219
221
|
var INTERNAL_ERROR_LINE = "Internal error. Fix: run ctx_doctor.";
|
|
220
222
|
var REQUIRE_SECURITY_ENV = "CONTEXT_MODE_REQUIRE_SECURITY";
|
|
221
223
|
var HOST_CONFIG_DIR_NAME = ".claude";
|
|
@@ -318,7 +320,8 @@ var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
|
318
320
|
var SED_COMMAND = "sed";
|
|
319
321
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
320
322
|
var JQ_COMMAND = "jq";
|
|
321
|
-
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";
|
|
322
325
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
323
326
|
var SHELL_TOOL = "Bash";
|
|
324
327
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
@@ -334,6 +337,7 @@ var RECALL_MIN_SCORE = 5;
|
|
|
334
337
|
var RECALL_MAX_ROWS = 340;
|
|
335
338
|
var COMPACTED_META_PREFIX = "compacted:";
|
|
336
339
|
var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
|
|
340
|
+
var UNITS_ANCESTOR_FACTOR = 8;
|
|
337
341
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
338
342
|
var RECALL_SEEN_META_PREFIX = "recall_seen:";
|
|
339
343
|
var RECALL_OPEN_TAG = "<context_mode_recall>";
|
|
@@ -427,8 +431,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
427
431
|
var DECISION_OPTION_KEY = "option";
|
|
428
432
|
var DECISION_LABEL_JOIN = " | ";
|
|
429
433
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
430
|
-
var
|
|
431
|
-
var BUNDLE_SHA = true ? "83f2da691359eaaf61f7baba841dea1942d3ccc1" : void 0;
|
|
434
|
+
var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
|
|
432
435
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
433
436
|
var DOCTOR_LABEL = Object.freeze({
|
|
434
437
|
D1: "version",
|
|
@@ -568,7 +571,6 @@ function D9_INDEX_DETAIL(sources, chunks) {
|
|
|
568
571
|
var PLUGIN_CACHE_DIR_NAME = "cache";
|
|
569
572
|
var DATA_PLUGINS_DIR_NAME = "plugins";
|
|
570
573
|
var PLUGIN_CURRENT_LINK = "current";
|
|
571
|
-
var RELEASE_SUMS_FILE = "SHA256SUMS";
|
|
572
574
|
var EXTENSIONS_DIR_NAME = "extensions";
|
|
573
575
|
var AGENT_HOME_DIR = Object.freeze({
|
|
574
576
|
"claude-code": [".claude"],
|
|
@@ -591,7 +593,6 @@ var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
|
591
593
|
var UPGRADE_TABLE_HEADER = "| Area | Before | After |";
|
|
592
594
|
var UPGRADE_TABLE_RULE = "|---|---|---|";
|
|
593
595
|
var UPGRADE_PLUGIN_ROOT_AREA = "plugin root";
|
|
594
|
-
var UPGRADE_CHECKOUT_AREA = "plugin checkout";
|
|
595
596
|
var UPGRADE_SERVER_AREA = "server";
|
|
596
597
|
var UPGRADE_SERVER_RUNNING = "running";
|
|
597
598
|
var UPGRADE_SERVER_STOPPED = "stopped after this reply";
|
|
@@ -601,25 +602,21 @@ var UPGRADE_DATA_AREA = "user data";
|
|
|
601
602
|
var UPGRADE_REPORT_ONLY = "report only: remove it by hand if you no longer use it";
|
|
602
603
|
var UPGRADE_AREA_KEY_SEP = ": ";
|
|
603
604
|
var V1_KEY_PATH_SEP = ".";
|
|
604
|
-
var UPGRADE_GIT_TIMEOUT_MS = 12e4;
|
|
605
605
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
606
606
|
var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
|
|
607
|
-
var UPGRADE_FETCH_DIR_PREFIX = ".fetch-";
|
|
608
|
-
var SUMS_LINE_SEP = " ";
|
|
609
|
-
var SUMS_HASH_ALGORITHM = "sha256";
|
|
610
|
-
var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
|
|
611
|
-
var UPGRADE_HOST_MANUAL = "update with the host's own install command, then restart";
|
|
612
607
|
var UPGRADE_CONFIG_AREA = "host config";
|
|
613
608
|
var UPGRADE_OWN_ENTRY = "context-mode entry";
|
|
614
609
|
var UPGRADE_CACHE_BY_HAND = "remove the release dir by hand: its place is your choice";
|
|
615
610
|
var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
|
|
616
611
|
var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
|
|
617
|
-
var GIT_NOT_STARTED = "git did not start";
|
|
618
612
|
var GIT_BIN = "git";
|
|
619
613
|
var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
|
|
620
614
|
var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
|
|
621
|
-
var GIT_EXIT_LABEL = "git exit ";
|
|
622
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;
|
|
623
620
|
var TABLE_ROW_START = "| ";
|
|
624
621
|
var TABLE_CELL_SEP = " | ";
|
|
625
622
|
var TABLE_ROW_END = " |";
|
|
@@ -631,7 +628,6 @@ var OPS_SPLIT_FILES = Object.freeze([
|
|
|
631
628
|
"doctor-hook.ts",
|
|
632
629
|
"doctor-db.ts",
|
|
633
630
|
"doctor-heal.ts",
|
|
634
|
-
"release-fetch.ts",
|
|
635
631
|
"verify-sums.ts",
|
|
636
632
|
"plugin-swap.ts",
|
|
637
633
|
"host-write.ts",
|
|
@@ -707,19 +703,19 @@ function D11_PASS_DETAIL(shell, win) {
|
|
|
707
703
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
708
704
|
var HEAL_TMP_SUFFIX = ".heal";
|
|
709
705
|
var HEAL_TS_SEP = ".";
|
|
710
|
-
var SUMS_LINE_END = "\n";
|
|
711
|
-
var HASH_ENCODING = "hex";
|
|
712
|
-
var PLUGIN_LINK_TMP_SUFFIX = ".swap";
|
|
713
|
-
var PLUGIN_LINK_OLD_SUFFIX = ".old";
|
|
714
|
-
var PLUGIN_LINK_TYPE = "dir";
|
|
715
|
-
var PLUGIN_LINK_TYPE_WIN32 = "junction";
|
|
716
706
|
var OWNER_STOP_EXT = ".stop";
|
|
717
707
|
var UPGRADE_DATA_DELETED = "user data deleted";
|
|
718
708
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
719
709
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
720
|
-
codex: "
|
|
721
|
-
gemini: "gemini extensions
|
|
722
|
-
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"
|
|
723
719
|
});
|
|
724
720
|
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
725
721
|
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
@@ -761,6 +757,7 @@ var HOOKS_JSON_FILE = "hooks.json";
|
|
|
761
757
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
762
758
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
763
759
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
760
|
+
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
764
761
|
var KIRO_HOME_ENV = "KIRO_HOME";
|
|
765
762
|
var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
|
|
766
763
|
var APPDATA_ENV = "APPDATA";
|
|
@@ -789,8 +786,12 @@ var STATUS_LINE_KEY = "statusLine";
|
|
|
789
786
|
var PI_PACKAGES_KEY = "packages";
|
|
790
787
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
791
788
|
var OPENCODE_PLUGINS_KEY = "plugins";
|
|
789
|
+
var OPENCODE_MCP_COMMAND_FIELD = "command";
|
|
792
790
|
var OPENCODE_PACKAGE_FIELD = "package";
|
|
793
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`;
|
|
794
795
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
795
796
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
796
797
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -819,18 +820,21 @@ var V1_REASON = Object.freeze({
|
|
|
819
820
|
kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
|
|
820
821
|
piNpm: "old context-mode Pi package npm:context-mode",
|
|
821
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",
|
|
822
825
|
zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
|
|
823
826
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
824
827
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
825
828
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
826
|
-
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"
|
|
827
831
|
});
|
|
828
|
-
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]);
|
|
829
834
|
var PLUGIN_ID = SERVER_KEY;
|
|
830
835
|
var PLUGIN_NAME = SERVER_KEY;
|
|
831
836
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
832
837
|
var SERVER_ENTRY_FILE = "server.mjs";
|
|
833
|
-
var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
|
|
834
838
|
var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
|
|
835
839
|
var HOST_NODE_COMMAND = "node";
|
|
836
840
|
var EXE_SUFFIX = ".exe";
|
|
@@ -953,7 +957,7 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
953
957
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
954
958
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
955
959
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
956
|
-
zcode: ["
|
|
960
|
+
zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
|
|
957
961
|
});
|
|
958
962
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
959
963
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
@@ -1031,7 +1035,7 @@ var CtxError = class extends Error {
|
|
|
1031
1035
|
};
|
|
1032
1036
|
|
|
1033
1037
|
// src/core/hooks/dispatch.ts
|
|
1034
|
-
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";
|
|
1035
1039
|
|
|
1036
1040
|
// src/core/contracts/agents.ts
|
|
1037
1041
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -1049,9 +1053,9 @@ function canonicalName(name, ownPrefix) {
|
|
|
1049
1053
|
if (name.startsWith(ownPrefix)) return name.slice(ownPrefix.length);
|
|
1050
1054
|
if (!name.startsWith(MCP_PREFIX)) return name;
|
|
1051
1055
|
const rest = name.slice(MCP_PREFIX.length);
|
|
1052
|
-
const
|
|
1053
|
-
if (
|
|
1054
|
-
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);
|
|
1055
1059
|
}
|
|
1056
1060
|
function outputOf(resp) {
|
|
1057
1061
|
if (resp === void 0) return "";
|
|
@@ -1251,6 +1255,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
|
1251
1255
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
1252
1256
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
1253
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";
|
|
1254
1259
|
function own(p, key) {
|
|
1255
1260
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
1256
1261
|
}
|
|
@@ -1270,13 +1275,67 @@ function canonicalName2(name, mcp) {
|
|
|
1270
1275
|
if (typeof server2 !== "string" || typeof tool !== "string") return name;
|
|
1271
1276
|
return "mcp:" + server2 + ":" + tool;
|
|
1272
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
|
+
}
|
|
1273
1293
|
function readResult2(resp) {
|
|
1274
1294
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
1275
1295
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
1276
|
-
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);
|
|
1277
1297
|
const err = obj === void 0 ? void 0 : own(obj, "error");
|
|
1278
1298
|
return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
|
|
1279
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
|
+
}
|
|
1280
1339
|
function decode3(raw) {
|
|
1281
1340
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
1282
1341
|
const p = raw;
|
|
@@ -1294,7 +1353,7 @@ function decode3(raw) {
|
|
|
1294
1353
|
ev.tool = {
|
|
1295
1354
|
name,
|
|
1296
1355
|
canonicalName: canonicalName2(name, own(p, "mcp_context")),
|
|
1297
|
-
input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
1356
|
+
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
1298
1357
|
};
|
|
1299
1358
|
}
|
|
1300
1359
|
if (event === "PostToolUse") ev.result = readResult2(own(p, "tool_response"));
|
|
@@ -1312,7 +1371,7 @@ function encode3(ev, d, _extra) {
|
|
|
1312
1371
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
1313
1372
|
case "replace":
|
|
1314
1373
|
if (ev.event !== "PostToolUse") return EMPTY;
|
|
1315
|
-
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 };
|
|
1316
1375
|
}
|
|
1317
1376
|
}
|
|
1318
1377
|
|
|
@@ -1469,9 +1528,9 @@ function canonicalName4(name) {
|
|
|
1469
1528
|
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
1470
1529
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
1471
1530
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
1472
|
-
const
|
|
1473
|
-
if (
|
|
1474
|
-
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);
|
|
1475
1534
|
}
|
|
1476
1535
|
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1477
1536
|
function policyInput(name, canonical, input) {
|
|
@@ -1600,9 +1659,9 @@ function canonicalName5(name) {
|
|
|
1600
1659
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1601
1660
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1602
1661
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
1603
|
-
const
|
|
1604
|
-
if (
|
|
1605
|
-
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);
|
|
1606
1665
|
}
|
|
1607
1666
|
function readResult5(resp) {
|
|
1608
1667
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
@@ -1645,6 +1704,7 @@ function encode7(ev, d, _extra) {
|
|
|
1645
1704
|
|
|
1646
1705
|
// src/adapters/zcode.ts
|
|
1647
1706
|
var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
|
|
1707
|
+
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1648
1708
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1649
1709
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1650
1710
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
@@ -1654,7 +1714,9 @@ function decode8(raw) {
|
|
|
1654
1714
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
1655
1715
|
const failure = p.hook_event_name === FAILURE_EVENT2;
|
|
1656
1716
|
if (failure) p.hook_event_name = "PostToolUse";
|
|
1657
|
-
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);
|
|
1658
1720
|
if (failure) {
|
|
1659
1721
|
const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
|
|
1660
1722
|
ev.result = { isError: true, bytes: Buffer.byteLength(text), text };
|
|
@@ -1735,8 +1797,9 @@ var OPENCODE_EVENTS = {
|
|
|
1735
1797
|
"step-finish": "Usage"
|
|
1736
1798
|
};
|
|
1737
1799
|
var SHELL_TOOL_NAME = "bash";
|
|
1800
|
+
var READ_TOOL_NAME = "read";
|
|
1738
1801
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1739
|
-
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"])) };
|
|
1740
1803
|
function toCanonicalTool(name) {
|
|
1741
1804
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1742
1805
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -1964,9 +2027,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1964
2027
|
installMode: "in-process",
|
|
1965
2028
|
projectSource: "spawn-cwd",
|
|
1966
2029
|
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
1967
|
-
nativeTools: { shell: [SHELL_TOOL_NAME] },
|
|
2030
|
+
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
1968
2031
|
execReadOnlyHint: false,
|
|
1969
|
-
// D-HF-OPENCODE-SHELL-1
|
|
2032
|
+
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
1970
2033
|
// Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
|
|
1971
2034
|
eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
|
|
1972
2035
|
compactDelivery: "opencode-cache",
|
|
@@ -2530,6 +2593,9 @@ var SUBSHELL_CLOSE = ")";
|
|
|
2530
2593
|
var CASE_BREAK = ";;";
|
|
2531
2594
|
var FUNC_PARENS = ["(", ")"];
|
|
2532
2595
|
var NOT = "!";
|
|
2596
|
+
function append(out, items) {
|
|
2597
|
+
for (const x of items) out.push(x);
|
|
2598
|
+
}
|
|
2533
2599
|
var KW = Object.freeze({
|
|
2534
2600
|
group: "{",
|
|
2535
2601
|
groupEnd: "}",
|
|
@@ -2709,12 +2775,12 @@ function ifBody(p) {
|
|
|
2709
2775
|
const t = at(p);
|
|
2710
2776
|
if (isWord(t, KW.then) || isWord(t, KW.else)) {
|
|
2711
2777
|
p.i++;
|
|
2712
|
-
out
|
|
2778
|
+
append(out, list(p, [KW.elif, KW.else, KW.fi]));
|
|
2713
2779
|
continue;
|
|
2714
2780
|
}
|
|
2715
2781
|
if (isWord(t, KW.elif)) {
|
|
2716
2782
|
p.i++;
|
|
2717
|
-
out
|
|
2783
|
+
append(out, list(p, [KW.then]));
|
|
2718
2784
|
continue;
|
|
2719
2785
|
}
|
|
2720
2786
|
if (isWord(t, KW.fi)) p.i++;
|
|
@@ -2725,7 +2791,7 @@ function ifBody(p) {
|
|
|
2725
2791
|
function loopBody(p) {
|
|
2726
2792
|
p.i++;
|
|
2727
2793
|
const out = list(p, [KW.do]);
|
|
2728
|
-
out
|
|
2794
|
+
append(out, doBlock(p));
|
|
2729
2795
|
return out;
|
|
2730
2796
|
}
|
|
2731
2797
|
function forBody(p) {
|
|
@@ -2739,10 +2805,10 @@ function forBody(p) {
|
|
|
2739
2805
|
p.i++;
|
|
2740
2806
|
const from = p.i;
|
|
2741
2807
|
while ((at(p)?.kind === "word" || at(p)?.kind === "unhandled") && !isWord(at(p), KW.do)) p.i++;
|
|
2742
|
-
out
|
|
2808
|
+
append(out, carrierOf(p, from, p.i));
|
|
2743
2809
|
}
|
|
2744
2810
|
}
|
|
2745
|
-
out
|
|
2811
|
+
append(out, doBlock(p));
|
|
2746
2812
|
return out;
|
|
2747
2813
|
}
|
|
2748
2814
|
function caseBody(p) {
|
|
@@ -2751,7 +2817,7 @@ function caseBody(p) {
|
|
|
2751
2817
|
const subject = at(p);
|
|
2752
2818
|
if (subject !== void 0 && subject.kind !== "op" && subject.kind !== "io") {
|
|
2753
2819
|
p.i++;
|
|
2754
|
-
out
|
|
2820
|
+
append(out, carrierOf(p, p.i - 1, p.i));
|
|
2755
2821
|
}
|
|
2756
2822
|
if (isWord(at(p), KW.in)) p.i++;
|
|
2757
2823
|
while (p.i < p.toks.length && p.err === null) {
|
|
@@ -2774,7 +2840,7 @@ function caseBody(p) {
|
|
|
2774
2840
|
p.i++;
|
|
2775
2841
|
const body = list(p, [KW.esac]);
|
|
2776
2842
|
tag(body, KW.case);
|
|
2777
|
-
out
|
|
2843
|
+
append(out, body);
|
|
2778
2844
|
}
|
|
2779
2845
|
return out;
|
|
2780
2846
|
}
|
|
@@ -2789,7 +2855,7 @@ function hasFuncParens(p, from) {
|
|
|
2789
2855
|
}
|
|
2790
2856
|
function simple(p) {
|
|
2791
2857
|
const first = p.i;
|
|
2792
|
-
const
|
|
2858
|
+
const words2 = [];
|
|
2793
2859
|
let toFile = false;
|
|
2794
2860
|
while (p.i < p.toks.length) {
|
|
2795
2861
|
const t = p.toks[p.i];
|
|
@@ -2798,7 +2864,7 @@ function simple(p) {
|
|
|
2798
2864
|
toFile = ioRedirect(p) || toFile;
|
|
2799
2865
|
continue;
|
|
2800
2866
|
}
|
|
2801
|
-
if (
|
|
2867
|
+
if (words2.length === 0 && t.kind === "word" && isAssignment(t.text)) {
|
|
2802
2868
|
p.i++;
|
|
2803
2869
|
const open = at(p);
|
|
2804
2870
|
if (t.text.endsWith(OPT_VALUE) && open !== void 0 && isOp(open, SUBSHELL_OPEN) && open.start === t.end) {
|
|
@@ -2812,15 +2878,15 @@ function simple(p) {
|
|
|
2812
2878
|
}
|
|
2813
2879
|
continue;
|
|
2814
2880
|
}
|
|
2815
|
-
|
|
2881
|
+
words2.push(t);
|
|
2816
2882
|
p.i++;
|
|
2817
2883
|
}
|
|
2818
2884
|
if (p.i === first) return EMPTY3();
|
|
2819
2885
|
const raw = p.src.slice(p.toks[first].start, p.toks[p.i - 1].end);
|
|
2820
|
-
if (
|
|
2886
|
+
if (words2.length === 0) return { cmds: carrier(raw), simple: null };
|
|
2821
2887
|
const text = (t) => t.kind === "word" ? dequote(t.text) : t.text;
|
|
2822
|
-
const argv0 = baseName(text(
|
|
2823
|
-
const args =
|
|
2888
|
+
const argv0 = baseName(text(words2[0]));
|
|
2889
|
+
const args = words2.slice(1).map(text);
|
|
2824
2890
|
const cmd = { argv0, args, redirectsToFile: toFile || writesFile(argv0, args), endsInBoundedSink: false, raw };
|
|
2825
2891
|
return { cmds: [cmd], simple: cmd };
|
|
2826
2892
|
}
|
|
@@ -2891,7 +2957,7 @@ function pipeline(p) {
|
|
|
2891
2957
|
let last2 = EMPTY3();
|
|
2892
2958
|
while (p.err === null) {
|
|
2893
2959
|
last2 = element(p);
|
|
2894
|
-
all
|
|
2960
|
+
append(all, last2.cmds);
|
|
2895
2961
|
const t = at(p);
|
|
2896
2962
|
if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
|
|
2897
2963
|
for (const c of last2.cmds) c.pipesOut = true;
|
|
@@ -2920,7 +2986,7 @@ function list(p, stop) {
|
|
|
2920
2986
|
}
|
|
2921
2987
|
if (t.kind === "word" && stop.includes(t.text)) return out;
|
|
2922
2988
|
const before = p.i;
|
|
2923
|
-
out
|
|
2989
|
+
append(out, pipeline(p));
|
|
2924
2990
|
if (p.i === before && p.err === null) p.i++;
|
|
2925
2991
|
}
|
|
2926
2992
|
return out;
|
|
@@ -2933,7 +2999,7 @@ function parseShell(cmd) {
|
|
|
2933
2999
|
const p = { toks: s.tokens, src: cmd, bodies: new Set(s.heredocBodies), i: 0, depth: 0, err: null };
|
|
2934
3000
|
const commands = [];
|
|
2935
3001
|
while (p.i < p.toks.length && p.err === null) {
|
|
2936
|
-
commands
|
|
3002
|
+
append(commands, list(p, NO_STOP));
|
|
2937
3003
|
if (p.i < p.toks.length) p.i++;
|
|
2938
3004
|
}
|
|
2939
3005
|
if (p.err !== null) return { ok: false, construct: p.err };
|
|
@@ -3188,57 +3254,57 @@ function param(word, names) {
|
|
|
3188
3254
|
const hits = names.filter((p) => p.startsWith(name));
|
|
3189
3255
|
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
3190
3256
|
}
|
|
3191
|
-
function psDump(
|
|
3192
|
-
if (
|
|
3193
|
-
const name = cmdName(
|
|
3257
|
+
function psDump(words2) {
|
|
3258
|
+
if (words2.length === 0) return null;
|
|
3259
|
+
const name = cmdName(words2[0]);
|
|
3194
3260
|
if (!READ_COMMANDS.includes(name)) {
|
|
3195
|
-
const lower =
|
|
3261
|
+
const lower = words2[0].toLowerCase();
|
|
3196
3262
|
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
3197
|
-
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) ||
|
|
3198
|
-
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 };
|
|
3199
3265
|
}
|
|
3200
3266
|
const files = [];
|
|
3201
3267
|
let bounded = false;
|
|
3202
|
-
for (let k = 1; k <
|
|
3203
|
-
const a =
|
|
3268
|
+
for (let k = 1; k < words2.length; k++) {
|
|
3269
|
+
const a = words2[k];
|
|
3204
3270
|
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
3205
3271
|
files.push(a);
|
|
3206
3272
|
continue;
|
|
3207
3273
|
}
|
|
3208
3274
|
const p = param(a, ALL_PARAMS);
|
|
3209
3275
|
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
3210
|
-
const value = p.inline ??
|
|
3276
|
+
const value = p.inline ?? words2[++k];
|
|
3211
3277
|
if (value === void 0) return null;
|
|
3212
3278
|
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
3213
3279
|
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
3214
3280
|
}
|
|
3215
3281
|
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
3216
3282
|
}
|
|
3217
|
-
function nestedScript(name,
|
|
3283
|
+
function nestedScript(name, words2) {
|
|
3218
3284
|
if (POWERSHELLS.includes(name)) {
|
|
3219
|
-
for (let k = 1; k <
|
|
3220
|
-
const w =
|
|
3285
|
+
for (let k = 1; k < words2.length; k++) {
|
|
3286
|
+
const w = words2[k];
|
|
3221
3287
|
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
3222
3288
|
const p = param(w, [COMMAND_PARAM]);
|
|
3223
3289
|
if (p.full === void 0) continue;
|
|
3224
|
-
return [...p.inline === void 0 ? [] : [p.inline], ...
|
|
3290
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words2.slice(k + 1)].join(" ");
|
|
3225
3291
|
}
|
|
3226
3292
|
return null;
|
|
3227
3293
|
}
|
|
3228
3294
|
if (CMDS.includes(name)) {
|
|
3229
|
-
for (let k = 1; k <
|
|
3230
|
-
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(" ");
|
|
3231
3297
|
}
|
|
3232
3298
|
}
|
|
3233
3299
|
return null;
|
|
3234
3300
|
}
|
|
3235
|
-
function cdTarget(
|
|
3236
|
-
for (let k = 1; k <
|
|
3237
|
-
const w =
|
|
3301
|
+
function cdTarget(words2) {
|
|
3302
|
+
for (let k = 1; k < words2.length; k++) {
|
|
3303
|
+
const w = words2[k];
|
|
3238
3304
|
if (w.toLowerCase() === "/d") continue;
|
|
3239
3305
|
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
3240
3306
|
const p = param(w, PATH_PARAMS);
|
|
3241
|
-
if (p.full !== void 0) return p.inline ??
|
|
3307
|
+
if (p.full !== void 0) return p.inline ?? words2[k + 1] ?? null;
|
|
3242
3308
|
}
|
|
3243
3309
|
return null;
|
|
3244
3310
|
}
|
|
@@ -3338,6 +3404,10 @@ function copilotDirOf(env, home) {
|
|
|
3338
3404
|
const dir = env[COPILOT_HOME_ENV];
|
|
3339
3405
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
3340
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
|
+
}
|
|
3341
3411
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
3342
3412
|
const p = platform === "win32" ? win32 : posix;
|
|
3343
3413
|
const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
|
|
@@ -3396,8 +3466,13 @@ function requireHomeDir(env, platform = process.platform) {
|
|
|
3396
3466
|
if (home !== null) return home;
|
|
3397
3467
|
throw new CtxError("NO_HOME", { name: platform === "win32" ? "USERPROFILE" : "HOME" });
|
|
3398
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
|
+
}
|
|
3399
3473
|
function resolveConfigDir(env) {
|
|
3400
|
-
const
|
|
3474
|
+
const set3 = env[DATA_DIR_ENV];
|
|
3475
|
+
const dir = dataRootOf(env, set3 !== void 0 && set3 !== "" ? "" : requireHomeDir(env));
|
|
3401
3476
|
mkdirSync(dir, { recursive: true });
|
|
3402
3477
|
return realpathSync.native(dir);
|
|
3403
3478
|
}
|
|
@@ -3769,14 +3844,13 @@ function tokenize(glob, path8) {
|
|
|
3769
3844
|
}
|
|
3770
3845
|
return toks;
|
|
3771
3846
|
}
|
|
3772
|
-
function
|
|
3773
|
-
const toks = tokenize(glob, path8);
|
|
3847
|
+
function matchStarts(toks, text, path8, ends) {
|
|
3774
3848
|
const n = text.length;
|
|
3775
|
-
let next =
|
|
3776
|
-
|
|
3849
|
+
let next = ends;
|
|
3850
|
+
let cur = new Uint8Array(n + 1);
|
|
3777
3851
|
for (let i = toks.length - 1; i >= 0; i--) {
|
|
3778
3852
|
const tok = toks[i];
|
|
3779
|
-
|
|
3853
|
+
if (next === ends) next = Uint8Array.from(ends);
|
|
3780
3854
|
let acc = 0;
|
|
3781
3855
|
for (let j = n; j >= 0; j--) {
|
|
3782
3856
|
const has3 = j < n;
|
|
@@ -3800,9 +3874,19 @@ function globMatch(glob, text, path8) {
|
|
|
3800
3874
|
break;
|
|
3801
3875
|
}
|
|
3802
3876
|
}
|
|
3803
|
-
|
|
3877
|
+
const done = cur;
|
|
3878
|
+
cur = next;
|
|
3879
|
+
next = done;
|
|
3804
3880
|
}
|
|
3805
|
-
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;
|
|
3806
3890
|
}
|
|
3807
3891
|
function parsePattern(pattern) {
|
|
3808
3892
|
const open = pattern.indexOf("(");
|
|
@@ -3810,14 +3894,25 @@ function parsePattern(pattern) {
|
|
|
3810
3894
|
const glob = pattern.slice(open + 1, pattern.length - ")".length);
|
|
3811
3895
|
return glob === "" ? null : { tool: pattern.slice(0, open), glob };
|
|
3812
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
|
+
}
|
|
3813
3905
|
function matchCommand(glob, text) {
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
for (
|
|
3818
|
-
|
|
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;
|
|
3819
3914
|
}
|
|
3820
|
-
return
|
|
3915
|
+
return null;
|
|
3821
3916
|
}
|
|
3822
3917
|
var DRIVE_PREFIX = /^[A-Za-z]:(?=\/)/;
|
|
3823
3918
|
function toSlash(p) {
|
|
@@ -3889,6 +3984,7 @@ var HOST_SEP = ".";
|
|
|
3889
3984
|
var SED_RANGE_SEP = ",";
|
|
3890
3985
|
var SED_PRINT = "p";
|
|
3891
3986
|
var SED_SCRIPT_FLAGS = ["-e", "--expression"];
|
|
3987
|
+
var EXE_SUFFIX2 = ".exe";
|
|
3892
3988
|
var COMMAND_STARTS = ";&|(`\n\r";
|
|
3893
3989
|
var ALLOW = Object.freeze({ kind: "allow" });
|
|
3894
3990
|
var deny = (reason) => ({ kind: "deny", reason });
|
|
@@ -3926,6 +4022,11 @@ function readPath(input) {
|
|
|
3926
4022
|
}
|
|
3927
4023
|
return void 0;
|
|
3928
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
|
+
}
|
|
3929
4030
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
3930
4031
|
if (rules.length === 0) return null;
|
|
3931
4032
|
const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
@@ -3934,35 +4035,65 @@ function userDenyHit(canonical, input, cwd, rules) {
|
|
|
3934
4035
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
3935
4036
|
}
|
|
3936
4037
|
if (canonical === READ) {
|
|
3937
|
-
const p
|
|
3938
|
-
|
|
4038
|
+
for (const p of readPaths(input)) {
|
|
4039
|
+
const h = readRule(p);
|
|
4040
|
+
if (h !== null) return h;
|
|
4041
|
+
}
|
|
4042
|
+
return null;
|
|
3939
4043
|
}
|
|
3940
4044
|
if (canonical === CTX_EXECUTE) {
|
|
3941
4045
|
const file2 = str(input.file);
|
|
3942
4046
|
const byFile = file2 === void 0 || file2 === "" ? null : readRule(file2);
|
|
3943
4047
|
if (byFile !== null) return byFile;
|
|
3944
4048
|
const code = str(input.code);
|
|
3945
|
-
return input.language
|
|
4049
|
+
return isShellLanguage(input.language) && code !== void 0 ? shellHit(code, rules) : null;
|
|
3946
4050
|
}
|
|
3947
4051
|
if (canonical === CTX_BATCH && Array.isArray(input.commands)) {
|
|
3948
4052
|
for (const c of input.commands) {
|
|
3949
|
-
const h = typeof c === "string" ?
|
|
4053
|
+
const h = typeof c === "string" ? shellHit(c, rules) : null;
|
|
3950
4054
|
if (h !== null) return h;
|
|
3951
4055
|
}
|
|
3952
4056
|
}
|
|
3953
4057
|
return null;
|
|
3954
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
|
+
}
|
|
3955
4078
|
function segmentHit(c, rules) {
|
|
3956
4079
|
if (rules.length === 0) return null;
|
|
3957
4080
|
return matchesAnyDenyPattern([c.argv0, ...c.args].join(" "), rules) ?? matchesAnyDenyPattern(c.raw, rules);
|
|
3958
4081
|
}
|
|
3959
|
-
function
|
|
3960
|
-
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;
|
|
3961
4086
|
for (let k = 0; k <= text.length; k++) {
|
|
3962
|
-
if (k
|
|
3963
|
-
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
|
+
}
|
|
3964
4092
|
}
|
|
3965
|
-
return
|
|
4093
|
+
return denyPatternFromAny(text, rules, from);
|
|
4094
|
+
}
|
|
4095
|
+
function couldMatch(text, rules) {
|
|
4096
|
+
return couldMatchRule(text, rules) !== null;
|
|
3966
4097
|
}
|
|
3967
4098
|
function neverDenied(url2) {
|
|
3968
4099
|
let host;
|
|
@@ -4037,8 +4168,7 @@ function fileSize(abs) {
|
|
|
4037
4168
|
}
|
|
4038
4169
|
function read(ev, row5, input) {
|
|
4039
4170
|
if (!present(input.offset) && !present(input.limit)) {
|
|
4040
|
-
const p
|
|
4041
|
-
if (p !== void 0) {
|
|
4171
|
+
for (const p of readPaths(input)) {
|
|
4042
4172
|
const abs = resolve3(ev.cwd, p);
|
|
4043
4173
|
const size = fileSize(abs);
|
|
4044
4174
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
@@ -4132,11 +4262,11 @@ function dumpTarget(name, args) {
|
|
|
4132
4262
|
}
|
|
4133
4263
|
|
|
4134
4264
|
// src/core/project/resolve.ts
|
|
4135
|
-
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";
|
|
4136
4266
|
|
|
4137
4267
|
// src/core/project/contain.ts
|
|
4138
|
-
import { dirname as dirname2, sep as sep2 } from "node:path";
|
|
4139
|
-
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");
|
|
4140
4270
|
function real(p) {
|
|
4141
4271
|
try {
|
|
4142
4272
|
return realpathSync2.native(p);
|
|
@@ -4175,6 +4305,21 @@ function commonRoot(paths) {
|
|
|
4175
4305
|
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
4176
4306
|
return q;
|
|
4177
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
|
+
}
|
|
4178
4323
|
|
|
4179
4324
|
// src/core/project/sha256.ts
|
|
4180
4325
|
var K = new Uint32Array([
|
|
@@ -4336,9 +4481,9 @@ function gitDirs(dir) {
|
|
|
4336
4481
|
}
|
|
4337
4482
|
const start = cur;
|
|
4338
4483
|
for (; ; ) {
|
|
4339
|
-
const gitDir = gitDirAt(
|
|
4484
|
+
const gitDir = gitDirAt(join5(cur, GIT_DIR_NAME));
|
|
4340
4485
|
if (gitDir !== null) {
|
|
4341
|
-
const common = firstLine(
|
|
4486
|
+
const common = firstLine(join5(gitDir, GIT_COMMONDIR_FILE));
|
|
4342
4487
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
4343
4488
|
}
|
|
4344
4489
|
const up = dirname3(cur);
|
|
@@ -4359,7 +4504,7 @@ function gitDirAt(dotGit) {
|
|
|
4359
4504
|
} catch {
|
|
4360
4505
|
return null;
|
|
4361
4506
|
}
|
|
4362
|
-
return existsSync(
|
|
4507
|
+
return existsSync(join5(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
4363
4508
|
}
|
|
4364
4509
|
function firstLine(file2) {
|
|
4365
4510
|
let text;
|
|
@@ -4400,11 +4545,11 @@ function resolveProject(agent, src) {
|
|
|
4400
4545
|
return key;
|
|
4401
4546
|
},
|
|
4402
4547
|
get projectDir() {
|
|
4403
|
-
pdir ??=
|
|
4548
|
+
pdir ??= join5(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
4404
4549
|
return pdir;
|
|
4405
4550
|
},
|
|
4406
4551
|
get dbPath() {
|
|
4407
|
-
return
|
|
4552
|
+
return join5(this.projectDir, DB_FILE_NAME);
|
|
4408
4553
|
},
|
|
4409
4554
|
worktree,
|
|
4410
4555
|
get containmentRoot() {
|
|
@@ -4545,6 +4690,15 @@ function applyMigrations(db, fromVersion) {
|
|
|
4545
4690
|
}
|
|
4546
4691
|
}
|
|
4547
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
|
+
|
|
4548
4702
|
// src/core/store/db.ts
|
|
4549
4703
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4550
4704
|
function versionParts(v) {
|
|
@@ -4610,7 +4764,7 @@ function openWritable(sqlite, path8) {
|
|
|
4610
4764
|
}
|
|
4611
4765
|
}
|
|
4612
4766
|
function openReadOnly(sqlite, path8) {
|
|
4613
|
-
const raw =
|
|
4767
|
+
const raw = openReadOnlyHandle(sqlite, path8);
|
|
4614
4768
|
try {
|
|
4615
4769
|
const found = readUserVersion(raw);
|
|
4616
4770
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -4830,14 +4984,14 @@ function identParts(w) {
|
|
|
4830
4984
|
if (cur !== "") parts.push(cur);
|
|
4831
4985
|
return parts;
|
|
4832
4986
|
}
|
|
4833
|
-
function snippetTerms(
|
|
4987
|
+
function snippetTerms(words2) {
|
|
4834
4988
|
const out = /* @__PURE__ */ new Map();
|
|
4835
4989
|
const add = (text, weight, symbol2) => {
|
|
4836
4990
|
if (text === "") return;
|
|
4837
4991
|
const prev = out.get(text);
|
|
4838
4992
|
if (!prev || prev.weight < weight) out.set(text, { text, weight, symbol: symbol2 });
|
|
4839
4993
|
};
|
|
4840
|
-
for (const raw of
|
|
4994
|
+
for (const raw of words2) {
|
|
4841
4995
|
let a = 0;
|
|
4842
4996
|
let b = raw.length;
|
|
4843
4997
|
while (a < b && !isAlnum(raw.charCodeAt(a))) a++;
|
|
@@ -6843,18 +6997,18 @@ function deleteChunkRows(raw, scope) {
|
|
|
6843
6997
|
return Number(raw.prepare("DELETE FROM chunks WHERE " + where).run(arg).changes);
|
|
6844
6998
|
}
|
|
6845
6999
|
function toMatch(q) {
|
|
6846
|
-
const
|
|
7000
|
+
const words2 = [];
|
|
6847
7001
|
let cur = "";
|
|
6848
7002
|
for (const ch of q) {
|
|
6849
7003
|
if (ch.trim() === "" || ch === "\0") {
|
|
6850
|
-
if (cur !== "")
|
|
7004
|
+
if (cur !== "") words2.push(cur);
|
|
6851
7005
|
cur = "";
|
|
6852
7006
|
} else {
|
|
6853
7007
|
cur += ch === '"' ? '""' : ch;
|
|
6854
7008
|
}
|
|
6855
7009
|
}
|
|
6856
|
-
if (cur !== "")
|
|
6857
|
-
return
|
|
7010
|
+
if (cur !== "") words2.push(cur);
|
|
7011
|
+
return words2.map((w) => `"${w}"*`).join(" ");
|
|
6858
7012
|
}
|
|
6859
7013
|
function toMatchAny(q) {
|
|
6860
7014
|
const terms = new Set(toMatch(q).split(" ").filter((t) => t !== ""));
|
|
@@ -6951,11 +7105,11 @@ function searchTerms(q) {
|
|
|
6951
7105
|
return kept.length > 0 ? kept : all;
|
|
6952
7106
|
}
|
|
6953
7107
|
function trigramMatch(q) {
|
|
6954
|
-
const
|
|
6955
|
-
const kept =
|
|
6956
|
-
const parts = new Set((kept.length > 0 ? kept :
|
|
6957
|
-
const whole2 =
|
|
6958
|
-
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);
|
|
6959
7113
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
6960
7114
|
}
|
|
6961
7115
|
function editDistance(a, b, max) {
|
|
@@ -7002,10 +7156,10 @@ function queryStems(q) {
|
|
|
7002
7156
|
}
|
|
7003
7157
|
var TYPO_MIN_LEN = 5;
|
|
7004
7158
|
var TYPO_MAX_DIST = 2;
|
|
7005
|
-
function typoTerms(db,
|
|
7159
|
+
function typoTerms(db, words2) {
|
|
7006
7160
|
const has3 = stmt(db.raw, "SELECT 1 AS x FROM chunks_vocab WHERE term = ?");
|
|
7007
7161
|
const near = stmt(db.raw, "SELECT term, doc, length(term) AS n FROM chunks_vocab WHERE length(term) BETWEEN ? AND ?");
|
|
7008
|
-
const stems = queryStems(
|
|
7162
|
+
const stems = queryStems(words2.join(" "));
|
|
7009
7163
|
const miss = stems.map((stem) => has3.get(stem) === void 0 && [...stem].length >= TYPO_MIN_LEN);
|
|
7010
7164
|
if (!miss.includes(true)) return null;
|
|
7011
7165
|
const lens = stems.filter((_, i) => miss[i]).map((stem) => stem.length);
|
|
@@ -7108,9 +7262,9 @@ function ftsListSource(db, source, scope, ctx, sessionId, limit, offset) {
|
|
|
7108
7262
|
}));
|
|
7109
7263
|
}
|
|
7110
7264
|
function highlight(row5, terms, maxBytes = SNIPPET_MAX_BYTES) {
|
|
7111
|
-
const
|
|
7112
|
-
const kept =
|
|
7113
|
-
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);
|
|
7114
7268
|
}
|
|
7115
7269
|
var TL_SCOPE = `
|
|
7116
7270
|
AND (:scope <> 'session' OR session_id = :session_id)
|
|
@@ -7376,13 +7530,24 @@ function buildUnits(text) {
|
|
|
7376
7530
|
const lines = text.split("\n");
|
|
7377
7531
|
const stack2 = [];
|
|
7378
7532
|
const out = [];
|
|
7533
|
+
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
7379
7534
|
for (let i = 0; i < lines.length; i++) {
|
|
7380
7535
|
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
7381
7536
|
const indent = indentOf(line);
|
|
7382
7537
|
if (indent === line.length) continue;
|
|
7383
7538
|
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
7384
|
-
|
|
7385
|
-
|
|
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 });
|
|
7386
7551
|
}
|
|
7387
7552
|
return out;
|
|
7388
7553
|
}
|
|
@@ -7521,7 +7686,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
7521
7686
|
const pool = cands.filter((u) => !seen.has(unitKey(u)) && u.score >= RECALL_MIN_SCORE);
|
|
7522
7687
|
if (pool.length === 0) return [];
|
|
7523
7688
|
const top = Math.max(...pool.map((u) => u.score));
|
|
7524
|
-
const
|
|
7689
|
+
const words2 = pool.map((u) => wordsOf(u.body));
|
|
7525
7690
|
const taken = [];
|
|
7526
7691
|
const left = new Set(pool.map((_, i) => i));
|
|
7527
7692
|
let used = 0;
|
|
@@ -7530,7 +7695,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
7530
7695
|
let bestVal = -Infinity;
|
|
7531
7696
|
for (const i of left) {
|
|
7532
7697
|
let sim = 0;
|
|
7533
|
-
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]));
|
|
7534
7699
|
const val = MMR_RELEVANCE_WEIGHT * (pool[i].score / top) - MMR_REDUNDANCY_WEIGHT * sim;
|
|
7535
7700
|
if (val > bestVal) {
|
|
7536
7701
|
bestVal = val;
|
|
@@ -7933,7 +8098,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
7933
8098
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
7934
8099
|
return { end: start + r.read, written: r.written };
|
|
7935
8100
|
}
|
|
7936
|
-
function merge(src, blocks,
|
|
8101
|
+
function merge(src, blocks, join24, cap, lineCut) {
|
|
7937
8102
|
const out = [];
|
|
7938
8103
|
const scratch = new Uint8Array(cap);
|
|
7939
8104
|
let wide;
|
|
@@ -7943,7 +8108,7 @@ function merge(src, blocks, join27, cap, lineCut) {
|
|
|
7943
8108
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
7944
8109
|
};
|
|
7945
8110
|
for (const b of blocks) {
|
|
7946
|
-
if (cur !== void 0 && !
|
|
8111
|
+
if (cur !== void 0 && !join24) {
|
|
7947
8112
|
emit(cur.start, cur.end, curBytes);
|
|
7948
8113
|
cur = void 0;
|
|
7949
8114
|
}
|
|
@@ -8061,11 +8226,11 @@ function shapeDigest(text, query, budget) {
|
|
|
8061
8226
|
const picked = [];
|
|
8062
8227
|
let used = 0;
|
|
8063
8228
|
for (const i of order) {
|
|
8064
|
-
const
|
|
8065
|
-
const r = shape.units[i].render(budget - used -
|
|
8066
|
-
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;
|
|
8067
8232
|
picked.push({ pos: shape.units[i].pos, text: r });
|
|
8068
|
-
used +=
|
|
8233
|
+
used += sep5 + bytes(r);
|
|
8069
8234
|
}
|
|
8070
8235
|
if (picked.length === 0) return null;
|
|
8071
8236
|
picked.sort((a, b) => a.pos - b.pos);
|
|
@@ -8385,7 +8550,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
8385
8550
|
}
|
|
8386
8551
|
|
|
8387
8552
|
// src/core/hooks/fallback.ts
|
|
8388
|
-
import { join as
|
|
8553
|
+
import { join as join6, resolve as resolve5 } from "node:path";
|
|
8389
8554
|
var fs = process.getBuiltinModule("node:fs");
|
|
8390
8555
|
function isRec(v) {
|
|
8391
8556
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8412,8 +8577,10 @@ function homeOf(env) {
|
|
|
8412
8577
|
return env.HOME ?? env.USERPROFILE ?? "";
|
|
8413
8578
|
}
|
|
8414
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);
|
|
8415
8582
|
const home = homeOf(env);
|
|
8416
|
-
return home === "" ? "" :
|
|
8583
|
+
return home === "" ? "" : join6(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
8417
8584
|
}
|
|
8418
8585
|
function errorLabel(err) {
|
|
8419
8586
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -8424,7 +8591,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
8424
8591
|
try {
|
|
8425
8592
|
const file2 = hookLogPath(env);
|
|
8426
8593
|
if (file2 === "") return;
|
|
8427
|
-
fs.mkdirSync(
|
|
8594
|
+
fs.mkdirSync(join6(file2, ".."), { recursive: true });
|
|
8428
8595
|
const line = JSON.stringify({
|
|
8429
8596
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8430
8597
|
agent,
|
|
@@ -8495,17 +8662,19 @@ function isPreTool(row5, event) {
|
|
|
8495
8662
|
const e = event.toLowerCase();
|
|
8496
8663
|
return HOOK_FAIL_PRE_EVENTS.includes(e) || (row5.eventMap.PreToolUse ?? "").toLowerCase() === e;
|
|
8497
8664
|
}
|
|
8498
|
-
function
|
|
8499
|
-
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
8500
|
-
const p = firstString(input, READ_PATH_KEYS);
|
|
8501
|
-
if (p === "") return false;
|
|
8665
|
+
function bigFile(abs) {
|
|
8502
8666
|
try {
|
|
8503
|
-
const st = fs.statSync(
|
|
8667
|
+
const st = fs.statSync(abs);
|
|
8504
8668
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
8505
8669
|
} catch {
|
|
8506
8670
|
return false;
|
|
8507
8671
|
}
|
|
8508
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
|
+
}
|
|
8509
8678
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
8510
8679
|
const row5 = getAdapter(agent);
|
|
8511
8680
|
const allow = () => row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
@@ -8530,7 +8699,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
8530
8699
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
8531
8700
|
|
|
8532
8701
|
// src/core/hooks/dispatch.ts
|
|
8533
|
-
var { readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
8702
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
8534
8703
|
var ALLOW2 = { kind: "allow" };
|
|
8535
8704
|
var EMPTY4 = { stdout: "", exitCode: 0 };
|
|
8536
8705
|
var DIGIT_0 = 48;
|
|
@@ -8791,7 +8960,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
8791
8960
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
8792
8961
|
const command = tool.input.command;
|
|
8793
8962
|
if (typeof command !== "string") return d0;
|
|
8794
|
-
const wrapper = '"' +
|
|
8963
|
+
const wrapper = '"' + join7(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
8795
8964
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
8796
8965
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
8797
8966
|
}
|
|
@@ -8832,7 +9001,7 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
8832
9001
|
const tool = ev.tool;
|
|
8833
9002
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
8834
9003
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
8835
|
-
const text = wholeOutput(result);
|
|
9004
|
+
const text = wholeOutput(result, ev.sessionId, env);
|
|
8836
9005
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
8837
9006
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
8838
9007
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -8911,10 +9080,23 @@ function replaceOutput(body, handleLine) {
|
|
|
8911
9080
|
function replaceBudget(handleLine, more) {
|
|
8912
9081
|
return Math.max(0, REPLACE_RETURN_BYTES + Buffer.byteLength("\n" + more) - 1 - Buffer.byteLength(handleLine));
|
|
8913
9082
|
}
|
|
8914
|
-
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) {
|
|
8915
9093
|
const head = result.text ?? "";
|
|
8916
9094
|
if (result.persistedPath === void 0) return head;
|
|
8917
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
|
+
}
|
|
8918
9100
|
return readFileSync4(result.persistedPath, "utf8");
|
|
8919
9101
|
} catch {
|
|
8920
9102
|
return head;
|
|
@@ -20233,10 +20415,10 @@ function findRuntime(lang, env = process.env) {
|
|
|
20233
20415
|
return shim;
|
|
20234
20416
|
}
|
|
20235
20417
|
function findGitBash(env) {
|
|
20236
|
-
const
|
|
20237
|
-
if (
|
|
20418
|
+
const git2 = findRuntime(GIT_BIN, env);
|
|
20419
|
+
if (git2 === null) return null;
|
|
20238
20420
|
for (const rel of GIT_BASH_RELATIVE) {
|
|
20239
|
-
const full = path.resolve(path.dirname(
|
|
20421
|
+
const full = path.resolve(path.dirname(git2), ...rel);
|
|
20240
20422
|
if (isRunnable(full)) return full;
|
|
20241
20423
|
}
|
|
20242
20424
|
return null;
|
|
@@ -20277,10 +20459,10 @@ function startArgv(argv) {
|
|
|
20277
20459
|
return sh === null ? null : [sh, ...argv];
|
|
20278
20460
|
}
|
|
20279
20461
|
function runProcess(argv, o) {
|
|
20280
|
-
return new Promise((
|
|
20462
|
+
return new Promise((resolve9) => {
|
|
20281
20463
|
const isWin2 = process.platform === "win32";
|
|
20282
20464
|
const start = startArgv(argv);
|
|
20283
|
-
if (start === null) return
|
|
20465
|
+
if (start === null) return resolve9(NOT_STARTED);
|
|
20284
20466
|
let child;
|
|
20285
20467
|
try {
|
|
20286
20468
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -20294,7 +20476,7 @@ function runProcess(argv, o) {
|
|
|
20294
20476
|
windowsHide: true
|
|
20295
20477
|
});
|
|
20296
20478
|
} catch {
|
|
20297
|
-
return
|
|
20479
|
+
return resolve9(NOT_STARTED);
|
|
20298
20480
|
}
|
|
20299
20481
|
const stdoutChunks = [];
|
|
20300
20482
|
const stderrChunks = [];
|
|
@@ -20319,7 +20501,7 @@ function runProcess(argv, o) {
|
|
|
20319
20501
|
settled = true;
|
|
20320
20502
|
clearTimeout(timer);
|
|
20321
20503
|
o.signal.removeEventListener("abort", onAbort);
|
|
20322
|
-
|
|
20504
|
+
resolve9({
|
|
20323
20505
|
stdout: Buffer.concat(stdoutChunks),
|
|
20324
20506
|
stderr: Buffer.concat(stderrChunks),
|
|
20325
20507
|
exitCode,
|
|
@@ -20341,7 +20523,7 @@ function runProcess(argv, o) {
|
|
|
20341
20523
|
|
|
20342
20524
|
// src/core/index/auto-memory.ts
|
|
20343
20525
|
import { readdirSync, readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
|
|
20344
|
-
import { join as
|
|
20526
|
+
import { join as join8 } from "node:path";
|
|
20345
20527
|
var MEMORY_FILES = Object.freeze([
|
|
20346
20528
|
Object.freeze(["CLAUDE.md"]),
|
|
20347
20529
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -20355,7 +20537,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20355
20537
|
var MD = ".md";
|
|
20356
20538
|
function steeringFiles(worktree) {
|
|
20357
20539
|
try {
|
|
20358
|
-
return readdirSync(
|
|
20540
|
+
return readdirSync(join8(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20359
20541
|
} catch {
|
|
20360
20542
|
return [];
|
|
20361
20543
|
}
|
|
@@ -20363,7 +20545,7 @@ function steeringFiles(worktree) {
|
|
|
20363
20545
|
function readAutoMemory(project) {
|
|
20364
20546
|
const rows = [];
|
|
20365
20547
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20366
|
-
const path8 =
|
|
20548
|
+
const path8 = join8(project.worktree, ...segs);
|
|
20367
20549
|
if (!isInside(project.worktree, path8)) continue;
|
|
20368
20550
|
try {
|
|
20369
20551
|
const st = statSync4(path8);
|
|
@@ -20946,18 +21128,18 @@ var ctxBatch = Object.freeze({
|
|
|
20946
21128
|
|
|
20947
21129
|
// src/core/tools/doctor.ts
|
|
20948
21130
|
import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
|
|
20949
|
-
import { basename as basename5, join as
|
|
21131
|
+
import { basename as basename5, join as join18 } from "node:path";
|
|
20950
21132
|
|
|
20951
21133
|
// src/core/ops/bundle-dir.ts
|
|
20952
21134
|
import { existsSync as existsSync3 } from "node:fs";
|
|
20953
|
-
import { dirname as dirname5, join as
|
|
21135
|
+
import { dirname as dirname5, join as join9 } from "node:path";
|
|
20954
21136
|
import { fileURLToPath } from "node:url";
|
|
20955
21137
|
function bundleDirOf(argv1, moduleFile) {
|
|
20956
21138
|
const own2 = dirname5(argv1);
|
|
20957
|
-
if (existsSync3(
|
|
21139
|
+
if (existsSync3(join9(own2, SERVER_ENTRY_FILE))) return own2;
|
|
20958
21140
|
let dir = dirname5(moduleFile);
|
|
20959
21141
|
for (; ; ) {
|
|
20960
|
-
if (existsSync3(
|
|
21142
|
+
if (existsSync3(join9(dir, SERVER_ENTRY_FILE))) return dir;
|
|
20961
21143
|
const up = dirname5(dir);
|
|
20962
21144
|
if (up === dir) return own2;
|
|
20963
21145
|
dir = up;
|
|
@@ -20972,16 +21154,16 @@ function ownBundleDir() {
|
|
|
20972
21154
|
|
|
20973
21155
|
// src/core/ops/doctor-config.ts
|
|
20974
21156
|
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
20975
|
-
import { join as
|
|
21157
|
+
import { join as join13 } from "node:path";
|
|
20976
21158
|
|
|
20977
21159
|
// src/core/ops/detect-v1.ts
|
|
20978
21160
|
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
|
|
20979
21161
|
import { tmpdir } from "node:os";
|
|
20980
|
-
import { join as
|
|
21162
|
+
import { join as join11 } from "node:path";
|
|
20981
21163
|
|
|
20982
21164
|
// src/core/ops/host-config.ts
|
|
20983
21165
|
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
20984
|
-
import { dirname as dirname6, join as
|
|
21166
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
20985
21167
|
|
|
20986
21168
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
20987
21169
|
var KEYS2 = {
|
|
@@ -23098,7 +23280,7 @@ function formatOf(path8) {
|
|
|
23098
23280
|
function readHostConfig(agent, path8) {
|
|
23099
23281
|
let file2 = path8;
|
|
23100
23282
|
if (agent === "opencode") {
|
|
23101
|
-
const jsonc =
|
|
23283
|
+
const jsonc = join10(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23102
23284
|
if (existsSync4(jsonc)) file2 = jsonc;
|
|
23103
23285
|
}
|
|
23104
23286
|
const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -23409,8 +23591,8 @@ function replaceToml(text, doc, path8, value) {
|
|
|
23409
23591
|
let out = text;
|
|
23410
23592
|
for (const [s, e, put] of cuts) out = out.slice(0, s) + put + out.slice(e);
|
|
23411
23593
|
if (owned.length > 0 || block === "") return out;
|
|
23412
|
-
const
|
|
23413
|
-
return out +
|
|
23594
|
+
const sep5 = out === "" ? "" : out.endsWith("\n\n") ? "" : out.endsWith("\n") ? "\n" : "\n\n";
|
|
23595
|
+
return out + sep5 + block;
|
|
23414
23596
|
}
|
|
23415
23597
|
var tableLike = (v) => v === void 0 || isPlainObject3(v);
|
|
23416
23598
|
function setTomlText(text, path8, value) {
|
|
@@ -23446,33 +23628,39 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
23446
23628
|
}
|
|
23447
23629
|
}
|
|
23448
23630
|
function serverScript() {
|
|
23449
|
-
return
|
|
23631
|
+
return join10(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23450
23632
|
}
|
|
23451
23633
|
function isNodeCommand(command) {
|
|
23452
23634
|
if (typeof command !== "string") return false;
|
|
23453
23635
|
let at2 = -1;
|
|
23454
|
-
for (const
|
|
23636
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, command.lastIndexOf(sep5));
|
|
23455
23637
|
const exe = command.slice(at2 + 1).toLowerCase();
|
|
23456
23638
|
return exe === HOST_NODE_COMMAND || exe === HOST_NODE_COMMAND + EXE_SUFFIX;
|
|
23457
23639
|
}
|
|
23458
23640
|
function ownMcpValue(agent, node, server2) {
|
|
23459
23641
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23460
23642
|
if (mcp === void 0) return void 0;
|
|
23461
|
-
|
|
23462
|
-
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] };
|
|
23463
23644
|
}
|
|
23464
23645
|
function opencodePluginFile() {
|
|
23465
23646
|
return ownBundleDir();
|
|
23466
23647
|
}
|
|
23467
|
-
function listTarget(key,
|
|
23648
|
+
function listTarget(key, legacy, swap, isNative) {
|
|
23468
23649
|
return {
|
|
23469
23650
|
key: [key],
|
|
23470
23651
|
next(current) {
|
|
23471
|
-
|
|
23472
|
-
|
|
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]);
|
|
23473
23657
|
}
|
|
23474
23658
|
};
|
|
23475
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;
|
|
23476
23664
|
function ownTargets(agent, accept) {
|
|
23477
23665
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23478
23666
|
if (mcp !== void 0) {
|
|
@@ -23485,8 +23673,18 @@ function ownTargets(agent, accept) {
|
|
|
23485
23673
|
}
|
|
23486
23674
|
}, ...(mcp.also ?? []).map(([key, value]) => ({ key, next: () => value }))];
|
|
23487
23675
|
}
|
|
23488
|
-
if (agent === "opencode")
|
|
23489
|
-
|
|
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
|
+
}
|
|
23490
23688
|
return [];
|
|
23491
23689
|
}
|
|
23492
23690
|
function applyEdits(agent, path8, text, format, wanted) {
|
|
@@ -23588,7 +23786,7 @@ function isV2McpTable(v) {
|
|
|
23588
23786
|
const first = Array.isArray(v[MCP_ARGS_FIELD]) ? v[MCP_ARGS_FIELD][0] : void 0;
|
|
23589
23787
|
if (typeof first !== "string") return false;
|
|
23590
23788
|
let at2 = -1;
|
|
23591
|
-
for (const
|
|
23789
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, first.lastIndexOf(sep5));
|
|
23592
23790
|
return first.slice(at2 + 1) === SERVER_ENTRY_FILE;
|
|
23593
23791
|
}
|
|
23594
23792
|
var listOf = (v) => Array.isArray(v) ? v : [];
|
|
@@ -23619,7 +23817,7 @@ function flatCommands(events, prefix) {
|
|
|
23619
23817
|
return out;
|
|
23620
23818
|
}
|
|
23621
23819
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23622
|
-
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));
|
|
23623
23821
|
function dataDir(dir, reason, out) {
|
|
23624
23822
|
if (existsSync5(dir)) out.push(finding(dir, "", reason));
|
|
23625
23823
|
}
|
|
@@ -23629,7 +23827,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23629
23827
|
}
|
|
23630
23828
|
}
|
|
23631
23829
|
function claudeShapeSettings(agentHome, out) {
|
|
23632
|
-
const file2 =
|
|
23830
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23633
23831
|
const doc = readJson(file2);
|
|
23634
23832
|
for (const c of nestedCommands(doc)) {
|
|
23635
23833
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23649,49 +23847,50 @@ function v1HookFile(file2, out) {
|
|
|
23649
23847
|
function scanClaudeCode(home, agentHome, out) {
|
|
23650
23848
|
claudeShapeSettings(agentHome, out);
|
|
23651
23849
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23652
|
-
const file2 =
|
|
23850
|
+
const file2 = join11(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
23653
23851
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23654
23852
|
}
|
|
23655
|
-
const userFile =
|
|
23853
|
+
const userFile = join11(home, CLAUDE_USER_CONFIG_FILE);
|
|
23656
23854
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23657
|
-
dataDir(
|
|
23855
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23658
23856
|
}
|
|
23659
23857
|
function scanCodex(agentHome, out) {
|
|
23660
|
-
const hooksFile =
|
|
23858
|
+
const hooksFile = join11(agentHome, HOOKS_JSON_FILE);
|
|
23661
23859
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23662
23860
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23663
23861
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23664
23862
|
}
|
|
23665
23863
|
}
|
|
23666
|
-
const tomlFile =
|
|
23864
|
+
const tomlFile = join11(agentHome, CONFIG_TOML_FILE);
|
|
23667
23865
|
const config2 = readTomlValue(tomlFile);
|
|
23668
23866
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23669
23867
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23670
23868
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
|
|
23671
23869
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23672
23870
|
}
|
|
23673
|
-
dataDir(
|
|
23871
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23674
23872
|
}
|
|
23675
23873
|
function scanGemini(agentHome, out) {
|
|
23676
|
-
const file2 =
|
|
23874
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23677
23875
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23678
23876
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23679
23877
|
}
|
|
23680
|
-
dataDir(
|
|
23878
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23681
23879
|
}
|
|
23682
23880
|
function scanVscode(agentHome, project, out) {
|
|
23683
23881
|
if (project !== void 0) {
|
|
23684
|
-
v1HookFile(
|
|
23685
|
-
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);
|
|
23686
23884
|
const doc = readJson(mcpFile2);
|
|
23687
23885
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23688
23886
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23689
23887
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23690
23888
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23691
23889
|
}
|
|
23692
|
-
|
|
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);
|
|
23693
23892
|
}
|
|
23694
|
-
dataDir(
|
|
23893
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23695
23894
|
}
|
|
23696
23895
|
function jsonFiles(dir) {
|
|
23697
23896
|
try {
|
|
@@ -23701,10 +23900,10 @@ function jsonFiles(dir) {
|
|
|
23701
23900
|
}
|
|
23702
23901
|
}
|
|
23703
23902
|
function scanKiro(agentHome, project, out) {
|
|
23704
|
-
const agentsDir =
|
|
23705
|
-
const defaultFile =
|
|
23903
|
+
const agentsDir = join11(agentHome, KIRO_AGENTS_DIR);
|
|
23904
|
+
const defaultFile = join11(agentHome, ...KIRO_AGENT_FILE);
|
|
23706
23905
|
for (const name of jsonFiles(agentsDir)) {
|
|
23707
|
-
const file2 =
|
|
23906
|
+
const file2 = join11(agentsDir, name);
|
|
23708
23907
|
const doc = readJson(file2);
|
|
23709
23908
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23710
23909
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23715,46 +23914,48 @@ function scanKiro(agentHome, project, out) {
|
|
|
23715
23914
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23716
23915
|
}
|
|
23717
23916
|
}
|
|
23718
|
-
const steeringDocs = [
|
|
23719
|
-
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));
|
|
23720
23919
|
for (const file2 of steeringDocs) {
|
|
23721
23920
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
23722
23921
|
}
|
|
23723
|
-
dataDir(
|
|
23922
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23724
23923
|
}
|
|
23725
23924
|
function piNpmIsCurrent(piAgentDir) {
|
|
23726
|
-
const doc = readJson(
|
|
23925
|
+
const doc = readJson(join11(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23727
23926
|
const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23728
23927
|
return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
|
|
23729
23928
|
}
|
|
23730
23929
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23731
|
-
const file2 =
|
|
23930
|
+
const file2 = join11(piAgentDir, SETTINGS_FILE);
|
|
23732
23931
|
const doc = readJson(file2);
|
|
23733
23932
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23734
23933
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23735
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));
|
|
23736
23936
|
});
|
|
23737
|
-
dataDir(
|
|
23937
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23738
23938
|
}
|
|
23739
23939
|
function scanOpencode(agentHome, out) {
|
|
23740
23940
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
23741
|
-
const file2 =
|
|
23941
|
+
const file2 = join11(agentHome, name);
|
|
23742
23942
|
const doc = readJson(file2);
|
|
23743
23943
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
23744
23944
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
23745
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));
|
|
23746
23947
|
});
|
|
23747
23948
|
return;
|
|
23748
23949
|
}
|
|
23749
23950
|
}
|
|
23750
23951
|
function scanZcode(agentHome, out) {
|
|
23751
|
-
const configFile =
|
|
23952
|
+
const configFile = join11(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
23752
23953
|
const config2 = readJson(configFile);
|
|
23753
23954
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
23754
23955
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
23755
23956
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
23756
23957
|
}
|
|
23757
|
-
const hooksFile =
|
|
23958
|
+
const hooksFile = join11(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
23758
23959
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23759
23960
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
23760
23961
|
}
|
|
@@ -23778,14 +23979,14 @@ function firstTmpMatch(dir) {
|
|
|
23778
23979
|
}
|
|
23779
23980
|
}
|
|
23780
23981
|
function scanAll(home, tmp, out) {
|
|
23781
|
-
const root =
|
|
23782
|
-
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);
|
|
23783
23984
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
23784
23985
|
}
|
|
23785
23986
|
function detectV1(agent, home, scope = {}) {
|
|
23786
23987
|
const out = [];
|
|
23787
23988
|
const project = scope.project;
|
|
23788
|
-
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]);
|
|
23789
23990
|
switch (agent) {
|
|
23790
23991
|
case "claude-code":
|
|
23791
23992
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -23798,11 +23999,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23798
23999
|
break;
|
|
23799
24000
|
case "qwen":
|
|
23800
24001
|
claudeShapeSettings(agentHome, out);
|
|
23801
|
-
dataDir(
|
|
24002
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23802
24003
|
break;
|
|
23803
24004
|
case "copilot-cli":
|
|
23804
|
-
v1HookFile(
|
|
23805
|
-
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);
|
|
23806
24007
|
break;
|
|
23807
24008
|
case "vscode":
|
|
23808
24009
|
scanVscode(agentHome, project, out);
|
|
@@ -23811,7 +24012,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23811
24012
|
scanKiro(agentHome, project, out);
|
|
23812
24013
|
break;
|
|
23813
24014
|
case "pi":
|
|
23814
|
-
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);
|
|
23815
24016
|
break;
|
|
23816
24017
|
// D-WIN-PIDIR-1: empty is unset
|
|
23817
24018
|
case "opencode":
|
|
@@ -23827,7 +24028,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23827
24028
|
|
|
23828
24029
|
// src/core/ops/plugin-root.ts
|
|
23829
24030
|
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23830
|
-
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";
|
|
23831
24032
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23832
24033
|
function missing(agent, path8) {
|
|
23833
24034
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -23875,8 +24076,8 @@ var readOrNull = (file2) => {
|
|
|
23875
24076
|
};
|
|
23876
24077
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
23877
24078
|
function enabledPlugins(claudeDir, project) {
|
|
23878
|
-
const files = [
|
|
23879
|
-
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));
|
|
23880
24081
|
const out = {};
|
|
23881
24082
|
for (const file2 of files) {
|
|
23882
24083
|
const text = readOrNull(file2);
|
|
@@ -23892,7 +24093,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
23892
24093
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23893
24094
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
23894
24095
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
23895
|
-
const record4 = readOrNull(
|
|
24096
|
+
const record4 = readOrNull(join12(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
23896
24097
|
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
23897
24098
|
if (recorded.length === 0) return { record: false };
|
|
23898
24099
|
const live = recorded.filter((r) => existsSync6(r.installPath));
|
|
@@ -23915,18 +24116,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
23915
24116
|
}
|
|
23916
24117
|
function marketplaceRoot(adapter, env, worktree) {
|
|
23917
24118
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23918
|
-
const plugins =
|
|
23919
|
-
const cache =
|
|
24119
|
+
const plugins = join12(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24120
|
+
const cache = join12(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23920
24121
|
const script = process.argv[1];
|
|
23921
24122
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23922
24123
|
const choice = marketplaceChoice(env, worktree);
|
|
23923
24124
|
if ("root" in choice) return choice.root;
|
|
23924
24125
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
23925
24126
|
const cacheReal = realOrNull(cache);
|
|
23926
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal +
|
|
23927
|
-
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);
|
|
23928
24129
|
if (!existsSync6(cache)) throw missing(adapter.id, pattern);
|
|
23929
|
-
const found = readdirSync3(cache).sort().map((marketplace) =>
|
|
24130
|
+
const found = readdirSync3(cache).sort().map((marketplace) => join12(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
|
|
23930
24131
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
23931
24132
|
return found[0];
|
|
23932
24133
|
}
|
|
@@ -23951,9 +24152,9 @@ function candidate(adapter, env, worktree) {
|
|
|
23951
24152
|
case "hooks+mcp":
|
|
23952
24153
|
return configEntryRoot(adapter, env);
|
|
23953
24154
|
case "extension":
|
|
23954
|
-
return
|
|
24155
|
+
return join12(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join12(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
23955
24156
|
case "plugin":
|
|
23956
|
-
return
|
|
24157
|
+
return join12(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
23957
24158
|
case "in-process":
|
|
23958
24159
|
return dirname7(fileURLToPath2(import.meta.url));
|
|
23959
24160
|
}
|
|
@@ -24060,7 +24261,7 @@ function composeMatcher(row5, event) {
|
|
|
24060
24261
|
}
|
|
24061
24262
|
var lastSegment = (p) => {
|
|
24062
24263
|
let at2 = -1;
|
|
24063
|
-
for (const
|
|
24264
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, p.lastIndexOf(sep5));
|
|
24064
24265
|
return p.slice(at2 + 1);
|
|
24065
24266
|
};
|
|
24066
24267
|
function splitHead(command) {
|
|
@@ -24082,7 +24283,7 @@ function isOwnCommand(command, agent) {
|
|
|
24082
24283
|
if (!split.rest.endsWith(tail) || split.rest.length <= tail.length) return false;
|
|
24083
24284
|
let script = split.rest.slice(0, split.rest.length - tail.length);
|
|
24084
24285
|
if (script.startsWith(SHELL_QUOTE) && script.endsWith(SHELL_QUOTE) && script.length > 1) script = script.slice(1, -1);
|
|
24085
|
-
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));
|
|
24086
24287
|
}
|
|
24087
24288
|
function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
24088
24289
|
const out = [];
|
|
@@ -24113,11 +24314,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24113
24314
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24114
24315
|
function mcpFile(row5, home, env) {
|
|
24115
24316
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24116
|
-
if (row5.id === "codex") return
|
|
24317
|
+
if (row5.id === "codex") return join13(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24117
24318
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24118
|
-
if (row5.id === "opencode") return
|
|
24319
|
+
if (row5.id === "opencode") return join13(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24119
24320
|
if (row5.id === "pi") {
|
|
24120
|
-
return
|
|
24321
|
+
return join13(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24121
24322
|
}
|
|
24122
24323
|
return null;
|
|
24123
24324
|
}
|
|
@@ -24130,27 +24331,27 @@ function codexNativeDir(env, home) {
|
|
|
24130
24331
|
const codexDir = codexDirOf(env, home);
|
|
24131
24332
|
let enabled;
|
|
24132
24333
|
try {
|
|
24133
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24334
|
+
enabled = hostConfigValueAt(readParsed("codex", join13(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24134
24335
|
} catch {
|
|
24135
24336
|
return null;
|
|
24136
24337
|
}
|
|
24137
24338
|
if (enabled !== true) return null;
|
|
24138
|
-
const cache =
|
|
24339
|
+
const cache = join13(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24139
24340
|
if (!existsSync8(cache)) return null;
|
|
24140
24341
|
const found = [];
|
|
24141
24342
|
for (const market of readdirSync4(cache)) {
|
|
24142
|
-
const plugin =
|
|
24343
|
+
const plugin = join13(cache, market, SERVER_KEY);
|
|
24143
24344
|
if (!existsSync8(plugin)) continue;
|
|
24144
24345
|
for (const version2 of readdirSync4(plugin).sort()) {
|
|
24145
|
-
const dir =
|
|
24146
|
-
if (existsSync8(
|
|
24346
|
+
const dir = join13(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24347
|
+
if (existsSync8(join13(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24147
24348
|
}
|
|
24148
24349
|
}
|
|
24149
24350
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24150
24351
|
}
|
|
24151
24352
|
function nativeMcpWrong(dir, row5) {
|
|
24152
24353
|
try {
|
|
24153
|
-
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]);
|
|
24154
24355
|
if (!isObject4(entry)) return true;
|
|
24155
24356
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24156
24357
|
const script = args[0];
|
|
@@ -24165,10 +24366,19 @@ function isOwnOpencodeEntry(entry, key, own2) {
|
|
|
24165
24366
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own2.includes(spec)) return true;
|
|
24166
24367
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
24167
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
|
+
}
|
|
24168
24375
|
function opencodeListed(file2) {
|
|
24169
24376
|
const { value } = readParsed("opencode", file2);
|
|
24170
|
-
const
|
|
24171
|
-
|
|
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]);
|
|
24172
24382
|
}
|
|
24173
24383
|
function mcpWrong(row5, home, env, worktree) {
|
|
24174
24384
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
@@ -24189,7 +24399,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24189
24399
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24190
24400
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24191
24401
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24192
|
-
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);
|
|
24193
24403
|
return file2;
|
|
24194
24404
|
}
|
|
24195
24405
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24200,7 +24410,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24200
24410
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24201
24411
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24202
24412
|
if (row5.id === "codex") {
|
|
24203
|
-
const config2 = readParsed(row5.id,
|
|
24413
|
+
const config2 = readParsed(row5.id, join13(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24204
24414
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24205
24415
|
}
|
|
24206
24416
|
} catch {
|
|
@@ -24244,7 +24454,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24244
24454
|
function checkPiInstall(env, home, worktree) {
|
|
24245
24455
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24246
24456
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24247
|
-
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]);
|
|
24248
24458
|
}
|
|
24249
24459
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24250
24460
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24263,10 +24473,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24263
24473
|
}
|
|
24264
24474
|
function checkDoubleFire(agent, worktree) {
|
|
24265
24475
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24266
|
-
const claude = parsedOrNull(agent,
|
|
24476
|
+
const claude = parsedOrNull(agent, join13(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24267
24477
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24268
24478
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24269
|
-
const vscode = parsedOrNull(agent,
|
|
24479
|
+
const vscode = parsedOrNull(agent, join13(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24270
24480
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24271
24481
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24272
24482
|
}
|
|
@@ -24277,7 +24487,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24277
24487
|
const mcp = mcpFile(row5, home, env);
|
|
24278
24488
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24279
24489
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24280
|
-
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) });
|
|
24281
24491
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24282
24492
|
if (spec !== null) {
|
|
24283
24493
|
try {
|
|
@@ -24317,7 +24527,7 @@ async function loadSqlite2() {
|
|
|
24317
24527
|
}
|
|
24318
24528
|
}
|
|
24319
24529
|
function openRead(sqlite, path8) {
|
|
24320
|
-
return
|
|
24530
|
+
return openReadOnlyHandle(sqlite, path8);
|
|
24321
24531
|
}
|
|
24322
24532
|
var cell = (row5) => Object.values(row5)[0];
|
|
24323
24533
|
function readSchema(raw) {
|
|
@@ -24391,7 +24601,7 @@ async function checkIndex(project) {
|
|
|
24391
24601
|
|
|
24392
24602
|
// src/core/ops/doctor-env.ts
|
|
24393
24603
|
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
24394
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24604
|
+
import { isAbsolute as isAbsolute3, join as join14, relative as relative4 } from "node:path";
|
|
24395
24605
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24396
24606
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24397
24607
|
}
|
|
@@ -24403,7 +24613,7 @@ function fail4(id2, detail, fixCommand) {
|
|
|
24403
24613
|
}
|
|
24404
24614
|
function bundleVersion(bundleDir2) {
|
|
24405
24615
|
try {
|
|
24406
|
-
const v = JSON.parse(readFileSync10(
|
|
24616
|
+
const v = JSON.parse(readFileSync10(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24407
24617
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24408
24618
|
} catch {
|
|
24409
24619
|
return void 0;
|
|
@@ -24498,12 +24708,12 @@ async function checkVersion(i) {
|
|
|
24498
24708
|
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24499
24709
|
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24500
24710
|
const tag2 = channelOf(i.version);
|
|
24501
|
-
const
|
|
24711
|
+
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24502
24712
|
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24503
24713
|
if (npm.ok) return versionRow(head, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
24504
24714
|
let cause = D1_GIT_MISSING;
|
|
24505
|
-
if (
|
|
24506
|
-
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], {
|
|
24507
24717
|
cwd: i.cwd,
|
|
24508
24718
|
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
24509
24719
|
signal: i.signal,
|
|
@@ -24517,7 +24727,7 @@ async function checkVersion(i) {
|
|
|
24517
24727
|
cause = gitCause(r, i.timeoutMs);
|
|
24518
24728
|
}
|
|
24519
24729
|
}
|
|
24520
|
-
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);
|
|
24521
24731
|
}
|
|
24522
24732
|
function numbers(v) {
|
|
24523
24733
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -24554,7 +24764,7 @@ function checkMcp(ctx) {
|
|
|
24554
24764
|
}
|
|
24555
24765
|
function piCwdInside(worktree, piCwd) {
|
|
24556
24766
|
if (piCwd === void 0 || !existsSync10(piCwd)) return false;
|
|
24557
|
-
const rel =
|
|
24767
|
+
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24558
24768
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24559
24769
|
}
|
|
24560
24770
|
function checkProject(i) {
|
|
@@ -24578,6 +24788,15 @@ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11
|
|
|
24578
24788
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24579
24789
|
import path7 from "node:path";
|
|
24580
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
|
+
|
|
24581
24800
|
// src/setup/codex-trust.ts
|
|
24582
24801
|
import { createHash } from "node:crypto";
|
|
24583
24802
|
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
@@ -24697,14 +24916,14 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
24697
24916
|
function askPluginHooks(env, pluginId, cwd) {
|
|
24698
24917
|
const bin = whichBin("codex", env);
|
|
24699
24918
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
24700
|
-
return new Promise((
|
|
24919
|
+
return new Promise((resolve9) => {
|
|
24701
24920
|
let asked;
|
|
24702
24921
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
24703
24922
|
let f;
|
|
24704
24923
|
try {
|
|
24705
24924
|
f = spawnForm(bin, ["app-server"], env);
|
|
24706
24925
|
} catch {
|
|
24707
|
-
|
|
24926
|
+
resolve9({ kind: "silent" });
|
|
24708
24927
|
return;
|
|
24709
24928
|
}
|
|
24710
24929
|
const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -24714,7 +24933,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
24714
24933
|
let result;
|
|
24715
24934
|
const settle = () => {
|
|
24716
24935
|
clearTimeout(grace);
|
|
24717
|
-
|
|
24936
|
+
resolve9(done_(result));
|
|
24718
24937
|
};
|
|
24719
24938
|
let grace;
|
|
24720
24939
|
const finish2 = (v) => {
|
|
@@ -24784,8 +25003,8 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
24784
25003
|
if (!bad.length) return void 0;
|
|
24785
25004
|
const counts = /* @__PURE__ */ new Map();
|
|
24786
25005
|
for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
|
|
24787
|
-
const
|
|
24788
|
-
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(", ")})`;
|
|
24789
25008
|
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
24790
25009
|
}
|
|
24791
25010
|
|
|
@@ -24897,9 +25116,10 @@ function isReadShape(stdout) {
|
|
|
24897
25116
|
async function readProbe(i, timeoutMs, ranged) {
|
|
24898
25117
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
24899
25118
|
try {
|
|
24900
|
-
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], {
|
|
24901
25121
|
cwd: i.bundleDir,
|
|
24902
|
-
env:
|
|
25122
|
+
env: node.env,
|
|
24903
25123
|
signal: i.signal,
|
|
24904
25124
|
timeoutMs,
|
|
24905
25125
|
stdin: JSON.stringify(readProbePayload(i.worktree ?? home, ranged))
|
|
@@ -24969,7 +25189,8 @@ async function checkHookRoundTrip(i) {
|
|
|
24969
25189
|
const timeoutMs = i.timeoutMs ?? HOOK_TIMEOUT_MS;
|
|
24970
25190
|
const bareMs = i.bareMs ?? (async () => {
|
|
24971
25191
|
const t = performance.now();
|
|
24972
|
-
|
|
25192
|
+
const node = nodeLaunch(i.env);
|
|
25193
|
+
await runProcess([node.file, "-e", ""], { cwd: i.bundleDir, env: node.env, signal: i.signal, timeoutMs });
|
|
24973
25194
|
return performance.now() - t;
|
|
24974
25195
|
});
|
|
24975
25196
|
const hookWalls = [];
|
|
@@ -24977,9 +25198,10 @@ async function checkHookRoundTrip(i) {
|
|
|
24977
25198
|
let ms = 0;
|
|
24978
25199
|
for (let n = 1; n <= maxPairs; n++) {
|
|
24979
25200
|
const start = now();
|
|
24980
|
-
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], {
|
|
24981
25203
|
cwd: i.bundleDir,
|
|
24982
|
-
env:
|
|
25204
|
+
env: node.env,
|
|
24983
25205
|
signal: i.signal,
|
|
24984
25206
|
timeoutMs,
|
|
24985
25207
|
stdin: JSON.stringify(payloadFor(i.agent, fixture.payload, i.worktree))
|
|
@@ -24998,13 +25220,13 @@ async function checkHookRoundTrip(i) {
|
|
|
24998
25220
|
|
|
24999
25221
|
// src/core/ops/db-heal.ts
|
|
25000
25222
|
import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
25001
|
-
import { basename as basename4, dirname as dirname8, join as
|
|
25223
|
+
import { basename as basename4, dirname as dirname8, join as join16 } from "node:path";
|
|
25002
25224
|
|
|
25003
25225
|
// src/core/store/owners.ts
|
|
25004
25226
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
25005
|
-
import { basename as basename3, join as
|
|
25227
|
+
import { basename as basename3, join as join15 } from "node:path";
|
|
25006
25228
|
function ownersDir(configDir, projectKey) {
|
|
25007
|
-
return
|
|
25229
|
+
return join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25008
25230
|
}
|
|
25009
25231
|
function errCode2(err) {
|
|
25010
25232
|
return err.code;
|
|
@@ -25032,7 +25254,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
25032
25254
|
const live = [];
|
|
25033
25255
|
for (const name of names) {
|
|
25034
25256
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25035
|
-
const file2 =
|
|
25257
|
+
const file2 = join15(dir, name);
|
|
25036
25258
|
let text;
|
|
25037
25259
|
try {
|
|
25038
25260
|
text = readFileSync12(file2, "utf8");
|
|
@@ -25056,7 +25278,7 @@ async function healLossless(dbPath) {
|
|
|
25056
25278
|
const tmp = dbPath + HEAL_TMP_SUFFIX;
|
|
25057
25279
|
rmSync4(tmp, { force: true });
|
|
25058
25280
|
try {
|
|
25059
|
-
const src =
|
|
25281
|
+
const src = openReadOnlyHandle({ DatabaseSync }, dbPath, { queryOnly: false });
|
|
25060
25282
|
try {
|
|
25061
25283
|
src.prepare("VACUUM INTO ?").run(tmp);
|
|
25062
25284
|
} finally {
|
|
@@ -25104,7 +25326,7 @@ function utcStamp(now) {
|
|
|
25104
25326
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
25105
25327
|
}
|
|
25106
25328
|
function makeOrphanDir(projectDir) {
|
|
25107
|
-
const base =
|
|
25329
|
+
const base = join16(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
25108
25330
|
for (let n = 1; ; n += 1) {
|
|
25109
25331
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
25110
25332
|
try {
|
|
@@ -25121,7 +25343,7 @@ async function healOrphan(project, files, row5) {
|
|
|
25121
25343
|
try {
|
|
25122
25344
|
dir = makeOrphanDir(dirname8(project.dbPath));
|
|
25123
25345
|
for (const f of files) {
|
|
25124
|
-
const to =
|
|
25346
|
+
const to = join16(dir, basename4(f.path));
|
|
25125
25347
|
renameWithRetry(f.path, to);
|
|
25126
25348
|
moved.push({ path: to, bytes: f.bytes });
|
|
25127
25349
|
}
|
|
@@ -25189,7 +25411,7 @@ function buildReportHead(input) {
|
|
|
25189
25411
|
// src/core/ops/doctor-issue.ts
|
|
25190
25412
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
25191
25413
|
import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25192
|
-
import { delimiter, join as
|
|
25414
|
+
import { delimiter, join as join17 } from "node:path";
|
|
25193
25415
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
25194
25416
|
function tildeOf(env) {
|
|
25195
25417
|
const home = homeDirOf(env);
|
|
@@ -25230,8 +25452,8 @@ function onPath(env, tool) {
|
|
|
25230
25452
|
const out = [];
|
|
25231
25453
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25232
25454
|
if (dir === "") continue;
|
|
25233
|
-
for (const n of names) if (existsSync14(
|
|
25234
|
-
out.push(
|
|
25455
|
+
for (const n of names) if (existsSync14(join17(dir, n))) {
|
|
25456
|
+
out.push(join17(dir, n));
|
|
25235
25457
|
break;
|
|
25236
25458
|
}
|
|
25237
25459
|
}
|
|
@@ -25277,8 +25499,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25277
25499
|
const home = homeDirOf(env);
|
|
25278
25500
|
const files = configPaths(adapter, env, worktree);
|
|
25279
25501
|
if (home !== null) {
|
|
25280
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
25281
|
-
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) });
|
|
25282
25504
|
}
|
|
25283
25505
|
const out = [];
|
|
25284
25506
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -25361,9 +25583,9 @@ async function buildIssueBody(i) {
|
|
|
25361
25583
|
async function writeIssueReport(i) {
|
|
25362
25584
|
const tilde = tildeOf(i.env);
|
|
25363
25585
|
const body = await buildIssueBody(i);
|
|
25364
|
-
const dir =
|
|
25586
|
+
const dir = join17(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
25365
25587
|
mkdirSync6(dir, { recursive: true });
|
|
25366
|
-
const file2 =
|
|
25588
|
+
const file2 = join17(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
25367
25589
|
writeFileSync3(file2, body);
|
|
25368
25590
|
const shown2 = tilde(file2);
|
|
25369
25591
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -25420,11 +25642,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25420
25642
|
}
|
|
25421
25643
|
}
|
|
25422
25644
|
function ownServerId(configDir, projectKey) {
|
|
25423
|
-
const dir =
|
|
25645
|
+
const dir = join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25424
25646
|
if (!existsSync15(dir)) return "";
|
|
25425
25647
|
for (const name of readdirSync6(dir)) {
|
|
25426
25648
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25427
|
-
if (readFileSync14(
|
|
25649
|
+
if (readFileSync14(join18(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25428
25650
|
}
|
|
25429
25651
|
return "";
|
|
25430
25652
|
}
|
|
@@ -25438,7 +25660,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
25438
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 }),
|
|
25439
25661
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
25440
25662
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
25441
|
-
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)) }),
|
|
25442
25664
|
D5: () => hookRow(ctx, adapter, host),
|
|
25443
25665
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
25444
25666
|
D6: () => checkMcp(ctx),
|
|
@@ -25479,13 +25701,13 @@ function reportEnv(env) {
|
|
|
25479
25701
|
async function doctorReply(ctx, host) {
|
|
25480
25702
|
const adapter = getAdapter(ctx.project.agent);
|
|
25481
25703
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
25482
|
-
const
|
|
25483
|
-
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}`;
|
|
25484
25706
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
25485
25707
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
25486
25708
|
const table3 = buildReport(input);
|
|
25487
25709
|
let notes = [];
|
|
25488
|
-
if (
|
|
25710
|
+
if (failed) {
|
|
25489
25711
|
try {
|
|
25490
25712
|
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
25491
25713
|
} catch (err) {
|
|
@@ -25521,7 +25743,7 @@ var ctxDoctor = Object.freeze({
|
|
|
25521
25743
|
// src/core/tools/execute.ts
|
|
25522
25744
|
import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25523
25745
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25524
|
-
import { dirname as dirname10, join as
|
|
25746
|
+
import { dirname as dirname10, join as join19, parse as parse3, resolve as resolve7 } from "node:path";
|
|
25525
25747
|
|
|
25526
25748
|
// src/core/sandbox/win-build.ts
|
|
25527
25749
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -25567,7 +25789,6 @@ var ctxExecuteSchema = external_exports.object({
|
|
|
25567
25789
|
background: external_exports.boolean().optional(),
|
|
25568
25790
|
summary: external_exports.boolean().optional()
|
|
25569
25791
|
}, { error: unknownField }).strict();
|
|
25570
|
-
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
25571
25792
|
var SCRIPT_EXT = Object.freeze({
|
|
25572
25793
|
javascript: ".js",
|
|
25573
25794
|
typescript: ".ts",
|
|
@@ -25586,7 +25807,7 @@ var LAUNCHER = [
|
|
|
25586
25807
|
'const { rmSync } = require("node:fs");',
|
|
25587
25808
|
"const [mode, dir, ...argv] = process.argv.slice(1);",
|
|
25588
25809
|
'if (mode === "start") {',
|
|
25589
|
-
' 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 });',
|
|
25590
25811
|
" b.unref();",
|
|
25591
25812
|
" process.stdout.write(String(b.pid));",
|
|
25592
25813
|
"} else {",
|
|
@@ -25669,7 +25890,7 @@ async function handler3(raw, ctx) {
|
|
|
25669
25890
|
const cwd = ctx.project.worktree;
|
|
25670
25891
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
25671
25892
|
if (input.file !== void 0) {
|
|
25672
|
-
const abs =
|
|
25893
|
+
const abs = resolve7(cwd, input.file);
|
|
25673
25894
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
25674
25895
|
if (bad !== null) return fail5(bad);
|
|
25675
25896
|
extra.CTX_FILE = abs;
|
|
@@ -25686,13 +25907,14 @@ async function handler3(raw, ctx) {
|
|
|
25686
25907
|
if (takesDashC(input.language, runtime)) {
|
|
25687
25908
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
25688
25909
|
} else {
|
|
25689
|
-
tmpDir = mkdtempSync2(
|
|
25690
|
-
const file2 =
|
|
25910
|
+
tmpDir = mkdtempSync2(join19(tmpdir3(), TMP_PREFIX));
|
|
25911
|
+
const file2 = join19(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25691
25912
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
25692
25913
|
argv = scriptArgv(input.language, runtime, file2);
|
|
25693
25914
|
}
|
|
25694
25915
|
if (input.background === true) {
|
|
25695
|
-
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 });
|
|
25696
25918
|
const pid = r2.stdout.toString("utf8");
|
|
25697
25919
|
if (r2.exitCode !== 0 || pid === "" || !Number.isSafeInteger(Number(pid))) return fail5(spawnFailed(argv[0], cwd), journal);
|
|
25698
25920
|
handedOff = true;
|
|
@@ -25723,11 +25945,11 @@ var ctxExecute = {
|
|
|
25723
25945
|
|
|
25724
25946
|
// src/core/tools/index.ts
|
|
25725
25947
|
import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
|
|
25726
|
-
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";
|
|
25727
25949
|
|
|
25728
25950
|
// src/core/index/walk.ts
|
|
25729
25951
|
import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
25730
|
-
import { join as
|
|
25952
|
+
import { join as join20 } from "node:path";
|
|
25731
25953
|
var GITIGNORE = ".gitignore";
|
|
25732
25954
|
var GIT_DIR = ".git";
|
|
25733
25955
|
function walkDir(root, containmentRoot) {
|
|
@@ -25736,7 +25958,7 @@ function walkDir(root, containmentRoot) {
|
|
|
25736
25958
|
const found = [];
|
|
25737
25959
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
25738
25960
|
found.sort(compareFound);
|
|
25739
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25961
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join20(...f.dir, f.name) }));
|
|
25740
25962
|
}
|
|
25741
25963
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
25742
25964
|
let entries;
|
|
@@ -25745,10 +25967,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25745
25967
|
} catch {
|
|
25746
25968
|
return;
|
|
25747
25969
|
}
|
|
25748
|
-
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;
|
|
25749
25971
|
for (const e of entries) {
|
|
25750
25972
|
if (e.name === GIT_DIR) continue;
|
|
25751
|
-
const path8 =
|
|
25973
|
+
const path8 = join20(abs, e.name);
|
|
25752
25974
|
let isDir = e.isDirectory();
|
|
25753
25975
|
let isFile = e.isFile();
|
|
25754
25976
|
let target = path8;
|
|
@@ -25882,11 +26104,24 @@ var PRIVATE_RANGES = [
|
|
|
25882
26104
|
["172.16.0.0", 12, "ipv4"],
|
|
25883
26105
|
["192.168.0.0", 16, "ipv4"],
|
|
25884
26106
|
["169.254.0.0", 16, "ipv4"],
|
|
25885
|
-
["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
|
|
25886
26115
|
["::1", 128, "ipv6"],
|
|
25887
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)
|
|
25888
26121
|
["fc00::", 7, "ipv6"],
|
|
25889
|
-
["fe80::", 10, "ipv6"]
|
|
26122
|
+
["fe80::", 10, "ipv6"],
|
|
26123
|
+
["fec0::", 10, "ipv6"]
|
|
26124
|
+
// D-SSRF-RANGES-1: site-local (RFC 3879)
|
|
25890
26125
|
];
|
|
25891
26126
|
var BLOCKED = new BlockList();
|
|
25892
26127
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
@@ -25939,9 +26174,41 @@ function pickProxy(u) {
|
|
|
25939
26174
|
const auth = p.username === "" ? void 0 : "Basic " + Buffer.from(decodeURIComponent(p.username) + ":" + decodeURIComponent(p.password)).toString("base64");
|
|
25940
26175
|
return { url: p, auth };
|
|
25941
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
|
+
}
|
|
25942
26208
|
function checkAddress(hostname2, address) {
|
|
25943
26209
|
const family = isIP(address);
|
|
25944
|
-
|
|
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")) {
|
|
25945
26212
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
25946
26213
|
}
|
|
25947
26214
|
}
|
|
@@ -25965,18 +26232,18 @@ function request(u, conn, proxy, signal) {
|
|
|
25965
26232
|
const host = bare(u.hostname);
|
|
25966
26233
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
25967
26234
|
const path8 = u.pathname + u.search;
|
|
25968
|
-
return new Promise((
|
|
26235
|
+
return new Promise((resolve9, reject) => {
|
|
25969
26236
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
25970
26237
|
if (proxy === void 0) {
|
|
25971
26238
|
const mod = u.protocol === "https:" ? https : http;
|
|
25972
26239
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
25973
|
-
req.on("response",
|
|
26240
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25974
26241
|
return;
|
|
25975
26242
|
}
|
|
25976
26243
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
25977
26244
|
if (u.protocol === "http:") {
|
|
25978
26245
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
25979
|
-
req.on("response",
|
|
26246
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25980
26247
|
return;
|
|
25981
26248
|
}
|
|
25982
26249
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -25996,16 +26263,16 @@ function request(u, conn, proxy, signal) {
|
|
|
25996
26263
|
headers: { host: u.host },
|
|
25997
26264
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
25998
26265
|
});
|
|
25999
|
-
req.on("response",
|
|
26266
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
26000
26267
|
});
|
|
26001
26268
|
tunnel.end();
|
|
26002
26269
|
});
|
|
26003
26270
|
}
|
|
26004
26271
|
function readBody(res) {
|
|
26005
|
-
return new Promise((
|
|
26272
|
+
return new Promise((resolve9, reject) => {
|
|
26006
26273
|
const parts = [];
|
|
26007
26274
|
res.on("data", (b) => parts.push(b));
|
|
26008
|
-
res.on("end", () =>
|
|
26275
|
+
res.on("end", () => resolve9(Buffer.concat(parts)));
|
|
26009
26276
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
26010
26277
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
26011
26278
|
});
|
|
@@ -28676,7 +28943,7 @@ var DomHandler = class {
|
|
|
28676
28943
|
var dist_exports2 = {};
|
|
28677
28944
|
__export(dist_exports2, {
|
|
28678
28945
|
DocumentPosition: () => DocumentPosition,
|
|
28679
|
-
append: () =>
|
|
28946
|
+
append: () => append2,
|
|
28680
28947
|
appendChild: () => appendChild,
|
|
28681
28948
|
compareDocumentPosition: () => compareDocumentPosition,
|
|
28682
28949
|
existsOne: () => existsOne,
|
|
@@ -29267,11 +29534,11 @@ function compareDocumentPosition(nodeA, nodeB) {
|
|
|
29267
29534
|
function uniqueSort(nodes) {
|
|
29268
29535
|
nodes = nodes.filter((node, index, array2) => !array2.includes(node, index + 1));
|
|
29269
29536
|
nodes.sort((a, b) => {
|
|
29270
|
-
const
|
|
29271
|
-
if (
|
|
29537
|
+
const relative6 = compareDocumentPosition(a, b);
|
|
29538
|
+
if (relative6 & DocumentPosition.PRECEDING) {
|
|
29272
29539
|
return -1;
|
|
29273
29540
|
}
|
|
29274
|
-
if (
|
|
29541
|
+
if (relative6 & DocumentPosition.FOLLOWING) {
|
|
29275
29542
|
return 1;
|
|
29276
29543
|
}
|
|
29277
29544
|
return 0;
|
|
@@ -29328,7 +29595,7 @@ function appendChild(parent, child) {
|
|
|
29328
29595
|
child.prev = null;
|
|
29329
29596
|
}
|
|
29330
29597
|
}
|
|
29331
|
-
function
|
|
29598
|
+
function append2(element2, next) {
|
|
29332
29599
|
removeElement(next);
|
|
29333
29600
|
const { parent } = element2;
|
|
29334
29601
|
const currentNext = element2.next;
|
|
@@ -29840,10 +30107,10 @@ function htmlToReadable(html, baseUrl) {
|
|
|
29840
30107
|
const st = { w: new Writer(), base, sawH1: false };
|
|
29841
30108
|
for (const n of contentRoot(doc.children)) walk2(st, n);
|
|
29842
30109
|
const body = st.w.result();
|
|
29843
|
-
const
|
|
29844
|
-
const text = !st.sawH1 && title !== "" &&
|
|
29845
|
-
const sparse =
|
|
29846
|
-
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 };
|
|
29847
30114
|
}
|
|
29848
30115
|
|
|
29849
30116
|
// src/core/tools/index.ts
|
|
@@ -29883,13 +30150,13 @@ function missingOrOutside(given, abs, root) {
|
|
|
29883
30150
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29884
30151
|
}
|
|
29885
30152
|
function pathItems(input, project) {
|
|
29886
|
-
const abs =
|
|
30153
|
+
const abs = resolve8(project.worktree, input.path);
|
|
29887
30154
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
29888
|
-
const base =
|
|
30155
|
+
const base = relative5(project.worktree, abs);
|
|
29889
30156
|
if (statSync8(abs).isDirectory()) {
|
|
29890
30157
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
29891
30158
|
sourceKind: "path",
|
|
29892
|
-
label: pathLabel(
|
|
30159
|
+
label: pathLabel(join21(base, f.relPath)),
|
|
29893
30160
|
kind: kindOfPath(f.relPath),
|
|
29894
30161
|
read: () => readUtf8(f.absPath)
|
|
29895
30162
|
}));
|
|
@@ -30428,13 +30695,9 @@ var ctxStats = Object.freeze({
|
|
|
30428
30695
|
handler: handler7
|
|
30429
30696
|
});
|
|
30430
30697
|
|
|
30431
|
-
// src/core/tools/upgrade.ts
|
|
30432
|
-
import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
|
|
30433
|
-
import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
|
|
30434
|
-
|
|
30435
30698
|
// src/core/ops/host-write.ts
|
|
30436
30699
|
import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30437
|
-
import { dirname as dirname12, join as
|
|
30700
|
+
import { dirname as dirname12, join as join22 } from "node:path";
|
|
30438
30701
|
function defaultWrite(file2, text) {
|
|
30439
30702
|
writeFileSync5(file2, text, "utf8");
|
|
30440
30703
|
}
|
|
@@ -30443,14 +30706,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
30443
30706
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
30444
30707
|
switch (agent) {
|
|
30445
30708
|
case "opencode":
|
|
30446
|
-
return
|
|
30709
|
+
return join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
30447
30710
|
// D-WIN-OPENCODE-DIR-1
|
|
30448
30711
|
case "pi":
|
|
30449
|
-
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
|
|
30450
30716
|
case "copilot-cli":
|
|
30451
30717
|
return null;
|
|
30452
30718
|
default:
|
|
30453
|
-
return
|
|
30719
|
+
return join22(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
30454
30720
|
}
|
|
30455
30721
|
}
|
|
30456
30722
|
function cell3(value) {
|
|
@@ -30499,96 +30765,16 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30499
30765
|
return result.edits.map((e) => toRow(current.path, e));
|
|
30500
30766
|
}
|
|
30501
30767
|
|
|
30502
|
-
// src/core/ops/plugin-swap.ts
|
|
30503
|
-
import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
30504
|
-
import { basename as basename6, join as join22, win32 as win322 } from "node:path";
|
|
30505
|
-
function linkTarget(path8, win) {
|
|
30506
|
-
if (!isLink(path8)) return null;
|
|
30507
|
-
const target = readlinkSync(path8);
|
|
30508
|
-
return win ? win322.basename(target) : target;
|
|
30509
|
-
}
|
|
30510
|
-
function isLink(path8) {
|
|
30511
|
-
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
30512
|
-
}
|
|
30513
|
-
function generations(agentDir) {
|
|
30514
|
-
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();
|
|
30515
|
-
}
|
|
30516
|
-
function settleLinks(link, tmp, old, opts) {
|
|
30517
|
-
if (isLink(tmp)) unlinkSync2(tmp);
|
|
30518
|
-
if (!isLink(old)) return;
|
|
30519
|
-
if (isLink(link)) unlinkSync2(old);
|
|
30520
|
-
else renameWithRetry(old, link, opts);
|
|
30521
|
-
}
|
|
30522
|
-
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
30523
|
-
const next = join22(agentDir, sha);
|
|
30524
|
-
if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
|
|
30525
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
30526
|
-
}
|
|
30527
|
-
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
30528
|
-
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
30529
|
-
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
30530
|
-
settleLinks(link, tmp, old, opts);
|
|
30531
|
-
const win = (opts.platform ?? process.platform) === "win32";
|
|
30532
|
-
const before = linkTarget(link, win);
|
|
30533
|
-
if (before === sha) return { current: next, previous: null, removed: [] };
|
|
30534
|
-
const symlink = opts.symlink ?? symlinkSync;
|
|
30535
|
-
if (win) symlink(next, tmp, PLUGIN_LINK_TYPE_WIN32);
|
|
30536
|
-
else symlink(sha, tmp, PLUGIN_LINK_TYPE);
|
|
30537
|
-
if (before !== null) renameWithRetry(link, old, opts);
|
|
30538
|
-
renameWithRetry(tmp, link, opts);
|
|
30539
|
-
if (before !== null) unlinkSync2(old);
|
|
30540
|
-
const keep = /* @__PURE__ */ new Set([sha]);
|
|
30541
|
-
if (before !== null) keep.add(before);
|
|
30542
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
|
|
30543
|
-
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
30544
|
-
const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
|
|
30545
|
-
return { current: next, previous, removed };
|
|
30546
|
-
}
|
|
30547
|
-
|
|
30548
|
-
// src/core/ops/release-fetch.ts
|
|
30549
|
-
import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
30550
|
-
import { join as join23 } from "node:path";
|
|
30551
|
-
function failed(r) {
|
|
30552
|
-
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30553
|
-
const status = r.killed ?? String(r.exitCode);
|
|
30554
|
-
return new CtxError("FETCH_FAILED", { code: GIT_EXIT_LABEL + status + UPGRADE_AREA_KEY_SEP + r.stderr.toString().trim() });
|
|
30555
|
-
}
|
|
30556
|
-
async function git2(bin, args, cwd, env, signal) {
|
|
30557
|
-
const r = await runProcess([bin, ...args], { cwd, env, signal, timeoutMs: UPGRADE_GIT_TIMEOUT_MS });
|
|
30558
|
-
if (r.exitCode !== 0 || r.killed !== null) throw failed(r);
|
|
30559
|
-
return r.stdout.toString().trim();
|
|
30560
|
-
}
|
|
30561
|
-
async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
30562
|
-
const agentDir = join23(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
30563
|
-
mkdirSync8(agentDir, { recursive: true });
|
|
30564
|
-
const fetchDir = join23(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
30565
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30566
|
-
const gitBin = findRuntime(GIT_BIN, env);
|
|
30567
|
-
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30568
|
-
const childEnv = buildChildEnv(env, { ...GIT_NO_PROMPT_ENV, ...GIT_NO_CRLF_ENV });
|
|
30569
|
-
try {
|
|
30570
|
-
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
30571
|
-
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
30572
|
-
const dir = join23(agentDir, sha);
|
|
30573
|
-
if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
30574
|
-
else renameWithRetry(fetchDir, dir, opts);
|
|
30575
|
-
return { sha, dir };
|
|
30576
|
-
} catch (e) {
|
|
30577
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30578
|
-
throw e;
|
|
30579
|
-
}
|
|
30580
|
-
}
|
|
30581
|
-
|
|
30582
30768
|
// src/core/ops/uninstall.ts
|
|
30583
|
-
import { existsSync as
|
|
30584
|
-
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";
|
|
30585
30771
|
function row2(area, before, after) {
|
|
30586
30772
|
return { area, before, after };
|
|
30587
30773
|
}
|
|
30588
30774
|
function stopServers(configDir, projectKey) {
|
|
30589
30775
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
30590
|
-
const dir =
|
|
30591
|
-
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");
|
|
30592
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 };
|
|
30593
30779
|
}
|
|
30594
30780
|
function rootOrNull(adapter, env) {
|
|
@@ -30606,16 +30792,16 @@ function removeCache(adapter, env, configDir) {
|
|
|
30606
30792
|
const root = rootOrNull(adapter, env);
|
|
30607
30793
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30608
30794
|
if (adapter.installMode === "marketplace") {
|
|
30609
|
-
const cache =
|
|
30795
|
+
const cache = join23(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
30610
30796
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
30611
30797
|
}
|
|
30612
|
-
|
|
30798
|
+
rmSync6(root, { recursive: true, force: true });
|
|
30613
30799
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
30614
30800
|
}
|
|
30615
30801
|
case "plugin": {
|
|
30616
|
-
const agentDir =
|
|
30617
|
-
if (!
|
|
30618
|
-
|
|
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 });
|
|
30619
30805
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30620
30806
|
}
|
|
30621
30807
|
case "config-mcp":
|
|
@@ -30630,7 +30816,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
30630
30816
|
function isObj3(v) {
|
|
30631
30817
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30632
30818
|
}
|
|
30633
|
-
function
|
|
30819
|
+
function piSource2(entry) {
|
|
30634
30820
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
30635
30821
|
}
|
|
30636
30822
|
function ownEntries2(agent, env) {
|
|
@@ -30659,7 +30845,7 @@ function ownEntries2(agent, env) {
|
|
|
30659
30845
|
}
|
|
30660
30846
|
if (agent === "opencode") {
|
|
30661
30847
|
return [{
|
|
30662
|
-
file:
|
|
30848
|
+
file: join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
30663
30849
|
// D-WIN-OPENCODE-DIR-1
|
|
30664
30850
|
key: OPENCODE_PLUGIN_KEY,
|
|
30665
30851
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -30670,11 +30856,11 @@ function ownEntries2(agent, env) {
|
|
|
30670
30856
|
if (agent === "pi") {
|
|
30671
30857
|
const agentDir = piAgentDirOf(env, home);
|
|
30672
30858
|
return [{
|
|
30673
|
-
file:
|
|
30859
|
+
file: join23(agentDir, SETTINGS_FILE),
|
|
30674
30860
|
key: PI_PACKAGES_KEY,
|
|
30675
30861
|
shown: PI_PACKAGES_KEY,
|
|
30676
|
-
has: (v) => Array.isArray(v) && v.some((x) =>
|
|
30677
|
-
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)
|
|
30678
30864
|
}];
|
|
30679
30865
|
}
|
|
30680
30866
|
return [];
|
|
@@ -30692,12 +30878,12 @@ function removeOwnEntries(agent, env) {
|
|
|
30692
30878
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
30693
30879
|
}
|
|
30694
30880
|
function removeProjectData(configDir, projectKey) {
|
|
30695
|
-
const projects =
|
|
30696
|
-
const dir =
|
|
30697
|
-
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);
|
|
30698
30884
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30699
|
-
for (const name of
|
|
30700
|
-
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 });
|
|
30701
30887
|
}
|
|
30702
30888
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
30703
30889
|
}
|
|
@@ -30705,25 +30891,32 @@ function runUninstall(input) {
|
|
|
30705
30891
|
const configDir = resolveConfigDir(input.env);
|
|
30706
30892
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
30707
30893
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
30708
|
-
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));
|
|
30709
30895
|
return { rows, stopped: stop.stopped };
|
|
30710
30896
|
}
|
|
30711
30897
|
|
|
30712
30898
|
// src/core/ops/v1-remove.ts
|
|
30713
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30899
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync17, rmSync as rmSync7 } from "node:fs";
|
|
30714
30900
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30715
30901
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30716
30902
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
30717
30903
|
function moveAside(target, undo) {
|
|
30718
30904
|
const trash = target + UPGRADE_TRASH_SUFFIX;
|
|
30719
|
-
|
|
30905
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30720
30906
|
renameWithRetry(target, trash);
|
|
30721
30907
|
undo.push({ trash, target });
|
|
30722
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
|
+
}
|
|
30723
30916
|
function keepOriginal(file2, kept, undo) {
|
|
30724
30917
|
if (kept.has(file2)) return;
|
|
30725
30918
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30726
|
-
|
|
30919
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30727
30920
|
copyFileSync2(file2, trash);
|
|
30728
30921
|
kept.add(file2);
|
|
30729
30922
|
undo.push({ trash, target: file2 });
|
|
@@ -30783,7 +30976,7 @@ function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
|
30783
30976
|
writeHostConfigEdit(file2, { agent, text, format: "jsonc", path: file2, layout }, patch);
|
|
30784
30977
|
return hit;
|
|
30785
30978
|
}
|
|
30786
|
-
function removeV1(agent, findings) {
|
|
30979
|
+
function removeV1(agent, findings, project) {
|
|
30787
30980
|
const undo = [];
|
|
30788
30981
|
const kept = /* @__PURE__ */ new Set();
|
|
30789
30982
|
const done = /* @__PURE__ */ new Map();
|
|
@@ -30791,14 +30984,16 @@ function removeV1(agent, findings) {
|
|
|
30791
30984
|
for (const f of findings) {
|
|
30792
30985
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30793
30986
|
else if (f.path === "") {
|
|
30794
|
-
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)) {
|
|
30795
30990
|
moveAside(f.file, undo);
|
|
30796
30991
|
done.set(f, UPGRADE_REMOVED);
|
|
30797
30992
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30798
30993
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30799
30994
|
}
|
|
30800
30995
|
for (const [file2, list4] of entries) {
|
|
30801
|
-
if (!
|
|
30996
|
+
if (!existsSync20(file2)) {
|
|
30802
30997
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30803
30998
|
continue;
|
|
30804
30999
|
}
|
|
@@ -30827,64 +31022,18 @@ function removeV1(agent, findings) {
|
|
|
30827
31022
|
return {
|
|
30828
31023
|
rows: findings.map((f) => row3(f, done.get(f) ?? UPGRADE_NOT_FOUND)),
|
|
30829
31024
|
commit() {
|
|
30830
|
-
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 });
|
|
30831
31026
|
},
|
|
30832
31027
|
rollback() {
|
|
30833
31028
|
for (const u of undo.splice(0).reverse()) {
|
|
30834
|
-
if (!
|
|
30835
|
-
|
|
31029
|
+
if (!existsSync20(u.trash)) continue;
|
|
31030
|
+
rmSync7(u.target, { recursive: true, force: true });
|
|
30836
31031
|
renameWithRetry(u.trash, u.target);
|
|
30837
31032
|
}
|
|
30838
31033
|
}
|
|
30839
31034
|
};
|
|
30840
31035
|
}
|
|
30841
31036
|
|
|
30842
|
-
// src/core/ops/verify-sums.ts
|
|
30843
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
30844
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
|
|
30845
|
-
import { join as join25 } from "node:path";
|
|
30846
|
-
function mismatch() {
|
|
30847
|
-
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
30848
|
-
}
|
|
30849
|
-
function parseSums(text) {
|
|
30850
|
-
const lines = text.split(SUMS_LINE_END);
|
|
30851
|
-
if (lines[lines.length - 1] === "") lines.pop();
|
|
30852
|
-
const sums = /* @__PURE__ */ new Map();
|
|
30853
|
-
for (const line of lines) {
|
|
30854
|
-
const at2 = line.indexOf(SUMS_LINE_SEP);
|
|
30855
|
-
if (at2 < 0) throw mismatch();
|
|
30856
|
-
const rel = line.slice(at2 + SUMS_LINE_SEP.length);
|
|
30857
|
-
if (rel === "" || sums.has(rel)) throw mismatch();
|
|
30858
|
-
sums.set(rel, line.slice(0, at2));
|
|
30859
|
-
}
|
|
30860
|
-
return sums;
|
|
30861
|
-
}
|
|
30862
|
-
function walk3(dir, prefix, out) {
|
|
30863
|
-
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
30864
|
-
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
30865
|
-
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
30866
|
-
const abs = join25(dir, entry.name);
|
|
30867
|
-
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
30868
|
-
else if (entry.isFile()) out.set(rel, abs);
|
|
30869
|
-
else throw mismatch();
|
|
30870
|
-
}
|
|
30871
|
-
}
|
|
30872
|
-
function verifySums(dir) {
|
|
30873
|
-
const sumsPath = join25(dir, RELEASE_SUMS_FILE);
|
|
30874
|
-
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30875
|
-
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30876
|
-
const sums = parseSums(readFileSync18(sumsPath, "utf8"));
|
|
30877
|
-
const files = /* @__PURE__ */ new Map();
|
|
30878
|
-
walk3(dir, "", files);
|
|
30879
|
-
if (files.size !== sums.size) throw mismatch();
|
|
30880
|
-
for (const [rel, abs] of files) {
|
|
30881
|
-
const want = sums.get(rel);
|
|
30882
|
-
if (want === void 0) throw mismatch();
|
|
30883
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
|
|
30884
|
-
if (got !== want) throw mismatch();
|
|
30885
|
-
}
|
|
30886
|
-
}
|
|
30887
|
-
|
|
30888
31037
|
// src/core/tools/upgrade.ts
|
|
30889
31038
|
var ctxUpgradeSchema = external_exports.object({
|
|
30890
31039
|
mode: external_exports.enum(UPGRADE_MODES).optional(),
|
|
@@ -30907,41 +31056,20 @@ function pluginRootRow(adapter, env) {
|
|
|
30907
31056
|
}
|
|
30908
31057
|
return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
|
|
30909
31058
|
}
|
|
30910
|
-
function isCurrent(agentDir, dir) {
|
|
30911
|
-
const link = join26(agentDir, PLUGIN_CURRENT_LINK);
|
|
30912
|
-
return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
30913
|
-
}
|
|
30914
|
-
async function checkout(adapter, deps) {
|
|
30915
|
-
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
30916
|
-
const agentDir = dirname13(fetched.dir);
|
|
30917
|
-
try {
|
|
30918
|
-
verifySums(fetched.dir);
|
|
30919
|
-
} catch (err) {
|
|
30920
|
-
if (!isCurrent(agentDir, fetched.dir)) rmSync10(fetched.dir, { recursive: true, force: true });
|
|
30921
|
-
throw err;
|
|
30922
|
-
}
|
|
30923
|
-
const swap = swapPluginCurrent(agentDir, fetched.sha);
|
|
30924
|
-
const rows = [row4(UPGRADE_CHECKOUT_AREA, swap.previous ?? "", swap.current)];
|
|
30925
|
-
for (const dir of swap.removed) rows.push(row4(UPGRADE_CACHE_AREA, dir, UPGRADE_REMOVED));
|
|
30926
|
-
return { rows, agentDir, swap };
|
|
30927
|
-
}
|
|
30928
31059
|
function hostRow(adapter) {
|
|
30929
|
-
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]
|
|
31060
|
+
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]);
|
|
30930
31061
|
}
|
|
30931
|
-
|
|
30932
|
-
let done = null;
|
|
31062
|
+
function upgrade(adapter, deps, home) {
|
|
30933
31063
|
let removal = null;
|
|
30934
31064
|
try {
|
|
30935
|
-
const step4 = UPGRADE_GIT_CHECKOUT_AGENTS.includes(adapter.id) ? (done = await checkout(adapter, deps)).rows : [hostRow(adapter)];
|
|
30936
31065
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
30937
|
-
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) });
|
|
30938
|
-
removal = removeV1(adapter.id, findings);
|
|
30939
|
-
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];
|
|
30940
31069
|
removal.commit();
|
|
30941
31070
|
return rows;
|
|
30942
31071
|
} catch (err) {
|
|
30943
31072
|
removal?.rollback();
|
|
30944
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename7(done.swap.previous));
|
|
30945
31073
|
throw err;
|
|
30946
31074
|
}
|
|
30947
31075
|
}
|
|
@@ -30961,12 +31089,12 @@ async function runUpgrade(input, deps) {
|
|
|
30961
31089
|
const result = runUninstall({ adapter, project: deps.project, env: deps.env, confirmDelete: input.confirmDelete === true });
|
|
30962
31090
|
rows.push(...result.rows);
|
|
30963
31091
|
} else {
|
|
30964
|
-
rows.push(...
|
|
31092
|
+
rows.push(...upgrade(adapter, deps, home));
|
|
30965
31093
|
}
|
|
30966
31094
|
return { text: renderTable(rows) + "\n\n" + UPGRADE_RESTART_LINE, isError: false, sandboxBytes: 0 };
|
|
30967
31095
|
}
|
|
30968
31096
|
async function handler8(input, ctx) {
|
|
30969
|
-
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 });
|
|
30970
31098
|
}
|
|
30971
31099
|
var ctxUpgrade = Object.freeze({
|
|
30972
31100
|
name: "ctx_upgrade",
|
|
@@ -31164,9 +31292,9 @@ async function setup(ctx) {
|
|
|
31164
31292
|
await hooks["tool.execute.before"]({ tool: i.tool, sessionID: i.sessionID, callID: i.id }, { args: i.input });
|
|
31165
31293
|
});
|
|
31166
31294
|
await ctx.tool.hook("execute.after", async (i) => {
|
|
31167
|
-
const
|
|
31168
|
-
const output =
|
|
31169
|
-
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 });
|
|
31170
31298
|
});
|
|
31171
31299
|
await ctx.session.hook("prompt", async (p) => {
|
|
31172
31300
|
await hooks["chat.message"]({ sessionID: p.sessionID }, { parts: [{ type: "text", text: p.prompt?.text ?? "" }] });
|