@yawlabs/mcp 0.75.4 → 0.76.1
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/CHANGELOG.md +32 -0
- package/dist/auto-upgrade-CIO76Z6V.js +14 -0
- package/dist/chunk-C3AQHLOR.js +15 -0
- package/dist/{chunk-VHPGG3GN.js → chunk-CNEMSMQD.js} +387 -53
- package/dist/chunk-U3KC5QAD.js +552 -0
- package/dist/index.js +802 -992
- package/dist/{oam-spawn-Z5CASEBY.js → oam-spawn-VPVBHI7B.js} +12 -1
- package/package.json +2 -2
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
log
|
|
4
|
+
} from "./chunk-C3AQHLOR.js";
|
|
5
|
+
|
|
6
|
+
// src/auto-upgrade.ts
|
|
7
|
+
import { spawn as spawn2 } from "child_process";
|
|
8
|
+
import { realpathSync as realpathSync2 } from "fs";
|
|
9
|
+
import { dirname, sep } from "path";
|
|
10
|
+
|
|
11
|
+
// src/upgrade-cmd.ts
|
|
12
|
+
import { spawn } from "child_process";
|
|
13
|
+
import { realpathSync } from "fs";
|
|
14
|
+
var BINARY_DOWNLOAD_URL = "https://github.com/YawLabs/mcp/releases/latest";
|
|
15
|
+
var POSIX_GLOBAL_LIB_PREFIX = /^(?:[A-Za-z]:)?(?:\/usr(?:\/local)?|\/opt\/[^/]+)\/lib\/node_modules\/@yawlabs\/mcp\//;
|
|
16
|
+
var MANAGED_NODE_LIB_PREFIX = /\/(?:\.local|\.nvm|\.fnm|fnm|\.asdf|\.volta|\.nodenv|\.nvs|n)\/(?:[^/]+\/)*lib\/node_modules\/@yawlabs\/mcp\//;
|
|
17
|
+
var UPGRADE_USAGE = `Usage: yaw-mcp upgrade [--run] [--json]
|
|
18
|
+
|
|
19
|
+
Show (or execute) the command to upgrade @yawlabs/mcp to the latest version.
|
|
20
|
+
|
|
21
|
+
--run Run the upgrade in place (global npm, pnpm, bun, and local npm
|
|
22
|
+
installs). No-op for npx installs -- they always fetch the latest.
|
|
23
|
+
--json Emit a machine-readable snapshot ({ current, latest, stale,
|
|
24
|
+
method, command }) instead of prose.
|
|
25
|
+
NOTE: --json is a report-only snapshot; it never spawns an upgrade
|
|
26
|
+
even when combined with --run. Use --run without --json to
|
|
27
|
+
actually perform the upgrade.`;
|
|
28
|
+
function parseUpgradeArgs(argv) {
|
|
29
|
+
const opts = {};
|
|
30
|
+
for (const a of argv) {
|
|
31
|
+
if (a === "--run") opts.run = true;
|
|
32
|
+
else if (a === "--json") opts.json = true;
|
|
33
|
+
else if (a === "--help" || a === "-h") return { ok: false, error: UPGRADE_USAGE, help: true };
|
|
34
|
+
else return { ok: false, error: `yaw-mcp upgrade: unknown argument "${a}"
|
|
35
|
+
|
|
36
|
+
${UPGRADE_USAGE}` };
|
|
37
|
+
}
|
|
38
|
+
return { ok: true, options: opts };
|
|
39
|
+
}
|
|
40
|
+
function detectInstallMethod(argvPath) {
|
|
41
|
+
if (!argvPath) return "unknown";
|
|
42
|
+
const normalized = argvPath.replace(/\\/g, "/");
|
|
43
|
+
if (/\/_npx\/[0-9a-f]+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "npx";
|
|
44
|
+
if (/\/app\.asar\.unpacked\//.test(normalized)) return "bundled-app";
|
|
45
|
+
if (/\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
|
|
46
|
+
if (POSIX_GLOBAL_LIB_PREFIX.test(normalized)) return "global-npm";
|
|
47
|
+
if (MANAGED_NODE_LIB_PREFIX.test(normalized)) return "global-npm";
|
|
48
|
+
if (/\/AppData\/Roaming\/npm\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
|
|
49
|
+
if (/\/bin\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "global-npm";
|
|
50
|
+
if (/\/pnpm\/global\/\d+\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "pnpm-global";
|
|
51
|
+
if (/\/\.bun\/install\/global\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "bun-global";
|
|
52
|
+
if (/\/node_modules\/@yawlabs\/mcp\//.test(normalized)) return "local-node-modules";
|
|
53
|
+
if (/\/(yaw-mcp|mcph)\/(dist|src)\//.test(normalized)) return "dev-checkout";
|
|
54
|
+
return "unknown";
|
|
55
|
+
}
|
|
56
|
+
function localInstallRoot(argvPath) {
|
|
57
|
+
if (!argvPath) return null;
|
|
58
|
+
const idx = argvPath.replace(/\\/g, "/").indexOf("/node_modules/");
|
|
59
|
+
return idx > 0 ? argvPath.slice(0, idx) : null;
|
|
60
|
+
}
|
|
61
|
+
async function npmGlobalPrefix() {
|
|
62
|
+
if (process.env.VITEST) return null;
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
const child = spawn("npm", ["prefix", "-g"], {
|
|
65
|
+
shell: process.platform === "win32",
|
|
66
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
67
|
+
});
|
|
68
|
+
let out = "";
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
child.kill();
|
|
71
|
+
resolve(null);
|
|
72
|
+
}, 3e3);
|
|
73
|
+
child.stdout?.on("data", (d) => {
|
|
74
|
+
out += String(d);
|
|
75
|
+
});
|
|
76
|
+
child.on("close", (code) => {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
resolve(code === 0 && out.trim() ? out.trim() : null);
|
|
79
|
+
});
|
|
80
|
+
child.on("error", () => {
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
resolve(null);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function comparablePath(p) {
|
|
87
|
+
let real = p;
|
|
88
|
+
try {
|
|
89
|
+
real = realpathSync(p);
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
const normalized = real.replace(/\\/g, "/");
|
|
93
|
+
return process.platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
94
|
+
}
|
|
95
|
+
async function refineInstallMethod(method, argvPath, npmPrefix = npmGlobalPrefix) {
|
|
96
|
+
if (method !== "local-node-modules" && method !== "unknown") return method;
|
|
97
|
+
if (!argvPath) return method;
|
|
98
|
+
const prefix = await npmPrefix();
|
|
99
|
+
if (!prefix) return method;
|
|
100
|
+
const entry = comparablePath(argvPath);
|
|
101
|
+
const pfx = comparablePath(prefix);
|
|
102
|
+
if (entry.startsWith(`${pfx}/node_modules/`) || entry.startsWith(`${pfx}/lib/node_modules/`)) {
|
|
103
|
+
return "global-npm";
|
|
104
|
+
}
|
|
105
|
+
return method;
|
|
106
|
+
}
|
|
107
|
+
function buildUpgradePlan(input) {
|
|
108
|
+
const { current, latest, method } = input;
|
|
109
|
+
const stale = latest !== null && current !== "dev" && compareSemverLocal(current, latest) < 0;
|
|
110
|
+
let command;
|
|
111
|
+
switch (method) {
|
|
112
|
+
case "global-npm":
|
|
113
|
+
command = "npm install -g @yawlabs/mcp@latest";
|
|
114
|
+
break;
|
|
115
|
+
case "pnpm-global":
|
|
116
|
+
command = "pnpm add -g @yawlabs/mcp@latest";
|
|
117
|
+
break;
|
|
118
|
+
case "bun-global":
|
|
119
|
+
command = "bun add -g @yawlabs/mcp@latest";
|
|
120
|
+
break;
|
|
121
|
+
case "npx":
|
|
122
|
+
command = null;
|
|
123
|
+
break;
|
|
124
|
+
case "bundled-app":
|
|
125
|
+
command = null;
|
|
126
|
+
break;
|
|
127
|
+
case "local-node-modules":
|
|
128
|
+
command = "npm install @yawlabs/mcp@latest";
|
|
129
|
+
break;
|
|
130
|
+
case "dev-checkout":
|
|
131
|
+
command = "git pull && npm run build";
|
|
132
|
+
break;
|
|
133
|
+
case "binary":
|
|
134
|
+
command = null;
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
command = "npm install -g @yawlabs/mcp@latest";
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return { current, latest, stale, method, command };
|
|
141
|
+
}
|
|
142
|
+
function compareSemverLocal(a, b) {
|
|
143
|
+
const parse = (s) => {
|
|
144
|
+
const cleaned = s.replace(/\+.*$/, "");
|
|
145
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(cleaned);
|
|
146
|
+
if (!m) return null;
|
|
147
|
+
const release = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
148
|
+
const prerelease = m[4] ? m[4].split(".") : [];
|
|
149
|
+
return { release, prerelease };
|
|
150
|
+
};
|
|
151
|
+
const pa = parse(a);
|
|
152
|
+
const pb = parse(b);
|
|
153
|
+
if (!pa || !pb) return 0;
|
|
154
|
+
for (let i = 0; i < 3; i++) {
|
|
155
|
+
if (pa.release[i] < pb.release[i]) return -1;
|
|
156
|
+
if (pa.release[i] > pb.release[i]) return 1;
|
|
157
|
+
}
|
|
158
|
+
if (pa.prerelease.length === 0 && pb.prerelease.length === 0) return 0;
|
|
159
|
+
if (pa.prerelease.length === 0) return 1;
|
|
160
|
+
if (pb.prerelease.length === 0) return -1;
|
|
161
|
+
const len = Math.min(pa.prerelease.length, pb.prerelease.length);
|
|
162
|
+
for (let i = 0; i < len; i++) {
|
|
163
|
+
const ai = pa.prerelease[i];
|
|
164
|
+
const bi = pb.prerelease[i];
|
|
165
|
+
const aNum = /^\d+$/.test(ai);
|
|
166
|
+
const bNum = /^\d+$/.test(bi);
|
|
167
|
+
if (aNum && bNum) {
|
|
168
|
+
const na = Number(ai);
|
|
169
|
+
const nb = Number(bi);
|
|
170
|
+
if (na < nb) return -1;
|
|
171
|
+
if (na > nb) return 1;
|
|
172
|
+
} else if (aNum !== bNum) {
|
|
173
|
+
return aNum ? -1 : 1;
|
|
174
|
+
} else {
|
|
175
|
+
if (ai < bi) return -1;
|
|
176
|
+
if (ai > bi) return 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (pa.prerelease.length < pb.prerelease.length) return -1;
|
|
180
|
+
if (pa.prerelease.length > pb.prerelease.length) return 1;
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
var REGISTRY_FETCH_TIMEOUT_MS = 3e3;
|
|
184
|
+
async function fetchLatestVersion(opts = {}) {
|
|
185
|
+
if (opts.override) {
|
|
186
|
+
try {
|
|
187
|
+
return await opts.override();
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const ac = new AbortController();
|
|
193
|
+
const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? REGISTRY_FETCH_TIMEOUT_MS);
|
|
194
|
+
try {
|
|
195
|
+
const res = await fetch("https://registry.npmjs.org/@yawlabs/mcp/latest", {
|
|
196
|
+
signal: ac.signal,
|
|
197
|
+
headers: { accept: "application/json" }
|
|
198
|
+
});
|
|
199
|
+
if (!res.ok) return null;
|
|
200
|
+
const body = await res.json();
|
|
201
|
+
return typeof body.version === "string" ? body.version : null;
|
|
202
|
+
} catch {
|
|
203
|
+
return null;
|
|
204
|
+
} finally {
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function oamFloorLines(probe) {
|
|
209
|
+
if (!probe && process.env.VITEST) return [];
|
|
210
|
+
try {
|
|
211
|
+
const { MIN_OAM_VERSION, probeOam } = await import("./oam-spawn-VPVBHI7B.js");
|
|
212
|
+
const oam = probe ? await probe() : await probeOam();
|
|
213
|
+
if (!oam.belowMin) return [];
|
|
214
|
+
return [
|
|
215
|
+
"",
|
|
216
|
+
`oam: v${oam.version ?? "unknown"} is installed but below the v${MIN_OAM_VERSION} floor yaw-mcp`,
|
|
217
|
+
" requires, so MCP sidecars run on node instead of oam. Update it:",
|
|
218
|
+
"",
|
|
219
|
+
" oam self-update"
|
|
220
|
+
];
|
|
221
|
+
} catch {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function defaultRunningPrefix(argvPath) {
|
|
226
|
+
if (process.env.VITEST) return null;
|
|
227
|
+
const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-CIO76Z6V.js");
|
|
228
|
+
return detectRunningInstallPrefix2(argvPath);
|
|
229
|
+
}
|
|
230
|
+
async function defaultSpawn(cmd, args, cwd) {
|
|
231
|
+
return new Promise((resolve) => {
|
|
232
|
+
const child = spawn(cmd, args, { stdio: "inherit", shell: process.platform === "win32", cwd });
|
|
233
|
+
child.on("close", (code) => resolve(typeof code === "number" ? code : 1));
|
|
234
|
+
child.on("error", () => resolve(1));
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
async function detectSea() {
|
|
238
|
+
if (process.env.ELECTRON_RUN_AS_NODE) return false;
|
|
239
|
+
const exe = process.execPath.replace(/\\/g, "/").split("/").pop()?.toLowerCase() ?? "";
|
|
240
|
+
if (exe === "node" || exe === "node.exe") return false;
|
|
241
|
+
try {
|
|
242
|
+
const sea = await import("sea");
|
|
243
|
+
return typeof sea.isSea === "function" && sea.isSea() === true;
|
|
244
|
+
} catch {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function runUpgrade(opts = {}) {
|
|
249
|
+
const write = opts.out ?? ((s) => process.stdout.write(s));
|
|
250
|
+
const writeErr = opts.err ?? ((s) => process.stderr.write(s));
|
|
251
|
+
const lines = [];
|
|
252
|
+
const print = (s = "") => {
|
|
253
|
+
lines.push(s);
|
|
254
|
+
write(`${s}
|
|
255
|
+
`);
|
|
256
|
+
};
|
|
257
|
+
const printErr = (s) => {
|
|
258
|
+
lines.push(s);
|
|
259
|
+
writeErr(`${s}
|
|
260
|
+
`);
|
|
261
|
+
};
|
|
262
|
+
const fetcher = opts.fetchLatest ?? fetchLatestVersion;
|
|
263
|
+
const current = opts.currentVersion ?? readCurrentVersion();
|
|
264
|
+
const argvPath = opts.argvPath ?? process.argv[1];
|
|
265
|
+
const sea = opts.isSea ? opts.isSea() : await detectSea();
|
|
266
|
+
const method = sea ? "binary" : await refineInstallMethod(detectInstallMethod(argvPath), argvPath, opts.npmPrefix);
|
|
267
|
+
let latest;
|
|
268
|
+
try {
|
|
269
|
+
latest = await fetcher();
|
|
270
|
+
} catch {
|
|
271
|
+
latest = null;
|
|
272
|
+
}
|
|
273
|
+
const plan = buildUpgradePlan({ current, latest, method });
|
|
274
|
+
let globalPrefixArg = null;
|
|
275
|
+
let suggestedCommand = plan.command;
|
|
276
|
+
if (method === "global-npm") {
|
|
277
|
+
const rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
|
|
278
|
+
if (rawPrefix !== null) {
|
|
279
|
+
const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-CIO76Z6V.js");
|
|
280
|
+
const spawnForm = quoteShellArgIfNeeded2(rawPrefix);
|
|
281
|
+
const displayForm = quoteArgForDisplay2(rawPrefix);
|
|
282
|
+
if (spawnForm !== null && displayForm !== null) {
|
|
283
|
+
globalPrefixArg = spawnForm;
|
|
284
|
+
suggestedCommand = `npm install -g --prefix ${displayForm} @yawlabs/mcp@latest`;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (opts.json) {
|
|
289
|
+
print(JSON.stringify({ ...plan, command: suggestedCommand }, null, 2));
|
|
290
|
+
return { exitCode: plan.stale && !opts.run ? 1 : 0, lines };
|
|
291
|
+
}
|
|
292
|
+
if (latest === null) {
|
|
293
|
+
print("yaw-mcp upgrade: couldn't reach the npm registry (offline? firewall?).");
|
|
294
|
+
if (suggestedCommand) {
|
|
295
|
+
print("When you're back online, run:");
|
|
296
|
+
print("");
|
|
297
|
+
print(` ${suggestedCommand}`);
|
|
298
|
+
} else if (method === "bundled-app") {
|
|
299
|
+
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app \u2014 nothing to run.");
|
|
300
|
+
} else if (method === "binary") {
|
|
301
|
+
print("yaw-mcp is a standalone binary \u2014 download the latest build and replace");
|
|
302
|
+
print(`this executable: ${BINARY_DOWNLOAD_URL}`);
|
|
303
|
+
} else {
|
|
304
|
+
print("Your install uses `npx -y` \u2014 just restart the MCP client when you're back online.");
|
|
305
|
+
}
|
|
306
|
+
return { exitCode: 0, lines };
|
|
307
|
+
}
|
|
308
|
+
print(`Current: ${current}`);
|
|
309
|
+
print(`Latest: ${latest}`);
|
|
310
|
+
print(`Install: ${method}`);
|
|
311
|
+
for (const line of await oamFloorLines(opts.oamProbe)) print(line);
|
|
312
|
+
if (!plan.stale) {
|
|
313
|
+
print("");
|
|
314
|
+
print("OK: You're on the latest version -- nothing to do.");
|
|
315
|
+
return { exitCode: 0, lines };
|
|
316
|
+
}
|
|
317
|
+
print("");
|
|
318
|
+
if (method === "npx") {
|
|
319
|
+
print("Your install uses `npx -y` \u2014 restart the MCP client and it will fetch the new version.");
|
|
320
|
+
return { exitCode: 0, lines };
|
|
321
|
+
}
|
|
322
|
+
if (method === "bundled-app") {
|
|
323
|
+
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app \u2014");
|
|
324
|
+
print("there is nothing to run here. Update Yaw Terminal to get the new version.");
|
|
325
|
+
return { exitCode: 0, lines };
|
|
326
|
+
}
|
|
327
|
+
if (method === "binary") {
|
|
328
|
+
print("yaw-mcp is running as a standalone binary \u2014 manual upgrade required.");
|
|
329
|
+
print("There's no package manager to upgrade it, and `--run` can't automate");
|
|
330
|
+
print("this: download the latest build and replace this executable:");
|
|
331
|
+
print("");
|
|
332
|
+
print(` ${BINARY_DOWNLOAD_URL}`);
|
|
333
|
+
return { exitCode: opts.run ? 2 : 1, lines };
|
|
334
|
+
}
|
|
335
|
+
const installRoot = method === "local-node-modules" ? localInstallRoot(argvPath) : null;
|
|
336
|
+
const runSpec = method === "global-npm" ? {
|
|
337
|
+
cmd: "npm",
|
|
338
|
+
args: globalPrefixArg ? ["install", "-g", "--prefix", globalPrefixArg, "@yawlabs/mcp@latest"] : ["install", "-g", "@yawlabs/mcp@latest"]
|
|
339
|
+
} : method === "pnpm-global" ? { cmd: "pnpm", args: ["add", "-g", "@yawlabs/mcp@latest"] } : method === "bun-global" ? { cmd: "bun", args: ["add", "-g", "@yawlabs/mcp@latest"] } : method === "local-node-modules" && installRoot !== null ? { cmd: "npm", args: ["install", "@yawlabs/mcp@latest"], cwd: installRoot } : null;
|
|
340
|
+
const commandLine = method === "global-npm" ? suggestedCommand : runSpec ? [runSpec.cmd, ...runSpec.args].join(" ") : plan.command;
|
|
341
|
+
if (!opts.run) {
|
|
342
|
+
if (runSpec) {
|
|
343
|
+
print("Run `yaw-mcp upgrade --run` to upgrade in place, or run it yourself:");
|
|
344
|
+
} else {
|
|
345
|
+
print("Manual upgrade required (--run can't safely automate this install method). Run it yourself:");
|
|
346
|
+
}
|
|
347
|
+
print("");
|
|
348
|
+
if (installRoot) {
|
|
349
|
+
print(`in ${installRoot}:`);
|
|
350
|
+
}
|
|
351
|
+
print(` ${commandLine}`);
|
|
352
|
+
return { exitCode: 1, lines };
|
|
353
|
+
}
|
|
354
|
+
if (!runSpec) {
|
|
355
|
+
printErr(
|
|
356
|
+
`yaw-mcp upgrade --run: a "${method}" install can't be upgraded automatically (manual upgrade required). Run it yourself:`
|
|
357
|
+
);
|
|
358
|
+
printErr("");
|
|
359
|
+
printErr(` ${commandLine}`);
|
|
360
|
+
return { exitCode: 2, lines };
|
|
361
|
+
}
|
|
362
|
+
const runner = opts.spawnImpl ?? defaultSpawn;
|
|
363
|
+
if (runSpec.cwd) {
|
|
364
|
+
print(`Running in ${runSpec.cwd}:`);
|
|
365
|
+
} else {
|
|
366
|
+
print("Running:");
|
|
367
|
+
}
|
|
368
|
+
print(` ${commandLine}`);
|
|
369
|
+
print("");
|
|
370
|
+
const code = await runner(runSpec.cmd, runSpec.args, runSpec.cwd);
|
|
371
|
+
if (code === 0) {
|
|
372
|
+
print("");
|
|
373
|
+
print(`OK: Upgraded @yawlabs/mcp to ${latest}`);
|
|
374
|
+
return { exitCode: 0, lines };
|
|
375
|
+
}
|
|
376
|
+
printErr(`yaw-mcp upgrade: ${runSpec.cmd} exited ${code}. Try running the command yourself:`);
|
|
377
|
+
printErr("");
|
|
378
|
+
printErr(` ${commandLine}`);
|
|
379
|
+
return { exitCode: 3, lines };
|
|
380
|
+
}
|
|
381
|
+
function readCurrentVersion() {
|
|
382
|
+
return true ? "0.76.1" : "dev";
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/auto-upgrade.ts
|
|
386
|
+
function quoteShellArgIfNeeded(arg, platform = process.platform) {
|
|
387
|
+
if (platform !== "win32") return arg;
|
|
388
|
+
if (/[\r\n\0"%]/.test(arg)) return null;
|
|
389
|
+
if (!/[\s&|<>^]/.test(arg)) return arg;
|
|
390
|
+
return `"${arg}"`;
|
|
391
|
+
}
|
|
392
|
+
function quoteArgForDisplay(arg, platform = process.platform) {
|
|
393
|
+
if (platform === "win32") return quoteShellArgIfNeeded(arg, platform);
|
|
394
|
+
if (/^[A-Za-z0-9_\-./+,:@=]+$/.test(arg)) return arg;
|
|
395
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
396
|
+
}
|
|
397
|
+
function detectRunningInstallPrefix(argvPath) {
|
|
398
|
+
if (!argvPath) return null;
|
|
399
|
+
let resolved;
|
|
400
|
+
try {
|
|
401
|
+
resolved = realpathSync2(argvPath);
|
|
402
|
+
} catch {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
let dir = dirname(resolved);
|
|
406
|
+
let prev = "";
|
|
407
|
+
let safety = 24;
|
|
408
|
+
while (dir !== prev && safety-- > 0) {
|
|
409
|
+
const idx = dir.lastIndexOf(`${sep}node_modules${sep}`);
|
|
410
|
+
if (idx !== -1) {
|
|
411
|
+
const candidate = dir.slice(0, idx);
|
|
412
|
+
if (candidate.endsWith(`${sep}lib`)) return candidate.slice(0, -`${sep}lib`.length);
|
|
413
|
+
return candidate;
|
|
414
|
+
}
|
|
415
|
+
prev = dir;
|
|
416
|
+
dir = dirname(dir);
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
function comparablePrefix(p) {
|
|
421
|
+
const trimmed = p.trim();
|
|
422
|
+
return process.platform === "win32" ? trimmed.toLowerCase() : trimmed;
|
|
423
|
+
}
|
|
424
|
+
async function compareWithNpmPrefix(detected, probe = npmGlobalPrefix) {
|
|
425
|
+
const npmPrefix = await probe();
|
|
426
|
+
if (!npmPrefix?.trim()) return;
|
|
427
|
+
if (comparablePrefix(npmPrefix) === comparablePrefix(detected)) return;
|
|
428
|
+
process.stderr.write(
|
|
429
|
+
`yaw-mcp self-upgrade: detected running prefix differs from \`npm prefix -g\`:
|
|
430
|
+
running: ${detected}
|
|
431
|
+
npm -g: ${npmPrefix}
|
|
432
|
+
Installing into the running prefix so the upgrade lands in the same tree the client spawned from.
|
|
433
|
+
`
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
function defaultSpawn2(cmd, args) {
|
|
437
|
+
let errorFired = false;
|
|
438
|
+
const correctiveCmd = cmd === "npm" ? "npm install -g @yawlabs/mcp@latest" : cmd === "pnpm" ? "pnpm add -g @yawlabs/mcp@latest" : "bun add -g @yawlabs/mcp@latest";
|
|
439
|
+
const child = spawn2(cmd, args, {
|
|
440
|
+
stdio: "ignore",
|
|
441
|
+
// Not detached, so the install shares yaw-mcp's process group and an MCP
|
|
442
|
+
// client that tears down the whole tree takes it with it. Two things this
|
|
443
|
+
// does NOT buy (the file header lists both as known gaps): on POSIX a
|
|
444
|
+
// plain parent exit does not kill it, and if it IS killed mid-install the
|
|
445
|
+
// result is not guaranteed intact -- npm reify removes the existing
|
|
446
|
+
// package dir before moving the new one in, and nothing here repairs a
|
|
447
|
+
// partial install on the next startup.
|
|
448
|
+
detached: false,
|
|
449
|
+
shell: process.platform === "win32"
|
|
450
|
+
});
|
|
451
|
+
child.on("close", (code) => {
|
|
452
|
+
if (errorFired) return;
|
|
453
|
+
if (code === 0) {
|
|
454
|
+
log("info", "yaw-mcp self-upgrade complete; the next client restart will run the new version");
|
|
455
|
+
} else {
|
|
456
|
+
const hint = cmd === "npm" ? " (often EACCES on a sudo-installed global -- run with the right permissions)" : "";
|
|
457
|
+
log(
|
|
458
|
+
"warn",
|
|
459
|
+
`yaw-mcp self-upgrade: ${cmd} exited non-zero${hint}. Run \`${correctiveCmd}\` manually, or set YAW_MCP_AUTO_UPGRADE=0 to silence this.`,
|
|
460
|
+
{ code }
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
child.on("error", (err) => {
|
|
465
|
+
errorFired = true;
|
|
466
|
+
log("warn", `yaw-mcp self-upgrade: ${cmd} spawn failed`, { error: err?.message });
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
async function maybeAutoUpgrade(deps = {}) {
|
|
470
|
+
const optOut = process.env.YAW_MCP_AUTO_UPGRADE;
|
|
471
|
+
if (optOut === "0" || optOut?.toLowerCase() === "false") return;
|
|
472
|
+
const current = deps.currentVersion ?? (true ? "0.76.1" : "dev");
|
|
473
|
+
if (current === "dev") return;
|
|
474
|
+
const method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(deps.argvPath ?? process.argv[1]);
|
|
475
|
+
const latest = await (deps.fetchLatestImpl ?? fetchLatestVersion)();
|
|
476
|
+
if (latest === null) return;
|
|
477
|
+
const plan = buildUpgradePlan({ current, latest, method });
|
|
478
|
+
if (!plan.stale) return;
|
|
479
|
+
const rawPrefix = method === "global-npm" ? detectRunningInstallPrefix(deps.argvPath ?? process.argv[1]) : null;
|
|
480
|
+
const quotedPrefix = rawPrefix === null ? null : quoteShellArgIfNeeded(rawPrefix);
|
|
481
|
+
const globalSpec = method === "global-npm" ? {
|
|
482
|
+
cmd: "npm",
|
|
483
|
+
args: quotedPrefix ? ["install", "-g", "--prefix", quotedPrefix, "@yawlabs/mcp@latest"] : ["install", "-g", "@yawlabs/mcp@latest"]
|
|
484
|
+
} : method === "pnpm-global" ? { cmd: "pnpm", args: ["add", "-g", "@yawlabs/mcp@latest"] } : method === "bun-global" ? { cmd: "bun", args: ["add", "-g", "@yawlabs/mcp@latest"] } : null;
|
|
485
|
+
if (globalSpec) {
|
|
486
|
+
log("info", "yaw-mcp is out of date; upgrading the global install in the background", {
|
|
487
|
+
current,
|
|
488
|
+
latest,
|
|
489
|
+
tool: globalSpec.cmd,
|
|
490
|
+
// The RAW prefix, not the shell-quoted argv form -- a log field is read
|
|
491
|
+
// by a human, and stray quotes read as part of the path. Omitted when
|
|
492
|
+
// quoting failed, because then no `--prefix` was passed at all and npm
|
|
493
|
+
// resolves its own prefix.
|
|
494
|
+
prefix: quotedPrefix === null ? void 0 : rawPrefix ?? void 0
|
|
495
|
+
});
|
|
496
|
+
if (method === "global-npm" && rawPrefix !== null && quotedPrefix !== null) {
|
|
497
|
+
void compareWithNpmPrefix(rawPrefix, deps.npmPrefixImpl);
|
|
498
|
+
}
|
|
499
|
+
(deps.spawnImpl ?? defaultSpawn2)(globalSpec.cmd, globalSpec.args);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (method === "bundled-app") {
|
|
503
|
+
log("info", "yaw-mcp (bundled with Yaw Terminal) is behind npm; it updates with the app", { current, latest });
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (method === "binary") {
|
|
507
|
+
log("info", "yaw-mcp (standalone binary) is behind npm; download the latest build to update", { current, latest });
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (method === "npx") {
|
|
511
|
+
log("info", "yaw-mcp is out of date; restart your MCP client to pick up the latest version", {
|
|
512
|
+
current,
|
|
513
|
+
latest,
|
|
514
|
+
method
|
|
515
|
+
});
|
|
516
|
+
} else if (method === "local-node-modules") {
|
|
517
|
+
log(
|
|
518
|
+
"info",
|
|
519
|
+
"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)",
|
|
520
|
+
{
|
|
521
|
+
current,
|
|
522
|
+
latest,
|
|
523
|
+
method
|
|
524
|
+
}
|
|
525
|
+
);
|
|
526
|
+
} else {
|
|
527
|
+
log(
|
|
528
|
+
"info",
|
|
529
|
+
"yaw-mcp is out of date; run `yaw-mcp upgrade` for the command that updates this install (`--run` can't automate this install method)",
|
|
530
|
+
{
|
|
531
|
+
current,
|
|
532
|
+
latest,
|
|
533
|
+
method
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export {
|
|
540
|
+
quoteShellArgIfNeeded,
|
|
541
|
+
quoteArgForDisplay,
|
|
542
|
+
detectRunningInstallPrefix,
|
|
543
|
+
maybeAutoUpgrade,
|
|
544
|
+
BINARY_DOWNLOAD_URL,
|
|
545
|
+
parseUpgradeArgs,
|
|
546
|
+
detectInstallMethod,
|
|
547
|
+
refineInstallMethod,
|
|
548
|
+
buildUpgradePlan,
|
|
549
|
+
fetchLatestVersion,
|
|
550
|
+
detectSea,
|
|
551
|
+
runUpgrade
|
|
552
|
+
};
|