@yawlabs/mcp 0.79.2 → 1.0.0
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 +1341 -995
- package/README.md +128 -14
- package/dist/auto-upgrade-PREISPB3.js +23 -0
- package/dist/{chunk-ODSIFM3N.js → chunk-PZMKIDQV.js} +444 -133
- package/dist/index.js +15091 -9711
- package/package.json +2 -2
- package/schemas/yaw-mcp.config.v1.json +31 -4
- package/dist/auto-upgrade-W6LVJ7XD.js +0 -15
|
@@ -2,18 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
// src/auto-upgrade.ts
|
|
4
4
|
import { spawn as spawn3 } from "child_process";
|
|
5
|
+
import { createHash } from "crypto";
|
|
5
6
|
import {
|
|
6
7
|
closeSync,
|
|
7
8
|
openSync,
|
|
8
|
-
readFileSync as
|
|
9
|
+
readFileSync as readFileSync3,
|
|
9
10
|
realpathSync as realpathSync2,
|
|
11
|
+
renameSync,
|
|
10
12
|
statSync as statSync2,
|
|
11
13
|
unlinkSync,
|
|
12
14
|
writeFileSync,
|
|
13
15
|
writeSync
|
|
14
16
|
} from "fs";
|
|
15
17
|
import { tmpdir } from "os";
|
|
16
|
-
import { dirname as dirname2, join as
|
|
18
|
+
import { dirname as dirname2, join as join4, sep as sep2 } from "path";
|
|
19
|
+
|
|
20
|
+
// src/internal-secret-env.ts
|
|
21
|
+
var INTERNAL_SECRET_ENV_KEYS = /* @__PURE__ */ new Set([
|
|
22
|
+
"YAW_MCP_TOKEN",
|
|
23
|
+
"YAW_MCP_VAULT_PASSPHRASE",
|
|
24
|
+
"YAW_MCP_VAULT_PASSPHRASE_NEW"
|
|
25
|
+
]);
|
|
26
|
+
function scrubInternalSecretsFromProcessEnv() {
|
|
27
|
+
for (const key of Object.keys(process.env)) {
|
|
28
|
+
if (INTERNAL_SECRET_ENV_KEYS.has(key.toUpperCase())) delete process.env[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function stripInternalSecretsFromEnv(env) {
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const [key, value] of Object.entries(env)) {
|
|
34
|
+
if (INTERNAL_SECRET_ENV_KEYS.has(key.toUpperCase())) continue;
|
|
35
|
+
out[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
17
39
|
|
|
18
40
|
// src/logger.ts
|
|
19
41
|
var LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
@@ -29,9 +51,35 @@ function guardStderrErrors() {
|
|
|
29
51
|
} catch {
|
|
30
52
|
}
|
|
31
53
|
}
|
|
54
|
+
var surface = "server";
|
|
55
|
+
function setLogSurface(next) {
|
|
56
|
+
surface = next;
|
|
57
|
+
}
|
|
58
|
+
function logLevelRequested() {
|
|
59
|
+
const raw = process.env.LOG_LEVEL?.trim().toLowerCase();
|
|
60
|
+
return raw !== void 0 && raw in LOG_LEVELS;
|
|
61
|
+
}
|
|
62
|
+
function renderData(data) {
|
|
63
|
+
if (data === void 0) return "";
|
|
64
|
+
try {
|
|
65
|
+
const parts = Object.entries(data).map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`);
|
|
66
|
+
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
67
|
+
} catch {
|
|
68
|
+
return " (details omitted)";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
32
71
|
function log(level, msg, data) {
|
|
33
72
|
if (LOG_LEVELS[level] < minLevel()) return;
|
|
34
73
|
guardStderrErrors();
|
|
74
|
+
if (surface === "cli" && !logLevelRequested()) {
|
|
75
|
+
if (LOG_LEVELS[level] < LOG_LEVELS.warn) return;
|
|
76
|
+
try {
|
|
77
|
+
process.stderr.write(`yaw-mcp: ${level === "warn" ? "warning" : "error"}: ${msg}${renderData(data)}
|
|
78
|
+
`);
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
35
83
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
36
84
|
let entry;
|
|
37
85
|
try {
|
|
@@ -45,10 +93,32 @@ function log(level, msg, data) {
|
|
|
45
93
|
} catch {
|
|
46
94
|
}
|
|
47
95
|
}
|
|
96
|
+
var brokenStreams = /* @__PURE__ */ new WeakSet();
|
|
97
|
+
var guardedStreams = /* @__PURE__ */ new WeakSet();
|
|
98
|
+
function createStreamWriter(stream) {
|
|
99
|
+
if (!guardedStreams.has(stream)) {
|
|
100
|
+
guardedStreams.add(stream);
|
|
101
|
+
try {
|
|
102
|
+
stream.on("error", () => {
|
|
103
|
+
brokenStreams.add(stream);
|
|
104
|
+
});
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return (s) => {
|
|
109
|
+
if (brokenStreams.has(stream)) return;
|
|
110
|
+
try {
|
|
111
|
+
stream.write(s);
|
|
112
|
+
} catch {
|
|
113
|
+
brokenStreams.add(stream);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
48
117
|
|
|
49
118
|
// src/upgrade-cmd.ts
|
|
50
119
|
import { spawn as spawn2 } from "child_process";
|
|
51
|
-
import { realpathSync } from "fs";
|
|
120
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
121
|
+
import { join as join3 } from "path";
|
|
52
122
|
|
|
53
123
|
// src/oam-spawn.ts
|
|
54
124
|
import { spawn } from "child_process";
|
|
@@ -93,7 +163,10 @@ var INSTALL_TARGETS = [
|
|
|
93
163
|
label: "Claude Desktop",
|
|
94
164
|
jsonShape: "mcpServers",
|
|
95
165
|
availableOn: ["macos", "windows"],
|
|
96
|
-
|
|
166
|
+
// ASCII `--`, not an em-dash: install prints this verbatim (`Note: ...`),
|
|
167
|
+
// and Claude Desktop is a Windows client -- on a console whose codepage is
|
|
168
|
+
// not UTF-8 the em-dash rendered as mojibake in the line the user reads.
|
|
169
|
+
notes: "Claude Desktop reads one file per OS -- no project scope. Restart the app after editing.",
|
|
97
170
|
scopes: [
|
|
98
171
|
{
|
|
99
172
|
scope: "user",
|
|
@@ -128,8 +201,17 @@ var INSTALL_TARGETS = [
|
|
|
128
201
|
label: "VS Code",
|
|
129
202
|
jsonShape: "servers",
|
|
130
203
|
availableOn: ["macos", "linux", "windows"],
|
|
131
|
-
notes: "VS Code uses `servers` (not `mcpServers`) as the top-level key in .vscode/mcp.json.",
|
|
204
|
+
notes: "VS Code uses `servers` (not `mcpServers`) as the top-level key in mcp.json -- the user-profile file and .vscode/mcp.json share that shape. The user file covers the DEFAULT profile only; a custom profile keeps its own copy under Code/User/profiles/<id>/mcp.json. Needs VS Code 1.102 or newer, before which user-level MCP lived under the `mcp` key in settings.json.",
|
|
132
205
|
scopes: [
|
|
206
|
+
// User FIRST: enumerateProbeSlots walks this array in order, so it
|
|
207
|
+
// decides --list and doctor row order, and every other multi-scope
|
|
208
|
+
// client lists user before project.
|
|
209
|
+
{
|
|
210
|
+
scope: "user",
|
|
211
|
+
label: "User (global)",
|
|
212
|
+
description: "Private to this machine; applies to every VS Code workspace.",
|
|
213
|
+
requiresProjectDir: false
|
|
214
|
+
},
|
|
133
215
|
{
|
|
134
216
|
scope: "project",
|
|
135
217
|
label: "Workspace",
|
|
@@ -137,6 +219,45 @@ var INSTALL_TARGETS = [
|
|
|
137
219
|
requiresProjectDir: true
|
|
138
220
|
}
|
|
139
221
|
]
|
|
222
|
+
},
|
|
223
|
+
// APPENDED, never inserted: autoDetectClient returns the first usable probe
|
|
224
|
+
// slot in array order and documents Claude-Code-first as an invariant, so an
|
|
225
|
+
// insert would silently change which client `try` picks for existing users.
|
|
226
|
+
{
|
|
227
|
+
clientId: "windsurf",
|
|
228
|
+
label: "Windsurf",
|
|
229
|
+
jsonShape: "mcpServers",
|
|
230
|
+
availableOn: ["macos", "linux", "windows"],
|
|
231
|
+
notes: "Windsurf reads ~/.codeium/windsurf/mcp_config.json and does not create it on first launch. If the server does not appear, open Cascade -> MCP servers -> Manage plugins -> View raw config and check it is the file above.",
|
|
232
|
+
scopes: [
|
|
233
|
+
{
|
|
234
|
+
scope: "user",
|
|
235
|
+
label: "User (global)",
|
|
236
|
+
description: "The only config file Windsurf reads; it has no workspace scope.",
|
|
237
|
+
requiresProjectDir: false
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
clientId: "gemini-cli",
|
|
243
|
+
label: "Gemini CLI",
|
|
244
|
+
jsonShape: "mcpServers",
|
|
245
|
+
availableOn: ["macos", "linux", "windows"],
|
|
246
|
+
notes: "Gemini CLI merges ~/.gemini/settings.json with <project>/.gemini/settings.json, project winning. `mcpServers` is a top-level key, distinct from the sibling `mcp` object that holds discovery knobs.",
|
|
247
|
+
scopes: [
|
|
248
|
+
{
|
|
249
|
+
scope: "user",
|
|
250
|
+
label: "User (global)",
|
|
251
|
+
description: "Private to this machine; applies to every project.",
|
|
252
|
+
requiresProjectDir: false
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
scope: "project",
|
|
256
|
+
label: "Project",
|
|
257
|
+
description: "Commit to share with your team; wins over the user file.",
|
|
258
|
+
requiresProjectDir: true
|
|
259
|
+
}
|
|
260
|
+
]
|
|
140
261
|
}
|
|
141
262
|
];
|
|
142
263
|
function resolveAppDataDir(opts) {
|
|
@@ -232,12 +353,52 @@ function pathFor(client, scope, os, base) {
|
|
|
232
353
|
};
|
|
233
354
|
}
|
|
234
355
|
if (client === "vscode") {
|
|
356
|
+
if (scope === "user") {
|
|
357
|
+
if (os === "windows") {
|
|
358
|
+
return {
|
|
359
|
+
absolute: join(appData, "Code", "User", "mcp.json"),
|
|
360
|
+
display: "%APPDATA%\\Code\\User\\mcp.json",
|
|
361
|
+
containerPath: ["servers"]
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
if (os === "macos") {
|
|
365
|
+
return {
|
|
366
|
+
absolute: join(home, "Library", "Application Support", "Code", "User", "mcp.json"),
|
|
367
|
+
display: "~/Library/Application Support/Code/User/mcp.json",
|
|
368
|
+
containerPath: ["servers"]
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
absolute: join(home, ".config", "Code", "User", "mcp.json"),
|
|
373
|
+
display: "~/.config/Code/User/mcp.json",
|
|
374
|
+
containerPath: ["servers"]
|
|
375
|
+
};
|
|
376
|
+
}
|
|
235
377
|
return {
|
|
236
378
|
absolute: join(projectDir, ".vscode", "mcp.json"),
|
|
237
379
|
display: joinPath("<project folder>", ".vscode", "mcp.json"),
|
|
238
380
|
containerPath: ["servers"]
|
|
239
381
|
};
|
|
240
382
|
}
|
|
383
|
+
if (client === "windsurf") {
|
|
384
|
+
const display = os === "windows" ? "%USERPROFILE%\\.codeium\\windsurf\\mcp_config.json" : "~/.codeium/windsurf/mcp_config.json";
|
|
385
|
+
return {
|
|
386
|
+
absolute: join(home, ".codeium", "windsurf", "mcp_config.json"),
|
|
387
|
+
display,
|
|
388
|
+
containerPath: ["mcpServers"]
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
if (client === "gemini-cli") {
|
|
392
|
+
if (scope === "user") {
|
|
393
|
+
const display = os === "windows" ? "%USERPROFILE%\\.gemini\\settings.json" : "~/.gemini/settings.json";
|
|
394
|
+
return { absolute: join(home, ".gemini", "settings.json"), display, containerPath: ["mcpServers"] };
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
absolute: join(projectDir, ".gemini", "settings.json"),
|
|
398
|
+
display: joinPath("<project folder>", ".gemini", "settings.json"),
|
|
399
|
+
containerPath: ["mcpServers"]
|
|
400
|
+
};
|
|
401
|
+
}
|
|
241
402
|
throw new Error(`Unhandled client: ${client}`);
|
|
242
403
|
}
|
|
243
404
|
var CMD_METACHARS = /[&|<>^()]/g;
|
|
@@ -250,6 +411,7 @@ var KNOWN_DIRECT_BINARIES = /* @__PURE__ */ new Set([
|
|
|
250
411
|
"python",
|
|
251
412
|
"python3",
|
|
252
413
|
"py",
|
|
414
|
+
"uv",
|
|
253
415
|
"uvx",
|
|
254
416
|
"pipx",
|
|
255
417
|
"ruby",
|
|
@@ -379,17 +541,12 @@ function isUnderHome(dir, homeResolved) {
|
|
|
379
541
|
}
|
|
380
542
|
var ALLOW_UNOWNED_ENV = "YAW_MCP_ALLOW_UNOWNED_PROJECT_DIRS";
|
|
381
543
|
var warnedUntrustedDirs = /* @__PURE__ */ new Set();
|
|
382
|
-
|
|
544
|
+
function ownedByCurrentUser(st, env) {
|
|
383
545
|
const geteuid = process.geteuid;
|
|
384
|
-
if (typeof geteuid !== "function") return
|
|
385
|
-
|
|
386
|
-
const st = await stat(candidate);
|
|
387
|
-
return typeof st.uid === "number" && st.uid === geteuid.call(process);
|
|
388
|
-
} catch {
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
546
|
+
if (typeof geteuid !== "function") return env[ALLOW_UNOWNED_ENV] === "1";
|
|
547
|
+
return typeof st.uid === "number" && st.uid === geteuid.call(process);
|
|
391
548
|
}
|
|
392
|
-
async function findProjectConfigDir(start, home = homedir2()) {
|
|
549
|
+
async function findProjectConfigDir(start, home = homedir2(), env = process.env) {
|
|
393
550
|
const homeFallback = home && home.length > 0 ? home : homedir2();
|
|
394
551
|
const homeResolved = path.resolve(await realpathOrSelf(path.resolve(homeFallback)));
|
|
395
552
|
let dir = path.resolve(await realpathOrSelf(path.resolve(start)));
|
|
@@ -405,7 +562,7 @@ async function findProjectConfigDir(start, home = homedir2()) {
|
|
|
405
562
|
log("debug", "Skipping a .yaw-mcp that exists but is not a directory", { candidate });
|
|
406
563
|
} else if (normalizeForCompare(await realpathOrSelf(candidate)) === userConfigKey) {
|
|
407
564
|
log("debug", "Skipping a .yaw-mcp/ that resolves to the user-global config dir", { candidate });
|
|
408
|
-
} else if (boundedByHome ||
|
|
565
|
+
} else if (boundedByHome || ownedByCurrentUser(st, env)) {
|
|
409
566
|
return candidate;
|
|
410
567
|
} else {
|
|
411
568
|
if (!warnedUntrustedDirs.has(candidate)) {
|
|
@@ -449,7 +606,10 @@ function specConstraint(spec) {
|
|
|
449
606
|
}
|
|
450
607
|
function isRegistrySpec(spec) {
|
|
451
608
|
if (spec.includes(":") || /^[./~\\]/.test(spec)) return false;
|
|
452
|
-
|
|
609
|
+
const m = /^(?:@([^/]+)\/)?([^./_][^/]*)$/.exec(packageName(spec));
|
|
610
|
+
if (!m) return false;
|
|
611
|
+
const [, scope, name] = m;
|
|
612
|
+
return (scope === void 0 || encodeURIComponent(scope) === scope) && encodeURIComponent(name) === name;
|
|
453
613
|
}
|
|
454
614
|
function npxSpecIndex(args) {
|
|
455
615
|
return args.findIndex((a) => a !== "-y" && a !== "--yes");
|
|
@@ -624,7 +784,11 @@ function spawnVersionProbe(bin) {
|
|
|
624
784
|
try {
|
|
625
785
|
child = spawn(bin, ["--version"], {
|
|
626
786
|
stdio: ["ignore", "pipe", "ignore"],
|
|
627
|
-
windowsHide: process.platform === "win32"
|
|
787
|
+
windowsHide: process.platform === "win32",
|
|
788
|
+
// oam is a binary yaw-mcp did not write; README promises the vault
|
|
789
|
+
// passphrase is stripped from every child yaw-mcp starts, and this
|
|
790
|
+
// probe was one of two spawns that still inherited process.env whole.
|
|
791
|
+
env: stripInternalSecretsFromEnv(process.env)
|
|
628
792
|
});
|
|
629
793
|
} catch (err) {
|
|
630
794
|
reject(err);
|
|
@@ -786,7 +950,7 @@ function rewriteForOam(command, args, deps) {
|
|
|
786
950
|
if (spec.startsWith("-")) {
|
|
787
951
|
log("debug", "npx launch carries flags yaw-mcp does not parse; staying on npx instead of oam", {
|
|
788
952
|
flag: spec,
|
|
789
|
-
args
|
|
953
|
+
argc: args.length
|
|
790
954
|
});
|
|
791
955
|
return { command, args };
|
|
792
956
|
}
|
|
@@ -821,6 +985,13 @@ function rewriteForOam(command, args, deps) {
|
|
|
821
985
|
return { command, args };
|
|
822
986
|
}
|
|
823
987
|
var NPX_CACHE_MARKER = `${sep}_npx${sep}`;
|
|
988
|
+
function npxHashNodeModules(npxRoot) {
|
|
989
|
+
try {
|
|
990
|
+
return readdirSync(npxRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => join2(npxRoot, e.name, "node_modules"));
|
|
991
|
+
} catch {
|
|
992
|
+
return [];
|
|
993
|
+
}
|
|
994
|
+
}
|
|
824
995
|
function npxCacheNodeModules(fromUrl = import.meta.url) {
|
|
825
996
|
let here;
|
|
826
997
|
try {
|
|
@@ -831,11 +1002,7 @@ function npxCacheNodeModules(fromUrl = import.meta.url) {
|
|
|
831
1002
|
const idx = here.indexOf(NPX_CACHE_MARKER);
|
|
832
1003
|
if (idx === -1) return [];
|
|
833
1004
|
const npxRoot = here.slice(0, idx + NPX_CACHE_MARKER.length - sep.length);
|
|
834
|
-
|
|
835
|
-
return readdirSync(npxRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => join2(npxRoot, e.name, "node_modules"));
|
|
836
|
-
} catch {
|
|
837
|
-
return [];
|
|
838
|
-
}
|
|
1005
|
+
return npxHashNodeModules(npxRoot);
|
|
839
1006
|
}
|
|
840
1007
|
function npmrcValue(raw) {
|
|
841
1008
|
const v = raw.trim();
|
|
@@ -879,12 +1046,19 @@ function npmrcCache(file) {
|
|
|
879
1046
|
for (const line of text.split(/\r?\n/)) {
|
|
880
1047
|
const m = /^\s*cache\s*=(.*)$/.exec(line);
|
|
881
1048
|
if (!m) continue;
|
|
882
|
-
const value = npmrcValue(m[1]);
|
|
1049
|
+
const value = expandNpmrcEnv(npmrcValue(m[1]));
|
|
883
1050
|
if (!value) continue;
|
|
884
1051
|
last = value.startsWith("~/") ? join2(homedir3(), value.slice(2)) : value;
|
|
885
1052
|
}
|
|
886
1053
|
return last;
|
|
887
1054
|
}
|
|
1055
|
+
function expandNpmrcEnv(value, env = process.env) {
|
|
1056
|
+
return value.replace(/(\\*)\$\{([^${}]+)\}/g, (orig, esc, name) => {
|
|
1057
|
+
if (esc.length % 2 === 1) return orig.slice((esc.length + 1) / 2);
|
|
1058
|
+
const val = env[name];
|
|
1059
|
+
return esc.slice(esc.length / 2) + (val === void 0 ? `\${${name}}` : val);
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
888
1062
|
var npmCacheDirCache = /* @__PURE__ */ new Map();
|
|
889
1063
|
function npmCacheDir(fromUrl = import.meta.url) {
|
|
890
1064
|
const cached = npmCacheDirCache.get(fromUrl);
|
|
@@ -924,12 +1098,7 @@ function resolveNpmCacheDir(fromUrl) {
|
|
|
924
1098
|
}
|
|
925
1099
|
function npmCacheNpxNodeModules(cacheDir2) {
|
|
926
1100
|
if (!cacheDir2) return [];
|
|
927
|
-
|
|
928
|
-
try {
|
|
929
|
-
return readdirSync(npxRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => join2(npxRoot, e.name, "node_modules"));
|
|
930
|
-
} catch {
|
|
931
|
-
return [];
|
|
932
|
-
}
|
|
1101
|
+
return npxHashNodeModules(join2(cacheDir2, "_npx"));
|
|
933
1102
|
}
|
|
934
1103
|
function ownNodeModules(fromUrl = import.meta.url) {
|
|
935
1104
|
let here;
|
|
@@ -946,21 +1115,25 @@ function ownNodeModules(fromUrl = import.meta.url) {
|
|
|
946
1115
|
function packageEntry(pkgDir, pkg) {
|
|
947
1116
|
const pjPath = join2(pkgDir, "package.json");
|
|
948
1117
|
if (!existsSync(pjPath)) return null;
|
|
949
|
-
let
|
|
1118
|
+
let parsed;
|
|
950
1119
|
try {
|
|
951
|
-
|
|
1120
|
+
parsed = JSON.parse(readFileSync(pjPath, "utf8"));
|
|
952
1121
|
} catch {
|
|
953
1122
|
return null;
|
|
954
1123
|
}
|
|
1124
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
1125
|
+
const j = parsed;
|
|
955
1126
|
let rel;
|
|
956
1127
|
if (typeof j.bin === "string") {
|
|
957
1128
|
rel = j.bin;
|
|
958
1129
|
} else if (j.bin && typeof j.bin === "object") {
|
|
1130
|
+
const bins = j.bin;
|
|
1131
|
+
const own = (key) => typeof key === "string" && Object.hasOwn(bins, key) ? bins[key] : void 0;
|
|
959
1132
|
const unscoped = pkg.slice(pkg.lastIndexOf("/") + 1);
|
|
960
|
-
rel =
|
|
1133
|
+
rel = own(unscoped) ?? own(j.name) ?? Object.values(bins)[0];
|
|
961
1134
|
}
|
|
962
1135
|
if (!rel && typeof j.main === "string") rel = j.main;
|
|
963
|
-
if (
|
|
1136
|
+
if (typeof rel !== "string" || rel.length === 0) return null;
|
|
964
1137
|
const entry = isAbsolute2(rel) ? rel : join2(pkgDir, rel);
|
|
965
1138
|
if (!existsSync(entry)) return null;
|
|
966
1139
|
return {
|
|
@@ -1120,7 +1293,6 @@ function isOamLaunch(command, args = []) {
|
|
|
1120
1293
|
}
|
|
1121
1294
|
|
|
1122
1295
|
// 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
1296
|
var POSIX_GLOBAL_LIB_PREFIX = /^(?:[A-Za-z]:)?(?:\/usr(?:\/local)?|\/opt\/[^/]+)\/lib\/node_modules\/@yawlabs\/mcp\//;
|
|
1125
1297
|
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
1298
|
var UPGRADE_USAGE = `Usage: yaw-mcp upgrade [--run] [--json]
|
|
@@ -1151,10 +1323,10 @@ ${UPGRADE_USAGE}` };
|
|
|
1151
1323
|
}
|
|
1152
1324
|
return { ok: true, options: opts };
|
|
1153
1325
|
}
|
|
1154
|
-
function detectInstallMethod(argvPath, realpath2 = realpathSync) {
|
|
1326
|
+
function detectInstallMethod(argvPath, realpath2 = realpathSync, resolveWhen = ["unknown"]) {
|
|
1155
1327
|
if (!argvPath) return "unknown";
|
|
1156
1328
|
const literal = classifyEntrypoint(argvPath);
|
|
1157
|
-
if (literal
|
|
1329
|
+
if (!resolveWhen.includes(literal)) return literal;
|
|
1158
1330
|
let resolved;
|
|
1159
1331
|
try {
|
|
1160
1332
|
resolved = realpath2(argvPath);
|
|
@@ -1183,6 +1355,30 @@ function localInstallRoot(argvPath) {
|
|
|
1183
1355
|
const idx = argvPath.replace(/\\/g, "/").indexOf("/node_modules/");
|
|
1184
1356
|
return idx > 0 ? argvPath.slice(0, idx) : null;
|
|
1185
1357
|
}
|
|
1358
|
+
function runningPackageDir(argvPath, realpath2 = realpathSync) {
|
|
1359
|
+
if (!argvPath) return null;
|
|
1360
|
+
const literal = packageDirOf(argvPath);
|
|
1361
|
+
if (literal !== null) return literal;
|
|
1362
|
+
try {
|
|
1363
|
+
return packageDirOf(realpath2(argvPath));
|
|
1364
|
+
} catch {
|
|
1365
|
+
return null;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
function packageDirOf(p) {
|
|
1369
|
+
const marker = "/node_modules/@yawlabs/mcp/";
|
|
1370
|
+
const idx = p.replace(/\\/g, "/").lastIndexOf(marker);
|
|
1371
|
+
return idx === -1 ? null : p.slice(0, idx + marker.length - 1);
|
|
1372
|
+
}
|
|
1373
|
+
function defaultInstalledVersion(pkgDir) {
|
|
1374
|
+
if (process.env.VITEST) return null;
|
|
1375
|
+
try {
|
|
1376
|
+
const parsed = JSON.parse(readFileSync2(join3(pkgDir, "package.json"), "utf8"));
|
|
1377
|
+
return typeof parsed.version === "string" ? parsed.version : null;
|
|
1378
|
+
} catch {
|
|
1379
|
+
return null;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1186
1382
|
function killProcessTree(child, platform = process.platform, spawnImpl = spawn2) {
|
|
1187
1383
|
if (platform === "win32" && child.pid !== void 0) {
|
|
1188
1384
|
try {
|
|
@@ -1193,12 +1389,16 @@ function killProcessTree(child, platform = process.platform, spawnImpl = spawn2)
|
|
|
1193
1389
|
}
|
|
1194
1390
|
child.kill();
|
|
1195
1391
|
}
|
|
1196
|
-
async function npmGlobalPrefix() {
|
|
1197
|
-
if (process.env.VITEST) return null;
|
|
1392
|
+
async function npmGlobalPrefix(spawnImpl) {
|
|
1393
|
+
if (process.env.VITEST && !spawnImpl) return null;
|
|
1394
|
+
const spawnFn = spawnImpl ?? spawn2;
|
|
1198
1395
|
return new Promise((resolve2) => {
|
|
1199
|
-
const child =
|
|
1396
|
+
const child = spawnFn("npm", ["prefix", "-g"], {
|
|
1200
1397
|
shell: process.platform === "win32",
|
|
1201
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
1398
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
1399
|
+
// Even a read-only `npm prefix -g` is an npm invocation: yaw-mcp's own
|
|
1400
|
+
// secrets do not ride into it. See internal-secret-env.ts.
|
|
1401
|
+
env: stripInternalSecretsFromEnv(process.env)
|
|
1202
1402
|
});
|
|
1203
1403
|
let out = "";
|
|
1204
1404
|
const timer = setTimeout(() => {
|
|
@@ -1239,38 +1439,58 @@ async function refineInstallMethod(method, argvPath, npmPrefix = npmGlobalPrefix
|
|
|
1239
1439
|
}
|
|
1240
1440
|
return method;
|
|
1241
1441
|
}
|
|
1442
|
+
var UPGRADE_PACKAGE_SPEC = "@yawlabs/mcp@latest";
|
|
1443
|
+
var UPGRADE_COMMANDS = {
|
|
1444
|
+
"global-npm": { cmd: "npm", args: ["install", "-g", UPGRADE_PACKAGE_SPEC] },
|
|
1445
|
+
"pnpm-global": { cmd: "pnpm", args: ["add", "-g", UPGRADE_PACKAGE_SPEC] },
|
|
1446
|
+
"bun-global": { cmd: "bun", args: ["add", "-g", UPGRADE_PACKAGE_SPEC] },
|
|
1447
|
+
"local-node-modules": { cmd: "npm", args: ["install", UPGRADE_PACKAGE_SPEC] },
|
|
1448
|
+
npx: null,
|
|
1449
|
+
"bundled-app": null,
|
|
1450
|
+
"dev-checkout": null,
|
|
1451
|
+
binary: null,
|
|
1452
|
+
unknown: null
|
|
1453
|
+
};
|
|
1454
|
+
var GLOBAL_UPGRADE_METHODS = ["global-npm", "pnpm-global", "bun-global"];
|
|
1455
|
+
function upgradeSpawnSpec(method, prefixArg = null) {
|
|
1456
|
+
const base = UPGRADE_COMMANDS[method];
|
|
1457
|
+
if (base === null) return null;
|
|
1458
|
+
const args = [...base.args];
|
|
1459
|
+
if (method === "global-npm" && prefixArg !== null) args.splice(args.length - 1, 0, "--prefix", prefixArg);
|
|
1460
|
+
return { cmd: base.cmd, args };
|
|
1461
|
+
}
|
|
1462
|
+
function upgradeCommandLine(method) {
|
|
1463
|
+
const spec = upgradeSpawnSpec(method);
|
|
1464
|
+
return spec === null ? null : [spec.cmd, ...spec.args].join(" ");
|
|
1465
|
+
}
|
|
1466
|
+
var BINARY_RETIRED_HINT = `the standalone-binary track was retired in 0.70.3. Install from npm instead -- \`${upgradeCommandLine("global-npm")}\` -- then delete this executable.`;
|
|
1467
|
+
function globalUpgradeCommandLineForTool(tool) {
|
|
1468
|
+
const method = GLOBAL_UPGRADE_METHODS.find((m) => UPGRADE_COMMANDS[m]?.cmd === tool);
|
|
1469
|
+
return method === void 0 ? null : upgradeCommandLine(method);
|
|
1470
|
+
}
|
|
1242
1471
|
function buildUpgradePlan(input) {
|
|
1243
1472
|
const { current, latest, method } = input;
|
|
1244
1473
|
const stripV = (s) => s.startsWith("v") ? s.slice(1) : s;
|
|
1245
1474
|
const stale = latest !== null && current !== "dev" && compareVersions(stripV(current), stripV(latest)) < 0;
|
|
1246
1475
|
let command;
|
|
1247
1476
|
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
1477
|
case "npx":
|
|
1258
1478
|
command = null;
|
|
1259
1479
|
break;
|
|
1260
1480
|
case "bundled-app":
|
|
1261
1481
|
command = null;
|
|
1262
1482
|
break;
|
|
1263
|
-
case "
|
|
1264
|
-
command =
|
|
1483
|
+
case "binary":
|
|
1484
|
+
command = null;
|
|
1265
1485
|
break;
|
|
1266
1486
|
case "dev-checkout":
|
|
1267
1487
|
command = "git pull && npm run build";
|
|
1268
1488
|
break;
|
|
1269
|
-
case "
|
|
1270
|
-
command =
|
|
1489
|
+
case "unknown":
|
|
1490
|
+
command = upgradeCommandLine("global-npm");
|
|
1271
1491
|
break;
|
|
1272
1492
|
default:
|
|
1273
|
-
command =
|
|
1493
|
+
command = upgradeCommandLine(method);
|
|
1274
1494
|
break;
|
|
1275
1495
|
}
|
|
1276
1496
|
return { current, latest, stale, method, command };
|
|
@@ -1328,12 +1548,21 @@ async function oamFloorLines(probe) {
|
|
|
1328
1548
|
}
|
|
1329
1549
|
async function defaultRunningPrefix(argvPath) {
|
|
1330
1550
|
if (process.env.VITEST) return null;
|
|
1331
|
-
const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-
|
|
1551
|
+
const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-PREISPB3.js");
|
|
1332
1552
|
return detectRunningInstallPrefix2(argvPath);
|
|
1333
1553
|
}
|
|
1334
1554
|
async function defaultSpawn(cmd, args, cwd) {
|
|
1335
1555
|
return new Promise((resolve2) => {
|
|
1336
|
-
const child = spawn2(cmd, args, {
|
|
1556
|
+
const child = spawn2(cmd, args, {
|
|
1557
|
+
stdio: "inherit",
|
|
1558
|
+
shell: process.platform === "win32",
|
|
1559
|
+
cwd,
|
|
1560
|
+
// yaw-mcp's own secrets stay out of the install: npm runs every
|
|
1561
|
+
// dependency's pre/postinstall with this env, and a passphrase parked
|
|
1562
|
+
// in yaw-mcp's env block (where README says to put it) must not reach
|
|
1563
|
+
// them. See internal-secret-env.ts.
|
|
1564
|
+
env: stripInternalSecretsFromEnv(process.env)
|
|
1565
|
+
});
|
|
1337
1566
|
child.on("close", (code) => resolve2(typeof code === "number" ? code : 1));
|
|
1338
1567
|
child.on("error", () => resolve2(1));
|
|
1339
1568
|
});
|
|
@@ -1350,8 +1579,8 @@ async function detectSea() {
|
|
|
1350
1579
|
}
|
|
1351
1580
|
}
|
|
1352
1581
|
async function runUpgrade(opts = {}) {
|
|
1353
|
-
const write = opts.out ?? (
|
|
1354
|
-
const writeErr = opts.err ?? (
|
|
1582
|
+
const write = opts.out ?? createStreamWriter(process.stdout);
|
|
1583
|
+
const writeErr = opts.err ?? createStreamWriter(process.stderr);
|
|
1355
1584
|
const lines = [];
|
|
1356
1585
|
const print = (s = "") => {
|
|
1357
1586
|
lines.push(s);
|
|
@@ -1380,12 +1609,13 @@ async function runUpgrade(opts = {}) {
|
|
|
1380
1609
|
if (method === "global-npm") {
|
|
1381
1610
|
const rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
|
|
1382
1611
|
if (rawPrefix !== null) {
|
|
1383
|
-
const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-
|
|
1612
|
+
const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-PREISPB3.js");
|
|
1384
1613
|
const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
|
|
1385
1614
|
const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
|
|
1386
1615
|
if (spawnForm !== null && displayForm !== null) {
|
|
1387
1616
|
globalPrefixArg = spawnForm;
|
|
1388
|
-
|
|
1617
|
+
const spec2 = upgradeSpawnSpec("global-npm", displayForm);
|
|
1618
|
+
suggestedCommand = spec2 === null ? null : [spec2.cmd, ...spec2.args].join(" ");
|
|
1389
1619
|
}
|
|
1390
1620
|
}
|
|
1391
1621
|
}
|
|
@@ -1404,11 +1634,11 @@ async function runUpgrade(opts = {}) {
|
|
|
1404
1634
|
}
|
|
1405
1635
|
print(` ${suggestedCommand}`);
|
|
1406
1636
|
} else if (method === "bundled-app") {
|
|
1407
|
-
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app
|
|
1637
|
+
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app -- nothing to run.");
|
|
1408
1638
|
} else if (method === "binary") {
|
|
1409
1639
|
print(`yaw-mcp is a standalone binary; ${BINARY_RETIRED_HINT}`);
|
|
1410
1640
|
} else {
|
|
1411
|
-
print("Your install uses `npx -y`
|
|
1641
|
+
print("Your install uses `npx -y` -- just restart the MCP client when you're back online.");
|
|
1412
1642
|
}
|
|
1413
1643
|
for (const line of await oamFloorLines(opts.oamProbe)) print(line);
|
|
1414
1644
|
return { exitCode: 0, lines };
|
|
@@ -1424,33 +1654,22 @@ async function runUpgrade(opts = {}) {
|
|
|
1424
1654
|
}
|
|
1425
1655
|
print("");
|
|
1426
1656
|
if (method === "npx") {
|
|
1427
|
-
print("Your install uses `npx -y`
|
|
1657
|
+
print("Your install uses `npx -y` -- restart the MCP client and it will fetch the new version.");
|
|
1428
1658
|
return { exitCode: 0, lines };
|
|
1429
1659
|
}
|
|
1430
1660
|
if (method === "bundled-app") {
|
|
1431
|
-
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app
|
|
1661
|
+
print("This copy of yaw-mcp ships inside Yaw Terminal and updates with the app --");
|
|
1432
1662
|
print("there is nothing to run here. Update Yaw Terminal to get the new version.");
|
|
1433
1663
|
return { exitCode: 0, lines };
|
|
1434
1664
|
}
|
|
1435
1665
|
if (method === "binary") {
|
|
1436
1666
|
const emit = opts.run ? printErr : print;
|
|
1437
|
-
emit("yaw-mcp is running as a standalone binary
|
|
1667
|
+
emit("yaw-mcp is running as a standalone binary -- manual upgrade required.");
|
|
1438
1668
|
emit(`There's no package manager to upgrade it, and \`--run\` can't automate this: ${BINARY_RETIRED_HINT}`);
|
|
1439
1669
|
return { exitCode: opts.run ? 2 : 1, lines };
|
|
1440
1670
|
}
|
|
1441
|
-
const
|
|
1442
|
-
|
|
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
|
-
);
|
|
1671
|
+
const spec = upgradeSpawnSpec(method, globalPrefixArg);
|
|
1672
|
+
const runSpec = spec === null ? null : method === "local-node-modules" ? installRoot !== null ? { ...spec, cwd: installRoot } : null : spec;
|
|
1454
1673
|
const commandLine = method === "global-npm" ? suggestedCommand : runSpec ? [runSpec.cmd, ...runSpec.args].join(" ") : plan.command;
|
|
1455
1674
|
if (!opts.run) {
|
|
1456
1675
|
if (runSpec) {
|
|
@@ -1485,6 +1704,17 @@ async function runUpgrade(opts = {}) {
|
|
|
1485
1704
|
if (code === 0) {
|
|
1486
1705
|
print("");
|
|
1487
1706
|
print(`OK: Upgraded @yawlabs/mcp to ${latest}`);
|
|
1707
|
+
const pkgDir = runningPackageDir(argvPath);
|
|
1708
|
+
const running = pkgDir === null ? null : await (opts.installedVersion ?? defaultInstalledVersion)(pkgDir);
|
|
1709
|
+
const bare = (s) => s.startsWith("v") ? s.slice(1) : s;
|
|
1710
|
+
if (running !== null && compareVersions(bare(running), bare(latest)) < 0) {
|
|
1711
|
+
printErr("");
|
|
1712
|
+
printErr(`WARNING: the copy this command ran from still reports ${running}, not ${latest}:`);
|
|
1713
|
+
printErr(` ${pkgDir}`);
|
|
1714
|
+
printErr(
|
|
1715
|
+
"The install landed in a different tree, so your MCP client keeps spawning the old version until that tree is upgraded too (for a copy nested under another package's node_modules, upgrade the package that pins it)."
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1488
1718
|
return { exitCode: 0, lines };
|
|
1489
1719
|
}
|
|
1490
1720
|
printErr(`yaw-mcp upgrade: ${runSpec.cmd} exited ${code}. Try running the command yourself:`);
|
|
@@ -1496,7 +1726,7 @@ async function runUpgrade(opts = {}) {
|
|
|
1496
1726
|
return { exitCode: 3, lines };
|
|
1497
1727
|
}
|
|
1498
1728
|
function readCurrentVersion() {
|
|
1499
|
-
return true ? "0.
|
|
1729
|
+
return true ? "1.0.0" : "dev";
|
|
1500
1730
|
}
|
|
1501
1731
|
|
|
1502
1732
|
// src/auto-upgrade.ts
|
|
@@ -1530,19 +1760,34 @@ async function compareWithNpmPrefix(detected, probe = npmGlobalPrefix) {
|
|
|
1530
1760
|
const npmPrefix = await probe();
|
|
1531
1761
|
if (!npmPrefix?.trim()) return;
|
|
1532
1762
|
if (comparablePath(npmPrefix.trim()) === comparablePath(detected)) return;
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
Installing into the running prefix so the upgrade lands in the same tree the client spawned from.
|
|
1538
|
-
`
|
|
1763
|
+
log(
|
|
1764
|
+
"warn",
|
|
1765
|
+
"yaw-mcp self-upgrade: running prefix differs from `npm prefix -g`; installing into the running prefix so the upgrade lands in the tree the client spawned from",
|
|
1766
|
+
{ running: detected, npmPrefix }
|
|
1539
1767
|
);
|
|
1540
1768
|
}
|
|
1541
1769
|
var UPGRADE_LOCK_NAME = ".yaw-mcp-upgrade.lock";
|
|
1542
1770
|
var UPGRADE_LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1543
1771
|
var UPGRADE_LOCK_FUTURE_SKEW_MS = 5 * 1e3;
|
|
1544
|
-
function
|
|
1545
|
-
|
|
1772
|
+
function lockHolderAlive(lockPath) {
|
|
1773
|
+
let pid;
|
|
1774
|
+
try {
|
|
1775
|
+
pid = Number.parseInt(readFileSync3(lockPath, "utf8").trim(), 10);
|
|
1776
|
+
} catch {
|
|
1777
|
+
return true;
|
|
1778
|
+
}
|
|
1779
|
+
if (!Number.isInteger(pid) || pid <= 0) return true;
|
|
1780
|
+
if (pid === process.pid) return true;
|
|
1781
|
+
try {
|
|
1782
|
+
process.kill(pid, 0);
|
|
1783
|
+
return true;
|
|
1784
|
+
} catch (err) {
|
|
1785
|
+
return err.code !== "ESRCH";
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
function acquireUpgradeLock(dir, lockName = UPGRADE_LOCK_NAME, opts = {}) {
|
|
1789
|
+
const lockPath = join4(dir, lockName);
|
|
1790
|
+
const holderAlive = (path2) => opts.probeHolder ? lockHolderAlive(path2) : true;
|
|
1546
1791
|
const mine = String(process.pid);
|
|
1547
1792
|
const take = () => {
|
|
1548
1793
|
try {
|
|
@@ -1558,7 +1803,7 @@ function acquireUpgradeLock(dir, lockName = UPGRADE_LOCK_NAME) {
|
|
|
1558
1803
|
if (released) return;
|
|
1559
1804
|
released = true;
|
|
1560
1805
|
try {
|
|
1561
|
-
if (
|
|
1806
|
+
if (readFileSync3(lockPath, "utf8").trim() !== mine) return;
|
|
1562
1807
|
unlinkSync(lockPath);
|
|
1563
1808
|
} catch {
|
|
1564
1809
|
}
|
|
@@ -1571,17 +1816,47 @@ function acquireUpgradeLock(dir, lockName = UPGRADE_LOCK_NAME) {
|
|
|
1571
1816
|
};
|
|
1572
1817
|
const first = take();
|
|
1573
1818
|
if (first !== void 0) return first;
|
|
1819
|
+
const isLive = (ageMs2) => ageMs2 > -UPGRADE_LOCK_FUTURE_SKEW_MS && ageMs2 < UPGRADE_LOCK_STALE_MS;
|
|
1574
1820
|
let ageMs;
|
|
1575
1821
|
try {
|
|
1576
1822
|
ageMs = Date.now() - statSync2(lockPath).mtimeMs;
|
|
1577
1823
|
} catch {
|
|
1578
1824
|
ageMs = UPGRADE_LOCK_STALE_MS;
|
|
1579
1825
|
}
|
|
1580
|
-
if (ageMs
|
|
1826
|
+
if (isLive(ageMs) && holderAlive(lockPath)) return null;
|
|
1827
|
+
const stolenPath = `${lockPath}.stale-${process.pid}`;
|
|
1581
1828
|
try {
|
|
1582
|
-
|
|
1829
|
+
renameSync(lockPath, stolenPath);
|
|
1583
1830
|
} catch (err) {
|
|
1584
1831
|
if (err.code !== "ENOENT") return null;
|
|
1832
|
+
const retry = take();
|
|
1833
|
+
return retry === void 0 ? null : retry;
|
|
1834
|
+
}
|
|
1835
|
+
let stoleLive = false;
|
|
1836
|
+
try {
|
|
1837
|
+
stoleLive = isLive(Date.now() - statSync2(stolenPath).mtimeMs) && holderAlive(stolenPath);
|
|
1838
|
+
} catch {
|
|
1839
|
+
}
|
|
1840
|
+
if (stoleLive) {
|
|
1841
|
+
try {
|
|
1842
|
+
const holder = readFileSync3(stolenPath, "utf8");
|
|
1843
|
+
const fd = openSync(lockPath, "wx");
|
|
1844
|
+
try {
|
|
1845
|
+
writeSync(fd, holder);
|
|
1846
|
+
} finally {
|
|
1847
|
+
closeSync(fd);
|
|
1848
|
+
}
|
|
1849
|
+
} catch {
|
|
1850
|
+
}
|
|
1851
|
+
try {
|
|
1852
|
+
unlinkSync(stolenPath);
|
|
1853
|
+
} catch {
|
|
1854
|
+
}
|
|
1855
|
+
return null;
|
|
1856
|
+
}
|
|
1857
|
+
try {
|
|
1858
|
+
unlinkSync(stolenPath);
|
|
1859
|
+
} catch {
|
|
1585
1860
|
}
|
|
1586
1861
|
const second = take();
|
|
1587
1862
|
return second === void 0 ? null : second;
|
|
@@ -1593,51 +1868,76 @@ function defaultAcquireLock(dir, lockName) {
|
|
|
1593
1868
|
}
|
|
1594
1869
|
var UPGRADE_CHECK_INTERVAL_MS = 60 * 60 * 1e3;
|
|
1595
1870
|
var UPGRADE_ATTEMPT_COOLDOWN_MS = 6 * 60 * 60 * 1e3;
|
|
1596
|
-
function
|
|
1871
|
+
function readMemo(path2) {
|
|
1597
1872
|
let parsed;
|
|
1598
1873
|
try {
|
|
1599
|
-
parsed = JSON.parse(
|
|
1874
|
+
parsed = JSON.parse(readFileSync3(path2, "utf8"));
|
|
1600
1875
|
} catch {
|
|
1601
1876
|
return null;
|
|
1602
1877
|
}
|
|
1603
1878
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
1604
1879
|
const memo = parsed;
|
|
1605
1880
|
if (typeof memo.at !== "number") return null;
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
return age < -UPGRADE_LOCK_FUTURE_SKEW_MS ? null : age;
|
|
1881
|
+
const ageMs = Date.now() - memo.at;
|
|
1882
|
+
return ageMs < -UPGRADE_LOCK_FUTURE_SKEW_MS ? null : { ageMs, memo };
|
|
1609
1883
|
}
|
|
1610
|
-
function writeMemo(path2,
|
|
1611
|
-
const memo = version === null ? { at: Date.now() } : { at: Date.now(), version };
|
|
1884
|
+
function writeMemo(path2, fields) {
|
|
1612
1885
|
try {
|
|
1613
|
-
writeFileSync(path2, `${JSON.stringify(
|
|
1886
|
+
writeFileSync(path2, `${JSON.stringify({ at: Date.now(), ...fields })}
|
|
1614
1887
|
`);
|
|
1615
1888
|
} catch {
|
|
1616
1889
|
}
|
|
1617
1890
|
}
|
|
1618
1891
|
function checkMemoPath() {
|
|
1619
|
-
return
|
|
1892
|
+
return join4(tmpdir(), `.yaw-mcp-upgrade-check-${process.getuid?.() ?? "win"}.json`);
|
|
1893
|
+
}
|
|
1894
|
+
function readCheckMemo(path2) {
|
|
1895
|
+
const read = readMemo(path2);
|
|
1896
|
+
if (read === null || read.ageMs >= UPGRADE_CHECK_INTERVAL_MS) return null;
|
|
1897
|
+
const latest = read.memo.latest;
|
|
1898
|
+
if (latest !== null && typeof latest !== "string") return null;
|
|
1899
|
+
return { latest };
|
|
1900
|
+
}
|
|
1901
|
+
function writeCheckMemo(path2, latest) {
|
|
1902
|
+
writeMemo(path2, { latest });
|
|
1620
1903
|
}
|
|
1621
1904
|
function attemptMemoPath(dir, lockName) {
|
|
1622
|
-
return
|
|
1905
|
+
return join4(dir, `${lockName}.attempt`);
|
|
1906
|
+
}
|
|
1907
|
+
function attemptMemoFallbackPath(dir, lockName, fallbackDir) {
|
|
1908
|
+
const scope = createHash("sha256").update(`${dir}\0${lockName}`).digest("hex").slice(0, 16);
|
|
1909
|
+
return join4(fallbackDir, `.yaw-mcp-upgrade-attempt-${process.getuid?.() ?? "win"}-${scope}.json`);
|
|
1623
1910
|
}
|
|
1624
1911
|
function defaultCheckedRecently() {
|
|
1625
|
-
if (process.env.VITEST) return
|
|
1626
|
-
|
|
1627
|
-
return age !== null && age < UPGRADE_CHECK_INTERVAL_MS;
|
|
1912
|
+
if (process.env.VITEST) return null;
|
|
1913
|
+
return readCheckMemo(checkMemoPath());
|
|
1628
1914
|
}
|
|
1629
|
-
function defaultRecordCheck() {
|
|
1915
|
+
function defaultRecordCheck(latest) {
|
|
1630
1916
|
if (process.env.VITEST) return;
|
|
1631
|
-
|
|
1917
|
+
writeCheckMemo(checkMemoPath(), latest);
|
|
1632
1918
|
}
|
|
1633
1919
|
function defaultAttemptedRecently(dir, lockName, version) {
|
|
1634
1920
|
if (process.env.VITEST) return false;
|
|
1635
|
-
|
|
1636
|
-
return age !== null && age < UPGRADE_ATTEMPT_COOLDOWN_MS;
|
|
1921
|
+
return attemptedRecentlyAt(dir, lockName, version);
|
|
1637
1922
|
}
|
|
1638
1923
|
function defaultRecordAttempt(dir, lockName, version) {
|
|
1639
1924
|
if (process.env.VITEST) return;
|
|
1640
|
-
|
|
1925
|
+
recordAttemptAt(dir, lockName, version);
|
|
1926
|
+
}
|
|
1927
|
+
function attemptedRecentlyAt(dir, lockName, version, fallbackDir = tmpdir()) {
|
|
1928
|
+
const recent = (read) => read !== null && read.memo.version === version && read.ageMs < UPGRADE_ATTEMPT_COOLDOWN_MS;
|
|
1929
|
+
if (recent(readMemo(attemptMemoPath(dir, lockName)))) return true;
|
|
1930
|
+
return recent(readMemo(attemptMemoFallbackPath(dir, lockName, fallbackDir)));
|
|
1931
|
+
}
|
|
1932
|
+
function recordAttemptAt(dir, lockName, version, fallbackDir = tmpdir()) {
|
|
1933
|
+
const primary = attemptMemoPath(dir, lockName);
|
|
1934
|
+
try {
|
|
1935
|
+
writeFileSync(primary, `${JSON.stringify({ at: Date.now(), version })}
|
|
1936
|
+
`);
|
|
1937
|
+
return;
|
|
1938
|
+
} catch {
|
|
1939
|
+
}
|
|
1940
|
+
writeMemo(attemptMemoFallbackPath(dir, lockName, fallbackDir), { version });
|
|
1641
1941
|
}
|
|
1642
1942
|
function defaultSpawn2(cmd, args, onDone = () => {
|
|
1643
1943
|
}) {
|
|
@@ -1648,9 +1948,17 @@ function defaultSpawn2(cmd, args, onDone = () => {
|
|
|
1648
1948
|
released = true;
|
|
1649
1949
|
onDone();
|
|
1650
1950
|
};
|
|
1651
|
-
const correctiveCmd = cmd
|
|
1951
|
+
const correctiveCmd = globalUpgradeCommandLineForTool(cmd);
|
|
1652
1952
|
const child = spawn3(cmd, args, {
|
|
1653
1953
|
stdio: "ignore",
|
|
1954
|
+
// yaw-mcp's own secrets stay out of the install. npm runs every
|
|
1955
|
+
// dependency's pre/postinstall with this env, and README tells the user to
|
|
1956
|
+
// put YAW_MCP_VAULT_PASSPHRASE in yaw-mcp's env block precisely because
|
|
1957
|
+
// "yaw-mcp strips its own secrets from every child env" -- a promise the
|
|
1958
|
+
// upstream spawn kept and this one, spawning with the full inherited
|
|
1959
|
+
// process.env, silently did not: a compromised transitive dependency's
|
|
1960
|
+
// install script plus ~/.yaw-mcp/secrets.json was the whole vault.
|
|
1961
|
+
env: stripInternalSecretsFromEnv(process.env),
|
|
1654
1962
|
// Not detached, so the install shares yaw-mcp's process group and an MCP
|
|
1655
1963
|
// client that tears down the whole tree takes it with it. Two things this
|
|
1656
1964
|
// does NOT buy (the file header lists both as known gaps): on POSIX a
|
|
@@ -1668,9 +1976,10 @@ function defaultSpawn2(cmd, args, onDone = () => {
|
|
|
1668
1976
|
log("info", "yaw-mcp self-upgrade complete; the next client restart will run the new version");
|
|
1669
1977
|
} else {
|
|
1670
1978
|
const hint = cmd === "npm" ? " (often EACCES on a sudo-installed global -- run with the right permissions)" : "";
|
|
1979
|
+
const manual = correctiveCmd === null ? "Set" : `Run \`${correctiveCmd}\` manually, or set`;
|
|
1671
1980
|
log(
|
|
1672
1981
|
"warn",
|
|
1673
|
-
`yaw-mcp self-upgrade: ${cmd} exited non-zero${hint}.
|
|
1982
|
+
`yaw-mcp self-upgrade: ${cmd} exited non-zero${hint}. ${manual} YAW_MCP_AUTO_UPGRADE=0 to silence this.`,
|
|
1674
1983
|
{ code }
|
|
1675
1984
|
);
|
|
1676
1985
|
}
|
|
@@ -1681,36 +1990,27 @@ function defaultSpawn2(cmd, args, onDone = () => {
|
|
|
1681
1990
|
log("warn", `yaw-mcp self-upgrade: ${cmd} spawn failed`, { error: err?.message });
|
|
1682
1991
|
});
|
|
1683
1992
|
}
|
|
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
1993
|
async function maybeAutoUpgrade(deps = {}) {
|
|
1696
1994
|
const optOut = process.env.YAW_MCP_AUTO_UPGRADE;
|
|
1697
1995
|
if (optOut === "0" || optOut?.toLowerCase() === "false") return;
|
|
1698
|
-
const current = deps.currentVersion ?? (true ? "0.
|
|
1996
|
+
const current = deps.currentVersion ?? (true ? "1.0.0" : "dev");
|
|
1699
1997
|
if (current === "dev") return;
|
|
1700
1998
|
const argvPath = deps.argvPath ?? process.argv[1];
|
|
1701
|
-
const method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" :
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
(
|
|
1999
|
+
const method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync2, ["unknown", "local-node-modules"]);
|
|
2000
|
+
const cached = (deps.checkedRecentlyImpl ?? defaultCheckedRecently)();
|
|
2001
|
+
let latest;
|
|
2002
|
+
if (cached !== null) {
|
|
2003
|
+
latest = cached.latest;
|
|
2004
|
+
} else {
|
|
2005
|
+
latest = await (deps.fetchLatestImpl ?? fetchLatestVersion)();
|
|
2006
|
+
(deps.recordCheckImpl ?? defaultRecordCheck)(latest);
|
|
2007
|
+
}
|
|
1705
2008
|
if (latest === null) return;
|
|
1706
2009
|
const plan = buildUpgradePlan({ current, latest, method });
|
|
1707
2010
|
if (!plan.stale) return;
|
|
1708
2011
|
const rawPrefix = method === "global-npm" ? detectRunningInstallPrefix(argvPath) : null;
|
|
1709
2012
|
const quotedPrefix = rawPrefix === null ? null : quoteShellArgIfNeeded(rawPrefix);
|
|
1710
|
-
const globalSpec = method
|
|
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;
|
|
2013
|
+
const globalSpec = GLOBAL_UPGRADE_METHODS.includes(method) ? upgradeSpawnSpec(method, quotedPrefix) : null;
|
|
1714
2014
|
if (globalSpec) {
|
|
1715
2015
|
const lockDir = rawPrefix ?? tmpdir();
|
|
1716
2016
|
const lockName = rawPrefix === null ? `.yaw-mcp-upgrade-${globalSpec.cmd}-${process.getuid?.() ?? "win"}.lock` : UPGRADE_LOCK_NAME;
|
|
@@ -1744,7 +2044,8 @@ async function maybeAutoUpgrade(deps = {}) {
|
|
|
1744
2044
|
prefix: quotedPrefix === null ? void 0 : rawPrefix ?? void 0
|
|
1745
2045
|
});
|
|
1746
2046
|
if (method === "global-npm" && rawPrefix !== null && quotedPrefix !== null) {
|
|
1747
|
-
|
|
2047
|
+
compareWithNpmPrefix(rawPrefix, deps.npmPrefixImpl).catch(() => {
|
|
2048
|
+
});
|
|
1748
2049
|
}
|
|
1749
2050
|
(deps.recordAttemptImpl ?? defaultRecordAttempt)(lockDir, lockName, latest);
|
|
1750
2051
|
try {
|
|
@@ -1799,12 +2100,18 @@ async function maybeAutoUpgrade(deps = {}) {
|
|
|
1799
2100
|
}
|
|
1800
2101
|
|
|
1801
2102
|
export {
|
|
2103
|
+
INTERNAL_SECRET_ENV_KEYS,
|
|
2104
|
+
scrubInternalSecretsFromProcessEnv,
|
|
2105
|
+
stripInternalSecretsFromEnv,
|
|
2106
|
+
setLogSurface,
|
|
1802
2107
|
log,
|
|
2108
|
+
createStreamWriter,
|
|
1803
2109
|
cacheDir,
|
|
1804
2110
|
CONFIG_DIRNAME,
|
|
1805
2111
|
sidecarsRoot,
|
|
1806
2112
|
sidecarsNodeModules,
|
|
1807
2113
|
userConfigDir,
|
|
2114
|
+
normalizeForCompare,
|
|
1808
2115
|
realpathOrSelf,
|
|
1809
2116
|
isUnderHome,
|
|
1810
2117
|
ALLOW_UNOWNED_ENV,
|
|
@@ -1840,10 +2147,10 @@ export {
|
|
|
1840
2147
|
resolveOamSpawn,
|
|
1841
2148
|
isOamCommand,
|
|
1842
2149
|
isOamLaunch,
|
|
1843
|
-
BINARY_RETIRED_HINT,
|
|
1844
2150
|
parseUpgradeArgs,
|
|
1845
2151
|
detectInstallMethod,
|
|
1846
2152
|
refineInstallMethod,
|
|
2153
|
+
BINARY_RETIRED_HINT,
|
|
1847
2154
|
buildUpgradePlan,
|
|
1848
2155
|
fetchLatestVersion,
|
|
1849
2156
|
detectSea,
|
|
@@ -1852,5 +2159,9 @@ export {
|
|
|
1852
2159
|
quoteArgForDisplay,
|
|
1853
2160
|
detectRunningInstallPrefix,
|
|
1854
2161
|
acquireUpgradeLock,
|
|
2162
|
+
readCheckMemo,
|
|
2163
|
+
writeCheckMemo,
|
|
2164
|
+
attemptedRecentlyAt,
|
|
2165
|
+
recordAttemptAt,
|
|
1855
2166
|
maybeAutoUpgrade
|
|
1856
2167
|
};
|