@yawlabs/mcp 1.1.10 → 1.1.12

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.
@@ -5,6 +5,7 @@ import { spawn as spawn3 } from "child_process";
5
5
  import { createHash } from "crypto";
6
6
  import {
7
7
  closeSync,
8
+ existsSync as existsSync3,
8
9
  openSync,
9
10
  readFileSync as readFileSync4,
10
11
  realpathSync as realpathSync3,
@@ -161,10 +162,13 @@ function stripInternalSecretsFromEnv(env) {
161
162
 
162
163
  // src/logger.ts
163
164
  var LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
164
- function resolveLogLevel() {
165
- const raw = process.env.LOG_LEVEL?.trim().toLowerCase();
165
+ function readLevelVar(name) {
166
+ const raw = process.env[name]?.trim().toLowerCase();
166
167
  return raw !== void 0 && Object.hasOwn(LOG_LEVELS, raw) ? raw : null;
167
168
  }
169
+ function resolveLogLevel() {
170
+ return readLevelVar("YAW_MCP_LOG_LEVEL") ?? readLevelVar("LOG_LEVEL");
171
+ }
168
172
  function minLevel() {
169
173
  const level = resolveLogLevel();
170
174
  return level === null ? LOG_LEVELS.info : LOG_LEVELS[level];
@@ -183,7 +187,7 @@ function setLogSurface(next) {
183
187
  surface = next;
184
188
  }
185
189
  function logLevelRequested() {
186
- return resolveLogLevel() !== null;
190
+ return readLevelVar("YAW_MCP_LOG_LEVEL") !== null;
187
191
  }
188
192
  function renderData(data) {
189
193
  if (data === void 0) return "";
@@ -278,7 +282,7 @@ import { join as join11 } from "path";
278
282
  import { spawn } from "child_process";
279
283
  import { accessSync, constants, existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
280
284
  import { homedir as homedir4 } from "os";
281
- import { dirname as dirname3, isAbsolute as isAbsolute8, join as join10, sep } from "path";
285
+ import { dirname as dirname3, isAbsolute as isAbsolute8, join as join10, resolve as resolve8, sep } from "path";
282
286
  import { fileURLToPath } from "url";
283
287
 
284
288
  // src/install-targets.ts
@@ -671,6 +675,17 @@ function spliceEdits(text, path5, value) {
671
675
  }
672
676
  return null;
673
677
  }
678
+ function duplicateJsoncKeyOnPath(src, path5) {
679
+ const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
680
+ let node = parseTree(debommed, [], { allowTrailingComma: true });
681
+ for (let i = 0; i < path5.length; i++) {
682
+ if (node === void 0 || node.type !== "object") return null;
683
+ const matches = (node.children ?? []).filter((member) => member.children?.[0]?.value === path5[i]);
684
+ if (matches.length > 1) return { path: path5.slice(0, i + 1), count: matches.length };
685
+ node = matches[0]?.children?.[1];
686
+ }
687
+ return null;
688
+ }
674
689
  function computeEdits(text, path5, value) {
675
690
  return spliceEdits(text, path5, value) ?? modify(text, path5, value, { formattingOptions: FORMATTING_OPTIONS });
676
691
  }
@@ -908,11 +923,22 @@ function classifyJson(raw, addr, transform, strict) {
908
923
  if (container === null) return { kind: "ok", containerPresent: false, entries: [], unloadable };
909
924
  return { kind: "ok", containerPresent: true, entries: entriesOf(container, transform), unloadable };
910
925
  }
926
+ function refuseDuplicateKey(raw, path5) {
927
+ const duplicate = duplicateJsoncKeyOnPath(raw, path5);
928
+ if (duplicate === null) return;
929
+ const key = duplicate.path[duplicate.path.length - 1];
930
+ const parent = duplicate.path.slice(0, -1);
931
+ const under = parent.length === 0 ? "at the top level" : `under ${JSON.stringify(parent.join("."))}`;
932
+ throw new Error(
933
+ `${JSON.stringify(key)} is defined ${duplicate.count} times ${under}; a JSON parser reads only the last definition, so delete the others by hand, then re-run`
934
+ );
935
+ }
911
936
  function upsertJson(raw, addr, key, entry) {
912
937
  if (raw === null || raw.trim().length === 0) {
913
938
  return `${JSON.stringify(buildFreshConfig(addr.containerPath, key, entry), null, 2)}
914
939
  `;
915
940
  }
941
+ refuseDuplicateKey(raw, [...addr.containerPath, key]);
916
942
  return editJsoncEntry(raw, [...addr.containerPath], key, entry);
917
943
  }
918
944
  function removeJson(raw, addr, key) {
@@ -925,6 +951,7 @@ function removeJson(raw, addr, key) {
925
951
  if (!isRecord2(parsed)) return raw;
926
952
  const container = containerAt(parsed, addr.containerPath);
927
953
  if (container === null || !Object.hasOwn(container, key)) return raw;
954
+ refuseDuplicateKey(raw, [...addr.containerPath, key]);
928
955
  return removeJsoncEntry(raw, [...addr.containerPath], key);
929
956
  }
930
957
  function repairJson(raw, _addr, blockedPath) {
@@ -1037,9 +1064,11 @@ function unloadableConfigProblem(v) {
1037
1064
  function unloadableConfigFix(then) {
1038
1065
  return `remove the comments and trailing commas, or move the file aside, then ${then}`;
1039
1066
  }
1040
- function carryableEnvOf(stored) {
1041
- if (!isRecord(stored)) return void 0;
1042
- return stringMap(stored.env);
1067
+ function carryableEnvOf(stored, transform) {
1068
+ const normalized = normalizeEntry(stored, transform);
1069
+ const from = isRecord(normalized) ? normalized : stored;
1070
+ if (!isRecord(from)) return void 0;
1071
+ return stringMap(from.env);
1043
1072
  }
1044
1073
  function carriedFieldsOf(stored, transform) {
1045
1074
  if (transform?.carry === void 0) return {};
@@ -1171,7 +1200,7 @@ function makeView(read, raw, address, addressIndex, adapter, opts) {
1171
1200
  return entries.filter((e) => !skip.has(e.key) && isRecord(e.value)).map((e) => e.key);
1172
1201
  },
1173
1202
  count: () => entries.length,
1174
- carryableEnv: (key) => carryableEnvOf(at(key)?.value),
1203
+ carryableEnv: (key) => carryableEnvOf(at(key)?.value, opts.transform),
1175
1204
  carried: (key) => carriedFieldsOf(at(key)?.value, opts.transform),
1176
1205
  unloadable: () => read.kind === "ok" || read.kind === "blocked" ? read.unloadable : null
1177
1206
  };
@@ -1257,6 +1286,10 @@ function decodeClientConfigBytes(bytes, format) {
1257
1286
  }
1258
1287
  async function readClientConfigFile(site, opts = {}) {
1259
1288
  const load = opts.readFile ?? ((path5) => readFile(path5));
1289
+ const firstAddress = {
1290
+ format: site.format,
1291
+ containerPath: opts.containerPaths?.[0] ?? site.resolved.containerPath
1292
+ };
1260
1293
  let loaded;
1261
1294
  try {
1262
1295
  loaded = await load(site.resolved.absolute);
@@ -1268,16 +1301,12 @@ async function readClientConfigFile(site, opts = {}) {
1268
1301
  code: typeof code === "string" ? code : null,
1269
1302
  message: err instanceof Error ? err.message : String(err)
1270
1303
  };
1271
- return makeView(read, null, addressOf(site), 0, adapterFor(site.format), opts);
1304
+ return makeView(read, null, firstAddress, 0, adapterFor(site.format), opts);
1272
1305
  }
1273
1306
  if (typeof loaded === "string") return classifyClientConfig(loaded, site, opts);
1274
1307
  const decoded = decodeClientConfigBytes(loaded, site.format);
1275
1308
  if (decoded.malformed === null) return classifyClientConfig(decoded.text, site, opts);
1276
- const address = {
1277
- format: site.format,
1278
- containerPath: opts.containerPaths?.[0] ?? site.resolved.containerPath
1279
- };
1280
- return makeView(decoded.malformed, decoded.text, address, 0, adapterFor(site.format), opts);
1309
+ return makeView(decoded.malformed, decoded.text, firstAddress, 0, adapterFor(site.format), opts);
1281
1310
  }
1282
1311
  var ClientConfigWriteError = class extends Error {
1283
1312
  constructor(message) {
@@ -1369,11 +1398,15 @@ function applyClientConfigEdits(view, edits, site) {
1369
1398
  verifyEdits(adapter, address, before, text, edits, where, view);
1370
1399
  return text;
1371
1400
  }
1401
+ function configPositionClause(position) {
1402
+ return position === null ? "" : ` at line ${position.line} column ${position.column}`;
1403
+ }
1372
1404
  function refusalFor(read, where, edits) {
1373
1405
  if (read.kind === "unreadable") return `${where} could not be read (${read.message})`;
1374
1406
  if (read.kind === "malformed") {
1375
- const at = read.position === null ? "" : ` at line ${read.position.line} column ${read.position.column}`;
1376
- return read.reason === "root" ? `${where} is not a ${read.syntax} object (it is ${read.detail})` : `${where} is not valid ${read.syntax}${at} (${read.detail})`;
1407
+ const at = configPositionClause(read.position);
1408
+ const detail = at !== "" && read.detail.endsWith(at) ? read.detail.slice(0, -at.length) : read.detail;
1409
+ return read.reason === "root" ? `${where} is not a ${read.syntax} object (it is ${read.detail})` : `${where} is not valid ${read.syntax}${at} (${detail})`;
1377
1410
  }
1378
1411
  if (read.kind === "unspliceable") {
1379
1412
  const fix = read.fix === void 0 ? "" : `; ${read.fix}, then re-run`;
@@ -1743,6 +1776,17 @@ import { isAbsolute as isAbsolute2, join as join3, resolve as resolve2 } from "p
1743
1776
 
1744
1777
  // src/client-config-toml.ts
1745
1778
  import { parse as parseTomlText, TomlDate, TomlError } from "smol-toml";
1779
+
1780
+ // src/json-key.ts
1781
+ function setJsonKey(target, key, value) {
1782
+ if (key === "__proto__") {
1783
+ Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
1784
+ return;
1785
+ }
1786
+ target[key] = value;
1787
+ }
1788
+
1789
+ // src/client-config-toml.ts
1746
1790
  var TOML_SYNTAX = "TOML";
1747
1791
  var PARSE_OPTIONS = { integersAsBigInt: "asNeeded" };
1748
1792
  var TomlConfigError = class extends Error {
@@ -2254,10 +2298,10 @@ function entryAsWritten(entry) {
2254
2298
  if (SUBTABLE_FIELDS.has(key) && isTomlTable(value)) {
2255
2299
  const pairs = Object.entries(value).filter(([, v]) => v !== void 0);
2256
2300
  if (pairs.length === 0) continue;
2257
- out[key] = Object.fromEntries(pairs);
2301
+ setJsonKey(out, key, Object.fromEntries(pairs));
2258
2302
  continue;
2259
2303
  }
2260
- out[key] = value;
2304
+ setJsonKey(out, key, value);
2261
2305
  }
2262
2306
  return out;
2263
2307
  }
@@ -2519,7 +2563,7 @@ function canonValue(value) {
2519
2563
  const out = {};
2520
2564
  for (const key of Object.keys(value).sort()) {
2521
2565
  if (value[key] === void 0) continue;
2522
- out[key] = canonValue(value[key]);
2566
+ setJsonKey(out, key, canonValue(value[key]));
2523
2567
  }
2524
2568
  return out;
2525
2569
  }
@@ -2709,14 +2753,16 @@ function classifyToml(raw, addr, transform) {
2709
2753
  switch (read.kind) {
2710
2754
  case "absent":
2711
2755
  return { kind: "absent" };
2712
- case "malformed":
2756
+ case "malformed": {
2757
+ const position = tomlPosition(raw, read.line, read.column);
2713
2758
  return {
2714
2759
  kind: "malformed",
2715
2760
  syntax: TOML_SYNTAX,
2716
2761
  reason: "syntax",
2717
- detail: read.detail,
2718
- position: tomlPosition(raw, read.line, read.column)
2762
+ detail: `${read.detail}${configPositionClause(position)}`,
2763
+ position
2719
2764
  };
2765
+ }
2720
2766
  case "blocked":
2721
2767
  if (read.path.length === 0) {
2722
2768
  return { kind: "malformed", syntax: TOML_SYNTAX, reason: "root", detail: read.shape, position: null };
@@ -2832,38 +2878,21 @@ function normalizeCodexEntry(stored) {
2832
2878
  const { startup_timeout_ms: _dropped, ...rest } = record;
2833
2879
  return { ...rest, startup_timeout_sec: ms / 1e3 };
2834
2880
  }
2835
- var IMPORT_DISCARDS = [
2836
- "env_vars",
2837
- "cwd",
2838
- "startup_timeout_sec",
2839
- "startup_timeout_ms",
2840
- "tool_timeout_sec",
2841
- "enabled_tools",
2842
- "disabled_tools",
2843
- "default_tools_approval_mode",
2844
- "bearer_token_env_var",
2845
- "env_http_headers",
2846
- "http_headers_helper",
2847
- "experimental_environment",
2848
- "environment_id",
2849
- "required",
2850
- "supports_parallel_tool_calls",
2851
- "auth",
2852
- "oauth",
2853
- "tools"
2854
- ];
2881
+ var IMPORT_FIELDS = ["command", "args", "env", "url", "headers", "type", "description"];
2882
+ var IMPORT_MAPPED = ["enabled", "http_headers"];
2855
2883
  function codexImportView(stored) {
2856
2884
  const entry = {};
2885
+ const discarded = [];
2857
2886
  for (const [key, value] of Object.entries(stored)) {
2858
- if (IMPORT_DISCARDS.includes(key) || key === "enabled" || key === "http_headers") continue;
2859
- entry[key] = value;
2887
+ if (IMPORT_MAPPED.includes(key) || value === void 0) continue;
2888
+ if (IMPORT_FIELDS.includes(key)) entry[key] = value;
2889
+ else discarded.push(key);
2860
2890
  }
2861
2891
  if (typeof stored.http_headers === "object" && stored.http_headers !== null && !Array.isArray(stored.http_headers)) {
2862
2892
  entry.headers = stored.http_headers;
2863
2893
  }
2864
2894
  const view = { entry };
2865
2895
  if (stored.enabled === false) view.disabled = true;
2866
- const discarded = IMPORT_DISCARDS.filter((key) => stored[key] !== void 0);
2867
2896
  if (discarded.length > 0) view.discardedKeys = discarded;
2868
2897
  return view;
2869
2898
  }
@@ -2961,8 +2990,9 @@ function resolveContinuePath(base) {
2961
2990
  var CONTINUE_TARGET = defineTarget({
2962
2991
  clientId: "continue",
2963
2992
  label: "Continue",
2964
- // DEDICATED: this file is created by install and holds nothing else, unlike
2965
- // every other row's shared user config.
2993
+ // DEDICATED: install creates this file itself, where every other row is
2994
+ // handed a user config. It is data only -- nothing reads it, and a user may
2995
+ // still add servers to the file (see the header).
2966
2996
  config: { format: "jsonc", root: "mcpServers", ownership: "dedicated" },
2967
2997
  availableOn: ["macos", "linux", "windows"],
2968
2998
  // Continue's VS Code extension does not watch the mcpServers folder, so the
@@ -3495,7 +3525,8 @@ function resolveInstallPath(opts) {
3495
3525
  home: base.home,
3496
3526
  appData: base.appData,
3497
3527
  projectDir: base.projectDir,
3498
- claudeConfigDir: base.env.claudeConfigDir
3528
+ claudeConfigDir: base.env.claudeConfigDir,
3529
+ xdgConfigHome: base.env.xdgConfigHome
3499
3530
  });
3500
3531
  }
3501
3532
  function resolveInstallSites(opts) {
@@ -3619,7 +3650,7 @@ function claudeCodeProjectSites(site, keysAt) {
3619
3650
  return out;
3620
3651
  }
3621
3652
  function pathFor(client, scope, os, base) {
3622
- const { home, appData, projectDir, claudeConfigDir } = base;
3653
+ const { home, appData, projectDir, claudeConfigDir, xdgConfigHome } = base;
3623
3654
  const sep3 = os === "windows" ? "\\" : "/";
3624
3655
  const joinPath = (...parts) => parts.join(sep3);
3625
3656
  if (client === "claude-code") {
@@ -3693,6 +3724,14 @@ function pathFor(client, scope, os, base) {
3693
3724
  containerPath: ["servers"]
3694
3725
  };
3695
3726
  }
3727
+ const xdg = xdgConfigHome?.trim();
3728
+ if (xdg && isAbsolute6(xdg)) {
3729
+ return {
3730
+ absolute: join8(xdg, "Code", "User", "mcp.json"),
3731
+ display: "$XDG_CONFIG_HOME/Code/User/mcp.json",
3732
+ containerPath: ["servers"]
3733
+ };
3734
+ }
3696
3735
  return {
3697
3736
  absolute: join8(home, ".config", "Code", "User", "mcp.json"),
3698
3737
  display: "~/.config/Code/User/mcp.json",
@@ -3757,6 +3796,11 @@ function isCmdShimLauncher(command) {
3757
3796
  return true;
3758
3797
  }
3759
3798
  function escapeCmdArg(arg, opts) {
3799
+ if (/[\r\n]/.test(arg)) {
3800
+ throw new Error(
3801
+ `Cannot encode an argument that contains a line break (CR or LF) for the Windows cmd /c launcher: ${JSON.stringify(arg)} -- cmd.exe stops reading its command line at a line break, so the server would be started with a truncated argument. Rework the server's args to drop the line break.`
3802
+ );
3803
+ }
3760
3804
  if (arg.includes('"')) {
3761
3805
  if (HAS_CMD_METACHAR.test(arg)) {
3762
3806
  throw new Error(
@@ -3811,28 +3855,6 @@ function isProjectLocalEntry(entryPath, cwd, platform = process.platform) {
3811
3855
  function findLegacyEntry(container) {
3812
3856
  return LEGACY_ENTRY_NAMES.find((n) => n in container) ?? null;
3813
3857
  }
3814
- function findBlockedContainerSegment(root, containerPath) {
3815
- let node = root;
3816
- for (let i = 0; i < containerPath.length; i++) {
3817
- const value = node[containerPath[i]];
3818
- if (value === void 0) return null;
3819
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
3820
- node = value;
3821
- continue;
3822
- }
3823
- return {
3824
- path: containerPath.slice(0, i + 1),
3825
- value,
3826
- reparable: value === null || !Array.isArray(value) || value.length === 0
3827
- };
3828
- }
3829
- return null;
3830
- }
3831
- function describeJsonShape(value) {
3832
- if (value === null) return "null";
3833
- if (Array.isArray(value)) return value.length === 0 ? "an empty array" : `an array of ${value.length}`;
3834
- return `a ${typeof value}`;
3835
- }
3836
3858
  function unparseableConfigFix(then, syntax = "JSON") {
3837
3859
  return `fix the ${syntax} by hand, or move the file aside, then ${then}`;
3838
3860
  }
@@ -4105,15 +4127,6 @@ async function withFileLock(path5, opts, describeTimeout, fn) {
4105
4127
  }
4106
4128
  }
4107
4129
 
4108
- // src/json-key.ts
4109
- function setJsonKey(target, key, value) {
4110
- if (key === "__proto__") {
4111
- Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
4112
- return;
4113
- }
4114
- target[key] = value;
4115
- }
4116
-
4117
4130
  // src/persistence.ts
4118
4131
  var STATE_SCHEMA_VERSION = 2;
4119
4132
  var STATE_FILENAME = "state.json";
@@ -4143,24 +4156,46 @@ var NO_RAW_COUNTS = { learning: 0, packHistory: 0, toolCache: 0, prewarmFailures
4143
4156
  async function loadState(filePath = statePath()) {
4144
4157
  return (await loadStateClassified(filePath)).state;
4145
4158
  }
4146
- async function loadStateClassified(filePath = statePath()) {
4159
+ async function loadStateClassified(filePath = statePath(), options = {}) {
4160
+ const quiet = options.quiet === true;
4147
4161
  let raw;
4148
4162
  try {
4149
4163
  raw = await readFile4(filePath, "utf8");
4150
4164
  } catch (err) {
4151
4165
  if (isFileNotFound(err) || err.code === "ENOTDIR")
4152
- return { state: emptyState(), rawCounts: NO_RAW_COUNTS, parsedCleanly: true };
4153
- log("warn", "Could not read yaw-mcp state file; flagged unreadable so a save cannot overwrite it", {
4154
- error: errorMessage(err)
4155
- });
4156
- return { state: { ...emptyState(), loadFailed: true }, rawCounts: NO_RAW_COUNTS, parsedCleanly: false };
4166
+ return { state: emptyState(), rawCounts: NO_RAW_COUNTS, parsedCleanly: true, missing: true, failure: null };
4167
+ if (!quiet) {
4168
+ log("warn", "Could not read yaw-mcp state file; flagged unreadable so a save cannot overwrite it", {
4169
+ error: errorMessage(err)
4170
+ });
4171
+ }
4172
+ return {
4173
+ state: { ...emptyState(), loadFailed: true },
4174
+ rawCounts: NO_RAW_COUNTS,
4175
+ parsedCleanly: false,
4176
+ missing: false,
4177
+ failure: { kind: "unreadable", message: errorMessage(err) }
4178
+ };
4157
4179
  }
4158
4180
  try {
4159
4181
  const parsed = JSON.parse(raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw);
4160
- if (!parsed || typeof parsed !== "object")
4161
- return { state: emptyState(), rawCounts: NO_RAW_COUNTS, parsedCleanly: false };
4162
- if (!isReadableStateVersion(parsed.version))
4163
- return { state: emptyState(), rawCounts: NO_RAW_COUNTS, parsedCleanly: false };
4182
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
4183
+ return {
4184
+ state: emptyState(),
4185
+ rawCounts: NO_RAW_COUNTS,
4186
+ parsedCleanly: false,
4187
+ missing: false,
4188
+ failure: { kind: "malformed", message: "top-level value is not an object" }
4189
+ };
4190
+ const version = parsed.version;
4191
+ if (!isReadableStateVersion(version))
4192
+ return {
4193
+ state: emptyState(),
4194
+ rawCounts: NO_RAW_COUNTS,
4195
+ parsedCleanly: false,
4196
+ missing: false,
4197
+ failure: { kind: "stale-version", version }
4198
+ };
4164
4199
  const p = parsed;
4165
4200
  return {
4166
4201
  state: {
@@ -4181,11 +4216,19 @@ async function loadStateClassified(filePath = statePath()) {
4181
4216
  toolCache: countRawEntries(p.toolCache),
4182
4217
  prewarmFailures: countRawEntries(p.prewarmFailures)
4183
4218
  },
4184
- parsedCleanly: true
4219
+ parsedCleanly: true,
4220
+ missing: false,
4221
+ failure: null
4185
4222
  };
4186
4223
  } catch (err) {
4187
- log("warn", "Failed to load yaw-mcp state, starting fresh", { error: errorMessage(err) });
4188
- return { state: emptyState(), rawCounts: NO_RAW_COUNTS, parsedCleanly: false };
4224
+ if (!quiet) log("warn", "Failed to load yaw-mcp state, starting fresh", { error: errorMessage(err) });
4225
+ return {
4226
+ state: emptyState(),
4227
+ rawCounts: NO_RAW_COUNTS,
4228
+ parsedCleanly: false,
4229
+ missing: false,
4230
+ failure: { kind: "malformed", message: errorMessage(err) }
4231
+ };
4189
4232
  }
4190
4233
  }
4191
4234
  function countRawEntries(input) {
@@ -4501,13 +4544,23 @@ function oamBinaryIdentity(absPath) {
4501
4544
  return null;
4502
4545
  }
4503
4546
  }
4547
+ function isStoredEntry(value) {
4548
+ if (typeof value !== "object" || value === null) return false;
4549
+ const e = value;
4550
+ return typeof e.size === "number" && typeof e.mtimeMs === "number" && (e.version === null || typeof e.version === "string") && typeof e.probedAt === "string";
4551
+ }
4504
4552
  function readFileEntries() {
4505
4553
  try {
4506
4554
  const parsed = JSON.parse(readFileSync(verdictFile(), "utf8"));
4507
4555
  if (!parsed || parsed.schema !== SCHEMA || typeof parsed.entries !== "object" || parsed.entries === null) {
4508
4556
  return {};
4509
4557
  }
4510
- return parsed.entries;
4558
+ if (Array.isArray(parsed.entries)) return {};
4559
+ const entries = {};
4560
+ for (const [key, value] of Object.entries(parsed.entries)) {
4561
+ if (isStoredEntry(value)) entries[key] = value;
4562
+ }
4563
+ return entries;
4511
4564
  } catch {
4512
4565
  return {};
4513
4566
  }
@@ -4519,7 +4572,6 @@ function readOamVerdict(id) {
4519
4572
  if (isPersistenceDisabled()) return void 0;
4520
4573
  const entry = readFileEntries()[keyOf(id.path)];
4521
4574
  if (!entry || entry.size !== id.size || entry.mtimeMs !== id.mtimeMs) return void 0;
4522
- if (entry.version !== null && typeof entry.version !== "string") return void 0;
4523
4575
  return entry.version;
4524
4576
  }
4525
4577
  async function writeOamVerdict(id, version) {
@@ -4647,7 +4699,11 @@ function specSuffix(spec) {
4647
4699
  const at = spec.indexOf("@", start);
4648
4700
  return at === -1 ? null : spec.slice(at + 1);
4649
4701
  }
4650
- var EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
4702
+ var SEMVER_IDENTIFIERS = "[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*";
4703
+ var SEMVER_SOURCE = `(\\d+)\\.(\\d+)\\.(\\d+)(?:-(${SEMVER_IDENTIFIERS}))?(?:\\+${SEMVER_IDENTIFIERS})?`;
4704
+ var EXACT_VERSION = new RegExp(`^${SEMVER_SOURCE}$`);
4705
+ var VERSION_IN_TEXT = new RegExp(SEMVER_SOURCE);
4706
+ var LEADING_VERSION = new RegExp(`^${SEMVER_SOURCE}`);
4651
4707
  function specConstraint(spec) {
4652
4708
  const suffix = specSuffix(spec);
4653
4709
  if (suffix === null || suffix === "") return { kind: "any" };
@@ -4671,7 +4727,7 @@ function npxSpec(args) {
4671
4727
  const spec = args[idx];
4672
4728
  return spec.startsWith("-") ? null : spec;
4673
4729
  }
4674
- var MIN_OAM_VERSION = "0.19.5";
4730
+ var MIN_OAM_VERSION = "0.20.1";
4675
4731
  var OAM_INSTALL_SH = "curl -fsSL https://oamjs.org/install.sh | sh";
4676
4732
  var OAM_INSTALL_PS1 = "irm https://oamjs.org/install.ps1 | iex";
4677
4733
  function oamInstallCommand(os) {
@@ -4708,7 +4764,7 @@ function oamHeapOomHint(stderr) {
4708
4764
  if (!stderr.includes("OAM-RT-OOM")) return null;
4709
4765
  return `The oam-hosted child hit its V8 heap cap. Raise it where it is set: the --max-old-space-size=<mb> flag in this server's node args if it has one (that wins), else NODE_OPTIONS=--max-old-space-size=<mb> in its env (honored by oam and node alike, and it takes precedence over OAM_MAX_HEAP_MB), or OAM_MAX_HEAP_MB=<mb> when nothing sets --max-old-space-size; or set "runtime": "node" for this server in bundles.json.`;
4710
4766
  }
4711
- var warnedOamUnavailable = false;
4767
+ var warnedOamUnavailable = /* @__PURE__ */ new Set();
4712
4768
  function oamFailureLabel(failure) {
4713
4769
  if (failure === "timeout") return "`oam --version` did not answer in time";
4714
4770
  if (failure === "exit") return "`oam --version` exited non-zero";
@@ -4718,11 +4774,11 @@ function oamFailureLabel(failure) {
4718
4774
  var oamProbeCache;
4719
4775
  var oamProbeCacheExpiresAt;
4720
4776
  function parseOamVersion(out) {
4721
- const m = /\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?/.exec(out);
4777
+ const m = VERSION_IN_TEXT.exec(out);
4722
4778
  return m ? m[0] : null;
4723
4779
  }
4724
- function parseSemver(s) {
4725
- const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?/.exec(s);
4780
+ function parseSemver(s, whole = false) {
4781
+ const m = (whole ? EXACT_VERSION : LEADING_VERSION).exec(s);
4726
4782
  if (!m) return null;
4727
4783
  const pre = m[4] === void 0 ? [] : m[4].split(".").map((id) => /^\d+$/.test(id) ? Number(id) : id);
4728
4784
  return { release: [Number(m[1]), Number(m[2]), Number(m[3])], pre };
@@ -4758,8 +4814,8 @@ function compareVersions(a, b) {
4758
4814
  }
4759
4815
  function satisfiesExactPin(declared, want) {
4760
4816
  if (declared === null) return false;
4761
- const d = parseSemver(declared);
4762
- const w = parseSemver(want);
4817
+ const d = parseSemver(declared, true);
4818
+ const w = parseSemver(want, true);
4763
4819
  if (d && w) return compareSemver(d, w) === 0;
4764
4820
  return declared === want;
4765
4821
  }
@@ -4781,6 +4837,13 @@ function isBuildTreePath(p) {
4781
4837
  const parts = p.toLowerCase().split(/[\\/]+/);
4782
4838
  return parts.some((seg) => BUILD_TREE_SEGMENTS.has(seg) || BUILD_TREE_PREFIXES.some((pre) => seg.startsWith(pre)));
4783
4839
  }
4840
+ function explicitBinOnDisk(bin, platform = process.platform) {
4841
+ const pathLike = isAbsolute8(bin) || bin.includes("/") || platform === "win32" && bin.includes("\\");
4842
+ if (!pathLike) return null;
4843
+ const abs = resolve8(bin);
4844
+ const candidates = platform === "win32" ? [abs, `${abs}.exe`, `${abs}.com`] : [abs];
4845
+ return candidates.find((c) => isExecutableFile(c, platform)) ?? null;
4846
+ }
4784
4847
  function resolveBinAbsolute(bin, env = process.env, platform = process.platform) {
4785
4848
  if (isAbsolute8(bin)) return isExecutableFile(bin, platform) ? winNormalize(bin, platform) : null;
4786
4849
  if (bin.includes("/") || platform === "win32" && bin.includes("\\")) return null;
@@ -4846,7 +4909,7 @@ function createProbeCollector(max = OAM_PROBE_MAX_OUTPUT) {
4846
4909
  };
4847
4910
  }
4848
4911
  function spawnVersionProbe(bin) {
4849
- return new Promise((resolve8, reject) => {
4912
+ return new Promise((resolve9, reject) => {
4850
4913
  let settled = false;
4851
4914
  let timer;
4852
4915
  const settle = (fn) => {
@@ -4884,7 +4947,7 @@ function spawnVersionProbe(bin) {
4884
4947
  "close",
4885
4948
  (code, signal) => settle(() => {
4886
4949
  if (code === 0) {
4887
- resolve8(collector.result());
4950
+ resolve9(collector.result());
4888
4951
  return;
4889
4952
  }
4890
4953
  const err = new Error(`oam exited ${code ?? signal}`);
@@ -4937,9 +5000,10 @@ async function probeOamUncached(run, generation) {
4937
5000
  }
4938
5001
  return probe;
4939
5002
  };
4940
- if (run === spawnVersionProbe && absResolved !== null && isBuildTreePath(absResolved)) {
5003
+ const spawnTarget = absResolved ?? (explicit ? explicitBinOnDisk(bin) : null);
5004
+ if (run === spawnVersionProbe && spawnTarget !== null && isBuildTreePath(spawnTarget)) {
4941
5005
  log("warn", "oam resolves to a local build-tree binary; falling back to node for this process", {
4942
- bin: absResolved,
5006
+ bin: spawnTarget,
4943
5007
  fix: oamBuildTreeFix(CURRENT_OS, explicit),
4944
5008
  thenRestart: "restart yaw-mcp; this probe is cached for the process lifetime"
4945
5009
  });
@@ -4949,7 +5013,7 @@ async function probeOamUncached(run, generation) {
4949
5013
  version: null,
4950
5014
  belowMin: false,
4951
5015
  failure: "build-tree",
4952
- failureDetail: `${absResolved} is a compiler output binary (build-tree), not a release`,
5016
+ failureDetail: `${spawnTarget} is a compiler output binary (build-tree), not a release`,
4953
5017
  viaOamBin: explicit
4954
5018
  });
4955
5019
  }
@@ -4989,7 +5053,11 @@ async function probeOamUncached(run, generation) {
4989
5053
  minVersion: MIN_OAM_VERSION,
4990
5054
  // The floor is a released oam (the last one verify:oam-floor passed
4991
5055
  // on), so below-min always means out of date, and oam updates itself
4992
- // in place.
5056
+ // in place. oam 0.20.0+ refuses `self-update` for a binary inside
5057
+ // node_modules, but oam is never published to npm, so no installer
5058
+ // puts one there: only a hand-pointed OAM_BIN could, and that is not
5059
+ // a case this remedy (or its copies in doctor, install, upgrade and
5060
+ // verify-oam-floor) needs to special-case.
4993
5061
  updateWith: "oam self-update",
4994
5062
  // ...but updating alone changes nothing here. A non-timeout verdict
4995
5063
  // like this one is cached for the process lifetime and only cleared by
@@ -5066,14 +5134,18 @@ async function probeOamUncached(run, generation) {
5066
5134
  }
5067
5135
  }
5068
5136
  var WIN_EXE_EXT = /\.(?:exe|cmd|bat)$/i;
5137
+ function launcherBasename(command) {
5138
+ return (command.split(/[\\/]/).pop() ?? command).replace(WIN_EXE_EXT, "").toLowerCase();
5139
+ }
5069
5140
  function nodeLaunchKind(command) {
5070
- const base = (command.split(/[\\/]/).pop() ?? command).replace(WIN_EXE_EXT, "").toLowerCase();
5141
+ const base = launcherBasename(command);
5071
5142
  if (base === "node") return "node";
5072
5143
  if (base === "npx") return "npx";
5073
5144
  return null;
5074
5145
  }
5075
5146
  var TS_ENTRY_RE = /\.[mc]?ts$/i;
5076
5147
  var POSITIVE_INT = /^[1-9]\d*$/;
5148
+ var HEAP_MB = POSITIVE_INT;
5077
5149
  var OAM_HOSTABLE_NODE_BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
5078
5150
  "--no-warnings",
5079
5151
  "--no-deprecation",
@@ -5084,7 +5156,7 @@ var OAM_HOSTABLE_NODE_BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
5084
5156
  "--expose-gc"
5085
5157
  ]);
5086
5158
  var OAM_HOSTABLE_NODE_VALUE_FLAGS = /* @__PURE__ */ new Map([
5087
- ["--max-old-space-size", POSITIVE_INT],
5159
+ ["--max-old-space-size", HEAP_MB],
5088
5160
  ["--max-http-header-size", POSITIVE_INT],
5089
5161
  ["--dns-result-order", /^(?:verbatim|ipv4first|ipv6first)$/],
5090
5162
  ["--disable-warning", /^[A-Za-z0-9_]+$/]
@@ -5505,8 +5577,9 @@ function resolveStableNpmEntry(pkg, fromUrl = import.meta.url, deps = {}) {
5505
5577
  }
5506
5578
  async function resolveOamSpawn(command, args, optedIn = true) {
5507
5579
  const probe = await probeOam();
5508
- if (optedIn && probe.bin === null && !probe.belowMin && !warnedOamUnavailable && nodeLaunchKind(command) !== null) {
5509
- warnedOamUnavailable = true;
5580
+ const unavailableReason = probe.failure ?? "absent";
5581
+ if (optedIn && probe.bin === null && !probe.belowMin && !warnedOamUnavailable.has(unavailableReason) && nodeLaunchKind(command) !== null) {
5582
+ warnedOamUnavailable.add(unavailableReason);
5510
5583
  if (probe.failure !== null) {
5511
5584
  log("warn", "a server opted in to oam but oam is installed and unusable; running it on node instead", {
5512
5585
  reason: oamFailureLabel(probe.failure),
@@ -5548,7 +5621,10 @@ function resolveManagedSpawn(command, args, fromUrl = import.meta.url, npmCache
5548
5621
  resolveEntry: (pkg, wantVersion) => {
5549
5622
  if (wantVersion !== null) return resolveNpmEntry(pkg, fromUrl, npmCache, managedRoot, wantVersion);
5550
5623
  const memoed = managedEntryMemo.get(pkg);
5551
- if (memoed !== void 0) return memoed;
5624
+ if (memoed !== void 0) {
5625
+ if (existsSync2(memoed)) return memoed;
5626
+ managedEntryMemo.delete(pkg);
5627
+ }
5552
5628
  const hit = resolveNpmEntry(pkg, fromUrl, npmCache, managedRoot, null);
5553
5629
  if (hit !== null && !hit.includes(NPX_CACHE_MARKER)) managedEntryMemo.set(pkg, hit);
5554
5630
  return hit;
@@ -5594,12 +5670,23 @@ function powershellPayload(args) {
5594
5670
  // src/upgrade-cmd.ts
5595
5671
  var POSIX_GLOBAL_LIB_PREFIX = /^(?:[A-Za-z]:)?(?:\/usr(?:\/local)?|\/opt\/[^/]+)\/lib\/node_modules\/@yawlabs\/mcp\//;
5596
5672
  var MANAGED_NODE_LIB_PREFIX = /\/(?:\.nvm\/versions\/node\/[^/]+|\.volta\/tools\/image\/node\/[^/]+|\.asdf\/installs\/nodejs\/[^/]+|(?:\.local\/share\/)?\.?fnm\/node-versions\/[^/]+\/installation|\.nodenv\/versions\/[^/]+|\.nvs\/[^/]+\/[^/]+\/[^/]+|n\/versions\/node\/[^/]+|\.local)\/lib\/node_modules\/@yawlabs\/mcp\//;
5673
+ var NPM_DIR_GLOBAL_MARKER = /\/npm\/node_modules\/@yawlabs\/mcp\//;
5674
+ var BIN_DIR_GLOBAL_MARKER = /\/bin\/node_modules\/@yawlabs\/mcp\//;
5675
+ var WIN32_DEFAULT_NPM_PREFIX = /\/AppData\/Roaming\/npm\/node_modules\/@yawlabs\/mcp\//i;
5676
+ function globalNpmMarkerIsUnanchored(entryPath) {
5677
+ const normalized = entryPath.replace(/\\/g, "/");
5678
+ if (WIN32_DEFAULT_NPM_PREFIX.test(normalized)) return false;
5679
+ return NPM_DIR_GLOBAL_MARKER.test(normalized) || BIN_DIR_GLOBAL_MARKER.test(normalized);
5680
+ }
5597
5681
  var UPGRADE_USAGE = `Usage: yaw-mcp upgrade [--run] [--json]
5598
5682
 
5599
5683
  Show (or execute) the command to upgrade @yawlabs/mcp to the latest version.
5600
5684
 
5601
5685
  --run Run the upgrade in place (global npm, pnpm, bun, and local npm
5602
- installs). No-op for npx installs -- they always fetch the latest.
5686
+ installs). No-op for npx installs: a client entry that runs
5687
+ @yawlabs/mcp@latest fetches the latest on every start. One
5688
+ without @latest keeps its cached copy -- re-run
5689
+ \`yaw-mcp install <client>\` to rewrite it.
5603
5690
  --json Emit a machine-readable snapshot ({ current, latest, stale,
5604
5691
  method, command, cwd }) instead of prose. "cwd" is the directory
5605
5692
  "command" must run IN -- the package-tree root for a
@@ -5638,11 +5725,11 @@ function classifyEntrypoint(argvPath) {
5638
5725
  const normalized = argvPath.replace(/\\/g, "/");
5639
5726
  if (/\/_npx\/[0-9a-f]+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "npx";
5640
5727
  if (/\/app\.asar\.unpacked\//.test(normalized)) return "bundled-app";
5641
- if (/\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5728
+ if (NPM_DIR_GLOBAL_MARKER.test(normalized)) return "global-npm";
5642
5729
  if (POSIX_GLOBAL_LIB_PREFIX.test(normalized)) return "global-npm";
5643
5730
  if (MANAGED_NODE_LIB_PREFIX.test(normalized)) return "global-npm";
5644
5731
  if (/\/\.npm-global\/(?:lib\/)?node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5645
- if (/\/bin\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5732
+ if (BIN_DIR_GLOBAL_MARKER.test(normalized)) return "global-npm";
5646
5733
  if (/\/pnpm\/global\/\d+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "pnpm-global";
5647
5734
  if (/\/\.bun\/install\/global\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "bun-global";
5648
5735
  if (/\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "local-node-modules";
@@ -5703,7 +5790,7 @@ function killProcessTree(child, platform = process.platform, spawnImpl = spawn2)
5703
5790
  async function npmGlobalPrefix(spawnImpl) {
5704
5791
  if (isTestSandbox() && !spawnImpl) return null;
5705
5792
  const spawnFn = spawnImpl ?? spawn2;
5706
- return new Promise((resolve8) => {
5793
+ return new Promise((resolve9) => {
5707
5794
  const child = spawnFn("npm", ["prefix", "-g"], {
5708
5795
  shell: process.platform === "win32",
5709
5796
  stdio: ["ignore", "pipe", "ignore"],
@@ -5714,18 +5801,18 @@ async function npmGlobalPrefix(spawnImpl) {
5714
5801
  let out = "";
5715
5802
  const timer = setTimeout(() => {
5716
5803
  killProcessTree(child);
5717
- resolve8(null);
5804
+ resolve9(null);
5718
5805
  }, 3e3);
5719
5806
  child.stdout?.on("data", (d) => {
5720
5807
  out += String(d);
5721
5808
  });
5722
5809
  child.on("close", (code) => {
5723
5810
  clearTimeout(timer);
5724
- resolve8(code === 0 && out.trim() ? out.trim() : null);
5811
+ resolve9(code === 0 && out.trim() ? out.trim() : null);
5725
5812
  });
5726
5813
  child.on("error", () => {
5727
5814
  clearTimeout(timer);
5728
- resolve8(null);
5815
+ resolve9(null);
5729
5816
  });
5730
5817
  });
5731
5818
  }
@@ -5775,6 +5862,7 @@ function upgradeCommandLine(method) {
5775
5862
  return spec === null ? null : [spec.cmd, ...spec.args].join(" ");
5776
5863
  }
5777
5864
  var BINARY_RETIRED_HINT = `the standalone-binary track was retired in 0.70.3. Install from npm instead -- \`${upgradeCommandLine("global-npm")}\` -- then delete this executable.`;
5865
+ var NPX_LATEST_CAVEAT = "That holds when the client's entry runs @yawlabs/mcp@latest; one without @latest keeps its cached copy -- re-run `yaw-mcp install <client>` to rewrite it.";
5778
5866
  function globalUpgradeCommandLineForTool(tool) {
5779
5867
  const method = GLOBAL_UPGRADE_METHODS.find((m) => UPGRADE_COMMANDS[m]?.cmd === tool);
5780
5868
  return method === void 0 ? null : upgradeCommandLine(method);
@@ -5832,13 +5920,17 @@ async function fetchLatestVersion(opts = {}) {
5832
5920
  }
5833
5921
  }
5834
5922
  async function probeOamQuietly() {
5835
- const prev = process.env.LOG_LEVEL;
5836
- process.env.LOG_LEVEL = "error";
5923
+ const names = ["YAW_MCP_LOG_LEVEL", "LOG_LEVEL"];
5924
+ const prev = names.map((name) => process.env[name]);
5925
+ for (const name of names) process.env[name] = "error";
5837
5926
  try {
5838
5927
  return await probeOam();
5839
5928
  } finally {
5840
- if (prev === void 0) delete process.env.LOG_LEVEL;
5841
- else process.env.LOG_LEVEL = prev;
5929
+ names.forEach((name, i) => {
5930
+ const value = prev[i];
5931
+ if (value === void 0) delete process.env[name];
5932
+ else process.env[name] = value;
5933
+ });
5842
5934
  }
5843
5935
  }
5844
5936
  async function oamFloorLines(probe) {
@@ -5865,21 +5957,25 @@ async function oamFloorLines(probe) {
5865
5957
  }
5866
5958
  async function defaultRunningPrefix(argvPath) {
5867
5959
  if (isTestSandbox()) return null;
5868
- const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-BFZR7HIL.js");
5960
+ const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-KXOCHAUR.js");
5869
5961
  return detectRunningInstallPrefix2(argvPath);
5870
5962
  }
5963
+ async function defaultConfirmGlobalPrefix(argvPath, prefix) {
5964
+ const { defaultConfirmGlobalPrefix: confirm } = await import("./auto-upgrade-KXOCHAUR.js");
5965
+ return confirm(argvPath, prefix);
5966
+ }
5871
5967
  async function defaultAcquireLock(prefixDir) {
5872
5968
  if (isTestSandbox()) return () => {
5873
5969
  };
5874
- const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-BFZR7HIL.js");
5970
+ const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-KXOCHAUR.js");
5875
5971
  return acquireUpgradeLock2(prefixDir);
5876
5972
  }
5877
5973
  async function upgradeLockPath(prefixDir) {
5878
- const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-BFZR7HIL.js");
5974
+ const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-KXOCHAUR.js");
5879
5975
  return join11(prefixDir, UPGRADE_LOCK_NAME2);
5880
5976
  }
5881
5977
  async function defaultSpawn(cmd, args, cwd) {
5882
- return new Promise((resolve8) => {
5978
+ return new Promise((resolve9) => {
5883
5979
  const child = spawn2(cmd, args, {
5884
5980
  stdio: "inherit",
5885
5981
  shell: process.platform === "win32",
@@ -5890,8 +5986,8 @@ async function defaultSpawn(cmd, args, cwd) {
5890
5986
  // them. See internal-secret-env.ts.
5891
5987
  env: stripInternalSecretsFromEnv(process.env)
5892
5988
  });
5893
- child.on("close", (code) => resolve8(typeof code === "number" ? code : 1));
5894
- child.on("error", () => resolve8(1));
5989
+ child.on("close", (code) => resolve9(typeof code === "number" ? code : 1));
5990
+ child.on("error", () => resolve9(1));
5895
5991
  });
5896
5992
  }
5897
5993
  async function detectSea() {
@@ -5935,10 +6031,16 @@ async function runUpgrade(opts = {}) {
5935
6031
  let globalPrefixArg = null;
5936
6032
  let suggestedCommand = plan.command;
5937
6033
  let rawPrefix = null;
6034
+ let prefixRefusedNote = null;
5938
6035
  if (method === "global-npm") {
5939
6036
  rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
6037
+ if (rawPrefix !== null && !await (opts.confirmGlobalPrefix ?? defaultConfirmGlobalPrefix)(argvPath, rawPrefix)) {
6038
+ const { PREFIX_REFUSED_REASON: PREFIX_REFUSED_REASON2, prefixRefusedRemedies: prefixRefusedRemedies2 } = await import("./auto-upgrade-KXOCHAUR.js");
6039
+ prefixRefusedNote = `Note: not pinning --prefix ${rawPrefix}: ${PREFIX_REFUSED_REASON2}. The command below installs into npm's own global prefix and does NOT update the copy at ${rawPrefix}. ` + prefixRefusedRemedies2(rawPrefix, opts.platform);
6040
+ rawPrefix = null;
6041
+ }
5940
6042
  if (rawPrefix !== null) {
5941
- const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-BFZR7HIL.js");
6043
+ const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-KXOCHAUR.js");
5942
6044
  const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
5943
6045
  const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
5944
6046
  if (spawnForm !== null && displayForm !== null) {
@@ -5956,6 +6058,7 @@ async function runUpgrade(opts = {}) {
5956
6058
  if (latest === null) {
5957
6059
  print("yaw-mcp upgrade: couldn't reach the npm registry (offline? firewall?).");
5958
6060
  if (suggestedCommand) {
6061
+ if (prefixRefusedNote) print(prefixRefusedNote);
5959
6062
  print("When you're back online, run:");
5960
6063
  print("");
5961
6064
  if (installRoot) {
@@ -5968,6 +6071,7 @@ async function runUpgrade(opts = {}) {
5968
6071
  print(`yaw-mcp is a standalone binary; ${BINARY_RETIRED_HINT}`);
5969
6072
  } else {
5970
6073
  print("Your install uses `npx -y` -- just restart the MCP client when you're back online.");
6074
+ print(NPX_LATEST_CAVEAT);
5971
6075
  }
5972
6076
  for (const line of await oamFloorLines(opts.oamProbe)) print(line);
5973
6077
  return { exitCode: 0, lines };
@@ -5984,6 +6088,7 @@ async function runUpgrade(opts = {}) {
5984
6088
  print("");
5985
6089
  if (method === "npx") {
5986
6090
  print("Your install uses `npx -y` -- restart the MCP client and it will fetch the new version.");
6091
+ print(NPX_LATEST_CAVEAT);
5987
6092
  return { exitCode: 0, lines };
5988
6093
  }
5989
6094
  if (method === "bundled-app") {
@@ -6000,6 +6105,10 @@ async function runUpgrade(opts = {}) {
6000
6105
  const spec = upgradeSpawnSpec(method, globalPrefixArg);
6001
6106
  const runSpec = spec === null ? null : method === "local-node-modules" ? installRoot !== null ? { ...spec, cwd: installRoot } : null : spec;
6002
6107
  const commandLine = method === "global-npm" ? suggestedCommand : runSpec ? [runSpec.cmd, ...runSpec.args].join(" ") : plan.command;
6108
+ if (prefixRefusedNote) {
6109
+ print(prefixRefusedNote);
6110
+ print("");
6111
+ }
6003
6112
  if (!opts.run) {
6004
6113
  if (runSpec) {
6005
6114
  print("Run `yaw-mcp upgrade --run` to upgrade in place, or run it yourself:");
@@ -6070,7 +6179,7 @@ async function runUpgrade(opts = {}) {
6070
6179
  return { exitCode: 3, lines };
6071
6180
  }
6072
6181
  function readCurrentVersion() {
6073
- return true ? "1.1.10" : "dev";
6182
+ return true ? "1.1.12" : "dev";
6074
6183
  }
6075
6184
 
6076
6185
  // src/auto-upgrade.ts
@@ -6085,6 +6194,11 @@ function quoteArgForDisplay(arg, platform = process.platform) {
6085
6194
  if (/^[A-Za-z0-9_\-./+,:@=]+$/.test(arg)) return arg;
6086
6195
  return `'${arg.replace(/'/g, "'\\''")}'`;
6087
6196
  }
6197
+ var PREFIX_REFUSED_REASON = "this copy sits under a directory named `npm` or `bin` with no yaw-mcp bin shim beside it, so it may be a project tree rather than a global npm prefix";
6198
+ function prefixRefusedRemedies(dir, platform = process.platform) {
6199
+ const shownDir = quoteArgForDisplay(dir, platform) ?? dir;
6200
+ return `If that directory really is a global npm prefix, run \`npm install -g --prefix ${shownDir} @yawlabs/mcp@latest\` instead; if it is a project, run \`npm install @yawlabs/mcp@latest\` in its project root (${dir}).`;
6201
+ }
6088
6202
  function detectRunningInstallPrefix(argvPath) {
6089
6203
  if (!argvPath) return null;
6090
6204
  let resolved;
@@ -6107,6 +6221,17 @@ function runsUnderNpmConfigPrefix(argvPath, env = process.env) {
6107
6221
  const entry = comparablePath(argvPath);
6108
6222
  return entry.startsWith(`${root}/lib/node_modules/@yawlabs/mcp/`) || entry.startsWith(`${root}/node_modules/@yawlabs/mcp/`);
6109
6223
  }
6224
+ function defaultConfirmGlobalPrefix2(argvPath, prefix, exists = existsSync3) {
6225
+ if (!argvPath) return true;
6226
+ let resolved;
6227
+ try {
6228
+ resolved = realpathSync3(argvPath);
6229
+ } catch {
6230
+ return true;
6231
+ }
6232
+ if (!globalNpmMarkerIsUnanchored(resolved)) return true;
6233
+ return exists(join12(prefix, "yaw-mcp.cmd")) || exists(join12(prefix, "yaw-mcp"));
6234
+ }
6110
6235
  async function compareWithNpmPrefix(detected, probe = npmGlobalPrefix) {
6111
6236
  const npmPrefix = await probe();
6112
6237
  if (!npmPrefix?.trim()) return;
@@ -6362,7 +6487,7 @@ function defaultSpawn2(cmd, args, onDone = () => {
6362
6487
  }
6363
6488
  async function maybeAutoUpgrade(deps = {}) {
6364
6489
  if (isFeatureDisabled("YAW_MCP_AUTO_UPGRADE")) return;
6365
- const current = deps.currentVersion ?? (true ? "1.1.10" : "dev");
6490
+ const current = deps.currentVersion ?? (true ? "1.1.12" : "dev");
6366
6491
  if (current === "dev") return;
6367
6492
  const argvPath = deps.argvPath ?? process.argv[1];
6368
6493
  let method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync3, ["unknown", "local-node-modules"]);
@@ -6379,6 +6504,14 @@ async function maybeAutoUpgrade(deps = {}) {
6379
6504
  const plan = buildUpgradePlan({ current, latest, method });
6380
6505
  if (!plan.stale) return;
6381
6506
  const rawPrefix = method === "global-npm" ? detectRunningInstallPrefix(argvPath) : null;
6507
+ if (rawPrefix !== null && !(deps.confirmGlobalPrefixImpl ?? defaultConfirmGlobalPrefix2)(argvPath, rawPrefix)) {
6508
+ log(
6509
+ "info",
6510
+ `yaw-mcp is out of date; not upgrading in the background: ${PREFIX_REFUSED_REASON}. The copy at ${rawPrefix} was not updated. ${prefixRefusedRemedies(rawPrefix)}`,
6511
+ { current, latest, method, prefix: rawPrefix }
6512
+ );
6513
+ return;
6514
+ }
6382
6515
  const quotedPrefix = rawPrefix === null ? null : quoteShellArgIfNeeded(rawPrefix);
6383
6516
  const globalSpec = GLOBAL_UPGRADE_METHODS.includes(method) ? upgradeSpawnSpec(method, quotedPrefix) : null;
6384
6517
  if (globalSpec) {
@@ -6437,7 +6570,7 @@ async function maybeAutoUpgrade(deps = {}) {
6437
6570
  return;
6438
6571
  }
6439
6572
  if (method === "npx") {
6440
- log("info", "yaw-mcp is out of date; restart your MCP client to pick up the latest version", {
6573
+ log("info", `yaw-mcp is out of date; restart your MCP client to pick up the latest version. ${NPX_LATEST_CAVEAT}`, {
6441
6574
  current,
6442
6575
  latest,
6443
6576
  method
@@ -6548,14 +6681,11 @@ export {
6548
6681
  buildLaunchEntry,
6549
6682
  isProjectLocalEntry,
6550
6683
  findLegacyEntry,
6551
- findBlockedContainerSegment,
6552
- describeJsonShape,
6553
6684
  unparseableConfigFix,
6554
6685
  blockedContainerFix,
6555
6686
  STATE_SCHEMA_VERSION,
6556
6687
  STATE_FILENAME,
6557
6688
  isPersistenceDisabled,
6558
- isReadableStateVersion,
6559
6689
  PREWARM_FAILURE_BACKOFF_MS,
6560
6690
  statePath,
6561
6691
  loadState,
@@ -6578,6 +6708,7 @@ export {
6578
6708
  compareVersions,
6579
6709
  resolveBinAbsolute,
6580
6710
  probeOam,
6711
+ launcherBasename,
6581
6712
  nodeLaunchKind,
6582
6713
  scanNodeLaunchFlags,
6583
6714
  describeNodeFlagRefusal,
@@ -6602,8 +6733,11 @@ export {
6602
6733
  runUpgrade,
6603
6734
  quoteShellArgIfNeeded,
6604
6735
  quoteArgForDisplay,
6736
+ PREFIX_REFUSED_REASON,
6737
+ prefixRefusedRemedies,
6605
6738
  detectRunningInstallPrefix,
6606
6739
  runsUnderNpmConfigPrefix,
6740
+ defaultConfirmGlobalPrefix2 as defaultConfirmGlobalPrefix,
6607
6741
  UPGRADE_LOCK_NAME,
6608
6742
  acquireUpgradeLock,
6609
6743
  readCheckMemo,