context-mode 2.0.1 → 2.1.0

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.
@@ -426,7 +426,7 @@ var DECISION_OPTION_KEY = "option";
426
426
  var DECISION_LABEL_JOIN = " | ";
427
427
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
428
428
  var RELEASE_BRANCH = "release";
429
- var BUNDLE_SHA = true ? "22367bce5f9db0a23a18cddba4d6e98c5250da10" : void 0;
429
+ var BUNDLE_SHA = true ? "d232ce4ddfb581a63a4c0d6ef894b64a0f8464f6" : void 0;
430
430
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
431
431
  var DOCTOR_LABEL = Object.freeze({
432
432
  D1: "version",
@@ -685,6 +685,7 @@ var REGEX_SPECIAL_CHARS = ".*+?^${}()|[]\\";
685
685
  var REGEX_ESCAPE = "\\";
686
686
  var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
687
687
  var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
688
+ var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
688
689
  function D5_SLOW_DETAIL(ms) {
689
690
  return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
690
691
  }
@@ -714,8 +715,8 @@ var UPGRADE_DATA_DELETED = "user data deleted";
714
715
  var UPGRADE_HOST_COMMAND = Object.freeze({
715
716
  "claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
716
717
  codex: "rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",
717
- gemini: "gemini extensions install https://github.com/mksglu/context-mode --ref release --auto-update",
718
- qwen: "qwen extensions install https://github.com/mksglu/context-mode --ref release --auto-update"
718
+ gemini: "gemini extensions install https://github.com/mksglu/context-mode --auto-update",
719
+ qwen: "qwen extensions install https://github.com/mksglu/context-mode --auto-update"
719
720
  });
720
721
  var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
721
722
  var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
@@ -779,6 +780,9 @@ var HOOKS_KEY = "hooks";
779
780
  var STATUS_LINE_KEY = "statusLine";
780
781
  var PI_PACKAGES_KEY = "packages";
781
782
  var OPENCODE_PLUGIN_KEY = "plugin";
783
+ var OPENCODE_PLUGINS_KEY = "plugins";
784
+ var OPENCODE_PACKAGE_FIELD = "package";
785
+ var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
782
786
  var V1_DATA_DIR_NAME = "context-mode";
783
787
  var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
784
788
  var V1_SESSIONS_DIR_NAME = "sessions";
@@ -877,6 +881,7 @@ var DOCTOR_REPORT_FILE_PREFIX = "doctor-";
877
881
  var DOCTOR_REPORT_LINE = "Report file: ";
878
882
  var DOCTOR_GH_LINE = "File it: ";
879
883
  var DOCTOR_URL_LINE = "Or open: ";
884
+ var DOCTOR_RULES_LINE = "Rules: ";
880
885
  var DOCTOR_GH_NEXT = " --";
881
886
  var DOCTOR_NOTE_PREFIXES = Object.freeze([
882
887
  DOCTOR_ENV_PREFIX,
@@ -884,10 +889,23 @@ var DOCTOR_NOTE_PREFIXES = Object.freeze([
884
889
  DOCTOR_REPORT_LINE,
885
890
  DOCTOR_GH_LINE,
886
891
  DOCTOR_GH_NEXT.trim(),
887
- DOCTOR_URL_LINE
892
+ DOCTOR_URL_LINE,
893
+ DOCTOR_RULES_LINE
888
894
  ]);
889
895
  var ISSUE_REPO_SLUG = "mksglu/context-mode";
890
896
  var ISSUE_FORM_FILE = "agent-report.yml";
897
+ var ISSUE_GUIDE_URL = `https://github.com/${ISSUE_REPO_SLUG}/blob/main/.github/AGENT_ISSUE.md`;
898
+ var ISSUE_AGENT_RULES = Object.freeze([
899
+ 'Search for the same problem first: `gh issue list -R mksglu/context-mode --state all --search "<check id or error>"`. When one matches, add your facts there as a comment.',
900
+ "File one bug per issue.",
901
+ "Call the `ctx_doctor` tool and paste its full output unchanged in the `ctx-report` field.",
902
+ "Give the versions: context-mode, the agent, the OS and arch, and Node.",
903
+ "Write numbered repro steps that start from a fresh project (`mktemp -d`) and the agent's own install command.",
904
+ "Give the exact command and its exact output in a fenced code block.",
905
+ "Say what you expected and what happened instead.",
906
+ "Name the source file and line when you found the cause.",
907
+ "Replace every secret with `<masked>` and the home folder with `~` before you send."
908
+ ]);
891
909
  var ISSUE_URL_MAX = 8e3;
892
910
  var ISSUE_FORM_HEADINGS = Object.freeze([
893
911
  "Summary",
@@ -918,16 +936,16 @@ var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
918
936
  var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
919
937
  var DOCTOR_MASK = "<masked>";
920
938
  var NATIVE_INSTALL = Object.freeze({
921
- "claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
922
- codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
923
- gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
924
- qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
925
- opencode: ["opencode plugin add context-mode@next"],
926
- pi: ["pi install npm:context-mode@next"],
927
- "copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
928
- vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
929
- kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
930
- zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
939
+ "claude-code": ["claude plugin marketplace add mksglu/context-mode", "claude plugin install context-mode@context-mode"],
940
+ codex: ["codex plugin marketplace add mksglu/context-mode", "codex plugin add context-mode@context-mode"],
941
+ gemini: ["gemini extensions install https://github.com/mksglu/context-mode"],
942
+ qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
943
+ opencode: ["opencode plugin add context-mode"],
944
+ pi: ["pi install npm:context-mode"],
945
+ "copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
946
+ vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
947
+ kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
948
+ zcode: ["npm i -g context-mode", "context-mode setup --agents zcode"]
931
949
  });
932
950
  var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
933
951
  var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
@@ -1039,9 +1057,28 @@ function outputOf(resp) {
1039
1057
  return err === "" ? out : out === "" ? err : out + "\n" + err;
1040
1058
  }
1041
1059
  }
1042
- if (typeof resp === "object" && resp !== null && isGrepContent(resp)) return resp.content;
1060
+ if (typeof resp === "object" && resp !== null && !Array.isArray(resp)) {
1061
+ const slot = textSlot(resp);
1062
+ if (slot !== null) return slot.text;
1063
+ }
1043
1064
  return JSON.stringify(resp);
1044
1065
  }
1066
+ function textSlot(r) {
1067
+ const file2 = r.file;
1068
+ if (r.type === "text" && typeof file2 === "object" && file2 !== null && typeof file2.content === "string") {
1069
+ return { text: file2.content, put: (o, output) => ({ ...o, file: { ...o.file, content: output } }) };
1070
+ }
1071
+ if (isGrepContent(r)) return { text: r.content, put: (o, output) => ({ ...o, content: output }) };
1072
+ if (Array.isArray(r.filenames) && r.filenames.every((f) => typeof f === "string")) {
1073
+ return { text: r.filenames.join("\n"), put: (o, output) => ({ ...o, filenames: output.split("\n") }) };
1074
+ }
1075
+ if (typeof r.result === "string") return { text: r.result, put: (o, output) => ({ ...o, result: output }) };
1076
+ return null;
1077
+ }
1078
+ function isShellShape(resp) {
1079
+ const r = resp;
1080
+ return typeof r.stdout === "string" || typeof r.stderr === "string";
1081
+ }
1045
1082
  function isGrepContent(resp) {
1046
1083
  const r = resp;
1047
1084
  return r.mode === "content" && typeof r.content === "string";
@@ -1060,7 +1097,10 @@ function readResult(resp) {
1060
1097
  const text = outputOf(resp);
1061
1098
  const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
1062
1099
  const info = { isError, bytes: Buffer.byteLength(text), text };
1063
- if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isGrepContent(resp)) info.shape = resp;
1100
+ if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
1101
+ if (textSlot(resp) !== null) info.shape = resp;
1102
+ else info.keep = true;
1103
+ }
1064
1104
  if (Array.isArray(resp)) {
1065
1105
  info.blocks = true;
1066
1106
  if (blocksOf(resp).keep) info.keep = true;
@@ -1097,7 +1137,9 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
1097
1137
  }
1098
1138
  function replaceShape(ev, output) {
1099
1139
  if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
1100
- if (ev.result?.shape !== void 0) return { ...ev.result.shape, content: output };
1140
+ const shape = ev.result?.shape;
1141
+ const slot = shape === void 0 ? null : textSlot(shape);
1142
+ if (shape !== void 0 && slot !== null) return slot.put(shape, output);
1101
1143
  if (ev.result?.blocks === true) return [{ type: "text", text: output }];
1102
1144
  return output;
1103
1145
  }
@@ -1490,7 +1532,8 @@ function encode6(ev, d, _extra) {
1490
1532
  }
1491
1533
 
1492
1534
  // src/adapters/kiro.ts
1493
- var TOOL_NAME_PREFIX7 = "mcp_context-mode_";
1535
+ var TOOL_NAME_PREFIX7 = "mcp_context_mode_";
1536
+ var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
1494
1537
  var KIRO_EVENTS = {
1495
1538
  SessionStart: "SessionStart",
1496
1539
  agentSpawn: "SessionStart",
@@ -1502,6 +1545,7 @@ var KIRO_EVENTS = {
1502
1545
  PostToolUse: "PostToolUse",
1503
1546
  postToolUse: "PostToolUse"
1504
1547
  };
1548
+ var PROMPT_FIELD = "prompt";
1505
1549
  var PROMPT_ENV = "USER_PROMPT";
1506
1550
  var MCP_PREFIX3 = "mcp_";
1507
1551
  var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
@@ -1510,6 +1554,7 @@ var MCP_SEP3 = "_";
1510
1554
  var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1511
1555
  function canonicalName5(name) {
1512
1556
  if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
1557
+ if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
1513
1558
  if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
1514
1559
  if (!name.startsWith(MCP_PREFIX3)) return name;
1515
1560
  const rest = name.slice(MCP_PREFIX3.length);
@@ -1530,7 +1575,8 @@ function decode7(raw) {
1530
1575
  const ev = { event, agent: "kiro", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
1531
1576
  if (event === "SessionStart" && typeof p.source === "string" && KIRO_SOURCES[p.source] !== void 0) ev.source = KIRO_SOURCES[p.source];
1532
1577
  if (event === "UserPromptSubmit") {
1533
- const prompt = process.env[PROMPT_ENV];
1578
+ const field = p[PROMPT_FIELD];
1579
+ const prompt = typeof field === "string" ? field : process.env[PROMPT_ENV];
1534
1580
  if (prompt !== void 0) ev.prompt = prompt;
1535
1581
  }
1536
1582
  if (event === "PreToolUse" || event === "PostToolUse") {
@@ -1542,7 +1588,7 @@ function decode7(raw) {
1542
1588
  return ev;
1543
1589
  }
1544
1590
  function encode7(ev, d, _extra) {
1545
- if (ev.event === "UserPromptSubmit") return { stdout: "", exitCode: 0 };
1591
+ if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
1546
1592
  switch (d.kind) {
1547
1593
  case "allow":
1548
1594
  return { stdout: "", exitCode: 0 };
@@ -1901,7 +1947,7 @@ var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "
1901
1947
  function dumpRunsThenReplaces(row5) {
1902
1948
  return DUMP_REPLACE_ROWS.has(row5.id) && hasReplace(row5);
1903
1949
  }
1904
- var RECALL_ROWS = /* @__PURE__ */ new Set(["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "zcode"]);
1950
+ var RECALL_ROWS = /* @__PURE__ */ new Set(["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "zcode", "kiro"]);
1905
1951
  function hasRecall(row5) {
1906
1952
  return RECALL_ROWS.has(row5.id);
1907
1953
  }
@@ -3252,14 +3298,29 @@ function copilotDirOf(env, home) {
3252
3298
  function kiroDirOf(env, home, platform = process.platform) {
3253
3299
  const p = platform === "win32" ? win32 : posix;
3254
3300
  const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
3255
- const dir = env[KIRO_HOME_ENV];
3301
+ const dir = env[KIRO_HOME_ENV]?.trim();
3256
3302
  if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
3257
3303
  if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
3258
3304
  const abs = p.resolve(dir);
3259
- if (p.dirname(abs) === abs) return fallback;
3260
- const up = p.relative(abs, p.resolve(home));
3305
+ const real2 = platform === process.platform ? realOrSelf : (x) => x;
3306
+ const target = real2(abs);
3307
+ if (p.parse(target).root === target) return fallback;
3308
+ const up = p.relative(target, real2(p.resolve(home)));
3261
3309
  if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
3262
- return dir;
3310
+ return abs;
3311
+ }
3312
+ function realOrSelf(path7) {
3313
+ const tail = [];
3314
+ for (let at2 = path7; ; ) {
3315
+ try {
3316
+ return join(realpathSync.native(at2), ...tail.reverse());
3317
+ } catch {
3318
+ const up = dirname(at2);
3319
+ if (up === at2) return path7;
3320
+ tail.push(basename(at2));
3321
+ at2 = up;
3322
+ }
3323
+ }
3263
3324
  }
3264
3325
  function claudeDirOf(env, home) {
3265
3326
  const dir = env[CLAUDE_CONFIG_DIR_ENV];
@@ -7829,7 +7890,7 @@ function cutPoint(src, start, end, scratch) {
7829
7890
  const r = encoder.encodeInto(src.slice(start, limit), scratch);
7830
7891
  return { end: start + r.read, written: r.written };
7831
7892
  }
7832
- function merge(src, blocks, join26, cap, lineCut) {
7893
+ function merge(src, blocks, join27, cap, lineCut) {
7833
7894
  const out = [];
7834
7895
  const scratch = new Uint8Array(cap);
7835
7896
  let wide;
@@ -7839,7 +7900,7 @@ function merge(src, blocks, join26, cap, lineCut) {
7839
7900
  out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
7840
7901
  };
7841
7902
  for (const b of blocks) {
7842
- if (cur !== void 0 && !join26) {
7903
+ if (cur !== void 0 && !join27) {
7843
7904
  emit(cur.start, cur.end, curBytes);
7844
7905
  cur = void 0;
7845
7906
  }
@@ -20833,21 +20894,43 @@ var ctxBatch = Object.freeze({
20833
20894
  });
20834
20895
 
20835
20896
  // src/core/tools/doctor.ts
20836
- import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as existsSync13 } from "node:fs";
20837
- import { basename as basename5, dirname as dirname8, join as join16 } from "node:path";
20897
+ import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as existsSync14 } from "node:fs";
20898
+ import { basename as basename5, join as join17 } from "node:path";
20899
+
20900
+ // src/core/ops/bundle-dir.ts
20901
+ import { existsSync as existsSync3 } from "node:fs";
20902
+ import { dirname as dirname5, join as join8 } from "node:path";
20903
+ import { fileURLToPath } from "node:url";
20904
+ function bundleDirOf(argv1, moduleFile) {
20905
+ const own2 = dirname5(argv1);
20906
+ if (existsSync3(join8(own2, SERVER_ENTRY_FILE))) return own2;
20907
+ let dir = dirname5(moduleFile);
20908
+ for (; ; ) {
20909
+ if (existsSync3(join8(dir, SERVER_ENTRY_FILE))) return dir;
20910
+ const up = dirname5(dir);
20911
+ if (up === dir) return own2;
20912
+ dir = up;
20913
+ }
20914
+ }
20915
+ var memo;
20916
+ function ownBundleDir() {
20917
+ const argv1 = process.argv[1] ?? "";
20918
+ if (memo?.argv1 !== argv1) memo = { argv1, dir: bundleDirOf(argv1, fileURLToPath(import.meta.url)) };
20919
+ return memo.dir;
20920
+ }
20838
20921
 
20839
20922
  // src/core/ops/doctor-config.ts
20840
- import { existsSync as existsSync6, readdirSync as readdirSync4 } from "node:fs";
20841
- import { join as join11 } from "node:path";
20923
+ import { existsSync as existsSync7, readdirSync as readdirSync4 } from "node:fs";
20924
+ import { join as join12 } from "node:path";
20842
20925
 
20843
20926
  // src/core/ops/detect-v1.ts
20844
- import { existsSync as existsSync4, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
20927
+ import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
20845
20928
  import { tmpdir } from "node:os";
20846
- import { join as join9 } from "node:path";
20929
+ import { join as join10 } from "node:path";
20847
20930
 
20848
20931
  // src/core/ops/host-config.ts
20849
- import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
20850
- import { dirname as dirname5, join as join8 } from "node:path";
20932
+ import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
20933
+ import { dirname as dirname6, join as join9 } from "node:path";
20851
20934
 
20852
20935
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
20853
20936
  var KEYS2 = {
@@ -22964,10 +23047,10 @@ function formatOf(path7) {
22964
23047
  function readHostConfig(agent, path7) {
22965
23048
  let file2 = path7;
22966
23049
  if (agent === "opencode") {
22967
- const jsonc = join8(dirname5(path7), OPENCODE_CONFIG_FILES[0]);
22968
- if (existsSync3(jsonc)) file2 = jsonc;
23050
+ const jsonc = join9(dirname6(path7), OPENCODE_CONFIG_FILES[0]);
23051
+ if (existsSync4(jsonc)) file2 = jsonc;
22969
23052
  }
22970
- const raw = existsSync3(file2) ? readFileSync6(file2, "utf8") : "";
23053
+ const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
22971
23054
  return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
22972
23055
  }
22973
23056
  function stripJsonComments(text) {
@@ -23312,7 +23395,7 @@ function setText(agent, path7, text, format, key, value) {
23312
23395
  }
23313
23396
  }
23314
23397
  function serverScript() {
23315
- return join8(dirname5(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
23398
+ return join9(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
23316
23399
  }
23317
23400
  function isNodeCommand(command) {
23318
23401
  if (typeof command !== "string") return false;
@@ -23328,7 +23411,7 @@ function ownMcpValue(agent, node, server2) {
23328
23411
  return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server2, AGENT_ARG, agent, ...tail] };
23329
23412
  }
23330
23413
  function opencodePluginFile() {
23331
- return dirname5(process.argv[1] ?? "");
23414
+ return ownBundleDir();
23332
23415
  }
23333
23416
  function listTarget(key, own2, v1, alt = []) {
23334
23417
  return {
@@ -23487,7 +23570,7 @@ function flatCommands(events, prefix) {
23487
23570
  var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
23488
23571
  var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep4) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep4) + sep4));
23489
23572
  function dataDir(dir, reason, out) {
23490
- if (existsSync4(dir)) out.push(finding(dir, "", reason));
23573
+ if (existsSync5(dir)) out.push(finding(dir, "", reason));
23491
23574
  }
23492
23575
  function mcpEntry(file2, doc, out) {
23493
23576
  if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
@@ -23495,7 +23578,7 @@ function mcpEntry(file2, doc, out) {
23495
23578
  }
23496
23579
  }
23497
23580
  function claudeShapeSettings(agentHome, out) {
23498
- const file2 = join9(agentHome, SETTINGS_FILE);
23581
+ const file2 = join10(agentHome, SETTINGS_FILE);
23499
23582
  const doc = readJson(file2);
23500
23583
  for (const c of nestedCommands(doc)) {
23501
23584
  if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
@@ -23515,49 +23598,49 @@ function v1HookFile(file2, out) {
23515
23598
  function scanClaudeCode(home, agentHome, out) {
23516
23599
  claudeShapeSettings(agentHome, out);
23517
23600
  for (const ext of V1_CACHE_HEAL_EXTS) {
23518
- const file2 = join9(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
23519
- if (existsSync4(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
23601
+ const file2 = join10(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
23602
+ if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
23520
23603
  }
23521
- const userFile = join9(home, CLAUDE_USER_CONFIG_FILE);
23604
+ const userFile = join10(home, CLAUDE_USER_CONFIG_FILE);
23522
23605
  mcpEntry(userFile, readJson(userFile), out);
23523
- dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23606
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23524
23607
  }
23525
23608
  function scanCodex(agentHome, out) {
23526
- const hooksFile = join9(agentHome, HOOKS_JSON_FILE);
23609
+ const hooksFile = join10(agentHome, HOOKS_JSON_FILE);
23527
23610
  for (const c of nestedCommands(readJson(hooksFile))) {
23528
23611
  if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
23529
23612
  out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
23530
23613
  }
23531
23614
  }
23532
- const tomlFile = join9(agentHome, CONFIG_TOML_FILE);
23615
+ const tomlFile = join10(agentHome, CONFIG_TOML_FILE);
23533
23616
  const config2 = readTomlValue(tomlFile);
23534
23617
  for (const span2 of readTomlTables(tomlFile)) {
23535
23618
  if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
23536
23619
  if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
23537
23620
  out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
23538
23621
  }
23539
- dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23622
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23540
23623
  }
23541
23624
  function scanGemini(agentHome, out) {
23542
- const file2 = join9(agentHome, SETTINGS_FILE);
23625
+ const file2 = join10(agentHome, SETTINGS_FILE);
23543
23626
  for (const c of nestedCommands(readJson(file2))) {
23544
23627
  if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
23545
23628
  }
23546
- dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
23629
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
23547
23630
  }
23548
23631
  function scanVscode(agentHome, project, out) {
23549
23632
  if (project !== void 0) {
23550
- v1HookFile(join9(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
23551
- const mcpFile2 = join9(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
23633
+ v1HookFile(join10(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
23634
+ const mcpFile2 = join10(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
23552
23635
  const doc = readJson(mcpFile2);
23553
23636
  const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
23554
23637
  const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
23555
23638
  if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
23556
23639
  out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
23557
23640
  }
23558
- dataDir(join9(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
23641
+ dataDir(join10(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
23559
23642
  }
23560
- dataDir(join9(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
23643
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
23561
23644
  }
23562
23645
  function jsonFiles(dir) {
23563
23646
  try {
@@ -23567,10 +23650,10 @@ function jsonFiles(dir) {
23567
23650
  }
23568
23651
  }
23569
23652
  function scanKiro(agentHome, project, out) {
23570
- const agentsDir = join9(agentHome, KIRO_AGENTS_DIR);
23571
- const defaultFile = join9(agentHome, ...KIRO_AGENT_FILE);
23653
+ const agentsDir = join10(agentHome, KIRO_AGENTS_DIR);
23654
+ const defaultFile = join10(agentHome, ...KIRO_AGENT_FILE);
23572
23655
  for (const name of jsonFiles(agentsDir)) {
23573
- const file2 = join9(agentsDir, name);
23656
+ const file2 = join10(agentsDir, name);
23574
23657
  const doc = readJson(file2);
23575
23658
  if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
23576
23659
  out.push(finding(file2, "", V1_REASON.kiroAgentFile));
@@ -23581,25 +23664,25 @@ function scanKiro(agentHome, project, out) {
23581
23664
  if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
23582
23665
  }
23583
23666
  }
23584
- const steeringDocs = [join9(agentHome, ...KIRO_STEERING_FILE)];
23585
- if (project !== void 0) steeringDocs.push(join9(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
23667
+ const steeringDocs = [join10(agentHome, ...KIRO_STEERING_FILE)];
23668
+ if (project !== void 0) steeringDocs.push(join10(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
23586
23669
  for (const file2 of steeringDocs) {
23587
- if (existsSync4(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
23670
+ if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
23588
23671
  }
23589
- dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23672
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23590
23673
  }
23591
23674
  function scanPi(piAgentDir, agentHome, out) {
23592
- const file2 = join9(piAgentDir, SETTINGS_FILE);
23675
+ const file2 = join10(piAgentDir, SETTINGS_FILE);
23593
23676
  const doc = readJson(file2);
23594
23677
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
23595
23678
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
23596
23679
  if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
23597
23680
  });
23598
- dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23681
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23599
23682
  }
23600
23683
  function scanOpencode(agentHome, out) {
23601
23684
  for (const name of OPENCODE_CONFIG_FILES) {
23602
- const file2 = join9(agentHome, name);
23685
+ const file2 = join10(agentHome, name);
23603
23686
  const doc = readJson(file2);
23604
23687
  if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
23605
23688
  doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
@@ -23609,13 +23692,13 @@ function scanOpencode(agentHome, out) {
23609
23692
  }
23610
23693
  }
23611
23694
  function scanZcode(agentHome, out) {
23612
- const configFile = join9(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
23695
+ const configFile = join10(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
23613
23696
  const config2 = readJson(configFile);
23614
23697
  const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
23615
23698
  for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
23616
23699
  if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
23617
23700
  }
23618
- const hooksFile = join9(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
23701
+ const hooksFile = join10(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
23619
23702
  for (const c of nestedCommands(readJson(hooksFile))) {
23620
23703
  if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
23621
23704
  }
@@ -23639,14 +23722,14 @@ function firstTmpMatch(dir) {
23639
23722
  }
23640
23723
  }
23641
23724
  function scanAll(home, tmp, out) {
23642
- const root = join9(home, DATA_ROOT.slice(1));
23643
- for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join9(root, name), V1_REASON.dataRoot, out);
23725
+ const root = join10(home, DATA_ROOT.slice(1));
23726
+ for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join10(root, name), V1_REASON.dataRoot, out);
23644
23727
  if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
23645
23728
  }
23646
23729
  function detectV1(agent, home, scope = {}) {
23647
23730
  const out = [];
23648
23731
  const project = scope.project;
23649
- 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 : join9(home, ...AGENT_HOME_DIR[agent]);
23732
+ 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 : join10(home, ...AGENT_HOME_DIR[agent]);
23650
23733
  switch (agent) {
23651
23734
  case "claude-code":
23652
23735
  scanClaudeCode(home, agentHome, out);
@@ -23659,11 +23742,11 @@ function detectV1(agent, home, scope = {}) {
23659
23742
  break;
23660
23743
  case "qwen":
23661
23744
  claudeShapeSettings(agentHome, out);
23662
- dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23745
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23663
23746
  break;
23664
23747
  case "copilot-cli":
23665
- v1HookFile(join9(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
23666
- dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23748
+ v1HookFile(join10(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
23749
+ dataDir(join10(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23667
23750
  break;
23668
23751
  case "vscode":
23669
23752
  scanVscode(agentHome, project, out);
@@ -23672,7 +23755,7 @@ function detectV1(agent, home, scope = {}) {
23672
23755
  scanKiro(agentHome, project, out);
23673
23756
  break;
23674
23757
  case "pi":
23675
- scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join9(agentHome, PI_AGENT_DIR), agentHome, out);
23758
+ scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join10(agentHome, PI_AGENT_DIR), agentHome, out);
23676
23759
  break;
23677
23760
  // D-WIN-PIDIR-1: empty is unset
23678
23761
  case "opencode":
@@ -23687,9 +23770,9 @@ function detectV1(agent, home, scope = {}) {
23687
23770
  }
23688
23771
 
23689
23772
  // src/core/ops/plugin-root.ts
23690
- import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23691
- import { dirname as dirname6, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
23692
- import { fileURLToPath } from "node:url";
23773
+ import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23774
+ import { dirname as dirname7, isAbsolute as isAbsolute2, join as join11, sep as sep3 } from "node:path";
23775
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
23693
23776
  function missing(agent, path7) {
23694
23777
  return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
23695
23778
  }
@@ -23736,8 +23819,8 @@ var readOrNull = (file2) => {
23736
23819
  };
23737
23820
  var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
23738
23821
  function enabledPlugins(claudeDir, project) {
23739
- const files = [join10(claudeDir, SETTINGS_FILE)];
23740
- if (project !== void 0) files.push(join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
23822
+ const files = [join11(claudeDir, SETTINGS_FILE)];
23823
+ if (project !== void 0) files.push(join11(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join11(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
23741
23824
  const out = {};
23742
23825
  for (const file2 of files) {
23743
23826
  const text = readOrNull(file2);
@@ -23750,13 +23833,13 @@ function enabledPlugins(claudeDir, project) {
23750
23833
  function marketplaceChoice(env, worktree) {
23751
23834
  const claudeDir = claudeDirOf(env, requireHomeDir(env));
23752
23835
  const script = process.argv[1];
23753
- const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
23836
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
23754
23837
  const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
23755
23838
  if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
23756
- const record4 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
23839
+ const record4 = readOrNull(join11(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
23757
23840
  const recorded = record4 === null ? [] : recordedInstalls(record4);
23758
23841
  if (recorded.length === 0) return { record: false };
23759
- const live = recorded.filter((r) => existsSync5(r.installPath));
23842
+ const live = recorded.filter((r) => existsSync6(r.installPath));
23760
23843
  const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
23761
23844
  if (mine !== void 0) return { root: mine.installPath };
23762
23845
  const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
@@ -23776,18 +23859,18 @@ function marketplaceChoice(env, worktree) {
23776
23859
  }
23777
23860
  function marketplaceRoot(adapter, env, worktree) {
23778
23861
  const claudeDir = claudeDirOf(env, requireHomeDir(env));
23779
- const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
23780
- const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
23862
+ const plugins = join11(claudeDir, HOST_PLUGINS_DIR_NAME);
23863
+ const cache = join11(plugins, PLUGIN_CACHE_DIR_NAME);
23781
23864
  const script = process.argv[1];
23782
- const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
23865
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
23783
23866
  const choice = marketplaceChoice(env, worktree);
23784
23867
  if ("root" in choice) return choice.root;
23785
23868
  if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
23786
23869
  const cacheReal = realOrNull(cache);
23787
- if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync5(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
23788
- const pattern = join10(cache, "*", PLUGIN_NAME);
23789
- if (!existsSync5(cache)) throw missing(adapter.id, pattern);
23790
- const found = readdirSync3(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync5(dir));
23870
+ if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync6(join11(ownReal, SERVER_ENTRY_FILE))) return ownReal;
23871
+ const pattern = join11(cache, "*", PLUGIN_NAME);
23872
+ if (!existsSync6(cache)) throw missing(adapter.id, pattern);
23873
+ const found = readdirSync3(cache).sort().map((marketplace) => join11(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
23791
23874
  if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
23792
23875
  return found[0];
23793
23876
  }
@@ -23795,13 +23878,13 @@ function configEntryRoot(adapter, env) {
23795
23878
  const spec = OWN_MCP_ENTRY[adapter.id];
23796
23879
  if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
23797
23880
  const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
23798
- if (!existsSync5(file2)) throw missing(adapter.id, file2);
23881
+ if (!existsSync6(file2)) throw missing(adapter.id, file2);
23799
23882
  const current = readHostConfig(adapter.id, file2);
23800
23883
  const value = parseHostConfig(adapter.id, file2, current.text, current.format);
23801
23884
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
23802
23885
  const script = Array.isArray(args) ? args[0] : void 0;
23803
23886
  if (typeof script !== "string" || !isAbsolute2(script)) throw missing(adapter.id, file2);
23804
- return dirname6(script);
23887
+ return dirname7(script);
23805
23888
  }
23806
23889
  function candidate(adapter, env, worktree) {
23807
23890
  switch (adapter.installMode) {
@@ -23812,11 +23895,11 @@ function candidate(adapter, env, worktree) {
23812
23895
  case "hooks+mcp":
23813
23896
  return configEntryRoot(adapter, env);
23814
23897
  case "extension":
23815
- return join10(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id], EXTENSIONS_DIR_NAME, PLUGIN_NAME);
23898
+ return join11(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id], EXTENSIONS_DIR_NAME, PLUGIN_NAME);
23816
23899
  case "plugin":
23817
- return join10(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
23900
+ return join11(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
23818
23901
  case "in-process":
23819
- return dirname6(fileURLToPath(import.meta.url));
23902
+ return dirname7(fileURLToPath2(import.meta.url));
23820
23903
  }
23821
23904
  }
23822
23905
  function resolvePluginRoot(adapter, env, worktree) {
@@ -23905,11 +23988,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
23905
23988
  var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
23906
23989
  function mcpFile(row5, home, env) {
23907
23990
  const spec = OWN_MCP_ENTRY[row5.id];
23908
- if (row5.id === "codex") return join11(codexDirOf(env, home), CONFIG_TOML_FILE);
23991
+ if (row5.id === "codex") return join12(codexDirOf(env, home), CONFIG_TOML_FILE);
23909
23992
  if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
23910
- if (row5.id === "opencode") return join11(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
23993
+ if (row5.id === "opencode") return join12(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
23911
23994
  if (row5.id === "pi") {
23912
- return join11(piAgentDirOf(env, home), SETTINGS_FILE);
23995
+ return join12(piAgentDirOf(env, home), SETTINGS_FILE);
23913
23996
  }
23914
23997
  return null;
23915
23998
  }
@@ -23922,27 +24005,27 @@ function codexNativeDir(env, home) {
23922
24005
  const codexDir = codexDirOf(env, home);
23923
24006
  let enabled;
23924
24007
  try {
23925
- enabled = hostConfigValueAt(readParsed("codex", join11(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
24008
+ enabled = hostConfigValueAt(readParsed("codex", join12(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
23926
24009
  } catch {
23927
24010
  return null;
23928
24011
  }
23929
24012
  if (enabled !== true) return null;
23930
- const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
23931
- if (!existsSync6(cache)) return null;
24013
+ const cache = join12(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
24014
+ if (!existsSync7(cache)) return null;
23932
24015
  const found = [];
23933
24016
  for (const market of readdirSync4(cache)) {
23934
- const plugin = join11(cache, market, SERVER_KEY);
23935
- if (!existsSync6(plugin)) continue;
24017
+ const plugin = join12(cache, market, SERVER_KEY);
24018
+ if (!existsSync7(plugin)) continue;
23936
24019
  for (const version2 of readdirSync4(plugin).sort()) {
23937
- const dir = join11(plugin, version2, CODEX_PLUGIN_SUBDIR);
23938
- if (existsSync6(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24020
+ const dir = join12(plugin, version2, CODEX_PLUGIN_SUBDIR);
24021
+ if (existsSync7(join12(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
23939
24022
  }
23940
24023
  }
23941
24024
  return found.length === 0 ? null : found[found.length - 1];
23942
24025
  }
23943
24026
  function nativeMcpWrong(dir, row5) {
23944
24027
  try {
23945
- const entry = hostConfigValueAt(readParsed(row5.id, join11(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
24028
+ const entry = hostConfigValueAt(readParsed(row5.id, join12(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
23946
24029
  if (!isObject4(entry)) return true;
23947
24030
  const args = list2(entry[MCP_ARGS_FIELD]);
23948
24031
  const script = args[0];
@@ -23951,6 +24034,17 @@ function nativeMcpWrong(dir, row5) {
23951
24034
  return true;
23952
24035
  }
23953
24036
  }
24037
+ function isOwnOpencodeEntry(entry, key, own2) {
24038
+ const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : entry;
24039
+ if (typeof spec !== "string") return false;
24040
+ if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own2.includes(spec)) return true;
24041
+ return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
24042
+ }
24043
+ function opencodeListed(file2) {
24044
+ const { value } = readParsed("opencode", file2);
24045
+ const own2 = [opencodePluginFile()];
24046
+ return [OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)));
24047
+ }
23954
24048
  function mcpWrong(row5, home, env, worktree) {
23955
24049
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
23956
24050
  if (native !== null) return nativeMcpWrong(native, row5);
@@ -23960,6 +24054,7 @@ function mcpWrong(row5, home, env, worktree) {
23960
24054
  resolvePluginRoot(row5, env, worktree);
23961
24055
  return false;
23962
24056
  }
24057
+ if (row5.id === "opencode") return !opencodeListed(file2);
23963
24058
  const cur = readHostConfig(row5.id, file2);
23964
24059
  return mergeOwnEntries(row5.id, cur.text, cur.format, row5, { nodePath: true, listEntries: [opencodePluginFile()] }).edits.length > 0;
23965
24060
  } catch {
@@ -23969,7 +24064,7 @@ function mcpWrong(row5, home, env, worktree) {
23969
24064
  function hookFile(row5, spec, home, env, worktree) {
23970
24065
  const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
23971
24066
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
23972
- const file2 = native !== null ? join11(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join11(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join11(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join11(kiroDirOf(env, home), ...spec.file.slice(1)) : join11(root, ...spec.file);
24067
+ const file2 = native !== null ? join12(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join12(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join12(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join12(kiroDirOf(env, home), ...spec.file.slice(1)) : join12(root, ...spec.file);
23973
24068
  return file2;
23974
24069
  }
23975
24070
  function hookParts(row5, home, env, worktree) {
@@ -23980,7 +24075,7 @@ function hookParts(row5, home, env, worktree) {
23980
24075
  const file2 = hookFile(row5, spec, home, env, worktree);
23981
24076
  block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
23982
24077
  if (row5.id === "codex") {
23983
- const config2 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
24078
+ const config2 = readParsed(row5.id, join12(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
23984
24079
  if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
23985
24080
  }
23986
24081
  } catch {
@@ -24026,7 +24121,7 @@ function checkV1Leftovers(agent, home, scope = {}) {
24026
24121
  if (findings.length === 0) return pass("D4");
24027
24122
  const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
24028
24123
  if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass("D4"), detail };
24029
- return fail2("D4", detail, DOCTOR_FIX_UPGRADE);
24124
+ return { ...fail2("D4", detail, DOCTOR_FIX_UPGRADE), status: "WARN" };
24030
24125
  }
24031
24126
  function parsedOrNull(agent, file2, jsonc) {
24032
24127
  try {
@@ -24038,10 +24133,10 @@ function parsedOrNull(agent, file2, jsonc) {
24038
24133
  }
24039
24134
  function checkDoubleFire(agent, worktree) {
24040
24135
  if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
24041
- const claude = parsedOrNull(agent, join11(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
24136
+ const claude = parsedOrNull(agent, join12(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
24042
24137
  const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
24043
24138
  const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
24044
- const vscode = parsedOrNull(agent, join11(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
24139
+ const vscode = parsedOrNull(agent, join12(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
24045
24140
  const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
24046
24141
  return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
24047
24142
  }
@@ -24052,7 +24147,7 @@ function configPaths(row5, env, worktree) {
24052
24147
  const mcp = mcpFile(row5, home, env);
24053
24148
  if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
24054
24149
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
24055
- if (native !== null) out.push({ label: "Codex plugin MCP", path: join11(native, CODEX_PLUGIN_MCP_FILE) });
24150
+ if (native !== null) out.push({ label: "Codex plugin MCP", path: join12(native, CODEX_PLUGIN_MCP_FILE) });
24056
24151
  const spec = HOOK_HOST_FILE[row5.id];
24057
24152
  if (spec !== null) {
24058
24153
  try {
@@ -24072,7 +24167,7 @@ function configPaths(row5, env, worktree) {
24072
24167
  }
24073
24168
 
24074
24169
  // src/core/ops/doctor-db.ts
24075
- import { existsSync as existsSync7, statSync as statSync5 } from "node:fs";
24170
+ import { existsSync as existsSync8, statSync as statSync5 } from "node:fs";
24076
24171
  var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
24077
24172
  var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
24078
24173
  var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -24114,15 +24209,15 @@ function orphanFiles(dbPath) {
24114
24209
  const files = [];
24115
24210
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
24116
24211
  const path7 = dbPath + suffix;
24117
- if (existsSync7(path7)) files.push({ path: path7, bytes: statSync5(path7).size });
24212
+ if (existsSync8(path7)) files.push({ path: path7, bytes: statSync5(path7).size });
24118
24213
  }
24119
- return files.length > 0 && !existsSync7(dbPath) ? files : [];
24214
+ return files.length > 0 && !existsSync8(dbPath) ? files : [];
24120
24215
  }
24121
24216
  async function checkDb(project) {
24122
24217
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
24123
24218
  const orphan = orphanFiles(project.dbPath);
24124
24219
  if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
24125
- if (!existsSync7(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24220
+ if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24126
24221
  const sqlite = await loadSqlite2();
24127
24222
  if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
24128
24223
  let raw = null;
@@ -24148,7 +24243,7 @@ async function checkDb(project) {
24148
24243
  }
24149
24244
  }
24150
24245
  async function checkIndex(project) {
24151
- if (!existsSync7(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24246
+ if (!existsSync8(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24152
24247
  const sqlite = await loadSqlite2();
24153
24248
  if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
24154
24249
  let raw = null;
@@ -24165,8 +24260,8 @@ async function checkIndex(project) {
24165
24260
  }
24166
24261
 
24167
24262
  // src/core/ops/doctor-env.ts
24168
- import { existsSync as existsSync8, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
24169
- import { isAbsolute as isAbsolute3, join as join12, relative as relative2 } from "node:path";
24263
+ import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
24264
+ import { isAbsolute as isAbsolute3, join as join13, relative as relative2 } from "node:path";
24170
24265
  function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
24171
24266
  return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
24172
24267
  }
@@ -24178,7 +24273,7 @@ function fail4(id2, detail, fixCommand) {
24178
24273
  }
24179
24274
  function bundleVersion(bundleDir2) {
24180
24275
  try {
24181
- const v = JSON.parse(readFileSync9(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24276
+ const v = JSON.parse(readFileSync9(join13(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24182
24277
  return typeof v === "string" && v !== "" ? v : void 0;
24183
24278
  } catch {
24184
24279
  return void 0;
@@ -24328,7 +24423,7 @@ function checkMcp(ctx) {
24328
24423
  return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
24329
24424
  }
24330
24425
  function piCwdInside(worktree, piCwd) {
24331
- if (piCwd === void 0 || !existsSync8(piCwd)) return false;
24426
+ if (piCwd === void 0 || !existsSync9(piCwd)) return false;
24332
24427
  const rel = relative2(worktree, realpathSync5.native(piCwd));
24333
24428
  return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
24334
24429
  }
@@ -24349,12 +24444,13 @@ function checkShell(env) {
24349
24444
  }
24350
24445
 
24351
24446
  // src/core/ops/doctor-hook.ts
24352
- import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync7 } from "node:fs";
24447
+ import { existsSync as existsSync11, mkdtempSync, readFileSync as readFileSync10, realpathSync as realpathSync7, rmSync as rmSync2 } from "node:fs";
24448
+ import { tmpdir as tmpdir2 } from "node:os";
24353
24449
  import path6 from "node:path";
24354
24450
 
24355
24451
  // src/setup/codex-trust.ts
24356
24452
  import { createHash } from "node:crypto";
24357
- import { existsSync as existsSync9, realpathSync as realpathSync6 } from "node:fs";
24453
+ import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
24358
24454
  import path5 from "node:path";
24359
24455
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
24360
24456
 
@@ -24452,6 +24548,7 @@ var LIST_TIMEOUT_MS = 15e3;
24452
24548
  var EXIT_GRACE_MS = 5e3;
24453
24549
  var PLUGIN_SOURCE = "plugin";
24454
24550
  var TRUSTED = "trusted";
24551
+ var UNTRUSTED = "untrusted";
24455
24552
  function pluginHooksFromReply(m, pluginId) {
24456
24553
  const out = [];
24457
24554
  if (!isObj2(m) || !isObj2(m.result) || !Array.isArray(m.result.data)) return out;
@@ -24461,7 +24558,8 @@ function pluginHooksFromReply(m, pluginId) {
24461
24558
  if (!isObj2(h) || h.source !== PLUGIN_SOURCE || h.pluginId !== pluginId) continue;
24462
24559
  if (typeof h.key !== "string" || typeof h.currentHash !== "string") continue;
24463
24560
  if (out.some((x) => x.key === h.key)) continue;
24464
- out.push({ key: h.key, hash: h.currentHash, trusted: h.trustStatus === TRUSTED });
24561
+ const status = typeof h.trustStatus === "string" ? h.trustStatus : UNTRUSTED;
24562
+ out.push({ key: h.key, hash: h.currentHash, trusted: status === TRUSTED, status });
24465
24563
  }
24466
24564
  }
24467
24565
  return out;
@@ -24554,7 +24652,11 @@ var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
24554
24652
  function untrustedPluginHooksDetail(hooks) {
24555
24653
  const bad = hooks.filter((h) => !h.trusted);
24556
24654
  if (!bad.length) return void 0;
24557
- return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
24655
+ const counts = /* @__PURE__ */ new Map();
24656
+ for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
24657
+ const words = [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1));
24658
+ const state = words.length === 1 ? words[0][0] : `${words.map(([w]) => w).join(" or ")} (${words.map(([w, n]) => `${n} ${w}`).join(", ")})`;
24659
+ return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
24558
24660
  }
24559
24661
 
24560
24662
  // src/core/ops/doctor-hook.ts
@@ -24571,7 +24673,7 @@ function isObject5(v) {
24571
24673
  }
24572
24674
  function loadFixture(bundleDir2, agent) {
24573
24675
  const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
24574
- if (!existsSync10(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24676
+ if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
24575
24677
  let all;
24576
24678
  try {
24577
24679
  all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
@@ -24633,6 +24735,50 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
24633
24735
  return COPILOT_KEYS.some((k) => Object.hasOwn(out, k));
24634
24736
  }
24635
24737
  }
24738
+ var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
24739
+ function readProbePayload(cwd) {
24740
+ const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
24741
+ const filePath = path6.join(cwd, "d5-read-probe.txt");
24742
+ return {
24743
+ session_id: "d5-read-probe",
24744
+ transcript_path: "",
24745
+ cwd,
24746
+ hook_event_name: "PostToolUse",
24747
+ tool_name: "Read",
24748
+ tool_use_id: "toolu_d5_read_probe",
24749
+ tool_input: { file_path: filePath },
24750
+ tool_response: { type: "text", file: { filePath, content, numLines: READ_PROBE_LINES, startLine: 1, totalLines: READ_PROBE_LINES } }
24751
+ };
24752
+ }
24753
+ function isReadShape(stdout) {
24754
+ if (stdout.trim() === "") return true;
24755
+ let out;
24756
+ try {
24757
+ out = JSON.parse(stdout);
24758
+ } catch {
24759
+ return false;
24760
+ }
24761
+ if (!isObject5(out) || !isObject5(out.hookSpecificOutput) || !Object.hasOwn(out.hookSpecificOutput, "updatedToolOutput")) return true;
24762
+ const r = out.hookSpecificOutput.updatedToolOutput;
24763
+ if (!isObject5(r) || r.type !== "text" || !isObject5(r.file)) return false;
24764
+ const f = r.file;
24765
+ return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
24766
+ }
24767
+ async function readProbeOk(i, timeoutMs) {
24768
+ const home = mkdtempSync(path6.join(tmpdir2(), "cm-d5-read-"));
24769
+ try {
24770
+ const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
24771
+ cwd: i.bundleDir,
24772
+ env: { ...i.env, HOME: home, USERPROFILE: home },
24773
+ signal: i.signal,
24774
+ timeoutMs,
24775
+ stdin: JSON.stringify(readProbePayload(i.worktree ?? home))
24776
+ });
24777
+ return isReadShape(r.stdout.toString("utf8"));
24778
+ } finally {
24779
+ rmSync2(home, { recursive: true, force: true });
24780
+ }
24781
+ }
24636
24782
  function codexHookJournaled(db) {
24637
24783
  if (db === null) return false;
24638
24784
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
@@ -24666,7 +24812,7 @@ async function checkHookRoundTrip(i) {
24666
24812
  const trust = await codexPluginTrust(i);
24667
24813
  if (trust !== null) return trust;
24668
24814
  }
24669
- if (i.agent === "codex" && existsSync10(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24815
+ if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
24670
24816
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
24671
24817
  }
24672
24818
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -24700,18 +24846,19 @@ async function checkHookRoundTrip(i) {
24700
24846
  if (n >= minPairs && ms <= HOOK_P95_MS) break;
24701
24847
  }
24702
24848
  if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
24849
+ if (i.agent === "claude-code" && !await readProbeOk(i, timeoutMs)) return row("FAIL", D5_READ_SHAPE_DETAIL, D5_FIX);
24703
24850
  return row("PASS", DOCTOR_PASS_DETAIL);
24704
24851
  }
24705
24852
 
24706
24853
  // src/core/ops/db-heal.ts
24707
- import { existsSync as existsSync11, mkdirSync as mkdirSync5, rmSync as rmSync3 } from "node:fs";
24708
- import { basename as basename4, dirname as dirname7, join as join14 } from "node:path";
24854
+ import { existsSync as existsSync12, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
24855
+ import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
24709
24856
 
24710
24857
  // src/core/store/owners.ts
24711
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync11, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24712
- import { basename as basename3, join as join13 } from "node:path";
24858
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync11, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
24859
+ import { basename as basename3, join as join14 } from "node:path";
24713
24860
  function ownersDir(configDir, projectKey) {
24714
- return join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
24861
+ return join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
24715
24862
  }
24716
24863
  function errCode2(err) {
24717
24864
  return err.code;
@@ -24739,7 +24886,7 @@ function listLiveOwners(configDir, projectKey) {
24739
24886
  const live = [];
24740
24887
  for (const name of names) {
24741
24888
  if (!name.endsWith(OWNER_PID_EXT)) continue;
24742
- const file2 = join13(dir, name);
24889
+ const file2 = join14(dir, name);
24743
24890
  let text;
24744
24891
  try {
24745
24892
  text = readFileSync11(file2, "utf8");
@@ -24749,7 +24896,7 @@ function listLiveOwners(configDir, projectKey) {
24749
24896
  }
24750
24897
  const serverId = basename3(name, OWNER_PID_EXT);
24751
24898
  if (isLive(Number(text.trim()))) live.push(serverId);
24752
- else rmSync2(file2, { force: true });
24899
+ else rmSync3(file2, { force: true });
24753
24900
  }
24754
24901
  return live;
24755
24902
  }
@@ -24761,7 +24908,7 @@ function integrityOk2(rows) {
24761
24908
  async function healLossless(dbPath) {
24762
24909
  const { DatabaseSync } = await import(SQLITE_MODULE);
24763
24910
  const tmp = dbPath + HEAL_TMP_SUFFIX;
24764
- rmSync3(tmp, { force: true });
24911
+ rmSync4(tmp, { force: true });
24765
24912
  try {
24766
24913
  const src = new DatabaseSync(dbPath, { readOnly: true, timeout: DB_TIMEOUT_MS });
24767
24914
  try {
@@ -24777,18 +24924,18 @@ async function healLossless(dbPath) {
24777
24924
  } finally {
24778
24925
  copy.close();
24779
24926
  }
24780
- rmSync3(dbPath + DB_WAL_SUFFIX, { force: true });
24781
- rmSync3(dbPath + DB_SHM_SUFFIX, { force: true });
24927
+ rmSync4(dbPath + DB_WAL_SUFFIX, { force: true });
24928
+ rmSync4(dbPath + DB_SHM_SUFFIX, { force: true });
24782
24929
  renameWithRetry(tmp, dbPath);
24783
24930
  } finally {
24784
- rmSync3(tmp, { force: true });
24931
+ rmSync4(tmp, { force: true });
24785
24932
  }
24786
24933
  }
24787
24934
  function renameAside(dbPath) {
24788
24935
  const ts = String(Date.now());
24789
24936
  for (const suffix of DB_SIBLING_SUFFIXES) {
24790
24937
  const file2 = dbPath + suffix;
24791
- if (existsSync11(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
24938
+ if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
24792
24939
  }
24793
24940
  return ts;
24794
24941
  }
@@ -24811,7 +24958,7 @@ function utcStamp(now) {
24811
24958
  return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
24812
24959
  }
24813
24960
  function makeOrphanDir(projectDir) {
24814
- const base = join14(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
24961
+ const base = join15(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
24815
24962
  for (let n = 1; ; n += 1) {
24816
24963
  const dir = n === 1 ? base : base + "-" + String(n);
24817
24964
  try {
@@ -24826,9 +24973,9 @@ async function healOrphan(project, files, row5) {
24826
24973
  const moved = [];
24827
24974
  let dir = "";
24828
24975
  try {
24829
- dir = makeOrphanDir(dirname7(project.dbPath));
24976
+ dir = makeOrphanDir(dirname8(project.dbPath));
24830
24977
  for (const f of files) {
24831
- const to = join14(dir, basename4(f.path));
24978
+ const to = join15(dir, basename4(f.path));
24832
24979
  renameWithRetry(f.path, to);
24833
24980
  moved.push({ path: to, bytes: f.bytes });
24834
24981
  }
@@ -24895,8 +25042,8 @@ function buildReportHead(input) {
24895
25042
 
24896
25043
  // src/core/ops/doctor-issue.ts
24897
25044
  import { spawnSync as spawnSync3 } from "node:child_process";
24898
- import { closeSync, existsSync as existsSync12, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
24899
- import { delimiter, join as join15 } from "node:path";
25045
+ import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
25046
+ import { delimiter, join as join16 } from "node:path";
24900
25047
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
24901
25048
  function tildeOf(env) {
24902
25049
  const home = homeDirOf(env);
@@ -24937,8 +25084,8 @@ function onPath(env, tool) {
24937
25084
  const out = [];
24938
25085
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
24939
25086
  if (dir === "") continue;
24940
- for (const n of names) if (existsSync12(join15(dir, n))) {
24941
- out.push(join15(dir, n));
25087
+ for (const n of names) if (existsSync13(join16(dir, n))) {
25088
+ out.push(join16(dir, n));
24942
25089
  break;
24943
25090
  }
24944
25091
  }
@@ -24946,7 +25093,7 @@ function onPath(env, tool) {
24946
25093
  }
24947
25094
  function hookLogTail(env) {
24948
25095
  const file2 = hookLogPath(env);
24949
- if (file2 === "" || !existsSync12(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
25096
+ if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
24950
25097
  try {
24951
25098
  const fd = openSync(file2, "r");
24952
25099
  try {
@@ -24966,7 +25113,7 @@ function hookLogTail(env) {
24966
25113
  }
24967
25114
  async function journalRows(ctx) {
24968
25115
  const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
24969
- if (!existsSync12(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
25116
+ if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
24970
25117
  try {
24971
25118
  const db = await openDb(ctx.project, { readOnly: true });
24972
25119
  try {
@@ -24984,15 +25131,15 @@ function agentConfig(adapter, env, worktree) {
24984
25131
  const home = homeDirOf(env);
24985
25132
  const files = configPaths(adapter, env, worktree);
24986
25133
  if (home !== null) {
24987
- if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join15(claudeDirOf(env, home), SETTINGS_FILE) });
24988
- if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join15(codexDirOf(env, home), CONFIG_TOML_FILE) });
25134
+ if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join16(claudeDirOf(env, home), SETTINGS_FILE) });
25135
+ if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join16(codexDirOf(env, home), CONFIG_TOML_FILE) });
24989
25136
  }
24990
25137
  const out = [];
24991
25138
  const seen = /* @__PURE__ */ new Set();
24992
25139
  for (const f of files) {
24993
25140
  if (seen.has(f.path)) continue;
24994
25141
  seen.add(f.path);
24995
- if (!existsSync12(f.path)) {
25142
+ if (!existsSync13(f.path)) {
24996
25143
  out.push(`${f.label}: ${f.path} (absent)`);
24997
25144
  continue;
24998
25145
  }
@@ -25068,14 +25215,14 @@ async function buildIssueBody(i) {
25068
25215
  async function writeIssueReport(i) {
25069
25216
  const tilde = tildeOf(i.env);
25070
25217
  const body = await buildIssueBody(i);
25071
- const dir = join15(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
25218
+ const dir = join16(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
25072
25219
  mkdirSync6(dir, { recursive: true });
25073
- const file2 = join15(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
25220
+ const file2 = join16(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
25074
25221
  writeFileSync3(file2, body);
25075
25222
  const shown2 = tilde(file2);
25076
25223
  const title = issueTitle(i.adapter.id, i.rows);
25077
25224
  const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
25078
- return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows))];
25225
+ return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows)), DOCTOR_RULES_LINE + ISSUE_GUIDE_URL];
25079
25226
  }
25080
25227
  function formUrl(title, summary) {
25081
25228
  const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
@@ -25097,7 +25244,7 @@ async function guard(id2, run) {
25097
25244
  }
25098
25245
  }
25099
25246
  async function codexDb(ctx, adapter) {
25100
- if (adapter.id !== "codex" || !existsSync13(ctx.project.dbPath)) return null;
25247
+ if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
25101
25248
  try {
25102
25249
  return await openDb(ctx.project, { readOnly: true });
25103
25250
  } catch {
@@ -25127,11 +25274,11 @@ async function hookRow(ctx, adapter, host) {
25127
25274
  }
25128
25275
  }
25129
25276
  function ownServerId(configDir, projectKey) {
25130
- const dir = join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
25131
- if (!existsSync13(dir)) return "";
25277
+ const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
25278
+ if (!existsSync14(dir)) return "";
25132
25279
  for (const name of readdirSync6(dir)) {
25133
25280
  if (!name.endsWith(OWNER_PID_EXT)) continue;
25134
- if (readFileSync13(join16(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25281
+ if (readFileSync13(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25135
25282
  }
25136
25283
  return "";
25137
25284
  }
@@ -25214,7 +25361,7 @@ async function doctorReply(ctx, host) {
25214
25361
  return { text, isError: false, sandboxBytes: bytes5 };
25215
25362
  }
25216
25363
  async function handler2(_input, ctx) {
25217
- return doctorReply(ctx, { env: process.env, bundleDir: dirname8(process.argv[1]), piCwd: void 0 });
25364
+ return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: void 0 });
25218
25365
  }
25219
25366
  var ctxDoctor = Object.freeze({
25220
25367
  name: "ctx_doctor",
@@ -25226,9 +25373,9 @@ var ctxDoctor = Object.freeze({
25226
25373
  });
25227
25374
 
25228
25375
  // src/core/tools/execute.ts
25229
- import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
25230
- import { tmpdir as tmpdir2 } from "node:os";
25231
- import { dirname as dirname9, join as join17, parse as parse3, resolve as resolve6 } from "node:path";
25376
+ import { existsSync as existsSync15, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
25377
+ import { tmpdir as tmpdir3 } from "node:os";
25378
+ import { dirname as dirname10, join as join18, parse as parse3, resolve as resolve6 } from "node:path";
25232
25379
 
25233
25380
  // src/core/sandbox/win-build.ts
25234
25381
  var SEPARATORS2 = ";&|(\n";
@@ -25312,7 +25459,7 @@ function schemaLine(issue2) {
25312
25459
  }
25313
25460
  function fileError(given, abs, root) {
25314
25461
  let dir = abs;
25315
- while (!existsSync14(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
25462
+ while (!existsSync15(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
25316
25463
  if (isInside(root, dir)) return null;
25317
25464
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
25318
25465
  }
@@ -25393,8 +25540,8 @@ async function handler3(raw, ctx) {
25393
25540
  if (takesDashC(input.language, runtime)) {
25394
25541
  argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
25395
25542
  } else {
25396
- tmpDir = mkdtempSync(join17(tmpdir2(), TMP_PREFIX));
25397
- const file2 = join17(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
25543
+ tmpDir = mkdtempSync2(join18(tmpdir3(), TMP_PREFIX));
25544
+ const file2 = join18(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
25398
25545
  writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
25399
25546
  argv = scriptArgv(input.language, runtime, file2);
25400
25547
  }
@@ -25417,7 +25564,7 @@ async function handler3(raw, ctx) {
25417
25564
  }
25418
25565
  throw err;
25419
25566
  } finally {
25420
- if (tmpDir !== null && !handedOff) rmSync4(tmpDir, { recursive: true, force: true });
25567
+ if (tmpDir !== null && !handedOff) rmSync5(tmpDir, { recursive: true, force: true });
25421
25568
  }
25422
25569
  }
25423
25570
  var ctxExecute = {
@@ -25429,12 +25576,12 @@ var ctxExecute = {
25429
25576
  };
25430
25577
 
25431
25578
  // src/core/tools/index.ts
25432
- import { existsSync as existsSync15, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
25433
- import { dirname as dirname10, extname, join as join19, relative as relative3, resolve as resolve7 } from "node:path";
25579
+ import { existsSync as existsSync16, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
25580
+ import { dirname as dirname11, extname, join as join20, relative as relative3, resolve as resolve7 } from "node:path";
25434
25581
 
25435
25582
  // src/core/index/walk.ts
25436
25583
  import { readdirSync as readdirSync7, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
25437
- import { join as join18 } from "node:path";
25584
+ import { join as join19 } from "node:path";
25438
25585
  var GITIGNORE = ".gitignore";
25439
25586
  var GIT_DIR = ".git";
25440
25587
  function walkDir(root, containmentRoot) {
@@ -25443,7 +25590,7 @@ function walkDir(root, containmentRoot) {
25443
25590
  const found = [];
25444
25591
  visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
25445
25592
  found.sort(compareFound);
25446
- return found.map((f) => ({ absPath: f.absPath, relPath: join18(...f.dir, f.name) }));
25593
+ return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
25447
25594
  }
25448
25595
  function visit(abs, rel, parent, contain, seen, found) {
25449
25596
  let entries;
@@ -25452,10 +25599,10 @@ function visit(abs, rel, parent, contain, seen, found) {
25452
25599
  } catch {
25453
25600
  return;
25454
25601
  }
25455
- const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join18(abs, GITIGNORE), rel)) : parent;
25602
+ const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
25456
25603
  for (const e of entries) {
25457
25604
  if (e.name === GIT_DIR) continue;
25458
- const path7 = join18(abs, e.name);
25605
+ const path7 = join19(abs, e.name);
25459
25606
  let isDir = e.isDirectory();
25460
25607
  let isFile = e.isFile();
25461
25608
  let target = path7;
@@ -29585,7 +29732,7 @@ function readUtf8(absPath) {
29585
29732
  }
29586
29733
  function missingOrOutside(given, abs, root) {
29587
29734
  let dir = abs;
29588
- while (!existsSync15(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
29735
+ while (!existsSync16(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
29589
29736
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
29590
29737
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
29591
29738
  }
@@ -29596,7 +29743,7 @@ function pathItems(input, project) {
29596
29743
  if (statSync8(abs).isDirectory()) {
29597
29744
  return walkDir(abs, project.containmentRoot).map((f) => ({
29598
29745
  sourceKind: "path",
29599
- label: pathLabel(join19(base, f.relPath)),
29746
+ label: pathLabel(join20(base, f.relPath)),
29600
29747
  kind: kindOfPath(f.relPath),
29601
29748
  read: () => readUtf8(f.absPath)
29602
29749
  }));
@@ -30136,12 +30283,12 @@ var ctxStats = Object.freeze({
30136
30283
  });
30137
30284
 
30138
30285
  // src/core/tools/upgrade.ts
30139
- import { existsSync as existsSync21, realpathSync as realpathSync10, rmSync as rmSync9 } from "node:fs";
30140
- import { basename as basename7, dirname as dirname12, join as join25 } from "node:path";
30286
+ import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
30287
+ import { basename as basename7, dirname as dirname13, join as join26 } from "node:path";
30141
30288
 
30142
30289
  // src/core/ops/host-write.ts
30143
- import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30144
- import { dirname as dirname11, join as join20 } from "node:path";
30290
+ import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
30291
+ import { dirname as dirname12, join as join21 } from "node:path";
30145
30292
  function defaultWrite(file2, text) {
30146
30293
  writeFileSync5(file2, text, "utf8");
30147
30294
  }
@@ -30150,14 +30297,14 @@ function hostConfigPath(agent, home, env) {
30150
30297
  if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
30151
30298
  switch (agent) {
30152
30299
  case "opencode":
30153
- return join20(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
30300
+ return join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
30154
30301
  // D-WIN-OPENCODE-DIR-1
30155
30302
  case "pi":
30156
- return join20(piAgentDirOf(env, home), SETTINGS_FILE);
30303
+ return join21(piAgentDirOf(env, home), SETTINGS_FILE);
30157
30304
  case "copilot-cli":
30158
30305
  return null;
30159
30306
  default:
30160
- return join20(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
30307
+ return join21(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
30161
30308
  }
30162
30309
  }
30163
30310
  function cell3(value) {
@@ -30169,8 +30316,8 @@ function toRow(file2, edit) {
30169
30316
  function writeWithRollback(file2, text, write2, atomic) {
30170
30317
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
30171
30318
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
30172
- const had = existsSync16(file2);
30173
- mkdirSync7(dirname11(file2), { recursive: true });
30319
+ const had = existsSync17(file2);
30320
+ mkdirSync7(dirname12(file2), { recursive: true });
30174
30321
  if (had) copyFileSync(file2, trash);
30175
30322
  try {
30176
30323
  write2(tmp, text);
@@ -30199,7 +30346,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
30199
30346
  if (requested === null) return [];
30200
30347
  const current = readHostConfig(row5.id, requested);
30201
30348
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
30202
- const exists = existsSync16(current.path);
30349
+ const exists = existsSync17(current.path);
30203
30350
  if (exists && result.text === current.text) return [];
30204
30351
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
30205
30352
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -30207,8 +30354,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
30207
30354
  }
30208
30355
 
30209
30356
  // src/core/ops/plugin-swap.ts
30210
- import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30211
- import { basename as basename6, join as join21, win32 as win322 } from "node:path";
30357
+ import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30358
+ import { basename as basename6, join as join22, win32 as win322 } from "node:path";
30212
30359
  function linkTarget(path7, win) {
30213
30360
  if (!isLink(path7)) return null;
30214
30361
  const target = readlinkSync(path7);
@@ -30227,11 +30374,11 @@ function settleLinks(link, tmp, old, opts) {
30227
30374
  else renameWithRetry(old, link, opts);
30228
30375
  }
30229
30376
  function swapPluginCurrent(agentDir, sha, opts = {}) {
30230
- const next = join21(agentDir, sha);
30231
- if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
30377
+ const next = join22(agentDir, sha);
30378
+ if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
30232
30379
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
30233
30380
  }
30234
- const link = join21(agentDir, PLUGIN_CURRENT_LINK);
30381
+ const link = join22(agentDir, PLUGIN_CURRENT_LINK);
30235
30382
  const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
30236
30383
  const old = link + PLUGIN_LINK_OLD_SUFFIX;
30237
30384
  settleLinks(link, tmp, old, opts);
@@ -30246,15 +30393,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
30246
30393
  if (before !== null) unlinkSync2(old);
30247
30394
  const keep = /* @__PURE__ */ new Set([sha]);
30248
30395
  if (before !== null) keep.add(before);
30249
- const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join21(agentDir, name));
30250
- for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
30251
- const previous = before !== null && existsSync17(join21(agentDir, before)) ? join21(agentDir, before) : null;
30396
+ const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join22(agentDir, name));
30397
+ for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
30398
+ const previous = before !== null && existsSync18(join22(agentDir, before)) ? join22(agentDir, before) : null;
30252
30399
  return { current: next, previous, removed };
30253
30400
  }
30254
30401
 
30255
30402
  // src/core/ops/release-fetch.ts
30256
- import { existsSync as existsSync18, mkdirSync as mkdirSync8, rmSync as rmSync6 } from "node:fs";
30257
- import { join as join22 } from "node:path";
30403
+ import { existsSync as existsSync19, mkdirSync as mkdirSync8, rmSync as rmSync7 } from "node:fs";
30404
+ import { join as join23 } from "node:path";
30258
30405
  function failed(r) {
30259
30406
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
30260
30407
  const status = r.killed ?? String(r.exitCode);
@@ -30266,36 +30413,36 @@ async function git2(bin, args, cwd, env, signal) {
30266
30413
  return r.stdout.toString().trim();
30267
30414
  }
30268
30415
  async function fetchRelease(agent, url2, env, signal, opts = {}) {
30269
- const agentDir = join22(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
30416
+ const agentDir = join23(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
30270
30417
  mkdirSync8(agentDir, { recursive: true });
30271
- const fetchDir = join22(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
30272
- rmSync6(fetchDir, { recursive: true, force: true });
30418
+ const fetchDir = join23(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
30419
+ rmSync7(fetchDir, { recursive: true, force: true });
30273
30420
  const gitBin = findRuntime(GIT_BIN, env);
30274
30421
  if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
30275
30422
  const childEnv = buildChildEnv(env, { ...GIT_NO_PROMPT_ENV, ...GIT_NO_CRLF_ENV });
30276
30423
  try {
30277
30424
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
30278
30425
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
30279
- const dir = join22(agentDir, sha);
30280
- if (existsSync18(dir)) rmSync6(fetchDir, { recursive: true, force: true });
30426
+ const dir = join23(agentDir, sha);
30427
+ if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
30281
30428
  else renameWithRetry(fetchDir, dir, opts);
30282
30429
  return { sha, dir };
30283
30430
  } catch (e) {
30284
- rmSync6(fetchDir, { recursive: true, force: true });
30431
+ rmSync7(fetchDir, { recursive: true, force: true });
30285
30432
  throw e;
30286
30433
  }
30287
30434
  }
30288
30435
 
30289
30436
  // src/core/ops/uninstall.ts
30290
- import { existsSync as existsSync19, readdirSync as readdirSync9, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
30291
- import { join as join23 } from "node:path";
30437
+ import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
30438
+ import { join as join24 } from "node:path";
30292
30439
  function row2(area, before, after) {
30293
30440
  return { area, before, after };
30294
30441
  }
30295
30442
  function stopServers(configDir, projectKey) {
30296
30443
  const stopped = listLiveOwners(configDir, projectKey);
30297
- const dir = join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
30298
- for (const serverId of stopped) writeFileSync6(join23(dir, serverId + OWNER_STOP_EXT), "", "utf8");
30444
+ const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
30445
+ for (const serverId of stopped) writeFileSync6(join24(dir, serverId + OWNER_STOP_EXT), "", "utf8");
30299
30446
  return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
30300
30447
  }
30301
30448
  function rootOrNull(adapter, env) {
@@ -30313,16 +30460,16 @@ function removeCache(adapter, env, configDir) {
30313
30460
  const root = rootOrNull(adapter, env);
30314
30461
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30315
30462
  if (adapter.installMode === "marketplace") {
30316
- const cache = join23(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
30463
+ const cache = join24(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
30317
30464
  if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
30318
30465
  }
30319
- rmSync7(root, { recursive: true, force: true });
30466
+ rmSync8(root, { recursive: true, force: true });
30320
30467
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
30321
30468
  }
30322
30469
  case "plugin": {
30323
- const agentDir = join23(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
30324
- if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30325
- rmSync7(agentDir, { recursive: true, force: true });
30470
+ const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
30471
+ if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
30472
+ rmSync8(agentDir, { recursive: true, force: true });
30326
30473
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
30327
30474
  }
30328
30475
  case "config-mcp":
@@ -30366,7 +30513,7 @@ function ownEntries(agent, env) {
30366
30513
  }
30367
30514
  if (agent === "opencode") {
30368
30515
  return [{
30369
- file: join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
30516
+ file: join24(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
30370
30517
  // D-WIN-OPENCODE-DIR-1
30371
30518
  key: OPENCODE_PLUGIN_KEY,
30372
30519
  shown: OPENCODE_PLUGIN_KEY,
@@ -30377,7 +30524,7 @@ function ownEntries(agent, env) {
30377
30524
  if (agent === "pi") {
30378
30525
  const agentDir = piAgentDirOf(env, home);
30379
30526
  return [{
30380
- file: join23(agentDir, SETTINGS_FILE),
30527
+ file: join24(agentDir, SETTINGS_FILE),
30381
30528
  key: PI_PACKAGES_KEY,
30382
30529
  shown: PI_PACKAGES_KEY,
30383
30530
  has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
@@ -30399,12 +30546,12 @@ function removeOwnEntries(agent, env) {
30399
30546
  return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
30400
30547
  }
30401
30548
  function removeProjectData(configDir, projectKey) {
30402
- const projects = join23(configDir, PROJECTS_DIR_NAME);
30403
- const dir = join23(projects, projectKey);
30404
- if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30549
+ const projects = join24(configDir, PROJECTS_DIR_NAME);
30550
+ const dir = join24(projects, projectKey);
30551
+ if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30405
30552
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
30406
30553
  for (const name of readdirSync9(dir)) {
30407
- if (name !== OWNERS_DIR_NAME) rmSync7(join23(dir, name), { recursive: true, force: true });
30554
+ if (name !== OWNERS_DIR_NAME) rmSync8(join24(dir, name), { recursive: true, force: true });
30408
30555
  }
30409
30556
  return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
30410
30557
  }
@@ -30412,25 +30559,25 @@ function runUninstall(input) {
30412
30559
  const configDir = resolveConfigDir(input.env);
30413
30560
  const stop = stopServers(configDir, input.project.projectKey);
30414
30561
  const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
30415
- rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join23(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
30562
+ rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join24(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
30416
30563
  return { rows, stopped: stop.stopped };
30417
30564
  }
30418
30565
 
30419
30566
  // src/core/ops/v1-remove.ts
30420
- import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync16, rmSync as rmSync8 } from "node:fs";
30567
+ import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync16, rmSync as rmSync9 } from "node:fs";
30421
30568
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
30422
30569
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
30423
30570
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
30424
30571
  function moveAside(target, undo) {
30425
30572
  const trash = target + UPGRADE_TRASH_SUFFIX;
30426
- rmSync8(trash, { recursive: true, force: true });
30573
+ rmSync9(trash, { recursive: true, force: true });
30427
30574
  renameWithRetry(target, trash);
30428
30575
  undo.push({ trash, target });
30429
30576
  }
30430
30577
  function keepOriginal(file2, kept, undo) {
30431
30578
  if (kept.has(file2)) return;
30432
30579
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
30433
- rmSync8(trash, { recursive: true, force: true });
30580
+ rmSync9(trash, { recursive: true, force: true });
30434
30581
  copyFileSync2(file2, trash);
30435
30582
  kept.add(file2);
30436
30583
  undo.push({ trash, target: file2 });
@@ -30498,14 +30645,14 @@ function removeV1(agent, findings) {
30498
30645
  for (const f of findings) {
30499
30646
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
30500
30647
  else if (f.path === "") {
30501
- if (existsSync20(f.file)) {
30648
+ if (existsSync21(f.file)) {
30502
30649
  moveAside(f.file, undo);
30503
30650
  done.set(f, UPGRADE_REMOVED);
30504
30651
  } else done.set(f, UPGRADE_NOT_FOUND);
30505
30652
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
30506
30653
  }
30507
30654
  for (const [file2, list4] of entries) {
30508
- if (!existsSync20(file2)) {
30655
+ if (!existsSync21(file2)) {
30509
30656
  for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
30510
30657
  continue;
30511
30658
  }
@@ -30534,12 +30681,12 @@ function removeV1(agent, findings) {
30534
30681
  return {
30535
30682
  rows: findings.map((f) => row3(f, done.get(f) ?? UPGRADE_NOT_FOUND)),
30536
30683
  commit() {
30537
- for (const u of undo.splice(0)) rmSync8(u.trash, { recursive: true, force: true });
30684
+ for (const u of undo.splice(0)) rmSync9(u.trash, { recursive: true, force: true });
30538
30685
  },
30539
30686
  rollback() {
30540
30687
  for (const u of undo.splice(0).reverse()) {
30541
- if (!existsSync20(u.trash)) continue;
30542
- rmSync8(u.target, { recursive: true, force: true });
30688
+ if (!existsSync21(u.trash)) continue;
30689
+ rmSync9(u.target, { recursive: true, force: true });
30543
30690
  renameWithRetry(u.trash, u.target);
30544
30691
  }
30545
30692
  }
@@ -30549,7 +30696,7 @@ function removeV1(agent, findings) {
30549
30696
  // src/core/ops/verify-sums.ts
30550
30697
  import { createHash as createHash2 } from "node:crypto";
30551
30698
  import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync17 } from "node:fs";
30552
- import { join as join24 } from "node:path";
30699
+ import { join as join25 } from "node:path";
30553
30700
  function mismatch() {
30554
30701
  return new CtxError("BUNDLE_HASH_MISMATCH");
30555
30702
  }
@@ -30570,14 +30717,14 @@ function walk3(dir, prefix, out) {
30570
30717
  for (const entry of readdirSync10(dir, { withFileTypes: true })) {
30571
30718
  const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
30572
30719
  if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
30573
- const abs = join24(dir, entry.name);
30720
+ const abs = join25(dir, entry.name);
30574
30721
  if (entry.isDirectory()) walk3(abs, rel, out);
30575
30722
  else if (entry.isFile()) out.set(rel, abs);
30576
30723
  else throw mismatch();
30577
30724
  }
30578
30725
  }
30579
30726
  function verifySums(dir) {
30580
- const sumsPath = join24(dir, RELEASE_SUMS_FILE);
30727
+ const sumsPath = join25(dir, RELEASE_SUMS_FILE);
30581
30728
  const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
30582
30729
  if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
30583
30730
  const sums = parseSums(readFileSync17(sumsPath, "utf8"));
@@ -30601,7 +30748,7 @@ function row4(area, before, after) {
30601
30748
  return { area, before, after };
30602
30749
  }
30603
30750
  function bundleDir() {
30604
- return dirname12(process.argv[1] ?? "");
30751
+ return ownBundleDir();
30605
30752
  }
30606
30753
  function pluginRootRow(adapter, env) {
30607
30754
  const own2 = bundleDir();
@@ -30615,16 +30762,16 @@ function pluginRootRow(adapter, env) {
30615
30762
  return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
30616
30763
  }
30617
30764
  function isCurrent(agentDir, dir) {
30618
- const link = join25(agentDir, PLUGIN_CURRENT_LINK);
30619
- return existsSync21(link) && realpathSync10.native(link) === realpathSync10.native(dir);
30765
+ const link = join26(agentDir, PLUGIN_CURRENT_LINK);
30766
+ return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
30620
30767
  }
30621
30768
  async function checkout(adapter, deps) {
30622
30769
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
30623
- const agentDir = dirname12(fetched.dir);
30770
+ const agentDir = dirname13(fetched.dir);
30624
30771
  try {
30625
30772
  verifySums(fetched.dir);
30626
30773
  } catch (err) {
30627
- if (!isCurrent(agentDir, fetched.dir)) rmSync9(fetched.dir, { recursive: true, force: true });
30774
+ if (!isCurrent(agentDir, fetched.dir)) rmSync10(fetched.dir, { recursive: true, force: true });
30628
30775
  throw err;
30629
30776
  }
30630
30777
  const swap = swapPluginCurrent(agentDir, fetched.sha);