@yawlabs/mcp 0.79.1 → 0.79.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/{auto-upgrade-YUPODM3T.js → auto-upgrade-W6LVJ7XD.js} +1 -2
- package/dist/{chunk-33LK4DLQ.js → chunk-ODSIFM3N.js} +781 -48
- package/dist/index.js +1468 -754
- package/package.json +5 -4
- package/schemas/yaw-mcp.config.v1.json +7 -6
- package/dist/chunk-3RRZQPA5.js +0 -39
- package/dist/chunk-TBJCXYS4.js +0 -639
- package/dist/oam-spawn-UUOFWXFP.js +0 -82
|
@@ -1,7 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/auto-upgrade.ts
|
|
4
|
+
import { spawn as spawn3 } from "child_process";
|
|
2
5
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
closeSync,
|
|
7
|
+
openSync,
|
|
8
|
+
readFileSync as readFileSync2,
|
|
9
|
+
realpathSync as realpathSync2,
|
|
10
|
+
statSync as statSync2,
|
|
11
|
+
unlinkSync,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
writeSync
|
|
14
|
+
} from "fs";
|
|
15
|
+
import { tmpdir } from "os";
|
|
16
|
+
import { dirname as dirname2, join as join3, sep as sep2 } from "path";
|
|
17
|
+
|
|
18
|
+
// src/logger.ts
|
|
19
|
+
var LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
20
|
+
function minLevel() {
|
|
21
|
+
return LOG_LEVELS[process.env.LOG_LEVEL?.toLowerCase()] ?? LOG_LEVELS.info;
|
|
22
|
+
}
|
|
23
|
+
function guardStderrErrors() {
|
|
24
|
+
try {
|
|
25
|
+
if (process.stderr.listenerCount("error") === 0) {
|
|
26
|
+
process.stderr.on("error", () => {
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function log(level, msg, data) {
|
|
33
|
+
if (LOG_LEVELS[level] < minLevel()) return;
|
|
34
|
+
guardStderrErrors();
|
|
35
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
36
|
+
let entry;
|
|
37
|
+
try {
|
|
38
|
+
entry = JSON.stringify({ ...data, level, msg, ts });
|
|
39
|
+
} catch {
|
|
40
|
+
entry = JSON.stringify({ level, msg, ts, dataOmitted: true });
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
process.stderr.write(`${entry}
|
|
44
|
+
`);
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/upgrade-cmd.ts
|
|
50
|
+
import { spawn as spawn2 } from "child_process";
|
|
51
|
+
import { realpathSync } from "fs";
|
|
5
52
|
|
|
6
53
|
// src/oam-spawn.ts
|
|
7
54
|
import { spawn } from "child_process";
|
|
@@ -92,9 +139,16 @@ var INSTALL_TARGETS = [
|
|
|
92
139
|
]
|
|
93
140
|
}
|
|
94
141
|
];
|
|
142
|
+
function resolveAppDataDir(opts) {
|
|
143
|
+
if (opts.appData !== void 0 && opts.appData.length > 0) return opts.appData;
|
|
144
|
+
if (opts.home !== void 0) return join(opts.home, "AppData", "Roaming");
|
|
145
|
+
const env = opts.env ?? process.env;
|
|
146
|
+
const fromEnv = env.APPDATA;
|
|
147
|
+
return fromEnv && fromEnv.length > 0 ? fromEnv : join(homedir(), "AppData", "Roaming");
|
|
148
|
+
}
|
|
95
149
|
function resolveInstallPath(opts) {
|
|
96
150
|
const home = opts.home ?? homedir();
|
|
97
|
-
const appData = opts.appData
|
|
151
|
+
const appData = opts.appData && opts.appData.length > 0 ? opts.appData : join(home, "AppData", "Roaming");
|
|
98
152
|
const { clientId, scope, os, projectDir, claudeConfigDir } = opts;
|
|
99
153
|
const target = INSTALL_TARGETS.find((t) => t.clientId === clientId);
|
|
100
154
|
if (!target) throw new Error(`Unknown client: ${clientId}`);
|
|
@@ -120,8 +174,8 @@ function claudeCodeProjectKey(projectDir) {
|
|
|
120
174
|
}
|
|
121
175
|
function pathFor(client, scope, os, base) {
|
|
122
176
|
const { home, appData, projectDir, claudeConfigDir } = base;
|
|
123
|
-
const
|
|
124
|
-
const joinPath = (...parts) => parts.join(
|
|
177
|
+
const sep3 = os === "windows" ? "\\" : "/";
|
|
178
|
+
const joinPath = (...parts) => parts.join(sep3);
|
|
125
179
|
if (client === "claude-code") {
|
|
126
180
|
if (scope === "user") {
|
|
127
181
|
if (claudeConfigDir) {
|
|
@@ -188,7 +242,7 @@ function pathFor(client, scope, os, base) {
|
|
|
188
242
|
}
|
|
189
243
|
var CMD_METACHARS = /[&|<>^()]/g;
|
|
190
244
|
var HAS_CMD_METACHAR = /[&|<>^()]/;
|
|
191
|
-
var KNOWN_CMD_SHIM_LAUNCHERS = /* @__PURE__ */ new Set(["npx", "
|
|
245
|
+
var KNOWN_CMD_SHIM_LAUNCHERS = /* @__PURE__ */ new Set(["npx", "npm", "pnpm", "yarn", "bunx"]);
|
|
192
246
|
var KNOWN_DIRECT_BINARIES = /* @__PURE__ */ new Set([
|
|
193
247
|
"node",
|
|
194
248
|
"deno",
|
|
@@ -196,6 +250,8 @@ var KNOWN_DIRECT_BINARIES = /* @__PURE__ */ new Set([
|
|
|
196
250
|
"python",
|
|
197
251
|
"python3",
|
|
198
252
|
"py",
|
|
253
|
+
"uvx",
|
|
254
|
+
"pipx",
|
|
199
255
|
"ruby",
|
|
200
256
|
"php",
|
|
201
257
|
"docker",
|
|
@@ -229,6 +285,11 @@ function buildLaunchEntry(opts) {
|
|
|
229
285
|
if (opts.upstream) {
|
|
230
286
|
const { command, args, env } = opts.upstream;
|
|
231
287
|
if (opts.os === "windows") {
|
|
288
|
+
if (/[ \t]/.test(command)) {
|
|
289
|
+
throw new Error(
|
|
290
|
+
`Cannot safely encode a launcher command that contains whitespace for the Windows cmd /c launcher: ${command} -- cmd.exe strips the outer quotes when the line carries another quoted token, so the client's spawn fails with "'...' is not recognized". Point the server at a whitespace-free launcher (a bare npx/uvx resolved on PATH, or a short path).`
|
|
291
|
+
);
|
|
292
|
+
}
|
|
232
293
|
const shim = isCmdShimLauncher(command);
|
|
233
294
|
const wrapped = {
|
|
234
295
|
command: "cmd",
|
|
@@ -272,7 +333,7 @@ function resolveClaudeCodeSettingsPath(scope, opts) {
|
|
|
272
333
|
}
|
|
273
334
|
|
|
274
335
|
// src/paths.ts
|
|
275
|
-
import {
|
|
336
|
+
import { realpath, stat } from "fs/promises";
|
|
276
337
|
import { homedir as homedir2 } from "os";
|
|
277
338
|
import path from "path";
|
|
278
339
|
function cacheDir() {
|
|
@@ -329,7 +390,7 @@ async function ownedByCurrentUser(candidate) {
|
|
|
329
390
|
}
|
|
330
391
|
}
|
|
331
392
|
async function findProjectConfigDir(start, home = homedir2()) {
|
|
332
|
-
const homeFallback = home && home.length > 0 ? home :
|
|
393
|
+
const homeFallback = home && home.length > 0 ? home : homedir2();
|
|
333
394
|
const homeResolved = path.resolve(await realpathOrSelf(path.resolve(homeFallback)));
|
|
334
395
|
let dir = path.resolve(await realpathOrSelf(path.resolve(start)));
|
|
335
396
|
const userConfigKey = normalizeForCompare(await realpathOrSelf(path.join(homeResolved, CONFIG_DIRNAME)));
|
|
@@ -339,8 +400,10 @@ async function findProjectConfigDir(start, home = homedir2()) {
|
|
|
339
400
|
if (boundedByHome && !isUnderHome(dir, homeResolved)) return null;
|
|
340
401
|
const candidate = path.join(dir, CONFIG_DIRNAME);
|
|
341
402
|
try {
|
|
342
|
-
await
|
|
343
|
-
if (
|
|
403
|
+
const st = await stat(candidate);
|
|
404
|
+
if (!st.isDirectory()) {
|
|
405
|
+
log("debug", "Skipping a .yaw-mcp that exists but is not a directory", { candidate });
|
|
406
|
+
} else if (normalizeForCompare(await realpathOrSelf(candidate)) === userConfigKey) {
|
|
344
407
|
log("debug", "Skipping a .yaw-mcp/ that resolves to the user-global config dir", { candidate });
|
|
345
408
|
} else if (boundedByHome || await ownedByCurrentUser(candidate)) {
|
|
346
409
|
return candidate;
|
|
@@ -397,7 +460,7 @@ function npxSpec(args) {
|
|
|
397
460
|
const spec = args[idx];
|
|
398
461
|
return spec.startsWith("-") ? null : spec;
|
|
399
462
|
}
|
|
400
|
-
var MIN_OAM_VERSION = "0.
|
|
463
|
+
var MIN_OAM_VERSION = "0.13.1";
|
|
401
464
|
var OAM_INSTALL_SH = "curl -fsSL https://oamjs.org/install.sh | sh";
|
|
402
465
|
var OAM_INSTALL_PS1 = "irm https://oamjs.org/install.ps1 | iex";
|
|
403
466
|
function oamInstallCommand(os) {
|
|
@@ -616,7 +679,7 @@ async function probeOam(run = spawnVersionProbe) {
|
|
|
616
679
|
return oamProbeInFlight;
|
|
617
680
|
}
|
|
618
681
|
async function probeOamUncached(run, generation) {
|
|
619
|
-
|
|
682
|
+
const explicit = Boolean(process.env.OAM_BIN);
|
|
620
683
|
const bin = winNormalize(process.env.OAM_BIN || (process.platform === "win32" ? "oam.exe" : "oam"));
|
|
621
684
|
const publish = (probe) => {
|
|
622
685
|
if (generation === oamProbeGeneration) oamProbeCache = probe;
|
|
@@ -664,6 +727,7 @@ async function probeOamUncached(run, generation) {
|
|
|
664
727
|
});
|
|
665
728
|
} catch (err) {
|
|
666
729
|
const code = err?.code;
|
|
730
|
+
const absent = code === "ENOENT" && !explicit;
|
|
667
731
|
if (code === "ETIMEDOUT") {
|
|
668
732
|
log("warn", "oam did not respond to --version in time; falling back to node for this process", {
|
|
669
733
|
timeoutMs: OAM_PROBE_TIMEOUT_MS,
|
|
@@ -674,24 +738,22 @@ async function probeOamUncached(run, generation) {
|
|
|
674
738
|
bin,
|
|
675
739
|
error: err instanceof Error ? err.message : String(err)
|
|
676
740
|
});
|
|
741
|
+
} else if (explicit) {
|
|
742
|
+
log("warn", "OAM_BIN points at a path that does not exist; falling back to node for this process", {
|
|
743
|
+
bin,
|
|
744
|
+
error: err instanceof Error ? err.message : String(err)
|
|
745
|
+
});
|
|
677
746
|
}
|
|
678
747
|
return publish({
|
|
679
748
|
bin: null,
|
|
680
749
|
binPath: null,
|
|
681
750
|
version: null,
|
|
682
751
|
belowMin: false,
|
|
683
|
-
failure:
|
|
684
|
-
failureDetail:
|
|
752
|
+
failure: absent ? null : classifyProbeFailure(err),
|
|
753
|
+
failureDetail: absent ? null : err instanceof Error ? err.message : String(err)
|
|
685
754
|
});
|
|
686
755
|
}
|
|
687
756
|
}
|
|
688
|
-
function resetOamBinCache() {
|
|
689
|
-
warnedOamUnavailable = false;
|
|
690
|
-
oamProbeCache = void 0;
|
|
691
|
-
oamProbeInFlight = void 0;
|
|
692
|
-
oamProbeGeneration++;
|
|
693
|
-
pinnedReported.clear();
|
|
694
|
-
}
|
|
695
757
|
var WIN_EXE_EXT = /\.(?:exe|cmd|bat)$/i;
|
|
696
758
|
function nodeLaunchKind(command) {
|
|
697
759
|
const base = (command.split(/[\\/]/).pop() ?? command).replace(WIN_EXE_EXT, "").toLowerCase();
|
|
@@ -831,11 +893,9 @@ function npmCacheDir(fromUrl = import.meta.url) {
|
|
|
831
893
|
npmCacheDirCache.set(fromUrl, resolved);
|
|
832
894
|
return resolved;
|
|
833
895
|
}
|
|
834
|
-
function resetNpmCacheDir() {
|
|
835
|
-
npmCacheDirCache.clear();
|
|
836
|
-
}
|
|
837
896
|
function resolveNpmCacheDir(fromUrl) {
|
|
838
|
-
const
|
|
897
|
+
const envKey = Object.keys(process.env).find((k) => /^npm_config_cache$/i.test(k));
|
|
898
|
+
const fromEnv = envKey === void 0 ? void 0 : process.env[envKey];
|
|
839
899
|
if (fromEnv) return fromEnv;
|
|
840
900
|
const candidates = [join2(homedir3(), ".npmrc")];
|
|
841
901
|
for (const nodeModules of ownNodeModules(fromUrl)) {
|
|
@@ -972,9 +1032,6 @@ var REFRESH_NOTE = {
|
|
|
972
1032
|
"npx-cache": "then Ctrl-C -- the cache is refreshed before the server starts"
|
|
973
1033
|
};
|
|
974
1034
|
var pinnedReported = /* @__PURE__ */ new Set();
|
|
975
|
-
function resetPinnedSidecarLog() {
|
|
976
|
-
pinnedReported.clear();
|
|
977
|
-
}
|
|
978
1035
|
function notePinnedSidecar(pkg, version, source, from) {
|
|
979
1036
|
if (pinnedReported.has(pkg)) return;
|
|
980
1037
|
pinnedReported.add(pkg);
|
|
@@ -1062,7 +1119,687 @@ function isOamLaunch(command, args = []) {
|
|
|
1062
1119
|
return false;
|
|
1063
1120
|
}
|
|
1064
1121
|
|
|
1122
|
+
// src/upgrade-cmd.ts
|
|
1123
|
+
var BINARY_RETIRED_HINT = "the standalone-binary track was retired in 0.70.3. Install from npm instead -- `npm install -g @yawlabs/mcp@latest` -- then delete this executable.";
|
|
1124
|
+
var POSIX_GLOBAL_LIB_PREFIX = /^(?:[A-Za-z]:)?(?:\/usr(?:\/local)?|\/opt\/[^/]+)\/lib\/node_modules\/@yawlabs\/mcp\//;
|
|
1125
|
+
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\//;
|
|
1126
|
+
var UPGRADE_USAGE = `Usage: yaw-mcp upgrade [--run] [--json]
|
|
1127
|
+
|
|
1128
|
+
Show (or execute) the command to upgrade @yawlabs/mcp to the latest version.
|
|
1129
|
+
|
|
1130
|
+
--run Run the upgrade in place (global npm, pnpm, bun, and local npm
|
|
1131
|
+
installs). No-op for npx installs -- they always fetch the latest.
|
|
1132
|
+
--json Emit a machine-readable snapshot ({ current, latest, stale,
|
|
1133
|
+
method, command, cwd }) instead of prose. "cwd" is the directory
|
|
1134
|
+
"command" must run IN -- the package-tree root for a
|
|
1135
|
+
local-node-modules install, null for every other method (the
|
|
1136
|
+
command can run anywhere). Running a local install's command from
|
|
1137
|
+
the wrong directory creates a stray package.json + node_modules
|
|
1138
|
+
there instead of upgrading the tree.
|
|
1139
|
+
NOTE: --json is a report-only snapshot; it never spawns an upgrade
|
|
1140
|
+
even when combined with --run, and exits 1 whenever "stale" is
|
|
1141
|
+
true. Use --run without --json to actually perform the upgrade.`;
|
|
1142
|
+
function parseUpgradeArgs(argv) {
|
|
1143
|
+
const opts = {};
|
|
1144
|
+
for (const a of argv) {
|
|
1145
|
+
if (a === "--run") opts.run = true;
|
|
1146
|
+
else if (a === "--json") opts.json = true;
|
|
1147
|
+
else if (a === "--help" || a === "-h") return { ok: false, error: UPGRADE_USAGE, help: true };
|
|
1148
|
+
else return { ok: false, error: `yaw-mcp upgrade: unknown argument "${a}"
|
|
1149
|
+
|
|
1150
|
+
${UPGRADE_USAGE}` };
|
|
1151
|
+
}
|
|
1152
|
+
return { ok: true, options: opts };
|
|
1153
|
+
}
|
|
1154
|
+
function detectInstallMethod(argvPath, realpath2 = realpathSync) {
|
|
1155
|
+
if (!argvPath) return "unknown";
|
|
1156
|
+
const literal = classifyEntrypoint(argvPath);
|
|
1157
|
+
if (literal !== "unknown") return literal;
|
|
1158
|
+
let resolved;
|
|
1159
|
+
try {
|
|
1160
|
+
resolved = realpath2(argvPath);
|
|
1161
|
+
} catch {
|
|
1162
|
+
return literal;
|
|
1163
|
+
}
|
|
1164
|
+
return resolved === argvPath ? literal : classifyEntrypoint(resolved);
|
|
1165
|
+
}
|
|
1166
|
+
function classifyEntrypoint(argvPath) {
|
|
1167
|
+
const normalized = argvPath.replace(/\\/g, "/");
|
|
1168
|
+
if (/\/_npx\/[0-9a-f]+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "npx";
|
|
1169
|
+
if (/\/app\.asar\.unpacked\//.test(normalized)) return "bundled-app";
|
|
1170
|
+
if (/\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
|
|
1171
|
+
if (POSIX_GLOBAL_LIB_PREFIX.test(normalized)) return "global-npm";
|
|
1172
|
+
if (MANAGED_NODE_LIB_PREFIX.test(normalized)) return "global-npm";
|
|
1173
|
+
if (/\/AppData\/Roaming\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
|
|
1174
|
+
if (/\/bin\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
|
|
1175
|
+
if (/\/pnpm\/global\/\d+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "pnpm-global";
|
|
1176
|
+
if (/\/\.bun\/install\/global\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "bun-global";
|
|
1177
|
+
if (/\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "local-node-modules";
|
|
1178
|
+
if (/\/(yaw-mcp|mcph|mcp)\/(dist|src)\//.test(normalized)) return "dev-checkout";
|
|
1179
|
+
return "unknown";
|
|
1180
|
+
}
|
|
1181
|
+
function localInstallRoot(argvPath) {
|
|
1182
|
+
if (!argvPath) return null;
|
|
1183
|
+
const idx = argvPath.replace(/\\/g, "/").indexOf("/node_modules/");
|
|
1184
|
+
return idx > 0 ? argvPath.slice(0, idx) : null;
|
|
1185
|
+
}
|
|
1186
|
+
function killProcessTree(child, platform = process.platform, spawnImpl = spawn2) {
|
|
1187
|
+
if (platform === "win32" && child.pid !== void 0) {
|
|
1188
|
+
try {
|
|
1189
|
+
spawnImpl("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" }).on("error", () => {
|
|
1190
|
+
});
|
|
1191
|
+
} catch {
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
child.kill();
|
|
1195
|
+
}
|
|
1196
|
+
async function npmGlobalPrefix() {
|
|
1197
|
+
if (process.env.VITEST) return null;
|
|
1198
|
+
return new Promise((resolve2) => {
|
|
1199
|
+
const child = spawn2("npm", ["prefix", "-g"], {
|
|
1200
|
+
shell: process.platform === "win32",
|
|
1201
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
1202
|
+
});
|
|
1203
|
+
let out = "";
|
|
1204
|
+
const timer = setTimeout(() => {
|
|
1205
|
+
killProcessTree(child);
|
|
1206
|
+
resolve2(null);
|
|
1207
|
+
}, 3e3);
|
|
1208
|
+
child.stdout?.on("data", (d) => {
|
|
1209
|
+
out += String(d);
|
|
1210
|
+
});
|
|
1211
|
+
child.on("close", (code) => {
|
|
1212
|
+
clearTimeout(timer);
|
|
1213
|
+
resolve2(code === 0 && out.trim() ? out.trim() : null);
|
|
1214
|
+
});
|
|
1215
|
+
child.on("error", () => {
|
|
1216
|
+
clearTimeout(timer);
|
|
1217
|
+
resolve2(null);
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
function comparablePath(p) {
|
|
1222
|
+
let real = p;
|
|
1223
|
+
try {
|
|
1224
|
+
real = realpathSync(p);
|
|
1225
|
+
} catch {
|
|
1226
|
+
}
|
|
1227
|
+
const normalized = real.replace(/\\/g, "/");
|
|
1228
|
+
return process.platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
1229
|
+
}
|
|
1230
|
+
async function refineInstallMethod(method, argvPath, npmPrefix = npmGlobalPrefix) {
|
|
1231
|
+
if (method !== "local-node-modules" && method !== "unknown") return method;
|
|
1232
|
+
if (!argvPath) return method;
|
|
1233
|
+
const prefix = await npmPrefix();
|
|
1234
|
+
if (!prefix) return method;
|
|
1235
|
+
const entry = comparablePath(argvPath);
|
|
1236
|
+
const pfx = comparablePath(prefix);
|
|
1237
|
+
if (entry.startsWith(`${pfx}/node_modules/`) || entry.startsWith(`${pfx}/lib/node_modules/`)) {
|
|
1238
|
+
return "global-npm";
|
|
1239
|
+
}
|
|
1240
|
+
return method;
|
|
1241
|
+
}
|
|
1242
|
+
function buildUpgradePlan(input) {
|
|
1243
|
+
const { current, latest, method } = input;
|
|
1244
|
+
const stripV = (s) => s.startsWith("v") ? s.slice(1) : s;
|
|
1245
|
+
const stale = latest !== null && current !== "dev" && compareVersions(stripV(current), stripV(latest)) < 0;
|
|
1246
|
+
let command;
|
|
1247
|
+
switch (method) {
|
|
1248
|
+
case "global-npm":
|
|
1249
|
+
command = "npm install -g @yawlabs/mcp@latest";
|
|
1250
|
+
break;
|
|
1251
|
+
case "pnpm-global":
|
|
1252
|
+
command = "pnpm add -g @yawlabs/mcp@latest";
|
|
1253
|
+
break;
|
|
1254
|
+
case "bun-global":
|
|
1255
|
+
command = "bun add -g @yawlabs/mcp@latest";
|
|
1256
|
+
break;
|
|
1257
|
+
case "npx":
|
|
1258
|
+
command = null;
|
|
1259
|
+
break;
|
|
1260
|
+
case "bundled-app":
|
|
1261
|
+
command = null;
|
|
1262
|
+
break;
|
|
1263
|
+
case "local-node-modules":
|
|
1264
|
+
command = "npm install @yawlabs/mcp@latest";
|
|
1265
|
+
break;
|
|
1266
|
+
case "dev-checkout":
|
|
1267
|
+
command = "git pull && npm run build";
|
|
1268
|
+
break;
|
|
1269
|
+
case "binary":
|
|
1270
|
+
command = null;
|
|
1271
|
+
break;
|
|
1272
|
+
default:
|
|
1273
|
+
command = "npm install -g @yawlabs/mcp@latest";
|
|
1274
|
+
break;
|
|
1275
|
+
}
|
|
1276
|
+
return { current, latest, stale, method, command };
|
|
1277
|
+
}
|
|
1278
|
+
var REGISTRY_FETCH_TIMEOUT_MS = 3e3;
|
|
1279
|
+
async function fetchLatestVersion(opts = {}) {
|
|
1280
|
+
if (opts.override) {
|
|
1281
|
+
try {
|
|
1282
|
+
return await opts.override();
|
|
1283
|
+
} catch {
|
|
1284
|
+
return null;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
const ac = new AbortController();
|
|
1288
|
+
const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? REGISTRY_FETCH_TIMEOUT_MS);
|
|
1289
|
+
try {
|
|
1290
|
+
const res = await fetch("https://registry.npmjs.org/@yawlabs/mcp/latest", {
|
|
1291
|
+
signal: ac.signal,
|
|
1292
|
+
headers: { accept: "application/json" }
|
|
1293
|
+
});
|
|
1294
|
+
if (!res.ok) return null;
|
|
1295
|
+
const body = await res.json();
|
|
1296
|
+
return typeof body.version === "string" ? body.version : null;
|
|
1297
|
+
} catch {
|
|
1298
|
+
return null;
|
|
1299
|
+
} finally {
|
|
1300
|
+
clearTimeout(timer);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
async function probeOamQuietly() {
|
|
1304
|
+
const prev = process.env.LOG_LEVEL;
|
|
1305
|
+
process.env.LOG_LEVEL = "error";
|
|
1306
|
+
try {
|
|
1307
|
+
return await probeOam();
|
|
1308
|
+
} finally {
|
|
1309
|
+
if (prev === void 0) delete process.env.LOG_LEVEL;
|
|
1310
|
+
else process.env.LOG_LEVEL = prev;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
async function oamFloorLines(probe) {
|
|
1314
|
+
if (!probe && process.env.VITEST) return [];
|
|
1315
|
+
try {
|
|
1316
|
+
const oam = probe ? await probe() : await probeOamQuietly();
|
|
1317
|
+
if (!oam.belowMin) return [];
|
|
1318
|
+
return [
|
|
1319
|
+
"",
|
|
1320
|
+
`oam: v${oam.version ?? "unknown"} is installed but below the v${MIN_OAM_VERSION} floor yaw-mcp`,
|
|
1321
|
+
" requires, so MCP sidecars run on node instead of oam. Update it:",
|
|
1322
|
+
"",
|
|
1323
|
+
" oam self-update"
|
|
1324
|
+
];
|
|
1325
|
+
} catch {
|
|
1326
|
+
return [];
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
async function defaultRunningPrefix(argvPath) {
|
|
1330
|
+
if (process.env.VITEST) return null;
|
|
1331
|
+
const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-W6LVJ7XD.js");
|
|
1332
|
+
return detectRunningInstallPrefix2(argvPath);
|
|
1333
|
+
}
|
|
1334
|
+
async function defaultSpawn(cmd, args, cwd) {
|
|
1335
|
+
return new Promise((resolve2) => {
|
|
1336
|
+
const child = spawn2(cmd, args, { stdio: "inherit", shell: process.platform === "win32", cwd });
|
|
1337
|
+
child.on("close", (code) => resolve2(typeof code === "number" ? code : 1));
|
|
1338
|
+
child.on("error", () => resolve2(1));
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
async function detectSea() {
|
|
1342
|
+
if (process.env.ELECTRON_RUN_AS_NODE) return false;
|
|
1343
|
+
const exe = process.execPath.replace(/\\/g, "/").split("/").pop()?.toLowerCase() ?? "";
|
|
1344
|
+
if (exe === "node" || exe === "node.exe") return false;
|
|
1345
|
+
try {
|
|
1346
|
+
const sea = await import("sea");
|
|
1347
|
+
return typeof sea.isSea === "function" && sea.isSea() === true;
|
|
1348
|
+
} catch {
|
|
1349
|
+
return false;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
async function runUpgrade(opts = {}) {
|
|
1353
|
+
const write = opts.out ?? ((s) => process.stdout.write(s));
|
|
1354
|
+
const writeErr = opts.err ?? ((s) => process.stderr.write(s));
|
|
1355
|
+
const lines = [];
|
|
1356
|
+
const print = (s = "") => {
|
|
1357
|
+
lines.push(s);
|
|
1358
|
+
write(`${s}
|
|
1359
|
+
`);
|
|
1360
|
+
};
|
|
1361
|
+
const printErr = (s) => {
|
|
1362
|
+
lines.push(s);
|
|
1363
|
+
writeErr(`${s}
|
|
1364
|
+
`);
|
|
1365
|
+
};
|
|
1366
|
+
const fetcher = opts.fetchLatest ?? fetchLatestVersion;
|
|
1367
|
+
const current = opts.currentVersion ?? readCurrentVersion();
|
|
1368
|
+
const argvPath = opts.argvPath ?? process.argv[1];
|
|
1369
|
+
const sea = opts.isSea ? opts.isSea() : await detectSea();
|
|
1370
|
+
const method = sea ? "binary" : await refineInstallMethod(detectInstallMethod(argvPath), argvPath, opts.npmPrefix);
|
|
1371
|
+
let latest;
|
|
1372
|
+
try {
|
|
1373
|
+
latest = await fetcher();
|
|
1374
|
+
} catch {
|
|
1375
|
+
latest = null;
|
|
1376
|
+
}
|
|
1377
|
+
const plan = buildUpgradePlan({ current, latest, method });
|
|
1378
|
+
let globalPrefixArg = null;
|
|
1379
|
+
let suggestedCommand = plan.command;
|
|
1380
|
+
if (method === "global-npm") {
|
|
1381
|
+
const rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
|
|
1382
|
+
if (rawPrefix !== null) {
|
|
1383
|
+
const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-W6LVJ7XD.js");
|
|
1384
|
+
const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
|
|
1385
|
+
const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
|
|
1386
|
+
if (spawnForm !== null && displayForm !== null) {
|
|
1387
|
+
globalPrefixArg = spawnForm;
|
|
1388
|
+
suggestedCommand = `npm install -g --prefix ${displayForm} @yawlabs/mcp@latest`;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
const installRoot = method === "local-node-modules" ? localInstallRoot(argvPath) : null;
|
|
1393
|
+
if (opts.json) {
|
|
1394
|
+
print(JSON.stringify({ ...plan, command: suggestedCommand, cwd: installRoot }, null, 2));
|
|
1395
|
+
return { exitCode: plan.stale ? 1 : 0, lines };
|
|
1396
|
+
}
|
|
1397
|
+
if (latest === null) {
|
|
1398
|
+
print("yaw-mcp upgrade: couldn't reach the npm registry (offline? firewall?).");
|
|
1399
|
+
if (suggestedCommand) {
|
|
1400
|
+
print("When you're back online, run:");
|
|
1401
|
+
print("");
|
|
1402
|
+
if (installRoot) {
|
|
1403
|
+
print(`in ${installRoot}:`);
|
|
1404
|
+
}
|
|
1405
|
+
print(` ${suggestedCommand}`);
|
|
1406
|
+
} else if (method === "bundled-app") {
|
|
1407
|
+
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app \u2014 nothing to run.");
|
|
1408
|
+
} else if (method === "binary") {
|
|
1409
|
+
print(`yaw-mcp is a standalone binary; ${BINARY_RETIRED_HINT}`);
|
|
1410
|
+
} else {
|
|
1411
|
+
print("Your install uses `npx -y` \u2014 just restart the MCP client when you're back online.");
|
|
1412
|
+
}
|
|
1413
|
+
for (const line of await oamFloorLines(opts.oamProbe)) print(line);
|
|
1414
|
+
return { exitCode: 0, lines };
|
|
1415
|
+
}
|
|
1416
|
+
print(`Current: ${current}`);
|
|
1417
|
+
print(`Latest: ${latest}`);
|
|
1418
|
+
print(`Install: ${method}`);
|
|
1419
|
+
for (const line of await oamFloorLines(opts.oamProbe)) print(line);
|
|
1420
|
+
if (!plan.stale) {
|
|
1421
|
+
print("");
|
|
1422
|
+
print("OK: You're on the latest version -- nothing to do.");
|
|
1423
|
+
return { exitCode: 0, lines };
|
|
1424
|
+
}
|
|
1425
|
+
print("");
|
|
1426
|
+
if (method === "npx") {
|
|
1427
|
+
print("Your install uses `npx -y` \u2014 restart the MCP client and it will fetch the new version.");
|
|
1428
|
+
return { exitCode: 0, lines };
|
|
1429
|
+
}
|
|
1430
|
+
if (method === "bundled-app") {
|
|
1431
|
+
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app \u2014");
|
|
1432
|
+
print("there is nothing to run here. Update Yaw Terminal to get the new version.");
|
|
1433
|
+
return { exitCode: 0, lines };
|
|
1434
|
+
}
|
|
1435
|
+
if (method === "binary") {
|
|
1436
|
+
const emit = opts.run ? printErr : print;
|
|
1437
|
+
emit("yaw-mcp is running as a standalone binary \u2014 manual upgrade required.");
|
|
1438
|
+
emit(`There's no package manager to upgrade it, and \`--run\` can't automate this: ${BINARY_RETIRED_HINT}`);
|
|
1439
|
+
return { exitCode: opts.run ? 2 : 1, lines };
|
|
1440
|
+
}
|
|
1441
|
+
const runSpec = method === "global-npm" ? {
|
|
1442
|
+
cmd: "npm",
|
|
1443
|
+
args: globalPrefixArg ? ["install", "-g", "--prefix", globalPrefixArg, "@yawlabs/mcp@latest"] : ["install", "-g", "@yawlabs/mcp@latest"]
|
|
1444
|
+
} : method === "pnpm-global" ? { cmd: "pnpm", args: ["add", "-g", "@yawlabs/mcp@latest"] } : method === "bun-global" ? { cmd: "bun", args: ["add", "-g", "@yawlabs/mcp@latest"] } : (
|
|
1445
|
+
// The `installRoot !== null` arm is defensive-dead, kept only so a
|
|
1446
|
+
// future localInstallRoot change cannot produce `cwd: undefined`
|
|
1447
|
+
// and silently install into the process cwd: localInstallRoot
|
|
1448
|
+
// returns null exactly when `/node_modules/` sits at index 0, i.e.
|
|
1449
|
+
// a node_modules directory at the filesystem root, which no real
|
|
1450
|
+
// classification produces (detectInstallMethod only labels a path
|
|
1451
|
+
// local-node-modules when there is a tree above it).
|
|
1452
|
+
method === "local-node-modules" && installRoot !== null ? { cmd: "npm", args: ["install", "@yawlabs/mcp@latest"], cwd: installRoot } : null
|
|
1453
|
+
);
|
|
1454
|
+
const commandLine = method === "global-npm" ? suggestedCommand : runSpec ? [runSpec.cmd, ...runSpec.args].join(" ") : plan.command;
|
|
1455
|
+
if (!opts.run) {
|
|
1456
|
+
if (runSpec) {
|
|
1457
|
+
print("Run `yaw-mcp upgrade --run` to upgrade in place, or run it yourself:");
|
|
1458
|
+
} else {
|
|
1459
|
+
print("Manual upgrade required (--run can't safely automate this install method). Run it yourself:");
|
|
1460
|
+
}
|
|
1461
|
+
print("");
|
|
1462
|
+
if (installRoot) {
|
|
1463
|
+
print(`in ${installRoot}:`);
|
|
1464
|
+
}
|
|
1465
|
+
print(` ${commandLine}`);
|
|
1466
|
+
return { exitCode: 1, lines };
|
|
1467
|
+
}
|
|
1468
|
+
if (!runSpec) {
|
|
1469
|
+
printErr(
|
|
1470
|
+
`yaw-mcp upgrade --run: a "${method}" install can't be upgraded automatically (manual upgrade required). Run it yourself:`
|
|
1471
|
+
);
|
|
1472
|
+
printErr("");
|
|
1473
|
+
printErr(` ${commandLine}`);
|
|
1474
|
+
return { exitCode: 2, lines };
|
|
1475
|
+
}
|
|
1476
|
+
const runner = opts.spawnImpl ?? defaultSpawn;
|
|
1477
|
+
if (runSpec.cwd) {
|
|
1478
|
+
print(`Running in ${runSpec.cwd}:`);
|
|
1479
|
+
} else {
|
|
1480
|
+
print("Running:");
|
|
1481
|
+
}
|
|
1482
|
+
print(` ${commandLine}`);
|
|
1483
|
+
print("");
|
|
1484
|
+
const code = await runner(runSpec.cmd, runSpec.args, runSpec.cwd);
|
|
1485
|
+
if (code === 0) {
|
|
1486
|
+
print("");
|
|
1487
|
+
print(`OK: Upgraded @yawlabs/mcp to ${latest}`);
|
|
1488
|
+
return { exitCode: 0, lines };
|
|
1489
|
+
}
|
|
1490
|
+
printErr(`yaw-mcp upgrade: ${runSpec.cmd} exited ${code}. Try running the command yourself:`);
|
|
1491
|
+
printErr("");
|
|
1492
|
+
if (installRoot) {
|
|
1493
|
+
printErr(`in ${installRoot}:`);
|
|
1494
|
+
}
|
|
1495
|
+
printErr(` ${commandLine}`);
|
|
1496
|
+
return { exitCode: 3, lines };
|
|
1497
|
+
}
|
|
1498
|
+
function readCurrentVersion() {
|
|
1499
|
+
return true ? "0.79.2" : "dev";
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
// src/auto-upgrade.ts
|
|
1503
|
+
function quoteShellArgIfNeeded(arg, platform = process.platform) {
|
|
1504
|
+
if (platform !== "win32") return arg;
|
|
1505
|
+
if (/[\r\n\0"%]/.test(arg)) return null;
|
|
1506
|
+
if (!/[\s&|<>^]/.test(arg)) return arg;
|
|
1507
|
+
return `"${arg}"`;
|
|
1508
|
+
}
|
|
1509
|
+
function quoteArgForDisplay(arg, platform = process.platform) {
|
|
1510
|
+
if (platform === "win32") return quoteShellArgIfNeeded(arg, platform);
|
|
1511
|
+
if (/^[A-Za-z0-9_\-./+,:@=]+$/.test(arg)) return arg;
|
|
1512
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
1513
|
+
}
|
|
1514
|
+
function detectRunningInstallPrefix(argvPath) {
|
|
1515
|
+
if (!argvPath) return null;
|
|
1516
|
+
let resolved;
|
|
1517
|
+
try {
|
|
1518
|
+
resolved = realpathSync2(argvPath);
|
|
1519
|
+
} catch {
|
|
1520
|
+
return null;
|
|
1521
|
+
}
|
|
1522
|
+
const dir = dirname2(resolved);
|
|
1523
|
+
const idx = dir.lastIndexOf(`${sep2}node_modules${sep2}`);
|
|
1524
|
+
if (idx === -1) return null;
|
|
1525
|
+
const candidate = dir.slice(0, idx);
|
|
1526
|
+
if (candidate.endsWith(`${sep2}lib`)) return candidate.slice(0, -`${sep2}lib`.length);
|
|
1527
|
+
return candidate;
|
|
1528
|
+
}
|
|
1529
|
+
async function compareWithNpmPrefix(detected, probe = npmGlobalPrefix) {
|
|
1530
|
+
const npmPrefix = await probe();
|
|
1531
|
+
if (!npmPrefix?.trim()) return;
|
|
1532
|
+
if (comparablePath(npmPrefix.trim()) === comparablePath(detected)) return;
|
|
1533
|
+
process.stderr.write(
|
|
1534
|
+
`yaw-mcp self-upgrade: detected running prefix differs from \`npm prefix -g\`:
|
|
1535
|
+
running: ${detected}
|
|
1536
|
+
npm -g: ${npmPrefix}
|
|
1537
|
+
Installing into the running prefix so the upgrade lands in the same tree the client spawned from.
|
|
1538
|
+
`
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
var UPGRADE_LOCK_NAME = ".yaw-mcp-upgrade.lock";
|
|
1542
|
+
var UPGRADE_LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1543
|
+
var UPGRADE_LOCK_FUTURE_SKEW_MS = 5 * 1e3;
|
|
1544
|
+
function acquireUpgradeLock(dir, lockName = UPGRADE_LOCK_NAME) {
|
|
1545
|
+
const lockPath = join3(dir, lockName);
|
|
1546
|
+
const mine = String(process.pid);
|
|
1547
|
+
const take = () => {
|
|
1548
|
+
try {
|
|
1549
|
+
const fd = openSync(lockPath, "wx");
|
|
1550
|
+
try {
|
|
1551
|
+
writeSync(fd, `${mine}
|
|
1552
|
+
`);
|
|
1553
|
+
} finally {
|
|
1554
|
+
closeSync(fd);
|
|
1555
|
+
}
|
|
1556
|
+
let released = false;
|
|
1557
|
+
return () => {
|
|
1558
|
+
if (released) return;
|
|
1559
|
+
released = true;
|
|
1560
|
+
try {
|
|
1561
|
+
if (readFileSync2(lockPath, "utf8").trim() !== mine) return;
|
|
1562
|
+
unlinkSync(lockPath);
|
|
1563
|
+
} catch {
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
} catch (err) {
|
|
1567
|
+
if (err.code === "EEXIST") return void 0;
|
|
1568
|
+
return () => {
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
const first = take();
|
|
1573
|
+
if (first !== void 0) return first;
|
|
1574
|
+
let ageMs;
|
|
1575
|
+
try {
|
|
1576
|
+
ageMs = Date.now() - statSync2(lockPath).mtimeMs;
|
|
1577
|
+
} catch {
|
|
1578
|
+
ageMs = UPGRADE_LOCK_STALE_MS;
|
|
1579
|
+
}
|
|
1580
|
+
if (ageMs > -UPGRADE_LOCK_FUTURE_SKEW_MS && ageMs < UPGRADE_LOCK_STALE_MS) return null;
|
|
1581
|
+
try {
|
|
1582
|
+
unlinkSync(lockPath);
|
|
1583
|
+
} catch (err) {
|
|
1584
|
+
if (err.code !== "ENOENT") return null;
|
|
1585
|
+
}
|
|
1586
|
+
const second = take();
|
|
1587
|
+
return second === void 0 ? null : second;
|
|
1588
|
+
}
|
|
1589
|
+
function defaultAcquireLock(dir, lockName) {
|
|
1590
|
+
if (process.env.VITEST) return () => {
|
|
1591
|
+
};
|
|
1592
|
+
return acquireUpgradeLock(dir, lockName);
|
|
1593
|
+
}
|
|
1594
|
+
var UPGRADE_CHECK_INTERVAL_MS = 60 * 60 * 1e3;
|
|
1595
|
+
var UPGRADE_ATTEMPT_COOLDOWN_MS = 6 * 60 * 60 * 1e3;
|
|
1596
|
+
function memoAgeMs(path2, version) {
|
|
1597
|
+
let parsed;
|
|
1598
|
+
try {
|
|
1599
|
+
parsed = JSON.parse(readFileSync2(path2, "utf8"));
|
|
1600
|
+
} catch {
|
|
1601
|
+
return null;
|
|
1602
|
+
}
|
|
1603
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
1604
|
+
const memo = parsed;
|
|
1605
|
+
if (typeof memo.at !== "number") return null;
|
|
1606
|
+
if (version !== null && memo.version !== version) return null;
|
|
1607
|
+
const age = Date.now() - memo.at;
|
|
1608
|
+
return age < -UPGRADE_LOCK_FUTURE_SKEW_MS ? null : age;
|
|
1609
|
+
}
|
|
1610
|
+
function writeMemo(path2, version) {
|
|
1611
|
+
const memo = version === null ? { at: Date.now() } : { at: Date.now(), version };
|
|
1612
|
+
try {
|
|
1613
|
+
writeFileSync(path2, `${JSON.stringify(memo)}
|
|
1614
|
+
`);
|
|
1615
|
+
} catch {
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
function checkMemoPath() {
|
|
1619
|
+
return join3(tmpdir(), `.yaw-mcp-upgrade-check-${process.getuid?.() ?? "win"}.json`);
|
|
1620
|
+
}
|
|
1621
|
+
function attemptMemoPath(dir, lockName) {
|
|
1622
|
+
return join3(dir, `${lockName}.attempt`);
|
|
1623
|
+
}
|
|
1624
|
+
function defaultCheckedRecently() {
|
|
1625
|
+
if (process.env.VITEST) return false;
|
|
1626
|
+
const age = memoAgeMs(checkMemoPath(), null);
|
|
1627
|
+
return age !== null && age < UPGRADE_CHECK_INTERVAL_MS;
|
|
1628
|
+
}
|
|
1629
|
+
function defaultRecordCheck() {
|
|
1630
|
+
if (process.env.VITEST) return;
|
|
1631
|
+
writeMemo(checkMemoPath(), null);
|
|
1632
|
+
}
|
|
1633
|
+
function defaultAttemptedRecently(dir, lockName, version) {
|
|
1634
|
+
if (process.env.VITEST) return false;
|
|
1635
|
+
const age = memoAgeMs(attemptMemoPath(dir, lockName), version);
|
|
1636
|
+
return age !== null && age < UPGRADE_ATTEMPT_COOLDOWN_MS;
|
|
1637
|
+
}
|
|
1638
|
+
function defaultRecordAttempt(dir, lockName, version) {
|
|
1639
|
+
if (process.env.VITEST) return;
|
|
1640
|
+
writeMemo(attemptMemoPath(dir, lockName), version);
|
|
1641
|
+
}
|
|
1642
|
+
function defaultSpawn2(cmd, args, onDone = () => {
|
|
1643
|
+
}) {
|
|
1644
|
+
let errorFired = false;
|
|
1645
|
+
let released = false;
|
|
1646
|
+
const finish = () => {
|
|
1647
|
+
if (released) return;
|
|
1648
|
+
released = true;
|
|
1649
|
+
onDone();
|
|
1650
|
+
};
|
|
1651
|
+
const correctiveCmd = cmd === "npm" ? "npm install -g @yawlabs/mcp@latest" : cmd === "pnpm" ? "pnpm add -g @yawlabs/mcp@latest" : "bun add -g @yawlabs/mcp@latest";
|
|
1652
|
+
const child = spawn3(cmd, args, {
|
|
1653
|
+
stdio: "ignore",
|
|
1654
|
+
// Not detached, so the install shares yaw-mcp's process group and an MCP
|
|
1655
|
+
// client that tears down the whole tree takes it with it. Two things this
|
|
1656
|
+
// does NOT buy (the file header lists both as known gaps): on POSIX a
|
|
1657
|
+
// plain parent exit does not kill it, and if it IS killed mid-install the
|
|
1658
|
+
// result is not guaranteed intact -- npm reify removes the existing
|
|
1659
|
+
// package dir before moving the new one in, and nothing here repairs a
|
|
1660
|
+
// partial install on the next startup.
|
|
1661
|
+
detached: false,
|
|
1662
|
+
shell: process.platform === "win32"
|
|
1663
|
+
});
|
|
1664
|
+
child.on("close", (code) => {
|
|
1665
|
+
finish();
|
|
1666
|
+
if (errorFired) return;
|
|
1667
|
+
if (code === 0) {
|
|
1668
|
+
log("info", "yaw-mcp self-upgrade complete; the next client restart will run the new version");
|
|
1669
|
+
} else {
|
|
1670
|
+
const hint = cmd === "npm" ? " (often EACCES on a sudo-installed global -- run with the right permissions)" : "";
|
|
1671
|
+
log(
|
|
1672
|
+
"warn",
|
|
1673
|
+
`yaw-mcp self-upgrade: ${cmd} exited non-zero${hint}. Run \`${correctiveCmd}\` manually, or set YAW_MCP_AUTO_UPGRADE=0 to silence this.`,
|
|
1674
|
+
{ code }
|
|
1675
|
+
);
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1678
|
+
child.on("error", (err) => {
|
|
1679
|
+
errorFired = true;
|
|
1680
|
+
finish();
|
|
1681
|
+
log("warn", `yaw-mcp self-upgrade: ${cmd} spawn failed`, { error: err?.message });
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
function classifyInstallMethod(argvPath) {
|
|
1685
|
+
const literal = detectInstallMethod(argvPath);
|
|
1686
|
+
if (argvPath === void 0 || literal !== "unknown" && literal !== "local-node-modules") return literal;
|
|
1687
|
+
let resolved;
|
|
1688
|
+
try {
|
|
1689
|
+
resolved = realpathSync2(argvPath);
|
|
1690
|
+
} catch {
|
|
1691
|
+
return literal;
|
|
1692
|
+
}
|
|
1693
|
+
return resolved === argvPath ? literal : detectInstallMethod(resolved);
|
|
1694
|
+
}
|
|
1695
|
+
async function maybeAutoUpgrade(deps = {}) {
|
|
1696
|
+
const optOut = process.env.YAW_MCP_AUTO_UPGRADE;
|
|
1697
|
+
if (optOut === "0" || optOut?.toLowerCase() === "false") return;
|
|
1698
|
+
const current = deps.currentVersion ?? (true ? "0.79.2" : "dev");
|
|
1699
|
+
if (current === "dev") return;
|
|
1700
|
+
const argvPath = deps.argvPath ?? process.argv[1];
|
|
1701
|
+
const method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : classifyInstallMethod(argvPath);
|
|
1702
|
+
if ((deps.checkedRecentlyImpl ?? defaultCheckedRecently)()) return;
|
|
1703
|
+
const latest = await (deps.fetchLatestImpl ?? fetchLatestVersion)();
|
|
1704
|
+
(deps.recordCheckImpl ?? defaultRecordCheck)();
|
|
1705
|
+
if (latest === null) return;
|
|
1706
|
+
const plan = buildUpgradePlan({ current, latest, method });
|
|
1707
|
+
if (!plan.stale) return;
|
|
1708
|
+
const rawPrefix = method === "global-npm" ? detectRunningInstallPrefix(argvPath) : null;
|
|
1709
|
+
const quotedPrefix = rawPrefix === null ? null : quoteShellArgIfNeeded(rawPrefix);
|
|
1710
|
+
const globalSpec = method === "global-npm" ? {
|
|
1711
|
+
cmd: "npm",
|
|
1712
|
+
args: quotedPrefix ? ["install", "-g", "--prefix", quotedPrefix, "@yawlabs/mcp@latest"] : ["install", "-g", "@yawlabs/mcp@latest"]
|
|
1713
|
+
} : method === "pnpm-global" ? { cmd: "pnpm", args: ["add", "-g", "@yawlabs/mcp@latest"] } : method === "bun-global" ? { cmd: "bun", args: ["add", "-g", "@yawlabs/mcp@latest"] } : null;
|
|
1714
|
+
if (globalSpec) {
|
|
1715
|
+
const lockDir = rawPrefix ?? tmpdir();
|
|
1716
|
+
const lockName = rawPrefix === null ? `.yaw-mcp-upgrade-${globalSpec.cmd}-${process.getuid?.() ?? "win"}.lock` : UPGRADE_LOCK_NAME;
|
|
1717
|
+
if ((deps.attemptedRecentlyImpl ?? defaultAttemptedRecently)(lockDir, lockName, latest)) {
|
|
1718
|
+
log("info", "yaw-mcp self-upgrade: this upgrade was already attempted recently; not retrying yet", {
|
|
1719
|
+
current,
|
|
1720
|
+
latest,
|
|
1721
|
+
tool: globalSpec.cmd,
|
|
1722
|
+
lockDir
|
|
1723
|
+
});
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
const releaseLock = (deps.acquireLockImpl ?? defaultAcquireLock)(lockDir, lockName);
|
|
1727
|
+
if (releaseLock === null) {
|
|
1728
|
+
log("info", "yaw-mcp self-upgrade: another process is already upgrading this install; skipping this one", {
|
|
1729
|
+
current,
|
|
1730
|
+
latest,
|
|
1731
|
+
tool: globalSpec.cmd,
|
|
1732
|
+
lockDir
|
|
1733
|
+
});
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1736
|
+
log("info", "yaw-mcp is out of date; upgrading the global install in the background", {
|
|
1737
|
+
current,
|
|
1738
|
+
latest,
|
|
1739
|
+
tool: globalSpec.cmd,
|
|
1740
|
+
// The RAW prefix, not the shell-quoted argv form -- a log field is read
|
|
1741
|
+
// by a human, and stray quotes read as part of the path. Omitted when
|
|
1742
|
+
// quoting failed, because then no `--prefix` was passed at all and npm
|
|
1743
|
+
// resolves its own prefix.
|
|
1744
|
+
prefix: quotedPrefix === null ? void 0 : rawPrefix ?? void 0
|
|
1745
|
+
});
|
|
1746
|
+
if (method === "global-npm" && rawPrefix !== null && quotedPrefix !== null) {
|
|
1747
|
+
void compareWithNpmPrefix(rawPrefix, deps.npmPrefixImpl);
|
|
1748
|
+
}
|
|
1749
|
+
(deps.recordAttemptImpl ?? defaultRecordAttempt)(lockDir, lockName, latest);
|
|
1750
|
+
try {
|
|
1751
|
+
(deps.spawnImpl ?? defaultSpawn2)(globalSpec.cmd, globalSpec.args, releaseLock);
|
|
1752
|
+
} catch (err) {
|
|
1753
|
+
releaseLock();
|
|
1754
|
+
log("warn", `yaw-mcp self-upgrade: could not start ${globalSpec.cmd}`, {
|
|
1755
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
return;
|
|
1759
|
+
}
|
|
1760
|
+
if (method === "bundled-app") {
|
|
1761
|
+
log("info", "yaw-mcp (bundled with Yaw Terminal) is behind npm; it updates with the app", { current, latest });
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
if (method === "binary") {
|
|
1765
|
+
log(
|
|
1766
|
+
"info",
|
|
1767
|
+
"yaw-mcp (standalone binary) is behind npm; the binary track was retired -- npm install -g @yawlabs/mcp@latest, then delete the old executable",
|
|
1768
|
+
{ current, latest }
|
|
1769
|
+
);
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
if (method === "npx") {
|
|
1773
|
+
log("info", "yaw-mcp is out of date; restart your MCP client to pick up the latest version", {
|
|
1774
|
+
current,
|
|
1775
|
+
latest,
|
|
1776
|
+
method
|
|
1777
|
+
});
|
|
1778
|
+
} else if (method === "local-node-modules") {
|
|
1779
|
+
log(
|
|
1780
|
+
"info",
|
|
1781
|
+
"yaw-mcp is out of date; run `yaw-mcp upgrade --run` to update this install (a restart re-runs the version pinned in your project's node_modules)",
|
|
1782
|
+
{
|
|
1783
|
+
current,
|
|
1784
|
+
latest,
|
|
1785
|
+
method
|
|
1786
|
+
}
|
|
1787
|
+
);
|
|
1788
|
+
} else {
|
|
1789
|
+
log(
|
|
1790
|
+
"info",
|
|
1791
|
+
"yaw-mcp is out of date; run `yaw-mcp upgrade` for the command that updates this install (`--run` can't automate this install method)",
|
|
1792
|
+
{
|
|
1793
|
+
current,
|
|
1794
|
+
latest,
|
|
1795
|
+
method
|
|
1796
|
+
}
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1065
1801
|
export {
|
|
1802
|
+
log,
|
|
1066
1803
|
cacheDir,
|
|
1067
1804
|
CONFIG_DIRNAME,
|
|
1068
1805
|
sidecarsRoot,
|
|
@@ -1070,10 +1807,12 @@ export {
|
|
|
1070
1807
|
userConfigDir,
|
|
1071
1808
|
realpathOrSelf,
|
|
1072
1809
|
isUnderHome,
|
|
1810
|
+
ALLOW_UNOWNED_ENV,
|
|
1073
1811
|
findProjectConfigDir,
|
|
1074
1812
|
guidePath,
|
|
1075
1813
|
CURRENT_OS,
|
|
1076
1814
|
INSTALL_TARGETS,
|
|
1815
|
+
resolveAppDataDir,
|
|
1077
1816
|
resolveInstallPath,
|
|
1078
1817
|
buildLaunchEntry,
|
|
1079
1818
|
isProjectLocalEntry,
|
|
@@ -1088,36 +1827,30 @@ export {
|
|
|
1088
1827
|
npxSpecIndex,
|
|
1089
1828
|
npxSpec,
|
|
1090
1829
|
MIN_OAM_VERSION,
|
|
1091
|
-
OAM_INSTALL_SH,
|
|
1092
|
-
OAM_INSTALL_PS1,
|
|
1093
1830
|
oamInstallCommand,
|
|
1094
|
-
oamPublishesBinaryFor,
|
|
1095
1831
|
oamPublishesBinaryForThisMachine,
|
|
1096
1832
|
oamNoBinaryReason,
|
|
1097
1833
|
oamInstallAdvice,
|
|
1098
1834
|
oamHeapOomHint,
|
|
1099
1835
|
oamFailureLabel,
|
|
1100
|
-
parseOamVersion,
|
|
1101
1836
|
compareVersions,
|
|
1102
|
-
winNormalize,
|
|
1103
|
-
resolveBinAbsolute,
|
|
1104
|
-
OAM_PROBE_TIMEOUT_MS,
|
|
1105
|
-
OAM_PROBE_KILL_SIGNAL,
|
|
1106
|
-
OAM_PROBE_MAX_OUTPUT,
|
|
1107
|
-
createProbeCollector,
|
|
1108
1837
|
probeOam,
|
|
1109
|
-
resetOamBinCache,
|
|
1110
1838
|
nodeLaunchKind,
|
|
1111
|
-
rewriteForOam,
|
|
1112
|
-
npxCacheNodeModules,
|
|
1113
|
-
npmCacheDir,
|
|
1114
|
-
resetNpmCacheDir,
|
|
1115
|
-
npmCacheNpxNodeModules,
|
|
1116
|
-
ownNodeModules,
|
|
1117
|
-
resolveNpmEntry,
|
|
1118
|
-
resetPinnedSidecarLog,
|
|
1119
1839
|
resolveStableNpmEntry,
|
|
1120
1840
|
resolveOamSpawn,
|
|
1121
1841
|
isOamCommand,
|
|
1122
|
-
isOamLaunch
|
|
1842
|
+
isOamLaunch,
|
|
1843
|
+
BINARY_RETIRED_HINT,
|
|
1844
|
+
parseUpgradeArgs,
|
|
1845
|
+
detectInstallMethod,
|
|
1846
|
+
refineInstallMethod,
|
|
1847
|
+
buildUpgradePlan,
|
|
1848
|
+
fetchLatestVersion,
|
|
1849
|
+
detectSea,
|
|
1850
|
+
runUpgrade,
|
|
1851
|
+
quoteShellArgIfNeeded,
|
|
1852
|
+
quoteArgForDisplay,
|
|
1853
|
+
detectRunningInstallPrefix,
|
|
1854
|
+
acquireUpgradeLock,
|
|
1855
|
+
maybeAutoUpgrade
|
|
1123
1856
|
};
|