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/cli.mjs
CHANGED
|
@@ -88,7 +88,7 @@ var require_src = __commonJS({
|
|
|
88
88
|
|
|
89
89
|
// src/entries/cli.ts
|
|
90
90
|
import { spawn as spawn4 } from "node:child_process";
|
|
91
|
-
import { readFileSync as readFileSync12, realpathSync as
|
|
91
|
+
import { readFileSync as readFileSync12, realpathSync as realpathSync11 } from "node:fs";
|
|
92
92
|
import path14 from "node:path";
|
|
93
93
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
94
94
|
|
|
@@ -96,6 +96,8 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
96
96
|
var SERVER_KEY = "context-mode";
|
|
97
97
|
var TOOL_ORDER = Object.freeze(["ctx_execute", "ctx_batch", "ctx_index", "ctx_search", "ctx_resume", "ctx_stats", "ctx_doctor", "ctx_upgrade", "ctx_purge"]);
|
|
98
98
|
var OUTPUT_CAP = 16384;
|
|
99
|
+
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
100
|
+
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
99
101
|
var WEIGHT = Object.freeze({ toolerr: 900, decision: 700, prompt: 500, edit: 400, index: 200 });
|
|
100
102
|
var DECAY_X1000 = Object.freeze([
|
|
101
103
|
1e3,
|
|
@@ -235,12 +237,13 @@ var HOOK_TIMEOUT_MS = 5e3;
|
|
|
235
237
|
var IN_PROCESS_TIMEOUT_MS = 0;
|
|
236
238
|
var PROJECTS_DIR_NAME = "projects";
|
|
237
239
|
var DB_FILE_NAME = "context.db";
|
|
238
|
-
var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
|
|
239
240
|
var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
|
|
241
|
+
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
240
242
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
241
243
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
242
244
|
var NODE_MIN = "24.15.0";
|
|
243
245
|
var DATA_ROOT = "~/.context-mode";
|
|
246
|
+
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
244
247
|
var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
245
248
|
var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
|
|
246
249
|
var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
|
|
@@ -293,7 +296,7 @@ var SHELL_DUMP_COMMANDS = Object.freeze(["cat", "head", "tail", "sed", "less", "
|
|
|
293
296
|
var DUMP_COUNT_COMMANDS = Object.freeze(["head", "tail"]);
|
|
294
297
|
var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
295
298
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
296
|
-
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path"]);
|
|
299
|
+
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
|
|
297
300
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
298
301
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
299
302
|
var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
|
|
@@ -363,18 +366,17 @@ var AGENT_HOME_DIR = Object.freeze({
|
|
|
363
366
|
var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
364
367
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
365
368
|
var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
|
|
366
|
-
var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
|
|
367
369
|
var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
|
|
368
370
|
var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
|
|
369
371
|
var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
|
|
370
372
|
var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
|
|
373
|
+
var PERSISTED_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
|
|
371
374
|
var OPS_SPLIT_FILES = Object.freeze([
|
|
372
375
|
"doctor-env.ts",
|
|
373
376
|
"doctor-config.ts",
|
|
374
377
|
"doctor-hook.ts",
|
|
375
378
|
"doctor-db.ts",
|
|
376
379
|
"doctor-heal.ts",
|
|
377
|
-
"release-fetch.ts",
|
|
378
380
|
"verify-sums.ts",
|
|
379
381
|
"plugin-swap.ts",
|
|
380
382
|
"host-write.ts",
|
|
@@ -407,10 +409,18 @@ var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
|
407
409
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
408
410
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
409
411
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
410
|
-
codex: "
|
|
411
|
-
gemini: "gemini extensions
|
|
412
|
-
qwen: "qwen extensions
|
|
412
|
+
codex: "codex plugin marketplace upgrade context-mode",
|
|
413
|
+
gemini: "gemini extensions update context-mode",
|
|
414
|
+
qwen: "qwen extensions update context-mode",
|
|
415
|
+
pi: "pi update --extensions",
|
|
416
|
+
opencode: "opencode plugin update",
|
|
417
|
+
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
418
|
+
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
419
|
+
kiro: "npm i -g context-mode && context-mode setup --agents kiro",
|
|
420
|
+
zcode: "npm i -g context-mode && context-mode setup --agents zcode"
|
|
413
421
|
});
|
|
422
|
+
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
423
|
+
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
414
424
|
var V1_SCRIPT_NAMES = Object.freeze([
|
|
415
425
|
"afteragentresponse.mjs",
|
|
416
426
|
"aftermodel.mjs",
|
|
@@ -448,6 +458,7 @@ var HOOKS_JSON_FILE = "hooks.json";
|
|
|
448
458
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
449
459
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
450
460
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
461
|
+
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
451
462
|
var KIRO_HOME_ENV = "KIRO_HOME";
|
|
452
463
|
var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
|
|
453
464
|
var APPDATA_ENV = "APPDATA";
|
|
@@ -474,6 +485,9 @@ var STATUS_LINE_KEY = "statusLine";
|
|
|
474
485
|
var PI_PACKAGES_KEY = "packages";
|
|
475
486
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
476
487
|
var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
|
|
488
|
+
var NPM_VERSION_SEP = "@";
|
|
489
|
+
var OPENCODE_NPM_LATEST = `${OPENCODE_NPM_SPEC_PREFIX}latest`;
|
|
490
|
+
var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
|
|
477
491
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
478
492
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
479
493
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -502,16 +516,19 @@ var V1_REASON = Object.freeze({
|
|
|
502
516
|
kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
|
|
503
517
|
piNpm: "old context-mode Pi package npm:context-mode",
|
|
504
518
|
opencodePlugin: "old context-mode OpenCode plugin spec context-mode",
|
|
519
|
+
piGit: "old context-mode Pi entry git:github.com/mksglu/context-mode@release: ctx_upgrade replaces it with npm:context-mode@latest",
|
|
520
|
+
opencodeGit: "old context-mode OpenCode entry git+https://github.com/mksglu/context-mode.git#release: ctx_upgrade replaces it with context-mode@latest",
|
|
505
521
|
zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
|
|
506
522
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
507
523
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
508
524
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
509
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
525
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep",
|
|
526
|
+
projectLink: "context-mode path in the project reached through a link: report only, upgrade keeps it as is and never follows a link"
|
|
510
527
|
});
|
|
511
|
-
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
528
|
+
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]);
|
|
529
|
+
var UPGRADE_KEEP_ASIDE_REASONS = Object.freeze([V1_REASON.dataDir, V1_REASON.dataRoot]);
|
|
512
530
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
513
531
|
var SERVER_ENTRY_FILE = "server.mjs";
|
|
514
|
-
var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
|
|
515
532
|
var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
|
|
516
533
|
var HOST_NODE_COMMAND = "node";
|
|
517
534
|
var EXE_SUFFIX = ".exe";
|
|
@@ -607,7 +624,7 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
607
624
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
608
625
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
609
626
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
610
|
-
zcode: ["
|
|
627
|
+
zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
|
|
611
628
|
});
|
|
612
629
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
613
630
|
|
|
@@ -624,9 +641,9 @@ function canonicalName(name, ownPrefix) {
|
|
|
624
641
|
if (name.startsWith(ownPrefix)) return name.slice(ownPrefix.length);
|
|
625
642
|
if (!name.startsWith(MCP_PREFIX)) return name;
|
|
626
643
|
const rest = name.slice(MCP_PREFIX.length);
|
|
627
|
-
const
|
|
628
|
-
if (
|
|
629
|
-
return "mcp:" + rest.slice(0,
|
|
644
|
+
const sep3 = rest.indexOf(MCP_SEP);
|
|
645
|
+
if (sep3 < 0) return name;
|
|
646
|
+
return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP.length);
|
|
630
647
|
}
|
|
631
648
|
function outputOf(resp) {
|
|
632
649
|
if (resp === void 0) return "";
|
|
@@ -826,6 +843,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
|
826
843
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
827
844
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
828
845
|
var EMPTY = { stdout: "", exitCode: 0 };
|
|
846
|
+
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";
|
|
829
847
|
function own(p3, key) {
|
|
830
848
|
return Object.hasOwn(p3, key) ? p3[key] : void 0;
|
|
831
849
|
}
|
|
@@ -845,13 +863,67 @@ function canonicalName2(name, mcp) {
|
|
|
845
863
|
if (typeof server !== "string" || typeof tool !== "string") return name;
|
|
846
864
|
return "mcp:" + server + ":" + tool;
|
|
847
865
|
}
|
|
866
|
+
function partsText(llm) {
|
|
867
|
+
if (!Array.isArray(llm) || llm.length === 0) return void 0;
|
|
868
|
+
const out2 = [];
|
|
869
|
+
for (const part of llm) {
|
|
870
|
+
if (typeof part === "string") {
|
|
871
|
+
out2.push(part);
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
if (typeof part !== "object" || part === null) return void 0;
|
|
875
|
+
const t2 = own(part, "text");
|
|
876
|
+
if (typeof t2 !== "string") return void 0;
|
|
877
|
+
out2.push(t2);
|
|
878
|
+
}
|
|
879
|
+
return out2.join("");
|
|
880
|
+
}
|
|
848
881
|
function readResult2(resp) {
|
|
849
882
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
850
883
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
851
|
-
const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : JSON.stringify(resp);
|
|
884
|
+
const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
852
885
|
const err2 = obj === void 0 ? void 0 : own(obj, "error");
|
|
853
886
|
return { isError: err2 !== void 0 && err2 !== null, bytes: Buffer.byteLength(text2), text: text2 };
|
|
854
887
|
}
|
|
888
|
+
var URL_STARTS = ["https://", "http://"];
|
|
889
|
+
var URL_TRAIL = `.,;:!?)]}>'"`;
|
|
890
|
+
var SPACE = " \n\r\f\v";
|
|
891
|
+
function words(text2) {
|
|
892
|
+
const out2 = [];
|
|
893
|
+
let cur = "";
|
|
894
|
+
for (const ch of text2) {
|
|
895
|
+
if (SPACE.includes(ch)) {
|
|
896
|
+
if (cur !== "") out2.push(cur);
|
|
897
|
+
cur = "";
|
|
898
|
+
} else cur += ch;
|
|
899
|
+
}
|
|
900
|
+
if (cur !== "") out2.push(cur);
|
|
901
|
+
return out2;
|
|
902
|
+
}
|
|
903
|
+
function firstUrl(prompt) {
|
|
904
|
+
if (typeof prompt !== "string") return void 0;
|
|
905
|
+
for (const word of words(prompt)) {
|
|
906
|
+
const lower = word.toLowerCase();
|
|
907
|
+
const at = URL_STARTS.map((s) => lower.indexOf(s)).filter((i2) => i2 >= 0).sort((a2, b3) => a2 - b3)[0];
|
|
908
|
+
if (at === void 0) continue;
|
|
909
|
+
let url = word.slice(at);
|
|
910
|
+
while (url.length > 0 && URL_TRAIL.includes(url[url.length - 1])) url = url.slice(0, -1);
|
|
911
|
+
return url;
|
|
912
|
+
}
|
|
913
|
+
return void 0;
|
|
914
|
+
}
|
|
915
|
+
function nativeInput(name, input) {
|
|
916
|
+
if (name === "web_fetch" && own(input, "url") === void 0) {
|
|
917
|
+
const url = firstUrl(own(input, "prompt"));
|
|
918
|
+
return url === void 0 ? input : { ...input, url };
|
|
919
|
+
}
|
|
920
|
+
if (name === "read_many_files" && own(input, "file_path") === void 0) {
|
|
921
|
+
const inc = own(input, "include");
|
|
922
|
+
const list2 = Array.isArray(inc) ? inc.filter((v) => typeof v === "string") : [];
|
|
923
|
+
return list2.length === 0 ? input : { ...input, file_path: list2.join(" ") };
|
|
924
|
+
}
|
|
925
|
+
return input;
|
|
926
|
+
}
|
|
855
927
|
function decode3(raw) {
|
|
856
928
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
857
929
|
const p3 = raw;
|
|
@@ -869,7 +941,7 @@ function decode3(raw) {
|
|
|
869
941
|
ev.tool = {
|
|
870
942
|
name,
|
|
871
943
|
canonicalName: canonicalName2(name, own(p3, "mcp_context")),
|
|
872
|
-
input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
944
|
+
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
873
945
|
};
|
|
874
946
|
}
|
|
875
947
|
if (event === "PostToolUse") ev.result = readResult2(own(p3, "tool_response"));
|
|
@@ -887,7 +959,7 @@ function encode3(ev, d, _extra) {
|
|
|
887
959
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
888
960
|
case "replace":
|
|
889
961
|
if (ev.event !== "PostToolUse") return EMPTY;
|
|
890
|
-
return { stdout: JSON.stringify({ decision: "deny", reason: d.output }), exitCode: 0 };
|
|
962
|
+
return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
|
|
891
963
|
}
|
|
892
964
|
}
|
|
893
965
|
|
|
@@ -948,6 +1020,14 @@ function canonicalName3(name) {
|
|
|
948
1020
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
949
1021
|
return name;
|
|
950
1022
|
}
|
|
1023
|
+
var isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1024
|
+
function viewRange(name, input) {
|
|
1025
|
+
const r2 = input.view_range;
|
|
1026
|
+
if (name !== "view" || !Array.isArray(r2) || !isNum(r2[0])) return input;
|
|
1027
|
+
const out2 = { ...input, offset: r2[0] };
|
|
1028
|
+
if (isNum(r2[1]) && r2[1] >= r2[0]) out2.limit = r2[1] - r2[0] + 1;
|
|
1029
|
+
return out2;
|
|
1030
|
+
}
|
|
951
1031
|
function readArgs(v) {
|
|
952
1032
|
if (isRecord(v)) return v;
|
|
953
1033
|
if (typeof v !== "string") return {};
|
|
@@ -992,7 +1072,7 @@ function decode5(raw) {
|
|
|
992
1072
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
993
1073
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
994
1074
|
const toolName = String(raw[k.tool] ?? "");
|
|
995
|
-
const tool = { name: toolName, canonicalName: canonicalName3(toolName), input: readArgs(raw[k.args]) };
|
|
1075
|
+
const tool = { name: toolName, canonicalName: canonicalName3(toolName), input: viewRange(toolName, readArgs(raw[k.args])) };
|
|
996
1076
|
ev.tool = tool;
|
|
997
1077
|
}
|
|
998
1078
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
@@ -1036,22 +1116,22 @@ function canonicalName4(name) {
|
|
|
1036
1116
|
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
1037
1117
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
1038
1118
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
1039
|
-
const
|
|
1040
|
-
if (
|
|
1041
|
-
return "mcp:" + rest.slice(0,
|
|
1119
|
+
const sep3 = rest.indexOf(MCP_SEP2);
|
|
1120
|
+
if (sep3 <= 0 || sep3 === rest.length - 1) return name;
|
|
1121
|
+
return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP2.length);
|
|
1042
1122
|
}
|
|
1043
|
-
var
|
|
1123
|
+
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1044
1124
|
function policyInput(name, canonical, input) {
|
|
1045
1125
|
if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
|
|
1046
1126
|
const out2 = { ...input };
|
|
1047
1127
|
if (name === "read_file") {
|
|
1048
1128
|
if (typeof input.filePath === "string") out2.file_path = input.filePath;
|
|
1049
|
-
if (
|
|
1050
|
-
if (
|
|
1051
|
-
} else if (Array.isArray(input.view_range) &&
|
|
1129
|
+
if (isNum2(input.startLine)) out2.offset = input.startLine;
|
|
1130
|
+
if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out2.limit = input.endLine - input.startLine + 1;
|
|
1131
|
+
} else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
|
|
1052
1132
|
out2.offset = input.view_range[0];
|
|
1053
1133
|
const end = input.view_range[1];
|
|
1054
|
-
if (
|
|
1134
|
+
if (isNum2(end) && end >= input.view_range[0]) out2.limit = end - input.view_range[0] + 1;
|
|
1055
1135
|
}
|
|
1056
1136
|
return out2;
|
|
1057
1137
|
}
|
|
@@ -1167,9 +1247,9 @@ function canonicalName5(name) {
|
|
|
1167
1247
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1168
1248
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1169
1249
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
1170
|
-
const
|
|
1171
|
-
if (
|
|
1172
|
-
return "mcp:" + rest.slice(0,
|
|
1250
|
+
const sep3 = rest.indexOf(MCP_SEP3);
|
|
1251
|
+
if (sep3 <= 0 || sep3 === rest.length - 1) return name;
|
|
1252
|
+
return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP3.length);
|
|
1173
1253
|
}
|
|
1174
1254
|
function readResult5(resp) {
|
|
1175
1255
|
const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
@@ -1212,6 +1292,7 @@ function encode7(ev, d, _extra) {
|
|
|
1212
1292
|
|
|
1213
1293
|
// src/adapters/zcode.ts
|
|
1214
1294
|
var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
|
|
1295
|
+
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1215
1296
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1216
1297
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1217
1298
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
@@ -1221,7 +1302,9 @@ function decode8(raw) {
|
|
|
1221
1302
|
for (const [snake2, camel] of Object.entries(TWINS)) if (p3[snake2] === void 0) p3[snake2] = p3[camel];
|
|
1222
1303
|
const failure = p3.hook_event_name === FAILURE_EVENT2;
|
|
1223
1304
|
if (failure) p3.hook_event_name = "PostToolUse";
|
|
1224
|
-
const
|
|
1305
|
+
const toolName = typeof p3.tool_name === "string" ? p3.tool_name : "";
|
|
1306
|
+
const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
|
|
1307
|
+
const ev = decodeClaudeShape(p3, "zcode", prefix, ZCODE_SOURCES);
|
|
1225
1308
|
if (failure) {
|
|
1226
1309
|
const text2 = typeof p3.error === "string" ? p3.error : p3.error === void 0 ? "" : JSON.stringify(p3.error);
|
|
1227
1310
|
ev.result = { isError: true, bytes: Buffer.byteLength(text2), text: text2 };
|
|
@@ -1302,8 +1385,9 @@ var OPENCODE_EVENTS = {
|
|
|
1302
1385
|
"step-finish": "Usage"
|
|
1303
1386
|
};
|
|
1304
1387
|
var SHELL_TOOL_NAME = "bash";
|
|
1388
|
+
var READ_TOOL_NAME = "read";
|
|
1305
1389
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1306
|
-
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n3) => [n3, "Bash"])) };
|
|
1390
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n3) => [n3, "Bash"])) };
|
|
1307
1391
|
function toCanonicalTool(name) {
|
|
1308
1392
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1309
1393
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -1531,9 +1615,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1531
1615
|
installMode: "in-process",
|
|
1532
1616
|
projectSource: "spawn-cwd",
|
|
1533
1617
|
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
1534
|
-
nativeTools: { shell: [SHELL_TOOL_NAME] },
|
|
1618
|
+
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
1535
1619
|
execReadOnlyHint: false,
|
|
1536
|
-
// D-HF-OPENCODE-SHELL-1
|
|
1620
|
+
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
1537
1621
|
// Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
|
|
1538
1622
|
eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
|
|
1539
1623
|
compactDelivery: "opencode-cache",
|
|
@@ -1763,7 +1847,7 @@ Examples:
|
|
|
1763
1847
|
// src/cli/commands.ts
|
|
1764
1848
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1765
1849
|
import { createHash as createHash2 } from "node:crypto";
|
|
1766
|
-
import { existsSync as
|
|
1850
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1767
1851
|
import os from "node:os";
|
|
1768
1852
|
import path13 from "node:path";
|
|
1769
1853
|
|
|
@@ -2054,18 +2138,18 @@ var wrapWord = (rows, word, columns) => {
|
|
|
2054
2138
|
}
|
|
2055
2139
|
};
|
|
2056
2140
|
var stringVisibleTrimSpacesRight = (string) => {
|
|
2057
|
-
const
|
|
2058
|
-
let last2 =
|
|
2141
|
+
const words2 = string.split(" ");
|
|
2142
|
+
let last2 = words2.length;
|
|
2059
2143
|
while (last2) {
|
|
2060
|
-
if (dist_default2(
|
|
2144
|
+
if (dist_default2(words2[last2 - 1])) {
|
|
2061
2145
|
break;
|
|
2062
2146
|
}
|
|
2063
2147
|
last2--;
|
|
2064
2148
|
}
|
|
2065
|
-
if (last2 ===
|
|
2149
|
+
if (last2 === words2.length) {
|
|
2066
2150
|
return string;
|
|
2067
2151
|
}
|
|
2068
|
-
return
|
|
2152
|
+
return words2.slice(0, last2).join(" ") + words2.slice(last2).join("");
|
|
2069
2153
|
};
|
|
2070
2154
|
var exec = (string, columns, options = {}) => {
|
|
2071
2155
|
if (options.trim !== false && string.trim() === "") {
|
|
@@ -2074,11 +2158,11 @@ var exec = (string, columns, options = {}) => {
|
|
|
2074
2158
|
let returnValue = "";
|
|
2075
2159
|
let escapeCode;
|
|
2076
2160
|
let escapeUrl;
|
|
2077
|
-
const
|
|
2161
|
+
const words2 = string.split(" ");
|
|
2078
2162
|
let rows = [""];
|
|
2079
2163
|
let rowLength = 0;
|
|
2080
|
-
for (let index = 0; index <
|
|
2081
|
-
const word =
|
|
2164
|
+
for (let index = 0; index < words2.length; index++) {
|
|
2165
|
+
const word = words2[index];
|
|
2082
2166
|
if (options.trim !== false) {
|
|
2083
2167
|
const row = rows.at(-1) ?? "";
|
|
2084
2168
|
const trimmed = row.trimStart();
|
|
@@ -4676,6 +4760,10 @@ function copilotDirOf(env, home) {
|
|
|
4676
4760
|
const dir = env[COPILOT_HOME_ENV];
|
|
4677
4761
|
return dir !== void 0 && dir !== "" ? dir : join2(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
4678
4762
|
}
|
|
4763
|
+
function geminiDirOf(env, home) {
|
|
4764
|
+
const dir = env[GEMINI_CLI_HOME_ENV];
|
|
4765
|
+
return join2(dir !== void 0 && dir !== "" ? dir : home, ...AGENT_HOME_DIR.gemini);
|
|
4766
|
+
}
|
|
4679
4767
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
4680
4768
|
const p3 = platform === "win32" ? win32 : posix;
|
|
4681
4769
|
const fallback = p3.join(home, ...AGENT_HOME_DIR.kiro);
|
|
@@ -4729,11 +4817,15 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4729
4817
|
if (agent === "kiro") return join2(kiroDirOf(env, home), ...file.slice(1));
|
|
4730
4818
|
return agent === "vscode" ? join2(vscodeUserDirOf(env, home), ...file) : join2(home, ...file);
|
|
4731
4819
|
}
|
|
4820
|
+
function dataRootOf(env, home) {
|
|
4821
|
+
const dir = env[DATA_DIR_ENV];
|
|
4822
|
+
return dir !== void 0 && dir !== "" ? resolve(dir) : join2(home, DATA_ROOT.slice(1));
|
|
4823
|
+
}
|
|
4732
4824
|
|
|
4733
4825
|
// src/core/ops/doctor-issue.ts
|
|
4734
4826
|
import { spawnSync } from "node:child_process";
|
|
4735
|
-
import { closeSync, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync5, readSync, realpathSync as
|
|
4736
|
-
import { delimiter, join as
|
|
4827
|
+
import { closeSync, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync5, readSync, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4828
|
+
import { delimiter, join as join10 } from "node:path";
|
|
4737
4829
|
|
|
4738
4830
|
// src/core/hooks/fallback.ts
|
|
4739
4831
|
import { join as join3, resolve as resolve2 } from "node:path";
|
|
@@ -4830,12 +4922,12 @@ var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = proce
|
|
|
4830
4922
|
|
|
4831
4923
|
// src/core/ops/doctor-config.ts
|
|
4832
4924
|
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
4833
|
-
import { join as
|
|
4925
|
+
import { join as join9 } from "node:path";
|
|
4834
4926
|
|
|
4835
4927
|
// src/core/ops/detect-v1.ts
|
|
4836
4928
|
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
4837
4929
|
import { tmpdir } from "node:os";
|
|
4838
|
-
import { join as
|
|
4930
|
+
import { join as join7 } from "node:path";
|
|
4839
4931
|
|
|
4840
4932
|
// src/core/ops/host-config.ts
|
|
4841
4933
|
import { existsSync as existsSync4, readFileSync } from "node:fs";
|
|
@@ -7281,8 +7373,8 @@ function replaceToml(text2, doc, path15, value) {
|
|
|
7281
7373
|
let out2 = text2;
|
|
7282
7374
|
for (const [s, e, put] of cuts) out2 = out2.slice(0, s) + put + out2.slice(e);
|
|
7283
7375
|
if (owned.length > 0 || block2 === "") return out2;
|
|
7284
|
-
const
|
|
7285
|
-
return out2 +
|
|
7376
|
+
const sep3 = out2 === "" ? "" : out2.endsWith("\n\n") ? "" : out2.endsWith("\n") ? "\n" : "\n\n";
|
|
7377
|
+
return out2 + sep3 + block2;
|
|
7286
7378
|
}
|
|
7287
7379
|
var tableLike = (v) => v === void 0 || isPlainObject(v);
|
|
7288
7380
|
function setTomlText(text2, path15, value) {
|
|
@@ -7320,15 +7412,14 @@ function setText(agent, path15, text2, format, key, value) {
|
|
|
7320
7412
|
function isNodeCommand(command) {
|
|
7321
7413
|
if (typeof command !== "string") return false;
|
|
7322
7414
|
let at = -1;
|
|
7323
|
-
for (const
|
|
7415
|
+
for (const sep3 of V1_PATH_SEPS) at = Math.max(at, command.lastIndexOf(sep3));
|
|
7324
7416
|
const exe = command.slice(at + 1).toLowerCase();
|
|
7325
7417
|
return exe === HOST_NODE_COMMAND || exe === HOST_NODE_COMMAND + EXE_SUFFIX;
|
|
7326
7418
|
}
|
|
7327
7419
|
function ownMcpValue(agent, node, server) {
|
|
7328
7420
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
7329
7421
|
if (mcp === void 0) return void 0;
|
|
7330
|
-
|
|
7331
|
-
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
|
|
7422
|
+
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent] };
|
|
7332
7423
|
}
|
|
7333
7424
|
function applyEdits(agent, path15, text2, format, wanted) {
|
|
7334
7425
|
const parsed = parseHostConfig(agent, path15, text2, format);
|
|
@@ -7346,6 +7437,28 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
|
|
|
7346
7437
|
return applyEdits(agent, path15, text2, format, wanted);
|
|
7347
7438
|
}
|
|
7348
7439
|
|
|
7440
|
+
// src/core/project/contain.ts
|
|
7441
|
+
import { dirname as dirname5, join as join6, relative, sep } from "node:path";
|
|
7442
|
+
var { lstatSync: lstatSync2, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
7443
|
+
function components(p3) {
|
|
7444
|
+
return p3.split(sep).filter((c3) => c3 !== "");
|
|
7445
|
+
}
|
|
7446
|
+
function reachedThroughLink(root, p3) {
|
|
7447
|
+
const rel = relative(root, p3);
|
|
7448
|
+
const steps = components(rel);
|
|
7449
|
+
if (rel === "" || steps[0] === ".." || rel === p3) return false;
|
|
7450
|
+
let at = root;
|
|
7451
|
+
for (const step of steps) {
|
|
7452
|
+
at = join6(at, step);
|
|
7453
|
+
try {
|
|
7454
|
+
if (lstatSync2(at).isSymbolicLink()) return true;
|
|
7455
|
+
} catch {
|
|
7456
|
+
return false;
|
|
7457
|
+
}
|
|
7458
|
+
}
|
|
7459
|
+
return false;
|
|
7460
|
+
}
|
|
7461
|
+
|
|
7349
7462
|
// src/core/ops/detect-v1.ts
|
|
7350
7463
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7351
7464
|
var keyPath = (...parts) => parts.join(".");
|
|
@@ -7420,7 +7533,7 @@ function isV2McpTable(v) {
|
|
|
7420
7533
|
const first = Array.isArray(v[MCP_ARGS_FIELD]) ? v[MCP_ARGS_FIELD][0] : void 0;
|
|
7421
7534
|
if (typeof first !== "string") return false;
|
|
7422
7535
|
let at = -1;
|
|
7423
|
-
for (const
|
|
7536
|
+
for (const sep3 of V1_PATH_SEPS) at = Math.max(at, first.lastIndexOf(sep3));
|
|
7424
7537
|
return first.slice(at + 1) === SERVER_ENTRY_FILE;
|
|
7425
7538
|
}
|
|
7426
7539
|
var listOf = (v) => Array.isArray(v) ? v : [];
|
|
@@ -7451,7 +7564,7 @@ function flatCommands(events2, prefix) {
|
|
|
7451
7564
|
return out2;
|
|
7452
7565
|
}
|
|
7453
7566
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7454
|
-
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((
|
|
7567
|
+
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
|
|
7455
7568
|
function dataDir(dir, reason, out2) {
|
|
7456
7569
|
if (existsSync5(dir)) out2.push(finding(dir, "", reason));
|
|
7457
7570
|
}
|
|
@@ -7461,7 +7574,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7461
7574
|
}
|
|
7462
7575
|
}
|
|
7463
7576
|
function claudeShapeSettings(agentHome, out2) {
|
|
7464
|
-
const file =
|
|
7577
|
+
const file = join7(agentHome, SETTINGS_FILE);
|
|
7465
7578
|
const doc = readJson(file);
|
|
7466
7579
|
for (const c3 of nestedCommands(doc)) {
|
|
7467
7580
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7481,49 +7594,50 @@ function v1HookFile(file, out2) {
|
|
|
7481
7594
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7482
7595
|
claudeShapeSettings(agentHome, out2);
|
|
7483
7596
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7484
|
-
const file =
|
|
7597
|
+
const file = join7(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
7485
7598
|
if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
|
|
7486
7599
|
}
|
|
7487
|
-
const userFile =
|
|
7600
|
+
const userFile = join7(home, CLAUDE_USER_CONFIG_FILE);
|
|
7488
7601
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7489
|
-
dataDir(
|
|
7602
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7490
7603
|
}
|
|
7491
7604
|
function scanCodex(agentHome, out2) {
|
|
7492
|
-
const hooksFile =
|
|
7605
|
+
const hooksFile = join7(agentHome, HOOKS_JSON_FILE);
|
|
7493
7606
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7494
7607
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7495
7608
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7496
7609
|
}
|
|
7497
7610
|
}
|
|
7498
|
-
const tomlFile =
|
|
7611
|
+
const tomlFile = join7(agentHome, CONFIG_TOML_FILE);
|
|
7499
7612
|
const config = readTomlValue(tomlFile);
|
|
7500
7613
|
for (const span of readTomlTables(tomlFile)) {
|
|
7501
7614
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7502
7615
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7503
7616
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7504
7617
|
}
|
|
7505
|
-
dataDir(
|
|
7618
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7506
7619
|
}
|
|
7507
7620
|
function scanGemini(agentHome, out2) {
|
|
7508
|
-
const file =
|
|
7621
|
+
const file = join7(agentHome, SETTINGS_FILE);
|
|
7509
7622
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7510
7623
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7511
7624
|
}
|
|
7512
|
-
dataDir(
|
|
7625
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7513
7626
|
}
|
|
7514
7627
|
function scanVscode(agentHome, project, out2) {
|
|
7515
7628
|
if (project !== void 0) {
|
|
7516
|
-
v1HookFile(
|
|
7517
|
-
const mcpFile =
|
|
7629
|
+
v1HookFile(join7(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7630
|
+
const mcpFile = join7(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
7518
7631
|
const doc = readJson(mcpFile);
|
|
7519
7632
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7520
7633
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7521
7634
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7522
7635
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7523
7636
|
}
|
|
7524
|
-
|
|
7637
|
+
const sessions = join7(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
7638
|
+
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out2);
|
|
7525
7639
|
}
|
|
7526
|
-
dataDir(
|
|
7640
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7527
7641
|
}
|
|
7528
7642
|
function jsonFiles(dir) {
|
|
7529
7643
|
try {
|
|
@@ -7533,10 +7647,10 @@ function jsonFiles(dir) {
|
|
|
7533
7647
|
}
|
|
7534
7648
|
}
|
|
7535
7649
|
function scanKiro(agentHome, project, out2) {
|
|
7536
|
-
const agentsDir =
|
|
7537
|
-
const defaultFile =
|
|
7650
|
+
const agentsDir = join7(agentHome, KIRO_AGENTS_DIR);
|
|
7651
|
+
const defaultFile = join7(agentHome, ...KIRO_AGENT_FILE);
|
|
7538
7652
|
for (const name of jsonFiles(agentsDir)) {
|
|
7539
|
-
const file =
|
|
7653
|
+
const file = join7(agentsDir, name);
|
|
7540
7654
|
const doc = readJson(file);
|
|
7541
7655
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7542
7656
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7547,46 +7661,48 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7547
7661
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7548
7662
|
}
|
|
7549
7663
|
}
|
|
7550
|
-
const steeringDocs = [
|
|
7551
|
-
if (project !== void 0) steeringDocs.push(
|
|
7664
|
+
const steeringDocs = [join7(agentHome, ...KIRO_STEERING_FILE)];
|
|
7665
|
+
if (project !== void 0) steeringDocs.push(join7(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7552
7666
|
for (const file of steeringDocs) {
|
|
7553
7667
|
if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7554
7668
|
}
|
|
7555
|
-
dataDir(
|
|
7669
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7556
7670
|
}
|
|
7557
7671
|
function piNpmIsCurrent(piAgentDir) {
|
|
7558
|
-
const doc = readJson(
|
|
7672
|
+
const doc = readJson(join7(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
7559
7673
|
const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
7560
7674
|
return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
|
|
7561
7675
|
}
|
|
7562
7676
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7563
|
-
const file =
|
|
7677
|
+
const file = join7(piAgentDir, SETTINGS_FILE);
|
|
7564
7678
|
const doc = readJson(file);
|
|
7565
7679
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7566
7680
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7567
7681
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7682
|
+
if (spec === PI_GIT_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piGit));
|
|
7568
7683
|
});
|
|
7569
|
-
dataDir(
|
|
7684
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7570
7685
|
}
|
|
7571
7686
|
function scanOpencode(agentHome, out2) {
|
|
7572
7687
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7573
|
-
const file =
|
|
7688
|
+
const file = join7(agentHome, name);
|
|
7574
7689
|
const doc = readJson(file);
|
|
7575
7690
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7576
7691
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
7577
7692
|
if (spec === V1_OPENCODE_PLUGIN_SPEC) out2.push(finding(file, keyPath(OPENCODE_PLUGIN_KEY, i2), V1_REASON.opencodePlugin));
|
|
7693
|
+
if (spec === OPENCODE_GIT_SPEC) out2.push(finding(file, keyPath(OPENCODE_PLUGIN_KEY, i2), V1_REASON.opencodeGit));
|
|
7578
7694
|
});
|
|
7579
7695
|
return;
|
|
7580
7696
|
}
|
|
7581
7697
|
}
|
|
7582
7698
|
function scanZcode(agentHome, out2) {
|
|
7583
|
-
const configFile =
|
|
7699
|
+
const configFile = join7(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7584
7700
|
const config = readJson(configFile);
|
|
7585
7701
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7586
7702
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7587
7703
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7588
7704
|
}
|
|
7589
|
-
const hooksFile =
|
|
7705
|
+
const hooksFile = join7(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7590
7706
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7591
7707
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7592
7708
|
}
|
|
@@ -7610,14 +7726,14 @@ function firstTmpMatch(dir) {
|
|
|
7610
7726
|
}
|
|
7611
7727
|
}
|
|
7612
7728
|
function scanAll(home, tmp, out2) {
|
|
7613
|
-
const root =
|
|
7614
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
7729
|
+
const root = join7(home, DATA_ROOT.slice(1));
|
|
7730
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join7(root, name), V1_REASON.dataRoot, out2);
|
|
7615
7731
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7616
7732
|
}
|
|
7617
7733
|
function detectV1(agent, home, scope = {}) {
|
|
7618
7734
|
const out2 = [];
|
|
7619
7735
|
const project = scope.project;
|
|
7620
|
-
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 :
|
|
7736
|
+
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 : join7(home, ...AGENT_HOME_DIR[agent]);
|
|
7621
7737
|
switch (agent) {
|
|
7622
7738
|
case "claude-code":
|
|
7623
7739
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7630,11 +7746,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7630
7746
|
break;
|
|
7631
7747
|
case "qwen":
|
|
7632
7748
|
claudeShapeSettings(agentHome, out2);
|
|
7633
|
-
dataDir(
|
|
7749
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7634
7750
|
break;
|
|
7635
7751
|
case "copilot-cli":
|
|
7636
|
-
v1HookFile(
|
|
7637
|
-
dataDir(
|
|
7752
|
+
v1HookFile(join7(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7753
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7638
7754
|
break;
|
|
7639
7755
|
case "vscode":
|
|
7640
7756
|
scanVscode(agentHome, project, out2);
|
|
@@ -7643,7 +7759,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7643
7759
|
scanKiro(agentHome, project, out2);
|
|
7644
7760
|
break;
|
|
7645
7761
|
case "pi":
|
|
7646
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7762
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join7(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7647
7763
|
break;
|
|
7648
7764
|
// D-WIN-PIDIR-1: empty is unset
|
|
7649
7765
|
case "opencode":
|
|
@@ -7658,12 +7774,12 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7658
7774
|
}
|
|
7659
7775
|
|
|
7660
7776
|
// src/core/ops/plugin-root.ts
|
|
7661
|
-
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as
|
|
7662
|
-
import { dirname as
|
|
7777
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync3 } from "node:fs";
|
|
7778
|
+
import { dirname as dirname6, isAbsolute, join as join8, sep as sep2 } from "node:path";
|
|
7663
7779
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7664
7780
|
|
|
7665
7781
|
// src/setup/pi-gate.ts
|
|
7666
|
-
import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as
|
|
7782
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
|
|
7667
7783
|
import path3 from "node:path";
|
|
7668
7784
|
var OWN_FILE = "pi/index.js";
|
|
7669
7785
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -7681,7 +7797,7 @@ function load(file) {
|
|
|
7681
7797
|
}
|
|
7682
7798
|
var real = (p3) => {
|
|
7683
7799
|
try {
|
|
7684
|
-
return
|
|
7800
|
+
return realpathSync4(p3);
|
|
7685
7801
|
} catch {
|
|
7686
7802
|
return path3.resolve(p3);
|
|
7687
7803
|
}
|
|
@@ -7782,6 +7898,7 @@ function formUrl(title, summary) {
|
|
|
7782
7898
|
}
|
|
7783
7899
|
|
|
7784
7900
|
// src/setup/registry.ts
|
|
7901
|
+
import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
7785
7902
|
import path4 from "node:path";
|
|
7786
7903
|
|
|
7787
7904
|
// src/setup/hook-shapes.ts
|
|
@@ -7840,7 +7957,6 @@ var HOOK_SHAPES = {
|
|
|
7840
7957
|
var SERVER_BUNDLE = "server.mjs";
|
|
7841
7958
|
var HOOK_BUNDLE = "hook.mjs";
|
|
7842
7959
|
var AGENT_FLAG = "--agent";
|
|
7843
|
-
var STATE_DIR = ".context-mode";
|
|
7844
7960
|
var LOCK_FILE = "setup.lock";
|
|
7845
7961
|
var BACKUP_DIR = "backups";
|
|
7846
7962
|
var PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
@@ -7904,10 +8020,39 @@ function extensionPlugin(bin, id) {
|
|
|
7904
8020
|
var NATIVE_PLUGIN = {
|
|
7905
8021
|
codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "table", hookTrust: true },
|
|
7906
8022
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
7907
|
-
gemini: extensionPlugin("gemini", "gemini")
|
|
8023
|
+
gemini: extensionPlugin("gemini", "gemini"),
|
|
8024
|
+
// D-R44-ZCODE-NATIVE-1 (host audit zcode-1/2): `zcode plugins install context-mode@context-mode` lists as JSON; ZCode loads
|
|
8025
|
+
// <plugin>/.zcode-plugin/plugin.json (MCP server, hooks run with --agent zcode) and the package skills/.
|
|
8026
|
+
zcode: {
|
|
8027
|
+
bin: "zcode",
|
|
8028
|
+
args: ["plugins", "list", "--json"],
|
|
8029
|
+
plugin: PLUGIN_ID,
|
|
8030
|
+
hooksVia: ".zcode-plugin",
|
|
8031
|
+
skillsVia: SKILLS_DIR_NAME,
|
|
8032
|
+
format: "json",
|
|
8033
|
+
enable: ["plugins", "enable", PLUGIN_ID]
|
|
8034
|
+
}
|
|
7908
8035
|
};
|
|
8036
|
+
var CELLAR_SEGMENT = "/Cellar/";
|
|
8037
|
+
var NODE_BIN = ["bin", "node"];
|
|
8038
|
+
var REAL_FS = { exists: existsSync10, real: (p3) => realpathSync6.native(p3) };
|
|
8039
|
+
function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
8040
|
+
const at = execPath.indexOf(CELLAR_SEGMENT);
|
|
8041
|
+
if (at < 0) return execPath;
|
|
8042
|
+
const prefix = execPath.slice(0, at);
|
|
8043
|
+
const formula = execPath.slice(at + CELLAR_SEGMENT.length).split("/")[0] ?? "";
|
|
8044
|
+
const target = fs2.real(execPath);
|
|
8045
|
+
for (const link of [[prefix, "opt", formula, ...NODE_BIN].join("/"), [prefix, ...NODE_BIN].join("/")]) {
|
|
8046
|
+
try {
|
|
8047
|
+
if (fs2.exists(link) && fs2.real(link) === target) return link;
|
|
8048
|
+
} catch {
|
|
8049
|
+
}
|
|
8050
|
+
}
|
|
8051
|
+
return execPath;
|
|
8052
|
+
}
|
|
8053
|
+
var SETUP_NODE = stableNodePath(process.execPath);
|
|
7909
8054
|
function serverCmd(ctx, id) {
|
|
7910
|
-
return [
|
|
8055
|
+
return [SETUP_NODE, path4.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
7911
8056
|
}
|
|
7912
8057
|
function hookCommandString(row) {
|
|
7913
8058
|
const [node, file, flag, id] = row.hookCommand ?? [];
|
|
@@ -7986,7 +8131,8 @@ function hookFilesFor(ctx, id) {
|
|
|
7986
8131
|
case "claude-code":
|
|
7987
8132
|
return [{ file: path4.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
7988
8133
|
case "gemini":
|
|
7989
|
-
return [{ file: path4.join(
|
|
8134
|
+
return [{ file: path4.join(geminiDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
8135
|
+
// D-R38-GEMINI-HOME-1
|
|
7990
8136
|
case "qwen":
|
|
7991
8137
|
return [{ file: path4.join(home, ".qwen", "settings.json"), mode: "drop" }];
|
|
7992
8138
|
default:
|
|
@@ -8033,8 +8179,8 @@ function buildRegistry(ctx) {
|
|
|
8033
8179
|
const id = row.id;
|
|
8034
8180
|
const config = configFor(ctx, id);
|
|
8035
8181
|
const hookFiles = hookFilesFor(ctx, id);
|
|
8036
|
-
const runCommand2 = [
|
|
8037
|
-
const bareNode = id === "codex" && (ctx.platform ?? process.platform) === "win32";
|
|
8182
|
+
const runCommand2 = [SETUP_NODE, path4.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
8183
|
+
const bareNode = (id === "codex" || id === "qwen") && (ctx.platform ?? process.platform) === "win32";
|
|
8038
8184
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
8039
8185
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
8040
8186
|
const hookInstall = hookInstallFor(ctx, getAdapter(id), command);
|
|
@@ -8079,11 +8225,13 @@ function assertWritable(row, file) {
|
|
|
8079
8225
|
}
|
|
8080
8226
|
|
|
8081
8227
|
// src/setup/gemini-gate.ts
|
|
8082
|
-
import { existsSync as
|
|
8228
|
+
import { existsSync as existsSync11, readFileSync as readFileSync6 } from "node:fs";
|
|
8083
8229
|
import path5 from "node:path";
|
|
8084
8230
|
var GEMINI_DIR = ".gemini";
|
|
8085
8231
|
var SETTINGS_FILE2 = "settings.json";
|
|
8086
8232
|
var SYSTEM_PATH_ENV = "GEMINI_CLI_SYSTEM_SETTINGS_PATH";
|
|
8233
|
+
var SYSTEM_DEFAULTS_ENV = "GEMINI_CLI_SYSTEM_DEFAULTS_PATH";
|
|
8234
|
+
var SYSTEM_DEFAULTS_FILE = "system-defaults.json";
|
|
8087
8235
|
var OWN_AGENT = "gemini";
|
|
8088
8236
|
function systemSettingsPath(env) {
|
|
8089
8237
|
const set2 = env[SYSTEM_PATH_ENV];
|
|
@@ -8092,8 +8240,12 @@ function systemSettingsPath(env) {
|
|
|
8092
8240
|
if (process.platform === "win32") return "C:\\ProgramData\\gemini-cli\\settings.json";
|
|
8093
8241
|
return "/etc/gemini-cli/settings.json";
|
|
8094
8242
|
}
|
|
8243
|
+
function systemDefaultsPath(env) {
|
|
8244
|
+
const set2 = env[SYSTEM_DEFAULTS_ENV];
|
|
8245
|
+
return set2 ? set2 : path5.join(path5.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8246
|
+
}
|
|
8095
8247
|
function load2(file) {
|
|
8096
|
-
if (!
|
|
8248
|
+
if (!existsSync11(file)) return void 0;
|
|
8097
8249
|
try {
|
|
8098
8250
|
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync6(file, "utf8")), "jsonc") };
|
|
8099
8251
|
} catch {
|
|
@@ -8101,7 +8253,7 @@ function load2(file) {
|
|
|
8101
8253
|
}
|
|
8102
8254
|
}
|
|
8103
8255
|
function sources(env, home, cwd) {
|
|
8104
|
-
return [path5.join(
|
|
8256
|
+
return [systemDefaultsPath(env), path5.join(geminiDirOf(env, home), SETTINGS_FILE2), path5.join(cwd, GEMINI_DIR, SETTINGS_FILE2), systemSettingsPath(env)].map(load2).filter((s) => s !== void 0);
|
|
8105
8257
|
}
|
|
8106
8258
|
function ownHookEntry(entry2) {
|
|
8107
8259
|
return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
|
|
@@ -8127,7 +8279,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8127
8279
|
}
|
|
8128
8280
|
|
|
8129
8281
|
// src/setup/zcode-gate.ts
|
|
8130
|
-
import { existsSync as
|
|
8282
|
+
import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
|
|
8131
8283
|
import path6 from "node:path";
|
|
8132
8284
|
var OWN_AGENT2 = "zcode";
|
|
8133
8285
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8219,7 +8371,7 @@ function zcodeSchemaBad(doc) {
|
|
|
8219
8371
|
}
|
|
8220
8372
|
function zcodeConfigGate(home) {
|
|
8221
8373
|
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8222
|
-
if (!
|
|
8374
|
+
if (!existsSync12(file)) return void 0;
|
|
8223
8375
|
let doc;
|
|
8224
8376
|
try {
|
|
8225
8377
|
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync7(file, "utf8")), "json");
|
|
@@ -8232,7 +8384,7 @@ function zcodeConfigGate(home) {
|
|
|
8232
8384
|
}
|
|
8233
8385
|
|
|
8234
8386
|
// src/setup/vscode-gate.ts
|
|
8235
|
-
import { existsSync as
|
|
8387
|
+
import { existsSync as existsSync13, readFileSync as readFileSync8 } from "node:fs";
|
|
8236
8388
|
import path7 from "node:path";
|
|
8237
8389
|
var SETTINGS_FILE3 = "settings.json";
|
|
8238
8390
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8241,7 +8393,7 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8241
8393
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8242
8394
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8243
8395
|
function load3(file) {
|
|
8244
|
-
if (!
|
|
8396
|
+
if (!existsSync13(file)) return void 0;
|
|
8245
8397
|
try {
|
|
8246
8398
|
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
|
|
8247
8399
|
} catch {
|
|
@@ -8283,7 +8435,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8283
8435
|
}
|
|
8284
8436
|
|
|
8285
8437
|
// src/setup/qwen-gate.ts
|
|
8286
|
-
import { existsSync as
|
|
8438
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
8287
8439
|
import path8 from "node:path";
|
|
8288
8440
|
var KEY = "disableAllHooks";
|
|
8289
8441
|
var SETTINGS = "settings.json";
|
|
@@ -8299,7 +8451,7 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8299
8451
|
}
|
|
8300
8452
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8301
8453
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8302
|
-
if (!
|
|
8454
|
+
if (!existsSync14(file)) continue;
|
|
8303
8455
|
let value;
|
|
8304
8456
|
try {
|
|
8305
8457
|
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
|
|
@@ -8313,7 +8465,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8313
8465
|
|
|
8314
8466
|
// src/setup/codex-trust.ts
|
|
8315
8467
|
import { createHash } from "node:crypto";
|
|
8316
|
-
import { existsSync as
|
|
8468
|
+
import { existsSync as existsSync15, realpathSync as realpathSync7 } from "node:fs";
|
|
8317
8469
|
import path10 from "node:path";
|
|
8318
8470
|
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8319
8471
|
|
|
@@ -8422,11 +8574,11 @@ function snake(name) {
|
|
|
8422
8574
|
function realFile(file) {
|
|
8423
8575
|
let dir = path10.resolve(file);
|
|
8424
8576
|
const rest = [];
|
|
8425
|
-
while (!
|
|
8577
|
+
while (!existsSync15(dir) && path10.dirname(dir) !== dir) {
|
|
8426
8578
|
rest.unshift(path10.basename(dir));
|
|
8427
8579
|
dir = path10.dirname(dir);
|
|
8428
8580
|
}
|
|
8429
|
-
return path10.join(
|
|
8581
|
+
return path10.join(realpathSync7(dir), ...rest);
|
|
8430
8582
|
}
|
|
8431
8583
|
var ASK_TIMEOUT_MS = 1e4;
|
|
8432
8584
|
var ASK_TRIES = 3;
|
|
@@ -8620,14 +8772,14 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
8620
8772
|
if (!bad.length) return void 0;
|
|
8621
8773
|
const counts = /* @__PURE__ */ new Map();
|
|
8622
8774
|
for (const h2 of bad) counts.set(h2.status, (counts.get(h2.status) ?? 0) + 1);
|
|
8623
|
-
const
|
|
8624
|
-
const state =
|
|
8775
|
+
const words2 = [...counts].sort((a2, b3) => b3[1] - a2[1] || (a2[0] < b3[0] ? -1 : 1));
|
|
8776
|
+
const state = words2.length === 1 ? words2[0][0] : `${words2.map(([w]) => w).join(" or ")} (${words2.map(([w, n3]) => `${n3} ${w}`).join(", ")})`;
|
|
8625
8777
|
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
8626
8778
|
}
|
|
8627
8779
|
|
|
8628
8780
|
// src/setup/copilot-hooks.ts
|
|
8629
8781
|
import { spawn as spawn2 } from "node:child_process";
|
|
8630
|
-
import { realpathSync as
|
|
8782
|
+
import { realpathSync as realpathSync8 } from "node:fs";
|
|
8631
8783
|
import path11 from "node:path";
|
|
8632
8784
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
8633
8785
|
var ASK_TIMEOUT_MS2 = 15e3;
|
|
@@ -8637,7 +8789,7 @@ var USER_ORIGIN = "user";
|
|
|
8637
8789
|
function canon(p3) {
|
|
8638
8790
|
let r2 = path11.resolve(p3);
|
|
8639
8791
|
try {
|
|
8640
|
-
r2 =
|
|
8792
|
+
r2 = realpathSync8(r2);
|
|
8641
8793
|
} catch {
|
|
8642
8794
|
}
|
|
8643
8795
|
return process.platform === "win32" ? r2.toLowerCase() : r2;
|
|
@@ -8722,7 +8874,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8722
8874
|
|
|
8723
8875
|
// src/setup/engine.ts
|
|
8724
8876
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8725
|
-
import { closeSync as closeSync2, existsSync as
|
|
8877
|
+
import { closeSync as closeSync2, existsSync as existsSync16, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, readdirSync as readdirSync5, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8726
8878
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8727
8879
|
import path12 from "node:path";
|
|
8728
8880
|
|
|
@@ -8820,7 +8972,7 @@ function isNativeBinary(file) {
|
|
|
8820
8972
|
function owningPackage(dir) {
|
|
8821
8973
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
8822
8974
|
const f2 = path12.join(d, "package.json");
|
|
8823
|
-
if (
|
|
8975
|
+
if (existsSync16(f2)) {
|
|
8824
8976
|
try {
|
|
8825
8977
|
return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
|
|
8826
8978
|
} catch {
|
|
@@ -8838,8 +8990,8 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
8838
8990
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8839
8991
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
8840
8992
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
8841
|
-
if (!f2 || !
|
|
8842
|
-
const file =
|
|
8993
|
+
if (!f2 || !existsSync16(f2) || !statSync2(f2).isFile()) continue;
|
|
8994
|
+
const file = realpathSync9(f2);
|
|
8843
8995
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
8844
8996
|
shims.push(f2);
|
|
8845
8997
|
}
|
|
@@ -8855,10 +9007,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
|
8855
9007
|
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
|
|
8856
9008
|
}
|
|
8857
9009
|
function readOr(file) {
|
|
8858
|
-
return
|
|
9010
|
+
return existsSync16(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
|
|
8859
9011
|
}
|
|
8860
9012
|
function readRaw(file) {
|
|
8861
|
-
return
|
|
9013
|
+
return existsSync16(file) ? readFileSync10(file, "utf8") : void 0;
|
|
8862
9014
|
}
|
|
8863
9015
|
var atomicWrite = atomicWriteFile;
|
|
8864
9016
|
function pidAlive(pid) {
|
|
@@ -9003,7 +9155,7 @@ function isNativeSpec(e) {
|
|
|
9003
9155
|
function isStaleOwnPlugin(e, entry2) {
|
|
9004
9156
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
9005
9157
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
9006
|
-
if (
|
|
9158
|
+
if (existsSync16(e)) return false;
|
|
9007
9159
|
const seg = e.split("\\").join("/").split("/");
|
|
9008
9160
|
const n3 = seg.length;
|
|
9009
9161
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -9067,7 +9219,7 @@ function planSkills(row, edits) {
|
|
|
9067
9219
|
const s = row.skillInstall;
|
|
9068
9220
|
if (s.kind !== "dir") return;
|
|
9069
9221
|
for (const f2 of s.files) {
|
|
9070
|
-
if (!
|
|
9222
|
+
if (!existsSync16(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
9071
9223
|
const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
|
|
9072
9224
|
const before = readRaw(f2.file);
|
|
9073
9225
|
if (before !== after) edits.push({ plain: true, file: f2.file, before, after, changes: [{ file: f2.file, path: f2.name, before: before === void 0 ? null : "old", after: "SKILL.md" }] });
|
|
@@ -9305,8 +9457,8 @@ function hookRound(row, env) {
|
|
|
9305
9457
|
const bareP95Ms = Math.round(p95(bare));
|
|
9306
9458
|
const overheadP95Ms = Math.max(0, wallP95Ms - bareP95Ms);
|
|
9307
9459
|
const budget = overheadBudgetMs(env);
|
|
9308
|
-
const
|
|
9309
|
-
return { name: "hook", ok, overheadP95Ms, wallP95Ms, bareP95Ms, detail:
|
|
9460
|
+
const over = overheadP95Ms > budget;
|
|
9461
|
+
return { name: "hook", ok: true, ...over ? { warn: true } : {}, overheadP95Ms, wallP95Ms, bareP95Ms, detail: over ? `hook overhead p95 ${overheadP95Ms} ms > ${budget} ms (slow host; not a failure)` : void 0 };
|
|
9310
9462
|
}
|
|
9311
9463
|
function hookCheck(row, env) {
|
|
9312
9464
|
let best;
|
|
@@ -9314,7 +9466,7 @@ function hookCheck(row, env) {
|
|
|
9314
9466
|
const c3 = hookRound(row, env);
|
|
9315
9467
|
if (c3.overheadP95Ms === void 0) return c3;
|
|
9316
9468
|
if (!best || c3.overheadP95Ms < best.overheadP95Ms) best = c3;
|
|
9317
|
-
if (c3.
|
|
9469
|
+
if (!c3.warn) break;
|
|
9318
9470
|
}
|
|
9319
9471
|
return best;
|
|
9320
9472
|
}
|
|
@@ -9371,9 +9523,9 @@ function hookRunsCheck(row, env) {
|
|
|
9371
9523
|
}
|
|
9372
9524
|
var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
9373
9525
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9374
|
-
function hookSeenCheck(row,
|
|
9375
|
-
const base = path12.join(
|
|
9376
|
-
const dirs =
|
|
9526
|
+
function hookSeenCheck(row, dataRoot) {
|
|
9527
|
+
const base = path12.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9528
|
+
const dirs = existsSync16(base) ? readdirSync5(base) : [];
|
|
9377
9529
|
let sqlite;
|
|
9378
9530
|
try {
|
|
9379
9531
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9382,7 +9534,7 @@ function hookSeenCheck(row, home) {
|
|
|
9382
9534
|
}
|
|
9383
9535
|
for (const d of dirs) {
|
|
9384
9536
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9385
|
-
if (!sqlite || !
|
|
9537
|
+
if (!sqlite || !existsSync16(file)) continue;
|
|
9386
9538
|
let db;
|
|
9387
9539
|
try {
|
|
9388
9540
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9399,7 +9551,7 @@ function skillsCheck(row, pkgDir) {
|
|
|
9399
9551
|
const s = row.skillInstall;
|
|
9400
9552
|
if (s.kind === "package") {
|
|
9401
9553
|
const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
9402
|
-
const miss = files.filter((f2) => !
|
|
9554
|
+
const miss = files.filter((f2) => !existsSync16(f2));
|
|
9403
9555
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
9404
9556
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
9405
9557
|
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
@@ -9409,7 +9561,7 @@ function skillsCheck(row, pkgDir) {
|
|
|
9409
9561
|
});
|
|
9410
9562
|
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
9411
9563
|
}
|
|
9412
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9564
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync16(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9413
9565
|
return { name: "skills", ok: bad.length === 0, detail: bad.length ? `${bad.map((f2) => f2.file).join(", ")} missing or without the ${s.prefixes.join(" / ") || "plain"} tool prefix` : void 0 };
|
|
9414
9566
|
}
|
|
9415
9567
|
var PLUGIN_ENABLED = "enabled";
|
|
@@ -9427,6 +9579,7 @@ function extensionState(n3, text2) {
|
|
|
9427
9579
|
let mine = false;
|
|
9428
9580
|
let state;
|
|
9429
9581
|
let workspaceOff = false;
|
|
9582
|
+
let workspaceOn = false;
|
|
9430
9583
|
for (const raw of text2.split("\n")) {
|
|
9431
9584
|
const line = raw.trimEnd();
|
|
9432
9585
|
if (line.length && !line.startsWith(" ")) {
|
|
@@ -9436,16 +9589,37 @@ function extensionState(n3, text2) {
|
|
|
9436
9589
|
const t2 = line.trim();
|
|
9437
9590
|
if (!mine) continue;
|
|
9438
9591
|
if (t2.startsWith(EXT_ENABLED_USER)) state = t2.slice(EXT_ENABLED_USER.length).trim() === EXT_TRUE ? "enabled" : "disabled";
|
|
9439
|
-
if (t2.startsWith(EXT_ENABLED_WORKSPACE))
|
|
9592
|
+
if (t2.startsWith(EXT_ENABLED_WORKSPACE)) {
|
|
9593
|
+
workspaceOff = t2.slice(EXT_ENABLED_WORKSPACE.length).trim() !== EXT_TRUE;
|
|
9594
|
+
workspaceOn = !workspaceOff;
|
|
9595
|
+
}
|
|
9440
9596
|
}
|
|
9597
|
+
if (state === "disabled" && workspaceOn) state = "enabled";
|
|
9441
9598
|
return { state, workspaceOff };
|
|
9442
9599
|
}
|
|
9600
|
+
function jsonState(n3, text2) {
|
|
9601
|
+
const none = { state: void 0, workspaceOff: false };
|
|
9602
|
+
let doc;
|
|
9603
|
+
try {
|
|
9604
|
+
doc = JSON.parse(text2);
|
|
9605
|
+
} catch {
|
|
9606
|
+
return none;
|
|
9607
|
+
}
|
|
9608
|
+
const mine = Array.isArray(doc) ? doc.find((p3) => isObj5(p3) && p3.id === n3.plugin) : void 0;
|
|
9609
|
+
if (!isObj5(mine)) return none;
|
|
9610
|
+
if (mine.enabled !== true) return { state: "disabled", workspaceOff: false };
|
|
9611
|
+
const hooks = Array.isArray(mine.hookDetails) ? mine.hookDetails : [];
|
|
9612
|
+
const own2 = `${AGENT_FLAG} ${n3.bin}`;
|
|
9613
|
+
const hookGate = hooks.some((h2) => isObj5(h2) && typeof h2.command === "string" && h2.command.includes(own2)) ? void 0 : `the installed ${n3.plugin} runs no ${own2} hook; run: ${n3.bin} plugins update ${n3.plugin}`;
|
|
9614
|
+
return { state: "enabled", workspaceOff: false, hookGate };
|
|
9615
|
+
}
|
|
9443
9616
|
function nativeState(row, env) {
|
|
9444
9617
|
const none = { state: void 0, workspaceOff: false };
|
|
9445
9618
|
const n3 = row.nativePlugin;
|
|
9446
9619
|
if (!n3 || !hostBin(n3.bin, env).file) return none;
|
|
9447
9620
|
const r2 = runBin(n3.bin, n3.args, env);
|
|
9448
9621
|
if (r2.status !== 0) return none;
|
|
9622
|
+
if (n3.format === "json") return jsonState(n3, `${r2.stdout}`);
|
|
9449
9623
|
return n3.format === "extension" ? extensionState(n3, `${r2.stdout}${r2.stderr}`) : { state: tableState(n3, `${r2.stdout}`), workspaceOff: false };
|
|
9450
9624
|
}
|
|
9451
9625
|
function nativeRow(row, n3) {
|
|
@@ -9469,7 +9643,7 @@ function trimChars(w, chars) {
|
|
|
9469
9643
|
}
|
|
9470
9644
|
async function nativeResult(row, ctx, apply2) {
|
|
9471
9645
|
const n3 = row.nativePlugin;
|
|
9472
|
-
const { state, workspaceOff } = nativeState(row, ctx.env);
|
|
9646
|
+
const { state, workspaceOff, hookGate } = nativeState(row, ctx.env);
|
|
9473
9647
|
if (!n3 || state === void 0) return void 0;
|
|
9474
9648
|
const bin = hostBin(n3.bin, ctx.env).file;
|
|
9475
9649
|
if (state === "disabled") {
|
|
@@ -9499,6 +9673,7 @@ async function nativeResult(row, ctx, apply2) {
|
|
|
9499
9673
|
res.checks = await verifyRow(nativeRow(row, n3), ctx);
|
|
9500
9674
|
if (n3.hookTrust) res.checks = withHookTrust(res.checks, hooks, !!apply2?.dryRun);
|
|
9501
9675
|
if (n3.format === "extension") res.checks = withHookGate(res.checks, geminiGate(n3, ctx, workspaceOff));
|
|
9676
|
+
if (n3.format === "json") res.checks = withHookGate(res.checks, hookGate);
|
|
9502
9677
|
const bad = res.checks.filter((c3) => !c3.ok);
|
|
9503
9678
|
if (bad.length) {
|
|
9504
9679
|
res.status = "FAIL";
|
|
@@ -9618,7 +9793,7 @@ async function verifyRow(row, ctx) {
|
|
|
9618
9793
|
const en = hookEnabledCheck(row, ls.status);
|
|
9619
9794
|
if (en) checks.push(en);
|
|
9620
9795
|
if (row.copilotSettings) checks.push(await copilotEnabledCheck(row, ctx));
|
|
9621
|
-
checks.push(hookRunsCheck(row, env), hookSeenCheck(row, ctx.home), skillsCheck(row, ctx.pkgDir));
|
|
9796
|
+
checks.push(hookRunsCheck(row, env), hookSeenCheck(row, dataRootOf(env, ctx.home)), skillsCheck(row, ctx.pkgDir));
|
|
9622
9797
|
if (row.id === "pi") return withHookGate(checks, piSettingsGate(env, ctx.home, ctx.pkgDir, process.cwd()));
|
|
9623
9798
|
if (row.id === "vscode") return withHookGate(checks, vscodeSettingsGate(env, ctx.home, process.cwd()));
|
|
9624
9799
|
return row.id === "zcode" ? withHookGate(checks, zcodeConfigGate(ctx.home)) : checks;
|
|
@@ -9690,20 +9865,21 @@ function agentHomeDir(id, ctx) {
|
|
|
9690
9865
|
if (id === "copilot-cli") return copilotDirOf(ctx.env, ctx.home);
|
|
9691
9866
|
if (id === "kiro") return kiroDirOf(ctx.env, ctx.home);
|
|
9692
9867
|
if (id === "opencode") return opencodeDirOf(ctx.env, ctx.home);
|
|
9868
|
+
if (id === "gemini") return geminiDirOf(ctx.env, ctx.home);
|
|
9693
9869
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9694
9870
|
}
|
|
9695
9871
|
function detectAgents(reg, ctx) {
|
|
9696
|
-
return reg.filter((r2) =>
|
|
9872
|
+
return reg.filter((r2) => existsSync16(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9697
9873
|
}
|
|
9698
9874
|
async function runSetup(opts) {
|
|
9699
9875
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9700
9876
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9701
9877
|
const reg = buildRegistry(ctx);
|
|
9702
9878
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9703
|
-
if (!
|
|
9879
|
+
if (!existsSync16(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9704
9880
|
}
|
|
9705
9881
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9706
|
-
const root =
|
|
9882
|
+
const root = dataRootOf(ctx.env, ctx.home);
|
|
9707
9883
|
if (!opts.dryRun) {
|
|
9708
9884
|
const held = takeLock(root, runId);
|
|
9709
9885
|
if (held) return { exitCode: 1, agents: [], error: held };
|
|
@@ -9756,7 +9932,7 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9756
9932
|
return { ...res, status: "FAIL", reason: e.message };
|
|
9757
9933
|
}
|
|
9758
9934
|
const configEdited = (file) => plan.edits.some((e) => e.file === file && e.changes.some((c3) => !isTrust(row, c3)));
|
|
9759
|
-
res.v1 = detectV1(row.id, ctx.home, { claudeDir: claudeDirOf(ctx.env, ctx.home), codexDir: codexDirOf(ctx.env, ctx.home), copilotDir: copilotDirOf(ctx.env, ctx.home), kiroDir: kiroDirOf(ctx.env, ctx.home), opencodeDir: opencodeDirOf(ctx.env, ctx.home) }).filter((f2) => !(row.config && f2.file === row.config.file && !configEdited(f2.file)));
|
|
9935
|
+
res.v1 = detectV1(row.id, ctx.home, { claudeDir: claudeDirOf(ctx.env, ctx.home), codexDir: codexDirOf(ctx.env, ctx.home), geminiDir: geminiDirOf(ctx.env, ctx.home), copilotDir: copilotDirOf(ctx.env, ctx.home), kiroDir: kiroDirOf(ctx.env, ctx.home), opencodeDir: opencodeDirOf(ctx.env, ctx.home) }).filter((f2) => !(row.config && f2.file === row.config.file && !configEdited(f2.file)));
|
|
9760
9936
|
res.changes = [...plan.edits.flatMap((e) => e.changes), ...[...plan.cli, ...plan.refresh].map((args) => ({ command: [row.cli.bin, ...args] }))];
|
|
9761
9937
|
if (dryRun) return res;
|
|
9762
9938
|
try {
|
|
@@ -9794,10 +9970,10 @@ async function runDoctor(opts) {
|
|
|
9794
9970
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9795
9971
|
const reg = buildRegistry(ctx);
|
|
9796
9972
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9797
|
-
if (!
|
|
9973
|
+
if (!existsSync16(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9798
9974
|
}
|
|
9799
9975
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9800
|
-
const run = new Run(
|
|
9976
|
+
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
9801
9977
|
const agents = [];
|
|
9802
9978
|
for (const id of ids) {
|
|
9803
9979
|
const row = reg.find((r2) => r2.id === id);
|
|
@@ -9838,7 +10014,9 @@ function notSetUpReason(row, res, env) {
|
|
|
9838
10014
|
const h2 = row.hookInstall;
|
|
9839
10015
|
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
9840
10016
|
const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
9841
|
-
|
|
10017
|
+
if (oc2) return `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode`;
|
|
10018
|
+
if (row.id === "gemini" && hostBin("gemini", env).file !== void 0) return `${NOT_SET_UP_REASON}, or run: ${NATIVE_INSTALL.gemini[0]}`;
|
|
10019
|
+
return NOT_SET_UP_REASON;
|
|
9842
10020
|
}
|
|
9843
10021
|
function hasPluginIssue(row) {
|
|
9844
10022
|
const h2 = row.hookInstall;
|
|
@@ -9860,14 +10038,14 @@ function isTrust(row, c3) {
|
|
|
9860
10038
|
}
|
|
9861
10039
|
function runRemove(opts) {
|
|
9862
10040
|
const env = opts.env ?? process.env;
|
|
9863
|
-
const root =
|
|
10041
|
+
const root = dataRootOf(env, opts.home);
|
|
9864
10042
|
const base = path12.join(root, BACKUP_DIR);
|
|
9865
|
-
if (!
|
|
10043
|
+
if (!existsSync16(base)) return { exitCode: 0, restored: 0 };
|
|
9866
10044
|
const held = takeLock(root, "remove");
|
|
9867
10045
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
9868
10046
|
let restored = 0;
|
|
9869
10047
|
try {
|
|
9870
|
-
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) =>
|
|
10048
|
+
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync16(path12.join(d, MANIFEST))).sort().reverse();
|
|
9871
10049
|
for (const dir of runs) {
|
|
9872
10050
|
const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
|
|
9873
10051
|
undo(dir, m3.entries, env);
|
|
@@ -10080,7 +10258,7 @@ async function report(ui, command, res, write) {
|
|
|
10080
10258
|
const { text: text2, title } = buildIssueReport(command, res, ui);
|
|
10081
10259
|
let file = "";
|
|
10082
10260
|
if (write) {
|
|
10083
|
-
const dir = path13.join(ui.ctx.
|
|
10261
|
+
const dir = path13.join(dataRootOf(ui.ctx.env, ui.ctx.home), REPORT_DIR);
|
|
10084
10262
|
mkdirSync6(dir, { recursive: true });
|
|
10085
10263
|
file = path13.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
10086
10264
|
writeFileSync4(file, text2);
|
|
@@ -10191,7 +10369,7 @@ async function remove(ui) {
|
|
|
10191
10369
|
}
|
|
10192
10370
|
}
|
|
10193
10371
|
if (ui.f.dryRun) {
|
|
10194
|
-
out(`Would restore every file recorded under ${path13.join(ui.ctx.
|
|
10372
|
+
out(`Would restore every file recorded under ${path13.join(dataRootOf(ui.ctx.env, ui.ctx.home), "backups")}`);
|
|
10195
10373
|
return EXIT_OK;
|
|
10196
10374
|
}
|
|
10197
10375
|
const r2 = runRemove({ home: ui.ctx.home, env: ui.ctx.env });
|
|
@@ -10331,7 +10509,7 @@ async function upgrade(ui) {
|
|
|
10331
10509
|
}
|
|
10332
10510
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10333
10511
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
10334
|
-
if (!root || !
|
|
10512
|
+
if (!root || !existsSync17(cli)) {
|
|
10335
10513
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10336
10514
|
return EXIT_FAIL;
|
|
10337
10515
|
}
|
|
@@ -10370,12 +10548,12 @@ Run context-mode ${cmd} --help.`);
|
|
|
10370
10548
|
}
|
|
10371
10549
|
|
|
10372
10550
|
// src/entries/is-entry.ts
|
|
10373
|
-
import { realpathSync as
|
|
10551
|
+
import { realpathSync as realpathSync10 } from "node:fs";
|
|
10374
10552
|
function isEntry(main2, argv1, self) {
|
|
10375
10553
|
if (main2 !== void 0) return main2;
|
|
10376
10554
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
10377
10555
|
try {
|
|
10378
|
-
return
|
|
10556
|
+
return realpathSync10(argv1) === realpathSync10(self);
|
|
10379
10557
|
} catch {
|
|
10380
10558
|
return false;
|
|
10381
10559
|
}
|
|
@@ -10426,7 +10604,7 @@ function route(argv, version) {
|
|
|
10426
10604
|
` };
|
|
10427
10605
|
}
|
|
10428
10606
|
function main() {
|
|
10429
|
-
const dir = path14.dirname(
|
|
10607
|
+
const dir = path14.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
|
|
10430
10608
|
let version = "";
|
|
10431
10609
|
try {
|
|
10432
10610
|
version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|