context-mode 2.0.2 → 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.
package/server.mjs CHANGED
@@ -7,9 +7,9 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/entries/server.ts
9
9
  import { randomUUID } from "node:crypto";
10
- import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync12 } from "node:fs";
11
- import { dirname as dirname12, join as join24 } from "node:path";
12
- import { fileURLToPath as fileURLToPath2 } from "node:url";
10
+ import { existsSync as existsSync24, realpathSync as realpathSync12, rmSync as rmSync12 } from "node:fs";
11
+ import { dirname as dirname13, join as join25 } from "node:path";
12
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
13
13
 
14
14
  // node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
15
15
  var __create = Object.create;
@@ -2386,8 +2386,8 @@ function handleArrayResult(result, final, index) {
2386
2386
  }
2387
2387
  var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
2388
2388
  $ZodType.init(inst, def);
2389
- const memo4 = globalConfig.memoizer;
2390
- memo4?.attach(inst);
2389
+ const memo5 = globalConfig.memoizer;
2390
+ memo5?.attach(inst);
2391
2391
  inst._zod.parse = (payload, ctx) => {
2392
2392
  const input = payload.value;
2393
2393
  if (!Array.isArray(input)) {
@@ -2399,7 +2399,7 @@ var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
2399
2399
  });
2400
2400
  return payload;
2401
2401
  }
2402
- payload.value = memo4 ? memo4.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
2402
+ payload.value = memo5 ? memo5.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
2403
2403
  const proms = [];
2404
2404
  const abortEarly = ctx?.abortEarly;
2405
2405
  for (let i = 0; i < input.length; i++) {
@@ -2559,8 +2559,8 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
2559
2559
  const isObject6 = isObject;
2560
2560
  const catchall = def.catchall;
2561
2561
  let value;
2562
- const memo4 = globalConfig.memoizer;
2563
- memo4?.attach(inst);
2562
+ const memo5 = globalConfig.memoizer;
2563
+ memo5?.attach(inst);
2564
2564
  inst._zod.parse = (payload, ctx) => {
2565
2565
  value ?? (value = _normalized.value);
2566
2566
  const input = payload.value;
@@ -2573,7 +2573,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
2573
2573
  });
2574
2574
  return payload;
2575
2575
  }
2576
- payload.value = memo4 ? memo4.alloc(inst, payload, {}, ctx) : {};
2576
+ payload.value = memo5 ? memo5.alloc(inst, payload, {}, ctx) : {};
2577
2577
  const proms = [];
2578
2578
  const shape = value.shape;
2579
2579
  const abortEarly = ctx?.abortEarly;
@@ -2606,11 +2606,11 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
2606
2606
  $ZodObject.init(inst, def);
2607
2607
  const superParse = inst._zod.parse;
2608
2608
  const _normalized = cached(() => normalizeDef(def));
