context-mode 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 realpathSync9 } from "node:fs";
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,7 @@ 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"]);
299
300
  var OWN_TOOL_PREFIX = "ctx_";
300
301
  var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
301
302
  var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
@@ -365,18 +366,17 @@ var AGENT_HOME_DIR = Object.freeze({
365
366
  var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
366
367
  var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
367
368
  var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
368
- var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
369
369
  var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
370
370
  var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
371
371
  var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
372
372
  var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
373
+ var PERSISTED_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
373
374
  var OPS_SPLIT_FILES = Object.freeze([
374
375
  "doctor-env.ts",
375
376
  "doctor-config.ts",
376
377
  "doctor-hook.ts",
377
378
  "doctor-db.ts",
378
379
  "doctor-heal.ts",
379
- "release-fetch.ts",
380
380
  "verify-sums.ts",
381
381
  "plugin-swap.ts",
382
382
  "host-write.ts",
@@ -409,10 +409,18 @@ var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
409
409
  var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
410
410
  var UPGRADE_HOST_COMMAND = Object.freeze({
411
411
  "claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
412
- codex: "rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",
413
- gemini: "gemini extensions install https://github.com/mksglu/context-mode --auto-update",
414
- qwen: "qwen extensions install https://github.com/mksglu/context-mode --auto-update"
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"
415
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";
416
424
  var V1_SCRIPT_NAMES = Object.freeze([
417
425
  "afteragentresponse.mjs",
418
426
  "aftermodel.mjs",
@@ -450,6 +458,7 @@ var HOOKS_JSON_FILE = "hooks.json";
450
458
  var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
451
459
  var CODEX_HOME_ENV = "CODEX_HOME";
452
460
  var COPILOT_HOME_ENV = "COPILOT_HOME";
461
+ var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
453
462
  var KIRO_HOME_ENV = "KIRO_HOME";
454
463
  var OPENCODE_CONFIG_DIR_ENV = "OPENCODE_CONFIG_DIR";
455
464
  var APPDATA_ENV = "APPDATA";
@@ -476,6 +485,9 @@ var STATUS_LINE_KEY = "statusLine";
476
485
  var PI_PACKAGES_KEY = "packages";
477
486
  var OPENCODE_PLUGIN_KEY = "plugin";
478
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`;
479
491
  var V1_DATA_DIR_NAME = "context-mode";
480
492
  var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
481
493
  var V1_SESSIONS_DIR_NAME = "sessions";
@@ -504,16 +516,19 @@ var V1_REASON = Object.freeze({
504
516
  kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
505
517
  piNpm: "old context-mode Pi package npm:context-mode",
506
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",
507
521
  zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
508
522
  dataDir: "old context-mode data dir <agent home>/context-mode/",
509
523
  dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
510
524
  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"
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"
512
527
  });
513
- 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]);
514
530
  var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
515
531
  var SERVER_ENTRY_FILE = "server.mjs";
516
- var VSCODE_WORKSPACE_VAR = "${workspaceFolder}";
517
532
  var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
518
533
  var HOST_NODE_COMMAND = "node";
519
534
  var EXE_SUFFIX = ".exe";
@@ -609,7 +624,7 @@ var NATIVE_INSTALL = Object.freeze({
609
624
  "copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
610
625
  vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
611
626
  kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
612
- zcode: ["npm i -g context-mode", "context-mode setup --agents zcode"]
627
+ zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
613
628
  });
614
629
  var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
615
630
 
@@ -626,9 +641,9 @@ function canonicalName(name, ownPrefix) {
626
641
  if (name.startsWith(ownPrefix)) return name.slice(ownPrefix.length);
627
642
  if (!name.startsWith(MCP_PREFIX)) return name;
628
643
  const rest = name.slice(MCP_PREFIX.length);
629
- const sep2 = rest.indexOf(MCP_SEP);
630
- if (sep2 < 0) return name;
631
- return "mcp:" + rest.slice(0, sep2) + ":" + rest.slice(sep2 + MCP_SEP.length);
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);
632
647
  }
633
648
  function outputOf(resp) {
634
649
  if (resp === void 0) return "";
@@ -828,6 +843,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
828
843
  var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
829
844
  var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
830
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";
831
847
  function own(p3, key) {
832
848
  return Object.hasOwn(p3, key) ? p3[key] : void 0;
833
849
  }
@@ -847,13 +863,67 @@ function canonicalName2(name, mcp) {
847
863
  if (typeof server !== "string" || typeof tool !== "string") return name;
848
864
  return "mcp:" + server + ":" + tool;
849
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
+ }
850
881
  function readResult2(resp) {
851
882
  const obj = typeof resp === "object" && resp !== null ? resp : void 0;
852
883
  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);
884
+ const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
854
885
  const err2 = obj === void 0 ? void 0 : own(obj, "error");
855
886
  return { isError: err2 !== void 0 && err2 !== null, bytes: Buffer.byteLength(text2), text: text2 };
856
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
+ }
857
927
  function decode3(raw) {
858
928
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
859
929
  const p3 = raw;
@@ -871,7 +941,7 @@ function decode3(raw) {
871
941
  ev.tool = {
872
942
  name,
873
943
  canonicalName: canonicalName2(name, own(p3, "mcp_context")),
874
- input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
944
+ input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
875
945
  };
876
946
  }
877
947
  if (event === "PostToolUse") ev.result = readResult2(own(p3, "tool_response"));
@@ -889,7 +959,7 @@ function encode3(ev, d, _extra) {
889
959
  return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
890
960
  case "replace":
891
961
  if (ev.event !== "PostToolUse") return EMPTY;
892
- 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 };
893
963
  }
894
964
  }
895
965
 
@@ -1046,9 +1116,9 @@ function canonicalName4(name) {
1046
1116
  if (Object.hasOwn(NATIVE_TO_CANONICAL4, name)) return NATIVE_TO_CANONICAL4[name];
1047
1117
  if (!name.startsWith(MCP_PREFIX2)) return name;
1048
1118
  const rest = name.slice(MCP_PREFIX2.length);
1049
- const sep2 = rest.indexOf(MCP_SEP2);
1050
- if (sep2 <= 0 || sep2 === rest.length - 1) return name;
1051
- return "mcp:" + rest.slice(0, sep2) + ":" + rest.slice(sep2 + MCP_SEP2.length);
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);
1052
1122
  }
1053
1123
  var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
1054
1124
  function policyInput(name, canonical, input) {
@@ -1177,9 +1247,9 @@ function canonicalName5(name) {
1177
1247
  if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
1178
1248
  if (!name.startsWith(MCP_PREFIX3)) return name;
1179
1249
  const rest = name.slice(MCP_PREFIX3.length);
1180
- const sep2 = rest.indexOf(MCP_SEP3);
1181
- if (sep2 <= 0 || sep2 === rest.length - 1) return name;
1182
- return "mcp:" + rest.slice(0, sep2) + ":" + rest.slice(sep2 + MCP_SEP3.length);
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);
1183
1253
  }
1184
1254
  function readResult5(resp) {
1185
1255
  const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : JSON.stringify(resp);
@@ -1222,6 +1292,7 @@ function encode7(ev, d, _extra) {
1222
1292
 
1223
1293
  // src/adapters/zcode.ts
1224
1294
  var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1295
+ var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1225
1296
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1226
1297
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1227
1298
  var FAILURE_EVENT2 = "PostToolUseFailure";
@@ -1231,7 +1302,9 @@ function decode8(raw) {
1231
1302
  for (const [snake2, camel] of Object.entries(TWINS)) if (p3[snake2] === void 0) p3[snake2] = p3[camel];
1232
1303
  const failure = p3.hook_event_name === FAILURE_EVENT2;
1233
1304
  if (failure) p3.hook_event_name = "PostToolUse";
1234
- const ev = decodeClaudeShape(p3, "zcode", TOOL_NAME_PREFIX8, ZCODE_SOURCES);
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);
1235
1308
  if (failure) {
1236
1309
  const text2 = typeof p3.error === "string" ? p3.error : p3.error === void 0 ? "" : JSON.stringify(p3.error);
1237
1310
  ev.result = { isError: true, bytes: Buffer.byteLength(text2), text: text2 };
@@ -1312,8 +1385,9 @@ var OPENCODE_EVENTS = {
1312
1385
  "step-finish": "Usage"
1313
1386
  };
1314
1387
  var SHELL_TOOL_NAME = "bash";
1388
+ var READ_TOOL_NAME = "read";
1315
1389
  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"])) };
1390
+ var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n3) => [n3, "Bash"])) };
1317
1391
  function toCanonicalTool(name) {
1318
1392
  if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1319
1393
  return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
@@ -1541,9 +1615,9 @@ var ADAPTERS = Object.freeze([
1541
1615
  installMode: "in-process",
1542
1616
  projectSource: "spawn-cwd",
1543
1617
  toolNamePrefix: TOOL_NAME_PREFIX10,
1544
- nativeTools: { shell: [SHELL_TOOL_NAME] },
1618
+ nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
1545
1619
  execReadOnlyHint: false,
1546
- // D-HF-OPENCODE-SHELL-1
1620
+ // D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
1547
1621
  // Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
1548
1622
  eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
1549
1623
  compactDelivery: "opencode-cache",
@@ -1773,7 +1847,7 @@ Examples:
1773
1847
  // src/cli/commands.ts
1774
1848
  import { spawnSync as spawnSync5 } from "node:child_process";
1775
1849
  import { createHash as createHash2 } from "node:crypto";
1776
- import { existsSync as existsSync16, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
1850
+ import { existsSync as existsSync17, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
1777
1851
  import os from "node:os";
1778
1852
  import path13 from "node:path";
1779
1853
 
@@ -2064,18 +2138,18 @@ var wrapWord = (rows, word, columns) => {
2064
2138
  }
2065
2139
  };
2066
2140
  var stringVisibleTrimSpacesRight = (string) => {
2067
- const words = string.split(" ");
2068
- let last2 = words.length;
2141
+ const words2 = string.split(" ");
2142
+ let last2 = words2.length;
2069
2143
  while (last2) {
2070
- if (dist_default2(words[last2 - 1])) {
2144
+ if (dist_default2(words2[last2 - 1])) {
2071
2145
  break;
2072
2146
  }
2073
2147
  last2--;
2074
2148
  }
2075
- if (last2 === words.length) {
2149
+ if (last2 === words2.length) {
2076
2150
  return string;
2077
2151
  }
2078
- return words.slice(0, last2).join(" ") + words.slice(last2).join("");
2152
+ return words2.slice(0, last2).join(" ") + words2.slice(last2).join("");
2079
2153
  };
2080
2154
  var exec = (string, columns, options = {}) => {
2081
2155
  if (options.trim !== false && string.trim() === "") {
@@ -2084,11 +2158,11 @@ var exec = (string, columns, options = {}) => {
2084
2158
  let returnValue = "";
2085
2159
  let escapeCode;
2086
2160
  let escapeUrl;
2087
- const words = string.split(" ");
2161
+ const words2 = string.split(" ");
2088
2162
  let rows = [""];
2089
2163
  let rowLength = 0;
2090
- for (let index = 0; index < words.length; index++) {
2091
- const word = words[index];
2164
+ for (let index = 0; index < words2.length; index++) {
2165
+ const word = words2[index];
2092
2166
  if (options.trim !== false) {
2093
2167
  const row = rows.at(-1) ?? "";
2094
2168
  const trimmed = row.trimStart();
@@ -4686,6 +4760,10 @@ function copilotDirOf(env, home) {
4686
4760
  const dir = env[COPILOT_HOME_ENV];
4687
4761
  return dir !== void 0 && dir !== "" ? dir : join2(home, ...AGENT_HOME_DIR["copilot-cli"]);
4688
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
+ }
4689
4767
  function kiroDirOf(env, home, platform = process.platform) {
4690
4768
  const p3 = platform === "win32" ? win32 : posix;
4691
4769
  const fallback = p3.join(home, ...AGENT_HOME_DIR.kiro);
@@ -4739,11 +4817,15 @@ function ownMcpFileOf(agent, file, env, home) {
4739
4817
  if (agent === "kiro") return join2(kiroDirOf(env, home), ...file.slice(1));
4740
4818
  return agent === "vscode" ? join2(vscodeUserDirOf(env, home), ...file) : join2(home, ...file);
4741
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
+ }
4742
4824
 
4743
4825
  // src/core/ops/doctor-issue.ts
4744
4826
  import { spawnSync } from "node:child_process";
4745
- import { closeSync, existsSync as existsSync9, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync5, readSync, realpathSync as realpathSync4, writeFileSync as writeFileSync2 } from "node:fs";
4746
- import { delimiter, join as join9 } from "node:path";
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";
4747
4829
 
4748
4830
  // src/core/hooks/fallback.ts
4749
4831
  import { join as join3, resolve as resolve2 } from "node:path";
@@ -4840,12 +4922,12 @@ var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = proce
4840
4922
 
4841
4923
  // src/core/ops/doctor-config.ts
4842
4924
  import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
4843
- import { join as join8 } from "node:path";
4925
+ import { join as join9 } from "node:path";
4844
4926
 
4845
4927
  // src/core/ops/detect-v1.ts
4846
4928
  import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
4847
4929
  import { tmpdir } from "node:os";
4848
- import { join as join6 } from "node:path";
4930
+ import { join as join7 } from "node:path";
4849
4931
 
4850
4932
  // src/core/ops/host-config.ts
4851
4933
  import { existsSync as existsSync4, readFileSync } from "node:fs";
@@ -7291,8 +7373,8 @@ function replaceToml(text2, doc, path15, value) {
7291
7373
  let out2 = text2;
7292
7374
  for (const [s, e, put] of cuts) out2 = out2.slice(0, s) + put + out2.slice(e);
7293
7375
  if (owned.length > 0 || block2 === "") return out2;
7294
- const sep2 = out2 === "" ? "" : out2.endsWith("\n\n") ? "" : out2.endsWith("\n") ? "\n" : "\n\n";
7295
- return out2 + sep2 + block2;
7376
+ const sep3 = out2 === "" ? "" : out2.endsWith("\n\n") ? "" : out2.endsWith("\n") ? "\n" : "\n\n";
7377
+ return out2 + sep3 + block2;
7296
7378
  }
7297
7379
  var tableLike = (v) => v === void 0 || isPlainObject(v);
7298
7380
  function setTomlText(text2, path15, value) {
@@ -7330,15 +7412,14 @@ function setText(agent, path15, text2, format, key, value) {
7330
7412
  function isNodeCommand(command) {
7331
7413
  if (typeof command !== "string") return false;
7332
7414
  let at = -1;
7333
- for (const sep2 of V1_PATH_SEPS) at = Math.max(at, command.lastIndexOf(sep2));
7415
+ for (const sep3 of V1_PATH_SEPS) at = Math.max(at, command.lastIndexOf(sep3));
7334
7416
  const exe = command.slice(at + 1).toLowerCase();
7335
7417
  return exe === HOST_NODE_COMMAND || exe === HOST_NODE_COMMAND + EXE_SUFFIX;
7336
7418
  }
7337
7419
  function ownMcpValue(agent, node, server) {
7338
7420
  const mcp = OWN_MCP_ENTRY[agent];
7339
7421
  if (mcp === void 0) return void 0;
7340
- const tail = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, VSCODE_WORKSPACE_VAR] : [];
7341
- 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] };
7342
7423
  }
7343
7424
  function applyEdits(agent, path15, text2, format, wanted) {
7344
7425
  const parsed = parseHostConfig(agent, path15, text2, format);
@@ -7356,6 +7437,28 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
7356
7437
  return applyEdits(agent, path15, text2, format, wanted);
7357
7438
  }
7358
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
+
7359
7462
  // src/core/ops/detect-v1.ts
7360
7463
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
7361
7464
  var keyPath = (...parts) => parts.join(".");
@@ -7430,7 +7533,7 @@ function isV2McpTable(v) {
7430
7533
  const first = Array.isArray(v[MCP_ARGS_FIELD]) ? v[MCP_ARGS_FIELD][0] : void 0;
7431
7534
  if (typeof first !== "string") return false;
7432
7535
  let at = -1;
7433
- for (const sep2 of V1_PATH_SEPS) at = Math.max(at, first.lastIndexOf(sep2));
7536
+ for (const sep3 of V1_PATH_SEPS) at = Math.max(at, first.lastIndexOf(sep3));
7434
7537
  return first.slice(at + 1) === SERVER_ENTRY_FILE;
7435
7538
  }
7436
7539
  var listOf = (v) => Array.isArray(v) ? v : [];
@@ -7461,7 +7564,7 @@ function flatCommands(events2, prefix) {
7461
7564
  return out2;
7462
7565
  }
7463
7566
  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((sep2) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep2) + sep2));
7567
+ var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
7465
7568
  function dataDir(dir, reason, out2) {
7466
7569
  if (existsSync5(dir)) out2.push(finding(dir, "", reason));
7467
7570
  }
@@ -7471,7 +7574,7 @@ function mcpEntry(file, doc, out2) {
7471
7574
  }
7472
7575
  }
7473
7576
  function claudeShapeSettings(agentHome, out2) {
7474
- const file = join6(agentHome, SETTINGS_FILE);
7577
+ const file = join7(agentHome, SETTINGS_FILE);
7475
7578
  const doc = readJson(file);
7476
7579
  for (const c3 of nestedCommands(doc)) {
7477
7580
  if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
@@ -7491,49 +7594,50 @@ function v1HookFile(file, out2) {
7491
7594
  function scanClaudeCode(home, agentHome, out2) {
7492
7595
  claudeShapeSettings(agentHome, out2);
7493
7596
  for (const ext of V1_CACHE_HEAL_EXTS) {
7494
- const file = join6(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
7597
+ const file = join7(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
7495
7598
  if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
7496
7599
  }
7497
- const userFile = join6(home, CLAUDE_USER_CONFIG_FILE);
7600
+ const userFile = join7(home, CLAUDE_USER_CONFIG_FILE);
7498
7601
  mcpEntry(userFile, readJson(userFile), out2);
7499
- dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7602
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7500
7603
  }
7501
7604
  function scanCodex(agentHome, out2) {
7502
- const hooksFile = join6(agentHome, HOOKS_JSON_FILE);
7605
+ const hooksFile = join7(agentHome, HOOKS_JSON_FILE);
7503
7606
  for (const c3 of nestedCommands(readJson(hooksFile))) {
7504
7607
  if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
7505
7608
  out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
7506
7609
  }
7507
7610
  }
7508
- const tomlFile = join6(agentHome, CONFIG_TOML_FILE);
7611
+ const tomlFile = join7(agentHome, CONFIG_TOML_FILE);
7509
7612
  const config = readTomlValue(tomlFile);
7510
7613
  for (const span of readTomlTables(tomlFile)) {
7511
7614
  if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
7512
7615
  if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
7513
7616
  out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
7514
7617
  }
7515
- dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7618
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7516
7619
  }
7517
7620
  function scanGemini(agentHome, out2) {
7518
- const file = join6(agentHome, SETTINGS_FILE);
7621
+ const file = join7(agentHome, SETTINGS_FILE);
7519
7622
  for (const c3 of nestedCommands(readJson(file))) {
7520
7623
  if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
7521
7624
  }
7522
- dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
7625
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
7523
7626
  }
7524
7627
  function scanVscode(agentHome, project, out2) {
7525
7628
  if (project !== void 0) {
7526
- v1HookFile(join6(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7527
- const mcpFile = join6(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
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);
7528
7631
  const doc = readJson(mcpFile);
7529
7632
  const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
7530
7633
  const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
7531
7634
  if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
7532
7635
  out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
7533
7636
  }
7534
- dataDir(join6(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
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);
7535
7639
  }
7536
- dataDir(join6(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7640
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7537
7641
  }
7538
7642
  function jsonFiles(dir) {
7539
7643
  try {
@@ -7543,10 +7647,10 @@ function jsonFiles(dir) {
7543
7647
  }
7544
7648
  }
7545
7649
  function scanKiro(agentHome, project, out2) {
7546
- const agentsDir = join6(agentHome, KIRO_AGENTS_DIR);
7547
- const defaultFile = join6(agentHome, ...KIRO_AGENT_FILE);
7650
+ const agentsDir = join7(agentHome, KIRO_AGENTS_DIR);
7651
+ const defaultFile = join7(agentHome, ...KIRO_AGENT_FILE);
7548
7652
  for (const name of jsonFiles(agentsDir)) {
7549
- const file = join6(agentsDir, name);
7653
+ const file = join7(agentsDir, name);
7550
7654
  const doc = readJson(file);
7551
7655
  if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
7552
7656
  out2.push(finding(file, "", V1_REASON.kiroAgentFile));
@@ -7557,46 +7661,48 @@ function scanKiro(agentHome, project, out2) {
7557
7661
  if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
7558
7662
  }
7559
7663
  }
7560
- const steeringDocs = [join6(agentHome, ...KIRO_STEERING_FILE)];
7561
- if (project !== void 0) steeringDocs.push(join6(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
7664
+ const steeringDocs = [join7(agentHome, ...KIRO_STEERING_FILE)];
7665
+ if (project !== void 0) steeringDocs.push(join7(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
7562
7666
  for (const file of steeringDocs) {
7563
7667
  if (existsSync5(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
7564
7668
  }
7565
- dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7669
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7566
7670
  }
7567
7671
  function piNpmIsCurrent(piAgentDir) {
7568
- const doc = readJson(join6(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
7672
+ const doc = readJson(join7(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
7569
7673
  const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
7570
7674
  return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
7571
7675
  }
7572
7676
  function scanPi(piAgentDir, agentHome, out2) {
7573
- const file = join6(piAgentDir, SETTINGS_FILE);
7677
+ const file = join7(piAgentDir, SETTINGS_FILE);
7574
7678
  const doc = readJson(file);
7575
7679
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
7576
7680
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
7577
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));
7578
7683
  });
7579
- dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7684
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7580
7685
  }
7581
7686
  function scanOpencode(agentHome, out2) {
7582
7687
  for (const name of OPENCODE_CONFIG_FILES) {
7583
- const file = join6(agentHome, name);
7688
+ const file = join7(agentHome, name);
7584
7689
  const doc = readJson(file);
7585
7690
  if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
7586
7691
  doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
7587
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));
7588
7694
  });
7589
7695
  return;
7590
7696
  }
7591
7697
  }
7592
7698
  function scanZcode(agentHome, out2) {
7593
- const configFile = join6(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
7699
+ const configFile = join7(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
7594
7700
  const config = readJson(configFile);
7595
7701
  const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
7596
7702
  for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
7597
7703
  if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
7598
7704
  }
7599
- const hooksFile = join6(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
7705
+ const hooksFile = join7(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
7600
7706
  for (const c3 of nestedCommands(readJson(hooksFile))) {
7601
7707
  if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
7602
7708
  }
@@ -7620,14 +7726,14 @@ function firstTmpMatch(dir) {
7620
7726
  }
7621
7727
  }
7622
7728
  function scanAll(home, tmp, out2) {
7623
- const root = join6(home, DATA_ROOT.slice(1));
7624
- for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join6(root, name), V1_REASON.dataRoot, out2);
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);
7625
7731
  if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
7626
7732
  }
7627
7733
  function detectV1(agent, home, scope = {}) {
7628
7734
  const out2 = [];
7629
7735
  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 : join6(home, ...AGENT_HOME_DIR[agent]);
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]);
7631
7737
  switch (agent) {
7632
7738
  case "claude-code":
7633
7739
  scanClaudeCode(home, agentHome, out2);
@@ -7640,11 +7746,11 @@ function detectV1(agent, home, scope = {}) {
7640
7746
  break;
7641
7747
  case "qwen":
7642
7748
  claudeShapeSettings(agentHome, out2);
7643
- dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7749
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7644
7750
  break;
7645
7751
  case "copilot-cli":
7646
- v1HookFile(join6(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7647
- dataDir(join6(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7752
+ v1HookFile(join7(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7753
+ dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7648
7754
  break;
7649
7755
  case "vscode":
7650
7756
  scanVscode(agentHome, project, out2);
@@ -7653,7 +7759,7 @@ function detectV1(agent, home, scope = {}) {
7653
7759
  scanKiro(agentHome, project, out2);
7654
7760
  break;
7655
7761
  case "pi":
7656
- scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join6(agentHome, PI_AGENT_DIR), agentHome, out2);
7762
+ scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join7(agentHome, PI_AGENT_DIR), agentHome, out2);
7657
7763
  break;
7658
7764
  // D-WIN-PIDIR-1: empty is unset
7659
7765
  case "opencode":
@@ -7668,12 +7774,12 @@ function detectV1(agent, home, scope = {}) {
7668
7774
  }
7669
7775
 
7670
7776
  // src/core/ops/plugin-root.ts
7671
- import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
7672
- import { dirname as dirname5, isAbsolute, join as join7, sep } from "node:path";
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";
7673
7779
  import { fileURLToPath as fileURLToPath2 } from "node:url";
7674
7780
 
7675
7781
  // src/setup/pi-gate.ts
7676
- import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
7782
+ import { existsSync as existsSync7, readFileSync as readFileSync4, realpathSync as realpathSync4 } from "node:fs";
7677
7783
  import path3 from "node:path";
7678
7784
  var OWN_FILE = "pi/index.js";
7679
7785
  var EXTENSIONS_KEY = "extensions";
@@ -7691,7 +7797,7 @@ function load(file) {
7691
7797
  }
7692
7798
  var real = (p3) => {
7693
7799
  try {
7694
- return realpathSync3(p3);
7800
+ return realpathSync4(p3);
7695
7801
  } catch {
7696
7802
  return path3.resolve(p3);
7697
7803
  }
@@ -7792,6 +7898,7 @@ function formUrl(title, summary) {
7792
7898
  }
7793
7899
 
7794
7900
  // src/setup/registry.ts
7901
+ import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
7795
7902
  import path4 from "node:path";
7796
7903
 
7797
7904
  // src/setup/hook-shapes.ts
@@ -7850,7 +7957,6 @@ var HOOK_SHAPES = {
7850
7957
  var SERVER_BUNDLE = "server.mjs";
7851
7958
  var HOOK_BUNDLE = "hook.mjs";
7852
7959
  var AGENT_FLAG = "--agent";
7853
- var STATE_DIR = ".context-mode";
7854
7960
  var LOCK_FILE = "setup.lock";
7855
7961
  var BACKUP_DIR = "backups";
7856
7962
  var PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
@@ -7914,10 +8020,39 @@ function extensionPlugin(bin, id) {
7914
8020
  var NATIVE_PLUGIN = {
7915
8021
  codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "table", hookTrust: true },
7916
8022
  qwen: extensionPlugin("qwen", "qwen"),
7917
- 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
+ }
7918
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);
7919
8054
  function serverCmd(ctx, id) {
7920
- return [process.execPath, path4.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
8055
+ return [SETUP_NODE, path4.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
7921
8056
  }
7922
8057
  function hookCommandString(row) {
7923
8058
  const [node, file, flag, id] = row.hookCommand ?? [];
@@ -7996,7 +8131,8 @@ function hookFilesFor(ctx, id) {
7996
8131
  case "claude-code":
7997
8132
  return [{ file: path4.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
7998
8133
  case "gemini":
7999
- return [{ file: path4.join(home, ".gemini", "settings.json"), mode: "drop" }];
8134
+ return [{ file: path4.join(geminiDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
8135
+ // D-R38-GEMINI-HOME-1
8000
8136
  case "qwen":
8001
8137
  return [{ file: path4.join(home, ".qwen", "settings.json"), mode: "drop" }];
8002
8138
  default:
@@ -8043,8 +8179,8 @@ function buildRegistry(ctx) {
8043
8179
  const id = row.id;
8044
8180
  const config = configFor(ctx, id);
8045
8181
  const hookFiles = hookFilesFor(ctx, id);
8046
- const runCommand2 = [process.execPath, path4.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
8047
- 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";
8048
8184
  const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
8049
8185
  const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
8050
8186
  const hookInstall = hookInstallFor(ctx, getAdapter(id), command);
@@ -8089,11 +8225,13 @@ function assertWritable(row, file) {
8089
8225
  }
8090
8226
 
8091
8227
  // src/setup/gemini-gate.ts
8092
- import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
8228
+ import { existsSync as existsSync11, readFileSync as readFileSync6 } from "node:fs";
8093
8229
  import path5 from "node:path";
8094
8230
  var GEMINI_DIR = ".gemini";
8095
8231
  var SETTINGS_FILE2 = "settings.json";
8096
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";
8097
8235
  var OWN_AGENT = "gemini";
8098
8236
  function systemSettingsPath(env) {
8099
8237
  const set2 = env[SYSTEM_PATH_ENV];
@@ -8102,8 +8240,12 @@ function systemSettingsPath(env) {
8102
8240
  if (process.platform === "win32") return "C:\\ProgramData\\gemini-cli\\settings.json";
8103
8241
  return "/etc/gemini-cli/settings.json";
8104
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
+ }
8105
8247
  function load2(file) {
8106
- if (!existsSync10(file)) return void 0;
8248
+ if (!existsSync11(file)) return void 0;
8107
8249
  try {
8108
8250
  return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync6(file, "utf8")), "jsonc") };
8109
8251
  } catch {
@@ -8111,7 +8253,7 @@ function load2(file) {
8111
8253
  }
8112
8254
  }
8113
8255
  function sources(env, home, cwd) {
8114
- return [path5.join(home, GEMINI_DIR, SETTINGS_FILE2), path5.join(cwd, GEMINI_DIR, SETTINGS_FILE2), systemSettingsPath(env)].map(load2).filter((s) => s !== void 0);
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);
8115
8257
  }
8116
8258
  function ownHookEntry(entry2) {
8117
8259
  return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
@@ -8137,7 +8279,7 @@ function geminiSettingsGate(env, home, cwd) {
8137
8279
  }
8138
8280
 
8139
8281
  // src/setup/zcode-gate.ts
8140
- import { existsSync as existsSync11, readFileSync as readFileSync7 } from "node:fs";
8282
+ import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
8141
8283
  import path6 from "node:path";
8142
8284
  var OWN_AGENT2 = "zcode";
8143
8285
  var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
@@ -8229,7 +8371,7 @@ function zcodeSchemaBad(doc) {
8229
8371
  }
8230
8372
  function zcodeConfigGate(home) {
8231
8373
  const file = path6.join(home, ".zcode", "cli", "config.json");
8232
- if (!existsSync11(file)) return void 0;
8374
+ if (!existsSync12(file)) return void 0;
8233
8375
  let doc;
8234
8376
  try {
8235
8377
  doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync7(file, "utf8")), "json");
@@ -8242,7 +8384,7 @@ function zcodeConfigGate(home) {
8242
8384
  }
8243
8385
 
8244
8386
  // src/setup/vscode-gate.ts
8245
- import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
8387
+ import { existsSync as existsSync13, readFileSync as readFileSync8 } from "node:fs";
8246
8388
  import path7 from "node:path";
8247
8389
  var SETTINGS_FILE3 = "settings.json";
8248
8390
  var WORKSPACE_DIR = ".vscode";
@@ -8251,7 +8393,7 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
8251
8393
  var OWN_LOCATION = "~/.copilot/hooks";
8252
8394
  var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
8253
8395
  function load3(file) {
8254
- if (!existsSync12(file)) return void 0;
8396
+ if (!existsSync13(file)) return void 0;
8255
8397
  try {
8256
8398
  return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
8257
8399
  } catch {
@@ -8293,7 +8435,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
8293
8435
  }
8294
8436
 
8295
8437
  // src/setup/qwen-gate.ts
8296
- import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
8438
+ import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
8297
8439
  import path8 from "node:path";
8298
8440
  var KEY = "disableAllHooks";
8299
8441
  var SETTINGS = "settings.json";
@@ -8309,7 +8451,7 @@ function settingsFiles(env, home, cwd, platform) {
8309
8451
  }
8310
8452
  function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
8311
8453
  for (const file of settingsFiles(env, home, cwd, platform)) {
8312
- if (!existsSync13(file)) continue;
8454
+ if (!existsSync14(file)) continue;
8313
8455
  let value;
8314
8456
  try {
8315
8457
  value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
@@ -8323,7 +8465,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
8323
8465
 
8324
8466
  // src/setup/codex-trust.ts
8325
8467
  import { createHash } from "node:crypto";
8326
- import { existsSync as existsSync14, realpathSync as realpathSync5 } from "node:fs";
8468
+ import { existsSync as existsSync15, realpathSync as realpathSync7 } from "node:fs";
8327
8469
  import path10 from "node:path";
8328
8470
  import { spawn, spawnSync as spawnSync3 } from "node:child_process";
8329
8471
 
@@ -8432,11 +8574,11 @@ function snake(name) {
8432
8574
  function realFile(file) {
8433
8575
  let dir = path10.resolve(file);
8434
8576
  const rest = [];
8435
- while (!existsSync14(dir) && path10.dirname(dir) !== dir) {
8577
+ while (!existsSync15(dir) && path10.dirname(dir) !== dir) {
8436
8578
  rest.unshift(path10.basename(dir));
8437
8579
  dir = path10.dirname(dir);
8438
8580
  }
8439
- return path10.join(realpathSync5(dir), ...rest);
8581
+ return path10.join(realpathSync7(dir), ...rest);
8440
8582
  }
8441
8583
  var ASK_TIMEOUT_MS = 1e4;
8442
8584
  var ASK_TRIES = 3;
@@ -8630,14 +8772,14 @@ function untrustedPluginHooksDetail(hooks) {
8630
8772
  if (!bad.length) return void 0;
8631
8773
  const counts = /* @__PURE__ */ new Map();
8632
8774
  for (const h2 of bad) counts.set(h2.status, (counts.get(h2.status) ?? 0) + 1);
8633
- const words = [...counts].sort((a2, b3) => b3[1] - a2[1] || (a2[0] < b3[0] ? -1 : 1));
8634
- const state = words.length === 1 ? words[0][0] : `${words.map(([w]) => w).join(" or ")} (${words.map(([w, n3]) => `${n3} ${w}`).join(", ")})`;
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(", ")})`;
8635
8777
  return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
8636
8778
  }
8637
8779
 
8638
8780
  // src/setup/copilot-hooks.ts
8639
8781
  import { spawn as spawn2 } from "node:child_process";
8640
- import { realpathSync as realpathSync6 } from "node:fs";
8782
+ import { realpathSync as realpathSync8 } from "node:fs";
8641
8783
  import path11 from "node:path";
8642
8784
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
8643
8785
  var ASK_TIMEOUT_MS2 = 15e3;
@@ -8647,7 +8789,7 @@ var USER_ORIGIN = "user";
8647
8789
  function canon(p3) {
8648
8790
  let r2 = path11.resolve(p3);
8649
8791
  try {
8650
- r2 = realpathSync6(r2);
8792
+ r2 = realpathSync8(r2);
8651
8793
  } catch {
8652
8794
  }
8653
8795
  return process.platform === "win32" ? r2.toLowerCase() : r2;
@@ -8732,7 +8874,7 @@ function listCopilotHooks(env, file, cwd) {
8732
8874
 
8733
8875
  // src/setup/engine.ts
8734
8876
  import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
8735
- import { closeSync as closeSync2, existsSync as existsSync15, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, readdirSync as readdirSync5, realpathSync as realpathSync7, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
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";
8736
8878
  import { tmpdir as tmpdir2 } from "node:os";
8737
8879
  import path12 from "node:path";
8738
8880
 
@@ -8830,7 +8972,7 @@ function isNativeBinary(file) {
8830
8972
  function owningPackage(dir) {
8831
8973
  for (let d = dir; ; d = path12.dirname(d)) {
8832
8974
  const f2 = path12.join(d, "package.json");
8833
- if (existsSync15(f2)) {
8975
+ if (existsSync16(f2)) {
8834
8976
  try {
8835
8977
  return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
8836
8978
  } catch {
@@ -8848,8 +8990,8 @@ function hostBin(bin, env, platform = process.platform) {
8848
8990
  for (const dir of pathEntries(get("PATH") ?? "", platform)) {
8849
8991
  const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
8850
8992
  for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
8851
- if (!f2 || !existsSync15(f2) || !statSync2(f2).isFile()) continue;
8852
- const file = realpathSync7(f2);
8993
+ if (!f2 || !existsSync16(f2) || !statSync2(f2).isFile()) continue;
8994
+ const file = realpathSync9(f2);
8853
8995
  if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
8854
8996
  shims.push(f2);
8855
8997
  }
@@ -8865,10 +9007,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
8865
9007
  return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
8866
9008
  }
8867
9009
  function readOr(file) {
8868
- return existsSync15(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
9010
+ return existsSync16(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
8869
9011
  }
8870
9012
  function readRaw(file) {
8871
- return existsSync15(file) ? readFileSync10(file, "utf8") : void 0;
9013
+ return existsSync16(file) ? readFileSync10(file, "utf8") : void 0;
8872
9014
  }
8873
9015
  var atomicWrite = atomicWriteFile;
8874
9016
  function pidAlive(pid) {
@@ -9013,7 +9155,7 @@ function isNativeSpec(e) {
9013
9155
  function isStaleOwnPlugin(e, entry2) {
9014
9156
  if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
9015
9157
  if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
9016
- if (existsSync15(e)) return false;
9158
+ if (existsSync16(e)) return false;
9017
9159
  const seg = e.split("\\").join("/").split("/");
9018
9160
  const n3 = seg.length;
9019
9161
  if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
@@ -9077,7 +9219,7 @@ function planSkills(row, edits) {
9077
9219
  const s = row.skillInstall;
9078
9220
  if (s.kind !== "dir") return;
9079
9221
  for (const f2 of s.files) {
9080
- if (!existsSync15(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
9222
+ if (!existsSync16(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
9081
9223
  const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
9082
9224
  const before = readRaw(f2.file);
9083
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" }] });
@@ -9315,8 +9457,8 @@ function hookRound(row, env) {
9315
9457
  const bareP95Ms = Math.round(p95(bare));
9316
9458
  const overheadP95Ms = Math.max(0, wallP95Ms - bareP95Ms);
9317
9459
  const budget = overheadBudgetMs(env);
9318
- const ok = overheadP95Ms <= budget;
9319
- return { name: "hook", ok, overheadP95Ms, wallP95Ms, bareP95Ms, detail: ok ? void 0 : `hook overhead p95 ${overheadP95Ms} ms > ${budget} ms` };
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 };
9320
9462
  }
9321
9463
  function hookCheck(row, env) {
9322
9464
  let best;
@@ -9324,7 +9466,7 @@ function hookCheck(row, env) {
9324
9466
  const c3 = hookRound(row, env);
9325
9467
  if (c3.overheadP95Ms === void 0) return c3;
9326
9468
  if (!best || c3.overheadP95Ms < best.overheadP95Ms) best = c3;
9327
- if (c3.ok) break;
9469
+ if (!c3.warn) break;
9328
9470
  }
9329
9471
  return best;
9330
9472
  }
@@ -9381,9 +9523,9 @@ function hookRunsCheck(row, env) {
9381
9523
  }
9382
9524
  var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
9383
9525
  var NOT_SEEN_LINE = "not seen yet, run one tool call";
9384
- function hookSeenCheck(row, home) {
9385
- const base = path12.join(home, STATE_DIR, PROJECTS_DIR_NAME);
9386
- const dirs = existsSync15(base) ? readdirSync5(base) : [];
9526
+ function hookSeenCheck(row, dataRoot) {
9527
+ const base = path12.join(dataRoot, PROJECTS_DIR_NAME);
9528
+ const dirs = existsSync16(base) ? readdirSync5(base) : [];
9387
9529
  let sqlite;
9388
9530
  try {
9389
9531
  sqlite = process.getBuiltinModule("node:sqlite");
@@ -9392,7 +9534,7 @@ function hookSeenCheck(row, home) {
9392
9534
  }
9393
9535
  for (const d of dirs) {
9394
9536
  const file = path12.join(base, d, DB_FILE_NAME);
9395
- if (!sqlite || !existsSync15(file)) continue;
9537
+ if (!sqlite || !existsSync16(file)) continue;
9396
9538
  let db;
9397
9539
  try {
9398
9540
  db = new sqlite.DatabaseSync(file, { readOnly: true });
@@ -9409,7 +9551,7 @@ function skillsCheck(row, pkgDir) {
9409
9551
  const s = row.skillInstall;
9410
9552
  if (s.kind === "package") {
9411
9553
  const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
9412
- const miss = files.filter((f2) => !existsSync15(f2));
9554
+ const miss = files.filter((f2) => !existsSync16(f2));
9413
9555
  if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
9414
9556
  const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
9415
9557
  const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
@@ -9419,7 +9561,7 @@ function skillsCheck(row, pkgDir) {
9419
9561
  });
9420
9562
  return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
9421
9563
  }
9422
- const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync15(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
9564
+ const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync16(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
9423
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 };
9424
9566
  }
9425
9567
  var PLUGIN_ENABLED = "enabled";
@@ -9437,6 +9579,7 @@ function extensionState(n3, text2) {
9437
9579
  let mine = false;
9438
9580
  let state;
9439
9581
  let workspaceOff = false;
9582
+ let workspaceOn = false;
9440
9583
  for (const raw of text2.split("\n")) {
9441
9584
  const line = raw.trimEnd();
9442
9585
  if (line.length && !line.startsWith(" ")) {
@@ -9446,16 +9589,37 @@ function extensionState(n3, text2) {
9446
9589
  const t2 = line.trim();
9447
9590
  if (!mine) continue;
9448
9591
  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)) workspaceOff = t2.slice(EXT_ENABLED_WORKSPACE.length).trim() !== EXT_TRUE;
9592
+ if (t2.startsWith(EXT_ENABLED_WORKSPACE)) {
9593
+ workspaceOff = t2.slice(EXT_ENABLED_WORKSPACE.length).trim() !== EXT_TRUE;
9594
+ workspaceOn = !workspaceOff;
9595
+ }
9450
9596
  }
9597
+ if (state === "disabled" && workspaceOn) state = "enabled";
9451
9598
  return { state, workspaceOff };
9452
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
+ }
9453
9616
  function nativeState(row, env) {
9454
9617
  const none = { state: void 0, workspaceOff: false };
9455
9618
  const n3 = row.nativePlugin;
9456
9619
  if (!n3 || !hostBin(n3.bin, env).file) return none;
9457
9620
  const r2 = runBin(n3.bin, n3.args, env);
9458
9621
  if (r2.status !== 0) return none;
9622
+ if (n3.format === "json") return jsonState(n3, `${r2.stdout}`);
9459
9623
  return n3.format === "extension" ? extensionState(n3, `${r2.stdout}${r2.stderr}`) : { state: tableState(n3, `${r2.stdout}`), workspaceOff: false };
9460
9624
  }
9461
9625
  function nativeRow(row, n3) {
@@ -9479,7 +9643,7 @@ function trimChars(w, chars) {
9479
9643
  }
9480
9644
  async function nativeResult(row, ctx, apply2) {
9481
9645
  const n3 = row.nativePlugin;
9482
- const { state, workspaceOff } = nativeState(row, ctx.env);
9646
+ const { state, workspaceOff, hookGate } = nativeState(row, ctx.env);
9483
9647
  if (!n3 || state === void 0) return void 0;
9484
9648
  const bin = hostBin(n3.bin, ctx.env).file;
9485
9649
  if (state === "disabled") {
@@ -9509,6 +9673,7 @@ async function nativeResult(row, ctx, apply2) {
9509
9673
  res.checks = await verifyRow(nativeRow(row, n3), ctx);
9510
9674
  if (n3.hookTrust) res.checks = withHookTrust(res.checks, hooks, !!apply2?.dryRun);
9511
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);
9512
9677
  const bad = res.checks.filter((c3) => !c3.ok);
9513
9678
  if (bad.length) {
9514
9679
  res.status = "FAIL";
@@ -9628,7 +9793,7 @@ async function verifyRow(row, ctx) {
9628
9793
  const en = hookEnabledCheck(row, ls.status);
9629
9794
  if (en) checks.push(en);
9630
9795
  if (row.copilotSettings) checks.push(await copilotEnabledCheck(row, ctx));
9631
- 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));
9632
9797
  if (row.id === "pi") return withHookGate(checks, piSettingsGate(env, ctx.home, ctx.pkgDir, process.cwd()));
9633
9798
  if (row.id === "vscode") return withHookGate(checks, vscodeSettingsGate(env, ctx.home, process.cwd()));
9634
9799
  return row.id === "zcode" ? withHookGate(checks, zcodeConfigGate(ctx.home)) : checks;
@@ -9700,20 +9865,21 @@ function agentHomeDir(id, ctx) {
9700
9865
  if (id === "copilot-cli") return copilotDirOf(ctx.env, ctx.home);
9701
9866
  if (id === "kiro") return kiroDirOf(ctx.env, ctx.home);
9702
9867
  if (id === "opencode") return opencodeDirOf(ctx.env, ctx.home);
9868
+ if (id === "gemini") return geminiDirOf(ctx.env, ctx.home);
9703
9869
  return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
9704
9870
  }
9705
9871
  function detectAgents(reg, ctx) {
9706
- return reg.filter((r2) => existsSync15(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
9872
+ return reg.filter((r2) => existsSync16(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
9707
9873
  }
9708
9874
  async function runSetup(opts) {
9709
9875
  const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
9710
9876
  const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
9711
9877
  const reg = buildRegistry(ctx);
9712
9878
  for (const f2 of ["server.mjs", "hook.mjs"]) {
9713
- if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9879
+ if (!existsSync16(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9714
9880
  }
9715
9881
  const ids = opts.agents ?? detectAgents(reg, ctx);
9716
- const root = path12.join(ctx.home, STATE_DIR);
9882
+ const root = dataRootOf(ctx.env, ctx.home);
9717
9883
  if (!opts.dryRun) {
9718
9884
  const held = takeLock(root, runId);
9719
9885
  if (held) return { exitCode: 1, agents: [], error: held };
@@ -9766,7 +9932,7 @@ async function setupRow(row, ctx, run, dryRun) {
9766
9932
  return { ...res, status: "FAIL", reason: e.message };
9767
9933
  }
9768
9934
  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)));
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)));
9770
9936
  res.changes = [...plan.edits.flatMap((e) => e.changes), ...[...plan.cli, ...plan.refresh].map((args) => ({ command: [row.cli.bin, ...args] }))];
9771
9937
  if (dryRun) return res;
9772
9938
  try {
@@ -9804,10 +9970,10 @@ async function runDoctor(opts) {
9804
9970
  const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
9805
9971
  const reg = buildRegistry(ctx);
9806
9972
  for (const f2 of ["server.mjs", "hook.mjs"]) {
9807
- if (!existsSync15(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9973
+ if (!existsSync16(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9808
9974
  }
9809
9975
  const ids = opts.agents ?? detectAgents(reg, ctx);
9810
- const run = new Run(path12.join(ctx.home, STATE_DIR), "doctor");
9976
+ const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
9811
9977
  const agents = [];
9812
9978
  for (const id of ids) {
9813
9979
  const row = reg.find((r2) => r2.id === id);
@@ -9848,7 +10014,9 @@ function notSetUpReason(row, res, env) {
9848
10014
  const h2 = row.hookInstall;
9849
10015
  const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
9850
10016
  const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
9851
- return oc2 ? `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode` : NOT_SET_UP_REASON;
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;
9852
10020
  }
9853
10021
  function hasPluginIssue(row) {
9854
10022
  const h2 = row.hookInstall;
@@ -9870,14 +10038,14 @@ function isTrust(row, c3) {
9870
10038
  }
9871
10039
  function runRemove(opts) {
9872
10040
  const env = opts.env ?? process.env;
9873
- const root = path12.join(opts.home, STATE_DIR);
10041
+ const root = dataRootOf(env, opts.home);
9874
10042
  const base = path12.join(root, BACKUP_DIR);
9875
- if (!existsSync15(base)) return { exitCode: 0, restored: 0 };
10043
+ if (!existsSync16(base)) return { exitCode: 0, restored: 0 };
9876
10044
  const held = takeLock(root, "remove");
9877
10045
  if (held) return { exitCode: 1, restored: 0, error: held };
9878
10046
  let restored = 0;
9879
10047
  try {
9880
- const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync15(path12.join(d, MANIFEST))).sort().reverse();
10048
+ const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync16(path12.join(d, MANIFEST))).sort().reverse();
9881
10049
  for (const dir of runs) {
9882
10050
  const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
9883
10051
  undo(dir, m3.entries, env);
@@ -10090,7 +10258,7 @@ async function report(ui, command, res, write) {
10090
10258
  const { text: text2, title } = buildIssueReport(command, res, ui);
10091
10259
  let file = "";
10092
10260
  if (write) {
10093
- const dir = path13.join(ui.ctx.home, STATE_DIR, REPORT_DIR);
10261
+ const dir = path13.join(dataRootOf(ui.ctx.env, ui.ctx.home), REPORT_DIR);
10094
10262
  mkdirSync6(dir, { recursive: true });
10095
10263
  file = path13.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
10096
10264
  writeFileSync4(file, text2);
@@ -10201,7 +10369,7 @@ async function remove(ui) {
10201
10369
  }
10202
10370
  }
10203
10371
  if (ui.f.dryRun) {
10204
- out(`Would restore every file recorded under ${path13.join(ui.ctx.home, STATE_DIR, "backups")}`);
10372
+ out(`Would restore every file recorded under ${path13.join(dataRootOf(ui.ctx.env, ui.ctx.home), "backups")}`);
10205
10373
  return EXIT_OK;
10206
10374
  }
10207
10375
  const r2 = runRemove({ home: ui.ctx.home, env: ui.ctx.env });
@@ -10341,7 +10509,7 @@ async function upgrade(ui) {
10341
10509
  }
10342
10510
  const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
10343
10511
  const cli = path13.join(root, "context-mode", "cli.mjs");
10344
- if (!root || !existsSync16(cli)) {
10512
+ if (!root || !existsSync17(cli)) {
10345
10513
  err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
10346
10514
  return EXIT_FAIL;
10347
10515
  }
@@ -10380,12 +10548,12 @@ Run context-mode ${cmd} --help.`);
10380
10548
  }
10381
10549
 
10382
10550
  // src/entries/is-entry.ts
10383
- import { realpathSync as realpathSync8 } from "node:fs";
10551
+ import { realpathSync as realpathSync10 } from "node:fs";
10384
10552
  function isEntry(main2, argv1, self) {
10385
10553
  if (main2 !== void 0) return main2;
10386
10554
  if (argv1 === void 0 || argv1 === "") return false;
10387
10555
  try {
10388
- return realpathSync8(argv1) === realpathSync8(self);
10556
+ return realpathSync10(argv1) === realpathSync10(self);
10389
10557
  } catch {
10390
10558
  return false;
10391
10559
  }
@@ -10436,7 +10604,7 @@ function route(argv, version) {
10436
10604
  ` };
10437
10605
  }
10438
10606
  function main() {
10439
- const dir = path14.dirname(realpathSync9(fileURLToPath3(import.meta.url)));
10607
+ const dir = path14.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
10440
10608
  let version = "";
10441
10609
  try {
10442
10610
  version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);