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