@yawlabs/mcp 1.1.12 → 1.1.15
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 +82 -0
- package/README.md +13 -6
- package/dist/{auto-upgrade-KXOCHAUR.js → auto-upgrade-NT3QNOO2.js} +1 -1
- package/dist/{chunk-PFDIDS6O.js → chunk-R55UHP2V.js} +992 -255
- package/dist/{chunk-SJWGO3WQ.js → chunk-UHSAFT6S.js} +315 -143
- package/dist/{git-source-W43NBUYR.js → git-source-HAQNOQRR.js} +4 -10
- package/dist/index.js +9980 -8380
- package/package.json +4 -4
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
CONFIG_DIRNAME,
|
|
4
4
|
GIT_BUILD_SHA_LEN,
|
|
5
|
+
GIT_BUILT_SUFFIX,
|
|
5
6
|
MIN_OAM_VERSION,
|
|
6
7
|
acquireUpgradeLock,
|
|
7
8
|
atomicWriteFile,
|
|
8
9
|
cacheDir,
|
|
10
|
+
classifyNpxLaunch,
|
|
9
11
|
compareVersions,
|
|
10
12
|
createStreamWriter,
|
|
11
13
|
describeNodeFlagRefusal,
|
|
@@ -16,12 +18,12 @@ import {
|
|
|
16
18
|
gitRoot,
|
|
17
19
|
isFeatureEnabled,
|
|
18
20
|
isRegistrySpec,
|
|
21
|
+
killAndDetach,
|
|
19
22
|
launcherBasename,
|
|
20
23
|
log,
|
|
21
24
|
managedNodeBin,
|
|
22
25
|
nodeLaunchKind,
|
|
23
26
|
npxSpec,
|
|
24
|
-
npxSpecIndex,
|
|
25
27
|
oamFailureLabel,
|
|
26
28
|
oamHeapOomHint,
|
|
27
29
|
packageEntry,
|
|
@@ -42,11 +44,11 @@ import {
|
|
|
42
44
|
stripJsoncComments,
|
|
43
45
|
stripTrailingCommas,
|
|
44
46
|
userConfigDir
|
|
45
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-UHSAFT6S.js";
|
|
46
48
|
|
|
47
49
|
// src/git-source.ts
|
|
48
50
|
import { spawn as spawn3 } from "child_process";
|
|
49
|
-
import { randomBytes as
|
|
51
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
50
52
|
import {
|
|
51
53
|
chmodSync,
|
|
52
54
|
existsSync as existsSync4,
|
|
@@ -57,7 +59,7 @@ import {
|
|
|
57
59
|
renameSync,
|
|
58
60
|
rmdirSync,
|
|
59
61
|
rmSync,
|
|
60
|
-
statSync as
|
|
62
|
+
statSync as statSync3,
|
|
61
63
|
writeFileSync as writeFileSync2
|
|
62
64
|
} from "fs";
|
|
63
65
|
import { dirname as dirname4, isAbsolute, join as join7, relative as relative2, resolve as resolve3 } from "path";
|
|
@@ -69,6 +71,19 @@ function printable(s) {
|
|
|
69
71
|
function asciiLines(text) {
|
|
70
72
|
return text.replace(/\r\n/g, "\n").replace(/[^\x20-\x7e\n]/g, "?");
|
|
71
73
|
}
|
|
74
|
+
var FORMAT_CHAR = new RegExp("\\p{Cf}", "u");
|
|
75
|
+
function withoutControls(s) {
|
|
76
|
+
let out = "";
|
|
77
|
+
for (const ch of s) {
|
|
78
|
+
const c = ch.codePointAt(0);
|
|
79
|
+
if (c === 10 || c === 13 || c === 9) {
|
|
80
|
+
out += " ";
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
out += c < 32 || c >= 127 && c <= 159 || FORMAT_CHAR.test(ch) ? "?" : ch;
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
72
87
|
|
|
73
88
|
// src/fuzzy.ts
|
|
74
89
|
function levenshtein(a, b) {
|
|
@@ -327,7 +342,7 @@ async function resolveCatalogSlug(slug, opts = {}) {
|
|
|
327
342
|
const servers = await fetchCatalog(url);
|
|
328
343
|
const entry = servers.find((s) => s.slug === slug);
|
|
329
344
|
if (!entry) {
|
|
330
|
-
const near = suggestCatalogSlugs(slug, servers, 3);
|
|
345
|
+
const near = suggestCatalogSlugs(slug, servers, 3).map(withoutControls);
|
|
331
346
|
const hint = near.length > 0 ? ` Did you mean: ${near.join(", ")}? Or run \`yaw-mcp search ${slug}\`.` : ` Run \`yaw-mcp search ${slug}\` to look for it, or browse https://yaw.sh/mcp/catalog/.`;
|
|
332
347
|
throw new Error(`no server with slug "${slug}" in the Yaw MCP catalog.${hint}`);
|
|
333
348
|
}
|
|
@@ -371,7 +386,7 @@ function normalizeCatalogGrade(raw) {
|
|
|
371
386
|
import { readFileSync, statSync, writeFileSync } from "fs";
|
|
372
387
|
import { basename, join, relative, resolve } from "path";
|
|
373
388
|
function builtMarkerPath(dir) {
|
|
374
|
-
return `${dir}
|
|
389
|
+
return `${dir}${GIT_BUILT_SUFFIX}`;
|
|
375
390
|
}
|
|
376
391
|
function mtimeMs(file) {
|
|
377
392
|
try {
|
|
@@ -421,7 +436,7 @@ function gitEntryBuilt(namespace, git, home) {
|
|
|
421
436
|
}
|
|
422
437
|
|
|
423
438
|
// src/local-bundles.ts
|
|
424
|
-
import { createHash as
|
|
439
|
+
import { createHash as createHash3 } from "crypto";
|
|
425
440
|
import { existsSync, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
|
|
426
441
|
import { chmod as chmod3, mkdir, readFile as readFile3 } from "fs/promises";
|
|
427
442
|
import { homedir as homedir3 } from "os";
|
|
@@ -429,17 +444,172 @@ import { join as join4 } from "path";
|
|
|
429
444
|
import { parse as parseJsoncTolerant } from "jsonc-parser";
|
|
430
445
|
|
|
431
446
|
// src/secrets-vault.ts
|
|
432
|
-
import { createHmac, randomBytes as
|
|
447
|
+
import { createHmac, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
|
|
433
448
|
import { chmod, readFile } from "fs/promises";
|
|
434
449
|
import { homedir } from "os";
|
|
435
450
|
import { dirname, join as join2 } from "path";
|
|
436
451
|
|
|
452
|
+
// src/recovery-code.ts
|
|
453
|
+
import { randomBytes } from "crypto";
|
|
454
|
+
var RECOVERY_SECRET_LEN = 16;
|
|
455
|
+
var RECOVERY_CODE_PREFIX = "YAWR";
|
|
456
|
+
var ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
457
|
+
var DATA_SYMBOLS = 26;
|
|
458
|
+
var CHECK_SYMBOLS = 2;
|
|
459
|
+
var TOTAL_SYMBOLS = DATA_SYMBOLS + CHECK_SYMBOLS;
|
|
460
|
+
var GROUP_LEN = 4;
|
|
461
|
+
var PAD_BITS = DATA_SYMBOLS * 5 - RECOVERY_SECRET_LEN * 8;
|
|
462
|
+
var CHECK1_MULTIPLIER = 2;
|
|
463
|
+
var CHECK2_MULTIPLIER = 3;
|
|
464
|
+
var RECOVERY_CODE_FORMAT_ERROR = "not a recovery code (wrong length/characters)";
|
|
465
|
+
var RECOVERY_CODE_TYPO_ERROR = "typo in the recovery code (check failed)";
|
|
466
|
+
var RECOVERY_CODE_WRONG_VAULT_ERROR = "this recovery code does not open this vault";
|
|
467
|
+
function gfMul(a, b) {
|
|
468
|
+
let x = a;
|
|
469
|
+
let y = b;
|
|
470
|
+
let out = 0;
|
|
471
|
+
while (y > 0) {
|
|
472
|
+
if (y & 1) out ^= x;
|
|
473
|
+
y >>= 1;
|
|
474
|
+
x <<= 1;
|
|
475
|
+
if (x & 32) x ^= 37;
|
|
476
|
+
}
|
|
477
|
+
return out;
|
|
478
|
+
}
|
|
479
|
+
function dammFold(symbols, multiplier, end = symbols.length) {
|
|
480
|
+
let interim = 0;
|
|
481
|
+
for (let i = 0; i < end; i++) interim = gfMul(multiplier, interim) ^ symbols[i];
|
|
482
|
+
return interim;
|
|
483
|
+
}
|
|
484
|
+
function dammCheck(symbols, multiplier) {
|
|
485
|
+
return gfMul(multiplier, dammFold(symbols, multiplier));
|
|
486
|
+
}
|
|
487
|
+
function withChecks(data) {
|
|
488
|
+
const out = [...data, dammCheck(data, CHECK1_MULTIPLIER)];
|
|
489
|
+
out.push(dammCheck(out, CHECK2_MULTIPLIER));
|
|
490
|
+
return out;
|
|
491
|
+
}
|
|
492
|
+
function checksPass(symbols) {
|
|
493
|
+
if (symbols.length !== TOTAL_SYMBOLS) return false;
|
|
494
|
+
return dammFold(symbols, CHECK1_MULTIPLIER, DATA_SYMBOLS + 1) === 0 && dammFold(symbols, CHECK2_MULTIPLIER) === 0;
|
|
495
|
+
}
|
|
496
|
+
function secretToSymbols(secret) {
|
|
497
|
+
const symbols = [];
|
|
498
|
+
for (let i = 0; i < DATA_SYMBOLS; i++) {
|
|
499
|
+
let v = 0;
|
|
500
|
+
for (let b = 0; b < 5; b++) {
|
|
501
|
+
const padded = i * 5 + b;
|
|
502
|
+
const bit = padded < PAD_BITS ? 0 : secret[padded - PAD_BITS >> 3] >> 7 - (padded - PAD_BITS & 7) & 1;
|
|
503
|
+
v = v << 1 | bit;
|
|
504
|
+
}
|
|
505
|
+
symbols.push(v);
|
|
506
|
+
}
|
|
507
|
+
return symbols;
|
|
508
|
+
}
|
|
509
|
+
function symbolsToSecret(symbols) {
|
|
510
|
+
const out = Buffer.alloc(RECOVERY_SECRET_LEN);
|
|
511
|
+
for (let i = 0; i < DATA_SYMBOLS; i++) {
|
|
512
|
+
for (let b = 0; b < 5; b++) {
|
|
513
|
+
const bit = symbols[i] >> 4 - b & 1;
|
|
514
|
+
const padded = i * 5 + b;
|
|
515
|
+
if (padded < PAD_BITS) {
|
|
516
|
+
if (bit !== 0) {
|
|
517
|
+
out.fill(0);
|
|
518
|
+
return null;
|
|
519
|
+
}
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const k = padded - PAD_BITS;
|
|
523
|
+
out[k >> 3] |= bit << 7 - (k & 7);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return out;
|
|
527
|
+
}
|
|
528
|
+
function recoverySymbols(secret) {
|
|
529
|
+
if (secret.length !== RECOVERY_SECRET_LEN) throw new Error(`recovery secret must be ${RECOVERY_SECRET_LEN} bytes`);
|
|
530
|
+
const data = secretToSymbols(secret);
|
|
531
|
+
try {
|
|
532
|
+
return withChecks(data);
|
|
533
|
+
} finally {
|
|
534
|
+
data.fill(0);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function formatSymbols(symbols) {
|
|
538
|
+
const chars = symbols.map((s) => ALPHABET[s]).join("");
|
|
539
|
+
const groups = [];
|
|
540
|
+
for (let i = 0; i < chars.length; i += GROUP_LEN) groups.push(chars.slice(i, i + GROUP_LEN));
|
|
541
|
+
return [RECOVERY_CODE_PREFIX, ...groups].join("-");
|
|
542
|
+
}
|
|
543
|
+
function generateRecoverySecret() {
|
|
544
|
+
const raw = randomBytes(RECOVERY_SECRET_LEN);
|
|
545
|
+
const out = Buffer.alloc(RECOVERY_SECRET_LEN);
|
|
546
|
+
raw.copy(out);
|
|
547
|
+
raw.fill(0);
|
|
548
|
+
return out;
|
|
549
|
+
}
|
|
550
|
+
function formatRecoveryCode(secret) {
|
|
551
|
+
const symbols = recoverySymbols(secret);
|
|
552
|
+
try {
|
|
553
|
+
return formatSymbols(symbols);
|
|
554
|
+
} finally {
|
|
555
|
+
symbols.fill(0);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function recoveryCodeGroups(code) {
|
|
559
|
+
const symbols = parseSymbols(code);
|
|
560
|
+
try {
|
|
561
|
+
const chars = symbols.map((s) => ALPHABET[s]).join("");
|
|
562
|
+
const groups = [];
|
|
563
|
+
for (let i = 0; i < chars.length; i += GROUP_LEN) groups.push(chars.slice(i, i + GROUP_LEN));
|
|
564
|
+
return groups;
|
|
565
|
+
} finally {
|
|
566
|
+
symbols.fill(0);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function normalizeRecoveryGroup(input) {
|
|
570
|
+
return normalizeChars(input);
|
|
571
|
+
}
|
|
572
|
+
function normalizeChars(input) {
|
|
573
|
+
return input.toUpperCase().replace(/[\s-]+/g, "").replace(/O/g, "0").replace(/[IL]/g, "1");
|
|
574
|
+
}
|
|
575
|
+
function parseSymbols(input) {
|
|
576
|
+
let s = input.toUpperCase().replace(/[\s-]+/g, "");
|
|
577
|
+
if (s.startsWith(RECOVERY_CODE_PREFIX)) s = s.slice(RECOVERY_CODE_PREFIX.length);
|
|
578
|
+
s = normalizeChars(s);
|
|
579
|
+
if (s.length !== TOTAL_SYMBOLS) throw new Error(RECOVERY_CODE_FORMAT_ERROR);
|
|
580
|
+
const symbols = [];
|
|
581
|
+
for (const ch of s) {
|
|
582
|
+
const v = ALPHABET.indexOf(ch);
|
|
583
|
+
if (v < 0) {
|
|
584
|
+
symbols.fill(0);
|
|
585
|
+
throw new Error(RECOVERY_CODE_FORMAT_ERROR);
|
|
586
|
+
}
|
|
587
|
+
symbols.push(v);
|
|
588
|
+
}
|
|
589
|
+
if (!checksPass(symbols)) {
|
|
590
|
+
symbols.fill(0);
|
|
591
|
+
throw new Error(RECOVERY_CODE_TYPO_ERROR);
|
|
592
|
+
}
|
|
593
|
+
return symbols;
|
|
594
|
+
}
|
|
595
|
+
function parseRecoveryCode(input) {
|
|
596
|
+
const symbols = parseSymbols(input);
|
|
597
|
+
const secret = symbolsToSecret(symbols);
|
|
598
|
+
symbols.fill(0);
|
|
599
|
+
if (secret === null) throw new Error(RECOVERY_CODE_FORMAT_ERROR);
|
|
600
|
+
return secret;
|
|
601
|
+
}
|
|
602
|
+
|
|
437
603
|
// src/secrets-crypto.ts
|
|
438
|
-
import { createCipheriv, createDecipheriv, randomBytes, scrypt as scryptCb } from "crypto";
|
|
604
|
+
import { createCipheriv, createDecipheriv, createHash, hkdfSync, randomBytes as randomBytes2, scrypt as scryptCb } from "crypto";
|
|
439
605
|
var KEY_LEN = 32;
|
|
440
606
|
var IV_LEN = 12;
|
|
441
607
|
var SALT_LEN = 16;
|
|
442
|
-
var DEFAULT_KDF = { N: 1 << 15, r: 8, p: 1 };
|
|
608
|
+
var DEFAULT_KDF = Object.freeze({ N: 1 << 15, r: 8, p: 1 });
|
|
609
|
+
var defaultKdfOverride = null;
|
|
610
|
+
function defaultKdf() {
|
|
611
|
+
return defaultKdfOverride ?? DEFAULT_KDF;
|
|
612
|
+
}
|
|
443
613
|
var LEGACY_KDF = Object.freeze({ N: 1 << 15, r: 8, p: 1 });
|
|
444
614
|
var MAX_KDF_N = 1 << 18;
|
|
445
615
|
var MAX_KDF_R = 32;
|
|
@@ -469,32 +639,42 @@ function isValidKdfParams(v) {
|
|
|
469
639
|
return invalidKdfParamsReason(v) === null;
|
|
470
640
|
}
|
|
471
641
|
function kdfExceedsDefault(params) {
|
|
472
|
-
|
|
642
|
+
const d = defaultKdf();
|
|
643
|
+
return params.N > d.N || params.r > d.r || params.p > d.p;
|
|
473
644
|
}
|
|
474
645
|
function generateSalt() {
|
|
475
|
-
return
|
|
646
|
+
return randomBytes2(SALT_LEN);
|
|
647
|
+
}
|
|
648
|
+
function copyKey(key) {
|
|
649
|
+
const out = Buffer.alloc(key.length);
|
|
650
|
+
key.copy(out);
|
|
651
|
+
return out;
|
|
476
652
|
}
|
|
477
653
|
function normalizePassphrase(passphrase) {
|
|
478
654
|
return passphrase.normalize("NFC");
|
|
479
655
|
}
|
|
480
656
|
async function deriveKey(passphrase, salt, params = LEGACY_KDF, normalize = true) {
|
|
657
|
+
const problem = invalidKdfParamsReason(params);
|
|
658
|
+
if (problem !== null) throw new Error(`invalid kdf parameters (${problem})`);
|
|
481
659
|
return scryptCallWithMaxmem(normalize ? normalizePassphrase(passphrase) : passphrase, salt, KEY_LEN, params);
|
|
482
660
|
}
|
|
483
661
|
async function scryptCallWithMaxmem(password, salt, keylen, params) {
|
|
484
662
|
const maxmem = Math.max(64 * 1024 * 1024, 256 * params.N * params.r);
|
|
485
663
|
return new Promise((resolve4, reject) => {
|
|
486
|
-
scryptCb(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
664
|
+
scryptCb(password, salt, keylen, { N: params.N, r: params.r, p: params.p, maxmem }, (err, key) => {
|
|
665
|
+
if (err) {
|
|
666
|
+
reject(err);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const own = copyKey(key);
|
|
670
|
+
key.fill(0);
|
|
671
|
+
resolve4(own);
|
|
672
|
+
});
|
|
493
673
|
});
|
|
494
674
|
}
|
|
495
675
|
function encryptEntry(plaintext, key, aad) {
|
|
496
676
|
if (key.length !== KEY_LEN) throw new Error(`key must be ${KEY_LEN} bytes`);
|
|
497
|
-
const iv =
|
|
677
|
+
const iv = randomBytes2(IV_LEN);
|
|
498
678
|
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
499
679
|
if (aad !== void 0) cipher.setAAD(Buffer.from(aad, "utf8"));
|
|
500
680
|
const ct = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
@@ -506,6 +686,14 @@ function encryptEntry(plaintext, key, aad) {
|
|
|
506
686
|
};
|
|
507
687
|
}
|
|
508
688
|
function decryptEntry(entry, key, aad) {
|
|
689
|
+
const pt = decryptRaw(entry, key, aad);
|
|
690
|
+
try {
|
|
691
|
+
return pt.toString("utf8");
|
|
692
|
+
} finally {
|
|
693
|
+
pt.fill(0);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
function decryptRaw(entry, key, aad) {
|
|
509
697
|
if (key.length !== KEY_LEN) throw new Error(`key must be ${KEY_LEN} bytes`);
|
|
510
698
|
const iv = Buffer.from(entry.iv, "base64");
|
|
511
699
|
const ct = Buffer.from(entry.ciphertext, "base64");
|
|
@@ -515,18 +703,117 @@ function decryptEntry(entry, key, aad) {
|
|
|
515
703
|
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
516
704
|
if (aad !== void 0) decipher.setAAD(Buffer.from(aad, "utf8"));
|
|
517
705
|
decipher.setAuthTag(authTag);
|
|
518
|
-
const
|
|
519
|
-
|
|
706
|
+
const head = decipher.update(ct);
|
|
707
|
+
let tail;
|
|
708
|
+
try {
|
|
709
|
+
tail = decipher.final();
|
|
710
|
+
} catch (err) {
|
|
711
|
+
head.fill(0);
|
|
712
|
+
throw err;
|
|
713
|
+
}
|
|
714
|
+
const out = Buffer.alloc(head.length + tail.length);
|
|
715
|
+
head.copy(out, 0);
|
|
716
|
+
tail.copy(out, head.length);
|
|
717
|
+
head.fill(0);
|
|
718
|
+
tail.fill(0);
|
|
719
|
+
return out;
|
|
720
|
+
}
|
|
721
|
+
var DEK_LEN = KEY_LEN;
|
|
722
|
+
var VAULT_ID_LEN = 16;
|
|
723
|
+
var SLOT_DIGEST_LEN = 32;
|
|
724
|
+
var RECOVERY_KEK_INFO = "yaw-mcp:keyslot:recovery:v1";
|
|
725
|
+
function generateDek() {
|
|
726
|
+
const raw = randomBytes2(DEK_LEN);
|
|
727
|
+
const out = copyKey(raw);
|
|
728
|
+
raw.fill(0);
|
|
729
|
+
return out;
|
|
730
|
+
}
|
|
731
|
+
function generateVaultId() {
|
|
732
|
+
return randomBytes2(VAULT_ID_LEN).toString("base64");
|
|
733
|
+
}
|
|
734
|
+
function deriveRecoveryKek(secret, salt) {
|
|
735
|
+
const ab = hkdfSync("sha256", secret, salt, RECOVERY_KEK_INFO, KEY_LEN);
|
|
736
|
+
const view = Buffer.from(ab);
|
|
737
|
+
const out = copyKey(view);
|
|
738
|
+
view.fill(0);
|
|
739
|
+
return out;
|
|
740
|
+
}
|
|
741
|
+
function wrapKey(keyBytes, kek, aad) {
|
|
742
|
+
if (kek.length !== KEY_LEN) throw new Error(`key must be ${KEY_LEN} bytes`);
|
|
743
|
+
const iv = randomBytes2(IV_LEN);
|
|
744
|
+
const cipher = createCipheriv("aes-256-gcm", kek, iv);
|
|
745
|
+
cipher.setAAD(Buffer.from(aad, "utf8"));
|
|
746
|
+
const ct = Buffer.concat([cipher.update(keyBytes), cipher.final()]);
|
|
747
|
+
return {
|
|
748
|
+
iv: iv.toString("base64"),
|
|
749
|
+
ciphertext: ct.toString("base64"),
|
|
750
|
+
authTag: cipher.getAuthTag().toString("base64")
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function unwrapKey(wrapped, kek, aad) {
|
|
754
|
+
const out = decryptRaw(wrapped, kek, aad);
|
|
755
|
+
if (out.length !== DEK_LEN) {
|
|
756
|
+
out.fill(0);
|
|
757
|
+
throw new Error("unwrapped key has the wrong length");
|
|
758
|
+
}
|
|
759
|
+
return out;
|
|
760
|
+
}
|
|
761
|
+
function slotDigest(aad, wrapped) {
|
|
762
|
+
return createHash("sha256").update(Buffer.from(aad, "utf8")).update(Buffer.from([0])).update(Buffer.from(wrapped.iv, "base64")).update(Buffer.from(wrapped.ciphertext, "base64")).update(Buffer.from(wrapped.authTag, "base64")).digest("base64");
|
|
763
|
+
}
|
|
764
|
+
function canonicalJson(value) {
|
|
765
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
766
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
767
|
+
const o = value;
|
|
768
|
+
const keys = Object.keys(o).filter((k) => o[k] !== void 0).sort();
|
|
769
|
+
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(o[k])}`).join(",")}}`;
|
|
520
770
|
}
|
|
521
771
|
|
|
522
772
|
// src/secrets-vault.ts
|
|
773
|
+
function errorMessage(err) {
|
|
774
|
+
return err instanceof Error ? err.message : String(err);
|
|
775
|
+
}
|
|
523
776
|
var SECRETS_FILENAME = "secrets.json";
|
|
524
|
-
var SECRETS_SCHEMA_VERSION =
|
|
777
|
+
var SECRETS_SCHEMA_VERSION = 3;
|
|
778
|
+
var FIRST_BOUND_SCHEMA_VERSION = 2;
|
|
779
|
+
var KEYSLOT_SCHEMA_VERSION = 3;
|
|
780
|
+
var LAST_SCRYPT_SCHEMA_VERSION = 2;
|
|
525
781
|
var LEGACY_SCHEMA_VERSION = 1;
|
|
782
|
+
var RECOVERY_SLOT_KDF = "hkdf-sha256";
|
|
526
783
|
var VAULT_CHECK_AAD = "yaw-mcp:vault-check";
|
|
784
|
+
function isV3Vault(vault) {
|
|
785
|
+
return vault.version >= KEYSLOT_SCHEMA_VERSION && typeof vault.vault_id === "string" && vault.keyslots !== void 0;
|
|
786
|
+
}
|
|
787
|
+
function assertCoherentVault(vault) {
|
|
788
|
+
if (vault.version >= KEYSLOT_SCHEMA_VERSION && !isV3Vault(vault)) {
|
|
789
|
+
throw new Error(`vault declares schema v${vault.version} but carries no vault_id/keyslots`);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
function vaultEntryAad(vault, name) {
|
|
793
|
+
return isV3Vault(vault) ? `yaw-mcp:v3:entry:${vault.vault_id}:${name}` : name;
|
|
794
|
+
}
|
|
795
|
+
function vaultCheckAad(vault) {
|
|
796
|
+
return isV3Vault(vault) ? `yaw-mcp:v3:check:${vault.vault_id}` : VAULT_CHECK_AAD;
|
|
797
|
+
}
|
|
798
|
+
function slotAad(role, vaultId, slot) {
|
|
799
|
+
return canonicalJson({
|
|
800
|
+
role,
|
|
801
|
+
vault_id: vaultId,
|
|
802
|
+
version: KEYSLOT_SCHEMA_VERSION,
|
|
803
|
+
kdf: slot.kdf,
|
|
804
|
+
salt: slot.salt,
|
|
805
|
+
...role === "recovery" ? { created: slot.created } : {}
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
function passphraseSlotDigest(vaultId, slot) {
|
|
809
|
+
return slotDigest(slotAad("passphrase", vaultId, slot), slot.wrapped);
|
|
810
|
+
}
|
|
527
811
|
var VAULT_CHECK_PLAINTEXT = "yaw-mcp-vault-v1";
|
|
528
812
|
var VAULT_CHECK_CORRUPT_ERROR = 'vault verification token ("check") is corrupt -- the passphrase is correct, but the check marker does not verify';
|
|
529
813
|
var VAULT_WRONG_PASSPHRASE_ERROR = "wrong passphrase for this vault (decryption failed)";
|
|
814
|
+
var VAULT_SLOT_DAMAGED_ERROR = "the vault's passphrase slot is damaged -- the passphrase cannot be checked; `yaw-mcp secrets recover` restores access if a recovery code was saved";
|
|
815
|
+
var VAULT_NO_RECOVERY_ERROR = "this vault has no recovery code -- `yaw-mcp secrets reset` starts over";
|
|
816
|
+
var VAULT_RECOVERY_SLOT_DAMAGED_ERROR = "the vault's recovery slot does not match its contents -- the recovery code cannot restore this vault";
|
|
530
817
|
function vaultPath(home = homedir()) {
|
|
531
818
|
return join2(home, CONFIG_DIRNAME, SECRETS_FILENAME);
|
|
532
819
|
}
|
|
@@ -573,6 +860,9 @@ async function loadVault(path2, opts) {
|
|
|
573
860
|
if (obj.version !== void 0 && typeof obj.version !== "number") {
|
|
574
861
|
throw new Error(`vault at ${path2} is corrupt: "version" must be a number`);
|
|
575
862
|
}
|
|
863
|
+
if (typeof obj.version === "number" && (!Number.isInteger(obj.version) || obj.version < 1)) {
|
|
864
|
+
throw new Error(`vault at ${path2} is corrupt: invalid "version" (${obj.version})`);
|
|
865
|
+
}
|
|
576
866
|
if (typeof obj.version === "number" && obj.version > SECRETS_SCHEMA_VERSION) {
|
|
577
867
|
throw new Error(
|
|
578
868
|
`vault at ${path2} was written by a newer yaw-mcp (schema version ${obj.version} > ${SECRETS_SCHEMA_VERSION}); upgrade yaw-mcp to read it`
|
|
@@ -588,6 +878,9 @@ async function loadVault(path2, opts) {
|
|
|
588
878
|
throw new VaultEntryCorruptError(name);
|
|
589
879
|
}
|
|
590
880
|
}
|
|
881
|
+
if (typeof obj.version === "number" && obj.version >= KEYSLOT_SCHEMA_VERSION) {
|
|
882
|
+
return loadV3Fields(obj, path2, onWarning);
|
|
883
|
+
}
|
|
591
884
|
if (obj.check !== void 0 && !isEncryptedEntry(obj.check)) {
|
|
592
885
|
const message = "Vault verification token is malformed; ignoring it (the next `yaw-mcp secrets set` re-stamps it)";
|
|
593
886
|
if (onWarning) onWarning({ kind: "check-malformed", path: path2, message });
|
|
@@ -602,13 +895,89 @@ async function loadVault(path2, opts) {
|
|
|
602
895
|
...check ? { check } : {}
|
|
603
896
|
};
|
|
604
897
|
}
|
|
898
|
+
function loadV3Fields(obj, path2, onWarning) {
|
|
899
|
+
const corrupt = (what) => new Error(`vault at ${path2} is corrupt: ${what}`);
|
|
900
|
+
if (typeof obj.vault_id !== "string" || !isBase64OfLength(obj.vault_id, VAULT_ID_LEN)) {
|
|
901
|
+
throw corrupt(`missing or invalid vault_id (expected ${VAULT_ID_LEN} bytes)`);
|
|
902
|
+
}
|
|
903
|
+
const keyslots = obj.keyslots;
|
|
904
|
+
if (!keyslots || typeof keyslots !== "object" || Array.isArray(keyslots)) {
|
|
905
|
+
throw corrupt("missing or invalid keyslots");
|
|
906
|
+
}
|
|
907
|
+
const slots = keyslots;
|
|
908
|
+
const passphrase = parsePassphraseSlot(slots.passphrase, corrupt);
|
|
909
|
+
if (obj.check !== void 0 && !isEncryptedEntry(obj.check)) {
|
|
910
|
+
throw corrupt(
|
|
911
|
+
'the "check" marker is malformed -- delete the "check" key by hand and re-run; the next `yaw-mcp secrets set` re-stamps it'
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
let recovery;
|
|
915
|
+
let recoveryMalformed = false;
|
|
916
|
+
if (slots.recovery !== void 0) {
|
|
917
|
+
recovery = parseRecoverySlot(slots.recovery) ?? void 0;
|
|
918
|
+
if (!recovery) {
|
|
919
|
+
recoveryMalformed = true;
|
|
920
|
+
const message = "Vault recovery slot is malformed; ignoring it (the recovery code cannot be used -- `yaw-mcp secrets recovery new` replaces it)";
|
|
921
|
+
if (onWarning) onWarning({ kind: "recovery-malformed", path: path2, message });
|
|
922
|
+
else log("warn", message, { path: path2 });
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return {
|
|
926
|
+
version: obj.version,
|
|
927
|
+
vault_id: obj.vault_id,
|
|
928
|
+
salt: obj.salt,
|
|
929
|
+
keyslots: { passphrase, ...recovery ? { recovery } : {} },
|
|
930
|
+
...recoveryMalformed ? { recoveryMalformed: true } : {},
|
|
931
|
+
...isEncryptedEntry(obj.check) ? { check: obj.check } : {},
|
|
932
|
+
entries: obj.entries
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
function isBase64OfLength(v, len) {
|
|
936
|
+
return typeof v === "string" && Buffer.from(v, "base64").length === len;
|
|
937
|
+
}
|
|
938
|
+
function parsePassphraseSlot(v, corrupt) {
|
|
939
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) throw corrupt("missing or invalid passphrase key slot");
|
|
940
|
+
const s = v;
|
|
941
|
+
if (!isBase64OfLength(s.salt, SALT_LEN)) throw corrupt(`passphrase key slot salt (expected ${SALT_LEN} bytes)`);
|
|
942
|
+
const kdfProblem = invalidKdfParamsReason(s.kdf);
|
|
943
|
+
if (kdfProblem !== null) throw corrupt(`passphrase key slot has invalid kdf parameters (${kdfProblem})`);
|
|
944
|
+
if (!isEncryptedEntry(s.wrapped)) throw corrupt("passphrase key slot has a malformed wrapped key");
|
|
945
|
+
if (!isBase64OfLength(s.digest, SLOT_DIGEST_LEN)) {
|
|
946
|
+
throw corrupt(`passphrase key slot digest (expected ${SLOT_DIGEST_LEN} bytes)`);
|
|
947
|
+
}
|
|
948
|
+
const kdf = s.kdf;
|
|
949
|
+
const w = s.wrapped;
|
|
950
|
+
return {
|
|
951
|
+
salt: s.salt,
|
|
952
|
+
kdf: { N: kdf.N, r: kdf.r, p: kdf.p },
|
|
953
|
+
wrapped: { iv: w.iv, ciphertext: w.ciphertext, authTag: w.authTag },
|
|
954
|
+
digest: s.digest
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
var ISO_UTC_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/;
|
|
958
|
+
function parseRecoverySlot(v) {
|
|
959
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return null;
|
|
960
|
+
const s = v;
|
|
961
|
+
if (!isBase64OfLength(s.salt, SALT_LEN)) return null;
|
|
962
|
+
if (s.kdf !== RECOVERY_SLOT_KDF) return null;
|
|
963
|
+
if (typeof s.created !== "string" || !ISO_UTC_RE.test(s.created) || Number.isNaN(Date.parse(s.created))) return null;
|
|
964
|
+
if (!isEncryptedEntry(s.wrapped)) return null;
|
|
965
|
+
const w = s.wrapped;
|
|
966
|
+
return {
|
|
967
|
+
salt: s.salt,
|
|
968
|
+
kdf: RECOVERY_SLOT_KDF,
|
|
969
|
+
created: s.created,
|
|
970
|
+
wrapped: { iv: w.iv, ciphertext: w.ciphertext, authTag: w.authTag }
|
|
971
|
+
};
|
|
972
|
+
}
|
|
605
973
|
function isEncryptedEntry(v) {
|
|
606
974
|
if (!v || typeof v !== "object") return false;
|
|
607
975
|
const e = v;
|
|
608
976
|
return typeof e.iv === "string" && typeof e.ciphertext === "string" && typeof e.authTag === "string";
|
|
609
977
|
}
|
|
610
978
|
async function saveVault(path2, vault) {
|
|
611
|
-
|
|
979
|
+
const { recoveryMalformed: _inMemoryOnly, ...onDisk } = vault;
|
|
980
|
+
await atomicWriteFile(path2, `${JSON.stringify(onDisk, null, 2)}
|
|
612
981
|
`, "utf8", 384, 448);
|
|
613
982
|
if (process.platform !== "win32") {
|
|
614
983
|
try {
|
|
@@ -624,54 +993,194 @@ async function saveVault(path2, vault) {
|
|
|
624
993
|
var cachedKey = null;
|
|
625
994
|
var cachedSalt = null;
|
|
626
995
|
var cachedFingerprint = null;
|
|
627
|
-
var
|
|
996
|
+
var cacheGeneration = 0;
|
|
997
|
+
var FINGERPRINT_HMAC_KEY = randomBytes3(32);
|
|
628
998
|
function passphraseFingerprint(passphrase, salt) {
|
|
629
999
|
return createHmac("sha256", FINGERPRINT_HMAC_KEY).update(salt).update(":").update(passphrase, "utf8").digest();
|
|
630
1000
|
}
|
|
631
1001
|
function lock() {
|
|
1002
|
+
cacheGeneration += 1;
|
|
632
1003
|
if (cachedKey) cachedKey.fill(0);
|
|
1004
|
+
if (cachedFingerprint) cachedFingerprint.fill(0);
|
|
633
1005
|
cachedKey = null;
|
|
634
1006
|
cachedSalt = null;
|
|
635
1007
|
cachedFingerprint = null;
|
|
636
1008
|
}
|
|
1009
|
+
function setCache(key, salt, fingerprint) {
|
|
1010
|
+
if (cachedKey && cachedKey !== key) cachedKey.fill(0);
|
|
1011
|
+
if (cachedFingerprint && cachedFingerprint !== fingerprint) cachedFingerprint.fill(0);
|
|
1012
|
+
cachedKey = key;
|
|
1013
|
+
cachedSalt = salt;
|
|
1014
|
+
cachedFingerprint = fingerprint;
|
|
1015
|
+
}
|
|
1016
|
+
var inflightDerivations = /* @__PURE__ */ new Map();
|
|
1017
|
+
async function sharedDeriveKey(passphrase, salt, params, normalize) {
|
|
1018
|
+
const id = [
|
|
1019
|
+
salt,
|
|
1020
|
+
`${params.N}:${params.r}:${params.p}`,
|
|
1021
|
+
normalize ? "nfc" : "raw",
|
|
1022
|
+
createHmac("sha256", FINGERPRINT_HMAC_KEY).update(passphrase, "utf8").digest("base64")
|
|
1023
|
+
].join("|");
|
|
1024
|
+
let flight = inflightDerivations.get(id);
|
|
1025
|
+
if (!flight) {
|
|
1026
|
+
flight = { promise: deriveKey(passphrase, Buffer.from(salt, "base64"), params, normalize), waiters: 0 };
|
|
1027
|
+
inflightDerivations.set(id, flight);
|
|
1028
|
+
}
|
|
1029
|
+
const mine = flight;
|
|
1030
|
+
mine.waiters += 1;
|
|
1031
|
+
try {
|
|
1032
|
+
return copyKey(await mine.promise);
|
|
1033
|
+
} finally {
|
|
1034
|
+
mine.waiters -= 1;
|
|
1035
|
+
if (mine.waiters === 0) {
|
|
1036
|
+
if (inflightDerivations.get(id) === mine) inflightDerivations.delete(id);
|
|
1037
|
+
mine.promise.then(
|
|
1038
|
+
(shared) => shared.fill(0),
|
|
1039
|
+
() => void 0
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
var establishedKeys = /* @__PURE__ */ new WeakMap();
|
|
1045
|
+
async function establishKey(passphrase) {
|
|
1046
|
+
const generation = cacheGeneration;
|
|
1047
|
+
const kdf = { ...defaultKdf() };
|
|
1048
|
+
const saltBytes = generateSalt();
|
|
1049
|
+
const salt = saltBytes.toString("base64");
|
|
1050
|
+
const key = await deriveKey(passphrase, saltBytes, kdf);
|
|
1051
|
+
const out = copyKey(key);
|
|
1052
|
+
if (generation === cacheGeneration) setCache(key, salt, passphraseFingerprint(passphrase, salt));
|
|
1053
|
+
else key.fill(0);
|
|
1054
|
+
establishedKeys.set(out, { salt, kdf });
|
|
1055
|
+
return out;
|
|
1056
|
+
}
|
|
637
1057
|
async function unlock(vault, passphrase) {
|
|
1058
|
+
assertCoherentVault(vault);
|
|
1059
|
+
if (isV3Vault(vault)) return unlockV3(vault, passphrase);
|
|
1060
|
+
if (!vaultVerifiesPassphrases(vault)) return establishKey(passphrase);
|
|
638
1061
|
const fingerprint = passphraseFingerprint(passphrase, vault.salt);
|
|
639
1062
|
if (cachedKey && cachedSalt === vault.salt && cachedFingerprint && cachedFingerprint.length === fingerprint.length && timingSafeEqual(cachedFingerprint, fingerprint)) {
|
|
640
|
-
|
|
1063
|
+
fingerprint.fill(0);
|
|
1064
|
+
return copyKey(cachedKey);
|
|
641
1065
|
}
|
|
642
|
-
const
|
|
1066
|
+
const generation = cacheGeneration;
|
|
643
1067
|
const params = vault.kdf ?? LEGACY_KDF;
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
defaultP: DEFAULT_KDF.p
|
|
652
|
-
});
|
|
1068
|
+
logSlowKdf(params);
|
|
1069
|
+
let key;
|
|
1070
|
+
try {
|
|
1071
|
+
key = await unlockDerivation(vault, passphrase, params);
|
|
1072
|
+
} catch (err) {
|
|
1073
|
+
fingerprint.fill(0);
|
|
1074
|
+
throw err;
|
|
653
1075
|
}
|
|
654
|
-
|
|
1076
|
+
if (generation !== cacheGeneration) {
|
|
1077
|
+
fingerprint.fill(0);
|
|
1078
|
+
return key;
|
|
1079
|
+
}
|
|
1080
|
+
setCache(key, vault.salt, fingerprint);
|
|
1081
|
+
return copyKey(key);
|
|
1082
|
+
}
|
|
1083
|
+
function logSlowKdf(params) {
|
|
1084
|
+
if (!kdfExceedsDefault(params)) return;
|
|
1085
|
+
const d = defaultKdf();
|
|
1086
|
+
log("debug", "Vault KDF parameters exceed this build's default; key derivation will be slower", {
|
|
1087
|
+
N: params.N,
|
|
1088
|
+
r: params.r,
|
|
1089
|
+
p: params.p,
|
|
1090
|
+
defaultN: d.N,
|
|
1091
|
+
defaultR: d.r,
|
|
1092
|
+
defaultP: d.p
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
function v3CacheId(vault) {
|
|
1096
|
+
const slot = vault.keyslots.passphrase;
|
|
1097
|
+
return `v3|${vault.vault_id}|${slot.salt}|${slot.digest}`;
|
|
1098
|
+
}
|
|
1099
|
+
function slotDigestMatches(vaultId, slot) {
|
|
1100
|
+
const recorded = Buffer.from(slot.digest, "base64");
|
|
1101
|
+
const actual = Buffer.from(passphraseSlotDigest(vaultId, slot), "base64");
|
|
1102
|
+
return recorded.length === actual.length && timingSafeEqual(recorded, actual);
|
|
1103
|
+
}
|
|
1104
|
+
async function unlockV3(vault, passphrase) {
|
|
1105
|
+
const slot = vault.keyslots.passphrase;
|
|
1106
|
+
const cacheId = v3CacheId(vault);
|
|
1107
|
+
const fingerprint = passphraseFingerprint(passphrase, slot.salt);
|
|
1108
|
+
if (cachedKey && cachedSalt === cacheId && cachedFingerprint && cachedFingerprint.length === fingerprint.length && timingSafeEqual(cachedFingerprint, fingerprint)) {
|
|
1109
|
+
fingerprint.fill(0);
|
|
1110
|
+
return copyKey(cachedKey);
|
|
1111
|
+
}
|
|
1112
|
+
if (!slotDigestMatches(vault.vault_id, slot)) {
|
|
1113
|
+
fingerprint.fill(0);
|
|
1114
|
+
throw new Error(VAULT_SLOT_DAMAGED_ERROR);
|
|
1115
|
+
}
|
|
1116
|
+
const generation = cacheGeneration;
|
|
1117
|
+
logSlowKdf(slot.kdf);
|
|
1118
|
+
let dek;
|
|
1119
|
+
try {
|
|
1120
|
+
const kek = await sharedDeriveKey(passphrase, slot.salt, slot.kdf, true);
|
|
1121
|
+
try {
|
|
1122
|
+
dek = unwrapKey(slot.wrapped, kek, slotAad("passphrase", vault.vault_id, slot));
|
|
1123
|
+
} catch {
|
|
1124
|
+
throw new Error(VAULT_WRONG_PASSPHRASE_ERROR);
|
|
1125
|
+
} finally {
|
|
1126
|
+
kek.fill(0);
|
|
1127
|
+
}
|
|
1128
|
+
const verdict = verifyV3Contents(vault, dek);
|
|
1129
|
+
if (verdict !== "ok") {
|
|
1130
|
+
dek.fill(0);
|
|
1131
|
+
throw new Error(verdict === "marker-corrupt" ? VAULT_CHECK_CORRUPT_ERROR : VAULT_SLOT_DAMAGED_ERROR);
|
|
1132
|
+
}
|
|
1133
|
+
} catch (err) {
|
|
1134
|
+
fingerprint.fill(0);
|
|
1135
|
+
throw err;
|
|
1136
|
+
}
|
|
1137
|
+
if (generation !== cacheGeneration) {
|
|
1138
|
+
fingerprint.fill(0);
|
|
1139
|
+
return dek;
|
|
1140
|
+
}
|
|
1141
|
+
setCache(dek, cacheId, fingerprint);
|
|
1142
|
+
return copyKey(dek);
|
|
1143
|
+
}
|
|
1144
|
+
function verifyV3Contents(vault, dek) {
|
|
1145
|
+
const entries = Object.entries(vault.entries);
|
|
1146
|
+
const someEntryDecrypts = () => entries.some(([name, e]) => canDecrypt(vault, e, dek, vaultEntryAad(vault, name)));
|
|
1147
|
+
if (vault.check) {
|
|
1148
|
+
if (checkMarkerMatches(vault, dek)) return "ok";
|
|
1149
|
+
return someEntryDecrypts() ? "marker-corrupt" : "mismatch";
|
|
1150
|
+
}
|
|
1151
|
+
if (entries.length === 0 || someEntryDecrypts()) return "ok";
|
|
1152
|
+
return "mismatch";
|
|
1153
|
+
}
|
|
1154
|
+
async function unlockDerivation(vault, passphrase, params) {
|
|
1155
|
+
const key = await sharedDeriveKey(passphrase, vault.salt, params, true);
|
|
1156
|
+
let primary;
|
|
655
1157
|
try {
|
|
656
1158
|
verifyKey(vault, key);
|
|
1159
|
+
return key;
|
|
657
1160
|
} catch (err) {
|
|
658
|
-
if (normalizePassphrase(passphrase) === passphrase) throw err;
|
|
659
1161
|
key.fill(0);
|
|
660
|
-
|
|
1162
|
+
primary = err;
|
|
1163
|
+
}
|
|
1164
|
+
if (errorMessage(primary) !== VAULT_WRONG_PASSPHRASE_ERROR) throw primary;
|
|
1165
|
+
const nfc = normalizePassphrase(passphrase);
|
|
1166
|
+
const nfd = passphrase.normalize("NFD");
|
|
1167
|
+
const legacyForms = [];
|
|
1168
|
+
if (passphrase !== nfc) legacyForms.push(passphrase);
|
|
1169
|
+
if (nfd !== passphrase && nfd !== nfc) legacyForms.push(nfd);
|
|
1170
|
+
for (const form of legacyForms) {
|
|
1171
|
+
const retry = await sharedDeriveKey(form, vault.salt, params, false);
|
|
661
1172
|
try {
|
|
662
|
-
verifyKey(vault,
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
1173
|
+
verifyKey(vault, retry);
|
|
1174
|
+
return retry;
|
|
1175
|
+
} catch (err) {
|
|
1176
|
+
retry.fill(0);
|
|
1177
|
+
if (errorMessage(err) === VAULT_CHECK_CORRUPT_ERROR) throw err;
|
|
666
1178
|
}
|
|
667
1179
|
}
|
|
668
|
-
|
|
669
|
-
cachedSalt = vault.salt;
|
|
670
|
-
cachedFingerprint = fingerprint;
|
|
671
|
-
return Buffer.from(key);
|
|
1180
|
+
throw primary;
|
|
672
1181
|
}
|
|
673
1182
|
function allowsUnboundDecrypt(vault) {
|
|
674
|
-
return vault.version <
|
|
1183
|
+
return vault.version < FIRST_BOUND_SCHEMA_VERSION;
|
|
675
1184
|
}
|
|
676
1185
|
function decryptBound(vault, entry, key, aad) {
|
|
677
1186
|
try {
|
|
@@ -691,7 +1200,7 @@ function canDecrypt(vault, entry, key, aad) {
|
|
|
691
1200
|
}
|
|
692
1201
|
function verifyKey(vault, key) {
|
|
693
1202
|
const entries = Object.entries(vault.entries);
|
|
694
|
-
const someEntryDecrypts = () => entries.some(([name, e]) => canDecrypt(vault, e, key, name));
|
|
1203
|
+
const someEntryDecrypts = () => entries.some(([name, e]) => canDecrypt(vault, e, key, vaultEntryAad(vault, name)));
|
|
695
1204
|
if (vault.check) {
|
|
696
1205
|
if (checkMarkerMatches(vault, key)) return;
|
|
697
1206
|
if (someEntryDecrypts()) throw new Error(VAULT_CHECK_CORRUPT_ERROR);
|
|
@@ -704,19 +1213,20 @@ function verifyKey(vault, key) {
|
|
|
704
1213
|
function checkMarkerMatches(vault, key) {
|
|
705
1214
|
if (!vault.check) return false;
|
|
706
1215
|
try {
|
|
707
|
-
return decryptBound(vault, vault.check, key,
|
|
1216
|
+
return decryptBound(vault, vault.check, key, vaultCheckAad(vault)) === VAULT_CHECK_PLAINTEXT;
|
|
708
1217
|
} catch {
|
|
709
1218
|
return false;
|
|
710
1219
|
}
|
|
711
1220
|
}
|
|
712
1221
|
function ensureCheck(vault, key) {
|
|
713
1222
|
if (vault.check) return vault;
|
|
714
|
-
return { ...vault, check: encryptEntry(VAULT_CHECK_PLAINTEXT, key,
|
|
1223
|
+
return { ...vault, check: encryptEntry(VAULT_CHECK_PLAINTEXT, key, vaultCheckAad(vault)) };
|
|
715
1224
|
}
|
|
716
1225
|
function isUnlocked() {
|
|
717
1226
|
return cachedKey !== null;
|
|
718
1227
|
}
|
|
719
1228
|
function vaultVerifiesPassphrases(vault) {
|
|
1229
|
+
if (isV3Vault(vault)) return true;
|
|
720
1230
|
return vault.check !== void 0 || Object.keys(vault.entries).length > 0;
|
|
721
1231
|
}
|
|
722
1232
|
async function checkVaultPassphrase(vault, passphrase) {
|
|
@@ -727,6 +1237,7 @@ async function checkVaultPassphrase(vault, passphrase) {
|
|
|
727
1237
|
} catch (err) {
|
|
728
1238
|
const msg = err instanceof Error ? err.message : String(err);
|
|
729
1239
|
if (msg === VAULT_CHECK_CORRUPT_ERROR) return "marker-corrupt";
|
|
1240
|
+
if (msg === VAULT_SLOT_DAMAGED_ERROR) return "slot-damaged";
|
|
730
1241
|
if (msg === VAULT_WRONG_PASSPHRASE_ERROR) return "wrong";
|
|
731
1242
|
throw err;
|
|
732
1243
|
}
|
|
@@ -734,51 +1245,132 @@ async function checkVaultPassphrase(vault, passphrase) {
|
|
|
734
1245
|
function vaultCheckCorruptHint(path2) {
|
|
735
1246
|
return `Your entries are intact: delete the "check" key from ${path2} by hand and re-run -- the next \`yaw-mcp secrets set\` re-stamps it.`;
|
|
736
1247
|
}
|
|
737
|
-
async function
|
|
738
|
-
const
|
|
739
|
-
const
|
|
1248
|
+
async function buildV3(plaintext, passphrase, recovery, previousSlotSalt) {
|
|
1249
|
+
const vaultId = generateVaultId();
|
|
1250
|
+
const slotSaltBytes = generateSalt();
|
|
1251
|
+
const slotSalt = slotSaltBytes.toString("base64");
|
|
1252
|
+
if (previousSlotSalt !== void 0 && slotSalt === previousSlotSalt) {
|
|
1253
|
+
throw new Error("internal error: a re-key must use a fresh passphrase slot salt");
|
|
1254
|
+
}
|
|
1255
|
+
const kdf = { ...defaultKdf() };
|
|
1256
|
+
const dek = generateDek();
|
|
1257
|
+
let kek;
|
|
1258
|
+
try {
|
|
1259
|
+
kek = await deriveKey(passphrase, slotSaltBytes, kdf);
|
|
1260
|
+
const wrapped = wrapKey(dek, kek, slotAad("passphrase", vaultId, { salt: slotSalt, kdf }));
|
|
1261
|
+
const keyslots = {
|
|
1262
|
+
passphrase: {
|
|
1263
|
+
salt: slotSalt,
|
|
1264
|
+
kdf,
|
|
1265
|
+
wrapped,
|
|
1266
|
+
digest: passphraseSlotDigest(vaultId, { salt: slotSalt, kdf, wrapped })
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
let recoveryCode;
|
|
1270
|
+
if (recovery) {
|
|
1271
|
+
const issued = writeRecoverySlot(vaultId, dek);
|
|
1272
|
+
keyslots.recovery = issued.slot;
|
|
1273
|
+
recoveryCode = issued.code;
|
|
1274
|
+
}
|
|
1275
|
+
const v3 = {
|
|
1276
|
+
version: KEYSLOT_SCHEMA_VERSION,
|
|
1277
|
+
vault_id: vaultId,
|
|
1278
|
+
// The inert placeholder (see the file-format note): random, so it says
|
|
1279
|
+
// nothing, and present, so builds >= 0.73.1 reach their version gate.
|
|
1280
|
+
salt: generateSalt().toString("base64"),
|
|
1281
|
+
keyslots,
|
|
1282
|
+
entries: {}
|
|
1283
|
+
};
|
|
1284
|
+
v3.check = encryptEntry(VAULT_CHECK_PLAINTEXT, dek, vaultCheckAad(v3));
|
|
1285
|
+
for (const [name, value] of plaintext) {
|
|
1286
|
+
setJsonKey(v3.entries, name, encryptEntry(value, dek, vaultEntryAad(v3, name)));
|
|
1287
|
+
}
|
|
1288
|
+
return recoveryCode === void 0 ? { vault: v3 } : { vault: v3, recoveryCode };
|
|
1289
|
+
} finally {
|
|
1290
|
+
dek.fill(0);
|
|
1291
|
+
kek?.fill(0);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
function writeRecoverySlot(vaultId, dek) {
|
|
1295
|
+
const secret = generateRecoverySecret();
|
|
1296
|
+
const saltBytes = generateSalt();
|
|
1297
|
+
let kek;
|
|
740
1298
|
try {
|
|
741
|
-
|
|
1299
|
+
kek = deriveRecoveryKek(secret, saltBytes);
|
|
1300
|
+
const salt = saltBytes.toString("base64");
|
|
1301
|
+
const created = (/* @__PURE__ */ new Date()).toISOString();
|
|
1302
|
+
const wrapped = wrapKey(dek, kek, slotAad("recovery", vaultId, { salt, kdf: RECOVERY_SLOT_KDF, created }));
|
|
1303
|
+
return { slot: { salt, kdf: RECOVERY_SLOT_KDF, created, wrapped }, code: formatRecoveryCode(secret) };
|
|
742
1304
|
} finally {
|
|
743
|
-
|
|
1305
|
+
secret.fill(0);
|
|
1306
|
+
kek?.fill(0);
|
|
744
1307
|
}
|
|
745
1308
|
}
|
|
746
|
-
async function
|
|
747
|
-
|
|
748
|
-
|
|
1309
|
+
async function createVaultV3(passphrase, opts) {
|
|
1310
|
+
return buildV3(/* @__PURE__ */ new Map(), passphrase, opts.recovery, void 0);
|
|
1311
|
+
}
|
|
1312
|
+
async function rekeyVault(vault, currentKey, newPassphrase, opts) {
|
|
1313
|
+
assertCoherentVault(vault);
|
|
1314
|
+
const op = opts.operation ?? "rotate";
|
|
1315
|
+
if (vault.check && !checkMarkerMatches(vault, currentKey)) {
|
|
1316
|
+
throw new Error(`${op} aborted: current passphrase is wrong (vault check failed to decrypt)`);
|
|
749
1317
|
}
|
|
750
1318
|
const plaintext = /* @__PURE__ */ new Map();
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
1319
|
+
try {
|
|
1320
|
+
for (const [name, entry] of Object.entries(vault.entries)) {
|
|
1321
|
+
try {
|
|
1322
|
+
plaintext.set(name, decryptBound(vault, entry, currentKey, vaultEntryAad(vault, name)));
|
|
1323
|
+
} catch {
|
|
1324
|
+
if (vault.check) {
|
|
1325
|
+
throw new Error(
|
|
1326
|
+
`${op} aborted: entry "${name}" failed to decrypt, but the passphrase is right (the vault's check marker verifies under it) -- the entry is corrupt, or was written under a different passphrase than the rest of the vault. Remove it (\`yaw-mcp secrets remove ${name}\`), set it again, and re-run ${op}.`
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
throw new Error(`${op} aborted: entry "${name}" failed to decrypt under the current passphrase`);
|
|
760
1330
|
}
|
|
761
|
-
throw new Error(`rotate aborted: entry "${name}" failed to decrypt under the current passphrase`);
|
|
762
1331
|
}
|
|
1332
|
+
return await buildV3(plaintext, newPassphrase, opts.recovery, vault.keyslots?.passphrase.salt);
|
|
1333
|
+
} finally {
|
|
1334
|
+
plaintext.clear();
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
function unlockWithRecoveryCode(vault, code) {
|
|
1338
|
+
if (!isV3Vault(vault) || !vault.keyslots.recovery) throw new Error(VAULT_NO_RECOVERY_ERROR);
|
|
1339
|
+
const slot = vault.keyslots.recovery;
|
|
1340
|
+
let secret;
|
|
1341
|
+
if (typeof code === "string") {
|
|
1342
|
+
secret = parseRecoveryCode(code);
|
|
1343
|
+
} else {
|
|
1344
|
+
if (code.length !== RECOVERY_SECRET_LEN) throw new Error(`recovery secret must be ${RECOVERY_SECRET_LEN} bytes`);
|
|
1345
|
+
secret = copyKey(code);
|
|
763
1346
|
}
|
|
764
|
-
|
|
765
|
-
const newKey = await deriveKey(newPassphrase, newSalt, DEFAULT_KDF);
|
|
1347
|
+
let kek;
|
|
766
1348
|
try {
|
|
767
|
-
|
|
768
|
-
for (const [name, value] of plaintext) {
|
|
769
|
-
setJsonKey(entries, name, encryptEntry(value, newKey, name));
|
|
770
|
-
}
|
|
771
|
-
return {
|
|
772
|
-
version: SECRETS_SCHEMA_VERSION,
|
|
773
|
-
salt: newSalt.toString("base64"),
|
|
774
|
-
kdf: { ...DEFAULT_KDF },
|
|
775
|
-
entries,
|
|
776
|
-
check: encryptEntry(VAULT_CHECK_PLAINTEXT, newKey, VAULT_CHECK_AAD)
|
|
777
|
-
};
|
|
1349
|
+
kek = deriveRecoveryKek(secret, Buffer.from(slot.salt, "base64"));
|
|
778
1350
|
} finally {
|
|
779
|
-
|
|
780
|
-
newKey.fill(0);
|
|
1351
|
+
secret.fill(0);
|
|
781
1352
|
}
|
|
1353
|
+
let dek;
|
|
1354
|
+
try {
|
|
1355
|
+
dek = unwrapKey(slot.wrapped, kek, slotAad("recovery", vault.vault_id, slot));
|
|
1356
|
+
} catch {
|
|
1357
|
+
throw new Error(RECOVERY_CODE_WRONG_VAULT_ERROR);
|
|
1358
|
+
} finally {
|
|
1359
|
+
kek.fill(0);
|
|
1360
|
+
}
|
|
1361
|
+
const verdict = verifyV3Contents(vault, dek);
|
|
1362
|
+
if (verdict !== "ok") {
|
|
1363
|
+
dek.fill(0);
|
|
1364
|
+
throw new Error(verdict === "marker-corrupt" ? VAULT_CHECK_CORRUPT_ERROR : VAULT_RECOVERY_SLOT_DAMAGED_ERROR);
|
|
1365
|
+
}
|
|
1366
|
+
return dek;
|
|
1367
|
+
}
|
|
1368
|
+
function recoveryStatus(vault) {
|
|
1369
|
+
if (!isV3Vault(vault)) return { state: "unsupported", created: null };
|
|
1370
|
+
const slot = vault.keyslots.recovery;
|
|
1371
|
+
if (slot) return { state: "set", created: slot.created };
|
|
1372
|
+
if (vault.recoveryMalformed) return { state: "malformed", created: null };
|
|
1373
|
+
return { state: "none", created: null };
|
|
782
1374
|
}
|
|
783
1375
|
function listKeys(vault) {
|
|
784
1376
|
return Object.keys(vault.entries).sort();
|
|
@@ -792,10 +1384,19 @@ function setSecret(vault, key, name, value) {
|
|
|
792
1384
|
`invalid secret name "${name}" -- use letters, digits, "_", "." or "-" only; other characters can never be referenced as \${secret:NAME}`
|
|
793
1385
|
);
|
|
794
1386
|
}
|
|
1387
|
+
assertCoherentVault(vault);
|
|
1388
|
+
if (isV3Vault(vault)) {
|
|
1389
|
+
return ensureCheck(
|
|
1390
|
+
{ ...vault, entries: { ...vault.entries, [name]: encryptEntry(value, key, vaultEntryAad(vault, name)) } },
|
|
1391
|
+
key
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
const established = vaultVerifiesPassphrases(vault) ? void 0 : establishedKeys.get(key);
|
|
1395
|
+
const keyed = established ? { salt: established.salt, kdf: { ...established.kdf } } : { salt: vault.salt, kdf: vault.kdf ?? { ...LEGACY_KDF } };
|
|
795
1396
|
return ensureCheck(
|
|
796
1397
|
{
|
|
797
1398
|
...vault,
|
|
798
|
-
|
|
1399
|
+
...keyed,
|
|
799
1400
|
entries: {
|
|
800
1401
|
...vault.entries,
|
|
801
1402
|
[name]: encryptEntry(value, key, name)
|
|
@@ -811,17 +1412,15 @@ function removeSecret(vault, name) {
|
|
|
811
1412
|
}
|
|
812
1413
|
function getSecret(vault, key, name) {
|
|
813
1414
|
if (!Object.hasOwn(vault.entries, name)) return null;
|
|
814
|
-
|
|
815
|
-
if (!entry) return null;
|
|
816
|
-
return decryptBound(vault, entry, key, name);
|
|
1415
|
+
return decryptBound(vault, vault.entries[name], key, vaultEntryAad(vault, name));
|
|
817
1416
|
}
|
|
818
1417
|
function newVault() {
|
|
819
1418
|
return {
|
|
820
|
-
version:
|
|
1419
|
+
version: LAST_SCRYPT_SCHEMA_VERSION,
|
|
821
1420
|
salt: generateSalt().toString("base64"),
|
|
822
1421
|
// Recorded, never assumed: see KdfParams. A vault that carries its own
|
|
823
1422
|
// cost factor keeps opening after the default is raised.
|
|
824
|
-
kdf: { ...
|
|
1423
|
+
kdf: { ...defaultKdf() },
|
|
825
1424
|
entries: {}
|
|
826
1425
|
};
|
|
827
1426
|
}
|
|
@@ -844,7 +1443,7 @@ function resolveSecretRefs(env, vault, key) {
|
|
|
844
1443
|
return full;
|
|
845
1444
|
}
|
|
846
1445
|
try {
|
|
847
|
-
const value = decryptBound(vault, entry, key, name);
|
|
1446
|
+
const value = decryptBound(vault, entry, key, vaultEntryAad(vault, name));
|
|
848
1447
|
decrypted.set(name, value);
|
|
849
1448
|
return value;
|
|
850
1449
|
} catch {
|
|
@@ -864,6 +1463,7 @@ var SECRET_REF_OPENER = "${secret:";
|
|
|
864
1463
|
var MALFORMED_REF_MARKER = "<malformed ref>";
|
|
865
1464
|
var SECRET_NAME_PREFIX_RE = new RegExp(`^${SECRET_NAME_CLASS}`);
|
|
866
1465
|
var MALFORMED_REF_NAME_CHARS = 16;
|
|
1466
|
+
var MALFORMED_REF_MAX_CHARS = SECRET_REF_OPENER.length + MALFORMED_REF_NAME_CHARS + 2;
|
|
867
1467
|
function describeMalformedSecretRef(span) {
|
|
868
1468
|
let printable2 = "";
|
|
869
1469
|
for (const ch of span) {
|
|
@@ -932,7 +1532,7 @@ function hasSecretRefs(env) {
|
|
|
932
1532
|
}
|
|
933
1533
|
|
|
934
1534
|
// src/trust.ts
|
|
935
|
-
import { createHash } from "crypto";
|
|
1535
|
+
import { createHash as createHash2 } from "crypto";
|
|
936
1536
|
import { chmod as chmod2, readFile as readFile2 } from "fs/promises";
|
|
937
1537
|
import { homedir as homedir2 } from "os";
|
|
938
1538
|
import { basename as basename2, dirname as dirname2, join as join3, resolve as resolve2 } from "path";
|
|
@@ -968,7 +1568,7 @@ function normalizeTrustKey(p, platform = process.platform) {
|
|
|
968
1568
|
return caseInsensitiveFs ? resolved.toLowerCase() : resolved;
|
|
969
1569
|
}
|
|
970
1570
|
function hashTrustContent(contents) {
|
|
971
|
-
return
|
|
1571
|
+
return createHash2("sha256").update(contents).digest("hex");
|
|
972
1572
|
}
|
|
973
1573
|
function isTrustBypassEnabled(env = process.env) {
|
|
974
1574
|
return isFeatureEnabled(TRUST_BYPASS_ENV, env);
|
|
@@ -1400,15 +2000,19 @@ async function readBundlesRawAt(path2) {
|
|
|
1400
2000
|
}
|
|
1401
2001
|
}
|
|
1402
2002
|
var READ_FAILURE_MARKER = "could not read file (";
|
|
1403
|
-
async function readBundlesAt(path2, warnings) {
|
|
2003
|
+
async function readBundlesAt(path2, warnings, onWarning) {
|
|
1404
2004
|
const r = await readBundlesRawAt(path2);
|
|
1405
2005
|
if (r.kind === "absent") return { exists: false, file: null };
|
|
1406
2006
|
if (r.kind === "error") {
|
|
1407
2007
|
warnings.push(`${path2}: ${READ_FAILURE_MARKER}${r.message}) -- skipping`);
|
|
1408
|
-
|
|
2008
|
+
warnLoad(onWarning, "Could not read bundles.json", { path: path2, error: r.message, code: r.code });
|
|
1409
2009
|
return { exists: true, file: null };
|
|
1410
2010
|
}
|
|
1411
|
-
return { exists: true, file: parseBundlesContent(path2, r.raw, warnings) };
|
|
2011
|
+
return { exists: true, file: parseBundlesContent(path2, r.raw, warnings, onWarning) };
|
|
2012
|
+
}
|
|
2013
|
+
function warnLoad(sink, message, data) {
|
|
2014
|
+
if (sink !== void 0) sink({ message, data });
|
|
2015
|
+
else log("warn", message, data);
|
|
1412
2016
|
}
|
|
1413
2017
|
function jsonErrorLocation(raw, err) {
|
|
1414
2018
|
const text = raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw;
|
|
@@ -1430,7 +2034,7 @@ function jsonErrorLocation(raw, err) {
|
|
|
1430
2034
|
const column = (lines[lines.length - 1] ?? "").length + 1;
|
|
1431
2035
|
return `at line ${line}, column ${column}`;
|
|
1432
2036
|
}
|
|
1433
|
-
function parseBundlesContent(path2, rawBytes, warnings) {
|
|
2037
|
+
function parseBundlesContent(path2, rawBytes, warnings, onWarning) {
|
|
1434
2038
|
const raw = rawBytes.toString("utf8");
|
|
1435
2039
|
let parsed;
|
|
1436
2040
|
try {
|
|
@@ -1438,7 +2042,7 @@ function parseBundlesContent(path2, rawBytes, warnings) {
|
|
|
1438
2042
|
} catch (err) {
|
|
1439
2043
|
const where = jsonErrorLocation(raw, err);
|
|
1440
2044
|
warnings.push(`${path2}: invalid JSON ${where} -- file ignored`);
|
|
1441
|
-
|
|
2045
|
+
warnLoad(onWarning, "bundles.json is not valid JSON; ignoring", { path: path2, location: where });
|
|
1442
2046
|
return null;
|
|
1443
2047
|
}
|
|
1444
2048
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
@@ -1497,7 +2101,7 @@ function rawEntryLoads(entry, home = homedir3()) {
|
|
|
1497
2101
|
return validateEntry(entry, [], home) !== null;
|
|
1498
2102
|
}
|
|
1499
2103
|
function hashContent(servers) {
|
|
1500
|
-
const h =
|
|
2104
|
+
const h = createHash3("sha256");
|
|
1501
2105
|
h.update(JSON.stringify(servers));
|
|
1502
2106
|
return `local-${h.digest("hex").slice(0, 16)}`;
|
|
1503
2107
|
}
|
|
@@ -1589,6 +2193,7 @@ function bundlesSignature(paths) {
|
|
|
1589
2193
|
async function loadLocalBundles(opts = {}) {
|
|
1590
2194
|
const cwd = opts.cwd ?? process.cwd();
|
|
1591
2195
|
const home = opts.home ?? homedir3();
|
|
2196
|
+
const onWarning = opts.onWarning;
|
|
1592
2197
|
const warnings = [];
|
|
1593
2198
|
const globalPath = localBundlesPath(userConfigDir(home));
|
|
1594
2199
|
const probe = await probeProjectTrust({ cwd, home, env: opts.env });
|
|
@@ -1607,10 +2212,13 @@ async function loadLocalBundles(opts = {}) {
|
|
|
1607
2212
|
if (projectPath !== null) {
|
|
1608
2213
|
if (probe.status === "unreadable") {
|
|
1609
2214
|
warnings.push(`${projectPath}: ${READ_FAILURE_MARKER}${probe.error}) -- skipping`);
|
|
1610
|
-
|
|
2215
|
+
warnLoad(onWarning, "Could not read bundles.json", { path: projectPath, error: probe.error });
|
|
1611
2216
|
projectResult = { exists: true, file: null };
|
|
1612
2217
|
} else {
|
|
1613
|
-
projectResult = {
|
|
2218
|
+
projectResult = {
|
|
2219
|
+
exists: true,
|
|
2220
|
+
file: parseBundlesContent(projectPath, probe.raw, warnings, onWarning)
|
|
2221
|
+
};
|
|
1614
2222
|
}
|
|
1615
2223
|
}
|
|
1616
2224
|
let file;
|
|
@@ -1619,14 +2227,14 @@ async function loadLocalBundles(opts = {}) {
|
|
|
1619
2227
|
file = projectResult.file;
|
|
1620
2228
|
sourcePath = projectPath;
|
|
1621
2229
|
} else {
|
|
1622
|
-
const globalResult = await readBundlesAt(globalPath, warnings);
|
|
2230
|
+
const globalResult = await readBundlesAt(globalPath, warnings, onWarning);
|
|
1623
2231
|
file = globalResult.file;
|
|
1624
2232
|
sourcePath = globalResult.exists ? globalPath : null;
|
|
1625
2233
|
}
|
|
1626
2234
|
if (!file) {
|
|
1627
2235
|
if (sourcePath === projectPath && projectPath !== null) {
|
|
1628
2236
|
const scratch = [];
|
|
1629
|
-
const globalResult = await readBundlesAt(globalPath, scratch);
|
|
2237
|
+
const globalResult = await readBundlesAt(globalPath, scratch, onWarning);
|
|
1630
2238
|
if (globalResult.file?.defaultRuntime !== void 0) {
|
|
1631
2239
|
return {
|
|
1632
2240
|
config: null,
|
|
@@ -1649,7 +2257,7 @@ async function loadLocalBundles(opts = {}) {
|
|
|
1649
2257
|
let defaultRuntimePath = defaultRuntime2 !== void 0 ? sourcePath ?? void 0 : void 0;
|
|
1650
2258
|
if (defaultRuntime2 === void 0 && sourcePath === projectPath && projectPath !== null) {
|
|
1651
2259
|
const scratch = [];
|
|
1652
|
-
const globalResult = await readBundlesAt(globalPath, scratch);
|
|
2260
|
+
const globalResult = await readBundlesAt(globalPath, scratch, onWarning);
|
|
1653
2261
|
if (globalResult.file?.defaultRuntime !== void 0) {
|
|
1654
2262
|
defaultRuntime2 = globalResult.file.defaultRuntime;
|
|
1655
2263
|
defaultRuntimePath = globalPath;
|
|
@@ -1776,6 +2384,9 @@ function mergeServerEntry(existing, incoming) {
|
|
|
1776
2384
|
delete merged.headers;
|
|
1777
2385
|
if (merged.transport !== void 0 && merged.transport !== "stdio") delete merged.transport;
|
|
1778
2386
|
if (incoming.type === void 0 && merged.type === "remote") delete merged.type;
|
|
2387
|
+
if (base.git === void 0 && incoming.optionalEnvKeys === void 0) {
|
|
2388
|
+
delete merged.optionalEnvKeys;
|
|
2389
|
+
}
|
|
1779
2390
|
} else if (typeof incoming.command === "string" || typeof incoming.url === "string") {
|
|
1780
2391
|
delete merged.git;
|
|
1781
2392
|
}
|
|
@@ -1793,6 +2404,9 @@ function mergeServerEntry(existing, incoming) {
|
|
|
1793
2404
|
}
|
|
1794
2405
|
merged.env = Object.keys(env).length > 0 ? env : void 0;
|
|
1795
2406
|
}
|
|
2407
|
+
if (incoming.complianceGrade === void 0 && !sameLaunch(launchShapeOf(base), launchShapeOf(merged))) {
|
|
2408
|
+
delete merged.complianceGrade;
|
|
2409
|
+
}
|
|
1796
2410
|
return merged;
|
|
1797
2411
|
}
|
|
1798
2412
|
function launchShapeOf(entry) {
|
|
@@ -1881,18 +2495,26 @@ function mergedUpsertEntry(servers, entry, target) {
|
|
|
1881
2495
|
if (target.matchedByNamespace) return written;
|
|
1882
2496
|
return { ...written, namespace: target.namespace ?? written.namespace, id: target.id ?? written.id };
|
|
1883
2497
|
}
|
|
2498
|
+
function droppedEnvValueKeys(stored, written) {
|
|
2499
|
+
const before = envStrings(stored?.env) ?? {};
|
|
2500
|
+
const after = envStrings(written.env) ?? {};
|
|
2501
|
+
return Object.keys(before).filter((k) => (before[k] ?? "").trim() !== "" && !Object.hasOwn(after, k));
|
|
2502
|
+
}
|
|
1884
2503
|
async function previewUpsertUserBundle(entry, opts = {}) {
|
|
1885
2504
|
const home = opts.home ?? homedir3();
|
|
1886
2505
|
const warnings = [];
|
|
1887
2506
|
const path2 = opts.configDir !== void 0 ? localBundlesPath(opts.configDir) : void 0;
|
|
1888
2507
|
const file = await readRawUserBundles(home, warnings, path2);
|
|
1889
2508
|
const target = resolveUpsertTarget(file.servers, entry, opts.origin ?? "catalog");
|
|
2509
|
+
const merged = mergedUpsertEntry(file.servers, entry, target);
|
|
2510
|
+
const dropped = target.idx >= 0 ? droppedEnvValueKeys(file.servers[target.idx], merged) : [];
|
|
1890
2511
|
return {
|
|
1891
2512
|
replaced: target.idx >= 0,
|
|
1892
2513
|
refusal: target.refusal,
|
|
1893
2514
|
namespace: target.namespace ?? entry.namespace,
|
|
1894
|
-
entry:
|
|
2515
|
+
entry: merged,
|
|
1895
2516
|
launchChanged: target.launchChanged,
|
|
2517
|
+
...dropped.length > 0 ? { droppedEnvKeys: dropped } : {},
|
|
1896
2518
|
replacing: target.idx >= 0 ? launchShapeOf(file.servers[target.idx] ?? {}) : void 0,
|
|
1897
2519
|
warnings
|
|
1898
2520
|
};
|
|
@@ -1912,6 +2534,7 @@ async function doUpsertUserBundle(entry, opts) {
|
|
|
1912
2534
|
const idx = target.idx;
|
|
1913
2535
|
const replaced = idx >= 0;
|
|
1914
2536
|
const written = mergedUpsertEntry(file.servers, entry, target);
|
|
2537
|
+
const dropped = replaced ? droppedEnvValueKeys(file.servers[idx], written) : [];
|
|
1915
2538
|
if (replaced) file.servers[idx] = written;
|
|
1916
2539
|
else file.servers.push(written);
|
|
1917
2540
|
const contents = await writeBundlesFile(path2, file);
|
|
@@ -1928,6 +2551,7 @@ async function doUpsertUserBundle(entry, opts) {
|
|
|
1928
2551
|
replaced,
|
|
1929
2552
|
entry: written,
|
|
1930
2553
|
launchChanged: target.launchChanged,
|
|
2554
|
+
...dropped.length > 0 ? { droppedEnvKeys: dropped } : {},
|
|
1931
2555
|
warnings,
|
|
1932
2556
|
...projectTrust ? { projectTrust } : {}
|
|
1933
2557
|
};
|
|
@@ -1945,7 +2569,13 @@ function updateGitPin(namespace, expectedCommit, patch, opts = {}) {
|
|
|
1945
2569
|
async () => {
|
|
1946
2570
|
const trustedBefore = opts.configDir !== void 0 && await bytesAreTrusted(path2, home);
|
|
1947
2571
|
const raw = await readFile3(path2, "utf8");
|
|
1948
|
-
|
|
2572
|
+
let parsed;
|
|
2573
|
+
try {
|
|
2574
|
+
parsed = parseJsonc(raw);
|
|
2575
|
+
} catch (err) {
|
|
2576
|
+
throw new Error(`${path2} is not valid JSON ${jsonErrorLocation(raw, err)}; nothing was written.`);
|
|
2577
|
+
}
|
|
2578
|
+
const servers = parsed?.servers;
|
|
1949
2579
|
if (!Array.isArray(servers)) throw new Error(`${path2} has no "servers" array; nothing was written.`);
|
|
1950
2580
|
const idx = servers.findIndex((s) => s?.namespace === namespace);
|
|
1951
2581
|
const git = servers[idx]?.git;
|
|
@@ -2034,21 +2664,12 @@ import { homedir as homedir4 } from "os";
|
|
|
2034
2664
|
import { dirname as dirname3, join as join5 } from "path";
|
|
2035
2665
|
|
|
2036
2666
|
// src/default-runtime.ts
|
|
2037
|
-
import { statSync as statSync3 } from "fs";
|
|
2038
2667
|
var bundlesDefaultCache;
|
|
2039
2668
|
var warnedInvalidEnv = false;
|
|
2040
2669
|
var inflight = null;
|
|
2041
2670
|
var degradedProbe = null;
|
|
2042
2671
|
var DEGRADED_RECHECK_MS = 5e3;
|
|
2043
2672
|
var warnedDegradedBundles = false;
|
|
2044
|
-
function statSignature(path2) {
|
|
2045
|
-
try {
|
|
2046
|
-
const s = statSync3(path2);
|
|
2047
|
-
return `${s.mtimeMs}:${s.size}`;
|
|
2048
|
-
} catch {
|
|
2049
|
-
return null;
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
2673
|
function readEnvChoice(env) {
|
|
2053
2674
|
const raw = env.YAW_MCP_DEFAULT_RUNTIME?.trim();
|
|
2054
2675
|
if (raw === "oam" || raw === "node") return raw;
|
|
@@ -2068,20 +2689,19 @@ async function describeDefaultRuntime(opts = {}) {
|
|
|
2068
2689
|
async function defaultRuntime(opts = {}) {
|
|
2069
2690
|
const fromEnv = readEnvChoice(opts.env ?? process.env);
|
|
2070
2691
|
if (fromEnv !== null) return fromEnv;
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
}
|
|
2077
|
-
return inflight;
|
|
2692
|
+
const cached = bundlesDefaultCache;
|
|
2693
|
+
if (cached !== void 0 && bundlesSignature(cached.watched) === cached.signature) return cached.value;
|
|
2694
|
+
if (inflight === null) {
|
|
2695
|
+
inflight = resolveBundlesDefault(opts).finally(() => {
|
|
2696
|
+
inflight = null;
|
|
2697
|
+
});
|
|
2078
2698
|
}
|
|
2079
|
-
return
|
|
2699
|
+
return inflight;
|
|
2080
2700
|
}
|
|
2081
2701
|
async function resolveBundlesDefault(opts) {
|
|
2082
2702
|
const now = opts.now ?? Date.now;
|
|
2083
|
-
if (degradedProbe !== null && now() - degradedProbe.at < DEGRADED_RECHECK_MS && degradedProbe.
|
|
2084
|
-
return null;
|
|
2703
|
+
if (degradedProbe !== null && now() - degradedProbe.at < DEGRADED_RECHECK_MS && bundlesSignature(degradedProbe.watched) === degradedProbe.signature) {
|
|
2704
|
+
return bundlesDefaultCache?.value ?? null;
|
|
2085
2705
|
}
|
|
2086
2706
|
const bundles = await loadLocalBundles({ cwd: opts.cwd ?? process.cwd(), home: opts.home, env: opts.env }).catch(
|
|
2087
2707
|
() => null
|
|
@@ -2089,27 +2709,27 @@ async function resolveBundlesDefault(opts) {
|
|
|
2089
2709
|
const degraded = bundles === null || bundles.config === null && bundles.path !== null;
|
|
2090
2710
|
const resolved = bundles?.defaultRuntime ?? null;
|
|
2091
2711
|
if (degraded && resolved === null) {
|
|
2712
|
+
const lastGood = bundlesDefaultCache?.value ?? null;
|
|
2092
2713
|
const path2 = bundles?.path ?? null;
|
|
2093
|
-
|
|
2094
|
-
if (path2 === null || signature === null) {
|
|
2714
|
+
if (path2 === null) {
|
|
2095
2715
|
degradedProbe = null;
|
|
2096
2716
|
} else {
|
|
2097
|
-
const
|
|
2098
|
-
degradedProbe = {
|
|
2099
|
-
files: watched.map((f) => ({ path: f, signature: statSignature(f) })),
|
|
2100
|
-
at: now()
|
|
2101
|
-
};
|
|
2717
|
+
const watched2 = bundles?.consultedPaths?.length ? bundles.consultedPaths : [path2];
|
|
2718
|
+
degradedProbe = { watched: watched2, signature: bundlesSignature(watched2), at: now() };
|
|
2102
2719
|
}
|
|
2103
2720
|
if (!warnedDegradedBundles) {
|
|
2104
2721
|
warnedDegradedBundles = true;
|
|
2105
|
-
log(
|
|
2106
|
-
|
|
2107
|
-
|
|
2722
|
+
log(
|
|
2723
|
+
"warn",
|
|
2724
|
+
lastGood === null ? "bundles.json could not be read for the default runtime; using the fallback until the file changes" : `bundles.json could not be read for the default runtime; keeping the last value read ("${lastGood}") until the file changes`,
|
|
2725
|
+
{ path: path2 ?? "(unknown)" }
|
|
2726
|
+
);
|
|
2108
2727
|
}
|
|
2109
|
-
return
|
|
2728
|
+
return lastGood;
|
|
2110
2729
|
}
|
|
2111
2730
|
degradedProbe = null;
|
|
2112
|
-
|
|
2731
|
+
const watched = bundles?.consultedPaths ?? [];
|
|
2732
|
+
bundlesDefaultCache = { value: resolved, watched, signature: bundlesSignature(watched) };
|
|
2113
2733
|
return resolved;
|
|
2114
2734
|
}
|
|
2115
2735
|
function describeLaunchShape(command, args) {
|
|
@@ -2122,29 +2742,28 @@ function describeLaunchShape(command, args) {
|
|
|
2122
2742
|
return null;
|
|
2123
2743
|
}
|
|
2124
2744
|
if (kind === "npx") {
|
|
2125
|
-
const
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2745
|
+
const launch = classifyNpxLaunch(args);
|
|
2746
|
+
switch (launch.kind) {
|
|
2747
|
+
case "no-spec":
|
|
2748
|
+
return { code: "npx-no-spec", detail: "the npx launch names no package" };
|
|
2749
|
+
case "flag-spec":
|
|
2750
|
+
return {
|
|
2751
|
+
code: "npx-flag-spec",
|
|
2752
|
+
detail: `the npx launch carries ${launch.flag}, a flag yaw-mcp does not parse`
|
|
2753
|
+
};
|
|
2754
|
+
case "non-registry-spec":
|
|
2755
|
+
return {
|
|
2756
|
+
code: "npx-non-registry-spec",
|
|
2757
|
+
detail: `the npx spec ${launch.spec} is a git/path target, not a registry package`
|
|
2758
|
+
};
|
|
2759
|
+
case "version-range":
|
|
2760
|
+
return {
|
|
2761
|
+
code: "npx-version-range",
|
|
2762
|
+
detail: `the npx spec pins the range ${launch.range}, which yaw-mcp cannot evaluate`
|
|
2763
|
+
};
|
|
2764
|
+
case "hostable":
|
|
2765
|
+
return null;
|
|
2146
2766
|
}
|
|
2147
|
-
return null;
|
|
2148
2767
|
}
|
|
2149
2768
|
return null;
|
|
2150
2769
|
}
|
|
@@ -2221,6 +2840,13 @@ async function questionOrEof(rl, prompt) {
|
|
|
2221
2840
|
rl.off("SIGINT", onSigint);
|
|
2222
2841
|
}
|
|
2223
2842
|
}
|
|
2843
|
+
function isInteractivePrompt(opts) {
|
|
2844
|
+
if (opts.isTTY !== void 0) return opts.isTTY;
|
|
2845
|
+
if (opts.promptAnswer !== void 0) return true;
|
|
2846
|
+
const stdin = opts.io?.stdin ?? process.stdin;
|
|
2847
|
+
const stdout = opts.io?.stdout ?? process.stdout;
|
|
2848
|
+
return stdin.isTTY === true && stdout.isTTY === true;
|
|
2849
|
+
}
|
|
2224
2850
|
async function readlineAnswer(input, output, question, terminal) {
|
|
2225
2851
|
const rl = createInterface({ input, output, terminal });
|
|
2226
2852
|
try {
|
|
@@ -2264,7 +2890,8 @@ function collectSidecarSpecs(servers) {
|
|
|
2264
2890
|
const existing = byPkg.get(pkg);
|
|
2265
2891
|
if (existing) {
|
|
2266
2892
|
if (s.namespace && !existing.namespaces.includes(s.namespace)) existing.namespaces.push(s.namespace);
|
|
2267
|
-
|
|
2893
|
+
const range = configuredRange({ pkg, spec, namespaces: [], conflicting: [] });
|
|
2894
|
+
if (range !== configuredRange(existing) && !existing.conflicting.includes(spec)) existing.conflicting.push(spec);
|
|
2268
2895
|
continue;
|
|
2269
2896
|
}
|
|
2270
2897
|
byPkg.set(pkg, { pkg, spec, namespaces: s.namespace ? [s.namespace] : [], conflicting: [] });
|
|
@@ -2526,10 +3153,7 @@ async function unhostedReasons(servers, opts, home, bundles) {
|
|
|
2526
3153
|
return [...new Set(verdicts.map((v) => v.reason))];
|
|
2527
3154
|
}
|
|
2528
3155
|
function gitInteractive(opts) {
|
|
2529
|
-
|
|
2530
|
-
if (opts.isTTY !== void 0) return opts.isTTY;
|
|
2531
|
-
if (opts.promptAnswer !== void 0) return true;
|
|
2532
|
-
return Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
3156
|
+
return !opts.json && isInteractivePrompt(opts);
|
|
2533
3157
|
}
|
|
2534
3158
|
function buildGitEntriesFor(servers, bundlesPath, opts, home, print, printErr) {
|
|
2535
3159
|
return buildPinnedGitEntries(
|
|
@@ -2596,9 +3220,10 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2596
3220
|
lines,
|
|
2597
3221
|
updateError
|
|
2598
3222
|
});
|
|
3223
|
+
const afterFailure = () => existsSync2(sidecarsNodeModules(home)) ? `Servers keep resolving from what is already in ${sidecarsNodeModules(home)} (a failed install can leave it incomplete), and from the npx cache for any package not there.` : "Servers keep resolving from the npx cache.";
|
|
2599
3224
|
const couldNotPrepare = (err) => {
|
|
2600
3225
|
const msg = err instanceof Error ? err.message : String(err);
|
|
2601
|
-
print(`Could not prepare ${root}: ${msg}.
|
|
3226
|
+
print(`Could not prepare ${root}: ${msg}. ${afterFailure()}`);
|
|
2602
3227
|
if (opts.json) write(doc({ error: `manifest write failed: ${msg}`, conflicts, skipped }));
|
|
2603
3228
|
return done(1);
|
|
2604
3229
|
};
|
|
@@ -2718,7 +3343,7 @@ async function runSidecarsInstall(opts = {}) {
|
|
|
2718
3343
|
const runNpm = opts.runNpm ?? ((args, cwd) => defaultRunNpm(args, cwd, { platform: opts.platform }));
|
|
2719
3344
|
const code = await runNpm(["install", "--no-audit", "--no-fund"], root);
|
|
2720
3345
|
if (code !== 0) {
|
|
2721
|
-
print(`npm install failed (exit ${code}).
|
|
3346
|
+
print(`npm install failed (exit ${code}). ${afterFailure()}`);
|
|
2722
3347
|
if (opts.json) write(doc({ error: `npm exited ${code}`, conflicts, skipped }));
|
|
2723
3348
|
return done(1);
|
|
2724
3349
|
}
|
|
@@ -2816,9 +3441,9 @@ var ENV_WORDS = `(?:(?:env|environment)${GAP})?(?:(?:variable|var)${GAP})?`;
|
|
|
2816
3441
|
var LEADING_ENV_WORDS = `(?:(?:env|environment)${SEP})?(?:(?:variables?|vars?)${SEP})?`;
|
|
2817
3442
|
var LEADING_CREDENTIAL_NOUN = `(?:api(?:${GAP}|-)?keys?|tokens?|credentials?|secrets?)${SEP}`;
|
|
2818
3443
|
var MISSING_PATTERNS = [
|
|
2819
|
-
new RegExp(`\\bmissing${SEP}(?:required${
|
|
3444
|
+
new RegExp(`\\bmissing${SEP}(?:required${SEP})?${LEADING_ENV_WORDS}${QUOTE}(${NAME})\\b`, "gi"),
|
|
2820
3445
|
new RegExp(
|
|
2821
|
-
`\\bmissing${SEP}(?:required${
|
|
3446
|
+
`\\bmissing${SEP}(?:required${SEP})?${LEADING_ENV_WORDS}${LEADING_CREDENTIAL_NOUN}${QUOTE}(${NAME})\\b`,
|
|
2822
3447
|
"gi"
|
|
2823
3448
|
),
|
|
2824
3449
|
new RegExp(
|
|
@@ -2940,6 +3565,12 @@ import { join as join6 } from "path";
|
|
|
2940
3565
|
var SECRETS_AUDIT_FILENAME = "secrets-audit.log";
|
|
2941
3566
|
var AUDIT_TAIL_CAP = 5e3;
|
|
2942
3567
|
var AUDIT_TRIM_TO = AUDIT_TAIL_CAP - 500;
|
|
3568
|
+
var VAULT_AUDIT_EVENT_KINDS = [
|
|
3569
|
+
"recovery-issued",
|
|
3570
|
+
"recovery-used",
|
|
3571
|
+
"recovery-removed",
|
|
3572
|
+
"vault-rekeyed"
|
|
3573
|
+
];
|
|
2943
3574
|
function auditLogPath(home = homedir5()) {
|
|
2944
3575
|
return join6(home, CONFIG_DIRNAME, SECRETS_AUDIT_FILENAME);
|
|
2945
3576
|
}
|
|
@@ -3006,7 +3637,7 @@ async function readAuditLog(filter = {}, home = homedir5()) {
|
|
|
3006
3637
|
function isAuditEvent(v) {
|
|
3007
3638
|
if (!v || typeof v !== "object") return false;
|
|
3008
3639
|
const e = v;
|
|
3009
|
-
return typeof e.ts === "string" && typeof e.server === "string" && typeof e.secret === "string" && (e.event === "injected" || e.event === "missing");
|
|
3640
|
+
return typeof e.ts === "string" && typeof e.server === "string" && typeof e.secret === "string" && (e.event === "injected" || e.event === "missing" || VAULT_AUDIT_EVENT_KINDS.includes(e.event));
|
|
3010
3641
|
}
|
|
3011
3642
|
|
|
3012
3643
|
// src/timeouts.ts
|
|
@@ -3167,7 +3798,7 @@ function fenceUpstreamInstructions(namespace, sanitized) {
|
|
|
3167
3798
|
|
|
3168
3799
|
// src/uv-bootstrap.ts
|
|
3169
3800
|
import { spawn as spawn2 } from "child_process";
|
|
3170
|
-
import { createHash as
|
|
3801
|
+
import { createHash as createHash4 } from "crypto";
|
|
3171
3802
|
import { createWriteStream } from "fs";
|
|
3172
3803
|
import fs from "fs/promises";
|
|
3173
3804
|
import path from "path";
|
|
@@ -3175,15 +3806,27 @@ import { pipeline } from "stream/promises";
|
|
|
3175
3806
|
import { request } from "undici";
|
|
3176
3807
|
var UV_VERSION = "0.12.10";
|
|
3177
3808
|
var RELEASE_BASE = `https://github.com/astral-sh/uv/releases/download/${UV_VERSION}`;
|
|
3809
|
+
var muslLibcMemo;
|
|
3178
3810
|
function isMuslLibc() {
|
|
3179
3811
|
if (process.platform !== "linux") return false;
|
|
3812
|
+
if (muslLibcMemo !== void 0) return muslLibcMemo;
|
|
3813
|
+
muslLibcMemo = readMuslLibc();
|
|
3814
|
+
return muslLibcMemo;
|
|
3815
|
+
}
|
|
3816
|
+
function readMuslLibc() {
|
|
3817
|
+
const report = process.report;
|
|
3818
|
+
const hadExclude = report?.excludeNetwork;
|
|
3819
|
+
const hasFlag = report !== void 0 && typeof hadExclude === "boolean";
|
|
3180
3820
|
try {
|
|
3181
|
-
|
|
3182
|
-
const
|
|
3183
|
-
const
|
|
3821
|
+
if (hasFlag) report.excludeNetwork = true;
|
|
3822
|
+
const raw = report?.getReport();
|
|
3823
|
+
const parsed = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
3824
|
+
const header = parsed?.header;
|
|
3184
3825
|
return typeof header?.glibcVersionRuntime !== "string";
|
|
3185
3826
|
} catch {
|
|
3186
3827
|
return false;
|
|
3828
|
+
} finally {
|
|
3829
|
+
if (hasFlag) report.excludeNetwork = hadExclude;
|
|
3187
3830
|
}
|
|
3188
3831
|
}
|
|
3189
3832
|
function uvTarget(platform = process.platform, arch = process.arch, musl = platform === "linux" && isMuslLibc()) {
|
|
@@ -3245,14 +3888,7 @@ async function probePath(cmd) {
|
|
|
3245
3888
|
return;
|
|
3246
3889
|
}
|
|
3247
3890
|
const timer = setTimeout(() => {
|
|
3248
|
-
|
|
3249
|
-
child.kill("SIGKILL");
|
|
3250
|
-
} catch {
|
|
3251
|
-
}
|
|
3252
|
-
try {
|
|
3253
|
-
child.unref();
|
|
3254
|
-
} catch {
|
|
3255
|
-
}
|
|
3891
|
+
killAndDetach(child);
|
|
3256
3892
|
settle("unknown");
|
|
3257
3893
|
}, PATH_PROBE_TIMEOUT_MS);
|
|
3258
3894
|
timer.unref?.();
|
|
@@ -3386,15 +4022,7 @@ function runCommand(cmd, args, timeoutMs = UV_EXTRACT_TIMEOUT_MS) {
|
|
|
3386
4022
|
);
|
|
3387
4023
|
timer = setTimeout(() => {
|
|
3388
4024
|
settle(() => {
|
|
3389
|
-
|
|
3390
|
-
child.kill("SIGKILL");
|
|
3391
|
-
} catch {
|
|
3392
|
-
}
|
|
3393
|
-
try {
|
|
3394
|
-
child.stderr?.destroy();
|
|
3395
|
-
child.unref();
|
|
3396
|
-
} catch {
|
|
3397
|
-
}
|
|
4025
|
+
killAndDetach(child);
|
|
3398
4026
|
reject(new Error(`${cmd} did not finish within ${timeoutMs}ms`));
|
|
3399
4027
|
});
|
|
3400
4028
|
}, timeoutMs);
|
|
@@ -3456,7 +4084,7 @@ async function resolveUv() {
|
|
|
3456
4084
|
const shaBuf = await fetchWithRedirects(shaUrl, void 0, totalDeadline);
|
|
3457
4085
|
const archiveBuf = await fetchWithRedirects(archiveUrl, void 0, totalDeadline);
|
|
3458
4086
|
const expected = shaBuf.toString("utf8").trim().split(/\s+/)[0];
|
|
3459
|
-
const actual =
|
|
4087
|
+
const actual = createHash4("sha256").update(archiveBuf).digest("hex");
|
|
3460
4088
|
if (!expected || expected.toLowerCase() !== actual.toLowerCase()) {
|
|
3461
4089
|
throw new Error(`uv archive checksum mismatch (expected ${expected}, got ${actual})`);
|
|
3462
4090
|
}
|
|
@@ -3512,16 +4140,18 @@ async function resolveUvSpawn(command, args) {
|
|
|
3512
4140
|
|
|
3513
4141
|
// src/upstream.ts
|
|
3514
4142
|
var VaultPassphraseRequiredError = class extends Error {
|
|
3515
|
-
constructor(message, namespace, refKeys, reason = "missing") {
|
|
4143
|
+
constructor(message, namespace, refKeys, reason = "missing", subject = "server env") {
|
|
3516
4144
|
super(message);
|
|
3517
4145
|
this.namespace = namespace;
|
|
3518
4146
|
this.refKeys = refKeys;
|
|
3519
4147
|
this.reason = reason;
|
|
4148
|
+
this.subject = subject;
|
|
3520
4149
|
this.name = "VaultPassphraseRequiredError";
|
|
3521
4150
|
}
|
|
3522
4151
|
namespace;
|
|
3523
4152
|
refKeys;
|
|
3524
4153
|
reason;
|
|
4154
|
+
subject;
|
|
3525
4155
|
};
|
|
3526
4156
|
var InvalidResolvedValueError = class extends Error {
|
|
3527
4157
|
constructor(key) {
|
|
@@ -3539,18 +4169,18 @@ function clearSessionVaultPassphrase() {
|
|
|
3539
4169
|
sessionVaultPassphrase = null;
|
|
3540
4170
|
}
|
|
3541
4171
|
async function verifyVaultPassphrase(passphrase) {
|
|
3542
|
-
if (passphrase.length === 0) return
|
|
4172
|
+
if (passphrase.length === 0) return "wrong";
|
|
3543
4173
|
let vault;
|
|
3544
4174
|
try {
|
|
3545
4175
|
vault = await loadVault(vaultPath());
|
|
3546
4176
|
} catch {
|
|
3547
|
-
return
|
|
4177
|
+
return "unverifiable";
|
|
3548
4178
|
}
|
|
3549
|
-
if (!vault) return
|
|
4179
|
+
if (!vault || !vaultVerifiesPassphrases(vault)) return "unverifiable";
|
|
3550
4180
|
try {
|
|
3551
|
-
return await checkVaultPassphrase(vault, passphrase) !== "wrong";
|
|
4181
|
+
return await checkVaultPassphrase(vault, passphrase) !== "wrong" ? "verified" : "wrong";
|
|
3552
4182
|
} catch {
|
|
3553
|
-
return
|
|
4183
|
+
return "wrong";
|
|
3554
4184
|
}
|
|
3555
4185
|
}
|
|
3556
4186
|
function vaultPassphrase() {
|
|
@@ -3565,19 +4195,6 @@ async function resolveServerEnv(env, namespace, subject = "server env", validate
|
|
|
3565
4195
|
}
|
|
3566
4196
|
const refKeys = Object.entries(env).filter(([, v]) => typeof v === "string" && v.includes("${secret:")).map(([k]) => k);
|
|
3567
4197
|
const lead = subject.charAt(0).toUpperCase() + subject.slice(1);
|
|
3568
|
-
const passphrase = vaultPassphrase();
|
|
3569
|
-
if (typeof passphrase !== "string" || passphrase.length === 0) {
|
|
3570
|
-
log("warn", `${lead} carries \${secret:...} refs but YAW_MCP_VAULT_PASSPHRASE is not set`, {
|
|
3571
|
-
namespace,
|
|
3572
|
-
keys: refKeys
|
|
3573
|
-
});
|
|
3574
|
-
throw new VaultPassphraseRequiredError(
|
|
3575
|
-
`vault locked: ${subject} references \${secret:...} but YAW_MCP_VAULT_PASSPHRASE is not set`,
|
|
3576
|
-
namespace,
|
|
3577
|
-
refKeys,
|
|
3578
|
-
"missing"
|
|
3579
|
-
);
|
|
3580
|
-
}
|
|
3581
4198
|
let vault;
|
|
3582
4199
|
try {
|
|
3583
4200
|
vault = await loadVault(vaultPath());
|
|
@@ -3589,21 +4206,15 @@ async function resolveServerEnv(env, namespace, subject = "server env", validate
|
|
|
3589
4206
|
if (!vault) {
|
|
3590
4207
|
throw new Error(`vault locked: ${subject} references \${secret:...} but no vault exists yet`);
|
|
3591
4208
|
}
|
|
3592
|
-
|
|
4209
|
+
const noEntries = Object.keys(vault.entries).length === 0;
|
|
4210
|
+
const key = noEntries ? Buffer.alloc(0) : await unlockForResolve(vault, namespace, refKeys, subject, lead);
|
|
4211
|
+
let decrypted;
|
|
3593
4212
|
try {
|
|
3594
|
-
|
|
3595
|
-
}
|
|
3596
|
-
|
|
3597
|
-
if (msg === VAULT_CHECK_CORRUPT_ERROR) throw err;
|
|
3598
|
-
log("warn", "Vault passphrase did not unlock the vault", { namespace, keys: refKeys });
|
|
3599
|
-
throw new VaultPassphraseRequiredError(
|
|
3600
|
-
`vault locked: the passphrase available to yaw-mcp does not unlock the vault (${msg})`,
|
|
3601
|
-
namespace,
|
|
3602
|
-
refKeys,
|
|
3603
|
-
"invalid"
|
|
3604
|
-
);
|
|
4213
|
+
decrypted = resolveSecretRefs(env, vault, key);
|
|
4214
|
+
} finally {
|
|
4215
|
+
key.fill(0);
|
|
3605
4216
|
}
|
|
3606
|
-
const { resolved, missing, malformed, values } =
|
|
4217
|
+
const { resolved, missing, malformed, values } = decrypted;
|
|
3607
4218
|
onSecretValues?.(values);
|
|
3608
4219
|
const invalid = missing.length === 0 && malformed.length === 0 ? validate?.(resolved) : void 0;
|
|
3609
4220
|
if (!invalid) {
|
|
@@ -3619,12 +4230,48 @@ async function resolveServerEnv(env, namespace, subject = "server env", validate
|
|
|
3619
4230
|
if (invalid) throw new InvalidResolvedValueError(invalid);
|
|
3620
4231
|
if (missing.length > 0 || malformed.length > 0) {
|
|
3621
4232
|
const problems = [];
|
|
3622
|
-
if (missing.length > 0)
|
|
4233
|
+
if (missing.length > 0) {
|
|
4234
|
+
const fix = noEntries ? ` (the vault holds no secrets yet; store each with \`yaw-mcp secrets set <name>\`)` : "";
|
|
4235
|
+
problems.push(`missing or undecryptable secret refs: ${missing.join(", ")}${fix}`);
|
|
4236
|
+
}
|
|
3623
4237
|
if (malformed.length > 0) problems.push(`malformed secret refs: ${malformed.map((m) => m.display).join(", ")}`);
|
|
3624
4238
|
throw new Error(`vault: ${problems.join("; ")}`);
|
|
3625
4239
|
}
|
|
3626
4240
|
return resolved;
|
|
3627
4241
|
}
|
|
4242
|
+
async function unlockForResolve(vault, namespace, refKeys, subject, lead) {
|
|
4243
|
+
const passphrase = vaultPassphrase();
|
|
4244
|
+
if (typeof passphrase !== "string" || passphrase.length === 0) {
|
|
4245
|
+
log("warn", `${lead} carries \${secret:...} refs but YAW_MCP_VAULT_PASSPHRASE is not set`, {
|
|
4246
|
+
namespace,
|
|
4247
|
+
keys: refKeys
|
|
4248
|
+
});
|
|
4249
|
+
throw new VaultPassphraseRequiredError(
|
|
4250
|
+
`vault locked: ${subject} references \${secret:...} but YAW_MCP_VAULT_PASSPHRASE is not set`,
|
|
4251
|
+
namespace,
|
|
4252
|
+
refKeys,
|
|
4253
|
+
"missing",
|
|
4254
|
+
subject
|
|
4255
|
+
);
|
|
4256
|
+
}
|
|
4257
|
+
let key;
|
|
4258
|
+
try {
|
|
4259
|
+
key = await unlock(vault, passphrase);
|
|
4260
|
+
} catch (err) {
|
|
4261
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4262
|
+
if (msg === VAULT_CHECK_CORRUPT_ERROR) throw new Error(`${msg}. ${vaultCheckCorruptHint(vaultPath())}`);
|
|
4263
|
+
if (msg === VAULT_SLOT_DAMAGED_ERROR) throw new Error(msg);
|
|
4264
|
+
log("warn", "Vault passphrase did not unlock the vault", { namespace, keys: refKeys });
|
|
4265
|
+
throw new VaultPassphraseRequiredError(
|
|
4266
|
+
`vault locked: the passphrase available to yaw-mcp does not unlock the vault (${msg})`,
|
|
4267
|
+
namespace,
|
|
4268
|
+
refKeys,
|
|
4269
|
+
"invalid",
|
|
4270
|
+
subject
|
|
4271
|
+
);
|
|
4272
|
+
}
|
|
4273
|
+
return key;
|
|
4274
|
+
}
|
|
3628
4275
|
async function recordResolveAudit(namespace, env, missing, malformed) {
|
|
3629
4276
|
if (missing.length > 0 || malformed.length > 0) {
|
|
3630
4277
|
for (const name of /* @__PURE__ */ new Set([...missing, ...malformed.map((m) => m.auditName)])) {
|
|
@@ -3703,7 +4350,8 @@ function shellActivationMessage(err) {
|
|
|
3703
4350
|
if (!(err instanceof ActivationError) || !err.configPointer) {
|
|
3704
4351
|
return err instanceof Error ? err.message : String(err);
|
|
3705
4352
|
}
|
|
3706
|
-
|
|
4353
|
+
const { summary, fix } = err.configPointer;
|
|
4354
|
+
return fix === null ? `${summary} -> then run the command again.` : `${summary} -> ${fix}, then run the command again.`;
|
|
3707
4355
|
}
|
|
3708
4356
|
function isUnresolvedSecretRef(value) {
|
|
3709
4357
|
return value.startsWith("${secret:") && value.endsWith("}");
|
|
@@ -3806,7 +4454,7 @@ function redactSecretsInOutput(text, env) {
|
|
|
3806
4454
|
if (v.length < SECRET_MATCH_MIN_LENGTH) continue;
|
|
3807
4455
|
if (isUnresolvedSecretRef(v)) continue;
|
|
3808
4456
|
const escaped = v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3809
|
-
out = out.replace(new RegExp(escaped, "g"), `***${k}***`);
|
|
4457
|
+
out = out.replace(new RegExp(escaped, "g"), () => `***${k}***`);
|
|
3810
4458
|
}
|
|
3811
4459
|
out = out.replace(/\$\{secret:([a-zA-Z0-9_.-]+)\}/g, "${secret:***}");
|
|
3812
4460
|
return out;
|
|
@@ -3821,6 +4469,15 @@ function withConfigPointer(summary, config, category, stderrTail, cause) {
|
|
|
3821
4469
|
{ summary, fix }
|
|
3822
4470
|
);
|
|
3823
4471
|
}
|
|
4472
|
+
function withoutConfigEdit(summary, category, stderrTail, cause) {
|
|
4473
|
+
return new ActivationError(
|
|
4474
|
+
`${summary} -> then activate it again -- no client restart is needed.`,
|
|
4475
|
+
category,
|
|
4476
|
+
stderrTail,
|
|
4477
|
+
cause,
|
|
4478
|
+
{ summary, fix: null }
|
|
4479
|
+
);
|
|
4480
|
+
}
|
|
3824
4481
|
var GIT_FAILED_TAIL_CAP = 600;
|
|
3825
4482
|
function quotedFailedTail(tail) {
|
|
3826
4483
|
const t = tail.trim();
|
|
@@ -3861,12 +4518,12 @@ async function gitBuildMissing(config, home, consented) {
|
|
|
3861
4518
|
}
|
|
3862
4519
|
async function gitRepoConsented(config) {
|
|
3863
4520
|
if (!config.git?.commit || gitEntryBuilt(config.namespace, config.git)) return void 0;
|
|
3864
|
-
const { hasRepoConsent: hasRepoConsent2 } = await import("./git-source-
|
|
4521
|
+
const { hasRepoConsent: hasRepoConsent2 } = await import("./git-source-HAQNOQRR.js");
|
|
3865
4522
|
return hasRepoConsent2(config.git.url, homedir6());
|
|
3866
4523
|
}
|
|
3867
4524
|
async function recordActivatedGitPin(namespace, commit) {
|
|
3868
4525
|
try {
|
|
3869
|
-
const { recordLoadedGitPin: recordLoadedGitPin2 } = await import("./git-source-
|
|
4526
|
+
const { recordLoadedGitPin: recordLoadedGitPin2 } = await import("./git-source-HAQNOQRR.js");
|
|
3870
4527
|
await recordLoadedGitPin2(namespace, commit, { home: homedir6(), cwd: process.cwd() });
|
|
3871
4528
|
} catch (e) {
|
|
3872
4529
|
log("debug", "Could not record the git build an activation uses", { namespace, error: e.message });
|
|
@@ -3991,7 +4648,11 @@ async function connectToUpstream(config, onDisconnect, onListChanged, bridge, pr
|
|
|
3991
4648
|
} else {
|
|
3992
4649
|
log("warn", "node respawn also failed; not pinning this server to node (oam was likely not the cause)", {
|
|
3993
4650
|
namespace: config.namespace,
|
|
3994
|
-
|
|
4651
|
+
// Two attempts, two fields: the category of the oam-hosted boot
|
|
4652
|
+
// that started this, and of the node respawn whose message is
|
|
4653
|
+
// logged beside it (null when that one was not an ActivationError).
|
|
4654
|
+
oamCategory: err.category,
|
|
4655
|
+
nodeCategory: nodeErr instanceof ActivationError ? nodeErr.category : null,
|
|
3995
4656
|
error: nodeErr instanceof Error ? nodeErr.message : String(nodeErr)
|
|
3996
4657
|
});
|
|
3997
4658
|
}
|
|
@@ -4026,7 +4687,9 @@ async function connectToUpstream(config, onDisconnect, onListChanged, bridge, pr
|
|
|
4026
4687
|
"npx respawn also failed; not pinning this server to npx (the managed sidecar was likely not the cause)",
|
|
4027
4688
|
{
|
|
4028
4689
|
namespace: config.namespace,
|
|
4029
|
-
|
|
4690
|
+
// Same split as the oam->node line above.
|
|
4691
|
+
managedCategory: err.category,
|
|
4692
|
+
npxCategory: npxErr instanceof ActivationError ? npxErr.category : null,
|
|
4030
4693
|
error: npxErr instanceof Error ? npxErr.message : String(npxErr)
|
|
4031
4694
|
}
|
|
4032
4695
|
);
|
|
@@ -4037,6 +4700,30 @@ async function connectToUpstream(config, onDisconnect, onListChanged, bridge, pr
|
|
|
4037
4700
|
throw err;
|
|
4038
4701
|
}
|
|
4039
4702
|
}
|
|
4703
|
+
function mergeChildEnv(parentEnv, serverEnv, platform = process.platform) {
|
|
4704
|
+
if (platform !== "win32") return { ...parentEnv, ...serverEnv };
|
|
4705
|
+
const out = { ...parentEnv };
|
|
4706
|
+
const spellings = /* @__PURE__ */ new Map();
|
|
4707
|
+
for (const key of Object.keys(out)) {
|
|
4708
|
+
const upper = key.toUpperCase();
|
|
4709
|
+
const list = spellings.get(upper);
|
|
4710
|
+
if (list) list.push(key);
|
|
4711
|
+
else spellings.set(upper, [key]);
|
|
4712
|
+
}
|
|
4713
|
+
for (const [key, value] of Object.entries(serverEnv)) {
|
|
4714
|
+
const upper = key.toUpperCase();
|
|
4715
|
+
const existing = spellings.get(upper);
|
|
4716
|
+
if (existing === void 0) {
|
|
4717
|
+
out[key] = value;
|
|
4718
|
+
spellings.set(upper, [key]);
|
|
4719
|
+
continue;
|
|
4720
|
+
}
|
|
4721
|
+
for (const spelling of existing) delete out[spelling];
|
|
4722
|
+
out[upper] = value;
|
|
4723
|
+
spellings.set(upper, [upper]);
|
|
4724
|
+
}
|
|
4725
|
+
return out;
|
|
4726
|
+
}
|
|
4040
4727
|
async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge, attempt, suppressRewrites, progress) {
|
|
4041
4728
|
const downstreamCaps = bridge?.getClientCapabilities();
|
|
4042
4729
|
const capabilities = {};
|
|
@@ -4044,7 +4731,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4044
4731
|
if (downstreamCaps?.sampling) capabilities.sampling = downstreamCaps.sampling;
|
|
4045
4732
|
if (downstreamCaps?.roots) capabilities.roots = {};
|
|
4046
4733
|
const client = new Client(
|
|
4047
|
-
{ name: "yaw-mcp", version: true ? "1.1.
|
|
4734
|
+
{ name: "yaw-mcp", version: true ? "1.1.15" : "dev" },
|
|
4048
4735
|
{ capabilities }
|
|
4049
4736
|
);
|
|
4050
4737
|
if (bridge && capabilities.elicitation) {
|
|
@@ -4071,10 +4758,14 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4071
4758
|
let spawnedCommand = config.command;
|
|
4072
4759
|
if (config.type === "local") {
|
|
4073
4760
|
const notBuilt = await gitBuildMissing(config, void 0, await gitRepoConsented(config));
|
|
4074
|
-
if (notBuilt !== null) throw
|
|
4761
|
+
if (notBuilt !== null) throw withoutConfigEdit(notBuilt, "install_failure");
|
|
4075
4762
|
if (config.git?.commit) await recordActivatedGitPin(config.namespace, config.git.commit);
|
|
4076
4763
|
if (!config.command) {
|
|
4077
|
-
throw
|
|
4764
|
+
throw withConfigPointer(
|
|
4765
|
+
`Server "${config.namespace}" has no "command": command is required for local servers`,
|
|
4766
|
+
config,
|
|
4767
|
+
"unknown"
|
|
4768
|
+
);
|
|
4078
4769
|
}
|
|
4079
4770
|
const parentEnv = stripInternalSecretsFromEnv(process.env);
|
|
4080
4771
|
if (config.headers && Object.keys(config.headers).length > 0) {
|
|
@@ -4096,12 +4787,22 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4096
4787
|
resolvedServerEnv = localRedactionMap(config.env ?? {}, serverEnv, secretValues);
|
|
4097
4788
|
let resolved;
|
|
4098
4789
|
try {
|
|
4099
|
-
|
|
4790
|
+
const args = config.args ?? [];
|
|
4791
|
+
resolved = await withHeartbeat(
|
|
4792
|
+
progress,
|
|
4793
|
+
(elapsed) => `"${config.namespace}" is still resolving its launch command -- ${elapsed}s so far (a first uv/uvx run downloads uv)`,
|
|
4794
|
+
() => resolveUvSpawn(config.command, args)
|
|
4795
|
+
);
|
|
4100
4796
|
const configured = config.runtime ?? await defaultRuntime();
|
|
4101
4797
|
const optedIn = configured !== null;
|
|
4102
4798
|
const effectiveRuntime = configured ?? "oam";
|
|
4103
4799
|
if (effectiveRuntime === "oam" && !suppressRewrites && !isPinnedToNode(config)) {
|
|
4104
|
-
const
|
|
4800
|
+
const beforeOam = resolved;
|
|
4801
|
+
const rewritten = await withHeartbeat(
|
|
4802
|
+
progress,
|
|
4803
|
+
(elapsed) => `"${config.namespace}" is still waiting on the oam runtime probe -- ${elapsed}s so far`,
|
|
4804
|
+
() => resolveOamSpawn(beforeOam.command, beforeOam.args, optedIn)
|
|
4805
|
+
);
|
|
4105
4806
|
if (rewritten.command !== resolved.command) {
|
|
4106
4807
|
attempt.oamRewriteApplied = true;
|
|
4107
4808
|
attempt.oamVersion = (await probeOam()).version;
|
|
@@ -4130,7 +4831,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4130
4831
|
const stdioTransport = new StdioClientTransport({
|
|
4131
4832
|
command: resolved.command,
|
|
4132
4833
|
args: resolved.args,
|
|
4133
|
-
env:
|
|
4834
|
+
env: mergeChildEnv(parentEnv, serverEnv),
|
|
4134
4835
|
stderr: "pipe",
|
|
4135
4836
|
...config.cwd !== void 0 ? { cwd: config.cwd } : {}
|
|
4136
4837
|
});
|
|
@@ -4141,7 +4842,11 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
4141
4842
|
transport = stdioTransport;
|
|
4142
4843
|
} else {
|
|
4143
4844
|
if (!config.url) {
|
|
4144
|
-
throw
|
|
4845
|
+
throw withConfigPointer(
|
|
4846
|
+
`Server "${config.namespace}" has no "url": url is required for remote servers`,
|
|
4847
|
+
config,
|
|
4848
|
+
"unknown"
|
|
4849
|
+
);
|
|
4145
4850
|
}
|
|
4146
4851
|
if (config.env && Object.keys(config.env).length > 0) {
|
|
4147
4852
|
log(
|
|
@@ -4616,10 +5321,10 @@ async function fetchToolsFromUpstream(client, namespace, opts = {}) {
|
|
|
4616
5321
|
tools: all.filter((tool) => tool.execution?.taskSupport === "required").map((tool) => tool.name)
|
|
4617
5322
|
});
|
|
4618
5323
|
}
|
|
4619
|
-
if (
|
|
5324
|
+
if (all.length > MAX_TOOLS_PER_SERVER) {
|
|
4620
5325
|
log("warn", "Upstream returned more tools than cap; truncating", {
|
|
4621
5326
|
namespace,
|
|
4622
|
-
reported:
|
|
5327
|
+
reported: all.length,
|
|
4623
5328
|
cap: MAX_TOOLS_PER_SERVER
|
|
4624
5329
|
});
|
|
4625
5330
|
}
|
|
@@ -4761,6 +5466,11 @@ function scrubRepoUrlUserinfo(url) {
|
|
|
4761
5466
|
parsed.password = "";
|
|
4762
5467
|
return parsed.href;
|
|
4763
5468
|
}
|
|
5469
|
+
function scrubStoredGitUrl(url) {
|
|
5470
|
+
const userinfo = /^[a-z][a-z0-9+.-]*:\/\/([^/?#\\]*)@/i.exec(url)?.[1];
|
|
5471
|
+
if (userinfo !== void 0 && isBareUsername(userinfo)) return url;
|
|
5472
|
+
return scrubRepoUrlUserinfo(url);
|
|
5473
|
+
}
|
|
4764
5474
|
function redactGitOutput(text, secrets = {}) {
|
|
4765
5475
|
return scrubUrlUserinfo(redactSecretsInOutput(text, secrets));
|
|
4766
5476
|
}
|
|
@@ -5338,7 +6048,7 @@ function readGitManifest(repoDir, subdirFlag) {
|
|
|
5338
6048
|
if (subdir === void 0 || subdir === "") return { manifest: root, warnings };
|
|
5339
6049
|
const label = `${subdir.replace(/\\/g, "/").replace(/\/+$/, "")}/${GIT_MANIFEST_FILENAME}`;
|
|
5340
6050
|
const sub = readManifestFile(join7(repoDir, ...subdir.split(/[\\/]/), GIT_MANIFEST_FILENAME), label, warnings, false);
|
|
5341
|
-
return { manifest: { ...root, ...sub
|
|
6051
|
+
return { manifest: { ...root, ...sub }, warnings };
|
|
5342
6052
|
}
|
|
5343
6053
|
var GIT_CONSENT_FILENAME = "consent.json";
|
|
5344
6054
|
function gitConsentPath(home) {
|
|
@@ -5398,7 +6108,20 @@ async function readVaultSecret(name, home) {
|
|
|
5398
6108
|
`the vault is locked, so the git token in secret "${name}" cannot be read. Set YAW_MCP_VAULT_PASSPHRASE for this command.`
|
|
5399
6109
|
);
|
|
5400
6110
|
}
|
|
5401
|
-
|
|
6111
|
+
let key;
|
|
6112
|
+
try {
|
|
6113
|
+
key = await unlock(vault, passphrase);
|
|
6114
|
+
} catch (err) {
|
|
6115
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6116
|
+
if (msg === VAULT_CHECK_CORRUPT_ERROR) throw new Error(`${msg}. ${vaultCheckCorruptHint(vaultPath(home))}`);
|
|
6117
|
+
throw err;
|
|
6118
|
+
}
|
|
6119
|
+
let value;
|
|
6120
|
+
try {
|
|
6121
|
+
value = getSecret(vault, key, name);
|
|
6122
|
+
} finally {
|
|
6123
|
+
key.fill(0);
|
|
6124
|
+
}
|
|
5402
6125
|
if (!value) throw new Error(`secret "${name}" is empty or unreadable.`);
|
|
5403
6126
|
return value;
|
|
5404
6127
|
}
|
|
@@ -5467,7 +6190,7 @@ function insideRelative(base, abs) {
|
|
|
5467
6190
|
}
|
|
5468
6191
|
function isRegularFile(path2) {
|
|
5469
6192
|
try {
|
|
5470
|
-
return
|
|
6193
|
+
return statSync3(path2).isFile();
|
|
5471
6194
|
} catch {
|
|
5472
6195
|
return false;
|
|
5473
6196
|
}
|
|
@@ -5614,7 +6337,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5614
6337
|
let namespace = req.namespace;
|
|
5615
6338
|
let commit = req.commit;
|
|
5616
6339
|
const directDir = req.namespace && fullKnown && readBuildMarker(gitBuildDir(req.namespace, req.commit, ctx.home), req.commit) === null ? gitBuildDir(req.namespace, req.commit, ctx.home) : null;
|
|
5617
|
-
let work = directDir ?? join7(root, `.tmp-${
|
|
6340
|
+
let work = directDir ?? join7(root, `.tmp-${randomBytes4(6).toString("hex")}`);
|
|
5618
6341
|
let step = "clone";
|
|
5619
6342
|
const fail = async (exitCode, message, tail = "", suffix = "", record = true) => {
|
|
5620
6343
|
if (tryRemoveTree(work, warn) && dirname4(work) !== root) {
|
|
@@ -5711,6 +6434,7 @@ async function buildLocked(req, ctx, root) {
|
|
|
5711
6434
|
const count = Number((await runGit(["rev-list", "--count", `${req.ancestor}..${commit}`], gitCtx, work)).stdout);
|
|
5712
6435
|
if (Number.isInteger(count)) ahead = count;
|
|
5713
6436
|
}
|
|
6437
|
+
step = "layout";
|
|
5714
6438
|
const { manifest, warnings: manifestWarnings } = readGitManifest(work, reqSubdir);
|
|
5715
6439
|
for (const w of manifestWarnings) warn(w);
|
|
5716
6440
|
namespace = namespace ?? manifest.namespace;
|
|
@@ -6101,7 +6825,7 @@ async function recordLoadedGitPin(namespace, commit, opts) {
|
|
|
6101
6825
|
}
|
|
6102
6826
|
function parentDirExists(file) {
|
|
6103
6827
|
try {
|
|
6104
|
-
return
|
|
6828
|
+
return statSync3(dirname4(file)).isDirectory();
|
|
6105
6829
|
} catch {
|
|
6106
6830
|
return false;
|
|
6107
6831
|
}
|
|
@@ -6207,15 +6931,17 @@ async function collectLocked(namespace, keep, home, opts) {
|
|
|
6207
6931
|
const removed = [];
|
|
6208
6932
|
const failed = [];
|
|
6209
6933
|
const errors = [];
|
|
6210
|
-
const
|
|
6934
|
+
const isBuiltMarker = (n) => n.endsWith(GIT_BUILT_SUFFIX);
|
|
6935
|
+
const names = readdirSync(dir).sort((a, b) => Number(isBuiltMarker(b)) - Number(isBuiltMarker(a)));
|
|
6211
6936
|
for (const n of names) {
|
|
6212
|
-
const
|
|
6213
|
-
|
|
6937
|
+
const suffix = isBuiltMarker(n) ? GIT_BUILT_SUFFIX : n.endsWith(".failed") ? ".failed" : "";
|
|
6938
|
+
const sha12 = suffix ? n.slice(0, -suffix.length) : n;
|
|
6939
|
+
if (!/^[0-9a-f]{12}$/.test(sha12) || kept.has(sha12)) continue;
|
|
6214
6940
|
try {
|
|
6215
6941
|
removeTree(join7(dir, n));
|
|
6216
|
-
if (!
|
|
6942
|
+
if (!suffix) removed.push(sha12);
|
|
6217
6943
|
} catch (e) {
|
|
6218
|
-
if (!
|
|
6944
|
+
if (!suffix) failed.push(sha12);
|
|
6219
6945
|
errors.push(`${n}: ${asciiLines(e.message)}`);
|
|
6220
6946
|
}
|
|
6221
6947
|
}
|
|
@@ -6285,8 +7011,11 @@ async function gcGitBuilds(namespace, keep, home, opts = {}) {
|
|
|
6285
7011
|
const release = acquireSidecarsLock(root, GIT_LOCK_NAME);
|
|
6286
7012
|
if (release === null) return { locked: true, message: lockedMessage(root, "old builds were left in place.") };
|
|
6287
7013
|
try {
|
|
7014
|
+
if (!existsSync4(gitCheckoutDir(namespace, home))) return { removed: [], errors: [], unreadable: [], notes: [] };
|
|
6288
7015
|
const res = await collectLocked(namespace, keep, home, opts);
|
|
6289
7016
|
return { removed: res.removed, errors: res.errors, unreadable: res.unreadable, notes: res.notes };
|
|
7017
|
+
} catch (e) {
|
|
7018
|
+
return { removed: [], errors: [asciiLines(e.message)], unreadable: [], notes: [] };
|
|
6290
7019
|
} finally {
|
|
6291
7020
|
release();
|
|
6292
7021
|
}
|
|
@@ -6362,9 +7091,15 @@ async function writeGitState(home, entries) {
|
|
|
6362
7091
|
}
|
|
6363
7092
|
|
|
6364
7093
|
export {
|
|
7094
|
+
RECOVERY_CODE_FORMAT_ERROR,
|
|
7095
|
+
RECOVERY_CODE_TYPO_ERROR,
|
|
7096
|
+
recoveryCodeGroups,
|
|
7097
|
+
normalizeRecoveryGroup,
|
|
7098
|
+
parseRecoveryCode,
|
|
6365
7099
|
SECRETS_SCHEMA_VERSION,
|
|
6366
7100
|
VAULT_CHECK_CORRUPT_ERROR,
|
|
6367
7101
|
VAULT_WRONG_PASSPHRASE_ERROR,
|
|
7102
|
+
VAULT_NO_RECOVERY_ERROR,
|
|
6368
7103
|
vaultPath,
|
|
6369
7104
|
VaultEntryCorruptError,
|
|
6370
7105
|
loadVault,
|
|
@@ -6375,8 +7110,10 @@ export {
|
|
|
6375
7110
|
vaultVerifiesPassphrases,
|
|
6376
7111
|
checkVaultPassphrase,
|
|
6377
7112
|
vaultCheckCorruptHint,
|
|
6378
|
-
|
|
6379
|
-
|
|
7113
|
+
createVaultV3,
|
|
7114
|
+
rekeyVault,
|
|
7115
|
+
unlockWithRecoveryCode,
|
|
7116
|
+
recoveryStatus,
|
|
6380
7117
|
listKeys,
|
|
6381
7118
|
SECRET_NAME_RE,
|
|
6382
7119
|
setSecret,
|
|
@@ -6434,6 +7171,7 @@ export {
|
|
|
6434
7171
|
describeServerRuntime,
|
|
6435
7172
|
readBuildMarker,
|
|
6436
7173
|
gitEntryBuilt,
|
|
7174
|
+
appendAuditEvent,
|
|
6437
7175
|
readAuditLog,
|
|
6438
7176
|
MAX_TIMEOUT_MS,
|
|
6439
7177
|
resolveMaxResultBytes,
|
|
@@ -6444,6 +7182,7 @@ export {
|
|
|
6444
7182
|
uvLaunchKind,
|
|
6445
7183
|
printable,
|
|
6446
7184
|
asciiLines,
|
|
7185
|
+
withoutControls,
|
|
6447
7186
|
levenshtein,
|
|
6448
7187
|
closestNames,
|
|
6449
7188
|
matchCatalog,
|
|
@@ -6459,6 +7198,7 @@ export {
|
|
|
6459
7198
|
QUESTION_CANCELLED,
|
|
6460
7199
|
QUESTION_EOF,
|
|
6461
7200
|
questionOrEmpty,
|
|
7201
|
+
isInteractivePrompt,
|
|
6462
7202
|
askYesNo,
|
|
6463
7203
|
scriptConsentConfirm,
|
|
6464
7204
|
collectSidecarSpecs,
|
|
@@ -6477,6 +7217,7 @@ export {
|
|
|
6477
7217
|
normalizeRepoUrl,
|
|
6478
7218
|
scrubUrlUserinfo,
|
|
6479
7219
|
scrubRepoUrlUserinfo,
|
|
7220
|
+
scrubStoredGitUrl,
|
|
6480
7221
|
redactGitOutput,
|
|
6481
7222
|
GIT_MISSING_MESSAGE,
|
|
6482
7223
|
runGit,
|
|
@@ -6501,7 +7242,6 @@ export {
|
|
|
6501
7242
|
recordRepoConsent,
|
|
6502
7243
|
tokenUsername,
|
|
6503
7244
|
writeAskpassHelper,
|
|
6504
|
-
readVaultSecret,
|
|
6505
7245
|
GIT_LOCK_NAME,
|
|
6506
7246
|
removeTree,
|
|
6507
7247
|
tryRemoveTree,
|
|
@@ -6512,8 +7252,6 @@ export {
|
|
|
6512
7252
|
prepareGit,
|
|
6513
7253
|
buildPinnedGitEntries,
|
|
6514
7254
|
treeSizeBytes,
|
|
6515
|
-
GIT_REFS_FILENAME,
|
|
6516
|
-
GIT_PIN_LOCK_WAIT_MS,
|
|
6517
7255
|
gitRefsPath,
|
|
6518
7256
|
recordGitPin,
|
|
6519
7257
|
forgetGitPin,
|
|
@@ -6527,7 +7265,6 @@ export {
|
|
|
6527
7265
|
gcGitBuilds,
|
|
6528
7266
|
discardBuild,
|
|
6529
7267
|
discardUnpinnedBuild,
|
|
6530
|
-
GIT_STATE_FILENAME,
|
|
6531
7268
|
gitStatePath,
|
|
6532
7269
|
readGitState,
|
|
6533
7270
|
writeGitState,
|