@yawlabs/mcp 1.1.13 → 1.1.15

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.
@@ -63,7 +63,6 @@ async function atomicWriteFile(filePath, contents, encoding = "utf8", mode, dirM
63
63
  const birthMode = mode ?? preserved;
64
64
  try {
65
65
  await writeFile(tmp, contents, birthMode === void 0 ? { encoding } : { encoding, mode: birthMode });
66
- await sweepStaleTmpSiblings(dir, path.basename(target), tmp);
67
66
  if (preserved !== void 0) {
68
67
  try {
69
68
  await chmod(tmp, preserved);
@@ -75,6 +74,7 @@ async function atomicWriteFile(filePath, contents, encoding = "utf8", mode, dirM
75
74
  await unlink(tmp).catch(() => void 0);
76
75
  throw err;
77
76
  }
77
+ await sweepStaleTmpSiblings(dir, path.basename(target), tmp);
78
78
  }
79
79
  async function sweepStaleTmpSiblings(dir, base, own) {
80
80
  const prefix = `${base}.tmp-`;
@@ -285,6 +285,26 @@ import { homedir as homedir4 } from "os";
285
285
  import { dirname as dirname3, isAbsolute as isAbsolute8, join as join10, resolve as resolve8, sep } from "path";
286
286
  import { fileURLToPath } from "url";
287
287
 
288
+ // src/bounded-child.ts
289
+ function killAndDetach(child, signal = "SIGKILL") {
290
+ try {
291
+ child.kill(signal);
292
+ } catch {
293
+ }
294
+ try {
295
+ child.stdout?.destroy();
296
+ } catch {
297
+ }
298
+ try {
299
+ child.stderr?.destroy();
300
+ } catch {
301
+ }
302
+ try {
303
+ child.unref();
304
+ } catch {
305
+ }
306
+ }
307
+
288
308
  // src/install-targets.ts
289
309
  import { homedir as homedir2 } from "os";
290
310
  import { isAbsolute as isAbsolute6, join as join8, resolve as resolve6 } from "path";
@@ -440,8 +460,11 @@ function stripTrailingCommas(src) {
440
460
  }
441
461
  return out;
442
462
  }
463
+ function debom(src) {
464
+ return src.charCodeAt(0) === 65279 ? src.slice(1) : src;
465
+ }
443
466
  function parseJsonc(src) {
444
- const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
467
+ const debommed = debom(src);
445
468
  const stripped = stripTrailingCommas(stripJsoncComments(debommed));
446
469
  return JSON.parse(stripped);
447
470
  }
@@ -676,7 +699,7 @@ function spliceEdits(text, path5, value) {
676
699
  return null;
677
700
  }
678
701
  function duplicateJsoncKeyOnPath(src, path5) {
679
- const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
702
+ const debommed = debom(src);
680
703
  let node = parseTree(debommed, [], { allowTrailingComma: true });
681
704
  for (let i = 0; i < path5.length; i++) {
682
705
  if (node === void 0 || node.type !== "object") return null;
@@ -693,14 +716,14 @@ function editJsoncEntry(src, containerPath, entryName, value) {
693
716
  if (entryName === "") {
694
717
  throw new Error("editJsoncEntry: entryName must be a non-empty key");
695
718
  }
696
- const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
719
+ const debommed = debom(src);
697
720
  return applyEdits(debommed, computeEdits(debommed, [...containerPath, entryName], value));
698
721
  }
699
722
  function removeJsoncEntry(src, containerPath, entryName) {
700
723
  if (entryName === "") {
701
724
  throw new Error("removeJsoncEntry: entryName must be a non-empty key");
702
725
  }
703
- const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
726
+ const debommed = debom(src);
704
727
  const edits = computeEdits(debommed, [...containerPath, entryName], void 0);
705
728
  if (edits.length === 0) return src;
706
729
  return applyEdits(debommed, edits);
@@ -712,7 +735,7 @@ function editJsoncPath(src, path5, value) {
712
735
  if (path5.some((seg) => seg === "")) {
713
736
  throw new Error("editJsoncPath: path segments must be non-empty");
714
737
  }
715
- const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
738
+ const debommed = debom(src);
716
739
  const edits = computeEdits(debommed, path5, value);
717
740
  if (edits.length === 0) return src;
718
741
  return applyEdits(debommed, edits);
@@ -729,7 +752,7 @@ function arrayNodeAt(text, path5) {
729
752
  }
730
753
  function addJsoncArrayElement(src, path5, value) {
731
754
  if (path5.length === 0) throw new Error("addJsoncArrayElement: path must not be empty");
732
- const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
755
+ const debommed = debom(src);
733
756
  const array = arrayNodeAt(debommed, path5);
734
757
  if (array === null) {
735
758
  const errors = [];
@@ -759,7 +782,7 @@ function addJsoncArrayElement(src, path5, value) {
759
782
  }
760
783
  function removeJsoncArrayElements(src, path5, matches) {
761
784
  if (path5.length === 0) throw new Error("removeJsoncArrayElements: path must not be empty");
762
- const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
785
+ const debommed = debom(src);
763
786
  const array = arrayNodeAt(debommed, path5);
764
787
  if (array === null) {
765
788
  const errors = [];
@@ -795,25 +818,23 @@ function removeJsoncArrayElements(src, path5, matches) {
795
818
  // src/client-config-json.ts
796
819
  var BOM = String.fromCharCode(65279);
797
820
  function stripBom(raw) {
798
- return raw.charCodeAt(0) === 65279 ? { text: raw.slice(1), had: true } : { text: raw, had: false };
799
- }
800
- function isRecord2(value) {
801
- return typeof value === "object" && value !== null && !Array.isArray(value);
821
+ const text = debom(raw);
822
+ return { text, had: text.length !== raw.length };
802
823
  }
803
824
  function containerAt(root, segments) {
804
825
  let cursor = root;
805
826
  for (const key of segments) {
806
- if (!isRecord2(cursor)) return null;
827
+ if (!isRecord(cursor)) return null;
807
828
  cursor = cursor[key];
808
829
  }
809
- return isRecord2(cursor) ? cursor : null;
830
+ return isRecord(cursor) ? cursor : null;
810
831
  }
811
832
  function blockedSegment(root, segments) {
812
833
  let node = root;
813
834
  for (let i = 0; i < segments.length; i++) {
814
835
  const value = node[segments[i]];
815
836
  if (value === void 0) return null;
816
- if (isRecord2(value)) {
837
+ if (isRecord(value)) {
817
838
  node = value;
818
839
  continue;
819
840
  }
@@ -914,7 +935,7 @@ function classifyJson(raw, addr, transform, strict) {
914
935
  };
915
936
  }
916
937
  }
917
- if (!isRecord2(parsed)) {
938
+ if (!isRecord(parsed)) {
918
939
  return { kind: "malformed", syntax: "JSON", reason: "root", detail: describeValueShape(parsed), position: null };
919
940
  }
920
941
  const blocked = blockedSegment(parsed, addr.containerPath);
@@ -948,7 +969,7 @@ function removeJson(raw, addr, key) {
948
969
  } catch {
949
970
  return raw;
950
971
  }
951
- if (!isRecord2(parsed)) return raw;
972
+ if (!isRecord(parsed)) return raw;
952
973
  const container = containerAt(parsed, addr.containerPath);
953
974
  if (container === null || !Object.hasOwn(container, key)) return raw;
954
975
  refuseDuplicateKey(raw, [...addr.containerPath, key]);
@@ -963,7 +984,7 @@ function previewJson(addr, key, entry, _creating) {
963
984
  }
964
985
  function canonJson(raw, addr, opts) {
965
986
  const parsed = parseJsonc(raw);
966
- if (!isRecord2(parsed)) throw new Error("client-config-json: canon needs a JSON object");
987
+ if (!isRecord(parsed)) throw new Error("client-config-json: canon needs a JSON object");
967
988
  const clone = JSON.parse(JSON.stringify(parsed));
968
989
  const segments = addr.containerPath;
969
990
  const leaf = segments[segments.length - 1];
@@ -973,7 +994,7 @@ function canonJson(raw, addr, opts) {
973
994
  for (let i = 0; i < segments.length; i++) {
974
995
  cut = i;
975
996
  const value = holder[segments[i]];
976
- if (!isRecord2(value) || i === segments.length - 1) break;
997
+ if (!isRecord(value) || i === segments.length - 1) break;
977
998
  holder = value;
978
999
  }
979
1000
  delete holder[segments[cut]];
@@ -981,13 +1002,13 @@ function canonJson(raw, addr, opts) {
981
1002
  const above = containerAt(clone, segments.slice(0, depth - 1));
982
1003
  const key = segments[depth - 1];
983
1004
  const value = above === null ? void 0 : above[key];
984
- if (above === null || !isRecord2(value) || Object.keys(value).length > 0) break;
1005
+ if (above === null || !isRecord(value) || Object.keys(value).length > 0) break;
985
1006
  delete above[key];
986
1007
  }
987
1008
  } else if (leaf !== void 0) {
988
1009
  const parent = containerAt(clone, segments.slice(0, -1));
989
1010
  const container = parent === null ? void 0 : parent[leaf];
990
- if (isRecord2(container)) {
1011
+ if (isRecord(container)) {
991
1012
  for (const key of opts?.drop ?? []) delete container[key];
992
1013
  }
993
1014
  }
@@ -1049,6 +1070,15 @@ function syntaxNameFor(format) {
1049
1070
  function containerNounFor(syntax) {
1050
1071
  return syntax === "TOML" ? "a TOML table" : "a JSON object";
1051
1072
  }
1073
+ function spellRootValue(value, syntax) {
1074
+ if (typeof value === "string") return JSON.stringify(value);
1075
+ if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return String(value);
1076
+ if (value instanceof Date) return value.toISOString();
1077
+ return Array.isArray(value) ? describeValueShape(value) : containerNounFor(syntax);
1078
+ }
1079
+ function rootLinePlacement(syntax) {
1080
+ return syntax === "TOML" ? "above the first table in the file" : "at the top level of the file";
1081
+ }
1052
1082
  function effectiveConfigFormat(shape, scope) {
1053
1083
  return scope?.strictJson === true && shape.format === "jsonc" ? "json" : shape.format;
1054
1084
  }
@@ -1150,6 +1180,28 @@ function terminateWithNewline(text) {
1150
1180
  function findLegacyKey(keys) {
1151
1181
  return LEGACY_ENTRY_NAMES.find((name) => keys.includes(name)) ?? null;
1152
1182
  }
1183
+ var BROKER_PACKAGE_SPEC = /^@yawlabs\/mcp(?:@[^/\s]*)?$/;
1184
+ var BROKER_ENTRY_FILE = /[\\/]@yawlabs[\\/]mcp[\\/]dist[\\/]index\.js$/;
1185
+ var BROKER_BIN = /(?:^|[\\/])yaw-mcp(?:\.cmd|\.exe|\.ps1)?$/i;
1186
+ var CMD_EXE = /(?:^|[\\/])cmd(?:\.exe)?$/i;
1187
+ var CMD_RUN_SWITCH = /^\/[ck]$/i;
1188
+ function cmdProgram(args) {
1189
+ for (let i = 0; i < args.length; i++) {
1190
+ const a = args[i];
1191
+ if (CMD_RUN_SWITCH.test(a)) return args[i + 1];
1192
+ if (!a.startsWith("/")) return void 0;
1193
+ }
1194
+ return void 0;
1195
+ }
1196
+ function launchesBroker(entry) {
1197
+ const command = typeof entry.command === "string" ? entry.command : "";
1198
+ const args = Array.isArray(entry.args) ? entry.args.filter((a) => typeof a === "string") : [];
1199
+ if ([command, ...args].some((t) => BROKER_PACKAGE_SPEC.test(t) || BROKER_ENTRY_FILE.test(t))) return true;
1200
+ if (BROKER_BIN.test(command)) return true;
1201
+ if (!CMD_EXE.test(command)) return false;
1202
+ const program = cmdProgram(args);
1203
+ return program !== void 0 && BROKER_BIN.test(program);
1204
+ }
1153
1205
  function classifyClientConfig(raw, site, opts = {}) {
1154
1206
  const adapter = adapterFor(site.format);
1155
1207
  const candidates = opts.containerPaths !== void 0 && opts.containerPaths.length > 0 ? opts.containerPaths : [site.resolved.containerPath];
@@ -1182,6 +1234,10 @@ function isWired(read) {
1182
1234
  function makeView(read, raw, address, addressIndex, adapter, opts) {
1183
1235
  const entries = read.kind === "ok" ? read.entries : [];
1184
1236
  const at = (key) => entries.find((e) => e.key === (key ?? ENTRY_NAME));
1237
+ const others = () => {
1238
+ const skip = /* @__PURE__ */ new Set([ENTRY_NAME, ...LEGACY_ENTRY_NAMES]);
1239
+ return entries.filter((e) => !skip.has(e.key) && isRecord(e.value));
1240
+ };
1185
1241
  return {
1186
1242
  read,
1187
1243
  raw,
@@ -1195,10 +1251,11 @@ function makeView(read, raw, address, addressIndex, adapter, opts) {
1195
1251
  return found === void 0 ? void 0 : normalizeEntry(found.value, opts.transform);
1196
1252
  },
1197
1253
  legacyKey: () => findLegacyKey(entries.map((e) => e.key)),
1198
- otherServerKeys: () => {
1199
- const skip = /* @__PURE__ */ new Set([ENTRY_NAME, ...LEGACY_ENTRY_NAMES]);
1200
- return entries.filter((e) => !skip.has(e.key) && isRecord(e.value)).map((e) => e.key);
1201
- },
1254
+ otherServerKeys: () => others().map((e) => e.key),
1255
+ otherBrokerKeys: () => others().filter((e) => {
1256
+ const normalized = normalizeEntry(e.value, opts.transform);
1257
+ return isRecord(normalized) && launchesBroker(normalized);
1258
+ }).map((e) => e.key),
1202
1259
  count: () => entries.length,
1203
1260
  carryableEnv: (key) => carryableEnvOf(at(key)?.value, opts.transform),
1204
1261
  carried: (key) => carriedFieldsOf(at(key)?.value, opts.transform),
@@ -1360,16 +1417,16 @@ function applyClientConfigEdits(view, edits, site) {
1360
1417
  if (read.kind === "blocked") {
1361
1418
  const repair = edits.find((edit) => edit.op === "repair" && sameSegments(edit.path, read.path));
1362
1419
  if (repair === void 0 || !read.reparable || edits[0] !== repair) {
1363
- throw new ClientConfigWriteError(refusalFor(read, where, edits));
1420
+ throw new ClientConfigWriteError(refusalFor(read, where, edits, adapter.syntax));
1364
1421
  }
1365
1422
  } else if (read.kind !== "ok") {
1366
- throw new ClientConfigWriteError(refusalFor(read, where, edits));
1423
+ throw new ClientConfigWriteError(refusalFor(read, where, edits, adapter.syntax));
1367
1424
  } else {
1368
1425
  for (const edit of edits) {
1369
1426
  if (edit.op !== "upsert" && edit.op !== "remove") continue;
1370
1427
  const stuck = read.unspliceableEntries?.find((e) => e.key === edit.key);
1371
1428
  if (stuck !== void 0) {
1372
- throw new ClientConfigWriteError(refusalFor({ kind: "unspliceable", ...stuck }, where, edits));
1429
+ throw new ClientConfigWriteError(refusalFor({ kind: "unspliceable", ...stuck }, where, edits, adapter.syntax));
1373
1430
  }
1374
1431
  }
1375
1432
  }
@@ -1401,12 +1458,12 @@ function applyClientConfigEdits(view, edits, site) {
1401
1458
  function configPositionClause(position) {
1402
1459
  return position === null ? "" : ` at line ${position.line} column ${position.column}`;
1403
1460
  }
1404
- function refusalFor(read, where, edits) {
1461
+ function refusalFor(read, where, edits, syntax) {
1405
1462
  if (read.kind === "unreadable") return `${where} could not be read (${read.message})`;
1406
1463
  if (read.kind === "malformed") {
1407
1464
  const at = configPositionClause(read.position);
1408
1465
  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})`;
1466
+ return read.reason === "root" ? `${where} is not ${containerNounFor(read.syntax)} (it is ${read.detail})` : `${where} is not valid ${read.syntax}${at} (${detail})`;
1410
1467
  }
1411
1468
  if (read.kind === "unspliceable") {
1412
1469
  const fix = read.fix === void 0 ? "" : `; ${read.fix}, then re-run`;
@@ -1418,7 +1475,7 @@ function refusalFor(read, where, edits) {
1418
1475
  if (repaired && read.reparable) {
1419
1476
  return `"${key}" in ${where} is ${read.shape}: its repair has to be the FIRST edit, before anything is spliced in`;
1420
1477
  }
1421
- return read.reparable ? `"${key}" in ${where} is ${read.shape}, not an object -- it has to be repaired before an entry can be written` : `"${key}" in ${where} is ${read.shape}, not an object -- refusing to overwrite it`;
1478
+ return read.reparable ? `"${key}" in ${where} is ${read.shape}, not ${containerNounFor(syntax)} -- it has to be repaired before an entry can be written` : `"${key}" in ${where} is ${read.shape}, not ${containerNounFor(syntax)} -- refusing to overwrite it`;
1422
1479
  }
1423
1480
  return `${where} cannot be edited`;
1424
1481
  }
@@ -1653,6 +1710,8 @@ function editorRoot(base, dirName) {
1653
1710
  display: ["~", "Library", "Application Support", dirName]
1654
1711
  };
1655
1712
  }
1713
+ const xdg = base.env.xdgConfigHome?.trim();
1714
+ if (xdg && isAbsolute(xdg)) return { dir: join2(xdg, dirName), display: ["$XDG_CONFIG_HOME", dirName] };
1656
1715
  return { dir: join2(base.home, ".config", dirName), display: ["~", ".config", dirName] };
1657
1716
  }
1658
1717
  function sharedSettingsFile(base) {
@@ -1830,7 +1889,7 @@ function bomOffset(text) {
1830
1889
  return text.charCodeAt(0) === 65279 ? 1 : 0;
1831
1890
  }
1832
1891
  function stripBom2(raw) {
1833
- return raw.slice(bomOffset(raw));
1892
+ return debom(raw);
1834
1893
  }
1835
1894
  function parseTomlConfig(raw) {
1836
1895
  const text = stripBom2(raw);
@@ -3110,20 +3169,18 @@ function zedConfigDir(base) {
3110
3169
  return { dir: join6(base.home, ".config", "zed"), display: "~/.config/zed" };
3111
3170
  }
3112
3171
  function resolveZedPath(base) {
3172
+ const sep3 = base.os === "windows" ? "\\" : "/";
3113
3173
  if (base.scope === "project") {
3114
- const sep4 = base.os === "windows" ? "\\" : "/";
3115
3174
  return {
3116
3175
  absolute: join6(base.projectDir, ".zed", "settings.json"),
3117
- display: ["<project folder>", ".zed", "settings.json"].join(sep4),
3176
+ display: ["<project folder>", ".zed", "settings.json"].join(sep3),
3118
3177
  containerPath: ["context_servers"]
3119
3178
  };
3120
3179
  }
3121
3180
  const cfg = zedConfigDir(base);
3122
- if (!cfg) throw new Error(`Zed's settings.json location on ${base.os} is unknown`);
3123
- const sep3 = base.os === "windows" ? "\\" : "/";
3124
3181
  return {
3125
3182
  absolute: join6(cfg.dir, "settings.json"),
3126
- display: [cfg.display, "settings.json"].join(base.os === "windows" ? sep3 : "/"),
3183
+ display: [cfg.display, "settings.json"].join(sep3),
3127
3184
  containerPath: ["context_servers"]
3128
3185
  };
3129
3186
  }
@@ -3341,13 +3398,23 @@ async function prepareClaudeCodeSettingsPatch(opts) {
3341
3398
  }
3342
3399
 
3343
3400
  // src/install-targets.ts
3401
+ function geminiImportView(stored) {
3402
+ if (typeof stored.httpUrl !== "string" || stored.httpUrl.trim() === "") return { entry: stored };
3403
+ const { httpUrl, url: _url, type: _type, ...rest } = stored;
3404
+ return { entry: { ...rest, url: httpUrl } };
3405
+ }
3344
3406
  var TARGET_ROWS = [
3345
3407
  defineTarget({
3346
3408
  clientId: "claude-code",
3347
3409
  label: "Claude Code",
3348
3410
  config: { format: "jsonc", root: "mcpServers" },
3349
3411
  availableOn: ["macos", "linux", "windows"],
3350
- hooks: { permissionsPatch: "claude-code" },
3412
+ // importVariables: Claude Code expands `${VAR}` and `${VAR:-default}` in
3413
+ // an entry's command, args, env, url and headers, in `.mcp.json` and in
3414
+ // `~/.claude.json` alike (code.claude.com/docs/en/mcp, "Environment
3415
+ // variable expansion in .mcp.json", read 2026-11-15), so `import` refuses
3416
+ // a server carrying one rather than copy the literal text.
3417
+ hooks: { permissionsPatch: "claude-code", importVariables: "posix-env" },
3351
3418
  scopes: [
3352
3419
  {
3353
3420
  scope: "user",
@@ -3407,6 +3474,11 @@ var TARGET_ROWS = [
3407
3474
  label: "Cursor",
3408
3475
  config: { format: "jsonc", root: "mcpServers" },
3409
3476
  availableOn: ["macos", "linux", "windows"],
3477
+ // Cursor resolves `${env:NAME}`, `${userHome}`, `${workspaceFolder}`,
3478
+ // `${workspaceFolderBasename}`, `${pathSeparator}` and `${/}` in command,
3479
+ // args, env, url and headers (cursor.com/docs/mcp, "Config
3480
+ // interpolation", read 2026-11-15).
3481
+ hooks: { importVariables: "cursor-env" },
3410
3482
  scopes: [
3411
3483
  {
3412
3484
  scope: "user",
@@ -3470,6 +3542,9 @@ var TARGET_ROWS = [
3470
3542
  label: "Gemini CLI",
3471
3543
  config: { format: "jsonc", root: "mcpServers" },
3472
3544
  availableOn: ["macos", "linux", "windows"],
3545
+ // `url` + `type` and a bare `url` import as they are; `httpUrl` is the one
3546
+ // Gemini spelling the importer cannot read -- see geminiImportView.
3547
+ entry: { forImport: geminiImportView },
3473
3548
  // The folder-trust sentence was measured on Gemini CLI 0.66.0 (Linux,
3474
3549
  // 2026-10-31): in a folder not yet trusted, `gemini mcp list` showed a
3475
3550
  // working user-level server as "Disabled", with "MCP servers are
@@ -3892,6 +3967,7 @@ function sidecarsNodeModules(home = homedir3()) {
3892
3967
  }
3893
3968
  var GIT_DIRNAME = "git";
3894
3969
  var GIT_BUILD_SHA_LEN = 12;
3970
+ var GIT_BUILT_SUFFIX = ".built";
3895
3971
  function gitRoot(home = homedir3()) {
3896
3972
  return path2.join(userConfigDir(home), GIT_DIRNAME);
3897
3973
  }
@@ -3951,7 +4027,11 @@ function ownedByCurrentUser(st, env) {
3951
4027
  if (typeof geteuid !== "function") return isFeatureEnabled(ALLOW_UNOWNED_ENV, env);
3952
4028
  return typeof st.uid === "number" && st.uid === geteuid.call(process);
3953
4029
  }
3954
- async function findProjectConfigDir(start, home = homedir3(), env = process.env) {
4030
+ function untrustedProjectDirReason() {
4031
+ const geteuid = process.geteuid;
4032
+ return typeof geteuid === "function" ? "it is owned by another user" : `its owner cannot be verified on this platform (set ${ALLOW_UNOWNED_ENV}=1 to trust it)`;
4033
+ }
4034
+ async function findProjectConfigDir(start, home = homedir3(), env = process.env, skipped = null) {
3955
4035
  const homeFallback = home && home.length > 0 ? home : homedir3();
3956
4036
  const homeResolved = path2.resolve(await realpathOrSelf(path2.resolve(homeFallback)));
3957
4037
  let dir = path2.resolve(await realpathOrSelf(path2.resolve(start)));
@@ -3974,9 +4054,10 @@ async function findProjectConfigDir(start, home = homedir3(), env = process.env)
3974
4054
  rememberWarnedUntrustedDir(candidate);
3975
4055
  log("warn", "Skipping an untrusted .yaw-mcp/ dir outside $HOME", {
3976
4056
  candidate,
3977
- hint: `owned by another user, or ownership is unverifiable on this platform (set ${ALLOW_UNOWNED_ENV}=1 to trust it)`
4057
+ hint: untrustedProjectDirReason()
3978
4058
  });
3979
4059
  }
4060
+ if (skipped !== null && skipped.first === null) skipped.first = candidate;
3980
4061
  }
3981
4062
  } catch {
3982
4063
  }
@@ -3999,6 +4080,7 @@ import { mkdir as mkdir2, open, readdir as readdir2, readFile as readFile3, rena
3999
4080
  import { basename as basename2, dirname, join as join9 } from "path";
4000
4081
  import { setTimeout as delay2 } from "timers/promises";
4001
4082
  var LOCK_SUFFIX = ".lock";
4083
+ var LOCK_DIR_MODE = 448;
4002
4084
  var DEFAULT_LOCK_STALE_MS = 1e4;
4003
4085
  var DEFAULT_LOCK_WAIT_MS = 15e3;
4004
4086
  var LOCK_POLL_MS = 25;
@@ -4092,7 +4174,7 @@ async function withFileLock(path5, opts, describeTimeout, fn) {
4092
4174
  const token = `${process.pid}-${++lockSeq}
4093
4175
  `;
4094
4176
  const isLive = (ageMs) => ageMs > -LOCK_FUTURE_SKEW_MS && ageMs < staleMs;
4095
- await mkdir2(dirname(path5), { recursive: true });
4177
+ await mkdir2(dirname(path5), { recursive: true, mode: LOCK_DIR_MODE });
4096
4178
  await sweepStaleLitter(lockPath, staleMs);
4097
4179
  const deadline = Date.now() + waitMs;
4098
4180
  let transientSince = null;
@@ -4179,7 +4261,8 @@ async function loadStateClassified(filePath = statePath(), options = {}) {
4179
4261
  }
4180
4262
  try {
4181
4263
  const parsed = JSON.parse(raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw);
4182
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
4264
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
4265
+ if (!quiet) log("warn", "yaw-mcp state file is not a JSON object; not read");
4183
4266
  return {
4184
4267
  state: emptyState(),
4185
4268
  rawCounts: NO_RAW_COUNTS,
@@ -4187,15 +4270,25 @@ async function loadStateClassified(filePath = statePath(), options = {}) {
4187
4270
  missing: false,
4188
4271
  failure: { kind: "malformed", message: "top-level value is not an object" }
4189
4272
  };
4273
+ }
4190
4274
  const version = parsed.version;
4191
- if (!isReadableStateVersion(version))
4275
+ if (!isReadableStateVersion(version)) {
4276
+ const newer = typeof version === "number" && version > STATE_SCHEMA_VERSION;
4277
+ if (!quiet) {
4278
+ log(
4279
+ "warn",
4280
+ newer ? "yaw-mcp state file was written by a newer yaw-mcp; not read, and flagged so a save cannot overwrite it" : "yaw-mcp state file has an unreadable schema version; not read",
4281
+ { fileVersion: typeof version === "number" ? version : String(version), reads: STATE_SCHEMA_VERSION }
4282
+ );
4283
+ }
4192
4284
  return {
4193
- state: emptyState(),
4285
+ state: newer ? { ...emptyState(), loadFailed: true } : emptyState(),
4194
4286
  rawCounts: NO_RAW_COUNTS,
4195
4287
  parsedCleanly: false,
4196
4288
  missing: false,
4197
4289
  failure: { kind: "stale-version", version }
4198
4290
  };
4291
+ }
4199
4292
  const p = parsed;
4200
4293
  return {
4201
4294
  state: {
@@ -4350,6 +4443,9 @@ function mergeStateDelta(disk, baseline, current) {
4350
4443
  }
4351
4444
  var StateSync = class {
4352
4445
  baseline = { learning: {}, packHistory: [], toolCache: {} };
4446
+ /** The "written by a newer yaw-mcp" deferral has been logged and no save
4447
+ * has completed since. */
4448
+ newerFileWarned = false;
4353
4449
  filePath;
4354
4450
  lock;
4355
4451
  hooks;
@@ -4366,7 +4462,15 @@ var StateSync = class {
4366
4462
  }
4367
4463
  /** Save this process's pending changes. Resolves true when they reached
4368
4464
  * disk, false when they are still pending for the next save. */
4369
- save() {
4465
+ async save() {
4466
+ return await this.saveWithOutcome() === "saved";
4467
+ }
4468
+ /** save(), saying why a save did not land: "pending" is a transient miss
4469
+ * (lock wait, unreadable re-read, failed write) worth retrying soon;
4470
+ * "newer-file" means state.json was written by a newer yaw-mcp, which
4471
+ * defers every save for as long as the file stays, so retrying on a
4472
+ * timer only re-reads it under the lock to the same answer. */
4473
+ saveWithOutcome() {
4370
4474
  return chained(() => this.saveLocked());
4371
4475
  }
4372
4476
  async saveLocked() {
@@ -4374,8 +4478,13 @@ var StateSync = class {
4374
4478
  let written;
4375
4479
  try {
4376
4480
  written = await withFileLock(filePath, lockOptions(this.lock), stateLockTimeoutMessage, async () => {
4377
- const onDisk = await loadStateClassified(filePath);
4378
- if (onDisk.state.loadFailed) return null;
4481
+ const onDisk = await loadStateClassified(filePath, { quiet: true });
4482
+ if (onDisk.state.loadFailed) return { deferred: onDisk.failure };
4483
+ if (onDisk.failure) {
4484
+ log("warn", "yaw-mcp state file was unusable at save time; replacing it with this process's state", {
4485
+ reason: onDisk.failure.kind
4486
+ });
4487
+ }
4379
4488
  const snapshot = cloneSavable(this.hooks.exportCurrent());
4380
4489
  const merged = onDisk.parsedCleanly ? mergeStateDelta(onDisk.state, this.baseline, snapshot) : mergeStateDelta(emptyState(), { learning: {}, packHistory: [] }, snapshot);
4381
4490
  const payload = buildPayload(merged);
@@ -4387,12 +4496,27 @@ var StateSync = class {
4387
4496
  error: errorMessage(err),
4388
4497
  lockTimeout: err instanceof FileLockTimeoutError
4389
4498
  });
4390
- return false;
4391
- }
4392
- if (written === null) {
4393
- log("warn", "yaw-mcp state save deferred: state.json could not be re-read; pending changes kept");
4394
- return false;
4499
+ return "pending";
4500
+ }
4501
+ if ("deferred" in written) {
4502
+ const failure = written.deferred;
4503
+ if (failure?.kind === "stale-version") {
4504
+ if (!this.newerFileWarned) {
4505
+ this.newerFileWarned = true;
4506
+ log(
4507
+ "warn",
4508
+ "yaw-mcp state save deferred: state.json was written by a newer yaw-mcp and will not be overwritten; nothing is saved until this install is upgraded (logged once)",
4509
+ { fileVersion: Number(failure.version), reads: STATE_SCHEMA_VERSION }
4510
+ );
4511
+ }
4512
+ return "newer-file";
4513
+ }
4514
+ log("warn", "yaw-mcp state save deferred: state.json could not be re-read; pending changes kept", {
4515
+ error: failure?.kind === "unreadable" ? failure.message : "unknown"
4516
+ });
4517
+ return "pending";
4395
4518
  }
4519
+ this.newerFileWarned = false;
4396
4520
  const refreshed = mergeStateDelta(written.payload, written.snapshot, this.hooks.exportCurrent());
4397
4521
  this.hooks.applyMerged(refreshed);
4398
4522
  this.baseline = cloneSavable({
@@ -4401,7 +4525,7 @@ var StateSync = class {
4401
4525
  toolCache: written.snapshot.toolCache,
4402
4526
  prewarmFailures: written.snapshot.prewarmFailures
4403
4527
  });
4404
- return true;
4528
+ return "saved";
4405
4529
  }
4406
4530
  };
4407
4531
  function cloneSavable(s) {
@@ -4608,6 +4732,11 @@ function isEphemeralMountPath(p) {
4608
4732
  // machine-global config, and no later pass could converge on it.
4609
4733
  /(^|\/)appimage_extracted_/i.test(posix);
4610
4734
  }
4735
+ function isSessionScopedPath(p) {
4736
+ if (isEphemeralMountPath(p)) return true;
4737
+ const posix = p.replace(/\\/g, "/");
4738
+ return /(^|\/)fnm_multishells\//.test(posix) || /^\/run\/user\/[0-9]+\//.test(posix);
4739
+ }
4611
4740
  function stableSpellingOf(entry, deps = {}) {
4612
4741
  const realpath3 = deps.realpath ?? realpathSync;
4613
4742
  let target;
@@ -4620,7 +4749,7 @@ function stableSpellingOf(entry, deps = {}) {
4620
4749
  if (typeof argv1 === "string" && argv1.length > 0) {
4621
4750
  try {
4622
4751
  const abs = isAbsolute7(argv1) ? argv1 : resolve7(argv1);
4623
- if (abs !== entry && realpath3(abs) === target) return abs;
4752
+ if (abs !== entry && !isSessionScopedPath(abs) && realpath3(abs) === target) return abs;
4624
4753
  } catch {
4625
4754
  }
4626
4755
  }
@@ -4957,15 +5086,7 @@ function spawnVersionProbe(bin) {
4957
5086
  );
4958
5087
  timer = setTimeout(() => {
4959
5088
  settle(() => {
4960
- try {
4961
- child.kill(OAM_PROBE_KILL_SIGNAL);
4962
- } catch {
4963
- }
4964
- try {
4965
- child.stdout?.destroy();
4966
- child.unref();
4967
- } catch {
4968
- }
5089
+ killAndDetach(child, OAM_PROBE_KILL_SIGNAL);
4969
5090
  const err = new Error(`oam --version exceeded ${OAM_PROBE_TIMEOUT_MS}ms`);
4970
5091
  err.code = "ETIMEDOUT";
4971
5092
  reject(err);
@@ -5080,9 +5201,10 @@ async function probeOamUncached(run, generation) {
5080
5201
  }
5081
5202
  return publish({
5082
5203
  bin,
5083
- // Resolved once (absResolved, above), alongside the probe that proved the
5084
- // name spawns, so the install path never has to re-derive it (or spawn
5085
- // `where`/`which`).
5204
+ // Resolved once (absResolved, above), alongside the probe, so the install
5205
+ // path never has to re-derive it (or spawn `where`/`which`). The probe
5206
+ // ran the bare name only on a verdict-cache miss; on a hit nothing was
5207
+ // spawned here and this path is the whole evidence (see OamProbe.bin).
5086
5208
  binPath: absResolved,
5087
5209
  version,
5088
5210
  belowMin: false,
@@ -5232,30 +5354,29 @@ function rewriteForOam(command, args, deps) {
5232
5354
  return toOam(scan.entry, scan.rest, scan.flags);
5233
5355
  }
5234
5356
  if (kind === "npx") {
5235
- const specIdx = npxSpecIndex(args);
5236
- const spec = specIdx === -1 ? void 0 : args[specIdx];
5237
- if (!spec) return { command, args };
5238
- if (spec.startsWith("-")) {
5357
+ const launch = classifyNpxLaunch(args);
5358
+ if (launch.kind === "no-spec") return { command, args };
5359
+ if (launch.kind === "flag-spec") {
5239
5360
  log("debug", "npx launch carries flags yaw-mcp does not parse; staying on npx instead of oam", {
5240
- flag: spec,
5361
+ flag: launch.flag,
5241
5362
  argc: args.length
5242
5363
  });
5243
5364
  return { command, args };
5244
5365
  }
5245
- if (!isRegistrySpec(spec)) {
5246
- log("debug", "npx spec is a git/path target, not a registry package; staying on npx instead of oam", { spec });
5366
+ if (launch.kind === "non-registry-spec") {
5367
+ log("debug", "npx spec is a git/path target, not a registry package; staying on npx instead of oam", {
5368
+ spec: launch.spec
5369
+ });
5247
5370
  return { command, args };
5248
5371
  }
5249
- const pkg = packageName(spec);
5250
- const constraint = specConstraint(spec);
5251
- if (constraint.kind === "range") {
5372
+ if (launch.kind === "version-range") {
5252
5373
  log("debug", "npx spec constrains the version with a range yaw-mcp cannot evaluate; staying on npx", {
5253
- package: pkg,
5254
- range: constraint.raw
5374
+ package: launch.pkg,
5375
+ range: launch.range
5255
5376
  });
5256
5377
  return { command, args };
5257
5378
  }
5258
- const wantVersion = constraint.kind === "exact" ? constraint.version : null;
5379
+ const { pkg, wantVersion } = launch;
5259
5380
  const entry = deps.resolveEntry(pkg, wantVersion);
5260
5381
  if (!entry) {
5261
5382
  if (wantVersion !== null) {
@@ -5268,10 +5389,26 @@ function rewriteForOam(command, args, deps) {
5268
5389
  }
5269
5390
  return { command, args };
5270
5391
  }
5271
- return toOam(entry, args.slice(specIdx + 1));
5392
+ return toOam(entry, launch.rest);
5272
5393
  }
5273
5394
  return { command, args };
5274
5395
  }
5396
+ function classifyNpxLaunch(args) {
5397
+ const specIdx = npxSpecIndex(args);
5398
+ const spec = specIdx === -1 ? void 0 : args[specIdx];
5399
+ if (!spec) return { kind: "no-spec" };
5400
+ if (spec.startsWith("-")) return { kind: "flag-spec", flag: spec };
5401
+ if (!isRegistrySpec(spec)) return { kind: "non-registry-spec", spec };
5402
+ const pkg = packageName(spec);
5403
+ const constraint = specConstraint(spec);
5404
+ if (constraint.kind === "range") return { kind: "version-range", pkg, range: constraint.raw };
5405
+ return {
5406
+ kind: "hostable",
5407
+ pkg,
5408
+ wantVersion: constraint.kind === "exact" ? constraint.version : null,
5409
+ rest: args.slice(specIdx + 1)
5410
+ };
5411
+ }
5275
5412
  function managedNodeBin(env = process.env, platform = process.platform, execPath = process.execPath) {
5276
5413
  if (nodeLaunchKind(execPath) === "node") return execPath;
5277
5414
  return resolveBinAbsolute("node", env, platform);
@@ -5282,46 +5419,44 @@ function rewriteNpmToManagedNode(command, args, deps) {
5282
5419
  log("debug", "no node binary located for the managed sidecar spawn; staying on npx", { command });
5283
5420
  return { command, args };
5284
5421
  }
5285
- const specIdx = npxSpecIndex(args);
5286
- const spec = specIdx === -1 ? void 0 : args[specIdx];
5287
- if (!spec) return { command, args };
5288
- if (spec.startsWith("-")) {
5422
+ const launch = classifyNpxLaunch(args);
5423
+ if (launch.kind === "no-spec") return { command, args };
5424
+ if (launch.kind === "flag-spec") {
5289
5425
  log("debug", "npx launch carries flags yaw-mcp does not parse; staying on npx instead of the managed tree", {
5290
- flag: spec,
5426
+ flag: launch.flag,
5291
5427
  argc: args.length
5292
5428
  });
5293
5429
  return { command, args };
5294
5430
  }
5295
- if (!isRegistrySpec(spec)) {
5431
+ if (launch.kind === "non-registry-spec") {
5296
5432
  log("debug", "npx spec is a git/path target, not a registry package; staying on npx instead of the managed tree", {
5297
- spec
5433
+ spec: launch.spec
5298
5434
  });
5299
5435
  return { command, args };
5300
5436
  }
5301
- const constraint = specConstraint(spec);
5302
- if (constraint.kind === "range") {
5437
+ if (launch.kind === "version-range") {
5303
5438
  log("debug", "npx spec constrains the version with a range yaw-mcp cannot evaluate; staying on npx", {
5304
- package: packageName(spec),
5305
- range: constraint.raw
5439
+ package: launch.pkg,
5440
+ range: launch.range
5306
5441
  });
5307
5442
  return { command, args };
5308
5443
  }
5309
- const wantVersion = constraint.kind === "exact" ? constraint.version : null;
5310
- const entry = deps.resolveEntry(packageName(spec), wantVersion);
5444
+ const { pkg, wantVersion } = launch;
5445
+ const entry = deps.resolveEntry(pkg, wantVersion);
5311
5446
  if (!entry) {
5312
5447
  if (wantVersion !== null) {
5313
5448
  log("debug", "no on-disk copy declares the pinned version; staying on npx so the pin is honoured", {
5314
- package: packageName(spec),
5449
+ package: pkg,
5315
5450
  version: wantVersion
5316
5451
  });
5317
5452
  } else {
5318
5453
  log("debug", "npx package has no on-disk entry; staying on npx instead of the managed tree", {
5319
- package: packageName(spec)
5454
+ package: pkg
5320
5455
  });
5321
5456
  }
5322
5457
  return { command, args };
5323
5458
  }
5324
- return { command: deps.nodeBin, args: [entry, ...args.slice(specIdx + 1)] };
5459
+ return { command: deps.nodeBin, args: [entry, ...launch.rest] };
5325
5460
  }
5326
5461
  var NPX_CACHE_MARKER = `${sep}_npx${sep}`;
5327
5462
  function npxHashNodeModules(npxRoot) {
@@ -5622,7 +5757,9 @@ function resolveManagedSpawn(command, args, fromUrl = import.meta.url, npmCache
5622
5757
  if (wantVersion !== null) return resolveNpmEntry(pkg, fromUrl, npmCache, managedRoot, wantVersion);
5623
5758
  const memoed = managedEntryMemo.get(pkg);
5624
5759
  if (memoed !== void 0) {
5625
- if (existsSync2(memoed)) return memoed;
5760
+ const managedPkgDir = managedRoot === null ? null : join10(managedRoot, ...pkg.split("/"));
5761
+ const supersededByManaged = managedPkgDir !== null && !memoed.startsWith(managedPkgDir + sep) && packageEntry(managedPkgDir, pkg) !== null;
5762
+ if (!supersededByManaged && existsSync2(memoed)) return memoed;
5626
5763
  managedEntryMemo.delete(pkg);
5627
5764
  }
5628
5765
  const hit = resolveNpmEntry(pkg, fromUrl, npmCache, managedRoot, null);
@@ -5636,26 +5773,35 @@ function isOamCommand(command) {
5636
5773
  return /^oam(\.exe)?$/i.test(base);
5637
5774
  }
5638
5775
  function isOamLaunch(command, args = []) {
5639
- if (isOamCommand(command)) return true;
5776
+ return unwrapOamLaunch(command, args, "strip-edge") !== null;
5777
+ }
5778
+ function unwrapOamLaunch(command, args, quotes) {
5779
+ if (isOamCommand(command)) return { oam: command, rest: args };
5640
5780
  const base = command.split(/[\\/]/).pop() ?? command;
5641
5781
  if (/^cmd(\.exe)?$/i.test(base)) {
5642
- const first = args.find((a) => !/^\/[a-z]$/i.test(a));
5643
- return first !== void 0 && isOamCommand(first);
5782
+ const i = args.findIndex((a) => !/^\/[a-z]$/i.test(a));
5783
+ if (i < 0 || !isOamCommand(args[i])) return null;
5784
+ return { oam: args[i], rest: args.slice(i + 1) };
5644
5785
  }
5645
5786
  if (POSIX_SHELL.test(base)) {
5646
5787
  const dashC = args.indexOf("-c");
5647
5788
  const payload = dashC >= 0 ? args[dashC + 1] : args[0];
5648
- if (payload === void 0) return false;
5649
- const firstToken = payload.trim().split(/\s+/)[0]?.replace(/^["']|["']$/g, "");
5650
- return firstToken !== void 0 && firstToken.length > 0 && isOamCommand(firstToken);
5789
+ return payload === void 0 ? null : shellPayloadTokens(payload, quotes);
5651
5790
  }
5652
5791
  if (POWERSHELL.test(base)) {
5653
5792
  const payload = powershellPayload(args);
5654
- if (payload === null) return false;
5655
- const firstToken = payload.trim().split(/\s+/)[0]?.replace(/^["']|["']$/g, "");
5656
- return firstToken !== void 0 && firstToken.length > 0 && isOamCommand(firstToken);
5793
+ return payload === null ? null : shellPayloadTokens(payload, quotes);
5657
5794
  }
5658
- return false;
5795
+ return null;
5796
+ }
5797
+ function shellPayloadTokens(payload, quotes) {
5798
+ if (quotes === "refuse" && /["']/.test(payload)) return null;
5799
+ const tokens = payload.trim().split(/\s+/);
5800
+ const first = firstShellToken(payload);
5801
+ return isOamCommand(first) ? { oam: first, rest: tokens.slice(1) } : null;
5802
+ }
5803
+ function firstShellToken(payload) {
5804
+ return (payload.trim().split(/\s+/)[0] ?? "").replace(/^["']|["']$/g, "");
5659
5805
  }
5660
5806
  var POSIX_SHELL = /^(sh|bash|zsh|dash|fish)$/i;
5661
5807
  var POWERSHELL = /^(pwsh|powershell)(\.exe)?$/i;
@@ -5667,6 +5813,25 @@ function powershellPayload(args) {
5667
5813
  return payload.trim().length > 0 ? payload : null;
5668
5814
  }
5669
5815
 
5816
+ // src/registry-latest.ts
5817
+ async function fetchLatestVersion(pkg, timeoutMs) {
5818
+ const ac = new AbortController();
5819
+ const timer = setTimeout(() => ac.abort(), timeoutMs);
5820
+ try {
5821
+ const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
5822
+ signal: ac.signal,
5823
+ headers: { accept: "application/json" }
5824
+ });
5825
+ if (!res.ok) return null;
5826
+ const body = await res.json();
5827
+ return typeof body.version === "string" ? body.version : null;
5828
+ } catch {
5829
+ return null;
5830
+ } finally {
5831
+ clearTimeout(timer);
5832
+ }
5833
+ }
5834
+
5670
5835
  // src/upgrade-cmd.ts
5671
5836
  var POSIX_GLOBAL_LIB_PREFIX = /^(?:[A-Za-z]:)?(?:\/usr(?:\/local)?|\/opt\/[^/]+)\/lib\/node_modules\/@yawlabs\/mcp\//;
5672
5837
  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\//;
@@ -5895,7 +6060,7 @@ function buildUpgradePlan(input) {
5895
6060
  return { current, latest, stale, method, command };
5896
6061
  }
5897
6062
  var REGISTRY_FETCH_TIMEOUT_MS = 3e3;
5898
- async function fetchLatestVersion(opts = {}) {
6063
+ async function fetchLatestVersion2(opts = {}) {
5899
6064
  if (opts.override) {
5900
6065
  try {
5901
6066
  return await opts.override();
@@ -5903,21 +6068,7 @@ async function fetchLatestVersion(opts = {}) {
5903
6068
  return null;
5904
6069
  }
5905
6070
  }
5906
- const ac = new AbortController();
5907
- const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? REGISTRY_FETCH_TIMEOUT_MS);
5908
- try {
5909
- const res = await fetch("https://registry.npmjs.org/@yawlabs/mcp/latest", {
5910
- signal: ac.signal,
5911
- headers: { accept: "application/json" }
5912
- });
5913
- if (!res.ok) return null;
5914
- const body = await res.json();
5915
- return typeof body.version === "string" ? body.version : null;
5916
- } catch {
5917
- return null;
5918
- } finally {
5919
- clearTimeout(timer);
5920
- }
6071
+ return fetchLatestVersion("@yawlabs/mcp", opts.timeoutMs ?? REGISTRY_FETCH_TIMEOUT_MS);
5921
6072
  }
5922
6073
  async function probeOamQuietly() {
5923
6074
  const names = ["YAW_MCP_LOG_LEVEL", "LOG_LEVEL"];
@@ -5957,21 +6108,21 @@ async function oamFloorLines(probe) {
5957
6108
  }
5958
6109
  async function defaultRunningPrefix(argvPath) {
5959
6110
  if (isTestSandbox()) return null;
5960
- const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-443C6423.js");
6111
+ const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-NT3QNOO2.js");
5961
6112
  return detectRunningInstallPrefix2(argvPath);
5962
6113
  }
5963
6114
  async function defaultConfirmGlobalPrefix(argvPath, prefix) {
5964
- const { defaultConfirmGlobalPrefix: confirm } = await import("./auto-upgrade-443C6423.js");
6115
+ const { defaultConfirmGlobalPrefix: confirm } = await import("./auto-upgrade-NT3QNOO2.js");
5965
6116
  return confirm(argvPath, prefix);
5966
6117
  }
5967
6118
  async function defaultAcquireLock(prefixDir) {
5968
6119
  if (isTestSandbox()) return () => {
5969
6120
  };
5970
- const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-443C6423.js");
6121
+ const { acquireUpgradeLock: acquireUpgradeLock2 } = await import("./auto-upgrade-NT3QNOO2.js");
5971
6122
  return acquireUpgradeLock2(prefixDir);
5972
6123
  }
5973
6124
  async function upgradeLockPath(prefixDir) {
5974
- const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-443C6423.js");
6125
+ const { UPGRADE_LOCK_NAME: UPGRADE_LOCK_NAME2 } = await import("./auto-upgrade-NT3QNOO2.js");
5975
6126
  return join11(prefixDir, UPGRADE_LOCK_NAME2);
5976
6127
  }
5977
6128
  async function defaultSpawn(cmd, args, cwd) {
@@ -6015,7 +6166,7 @@ async function runUpgrade(opts = {}) {
6015
6166
  writeErr(`${s}
6016
6167
  `);
6017
6168
  };
6018
- const fetcher = opts.fetchLatest ?? (isTestSandbox() ? async () => null : fetchLatestVersion);
6169
+ const fetcher = opts.fetchLatest ?? (isTestSandbox() ? async () => null : fetchLatestVersion2);
6019
6170
  const current = opts.currentVersion ?? readCurrentVersion();
6020
6171
  const argvPath = opts.argvPath ?? process.argv[1];
6021
6172
  const sea = opts.isSea ? opts.isSea() : await detectSea();
@@ -6035,12 +6186,12 @@ async function runUpgrade(opts = {}) {
6035
6186
  if (method === "global-npm") {
6036
6187
  rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
6037
6188
  if (rawPrefix !== null && !await (opts.confirmGlobalPrefix ?? defaultConfirmGlobalPrefix)(argvPath, rawPrefix)) {
6038
- const { PREFIX_REFUSED_REASON: PREFIX_REFUSED_REASON2, prefixRefusedRemedies: prefixRefusedRemedies2 } = await import("./auto-upgrade-443C6423.js");
6189
+ const { PREFIX_REFUSED_REASON: PREFIX_REFUSED_REASON2, prefixRefusedRemedies: prefixRefusedRemedies2 } = await import("./auto-upgrade-NT3QNOO2.js");
6039
6190
  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
6191
  rawPrefix = null;
6041
6192
  }
6042
6193
  if (rawPrefix !== null) {
6043
- const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-443C6423.js");
6194
+ const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-NT3QNOO2.js");
6044
6195
  const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
6045
6196
  const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
6046
6197
  if (spawnForm !== null && displayForm !== null) {
@@ -6179,7 +6330,7 @@ async function runUpgrade(opts = {}) {
6179
6330
  return { exitCode: 3, lines };
6180
6331
  }
6181
6332
  function readCurrentVersion() {
6182
- return true ? "1.1.13" : "dev";
6333
+ return true ? "1.1.15" : "dev";
6183
6334
  }
6184
6335
 
6185
6336
  // src/auto-upgrade.ts
@@ -6286,9 +6437,18 @@ function acquireUpgradeLock(dir, lockName = UPGRADE_LOCK_NAME, opts = {}) {
6286
6437
  try {
6287
6438
  writeSync(fd, `${mine}
6288
6439
  `);
6289
- } finally {
6290
- closeSync(fd);
6440
+ } catch (err) {
6441
+ try {
6442
+ closeSync(fd);
6443
+ } catch {
6444
+ }
6445
+ try {
6446
+ unlinkSync(lockPath);
6447
+ } catch {
6448
+ }
6449
+ throw err;
6291
6450
  }
6451
+ closeSync(fd);
6292
6452
  let released = false;
6293
6453
  return () => {
6294
6454
  if (released) return;
@@ -6359,7 +6519,7 @@ function defaultAcquireLock2(dir, lockName) {
6359
6519
  }
6360
6520
  function defaultFetchLatest() {
6361
6521
  if (isTestSandbox()) return Promise.resolve(null);
6362
- return fetchLatestVersion();
6522
+ return fetchLatestVersion2();
6363
6523
  }
6364
6524
  var UPGRADE_CHECK_INTERVAL_MS = 60 * 60 * 1e3;
6365
6525
  var UPGRADE_ATTEMPT_COOLDOWN_MS = 6 * 60 * 60 * 1e3;
@@ -6487,7 +6647,7 @@ function defaultSpawn2(cmd, args, onDone = () => {
6487
6647
  }
6488
6648
  async function maybeAutoUpgrade(deps = {}) {
6489
6649
  if (isFeatureDisabled("YAW_MCP_AUTO_UPGRADE")) return;
6490
- const current = deps.currentVersion ?? (true ? "1.1.13" : "dev");
6650
+ const current = deps.currentVersion ?? (true ? "1.1.15" : "dev");
6491
6651
  if (current === "dev") return;
6492
6652
  const argvPath = deps.argvPath ?? process.argv[1];
6493
6653
  let method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync3, ["unknown", "local-node-modules"]);
@@ -6504,6 +6664,14 @@ async function maybeAutoUpgrade(deps = {}) {
6504
6664
  const plan = buildUpgradePlan({ current, latest, method });
6505
6665
  if (!plan.stale) return;
6506
6666
  const rawPrefix = method === "global-npm" ? detectRunningInstallPrefix(argvPath) : null;
6667
+ if (method === "global-npm" && rawPrefix === null) {
6668
+ log(
6669
+ "info",
6670
+ "yaw-mcp is out of date; not upgrading in the background: the running copy could not be traced to a file inside a node_modules tree, so there is no install prefix to upgrade in place. Either it is a linked checkout (`npm link`), which a global install would replace rather than update, or its path could not be resolved. For a linked checkout, update the checkout it links to; otherwise run `npm install -g @yawlabs/mcp@latest` to install the published package.",
6671
+ { current, latest, method }
6672
+ );
6673
+ return;
6674
+ }
6507
6675
  if (rawPrefix !== null && !(deps.confirmGlobalPrefixImpl ?? defaultConfirmGlobalPrefix2)(argvPath, rawPrefix)) {
6508
6676
  log(
6509
6677
  "info",
@@ -6621,6 +6789,7 @@ export {
6621
6789
  sidecarsRoot,
6622
6790
  sidecarsNodeModules,
6623
6791
  GIT_BUILD_SHA_LEN,
6792
+ GIT_BUILT_SUFFIX,
6624
6793
  gitRoot,
6625
6794
  gitBuildDir,
6626
6795
  gitFailedPath,
@@ -6629,9 +6798,11 @@ export {
6629
6798
  tildePath,
6630
6799
  realpathOrSelf,
6631
6800
  isUnderHome,
6632
- ALLOW_UNOWNED_ENV,
6801
+ untrustedProjectDirReason,
6633
6802
  findProjectConfigDir,
6634
6803
  guidePath,
6804
+ killAndDetach,
6805
+ normalizeEntry,
6635
6806
  launchOf,
6636
6807
  canonicalJson,
6637
6808
  describeValueShape,
@@ -6643,6 +6814,8 @@ export {
6643
6814
  CONFIG_FORMATS,
6644
6815
  syntaxNameFor,
6645
6816
  containerNounFor,
6817
+ spellRootValue,
6818
+ rootLinePlacement,
6646
6819
  effectiveConfigFormat,
6647
6820
  selectSites,
6648
6821
  addressOf,
@@ -6656,6 +6829,7 @@ export {
6656
6829
  reloadRemovalClause,
6657
6830
  hasConfigAdapter,
6658
6831
  terminateWithNewline,
6832
+ launchesBroker,
6659
6833
  classifyClientConfig,
6660
6834
  containerKeysAt,
6661
6835
  siteAt,
@@ -6695,7 +6869,6 @@ export {
6695
6869
  packageName,
6696
6870
  specConstraint,
6697
6871
  isRegistrySpec,
6698
- npxSpecIndex,
6699
6872
  npxSpec,
6700
6873
  MIN_OAM_VERSION,
6701
6874
  oamInstallCommand,
@@ -6713,22 +6886,21 @@ export {
6713
6886
  scanNodeLaunchFlags,
6714
6887
  describeNodeFlagRefusal,
6715
6888
  OAM_SPACED_VALUE_OPTIONS,
6889
+ classifyNpxLaunch,
6716
6890
  managedNodeBin,
6717
6891
  packageEntry,
6718
6892
  resolveStableNpmEntry,
6719
6893
  resolveOamSpawn,
6720
6894
  resolveManagedSpawn,
6721
- isOamCommand,
6722
6895
  isOamLaunch,
6723
- POSIX_SHELL,
6724
- POWERSHELL,
6725
- powershellPayload,
6896
+ unwrapOamLaunch,
6897
+ fetchLatestVersion,
6726
6898
  parseUpgradeArgs,
6727
6899
  detectInstallMethod,
6728
6900
  refineInstallMethod,
6729
6901
  BINARY_RETIRED_HINT,
6730
6902
  buildUpgradePlan,
6731
- fetchLatestVersion,
6903
+ fetchLatestVersion2,
6732
6904
  detectSea,
6733
6905
  runUpgrade,
6734
6906
  quoteShellArgIfNeeded,