context-mode 2.1.3 → 2.1.5
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 +389 -173
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +99 -97
- package/opencode/plugin.js +2774 -727
- package/package.json +2 -1
- package/pi/index.js +2796 -728
- package/qwen-extension.json +1 -1
- package/run.mjs +340 -128
- package/search.mjs +340 -128
- package/server.mjs +2507 -549
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
|
|
|
@@ -237,12 +237,13 @@ var HOOK_TIMEOUT_MS = 5e3;
|
|
|
237
237
|
var IN_PROCESS_TIMEOUT_MS = 0;
|
|
238
238
|
var PROJECTS_DIR_NAME = "projects";
|
|
239
239
|
var DB_FILE_NAME = "context.db";
|
|
240
|
-
var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
|
|
241
240
|
var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
|
|
241
|
+
var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
242
242
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
243
243
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
244
244
|
var NODE_MIN = "24.15.0";
|
|
245
245
|
var DATA_ROOT = "~/.context-mode";
|
|
246
|
+
var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
|
|
246
247
|
var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
247
248
|
var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
|
|
248
249
|
var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
|
|
@@ -295,7 +296,31 @@ var SHELL_DUMP_COMMANDS = Object.freeze(["cat", "head", "tail", "sed", "less", "
|
|
|
295
296
|
var DUMP_COUNT_COMMANDS = Object.freeze(["head", "tail"]);
|
|
296
297
|
var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
297
298
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
298
|
-
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path"]);
|
|
299
|
+
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
|
|
300
|
+
var READ_MEDIA_TYPES = Object.freeze({
|
|
301
|
+
png: { exts: [".png"], sig: [{ at: 0, bytes: [137, 80, 78, 71, 13, 10, 26, 10] }] },
|
|
302
|
+
jpeg: { exts: [".jpg", ".jpeg"], sig: [{ at: 0, bytes: [255, 216, 255] }] },
|
|
303
|
+
gif: { exts: [".gif"], sig: [{ at: 0, bytes: [71, 73, 70, 56] }] },
|
|
304
|
+
// "GIF8"
|
|
305
|
+
webp: { exts: [".webp"], sig: [{ at: 0, bytes: [82, 73, 70, 70] }, { at: 8, bytes: [87, 69, 66, 80] }] },
|
|
306
|
+
// "RIFF" .... "WEBP"
|
|
307
|
+
pdf: { exts: [".pdf"], sig: [{ at: 0, bytes: [37, 80, 68, 70, 45] }] }
|
|
308
|
+
// "%PDF-"
|
|
309
|
+
});
|
|
310
|
+
var READ_IMAGES = Object.freeze(["png", "jpeg", "gif", "webp"]);
|
|
311
|
+
var READ_IMAGES_AND_PDF = Object.freeze([...READ_IMAGES, "pdf"]);
|
|
312
|
+
var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
313
|
+
"claude-code": READ_IMAGES_AND_PDF,
|
|
314
|
+
gemini: READ_IMAGES_AND_PDF,
|
|
315
|
+
qwen: READ_IMAGES_AND_PDF,
|
|
316
|
+
opencode: READ_IMAGES_AND_PDF,
|
|
317
|
+
pi: READ_IMAGES,
|
|
318
|
+
vscode: READ_IMAGES,
|
|
319
|
+
"copilot-cli": [],
|
|
320
|
+
codex: [],
|
|
321
|
+
kiro: [],
|
|
322
|
+
zcode: []
|
|
323
|
+
});
|
|
299
324
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
300
325
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
301
326
|
var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
|
|
@@ -365,18 +390,17 @@ var AGENT_HOME_DIR = Object.freeze({
|
|
|
365
390
|
var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
366
391
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
367
392
|
var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
|
|
368
|
-
var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
|
|
369
393
|
var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
|
|
370
394
|
var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
|
|
371
395
|
var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
|
|
372
396
|
var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
|
|
397
|
+
var PERSISTED_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
|
|
373
398
|
var OPS_SPLIT_FILES = Object.freeze([
|
|
374
399
|
"doctor-env.ts",
|
|
375
400
|
"doctor-config.ts",
|
|
376
401
|
"doctor-hook.ts",
|
|
377
402
|
"doctor-db.ts",
|
|
378
403
|
"doctor-heal.ts",
|
|
379
|
-
"release-fetch.ts",
|
|
380
404
|
"verify-sums.ts",
|
|
381
405
|
"plugin-swap.ts",
|
|
382
406
|
"host-write.ts",
|
|
@@ -409,10 +433,18 @@ var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
|
409
433
|
var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
|
|
410
434
|
var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
411
435
|
"claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
|
|
412
|
-
codex: "
|
|
413
|
-
gemini: "gemini extensions
|
|
414
|
-
qwen: "qwen extensions
|
|
436
|
+
codex: "codex plugin marketplace upgrade context-mode",
|
|
437
|
+
gemini: "gemini extensions update context-mode",
|
|
438
|
+
qwen: "qwen extensions update context-mode",
|
|
439
|
+
pi: "pi update --extensions",
|
|
440
|
+
opencode: "opencode plugin update",
|
|
441
|
+
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
442
|
+
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
443
|
+
kiro: "npm i -g context-mode && context-mode setup --agents kiro",
|
|
444
|
+
zcode: "npm i -g context-mode && context-mode setup --agents zcode"
|
|
415
445
|
});
|
|
446
|
+
var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
|
|
447
|
+
var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
|
|
416
448
|
var V1_SCRIPT_NAMES = Object.freeze([
|
|
417
449
|
"afteragentresponse.mjs",
|
|
418
450
|
"aftermodel.mjs",
|
|
@@ -450,6 +482,7 @@ var HOOKS_JSON_FILE = "hooks.json";
|
|
|
450
482
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
451
483
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
452
484
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
485
|
+
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
453
486
|
var KIRO_HOME_ENV = "KIRO_HOME";
|
|
454
487
|
var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
|
|
455
488
|
var APPDATA_ENV = "APPDATA";
|
|
@@ -476,6 +509,9 @@ var STATUS_LINE_KEY = "statusLine";
|
|
|
476
509
|
var PI_PACKAGES_KEY = "packages";
|
|
477
510
|
var OPENCODE_PLUGIN_KEY = "plugin";
|
|
478
511
|
var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
|
|
512
|
+
var NPM_VERSION_SEP = "@";
|
|
513
|
+
var OPENCODE_NPM_LATEST = `${OPENCODE_NPM_SPEC_PREFIX}latest`;
|
|
514
|
+
var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
|
|
479
515
|
var V1_DATA_DIR_NAME = "context-mode";
|
|
480
516
|
var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
|
|
481
517
|
var V1_SESSIONS_DIR_NAME = "sessions";
|
|
@@ -504,16 +540,19 @@ var V1_REASON = Object.freeze({
|
|
|
504
540
|
kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
|
|
505
541
|
piNpm: "old context-mode Pi package npm:context-mode",
|
|
506
542
|
opencodePlugin: "old context-mode OpenCode plugin spec context-mode",
|
|
543
|
+
piGit: "old context-mode Pi entry git:github.com/mksglu/context-mode@release: ctx_upgrade replaces it with npm:context-mode@latest",
|
|
544
|
+
opencodeGit: "old context-mode OpenCode entry git+https://github.com/mksglu/context-mode.git#release: ctx_upgrade replaces it with context-mode@latest",
|
|
507
545
|
zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
|
|
508
546
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
509
547
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
510
548
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
511
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
549
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep",
|
|
550
|
+
projectLink: "context-mode path in the project reached through a link: report only, upgrade keeps it as is and never follows a link"
|
|
512
551
|
});
|
|
513
|
-
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
552
|
+
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]);
|
|
553
|
+
var UPGRADE_KEEP_ASIDE_REASONS = Object.freeze([V1_REASON.dataDir, V1_REASON.dataRoot]);
|
|
514
554
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
515
555
|
var SERVER_ENTRY_FILE = "server.mjs";
|
|
516
|
-
var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
|
|
517
556
|
var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
|
|
518
557
|
var HOST_NODE_COMMAND = "node";
|
|
519
558
|
var EXE_SUFFIX = ".exe";
|
|
@@ -609,7 +648,7 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
609
648
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
610
649
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
611
650
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
612
|
-
zcode: ["
|
|
651
|
+
zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
|
|
613
652
|
});
|
|
614
653
|
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
615
654
|
|
|
@@ -626,9 +665,9 @@ function canonicalName(name, ownPrefix) {
|
|
|
626
665
|
if (name.startsWith(ownPrefix)) return name.slice(ownPrefix.length);
|
|
627
666
|
if (!name.startsWith(MCP_PREFIX)) return name;
|
|
628
667
|
const rest = name.slice(MCP_PREFIX.length);
|
|
629
|
-
const
|
|
630
|
-
if (
|
|
631
|
-
return "mcp:" + rest.slice(0,
|
|
668
|
+
const sep3 = rest.indexOf(MCP_SEP);
|
|
669
|
+
if (sep3 < 0) return name;
|
|
670
|
+
return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP.length);
|
|
632
671
|
}
|
|
633
672
|
function outputOf(resp) {
|
|
634
673
|
if (resp === void 0) return "";
|
|
@@ -808,10 +847,17 @@ function encode(ev, d, _extra) {
|
|
|
808
847
|
// src/adapters/codex.ts
|
|
809
848
|
var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
|
|
810
849
|
var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
|
|
850
|
+
var STOP_EVENT = "Stop";
|
|
851
|
+
var EMPTY = { stdout: "", exitCode: 0 };
|
|
811
852
|
function decode2(raw) {
|
|
853
|
+
if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
|
|
854
|
+
const p3 = raw;
|
|
855
|
+
return { event: STOP_EVENT, agent: "codex", sessionId: String(p3.session_id ?? ""), cwd: String(p3.cwd ?? "") };
|
|
856
|
+
}
|
|
812
857
|
return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
|
|
813
858
|
}
|
|
814
859
|
function encode2(ev, d, _extra) {
|
|
860
|
+
if (ev.event === STOP_EVENT) return EMPTY;
|
|
815
861
|
return encodeClaudeShape(ev, d, false);
|
|
816
862
|
}
|
|
817
863
|
|
|
@@ -827,7 +873,8 @@ var GEMINI_EVENTS = {
|
|
|
827
873
|
var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
828
874
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
829
875
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
830
|
-
var
|
|
876
|
+
var EMPTY2 = { stdout: "", exitCode: 0 };
|
|
877
|
+
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";
|
|
831
878
|
function own(p3, key) {
|
|
832
879
|
return Object.hasOwn(p3, key) ? p3[key] : void 0;
|
|
833
880
|
}
|
|
@@ -847,12 +894,72 @@ function canonicalName2(name, mcp) {
|
|
|
847
894
|
if (typeof server !== "string" || typeof tool !== "string") return name;
|
|
848
895
|
return "mcp:" + server + ":" + tool;
|
|
849
896
|
}
|
|
897
|
+
function partsText(llm) {
|
|
898
|
+
if (!Array.isArray(llm) || llm.length === 0) return void 0;
|
|
899
|
+
const out2 = [];
|
|
900
|
+
for (const part of llm) {
|
|
901
|
+
if (typeof part === "string") {
|
|
902
|
+
out2.push(part);
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
if (typeof part !== "object" || part === null) return void 0;
|
|
906
|
+
const t2 = own(part, "text");
|
|
907
|
+
if (typeof t2 !== "string") return void 0;
|
|
908
|
+
out2.push(t2);
|
|
909
|
+
}
|
|
910
|
+
return out2.join("");
|
|
911
|
+
}
|
|
850
912
|
function readResult2(resp) {
|
|
851
913
|
const obj = typeof resp === "object" && resp !== null ? resp : void 0;
|
|
852
914
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
853
|
-
const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : JSON.stringify(resp);
|
|
915
|
+
const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
854
916
|
const err2 = obj === void 0 ? void 0 : own(obj, "error");
|
|
855
|
-
|
|
917
|
+
const info = { isError: err2 !== void 0 && err2 !== null, bytes: Buffer.byteLength(text2), text: text2 };
|
|
918
|
+
if (hasMediaPart(llm)) info.keep = true;
|
|
919
|
+
return info;
|
|
920
|
+
}
|
|
921
|
+
function hasMediaPart(llm) {
|
|
922
|
+
const parts = Array.isArray(llm) ? llm : [llm];
|
|
923
|
+
return parts.some((p3) => typeof p3 === "object" && p3 !== null && (Object.hasOwn(p3, "inlineData") || Object.hasOwn(p3, "fileData")));
|
|
924
|
+
}
|
|
925
|
+
var URL_STARTS = ["https://", "http://"];
|
|
926
|
+
var URL_TRAIL = `.,;:!?)]}>'"`;
|
|
927
|
+
var SPACE = " \n\r\f\v";
|
|
928
|
+
function words(text2) {
|
|
929
|
+
const out2 = [];
|
|
930
|
+
let cur = "";
|
|
931
|
+
for (const ch of text2) {
|
|
932
|
+
if (SPACE.includes(ch)) {
|
|
933
|
+
if (cur !== "") out2.push(cur);
|
|
934
|
+
cur = "";
|
|
935
|
+
} else cur += ch;
|
|
936
|
+
}
|
|
937
|
+
if (cur !== "") out2.push(cur);
|
|
938
|
+
return out2;
|
|
939
|
+
}
|
|
940
|
+
function firstUrl(prompt) {
|
|
941
|
+
if (typeof prompt !== "string") return void 0;
|
|
942
|
+
for (const word of words(prompt)) {
|
|
943
|
+
const lower = word.toLowerCase();
|
|
944
|
+
const at = URL_STARTS.map((s) => lower.indexOf(s)).filter((i2) => i2 >= 0).sort((a2, b3) => a2 - b3)[0];
|
|
945
|
+
if (at === void 0) continue;
|
|
946
|
+
let url = word.slice(at);
|
|
947
|
+
while (url.length > 0 && URL_TRAIL.includes(url[url.length - 1])) url = url.slice(0, -1);
|
|
948
|
+
return url;
|
|
949
|
+
}
|
|
950
|
+
return void 0;
|
|
951
|
+
}
|
|
952
|
+
function nativeInput(name, input) {
|
|
953
|
+
if (name === "web_fetch" && own(input, "url") === void 0) {
|
|
954
|
+
const url = firstUrl(own(input, "prompt"));
|
|
955
|
+
return url === void 0 ? input : { ...input, url };
|
|
956
|
+
}
|
|
957
|
+
if (name === "read_many_files" && own(input, "file_path") === void 0) {
|
|
958
|
+
const inc = own(input, "include");
|
|
959
|
+
const list2 = Array.isArray(inc) ? inc.filter((v) => typeof v === "string") : [];
|
|
960
|
+
return list2.length === 0 ? input : { ...input, file_path: list2.join(" ") };
|
|
961
|
+
}
|
|
962
|
+
return input;
|
|
856
963
|
}
|
|
857
964
|
function decode3(raw) {
|
|
858
965
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
|
|
@@ -871,7 +978,7 @@ function decode3(raw) {
|
|
|
871
978
|
ev.tool = {
|
|
872
979
|
name,
|
|
873
980
|
canonicalName: canonicalName2(name, own(p3, "mcp_context")),
|
|
874
|
-
input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
981
|
+
input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
|
|
875
982
|
};
|
|
876
983
|
}
|
|
877
984
|
if (event === "PostToolUse") ev.result = readResult2(own(p3, "tool_response"));
|
|
@@ -880,16 +987,16 @@ function decode3(raw) {
|
|
|
880
987
|
function encode3(ev, d, _extra) {
|
|
881
988
|
switch (d.kind) {
|
|
882
989
|
case "allow":
|
|
883
|
-
return
|
|
990
|
+
return EMPTY2;
|
|
884
991
|
case "hint":
|
|
885
|
-
if (!HINT_EVENTS.includes(ev.event)) return
|
|
992
|
+
if (!HINT_EVENTS.includes(ev.event)) return EMPTY2;
|
|
886
993
|
return { stdout: JSON.stringify({ hookSpecificOutput: { additionalContext: d.text } }), exitCode: 0 };
|
|
887
994
|
case "deny":
|
|
888
|
-
if (!DENY_EVENTS.includes(ev.event)) return
|
|
995
|
+
if (!DENY_EVENTS.includes(ev.event)) return EMPTY2;
|
|
889
996
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
890
997
|
case "replace":
|
|
891
|
-
if (ev.event !== "PostToolUse") return
|
|
892
|
-
return { stdout: JSON.stringify({ decision: "deny", reason: d.output }), exitCode: 0 };
|
|
998
|
+
if (ev.event !== "PostToolUse") return EMPTY2;
|
|
999
|
+
return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
|
|
893
1000
|
}
|
|
894
1001
|
}
|
|
895
1002
|
|
|
@@ -1008,21 +1115,21 @@ function decode5(raw) {
|
|
|
1008
1115
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
1009
1116
|
return ev;
|
|
1010
1117
|
}
|
|
1011
|
-
var
|
|
1118
|
+
var EMPTY3 = { stdout: "", exitCode: 0 };
|
|
1012
1119
|
function encode5(ev, d, _extra) {
|
|
1013
1120
|
switch (d.kind) {
|
|
1014
1121
|
case "allow":
|
|
1015
|
-
return
|
|
1122
|
+
return EMPTY3;
|
|
1016
1123
|
case "hint":
|
|
1017
|
-
return ev.event === "PostToolUse" ?
|
|
1124
|
+
return ev.event === "PostToolUse" ? EMPTY3 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
|
|
1018
1125
|
case "deny":
|
|
1019
|
-
if (ev.event !== "PreToolUse") return
|
|
1126
|
+
if (ev.event !== "PreToolUse") return EMPTY3;
|
|
1020
1127
|
return {
|
|
1021
1128
|
stdout: JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }),
|
|
1022
1129
|
exitCode: 0
|
|
1023
1130
|
};
|
|
1024
1131
|
case "replace":
|
|
1025
|
-
if (ev.event !== "PostToolUse") return
|
|
1132
|
+
if (ev.event !== "PostToolUse") return EMPTY3;
|
|
1026
1133
|
return { stdout: JSON.stringify({ modifiedResult: { resultType: RESULT_SUCCESS, textResultForLlm: d.output } }), exitCode: 0 };
|
|
1027
1134
|
}
|
|
1028
1135
|
}
|
|
@@ -1046,9 +1153,9 @@ function canonicalName4(name) {
|
|
|
1046
1153
|
if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
|
|
1047
1154
|
if (!name.startsWith(MCP_PREFIX2)) return name;
|
|
1048
1155
|
const rest = name.slice(MCP_PREFIX2.length);
|
|
1049
|
-
const
|
|
1050
|
-
if (
|
|
1051
|
-
return "mcp:" + rest.slice(0,
|
|
1156
|
+
const sep3 = rest.indexOf(MCP_SEP2);
|
|
1157
|
+
if (sep3 <= 0 || sep3 === rest.length - 1) return name;
|
|
1158
|
+
return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP2.length);
|
|
1052
1159
|
}
|
|
1053
1160
|
var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1054
1161
|
function policyInput(name, canonical, input) {
|
|
@@ -1177,9 +1284,9 @@ function canonicalName5(name) {
|
|
|
1177
1284
|
if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
|
|
1178
1285
|
if (!name.startsWith(MCP_PREFIX3)) return name;
|
|
1179
1286
|
const rest = name.slice(MCP_PREFIX3.length);
|
|
1180
|
-
const
|
|
1181
|
-
if (
|
|
1182
|
-
return "mcp:" + rest.slice(0,
|
|
1287
|
+
const sep3 = rest.indexOf(MCP_SEP3);
|
|
1288
|
+
if (sep3 <= 0 || sep3 === rest.length - 1) return name;
|
|
1289
|
+
return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP3.length);
|
|
1183
1290
|
}
|
|
1184
1291
|
function readResult5(resp) {
|
|
1185
1292
|
const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
|
|
@@ -1222,6 +1329,7 @@ function encode7(ev, d, _extra) {
|
|
|
1222
1329
|
|
|
1223
1330
|
// src/adapters/zcode.ts
|
|
1224
1331
|
var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
|
|
1332
|
+
var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1225
1333
|
var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1226
1334
|
var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
|
|
1227
1335
|
var FAILURE_EVENT2 = "PostToolUseFailure";
|
|
@@ -1231,7 +1339,9 @@ function decode8(raw) {
|
|
|
1231
1339
|
for (const [snake2, camel] of Object.entries(TWINS)) if (p3[snake2] === void 0) p3[snake2] = p3[camel];
|
|
1232
1340
|
const failure = p3.hook_event_name === FAILURE_EVENT2;
|
|
1233
1341
|
if (failure) p3.hook_event_name = "PostToolUse";
|
|
1234
|
-
const
|
|
1342
|
+
const toolName = typeof p3.tool_name === "string" ? p3.tool_name : "";
|
|
1343
|
+
const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
|
|
1344
|
+
const ev = decodeClaudeShape(p3, "zcode", prefix, ZCODE_SOURCES);
|
|
1235
1345
|
if (failure) {
|
|
1236
1346
|
const text2 = typeof p3.error === "string" ? p3.error : p3.error === void 0 ? "" : JSON.stringify(p3.error);
|
|
1237
1347
|
ev.result = { isError: true, bytes: Buffer.byteLength(text2), text: text2 };
|
|
@@ -1312,8 +1422,9 @@ var OPENCODE_EVENTS = {
|
|
|
1312
1422
|
"step-finish": "Usage"
|
|
1313
1423
|
};
|
|
1314
1424
|
var SHELL_TOOL_NAME = "bash";
|
|
1425
|
+
var READ_TOOL_NAME = "read";
|
|
1315
1426
|
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1316
|
-
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n3) => [n3, "Bash"])) };
|
|
1427
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n3) => [n3, "Bash"])) };
|
|
1317
1428
|
function toCanonicalTool(name) {
|
|
1318
1429
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1319
1430
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -1541,9 +1652,9 @@ var ADAPTERS = Object.freeze([
|
|
|
1541
1652
|
installMode: "in-process",
|
|
1542
1653
|
projectSource: "spawn-cwd",
|
|
1543
1654
|
toolNamePrefix: TOOL_NAME_PREFIX10,
|
|
1544
|
-
nativeTools: { shell: [SHELL_TOOL_NAME] },
|
|
1655
|
+
nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
|
|
1545
1656
|
execReadOnlyHint: false,
|
|
1546
|
-
// D-HF-OPENCODE-SHELL-1
|
|
1657
|
+
// D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
|
|
1547
1658
|
// Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
|
|
1548
1659
|
eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
|
|
1549
1660
|
compactDelivery: "opencode-cache",
|
|
@@ -1773,7 +1884,7 @@ Examples:
|
|
|
1773
1884
|
// src/cli/commands.ts
|
|
1774
1885
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1775
1886
|
import { createHash as createHash2 } from "node:crypto";
|
|
1776
|
-
import { existsSync as
|
|
1887
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1777
1888
|
import os from "node:os";
|
|
1778
1889
|
import path13 from "node:path";
|
|
1779
1890
|
|
|
@@ -2064,18 +2175,18 @@ var wrapWord = (rows, word, columns) => {
|
|
|
2064
2175
|
}
|
|
2065
2176
|
};
|
|
2066
2177
|
var stringVisibleTrimSpacesRight = (string) => {
|
|
2067
|
-
const
|
|
2068
|
-
let last2 =
|
|
2178
|
+
const words2 = string.split(" ");
|
|
2179
|
+
let last2 = words2.length;
|
|
2069
2180
|
while (last2) {
|
|
2070
|
-
if (dist_default2(
|
|
2181
|
+
if (dist_default2(words2[last2 - 1])) {
|
|
2071
2182
|
break;
|
|
2072
2183
|
}
|
|
2073
2184
|
last2--;
|
|
2074
2185
|
}
|
|
2075
|
-
if (last2 ===
|
|
2186
|
+
if (last2 === words2.length) {
|
|
2076
2187
|
return string;
|
|
2077
2188
|
}
|
|
2078
|
-
return
|
|
2189
|
+
return words2.slice(0, last2).join(" ") + words2.slice(last2).join("");
|
|
2079
2190
|
};
|
|
2080
2191
|
var exec = (string, columns, options = {}) => {
|
|
2081
2192
|
if (options.trim !== false && string.trim() === "") {
|
|
@@ -2084,11 +2195,11 @@ var exec = (string, columns, options = {}) => {
|
|
|
2084
2195
|
let returnValue = "";
|
|
2085
2196
|
let escapeCode;
|
|
2086
2197
|
let escapeUrl;
|
|
2087
|
-
const
|
|
2198
|
+
const words2 = string.split(" ");
|
|
2088
2199
|
let rows = [""];
|
|
2089
2200
|
let rowLength = 0;
|
|
2090
|
-
for (let index = 0; index <
|
|
2091
|
-
const word =
|
|
2201
|
+
for (let index = 0; index < words2.length; index++) {
|
|
2202
|
+
const word = words2[index];
|
|
2092
2203
|
if (options.trim !== false) {
|
|
2093
2204
|
const row = rows.at(-1) ?? "";
|
|
2094
2205
|
const trimmed = row.trimStart();
|
|
@@ -4686,6 +4797,10 @@ function copilotDirOf(env, home) {
|
|
|
4686
4797
|
const dir = env[COPILOT_HOME_ENV];
|
|
4687
4798
|
return dir !== void 0 && dir !== "" ? dir : join2(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
4688
4799
|
}
|
|
4800
|
+
function geminiDirOf(env, home) {
|
|
4801
|
+
const dir = env[GEMINI_CLI_HOME_ENV];
|
|
4802
|
+
return join2(dir !== void 0 && dir !== "" ? dir : home, ...AGENT_HOME_DIR.gemini);
|
|
4803
|
+
}
|
|
4689
4804
|
function kiroDirOf(env, home, platform = process.platform) {
|
|
4690
4805
|
const p3 = platform === "win32" ? win32 : posix;
|
|
4691
4806
|
const fallback = p3.join(home, ...AGENT_HOME_DIR.kiro);
|
|
@@ -4739,14 +4854,24 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4739
4854
|
if (agent === "kiro") return join2(kiroDirOf(env, home), ...file.slice(1));
|
|
4740
4855
|
return agent === "vscode" ? join2(vscodeUserDirOf(env, home), ...file) : join2(home, ...file);
|
|
4741
4856
|
}
|
|
4857
|
+
function dataRootOf(env, home) {
|
|
4858
|
+
const dir = env[DATA_DIR_ENV];
|
|
4859
|
+
return dir !== void 0 && dir !== "" ? resolve(dir) : join2(home, DATA_ROOT.slice(1));
|
|
4860
|
+
}
|
|
4742
4861
|
|
|
4743
4862
|
// src/core/ops/doctor-issue.ts
|
|
4744
4863
|
import { spawnSync } from "node:child_process";
|
|
4745
|
-
import { closeSync, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync5, readSync, realpathSync as
|
|
4746
|
-
import { delimiter, join as
|
|
4864
|
+
import { closeSync as closeSync2, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync5, readSync as readSync2, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4865
|
+
import { delimiter, join as join10 } from "node:path";
|
|
4747
4866
|
|
|
4748
4867
|
// src/core/hooks/fallback.ts
|
|
4749
4868
|
import { join as join3, resolve as resolve2 } from "node:path";
|
|
4869
|
+
|
|
4870
|
+
// src/core/policy/read-media.ts
|
|
4871
|
+
import { extname } from "node:path";
|
|
4872
|
+
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
4873
|
+
|
|
4874
|
+
// src/core/hooks/fallback.ts
|
|
4750
4875
|
var fs = process.getBuiltinModule("node:fs");
|
|
4751
4876
|
|
|
4752
4877
|
// src/core/store/schema.ts
|
|
@@ -4840,12 +4965,12 @@ var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = proce
|
|
|
4840
4965
|
|
|
4841
4966
|
// src/core/ops/doctor-config.ts
|
|
4842
4967
|
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
|
|
4843
|
-
import { join as
|
|
4968
|
+
import { join as join9 } from "node:path";
|
|
4844
4969
|
|
|
4845
4970
|
// src/core/ops/detect-v1.ts
|
|
4846
4971
|
import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
4847
4972
|
import { tmpdir } from "node:os";
|
|
4848
|
-
import { join as
|
|
4973
|
+
import { join as join7 } from "node:path";
|
|
4849
4974
|
|
|
4850
4975
|
// src/core/ops/host-config.ts
|
|
4851
4976
|
import { existsSync as existsSync4, readFileSync } from "node:fs";
|
|
@@ -7291,8 +7416,8 @@ function replaceToml(text2, doc, path15, value) {
|
|
|
7291
7416
|
let out2 = text2;
|
|
7292
7417
|
for (const [s, e, put] of cuts) out2 = out2.slice(0, s) + put + out2.slice(e);
|
|
7293
7418
|
if (owned.length > 0 || block2 === "") return out2;
|
|
7294
|
-
const
|
|
7295
|
-
return out2 +
|
|
7419
|
+
const sep3 = out2 === "" ? "" : out2.endsWith("\n\n") ? "" : out2.endsWith("\n") ? "\n" : "\n\n";
|
|
7420
|
+
return out2 + sep3 + block2;
|
|
7296
7421
|
}
|
|
7297
7422
|
var tableLike = (v) => v === void 0 || isPlainObject(v);
|
|
7298
7423
|
function setTomlText(text2, path15, value) {
|
|
@@ -7330,15 +7455,14 @@ function setText(agent, path15, text2, format, key, value) {
|
|
|
7330
7455
|
function isNodeCommand(command) {
|
|
7331
7456
|
if (typeof command !== "string") return false;
|
|
7332
7457
|
let at = -1;
|
|
7333
|
-
for (const
|
|
7458
|
+
for (const sep3 of V1_PATH_SEPS) at = Math.max(at, command.lastIndexOf(sep3));
|
|
7334
7459
|
const exe = command.slice(at + 1).toLowerCase();
|
|
7335
7460
|
return exe === HOST_NODE_COMMAND || exe === HOST_NODE_COMMAND + EXE_SUFFIX;
|
|
7336
7461
|
}
|
|
7337
7462
|
function ownMcpValue(agent, node, server) {
|
|
7338
7463
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
7339
7464
|
if (mcp === void 0) return void 0;
|
|
7340
|
-
|
|
7341
|
-
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
|
|
7465
|
+
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent] };
|
|
7342
7466
|
}
|
|
7343
7467
|
function applyEdits(agent, path15, text2, format, wanted) {
|
|
7344
7468
|
const parsed = parseHostConfig(agent, path15, text2, format);
|
|
@@ -7356,6 +7480,28 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
|
|
|
7356
7480
|
return applyEdits(agent, path15, text2, format, wanted);
|
|
7357
7481
|
}
|
|
7358
7482
|
|
|
7483
|
+
// src/core/project/contain.ts
|
|
7484
|
+
import { dirname as dirname5, join as join6, relative, sep } from "node:path";
|
|
7485
|
+
var { lstatSync: lstatSync2, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
7486
|
+
function components(p3) {
|
|
7487
|
+
return p3.split(sep).filter((c3) => c3 !== "");
|
|
7488
|
+
}
|
|
7489
|
+
function reachedThroughLink(root, p3) {
|
|
7490
|
+
const rel = relative(root, p3);
|
|
7491
|
+
const steps = components(rel);
|
|
7492
|
+
if (rel === "" || steps[0] === ".." || rel === p3) return false;
|
|
7493
|
+
let at = root;
|
|
7494
|
+
for (const step of steps) {
|
|
7495
|
+
at = join6(at, step);
|
|
7496
|
+
try {
|
|
7497
|
+
if (lstatSync2(at).isSymbolicLink()) return true;
|
|
7498
|
+
} catch {
|
|
7499
|
+
return false;
|
|
7500
|
+
}
|
|
7501
|
+
}
|
|
7502
|
+
return false;
|
|
7503
|
+
}
|
|
7504
|
+
|
|
7359
7505
|
// src/core/ops/detect-v1.ts
|
|
7360
7506
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7361
7507
|
var keyPath = (...parts) => parts.join(".");
|
|
@@ -7430,7 +7576,7 @@ function isV2McpTable(v) {
|
|
|
7430
7576
|
const first = Array.isArray(v[MCP_ARGS_FIELD]) ? v[MCP_ARGS_FIELD][0] : void 0;
|
|
7431
7577
|
if (typeof first !== "string") return false;
|
|
7432
7578
|
let at = -1;
|
|
7433
|
-
for (const
|
|
7579
|
+
for (const sep3 of V1_PATH_SEPS) at = Math.max(at, first.lastIndexOf(sep3));
|
|
7434
7580
|
return first.slice(at + 1) === SERVER_ENTRY_FILE;
|
|
7435
7581
|
}
|
|
7436
7582
|
var listOf = (v) => Array.isArray(v) ? v : [];
|
|
@@ -7461,7 +7607,7 @@ function flatCommands(events2, prefix) {
|
|
|
7461
7607
|
return out2;
|
|
7462
7608
|
}
|
|
7463
7609
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7464
|
-
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((
|
|
7610
|
+
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
|
|
7465
7611
|
function dataDir(dir, reason, out2) {
|
|
7466
7612
|
if (existsSync5(dir)) out2.push(finding(dir, "", reason));
|
|
7467
7613
|
}
|
|
@@ -7471,7 +7617,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7471
7617
|
}
|
|
7472
7618
|
}
|
|
7473
7619
|
function claudeShapeSettings(agentHome, out2) {
|
|
7474
|
-
const file =
|
|
7620
|
+
const file = join7(agentHome, SETTINGS_FILE);
|
|
7475
7621
|
const doc = readJson(file);
|
|
7476
7622
|
for (const c3 of nestedCommands(doc)) {
|
|
7477
7623
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7491,49 +7637,50 @@ function v1HookFile(file, out2) {
|
|
|
7491
7637
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7492
7638
|
claudeShapeSettings(agentHome, out2);
|
|
7493
7639
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7494
|
-
const file =
|
|
7640
|
+
const file = join7(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
7495
7641
|
if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
|
|
7496
7642
|
}
|
|
7497
|
-
const userFile =
|
|
7643
|
+
const userFile = join7(home, CLAUDE_USER_CONFIG_FILE);
|
|
7498
7644
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7499
|
-
dataDir(
|
|
7645
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7500
7646
|
}
|
|
7501
7647
|
function scanCodex(agentHome, out2) {
|
|
7502
|
-
const hooksFile =
|
|
7648
|
+
const hooksFile = join7(agentHome, HOOKS_JSON_FILE);
|
|
7503
7649
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7504
7650
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7505
7651
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7506
7652
|
}
|
|
7507
7653
|
}
|
|
7508
|
-
const tomlFile =
|
|
7654
|
+
const tomlFile = join7(agentHome, CONFIG_TOML_FILE);
|
|
7509
7655
|
const config = readTomlValue(tomlFile);
|
|
7510
7656
|
for (const span of readTomlTables(tomlFile)) {
|
|
7511
7657
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7512
7658
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7513
7659
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7514
7660
|
}
|
|
7515
|
-
dataDir(
|
|
7661
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7516
7662
|
}
|
|
7517
7663
|
function scanGemini(agentHome, out2) {
|
|
7518
|
-
const file =
|
|
7664
|
+
const file = join7(agentHome, SETTINGS_FILE);
|
|
7519
7665
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7520
7666
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7521
7667
|
}
|
|
7522
|
-
dataDir(
|
|
7668
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7523
7669
|
}
|
|
7524
7670
|
function scanVscode(agentHome, project, out2) {
|
|
7525
7671
|
if (project !== void 0) {
|
|
7526
|
-
v1HookFile(
|
|
7527
|
-
const mcpFile =
|
|
7672
|
+
v1HookFile(join7(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7673
|
+
const mcpFile = join7(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
7528
7674
|
const doc = readJson(mcpFile);
|
|
7529
7675
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7530
7676
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7531
7677
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7532
7678
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7533
7679
|
}
|
|
7534
|
-
|
|
7680
|
+
const sessions = join7(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
7681
|
+
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out2);
|
|
7535
7682
|
}
|
|
7536
|
-
dataDir(
|
|
7683
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7537
7684
|
}
|
|
7538
7685
|
function jsonFiles(dir) {
|
|
7539
7686
|
try {
|
|
@@ -7543,10 +7690,10 @@ function jsonFiles(dir) {
|
|
|
7543
7690
|
}
|
|
7544
7691
|
}
|
|
7545
7692
|
function scanKiro(agentHome, project, out2) {
|
|
7546
|
-
const agentsDir =
|
|
7547
|
-
const defaultFile =
|
|
7693
|
+
const agentsDir = join7(agentHome, KIRO_AGENTS_DIR);
|
|
7694
|
+
const defaultFile = join7(agentHome, ...KIRO_AGENT_FILE);
|
|
7548
7695
|
for (const name of jsonFiles(agentsDir)) {
|
|
7549
|
-
const file =
|
|
7696
|
+
const file = join7(agentsDir, name);
|
|
7550
7697
|
const doc = readJson(file);
|
|
7551
7698
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7552
7699
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7557,46 +7704,48 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7557
7704
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7558
7705
|
}
|
|
7559
7706
|
}
|
|
7560
|
-
const steeringDocs = [
|
|
7561
|
-
if (project !== void 0) steeringDocs.push(
|
|
7707
|
+
const steeringDocs = [join7(agentHome, ...KIRO_STEERING_FILE)];
|
|
7708
|
+
if (project !== void 0) steeringDocs.push(join7(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7562
7709
|
for (const file of steeringDocs) {
|
|
7563
7710
|
if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7564
7711
|
}
|
|
7565
|
-
dataDir(
|
|
7712
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7566
7713
|
}
|
|
7567
7714
|
function piNpmIsCurrent(piAgentDir) {
|
|
7568
|
-
const doc = readJson(
|
|
7715
|
+
const doc = readJson(join7(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
7569
7716
|
const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
7570
7717
|
return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
|
|
7571
7718
|
}
|
|
7572
7719
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7573
|
-
const file =
|
|
7720
|
+
const file = join7(piAgentDir, SETTINGS_FILE);
|
|
7574
7721
|
const doc = readJson(file);
|
|
7575
7722
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7576
7723
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7577
7724
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7725
|
+
if (spec === PI_GIT_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piGit));
|
|
7578
7726
|
});
|
|
7579
|
-
dataDir(
|
|
7727
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7580
7728
|
}
|
|
7581
7729
|
function scanOpencode(agentHome, out2) {
|
|
7582
7730
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7583
|
-
const file =
|
|
7731
|
+
const file = join7(agentHome, name);
|
|
7584
7732
|
const doc = readJson(file);
|
|
7585
7733
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7586
7734
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
7587
7735
|
if (spec === V1_OPENCODE_PLUGIN_SPEC) out2.push(finding(file, keyPath(OPENCODE_PLUGIN_KEY, i2), V1_REASON.opencodePlugin));
|
|
7736
|
+
if (spec === OPENCODE_GIT_SPEC) out2.push(finding(file, keyPath(OPENCODE_PLUGIN_KEY, i2), V1_REASON.opencodeGit));
|
|
7588
7737
|
});
|
|
7589
7738
|
return;
|
|
7590
7739
|
}
|
|
7591
7740
|
}
|
|
7592
7741
|
function scanZcode(agentHome, out2) {
|
|
7593
|
-
const configFile =
|
|
7742
|
+
const configFile = join7(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7594
7743
|
const config = readJson(configFile);
|
|
7595
7744
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7596
7745
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7597
7746
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7598
7747
|
}
|
|
7599
|
-
const hooksFile =
|
|
7748
|
+
const hooksFile = join7(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7600
7749
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7601
7750
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7602
7751
|
}
|
|
@@ -7620,14 +7769,14 @@ function firstTmpMatch(dir) {
|
|
|
7620
7769
|
}
|
|
7621
7770
|
}
|
|
7622
7771
|
function scanAll(home, tmp, out2) {
|
|
7623
|
-
const root =
|
|
7624
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
7772
|
+
const root = join7(home, DATA_ROOT.slice(1));
|
|
7773
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join7(root, name), V1_REASON.dataRoot, out2);
|
|
7625
7774
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7626
7775
|
}
|
|
7627
7776
|
function detectV1(agent, home, scope = {}) {
|
|
7628
7777
|
const out2 = [];
|
|
7629
7778
|
const project = scope.project;
|
|
7630
|
-
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 :
|
|
7779
|
+
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]);
|
|
7631
7780
|
switch (agent) {
|
|
7632
7781
|
case "claude-code":
|
|
7633
7782
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7640,11 +7789,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7640
7789
|
break;
|
|
7641
7790
|
case "qwen":
|
|
7642
7791
|
claudeShapeSettings(agentHome, out2);
|
|
7643
|
-
dataDir(
|
|
7792
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7644
7793
|
break;
|
|
7645
7794
|
case "copilot-cli":
|
|
7646
|
-
v1HookFile(
|
|
7647
|
-
dataDir(
|
|
7795
|
+
v1HookFile(join7(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7796
|
+
dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7648
7797
|
break;
|
|
7649
7798
|
case "vscode":
|
|
7650
7799
|
scanVscode(agentHome, project, out2);
|
|
@@ -7653,7 +7802,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7653
7802
|
scanKiro(agentHome, project, out2);
|
|
7654
7803
|
break;
|
|
7655
7804
|
case "pi":
|
|
7656
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7805
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join7(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7657
7806
|
break;
|
|
7658
7807
|
// D-WIN-PIDIR-1: empty is unset
|
|
7659
7808
|
case "opencode":
|
|
@@ -7668,12 +7817,12 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7668
7817
|
}
|
|
7669
7818
|
|
|
7670
7819
|
// src/core/ops/plugin-root.ts
|
|
7671
|
-
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as
|
|
7672
|
-
import { dirname as
|
|
7820
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync3 } from "node:fs";
|
|
7821
|
+
import { dirname as dirname6, isAbsolute, join as join8, sep as sep2 } from "node:path";
|
|
7673
7822
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7674
7823
|
|
|
7675
7824
|
// src/setup/pi-gate.ts
|
|
7676
|
-
import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as
|
|
7825
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
|
|
7677
7826
|
import path3 from "node:path";
|
|
7678
7827
|
var OWN_FILE = "pi/index.js";
|
|
7679
7828
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -7691,7 +7840,7 @@ function load(file) {
|
|
|
7691
7840
|
}
|
|
7692
7841
|
var real = (p3) => {
|
|
7693
7842
|
try {
|
|
7694
|
-
return
|
|
7843
|
+
return realpathSync4(p3);
|
|
7695
7844
|
} catch {
|
|
7696
7845
|
return path3.resolve(p3);
|
|
7697
7846
|
}
|
|
@@ -7792,6 +7941,7 @@ function formUrl(title, summary) {
|
|
|
7792
7941
|
}
|
|
7793
7942
|
|
|
7794
7943
|
// src/setup/registry.ts
|
|
7944
|
+
import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
7795
7945
|
import path4 from "node:path";
|
|
7796
7946
|
|
|
7797
7947
|
// src/setup/hook-shapes.ts
|
|
@@ -7850,7 +8000,6 @@ var HOOK_SHAPES = {
|
|
|
7850
8000
|
var SERVER_BUNDLE = "server.mjs";
|
|
7851
8001
|
var HOOK_BUNDLE = "hook.mjs";
|
|
7852
8002
|
var AGENT_FLAG = "--agent";
|
|
7853
|
-
var STATE_DIR = ".context-mode";
|
|
7854
8003
|
var LOCK_FILE = "setup.lock";
|
|
7855
8004
|
var BACKUP_DIR = "backups";
|
|
7856
8005
|
var PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
@@ -7912,12 +8061,41 @@ function extensionPlugin(bin, id) {
|
|
|
7912
8061
|
};
|
|
7913
8062
|
}
|
|
7914
8063
|
var NATIVE_PLUGIN = {
|
|
7915
|
-
codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "
|
|
8064
|
+
codex: { bin: "codex", args: ["plugin", "list", "--json"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "codex-json", hookTrust: true },
|
|
7916
8065
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
7917
|
-
gemini: extensionPlugin("gemini", "gemini")
|
|
8066
|
+
gemini: extensionPlugin("gemini", "gemini"),
|
|
8067
|
+
// D-R44-ZCODE-NATIVE-1 (host audit zcode-1/2): `zcode plugins install context-mode@context-mode` lists as JSON; ZCode loads
|
|
8068
|
+
// <plugin>/.zcode-plugin/plugin.json (MCP server, hooks run with --agent zcode) and the package skills/.
|
|
8069
|
+
zcode: {
|
|
8070
|
+
bin: "zcode",
|
|
8071
|
+
args: ["plugins", "list", "--json"],
|
|
8072
|
+
plugin: PLUGIN_ID,
|
|
8073
|
+
hooksVia: ".zcode-plugin",
|
|
8074
|
+
skillsVia: SKILLS_DIR_NAME,
|
|
8075
|
+
format: "json",
|
|
8076
|
+
enable: ["plugins", "enable", PLUGIN_ID]
|
|
8077
|
+
}
|
|
7918
8078
|
};
|
|
8079
|
+
var CELLAR_SEGMENT = "/Cellar/";
|
|
8080
|
+
var NODE_BIN = ["bin", "node"];
|
|
8081
|
+
var REAL_FS = { exists: existsSync10, real: (p3) => realpathSync6.native(p3) };
|
|
8082
|
+
function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
8083
|
+
const at = execPath.indexOf(CELLAR_SEGMENT);
|
|
8084
|
+
if (at < 0) return execPath;
|
|
8085
|
+
const prefix = execPath.slice(0, at);
|
|
8086
|
+
const formula = execPath.slice(at + CELLAR_SEGMENT.length).split("/")[0] ?? "";
|
|
8087
|
+
const target = fs2.real(execPath);
|
|
8088
|
+
for (const link of [[prefix, "opt", formula, ...NODE_BIN].join("/"), [prefix, ...NODE_BIN].join("/")]) {
|
|
8089
|
+
try {
|
|
8090
|
+
if (fs2.exists(link) && fs2.real(link) === target) return link;
|
|
8091
|
+
} catch {
|
|
8092
|
+
}
|
|
8093
|
+
}
|
|
8094
|
+
return execPath;
|
|
8095
|
+
}
|
|
8096
|
+
var SETUP_NODE = stableNodePath(process.execPath);
|
|
7919
8097
|
function serverCmd(ctx, id) {
|
|
7920
|
-
return [
|
|
8098
|
+
return [SETUP_NODE, path4.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
7921
8099
|
}
|
|
7922
8100
|
function hookCommandString(row) {
|
|
7923
8101
|
const [node, file, flag, id] = row.hookCommand ?? [];
|
|
@@ -7996,7 +8174,8 @@ function hookFilesFor(ctx, id) {
|
|
|
7996
8174
|
case "claude-code":
|
|
7997
8175
|
return [{ file: path4.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
7998
8176
|
case "gemini":
|
|
7999
|
-
return [{ file: path4.join(
|
|
8177
|
+
return [{ file: path4.join(geminiDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
8178
|
+
// D-R38-GEMINI-HOME-1
|
|
8000
8179
|
case "qwen":
|
|
8001
8180
|
return [{ file: path4.join(home, ".qwen", "settings.json"), mode: "drop" }];
|
|
8002
8181
|
default:
|
|
@@ -8043,8 +8222,8 @@ function buildRegistry(ctx) {
|
|
|
8043
8222
|
const id = row.id;
|
|
8044
8223
|
const config = configFor(ctx, id);
|
|
8045
8224
|
const hookFiles = hookFilesFor(ctx, id);
|
|
8046
|
-
const runCommand2 = [
|
|
8047
|
-
const bareNode = id === "codex" && (ctx.platform ?? process.platform) === "win32";
|
|
8225
|
+
const runCommand2 = [SETUP_NODE, path4.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
8226
|
+
const bareNode = (id === "codex" || id === "qwen") && (ctx.platform ?? process.platform) === "win32";
|
|
8048
8227
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
8049
8228
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
8050
8229
|
const hookInstall = hookInstallFor(ctx, getAdapter(id), command);
|
|
@@ -8089,11 +8268,13 @@ function assertWritable(row, file) {
|
|
|
8089
8268
|
}
|
|
8090
8269
|
|
|
8091
8270
|
// src/setup/gemini-gate.ts
|
|
8092
|
-
import { existsSync as
|
|
8271
|
+
import { existsSync as existsSync11, readFileSync as readFileSync6 } from "node:fs";
|
|
8093
8272
|
import path5 from "node:path";
|
|
8094
8273
|
var GEMINI_DIR = ".gemini";
|
|
8095
8274
|
var SETTINGS_FILE2 = "settings.json";
|
|
8096
8275
|
var SYSTEM_PATH_ENV = "GEMINI_CLI_SYSTEM_SETTINGS_PATH";
|
|
8276
|
+
var SYSTEM_DEFAULTS_ENV = "GEMINI_CLI_SYSTEM_DEFAULTS_PATH";
|
|
8277
|
+
var SYSTEM_DEFAULTS_FILE = "system-defaults.json";
|
|
8097
8278
|
var OWN_AGENT = "gemini";
|
|
8098
8279
|
function systemSettingsPath(env) {
|
|
8099
8280
|
const set2 = env[SYSTEM_PATH_ENV];
|
|
@@ -8102,8 +8283,12 @@ function systemSettingsPath(env) {
|
|
|
8102
8283
|
if (process.platform === "win32") return "C:\\ProgramData\\gemini-cli\\settings.json";
|
|
8103
8284
|
return "/etc/gemini-cli/settings.json";
|
|
8104
8285
|
}
|
|
8286
|
+
function systemDefaultsPath(env) {
|
|
8287
|
+
const set2 = env[SYSTEM_DEFAULTS_ENV];
|
|
8288
|
+
return set2 ? set2 : path5.join(path5.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8289
|
+
}
|
|
8105
8290
|
function load2(file) {
|
|
8106
|
-
if (!
|
|
8291
|
+
if (!existsSync11(file)) return void 0;
|
|
8107
8292
|
try {
|
|
8108
8293
|
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync6(file, "utf8")), "jsonc") };
|
|
8109
8294
|
} catch {
|
|
@@ -8111,7 +8296,7 @@ function load2(file) {
|
|
|
8111
8296
|
}
|
|
8112
8297
|
}
|
|
8113
8298
|
function sources(env, home, cwd) {
|
|
8114
|
-
return [path5.join(
|
|
8299
|
+
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);
|
|
8115
8300
|
}
|
|
8116
8301
|
function ownHookEntry(entry2) {
|
|
8117
8302
|
return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
|
|
@@ -8137,7 +8322,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8137
8322
|
}
|
|
8138
8323
|
|
|
8139
8324
|
// src/setup/zcode-gate.ts
|
|
8140
|
-
import { existsSync as
|
|
8325
|
+
import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
|
|
8141
8326
|
import path6 from "node:path";
|
|
8142
8327
|
var OWN_AGENT2 = "zcode";
|
|
8143
8328
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8229,7 +8414,7 @@ function zcodeSchemaBad(doc) {
|
|
|
8229
8414
|
}
|
|
8230
8415
|
function zcodeConfigGate(home) {
|
|
8231
8416
|
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8232
|
-
if (!
|
|
8417
|
+
if (!existsSync12(file)) return void 0;
|
|
8233
8418
|
let doc;
|
|
8234
8419
|
try {
|
|
8235
8420
|
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync7(file, "utf8")), "json");
|
|
@@ -8242,7 +8427,7 @@ function zcodeConfigGate(home) {
|
|
|
8242
8427
|
}
|
|
8243
8428
|
|
|
8244
8429
|
// src/setup/vscode-gate.ts
|
|
8245
|
-
import { existsSync as
|
|
8430
|
+
import { existsSync as existsSync13, readFileSync as readFileSync8 } from "node:fs";
|
|
8246
8431
|
import path7 from "node:path";
|
|
8247
8432
|
var SETTINGS_FILE3 = "settings.json";
|
|
8248
8433
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8251,7 +8436,7 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8251
8436
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8252
8437
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8253
8438
|
function load3(file) {
|
|
8254
|
-
if (!
|
|
8439
|
+
if (!existsSync13(file)) return void 0;
|
|
8255
8440
|
try {
|
|
8256
8441
|
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
|
|
8257
8442
|
} catch {
|
|
@@ -8293,7 +8478,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8293
8478
|
}
|
|
8294
8479
|
|
|
8295
8480
|
// src/setup/qwen-gate.ts
|
|
8296
|
-
import { existsSync as
|
|
8481
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
8297
8482
|
import path8 from "node:path";
|
|
8298
8483
|
var KEY = "disableAllHooks";
|
|
8299
8484
|
var SETTINGS = "settings.json";
|
|
@@ -8309,7 +8494,7 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8309
8494
|
}
|
|
8310
8495
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8311
8496
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8312
|
-
if (!
|
|
8497
|
+
if (!existsSync14(file)) continue;
|
|
8313
8498
|
let value;
|
|
8314
8499
|
try {
|
|
8315
8500
|
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
|
|
@@ -8323,7 +8508,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8323
8508
|
|
|
8324
8509
|
// src/setup/codex-trust.ts
|
|
8325
8510
|
import { createHash } from "node:crypto";
|
|
8326
|
-
import { existsSync as
|
|
8511
|
+
import { existsSync as existsSync15, realpathSync as realpathSync7 } from "node:fs";
|
|
8327
8512
|
import path10 from "node:path";
|
|
8328
8513
|
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8329
8514
|
|
|
@@ -8432,11 +8617,11 @@ function snake(name) {
|
|
|
8432
8617
|
function realFile(file) {
|
|
8433
8618
|
let dir = path10.resolve(file);
|
|
8434
8619
|
const rest = [];
|
|
8435
|
-
while (!
|
|
8620
|
+
while (!existsSync15(dir) && path10.dirname(dir) !== dir) {
|
|
8436
8621
|
rest.unshift(path10.basename(dir));
|
|
8437
8622
|
dir = path10.dirname(dir);
|
|
8438
8623
|
}
|
|
8439
|
-
return path10.join(
|
|
8624
|
+
return path10.join(realpathSync7(dir), ...rest);
|
|
8440
8625
|
}
|
|
8441
8626
|
var ASK_TIMEOUT_MS = 1e4;
|
|
8442
8627
|
var ASK_TRIES = 3;
|
|
@@ -8630,14 +8815,14 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
8630
8815
|
if (!bad.length) return void 0;
|
|
8631
8816
|
const counts = /* @__PURE__ */ new Map();
|
|
8632
8817
|
for (const h2 of bad) counts.set(h2.status, (counts.get(h2.status) ?? 0) + 1);
|
|
8633
|
-
const
|
|
8634
|
-
const state =
|
|
8818
|
+
const words2 = [...counts].sort((a2, b3) => b3[1] - a2[1] || (a2[0] < b3[0] ? -1 : 1));
|
|
8819
|
+
const state = words2.length === 1 ? words2[0][0] : `${words2.map(([w]) => w).join(" or ")} (${words2.map(([w, n3]) => `${n3} ${w}`).join(", ")})`;
|
|
8635
8820
|
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
8636
8821
|
}
|
|
8637
8822
|
|
|
8638
8823
|
// src/setup/copilot-hooks.ts
|
|
8639
8824
|
import { spawn as spawn2 } from "node:child_process";
|
|
8640
|
-
import { realpathSync as
|
|
8825
|
+
import { realpathSync as realpathSync8 } from "node:fs";
|
|
8641
8826
|
import path11 from "node:path";
|
|
8642
8827
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
8643
8828
|
var ASK_TIMEOUT_MS2 = 15e3;
|
|
@@ -8647,7 +8832,7 @@ var USER_ORIGIN = "user";
|
|
|
8647
8832
|
function canon(p3) {
|
|
8648
8833
|
let r2 = path11.resolve(p3);
|
|
8649
8834
|
try {
|
|
8650
|
-
r2 =
|
|
8835
|
+
r2 = realpathSync8(r2);
|
|
8651
8836
|
} catch {
|
|
8652
8837
|
}
|
|
8653
8838
|
return process.platform === "win32" ? r2.toLowerCase() : r2;
|
|
@@ -8732,7 +8917,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8732
8917
|
|
|
8733
8918
|
// src/setup/engine.ts
|
|
8734
8919
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8735
|
-
import { closeSync as
|
|
8920
|
+
import { closeSync as closeSync3, existsSync as existsSync16, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync10, readSync as readSync3, readdirSync as readdirSync5, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8736
8921
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8737
8922
|
import path12 from "node:path";
|
|
8738
8923
|
|
|
@@ -8818,11 +9003,11 @@ var REAL_HOST = Object.freeze({
|
|
|
8818
9003
|
var BINARY_MAGICS = Object.freeze(["cffaedfe", "cefaedfe", "7f454c46", "4d5a"]);
|
|
8819
9004
|
function isNativeBinary(file) {
|
|
8820
9005
|
const head = Buffer.alloc(4);
|
|
8821
|
-
const fd =
|
|
9006
|
+
const fd = openSync3(file, "r");
|
|
8822
9007
|
try {
|
|
8823
|
-
|
|
9008
|
+
readSync3(fd, head, 0, 4, 0);
|
|
8824
9009
|
} finally {
|
|
8825
|
-
|
|
9010
|
+
closeSync3(fd);
|
|
8826
9011
|
}
|
|
8827
9012
|
const hex = head.toString("hex");
|
|
8828
9013
|
return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
|
|
@@ -8830,7 +9015,7 @@ function isNativeBinary(file) {
|
|
|
8830
9015
|
function owningPackage(dir) {
|
|
8831
9016
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
8832
9017
|
const f2 = path12.join(d, "package.json");
|
|
8833
|
-
if (
|
|
9018
|
+
if (existsSync16(f2)) {
|
|
8834
9019
|
try {
|
|
8835
9020
|
return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
|
|
8836
9021
|
} catch {
|
|
@@ -8848,8 +9033,8 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
8848
9033
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8849
9034
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
8850
9035
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
8851
|
-
if (!f2 || !
|
|
8852
|
-
const file =
|
|
9036
|
+
if (!f2 || !existsSync16(f2) || !statSync2(f2).isFile()) continue;
|
|
9037
|
+
const file = realpathSync9(f2);
|
|
8853
9038
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
8854
9039
|
shims.push(f2);
|
|
8855
9040
|
}
|
|
@@ -8862,13 +9047,13 @@ function installExitOk(status, listed, platform = process.platform) {
|
|
|
8862
9047
|
return platform === "win32" && status === WIN_EXIT_CRASH && listed;
|
|
8863
9048
|
}
|
|
8864
9049
|
function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
8865
|
-
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
|
|
9050
|
+
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout, maxBuffer: Infinity });
|
|
8866
9051
|
}
|
|
8867
9052
|
function readOr(file) {
|
|
8868
|
-
return
|
|
9053
|
+
return existsSync16(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
|
|
8869
9054
|
}
|
|
8870
9055
|
function readRaw(file) {
|
|
8871
|
-
return
|
|
9056
|
+
return existsSync16(file) ? readFileSync10(file, "utf8") : void 0;
|
|
8872
9057
|
}
|
|
8873
9058
|
var atomicWrite = atomicWriteFile;
|
|
8874
9059
|
function pidAlive(pid) {
|
|
@@ -9013,7 +9198,7 @@ function isNativeSpec(e) {
|
|
|
9013
9198
|
function isStaleOwnPlugin(e, entry2) {
|
|
9014
9199
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
9015
9200
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
9016
|
-
if (
|
|
9201
|
+
if (existsSync16(e)) return false;
|
|
9017
9202
|
const seg = e.split("\\").join("/").split("/");
|
|
9018
9203
|
const n3 = seg.length;
|
|
9019
9204
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -9077,7 +9262,7 @@ function planSkills(row, edits) {
|
|
|
9077
9262
|
const s = row.skillInstall;
|
|
9078
9263
|
if (s.kind !== "dir") return;
|
|
9079
9264
|
for (const f2 of s.files) {
|
|
9080
|
-
if (!
|
|
9265
|
+
if (!existsSync16(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
9081
9266
|
const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
|
|
9082
9267
|
const before = readRaw(f2.file);
|
|
9083
9268
|
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" }] });
|
|
@@ -9315,8 +9500,8 @@ function hookRound(row, env) {
|
|
|
9315
9500
|
const bareP95Ms = Math.round(p95(bare));
|
|
9316
9501
|
const overheadP95Ms = Math.max(0, wallP95Ms - bareP95Ms);
|
|
9317
9502
|
const budget = overheadBudgetMs(env);
|
|
9318
|
-
const
|
|
9319
|
-
return { name: "hook", ok, overheadP95Ms, wallP95Ms, bareP95Ms, detail:
|
|
9503
|
+
const over = overheadP95Ms > budget;
|
|
9504
|
+
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 };
|
|
9320
9505
|
}
|
|
9321
9506
|
function hookCheck(row, env) {
|
|
9322
9507
|
let best;
|
|
@@ -9324,7 +9509,7 @@ function hookCheck(row, env) {
|
|
|
9324
9509
|
const c3 = hookRound(row, env);
|
|
9325
9510
|
if (c3.overheadP95Ms === void 0) return c3;
|
|
9326
9511
|
if (!best || c3.overheadP95Ms < best.overheadP95Ms) best = c3;
|
|
9327
|
-
if (c3.
|
|
9512
|
+
if (!c3.warn) break;
|
|
9328
9513
|
}
|
|
9329
9514
|
return best;
|
|
9330
9515
|
}
|
|
@@ -9381,9 +9566,9 @@ function hookRunsCheck(row, env) {
|
|
|
9381
9566
|
}
|
|
9382
9567
|
var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
9383
9568
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9384
|
-
function hookSeenCheck(row,
|
|
9385
|
-
const base = path12.join(
|
|
9386
|
-
const dirs =
|
|
9569
|
+
function hookSeenCheck(row, dataRoot) {
|
|
9570
|
+
const base = path12.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9571
|
+
const dirs = existsSync16(base) ? readdirSync5(base) : [];
|
|
9387
9572
|
let sqlite;
|
|
9388
9573
|
try {
|
|
9389
9574
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9392,7 +9577,7 @@ function hookSeenCheck(row, home) {
|
|
|
9392
9577
|
}
|
|
9393
9578
|
for (const d of dirs) {
|
|
9394
9579
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9395
|
-
if (!sqlite || !
|
|
9580
|
+
if (!sqlite || !existsSync16(file)) continue;
|
|
9396
9581
|
let db;
|
|
9397
9582
|
try {
|
|
9398
9583
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9409,7 +9594,7 @@ function skillsCheck(row, pkgDir) {
|
|
|
9409
9594
|
const s = row.skillInstall;
|
|
9410
9595
|
if (s.kind === "package") {
|
|
9411
9596
|
const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
9412
|
-
const miss = files.filter((f2) => !
|
|
9597
|
+
const miss = files.filter((f2) => !existsSync16(f2));
|
|
9413
9598
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
9414
9599
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
9415
9600
|
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
@@ -9419,24 +9604,30 @@ function skillsCheck(row, pkgDir) {
|
|
|
9419
9604
|
});
|
|
9420
9605
|
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
9421
9606
|
}
|
|
9422
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9607
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync16(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9423
9608
|
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 };
|
|
9424
9609
|
}
|
|
9425
|
-
var PLUGIN_ENABLED = "enabled";
|
|
9426
|
-
var WORD_TRIM = ",;";
|
|
9427
9610
|
var CODEX_CONFIG_FILE2 = "config.toml";
|
|
9428
9611
|
var EXT_ENABLED_USER = "Enabled (User):";
|
|
9429
9612
|
var EXT_ENABLED_WORKSPACE = "Enabled (Workspace):";
|
|
9430
9613
|
var EXT_TRUE = "true";
|
|
9431
|
-
function
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9614
|
+
function codexJsonState(n3, text2) {
|
|
9615
|
+
let doc;
|
|
9616
|
+
try {
|
|
9617
|
+
doc = JSON.parse(text2);
|
|
9618
|
+
} catch {
|
|
9619
|
+
return void 0;
|
|
9620
|
+
}
|
|
9621
|
+
const list2 = isObj5(doc) && Array.isArray(doc.installed) ? doc.installed : [];
|
|
9622
|
+
const mine = list2.find((p3) => isObj5(p3) && p3.pluginId === n3.plugin);
|
|
9623
|
+
if (!isObj5(mine)) return void 0;
|
|
9624
|
+
return mine.enabled === true ? "enabled" : "disabled";
|
|
9435
9625
|
}
|
|
9436
9626
|
function extensionState(n3, text2) {
|
|
9437
9627
|
let mine = false;
|
|
9438
9628
|
let state;
|
|
9439
9629
|
let workspaceOff = false;
|
|
9630
|
+
let workspaceOn = false;
|
|
9440
9631
|
for (const raw of text2.split("\n")) {
|
|
9441
9632
|
const line = raw.trimEnd();
|
|
9442
9633
|
if (line.length && !line.startsWith(" ")) {
|
|
@@ -9446,17 +9637,44 @@ function extensionState(n3, text2) {
|
|
|
9446
9637
|
const t2 = line.trim();
|
|
9447
9638
|
if (!mine) continue;
|
|
9448
9639
|
if (t2.startsWith(EXT_ENABLED_USER)) state = t2.slice(EXT_ENABLED_USER.length).trim() === EXT_TRUE ? "enabled" : "disabled";
|
|
9449
|
-
if (t2.startsWith(EXT_ENABLED_WORKSPACE))
|
|
9640
|
+
if (t2.startsWith(EXT_ENABLED_WORKSPACE)) {
|
|
9641
|
+
workspaceOff = t2.slice(EXT_ENABLED_WORKSPACE.length).trim() !== EXT_TRUE;
|
|
9642
|
+
workspaceOn = !workspaceOff;
|
|
9643
|
+
}
|
|
9450
9644
|
}
|
|
9645
|
+
if (state === "disabled" && workspaceOn) state = "enabled";
|
|
9451
9646
|
return { state, workspaceOff };
|
|
9452
9647
|
}
|
|
9648
|
+
function jsonState(n3, text2) {
|
|
9649
|
+
const none = { state: void 0, workspaceOff: false };
|
|
9650
|
+
let doc;
|
|
9651
|
+
try {
|
|
9652
|
+
doc = JSON.parse(text2);
|
|
9653
|
+
} catch {
|
|
9654
|
+
return none;
|
|
9655
|
+
}
|
|
9656
|
+
const mine = Array.isArray(doc) ? doc.find((p3) => isObj5(p3) && p3.id === n3.plugin) : void 0;
|
|
9657
|
+
if (!isObj5(mine)) return none;
|
|
9658
|
+
if (mine.enabled !== true) return { state: "disabled", workspaceOff: false };
|
|
9659
|
+
const hooks = Array.isArray(mine.hookDetails) ? mine.hookDetails : [];
|
|
9660
|
+
const own2 = `${AGENT_FLAG} ${n3.bin}`;
|
|
9661
|
+
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}`;
|
|
9662
|
+
return { state: "enabled", workspaceOff: false, hookGate };
|
|
9663
|
+
}
|
|
9453
9664
|
function nativeState(row, env) {
|
|
9454
9665
|
const none = { state: void 0, workspaceOff: false };
|
|
9455
9666
|
const n3 = row.nativePlugin;
|
|
9456
9667
|
if (!n3 || !hostBin(n3.bin, env).file) return none;
|
|
9457
9668
|
const r2 = runBin(n3.bin, n3.args, env);
|
|
9669
|
+
const why = r2.error?.code ?? r2.signal;
|
|
9670
|
+
if (why && `${r2.stdout}`.includes(n3.plugin)) {
|
|
9671
|
+
const cmd = [n3.bin, ...n3.args].join(" ");
|
|
9672
|
+
return { ...none, stopped: `${cmd} stopped before it finished (${why}); it names ${n3.plugin}, run ${cmd} in a terminal` };
|
|
9673
|
+
}
|
|
9458
9674
|
if (r2.status !== 0) return none;
|
|
9459
|
-
|
|
9675
|
+
if (n3.format === "json") return jsonState(n3, `${r2.stdout}`);
|
|
9676
|
+
if (n3.format === "codex-json") return { state: codexJsonState(n3, `${r2.stdout}`), workspaceOff: false };
|
|
9677
|
+
return extensionState(n3, `${r2.stdout}${r2.stderr}`);
|
|
9460
9678
|
}
|
|
9461
9679
|
function nativeRow(row, n3) {
|
|
9462
9680
|
return {
|
|
@@ -9470,18 +9688,12 @@ function nativeRow(row, n3) {
|
|
|
9470
9688
|
skillInstall: { kind: "package", via: n3.skillsVia }
|
|
9471
9689
|
};
|
|
9472
9690
|
}
|
|
9473
|
-
function trimChars(w, chars) {
|
|
9474
|
-
let a2 = 0;
|
|
9475
|
-
let b3 = w.length;
|
|
9476
|
-
while (a2 < b3 && chars.includes(w.charAt(a2))) a2++;
|
|
9477
|
-
while (b3 > a2 && chars.includes(w.charAt(b3 - 1))) b3--;
|
|
9478
|
-
return w.slice(a2, b3);
|
|
9479
|
-
}
|
|
9480
9691
|
async function nativeResult(row, ctx, apply2) {
|
|
9481
9692
|
const n3 = row.nativePlugin;
|
|
9482
|
-
const { state, workspaceOff } = nativeState(row, ctx.env);
|
|
9693
|
+
const { state, workspaceOff, hookGate, stopped } = nativeState(row, ctx.env);
|
|
9694
|
+
const bin = n3 ? hostBin(n3.bin, ctx.env).file : void 0;
|
|
9695
|
+
if (stopped) return { id: row.id, status: "FAIL", v1: [], changes: [], checks: [], bin, reason: stopped };
|
|
9483
9696
|
if (!n3 || state === void 0) return void 0;
|
|
9484
|
-
const bin = hostBin(n3.bin, ctx.env).file;
|
|
9485
9697
|
if (state === "disabled") {
|
|
9486
9698
|
if (!n3.enable) return void 0;
|
|
9487
9699
|
return {
|
|
@@ -9509,6 +9721,7 @@ async function nativeResult(row, ctx, apply2) {
|
|
|
9509
9721
|
res.checks = await verifyRow(nativeRow(row, n3), ctx);
|
|
9510
9722
|
if (n3.hookTrust) res.checks = withHookTrust(res.checks, hooks, !!apply2?.dryRun);
|
|
9511
9723
|
if (n3.format === "extension") res.checks = withHookGate(res.checks, geminiGate(n3, ctx, workspaceOff));
|
|
9724
|
+
if (n3.format === "json") res.checks = withHookGate(res.checks, hookGate);
|
|
9512
9725
|
const bad = res.checks.filter((c3) => !c3.ok);
|
|
9513
9726
|
if (bad.length) {
|
|
9514
9727
|
res.status = "FAIL";
|
|
@@ -9628,7 +9841,7 @@ async function verifyRow(row, ctx) {
|
|
|
9628
9841
|
const en = hookEnabledCheck(row, ls.status);
|
|
9629
9842
|
if (en) checks.push(en);
|
|
9630
9843
|
if (row.copilotSettings) checks.push(await copilotEnabledCheck(row, ctx));
|
|
9631
|
-
checks.push(hookRunsCheck(row, env), hookSeenCheck(row, ctx.home), skillsCheck(row, ctx.pkgDir));
|
|
9844
|
+
checks.push(hookRunsCheck(row, env), hookSeenCheck(row, dataRootOf(env, ctx.home)), skillsCheck(row, ctx.pkgDir));
|
|
9632
9845
|
if (row.id === "pi") return withHookGate(checks, piSettingsGate(env, ctx.home, ctx.pkgDir, process.cwd()));
|
|
9633
9846
|
if (row.id === "vscode") return withHookGate(checks, vscodeSettingsGate(env, ctx.home, process.cwd()));
|
|
9634
9847
|
return row.id === "zcode" ? withHookGate(checks, zcodeConfigGate(ctx.home)) : checks;
|
|
@@ -9700,20 +9913,21 @@ function agentHomeDir(id, ctx) {
|
|
|
9700
9913
|
if (id === "copilot-cli") return copilotDirOf(ctx.env, ctx.home);
|
|
9701
9914
|
if (id === "kiro") return kiroDirOf(ctx.env, ctx.home);
|
|
9702
9915
|
if (id === "opencode") return opencodeDirOf(ctx.env, ctx.home);
|
|
9916
|
+
if (id === "gemini") return geminiDirOf(ctx.env, ctx.home);
|
|
9703
9917
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9704
9918
|
}
|
|
9705
9919
|
function detectAgents(reg, ctx) {
|
|
9706
|
-
return reg.filter((r2) =>
|
|
9920
|
+
return reg.filter((r2) => existsSync16(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9707
9921
|
}
|
|
9708
9922
|
async function runSetup(opts) {
|
|
9709
9923
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9710
9924
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9711
9925
|
const reg = buildRegistry(ctx);
|
|
9712
9926
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9713
|
-
if (!
|
|
9927
|
+
if (!existsSync16(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9714
9928
|
}
|
|
9715
9929
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9716
|
-
const root =
|
|
9930
|
+
const root = dataRootOf(ctx.env, ctx.home);
|
|
9717
9931
|
if (!opts.dryRun) {
|
|
9718
9932
|
const held = takeLock(root, runId);
|
|
9719
9933
|
if (held) return { exitCode: 1, agents: [], error: held };
|
|
@@ -9766,7 +9980,7 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9766
9980
|
return { ...res, status: "FAIL", reason: e.message };
|
|
9767
9981
|
}
|
|
9768
9982
|
const configEdited = (file) => plan.edits.some((e) => e.file === file && e.changes.some((c3) => !isTrust(row, c3)));
|
|
9769
|
-
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)));
|
|
9983
|
+
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)));
|
|
9770
9984
|
res.changes = [...plan.edits.flatMap((e) => e.changes), ...[...plan.cli, ...plan.refresh].map((args) => ({ command: [row.cli.bin, ...args] }))];
|
|
9771
9985
|
if (dryRun) return res;
|
|
9772
9986
|
try {
|
|
@@ -9804,10 +10018,10 @@ async function runDoctor(opts) {
|
|
|
9804
10018
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9805
10019
|
const reg = buildRegistry(ctx);
|
|
9806
10020
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9807
|
-
if (!
|
|
10021
|
+
if (!existsSync16(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9808
10022
|
}
|
|
9809
10023
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9810
|
-
const run = new Run(
|
|
10024
|
+
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
9811
10025
|
const agents = [];
|
|
9812
10026
|
for (const id of ids) {
|
|
9813
10027
|
const row = reg.find((r2) => r2.id === id);
|
|
@@ -9848,7 +10062,9 @@ function notSetUpReason(row, res, env) {
|
|
|
9848
10062
|
const h2 = row.hookInstall;
|
|
9849
10063
|
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
9850
10064
|
const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
9851
|
-
|
|
10065
|
+
if (oc2) return `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode`;
|
|
10066
|
+
if (row.id === "gemini" && hostBin("gemini", env).file !== void 0) return `${NOT_SET_UP_REASON}, or run: ${NATIVE_INSTALL.gemini[0]}`;
|
|
10067
|
+
return NOT_SET_UP_REASON;
|
|
9852
10068
|
}
|
|
9853
10069
|
function hasPluginIssue(row) {
|
|
9854
10070
|
const h2 = row.hookInstall;
|
|
@@ -9870,14 +10086,14 @@ function isTrust(row, c3) {
|
|
|
9870
10086
|
}
|
|
9871
10087
|
function runRemove(opts) {
|
|
9872
10088
|
const env = opts.env ?? process.env;
|
|
9873
|
-
const root =
|
|
10089
|
+
const root = dataRootOf(env, opts.home);
|
|
9874
10090
|
const base = path12.join(root, BACKUP_DIR);
|
|
9875
|
-
if (!
|
|
10091
|
+
if (!existsSync16(base)) return { exitCode: 0, restored: 0 };
|
|
9876
10092
|
const held = takeLock(root, "remove");
|
|
9877
10093
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
9878
10094
|
let restored = 0;
|
|
9879
10095
|
try {
|
|
9880
|
-
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) =>
|
|
10096
|
+
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync16(path12.join(d, MANIFEST))).sort().reverse();
|
|
9881
10097
|
for (const dir of runs) {
|
|
9882
10098
|
const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
|
|
9883
10099
|
undo(dir, m3.entries, env);
|
|
@@ -10090,7 +10306,7 @@ async function report(ui, command, res, write) {
|
|
|
10090
10306
|
const { text: text2, title } = buildIssueReport(command, res, ui);
|
|
10091
10307
|
let file = "";
|
|
10092
10308
|
if (write) {
|
|
10093
|
-
const dir = path13.join(ui.ctx.
|
|
10309
|
+
const dir = path13.join(dataRootOf(ui.ctx.env, ui.ctx.home), REPORT_DIR);
|
|
10094
10310
|
mkdirSync6(dir, { recursive: true });
|
|
10095
10311
|
file = path13.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
10096
10312
|
writeFileSync4(file, text2);
|
|
@@ -10201,7 +10417,7 @@ async function remove(ui) {
|
|
|
10201
10417
|
}
|
|
10202
10418
|
}
|
|
10203
10419
|
if (ui.f.dryRun) {
|
|
10204
|
-
out(`Would restore every file recorded under ${path13.join(ui.ctx.
|
|
10420
|
+
out(`Would restore every file recorded under ${path13.join(dataRootOf(ui.ctx.env, ui.ctx.home), "backups")}`);
|
|
10205
10421
|
return EXIT_OK;
|
|
10206
10422
|
}
|
|
10207
10423
|
const r2 = runRemove({ home: ui.ctx.home, env: ui.ctx.env });
|
|
@@ -10341,7 +10557,7 @@ async function upgrade(ui) {
|
|
|
10341
10557
|
}
|
|
10342
10558
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10343
10559
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
10344
|
-
if (!root || !
|
|
10560
|
+
if (!root || !existsSync17(cli)) {
|
|
10345
10561
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10346
10562
|
return EXIT_FAIL;
|
|
10347
10563
|
}
|
|
@@ -10380,12 +10596,12 @@ Run context-mode ${cmd} --help.`);
|
|
|
10380
10596
|
}
|
|
10381
10597
|
|
|
10382
10598
|
// src/entries/is-entry.ts
|
|
10383
|
-
import { realpathSync as
|
|
10599
|
+
import { realpathSync as realpathSync10 } from "node:fs";
|
|
10384
10600
|
function isEntry(main2, argv1, self) {
|
|
10385
10601
|
if (main2 !== void 0) return main2;
|
|
10386
10602
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
10387
10603
|
try {
|
|
10388
|
-
return
|
|
10604
|
+
return realpathSync10(argv1) === realpathSync10(self);
|
|
10389
10605
|
} catch {
|
|
10390
10606
|
return false;
|
|
10391
10607
|
}
|
|
@@ -10436,7 +10652,7 @@ function route(argv, version) {
|
|
|
10436
10652
|
` };
|
|
10437
10653
|
}
|
|
10438
10654
|
function main() {
|
|
10439
|
-
const dir = path14.dirname(
|
|
10655
|
+
const dir = path14.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
|
|
10440
10656
|
let version = "";
|
|
10441
10657
|
try {
|
|
10442
10658
|
version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|