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/server.mjs
CHANGED
|
@@ -7,8 +7,8 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { dirname as
|
|
10
|
+
import { existsSync as existsSync22, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
|
|
11
|
+
import { dirname as dirname12, join as join22 } from "node:path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
13
13
|
|
|
14
14
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -21994,41 +21994,41 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
21994
21994
|
schemelessOptions.skipEscape = true;
|
|
21995
21995
|
return serialize(resolved, schemelessOptions);
|
|
21996
21996
|
}
|
|
21997
|
-
function resolveComponent(base,
|
|
21997
|
+
function resolveComponent(base, relative4, options, skipNormalization) {
|
|
21998
21998
|
const target = {};
|
|
21999
21999
|
if (!skipNormalization) {
|
|
22000
22000
|
base = parse6(serialize(base, options), options);
|
|
22001
|
-
|
|
22001
|
+
relative4 = parse6(serialize(relative4, options), options);
|
|
22002
22002
|
}
|
|
22003
22003
|
options = options || {};
|
|
22004
|
-
if (!options.tolerant &&
|
|
22005
|
-
target.scheme =
|
|
22006
|
-
target.userinfo =
|
|
22007
|
-
target.host =
|
|
22008
|
-
target.port =
|
|
22009
|
-
target.path = removeDotSegments(
|
|
22010
|
-
target.query =
|
|
22004
|
+
if (!options.tolerant && relative4.scheme) {
|
|
22005
|
+
target.scheme = relative4.scheme;
|
|
22006
|
+
target.userinfo = relative4.userinfo;
|
|
22007
|
+
target.host = relative4.host;
|
|
22008
|
+
target.port = relative4.port;
|
|
22009
|
+
target.path = removeDotSegments(relative4.path || "");
|
|
22010
|
+
target.query = relative4.query;
|
|
22011
22011
|
} else {
|
|
22012
|
-
if (
|
|
22013
|
-
target.userinfo =
|
|
22014
|
-
target.host =
|
|
22015
|
-
target.port =
|
|
22016
|
-
target.path = removeDotSegments(
|
|
22017
|
-
target.query =
|
|
22012
|
+
if (relative4.userinfo !== void 0 || relative4.host !== void 0 || relative4.port !== void 0) {
|
|
22013
|
+
target.userinfo = relative4.userinfo;
|
|
22014
|
+
target.host = relative4.host;
|
|
22015
|
+
target.port = relative4.port;
|
|
22016
|
+
target.path = removeDotSegments(relative4.path || "");
|
|
22017
|
+
target.query = relative4.query;
|
|
22018
22018
|
} else {
|
|
22019
|
-
if (!
|
|
22019
|
+
if (!relative4.path) {
|
|
22020
22020
|
target.path = base.path;
|
|
22021
|
-
if (
|
|
22021
|
+
if (relative4.query !== void 0) target.query = relative4.query;
|
|
22022
22022
|
else target.query = base.query;
|
|
22023
22023
|
} else {
|
|
22024
|
-
if (
|
|
22024
|
+
if (relative4.path[0] === "/") target.path = removeDotSegments(relative4.path);
|
|
22025
22025
|
else {
|
|
22026
|
-
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" +
|
|
22027
|
-
else if (!base.path) target.path =
|
|
22028
|
-
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
22026
|
+
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) target.path = "/" + relative4.path;
|
|
22027
|
+
else if (!base.path) target.path = relative4.path;
|
|
22028
|
+
else target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative4.path;
|
|
22029
22029
|
target.path = removeDotSegments(target.path);
|
|
22030
22030
|
}
|
|
22031
|
-
target.query =
|
|
22031
|
+
target.query = relative4.query;
|
|
22032
22032
|
}
|
|
22033
22033
|
target.userinfo = base.userinfo;
|
|
22034
22034
|
target.host = base.host;
|
|
@@ -22036,7 +22036,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
22036
22036
|
}
|
|
22037
22037
|
target.scheme = base.scheme;
|
|
22038
22038
|
}
|
|
22039
|
-
target.fragment =
|
|
22039
|
+
target.fragment = relative4.fragment;
|
|
22040
22040
|
return target;
|
|
22041
22041
|
}
|
|
22042
22042
|
function equal(uriA, uriB, options) {
|
|
@@ -28066,6 +28066,8 @@ var POINTER_MIN = 640;
|
|
|
28066
28066
|
var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
28067
28067
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
28068
28068
|
var REPLACE_TRIGGER_BYTES = 4096;
|
|
28069
|
+
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
28070
|
+
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
28069
28071
|
var MAX_CHUNK_BYTES = 4096;
|
|
28070
28072
|
var SEARCH_PAGE_SIZE = 20;
|
|
28071
28073
|
var MEMORY_LABEL_PREFIX = "memory ";
|
|
@@ -28242,6 +28244,7 @@ var GIT_COMMONDIR_FILE = "commondir";
|
|
|
28242
28244
|
var GIT_HEAD_FILE = "HEAD";
|
|
28243
28245
|
var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
|
|
28244
28246
|
var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
|
|
28247
|
+
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
28245
28248
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
28246
28249
|
var FETCH_MAX_HOPS = 5;
|
|
28247
28250
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
@@ -28253,6 +28256,7 @@ var RUN_SESSION_PREFIX = "mcp:";
|
|
|
28253
28256
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
28254
28257
|
var NODE_MIN = "24.15.0";
|
|
28255
28258
|
var DATA_ROOT = "~/.context-mode";
|
|
28259
|
+
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
28256
28260
|
var INTERNAL_ERROR_LINE = "Internal error. Fix: run ctx_doctor.";
|
|
28257
28261
|
var HOST_CONFIG_DIR_NAME = ".claude";
|
|
28258
28262
|
var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
@@ -28321,7 +28325,7 @@ var SHELL_DUMP_COMMANDS = Object.freeze(["cat", "head", "tail", "sed", "less", "
|
|
|
28321
28325
|
var DUMP_COUNT_COMMANDS = Object.freeze(["head", "tail"]);
|
|
28322
28326
|
var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
28323
28327
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
28324
|
-
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path"]);
|
|
28328
|
+
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
|
|
28325
28329
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
28326
28330
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
28327
28331
|
var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
|
|
@@ -28406,8 +28410,7 @@ function PURGE_SUMMARY(rows, scope) {
|
|
|
28406
28410
|
var DECISION_SOURCE = "decision";
|
|
28407
28411
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28408
28412
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28409
|
-
var
|
|
28410
|
-
var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
|
|
28413
|
+
var BUNDLE_SHA = true ? "b496e208f503714cb28500a0b5767799ba882039" : void 0;
|
|
28411
28414
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28412
28415
|
var DOCTOR_LABEL = Object.freeze({
|
|
28413
28416
|
D1: "version",
|
|
@@ -28551,7 +28554,6 @@ function D9_INDEX_DETAIL(sources, chunks) {
|
|
|
28551
28554
|
var PLUGIN_CACHE_DIR_NAME = "cache";
|
|
28552
28555
|
var DATA_PLUGINS_DIR_NAME = "plugins";
|
|
28553
28556
|
var PLUGIN_CURRENT_LINK = "current";
|
|
28554
|
-
var RELEASE_SUMS_FILE = "SHA256SUMS";
|
|
28555
28557
|
var EXTENSIONS_DIR_NAME = "extensions";
|
|
28556
28558
|
var AGENT_HOME_DIR = Object.freeze({
|
|
28557
28559
|
"claude-code": [".claude"],
|
|
@@ -28574,7 +28576,6 @@ var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
|
28574
28576
|
var UPGRADE_TABLE_HEADER = "| Area | Before | After |";
|
|
28575
28577
|
var UPGRADE_TABLE_RULE = "|---|---|---|";
|
|
28576
28578
|
var UPGRADE_PLUGIN_ROOT_AREA = "plugin root";
|
|
28577
|
-
var UPGRADE_CHECKOUT_AREA = "plugin checkout";
|
|
28578
28579
|
var UPGRADE_SERVER_AREA = "server";
|
|
28579
28580
|
var UPGRADE_SERVER_RUNNING = "running";
|
|
28580
28581
|
var UPGRADE_SERVER_STOPPED = "stopped after this reply";
|
|
@@ -28585,25 +28586,20 @@ var UPGRADE_REPORT_ONLY = "report only: remove it by hand if you no longer use i
|
|
|
28585
28586
|
var UPGRADE_STOP_DELAY_MS = 200;
|
|
28586
28587
|
var UPGRADE_AREA_KEY_SEP = ": ";
|
|
28587
28588
|
var V1_KEY_PATH_SEP = ".";
|
|
28588
|
-
var UPGRADE_GIT_TIMEOUT_MS = 12e4;
|
|
28589
28589
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
28590
28590
|
var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
|
|
28591
|
-
var UPGRADE_FETCH_DIR_PREFIX = ".fetch-";
|
|
28592
|
-
var SUMS_LINE_SEP = " ";
|
|
28593
|
-
var SUMS_HASH_ALGORITHM = "sha256";
|
|
28594
|
-
var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
|
|
28595
|
-
var UPGRADE_HOST_MANUAL = "update with the host's own install command, then restart";
|
|
28596
28591
|
var UPGRADE_CONFIG_AREA = "host config";
|
|
28597
28592
|
var UPGRADE_OWN_ENTRY = "context-mode entry";
|
|
28598
28593
|
var UPGRADE_CACHE_BY_HAND = "remove the release dir by hand: its place is your choice";
|
|
28599
28594
|
var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
|
|
28600
28595
|
var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
|
|
28601
|
-
var GIT_NOT_STARTED = "git did not start";
|
|
28602
28596
|
var GIT_BIN = "git";
|
|
28603
28597
|
var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
|
|
28604
28598
|
var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
|
|
28605
|
-
var GIT_EXIT_LABEL = "git exit ";
|
|
28606
28599
|
var UPGRADE_TRASH_SUFFIX = ".ctx-upgrade-removing";
|
|
28600
|
+
var UPGRADE_ASIDE_SUFFIX = ".ctx-v1-old";
|
|
28601
|
+
var UPGRADE_MOVED_ASIDE = "moved aside to ";
|
|
28602
|
+
var PERSISTED_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
|
|
28607
28603
|
var TABLE_ROW_START = "| ";
|
|
28608
28604
|
var TABLE_CELL_SEP = " | ";
|
|
28609
28605
|
var TABLE_ROW_END = " |";
|
|
@@ -28615,7 +28611,6 @@ var OPS_SPLIT_FILES = Object.freeze([
|
|
|
28615
28611
|
"doctor-hook.ts",
|
|
28616
28612
|
"doctor-db.ts",
|
|
28617
28613
|
"doctor-heal.ts",
|
|
28618
|
-
"release-fetch.ts",
|
|
28619
28614
|
"verify-sums.ts",
|
|
28620
28615
|
"plugin-swap.ts",
|
|
28621
28616
|
"host-write.ts",
|
|
@@ -28671,6 +28666,7 @@ var REGEX_SPECIAL_CHARS = ".*+?^${}()|[]\\";
|
|
|
28671
28666
|
var REGEX_ESCAPE = "\\";
|
|
28672
28667
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
28673
28668
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
28669
|
+
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";
|
|
28674
28670
|
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`;
|
|
28675
28671
|
function D5_SLOW_DETAIL(ms) {
|
|
28676
28672
|
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
@@ -28690,19 +28686,19 @@ function D11_PASS_DETAIL(shell, win) {
|
|
|
28690
28686
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
28691
28687
|
var HEAL_TMP_SUFFIX = ".heal";
|
|
28692
28688
|
var HEAL_TS_SEP = ".";
|
|
28693
|
-
var SUMS_LINE_END = "\n";
|
|
28694
|
-
var HASH_ENCODING = "hex";
|
|
28695
|
-
var PLUGIN_LINK_TMP_SUFFIX = ".swap";
|
|
28696
|
-
var PLUGIN_LINK_OLD_SUFFIX = ".old";
|
|
28697
|
-
var PLUGIN_LINK_TYPE = "dir";
|
|
28698
|
-
var PLUGIN_LINK_TYPE_WIN32 = "junction";
|
|
28699
28689
|
var OWNER_STOP_EXT = ".stop";
|
|
28700
28690
|
var UPGRADE_DATA_DELETED = "user data deleted";
|
|
28701
28691
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
28702
28692
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
28703
|
-
codex: "
|
|
28704
|
-
gemini: "gemini extensions
|
|
28705
|
-
qwen: "qwen extensions
|
|
28693
|
+
codex: "codex plugin marketplace upgrade context-mode",
|
|
28694
|
+
gemini: "gemini extensions update context-mode",
|
|
28695
|
+
qwen: "qwen extensions update context-mode",
|
|
28696
|
+
pi: "pi update --extensions",
|
|
28697
|
+
opencode: "opencode plugin update",
|
|
28698
|
+
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
28699
|
+
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
28700
|
+
kiro: "npm i -g context-mode && context-mode setup --agents kiro",
|
|
28701
|
+
zcode: "npm i -g context-mode && context-mode setup --agents zcode"
|
|
28706
28702
|
});
|
|
28707
28703
|
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
28708
28704
|
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
@@ -28744,6 +28740,7 @@ var HOOKS_JSON_FILE = "hooks.json";
|
|
|
28744
28740
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
28745
28741
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
28746
28742
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
28743
|
+
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
28747
28744
|
var KIRO_HOME_ENV = "KIRO_HOME";
|
|
28748
28745
|
var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
|
|
28749
28746
|
var APPDATA_ENV = "APPDATA";
|
|
@@ -28772,8 +28769,12 @@ var STATUS_LINE_KEY = "statusLine";
|
|
|
28772
28769
|
var PI_PACKAGES_KEY = "packages";
|
|
28773
28770
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
28774
28771
|
var OPENCODE_PLUGINS_KEY = "plugins";
|
|
28772
|
+
var OPENCODE_MCP_COMMAND_FIELD = "command";
|
|
28775
28773
|
var OPENCODE_PACKAGE_FIELD = "package";
|
|
28776
28774
|
var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
|
|
28775
|
+
var NPM_VERSION_SEP = "@";
|
|
28776
|
+
var OPENCODE_NPM_LATEST = `${OPENCODE_NPM_SPEC_PREFIX}latest`;
|
|
28777
|
+
var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
|
|
28777
28778
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
28778
28779
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
28779
28780
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -28802,17 +28803,22 @@ var V1_REASON = Object.freeze({
|
|
|
28802
28803
|
kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
|
|
28803
28804
|
piNpm: "old context-mode Pi package npm:context-mode",
|
|
28804
28805
|
opencodePlugin: "old context-mode OpenCode plugin spec context-mode",
|
|
28806
|
+
piGit: "old context-mode Pi entry git:github.com/mksglu/context-mode@release: ctx_upgrade replaces it with npm:context-mode@latest",
|
|
28807
|
+
opencodeGit: "old context-mode OpenCode entry git+https://github.com/mksglu/context-mode.git#release: ctx_upgrade replaces it with context-mode@latest",
|
|
28805
28808
|
zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
|
|
28806
28809
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
28807
28810
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
28808
28811
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
28809
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
28812
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep",
|
|
28813
|
+
projectLink: "context-mode path in the project reached through a link: report only, upgrade keeps it as is and never follows a link"
|
|
28810
28814
|
});
|
|
28811
|
-
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
28815
|
+
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]);
|
|
28816
|
+
var UPGRADE_KEEP_ASIDE_REASONS = Object.freeze([V1_REASON.dataDir, V1_REASON.dataRoot]);
|
|
28812
28817
|
var PLUGIN_NAME = SERVER_KEY;
|
|
28813
28818
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
28814
28819
|
var SERVER_ENTRY_FILE = "server.mjs";
|
|
28815
28820
|
var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
|
|
28821
|
+
var ROOTS_TIMEOUT_MS = 2e3;
|
|
28816
28822
|
var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
|
|
28817
28823
|
var HOST_NODE_COMMAND = "node";
|
|
28818
28824
|
var EXE_SUFFIX = ".exe";
|
|
@@ -28935,7 +28941,7 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
28935
28941
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
28936
28942
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
28937
28943
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
28938
|
-
zcode: ["
|
|
28944
|
+
zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
|
|
28939
28945
|
});
|
|
28940
28946
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
28941
28947
|
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
@@ -29141,6 +29147,15 @@ function applyMigrations(db, fromVersion) {
|
|
|
29141
29147
|
}
|
|
29142
29148
|
}
|
|
29143
29149
|
|
|
29150
|
+
// src/core/store/open-read.ts
|
|
29151
|
+
function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
29152
|
+
const bun = "bun" in opts ? opts.bun : process.versions.bun;
|
|
29153
|
+
if (bun === void 0) return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
29154
|
+
const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
29155
|
+
if (opts.queryOnly !== false) raw.exec("PRAGMA query_only = ON");
|
|
29156
|
+
return raw;
|
|
29157
|
+
}
|
|
29158
|
+
|
|
29144
29159
|
// src/core/store/db.ts
|
|
29145
29160
|
var { existsSync, linkSync, mkdirSync, rmSync } = process.getBuiltinModule("node:fs");
|
|
29146
29161
|
function versionParts(v) {
|
|
@@ -29206,7 +29221,7 @@ function openWritable(sqlite, path8) {
|
|
|
29206
29221
|
}
|
|
29207
29222
|
}
|
|
29208
29223
|
function openReadOnly(sqlite, path8) {
|
|
29209
|
-
const raw =
|
|
29224
|
+
const raw = openReadOnlyHandle(sqlite, path8);
|
|
29210
29225
|
try {
|
|
29211
29226
|
const found = readUserVersion(raw);
|
|
29212
29227
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -29399,6 +29414,10 @@ function copilotDirOf(env, home) {
|
|
|
29399
29414
|
const dir = env[COPILOT_HOME_ENV];
|
|
29400
29415
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
29401
29416
|
}
|
|
29417
|
+
function geminiDirOf(env, home) {
|
|
29418
|
+
const dir = env[GEMINI_CLI_HOME_ENV];
|
|
29419
|
+
return join(dir !== void 0 && dir !== "" ? dir : home, ...AGENT_HOME_DIR.gemini);
|
|
29420
|
+
}
|
|
29402
29421
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
29403
29422
|
const p = platform === "win32" ? win32 : posix;
|
|
29404
29423
|
const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
|
|
@@ -29457,18 +29476,23 @@ function requireHomeDir(env, platform = process.platform) {
|
|
|
29457
29476
|
if (home !== null) return home;
|
|
29458
29477
|
throw new CtxError("NO_HOME", { name: platform === "win32" ? "USERPROFILE" : "HOME" });
|
|
29459
29478
|
}
|
|
29479
|
+
function dataRootOf(env, home) {
|
|
29480
|
+
const dir = env[DATA_DIR_ENV];
|
|
29481
|
+
return dir !== void 0 && dir !== "" ? resolve(dir) : join(home, DATA_ROOT.slice(1));
|
|
29482
|
+
}
|
|
29460
29483
|
function resolveConfigDir(env) {
|
|
29461
|
-
const
|
|
29484
|
+
const set3 = env[DATA_DIR_ENV];
|
|
29485
|
+
const dir = dataRootOf(env, set3 !== void 0 && set3 !== "" ? "" : requireHomeDir(env));
|
|
29462
29486
|
mkdirSync2(dir, { recursive: true });
|
|
29463
29487
|
return realpathSync.native(dir);
|
|
29464
29488
|
}
|
|
29465
29489
|
|
|
29466
29490
|
// src/core/project/resolve.ts
|
|
29467
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
29491
|
+
import { basename as basename2, dirname as dirname3, join as join3, resolve as resolve2 } from "node:path";
|
|
29468
29492
|
|
|
29469
29493
|
// src/core/project/contain.ts
|
|
29470
|
-
import { dirname as dirname2, sep } from "node:path";
|
|
29471
|
-
var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
29494
|
+
import { dirname as dirname2, join as join2, relative, sep } from "node:path";
|
|
29495
|
+
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
29472
29496
|
function real(p) {
|
|
29473
29497
|
try {
|
|
29474
29498
|
return realpathSync2.native(p);
|
|
@@ -29507,6 +29531,21 @@ function commonRoot(paths) {
|
|
|
29507
29531
|
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
29508
29532
|
return q;
|
|
29509
29533
|
}
|
|
29534
|
+
function reachedThroughLink(root, p) {
|
|
29535
|
+
const rel = relative(root, p);
|
|
29536
|
+
const steps = components(rel);
|
|
29537
|
+
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
29538
|
+
let at = root;
|
|
29539
|
+
for (const step of steps) {
|
|
29540
|
+
at = join2(at, step);
|
|
29541
|
+
try {
|
|
29542
|
+
if (lstatSync(at).isSymbolicLink()) return true;
|
|
29543
|
+
} catch {
|
|
29544
|
+
return false;
|
|
29545
|
+
}
|
|
29546
|
+
}
|
|
29547
|
+
return false;
|
|
29548
|
+
}
|
|
29510
29549
|
|
|
29511
29550
|
// src/core/project/sha256.ts
|
|
29512
29551
|
var K = new Uint32Array([
|
|
@@ -29668,9 +29707,9 @@ function gitDirs(dir) {
|
|
|
29668
29707
|
}
|
|
29669
29708
|
const start = cur;
|
|
29670
29709
|
for (; ; ) {
|
|
29671
|
-
const gitDir = gitDirAt(
|
|
29710
|
+
const gitDir = gitDirAt(join3(cur, GIT_DIR_NAME));
|
|
29672
29711
|
if (gitDir !== null) {
|
|
29673
|
-
const common = firstLine(
|
|
29712
|
+
const common = firstLine(join3(gitDir, GIT_COMMONDIR_FILE));
|
|
29674
29713
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve2(gitDir, common)), worktree: cur, start };
|
|
29675
29714
|
}
|
|
29676
29715
|
const up = dirname3(cur);
|
|
@@ -29691,7 +29730,7 @@ function gitDirAt(dotGit) {
|
|
|
29691
29730
|
} catch {
|
|
29692
29731
|
return null;
|
|
29693
29732
|
}
|
|
29694
|
-
return existsSync2(
|
|
29733
|
+
return existsSync2(join3(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
29695
29734
|
}
|
|
29696
29735
|
function firstLine(file2) {
|
|
29697
29736
|
let text;
|
|
@@ -29732,11 +29771,11 @@ function resolveProject(agent, src) {
|
|
|
29732
29771
|
return key;
|
|
29733
29772
|
},
|
|
29734
29773
|
get projectDir() {
|
|
29735
|
-
pdir ??=
|
|
29774
|
+
pdir ??= join3(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
29736
29775
|
return pdir;
|
|
29737
29776
|
},
|
|
29738
29777
|
get dbPath() {
|
|
29739
|
-
return
|
|
29778
|
+
return join3(this.projectDir, DB_FILE_NAME);
|
|
29740
29779
|
},
|
|
29741
29780
|
worktree,
|
|
29742
29781
|
get containmentRoot() {
|
|
@@ -29750,7 +29789,7 @@ function resolveProject(agent, src) {
|
|
|
29750
29789
|
|
|
29751
29790
|
// src/core/store/cleanup.ts
|
|
29752
29791
|
import { existsSync as existsSync3, readdirSync as readdirSync2, rmSync as rmSync3 } from "node:fs";
|
|
29753
|
-
import { join as
|
|
29792
|
+
import { join as join5 } from "node:path";
|
|
29754
29793
|
|
|
29755
29794
|
// src/core/store/snippet.ts
|
|
29756
29795
|
var K1 = 1.2;
|
|
@@ -29784,14 +29823,14 @@ function identParts(w) {
|
|
|
29784
29823
|
if (cur !== "") parts.push(cur);
|
|
29785
29824
|
return parts;
|
|
29786
29825
|
}
|
|
29787
|
-
function snippetTerms(
|
|
29826
|
+
function snippetTerms(words2) {
|
|
29788
29827
|
const out = /* @__PURE__ */ new Map();
|
|
29789
29828
|
const add = (text, weight, symbol2) => {
|
|
29790
29829
|
if (text === "") return;
|
|
29791
29830
|
const prev = out.get(text);
|
|
29792
29831
|
if (!prev || prev.weight < weight) out.set(text, { text, weight, symbol: symbol2 });
|
|
29793
29832
|
};
|
|
29794
|
-
for (const raw of
|
|
29833
|
+
for (const raw of words2) {
|
|
29795
29834
|
let a = 0;
|
|
29796
29835
|
let b = raw.length;
|
|
29797
29836
|
while (a < b && !isAlnum(raw.charCodeAt(a))) a++;
|
|
@@ -31785,18 +31824,18 @@ function deleteChunkRows(raw, scope) {
|
|
|
31785
31824
|
return Number(raw.prepare("DELETE FROM chunks WHERE " + where).run(arg).changes);
|
|
31786
31825
|
}
|
|
31787
31826
|
function toMatch(q) {
|
|
31788
|
-
const
|
|
31827
|
+
const words2 = [];
|
|
31789
31828
|
let cur = "";
|
|
31790
31829
|
for (const ch of q) {
|
|
31791
31830
|
if (ch.trim() === "" || ch === "\0") {
|
|
31792
|
-
if (cur !== "")
|
|
31831
|
+
if (cur !== "") words2.push(cur);
|
|
31793
31832
|
cur = "";
|
|
31794
31833
|
} else {
|
|
31795
31834
|
cur += ch === '"' ? '""' : ch;
|
|
31796
31835
|
}
|
|
31797
31836
|
}
|
|
31798
|
-
if (cur !== "")
|
|
31799
|
-
return
|
|
31837
|
+
if (cur !== "") words2.push(cur);
|
|
31838
|
+
return words2.map((w) => `"${w}"*`).join(" ");
|
|
31800
31839
|
}
|
|
31801
31840
|
function toMatchAny(q) {
|
|
31802
31841
|
const terms = new Set(toMatch(q).split(" ").filter((t) => t !== ""));
|
|
@@ -31893,11 +31932,11 @@ function searchTerms(q) {
|
|
|
31893
31932
|
return kept.length > 0 ? kept : all;
|
|
31894
31933
|
}
|
|
31895
31934
|
function trigramMatch(q) {
|
|
31896
|
-
const
|
|
31897
|
-
const kept =
|
|
31898
|
-
const parts = new Set((kept.length > 0 ? kept :
|
|
31899
|
-
const whole2 =
|
|
31900
|
-
if (
|
|
31935
|
+
const words2 = blankTokens(q);
|
|
31936
|
+
const kept = words2.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
31937
|
+
const parts = new Set((kept.length > 0 ? kept : words2).filter((w) => [...w].length >= 3));
|
|
31938
|
+
const whole2 = words2.join(" ");
|
|
31939
|
+
if (words2.length > 1 && [...whole2].length >= 3) parts.add(whole2);
|
|
31901
31940
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
31902
31941
|
}
|
|
31903
31942
|
function editDistance(a, b, max) {
|
|
@@ -31944,10 +31983,10 @@ function queryStems(q) {
|
|
|
31944
31983
|
}
|
|
31945
31984
|
var TYPO_MIN_LEN = 5;
|
|
31946
31985
|
var TYPO_MAX_DIST = 2;
|
|
31947
|
-
function typoTerms(db,
|
|
31986
|
+
function typoTerms(db, words2) {
|
|
31948
31987
|
const has = stmt(db.raw, "SELECT 1 AS x FROM chunks_vocab WHERE term = ?");
|
|
31949
31988
|
const near = stmt(db.raw, "SELECT term, doc, length(term) AS n FROM chunks_vocab WHERE length(term) BETWEEN ? AND ?");
|
|
31950
|
-
const stems = queryStems(
|
|
31989
|
+
const stems = queryStems(words2.join(" "));
|
|
31951
31990
|
const miss = stems.map((stem) => has.get(stem) === void 0 && [...stem].length >= TYPO_MIN_LEN);
|
|
31952
31991
|
if (!miss.includes(true)) return null;
|
|
31953
31992
|
const lens = stems.filter((_, i) => miss[i]).map((stem) => stem.length);
|
|
@@ -32050,9 +32089,9 @@ function ftsListSource(db, source, scope, ctx, sessionId, limit, offset) {
|
|
|
32050
32089
|
}));
|
|
32051
32090
|
}
|
|
32052
32091
|
function highlight(row5, terms, maxBytes = SNIPPET_MAX_BYTES) {
|
|
32053
|
-
const
|
|
32054
|
-
const kept =
|
|
32055
|
-
return buildSnippet(row5, snippetTerms(kept.length > 0 ? kept :
|
|
32092
|
+
const words2 = blankTokens(terms);
|
|
32093
|
+
const kept = words2.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
32094
|
+
return buildSnippet(row5, snippetTerms(kept.length > 0 ? kept : words2), maxBytes);
|
|
32056
32095
|
}
|
|
32057
32096
|
var TL_SCOPE = `
|
|
32058
32097
|
AND (:scope <> 'session' OR session_id = :session_id)
|
|
@@ -32290,12 +32329,12 @@ function queryUnits(db, sessionId, q, limit) {
|
|
|
32290
32329
|
|
|
32291
32330
|
// src/core/store/owners.ts
|
|
32292
32331
|
import { mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync2, rmSync as rmSync2, writeFileSync } from "node:fs";
|
|
32293
|
-
import { basename as basename3, join as
|
|
32332
|
+
import { basename as basename3, join as join4 } from "node:path";
|
|
32294
32333
|
function ownersDir(configDir, projectKey) {
|
|
32295
|
-
return
|
|
32334
|
+
return join4(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
32296
32335
|
}
|
|
32297
32336
|
function ownerFile(configDir, projectKey, serverId) {
|
|
32298
|
-
return
|
|
32337
|
+
return join4(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
|
|
32299
32338
|
}
|
|
32300
32339
|
function errCode(err) {
|
|
32301
32340
|
return err.code;
|
|
@@ -32330,7 +32369,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
32330
32369
|
const live = [];
|
|
32331
32370
|
for (const name of names) {
|
|
32332
32371
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
32333
|
-
const file2 =
|
|
32372
|
+
const file2 = join4(dir, name);
|
|
32334
32373
|
let text;
|
|
32335
32374
|
try {
|
|
32336
32375
|
text = readFileSync2(file2, "utf8");
|
|
@@ -32401,8 +32440,8 @@ function lastAccess(raw) {
|
|
|
32401
32440
|
return row5.t;
|
|
32402
32441
|
}
|
|
32403
32442
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
32404
|
-
const dir =
|
|
32405
|
-
const db = openForSweep(
|
|
32443
|
+
const dir = join5(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
32444
|
+
const db = openForSweep(join5(dir, DB_FILE_NAME), projectKey);
|
|
32406
32445
|
let dead;
|
|
32407
32446
|
try {
|
|
32408
32447
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
@@ -32415,7 +32454,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
32415
32454
|
function sweepDeadProjects(configDir) {
|
|
32416
32455
|
let entries;
|
|
32417
32456
|
try {
|
|
32418
|
-
entries = readdirSync2(
|
|
32457
|
+
entries = readdirSync2(join5(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
32419
32458
|
} catch (err) {
|
|
32420
32459
|
if (err.code === "ENOENT") return [];
|
|
32421
32460
|
throw err;
|
|
@@ -43864,7 +43903,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
43864
43903
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
43865
43904
|
return { end: start + r.read, written: r.written };
|
|
43866
43905
|
}
|
|
43867
|
-
function merge4(src, blocks,
|
|
43906
|
+
function merge4(src, blocks, join23, cap, lineCut) {
|
|
43868
43907
|
const out = [];
|
|
43869
43908
|
const scratch = new Uint8Array(cap);
|
|
43870
43909
|
let wide;
|
|
@@ -43874,7 +43913,7 @@ function merge4(src, blocks, join26, cap, lineCut) {
|
|
|
43874
43913
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
43875
43914
|
};
|
|
43876
43915
|
for (const b of blocks) {
|
|
43877
|
-
if (cur !== void 0 && !
|
|
43916
|
+
if (cur !== void 0 && !join23) {
|
|
43878
43917
|
emit(cur.start, cur.end, curBytes);
|
|
43879
43918
|
cur = void 0;
|
|
43880
43919
|
}
|
|
@@ -44036,10 +44075,10 @@ function findRuntime(lang, env = process.env) {
|
|
|
44036
44075
|
return shim;
|
|
44037
44076
|
}
|
|
44038
44077
|
function findGitBash(env) {
|
|
44039
|
-
const
|
|
44040
|
-
if (
|
|
44078
|
+
const git2 = findRuntime(GIT_BIN, env);
|
|
44079
|
+
if (git2 === null) return null;
|
|
44041
44080
|
for (const rel of GIT_BASH_RELATIVE) {
|
|
44042
|
-
const full = path.resolve(path.dirname(
|
|
44081
|
+
const full = path.resolve(path.dirname(git2), ...rel);
|
|
44043
44082
|
if (isRunnable(full)) return full;
|
|
44044
44083
|
}
|
|
44045
44084
|
return null;
|
|
@@ -44144,7 +44183,7 @@ function runProcess(argv, o) {
|
|
|
44144
44183
|
|
|
44145
44184
|
// src/core/index/auto-memory.ts
|
|
44146
44185
|
import { readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
|
|
44147
|
-
import { join as
|
|
44186
|
+
import { join as join6 } from "node:path";
|
|
44148
44187
|
var MEMORY_FILES = Object.freeze([
|
|
44149
44188
|
Object.freeze(["CLAUDE.md"]),
|
|
44150
44189
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -44158,7 +44197,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
44158
44197
|
var MD = ".md";
|
|
44159
44198
|
function steeringFiles(worktree) {
|
|
44160
44199
|
try {
|
|
44161
|
-
return readdirSync3(
|
|
44200
|
+
return readdirSync3(join6(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
44162
44201
|
} catch {
|
|
44163
44202
|
return [];
|
|
44164
44203
|
}
|
|
@@ -44166,7 +44205,7 @@ function steeringFiles(worktree) {
|
|
|
44166
44205
|
function readAutoMemory(project) {
|
|
44167
44206
|
const rows = [];
|
|
44168
44207
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
44169
|
-
const path8 =
|
|
44208
|
+
const path8 = join6(project.worktree, ...segs);
|
|
44170
44209
|
if (!isInside(project.worktree, path8)) continue;
|
|
44171
44210
|
try {
|
|
44172
44211
|
const st = statSync3(path8);
|
|
@@ -44803,7 +44842,7 @@ var ctxBatch = Object.freeze({
|
|
|
44803
44842
|
|
|
44804
44843
|
// src/core/tools/doctor.ts
|
|
44805
44844
|
import { readdirSync as readdirSync7, readFileSync as readFileSync11, existsSync as existsSync16 } from "node:fs";
|
|
44806
|
-
import { basename as basename5, join as
|
|
44845
|
+
import { basename as basename5, join as join16 } from "node:path";
|
|
44807
44846
|
|
|
44808
44847
|
// src/adapters/claude-code.ts
|
|
44809
44848
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -45020,6 +45059,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
|
45020
45059
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
45021
45060
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
45022
45061
|
var EMPTY = { stdout: "", exitCode: 0 };
|
|
45062
|
+
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";
|
|
45023
45063
|
function own3(p, key) {
|
|
45024
45064
|
return Object.hasOwn(p, key) ? p[key] : void 0;
|
|
45025
45065
|
}
|
|
@@ -45039,13 +45079,67 @@ function canonicalName2(name, mcp) {
|
|
|
45039
45079
|
if (typeof server !== "string" || typeof tool !== "string") return name;
|
|
45040
45080
|
return "mcp:" + server + ":" + tool;
|
|
45041
45081
|
}
|
|
45082
|
+
function partsText(llm) {
|
|
45083
|
+
if (!Array.isArray(llm) || llm.length === 0) return void 0;
|
|
45084
|
+
const out = [];
|
|
45085
|
+
for (const part of llm) {
|
|
45086
|
+
if (typeof part === "string") {
|
|
45087
|
+
out.push(part);
|
|
45088
|
+
continue;
|
|
45089
|
+
}
|
|
45090
|
+
if (typeof part !== "object" || part === null) return void 0;
|
|
45091
|
+
const t = own3(part, "text");
|
|
45092
|
+
if (typeof t !== "string") return void 0;
|
|
45093
|
+
out.push(t);
|
|
45094
|
+
}
|
|
45095
|
+
return out.join("");
|
|
45096
|
+
}
|
|
45042
45097
|
function readResult2(resp) {
|
|
45043
45098
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
45044
45099
|
const llm = obj === void 0 ? void 0 : own3(obj, "llmContent");
|
|
45045
|
-
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : JSON.stringify(resp);
|
|
45100
|
+
const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
45046
45101
|
const err = obj === void 0 ? void 0 : own3(obj, "error");
|
|
45047
45102
|
return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
|
|
45048
45103
|
}
|
|
45104
|
+
var URL_STARTS = ["https://", "http://"];
|
|
45105
|
+
var URL_TRAIL = `.,;:!?)]}>'"`;
|
|
45106
|
+
var SPACE = " \n\r\f\v";
|
|
45107
|
+
function words(text) {
|
|
45108
|
+
const out = [];
|
|
45109
|
+
let cur = "";
|
|
45110
|
+
for (const ch of text) {
|
|
45111
|
+
if (SPACE.includes(ch)) {
|
|
45112
|
+
if (cur !== "") out.push(cur);
|
|
45113
|
+
cur = "";
|
|
45114
|
+
} else cur += ch;
|
|
45115
|
+
}
|
|
45116
|
+
if (cur !== "") out.push(cur);
|
|
45117
|
+
return out;
|
|
45118
|
+
}
|
|
45119
|
+
function firstUrl(prompt) {
|
|
45120
|
+
if (typeof prompt !== "string") return void 0;
|
|
45121
|
+
for (const word of words(prompt)) {
|
|
45122
|
+
const lower = word.toLowerCase();
|
|
45123
|
+
const at = URL_STARTS.map((s) => lower.indexOf(s)).filter((i) => i >= 0).sort((a, b) => a - b)[0];
|
|
45124
|
+
if (at === void 0) continue;
|
|
45125
|
+
let url4 = word.slice(at);
|
|
45126
|
+
while (url4.length > 0 && URL_TRAIL.includes(url4[url4.length - 1])) url4 = url4.slice(0, -1);
|
|
45127
|
+
return url4;
|
|
45128
|
+
}
|
|
45129
|
+
return void 0;
|
|
45130
|
+
}
|
|
45131
|
+
function nativeInput(name, input) {
|
|
45132
|
+
if (name === "web_fetch" && own3(input, "url") === void 0) {
|
|
45133
|
+
const url4 = firstUrl(own3(input, "prompt"));
|
|
45134
|
+
return url4 === void 0 ? input : { ...input, url: url4 };
|
|
45135
|
+
}
|
|
45136
|
+
if (name === "read_many_files" && own3(input, "file_path") === void 0) {
|
|
45137
|
+
const inc = own3(input, "include");
|
|
45138
|
+
const list3 = Array.isArray(inc) ? inc.filter((v) => typeof v === "string") : [];
|
|
45139
|
+
return list3.length === 0 ? input : { ...input, file_path: list3.join(" ") };
|
|
45140
|
+
}
|
|
45141
|
+
return input;
|
|
45142
|
+
}
|
|
45049
45143
|
function decode5(raw) {
|
|
45050
45144
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
45051
45145
|
const p = raw;
|
|
@@ -45063,7 +45157,7 @@ function decode5(raw) {
|
|
|
45063
45157
|
ev.tool = {
|
|
45064
45158
|
name,
|
|
45065
45159
|
canonicalName: canonicalName2(name, own3(p, "mcp_context")),
|
|
45066
|
-
input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
45160
|
+
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
45067
45161
|
};
|
|
45068
45162
|
}
|
|
45069
45163
|
if (event === "PostToolUse") ev.result = readResult2(own3(p, "tool_response"));
|
|
@@ -45081,7 +45175,7 @@ function encode5(ev, d, _extra) {
|
|
|
45081
45175
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
45082
45176
|
case "replace":
|
|
45083
45177
|
if (ev.event !== "PostToolUse") return EMPTY;
|
|
45084
|
-
return { stdout: JSON.stringify({ decision: "deny", reason: d.output }), exitCode: 0 };
|
|
45178
|
+
return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
|
|
45085
45179
|
}
|
|
45086
45180
|
}
|
|
45087
45181
|
|
|
@@ -45142,6 +45236,14 @@ function canonicalName3(name) {
|
|
|
45142
45236
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
45143
45237
|
return name;
|
|
45144
45238
|
}
|
|
45239
|
+
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
45240
|
+
function viewRange(name, input) {
|
|
45241
|
+
const r = input.view_range;
|
|
45242
|
+
if (name !== "view" || !Array.isArray(r) || !isNum(r[0])) return input;
|
|
45243
|
+
const out = { ...input, offset: r[0] };
|
|
45244
|
+
if (isNum(r[1]) && r[1] >= r[0]) out.limit = r[1] - r[0] + 1;
|
|
45245
|
+
return out;
|
|
45246
|
+
}
|
|
45145
45247
|
function readArgs(v) {
|
|
45146
45248
|
if (isRecord(v)) return v;
|
|
45147
45249
|
if (typeof v !== "string") return {};
|
|
@@ -45186,7 +45288,7 @@ function decode7(raw) {
|
|
|
45186
45288
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
45187
45289
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
45188
45290
|
const toolName2 = String(raw[k.tool] ?? "");
|
|
45189
|
-
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
45291
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: viewRange(toolName2, readArgs(raw[k.args])) };
|
|
45190
45292
|
ev.tool = tool;
|
|
45191
45293
|
}
|
|
45192
45294
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
@@ -45234,18 +45336,18 @@ function canonicalName4(name) {
|
|
|
45234
45336
|
if (sep3 <= 0 || sep3 === rest.length - 1) return name;
|
|
45235
45337
|
return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP2.length);
|
|
45236
45338
|
}
|
|
45237
|
-
var
|
|
45339
|
+
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
45238
45340
|
function policyInput(name, canonical, input) {
|
|
45239
45341
|
if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
|
|
45240
45342
|
const out = { ...input };
|
|
45241
45343
|
if (name === "read_file") {
|
|
45242
45344
|
if (typeof input.filePath === "string") out.file_path = input.filePath;
|
|
45243
|
-
if (
|
|
45244
|
-
if (
|
|
45245
|
-
} else if (Array.isArray(input.view_range) &&
|
|
45345
|
+
if (isNum2(input.startLine)) out.offset = input.startLine;
|
|
45346
|
+
if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
|
|
45347
|
+
} else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
|
|
45246
45348
|
out.offset = input.view_range[0];
|
|
45247
45349
|
const end = input.view_range[1];
|
|
45248
|
-
if (
|
|
45350
|
+
if (isNum2(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
|
|
45249
45351
|
}
|
|
45250
45352
|
return out;
|
|
45251
45353
|
}
|
|
@@ -45406,6 +45508,7 @@ function encode9(ev, d, _extra) {
|
|
|
45406
45508
|
|
|
45407
45509
|
// src/adapters/zcode.ts
|
|
45408
45510
|
var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
|
|
45511
|
+
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
45409
45512
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
45410
45513
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
45411
45514
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
@@ -45415,7 +45518,9 @@ function decode10(raw) {
|
|
|
45415
45518
|
for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
|
|
45416
45519
|
const failure3 = p.hook_event_name === FAILURE_EVENT2;
|
|
45417
45520
|
if (failure3) p.hook_event_name = "PostToolUse";
|
|
45418
|
-
const
|
|
45521
|
+
const toolName2 = typeof p.tool_name === "string" ? p.tool_name : "";
|
|
45522
|
+
const prefix = toolName2.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
|
|
45523
|
+
const ev = decodeClaudeShape(p, "zcode", prefix, ZCODE_SOURCES);
|
|
45419
45524
|
if (failure3) {
|
|
45420
45525
|
const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
|
|
45421
45526
|
ev.result = { isError: true, bytes: Buffer.byteLength(text), text };
|
|
@@ -45496,8 +45601,9 @@ var OPENCODE_EVENTS = {
|
|
|
45496
45601
|
"step-finish": "Usage"
|
|
45497
45602
|
};
|
|
45498
45603
|
var SHELL_TOOL_NAME = "bash";
|
|
45604
|
+
var READ_TOOL_NAME = "read";
|
|
45499
45605
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
45500
|
-
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
45606
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
45501
45607
|
function toCanonicalTool(name) {
|
|
45502
45608
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
45503
45609
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -45725,9 +45831,9 @@ var ADAPTERS = Object.freeze([
|
|
|
45725
45831
|
installMode: "in-process",
|
|
45726
45832
|
projectSource: "spawn-cwd",
|
|
45727
45833
|
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
45728
|
-
nativeTools: { shell: [SHELL_TOOL_NAME] },
|
|
45834
|
+
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
45729
45835
|
execReadOnlyHint: false,
|
|
45730
|
-
// D-HF-OPENCODE-SHELL-1
|
|
45836
|
+
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
45731
45837
|
// Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
|
|
45732
45838
|
eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
|
|
45733
45839
|
compactDelivery: "opencode-cache",
|
|
@@ -45753,14 +45859,14 @@ function getAdapter(id) {
|
|
|
45753
45859
|
|
|
45754
45860
|
// src/core/ops/bundle-dir.ts
|
|
45755
45861
|
import { existsSync as existsSync4 } from "node:fs";
|
|
45756
|
-
import { dirname as dirname4, join as
|
|
45862
|
+
import { dirname as dirname4, join as join7 } from "node:path";
|
|
45757
45863
|
import { fileURLToPath } from "node:url";
|
|
45758
45864
|
function bundleDirOf(argv1, moduleFile) {
|
|
45759
45865
|
const own4 = dirname4(argv1);
|
|
45760
|
-
if (existsSync4(
|
|
45866
|
+
if (existsSync4(join7(own4, SERVER_ENTRY_FILE))) return own4;
|
|
45761
45867
|
let dir = dirname4(moduleFile);
|
|
45762
45868
|
for (; ; ) {
|
|
45763
|
-
if (existsSync4(
|
|
45869
|
+
if (existsSync4(join7(dir, SERVER_ENTRY_FILE))) return dir;
|
|
45764
45870
|
const up = dirname4(dir);
|
|
45765
45871
|
if (up === dir) return own4;
|
|
45766
45872
|
dir = up;
|
|
@@ -45775,16 +45881,16 @@ function ownBundleDir() {
|
|
|
45775
45881
|
|
|
45776
45882
|
// src/core/ops/doctor-config.ts
|
|
45777
45883
|
import { existsSync as existsSync9, readdirSync as readdirSync6 } from "node:fs";
|
|
45778
|
-
import { join as
|
|
45884
|
+
import { join as join11 } from "node:path";
|
|
45779
45885
|
|
|
45780
45886
|
// src/core/ops/detect-v1.ts
|
|
45781
45887
|
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync5 } from "node:fs";
|
|
45782
45888
|
import { tmpdir } from "node:os";
|
|
45783
|
-
import { join as
|
|
45889
|
+
import { join as join9 } from "node:path";
|
|
45784
45890
|
|
|
45785
45891
|
// src/core/ops/host-config.ts
|
|
45786
45892
|
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "node:fs";
|
|
45787
|
-
import { dirname as dirname5, join as
|
|
45893
|
+
import { dirname as dirname5, join as join8 } from "node:path";
|
|
45788
45894
|
|
|
45789
45895
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
45790
45896
|
var KEYS2 = {
|
|
@@ -47924,7 +48030,7 @@ function formatOf(path8) {
|
|
|
47924
48030
|
function readHostConfig(agent, path8) {
|
|
47925
48031
|
let file2 = path8;
|
|
47926
48032
|
if (agent === "opencode") {
|
|
47927
|
-
const jsonc =
|
|
48033
|
+
const jsonc = join8(dirname5(path8), OPENCODE_CONFIG_FILES[0]);
|
|
47928
48034
|
if (existsSync5(jsonc)) file2 = jsonc;
|
|
47929
48035
|
}
|
|
47930
48036
|
const raw = existsSync5(file2) ? readFileSync4(file2, "utf8") : "";
|
|
@@ -48272,7 +48378,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
48272
48378
|
}
|
|
48273
48379
|
}
|
|
48274
48380
|
function serverScript() {
|
|
48275
|
-
return
|
|
48381
|
+
return join8(dirname5(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
48276
48382
|
}
|
|
48277
48383
|
function isNodeCommand(command) {
|
|
48278
48384
|
if (typeof command !== "string") return false;
|
|
@@ -48284,21 +48390,27 @@ function isNodeCommand(command) {
|
|
|
48284
48390
|
function ownMcpValue(agent, node3, server) {
|
|
48285
48391
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
48286
48392
|
if (mcp === void 0) return void 0;
|
|
48287
|
-
|
|
48288
|
-
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
|
|
48393
|
+
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent] };
|
|
48289
48394
|
}
|
|
48290
48395
|
function opencodePluginFile() {
|
|
48291
48396
|
return ownBundleDir();
|
|
48292
48397
|
}
|
|
48293
|
-
function listTarget(key,
|
|
48398
|
+
function listTarget(key, legacy, swap, isNative) {
|
|
48294
48399
|
return {
|
|
48295
48400
|
key: [key],
|
|
48296
48401
|
next(current) {
|
|
48297
|
-
|
|
48298
|
-
|
|
48402
|
+
if (!Array.isArray(current) || !current.some(legacy)) return current;
|
|
48403
|
+
const keep = current.filter((x) => !legacy(x));
|
|
48404
|
+
if (keep.some(isNative)) return keep;
|
|
48405
|
+
const at = current.findIndex(legacy);
|
|
48406
|
+
return current.flatMap((x, i) => i === at ? [swap(x)] : legacy(x) ? [] : [x]);
|
|
48299
48407
|
}
|
|
48300
48408
|
};
|
|
48301
48409
|
}
|
|
48410
|
+
var piSource = (x) => isPlainObject6(x) ? x[PI_PACKAGE_SOURCE_KEY] : x;
|
|
48411
|
+
var opencodeSpec = (x) => isPlainObject6(x) ? x[OPENCODE_PACKAGE_FIELD] : x;
|
|
48412
|
+
var isNpmOf = (bare2) => (s) => typeof s === "string" && (s === bare2 || s.startsWith(bare2 + NPM_VERSION_SEP));
|
|
48413
|
+
var swapField = (field, spec) => (x) => isPlainObject6(x) ? { ...x, [field]: spec } : spec;
|
|
48302
48414
|
function ownTargets(agent, accept) {
|
|
48303
48415
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
48304
48416
|
if (mcp !== void 0) {
|
|
@@ -48311,8 +48423,18 @@ function ownTargets(agent, accept) {
|
|
|
48311
48423
|
}
|
|
48312
48424
|
}, ...(mcp.also ?? []).map(([key, value]) => ({ key, next: () => value }))];
|
|
48313
48425
|
}
|
|
48314
|
-
if (agent === "opencode")
|
|
48315
|
-
|
|
48426
|
+
if (agent === "opencode") {
|
|
48427
|
+
const alt = accept.listEntries ?? [];
|
|
48428
|
+
const native = (x) => {
|
|
48429
|
+
const s = opencodeSpec(x);
|
|
48430
|
+
return typeof s === "string" && (s.startsWith(OPENCODE_NPM_SPEC_PREFIX) || alt.includes(s));
|
|
48431
|
+
};
|
|
48432
|
+
return [listTarget(OPENCODE_PLUGIN_KEY, (x) => opencodeSpec(x) === OPENCODE_GIT_SPEC, swapField(OPENCODE_PACKAGE_FIELD, OPENCODE_NPM_LATEST), native)];
|
|
48433
|
+
}
|
|
48434
|
+
if (agent === "pi") {
|
|
48435
|
+
const npm = isNpmOf(V1_PI_PACKAGE);
|
|
48436
|
+
return [listTarget(PI_PACKAGES_KEY, (x) => piSource(x) === PI_GIT_PACKAGE, swapField(PI_PACKAGE_SOURCE_KEY, PI_NPM_LATEST), (x) => npm(piSource(x)))];
|
|
48437
|
+
}
|
|
48316
48438
|
return [];
|
|
48317
48439
|
}
|
|
48318
48440
|
function applyEdits(agent, path8, text, format, wanted) {
|
|
@@ -48455,7 +48577,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
48455
48577
|
}
|
|
48456
48578
|
}
|
|
48457
48579
|
function claudeShapeSettings(agentHome, out) {
|
|
48458
|
-
const file2 =
|
|
48580
|
+
const file2 = join9(agentHome, SETTINGS_FILE);
|
|
48459
48581
|
const doc = readJson(file2);
|
|
48460
48582
|
for (const c of nestedCommands(doc)) {
|
|
48461
48583
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -48475,49 +48597,50 @@ function v1HookFile(file2, out) {
|
|
|
48475
48597
|
function scanClaudeCode(home, agentHome, out) {
|
|
48476
48598
|
claudeShapeSettings(agentHome, out);
|
|
48477
48599
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
48478
|
-
const file2 =
|
|
48600
|
+
const file2 = join9(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
48479
48601
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
48480
48602
|
}
|
|
48481
|
-
const userFile =
|
|
48603
|
+
const userFile = join9(home, CLAUDE_USER_CONFIG_FILE);
|
|
48482
48604
|
mcpEntry(userFile, readJson(userFile), out);
|
|
48483
|
-
dataDir(
|
|
48605
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48484
48606
|
}
|
|
48485
48607
|
function scanCodex(agentHome, out) {
|
|
48486
|
-
const hooksFile =
|
|
48608
|
+
const hooksFile = join9(agentHome, HOOKS_JSON_FILE);
|
|
48487
48609
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
48488
48610
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
48489
48611
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
48490
48612
|
}
|
|
48491
48613
|
}
|
|
48492
|
-
const tomlFile =
|
|
48614
|
+
const tomlFile = join9(agentHome, CONFIG_TOML_FILE);
|
|
48493
48615
|
const config4 = readTomlValue(tomlFile);
|
|
48494
48616
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
48495
48617
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
48496
48618
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
48497
48619
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
48498
48620
|
}
|
|
48499
|
-
dataDir(
|
|
48621
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48500
48622
|
}
|
|
48501
48623
|
function scanGemini(agentHome, out) {
|
|
48502
|
-
const file2 =
|
|
48624
|
+
const file2 = join9(agentHome, SETTINGS_FILE);
|
|
48503
48625
|
for (const c of nestedCommands(readJson(file2))) {
|
|
48504
48626
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
48505
48627
|
}
|
|
48506
|
-
dataDir(
|
|
48628
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
48507
48629
|
}
|
|
48508
48630
|
function scanVscode(agentHome, project, out) {
|
|
48509
48631
|
if (project !== void 0) {
|
|
48510
|
-
v1HookFile(
|
|
48511
|
-
const mcpFile2 =
|
|
48632
|
+
v1HookFile(join9(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
48633
|
+
const mcpFile2 = join9(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
48512
48634
|
const doc = readJson(mcpFile2);
|
|
48513
48635
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
48514
48636
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
48515
48637
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
48516
48638
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
48517
48639
|
}
|
|
48518
|
-
|
|
48640
|
+
const sessions = join9(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
48641
|
+
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
48519
48642
|
}
|
|
48520
|
-
dataDir(
|
|
48643
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
48521
48644
|
}
|
|
48522
48645
|
function jsonFiles(dir) {
|
|
48523
48646
|
try {
|
|
@@ -48527,10 +48650,10 @@ function jsonFiles(dir) {
|
|
|
48527
48650
|
}
|
|
48528
48651
|
}
|
|
48529
48652
|
function scanKiro(agentHome, project, out) {
|
|
48530
|
-
const agentsDir =
|
|
48531
|
-
const defaultFile =
|
|
48653
|
+
const agentsDir = join9(agentHome, KIRO_AGENTS_DIR);
|
|
48654
|
+
const defaultFile = join9(agentHome, ...KIRO_AGENT_FILE);
|
|
48532
48655
|
for (const name of jsonFiles(agentsDir)) {
|
|
48533
|
-
const file2 =
|
|
48656
|
+
const file2 = join9(agentsDir, name);
|
|
48534
48657
|
const doc = readJson(file2);
|
|
48535
48658
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
48536
48659
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -48541,46 +48664,48 @@ function scanKiro(agentHome, project, out) {
|
|
|
48541
48664
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
48542
48665
|
}
|
|
48543
48666
|
}
|
|
48544
|
-
const steeringDocs = [
|
|
48545
|
-
if (project !== void 0) steeringDocs.push(
|
|
48667
|
+
const steeringDocs = [join9(agentHome, ...KIRO_STEERING_FILE)];
|
|
48668
|
+
if (project !== void 0) steeringDocs.push(join9(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
48546
48669
|
for (const file2 of steeringDocs) {
|
|
48547
48670
|
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
48548
48671
|
}
|
|
48549
|
-
dataDir(
|
|
48672
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48550
48673
|
}
|
|
48551
48674
|
function piNpmIsCurrent(piAgentDir) {
|
|
48552
|
-
const doc = readJson(
|
|
48675
|
+
const doc = readJson(join9(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
48553
48676
|
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
48554
48677
|
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
48555
48678
|
}
|
|
48556
48679
|
function scanPi(piAgentDir, agentHome, out) {
|
|
48557
|
-
const file2 =
|
|
48680
|
+
const file2 = join9(piAgentDir, SETTINGS_FILE);
|
|
48558
48681
|
const doc = readJson(file2);
|
|
48559
48682
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
48560
48683
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
48561
48684
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
48685
|
+
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
48562
48686
|
});
|
|
48563
|
-
dataDir(
|
|
48687
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48564
48688
|
}
|
|
48565
48689
|
function scanOpencode(agentHome, out) {
|
|
48566
48690
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
48567
|
-
const file2 =
|
|
48691
|
+
const file2 = join9(agentHome, name);
|
|
48568
48692
|
const doc = readJson(file2);
|
|
48569
48693
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
48570
48694
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
48571
48695
|
if (spec === V1_OPENCODE_PLUGIN_SPEC) out.push(finding(file2, keyPath(OPENCODE_PLUGIN_KEY, i), V1_REASON.opencodePlugin));
|
|
48696
|
+
if (spec === OPENCODE_GIT_SPEC) out.push(finding(file2, keyPath(OPENCODE_PLUGIN_KEY, i), V1_REASON.opencodeGit));
|
|
48572
48697
|
});
|
|
48573
48698
|
return;
|
|
48574
48699
|
}
|
|
48575
48700
|
}
|
|
48576
48701
|
function scanZcode(agentHome, out) {
|
|
48577
|
-
const configFile =
|
|
48702
|
+
const configFile = join9(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
48578
48703
|
const config4 = readJson(configFile);
|
|
48579
48704
|
const events = isObj(config4) && isObj(config4[HOOKS_KEY]) ? config4[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
48580
48705
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
48581
48706
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
48582
48707
|
}
|
|
48583
|
-
const hooksFile =
|
|
48708
|
+
const hooksFile = join9(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
48584
48709
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
48585
48710
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
48586
48711
|
}
|
|
@@ -48604,14 +48729,14 @@ function firstTmpMatch(dir) {
|
|
|
48604
48729
|
}
|
|
48605
48730
|
}
|
|
48606
48731
|
function scanAll(home, tmp, out) {
|
|
48607
|
-
const root =
|
|
48608
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
48732
|
+
const root = join9(home, DATA_ROOT.slice(1));
|
|
48733
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join9(root, name), V1_REASON.dataRoot, out);
|
|
48609
48734
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
48610
48735
|
}
|
|
48611
48736
|
function detectV1(agent, home, scope = {}) {
|
|
48612
48737
|
const out = [];
|
|
48613
48738
|
const project = scope.project;
|
|
48614
|
-
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 :
|
|
48739
|
+
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 : join9(home, ...AGENT_HOME_DIR[agent]);
|
|
48615
48740
|
switch (agent) {
|
|
48616
48741
|
case "claude-code":
|
|
48617
48742
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -48624,11 +48749,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
48624
48749
|
break;
|
|
48625
48750
|
case "qwen":
|
|
48626
48751
|
claudeShapeSettings(agentHome, out);
|
|
48627
|
-
dataDir(
|
|
48752
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48628
48753
|
break;
|
|
48629
48754
|
case "copilot-cli":
|
|
48630
|
-
v1HookFile(
|
|
48631
|
-
dataDir(
|
|
48755
|
+
v1HookFile(join9(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
48756
|
+
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48632
48757
|
break;
|
|
48633
48758
|
case "vscode":
|
|
48634
48759
|
scanVscode(agentHome, project, out);
|
|
@@ -48637,7 +48762,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
48637
48762
|
scanKiro(agentHome, project, out);
|
|
48638
48763
|
break;
|
|
48639
48764
|
case "pi":
|
|
48640
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
48765
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join9(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
48641
48766
|
break;
|
|
48642
48767
|
// D-WIN-PIDIR-1: empty is unset
|
|
48643
48768
|
case "opencode":
|
|
@@ -48653,7 +48778,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
48653
48778
|
|
|
48654
48779
|
// src/core/ops/plugin-root.ts
|
|
48655
48780
|
import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
|
|
48656
|
-
import { dirname as dirname6, isAbsolute, join as
|
|
48781
|
+
import { dirname as dirname6, isAbsolute, join as join10, sep as sep2 } from "node:path";
|
|
48657
48782
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
48658
48783
|
function missing(agent, path8) {
|
|
48659
48784
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -48701,8 +48826,8 @@ var readOrNull = (file2) => {
|
|
|
48701
48826
|
};
|
|
48702
48827
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
48703
48828
|
function enabledPlugins(claudeDir, project) {
|
|
48704
|
-
const files = [
|
|
48705
|
-
if (project !== void 0) files.push(
|
|
48829
|
+
const files = [join10(claudeDir, SETTINGS_FILE)];
|
|
48830
|
+
if (project !== void 0) files.push(join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
48706
48831
|
const out = {};
|
|
48707
48832
|
for (const file2 of files) {
|
|
48708
48833
|
const text = readOrNull(file2);
|
|
@@ -48718,7 +48843,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
48718
48843
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
|
|
48719
48844
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
48720
48845
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
48721
|
-
const record6 = readOrNull(
|
|
48846
|
+
const record6 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
48722
48847
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
48723
48848
|
if (recorded.length === 0) return { record: false };
|
|
48724
48849
|
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
@@ -48741,18 +48866,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
48741
48866
|
}
|
|
48742
48867
|
function marketplaceRoot(adapter, env, worktree) {
|
|
48743
48868
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
48744
|
-
const plugins =
|
|
48745
|
-
const cache =
|
|
48869
|
+
const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
48870
|
+
const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
48746
48871
|
const script = process.argv[1];
|
|
48747
48872
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
|
|
48748
48873
|
const choice = marketplaceChoice(env, worktree);
|
|
48749
48874
|
if ("root" in choice) return choice.root;
|
|
48750
48875
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
48751
48876
|
const cacheReal = realOrNull(cache);
|
|
48752
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync7(
|
|
48753
|
-
const pattern =
|
|
48877
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync7(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
48878
|
+
const pattern = join10(cache, "*", PLUGIN_NAME);
|
|
48754
48879
|
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
48755
|
-
const found = readdirSync5(cache).sort().map((marketplace) =>
|
|
48880
|
+
const found = readdirSync5(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
48756
48881
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
48757
48882
|
return found[0];
|
|
48758
48883
|
}
|
|
@@ -48777,9 +48902,9 @@ function candidate(adapter, env, worktree) {
|
|
|
48777
48902
|
case "hooks+mcp":
|
|
48778
48903
|
return configEntryRoot(adapter, env);
|
|
48779
48904
|
case "extension":
|
|
48780
|
-
return
|
|
48905
|
+
return join10(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join10(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
48781
48906
|
case "plugin":
|
|
48782
|
-
return
|
|
48907
|
+
return join10(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
48783
48908
|
case "in-process":
|
|
48784
48909
|
return dirname6(fileURLToPath2(import.meta.url));
|
|
48785
48910
|
}
|
|
@@ -48939,11 +49064,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
48939
49064
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
48940
49065
|
function mcpFile(row5, home, env) {
|
|
48941
49066
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
48942
|
-
if (row5.id === "codex") return
|
|
49067
|
+
if (row5.id === "codex") return join11(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
48943
49068
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
48944
|
-
if (row5.id === "opencode") return
|
|
49069
|
+
if (row5.id === "opencode") return join11(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
48945
49070
|
if (row5.id === "pi") {
|
|
48946
|
-
return
|
|
49071
|
+
return join11(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
48947
49072
|
}
|
|
48948
49073
|
return null;
|
|
48949
49074
|
}
|
|
@@ -48956,27 +49081,27 @@ function codexNativeDir(env, home) {
|
|
|
48956
49081
|
const codexDir = codexDirOf(env, home);
|
|
48957
49082
|
let enabled;
|
|
48958
49083
|
try {
|
|
48959
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
49084
|
+
enabled = hostConfigValueAt(readParsed("codex", join11(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
48960
49085
|
} catch {
|
|
48961
49086
|
return null;
|
|
48962
49087
|
}
|
|
48963
49088
|
if (enabled !== true) return null;
|
|
48964
|
-
const cache =
|
|
49089
|
+
const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
48965
49090
|
if (!existsSync9(cache)) return null;
|
|
48966
49091
|
const found = [];
|
|
48967
49092
|
for (const market of readdirSync6(cache)) {
|
|
48968
|
-
const plugin =
|
|
49093
|
+
const plugin = join11(cache, market, SERVER_KEY);
|
|
48969
49094
|
if (!existsSync9(plugin)) continue;
|
|
48970
49095
|
for (const version4 of readdirSync6(plugin).sort()) {
|
|
48971
|
-
const dir =
|
|
48972
|
-
if (existsSync9(
|
|
49096
|
+
const dir = join11(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
49097
|
+
if (existsSync9(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
48973
49098
|
}
|
|
48974
49099
|
}
|
|
48975
49100
|
return found.length === 0 ? null : found[found.length - 1];
|
|
48976
49101
|
}
|
|
48977
49102
|
function nativeMcpWrong(dir, row5) {
|
|
48978
49103
|
try {
|
|
48979
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
49104
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join11(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
48980
49105
|
if (!isObject4(entry)) return true;
|
|
48981
49106
|
const args = list(entry[MCP_ARGS_FIELD]);
|
|
48982
49107
|
const script = args[0];
|
|
@@ -48991,10 +49116,19 @@ function isOwnOpencodeEntry(entry, key, own4) {
|
|
|
48991
49116
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own4.includes(spec)) return true;
|
|
48992
49117
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
48993
49118
|
}
|
|
49119
|
+
function opencodeMcpOwn(entry) {
|
|
49120
|
+
if (!isObject4(entry)) return false;
|
|
49121
|
+
const cmd = Array.isArray(entry[OPENCODE_MCP_COMMAND_FIELD]) ? entry[OPENCODE_MCP_COMMAND_FIELD] : [entry[MCP_COMMAND_FIELD], ...list(entry[MCP_ARGS_FIELD])];
|
|
49122
|
+
const [node3, script, flag, agent] = cmd;
|
|
49123
|
+
return isNodeCommand(node3) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
49124
|
+
}
|
|
48994
49125
|
function opencodeListed(file2) {
|
|
48995
49126
|
const { value } = readParsed("opencode", file2);
|
|
48996
|
-
const
|
|
48997
|
-
|
|
49127
|
+
const bundle = opencodePluginFile();
|
|
49128
|
+
const own4 = [bundle, join11(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
49129
|
+
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own4)))) return true;
|
|
49130
|
+
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
49131
|
+
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
48998
49132
|
}
|
|
48999
49133
|
function mcpWrong(row5, home, env, worktree) {
|
|
49000
49134
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
@@ -49015,7 +49149,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
49015
49149
|
function hookFile(row5, spec, home, env, worktree) {
|
|
49016
49150
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
49017
49151
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
49018
|
-
const file2 = native !== null ?
|
|
49152
|
+
const file2 = native !== null ? join11(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join11(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join11(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join11(kiroDirOf(env, home), ...spec.file.slice(1)) : join11(root, ...spec.file);
|
|
49019
49153
|
return file2;
|
|
49020
49154
|
}
|
|
49021
49155
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -49026,7 +49160,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
49026
49160
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
49027
49161
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
49028
49162
|
if (row5.id === "codex") {
|
|
49029
|
-
const config4 = readParsed(row5.id,
|
|
49163
|
+
const config4 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
49030
49164
|
if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
49031
49165
|
}
|
|
49032
49166
|
} catch {
|
|
@@ -49070,7 +49204,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
49070
49204
|
function checkPiInstall(env, home, worktree) {
|
|
49071
49205
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
49072
49206
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
49073
|
-
return fail("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
49207
|
+
return fail("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join11(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
49074
49208
|
}
|
|
49075
49209
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
49076
49210
|
const findings = detectV1(agent, home, scope);
|
|
@@ -49089,10 +49223,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
49089
49223
|
}
|
|
49090
49224
|
function checkDoubleFire(agent, worktree) {
|
|
49091
49225
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
49092
|
-
const claude = parsedOrNull(agent,
|
|
49226
|
+
const claude = parsedOrNull(agent, join11(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
49093
49227
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
49094
49228
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
49095
|
-
const vscode = parsedOrNull(agent,
|
|
49229
|
+
const vscode = parsedOrNull(agent, join11(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
49096
49230
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
49097
49231
|
return hooksOn && useClaudeHooks ? fail("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
49098
49232
|
}
|
|
@@ -49103,7 +49237,7 @@ function configPaths(row5, env, worktree) {
|
|
|
49103
49237
|
const mcp = mcpFile(row5, home, env);
|
|
49104
49238
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
49105
49239
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
49106
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
49240
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join11(native, CODEX_PLUGIN_MCP_FILE) });
|
|
49107
49241
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
49108
49242
|
if (spec !== null) {
|
|
49109
49243
|
try {
|
|
@@ -49143,7 +49277,7 @@ async function loadSqlite2() {
|
|
|
49143
49277
|
}
|
|
49144
49278
|
}
|
|
49145
49279
|
function openRead(sqlite, path8) {
|
|
49146
|
-
return
|
|
49280
|
+
return openReadOnlyHandle(sqlite, path8);
|
|
49147
49281
|
}
|
|
49148
49282
|
var cell = (row5) => Object.values(row5)[0];
|
|
49149
49283
|
function readSchema(raw) {
|
|
@@ -49217,7 +49351,7 @@ async function checkIndex(project) {
|
|
|
49217
49351
|
|
|
49218
49352
|
// src/core/ops/doctor-env.ts
|
|
49219
49353
|
import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync6 } from "node:fs";
|
|
49220
|
-
import { isAbsolute as isAbsolute2, join as
|
|
49354
|
+
import { isAbsolute as isAbsolute2, join as join12, relative as relative2 } from "node:path";
|
|
49221
49355
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
49222
49356
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
49223
49357
|
}
|
|
@@ -49229,7 +49363,7 @@ function fail3(id, detail, fixCommand) {
|
|
|
49229
49363
|
}
|
|
49230
49364
|
function bundleVersion(bundleDir2) {
|
|
49231
49365
|
try {
|
|
49232
|
-
const v = JSON.parse(readFileSync8(
|
|
49366
|
+
const v = JSON.parse(readFileSync8(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
49233
49367
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
49234
49368
|
} catch {
|
|
49235
49369
|
return void 0;
|
|
@@ -49324,12 +49458,12 @@ async function checkVersion(i) {
|
|
|
49324
49458
|
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
49325
49459
|
if (i.version === void 0) return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
49326
49460
|
const tag = channelOf(i.version);
|
|
49327
|
-
const
|
|
49461
|
+
const git2 = findRuntime(GIT_BIN, i.env);
|
|
49328
49462
|
const npm = await npmLatest(i.registryUrl, tag, i.signal, i.timeoutMs);
|
|
49329
49463
|
if (npm.ok) return versionRow(head, i.version, tag, D1_SOURCE_NPM, npm.version, "");
|
|
49330
49464
|
let cause = D1_GIT_MISSING;
|
|
49331
|
-
if (
|
|
49332
|
-
const r = await runProcess([
|
|
49465
|
+
if (git2 !== null) {
|
|
49466
|
+
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
49333
49467
|
cwd: i.cwd,
|
|
49334
49468
|
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
49335
49469
|
signal: i.signal,
|
|
@@ -49343,7 +49477,7 @@ async function checkVersion(i) {
|
|
|
49343
49477
|
cause = gitCause(r, i.timeoutMs);
|
|
49344
49478
|
}
|
|
49345
49479
|
}
|
|
49346
|
-
return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause,
|
|
49480
|
+
return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
49347
49481
|
}
|
|
49348
49482
|
function numbers(v) {
|
|
49349
49483
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -49380,7 +49514,7 @@ function checkMcp(ctx) {
|
|
|
49380
49514
|
}
|
|
49381
49515
|
function piCwdInside(worktree, piCwd) {
|
|
49382
49516
|
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
49383
|
-
const rel =
|
|
49517
|
+
const rel = relative2(worktree, realpathSync6.native(piCwd));
|
|
49384
49518
|
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
49385
49519
|
}
|
|
49386
49520
|
function checkProject(i) {
|
|
@@ -49404,6 +49538,15 @@ import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync9,
|
|
|
49404
49538
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49405
49539
|
import path7 from "node:path";
|
|
49406
49540
|
|
|
49541
|
+
// src/core/sandbox/host-node.ts
|
|
49542
|
+
var BUN_BE_BUN_ENV = "BUN_BE_BUN";
|
|
49543
|
+
function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.execPath }, find2 = findRuntime) {
|
|
49544
|
+
if (host.bun === void 0) return { file: host.execPath, env };
|
|
49545
|
+
const node3 = find2("javascript", env);
|
|
49546
|
+
if (node3 !== null) return { file: node3, env };
|
|
49547
|
+
return { file: host.execPath, env: { ...env, [BUN_BE_BUN_ENV]: "1" } };
|
|
49548
|
+
}
|
|
49549
|
+
|
|
49407
49550
|
// src/setup/codex-trust.ts
|
|
49408
49551
|
import { createHash } from "node:crypto";
|
|
49409
49552
|
import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
|
|
@@ -49610,8 +49753,8 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
49610
49753
|
if (!bad.length) return void 0;
|
|
49611
49754
|
const counts = /* @__PURE__ */ new Map();
|
|
49612
49755
|
for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
|
|
49613
|
-
const
|
|
49614
|
-
const state =
|
|
49756
|
+
const words2 = [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1));
|
|
49757
|
+
const state = words2.length === 1 ? words2[0][0] : `${words2.map(([w]) => w).join(" or ")} (${words2.map(([w, n]) => `${n} ${w}`).join(", ")})`;
|
|
49615
49758
|
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
49616
49759
|
}
|
|
49617
49760
|
|
|
@@ -49692,7 +49835,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
|
49692
49835
|
}
|
|
49693
49836
|
}
|
|
49694
49837
|
var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
|
|
49695
|
-
function readProbePayload(cwd) {
|
|
49838
|
+
function readProbePayload(cwd, ranged) {
|
|
49696
49839
|
const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
|
|
49697
49840
|
const filePath = path7.join(cwd, "d5-read-probe.txt");
|
|
49698
49841
|
return {
|
|
@@ -49702,7 +49845,7 @@ function readProbePayload(cwd) {
|
|
|
49702
49845
|
hook_event_name: "PostToolUse",
|
|
49703
49846
|
tool_name: "Read",
|
|
49704
49847
|
tool_use_id: "toolu_d5_read_probe",
|
|
49705
|
-
tool_input: { file_path: filePath },
|
|
49848
|
+
tool_input: ranged ? { file_path: filePath, offset: 1, limit: READ_PROBE_LINES } : { file_path: filePath },
|
|
49706
49849
|
tool_response: { type: "text", file: { filePath, content, numLines: READ_PROBE_LINES, startLine: 1, totalLines: READ_PROBE_LINES } }
|
|
49707
49850
|
};
|
|
49708
49851
|
}
|
|
@@ -49720,21 +49863,37 @@ function isReadShape(stdout) {
|
|
|
49720
49863
|
const f = r.file;
|
|
49721
49864
|
return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
|
|
49722
49865
|
}
|
|
49723
|
-
async function
|
|
49866
|
+
async function readProbe(i, timeoutMs, ranged) {
|
|
49724
49867
|
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
49725
49868
|
try {
|
|
49726
|
-
const
|
|
49869
|
+
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home });
|
|
49870
|
+
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
49727
49871
|
cwd: i.bundleDir,
|
|
49728
|
-
env:
|
|
49872
|
+
env: node3.env,
|
|
49729
49873
|
signal: i.signal,
|
|
49730
49874
|
timeoutMs,
|
|
49731
|
-
stdin: JSON.stringify(readProbePayload(i.worktree ?? home))
|
|
49875
|
+
stdin: JSON.stringify(readProbePayload(i.worktree ?? home, ranged))
|
|
49732
49876
|
});
|
|
49733
|
-
return
|
|
49877
|
+
return r.stdout.toString("utf8");
|
|
49734
49878
|
} finally {
|
|
49735
49879
|
rmSync4(home, { recursive: true, force: true });
|
|
49736
49880
|
}
|
|
49737
49881
|
}
|
|
49882
|
+
function isPassThrough(stdout) {
|
|
49883
|
+
if (stdout.trim() === "") return true;
|
|
49884
|
+
let out;
|
|
49885
|
+
try {
|
|
49886
|
+
out = JSON.parse(stdout);
|
|
49887
|
+
} catch {
|
|
49888
|
+
return false;
|
|
49889
|
+
}
|
|
49890
|
+
return !isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput");
|
|
49891
|
+
}
|
|
49892
|
+
async function readProbeDetail(i, timeoutMs) {
|
|
49893
|
+
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
49894
|
+
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
49895
|
+
return null;
|
|
49896
|
+
}
|
|
49738
49897
|
function codexHookJournaled(db) {
|
|
49739
49898
|
if (db === null) return false;
|
|
49740
49899
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -49780,7 +49939,8 @@ async function checkHookRoundTrip(i) {
|
|
|
49780
49939
|
const timeoutMs = i.timeoutMs ?? HOOK_TIMEOUT_MS;
|
|
49781
49940
|
const bareMs = i.bareMs ?? (async () => {
|
|
49782
49941
|
const t = performance.now();
|
|
49783
|
-
|
|
49942
|
+
const node3 = nodeLaunch(i.env);
|
|
49943
|
+
await runProcess([node3.file, "-e", ""], { cwd: i.bundleDir, env: node3.env, signal: i.signal, timeoutMs });
|
|
49784
49944
|
return performance.now() - t;
|
|
49785
49945
|
});
|
|
49786
49946
|
const hookWalls = [];
|
|
@@ -49788,9 +49948,10 @@ async function checkHookRoundTrip(i) {
|
|
|
49788
49948
|
let ms = 0;
|
|
49789
49949
|
for (let n = 1; n <= maxPairs; n++) {
|
|
49790
49950
|
const start = now();
|
|
49791
|
-
const
|
|
49951
|
+
const node3 = nodeLaunch(i.env);
|
|
49952
|
+
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
49792
49953
|
cwd: i.bundleDir,
|
|
49793
|
-
env:
|
|
49954
|
+
env: node3.env,
|
|
49794
49955
|
signal: i.signal,
|
|
49795
49956
|
timeoutMs,
|
|
49796
49957
|
stdin: JSON.stringify(payloadFor(i.agent, fixture.payload, i.worktree))
|
|
@@ -49802,19 +49963,22 @@ async function checkHookRoundTrip(i) {
|
|
|
49802
49963
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
49803
49964
|
}
|
|
49804
49965
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
49805
|
-
|
|
49966
|
+
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : null;
|
|
49967
|
+
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
49806
49968
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
49807
49969
|
}
|
|
49808
49970
|
|
|
49809
49971
|
// src/core/hooks/fallback.ts
|
|
49810
|
-
import { join as
|
|
49972
|
+
import { join as join13, resolve as resolve3 } from "node:path";
|
|
49811
49973
|
var fs = process.getBuiltinModule("node:fs");
|
|
49812
49974
|
function homeOf(env) {
|
|
49813
49975
|
return env.HOME ?? env.USERPROFILE ?? "";
|
|
49814
49976
|
}
|
|
49815
49977
|
function hookLogPath(env) {
|
|
49978
|
+
const dir = env[DATA_DIR_ENV];
|
|
49979
|
+
if (dir !== void 0 && dir !== "") return join13(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
49816
49980
|
const home = homeOf(env);
|
|
49817
|
-
return home === "" ? "" :
|
|
49981
|
+
return home === "" ? "" : join13(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
49818
49982
|
}
|
|
49819
49983
|
function lastHookError(env) {
|
|
49820
49984
|
try {
|
|
@@ -49845,7 +50009,7 @@ function lastHookError(env) {
|
|
|
49845
50009
|
|
|
49846
50010
|
// src/core/ops/db-heal.ts
|
|
49847
50011
|
import { existsSync as existsSync14, mkdirSync as mkdirSync5, rmSync as rmSync5 } from "node:fs";
|
|
49848
|
-
import { basename as basename4, dirname as dirname7, join as
|
|
50012
|
+
import { basename as basename4, dirname as dirname7, join as join14 } from "node:path";
|
|
49849
50013
|
function integrityOk2(rows) {
|
|
49850
50014
|
return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
|
|
49851
50015
|
}
|
|
@@ -49854,7 +50018,7 @@ async function healLossless(dbPath) {
|
|
|
49854
50018
|
const tmp = dbPath + HEAL_TMP_SUFFIX;
|
|
49855
50019
|
rmSync5(tmp, { force: true });
|
|
49856
50020
|
try {
|
|
49857
|
-
const src =
|
|
50021
|
+
const src = openReadOnlyHandle({ DatabaseSync }, dbPath, { queryOnly: false });
|
|
49858
50022
|
try {
|
|
49859
50023
|
src.prepare("VACUUM INTO ?").run(tmp);
|
|
49860
50024
|
} finally {
|
|
@@ -49902,7 +50066,7 @@ function utcStamp(now) {
|
|
|
49902
50066
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
49903
50067
|
}
|
|
49904
50068
|
function makeOrphanDir(projectDir) {
|
|
49905
|
-
const base =
|
|
50069
|
+
const base = join14(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
49906
50070
|
for (let n = 1; ; n += 1) {
|
|
49907
50071
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
49908
50072
|
try {
|
|
@@ -49919,7 +50083,7 @@ async function healOrphan(project, files, row5) {
|
|
|
49919
50083
|
try {
|
|
49920
50084
|
dir = makeOrphanDir(dirname7(project.dbPath));
|
|
49921
50085
|
for (const f of files) {
|
|
49922
|
-
const to =
|
|
50086
|
+
const to = join14(dir, basename4(f.path));
|
|
49923
50087
|
renameWithRetry(f.path, to);
|
|
49924
50088
|
moved.push({ path: to, bytes: f.bytes });
|
|
49925
50089
|
}
|
|
@@ -49987,7 +50151,7 @@ function buildReportHead(input) {
|
|
|
49987
50151
|
// src/core/ops/doctor-issue.ts
|
|
49988
50152
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
49989
50153
|
import { closeSync, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync10, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49990
|
-
import { delimiter, join as
|
|
50154
|
+
import { delimiter, join as join15 } from "node:path";
|
|
49991
50155
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
49992
50156
|
function tildeOf(env) {
|
|
49993
50157
|
const home = homeDirOf(env);
|
|
@@ -50028,8 +50192,8 @@ function onPath(env, tool) {
|
|
|
50028
50192
|
const out = [];
|
|
50029
50193
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
50030
50194
|
if (dir === "") continue;
|
|
50031
|
-
for (const n of names) if (existsSync15(
|
|
50032
|
-
out.push(
|
|
50195
|
+
for (const n of names) if (existsSync15(join15(dir, n))) {
|
|
50196
|
+
out.push(join15(dir, n));
|
|
50033
50197
|
break;
|
|
50034
50198
|
}
|
|
50035
50199
|
}
|
|
@@ -50075,8 +50239,8 @@ function agentConfig(adapter, env, worktree) {
|
|
|
50075
50239
|
const home = homeDirOf(env);
|
|
50076
50240
|
const files = configPaths(adapter, env, worktree);
|
|
50077
50241
|
if (home !== null) {
|
|
50078
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
50079
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
50242
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join15(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
50243
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join15(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
50080
50244
|
}
|
|
50081
50245
|
const out = [];
|
|
50082
50246
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -50159,9 +50323,9 @@ async function buildIssueBody(i) {
|
|
|
50159
50323
|
async function writeIssueReport(i) {
|
|
50160
50324
|
const tilde = tildeOf(i.env);
|
|
50161
50325
|
const body = await buildIssueBody(i);
|
|
50162
|
-
const dir =
|
|
50326
|
+
const dir = join15(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
50163
50327
|
mkdirSync6(dir, { recursive: true });
|
|
50164
|
-
const file2 =
|
|
50328
|
+
const file2 = join15(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
50165
50329
|
writeFileSync3(file2, body);
|
|
50166
50330
|
const shown2 = tilde(file2);
|
|
50167
50331
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -50237,11 +50401,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
50237
50401
|
}
|
|
50238
50402
|
}
|
|
50239
50403
|
function ownServerId(configDir, projectKey) {
|
|
50240
|
-
const dir =
|
|
50404
|
+
const dir = join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
50241
50405
|
if (!existsSync16(dir)) return "";
|
|
50242
50406
|
for (const name of readdirSync7(dir)) {
|
|
50243
50407
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
50244
|
-
if (readFileSync11(
|
|
50408
|
+
if (readFileSync11(join16(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
50245
50409
|
}
|
|
50246
50410
|
return "";
|
|
50247
50411
|
}
|
|
@@ -50255,7 +50419,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
50255
50419
|
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 }),
|
|
50256
50420
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
50257
50421
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
50258
|
-
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)) }),
|
|
50422
|
+
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)) }),
|
|
50259
50423
|
D5: () => hookRow(ctx, adapter, host),
|
|
50260
50424
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
50261
50425
|
D6: () => checkMcp(ctx),
|
|
@@ -50296,13 +50460,13 @@ function reportEnv(env) {
|
|
|
50296
50460
|
async function doctorReply(ctx, host) {
|
|
50297
50461
|
const adapter = getAdapter(ctx.project.agent);
|
|
50298
50462
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
50299
|
-
const
|
|
50300
|
-
const command = adapter.id === "pi" ?
|
|
50463
|
+
const failed = rows.some((r) => r.status === "FAIL");
|
|
50464
|
+
const command = adapter.id === "pi" ? failed ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
50301
50465
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
50302
50466
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
50303
50467
|
const table3 = buildReport(input);
|
|
50304
50468
|
let notes = [];
|
|
50305
|
-
if (
|
|
50469
|
+
if (failed) {
|
|
50306
50470
|
try {
|
|
50307
50471
|
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
50308
50472
|
} catch (err) {
|
|
@@ -50338,7 +50502,7 @@ var ctxDoctor = Object.freeze({
|
|
|
50338
50502
|
// src/core/tools/execute.ts
|
|
50339
50503
|
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
50340
50504
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
50341
|
-
import { dirname as dirname9, join as
|
|
50505
|
+
import { dirname as dirname9, join as join17, parse as parse5, resolve as resolve4 } from "node:path";
|
|
50342
50506
|
|
|
50343
50507
|
// src/core/index/select.ts
|
|
50344
50508
|
var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
|
|
@@ -50423,7 +50587,6 @@ var ctxExecuteSchema = external_exports.object({
|
|
|
50423
50587
|
background: external_exports.boolean().optional(),
|
|
50424
50588
|
summary: external_exports.boolean().optional()
|
|
50425
50589
|
}, { error: unknownField }).strict();
|
|
50426
|
-
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
50427
50590
|
var SCRIPT_EXT = Object.freeze({
|
|
50428
50591
|
javascript: ".js",
|
|
50429
50592
|
typescript: ".ts",
|
|
@@ -50442,7 +50605,7 @@ var LAUNCHER = [
|
|
|
50442
50605
|
'const { rmSync } = require("node:fs");',
|
|
50443
50606
|
"const [mode, dir, ...argv] = process.argv.slice(1);",
|
|
50444
50607
|
'if (mode === "start") {',
|
|
50445
|
-
' const b = spawn(process.execPath, [...process.execArgv, "--", "run", dir, ...argv], { detached: true, stdio: "ignore", windowsHide: true });',
|
|
50608
|
+
' const b = spawn(process.execPath, [...process.execArgv.filter((a) => a !== "--"), "--", "run", dir, ...argv], { detached: true, stdio: "ignore", windowsHide: true });',
|
|
50446
50609
|
" b.unref();",
|
|
50447
50610
|
" process.stdout.write(String(b.pid));",
|
|
50448
50611
|
"} else {",
|
|
@@ -50542,13 +50705,14 @@ async function handler3(raw, ctx) {
|
|
|
50542
50705
|
if (takesDashC(input.language, runtime)) {
|
|
50543
50706
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
50544
50707
|
} else {
|
|
50545
|
-
tmpDir = mkdtempSync2(
|
|
50546
|
-
const file2 =
|
|
50708
|
+
tmpDir = mkdtempSync2(join17(tmpdir3(), TMP_PREFIX));
|
|
50709
|
+
const file2 = join17(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
50547
50710
|
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
50548
50711
|
argv = scriptArgv(input.language, runtime, file2);
|
|
50549
50712
|
}
|
|
50550
50713
|
if (input.background === true) {
|
|
50551
|
-
const
|
|
50714
|
+
const node3 = nodeLaunch(env);
|
|
50715
|
+
const r2 = await runProcess([node3.file, "-e", LAUNCHER, "--", "start", tmpDir ?? "", ...argv], { cwd, env: node3.env, signal: ctx.signal, timeoutMs });
|
|
50552
50716
|
const pid = r2.stdout.toString("utf8");
|
|
50553
50717
|
if (r2.exitCode !== 0 || pid === "" || !Number.isSafeInteger(Number(pid))) return fail4(spawnFailed(argv[0], cwd), journal);
|
|
50554
50718
|
handedOff = true;
|
|
@@ -50579,11 +50743,11 @@ var ctxExecute = {
|
|
|
50579
50743
|
|
|
50580
50744
|
// src/core/tools/index.ts
|
|
50581
50745
|
import { existsSync as existsSync18, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
|
|
50582
|
-
import { dirname as dirname10, extname, join as
|
|
50746
|
+
import { dirname as dirname10, extname, join as join19, relative as relative3, resolve as resolve5 } from "node:path";
|
|
50583
50747
|
|
|
50584
50748
|
// src/core/index/walk.ts
|
|
50585
50749
|
import { readdirSync as readdirSync8, readFileSync as readFileSync12, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
|
|
50586
|
-
import { join as
|
|
50750
|
+
import { join as join18 } from "node:path";
|
|
50587
50751
|
var GITIGNORE = ".gitignore";
|
|
50588
50752
|
var GIT_DIR = ".git";
|
|
50589
50753
|
function walkDir(root, containmentRoot) {
|
|
@@ -50592,7 +50756,7 @@ function walkDir(root, containmentRoot) {
|
|
|
50592
50756
|
const found = [];
|
|
50593
50757
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
50594
50758
|
found.sort(compareFound);
|
|
50595
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
50759
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join18(...f.dir, f.name) }));
|
|
50596
50760
|
}
|
|
50597
50761
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
50598
50762
|
let entries;
|
|
@@ -50601,10 +50765,10 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
50601
50765
|
} catch {
|
|
50602
50766
|
return;
|
|
50603
50767
|
}
|
|
50604
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
50768
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join18(abs, GITIGNORE), rel)) : parent;
|
|
50605
50769
|
for (const e of entries) {
|
|
50606
50770
|
if (e.name === GIT_DIR) continue;
|
|
50607
|
-
const path8 =
|
|
50771
|
+
const path8 = join18(abs, e.name);
|
|
50608
50772
|
let isDir = e.isDirectory();
|
|
50609
50773
|
let isFile = e.isFile();
|
|
50610
50774
|
let target = path8;
|
|
@@ -50738,11 +50902,24 @@ var PRIVATE_RANGES = [
|
|
|
50738
50902
|
["172.16.0.0", 12, "ipv4"],
|
|
50739
50903
|
["192.168.0.0", 16, "ipv4"],
|
|
50740
50904
|
["169.254.0.0", 16, "ipv4"],
|
|
50741
|
-
["0.0.0.0",
|
|
50905
|
+
["0.0.0.0", 8, "ipv4"],
|
|
50906
|
+
// D-SSRF-RANGES-1: "this network", not only 0.0.0.0
|
|
50907
|
+
["100.64.0.0", 10, "ipv4"],
|
|
50908
|
+
// D-SSRF-RANGES-1: shared address space (RFC 6598), cloud metadata lives here
|
|
50909
|
+
["198.18.0.0", 15, "ipv4"],
|
|
50910
|
+
// D-SSRF-RANGES-1: benchmark networks (RFC 2544)
|
|
50911
|
+
["240.0.0.0", 4, "ipv4"],
|
|
50912
|
+
// D-SSRF-RANGES-1: reserved and broadcast
|
|
50742
50913
|
["::1", 128, "ipv6"],
|
|
50743
50914
|
["::", 128, "ipv6"],
|
|
50915
|
+
["::", 96, "ipv6"],
|
|
50916
|
+
// D-SSRF-RANGES-1: IPv4-compatible (::a.b.c.d), deprecated, never a public origin
|
|
50917
|
+
["64:ff9b:1::", 48, "ipv6"],
|
|
50918
|
+
// D-SSRF-RANGES-1: local-use NAT64 (RFC 8215)
|
|
50744
50919
|
["fc00::", 7, "ipv6"],
|
|
50745
|
-
["fe80::", 10, "ipv6"]
|
|
50920
|
+
["fe80::", 10, "ipv6"],
|
|
50921
|
+
["fec0::", 10, "ipv6"]
|
|
50922
|
+
// D-SSRF-RANGES-1: site-local (RFC 3879)
|
|
50746
50923
|
];
|
|
50747
50924
|
var BLOCKED = new BlockList();
|
|
50748
50925
|
for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix, type);
|
|
@@ -50795,9 +50972,41 @@ function pickProxy(u) {
|
|
|
50795
50972
|
const auth = p.username === "" ? void 0 : "Basic " + Buffer.from(decodeURIComponent(p.username) + ":" + decodeURIComponent(p.password)).toString("base64");
|
|
50796
50973
|
return { url: p, auth };
|
|
50797
50974
|
}
|
|
50975
|
+
function ipv6Words(address) {
|
|
50976
|
+
const zone = address.indexOf("%");
|
|
50977
|
+
const a = zone < 0 ? address : address.slice(0, zone);
|
|
50978
|
+
const words2 = (part) => {
|
|
50979
|
+
if (part === "") return [];
|
|
50980
|
+
const out = [];
|
|
50981
|
+
for (const w of part.split(":")) {
|
|
50982
|
+
if (w.includes(".")) {
|
|
50983
|
+
const q = w.split(".").map(Number);
|
|
50984
|
+
out.push(q[0] * 256 + q[1], q[2] * 256 + q[3]);
|
|
50985
|
+
} else out.push(parseInt(w, 16));
|
|
50986
|
+
}
|
|
50987
|
+
return out;
|
|
50988
|
+
};
|
|
50989
|
+
const gap = a.indexOf("::");
|
|
50990
|
+
if (gap < 0) return words2(a);
|
|
50991
|
+
const head = words2(a.slice(0, gap));
|
|
50992
|
+
const tail = words2(a.slice(gap + 2));
|
|
50993
|
+
return [...head, ...new Array(8 - head.length - tail.length).fill(0), ...tail];
|
|
50994
|
+
}
|
|
50995
|
+
function dotted(hi, lo) {
|
|
50996
|
+
return [hi >> 8, hi & 255, lo >> 8, lo & 255].join(".");
|
|
50997
|
+
}
|
|
50998
|
+
function embeddedIpv4(address) {
|
|
50999
|
+
const w = ipv6Words(address);
|
|
51000
|
+
if (w[0] === 100 && w[1] === 65435 && w[2] === 0 && w[3] === 0 && w[4] === 0 && w[5] === 0) {
|
|
51001
|
+
return dotted(w[6], w[7]);
|
|
51002
|
+
}
|
|
51003
|
+
if (w[0] === 8194) return dotted(w[1], w[2]);
|
|
51004
|
+
return void 0;
|
|
51005
|
+
}
|
|
50798
51006
|
function checkAddress(hostname2, address) {
|
|
50799
51007
|
const family = isIP(address);
|
|
50800
|
-
|
|
51008
|
+
const inner = family === 6 ? embeddedIpv4(address) : void 0;
|
|
51009
|
+
if (family === 0 || BLOCKED.check(address, family === 4 ? "ipv4" : "ipv6") || inner !== void 0 && BLOCKED.check(inner, "ipv4")) {
|
|
50801
51010
|
throw new CtxError("SSRF", { host: hostname2 });
|
|
50802
51011
|
}
|
|
50803
51012
|
}
|
|
@@ -54123,11 +54332,11 @@ function compareDocumentPosition(nodeA, nodeB) {
|
|
|
54123
54332
|
function uniqueSort(nodes) {
|
|
54124
54333
|
nodes = nodes.filter((node3, index, array4) => !array4.includes(node3, index + 1));
|
|
54125
54334
|
nodes.sort((a, b) => {
|
|
54126
|
-
const
|
|
54127
|
-
if (
|
|
54335
|
+
const relative4 = compareDocumentPosition(a, b);
|
|
54336
|
+
if (relative4 & DocumentPosition.PRECEDING) {
|
|
54128
54337
|
return -1;
|
|
54129
54338
|
}
|
|
54130
|
-
if (
|
|
54339
|
+
if (relative4 & DocumentPosition.FOLLOWING) {
|
|
54131
54340
|
return 1;
|
|
54132
54341
|
}
|
|
54133
54342
|
return 0;
|
|
@@ -54696,10 +54905,10 @@ function htmlToReadable(html, baseUrl) {
|
|
|
54696
54905
|
const st = { w: new Writer(), base, sawH1: false };
|
|
54697
54906
|
for (const n of contentRoot(doc.children)) walk(st, n);
|
|
54698
54907
|
const body = st.w.result();
|
|
54699
|
-
const
|
|
54700
|
-
const text = !st.sawH1 && title !== "" &&
|
|
54701
|
-
const sparse =
|
|
54702
|
-
return { text: text === "" ? "" : text + "\n", title, words, sparse };
|
|
54908
|
+
const words2 = wordCount(body);
|
|
54909
|
+
const text = !st.sawH1 && title !== "" && words2 > 0 ? "# " + title + "\n\n" + body : body;
|
|
54910
|
+
const sparse = words2 < SPARSE_MAX_WORDS && html.length > SPARSE_RATIO * Math.max(text.length, 1);
|
|
54911
|
+
return { text: text === "" ? "" : text + "\n", title, words: words2, sparse };
|
|
54703
54912
|
}
|
|
54704
54913
|
|
|
54705
54914
|
// src/core/tools/index.ts
|
|
@@ -54741,11 +54950,11 @@ function missingOrOutside(given, abs, root) {
|
|
|
54741
54950
|
function pathItems(input, project) {
|
|
54742
54951
|
const abs = resolve5(project.worktree, input.path);
|
|
54743
54952
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
54744
|
-
const base =
|
|
54953
|
+
const base = relative3(project.worktree, abs);
|
|
54745
54954
|
if (statSync7(abs).isDirectory()) {
|
|
54746
54955
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
54747
54956
|
sourceKind: "path",
|
|
54748
|
-
label: pathLabel(
|
|
54957
|
+
label: pathLabel(join19(base, f.relPath)),
|
|
54749
54958
|
kind: kindOfPath(f.relPath),
|
|
54750
54959
|
read: () => readUtf8(f.absPath)
|
|
54751
54960
|
}));
|
|
@@ -55034,7 +55243,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
55034
55243
|
const pool = cands.filter((u) => !seen.has(unitKey(u)) && u.score >= RECALL_MIN_SCORE);
|
|
55035
55244
|
if (pool.length === 0) return [];
|
|
55036
55245
|
const top = Math.max(...pool.map((u) => u.score));
|
|
55037
|
-
const
|
|
55246
|
+
const words2 = pool.map((u) => wordsOf(u.body));
|
|
55038
55247
|
const taken = [];
|
|
55039
55248
|
const left = new Set(pool.map((_, i) => i));
|
|
55040
55249
|
let used = 0;
|
|
@@ -55043,7 +55252,7 @@ function pickUnits(cands, seen, budget) {
|
|
|
55043
55252
|
let bestVal = -Infinity;
|
|
55044
55253
|
for (const i of left) {
|
|
55045
55254
|
let sim = 0;
|
|
55046
|
-
for (const j of taken) sim = Math.max(sim, overlap(
|
|
55255
|
+
for (const j of taken) sim = Math.max(sim, overlap(words2[i], words2[j]));
|
|
55047
55256
|
const val = MMR_RELEVANCE_WEIGHT * (pool[i].score / top) - MMR_REDUNDANCY_WEIGHT * sim;
|
|
55048
55257
|
if (val > bestVal) {
|
|
55049
55258
|
bestVal = val;
|
|
@@ -55549,13 +55758,9 @@ var ctxStats = Object.freeze({
|
|
|
55549
55758
|
handler: handler7
|
|
55550
55759
|
});
|
|
55551
55760
|
|
|
55552
|
-
// src/core/tools/upgrade.ts
|
|
55553
|
-
import { existsSync as existsSync24, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
|
|
55554
|
-
import { basename as basename7, dirname as dirname12, join as join24 } from "node:path";
|
|
55555
|
-
|
|
55556
55761
|
// src/core/ops/host-write.ts
|
|
55557
55762
|
import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
55558
|
-
import { dirname as dirname11, join as
|
|
55763
|
+
import { dirname as dirname11, join as join20 } from "node:path";
|
|
55559
55764
|
function defaultWrite(file2, text) {
|
|
55560
55765
|
writeFileSync5(file2, text, "utf8");
|
|
55561
55766
|
}
|
|
@@ -55564,14 +55769,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
55564
55769
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
55565
55770
|
switch (agent) {
|
|
55566
55771
|
case "opencode":
|
|
55567
|
-
return
|
|
55772
|
+
return join20(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
55568
55773
|
// D-WIN-OPENCODE-DIR-1
|
|
55569
55774
|
case "pi":
|
|
55570
|
-
return
|
|
55775
|
+
return join20(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
55776
|
+
case "gemini":
|
|
55777
|
+
return join20(geminiDirOf(env, home), SETTINGS_FILE);
|
|
55778
|
+
// D-R38-GEMINI-HOME-1
|
|
55571
55779
|
case "copilot-cli":
|
|
55572
55780
|
return null;
|
|
55573
55781
|
default:
|
|
55574
|
-
return
|
|
55782
|
+
return join20(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
55575
55783
|
}
|
|
55576
55784
|
}
|
|
55577
55785
|
function cell3(value) {
|
|
@@ -55620,96 +55828,16 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
55620
55828
|
return result.edits.map((e) => toRow(current.path, e));
|
|
55621
55829
|
}
|
|
55622
55830
|
|
|
55623
|
-
// src/core/ops/plugin-swap.ts
|
|
55624
|
-
import { existsSync as existsSync20, lstatSync, readdirSync as readdirSync9, readlinkSync, rmSync as rmSync7, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
55625
|
-
import { basename as basename6, join as join20, win32 as win322 } from "node:path";
|
|
55626
|
-
function linkTarget(path8, win) {
|
|
55627
|
-
if (!isLink(path8)) return null;
|
|
55628
|
-
const target = readlinkSync(path8);
|
|
55629
|
-
return win ? win322.basename(target) : target;
|
|
55630
|
-
}
|
|
55631
|
-
function isLink(path8) {
|
|
55632
|
-
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
55633
|
-
}
|
|
55634
|
-
function generations(agentDir) {
|
|
55635
|
-
return readdirSync9(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();
|
|
55636
|
-
}
|
|
55637
|
-
function settleLinks(link, tmp, old, opts) {
|
|
55638
|
-
if (isLink(tmp)) unlinkSync2(tmp);
|
|
55639
|
-
if (!isLink(old)) return;
|
|
55640
|
-
if (isLink(link)) unlinkSync2(old);
|
|
55641
|
-
else renameWithRetry(old, link, opts);
|
|
55642
|
-
}
|
|
55643
|
-
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
55644
|
-
const next = join20(agentDir, sha);
|
|
55645
|
-
if (!existsSync20(next) || !lstatSync(next).isDirectory()) {
|
|
55646
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
55647
|
-
}
|
|
55648
|
-
const link = join20(agentDir, PLUGIN_CURRENT_LINK);
|
|
55649
|
-
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
55650
|
-
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
55651
|
-
settleLinks(link, tmp, old, opts);
|
|
55652
|
-
const win = (opts.platform ?? process.platform) === "win32";
|
|
55653
|
-
const before = linkTarget(link, win);
|
|
55654
|
-
if (before === sha) return { current: next, previous: null, removed: [] };
|
|
55655
|
-
const symlink = opts.symlink ?? symlinkSync;
|
|
55656
|
-
if (win) symlink(next, tmp, PLUGIN_LINK_TYPE_WIN32);
|
|
55657
|
-
else symlink(sha, tmp, PLUGIN_LINK_TYPE);
|
|
55658
|
-
if (before !== null) renameWithRetry(link, old, opts);
|
|
55659
|
-
renameWithRetry(tmp, link, opts);
|
|
55660
|
-
if (before !== null) unlinkSync2(old);
|
|
55661
|
-
const keep = /* @__PURE__ */ new Set([sha]);
|
|
55662
|
-
if (before !== null) keep.add(before);
|
|
55663
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join20(agentDir, name));
|
|
55664
|
-
for (const dir of removed) rmSync7(dir, { recursive: true, force: true });
|
|
55665
|
-
const previous = before !== null && existsSync20(join20(agentDir, before)) ? join20(agentDir, before) : null;
|
|
55666
|
-
return { current: next, previous, removed };
|
|
55667
|
-
}
|
|
55668
|
-
|
|
55669
|
-
// src/core/ops/release-fetch.ts
|
|
55670
|
-
import { existsSync as existsSync21, mkdirSync as mkdirSync8, rmSync as rmSync8 } from "node:fs";
|
|
55671
|
-
import { join as join21 } from "node:path";
|
|
55672
|
-
function failed(r) {
|
|
55673
|
-
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
55674
|
-
const status = r.killed ?? String(r.exitCode);
|
|
55675
|
-
return new CtxError("FETCH_FAILED", { code: GIT_EXIT_LABEL + status + UPGRADE_AREA_KEY_SEP + r.stderr.toString().trim() });
|
|
55676
|
-
}
|
|
55677
|
-
async function git2(bin, args, cwd, env, signal) {
|
|
55678
|
-
const r = await runProcess([bin, ...args], { cwd, env, signal, timeoutMs: UPGRADE_GIT_TIMEOUT_MS });
|
|
55679
|
-
if (r.exitCode !== 0 || r.killed !== null) throw failed(r);
|
|
55680
|
-
return r.stdout.toString().trim();
|
|
55681
|
-
}
|
|
55682
|
-
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
55683
|
-
const agentDir = join21(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
55684
|
-
mkdirSync8(agentDir, { recursive: true });
|
|
55685
|
-
const fetchDir = join21(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
55686
|
-
rmSync8(fetchDir, { recursive: true, force: true });
|
|
55687
|
-
const gitBin = findRuntime(GIT_BIN, env);
|
|
55688
|
-
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
55689
|
-
const childEnv = buildChildEnv(env, { ...GIT_NO_PROMPT_ENV, ...GIT_NO_CRLF_ENV });
|
|
55690
|
-
try {
|
|
55691
|
-
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
55692
|
-
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
55693
|
-
const dir = join21(agentDir, sha);
|
|
55694
|
-
if (existsSync21(dir)) rmSync8(fetchDir, { recursive: true, force: true });
|
|
55695
|
-
else renameWithRetry(fetchDir, dir, opts);
|
|
55696
|
-
return { sha, dir };
|
|
55697
|
-
} catch (e) {
|
|
55698
|
-
rmSync8(fetchDir, { recursive: true, force: true });
|
|
55699
|
-
throw e;
|
|
55700
|
-
}
|
|
55701
|
-
}
|
|
55702
|
-
|
|
55703
55831
|
// src/core/ops/uninstall.ts
|
|
55704
|
-
import { existsSync as
|
|
55705
|
-
import { join as
|
|
55832
|
+
import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
|
|
55833
|
+
import { join as join21 } from "node:path";
|
|
55706
55834
|
function row2(area, before, after) {
|
|
55707
55835
|
return { area, before, after };
|
|
55708
55836
|
}
|
|
55709
55837
|
function stopServers(configDir, projectKey) {
|
|
55710
55838
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
55711
|
-
const dir =
|
|
55712
|
-
for (const serverId of stopped) writeFileSync6(
|
|
55839
|
+
const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
55840
|
+
for (const serverId of stopped) writeFileSync6(join21(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
55713
55841
|
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 };
|
|
55714
55842
|
}
|
|
55715
55843
|
function rootOrNull(adapter, env) {
|
|
@@ -55727,16 +55855,16 @@ function removeCache(adapter, env, configDir) {
|
|
|
55727
55855
|
const root = rootOrNull(adapter, env);
|
|
55728
55856
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
55729
55857
|
if (adapter.installMode === "marketplace") {
|
|
55730
|
-
const cache =
|
|
55858
|
+
const cache = join21(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
55731
55859
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
55732
55860
|
}
|
|
55733
|
-
|
|
55861
|
+
rmSync7(root, { recursive: true, force: true });
|
|
55734
55862
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
55735
55863
|
}
|
|
55736
55864
|
case "plugin": {
|
|
55737
|
-
const agentDir =
|
|
55738
|
-
if (!
|
|
55739
|
-
|
|
55865
|
+
const agentDir = join21(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
55866
|
+
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
55867
|
+
rmSync7(agentDir, { recursive: true, force: true });
|
|
55740
55868
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
55741
55869
|
}
|
|
55742
55870
|
case "config-mcp":
|
|
@@ -55751,7 +55879,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
55751
55879
|
function isObj3(v) {
|
|
55752
55880
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
55753
55881
|
}
|
|
55754
|
-
function
|
|
55882
|
+
function piSource2(entry) {
|
|
55755
55883
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
55756
55884
|
}
|
|
55757
55885
|
function ownEntries2(agent, env) {
|
|
@@ -55780,7 +55908,7 @@ function ownEntries2(agent, env) {
|
|
|
55780
55908
|
}
|
|
55781
55909
|
if (agent === "opencode") {
|
|
55782
55910
|
return [{
|
|
55783
|
-
file:
|
|
55911
|
+
file: join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
55784
55912
|
// D-WIN-OPENCODE-DIR-1
|
|
55785
55913
|
key: OPENCODE_PLUGIN_KEY,
|
|
55786
55914
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -55791,11 +55919,11 @@ function ownEntries2(agent, env) {
|
|
|
55791
55919
|
if (agent === "pi") {
|
|
55792
55920
|
const agentDir = piAgentDirOf(env, home);
|
|
55793
55921
|
return [{
|
|
55794
|
-
file:
|
|
55922
|
+
file: join21(agentDir, SETTINGS_FILE),
|
|
55795
55923
|
key: PI_PACKAGES_KEY,
|
|
55796
55924
|
shown: PI_PACKAGES_KEY,
|
|
55797
|
-
has: (v) => Array.isArray(v) && v.some((x) =>
|
|
55798
|
-
drop: (v) => v.filter((x) =>
|
|
55925
|
+
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
55926
|
+
drop: (v) => v.filter((x) => piSource2(x) !== PI_GIT_PACKAGE)
|
|
55799
55927
|
}];
|
|
55800
55928
|
}
|
|
55801
55929
|
return [];
|
|
@@ -55813,12 +55941,12 @@ function removeOwnEntries(agent, env) {
|
|
|
55813
55941
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
55814
55942
|
}
|
|
55815
55943
|
function removeProjectData(configDir, projectKey) {
|
|
55816
|
-
const projects =
|
|
55817
|
-
const dir =
|
|
55818
|
-
if (!
|
|
55944
|
+
const projects = join21(configDir, PROJECTS_DIR_NAME);
|
|
55945
|
+
const dir = join21(projects, projectKey);
|
|
55946
|
+
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
55819
55947
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
55820
|
-
for (const name of
|
|
55821
|
-
if (name !== OWNERS_DIR_NAME)
|
|
55948
|
+
for (const name of readdirSync9(dir)) {
|
|
55949
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join21(dir, name), { recursive: true, force: true });
|
|
55822
55950
|
}
|
|
55823
55951
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
55824
55952
|
}
|
|
@@ -55826,25 +55954,32 @@ function runUninstall(input) {
|
|
|
55826
55954
|
const configDir = resolveConfigDir(input.env);
|
|
55827
55955
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
55828
55956
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
55829
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
55957
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join21(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
55830
55958
|
return { rows, stopped: stop.stopped };
|
|
55831
55959
|
}
|
|
55832
55960
|
|
|
55833
55961
|
// src/core/ops/v1-remove.ts
|
|
55834
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
55962
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
|
|
55835
55963
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
55836
55964
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
55837
55965
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
55838
55966
|
function moveAside(target, undo) {
|
|
55839
55967
|
const trash = target + UPGRADE_TRASH_SUFFIX;
|
|
55840
|
-
|
|
55968
|
+
rmSync8(trash, { recursive: true, force: true });
|
|
55841
55969
|
renameWithRetry(target, trash);
|
|
55842
55970
|
undo.push({ trash, target });
|
|
55843
55971
|
}
|
|
55972
|
+
function keepAside(target, undo) {
|
|
55973
|
+
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
55974
|
+
for (let n = 2; existsSync21(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
55975
|
+
renameWithRetry(target, aside);
|
|
55976
|
+
undo.push({ trash: aside, target, keep: true });
|
|
55977
|
+
return aside;
|
|
55978
|
+
}
|
|
55844
55979
|
function keepOriginal(file2, kept, undo) {
|
|
55845
55980
|
if (kept.has(file2)) return;
|
|
55846
55981
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
55847
|
-
|
|
55982
|
+
rmSync8(trash, { recursive: true, force: true });
|
|
55848
55983
|
copyFileSync2(file2, trash);
|
|
55849
55984
|
kept.add(file2);
|
|
55850
55985
|
undo.push({ trash, target: file2 });
|
|
@@ -55904,7 +56039,7 @@ function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
|
55904
56039
|
writeHostConfigEdit(file2, { agent, text, format: "jsonc", path: file2, layout }, patch);
|
|
55905
56040
|
return hit;
|
|
55906
56041
|
}
|
|
55907
|
-
function removeV1(agent, findings) {
|
|
56042
|
+
function removeV1(agent, findings, project) {
|
|
55908
56043
|
const undo = [];
|
|
55909
56044
|
const kept = /* @__PURE__ */ new Set();
|
|
55910
56045
|
const done = /* @__PURE__ */ new Map();
|
|
@@ -55912,14 +56047,16 @@ function removeV1(agent, findings) {
|
|
|
55912
56047
|
for (const f of findings) {
|
|
55913
56048
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
55914
56049
|
else if (f.path === "") {
|
|
55915
|
-
if (
|
|
56050
|
+
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
56051
|
+
else if (existsSync21(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
56052
|
+
else if (existsSync21(f.file)) {
|
|
55916
56053
|
moveAside(f.file, undo);
|
|
55917
56054
|
done.set(f, UPGRADE_REMOVED);
|
|
55918
56055
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
55919
56056
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
55920
56057
|
}
|
|
55921
56058
|
for (const [file2, list3] of entries) {
|
|
55922
|
-
if (!
|
|
56059
|
+
if (!existsSync21(file2)) {
|
|
55923
56060
|
for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
|
|
55924
56061
|
continue;
|
|
55925
56062
|
}
|
|
@@ -55948,64 +56085,18 @@ function removeV1(agent, findings) {
|
|
|
55948
56085
|
return {
|
|
55949
56086
|
rows: findings.map((f) => row3(f, done.get(f) ?? UPGRADE_NOT_FOUND)),
|
|
55950
56087
|
commit() {
|
|
55951
|
-
for (const u of undo.splice(0))
|
|
56088
|
+
for (const u of undo.splice(0)) if (u.keep !== true) rmSync8(u.trash, { recursive: true, force: true });
|
|
55952
56089
|
},
|
|
55953
56090
|
rollback() {
|
|
55954
56091
|
for (const u of undo.splice(0).reverse()) {
|
|
55955
|
-
if (!
|
|
55956
|
-
|
|
56092
|
+
if (!existsSync21(u.trash)) continue;
|
|
56093
|
+
rmSync8(u.target, { recursive: true, force: true });
|
|
55957
56094
|
renameWithRetry(u.trash, u.target);
|
|
55958
56095
|
}
|
|
55959
56096
|
}
|
|
55960
56097
|
};
|
|
55961
56098
|
}
|
|
55962
56099
|
|
|
55963
|
-
// src/core/ops/verify-sums.ts
|
|
55964
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
55965
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync11, readFileSync as readFileSync15 } from "node:fs";
|
|
55966
|
-
import { join as join23 } from "node:path";
|
|
55967
|
-
function mismatch() {
|
|
55968
|
-
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
55969
|
-
}
|
|
55970
|
-
function parseSums(text) {
|
|
55971
|
-
const lines = text.split(SUMS_LINE_END);
|
|
55972
|
-
if (lines[lines.length - 1] === "") lines.pop();
|
|
55973
|
-
const sums = /* @__PURE__ */ new Map();
|
|
55974
|
-
for (const line of lines) {
|
|
55975
|
-
const at = line.indexOf(SUMS_LINE_SEP);
|
|
55976
|
-
if (at < 0) throw mismatch();
|
|
55977
|
-
const rel = line.slice(at + SUMS_LINE_SEP.length);
|
|
55978
|
-
if (rel === "" || sums.has(rel)) throw mismatch();
|
|
55979
|
-
sums.set(rel, line.slice(0, at));
|
|
55980
|
-
}
|
|
55981
|
-
return sums;
|
|
55982
|
-
}
|
|
55983
|
-
function walk2(dir, prefix, out) {
|
|
55984
|
-
for (const entry of readdirSync11(dir, { withFileTypes: true })) {
|
|
55985
|
-
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
55986
|
-
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
55987
|
-
const abs = join23(dir, entry.name);
|
|
55988
|
-
if (entry.isDirectory()) walk2(abs, rel, out);
|
|
55989
|
-
else if (entry.isFile()) out.set(rel, abs);
|
|
55990
|
-
else throw mismatch();
|
|
55991
|
-
}
|
|
55992
|
-
}
|
|
55993
|
-
function verifySums(dir) {
|
|
55994
|
-
const sumsPath = join23(dir, RELEASE_SUMS_FILE);
|
|
55995
|
-
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
55996
|
-
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
55997
|
-
const sums = parseSums(readFileSync15(sumsPath, "utf8"));
|
|
55998
|
-
const files = /* @__PURE__ */ new Map();
|
|
55999
|
-
walk2(dir, "", files);
|
|
56000
|
-
if (files.size !== sums.size) throw mismatch();
|
|
56001
|
-
for (const [rel, abs] of files) {
|
|
56002
|
-
const want = sums.get(rel);
|
|
56003
|
-
if (want === void 0) throw mismatch();
|
|
56004
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync15(abs)).digest(HASH_ENCODING);
|
|
56005
|
-
if (got !== want) throw mismatch();
|
|
56006
|
-
}
|
|
56007
|
-
}
|
|
56008
|
-
|
|
56009
56100
|
// src/core/tools/upgrade.ts
|
|
56010
56101
|
var ctxUpgradeSchema = external_exports.object({
|
|
56011
56102
|
mode: external_exports.enum(UPGRADE_MODES).optional(),
|
|
@@ -56028,41 +56119,20 @@ function pluginRootRow(adapter, env) {
|
|
|
56028
56119
|
}
|
|
56029
56120
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
56030
56121
|
}
|
|
56031
|
-
function isCurrent(agentDir, dir) {
|
|
56032
|
-
const link = join24(agentDir, PLUGIN_CURRENT_LINK);
|
|
56033
|
-
return existsSync24(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
56034
|
-
}
|
|
56035
|
-
async function checkout(adapter, deps) {
|
|
56036
|
-
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
56037
|
-
const agentDir = dirname12(fetched.dir);
|
|
56038
|
-
try {
|
|
56039
|
-
verifySums(fetched.dir);
|
|
56040
|
-
} catch (err) {
|
|
56041
|
-
if (!isCurrent(agentDir, fetched.dir)) rmSync11(fetched.dir, { recursive: true, force: true });
|
|
56042
|
-
throw err;
|
|
56043
|
-
}
|
|
56044
|
-
const swap = swapPluginCurrent(agentDir, fetched.sha);
|
|
56045
|
-
const rows = [row4(UPGRADE_CHECKOUT_AREA, swap.previous ?? "", swap.current)];
|
|
56046
|
-
for (const dir of swap.removed) rows.push(row4(UPGRADE_CACHE_AREA, dir, UPGRADE_REMOVED));
|
|
56047
|
-
return { rows, agentDir, swap };
|
|
56048
|
-
}
|
|
56049
56122
|
function hostRow(adapter) {
|
|
56050
|
-
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]
|
|
56123
|
+
return row4(UPGRADE_HOST_AREA, "", UPGRADE_HOST_COMMAND[adapter.id]);
|
|
56051
56124
|
}
|
|
56052
|
-
|
|
56053
|
-
let done = null;
|
|
56125
|
+
function upgrade(adapter, deps, home) {
|
|
56054
56126
|
let removal = null;
|
|
56055
56127
|
try {
|
|
56056
|
-
const step4 = UPGRADE_GIT_CHECKOUT_AGENTS.includes(adapter.id) ? (done = await checkout(adapter, deps)).rows : [hostRow(adapter)];
|
|
56057
56128
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
56058
|
-
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) });
|
|
56059
|
-
removal = removeV1(adapter.id, findings);
|
|
56060
|
-
const rows = [
|
|
56129
|
+
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) });
|
|
56130
|
+
removal = removeV1(adapter.id, findings, deps.project.worktree);
|
|
56131
|
+
const rows = [hostRow(adapter), ...step5, ...removal.rows];
|
|
56061
56132
|
removal.commit();
|
|
56062
56133
|
return rows;
|
|
56063
56134
|
} catch (err) {
|
|
56064
56135
|
removal?.rollback();
|
|
56065
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename7(done.swap.previous));
|
|
56066
56136
|
throw err;
|
|
56067
56137
|
}
|
|
56068
56138
|
}
|
|
@@ -56082,12 +56152,12 @@ async function runUpgrade(input, deps) {
|
|
|
56082
56152
|
const result = runUninstall({ adapter, project: deps.project, env: deps.env, confirmDelete: input.confirmDelete === true });
|
|
56083
56153
|
rows.push(...result.rows);
|
|
56084
56154
|
} else {
|
|
56085
|
-
rows.push(...
|
|
56155
|
+
rows.push(...upgrade(adapter, deps, home));
|
|
56086
56156
|
}
|
|
56087
56157
|
return { text: renderTable(rows) + "\n\n" + UPGRADE_RESTART_LINE, isError: false, sandboxBytes: 0 };
|
|
56088
56158
|
}
|
|
56089
56159
|
async function handler8(input, ctx) {
|
|
56090
|
-
return runUpgrade(input, { project: ctx.project, env: process.env, signal: ctx.signal
|
|
56160
|
+
return runUpgrade(input, { project: ctx.project, env: process.env, signal: ctx.signal });
|
|
56091
56161
|
}
|
|
56092
56162
|
var ctxUpgrade = Object.freeze({
|
|
56093
56163
|
name: "ctx_upgrade",
|
|
@@ -56149,12 +56219,12 @@ function checkCall(tool, input) {
|
|
|
56149
56219
|
}
|
|
56150
56220
|
|
|
56151
56221
|
// src/entries/is-entry.ts
|
|
56152
|
-
import { realpathSync as
|
|
56222
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
56153
56223
|
function isEntry(main, argv1, self) {
|
|
56154
56224
|
if (main !== void 0) return main;
|
|
56155
56225
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
56156
56226
|
try {
|
|
56157
|
-
return
|
|
56227
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
56158
56228
|
} catch {
|
|
56159
56229
|
return false;
|
|
56160
56230
|
}
|
|
@@ -56230,16 +56300,33 @@ function workspaceFromMeta(meta3) {
|
|
|
56230
56300
|
}
|
|
56231
56301
|
function realOrSame(p) {
|
|
56232
56302
|
try {
|
|
56233
|
-
return
|
|
56303
|
+
return realpathSync12.native(p);
|
|
56234
56304
|
} catch {
|
|
56235
56305
|
return p;
|
|
56236
56306
|
}
|
|
56237
56307
|
}
|
|
56308
|
+
function hasWorkspaceFolder(argv) {
|
|
56309
|
+
const i = argv.indexOf(WORKSPACE_FOLDER_FLAG);
|
|
56310
|
+
const v = i < 0 ? void 0 : argv[i + 1];
|
|
56311
|
+
return v !== void 0 && v !== "" && v !== VSCODE_WORKSPACE_VAR;
|
|
56312
|
+
}
|
|
56313
|
+
async function workspaceFromRoots(server) {
|
|
56314
|
+
if (server.server.getClientCapabilities()?.roots === void 0) return void 0;
|
|
56315
|
+
try {
|
|
56316
|
+
const { roots } = await server.server.listRoots(void 0, { timeout: ROOTS_TIMEOUT_MS });
|
|
56317
|
+
for (const root of roots) {
|
|
56318
|
+
if (root.uri.startsWith(FILE_URL_PREFIX)) return fileURLToPath3(root.uri);
|
|
56319
|
+
}
|
|
56320
|
+
} catch (err) {
|
|
56321
|
+
console.error("context-mode: roots/list: " + (err instanceof Error ? err.message : String(err)));
|
|
56322
|
+
}
|
|
56323
|
+
return void 0;
|
|
56324
|
+
}
|
|
56238
56325
|
function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
56239
56326
|
const fromHost = workspaceFromMeta(meta3);
|
|
56240
56327
|
if (fromHost !== void 0) return fromHost;
|
|
56241
56328
|
if (script === void 0 || script === "") return spawnCwd;
|
|
56242
|
-
return realOrSame(spawnCwd) === realOrSame(
|
|
56329
|
+
return realOrSame(spawnCwd) === realOrSame(dirname12(script)) ? "" : spawnCwd;
|
|
56243
56330
|
}
|
|
56244
56331
|
function errorReply(err) {
|
|
56245
56332
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
@@ -56278,15 +56365,15 @@ async function startServer(argv, env) {
|
|
|
56278
56365
|
opening.catch(() => pending.delete(project.dbPath));
|
|
56279
56366
|
}
|
|
56280
56367
|
const db = await opening;
|
|
56281
|
-
if (!
|
|
56368
|
+
if (!existsSync22(db.path)) throw new CtxError("DB_GONE");
|
|
56282
56369
|
return db;
|
|
56283
56370
|
}
|
|
56284
56371
|
function stopMarker(configDir, projectKey) {
|
|
56285
|
-
return
|
|
56372
|
+
return join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
56286
56373
|
}
|
|
56287
56374
|
function stopRequested() {
|
|
56288
56375
|
const configDir = resolveConfigDir(process.env);
|
|
56289
|
-
return held.some((db) =>
|
|
56376
|
+
return held.some((db) => existsSync22(stopMarker(configDir, db.projectKey)));
|
|
56290
56377
|
}
|
|
56291
56378
|
async function journal(project, ctx, name, reply4) {
|
|
56292
56379
|
const db = await ownDb(project);
|
|
@@ -56296,10 +56383,12 @@ async function startServer(argv, env) {
|
|
|
56296
56383
|
return async (input, req) => {
|
|
56297
56384
|
const meta3 = req.mcpReq._meta;
|
|
56298
56385
|
const agent = resolveAgent(argv, env);
|
|
56386
|
+
const fromRoots = agent === "vscode" && !hasWorkspaceFolder(argv) ? await workspaceFromRoots(server) : void 0;
|
|
56387
|
+
const callArgv = fromRoots === void 0 ? argv : [...argv, WORKSPACE_FOLDER_FLAG, fromRoots];
|
|
56299
56388
|
let project;
|
|
56300
56389
|
const projectOf = () => {
|
|
56301
56390
|
if (agent === void 0) throw new CtxError("NO_PROJECT", { kind: "--agent" });
|
|
56302
|
-
project ??= resolveProject(agent, { env, argv, cwd: workspaceCwdOf(meta3, process.cwd(), process.argv[1]), piCwd: void 0 });
|
|
56391
|
+
project ??= resolveProject(agent, { env, argv: callArgv, cwd: workspaceCwdOf(meta3, process.cwd(), process.argv[1]), piCwd: void 0 });
|
|
56303
56392
|
return project;
|
|
56304
56393
|
};
|
|
56305
56394
|
const ctx = {
|
|
@@ -56379,7 +56468,7 @@ async function startServer(argv, env) {
|
|
|
56379
56468
|
try {
|
|
56380
56469
|
const configDir = resolveConfigDir(process.env);
|
|
56381
56470
|
removeOwnerPid(configDir, db.projectKey, serverId);
|
|
56382
|
-
|
|
56471
|
+
rmSync9(stopMarker(configDir, db.projectKey), { force: true });
|
|
56383
56472
|
} catch (err) {
|
|
56384
56473
|
console.error(err);
|
|
56385
56474
|
}
|