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/pi/index.js
CHANGED
|
@@ -11350,6 +11350,7 @@ var GIT_COMMONDIR_FILE = "commondir";
|
|
|
11350
11350
|
var GIT_HEAD_FILE = "HEAD";
|
|
11351
11351
|
var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
|
|
11352
11352
|
var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
|
|
11353
|
+
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
11353
11354
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
11354
11355
|
var FETCH_MAX_HOPS = 5;
|
|
11355
11356
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
@@ -11361,6 +11362,7 @@ var RUN_SESSION_PREFIX = "mcp:";
|
|
|
11361
11362
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
11362
11363
|
var NODE_MIN = "24.15.0";
|
|
11363
11364
|
var DATA_ROOT = "~/.context-mode";
|
|
11365
|
+
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
11364
11366
|
var INTERNAL_ERROR_LINE = "Internal error. Fix: run ctx_doctor.";
|
|
11365
11367
|
var REQUIRE_SECURITY_ENV = "CONTEXT_MODE_REQUIRE_SECURITY";
|
|
11366
11368
|
var HOST_CONFIG_DIR_NAME = ".claude";
|
|
@@ -11463,7 +11465,8 @@ var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
|
11463
11465
|
var SED_COMMAND = "sed";
|
|
11464
11466
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
11465
11467
|
var JQ_COMMAND = "jq";
|
|
11466
|
-
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path"]);
|
|
11468
|
+
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
|
|
11469
|
+
var READ_PATH_LIST_KEY = "filePaths";
|
|
11467
11470
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
11468
11471
|
var SHELL_TOOL = "Bash";
|
|
11469
11472
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
@@ -11479,6 +11482,7 @@ var RECALL_MIN_SCORE = 5;
|
|
|
11479
11482
|
var RECALL_MAX_ROWS = 340;
|
|
11480
11483
|
var COMPACTED_META_PREFIX = "compacted:";
|
|
11481
11484
|
var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
|
|
11485
|
+
var UNITS_ANCESTOR_FACTOR = 8;
|
|
11482
11486
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
11483
11487
|
var RECALL_SEEN_META_PREFIX = "recall_seen:";
|
|
11484
11488
|
var RECALL_OPEN_TAG = "<context_mode_recall>";
|
|
@@ -11572,8 +11576,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
11572
11576
|
var DECISION_OPTION_KEY = "option";
|
|
11573
11577
|
var DECISION_LABEL_JOIN = " | ";
|
|
11574
11578
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11575
|
-
var
|
|
11576
|
-
var BUNDLE_SHA = true ? "83f2da691359eaaf61f7baba841dea1942d3ccc1" : void 0;
|
|
11579
|
+
var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
|
|
11577
11580
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11578
11581
|
var DOCTOR_LABEL = Object.freeze({
|
|
11579
11582
|
D1: "version",
|
|
@@ -11717,7 +11720,6 @@ function D9_INDEX_DETAIL(sources, chunks) {
|
|
|
11717
11720
|
var PLUGIN_CACHE_DIR_NAME = "cache";
|
|
11718
11721
|
var DATA_PLUGINS_DIR_NAME = "plugins";
|
|
11719
11722
|
var PLUGIN_CURRENT_LINK = "current";
|
|
11720
|
-
var RELEASE_SUMS_FILE = "SHA256SUMS";
|
|
11721
11723
|
var EXTENSIONS_DIR_NAME = "extensions";
|
|
11722
11724
|
var AGENT_HOME_DIR = Object.freeze({
|
|
11723
11725
|
"claude-code": [".claude"],
|
|
@@ -11740,7 +11742,6 @@ var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
|
11740
11742
|
var UPGRADE_TABLE_HEADER = "| Area | Before | After |";
|
|
11741
11743
|
var UPGRADE_TABLE_RULE = "|---|---|---|";
|
|
11742
11744
|
var UPGRADE_PLUGIN_ROOT_AREA = "plugin root";
|
|
11743
|
-
var UPGRADE_CHECKOUT_AREA = "plugin checkout";
|
|
11744
11745
|
var UPGRADE_SERVER_AREA = "server";
|
|
11745
11746
|
var UPGRADE_SERVER_RUNNING = "running";
|
|
11746
11747
|
var UPGRADE_SERVER_STOPPED = "stopped after this reply";
|
|
@@ -11751,25 +11752,21 @@ var UPGRADE_REPORT_ONLY = "report only: remove it by hand if you no longer use i
|
|
|
11751
11752
|
var UPGRADE_STOP_DELAY_MS = 200;
|
|
11752
11753
|
var UPGRADE_AREA_KEY_SEP = ": ";
|
|
11753
11754
|
var V1_KEY_PATH_SEP = ".";
|
|
11754
|
-
var UPGRADE_GIT_TIMEOUT_MS = 12e4;
|
|
11755
11755
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
11756
11756
|
var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
|
|
11757
|
-
var UPGRADE_FETCH_DIR_PREFIX = ".fetch-";
|
|
11758
|
-
var SUMS_LINE_SEP = " ";
|
|
11759
|
-
var SUMS_HASH_ALGORITHM = "sha256";
|
|
11760
|
-
var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
|
|
11761
|
-
var UPGRADE_HOST_MANUAL = "update with the host's own install command, then restart";
|
|
11762
11757
|
var UPGRADE_CONFIG_AREA = "host config";
|
|
11763
11758
|
var UPGRADE_OWN_ENTRY = "context-mode entry";
|
|
11764
11759
|
var UPGRADE_CACHE_BY_HAND = "remove the release dir by hand: its place is your choice";
|
|
11765
11760
|
var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
|
|
11766
11761
|
var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
|
|
11767
|
-
var GIT_NOT_STARTED = "git did not start";
|
|
11768
11762
|
var GIT_BIN = "git";
|
|
11769
11763
|
var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
|
|
11770
11764
|
var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
|
|
11771
|
-
var GIT_EXIT_LABEL = "git exit ";
|
|
11772
11765
|
var UPGRADE_TRASH_SUFFIX = ".ctx-upgrade-removing";
|
|
11766
|
+
var UPGRADE_ASIDE_SUFFIX = ".ctx-v1-old";
|
|
11767
|
+
var UPGRADE_MOVED_ASIDE = "moved aside to ";
|
|
11768
|
+
var CLAUDE_TOOL_RESULTS_DIR_NAME = "tool-results";
|
|
11769
|
+
var PERSISTED_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
|
|
11773
11770
|
var TABLE_ROW_START = "| ";
|
|
11774
11771
|
var TABLE_CELL_SEP = " | ";
|
|
11775
11772
|
var TABLE_ROW_END = " |";
|
|
@@ -11781,7 +11778,6 @@ var OPS_SPLIT_FILES = Object.freeze([
|
|
|
11781
11778
|
"doctor-hook.ts",
|
|
11782
11779
|
"doctor-db.ts",
|
|
11783
11780
|
"doctor-heal.ts",
|
|
11784
|
-
"release-fetch.ts",
|
|
11785
11781
|
"verify-sums.ts",
|
|
11786
11782
|
"plugin-swap.ts",
|
|
11787
11783
|
"host-write.ts",
|
|
@@ -11857,19 +11853,19 @@ function D11_PASS_DETAIL(shell, win) {
|
|
|
11857
11853
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
11858
11854
|
var HEAL_TMP_SUFFIX = ".heal";
|
|
11859
11855
|
var HEAL_TS_SEP = ".";
|
|
11860
|
-
var SUMS_LINE_END = "\n";
|
|
11861
|
-
var HASH_ENCODING = "hex";
|
|
11862
|
-
var PLUGIN_LINK_TMP_SUFFIX = ".swap";
|
|
11863
|
-
var PLUGIN_LINK_OLD_SUFFIX = ".old";
|
|
11864
|
-
var PLUGIN_LINK_TYPE = "dir";
|
|
11865
|
-
var PLUGIN_LINK_TYPE_WIN32 = "junction";
|
|
11866
11856
|
var OWNER_STOP_EXT = ".stop";
|
|
11867
11857
|
var UPGRADE_DATA_DELETED = "user data deleted";
|
|
11868
11858
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
11869
11859
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
11870
|
-
codex: "
|
|
11871
|
-
gemini: "gemini extensions
|
|
11872
|
-
qwen: "qwen extensions
|
|
11860
|
+
codex: "codex plugin marketplace upgrade context-mode",
|
|
11861
|
+
gemini: "gemini extensions update context-mode",
|
|
11862
|
+
qwen: "qwen extensions update context-mode",
|
|
11863
|
+
pi: "pi update --extensions",
|
|
11864
|
+
opencode: "opencode plugin update",
|
|
11865
|
+
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
11866
|
+
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
11867
|
+
kiro: "npm i -g context-mode && context-mode setup --agents kiro",
|
|
11868
|
+
zcode: "npm i -g context-mode && context-mode setup --agents zcode"
|
|
11873
11869
|
});
|
|
11874
11870
|
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
11875
11871
|
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
@@ -11911,6 +11907,7 @@ var HOOKS_JSON_FILE = "hooks.json";
|
|
|
11911
11907
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
11912
11908
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
11913
11909
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
11910
|
+
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
11914
11911
|
var KIRO_HOME_ENV = "KIRO_HOME";
|
|
11915
11912
|
var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
|
|
11916
11913
|
var APPDATA_ENV = "APPDATA";
|
|
@@ -11939,8 +11936,12 @@ var STATUS_LINE_KEY = "statusLine";
|
|
|
11939
11936
|
var PI_PACKAGES_KEY = "packages";
|
|
11940
11937
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
11941
11938
|
var OPENCODE_PLUGINS_KEY = "plugins";
|
|
11939
|
+
var OPENCODE_MCP_COMMAND_FIELD = "command";
|
|
11942
11940
|
var OPENCODE_PACKAGE_FIELD = "package";
|
|
11943
11941
|
var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
|
|
11942
|
+
var NPM_VERSION_SEP = "@";
|
|
11943
|
+
var OPENCODE_NPM_LATEST = `${OPENCODE_NPM_SPEC_PREFIX}latest`;
|
|
11944
|
+
var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
|
|
11944
11945
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
11945
11946
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
11946
11947
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -11969,17 +11970,22 @@ var V1_REASON = Object.freeze({
|
|
|
11969
11970
|
kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
|
|
11970
11971
|
piNpm: "old context-mode Pi package npm:context-mode",
|
|
11971
11972
|
opencodePlugin: "old context-mode OpenCode plugin spec context-mode",
|
|
11973
|
+
piGit: "old context-mode Pi entry git:github.com/mksglu/context-mode@release: ctx_upgrade replaces it with npm:context-mode@latest",
|
|
11974
|
+
opencodeGit: "old context-mode OpenCode entry git+https://github.com/mksglu/context-mode.git#release: ctx_upgrade replaces it with context-mode@latest",
|
|
11972
11975
|
zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
|
|
11973
11976
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
11974
11977
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
11975
11978
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
11976
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
11979
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep",
|
|
11980
|
+
projectLink: "context-mode path in the project reached through a link: report only, upgrade keeps it as is and never follows a link"
|
|
11977
11981
|
});
|
|
11978
|
-
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
11982
|
+
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]);
|
|
11983
|
+
var UPGRADE_KEEP_ASIDE_REASONS = Object.freeze([V1_REASON.dataDir, V1_REASON.dataRoot]);
|
|
11979
11984
|
var PLUGIN_NAME = SERVER_KEY;
|
|
11980
11985
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
11981
11986
|
var SERVER_ENTRY_FILE = "server.mjs";
|
|
11982
11987
|
var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
|
|
11988
|
+
var ROOTS_TIMEOUT_MS = 2e3;
|
|
11983
11989
|
var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
|
|
11984
11990
|
var HOST_NODE_COMMAND = "node";
|
|
11985
11991
|
var EXE_SUFFIX = ".exe";
|
|
@@ -12102,7 +12108,7 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
12102
12108
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
12103
12109
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
12104
12110
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
12105
|
-
zcode: ["
|
|
12111
|
+
zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
|
|
12106
12112
|
});
|
|
12107
12113
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
12108
12114
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
@@ -12238,7 +12244,7 @@ var CtxError = class extends Error {
|
|
|
12238
12244
|
};
|
|
12239
12245
|
|
|
12240
12246
|
// src/core/hooks/dispatch.ts
|
|
12241
|
-
import { dirname as dirname4, join as
|
|
12247
|
+
import { dirname as dirname4, join as join7, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
|
|
12242
12248
|
|
|
12243
12249
|
// src/core/contracts/agents.ts
|
|
12244
12250
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -12256,9 +12262,9 @@ function canonicalName(name, ownPrefix) {
|
|
|
12256
12262
|
if (name.startsWith(ownPrefix)) return name.slice(ownPrefix.length);
|
|
12257
12263
|
if (!name.startsWith(MCP_PREFIX)) return name;
|
|
12258
12264
|
const rest = name.slice(MCP_PREFIX.length);
|
|
12259
|
-
const
|
|
12260
|
-
if (
|
|
12261
|
-
return "mcp:" + rest.slice(0,
|
|
12265
|
+
const sep5 = rest.indexOf(MCP_SEP);
|
|
12266
|
+
if (sep5 < 0) return name;
|
|
12267
|
+
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP.length);
|
|
12262
12268
|
}
|
|
12263
12269
|
function outputOf(resp) {
|
|
12264
12270
|
if (resp === void 0) return "";
|
|
@@ -12458,6 +12464,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
|
12458
12464
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
12459
12465
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
12460
12466
|
var EMPTY = { stdout: "", exitCode: 0 };
|
|
12467
|
+
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";
|
|
12461
12468
|
function own(p, key) {
|
|
12462
12469
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
12463
12470
|
}
|
|
@@ -12477,13 +12484,67 @@ function canonicalName2(name, mcp) {
|
|
|
12477
12484
|
if (typeof server !== "string" || typeof tool !== "string") return name;
|
|
12478
12485
|
return "mcp:" + server + ":" + tool;
|
|
12479
12486
|
}
|
|
12487
|
+
function partsText(llm) {
|
|
12488
|
+
if (!Array.isArray(llm) || llm.length === 0) return void 0;
|
|
12489
|
+
const out = [];
|
|
12490
|
+
for (const part of llm) {
|
|
12491
|
+
if (typeof part === "string") {
|
|
12492
|
+
out.push(part);
|
|
12493
|
+
continue;
|
|
12494
|
+
}
|
|
12495
|
+
if (typeof part !== "object" || part === null) return void 0;
|
|
12496
|
+
const t = own(part, "text");
|
|
12497
|
+
if (typeof t !== "string") return void 0;
|
|
12498
|
+
out.push(t);
|
|
12499
|
+
}
|
|
12500
|
+
return out.join("");
|
|
12501
|
+
}
|
|
12480
12502
|
function readResult3(resp) {
|
|
12481
12503
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
12482
12504
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
12483
|
-
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : JSON.stringify(resp);
|
|
12505
|
+
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
12484
12506
|
const err = obj === void 0 ? void 0 : own(obj, "error");
|
|
12485
12507
|
return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
|
|
12486
12508
|
}
|
|
12509
|
+
var URL_STARTS = ["https://", "http://"];
|
|
12510
|
+
var URL_TRAIL = `.,;:!?)]}>'"`;
|
|
12511
|
+
var SPACE = " \n\r\f\v";
|
|
12512
|
+
function words(text) {
|
|
12513
|
+
const out = [];
|
|
12514
|
+
let cur = "";
|
|
12515
|
+
for (const ch of text) {
|
|
12516
|
+
if (SPACE.includes(ch)) {
|
|
12517
|
+
if (cur !== "") out.push(cur);
|
|
12518
|
+
cur = "";
|
|
12519
|
+
} else cur += ch;
|
|
12520
|
+
}
|
|
12521
|
+
if (cur !== "") out.push(cur);
|
|
12522
|
+
return out;
|
|
12523
|
+
}
|
|
12524
|
+
function firstUrl(prompt) {
|
|
12525
|
+
if (typeof prompt !== "string") return void 0;
|
|
12526
|
+
for (const word of words(prompt)) {
|
|
12527
|
+
const lower = word.toLowerCase();
|
|
12528
|
+
const at2 = URL_STARTS.map((s) => lower.indexOf(s)).filter((i) => i >= 0).sort((a, b) => a - b)[0];
|
|
12529
|
+
if (at2 === void 0) continue;
|
|
12530
|
+
let url4 = word.slice(at2);
|
|
12531
|
+
while (url4.length > 0 && URL_TRAIL.includes(url4[url4.length - 1])) url4 = url4.slice(0, -1);
|
|
12532
|
+
return url4;
|
|
12533
|
+
}
|
|
12534
|
+
return void 0;
|
|
12535
|
+
}
|
|
12536
|
+
function nativeInput(name, input) {
|
|
12537
|
+
if (name === "web_fetch" && own(input, "url") === void 0) {
|
|
12538
|
+
const url4 = firstUrl(own(input, "prompt"));
|
|
12539
|
+
return url4 === void 0 ? input : { ...input, url: url4 };
|
|
12540
|
+
}
|
|
12541
|
+
if (name === "read_many_files" && own(input, "file_path") === void 0) {
|
|
12542
|
+
const inc = own(input, "include");
|
|
12543
|
+
const list4 = Array.isArray(inc) ? inc.filter((v) => typeof v === "string") : [];
|
|
12544
|
+
return list4.length === 0 ? input : { ...input, file_path: list4.join(" ") };
|
|
12545
|
+
}
|
|
12546
|
+
return input;
|
|
12547
|
+
}
|
|
12487
12548
|
function decode4(raw) {
|
|
12488
12549
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
12489
12550
|
const p = raw;
|
|
@@ -12501,7 +12562,7 @@ function decode4(raw) {
|
|
|
12501
12562
|
ev.tool = {
|
|
12502
12563
|
name,
|
|
12503
12564
|
canonicalName: canonicalName2(name, own(p, "mcp_context")),
|
|
12504
|
-
input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
12565
|
+
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
12505
12566
|
};
|
|
12506
12567
|
}
|
|
12507
12568
|
if (event === "PostToolUse") ev.result = readResult3(own(p, "tool_response"));
|
|
@@ -12519,7 +12580,7 @@ function encode4(ev, d, _extra) {
|
|
|
12519
12580
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
12520
12581
|
case "replace":
|
|
12521
12582
|
if (ev.event !== "PostToolUse") return EMPTY;
|
|
12522
|
-
return { stdout: JSON.stringify({ decision: "deny", reason: d.output }), exitCode: 0 };
|
|
12583
|
+
return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
|
|
12523
12584
|
}
|
|
12524
12585
|
}
|
|
12525
12586
|
|
|
@@ -12676,9 +12737,9 @@ function canonicalName4(name) {
|
|
|
12676
12737
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
12677
12738
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
12678
12739
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
12679
|
-
const
|
|
12680
|
-
if (
|
|
12681
|
-
return "mcp:" + rest.slice(0,
|
|
12740
|
+
const sep5 = rest.indexOf(MCP_SEP2);
|
|
12741
|
+
if (sep5 <= 0 || sep5 === rest.length - 1) return name;
|
|
12742
|
+
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP2.length);
|
|
12682
12743
|
}
|
|
12683
12744
|
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
12684
12745
|
function policyInput(name, canonical, input) {
|
|
@@ -12807,9 +12868,9 @@ function canonicalName5(name) {
|
|
|
12807
12868
|
if (Object.hasOwn(NATIVE_TO_CANONICAL6, name)) return NATIVE_TO_CANONICAL6[name];
|
|
12808
12869
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
12809
12870
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
12810
|
-
const
|
|
12811
|
-
if (
|
|
12812
|
-
return "mcp:" + rest.slice(0,
|
|
12871
|
+
const sep5 = rest.indexOf(MCP_SEP3);
|
|
12872
|
+
if (sep5 <= 0 || sep5 === rest.length - 1) return name;
|
|
12873
|
+
return "mcp:" + rest.slice(0, sep5) + ":" + rest.slice(sep5 + MCP_SEP3.length);
|
|
12813
12874
|
}
|
|
12814
12875
|
function readResult6(resp) {
|
|
12815
12876
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
@@ -12852,6 +12913,7 @@ function encode8(ev, d, _extra) {
|
|
|
12852
12913
|
|
|
12853
12914
|
// src/adapters/zcode.ts
|
|
12854
12915
|
var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
12916
|
+
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
12855
12917
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
12856
12918
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
12857
12919
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
@@ -12861,7 +12923,9 @@ function decode9(raw) {
|
|
|
12861
12923
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
12862
12924
|
const failure3 = p.hook_event_name === FAILURE_EVENT2;
|
|
12863
12925
|
if (failure3) p.hook_event_name = "PostToolUse";
|
|
12864
|
-
const
|
|
12926
|
+
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
12927
|
+
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX9;
|
|
12928
|
+
const ev = decodeClaudeShape(p, "zcode", prefix, ZCODE_SOURCES);
|
|
12865
12929
|
if (failure3) {
|
|
12866
12930
|
const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
|
|
12867
12931
|
ev.result = { isError: true, bytes: Buffer.byteLength(text), text };
|
|
@@ -12884,8 +12948,9 @@ var OPENCODE_EVENTS = {
|
|
|
12884
12948
|
"step-finish": "Usage"
|
|
12885
12949
|
};
|
|
12886
12950
|
var SHELL_TOOL_NAME = "bash";
|
|
12951
|
+
var READ_TOOL_NAME = "read";
|
|
12887
12952
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
12888
|
-
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
12953
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
12889
12954
|
function toCanonicalTool(name) {
|
|
12890
12955
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
12891
12956
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -13113,9 +13178,9 @@ var ADAPTERS = Object.freeze([
|
|
|
13113
13178
|
installMode: "in-process",
|
|
13114
13179
|
projectSource: "spawn-cwd",
|
|
13115
13180
|
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
13116
|
-
nativeTools: { shell: [SHELL_TOOL_NAME] },
|
|
13181
|
+
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
13117
13182
|
execReadOnlyHint: false,
|
|
13118
|
-
// D-HF-OPENCODE-SHELL-1
|
|
13183
|
+
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
13119
13184
|
// Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
|
|
13120
13185
|
eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
|
|
13121
13186
|
compactDelivery: "opencode-cache",
|
|
@@ -13679,6 +13744,9 @@ var SUBSHELL_CLOSE = ")";
|
|
|
13679
13744
|
var CASE_BREAK = ";;";
|
|
13680
13745
|
var FUNC_PARENS = ["(", ")"];
|
|
13681
13746
|
var NOT = "!";
|
|
13747
|
+
function append(out, items) {
|
|
13748
|
+
for (const x of items) out.push(x);
|
|
13749
|
+
}
|
|
13682
13750
|
var KW = Object.freeze({
|
|
13683
13751
|
group: "{",
|
|
13684
13752
|
groupEnd: "}",
|
|
@@ -13858,12 +13926,12 @@ function ifBody(p) {
|
|
|
13858
13926
|
const t = at(p);
|
|
13859
13927
|
if (isWord(t, KW.then) || isWord(t, KW.else)) {
|
|
13860
13928
|
p.i++;
|
|
13861
|
-
out
|
|
13929
|
+
append(out, list(p, [KW.elif, KW.else, KW.fi]));
|
|
13862
13930
|
continue;
|
|
13863
13931
|
}
|
|
13864
13932
|
if (isWord(t, KW.elif)) {
|
|
13865
13933
|
p.i++;
|
|
13866
|
-
out
|
|
13934
|
+
append(out, list(p, [KW.then]));
|
|
13867
13935
|
continue;
|
|
13868
13936
|
}
|
|
13869
13937
|
if (isWord(t, KW.fi)) p.i++;
|
|
@@ -13874,7 +13942,7 @@ function ifBody(p) {
|
|
|
13874
13942
|
function loopBody(p) {
|
|
13875
13943
|
p.i++;
|
|
13876
13944
|
const out = list(p, [KW.do]);
|
|
13877
|
-
out
|
|
13945
|
+
append(out, doBlock(p));
|
|
13878
13946
|
return out;
|
|
13879
13947
|
}
|
|
13880
13948
|
function forBody(p) {
|
|
@@ -13888,10 +13956,10 @@ function forBody(p) {
|
|
|
13888
13956
|
p.i++;
|
|
13889
13957
|
const from = p.i;
|
|
13890
13958
|
while ((at(p)?.kind === "word" || at(p)?.kind === "unhandled") && !isWord(at(p), KW.do)) p.i++;
|
|
13891
|
-
out
|
|
13959
|
+
append(out, carrierOf(p, from, p.i));
|
|
13892
13960
|
}
|
|
13893
13961
|
}
|
|
13894
|
-
out
|
|
13962
|
+
append(out, doBlock(p));
|
|
13895
13963
|
return out;
|
|
13896
13964
|
}
|
|
13897
13965
|
function caseBody(p) {
|
|
@@ -13900,7 +13968,7 @@ function caseBody(p) {
|
|
|
13900
13968
|
const subject = at(p);
|
|
13901
13969
|
if (subject !== void 0 && subject.kind !== "op" && subject.kind !== "io") {
|
|
13902
13970
|
p.i++;
|
|
13903
|
-
out
|
|
13971
|
+
append(out, carrierOf(p, p.i - 1, p.i));
|
|
13904
13972
|
}
|
|
13905
13973
|
if (isWord(at(p), KW.in)) p.i++;
|
|
13906
13974
|
while (p.i < p.toks.length && p.err === null) {
|
|
@@ -13923,7 +13991,7 @@ function caseBody(p) {
|
|
|
13923
13991
|
p.i++;
|
|
13924
13992
|
const body = list(p, [KW.esac]);
|
|
13925
13993
|
tag(body, KW.case);
|
|
13926
|
-
out
|
|
13994
|
+
append(out, body);
|
|
13927
13995
|
}
|
|
13928
13996
|
return out;
|
|
13929
13997
|
}
|
|
@@ -13938,7 +14006,7 @@ function hasFuncParens(p, from) {
|
|
|
13938
14006
|
}
|
|
13939
14007
|
function simple(p) {
|
|
13940
14008
|
const first = p.i;
|
|
13941
|
-
const
|
|
14009
|
+
const words2 = [];
|
|
13942
14010
|
let toFile = false;
|
|
13943
14011
|
while (p.i < p.toks.length) {
|
|
13944
14012
|
const t = p.toks[p.i];
|
|
@@ -13947,7 +14015,7 @@ function simple(p) {
|
|
|
13947
14015
|
toFile = ioRedirect(p) || toFile;
|
|
13948
14016
|
continue;
|
|
13949
14017
|
}
|
|
13950
|
-
if (
|
|
14018
|
+
if (words2.length === 0 && t.kind === "word" && isAssignment(t.text)) {
|
|
13951
14019
|
p.i++;
|
|
13952
14020
|
const open3 = at(p);
|
|
13953
14021
|
if (t.text.endsWith(OPT_VALUE) && open3 !== void 0 && isOp(open3, SUBSHELL_OPEN) && open3.start === t.end) {
|
|
@@ -13961,15 +14029,15 @@ function simple(p) {
|
|
|
13961
14029
|
}
|
|
13962
14030
|
continue;
|
|
13963
14031
|
}
|
|
13964
|
-
|
|
14032
|
+
words2.push(t);
|
|
13965
14033
|
p.i++;
|
|
13966
14034
|
}
|
|
13967
14035
|
if (p.i === first) return EMPTY3();
|
|
13968
14036
|
const raw = p.src.slice(p.toks[first].start, p.toks[p.i - 1].end);
|
|
13969
|
-
if (
|
|
14037
|
+
if (words2.length === 0) return { cmds: carrier(raw), simple: null };
|
|
13970
14038
|
const text = (t) => t.kind === "word" ? dequote(t.text) : t.text;
|
|
13971
|
-
const argv0 = baseName(text(
|
|
13972
|
-
const args =
|
|
14039
|
+
const argv0 = baseName(text(words2[0]));
|
|
14040
|
+
const args = words2.slice(1).map(text);
|
|
13973
14041
|
const cmd = { argv0, args, redirectsToFile: toFile || writesFile(argv0, args), endsInBoundedSink: false, raw };
|
|
13974
14042
|
return { cmds: [cmd], simple: cmd };
|
|
13975
14043
|
}
|
|
@@ -14040,7 +14108,7 @@ function pipeline(p) {
|
|
|
14040
14108
|
let last2 = EMPTY3();
|
|
14041
14109
|
while (p.err === null) {
|
|
14042
14110
|
last2 = element(p);
|
|
14043
|
-
all
|
|
14111
|
+
append(all, last2.cmds);
|
|
14044
14112
|
const t = at(p);
|
|
14045
14113
|
if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
|
|
14046
14114
|
for (const c of last2.cmds) c.pipesOut = true;
|
|
@@ -14069,7 +14137,7 @@ function list(p, stop) {
|
|
|
14069
14137
|
}
|
|
14070
14138
|
if (t.kind === "word" && stop.includes(t.text)) return out;
|
|
14071
14139
|
const before = p.i;
|
|
14072
|
-
out
|
|
14140
|
+
append(out, pipeline(p));
|
|
14073
14141
|
if (p.i === before && p.err === null) p.i++;
|
|
14074
14142
|
}
|
|
14075
14143
|
return out;
|
|
@@ -14082,7 +14150,7 @@ function parseShell(cmd) {
|
|
|
14082
14150
|
const p = { toks: s.tokens, src: cmd, bodies: new Set(s.heredocBodies), i: 0, depth: 0, err: null };
|
|
14083
14151
|
const commands = [];
|
|
14084
14152
|
while (p.i < p.toks.length && p.err === null) {
|
|
14085
|
-
commands
|
|
14153
|
+
append(commands, list(p, NO_STOP));
|
|
14086
14154
|
if (p.i < p.toks.length) p.i++;
|
|
14087
14155
|
}
|
|
14088
14156
|
if (p.err !== null) return { ok: false, construct: p.err };
|
|
@@ -14337,57 +14405,57 @@ function param(word, names) {
|
|
|
14337
14405
|
const hits = names.filter((p) => p.startsWith(name));
|
|
14338
14406
|
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
14339
14407
|
}
|
|
14340
|
-
function psDump(
|
|
14341
|
-
if (
|
|
14342
|
-
const name = cmdName(
|
|
14408
|
+
function psDump(words2) {
|
|
14409
|
+
if (words2.length === 0) return null;
|
|
14410
|
+
const name = cmdName(words2[0]);
|
|
14343
14411
|
if (!READ_COMMANDS.includes(name)) {
|
|
14344
|
-
const lower =
|
|
14412
|
+
const lower = words2[0].toLowerCase();
|
|
14345
14413
|
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
14346
|
-
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) ||
|
|
14347
|
-
return { file:
|
|
14414
|
+
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words2.length < MIN_STATIC_CALL) return null;
|
|
14415
|
+
return { file: words2[1], bounded: false };
|
|
14348
14416
|
}
|
|
14349
14417
|
const files = [];
|
|
14350
14418
|
let bounded = false;
|
|
14351
|
-
for (let k = 1; k <
|
|
14352
|
-
const a =
|
|
14419
|
+
for (let k = 1; k < words2.length; k++) {
|
|
14420
|
+
const a = words2[k];
|
|
14353
14421
|
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
14354
14422
|
files.push(a);
|
|
14355
14423
|
continue;
|
|
14356
14424
|
}
|
|
14357
14425
|
const p = param(a, ALL_PARAMS);
|
|
14358
14426
|
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
14359
|
-
const value = p.inline ??
|
|
14427
|
+
const value = p.inline ?? words2[++k];
|
|
14360
14428
|
if (value === void 0) return null;
|
|
14361
14429
|
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
14362
14430
|
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
14363
14431
|
}
|
|
14364
14432
|
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
14365
14433
|
}
|
|
14366
|
-
function nestedScript(name,
|
|
14434
|
+
function nestedScript(name, words2) {
|
|
14367
14435
|
if (POWERSHELLS.includes(name)) {
|
|
14368
|
-
for (let k = 1; k <
|
|
14369
|
-
const w =
|
|
14436
|
+
for (let k = 1; k < words2.length; k++) {
|
|
14437
|
+
const w = words2[k];
|
|
14370
14438
|
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
14371
14439
|
const p = param(w, [COMMAND_PARAM]);
|
|
14372
14440
|
if (p.full === void 0) continue;
|
|
14373
|
-
return [...p.inline === void 0 ? [] : [p.inline], ...
|
|
14441
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words2.slice(k + 1)].join(" ");
|
|
14374
14442
|
}
|
|
14375
14443
|
return null;
|
|
14376
14444
|
}
|
|
14377
14445
|
if (CMDS.includes(name)) {
|
|
14378
|
-
for (let k = 1; k <
|
|
14379
|
-
if (CMD_RUN_FLAGS.includes(
|
|
14446
|
+
for (let k = 1; k < words2.length; k++) {
|
|
14447
|
+
if (CMD_RUN_FLAGS.includes(words2[k].toLowerCase())) return words2.slice(k + 1).join(" ");
|
|
14380
14448
|
}
|
|
14381
14449
|
}
|
|
14382
14450
|
return null;
|
|
14383
14451
|
}
|
|
14384
|
-
function cdTarget(
|
|
14385
|
-
for (let k = 1; k <
|
|
14386
|
-
const w =
|
|
14452
|
+
function cdTarget(words2) {
|
|
14453
|
+
for (let k = 1; k < words2.length; k++) {
|
|
14454
|
+
const w = words2[k];
|
|
14387
14455
|
if (w.toLowerCase() === "/d") continue;
|
|
14388
14456
|
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
14389
14457
|
const p = param(w, PATH_PARAMS);
|
|
14390
|
-
if (p.full !== void 0) return p.inline ??
|
|
14458
|
+
if (p.full !== void 0) return p.inline ?? words2[k + 1] ?? null;
|
|
14391
14459
|
}
|
|
14392
14460
|
return null;
|
|
14393
14461
|
}
|
|
@@ -14487,6 +14555,10 @@ function copilotDirOf(env, home) {
|
|
|
14487
14555
|
const dir = env[COPILOT_HOME_ENV];
|
|
14488
14556
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
14489
14557
|
}
|
|
14558
|
+
function geminiDirOf(env, home) {
|
|
14559
|
+
const dir = env[GEMINI_CLI_HOME_ENV];
|
|
14560
|
+
return join(dir !== void 0 && dir !== "" ? dir : home, ...AGENT_HOME_DIR.gemini);
|
|
14561
|
+
}
|
|
14490
14562
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
14491
14563
|
const p = platform === "win32" ? win32 : posix;
|
|
14492
14564
|
const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
|
|
@@ -14545,8 +14617,13 @@ function requireHomeDir(env, platform = process.platform) {
|
|
|
14545
14617
|
if (home !== null) return home;
|
|
14546
14618
|
throw new CtxError("NO_HOME", { name: platform === "win32" ? "USERPROFILE" : "HOME" });
|
|
14547
14619
|
}
|
|
14620
|
+
function dataRootOf(env, home) {
|
|
14621
|
+
const dir = env[DATA_DIR_ENV];
|
|
14622
|
+
return dir !== void 0 && dir !== "" ? resolve2(dir) : join(home, DATA_ROOT.slice(1));
|
|
14623
|
+
}
|
|
14548
14624
|
function resolveConfigDir(env) {
|
|
14549
|
-
const
|
|
14625
|
+
const set3 = env[DATA_DIR_ENV];
|
|
14626
|
+
const dir = dataRootOf(env, set3 !== void 0 && set3 !== "" ? "" : requireHomeDir(env));
|
|
14550
14627
|
mkdirSync(dir, { recursive: true });
|
|
14551
14628
|
return realpathSync.native(dir);
|
|
14552
14629
|
}
|
|
@@ -14918,14 +14995,13 @@ function tokenize(glob, path8) {
|
|
|
14918
14995
|
}
|
|
14919
14996
|
return toks;
|
|
14920
14997
|
}
|
|
14921
|
-
function
|
|
14922
|
-
const toks = tokenize(glob, path8);
|
|
14998
|
+
function matchStarts(toks, text, path8, ends) {
|
|
14923
14999
|
const n = text.length;
|
|
14924
|
-
let next =
|
|
14925
|
-
|
|
15000
|
+
let next = ends;
|
|
15001
|
+
let cur = new Uint8Array(n + 1);
|
|
14926
15002
|
for (let i = toks.length - 1; i >= 0; i--) {
|
|
14927
15003
|
const tok = toks[i];
|
|
14928
|
-
|
|
15004
|
+
if (next === ends) next = Uint8Array.from(ends);
|
|
14929
15005
|
let acc = 0;
|
|
14930
15006
|
for (let j = n; j >= 0; j--) {
|
|
14931
15007
|
const has3 = j < n;
|
|
@@ -14949,9 +15025,19 @@ function globMatch(glob, text, path8) {
|
|
|
14949
15025
|
break;
|
|
14950
15026
|
}
|
|
14951
15027
|
}
|
|
14952
|
-
|
|
15028
|
+
const done = cur;
|
|
15029
|
+
cur = next;
|
|
15030
|
+
next = done;
|
|
14953
15031
|
}
|
|
14954
|
-
return next
|
|
15032
|
+
return next;
|
|
15033
|
+
}
|
|
15034
|
+
function globMatch(glob, text, path8) {
|
|
15035
|
+
const toks = tokenize(glob, path8);
|
|
15036
|
+
const first = toks[0];
|
|
15037
|
+
if (first !== void 0 && first.t === "lit" && text[0] !== first.c) return false;
|
|
15038
|
+
const ends = new Uint8Array(text.length + 1);
|
|
15039
|
+
ends[text.length] = 1;
|
|
15040
|
+
return matchStarts(toks, text, path8, ends)[0] === 1;
|
|
14955
15041
|
}
|
|
14956
15042
|
function parsePattern(pattern) {
|
|
14957
15043
|
const open3 = pattern.indexOf("(");
|
|
@@ -14959,14 +15045,25 @@ function parsePattern(pattern) {
|
|
|
14959
15045
|
const glob = pattern.slice(open3 + 1, pattern.length - ")".length);
|
|
14960
15046
|
return glob === "" ? null : { tool: pattern.slice(0, open3), glob };
|
|
14961
15047
|
}
|
|
15048
|
+
function commandStarts(glob, text) {
|
|
15049
|
+
const n = text.length;
|
|
15050
|
+
const ends = new Uint8Array(n + 1);
|
|
15051
|
+
ends[n] = 1;
|
|
15052
|
+
if (!glob.endsWith(PREFIX_RULE)) return matchStarts(tokenize(glob, false), text, false, ends);
|
|
15053
|
+
for (let k = 0; k < n; k++) if (WHITESPACE.includes(text[k])) ends[k] = 1;
|
|
15054
|
+
return matchStarts(tokenize(glob.slice(0, glob.length - PREFIX_RULE.length), false), text, false, ends);
|
|
15055
|
+
}
|
|
14962
15056
|
function matchCommand(glob, text) {
|
|
14963
|
-
|
|
14964
|
-
|
|
14965
|
-
|
|
14966
|
-
for (
|
|
14967
|
-
|
|
15057
|
+
return commandStarts(glob, text)[0] === 1;
|
|
15058
|
+
}
|
|
15059
|
+
function denyPatternFromAny(text, patterns, from) {
|
|
15060
|
+
for (const pattern of patterns) {
|
|
15061
|
+
const p = parsePattern(pattern);
|
|
15062
|
+
if (p === null || p.tool !== BASH_TOOL) continue;
|
|
15063
|
+
const starts = commandStarts(p.glob, text);
|
|
15064
|
+
for (let j = 0; j <= text.length; j++) if (from[j] === 1 && starts[j] === 1) return pattern;
|
|
14968
15065
|
}
|
|
14969
|
-
return
|
|
15066
|
+
return null;
|
|
14970
15067
|
}
|
|
14971
15068
|
var DRIVE_PREFIX = /^[A-Za-z]:(?=\/)/;
|
|
14972
15069
|
function toSlash(p) {
|
|
@@ -15038,6 +15135,7 @@ var HOST_SEP = ".";
|
|
|
15038
15135
|
var SED_RANGE_SEP = ",";
|
|
15039
15136
|
var SED_PRINT = "p";
|
|
15040
15137
|
var SED_SCRIPT_FLAGS = ["-e", "--expression"];
|
|
15138
|
+
var EXE_SUFFIX2 = ".exe";
|
|
15041
15139
|
var COMMAND_STARTS = ";&|(`\n\r";
|
|
15042
15140
|
var ALLOW = Object.freeze({ kind: "allow" });
|
|
15043
15141
|
var deny = (reason) => ({ kind: "deny", reason });
|
|
@@ -15075,6 +15173,11 @@ function readPath(input) {
|
|
|
15075
15173
|
}
|
|
15076
15174
|
return void 0;
|
|
15077
15175
|
}
|
|
15176
|
+
function readPaths(input) {
|
|
15177
|
+
const one = readPath(input);
|
|
15178
|
+
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((p) => typeof p === "string" && p !== "") : [];
|
|
15179
|
+
return one === void 0 ? many : [one, ...many];
|
|
15180
|
+
}
|
|
15078
15181
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
15079
15182
|
if (rules.length === 0) return null;
|
|
15080
15183
|
const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
@@ -15083,35 +15186,65 @@ function userDenyHit(canonical, input, cwd, rules) {
|
|
|
15083
15186
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
15084
15187
|
}
|
|
15085
15188
|
if (canonical === READ) {
|
|
15086
|
-
const p
|
|
15087
|
-
|
|
15189
|
+
for (const p of readPaths(input)) {
|
|
15190
|
+
const h = readRule(p);
|
|
15191
|
+
if (h !== null) return h;
|
|
15192
|
+
}
|
|
15193
|
+
return null;
|
|
15088
15194
|
}
|
|
15089
15195
|
if (canonical === CTX_EXECUTE) {
|
|
15090
15196
|
const file2 = str(input.file);
|
|
15091
15197
|
const byFile = file2 === void 0 || file2 === "" ? null : readRule(file2);
|
|
15092
15198
|
if (byFile !== null) return byFile;
|
|
15093
15199
|
const code = str(input.code);
|
|
15094
|
-
return input.language
|
|
15200
|
+
return isShellLanguage(input.language) && code !== void 0 ? shellHit(code, rules) : null;
|
|
15095
15201
|
}
|
|
15096
15202
|
if (canonical === CTX_BATCH && Array.isArray(input.commands)) {
|
|
15097
15203
|
for (const c of input.commands) {
|
|
15098
|
-
const h = typeof c === "string" ?
|
|
15204
|
+
const h = typeof c === "string" ? shellHit(c, rules) : null;
|
|
15099
15205
|
if (h !== null) return h;
|
|
15100
15206
|
}
|
|
15101
15207
|
}
|
|
15102
15208
|
return null;
|
|
15103
15209
|
}
|
|
15210
|
+
function isShellLanguage(language) {
|
|
15211
|
+
if (typeof language !== "string") return false;
|
|
15212
|
+
let name = language.toLowerCase();
|
|
15213
|
+
const slash = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
|
|
15214
|
+
if (slash >= 0) name = name.slice(slash + 1);
|
|
15215
|
+
if (name.endsWith(EXE_SUFFIX2)) name = name.slice(0, name.length - EXE_SUFFIX2.length);
|
|
15216
|
+
return name === SHELL_LANGUAGE || has(SHELL_FAMILY, name);
|
|
15217
|
+
}
|
|
15218
|
+
function shellHit(cmd, rules) {
|
|
15219
|
+
const whole2 = matchesAnyDenyPattern(cmd, rules);
|
|
15220
|
+
if (whole2 !== null) return whole2;
|
|
15221
|
+
const parsed = parseShell(cmd);
|
|
15222
|
+
if (!parsed.ok) return couldMatchRule(cmd, rules);
|
|
15223
|
+
for (const c of unwrap(parsed.commands)) {
|
|
15224
|
+
const h = segmentHit(c, rules);
|
|
15225
|
+
if (h !== null) return h;
|
|
15226
|
+
}
|
|
15227
|
+
return null;
|
|
15228
|
+
}
|
|
15104
15229
|
function segmentHit(c, rules) {
|
|
15105
15230
|
if (rules.length === 0) return null;
|
|
15106
15231
|
return matchesAnyDenyPattern([c.argv0, ...c.args].join(" "), rules) ?? matchesAnyDenyPattern(c.raw, rules);
|
|
15107
15232
|
}
|
|
15108
|
-
function
|
|
15109
|
-
if (rules.length === 0) return
|
|
15233
|
+
function couldMatchRule(text, rules) {
|
|
15234
|
+
if (rules.length === 0) return null;
|
|
15235
|
+
const from = new Uint8Array(text.length + 1);
|
|
15236
|
+
let pending = false;
|
|
15110
15237
|
for (let k = 0; k <= text.length; k++) {
|
|
15111
|
-
if (k
|
|
15112
|
-
if (
|
|
15238
|
+
if (k === 0 || COMMAND_STARTS.includes(text.charAt(k - 1))) pending = true;
|
|
15239
|
+
if (pending && (k === text.length || text.charAt(k).trim() !== "")) {
|
|
15240
|
+
from[k] = 1;
|
|
15241
|
+
pending = false;
|
|
15242
|
+
}
|
|
15113
15243
|
}
|
|
15114
|
-
return
|
|
15244
|
+
return denyPatternFromAny(text, rules, from);
|
|
15245
|
+
}
|
|
15246
|
+
function couldMatch(text, rules) {
|
|
15247
|
+
return couldMatchRule(text, rules) !== null;
|
|
15115
15248
|
}
|
|
15116
15249
|
function neverDenied(url4) {
|
|
15117
15250
|
let host;
|
|
@@ -15186,8 +15319,7 @@ function fileSize(abs) {
|
|
|
15186
15319
|
}
|
|
15187
15320
|
function read(ev, row5, input) {
|
|
15188
15321
|
if (!present(input.offset) && !present(input.limit)) {
|
|
15189
|
-
const p
|
|
15190
|
-
if (p !== void 0) {
|
|
15322
|
+
for (const p of readPaths(input)) {
|
|
15191
15323
|
const abs = resolve3(ev.cwd, p);
|
|
15192
15324
|
const size = fileSize(abs);
|
|
15193
15325
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
@@ -15281,11 +15413,11 @@ function dumpTarget(name, args) {
|
|
|
15281
15413
|
}
|
|
15282
15414
|
|
|
15283
15415
|
// src/core/project/resolve.ts
|
|
15284
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
15416
|
+
import { basename as basename2, dirname as dirname3, join as join5, resolve as resolve4 } from "node:path";
|
|
15285
15417
|
|
|
15286
15418
|
// src/core/project/contain.ts
|
|
15287
|
-
import { dirname as dirname2, sep as sep2 } from "node:path";
|
|
15288
|
-
var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
15419
|
+
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
15420
|
+
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
15289
15421
|
function real(p) {
|
|
15290
15422
|
try {
|
|
15291
15423
|
return realpathSync2.native(p);
|
|
@@ -15324,6 +15456,21 @@ function commonRoot(paths) {
|
|
|
15324
15456
|
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
15325
15457
|
return q;
|
|
15326
15458
|
}
|
|
15459
|
+
function reachedThroughLink(root, p) {
|
|
15460
|
+
const rel = relative2(root, p);
|
|
15461
|
+
const steps = components(rel);
|
|
15462
|
+
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
15463
|
+
let at2 = root;
|
|
15464
|
+
for (const step of steps) {
|
|
15465
|
+
at2 = join4(at2, step);
|
|
15466
|
+
try {
|
|
15467
|
+
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
15468
|
+
} catch {
|
|
15469
|
+
return false;
|
|
15470
|
+
}
|
|
15471
|
+
}
|
|
15472
|
+
return false;
|
|
15473
|
+
}
|
|
15327
15474
|
|
|
15328
15475
|
// src/core/project/sha256.ts
|
|
15329
15476
|
var K = new Uint32Array([
|
|
@@ -15485,9 +15632,9 @@ function gitDirs(dir) {
|
|
|
15485
15632
|
}
|
|
15486
15633
|
const start = cur;
|
|
15487
15634
|
for (; ; ) {
|
|
15488
|
-
const gitDir = gitDirAt(
|
|
15635
|
+
const gitDir = gitDirAt(join5(cur, GIT_DIR_NAME));
|
|
15489
15636
|
if (gitDir !== null) {
|
|
15490
|
-
const common = firstLine(
|
|
15637
|
+
const common = firstLine(join5(gitDir, GIT_COMMONDIR_FILE));
|
|
15491
15638
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
15492
15639
|
}
|
|
15493
15640
|
const up = dirname3(cur);
|
|
@@ -15508,7 +15655,7 @@ function gitDirAt(dotGit) {
|
|
|
15508
15655
|
} catch {
|
|
15509
15656
|
return null;
|
|
15510
15657
|
}
|
|
15511
|
-
return existsSync(
|
|
15658
|
+
return existsSync(join5(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
15512
15659
|
}
|
|
15513
15660
|
function firstLine(file2) {
|
|
15514
15661
|
let text;
|
|
@@ -15549,11 +15696,11 @@ function resolveProject(agent, src) {
|
|
|
15549
15696
|
return key;
|
|
15550
15697
|
},
|
|
15551
15698
|
get projectDir() {
|
|
15552
|
-
pdir ??=
|
|
15699
|
+
pdir ??= join5(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
15553
15700
|
return pdir;
|
|
15554
15701
|
},
|
|
15555
15702
|
get dbPath() {
|
|
15556
|
-
return
|
|
15703
|
+
return join5(this.projectDir, DB_FILE_NAME);
|
|
15557
15704
|
},
|
|
15558
15705
|
worktree,
|
|
15559
15706
|
get containmentRoot() {
|
|
@@ -15694,6 +15841,15 @@ function applyMigrations(db, fromVersion) {
|
|
|
15694
15841
|
}
|
|
15695
15842
|
}
|
|
15696
15843
|
|
|
15844
|
+
// src/core/store/open-read.ts
|
|
15845
|
+
function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
15846
|
+
const bun = "bun" in opts ? opts.bun : process.versions.bun;
|
|
15847
|
+
if (bun === void 0) return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
15848
|
+
const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
15849
|
+
if (opts.queryOnly !== false) raw.exec("PRAGMA query_only = ON");
|
|
15850
|
+
return raw;
|
|
15851
|
+
}
|
|
15852
|
+
|
|
15697
15853
|
// src/core/store/db.ts
|
|
15698
15854
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
15699
15855
|
function versionParts(v) {
|
|
@@ -15759,7 +15915,7 @@ function openWritable(sqlite, path8) {
|
|
|
15759
15915
|
}
|
|
15760
15916
|
}
|
|
15761
15917
|
function openReadOnly(sqlite, path8) {
|
|
15762
|
-
const raw =
|
|
15918
|
+
const raw = openReadOnlyHandle(sqlite, path8);
|
|
15763
15919
|
try {
|
|
15764
15920
|
const found = readUserVersion(raw);
|
|
15765
15921
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -15979,14 +16135,14 @@ function identParts(w) {
|
|
|
15979
16135
|
if (cur !== "") parts.push(cur);
|
|
15980
16136
|
return parts;
|
|
15981
16137
|
}
|
|
15982
|
-
function snippetTerms(
|
|
16138
|
+
function snippetTerms(words2) {
|
|
15983
16139
|
const out = /* @__PURE__ */ new Map();
|
|
15984
16140
|
const add = (text, weight, symbol2) => {
|
|
15985
16141
|
if (text === "") return;
|
|
15986
16142
|
const prev = out.get(text);
|
|
15987
16143
|
if (!prev || prev.weight < weight) out.set(text, { text, weight, symbol: symbol2 });
|
|
15988
16144
|
};
|
|
15989
|
-
for (const raw of
|
|
16145
|
+
for (const raw of words2) {
|
|
15990
16146
|
let a = 0;
|
|
15991
16147
|
let b = raw.length;
|
|
15992
16148
|
while (a < b && !isAlnum(raw.charCodeAt(a))) a++;
|
|
@@ -17992,18 +18148,18 @@ function deleteChunkRows(raw, scope) {
|
|
|
17992
18148
|
return Number(raw.prepare("DELETE FROM chunks WHERE " + where).run(arg).changes);
|
|
17993
18149
|
}
|
|
17994
18150
|
function toMatch(q) {
|
|
17995
|
-
const
|
|
18151
|
+
const words2 = [];
|
|
17996
18152
|
let cur = "";
|
|
17997
18153
|
for (const ch of q) {
|
|
17998
18154
|
if (ch.trim() === "" || ch === "\0") {
|
|
17999
|
-
if (cur !== "")
|
|
18155
|
+
if (cur !== "") words2.push(cur);
|
|
18000
18156
|
cur = "";
|
|
18001
18157
|
} else {
|
|
18002
18158
|
cur += ch === '"' ? '""' : ch;
|
|
18003
18159
|
}
|
|
18004
18160
|
}
|
|
18005
|
-
if (cur !== "")
|
|
18006
|
-
return
|
|
18161
|
+
if (cur !== "") words2.push(cur);
|
|
18162
|
+
return words2.map((w) => `"${w}"*`).join(" ");
|
|
18007
18163
|
}
|
|
18008
18164
|
function toMatchAny(q) {
|
|
18009
18165
|
const terms = new Set(toMatch(q).split(" ").filter((t) => t !== ""));
|
|
@@ -18100,11 +18256,11 @@ function searchTerms(q) {
|
|
|
18100
18256
|
return kept.length > 0 ? kept : all;
|
|
18101
18257
|
}
|
|
18102
18258
|
function trigramMatch(q) {
|
|
18103
|
-
const
|
|
18104
|
-
const kept =
|
|
18105
|
-
const parts = new Set((kept.length > 0 ? kept :
|
|
18106
|
-
const whole2 =
|
|
18107
|
-
if (
|
|
18259
|
+
const words2 = blankTokens(q);
|
|
18260
|
+
const kept = words2.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
18261
|
+
const parts = new Set((kept.length > 0 ? kept : words2).filter((w) => [...w].length >= 3));
|
|
18262
|
+
const whole2 = words2.join(" ");
|
|
18263
|
+
if (words2.length > 1 && [...whole2].length >= 3) parts.add(whole2);
|
|
18108
18264
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
18109
18265
|
}
|
|
18110
18266
|
function editDistance(a, b, max) {
|
|
@@ -18151,10 +18307,10 @@ function queryStems(q) {
|
|
|
18151
18307
|
}
|
|
18152
18308
|
var TYPO_MIN_LEN = 5;
|
|
18153
18309
|
var TYPO_MAX_DIST = 2;
|
|
18154
|
-
function typoTerms(db,
|
|
18310
|
+
function typoTerms(db, words2) {
|
|
18155
18311
|
const has3 = stmt(db.raw, "SELECT 1 AS x FROM chunks_vocab WHERE term = ?");
|
|
18156
18312
|
const near = stmt(db.raw, "SELECT term, doc, length(term) AS n FROM chunks_vocab WHERE length(term) BETWEEN ? AND ?");
|
|
18157
|
-
const stems = queryStems(
|
|
18313
|
+
const stems = queryStems(words2.join(" "));
|
|
18158
18314
|
const miss = stems.map((stem) => has3.get(stem) === void 0 && [...stem].length >= TYPO_MIN_LEN);
|
|
18159
18315
|
if (!miss.includes(true)) return null;
|
|
18160
18316
|
const lens = stems.filter((_, i) => miss[i]).map((stem) => stem.length);
|
|
@@ -18257,9 +18413,9 @@ function ftsListSource(db, source, scope, ctx, sessionId, limit, offset) {
|
|
|
18257
18413
|
}));
|
|
18258
18414
|
}
|
|
18259
18415
|
function highlight(row5, terms, maxBytes = SNIPPET_MAX_BYTES) {
|
|
18260
|
-
const
|
|
18261
|
-
const kept =
|
|
18262
|
-
return buildSnippet(row5, snippetTerms(kept.length > 0 ? kept :
|
|
18416
|
+
const words2 = blankTokens(terms);
|
|
18417
|
+
const kept = words2.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
18418
|
+
return buildSnippet(row5, snippetTerms(kept.length > 0 ? kept : words2), maxBytes);
|
|
18263
18419
|
}
|
|
18264
18420
|
var TL_SCOPE = `
|
|
18265
18421
|
AND (:scope <> 'session' OR session_id = :session_id)
|
|
@@ -18525,13 +18681,24 @@ function buildUnits(text) {
|
|
|
18525
18681
|
const lines = text.split("\n");
|
|
18526
18682
|
const stack2 = [];
|
|
18527
18683
|
const out = [];
|
|
18684
|
+
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
18528
18685
|
for (let i = 0; i < lines.length; i++) {
|
|
18529
18686
|
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
18530
18687
|
const indent = indentOf(line);
|
|
18531
18688
|
if (indent === line.length) continue;
|
|
18532
18689
|
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
18533
|
-
|
|
18534
|
-
|
|
18690
|
+
const bytes5 = Buffer.byteLength(line, "utf8");
|
|
18691
|
+
let size = bytes5;
|
|
18692
|
+
let from = stack2.length;
|
|
18693
|
+
while (from > 0) {
|
|
18694
|
+
const add = stack2[from - 1].bytes + 1;
|
|
18695
|
+
if (size + add > RECALL_BUDGET_BYTES || size - bytes5 + add > left) break;
|
|
18696
|
+
size += add;
|
|
18697
|
+
from--;
|
|
18698
|
+
}
|
|
18699
|
+
left -= size - bytes5;
|
|
18700
|
+
out.push({ ord: i, body: [...stack2.slice(from).map((s) => s.line), line].join("\n") });
|
|
18701
|
+
stack2.push({ indent, line, bytes: bytes5 });
|
|
18535
18702
|
}
|
|
18536
18703
|
return out;
|
|
18537
18704
|
}
|
|
@@ -18670,7 +18837,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
18670
18837
|
const pool = cands.filter((u) => !seen.has(unitKey(u)) && u.score >= RECALL_MIN_SCORE);
|
|
18671
18838
|
if (pool.length === 0) return [];
|
|
18672
18839
|
const top = Math.max(...pool.map((u) => u.score));
|
|
18673
|
-
const
|
|
18840
|
+
const words2 = pool.map((u) => wordsOf(u.body));
|
|
18674
18841
|
const taken = [];
|
|
18675
18842
|
const left = new Set(pool.map((_, i) => i));
|
|
18676
18843
|
let used = 0;
|
|
@@ -18679,7 +18846,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
18679
18846
|
let bestVal = -Infinity;
|
|
18680
18847
|
for (const i of left) {
|
|
18681
18848
|
let sim = 0;
|
|
18682
|
-
for (const j of taken) sim = Math.max(sim, overlap(
|
|
18849
|
+
for (const j of taken) sim = Math.max(sim, overlap(words2[i], words2[j]));
|
|
18683
18850
|
const val = MMR_RELEVANCE_WEIGHT * (pool[i].score / top) - MMR_REDUNDANCY_WEIGHT * sim;
|
|
18684
18851
|
if (val > bestVal) {
|
|
18685
18852
|
bestVal = val;
|
|
@@ -19082,7 +19249,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
19082
19249
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
19083
19250
|
return { end: start + r.read, written: r.written };
|
|
19084
19251
|
}
|
|
19085
|
-
function merge2(src, blocks,
|
|
19252
|
+
function merge2(src, blocks, join26, cap, lineCut) {
|
|
19086
19253
|
const out = [];
|
|
19087
19254
|
const scratch = new Uint8Array(cap);
|
|
19088
19255
|
let wide;
|
|
@@ -19092,7 +19259,7 @@ function merge2(src, blocks, join29, cap, lineCut) {
|
|
|
19092
19259
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
19093
19260
|
};
|
|
19094
19261
|
for (const b of blocks) {
|
|
19095
|
-
if (cur !== void 0 && !
|
|
19262
|
+
if (cur !== void 0 && !join26) {
|
|
19096
19263
|
emit(cur.start, cur.end, curBytes);
|
|
19097
19264
|
cur = void 0;
|
|
19098
19265
|
}
|
|
@@ -19210,11 +19377,11 @@ function shapeDigest(text, query, budget) {
|
|
|
19210
19377
|
const picked = [];
|
|
19211
19378
|
let used = 0;
|
|
19212
19379
|
for (const i of order) {
|
|
19213
|
-
const
|
|
19214
|
-
const r = shape.units[i].render(budget - used -
|
|
19215
|
-
if (r === null || used +
|
|
19380
|
+
const sep5 = picked.length > 0 ? bytes(SEP2) : 0;
|
|
19381
|
+
const r = shape.units[i].render(budget - used - sep5);
|
|
19382
|
+
if (r === null || used + sep5 + bytes(r) > budget) continue;
|
|
19216
19383
|
picked.push({ pos: shape.units[i].pos, text: r });
|
|
19217
|
-
used +=
|
|
19384
|
+
used += sep5 + bytes(r);
|
|
19218
19385
|
}
|
|
19219
19386
|
if (picked.length === 0) return null;
|
|
19220
19387
|
picked.sort((a, b) => a.pos - b.pos);
|
|
@@ -19534,7 +19701,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
19534
19701
|
}
|
|
19535
19702
|
|
|
19536
19703
|
// src/core/hooks/fallback.ts
|
|
19537
|
-
import { join as
|
|
19704
|
+
import { join as join6, resolve as resolve5 } from "node:path";
|
|
19538
19705
|
var fs = process.getBuiltinModule("node:fs");
|
|
19539
19706
|
function isRec(v) {
|
|
19540
19707
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -19561,8 +19728,10 @@ function homeOf(env) {
|
|
|
19561
19728
|
return env.HOME ?? env.USERPROFILE ?? "";
|
|
19562
19729
|
}
|
|
19563
19730
|
function hookLogPath(env) {
|
|
19731
|
+
const dir = env[DATA_DIR_ENV];
|
|
19732
|
+
if (dir !== void 0 && dir !== "") return join6(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
19564
19733
|
const home = homeOf(env);
|
|
19565
|
-
return home === "" ? "" :
|
|
19734
|
+
return home === "" ? "" : join6(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
19566
19735
|
}
|
|
19567
19736
|
function errorLabel(err) {
|
|
19568
19737
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -19573,7 +19742,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
19573
19742
|
try {
|
|
19574
19743
|
const file2 = hookLogPath(env);
|
|
19575
19744
|
if (file2 === "") return;
|
|
19576
|
-
fs.mkdirSync(
|
|
19745
|
+
fs.mkdirSync(join6(file2, ".."), { recursive: true });
|
|
19577
19746
|
const line = JSON.stringify({
|
|
19578
19747
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19579
19748
|
agent,
|
|
@@ -19644,17 +19813,19 @@ function isPreTool(row5, event) {
|
|
|
19644
19813
|
const e = event.toLowerCase();
|
|
19645
19814
|
return HOOK_FAIL_PRE_EVENTS.includes(e) || (row5.eventMap.PreToolUse ?? "").toLowerCase() === e;
|
|
19646
19815
|
}
|
|
19647
|
-
function
|
|
19648
|
-
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
19649
|
-
const p = firstString(input, READ_PATH_KEYS);
|
|
19650
|
-
if (p === "") return false;
|
|
19816
|
+
function bigFile(abs) {
|
|
19651
19817
|
try {
|
|
19652
|
-
const st = fs.statSync(
|
|
19818
|
+
const st = fs.statSync(abs);
|
|
19653
19819
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
19654
19820
|
} catch {
|
|
19655
19821
|
return false;
|
|
19656
19822
|
}
|
|
19657
19823
|
}
|
|
19824
|
+
function bigRead(input, cwd) {
|
|
19825
|
+
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
19826
|
+
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
|
|
19827
|
+
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)));
|
|
19828
|
+
}
|
|
19658
19829
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
19659
19830
|
const row5 = getAdapter(agent);
|
|
19660
19831
|
const allow = () => row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
@@ -19679,7 +19850,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
19679
19850
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
19680
19851
|
|
|
19681
19852
|
// src/core/hooks/dispatch.ts
|
|
19682
|
-
var { readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
19853
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
19683
19854
|
var ALLOW2 = { kind: "allow" };
|
|
19684
19855
|
var EMPTY4 = { stdout: "", exitCode: 0 };
|
|
19685
19856
|
var DIGIT_0 = 48;
|
|
@@ -19940,7 +20111,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
19940
20111
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
19941
20112
|
const command = tool.input.command;
|
|
19942
20113
|
if (typeof command !== "string") return d0;
|
|
19943
|
-
const wrapper = '"' +
|
|
20114
|
+
const wrapper = '"' + join7(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
19944
20115
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
19945
20116
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
19946
20117
|
}
|
|
@@ -19981,7 +20152,7 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
19981
20152
|
const tool = ev.tool;
|
|
19982
20153
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
19983
20154
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
19984
|
-
const text = wholeOutput(result);
|
|
20155
|
+
const text = wholeOutput(result, ev.sessionId, env);
|
|
19985
20156
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
19986
20157
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
19987
20158
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -20060,10 +20231,23 @@ function replaceOutput(body, handleLine) {
|
|
|
20060
20231
|
function replaceBudget(handleLine, more) {
|
|
20061
20232
|
return Math.max(0, REPLACE_RETURN_BYTES + Buffer.byteLength("\n" + more) - 1 - Buffer.byteLength(handleLine));
|
|
20062
20233
|
}
|
|
20063
|
-
function
|
|
20234
|
+
function hostToolResult(file2, sessionId, env) {
|
|
20235
|
+
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
20236
|
+
const projects = join7(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
20237
|
+
const steps = relative3(projects, resolve6(file2)).split(sep3);
|
|
20238
|
+
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
20239
|
+
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
20240
|
+
const st = lstatSync2(file2);
|
|
20241
|
+
return st.isFile() && st.size <= PERSISTED_OUTPUT_MAX_BYTES && isInside(projects, file2);
|
|
20242
|
+
}
|
|
20243
|
+
function wholeOutput(result, sessionId, env) {
|
|
20064
20244
|
const head = result.text ?? "";
|
|
20065
20245
|
if (result.persistedPath === void 0) return head;
|
|
20066
20246
|
try {
|
|
20247
|
+
if (!hostToolResult(result.persistedPath, sessionId, env)) {
|
|
20248
|
+
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"));
|
|
20249
|
+
return head;
|
|
20250
|
+
}
|
|
20067
20251
|
return readFileSync4(result.persistedPath, "utf8");
|
|
20068
20252
|
} catch {
|
|
20069
20253
|
return head;
|
|
@@ -20243,10 +20427,10 @@ function findRuntime(lang, env = process.env) {
|
|
|
20243
20427
|
return shim;
|
|
20244
20428
|
}
|
|
20245
20429
|
function findGitBash(env) {
|
|
20246
|
-
const
|
|
20247
|
-
if (
|
|
20430
|
+
const git2 = findRuntime(GIT_BIN, env);
|
|
20431
|
+
if (git2 === null) return null;
|
|
20248
20432
|
for (const rel of GIT_BASH_RELATIVE) {
|
|
20249
|
-
const full = path.resolve(path.dirname(
|
|
20433
|
+
const full = path.resolve(path.dirname(git2), ...rel);
|
|
20250
20434
|
if (isRunnable(full)) return full;
|
|
20251
20435
|
}
|
|
20252
20436
|
return null;
|
|
@@ -20287,10 +20471,10 @@ function startArgv(argv) {
|
|
|
20287
20471
|
return sh === null ? null : [sh, ...argv];
|
|
20288
20472
|
}
|
|
20289
20473
|
function runProcess(argv, o) {
|
|
20290
|
-
return new Promise((
|
|
20474
|
+
return new Promise((resolve9) => {
|
|
20291
20475
|
const isWin2 = process.platform === "win32";
|
|
20292
20476
|
const start = startArgv(argv);
|
|
20293
|
-
if (start === null) return
|
|
20477
|
+
if (start === null) return resolve9(NOT_STARTED);
|
|
20294
20478
|
let child;
|
|
20295
20479
|
try {
|
|
20296
20480
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -20304,7 +20488,7 @@ function runProcess(argv, o) {
|
|
|
20304
20488
|
windowsHide: true
|
|
20305
20489
|
});
|
|
20306
20490
|
} catch {
|
|
20307
|
-
return
|
|
20491
|
+
return resolve9(NOT_STARTED);
|
|
20308
20492
|
}
|
|
20309
20493
|
const stdoutChunks = [];
|
|
20310
20494
|
const stderrChunks = [];
|
|
@@ -20329,7 +20513,7 @@ function runProcess(argv, o) {
|
|
|
20329
20513
|
settled = true;
|
|
20330
20514
|
clearTimeout(timer);
|
|
20331
20515
|
o.signal.removeEventListener("abort", onAbort);
|
|
20332
|
-
|
|
20516
|
+
resolve9({
|
|
20333
20517
|
stdout: Buffer.concat(stdoutChunks),
|
|
20334
20518
|
stderr: Buffer.concat(stderrChunks),
|
|
20335
20519
|
exitCode,
|
|
@@ -20351,7 +20535,7 @@ function runProcess(argv, o) {
|
|
|
20351
20535
|
|
|
20352
20536
|
// src/core/index/auto-memory.ts
|
|
20353
20537
|
import { readdirSync, readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
|
|
20354
|
-
import { join as
|
|
20538
|
+
import { join as join8 } from "node:path";
|
|
20355
20539
|
var MEMORY_FILES = Object.freeze([
|
|
20356
20540
|
Object.freeze(["CLAUDE.md"]),
|
|
20357
20541
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -20365,7 +20549,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20365
20549
|
var MD = ".md";
|
|
20366
20550
|
function steeringFiles(worktree) {
|
|
20367
20551
|
try {
|
|
20368
|
-
return readdirSync(
|
|
20552
|
+
return readdirSync(join8(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20369
20553
|
} catch {
|
|
20370
20554
|
return [];
|
|
20371
20555
|
}
|
|
@@ -20373,7 +20557,7 @@ function steeringFiles(worktree) {
|
|
|
20373
20557
|
function readAutoMemory(project) {
|
|
20374
20558
|
const rows = [];
|
|
20375
20559
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20376
|
-
const path8 =
|
|
20560
|
+
const path8 = join8(project.worktree, ...segs);
|
|
20377
20561
|
if (!isInside(project.worktree, path8)) continue;
|
|
20378
20562
|
try {
|
|
20379
20563
|
const st = statSync4(path8);
|
|
@@ -20956,18 +21140,18 @@ var ctxBatch = Object.freeze({
|
|
|
20956
21140
|
|
|
20957
21141
|
// src/core/tools/doctor.ts
|
|
20958
21142
|
import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
|
|
20959
|
-
import { basename as basename5, join as
|
|
21143
|
+
import { basename as basename5, join as join18 } from "node:path";
|
|
20960
21144
|
|
|
20961
21145
|
// src/core/ops/bundle-dir.ts
|
|
20962
21146
|
import { existsSync as existsSync3 } from "node:fs";
|
|
20963
|
-
import { dirname as dirname5, join as
|
|
21147
|
+
import { dirname as dirname5, join as join9 } from "node:path";
|
|
20964
21148
|
import { fileURLToPath } from "node:url";
|
|
20965
21149
|
function bundleDirOf(argv1, moduleFile) {
|
|
20966
21150
|
const own4 = dirname5(argv1);
|
|
20967
|
-
if (existsSync3(
|
|
21151
|
+
if (existsSync3(join9(own4, SERVER_ENTRY_FILE))) return own4;
|
|
20968
21152
|
let dir = dirname5(moduleFile);
|
|
20969
21153
|
for (; ; ) {
|
|
20970
|
-
if (existsSync3(
|
|
21154
|
+
if (existsSync3(join9(dir, SERVER_ENTRY_FILE))) return dir;
|
|
20971
21155
|
const up = dirname5(dir);
|
|
20972
21156
|
if (up === dir) return own4;
|
|
20973
21157
|
dir = up;
|
|
@@ -20982,16 +21166,16 @@ function ownBundleDir() {
|
|
|
20982
21166
|
|
|
20983
21167
|
// src/core/ops/doctor-config.ts
|
|
20984
21168
|
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
20985
|
-
import { join as
|
|
21169
|
+
import { join as join13 } from "node:path";
|
|
20986
21170
|
|
|
20987
21171
|
// src/core/ops/detect-v1.ts
|
|
20988
21172
|
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
|
|
20989
21173
|
import { tmpdir } from "node:os";
|
|
20990
|
-
import { join as
|
|
21174
|
+
import { join as join11 } from "node:path";
|
|
20991
21175
|
|
|
20992
21176
|
// src/core/ops/host-config.ts
|
|
20993
21177
|
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
20994
|
-
import { dirname as dirname6, join as
|
|
21178
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
20995
21179
|
|
|
20996
21180
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
20997
21181
|
var KEYS2 = {
|
|
@@ -23108,7 +23292,7 @@ function formatOf(path8) {
|
|
|
23108
23292
|
function readHostConfig(agent, path8) {
|
|
23109
23293
|
let file2 = path8;
|
|
23110
23294
|
if (agent === "opencode") {
|
|
23111
|
-
const jsonc =
|
|
23295
|
+
const jsonc = join10(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23112
23296
|
if (existsSync4(jsonc)) file2 = jsonc;
|
|
23113
23297
|
}
|
|
23114
23298
|
const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -23419,8 +23603,8 @@ function replaceToml(text, doc, path8, value) {
|
|
|
23419
23603
|
let out = text;
|
|
23420
23604
|
for (const [s, e, put] of cuts) out = out.slice(0, s) + put + out.slice(e);
|
|
23421
23605
|
if (owned.length > 0 || block === "") return out;
|
|
23422
|
-
const
|
|
23423
|
-
return out +
|
|
23606
|
+
const sep5 = out === "" ? "" : out.endsWith("\n\n") ? "" : out.endsWith("\n") ? "\n" : "\n\n";
|
|
23607
|
+
return out + sep5 + block;
|
|
23424
23608
|
}
|
|
23425
23609
|
var tableLike = (v) => v === void 0 || isPlainObject3(v);
|
|
23426
23610
|
function setTomlText(text, path8, value) {
|
|
@@ -23456,33 +23640,39 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
23456
23640
|
}
|
|
23457
23641
|
}
|
|
23458
23642
|
function serverScript() {
|
|
23459
|
-
return
|
|
23643
|
+
return join10(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23460
23644
|
}
|
|
23461
23645
|
function isNodeCommand(command) {
|
|
23462
23646
|
if (typeof command !== "string") return false;
|
|
23463
23647
|
let at2 = -1;
|
|
23464
|
-
for (const
|
|
23648
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, command.lastIndexOf(sep5));
|
|
23465
23649
|
const exe = command.slice(at2 + 1).toLowerCase();
|
|
23466
23650
|
return exe === HOST_NODE_COMMAND || exe === HOST_NODE_COMMAND + EXE_SUFFIX;
|
|
23467
23651
|
}
|
|
23468
23652
|
function ownMcpValue(agent, node3, server) {
|
|
23469
23653
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23470
23654
|
if (mcp === void 0) return void 0;
|
|
23471
|
-
|
|
23472
|
-
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
|
|
23655
|
+
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent] };
|
|
23473
23656
|
}
|
|
23474
23657
|
function opencodePluginFile() {
|
|
23475
23658
|
return ownBundleDir();
|
|
23476
23659
|
}
|
|
23477
|
-
function listTarget(key,
|
|
23660
|
+
function listTarget(key, legacy, swap, isNative) {
|
|
23478
23661
|
return {
|
|
23479
23662
|
key: [key],
|
|
23480
23663
|
next(current) {
|
|
23481
|
-
|
|
23482
|
-
|
|
23664
|
+
if (!Array.isArray(current) || !current.some(legacy)) return current;
|
|
23665
|
+
const keep = current.filter((x) => !legacy(x));
|
|
23666
|
+
if (keep.some(isNative)) return keep;
|
|
23667
|
+
const at2 = current.findIndex(legacy);
|
|
23668
|
+
return current.flatMap((x, i) => i === at2 ? [swap(x)] : legacy(x) ? [] : [x]);
|
|
23483
23669
|
}
|
|
23484
23670
|
};
|
|
23485
23671
|
}
|
|
23672
|
+
var piSource = (x) => isPlainObject3(x) ? x[PI_PACKAGE_SOURCE_KEY] : x;
|
|
23673
|
+
var opencodeSpec = (x) => isPlainObject3(x) ? x[OPENCODE_PACKAGE_FIELD] : x;
|
|
23674
|
+
var isNpmOf = (bare2) => (s) => typeof s === "string" && (s === bare2 || s.startsWith(bare2 + NPM_VERSION_SEP));
|
|
23675
|
+
var swapField = (field, spec) => (x) => isPlainObject3(x) ? { ...x, [field]: spec } : spec;
|
|
23486
23676
|
function ownTargets(agent, accept) {
|
|
23487
23677
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23488
23678
|
if (mcp !== void 0) {
|
|
@@ -23495,8 +23685,18 @@ function ownTargets(agent, accept) {
|
|
|
23495
23685
|
}
|
|
23496
23686
|
}, ...(mcp.also ?? []).map(([key, value]) => ({ key, next: () => value }))];
|
|
23497
23687
|
}
|
|
23498
|
-
if (agent === "opencode")
|
|
23499
|
-
|
|
23688
|
+
if (agent === "opencode") {
|
|
23689
|
+
const alt = accept.listEntries ?? [];
|
|
23690
|
+
const native = (x) => {
|
|
23691
|
+
const s = opencodeSpec(x);
|
|
23692
|
+
return typeof s === "string" && (s.startsWith(OPENCODE_NPM_SPEC_PREFIX) || alt.includes(s));
|
|
23693
|
+
};
|
|
23694
|
+
return [listTarget(OPENCODE_PLUGIN_KEY, (x) => opencodeSpec(x) === OPENCODE_GIT_SPEC, swapField(OPENCODE_PACKAGE_FIELD, OPENCODE_NPM_LATEST), native)];
|
|
23695
|
+
}
|
|
23696
|
+
if (agent === "pi") {
|
|
23697
|
+
const npm = isNpmOf(V1_PI_PACKAGE);
|
|
23698
|
+
return [listTarget(PI_PACKAGES_KEY, (x) => piSource(x) === PI_GIT_PACKAGE, swapField(PI_PACKAGE_SOURCE_KEY, PI_NPM_LATEST), (x) => npm(piSource(x)))];
|
|
23699
|
+
}
|
|
23500
23700
|
return [];
|
|
23501
23701
|
}
|
|
23502
23702
|
function applyEdits(agent, path8, text, format, wanted) {
|
|
@@ -23598,7 +23798,7 @@ function isV2McpTable(v) {
|
|
|
23598
23798
|
const first = Array.isArray(v[MCP_ARGS_FIELD]) ? v[MCP_ARGS_FIELD][0] : void 0;
|
|
23599
23799
|
if (typeof first !== "string") return false;
|
|
23600
23800
|
let at2 = -1;
|
|
23601
|
-
for (const
|
|
23801
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, first.lastIndexOf(sep5));
|
|
23602
23802
|
return first.slice(at2 + 1) === SERVER_ENTRY_FILE;
|
|
23603
23803
|
}
|
|
23604
23804
|
var listOf = (v) => Array.isArray(v) ? v : [];
|
|
@@ -23629,7 +23829,7 @@ function flatCommands(events, prefix) {
|
|
|
23629
23829
|
return out;
|
|
23630
23830
|
}
|
|
23631
23831
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23632
|
-
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((
|
|
23832
|
+
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep5) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5));
|
|
23633
23833
|
function dataDir(dir, reason, out) {
|
|
23634
23834
|
if (existsSync5(dir)) out.push(finding(dir, "", reason));
|
|
23635
23835
|
}
|
|
@@ -23639,7 +23839,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23639
23839
|
}
|
|
23640
23840
|
}
|
|
23641
23841
|
function claudeShapeSettings(agentHome, out) {
|
|
23642
|
-
const file2 =
|
|
23842
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23643
23843
|
const doc = readJson(file2);
|
|
23644
23844
|
for (const c of nestedCommands(doc)) {
|
|
23645
23845
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23659,49 +23859,50 @@ function v1HookFile(file2, out) {
|
|
|
23659
23859
|
function scanClaudeCode(home, agentHome, out) {
|
|
23660
23860
|
claudeShapeSettings(agentHome, out);
|
|
23661
23861
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23662
|
-
const file2 =
|
|
23862
|
+
const file2 = join11(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
23663
23863
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23664
23864
|
}
|
|
23665
|
-
const userFile =
|
|
23865
|
+
const userFile = join11(home, CLAUDE_USER_CONFIG_FILE);
|
|
23666
23866
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23667
|
-
dataDir(
|
|
23867
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23668
23868
|
}
|
|
23669
23869
|
function scanCodex(agentHome, out) {
|
|
23670
|
-
const hooksFile =
|
|
23870
|
+
const hooksFile = join11(agentHome, HOOKS_JSON_FILE);
|
|
23671
23871
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23672
23872
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23673
23873
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23674
23874
|
}
|
|
23675
23875
|
}
|
|
23676
|
-
const tomlFile =
|
|
23876
|
+
const tomlFile = join11(agentHome, CONFIG_TOML_FILE);
|
|
23677
23877
|
const config4 = readTomlValue(tomlFile);
|
|
23678
23878
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23679
23879
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23680
23880
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
23681
23881
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23682
23882
|
}
|
|
23683
|
-
dataDir(
|
|
23883
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23684
23884
|
}
|
|
23685
23885
|
function scanGemini(agentHome, out) {
|
|
23686
|
-
const file2 =
|
|
23886
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23687
23887
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23688
23888
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23689
23889
|
}
|
|
23690
|
-
dataDir(
|
|
23890
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23691
23891
|
}
|
|
23692
23892
|
function scanVscode(agentHome, project, out) {
|
|
23693
23893
|
if (project !== void 0) {
|
|
23694
|
-
v1HookFile(
|
|
23695
|
-
const mcpFile2 =
|
|
23894
|
+
v1HookFile(join11(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
23895
|
+
const mcpFile2 = join11(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
23696
23896
|
const doc = readJson(mcpFile2);
|
|
23697
23897
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23698
23898
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23699
23899
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23700
23900
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23701
23901
|
}
|
|
23702
|
-
|
|
23902
|
+
const sessions = join11(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
23903
|
+
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
23703
23904
|
}
|
|
23704
|
-
dataDir(
|
|
23905
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23705
23906
|
}
|
|
23706
23907
|
function jsonFiles(dir) {
|
|
23707
23908
|
try {
|
|
@@ -23711,10 +23912,10 @@ function jsonFiles(dir) {
|
|
|
23711
23912
|
}
|
|
23712
23913
|
}
|
|
23713
23914
|
function scanKiro(agentHome, project, out) {
|
|
23714
|
-
const agentsDir =
|
|
23715
|
-
const defaultFile =
|
|
23915
|
+
const agentsDir = join11(agentHome, KIRO_AGENTS_DIR);
|
|
23916
|
+
const defaultFile = join11(agentHome, ...KIRO_AGENT_FILE);
|
|
23716
23917
|
for (const name of jsonFiles(agentsDir)) {
|
|
23717
|
-
const file2 =
|
|
23918
|
+
const file2 = join11(agentsDir, name);
|
|
23718
23919
|
const doc = readJson(file2);
|
|
23719
23920
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23720
23921
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23725,46 +23926,48 @@ function scanKiro(agentHome, project, out) {
|
|
|
23725
23926
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23726
23927
|
}
|
|
23727
23928
|
}
|
|
23728
|
-
const steeringDocs = [
|
|
23729
|
-
if (project !== void 0) steeringDocs.push(
|
|
23929
|
+
const steeringDocs = [join11(agentHome, ...KIRO_STEERING_FILE)];
|
|
23930
|
+
if (project !== void 0) steeringDocs.push(join11(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
23730
23931
|
for (const file2 of steeringDocs) {
|
|
23731
23932
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
23732
23933
|
}
|
|
23733
|
-
dataDir(
|
|
23934
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23734
23935
|
}
|
|
23735
23936
|
function piNpmIsCurrent(piAgentDir) {
|
|
23736
|
-
const doc = readJson(
|
|
23937
|
+
const doc = readJson(join11(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23737
23938
|
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23738
23939
|
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
23739
23940
|
}
|
|
23740
23941
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23741
|
-
const file2 =
|
|
23942
|
+
const file2 = join11(piAgentDir, SETTINGS_FILE);
|
|
23742
23943
|
const doc = readJson(file2);
|
|
23743
23944
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23744
23945
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23745
23946
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
23947
|
+
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
23746
23948
|
});
|
|
23747
|
-
dataDir(
|
|
23949
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23748
23950
|
}
|
|
23749
23951
|
function scanOpencode(agentHome, out) {
|
|
23750
23952
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
23751
|
-
const file2 =
|
|
23953
|
+
const file2 = join11(agentHome, name);
|
|
23752
23954
|
const doc = readJson(file2);
|
|
23753
23955
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
23754
23956
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
23755
23957
|
if (spec === V1_OPENCODE_PLUGIN_SPEC) out.push(finding(file2, keyPath(OPENCODE_PLUGIN_KEY, i), V1_REASON.opencodePlugin));
|
|
23958
|
+
if (spec === OPENCODE_GIT_SPEC) out.push(finding(file2, keyPath(OPENCODE_PLUGIN_KEY, i), V1_REASON.opencodeGit));
|
|
23756
23959
|
});
|
|
23757
23960
|
return;
|
|
23758
23961
|
}
|
|
23759
23962
|
}
|
|
23760
23963
|
function scanZcode(agentHome, out) {
|
|
23761
|
-
const configFile =
|
|
23964
|
+
const configFile = join11(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
23762
23965
|
const config4 = readJson(configFile);
|
|
23763
23966
|
const events = isObj(config4) && isObj(config4[HOOKS_KEY]) ? config4[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
23764
23967
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
23765
23968
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
23766
23969
|
}
|
|
23767
|
-
const hooksFile =
|
|
23970
|
+
const hooksFile = join11(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
23768
23971
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23769
23972
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
23770
23973
|
}
|
|
@@ -23788,14 +23991,14 @@ function firstTmpMatch(dir) {
|
|
|
23788
23991
|
}
|
|
23789
23992
|
}
|
|
23790
23993
|
function scanAll(home, tmp, out) {
|
|
23791
|
-
const root =
|
|
23792
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
23994
|
+
const root = join11(home, DATA_ROOT.slice(1));
|
|
23995
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join11(root, name), V1_REASON.dataRoot, out);
|
|
23793
23996
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
23794
23997
|
}
|
|
23795
23998
|
function detectV1(agent, home, scope = {}) {
|
|
23796
23999
|
const out = [];
|
|
23797
24000
|
const project = scope.project;
|
|
23798
|
-
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 :
|
|
24001
|
+
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]);
|
|
23799
24002
|
switch (agent) {
|
|
23800
24003
|
case "claude-code":
|
|
23801
24004
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -23808,11 +24011,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23808
24011
|
break;
|
|
23809
24012
|
case "qwen":
|
|
23810
24013
|
claudeShapeSettings(agentHome, out);
|
|
23811
|
-
dataDir(
|
|
24014
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23812
24015
|
break;
|
|
23813
24016
|
case "copilot-cli":
|
|
23814
|
-
v1HookFile(
|
|
23815
|
-
dataDir(
|
|
24017
|
+
v1HookFile(join11(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24018
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23816
24019
|
break;
|
|
23817
24020
|
case "vscode":
|
|
23818
24021
|
scanVscode(agentHome, project, out);
|
|
@@ -23821,7 +24024,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23821
24024
|
scanKiro(agentHome, project, out);
|
|
23822
24025
|
break;
|
|
23823
24026
|
case "pi":
|
|
23824
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24027
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join11(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
23825
24028
|
break;
|
|
23826
24029
|
// D-WIN-PIDIR-1: empty is unset
|
|
23827
24030
|
case "opencode":
|
|
@@ -23837,7 +24040,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23837
24040
|
|
|
23838
24041
|
// src/core/ops/plugin-root.ts
|
|
23839
24042
|
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23840
|
-
import { dirname as dirname7, isAbsolute as isAbsolute2, join as
|
|
24043
|
+
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join12, sep as sep4 } from "node:path";
|
|
23841
24044
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23842
24045
|
function missing(agent, path8) {
|
|
23843
24046
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -23885,8 +24088,8 @@ var readOrNull = (file2) => {
|
|
|
23885
24088
|
};
|
|
23886
24089
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
23887
24090
|
function enabledPlugins(claudeDir, project) {
|
|
23888
|
-
const files = [
|
|
23889
|
-
if (project !== void 0) files.push(
|
|
24091
|
+
const files = [join12(claudeDir, SETTINGS_FILE)];
|
|
24092
|
+
if (project !== void 0) files.push(join12(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join12(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
23890
24093
|
const out = {};
|
|
23891
24094
|
for (const file2 of files) {
|
|
23892
24095
|
const text = readOrNull(file2);
|
|
@@ -23902,7 +24105,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
23902
24105
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23903
24106
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
23904
24107
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
23905
|
-
const record6 = readOrNull(
|
|
24108
|
+
const record6 = readOrNull(join12(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
23906
24109
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
23907
24110
|
if (recorded.length === 0) return { record: false };
|
|
23908
24111
|
const live = recorded.filter((r) => existsSync6(r.installPath));
|
|
@@ -23925,18 +24128,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
23925
24128
|
}
|
|
23926
24129
|
function marketplaceRoot(adapter, env, worktree) {
|
|
23927
24130
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23928
|
-
const plugins =
|
|
23929
|
-
const cache =
|
|
24131
|
+
const plugins = join12(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24132
|
+
const cache = join12(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23930
24133
|
const script = process.argv[1];
|
|
23931
24134
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23932
24135
|
const choice = marketplaceChoice(env, worktree);
|
|
23933
24136
|
if ("root" in choice) return choice.root;
|
|
23934
24137
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
23935
24138
|
const cacheReal = realOrNull(cache);
|
|
23936
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal +
|
|
23937
|
-
const pattern =
|
|
24139
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync6(join12(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24140
|
+
const pattern = join12(cache, "*", PLUGIN_NAME);
|
|
23938
24141
|
if (!existsSync6(cache)) throw missing(adapter.id, pattern);
|
|
23939
|
-
const found = readdirSync3(cache).sort().map((marketplace) =>
|
|
24142
|
+
const found = readdirSync3(cache).sort().map((marketplace) => join12(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
|
|
23940
24143
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
23941
24144
|
return found[0];
|
|
23942
24145
|
}
|
|
@@ -23961,9 +24164,9 @@ function candidate(adapter, env, worktree) {
|
|
|
23961
24164
|
case "hooks+mcp":
|
|
23962
24165
|
return configEntryRoot(adapter, env);
|
|
23963
24166
|
case "extension":
|
|
23964
|
-
return
|
|
24167
|
+
return join12(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join12(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
23965
24168
|
case "plugin":
|
|
23966
|
-
return
|
|
24169
|
+
return join12(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
23967
24170
|
case "in-process":
|
|
23968
24171
|
return dirname7(fileURLToPath2(import.meta.url));
|
|
23969
24172
|
}
|
|
@@ -24070,7 +24273,7 @@ function composeMatcher(row5, event) {
|
|
|
24070
24273
|
}
|
|
24071
24274
|
var lastSegment = (p) => {
|
|
24072
24275
|
let at2 = -1;
|
|
24073
|
-
for (const
|
|
24276
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, p.lastIndexOf(sep5));
|
|
24074
24277
|
return p.slice(at2 + 1);
|
|
24075
24278
|
};
|
|
24076
24279
|
function splitHead(command) {
|
|
@@ -24092,7 +24295,7 @@ function isOwnCommand(command, agent) {
|
|
|
24092
24295
|
if (!split.rest.endsWith(tail) || split.rest.length <= tail.length) return false;
|
|
24093
24296
|
let script = split.rest.slice(0, split.rest.length - tail.length);
|
|
24094
24297
|
if (script.startsWith(SHELL_QUOTE) && script.endsWith(SHELL_QUOTE) && script.length > 1) script = script.slice(1, -1);
|
|
24095
|
-
return script === HOOK_ENTRY_FILE || HOOK_SCRIPT_SEPS.some((
|
|
24298
|
+
return script === HOOK_ENTRY_FILE || HOOK_SCRIPT_SEPS.some((sep5) => script.endsWith(sep5 + HOOK_ENTRY_FILE));
|
|
24096
24299
|
}
|
|
24097
24300
|
function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
24098
24301
|
const out = [];
|
|
@@ -24123,11 +24326,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24123
24326
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24124
24327
|
function mcpFile(row5, home, env) {
|
|
24125
24328
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24126
|
-
if (row5.id === "codex") return
|
|
24329
|
+
if (row5.id === "codex") return join13(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24127
24330
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24128
|
-
if (row5.id === "opencode") return
|
|
24331
|
+
if (row5.id === "opencode") return join13(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24129
24332
|
if (row5.id === "pi") {
|
|
24130
|
-
return
|
|
24333
|
+
return join13(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24131
24334
|
}
|
|
24132
24335
|
return null;
|
|
24133
24336
|
}
|
|
@@ -24140,27 +24343,27 @@ function codexNativeDir(env, home) {
|
|
|
24140
24343
|
const codexDir = codexDirOf(env, home);
|
|
24141
24344
|
let enabled;
|
|
24142
24345
|
try {
|
|
24143
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24346
|
+
enabled = hostConfigValueAt(readParsed("codex", join13(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24144
24347
|
} catch {
|
|
24145
24348
|
return null;
|
|
24146
24349
|
}
|
|
24147
24350
|
if (enabled !== true) return null;
|
|
24148
|
-
const cache =
|
|
24351
|
+
const cache = join13(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24149
24352
|
if (!existsSync8(cache)) return null;
|
|
24150
24353
|
const found = [];
|
|
24151
24354
|
for (const market of readdirSync4(cache)) {
|
|
24152
|
-
const plugin =
|
|
24355
|
+
const plugin = join13(cache, market, SERVER_KEY);
|
|
24153
24356
|
if (!existsSync8(plugin)) continue;
|
|
24154
24357
|
for (const version4 of readdirSync4(plugin).sort()) {
|
|
24155
|
-
const dir =
|
|
24156
|
-
if (existsSync8(
|
|
24358
|
+
const dir = join13(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
24359
|
+
if (existsSync8(join13(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24157
24360
|
}
|
|
24158
24361
|
}
|
|
24159
24362
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24160
24363
|
}
|
|
24161
24364
|
function nativeMcpWrong(dir, row5) {
|
|
24162
24365
|
try {
|
|
24163
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
24366
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join13(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
24164
24367
|
if (!isObject4(entry)) return true;
|
|
24165
24368
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24166
24369
|
const script = args[0];
|
|
@@ -24175,10 +24378,19 @@ function isOwnOpencodeEntry(entry, key, own4) {
|
|
|
24175
24378
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own4.includes(spec)) return true;
|
|
24176
24379
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
24177
24380
|
}
|
|
24381
|
+
function opencodeMcpOwn(entry) {
|
|
24382
|
+
if (!isObject4(entry)) return false;
|
|
24383
|
+
const cmd = Array.isArray(entry[OPENCODE_MCP_COMMAND_FIELD]) ? entry[OPENCODE_MCP_COMMAND_FIELD] : [entry[MCP_COMMAND_FIELD], ...list2(entry[MCP_ARGS_FIELD])];
|
|
24384
|
+
const [node3, script, flag, agent] = cmd;
|
|
24385
|
+
return isNodeCommand(node3) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
24386
|
+
}
|
|
24178
24387
|
function opencodeListed(file2) {
|
|
24179
24388
|
const { value } = readParsed("opencode", file2);
|
|
24180
|
-
const
|
|
24181
|
-
|
|
24389
|
+
const bundle = opencodePluginFile();
|
|
24390
|
+
const own4 = [bundle, join13(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
24391
|
+
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own4)))) return true;
|
|
24392
|
+
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
24393
|
+
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
24182
24394
|
}
|
|
24183
24395
|
function mcpWrong(row5, home, env, worktree) {
|
|
24184
24396
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
@@ -24199,7 +24411,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24199
24411
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24200
24412
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24201
24413
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24202
|
-
const file2 = native !== null ?
|
|
24414
|
+
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);
|
|
24203
24415
|
return file2;
|
|
24204
24416
|
}
|
|
24205
24417
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24210,7 +24422,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24210
24422
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24211
24423
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24212
24424
|
if (row5.id === "codex") {
|
|
24213
|
-
const config4 = readParsed(row5.id,
|
|
24425
|
+
const config4 = readParsed(row5.id, join13(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24214
24426
|
if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24215
24427
|
}
|
|
24216
24428
|
} catch {
|
|
@@ -24254,7 +24466,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24254
24466
|
function checkPiInstall(env, home, worktree) {
|
|
24255
24467
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24256
24468
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24257
|
-
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
24469
|
+
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join13(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
24258
24470
|
}
|
|
24259
24471
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24260
24472
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24273,10 +24485,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24273
24485
|
}
|
|
24274
24486
|
function checkDoubleFire(agent, worktree) {
|
|
24275
24487
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24276
|
-
const claude = parsedOrNull(agent,
|
|
24488
|
+
const claude = parsedOrNull(agent, join13(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24277
24489
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24278
24490
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24279
|
-
const vscode = parsedOrNull(agent,
|
|
24491
|
+
const vscode = parsedOrNull(agent, join13(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24280
24492
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24281
24493
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24282
24494
|
}
|
|
@@ -24287,7 +24499,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24287
24499
|
const mcp = mcpFile(row5, home, env);
|
|
24288
24500
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24289
24501
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24290
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
24502
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join13(native, CODEX_PLUGIN_MCP_FILE) });
|
|
24291
24503
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24292
24504
|
if (spec !== null) {
|
|
24293
24505
|
try {
|
|
@@ -24327,7 +24539,7 @@ async function loadSqlite2() {
|
|
|
24327
24539
|
}
|
|
24328
24540
|
}
|
|
24329
24541
|
function openRead(sqlite, path8) {
|
|
24330
|
-
return
|
|
24542
|
+
return openReadOnlyHandle(sqlite, path8);
|
|
24331
24543
|
}
|
|
24332
24544
|
var cell = (row5) => Object.values(row5)[0];
|
|
24333
24545
|
function readSchema(raw) {
|
|
@@ -24401,7 +24613,7 @@ async function checkIndex(project) {
|
|
|
24401
24613
|
|
|
24402
24614
|
// src/core/ops/doctor-env.ts
|
|
24403
24615
|
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
24404
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24616
|
+
import { isAbsolute as isAbsolute3, join as join14, relative as relative4 } from "node:path";
|
|
24405
24617
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
24406
24618
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
24407
24619
|
}
|
|
@@ -24413,7 +24625,7 @@ function fail4(id, detail, fixCommand) {
|
|
|
24413
24625
|
}
|
|
24414
24626
|
function bundleVersion(bundleDir2) {
|
|
24415
24627
|
try {
|
|
24416
|
-
const v = JSON.parse(readFileSync10(
|
|
24628
|
+
const v = JSON.parse(readFileSync10(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24417
24629
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24418
24630
|
} catch {
|
|
24419
24631
|
return void 0;
|
|
@@ -24508,12 +24720,12 @@ async function checkVersion(i) {
|
|
|
24508
24720
|
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24509
24721
|
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24510
24722
|
const tag2 = channelOf(i.version);
|
|
24511
|
-
const
|
|
24723
|
+
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24512
24724
|
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24513
24725
|
if (npm.ok) return versionRow(head, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
24514
24726
|
let cause = D1_GIT_MISSING;
|
|
24515
|
-
if (
|
|
24516
|
-
const r = await runProcess([
|
|
24727
|
+
if (git2 !== null) {
|
|
24728
|
+
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
24517
24729
|
cwd: i.cwd,
|
|
24518
24730
|
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
24519
24731
|
signal: i.signal,
|
|
@@ -24527,7 +24739,7 @@ async function checkVersion(i) {
|
|
|
24527
24739
|
cause = gitCause(r, i.timeoutMs);
|
|
24528
24740
|
}
|
|
24529
24741
|
}
|
|
24530
|
-
return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause,
|
|
24742
|
+
return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
24531
24743
|
}
|
|
24532
24744
|
function numbers(v) {
|
|
24533
24745
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -24564,7 +24776,7 @@ function checkMcp(ctx) {
|
|
|
24564
24776
|
}
|
|
24565
24777
|
function piCwdInside(worktree, piCwd) {
|
|
24566
24778
|
if (piCwd === void 0 || !existsSync10(piCwd)) return false;
|
|
24567
|
-
const rel =
|
|
24779
|
+
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24568
24780
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24569
24781
|
}
|
|
24570
24782
|
function checkProject(i) {
|
|
@@ -24588,6 +24800,15 @@ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11
|
|
|
24588
24800
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24589
24801
|
import path7 from "node:path";
|
|
24590
24802
|
|
|
24803
|
+
// src/core/sandbox/host-node.ts
|
|
24804
|
+
var BUN_BE_BUN_ENV = "BUN_BE_BUN";
|
|
24805
|
+
function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
|
|
24806
|
+
if (host.bun === void 0) return { file: host.execPath, env };
|
|
24807
|
+
const node3 = find2("javascript", env);
|
|
24808
|
+
if (node3 !== null) return { file: node3, env };
|
|
24809
|
+
return { file: host.execPath, env: { ...env, [BUN_BE_BUN_ENV]: "1" } };
|
|
24810
|
+
}
|
|
24811
|
+
|
|
24591
24812
|
// src/setup/codex-trust.ts
|
|
24592
24813
|
import { createHash } from "node:crypto";
|
|
24593
24814
|
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
@@ -24707,14 +24928,14 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
24707
24928
|
function askPluginHooks(env, pluginId, cwd) {
|
|
24708
24929
|
const bin = whichBin("codex", env);
|
|
24709
24930
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
24710
|
-
return new Promise((
|
|
24931
|
+
return new Promise((resolve9) => {
|
|
24711
24932
|
let asked;
|
|
24712
24933
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
24713
24934
|
let f;
|
|
24714
24935
|
try {
|
|
24715
24936
|
f = spawnForm(bin, ["app-server"], env);
|
|
24716
24937
|
} catch {
|
|
24717
|
-
|
|
24938
|
+
resolve9({ kind: "silent" });
|
|
24718
24939
|
return;
|
|
24719
24940
|
}
|
|
24720
24941
|
const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -24724,7 +24945,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
24724
24945
|
let result;
|
|
24725
24946
|
const settle3 = () => {
|
|
24726
24947
|
clearTimeout(grace);
|
|
24727
|
-
|
|
24948
|
+
resolve9(done_(result));
|
|
24728
24949
|
};
|
|
24729
24950
|
let grace;
|
|
24730
24951
|
const finish2 = (v) => {
|
|
@@ -24794,8 +25015,8 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
24794
25015
|
if (!bad.length) return void 0;
|
|
24795
25016
|
const counts = /* @__PURE__ */ new Map();
|
|
24796
25017
|
for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
|
|
24797
|
-
const
|
|
24798
|
-
const state =
|
|
25018
|
+
const words2 = [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1));
|
|
25019
|
+
const state = words2.length === 1 ? words2[0][0] : `${words2.map(([w]) => w).join(" or ")} (${words2.map(([w, n]) => `${n} ${w}`).join(", ")})`;
|
|
24799
25020
|
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
24800
25021
|
}
|
|
24801
25022
|
|
|
@@ -24907,9 +25128,10 @@ function isReadShape(stdout) {
|
|
|
24907
25128
|
async function readProbe(i, timeoutMs, ranged) {
|
|
24908
25129
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
24909
25130
|
try {
|
|
24910
|
-
const
|
|
25131
|
+
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
25132
|
+
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24911
25133
|
cwd: i.bundleDir,
|
|
24912
|
-
env:
|
|
25134
|
+
env: node3.env,
|
|
24913
25135
|
signal: i.signal,
|
|
24914
25136
|
timeoutMs,
|
|
24915
25137
|
stdin: JSON.stringify(readProbePayload(i.worktree ?? home, ranged))
|
|
@@ -24979,7 +25201,8 @@ async function checkHookRoundTrip(i) {
|
|
|
24979
25201
|
const timeoutMs = i.timeoutMs ?? HOOK_TIMEOUT_MS;
|
|
24980
25202
|
const bareMs = i.bareMs ?? (async () => {
|
|
24981
25203
|
const t = performance.now();
|
|
24982
|
-
|
|
25204
|
+
const node3 = nodeLaunch(i.env);
|
|
25205
|
+
await runProcess([node3.file, "-e", ""], { cwd: i.bundleDir, env: node3.env, signal: i.signal, timeoutMs });
|
|
24983
25206
|
return performance.now() - t;
|
|
24984
25207
|
});
|
|
24985
25208
|
const hookWalls = [];
|
|
@@ -24987,9 +25210,10 @@ async function checkHookRoundTrip(i) {
|
|
|
24987
25210
|
let ms = 0;
|
|
24988
25211
|
for (let n = 1; n <= maxPairs; n++) {
|
|
24989
25212
|
const start = now();
|
|
24990
|
-
const
|
|
25213
|
+
const node3 = nodeLaunch(i.env);
|
|
25214
|
+
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
24991
25215
|
cwd: i.bundleDir,
|
|
24992
|
-
env:
|
|
25216
|
+
env: node3.env,
|
|
24993
25217
|
signal: i.signal,
|
|
24994
25218
|
timeoutMs,
|
|
24995
25219
|
stdin: JSON.stringify(payloadFor(i.agent, fixture.payload, i.worktree))
|
|
@@ -25008,16 +25232,16 @@ async function checkHookRoundTrip(i) {
|
|
|
25008
25232
|
|
|
25009
25233
|
// src/core/ops/db-heal.ts
|
|
25010
25234
|
import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
25011
|
-
import { basename as basename4, dirname as dirname8, join as
|
|
25235
|
+
import { basename as basename4, dirname as dirname8, join as join16 } from "node:path";
|
|
25012
25236
|
|
|
25013
25237
|
// src/core/store/owners.ts
|
|
25014
25238
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
25015
|
-
import { basename as basename3, join as
|
|
25239
|
+
import { basename as basename3, join as join15 } from "node:path";
|
|
25016
25240
|
function ownersDir(configDir, projectKey) {
|
|
25017
|
-
return
|
|
25241
|
+
return join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25018
25242
|
}
|
|
25019
25243
|
function ownerFile(configDir, projectKey, serverId) {
|
|
25020
|
-
return
|
|
25244
|
+
return join15(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
|
|
25021
25245
|
}
|
|
25022
25246
|
function errCode2(err) {
|
|
25023
25247
|
return err.code;
|
|
@@ -25052,7 +25276,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
25052
25276
|
const live = [];
|
|
25053
25277
|
for (const name of names) {
|
|
25054
25278
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25055
|
-
const file2 =
|
|
25279
|
+
const file2 = join15(dir, name);
|
|
25056
25280
|
let text;
|
|
25057
25281
|
try {
|
|
25058
25282
|
text = readFileSync12(file2, "utf8");
|
|
@@ -25076,7 +25300,7 @@ async function healLossless(dbPath) {
|
|
|
25076
25300
|
const tmp = dbPath + HEAL_TMP_SUFFIX;
|
|
25077
25301
|
rmSync4(tmp, { force: true });
|
|
25078
25302
|
try {
|
|
25079
|
-
const src =
|
|
25303
|
+
const src = openReadOnlyHandle({ DatabaseSync }, dbPath, { queryOnly: false });
|
|
25080
25304
|
try {
|
|
25081
25305
|
src.prepare("VACUUM INTO ?").run(tmp);
|
|
25082
25306
|
} finally {
|
|
@@ -25124,7 +25348,7 @@ function utcStamp(now) {
|
|
|
25124
25348
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
25125
25349
|
}
|
|
25126
25350
|
function makeOrphanDir(projectDir) {
|
|
25127
|
-
const base =
|
|
25351
|
+
const base = join16(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
25128
25352
|
for (let n = 1; ; n += 1) {
|
|
25129
25353
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
25130
25354
|
try {
|
|
@@ -25141,7 +25365,7 @@ async function healOrphan(project, files, row5) {
|
|
|
25141
25365
|
try {
|
|
25142
25366
|
dir = makeOrphanDir(dirname8(project.dbPath));
|
|
25143
25367
|
for (const f of files) {
|
|
25144
|
-
const to =
|
|
25368
|
+
const to = join16(dir, basename4(f.path));
|
|
25145
25369
|
renameWithRetry(f.path, to);
|
|
25146
25370
|
moved.push({ path: to, bytes: f.bytes });
|
|
25147
25371
|
}
|
|
@@ -25209,7 +25433,7 @@ function buildReportHead(input) {
|
|
|
25209
25433
|
// src/core/ops/doctor-issue.ts
|
|
25210
25434
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
25211
25435
|
import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25212
|
-
import { delimiter, join as
|
|
25436
|
+
import { delimiter, join as join17 } from "node:path";
|
|
25213
25437
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
25214
25438
|
function tildeOf(env) {
|
|
25215
25439
|
const home = homeDirOf(env);
|
|
@@ -25250,8 +25474,8 @@ function onPath(env, tool) {
|
|
|
25250
25474
|
const out = [];
|
|
25251
25475
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25252
25476
|
if (dir === "") continue;
|
|
25253
|
-
for (const n of names) if (existsSync14(
|
|
25254
|
-
out.push(
|
|
25477
|
+
for (const n of names) if (existsSync14(join17(dir, n))) {
|
|
25478
|
+
out.push(join17(dir, n));
|
|
25255
25479
|
break;
|
|
25256
25480
|
}
|
|
25257
25481
|
}
|
|
@@ -25297,8 +25521,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25297
25521
|
const home = homeDirOf(env);
|
|
25298
25522
|
const files = configPaths(adapter, env, worktree);
|
|
25299
25523
|
if (home !== null) {
|
|
25300
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
25301
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
25524
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join17(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
25525
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join17(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
25302
25526
|
}
|
|
25303
25527
|
const out = [];
|
|
25304
25528
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -25381,9 +25605,9 @@ async function buildIssueBody(i) {
|
|
|
25381
25605
|
async function writeIssueReport(i) {
|
|
25382
25606
|
const tilde = tildeOf(i.env);
|
|
25383
25607
|
const body = await buildIssueBody(i);
|
|
25384
|
-
const dir =
|
|
25608
|
+
const dir = join17(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
25385
25609
|
mkdirSync6(dir, { recursive: true });
|
|
25386
|
-
const file2 =
|
|
25610
|
+
const file2 = join17(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
25387
25611
|
writeFileSync3(file2, body);
|
|
25388
25612
|
const shown2 = tilde(file2);
|
|
25389
25613
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -25440,11 +25664,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25440
25664
|
}
|
|
25441
25665
|
}
|
|
25442
25666
|
function ownServerId(configDir, projectKey) {
|
|
25443
|
-
const dir =
|
|
25667
|
+
const dir = join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25444
25668
|
if (!existsSync15(dir)) return "";
|
|
25445
25669
|
for (const name of readdirSync6(dir)) {
|
|
25446
25670
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25447
|
-
if (readFileSync14(
|
|
25671
|
+
if (readFileSync14(join18(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25448
25672
|
}
|
|
25449
25673
|
return "";
|
|
25450
25674
|
}
|
|
@@ -25458,7 +25682,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
25458
25682
|
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 }),
|
|
25459
25683
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
25460
25684
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
25461
|
-
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)) }),
|
|
25685
|
+
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)) }),
|
|
25462
25686
|
D5: () => hookRow(ctx, adapter, host),
|
|
25463
25687
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
25464
25688
|
D6: () => checkMcp(ctx),
|
|
@@ -25499,13 +25723,13 @@ function reportEnv(env) {
|
|
|
25499
25723
|
async function doctorReply(ctx, host) {
|
|
25500
25724
|
const adapter = getAdapter(ctx.project.agent);
|
|
25501
25725
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
25502
|
-
const
|
|
25503
|
-
const command = adapter.id === "pi" ?
|
|
25726
|
+
const failed = rows.some((r) => r.status === "FAIL");
|
|
25727
|
+
const command = adapter.id === "pi" ? failed ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
25504
25728
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
25505
25729
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
25506
25730
|
const table3 = buildReport(input);
|
|
25507
25731
|
let notes = [];
|
|
25508
|
-
if (
|
|
25732
|
+
if (failed) {
|
|
25509
25733
|
try {
|
|
25510
25734
|
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
25511
25735
|
} catch (err) {
|
|
@@ -25541,7 +25765,7 @@ var ctxDoctor = Object.freeze({
|
|
|
25541
25765
|
// src/core/tools/execute.ts
|
|
25542
25766
|
import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25543
25767
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25544
|
-
import { dirname as dirname10, join as
|
|
25768
|
+
import { dirname as dirname10, join as join19, parse as parse3, resolve as resolve7 } from "node:path";
|
|
25545
25769
|
|
|
25546
25770
|
// src/core/sandbox/win-build.ts
|
|
25547
25771
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -25587,7 +25811,6 @@ var ctxExecuteSchema = external_exports.object({
|
|
|
25587
25811
|
background: external_exports.boolean().optional(),
|
|
25588
25812
|
summary: external_exports.boolean().optional()
|
|
25589
25813
|
}, { error: unknownField }).strict();
|
|
25590
|
-
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
25591
25814
|
var SCRIPT_EXT = Object.freeze({
|
|
25592
25815
|
javascript: ".js",
|
|
25593
25816
|
typescript: ".ts",
|
|
@@ -25606,7 +25829,7 @@ var LAUNCHER = [
|
|
|
25606
25829
|
'const { rmSync } = require("node:fs");',
|
|
25607
25830
|
"const [mode, dir, ...argv] = process.argv.slice(1);",
|
|
25608
25831
|
'if (mode === "start") {',
|
|
25609
|
-
' const b = spawn(process.execPath, [...process.execArgv, "--", "run", dir, ...argv], { detached: true, stdio: "ignore", windowsHide: true });',
|
|
25832
|
+
' const b = spawn(process.execPath, [...process.execArgv.filter((a) => a !== "--"), "--", "run", dir, ...argv], { detached: true, stdio: "ignore", windowsHide: true });',
|
|
25610
25833
|
" b.unref();",
|
|
25611
25834
|
" process.stdout.write(String(b.pid));",
|
|
25612
25835
|
"} else {",
|
|
@@ -25689,7 +25912,7 @@ async function handler3(raw, ctx) {
|
|
|
25689
25912
|
const cwd = ctx.project.worktree;
|
|
25690
25913
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
25691
25914
|
if (input.file !== void 0) {
|
|
25692
|
-
const abs =
|
|
25915
|
+
const abs = resolve7(cwd, input.file);
|
|
25693
25916
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
25694
25917
|
if (bad !== null) return fail5(bad);
|
|
25695
25918
|
extra.CTX_FILE = abs;
|
|
@@ -25706,13 +25929,14 @@ async function handler3(raw, ctx) {
|
|
|
25706
25929
|
if (takesDashC(input.language, runtime)) {
|
|
25707
25930
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
25708
25931
|
} else {
|
|
25709
|
-
tmpDir = mkdtempSync2(
|
|
25710
|
-
const file2 =
|
|
25932
|
+
tmpDir = mkdtempSync2(join19(tmpdir3(), TMP_PREFIX));
|
|
25933
|
+
const file2 = join19(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25711
25934
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
25712
25935
|
argv = scriptArgv(input.language, runtime, file2);
|
|
25713
25936
|
}
|
|
25714
25937
|
if (input.background === true) {
|
|
25715
|
-
const
|
|
25938
|
+
const node3 = nodeLaunch(env);
|
|
25939
|
+
const r2 = await runProcess([node3.file, "-e", LAUNCHER, "--", "start", tmpDir ?? "", ...argv], { cwd, env: node3.env, signal: ctx.signal, timeoutMs });
|
|
25716
25940
|
const pid = r2.stdout.toString("utf8");
|
|
25717
25941
|
if (r2.exitCode !== 0 || pid === "" || !Number.isSafeInteger(Number(pid))) return fail5(spawnFailed(argv[0], cwd), journal);
|
|
25718
25942
|
handedOff = true;
|
|
@@ -25743,11 +25967,11 @@ var ctxExecute = {
|
|
|
25743
25967
|
|
|
25744
25968
|
// src/core/tools/index.ts
|
|
25745
25969
|
import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
|
|
25746
|
-
import { dirname as dirname11, extname, join as
|
|
25970
|
+
import { dirname as dirname11, extname, join as join21, relative as relative5, resolve as resolve8 } from "node:path";
|
|
25747
25971
|
|
|
25748
25972
|
// src/core/index/walk.ts
|
|
25749
25973
|
import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
25750
|
-
import { join as
|
|
25974
|
+
import { join as join20 } from "node:path";
|
|
25751
25975
|
var GITIGNORE = ".gitignore";
|
|
25752
25976
|
var GIT_DIR = ".git";
|
|
25753
25977
|
function walkDir(root, containmentRoot) {
|
|
@@ -25756,7 +25980,7 @@ function walkDir(root, containmentRoot) {
|
|
|
25756
25980
|
const found = [];
|
|
25757
25981
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
25758
25982
|
found.sort(compareFound);
|
|
25759
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25983
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join20(...f.dir, f.name) }));
|
|
25760
25984
|
}
|
|
25761
25985
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
25762
25986
|
let entries;
|
|
@@ -25765,10 +25989,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25765
25989
|
} catch {
|
|
25766
25990
|
return;
|
|
25767
25991
|
}
|
|
25768
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
25992
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join20(abs, GITIGNORE), rel)) : parent;
|
|
25769
25993
|
for (const e of entries) {
|
|
25770
25994
|
if (e.name === GIT_DIR) continue;
|
|
25771
|
-
const path8 =
|
|
25995
|
+
const path8 = join20(abs, e.name);
|
|
25772
25996
|
let isDir = e.isDirectory();
|
|
25773
25997
|
let isFile = e.isFile();
|
|
25774
25998
|
let target = path8;
|
|
@@ -25902,11 +26126,24 @@ var PRIVATE_RANGES = [
|
|
|
25902
26126
|
["172.16.0.0", 12, "ipv4"],
|
|
25903
26127
|
["192.168.0.0", 16, "ipv4"],
|
|
25904
26128
|
["169.254.0.0", 16, "ipv4"],
|
|
25905
|
-
["0.0.0.0",
|
|
26129
|
+
["0.0.0.0", 8, "ipv4"],
|
|
26130
|
+
// D-SSRF-RANGES-1: "this network", not only 0.0.0.0
|
|
26131
|
+
["100.64.0.0", 10, "ipv4"],
|
|
26132
|
+
// D-SSRF-RANGES-1: shared address space (RFC 6598), cloud metadata lives here
|
|
26133
|
+
["198.18.0.0", 15, "ipv4"],
|
|
26134
|
+
// D-SSRF-RANGES-1: benchmark networks (RFC 2544)
|
|
26135
|
+
["240.0.0.0", 4, "ipv4"],
|
|
26136
|
+
// D-SSRF-RANGES-1: reserved and broadcast
|
|
25906
26137
|
["::1", 128, "ipv6"],
|
|
25907
26138
|
["::", 128, "ipv6"],
|
|
26139
|
+
["::", 96, "ipv6"],
|
|
26140
|
+
// D-SSRF-RANGES-1: IPv4-compatible (::a.b.c.d), deprecated, never a public origin
|
|
26141
|
+
["64:ff9b:1::", 48, "ipv6"],
|
|
26142
|
+
// D-SSRF-RANGES-1: local-use NAT64 (RFC 8215)
|
|
25908
26143
|
["fc00::", 7, "ipv6"],
|
|
25909
|
-
["fe80::", 10, "ipv6"]
|
|
26144
|
+
["fe80::", 10, "ipv6"],
|
|
26145
|
+
["fec0::", 10, "ipv6"]
|
|
26146
|
+
// D-SSRF-RANGES-1: site-local (RFC 3879)
|
|
25910
26147
|
];
|
|
25911
26148
|
var BLOCKED = new BlockList();
|
|
25912
26149
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
@@ -25959,9 +26196,41 @@ function pickProxy(u) {
|
|
|
25959
26196
|
const auth = p.username === "" ? void 0 : "Basic " + Buffer.from(decodeURIComponent(p.username) + ":" + decodeURIComponent(p.password)).toString("base64");
|
|
25960
26197
|
return { url: p, auth };
|
|
25961
26198
|
}
|
|
26199
|
+
function ipv6Words(address) {
|
|
26200
|
+
const zone = address.indexOf("%");
|
|
26201
|
+
const a = zone < 0 ? address : address.slice(0, zone);
|
|
26202
|
+
const words2 = (part) => {
|
|
26203
|
+
if (part === "") return [];
|
|
26204
|
+
const out = [];
|
|
26205
|
+
for (const w of part.split(":")) {
|
|
26206
|
+
if (w.includes(".")) {
|
|
26207
|
+
const q = w.split(".").map(Number);
|
|
26208
|
+
out.push(q[0] * 256 + q[1], q[2] * 256 + q[3]);
|
|
26209
|
+
} else out.push(parseInt(w, 16));
|
|
26210
|
+
}
|
|
26211
|
+
return out;
|
|
26212
|
+
};
|
|
26213
|
+
const gap = a.indexOf("::");
|
|
26214
|
+
if (gap < 0) return words2(a);
|
|
26215
|
+
const head = words2(a.slice(0, gap));
|
|
26216
|
+
const tail = words2(a.slice(gap + 2));
|
|
26217
|
+
return [...head, ...new Array(8 - head.length - tail.length).fill(0), ...tail];
|
|
26218
|
+
}
|
|
26219
|
+
function dotted(hi, lo) {
|
|
26220
|
+
return [hi >> 8, hi & 255, lo >> 8, lo & 255].join(".");
|
|
26221
|
+
}
|
|
26222
|
+
function embeddedIpv4(address) {
|
|
26223
|
+
const w = ipv6Words(address);
|
|
26224
|
+
if (w[0] === 100 && w[1] === 65435 && w[2] === 0 && w[3] === 0 && w[4] === 0 && w[5] === 0) {
|
|
26225
|
+
return dotted(w[6], w[7]);
|
|
26226
|
+
}
|
|
26227
|
+
if (w[0] === 8194) return dotted(w[1], w[2]);
|
|
26228
|
+
return void 0;
|
|
26229
|
+
}
|
|
25962
26230
|
function checkAddress(hostname2, address) {
|
|
25963
26231
|
const family = isIP(address);
|
|
25964
|
-
|
|
26232
|
+
const inner = family === 6 ? embeddedIpv4(address) : void 0;
|
|
26233
|
+
if (family === 0 || BLOCKED.check(address, family === 4 ? "ipv4" : "ipv6") || inner !== void 0 && BLOCKED.check(inner, "ipv4")) {
|
|
25965
26234
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
25966
26235
|
}
|
|
25967
26236
|
}
|
|
@@ -25985,18 +26254,18 @@ function request(u, conn, proxy, signal) {
|
|
|
25985
26254
|
const host = bare(u.hostname);
|
|
25986
26255
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
25987
26256
|
const path8 = u.pathname + u.search;
|
|
25988
|
-
return new Promise((
|
|
26257
|
+
return new Promise((resolve9, reject) => {
|
|
25989
26258
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
25990
26259
|
if (proxy === void 0) {
|
|
25991
26260
|
const mod = u.protocol === "https:" ? https : http;
|
|
25992
26261
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
25993
|
-
req.on("response",
|
|
26262
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25994
26263
|
return;
|
|
25995
26264
|
}
|
|
25996
26265
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
25997
26266
|
if (u.protocol === "http:") {
|
|
25998
26267
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
25999
|
-
req.on("response",
|
|
26268
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
26000
26269
|
return;
|
|
26001
26270
|
}
|
|
26002
26271
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -26016,16 +26285,16 @@ function request(u, conn, proxy, signal) {
|
|
|
26016
26285
|
headers: { host: u.host },
|
|
26017
26286
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
26018
26287
|
});
|
|
26019
|
-
req.on("response",
|
|
26288
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
26020
26289
|
});
|
|
26021
26290
|
tunnel.end();
|
|
26022
26291
|
});
|
|
26023
26292
|
}
|
|
26024
26293
|
function readBody(res) {
|
|
26025
|
-
return new Promise((
|
|
26294
|
+
return new Promise((resolve9, reject) => {
|
|
26026
26295
|
const parts = [];
|
|
26027
26296
|
res.on("data", (b) => parts.push(b));
|
|
26028
|
-
res.on("end", () =>
|
|
26297
|
+
res.on("end", () => resolve9(Buffer.concat(parts)));
|
|
26029
26298
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
26030
26299
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
26031
26300
|
});
|
|
@@ -28696,7 +28965,7 @@ var DomHandler = class {
|
|
|
28696
28965
|
var dist_exports2 = {};
|
|
28697
28966
|
__export(dist_exports2, {
|
|
28698
28967
|
DocumentPosition: () => DocumentPosition,
|
|
28699
|
-
append: () =>
|
|
28968
|
+
append: () => append2,
|
|
28700
28969
|
appendChild: () => appendChild,
|
|
28701
28970
|
compareDocumentPosition: () => compareDocumentPosition,
|
|
28702
28971
|
existsOne: () => existsOne,
|
|
@@ -29287,11 +29556,11 @@ function compareDocumentPosition(nodeA, nodeB) {
|
|
|
29287
29556
|
function uniqueSort(nodes) {
|
|
29288
29557
|
nodes = nodes.filter((node3, index, array4) => !array4.includes(node3, index + 1));
|
|
29289
29558
|
nodes.sort((a, b) => {
|
|
29290
|
-
const
|
|
29291
|
-
if (
|
|
29559
|
+
const relative6 = compareDocumentPosition(a, b);
|
|
29560
|
+
if (relative6 & DocumentPosition.PRECEDING) {
|
|
29292
29561
|
return -1;
|
|
29293
29562
|
}
|
|
29294
|
-
if (
|
|
29563
|
+
if (relative6 & DocumentPosition.FOLLOWING) {
|
|
29295
29564
|
return 1;
|
|
29296
29565
|
}
|
|
29297
29566
|
return 0;
|
|
@@ -29348,7 +29617,7 @@ function appendChild(parent, child) {
|
|
|
29348
29617
|
child.prev = null;
|
|
29349
29618
|
}
|
|
29350
29619
|
}
|
|
29351
|
-
function
|
|
29620
|
+
function append2(element2, next) {
|
|
29352
29621
|
removeElement(next);
|
|
29353
29622
|
const { parent } = element2;
|
|
29354
29623
|
const currentNext = element2.next;
|
|
@@ -29860,10 +30129,10 @@ function htmlToReadable(html, baseUrl) {
|
|
|
29860
30129
|
const st = { w: new Writer(), base, sawH1: false };
|
|
29861
30130
|
for (const n of contentRoot(doc.children)) walk2(st, n);
|
|
29862
30131
|
const body = st.w.result();
|
|
29863
|
-
const
|
|
29864
|
-
const text = !st.sawH1 && title !== "" &&
|
|
29865
|
-
const sparse =
|
|
29866
|
-
return { text: text === "" ? "" : text + "\n", title, words, sparse };
|
|
30132
|
+
const words2 = wordCount(body);
|
|
30133
|
+
const text = !st.sawH1 && title !== "" && words2 > 0 ? "# " + title + "\n\n" + body : body;
|
|
30134
|
+
const sparse = words2 < SPARSE_MAX_WORDS && html.length > SPARSE_RATIO * Math.max(text.length, 1);
|
|
30135
|
+
return { text: text === "" ? "" : text + "\n", title, words: words2, sparse };
|
|
29867
30136
|
}
|
|
29868
30137
|
|
|
29869
30138
|
// src/core/tools/index.ts
|
|
@@ -29903,13 +30172,13 @@ function missingOrOutside(given, abs, root) {
|
|
|
29903
30172
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29904
30173
|
}
|
|
29905
30174
|
function pathItems(input, project) {
|
|
29906
|
-
const abs =
|
|
30175
|
+
const abs = resolve8(project.worktree, input.path);
|
|
29907
30176
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
29908
|
-
const base =
|
|
30177
|
+
const base = relative5(project.worktree, abs);
|
|
29909
30178
|
if (statSync8(abs).isDirectory()) {
|
|
29910
30179
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
29911
30180
|
sourceKind: "path",
|
|
29912
|
-
label: pathLabel(
|
|
30181
|
+
label: pathLabel(join21(base, f.relPath)),
|
|
29913
30182
|
kind: kindOfPath(f.relPath),
|
|
29914
30183
|
read: () => readUtf8(f.absPath)
|
|
29915
30184
|
}));
|
|
@@ -30448,13 +30717,9 @@ var ctxStats = Object.freeze({
|
|
|
30448
30717
|
handler: handler7
|
|
30449
30718
|
});
|
|
30450
30719
|
|
|
30451
|
-
// src/core/tools/upgrade.ts
|
|
30452
|
-
import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
|
|
30453
|
-
import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
|
|
30454
|
-
|
|
30455
30720
|
// src/core/ops/host-write.ts
|
|
30456
30721
|
import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30457
|
-
import { dirname as dirname12, join as
|
|
30722
|
+
import { dirname as dirname12, join as join22 } from "node:path";
|
|
30458
30723
|
function defaultWrite(file2, text) {
|
|
30459
30724
|
writeFileSync5(file2, text, "utf8");
|
|
30460
30725
|
}
|
|
@@ -30463,14 +30728,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
30463
30728
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
30464
30729
|
switch (agent) {
|
|
30465
30730
|
case "opencode":
|
|
30466
|
-
return
|
|
30731
|
+
return join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
30467
30732
|
// D-WIN-OPENCODE-DIR-1
|
|
30468
30733
|
case "pi":
|
|
30469
|
-
return
|
|
30734
|
+
return join22(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
30735
|
+
case "gemini":
|
|
30736
|
+
return join22(geminiDirOf(env, home), SETTINGS_FILE);
|
|
30737
|
+
// D-R38-GEMINI-HOME-1
|
|
30470
30738
|
case "copilot-cli":
|
|
30471
30739
|
return null;
|
|
30472
30740
|
default:
|
|
30473
|
-
return
|
|
30741
|
+
return join22(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
30474
30742
|
}
|
|
30475
30743
|
}
|
|
30476
30744
|
function cell3(value) {
|
|
@@ -30519,96 +30787,16 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30519
30787
|
return result.edits.map((e) => toRow(current.path, e));
|
|
30520
30788
|
}
|
|
30521
30789
|
|
|
30522
|
-
// src/core/ops/plugin-swap.ts
|
|
30523
|
-
import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
30524
|
-
import { basename as basename6, join as join22, win32 as win322 } from "node:path";
|
|
30525
|
-
function linkTarget(path8, win) {
|
|
30526
|
-
if (!isLink(path8)) return null;
|
|
30527
|
-
const target = readlinkSync(path8);
|
|
30528
|
-
return win ? win322.basename(target) : target;
|
|
30529
|
-
}
|
|
30530
|
-
function isLink(path8) {
|
|
30531
|
-
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
30532
|
-
}
|
|
30533
|
-
function generations(agentDir) {
|
|
30534
|
-
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();
|
|
30535
|
-
}
|
|
30536
|
-
function settleLinks(link, tmp, old, opts) {
|
|
30537
|
-
if (isLink(tmp)) unlinkSync2(tmp);
|
|
30538
|
-
if (!isLink(old)) return;
|
|
30539
|
-
if (isLink(link)) unlinkSync2(old);
|
|
30540
|
-
else renameWithRetry(old, link, opts);
|
|
30541
|
-
}
|
|
30542
|
-
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
30543
|
-
const next = join22(agentDir, sha);
|
|
30544
|
-
if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
|
|
30545
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
30546
|
-
}
|
|
30547
|
-
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
30548
|
-
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
30549
|
-
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
30550
|
-
settleLinks(link, tmp, old, opts);
|
|
30551
|
-
const win = (opts.platform ?? process.platform) === "win32";
|
|
30552
|
-
const before = linkTarget(link, win);
|
|
30553
|
-
if (before === sha) return { current: next, previous: null, removed: [] };
|
|
30554
|
-
const symlink = opts.symlink ?? symlinkSync;
|
|
30555
|
-
if (win) symlink(next, tmp, PLUGIN_LINK_TYPE_WIN32);
|
|
30556
|
-
else symlink(sha, tmp, PLUGIN_LINK_TYPE);
|
|
30557
|
-
if (before !== null) renameWithRetry(link, old, opts);
|
|
30558
|
-
renameWithRetry(tmp, link, opts);
|
|
30559
|
-
if (before !== null) unlinkSync2(old);
|
|
30560
|
-
const keep = /* @__PURE__ */ new Set([sha]);
|
|
30561
|
-
if (before !== null) keep.add(before);
|
|
30562
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
|
|
30563
|
-
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
30564
|
-
const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
|
|
30565
|
-
return { current: next, previous, removed };
|
|
30566
|
-
}
|
|
30567
|
-
|
|
30568
|
-
// src/core/ops/release-fetch.ts
|
|
30569
|
-
import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
30570
|
-
import { join as join23 } from "node:path";
|
|
30571
|
-
function failed(r) {
|
|
30572
|
-
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30573
|
-
const status = r.killed ?? String(r.exitCode);
|
|
30574
|
-
return new CtxError("FETCH_FAILED", { code: GIT_EXIT_LABEL + status + UPGRADE_AREA_KEY_SEP + r.stderr.toString().trim() });
|
|
30575
|
-
}
|
|
30576
|
-
async function git2(bin, args, cwd, env, signal) {
|
|
30577
|
-
const r = await runProcess([bin, ...args], { cwd, env, signal, timeoutMs: UPGRADE_GIT_TIMEOUT_MS });
|
|
30578
|
-
if (r.exitCode !== 0 || r.killed !== null) throw failed(r);
|
|
30579
|
-
return r.stdout.toString().trim();
|
|
30580
|
-
}
|
|
30581
|
-
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
30582
|
-
const agentDir = join23(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
30583
|
-
mkdirSync8(agentDir, { recursive: true });
|
|
30584
|
-
const fetchDir = join23(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
30585
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30586
|
-
const gitBin = findRuntime(GIT_BIN, env);
|
|
30587
|
-
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30588
|
-
const childEnv = buildChildEnv(env, { ...GIT_NO_PROMPT_ENV, ...GIT_NO_CRLF_ENV });
|
|
30589
|
-
try {
|
|
30590
|
-
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
30591
|
-
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
30592
|
-
const dir = join23(agentDir, sha);
|
|
30593
|
-
if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
30594
|
-
else renameWithRetry(fetchDir, dir, opts);
|
|
30595
|
-
return { sha, dir };
|
|
30596
|
-
} catch (e) {
|
|
30597
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30598
|
-
throw e;
|
|
30599
|
-
}
|
|
30600
|
-
}
|
|
30601
|
-
|
|
30602
30790
|
// src/core/ops/uninstall.ts
|
|
30603
|
-
import { existsSync as
|
|
30604
|
-
import { join as
|
|
30791
|
+
import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
30792
|
+
import { join as join23 } from "node:path";
|
|
30605
30793
|
function row2(area, before, after) {
|
|
30606
30794
|
return { area, before, after };
|
|
30607
30795
|
}
|
|
30608
30796
|
function stopServers(configDir, projectKey) {
|
|
30609
30797
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
30610
|
-
const dir =
|
|
30611
|
-
for (const serverId of stopped) writeFileSync6(
|
|
30798
|
+
const dir = join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
30799
|
+
for (const serverId of stopped) writeFileSync6(join23(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
30612
30800
|
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 };
|
|
30613
30801
|
}
|
|
30614
30802
|
function rootOrNull(adapter, env) {
|
|
@@ -30626,16 +30814,16 @@ function removeCache(adapter, env, configDir) {
|
|
|
30626
30814
|
const root = rootOrNull(adapter, env);
|
|
30627
30815
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30628
30816
|
if (adapter.installMode === "marketplace") {
|
|
30629
|
-
const cache =
|
|
30817
|
+
const cache = join23(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
30630
30818
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
30631
30819
|
}
|
|
30632
|
-
|
|
30820
|
+
rmSync6(root, { recursive: true, force: true });
|
|
30633
30821
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
30634
30822
|
}
|
|
30635
30823
|
case "plugin": {
|
|
30636
|
-
const agentDir =
|
|
30637
|
-
if (!
|
|
30638
|
-
|
|
30824
|
+
const agentDir = join23(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
30825
|
+
if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30826
|
+
rmSync6(agentDir, { recursive: true, force: true });
|
|
30639
30827
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30640
30828
|
}
|
|
30641
30829
|
case "config-mcp":
|
|
@@ -30650,7 +30838,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
30650
30838
|
function isObj3(v) {
|
|
30651
30839
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30652
30840
|
}
|
|
30653
|
-
function
|
|
30841
|
+
function piSource2(entry) {
|
|
30654
30842
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
30655
30843
|
}
|
|
30656
30844
|
function ownEntries2(agent, env) {
|
|
@@ -30679,7 +30867,7 @@ function ownEntries2(agent, env) {
|
|
|
30679
30867
|
}
|
|
30680
30868
|
if (agent === "opencode") {
|
|
30681
30869
|
return [{
|
|
30682
|
-
file:
|
|
30870
|
+
file: join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
30683
30871
|
// D-WIN-OPENCODE-DIR-1
|
|
30684
30872
|
key: OPENCODE_PLUGIN_KEY,
|
|
30685
30873
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -30690,11 +30878,11 @@ function ownEntries2(agent, env) {
|
|
|
30690
30878
|
if (agent === "pi") {
|
|
30691
30879
|
const agentDir = piAgentDirOf(env, home);
|
|
30692
30880
|
return [{
|
|
30693
|
-
file:
|
|
30881
|
+
file: join23(agentDir, SETTINGS_FILE),
|
|
30694
30882
|
key: PI_PACKAGES_KEY,
|
|
30695
30883
|
shown: PI_PACKAGES_KEY,
|
|
30696
|
-
has: (v) => Array.isArray(v) && v.some((x) =>
|
|
30697
|
-
drop: (v) => v.filter((x) =>
|
|
30884
|
+
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
30885
|
+
drop: (v) => v.filter((x) => piSource2(x) !== PI_GIT_PACKAGE)
|
|
30698
30886
|
}];
|
|
30699
30887
|
}
|
|
30700
30888
|
return [];
|
|
@@ -30712,12 +30900,12 @@ function removeOwnEntries(agent, env) {
|
|
|
30712
30900
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
30713
30901
|
}
|
|
30714
30902
|
function removeProjectData(configDir, projectKey) {
|
|
30715
|
-
const projects =
|
|
30716
|
-
const dir =
|
|
30717
|
-
if (!
|
|
30903
|
+
const projects = join23(configDir, PROJECTS_DIR_NAME);
|
|
30904
|
+
const dir = join23(projects, projectKey);
|
|
30905
|
+
if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
30718
30906
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30719
|
-
for (const name of
|
|
30720
|
-
if (name !== OWNERS_DIR_NAME)
|
|
30907
|
+
for (const name of readdirSync8(dir)) {
|
|
30908
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join23(dir, name), { recursive: true, force: true });
|
|
30721
30909
|
}
|
|
30722
30910
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
30723
30911
|
}
|
|
@@ -30725,25 +30913,32 @@ function runUninstall(input) {
|
|
|
30725
30913
|
const configDir = resolveConfigDir(input.env);
|
|
30726
30914
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
30727
30915
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
30728
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
30916
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join23(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
30729
30917
|
return { rows, stopped: stop.stopped };
|
|
30730
30918
|
}
|
|
30731
30919
|
|
|
30732
30920
|
// src/core/ops/v1-remove.ts
|
|
30733
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30921
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync17, rmSync as rmSync7 } from "node:fs";
|
|
30734
30922
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30735
30923
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30736
30924
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
30737
30925
|
function moveAside(target, undo) {
|
|
30738
30926
|
const trash = target + UPGRADE_TRASH_SUFFIX;
|
|
30739
|
-
|
|
30927
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30740
30928
|
renameWithRetry(target, trash);
|
|
30741
30929
|
undo.push({ trash, target });
|
|
30742
30930
|
}
|
|
30931
|
+
function keepAside(target, undo) {
|
|
30932
|
+
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
30933
|
+
for (let n = 2; existsSync20(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
30934
|
+
renameWithRetry(target, aside);
|
|
30935
|
+
undo.push({ trash: aside, target, keep: true });
|
|
30936
|
+
return aside;
|
|
30937
|
+
}
|
|
30743
30938
|
function keepOriginal(file2, kept, undo) {
|
|
30744
30939
|
if (kept.has(file2)) return;
|
|
30745
30940
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30746
|
-
|
|
30941
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30747
30942
|
copyFileSync2(file2, trash);
|
|
30748
30943
|
kept.add(file2);
|
|
30749
30944
|
undo.push({ trash, target: file2 });
|
|
@@ -30803,7 +30998,7 @@ function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
|
30803
30998
|
writeHostConfigEdit(file2, { agent, text, format: "jsonc", path: file2, layout }, patch);
|
|
30804
30999
|
return hit;
|
|
30805
31000
|
}
|
|
30806
|
-
function removeV1(agent, findings) {
|
|
31001
|
+
function removeV1(agent, findings, project) {
|
|
30807
31002
|
const undo = [];
|
|
30808
31003
|
const kept = /* @__PURE__ */ new Set();
|
|
30809
31004
|
const done = /* @__PURE__ */ new Map();
|
|
@@ -30811,14 +31006,16 @@ function removeV1(agent, findings) {
|
|
|
30811
31006
|
for (const f of findings) {
|
|
30812
31007
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30813
31008
|
else if (f.path === "") {
|
|
30814
|
-
if (
|
|
31009
|
+
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
31010
|
+
else if (existsSync20(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
31011
|
+
else if (existsSync20(f.file)) {
|
|
30815
31012
|
moveAside(f.file, undo);
|
|
30816
31013
|
done.set(f, UPGRADE_REMOVED);
|
|
30817
31014
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30818
31015
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30819
31016
|
}
|
|
30820
31017
|
for (const [file2, list4] of entries) {
|
|
30821
|
-
if (!
|
|
31018
|
+
if (!existsSync20(file2)) {
|
|
30822
31019
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30823
31020
|
continue;
|
|
30824
31021
|
}
|
|
@@ -30847,64 +31044,18 @@ function removeV1(agent, findings) {
|
|
|
30847
31044
|
return {
|
|
30848
31045
|
rows: findings.map((f) => row3(f, done.get(f) ?? UPGRADE_NOT_FOUND)),
|
|
30849
31046
|
commit() {
|
|
30850
|
-
for (const u of undo.splice(0))
|
|
31047
|
+
for (const u of undo.splice(0)) if (u.keep !== true) rmSync7(u.trash, { recursive: true, force: true });
|
|
30851
31048
|
},
|
|
30852
31049
|
rollback() {
|
|
30853
31050
|
for (const u of undo.splice(0).reverse()) {
|
|
30854
|
-
if (!
|
|
30855
|
-
|
|
31051
|
+
if (!existsSync20(u.trash)) continue;
|
|
31052
|
+
rmSync7(u.target, { recursive: true, force: true });
|
|
30856
31053
|
renameWithRetry(u.trash, u.target);
|
|
30857
31054
|
}
|
|
30858
31055
|
}
|
|
30859
31056
|
};
|
|
30860
31057
|
}
|
|
30861
31058
|
|
|
30862
|
-
// src/core/ops/verify-sums.ts
|
|
30863
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
30864
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
|
|
30865
|
-
import { join as join25 } from "node:path";
|
|
30866
|
-
function mismatch() {
|
|
30867
|
-
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
30868
|
-
}
|
|
30869
|
-
function parseSums(text) {
|
|
30870
|
-
const lines = text.split(SUMS_LINE_END);
|
|
30871
|
-
if (lines[lines.length - 1] === "") lines.pop();
|
|
30872
|
-
const sums = /* @__PURE__ */ new Map();
|
|
30873
|
-
for (const line of lines) {
|
|
30874
|
-
const at2 = line.indexOf(SUMS_LINE_SEP);
|
|
30875
|
-
if (at2 < 0) throw mismatch();
|
|
30876
|
-
const rel = line.slice(at2 + SUMS_LINE_SEP.length);
|
|
30877
|
-
if (rel === "" || sums.has(rel)) throw mismatch();
|
|
30878
|
-
sums.set(rel, line.slice(0, at2));
|
|
30879
|
-
}
|
|
30880
|
-
return sums;
|
|
30881
|
-
}
|
|
30882
|
-
function walk3(dir, prefix, out) {
|
|
30883
|
-
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
30884
|
-
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
30885
|
-
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
30886
|
-
const abs = join25(dir, entry.name);
|
|
30887
|
-
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
30888
|
-
else if (entry.isFile()) out.set(rel, abs);
|
|
30889
|
-
else throw mismatch();
|
|
30890
|
-
}
|
|
30891
|
-
}
|
|
30892
|
-
function verifySums(dir) {
|
|
30893
|
-
const sumsPath = join25(dir, RELEASE_SUMS_FILE);
|
|
30894
|
-
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30895
|
-
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30896
|
-
const sums = parseSums(readFileSync18(sumsPath, "utf8"));
|
|
30897
|
-
const files = /* @__PURE__ */ new Map();
|
|
30898
|
-
walk3(dir, "", files);
|
|
30899
|
-
if (files.size !== sums.size) throw mismatch();
|
|
30900
|
-
for (const [rel, abs] of files) {
|
|
30901
|
-
const want = sums.get(rel);
|
|
30902
|
-
if (want === void 0) throw mismatch();
|
|
30903
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
|
|
30904
|
-
if (got !== want) throw mismatch();
|
|
30905
|
-
}
|
|
30906
|
-
}
|
|
30907
|
-
|
|
30908
31059
|
// src/core/tools/upgrade.ts
|
|
30909
31060
|
var ctxUpgradeSchema = external_exports.object({
|
|
30910
31061
|
mode: external_exports.enum(UPGRADE_MODES).optional(),
|
|
@@ -30927,41 +31078,20 @@ function pluginRootRow(adapter, env) {
|
|
|
30927
31078
|
}
|
|
30928
31079
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
30929
31080
|
}
|
|
30930
|
-
function isCurrent(agentDir, dir) {
|
|
30931
|
-
const link = join26(agentDir, PLUGIN_CURRENT_LINK);
|
|
30932
|
-
return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
30933
|
-
}
|
|
30934
|
-
async function checkout(adapter, deps) {
|
|
30935
|
-
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
30936
|
-
const agentDir = dirname13(fetched.dir);
|
|
30937
|
-
try {
|
|
30938
|
-
verifySums(fetched.dir);
|
|
30939
|
-
} catch (err) {
|
|
30940
|
-
if (!isCurrent(agentDir, fetched.dir)) rmSync10(fetched.dir, { recursive: true, force: true });
|
|
30941
|
-
throw err;
|
|
30942
|
-
}
|
|
30943
|
-
const swap = swapPluginCurrent(agentDir, fetched.sha);
|
|
30944
|
-
const rows = [row4(UPGRADE_CHECKOUT_AREA, swap.previous ?? "", swap.current)];
|
|
30945
|
-
for (const dir of swap.removed) rows.push(row4(UPGRADE_CACHE_AREA, dir, UPGRADE_REMOVED));
|
|
30946
|
-
return { rows, agentDir, swap };
|
|
30947
|
-
}
|
|
30948
31081
|
function hostRow(adapter) {
|
|
30949
|
-
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]
|
|
31082
|
+
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]);
|
|
30950
31083
|
}
|
|
30951
|
-
|
|
30952
|
-
let done = null;
|
|
31084
|
+
function upgrade(adapter, deps, home) {
|
|
30953
31085
|
let removal = null;
|
|
30954
31086
|
try {
|
|
30955
|
-
const step4 = UPGRADE_GIT_CHECKOUT_AGENTS.includes(adapter.id) ? (done = await checkout(adapter, deps)).rows : [hostRow(adapter)];
|
|
30956
31087
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
30957
|
-
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) });
|
|
30958
|
-
removal = removeV1(adapter.id, findings);
|
|
30959
|
-
const rows = [
|
|
31088
|
+
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) });
|
|
31089
|
+
removal = removeV1(adapter.id, findings, deps.project.worktree);
|
|
31090
|
+
const rows = [hostRow(adapter), ...step5, ...removal.rows];
|
|
30960
31091
|
removal.commit();
|
|
30961
31092
|
return rows;
|
|
30962
31093
|
} catch (err) {
|
|
30963
31094
|
removal?.rollback();
|
|
30964
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename7(done.swap.previous));
|
|
30965
31095
|
throw err;
|
|
30966
31096
|
}
|
|
30967
31097
|
}
|
|
@@ -30981,12 +31111,12 @@ async function runUpgrade(input, deps) {
|
|
|
30981
31111
|
const result = runUninstall({ adapter, project: deps.project, env: deps.env, confirmDelete: input.confirmDelete === true });
|
|
30982
31112
|
rows.push(...result.rows);
|
|
30983
31113
|
} else {
|
|
30984
|
-
rows.push(...
|
|
31114
|
+
rows.push(...upgrade(adapter, deps, home));
|
|
30985
31115
|
}
|
|
30986
31116
|
return { text: renderTable(rows) + "\n\n" + UPGRADE_RESTART_LINE, isError: false, sandboxBytes: 0 };
|
|
30987
31117
|
}
|
|
30988
31118
|
async function handler8(input, ctx) {
|
|
30989
|
-
return runUpgrade(input, { project: ctx.project, env: process.env, signal: ctx.signal
|
|
31119
|
+
return runUpgrade(input, { project: ctx.project, env: process.env, signal: ctx.signal });
|
|
30990
31120
|
}
|
|
30991
31121
|
var ctxUpgrade = Object.freeze({
|
|
30992
31122
|
name: "ctx_upgrade",
|
|
@@ -31049,8 +31179,8 @@ function checkCall(tool, input) {
|
|
|
31049
31179
|
|
|
31050
31180
|
// src/entries/server.ts
|
|
31051
31181
|
import { randomUUID } from "node:crypto";
|
|
31052
|
-
import { existsSync as
|
|
31053
|
-
import { dirname as
|
|
31182
|
+
import { existsSync as existsSync22, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
|
|
31183
|
+
import { dirname as dirname13, join as join25 } from "node:path";
|
|
31054
31184
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
31055
31185
|
|
|
31056
31186
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -34529,7 +34659,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
34529
34659
|
var NONE3 = 0;
|
|
34530
34660
|
var ASSUMED = 1;
|
|
34531
34661
|
var PROVEN = 2;
|
|
34532
|
-
function isRecursive(inst, stack2,
|
|
34662
|
+
function isRecursive(inst, stack2, resolve9) {
|
|
34533
34663
|
const cached4 = recursive.get(inst);
|
|
34534
34664
|
if (cached4 !== void 0)
|
|
34535
34665
|
return cached4 ? PROVEN : NONE3;
|
|
@@ -34539,7 +34669,7 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34539
34669
|
let result = NONE3;
|
|
34540
34670
|
const check2 = (child) => {
|
|
34541
34671
|
if (result !== PROVEN && child?._zod) {
|
|
34542
|
-
const answer3 = isRecursive(child, stack2,
|
|
34672
|
+
const answer3 = isRecursive(child, stack2, resolve9);
|
|
34543
34673
|
if (answer3 > result)
|
|
34544
34674
|
result = answer3;
|
|
34545
34675
|
}
|
|
@@ -34550,7 +34680,7 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34550
34680
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
34551
34681
|
if (spread && !desc.enumerable)
|
|
34552
34682
|
continue;
|
|
34553
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2,
|
|
34683
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve9) : NONE3;
|
|
34554
34684
|
if (child > answer3)
|
|
34555
34685
|
answer3 = child;
|
|
34556
34686
|
}
|
|
@@ -34614,7 +34744,7 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34614
34744
|
break;
|
|
34615
34745
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
34616
34746
|
case "lazy": {
|
|
34617
|
-
const inner = def._cachedInner ?? (
|
|
34747
|
+
const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
|
|
34618
34748
|
merge5(inner ? isRecursive(inner, stack2, false) : ASSUMED);
|
|
34619
34749
|
break;
|
|
34620
34750
|
}
|
|
@@ -42058,7 +42188,7 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
|
|
|
42058
42188
|
var NONE4 = 0;
|
|
42059
42189
|
var ASSUMED2 = 1;
|
|
42060
42190
|
var PROVEN2 = 2;
|
|
42061
|
-
function isRecursive2(inst, stack2,
|
|
42191
|
+
function isRecursive2(inst, stack2, resolve9) {
|
|
42062
42192
|
const cached4 = recursive2.get(inst);
|
|
42063
42193
|
if (cached4 !== void 0)
|
|
42064
42194
|
return cached4 ? PROVEN2 : NONE4;
|
|
@@ -42068,7 +42198,7 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
42068
42198
|
let result = NONE4;
|
|
42069
42199
|
const check2 = (child) => {
|
|
42070
42200
|
if (result !== PROVEN2 && child?._zod) {
|
|
42071
|
-
const answer3 = isRecursive2(child, stack2,
|
|
42201
|
+
const answer3 = isRecursive2(child, stack2, resolve9);
|
|
42072
42202
|
if (answer3 > result)
|
|
42073
42203
|
result = answer3;
|
|
42074
42204
|
}
|
|
@@ -42079,7 +42209,7 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
42079
42209
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
42080
42210
|
if (spread && !desc.enumerable)
|
|
42081
42211
|
continue;
|
|
42082
|
-
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2,
|
|
42212
|
+
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve9) : NONE4;
|
|
42083
42213
|
if (child > answer3)
|
|
42084
42214
|
answer3 = child;
|
|
42085
42215
|
}
|
|
@@ -42143,7 +42273,7 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
42143
42273
|
break;
|
|
42144
42274
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
42145
42275
|
case "lazy": {
|
|
42146
|
-
const inner = def._cachedInner ?? (
|
|
42276
|
+
const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
|
|
42147
42277
|
merge5(inner ? isRecursive2(inner, stack2, false) : ASSUMED2);
|
|
42148
42278
|
break;
|
|
42149
42279
|
}
|
|
@@ -48747,14 +48877,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
|
|
|
48747
48877
|
return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
|
|
48748
48878
|
}
|
|
48749
48879
|
function sleep(ms, signal) {
|
|
48750
|
-
return new Promise((
|
|
48880
|
+
return new Promise((resolve9, reject) => {
|
|
48751
48881
|
if (signal?.aborted) {
|
|
48752
48882
|
reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
|
|
48753
48883
|
return;
|
|
48754
48884
|
}
|
|
48755
48885
|
const timer = setTimeout(() => {
|
|
48756
48886
|
signal?.removeEventListener("abort", onAbort);
|
|
48757
|
-
|
|
48887
|
+
resolve9();
|
|
48758
48888
|
}, ms);
|
|
48759
48889
|
const onAbort = () => {
|
|
48760
48890
|
clearTimeout(timer);
|
|
@@ -49553,7 +49683,7 @@ var Protocol = class {
|
|
|
49553
49683
|
const flowStartedAt = Date.now();
|
|
49554
49684
|
let onAbort;
|
|
49555
49685
|
let cleanupMessageId;
|
|
49556
|
-
return new Promise((
|
|
49686
|
+
return new Promise((resolve9, reject) => {
|
|
49557
49687
|
const earlyReject = (error42) => {
|
|
49558
49688
|
reject(error42);
|
|
49559
49689
|
};
|
|
@@ -49622,7 +49752,7 @@ var Protocol = class {
|
|
|
49622
49752
|
}
|
|
49623
49753
|
if (decoded.kind === "invalid") return reject(decoded.error);
|
|
49624
49754
|
if (decoded.kind === "input_required") {
|
|
49625
|
-
if (options?.allowInputRequired === true) return
|
|
49755
|
+
if (options?.allowInputRequired === true) return resolve9(manualInputRequiredValue(decoded));
|
|
49626
49756
|
const flow = {
|
|
49627
49757
|
codec,
|
|
49628
49758
|
request: request2,
|
|
@@ -49634,11 +49764,11 @@ var Protocol = class {
|
|
|
49634
49764
|
params
|
|
49635
49765
|
}, resultSchema, legOptions)
|
|
49636
49766
|
};
|
|
49637
|
-
return
|
|
49767
|
+
return resolve9(this._resolveNonCompleteResult(decoded, flow));
|
|
49638
49768
|
}
|
|
49639
49769
|
const result = decoded.result;
|
|
49640
49770
|
validateStandardSchema(resultSchema, result).then((parseResult) => {
|
|
49641
|
-
if (parseResult.success)
|
|
49771
|
+
if (parseResult.success) resolve9(parseResult.data);
|
|
49642
49772
|
else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request2.method}: ${parseResult.error}`));
|
|
49643
49773
|
}, reject);
|
|
49644
49774
|
});
|
|
@@ -52278,17 +52408,17 @@ var require_validate = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
52278
52408
|
const { schemaCode } = this;
|
|
52279
52409
|
this.fail((0, codegen_1._)`${schemaCode} !== undefined && (${(0, codegen_1.or)(this.invalid$data(), condition)})`);
|
|
52280
52410
|
}
|
|
52281
|
-
error(
|
|
52411
|
+
error(append3, errorParams, errorPaths) {
|
|
52282
52412
|
if (errorParams) {
|
|
52283
52413
|
this.setParams(errorParams);
|
|
52284
|
-
this._error(
|
|
52414
|
+
this._error(append3, errorPaths);
|
|
52285
52415
|
this.setParams({});
|
|
52286
52416
|
return;
|
|
52287
52417
|
}
|
|
52288
|
-
this._error(
|
|
52418
|
+
this._error(append3, errorPaths);
|
|
52289
52419
|
}
|
|
52290
|
-
_error(
|
|
52291
|
-
(
|
|
52420
|
+
_error(append3, errorPaths) {
|
|
52421
|
+
(append3 ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
52292
52422
|
}
|
|
52293
52423
|
$dataError() {
|
|
52294
52424
|
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
@@ -52554,7 +52684,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
52554
52684
|
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
|
|
52555
52685
|
const schOrFunc = root.refs[ref];
|
|
52556
52686
|
if (schOrFunc) return schOrFunc;
|
|
52557
|
-
let _sch =
|
|
52687
|
+
let _sch = resolve9.call(this, root, ref);
|
|
52558
52688
|
if (_sch === void 0) {
|
|
52559
52689
|
const schema = (_a5 = root.localRefs) === null || _a5 === void 0 ? void 0 : _a5[ref];
|
|
52560
52690
|
const { schemaId } = this.opts;
|
|
@@ -52580,7 +52710,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
52580
52710
|
function sameSchemaEnv(s1, s2) {
|
|
52581
52711
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
52582
52712
|
}
|
|
52583
|
-
function
|
|
52713
|
+
function resolve9(root, ref) {
|
|
52584
52714
|
let sch;
|
|
52585
52715
|
while (typeof (sch = this.refs[ref]) == "string") ref = sch;
|
|
52586
52716
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
@@ -53030,47 +53160,47 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
53030
53160
|
else if (typeof uri === "object") uri = parse6(serialize(uri, options), options);
|
|
53031
53161
|
return uri;
|
|
53032
53162
|
}
|
|
53033
|
-
function
|
|
53163
|
+
function resolve9(baseURI, relativeURI, options) {
|
|
53034
53164
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
53035
53165
|
const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
53036
53166
|
schemelessOptions.skipEscape = true;
|
|
53037
53167
|
return serialize(resolved, schemelessOptions);
|
|
53038
53168
|
}
|
|
53039
|
-
function resolveComponent(base,
|
|
53169
|
+
function resolveComponent(base, relative6, options, skipNormalization) {
|
|
53040
53170
|
const target = {};
|
|
53041
53171
|
if (!skipNormalization) {
|
|
53042
53172
|
base = parse6(serialize(base, options), options);
|
|
53043
|
-
|
|
53173
|
+
relative6 = parse6(serialize(relative6, options), options);
|
|
53044
53174
|
}
|
|
53045
53175
|
options = options || {};
|
|
53046
|
-
if (!options.tolerant &&
|
|
53047
|
-
target.scheme =
|
|
53048
|
-
target.userinfo =
|
|
53049
|
-
target.host =
|
|
53050
|
-
target.port =
|
|
53051
|
-
target.path = removeDotSegments(
|
|
53052
|
-
target.query =
|
|
53176
|
+
if (!options.tolerant && relative6.scheme) {
|
|
53177
|
+
target.scheme = relative6.scheme;
|
|
53178
|
+
target.userinfo = relative6.userinfo;
|
|
53179
|
+
target.host = relative6.host;
|
|
53180
|
+
target.port = relative6.port;
|
|
53181
|
+
target.path = removeDotSegments(relative6.path || "");
|
|
53182
|
+
target.query = relative6.query;
|
|
53053
53183
|
} else {
|
|
53054
|
-
if (
|
|
53055
|
-
target.userinfo =
|
|
53056
|
-
target.host =
|
|
53057
|
-
target.port =
|
|
53058
|
-
target.path = removeDotSegments(
|
|
53059
|
-
target.query =
|
|
53184
|
+
if (relative6.userinfo !== void 0 || relative6.host !== void 0 || relative6.port !== void 0) {
|
|
53185
|
+
target.userinfo = relative6.userinfo;
|
|
53186
|
+
target.host = relative6.host;
|
|
53187
|
+
target.port = relative6.port;
|
|
53188
|
+
target.path = removeDotSegments(relative6.path || "");
|
|
53189
|
+
target.query = relative6.query;
|
|
53060
53190
|
} else {
|
|
53061
|
-
if (!
|
|
53191
|
+
if (!relative6.path) {
|
|
53062
53192
|
target.path = base.path;
|
|
53063
|
-
if (
|
|
53193
|
+
if (relative6.query !== void 0) target.query = relative6.query;
|
|
53064
53194
|
else target.query = base.query;
|
|
53065
53195
|
} else {
|
|
53066
|
-
if (
|
|
53196
|
+
if (relative6.path[0] === "/") target.path = removeDotSegments(relative6.path);
|
|
53067
53197
|
else {
|
|
53068
|
-
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" +
|
|
53069
|
-
else if (!base.path) target.path =
|
|
53070
|
-
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
53198
|
+
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" + relative6.path;
|
|
53199
|
+
else if (!base.path) target.path = relative6.path;
|
|
53200
|
+
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative6.path;
|
|
53071
53201
|
target.path = removeDotSegments(target.path);
|
|
53072
53202
|
}
|
|
53073
|
-
target.query =
|
|
53203
|
+
target.query = relative6.query;
|
|
53074
53204
|
}
|
|
53075
53205
|
target.userinfo = base.userinfo;
|
|
53076
53206
|
target.host = base.host;
|
|
@@ -53078,7 +53208,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
53078
53208
|
}
|
|
53079
53209
|
target.scheme = base.scheme;
|
|
53080
53210
|
}
|
|
53081
|
-
target.fragment =
|
|
53211
|
+
target.fragment = relative6.fragment;
|
|
53082
53212
|
return target;
|
|
53083
53213
|
}
|
|
53084
53214
|
function equal(uriA, uriB, options) {
|
|
@@ -53204,7 +53334,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
53204
53334
|
const fastUri = {
|
|
53205
53335
|
SCHEMES,
|
|
53206
53336
|
normalize: normalize2,
|
|
53207
|
-
resolve:
|
|
53337
|
+
resolve: resolve9,
|
|
53208
53338
|
resolveComponent,
|
|
53209
53339
|
equal,
|
|
53210
53340
|
serialize,
|
|
@@ -58669,7 +58799,7 @@ var StdioServerTransport = class {
|
|
|
58669
58799
|
}
|
|
58670
58800
|
send(message3) {
|
|
58671
58801
|
if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
|
|
58672
|
-
return new Promise((
|
|
58802
|
+
return new Promise((resolve9, reject) => {
|
|
58673
58803
|
const json2 = serializeMessage(message3);
|
|
58674
58804
|
let settled = false;
|
|
58675
58805
|
const onError = (error42) => {
|
|
@@ -58684,14 +58814,14 @@ var StdioServerTransport = class {
|
|
|
58684
58814
|
settled = true;
|
|
58685
58815
|
this._stdout.off("error", onError);
|
|
58686
58816
|
this._stdout.off("drain", onDrain);
|
|
58687
|
-
|
|
58817
|
+
resolve9();
|
|
58688
58818
|
};
|
|
58689
58819
|
this._stdout.once("error", onError);
|
|
58690
58820
|
if (this._stdout.write(json2)) {
|
|
58691
58821
|
if (settled) return;
|
|
58692
58822
|
settled = true;
|
|
58693
58823
|
this._stdout.off("error", onError);
|
|
58694
|
-
|
|
58824
|
+
resolve9();
|
|
58695
58825
|
} else if (!settled) this._stdout.once("drain", onDrain);
|
|
58696
58826
|
});
|
|
58697
58827
|
}
|
|
@@ -58745,14 +58875,14 @@ var StdioConnectionChannel = class {
|
|
|
58745
58875
|
*/
|
|
58746
58876
|
async whenRequestsAnswered(timeoutMs) {
|
|
58747
58877
|
if (this._closed || this._pendingRequests.size === 0) return true;
|
|
58748
|
-
return await new Promise((
|
|
58878
|
+
return await new Promise((resolve9) => {
|
|
58749
58879
|
const waiter = () => {
|
|
58750
58880
|
clearTimeout(timer);
|
|
58751
|
-
|
|
58881
|
+
resolve9(true);
|
|
58752
58882
|
};
|
|
58753
58883
|
const timer = setTimeout(() => {
|
|
58754
58884
|
this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
|
|
58755
|
-
|
|
58885
|
+
resolve9(false);
|
|
58756
58886
|
}, timeoutMs);
|
|
58757
58887
|
this._drainWaiters.push(waiter);
|
|
58758
58888
|
});
|
|
@@ -59115,8 +59245,8 @@ function installExitGuard(opts) {
|
|
|
59115
59245
|
}
|
|
59116
59246
|
|
|
59117
59247
|
// src/core/store/cleanup.ts
|
|
59118
|
-
import { existsSync as
|
|
59119
|
-
import { join as
|
|
59248
|
+
import { existsSync as existsSync21, readdirSync as readdirSync9, rmSync as rmSync8 } from "node:fs";
|
|
59249
|
+
import { join as join24 } from "node:path";
|
|
59120
59250
|
function deleteSource(raw, id) {
|
|
59121
59251
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
59122
59252
|
deleteChunkRows(raw, { sourceId: id });
|
|
@@ -59151,7 +59281,7 @@ function userVersion(raw) {
|
|
|
59151
59281
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
59152
59282
|
}
|
|
59153
59283
|
function openForSweep(dbPath, projectKey) {
|
|
59154
|
-
if (!
|
|
59284
|
+
if (!existsSync21(dbPath) && (existsSync21(dbPath + DB_WAL_SUFFIX) || existsSync21(dbPath + DB_SHM_SUFFIX))) {
|
|
59155
59285
|
throw new CtxError("DB_GONE");
|
|
59156
59286
|
}
|
|
59157
59287
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -59172,21 +59302,21 @@ function lastAccess(raw) {
|
|
|
59172
59302
|
return row5.t;
|
|
59173
59303
|
}
|
|
59174
59304
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
59175
|
-
const dir =
|
|
59176
|
-
const db = openForSweep(
|
|
59305
|
+
const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
59306
|
+
const db = openForSweep(join24(dir, DB_FILE_NAME), projectKey);
|
|
59177
59307
|
let dead;
|
|
59178
59308
|
try {
|
|
59179
59309
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
59180
59310
|
} finally {
|
|
59181
59311
|
closeDb(db);
|
|
59182
59312
|
}
|
|
59183
|
-
if (dead)
|
|
59313
|
+
if (dead) rmSync8(dir, { recursive: true, force: true });
|
|
59184
59314
|
return dead;
|
|
59185
59315
|
}
|
|
59186
59316
|
function sweepDeadProjects(configDir) {
|
|
59187
59317
|
let entries;
|
|
59188
59318
|
try {
|
|
59189
|
-
entries =
|
|
59319
|
+
entries = readdirSync9(join24(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
59190
59320
|
} catch (err) {
|
|
59191
59321
|
if (err.code === "ENOENT") return [];
|
|
59192
59322
|
throw err;
|
|
@@ -59205,12 +59335,12 @@ function sweepDeadProjects(configDir) {
|
|
|
59205
59335
|
}
|
|
59206
59336
|
|
|
59207
59337
|
// src/entries/is-entry.ts
|
|
59208
|
-
import { realpathSync as
|
|
59338
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
59209
59339
|
function isEntry(main, argv1, self) {
|
|
59210
59340
|
if (main !== void 0) return main;
|
|
59211
59341
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
59212
59342
|
try {
|
|
59213
|
-
return
|
|
59343
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
59214
59344
|
} catch {
|
|
59215
59345
|
return false;
|
|
59216
59346
|
}
|
|
@@ -59286,16 +59416,33 @@ function workspaceFromMeta(meta3) {
|
|
|
59286
59416
|
}
|
|
59287
59417
|
function realOrSame(p) {
|
|
59288
59418
|
try {
|
|
59289
|
-
return
|
|
59419
|
+
return realpathSync12.native(p);
|
|
59290
59420
|
} catch {
|
|
59291
59421
|
return p;
|
|
59292
59422
|
}
|
|
59293
59423
|
}
|
|
59424
|
+
function hasWorkspaceFolder(argv) {
|
|
59425
|
+
const i = argv.indexOf(WORKSPACE_FOLDER_FLAG);
|
|
59426
|
+
const v = i < 0 ? void 0 : argv[i + 1];
|
|
59427
|
+
return v !== void 0 && v !== "" && v !== VSCODE_WORKSPACE_VAR;
|
|
59428
|
+
}
|
|
59429
|
+
async function workspaceFromRoots(server) {
|
|
59430
|
+
if (server.server.getClientCapabilities()?.roots === void 0) return void 0;
|
|
59431
|
+
try {
|
|
59432
|
+
const { roots } = await server.server.listRoots(void 0, { timeout: ROOTS_TIMEOUT_MS });
|
|
59433
|
+
for (const root of roots) {
|
|
59434
|
+
if (root.uri.startsWith(FILE_URL_PREFIX)) return fileURLToPath3(root.uri);
|
|
59435
|
+
}
|
|
59436
|
+
} catch (err) {
|
|
59437
|
+
console.error("context-mode: roots/list: " + (err instanceof Error ? err.message : String(err)));
|
|
59438
|
+
}
|
|
59439
|
+
return void 0;
|
|
59440
|
+
}
|
|
59294
59441
|
function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
59295
59442
|
const fromHost = workspaceFromMeta(meta3);
|
|
59296
59443
|
if (fromHost !== void 0) return fromHost;
|
|
59297
59444
|
if (script === void 0 || script === "") return spawnCwd;
|
|
59298
|
-
return realOrSame(spawnCwd) === realOrSame(
|
|
59445
|
+
return realOrSame(spawnCwd) === realOrSame(dirname13(script)) ? "" : spawnCwd;
|
|
59299
59446
|
}
|
|
59300
59447
|
function errorReply(err) {
|
|
59301
59448
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
@@ -59334,15 +59481,15 @@ async function startServer(argv, env) {
|
|
|
59334
59481
|
opening.catch(() => pending.delete(project.dbPath));
|
|
59335
59482
|
}
|
|
59336
59483
|
const db = await opening;
|
|
59337
|
-
if (!
|
|
59484
|
+
if (!existsSync22(db.path)) throw new CtxError("DB_GONE");
|
|
59338
59485
|
return db;
|
|
59339
59486
|
}
|
|
59340
59487
|
function stopMarker(configDir, projectKey) {
|
|
59341
|
-
return
|
|
59488
|
+
return join25(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
59342
59489
|
}
|
|
59343
59490
|
function stopRequested() {
|
|
59344
59491
|
const configDir = resolveConfigDir(process.env);
|
|
59345
|
-
return held.some((db) =>
|
|
59492
|
+
return held.some((db) => existsSync22(stopMarker(configDir, db.projectKey)));
|
|
59346
59493
|
}
|
|
59347
59494
|
async function journal(project, ctx, name, reply4) {
|
|
59348
59495
|
const db = await ownDb(project);
|
|
@@ -59352,10 +59499,12 @@ async function startServer(argv, env) {
|
|
|
59352
59499
|
return async (input, req) => {
|
|
59353
59500
|
const meta3 = req.mcpReq._meta;
|
|
59354
59501
|
const agent = resolveAgent(argv, env);
|
|
59502
|
+
const fromRoots = agent === "vscode" && !hasWorkspaceFolder(argv) ? await workspaceFromRoots(server) : void 0;
|
|
59503
|
+
const callArgv = fromRoots === void 0 ? argv : [...argv, WORKSPACE_FOLDER_FLAG, fromRoots];
|
|
59355
59504
|
let project;
|
|
59356
59505
|
const projectOf = () => {
|
|
59357
59506
|
if (agent === void 0) throw new CtxError("NO_PROJECT", { kind: "--agent" });
|
|
59358
|
-
project ??= resolveProject(agent, { env, argv, cwd: workspaceCwdOf(meta3, process.cwd(), process.argv[1]), piCwd: void 0 });
|
|
59507
|
+
project ??= resolveProject(agent, { env, argv: callArgv, cwd: workspaceCwdOf(meta3, process.cwd(), process.argv[1]), piCwd: void 0 });
|
|
59359
59508
|
return project;
|
|
59360
59509
|
};
|
|
59361
59510
|
const ctx = {
|
|
@@ -59435,7 +59584,7 @@ async function startServer(argv, env) {
|
|
|
59435
59584
|
try {
|
|
59436
59585
|
const configDir = resolveConfigDir(process.env);
|
|
59437
59586
|
removeOwnerPid(configDir, db.projectKey, serverId);
|
|
59438
|
-
|
|
59587
|
+
rmSync9(stopMarker(configDir, db.projectKey), { force: true });
|
|
59439
59588
|
} catch (err) {
|
|
59440
59589
|
console.error(err);
|
|
59441
59590
|
}
|
|
@@ -59449,7 +59598,7 @@ async function startServer(argv, env) {
|
|
|
59449
59598
|
}
|
|
59450
59599
|
installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
|
|
59451
59600
|
handle = serveStdio(createServer);
|
|
59452
|
-
await new Promise((
|
|
59601
|
+
await new Promise((resolve9) => process.once("exit", () => resolve9()));
|
|
59453
59602
|
}
|
|
59454
59603
|
if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) {
|
|
59455
59604
|
const [, , ...cliArgs] = process.argv;
|