@yawlabs/mcp 1.0.2 → 1.0.3
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 +18 -4
- package/README.md +1 -1
- package/dist/{auto-upgrade-A3WTRVGV.js → auto-upgrade-S4MOIA6T.js} +1 -1
- package/dist/{chunk-PAUBVL2N.js → chunk-7AUZKQTT.js} +200 -89
- package/dist/index.js +384 -447
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
MIN_OAM_VERSION,
|
|
13
13
|
acquireUpgradeLock,
|
|
14
14
|
applyClientConfigEdits,
|
|
15
|
+
atomicWriteFile,
|
|
15
16
|
blockedContainerFix,
|
|
16
17
|
buildLaunchEntry,
|
|
17
18
|
buildUpgradePlan,
|
|
@@ -40,6 +41,7 @@ import {
|
|
|
40
41
|
isProjectLocalEntry,
|
|
41
42
|
isRegistrySpec,
|
|
42
43
|
isUnderHome,
|
|
44
|
+
isWin32TransientFsError,
|
|
43
45
|
log,
|
|
44
46
|
maybeAutoUpgrade,
|
|
45
47
|
nodeLaunchKind,
|
|
@@ -57,6 +59,7 @@ import {
|
|
|
57
59
|
parseUpgradeArgs,
|
|
58
60
|
prepareClaudeCodeSettingsPatch,
|
|
59
61
|
probeOam,
|
|
62
|
+
quoteArgForDisplay,
|
|
60
63
|
readClientConfigFile,
|
|
61
64
|
readClientEnv,
|
|
62
65
|
readStrictJson,
|
|
@@ -88,7 +91,7 @@ import {
|
|
|
88
91
|
unparseableConfigFix,
|
|
89
92
|
userConfigDir,
|
|
90
93
|
yawModeOverlay
|
|
91
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-7AUZKQTT.js";
|
|
92
95
|
|
|
93
96
|
// src/audit-cmd.ts
|
|
94
97
|
import { homedir as homedir6 } from "os";
|
|
@@ -426,100 +429,10 @@ Target: ${url}
|
|
|
426
429
|
}
|
|
427
430
|
|
|
428
431
|
// src/grades-cache.ts
|
|
429
|
-
import { mkdir
|
|
432
|
+
import { mkdir, open, readFile as readFile2, rename, rm, stat } from "fs/promises";
|
|
430
433
|
import { homedir } from "os";
|
|
431
434
|
import { dirname as dirname2, join as join2 } from "path";
|
|
432
|
-
import { setTimeout as delay2 } from "timers/promises";
|
|
433
|
-
|
|
434
|
-
// src/atomic-write.ts
|
|
435
|
-
import { chmod, lstat, mkdir, realpath, rename, stat, unlink, writeFile } from "fs/promises";
|
|
436
|
-
import path from "path";
|
|
437
435
|
import { setTimeout as delay } from "timers/promises";
|
|
438
|
-
var RENAME_RETRY_CODES = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "EACCES"]);
|
|
439
|
-
var RENAME_RETRY_DELAYS_MS = [10, 50, 100];
|
|
440
|
-
async function renameWithRetry(tmp, target) {
|
|
441
|
-
if (process.platform !== "win32") {
|
|
442
|
-
await rename(tmp, target);
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
for (const ms of RENAME_RETRY_DELAYS_MS) {
|
|
446
|
-
try {
|
|
447
|
-
await rename(tmp, target);
|
|
448
|
-
return;
|
|
449
|
-
} catch (err) {
|
|
450
|
-
const code = err.code;
|
|
451
|
-
if (code === void 0 || !RENAME_RETRY_CODES.has(code)) throw err;
|
|
452
|
-
await delay(ms);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
await rename(tmp, target);
|
|
456
|
-
}
|
|
457
|
-
var tmpSeq = 0;
|
|
458
|
-
async function atomicWriteFile(filePath, contents, encoding = "utf8", mode, dirMode) {
|
|
459
|
-
const target = await resolveSymlinkTarget(filePath);
|
|
460
|
-
const dir = path.dirname(target);
|
|
461
|
-
const tmp = `${target}.tmp-${process.pid}-${Date.now()}-${++tmpSeq}`;
|
|
462
|
-
await mkdirpWithMode(dir, dirMode);
|
|
463
|
-
let preserved;
|
|
464
|
-
if (mode === void 0 && process.platform !== "win32") {
|
|
465
|
-
try {
|
|
466
|
-
preserved = (await stat(target)).mode & 511;
|
|
467
|
-
} catch {
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
const birthMode = mode ?? preserved;
|
|
471
|
-
try {
|
|
472
|
-
await writeFile(tmp, contents, birthMode === void 0 ? { encoding } : { encoding, mode: birthMode });
|
|
473
|
-
if (preserved !== void 0) {
|
|
474
|
-
try {
|
|
475
|
-
await chmod(tmp, preserved);
|
|
476
|
-
} catch {
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
await renameWithRetry(tmp, target);
|
|
480
|
-
} catch (err) {
|
|
481
|
-
await unlink(tmp).catch(() => void 0);
|
|
482
|
-
throw err;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
async function resolveSymlinkTarget(filePath) {
|
|
486
|
-
try {
|
|
487
|
-
if (!(await lstat(filePath)).isSymbolicLink()) return filePath;
|
|
488
|
-
return await realpath(filePath);
|
|
489
|
-
} catch {
|
|
490
|
-
return filePath;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
async function mkdirpWithMode(dir, dirMode) {
|
|
494
|
-
if (dirMode === void 0 || process.platform === "win32") {
|
|
495
|
-
await mkdir(dir, { recursive: true });
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
const resolved = path.resolve(dir);
|
|
499
|
-
const toCreate = [];
|
|
500
|
-
let cursor = resolved;
|
|
501
|
-
while (true) {
|
|
502
|
-
let exists2 = true;
|
|
503
|
-
try {
|
|
504
|
-
await stat(cursor);
|
|
505
|
-
} catch {
|
|
506
|
-
exists2 = false;
|
|
507
|
-
}
|
|
508
|
-
if (exists2) break;
|
|
509
|
-
toCreate.unshift(cursor);
|
|
510
|
-
const parent = path.dirname(cursor);
|
|
511
|
-
if (parent === cursor) break;
|
|
512
|
-
cursor = parent;
|
|
513
|
-
}
|
|
514
|
-
if (toCreate.length === 0) return;
|
|
515
|
-
await mkdir(resolved, { recursive: true, mode: dirMode });
|
|
516
|
-
for (const created of toCreate) {
|
|
517
|
-
try {
|
|
518
|
-
await chmod(created, dirMode);
|
|
519
|
-
} catch {
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
436
|
|
|
524
437
|
// src/json-key.ts
|
|
525
438
|
function setJsonKey(target, key, value) {
|
|
@@ -555,10 +468,10 @@ async function readGradesCache(home = homedir()) {
|
|
|
555
468
|
return readGradesCacheImpl(home, { strictRead: false });
|
|
556
469
|
}
|
|
557
470
|
async function readGradesCacheImpl(home, opts) {
|
|
558
|
-
const
|
|
471
|
+
const path5 = gradesCachePath(home);
|
|
559
472
|
let raw;
|
|
560
473
|
try {
|
|
561
|
-
raw = await readFile2(
|
|
474
|
+
raw = await readFile2(path5, "utf8");
|
|
562
475
|
} catch (err) {
|
|
563
476
|
const code = err.code;
|
|
564
477
|
if (opts.strictRead && code !== "ENOENT" && code !== "ENOTDIR") throw err;
|
|
@@ -569,14 +482,14 @@ async function readGradesCacheImpl(home, opts) {
|
|
|
569
482
|
parsed = parseJsonc(raw);
|
|
570
483
|
} catch (err) {
|
|
571
484
|
log("warn", "grades.json is not valid JSON; ignoring", {
|
|
572
|
-
path:
|
|
485
|
+
path: path5,
|
|
573
486
|
error: err instanceof Error ? err.message : String(err)
|
|
574
487
|
});
|
|
575
488
|
return {};
|
|
576
489
|
}
|
|
577
490
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
578
491
|
log("warn", "grades.json is not a JSON object of namespace -> grade; ignoring", {
|
|
579
|
-
path:
|
|
492
|
+
path: path5,
|
|
580
493
|
rootType: Array.isArray(parsed) ? "array" : parsed === null ? "null" : typeof parsed
|
|
581
494
|
});
|
|
582
495
|
return {};
|
|
@@ -592,6 +505,7 @@ var GRADES_LOCK_SUFFIX = ".lock";
|
|
|
592
505
|
var GRADES_LOCK_STALE_MS = 1e4;
|
|
593
506
|
var GRADES_LOCK_WAIT_MS = 15e3;
|
|
594
507
|
var GRADES_LOCK_POLL_MS = 25;
|
|
508
|
+
var GRADES_LOCK_TRANSIENT_MS = 1e3;
|
|
595
509
|
var GRADES_LOCK_FUTURE_SKEW_MS = 5e3;
|
|
596
510
|
var lockSeq = 0;
|
|
597
511
|
async function takeLock(lockPath, token) {
|
|
@@ -617,13 +531,13 @@ async function takeLock(lockPath, token) {
|
|
|
617
531
|
async function stealStaleLock(lockPath, isLive) {
|
|
618
532
|
const stolenPath = `${lockPath}.stale-${process.pid}-${++lockSeq}`;
|
|
619
533
|
try {
|
|
620
|
-
await
|
|
534
|
+
await rename(lockPath, stolenPath);
|
|
621
535
|
} catch (err) {
|
|
622
536
|
return err.code === "ENOENT";
|
|
623
537
|
}
|
|
624
538
|
let holder = null;
|
|
625
539
|
try {
|
|
626
|
-
if (isLive(Date.now() - (await
|
|
540
|
+
if (isLive(Date.now() - (await stat(stolenPath)).mtimeMs)) holder = await readFile2(stolenPath, "utf8");
|
|
627
541
|
} catch {
|
|
628
542
|
}
|
|
629
543
|
if (holder !== null) {
|
|
@@ -643,25 +557,39 @@ function lockTimeout(_path, lockPath, ageMs) {
|
|
|
643
557
|
const held = ageMs === null ? "" : ` for ${Math.round(ageMs / 1e3)}s`;
|
|
644
558
|
return new Error(`locked by another yaw-mcp audit (${lockPath}, held${held}) -- re-run this audit once it finishes`);
|
|
645
559
|
}
|
|
646
|
-
async function withGradesLock(
|
|
647
|
-
const lockPath = `${
|
|
560
|
+
async function withGradesLock(path5, opts, fn) {
|
|
561
|
+
const lockPath = `${path5}${GRADES_LOCK_SUFFIX}`;
|
|
648
562
|
const staleMs = opts.lockStaleMs ?? GRADES_LOCK_STALE_MS;
|
|
649
563
|
const waitMs = opts.lockWaitMs ?? GRADES_LOCK_WAIT_MS;
|
|
650
564
|
const token = `${process.pid}-${++lockSeq}
|
|
651
565
|
`;
|
|
652
566
|
const isLive = (ageMs) => ageMs > -GRADES_LOCK_FUTURE_SKEW_MS && ageMs < staleMs;
|
|
653
|
-
await
|
|
567
|
+
await mkdir(dirname2(path5), { recursive: true });
|
|
654
568
|
const deadline = Date.now() + waitMs;
|
|
655
|
-
|
|
569
|
+
let transientSince = null;
|
|
570
|
+
for (; ; ) {
|
|
571
|
+
let taken;
|
|
572
|
+
try {
|
|
573
|
+
taken = await takeLock(lockPath, token);
|
|
574
|
+
} catch (err) {
|
|
575
|
+
if (!isWin32TransientFsError(err)) throw err;
|
|
576
|
+
const now = Date.now();
|
|
577
|
+
transientSince ??= now;
|
|
578
|
+
if (now >= deadline || now - transientSince >= GRADES_LOCK_TRANSIENT_MS) throw err;
|
|
579
|
+
await delay(GRADES_LOCK_POLL_MS);
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
if (taken) break;
|
|
583
|
+
transientSince = null;
|
|
656
584
|
let ageMs;
|
|
657
585
|
try {
|
|
658
|
-
ageMs = Date.now() - (await
|
|
586
|
+
ageMs = Date.now() - (await stat(lockPath)).mtimeMs;
|
|
659
587
|
} catch {
|
|
660
588
|
ageMs = null;
|
|
661
589
|
}
|
|
662
590
|
if (ageMs !== null && !isLive(ageMs) && await stealStaleLock(lockPath, isLive)) continue;
|
|
663
|
-
if (Date.now() >= deadline) throw lockTimeout(
|
|
664
|
-
await
|
|
591
|
+
if (Date.now() >= deadline) throw lockTimeout(path5, lockPath, ageMs);
|
|
592
|
+
await delay(GRADES_LOCK_POLL_MS);
|
|
665
593
|
}
|
|
666
594
|
try {
|
|
667
595
|
return await fn();
|
|
@@ -670,14 +598,14 @@ async function withGradesLock(path6, opts, fn) {
|
|
|
670
598
|
}
|
|
671
599
|
}
|
|
672
600
|
async function writeGrade(namespace, grade, home = homedir(), opts = {}) {
|
|
673
|
-
const
|
|
674
|
-
await withGradesLock(
|
|
601
|
+
const path5 = gradesCachePath(home);
|
|
602
|
+
await withGradesLock(path5, opts, async () => {
|
|
675
603
|
const cache = await readGradesCacheImpl(home, { strictRead: true });
|
|
676
604
|
setJsonKey(cache, namespace, grade);
|
|
677
|
-
await atomicWriteFile(
|
|
605
|
+
await atomicWriteFile(path5, `${JSON.stringify(cache, null, 2)}
|
|
678
606
|
`);
|
|
679
607
|
});
|
|
680
|
-
return
|
|
608
|
+
return path5;
|
|
681
609
|
}
|
|
682
610
|
|
|
683
611
|
// src/health-score.ts
|
|
@@ -815,13 +743,13 @@ function truncateForWarning(msg) {
|
|
|
815
743
|
// src/local-bundles.ts
|
|
816
744
|
import { createHash as createHash2 } from "crypto";
|
|
817
745
|
import { existsSync as existsSync2, statSync } from "fs";
|
|
818
|
-
import { chmod as
|
|
746
|
+
import { chmod as chmod2, mkdir as mkdir2, readFile as readFile4 } from "fs/promises";
|
|
819
747
|
import { homedir as homedir3 } from "os";
|
|
820
748
|
import { join as join4 } from "path";
|
|
821
749
|
|
|
822
750
|
// src/trust.ts
|
|
823
751
|
import { createHash } from "crypto";
|
|
824
|
-
import { chmod
|
|
752
|
+
import { chmod, readFile as readFile3 } from "fs/promises";
|
|
825
753
|
import { homedir as homedir2 } from "os";
|
|
826
754
|
import { basename, dirname as dirname3, join as join3, resolve } from "path";
|
|
827
755
|
var TRUST_FILENAME = "trusted.json";
|
|
@@ -873,60 +801,60 @@ function emptyStore(kind = null, reason = null, errorCode = null, version = TRUS
|
|
|
873
801
|
};
|
|
874
802
|
}
|
|
875
803
|
async function readTrustStore(home = homedir2(), platform = process.platform) {
|
|
876
|
-
const
|
|
804
|
+
const path5 = trustStorePath(home);
|
|
877
805
|
let raw;
|
|
878
806
|
try {
|
|
879
|
-
raw = await readFile3(
|
|
807
|
+
raw = await readFile3(path5, "utf8");
|
|
880
808
|
} catch (err) {
|
|
881
809
|
const code = err.code;
|
|
882
810
|
if (code === "ENOENT") return emptyStore();
|
|
883
811
|
const msg = err instanceof Error ? err.message : String(err);
|
|
884
|
-
log("warn", "Trust store unreadable; nothing is trusted", { path:
|
|
885
|
-
return emptyStore("io", `could not read ${
|
|
812
|
+
log("warn", "Trust store unreadable; nothing is trusted", { path: path5, error: msg, code });
|
|
813
|
+
return emptyStore("io", `could not read ${path5} (${msg})`, code ?? null);
|
|
886
814
|
}
|
|
887
815
|
let parsed;
|
|
888
816
|
try {
|
|
889
817
|
parsed = JSON.parse(raw);
|
|
890
818
|
} catch (err) {
|
|
891
819
|
const msg = err instanceof Error ? err.message : String(err);
|
|
892
|
-
log("warn", "Trust store is not valid JSON; nothing is trusted", { path:
|
|
893
|
-
return emptyStore("parse", `${
|
|
820
|
+
log("warn", "Trust store is not valid JSON; nothing is trusted", { path: path5, error: msg });
|
|
821
|
+
return emptyStore("parse", `${path5} is not valid JSON (${msg})`);
|
|
894
822
|
}
|
|
895
823
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
896
|
-
return emptyStore("parse", `${
|
|
824
|
+
return emptyStore("parse", `${path5} root must be a JSON object`);
|
|
897
825
|
}
|
|
898
826
|
const obj = parsed;
|
|
899
827
|
if (obj.version !== void 0 && typeof obj.version !== "number") {
|
|
900
|
-
log("warn", "Trust store has a non-numeric version; nothing is trusted", { path:
|
|
901
|
-
return emptyStore("parse", `${
|
|
828
|
+
log("warn", "Trust store has a non-numeric version; nothing is trusted", { path: path5 });
|
|
829
|
+
return emptyStore("parse", `${path5} has a non-numeric "version" field; the store is corrupt`);
|
|
902
830
|
}
|
|
903
831
|
const version = typeof obj.version === "number" ? obj.version : TRUST_SCHEMA_VERSION;
|
|
904
832
|
if (!Number.isInteger(version) || version < 1) {
|
|
905
|
-
log("warn", "Trust store has an out-of-range version; nothing is trusted", { path:
|
|
906
|
-
return emptyStore("parse", `${
|
|
833
|
+
log("warn", "Trust store has an out-of-range version; nothing is trusted", { path: path5, version });
|
|
834
|
+
return emptyStore("parse", `${path5} has an invalid "version" (${version}); the store is corrupt`);
|
|
907
835
|
}
|
|
908
836
|
if (version > TRUST_SCHEMA_VERSION) {
|
|
909
|
-
log("warn", "Trust store was written by a newer yaw-mcp; nothing is trusted", { path:
|
|
837
|
+
log("warn", "Trust store was written by a newer yaw-mcp; nothing is trusted", { path: path5, version });
|
|
910
838
|
return emptyStore(
|
|
911
839
|
"schema",
|
|
912
|
-
`${
|
|
840
|
+
`${path5} was written by a newer yaw-mcp (schema version ${version}; this build understands ${TRUST_SCHEMA_VERSION})`,
|
|
913
841
|
null,
|
|
914
842
|
version
|
|
915
843
|
);
|
|
916
844
|
}
|
|
917
845
|
const rawEntries = obj.trusted;
|
|
918
846
|
if (!rawEntries || typeof rawEntries !== "object" || Array.isArray(rawEntries)) {
|
|
919
|
-
return emptyStore("parse", `${
|
|
847
|
+
return emptyStore("parse", `${path5} is missing a 'trusted' object`, null, version);
|
|
920
848
|
}
|
|
921
849
|
const entries = {};
|
|
922
850
|
for (const [key, value] of Object.entries(rawEntries)) {
|
|
923
851
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
924
|
-
log("warn", "Dropping malformed trust entry", { path:
|
|
852
|
+
log("warn", "Dropping malformed trust entry", { path: path5, key });
|
|
925
853
|
continue;
|
|
926
854
|
}
|
|
927
855
|
const v = value;
|
|
928
856
|
if (typeof v.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(v.sha256)) {
|
|
929
|
-
log("warn", "Dropping trust entry with a missing or malformed sha256", { path:
|
|
857
|
+
log("warn", "Dropping trust entry with a missing or malformed sha256", { path: path5, key });
|
|
930
858
|
continue;
|
|
931
859
|
}
|
|
932
860
|
setJsonKey(entries, normalizeTrustKey(key, platform), {
|
|
@@ -937,39 +865,39 @@ async function readTrustStore(home = homedir2(), platform = process.platform) {
|
|
|
937
865
|
}
|
|
938
866
|
return { version, entries, malformed: false, malformedReason: null, malformedKind: null, errorCode: null };
|
|
939
867
|
}
|
|
940
|
-
function trustStatusFor(
|
|
868
|
+
function trustStatusFor(path5, contents, store) {
|
|
941
869
|
if (store.malformed) return "store-unreadable";
|
|
942
|
-
const record = store.entries[normalizeTrustKey(
|
|
870
|
+
const record = store.entries[normalizeTrustKey(path5)];
|
|
943
871
|
if (!record) return "untrusted";
|
|
944
872
|
return record.sha256 === hashTrustContent(contents) ? "trusted" : "changed";
|
|
945
873
|
}
|
|
946
874
|
async function writeTrustStore(home, entries) {
|
|
947
|
-
const
|
|
875
|
+
const path5 = trustStorePath(home);
|
|
948
876
|
const body = { version: TRUST_SCHEMA_VERSION, trusted: entries };
|
|
949
|
-
await atomicWriteFile(
|
|
877
|
+
await atomicWriteFile(path5, `${JSON.stringify(body, null, 2)}
|
|
950
878
|
`, "utf8", 384, 448);
|
|
951
879
|
if (process.platform !== "win32") {
|
|
952
880
|
try {
|
|
953
|
-
await
|
|
881
|
+
await chmod(path5, 384);
|
|
954
882
|
} catch {
|
|
955
883
|
}
|
|
956
884
|
}
|
|
957
|
-
return
|
|
885
|
+
return path5;
|
|
958
886
|
}
|
|
959
|
-
async function grantTrust(
|
|
887
|
+
async function grantTrust(path5, contents, opts = {}) {
|
|
960
888
|
const home = opts.home ?? homedir2();
|
|
961
889
|
const platform = opts.platform ?? process.platform;
|
|
962
890
|
const store = await readTrustStore(home, platform);
|
|
963
891
|
refuseUnusableStore(home, store);
|
|
964
892
|
const record = {
|
|
965
|
-
path: resolve(
|
|
893
|
+
path: resolve(path5),
|
|
966
894
|
sha256: hashTrustContent(contents),
|
|
967
895
|
grantedAt: new Date(opts.now ? opts.now() : Date.now()).toISOString()
|
|
968
896
|
};
|
|
969
897
|
const fresh = await readTrustStore(home, platform);
|
|
970
898
|
refuseUnusableStore(home, fresh);
|
|
971
899
|
const entries = fresh.malformed ? {} : { ...fresh.entries };
|
|
972
|
-
setJsonKey(entries, normalizeTrustKey(
|
|
900
|
+
setJsonKey(entries, normalizeTrustKey(path5, platform), record);
|
|
973
901
|
const storePath = await writeTrustStore(home, entries);
|
|
974
902
|
log("info", "Granted project bundles.json trust", { path: record.path, sha256: record.sha256 });
|
|
975
903
|
return { storePath, record, storeWasMalformed: store.malformed || fresh.malformed };
|
|
@@ -990,7 +918,7 @@ async function revokeKeyCandidates(p, platform) {
|
|
|
990
918
|
const physical = normalizeTrustKey(join3(await realpathOrSelf(dirname3(resolved)), basename(resolved)), platform);
|
|
991
919
|
return physical === lexical ? [lexical] : [lexical, physical];
|
|
992
920
|
}
|
|
993
|
-
async function revokeTrust(
|
|
921
|
+
async function revokeTrust(path5, opts = {}) {
|
|
994
922
|
const home = opts.home ?? homedir2();
|
|
995
923
|
const platform = opts.platform ?? process.platform;
|
|
996
924
|
const store = await readTrustStore(home, platform);
|
|
@@ -1010,7 +938,7 @@ async function revokeTrust(path6, opts = {}) {
|
|
|
1010
938
|
malformedReason: null
|
|
1011
939
|
});
|
|
1012
940
|
if (store.malformed) return refused(store);
|
|
1013
|
-
const candidates = await revokeKeyCandidates(
|
|
941
|
+
const candidates = await revokeKeyCandidates(path5, platform);
|
|
1014
942
|
const keys = candidates.filter((c) => Object.hasOwn(store.entries, c));
|
|
1015
943
|
if (keys.length === 0) return done(false);
|
|
1016
944
|
const fresh = await readTrustStore(home, platform);
|
|
@@ -1020,7 +948,7 @@ async function revokeTrust(path6, opts = {}) {
|
|
|
1020
948
|
const entries = { ...fresh.entries };
|
|
1021
949
|
for (const k of present) delete entries[k];
|
|
1022
950
|
await writeTrustStore(home, entries);
|
|
1023
|
-
log("info", "Revoked project bundles.json trust", { path: resolve(
|
|
951
|
+
log("info", "Revoked project bundles.json trust", { path: resolve(path5) });
|
|
1024
952
|
return done(true);
|
|
1025
953
|
}
|
|
1026
954
|
function trustedRecords(store) {
|
|
@@ -1158,9 +1086,9 @@ function validateEntry2(entry, warnings) {
|
|
|
1158
1086
|
};
|
|
1159
1087
|
}
|
|
1160
1088
|
var IS_A_DIRECTORY_DETAIL = "the path is a directory, not a file";
|
|
1161
|
-
async function readBundlesRawAt(
|
|
1089
|
+
async function readBundlesRawAt(path5) {
|
|
1162
1090
|
try {
|
|
1163
|
-
return { kind: "ok", raw: await readFile4(
|
|
1091
|
+
return { kind: "ok", raw: await readFile4(path5) };
|
|
1164
1092
|
} catch (err) {
|
|
1165
1093
|
const code = err.code;
|
|
1166
1094
|
if (code === "ENOENT") return { kind: "absent" };
|
|
@@ -1169,41 +1097,41 @@ async function readBundlesRawAt(path6) {
|
|
|
1169
1097
|
}
|
|
1170
1098
|
}
|
|
1171
1099
|
var READ_FAILURE_MARKER = "could not read file (";
|
|
1172
|
-
async function readBundlesAt(
|
|
1173
|
-
const r = await readBundlesRawAt(
|
|
1100
|
+
async function readBundlesAt(path5, warnings) {
|
|
1101
|
+
const r = await readBundlesRawAt(path5);
|
|
1174
1102
|
if (r.kind === "absent") return { exists: false, file: null };
|
|
1175
1103
|
if (r.kind === "error") {
|
|
1176
|
-
warnings.push(`${
|
|
1177
|
-
log("warn", "Could not read bundles.json", { path:
|
|
1104
|
+
warnings.push(`${path5}: ${READ_FAILURE_MARKER}${r.message}) -- skipping`);
|
|
1105
|
+
log("warn", "Could not read bundles.json", { path: path5, error: r.message, code: r.code });
|
|
1178
1106
|
return { exists: true, file: null };
|
|
1179
1107
|
}
|
|
1180
|
-
return { exists: true, file: parseBundlesContent(
|
|
1108
|
+
return { exists: true, file: parseBundlesContent(path5, r.raw, warnings) };
|
|
1181
1109
|
}
|
|
1182
|
-
function parseBundlesContent(
|
|
1110
|
+
function parseBundlesContent(path5, rawBytes, warnings) {
|
|
1183
1111
|
const raw = rawBytes.toString("utf8");
|
|
1184
1112
|
let parsed;
|
|
1185
1113
|
try {
|
|
1186
1114
|
parsed = parseJsonc(raw);
|
|
1187
1115
|
} catch (err) {
|
|
1188
1116
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1189
|
-
warnings.push(`${
|
|
1190
|
-
log("warn", "bundles.json is not valid JSON; ignoring", { path:
|
|
1117
|
+
warnings.push(`${path5}: invalid JSON (${msg}) -- file ignored`);
|
|
1118
|
+
log("warn", "bundles.json is not valid JSON; ignoring", { path: path5, error: msg });
|
|
1191
1119
|
return null;
|
|
1192
1120
|
}
|
|
1193
1121
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1194
|
-
warnings.push(`${
|
|
1122
|
+
warnings.push(`${path5}: root must be a JSON object -- file ignored`);
|
|
1195
1123
|
return null;
|
|
1196
1124
|
}
|
|
1197
1125
|
const obj = parsed;
|
|
1198
1126
|
const version = typeof obj.version === "number" ? obj.version : void 0;
|
|
1199
1127
|
if (version !== void 0 && version > CURRENT_BUNDLES_SCHEMA_VERSION) {
|
|
1200
1128
|
warnings.push(
|
|
1201
|
-
`${
|
|
1129
|
+
`${path5}: schema version ${version} is newer than this yaw-mcp (${CURRENT_BUNDLES_SCHEMA_VERSION}); upgrade with \`npm i -g @yawlabs/mcp@latest\`. Loading best-effort.`
|
|
1202
1130
|
);
|
|
1203
1131
|
}
|
|
1204
1132
|
const rawServers = obj.servers;
|
|
1205
1133
|
if (!Array.isArray(rawServers)) {
|
|
1206
|
-
warnings.push(`${
|
|
1134
|
+
warnings.push(`${path5}: 'servers' must be an array -- file ignored`);
|
|
1207
1135
|
return null;
|
|
1208
1136
|
}
|
|
1209
1137
|
let defaultRuntime2;
|
|
@@ -1211,14 +1139,14 @@ function parseBundlesContent(path6, rawBytes, warnings) {
|
|
|
1211
1139
|
defaultRuntime2 = obj.defaultRuntime;
|
|
1212
1140
|
} else if (obj.defaultRuntime !== void 0) {
|
|
1213
1141
|
warnings.push(
|
|
1214
|
-
`${
|
|
1142
|
+
`${path5}: ignoring invalid 'defaultRuntime' ${JSON.stringify(obj.defaultRuntime)} (expected "oam" or "node")`
|
|
1215
1143
|
);
|
|
1216
1144
|
}
|
|
1217
1145
|
return { version, servers: rawServers, defaultRuntime: defaultRuntime2 };
|
|
1218
1146
|
}
|
|
1219
|
-
function previewBundlesContent(
|
|
1147
|
+
function previewBundlesContent(path5, rawBytes) {
|
|
1220
1148
|
const warnings = [];
|
|
1221
|
-
const file = parseBundlesContent(
|
|
1149
|
+
const file = parseBundlesContent(path5, rawBytes, warnings);
|
|
1222
1150
|
if (!file) return { ok: false, servers: [], warnings };
|
|
1223
1151
|
const servers = [];
|
|
1224
1152
|
for (const entry of file.servers) {
|
|
@@ -1239,8 +1167,8 @@ async function probeProjectTrust(opts = {}) {
|
|
|
1239
1167
|
const bypassed = isTrustBypassEnabled(env);
|
|
1240
1168
|
const storePath = trustStorePath(home);
|
|
1241
1169
|
const projectDir = await findProjectConfigDir(cwd, home, env).catch(() => null);
|
|
1242
|
-
const
|
|
1243
|
-
if (
|
|
1170
|
+
const path5 = projectDir ? localBundlesPath(projectDir) : null;
|
|
1171
|
+
if (path5 === null) {
|
|
1244
1172
|
return {
|
|
1245
1173
|
path: null,
|
|
1246
1174
|
status: "none",
|
|
@@ -1252,15 +1180,15 @@ async function probeProjectTrust(opts = {}) {
|
|
|
1252
1180
|
pathTrusted: false
|
|
1253
1181
|
};
|
|
1254
1182
|
}
|
|
1255
|
-
const read = await readBundlesRawAt(
|
|
1183
|
+
const read = await readBundlesRawAt(path5);
|
|
1256
1184
|
if (read.kind === "absent") {
|
|
1257
|
-
return { path:
|
|
1185
|
+
return { path: path5, status: "none", bypassed, raw: null, sha256: null, error: null, storePath, pathTrusted: false };
|
|
1258
1186
|
}
|
|
1259
1187
|
const store = await readTrustStore(home);
|
|
1260
|
-
const pathTrusted = !store.malformed && normalizeTrustKey(
|
|
1188
|
+
const pathTrusted = !store.malformed && normalizeTrustKey(path5) in store.entries;
|
|
1261
1189
|
if (read.kind === "error") {
|
|
1262
1190
|
return {
|
|
1263
|
-
path:
|
|
1191
|
+
path: path5,
|
|
1264
1192
|
status: "unreadable",
|
|
1265
1193
|
bypassed,
|
|
1266
1194
|
raw: null,
|
|
@@ -1271,8 +1199,8 @@ async function probeProjectTrust(opts = {}) {
|
|
|
1271
1199
|
};
|
|
1272
1200
|
}
|
|
1273
1201
|
return {
|
|
1274
|
-
path:
|
|
1275
|
-
status: trustStatusFor(
|
|
1202
|
+
path: path5,
|
|
1203
|
+
status: trustStatusFor(path5, read.raw, store),
|
|
1276
1204
|
bypassed,
|
|
1277
1205
|
raw: read.raw,
|
|
1278
1206
|
sha256: hashTrustContent(read.raw),
|
|
@@ -1282,25 +1210,25 @@ async function probeProjectTrust(opts = {}) {
|
|
|
1282
1210
|
};
|
|
1283
1211
|
}
|
|
1284
1212
|
function untrustedProjectWarning(probe, opts = {}) {
|
|
1285
|
-
const
|
|
1213
|
+
const path5 = probe.path ?? "(unknown)";
|
|
1286
1214
|
const approve = "`yaw-mcp trust` to approve";
|
|
1287
1215
|
const detail = opts.detail === true;
|
|
1288
1216
|
const fallback = detail ? " Falling back to your user-global ~/.yaw-mcp/bundles.json." : " Using user-global instead.";
|
|
1289
1217
|
const escapeHatch = detail ? ` Set ${TRUST_BYPASS_ENV}=1 to skip this check (CI/automation only -- it lets any repo you run inside spawn commands as you).` : ` (${TRUST_BYPASS_ENV}=1 skips this check; CI only.)`;
|
|
1290
1218
|
if (probe.status === "changed") {
|
|
1291
1219
|
const why2 = detail ? " The new contents could spawn commands you never reviewed." : "";
|
|
1292
|
-
return `${
|
|
1220
|
+
return `${path5}: project bundles.json CHANGED since you approved it -- IGNORED.${why2}${fallback} Re-review, then run ${approve}.${escapeHatch}`;
|
|
1293
1221
|
}
|
|
1294
1222
|
if (probe.status === "store-unreadable") {
|
|
1295
1223
|
const fix = detail ? " Fix or delete that file, then re-approve from inside this project." : "";
|
|
1296
|
-
return `${
|
|
1224
|
+
return `${path5}: project bundles.json IGNORED -- the trust store at ${probe.storePath} could not be read, so nothing is trusted (fail-closed).${fallback}${fix} Then run ${approve}.${escapeHatch}`;
|
|
1297
1225
|
}
|
|
1298
1226
|
if (probe.status === "unreadable") {
|
|
1299
1227
|
const why2 = detail ? " An unreadable project file that has never been approved is treated as absent rather than as authoritative -- otherwise a repo could blank out your servers just by committing something yaw-mcp cannot read." : "";
|
|
1300
|
-
return `${
|
|
1228
|
+
return `${path5}: project bundles.json could not be read (${probe.error}) and was never approved -- IGNORED.${why2}${fallback} Fix the file, then run ${approve}.`;
|
|
1301
1229
|
}
|
|
1302
1230
|
const why = detail ? " A project file is usually committed to the repo and can spawn arbitrary commands as you, so it has to be approved first." : "";
|
|
1303
|
-
return `${
|
|
1231
|
+
return `${path5}: untrusted project bundles.json -- IGNORED.${why}${fallback} Review the servers, then run ${approve}.${escapeHatch}`;
|
|
1304
1232
|
}
|
|
1305
1233
|
function projectFileIsHonoured(probe) {
|
|
1306
1234
|
if (probe.status === "none") return false;
|
|
@@ -1308,12 +1236,12 @@ function projectFileIsHonoured(probe) {
|
|
|
1308
1236
|
return probe.bypassed || probe.status === "trusted";
|
|
1309
1237
|
}
|
|
1310
1238
|
function bundlesSignature(paths) {
|
|
1311
|
-
return paths.map((
|
|
1239
|
+
return paths.map((path5) => {
|
|
1312
1240
|
try {
|
|
1313
|
-
const s = statSync(
|
|
1314
|
-
return `${
|
|
1241
|
+
const s = statSync(path5);
|
|
1242
|
+
return `${path5}=${s.mtimeMs}:${s.size}`;
|
|
1315
1243
|
} catch {
|
|
1316
|
-
return `${
|
|
1244
|
+
return `${path5}=absent`;
|
|
1317
1245
|
}
|
|
1318
1246
|
}).join("|");
|
|
1319
1247
|
}
|
|
@@ -1404,7 +1332,7 @@ var BUNDLES_LOCK_WAIT_MS = 5e3;
|
|
|
1404
1332
|
var BUNDLES_LOCK_POLL_MS = 20;
|
|
1405
1333
|
async function withBundlesLock(home, fn) {
|
|
1406
1334
|
const dir = userConfigDir(home);
|
|
1407
|
-
await
|
|
1335
|
+
await mkdir2(dir, { recursive: true, mode: 448 });
|
|
1408
1336
|
const lockPath = join4(dir, BUNDLES_LOCK_NAME);
|
|
1409
1337
|
const deadline = Date.now() + BUNDLES_LOCK_WAIT_MS;
|
|
1410
1338
|
let release = acquireUpgradeLock(dir, BUNDLES_LOCK_NAME, { probeHolder: true });
|
|
@@ -1443,20 +1371,20 @@ function deriveNamespace(name) {
|
|
|
1443
1371
|
return ns;
|
|
1444
1372
|
}
|
|
1445
1373
|
async function readRawUserBundles(home, warnings) {
|
|
1446
|
-
const
|
|
1447
|
-
const r = await readBundlesAt(
|
|
1374
|
+
const path5 = localBundlesPath(userConfigDir(home));
|
|
1375
|
+
const r = await readBundlesAt(path5, warnings);
|
|
1448
1376
|
if (!r.exists) return { version: CURRENT_BUNDLES_SCHEMA_VERSION, servers: [] };
|
|
1449
1377
|
if (!r.file) {
|
|
1450
1378
|
const warningText = warnings.join("; ");
|
|
1451
|
-
const readWarning = warnings.find((w) => w.startsWith(`${
|
|
1379
|
+
const readWarning = warnings.find((w) => w.startsWith(`${path5}: ${READ_FAILURE_MARKER}`));
|
|
1452
1380
|
if (readWarning) {
|
|
1453
1381
|
if (readWarning.includes(IS_A_DIRECTORY_DETAIL)) {
|
|
1454
|
-
throw new Error(`${
|
|
1382
|
+
throw new Error(`${path5} is a directory, not a file -- move or remove it before adding servers.`);
|
|
1455
1383
|
}
|
|
1456
|
-
throw new Error(`${
|
|
1384
|
+
throw new Error(`${path5} could not be read (${warningText}) -- check file permissions before adding servers.`);
|
|
1457
1385
|
}
|
|
1458
1386
|
const detail = warnings.length > 0 ? ` (${warningText})` : "";
|
|
1459
|
-
throw new Error(`${
|
|
1387
|
+
throw new Error(`${path5} could not be parsed -- fix the JSON${detail} before adding servers.`);
|
|
1460
1388
|
}
|
|
1461
1389
|
for (const w of warnings) {
|
|
1462
1390
|
log("debug", "bundles.json warning (write path)", { warning: w });
|
|
@@ -1605,7 +1533,7 @@ async function previewUpsertUserBundle(entry, opts = {}) {
|
|
|
1605
1533
|
}
|
|
1606
1534
|
async function doUpsertUserBundle(entry, opts) {
|
|
1607
1535
|
const home = opts.home ?? homedir3();
|
|
1608
|
-
const
|
|
1536
|
+
const path5 = localBundlesPath(userConfigDir(home));
|
|
1609
1537
|
return withBundlesLock(home, async () => {
|
|
1610
1538
|
const warnings = [];
|
|
1611
1539
|
const file = await readRawUserBundles(home, warnings);
|
|
@@ -1616,15 +1544,15 @@ async function doUpsertUserBundle(entry, opts) {
|
|
|
1616
1544
|
const written = mergedUpsertEntry(file.servers, entry, target);
|
|
1617
1545
|
if (replaced) file.servers[idx] = written;
|
|
1618
1546
|
else file.servers.push(written);
|
|
1619
|
-
await atomicWriteFile(
|
|
1547
|
+
await atomicWriteFile(path5, `${JSON.stringify(file, null, 2)}
|
|
1620
1548
|
`, "utf8", 384, 448);
|
|
1621
1549
|
if (process.platform !== "win32") {
|
|
1622
1550
|
try {
|
|
1623
|
-
await
|
|
1551
|
+
await chmod2(path5, 384);
|
|
1624
1552
|
} catch {
|
|
1625
1553
|
}
|
|
1626
1554
|
}
|
|
1627
|
-
return { path:
|
|
1555
|
+
return { path: path5, replaced, entry: written, launchChanged: target.launchChanged, warnings };
|
|
1628
1556
|
});
|
|
1629
1557
|
}
|
|
1630
1558
|
function removeUserBundle(namespace, opts = {}) {
|
|
@@ -1637,23 +1565,23 @@ function removeUserBundle(namespace, opts = {}) {
|
|
|
1637
1565
|
}
|
|
1638
1566
|
async function doRemoveUserBundle(namespace, opts) {
|
|
1639
1567
|
const home = opts.home ?? homedir3();
|
|
1640
|
-
const
|
|
1641
|
-
if (!existsSync2(
|
|
1568
|
+
const path5 = localBundlesPath(userConfigDir(home));
|
|
1569
|
+
if (!existsSync2(path5)) return { path: path5, removed: false, warnings: [] };
|
|
1642
1570
|
return withBundlesLock(home, async () => {
|
|
1643
1571
|
const warnings = [];
|
|
1644
1572
|
const file = await readRawUserBundles(home, warnings);
|
|
1645
1573
|
const before = file.servers.length;
|
|
1646
1574
|
file.servers = file.servers.filter((s) => s?.namespace !== namespace);
|
|
1647
|
-
if (file.servers.length === before) return { path:
|
|
1648
|
-
await atomicWriteFile(
|
|
1575
|
+
if (file.servers.length === before) return { path: path5, removed: false, warnings };
|
|
1576
|
+
await atomicWriteFile(path5, `${JSON.stringify(file, null, 2)}
|
|
1649
1577
|
`, "utf8", 384, 448);
|
|
1650
1578
|
if (process.platform !== "win32") {
|
|
1651
1579
|
try {
|
|
1652
|
-
await
|
|
1580
|
+
await chmod2(path5, 384);
|
|
1653
1581
|
} catch {
|
|
1654
1582
|
}
|
|
1655
1583
|
}
|
|
1656
|
-
return { path:
|
|
1584
|
+
return { path: path5, removed: true, warnings };
|
|
1657
1585
|
});
|
|
1658
1586
|
}
|
|
1659
1587
|
async function findShadowingProjectBundles(cwd, home = homedir3(), env = process.env) {
|
|
@@ -1663,7 +1591,7 @@ async function findShadowingProjectBundles(cwd, home = homedir3(), env = process
|
|
|
1663
1591
|
|
|
1664
1592
|
// src/secrets-vault.ts
|
|
1665
1593
|
import { createHmac, randomBytes as randomBytes2, timingSafeEqual } from "crypto";
|
|
1666
|
-
import { chmod as
|
|
1594
|
+
import { chmod as chmod3, readFile as readFile5 } from "fs/promises";
|
|
1667
1595
|
import { homedir as homedir4 } from "os";
|
|
1668
1596
|
import { dirname as dirname4, join as join5 } from "path";
|
|
1669
1597
|
|
|
@@ -1769,43 +1697,43 @@ var VaultEntryCorruptError = class extends Error {
|
|
|
1769
1697
|
this.entryName = entryName;
|
|
1770
1698
|
}
|
|
1771
1699
|
};
|
|
1772
|
-
async function loadVault(
|
|
1700
|
+
async function loadVault(path5) {
|
|
1773
1701
|
let raw;
|
|
1774
1702
|
try {
|
|
1775
|
-
raw = await readFile5(
|
|
1703
|
+
raw = await readFile5(path5, "utf8");
|
|
1776
1704
|
} catch (err) {
|
|
1777
1705
|
const code = err.code;
|
|
1778
1706
|
if (code === "ENOENT") return null;
|
|
1779
|
-
log("warn", "Failed to read vault", { path:
|
|
1707
|
+
log("warn", "Failed to read vault", { path: path5, error: err instanceof Error ? err.message : String(err), code });
|
|
1780
1708
|
throw err;
|
|
1781
1709
|
}
|
|
1782
1710
|
let parsed;
|
|
1783
1711
|
try {
|
|
1784
1712
|
parsed = JSON.parse(raw);
|
|
1785
1713
|
} catch (err) {
|
|
1786
|
-
log("warn", "Vault file is not valid JSON", { path:
|
|
1787
|
-
throw new Error(`vault at ${
|
|
1714
|
+
log("warn", "Vault file is not valid JSON", { path: path5, error: err instanceof Error ? err.message : String(err) });
|
|
1715
|
+
throw new Error(`vault at ${path5} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
1788
1716
|
}
|
|
1789
1717
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1790
|
-
throw new Error(`vault at ${
|
|
1718
|
+
throw new Error(`vault at ${path5} is corrupt: root must be a JSON object`);
|
|
1791
1719
|
}
|
|
1792
1720
|
const obj = parsed;
|
|
1793
1721
|
if (typeof obj.salt !== "string" || !obj.entries || typeof obj.entries !== "object") {
|
|
1794
|
-
throw new Error(`vault at ${
|
|
1722
|
+
throw new Error(`vault at ${path5} is corrupt: missing or invalid salt/entries`);
|
|
1795
1723
|
}
|
|
1796
1724
|
if (Buffer.from(obj.salt, "base64").length !== SALT_LEN) {
|
|
1797
|
-
throw new Error(`vault at ${
|
|
1725
|
+
throw new Error(`vault at ${path5} is corrupt: salt (expected ${SALT_LEN} bytes)`);
|
|
1798
1726
|
}
|
|
1799
1727
|
if (obj.version !== void 0 && typeof obj.version !== "number") {
|
|
1800
|
-
throw new Error(`vault at ${
|
|
1728
|
+
throw new Error(`vault at ${path5} is corrupt: "version" must be a number`);
|
|
1801
1729
|
}
|
|
1802
1730
|
if (typeof obj.version === "number" && obj.version > SECRETS_SCHEMA_VERSION) {
|
|
1803
1731
|
throw new Error(
|
|
1804
|
-
`vault at ${
|
|
1732
|
+
`vault at ${path5} was written by a newer yaw-mcp (schema version ${obj.version} > ${SECRETS_SCHEMA_VERSION}); upgrade yaw-mcp to read it`
|
|
1805
1733
|
);
|
|
1806
1734
|
}
|
|
1807
1735
|
if (obj.kdf !== void 0 && !isValidKdfParams(obj.kdf)) {
|
|
1808
|
-
throw new Error(`vault at ${
|
|
1736
|
+
throw new Error(`vault at ${path5} is corrupt: invalid kdf parameters`);
|
|
1809
1737
|
}
|
|
1810
1738
|
const entries = obj.entries;
|
|
1811
1739
|
for (const [name, entry] of Object.entries(entries)) {
|
|
@@ -1814,7 +1742,7 @@ async function loadVault(path6) {
|
|
|
1814
1742
|
}
|
|
1815
1743
|
}
|
|
1816
1744
|
if (obj.check !== void 0 && !isEncryptedEntry(obj.check)) {
|
|
1817
|
-
log("warn", "Vault verification token is malformed; ignoring it (the next write re-stamps it)", { path:
|
|
1745
|
+
log("warn", "Vault verification token is malformed; ignoring it (the next write re-stamps it)", { path: path5 });
|
|
1818
1746
|
}
|
|
1819
1747
|
const check = isEncryptedEntry(obj.check) ? obj.check : void 0;
|
|
1820
1748
|
return {
|
|
@@ -1830,16 +1758,16 @@ function isEncryptedEntry(v) {
|
|
|
1830
1758
|
const e = v;
|
|
1831
1759
|
return typeof e.iv === "string" && typeof e.ciphertext === "string" && typeof e.authTag === "string";
|
|
1832
1760
|
}
|
|
1833
|
-
async function saveVault(
|
|
1834
|
-
await atomicWriteFile(
|
|
1761
|
+
async function saveVault(path5, vault) {
|
|
1762
|
+
await atomicWriteFile(path5, `${JSON.stringify(vault, null, 2)}
|
|
1835
1763
|
`, "utf8", 384, 448);
|
|
1836
1764
|
if (process.platform !== "win32") {
|
|
1837
1765
|
try {
|
|
1838
|
-
await
|
|
1766
|
+
await chmod3(dirname4(path5), 448);
|
|
1839
1767
|
} catch {
|
|
1840
1768
|
}
|
|
1841
1769
|
try {
|
|
1842
|
-
await
|
|
1770
|
+
await chmod3(path5, 384);
|
|
1843
1771
|
} catch {
|
|
1844
1772
|
}
|
|
1845
1773
|
}
|
|
@@ -2230,9 +2158,9 @@ var inflight = null;
|
|
|
2230
2158
|
var degradedProbe = null;
|
|
2231
2159
|
var DEGRADED_RECHECK_MS = 5e3;
|
|
2232
2160
|
var warnedDegradedBundles = false;
|
|
2233
|
-
function statSignature(
|
|
2161
|
+
function statSignature(path5) {
|
|
2234
2162
|
try {
|
|
2235
|
-
const s = statSync2(
|
|
2163
|
+
const s = statSync2(path5);
|
|
2236
2164
|
return `${s.mtimeMs}:${s.size}`;
|
|
2237
2165
|
} catch {
|
|
2238
2166
|
return null;
|
|
@@ -2276,12 +2204,12 @@ async function resolveBundlesDefault(opts) {
|
|
|
2276
2204
|
const degraded = bundles === null || bundles.config === null && bundles.path !== null;
|
|
2277
2205
|
const resolved = bundles?.defaultRuntime ?? null;
|
|
2278
2206
|
if (degraded && resolved === null) {
|
|
2279
|
-
const
|
|
2280
|
-
const signature =
|
|
2281
|
-
if (
|
|
2207
|
+
const path5 = bundles?.path ?? null;
|
|
2208
|
+
const signature = path5 === null ? null : statSignature(path5);
|
|
2209
|
+
if (path5 === null || signature === null) {
|
|
2282
2210
|
degradedProbe = null;
|
|
2283
2211
|
} else {
|
|
2284
|
-
const watched = bundles?.consultedPaths?.length ? bundles.consultedPaths : [
|
|
2212
|
+
const watched = bundles?.consultedPaths?.length ? bundles.consultedPaths : [path5];
|
|
2285
2213
|
degradedProbe = {
|
|
2286
2214
|
files: watched.map((f) => ({ path: f, signature: statSignature(f) })),
|
|
2287
2215
|
at: now()
|
|
@@ -2290,7 +2218,7 @@ async function resolveBundlesDefault(opts) {
|
|
|
2290
2218
|
if (!warnedDegradedBundles) {
|
|
2291
2219
|
warnedDegradedBundles = true;
|
|
2292
2220
|
log("warn", "bundles.json could not be read for the default runtime; using the fallback until the file changes", {
|
|
2293
|
-
path:
|
|
2221
|
+
path: path5 ?? "(unknown)"
|
|
2294
2222
|
});
|
|
2295
2223
|
}
|
|
2296
2224
|
return null;
|
|
@@ -2381,7 +2309,7 @@ function describeServerRuntime(server, configDefault, probe) {
|
|
|
2381
2309
|
|
|
2382
2310
|
// src/secrets-audit.ts
|
|
2383
2311
|
import { existsSync as existsSync3 } from "fs";
|
|
2384
|
-
import { appendFile, chmod as
|
|
2312
|
+
import { appendFile, chmod as chmod4, readFile as readFile6, stat as stat2 } from "fs/promises";
|
|
2385
2313
|
import { homedir as homedir5 } from "os";
|
|
2386
2314
|
import { join as join6 } from "path";
|
|
2387
2315
|
var SECRETS_AUDIT_FILENAME = "secrets-audit.log";
|
|
@@ -2398,41 +2326,41 @@ async function appendAuditEvent(input, home = homedir5()) {
|
|
|
2398
2326
|
secret: input.secret,
|
|
2399
2327
|
event: input.event
|
|
2400
2328
|
};
|
|
2401
|
-
const
|
|
2329
|
+
const path5 = auditLogPath(home);
|
|
2402
2330
|
const line = `${JSON.stringify(event)}
|
|
2403
2331
|
`;
|
|
2404
|
-
if (!existsSync3(
|
|
2405
|
-
await atomicWriteFile(
|
|
2332
|
+
if (!existsSync3(path5)) {
|
|
2333
|
+
await atomicWriteFile(path5, line, "utf8", 384, 448);
|
|
2406
2334
|
} else {
|
|
2407
|
-
await appendFile(
|
|
2335
|
+
await appendFile(path5, line, "utf8");
|
|
2408
2336
|
}
|
|
2409
2337
|
if (process.platform !== "win32") {
|
|
2410
|
-
await
|
|
2338
|
+
await chmod4(path5, 384).catch(() => void 0);
|
|
2411
2339
|
}
|
|
2412
|
-
await trimToTailCap(
|
|
2340
|
+
await trimToTailCap(path5);
|
|
2413
2341
|
} catch {
|
|
2414
2342
|
}
|
|
2415
2343
|
}
|
|
2416
2344
|
var MIN_AUDIT_LINE_BYTES = 64;
|
|
2417
|
-
async function trimToTailCap(
|
|
2418
|
-
const { size } = await
|
|
2345
|
+
async function trimToTailCap(path5) {
|
|
2346
|
+
const { size } = await stat2(path5);
|
|
2419
2347
|
if (size < AUDIT_TAIL_CAP * MIN_AUDIT_LINE_BYTES) return;
|
|
2420
|
-
const raw = await readFile6(
|
|
2348
|
+
const raw = await readFile6(path5, "utf8");
|
|
2421
2349
|
const lines = raw.split("\n").filter((l) => l.length > 0);
|
|
2422
2350
|
if (lines.length <= AUDIT_TAIL_CAP) return;
|
|
2423
2351
|
const kept = lines.slice(lines.length - AUDIT_TRIM_TO);
|
|
2424
|
-
await atomicWriteFile(
|
|
2352
|
+
await atomicWriteFile(path5, `${kept.join("\n")}
|
|
2425
2353
|
`, "utf8", 384);
|
|
2426
2354
|
}
|
|
2427
2355
|
async function readAuditLog(filter = {}, home = homedir5()) {
|
|
2428
|
-
const
|
|
2356
|
+
const path5 = auditLogPath(home);
|
|
2429
2357
|
let raw;
|
|
2430
2358
|
try {
|
|
2431
|
-
raw = await readFile6(
|
|
2359
|
+
raw = await readFile6(path5, "utf8");
|
|
2432
2360
|
} catch (err) {
|
|
2433
2361
|
const e = err;
|
|
2434
2362
|
if (e.code === "ENOENT") return [];
|
|
2435
|
-
throw new Error(`could not read the audit log at ${
|
|
2363
|
+
throw new Error(`could not read the audit log at ${path5} (${e.code ?? e.message})`);
|
|
2436
2364
|
}
|
|
2437
2365
|
const out = [];
|
|
2438
2366
|
for (const line of raw.split("\n")) {
|
|
@@ -2600,7 +2528,7 @@ import { spawn as spawn2 } from "child_process";
|
|
|
2600
2528
|
import { createHash as createHash3 } from "crypto";
|
|
2601
2529
|
import { createWriteStream } from "fs";
|
|
2602
2530
|
import fs from "fs/promises";
|
|
2603
|
-
import
|
|
2531
|
+
import path from "path";
|
|
2604
2532
|
import { pipeline } from "stream/promises";
|
|
2605
2533
|
import { request } from "undici";
|
|
2606
2534
|
var UV_VERSION = "0.12.10";
|
|
@@ -2830,7 +2758,7 @@ function runCommand(cmd, args, timeoutMs = UV_EXTRACT_TIMEOUT_MS) {
|
|
|
2830
2758
|
async function findBinary(root, name) {
|
|
2831
2759
|
const entries = await fs.readdir(root, { withFileTypes: true });
|
|
2832
2760
|
for (const e of entries) {
|
|
2833
|
-
const full =
|
|
2761
|
+
const full = path.join(root, e.name);
|
|
2834
2762
|
if (e.isFile() && e.name === name) return full;
|
|
2835
2763
|
if (e.isDirectory()) {
|
|
2836
2764
|
const found = await findBinary(full, name);
|
|
@@ -2869,8 +2797,8 @@ async function resolveUv() {
|
|
|
2869
2797
|
`No prebuilt uv binary for ${process.platform}/${process.arch}. Install uv manually: https://docs.astral.sh/uv/`
|
|
2870
2798
|
);
|
|
2871
2799
|
}
|
|
2872
|
-
const installDir =
|
|
2873
|
-
const finalBin =
|
|
2800
|
+
const installDir = path.join(cacheDir(), "uv", UV_VERSION, target);
|
|
2801
|
+
const finalBin = path.join(installDir, binName());
|
|
2874
2802
|
const cached = await fs.stat(finalBin).catch(() => null);
|
|
2875
2803
|
if (cached?.isFile() && cached.size > 0) return finalBin;
|
|
2876
2804
|
await fs.mkdir(installDir, { recursive: true });
|
|
@@ -2886,11 +2814,11 @@ async function resolveUv() {
|
|
|
2886
2814
|
throw new Error(`uv archive checksum mismatch (expected ${expected}, got ${actual})`);
|
|
2887
2815
|
}
|
|
2888
2816
|
const archiveBase = archiveName.endsWith(".tar.gz") ? `${archiveName.slice(0, -".tar.gz".length)}.${process.pid}.tar.gz` : archiveName.endsWith(".zip") ? `${archiveName.slice(0, -".zip".length)}.${process.pid}.zip` : `${archiveName}.${process.pid}`;
|
|
2889
|
-
const archivePath =
|
|
2817
|
+
const archivePath = path.join(installDir, archiveBase);
|
|
2890
2818
|
await pipeline(async function* () {
|
|
2891
2819
|
yield archiveBuf;
|
|
2892
2820
|
}, createWriteStream(archivePath));
|
|
2893
|
-
const extractDir =
|
|
2821
|
+
const extractDir = path.join(installDir, `extract-${process.pid}-${Date.now()}`);
|
|
2894
2822
|
try {
|
|
2895
2823
|
await extractArchive(archivePath, extractDir);
|
|
2896
2824
|
const extracted = await findBinary(extractDir, binName());
|
|
@@ -3265,7 +3193,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3265
3193
|
if (downstreamCaps?.sampling) capabilities.sampling = downstreamCaps.sampling;
|
|
3266
3194
|
if (downstreamCaps?.roots) capabilities.roots = {};
|
|
3267
3195
|
const client = new Client(
|
|
3268
|
-
{ name: "yaw-mcp", version: true ? "1.0.
|
|
3196
|
+
{ name: "yaw-mcp", version: true ? "1.0.3" : "dev" },
|
|
3269
3197
|
{ capabilities }
|
|
3270
3198
|
);
|
|
3271
3199
|
if (bridge && capabilities.elicitation) {
|
|
@@ -3891,12 +3819,12 @@ async function runAudit(opts = {}) {
|
|
|
3891
3819
|
return { exitCode: 2 };
|
|
3892
3820
|
}
|
|
3893
3821
|
const home = opts.home ?? homedir6();
|
|
3894
|
-
const { config, path:
|
|
3822
|
+
const { config, path: path5, warnings } = await loadLocalBundles({ cwd: opts.cwd, home });
|
|
3895
3823
|
for (const w of warnings) printErr(`warning: ${w}`);
|
|
3896
3824
|
const servers = config?.servers ?? [];
|
|
3897
3825
|
const server = findServer(servers, namespace);
|
|
3898
3826
|
if (!server) {
|
|
3899
|
-
const where =
|
|
3827
|
+
const where = path5 ? ` (${path5})` : "";
|
|
3900
3828
|
printErr(
|
|
3901
3829
|
`yaw-mcp audit: no server named "${namespace}" in bundles.json${where}. Run \`yaw-mcp list\` to see configured servers.`
|
|
3902
3830
|
);
|
|
@@ -4080,16 +4008,16 @@ import { homedir as homedir7 } from "os";
|
|
|
4080
4008
|
import { join as join8, resolve as resolve3 } from "path";
|
|
4081
4009
|
|
|
4082
4010
|
// src/migrate.ts
|
|
4083
|
-
import { lstat
|
|
4011
|
+
import { lstat, mkdir as mkdir3, rename as rename2, stat as stat3 } from "fs/promises";
|
|
4084
4012
|
import { dirname as dirname5, join as join7, resolve as resolve2 } from "path";
|
|
4085
4013
|
var LEGACY_GLOBAL_FILENAME = ".yaw-mcp.json";
|
|
4086
4014
|
var LEGACY_PROJECT_FILENAME = ".yaw-mcp.json";
|
|
4087
4015
|
var LEGACY_LOCAL_FILENAME = ".yaw-mcp.local.json";
|
|
4088
4016
|
var NEW_CONFIG_FILENAME = "config.json";
|
|
4089
4017
|
var NEW_LOCAL_FILENAME = "config.local.json";
|
|
4090
|
-
async function exists(
|
|
4018
|
+
async function exists(path5) {
|
|
4091
4019
|
try {
|
|
4092
|
-
await
|
|
4020
|
+
await stat3(path5);
|
|
4093
4021
|
return true;
|
|
4094
4022
|
} catch {
|
|
4095
4023
|
return false;
|
|
@@ -4098,7 +4026,7 @@ async function exists(path6) {
|
|
|
4098
4026
|
async function migrateFile(legacy, target, scope) {
|
|
4099
4027
|
let st;
|
|
4100
4028
|
try {
|
|
4101
|
-
st = await
|
|
4029
|
+
st = await lstat(legacy);
|
|
4102
4030
|
} catch {
|
|
4103
4031
|
return;
|
|
4104
4032
|
}
|
|
@@ -4136,8 +4064,8 @@ async function migrateFile(legacy, target, scope) {
|
|
|
4136
4064
|
return;
|
|
4137
4065
|
}
|
|
4138
4066
|
try {
|
|
4139
|
-
await
|
|
4140
|
-
await
|
|
4067
|
+
await mkdir3(dirname5(target), { recursive: true });
|
|
4068
|
+
await rename2(legacy, target);
|
|
4141
4069
|
log("info", "yaw-mcp config: migrated legacy file into .yaw-mcp/ directory", {
|
|
4142
4070
|
scope,
|
|
4143
4071
|
from: legacy,
|
|
@@ -4213,32 +4141,32 @@ var KNOWN_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
4213
4141
|
"installNudge"
|
|
4214
4142
|
]);
|
|
4215
4143
|
var CONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/YawLabs/mcp/main/schemas/yaw-mcp.config.v1.json";
|
|
4216
|
-
function deprecatedKeyWarning(
|
|
4144
|
+
function deprecatedKeyWarning(path5, keys) {
|
|
4217
4145
|
const quoted = keys.map((k) => `'${k}'`).join(" and ");
|
|
4218
4146
|
const isAre = keys.length > 1 ? "are" : "is";
|
|
4219
4147
|
const them = keys.length > 1 ? "them" : "it";
|
|
4220
4148
|
const revoke = keys.includes("token") ? ` Revoke that PAT at its source -- deleting it here does not deactivate it.` : "";
|
|
4221
|
-
return `${
|
|
4149
|
+
return `${path5}: ${quoted} ${isAre} no longer used -- yaw-mcp is local-only and never contacts a hosted API. Delete ${them} from ${path5}.${revoke}`;
|
|
4222
4150
|
}
|
|
4223
|
-
var namespaceEntry = (entry, field,
|
|
4151
|
+
var namespaceEntry = (entry, field, path5) => NAMESPACE_RE.test(entry) ? null : `${path5}: '${field}' entry '${entry}' is not a valid namespace (a lowercase letter followed by [a-z0-9_]) -- it can never match an installed server.`;
|
|
4224
4152
|
var TOOL_ENTRY_RE = /^[A-Za-z0-9_.:-]+\*?$/;
|
|
4225
|
-
var toolEntry = (entry, field,
|
|
4153
|
+
var toolEntry = (entry, field, path5) => {
|
|
4226
4154
|
if (!TOOL_ENTRY_RE.test(entry)) {
|
|
4227
|
-
return `${
|
|
4155
|
+
return `${path5}: '${field}' entry '${entry}' is not a valid tool name (letters, digits, '_', '.', ':', '-', with an optional single trailing '*') -- it can never match a tool.`;
|
|
4228
4156
|
}
|
|
4229
4157
|
if (entry.startsWith("mcp_connect_")) {
|
|
4230
|
-
return `${
|
|
4158
|
+
return `${path5}: '${field}' entry '${entry}' names a yaw-mcp meta-tool, which cannot be blocked -- remove it, or block the upstream server with 'blocked'.`;
|
|
4231
4159
|
}
|
|
4232
4160
|
if (!entry.includes("_")) {
|
|
4233
|
-
return `${
|
|
4161
|
+
return `${path5}: '${field}' entry '${entry}' has no '_' separator, so it cannot be a '<namespace>_<tool>' name -- to block a whole server use 'blocked'.`;
|
|
4234
4162
|
}
|
|
4235
4163
|
return null;
|
|
4236
4164
|
};
|
|
4237
|
-
function filterStringArray(raw, field,
|
|
4165
|
+
function filterStringArray(raw, field, path5, warnings, validate = namespaceEntry, dropInvalid = false) {
|
|
4238
4166
|
if (!Array.isArray(raw)) {
|
|
4239
4167
|
if (raw !== void 0) {
|
|
4240
4168
|
warnings.push(
|
|
4241
|
-
`${
|
|
4169
|
+
`${path5}: '${field}' must be an array of namespace strings (found ${raw === null ? "null" : typeof raw}) -- ignored.`
|
|
4242
4170
|
);
|
|
4243
4171
|
}
|
|
4244
4172
|
return void 0;
|
|
@@ -4247,28 +4175,28 @@ function filterStringArray(raw, field, path6, warnings, validate = namespaceEntr
|
|
|
4247
4175
|
const dropped = raw.length - strings.length;
|
|
4248
4176
|
if (dropped > 0) {
|
|
4249
4177
|
warnings.push(
|
|
4250
|
-
`${
|
|
4178
|
+
`${path5}: '${field}' dropped ${dropped} non-string or empty ${dropped === 1 ? "entry" : "entries"} -- only non-empty string namespaces are honored.`
|
|
4251
4179
|
);
|
|
4252
4180
|
}
|
|
4253
4181
|
const kept = [];
|
|
4254
4182
|
for (const s of strings) {
|
|
4255
|
-
const problem = validate(s, field,
|
|
4183
|
+
const problem = validate(s, field, path5);
|
|
4256
4184
|
if (problem) warnings.push(problem);
|
|
4257
4185
|
if (!problem || !dropInvalid) kept.push(s);
|
|
4258
4186
|
}
|
|
4259
4187
|
if (strings.length === 0 && raw.length > 0) return void 0;
|
|
4260
4188
|
return kept;
|
|
4261
4189
|
}
|
|
4262
|
-
async function readConfigAt(
|
|
4190
|
+
async function readConfigAt(path5, scope, warnings) {
|
|
4263
4191
|
let raw;
|
|
4264
4192
|
try {
|
|
4265
|
-
raw = await readFile7(
|
|
4193
|
+
raw = await readFile7(path5, "utf8");
|
|
4266
4194
|
} catch (err) {
|
|
4267
4195
|
const code = err.code;
|
|
4268
4196
|
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
4269
4197
|
const msg = err instanceof Error ? err.message : String(err);
|
|
4270
|
-
warnings.push(`${
|
|
4271
|
-
log("warn", "Config file exists but could not be read; ignoring", { path:
|
|
4198
|
+
warnings.push(`${path5}: unreadable (${code ?? msg}) -- file ignored`);
|
|
4199
|
+
log("warn", "Config file exists but could not be read; ignoring", { path: path5, error: msg, code });
|
|
4272
4200
|
return null;
|
|
4273
4201
|
}
|
|
4274
4202
|
let parsed;
|
|
@@ -4276,49 +4204,49 @@ async function readConfigAt(path6, scope, warnings) {
|
|
|
4276
4204
|
parsed = parseJsonc(raw);
|
|
4277
4205
|
} catch (err) {
|
|
4278
4206
|
const msg = err instanceof Error ? err.message : String(err);
|
|
4279
|
-
warnings.push(`${
|
|
4280
|
-
log("warn", "Config file is not valid JSON; ignoring", { path:
|
|
4207
|
+
warnings.push(`${path5}: invalid JSON (${msg}) -- file ignored`);
|
|
4208
|
+
log("warn", "Config file is not valid JSON; ignoring", { path: path5, error: msg });
|
|
4281
4209
|
return null;
|
|
4282
4210
|
}
|
|
4283
4211
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
4284
|
-
warnings.push(`${
|
|
4212
|
+
warnings.push(`${path5}: root must be a JSON object -- file ignored`);
|
|
4285
4213
|
return null;
|
|
4286
4214
|
}
|
|
4287
4215
|
const obj = parsed;
|
|
4288
4216
|
const version = typeof obj.version === "number" ? obj.version : void 0;
|
|
4289
4217
|
if ("version" in obj && version === void 0) {
|
|
4290
4218
|
warnings.push(
|
|
4291
|
-
`${
|
|
4219
|
+
`${path5}: 'version' must be a number (found ${obj.version === null ? "null" : typeof obj.version}) -- ignored; schema-version checks are skipped for this file.`
|
|
4292
4220
|
);
|
|
4293
4221
|
}
|
|
4294
4222
|
if (version !== void 0 && version > CURRENT_SCHEMA_VERSION) {
|
|
4295
4223
|
warnings.push(
|
|
4296
|
-
`${
|
|
4224
|
+
`${path5}: schema version ${version} is newer than this yaw-mcp (${CURRENT_SCHEMA_VERSION}); upgrade with \`npm i -g @yawlabs/mcp@latest\`. Loading best-effort.`
|
|
4297
4225
|
);
|
|
4298
4226
|
}
|
|
4299
4227
|
const staleKeys = DEPRECATED_KEYS.filter((k) => k in obj);
|
|
4300
4228
|
if (staleKeys.length > 0) {
|
|
4301
|
-
warnings.push(deprecatedKeyWarning(
|
|
4302
|
-
log("warn", "Config file carries retired hosted-backend keys", { path:
|
|
4229
|
+
warnings.push(deprecatedKeyWarning(path5, [...staleKeys]));
|
|
4230
|
+
log("warn", "Config file carries retired hosted-backend keys", { path: path5, keys: staleKeys.join(",") });
|
|
4303
4231
|
}
|
|
4304
4232
|
const unknownKeys = Object.keys(obj).filter(
|
|
4305
4233
|
(k) => !KNOWN_CONFIG_KEYS.has(k) && !DEPRECATED_KEYS.includes(k)
|
|
4306
4234
|
);
|
|
4307
4235
|
if (unknownKeys.length > 0) {
|
|
4308
4236
|
warnings.push(
|
|
4309
|
-
`${
|
|
4237
|
+
`${path5}: unknown ${unknownKeys.length === 1 ? "key" : "keys"} ${unknownKeys.map((k) => `'${k}'`).join(", ")} ignored -- known keys: ${[...KNOWN_CONFIG_KEYS].join(", ")}. Full schema: ${CONFIG_SCHEMA_URL}`
|
|
4310
4238
|
);
|
|
4311
4239
|
}
|
|
4312
|
-
const servers = filterStringArray(obj.servers, "servers",
|
|
4313
|
-
const blocked = filterStringArray(obj.blocked, "blocked",
|
|
4314
|
-
const blockedTools = filterStringArray(obj.blockedTools, "blockedTools",
|
|
4240
|
+
const servers = filterStringArray(obj.servers, "servers", path5, warnings);
|
|
4241
|
+
const blocked = filterStringArray(obj.blocked, "blocked", path5, warnings);
|
|
4242
|
+
const blockedTools = filterStringArray(obj.blockedTools, "blockedTools", path5, warnings, toolEntry, true);
|
|
4315
4243
|
const installNudge = typeof obj.installNudge === "boolean" ? obj.installNudge : void 0;
|
|
4316
4244
|
if ("installNudge" in obj && installNudge === void 0) {
|
|
4317
4245
|
warnings.push(
|
|
4318
|
-
`${
|
|
4246
|
+
`${path5}: 'installNudge' must be a boolean (found ${obj.installNudge === null ? "null" : typeof obj.installNudge}) -- ignored; the nudge stays off for this file.`
|
|
4319
4247
|
);
|
|
4320
4248
|
}
|
|
4321
|
-
return { path:
|
|
4249
|
+
return { path: path5, scope, version, servers, blocked, blockedTools, installNudge };
|
|
4322
4250
|
}
|
|
4323
4251
|
function pickServers(files) {
|
|
4324
4252
|
const local = files.find((f) => f.scope === "local")?.servers;
|
|
@@ -4810,7 +4738,7 @@ async function withTransientUpstream(config, use, opts = {}) {
|
|
|
4810
4738
|
}
|
|
4811
4739
|
|
|
4812
4740
|
// src/trust-cmd.ts
|
|
4813
|
-
import { readFile as readFile9, stat as
|
|
4741
|
+
import { readFile as readFile9, stat as stat4 } from "fs/promises";
|
|
4814
4742
|
import { homedir as homedir9 } from "os";
|
|
4815
4743
|
import { basename as basename2, isAbsolute, join as join9, resolve as resolve4 } from "path";
|
|
4816
4744
|
|
|
@@ -5014,13 +4942,13 @@ ${SECRETS_USAGE}`
|
|
|
5014
4942
|
}
|
|
5015
4943
|
return { ok: true, options: opts };
|
|
5016
4944
|
}
|
|
5017
|
-
async function safeLoadVault(
|
|
4945
|
+
async function safeLoadVault(path5, io, json, action) {
|
|
5018
4946
|
try {
|
|
5019
|
-
return { ok: true, vault: await loadVault(
|
|
4947
|
+
return { ok: true, vault: await loadVault(path5) };
|
|
5020
4948
|
} catch (err) {
|
|
5021
4949
|
const raw = err instanceof Error ? err.message : String(err);
|
|
5022
4950
|
const name = err instanceof VaultEntryCorruptError ? err.entryName : void 0;
|
|
5023
|
-
const msg = name ? `secret entry ${name} is corrupt, and every secrets command fails until it is gone. Delete the "${name}" key from ${
|
|
4951
|
+
const msg = name ? `secret entry ${name} is corrupt, and every secrets command fails until it is gone. Delete the "${name}" key from ${path5} by hand (or delete that file to start the vault over), then re-add it with \`yaw-mcp secrets set ${name}\`.` : raw;
|
|
5024
4952
|
if (json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5025
4953
|
`);
|
|
5026
4954
|
else io.err(`yaw-mcp secrets${action ? ` ${action}` : ""}: ${msg}
|
|
@@ -5031,36 +4959,36 @@ async function safeLoadVault(path6, io, json, action) {
|
|
|
5031
4959
|
function isVaultUnreadable(fp) {
|
|
5032
4960
|
return typeof fp === "object" && fp !== null && fp.unreadable === true;
|
|
5033
4961
|
}
|
|
5034
|
-
async function vaultFingerprint(
|
|
4962
|
+
async function vaultFingerprint(path5) {
|
|
5035
4963
|
try {
|
|
5036
|
-
return createHash4("sha256").update(await readFile8(
|
|
4964
|
+
return createHash4("sha256").update(await readFile8(path5)).digest("hex");
|
|
5037
4965
|
} catch (err) {
|
|
5038
4966
|
const e = err;
|
|
5039
4967
|
return e.code === "ENOENT" ? null : { unreadable: true, error: e };
|
|
5040
4968
|
}
|
|
5041
4969
|
}
|
|
5042
|
-
async function vaultChangedSinceLoad(
|
|
5043
|
-
const now = await vaultFingerprint(
|
|
4970
|
+
async function vaultChangedSinceLoad(path5, baseline) {
|
|
4971
|
+
const now = await vaultFingerprint(path5);
|
|
5044
4972
|
if (isVaultUnreadable(now) || isVaultUnreadable(baseline)) return true;
|
|
5045
4973
|
return now !== baseline;
|
|
5046
4974
|
}
|
|
5047
|
-
function vaultUnreadableResult(io, json, action,
|
|
4975
|
+
function vaultUnreadableResult(io, json, action, path5, fp) {
|
|
5048
4976
|
const cause = fp.error.code ?? fp.error.message;
|
|
5049
|
-
const msg = `could not read the vault file at ${
|
|
4977
|
+
const msg = `could not read the vault file at ${path5} (${cause}) -- fix that and re-run. Nothing was written.`;
|
|
5050
4978
|
if (json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5051
4979
|
`);
|
|
5052
4980
|
else io.err(`yaw-mcp secrets${action ? ` ${action}` : ""}: ${msg}
|
|
5053
4981
|
`);
|
|
5054
4982
|
return { exitCode: 1 };
|
|
5055
4983
|
}
|
|
5056
|
-
async function saveVaultOrReport(
|
|
4984
|
+
async function saveVaultOrReport(path5, vault, io, json, action) {
|
|
5057
4985
|
try {
|
|
5058
|
-
await saveVault(
|
|
4986
|
+
await saveVault(path5, vault);
|
|
5059
4987
|
return null;
|
|
5060
4988
|
} catch (err) {
|
|
5061
4989
|
const e = err;
|
|
5062
4990
|
const cause = e.code ?? (err instanceof Error ? err.message : String(err));
|
|
5063
|
-
const msg = `could not write the vault file at ${
|
|
4991
|
+
const msg = `could not write the vault file at ${path5} (${cause}) -- nothing was saved.`;
|
|
5064
4992
|
if (json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5065
4993
|
`);
|
|
5066
4994
|
else io.err(`yaw-mcp secrets${action ? ` ${action}` : ""}: ${msg}
|
|
@@ -5076,10 +5004,10 @@ function vaultChangedResult(io, json, action) {
|
|
|
5076
5004
|
`);
|
|
5077
5005
|
return { exitCode: 1 };
|
|
5078
5006
|
}
|
|
5079
|
-
function unlockErrorMessage(err,
|
|
5007
|
+
function unlockErrorMessage(err, path5) {
|
|
5080
5008
|
const msg = err instanceof Error ? err.message : String(err);
|
|
5081
5009
|
if (msg !== VAULT_CHECK_CORRUPT_ERROR) return msg;
|
|
5082
|
-
return `${msg}. Your entries are intact: delete the "check" key from ${
|
|
5010
|
+
return `${msg}. Your entries are intact: delete the "check" key from ${path5} by hand and re-run -- the next \`yaw-mcp secrets set\` re-stamps it.`;
|
|
5083
5011
|
}
|
|
5084
5012
|
var CANCELLED = /* @__PURE__ */ Symbol("yaw-mcp:passphrase-cancelled");
|
|
5085
5013
|
function cancelledResult(io, json) {
|
|
@@ -5136,7 +5064,7 @@ function warnIfShortPassphrase(io, passphrase, subject, hint) {
|
|
|
5136
5064
|
`
|
|
5137
5065
|
);
|
|
5138
5066
|
}
|
|
5139
|
-
function freshVaultNudge(io,
|
|
5067
|
+
function freshVaultNudge(io, path5) {
|
|
5140
5068
|
const envSet = (process.env.YAW_MCP_VAULT_PASSPHRASE ?? "").length > 0;
|
|
5141
5069
|
const lines = envSet ? [
|
|
5142
5070
|
" YAW_MCP_VAULT_PASSPHRASE is set in THIS shell, but ${secret:NAME} refs are resolved",
|
|
@@ -5149,11 +5077,11 @@ function freshVaultNudge(io, path6) {
|
|
|
5149
5077
|
" passphrase in-session (on clients that support elicitation) or fails to start.",
|
|
5150
5078
|
" `yaw-mcp doctor` reports whether it is set."
|
|
5151
5079
|
];
|
|
5152
|
-
io.err(`yaw-mcp secrets: created the vault at ${
|
|
5080
|
+
io.err(`yaw-mcp secrets: created the vault at ${path5}.
|
|
5153
5081
|
${lines.join("\n")}
|
|
5154
5082
|
`);
|
|
5155
5083
|
}
|
|
5156
|
-
function schemaBehindNotice(io, vault,
|
|
5084
|
+
function schemaBehindNotice(io, vault, path5, json) {
|
|
5157
5085
|
if (vault.version >= SECRETS_SCHEMA_VERSION) return;
|
|
5158
5086
|
if (json) {
|
|
5159
5087
|
io.err(
|
|
@@ -5162,14 +5090,14 @@ function schemaBehindNotice(io, vault, path6, json) {
|
|
|
5162
5090
|
schema: vault.version,
|
|
5163
5091
|
current: SECRETS_SCHEMA_VERSION,
|
|
5164
5092
|
upgrade: "yaw-mcp secrets rotate",
|
|
5165
|
-
path:
|
|
5093
|
+
path: path5
|
|
5166
5094
|
})}
|
|
5167
5095
|
`
|
|
5168
5096
|
);
|
|
5169
5097
|
return;
|
|
5170
5098
|
}
|
|
5171
5099
|
io.err(
|
|
5172
|
-
`yaw-mcp secrets: warning -- the vault at ${
|
|
5100
|
+
`yaw-mcp secrets: warning -- the vault at ${path5} is schema v${vault.version} (this build writes v${SECRETS_SCHEMA_VERSION}); its ciphertexts are not bound to their entry names until \`yaw-mcp secrets rotate\` rewrites it. No other command upgrades the file.
|
|
5173
5101
|
`
|
|
5174
5102
|
);
|
|
5175
5103
|
}
|
|
@@ -5350,7 +5278,7 @@ async function runSecrets(opts, io = {
|
|
|
5350
5278
|
err: createStreamWriter(process.stderr)
|
|
5351
5279
|
}) {
|
|
5352
5280
|
const home = opts.home ?? homedir8();
|
|
5353
|
-
const
|
|
5281
|
+
const path5 = vaultPath(home);
|
|
5354
5282
|
if (opts.action === "lock") {
|
|
5355
5283
|
lock();
|
|
5356
5284
|
if (opts.json) {
|
|
@@ -5372,30 +5300,30 @@ async function runSecrets(opts, io = {
|
|
|
5372
5300
|
return await runSecretsAudit(opts, io);
|
|
5373
5301
|
}
|
|
5374
5302
|
if (opts.action === "list") {
|
|
5375
|
-
const loaded2 = await safeLoadVault(
|
|
5303
|
+
const loaded2 = await safeLoadVault(path5, io, opts.json, "list");
|
|
5376
5304
|
if (!loaded2.ok) return loaded2.result;
|
|
5377
5305
|
const vault2 = loaded2.vault;
|
|
5378
|
-
if (vault2) schemaBehindNotice(io, vault2,
|
|
5306
|
+
if (vault2) schemaBehindNotice(io, vault2, path5, opts.json);
|
|
5379
5307
|
const keys = vault2 ? listKeys(vault2) : [];
|
|
5380
5308
|
if (opts.json) io.out(`${JSON.stringify({ ok: true, vault: vault2 !== null, keys }, null, 2)}
|
|
5381
5309
|
`);
|
|
5382
|
-
else if (!vault2) io.out(`No vault at ${
|
|
5310
|
+
else if (!vault2) io.out(`No vault at ${path5}. Run \`yaw-mcp secrets set <name>\` to create one.
|
|
5383
5311
|
`);
|
|
5384
|
-
else if (keys.length === 0) io.out(`Vault at ${
|
|
5312
|
+
else if (keys.length === 0) io.out(`Vault at ${path5} is empty.
|
|
5385
5313
|
`);
|
|
5386
5314
|
else {
|
|
5387
|
-
io.out(`Vault at ${
|
|
5315
|
+
io.out(`Vault at ${path5}
|
|
5388
5316
|
`);
|
|
5389
5317
|
for (const k of keys) io.out(` ${k}
|
|
5390
5318
|
`);
|
|
5391
5319
|
}
|
|
5392
5320
|
return { exitCode: 0 };
|
|
5393
5321
|
}
|
|
5394
|
-
const baseline = opts.action === "get" ? null : await vaultFingerprint(
|
|
5395
|
-
if (isVaultUnreadable(baseline)) return vaultUnreadableResult(io, opts.json, opts.action ?? "",
|
|
5396
|
-
const loaded = await safeLoadVault(
|
|
5322
|
+
const baseline = opts.action === "get" ? null : await vaultFingerprint(path5);
|
|
5323
|
+
if (isVaultUnreadable(baseline)) return vaultUnreadableResult(io, opts.json, opts.action ?? "", path5, baseline);
|
|
5324
|
+
const loaded = await safeLoadVault(path5, io, opts.json, opts.action ?? "");
|
|
5397
5325
|
if (!loaded.ok) return loaded.result;
|
|
5398
|
-
if (loaded.vault) schemaBehindNotice(io, loaded.vault,
|
|
5326
|
+
if (loaded.vault) schemaBehindNotice(io, loaded.vault, path5, opts.json);
|
|
5399
5327
|
if (opts.action === "get" || opts.action === "remove") {
|
|
5400
5328
|
const name = opts.name;
|
|
5401
5329
|
if (!loaded.vault || !Object.hasOwn(loaded.vault.entries, name)) {
|
|
@@ -5449,7 +5377,7 @@ async function runSecrets(opts, io = {
|
|
|
5449
5377
|
try {
|
|
5450
5378
|
key = await unlock(vault, passphrase);
|
|
5451
5379
|
} catch (err) {
|
|
5452
|
-
const msg = unlockErrorMessage(err,
|
|
5380
|
+
const msg = unlockErrorMessage(err, path5);
|
|
5453
5381
|
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5454
5382
|
`);
|
|
5455
5383
|
else io.err(`yaw-mcp secrets: ${msg}
|
|
@@ -5491,8 +5419,8 @@ async function runSecrets(opts, io = {
|
|
|
5491
5419
|
`);
|
|
5492
5420
|
return { exitCode: 1 };
|
|
5493
5421
|
}
|
|
5494
|
-
if (await vaultChangedSinceLoad(
|
|
5495
|
-
const failed = await saveVaultOrReport(
|
|
5422
|
+
if (await vaultChangedSinceLoad(path5, baseline)) return vaultChangedResult(io, opts.json, "set");
|
|
5423
|
+
const failed = await saveVaultOrReport(path5, vault, io, opts.json, "set");
|
|
5496
5424
|
if (failed) return failed;
|
|
5497
5425
|
if (opts.json) io.out(`${JSON.stringify({ ok: true, name, fresh_vault: isFresh, replaced: replacing })}
|
|
5498
5426
|
`);
|
|
@@ -5500,7 +5428,7 @@ async function runSecrets(opts, io = {
|
|
|
5500
5428
|
`);
|
|
5501
5429
|
else io.out(`${isFresh ? "Created vault and " : ""}Stored secret "${name}".
|
|
5502
5430
|
`);
|
|
5503
|
-
if (isFresh) freshVaultNudge(io,
|
|
5431
|
+
if (isFresh) freshVaultNudge(io, path5);
|
|
5504
5432
|
return { exitCode: 0 };
|
|
5505
5433
|
}
|
|
5506
5434
|
if (opts.action === "get") {
|
|
@@ -5532,9 +5460,9 @@ async function runSecrets(opts, io = {
|
|
|
5532
5460
|
}
|
|
5533
5461
|
if (opts.action === "remove") {
|
|
5534
5462
|
const name = opts.name;
|
|
5535
|
-
if (await vaultChangedSinceLoad(
|
|
5463
|
+
if (await vaultChangedSinceLoad(path5, baseline)) return vaultChangedResult(io, opts.json, "remove");
|
|
5536
5464
|
vault = removeSecret(vault, name);
|
|
5537
|
-
const failed = await saveVaultOrReport(
|
|
5465
|
+
const failed = await saveVaultOrReport(path5, vault, io, opts.json, "remove");
|
|
5538
5466
|
if (failed) return failed;
|
|
5539
5467
|
if (opts.json) io.out(`${JSON.stringify({ ok: true, removed: name })}
|
|
5540
5468
|
`);
|
|
@@ -5548,14 +5476,14 @@ async function runSecrets(opts, io = {
|
|
|
5548
5476
|
}
|
|
5549
5477
|
async function runSecretsRotate(opts, io) {
|
|
5550
5478
|
const home = opts.home ?? homedir8();
|
|
5551
|
-
const
|
|
5552
|
-
const baseline = await vaultFingerprint(
|
|
5553
|
-
if (isVaultUnreadable(baseline)) return vaultUnreadableResult(io, opts.json, "rotate",
|
|
5554
|
-
const loaded = await safeLoadVault(
|
|
5479
|
+
const path5 = vaultPath(home);
|
|
5480
|
+
const baseline = await vaultFingerprint(path5);
|
|
5481
|
+
if (isVaultUnreadable(baseline)) return vaultUnreadableResult(io, opts.json, "rotate", path5, baseline);
|
|
5482
|
+
const loaded = await safeLoadVault(path5, io, opts.json, "rotate");
|
|
5555
5483
|
if (!loaded.ok) return loaded.result;
|
|
5556
5484
|
const vault = loaded.vault;
|
|
5557
5485
|
if (!vault) {
|
|
5558
|
-
const msg = `No vault at ${
|
|
5486
|
+
const msg = `No vault at ${path5} to rotate. Run \`yaw-mcp secrets set <name>\` first.`;
|
|
5559
5487
|
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5560
5488
|
`);
|
|
5561
5489
|
else io.err(`yaw-mcp secrets rotate: ${msg}
|
|
@@ -5576,7 +5504,7 @@ async function runSecretsRotate(opts, io) {
|
|
|
5576
5504
|
try {
|
|
5577
5505
|
oldKey = await unlock(vault, currentPassphrase);
|
|
5578
5506
|
} catch (err) {
|
|
5579
|
-
const msg = unlockErrorMessage(err,
|
|
5507
|
+
const msg = unlockErrorMessage(err, path5);
|
|
5580
5508
|
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5581
5509
|
`);
|
|
5582
5510
|
else io.err(`yaw-mcp secrets rotate: ${msg}
|
|
@@ -5609,11 +5537,11 @@ async function runSecretsRotate(opts, io) {
|
|
|
5609
5537
|
lock();
|
|
5610
5538
|
return { exitCode: 1 };
|
|
5611
5539
|
}
|
|
5612
|
-
if (await vaultChangedSinceLoad(
|
|
5540
|
+
if (await vaultChangedSinceLoad(path5, baseline)) {
|
|
5613
5541
|
lock();
|
|
5614
5542
|
return vaultChangedResult(io, opts.json, "rotate");
|
|
5615
5543
|
}
|
|
5616
|
-
const failed = await saveVaultOrReport(
|
|
5544
|
+
const failed = await saveVaultOrReport(path5, rotated, io, opts.json, "rotate");
|
|
5617
5545
|
if (failed) {
|
|
5618
5546
|
lock();
|
|
5619
5547
|
return failed;
|
|
@@ -5800,10 +5728,10 @@ async function runTrustGrant(opts) {
|
|
|
5800
5728
|
);
|
|
5801
5729
|
return { exitCode: 1 };
|
|
5802
5730
|
}
|
|
5803
|
-
const
|
|
5731
|
+
const path5 = probe.path;
|
|
5804
5732
|
const raw = probe.raw;
|
|
5805
5733
|
if (probe.status === "trusted") {
|
|
5806
|
-
print(`Already approved: ${displaySafe(
|
|
5734
|
+
print(`Already approved: ${displaySafe(path5)}`);
|
|
5807
5735
|
print(` contents unchanged since approval (sha256 ${probe.sha256}) -- nothing to do.`);
|
|
5808
5736
|
return { exitCode: 0 };
|
|
5809
5737
|
}
|
|
@@ -5819,16 +5747,16 @@ async function runTrustGrant(opts) {
|
|
|
5819
5747
|
return { exitCode: 1 };
|
|
5820
5748
|
}
|
|
5821
5749
|
}
|
|
5822
|
-
const preview = previewBundlesContent(
|
|
5750
|
+
const preview = previewBundlesContent(path5, raw);
|
|
5823
5751
|
if (!preview.ok) {
|
|
5824
|
-
printErr(`yaw-mcp trust: ${displaySafe(
|
|
5752
|
+
printErr(`yaw-mcp trust: ${displaySafe(path5)} is not a usable bundles.json, so there is nothing to review:`);
|
|
5825
5753
|
for (const w of preview.warnings) printErr(` ! ${displaySafe(w)}`);
|
|
5826
5754
|
printErr("Fix the file, then re-run `yaw-mcp trust`.");
|
|
5827
5755
|
return { exitCode: 1 };
|
|
5828
5756
|
}
|
|
5829
5757
|
const serverCount = preview.servers.length;
|
|
5830
5758
|
print("");
|
|
5831
|
-
print(` Project file: ${displaySafe(
|
|
5759
|
+
print(` Project file: ${displaySafe(path5)}`);
|
|
5832
5760
|
print(` SHA-256: ${probe.sha256}`);
|
|
5833
5761
|
print(
|
|
5834
5762
|
` Status: ${probe.status === "changed" ? "CHANGED since you approved it" : probe.status === "store-unreadable" ? `trust store unreadable (${displaySafe(probe.storePath)})` : "never approved"}`
|
|
@@ -5879,22 +5807,22 @@ async function runTrustGrant(opts) {
|
|
|
5879
5807
|
}
|
|
5880
5808
|
let confirmBytes;
|
|
5881
5809
|
try {
|
|
5882
|
-
confirmBytes = await readFile9(
|
|
5810
|
+
confirmBytes = await readFile9(path5);
|
|
5883
5811
|
} catch (e) {
|
|
5884
5812
|
printErr(
|
|
5885
|
-
`yaw-mcp trust: ${displaySafe(
|
|
5813
|
+
`yaw-mcp trust: ${displaySafe(path5)} could not be re-read before approving (${e.message}). Nothing approved.`
|
|
5886
5814
|
);
|
|
5887
5815
|
return { exitCode: 1 };
|
|
5888
5816
|
}
|
|
5889
5817
|
if (hashTrustContent(confirmBytes) !== probe.sha256) {
|
|
5890
5818
|
printErr(
|
|
5891
|
-
`yaw-mcp trust: ${displaySafe(
|
|
5819
|
+
`yaw-mcp trust: ${displaySafe(path5)} changed while you were reviewing it. Nothing approved -- re-run \`yaw-mcp trust\` to see the new contents.`
|
|
5892
5820
|
);
|
|
5893
5821
|
return { exitCode: 1 };
|
|
5894
5822
|
}
|
|
5895
5823
|
let granted;
|
|
5896
5824
|
try {
|
|
5897
|
-
granted = await grantTrust(
|
|
5825
|
+
granted = await grantTrust(path5, raw, { home, now: opts.now });
|
|
5898
5826
|
} catch (e) {
|
|
5899
5827
|
if (e instanceof TrustStoreUnreadableError) {
|
|
5900
5828
|
printStoreRefusal(printErr, { storePath: e.storePath, reason: e.reason, code: e.code, kind: e.kind });
|
|
@@ -5907,7 +5835,7 @@ async function runTrustGrant(opts) {
|
|
|
5907
5835
|
`Note: the previous trust store at ${displaySafe(granted.storePath)} was not valid JSON and has been replaced -- any other project you had approved must be approved again.`
|
|
5908
5836
|
);
|
|
5909
5837
|
}
|
|
5910
|
-
print(`Approved ${displaySafe(
|
|
5838
|
+
print(`Approved ${displaySafe(path5)}`);
|
|
5911
5839
|
print(` pinned to sha256 ${granted.record.sha256}`);
|
|
5912
5840
|
print(` recorded in ${displaySafe(granted.storePath)}`);
|
|
5913
5841
|
print(" PINNED: the exact bytes of that file -- any later edit to it re-requires approval.");
|
|
@@ -6119,9 +6047,9 @@ async function runTrustList(opts) {
|
|
|
6119
6047
|
}
|
|
6120
6048
|
return { exitCode: 0 };
|
|
6121
6049
|
}
|
|
6122
|
-
async function classifyRecord(
|
|
6050
|
+
async function classifyRecord(path5, sha256) {
|
|
6123
6051
|
try {
|
|
6124
|
-
const raw = await readFile9(
|
|
6052
|
+
const raw = await readFile9(path5);
|
|
6125
6053
|
return hashTrustContent(raw) === sha256 ? "ok" : "stale (content changed)";
|
|
6126
6054
|
} catch (e) {
|
|
6127
6055
|
const code = e.code;
|
|
@@ -6131,7 +6059,7 @@ async function classifyRecord(path6, sha256) {
|
|
|
6131
6059
|
async function resolveRevokeTarget(target) {
|
|
6132
6060
|
let isDir;
|
|
6133
6061
|
try {
|
|
6134
|
-
isDir = (await
|
|
6062
|
+
isDir = (await stat4(target)).isDirectory();
|
|
6135
6063
|
} catch {
|
|
6136
6064
|
return target;
|
|
6137
6065
|
}
|
|
@@ -7108,8 +7036,8 @@ function formatShadowLine(server) {
|
|
|
7108
7036
|
import { createReadStream } from "fs";
|
|
7109
7037
|
var GUIDE_READ_TIMEOUT_MS = 1e3;
|
|
7110
7038
|
var MAX_GUIDE_BYTES = 256 * 1024;
|
|
7111
|
-
async function readCapped(
|
|
7112
|
-
const stream = createReadStream(
|
|
7039
|
+
async function readCapped(path5, signal) {
|
|
7040
|
+
const stream = createReadStream(path5, { start: 0, end: MAX_GUIDE_BYTES, signal });
|
|
7113
7041
|
const chunks = [];
|
|
7114
7042
|
let total = 0;
|
|
7115
7043
|
for await (const chunk of stream) {
|
|
@@ -7122,20 +7050,20 @@ async function readCapped(path6, signal) {
|
|
|
7122
7050
|
truncated: total > MAX_GUIDE_BYTES
|
|
7123
7051
|
};
|
|
7124
7052
|
}
|
|
7125
|
-
async function readGuide(
|
|
7053
|
+
async function readGuide(path5, scope) {
|
|
7126
7054
|
let read;
|
|
7127
7055
|
const ac = new AbortController();
|
|
7128
7056
|
const timer = setTimeout(() => ac.abort(new Error("guide read timeout")), GUIDE_READ_TIMEOUT_MS);
|
|
7129
7057
|
try {
|
|
7130
|
-
read = await readCapped(
|
|
7058
|
+
read = await readCapped(path5, ac.signal);
|
|
7131
7059
|
} catch (err) {
|
|
7132
7060
|
const code = err.code;
|
|
7133
7061
|
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
7134
7062
|
if (code === "ABORT_ERR") {
|
|
7135
|
-
log("warn", "Guide read timed out", { path:
|
|
7063
|
+
log("warn", "Guide read timed out", { path: path5 });
|
|
7136
7064
|
} else {
|
|
7137
7065
|
log("warn", "Guide exists but could not be read; serving no guide", {
|
|
7138
|
-
path:
|
|
7066
|
+
path: path5,
|
|
7139
7067
|
error: err instanceof Error ? err.message : String(err)
|
|
7140
7068
|
});
|
|
7141
7069
|
}
|
|
@@ -7145,7 +7073,7 @@ async function readGuide(path6, scope) {
|
|
|
7145
7073
|
}
|
|
7146
7074
|
if (read.truncated) {
|
|
7147
7075
|
log("warn", "Guide is larger than the size cap; serving the leading portion only", {
|
|
7148
|
-
path:
|
|
7076
|
+
path: path5,
|
|
7149
7077
|
maxBytes: MAX_GUIDE_BYTES
|
|
7150
7078
|
});
|
|
7151
7079
|
}
|
|
@@ -7153,7 +7081,7 @@ async function readGuide(path6, scope) {
|
|
|
7153
7081
|
if (content.length === 0) {
|
|
7154
7082
|
return null;
|
|
7155
7083
|
}
|
|
7156
|
-
return { scope, path:
|
|
7084
|
+
return { scope, path: path5, content };
|
|
7157
7085
|
}
|
|
7158
7086
|
async function loadUserGuide(home) {
|
|
7159
7087
|
const p = guidePath(userConfigDir(home));
|
|
@@ -7222,7 +7150,7 @@ function renderActiveServersSection(activeServers) {
|
|
|
7222
7150
|
|
|
7223
7151
|
// src/persistence.ts
|
|
7224
7152
|
import { readFile as readFile10 } from "fs/promises";
|
|
7225
|
-
import
|
|
7153
|
+
import path2 from "path";
|
|
7226
7154
|
var STATE_SCHEMA_VERSION = 2;
|
|
7227
7155
|
var STATE_FILENAME = "state.json";
|
|
7228
7156
|
var DISABLE_PERSISTENCE_ENV = "YAW_MCP_DISABLE_PERSISTENCE";
|
|
@@ -7240,7 +7168,7 @@ var TOOLCACHE_MAX_TOOLS_PER_NAMESPACE = 512;
|
|
|
7240
7168
|
var TOOLCACHE_MAX_DESCRIPTION_CHARS = 2e3;
|
|
7241
7169
|
var TOOLCACHE_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7242
7170
|
function statePath(configDir = userConfigDir()) {
|
|
7243
|
-
return
|
|
7171
|
+
return path2.join(configDir, STATE_FILENAME);
|
|
7244
7172
|
}
|
|
7245
7173
|
function emptyState() {
|
|
7246
7174
|
return { version: STATE_SCHEMA_VERSION, savedAt: 0, learning: {}, packHistory: [], toolCache: {} };
|
|
@@ -7942,9 +7870,9 @@ function defaultReadState(home) {
|
|
|
7942
7870
|
async function defaultWriteState(home, patch) {
|
|
7943
7871
|
if (inUnitTest()) return;
|
|
7944
7872
|
try {
|
|
7945
|
-
const
|
|
7873
|
+
const path5 = sidecarRefreshStatePath(home);
|
|
7946
7874
|
const next = mergeSidecarRefreshState(defaultReadState(home), patch);
|
|
7947
|
-
await atomicWriteFile(
|
|
7875
|
+
await atomicWriteFile(path5, `${JSON.stringify(next, null, 2)}
|
|
7948
7876
|
`);
|
|
7949
7877
|
} catch (err) {
|
|
7950
7878
|
log("debug", "sidecar-refresh: failed to record the check timestamp", {
|
|
@@ -8065,7 +7993,7 @@ async function maybeRefreshSidecars(deps = {}) {
|
|
|
8065
7993
|
// src/try-cmd.ts
|
|
8066
7994
|
import { createHash as createHash5 } from "crypto";
|
|
8067
7995
|
import { existsSync as existsSync5 } from "fs";
|
|
8068
|
-
import { chmod as
|
|
7996
|
+
import { chmod as chmod5, mkdir as mkdir4, readdir, readFile as readFile12, unlink } from "fs/promises";
|
|
8069
7997
|
import { homedir as homedir14 } from "os";
|
|
8070
7998
|
import { join as join13, resolve as resolve6 } from "path";
|
|
8071
7999
|
import { createInterface as createInterface2 } from "readline/promises";
|
|
@@ -8278,7 +8206,7 @@ function normalizeCatalogGrade(raw) {
|
|
|
8278
8206
|
}
|
|
8279
8207
|
|
|
8280
8208
|
// src/install-cmd.ts
|
|
8281
|
-
import { readFile as readFile11, stat as
|
|
8209
|
+
import { readFile as readFile11, stat as stat5 } from "fs/promises";
|
|
8282
8210
|
import { homedir as homedir13 } from "os";
|
|
8283
8211
|
import { dirname as dirname7, join as join12, resolve as resolve5, sep } from "path";
|
|
8284
8212
|
import { createInterface } from "readline/promises";
|
|
@@ -8375,11 +8303,11 @@ var USAGE = (
|
|
|
8375
8303
|
|
|
8376
8304
|
When a different \`` + ENTRY_NAME + "` entry is already in the config, install asks on a TTY\n and refuses without one, showing what differs (exit 2; a real failure, such\n as a malformed config, exits 1). Under --all the run exits 2 when every\n client that did not succeed was refused this way, and 1 if any one failed.\n Answer up front with:\n --force Overwrite whatever is there, env included: the new entry keeps\n none of the old entry's env, and install names each key it drops.\n --repair Replace an entry that has DRIFTED from what install writes,\n keeping the old entry's string-valued env; a no-op when it\n already matches, so a fixup script can run it unconditionally.\n --skip Leave the existing entry untouched and exit 0.\n --dry-run Print the entry (and any permissions patch) that WOULD be\n written, and exit 0 without touching a file.\n\n Deprecated (accepted, ignored, warns): --token <mcp_pat_...>, --no-yaw-mcp-config.\n yaw-mcp is local-only -- it stores no token and never writes ~/.yaw-mcp/config.json.\n Configure servers in ~/.yaw-mcp/bundles.json (see `yaw-mcp add <slug>`)."
|
|
8377
8305
|
);
|
|
8378
|
-
function describeUnreadableConfig(cmd,
|
|
8306
|
+
function describeUnreadableConfig(cmd, path5, err) {
|
|
8379
8307
|
if (err.code === "EISDIR") {
|
|
8380
|
-
return `yaw-mcp ${cmd}: ${
|
|
8308
|
+
return `yaw-mcp ${cmd}: ${path5} is a directory, not a file -- move or remove it, then re-run.`;
|
|
8381
8309
|
}
|
|
8382
|
-
return `yaw-mcp ${cmd}: cannot read ${
|
|
8310
|
+
return `yaw-mcp ${cmd}: cannot read ${path5}: ${err.message}`;
|
|
8383
8311
|
}
|
|
8384
8312
|
function clientUnavailableMessage(cmd, target, os, genericFix) {
|
|
8385
8313
|
const reason = target.notConfigurableOn?.[os];
|
|
@@ -8823,8 +8751,11 @@ permissions.allow += ${JSON.stringify(settingsPatch.added)}`);
|
|
|
8823
8751
|
}
|
|
8824
8752
|
}
|
|
8825
8753
|
const freshNote2 = yawFreshPaneNote({
|
|
8826
|
-
|
|
8754
|
+
grantPatches: settingsPatches,
|
|
8827
8755
|
target,
|
|
8756
|
+
scope,
|
|
8757
|
+
projectDir,
|
|
8758
|
+
yawMode: opts.clientEnv?.yawMode,
|
|
8828
8759
|
claudeConfigDir: opts.claudeConfigDir,
|
|
8829
8760
|
entryFile: resolved.absolute,
|
|
8830
8761
|
wrote: [
|
|
@@ -8914,8 +8845,11 @@ permissions.allow += ${JSON.stringify(settingsPatch.added)}`);
|
|
|
8914
8845
|
}
|
|
8915
8846
|
}
|
|
8916
8847
|
const freshNote = yawFreshPaneNote({
|
|
8917
|
-
|
|
8848
|
+
grantPatches: settingsPatches,
|
|
8918
8849
|
target,
|
|
8850
|
+
scope,
|
|
8851
|
+
projectDir,
|
|
8852
|
+
yawMode: opts.clientEnv?.yawMode,
|
|
8919
8853
|
claudeConfigDir: opts.claudeConfigDir,
|
|
8920
8854
|
entryFile: resolved.absolute,
|
|
8921
8855
|
wrote: written
|
|
@@ -8977,19 +8911,22 @@ async function prepareGrantPatches(args) {
|
|
|
8977
8911
|
}
|
|
8978
8912
|
var YAW_HOME_GRANT_REASON = " -- a Yaw Mode pane's own settings.json does not outlive the pane";
|
|
8979
8913
|
function yawFreshPaneNote(args) {
|
|
8980
|
-
const overlayPatch = args.grant.patches.find((p) => !p.yawHome);
|
|
8981
8914
|
const cfg = args.claudeConfigDir;
|
|
8982
|
-
if (
|
|
8983
|
-
const
|
|
8984
|
-
const
|
|
8915
|
+
if (cfg === void 0 || yawModeOverlay({ yawMode: args.yawMode, claudeConfigDir: cfg }) !== "fresh") return null;
|
|
8916
|
+
const inOverlay = (file) => samePathKey(file).startsWith(`${samePathKey(cfg)}${sep}`);
|
|
8917
|
+
const overlayPatch = args.grantPatches.find((p) => !p.yawHome && inOverlay(p.path));
|
|
8918
|
+
const entryInOverlay = inOverlay(args.entryFile);
|
|
8919
|
+
const grantWritten = overlayPatch !== void 0 && args.wrote.includes(overlayPatch.path);
|
|
8985
8920
|
const entryWritten = entryInOverlay && args.wrote.includes(args.entryFile);
|
|
8986
8921
|
if (!grantWritten && !entryWritten) return null;
|
|
8987
8922
|
const { label, clientId } = args.target;
|
|
8988
|
-
const
|
|
8989
|
-
|
|
8923
|
+
const projectFlag = args.projectDir === void 0 ? "" : ` --project-dir ${quoteArgForDisplay(args.projectDir) ?? args.projectDir}`;
|
|
8924
|
+
const scopeFlags = args.scope === "user" ? "" : ` --scope ${args.scope}${projectFlag}`;
|
|
8925
|
+
const again = `Run \`yaw-mcp install ${clientId}${scopeFlags}\` from a normal shell to keep`;
|
|
8926
|
+
if (!entryInOverlay && overlayPatch !== void 0) {
|
|
8990
8927
|
return `Note: a fresh Yaw Mode pane does not keep its settings.json, so the ${CLAUDE_CODE_ALLOW_PATTERN} grant in ${overlayPatch.path} goes when this pane closes. ${again} it.`;
|
|
8991
8928
|
}
|
|
8992
|
-
return overlayPatch.malformed ? `Note: a fresh Yaw Mode pane does not keep its config dir, so the ${label} entry in ${args.entryFile} goes when this pane closes. ${again} it.` : `Note: a fresh Yaw Mode pane does not keep its config dir, so the ${label} entry in ${args.entryFile} and the ${CLAUDE_CODE_ALLOW_PATTERN} grant in ${overlayPatch.path} go when this pane closes. ${again} them.`;
|
|
8929
|
+
return overlayPatch === void 0 || overlayPatch.malformed ? `Note: a fresh Yaw Mode pane does not keep its config dir, so the ${label} entry in ${args.entryFile} goes when this pane closes. ${again} it.` : `Note: a fresh Yaw Mode pane does not keep its config dir, so the ${label} entry in ${args.entryFile} and the ${CLAUDE_CODE_ALLOW_PATTERN} grant in ${overlayPatch.path} go when this pane closes. ${again} them.`;
|
|
8993
8930
|
}
|
|
8994
8931
|
async function staleProgramWarning(opts) {
|
|
8995
8932
|
const probe = resolveProgramProbe(opts);
|
|
@@ -9002,9 +8939,9 @@ async function staleProgramWarning(opts) {
|
|
|
9002
8939
|
}
|
|
9003
8940
|
return probe.markers.some((marker) => bytes.includes(marker)) ? null : probe.warning;
|
|
9004
8941
|
}
|
|
9005
|
-
async function fileFingerprint(
|
|
8942
|
+
async function fileFingerprint(path5) {
|
|
9006
8943
|
try {
|
|
9007
|
-
const st = await
|
|
8944
|
+
const st = await stat5(path5);
|
|
9008
8945
|
return { mtimeMs: st.mtimeMs, size: st.size };
|
|
9009
8946
|
} catch {
|
|
9010
8947
|
return null;
|
|
@@ -9014,14 +8951,14 @@ function sameFingerprint(a, b) {
|
|
|
9014
8951
|
if (a === null || b === null) return a === b;
|
|
9015
8952
|
return a.mtimeMs === b.mtimeMs && a.size === b.size;
|
|
9016
8953
|
}
|
|
9017
|
-
async function promptCollision(
|
|
8954
|
+
async function promptCollision(path5, diff, io, keptEnvKeys) {
|
|
9018
8955
|
const stdin = io?.stdin ?? process.stdin;
|
|
9019
8956
|
const stdout = io?.stdout ?? process.stdout;
|
|
9020
8957
|
const rl = createInterface({ input: stdin, output: stdout, terminal: io?.terminal });
|
|
9021
8958
|
try {
|
|
9022
8959
|
const raw = await questionOrEmpty(
|
|
9023
8960
|
rl,
|
|
9024
|
-
`${
|
|
8961
|
+
`${path5} already has an "${ENTRY_NAME}" entry that differs from the one install would write:
|
|
9025
8962
|
${indentDiff(diff, " ")}
|
|
9026
8963
|
[o]verwrite${keptEnvKeys.length > 0 ? ` (keeping env: ${keptEnvKeys.join(", ")})` : ""}, [s]kip, or [a]bort? (default: skip) `
|
|
9027
8964
|
);
|
|
@@ -9451,8 +9388,8 @@ async function runInstallAll(opts, log2, err, messages) {
|
|
|
9451
9388
|
// client (vscode) into the run.
|
|
9452
9389
|
projectDir: plan.usesProjectDir ? opts.projectDir : void 0
|
|
9453
9390
|
});
|
|
9454
|
-
for (const
|
|
9455
|
-
for (const
|
|
9391
|
+
for (const path5 of result.written) if (!aggregateWritten.includes(path5)) aggregateWritten.push(path5);
|
|
9392
|
+
for (const path5 of result.wouldWrite) if (!aggregateWouldWrite.includes(path5)) aggregateWouldWrite.push(path5);
|
|
9456
9393
|
messages.push(...result.messages);
|
|
9457
9394
|
if (result.exitCode === 0) succeeded += 1;
|
|
9458
9395
|
else if (result.collisionRefused) refusedClients.push(plan.clientId);
|
|
@@ -9861,7 +9798,7 @@ ${UNINSTALL_USAGE}`);
|
|
|
9861
9798
|
}
|
|
9862
9799
|
if (holder !== null) {
|
|
9863
9800
|
log2(
|
|
9864
|
-
holder.unreadable ? `Keeping ${CLAUDE_CODE_ALLOW_PATTERN} in ${settingsPatch.path}: could not read ${holder.file} to tell whether ${holder.label} (${holder.scope}) still uses it.` : carried ? `Keeping ${CLAUDE_CODE_ALLOW_PATTERN} in ${settingsPatch.path}: ${holder.label} (${holder.scope}) still launches yaw-mcp from ${holder.file}, which Yaw
|
|
9801
|
+
holder.unreadable ? `Keeping ${CLAUDE_CODE_ALLOW_PATTERN} in ${settingsPatch.path}: could not read ${holder.file} to tell whether ${holder.label} (${holder.scope}) still uses it.` : carried ? `Keeping ${CLAUDE_CODE_ALLOW_PATTERN} in ${settingsPatch.path}: ${holder.label} (${holder.scope}) still launches yaw-mcp from ${holder.file}, which Yaw may carry home when the pane closes.` : `Keeping ${CLAUDE_CODE_ALLOW_PATTERN} in ${settingsPatch.path}: ${holder.label} (${holder.scope}) still launches yaw-mcp from ${holder.file} and reads that grant.`
|
|
9865
9802
|
);
|
|
9866
9803
|
continue;
|
|
9867
9804
|
}
|
|
@@ -10573,7 +10510,7 @@ async function runTry(opts) {
|
|
|
10573
10510
|
}
|
|
10574
10511
|
const written = [];
|
|
10575
10512
|
try {
|
|
10576
|
-
await
|
|
10513
|
+
await mkdir4(trialsDir(home), { recursive: true });
|
|
10577
10514
|
await atomicWriteFile(trialMarkerPath(slug, home), markerJson);
|
|
10578
10515
|
written.push(trialMarkerPath(slug, home));
|
|
10579
10516
|
} catch (e) {
|
|
@@ -10586,7 +10523,7 @@ async function runTry(opts) {
|
|
|
10586
10523
|
written.push(resolved.absolute);
|
|
10587
10524
|
if (tightenPerms) {
|
|
10588
10525
|
try {
|
|
10589
|
-
await
|
|
10526
|
+
await chmod5(resolved.absolute, 384);
|
|
10590
10527
|
} catch {
|
|
10591
10528
|
}
|
|
10592
10529
|
}
|
|
@@ -10595,7 +10532,7 @@ async function runTry(opts) {
|
|
|
10595
10532
|
if (previousRead !== null && (!peelsPrevious || previousPeelFailedWhileTrusted)) {
|
|
10596
10533
|
await atomicWriteFile(trialMarkerPath(slug, home), previousRead.raw).catch(() => void 0);
|
|
10597
10534
|
} else {
|
|
10598
|
-
await
|
|
10535
|
+
await unlink(trialMarkerPath(slug, home)).catch(() => void 0);
|
|
10599
10536
|
}
|
|
10600
10537
|
return { exitCode: 1, written: [] };
|
|
10601
10538
|
}
|
|
@@ -10727,7 +10664,7 @@ async function runTryCleanup(opts) {
|
|
|
10727
10664
|
);
|
|
10728
10665
|
}
|
|
10729
10666
|
try {
|
|
10730
|
-
await
|
|
10667
|
+
await unlink(markerPath);
|
|
10731
10668
|
} catch (e) {
|
|
10732
10669
|
printErr(`yaw-mcp try-cleanup: couldn't delete marker ${markerPath} (${e.message}).`);
|
|
10733
10670
|
return { exitCode: 1, written: [] };
|
|
@@ -10758,9 +10695,9 @@ async function scanTrials(opts = {}) {
|
|
|
10758
10695
|
}
|
|
10759
10696
|
for (const filename of entries) {
|
|
10760
10697
|
if (!filename.endsWith(".json")) continue;
|
|
10761
|
-
const
|
|
10698
|
+
const path5 = join13(dir, filename);
|
|
10762
10699
|
try {
|
|
10763
|
-
const raw = await readFile12(
|
|
10700
|
+
const raw = await readFile12(path5, "utf8");
|
|
10764
10701
|
const parsed = JSON.parse(raw);
|
|
10765
10702
|
if (!parsed || typeof parsed !== "object" || typeof parsed.slug !== "string" || typeof parsed.expiresAt !== "number" || typeof parsed.clientPath !== "string" || // Not consumed by the peel, but doctor PRINTS it verbatim ("demo ->
|
|
10766
10703
|
// claude-code (expires in 42m)"), so a hand-rolled marker without it
|
|
@@ -10772,16 +10709,16 @@ async function scanTrials(opts = {}) {
|
|
|
10772
10709
|
// understand -- is surfaced as malformed for the user rather than
|
|
10773
10710
|
// acted on.
|
|
10774
10711
|
rejectUntrustedMarker(parsed) !== null) {
|
|
10775
|
-
result.malformed.push(
|
|
10712
|
+
result.malformed.push(path5);
|
|
10776
10713
|
continue;
|
|
10777
10714
|
}
|
|
10778
10715
|
const msUntilExpiry = parsed.expiresAt - now;
|
|
10779
10716
|
const expired = msUntilExpiry <= 0;
|
|
10780
|
-
const entry = { marker: parsed, path:
|
|
10717
|
+
const entry = { marker: parsed, path: path5, msUntilExpiry, expired };
|
|
10781
10718
|
if (expired) result.expired.push(entry);
|
|
10782
10719
|
else result.live.push(entry);
|
|
10783
10720
|
} catch {
|
|
10784
|
-
result.malformed.push(
|
|
10721
|
+
result.malformed.push(path5);
|
|
10785
10722
|
}
|
|
10786
10723
|
}
|
|
10787
10724
|
return result;
|
|
@@ -10792,7 +10729,7 @@ async function gcExpiredTrials(opts) {
|
|
|
10792
10729
|
if (scan.expired.length === 0) return { cleared: 0, failed: 0, failures: [] };
|
|
10793
10730
|
let cleared = 0;
|
|
10794
10731
|
const failures = [];
|
|
10795
|
-
for (const { marker, path:
|
|
10732
|
+
for (const { marker, path: path5 } of scan.expired) {
|
|
10796
10733
|
let stage = "peel";
|
|
10797
10734
|
try {
|
|
10798
10735
|
const outcome = await peelEntryFromConfig(
|
|
@@ -10806,19 +10743,19 @@ async function gcExpiredTrials(opts) {
|
|
|
10806
10743
|
stage = "replaced";
|
|
10807
10744
|
let markerRemoved = true;
|
|
10808
10745
|
try {
|
|
10809
|
-
await
|
|
10746
|
+
await unlink(path5);
|
|
10810
10747
|
} catch {
|
|
10811
10748
|
markerRemoved = false;
|
|
10812
10749
|
}
|
|
10813
10750
|
failures.push({
|
|
10814
10751
|
slug: marker.slug,
|
|
10815
10752
|
clientPath: marker.clientPath,
|
|
10816
|
-
markerPath:
|
|
10753
|
+
markerPath: path5,
|
|
10817
10754
|
stage,
|
|
10818
10755
|
// The WHOLE sentence, because the two cases differ in what actually
|
|
10819
10756
|
// happened -- see trialGcFailureWarning, which prints this verbatim
|
|
10820
10757
|
// for stage "replaced" rather than adding a tail that could contradict it.
|
|
10821
|
-
error: markerRemoved ? `${marker.entryName} in ${marker.clientPath} was replaced since the trial wrote it, so it was left in place; the expired trial marker was deleted -- remove that entry by hand if you do not want it` : `${marker.entryName} in ${marker.clientPath} was replaced since the trial wrote it, so it was left in place; its marker ${
|
|
10758
|
+
error: markerRemoved ? `${marker.entryName} in ${marker.clientPath} was replaced since the trial wrote it, so it was left in place; the expired trial marker was deleted -- remove that entry by hand if you do not want it` : `${marker.entryName} in ${marker.clientPath} was replaced since the trial wrote it, so it was left in place; its marker ${path5} could not be deleted either, so this will be reported again -- delete that marker by hand`
|
|
10822
10759
|
});
|
|
10823
10760
|
continue;
|
|
10824
10761
|
}
|
|
@@ -10826,12 +10763,12 @@ async function gcExpiredTrials(opts) {
|
|
|
10826
10763
|
throw new Error(`${marker.clientPath} is not a JSON object`);
|
|
10827
10764
|
}
|
|
10828
10765
|
stage = "unlink";
|
|
10829
|
-
await
|
|
10766
|
+
await unlink(path5);
|
|
10830
10767
|
cleared++;
|
|
10831
10768
|
} catch (e) {
|
|
10832
10769
|
const error = e.message;
|
|
10833
10770
|
log("debug", "trial gc failed", { slug: marker.slug, stage, error });
|
|
10834
|
-
failures.push({ slug: marker.slug, clientPath: marker.clientPath, markerPath:
|
|
10771
|
+
failures.push({ slug: marker.slug, clientPath: marker.clientPath, markerPath: path5, stage, error });
|
|
10835
10772
|
}
|
|
10836
10773
|
}
|
|
10837
10774
|
return { cleared, failed: failures.length, failures };
|
|
@@ -11091,7 +11028,7 @@ function foldBundleWarnings(warnings, probe) {
|
|
|
11091
11028
|
const prefix = `${probe.path}:`;
|
|
11092
11029
|
return warnings.filter((w) => !w.startsWith(prefix));
|
|
11093
11030
|
}
|
|
11094
|
-
var VERSION = true ? "1.0.
|
|
11031
|
+
var VERSION = true ? "1.0.3" : "dev";
|
|
11095
11032
|
var DOCTOR_USAGE = `Usage: yaw-mcp doctor [--json]
|
|
11096
11033
|
|
|
11097
11034
|
Print a diagnostic of your yaw-mcp setup.
|
|
@@ -11554,14 +11491,14 @@ function renderEnvSection(opts) {
|
|
|
11554
11491
|
print("");
|
|
11555
11492
|
}
|
|
11556
11493
|
async function collectVaultStatus(opts) {
|
|
11557
|
-
const
|
|
11558
|
-
const exists2 = existsSync6(
|
|
11494
|
+
const path5 = vaultPath(opts.home);
|
|
11495
|
+
const exists2 = existsSync6(path5);
|
|
11559
11496
|
let entries = exists2 ? null : [];
|
|
11560
11497
|
let unreadable = null;
|
|
11561
11498
|
let schemaVersion = null;
|
|
11562
11499
|
if (exists2) {
|
|
11563
11500
|
try {
|
|
11564
|
-
const vault = await loadVault(
|
|
11501
|
+
const vault = await loadVault(path5);
|
|
11565
11502
|
entries = vault ? listKeys(vault) : [];
|
|
11566
11503
|
schemaVersion = vault ? vault.version : null;
|
|
11567
11504
|
} catch (err) {
|
|
@@ -11581,7 +11518,7 @@ async function collectVaultStatus(opts) {
|
|
|
11581
11518
|
const referenced = new Set(refs.flatMap((r) => r.secretNames));
|
|
11582
11519
|
const missing = known === null ? [] : [...referenced].filter((n) => !known.includes(n)).sort();
|
|
11583
11520
|
return {
|
|
11584
|
-
path:
|
|
11521
|
+
path: path5,
|
|
11585
11522
|
exists: exists2,
|
|
11586
11523
|
entries,
|
|
11587
11524
|
unreadable,
|
|
@@ -11904,8 +11841,8 @@ async function renderTrialsSection(opts) {
|
|
|
11904
11841
|
for (const { marker, msUntilExpiry } of scan.live) {
|
|
11905
11842
|
print(` ${marker.slug} -> ${marker.clientName} (${marker.clientPath}) -- expires in ${formatTtl(msUntilExpiry)}`);
|
|
11906
11843
|
}
|
|
11907
|
-
for (const
|
|
11908
|
-
print(` ! malformed marker at ${
|
|
11844
|
+
for (const path5 of scan.malformed) {
|
|
11845
|
+
print(` ! malformed marker at ${path5} (delete by hand)`);
|
|
11909
11846
|
}
|
|
11910
11847
|
print("");
|
|
11911
11848
|
return warnings;
|
|
@@ -12074,9 +12011,9 @@ function probeClients(opts) {
|
|
|
12074
12011
|
}
|
|
12075
12012
|
return out;
|
|
12076
12013
|
}
|
|
12077
|
-
function walkContainer(root,
|
|
12014
|
+
function walkContainer(root, path5) {
|
|
12078
12015
|
let cur = root;
|
|
12079
|
-
for (const key of
|
|
12016
|
+
for (const key of path5) {
|
|
12080
12017
|
if (typeof cur !== "object" || cur === null || Array.isArray(cur)) return null;
|
|
12081
12018
|
cur = cur[key];
|
|
12082
12019
|
}
|
|
@@ -12293,10 +12230,10 @@ function shellHistorySources(opts) {
|
|
|
12293
12230
|
});
|
|
12294
12231
|
return sources.filter((s, i) => lastIndex.get(normalizeForCompare(resolve7(s.path))) === i);
|
|
12295
12232
|
}
|
|
12296
|
-
function readTailLines(
|
|
12233
|
+
function readTailLines(path5, n) {
|
|
12297
12234
|
let fd;
|
|
12298
12235
|
try {
|
|
12299
|
-
fd = openSync(
|
|
12236
|
+
fd = openSync(path5, "r");
|
|
12300
12237
|
const size = fstatSync(fd).size;
|
|
12301
12238
|
const start = size > SHELL_HISTORY_TAIL_BYTES ? size - SHELL_HISTORY_TAIL_BYTES : 0;
|
|
12302
12239
|
const length = size - start;
|
|
@@ -12351,12 +12288,12 @@ function compareSemver(a, b) {
|
|
|
12351
12288
|
// src/foundry-cmd.ts
|
|
12352
12289
|
import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
12353
12290
|
import { homedir as homedir17 } from "os";
|
|
12354
|
-
import
|
|
12291
|
+
import path4 from "path";
|
|
12355
12292
|
|
|
12356
12293
|
// src/foundry.ts
|
|
12357
|
-
import { appendFile as appendFile2, mkdir as
|
|
12294
|
+
import { appendFile as appendFile2, mkdir as mkdir5, stat as stat6 } from "fs/promises";
|
|
12358
12295
|
import { homedir as homedir16 } from "os";
|
|
12359
|
-
import
|
|
12296
|
+
import path3 from "path";
|
|
12360
12297
|
|
|
12361
12298
|
// src/relevance.ts
|
|
12362
12299
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -12700,9 +12637,9 @@ async function appendFoundryTrace(trace, home = homedir16()) {
|
|
|
12700
12637
|
try {
|
|
12701
12638
|
if (!isFoundryEnabled()) return;
|
|
12702
12639
|
const dir = userConfigDir(home);
|
|
12703
|
-
const file =
|
|
12640
|
+
const file = path3.join(dir, FOUNDRY_FILENAME);
|
|
12704
12641
|
try {
|
|
12705
|
-
const info = await
|
|
12642
|
+
const info = await stat6(file);
|
|
12706
12643
|
if (info.size >= MAX_FOUNDRY_BYTES) return;
|
|
12707
12644
|
} catch {
|
|
12708
12645
|
}
|
|
@@ -12712,7 +12649,7 @@ async function appendFoundryTrace(trace, home = homedir16()) {
|
|
|
12712
12649
|
redactedCount: trace.redactedCount
|
|
12713
12650
|
})}
|
|
12714
12651
|
`;
|
|
12715
|
-
await
|
|
12652
|
+
await mkdir5(dir, { recursive: true, mode: 448 });
|
|
12716
12653
|
await appendFile2(file, line, { encoding: "utf8", mode: 384 });
|
|
12717
12654
|
} catch {
|
|
12718
12655
|
}
|
|
@@ -12805,7 +12742,7 @@ function scoreCorpus(corpus) {
|
|
|
12805
12742
|
}
|
|
12806
12743
|
|
|
12807
12744
|
// src/foundry-cmd.ts
|
|
12808
|
-
var DEFAULT_OUT =
|
|
12745
|
+
var DEFAULT_OUT = path4.join("src", "tests", "fixtures", "foundry-corpus.json");
|
|
12809
12746
|
var FOUNDRY_USAGE = `Usage: yaw-mcp foundry export [--out <path>] [--cap <n>] [--json]
|
|
12810
12747
|
|
|
12811
12748
|
Fold the opt-in dispatch harvest (~/.yaw-mcp/foundry.jsonl) into a routing
|
|
@@ -12884,7 +12821,7 @@ async function runFoundryExport(opts) {
|
|
|
12884
12821
|
`);
|
|
12885
12822
|
};
|
|
12886
12823
|
const home = opts.home ?? homedir17();
|
|
12887
|
-
const harvestPath =
|
|
12824
|
+
const harvestPath = path4.join(userConfigDir(home), FOUNDRY_FILENAME);
|
|
12888
12825
|
const blob = opts.readTraces ? opts.readTraces() : (() => {
|
|
12889
12826
|
try {
|
|
12890
12827
|
return readFileSync5(harvestPath, "utf8");
|
|
@@ -12923,8 +12860,8 @@ async function runFoundryExport(opts) {
|
|
|
12923
12860
|
`yaw-mcp foundry: warning -- ${toolless}/${servers.length} snapshot servers carry no tools (no entry in ~/.yaw-mcp/state.json, or it aged past the tool-cache TTL). Those rank on name + namespace only, which depresses the accuracy printed below; activate them once and re-export.`
|
|
12924
12861
|
);
|
|
12925
12862
|
}
|
|
12926
|
-
const outPath =
|
|
12927
|
-
mkdirSync2(
|
|
12863
|
+
const outPath = path4.resolve(opts.cwd ?? process.cwd(), opts.out);
|
|
12864
|
+
mkdirSync2(path4.dirname(outPath), { recursive: true });
|
|
12928
12865
|
writeFileSync(outPath, `${JSON.stringify(corpus, null, 2)}
|
|
12929
12866
|
`, "utf8");
|
|
12930
12867
|
const score = scoreCorpus(corpus);
|
|
@@ -13867,8 +13804,8 @@ async function anyClientWiredToYawMcp(home, cwd, env, appData) {
|
|
|
13867
13804
|
return true;
|
|
13868
13805
|
}
|
|
13869
13806
|
}
|
|
13870
|
-
function nameBundlesFileOnce(message,
|
|
13871
|
-
return message.split(`${
|
|
13807
|
+
function nameBundlesFileOnce(message, path5) {
|
|
13808
|
+
return message.split(`${path5}: `).join("");
|
|
13872
13809
|
}
|
|
13873
13810
|
function renderLaunchChange(change) {
|
|
13874
13811
|
return ` from: ${renderLaunch3(change.from)}
|
|
@@ -14158,10 +14095,10 @@ ${REMOVE_USAGE}` };
|
|
|
14158
14095
|
opts.target = positional[0];
|
|
14159
14096
|
return { ok: true, options: opts };
|
|
14160
14097
|
}
|
|
14161
|
-
async function readRawServers(
|
|
14098
|
+
async function readRawServers(path5) {
|
|
14162
14099
|
let raw;
|
|
14163
14100
|
try {
|
|
14164
|
-
raw = await readFile14(
|
|
14101
|
+
raw = await readFile14(path5, "utf8");
|
|
14165
14102
|
} catch {
|
|
14166
14103
|
return null;
|
|
14167
14104
|
}
|
|
@@ -14201,9 +14138,9 @@ function renderLaunch3(entry) {
|
|
|
14201
14138
|
const url = typeof entry.url === "string" ? entry.url : "";
|
|
14202
14139
|
return url.length > 0 ? `HTTP ${displaySafe(url)}` : "(no command)";
|
|
14203
14140
|
}
|
|
14204
|
-
function printRemovalPreview(print,
|
|
14141
|
+
function printRemovalPreview(print, path5, t) {
|
|
14205
14142
|
print("");
|
|
14206
|
-
print(` Remove from ${displaySafe(
|
|
14143
|
+
print(` Remove from ${displaySafe(path5)}:`);
|
|
14207
14144
|
print("");
|
|
14208
14145
|
print(` namespace: ${t.namespace}`);
|
|
14209
14146
|
print(` name: ${displaySafe(t.name)}`);
|
|
@@ -14247,8 +14184,8 @@ async function runRemove(opts) {
|
|
|
14247
14184
|
const home = opts.home ?? homedir19();
|
|
14248
14185
|
const cwd = opts.cwd ?? process.cwd();
|
|
14249
14186
|
const env = opts.env ?? process.env;
|
|
14250
|
-
const
|
|
14251
|
-
const rawServers = await readRawServers(
|
|
14187
|
+
const path5 = localBundlesPath(userConfigDir(home));
|
|
14188
|
+
const rawServers = await readRawServers(path5);
|
|
14252
14189
|
const byIdentity = namespacesForStoredIdentity(opts.target, rawServers);
|
|
14253
14190
|
const candidates = [.../* @__PURE__ */ new Set([opts.target, ...byIdentity, deriveNamespace(opts.target)])];
|
|
14254
14191
|
if (byIdentity.length === 0 && !REMOVE_TARGET_RE.test(opts.target)) {
|
|
@@ -14260,7 +14197,7 @@ async function runRemove(opts) {
|
|
|
14260
14197
|
if (!opts.force) {
|
|
14261
14198
|
const doomed = findRemovalTarget(candidates, rawServers);
|
|
14262
14199
|
if (doomed) {
|
|
14263
|
-
printRemovalPreview(print,
|
|
14200
|
+
printRemovalPreview(print, path5, doomed);
|
|
14264
14201
|
if (!isInteractive4(opts)) {
|
|
14265
14202
|
printErr(
|
|
14266
14203
|
`yaw-mcp remove: refusing to remove "${doomed.namespace}" without a confirmation -- stdin/stdout is not a TTY.`
|
|
@@ -14292,12 +14229,12 @@ async function runRemove(opts) {
|
|
|
14292
14229
|
}
|
|
14293
14230
|
}
|
|
14294
14231
|
} catch (e) {
|
|
14295
|
-
printErr(`yaw-mcp remove: ${nameBundlesFileOnce(e.message,
|
|
14232
|
+
printErr(`yaw-mcp remove: ${nameBundlesFileOnce(e.message, path5)}`);
|
|
14296
14233
|
return { exitCode: 1, written: [] };
|
|
14297
14234
|
}
|
|
14298
14235
|
for (const w of warnings) printErr(`warning: ${w}`);
|
|
14299
14236
|
if (!res?.removed) {
|
|
14300
|
-
print(`yaw-mcp remove: no server matching "${opts.target}" in ${
|
|
14237
|
+
print(`yaw-mcp remove: no server matching "${opts.target}" in ${path5} (nothing to do).`);
|
|
14301
14238
|
const shadow2 = await findShadowingProjectBundles(cwd, home, env).catch(() => null);
|
|
14302
14239
|
if (shadow2) {
|
|
14303
14240
|
printErr(
|
|
@@ -14329,10 +14266,10 @@ var LIST_USAGE = `Usage: yaw-mcp list [--json]
|
|
|
14329
14266
|
configured yet, which is not a fault. Exits 1 when bundles.json is there
|
|
14330
14267
|
and could not be read or parsed, in both modes, so a script gating on
|
|
14331
14268
|
\`list\` does not read a broken config as an empty machine.`;
|
|
14332
|
-
async function rawEnvKeysByNamespace(
|
|
14269
|
+
async function rawEnvKeysByNamespace(path5) {
|
|
14333
14270
|
const out = /* @__PURE__ */ new Map();
|
|
14334
|
-
if (!
|
|
14335
|
-
const servers = await readRawServers(
|
|
14271
|
+
if (!path5) return out;
|
|
14272
|
+
const servers = await readRawServers(path5);
|
|
14336
14273
|
if (servers === null) return out;
|
|
14337
14274
|
for (const s of servers) {
|
|
14338
14275
|
const e = s;
|
|
@@ -14648,23 +14585,23 @@ async function runSet(opts) {
|
|
|
14648
14585
|
assignments.push(parsed.value);
|
|
14649
14586
|
}
|
|
14650
14587
|
const home = opts.home ?? homedir20();
|
|
14651
|
-
const
|
|
14652
|
-
if (!existsSync7(
|
|
14588
|
+
const path5 = localBundlesPath(userConfigDir(home));
|
|
14589
|
+
if (!existsSync7(path5)) {
|
|
14653
14590
|
printErr(
|
|
14654
|
-
`yaw-mcp ${verb}: no servers configured yet (${
|
|
14591
|
+
`yaw-mcp ${verb}: no servers configured yet (${path5} does not exist). Add one with \`yaw-mcp add <slug>\`.`
|
|
14655
14592
|
);
|
|
14656
14593
|
return { exitCode: 1, written: [] };
|
|
14657
14594
|
}
|
|
14658
14595
|
return withBundlesLock(home, async () => {
|
|
14659
14596
|
let rawText;
|
|
14660
14597
|
try {
|
|
14661
|
-
rawText = await readFile15(
|
|
14598
|
+
rawText = await readFile15(path5, "utf8");
|
|
14662
14599
|
} catch (e) {
|
|
14663
14600
|
if (e.code === "EISDIR") {
|
|
14664
|
-
printErr(`yaw-mcp ${verb}: ${
|
|
14601
|
+
printErr(`yaw-mcp ${verb}: ${path5} is a directory, not a file -- move or remove it, then re-run.`);
|
|
14665
14602
|
return { exitCode: 1, written: [] };
|
|
14666
14603
|
}
|
|
14667
|
-
printErr(`yaw-mcp ${verb}: ${
|
|
14604
|
+
printErr(`yaw-mcp ${verb}: ${path5} could not be read (${e.message}).`);
|
|
14668
14605
|
return { exitCode: 1, written: [] };
|
|
14669
14606
|
}
|
|
14670
14607
|
let parsed;
|
|
@@ -14672,13 +14609,13 @@ async function runSet(opts) {
|
|
|
14672
14609
|
parsed = parseJsonc(rawText);
|
|
14673
14610
|
} catch (e) {
|
|
14674
14611
|
printErr(
|
|
14675
|
-
`yaw-mcp ${verb}: ${
|
|
14612
|
+
`yaw-mcp ${verb}: ${path5} could not be parsed -- fix the JSON before setting fields (${e.message}).`
|
|
14676
14613
|
);
|
|
14677
14614
|
return { exitCode: 1, written: [] };
|
|
14678
14615
|
}
|
|
14679
14616
|
const servers = parsed?.servers;
|
|
14680
14617
|
if (!Array.isArray(servers)) {
|
|
14681
|
-
printErr(`yaw-mcp ${verb}: ${
|
|
14618
|
+
printErr(`yaw-mcp ${verb}: ${path5} has no "servers" array.`);
|
|
14682
14619
|
printErr(
|
|
14683
14620
|
` Add a top-level "servers": [] to that file (or delete the file, and \`yaw-mcp add <slug>\` will recreate it).`
|
|
14684
14621
|
);
|
|
@@ -14697,7 +14634,7 @@ async function runSet(opts) {
|
|
|
14697
14634
|
}
|
|
14698
14635
|
if (idx < 0) {
|
|
14699
14636
|
printErr(
|
|
14700
|
-
`yaw-mcp ${verb}: no server named "${target}" in ${
|
|
14637
|
+
`yaw-mcp ${verb}: no server named "${target}" in ${path5}. Run \`yaw-mcp list\` to see what is configured.`
|
|
14701
14638
|
);
|
|
14702
14639
|
return { exitCode: 1, written: [] };
|
|
14703
14640
|
}
|
|
@@ -14708,7 +14645,7 @@ async function runSet(opts) {
|
|
|
14708
14645
|
const targeted = envAssignments.map((a) => `env.${a.key}`).join(", ");
|
|
14709
14646
|
printErr(`yaw-mcp ${verb}: "${namespace}" is a remote server, so ${targeted} would never be read.`);
|
|
14710
14647
|
printErr(
|
|
14711
|
-
` A remote server spawns no process: its credentials travel in "headers". Re-add it with \`yaw-mcp add ${namespace} --url <url> --header 'Name: value'\`, or edit "headers" in ${
|
|
14648
|
+
` A remote server spawns no process: its credentials travel in "headers". Re-add it with \`yaw-mcp add ${namespace} --url <url> --header 'Name: value'\`, or edit "headers" in ${path5} by hand.`
|
|
14712
14649
|
);
|
|
14713
14650
|
return { exitCode: 1, written: [] };
|
|
14714
14651
|
}
|
|
@@ -14716,7 +14653,7 @@ async function runSet(opts) {
|
|
|
14716
14653
|
if (!envIsMap && envAssignments.length > 0) {
|
|
14717
14654
|
const targeted = envAssignments.map((a) => `env.${a.key}`).join(", ");
|
|
14718
14655
|
printErr(
|
|
14719
|
-
`yaw-mcp ${verb}: "${namespace}" in ${
|
|
14656
|
+
`yaw-mcp ${verb}: "${namespace}" in ${path5} has an "env" that is ${describeJsonShape2(entry.env)}, not an object of "NAME": "value" pairs.`
|
|
14720
14657
|
);
|
|
14721
14658
|
printErr(` Fix that field by hand (or delete it), then re-run to set ${targeted}.`);
|
|
14722
14659
|
return { exitCode: 1, written: [] };
|
|
@@ -14736,7 +14673,7 @@ async function runSet(opts) {
|
|
|
14736
14673
|
const current = projectedEnv[key];
|
|
14737
14674
|
if (current !== void 0 && typeof current !== "string") {
|
|
14738
14675
|
printErr(
|
|
14739
|
-
`yaw-mcp ${verb}: env.${key} on "${namespace}" is ${describeJsonShape2(current)} in ${
|
|
14676
|
+
`yaw-mcp ${verb}: env.${key} on "${namespace}" is ${describeJsonShape2(current)} in ${path5}, not a string -- remove it by hand.`
|
|
14740
14677
|
);
|
|
14741
14678
|
printErr(" Nothing was written; re-run once that field is a string or gone.");
|
|
14742
14679
|
return { exitCode: 1, written: [] };
|
|
@@ -14773,7 +14710,7 @@ async function runSet(opts) {
|
|
|
14773
14710
|
JSON.stringify({
|
|
14774
14711
|
ok: false,
|
|
14775
14712
|
error: `refusing to ${phrase} on "${namespace}" without a confirmation -- stdin/stdout is not a TTY. Re-run with --force (or -y).`,
|
|
14776
|
-
path:
|
|
14713
|
+
path: path5,
|
|
14777
14714
|
namespace,
|
|
14778
14715
|
// Key NAMES only, like every other env surface here.
|
|
14779
14716
|
destructive: [...destroyed.keys()]
|
|
@@ -14787,12 +14724,12 @@ async function runSet(opts) {
|
|
|
14787
14724
|
}
|
|
14788
14725
|
const answer = await askYesNo5(opts, `${phrase[0].toUpperCase()}${phrase.slice(1)} on "${namespace}"? [y/N] `);
|
|
14789
14726
|
if (answer === QUESTION_CANCELLED) {
|
|
14790
|
-
if (opts.json) printErr(JSON.stringify({ ok: false, error: "Cancelled.", cancelled: true, path:
|
|
14727
|
+
if (opts.json) printErr(JSON.stringify({ ok: false, error: "Cancelled.", cancelled: true, path: path5, namespace }));
|
|
14791
14728
|
else printErr("Aborted.");
|
|
14792
14729
|
return { exitCode: 130, written: [] };
|
|
14793
14730
|
}
|
|
14794
14731
|
if (answer !== "y" && answer !== "yes") {
|
|
14795
|
-
if (opts.json) printErr(JSON.stringify({ ok: false, error: "Aborted.", aborted: true, path:
|
|
14732
|
+
if (opts.json) printErr(JSON.stringify({ ok: false, error: "Aborted.", aborted: true, path: path5, namespace }));
|
|
14796
14733
|
else print("Aborted.");
|
|
14797
14734
|
return { exitCode: 1, written: [] };
|
|
14798
14735
|
}
|
|
@@ -14856,22 +14793,22 @@ async function runSet(opts) {
|
|
|
14856
14793
|
}
|
|
14857
14794
|
const changed = jsonChanges.length > 0;
|
|
14858
14795
|
if (changed) {
|
|
14859
|
-
await atomicWriteFile(
|
|
14796
|
+
await atomicWriteFile(path5, text, "utf8", 384, 448);
|
|
14860
14797
|
}
|
|
14861
14798
|
if (opts.json) {
|
|
14862
14799
|
print(
|
|
14863
14800
|
JSON.stringify({
|
|
14864
14801
|
ok: true,
|
|
14865
|
-
path:
|
|
14802
|
+
path: path5,
|
|
14866
14803
|
namespace,
|
|
14867
14804
|
changed,
|
|
14868
14805
|
changes: jsonChanges,
|
|
14869
14806
|
unchanged: jsonUnchanged
|
|
14870
14807
|
})
|
|
14871
14808
|
);
|
|
14872
|
-
return { exitCode: 0, written: changed ? [
|
|
14809
|
+
return { exitCode: 0, written: changed ? [path5] : [] };
|
|
14873
14810
|
}
|
|
14874
|
-
print(changed ? `Updated "${namespace}" in ${
|
|
14811
|
+
print(changed ? `Updated "${namespace}" in ${path5}` : `No change to "${namespace}" in ${path5}`);
|
|
14875
14812
|
for (const line of applied) print(` ${line}`);
|
|
14876
14813
|
if (changed) {
|
|
14877
14814
|
const stillDisabled = isActiveTouched ? assignments.some((a) => a.field === "isActive" && a.value === false) : entry.isActive === false;
|
|
@@ -14890,7 +14827,7 @@ async function runSet(opts) {
|
|
|
14890
14827
|
}
|
|
14891
14828
|
print("A running yaw-mcp applies it on its next mcp_connect_* call -- no client restart.");
|
|
14892
14829
|
}
|
|
14893
|
-
return { exitCode: 0, written: changed ? [
|
|
14830
|
+
return { exitCode: 0, written: changed ? [path5] : [] };
|
|
14894
14831
|
});
|
|
14895
14832
|
}
|
|
14896
14833
|
async function runEnableDisable(opts) {
|
|
@@ -14899,7 +14836,7 @@ async function runEnableDisable(opts) {
|
|
|
14899
14836
|
|
|
14900
14837
|
// src/reset-learning-cmd.ts
|
|
14901
14838
|
import { existsSync as existsSync8 } from "fs";
|
|
14902
|
-
import { unlink as
|
|
14839
|
+
import { unlink as unlink2 } from "fs/promises";
|
|
14903
14840
|
import { homedir as homedir21 } from "os";
|
|
14904
14841
|
import { createInterface as createInterface6 } from "readline/promises";
|
|
14905
14842
|
var RESET_LEARNING_USAGE = `Usage: yaw-mcp reset-learning
|
|
@@ -15013,7 +14950,7 @@ async function runResetLearning(opts = {}) {
|
|
|
15013
14950
|
}
|
|
15014
14951
|
}
|
|
15015
14952
|
try {
|
|
15016
|
-
await
|
|
14953
|
+
await unlink2(filePath);
|
|
15017
14954
|
} catch (err) {
|
|
15018
14955
|
if (isFileNotFound(err)) {
|
|
15019
14956
|
print("yaw-mcp reset-learning: no persisted state to reset.");
|
|
@@ -15713,21 +15650,21 @@ function installNudgeEnabled(env, config) {
|
|
|
15713
15650
|
}
|
|
15714
15651
|
var stateMemo = null;
|
|
15715
15652
|
function readState(home) {
|
|
15716
|
-
const
|
|
15717
|
-
if (!existsSync9(
|
|
15718
|
-
if (stateMemo?.path ===
|
|
15653
|
+
const path5 = installNudgeStatePath(home);
|
|
15654
|
+
if (!existsSync9(path5)) {
|
|
15655
|
+
if (stateMemo?.path === path5) stateMemo = null;
|
|
15719
15656
|
return { nudges: [] };
|
|
15720
15657
|
}
|
|
15721
15658
|
try {
|
|
15722
|
-
const st = statSync3(
|
|
15723
|
-
if (stateMemo && stateMemo.path ===
|
|
15659
|
+
const st = statSync3(path5);
|
|
15660
|
+
if (stateMemo && stateMemo.path === path5 && stateMemo.mtimeMs === st.mtimeMs && stateMemo.size === st.size) {
|
|
15724
15661
|
return stateMemo.state;
|
|
15725
15662
|
}
|
|
15726
15663
|
const remember = (state) => {
|
|
15727
|
-
stateMemo = { path:
|
|
15664
|
+
stateMemo = { path: path5, mtimeMs: st.mtimeMs, size: st.size, state };
|
|
15728
15665
|
return state;
|
|
15729
15666
|
};
|
|
15730
|
-
const parsed = JSON.parse(readFileSync6(
|
|
15667
|
+
const parsed = JSON.parse(readFileSync6(path5, "utf8"));
|
|
15731
15668
|
if (!parsed || typeof parsed !== "object") return remember({ nudges: [] });
|
|
15732
15669
|
const raw = parsed.nudges;
|
|
15733
15670
|
if (!Array.isArray(raw)) return remember({ nudges: [] });
|
|
@@ -15760,13 +15697,13 @@ function recordNudges(clis, home, now = Date.now) {
|
|
|
15760
15697
|
const state = readState(home);
|
|
15761
15698
|
const kept = state.nudges.filter((n) => !recorded.has(n.cli) && at - clampToNow(n.nudgedAt, at) < INSTALL_NUDGE_COOLDOWN_MS).map((n) => ({ cli: n.cli, nudgedAt: clampToNow(n.nudgedAt, at) }));
|
|
15762
15699
|
for (const cli of recorded) kept.push({ cli, nudgedAt: at });
|
|
15763
|
-
const
|
|
15764
|
-
mkdirSync3(dirname8(
|
|
15765
|
-
writeFileSync2(
|
|
15700
|
+
const path5 = installNudgeStatePath(home);
|
|
15701
|
+
mkdirSync3(dirname8(path5), { recursive: true });
|
|
15702
|
+
writeFileSync2(path5, `${JSON.stringify({ nudges: kept }, null, 2)}
|
|
15766
15703
|
`, "utf8");
|
|
15767
15704
|
try {
|
|
15768
|
-
const st = statSync3(
|
|
15769
|
-
stateMemo = { path:
|
|
15705
|
+
const st = statSync3(path5);
|
|
15706
|
+
stateMemo = { path: path5, mtimeMs: st.mtimeMs, size: st.size, state: { nudges: kept } };
|
|
15770
15707
|
} catch {
|
|
15771
15708
|
stateMemo = null;
|
|
15772
15709
|
}
|
|
@@ -17722,7 +17659,7 @@ var ConnectServer = class _ConnectServer {
|
|
|
17722
17659
|
static SHUTDOWN_DRAIN_MS = 2e3;
|
|
17723
17660
|
constructor() {
|
|
17724
17661
|
this.server = new Server(
|
|
17725
|
-
{ name: "yaw-mcp", version: true ? "1.0.
|
|
17662
|
+
{ name: "yaw-mcp", version: true ? "1.0.3" : "dev" },
|
|
17726
17663
|
{
|
|
17727
17664
|
capabilities: {
|
|
17728
17665
|
tools: { listChanged: true },
|
|
@@ -21125,7 +21062,7 @@ function registerShutdownTriggers(shutdown, targets) {
|
|
|
21125
21062
|
// src/status-cmd.ts
|
|
21126
21063
|
import { existsSync as existsSync10 } from "fs";
|
|
21127
21064
|
import { homedir as homedir23 } from "os";
|
|
21128
|
-
var VERSION2 = true ? "1.0.
|
|
21065
|
+
var VERSION2 = true ? "1.0.3" : "dev";
|
|
21129
21066
|
var STATUS_SCHEMA_VERSION = 1;
|
|
21130
21067
|
var STATUS_USAGE = `Usage: yaw-mcp status [--json]
|
|
21131
21068
|
|
|
@@ -21877,7 +21814,7 @@ if (subcommand === "compliance") {
|
|
|
21877
21814
|
`);
|
|
21878
21815
|
process.exitCode = 0;
|
|
21879
21816
|
} else if (subcommand === "--version" || subcommand === "-V") {
|
|
21880
|
-
process.stdout.write(`yaw-mcp ${true ? "1.0.
|
|
21817
|
+
process.stdout.write(`yaw-mcp ${true ? "1.0.3" : "dev"}
|
|
21881
21818
|
`);
|
|
21882
21819
|
process.exitCode = 0;
|
|
21883
21820
|
} else if (subcommand !== void 0 && !subcommand.startsWith("-")) {
|