context-mode 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/hooks.json +50 -0
- package/.zcode-plugin/plugin.json +20 -0
- package/README.md +78 -79
- package/SHA256SUMS +17 -15
- package/cli.mjs +326 -148
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +99 -97
- package/opencode/plugin.js +680 -521
- package/package.json +2 -1
- package/pi/index.js +769 -589
- package/qwen-extension.json +1 -1
- package/run.mjs +256 -99
- package/search.mjs +256 -99
- package/server.mjs +536 -447
package/pi/index.js
CHANGED
|
@@ -11163,6 +11163,8 @@ var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
|
11163
11163
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
11164
11164
|
var SYNC_INDEX_MAX_BYTES = 65536;
|
|
11165
11165
|
var REPLACE_TRIGGER_BYTES = 4096;
|
|
11166
|
+
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
11167
|
+
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
11166
11168
|
var REPLACE_RETURN_BYTES = 96;
|
|
11167
11169
|
var SHAPE_RETURN_BYTES = 256;
|
|
11168
11170
|
var REPLACE_CHUNK_BYTES = 48;
|
|
@@ -11348,6 +11350,7 @@ var GIT_COMMONDIR_FILE = "commondir";
|
|
|
11348
11350
|
var GIT_HEAD_FILE = "HEAD";
|
|
11349
11351
|
var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
|
|
11350
11352
|
var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
|
|
11353
|
+
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
11351
11354
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
11352
11355
|
var FETCH_MAX_HOPS = 5;
|
|
11353
11356
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
@@ -11359,6 +11362,7 @@ var RUN_SESSION_PREFIX = "mcp:";
|
|
|
11359
11362
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
11360
11363
|
var NODE_MIN = "24.15.0";
|
|
11361
11364
|
var DATA_ROOT = "~/.context-mode";
|
|
11365
|
+
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
11362
11366
|
var INTERNAL_ERROR_LINE = "Internal error. Fix: run ctx_doctor.";
|
|
11363
11367
|
var REQUIRE_SECURITY_ENV = "CONTEXT_MODE_REQUIRE_SECURITY";
|
|
11364
11368
|
var HOST_CONFIG_DIR_NAME = ".claude";
|
|
@@ -11461,7 +11465,8 @@ var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
|
11461
11465
|
var SED_COMMAND = "sed";
|
|
11462
11466
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
11463
11467
|
var JQ_COMMAND = "jq";
|
|
11464
|
-
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";
|
|
11465
11470
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
11466
11471
|
var SHELL_TOOL = "Bash";
|
|
11467
11472
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
@@ -11477,6 +11482,7 @@ var RECALL_MIN_SCORE = 5;
|
|
|
11477
11482
|
var RECALL_MAX_ROWS = 340;
|
|
11478
11483
|
var COMPACTED_META_PREFIX = "compacted:";
|
|
11479
11484
|
var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
|
|
11485
|
+
var UNITS_ANCESTOR_FACTOR = 8;
|
|
11480
11486
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
11481
11487
|
var RECALL_SEEN_META_PREFIX = "recall_seen:";
|
|
11482
11488
|
var RECALL_OPEN_TAG = "<context_mode_recall>";
|
|
@@ -11570,8 +11576,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
11570
11576
|
var DECISION_OPTION_KEY = "option";
|
|
11571
11577
|
var DECISION_LABEL_JOIN = " | ";
|
|
11572
11578
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11573
|
-
var
|
|
11574
|
-
var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
|
|
11579
|
+
var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
|
|
11575
11580
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11576
11581
|
var DOCTOR_LABEL = Object.freeze({
|
|
11577
11582
|
D1: "version",
|
|
@@ -11715,7 +11720,6 @@ function D9_INDEX_DETAIL(sources, chunks) {
|
|
|
11715
11720
|
var PLUGIN_CACHE_DIR_NAME = "cache";
|
|
11716
11721
|
var DATA_PLUGINS_DIR_NAME = "plugins";
|
|
11717
11722
|
var PLUGIN_CURRENT_LINK = "current";
|
|
11718
|
-
var RELEASE_SUMS_FILE = "SHA256SUMS";
|
|
11719
11723
|
var EXTENSIONS_DIR_NAME = "extensions";
|
|
11720
11724
|
var AGENT_HOME_DIR = Object.freeze({
|
|
11721
11725
|
"claude-code": [".claude"],
|
|
@@ -11738,7 +11742,6 @@ var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
|
11738
11742
|
var UPGRADE_TABLE_HEADER = "| Area | Before | After |";
|
|
11739
11743
|
var UPGRADE_TABLE_RULE = "|---|---|---|";
|
|
11740
11744
|
var UPGRADE_PLUGIN_ROOT_AREA = "plugin root";
|
|
11741
|
-
var UPGRADE_CHECKOUT_AREA = "plugin checkout";
|
|
11742
11745
|
var UPGRADE_SERVER_AREA = "server";
|
|
11743
11746
|
var UPGRADE_SERVER_RUNNING = "running";
|
|
11744
11747
|
var UPGRADE_SERVER_STOPPED = "stopped after this reply";
|
|
@@ -11749,25 +11752,21 @@ var UPGRADE_REPORT_ONLY = "report only: remove it by hand if you no longer use i
|
|
|
11749
11752
|
var UPGRADE_STOP_DELAY_MS = 200;
|
|
11750
11753
|
var UPGRADE_AREA_KEY_SEP = ": ";
|
|
11751
11754
|
var V1_KEY_PATH_SEP = ".";
|
|
11752
|
-
var UPGRADE_GIT_TIMEOUT_MS = 12e4;
|
|
11753
11755
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
11754
11756
|
var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
|
|
11755
|
-
var UPGRADE_FETCH_DIR_PREFIX = ".fetch-";
|
|
11756
|
-
var SUMS_LINE_SEP = " ";
|
|
11757
|
-
var SUMS_HASH_ALGORITHM = "sha256";
|
|
11758
|
-
var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
|
|
11759
|
-
var UPGRADE_HOST_MANUAL = "update with the host's own install command, then restart";
|
|
11760
11757
|
var UPGRADE_CONFIG_AREA = "host config";
|
|
11761
11758
|
var UPGRADE_OWN_ENTRY = "context-mode entry";
|
|
11762
11759
|
var UPGRADE_CACHE_BY_HAND = "remove the release dir by hand: its place is your choice";
|
|
11763
11760
|
var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
|
|
11764
11761
|
var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
|
|
11765
|
-
var GIT_NOT_STARTED = "git did not start";
|
|
11766
11762
|
var GIT_BIN = "git";
|
|
11767
11763
|
var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
|
|
11768
11764
|
var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
|
|
11769
|
-
var GIT_EXIT_LABEL = "git exit ";
|
|
11770
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;
|
|
11771
11770
|
var TABLE_ROW_START = "| ";
|
|
11772
11771
|
var TABLE_CELL_SEP = " | ";
|
|
11773
11772
|
var TABLE_ROW_END = " |";
|
|
@@ -11779,7 +11778,6 @@ var OPS_SPLIT_FILES = Object.freeze([
|
|
|
11779
11778
|
"doctor-hook.ts",
|
|
11780
11779
|
"doctor-db.ts",
|
|
11781
11780
|
"doctor-heal.ts",
|
|
11782
|
-
"release-fetch.ts",
|
|
11783
11781
|
"verify-sums.ts",
|
|
11784
11782
|
"plugin-swap.ts",
|
|
11785
11783
|
"host-write.ts",
|
|
@@ -11835,6 +11833,7 @@ var REGEX_SPECIAL_CHARS = ".*+?^${}()|[]\\";
|
|
|
11835
11833
|
var REGEX_ESCAPE = "\\";
|
|
11836
11834
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
11837
11835
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
11836
|
+
var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
|
|
11838
11837
|
var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
|
|
11839
11838
|
function D5_SLOW_DETAIL(ms) {
|
|
11840
11839
|
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
@@ -11854,19 +11853,19 @@ function D11_PASS_DETAIL(shell, win) {
|
|
|
11854
11853
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
11855
11854
|
var HEAL_TMP_SUFFIX = ".heal";
|
|
11856
11855
|
var HEAL_TS_SEP = ".";
|
|
11857
|
-
var SUMS_LINE_END = "\n";
|
|
11858
|
-
var HASH_ENCODING = "hex";
|
|
11859
|
-
var PLUGIN_LINK_TMP_SUFFIX = ".swap";
|
|
11860
|
-
var PLUGIN_LINK_OLD_SUFFIX = ".old";
|
|
11861
|
-
var PLUGIN_LINK_TYPE = "dir";
|
|
11862
|
-
var PLUGIN_LINK_TYPE_WIN32 = "junction";
|
|
11863
11856
|
var OWNER_STOP_EXT = ".stop";
|
|
11864
11857
|
var UPGRADE_DATA_DELETED = "user data deleted";
|
|
11865
11858
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
11866
11859
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
11867
|
-
codex: "
|
|
11868
|
-
gemini: "gemini extensions
|
|
11869
|
-
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"
|
|
11870
11869
|
});
|
|
11871
11870
|
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
11872
11871
|
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
@@ -11908,6 +11907,7 @@ var HOOKS_JSON_FILE = "hooks.json";
|
|
|
11908
11907
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
11909
11908
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
11910
11909
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
11910
|
+
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
11911
11911
|
var KIRO_HOME_ENV = "KIRO_HOME";
|
|
11912
11912
|
var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
|
|
11913
11913
|
var APPDATA_ENV = "APPDATA";
|
|
@@ -11936,8 +11936,12 @@ var STATUS_LINE_KEY = "statusLine";
|
|
|
11936
11936
|
var PI_PACKAGES_KEY = "packages";
|
|
11937
11937
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
11938
11938
|
var OPENCODE_PLUGINS_KEY = "plugins";
|
|
11939
|
+
var OPENCODE_MCP_COMMAND_FIELD = "command";
|
|
11939
11940
|
var OPENCODE_PACKAGE_FIELD = "package";
|
|
11940
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`;
|
|
11941
11945
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
11942
11946
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
11943
11947
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -11966,17 +11970,22 @@ var V1_REASON = Object.freeze({
|
|
|
11966
11970
|
kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
|
|
11967
11971
|
piNpm: "old context-mode Pi package npm:context-mode",
|
|
11968
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",
|
|
11969
11975
|
zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
|
|
11970
11976
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
11971
11977
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
11972
11978
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
11973
|
-
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"
|
|
11974
11981
|
});
|
|
11975
|
-
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]);
|
|
11976
11984
|
var PLUGIN_NAME = SERVER_KEY;
|
|
11977
11985
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
11978
11986
|
var SERVER_ENTRY_FILE = "server.mjs";
|
|
11979
11987
|
var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
|
|
11988
|
+
var ROOTS_TIMEOUT_MS = 2e3;
|
|
11980
11989
|
var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
|
|
11981
11990
|
var HOST_NODE_COMMAND = "node";
|
|
11982
11991
|
var EXE_SUFFIX = ".exe";
|
|
@@ -12099,7 +12108,7 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
12099
12108
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
12100
12109
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
12101
12110
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
12102
|
-
zcode: ["
|
|
12111
|
+
zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
|
|
12103
12112
|
});
|
|
12104
12113
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
12105
12114
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
@@ -12235,7 +12244,7 @@ var CtxError = class extends Error {
|
|
|
12235
12244
|
};
|
|
12236
12245
|
|
|
12237
12246
|
// src/core/hooks/dispatch.ts
|
|
12238
|
-
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";
|
|
12239
12248
|
|
|
12240
12249
|
// src/core/contracts/agents.ts
|
|
12241
12250
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -12253,9 +12262,9 @@ function canonicalName(name, ownPrefix) {
|
|
|
12253
12262
|
if (name.startsWith(ownPrefix)) return name.slice(ownPrefix.length);
|
|
12254
12263
|
if (!name.startsWith(MCP_PREFIX)) return name;
|
|
12255
12264
|
const rest = name.slice(MCP_PREFIX.length);
|
|
12256
|
-
const
|
|
12257
|
-
if (
|
|
12258
|
-
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);
|
|
12259
12268
|
}
|
|
12260
12269
|
function outputOf(resp) {
|
|
12261
12270
|
if (resp === void 0) return "";
|
|
@@ -12455,6 +12464,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
|
12455
12464
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
12456
12465
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
12457
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";
|
|
12458
12468
|
function own(p, key) {
|
|
12459
12469
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
12460
12470
|
}
|
|
@@ -12474,13 +12484,67 @@ function canonicalName2(name, mcp) {
|
|
|
12474
12484
|
if (typeof server !== "string" || typeof tool !== "string") return name;
|
|
12475
12485
|
return "mcp:" + server + ":" + tool;
|
|
12476
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
|
+
}
|
|
12477
12502
|
function readResult3(resp) {
|
|
12478
12503
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
12479
12504
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
12480
|
-
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);
|
|
12481
12506
|
const err = obj === void 0 ? void 0 : own(obj, "error");
|
|
12482
12507
|
return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
|
|
12483
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
|
+
}
|
|
12484
12548
|
function decode4(raw) {
|
|
12485
12549
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
12486
12550
|
const p = raw;
|
|
@@ -12498,7 +12562,7 @@ function decode4(raw) {
|
|
|
12498
12562
|
ev.tool = {
|
|
12499
12563
|
name,
|
|
12500
12564
|
canonicalName: canonicalName2(name, own(p, "mcp_context")),
|
|
12501
|
-
input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
12565
|
+
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
12502
12566
|
};
|
|
12503
12567
|
}
|
|
12504
12568
|
if (event === "PostToolUse") ev.result = readResult3(own(p, "tool_response"));
|
|
@@ -12516,7 +12580,7 @@ function encode4(ev, d, _extra) {
|
|
|
12516
12580
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
12517
12581
|
case "replace":
|
|
12518
12582
|
if (ev.event !== "PostToolUse") return EMPTY;
|
|
12519
|
-
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 };
|
|
12520
12584
|
}
|
|
12521
12585
|
}
|
|
12522
12586
|
|
|
@@ -12577,6 +12641,14 @@ function canonicalName3(name) {
|
|
|
12577
12641
|
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
12578
12642
|
return name;
|
|
12579
12643
|
}
|
|
12644
|
+
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
12645
|
+
function viewRange(name, input) {
|
|
12646
|
+
const r = input.view_range;
|
|
12647
|
+
if (name !== "view" || !Array.isArray(r) || !isNum(r[0])) return input;
|
|
12648
|
+
const out = { ...input, offset: r[0] };
|
|
12649
|
+
if (isNum(r[1]) && r[1] >= r[0]) out.limit = r[1] - r[0] + 1;
|
|
12650
|
+
return out;
|
|
12651
|
+
}
|
|
12580
12652
|
function readArgs(v) {
|
|
12581
12653
|
if (isRecord(v)) return v;
|
|
12582
12654
|
if (typeof v !== "string") return {};
|
|
@@ -12621,7 +12693,7 @@ function decode6(raw) {
|
|
|
12621
12693
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
12622
12694
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
12623
12695
|
const toolName2 = String(raw[k.tool] ?? "");
|
|
12624
|
-
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
12696
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
|
|
12625
12697
|
ev.tool = tool;
|
|
12626
12698
|
}
|
|
12627
12699
|
if (event === "PostToolUse") ev.result = readResult4(raw[k.result], native.casing, native.failure);
|
|
@@ -12665,22 +12737,22 @@ function canonicalName4(name) {
|
|
|
12665
12737
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
12666
12738
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
12667
12739
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
12668
|
-
const
|
|
12669
|
-
if (
|
|
12670
|
-
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);
|
|
12671
12743
|
}
|
|
12672
|
-
var
|
|
12744
|
+
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
12673
12745
|
function policyInput(name, canonical, input) {
|
|
12674
12746
|
if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
|
|
12675
12747
|
const out = { ...input };
|
|
12676
12748
|
if (name === "read_file") {
|
|
12677
12749
|
if (typeof input.filePath === "string") out.file_path = input.filePath;
|
|
12678
|
-
if (
|
|
12679
|
-
if (
|
|
12680
|
-
} else if (Array.isArray(input.view_range) &&
|
|
12750
|
+
if (isNum2(input.startLine)) out.offset = input.startLine;
|
|
12751
|
+
if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
|
|
12752
|
+
} else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
|
|
12681
12753
|
out.offset = input.view_range[0];
|
|
12682
12754
|
const end = input.view_range[1];
|
|
12683
|
-
if (
|
|
12755
|
+
if (isNum2(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
|
|
12684
12756
|
}
|
|
12685
12757
|
return out;
|
|
12686
12758
|
}
|
|
@@ -12796,9 +12868,9 @@ function canonicalName5(name) {
|
|
|
12796
12868
|
if (Object.hasOwn(NATIVE_TO_CANONICAL6, name)) return NATIVE_TO_CANONICAL6[name];
|
|
12797
12869
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
12798
12870
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
12799
|
-
const
|
|
12800
|
-
if (
|
|
12801
|
-
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);
|
|
12802
12874
|
}
|
|
12803
12875
|
function readResult6(resp) {
|
|
12804
12876
|
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
@@ -12841,6 +12913,7 @@ function encode8(ev, d, _extra) {
|
|
|
12841
12913
|
|
|
12842
12914
|
// src/adapters/zcode.ts
|
|
12843
12915
|
var TOOL_NAME_PREFIX9 = "mcp__context-mode__";
|
|
12916
|
+
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
12844
12917
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
12845
12918
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
12846
12919
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
@@ -12850,7 +12923,9 @@ function decode9(raw) {
|
|
|
12850
12923
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
12851
12924
|
const failure3 = p.hook_event_name === FAILURE_EVENT2;
|
|
12852
12925
|
if (failure3) p.hook_event_name = "PostToolUse";
|
|
12853
|
-
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);
|
|
12854
12929
|
if (failure3) {
|
|
12855
12930
|
const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
|
|
12856
12931
|
ev.result = { isError: true, bytes: Buffer.byteLength(text), text };
|
|
@@ -12873,8 +12948,9 @@ var OPENCODE_EVENTS = {
|
|
|
12873
12948
|
"step-finish": "Usage"
|
|
12874
12949
|
};
|
|
12875
12950
|
var SHELL_TOOL_NAME = "bash";
|
|
12951
|
+
var READ_TOOL_NAME = "read";
|
|
12876
12952
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
12877
|
-
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"])) };
|
|
12878
12954
|
function toCanonicalTool(name) {
|
|
12879
12955
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
12880
12956
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -13102,9 +13178,9 @@ var ADAPTERS = Object.freeze([
|
|
|
13102
13178
|
installMode: "in-process",
|
|
13103
13179
|
projectSource: "spawn-cwd",
|
|
13104
13180
|
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
13105
|
-
nativeTools: { shell: [SHELL_TOOL_NAME] },
|
|
13181
|
+
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
13106
13182
|
execReadOnlyHint: false,
|
|
13107
|
-
// D-HF-OPENCODE-SHELL-1
|
|
13183
|
+
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
13108
13184
|
// Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
|
|
13109
13185
|
eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
|
|
13110
13186
|
compactDelivery: "opencode-cache",
|
|
@@ -13668,6 +13744,9 @@ var SUBSHELL_CLOSE = ")";
|
|
|
13668
13744
|
var CASE_BREAK = ";;";
|
|
13669
13745
|
var FUNC_PARENS = ["(", ")"];
|
|
13670
13746
|
var NOT = "!";
|
|
13747
|
+
function append(out, items) {
|
|
13748
|
+
for (const x of items) out.push(x);
|
|
13749
|
+
}
|
|
13671
13750
|
var KW = Object.freeze({
|
|
13672
13751
|
group: "{",
|
|
13673
13752
|
groupEnd: "}",
|
|
@@ -13847,12 +13926,12 @@ function ifBody(p) {
|
|
|
13847
13926
|
const t = at(p);
|
|
13848
13927
|
if (isWord(t, KW.then) || isWord(t, KW.else)) {
|
|
13849
13928
|
p.i++;
|
|
13850
|
-
out
|
|
13929
|
+
append(out, list(p, [KW.elif, KW.else, KW.fi]));
|
|
13851
13930
|
continue;
|
|
13852
13931
|
}
|
|
13853
13932
|
if (isWord(t, KW.elif)) {
|
|
13854
13933
|
p.i++;
|
|
13855
|
-
out
|
|
13934
|
+
append(out, list(p, [KW.then]));
|
|
13856
13935
|
continue;
|
|
13857
13936
|
}
|
|
13858
13937
|
if (isWord(t, KW.fi)) p.i++;
|
|
@@ -13863,7 +13942,7 @@ function ifBody(p) {
|
|
|
13863
13942
|
function loopBody(p) {
|
|
13864
13943
|
p.i++;
|
|
13865
13944
|
const out = list(p, [KW.do]);
|
|
13866
|
-
out
|
|
13945
|
+
append(out, doBlock(p));
|
|
13867
13946
|
return out;
|
|
13868
13947
|
}
|
|
13869
13948
|
function forBody(p) {
|
|
@@ -13877,10 +13956,10 @@ function forBody(p) {
|
|
|
13877
13956
|
p.i++;
|
|
13878
13957
|
const from = p.i;
|
|
13879
13958
|
while ((at(p)?.kind === "word" || at(p)?.kind === "unhandled") && !isWord(at(p), KW.do)) p.i++;
|
|
13880
|
-
out
|
|
13959
|
+
append(out, carrierOf(p, from, p.i));
|
|
13881
13960
|
}
|
|
13882
13961
|
}
|
|
13883
|
-
out
|
|
13962
|
+
append(out, doBlock(p));
|
|
13884
13963
|
return out;
|
|
13885
13964
|
}
|
|
13886
13965
|
function caseBody(p) {
|
|
@@ -13889,7 +13968,7 @@ function caseBody(p) {
|
|
|
13889
13968
|
const subject = at(p);
|
|
13890
13969
|
if (subject !== void 0 && subject.kind !== "op" && subject.kind !== "io") {
|
|
13891
13970
|
p.i++;
|
|
13892
|
-
out
|
|
13971
|
+
append(out, carrierOf(p, p.i - 1, p.i));
|
|
13893
13972
|
}
|
|
13894
13973
|
if (isWord(at(p), KW.in)) p.i++;
|
|
13895
13974
|
while (p.i < p.toks.length && p.err === null) {
|
|
@@ -13912,7 +13991,7 @@ function caseBody(p) {
|
|
|
13912
13991
|
p.i++;
|
|
13913
13992
|
const body = list(p, [KW.esac]);
|
|
13914
13993
|
tag(body, KW.case);
|
|
13915
|
-
out
|
|
13994
|
+
append(out, body);
|
|
13916
13995
|
}
|
|
13917
13996
|
return out;
|
|
13918
13997
|
}
|
|
@@ -13927,7 +14006,7 @@ function hasFuncParens(p, from) {
|
|
|
13927
14006
|
}
|
|
13928
14007
|
function simple(p) {
|
|
13929
14008
|
const first = p.i;
|
|
13930
|
-
const
|
|
14009
|
+
const words2 = [];
|
|
13931
14010
|
let toFile = false;
|
|
13932
14011
|
while (p.i < p.toks.length) {
|
|
13933
14012
|
const t = p.toks[p.i];
|
|
@@ -13936,7 +14015,7 @@ function simple(p) {
|
|
|
13936
14015
|
toFile = ioRedirect(p) || toFile;
|
|
13937
14016
|
continue;
|
|
13938
14017
|
}
|
|
13939
|
-
if (
|
|
14018
|
+
if (words2.length === 0 && t.kind === "word" && isAssignment(t.text)) {
|
|
13940
14019
|
p.i++;
|
|
13941
14020
|
const open3 = at(p);
|
|
13942
14021
|
if (t.text.endsWith(OPT_VALUE) && open3 !== void 0 && isOp(open3, SUBSHELL_OPEN) && open3.start === t.end) {
|
|
@@ -13950,15 +14029,15 @@ function simple(p) {
|
|
|
13950
14029
|
}
|
|
13951
14030
|
continue;
|
|
13952
14031
|
}
|
|
13953
|
-
|
|
14032
|
+
words2.push(t);
|
|
13954
14033
|
p.i++;
|
|
13955
14034
|
}
|
|
13956
14035
|
if (p.i === first) return EMPTY3();
|
|
13957
14036
|
const raw = p.src.slice(p.toks[first].start, p.toks[p.i - 1].end);
|
|
13958
|
-
if (
|
|
14037
|
+
if (words2.length === 0) return { cmds: carrier(raw), simple: null };
|
|
13959
14038
|
const text = (t) => t.kind === "word" ? dequote(t.text) : t.text;
|
|
13960
|
-
const argv0 = baseName(text(
|
|
13961
|
-
const args =
|
|
14039
|
+
const argv0 = baseName(text(words2[0]));
|
|
14040
|
+
const args = words2.slice(1).map(text);
|
|
13962
14041
|
const cmd = { argv0, args, redirectsToFile: toFile || writesFile(argv0, args), endsInBoundedSink: false, raw };
|
|
13963
14042
|
return { cmds: [cmd], simple: cmd };
|
|
13964
14043
|
}
|
|
@@ -14029,7 +14108,7 @@ function pipeline(p) {
|
|
|
14029
14108
|
let last2 = EMPTY3();
|
|
14030
14109
|
while (p.err === null) {
|
|
14031
14110
|
last2 = element(p);
|
|
14032
|
-
all
|
|
14111
|
+
append(all, last2.cmds);
|
|
14033
14112
|
const t = at(p);
|
|
14034
14113
|
if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
|
|
14035
14114
|
for (const c of last2.cmds) c.pipesOut = true;
|
|
@@ -14058,7 +14137,7 @@ function list(p, stop) {
|
|
|
14058
14137
|
}
|
|
14059
14138
|
if (t.kind === "word" && stop.includes(t.text)) return out;
|
|
14060
14139
|
const before = p.i;
|
|
14061
|
-
out
|
|
14140
|
+
append(out, pipeline(p));
|
|
14062
14141
|
if (p.i === before && p.err === null) p.i++;
|
|
14063
14142
|
}
|
|
14064
14143
|
return out;
|
|
@@ -14071,7 +14150,7 @@ function parseShell(cmd) {
|
|
|
14071
14150
|
const p = { toks: s.tokens, src: cmd, bodies: new Set(s.heredocBodies), i: 0, depth: 0, err: null };
|
|
14072
14151
|
const commands = [];
|
|
14073
14152
|
while (p.i < p.toks.length && p.err === null) {
|
|
14074
|
-
commands
|
|
14153
|
+
append(commands, list(p, NO_STOP));
|
|
14075
14154
|
if (p.i < p.toks.length) p.i++;
|
|
14076
14155
|
}
|
|
14077
14156
|
if (p.err !== null) return { ok: false, construct: p.err };
|
|
@@ -14326,57 +14405,57 @@ function param(word, names) {
|
|
|
14326
14405
|
const hits = names.filter((p) => p.startsWith(name));
|
|
14327
14406
|
return { full: hits.length === 1 ? hits[0] : void 0, inline };
|
|
14328
14407
|
}
|
|
14329
|
-
function psDump(
|
|
14330
|
-
if (
|
|
14331
|
-
const name = cmdName(
|
|
14408
|
+
function psDump(words2) {
|
|
14409
|
+
if (words2.length === 0) return null;
|
|
14410
|
+
const name = cmdName(words2[0]);
|
|
14332
14411
|
if (!READ_COMMANDS.includes(name)) {
|
|
14333
|
-
const lower =
|
|
14412
|
+
const lower = words2[0].toLowerCase();
|
|
14334
14413
|
const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
|
|
14335
|
-
if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) ||
|
|
14336
|
-
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 };
|
|
14337
14416
|
}
|
|
14338
14417
|
const files = [];
|
|
14339
14418
|
let bounded = false;
|
|
14340
|
-
for (let k = 1; k <
|
|
14341
|
-
const a =
|
|
14419
|
+
for (let k = 1; k < words2.length; k++) {
|
|
14420
|
+
const a = words2[k];
|
|
14342
14421
|
if (!a.startsWith(DASH) || a.length === DASH.length) {
|
|
14343
14422
|
files.push(a);
|
|
14344
14423
|
continue;
|
|
14345
14424
|
}
|
|
14346
14425
|
const p = param(a, ALL_PARAMS);
|
|
14347
14426
|
if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
|
|
14348
|
-
const value = p.inline ??
|
|
14427
|
+
const value = p.inline ?? words2[++k];
|
|
14349
14428
|
if (value === void 0) return null;
|
|
14350
14429
|
if (PATH_PARAMS.includes(p.full)) files.push(value);
|
|
14351
14430
|
if (BOUND_PARAMS.includes(p.full)) bounded = true;
|
|
14352
14431
|
}
|
|
14353
14432
|
return files.length === 1 ? { file: files[0], bounded } : null;
|
|
14354
14433
|
}
|
|
14355
|
-
function nestedScript(name,
|
|
14434
|
+
function nestedScript(name, words2) {
|
|
14356
14435
|
if (POWERSHELLS.includes(name)) {
|
|
14357
|
-
for (let k = 1; k <
|
|
14358
|
-
const w =
|
|
14436
|
+
for (let k = 1; k < words2.length; k++) {
|
|
14437
|
+
const w = words2[k];
|
|
14359
14438
|
if (!w.startsWith(DASH) || w.length === DASH.length) continue;
|
|
14360
14439
|
const p = param(w, [COMMAND_PARAM]);
|
|
14361
14440
|
if (p.full === void 0) continue;
|
|
14362
|
-
return [...p.inline === void 0 ? [] : [p.inline], ...
|
|
14441
|
+
return [...p.inline === void 0 ? [] : [p.inline], ...words2.slice(k + 1)].join(" ");
|
|
14363
14442
|
}
|
|
14364
14443
|
return null;
|
|
14365
14444
|
}
|
|
14366
14445
|
if (CMDS.includes(name)) {
|
|
14367
|
-
for (let k = 1; k <
|
|
14368
|
-
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(" ");
|
|
14369
14448
|
}
|
|
14370
14449
|
}
|
|
14371
14450
|
return null;
|
|
14372
14451
|
}
|
|
14373
|
-
function cdTarget(
|
|
14374
|
-
for (let k = 1; k <
|
|
14375
|
-
const w =
|
|
14452
|
+
function cdTarget(words2) {
|
|
14453
|
+
for (let k = 1; k < words2.length; k++) {
|
|
14454
|
+
const w = words2[k];
|
|
14376
14455
|
if (w.toLowerCase() === "/d") continue;
|
|
14377
14456
|
if (!w.startsWith(DASH) || w.length === DASH.length) return w;
|
|
14378
14457
|
const p = param(w, PATH_PARAMS);
|
|
14379
|
-
if (p.full !== void 0) return p.inline ??
|
|
14458
|
+
if (p.full !== void 0) return p.inline ?? words2[k + 1] ?? null;
|
|
14380
14459
|
}
|
|
14381
14460
|
return null;
|
|
14382
14461
|
}
|
|
@@ -14476,6 +14555,10 @@ function copilotDirOf(env, home) {
|
|
|
14476
14555
|
const dir = env[COPILOT_HOME_ENV];
|
|
14477
14556
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
14478
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
|
+
}
|
|
14479
14562
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
14480
14563
|
const p = platform === "win32" ? win32 : posix;
|
|
14481
14564
|
const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
|
|
@@ -14534,8 +14617,13 @@ function requireHomeDir(env, platform = process.platform) {
|
|
|
14534
14617
|
if (home !== null) return home;
|
|
14535
14618
|
throw new CtxError("NO_HOME", { name: platform === "win32" ? "USERPROFILE" : "HOME" });
|
|
14536
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
|
+
}
|
|
14537
14624
|
function resolveConfigDir(env) {
|
|
14538
|
-
const
|
|
14625
|
+
const set3 = env[DATA_DIR_ENV];
|
|
14626
|
+
const dir = dataRootOf(env, set3 !== void 0 && set3 !== "" ? "" : requireHomeDir(env));
|
|
14539
14627
|
mkdirSync(dir, { recursive: true });
|
|
14540
14628
|
return realpathSync.native(dir);
|
|
14541
14629
|
}
|
|
@@ -14907,14 +14995,13 @@ function tokenize(glob, path8) {
|
|
|
14907
14995
|
}
|
|
14908
14996
|
return toks;
|
|
14909
14997
|
}
|
|
14910
|
-
function
|
|
14911
|
-
const toks = tokenize(glob, path8);
|
|
14998
|
+
function matchStarts(toks, text, path8, ends) {
|
|
14912
14999
|
const n = text.length;
|
|
14913
|
-
let next =
|
|
14914
|
-
|
|
15000
|
+
let next = ends;
|
|
15001
|
+
let cur = new Uint8Array(n + 1);
|
|
14915
15002
|
for (let i = toks.length - 1; i >= 0; i--) {
|
|
14916
15003
|
const tok = toks[i];
|
|
14917
|
-
|
|
15004
|
+
if (next === ends) next = Uint8Array.from(ends);
|
|
14918
15005
|
let acc = 0;
|
|
14919
15006
|
for (let j = n; j >= 0; j--) {
|
|
14920
15007
|
const has3 = j < n;
|
|
@@ -14938,9 +15025,19 @@ function globMatch(glob, text, path8) {
|
|
|
14938
15025
|
break;
|
|
14939
15026
|
}
|
|
14940
15027
|
}
|
|
14941
|
-
|
|
15028
|
+
const done = cur;
|
|
15029
|
+
cur = next;
|
|
15030
|
+
next = done;
|
|
14942
15031
|
}
|
|
14943
|
-
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;
|
|
14944
15041
|
}
|
|
14945
15042
|
function parsePattern(pattern) {
|
|
14946
15043
|
const open3 = pattern.indexOf("(");
|
|
@@ -14948,14 +15045,25 @@ function parsePattern(pattern) {
|
|
|
14948
15045
|
const glob = pattern.slice(open3 + 1, pattern.length - ")".length);
|
|
14949
15046
|
return glob === "" ? null : { tool: pattern.slice(0, open3), glob };
|
|
14950
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
|
+
}
|
|
14951
15056
|
function matchCommand(glob, text) {
|
|
14952
|
-
|
|
14953
|
-
|
|
14954
|
-
|
|
14955
|
-
for (
|
|
14956
|
-
|
|
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;
|
|
14957
15065
|
}
|
|
14958
|
-
return
|
|
15066
|
+
return null;
|
|
14959
15067
|
}
|
|
14960
15068
|
var DRIVE_PREFIX = /^[A-Za-z]:(?=\/)/;
|
|
14961
15069
|
function toSlash(p) {
|
|
@@ -15027,6 +15135,7 @@ var HOST_SEP = ".";
|
|
|
15027
15135
|
var SED_RANGE_SEP = ",";
|
|
15028
15136
|
var SED_PRINT = "p";
|
|
15029
15137
|
var SED_SCRIPT_FLAGS = ["-e", "--expression"];
|
|
15138
|
+
var EXE_SUFFIX2 = ".exe";
|
|
15030
15139
|
var COMMAND_STARTS = ";&|(`\n\r";
|
|
15031
15140
|
var ALLOW = Object.freeze({ kind: "allow" });
|
|
15032
15141
|
var deny = (reason) => ({ kind: "deny", reason });
|
|
@@ -15064,6 +15173,11 @@ function readPath(input) {
|
|
|
15064
15173
|
}
|
|
15065
15174
|
return void 0;
|
|
15066
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
|
+
}
|
|
15067
15181
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
15068
15182
|
if (rules.length === 0) return null;
|
|
15069
15183
|
const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
@@ -15072,35 +15186,65 @@ function userDenyHit(canonical, input, cwd, rules) {
|
|
|
15072
15186
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
15073
15187
|
}
|
|
15074
15188
|
if (canonical === READ) {
|
|
15075
|
-
const p
|
|
15076
|
-
|
|
15189
|
+
for (const p of readPaths(input)) {
|
|
15190
|
+
const h = readRule(p);
|
|
15191
|
+
if (h !== null) return h;
|
|
15192
|
+
}
|
|
15193
|
+
return null;
|
|
15077
15194
|
}
|
|
15078
15195
|
if (canonical === CTX_EXECUTE) {
|
|
15079
15196
|
const file2 = str(input.file);
|
|
15080
15197
|
const byFile = file2 === void 0 || file2 === "" ? null : readRule(file2);
|
|
15081
15198
|
if (byFile !== null) return byFile;
|
|
15082
15199
|
const code = str(input.code);
|
|
15083
|
-
return input.language
|
|
15200
|
+
return isShellLanguage(input.language) && code !== void 0 ? shellHit(code, rules) : null;
|
|
15084
15201
|
}
|
|
15085
15202
|
if (canonical === CTX_BATCH && Array.isArray(input.commands)) {
|
|
15086
15203
|
for (const c of input.commands) {
|
|
15087
|
-
const h = typeof c === "string" ?
|
|
15204
|
+
const h = typeof c === "string" ? shellHit(c, rules) : null;
|
|
15088
15205
|
if (h !== null) return h;
|
|
15089
15206
|
}
|
|
15090
15207
|
}
|
|
15091
15208
|
return null;
|
|
15092
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
|
+
}
|
|
15093
15229
|
function segmentHit(c, rules) {
|
|
15094
15230
|
if (rules.length === 0) return null;
|
|
15095
15231
|
return matchesAnyDenyPattern([c.argv0, ...c.args].join(" "), rules) ?? matchesAnyDenyPattern(c.raw, rules);
|
|
15096
15232
|
}
|
|
15097
|
-
function
|
|
15098
|
-
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;
|
|
15099
15237
|
for (let k = 0; k <= text.length; k++) {
|
|
15100
|
-
if (k
|
|
15101
|
-
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
|
+
}
|
|
15102
15243
|
}
|
|
15103
|
-
return
|
|
15244
|
+
return denyPatternFromAny(text, rules, from);
|
|
15245
|
+
}
|
|
15246
|
+
function couldMatch(text, rules) {
|
|
15247
|
+
return couldMatchRule(text, rules) !== null;
|
|
15104
15248
|
}
|
|
15105
15249
|
function neverDenied(url4) {
|
|
15106
15250
|
let host;
|
|
@@ -15175,8 +15319,7 @@ function fileSize(abs) {
|
|
|
15175
15319
|
}
|
|
15176
15320
|
function read(ev, row5, input) {
|
|
15177
15321
|
if (!present(input.offset) && !present(input.limit)) {
|
|
15178
|
-
const p
|
|
15179
|
-
if (p !== void 0) {
|
|
15322
|
+
for (const p of readPaths(input)) {
|
|
15180
15323
|
const abs = resolve3(ev.cwd, p);
|
|
15181
15324
|
const size = fileSize(abs);
|
|
15182
15325
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
@@ -15270,11 +15413,11 @@ function dumpTarget(name, args) {
|
|
|
15270
15413
|
}
|
|
15271
15414
|
|
|
15272
15415
|
// src/core/project/resolve.ts
|
|
15273
|
-
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";
|
|
15274
15417
|
|
|
15275
15418
|
// src/core/project/contain.ts
|
|
15276
|
-
import { dirname as dirname2, sep as sep2 } from "node:path";
|
|
15277
|
-
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");
|
|
15278
15421
|
function real(p) {
|
|
15279
15422
|
try {
|
|
15280
15423
|
return realpathSync2.native(p);
|
|
@@ -15313,6 +15456,21 @@ function commonRoot(paths) {
|
|
|
15313
15456
|
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
15314
15457
|
return q;
|
|
15315
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
|
+
}
|
|
15316
15474
|
|
|
15317
15475
|
// src/core/project/sha256.ts
|
|
15318
15476
|
var K = new Uint32Array([
|
|
@@ -15474,9 +15632,9 @@ function gitDirs(dir) {
|
|
|
15474
15632
|
}
|
|
15475
15633
|
const start = cur;
|
|
15476
15634
|
for (; ; ) {
|
|
15477
|
-
const gitDir = gitDirAt(
|
|
15635
|
+
const gitDir = gitDirAt(join5(cur, GIT_DIR_NAME));
|
|
15478
15636
|
if (gitDir !== null) {
|
|
15479
|
-
const common = firstLine(
|
|
15637
|
+
const common = firstLine(join5(gitDir, GIT_COMMONDIR_FILE));
|
|
15480
15638
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
15481
15639
|
}
|
|
15482
15640
|
const up = dirname3(cur);
|
|
@@ -15497,7 +15655,7 @@ function gitDirAt(dotGit) {
|
|
|
15497
15655
|
} catch {
|
|
15498
15656
|
return null;
|
|
15499
15657
|
}
|
|
15500
|
-
return existsSync(
|
|
15658
|
+
return existsSync(join5(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
15501
15659
|
}
|
|
15502
15660
|
function firstLine(file2) {
|
|
15503
15661
|
let text;
|
|
@@ -15538,11 +15696,11 @@ function resolveProject(agent, src) {
|
|
|
15538
15696
|
return key;
|
|
15539
15697
|
},
|
|
15540
15698
|
get projectDir() {
|
|
15541
|
-
pdir ??=
|
|
15699
|
+
pdir ??= join5(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
15542
15700
|
return pdir;
|
|
15543
15701
|
},
|
|
15544
15702
|
get dbPath() {
|
|
15545
|
-
return
|
|
15703
|
+
return join5(this.projectDir, DB_FILE_NAME);
|
|
15546
15704
|
},
|
|
15547
15705
|
worktree,
|
|
15548
15706
|
get containmentRoot() {
|
|
@@ -15683,6 +15841,15 @@ function applyMigrations(db, fromVersion) {
|
|
|
15683
15841
|
}
|
|
15684
15842
|
}
|
|
15685
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
|
+
|
|
15686
15853
|
// src/core/store/db.ts
|
|
15687
15854
|
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
15688
15855
|
function versionParts(v) {
|
|
@@ -15748,7 +15915,7 @@ function openWritable(sqlite, path8) {
|
|
|
15748
15915
|
}
|
|
15749
15916
|
}
|
|
15750
15917
|
function openReadOnly(sqlite, path8) {
|
|
15751
|
-
const raw =
|
|
15918
|
+
const raw = openReadOnlyHandle(sqlite, path8);
|
|
15752
15919
|
try {
|
|
15753
15920
|
const found = readUserVersion(raw);
|
|
15754
15921
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -15968,14 +16135,14 @@ function identParts(w) {
|
|
|
15968
16135
|
if (cur !== "") parts.push(cur);
|
|
15969
16136
|
return parts;
|
|
15970
16137
|
}
|
|
15971
|
-
function snippetTerms(
|
|
16138
|
+
function snippetTerms(words2) {
|
|
15972
16139
|
const out = /* @__PURE__ */ new Map();
|
|
15973
16140
|
const add = (text, weight, symbol2) => {
|
|
15974
16141
|
if (text === "") return;
|
|
15975
16142
|
const prev = out.get(text);
|
|
15976
16143
|
if (!prev || prev.weight < weight) out.set(text, { text, weight, symbol: symbol2 });
|
|
15977
16144
|
};
|
|
15978
|
-
for (const raw of
|
|
16145
|
+
for (const raw of words2) {
|
|
15979
16146
|
let a = 0;
|
|
15980
16147
|
let b = raw.length;
|
|
15981
16148
|
while (a < b && !isAlnum(raw.charCodeAt(a))) a++;
|
|
@@ -17981,18 +18148,18 @@ function deleteChunkRows(raw, scope) {
|
|
|
17981
18148
|
return Number(raw.prepare("DELETE FROM chunks WHERE " + where).run(arg).changes);
|
|
17982
18149
|
}
|
|
17983
18150
|
function toMatch(q) {
|
|
17984
|
-
const
|
|
18151
|
+
const words2 = [];
|
|
17985
18152
|
let cur = "";
|
|
17986
18153
|
for (const ch of q) {
|
|
17987
18154
|
if (ch.trim() === "" || ch === "\0") {
|
|
17988
|
-
if (cur !== "")
|
|
18155
|
+
if (cur !== "") words2.push(cur);
|
|
17989
18156
|
cur = "";
|
|
17990
18157
|
} else {
|
|
17991
18158
|
cur += ch === '"' ? '""' : ch;
|
|
17992
18159
|
}
|
|
17993
18160
|
}
|
|
17994
|
-
if (cur !== "")
|
|
17995
|
-
return
|
|
18161
|
+
if (cur !== "") words2.push(cur);
|
|
18162
|
+
return words2.map((w) => `"${w}"*`).join(" ");
|
|
17996
18163
|
}
|
|
17997
18164
|
function toMatchAny(q) {
|
|
17998
18165
|
const terms = new Set(toMatch(q).split(" ").filter((t) => t !== ""));
|
|
@@ -18089,11 +18256,11 @@ function searchTerms(q) {
|
|
|
18089
18256
|
return kept.length > 0 ? kept : all;
|
|
18090
18257
|
}
|
|
18091
18258
|
function trigramMatch(q) {
|
|
18092
|
-
const
|
|
18093
|
-
const kept =
|
|
18094
|
-
const parts = new Set((kept.length > 0 ? kept :
|
|
18095
|
-
const whole2 =
|
|
18096
|
-
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);
|
|
18097
18264
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
18098
18265
|
}
|
|
18099
18266
|
function editDistance(a, b, max) {
|
|
@@ -18140,10 +18307,10 @@ function queryStems(q) {
|
|
|
18140
18307
|
}
|
|
18141
18308
|
var TYPO_MIN_LEN = 5;
|
|
18142
18309
|
var TYPO_MAX_DIST = 2;
|
|
18143
|
-
function typoTerms(db,
|
|
18310
|
+
function typoTerms(db, words2) {
|
|
18144
18311
|
const has3 = stmt(db.raw, "SELECT 1 AS x FROM chunks_vocab WHERE term = ?");
|
|
18145
18312
|
const near = stmt(db.raw, "SELECT term, doc, length(term) AS n FROM chunks_vocab WHERE length(term) BETWEEN ? AND ?");
|
|
18146
|
-
const stems = queryStems(
|
|
18313
|
+
const stems = queryStems(words2.join(" "));
|
|
18147
18314
|
const miss = stems.map((stem) => has3.get(stem) === void 0 && [...stem].length >= TYPO_MIN_LEN);
|
|
18148
18315
|
if (!miss.includes(true)) return null;
|
|
18149
18316
|
const lens = stems.filter((_, i) => miss[i]).map((stem) => stem.length);
|
|
@@ -18246,9 +18413,9 @@ function ftsListSource(db, source, scope, ctx, sessionId, limit, offset) {
|
|
|
18246
18413
|
}));
|
|
18247
18414
|
}
|
|
18248
18415
|
function highlight(row5, terms, maxBytes = SNIPPET_MAX_BYTES) {
|
|
18249
|
-
const
|
|
18250
|
-
const kept =
|
|
18251
|
-
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);
|
|
18252
18419
|
}
|
|
18253
18420
|
var TL_SCOPE = `
|
|
18254
18421
|
AND (:scope <> 'session' OR session_id = :session_id)
|
|
@@ -18514,13 +18681,24 @@ function buildUnits(text) {
|
|
|
18514
18681
|
const lines = text.split("\n");
|
|
18515
18682
|
const stack2 = [];
|
|
18516
18683
|
const out = [];
|
|
18684
|
+
let left = UNITS_ANCESTOR_FACTOR * Buffer.byteLength(text, "utf8");
|
|
18517
18685
|
for (let i = 0; i < lines.length; i++) {
|
|
18518
18686
|
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
18519
18687
|
const indent = indentOf(line);
|
|
18520
18688
|
if (indent === line.length) continue;
|
|
18521
18689
|
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
18522
|
-
|
|
18523
|
-
|
|
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 });
|
|
18524
18702
|
}
|
|
18525
18703
|
return out;
|
|
18526
18704
|
}
|
|
@@ -18659,7 +18837,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
18659
18837
|
const pool = cands.filter((u) => !seen.has(unitKey(u)) && u.score >= RECALL_MIN_SCORE);
|
|
18660
18838
|
if (pool.length === 0) return [];
|
|
18661
18839
|
const top = Math.max(...pool.map((u) => u.score));
|
|
18662
|
-
const
|
|
18840
|
+
const words2 = pool.map((u) => wordsOf(u.body));
|
|
18663
18841
|
const taken = [];
|
|
18664
18842
|
const left = new Set(pool.map((_, i) => i));
|
|
18665
18843
|
let used = 0;
|
|
@@ -18668,7 +18846,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
18668
18846
|
let bestVal = -Infinity;
|
|
18669
18847
|
for (const i of left) {
|
|
18670
18848
|
let sim = 0;
|
|
18671
|
-
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]));
|
|
18672
18850
|
const val = MMR_RELEVANCE_WEIGHT * (pool[i].score / top) - MMR_REDUNDANCY_WEIGHT * sim;
|
|
18673
18851
|
if (val > bestVal) {
|
|
18674
18852
|
bestVal = val;
|
|
@@ -19071,7 +19249,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
19071
19249
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
19072
19250
|
return { end: start + r.read, written: r.written };
|
|
19073
19251
|
}
|
|
19074
|
-
function merge2(src, blocks,
|
|
19252
|
+
function merge2(src, blocks, join26, cap, lineCut) {
|
|
19075
19253
|
const out = [];
|
|
19076
19254
|
const scratch = new Uint8Array(cap);
|
|
19077
19255
|
let wide;
|
|
@@ -19081,7 +19259,7 @@ function merge2(src, blocks, join29, cap, lineCut) {
|
|
|
19081
19259
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
19082
19260
|
};
|
|
19083
19261
|
for (const b of blocks) {
|
|
19084
|
-
if (cur !== void 0 && !
|
|
19262
|
+
if (cur !== void 0 && !join26) {
|
|
19085
19263
|
emit(cur.start, cur.end, curBytes);
|
|
19086
19264
|
cur = void 0;
|
|
19087
19265
|
}
|
|
@@ -19199,11 +19377,11 @@ function shapeDigest(text, query, budget) {
|
|
|
19199
19377
|
const picked = [];
|
|
19200
19378
|
let used = 0;
|
|
19201
19379
|
for (const i of order) {
|
|
19202
|
-
const
|
|
19203
|
-
const r = shape.units[i].render(budget - used -
|
|
19204
|
-
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;
|
|
19205
19383
|
picked.push({ pos: shape.units[i].pos, text: r });
|
|
19206
|
-
used +=
|
|
19384
|
+
used += sep5 + bytes(r);
|
|
19207
19385
|
}
|
|
19208
19386
|
if (picked.length === 0) return null;
|
|
19209
19387
|
picked.sort((a, b) => a.pos - b.pos);
|
|
@@ -19523,7 +19701,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
19523
19701
|
}
|
|
19524
19702
|
|
|
19525
19703
|
// src/core/hooks/fallback.ts
|
|
19526
|
-
import { join as
|
|
19704
|
+
import { join as join6, resolve as resolve5 } from "node:path";
|
|
19527
19705
|
var fs = process.getBuiltinModule("node:fs");
|
|
19528
19706
|
function isRec(v) {
|
|
19529
19707
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -19550,8 +19728,10 @@ function homeOf(env) {
|
|
|
19550
19728
|
return env.HOME ?? env.USERPROFILE ?? "";
|
|
19551
19729
|
}
|
|
19552
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);
|
|
19553
19733
|
const home = homeOf(env);
|
|
19554
|
-
return home === "" ? "" :
|
|
19734
|
+
return home === "" ? "" : join6(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
19555
19735
|
}
|
|
19556
19736
|
function errorLabel(err) {
|
|
19557
19737
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -19562,7 +19742,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
19562
19742
|
try {
|
|
19563
19743
|
const file2 = hookLogPath(env);
|
|
19564
19744
|
if (file2 === "") return;
|
|
19565
|
-
fs.mkdirSync(
|
|
19745
|
+
fs.mkdirSync(join6(file2, ".."), { recursive: true });
|
|
19566
19746
|
const line = JSON.stringify({
|
|
19567
19747
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19568
19748
|
agent,
|
|
@@ -19633,17 +19813,19 @@ function isPreTool(row5, event) {
|
|
|
19633
19813
|
const e = event.toLowerCase();
|
|
19634
19814
|
return HOOK_FAIL_PRE_EVENTS.includes(e) || (row5.eventMap.PreToolUse ?? "").toLowerCase() === e;
|
|
19635
19815
|
}
|
|
19636
|
-
function
|
|
19637
|
-
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
19638
|
-
const p = firstString(input, READ_PATH_KEYS);
|
|
19639
|
-
if (p === "") return false;
|
|
19816
|
+
function bigFile(abs) {
|
|
19640
19817
|
try {
|
|
19641
|
-
const st = fs.statSync(
|
|
19818
|
+
const st = fs.statSync(abs);
|
|
19642
19819
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
19643
19820
|
} catch {
|
|
19644
19821
|
return false;
|
|
19645
19822
|
}
|
|
19646
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
|
+
}
|
|
19647
19829
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
19648
19830
|
const row5 = getAdapter(agent);
|
|
19649
19831
|
const allow = () => row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
@@ -19668,7 +19850,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
19668
19850
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
19669
19851
|
|
|
19670
19852
|
// src/core/hooks/dispatch.ts
|
|
19671
|
-
var { readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
19853
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
|
|
19672
19854
|
var ALLOW2 = { kind: "allow" };
|
|
19673
19855
|
var EMPTY4 = { stdout: "", exitCode: 0 };
|
|
19674
19856
|
var DIGIT_0 = 48;
|
|
@@ -19929,7 +20111,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
19929
20111
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
19930
20112
|
const command = tool.input.command;
|
|
19931
20113
|
if (typeof command !== "string") return d0;
|
|
19932
|
-
const wrapper = '"' +
|
|
20114
|
+
const wrapper = '"' + join7(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
19933
20115
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
19934
20116
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
19935
20117
|
}
|
|
@@ -19970,7 +20152,7 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
19970
20152
|
const tool = ev.tool;
|
|
19971
20153
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
19972
20154
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
19973
|
-
const text = wholeOutput(result);
|
|
20155
|
+
const text = wholeOutput(result, ev.sessionId, env);
|
|
19974
20156
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
19975
20157
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
19976
20158
|
const kind = journalKind(tool, row5, result.isError);
|
|
@@ -20008,6 +20190,7 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
20008
20190
|
}
|
|
20009
20191
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
20010
20192
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
20193
|
+
if (boundedRead(tool)) return ALLOW2;
|
|
20011
20194
|
if (result.keep === true) return ALLOW2;
|
|
20012
20195
|
if (!hasReplace(row5)) return ALLOW2;
|
|
20013
20196
|
let label2;
|
|
@@ -20039,16 +20222,32 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
20039
20222
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
20040
20223
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, handleLine) : selected.text };
|
|
20041
20224
|
}
|
|
20225
|
+
function boundedRead(tool) {
|
|
20226
|
+
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
20227
|
+
}
|
|
20042
20228
|
function replaceOutput(body, handleLine) {
|
|
20043
20229
|
return body === "" ? handleLine : body + "\n" + handleLine;
|
|
20044
20230
|
}
|
|
20045
20231
|
function replaceBudget(handleLine, more) {
|
|
20046
20232
|
return Math.max(0, REPLACE_RETURN_BYTES + Buffer.byteLength("\n" + more) - 1 - Buffer.byteLength(handleLine));
|
|
20047
20233
|
}
|
|
20048
|
-
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) {
|
|
20049
20244
|
const head = result.text ?? "";
|
|
20050
20245
|
if (result.persistedPath === void 0) return head;
|
|
20051
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
|
+
}
|
|
20052
20251
|
return readFileSync4(result.persistedPath, "utf8");
|
|
20053
20252
|
} catch {
|
|
20054
20253
|
return head;
|
|
@@ -20228,10 +20427,10 @@ function findRuntime(lang, env = process.env) {
|
|
|
20228
20427
|
return shim;
|
|
20229
20428
|
}
|
|
20230
20429
|
function findGitBash(env) {
|
|
20231
|
-
const
|
|
20232
|
-
if (
|
|
20430
|
+
const git2 = findRuntime(GIT_BIN, env);
|
|
20431
|
+
if (git2 === null) return null;
|
|
20233
20432
|
for (const rel of GIT_BASH_RELATIVE) {
|
|
20234
|
-
const full = path.resolve(path.dirname(
|
|
20433
|
+
const full = path.resolve(path.dirname(git2), ...rel);
|
|
20235
20434
|
if (isRunnable(full)) return full;
|
|
20236
20435
|
}
|
|
20237
20436
|
return null;
|
|
@@ -20272,10 +20471,10 @@ function startArgv(argv) {
|
|
|
20272
20471
|
return sh === null ? null : [sh, ...argv];
|
|
20273
20472
|
}
|
|
20274
20473
|
function runProcess(argv, o) {
|
|
20275
|
-
return new Promise((
|
|
20474
|
+
return new Promise((resolve9) => {
|
|
20276
20475
|
const isWin2 = process.platform === "win32";
|
|
20277
20476
|
const start = startArgv(argv);
|
|
20278
|
-
if (start === null) return
|
|
20477
|
+
if (start === null) return resolve9(NOT_STARTED);
|
|
20279
20478
|
let child;
|
|
20280
20479
|
try {
|
|
20281
20480
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -20289,7 +20488,7 @@ function runProcess(argv, o) {
|
|
|
20289
20488
|
windowsHide: true
|
|
20290
20489
|
});
|
|
20291
20490
|
} catch {
|
|
20292
|
-
return
|
|
20491
|
+
return resolve9(NOT_STARTED);
|
|
20293
20492
|
}
|
|
20294
20493
|
const stdoutChunks = [];
|
|
20295
20494
|
const stderrChunks = [];
|
|
@@ -20314,7 +20513,7 @@ function runProcess(argv, o) {
|
|
|
20314
20513
|
settled = true;
|
|
20315
20514
|
clearTimeout(timer);
|
|
20316
20515
|
o.signal.removeEventListener("abort", onAbort);
|
|
20317
|
-
|
|
20516
|
+
resolve9({
|
|
20318
20517
|
stdout: Buffer.concat(stdoutChunks),
|
|
20319
20518
|
stderr: Buffer.concat(stderrChunks),
|
|
20320
20519
|
exitCode,
|
|
@@ -20336,7 +20535,7 @@ function runProcess(argv, o) {
|
|
|
20336
20535
|
|
|
20337
20536
|
// src/core/index/auto-memory.ts
|
|
20338
20537
|
import { readdirSync, readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
|
|
20339
|
-
import { join as
|
|
20538
|
+
import { join as join8 } from "node:path";
|
|
20340
20539
|
var MEMORY_FILES = Object.freeze([
|
|
20341
20540
|
Object.freeze(["CLAUDE.md"]),
|
|
20342
20541
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -20350,7 +20549,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20350
20549
|
var MD = ".md";
|
|
20351
20550
|
function steeringFiles(worktree) {
|
|
20352
20551
|
try {
|
|
20353
|
-
return readdirSync(
|
|
20552
|
+
return readdirSync(join8(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20354
20553
|
} catch {
|
|
20355
20554
|
return [];
|
|
20356
20555
|
}
|
|
@@ -20358,7 +20557,7 @@ function steeringFiles(worktree) {
|
|
|
20358
20557
|
function readAutoMemory(project) {
|
|
20359
20558
|
const rows = [];
|
|
20360
20559
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20361
|
-
const path8 =
|
|
20560
|
+
const path8 = join8(project.worktree, ...segs);
|
|
20362
20561
|
if (!isInside(project.worktree, path8)) continue;
|
|
20363
20562
|
try {
|
|
20364
20563
|
const st = statSync4(path8);
|
|
@@ -20941,18 +21140,18 @@ var ctxBatch = Object.freeze({
|
|
|
20941
21140
|
|
|
20942
21141
|
// src/core/tools/doctor.ts
|
|
20943
21142
|
import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
|
|
20944
|
-
import { basename as basename5, join as
|
|
21143
|
+
import { basename as basename5, join as join18 } from "node:path";
|
|
20945
21144
|
|
|
20946
21145
|
// src/core/ops/bundle-dir.ts
|
|
20947
21146
|
import { existsSync as existsSync3 } from "node:fs";
|
|
20948
|
-
import { dirname as dirname5, join as
|
|
21147
|
+
import { dirname as dirname5, join as join9 } from "node:path";
|
|
20949
21148
|
import { fileURLToPath } from "node:url";
|
|
20950
21149
|
function bundleDirOf(argv1, moduleFile) {
|
|
20951
21150
|
const own4 = dirname5(argv1);
|
|
20952
|
-
if (existsSync3(
|
|
21151
|
+
if (existsSync3(join9(own4, SERVER_ENTRY_FILE))) return own4;
|
|
20953
21152
|
let dir = dirname5(moduleFile);
|
|
20954
21153
|
for (; ; ) {
|
|
20955
|
-
if (existsSync3(
|
|
21154
|
+
if (existsSync3(join9(dir, SERVER_ENTRY_FILE))) return dir;
|
|
20956
21155
|
const up = dirname5(dir);
|
|
20957
21156
|
if (up === dir) return own4;
|
|
20958
21157
|
dir = up;
|
|
@@ -20967,16 +21166,16 @@ function ownBundleDir() {
|
|
|
20967
21166
|
|
|
20968
21167
|
// src/core/ops/doctor-config.ts
|
|
20969
21168
|
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
20970
|
-
import { join as
|
|
21169
|
+
import { join as join13 } from "node:path";
|
|
20971
21170
|
|
|
20972
21171
|
// src/core/ops/detect-v1.ts
|
|
20973
21172
|
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
|
|
20974
21173
|
import { tmpdir } from "node:os";
|
|
20975
|
-
import { join as
|
|
21174
|
+
import { join as join11 } from "node:path";
|
|
20976
21175
|
|
|
20977
21176
|
// src/core/ops/host-config.ts
|
|
20978
21177
|
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
20979
|
-
import { dirname as dirname6, join as
|
|
21178
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
20980
21179
|
|
|
20981
21180
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
20982
21181
|
var KEYS2 = {
|
|
@@ -23093,7 +23292,7 @@ function formatOf(path8) {
|
|
|
23093
23292
|
function readHostConfig(agent, path8) {
|
|
23094
23293
|
let file2 = path8;
|
|
23095
23294
|
if (agent === "opencode") {
|
|
23096
|
-
const jsonc =
|
|
23295
|
+
const jsonc = join10(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23097
23296
|
if (existsSync4(jsonc)) file2 = jsonc;
|
|
23098
23297
|
}
|
|
23099
23298
|
const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -23404,8 +23603,8 @@ function replaceToml(text, doc, path8, value) {
|
|
|
23404
23603
|
let out = text;
|
|
23405
23604
|
for (const [s, e, put] of cuts) out = out.slice(0, s) + put + out.slice(e);
|
|
23406
23605
|
if (owned.length > 0 || block === "") return out;
|
|
23407
|
-
const
|
|
23408
|
-
return out +
|
|
23606
|
+
const sep5 = out === "" ? "" : out.endsWith("\n\n") ? "" : out.endsWith("\n") ? "\n" : "\n\n";
|
|
23607
|
+
return out + sep5 + block;
|
|
23409
23608
|
}
|
|
23410
23609
|
var tableLike = (v) => v === void 0 || isPlainObject3(v);
|
|
23411
23610
|
function setTomlText(text, path8, value) {
|
|
@@ -23441,33 +23640,39 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
23441
23640
|
}
|
|
23442
23641
|
}
|
|
23443
23642
|
function serverScript() {
|
|
23444
|
-
return
|
|
23643
|
+
return join10(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23445
23644
|
}
|
|
23446
23645
|
function isNodeCommand(command) {
|
|
23447
23646
|
if (typeof command !== "string") return false;
|
|
23448
23647
|
let at2 = -1;
|
|
23449
|
-
for (const
|
|
23648
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, command.lastIndexOf(sep5));
|
|
23450
23649
|
const exe = command.slice(at2 + 1).toLowerCase();
|
|
23451
23650
|
return exe === HOST_NODE_COMMAND || exe === HOST_NODE_COMMAND + EXE_SUFFIX;
|
|
23452
23651
|
}
|
|
23453
23652
|
function ownMcpValue(agent, node3, server) {
|
|
23454
23653
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23455
23654
|
if (mcp === void 0) return void 0;
|
|
23456
|
-
|
|
23457
|
-
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] };
|
|
23458
23656
|
}
|
|
23459
23657
|
function opencodePluginFile() {
|
|
23460
23658
|
return ownBundleDir();
|
|
23461
23659
|
}
|
|
23462
|
-
function listTarget(key,
|
|
23660
|
+
function listTarget(key, legacy, swap, isNative) {
|
|
23463
23661
|
return {
|
|
23464
23662
|
key: [key],
|
|
23465
23663
|
next(current) {
|
|
23466
|
-
|
|
23467
|
-
|
|
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]);
|
|
23468
23669
|
}
|
|
23469
23670
|
};
|
|
23470
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;
|
|
23471
23676
|
function ownTargets(agent, accept) {
|
|
23472
23677
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
23473
23678
|
if (mcp !== void 0) {
|
|
@@ -23480,8 +23685,18 @@ function ownTargets(agent, accept) {
|
|
|
23480
23685
|
}
|
|
23481
23686
|
}, ...(mcp.also ?? []).map(([key, value]) => ({ key, next: () => value }))];
|
|
23482
23687
|
}
|
|
23483
|
-
if (agent === "opencode")
|
|
23484
|
-
|
|
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
|
+
}
|
|
23485
23700
|
return [];
|
|
23486
23701
|
}
|
|
23487
23702
|
function applyEdits(agent, path8, text, format, wanted) {
|
|
@@ -23583,7 +23798,7 @@ function isV2McpTable(v) {
|
|
|
23583
23798
|
const first = Array.isArray(v[MCP_ARGS_FIELD]) ? v[MCP_ARGS_FIELD][0] : void 0;
|
|
23584
23799
|
if (typeof first !== "string") return false;
|
|
23585
23800
|
let at2 = -1;
|
|
23586
|
-
for (const
|
|
23801
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, first.lastIndexOf(sep5));
|
|
23587
23802
|
return first.slice(at2 + 1) === SERVER_ENTRY_FILE;
|
|
23588
23803
|
}
|
|
23589
23804
|
var listOf = (v) => Array.isArray(v) ? v : [];
|
|
@@ -23614,7 +23829,7 @@ function flatCommands(events, prefix) {
|
|
|
23614
23829
|
return out;
|
|
23615
23830
|
}
|
|
23616
23831
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23617
|
-
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));
|
|
23618
23833
|
function dataDir(dir, reason, out) {
|
|
23619
23834
|
if (existsSync5(dir)) out.push(finding(dir, "", reason));
|
|
23620
23835
|
}
|
|
@@ -23624,7 +23839,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23624
23839
|
}
|
|
23625
23840
|
}
|
|
23626
23841
|
function claudeShapeSettings(agentHome, out) {
|
|
23627
|
-
const file2 =
|
|
23842
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23628
23843
|
const doc = readJson(file2);
|
|
23629
23844
|
for (const c of nestedCommands(doc)) {
|
|
23630
23845
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23644,49 +23859,50 @@ function v1HookFile(file2, out) {
|
|
|
23644
23859
|
function scanClaudeCode(home, agentHome, out) {
|
|
23645
23860
|
claudeShapeSettings(agentHome, out);
|
|
23646
23861
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23647
|
-
const file2 =
|
|
23862
|
+
const file2 = join11(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
23648
23863
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23649
23864
|
}
|
|
23650
|
-
const userFile =
|
|
23865
|
+
const userFile = join11(home, CLAUDE_USER_CONFIG_FILE);
|
|
23651
23866
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23652
|
-
dataDir(
|
|
23867
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23653
23868
|
}
|
|
23654
23869
|
function scanCodex(agentHome, out) {
|
|
23655
|
-
const hooksFile =
|
|
23870
|
+
const hooksFile = join11(agentHome, HOOKS_JSON_FILE);
|
|
23656
23871
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23657
23872
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23658
23873
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23659
23874
|
}
|
|
23660
23875
|
}
|
|
23661
|
-
const tomlFile =
|
|
23876
|
+
const tomlFile = join11(agentHome, CONFIG_TOML_FILE);
|
|
23662
23877
|
const config4 = readTomlValue(tomlFile);
|
|
23663
23878
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23664
23879
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23665
23880
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
23666
23881
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23667
23882
|
}
|
|
23668
|
-
dataDir(
|
|
23883
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23669
23884
|
}
|
|
23670
23885
|
function scanGemini(agentHome, out) {
|
|
23671
|
-
const file2 =
|
|
23886
|
+
const file2 = join11(agentHome, SETTINGS_FILE);
|
|
23672
23887
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23673
23888
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23674
23889
|
}
|
|
23675
|
-
dataDir(
|
|
23890
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23676
23891
|
}
|
|
23677
23892
|
function scanVscode(agentHome, project, out) {
|
|
23678
23893
|
if (project !== void 0) {
|
|
23679
|
-
v1HookFile(
|
|
23680
|
-
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);
|
|
23681
23896
|
const doc = readJson(mcpFile2);
|
|
23682
23897
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23683
23898
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23684
23899
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23685
23900
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23686
23901
|
}
|
|
23687
|
-
|
|
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);
|
|
23688
23904
|
}
|
|
23689
|
-
dataDir(
|
|
23905
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23690
23906
|
}
|
|
23691
23907
|
function jsonFiles(dir) {
|
|
23692
23908
|
try {
|
|
@@ -23696,10 +23912,10 @@ function jsonFiles(dir) {
|
|
|
23696
23912
|
}
|
|
23697
23913
|
}
|
|
23698
23914
|
function scanKiro(agentHome, project, out) {
|
|
23699
|
-
const agentsDir =
|
|
23700
|
-
const defaultFile =
|
|
23915
|
+
const agentsDir = join11(agentHome, KIRO_AGENTS_DIR);
|
|
23916
|
+
const defaultFile = join11(agentHome, ...KIRO_AGENT_FILE);
|
|
23701
23917
|
for (const name of jsonFiles(agentsDir)) {
|
|
23702
|
-
const file2 =
|
|
23918
|
+
const file2 = join11(agentsDir, name);
|
|
23703
23919
|
const doc = readJson(file2);
|
|
23704
23920
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23705
23921
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23710,46 +23926,48 @@ function scanKiro(agentHome, project, out) {
|
|
|
23710
23926
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23711
23927
|
}
|
|
23712
23928
|
}
|
|
23713
|
-
const steeringDocs = [
|
|
23714
|
-
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));
|
|
23715
23931
|
for (const file2 of steeringDocs) {
|
|
23716
23932
|
if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
23717
23933
|
}
|
|
23718
|
-
dataDir(
|
|
23934
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23719
23935
|
}
|
|
23720
23936
|
function piNpmIsCurrent(piAgentDir) {
|
|
23721
|
-
const doc = readJson(
|
|
23937
|
+
const doc = readJson(join11(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23722
23938
|
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23723
23939
|
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
23724
23940
|
}
|
|
23725
23941
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23726
|
-
const file2 =
|
|
23942
|
+
const file2 = join11(piAgentDir, SETTINGS_FILE);
|
|
23727
23943
|
const doc = readJson(file2);
|
|
23728
23944
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
23729
23945
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
23730
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));
|
|
23731
23948
|
});
|
|
23732
|
-
dataDir(
|
|
23949
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23733
23950
|
}
|
|
23734
23951
|
function scanOpencode(agentHome, out) {
|
|
23735
23952
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
23736
|
-
const file2 =
|
|
23953
|
+
const file2 = join11(agentHome, name);
|
|
23737
23954
|
const doc = readJson(file2);
|
|
23738
23955
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
23739
23956
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
23740
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));
|
|
23741
23959
|
});
|
|
23742
23960
|
return;
|
|
23743
23961
|
}
|
|
23744
23962
|
}
|
|
23745
23963
|
function scanZcode(agentHome, out) {
|
|
23746
|
-
const configFile =
|
|
23964
|
+
const configFile = join11(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
23747
23965
|
const config4 = readJson(configFile);
|
|
23748
23966
|
const events = isObj(config4) && isObj(config4[HOOKS_KEY]) ? config4[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
23749
23967
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
23750
23968
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
23751
23969
|
}
|
|
23752
|
-
const hooksFile =
|
|
23970
|
+
const hooksFile = join11(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
23753
23971
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23754
23972
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
23755
23973
|
}
|
|
@@ -23773,14 +23991,14 @@ function firstTmpMatch(dir) {
|
|
|
23773
23991
|
}
|
|
23774
23992
|
}
|
|
23775
23993
|
function scanAll(home, tmp, out) {
|
|
23776
|
-
const root =
|
|
23777
|
-
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);
|
|
23778
23996
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
23779
23997
|
}
|
|
23780
23998
|
function detectV1(agent, home, scope = {}) {
|
|
23781
23999
|
const out = [];
|
|
23782
24000
|
const project = scope.project;
|
|
23783
|
-
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]);
|
|
23784
24002
|
switch (agent) {
|
|
23785
24003
|
case "claude-code":
|
|
23786
24004
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -23793,11 +24011,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23793
24011
|
break;
|
|
23794
24012
|
case "qwen":
|
|
23795
24013
|
claudeShapeSettings(agentHome, out);
|
|
23796
|
-
dataDir(
|
|
24014
|
+
dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23797
24015
|
break;
|
|
23798
24016
|
case "copilot-cli":
|
|
23799
|
-
v1HookFile(
|
|
23800
|
-
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);
|
|
23801
24019
|
break;
|
|
23802
24020
|
case "vscode":
|
|
23803
24021
|
scanVscode(agentHome, project, out);
|
|
@@ -23806,7 +24024,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23806
24024
|
scanKiro(agentHome, project, out);
|
|
23807
24025
|
break;
|
|
23808
24026
|
case "pi":
|
|
23809
|
-
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);
|
|
23810
24028
|
break;
|
|
23811
24029
|
// D-WIN-PIDIR-1: empty is unset
|
|
23812
24030
|
case "opencode":
|
|
@@ -23822,7 +24040,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23822
24040
|
|
|
23823
24041
|
// src/core/ops/plugin-root.ts
|
|
23824
24042
|
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23825
|
-
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";
|
|
23826
24044
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
23827
24045
|
function missing(agent, path8) {
|
|
23828
24046
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -23870,8 +24088,8 @@ var readOrNull = (file2) => {
|
|
|
23870
24088
|
};
|
|
23871
24089
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
23872
24090
|
function enabledPlugins(claudeDir, project) {
|
|
23873
|
-
const files = [
|
|
23874
|
-
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));
|
|
23875
24093
|
const out = {};
|
|
23876
24094
|
for (const file2 of files) {
|
|
23877
24095
|
const text = readOrNull(file2);
|
|
@@ -23887,7 +24105,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
23887
24105
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23888
24106
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
23889
24107
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
23890
|
-
const record6 = readOrNull(
|
|
24108
|
+
const record6 = readOrNull(join12(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
23891
24109
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
23892
24110
|
if (recorded.length === 0) return { record: false };
|
|
23893
24111
|
const live = recorded.filter((r) => existsSync6(r.installPath));
|
|
@@ -23910,18 +24128,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
23910
24128
|
}
|
|
23911
24129
|
function marketplaceRoot(adapter, env, worktree) {
|
|
23912
24130
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23913
|
-
const plugins =
|
|
23914
|
-
const cache =
|
|
24131
|
+
const plugins = join12(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24132
|
+
const cache = join12(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23915
24133
|
const script = process.argv[1];
|
|
23916
24134
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
23917
24135
|
const choice = marketplaceChoice(env, worktree);
|
|
23918
24136
|
if ("root" in choice) return choice.root;
|
|
23919
24137
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
23920
24138
|
const cacheReal = realOrNull(cache);
|
|
23921
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal +
|
|
23922
|
-
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);
|
|
23923
24141
|
if (!existsSync6(cache)) throw missing(adapter.id, pattern);
|
|
23924
|
-
const found = readdirSync3(cache).sort().map((marketplace) =>
|
|
24142
|
+
const found = readdirSync3(cache).sort().map((marketplace) => join12(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
|
|
23925
24143
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
23926
24144
|
return found[0];
|
|
23927
24145
|
}
|
|
@@ -23946,9 +24164,9 @@ function candidate(adapter, env, worktree) {
|
|
|
23946
24164
|
case "hooks+mcp":
|
|
23947
24165
|
return configEntryRoot(adapter, env);
|
|
23948
24166
|
case "extension":
|
|
23949
|
-
return
|
|
24167
|
+
return join12(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join12(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
23950
24168
|
case "plugin":
|
|
23951
|
-
return
|
|
24169
|
+
return join12(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
23952
24170
|
case "in-process":
|
|
23953
24171
|
return dirname7(fileURLToPath2(import.meta.url));
|
|
23954
24172
|
}
|
|
@@ -24055,7 +24273,7 @@ function composeMatcher(row5, event) {
|
|
|
24055
24273
|
}
|
|
24056
24274
|
var lastSegment = (p) => {
|
|
24057
24275
|
let at2 = -1;
|
|
24058
|
-
for (const
|
|
24276
|
+
for (const sep5 of V1_PATH_SEPS) at2 = Math.max(at2, p.lastIndexOf(sep5));
|
|
24059
24277
|
return p.slice(at2 + 1);
|
|
24060
24278
|
};
|
|
24061
24279
|
function splitHead(command) {
|
|
@@ -24077,7 +24295,7 @@ function isOwnCommand(command, agent) {
|
|
|
24077
24295
|
if (!split.rest.endsWith(tail) || split.rest.length <= tail.length) return false;
|
|
24078
24296
|
let script = split.rest.slice(0, split.rest.length - tail.length);
|
|
24079
24297
|
if (script.startsWith(SHELL_QUOTE) && script.endsWith(SHELL_QUOTE) && script.length > 1) script = script.slice(1, -1);
|
|
24080
|
-
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));
|
|
24081
24299
|
}
|
|
24082
24300
|
function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
24083
24301
|
const out = [];
|
|
@@ -24108,11 +24326,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24108
24326
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24109
24327
|
function mcpFile(row5, home, env) {
|
|
24110
24328
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24111
|
-
if (row5.id === "codex") return
|
|
24329
|
+
if (row5.id === "codex") return join13(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24112
24330
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24113
|
-
if (row5.id === "opencode") return
|
|
24331
|
+
if (row5.id === "opencode") return join13(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24114
24332
|
if (row5.id === "pi") {
|
|
24115
|
-
return
|
|
24333
|
+
return join13(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24116
24334
|
}
|
|
24117
24335
|
return null;
|
|
24118
24336
|
}
|
|
@@ -24125,27 +24343,27 @@ function codexNativeDir(env, home) {
|
|
|
24125
24343
|
const codexDir = codexDirOf(env, home);
|
|
24126
24344
|
let enabled;
|
|
24127
24345
|
try {
|
|
24128
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24346
|
+
enabled = hostConfigValueAt(readParsed("codex", join13(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24129
24347
|
} catch {
|
|
24130
24348
|
return null;
|
|
24131
24349
|
}
|
|
24132
24350
|
if (enabled !== true) return null;
|
|
24133
|
-
const cache =
|
|
24351
|
+
const cache = join13(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24134
24352
|
if (!existsSync8(cache)) return null;
|
|
24135
24353
|
const found = [];
|
|
24136
24354
|
for (const market of readdirSync4(cache)) {
|
|
24137
|
-
const plugin =
|
|
24355
|
+
const plugin = join13(cache, market, SERVER_KEY);
|
|
24138
24356
|
if (!existsSync8(plugin)) continue;
|
|
24139
24357
|
for (const version4 of readdirSync4(plugin).sort()) {
|
|
24140
|
-
const dir =
|
|
24141
|
-
if (existsSync8(
|
|
24358
|
+
const dir = join13(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
24359
|
+
if (existsSync8(join13(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24142
24360
|
}
|
|
24143
24361
|
}
|
|
24144
24362
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24145
24363
|
}
|
|
24146
24364
|
function nativeMcpWrong(dir, row5) {
|
|
24147
24365
|
try {
|
|
24148
|
-
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]);
|
|
24149
24367
|
if (!isObject4(entry)) return true;
|
|
24150
24368
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24151
24369
|
const script = args[0];
|
|
@@ -24160,10 +24378,19 @@ function isOwnOpencodeEntry(entry, key, own4) {
|
|
|
24160
24378
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own4.includes(spec)) return true;
|
|
24161
24379
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
24162
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
|
+
}
|
|
24163
24387
|
function opencodeListed(file2) {
|
|
24164
24388
|
const { value } = readParsed("opencode", file2);
|
|
24165
|
-
const
|
|
24166
|
-
|
|
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]);
|
|
24167
24394
|
}
|
|
24168
24395
|
function mcpWrong(row5, home, env, worktree) {
|
|
24169
24396
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
@@ -24184,7 +24411,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24184
24411
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24185
24412
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24186
24413
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24187
|
-
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);
|
|
24188
24415
|
return file2;
|
|
24189
24416
|
}
|
|
24190
24417
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24195,7 +24422,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24195
24422
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24196
24423
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24197
24424
|
if (row5.id === "codex") {
|
|
24198
|
-
const config4 = readParsed(row5.id,
|
|
24425
|
+
const config4 = readParsed(row5.id, join13(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24199
24426
|
if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24200
24427
|
}
|
|
24201
24428
|
} catch {
|
|
@@ -24239,7 +24466,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24239
24466
|
function checkPiInstall(env, home, worktree) {
|
|
24240
24467
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24241
24468
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24242
|
-
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]);
|
|
24243
24470
|
}
|
|
24244
24471
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24245
24472
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24258,10 +24485,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24258
24485
|
}
|
|
24259
24486
|
function checkDoubleFire(agent, worktree) {
|
|
24260
24487
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24261
|
-
const claude = parsedOrNull(agent,
|
|
24488
|
+
const claude = parsedOrNull(agent, join13(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24262
24489
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24263
24490
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24264
|
-
const vscode = parsedOrNull(agent,
|
|
24491
|
+
const vscode = parsedOrNull(agent, join13(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24265
24492
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24266
24493
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24267
24494
|
}
|
|
@@ -24272,7 +24499,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24272
24499
|
const mcp = mcpFile(row5, home, env);
|
|
24273
24500
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24274
24501
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24275
|
-
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) });
|
|
24276
24503
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24277
24504
|
if (spec !== null) {
|
|
24278
24505
|
try {
|
|
@@ -24312,7 +24539,7 @@ async function loadSqlite2() {
|
|
|
24312
24539
|
}
|
|
24313
24540
|
}
|
|
24314
24541
|
function openRead(sqlite, path8) {
|
|
24315
|
-
return
|
|
24542
|
+
return openReadOnlyHandle(sqlite, path8);
|
|
24316
24543
|
}
|
|
24317
24544
|
var cell = (row5) => Object.values(row5)[0];
|
|
24318
24545
|
function readSchema(raw) {
|
|
@@ -24386,7 +24613,7 @@ async function checkIndex(project) {
|
|
|
24386
24613
|
|
|
24387
24614
|
// src/core/ops/doctor-env.ts
|
|
24388
24615
|
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
24389
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24616
|
+
import { isAbsolute as isAbsolute3, join as join14, relative as relative4 } from "node:path";
|
|
24390
24617
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
24391
24618
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
24392
24619
|
}
|
|
@@ -24398,7 +24625,7 @@ function fail4(id, detail, fixCommand) {
|
|
|
24398
24625
|
}
|
|
24399
24626
|
function bundleVersion(bundleDir2) {
|
|
24400
24627
|
try {
|
|
24401
|
-
const v = JSON.parse(readFileSync10(
|
|
24628
|
+
const v = JSON.parse(readFileSync10(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24402
24629
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24403
24630
|
} catch {
|
|
24404
24631
|
return void 0;
|
|
@@ -24493,12 +24720,12 @@ async function checkVersion(i) {
|
|
|
24493
24720
|
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24494
24721
|
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24495
24722
|
const tag2 = channelOf(i.version);
|
|
24496
|
-
const
|
|
24723
|
+
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24497
24724
|
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24498
24725
|
if (npm.ok) return versionRow(head, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
24499
24726
|
let cause = D1_GIT_MISSING;
|
|
24500
|
-
if (
|
|
24501
|
-
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], {
|
|
24502
24729
|
cwd: i.cwd,
|
|
24503
24730
|
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
24504
24731
|
signal: i.signal,
|
|
@@ -24512,7 +24739,7 @@ async function checkVersion(i) {
|
|
|
24512
24739
|
cause = gitCause(r, i.timeoutMs);
|
|
24513
24740
|
}
|
|
24514
24741
|
}
|
|
24515
|
-
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);
|
|
24516
24743
|
}
|
|
24517
24744
|
function numbers(v) {
|
|
24518
24745
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -24549,7 +24776,7 @@ function checkMcp(ctx) {
|
|
|
24549
24776
|
}
|
|
24550
24777
|
function piCwdInside(worktree, piCwd) {
|
|
24551
24778
|
if (piCwd === void 0 || !existsSync10(piCwd)) return false;
|
|
24552
|
-
const rel =
|
|
24779
|
+
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24553
24780
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24554
24781
|
}
|
|
24555
24782
|
function checkProject(i) {
|
|
@@ -24573,6 +24800,15 @@ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11
|
|
|
24573
24800
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24574
24801
|
import path7 from "node:path";
|
|
24575
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
|
+
|
|
24576
24812
|
// src/setup/codex-trust.ts
|
|
24577
24813
|
import { createHash } from "node:crypto";
|
|
24578
24814
|
import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
|
|
@@ -24692,14 +24928,14 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
24692
24928
|
function askPluginHooks(env, pluginId, cwd) {
|
|
24693
24929
|
const bin = whichBin("codex", env);
|
|
24694
24930
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
24695
|
-
return new Promise((
|
|
24931
|
+
return new Promise((resolve9) => {
|
|
24696
24932
|
let asked;
|
|
24697
24933
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
24698
24934
|
let f;
|
|
24699
24935
|
try {
|
|
24700
24936
|
f = spawnForm(bin, ["app-server"], env);
|
|
24701
24937
|
} catch {
|
|
24702
|
-
|
|
24938
|
+
resolve9({ kind: "silent" });
|
|
24703
24939
|
return;
|
|
24704
24940
|
}
|
|
24705
24941
|
const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -24709,7 +24945,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
24709
24945
|
let result;
|
|
24710
24946
|
const settle3 = () => {
|
|
24711
24947
|
clearTimeout(grace);
|
|
24712
|
-
|
|
24948
|
+
resolve9(done_(result));
|
|
24713
24949
|
};
|
|
24714
24950
|
let grace;
|
|
24715
24951
|
const finish2 = (v) => {
|
|
@@ -24779,8 +25015,8 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
24779
25015
|
if (!bad.length) return void 0;
|
|
24780
25016
|
const counts = /* @__PURE__ */ new Map();
|
|
24781
25017
|
for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
|
|
24782
|
-
const
|
|
24783
|
-
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(", ")})`;
|
|
24784
25020
|
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
24785
25021
|
}
|
|
24786
25022
|
|
|
@@ -24861,7 +25097,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
|
24861
25097
|
}
|
|
24862
25098
|
}
|
|
24863
25099
|
var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
|
|
24864
|
-
function readProbePayload(cwd) {
|
|
25100
|
+
function readProbePayload(cwd, ranged) {
|
|
24865
25101
|
const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
|
|
24866
25102
|
const filePath = path7.join(cwd, "d5-read-probe.txt");
|
|
24867
25103
|
return {
|
|
@@ -24871,7 +25107,7 @@ function readProbePayload(cwd) {
|
|
|
24871
25107
|
hook_event_name: "PostToolUse",
|
|
24872
25108
|
tool_name: "Read",
|
|
24873
25109
|
tool_use_id: "toolu_d5_read_probe",
|
|
24874
|
-
tool_input: { file_path: filePath },
|
|
25110
|
+
tool_input: ranged ? { file_path: filePath, offset: 1, limit: READ_PROBE_LINES } : { file_path: filePath },
|
|
24875
25111
|
tool_response: { type: "text", file: { filePath, content, numLines: READ_PROBE_LINES, startLine: 1, totalLines: READ_PROBE_LINES } }
|
|
24876
25112
|
};
|
|
24877
25113
|
}
|
|
@@ -24889,21 +25125,37 @@ function isReadShape(stdout) {
|
|
|
24889
25125
|
const f = r.file;
|
|
24890
25126
|
return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
|
|
24891
25127
|
}
|
|
24892
|
-
async function
|
|
25128
|
+
async function readProbe(i, timeoutMs, ranged) {
|
|
24893
25129
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
24894
25130
|
try {
|
|
24895
|
-
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], {
|
|
24896
25133
|
cwd: i.bundleDir,
|
|
24897
|
-
env:
|
|
25134
|
+
env: node3.env,
|
|
24898
25135
|
signal: i.signal,
|
|
24899
25136
|
timeoutMs,
|
|
24900
|
-
stdin: JSON.stringify(readProbePayload(i.worktree ?? home))
|
|
25137
|
+
stdin: JSON.stringify(readProbePayload(i.worktree ?? home, ranged))
|
|
24901
25138
|
});
|
|
24902
|
-
return
|
|
25139
|
+
return r.stdout.toString("utf8");
|
|
24903
25140
|
} finally {
|
|
24904
25141
|
rmSync2(home, { recursive: true, force: true });
|
|
24905
25142
|
}
|
|
24906
25143
|
}
|
|
25144
|
+
function isPassThrough(stdout) {
|
|
25145
|
+
if (stdout.trim() === "") return true;
|
|
25146
|
+
let out;
|
|
25147
|
+
try {
|
|
25148
|
+
out = JSON.parse(stdout);
|
|
25149
|
+
} catch {
|
|
25150
|
+
return false;
|
|
25151
|
+
}
|
|
25152
|
+
return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
|
|
25153
|
+
}
|
|
25154
|
+
async function readProbeDetail(i, timeoutMs) {
|
|
25155
|
+
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
25156
|
+
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
25157
|
+
return null;
|
|
25158
|
+
}
|
|
24907
25159
|
function codexHookJournaled(db) {
|
|
24908
25160
|
if (db === null) return false;
|
|
24909
25161
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -24949,7 +25201,8 @@ async function checkHookRoundTrip(i) {
|
|
|
24949
25201
|
const timeoutMs = i.timeoutMs ?? HOOK_TIMEOUT_MS;
|
|
24950
25202
|
const bareMs = i.bareMs ?? (async () => {
|
|
24951
25203
|
const t = performance.now();
|
|
24952
|
-
|
|
25204
|
+
const node3 = nodeLaunch(i.env);
|
|
25205
|
+
await runProcess([node3.file, "-e", ""], { cwd: i.bundleDir, env: node3.env, signal: i.signal, timeoutMs });
|
|
24953
25206
|
return performance.now() - t;
|
|
24954
25207
|
});
|
|
24955
25208
|
const hookWalls = [];
|
|
@@ -24957,9 +25210,10 @@ async function checkHookRoundTrip(i) {
|
|
|
24957
25210
|
let ms = 0;
|
|
24958
25211
|
for (let n = 1; n <= maxPairs; n++) {
|
|
24959
25212
|
const start = now();
|
|
24960
|
-
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], {
|
|
24961
25215
|
cwd: i.bundleDir,
|
|
24962
|
-
env:
|
|
25216
|
+
env: node3.env,
|
|
24963
25217
|
signal: i.signal,
|
|
24964
25218
|
timeoutMs,
|
|
24965
25219
|
stdin: JSON.stringify(payloadFor(i.agent, fixture.payload, i.worktree))
|
|
@@ -24971,22 +25225,23 @@ async function checkHookRoundTrip(i) {
|
|
|
24971
25225
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
24972
25226
|
}
|
|
24973
25227
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
24974
|
-
|
|
25228
|
+
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
|
|
25229
|
+
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
24975
25230
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
24976
25231
|
}
|
|
24977
25232
|
|
|
24978
25233
|
// src/core/ops/db-heal.ts
|
|
24979
25234
|
import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
|
|
24980
|
-
import { basename as basename4, dirname as dirname8, join as
|
|
25235
|
+
import { basename as basename4, dirname as dirname8, join as join16 } from "node:path";
|
|
24981
25236
|
|
|
24982
25237
|
// src/core/store/owners.ts
|
|
24983
25238
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24984
|
-
import { basename as basename3, join as
|
|
25239
|
+
import { basename as basename3, join as join15 } from "node:path";
|
|
24985
25240
|
function ownersDir(configDir, projectKey) {
|
|
24986
|
-
return
|
|
25241
|
+
return join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24987
25242
|
}
|
|
24988
25243
|
function ownerFile(configDir, projectKey, serverId) {
|
|
24989
|
-
return
|
|
25244
|
+
return join15(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
|
|
24990
25245
|
}
|
|
24991
25246
|
function errCode2(err) {
|
|
24992
25247
|
return err.code;
|
|
@@ -25021,7 +25276,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
25021
25276
|
const live = [];
|
|
25022
25277
|
for (const name of names) {
|
|
25023
25278
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25024
|
-
const file2 =
|
|
25279
|
+
const file2 = join15(dir, name);
|
|
25025
25280
|
let text;
|
|
25026
25281
|
try {
|
|
25027
25282
|
text = readFileSync12(file2, "utf8");
|
|
@@ -25045,7 +25300,7 @@ async function healLossless(dbPath) {
|
|
|
25045
25300
|
const tmp = dbPath + HEAL_TMP_SUFFIX;
|
|
25046
25301
|
rmSync4(tmp, { force: true });
|
|
25047
25302
|
try {
|
|
25048
|
-
const src =
|
|
25303
|
+
const src = openReadOnlyHandle({ DatabaseSync }, dbPath, { queryOnly: false });
|
|
25049
25304
|
try {
|
|
25050
25305
|
src.prepare("VACUUM INTO ?").run(tmp);
|
|
25051
25306
|
} finally {
|
|
@@ -25093,7 +25348,7 @@ function utcStamp(now) {
|
|
|
25093
25348
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
25094
25349
|
}
|
|
25095
25350
|
function makeOrphanDir(projectDir) {
|
|
25096
|
-
const base =
|
|
25351
|
+
const base = join16(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
25097
25352
|
for (let n = 1; ; n += 1) {
|
|
25098
25353
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
25099
25354
|
try {
|
|
@@ -25110,7 +25365,7 @@ async function healOrphan(project, files, row5) {
|
|
|
25110
25365
|
try {
|
|
25111
25366
|
dir = makeOrphanDir(dirname8(project.dbPath));
|
|
25112
25367
|
for (const f of files) {
|
|
25113
|
-
const to =
|
|
25368
|
+
const to = join16(dir, basename4(f.path));
|
|
25114
25369
|
renameWithRetry(f.path, to);
|
|
25115
25370
|
moved.push({ path: to, bytes: f.bytes });
|
|
25116
25371
|
}
|
|
@@ -25178,7 +25433,7 @@ function buildReportHead(input) {
|
|
|
25178
25433
|
// src/core/ops/doctor-issue.ts
|
|
25179
25434
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
25180
25435
|
import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync13, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
25181
|
-
import { delimiter, join as
|
|
25436
|
+
import { delimiter, join as join17 } from "node:path";
|
|
25182
25437
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
25183
25438
|
function tildeOf(env) {
|
|
25184
25439
|
const home = homeDirOf(env);
|
|
@@ -25219,8 +25474,8 @@ function onPath(env, tool) {
|
|
|
25219
25474
|
const out = [];
|
|
25220
25475
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
25221
25476
|
if (dir === "") continue;
|
|
25222
|
-
for (const n of names) if (existsSync14(
|
|
25223
|
-
out.push(
|
|
25477
|
+
for (const n of names) if (existsSync14(join17(dir, n))) {
|
|
25478
|
+
out.push(join17(dir, n));
|
|
25224
25479
|
break;
|
|
25225
25480
|
}
|
|
25226
25481
|
}
|
|
@@ -25266,8 +25521,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
25266
25521
|
const home = homeDirOf(env);
|
|
25267
25522
|
const files = configPaths(adapter, env, worktree);
|
|
25268
25523
|
if (home !== null) {
|
|
25269
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
25270
|
-
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) });
|
|
25271
25526
|
}
|
|
25272
25527
|
const out = [];
|
|
25273
25528
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -25350,9 +25605,9 @@ async function buildIssueBody(i) {
|
|
|
25350
25605
|
async function writeIssueReport(i) {
|
|
25351
25606
|
const tilde = tildeOf(i.env);
|
|
25352
25607
|
const body = await buildIssueBody(i);
|
|
25353
|
-
const dir =
|
|
25608
|
+
const dir = join17(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
25354
25609
|
mkdirSync6(dir, { recursive: true });
|
|
25355
|
-
const file2 =
|
|
25610
|
+
const file2 = join17(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
25356
25611
|
writeFileSync3(file2, body);
|
|
25357
25612
|
const shown2 = tilde(file2);
|
|
25358
25613
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -25409,11 +25664,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
25409
25664
|
}
|
|
25410
25665
|
}
|
|
25411
25666
|
function ownServerId(configDir, projectKey) {
|
|
25412
|
-
const dir =
|
|
25667
|
+
const dir = join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
25413
25668
|
if (!existsSync15(dir)) return "";
|
|
25414
25669
|
for (const name of readdirSync6(dir)) {
|
|
25415
25670
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
25416
|
-
if (readFileSync14(
|
|
25671
|
+
if (readFileSync14(join18(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
25417
25672
|
}
|
|
25418
25673
|
return "";
|
|
25419
25674
|
}
|
|
@@ -25427,7 +25682,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
25427
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 }),
|
|
25428
25683
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
25429
25684
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
25430
|
-
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)) }),
|
|
25431
25686
|
D5: () => hookRow(ctx, adapter, host),
|
|
25432
25687
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
25433
25688
|
D6: () => checkMcp(ctx),
|
|
@@ -25468,13 +25723,13 @@ function reportEnv(env) {
|
|
|
25468
25723
|
async function doctorReply(ctx, host) {
|
|
25469
25724
|
const adapter = getAdapter(ctx.project.agent);
|
|
25470
25725
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
25471
|
-
const
|
|
25472
|
-
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}`;
|
|
25473
25728
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
25474
25729
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
25475
25730
|
const table3 = buildReport(input);
|
|
25476
25731
|
let notes = [];
|
|
25477
|
-
if (
|
|
25732
|
+
if (failed) {
|
|
25478
25733
|
try {
|
|
25479
25734
|
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
25480
25735
|
} catch (err) {
|
|
@@ -25510,7 +25765,7 @@ var ctxDoctor = Object.freeze({
|
|
|
25510
25765
|
// src/core/tools/execute.ts
|
|
25511
25766
|
import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
25512
25767
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
25513
|
-
import { dirname as dirname10, join as
|
|
25768
|
+
import { dirname as dirname10, join as join19, parse as parse3, resolve as resolve7 } from "node:path";
|
|
25514
25769
|
|
|
25515
25770
|
// src/core/sandbox/win-build.ts
|
|
25516
25771
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -25556,7 +25811,6 @@ var ctxExecuteSchema = external_exports.object({
|
|
|
25556
25811
|
background: external_exports.boolean().optional(),
|
|
25557
25812
|
summary: external_exports.boolean().optional()
|
|
25558
25813
|
}, { error: unknownField }).strict();
|
|
25559
|
-
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
25560
25814
|
var SCRIPT_EXT = Object.freeze({
|
|
25561
25815
|
javascript: ".js",
|
|
25562
25816
|
typescript: ".ts",
|
|
@@ -25575,7 +25829,7 @@ var LAUNCHER = [
|
|
|
25575
25829
|
'const { rmSync } = require("node:fs");',
|
|
25576
25830
|
"const [mode, dir, ...argv] = process.argv.slice(1);",
|
|
25577
25831
|
'if (mode === "start") {',
|
|
25578
|
-
' 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 });',
|
|
25579
25833
|
" b.unref();",
|
|
25580
25834
|
" process.stdout.write(String(b.pid));",
|
|
25581
25835
|
"} else {",
|
|
@@ -25658,7 +25912,7 @@ async function handler3(raw, ctx) {
|
|
|
25658
25912
|
const cwd = ctx.project.worktree;
|
|
25659
25913
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
25660
25914
|
if (input.file !== void 0) {
|
|
25661
|
-
const abs =
|
|
25915
|
+
const abs = resolve7(cwd, input.file);
|
|
25662
25916
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
25663
25917
|
if (bad !== null) return fail5(bad);
|
|
25664
25918
|
extra.CTX_FILE = abs;
|
|
@@ -25675,13 +25929,14 @@ async function handler3(raw, ctx) {
|
|
|
25675
25929
|
if (takesDashC(input.language, runtime)) {
|
|
25676
25930
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
25677
25931
|
} else {
|
|
25678
|
-
tmpDir = mkdtempSync2(
|
|
25679
|
-
const file2 =
|
|
25932
|
+
tmpDir = mkdtempSync2(join19(tmpdir3(), TMP_PREFIX));
|
|
25933
|
+
const file2 = join19(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25680
25934
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
25681
25935
|
argv = scriptArgv(input.language, runtime, file2);
|
|
25682
25936
|
}
|
|
25683
25937
|
if (input.background === true) {
|
|
25684
|
-
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 });
|
|
25685
25940
|
const pid = r2.stdout.toString("utf8");
|
|
25686
25941
|
if (r2.exitCode !== 0 || pid === "" || !Number.isSafeInteger(Number(pid))) return fail5(spawnFailed(argv[0], cwd), journal);
|
|
25687
25942
|
handedOff = true;
|
|
@@ -25712,11 +25967,11 @@ var ctxExecute = {
|
|
|
25712
25967
|
|
|
25713
25968
|
// src/core/tools/index.ts
|
|
25714
25969
|
import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
|
|
25715
|
-
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";
|
|
25716
25971
|
|
|
25717
25972
|
// src/core/index/walk.ts
|
|
25718
25973
|
import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
25719
|
-
import { join as
|
|
25974
|
+
import { join as join20 } from "node:path";
|
|
25720
25975
|
var GITIGNORE = ".gitignore";
|
|
25721
25976
|
var GIT_DIR = ".git";
|
|
25722
25977
|
function walkDir(root, containmentRoot) {
|
|
@@ -25725,7 +25980,7 @@ function walkDir(root, containmentRoot) {
|
|
|
25725
25980
|
const found = [];
|
|
25726
25981
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
25727
25982
|
found.sort(compareFound);
|
|
25728
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25983
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join20(...f.dir, f.name) }));
|
|
25729
25984
|
}
|
|
25730
25985
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
25731
25986
|
let entries;
|
|
@@ -25734,10 +25989,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
25734
25989
|
} catch {
|
|
25735
25990
|
return;
|
|
25736
25991
|
}
|
|
25737
|
-
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;
|
|
25738
25993
|
for (const e of entries) {
|
|
25739
25994
|
if (e.name === GIT_DIR) continue;
|
|
25740
|
-
const path8 =
|
|
25995
|
+
const path8 = join20(abs, e.name);
|
|
25741
25996
|
let isDir = e.isDirectory();
|
|
25742
25997
|
let isFile = e.isFile();
|
|
25743
25998
|
let target = path8;
|
|
@@ -25871,11 +26126,24 @@ var PRIVATE_RANGES = [
|
|
|
25871
26126
|
["172.16.0.0", 12, "ipv4"],
|
|
25872
26127
|
["192.168.0.0", 16, "ipv4"],
|
|
25873
26128
|
["169.254.0.0", 16, "ipv4"],
|
|
25874
|
-
["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
|
|
25875
26137
|
["::1", 128, "ipv6"],
|
|
25876
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)
|
|
25877
26143
|
["fc00::", 7, "ipv6"],
|
|
25878
|
-
["fe80::", 10, "ipv6"]
|
|
26144
|
+
["fe80::", 10, "ipv6"],
|
|
26145
|
+
["fec0::", 10, "ipv6"]
|
|
26146
|
+
// D-SSRF-RANGES-1: site-local (RFC 3879)
|
|
25879
26147
|
];
|
|
25880
26148
|
var BLOCKED = new BlockList();
|
|
25881
26149
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
@@ -25928,9 +26196,41 @@ function pickProxy(u) {
|
|
|
25928
26196
|
const auth = p.username === "" ? void 0 : "Basic " + Buffer.from(decodeURIComponent(p.username) + ":" + decodeURIComponent(p.password)).toString("base64");
|
|
25929
26197
|
return { url: p, auth };
|
|
25930
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
|
+
}
|
|
25931
26230
|
function checkAddress(hostname2, address) {
|
|
25932
26231
|
const family = isIP(address);
|
|
25933
|
-
|
|
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")) {
|
|
25934
26234
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
25935
26235
|
}
|
|
25936
26236
|
}
|
|
@@ -25954,18 +26254,18 @@ function request(u, conn, proxy, signal) {
|
|
|
25954
26254
|
const host = bare(u.hostname);
|
|
25955
26255
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
25956
26256
|
const path8 = u.pathname + u.search;
|
|
25957
|
-
return new Promise((
|
|
26257
|
+
return new Promise((resolve9, reject) => {
|
|
25958
26258
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
25959
26259
|
if (proxy === void 0) {
|
|
25960
26260
|
const mod = u.protocol === "https:" ? https : http;
|
|
25961
26261
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
25962
|
-
req.on("response",
|
|
26262
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25963
26263
|
return;
|
|
25964
26264
|
}
|
|
25965
26265
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
25966
26266
|
if (u.protocol === "http:") {
|
|
25967
26267
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
25968
|
-
req.on("response",
|
|
26268
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25969
26269
|
return;
|
|
25970
26270
|
}
|
|
25971
26271
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -25985,16 +26285,16 @@ function request(u, conn, proxy, signal) {
|
|
|
25985
26285
|
headers: { host: u.host },
|
|
25986
26286
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
25987
26287
|
});
|
|
25988
|
-
req.on("response",
|
|
26288
|
+
req.on("response", resolve9).on("error", onErr).end();
|
|
25989
26289
|
});
|
|
25990
26290
|
tunnel.end();
|
|
25991
26291
|
});
|
|
25992
26292
|
}
|
|
25993
26293
|
function readBody(res) {
|
|
25994
|
-
return new Promise((
|
|
26294
|
+
return new Promise((resolve9, reject) => {
|
|
25995
26295
|
const parts = [];
|
|
25996
26296
|
res.on("data", (b) => parts.push(b));
|
|
25997
|
-
res.on("end", () =>
|
|
26297
|
+
res.on("end", () => resolve9(Buffer.concat(parts)));
|
|
25998
26298
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
25999
26299
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
26000
26300
|
});
|
|
@@ -28665,7 +28965,7 @@ var DomHandler = class {
|
|
|
28665
28965
|
var dist_exports2 = {};
|
|
28666
28966
|
__export(dist_exports2, {
|
|
28667
28967
|
DocumentPosition: () => DocumentPosition,
|
|
28668
|
-
append: () =>
|
|
28968
|
+
append: () => append2,
|
|
28669
28969
|
appendChild: () => appendChild,
|
|
28670
28970
|
compareDocumentPosition: () => compareDocumentPosition,
|
|
28671
28971
|
existsOne: () => existsOne,
|
|
@@ -29256,11 +29556,11 @@ function compareDocumentPosition(nodeA, nodeB) {
|
|
|
29256
29556
|
function uniqueSort(nodes) {
|
|
29257
29557
|
nodes = nodes.filter((node3, index, array4) => !array4.includes(node3, index + 1));
|
|
29258
29558
|
nodes.sort((a, b) => {
|
|
29259
|
-
const
|
|
29260
|
-
if (
|
|
29559
|
+
const relative6 = compareDocumentPosition(a, b);
|
|
29560
|
+
if (relative6 & DocumentPosition.PRECEDING) {
|
|
29261
29561
|
return -1;
|
|
29262
29562
|
}
|
|
29263
|
-
if (
|
|
29563
|
+
if (relative6 & DocumentPosition.FOLLOWING) {
|
|
29264
29564
|
return 1;
|
|
29265
29565
|
}
|
|
29266
29566
|
return 0;
|
|
@@ -29317,7 +29617,7 @@ function appendChild(parent, child) {
|
|
|
29317
29617
|
child.prev = null;
|
|
29318
29618
|
}
|
|
29319
29619
|
}
|
|
29320
|
-
function
|
|
29620
|
+
function append2(element2, next) {
|
|
29321
29621
|
removeElement(next);
|
|
29322
29622
|
const { parent } = element2;
|
|
29323
29623
|
const currentNext = element2.next;
|
|
@@ -29829,10 +30129,10 @@ function htmlToReadable(html, baseUrl) {
|
|
|
29829
30129
|
const st = { w: new Writer(), base, sawH1: false };
|
|
29830
30130
|
for (const n of contentRoot(doc.children)) walk2(st, n);
|
|
29831
30131
|
const body = st.w.result();
|
|
29832
|
-
const
|
|
29833
|
-
const text = !st.sawH1 && title !== "" &&
|
|
29834
|
-
const sparse =
|
|
29835
|
-
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 };
|
|
29836
30136
|
}
|
|
29837
30137
|
|
|
29838
30138
|
// src/core/tools/index.ts
|
|
@@ -29872,13 +30172,13 @@ function missingOrOutside(given, abs, root) {
|
|
|
29872
30172
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
29873
30173
|
}
|
|
29874
30174
|
function pathItems(input, project) {
|
|
29875
|
-
const abs =
|
|
30175
|
+
const abs = resolve8(project.worktree, input.path);
|
|
29876
30176
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
29877
|
-
const base =
|
|
30177
|
+
const base = relative5(project.worktree, abs);
|
|
29878
30178
|
if (statSync8(abs).isDirectory()) {
|
|
29879
30179
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
29880
30180
|
sourceKind: "path",
|
|
29881
|
-
label: pathLabel(
|
|
30181
|
+
label: pathLabel(join21(base, f.relPath)),
|
|
29882
30182
|
kind: kindOfPath(f.relPath),
|
|
29883
30183
|
read: () => readUtf8(f.absPath)
|
|
29884
30184
|
}));
|
|
@@ -30417,13 +30717,9 @@ var ctxStats = Object.freeze({
|
|
|
30417
30717
|
handler: handler7
|
|
30418
30718
|
});
|
|
30419
30719
|
|
|
30420
|
-
// src/core/tools/upgrade.ts
|
|
30421
|
-
import { existsSync as existsSync23, realpathSync as realpathSync11, rmSync as rmSync10 } from "node:fs";
|
|
30422
|
-
import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
|
|
30423
|
-
|
|
30424
30720
|
// src/core/ops/host-write.ts
|
|
30425
30721
|
import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30426
|
-
import { dirname as dirname12, join as
|
|
30722
|
+
import { dirname as dirname12, join as join22 } from "node:path";
|
|
30427
30723
|
function defaultWrite(file2, text) {
|
|
30428
30724
|
writeFileSync5(file2, text, "utf8");
|
|
30429
30725
|
}
|
|
@@ -30432,14 +30728,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
30432
30728
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
30433
30729
|
switch (agent) {
|
|
30434
30730
|
case "opencode":
|
|
30435
|
-
return
|
|
30731
|
+
return join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
30436
30732
|
// D-WIN-OPENCODE-DIR-1
|
|
30437
30733
|
case "pi":
|
|
30438
|
-
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
|
|
30439
30738
|
case "copilot-cli":
|
|
30440
30739
|
return null;
|
|
30441
30740
|
default:
|
|
30442
|
-
return
|
|
30741
|
+
return join22(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
30443
30742
|
}
|
|
30444
30743
|
}
|
|
30445
30744
|
function cell3(value) {
|
|
@@ -30488,96 +30787,16 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
30488
30787
|
return result.edits.map((e) => toRow(current.path, e));
|
|
30489
30788
|
}
|
|
30490
30789
|
|
|
30491
|
-
// src/core/ops/plugin-swap.ts
|
|
30492
|
-
import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
30493
|
-
import { basename as basename6, join as join22, win32 as win322 } from "node:path";
|
|
30494
|
-
function linkTarget(path8, win) {
|
|
30495
|
-
if (!isLink(path8)) return null;
|
|
30496
|
-
const target = readlinkSync(path8);
|
|
30497
|
-
return win ? win322.basename(target) : target;
|
|
30498
|
-
}
|
|
30499
|
-
function isLink(path8) {
|
|
30500
|
-
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
30501
|
-
}
|
|
30502
|
-
function generations(agentDir) {
|
|
30503
|
-
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();
|
|
30504
|
-
}
|
|
30505
|
-
function settleLinks(link, tmp, old, opts) {
|
|
30506
|
-
if (isLink(tmp)) unlinkSync2(tmp);
|
|
30507
|
-
if (!isLink(old)) return;
|
|
30508
|
-
if (isLink(link)) unlinkSync2(old);
|
|
30509
|
-
else renameWithRetry(old, link, opts);
|
|
30510
|
-
}
|
|
30511
|
-
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
30512
|
-
const next = join22(agentDir, sha);
|
|
30513
|
-
if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
|
|
30514
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
30515
|
-
}
|
|
30516
|
-
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
30517
|
-
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
30518
|
-
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
30519
|
-
settleLinks(link, tmp, old, opts);
|
|
30520
|
-
const win = (opts.platform ?? process.platform) === "win32";
|
|
30521
|
-
const before = linkTarget(link, win);
|
|
30522
|
-
if (before === sha) return { current: next, previous: null, removed: [] };
|
|
30523
|
-
const symlink = opts.symlink ?? symlinkSync;
|
|
30524
|
-
if (win) symlink(next, tmp, PLUGIN_LINK_TYPE_WIN32);
|
|
30525
|
-
else symlink(sha, tmp, PLUGIN_LINK_TYPE);
|
|
30526
|
-
if (before !== null) renameWithRetry(link, old, opts);
|
|
30527
|
-
renameWithRetry(tmp, link, opts);
|
|
30528
|
-
if (before !== null) unlinkSync2(old);
|
|
30529
|
-
const keep = /* @__PURE__ */ new Set([sha]);
|
|
30530
|
-
if (before !== null) keep.add(before);
|
|
30531
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
|
|
30532
|
-
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
30533
|
-
const previous = before !== null && existsSync19(join22(agentDir, before)) ? join22(agentDir, before) : null;
|
|
30534
|
-
return { current: next, previous, removed };
|
|
30535
|
-
}
|
|
30536
|
-
|
|
30537
|
-
// src/core/ops/release-fetch.ts
|
|
30538
|
-
import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
|
|
30539
|
-
import { join as join23 } from "node:path";
|
|
30540
|
-
function failed(r) {
|
|
30541
|
-
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30542
|
-
const status = r.killed ?? String(r.exitCode);
|
|
30543
|
-
return new CtxError("FETCH_FAILED", { code: GIT_EXIT_LABEL + status + UPGRADE_AREA_KEY_SEP + r.stderr.toString().trim() });
|
|
30544
|
-
}
|
|
30545
|
-
async function git2(bin, args, cwd, env, signal) {
|
|
30546
|
-
const r = await runProcess([bin, ...args], { cwd, env, signal, timeoutMs: UPGRADE_GIT_TIMEOUT_MS });
|
|
30547
|
-
if (r.exitCode !== 0 || r.killed !== null) throw failed(r);
|
|
30548
|
-
return r.stdout.toString().trim();
|
|
30549
|
-
}
|
|
30550
|
-
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
30551
|
-
const agentDir = join23(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
30552
|
-
mkdirSync8(agentDir, { recursive: true });
|
|
30553
|
-
const fetchDir = join23(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
30554
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30555
|
-
const gitBin = findRuntime(GIT_BIN, env);
|
|
30556
|
-
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
30557
|
-
const childEnv = buildChildEnv(env, { ...GIT_NO_PROMPT_ENV, ...GIT_NO_CRLF_ENV });
|
|
30558
|
-
try {
|
|
30559
|
-
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
30560
|
-
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
30561
|
-
const dir = join23(agentDir, sha);
|
|
30562
|
-
if (existsSync20(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
30563
|
-
else renameWithRetry(fetchDir, dir, opts);
|
|
30564
|
-
return { sha, dir };
|
|
30565
|
-
} catch (e) {
|
|
30566
|
-
rmSync7(fetchDir, { recursive: true, force: true });
|
|
30567
|
-
throw e;
|
|
30568
|
-
}
|
|
30569
|
-
}
|
|
30570
|
-
|
|
30571
30790
|
// src/core/ops/uninstall.ts
|
|
30572
|
-
import { existsSync as
|
|
30573
|
-
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";
|
|
30574
30793
|
function row2(area, before, after) {
|
|
30575
30794
|
return { area, before, after };
|
|
30576
30795
|
}
|
|
30577
30796
|
function stopServers(configDir, projectKey) {
|
|
30578
30797
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
30579
|
-
const dir =
|
|
30580
|
-
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");
|
|
30581
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 };
|
|
30582
30801
|
}
|
|
30583
30802
|
function rootOrNull(adapter, env) {
|
|
@@ -30595,16 +30814,16 @@ function removeCache(adapter, env, configDir) {
|
|
|
30595
30814
|
const root = rootOrNull(adapter, env);
|
|
30596
30815
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
30597
30816
|
if (adapter.installMode === "marketplace") {
|
|
30598
|
-
const cache =
|
|
30817
|
+
const cache = join23(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
30599
30818
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
30600
30819
|
}
|
|
30601
|
-
|
|
30820
|
+
rmSync6(root, { recursive: true, force: true });
|
|
30602
30821
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
30603
30822
|
}
|
|
30604
30823
|
case "plugin": {
|
|
30605
|
-
const agentDir =
|
|
30606
|
-
if (!
|
|
30607
|
-
|
|
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 });
|
|
30608
30827
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
30609
30828
|
}
|
|
30610
30829
|
case "config-mcp":
|
|
@@ -30619,7 +30838,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
30619
30838
|
function isObj3(v) {
|
|
30620
30839
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30621
30840
|
}
|
|
30622
|
-
function
|
|
30841
|
+
function piSource2(entry) {
|
|
30623
30842
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
30624
30843
|
}
|
|
30625
30844
|
function ownEntries2(agent, env) {
|
|
@@ -30648,7 +30867,7 @@ function ownEntries2(agent, env) {
|
|
|
30648
30867
|
}
|
|
30649
30868
|
if (agent === "opencode") {
|
|
30650
30869
|
return [{
|
|
30651
|
-
file:
|
|
30870
|
+
file: join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
30652
30871
|
// D-WIN-OPENCODE-DIR-1
|
|
30653
30872
|
key: OPENCODE_PLUGIN_KEY,
|
|
30654
30873
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -30659,11 +30878,11 @@ function ownEntries2(agent, env) {
|
|
|
30659
30878
|
if (agent === "pi") {
|
|
30660
30879
|
const agentDir = piAgentDirOf(env, home);
|
|
30661
30880
|
return [{
|
|
30662
|
-
file:
|
|
30881
|
+
file: join23(agentDir, SETTINGS_FILE),
|
|
30663
30882
|
key: PI_PACKAGES_KEY,
|
|
30664
30883
|
shown: PI_PACKAGES_KEY,
|
|
30665
|
-
has: (v) => Array.isArray(v) && v.some((x) =>
|
|
30666
|
-
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)
|
|
30667
30886
|
}];
|
|
30668
30887
|
}
|
|
30669
30888
|
return [];
|
|
@@ -30681,12 +30900,12 @@ function removeOwnEntries(agent, env) {
|
|
|
30681
30900
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
30682
30901
|
}
|
|
30683
30902
|
function removeProjectData(configDir, projectKey) {
|
|
30684
|
-
const projects =
|
|
30685
|
-
const dir =
|
|
30686
|
-
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);
|
|
30687
30906
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
30688
|
-
for (const name of
|
|
30689
|
-
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 });
|
|
30690
30909
|
}
|
|
30691
30910
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
30692
30911
|
}
|
|
@@ -30694,25 +30913,32 @@ function runUninstall(input) {
|
|
|
30694
30913
|
const configDir = resolveConfigDir(input.env);
|
|
30695
30914
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
30696
30915
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
30697
|
-
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));
|
|
30698
30917
|
return { rows, stopped: stop.stopped };
|
|
30699
30918
|
}
|
|
30700
30919
|
|
|
30701
30920
|
// src/core/ops/v1-remove.ts
|
|
30702
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30921
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync17, rmSync as rmSync7 } from "node:fs";
|
|
30703
30922
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30704
30923
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
30705
30924
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
30706
30925
|
function moveAside(target, undo) {
|
|
30707
30926
|
const trash = target + UPGRADE_TRASH_SUFFIX;
|
|
30708
|
-
|
|
30927
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30709
30928
|
renameWithRetry(target, trash);
|
|
30710
30929
|
undo.push({ trash, target });
|
|
30711
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
|
+
}
|
|
30712
30938
|
function keepOriginal(file2, kept, undo) {
|
|
30713
30939
|
if (kept.has(file2)) return;
|
|
30714
30940
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
30715
|
-
|
|
30941
|
+
rmSync7(trash, { recursive: true, force: true });
|
|
30716
30942
|
copyFileSync2(file2, trash);
|
|
30717
30943
|
kept.add(file2);
|
|
30718
30944
|
undo.push({ trash, target: file2 });
|
|
@@ -30772,7 +30998,7 @@ function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
|
30772
30998
|
writeHostConfigEdit(file2, { agent, text, format: "jsonc", path: file2, layout }, patch);
|
|
30773
30999
|
return hit;
|
|
30774
31000
|
}
|
|
30775
|
-
function removeV1(agent, findings) {
|
|
31001
|
+
function removeV1(agent, findings, project) {
|
|
30776
31002
|
const undo = [];
|
|
30777
31003
|
const kept = /* @__PURE__ */ new Set();
|
|
30778
31004
|
const done = /* @__PURE__ */ new Map();
|
|
@@ -30780,14 +31006,16 @@ function removeV1(agent, findings) {
|
|
|
30780
31006
|
for (const f of findings) {
|
|
30781
31007
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
30782
31008
|
else if (f.path === "") {
|
|
30783
|
-
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)) {
|
|
30784
31012
|
moveAside(f.file, undo);
|
|
30785
31013
|
done.set(f, UPGRADE_REMOVED);
|
|
30786
31014
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
30787
31015
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
30788
31016
|
}
|
|
30789
31017
|
for (const [file2, list4] of entries) {
|
|
30790
|
-
if (!
|
|
31018
|
+
if (!existsSync20(file2)) {
|
|
30791
31019
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
30792
31020
|
continue;
|
|
30793
31021
|
}
|
|
@@ -30816,64 +31044,18 @@ function removeV1(agent, findings) {
|
|
|
30816
31044
|
return {
|
|
30817
31045
|
rows: findings.map((f) => row3(f, done.get(f) ?? UPGRADE_NOT_FOUND)),
|
|
30818
31046
|
commit() {
|
|
30819
|
-
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 });
|
|
30820
31048
|
},
|
|
30821
31049
|
rollback() {
|
|
30822
31050
|
for (const u of undo.splice(0).reverse()) {
|
|
30823
|
-
if (!
|
|
30824
|
-
|
|
31051
|
+
if (!existsSync20(u.trash)) continue;
|
|
31052
|
+
rmSync7(u.target, { recursive: true, force: true });
|
|
30825
31053
|
renameWithRetry(u.trash, u.target);
|
|
30826
31054
|
}
|
|
30827
31055
|
}
|
|
30828
31056
|
};
|
|
30829
31057
|
}
|
|
30830
31058
|
|
|
30831
|
-
// src/core/ops/verify-sums.ts
|
|
30832
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
30833
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync18 } from "node:fs";
|
|
30834
|
-
import { join as join25 } from "node:path";
|
|
30835
|
-
function mismatch() {
|
|
30836
|
-
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
30837
|
-
}
|
|
30838
|
-
function parseSums(text) {
|
|
30839
|
-
const lines = text.split(SUMS_LINE_END);
|
|
30840
|
-
if (lines[lines.length - 1] === "") lines.pop();
|
|
30841
|
-
const sums = /* @__PURE__ */ new Map();
|
|
30842
|
-
for (const line of lines) {
|
|
30843
|
-
const at2 = line.indexOf(SUMS_LINE_SEP);
|
|
30844
|
-
if (at2 < 0) throw mismatch();
|
|
30845
|
-
const rel = line.slice(at2 + SUMS_LINE_SEP.length);
|
|
30846
|
-
if (rel === "" || sums.has(rel)) throw mismatch();
|
|
30847
|
-
sums.set(rel, line.slice(0, at2));
|
|
30848
|
-
}
|
|
30849
|
-
return sums;
|
|
30850
|
-
}
|
|
30851
|
-
function walk3(dir, prefix, out) {
|
|
30852
|
-
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
30853
|
-
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
30854
|
-
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
30855
|
-
const abs = join25(dir, entry.name);
|
|
30856
|
-
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
30857
|
-
else if (entry.isFile()) out.set(rel, abs);
|
|
30858
|
-
else throw mismatch();
|
|
30859
|
-
}
|
|
30860
|
-
}
|
|
30861
|
-
function verifySums(dir) {
|
|
30862
|
-
const sumsPath = join25(dir, RELEASE_SUMS_FILE);
|
|
30863
|
-
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
30864
|
-
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
30865
|
-
const sums = parseSums(readFileSync18(sumsPath, "utf8"));
|
|
30866
|
-
const files = /* @__PURE__ */ new Map();
|
|
30867
|
-
walk3(dir, "", files);
|
|
30868
|
-
if (files.size !== sums.size) throw mismatch();
|
|
30869
|
-
for (const [rel, abs] of files) {
|
|
30870
|
-
const want = sums.get(rel);
|
|
30871
|
-
if (want === void 0) throw mismatch();
|
|
30872
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync18(abs)).digest(HASH_ENCODING);
|
|
30873
|
-
if (got !== want) throw mismatch();
|
|
30874
|
-
}
|
|
30875
|
-
}
|
|
30876
|
-
|
|
30877
31059
|
// src/core/tools/upgrade.ts
|
|
30878
31060
|
var ctxUpgradeSchema = external_exports.object({
|
|
30879
31061
|
mode: external_exports.enum(UPGRADE_MODES).optional(),
|
|
@@ -30896,41 +31078,20 @@ function pluginRootRow(adapter, env) {
|
|
|
30896
31078
|
}
|
|
30897
31079
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
30898
31080
|
}
|
|
30899
|
-
function isCurrent(agentDir, dir) {
|
|
30900
|
-
const link = join26(agentDir, PLUGIN_CURRENT_LINK);
|
|
30901
|
-
return existsSync23(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
30902
|
-
}
|
|
30903
|
-
async function checkout(adapter, deps) {
|
|
30904
|
-
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
30905
|
-
const agentDir = dirname13(fetched.dir);
|
|
30906
|
-
try {
|
|
30907
|
-
verifySums(fetched.dir);
|
|
30908
|
-
} catch (err) {
|
|
30909
|
-
if (!isCurrent(agentDir, fetched.dir)) rmSync10(fetched.dir, { recursive: true, force: true });
|
|
30910
|
-
throw err;
|
|
30911
|
-
}
|
|
30912
|
-
const swap = swapPluginCurrent(agentDir, fetched.sha);
|
|
30913
|
-
const rows = [row4(UPGRADE_CHECKOUT_AREA, swap.previous ?? "", swap.current)];
|
|
30914
|
-
for (const dir of swap.removed) rows.push(row4(UPGRADE_CACHE_AREA, dir, UPGRADE_REMOVED));
|
|
30915
|
-
return { rows, agentDir, swap };
|
|
30916
|
-
}
|
|
30917
31081
|
function hostRow(adapter) {
|
|
30918
|
-
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]
|
|
31082
|
+
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]);
|
|
30919
31083
|
}
|
|
30920
|
-
|
|
30921
|
-
let done = null;
|
|
31084
|
+
function upgrade(adapter, deps, home) {
|
|
30922
31085
|
let removal = null;
|
|
30923
31086
|
try {
|
|
30924
|
-
const step4 = UPGRADE_GIT_CHECKOUT_AGENTS.includes(adapter.id) ? (done = await checkout(adapter, deps)).rows : [hostRow(adapter)];
|
|
30925
31087
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
30926
|
-
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) });
|
|
30927
|
-
removal = removeV1(adapter.id, findings);
|
|
30928
|
-
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];
|
|
30929
31091
|
removal.commit();
|
|
30930
31092
|
return rows;
|
|
30931
31093
|
} catch (err) {
|
|
30932
31094
|
removal?.rollback();
|
|
30933
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename7(done.swap.previous));
|
|
30934
31095
|
throw err;
|
|
30935
31096
|
}
|
|
30936
31097
|
}
|
|
@@ -30950,12 +31111,12 @@ async function runUpgrade(input, deps) {
|
|
|
30950
31111
|
const result = runUninstall({ adapter, project: deps.project, env: deps.env, confirmDelete: input.confirmDelete === true });
|
|
30951
31112
|
rows.push(...result.rows);
|
|
30952
31113
|
} else {
|
|
30953
|
-
rows.push(...
|
|
31114
|
+
rows.push(...upgrade(adapter, deps, home));
|
|
30954
31115
|
}
|
|
30955
31116
|
return { text: renderTable(rows) + "\n\n" + UPGRADE_RESTART_LINE, isError: false, sandboxBytes: 0 };
|
|
30956
31117
|
}
|
|
30957
31118
|
async function handler8(input, ctx) {
|
|
30958
|
-
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 });
|
|
30959
31120
|
}
|
|
30960
31121
|
var ctxUpgrade = Object.freeze({
|
|
30961
31122
|
name: "ctx_upgrade",
|
|
@@ -31018,8 +31179,8 @@ function checkCall(tool, input) {
|
|
|
31018
31179
|
|
|
31019
31180
|
// src/entries/server.ts
|
|
31020
31181
|
import { randomUUID } from "node:crypto";
|
|
31021
|
-
import { existsSync as
|
|
31022
|
-
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";
|
|
31023
31184
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
31024
31185
|
|
|
31025
31186
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -34498,7 +34659,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
34498
34659
|
var NONE3 = 0;
|
|
34499
34660
|
var ASSUMED = 1;
|
|
34500
34661
|
var PROVEN = 2;
|
|
34501
|
-
function isRecursive(inst, stack2,
|
|
34662
|
+
function isRecursive(inst, stack2, resolve9) {
|
|
34502
34663
|
const cached4 = recursive.get(inst);
|
|
34503
34664
|
if (cached4 !== void 0)
|
|
34504
34665
|
return cached4 ? PROVEN : NONE3;
|
|
@@ -34508,7 +34669,7 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34508
34669
|
let result = NONE3;
|
|
34509
34670
|
const check2 = (child) => {
|
|
34510
34671
|
if (result !== PROVEN && child?._zod) {
|
|
34511
|
-
const answer3 = isRecursive(child, stack2,
|
|
34672
|
+
const answer3 = isRecursive(child, stack2, resolve9);
|
|
34512
34673
|
if (answer3 > result)
|
|
34513
34674
|
result = answer3;
|
|
34514
34675
|
}
|
|
@@ -34519,7 +34680,7 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34519
34680
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
34520
34681
|
if (spread && !desc.enumerable)
|
|
34521
34682
|
continue;
|
|
34522
|
-
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;
|
|
34523
34684
|
if (child > answer3)
|
|
34524
34685
|
answer3 = child;
|
|
34525
34686
|
}
|
|
@@ -34583,7 +34744,7 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34583
34744
|
break;
|
|
34584
34745
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
34585
34746
|
case "lazy": {
|
|
34586
|
-
const inner = def._cachedInner ?? (
|
|
34747
|
+
const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
|
|
34587
34748
|
merge5(inner ? isRecursive(inner, stack2, false) : ASSUMED);
|
|
34588
34749
|
break;
|
|
34589
34750
|
}
|
|
@@ -42027,7 +42188,7 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
|
|
|
42027
42188
|
var NONE4 = 0;
|
|
42028
42189
|
var ASSUMED2 = 1;
|
|
42029
42190
|
var PROVEN2 = 2;
|
|
42030
|
-
function isRecursive2(inst, stack2,
|
|
42191
|
+
function isRecursive2(inst, stack2, resolve9) {
|
|
42031
42192
|
const cached4 = recursive2.get(inst);
|
|
42032
42193
|
if (cached4 !== void 0)
|
|
42033
42194
|
return cached4 ? PROVEN2 : NONE4;
|
|
@@ -42037,7 +42198,7 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
42037
42198
|
let result = NONE4;
|
|
42038
42199
|
const check2 = (child) => {
|
|
42039
42200
|
if (result !== PROVEN2 && child?._zod) {
|
|
42040
|
-
const answer3 = isRecursive2(child, stack2,
|
|
42201
|
+
const answer3 = isRecursive2(child, stack2, resolve9);
|
|
42041
42202
|
if (answer3 > result)
|
|
42042
42203
|
result = answer3;
|
|
42043
42204
|
}
|
|
@@ -42048,7 +42209,7 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
42048
42209
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
42049
42210
|
if (spread && !desc.enumerable)
|
|
42050
42211
|
continue;
|
|
42051
|
-
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;
|
|
42052
42213
|
if (child > answer3)
|
|
42053
42214
|
answer3 = child;
|
|
42054
42215
|
}
|
|
@@ -42112,7 +42273,7 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
42112
42273
|
break;
|
|
42113
42274
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
42114
42275
|
case "lazy": {
|
|
42115
|
-
const inner = def._cachedInner ?? (
|
|
42276
|
+
const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
|
|
42116
42277
|
merge5(inner ? isRecursive2(inner, stack2, false) : ASSUMED2);
|
|
42117
42278
|
break;
|
|
42118
42279
|
}
|
|
@@ -48716,14 +48877,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
|
|
|
48716
48877
|
return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
|
|
48717
48878
|
}
|
|
48718
48879
|
function sleep(ms, signal) {
|
|
48719
|
-
return new Promise((
|
|
48880
|
+
return new Promise((resolve9, reject) => {
|
|
48720
48881
|
if (signal?.aborted) {
|
|
48721
48882
|
reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
|
|
48722
48883
|
return;
|
|
48723
48884
|
}
|
|
48724
48885
|
const timer = setTimeout(() => {
|
|
48725
48886
|
signal?.removeEventListener("abort", onAbort);
|
|
48726
|
-
|
|
48887
|
+
resolve9();
|
|
48727
48888
|
}, ms);
|
|
48728
48889
|
const onAbort = () => {
|
|
48729
48890
|
clearTimeout(timer);
|
|
@@ -49522,7 +49683,7 @@ var Protocol = class {
|
|
|
49522
49683
|
const flowStartedAt = Date.now();
|
|
49523
49684
|
let onAbort;
|
|
49524
49685
|
let cleanupMessageId;
|
|
49525
|
-
return new Promise((
|
|
49686
|
+
return new Promise((resolve9, reject) => {
|
|
49526
49687
|
const earlyReject = (error42) => {
|
|
49527
49688
|
reject(error42);
|
|
49528
49689
|
};
|
|
@@ -49591,7 +49752,7 @@ var Protocol = class {
|
|
|
49591
49752
|
}
|
|
49592
49753
|
if (decoded.kind === "invalid") return reject(decoded.error);
|
|
49593
49754
|
if (decoded.kind === "input_required") {
|
|
49594
|
-
if (options?.allowInputRequired === true) return
|
|
49755
|
+
if (options?.allowInputRequired === true) return resolve9(manualInputRequiredValue(decoded));
|
|
49595
49756
|
const flow = {
|
|
49596
49757
|
codec,
|
|
49597
49758
|
request: request2,
|
|
@@ -49603,11 +49764,11 @@ var Protocol = class {
|
|
|
49603
49764
|
params
|
|
49604
49765
|
}, resultSchema, legOptions)
|
|
49605
49766
|
};
|
|
49606
|
-
return
|
|
49767
|
+
return resolve9(this._resolveNonCompleteResult(decoded, flow));
|
|
49607
49768
|
}
|
|
49608
49769
|
const result = decoded.result;
|
|
49609
49770
|
validateStandardSchema(resultSchema, result).then((parseResult) => {
|
|
49610
|
-
if (parseResult.success)
|
|
49771
|
+
if (parseResult.success) resolve9(parseResult.data);
|
|
49611
49772
|
else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request2.method}: ${parseResult.error}`));
|
|
49612
49773
|
}, reject);
|
|
49613
49774
|
});
|
|
@@ -52247,17 +52408,17 @@ var require_validate = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
52247
52408
|
const { schemaCode } = this;
|
|
52248
52409
|
this.fail((0, codegen_1._)`${schemaCode} !== undefined && (${(0, codegen_1.or)(this.invalid$data(), condition)})`);
|
|
52249
52410
|
}
|
|
52250
|
-
error(
|
|
52411
|
+
error(append3, errorParams, errorPaths) {
|
|
52251
52412
|
if (errorParams) {
|
|
52252
52413
|
this.setParams(errorParams);
|
|
52253
|
-
this._error(
|
|
52414
|
+
this._error(append3, errorPaths);
|
|
52254
52415
|
this.setParams({});
|
|
52255
52416
|
return;
|
|
52256
52417
|
}
|
|
52257
|
-
this._error(
|
|
52418
|
+
this._error(append3, errorPaths);
|
|
52258
52419
|
}
|
|
52259
|
-
_error(
|
|
52260
|
-
(
|
|
52420
|
+
_error(append3, errorPaths) {
|
|
52421
|
+
(append3 ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
52261
52422
|
}
|
|
52262
52423
|
$dataError() {
|
|
52263
52424
|
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
@@ -52523,7 +52684,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
52523
52684
|
ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
|
|
52524
52685
|
const schOrFunc = root.refs[ref];
|
|
52525
52686
|
if (schOrFunc) return schOrFunc;
|
|
52526
|
-
let _sch =
|
|
52687
|
+
let _sch = resolve9.call(this, root, ref);
|
|
52527
52688
|
if (_sch === void 0) {
|
|
52528
52689
|
const schema = (_a5 = root.localRefs) === null || _a5 === void 0 ? void 0 : _a5[ref];
|
|
52529
52690
|
const { schemaId } = this.opts;
|
|
@@ -52549,7 +52710,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
52549
52710
|
function sameSchemaEnv(s1, s2) {
|
|
52550
52711
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
52551
52712
|
}
|
|
52552
|
-
function
|
|
52713
|
+
function resolve9(root, ref) {
|
|
52553
52714
|
let sch;
|
|
52554
52715
|
while (typeof (sch = this.refs[ref]) == "string") ref = sch;
|
|
52555
52716
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
@@ -52999,47 +53160,47 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
52999
53160
|
else if (typeof uri === "object") uri = parse6(serialize(uri, options), options);
|
|
53000
53161
|
return uri;
|
|
53001
53162
|
}
|
|
53002
|
-
function
|
|
53163
|
+
function resolve9(baseURI, relativeURI, options) {
|
|
53003
53164
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
53004
53165
|
const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
53005
53166
|
schemelessOptions.skipEscape = true;
|
|
53006
53167
|
return serialize(resolved, schemelessOptions);
|
|
53007
53168
|
}
|
|
53008
|
-
function resolveComponent(base,
|
|
53169
|
+
function resolveComponent(base, relative6, options, skipNormalization) {
|
|
53009
53170
|
const target = {};
|
|
53010
53171
|
if (!skipNormalization) {
|
|
53011
53172
|
base = parse6(serialize(base, options), options);
|
|
53012
|
-
|
|
53173
|
+
relative6 = parse6(serialize(relative6, options), options);
|
|
53013
53174
|
}
|
|
53014
53175
|
options = options || {};
|
|
53015
|
-
if (!options.tolerant &&
|
|
53016
|
-
target.scheme =
|
|
53017
|
-
target.userinfo =
|
|
53018
|
-
target.host =
|
|
53019
|
-
target.port =
|
|
53020
|
-
target.path = removeDotSegments(
|
|
53021
|
-
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;
|
|
53022
53183
|
} else {
|
|
53023
|
-
if (
|
|
53024
|
-
target.userinfo =
|
|
53025
|
-
target.host =
|
|
53026
|
-
target.port =
|
|
53027
|
-
target.path = removeDotSegments(
|
|
53028
|
-
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;
|
|
53029
53190
|
} else {
|
|
53030
|
-
if (!
|
|
53191
|
+
if (!relative6.path) {
|
|
53031
53192
|
target.path = base.path;
|
|
53032
|
-
if (
|
|
53193
|
+
if (relative6.query !== void 0) target.query = relative6.query;
|
|
53033
53194
|
else target.query = base.query;
|
|
53034
53195
|
} else {
|
|
53035
|
-
if (
|
|
53196
|
+
if (relative6.path[0] === "/") target.path = removeDotSegments(relative6.path);
|
|
53036
53197
|
else {
|
|
53037
|
-
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" +
|
|
53038
|
-
else if (!base.path) target.path =
|
|
53039
|
-
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;
|
|
53040
53201
|
target.path = removeDotSegments(target.path);
|
|
53041
53202
|
}
|
|
53042
|
-
target.query =
|
|
53203
|
+
target.query = relative6.query;
|
|
53043
53204
|
}
|
|
53044
53205
|
target.userinfo = base.userinfo;
|
|
53045
53206
|
target.host = base.host;
|
|
@@ -53047,7 +53208,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
53047
53208
|
}
|
|
53048
53209
|
target.scheme = base.scheme;
|
|
53049
53210
|
}
|
|
53050
|
-
target.fragment =
|
|
53211
|
+
target.fragment = relative6.fragment;
|
|
53051
53212
|
return target;
|
|
53052
53213
|
}
|
|
53053
53214
|
function equal(uriA, uriB, options) {
|
|
@@ -53173,7 +53334,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
53173
53334
|
const fastUri = {
|
|
53174
53335
|
SCHEMES,
|
|
53175
53336
|
normalize: normalize2,
|
|
53176
|
-
resolve:
|
|
53337
|
+
resolve: resolve9,
|
|
53177
53338
|
resolveComponent,
|
|
53178
53339
|
equal,
|
|
53179
53340
|
serialize,
|
|
@@ -58638,7 +58799,7 @@ var StdioServerTransport = class {
|
|
|
58638
58799
|
}
|
|
58639
58800
|
send(message3) {
|
|
58640
58801
|
if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
|
|
58641
|
-
return new Promise((
|
|
58802
|
+
return new Promise((resolve9, reject) => {
|
|
58642
58803
|
const json2 = serializeMessage(message3);
|
|
58643
58804
|
let settled = false;
|
|
58644
58805
|
const onError = (error42) => {
|
|
@@ -58653,14 +58814,14 @@ var StdioServerTransport = class {
|
|
|
58653
58814
|
settled = true;
|
|
58654
58815
|
this._stdout.off("error", onError);
|
|
58655
58816
|
this._stdout.off("drain", onDrain);
|
|
58656
|
-
|
|
58817
|
+
resolve9();
|
|
58657
58818
|
};
|
|
58658
58819
|
this._stdout.once("error", onError);
|
|
58659
58820
|
if (this._stdout.write(json2)) {
|
|
58660
58821
|
if (settled) return;
|
|
58661
58822
|
settled = true;
|
|
58662
58823
|
this._stdout.off("error", onError);
|
|
58663
|
-
|
|
58824
|
+
resolve9();
|
|
58664
58825
|
} else if (!settled) this._stdout.once("drain", onDrain);
|
|
58665
58826
|
});
|
|
58666
58827
|
}
|
|
@@ -58714,14 +58875,14 @@ var StdioConnectionChannel = class {
|
|
|
58714
58875
|
*/
|
|
58715
58876
|
async whenRequestsAnswered(timeoutMs) {
|
|
58716
58877
|
if (this._closed || this._pendingRequests.size === 0) return true;
|
|
58717
|
-
return await new Promise((
|
|
58878
|
+
return await new Promise((resolve9) => {
|
|
58718
58879
|
const waiter = () => {
|
|
58719
58880
|
clearTimeout(timer);
|
|
58720
|
-
|
|
58881
|
+
resolve9(true);
|
|
58721
58882
|
};
|
|
58722
58883
|
const timer = setTimeout(() => {
|
|
58723
58884
|
this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
|
|
58724
|
-
|
|
58885
|
+
resolve9(false);
|
|
58725
58886
|
}, timeoutMs);
|
|
58726
58887
|
this._drainWaiters.push(waiter);
|
|
58727
58888
|
});
|
|
@@ -59084,8 +59245,8 @@ function installExitGuard(opts) {
|
|
|
59084
59245
|
}
|
|
59085
59246
|
|
|
59086
59247
|
// src/core/store/cleanup.ts
|
|
59087
|
-
import { existsSync as
|
|
59088
|
-
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";
|
|
59089
59250
|
function deleteSource(raw, id) {
|
|
59090
59251
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
59091
59252
|
deleteChunkRows(raw, { sourceId: id });
|
|
@@ -59120,7 +59281,7 @@ function userVersion(raw) {
|
|
|
59120
59281
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
59121
59282
|
}
|
|
59122
59283
|
function openForSweep(dbPath, projectKey) {
|
|
59123
|
-
if (!
|
|
59284
|
+
if (!existsSync21(dbPath) && (existsSync21(dbPath + DB_WAL_SUFFIX) || existsSync21(dbPath + DB_SHM_SUFFIX))) {
|
|
59124
59285
|
throw new CtxError("DB_GONE");
|
|
59125
59286
|
}
|
|
59126
59287
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -59141,21 +59302,21 @@ function lastAccess(raw) {
|
|
|
59141
59302
|
return row5.t;
|
|
59142
59303
|
}
|
|
59143
59304
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
59144
|
-
const dir =
|
|
59145
|
-
const db = openForSweep(
|
|
59305
|
+
const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
59306
|
+
const db = openForSweep(join24(dir, DB_FILE_NAME), projectKey);
|
|
59146
59307
|
let dead;
|
|
59147
59308
|
try {
|
|
59148
59309
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
59149
59310
|
} finally {
|
|
59150
59311
|
closeDb(db);
|
|
59151
59312
|
}
|
|
59152
|
-
if (dead)
|
|
59313
|
+
if (dead) rmSync8(dir, { recursive: true, force: true });
|
|
59153
59314
|
return dead;
|
|
59154
59315
|
}
|
|
59155
59316
|
function sweepDeadProjects(configDir) {
|
|
59156
59317
|
let entries;
|
|
59157
59318
|
try {
|
|
59158
|
-
entries =
|
|
59319
|
+
entries = readdirSync9(join24(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
59159
59320
|
} catch (err) {
|
|
59160
59321
|
if (err.code === "ENOENT") return [];
|
|
59161
59322
|
throw err;
|
|
@@ -59174,12 +59335,12 @@ function sweepDeadProjects(configDir) {
|
|
|
59174
59335
|
}
|
|
59175
59336
|
|
|
59176
59337
|
// src/entries/is-entry.ts
|
|
59177
|
-
import { realpathSync as
|
|
59338
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
59178
59339
|
function isEntry(main, argv1, self) {
|
|
59179
59340
|
if (main !== void 0) return main;
|
|
59180
59341
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
59181
59342
|
try {
|
|
59182
|
-
return
|
|
59343
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
59183
59344
|
} catch {
|
|
59184
59345
|
return false;
|
|
59185
59346
|
}
|
|
@@ -59255,16 +59416,33 @@ function workspaceFromMeta(meta3) {
|
|
|
59255
59416
|
}
|
|
59256
59417
|
function realOrSame(p) {
|
|
59257
59418
|
try {
|
|
59258
|
-
return
|
|
59419
|
+
return realpathSync12.native(p);
|
|
59259
59420
|
} catch {
|
|
59260
59421
|
return p;
|
|
59261
59422
|
}
|
|
59262
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
|
+
}
|
|
59263
59441
|
function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
59264
59442
|
const fromHost = workspaceFromMeta(meta3);
|
|
59265
59443
|
if (fromHost !== void 0) return fromHost;
|
|
59266
59444
|
if (script === void 0 || script === "") return spawnCwd;
|
|
59267
|
-
return realOrSame(spawnCwd) === realOrSame(
|
|
59445
|
+
return realOrSame(spawnCwd) === realOrSame(dirname13(script)) ? "" : spawnCwd;
|
|
59268
59446
|
}
|
|
59269
59447
|
function errorReply(err) {
|
|
59270
59448
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
@@ -59303,15 +59481,15 @@ async function startServer(argv, env) {
|
|
|
59303
59481
|
opening.catch(() => pending.delete(project.dbPath));
|
|
59304
59482
|
}
|
|
59305
59483
|
const db = await opening;
|
|
59306
|
-
if (!
|
|
59484
|
+
if (!existsSync22(db.path)) throw new CtxError("DB_GONE");
|
|
59307
59485
|
return db;
|
|
59308
59486
|
}
|
|
59309
59487
|
function stopMarker(configDir, projectKey) {
|
|
59310
|
-
return
|
|
59488
|
+
return join25(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
59311
59489
|
}
|
|
59312
59490
|
function stopRequested() {
|
|
59313
59491
|
const configDir = resolveConfigDir(process.env);
|
|
59314
|
-
return held.some((db) =>
|
|
59492
|
+
return held.some((db) => existsSync22(stopMarker(configDir, db.projectKey)));
|
|
59315
59493
|
}
|
|
59316
59494
|
async function journal(project, ctx, name, reply4) {
|
|
59317
59495
|
const db = await ownDb(project);
|
|
@@ -59321,10 +59499,12 @@ async function startServer(argv, env) {
|
|
|
59321
59499
|
return async (input, req) => {
|
|
59322
59500
|
const meta3 = req.mcpReq._meta;
|
|
59323
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];
|
|
59324
59504
|
let project;
|
|
59325
59505
|
const projectOf = () => {
|
|
59326
59506
|
if (agent === void 0) throw new CtxError("NO_PROJECT", { kind: "--agent" });
|
|
59327
|
-
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 });
|
|
59328
59508
|
return project;
|
|
59329
59509
|
};
|
|
59330
59510
|
const ctx = {
|
|
@@ -59404,7 +59584,7 @@ async function startServer(argv, env) {
|
|
|
59404
59584
|
try {
|
|
59405
59585
|
const configDir = resolveConfigDir(process.env);
|
|
59406
59586
|
removeOwnerPid(configDir, db.projectKey, serverId);
|
|
59407
|
-
|
|
59587
|
+
rmSync9(stopMarker(configDir, db.projectKey), { force: true });
|
|
59408
59588
|
} catch (err) {
|
|
59409
59589
|
console.error(err);
|
|
59410
59590
|
}
|
|
@@ -59418,7 +59598,7 @@ async function startServer(argv, env) {
|
|
|
59418
59598
|
}
|
|
59419
59599
|
installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
|
|
59420
59600
|
handle = serveStdio(createServer);
|
|
59421
|
-
await new Promise((
|
|
59601
|
+
await new Promise((resolve9) => process.once("exit", () => resolve9()));
|
|
59422
59602
|
}
|
|
59423
59603
|
if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) {
|
|
59424
59604
|
const [, , ...cliArgs] = process.argv;
|