@yawlabs/mcp 1.1.9 → 1.1.11

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.1";
4730
+ var MIN_OAM_VERSION = "0.20.0";
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) {
@@ -4706,9 +4762,9 @@ function oamBuildTreeFix(os, viaOamBin = false) {
4706
4762
  }
4707
4763
  function oamHeapOomHint(stderr) {
4708
4764
  if (!stderr.includes("OAM-RT-OOM")) return null;
4709
- return `The oam-hosted child hit its V8 heap cap. Raise it with OAM_MAX_HEAP_MB=<mb> in this server's env, or set "runtime": "node" for this server in bundles.json.`;
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,14 @@ 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. "In place" holds for every binary that reaches here only
5057
+ // while the floor is 0.20.0: oam 0.20.0+ refuses `self-update` for a
5058
+ // binary inside node_modules (pointing at `npm install -g
5059
+ // oamjs@latest`), and npm's oamjs exposes `oamjs`, not `oam`, so
5060
+ // only an OAM_BIN can point there. When the floor rises past 0.20.x,
5061
+ // and oamjs is published, route this remedy and its copies (doctor,
5062
+ // install, upgrade, verify-oam-floor) through one helper that checks
5063
+ // the resolved path for a node_modules component.
4993
5064
  updateWith: "oam self-update",
4994
5065
  // ...but updating alone changes nothing here. A non-timeout verdict
4995
5066
  // like this one is cached for the process lifetime and only cleared by
@@ -5066,18 +5137,84 @@ async function probeOamUncached(run, generation) {
5066
5137
  }
5067
5138
  }
5068
5139
  var WIN_EXE_EXT = /\.(?:exe|cmd|bat)$/i;
5140
+ function launcherBasename(command) {
5141
+ return (command.split(/[\\/]/).pop() ?? command).replace(WIN_EXE_EXT, "").toLowerCase();
5142
+ }
5069
5143
  function nodeLaunchKind(command) {
5070
- const base = (command.split(/[\\/]/).pop() ?? command).replace(WIN_EXE_EXT, "").toLowerCase();
5144
+ const base = launcherBasename(command);
5071
5145
  if (base === "node") return "node";
5072
5146
  if (base === "npx") return "npx";
5073
5147
  return null;
5074
5148
  }
5075
5149
  var TS_ENTRY_RE = /\.[mc]?ts$/i;
5150
+ var POSITIVE_INT = /^[1-9]\d*$/;
5151
+ var HEAP_MB = /^(?:1[6-9]|[2-9]\d|[1-9]\d{2,})$/;
5152
+ var OAM_HOSTABLE_NODE_BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
5153
+ "--no-warnings",
5154
+ "--no-deprecation",
5155
+ "--trace-warnings",
5156
+ "--trace-deprecation",
5157
+ "--throw-deprecation",
5158
+ "--trace-uncaught",
5159
+ "--expose-gc"
5160
+ ]);
5161
+ var OAM_HOSTABLE_NODE_VALUE_FLAGS = /* @__PURE__ */ new Map([
5162
+ ["--max-old-space-size", HEAP_MB],
5163
+ ["--max-http-header-size", POSITIVE_INT],
5164
+ ["--dns-result-order", /^(?:verbatim|ipv4first|ipv6first)$/],
5165
+ ["--disable-warning", /^[A-Za-z0-9_]+$/]
5166
+ ]);
5167
+ function scanNodeLaunchFlags(args) {
5168
+ const flags = [];
5169
+ for (let i = 0; i < args.length; i++) {
5170
+ const a = args[i];
5171
+ if (!a.startsWith("-")) {
5172
+ if (a === "") return { kind: "no-entry" };
5173
+ return { kind: "entry", flags, entry: a, rest: args.slice(i + 1) };
5174
+ }
5175
+ const eq = a.indexOf("=");
5176
+ const name = eq === -1 ? a : a.slice(0, eq);
5177
+ if (OAM_HOSTABLE_NODE_BOOLEAN_FLAGS.has(name)) {
5178
+ if (eq !== -1) return { kind: "refused", flag: name, why: "bad-value" };
5179
+ } else {
5180
+ const valueRe = OAM_HOSTABLE_NODE_VALUE_FLAGS.get(name);
5181
+ if (valueRe === void 0) return { kind: "refused", flag: name, why: "unlisted" };
5182
+ if (eq === -1) return { kind: "refused", flag: name, why: "spaced-value" };
5183
+ if (!valueRe.test(a.slice(eq + 1))) return { kind: "refused", flag: name, why: "bad-value" };
5184
+ }
5185
+ flags.push(a);
5186
+ }
5187
+ return { kind: "no-entry" };
5188
+ }
5189
+ function describeNodeFlagRefusal(flag, why) {
5190
+ if (why === "spaced-value") {
5191
+ return `the node launch gives ${flag} its value as a separate argument; yaw-mcp hosts it on oam only as ${flag}=<value>`;
5192
+ }
5193
+ if (why === "bad-value") return `the node launch gives ${flag} a value yaw-mcp does not pass to oam`;
5194
+ return `the node launch carries the node flag ${flag}, which yaw-mcp does not host on oam`;
5195
+ }
5196
+ var OAM_SPACED_VALUE_OPTIONS = /* @__PURE__ */ new Set([
5197
+ "--check",
5198
+ "--record",
5199
+ "--replay",
5200
+ "--env-file",
5201
+ "--env-file-if-exists",
5202
+ "--input-type",
5203
+ "--max-http-header-size",
5204
+ "--max-old-space-size",
5205
+ "--v8-pool-size",
5206
+ "--trace-require-module",
5207
+ "--dns-result-order",
5208
+ "--disable-warning",
5209
+ "--redirect-warnings",
5210
+ "--allow-fs-read",
5211
+ "--allow-fs-write"
5212
+ ]);
5076
5213
  function rewriteForOam(command, args, deps) {
5077
5214
  const bin = deps.oamBin;
5078
5215
  if (!bin) return { command, args };
5079
- const toOam = (entry, rest) => {
5080
- const flags = TS_ENTRY_RE.test(entry) ? ["--no-check"] : [];
5216
+ const toOam = (entry, rest, nodeFlags = []) => {
5217
+ const flags = [...nodeFlags, ...TS_ENTRY_RE.test(entry) ? ["--no-check"] : []];
5081
5218
  return {
5082
5219
  command: bin,
5083
5220
  args: rest.length > 0 ? ["run", ...flags, entry, "--", ...rest] : ["run", ...flags, entry]
@@ -5085,10 +5222,17 @@ function rewriteForOam(command, args, deps) {
5085
5222
  };
5086
5223
  const kind = nodeLaunchKind(command);
5087
5224
  if (kind === "node") {
5088
- const [entry, ...rest] = args;
5089
- if (!entry) return { command, args };
5090
- if (entry.startsWith("-")) return { command, args };
5091
- return toOam(entry, rest);
5225
+ const scan = scanNodeLaunchFlags(args);
5226
+ if (scan.kind === "no-entry") return { command, args };
5227
+ if (scan.kind === "refused") {
5228
+ log("debug", "node launch carries a node flag yaw-mcp does not host on oam; staying on node", {
5229
+ flag: scan.flag,
5230
+ why: scan.why,
5231
+ argc: args.length
5232
+ });
5233
+ return { command, args };
5234
+ }
5235
+ return toOam(scan.entry, scan.rest, scan.flags);
5092
5236
  }
5093
5237
  if (kind === "npx") {
5094
5238
  const specIdx = npxSpecIndex(args);
@@ -5436,8 +5580,9 @@ function resolveStableNpmEntry(pkg, fromUrl = import.meta.url, deps = {}) {
5436
5580
  }
5437
5581
  async function resolveOamSpawn(command, args, optedIn = true) {
5438
5582
  const probe = await probeOam();
5439
- if (optedIn && probe.bin === null && !probe.belowMin && !warnedOamUnavailable && nodeLaunchKind(command) !== null) {
5440
- warnedOamUnavailable = true;
5583
+ const unavailableReason = probe.failure ?? "absent";
5584
+ if (optedIn && probe.bin === null && !probe.belowMin && !warnedOamUnavailable.has(unavailableReason) && nodeLaunchKind(command) !== null) {
5585
+ warnedOamUnavailable.add(unavailableReason);
5441
5586
  if (probe.failure !== null) {
5442
5587
  log("warn", "a server opted in to oam but oam is installed and unusable; running it on node instead", {
5443
5588
  reason: oamFailureLabel(probe.failure),
@@ -5479,7 +5624,10 @@ function resolveManagedSpawn(command, args, fromUrl = import.meta.url, npmCache
5479
5624
  resolveEntry: (pkg, wantVersion) => {
5480
5625
  if (wantVersion !== null) return resolveNpmEntry(pkg, fromUrl, npmCache, managedRoot, wantVersion);
5481
5626
  const memoed = managedEntryMemo.get(pkg);
5482
- if (memoed !== void 0) return memoed;
5627
+ if (memoed !== void 0) {
5628
+ if (existsSync2(memoed)) return memoed;
5629
+ managedEntryMemo.delete(pkg);
5630
+ }
5483
5631
  const hit = resolveNpmEntry(pkg, fromUrl, npmCache, managedRoot, null);
5484
5632
  if (hit !== null && !hit.includes(NPX_CACHE_MARKER)) managedEntryMemo.set(pkg, hit);
5485
5633
  return hit;
@@ -5525,12 +5673,23 @@ function powershellPayload(args) {
5525
5673
  // src/upgrade-cmd.ts
5526
5674
  var POSIX_GLOBAL_LIB_PREFIX = /^(?:[A-Za-z]:)?(?:\/usr(?:\/local)?|\/opt\/[^/]+)\/lib\/node_modules\/@yawlabs\/mcp\//;
5527
5675
  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\//;
5676
+ var NPM_DIR_GLOBAL_MARKER = /\/npm\/node_modules\/@yawlabs\/mcp\//;
5677
+ var BIN_DIR_GLOBAL_MARKER = /\/bin\/node_modules\/@yawlabs\/mcp\//;
5678
+ var WIN32_DEFAULT_NPM_PREFIX = /\/AppData\/Roaming\/npm\/node_modules\/@yawlabs\/mcp\//i;
5679
+ function globalNpmMarkerIsUnanchored(entryPath) {
5680
+ const normalized = entryPath.replace(/\\/g, "/");
5681
+ if (WIN32_DEFAULT_NPM_PREFIX.test(normalized)) return false;
5682
+ return NPM_DIR_GLOBAL_MARKER.test(normalized) || BIN_DIR_GLOBAL_MARKER.test(normalized);
5683
+ }
5528
5684
  var UPGRADE_USAGE = `Usage: yaw-mcp upgrade [--run] [--json]
5529
5685
 
5530
5686
  Show (or execute) the command to upgrade @yawlabs/mcp to the latest version.
5531
5687
 
5532
5688
  --run Run the upgrade in place (global npm, pnpm, bun, and local npm
5533
- installs). No-op for npx installs -- they always fetch the latest.
5689
+ installs). No-op for npx installs: a client entry that runs
5690
+ @yawlabs/mcp@latest fetches the latest on every start. One
5691
+ without @latest keeps its cached copy -- re-run
5692
+ \`yaw-mcp install <client>\` to rewrite it.
5534
5693
  --json Emit a machine-readable snapshot ({ current, latest, stale,
5535
5694
  method, command, cwd }) instead of prose. "cwd" is the directory
5536
5695
  "command" must run IN -- the package-tree root for a
@@ -5569,11 +5728,11 @@ function classifyEntrypoint(argvPath) {
5569
5728
  const normalized = argvPath.replace(/\\/g, "/");
5570
5729
  if (/\/_npx\/[0-9a-f]+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "npx";
5571
5730
  if (/\/app\.asar\.unpacked\//.test(normalized)) return "bundled-app";
5572
- if (/\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5731
+ if (NPM_DIR_GLOBAL_MARKER.test(normalized)) return "global-npm";
5573
5732
  if (POSIX_GLOBAL_LIB_PREFIX.test(normalized)) return "global-npm";
5574
5733
  if (MANAGED_NODE_LIB_PREFIX.test(normalized)) return "global-npm";
5575
5734
  if (/\/\.npm-global\/(?:lib\/)?node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5576
- if (/\/bin\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
5735
+ if (BIN_DIR_GLOBAL_MARKER.test(normalized)) return "global-npm";
5577
5736
  if (/\/pnpm\/global\/\d+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "pnpm-global";
5578
5737
  if (/\/\.bun\/install\/global\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "bun-global";
5579
5738
  if (/\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "local-node-modules";
@@ -5634,7 +5793,7 @@ function killProcessTree(child, platform = process.platform, spawnImpl = spawn2)
5634
5793
  async function npmGlobalPrefix(spawnImpl) {
5635
5794
  if (isTestSandbox() && !spawnImpl) return null;
5636
5795
  const spawnFn = spawnImpl ?? spawn2;
5637
- return new Promise((resolve8) => {
5796
+ return new Promise((resolve9) => {
5638
5797
  const child = spawnFn("npm", ["prefix", "-g"], {
5639
5798
  shell: process.platform === "win32",
5640
5799
  stdio: ["ignore", "pipe", "ignore"],
@@ -5645,18 +5804,18 @@ async function npmGlobalPrefix(spawnImpl) {
5645
5804
  let out = "";
5646
5805
  const timer = setTimeout(() => {
5647
5806
  killProcessTree(child);
5648
- resolve8(null);
5807
+ resolve9(null);
5649
5808
  }, 3e3);
5650
5809
  child.stdout?.on("data", (d) => {
5651
5810
  out += String(d);
5652
5811
  });
5653
5812
  child.on("close", (code) => {
5654
5813
  clearTimeout(timer);
5655
- resolve8(code === 0 && out.trim() ? out.trim() : null);
5814
+ resolve9(code === 0 && out.trim() ? out.trim() : null);
5656
5815
  });
5657
5816
  child.on("error", () => {
5658
5817
  clearTimeout(timer);
5659
- resolve8(null);
5818
+ resolve9(null);
5660
5819
  });
5661
5820
  });
5662
5821
  }
@@ -5706,6 +5865,7 @@ function upgradeCommandLine(method) {
5706
5865
  return spec === null ? null : [spec.cmd, ...spec.args].join(" ");
5707
5866
  }
5708
5867
  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.`;
5868
+ 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.";
5709
5869
  function globalUpgradeCommandLineForTool(tool) {
5710
5870
  const method = GLOBAL_UPGRADE_METHODS.find((m) => UPGRADE_COMMANDS[m]?.cmd === tool);
5711
5871
  return method === void 0 ? null : upgradeCommandLine(method);
@@ -5763,13 +5923,17 @@ async function fetchLatestVersion(opts = {}) {
5763
5923
  }
5764
5924
  }
5765
5925
  async function probeOamQuietly() {
5766
- const prev = process.env.LOG_LEVEL;
5767
- process.env.LOG_LEVEL = "error";
5926
+ const names = ["YAW_MCP_LOG_LEVEL", "LOG_LEVEL"];
5927
+ const prev = names.map((name) => process.env[name]);
5928
+ for (const name of names) process.env[name] = "error";
5768
5929
  try {
5769
5930
  return await probeOam();
5770
5931
  } finally {
5771
- if (prev === void 0) delete process.env.LOG_LEVEL;
5772
- else process.env.LOG_LEVEL = prev;
5932
+ names.forEach((name, i) => {
5933
+ const value = prev[i];
5934
+ if (value === void 0) delete process.env[name];
5935
+ else process.env[name] = value;
5936
+ });
5773
5937
  }
5774
5938
  }
5775
5939
  async function oamFloorLines(probe) {
@@ -5796,21 +5960,25 @@ async function oamFloorLines(probe) {
5796
5960
  }
5797
5961
  async function defaultRunningPrefix(argvPath) {
5798
5962
  if (isTestSandbox()) return null;
5799
- const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-RGWSTKNN.js");
5963
+ const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-QWLYCX74.js");
5800
5964
  return detectRunningInstallPrefix2(argvPath);
5801
5965
  }
5966
+ async function defaultConfirmGlobalPrefix(argvPath, prefix) {
5967
+ const { defaultConfirmGlobalPrefix: confirm } = await import("./auto-upgrade-QWLYCX74.js");
5968
+ return confirm(argvPath, prefix);
5969
+ }
5802
5970
  async function defaultAcquireLock(prefixDir) {
5803
5971
  if (isTestSandbox()) return () => {
5804
5972
  };
5805
- const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-RGWSTKNN.js");
5973
+ const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-QWLYCX74.js");
5806
5974
  return acquireUpgradeLock2(prefixDir);
5807
5975
  }
5808
5976
  async function upgradeLockPath(prefixDir) {
5809
- const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-RGWSTKNN.js");
5977
+ const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-QWLYCX74.js");
5810
5978
  return join11(prefixDir, UPGRADE_LOCK_NAME2);
5811
5979
  }
5812
5980
  async function defaultSpawn(cmd, args, cwd) {
5813
- return new Promise((resolve8) => {
5981
+ return new Promise((resolve9) => {
5814
5982
  const child = spawn2(cmd, args, {
5815
5983
  stdio: "inherit",
5816
5984
  shell: process.platform === "win32",
@@ -5821,8 +5989,8 @@ async function defaultSpawn(cmd, args, cwd) {
5821
5989
  // them. See internal-secret-env.ts.
5822
5990
  env: stripInternalSecretsFromEnv(process.env)
5823
5991
  });
5824
- child.on("close", (code) => resolve8(typeof code === "number" ? code : 1));
5825
- child.on("error", () => resolve8(1));
5992
+ child.on("close", (code) => resolve9(typeof code === "number" ? code : 1));
5993
+ child.on("error", () => resolve9(1));
5826
5994
  });
5827
5995
  }
5828
5996
  async function detectSea() {
@@ -5866,10 +6034,16 @@ async function runUpgrade(opts = {}) {
5866
6034
  let globalPrefixArg = null;
5867
6035
  let suggestedCommand = plan.command;
5868
6036
  let rawPrefix = null;
6037
+ let prefixRefusedNote = null;
5869
6038
  if (method === "global-npm") {
5870
6039
  rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
6040
+ if (rawPrefix !== null && !await (opts.confirmGlobalPrefix ?? defaultConfirmGlobalPrefix)(argvPath, rawPrefix)) {
6041
+ const { PREFIX_REFUSED_REASON: PREFIX_REFUSED_REASON2, prefixRefusedRemedies: prefixRefusedRemedies2 } = await import("./auto-upgrade-QWLYCX74.js");
6042
+ 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);
6043
+ rawPrefix = null;
6044
+ }
5871
6045
  if (rawPrefix !== null) {
5872
- const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-RGWSTKNN.js");
6046
+ const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-QWLYCX74.js");
5873
6047
  const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
5874
6048
  const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
5875
6049
  if (spawnForm !== null && displayForm !== null) {
@@ -5887,6 +6061,7 @@ async function runUpgrade(opts = {}) {
5887
6061
  if (latest === null) {
5888
6062
  print("yaw-mcp upgrade: couldn't reach the npm registry (offline? firewall?).");
5889
6063
  if (suggestedCommand) {
6064
+ if (prefixRefusedNote) print(prefixRefusedNote);
5890
6065
  print("When you're back online, run:");
5891
6066
  print("");
5892
6067
  if (installRoot) {
@@ -5899,6 +6074,7 @@ async function runUpgrade(opts = {}) {
5899
6074
  print(`yaw-mcp is a standalone binary; ${BINARY_RETIRED_HINT}`);
5900
6075
  } else {
5901
6076
  print("Your install uses `npx -y` -- just restart the MCP client when you're back online.");
6077
+ print(NPX_LATEST_CAVEAT);
5902
6078
  }
5903
6079
  for (const line of await oamFloorLines(opts.oamProbe)) print(line);
5904
6080
  return { exitCode: 0, lines };
@@ -5915,6 +6091,7 @@ async function runUpgrade(opts = {}) {
5915
6091
  print("");
5916
6092
  if (method === "npx") {
5917
6093
  print("Your install uses `npx -y` -- restart the MCP client and it will fetch the new version.");
6094
+ print(NPX_LATEST_CAVEAT);
5918
6095
  return { exitCode: 0, lines };
5919
6096
  }
5920
6097
  if (method === "bundled-app") {
@@ -5931,6 +6108,10 @@ async function runUpgrade(opts = {}) {
5931
6108
  const spec = upgradeSpawnSpec(method, globalPrefixArg);
5932
6109
  const runSpec = spec === null ? null : method === "local-node-modules" ? installRoot !== null ? { ...spec, cwd: installRoot } : null : spec;
5933
6110
  const commandLine = method === "global-npm" ? suggestedCommand : runSpec ? [runSpec.cmd, ...runSpec.args].join(" ") : plan.command;
6111
+ if (prefixRefusedNote) {
6112
+ print(prefixRefusedNote);
6113
+ print("");
6114
+ }
5934
6115
  if (!opts.run) {
5935
6116
  if (runSpec) {
5936
6117
  print("Run `yaw-mcp upgrade --run` to upgrade in place, or run it yourself:");
@@ -6001,7 +6182,7 @@ async function runUpgrade(opts = {}) {
6001
6182
  return { exitCode: 3, lines };
6002
6183
  }
6003
6184
  function readCurrentVersion() {
6004
- return true ? "1.1.9" : "dev";
6185
+ return true ? "1.1.11" : "dev";
6005
6186
  }
6006
6187
 
6007
6188
  // src/auto-upgrade.ts
@@ -6016,6 +6197,11 @@ function quoteArgForDisplay(arg, platform = process.platform) {
6016
6197
  if (/^[A-Za-z0-9_\-./+,:@=]+$/.test(arg)) return arg;
6017
6198
  return `'${arg.replace(/'/g, "'\\''")}'`;
6018
6199
  }
6200
+ 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";
6201
+ function prefixRefusedRemedies(dir, platform = process.platform) {
6202
+ const shownDir = quoteArgForDisplay(dir, platform) ?? dir;
6203
+ 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}).`;
6204
+ }
6019
6205
  function detectRunningInstallPrefix(argvPath) {
6020
6206
  if (!argvPath) return null;
6021
6207
  let resolved;
@@ -6038,6 +6224,17 @@ function runsUnderNpmConfigPrefix(argvPath, env = process.env) {
6038
6224
  const entry = comparablePath(argvPath);
6039
6225
  return entry.startsWith(`${root}/lib/node_modules/@yawlabs/mcp/`) || entry.startsWith(`${root}/node_modules/@yawlabs/mcp/`);
6040
6226
  }
6227
+ function defaultConfirmGlobalPrefix2(argvPath, prefix, exists = existsSync3) {
6228
+ if (!argvPath) return true;
6229
+ let resolved;
6230
+ try {
6231
+ resolved = realpathSync3(argvPath);
6232
+ } catch {
6233
+ return true;
6234
+ }
6235
+ if (!globalNpmMarkerIsUnanchored(resolved)) return true;
6236
+ return exists(join12(prefix, "yaw-mcp.cmd")) || exists(join12(prefix, "yaw-mcp"));
6237
+ }
6041
6238
  async function compareWithNpmPrefix(detected, probe = npmGlobalPrefix) {
6042
6239
  const npmPrefix = await probe();
6043
6240
  if (!npmPrefix?.trim()) return;
@@ -6293,7 +6490,7 @@ function defaultSpawn2(cmd, args, onDone = () => {
6293
6490
  }
6294
6491
  async function maybeAutoUpgrade(deps = {}) {
6295
6492
  if (isFeatureDisabled("YAW_MCP_AUTO_UPGRADE")) return;
6296
- const current = deps.currentVersion ?? (true ? "1.1.9" : "dev");
6493
+ const current = deps.currentVersion ?? (true ? "1.1.11" : "dev");
6297
6494
  if (current === "dev") return;
6298
6495
  const argvPath = deps.argvPath ?? process.argv[1];
6299
6496
  let method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync3, ["unknown", "local-node-modules"]);
@@ -6310,6 +6507,14 @@ async function maybeAutoUpgrade(deps = {}) {
6310
6507
  const plan = buildUpgradePlan({ current, latest, method });
6311
6508
  if (!plan.stale) return;
6312
6509
  const rawPrefix = method === "global-npm" ? detectRunningInstallPrefix(argvPath) : null;
6510
+ if (rawPrefix !== null && !(deps.confirmGlobalPrefixImpl ?? defaultConfirmGlobalPrefix2)(argvPath, rawPrefix)) {
6511
+ log(
6512
+ "info",
6513
+ `yaw-mcp is out of date; not upgrading in the background: ${PREFIX_REFUSED_REASON}. The copy at ${rawPrefix} was not updated. ${prefixRefusedRemedies(rawPrefix)}`,
6514
+ { current, latest, method, prefix: rawPrefix }
6515
+ );
6516
+ return;
6517
+ }
6313
6518
  const quotedPrefix = rawPrefix === null ? null : quoteShellArgIfNeeded(rawPrefix);
6314
6519
  const globalSpec = GLOBAL_UPGRADE_METHODS.includes(method) ? upgradeSpawnSpec(method, quotedPrefix) : null;
6315
6520
  if (globalSpec) {
@@ -6368,7 +6573,7 @@ async function maybeAutoUpgrade(deps = {}) {
6368
6573
  return;
6369
6574
  }
6370
6575
  if (method === "npx") {
6371
- log("info", "yaw-mcp is out of date; restart your MCP client to pick up the latest version", {
6576
+ log("info", `yaw-mcp is out of date; restart your MCP client to pick up the latest version. ${NPX_LATEST_CAVEAT}`, {
6372
6577
  current,
6373
6578
  latest,
6374
6579
  method
@@ -6479,14 +6684,11 @@ export {
6479
6684
  buildLaunchEntry,
6480
6685
  isProjectLocalEntry,
6481
6686
  findLegacyEntry,
6482
- findBlockedContainerSegment,
6483
- describeJsonShape,
6484
6687
  unparseableConfigFix,
6485
6688
  blockedContainerFix,
6486
6689
  STATE_SCHEMA_VERSION,
6487
6690
  STATE_FILENAME,
6488
6691
  isPersistenceDisabled,
6489
- isReadableStateVersion,
6490
6692
  PREWARM_FAILURE_BACKOFF_MS,
6491
6693
  statePath,
6492
6694
  loadState,
@@ -6509,7 +6711,11 @@ export {
6509
6711
  compareVersions,
6510
6712
  resolveBinAbsolute,
6511
6713
  probeOam,
6714
+ launcherBasename,
6512
6715
  nodeLaunchKind,
6716
+ scanNodeLaunchFlags,
6717
+ describeNodeFlagRefusal,
6718
+ OAM_SPACED_VALUE_OPTIONS,
6513
6719
  managedNodeBin,
6514
6720
  packageEntry,
6515
6721
  resolveStableNpmEntry,
@@ -6530,8 +6736,11 @@ export {
6530
6736
  runUpgrade,
6531
6737
  quoteShellArgIfNeeded,
6532
6738
  quoteArgForDisplay,
6739
+ PREFIX_REFUSED_REASON,
6740
+ prefixRefusedRemedies,
6533
6741
  detectRunningInstallPrefix,
6534
6742
  runsUnderNpmConfigPrefix,
6743
+ defaultConfirmGlobalPrefix2 as defaultConfirmGlobalPrefix,
6535
6744
  UPGRADE_LOCK_NAME,
6536
6745
  acquireUpgradeLock,
6537
6746
  readCheckMemo,