@yawlabs/mcp 1.1.9 → 1.1.11
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 +127 -5
- package/README.md +33 -21
- package/dist/{auto-upgrade-RGWSTKNN.js → auto-upgrade-QWLYCX74.js} +7 -1
- package/dist/{chunk-NYVP3NOV.js → chunk-FJ5PPHDD.js} +353 -144
- package/dist/{chunk-PPQ2SHCU.js → chunk-VG7NPV2A.js} +391 -150
- package/dist/{git-source-ROCB3T3U.js → git-source-XOJY3JWD.js} +12 -2
- package/dist/index.js +1859 -1046
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
cacheDir,
|
|
9
9
|
compareVersions,
|
|
10
10
|
createStreamWriter,
|
|
11
|
+
describeNodeFlagRefusal,
|
|
11
12
|
editJsoncPath,
|
|
12
13
|
findProjectConfigDir,
|
|
13
14
|
gitBuildDir,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
gitRoot,
|
|
16
17
|
isFeatureEnabled,
|
|
17
18
|
isRegistrySpec,
|
|
19
|
+
launcherBasename,
|
|
18
20
|
log,
|
|
19
21
|
managedNodeBin,
|
|
20
22
|
nodeLaunchKind,
|
|
@@ -31,6 +33,7 @@ import {
|
|
|
31
33
|
resolveManagedSpawn,
|
|
32
34
|
resolveNonNegativeIntEnv,
|
|
33
35
|
resolveOamSpawn,
|
|
36
|
+
scanNodeLaunchFlags,
|
|
34
37
|
setJsonKey,
|
|
35
38
|
sidecarsNodeModules,
|
|
36
39
|
sidecarsRoot,
|
|
@@ -39,7 +42,7 @@ import {
|
|
|
39
42
|
stripJsoncComments,
|
|
40
43
|
stripTrailingCommas,
|
|
41
44
|
userConfigDir
|
|
42
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-FJ5PPHDD.js";
|
|
43
46
|
|
|
44
47
|
// src/git-source.ts
|
|
45
48
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -59,6 +62,14 @@ import {
|
|
|
59
62
|
} from "fs";
|
|
60
63
|
import { dirname as dirname4, isAbsolute, join as join7, relative as relative2, resolve as resolve3 } from "path";
|
|
61
64
|
|
|
65
|
+
// src/ascii.ts
|
|
66
|
+
function printable(s) {
|
|
67
|
+
return s.replace(/[^\x20-\x7e]/g, "?");
|
|
68
|
+
}
|
|
69
|
+
function asciiLines(text) {
|
|
70
|
+
return text.replace(/\r\n/g, "\n").replace(/[^\x20-\x7e\n]/g, "?");
|
|
71
|
+
}
|
|
72
|
+
|
|
62
73
|
// src/fuzzy.ts
|
|
63
74
|
function levenshtein(a, b) {
|
|
64
75
|
if (a === b) return 0;
|
|
@@ -292,6 +303,24 @@ async function defaultFetchCatalog(catalogUrl = DEFAULT_CATALOG_URL, deps = {})
|
|
|
292
303
|
function withWarnSink(warn) {
|
|
293
304
|
return (url) => defaultFetchCatalog(url, warn ? { warn } : {});
|
|
294
305
|
}
|
|
306
|
+
function isRemoteCatalogEntry(entry) {
|
|
307
|
+
const install = entry.install ?? {};
|
|
308
|
+
const runtime = typeof install.runtime === "string" ? install.runtime.toLowerCase() : "";
|
|
309
|
+
return Boolean(install.url) || install.type === "remote" || /^(remote|https?|sse|url)$/.test(runtime);
|
|
310
|
+
}
|
|
311
|
+
function catalogEnvKeys(entry) {
|
|
312
|
+
const required = [];
|
|
313
|
+
const optional = [];
|
|
314
|
+
const raw = entry.requiredEnv;
|
|
315
|
+
if (Array.isArray(raw)) {
|
|
316
|
+
for (const e of raw) {
|
|
317
|
+
const key = e && typeof e === "object" ? e.key : void 0;
|
|
318
|
+
if (typeof key !== "string" || !ENV_KEY_RE.test(key)) continue;
|
|
319
|
+
(e.optional === true ? optional : required).push(key);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return { required, optional: optional.filter((k) => !required.includes(k)) };
|
|
323
|
+
}
|
|
295
324
|
async function resolveCatalogSlug(slug, opts = {}) {
|
|
296
325
|
const url = normalizeCatalogUrl(opts.catalogUrl);
|
|
297
326
|
const fetchCatalog = opts.fetchCatalog ?? withWarnSink(opts.warn);
|
|
@@ -303,8 +332,7 @@ async function resolveCatalogSlug(slug, opts = {}) {
|
|
|
303
332
|
throw new Error(`no server with slug "${slug}" in the Yaw MCP catalog.${hint}`);
|
|
304
333
|
}
|
|
305
334
|
const install = entry.install ?? {};
|
|
306
|
-
|
|
307
|
-
if (install.url || install.type === "remote" || /^(remote|https?|sse|url)$/.test(runtime)) {
|
|
335
|
+
if (isRemoteCatalogEntry(entry)) {
|
|
308
336
|
throw new Error(
|
|
309
337
|
`"${slug}" is a remote (HTTP) server, which has no stdio command to spawn. Add it by hand to ~/.yaw-mcp/bundles.json with "type": "remote", its "url", and a "headers" block for any auth token (values may use \${secret:NAME}).`
|
|
310
338
|
);
|
|
@@ -318,16 +346,7 @@ async function resolveCatalogSlug(slug, opts = {}) {
|
|
|
318
346
|
if (!command) {
|
|
319
347
|
throw new Error(`catalog entry "${slug}" install command was empty.`);
|
|
320
348
|
}
|
|
321
|
-
const requiredEnvKeys =
|
|
322
|
-
const optionalEnvKeys = [];
|
|
323
|
-
if (Array.isArray(entry.requiredEnv)) {
|
|
324
|
-
for (const e of entry.requiredEnv) {
|
|
325
|
-
const key = e && typeof e === "object" ? e.key : void 0;
|
|
326
|
-
if (typeof key !== "string" || !ENV_KEY_RE.test(key)) continue;
|
|
327
|
-
(e.optional === true ? optionalEnvKeys : requiredEnvKeys).push(key);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
const optionalOnly = optionalEnvKeys.filter((k) => !requiredEnvKeys.includes(k));
|
|
349
|
+
const { required: requiredEnvKeys, optional: optionalOnly } = catalogEnvKeys(entry);
|
|
331
350
|
const source = typeof entry.repo === "string" ? entry.repo : typeof entry.homepage === "string" ? entry.homepage : void 0;
|
|
332
351
|
return {
|
|
333
352
|
slug,
|
|
@@ -1155,7 +1174,7 @@ var GIT_COMMIT_RE = /^[0-9a-f]{40}$/;
|
|
|
1155
1174
|
function hasControlChar(s) {
|
|
1156
1175
|
for (let i = 0; i < s.length; i++) {
|
|
1157
1176
|
const c = s.charCodeAt(i);
|
|
1158
|
-
if (c < 32 || c
|
|
1177
|
+
if (c < 32 || c >= 127 && c <= 159) return true;
|
|
1159
1178
|
}
|
|
1160
1179
|
return false;
|
|
1161
1180
|
}
|
|
@@ -1474,6 +1493,9 @@ function previewBundlesContent(path2, rawBytes, home = homedir3()) {
|
|
|
1474
1493
|
}
|
|
1475
1494
|
return { ok: true, servers, warnings };
|
|
1476
1495
|
}
|
|
1496
|
+
function rawEntryLoads(entry, home = homedir3()) {
|
|
1497
|
+
return validateEntry(entry, [], home) !== null;
|
|
1498
|
+
}
|
|
1477
1499
|
function hashContent(servers) {
|
|
1478
1500
|
const h = createHash2("sha256");
|
|
1479
1501
|
h.update(JSON.stringify(servers));
|
|
@@ -1704,12 +1726,12 @@ async function readRawUserBundles(home, warnings, path2 = localBundlesPath(userC
|
|
|
1704
1726
|
const readWarning = warnings.find((w) => w.startsWith(`${path2}: ${READ_FAILURE_MARKER}`));
|
|
1705
1727
|
if (readWarning) {
|
|
1706
1728
|
if (readWarning.includes(IS_A_DIRECTORY_DETAIL)) {
|
|
1707
|
-
throw new Error(`${path2} is a directory, not a file -- move or remove it
|
|
1729
|
+
throw new Error(`${path2} is a directory, not a file -- move or remove it first.`);
|
|
1708
1730
|
}
|
|
1709
|
-
throw new Error(`${path2} could not be read (${warningText}) -- check file permissions
|
|
1731
|
+
throw new Error(`${path2} could not be read (${warningText}) -- check file permissions first.`);
|
|
1710
1732
|
}
|
|
1711
1733
|
const detail = warnings.length > 0 ? ` (${warningText})` : "";
|
|
1712
|
-
throw new Error(`${path2} could not be parsed -- fix the JSON${detail}
|
|
1734
|
+
throw new Error(`${path2} could not be parsed -- fix the JSON${detail} first.`);
|
|
1713
1735
|
}
|
|
1714
1736
|
for (const w of warnings) {
|
|
1715
1737
|
log("debug", "bundles.json warning (write path)", { warning: w });
|
|
@@ -1785,7 +1807,8 @@ function launchShapeOf(entry) {
|
|
|
1785
1807
|
return typeof entry.url === "string" && entry.url.length > 0 ? { url: entry.url } : {};
|
|
1786
1808
|
}
|
|
1787
1809
|
function sameLaunch(a, b) {
|
|
1788
|
-
|
|
1810
|
+
const dir = (s) => relativeSegments(s.git?.subdir ?? "").join("/");
|
|
1811
|
+
return a.command === b.command && a.url === b.url && JSON.stringify(a.args ?? []) === JSON.stringify(b.args ?? []) && a.git?.url === b.git?.url && dir(a) === dir(b);
|
|
1789
1812
|
}
|
|
1790
1813
|
function formatBundleCollision(c, safe = (s) => s) {
|
|
1791
1814
|
const what = c.origin === "catalog" ? "catalog server" : "server";
|
|
@@ -1849,7 +1872,11 @@ function resolveUpsertTarget(servers, entry, origin) {
|
|
|
1849
1872
|
};
|
|
1850
1873
|
}
|
|
1851
1874
|
function mergedUpsertEntry(servers, entry, target) {
|
|
1852
|
-
if (target.idx < 0)
|
|
1875
|
+
if (target.idx < 0) {
|
|
1876
|
+
const fresh = { ...entry };
|
|
1877
|
+
if (Array.isArray(fresh.optionalEnvKeys) && fresh.optionalEnvKeys.length === 0) delete fresh.optionalEnvKeys;
|
|
1878
|
+
return fresh;
|
|
1879
|
+
}
|
|
1853
1880
|
const written = mergeServerEntry(servers[target.idx] ?? {}, entry);
|
|
1854
1881
|
if (target.matchedByNamespace) return written;
|
|
1855
1882
|
return { ...written, namespace: target.namespace ?? written.namespace, id: target.id ?? written.id };
|
|
@@ -2088,11 +2115,10 @@ async function resolveBundlesDefault(opts) {
|
|
|
2088
2115
|
function describeLaunchShape(command, args) {
|
|
2089
2116
|
const kind = nodeLaunchKind(command);
|
|
2090
2117
|
if (kind === "node") {
|
|
2091
|
-
const
|
|
2092
|
-
if (
|
|
2093
|
-
if (
|
|
2094
|
-
return { code: "node-flag-entry", detail:
|
|
2095
|
-
}
|
|
2118
|
+
const scan = scanNodeLaunchFlags(args);
|
|
2119
|
+
if (scan.kind === "no-entry") return { code: "node-no-entry", detail: "the node launch names no entry file" };
|
|
2120
|
+
if (scan.kind === "refused")
|
|
2121
|
+
return { code: "node-flag-entry", detail: describeNodeFlagRefusal(scan.flag, scan.why) };
|
|
2096
2122
|
return null;
|
|
2097
2123
|
}
|
|
2098
2124
|
if (kind === "npx") {
|
|
@@ -2168,8 +2194,13 @@ function describeServerRuntime(server, configDefault, probe) {
|
|
|
2168
2194
|
// src/readline-question.ts
|
|
2169
2195
|
import { createInterface } from "readline/promises";
|
|
2170
2196
|
var QUESTION_CANCELLED = /* @__PURE__ */ Symbol("yaw-mcp:question-cancelled");
|
|
2197
|
+
var QUESTION_EOF = /* @__PURE__ */ Symbol("yaw-mcp:question-eof");
|
|
2171
2198
|
async function questionOrEmpty(rl, prompt) {
|
|
2172
|
-
|
|
2199
|
+
const answer = await questionOrEof(rl, prompt);
|
|
2200
|
+
return answer === QUESTION_EOF ? "" : answer;
|
|
2201
|
+
}
|
|
2202
|
+
async function questionOrEof(rl, prompt) {
|
|
2203
|
+
if (rl.closed === true) return QUESTION_EOF;
|
|
2173
2204
|
const ac = new AbortController();
|
|
2174
2205
|
let cancelled = false;
|
|
2175
2206
|
const onClose = () => ac.abort();
|
|
@@ -2183,7 +2214,7 @@ async function questionOrEmpty(rl, prompt) {
|
|
|
2183
2214
|
return await rl.question(prompt, { signal: ac.signal });
|
|
2184
2215
|
} catch (err) {
|
|
2185
2216
|
if (cancelled) return QUESTION_CANCELLED;
|
|
2186
|
-
if (ac.signal.aborted) return
|
|
2217
|
+
if (ac.signal.aborted) return QUESTION_EOF;
|
|
2187
2218
|
throw err;
|
|
2188
2219
|
} finally {
|
|
2189
2220
|
rl.off("close", onClose);
|
|
@@ -2193,7 +2224,7 @@ async function questionOrEmpty(rl, prompt) {
|
|
|
2193
2224
|
async function readlineAnswer(input, output, question, terminal) {
|
|
2194
2225
|
const rl = createInterface({ input, output, terminal });
|
|
2195
2226
|
try {
|
|
2196
|
-
return await
|
|
2227
|
+
return await questionOrEof(rl, question);
|
|
2197
2228
|
} finally {
|
|
2198
2229
|
rl.close();
|
|
2199
2230
|
}
|
|
@@ -2203,7 +2234,18 @@ async function askYesNo(opts, question, read = readlineAnswer) {
|
|
|
2203
2234
|
const input = opts.io?.stdin ?? process.stdin;
|
|
2204
2235
|
const output = opts.io?.stdout ?? process.stdout;
|
|
2205
2236
|
const raw = await read(input, output, question, opts.io?.terminal);
|
|
2206
|
-
return raw ===
|
|
2237
|
+
return typeof raw === "string" ? raw.trim().toLowerCase() : raw;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
// src/git-consent-prompt.ts
|
|
2241
|
+
var SCRIPT_CONSENT_QUESTION = "Proceed? [Y/n] ";
|
|
2242
|
+
function scriptConsentConfirm(opts, print, read) {
|
|
2243
|
+
return async (lines) => {
|
|
2244
|
+
for (const l of lines) print(l);
|
|
2245
|
+
const answer = await askYesNo(opts, SCRIPT_CONSENT_QUESTION, read);
|
|
2246
|
+
if (answer === QUESTION_CANCELLED) return "cancelled";
|
|
2247
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
2248
|
+
};
|
|
2207
2249
|
}
|
|
2208
2250
|
|
|
2209
2251
|
// src/sidecars-cmd.ts
|
|
@@ -2404,8 +2446,9 @@ var SIDECARS_USAGE = `Usage: yaw-mcp sidecars install [--yes] [--json]
|
|
|
2404
2446
|
so they run from one known version instead of whatever npm's npx cache
|
|
2405
2447
|
happens to hold.
|
|
2406
2448
|
|
|
2407
|
-
Worth running
|
|
2408
|
-
disk
|
|
2449
|
+
Worth running on either runtime: yaw-mcp starts an npx server from a copy
|
|
2450
|
+
already on disk -- on oam, or with node when oam is not hosting it -- and
|
|
2451
|
+
that cannot re-resolve "@latest" the way npx did, so without a managed
|
|
2409
2452
|
install a server stays pinned at whatever was last fetched. Re-run this to
|
|
2410
2453
|
move them forward.
|
|
2411
2454
|
|
|
@@ -2421,7 +2464,12 @@ var SIDECARS_USAGE = `Usage: yaw-mcp sidecars install [--yes] [--json]
|
|
|
2421
2464
|
--yes, -y Allow a git repo's install and build scripts to run. Asked once
|
|
2422
2465
|
per repo; when stdin or stdout is not a TTY, required until the
|
|
2423
2466
|
repo is allowed here. Recorded per repo in
|
|
2424
|
-
~/.yaw-mcp/git/consent.json
|
|
2467
|
+
~/.yaw-mcp/git/consent.json. Ctrl+C at that question ends the
|
|
2468
|
+
run with exit 130; nothing after it is built or installed.
|
|
2469
|
+
--json Print one JSON document on stdout instead of the text report,
|
|
2470
|
+
with the same keys on every run: root, installed, reason, error,
|
|
2471
|
+
updateError, markerError, unhosted, conflicts, skipped, git.
|
|
2472
|
+
"error" is null on a clean run.`;
|
|
2425
2473
|
function parseSidecarsArgs(argv) {
|
|
2426
2474
|
let json = false;
|
|
2427
2475
|
let yes = false;
|
|
@@ -2494,11 +2542,8 @@ function buildGitEntriesFor(servers, bundlesPath, opts, home, print, printErr) {
|
|
|
2494
2542
|
platform: opts.platform,
|
|
2495
2543
|
progress: (l) => print(l),
|
|
2496
2544
|
warn: (w) => printErr(`warning: ${w}`),
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
const answer = await askYesNo(opts, "Proceed? [Y/n] ");
|
|
2500
|
-
return answer === "" || answer === "y" || answer === "yes";
|
|
2501
|
-
},
|
|
2545
|
+
// Ctrl+C there ends the run with exit 130 (runSidecarsInstall).
|
|
2546
|
+
confirm: scriptConsentConfirm(opts, print),
|
|
2502
2547
|
runPm: opts.runPm
|
|
2503
2548
|
},
|
|
2504
2549
|
bundlesPath !== null && bundlesPath !== localBundlesPath(userConfigDir(home)),
|
|
@@ -2545,10 +2590,11 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2545
2590
|
...over,
|
|
2546
2591
|
error: over.error ?? gitError
|
|
2547
2592
|
});
|
|
2548
|
-
const done = (exitCode, installed = []) => ({
|
|
2593
|
+
const done = (exitCode, installed = [], updateError = null) => ({
|
|
2549
2594
|
exitCode: exitCode === 0 && gitBad + gitUnconsented > 0 ? 1 : exitCode,
|
|
2550
2595
|
installed,
|
|
2551
|
-
lines
|
|
2596
|
+
lines,
|
|
2597
|
+
updateError
|
|
2552
2598
|
});
|
|
2553
2599
|
const couldNotPrepare = (err) => {
|
|
2554
2600
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -2581,21 +2627,31 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2581
2627
|
return done(1);
|
|
2582
2628
|
}
|
|
2583
2629
|
}
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
print("Git sources:");
|
|
2594
|
-
for (const g of git) {
|
|
2595
|
-
print(` ${g.namespace} ${g.commit ? g.commit.slice(0, 12) : "(no commit)"} ${g.status}`);
|
|
2596
|
-
if (g.error) for (const l of g.error.split("\n")) print(` ${l}`);
|
|
2630
|
+
try {
|
|
2631
|
+
git = opts.buildGit === false ? [] : await buildGitEntriesFor(servers, bundles.path, opts, home, print, printErr);
|
|
2632
|
+
if (git.length > 0) {
|
|
2633
|
+
print("Git sources:");
|
|
2634
|
+
for (const g of git) {
|
|
2635
|
+
print(` ${g.namespace} ${g.commit ? g.commit.slice(0, 12) : "(no commit)"} ${g.status}`);
|
|
2636
|
+
if (g.error) for (const l of g.error.split("\n")) print(` ${l}`);
|
|
2637
|
+
}
|
|
2638
|
+
print();
|
|
2597
2639
|
}
|
|
2598
|
-
|
|
2640
|
+
if (git.some((g) => g.status === "cancelled")) {
|
|
2641
|
+
release?.();
|
|
2642
|
+
printErr("yaw-mcp sidecars: Cancelled. Nothing more was built or installed.");
|
|
2643
|
+
return { exitCode: 130, installed: [], lines, updateError: null };
|
|
2644
|
+
}
|
|
2645
|
+
gitBad = git.filter((g) => g.status === "failed" || g.status === "refused").length;
|
|
2646
|
+
gitUnconsented = git.filter((g) => g.status === "needs-consent").length;
|
|
2647
|
+
const gitProblems = [
|
|
2648
|
+
...gitBad > 0 ? [`${gitBad} git source(s) did not build`] : [],
|
|
2649
|
+
...gitUnconsented > 0 ? [`${gitUnconsented} git source(s) were not built: their repo's scripts need consent (re-run with --yes)`] : []
|
|
2650
|
+
];
|
|
2651
|
+
gitError = gitProblems.length > 0 ? gitProblems.join("; ") : null;
|
|
2652
|
+
} catch (err) {
|
|
2653
|
+
release?.();
|
|
2654
|
+
throw err;
|
|
2599
2655
|
}
|
|
2600
2656
|
if (specs.length === 0) {
|
|
2601
2657
|
if (bundles.config === null && bundles.path !== null) {
|
|
@@ -2687,33 +2743,39 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2687
2743
|
namespaces: s.namespaces
|
|
2688
2744
|
}));
|
|
2689
2745
|
const missing = installed.filter((i) => i.version === null);
|
|
2746
|
+
const nothingLanded = missing.length === installed.length;
|
|
2690
2747
|
print("Installed:");
|
|
2691
2748
|
for (const i of installed) print(` ${i.pkg} ${i.version ?? "NOT FOUND"}`);
|
|
2692
|
-
if (
|
|
2749
|
+
if (nothingLanded) {
|
|
2750
|
+
print();
|
|
2751
|
+
print("npm exited 0 but none of these packages resolved in the managed tree -- nothing was installed.");
|
|
2752
|
+
print("Servers keep resolving from the npx cache.");
|
|
2753
|
+
} else if (missing.length > 0) {
|
|
2693
2754
|
print();
|
|
2694
2755
|
print(`${missing.length} package(s) did not land; those servers keep resolving from the npx cache.`);
|
|
2695
2756
|
}
|
|
2696
|
-
if (updateError !== null) {
|
|
2757
|
+
if (updateError !== null && !nothingLanded) {
|
|
2697
2758
|
print();
|
|
2698
2759
|
print(`npm update failed (exit ${updateCode}). The installed copies are usable, but a server`);
|
|
2699
2760
|
print('configured "@latest" may still be on the version it was already on.');
|
|
2700
2761
|
}
|
|
2701
|
-
|
|
2702
|
-
|
|
2762
|
+
if (!nothingLanded) {
|
|
2763
|
+
print();
|
|
2764
|
+
print("These versions are now fixed. Re-run this command to move them forward.");
|
|
2765
|
+
}
|
|
2703
2766
|
const unhosted = await unhostedReasons(servers, opts, home, bundles);
|
|
2704
|
-
if (unhosted.length > 0) {
|
|
2767
|
+
if (unhosted.length > 0 && !nothingLanded) {
|
|
2705
2768
|
print();
|
|
2706
|
-
print("
|
|
2769
|
+
print("None of these servers will be hosted on oam:");
|
|
2707
2770
|
for (const reason of unhosted) print(` ${reason}`);
|
|
2708
|
-
print("
|
|
2709
|
-
print("
|
|
2771
|
+
print("They still start from these copies: yaw-mcp runs each one with node instead,");
|
|
2772
|
+
print("and falls back to npx only when it cannot.");
|
|
2710
2773
|
}
|
|
2711
|
-
const nothingLanded = missing.length === installed.length;
|
|
2712
2774
|
const error = nothingLanded ? "npm exited 0 but no requested package resolved in the managed tree" : null;
|
|
2713
2775
|
if (opts.json) {
|
|
2714
2776
|
write(doc({ installed, conflicts, skipped, error, updateError, unhosted, markerError }));
|
|
2715
2777
|
}
|
|
2716
|
-
return done(nothingLanded ? 1 : 0, installed);
|
|
2778
|
+
return done(nothingLanded ? 1 : 0, installed, updateError);
|
|
2717
2779
|
} finally {
|
|
2718
2780
|
release?.();
|
|
2719
2781
|
}
|
|
@@ -2752,8 +2814,13 @@ var SEP = "(?:[^\\S\\r\\n]*:\\s+|[^\\S\\r\\n]+)";
|
|
|
2752
2814
|
var QUOTE = "[\"'`]?";
|
|
2753
2815
|
var ENV_WORDS = `(?:(?:env|environment)${GAP})?(?:(?:variable|var)${GAP})?`;
|
|
2754
2816
|
var LEADING_ENV_WORDS = `(?:(?:env|environment)${SEP})?(?:(?:variables?|vars?)${SEP})?`;
|
|
2817
|
+
var LEADING_CREDENTIAL_NOUN = `(?:api(?:${GAP}|-)?keys?|tokens?|credentials?|secrets?)${SEP}`;
|
|
2755
2818
|
var MISSING_PATTERNS = [
|
|
2756
2819
|
new RegExp(`\\bmissing${SEP}(?:required${GAP})?${LEADING_ENV_WORDS}${QUOTE}(${NAME})\\b`, "gi"),
|
|
2820
|
+
new RegExp(
|
|
2821
|
+
`\\bmissing${SEP}(?:required${GAP})?${LEADING_ENV_WORDS}${LEADING_CREDENTIAL_NOUN}${QUOTE}(${NAME})\\b`,
|
|
2822
|
+
"gi"
|
|
2823
|
+
),
|
|
2757
2824
|
new RegExp(
|
|
2758
2825
|
`\\b(${NAME})${QUOTE}${GAP}${ENV_WORDS}(?:is${GAP}(?:required|missing|empty|undefined)|(?:is${GAP})?(?:not${GAP}set|unset|not${GAP}provided))\\b`,
|
|
2759
2826
|
"gi"
|
|
@@ -2952,7 +3019,10 @@ function resolveMaxResultBytes(env = process.env) {
|
|
|
2952
3019
|
}
|
|
2953
3020
|
function cutToBytes(text, maxBytes) {
|
|
2954
3021
|
if (maxBytes <= 0) return "";
|
|
2955
|
-
|
|
3022
|
+
return cutEncodedToBytes(text, Buffer.from(text, "utf8"), maxBytes);
|
|
3023
|
+
}
|
|
3024
|
+
function cutEncodedToBytes(text, buf, maxBytes) {
|
|
3025
|
+
if (maxBytes <= 0) return "";
|
|
2956
3026
|
if (buf.byteLength <= maxBytes) return text;
|
|
2957
3027
|
const cut = buf.subarray(0, maxBytes).toString("utf8");
|
|
2958
3028
|
if (!cut.endsWith("\uFFFD")) return cut;
|
|
@@ -2962,12 +3032,13 @@ function cutToBytes(text, maxBytes) {
|
|
|
2962
3032
|
}
|
|
2963
3033
|
function fitTextBlock(item, budget) {
|
|
2964
3034
|
if (typeof item.text !== "string" || budget <= 0) return null;
|
|
3035
|
+
const encoded = Buffer.from(item.text, "utf8");
|
|
2965
3036
|
let lo = 0;
|
|
2966
|
-
let hi =
|
|
3037
|
+
let hi = Math.min(encoded.byteLength, budget);
|
|
2967
3038
|
let best = null;
|
|
2968
3039
|
while (lo <= hi) {
|
|
2969
3040
|
const mid = Math.floor((lo + hi) / 2);
|
|
2970
|
-
const cut =
|
|
3041
|
+
const cut = cutEncodedToBytes(item.text, encoded, mid);
|
|
2971
3042
|
if (cut.length === 0) {
|
|
2972
3043
|
lo = mid + 1;
|
|
2973
3044
|
continue;
|
|
@@ -3010,16 +3081,17 @@ function capContent(content, maxBytes) {
|
|
|
3010
3081
|
let droppedBlocks = 0;
|
|
3011
3082
|
let truncatedText = false;
|
|
3012
3083
|
const noticeReserve = MAX_NOTICE_BYTES;
|
|
3013
|
-
const contentBudget = maxBytes - noticeReserve;
|
|
3084
|
+
const contentBudget = maxBytes - noticeReserve - ARRAY_BRACKET_BYTES;
|
|
3014
3085
|
for (let i = 0; i < content.length; i++) {
|
|
3015
3086
|
const item = content[i];
|
|
3016
3087
|
const size = serializedBytes(item);
|
|
3017
|
-
|
|
3088
|
+
const separators = kept.length + 1;
|
|
3089
|
+
if (Number.isFinite(size) && used + size + separators <= contentBudget) {
|
|
3018
3090
|
kept.push(item);
|
|
3019
3091
|
used += size;
|
|
3020
3092
|
continue;
|
|
3021
3093
|
}
|
|
3022
|
-
const remaining = contentBudget - used;
|
|
3094
|
+
const remaining = contentBudget - used - separators;
|
|
3023
3095
|
if (item.type === "text" && typeof item.text === "string" && remaining > MIN_USEFUL_TAIL_BYTES) {
|
|
3024
3096
|
const fitted = fitTextBlock(item, remaining);
|
|
3025
3097
|
if (fitted) {
|
|
@@ -3037,6 +3109,7 @@ function capContent(content, maxBytes) {
|
|
|
3037
3109
|
return { content: kept, capped: true, bytesRaw, bytesKept: used };
|
|
3038
3110
|
}
|
|
3039
3111
|
var MIN_USEFUL_TAIL_BYTES = 512;
|
|
3112
|
+
var ARRAY_BRACKET_BYTES = 2;
|
|
3040
3113
|
var MAX_NOTICE_BYTES = (() => {
|
|
3041
3114
|
const worst = capNotice(999999999, 999999999, 999999999, true);
|
|
3042
3115
|
return Buffer.byteLength(JSON.stringify({ type: "text", text: worst }), "utf8");
|
|
@@ -3052,8 +3125,16 @@ var MAX_UPSTREAM_INSTRUCTIONS_BYTES = 2e3;
|
|
|
3052
3125
|
var FENCE_OPEN = "<<<BEGIN UPSTREAM SERVER TEXT";
|
|
3053
3126
|
var FENCE_CLOSE = "<<<END UPSTREAM SERVER TEXT";
|
|
3054
3127
|
var BROKER_VOICE = "[yaw-mcp]";
|
|
3128
|
+
function escapeRegex(literal) {
|
|
3129
|
+
return literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3130
|
+
}
|
|
3131
|
+
function fencePattern(delimiter) {
|
|
3132
|
+
return delimiter.split(" ").map(escapeRegex).join("\\s+").replace(/^<<</, "<<<\\s*");
|
|
3133
|
+
}
|
|
3055
3134
|
var FORGED_MARKERS = new RegExp(
|
|
3056
|
-
[FENCE_OPEN, FENCE_CLOSE, BROKER_VOICE
|
|
3135
|
+
[fencePattern(FENCE_OPEN), fencePattern(FENCE_CLOSE), `\\[\\s*${escapeRegex(BROKER_VOICE.slice(1, -1))}\\s*\\]`].join(
|
|
3136
|
+
"|"
|
|
3137
|
+
),
|
|
3057
3138
|
"gi"
|
|
3058
3139
|
);
|
|
3059
3140
|
var NEUTRALIZED = "[redacted-marker]";
|
|
@@ -3211,8 +3292,13 @@ async function fetchWithRedirects(url, maxHops = 5, totalDeadline = AbortSignal.
|
|
|
3211
3292
|
if (res.statusCode >= 300 && res.statusCode < 400) {
|
|
3212
3293
|
const loc = res.headers.location;
|
|
3213
3294
|
if (!loc) throw new Error(`Redirect without Location header from ${current}`);
|
|
3214
|
-
current = Array.isArray(loc) ? loc[0] : loc;
|
|
3215
3295
|
await res.body.dump();
|
|
3296
|
+
const target = Array.isArray(loc) ? loc[0] : loc;
|
|
3297
|
+
try {
|
|
3298
|
+
current = new URL(target, current).href;
|
|
3299
|
+
} catch {
|
|
3300
|
+
throw new Error(`Redirect to an unusable Location (${target}) from ${current}`);
|
|
3301
|
+
}
|
|
3216
3302
|
continue;
|
|
3217
3303
|
}
|
|
3218
3304
|
if (res.statusCode !== 200) {
|
|
@@ -3405,10 +3491,9 @@ async function resolveUv() {
|
|
|
3405
3491
|
log("info", "uv bootstrap complete", { bin: finalBin });
|
|
3406
3492
|
return finalBin;
|
|
3407
3493
|
}
|
|
3408
|
-
var UV_WIN_EXE_EXT = /\.(?:exe|cmd|bat)$/i;
|
|
3409
3494
|
function uvLaunchKind(command) {
|
|
3410
3495
|
if (/[\\/]/.test(command)) return null;
|
|
3411
|
-
const base = command
|
|
3496
|
+
const base = launcherBasename(command);
|
|
3412
3497
|
if (base === "uv") return "uv";
|
|
3413
3498
|
if (base === "uvx") return "uvx";
|
|
3414
3499
|
return null;
|
|
@@ -3601,17 +3686,25 @@ var MAX_RESOURCES_PER_SERVER = 1e3;
|
|
|
3601
3686
|
var MAX_PROMPTS_PER_SERVER = 1e3;
|
|
3602
3687
|
var MAX_LIST_PAGES = 50;
|
|
3603
3688
|
var ActivationError = class extends Error {
|
|
3604
|
-
constructor(message, category, stderrTail, cause) {
|
|
3689
|
+
constructor(message, category, stderrTail, cause, configPointer) {
|
|
3605
3690
|
super(message);
|
|
3606
3691
|
this.category = category;
|
|
3607
3692
|
this.stderrTail = stderrTail;
|
|
3608
3693
|
this.cause = cause;
|
|
3694
|
+
this.configPointer = configPointer;
|
|
3609
3695
|
this.name = "ActivationError";
|
|
3610
3696
|
}
|
|
3611
3697
|
category;
|
|
3612
3698
|
stderrTail;
|
|
3613
3699
|
cause;
|
|
3700
|
+
configPointer;
|
|
3614
3701
|
};
|
|
3702
|
+
function shellActivationMessage(err) {
|
|
3703
|
+
if (!(err instanceof ActivationError) || !err.configPointer) {
|
|
3704
|
+
return err instanceof Error ? err.message : String(err);
|
|
3705
|
+
}
|
|
3706
|
+
return `${err.configPointer.summary} -> ${err.configPointer.fix}, then run the command again.`;
|
|
3707
|
+
}
|
|
3615
3708
|
function isUnresolvedSecretRef(value) {
|
|
3616
3709
|
return value.startsWith("${secret:") && value.endsWith("}");
|
|
3617
3710
|
}
|
|
@@ -3654,7 +3747,28 @@ function localRedactionMap(configEnv, serverEnv, secretValues) {
|
|
|
3654
3747
|
return { ...out, ...secretValues };
|
|
3655
3748
|
}
|
|
3656
3749
|
function hasUrlPassword(value) {
|
|
3657
|
-
|
|
3750
|
+
const { scheme, userinfo } = splitUserinfo(value.trim());
|
|
3751
|
+
return scheme !== "" && userinfo !== null && /^[^/\s:]*:[\s\S]/.test(userinfo);
|
|
3752
|
+
}
|
|
3753
|
+
function splitUserinfo(raw) {
|
|
3754
|
+
const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(raw)?.[0] ?? "";
|
|
3755
|
+
const tail = raw.slice(scheme.length);
|
|
3756
|
+
const at = tail.lastIndexOf("@");
|
|
3757
|
+
if (at === -1) return { scheme, userinfo: null, rest: tail };
|
|
3758
|
+
return { scheme, userinfo: tail.slice(0, at), rest: tail.slice(at + 1) };
|
|
3759
|
+
}
|
|
3760
|
+
function displayRemoteUrl(raw) {
|
|
3761
|
+
try {
|
|
3762
|
+
const u = new URL(raw);
|
|
3763
|
+
if (u.host !== "" && !`${u.pathname}${u.search}${u.hash}`.includes("@")) {
|
|
3764
|
+
return `${u.protocol}//${u.host}${u.pathname}${u.search || u.hash ? "?..." : ""}`;
|
|
3765
|
+
}
|
|
3766
|
+
} catch {
|
|
3767
|
+
}
|
|
3768
|
+
const withoutQuery = (s) => s.replace(/[?#][\s\S]*$/, "?...");
|
|
3769
|
+
const { scheme, userinfo: dropped, rest } = splitUserinfo(raw);
|
|
3770
|
+
if (dropped === null) return `${scheme}${withoutQuery(rest)}`;
|
|
3771
|
+
return `${scheme}${/[/?#\s]/.test(dropped) ? "...@" : ""}${withoutQuery(rest)}`;
|
|
3658
3772
|
}
|
|
3659
3773
|
function credentialShapedParentEnv() {
|
|
3660
3774
|
const out = {};
|
|
@@ -3697,8 +3811,15 @@ function redactSecretsInOutput(text, env) {
|
|
|
3697
3811
|
out = out.replace(/\$\{secret:([a-zA-Z0-9_.-]+)\}/g, "${secret:***}");
|
|
3698
3812
|
return out;
|
|
3699
3813
|
}
|
|
3700
|
-
function withConfigPointer(
|
|
3701
|
-
|
|
3814
|
+
function withConfigPointer(summary, config, category, stderrTail, cause) {
|
|
3815
|
+
const fix = `Fix "${config.namespace}" in ${bundlesFileHint("defines-it")}`;
|
|
3816
|
+
return new ActivationError(
|
|
3817
|
+
`${summary} -> ${fix}, then activate it again -- the edit is picked up on the next mcp_connect_* call, with no client restart.`,
|
|
3818
|
+
category,
|
|
3819
|
+
stderrTail,
|
|
3820
|
+
cause,
|
|
3821
|
+
{ summary, fix }
|
|
3822
|
+
);
|
|
3702
3823
|
}
|
|
3703
3824
|
var GIT_FAILED_TAIL_CAP = 600;
|
|
3704
3825
|
function quotedFailedTail(tail) {
|
|
@@ -3740,12 +3861,12 @@ async function gitBuildMissing(config, home, consented) {
|
|
|
3740
3861
|
}
|
|
3741
3862
|
async function gitRepoConsented(config) {
|
|
3742
3863
|
if (!config.git?.commit || gitEntryBuilt(config.namespace, config.git)) return void 0;
|
|
3743
|
-
const { hasRepoConsent: hasRepoConsent2 } = await import("./git-source-
|
|
3864
|
+
const { hasRepoConsent: hasRepoConsent2 } = await import("./git-source-XOJY3JWD.js");
|
|
3744
3865
|
return hasRepoConsent2(config.git.url, homedir6());
|
|
3745
3866
|
}
|
|
3746
3867
|
async function recordActivatedGitPin(namespace, commit) {
|
|
3747
3868
|
try {
|
|
3748
|
-
const { recordLoadedGitPin: recordLoadedGitPin2 } = await import("./git-source-
|
|
3869
|
+
const { recordLoadedGitPin: recordLoadedGitPin2 } = await import("./git-source-XOJY3JWD.js");
|
|
3749
3870
|
await recordLoadedGitPin2(namespace, commit, { home: homedir6(), cwd: process.cwd() });
|
|
3750
3871
|
} catch (e) {
|
|
3751
3872
|
log("debug", "Could not record the git build an activation uses", { namespace, error: e.message });
|
|
@@ -3773,11 +3894,15 @@ function unstartableFileMessage(code, err, command) {
|
|
|
3773
3894
|
}
|
|
3774
3895
|
return `Command '${command}' could not be started: the OS refused to run it (spawn UNKNOWN${winError === void 0 ? "" : `, Win32 error ${winError}`}). Common causes: a binary built for another CPU architecture, a corrupt or partial download, or an application-control or antivirus block.`;
|
|
3775
3896
|
}
|
|
3897
|
+
var SPAWN_ERRNO = /\b(?:ENOENT|EACCES|EPERM)\b/;
|
|
3776
3898
|
function categorizeSpawnError(err) {
|
|
3777
3899
|
if (unstartableFileCode(err)) return "spawn_failure";
|
|
3900
|
+
const code = typeof err === "object" && err !== null ? err.code : void 0;
|
|
3901
|
+
if (typeof code === "number") return "unknown";
|
|
3902
|
+
if (typeof code === "string" && SPAWN_ERRNO.test(code)) return "spawn_failure";
|
|
3778
3903
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3779
|
-
if (
|
|
3780
|
-
if (/
|
|
3904
|
+
if (SPAWN_ERRNO.test(msg)) return "spawn_failure";
|
|
3905
|
+
if (/not found|cannot find|command failed to start|permission denied/i.test(msg)) return "spawn_failure";
|
|
3781
3906
|
return "unknown";
|
|
3782
3907
|
}
|
|
3783
3908
|
function remoteFailureDetail(err, resolved) {
|
|
@@ -3793,7 +3918,11 @@ function redactActivationMessage(err, env) {
|
|
|
3793
3918
|
if (!(err instanceof ActivationError)) return err;
|
|
3794
3919
|
const safe = redactSecretsInOutput(err.message, env);
|
|
3795
3920
|
if (safe === err.message) return err;
|
|
3796
|
-
|
|
3921
|
+
const pointer = err.configPointer && {
|
|
3922
|
+
summary: redactSecretsInOutput(err.configPointer.summary, env),
|
|
3923
|
+
fix: err.configPointer.fix
|
|
3924
|
+
};
|
|
3925
|
+
return new ActivationError(safe, err.category, err.stderrTail, err.cause, pointer);
|
|
3797
3926
|
}
|
|
3798
3927
|
function withStderrTail(err, stderrRing, env) {
|
|
3799
3928
|
if (!(err instanceof ActivationError) || err.stderrTail) return err;
|
|
@@ -3801,8 +3930,12 @@ function withStderrTail(err, stderrRing, env) {
|
|
|
3801
3930
|
if (trimmed.length === 0) return err;
|
|
3802
3931
|
const safe = redactSecretsInOutput(trimmed, env);
|
|
3803
3932
|
const oomHint = oamHeapOomHint(trimmed);
|
|
3804
|
-
const
|
|
3805
|
-
|
|
3933
|
+
const appended = `${oomHint ? ` ${oomHint}` : ""} stderr tail: ${safe.slice(-500)}`;
|
|
3934
|
+
const pointer = err.configPointer && {
|
|
3935
|
+
summary: `${err.configPointer.summary}${appended}`,
|
|
3936
|
+
fix: err.configPointer.fix
|
|
3937
|
+
};
|
|
3938
|
+
return new ActivationError(`${err.message}${appended}`, err.category, safe, err.cause, pointer);
|
|
3806
3939
|
}
|
|
3807
3940
|
var oamDowngradedNamespaces = /* @__PURE__ */ new Map();
|
|
3808
3941
|
function isPinnedToNode(config) {
|
|
@@ -3911,7 +4044,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3911
4044
|
if (downstreamCaps?.sampling) capabilities.sampling = downstreamCaps.sampling;
|
|
3912
4045
|
if (downstreamCaps?.roots) capabilities.roots = {};
|
|
3913
4046
|
const client = new Client(
|
|
3914
|
-
{ name: "yaw-mcp", version: true ? "1.1.
|
|
4047
|
+
{ name: "yaw-mcp", version: true ? "1.1.11" : "dev" },
|
|
3915
4048
|
{ capabilities }
|
|
3916
4049
|
);
|
|
3917
4050
|
if (bridge && capabilities.elicitation) {
|
|
@@ -3938,7 +4071,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3938
4071
|
let spawnedCommand = config.command;
|
|
3939
4072
|
if (config.type === "local") {
|
|
3940
4073
|
const notBuilt = await gitBuildMissing(config, void 0, await gitRepoConsented(config));
|
|
3941
|
-
if (notBuilt !== null) throw
|
|
4074
|
+
if (notBuilt !== null) throw withConfigPointer(notBuilt, config, "install_failure");
|
|
3942
4075
|
if (config.git?.commit) await recordActivatedGitPin(config.namespace, config.git.commit);
|
|
3943
4076
|
if (!config.command) {
|
|
3944
4077
|
throw new Error("command is required for local servers");
|
|
@@ -3985,8 +4118,9 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3985
4118
|
} catch (err) {
|
|
3986
4119
|
if (err instanceof ActivationError) throw err;
|
|
3987
4120
|
const message = err instanceof Error ? err.message : String(err);
|
|
3988
|
-
throw
|
|
3989
|
-
|
|
4121
|
+
throw withConfigPointer(
|
|
4122
|
+
`Server "${config.namespace}" could not resolve its launch command. ${message}`,
|
|
4123
|
+
config,
|
|
3990
4124
|
categorizeSpawnError(err),
|
|
3991
4125
|
void 0,
|
|
3992
4126
|
err
|
|
@@ -4028,8 +4162,9 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4028
4162
|
url = new URL(config.url);
|
|
4029
4163
|
} catch (err) {
|
|
4030
4164
|
const message = err instanceof Error ? err.message : String(err);
|
|
4031
|
-
throw
|
|
4032
|
-
|
|
4165
|
+
throw withConfigPointer(
|
|
4166
|
+
`Server "${config.namespace}" has an invalid url "${displayRemoteUrl(config.url)}": ${message}`,
|
|
4167
|
+
config,
|
|
4033
4168
|
"unknown",
|
|
4034
4169
|
void 0,
|
|
4035
4170
|
err
|
|
@@ -4063,14 +4198,10 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4063
4198
|
);
|
|
4064
4199
|
} catch (err) {
|
|
4065
4200
|
if (err instanceof InvalidResolvedValueError) {
|
|
4066
|
-
throw
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
),
|
|
4071
|
-
"unknown",
|
|
4072
|
-
void 0,
|
|
4073
|
-
void 0
|
|
4201
|
+
throw withConfigPointer(
|
|
4202
|
+
`Server "${config.namespace}" has an invalid value for header "${err.key}" -- an HTTP header value cannot contain a line break or a control character (the value is not shown).`,
|
|
4203
|
+
config,
|
|
4204
|
+
"unknown"
|
|
4074
4205
|
);
|
|
4075
4206
|
}
|
|
4076
4207
|
throw err;
|
|
@@ -4155,7 +4286,8 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4155
4286
|
if (config.type !== "local") {
|
|
4156
4287
|
category = timedOut ? "init_timeout" : "protocol_error";
|
|
4157
4288
|
const detail = timedOut ? "" : remoteFailureDetail(err, resolvedServerEnv);
|
|
4158
|
-
|
|
4289
|
+
const shownUrl = displayRemoteUrl(config.url ?? "");
|
|
4290
|
+
message = timedOut ? `Remote server at ${shownUrl} did not respond within ${deadlineMs / 1e3}s. Verify the URL is reachable.` : `Remote server at ${shownUrl} refused the connection.${detail ? ` ${detail}` : ""}`;
|
|
4159
4291
|
} else if (timedOut) {
|
|
4160
4292
|
category = "init_timeout";
|
|
4161
4293
|
message = `Server "${config.namespace}" started but didn't complete the MCP handshake within ${deadlineMs / 1e3}s${extended ? " (including one extension for a slow start)" : ""}.${trimmedStderr ? ` stderr tail: ${redactSecretsInOutput(trimmedStderr, resolvedServerEnv).slice(-500)}` : ""}`;
|
|
@@ -4171,20 +4303,22 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4171
4303
|
if (unstartable) {
|
|
4172
4304
|
message = `${unstartableFileMessage(unstartable, err, config.command)}${spawnedNote}`;
|
|
4173
4305
|
} else if (category === "spawn_failure") {
|
|
4174
|
-
|
|
4306
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
4307
|
+
const underlying = SPAWN_ERRNO.test(raw) ? "" : ` Underlying error: ${redactSecretsInOutput(raw, resolvedServerEnv).slice(0, 300)}`;
|
|
4308
|
+
message = `Command '${config.command}' is not on PATH or is not executable. Verify the runtime is installed (e.g. Node.js for npx, Python for uvx).${spawnedNote}${underlying}`;
|
|
4175
4309
|
} else {
|
|
4176
4310
|
message = err instanceof Error ? err.message : String(err);
|
|
4177
4311
|
}
|
|
4178
4312
|
}
|
|
4179
|
-
message = withConfigPointer(message, config);
|
|
4180
4313
|
const redactedTail = trimmedStderr ? redactSecretsInOutput(trimmedStderr, resolvedServerEnv) : void 0;
|
|
4181
|
-
throw
|
|
4314
|
+
throw withConfigPointer(message, config, category, redactedTail, err);
|
|
4182
4315
|
}
|
|
4183
4316
|
let runtimeFields = {};
|
|
4184
4317
|
if (attempt.oamRewriteApplied) {
|
|
4185
4318
|
runtimeFields = suppressRewrites ? { runtime: "node", downgradedFromOam: true } : { runtime: "oam", oamVersion: attempt.oamVersion };
|
|
4186
4319
|
} else if (attempt.managedRewriteApplied) {
|
|
4187
|
-
|
|
4320
|
+
const oamPinFields = isPinnedToNode(config) ? { downgradedFromOam: true, oamPinned: true } : {};
|
|
4321
|
+
runtimeFields = suppressRewrites ? { runtime: "node", ...oamPinFields, downgradedFromManaged: true } : { runtime: "node", managedSpawn: true, ...oamPinFields };
|
|
4188
4322
|
} else if (config.type === "local" && (isPinnedToNode(config) || isPinnedToNpx(config))) {
|
|
4189
4323
|
const oamPin = isPinnedToNode(config);
|
|
4190
4324
|
const managedPin = isPinnedToNpx(config);
|
|
@@ -4397,7 +4531,10 @@ async function fetchResourcesFromUpstream(client, namespace, opts = {}) {
|
|
|
4397
4531
|
_meta: r._meta
|
|
4398
4532
|
}));
|
|
4399
4533
|
} catch (err) {
|
|
4400
|
-
if (!opts.throwOnError)
|
|
4534
|
+
if (!opts.throwOnError) {
|
|
4535
|
+
warnSwallowedListError(err, namespace, "resources/list");
|
|
4536
|
+
return [];
|
|
4537
|
+
}
|
|
4401
4538
|
const message = err instanceof Error ? err.message : String(err);
|
|
4402
4539
|
throw new Error(`"${namespace}" returned an error on resources/list: ${message}`);
|
|
4403
4540
|
}
|
|
@@ -4429,7 +4566,10 @@ async function fetchPromptsFromUpstream(client, namespace, opts = {}) {
|
|
|
4429
4566
|
_meta: p._meta
|
|
4430
4567
|
}));
|
|
4431
4568
|
} catch (err) {
|
|
4432
|
-
if (!opts.throwOnError)
|
|
4569
|
+
if (!opts.throwOnError) {
|
|
4570
|
+
warnSwallowedListError(err, namespace, "prompts/list");
|
|
4571
|
+
return [];
|
|
4572
|
+
}
|
|
4433
4573
|
const message = err instanceof Error ? err.message : String(err);
|
|
4434
4574
|
throw new Error(`"${namespace}" returned an error on prompts/list: ${message}`);
|
|
4435
4575
|
}
|
|
@@ -4437,6 +4577,14 @@ async function fetchPromptsFromUpstream(client, namespace, opts = {}) {
|
|
|
4437
4577
|
function isMethodNotFound(err) {
|
|
4438
4578
|
return err?.code === -32601;
|
|
4439
4579
|
}
|
|
4580
|
+
function warnSwallowedListError(err, namespace, endpoint) {
|
|
4581
|
+
if (isMethodNotFound(err)) return;
|
|
4582
|
+
log("warn", "Upstream list failed at connect; continuing with an empty inventory", {
|
|
4583
|
+
namespace,
|
|
4584
|
+
endpoint,
|
|
4585
|
+
error: (err instanceof Error ? err.message : String(err)).slice(0, 300)
|
|
4586
|
+
});
|
|
4587
|
+
}
|
|
4440
4588
|
async function fetchToolsFromUpstream(client, namespace, opts = {}) {
|
|
4441
4589
|
let all;
|
|
4442
4590
|
try {
|
|
@@ -4497,16 +4645,6 @@ function isBareUsername(user) {
|
|
|
4497
4645
|
if (!/^[A-Za-z0-9._-]{1,19}$/.test(user)) return false;
|
|
4498
4646
|
return !/^(gh[pousr]_|github_pat_|glpat-|glptt-|xox[abp]-)/i.test(user);
|
|
4499
4647
|
}
|
|
4500
|
-
function printable(s) {
|
|
4501
|
-
return s.replace(/[^\x20-\x7e]/g, "?");
|
|
4502
|
-
}
|
|
4503
|
-
function hasControlBytes(s) {
|
|
4504
|
-
for (let i = 0; i < s.length; i++) {
|
|
4505
|
-
const c = s.charCodeAt(i);
|
|
4506
|
-
if (c < 32 || c >= 127 && c <= 159) return true;
|
|
4507
|
-
}
|
|
4508
|
-
return false;
|
|
4509
|
-
}
|
|
4510
4648
|
function gitRefProblem(ref) {
|
|
4511
4649
|
if (ref === "") return "the ref after # is empty";
|
|
4512
4650
|
if (ref.startsWith("-")) return 'the ref cannot start with "-"';
|
|
@@ -4517,7 +4655,7 @@ function gitRefProblem(ref) {
|
|
|
4517
4655
|
}
|
|
4518
4656
|
function parseGitSpec(raw) {
|
|
4519
4657
|
const fail = (error) => ({ ok: false, error });
|
|
4520
|
-
if (
|
|
4658
|
+
if (hasControlChar(raw)) return fail("--git: the URL contains control characters.");
|
|
4521
4659
|
const value = raw.trim();
|
|
4522
4660
|
if (value === "") return fail("--git requires a URL");
|
|
4523
4661
|
if (value.startsWith("-")) return fail('--git: the URL cannot start with "-".');
|
|
@@ -4575,7 +4713,7 @@ function parseGitSpec(raw) {
|
|
|
4575
4713
|
if (scp) {
|
|
4576
4714
|
const [, user, host = "", path2 = ""] = scp;
|
|
4577
4715
|
if (host.length === 1) return fail("--git: local paths need a file:// URL (file:///C:/path/to/repo).");
|
|
4578
|
-
if (path2.startsWith("
|
|
4716
|
+
if (path2.startsWith("//")) return fail(`--git: not a git URL. Use ${GIT_URL_FORMS}.`);
|
|
4579
4717
|
return withRef({ url, protocol: "ssh", host: host.toLowerCase(), ...user ? { username: user } : {} });
|
|
4580
4718
|
}
|
|
4581
4719
|
return fail(`--git: not a git URL. Use ${GIT_URL_FORMS}.`);
|
|
@@ -4593,7 +4731,11 @@ function normalizeRepoUrl(url) {
|
|
|
4593
4731
|
if (!spec.ok) return tidy(url.trim());
|
|
4594
4732
|
const bare = spec.spec.url;
|
|
4595
4733
|
if (spec.spec.protocol === "file") {
|
|
4596
|
-
let path3 =
|
|
4734
|
+
let path3 = new URL(bare).pathname;
|
|
4735
|
+
try {
|
|
4736
|
+
path3 = decodeURIComponent(path3);
|
|
4737
|
+
} catch {
|
|
4738
|
+
}
|
|
4597
4739
|
if (/^\/[A-Za-z]:/.test(path3)) path3 = path3.slice(1).toLowerCase();
|
|
4598
4740
|
return `file:${tidy(path3)}`;
|
|
4599
4741
|
}
|
|
@@ -4603,7 +4745,21 @@ function normalizeRepoUrl(url) {
|
|
|
4603
4745
|
return `${spec.spec.host}/${tidy(path2).replace(/^\/+/, "")}`;
|
|
4604
4746
|
}
|
|
4605
4747
|
function scrubUrlUserinfo(text) {
|
|
4606
|
-
return text.replace(/\b([a-z][a-z0-9+.-]
|
|
4748
|
+
return text.replace(/\b([a-z][a-z0-9+.-]{0,31}:\/\/)(?:[^/\s:'"]*:(?:(?!:\/\/)[^\r\n'"])*|[^/@\s'"]+)@/gi, "$1***@");
|
|
4749
|
+
}
|
|
4750
|
+
function scrubRepoUrlUserinfo(url) {
|
|
4751
|
+
let parsed;
|
|
4752
|
+
try {
|
|
4753
|
+
parsed = new URL(url);
|
|
4754
|
+
} catch {
|
|
4755
|
+
return scrubUrlUserinfo(url);
|
|
4756
|
+
}
|
|
4757
|
+
if (!parsed.username && !parsed.password) return url;
|
|
4758
|
+
const m = /^([a-z][a-z0-9+.-]*:\/\/)[^/?#\\]*@/i.exec(url);
|
|
4759
|
+
if (m) return `${m[1]}***@${url.slice(m[0].length)}`;
|
|
4760
|
+
parsed.username = "***";
|
|
4761
|
+
parsed.password = "";
|
|
4762
|
+
return parsed.href;
|
|
4607
4763
|
}
|
|
4608
4764
|
function redactGitOutput(text, secrets = {}) {
|
|
4609
4765
|
return scrubUrlUserinfo(redactSecretsInOutput(text, secrets));
|
|
@@ -4722,7 +4878,7 @@ async function listRemoteRefs(spec, git, tokenSecret, shared = false) {
|
|
|
4722
4878
|
const access = gitAccessFailure(spec, r.stderr, tokenSecret, shared);
|
|
4723
4879
|
if (access) return { ok: false, exitCode: 1, message: access };
|
|
4724
4880
|
const tail = redactGitOutput(lastLines(r.stderr), git.secrets);
|
|
4725
|
-
return { ok: false, exitCode: 1, message: `git ls-remote failed for ${
|
|
4881
|
+
return { ok: false, exitCode: 1, message: `git ls-remote failed for ${scrubRepoUrlUserinfo(spec.url)}:
|
|
4726
4882
|
${tail}` };
|
|
4727
4883
|
}
|
|
4728
4884
|
const refs = /* @__PURE__ */ new Map();
|
|
@@ -4752,7 +4908,7 @@ function resolveRefIn(spec, remote) {
|
|
|
4752
4908
|
return {
|
|
4753
4909
|
ok: false,
|
|
4754
4910
|
exitCode: 1,
|
|
4755
|
-
message: `${
|
|
4911
|
+
message: `${scrubRepoUrlUserinfo(spec.url)} has no default branch to track. Name one: --git <url>#<branch>`
|
|
4756
4912
|
};
|
|
4757
4913
|
if (headTarget?.startsWith("refs/heads/")) {
|
|
4758
4914
|
return { ok: true, ref: headTarget.slice("refs/heads/".length), kind: "branch", commit: head };
|
|
@@ -4767,7 +4923,7 @@ function resolveRefIn(spec, remote) {
|
|
|
4767
4923
|
if (/^[0-9a-f]{40}$/i.test(ref)) return { ok: true, ref: ref.toLowerCase(), kind: "sha", commit: ref.toLowerCase() };
|
|
4768
4924
|
if (/^[0-9a-f]{4,39}$/i.test(ref))
|
|
4769
4925
|
return { ok: true, ref: ref.toLowerCase(), kind: "sha", shortSha: ref.toLowerCase() };
|
|
4770
|
-
const safe =
|
|
4926
|
+
const safe = scrubRepoUrlUserinfo(spec.url);
|
|
4771
4927
|
return {
|
|
4772
4928
|
ok: false,
|
|
4773
4929
|
exitCode: 1,
|
|
@@ -5107,14 +5263,15 @@ function readManifestFile(file, label, warnings, allowSubdir) {
|
|
|
5107
5263
|
}
|
|
5108
5264
|
}
|
|
5109
5265
|
if (m.version !== void 0 && m.version !== 1) {
|
|
5266
|
+
const shown = printable(JSON.stringify(m.version) ?? "");
|
|
5110
5267
|
warnings.push(
|
|
5111
|
-
`${label}: version ${
|
|
5268
|
+
typeof m.version === "number" && m.version > 1 ? `${label}: version ${shown} is newer than this yaw-mcp; reading the fields it knows.` : `${label}: version ${shown} is not a supported version (this yaw-mcp reads version 1); reading the fields it knows.`
|
|
5112
5269
|
);
|
|
5113
5270
|
}
|
|
5114
5271
|
const str2 = (key) => {
|
|
5115
5272
|
const v = m[key];
|
|
5116
5273
|
if (v === void 0) return void 0;
|
|
5117
|
-
if (typeof v !== "string" || v.trim() === "" ||
|
|
5274
|
+
if (typeof v !== "string" || v.trim() === "" || hasControlChar(v)) {
|
|
5118
5275
|
warnings.push(`${label}: "${key}" ignored: not a non-empty string.`);
|
|
5119
5276
|
return void 0;
|
|
5120
5277
|
}
|
|
@@ -5162,8 +5319,8 @@ function readManifestFile(file, label, warnings, allowSubdir) {
|
|
|
5162
5319
|
else warnings.push(`${label}: env "${k}" secret name ignored: letters, digits, "_", "." or "-" only.`);
|
|
5163
5320
|
}
|
|
5164
5321
|
if (d.required === true) decl.required = true;
|
|
5165
|
-
if (typeof d.help === "string" && !
|
|
5166
|
-
if (typeof d.default === "string" && !
|
|
5322
|
+
if (typeof d.help === "string" && !hasControlChar(d.help)) decl.help = d.help;
|
|
5323
|
+
if (typeof d.default === "string" && !hasControlChar(d.default)) {
|
|
5167
5324
|
if (decl.secret) warnings.push(`${label}: env "${k}" default ignored: a secret has no default.`);
|
|
5168
5325
|
else decl.default = d.default;
|
|
5169
5326
|
}
|
|
@@ -5308,6 +5465,13 @@ function insideRelative(base, abs) {
|
|
|
5308
5465
|
if (rel === "" || rel.startsWith("..") || /^[A-Za-z]:/.test(rel) || rel.startsWith("/")) return null;
|
|
5309
5466
|
return rel.replace(/\\/g, "/");
|
|
5310
5467
|
}
|
|
5468
|
+
function isRegularFile(path2) {
|
|
5469
|
+
try {
|
|
5470
|
+
return statSync4(path2).isFile();
|
|
5471
|
+
} catch {
|
|
5472
|
+
return false;
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5311
5475
|
function inferredEntry(pkgDir) {
|
|
5312
5476
|
const pkg = readJsonObject(join7(pkgDir, "package.json"));
|
|
5313
5477
|
const hit = packageEntry(pkgDir, typeof pkg?.name === "string" ? pkg.name : "");
|
|
@@ -5335,7 +5499,7 @@ function consentLines(scripts, manifest, namespace, configs = []) {
|
|
|
5335
5499
|
const parts = secrets.map(([k, d]) => `${d.secret} (${k})${d.help ? ` -- ${d.help}` : ""}`);
|
|
5336
5500
|
lines.push(`Needs secrets: ${parts.join(", ")}`);
|
|
5337
5501
|
}
|
|
5338
|
-
return lines.map(
|
|
5502
|
+
return lines.map(printable);
|
|
5339
5503
|
}
|
|
5340
5504
|
async function buildGitSource(req, ctx) {
|
|
5341
5505
|
const root = gitRoot(ctx.home);
|
|
@@ -5397,15 +5561,17 @@ async function buildLocked(req, ctx, root) {
|
|
|
5397
5561
|
const gitCtx = prepared.run;
|
|
5398
5562
|
const secrets = prepared.secrets;
|
|
5399
5563
|
const redact = (text) => redactGitOutput(lastLines(text), secrets);
|
|
5400
|
-
const
|
|
5564
|
+
const tidySubdir = (s) => relativeSegments(s).join("/");
|
|
5565
|
+
const reqSubdir = req.subdir === void 0 ? void 0 : tidySubdir(req.subdir);
|
|
5566
|
+
const subdirOf = (manifest2) => (reqSubdir !== void 0 ? reqSubdir : tidySubdir(manifest2.subdir ?? "")) || void 0;
|
|
5401
5567
|
const fullKnown = /^[0-9a-f]{40}$/.test(req.commit);
|
|
5402
5568
|
const reuse = (ns, commit2) => {
|
|
5403
5569
|
const dir = gitBuildDir(ns, commit2, ctx.home);
|
|
5404
5570
|
const marker2 = readBuildMarker(dir, commit2);
|
|
5405
5571
|
if (!marker2) return null;
|
|
5406
|
-
const { manifest: manifest2, warnings } = readGitManifest(dir,
|
|
5572
|
+
const { manifest: manifest2, warnings } = readGitManifest(dir, reqSubdir);
|
|
5407
5573
|
const subdir2 = subdirOf(manifest2);
|
|
5408
|
-
if ((marker2.subdir ?? "") !== (subdir2 ?? "")) {
|
|
5574
|
+
if (tidySubdir(marker2.subdir ?? "") !== (subdir2 ?? "")) {
|
|
5409
5575
|
return {
|
|
5410
5576
|
ok: false,
|
|
5411
5577
|
exitCode: 1,
|
|
@@ -5416,11 +5582,13 @@ async function buildLocked(req, ctx, root) {
|
|
|
5416
5582
|
}
|
|
5417
5583
|
for (const w of warnings) warn(w);
|
|
5418
5584
|
const entry2 = (req.entry ?? marker2.entry).replace(/\\/g, "/");
|
|
5419
|
-
|
|
5585
|
+
const entryPath = join7(dir, ...(subdir2 ?? "").split("/"), ...entry2.split("/"));
|
|
5586
|
+
if (!isRegularFile(entryPath)) {
|
|
5587
|
+
const why = existsSync4(entryPath) ? "is not a file" : "does not exist";
|
|
5420
5588
|
return {
|
|
5421
5589
|
ok: false,
|
|
5422
5590
|
exitCode: 1,
|
|
5423
|
-
message: printable(`Built ${commit2.slice(0, 7)}
|
|
5591
|
+
message: printable(`Built ${commit2.slice(0, 7)} but its entry ${entry2} ${why}. Pass --entry <file>.`)
|
|
5424
5592
|
};
|
|
5425
5593
|
}
|
|
5426
5594
|
return {
|
|
@@ -5439,7 +5607,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5439
5607
|
if (req.namespace && fullKnown && !ancestorCheck) {
|
|
5440
5608
|
const hit = reuse(req.namespace, req.commit);
|
|
5441
5609
|
if (hit) {
|
|
5442
|
-
progress(`Using the existing build of ${req.commit.slice(0, GIT_BUILD_SHA_LEN)}`);
|
|
5610
|
+
if (hit.ok) progress(`Using the existing build of ${req.commit.slice(0, GIT_BUILD_SHA_LEN)}`);
|
|
5443
5611
|
return hit;
|
|
5444
5612
|
}
|
|
5445
5613
|
}
|
|
@@ -5456,10 +5624,10 @@ async function buildLocked(req, ctx, root) {
|
|
|
5456
5624
|
}
|
|
5457
5625
|
}
|
|
5458
5626
|
if (record && namespace && /^[0-9a-f]{40}$/.test(commit)) {
|
|
5459
|
-
const
|
|
5627
|
+
const failedRecord = { commit, at: (ctx.now?.() ?? /* @__PURE__ */ new Date()).toISOString(), step, tail: redact(tail) };
|
|
5460
5628
|
try {
|
|
5461
5629
|
mkdirSync2(dirname4(gitFailedPath(namespace, commit, ctx.home)), { recursive: true, mode: 448 });
|
|
5462
|
-
writeFileSync2(gitFailedPath(namespace, commit, ctx.home), `${JSON.stringify(
|
|
5630
|
+
writeFileSync2(gitFailedPath(namespace, commit, ctx.home), `${JSON.stringify(failedRecord, null, 2)}
|
|
5463
5631
|
`, {
|
|
5464
5632
|
mode: 384
|
|
5465
5633
|
});
|
|
@@ -5494,7 +5662,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5494
5662
|
if (clone.code === -1 && !clone.stderr) return fail(2, GIT_MISSING_MESSAGE);
|
|
5495
5663
|
const access = gitAccessFailure(req.spec, clone.stderr, req.tokenSecret, req.shared);
|
|
5496
5664
|
if (access) return fail(1, access);
|
|
5497
|
-
return fail(1, `git clone failed for ${
|
|
5665
|
+
return fail(1, `git clone failed for ${scrubRepoUrlUserinfo(req.spec.url)}:`, clone.stderr);
|
|
5498
5666
|
}
|
|
5499
5667
|
progress(timed("Cloning (blobless)", t));
|
|
5500
5668
|
step = "checkout";
|
|
@@ -5502,14 +5670,17 @@ async function buildLocked(req, ctx, root) {
|
|
|
5502
5670
|
const rp = await runGit(["rev-parse", "--verify", "--quiet", `${commit}^{commit}`], gitCtx, work);
|
|
5503
5671
|
const full = rp.stdout.trim();
|
|
5504
5672
|
if (rp.code !== 0 || !/^[0-9a-f]{40}$/.test(full)) {
|
|
5505
|
-
return fail(
|
|
5673
|
+
return fail(
|
|
5674
|
+
1,
|
|
5675
|
+
`commit ${commit} is not in ${scrubRepoUrlUserinfo(req.spec.url)} (or the short SHA is ambiguous).`
|
|
5676
|
+
);
|
|
5506
5677
|
}
|
|
5507
5678
|
commit = full;
|
|
5508
5679
|
}
|
|
5509
5680
|
const co = await runGit([...gitCfg, "checkout", "--detach", commit], gitCtx, work);
|
|
5510
5681
|
if (co.code !== 0) {
|
|
5511
5682
|
const sha12 = commit.slice(0, 12);
|
|
5512
|
-
const url =
|
|
5683
|
+
const url = scrubRepoUrlUserinfo(req.spec.url);
|
|
5513
5684
|
let headline = `git checkout of ${sha12} from ${url} failed:`;
|
|
5514
5685
|
if (/invalid path '/i.test(co.stderr)) {
|
|
5515
5686
|
headline = `${sha12} of ${url} holds a file name this system cannot create (on Windows: a reserved name such as aux or con, a ":", or a trailing dot or space), so it cannot be checked out here:`;
|
|
@@ -5540,7 +5711,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5540
5711
|
const count = Number((await runGit(["rev-list", "--count", `${req.ancestor}..${commit}`], gitCtx, work)).stdout);
|
|
5541
5712
|
if (Number.isInteger(count)) ahead = count;
|
|
5542
5713
|
}
|
|
5543
|
-
const { manifest, warnings: manifestWarnings } = readGitManifest(work,
|
|
5714
|
+
const { manifest, warnings: manifestWarnings } = readGitManifest(work, reqSubdir);
|
|
5544
5715
|
for (const w of manifestWarnings) warn(w);
|
|
5545
5716
|
namespace = namespace ?? manifest.namespace;
|
|
5546
5717
|
if (!namespace) {
|
|
@@ -5550,7 +5721,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5550
5721
|
const hit = reuse(namespace, commit);
|
|
5551
5722
|
if (hit) {
|
|
5552
5723
|
tryRemoveTree(work, warn);
|
|
5553
|
-
progress(`Using the existing build of ${commit.slice(0, GIT_BUILD_SHA_LEN)}`);
|
|
5724
|
+
if (hit.ok) progress(`Using the existing build of ${commit.slice(0, GIT_BUILD_SHA_LEN)}`);
|
|
5554
5725
|
return hit.ok && ahead !== void 0 ? { ...hit, ahead } : hit;
|
|
5555
5726
|
}
|
|
5556
5727
|
const dest = gitBuildDir(namespace, commit, ctx.home);
|
|
@@ -5565,14 +5736,14 @@ async function buildLocked(req, ctx, root) {
|
|
|
5565
5736
|
work = dest;
|
|
5566
5737
|
}
|
|
5567
5738
|
const subdir = subdirOf(manifest);
|
|
5568
|
-
const targetDir = subdir ? join7(work, ...subdir.split(/
|
|
5739
|
+
const targetDir = subdir ? join7(work, ...subdir.split("/")) : work;
|
|
5569
5740
|
if (targetDir !== work && insideRelative(work, targetDir) === null) {
|
|
5570
5741
|
return fail(2, `subdir "${subdir}" is outside the repository; refusing to build.`, "", "", false);
|
|
5571
5742
|
}
|
|
5572
5743
|
if (!existsSync4(join7(targetDir, "package.json"))) {
|
|
5573
5744
|
if (req.subdir === "") {
|
|
5574
5745
|
const moved = manifest.subdir ? printable(manifest.subdir) : void 0;
|
|
5575
|
-
const url =
|
|
5746
|
+
const url = scrubRepoUrlUserinfo(req.spec.url) + (req.ref ? `#${req.ref}` : "");
|
|
5576
5747
|
return fail(
|
|
5577
5748
|
1,
|
|
5578
5749
|
`the repo root has no package.json. "${namespace}" builds the repo root (its entry has no git.subdir)${moved ? `, but the repo's yaw-mcp.json now puts the server in "${moved}"` : ""}. Re-add it with the subdir: yaw-mcp add ${namespace} --git ${url} --subdir ${moved ?? "<path>"}${req.shared ? " --project" : ""}`
|
|
@@ -5585,7 +5756,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5585
5756
|
}
|
|
5586
5757
|
const installDir = existsSync4(join7(work, "package.json")) ? work : targetDir;
|
|
5587
5758
|
const plan = detectPackageManager(installDir);
|
|
5588
|
-
if ("error" in plan) return fail(2, `${
|
|
5759
|
+
if ("error" in plan) return fail(2, `${scrubRepoUrlUserinfo(req.spec.url)}: ${plan.error}`);
|
|
5589
5760
|
for (const w of plan.warnings) warn(w);
|
|
5590
5761
|
const pmCmd = resolvePmCommand(plan, { env: ctx.env, platform: ctx.platform, exclude: work });
|
|
5591
5762
|
if ("error" in pmCmd) return fail(2, pmCmd.error);
|
|
@@ -5610,7 +5781,11 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5610
5781
|
);
|
|
5611
5782
|
return { ...refused, needsConsent: true };
|
|
5612
5783
|
}
|
|
5613
|
-
|
|
5784
|
+
const consent = await ctx.confirm(lines);
|
|
5785
|
+
if (consent === "cancelled") {
|
|
5786
|
+
return { ...await fail(130, "Cancelled; nothing was built.", "", "", false), cancelled: true };
|
|
5787
|
+
}
|
|
5788
|
+
if (!consent) return fail(1, "Aborted; nothing was built.", "", "", false);
|
|
5614
5789
|
}
|
|
5615
5790
|
await recordRepoConsent(req.spec.url, ctx.home, ctx.now?.());
|
|
5616
5791
|
}
|
|
@@ -5635,7 +5810,7 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5635
5810
|
const shown = (args) => `${pmCmd.label} ${args.filter((a) => a !== "--no-audit" && a !== "--no-fund").join(" ")}`;
|
|
5636
5811
|
const sha7 = commit.slice(0, 7);
|
|
5637
5812
|
const built = commit;
|
|
5638
|
-
const unchanged = keptBuilds(namespace, ctx.home).some((k) => k.marker.commit !== built) ? "Nothing was changed; the previous build still runs." : "Nothing was changed.";
|
|
5813
|
+
const unchanged = req.unchanged ?? (keptBuilds(namespace, ctx.home).some((k) => k.marker.commit !== built) ? "Nothing was changed; the previous build still runs." : "Nothing was changed.");
|
|
5639
5814
|
step = "install";
|
|
5640
5815
|
t = Date.now();
|
|
5641
5816
|
const install = await runStep(plan.installArgs, installDir);
|
|
@@ -5661,8 +5836,12 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5661
5836
|
const entryName = req.entry ?? manifest.entry;
|
|
5662
5837
|
let entry = null;
|
|
5663
5838
|
if (entryName !== void 0) {
|
|
5664
|
-
|
|
5665
|
-
|
|
5839
|
+
const entryPath = join7(targetDir, ...entryName.split(/[\\/]/));
|
|
5840
|
+
if (isRegularFile(entryPath)) entry = entryName.replace(/\\/g, "/");
|
|
5841
|
+
else {
|
|
5842
|
+
const why = existsSync4(entryPath) ? "is not a file" : "does not exist";
|
|
5843
|
+
return fail(1, `Built ${sha7} but its entry ${entryName} ${why}. Pass --entry <file>.`);
|
|
5844
|
+
}
|
|
5666
5845
|
} else {
|
|
5667
5846
|
entry = inferredEntry(targetDir);
|
|
5668
5847
|
if (!entry) {
|
|
@@ -5713,9 +5892,6 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5713
5892
|
...ahead !== void 0 ? { ahead } : {}
|
|
5714
5893
|
};
|
|
5715
5894
|
}
|
|
5716
|
-
function asciiLines(text) {
|
|
5717
|
-
return text.replace(/\r\n/g, "\n").replace(/[^\x20-\x7e\n]/g, "?");
|
|
5718
|
-
}
|
|
5719
5895
|
async function buildPinnedGitEntries(servers, ctx, shared, pinFile) {
|
|
5720
5896
|
const reports = [];
|
|
5721
5897
|
for (const s of servers) {
|
|
@@ -5760,6 +5936,9 @@ async function buildPinnedGitEntries(servers, ctx, shared, pinFile) {
|
|
|
5760
5936
|
if (res.ok) {
|
|
5761
5937
|
ctx.progress(`${ns} ready (${commit.slice(0, 7)}).`);
|
|
5762
5938
|
reports.push({ namespace: ns, commit, status: res.reused ? "ready" : "built", error: null });
|
|
5939
|
+
} else if (res.cancelled) {
|
|
5940
|
+
reports.push({ namespace: ns, commit, status: "cancelled", error: asciiLines(res.message) });
|
|
5941
|
+
break;
|
|
5763
5942
|
} else {
|
|
5764
5943
|
reports.push({
|
|
5765
5944
|
namespace: ns,
|
|
@@ -5888,6 +6067,31 @@ async function recordGitPin(namespace, file, commit, home, warn = () => {
|
|
|
5888
6067
|
release();
|
|
5889
6068
|
}
|
|
5890
6069
|
}
|
|
6070
|
+
async function forgetGitPin(namespace, file, commit, home, warn = () => {
|
|
6071
|
+
}, opts = {}) {
|
|
6072
|
+
if (!NAMESPACE_RE.test(namespace) || !GIT_COMMIT_RE.test(commit)) return;
|
|
6073
|
+
if (!existsSync4(gitCheckoutDir(namespace, home))) return;
|
|
6074
|
+
const key = resolve3(file);
|
|
6075
|
+
const known = readRefs(namespace, home);
|
|
6076
|
+
if (known.kind !== "ok" || known.refs[key] !== commit) return;
|
|
6077
|
+
const release = await acquireGitLockWithin(gitRoot(home), opts.waitMs ?? GIT_PIN_LOCK_WAIT_MS);
|
|
6078
|
+
if (release === null) {
|
|
6079
|
+
log("debug", "Skipped dropping a git pin record: the git lock stayed busy", { namespace, file, commit });
|
|
6080
|
+
return;
|
|
6081
|
+
}
|
|
6082
|
+
try {
|
|
6083
|
+
const read = readRefs(namespace, home);
|
|
6084
|
+
if (read.kind !== "ok" || read.refs[key] !== commit) return;
|
|
6085
|
+
const { [key]: _dropped, ...rest } = read.refs;
|
|
6086
|
+
await writeRefs(namespace, home, rest);
|
|
6087
|
+
} catch (e) {
|
|
6088
|
+
warn(
|
|
6089
|
+
`could not drop the record that ${file} uses build ${commit.slice(0, 7)} of ${namespace}: ${e.message}`
|
|
6090
|
+
);
|
|
6091
|
+
} finally {
|
|
6092
|
+
release();
|
|
6093
|
+
}
|
|
6094
|
+
}
|
|
5891
6095
|
async function recordLoadedGitPin(namespace, commit, opts) {
|
|
5892
6096
|
const probe = await probeProjectTrust({ cwd: opts.cwd, home: opts.home, env: opts.env }).catch(() => null);
|
|
5893
6097
|
const file = probe?.path && projectFileIsHonoured(probe) ? probe.path : localBundlesPath(userConfigDir(opts.home));
|
|
@@ -6111,6 +6315,31 @@ async function discardBuild(namespace, commit, home, opts = {}) {
|
|
|
6111
6315
|
release();
|
|
6112
6316
|
}
|
|
6113
6317
|
}
|
|
6318
|
+
async function discardUnpinnedBuild(namespace, commit, home, opts = {}) {
|
|
6319
|
+
const root = gitRoot(home);
|
|
6320
|
+
const release = acquireSidecarsLock(root, GIT_LOCK_NAME);
|
|
6321
|
+
if (release === null) return { removed: false, reason: lockedMessage(root, "the build was left in place.") };
|
|
6322
|
+
try {
|
|
6323
|
+
const live = await gitLiveness(namespace, home, { ...opts, repair: false });
|
|
6324
|
+
if (live.unreadable.length > 0) {
|
|
6325
|
+
return { removed: false, reason: `yaw-mcp could not read ${live.unreadable.join(", ")}, which may pin it.` };
|
|
6326
|
+
}
|
|
6327
|
+
const sha12 = commit.slice(0, GIT_BUILD_SHA_LEN);
|
|
6328
|
+
if (live.pins.some((p) => p.sha12 === sha12)) return { removed: false };
|
|
6329
|
+
const dir = gitBuildDir(namespace, commit, home);
|
|
6330
|
+
rmSync(builtMarkerPath(dir), { force: true });
|
|
6331
|
+
removeTree(dir);
|
|
6332
|
+
try {
|
|
6333
|
+
rmdirSync(gitCheckoutDir(namespace, home));
|
|
6334
|
+
} catch {
|
|
6335
|
+
}
|
|
6336
|
+
return { removed: true };
|
|
6337
|
+
} catch (e) {
|
|
6338
|
+
return { removed: false, reason: asciiLines(e.message) };
|
|
6339
|
+
} finally {
|
|
6340
|
+
release();
|
|
6341
|
+
}
|
|
6342
|
+
}
|
|
6114
6343
|
var GIT_STATE_FILENAME = "state.json";
|
|
6115
6344
|
function gitStatePath(home) {
|
|
6116
6345
|
return join7(gitRoot(home), GIT_STATE_FILENAME);
|
|
@@ -6175,11 +6404,13 @@ export {
|
|
|
6175
6404
|
HTTP_HEADER_NAME_RE,
|
|
6176
6405
|
RESERVED_HEADER_NAMES,
|
|
6177
6406
|
unsafeRelativePathReason,
|
|
6407
|
+
relativeSegments,
|
|
6178
6408
|
gitSourceFromRaw,
|
|
6179
6409
|
gitNodeCommand,
|
|
6180
6410
|
jsonErrorLocation,
|
|
6181
6411
|
readBundlesServersSync,
|
|
6182
6412
|
previewBundlesContent,
|
|
6413
|
+
rawEntryLoads,
|
|
6183
6414
|
probeProjectTrust,
|
|
6184
6415
|
untrustedProjectWarning,
|
|
6185
6416
|
projectFileIsHonoured,
|
|
@@ -6211,6 +6442,8 @@ export {
|
|
|
6211
6442
|
fenceUpstreamInstructions,
|
|
6212
6443
|
ensureUv,
|
|
6213
6444
|
uvLaunchKind,
|
|
6445
|
+
printable,
|
|
6446
|
+
asciiLines,
|
|
6214
6447
|
levenshtein,
|
|
6215
6448
|
closestNames,
|
|
6216
6449
|
matchCatalog,
|
|
@@ -6220,12 +6453,17 @@ export {
|
|
|
6220
6453
|
tokenizeCommand,
|
|
6221
6454
|
normalizeCatalogUrl,
|
|
6222
6455
|
withWarnSink,
|
|
6456
|
+
isRemoteCatalogEntry,
|
|
6457
|
+
catalogEnvKeys,
|
|
6223
6458
|
resolveCatalogSlug,
|
|
6224
6459
|
QUESTION_CANCELLED,
|
|
6460
|
+
QUESTION_EOF,
|
|
6225
6461
|
questionOrEmpty,
|
|
6226
6462
|
askYesNo,
|
|
6463
|
+
scriptConsentConfirm,
|
|
6227
6464
|
collectSidecarSpecs,
|
|
6228
6465
|
configuredRange,
|
|
6466
|
+
sidecarsManifest,
|
|
6229
6467
|
installedPlatform,
|
|
6230
6468
|
installedVersion,
|
|
6231
6469
|
defaultRunNpm,
|
|
@@ -6234,11 +6472,11 @@ export {
|
|
|
6234
6472
|
runSidecarsInstall,
|
|
6235
6473
|
hasManagedSidecars,
|
|
6236
6474
|
GIT_CREDENTIALS_REFUSAL,
|
|
6237
|
-
printable,
|
|
6238
6475
|
gitRefProblem,
|
|
6239
6476
|
parseGitSpec,
|
|
6240
6477
|
normalizeRepoUrl,
|
|
6241
6478
|
scrubUrlUserinfo,
|
|
6479
|
+
scrubRepoUrlUserinfo,
|
|
6242
6480
|
redactGitOutput,
|
|
6243
6481
|
GIT_MISSING_MESSAGE,
|
|
6244
6482
|
runGit,
|
|
@@ -6278,6 +6516,7 @@ export {
|
|
|
6278
6516
|
GIT_PIN_LOCK_WAIT_MS,
|
|
6279
6517
|
gitRefsPath,
|
|
6280
6518
|
recordGitPin,
|
|
6519
|
+
forgetGitPin,
|
|
6281
6520
|
recordLoadedGitPin,
|
|
6282
6521
|
gitLivenessWarning,
|
|
6283
6522
|
planGitRemoval,
|
|
@@ -6287,6 +6526,7 @@ export {
|
|
|
6287
6526
|
keptBuilds,
|
|
6288
6527
|
gcGitBuilds,
|
|
6289
6528
|
discardBuild,
|
|
6529
|
+
discardUnpinnedBuild,
|
|
6290
6530
|
GIT_STATE_FILENAME,
|
|
6291
6531
|
gitStatePath,
|
|
6292
6532
|
readGitState,
|
|
@@ -6298,6 +6538,7 @@ export {
|
|
|
6298
6538
|
resolveServerEnv,
|
|
6299
6539
|
resolveTimeoutEnv,
|
|
6300
6540
|
ActivationError,
|
|
6541
|
+
shellActivationMessage,
|
|
6301
6542
|
readGitFailedRecord,
|
|
6302
6543
|
gitBuildMissing,
|
|
6303
6544
|
withHeartbeat,
|