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

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/pi/index.js CHANGED
@@ -11366,6 +11366,13 @@ var HOST_PLUGINS_DIR_NAME = "plugins";
11366
11366
  var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
11367
11367
  var PLUGIN_AGENT_SEPARATOR = ":";
11368
11368
  var PLUGIN_KEY_SEPARATOR = "@";
11369
+ var CLAUDE_PLUGIN_ROOT_ENV = "CLAUDE_PLUGIN_ROOT";
11370
+ var CLAUDE_PROJECT_DIR_ENV = "CLAUDE_PROJECT_DIR";
11371
+ var ENABLED_PLUGINS_KEY = "enabledPlugins";
11372
+ var SETTINGS_LOCAL_FILE = "settings.local.json";
11373
+ var DEFAULT_PLUGIN_SCOPE = "user";
11374
+ var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
11375
+ var PLUGIN_SCOPE_RANK = Object.freeze({ local: 0, project: 1, user: 2, managed: 2 });
11369
11376
  var FRONTMATTER_FENCE = "---";
11370
11377
  var FRONTMATTER_TOOLS_KEY = "tools";
11371
11378
  var FRONTMATTER_DISALLOWED_KEY = "disallowedTools";
@@ -11509,7 +11516,7 @@ var DECISION_OPTION_KEY = "option";
11509
11516
  var DECISION_LABEL_JOIN = " | ";
11510
11517
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
11511
11518
  var RELEASE_BRANCH = "release";
