context-mode 2.0.0-next.24 → 2.0.0-next.26

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,8 +7,8 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/entries/server.ts
9
9
  import { randomUUID } from "node:crypto";
10
- import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync11 } from "node:fs";
11
- import { dirname as dirname10, join as join21 } from "node:path";
10
+ import { existsSync as existsSync22, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
11
+ import { dirname as dirname11, join as join21 } from "node:path";
12
12
  import { fileURLToPath as fileURLToPath2 } from "node:url";
13
13
 
14
14
  // node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
@@ -3487,7 +3487,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
3487
3487
  var NONE = 0;
3488
3488
  var ASSUMED = 1;
3489
3489
  var PROVEN = 2;
3490
- function isRecursive(inst, stack, resolve5) {
3490
+ function isRecursive(inst, stack, resolve6) {
3491
3491
  const cached4 = recursive.get(inst);
3492
3492
  if (cached4 !== void 0)
3493
3493
  return cached4 ? PROVEN : NONE;
@@ -3497,7 +3497,7 @@ function isRecursive(inst, stack, resolve5) {
3497
3497
  let result = NONE;
3498
3498
  const check2 = (child) => {
3499
3499
  if (result !== PROVEN && child?._zod) {
3500
- const answer2 = isRecursive(child, stack, resolve5);
3500
+ const answer2 = isRecursive(child, stack, resolve6);
3501
3501
  if (answer2 > result)
3502
3502
  result = answer2;
3503
3503
  }
@@ -3508,7 +3508,7 @@ function isRecursive(inst, stack, resolve5) {
3508
3508
  const desc = Object.getOwnPropertyDescriptor(sh, key);
3509
3509
  if (spread && !desc.enumerable)
3510
3510
  continue;
3511
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve5) : NONE;
3511
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve6) : NONE;
3512
3512
  if (child > answer2)
3513
3513
  answer2 = child;
3514
3514
  }
@@ -3572,7 +3572,7 @@ function isRecursive(inst, stack, resolve5) {
3572
3572
  break;
3573
3573
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
3574
3574
  case "lazy": {
3575
- const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
3575
+ const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
3576
3576
  merge5(inner ? isRecursive(inner, stack, false) : ASSUMED);
3577
3577
  break;
3578
3578
  }
@@ -11016,7 +11016,7 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
11016
11016
  var NONE2 = 0;
11017
11017
  var ASSUMED2 = 1;
11018
11018
  var PROVEN2 = 2;
11019
- function isRecursive2(inst, stack, resolve5) {
11019
+ function isRecursive2(inst, stack, resolve6) {
11020
11020
  const cached4 = recursive2.get(inst);
11021
11021
  if (cached4 !== void 0)
11022
11022
  return cached4 ? PROVEN2 : NONE2;
@@ -11026,7 +11026,7 @@ function isRecursive2(inst, stack, resolve5) {
11026
11026
  let result = NONE2;
11027
11027
  const check2 = (child) => {
11028
11028
  if (result !== PROVEN2 && child?._zod) {
11029
- const answer2 = isRecursive2(child, stack, resolve5);
11029
+ const answer2 = isRecursive2(child, stack, resolve6);
11030
11030
  if (answer2 > result)
11031
11031
  result = answer2;
11032
11032
  }
@@ -11037,7 +11037,7 @@ function isRecursive2(inst, stack, resolve5) {
11037
11037
  const desc = Object.getOwnPropertyDescriptor(sh, key);
11038
11038
  if (spread && !desc.enumerable)
11039
11039
  continue;
11040
- const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve5) : NONE2;
11040
+ const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve6) : NONE2;
11041
11041
  if (child > answer2)
11042
11042
  answer2 = child;
11043
11043
  }
@@ -11101,7 +11101,7 @@ function isRecursive2(inst, stack, resolve5) {
11101
11101
  break;
11102
11102
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
11103
11103
  case "lazy": {
11104
- const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
11104
+ const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
11105
11105
  merge5(inner ? isRecursive2(inner, stack, false) : ASSUMED2);
11106
11106
  break;
11107
11107
  }
@@ -17705,14 +17705,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
17705
17705
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
17706
17706
  }
17707
17707
  function sleep(ms, signal) {
17708
- return new Promise((resolve5, reject) => {
17708
+ return new Promise((resolve6, reject) => {
17709
17709
  if (signal?.aborted) {
17710
17710
  reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
17711
17711
  return;
17712
17712
  }
17713
17713
  const timer = setTimeout(() => {
17714
17714
  signal?.removeEventListener("abort", onAbort);
17715
- resolve5();
17715
+ resolve6();
17716
17716
  }, ms);
17717
17717
  const onAbort = () => {
17718
17718
  clearTimeout(timer);
@@ -18511,7 +18511,7 @@ var Protocol = class {
18511
18511
  const flowStartedAt = Date.now();
18512
18512
  let onAbort;
18513
18513
  let cleanupMessageId;
18514
- return new Promise((resolve5, reject) => {
18514
+ return new Promise((resolve6, reject) => {
18515
18515
  const earlyReject = (error42) => {
18516
18516
  reject(error42);
18517
18517
  };
@@ -18580,7 +18580,7 @@ var Protocol = class {
18580
18580
  }
18581
18581
  if (decoded.kind === "invalid") return reject(decoded.error);
18582
18582
  if (decoded.kind === "input_required") {
18583
- if (options?.allowInputRequired === true) return resolve5(manualInputRequiredValue(decoded));
18583
+ if (options?.allowInputRequired === true) return resolve6(manualInputRequiredValue(decoded));
18584
18584
  const flow = {
18585
18585
  codec,
18586
18586
  request: request2,
@@ -18592,11 +18592,11 @@ var Protocol = class {
18592
18592
  params
18593
18593
  }, resultSchema, legOptions)
18594
18594
  };
18595
- return resolve5(this._resolveNonCompleteResult(decoded, flow));
18595
+ return resolve6(this._resolveNonCompleteResult(decoded, flow));
18596
18596
  }
18597
18597
  const result = decoded.result;
18598
18598
  validateStandardSchema(resultSchema, result).then((parseResult) => {
18599
- if (parseResult.success) resolve5(parseResult.data);
18599
+ if (parseResult.success) resolve6(parseResult.data);
18600
18600
  else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request2.method}: ${parseResult.error}`));
18601
18601
  }, reject);
18602
18602
  });
@@ -21512,7 +21512,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
21512
21512
  ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
21513
21513
  const schOrFunc = root.refs[ref];
21514
21514
  if (schOrFunc) return schOrFunc;
21515
- let _sch = resolve5.call(this, root, ref);
21515
+ let _sch = resolve6.call(this, root, ref);
21516
21516
  if (_sch === void 0) {
21517
21517
  const schema = (_a5 = root.localRefs) === null || _a5 === void 0 ? void 0 : _a5[ref];
21518
21518
  const { schemaId } = this.opts;
@@ -21538,7 +21538,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
21538
21538
  function sameSchemaEnv(s1, s2) {
21539
21539
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
21540
21540
  }
21541
- function resolve5(root, ref) {
21541
+ function resolve6(root, ref) {
21542
21542
  let sch;
21543
21543
  while (typeof (sch = this.refs[ref]) == "string") ref = sch;
21544
21544
  return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
@@ -21988,7 +21988,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
21988
21988
  else if (typeof uri === "object") uri = parse6(serialize(uri, options), options);
21989
21989
  return uri;
21990
21990
  }
21991
- function resolve5(baseURI, relativeURI, options) {
21991
+ function resolve6(baseURI, relativeURI, options) {
21992
21992
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
21993
21993
  const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
21994
21994
  schemelessOptions.skipEscape = true;
@@ -22162,7 +22162,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
22162
22162
  const fastUri = {
22163
22163
  SCHEMES,
22164
22164
  normalize: normalize2,
22165
- resolve: resolve5,
22165
+ resolve: resolve6,
22166
22166
  resolveComponent,
22167
22167
  equal,
22168
22168
  serialize,
@@ -27627,7 +27627,7 @@ var StdioServerTransport = class {
27627
27627
  }
27628
27628
  send(message2) {
27629
27629
  if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
27630
- return new Promise((resolve5, reject) => {
27630
+ return new Promise((resolve6, reject) => {
27631
27631
  const json2 = serializeMessage(message2);
27632
27632
  let settled = false;
27633
27633
  const onError = (error42) => {
@@ -27642,14 +27642,14 @@ var StdioServerTransport = class {
27642
27642
  settled = true;
27643
27643
  this._stdout.off("error", onError);
27644
27644
  this._stdout.off("drain", onDrain);
27645
- resolve5();
27645
+ resolve6();
27646
27646
  };
27647
27647
  this._stdout.once("error", onError);
27648
27648
  if (this._stdout.write(json2)) {
27649
27649
  if (settled) return;
27650
27650
  settled = true;
27651
27651
  this._stdout.off("error", onError);
27652
- resolve5();
27652
+ resolve6();
27653
27653
  } else if (!settled) this._stdout.once("drain", onDrain);
27654
27654
  });
27655
27655
  }
@@ -27703,14 +27703,14 @@ var StdioConnectionChannel = class {
27703
27703
  */
27704
27704
  async whenRequestsAnswered(timeoutMs) {
27705
27705
  if (this._closed || this._pendingRequests.size === 0) return true;
27706
- return await new Promise((resolve5) => {
27706
+ return await new Promise((resolve6) => {
27707
27707
  const waiter = () => {
27708
27708
  clearTimeout(timer);
27709
- resolve5(true);
27709
+ resolve6(true);
27710
27710
  };
27711
27711
  const timer = setTimeout(() => {
27712
27712
  this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
27713
- resolve5(false);
27713
+ resolve6(false);
27714
27714
  }, timeoutMs);
27715
27715
  this._drainWaiters.push(waiter);
27716
27716
  });
@@ -28255,6 +28255,13 @@ var HOST_CONFIG_DIR_NAME = ".claude";
28255
28255
  var HOST_PLUGINS_DIR_NAME = "plugins";
28256
28256
  var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
28257
28257
  var PLUGIN_KEY_SEPARATOR = "@";
28258
+ var CLAUDE_PLUGIN_ROOT_ENV = "CLAUDE_PLUGIN_ROOT";
28259
+ var CLAUDE_PROJECT_DIR_ENV = "CLAUDE_PROJECT_DIR";
28260
+ var ENABLED_PLUGINS_KEY = "enabledPlugins";
28261
+ var SETTINGS_LOCAL_FILE = "settings.local.json";
28262
+ var DEFAULT_PLUGIN_SCOPE = "user";
28263
+ var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
28264
+ var PLUGIN_SCOPE_RANK = Object.freeze({ local: 0, project: 1, user: 2, managed: 2 });
28258
28265
  var MCP_HINT_EVERY_DEFAULT = 10;
28259
28266
  function readHintEvery(raw) {
28260
28267
  if (raw === void 0 || raw.trim() === "") return MCP_HINT_EVERY_DEFAULT;
@@ -28344,7 +28351,7 @@ var DECISION_SOURCE = "decision";
28344
28351
  var DECISION_USER_LABEL = "decision (user)";
28345
28352
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
28346
28353
  var RELEASE_BRANCH = "release";
28347
- var BUNDLE_SHA = true ? "baaa3149e881980288944e90179895fa6a2be13e" : void 0;
28354
+ var BUNDLE_SHA = true ? "c1992122ec8c3a499db1de0457f3c0bce13c9572" : void 0;
28348
28355
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
28349
28356
  var DOCTOR_LABEL = Object.freeze({
28350
28357
  D1: "version",
@@ -28501,6 +28508,13 @@ var D3_PART_JOIN = ", ";
28501
28508
  function D3_DETAIL(parts) {
28502
28509
  return `wrong: ${parts.join(D3_PART_JOIN)}`;
28503
28510
  }
28511
+ function D3_ROOT_DETAIL(paths) {
28512
+ return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
28513
+ }
28514
+ var D3_ROOT_FIX_JOIN = " or ";
28515
+ function D3_ROOT_FIX(installs) {
28516
+ return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
28517
+ }
28504
28518
  var HOOK_HOST_FILE = Object.freeze({
28505
28519
  "claude-code": { root: "plugin", file: ["hooks", "claude-code.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
28506
28520
  codex: { root: "home", file: [".codex", "hooks.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
@@ -29123,7 +29137,7 @@ function installExitGuard(opts) {
29123
29137
  }
29124
29138
 
29125
29139
  // src/core/project/config-dir.ts
29126
- import { join, posix, win32 } from "node:path";
29140
+ import { basename, dirname, join, posix, resolve, win32 } from "node:path";
29127
29141
  var { mkdirSync: mkdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
29128
29142
  function homeDirOf(env, platform = process.platform) {
29129
29143
  const set3 = (v) => v !== void 0 && v !== "";
@@ -29139,6 +29153,20 @@ function codexDirOf(env, home) {
29139
29153
  const dir = env[CODEX_HOME_ENV];
29140
29154
  return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR.codex);
29141
29155
  }
29156
+ function codexPluginHomeOf(bundleDir2) {
29157
+ let dir = resolve(bundleDir2);
29158
+ while (dirname(dir) !== dir) {
29159
+ const up = dirname(dir);
29160
+ if (basename(dir) === PLUGIN_CACHE_DIR_NAME && basename(up) === HOST_PLUGINS_DIR_NAME) return dirname(up);
29161
+ dir = up;
29162
+ }
29163
+ return null;
29164
+ }
29165
+ function codexRunDirOf(env, home, bundleDir2) {
29166
+ const dir = env[CODEX_HOME_ENV];
29167
+ if (dir !== void 0 && dir !== "") return dir;
29168
+ return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
29169
+ }
29142
29170
  function copilotDirOf(env, home) {
29143
29171
  const dir = env[COPILOT_HOME_ENV];
29144
29172
  return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
@@ -29193,10 +29221,10 @@ function resolveConfigDir(env) {
29193
29221
  }
29194
29222
 
29195
29223
  // src/core/project/resolve.ts
29196
- import { basename, dirname as dirname2, join as join2, resolve } from "node:path";
29224
+ import { basename as basename2, dirname as dirname3, join as join2, resolve as resolve2 } from "node:path";
29197
29225
 
29198
29226
  // src/core/project/contain.ts
29199
- import { dirname, sep } from "node:path";
29227
+ import { dirname as dirname2, sep } from "node:path";
29200
29228
  var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
29201
29229
  function real(p) {
29202
29230
  try {
@@ -29233,7 +29261,7 @@ function commonRoot(paths) {
29233
29261
  n = i;
29234
29262
  }
29235
29263
  let q = first;
29236
- while (components(q).length > n && dirname(q) !== q) q = dirname(q);
29264
+ while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
29237
29265
  return q;
29238
29266
  }
29239
29267
 
@@ -29400,9 +29428,9 @@ function gitDirs(dir) {
29400
29428
  const gitDir = gitDirAt(join2(cur, GIT_DIR_NAME));
29401
29429
  if (gitDir !== null) {
29402
29430
  const common = firstLine(join2(gitDir, GIT_COMMONDIR_FILE));
29403
- return { commonDir: realpathSync3.native(common === null ? gitDir : resolve(gitDir, common)), worktree: cur, start };
29431
+ return { commonDir: realpathSync3.native(common === null ? gitDir : resolve2(gitDir, common)), worktree: cur, start };
29404
29432
  }
29405
- const up = dirname2(cur);
29433
+ const up = dirname3(cur);
29406
29434
  if (up === cur) return { commonDir: null, start };
29407
29435
  cur = up;
29408
29436
  }
@@ -29415,7 +29443,7 @@ function gitDirAt(dotGit) {
29415
29443
  } else {
29416
29444
  const line = firstLine(dotGit);
29417
29445
  if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
29418
- gitDir = resolve(dirname2(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
29446
+ gitDir = resolve2(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
29419
29447
  }
29420
29448
  } catch {
29421
29449
  return null;
@@ -29440,9 +29468,9 @@ function git(dir, args) {
29440
29468
  return r.stdout.split("\n").filter((l) => l !== "");
29441
29469
  }
29442
29470
  function containmentRootOf(dir, commonDir) {
29443
- const repoDir = basename(commonDir) === GIT_DIR_NAME ? dirname2(commonDir) : commonDir;
29471
+ const repoDir = basename2(commonDir) === GIT_DIR_NAME ? dirname3(commonDir) : commonDir;
29444
29472
  const worktrees = git(dir, ["worktree", "list", "--porcelain"]).filter((l) => l.startsWith(GIT_WORKTREE_LINE_PREFIX)).map((l) => l.slice(GIT_WORKTREE_LINE_PREFIX.length));
29445
- return commonRoot([dirname2(repoDir), ...worktrees]);
29473
+ return commonRoot([dirname3(repoDir), ...worktrees]);
29446
29474
  }
29447
29475
  function resolveProject(agent, src) {
29448
29476
  const source = sourceOf(agent);
@@ -31945,7 +31973,7 @@ function queryUnits(db, sessionId, q, limit) {
31945
31973
 
31946
31974
  // src/core/store/owners.ts
31947
31975
  import { mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync2, rmSync as rmSync2, writeFileSync } from "node:fs";
31948
- import { basename as basename2, join as join3 } from "node:path";
31976
+ import { basename as basename3, join as join3 } from "node:path";
31949
31977
  function ownersDir(configDir, projectKey) {
31950
31978
  return join3(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
31951
31979
  }
@@ -31993,7 +32021,7 @@ function listLiveOwners(configDir, projectKey) {
31993
32021
  if (errCode(err) === "ENOENT") continue;
31994
32022
  throw err;
31995
32023
  }
31996
- const serverId = basename2(name, OWNER_PID_EXT);
32024
+ const serverId = basename3(name, OWNER_PID_EXT);
31997
32025
  if (isLive(Number(text.trim()))) live.push(serverId);
31998
32026
  else rmSync2(file2, { force: true });
31999
32027
  }
@@ -43735,10 +43763,10 @@ function startArgv(argv) {
43735
43763
  return sh === null ? null : [sh, ...argv];
43736
43764
  }
43737
43765
  function runProcess(argv, o) {
43738
- return new Promise((resolve5) => {
43766
+ return new Promise((resolve6) => {
43739
43767
  const isWin2 = process.platform === "win32";
43740
43768
  const start = startArgv(argv);
43741
- if (start === null) return resolve5(NOT_STARTED);
43769
+ if (start === null) return resolve6(NOT_STARTED);
43742
43770
  let child;
43743
43771
  try {
43744
43772
  child = spawn(start[0], start.slice(1), {
@@ -43752,7 +43780,7 @@ function runProcess(argv, o) {
43752
43780
  windowsHide: true
43753
43781
  });
43754
43782
  } catch {
43755
- return resolve5(NOT_STARTED);
43783
+ return resolve6(NOT_STARTED);
43756
43784
  }
43757
43785
  const stdoutChunks = [];
43758
43786
  const stderrChunks = [];
@@ -43777,7 +43805,7 @@ function runProcess(argv, o) {
43777
43805
  settled = true;
43778
43806
  clearTimeout(timer);
43779
43807
  o.signal.removeEventListener("abort", onAbort);
43780
- resolve5({
43808
+ resolve6({
43781
43809
  stdout: Buffer.concat(stdoutChunks),
43782
43810
  stderr: Buffer.concat(stderrChunks),
43783
43811
  exitCode,
@@ -44349,7 +44377,7 @@ var ctxBatch = Object.freeze({
44349
44377
 
44350
44378
  // src/core/tools/doctor.ts
44351
44379
  import { readdirSync as readdirSync6, readFileSync as readFileSync8, existsSync as existsSync13 } from "node:fs";
44352
- import { basename as basename3, dirname as dirname5, join as join11 } from "node:path";
44380
+ import { basename as basename4, dirname as dirname6, join as join11 } from "node:path";
44353
44381
 
44354
44382
  // src/adapters/claude-code.ts
44355
44383
  var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
@@ -45248,7 +45276,7 @@ import { join as join7 } from "node:path";
45248
45276
 
45249
45277
  // src/core/ops/host-config.ts
45250
45278
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
45251
- import { dirname as dirname3, join as join6 } from "node:path";
45279
+ import { dirname as dirname4, join as join6 } from "node:path";
45252
45280
 
45253
45281
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
45254
45282
  var KEYS2 = {
@@ -47388,7 +47416,7 @@ function formatOf(path7) {
47388
47416
  function readHostConfig(agent, path7) {
47389
47417
  let file2 = path7;
47390
47418
  if (agent === "opencode") {
47391
- const jsonc = join6(dirname3(path7), OPENCODE_CONFIG_FILES[0]);
47419
+ const jsonc = join6(dirname4(path7), OPENCODE_CONFIG_FILES[0]);
47392
47420
  if (existsSync4(jsonc)) file2 = jsonc;
47393
47421
  }
47394
47422
  const raw = existsSync4(file2) ? readFileSync4(file2, "utf8") : "";
@@ -47736,7 +47764,7 @@ function setText(agent, path7, text, format, key, value) {
47736
47764
  }
47737
47765
  }
47738
47766
  function serverScript() {
47739
- return join6(dirname3(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
47767
+ return join6(dirname4(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
47740
47768
  }
47741
47769
  function isNodeCommand(command) {
47742
47770
  if (typeof command !== "string") return false;
@@ -47752,7 +47780,7 @@ function ownMcpValue(agent, node3, server) {
47752
47780
  return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
47753
47781
  }
47754
47782
  function opencodePluginFile() {
47755
- return dirname3(process.argv[1] ?? "");
47783
+ return dirname4(process.argv[1] ?? "");
47756
47784
  }
47757
47785
  function listTarget(key, own4, v1, alt = []) {
47758
47786
  return {
@@ -48112,20 +48140,23 @@ function detectV1(agent, home, scope = {}) {
48112
48140
 
48113
48141
  // src/core/ops/plugin-root.ts
48114
48142
  import { existsSync as existsSync6, readdirSync as readdirSync4, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
48115
- import { dirname as dirname4, isAbsolute, join as join8, sep as sep2 } from "node:path";
48143
+ import { dirname as dirname5, isAbsolute, join as join8, sep as sep2 } from "node:path";
48116
48144
  import { fileURLToPath } from "node:url";
48117
48145
  function missing(agent, path7) {
48118
48146
  return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
48119
48147
  }
48120
- function recordedInstallPaths(text) {
48121
- let parsed;
48148
+ var parseOrNull = (text) => {
48122
48149
  try {
48123
- parsed = JSON.parse(hostText(text));
48150
+ return JSON.parse(hostText(text));
48124
48151
  } catch {
48125
- return [];
48152
+ return null;
48126
48153
  }
48127
- const plugins = parsed?.plugins;
48128
- if (plugins === null || typeof plugins !== "object") return [];
48154
+ };
48155
+ var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
48156
+ function recordedInstalls(text) {
48157
+ const parsed = parseOrNull(text);
48158
+ const plugins = isRecord3(parsed) ? parsed.plugins : void 0;
48159
+ if (!isRecord3(plugins)) return [];
48129
48160
  const out = [];
48130
48161
  for (const key of Object.keys(plugins)) {
48131
48162
  const at = key.indexOf(PLUGIN_KEY_SEPARATOR);
@@ -48133,8 +48164,10 @@ function recordedInstallPaths(text) {
48133
48164
  const entries = plugins[key];
48134
48165
  if (!Array.isArray(entries)) continue;
48135
48166
  for (const e of entries) {
48136
- const dir = e?.installPath;
48137
- if (typeof dir === "string" && dir !== "" && !out.includes(dir)) out.push(dir);
48167
+ if (!isRecord3(e) || typeof e.installPath !== "string" || e.installPath === "") continue;
48168
+ const scope = typeof e.scope === "string" ? e.scope : DEFAULT_PLUGIN_SCOPE;
48169
+ const projectPath = typeof e.projectPath === "string" ? e.projectPath : void 0;
48170
+ out.push({ key, scope, projectPath, installPath: e.installPath });
48138
48171
  }
48139
48172
  }
48140
48173
  return out;
@@ -48146,26 +48179,62 @@ var realOrNull = (path7) => {
48146
48179
  return null;
48147
48180
  }
48148
48181
  };
48149
- function marketplaceRoot(adapter, env) {
48150
- const claudeDir = claudeDirOf(env, requireHomeDir(env));
48151
- const plugins = join8(claudeDir, HOST_PLUGINS_DIR_NAME);
48152
- const cache = join8(plugins, PLUGIN_CACHE_DIR_NAME);
48153
- const script = process.argv[1];
48154
- const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname4(script));
48155
- let record6 = null;
48182
+ var readOrNull = (file2) => {
48156
48183
  try {
48157
- record6 = readFileSync6(join8(plugins, INSTALLED_PLUGINS_FILE), "utf8");
48184
+ return readFileSync6(file2, "utf8");
48158
48185
  } catch {
48159
- record6 = null;
48186
+ return null;
48160
48187
  }
48161
- const recorded = record6 === null ? [] : recordedInstallPaths(record6);
48162
- if (recorded.length > 0) {
48163
- const live = recorded.filter((dir) => existsSync6(dir));
48164
- const mine = live.find((dir) => realOrNull(dir) === ownReal);
48165
- if (mine !== void 0) return mine;
48166
- if (live.length === 1) return live[0];
48167
- throw missing(adapter.id, recorded.join(", "));
48188
+ };
48189
+ var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
48190
+ function enabledPlugins(claudeDir, project) {
48191
+ const files = [join8(claudeDir, SETTINGS_FILE)];
48192
+ if (project !== void 0) files.push(join8(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join8(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
48193
+ const out = {};
48194
+ for (const file2 of files) {
48195
+ const text = readOrNull(file2);
48196
+ const doc = text === null ? null : parseOrNull(text);
48197
+ const on = isRecord3(doc) ? doc[ENABLED_PLUGINS_KEY] : void 0;
48198
+ if (isRecord3(on)) Object.assign(out, on);
48168
48199
  }
48200
+ return out;
48201
+ }
48202
+ function marketplaceChoice(env, worktree) {
48203
+ const claudeDir = claudeDirOf(env, requireHomeDir(env));
48204
+ const script = process.argv[1];
48205
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
48206
+ const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
48207
+ if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
48208
+ const record6 = readOrNull(join8(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
48209
+ const recorded = record6 === null ? [] : recordedInstalls(record6);
48210
+ if (recorded.length === 0) return { record: false };
48211
+ const live = recorded.filter((r) => existsSync6(r.installPath));
48212
+ const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
48213
+ if (mine !== void 0) return { root: mine.installPath };
48214
+ const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
48215
+ if (dirs.length === 1) return { root: dirs[0].installPath };
48216
+ const projectEnv = env[CLAUDE_PROJECT_DIR_ENV];
48217
+ const project = worktree ?? (projectEnv === void 0 || projectEnv === "" ? void 0 : projectEnv);
48218
+ const on = enabledPlugins(claudeDir, project);
48219
+ const applies = (r) => !PROJECT_PLUGIN_SCOPES.includes(r.scope) || project !== void 0 && r.projectPath !== void 0 && samePath(r.projectPath, project);
48220
+ const rank = (r) => PLUGIN_SCOPE_RANK[r.scope] ?? PLUGIN_SCOPE_RANK[DEFAULT_PLUGIN_SCOPE];
48221
+ const used = live.filter((r) => on[r.key] === true && applies(r));
48222
+ if (used.length > 0) {
48223
+ const best = Math.min(...used.map(rank));
48224
+ const top = used.filter((r) => rank(r) === best);
48225
+ if (top.every((r) => samePath(r.installPath, top[0].installPath))) return { root: top[0].installPath };
48226
+ }
48227
+ return { installs: live.length === 0 ? recorded : live };
48228
+ }
48229
+ function marketplaceRoot(adapter, env, worktree) {
48230
+ const claudeDir = claudeDirOf(env, requireHomeDir(env));
48231
+ const plugins = join8(claudeDir, HOST_PLUGINS_DIR_NAME);
48232
+ const cache = join8(plugins, PLUGIN_CACHE_DIR_NAME);
48233
+ const script = process.argv[1];
48234
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
48235
+ const choice = marketplaceChoice(env, worktree);
48236
+ if ("root" in choice) return choice.root;
48237
+ if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
48169
48238
  const cacheReal = realOrNull(cache);
48170
48239
  if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync6(join8(ownReal, SERVER_ENTRY_FILE))) return ownReal;
48171
48240
  const pattern = join8(cache, "*", PLUGIN_NAME);
@@ -48184,12 +48253,12 @@ function configEntryRoot(adapter, env) {
48184
48253
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
48185
48254
  const script = Array.isArray(args) ? args[0] : void 0;
48186
48255
  if (typeof script !== "string" || !isAbsolute(script)) throw missing(adapter.id, file2);
48187
- return dirname4(script);
48256
+ return dirname5(script);
48188
48257
  }
48189
- function candidate(adapter, env) {
48258
+ function candidate(adapter, env, worktree) {
48190
48259
  switch (adapter.installMode) {
48191
48260
  case "marketplace":
48192
- return marketplaceRoot(adapter, env);
48261
+ return marketplaceRoot(adapter, env, worktree);
48193
48262
  case "config-mcp":
48194
48263
  case "mcp-entry":
48195
48264
  case "hooks+mcp":
@@ -48199,11 +48268,11 @@ function candidate(adapter, env) {
48199
48268
  case "plugin":
48200
48269
  return join8(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
48201
48270
  case "in-process":
48202
- return dirname4(fileURLToPath(import.meta.url));
48271
+ return dirname5(fileURLToPath(import.meta.url));
48203
48272
  }
48204
48273
  }
48205
- function resolvePluginRoot(adapter, env) {
48206
- const path7 = candidate(adapter, env);
48274
+ function resolvePluginRoot(adapter, env, worktree) {
48275
+ const path7 = candidate(adapter, env, worktree);
48207
48276
  try {
48208
48277
  return realpathSync4.native(path7);
48209
48278
  } catch {
@@ -48334,13 +48403,13 @@ function nativeMcpWrong(dir, row5) {
48334
48403
  return true;
48335
48404
  }
48336
48405
  }
48337
- function mcpWrong(row5, home, env) {
48406
+ function mcpWrong(row5, home, env, worktree) {
48338
48407
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
48339
48408
  if (native !== null) return nativeMcpWrong(native, row5);
48340
48409
  const file2 = mcpFile(row5, home, env);
48341
48410
  try {
48342
48411
  if (file2 === null) {
48343
- resolvePluginRoot(row5, env);
48412
+ resolvePluginRoot(row5, env, worktree);
48344
48413
  return false;
48345
48414
  }
48346
48415
  const cur = readHostConfig(row5.id, file2);
@@ -48354,7 +48423,7 @@ function hookParts(row5, home, env, worktree) {
48354
48423
  if (spec === null) return [];
48355
48424
  let block;
48356
48425
  try {
48357
- const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
48426
+ const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
48358
48427
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
48359
48428
  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);
48360
48429
  block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
@@ -48389,7 +48458,11 @@ function hookParts(row5, home, env, worktree) {
48389
48458
  function checkHostConfig(row5, env, worktree) {
48390
48459
  const home = homeDirOf(env);
48391
48460
  if (home === null) return fail("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
48392
- const parts = [...mcpWrong(row5, home, env) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
48461
+ if (row5.installMode === "marketplace") {
48462
+ const choice = marketplaceChoice(env, worktree);
48463
+ if ("installs" in choice) return fail("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
48464
+ }
48465
+ const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
48393
48466
  const read = row5.id === "pi" ? mcpFile(row5, home, env) : null;
48394
48467
  if (parts.length === 0) return read === null ? pass("D3") : { ...pass("D3"), detail: read };
48395
48468
  const detail = D3_DETAIL(parts);
@@ -48581,7 +48654,7 @@ function checkShell(env) {
48581
48654
  }
48582
48655
 
48583
48656
  // src/core/ops/doctor-hook.ts
48584
- import { existsSync as existsSync11, readFileSync as readFileSync7 } from "node:fs";
48657
+ import { existsSync as existsSync11, readFileSync as readFileSync7, realpathSync as realpathSync7 } from "node:fs";
48585
48658
  import path6 from "node:path";
48586
48659
 
48587
48660
  // src/setup/codex-trust.ts
@@ -48658,6 +48731,28 @@ function spawnForm(file2, args, env, platform = process.platform) {
48658
48731
  var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
48659
48732
  var TRUST_KEY = ["hooks", "state"];
48660
48733
  var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
48734
+ var WIN_VERBATIM_PREFIX = "\\\\?\\";
48735
+ function codexHomeFromReply(out) {
48736
+ for (const line of out.split("\n")) {
48737
+ let m;
48738
+ try {
48739
+ m = JSON.parse(line);
48740
+ } catch {
48741
+ continue;
48742
+ }
48743
+ if (isObj2(m) && isObj2(m.result) && typeof m.result.codexHome === "string" && m.result.codexHome !== "") return m.result.codexHome;
48744
+ }
48745
+ return void 0;
48746
+ }
48747
+ function sameDir(a, b, platform = process.platform) {
48748
+ if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
48749
+ const norm = (p) => {
48750
+ const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
48751
+ const n = path5.win32.normalize(bare2).toLowerCase();
48752
+ return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
48753
+ };
48754
+ return norm(a) === norm(b);
48755
+ }
48661
48756
  var LIST_TIMEOUT_MS = 15e3;
48662
48757
  var EXIT_GRACE_MS = 5e3;
48663
48758
  var PLUGIN_SOURCE = "plugin";
@@ -48676,15 +48771,17 @@ function pluginHooksFromReply(m, pluginId) {
48676
48771
  }
48677
48772
  return out;
48678
48773
  }
48679
- function listPluginHooks(env, pluginId, cwd) {
48774
+ function askPluginHooks(env, pluginId, cwd) {
48680
48775
  const bin = whichBin("codex", env);
48681
- if (!bin) return Promise.resolve(void 0);
48682
- return new Promise((resolve5) => {
48776
+ if (!bin) return Promise.resolve({ kind: "absent" });
48777
+ return new Promise((resolve6) => {
48778
+ let asked;
48779
+ const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
48683
48780
  let f;
48684
48781
  try {
48685
48782
  f = spawnForm(bin, ["app-server"], env);
48686
48783
  } catch {
48687
- resolve5(void 0);
48784
+ resolve6({ kind: "silent" });
48688
48785
  return;
48689
48786
  }
48690
48787
  const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
@@ -48694,7 +48791,7 @@ function listPluginHooks(env, pluginId, cwd) {
48694
48791
  let result;
48695
48792
  const settle3 = () => {
48696
48793
  clearTimeout(grace);
48697
- resolve5(result);
48794
+ resolve6(done_(result));
48698
48795
  };
48699
48796
  let grace;
48700
48797
  const finish2 = (v) => {
@@ -48739,6 +48836,7 @@ function listPluginHooks(env, pluginId, cwd) {
48739
48836
  }
48740
48837
  if (!isObj2(m)) continue;
48741
48838
  if (m.id === 1) {
48839
+ asked = codexHomeFromReply(line);
48742
48840
  send({ method: "initialized" });
48743
48841
  send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
48744
48842
  } else if (m.id === 2) finish2(pluginHooksFromReply(m, pluginId));
@@ -48768,6 +48866,10 @@ function untrustedPluginHooksDetail(hooks) {
48768
48866
  var D5_MIN_PAIRS = 3;
48769
48867
  var D5_MAX_PAIRS = 9;
48770
48868
  var D5_CODEX_TRUST_FIX = "context-mode setup --agents codex";
48869
+ var D5_CODEX_ABSENT_DETAIL = (home) => `codex is not on PATH, so the trust of the context-mode plugin hooks in ${home} is not known`;
48870
+ var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answer for ${home} in time, so the context-mode plugin hooks are not known to run`;
48871
+ var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
48872
+ var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
48771
48873
  var row = (status, detail, fixCommand) => fixCommand === void 0 ? { id: "D5", label: DOCTOR_LABEL.D5, status, detail } : { id: "D5", label: DOCTOR_LABEL.D5, status, detail, fixCommand };
48772
48874
  function isObject5(v) {
48773
48875
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -48804,11 +48906,34 @@ function codexHookJournaled(db) {
48804
48906
  if (db === null) return false;
48805
48907
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
48806
48908
  }
48909
+ function realDir(p) {
48910
+ try {
48911
+ return realpathSync7(p);
48912
+ } catch {
48913
+ return p;
48914
+ }
48915
+ }
48916
+ async function codexPluginTrust(i) {
48917
+ const home = i.codexConfigDir;
48918
+ const plugin = codexPluginHomeOf(i.bundleDir) !== null;
48919
+ const reply4 = await askPluginHooks({ ...i.env, CODEX_HOME: home }, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
48920
+ if (reply4.kind === "list") {
48921
+ const detail = untrustedPluginHooksDetail(reply4.hooks);
48922
+ if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
48923
+ }
48924
+ if (!plugin) return null;
48925
+ if (reply4.kind === "absent") return row("UNKNOWN", D5_CODEX_ABSENT_DETAIL(home), D5_CODEX_TRUST_FIX);
48926
+ if (reply4.kind === "silent") return row("FAIL", D5_CODEX_SILENT_DETAIL(home), D5_CODEX_TRUST_FIX);
48927
+ if (reply4.codexHome !== void 0 && !sameDir(realDir(reply4.codexHome), realDir(home))) {
48928
+ return row("FAIL", D5_CODEX_OTHER_HOME_DETAIL(reply4.codexHome, home), D5_CODEX_TRUST_FIX);
48929
+ }
48930
+ if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
48931
+ return null;
48932
+ }
48807
48933
  async function checkHookRoundTrip(i) {
48808
48934
  if (i.agent === "codex") {
48809
- const hooks = await listPluginHooks(i.env, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
48810
- const detail = hooks === void 0 ? void 0 : untrustedPluginHooksDetail(hooks);
48811
- if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
48935
+ const trust = await codexPluginTrust(i);
48936
+ if (trust !== null) return trust;
48812
48937
  }
48813
48938
  if (i.agent === "codex" && existsSync11(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
48814
48939
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
@@ -48847,7 +48972,7 @@ async function checkHookRoundTrip(i) {
48847
48972
  }
48848
48973
 
48849
48974
  // src/core/hooks/fallback.ts
48850
- import { join as join10, resolve as resolve2 } from "node:path";
48975
+ import { join as join10, resolve as resolve3 } from "node:path";
48851
48976
  var fs = process.getBuiltinModule("node:fs");
48852
48977
  function homeOf(env) {
48853
48978
  return env.HOME ?? env.USERPROFILE ?? "";
@@ -49036,7 +49161,7 @@ async function hookRow(ctx, adapter, host) {
49036
49161
  env: buildChildEnv(host.env),
49037
49162
  signal: ctx.signal,
49038
49163
  codexConfigDir: codexDirOf(host.env, requireHomeDir(host.env)),
49039
- // same Codex dir D3 reads (D-N6-CODEX-HOME-2)
49164
+ // = codexRunDirOf: runDoctorChecks sets CODEX_HOME for codex (D-CODEX-HOME-RUN-1)
49040
49165
  db
49041
49166
  });
49042
49167
  const last2 = lastHookError(host.env);
@@ -49052,11 +49177,12 @@ function ownServerId(configDir, projectKey) {
49052
49177
  if (!existsSync13(dir)) return "";
49053
49178
  for (const name of readdirSync6(dir)) {
49054
49179
  if (!name.endsWith(OWNER_PID_EXT)) continue;
49055
- if (readFileSync8(join11(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
49180
+ if (readFileSync8(join11(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
49056
49181
  }
49057
49182
  return "";
49058
49183
  }
49059
- async function runDoctorChecks(ctx, adapter, host) {
49184
+ async function runDoctorChecks(ctx, adapter, host0) {
49185
+ const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
49060
49186
  const env = host.env;
49061
49187
  const project = ctx.project;
49062
49188
  let integrityFailed = false;
@@ -49098,7 +49224,7 @@ function reportEnv(env) {
49098
49224
  }
49099
49225
  async function handler2(_input, ctx) {
49100
49226
  const adapter = getAdapter(ctx.project.agent);
49101
- const host = { env: process.env, bundleDir: dirname5(process.argv[1]), piCwd: void 0 };
49227
+ const host = { env: process.env, bundleDir: dirname6(process.argv[1]), piCwd: void 0 };
49102
49228
  const rows = await runDoctorChecks(ctx, adapter, host);
49103
49229
  const command = `context-mode ${rows.some((r) => r.status === "FAIL") ? "setup" : "doctor"} --agents ${adapter.id}`;
49104
49230
  const input = { agent: adapter.id, rows, env: reportEnv(process.env), command };
@@ -49126,7 +49252,7 @@ var ctxDoctor = Object.freeze({
49126
49252
  // src/core/tools/execute.ts
49127
49253
  import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
49128
49254
  import { tmpdir as tmpdir2 } from "node:os";
49129
- import { dirname as dirname6, join as join12, parse as parse5, resolve as resolve3 } from "node:path";
49255
+ import { dirname as dirname7, join as join12, parse as parse5, resolve as resolve4 } from "node:path";
49130
49256
 
49131
49257
  // src/core/index/select.ts
49132
49258
  var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
@@ -49249,7 +49375,7 @@ function schemaLine(issue4) {
49249
49375
  }
49250
49376
  function fileError(given, abs, root) {
49251
49377
  let dir = abs;
49252
- while (!existsSync14(dir) && dirname6(dir) !== dir) dir = dirname6(dir);
49378
+ while (!existsSync14(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
49253
49379
  if (isInside(root, dir)) return null;
49254
49380
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
49255
49381
  }
@@ -49313,7 +49439,7 @@ async function handler3(raw, ctx) {
49313
49439
  const cwd = ctx.project.worktree;
49314
49440
  const extra = { ...PLAIN_OUTPUT_ENV2 };
49315
49441
  if (input.file !== void 0) {
49316
- const abs = resolve3(cwd, input.file);
49442
+ const abs = resolve4(cwd, input.file);
49317
49443
  const bad = fileError(input.file, abs, ctx.project.containmentRoot);
49318
49444
  if (bad !== null) return fail4(bad);
49319
49445
  extra.CTX_FILE = abs;
@@ -49367,15 +49493,15 @@ var ctxExecute = {
49367
49493
 
49368
49494
  // src/core/tools/index.ts
49369
49495
  import { existsSync as existsSync15, readFileSync as readFileSync10, statSync as statSync6 } from "node:fs";
49370
- import { dirname as dirname7, extname, join as join14, relative as relative2, resolve as resolve4 } from "node:path";
49496
+ import { dirname as dirname8, extname, join as join14, relative as relative2, resolve as resolve5 } from "node:path";
49371
49497
 
49372
49498
  // src/core/index/walk.ts
49373
- import { readdirSync as readdirSync7, readFileSync as readFileSync9, realpathSync as realpathSync7, statSync as statSync5 } from "node:fs";
49499
+ import { readdirSync as readdirSync7, readFileSync as readFileSync9, realpathSync as realpathSync8, statSync as statSync5 } from "node:fs";
49374
49500
  import { join as join13 } from "node:path";
49375
49501
  var GITIGNORE = ".gitignore";
49376
49502
  var GIT_DIR = ".git";
49377
49503
  function walkDir(root, containmentRoot) {
49378
- const real2 = realpathSync7(root);
49504
+ const real2 = realpathSync8(root);
49379
49505
  if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
49380
49506
  const found = [];
49381
49507
  visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
@@ -49399,7 +49525,7 @@ function visit(abs, rel, parent, contain, seen, found) {
49399
49525
  if (e.isSymbolicLink()) {
49400
49526
  let resolved;
49401
49527
  try {
49402
- resolved = realpathSync7(path7);
49528
+ resolved = realpathSync8(path7);
49403
49529
  } catch {
49404
49530
  continue;
49405
49531
  }
@@ -49414,7 +49540,7 @@ function visit(abs, rel, parent, contain, seen, found) {
49414
49540
  if (isFile) {
49415
49541
  found.push({ dir: rel, name: e.name, absPath: path7 });
49416
49542
  } else if (isDir) {
49417
- const key = e.isSymbolicLink() ? target : realpathSync7(path7);
49543
+ const key = e.isSymbolicLink() ? target : realpathSync8(path7);
49418
49544
  if (seen.has(key)) continue;
49419
49545
  seen.add(key);
49420
49546
  visit(path7, segs, rules, contain, seen, found);
@@ -49609,18 +49735,18 @@ function request(u, conn, proxy, signal) {
49609
49735
  const host = bare(u.hostname);
49610
49736
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
49611
49737
  const path7 = u.pathname + u.search;
49612
- return new Promise((resolve5, reject) => {
49738
+ return new Promise((resolve6, reject) => {
49613
49739
  const onErr = (err) => reject(fail5(causeCode(err)));
49614
49740
  if (proxy === void 0) {
49615
49741
  const mod = u.protocol === "https:" ? https : http;
49616
49742
  const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
49617
- req.on("response", resolve5).on("error", onErr).end();
49743
+ req.on("response", resolve6).on("error", onErr).end();
49618
49744
  return;
49619
49745
  }
49620
49746
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
49621
49747
  if (u.protocol === "http:") {
49622
49748
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
49623
- req.on("response", resolve5).on("error", onErr).end();
49749
+ req.on("response", resolve6).on("error", onErr).end();
49624
49750
  return;
49625
49751
  }
49626
49752
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -49640,16 +49766,16 @@ function request(u, conn, proxy, signal) {
49640
49766
  headers: { host: u.host },
49641
49767
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
49642
49768
  });
49643
- req.on("response", resolve5).on("error", onErr).end();
49769
+ req.on("response", resolve6).on("error", onErr).end();
49644
49770
  });
49645
49771
  tunnel.end();
49646
49772
  });
49647
49773
  }
49648
49774
  function readBody(res) {
49649
- return new Promise((resolve5, reject) => {
49775
+ return new Promise((resolve6, reject) => {
49650
49776
  const parts = [];
49651
49777
  res.on("data", (b) => parts.push(b));
49652
- res.on("end", () => resolve5(Buffer.concat(parts)));
49778
+ res.on("end", () => resolve6(Buffer.concat(parts)));
49653
49779
  res.on("error", (err) => reject(fail5(causeCode(err))));
49654
49780
  res.on("aborted", () => reject(fail5("ECONNRESET")));
49655
49781
  });
@@ -53522,12 +53648,12 @@ function readUtf8(absPath) {
53522
53648
  }
53523
53649
  function missingOrOutside(given, abs, root) {
53524
53650
  let dir = abs;
53525
- while (!existsSync15(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
53651
+ while (!existsSync15(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
53526
53652
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
53527
53653
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
53528
53654
  }
53529
53655
  function pathItems(input, project) {
53530
- const abs = resolve4(project.worktree, input.path);
53656
+ const abs = resolve5(project.worktree, input.path);
53531
53657
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
53532
53658
  const base = relative2(project.worktree, abs);
53533
53659
  if (statSync6(abs).isDirectory()) {
@@ -54055,12 +54181,12 @@ var ctxStats = Object.freeze({
54055
54181
  });
54056
54182
 
54057
54183
  // src/core/tools/upgrade.ts
54058
- import { existsSync as existsSync21, realpathSync as realpathSync8, rmSync as rmSync10 } from "node:fs";
54059
- import { basename as basename5, dirname as dirname9, join as join20 } from "node:path";
54184
+ import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync10 } from "node:fs";
54185
+ import { basename as basename6, dirname as dirname10, join as join20 } from "node:path";
54060
54186
 
54061
54187
  // src/core/ops/host-write.ts
54062
54188
  import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
54063
- import { dirname as dirname8, join as join15 } from "node:path";
54189
+ import { dirname as dirname9, join as join15 } from "node:path";
54064
54190
  function defaultWrite(file2, text) {
54065
54191
  writeFileSync4(file2, text, "utf8");
54066
54192
  }
@@ -54089,7 +54215,7 @@ function writeWithRollback(file2, text, write, atomic) {
54089
54215
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
54090
54216
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
54091
54217
  const had = existsSync16(file2);
54092
- mkdirSync5(dirname8(file2), { recursive: true });
54218
+ mkdirSync5(dirname9(file2), { recursive: true });
54093
54219
  if (had) copyFileSync(file2, trash);
54094
54220
  try {
54095
54221
  write(tmp, text);
@@ -54127,7 +54253,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
54127
54253
 
54128
54254
  // src/core/ops/plugin-swap.ts
54129
54255
  import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
54130
- import { basename as basename4, join as join16, win32 as win322 } from "node:path";
54256
+ import { basename as basename5, join as join16, win32 as win322 } from "node:path";
54131
54257
  function linkTarget(path7, win) {
54132
54258
  if (!isLink(path7)) return null;
54133
54259
  const target = readlinkSync(path7);
@@ -54148,7 +54274,7 @@ function settleLinks(link, tmp, old, opts) {
54148
54274
  function swapPluginCurrent(agentDir, sha, opts = {}) {
54149
54275
  const next = join16(agentDir, sha);
54150
54276
  if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
54151
- throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
54277
+ throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
54152
54278
  }
54153
54279
  const link = join16(agentDir, PLUGIN_CURRENT_LINK);
54154
54280
  const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
@@ -54231,6 +54357,10 @@ function removeCache(adapter, env, configDir) {
54231
54357
  case "extension": {
54232
54358
  const root = rootOrNull(adapter, env);
54233
54359
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
54360
+ if (adapter.installMode === "marketplace") {
54361
+ const cache = join18(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
54362
+ if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
54363
+ }
54234
54364
  rmSync8(root, { recursive: true, force: true });
54235
54365
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
54236
54366
  }
@@ -54516,7 +54646,7 @@ function row4(area, before, after) {
54516
54646
  return { area, before, after };
54517
54647
  }
54518
54648
  function bundleDir() {
54519
- return dirname9(process.argv[1] ?? "");
54649
+ return dirname10(process.argv[1] ?? "");
54520
54650
  }
54521
54651
  function pluginRootRow(adapter, env) {
54522
54652
  const own4 = bundleDir();
@@ -54531,11 +54661,11 @@ function pluginRootRow(adapter, env) {
54531
54661
  }
54532
54662
  function isCurrent(agentDir, dir) {
54533
54663
  const link = join20(agentDir, PLUGIN_CURRENT_LINK);
54534
- return existsSync21(link) && realpathSync8.native(link) === realpathSync8.native(dir);
54664
+ return existsSync21(link) && realpathSync9.native(link) === realpathSync9.native(dir);
54535
54665
  }
54536
54666
  async function checkout(adapter, deps) {
54537
54667
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
54538
- const agentDir = dirname9(fetched.dir);
54668
+ const agentDir = dirname10(fetched.dir);
54539
54669
  try {
54540
54670
  verifySums(fetched.dir);
54541
54671
  } catch (err) {
@@ -54563,7 +54693,7 @@ async function upgrade(adapter, deps, home) {
54563
54693
  return rows;
54564
54694
  } catch (err) {
54565
54695
  removal?.rollback();
54566
- if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename5(done.swap.previous));
54696
+ if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename6(done.swap.previous));
54567
54697
  throw err;
54568
54698
  }
54569
54699
  }
@@ -54650,12 +54780,12 @@ function checkCall(tool, input) {
54650
54780
  }
54651
54781
 
54652
54782
  // src/entries/is-entry.ts
54653
- import { realpathSync as realpathSync9 } from "node:fs";
54783
+ import { realpathSync as realpathSync10 } from "node:fs";
54654
54784
  function isEntry(main, argv1, self) {
54655
54785
  if (main !== void 0) return main;
54656
54786
  if (argv1 === void 0 || argv1 === "") return false;
54657
54787
  try {
54658
- return realpathSync9(argv1) === realpathSync9(self);
54788
+ return realpathSync10(argv1) === realpathSync10(self);
54659
54789
  } catch {
54660
54790
  return false;
54661
54791
  }
@@ -54731,7 +54861,7 @@ function workspaceFromMeta(meta3) {
54731
54861
  }
54732
54862
  function realOrSame(p) {
54733
54863
  try {
54734
- return realpathSync10.native(p);
54864
+ return realpathSync11.native(p);
54735
54865
  } catch {
54736
54866
  return p;
54737
54867
  }
@@ -54740,7 +54870,7 @@ function workspaceCwdOf(meta3, spawnCwd, script) {
54740
54870
  const fromHost = workspaceFromMeta(meta3);
54741
54871
  if (fromHost !== void 0) return fromHost;
54742
54872
  if (script === void 0 || script === "") return spawnCwd;
54743
- return realOrSame(spawnCwd) === realOrSame(dirname10(script)) ? "" : spawnCwd;
54873
+ return realOrSame(spawnCwd) === realOrSame(dirname11(script)) ? "" : spawnCwd;
54744
54874
  }
54745
54875
  function errorReply(err) {
54746
54876
  if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
@@ -54894,7 +55024,7 @@ async function startServer(argv, env) {
54894
55024
  }
54895
55025
  installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
54896
55026
  handle = serveStdio(createServer);
54897
- await new Promise((resolve5) => process.once("exit", () => resolve5()));
55027
+ await new Promise((resolve6) => process.once("exit", () => resolve6()));
54898
55028
  }
54899
55029
  if (isEntry(import.meta.main, process.argv[1], fileURLToPath2(import.meta.url))) {
54900
55030
  const [, , ...cliArgs] = process.argv;