@yawlabs/mcp 1.1.10 → 1.1.12
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 +137 -15
- package/README.md +31 -21
- package/dist/{auto-upgrade-BFZR7HIL.js → auto-upgrade-KXOCHAUR.js} +7 -1
- package/dist/{chunk-DQ4KOZI5.js → chunk-PFDIDS6O.js} +385 -145
- package/dist/{chunk-X54WSPEC.js → chunk-SJWGO3WQ.js} +272 -138
- package/dist/{git-source-TFNP7Y3W.js → git-source-W43NBUYR.js} +12 -2
- package/dist/index.js +1847 -1051
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
gitRoot,
|
|
17
17
|
isFeatureEnabled,
|
|
18
18
|
isRegistrySpec,
|
|
19
|
+
launcherBasename,
|
|
19
20
|
log,
|
|
20
21
|
managedNodeBin,
|
|
21
22
|
nodeLaunchKind,
|
|
@@ -41,7 +42,7 @@ import {
|
|
|
41
42
|
stripJsoncComments,
|
|
42
43
|
stripTrailingCommas,
|
|
43
44
|
userConfigDir
|
|
44
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-SJWGO3WQ.js";
|
|
45
46
|
|
|
46
47
|
// src/git-source.ts
|
|
47
48
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -61,6 +62,14 @@ import {
|
|
|
61
62
|
} from "fs";
|
|
62
63
|
import { dirname as dirname4, isAbsolute, join as join7, relative as relative2, resolve as resolve3 } from "path";
|
|
63
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
|
+
|
|
64
73
|
// src/fuzzy.ts
|
|
65
74
|
function levenshtein(a, b) {
|
|
66
75
|
if (a === b) return 0;
|
|
@@ -294,6 +303,24 @@ async function defaultFetchCatalog(catalogUrl = DEFAULT_CATALOG_URL, deps = {})
|
|
|
294
303
|
function withWarnSink(warn) {
|
|
295
304
|
return (url) => defaultFetchCatalog(url, warn ? { warn } : {});
|
|
296
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
|
+
}
|
|
297
324
|
async function resolveCatalogSlug(slug, opts = {}) {
|
|
298
325
|
const url = normalizeCatalogUrl(opts.catalogUrl);
|
|
299
326
|
const fetchCatalog = opts.fetchCatalog ?? withWarnSink(opts.warn);
|
|
@@ -305,8 +332,7 @@ async function resolveCatalogSlug(slug, opts = {}) {
|
|
|
305
332
|
throw new Error(`no server with slug "${slug}" in the Yaw MCP catalog.${hint}`);
|
|
306
333
|
}
|
|
307
334
|
const install = entry.install ?? {};
|
|
308
|
-
|
|
309
|
-
if (install.url || install.type === "remote" || /^(remote|https?|sse|url)$/.test(runtime)) {
|
|
335
|
+
if (isRemoteCatalogEntry(entry)) {
|
|
310
336
|
throw new Error(
|
|
311
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}).`
|
|
312
338
|
);
|
|
@@ -320,16 +346,7 @@ async function resolveCatalogSlug(slug, opts = {}) {
|
|
|
320
346
|
if (!command) {
|
|
321
347
|
throw new Error(`catalog entry "${slug}" install command was empty.`);
|
|
322
348
|
}
|
|
323
|
-
const requiredEnvKeys =
|
|
324
|
-
const optionalEnvKeys = [];
|
|
325
|
-
if (Array.isArray(entry.requiredEnv)) {
|
|
326
|
-
for (const e of entry.requiredEnv) {
|
|
327
|
-
const key = e && typeof e === "object" ? e.key : void 0;
|
|
328
|
-
if (typeof key !== "string" || !ENV_KEY_RE.test(key)) continue;
|
|
329
|
-
(e.optional === true ? optionalEnvKeys : requiredEnvKeys).push(key);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
const optionalOnly = optionalEnvKeys.filter((k) => !requiredEnvKeys.includes(k));
|
|
349
|
+
const { required: requiredEnvKeys, optional: optionalOnly } = catalogEnvKeys(entry);
|
|
333
350
|
const source = typeof entry.repo === "string" ? entry.repo : typeof entry.homepage === "string" ? entry.homepage : void 0;
|
|
334
351
|
return {
|
|
335
352
|
slug,
|
|
@@ -1157,7 +1174,7 @@ var GIT_COMMIT_RE = /^[0-9a-f]{40}$/;
|
|
|
1157
1174
|
function hasControlChar(s) {
|
|
1158
1175
|
for (let i = 0; i < s.length; i++) {
|
|
1159
1176
|
const c = s.charCodeAt(i);
|
|
1160
|
-
if (c < 32 || c
|
|
1177
|
+
if (c < 32 || c >= 127 && c <= 159) return true;
|
|
1161
1178
|
}
|
|
1162
1179
|
return false;
|
|
1163
1180
|
}
|
|
@@ -1476,6 +1493,9 @@ function previewBundlesContent(path2, rawBytes, home = homedir3()) {
|
|
|
1476
1493
|
}
|
|
1477
1494
|
return { ok: true, servers, warnings };
|
|
1478
1495
|
}
|
|
1496
|
+
function rawEntryLoads(entry, home = homedir3()) {
|
|
1497
|
+
return validateEntry(entry, [], home) !== null;
|
|
1498
|
+
}
|
|
1479
1499
|
function hashContent(servers) {
|
|
1480
1500
|
const h = createHash2("sha256");
|
|
1481
1501
|
h.update(JSON.stringify(servers));
|
|
@@ -1706,12 +1726,12 @@ async function readRawUserBundles(home, warnings, path2 = localBundlesPath(userC
|
|
|
1706
1726
|
const readWarning = warnings.find((w) => w.startsWith(`${path2}: ${READ_FAILURE_MARKER}`));
|
|
1707
1727
|
if (readWarning) {
|
|
1708
1728
|
if (readWarning.includes(IS_A_DIRECTORY_DETAIL)) {
|
|
1709
|
-
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.`);
|
|
1710
1730
|
}
|
|
1711
|
-
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.`);
|
|
1712
1732
|
}
|
|
1713
1733
|
const detail = warnings.length > 0 ? ` (${warningText})` : "";
|
|
1714
|
-
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.`);
|
|
1715
1735
|
}
|
|
1716
1736
|
for (const w of warnings) {
|
|
1717
1737
|
log("debug", "bundles.json warning (write path)", { warning: w });
|
|
@@ -1787,7 +1807,8 @@ function launchShapeOf(entry) {
|
|
|
1787
1807
|
return typeof entry.url === "string" && entry.url.length > 0 ? { url: entry.url } : {};
|
|
1788
1808
|
}
|
|
1789
1809
|
function sameLaunch(a, b) {
|
|
1790
|
-
|
|
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);
|
|
1791
1812
|
}
|
|
1792
1813
|
function formatBundleCollision(c, safe = (s) => s) {
|
|
1793
1814
|
const what = c.origin === "catalog" ? "catalog server" : "server";
|
|
@@ -1851,7 +1872,11 @@ function resolveUpsertTarget(servers, entry, origin) {
|
|
|
1851
1872
|
};
|
|
1852
1873
|
}
|
|
1853
1874
|
function mergedUpsertEntry(servers, entry, target) {
|
|
1854
|
-
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
|
+
}
|
|
1855
1880
|
const written = mergeServerEntry(servers[target.idx] ?? {}, entry);
|
|
1856
1881
|
if (target.matchedByNamespace) return written;
|
|
1857
1882
|
return { ...written, namespace: target.namespace ?? written.namespace, id: target.id ?? written.id };
|
|
@@ -2169,8 +2194,13 @@ function describeServerRuntime(server, configDefault, probe) {
|
|
|
2169
2194
|
// src/readline-question.ts
|
|
2170
2195
|
import { createInterface } from "readline/promises";
|
|
2171
2196
|
var QUESTION_CANCELLED = /* @__PURE__ */ Symbol("yaw-mcp:question-cancelled");
|
|
2197
|
+
var QUESTION_EOF = /* @__PURE__ */ Symbol("yaw-mcp:question-eof");
|
|
2172
2198
|
async function questionOrEmpty(rl, prompt) {
|
|
2173
|
-
|
|
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;
|
|
2174
2204
|
const ac = new AbortController();
|
|
2175
2205
|
let cancelled = false;
|
|
2176
2206
|
const onClose = () => ac.abort();
|
|
@@ -2184,7 +2214,7 @@ async function questionOrEmpty(rl, prompt) {
|
|
|
2184
2214
|
return await rl.question(prompt, { signal: ac.signal });
|
|
2185
2215
|
} catch (err) {
|
|
2186
2216
|
if (cancelled) return QUESTION_CANCELLED;
|
|
2187
|
-
if (ac.signal.aborted) return
|
|
2217
|
+
if (ac.signal.aborted) return QUESTION_EOF;
|
|
2188
2218
|
throw err;
|
|
2189
2219
|
} finally {
|
|
2190
2220
|
rl.off("close", onClose);
|
|
@@ -2194,7 +2224,7 @@ async function questionOrEmpty(rl, prompt) {
|
|
|
2194
2224
|
async function readlineAnswer(input, output, question, terminal) {
|
|
2195
2225
|
const rl = createInterface({ input, output, terminal });
|
|
2196
2226
|
try {
|
|
2197
|
-
return await
|
|
2227
|
+
return await questionOrEof(rl, question);
|
|
2198
2228
|
} finally {
|
|
2199
2229
|
rl.close();
|
|
2200
2230
|
}
|
|
@@ -2204,7 +2234,18 @@ async function askYesNo(opts, question, read = readlineAnswer) {
|
|
|
2204
2234
|
const input = opts.io?.stdin ?? process.stdin;
|
|
2205
2235
|
const output = opts.io?.stdout ?? process.stdout;
|
|
2206
2236
|
const raw = await read(input, output, question, opts.io?.terminal);
|
|
2207
|
-
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
|
+
};
|
|
2208
2249
|
}
|
|
2209
2250
|
|
|
2210
2251
|
// src/sidecars-cmd.ts
|
|
@@ -2405,8 +2446,9 @@ var SIDECARS_USAGE = `Usage: yaw-mcp sidecars install [--yes] [--json]
|
|
|
2405
2446
|
so they run from one known version instead of whatever npm's npx cache
|
|
2406
2447
|
happens to hold.
|
|
2407
2448
|
|
|
2408
|
-
Worth running
|
|
2409
|
-
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
|
|
2410
2452
|
install a server stays pinned at whatever was last fetched. Re-run this to
|
|
2411
2453
|
move them forward.
|
|
2412
2454
|
|
|
@@ -2422,7 +2464,12 @@ var SIDECARS_USAGE = `Usage: yaw-mcp sidecars install [--yes] [--json]
|
|
|
2422
2464
|
--yes, -y Allow a git repo's install and build scripts to run. Asked once
|
|
2423
2465
|
per repo; when stdin or stdout is not a TTY, required until the
|
|
2424
2466
|
repo is allowed here. Recorded per repo in
|
|
2425
|
-
~/.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.`;
|
|
2426
2473
|
function parseSidecarsArgs(argv) {
|
|
2427
2474
|
let json = false;
|
|
2428
2475
|
let yes = false;
|
|
@@ -2495,11 +2542,8 @@ function buildGitEntriesFor(servers, bundlesPath, opts, home, print, printErr) {
|
|
|
2495
2542
|
platform: opts.platform,
|
|
2496
2543
|
progress: (l) => print(l),
|
|
2497
2544
|
warn: (w) => printErr(`warning: ${w}`),
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
const answer = await askYesNo(opts, "Proceed? [Y/n] ");
|
|
2501
|
-
return answer === "" || answer === "y" || answer === "yes";
|
|
2502
|
-
},
|
|
2545
|
+
// Ctrl+C there ends the run with exit 130 (runSidecarsInstall).
|
|
2546
|
+
confirm: scriptConsentConfirm(opts, print),
|
|
2503
2547
|
runPm: opts.runPm
|
|
2504
2548
|
},
|
|
2505
2549
|
bundlesPath !== null && bundlesPath !== localBundlesPath(userConfigDir(home)),
|
|
@@ -2546,10 +2590,11 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2546
2590
|
...over,
|
|
2547
2591
|
error: over.error ?? gitError
|
|
2548
2592
|
});
|
|
2549
|
-
const done = (exitCode, installed = []) => ({
|
|
2593
|
+
const done = (exitCode, installed = [], updateError = null) => ({
|
|
2550
2594
|
exitCode: exitCode === 0 && gitBad + gitUnconsented > 0 ? 1 : exitCode,
|
|
2551
2595
|
installed,
|
|
2552
|
-
lines
|
|
2596
|
+
lines,
|
|
2597
|
+
updateError
|
|
2553
2598
|
});
|
|
2554
2599
|
const couldNotPrepare = (err) => {
|
|
2555
2600
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -2582,21 +2627,31 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2582
2627
|
return done(1);
|
|
2583
2628
|
}
|
|
2584
2629
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
print("Git sources:");
|
|
2595
|
-
for (const g of git) {
|
|
2596
|
-
print(` ${g.namespace} ${g.commit ? g.commit.slice(0, 12) : "(no commit)"} ${g.status}`);
|
|
2597
|
-
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();
|
|
2598
2639
|
}
|
|
2599
|
-
|
|
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;
|
|
2600
2655
|
}
|
|
2601
2656
|
if (specs.length === 0) {
|
|
2602
2657
|
if (bundles.config === null && bundles.path !== null) {
|
|
@@ -2688,33 +2743,39 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2688
2743
|
namespaces: s.namespaces
|
|
2689
2744
|
}));
|
|
2690
2745
|
const missing = installed.filter((i) => i.version === null);
|
|
2746
|
+
const nothingLanded = missing.length === installed.length;
|
|
2691
2747
|
print("Installed:");
|
|
2692
2748
|
for (const i of installed) print(` ${i.pkg} ${i.version ?? "NOT FOUND"}`);
|
|
2693
|
-
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) {
|
|
2694
2754
|
print();
|
|
2695
2755
|
print(`${missing.length} package(s) did not land; those servers keep resolving from the npx cache.`);
|
|
2696
2756
|
}
|
|
2697
|
-
if (updateError !== null) {
|
|
2757
|
+
if (updateError !== null && !nothingLanded) {
|
|
2698
2758
|
print();
|
|
2699
2759
|
print(`npm update failed (exit ${updateCode}). The installed copies are usable, but a server`);
|
|
2700
2760
|
print('configured "@latest" may still be on the version it was already on.');
|
|
2701
2761
|
}
|
|
2702
|
-
|
|
2703
|
-
|
|
2762
|
+
if (!nothingLanded) {
|
|
2763
|
+
print();
|
|
2764
|
+
print("These versions are now fixed. Re-run this command to move them forward.");
|
|
2765
|
+
}
|
|
2704
2766
|
const unhosted = await unhostedReasons(servers, opts, home, bundles);
|
|
2705
|
-
if (unhosted.length > 0) {
|
|
2767
|
+
if (unhosted.length > 0 && !nothingLanded) {
|
|
2706
2768
|
print();
|
|
2707
|
-
print("
|
|
2769
|
+
print("None of these servers will be hosted on oam:");
|
|
2708
2770
|
for (const reason of unhosted) print(` ${reason}`);
|
|
2709
|
-
print("
|
|
2710
|
-
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.");
|
|
2711
2773
|
}
|
|
2712
|
-
const nothingLanded = missing.length === installed.length;
|
|
2713
2774
|
const error = nothingLanded ? "npm exited 0 but no requested package resolved in the managed tree" : null;
|
|
2714
2775
|
if (opts.json) {
|
|
2715
2776
|
write(doc({ installed, conflicts, skipped, error, updateError, unhosted, markerError }));
|
|
2716
2777
|
}
|
|
2717
|
-
return done(nothingLanded ? 1 : 0, installed);
|
|
2778
|
+
return done(nothingLanded ? 1 : 0, installed, updateError);
|
|
2718
2779
|
} finally {
|
|
2719
2780
|
release?.();
|
|
2720
2781
|
}
|
|
@@ -2753,8 +2814,13 @@ var SEP = "(?:[^\\S\\r\\n]*:\\s+|[^\\S\\r\\n]+)";
|
|
|
2753
2814
|
var QUOTE = "[\"'`]?";
|
|
2754
2815
|
var ENV_WORDS = `(?:(?:env|environment)${GAP})?(?:(?:variable|var)${GAP})?`;
|
|
2755
2816
|
var LEADING_ENV_WORDS = `(?:(?:env|environment)${SEP})?(?:(?:variables?|vars?)${SEP})?`;
|
|
2817
|
+
var LEADING_CREDENTIAL_NOUN = `(?:api(?:${GAP}|-)?keys?|tokens?|credentials?|secrets?)${SEP}`;
|
|
2756
2818
|
var MISSING_PATTERNS = [
|
|
2757
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
|
+
),
|
|
2758
2824
|
new RegExp(
|
|
2759
2825
|
`\\b(${NAME})${QUOTE}${GAP}${ENV_WORDS}(?:is${GAP}(?:required|missing|empty|undefined)|(?:is${GAP})?(?:not${GAP}set|unset|not${GAP}provided))\\b`,
|
|
2760
2826
|
"gi"
|
|
@@ -2953,7 +3019,10 @@ function resolveMaxResultBytes(env = process.env) {
|
|
|
2953
3019
|
}
|
|
2954
3020
|
function cutToBytes(text, maxBytes) {
|
|
2955
3021
|
if (maxBytes <= 0) return "";
|
|
2956
|
-
|
|
3022
|
+
return cutEncodedToBytes(text, Buffer.from(text, "utf8"), maxBytes);
|
|
3023
|
+
}
|
|
3024
|
+
function cutEncodedToBytes(text, buf, maxBytes) {
|
|
3025
|
+
if (maxBytes <= 0) return "";
|
|
2957
3026
|
if (buf.byteLength <= maxBytes) return text;
|
|
2958
3027
|
const cut = buf.subarray(0, maxBytes).toString("utf8");
|
|
2959
3028
|
if (!cut.endsWith("\uFFFD")) return cut;
|
|
@@ -2963,12 +3032,13 @@ function cutToBytes(text, maxBytes) {
|
|
|
2963
3032
|
}
|
|
2964
3033
|
function fitTextBlock(item, budget) {
|
|
2965
3034
|
if (typeof item.text !== "string" || budget <= 0) return null;
|
|
3035
|
+
const encoded = Buffer.from(item.text, "utf8");
|
|
2966
3036
|
let lo = 0;
|
|
2967
|
-
let hi =
|
|
3037
|
+
let hi = Math.min(encoded.byteLength, budget);
|
|
2968
3038
|
let best = null;
|
|
2969
3039
|
while (lo <= hi) {
|
|
2970
3040
|
const mid = Math.floor((lo + hi) / 2);
|
|
2971
|
-
const cut =
|
|
3041
|
+
const cut = cutEncodedToBytes(item.text, encoded, mid);
|
|
2972
3042
|
if (cut.length === 0) {
|
|
2973
3043
|
lo = mid + 1;
|
|
2974
3044
|
continue;
|
|
@@ -3011,16 +3081,17 @@ function capContent(content, maxBytes) {
|
|
|
3011
3081
|
let droppedBlocks = 0;
|
|
3012
3082
|
let truncatedText = false;
|
|
3013
3083
|
const noticeReserve = MAX_NOTICE_BYTES;
|
|
3014
|
-
const contentBudget = maxBytes - noticeReserve;
|
|
3084
|
+
const contentBudget = maxBytes - noticeReserve - ARRAY_BRACKET_BYTES;
|
|
3015
3085
|
for (let i = 0; i < content.length; i++) {
|
|
3016
3086
|
const item = content[i];
|
|
3017
3087
|
const size = serializedBytes(item);
|
|
3018
|
-
|
|
3088
|
+
const separators = kept.length + 1;
|
|
3089
|
+
if (Number.isFinite(size) && used + size + separators <= contentBudget) {
|
|
3019
3090
|
kept.push(item);
|
|
3020
3091
|
used += size;
|
|
3021
3092
|
continue;
|
|
3022
3093
|
}
|
|
3023
|
-
const remaining = contentBudget - used;
|
|
3094
|
+
const remaining = contentBudget - used - separators;
|
|
3024
3095
|
if (item.type === "text" && typeof item.text === "string" && remaining > MIN_USEFUL_TAIL_BYTES) {
|
|
3025
3096
|
const fitted = fitTextBlock(item, remaining);
|
|
3026
3097
|
if (fitted) {
|
|
@@ -3038,6 +3109,7 @@ function capContent(content, maxBytes) {
|
|
|
3038
3109
|
return { content: kept, capped: true, bytesRaw, bytesKept: used };
|
|
3039
3110
|
}
|
|
3040
3111
|
var MIN_USEFUL_TAIL_BYTES = 512;
|
|
3112
|
+
var ARRAY_BRACKET_BYTES = 2;
|
|
3041
3113
|
var MAX_NOTICE_BYTES = (() => {
|
|
3042
3114
|
const worst = capNotice(999999999, 999999999, 999999999, true);
|
|
3043
3115
|
return Buffer.byteLength(JSON.stringify({ type: "text", text: worst }), "utf8");
|
|
@@ -3053,8 +3125,16 @@ var MAX_UPSTREAM_INSTRUCTIONS_BYTES = 2e3;
|
|
|
3053
3125
|
var FENCE_OPEN = "<<<BEGIN UPSTREAM SERVER TEXT";
|
|
3054
3126
|
var FENCE_CLOSE = "<<<END UPSTREAM SERVER TEXT";
|
|
3055
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
|
+
}
|
|
3056
3134
|
var FORGED_MARKERS = new RegExp(
|
|
3057
|
-
[FENCE_OPEN, FENCE_CLOSE, BROKER_VOICE
|
|
3135
|
+
[fencePattern(FENCE_OPEN), fencePattern(FENCE_CLOSE), `\\[\\s*${escapeRegex(BROKER_VOICE.slice(1, -1))}\\s*\\]`].join(
|
|
3136
|
+
"|"
|
|
3137
|
+
),
|
|
3058
3138
|
"gi"
|
|
3059
3139
|
);
|
|
3060
3140
|
var NEUTRALIZED = "[redacted-marker]";
|
|
@@ -3212,8 +3292,13 @@ async function fetchWithRedirects(url, maxHops = 5, totalDeadline = AbortSignal.
|
|
|
3212
3292
|
if (res.statusCode >= 300 && res.statusCode < 400) {
|
|
3213
3293
|
const loc = res.headers.location;
|
|
3214
3294
|
if (!loc) throw new Error(`Redirect without Location header from ${current}`);
|
|
3215
|
-
current = Array.isArray(loc) ? loc[0] : loc;
|
|
3216
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
|
+
}
|
|
3217
3302
|
continue;
|
|
3218
3303
|
}
|
|
3219
3304
|
if (res.statusCode !== 200) {
|
|
@@ -3406,10 +3491,9 @@ async function resolveUv() {
|
|
|
3406
3491
|
log("info", "uv bootstrap complete", { bin: finalBin });
|
|
3407
3492
|
return finalBin;
|
|
3408
3493
|
}
|
|
3409
|
-
var UV_WIN_EXE_EXT = /\.(?:exe|cmd|bat)$/i;
|
|
3410
3494
|
function uvLaunchKind(command) {
|
|
3411
3495
|
if (/[\\/]/.test(command)) return null;
|
|
3412
|
-
const base = command
|
|
3496
|
+
const base = launcherBasename(command);
|
|
3413
3497
|
if (base === "uv") return "uv";
|
|
3414
3498
|
if (base === "uvx") return "uvx";
|
|
3415
3499
|
return null;
|
|
@@ -3602,17 +3686,25 @@ var MAX_RESOURCES_PER_SERVER = 1e3;
|
|
|
3602
3686
|
var MAX_PROMPTS_PER_SERVER = 1e3;
|
|
3603
3687
|
var MAX_LIST_PAGES = 50;
|
|
3604
3688
|
var ActivationError = class extends Error {
|
|
3605
|
-
constructor(message, category, stderrTail, cause) {
|
|
3689
|
+
constructor(message, category, stderrTail, cause, configPointer) {
|
|
3606
3690
|
super(message);
|
|
3607
3691
|
this.category = category;
|
|
3608
3692
|
this.stderrTail = stderrTail;
|
|
3609
3693
|
this.cause = cause;
|
|
3694
|
+
this.configPointer = configPointer;
|
|
3610
3695
|
this.name = "ActivationError";
|
|
3611
3696
|
}
|
|
3612
3697
|
category;
|
|
3613
3698
|
stderrTail;
|
|
3614
3699
|
cause;
|
|
3700
|
+
configPointer;
|
|
3615
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
|
+
}
|
|
3616
3708
|
function isUnresolvedSecretRef(value) {
|
|
3617
3709
|
return value.startsWith("${secret:") && value.endsWith("}");
|
|
3618
3710
|
}
|
|
@@ -3655,7 +3747,28 @@ function localRedactionMap(configEnv, serverEnv, secretValues) {
|
|
|
3655
3747
|
return { ...out, ...secretValues };
|
|
3656
3748
|
}
|
|
3657
3749
|
function hasUrlPassword(value) {
|
|
3658
|
-
|
|
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)}`;
|
|
3659
3772
|
}
|
|
3660
3773
|
function credentialShapedParentEnv() {
|
|
3661
3774
|
const out = {};
|
|
@@ -3698,8 +3811,15 @@ function redactSecretsInOutput(text, env) {
|
|
|
3698
3811
|
out = out.replace(/\$\{secret:([a-zA-Z0-9_.-]+)\}/g, "${secret:***}");
|
|
3699
3812
|
return out;
|
|
3700
3813
|
}
|
|
3701
|
-
function withConfigPointer(
|
|
3702
|
-
|
|
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
|
+
);
|
|
3703
3823
|
}
|
|
3704
3824
|
var GIT_FAILED_TAIL_CAP = 600;
|
|
3705
3825
|
function quotedFailedTail(tail) {
|
|
@@ -3741,12 +3861,12 @@ async function gitBuildMissing(config, home, consented) {
|
|
|
3741
3861
|
}
|
|
3742
3862
|
async function gitRepoConsented(config) {
|
|
3743
3863
|
if (!config.git?.commit || gitEntryBuilt(config.namespace, config.git)) return void 0;
|
|
3744
|
-
const { hasRepoConsent: hasRepoConsent2 } = await import("./git-source-
|
|
3864
|
+
const { hasRepoConsent: hasRepoConsent2 } = await import("./git-source-W43NBUYR.js");
|
|
3745
3865
|
return hasRepoConsent2(config.git.url, homedir6());
|
|
3746
3866
|
}
|
|
3747
3867
|
async function recordActivatedGitPin(namespace, commit) {
|
|
3748
3868
|
try {
|
|
3749
|
-
const { recordLoadedGitPin: recordLoadedGitPin2 } = await import("./git-source-
|
|
3869
|
+
const { recordLoadedGitPin: recordLoadedGitPin2 } = await import("./git-source-W43NBUYR.js");
|
|
3750
3870
|
await recordLoadedGitPin2(namespace, commit, { home: homedir6(), cwd: process.cwd() });
|
|
3751
3871
|
} catch (e) {
|
|
3752
3872
|
log("debug", "Could not record the git build an activation uses", { namespace, error: e.message });
|
|
@@ -3774,11 +3894,15 @@ function unstartableFileMessage(code, err, command) {
|
|
|
3774
3894
|
}
|
|
3775
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.`;
|
|
3776
3896
|
}
|
|
3897
|
+
var SPAWN_ERRNO = /\b(?:ENOENT|EACCES|EPERM)\b/;
|
|
3777
3898
|
function categorizeSpawnError(err) {
|
|
3778
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";
|
|
3779
3903
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3780
|
-
if (
|
|
3781
|
-
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";
|
|
3782
3906
|
return "unknown";
|
|
3783
3907
|
}
|
|
3784
3908
|
function remoteFailureDetail(err, resolved) {
|
|
@@ -3794,7 +3918,11 @@ function redactActivationMessage(err, env) {
|
|
|
3794
3918
|
if (!(err instanceof ActivationError)) return err;
|
|
3795
3919
|
const safe = redactSecretsInOutput(err.message, env);
|
|
3796
3920
|
if (safe === err.message) return err;
|
|
3797
|
-
|
|
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);
|
|
3798
3926
|
}
|
|
3799
3927
|
function withStderrTail(err, stderrRing, env) {
|
|
3800
3928
|
if (!(err instanceof ActivationError) || err.stderrTail) return err;
|
|
@@ -3802,8 +3930,12 @@ function withStderrTail(err, stderrRing, env) {
|
|
|
3802
3930
|
if (trimmed.length === 0) return err;
|
|
3803
3931
|
const safe = redactSecretsInOutput(trimmed, env);
|
|
3804
3932
|
const oomHint = oamHeapOomHint(trimmed);
|
|
3805
|
-
const
|
|
3806
|
-
|
|
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);
|
|
3807
3939
|
}
|
|
3808
3940
|
var oamDowngradedNamespaces = /* @__PURE__ */ new Map();
|
|
3809
3941
|
function isPinnedToNode(config) {
|
|
@@ -3912,7 +4044,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3912
4044
|
if (downstreamCaps?.sampling) capabilities.sampling = downstreamCaps.sampling;
|
|
3913
4045
|
if (downstreamCaps?.roots) capabilities.roots = {};
|
|
3914
4046
|
const client = new Client(
|
|
3915
|
-
{ name: "yaw-mcp", version: true ? "1.1.
|
|
4047
|
+
{ name: "yaw-mcp", version: true ? "1.1.12" : "dev" },
|
|
3916
4048
|
{ capabilities }
|
|
3917
4049
|
);
|
|
3918
4050
|
if (bridge && capabilities.elicitation) {
|
|
@@ -3939,7 +4071,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3939
4071
|
let spawnedCommand = config.command;
|
|
3940
4072
|
if (config.type === "local") {
|
|
3941
4073
|
const notBuilt = await gitBuildMissing(config, void 0, await gitRepoConsented(config));
|
|
3942
|
-
if (notBuilt !== null) throw
|
|
4074
|
+
if (notBuilt !== null) throw withConfigPointer(notBuilt, config, "install_failure");
|
|
3943
4075
|
if (config.git?.commit) await recordActivatedGitPin(config.namespace, config.git.commit);
|
|
3944
4076
|
if (!config.command) {
|
|
3945
4077
|
throw new Error("command is required for local servers");
|
|
@@ -3986,8 +4118,9 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3986
4118
|
} catch (err) {
|
|
3987
4119
|
if (err instanceof ActivationError) throw err;
|
|
3988
4120
|
const message = err instanceof Error ? err.message : String(err);
|
|
3989
|
-
throw
|
|
3990
|
-
|
|
4121
|
+
throw withConfigPointer(
|
|
4122
|
+
`Server "${config.namespace}" could not resolve its launch command. ${message}`,
|
|
4123
|
+
config,
|
|
3991
4124
|
categorizeSpawnError(err),
|
|
3992
4125
|
void 0,
|
|
3993
4126
|
err
|
|
@@ -4029,8 +4162,9 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4029
4162
|
url = new URL(config.url);
|
|
4030
4163
|
} catch (err) {
|
|
4031
4164
|
const message = err instanceof Error ? err.message : String(err);
|
|
4032
|
-
throw
|
|
4033
|
-
|
|
4165
|
+
throw withConfigPointer(
|
|
4166
|
+
`Server "${config.namespace}" has an invalid url "${displayRemoteUrl(config.url)}": ${message}`,
|
|
4167
|
+
config,
|
|
4034
4168
|
"unknown",
|
|
4035
4169
|
void 0,
|
|
4036
4170
|
err
|
|
@@ -4064,14 +4198,10 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4064
4198
|
);
|
|
4065
4199
|
} catch (err) {
|
|
4066
4200
|
if (err instanceof InvalidResolvedValueError) {
|
|
4067
|
-
throw
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
),
|
|
4072
|
-
"unknown",
|
|
4073
|
-
void 0,
|
|
4074
|
-
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"
|
|
4075
4205
|
);
|
|
4076
4206
|
}
|
|
4077
4207
|
throw err;
|
|
@@ -4156,7 +4286,8 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4156
4286
|
if (config.type !== "local") {
|
|
4157
4287
|
category = timedOut ? "init_timeout" : "protocol_error";
|
|
4158
4288
|
const detail = timedOut ? "" : remoteFailureDetail(err, resolvedServerEnv);
|
|
4159
|
-
|
|
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}` : ""}`;
|
|
4160
4291
|
} else if (timedOut) {
|
|
4161
4292
|
category = "init_timeout";
|
|
4162
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)}` : ""}`;
|
|
@@ -4172,20 +4303,22 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4172
4303
|
if (unstartable) {
|
|
4173
4304
|
message = `${unstartableFileMessage(unstartable, err, config.command)}${spawnedNote}`;
|
|
4174
4305
|
} else if (category === "spawn_failure") {
|
|
4175
|
-
|
|
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}`;
|
|
4176
4309
|
} else {
|
|
4177
4310
|
message = err instanceof Error ? err.message : String(err);
|
|
4178
4311
|
}
|
|
4179
4312
|
}
|
|
4180
|
-
message = withConfigPointer(message, config);
|
|
4181
4313
|
const redactedTail = trimmedStderr ? redactSecretsInOutput(trimmedStderr, resolvedServerEnv) : void 0;
|
|
4182
|
-
throw
|
|
4314
|
+
throw withConfigPointer(message, config, category, redactedTail, err);
|
|
4183
4315
|
}
|
|
4184
4316
|
let runtimeFields = {};
|
|
4185
4317
|
if (attempt.oamRewriteApplied) {
|
|
4186
4318
|
runtimeFields = suppressRewrites ? { runtime: "node", downgradedFromOam: true } : { runtime: "oam", oamVersion: attempt.oamVersion };
|
|
4187
4319
|
} else if (attempt.managedRewriteApplied) {
|
|
4188
|
-
|
|
4320
|
+
const oamPinFields = isPinnedToNode(config) ? { downgradedFromOam: true, oamPinned: true } : {};
|
|
4321
|
+
runtimeFields = suppressRewrites ? { runtime: "node", ...oamPinFields, downgradedFromManaged: true } : { runtime: "node", managedSpawn: true, ...oamPinFields };
|
|
4189
4322
|
} else if (config.type === "local" && (isPinnedToNode(config) || isPinnedToNpx(config))) {
|
|
4190
4323
|
const oamPin = isPinnedToNode(config);
|
|
4191
4324
|
const managedPin = isPinnedToNpx(config);
|
|
@@ -4398,7 +4531,10 @@ async function fetchResourcesFromUpstream(client, namespace, opts = {}) {
|
|
|
4398
4531
|
_meta: r._meta
|
|
4399
4532
|
}));
|
|
4400
4533
|
} catch (err) {
|
|
4401
|
-
if (!opts.throwOnError)
|
|
4534
|
+
if (!opts.throwOnError) {
|
|
4535
|
+
warnSwallowedListError(err, namespace, "resources/list");
|
|
4536
|
+
return [];
|
|
4537
|
+
}
|
|
4402
4538
|
const message = err instanceof Error ? err.message : String(err);
|
|
4403
4539
|
throw new Error(`"${namespace}" returned an error on resources/list: ${message}`);
|
|
4404
4540
|
}
|
|
@@ -4430,7 +4566,10 @@ async function fetchPromptsFromUpstream(client, namespace, opts = {}) {
|
|
|
4430
4566
|
_meta: p._meta
|
|
4431
4567
|
}));
|
|
4432
4568
|
} catch (err) {
|
|
4433
|
-
if (!opts.throwOnError)
|
|
4569
|
+
if (!opts.throwOnError) {
|
|
4570
|
+
warnSwallowedListError(err, namespace, "prompts/list");
|
|
4571
|
+
return [];
|
|
4572
|
+
}
|
|
4434
4573
|
const message = err instanceof Error ? err.message : String(err);
|
|
4435
4574
|
throw new Error(`"${namespace}" returned an error on prompts/list: ${message}`);
|
|
4436
4575
|
}
|
|
@@ -4438,6 +4577,14 @@ async function fetchPromptsFromUpstream(client, namespace, opts = {}) {
|
|
|
4438
4577
|
function isMethodNotFound(err) {
|
|
4439
4578
|
return err?.code === -32601;
|
|
4440
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
|
+
}
|
|
4441
4588
|
async function fetchToolsFromUpstream(client, namespace, opts = {}) {
|
|
4442
4589
|
let all;
|
|
4443
4590
|
try {
|
|
@@ -4498,16 +4645,6 @@ function isBareUsername(user) {
|
|
|
4498
4645
|
if (!/^[A-Za-z0-9._-]{1,19}$/.test(user)) return false;
|
|
4499
4646
|
return !/^(gh[pousr]_|github_pat_|glpat-|glptt-|xox[abp]-)/i.test(user);
|
|
4500
4647
|
}
|
|
4501
|
-
function printable(s) {
|
|
4502
|
-
return s.replace(/[^\x20-\x7e]/g, "?");
|
|
4503
|
-
}
|
|
4504
|
-
function hasControlBytes(s) {
|
|
4505
|
-
for (let i = 0; i < s.length; i++) {
|
|
4506
|
-
const c = s.charCodeAt(i);
|
|
4507
|
-
if (c < 32 || c >= 127 && c <= 159) return true;
|
|
4508
|
-
}
|
|
4509
|
-
return false;
|
|
4510
|
-
}
|
|
4511
4648
|
function gitRefProblem(ref) {
|
|
4512
4649
|
if (ref === "") return "the ref after # is empty";
|
|
4513
4650
|
if (ref.startsWith("-")) return 'the ref cannot start with "-"';
|
|
@@ -4518,7 +4655,7 @@ function gitRefProblem(ref) {
|
|
|
4518
4655
|
}
|
|
4519
4656
|
function parseGitSpec(raw) {
|
|
4520
4657
|
const fail = (error) => ({ ok: false, error });
|
|
4521
|
-
if (
|
|
4658
|
+
if (hasControlChar(raw)) return fail("--git: the URL contains control characters.");
|
|
4522
4659
|
const value = raw.trim();
|
|
4523
4660
|
if (value === "") return fail("--git requires a URL");
|
|
4524
4661
|
if (value.startsWith("-")) return fail('--git: the URL cannot start with "-".');
|
|
@@ -4576,7 +4713,7 @@ function parseGitSpec(raw) {
|
|
|
4576
4713
|
if (scp) {
|
|
4577
4714
|
const [, user, host = "", path2 = ""] = scp;
|
|
4578
4715
|
if (host.length === 1) return fail("--git: local paths need a file:// URL (file:///C:/path/to/repo).");
|
|
4579
|
-
if (path2.startsWith("
|
|
4716
|
+
if (path2.startsWith("//")) return fail(`--git: not a git URL. Use ${GIT_URL_FORMS}.`);
|
|
4580
4717
|
return withRef({ url, protocol: "ssh", host: host.toLowerCase(), ...user ? { username: user } : {} });
|
|
4581
4718
|
}
|
|
4582
4719
|
return fail(`--git: not a git URL. Use ${GIT_URL_FORMS}.`);
|
|
@@ -4594,7 +4731,11 @@ function normalizeRepoUrl(url) {
|
|
|
4594
4731
|
if (!spec.ok) return tidy(url.trim());
|
|
4595
4732
|
const bare = spec.spec.url;
|
|
4596
4733
|
if (spec.spec.protocol === "file") {
|
|
4597
|
-
let path3 =
|
|
4734
|
+
let path3 = new URL(bare).pathname;
|
|
4735
|
+
try {
|
|
4736
|
+
path3 = decodeURIComponent(path3);
|
|
4737
|
+
} catch {
|
|
4738
|
+
}
|
|
4598
4739
|
if (/^\/[A-Za-z]:/.test(path3)) path3 = path3.slice(1).toLowerCase();
|
|
4599
4740
|
return `file:${tidy(path3)}`;
|
|
4600
4741
|
}
|
|
@@ -4604,7 +4745,21 @@ function normalizeRepoUrl(url) {
|
|
|
4604
4745
|
return `${spec.spec.host}/${tidy(path2).replace(/^\/+/, "")}`;
|
|
4605
4746
|
}
|
|
4606
4747
|
function scrubUrlUserinfo(text) {
|
|
4607
|
-
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;
|
|
4608
4763
|
}
|
|
4609
4764
|
function redactGitOutput(text, secrets = {}) {
|
|
4610
4765
|
return scrubUrlUserinfo(redactSecretsInOutput(text, secrets));
|
|
@@ -4723,7 +4878,7 @@ async function listRemoteRefs(spec, git, tokenSecret, shared = false) {
|
|
|
4723
4878
|
const access = gitAccessFailure(spec, r.stderr, tokenSecret, shared);
|
|
4724
4879
|
if (access) return { ok: false, exitCode: 1, message: access };
|
|
4725
4880
|
const tail = redactGitOutput(lastLines(r.stderr), git.secrets);
|
|
4726
|
-
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)}:
|
|
4727
4882
|
${tail}` };
|
|
4728
4883
|
}
|
|
4729
4884
|
const refs = /* @__PURE__ */ new Map();
|
|
@@ -4753,7 +4908,7 @@ function resolveRefIn(spec, remote) {
|
|
|
4753
4908
|
return {
|
|
4754
4909
|
ok: false,
|
|
4755
4910
|
exitCode: 1,
|
|
4756
|
-
message: `${
|
|
4911
|
+
message: `${scrubRepoUrlUserinfo(spec.url)} has no default branch to track. Name one: --git <url>#<branch>`
|
|
4757
4912
|
};
|
|
4758
4913
|
if (headTarget?.startsWith("refs/heads/")) {
|
|
4759
4914
|
return { ok: true, ref: headTarget.slice("refs/heads/".length), kind: "branch", commit: head };
|
|
@@ -4768,7 +4923,7 @@ function resolveRefIn(spec, remote) {
|
|
|
4768
4923
|
if (/^[0-9a-f]{40}$/i.test(ref)) return { ok: true, ref: ref.toLowerCase(), kind: "sha", commit: ref.toLowerCase() };
|
|
4769
4924
|
if (/^[0-9a-f]{4,39}$/i.test(ref))
|
|
4770
4925
|
return { ok: true, ref: ref.toLowerCase(), kind: "sha", shortSha: ref.toLowerCase() };
|
|
4771
|
-
const safe =
|
|
4926
|
+
const safe = scrubRepoUrlUserinfo(spec.url);
|
|
4772
4927
|
return {
|
|
4773
4928
|
ok: false,
|
|
4774
4929
|
exitCode: 1,
|
|
@@ -5108,14 +5263,15 @@ function readManifestFile(file, label, warnings, allowSubdir) {
|
|
|
5108
5263
|
}
|
|
5109
5264
|
}
|
|
5110
5265
|
if (m.version !== void 0 && m.version !== 1) {
|
|
5266
|
+
const shown = printable(JSON.stringify(m.version) ?? "");
|
|
5111
5267
|
warnings.push(
|
|
5112
|
-
`${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.`
|
|
5113
5269
|
);
|
|
5114
5270
|
}
|
|
5115
5271
|
const str2 = (key) => {
|
|
5116
5272
|
const v = m[key];
|
|
5117
5273
|
if (v === void 0) return void 0;
|
|
5118
|
-
if (typeof v !== "string" || v.trim() === "" ||
|
|
5274
|
+
if (typeof v !== "string" || v.trim() === "" || hasControlChar(v)) {
|
|
5119
5275
|
warnings.push(`${label}: "${key}" ignored: not a non-empty string.`);
|
|
5120
5276
|
return void 0;
|
|
5121
5277
|
}
|
|
@@ -5163,8 +5319,8 @@ function readManifestFile(file, label, warnings, allowSubdir) {
|
|
|
5163
5319
|
else warnings.push(`${label}: env "${k}" secret name ignored: letters, digits, "_", "." or "-" only.`);
|
|
5164
5320
|
}
|
|
5165
5321
|
if (d.required === true) decl.required = true;
|
|
5166
|
-
if (typeof d.help === "string" && !
|
|
5167
|
-
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)) {
|
|
5168
5324
|
if (decl.secret) warnings.push(`${label}: env "${k}" default ignored: a secret has no default.`);
|
|
5169
5325
|
else decl.default = d.default;
|
|
5170
5326
|
}
|
|
@@ -5309,6 +5465,13 @@ function insideRelative(base, abs) {
|
|
|
5309
5465
|
if (rel === "" || rel.startsWith("..") || /^[A-Za-z]:/.test(rel) || rel.startsWith("/")) return null;
|
|
5310
5466
|
return rel.replace(/\\/g, "/");
|
|
5311
5467
|
}
|
|
5468
|
+
function isRegularFile(path2) {
|
|
5469
|
+
try {
|
|
5470
|
+
return statSync4(path2).isFile();
|
|
5471
|
+
} catch {
|
|
5472
|
+
return false;
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5312
5475
|
function inferredEntry(pkgDir) {
|
|
5313
5476
|
const pkg = readJsonObject(join7(pkgDir, "package.json"));
|
|
5314
5477
|
const hit = packageEntry(pkgDir, typeof pkg?.name === "string" ? pkg.name : "");
|
|
@@ -5336,7 +5499,7 @@ function consentLines(scripts, manifest, namespace, configs = []) {
|
|
|
5336
5499
|
const parts = secrets.map(([k, d]) => `${d.secret} (${k})${d.help ? ` -- ${d.help}` : ""}`);
|
|
5337
5500
|
lines.push(`Needs secrets: ${parts.join(", ")}`);
|
|
5338
5501
|
}
|
|
5339
|
-
return lines.map(
|
|
5502
|
+
return lines.map(printable);
|
|
5340
5503
|
}
|
|
5341
5504
|
async function buildGitSource(req, ctx) {
|
|
5342
5505
|
const root = gitRoot(ctx.home);
|
|
@@ -5398,15 +5561,17 @@ async function buildLocked(req, ctx, root) {
|
|
|
5398
5561
|
const gitCtx = prepared.run;
|
|
5399
5562
|
const secrets = prepared.secrets;
|
|
5400
5563
|
const redact = (text) => redactGitOutput(lastLines(text), secrets);
|
|
5401
|
-
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;
|
|
5402
5567
|
const fullKnown = /^[0-9a-f]{40}$/.test(req.commit);
|
|
5403
5568
|
const reuse = (ns, commit2) => {
|
|
5404
5569
|
const dir = gitBuildDir(ns, commit2, ctx.home);
|
|
5405
5570
|
const marker2 = readBuildMarker(dir, commit2);
|
|
5406
5571
|
if (!marker2) return null;
|
|
5407
|
-
const { manifest: manifest2, warnings } = readGitManifest(dir,
|
|
5572
|
+
const { manifest: manifest2, warnings } = readGitManifest(dir, reqSubdir);
|
|
5408
5573
|
const subdir2 = subdirOf(manifest2);
|
|
5409
|
-
if ((marker2.subdir ?? "") !== (subdir2 ?? "")) {
|
|
5574
|
+
if (tidySubdir(marker2.subdir ?? "") !== (subdir2 ?? "")) {
|
|
5410
5575
|
return {
|
|
5411
5576
|
ok: false,
|
|
5412
5577
|
exitCode: 1,
|
|
@@ -5417,11 +5582,13 @@ async function buildLocked(req, ctx, root) {
|
|
|
5417
5582
|
}
|
|
5418
5583
|
for (const w of warnings) warn(w);
|
|
5419
5584
|
const entry2 = (req.entry ?? marker2.entry).replace(/\\/g, "/");
|
|
5420
|
-
|
|
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";
|
|
5421
5588
|
return {
|
|
5422
5589
|
ok: false,
|
|
5423
5590
|
exitCode: 1,
|
|
5424
|
-
message: printable(`Built ${commit2.slice(0, 7)}
|
|
5591
|
+
message: printable(`Built ${commit2.slice(0, 7)} but its entry ${entry2} ${why}. Pass --entry <file>.`)
|
|
5425
5592
|
};
|
|
5426
5593
|
}
|
|
5427
5594
|
return {
|
|
@@ -5440,7 +5607,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5440
5607
|
if (req.namespace && fullKnown && !ancestorCheck) {
|
|
5441
5608
|
const hit = reuse(req.namespace, req.commit);
|
|
5442
5609
|
if (hit) {
|
|
5443
|
-
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)}`);
|
|
5444
5611
|
return hit;
|
|
5445
5612
|
}
|
|
5446
5613
|
}
|
|
@@ -5457,10 +5624,10 @@ async function buildLocked(req, ctx, root) {
|
|
|
5457
5624
|
}
|
|
5458
5625
|
}
|
|
5459
5626
|
if (record && namespace && /^[0-9a-f]{40}$/.test(commit)) {
|
|
5460
|
-
const
|
|
5627
|
+
const failedRecord = { commit, at: (ctx.now?.() ?? /* @__PURE__ */ new Date()).toISOString(), step, tail: redact(tail) };
|
|
5461
5628
|
try {
|
|
5462
5629
|
mkdirSync2(dirname4(gitFailedPath(namespace, commit, ctx.home)), { recursive: true, mode: 448 });
|
|
5463
|
-
writeFileSync2(gitFailedPath(namespace, commit, ctx.home), `${JSON.stringify(
|
|
5630
|
+
writeFileSync2(gitFailedPath(namespace, commit, ctx.home), `${JSON.stringify(failedRecord, null, 2)}
|
|
5464
5631
|
`, {
|
|
5465
5632
|
mode: 384
|
|
5466
5633
|
});
|
|
@@ -5495,7 +5662,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5495
5662
|
if (clone.code === -1 && !clone.stderr) return fail(2, GIT_MISSING_MESSAGE);
|
|
5496
5663
|
const access = gitAccessFailure(req.spec, clone.stderr, req.tokenSecret, req.shared);
|
|
5497
5664
|
if (access) return fail(1, access);
|
|
5498
|
-
return fail(1, `git clone failed for ${
|
|
5665
|
+
return fail(1, `git clone failed for ${scrubRepoUrlUserinfo(req.spec.url)}:`, clone.stderr);
|
|
5499
5666
|
}
|
|
5500
5667
|
progress(timed("Cloning (blobless)", t));
|
|
5501
5668
|
step = "checkout";
|
|
@@ -5503,14 +5670,17 @@ async function buildLocked(req, ctx, root) {
|
|
|
5503
5670
|
const rp = await runGit(["rev-parse", "--verify", "--quiet", `${commit}^{commit}`], gitCtx, work);
|
|
5504
5671
|
const full = rp.stdout.trim();
|
|
5505
5672
|
if (rp.code !== 0 || !/^[0-9a-f]{40}$/.test(full)) {
|
|
5506
|
-
return fail(
|
|
5673
|
+
return fail(
|
|
5674
|
+
1,
|
|
5675
|
+
`commit ${commit} is not in ${scrubRepoUrlUserinfo(req.spec.url)} (or the short SHA is ambiguous).`
|
|
5676
|
+
);
|
|
5507
5677
|
}
|
|
5508
5678
|
commit = full;
|
|
5509
5679
|
}
|
|
5510
5680
|
const co = await runGit([...gitCfg, "checkout", "--detach", commit], gitCtx, work);
|
|
5511
5681
|
if (co.code !== 0) {
|
|
5512
5682
|
const sha12 = commit.slice(0, 12);
|
|
5513
|
-
const url =
|
|
5683
|
+
const url = scrubRepoUrlUserinfo(req.spec.url);
|
|
5514
5684
|
let headline = `git checkout of ${sha12} from ${url} failed:`;
|
|
5515
5685
|
if (/invalid path '/i.test(co.stderr)) {
|
|
5516
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:`;
|
|
@@ -5541,7 +5711,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5541
5711
|
const count = Number((await runGit(["rev-list", "--count", `${req.ancestor}..${commit}`], gitCtx, work)).stdout);
|
|
5542
5712
|
if (Number.isInteger(count)) ahead = count;
|
|
5543
5713
|
}
|
|
5544
|
-
const { manifest, warnings: manifestWarnings } = readGitManifest(work,
|
|
5714
|
+
const { manifest, warnings: manifestWarnings } = readGitManifest(work, reqSubdir);
|
|
5545
5715
|
for (const w of manifestWarnings) warn(w);
|
|
5546
5716
|
namespace = namespace ?? manifest.namespace;
|
|
5547
5717
|
if (!namespace) {
|
|
@@ -5551,7 +5721,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5551
5721
|
const hit = reuse(namespace, commit);
|
|
5552
5722
|
if (hit) {
|
|
5553
5723
|
tryRemoveTree(work, warn);
|
|
5554
|
-
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)}`);
|
|
5555
5725
|
return hit.ok && ahead !== void 0 ? { ...hit, ahead } : hit;
|
|
5556
5726
|
}
|
|
5557
5727
|
const dest = gitBuildDir(namespace, commit, ctx.home);
|
|
@@ -5566,14 +5736,14 @@ async function buildLocked(req, ctx, root) {
|
|
|
5566
5736
|
work = dest;
|
|
5567
5737
|
}
|
|
5568
5738
|
const subdir = subdirOf(manifest);
|
|
5569
|
-
const targetDir = subdir ? join7(work, ...subdir.split(/
|
|
5739
|
+
const targetDir = subdir ? join7(work, ...subdir.split("/")) : work;
|
|
5570
5740
|
if (targetDir !== work && insideRelative(work, targetDir) === null) {
|
|
5571
5741
|
return fail(2, `subdir "${subdir}" is outside the repository; refusing to build.`, "", "", false);
|
|
5572
5742
|
}
|
|
5573
5743
|
if (!existsSync4(join7(targetDir, "package.json"))) {
|
|
5574
5744
|
if (req.subdir === "") {
|
|
5575
5745
|
const moved = manifest.subdir ? printable(manifest.subdir) : void 0;
|
|
5576
|
-
const url =
|
|
5746
|
+
const url = scrubRepoUrlUserinfo(req.spec.url) + (req.ref ? `#${req.ref}` : "");
|
|
5577
5747
|
return fail(
|
|
5578
5748
|
1,
|
|
5579
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" : ""}`
|
|
@@ -5586,7 +5756,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5586
5756
|
}
|
|
5587
5757
|
const installDir = existsSync4(join7(work, "package.json")) ? work : targetDir;
|
|
5588
5758
|
const plan = detectPackageManager(installDir);
|
|
5589
|
-
if ("error" in plan) return fail(2, `${
|
|
5759
|
+
if ("error" in plan) return fail(2, `${scrubRepoUrlUserinfo(req.spec.url)}: ${plan.error}`);
|
|
5590
5760
|
for (const w of plan.warnings) warn(w);
|
|
5591
5761
|
const pmCmd = resolvePmCommand(plan, { env: ctx.env, platform: ctx.platform, exclude: work });
|
|
5592
5762
|
if ("error" in pmCmd) return fail(2, pmCmd.error);
|
|
@@ -5611,7 +5781,11 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5611
5781
|
);
|
|
5612
5782
|
return { ...refused, needsConsent: true };
|
|
5613
5783
|
}
|
|
5614
|
-
|
|
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);
|
|
5615
5789
|
}
|
|
5616
5790
|
await recordRepoConsent(req.spec.url, ctx.home, ctx.now?.());
|
|
5617
5791
|
}
|
|
@@ -5636,7 +5810,7 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5636
5810
|
const shown = (args) => `${pmCmd.label} ${args.filter((a) => a !== "--no-audit" && a !== "--no-fund").join(" ")}`;
|
|
5637
5811
|
const sha7 = commit.slice(0, 7);
|
|
5638
5812
|
const built = commit;
|
|
5639
|
-
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.");
|
|
5640
5814
|
step = "install";
|
|
5641
5815
|
t = Date.now();
|
|
5642
5816
|
const install = await runStep(plan.installArgs, installDir);
|
|
@@ -5662,8 +5836,12 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5662
5836
|
const entryName = req.entry ?? manifest.entry;
|
|
5663
5837
|
let entry = null;
|
|
5664
5838
|
if (entryName !== void 0) {
|
|
5665
|
-
|
|
5666
|
-
|
|
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
|
+
}
|
|
5667
5845
|
} else {
|
|
5668
5846
|
entry = inferredEntry(targetDir);
|
|
5669
5847
|
if (!entry) {
|
|
@@ -5714,9 +5892,6 @@ Not a TTY, so nothing can be asked: re-run with --yes to allow this repo's scrip
|
|
|
5714
5892
|
...ahead !== void 0 ? { ahead } : {}
|
|
5715
5893
|
};
|
|
5716
5894
|
}
|
|
5717
|
-
function asciiLines(text) {
|
|
5718
|
-
return text.replace(/\r\n/g, "\n").replace(/[^\x20-\x7e\n]/g, "?");
|
|
5719
|
-
}
|
|
5720
5895
|
async function buildPinnedGitEntries(servers, ctx, shared, pinFile) {
|
|
5721
5896
|
const reports = [];
|
|
5722
5897
|
for (const s of servers) {
|
|
@@ -5761,6 +5936,9 @@ async function buildPinnedGitEntries(servers, ctx, shared, pinFile) {
|
|
|
5761
5936
|
if (res.ok) {
|
|
5762
5937
|
ctx.progress(`${ns} ready (${commit.slice(0, 7)}).`);
|
|
5763
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;
|
|
5764
5942
|
} else {
|
|
5765
5943
|
reports.push({
|
|
5766
5944
|
namespace: ns,
|
|
@@ -5889,6 +6067,31 @@ async function recordGitPin(namespace, file, commit, home, warn = () => {
|
|
|
5889
6067
|
release();
|
|
5890
6068
|
}
|
|
5891
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
|
+
}
|
|
5892
6095
|
async function recordLoadedGitPin(namespace, commit, opts) {
|
|
5893
6096
|
const probe = await probeProjectTrust({ cwd: opts.cwd, home: opts.home, env: opts.env }).catch(() => null);
|
|
5894
6097
|
const file = probe?.path && projectFileIsHonoured(probe) ? probe.path : localBundlesPath(userConfigDir(opts.home));
|
|
@@ -6112,6 +6315,31 @@ async function discardBuild(namespace, commit, home, opts = {}) {
|
|
|
6112
6315
|
release();
|
|
6113
6316
|
}
|
|
6114
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
|
+
}
|
|
6115
6343
|
var GIT_STATE_FILENAME = "state.json";
|
|
6116
6344
|
function gitStatePath(home) {
|
|
6117
6345
|
return join7(gitRoot(home), GIT_STATE_FILENAME);
|
|
@@ -6176,11 +6404,13 @@ export {
|
|
|
6176
6404
|
HTTP_HEADER_NAME_RE,
|
|
6177
6405
|
RESERVED_HEADER_NAMES,
|
|
6178
6406
|
unsafeRelativePathReason,
|
|
6407
|
+
relativeSegments,
|
|
6179
6408
|
gitSourceFromRaw,
|
|
6180
6409
|
gitNodeCommand,
|
|
6181
6410
|
jsonErrorLocation,
|
|
6182
6411
|
readBundlesServersSync,
|
|
6183
6412
|
previewBundlesContent,
|
|
6413
|
+
rawEntryLoads,
|
|
6184
6414
|
probeProjectTrust,
|
|
6185
6415
|
untrustedProjectWarning,
|
|
6186
6416
|
projectFileIsHonoured,
|
|
@@ -6212,6 +6442,8 @@ export {
|
|
|
6212
6442
|
fenceUpstreamInstructions,
|
|
6213
6443
|
ensureUv,
|
|
6214
6444
|
uvLaunchKind,
|
|
6445
|
+
printable,
|
|
6446
|
+
asciiLines,
|
|
6215
6447
|
levenshtein,
|
|
6216
6448
|
closestNames,
|
|
6217
6449
|
matchCatalog,
|
|
@@ -6221,12 +6453,17 @@ export {
|
|
|
6221
6453
|
tokenizeCommand,
|
|
6222
6454
|
normalizeCatalogUrl,
|
|
6223
6455
|
withWarnSink,
|
|
6456
|
+
isRemoteCatalogEntry,
|
|
6457
|
+
catalogEnvKeys,
|
|
6224
6458
|
resolveCatalogSlug,
|
|
6225
6459
|
QUESTION_CANCELLED,
|
|
6460
|
+
QUESTION_EOF,
|
|
6226
6461
|
questionOrEmpty,
|
|
6227
6462
|
askYesNo,
|
|
6463
|
+
scriptConsentConfirm,
|
|
6228
6464
|
collectSidecarSpecs,
|
|
6229
6465
|
configuredRange,
|
|
6466
|
+
sidecarsManifest,
|
|
6230
6467
|
installedPlatform,
|
|
6231
6468
|
installedVersion,
|
|
6232
6469
|
defaultRunNpm,
|
|
@@ -6235,11 +6472,11 @@ export {
|
|
|
6235
6472
|
runSidecarsInstall,
|
|
6236
6473
|
hasManagedSidecars,
|
|
6237
6474
|
GIT_CREDENTIALS_REFUSAL,
|
|
6238
|
-
printable,
|
|
6239
6475
|
gitRefProblem,
|
|
6240
6476
|
parseGitSpec,
|
|
6241
6477
|
normalizeRepoUrl,
|
|
6242
6478
|
scrubUrlUserinfo,
|
|
6479
|
+
scrubRepoUrlUserinfo,
|
|
6243
6480
|
redactGitOutput,
|
|
6244
6481
|
GIT_MISSING_MESSAGE,
|
|
6245
6482
|
runGit,
|
|
@@ -6279,6 +6516,7 @@ export {
|
|
|
6279
6516
|
GIT_PIN_LOCK_WAIT_MS,
|
|
6280
6517
|
gitRefsPath,
|
|
6281
6518
|
recordGitPin,
|
|
6519
|
+
forgetGitPin,
|
|
6282
6520
|
recordLoadedGitPin,
|
|
6283
6521
|
gitLivenessWarning,
|
|
6284
6522
|
planGitRemoval,
|
|
@@ -6288,6 +6526,7 @@ export {
|
|
|
6288
6526
|
keptBuilds,
|
|
6289
6527
|
gcGitBuilds,
|
|
6290
6528
|
discardBuild,
|
|
6529
|
+
discardUnpinnedBuild,
|
|
6291
6530
|
GIT_STATE_FILENAME,
|
|
6292
6531
|
gitStatePath,
|
|
6293
6532
|
readGitState,
|
|
@@ -6299,6 +6538,7 @@ export {
|
|
|
6299
6538
|
resolveServerEnv,
|
|
6300
6539
|
resolveTimeoutEnv,
|
|
6301
6540
|
ActivationError,
|
|
6541
|
+
shellActivationMessage,
|
|
6302
6542
|
readGitFailedRecord,
|
|
6303
6543
|
gitBuildMissing,
|
|
6304
6544
|
withHeartbeat,
|