11512
- var BUNDLE_SHA = true ? "baaa3149e881980288944e90179895fa6a2be13e" : void 0;
11519
+ var BUNDLE_SHA = true ? "58d6b744f8c640e9f43f03516d8bc50dc1292ae0" : void 0;
11513
11520
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
11514
11521
  var DOCTOR_LABEL = Object.freeze({
11515
11522
  D1: "version",
@@ -11666,6 +11673,13 @@ var D3_PART_JOIN = ", ";
11666
11673
  function D3_DETAIL(parts) {
11667
11674
  return `wrong: ${parts.join(D3_PART_JOIN)}`;
11668
11675
  }
11676
+ function D3_ROOT_DETAIL(paths) {
11677
+ return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
11678
+ }
11679
+ var D3_ROOT_FIX_JOIN = " or ";
11680
+ function D3_ROOT_FIX(installs) {
11681
+ return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
11682
+ }
11669
11683
  var HOOK_HOST_FILE = Object.freeze({
11670
11684
  "claude-code": { root: "plugin", file: ["hooks", "claude-code.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
11671
11685
  codex: { root: "home", file: [".codex", "hooks.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
@@ -11994,7 +12008,7 @@ var CtxError = class extends Error {
11994
12008
  };
11995
12009
 
11996
12010
  // src/core/hooks/dispatch.ts
11997
- import { dirname as dirname3, join as join6 } from "node:path";
12011
+ import { dirname as dirname4, join as join6 } from "node:path";
11998
12012
 
11999
12013
  // src/core/contracts/agents.ts
12000
12014
  var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
@@ -12836,7 +12850,7 @@ function getAdapter(id) {
12836
12850
  }
12837
12851
 
12838
12852
  // src/core/policy/decide.ts
12839
- import { resolve as resolve2 } from "node:path";
12853
+ import { resolve as resolve3 } from "node:path";
12840
12854
 
12841
12855
  // src/core/policy/lexer.ts
12842
12856
  var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
@@ -14141,7 +14155,7 @@ function withLayout(text, layout) {
14141
14155
  }
14142
14156
 
14143
14157
  // src/core/project/config-dir.ts
14144
- import { join, posix, win32 } from "node:path";
14158
+ import { basename, dirname, join, posix, resolve as resolve2, win32 } from "node:path";
14145
14159
  var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
14146
14160
  function homeDirOf(env, platform = process.platform) {
14147
14161
  const set3 = (v) => v !== void 0 && v !== "";
@@ -14157,6 +14171,20 @@ function codexDirOf(env, home) {
14157
14171
  const dir = env[CODEX_HOME_ENV];
14158
14172
  return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR.codex);
14159
14173
  }
14174
+ function codexPluginHomeOf(bundleDir2) {
14175
+ let dir = resolve2(bundleDir2);
14176
+ while (dirname(dir) !== dir) {
14177
+ const up = dirname(dir);
14178
+ if (basename(dir) === PLUGIN_CACHE_DIR_NAME && basename(up) === HOST_PLUGINS_DIR_NAME) return dirname(up);
14179
+ dir = up;
14180
+ }
14181
+ return null;
14182
+ }
14183
+ function codexRunDirOf(env, home, bundleDir2) {
14184
+ const dir = env[CODEX_HOME_ENV];
14185
+ if (dir !== void 0 && dir !== "") return dir;
14186
+ return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
14187
+ }
14160
14188
  function copilotDirOf(env, home) {
14161
14189
  const dir = env[COPILOT_HOME_ENV];
14162
14190
  return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
@@ -14736,7 +14764,7 @@ function readPath(input) {
14736
14764
  }
14737
14765
  function userDenyHit(canonical, input, cwd, rules) {
14738
14766
  if (rules.length === 0) return null;
14739
- const readRule = (p) => matchesAnyDenyPattern(resolve2(cwd, p), rules, { tool: READ, projectDir: cwd });
14767
+ const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
14740
14768
  if (canonical === BASH) {
14741
14769
  const cmd = str(input.command);
14742
14770
  return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
@@ -14847,7 +14875,7 @@ function read(ev, row5, input) {
14847
14875
  if (!present(input.offset) && !present(input.limit)) {
14848
14876
  const p = readPath(input);
14849
14877
  if (p !== void 0) {
14850
- const abs = resolve2(ev.cwd, p);
14878
+ const abs = resolve3(ev.cwd, p);
14851
14879
  const size = fileSize(abs);
14852
14880
  if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
14853
14881
  }
@@ -14860,7 +14888,7 @@ function shellDump(cmds, cwd, row5) {
14860
14888
  let verdict = null;
14861
14889
  for (const c of cmds) {
14862
14890
  const name = c.argv0.toLowerCase();
14863
- if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve2(dir, c.args[0]);
14891
+ if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve3(dir, c.args[0]);
14864
14892
  if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
14865
14893
  if (!has(SHELL_DUMP_COMMANDS, name)) continue;
14866
14894
  const d = dumpTarget(name, c.args);
@@ -14869,7 +14897,7 @@ function shellDump(cmds, cwd, row5) {
14869
14897
  verdict = ALLOW;
14870
14898
  continue;
14871
14899
  }
14872
- const abs = resolve2(dir, d.file);
14900
+ const abs = resolve3(dir, d.file);
14873
14901
  const size = fileSize(abs);
14874
14902
  if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
14875
14903
  }
@@ -14940,10 +14968,10 @@ function dumpTarget(name, args) {
14940
14968
  }
14941
14969
 
14942
14970
  // src/core/project/resolve.ts
14943
- import { basename, dirname as dirname2, join as join4, resolve as resolve3 } from "node:path";
14971
+ import { basename as basename2, dirname as dirname3, join as join4, resolve as resolve4 } from "node:path";
14944
14972
 
14945
14973
  // src/core/project/contain.ts
14946
- import { dirname, sep as sep2 } from "node:path";
14974
+ import { dirname as dirname2, sep as sep2 } from "node:path";
14947
14975
  var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
14948
14976
  function real(p) {
14949
14977
  try {
@@ -14980,7 +15008,7 @@ function commonRoot(paths) {
14980
15008
  n = i;
14981
15009
  }
14982
15010
  let q = first;
14983
- while (components(q).length > n && dirname(q) !== q) q = dirname(q);
15011
+ while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
14984
15012
  return q;
14985
15013
  }
14986
15014
 
@@ -15147,9 +15175,9 @@ function gitDirs(dir) {
15147
15175
  const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
15148
15176
  if (gitDir !== null) {
15149
15177
  const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
15150
- return { commonDir: realpathSync3.native(common === null ? gitDir : resolve3(gitDir, common)), worktree: cur, start };
15178
+ return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
15151
15179
  }
15152
- const up = dirname2(cur);
15180
+ const up = dirname3(cur);
15153
15181
  if (up === cur) return { commonDir: null, start };
15154
15182
  cur = up;
15155
15183
  }
@@ -15162,7 +15190,7 @@ function gitDirAt(dotGit) {
15162
15190
  } else {
15163
15191
  const line = firstLine(dotGit);
15164
15192
  if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
15165
- gitDir = resolve3(dirname2(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
15193
+ gitDir = resolve4(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
15166
15194
  }
15167
15195
  } catch {
15168
15196
  return null;
@@ -15187,9 +15215,9 @@ function git(dir, args) {
15187
15215
  return r.stdout.split("\n").filter((l) => l !== "");
15188
15216
  }
15189
15217
  function containmentRootOf(dir, commonDir) {
15190
- const repoDir = basename(commonDir) === GIT_DIR_NAME ? dirname2(commonDir) : commonDir;
15218
+ const repoDir = basename2(commonDir) === GIT_DIR_NAME ? dirname3(commonDir) : commonDir;
15191
15219
  const worktrees = git(dir, ["worktree", "list", "--porcelain"]).filter((l) => l.startsWith(GIT_WORKTREE_LINE_PREFIX)).map((l) => l.slice(GIT_WORKTREE_LINE_PREFIX.length));
15192
- return commonRoot([dirname2(repoDir), ...worktrees]);
15220
+ return commonRoot([dirname3(repoDir), ...worktrees]);
15193
15221
  }
15194
15222
  function resolveProject(agent, src) {
15195
15223
  const source = sourceOf(agent);
@@ -19119,7 +19147,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
19119
19147
  }
19120
19148
 
19121
19149
  // src/core/hooks/fallback.ts
19122
- import { join as join5, resolve as resolve4 } from "node:path";
19150
+ import { join as join5, resolve as resolve5 } from "node:path";
19123
19151
  var fs = process.getBuiltinModule("node:fs");
19124
19152
  function isRec(v) {
19125
19153
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -19234,7 +19262,7 @@ function bigRead(input, cwd) {
19234
19262
  const p = firstString(input, READ_PATH_KEYS);
19235
19263
  if (p === "") return false;
19236
19264
  try {
19237
- const st = fs.statSync(resolve4(cwd, p));
19265
+ const st = fs.statSync(resolve5(cwd, p));
19238
19266
  return st.isFile() && st.size > OUTPUT_CAP;
19239
19267
  } catch {
19240
19268
  return false;
@@ -19305,20 +19333,24 @@ async function handleHook(agent, raw, env) {
19305
19333
  return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message(err) + "\n");
19306
19334
  }
19307
19335
  let decision;
19336
+ const settle3 = {};
19308
19337
  try {
19309
19338
  fault(env, "policy");
19310
- decision = await dispatch(ev, row5, project, env);
19339
+ decision = await dispatch(ev, row5, project, env, settle3);
19311
19340
  } catch (err) {
19312
19341
  return fail7("store", err);
19313
19342
  }
19314
19343
  try {
19315
19344
  fault(env, "encode");
19316
- return row5.encode(ev, decision);
19345
+ const out = row5.encode(ev, decision);
19346
+ settle3.run?.(true);
19347
+ return out;
19317
19348
  } catch (err) {
19349
+ settle3.run?.(false);
19318
19350
  return fail7("encode", err);
19319
19351
  }
19320
19352
  }
19321
- function dispatch(ev, row5, project, env) {
19353
+ function dispatch(ev, row5, project, env, settle3) {
19322
19354
  switch (ev.event) {
19323
19355
  case "SessionStart":
19324
19356
  return sessionStart(ev, row5, project);
@@ -19327,7 +19359,7 @@ function dispatch(ev, row5, project, env) {
19327
19359
  case "PreToolUse":
19328
19360
  return preToolUse(ev, row5, project, env);
19329
19361
  case "PostToolUse":
19330
- return postToolUse(ev, row5, project, env);
19362
+ return postToolUse(ev, row5, project, env, settle3);
19331
19363
  case "PreCompact":
19332
19364
  return preCompact(ev, row5, project);
19333
19365
  case "Usage":
@@ -19517,7 +19549,7 @@ function caseB(ev, row5, d0, userDeny) {
19517
19549
  if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
19518
19550
  const command = tool.input.command;
19519
19551
  if (typeof command !== "string") return d0;
19520
- const wrapper = '"' + join6(dirname3(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
19552
+ const wrapper = '"' + join6(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
19521
19553
  const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
19522
19554
  return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
19523
19555
  }
@@ -19554,7 +19586,7 @@ function pathOf(input) {
19554
19586
  for (const k of EDIT_PATH_KEYS) if (typeof input[k] === "string") return input[k];
19555
19587
  return null;
19556
19588
  }
19557
- async function postToolUse(ev, row5, project, env) {
19589
+ async function postToolUse(ev, row5, project, env, settle3) {
19558
19590
  const tool = ev.tool;
19559
19591
  if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
19560
19592
  const result = ev.result ?? { isError: false, bytes: 0 };
@@ -19562,7 +19594,8 @@ async function postToolUse(ev, row5, project, env) {
19562
19594
  if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
19563
19595
  if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
19564
19596
  const kind = journalKind(tool, row5, result.isError);
19565
- if (kind !== null) {
19597
+ const journal = (returned) => {
19598
+ if (kind === null) return;
19566
19599
  const key = kind === "cmd" ? canonicalKey(tool.canonicalName, str2(tool.input.command)) : kind === "toolerr" ? tool.canonicalName + ":" + stableJson(tool.input) : null;
19567
19600
  appendDetached(project, ev.sessionId, {
19568
19601
  // step 4; body is the whole text (D-M3-H2-6)
@@ -19579,18 +19612,30 @@ async function postToolUse(ev, row5, project, env) {
19579
19612
  body: text,
19580
19613
  turn: ev.turn ?? 0,
19581
19614
  sandbox_bytes: result.bytes,
19582
- returned_bytes: result.bytes
19615
+ returned_bytes: returned
19583
19616
  });
19617
+ };
19618
+ let decision;
19619
+ try {
19620
+ decision = await postReplace(ev, row5, project, env, tool, result, text);
19621
+ } catch (err) {
19622
+ journal(result.bytes);
19623
+ throw err;
19584
19624
  }
19625
+ const decided = decision;
19626
+ settle3.run = (encoded) => journal(encoded && decided.kind === "replace" ? Buffer.byteLength(decided.output) : result.bytes);
19627
+ return decision;
19628
+ }
19629
+ async function postReplace(ev, row5, project, env, tool, result, text) {
19585
19630
  if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
19586
19631
  if (result.keep === true) return ALLOW2;
19632
+ if (!hasReplace(row5)) return ALLOW2;
19587
19633
  let label;
19588
19634
  if (isSubagentCall(ev)) {
19589
19635
  const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
19590
19636
  if (subCase === "A") return ALLOW2;
19591
19637
  label = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + String(ev.turn ?? 0);
19592
19638
  } else {
19593
- if (!hasReplace(row5)) return ALLOW2;
19594
19639
  label = mainLabel(tool, ev);
19595
19640
  }
19596
19641
  const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url].map(str2).find((v) => v.trim() !== "") ?? "";
@@ -19847,10 +19892,10 @@ function startArgv(argv) {
19847
19892
  return sh === null ? null : [sh, ...argv];
19848
19893
  }
19849
19894
  function runProcess(argv, o) {
19850
- return new Promise((resolve7) => {
19895
+ return new Promise((resolve8) => {
19851
19896
  const isWin2 = process.platform === "win32";
19852
19897
  const start = startArgv(argv);
19853
- if (start === null) return resolve7(NOT_STARTED);
19898
+ if (start === null) return resolve8(NOT_STARTED);
19854
19899
  let child;
19855
19900
  try {
19856
19901
  child = spawn(start[0], start.slice(1), {
@@ -19864,7 +19909,7 @@ function runProcess(argv, o) {
19864
19909
  windowsHide: true
19865
19910
  });
19866
19911
  } catch {
19867
- return resolve7(NOT_STARTED);
19912
+ return resolve8(NOT_STARTED);
19868
19913
  }
19869
19914
  const stdoutChunks = [];
19870
19915
  const stderrChunks = [];
@@ -19889,7 +19934,7 @@ function runProcess(argv, o) {
19889
19934
  settled = true;
19890
19935
  clearTimeout(timer);
19891
19936
  o.signal.removeEventListener("abort", onAbort);
19892
- resolve7({
19937
+ resolve8({
19893
19938
  stdout: Buffer.concat(stdoutChunks),
19894
19939
  stderr: Buffer.concat(stderrChunks),
19895
19940
  exitCode,
@@ -20407,7 +20452,7 @@ var ctxBatch = Object.freeze({
20407
20452
 
20408
20453
  // src/core/tools/doctor.ts
20409
20454
  import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync12 } from "node:fs";
20410
- import { basename as basename3, dirname as dirname6, join as join13 } from "node:path";
20455
+ import { basename as basename4, dirname as dirname7, join as join13 } from "node:path";
20411
20456
 
20412
20457
  // src/core/ops/doctor-config.ts
20413
20458
  import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
@@ -20420,7 +20465,7 @@ import { join as join9 } from "node:path";
20420
20465
 
20421
20466
  // src/core/ops/host-config.ts
20422
20467
  import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
20423
- import { dirname as dirname4, join as join8 } from "node:path";
20468
+ import { dirname as dirname5, join as join8 } from "node:path";
20424
20469
 
20425
20470
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
20426
20471
  var KEYS2 = {
@@ -22537,7 +22582,7 @@ function formatOf(path7) {
22537
22582
  function readHostConfig(agent, path7) {
22538
22583
  let file2 = path7;
22539
22584
  if (agent === "opencode") {
22540
- const jsonc = join8(dirname4(path7), OPENCODE_CONFIG_FILES[0]);
22585
+ const jsonc = join8(dirname5(path7), OPENCODE_CONFIG_FILES[0]);
22541
22586
  if (existsSync3(jsonc)) file2 = jsonc;
22542
22587
  }
22543
22588
  const raw = existsSync3(file2) ? readFileSync6(file2, "utf8") : "";
@@ -22885,7 +22930,7 @@ function setText(agent, path7, text, format, key, value) {
22885
22930
  }
22886
22931
  }
22887
22932
  function serverScript() {
22888
- return join8(dirname4(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
22933
+ return join8(dirname5(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
22889
22934
  }
22890
22935
  function isNodeCommand(command) {
22891
22936
  if (typeof command !== "string") return false;
@@ -22901,7 +22946,7 @@ function ownMcpValue(agent, node3, server) {
22901
22946
  return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
22902
22947
  }
22903
22948
  function opencodePluginFile() {
22904
- return dirname4(process.argv[1] ?? "");
22949
+ return dirname5(process.argv[1] ?? "");
22905
22950
  }
22906
22951
  function listTarget(key, own4, v1, alt = []) {
22907
22952
  return {
@@ -23261,20 +23306,23 @@ function detectV1(agent, home, scope = {}) {
23261
23306
 
23262
23307
  // src/core/ops/plugin-root.ts
23263
23308
  import { existsSync as existsSync5, readdirSync as readdirSync2, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23264
- import { dirname as dirname5, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
23309
+ import { dirname as dirname6, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
23265
23310
  import { fileURLToPath } from "node:url";
23266
23311
  function missing(agent, path7) {
23267
23312
  return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
23268
23313
  }
23269
- function recordedInstallPaths(text) {
23270
- let parsed;
23314
+ var parseOrNull = (text) => {
23271
23315
  try {
23272
- parsed = JSON.parse(hostText(text));
23316
+ return JSON.parse(hostText(text));
23273
23317
  } catch {
23274
- return [];
23318
+ return null;
23275
23319
  }
23276
- const plugins = parsed?.plugins;
23277
- if (plugins === null || typeof plugins !== "object") return [];
23320
+ };
23321
+ var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23322
+ function recordedInstalls(text) {
23323
+ const parsed = parseOrNull(text);
23324
+ const plugins = isRecord3(parsed) ? parsed.plugins : void 0;
23325
+ if (!isRecord3(plugins)) return [];
23278
23326
  const out = [];
23279
23327
  for (const key of Object.keys(plugins)) {
23280
23328
  const at2 = key.indexOf(PLUGIN_KEY_SEPARATOR);
@@ -23282,8 +23330,10 @@ function recordedInstallPaths(text) {
23282
23330
  const entries = plugins[key];
23283
23331
  if (!Array.isArray(entries)) continue;
23284
23332
  for (const e of entries) {
23285
- const dir = e?.installPath;
23286
- if (typeof dir === "string" && dir !== "" && !out.includes(dir)) out.push(dir);
23333
+ if (!isRecord3(e) || typeof e.installPath !== "string" || e.installPath === "") continue;
23334
+ const scope = typeof e.scope === "string" ? e.scope : DEFAULT_PLUGIN_SCOPE;
23335
+ const projectPath = typeof e.projectPath === "string" ? e.projectPath : void 0;
23336
+ out.push({ key, scope, projectPath, installPath: e.installPath });
23287
23337
  }
23288
23338
  }
23289
23339
  return out;
@@ -23295,26 +23345,62 @@ var realOrNull = (path7) => {
23295
23345
  return null;
23296
23346
  }
23297
23347
  };
23298
- function marketplaceRoot(adapter, env) {
23299
- const claudeDir = claudeDirOf(env, requireHomeDir(env));
23300
- const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
23301
- const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
23302
- const script = process.argv[1];
23303
- const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
23304
- let record6 = null;
23348
+ var readOrNull = (file2) => {
23305
23349
  try {
23306
- record6 = readFileSync8(join10(plugins, INSTALLED_PLUGINS_FILE), "utf8");
23350
+ return readFileSync8(file2, "utf8");
23307
23351
  } catch {
23308
- record6 = null;
23352
+ return null;
23309
23353
  }
23310
- const recorded = record6 === null ? [] : recordedInstallPaths(record6);
23311
- if (recorded.length > 0) {
23312
- const live = recorded.filter((dir) => existsSync5(dir));
23313
- const mine = live.find((dir) => realOrNull(dir) === ownReal);
23314
- if (mine !== void 0) return mine;
23315
- if (live.length === 1) return live[0];
23316
- throw missing(adapter.id, recorded.join(", "));
23354
+ };
23355
+ var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
23356
+ function enabledPlugins(claudeDir, project) {
23357
+ const files = [join10(claudeDir, SETTINGS_FILE)];
23358
+ if (project !== void 0) files.push(join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
23359
+ const out = {};
23360
+ for (const file2 of files) {
23361
+ const text = readOrNull(file2);
23362
+ const doc = text === null ? null : parseOrNull(text);
23363
+ const on = isRecord3(doc) ? doc[ENABLED_PLUGINS_KEY] : void 0;
23364
+ if (isRecord3(on)) Object.assign(out, on);
23317
23365
  }
23366
+ return out;
23367
+ }
23368
+ function marketplaceChoice(env, worktree) {
23369
+ const claudeDir = claudeDirOf(env, requireHomeDir(env));
23370
+ const script = process.argv[1];
23371
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
23372
+ const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
23373
+ if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
23374
+ const record6 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
23375
+ const recorded = record6 === null ? [] : recordedInstalls(record6);
23376
+ if (recorded.length === 0) return { record: false };
23377
+ const live = recorded.filter((r) => existsSync5(r.installPath));
23378
+ const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
23379
+ if (mine !== void 0) return { root: mine.installPath };
23380
+ const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
23381
+ if (dirs.length === 1) return { root: dirs[0].installPath };
23382
+ const projectEnv = env[CLAUDE_PROJECT_DIR_ENV];
23383
+ const project = worktree ?? (projectEnv === void 0 || projectEnv === "" ? void 0 : projectEnv);
23384
+ const on = enabledPlugins(claudeDir, project);
23385
+ const applies = (r) => !PROJECT_PLUGIN_SCOPES.includes(r.scope) || project !== void 0 && r.projectPath !== void 0 && samePath(r.projectPath, project);
23386
+ const rank = (r) => PLUGIN_SCOPE_RANK[r.scope] ?? PLUGIN_SCOPE_RANK[DEFAULT_PLUGIN_SCOPE];
23387
+ const used = live.filter((r) => on[r.key] === true && applies(r));
23388
+ if (used.length > 0) {
23389
+ const best = Math.min(...used.map(rank));
23390
+ const top = used.filter((r) => rank(r) === best);
23391
+ if (top.every((r) => samePath(r.installPath, top[0].installPath))) return { root: top[0].installPath };
23392
+ }
23393
+ return { installs: live.length === 0 ? recorded : live };
23394
+ }
23395
+ function marketplaceRoot(adapter, env, worktree) {
23396
+ const claudeDir = claudeDirOf(env, requireHomeDir(env));
23397
+ const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
23398
+ const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
23399
+ const script = process.argv[1];
23400
+ const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
23401
+ const choice = marketplaceChoice(env, worktree);
23402
+ if ("root" in choice) return choice.root;
23403
+ if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
23318
23404
  const cacheReal = realOrNull(cache);
23319
23405
  if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync5(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
23320
23406
  const pattern = join10(cache, "*", PLUGIN_NAME);
@@ -23333,12 +23419,12 @@ function configEntryRoot(adapter, env) {
23333
23419
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
23334
23420
  const script = Array.isArray(args) ? args[0] : void 0;
23335
23421
  if (typeof script !== "string" || !isAbsolute2(script)) throw missing(adapter.id, file2);
23336
- return dirname5(script);
23422
+ return dirname6(script);
23337
23423
  }
23338
- function candidate(adapter, env) {
23424
+ function candidate(adapter, env, worktree) {
23339
23425
  switch (adapter.installMode) {
23340
23426
  case "marketplace":
23341
- return marketplaceRoot(adapter, env);
23427
+ return marketplaceRoot(adapter, env, worktree);
23342
23428
  case "config-mcp":
23343
23429
  case "mcp-entry":
23344
23430
  case "hooks+mcp":
@@ -23348,11 +23434,11 @@ function candidate(adapter, env) {
23348
23434
  case "plugin":
23349
23435
  return join10(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
23350
23436
  case "in-process":
23351
- return dirname5(fileURLToPath(import.meta.url));
23437
+ return dirname6(fileURLToPath(import.meta.url));
23352
23438
  }
23353
23439
  }
23354
- function resolvePluginRoot(adapter, env) {
23355
- const path7 = candidate(adapter, env);
23440
+ function resolvePluginRoot(adapter, env, worktree) {
23441
+ const path7 = candidate(adapter, env, worktree);
23356
23442
  try {
23357
23443
  return realpathSync4.native(path7);
23358
23444
  } catch {
@@ -23483,13 +23569,13 @@ function nativeMcpWrong(dir, row5) {
23483
23569
  return true;
23484
23570
  }
23485
23571
  }
23486
- function mcpWrong(row5, home, env) {
23572
+ function mcpWrong(row5, home, env, worktree) {
23487
23573
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
23488
23574
  if (native !== null) return nativeMcpWrong(native, row5);
23489
23575
  const file2 = mcpFile(row5, home, env);
23490
23576
  try {
23491
23577
  if (file2 === null) {
23492
- resolvePluginRoot(row5, env);
23578
+ resolvePluginRoot(row5, env, worktree);
23493
23579
  return false;
23494
23580
  }
23495
23581
  const cur = readHostConfig(row5.id, file2);
@@ -23503,7 +23589,7 @@ function hookParts(row5, home, env, worktree) {
23503
23589
  if (spec === null) return [];
23504
23590
  let block;
23505
23591
  try {
23506
- const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
23592
+ const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
23507
23593
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
23508
23594
  const file2 = native !== null ? join11(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join11(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join11(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join11(kiroDirOf(env, home), ...spec.file.slice(1)) : join11(root, ...spec.file);
23509
23595
  block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
@@ -23538,7 +23624,11 @@ function hookParts(row5, home, env, worktree) {
23538
23624
  function checkHostConfig(row5, env, worktree) {
23539
23625
  const home = homeDirOf(env);
23540
23626
  if (home === null) return fail2("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
23541
- const parts = [...mcpWrong(row5, home, env) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
23627
+ if (row5.installMode === "marketplace") {
23628
+ const choice = marketplaceChoice(env, worktree);
23629
+ if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
23630
+ }
23631
+ const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
23542
23632
  const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
23543
23633
  if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
23544
23634
  const detail = D3_DETAIL(parts);
@@ -23730,7 +23820,7 @@ function checkShell(env) {
23730
23820
  }
23731
23821
 
23732
23822
  // src/core/ops/doctor-hook.ts
23733
- import { existsSync as existsSync10, readFileSync as readFileSync9 } from "node:fs";
23823
+ import { existsSync as existsSync10, readFileSync as readFileSync9, realpathSync as realpathSync7 } from "node:fs";
23734
23824
  import path6 from "node:path";
23735
23825
 
23736
23826
  // src/setup/codex-trust.ts
@@ -23807,6 +23897,28 @@ function spawnForm(file2, args, env, platform = process.platform) {
23807
23897
  var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23808
23898
  var TRUST_KEY = ["hooks", "state"];
23809
23899
  var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
23900
+ var WIN_VERBATIM_PREFIX = "\\\\?\\";
23901
+ function codexHomeFromReply(out) {
23902
+ for (const line of out.split("\n")) {
23903
+ let m;
23904
+ try {
23905
+ m = JSON.parse(line);
23906
+ } catch {
23907
+ continue;
23908
+ }
23909
+ if (isObj2(m) && isObj2(m.result) && typeof m.result.codexHome === "string" && m.result.codexHome !== "") return m.result.codexHome;
23910
+ }
23911
+ return void 0;
23912
+ }
23913
+ function sameDir(a, b, platform = process.platform) {
23914
+ if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
23915
+ const norm2 = (p) => {
23916
+ const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
23917
+ const n = path5.win32.normalize(bare2).toLowerCase();
23918
+ return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
23919
+ };
23920
+ return norm2(a) === norm2(b);
23921
+ }
23810
23922
  var LIST_TIMEOUT_MS = 15e3;
23811
23923
  var EXIT_GRACE_MS = 5e3;
23812
23924
  var PLUGIN_SOURCE = "plugin";
@@ -23825,15 +23937,17 @@ function pluginHooksFromReply(m, pluginId) {
23825
23937
  }
23826
23938
  return out;
23827
23939
  }
23828
- function listPluginHooks(env, pluginId, cwd) {
23940
+ function askPluginHooks(env, pluginId, cwd) {
23829
23941
  const bin = whichBin("codex", env);
23830
- if (!bin) return Promise.resolve(void 0);
23831
- return new Promise((resolve7) => {
23942
+ if (!bin) return Promise.resolve({ kind: "absent" });
23943
+ return new Promise((resolve8) => {
23944
+ let asked;
23945
+ const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
23832
23946
  let f;
23833
23947
  try {
23834
23948
  f = spawnForm(bin, ["app-server"], env);
23835
23949
  } catch {
23836
- resolve7(void 0);
23950
+ resolve8({ kind: "silent" });
23837
23951
  return;
23838
23952
  }
23839
23953
  const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
@@ -23843,7 +23957,7 @@ function listPluginHooks(env, pluginId, cwd) {
23843
23957
  let result;
23844
23958
  const settle3 = () => {
23845
23959
  clearTimeout(grace);
23846
- resolve7(result);
23960
+ resolve8(done_(result));
23847
23961
  };
23848
23962
  let grace;
23849
23963
  const finish2 = (v) => {
@@ -23888,6 +24002,7 @@ function listPluginHooks(env, pluginId, cwd) {
23888
24002
  }
23889
24003
  if (!isObj2(m)) continue;
23890
24004
  if (m.id === 1) {
24005
+ asked = codexHomeFromReply(line);
23891
24006
  send({ method: "initialized" });
23892
24007
  send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
23893
24008
  } else if (m.id === 2) finish2(pluginHooksFromReply(m, pluginId));
@@ -23917,6 +24032,10 @@ function untrustedPluginHooksDetail(hooks) {
23917
24032
  var D5_MIN_PAIRS = 3;
23918
24033
  var D5_MAX_PAIRS = 9;
23919
24034
  var D5_CODEX_TRUST_FIX = "context-mode setup --agents codex";
24035
+ 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`;
24036
+ 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`;
24037
+ var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
24038
+ var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
23920
24039
  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 };
23921
24040
  function isObject5(v) {
23922
24041
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -23953,11 +24072,34 @@ function codexHookJournaled(db) {
23953
24072
  if (db === null) return false;
23954
24073
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
23955
24074
  }
24075
+ function realDir(p) {
24076
+ try {
24077
+ return realpathSync7(p);
24078
+ } catch {
24079
+ return p;
24080
+ }
24081
+ }
24082
+ async function codexPluginTrust(i) {
24083
+ const home = i.codexConfigDir;
24084
+ const plugin = codexPluginHomeOf(i.bundleDir) !== null;
24085
+ const reply4 = await askPluginHooks({ ...i.env, CODEX_HOME: home }, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
24086
+ if (reply4.kind === "list") {
24087
+ const detail = untrustedPluginHooksDetail(reply4.hooks);
24088
+ if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
24089
+ }
24090
+ if (!plugin) return null;
24091
+ if (reply4.kind === "absent") return row("UNKNOWN", D5_CODEX_ABSENT_DETAIL(home), D5_CODEX_TRUST_FIX);
24092
+ if (reply4.kind === "silent") return row("FAIL", D5_CODEX_SILENT_DETAIL(home), D5_CODEX_TRUST_FIX);
24093
+ if (reply4.codexHome !== void 0 && !sameDir(realDir(reply4.codexHome), realDir(home))) {
24094
+ return row("FAIL", D5_CODEX_OTHER_HOME_DETAIL(reply4.codexHome, home), D5_CODEX_TRUST_FIX);
24095
+ }
24096
+ if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
24097
+ return null;
24098
+ }
23956
24099
  async function checkHookRoundTrip(i) {
23957
24100
  if (i.agent === "codex") {
23958
- const hooks = await listPluginHooks(i.env, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
23959
- const detail = hooks === void 0 ? void 0 : untrustedPluginHooksDetail(hooks);
23960
- if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
24101
+ const trust = await codexPluginTrust(i);
24102
+ if (trust !== null) return trust;
23961
24103
  }
23962
24104
  if (i.agent === "codex" && existsSync10(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
23963
24105
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
@@ -24000,7 +24142,7 @@ import { existsSync as existsSync11, rmSync as rmSync3 } from "node:fs";
24000
24142
 
24001
24143
  // src/core/store/owners.ts
24002
24144
  import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24003
- import { basename as basename2, join as join12 } from "node:path";
24145
+ import { basename as basename3, join as join12 } from "node:path";
24004
24146
  function ownersDir(configDir, projectKey) {
24005
24147
  return join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
24006
24148
  }
@@ -24048,7 +24190,7 @@ function listLiveOwners(configDir, projectKey) {
24048
24190
  if (errCode2(err) === "ENOENT") continue;
24049
24191
  throw err;
24050
24192
  }
24051
- const serverId = basename2(name, OWNER_PID_EXT);
24193
+ const serverId = basename3(name, OWNER_PID_EXT);
24052
24194
  if (isLive(Number(text.trim()))) live.push(serverId);
24053
24195
  else rmSync2(file2, { force: true });
24054
24196
  }
@@ -24188,7 +24330,7 @@ async function hookRow(ctx, adapter, host) {
24188
24330
  env: buildChildEnv(host.env),
24189
24331
  signal: ctx.signal,
24190
24332
  codexConfigDir: codexDirOf(host.env, requireHomeDir(host.env)),
24191
- // same Codex dir D3 reads (D-N6-CODEX-HOME-2)
24333
+ // = codexRunDirOf: runDoctorChecks sets CODEX_HOME for codex (D-CODEX-HOME-RUN-1)
24192
24334
  db
24193
24335
  });
24194
24336
  const last2 = lastHookError(host.env);
@@ -24204,11 +24346,12 @@ function ownServerId(configDir, projectKey) {
24204
24346
  if (!existsSync12(dir)) return "";
24205
24347
  for (const name of readdirSync5(dir)) {
24206
24348
  if (!name.endsWith(OWNER_PID_EXT)) continue;
24207
- if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
24349
+ if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
24208
24350
  }
24209
24351
  return "";
24210
24352
  }
24211
- async function runDoctorChecks(ctx, adapter, host) {
24353
+ async function runDoctorChecks(ctx, adapter, host0) {
24354
+ const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
24212
24355
  const env = host.env;
24213
24356
  const project = ctx.project;
24214
24357
  let integrityFailed = false;
@@ -24250,7 +24393,7 @@ function reportEnv(env) {
24250
24393
  }
24251
24394
  async function handler2(_input, ctx) {
24252
24395
  const adapter = getAdapter(ctx.project.agent);
24253
- const host = { env: process.env, bundleDir: dirname6(process.argv[1]), piCwd: void 0 };
24396
+ const host = { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 };
24254
24397
  const rows = await runDoctorChecks(ctx, adapter, host);
24255
24398
  const command = `context-mode ${rows.some((r) => r.status === "FAIL") ? "setup" : "doctor"} --agents ${adapter.id}`;
24256
24399
  const input = { agent: adapter.id, rows, env: reportEnv(process.env), command };
@@ -24278,7 +24421,7 @@ var ctxDoctor = Object.freeze({
24278
24421
  // src/core/tools/execute.ts
24279
24422
  import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
24280
24423
  import { tmpdir as tmpdir2 } from "node:os";
24281
- import { dirname as dirname7, join as join14, parse as parse3, resolve as resolve5 } from "node:path";
24424
+ import { dirname as dirname8, join as join14, parse as parse3, resolve as resolve6 } from "node:path";
24282
24425
 
24283
24426
  // src/core/sandbox/win-build.ts
24284
24427
  var SEPARATORS2 = ";&|(\n";
@@ -24362,7 +24505,7 @@ function schemaLine(issue4) {
24362
24505
  }
24363
24506
  function fileError(given, abs, root) {
24364
24507
  let dir = abs;
24365
- while (!existsSync13(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
24508
+ while (!existsSync13(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
24366
24509
  if (isInside(root, dir)) return null;
24367
24510
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
24368
24511
  }
@@ -24426,7 +24569,7 @@ async function handler3(raw, ctx) {
24426
24569
  const cwd = ctx.project.worktree;
24427
24570
  const extra = { ...PLAIN_OUTPUT_ENV2 };
24428
24571
  if (input.file !== void 0) {
24429
- const abs = resolve5(cwd, input.file);
24572
+ const abs = resolve6(cwd, input.file);
24430
24573
  const bad = fileError(input.file, abs, ctx.project.containmentRoot);
24431
24574
  if (bad !== null) return fail5(bad);
24432
24575
  extra.CTX_FILE = abs;
@@ -24480,15 +24623,15 @@ var ctxExecute = {
24480
24623
 
24481
24624
  // src/core/tools/index.ts
24482
24625
  import { existsSync as existsSync14, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
24483
- import { dirname as dirname8, extname, join as join16, relative as relative3, resolve as resolve6 } from "node:path";
24626
+ import { dirname as dirname9, extname, join as join16, relative as relative3, resolve as resolve7 } from "node:path";
24484
24627
 
24485
24628
  // src/core/index/walk.ts
24486
- import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync7, statSync as statSync6 } from "node:fs";
24629
+ import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync8, statSync as statSync6 } from "node:fs";
24487
24630
  import { join as join15 } from "node:path";
24488
24631
  var GITIGNORE = ".gitignore";
24489
24632
  var GIT_DIR = ".git";
24490
24633
  function walkDir(root, containmentRoot) {
24491
- const real2 = realpathSync7(root);
24634
+ const real2 = realpathSync8(root);
24492
24635
  if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
24493
24636
  const found = [];
24494
24637
  visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
@@ -24512,7 +24655,7 @@ function visit(abs, rel, parent, contain, seen, found) {
24512
24655
  if (e.isSymbolicLink()) {
24513
24656
  let resolved;
24514
24657
  try {
24515
- resolved = realpathSync7(path7);
24658
+ resolved = realpathSync8(path7);
24516
24659
  } catch {
24517
24660
  continue;
24518
24661
  }
@@ -24527,7 +24670,7 @@ function visit(abs, rel, parent, contain, seen, found) {
24527
24670
  if (isFile) {
24528
24671
  found.push({ dir: rel, name: e.name, absPath: path7 });
24529
24672
  } else if (isDir) {
24530
- const key = e.isSymbolicLink() ? target : realpathSync7(path7);
24673
+ const key = e.isSymbolicLink() ? target : realpathSync8(path7);
24531
24674
  if (seen.has(key)) continue;
24532
24675
  seen.add(key);
24533
24676
  visit(path7, segs, rules, contain, seen, found);
@@ -24722,18 +24865,18 @@ function request(u, conn, proxy, signal) {
24722
24865
  const host = bare(u.hostname);
24723
24866
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
24724
24867
  const path7 = u.pathname + u.search;
24725
- return new Promise((resolve7, reject) => {
24868
+ return new Promise((resolve8, reject) => {
24726
24869
  const onErr = (err) => reject(fail6(causeCode(err)));
24727
24870
  if (proxy === void 0) {
24728
24871
  const mod = u.protocol === "https:" ? https : http;
24729
24872
  const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
24730
- req.on("response", resolve7).on("error", onErr).end();
24873
+ req.on("response", resolve8).on("error", onErr).end();
24731
24874
  return;
24732
24875
  }
24733
24876
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
24734
24877
  if (u.protocol === "http:") {
24735
24878
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
24736
- req.on("response", resolve7).on("error", onErr).end();
24879
+ req.on("response", resolve8).on("error", onErr).end();
24737
24880
  return;
24738
24881
  }
24739
24882
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -24753,16 +24896,16 @@ function request(u, conn, proxy, signal) {
24753
24896
  headers: { host: u.host },
24754
24897
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
24755
24898
  });
24756
- req.on("response", resolve7).on("error", onErr).end();
24899
+ req.on("response", resolve8).on("error", onErr).end();
24757
24900
  });
24758
24901
  tunnel.end();
24759
24902
  });
24760
24903
  }
24761
24904
  function readBody(res) {
24762
- return new Promise((resolve7, reject) => {
24905
+ return new Promise((resolve8, reject) => {
24763
24906
  const parts = [];
24764
24907
  res.on("data", (b) => parts.push(b));
24765
- res.on("end", () => resolve7(Buffer.concat(parts)));
24908
+ res.on("end", () => resolve8(Buffer.concat(parts)));
24766
24909
  res.on("error", (err) => reject(fail6(causeCode(err))));
24767
24910
  res.on("aborted", () => reject(fail6("ECONNRESET")));
24768
24911
  });
@@ -28635,12 +28778,12 @@ function readUtf8(absPath) {
28635
28778
  }
28636
28779
  function missingOrOutside(given, abs, root) {
28637
28780
  let dir = abs;
28638
- while (!existsSync14(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
28781
+ while (!existsSync14(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
28639
28782
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
28640
28783
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
28641
28784
  }
28642
28785
  function pathItems(input, project) {
28643
- const abs = resolve6(project.worktree, input.path);
28786
+ const abs = resolve7(project.worktree, input.path);
28644
28787
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
28645
28788
  const base = relative3(project.worktree, abs);
28646
28789
  if (statSync7(abs).isDirectory()) {
@@ -28903,12 +29046,12 @@ var ctxStats = Object.freeze({
28903
29046
  });
28904
29047
 
28905
29048
  // src/core/tools/upgrade.ts
28906
- import { existsSync as existsSync20, realpathSync as realpathSync8, rmSync as rmSync9 } from "node:fs";
28907
- import { basename as basename5, dirname as dirname10, join as join22 } from "node:path";
29049
+ import { existsSync as existsSync20, realpathSync as realpathSync9, rmSync as rmSync9 } from "node:fs";
29050
+ import { basename as basename6, dirname as dirname11, join as join22 } from "node:path";
28908
29051
 
28909
29052
  // src/core/ops/host-write.ts
28910
29053
  import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
28911
- import { dirname as dirname9, join as join17 } from "node:path";
29054
+ import { dirname as dirname10, join as join17 } from "node:path";
28912
29055
  function defaultWrite(file2, text) {
28913
29056
  writeFileSync4(file2, text, "utf8");
28914
29057
  }
@@ -28937,7 +29080,7 @@ function writeWithRollback(file2, text, write2, atomic) {
28937
29080
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
28938
29081
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
28939
29082
  const had = existsSync15(file2);
28940
- mkdirSync5(dirname9(file2), { recursive: true });
29083
+ mkdirSync5(dirname10(file2), { recursive: true });
28941
29084
  if (had) copyFileSync(file2, trash);
28942
29085
  try {
28943
29086
  write2(tmp, text);
@@ -28975,7 +29118,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
28975
29118
 
28976
29119
  // src/core/ops/plugin-swap.ts
28977
29120
  import { existsSync as existsSync16, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
28978
- import { basename as basename4, join as join18, win32 as win322 } from "node:path";
29121
+ import { basename as basename5, join as join18, win32 as win322 } from "node:path";
28979
29122
  function linkTarget(path7, win) {
28980
29123
  if (!isLink(path7)) return null;
28981
29124
  const target = readlinkSync(path7);
@@ -28996,7 +29139,7 @@ function settleLinks(link, tmp, old, opts) {
28996
29139
  function swapPluginCurrent(agentDir, sha, opts = {}) {
28997
29140
  const next = join18(agentDir, sha);
28998
29141
  if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
28999
- throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
29142
+ throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
29000
29143
  }
29001
29144
  const link = join18(agentDir, PLUGIN_CURRENT_LINK);
29002
29145
  const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
@@ -29079,6 +29222,10 @@ function removeCache(adapter, env, configDir) {
29079
29222
  case "extension": {
29080
29223
  const root = rootOrNull(adapter, env);
29081
29224
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
29225
+ if (adapter.installMode === "marketplace") {
29226
+ const cache = join20(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
29227
+ if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
29228
+ }
29082
29229
  rmSync7(root, { recursive: true, force: true });
29083
29230
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
29084
29231
  }
@@ -29364,7 +29511,7 @@ function row4(area, before, after) {
29364
29511
  return { area, before, after };
29365
29512
  }
29366
29513
  function bundleDir() {
29367
- return dirname10(process.argv[1] ?? "");
29514
+ return dirname11(process.argv[1] ?? "");
29368
29515
  }
29369
29516
  function pluginRootRow(adapter, env) {
29370
29517
  const own4 = bundleDir();
@@ -29379,11 +29526,11 @@ function pluginRootRow(adapter, env) {
29379
29526
  }
29380
29527
  function isCurrent(agentDir, dir) {
29381
29528
  const link = join22(agentDir, PLUGIN_CURRENT_LINK);
29382
- return existsSync20(link) && realpathSync8.native(link) === realpathSync8.native(dir);
29529
+ return existsSync20(link) && realpathSync9.native(link) === realpathSync9.native(dir);
29383
29530
  }
29384
29531
  async function checkout(adapter, deps) {
29385
29532
  const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
29386
- const agentDir = dirname10(fetched.dir);
29533
+ const agentDir = dirname11(fetched.dir);
29387
29534
  try {
29388
29535
  verifySums(fetched.dir);
29389
29536
  } catch (err) {
@@ -29411,7 +29558,7 @@ async function upgrade(adapter, deps, home) {
29411
29558
  return rows;
29412
29559
  } catch (err) {
29413
29560
  removal?.rollback();
29414
- if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename5(done.swap.previous));
29561
+ if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename6(done.swap.previous));
29415
29562
  throw err;
29416
29563
  }
29417
29564
  }
@@ -29499,8 +29646,8 @@ function checkCall(tool, input) {
29499
29646
 
29500
29647
  // src/entries/server.ts
29501
29648
  import { randomUUID } from "node:crypto";
29502
- import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync11 } from "node:fs";
29503
- import { dirname as dirname11, join as join24 } from "node:path";
29649
+ import { existsSync as existsSync22, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
29650
+ import { dirname as dirname12, join as join24 } from "node:path";
29504
29651
  import { fileURLToPath as fileURLToPath2 } from "node:url";
29505
29652
 
29506
29653
  // node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
@@ -32979,7 +33126,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
32979
33126
  var NONE3 = 0;
32980
33127
  var ASSUMED = 1;
32981
33128
  var PROVEN = 2;
32982
- function isRecursive(inst, stack, resolve7) {
33129
+ function isRecursive(inst, stack, resolve8) {
32983
33130
  const cached4 = recursive.get(inst);
32984
33131
  if (cached4 !== void 0)
32985
33132
  return cached4 ? PROVEN : NONE3;
@@ -32989,7 +33136,7 @@ function isRecursive(inst, stack, resolve7) {
32989
33136
  let result = NONE3;
32990
33137
  const check2 = (child) => {
32991
33138
  if (result !== PROVEN && child?._zod) {
32992
- const answer2 = isRecursive(child, stack, resolve7);
33139
+ const answer2 = isRecursive(child, stack, resolve8);
32993
33140
  if (answer2 > result)
32994
33141
  result = answer2;
32995
33142
  }
@@ -33000,7 +33147,7 @@ function isRecursive(inst, stack, resolve7) {
33000
33147
  const desc = Object.getOwnPropertyDescriptor(sh, key);
33001
33148
  if (spread && !desc.enumerable)
33002
33149
  continue;
33003
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve7) : NONE3;
33150
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve8) : NONE3;
33004
33151
  if (child > answer2)
33005
33152
  answer2 = child;
33006
33153
  }
@@ -33064,7 +33211,7 @@ function isRecursive(inst, stack, resolve7) {
33064
33211
  break;
33065
33212
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
33066
33213
  case "lazy": {
33067
- const inner = def._cachedInner ?? (resolve7 ? inst._zod.innerType : void 0);
33214
+ const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
33068
33215
  merge5(inner ? isRecursive(inner, stack, false) : ASSUMED);
33069
33216
  break;
33070
33217
  }
@@ -40508,7 +40655,7 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
40508
40655
  var NONE4 = 0;
40509
40656
  var ASSUMED2 = 1;
40510
40657
  var PROVEN2 = 2;
40511
- function isRecursive2(inst, stack, resolve7) {
40658
+ function isRecursive2(inst, stack, resolve8) {
40512
40659
  const cached4 = recursive2.get(inst);
40513
40660
  if (cached4 !== void 0)
40514
40661
  return cached4 ? PROVEN2 : NONE4;
@@ -40518,7 +40665,7 @@ function isRecursive2(inst, stack, resolve7) {
40518
40665
  let result = NONE4;
40519
40666
  const check2 = (child) => {
40520
40667
  if (result !== PROVEN2 && child?._zod) {
40521
- const answer2 = isRecursive2(child, stack, resolve7);
40668
+ const answer2 = isRecursive2(child, stack, resolve8);
40522
40669
  if (answer2 > result)
40523
40670
  result = answer2;
40524
40671
  }
@@ -40529,7 +40676,7 @@ function isRecursive2(inst, stack, resolve7) {
40529
40676
  const desc = Object.getOwnPropertyDescriptor(sh, key);
40530
40677
  if (spread && !desc.enumerable)
40531
40678
  continue;
40532
- const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve7) : NONE4;
40679
+ const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack, resolve8) : NONE4;
40533
40680
  if (child > answer2)
40534
40681
  answer2 = child;
40535
40682
  }
@@ -40593,7 +40740,7 @@ function isRecursive2(inst, stack, resolve7) {
40593
40740
  break;
40594
40741
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
40595
40742
  case "lazy": {
40596
- const inner = def._cachedInner ?? (resolve7 ? inst._zod.innerType : void 0);
40743
+ const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
40597
40744
  merge5(inner ? isRecursive2(inner, stack, false) : ASSUMED2);
40598
40745
  break;
40599
40746
  }
@@ -47197,14 +47344,14 @@ function inputRequiredRoundsExceededMessage(method, maxRounds) {
47197
47344
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
47198
47345
  }
47199
47346
  function sleep(ms, signal) {
47200
- return new Promise((resolve7, reject) => {
47347
+ return new Promise((resolve8, reject) => {
47201
47348
  if (signal?.aborted) {
47202
47349
  reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
47203
47350
  return;
47204
47351
  }
47205
47352
  const timer = setTimeout(() => {
47206
47353
  signal?.removeEventListener("abort", onAbort);
47207
- resolve7();
47354
+ resolve8();
47208
47355
  }, ms);
47209
47356
  const onAbort = () => {
47210
47357
  clearTimeout(timer);
@@ -48003,7 +48150,7 @@ var Protocol = class {
48003
48150
  const flowStartedAt = Date.now();
48004
48151
  let onAbort;
48005
48152
  let cleanupMessageId;
48006
- return new Promise((resolve7, reject) => {
48153
+ return new Promise((resolve8, reject) => {
48007
48154
  const earlyReject = (error42) => {
48008
48155
  reject(error42);
48009
48156
  };
@@ -48072,7 +48219,7 @@ var Protocol = class {
48072
48219
  }
48073
48220
  if (decoded.kind === "invalid") return reject(decoded.error);
48074
48221
  if (decoded.kind === "input_required") {
48075
- if (options?.allowInputRequired === true) return resolve7(manualInputRequiredValue(decoded));
48222
+ if (options?.allowInputRequired === true) return resolve8(manualInputRequiredValue(decoded));
48076
48223
  const flow = {
48077
48224
  codec,
48078
48225
  request: request2,
@@ -48084,11 +48231,11 @@ var Protocol = class {
48084
48231
  params
48085
48232
  }, resultSchema, legOptions)
48086
48233
  };
48087
- return resolve7(this._resolveNonCompleteResult(decoded, flow));
48234
+ return resolve8(this._resolveNonCompleteResult(decoded, flow));
48088
48235
  }
48089
48236
  const result = decoded.result;
48090
48237
  validateStandardSchema(resultSchema, result).then((parseResult) => {
48091
- if (parseResult.success) resolve7(parseResult.data);
48238
+ if (parseResult.success) resolve8(parseResult.data);
48092
48239
  else reject(new SdkError(SdkErrorCode.InvalidResult, `Invalid result for ${request2.method}: ${parseResult.error}`));
48093
48240
  }, reject);
48094
48241
  });
@@ -51004,7 +51151,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
51004
51151
  ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, ref);
51005
51152
  const schOrFunc = root.refs[ref];
51006
51153
  if (schOrFunc) return schOrFunc;
51007
- let _sch = resolve7.call(this, root, ref);
51154
+ let _sch = resolve8.call(this, root, ref);
51008
51155
  if (_sch === void 0) {
51009
51156
  const schema = (_a5 = root.localRefs) === null || _a5 === void 0 ? void 0 : _a5[ref];
51010
51157
  const { schemaId } = this.opts;
@@ -51030,7 +51177,7 @@ var require_compile = /* @__PURE__ */ __commonJSMin((exports) => {
51030
51177
  function sameSchemaEnv(s1, s2) {
51031
51178
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
51032
51179
  }
51033
- function resolve7(root, ref) {
51180
+ function resolve8(root, ref) {
51034
51181
  let sch;
51035
51182
  while (typeof (sch = this.refs[ref]) == "string") ref = sch;
51036
51183
  return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
@@ -51480,7 +51627,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
51480
51627
  else if (typeof uri === "object") uri = parse6(serialize(uri, options), options);
51481
51628
  return uri;
51482
51629
  }
51483
- function resolve7(baseURI, relativeURI, options) {
51630
+ function resolve8(baseURI, relativeURI, options) {
51484
51631
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
51485
51632
  const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
51486
51633
  schemelessOptions.skipEscape = true;
@@ -51654,7 +51801,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin((exports, module) => {
51654
51801
  const fastUri = {
51655
51802
  SCHEMES,
51656
51803
  normalize: normalize2,
51657
- resolve: resolve7,
51804
+ resolve: resolve8,
51658
51805
  resolveComponent,
51659
51806
  equal,
51660
51807
  serialize,
@@ -57119,7 +57266,7 @@ var StdioServerTransport = class {
57119
57266
  }
57120
57267
  send(message3) {
57121
57268
  if (this._closed) return Promise.reject(/* @__PURE__ */ new Error("StdioServerTransport is closed"));
57122
- return new Promise((resolve7, reject) => {
57269
+ return new Promise((resolve8, reject) => {
57123
57270
  const json2 = serializeMessage(message3);
57124
57271
  let settled = false;
57125
57272
  const onError = (error42) => {
@@ -57134,14 +57281,14 @@ var StdioServerTransport = class {
57134
57281
  settled = true;
57135
57282
  this._stdout.off("error", onError);
57136
57283
  this._stdout.off("drain", onDrain);
57137
- resolve7();
57284
+ resolve8();
57138
57285
  };
57139
57286
  this._stdout.once("error", onError);
57140
57287
  if (this._stdout.write(json2)) {
57141
57288
  if (settled) return;
57142
57289
  settled = true;
57143
57290
  this._stdout.off("error", onError);
57144
- resolve7();
57291
+ resolve8();
57145
57292
  } else if (!settled) this._stdout.once("drain", onDrain);
57146
57293
  });
57147
57294
  }
@@ -57195,14 +57342,14 @@ var StdioConnectionChannel = class {
57195
57342
  */
57196
57343
  async whenRequestsAnswered(timeoutMs) {
57197
57344
  if (this._closed || this._pendingRequests.size === 0) return true;
57198
- return await new Promise((resolve7) => {
57345
+ return await new Promise((resolve8) => {
57199
57346
  const waiter = () => {
57200
57347
  clearTimeout(timer);
57201
- resolve7(true);
57348
+ resolve8(true);
57202
57349
  };
57203
57350
  const timer = setTimeout(() => {
57204
57351
  this._drainWaiters = this._drainWaiters.filter((pending) => pending !== waiter);
57205
- resolve7(false);
57352
+ resolve8(false);
57206
57353
  }, timeoutMs);
57207
57354
  this._drainWaiters.push(waiter);
57208
57355
  });
@@ -57655,12 +57802,12 @@ function sweepDeadProjects(configDir) {
57655
57802
  }
57656
57803
 
57657
57804
  // src/entries/is-entry.ts
57658
- import { realpathSync as realpathSync9 } from "node:fs";
57805
+ import { realpathSync as realpathSync10 } from "node:fs";
57659
57806
  function isEntry(main, argv1, self) {
57660
57807
  if (main !== void 0) return main;
57661
57808
  if (argv1 === void 0 || argv1 === "") return false;
57662
57809
  try {
57663
- return realpathSync9(argv1) === realpathSync9(self);
57810
+ return realpathSync10(argv1) === realpathSync10(self);
57664
57811
  } catch {
57665
57812
  return false;
57666
57813
  }
@@ -57736,7 +57883,7 @@ function workspaceFromMeta(meta3) {
57736
57883
  }
57737
57884
  function realOrSame(p) {
57738
57885
  try {
57739
- return realpathSync10.native(p);
57886
+ return realpathSync11.native(p);
57740
57887
  } catch {
57741
57888
  return p;
57742
57889
  }
@@ -57745,7 +57892,7 @@ function workspaceCwdOf(meta3, spawnCwd, script) {
57745
57892
  const fromHost = workspaceFromMeta(meta3);
57746
57893
  if (fromHost !== void 0) return fromHost;
57747
57894
  if (script === void 0 || script === "") return spawnCwd;
57748
- return realOrSame(spawnCwd) === realOrSame(dirname11(script)) ? "" : spawnCwd;
57895
+ return realOrSame(spawnCwd) === realOrSame(dirname12(script)) ? "" : spawnCwd;
57749
57896
  }
57750
57897
  function errorReply(err) {
57751
57898
  if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
@@ -57899,7 +58046,7 @@ async function startServer(argv, env) {
57899
58046
  }
57900
58047
  installExitGuard({ onShutdown: shutdown, isTTY: process.stdin.isTTY === true });
57901
58048
  handle = serveStdio(createServer);
57902
- await new Promise((resolve7) => process.once("exit", () => resolve7()));
58049
+ await new Promise((resolve8) => process.once("exit", () => resolve8()));
57903
58050
  }
57904
58051
  if (isEntry(import.meta.main, process.argv[1], fileURLToPath2(import.meta.url))) {
57905
58052
  const [, , ...cliArgs] = process.argv;