2609
- const memo4 = globalConfig.memoizer;
2609
+ const memo5 = globalConfig.memoizer;
2610
2610
  const generateFastpass = (shape) => {
2611
2611
  const normalized = _normalized.value;
2612
2612
  const syms = normalized.symbolKeys;
2613
- const doc = new Doc(["payload", "ctx"], { shape, inst, memo: memo4, syms });
2613
+ const doc = new Doc(["payload", "ctx"], { shape, inst, memo: memo5, syms });
2614
2614
  const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
2615
2615
  const prefixStr = (id, k) => `
2616
2616
  let ${id}_ab = false;
@@ -2630,7 +2630,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
2630
2630
  for (const key of normalized.allKeys) {
2631
2631
  ids[key] = `key_${counter++}`;
2632
2632
  }
2633
- doc.write(memo4 ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
2633
+ doc.write(memo5 ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
2634
2634
  for (const key of normalized.allKeys) {
2635
2635
  if (key === "__proto__")
2636
2636
  continue;
@@ -2993,8 +2993,8 @@ function handleIntersectionResults(result, left, right2) {
2993
2993
  }
2994
2994
  var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
2995
2995
  $ZodType.init(inst, def);
2996
- const memo4 = globalConfig.memoizer;
2997
- memo4?.attach(inst);
2996
+ const memo5 = globalConfig.memoizer;
2997
+ memo5?.attach(inst);
2998
2998
  inst._zod.parse = (payload, ctx) => {
2999
2999
  const input = payload.value;
3000
3000
  if (!isPlainObject(input)) {
@@ -3009,7 +3009,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
3009
3009
  const proms = [];
3010
3010
  const values = def.keyType._zod.values;
3011
3011
  if (values && !def.partial) {
3012
- payload.value = memo4 ? memo4.alloc(inst, payload, {}, ctx) : {};
3012
+ payload.value = memo5 ? memo5.alloc(inst, payload, {}, ctx) : {};
3013
3013
  const recordKeys = /* @__PURE__ */ new Set();
3014
3014
  for (const key of values) {
3015
3015
  if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
@@ -3073,7 +3073,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
3073
3073
  });
3074
3074
  }
3075
3075
  } else {
3076
- payload.value = memo4 ? memo4.alloc(inst, payload, {}, ctx) : {};
3076
+ payload.value = memo5 ? memo5.alloc(inst, payload, {}, ctx) : {};
3077
3077
  let unrecognized;
3078
3078
  for (const key of Reflect.ownKeys(input)) {
3079
3079
  if (key === "__proto__")
@@ -9915,8 +9915,8 @@ function handleArrayResult2(result, final, index) {
9915
9915
  }
9916
9916
  var $ZodArray2 = /* @__PURE__ */ $constructor2("$ZodArray", (inst, def) => {
9917
9917
  $ZodType2.init(inst, def);
9918
- const memo4 = globalConfig2.memoizer;
9919
- memo4?.attach(inst);
9918
+ const memo5 = globalConfig2.memoizer;
9919
+ memo5?.attach(inst);
9920
9920
  inst._zod.parse = (payload, ctx) => {
9921
9921
  const input = payload.value;
9922
9922
  if (!Array.isArray(input)) {
@@ -9928,7 +9928,7 @@ var $ZodArray2 = /* @__PURE__ */ $constructor2("$ZodArray", (inst, def) => {
9928
9928
  });
9929
9929
  return payload;
9930
9930
  }
9931
- payload.value = memo4 ? memo4.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
9931
+ payload.value = memo5 ? memo5.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
9932
9932
  const proms = [];
9933
9933
  const abortEarly = ctx?.abortEarly;
9934
9934
  for (let i = 0; i < input.length; i++) {
@@ -10088,8 +10088,8 @@ var $ZodObject2 = /* @__PURE__ */ $constructor2("$ZodObject", (inst, def) => {
10088
10088
  const isObject6 = isObject2;
10089
10089
  const catchall = def.catchall;
10090
10090
  let value;
10091
- const memo4 = globalConfig2.memoizer;
10092
- memo4?.attach(inst);
10091
+ const memo5 = globalConfig2.memoizer;
10092
+ memo5?.attach(inst);
10093
10093
  inst._zod.parse = (payload, ctx) => {
10094
10094
  value ?? (value = _normalized.value);
10095
10095
  const input = payload.value;
@@ -10102,7 +10102,7 @@ var $ZodObject2 = /* @__PURE__ */ $constructor2("$ZodObject", (inst, def) => {
10102
10102
  });
10103
10103
  return payload;
10104
10104
  }
10105
- payload.value = memo4 ? memo4.alloc(inst, payload, {}, ctx) : {};
10105
+ payload.value = memo5 ? memo5.alloc(inst, payload, {}, ctx) : {};
10106
10106
  const proms = [];
10107
10107
  const shape = value.shape;
10108
10108
  const abortEarly = ctx?.abortEarly;
@@ -10135,11 +10135,11 @@ var $ZodObjectJIT2 = /* @__PURE__ */ $constructor2("$ZodObjectJIT", (inst, def)
10135
10135
  $ZodObject2.init(inst, def);
10136
10136
  const superParse = inst._zod.parse;
10137
10137
  const _normalized = cached2(() => normalizeDef2(def));
10138
- const memo4 = globalConfig2.memoizer;
10138
+ const memo5 = globalConfig2.memoizer;
10139
10139
  const generateFastpass = (shape) => {
10140
10140
  const normalized = _normalized.value;
10141
10141
  const syms = normalized.symbolKeys;
10142
- const doc = new Doc2(["payload", "ctx"], { shape, inst, memo: memo4, syms });
10142
+ const doc = new Doc2(["payload", "ctx"], { shape, inst, memo: memo5, syms });
10143
10143
  const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
10144
10144
  const prefixStr = (id, k) => `
10145
10145
  let ${id}_ab = false;
@@ -10159,7 +10159,7 @@ var $ZodObjectJIT2 = /* @__PURE__ */ $constructor2("$ZodObjectJIT", (inst, def)
10159
10159
  for (const key of normalized.allKeys) {
10160
10160
  ids[key] = `key_${counter++}`;
10161
10161
  }
10162
- doc.write(memo4 ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
10162
+ doc.write(memo5 ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
10163
10163
  for (const key of normalized.allKeys) {
10164
10164
  if (key === "__proto__")
10165
10165
  continue;
@@ -10522,8 +10522,8 @@ function handleIntersectionResults2(result, left, right2) {
10522
10522
  }
10523
10523
  var $ZodRecord2 = /* @__PURE__ */ $constructor2("$ZodRecord", (inst, def) => {
10524
10524
  $ZodType2.init(inst, def);
10525
- const memo4 = globalConfig2.memoizer;
10526
- memo4?.attach(inst);
10525
+ const memo5 = globalConfig2.memoizer;
10526
+ memo5?.attach(inst);
10527
10527
  inst._zod.parse = (payload, ctx) => {
10528
10528
  const input = payload.value;
10529
10529
  if (!isPlainObject2(input)) {
@@ -10538,7 +10538,7 @@ var $ZodRecord2 = /* @__PURE__ */ $constructor2("$ZodRecord", (inst, def) => {
10538
10538
  const proms = [];
10539
10539
  const values = def.keyType._zod.values;
10540
10540
  if (values && !def.partial) {
10541
- payload.value = memo4 ? memo4.alloc(inst, payload, {}, ctx) : {};
10541
+ payload.value = memo5 ? memo5.alloc(inst, payload, {}, ctx) : {};
10542
10542
  const recordKeys = /* @__PURE__ */ new Set();
10543
10543
  for (const key of values) {
10544
10544
  if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
@@ -10602,7 +10602,7 @@ var $ZodRecord2 = /* @__PURE__ */ $constructor2("$ZodRecord", (inst, def) => {
10602
10602
  });
10603
10603
  }
10604
10604
  } else {
10605
- payload.value = memo4 ? memo4.alloc(inst, payload, {}, ctx) : {};
10605
+ payload.value = memo5 ? memo5.alloc(inst, payload, {}, ctx) : {};
10606
10606
  let unrecognized;
10607
10607
  for (const key of Reflect.ownKeys(input)) {
10608
10608
  if (key === "__proto__")
@@ -28407,7 +28407,7 @@ var DECISION_SOURCE = "decision";
28407
28407
  var DECISION_USER_LABEL = "decision (user)";
28408
28408
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
28409
28409
  var RELEASE_BRANCH = "release";
28410
- var BUNDLE_SHA = true ? "9f1916d761e6a8e55ac43858b99dcdcd3cc53caa" : void 0;
28410
+ var BUNDLE_SHA = true ? "d232ce4ddfb581a63a4c0d6ef894b64a0f8464f6" : void 0;
28411
28411
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
28412
28412
  var DOCTOR_LABEL = Object.freeze({
28413
28413
  D1: "version",
@@ -28701,8 +28701,8 @@ var UPGRADE_DATA_DELETED = "user data deleted";
28701
28701
  var UPGRADE_HOST_COMMAND = Object.freeze({
28702
28702
  "claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
28703
28703
  codex: "rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",
28704
- gemini: "gemini extensions install https://github.com/mksglu/context-mode --ref release --auto-update",
28705
- qwen: "qwen extensions install https://github.com/mksglu/context-mode --ref release --auto-update"
28704
+ gemini: "gemini extensions install https://github.com/mksglu/context-mode --auto-update",
28705
+ qwen: "qwen extensions install https://github.com/mksglu/context-mode --auto-update"
28706
28706
  });
28707
28707
  var PI_GIT_PACKAGE = "git:github.com/mksglu/context-mode@release";
28708
28708
  var OPENCODE_GIT_SPEC = "git+https://github.com/mksglu/context-mode.git#release";
@@ -28766,6 +28766,9 @@ var HOOKS_KEY = "hooks";
28766
28766
  var STATUS_LINE_KEY = "statusLine";
28767
28767
  var PI_PACKAGES_KEY = "packages";
28768
28768
  var OPENCODE_PLUGIN_KEY = "plugin";
28769
+ var OPENCODE_PLUGINS_KEY = "plugins";
28770
+ var OPENCODE_PACKAGE_FIELD = "package";
28771
+ var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
28769
28772
  var V1_DATA_DIR_NAME = "context-mode";
28770
28773
  var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
28771
28774
  var V1_SESSIONS_DIR_NAME = "sessions";
@@ -28863,6 +28866,7 @@ var DOCTOR_REPORT_FILE_PREFIX = "doctor-";
28863
28866
  var DOCTOR_REPORT_LINE = "Report file: ";
28864
28867
  var DOCTOR_GH_LINE = "File it: ";
28865
28868
  var DOCTOR_URL_LINE = "Or open: ";
28869
+ var DOCTOR_RULES_LINE = "Rules: ";
28866
28870
  var DOCTOR_GH_NEXT = " --";
28867
28871
  var DOCTOR_NOTE_PREFIXES = Object.freeze([
28868
28872
  DOCTOR_ENV_PREFIX,
@@ -28870,10 +28874,23 @@ var DOCTOR_NOTE_PREFIXES = Object.freeze([
28870
28874
  DOCTOR_REPORT_LINE,
28871
28875
  DOCTOR_GH_LINE,
28872
28876
  DOCTOR_GH_NEXT.trim(),
28873
- DOCTOR_URL_LINE
28877
+ DOCTOR_URL_LINE,
28878
+ DOCTOR_RULES_LINE
28874
28879
  ]);
28875
28880
  var ISSUE_REPO_SLUG = "mksglu/context-mode";
28876
28881
  var ISSUE_FORM_FILE = "agent-report.yml";
28882
+ var ISSUE_GUIDE_URL = `https://github.com/${ISSUE_REPO_SLUG}/blob/main/.github/AGENT_ISSUE.md`;
28883
+ var ISSUE_AGENT_RULES = Object.freeze([
28884
+ '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.',
28885
+ "File one bug per issue.",
28886
+ "Call the `ctx_doctor` tool and paste its full output unchanged in the `ctx-report` field.",
28887
+ "Give the versions: context-mode, the agent, the OS and arch, and Node.",
28888
+ "Write numbered repro steps that start from a fresh project (`mktemp -d`) and the agent's own install command.",
28889
+ "Give the exact command and its exact output in a fenced code block.",
28890
+ "Say what you expected and what happened instead.",
28891
+ "Name the source file and line when you found the cause.",
28892
+ "Replace every secret with `<masked>` and the home folder with `~` before you send."
28893
+ ]);
28877
28894
  var ISSUE_URL_MAX = 8e3;
28878
28895
  var ISSUE_FORM_HEADINGS = Object.freeze([
28879
28896
  "Summary",
@@ -28904,16 +28921,16 @@ var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
28904
28921
  var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
28905
28922
  var DOCTOR_MASK = "<masked>";
28906
28923
  var NATIVE_INSTALL = Object.freeze({
28907
- "claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
28908
- codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
28909
- gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
28910
- qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
28911
- opencode: ["opencode plugin add context-mode@next"],
28912
- pi: ["pi install npm:context-mode@next"],
28913
- "copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
28914
- vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
28915
- kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
28916
- zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
28924
+ "claude-code": ["claude plugin marketplace add mksglu/context-mode", "claude plugin install context-mode@context-mode"],
28925
+ codex: ["codex plugin marketplace add mksglu/context-mode", "codex plugin add context-mode@context-mode"],
28926
+ gemini: ["gemini extensions install https://github.com/mksglu/context-mode"],
28927
+ qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
28928
+ opencode: ["opencode plugin add context-mode"],
28929
+ pi: ["pi install npm:context-mode"],
28930
+ "copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
28931
+ vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
28932
+ kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
28933
+ zcode: ["npm i -g context-mode", "context-mode setup --agents zcode"]
28917
28934
  });
28918
28935
  var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
28919
28936
  var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
@@ -29380,14 +29397,29 @@ function copilotDirOf(env, home) {
29380
29397
  function kiroDirOf(env, home, platform = process.platform) {
29381
29398
  const p = platform === "win32" ? win32 : posix;
29382
29399
  const fallback = p.join(home, ...AGENT_HOME_DIR.kiro);
29383
- const dir = env[KIRO_HOME_ENV];
29400
+ const dir = env[KIRO_HOME_ENV]?.trim();
29384
29401
  if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
29385
29402
  if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
29386
29403
  const abs = p.resolve(dir);
29387
- if (p.dirname(abs) === abs) return fallback;
29388
- const up = p.relative(abs, p.resolve(home));
29404
+ const real2 = platform === process.platform ? realOrSelf : (x) => x;
29405
+ const target = real2(abs);
29406
+ if (p.parse(target).root === target) return fallback;
29407
+ const up = p.relative(target, real2(p.resolve(home)));
29389
29408
  if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
29390
- return dir;
29409
+ return abs;
29410
+ }
29411
+ function realOrSelf(path7) {
29412
+ const tail = [];
29413
+ for (let at = path7; ; ) {
29414
+ try {
29415
+ return join(realpathSync.native(at), ...tail.reverse());
29416
+ } catch {
29417
+ const up = dirname(at);
29418
+ if (up === at) return path7;
29419
+ tail.push(basename(at));
29420
+ at = up;
29421
+ }
29422
+ }
29391
29423
  }
29392
29424
  function claudeDirOf(env, home) {
29393
29425
  const dir = env[CLAUDE_CONFIG_DIR_ENV];
@@ -43827,7 +43859,7 @@ function cutPoint(src, start, end, scratch) {
43827
43859
  const r = encoder.encodeInto(src.slice(start, limit), scratch);
43828
43860
  return { end: start + r.read, written: r.written };
43829
43861
  }
43830
- function merge4(src, blocks, join25, cap, lineCut) {
43862
+ function merge4(src, blocks, join26, cap, lineCut) {
43831
43863
  const out = [];
43832
43864
  const scratch = new Uint8Array(cap);
43833
43865
  let wide;
@@ -43837,7 +43869,7 @@ function merge4(src, blocks, join25, cap, lineCut) {
43837
43869
  out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
43838
43870
  };
43839
43871
  for (const b of blocks) {
43840
- if (cur !== void 0 && !join25) {
43872
+ if (cur !== void 0 && !join26) {
43841
43873
  emit(cur.start, cur.end, curBytes);
43842
43874
  cur = void 0;
43843
43875
  }
@@ -44765,8 +44797,8 @@ var ctxBatch = Object.freeze({
44765
44797
  });
44766
44798
 
44767
44799
  // src/core/tools/doctor.ts
44768
- import { readdirSync as readdirSync7, readFileSync as readFileSync10, existsSync as existsSync14 } from "node:fs";
44769
- import { basename as basename5, dirname as dirname7, join as join14 } from "node:path";
44800
+ import { readdirSync as readdirSync7, readFileSync as readFileSync10, existsSync as existsSync15 } from "node:fs";
44801
+ import { basename as basename5, join as join15 } from "node:path";
44770
44802
 
44771
44803
  // src/adapters/claude-code.ts
44772
44804
  var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
@@ -45272,7 +45304,8 @@ function encode8(ev, d, _extra) {
45272
45304
  }
45273
45305
 
45274
45306
  // src/adapters/kiro.ts
45275
- var TOOL_NAME_PREFIX7 = "mcp_context-mode_";
45307
+ var TOOL_NAME_PREFIX7 = "mcp_context_mode_";
45308
+ var LEGACY_TOOL_NAME_PREFIX = "mcp_context-mode_";
45276
45309
  var KIRO_EVENTS = {
45277
45310
  SessionStart: "SessionStart",
45278
45311
  agentSpawn: "SessionStart",
@@ -45284,6 +45317,7 @@ var KIRO_EVENTS = {
45284
45317
  PostToolUse: "PostToolUse",
45285
45318
  postToolUse: "PostToolUse"
45286
45319
  };
45320
+ var PROMPT_FIELD = "prompt";
45287
45321
  var PROMPT_ENV = "USER_PROMPT";
45288
45322
  var MCP_PREFIX3 = "mcp_";
45289
45323
  var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
@@ -45292,6 +45326,7 @@ var MCP_SEP3 = "_";
45292
45326
  var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
45293
45327
  function canonicalName5(name) {
45294
45328
  if (name.startsWith(TOOL_NAME_PREFIX7)) return name.slice(TOOL_NAME_PREFIX7.length);
45329
+ if (name.startsWith(LEGACY_TOOL_NAME_PREFIX)) return name.slice(LEGACY_TOOL_NAME_PREFIX.length);
45295
45330
  if (Object.hasOwn(NATIVE_TO_CANONICAL5, name)) return NATIVE_TO_CANONICAL5[name];
45296
45331
  if (!name.startsWith(MCP_PREFIX3)) return name;
45297
45332
  const rest = name.slice(MCP_PREFIX3.length);
@@ -45312,7 +45347,8 @@ function decode9(raw) {
45312
45347
  const ev = { event, agent: "kiro", sessionId: String(p.session_id ?? ""), cwd: String(p.cwd ?? "") };
45313
45348
  if (event === "SessionStart" && typeof p.source === "string" && KIRO_SOURCES[p.source] !== void 0) ev.source = KIRO_SOURCES[p.source];
45314
45349
  if (event === "UserPromptSubmit") {
45315
- const prompt = process.env[PROMPT_ENV];
45350
+ const field = p[PROMPT_FIELD];
45351
+ const prompt = typeof field === "string" ? field : process.env[PROMPT_ENV];
45316
45352
  if (prompt !== void 0) ev.prompt = prompt;
45317
45353
  }
45318
45354
  if (event === "PreToolUse" || event === "PostToolUse") {
@@ -45324,7 +45360,7 @@ function decode9(raw) {
45324
45360
  return ev;
45325
45361
  }
45326
45362
  function encode9(ev, d, _extra) {
45327
- if (ev.event === "UserPromptSubmit") return { stdout: "", exitCode: 0 };
45363
+ if (ev.event === "UserPromptSubmit") return { stdout: d.kind === "hint" ? d.text : "", exitCode: 0 };
45328
45364
  switch (d.kind) {
45329
45365
  case "allow":
45330
45366
  return { stdout: "", exitCode: 0 };
@@ -45683,18 +45719,40 @@ function getAdapter(id) {
45683
45719
  return BY_ID.get(id);
45684
45720
  }
45685
45721
 
45722
+ // src/core/ops/bundle-dir.ts
45723
+ import { existsSync as existsSync4 } from "node:fs";
45724
+ import { dirname as dirname4, join as join6 } from "node:path";
45725
+ import { fileURLToPath } from "node:url";
45726
+ function bundleDirOf(argv1, moduleFile) {
45727
+ const own4 = dirname4(argv1);
45728
+ if (existsSync4(join6(own4, SERVER_ENTRY_FILE))) return own4;
45729
+ let dir = dirname4(moduleFile);
45730
+ for (; ; ) {
45731
+ if (existsSync4(join6(dir, SERVER_ENTRY_FILE))) return dir;
45732
+ const up = dirname4(dir);
45733
+ if (up === dir) return own4;
45734
+ dir = up;
45735
+ }
45736
+ }
45737
+ var memo4;
45738
+ function ownBundleDir() {
45739
+ const argv1 = process.argv[1] ?? "";
45740
+ if (memo4?.argv1 !== argv1) memo4 = { argv1, dir: bundleDirOf(argv1, fileURLToPath(import.meta.url)) };
45741
+ return memo4.dir;
45742
+ }
45743
+
45686
45744
  // src/core/ops/doctor-config.ts
45687
- import { existsSync as existsSync7, readdirSync as readdirSync6 } from "node:fs";
45688
- import { join as join9 } from "node:path";
45745
+ import { existsSync as existsSync8, readdirSync as readdirSync6 } from "node:fs";
45746
+ import { join as join10 } from "node:path";
45689
45747
 
45690
45748
  // src/core/ops/detect-v1.ts
45691
- import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync5 } from "node:fs";
45749
+ import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync5 } from "node:fs";
45692
45750
  import { tmpdir } from "node:os";
45693
- import { join as join7 } from "node:path";
45751
+ import { join as join8 } from "node:path";
45694
45752
 
45695
45753
  // src/core/ops/host-config.ts
45696
- import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
45697
- import { dirname as dirname4, join as join6 } from "node:path";
45754
+ import { existsSync as existsSync5, readFileSync as readFileSync4 } from "node:fs";
45755
+ import { dirname as dirname5, join as join7 } from "node:path";
45698
45756
 
45699
45757
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
45700
45758
  var KEYS2 = {
@@ -47834,10 +47892,10 @@ function formatOf(path7) {
47834
47892
  function readHostConfig(agent, path7) {
47835
47893
  let file2 = path7;
47836
47894
  if (agent === "opencode") {
47837
- const jsonc = join6(dirname4(path7), OPENCODE_CONFIG_FILES[0]);
47838
- if (existsSync4(jsonc)) file2 = jsonc;
47895
+ const jsonc = join7(dirname5(path7), OPENCODE_CONFIG_FILES[0]);
47896
+ if (existsSync5(jsonc)) file2 = jsonc;
47839
47897
  }
47840
- const raw = existsSync4(file2) ? readFileSync4(file2, "utf8") : "";
47898
+ const raw = existsSync5(file2) ? readFileSync4(file2, "utf8") : "";
47841
47899
  return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
47842
47900
  }
47843
47901
  function stripJsonComments(text) {
@@ -48182,7 +48240,7 @@ function setText(agent, path7, text, format, key, value) {
48182
48240
  }
48183
48241
  }
48184
48242
  function serverScript() {
48185
- return join6(dirname4(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
48243
+ return join7(dirname5(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
48186
48244
  }
48187
48245
  function isNodeCommand(command) {
48188
48246
  if (typeof command !== "string") return false;
@@ -48198,7 +48256,7 @@ function ownMcpValue(agent, node3, server) {
48198
48256
  return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
48199
48257
  }
48200
48258
  function opencodePluginFile() {
48201
- return dirname4(process.argv[1] ?? "");
48259
+ return ownBundleDir();
48202
48260
  }
48203
48261
  function listTarget(key, own4, v1, alt = []) {
48204
48262
  return {
@@ -48357,7 +48415,7 @@ function flatCommands(events, prefix) {
48357
48415
  var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
48358
48416
  var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
48359
48417
  function dataDir(dir, reason, out) {
48360
- if (existsSync5(dir)) out.push(finding(dir, "", reason));
48418
+ if (existsSync6(dir)) out.push(finding(dir, "", reason));
48361
48419
  }
48362
48420
  function mcpEntry(file2, doc, out) {
48363
48421
  if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
@@ -48365,7 +48423,7 @@ function mcpEntry(file2, doc, out) {
48365
48423
  }
48366
48424
  }
48367
48425
  function claudeShapeSettings(agentHome, out) {
48368
- const file2 = join7(agentHome, SETTINGS_FILE);
48426
+ const file2 = join8(agentHome, SETTINGS_FILE);
48369
48427
  const doc = readJson(file2);
48370
48428
  for (const c of nestedCommands(doc)) {
48371
48429
  if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
@@ -48385,49 +48443,49 @@ function v1HookFile(file2, out) {
48385
48443
  function scanClaudeCode(home, agentHome, out) {
48386
48444
  claudeShapeSettings(agentHome, out);
48387
48445
  for (const ext of V1_CACHE_HEAL_EXTS) {
48388
- const file2 = join7(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
48389
- if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
48446
+ const file2 = join8(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
48447
+ if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
48390
48448
  }
48391
- const userFile = join7(home, CLAUDE_USER_CONFIG_FILE);
48449
+ const userFile = join8(home, CLAUDE_USER_CONFIG_FILE);
48392
48450
  mcpEntry(userFile, readJson(userFile), out);
48393
- dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48451
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48394
48452
  }
48395
48453
  function scanCodex(agentHome, out) {
48396
- const hooksFile = join7(agentHome, HOOKS_JSON_FILE);
48454
+ const hooksFile = join8(agentHome, HOOKS_JSON_FILE);
48397
48455
  for (const c of nestedCommands(readJson(hooksFile))) {
48398
48456
  if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
48399
48457
  out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
48400
48458
  }
48401
48459
  }
48402
- const tomlFile = join7(agentHome, CONFIG_TOML_FILE);
48460
+ const tomlFile = join8(agentHome, CONFIG_TOML_FILE);
48403
48461
  const config4 = readTomlValue(tomlFile);
48404
48462
  for (const span2 of readTomlTables(tomlFile)) {
48405
48463
  if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
48406
48464
  if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
48407
48465
  out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
48408
48466
  }
48409
- dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48467
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48410
48468
  }
48411
48469
  function scanGemini(agentHome, out) {
48412
- const file2 = join7(agentHome, SETTINGS_FILE);
48470
+ const file2 = join8(agentHome, SETTINGS_FILE);
48413
48471
  for (const c of nestedCommands(readJson(file2))) {
48414
48472
  if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
48415
48473
  }
48416
- dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
48474
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
48417
48475
  }
48418
48476
  function scanVscode(agentHome, project, out) {
48419
48477
  if (project !== void 0) {
48420
- v1HookFile(join7(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
48421
- const mcpFile2 = join7(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
48478
+ v1HookFile(join8(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
48479
+ const mcpFile2 = join8(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
48422
48480
  const doc = readJson(mcpFile2);
48423
48481
  const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
48424
48482
  const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
48425
48483
  if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
48426
48484
  out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
48427
48485
  }
48428
- dataDir(join7(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
48486
+ dataDir(join8(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
48429
48487
  }
48430
- dataDir(join7(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
48488
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
48431
48489
  }
48432
48490
  function jsonFiles(dir) {
48433
48491
  try {
@@ -48437,10 +48495,10 @@ function jsonFiles(dir) {
48437
48495
  }
48438
48496
  }
48439
48497
  function scanKiro(agentHome, project, out) {
48440
- const agentsDir = join7(agentHome, KIRO_AGENTS_DIR);
48441
- const defaultFile = join7(agentHome, ...KIRO_AGENT_FILE);
48498
+ const agentsDir = join8(agentHome, KIRO_AGENTS_DIR);
48499
+ const defaultFile = join8(agentHome, ...KIRO_AGENT_FILE);
48442
48500
  for (const name of jsonFiles(agentsDir)) {
48443
- const file2 = join7(agentsDir, name);
48501
+ const file2 = join8(agentsDir, name);
48444
48502
  const doc = readJson(file2);
48445
48503
  if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
48446
48504
  out.push(finding(file2, "", V1_REASON.kiroAgentFile));
@@ -48451,25 +48509,25 @@ function scanKiro(agentHome, project, out) {
48451
48509
  if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
48452
48510
  }
48453
48511
  }
48454
- const steeringDocs = [join7(agentHome, ...KIRO_STEERING_FILE)];
48455
- if (project !== void 0) steeringDocs.push(join7(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
48512
+ const steeringDocs = [join8(agentHome, ...KIRO_STEERING_FILE)];
48513
+ if (project !== void 0) steeringDocs.push(join8(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
48456
48514
  for (const file2 of steeringDocs) {
48457
- if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
48515
+ if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
48458
48516
  }
48459
- dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48517
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48460
48518
  }
48461
48519
  function scanPi(piAgentDir, agentHome, out) {
48462
- const file2 = join7(piAgentDir, SETTINGS_FILE);
48520
+ const file2 = join8(piAgentDir, SETTINGS_FILE);
48463
48521
  const doc = readJson(file2);
48464
48522
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
48465
48523
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
48466
48524
  if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
48467
48525
  });
48468
- dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48526
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48469
48527
  }
48470
48528
  function scanOpencode(agentHome, out) {
48471
48529
  for (const name of OPENCODE_CONFIG_FILES) {
48472
- const file2 = join7(agentHome, name);
48530
+ const file2 = join8(agentHome, name);
48473
48531
  const doc = readJson(file2);
48474
48532
  if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
48475
48533
  doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
@@ -48479,13 +48537,13 @@ function scanOpencode(agentHome, out) {
48479
48537
  }
48480
48538
  }
48481
48539
  function scanZcode(agentHome, out) {
48482
- const configFile = join7(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
48540
+ const configFile = join8(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
48483
48541
  const config4 = readJson(configFile);
48484
48542
  const events = isObj(config4) && isObj(config4[HOOKS_KEY]) ? config4[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
48485
48543
  for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
48486
48544
  if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
48487
48545
  }
48488
- const hooksFile = join7(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
48546
+ const hooksFile = join8(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
48489
48547
  for (const c of nestedCommands(readJson(hooksFile))) {
48490
48548
  if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
48491
48549
  }
@@ -48509,14 +48567,14 @@ function firstTmpMatch(dir) {
48509
48567
  }
48510
48568
  }
48511
48569
  function scanAll(home, tmp, out) {
48512
- const root = join7(home, DATA_ROOT.slice(1));
48513
- for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join7(root, name), V1_REASON.dataRoot, out);
48570
+ const root = join8(home, DATA_ROOT.slice(1));
48571
+ for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join8(root, name), V1_REASON.dataRoot, out);
48514
48572
  if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
48515
48573
  }
48516
48574
  function detectV1(agent, home, scope = {}) {
48517
48575
  const out = [];
48518
48576
  const project = scope.project;
48519
- 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 : join7(home, ...AGENT_HOME_DIR[agent]);
48577
+ 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 : join8(home, ...AGENT_HOME_DIR[agent]);
48520
48578
  switch (agent) {
48521
48579
  case "claude-code":
48522
48580
  scanClaudeCode(home, agentHome, out);
@@ -48529,11 +48587,11 @@ function detectV1(agent, home, scope = {}) {
48529
48587
  break;
48530
48588
  case "qwen":
48531
48589
  claudeShapeSettings(agentHome, out);
48532
- dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48590
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48533
48591
  break;
48534
48592
  case "copilot-cli":
48535
- v1HookFile(join7(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
48536
- dataDir(join7(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48593
+ v1HookFile(join8(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
48594
+ dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
48537
48595
  break;
48538
48596
  case "vscode":
48539
48597
  scanVscode(agentHome, project, out);
@@ -48542,7 +48600,7 @@ function detectV1(agent, home, scope = {}) {
48542
48600
  scanKiro(agentHome, project, out);
48543
48601
  break;
48544
48602
  case "pi":
48545
- scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join7(agentHome, PI_AGENT_DIR), agentHome, out);
48603
+ scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join8(agentHome, PI_AGENT_DIR), agentHome, out);
48546
48604
  break;
48547
48605
  // D-WIN-PIDIR-1: empty is unset
48548
48606
  case "opencode":
@@ -48557,9 +48615,9 @@ function detectV1(agent, home, scope = {}) {
48557
48615
  }
48558
48616
 
48559
48617
  // src/core/ops/plugin-root.ts
48560
- import { existsSync as existsSync6, readdirSync as readdirSync5, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
48561
- import { dirname as dirname5, isAbsolute, join as join8, sep as sep2 } from "node:path";
48562
- import { fileURLToPath } from "node:url";
48618
+ import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
48619
+ import { dirname as dirname6, isAbsolute, join as join9, sep as sep2 } from "node:path";
48620
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
48563
48621
  function missing(agent, path7) {
48564
48622
  return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
48565
48623
  }
@@ -48606,8 +48664,8 @@ var readOrNull = (file2) => {
48606
48664
  };
48607
48665
  var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
48608
48666
  function enabledPlugins(claudeDir, project) {
48609
- const files = [join8(claudeDir, SETTINGS_FILE)];
48610
- if (project !== void 0) files.push(join8(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join8(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
48667
+ const files = [join9(claudeDir, SETTINGS_FILE)];
48668
+ if (project !== void 0) files.push(join9(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join9(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
48611
48669
  const out = {};
48612
48670
  for (const file2 of files) {
48613
48671
  const text = readOrNull(file2);
@@ -48620,13 +48678,13 @@ function enabledPlugins(claudeDir, project) {
48620
48678
  function marketplaceChoice(env, worktree) {
48621
48679
  const claudeDir = claudeDirOf(env, requireHomeDir(env));
48622
48680
  const script = process.argv[1];
48623
- const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
48681
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
48624
48682
  const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
48625
48683
  if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
48626
- const record6 = readOrNull(join8(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
48684
+ const record6 = readOrNull(join9(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
48627
48685
  const recorded = record6 === null ? [] : recordedInstalls(record6);
48628
48686
  if (recorded.length === 0) return { record: false };
48629
- const live = recorded.filter((r) => existsSync6(r.installPath));
48687
+ const live = recorded.filter((r) => existsSync7(r.installPath));
48630
48688
  const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
48631
48689
  if (mine !== void 0) return { root: mine.installPath };
48632
48690
  const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
@@ -48646,18 +48704,18 @@ function marketplaceChoice(env, worktree) {
48646
48704
  }
48647
48705
  function marketplaceRoot(adapter, env, worktree) {
48648
48706
  const claudeDir = claudeDirOf(env, requireHomeDir(env));
48649
- const plugins = join8(claudeDir, HOST_PLUGINS_DIR_NAME);
48650
- const cache = join8(plugins, PLUGIN_CACHE_DIR_NAME);
48707
+ const plugins = join9(claudeDir, HOST_PLUGINS_DIR_NAME);
48708
+ const cache = join9(plugins, PLUGIN_CACHE_DIR_NAME);
48651
48709
  const script = process.argv[1];
48652
- const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
48710
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
48653
48711
  const choice = marketplaceChoice(env, worktree);
48654
48712
  if ("root" in choice) return choice.root;
48655
48713
  if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
48656
48714
  const cacheReal = realOrNull(cache);
48657
- if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync6(join8(ownReal, SERVER_ENTRY_FILE))) return ownReal;
48658
- const pattern = join8(cache, "*", PLUGIN_NAME);
48659
- if (!existsSync6(cache)) throw missing(adapter.id, pattern);
48660
- const found = readdirSync5(cache).sort().map((marketplace) => join8(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
48715
+ if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync7(join9(ownReal, SERVER_ENTRY_FILE))) return ownReal;
48716
+ const pattern = join9(cache, "*", PLUGIN_NAME);
48717
+ if (!existsSync7(cache)) throw missing(adapter.id, pattern);
48718
+ const found = readdirSync5(cache).sort().map((marketplace) => join9(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
48661
48719
  if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
48662
48720
  return found[0];
48663
48721
  }
@@ -48665,13 +48723,13 @@ function configEntryRoot(adapter, env) {
48665
48723
  const spec = OWN_MCP_ENTRY[adapter.id];
48666
48724
  if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
48667
48725
  const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
48668
- if (!existsSync6(file2)) throw missing(adapter.id, file2);
48726
+ if (!existsSync7(file2)) throw missing(adapter.id, file2);
48669
48727
  const current = readHostConfig(adapter.id, file2);
48670
48728
  const value = parseHostConfig(adapter.id, file2, current.text, current.format);
48671
48729
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
48672
48730
  const script = Array.isArray(args) ? args[0] : void 0;
48673
48731
  if (typeof script !== "string" || !isAbsolute(script)) throw missing(adapter.id, file2);
48674
- return dirname5(script);
48732
+ return dirname6(script);
48675
48733
  }
48676
48734
  function candidate(adapter, env, worktree) {
48677
48735
  switch (adapter.installMode) {
@@ -48682,11 +48740,11 @@ function candidate(adapter, env, worktree) {
48682
48740
  case "hooks+mcp":
48683
48741
  return configEntryRoot(adapter, env);
48684
48742
  case "extension":
48685
- return join8(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id], EXTENSIONS_DIR_NAME, PLUGIN_NAME);
48743
+ return join9(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id], EXTENSIONS_DIR_NAME, PLUGIN_NAME);
48686
48744
  case "plugin":
48687
- return join8(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
48745
+ return join9(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
48688
48746
  case "in-process":
48689
- return dirname5(fileURLToPath(import.meta.url));
48747
+ return dirname6(fileURLToPath2(import.meta.url));
48690
48748
  }
48691
48749
  }
48692
48750
  function resolvePluginRoot(adapter, env, worktree) {
@@ -48775,11 +48833,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
48775
48833
  var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
48776
48834
  function mcpFile(row5, home, env) {
48777
48835
  const spec = OWN_MCP_ENTRY[row5.id];
48778
- if (row5.id === "codex") return join9(codexDirOf(env, home), CONFIG_TOML_FILE);
48836
+ if (row5.id === "codex") return join10(codexDirOf(env, home), CONFIG_TOML_FILE);
48779
48837
  if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
48780
- if (row5.id === "opencode") return join9(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
48838
+ if (row5.id === "opencode") return join10(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
48781
48839
  if (row5.id === "pi") {
48782
- return join9(piAgentDirOf(env, home), SETTINGS_FILE);
48840
+ return join10(piAgentDirOf(env, home), SETTINGS_FILE);
48783
48841
  }
48784
48842
  return null;
48785
48843
  }
@@ -48792,27 +48850,27 @@ function codexNativeDir(env, home) {
48792
48850
  const codexDir = codexDirOf(env, home);
48793
48851
  let enabled;
48794
48852
  try {
48795
- enabled = hostConfigValueAt(readParsed("codex", join9(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
48853
+ enabled = hostConfigValueAt(readParsed("codex", join10(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
48796
48854
  } catch {
48797
48855
  return null;
48798
48856
  }
48799
48857
  if (enabled !== true) return null;
48800
- const cache = join9(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
48801
- if (!existsSync7(cache)) return null;
48858
+ const cache = join10(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
48859
+ if (!existsSync8(cache)) return null;
48802
48860
  const found = [];
48803
48861
  for (const market of readdirSync6(cache)) {
48804
- const plugin = join9(cache, market, SERVER_KEY);
48805
- if (!existsSync7(plugin)) continue;
48862
+ const plugin = join10(cache, market, SERVER_KEY);
48863
+ if (!existsSync8(plugin)) continue;
48806
48864
  for (const version4 of readdirSync6(plugin).sort()) {
48807
- const dir = join9(plugin, version4, CODEX_PLUGIN_SUBDIR);
48808
- if (existsSync7(join9(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
48865
+ const dir = join10(plugin, version4, CODEX_PLUGIN_SUBDIR);
48866
+ if (existsSync8(join10(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
48809
48867
  }
48810
48868
  }
48811
48869
  return found.length === 0 ? null : found[found.length - 1];
48812
48870
  }
48813
48871
  function nativeMcpWrong(dir, row5) {
48814
48872
  try {
48815
- const entry = hostConfigValueAt(readParsed(row5.id, join9(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
48873
+ const entry = hostConfigValueAt(readParsed(row5.id, join10(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
48816
48874
  if (!isObject4(entry)) return true;
48817
48875
  const args = list(entry[MCP_ARGS_FIELD]);
48818
48876
  const script = args[0];
@@ -48821,6 +48879,17 @@ function nativeMcpWrong(dir, row5) {
48821
48879
  return true;
48822
48880
  }
48823
48881
  }
48882
+ function isOwnOpencodeEntry(entry, key, own4) {
48883
+ const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : entry;
48884
+ if (typeof spec !== "string") return false;
48885
+ if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own4.includes(spec)) return true;
48886
+ return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
48887
+ }
48888
+ function opencodeListed(file2) {
48889
+ const { value } = readParsed("opencode", file2);
48890
+ const own4 = [opencodePluginFile()];
48891
+ return [OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own4)));
48892
+ }
48824
48893
  function mcpWrong(row5, home, env, worktree) {
48825
48894
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
48826
48895
  if (native !== null) return nativeMcpWrong(native, row5);
@@ -48830,6 +48899,7 @@ function mcpWrong(row5, home, env, worktree) {
48830
48899
  resolvePluginRoot(row5, env, worktree);
48831
48900
  return false;
48832
48901
  }
48902
+ if (row5.id === "opencode") return !opencodeListed(file2);
48833
48903
  const cur = readHostConfig(row5.id, file2);
48834
48904
  return mergeOwnEntries(row5.id, cur.text, cur.format, row5, { nodePath: true, listEntries: [opencodePluginFile()] }).edits.length > 0;
48835
48905
  } catch {
@@ -48839,7 +48909,7 @@ function mcpWrong(row5, home, env, worktree) {
48839
48909
  function hookFile(row5, spec, home, env, worktree) {
48840
48910
  const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
48841
48911
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
48842
- const file2 = native !== null ? join9(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join9(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join9(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join9(kiroDirOf(env, home), ...spec.file.slice(1)) : join9(root, ...spec.file);
48912
+ const file2 = native !== null ? join10(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join10(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join10(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join10(kiroDirOf(env, home), ...spec.file.slice(1)) : join10(root, ...spec.file);
48843
48913
  return file2;
48844
48914
  }
48845
48915
  function hookParts(row5, home, env, worktree) {
@@ -48850,7 +48920,7 @@ function hookParts(row5, home, env, worktree) {
48850
48920
  const file2 = hookFile(row5, spec, home, env, worktree);
48851
48921
  block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
48852
48922
  if (row5.id === "codex") {
48853
- const config4 = readParsed(row5.id, join9(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
48923
+ const config4 = readParsed(row5.id, join10(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
48854
48924
  if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
48855
48925
  }
48856
48926
  } catch {
@@ -48908,10 +48978,10 @@ function parsedOrNull(agent, file2, jsonc) {
48908
48978
  }
48909
48979
  function checkDoubleFire(agent, worktree) {
48910
48980
  if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
48911
- const claude = parsedOrNull(agent, join9(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
48981
+ const claude = parsedOrNull(agent, join10(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
48912
48982
  const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
48913
48983
  const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
48914
- const vscode = parsedOrNull(agent, join9(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
48984
+ const vscode = parsedOrNull(agent, join10(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
48915
48985
  const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
48916
48986
  return hooksOn && useClaudeHooks ? fail("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
48917
48987
  }
@@ -48922,7 +48992,7 @@ function configPaths(row5, env, worktree) {
48922
48992
  const mcp = mcpFile(row5, home, env);
48923
48993
  if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
48924
48994
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
48925
- if (native !== null) out.push({ label: "Codex plugin MCP", path: join9(native, CODEX_PLUGIN_MCP_FILE) });
48995
+ if (native !== null) out.push({ label: "Codex plugin MCP", path: join10(native, CODEX_PLUGIN_MCP_FILE) });
48926
48996
  const spec = HOOK_HOST_FILE[row5.id];
48927
48997
  if (spec !== null) {
48928
48998
  try {
@@ -48942,7 +49012,7 @@ function configPaths(row5, env, worktree) {
48942
49012
  }
48943
49013
 
48944
49014
  // src/core/ops/doctor-db.ts
48945
- import { existsSync as existsSync8, statSync as statSync4 } from "node:fs";
49015
+ import { existsSync as existsSync9, statSync as statSync4 } from "node:fs";
48946
49016
  var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
48947
49017
  var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
48948
49018
  var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -48984,15 +49054,15 @@ function orphanFiles(dbPath) {
48984
49054
  const files = [];
48985
49055
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
48986
49056
  const path7 = dbPath + suffix;
48987
- if (existsSync8(path7)) files.push({ path: path7, bytes: statSync4(path7).size });
49057
+ if (existsSync9(path7)) files.push({ path: path7, bytes: statSync4(path7).size });
48988
49058
  }
48989
- return files.length > 0 && !existsSync8(dbPath) ? files : [];
49059
+ return files.length > 0 && !existsSync9(dbPath) ? files : [];
48990
49060
  }
48991
49061
  async function checkDb(project) {
48992
49062
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
48993
49063
  const orphan = orphanFiles(project.dbPath);
48994
49064
  if (orphan.length > 0) return { row: fail2(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
48995
- if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
49065
+ if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
48996
49066
  const sqlite = await loadSqlite2();
48997
49067
  if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
48998
49068
  let raw = null;
@@ -49018,7 +49088,7 @@ async function checkDb(project) {
49018
49088
  }
49019
49089
  }
49020
49090
  async function checkIndex(project) {
49021
- if (!existsSync8(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
49091
+ if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
49022
49092
  const sqlite = await loadSqlite2();
49023
49093
  if (sqlite === null) return unknown4("D9", D2_SQLITE_DETAIL);
49024
49094
  let raw = null;
@@ -49035,8 +49105,8 @@ async function checkIndex(project) {
49035
49105
  }
49036
49106
 
49037
49107
  // src/core/ops/doctor-env.ts
49038
- import { existsSync as existsSync9, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
49039
- import { isAbsolute as isAbsolute2, join as join10, relative } from "node:path";
49108
+ import { existsSync as existsSync10, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
49109
+ import { isAbsolute as isAbsolute2, join as join11, relative } from "node:path";
49040
49110
  function pass3(id, detail = DOCTOR_PASS_DETAIL) {
49041
49111
  return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
49042
49112
  }
@@ -49048,7 +49118,7 @@ function fail3(id, detail, fixCommand) {
49048
49118
  }
49049
49119
  function bundleVersion(bundleDir2) {
49050
49120
  try {
49051
- const v = JSON.parse(readFileSync7(join10(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
49121
+ const v = JSON.parse(readFileSync7(join11(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
49052
49122
  return typeof v === "string" && v !== "" ? v : void 0;
49053
49123
  } catch {
49054
49124
  return void 0;
@@ -49198,7 +49268,7 @@ function checkMcp(ctx) {
49198
49268
  return named2 || versioned ? pass3("D6") : unknown5("D6", D6_UNKNOWN_DETAIL);
49199
49269
  }
49200
49270
  function piCwdInside(worktree, piCwd) {
49201
- if (piCwd === void 0 || !existsSync9(piCwd)) return false;
49271
+ if (piCwd === void 0 || !existsSync10(piCwd)) return false;
49202
49272
  const rel = relative(worktree, realpathSync5.native(piCwd));
49203
49273
  return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
49204
49274
  }
@@ -49219,13 +49289,13 @@ function checkShell(env) {
49219
49289
  }
49220
49290
 
49221
49291
  // src/core/ops/doctor-hook.ts
49222
- import { existsSync as existsSync11, mkdtempSync, readFileSync as readFileSync8, realpathSync as realpathSync7, rmSync as rmSync4 } from "node:fs";
49292
+ import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync8, realpathSync as realpathSync7, rmSync as rmSync4 } from "node:fs";
49223
49293
  import { tmpdir as tmpdir2 } from "node:os";
49224
49294
  import path6 from "node:path";
49225
49295
 
49226
49296
  // src/setup/codex-trust.ts
49227
49297
  import { createHash } from "node:crypto";
49228
- import { existsSync as existsSync10, realpathSync as realpathSync6 } from "node:fs";
49298
+ import { existsSync as existsSync11, realpathSync as realpathSync6 } from "node:fs";
49229
49299
  import path5 from "node:path";
49230
49300
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
49231
49301
 
@@ -49323,6 +49393,7 @@ var LIST_TIMEOUT_MS = 15e3;
49323
49393
  var EXIT_GRACE_MS = 5e3;
49324
49394
  var PLUGIN_SOURCE = "plugin";
49325
49395
  var TRUSTED = "trusted";
49396
+ var UNTRUSTED = "untrusted";
49326
49397
  function pluginHooksFromReply(m, pluginId) {
49327
49398
  const out = [];
49328
49399
  if (!isObj2(m) || !isObj2(m.result) || !Array.isArray(m.result.data)) return out;
@@ -49332,7 +49403,8 @@ function pluginHooksFromReply(m, pluginId) {
49332
49403
  if (!isObj2(h) || h.source !== PLUGIN_SOURCE || h.pluginId !== pluginId) continue;
49333
49404
  if (typeof h.key !== "string" || typeof h.currentHash !== "string") continue;
49334
49405
  if (out.some((x) => x.key === h.key)) continue;
49335
- out.push({ key: h.key, hash: h.currentHash, trusted: h.trustStatus === TRUSTED });
49406
+ const status = typeof h.trustStatus === "string" ? h.trustStatus : UNTRUSTED;
49407
+ out.push({ key: h.key, hash: h.currentHash, trusted: status === TRUSTED, status });
49336
49408
  }
49337
49409
  }
49338
49410
  return out;
@@ -49425,7 +49497,11 @@ var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
49425
49497
  function untrustedPluginHooksDetail(hooks) {
49426
49498
  const bad = hooks.filter((h) => !h.trusted);
49427
49499
  if (!bad.length) return void 0;
49428
- return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
49500
+ const counts = /* @__PURE__ */ new Map();
49501
+ for (const h of bad) counts.set(h.status, (counts.get(h.status) ?? 0) + 1);
49502
+ const words = [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1));
49503
+ const state = words.length === 1 ? words[0][0] : `${words.map(([w]) => w).join(" or ")} (${words.map(([w, n]) => `${n} ${w}`).join(", ")})`;
49504
+ return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks ${state}, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
49429
49505
  }
49430
49506
 
49431
49507
  // src/core/ops/doctor-hook.ts
@@ -49442,7 +49518,7 @@ function isObject5(v) {
49442
49518
  }
49443
49519
  function loadFixture(bundleDir2, agent) {
49444
49520
  const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
49445
- if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
49521
+ if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
49446
49522
  let all;
49447
49523
  try {
49448
49524
  all = JSON.parse(hostText(readFileSync8(file2, "utf8")));
@@ -49581,7 +49657,7 @@ async function checkHookRoundTrip(i) {
49581
49657
  const trust = await codexPluginTrust(i);
49582
49658
  if (trust !== null) return trust;
49583
49659
  }
49584
- if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
49660
+ if (i.agent === "codex" && existsSync12(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
49585
49661
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
49586
49662
  }
49587
49663
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -49620,14 +49696,14 @@ async function checkHookRoundTrip(i) {
49620
49696
  }
49621
49697
 
49622
49698
  // src/core/hooks/fallback.ts
49623
- import { join as join11, resolve as resolve3 } from "node:path";
49699
+ import { join as join12, resolve as resolve3 } from "node:path";
49624
49700
  var fs = process.getBuiltinModule("node:fs");
49625
49701
  function homeOf(env) {
49626
49702
  return env.HOME ?? env.USERPROFILE ?? "";
49627
49703
  }
49628
49704
  function hookLogPath(env) {
49629
49705
  const home = homeOf(env);
49630
- return home === "" ? "" : join11(home, DATA_ROOT.slice(1), HOOK_ERROR_LOG_FILE);
49706
+ return home === "" ? "" : join12(home, DATA_ROOT.slice(1), HOOK_ERROR_LOG_FILE);
49631
49707
  }
49632
49708
  function lastHookError(env) {
49633
49709
  try {
@@ -49657,8 +49733,8 @@ function lastHookError(env) {
49657
49733
  }
49658
49734
 
49659
49735
  // src/core/ops/db-heal.ts
49660
- import { existsSync as existsSync12, mkdirSync as mkdirSync5, rmSync as rmSync5 } from "node:fs";
49661
- import { basename as basename4, dirname as dirname6, join as join12 } from "node:path";
49736
+ import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync5 } from "node:fs";
49737
+ import { basename as basename4, dirname as dirname7, join as join13 } from "node:path";
49662
49738
  function integrityOk2(rows) {
49663
49739
  return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
49664
49740
  }
@@ -49692,7 +49768,7 @@ function renameAside(dbPath) {
49692
49768
  const ts = String(Date.now());
49693
49769
  for (const suffix of DB_SIBLING_SUFFIXES) {
49694
49770
  const file2 = dbPath + suffix;
49695
- if (existsSync12(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
49771
+ if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
49696
49772
  }
49697
49773
  return ts;
49698
49774
  }
@@ -49715,7 +49791,7 @@ function utcStamp(now) {
49715
49791
  return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
49716
49792
  }
49717
49793
  function makeOrphanDir(projectDir) {
49718
- const base = join12(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
49794
+ const base = join13(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
49719
49795
  for (let n = 1; ; n += 1) {
49720
49796
  const dir = n === 1 ? base : base + "-" + String(n);
49721
49797
  try {
@@ -49730,9 +49806,9 @@ async function healOrphan(project, files, row5) {
49730
49806
  const moved = [];
49731
49807
  let dir = "";
49732
49808
  try {
49733
- dir = makeOrphanDir(dirname6(project.dbPath));
49809
+ dir = makeOrphanDir(dirname7(project.dbPath));
49734
49810
  for (const f of files) {
49735
- const to = join12(dir, basename4(f.path));
49811
+ const to = join13(dir, basename4(f.path));
49736
49812
  renameWithRetry(f.path, to);
49737
49813
  moved.push({ path: to, bytes: f.bytes });
49738
49814
  }
@@ -49799,8 +49875,8 @@ function buildReportHead(input) {
49799
49875
 
49800
49876
  // src/core/ops/doctor-issue.ts
49801
49877
  import { spawnSync as spawnSync3 } from "node:child_process";
49802
- import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync9, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
49803
- import { delimiter, join as join13 } from "node:path";
49878
+ import { closeSync, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync9, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
49879
+ import { delimiter, join as join14 } from "node:path";
49804
49880
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
49805
49881
  function tildeOf(env) {
49806
49882
  const home = homeDirOf(env);
@@ -49841,8 +49917,8 @@ function onPath(env, tool) {
49841
49917
  const out = [];
49842
49918
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
49843
49919
  if (dir === "") continue;
49844
- for (const n of names) if (existsSync13(join13(dir, n))) {
49845
- out.push(join13(dir, n));
49920
+ for (const n of names) if (existsSync14(join14(dir, n))) {
49921
+ out.push(join14(dir, n));
49846
49922
  break;
49847
49923
  }
49848
49924
  }
@@ -49850,7 +49926,7 @@ function onPath(env, tool) {
49850
49926
  }
49851
49927
  function hookLogTail(env) {
49852
49928
  const file2 = hookLogPath(env);
49853
- if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
49929
+ if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
49854
49930
  try {
49855
49931
  const fd = openSync(file2, "r");
49856
49932
  try {
@@ -49870,7 +49946,7 @@ function hookLogTail(env) {
49870
49946
  }
49871
49947
  async function journalRows(ctx) {
49872
49948
  const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
49873
- if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
49949
+ if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
49874
49950
  try {
49875
49951
  const db = await openDb(ctx.project, { readOnly: true });
49876
49952
  try {
@@ -49888,15 +49964,15 @@ function agentConfig(adapter, env, worktree) {
49888
49964
  const home = homeDirOf(env);
49889
49965
  const files = configPaths(adapter, env, worktree);
49890
49966
  if (home !== null) {
49891
- if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join13(claudeDirOf(env, home), SETTINGS_FILE) });
49892
- if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join13(codexDirOf(env, home), CONFIG_TOML_FILE) });
49967
+ if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join14(claudeDirOf(env, home), SETTINGS_FILE) });
49968
+ if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join14(codexDirOf(env, home), CONFIG_TOML_FILE) });
49893
49969
  }
49894
49970
  const out = [];
49895
49971
  const seen = /* @__PURE__ */ new Set();
49896
49972
  for (const f of files) {
49897
49973
  if (seen.has(f.path)) continue;
49898
49974
  seen.add(f.path);
49899
- if (!existsSync13(f.path)) {
49975
+ if (!existsSync14(f.path)) {
49900
49976
  out.push(`${f.label}: ${f.path} (absent)`);
49901
49977
  continue;
49902
49978
  }
@@ -49972,14 +50048,14 @@ async function buildIssueBody(i) {
49972
50048
  async function writeIssueReport(i) {
49973
50049
  const tilde = tildeOf(i.env);
49974
50050
  const body = await buildIssueBody(i);
49975
- const dir = join13(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
50051
+ const dir = join14(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
49976
50052
  mkdirSync6(dir, { recursive: true });
49977
- const file2 = join13(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
50053
+ const file2 = join14(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
49978
50054
  writeFileSync3(file2, body);
49979
50055
  const shown2 = tilde(file2);
49980
50056
  const title = issueTitle(i.adapter.id, i.rows);
49981
50057
  const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
49982
- 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))];
50058
+ 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];
49983
50059
  }
49984
50060
  function formUrl(title, summary) {
49985
50061
  const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
@@ -50020,7 +50096,7 @@ async function guard(id, run) {
50020
50096
  }
50021
50097
  }
50022
50098
  async function codexDb(ctx, adapter) {
50023
- if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
50099
+ if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
50024
50100
  try {
50025
50101
  return await openDb(ctx.project, { readOnly: true });
50026
50102
  } catch {
@@ -50050,11 +50126,11 @@ async function hookRow(ctx, adapter, host) {
50050
50126
  }
50051
50127
  }
50052
50128
  function ownServerId(configDir, projectKey) {
50053
- const dir = join14(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
50054
- if (!existsSync14(dir)) return "";
50129
+ const dir = join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
50130
+ if (!existsSync15(dir)) return "";
50055
50131
  for (const name of readdirSync7(dir)) {
50056
50132
  if (!name.endsWith(OWNER_PID_EXT)) continue;
50057
- if (readFileSync10(join14(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
50133
+ if (readFileSync10(join15(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
50058
50134
  }
50059
50135
  return "";
50060
50136
  }
@@ -50137,7 +50213,7 @@ async function doctorReply(ctx, host) {
50137
50213
  return { text, isError: false, sandboxBytes: bytes5 };
50138
50214
  }
50139
50215
  async function handler2(_input, ctx) {
50140
- return doctorReply(ctx, { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 });
50216
+ return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: void 0 });
50141
50217
  }
50142
50218
  var ctxDoctor = Object.freeze({
50143
50219
  name: "ctx_doctor",
@@ -50149,9 +50225,9 @@ var ctxDoctor = Object.freeze({
50149
50225
  });
50150
50226
 
50151
50227
  // src/core/tools/execute.ts
50152
- import { existsSync as existsSync15, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
50228
+ import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
50153
50229
  import { tmpdir as tmpdir3 } from "node:os";
50154
- import { dirname as dirname8, join as join15, parse as parse5, resolve as resolve4 } from "node:path";
50230
+ import { dirname as dirname9, join as join16, parse as parse5, resolve as resolve4 } from "node:path";
50155
50231
 
50156
50232
  // src/core/index/select.ts
50157
50233
  var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
@@ -50274,7 +50350,7 @@ function schemaLine(issue4) {
50274
50350
  }
50275
50351
  function fileError(given, abs, root) {
50276
50352
  let dir = abs;
50277
- while (!existsSync15(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
50353
+ while (!existsSync16(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
50278
50354
  if (isInside(root, dir)) return null;
50279
50355
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
50280
50356
  }
@@ -50355,8 +50431,8 @@ async function handler3(raw, ctx) {
50355
50431
  if (takesDashC(input.language, runtime)) {
50356
50432
  argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
50357
50433
  } else {
50358
- tmpDir = mkdtempSync2(join15(tmpdir3(), TMP_PREFIX));
50359
- const file2 = join15(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
50434
+ tmpDir = mkdtempSync2(join16(tmpdir3(), TMP_PREFIX));
50435
+ const file2 = join16(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
50360
50436
  writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
50361
50437
  argv = scriptArgv(input.language, runtime, file2);
50362
50438
  }
@@ -50391,12 +50467,12 @@ var ctxExecute = {
50391
50467
  };
50392
50468
 
50393
50469
  // src/core/tools/index.ts
50394
- import { existsSync as existsSync16, readFileSync as readFileSync12, statSync as statSync7 } from "node:fs";
50395
- import { dirname as dirname9, extname, join as join17, relative as relative2, resolve as resolve5 } from "node:path";
50470
+ import { existsSync as existsSync17, readFileSync as readFileSync12, statSync as statSync7 } from "node:fs";
50471
+ import { dirname as dirname10, extname, join as join18, relative as relative2, resolve as resolve5 } from "node:path";
50396
50472
 
50397
50473
  // src/core/index/walk.ts
50398
50474
  import { readdirSync as readdirSync8, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync6 } from "node:fs";
50399
- import { join as join16 } from "node:path";
50475
+ import { join as join17 } from "node:path";
50400
50476
  var GITIGNORE = ".gitignore";
50401
50477
  var GIT_DIR = ".git";
50402
50478
  function walkDir(root, containmentRoot) {
@@ -50405,7 +50481,7 @@ function walkDir(root, containmentRoot) {
50405
50481
  const found = [];
50406
50482
  visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
50407
50483
  found.sort(compareFound);
50408
- return found.map((f) => ({ absPath: f.absPath, relPath: join16(...f.dir, f.name) }));
50484
+ return found.map((f) => ({ absPath: f.absPath, relPath: join17(...f.dir, f.name) }));
50409
50485
  }
50410
50486
  function visit(abs, rel, parent, contain, seen, found) {
50411
50487
  let entries;
@@ -50414,10 +50490,10 @@ function visit(abs, rel, parent, contain, seen, found) {
50414
50490
  } catch {
50415
50491
  return;
50416
50492
  }
50417
- const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join16(abs, GITIGNORE), rel)) : parent;
50493
+ const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join17(abs, GITIGNORE), rel)) : parent;
50418
50494
  for (const e of entries) {
50419
50495
  if (e.name === GIT_DIR) continue;
50420
- const path7 = join16(abs, e.name);
50496
+ const path7 = join17(abs, e.name);
50421
50497
  let isDir = e.isDirectory();
50422
50498
  let isFile = e.isFile();
50423
50499
  let target = path7;
@@ -54547,7 +54623,7 @@ function readUtf8(absPath) {
54547
54623
  }
54548
54624
  function missingOrOutside(given, abs, root) {
54549
54625
  let dir = abs;
54550
- while (!existsSync16(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
54626
+ while (!existsSync17(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
54551
54627
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
54552
54628
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
54553
54629
  }
@@ -54558,7 +54634,7 @@ function pathItems(input, project) {
54558
54634
  if (statSync7(abs).isDirectory()) {
54559
54635
  return walkDir(abs, project.containmentRoot).map((f) => ({
54560
54636
  sourceKind: "path",
54561
- label: pathLabel(join17(base, f.relPath)),
54637
+ label: pathLabel(join18(base, f.relPath)),
54562
54638
  kind: kindOfPath(f.relPath),
54563
54639
  read: () => readUtf8(f.absPath)
54564
54640
  }));
@@ -55363,12 +55439,12 @@ var ctxStats = Object.freeze({
55363
55439
  });
55364
55440
 
55365
55441
  // src/core/tools/upgrade.ts
55366
- import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync11 } from "node:fs";
55367
- import { basename as basename7, dirname as dirname11, join as join23 } from "node:path";
55442
+ import { existsSync as existsSync23, realpathSync as realpathSync10, rmSync as rmSync11 } from "node:fs";
55443
+ import { basename as basename7, dirname as dirname12, join as join24 } from "node:path";
55368
55444
 
55369
55445
  // src/core/ops/host-write.ts
55370
- import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
55371
- import { dirname as dirname10, join as join18 } from "node:path";
55446
+ import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
55447
+ import { dirname as dirname11, join as join19 } from "node:path";
55372
55448
  function defaultWrite(file2, text) {
55373
55449
  writeFileSync5(file2, text, "utf8");
55374
55450
  }
@@ -55377,14 +55453,14 @@ function hostConfigPath(agent, home, env) {
55377
55453
  if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
55378
55454
  switch (agent) {
55379
55455
  case "opencode":
55380
- return join18(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
55456
+ return join19(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
55381
55457
  // D-WIN-OPENCODE-DIR-1
55382
55458
  case "pi":
55383
- return join18(piAgentDirOf(env, home), SETTINGS_FILE);
55459
+ return join19(piAgentDirOf(env, home), SETTINGS_FILE);
55384
55460
  case "copilot-cli":
55385
55461
  return null;
55386
55462
  default:
55387
- return join18(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
55463
+ return join19(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
55388
55464
  }
55389
55465
  }
55390
55466
  function cell3(value) {
@@ -55396,8 +55472,8 @@ function toRow(file2, edit) {
55396
55472
  function writeWithRollback(file2, text, write, atomic) {
55397
55473
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
55398
55474
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
55399
- const had = existsSync17(file2);
55400
- mkdirSync7(dirname10(file2), { recursive: true });
55475
+ const had = existsSync18(file2);
55476
+ mkdirSync7(dirname11(file2), { recursive: true });
55401
55477
  if (had) copyFileSync(file2, trash);
55402
55478
  try {
55403
55479
  write(tmp, text);
@@ -55426,7 +55502,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
55426
55502
  if (requested === null) return [];
55427
55503
  const current = readHostConfig(row5.id, requested);
55428
55504
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
55429
- const exists = existsSync17(current.path);
55505
+ const exists = existsSync18(current.path);
55430
55506
  if (exists && result.text === current.text) return [];
55431
55507
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
55432
55508
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -55434,8 +55510,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
55434
55510
  }
55435
55511
 
55436
55512
  // src/core/ops/plugin-swap.ts
55437
- import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync9, readlinkSync, rmSync as rmSync7, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
55438
- import { basename as basename6, join as join19, win32 as win322 } from "node:path";
55513
+ import { existsSync as existsSync19, lstatSync, readdirSync as readdirSync9, readlinkSync, rmSync as rmSync7, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
55514
+ import { basename as basename6, join as join20, win32 as win322 } from "node:path";
55439
55515
  function linkTarget(path7, win) {
55440
55516
  if (!isLink(path7)) return null;
55441
55517
  const target = readlinkSync(path7);
@@ -55454,11 +55530,11 @@ function settleLinks(link, tmp, old, opts) {
55454
55530
  else renameWithRetry(old, link, opts);
55455
55531
  }
55456
55532
  function swapPluginCurrent(agentDir, sha, opts = {}) {
55457
- const next = join19(agentDir, sha);
55458
- if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
55533
+ const next = join20(agentDir, sha);
55534
+ if (!existsSync19(next) || !lstatSync(next).isDirectory()) {
55459
55535
  throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
55460
55536
  }
55461
- const link = join19(agentDir, PLUGIN_CURRENT_LINK);
55537
+ const link = join20(agentDir, PLUGIN_CURRENT_LINK);
55462
55538
  const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
55463
55539
  const old = link + PLUGIN_LINK_OLD_SUFFIX;
55464
55540
  settleLinks(link, tmp, old, opts);
@@ -55473,15 +55549,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
55473
55549
  if (before !== null) unlinkSync2(old);
55474
55550
  const keep = /* @__PURE__ */ new Set([sha]);
55475
55551
  if (before !== null) keep.add(before);
55476
- const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join19(agentDir, name));
55552
+ const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join20(agentDir, name));
55477
55553
  for (const dir of removed) rmSync7(dir, { recursive: true, force: true });
55478
- const previous = before !== null && existsSync18(join19(agentDir, before)) ? join19(agentDir, before) : null;
55554
+ const previous = before !== null && existsSync19(join20(agentDir, before)) ? join20(agentDir, before) : null;
55479
55555
  return { current: next, previous, removed };
55480
55556
  }
55481
55557
 
55482
55558
  // src/core/ops/release-fetch.ts
55483
- import { existsSync as existsSync19, mkdirSync as mkdirSync8, rmSync as rmSync8 } from "node:fs";
55484
- import { join as join20 } from "node:path";
55559
+ import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync8 } from "node:fs";
55560
+ import { join as join21 } from "node:path";
55485
55561
  function failed(r) {
55486
55562
  if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
55487
55563
  const status = r.killed ?? String(r.exitCode);
@@ -55493,9 +55569,9 @@ async function git2(bin, args, cwd, env, signal) {
55493
55569
  return r.stdout.toString().trim();
55494
55570
  }
55495
55571
  async function fetchRelease(agent, url4, env, signal, opts = {}) {
55496
- const agentDir = join20(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
55572
+ const agentDir = join21(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
55497
55573
  mkdirSync8(agentDir, { recursive: true });
55498
- const fetchDir = join20(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
55574
+ const fetchDir = join21(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
55499
55575
  rmSync8(fetchDir, { recursive: true, force: true });
55500
55576
  const gitBin = findRuntime(GIT_BIN, env);
55501
55577
  if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
@@ -55503,8 +55579,8 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
55503
55579
  try {
55504
55580
  await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
55505
55581
  const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
55506
- const dir = join20(agentDir, sha);
55507
- if (existsSync19(dir)) rmSync8(fetchDir, { recursive: true, force: true });
55582
+ const dir = join21(agentDir, sha);
55583
+ if (existsSync20(dir)) rmSync8(fetchDir, { recursive: true, force: true });
55508
55584
  else renameWithRetry(fetchDir, dir, opts);
55509
55585
  return { sha, dir };
55510
55586
  } catch (e) {
@@ -55514,15 +55590,15 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
55514
55590
  }
55515
55591
 
55516
55592
  // src/core/ops/uninstall.ts
55517
- import { existsSync as existsSync20, readdirSync as readdirSync10, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
55518
- import { join as join21 } from "node:path";
55593
+ import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
55594
+ import { join as join22 } from "node:path";
55519
55595
  function row2(area, before, after) {
55520
55596
  return { area, before, after };
55521
55597
  }
55522
55598
  function stopServers(configDir, projectKey) {
55523
55599
  const stopped = listLiveOwners(configDir, projectKey);
55524
- const dir = join21(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
55525
- for (const serverId of stopped) writeFileSync6(join21(dir, serverId + OWNER_STOP_EXT), "", "utf8");
55600
+ const dir = join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
55601
+ for (const serverId of stopped) writeFileSync6(join22(dir, serverId + OWNER_STOP_EXT), "", "utf8");
55526
55602
  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 };
55527
55603
  }
55528
55604
  function rootOrNull(adapter, env) {
@@ -55540,15 +55616,15 @@ function removeCache(adapter, env, configDir) {
55540
55616
  const root = rootOrNull(adapter, env);
55541
55617
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
55542
55618
  if (adapter.installMode === "marketplace") {
55543
- const cache = join21(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
55619
+ const cache = join22(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
55544
55620
  if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
55545
55621
  }
55546
55622
  rmSync9(root, { recursive: true, force: true });
55547
55623
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
55548
55624
  }
55549
55625
  case "plugin": {
55550
- const agentDir = join21(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
55551
- if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
55626
+ const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
55627
+ if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
55552
55628
  rmSync9(agentDir, { recursive: true, force: true });
55553
55629
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
55554
55630
  }
@@ -55593,7 +55669,7 @@ function ownEntries(agent, env) {
55593
55669
  }
55594
55670
  if (agent === "opencode") {
55595
55671
  return [{
55596
- file: join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
55672
+ file: join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
55597
55673
  // D-WIN-OPENCODE-DIR-1
55598
55674
  key: OPENCODE_PLUGIN_KEY,
55599
55675
  shown: OPENCODE_PLUGIN_KEY,
@@ -55604,7 +55680,7 @@ function ownEntries(agent, env) {
55604
55680
  if (agent === "pi") {
55605
55681
  const agentDir = piAgentDirOf(env, home);
55606
55682
  return [{
55607
- file: join21(agentDir, SETTINGS_FILE),
55683
+ file: join22(agentDir, SETTINGS_FILE),
55608
55684
  key: PI_PACKAGES_KEY,
55609
55685
  shown: PI_PACKAGES_KEY,
55610
55686
  has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
@@ -55626,12 +55702,12 @@ function removeOwnEntries(agent, env) {
55626
55702
  return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
55627
55703
  }
55628
55704
  function removeProjectData(configDir, projectKey) {
55629
- const projects = join21(configDir, PROJECTS_DIR_NAME);
55630
- const dir = join21(projects, projectKey);
55631
- if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
55705
+ const projects = join22(configDir, PROJECTS_DIR_NAME);
55706
+ const dir = join22(projects, projectKey);
55707
+ if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
55632
55708
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
55633
55709
  for (const name of readdirSync10(dir)) {
55634
- if (name !== OWNERS_DIR_NAME) rmSync9(join21(dir, name), { recursive: true, force: true });
55710
+ if (name !== OWNERS_DIR_NAME) rmSync9(join22(dir, name), { recursive: true, force: true });
55635
55711
  }
55636
55712
  return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
55637
55713
  }
@@ -55639,12 +55715,12 @@ function runUninstall(input) {
55639
55715
  const configDir = resolveConfigDir(input.env);
55640
55716
  const stop = stopServers(configDir, input.project.projectKey);
55641
55717
  const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
55642
- rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join21(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
55718
+ rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join22(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
55643
55719
  return { rows, stopped: stop.stopped };
55644
55720
  }
55645
55721
 
55646
55722
  // src/core/ops/v1-remove.ts
55647
- import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync13, rmSync as rmSync10 } from "node:fs";
55723
+ import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync13, rmSync as rmSync10 } from "node:fs";
55648
55724
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
55649
55725
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
55650
55726
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -55725,14 +55801,14 @@ function removeV1(agent, findings) {
55725
55801
  for (const f of findings) {
55726
55802
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
55727
55803
  else if (f.path === "") {
55728
- if (existsSync21(f.file)) {
55804
+ if (existsSync22(f.file)) {
55729
55805
  moveAside(f.file, undo);
55730
55806
  done.set(f, UPGRADE_REMOVED);
55731
55807
  } else done.set(f, UPGRADE_NOT_FOUND);
55732
55808
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
55733
55809
  }
55734
55810
  for (const [file2, list3] of entries) {
55735
- if (!existsSync21(file2)) {
55811
+ if (!existsSync22(file2)) {
55736
55812
  for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
55737
55813
  continue;
55738
55814
  }
@@ -55765,7 +55841,7 @@ function removeV1(agent, findings) {
55765
55841
  },
55766
55842
  rollback() {
55767
55843
  for (const u of undo.splice(0).reverse()) {
55768
- if (!existsSync21(u.trash)) continue;
55844
+ if (!existsSync22(u.trash)) continue;
55769
55845
  rmSync10(u.target, { recursive: true, force: true });
55770
55846
  renameWithRetry(u.trash, u.target);
55771
55847
  }
@@ -55776,7 +55852,7 @@ function removeV1(agent, findings) {
55776
55852
  // src/core/ops/verify-sums.ts
55777
55853
  import { createHash as createHash2 } from "node:crypto";
55778
55854
  import { lstatSync as lstatSync2, readdirSync as readdirSync11, readFileSync as readFileSync14 } from "node:fs";
55779
- import { join as join22 } from "node:path";
55855
+ import { join as join23 } from "node:path";
55780
55856
  function mismatch() {
55781
55857
  return new CtxError("BUNDLE_HASH_MISMATCH");
55782
55858
  }
@@ -55797,14 +55873,14 @@ function walk2(dir, prefix, out) {
55797
55873
  for (const entry of readdirSync11(dir, { withFileTypes: true })) {
55798
55874
  const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
55799
55875
  if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
55800
- const abs = join22(dir, entry.name);
55876
+ const abs = join23(dir, entry.name);
55801
55877
  if (entry.isDirectory()) walk2(abs, rel, out);
55802
55878
  else if (entry.isFile()) out.set(rel, abs);
55803
55879
  else throw mismatch();
55804
55880
  }
55805
55881
  }
55806
55882
  function verifySums(dir) {
55807
- const sumsPath = join22(dir, RELEASE_SUMS_FILE);
55883
+ const sumsPath = join23(dir, RELEASE_SUMS_FILE);
55808
55884
  const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
55809
55885
  if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
55810
55886
  const sums = parseSums(readFileSync14(sumsPath, "utf8"));
@@ -55828,7 +55904,7 @@ function row4(area, before, after) {
55828
55904
  return { area, before, after };
55829
55905
  }
55830
55906
  function bundleDir() {
55831
- return dirname11(process.argv[1] ?? "");
55907
+ return ownBundleDir();
55832
55908
  }
55833
55909
  function pluginRootRow(adapter, env) {
55834
55910
  const own4 = bundleDir();
@@ -55842,12 +55918,12 @@ function pluginRootRow(adapter, env) {
55842
55918
  return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
55843
55919
  }
55844
55920
  function isCurrent(agentDir, dir) {
55845
- const link = join23(agentDir, PLUGIN_CURRENT_LINK);
55846
- return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
55921
+ const link = join24(agentDir, PLUGIN_CURRENT_LINK);
55922
+ return existsSync23(link) && realpathSync10.native(link) === realpathSync10.native(dir);
55847
55923
  }
55848
55924
  async function checkout(adapter, deps) {
55849
55925
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
55850
- const agentDir = dirname11(fetched.dir);
55926
+ const agentDir = dirname12(fetched.dir);
55851
55927
  try {
55852
55928
  verifySums(fetched.dir);
55853
55929
  } catch (err) {
@@ -56036,7 +56112,7 @@ function workspaceFromMeta(meta3) {
56036
56112
  if (typeof cwd !== "string" || cwd === "") return void 0;
56037
56113
  if (!cwd.startsWith(FILE_URL_PREFIX)) return cwd;
56038
56114
  try {
56039
- return fileURLToPath2(cwd);
56115
+ return fileURLToPath3(cwd);
56040
56116
  } catch {
56041
56117
  return void 0;
56042
56118
  }
@@ -56052,7 +56128,7 @@ function workspaceCwdOf(meta3, spawnCwd, script) {
56052
56128
  const fromHost = workspaceFromMeta(meta3);
56053
56129
  if (fromHost !== void 0) return fromHost;
56054
56130
  if (script === void 0 || script === "") return spawnCwd;
56055
- return realOrSame(spawnCwd) === realOrSame(dirname12(script)) ? "" : spawnCwd;
56131
+ return realOrSame(spawnCwd) === realOrSame(dirname13(script)) ? "" : spawnCwd;
56056
56132
  }
56057
56133
  function errorReply(err) {
56058
56134
  if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
@@ -56091,15 +56167,15 @@ async function startServer(argv, env) {
56091
56167
  opening.catch(() => pending.delete(project.dbPath));
56092
56168
  }
56093
56169
  const db = await opening;
56094
- if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
56170
+ if (!existsSync24(db.path)) throw new CtxError("DB_GONE");
56095
56171
  return db;
56096
56172
  }
56097
56173
  function stopMarker(configDir, projectKey) {
56098
- return join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
56174
+ return join25(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
56099
56175
  }
56100
56176
  function stopRequested() {
56101
56177
  const configDir = resolveConfigDir(process.env);
56102
- return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
56178
+ return held.some((db) => existsSync24(stopMarker(configDir, db.projectKey)));
56103
56179
  }
56104
56180
  async function journal(project, ctx, name, reply4) {
56105
56181
  const db = await ownDb(project);
@@ -56208,7 +56284,7 @@ async function startServer(argv, env) {
56208
56284
  handle = serveStdio(createServer);
56209
56285
  await new Promise((resolve6) => process.once("exit", () => resolve6()));
56210
56286
  }
56211
- if (isEntry(import.meta.main, process.argv[1], fileURLToPath2(import.meta.url))) {
56287
+ if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url))) {
56212
56288
  const [, , ...cliArgs] = process.argv;
56213
56289
  await startServer(cliArgs, process.env);
56214
56290
  }