nulladrift 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/index.js +1082 -353
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -99,7 +99,8 @@ function serversThatShippedNothing(changes) {
|
|
|
99
99
|
const moved = /* @__PURE__ */ new Set();
|
|
100
100
|
const versioned = /* @__PURE__ */ new Set();
|
|
101
101
|
for (const change2 of changes) {
|
|
102
|
-
|
|
102
|
+
const uncaptured = change2.kind === "server.removed" || change2.kind === "server.added" && change2.after === void 0;
|
|
103
|
+
if (!uncaptured) moved.add(change2.server);
|
|
103
104
|
if (change2.kind === "server.identity.changed") versioned.add(change2.server);
|
|
104
105
|
}
|
|
105
106
|
return [...moved].filter((server2) => !versioned.has(server2)).sort();
|
|
@@ -446,11 +447,17 @@ function redactArgs(args) {
|
|
|
446
447
|
function looksLikeAnOperand(value) {
|
|
447
448
|
return value.startsWith("@") || value.includes("/") || /\.(m?[jt]s|cjs|py|json|ya?ml|toml|sh|exe)$/i.test(value);
|
|
448
449
|
}
|
|
450
|
+
var REVISION_WORDS = /* @__PURE__ */ new Set(["raw", "blob", "blobs", "tree", "trees", "commit", "commits", "archive", "src", "+"]);
|
|
451
|
+
var COMMIT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
|
|
449
452
|
function redactPath(pathname, options = {}) {
|
|
453
|
+
let revisionPath = false;
|
|
450
454
|
return pathname.split("/").map((segment) => {
|
|
455
|
+
const afterRevisionWord = revisionPath;
|
|
456
|
+
if (REVISION_WORDS.has(decoded(segment).toLowerCase())) revisionPath = true;
|
|
451
457
|
if (segment === "" || PLACEHOLDER.test(decoded(segment))) return segment;
|
|
452
458
|
if (looksRandom(segment)) return REDACTED;
|
|
453
|
-
|
|
459
|
+
const commit = afterRevisionWord && COMMIT_ID.test(segment);
|
|
460
|
+
if (!options.contentAddressed && !commit && (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(segment) || /^[0-9a-f]{32,}$/i.test(segment)))
|
|
454
461
|
return REDACTED;
|
|
455
462
|
return redactFormats(segment);
|
|
456
463
|
}).join("/");
|
|
@@ -465,26 +472,65 @@ var MAX_REF_DEPTH = 32;
|
|
|
465
472
|
var MAX_VISIT_DEPTH = 12;
|
|
466
473
|
var MAX_FACTS = 5e3;
|
|
467
474
|
var MAX_RESOLUTIONS = 1e5;
|
|
475
|
+
var MAX_MERGED_KEYS = 1e5;
|
|
468
476
|
var states = /* @__PURE__ */ new WeakMap();
|
|
477
|
+
function freshState() {
|
|
478
|
+
return { refs: /* @__PURE__ */ new Map(), nodes: /* @__PURE__ */ new WeakMap(), spent: 0, merged: 0 };
|
|
479
|
+
}
|
|
480
|
+
function beginWalk(root) {
|
|
481
|
+
if (root !== null && typeof root === "object") states.delete(root);
|
|
482
|
+
}
|
|
469
483
|
function stateOf(root) {
|
|
470
|
-
if (root === null || typeof root !== "object") return
|
|
484
|
+
if (root === null || typeof root !== "object") return freshState();
|
|
471
485
|
let state = states.get(root);
|
|
472
486
|
if (!state) {
|
|
473
|
-
state =
|
|
487
|
+
state = freshState();
|
|
474
488
|
states.set(root, state);
|
|
475
489
|
}
|
|
476
490
|
return state;
|
|
477
491
|
}
|
|
492
|
+
var LOWER_BOUNDS = /* @__PURE__ */ new Set(["minimum", "exclusiveMinimum", "minLength", "minItems", "minProperties", "minContains"]);
|
|
493
|
+
var UPPER_BOUNDS = /* @__PURE__ */ new Set(["maximum", "exclusiveMaximum", "maxLength", "maxItems", "maxProperties", "maxContains"]);
|
|
494
|
+
var ANNOTATIONS = /* @__PURE__ */ new Set(["title", "description", "default", "examples", "example", "$comment", "$id", "$schema", "$anchor", "deprecated", "readOnly", "writeOnly"]);
|
|
495
|
+
var shadows = /* @__PURE__ */ new WeakMap();
|
|
496
|
+
function shadowedIn(effective) {
|
|
497
|
+
return shadows.get(effective);
|
|
498
|
+
}
|
|
499
|
+
function remember(into, key, value) {
|
|
500
|
+
const held = into.get(key);
|
|
501
|
+
if (held) held.push(value);
|
|
502
|
+
else into.set(key, [value]);
|
|
503
|
+
}
|
|
504
|
+
function canonicalOrUndefined(value) {
|
|
505
|
+
try {
|
|
506
|
+
return canonicalize(value);
|
|
507
|
+
} catch {
|
|
508
|
+
return void 0;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function intersectEnum(held, value) {
|
|
512
|
+
const allowed = new Set(value.map(canonicalOrUndefined));
|
|
513
|
+
return held.filter((member) => allowed.has(canonicalOrUndefined(member)));
|
|
514
|
+
}
|
|
515
|
+
function intersectTypes(held, value) {
|
|
516
|
+
const list = (types) => typeof types === "string" ? /* @__PURE__ */ new Set([types]) : Array.isArray(types) ? new Set(types.filter((entry) => typeof entry === "string")) : void 0;
|
|
517
|
+
const a = list(held);
|
|
518
|
+
const b = list(value);
|
|
519
|
+
if (a === void 0 || b === void 0) return held;
|
|
520
|
+
const both = [...a].filter((type) => b.has(type) || type === "integer" && b.has("number"));
|
|
521
|
+
if (a.has("number") && b.has("integer") && !both.includes("integer")) both.push("integer");
|
|
522
|
+
return both.length === 1 ? both[0] : both;
|
|
523
|
+
}
|
|
478
524
|
function asObject(value) {
|
|
479
525
|
return value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
480
526
|
}
|
|
481
527
|
function decodeToken(token) {
|
|
482
|
-
let
|
|
528
|
+
let decoded3 = token;
|
|
483
529
|
try {
|
|
484
|
-
|
|
530
|
+
decoded3 = decodeURIComponent(token);
|
|
485
531
|
} catch {
|
|
486
532
|
}
|
|
487
|
-
return
|
|
533
|
+
return decoded3.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
488
534
|
}
|
|
489
535
|
function resolvePointer(root, ref) {
|
|
490
536
|
if (!ref.startsWith("#")) return void 0;
|
|
@@ -503,25 +549,68 @@ function effectiveSchema(node, root, seenRefs = /* @__PURE__ */ new Set(), depth
|
|
|
503
549
|
if (object === void 0) return void 0;
|
|
504
550
|
if (depth > MAX_REF_DEPTH) return object;
|
|
505
551
|
const state = stateOf(root);
|
|
506
|
-
if (depth === 0)
|
|
507
|
-
|
|
552
|
+
if (depth === 0) {
|
|
553
|
+
const known = state.nodes.get(object);
|
|
554
|
+
if (known !== void 0) return known;
|
|
555
|
+
state.spent = 0;
|
|
556
|
+
}
|
|
557
|
+
if (++state.spent > MAX_RESOLUTIONS || state.merged > MAX_MERGED_KEYS) {
|
|
558
|
+
if (depth === 0) state.nodes.set(object, object);
|
|
559
|
+
return object;
|
|
560
|
+
}
|
|
508
561
|
const out = /* @__PURE__ */ Object.create(null);
|
|
562
|
+
let shadow;
|
|
563
|
+
const shadowed = () => shadow ??= { keywords: /* @__PURE__ */ new Map(), properties: /* @__PURE__ */ new Map() };
|
|
564
|
+
let ownsProperties = false;
|
|
509
565
|
const merge = (source) => {
|
|
510
|
-
|
|
566
|
+
if (state.merged > MAX_MERGED_KEYS) return;
|
|
567
|
+
const entries = Object.entries(source);
|
|
568
|
+
state.merged += entries.length;
|
|
569
|
+
for (const [key, value] of entries) {
|
|
511
570
|
if (key === "$ref" || key === "allOf") continue;
|
|
512
571
|
if (key === "properties") {
|
|
513
|
-
const
|
|
514
|
-
|
|
572
|
+
const incoming = asObject(value);
|
|
573
|
+
const held = asObject(out["properties"]);
|
|
574
|
+
if (held === void 0) {
|
|
575
|
+
out["properties"] = incoming ?? /* @__PURE__ */ Object.create(null);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (incoming === void 0 || incoming === held) continue;
|
|
579
|
+
const names = Object.keys(incoming);
|
|
580
|
+
if (names.length === 0) continue;
|
|
581
|
+
const merged = ownsProperties ? held : Object.assign(/* @__PURE__ */ Object.create(null), held);
|
|
582
|
+
if (!ownsProperties) state.merged += Object.keys(held).length;
|
|
583
|
+
state.merged += names.length;
|
|
584
|
+
ownsProperties = true;
|
|
585
|
+
for (const name of names) {
|
|
586
|
+
const schema = incoming[name];
|
|
515
587
|
if (!Object.hasOwn(merged, name)) Object.defineProperty(merged, name, { value: schema, enumerable: true, writable: true, configurable: true });
|
|
588
|
+
else if (merged[name] !== schema) remember(shadowed().properties, name, schema);
|
|
516
589
|
}
|
|
517
590
|
out["properties"] = merged;
|
|
518
591
|
} else if (key === "required" && Array.isArray(value)) {
|
|
519
592
|
const already = Array.isArray(out["required"]) ? out["required"] : [];
|
|
593
|
+
state.merged += already.length + value.length;
|
|
520
594
|
out["required"] = [...new Set([...already, ...value].filter((entry) => typeof entry === "string"))];
|
|
521
595
|
} else if (!Object.hasOwn(out, key)) {
|
|
522
596
|
out[key] = value;
|
|
597
|
+
} else {
|
|
598
|
+
const held = out[key];
|
|
599
|
+
if (held === value) continue;
|
|
600
|
+
if (typeof held === "number" && typeof value === "number" && LOWER_BOUNDS.has(key)) out[key] = Math.max(held, value);
|
|
601
|
+
else if (typeof held === "number" && typeof value === "number" && UPPER_BOUNDS.has(key)) out[key] = Math.min(held, value);
|
|
602
|
+
else if (key === "enum" && Array.isArray(held) && Array.isArray(value)) {
|
|
603
|
+
state.merged += held.length + value.length;
|
|
604
|
+
out[key] = intersectEnum(held, value);
|
|
605
|
+
} else if (key === "type") out[key] = intersectTypes(held, value);
|
|
606
|
+
else if (!ANNOTATIONS.has(key)) remember(shadowed().keywords, key, value);
|
|
523
607
|
}
|
|
524
608
|
}
|
|
609
|
+
const inherited = shadows.get(source);
|
|
610
|
+
if (inherited) {
|
|
611
|
+
for (const [key, values] of inherited.keywords) for (const value of values) remember(shadowed().keywords, key, value);
|
|
612
|
+
for (const [name, values] of inherited.properties) for (const value of values) remember(shadowed().properties, name, value);
|
|
613
|
+
}
|
|
525
614
|
};
|
|
526
615
|
merge(object);
|
|
527
616
|
const ref = object["$ref"];
|
|
@@ -541,9 +630,23 @@ function effectiveSchema(node, root, seenRefs = /* @__PURE__ */ new Set(), depth
|
|
|
541
630
|
if (resolved) merge(resolved);
|
|
542
631
|
}
|
|
543
632
|
}
|
|
633
|
+
if (shadow) shadows.set(out, shadow);
|
|
634
|
+
if (depth === 0) state.nodes.set(object, out);
|
|
544
635
|
return out;
|
|
545
636
|
}
|
|
637
|
+
var entryLists = /* @__PURE__ */ new WeakMap();
|
|
638
|
+
var alternativeLists = /* @__PURE__ */ new WeakMap();
|
|
639
|
+
function entriesOf(object) {
|
|
640
|
+
let entries = entryLists.get(object);
|
|
641
|
+
if (!entries) {
|
|
642
|
+
entries = Object.entries(object);
|
|
643
|
+
entryLists.set(object, entries);
|
|
644
|
+
}
|
|
645
|
+
return entries;
|
|
646
|
+
}
|
|
546
647
|
function alternatives(object) {
|
|
648
|
+
const known = alternativeLists.get(object);
|
|
649
|
+
if (known) return known;
|
|
547
650
|
const branches = [];
|
|
548
651
|
for (const keyword of ["anyOf", "oneOf"]) {
|
|
549
652
|
const value = object[keyword];
|
|
@@ -553,6 +656,7 @@ function alternatives(object) {
|
|
|
553
656
|
for (const keyword of ["then", "else", "not"]) {
|
|
554
657
|
if (object[keyword] !== void 0) branches.push({ label: keyword, schema: object[keyword] });
|
|
555
658
|
}
|
|
659
|
+
alternativeLists.set(object, branches);
|
|
556
660
|
return branches;
|
|
557
661
|
}
|
|
558
662
|
|
|
@@ -569,8 +673,25 @@ function resolveBehavior(annotations2) {
|
|
|
569
673
|
function isEscalation(previous, next) {
|
|
570
674
|
return previous.readOnly && !next.readOnly || !previous.destructive && next.destructive || previous.idempotent && !next.idempotent || !previous.openWorld && next.openWorld;
|
|
571
675
|
}
|
|
572
|
-
var
|
|
573
|
-
|
|
676
|
+
var SCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
677
|
+
"items",
|
|
678
|
+
"prefixItems",
|
|
679
|
+
"additionalItems",
|
|
680
|
+
"contains",
|
|
681
|
+
"allOf",
|
|
682
|
+
"anyOf",
|
|
683
|
+
"oneOf",
|
|
684
|
+
"not",
|
|
685
|
+
"if",
|
|
686
|
+
"then",
|
|
687
|
+
"else",
|
|
688
|
+
"additionalProperties",
|
|
689
|
+
"unevaluatedProperties",
|
|
690
|
+
"unevaluatedItems",
|
|
691
|
+
"propertyNames",
|
|
692
|
+
"contentSchema"
|
|
693
|
+
]);
|
|
694
|
+
var NAMED_SCHEMAS = /* @__PURE__ */ new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas", "dependencies"]);
|
|
574
695
|
function normalizeSchema(value) {
|
|
575
696
|
return normalizeNode(value, false);
|
|
576
697
|
}
|
|
@@ -587,47 +708,54 @@ function normalizeNode(value, namesOnly) {
|
|
|
587
708
|
out[key] = [...member].sort();
|
|
588
709
|
continue;
|
|
589
710
|
}
|
|
590
|
-
if (
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
out[key] = normalizeNode(member, NAMED_SCHEMAS.has(key));
|
|
711
|
+
if (NAMED_SCHEMAS.has(key)) out[key] = normalizeNode(member, true);
|
|
712
|
+
else if (SCHEMA_KEYWORDS.has(key)) out[key] = normalizeNode(member, false);
|
|
713
|
+
else out[key] = member;
|
|
595
714
|
}
|
|
596
715
|
return out;
|
|
597
716
|
}
|
|
598
717
|
function extractHeaderParams(schema) {
|
|
599
718
|
const found = [];
|
|
600
719
|
let budget = MAX_HEADER_VISITS;
|
|
720
|
+
let reads = 0;
|
|
601
721
|
const walk = (node, path, depth, refsOnPath) => {
|
|
602
722
|
if (depth > MAX_VISIT_DEPTH) return;
|
|
603
723
|
if (budget <= 0) return;
|
|
604
724
|
budget -= 1;
|
|
605
725
|
const object = effectiveSchema(node, schema);
|
|
606
726
|
if (!object) return;
|
|
727
|
+
const descend = () => budget > 0 && depth + 1 <= MAX_VISIT_DEPTH;
|
|
607
728
|
const properties = asObject(object["properties"]);
|
|
608
729
|
if (properties) {
|
|
609
|
-
for (const [name, child] of
|
|
730
|
+
for (const [name, child] of entriesOf(properties)) {
|
|
731
|
+
if (++reads > MAX_HEADER_READS) return;
|
|
610
732
|
const resolved = effectiveSchema(child, schema);
|
|
611
733
|
if (!resolved) continue;
|
|
612
734
|
const header = resolved["x-mcp-header"];
|
|
613
735
|
if (typeof header === "string" && header.length > 0) found.push(`${[...path, name].join(".")} -> ${header}`);
|
|
614
736
|
const ref = asObject(child)?.["$ref"];
|
|
615
737
|
if (typeof ref === "string" && refsOnPath.has(ref)) continue;
|
|
738
|
+
if (!descend()) continue;
|
|
616
739
|
walk(child, [...path, name], depth + 1, typeof ref === "string" ? /* @__PURE__ */ new Set([...refsOnPath, ref]) : refsOnPath);
|
|
617
740
|
}
|
|
618
741
|
}
|
|
619
742
|
for (const branch of alternatives(object)) {
|
|
743
|
+
if (++reads > MAX_HEADER_READS) return;
|
|
620
744
|
const ref = asObject(branch.schema)?.["$ref"];
|
|
621
745
|
if (typeof ref === "string" && refsOnPath.has(ref)) continue;
|
|
746
|
+
if (!descend()) continue;
|
|
622
747
|
walk(branch.schema, path, depth + 1, typeof ref === "string" ? /* @__PURE__ */ new Set([...refsOnPath, ref]) : refsOnPath);
|
|
623
748
|
}
|
|
624
749
|
};
|
|
625
750
|
const rootRef = asObject(schema)?.["$ref"];
|
|
751
|
+
beginWalk(schema);
|
|
626
752
|
walk(schema, [], 0, new Set(typeof rootRef === "string" ? [rootRef] : []));
|
|
627
753
|
if (budget <= 0) found.push(`(schema too large to scan for headers past ${MAX_HEADER_VISITS} nodes)`);
|
|
754
|
+
if (reads > MAX_HEADER_READS) found.push(`(schema too large to scan for headers past ${MAX_HEADER_READS} reads)`);
|
|
628
755
|
return [...new Set(found)].sort();
|
|
629
756
|
}
|
|
630
757
|
var MAX_HEADER_VISITS = 2e4;
|
|
758
|
+
var MAX_HEADER_READS = 50 * MAX_HEADER_VISITS;
|
|
631
759
|
function stripIgnoredMeta(meta, ignoredPrefixes) {
|
|
632
760
|
if (meta === null || meta === void 0 || typeof meta !== "object" || Array.isArray(meta)) return void 0;
|
|
633
761
|
const out = /* @__PURE__ */ Object.create(null);
|
|
@@ -750,19 +878,43 @@ var CONFUSABLE_PATTERN = new RegExp(`[${Object.keys(CONFUSABLES).join("")}]`, "g
|
|
|
750
878
|
function normalize(identifier) {
|
|
751
879
|
return identifier.toLowerCase().replace(CONFUSABLE_PATTERN, (character) => CONFUSABLES[character] ?? character).replace(/[-.\s/]+/g, "_");
|
|
752
880
|
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
const
|
|
756
|
-
const names =
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
881
|
+
var MAX_ARGUMENT_READS = 10 * MAX_FACTS;
|
|
882
|
+
function argumentNames(inputSchema) {
|
|
883
|
+
const root = inputSchema;
|
|
884
|
+
const names = /* @__PURE__ */ new Set();
|
|
885
|
+
let budget = MAX_ARGUMENT_READS;
|
|
886
|
+
const walk = (node, depth) => {
|
|
887
|
+
if (budget <= 0) return false;
|
|
888
|
+
budget -= 1;
|
|
889
|
+
const object = effectiveSchema(node, root);
|
|
890
|
+
if (!object) return true;
|
|
891
|
+
const deeper = depth < MAX_VISIT_DEPTH;
|
|
892
|
+
const into = (child) => deeper && child !== null && typeof child === "object" ? walk(child, depth + 1) : budget > 0;
|
|
893
|
+
const properties = asObject(object["properties"]);
|
|
894
|
+
if (properties) {
|
|
895
|
+
for (const [name, child] of entriesOf(properties)) {
|
|
896
|
+
if (--budget <= 0) return false;
|
|
897
|
+
names.add(name);
|
|
898
|
+
if (!into(child)) return false;
|
|
899
|
+
}
|
|
762
900
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
901
|
+
for (const keyword of ["items", "prefixItems"]) {
|
|
902
|
+
const value = object[keyword];
|
|
903
|
+
if (Array.isArray(value)) {
|
|
904
|
+
for (const child of value) if (!into(child)) return false;
|
|
905
|
+
} else if (!into(value)) return false;
|
|
906
|
+
}
|
|
907
|
+
if (!into(object["additionalProperties"])) return false;
|
|
908
|
+
const patternProperties = asObject(object["patternProperties"]);
|
|
909
|
+
if (patternProperties) {
|
|
910
|
+
for (const [, child] of entriesOf(patternProperties)) if (!into(child)) return false;
|
|
911
|
+
}
|
|
912
|
+
for (const branch of alternatives(object)) if (!into(branch.schema)) return false;
|
|
913
|
+
return true;
|
|
914
|
+
};
|
|
915
|
+
beginWalk(root);
|
|
916
|
+
walk(root, 0);
|
|
917
|
+
return [...names];
|
|
766
918
|
}
|
|
767
919
|
function toolCapabilities(tool2) {
|
|
768
920
|
const subject = objectOr(tool2);
|
|
@@ -801,111 +953,297 @@ function surfaceCapabilities(tools) {
|
|
|
801
953
|
}
|
|
802
954
|
|
|
803
955
|
// ../core/src/diff/schema.ts
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
956
|
+
var LOWER_BOUNDS2 = ["minimum", "exclusiveMinimum", "minLength", "minItems", "minProperties", "minContains"];
|
|
957
|
+
var UPPER_BOUNDS2 = ["maximum", "exclusiveMaximum", "maxLength", "maxItems", "maxProperties", "maxContains"];
|
|
958
|
+
var OPAQUE = [
|
|
959
|
+
"pattern",
|
|
960
|
+
"format",
|
|
961
|
+
"multipleOf",
|
|
962
|
+
"uniqueItems",
|
|
963
|
+
"not",
|
|
964
|
+
"if",
|
|
965
|
+
"contains",
|
|
966
|
+
"propertyNames",
|
|
967
|
+
"dependentRequired",
|
|
968
|
+
"dependentSchemas",
|
|
969
|
+
"dependencies",
|
|
970
|
+
"unevaluatedProperties",
|
|
971
|
+
"unevaluatedItems",
|
|
972
|
+
"additionalItems"
|
|
973
|
+
];
|
|
974
|
+
var OPEN_WHEN_EMPTY = /* @__PURE__ */ new Set(["unevaluatedProperties", "unevaluatedItems", "additionalItems", "propertyNames"]);
|
|
975
|
+
var SLOT_KEYWORDS = ["items", "anyOf", "oneOf", "then", "else"];
|
|
976
|
+
var CONSIDERED = /* @__PURE__ */ new Set([...LOWER_BOUNDS2, ...UPPER_BOUNDS2, ...OPAQUE, ...SLOT_KEYWORDS]);
|
|
977
|
+
var MEMBERS = /* @__PURE__ */ new Set(["properties", "patternProperties", "prefixItems"]);
|
|
978
|
+
function isOpen(value) {
|
|
979
|
+
if (value === true) return true;
|
|
980
|
+
const object = asObject(value);
|
|
981
|
+
return object !== void 0 && Object.keys(object).length === 0;
|
|
982
|
+
}
|
|
983
|
+
function isVacuous(keyword, value) {
|
|
984
|
+
if (value === false) return keyword === "uniqueItems" || keyword === "exclusiveMinimum" || keyword === "exclusiveMaximum";
|
|
985
|
+
return OPEN_WHEN_EMPTY.has(keyword) && isOpen(value);
|
|
986
|
+
}
|
|
987
|
+
function typesOf(values) {
|
|
988
|
+
const types = /* @__PURE__ */ new Set();
|
|
989
|
+
for (const value of values) {
|
|
990
|
+
if (value === null) types.add("null");
|
|
991
|
+
else if (Array.isArray(value)) types.add("array");
|
|
992
|
+
else if (typeof value === "number") types.add(Number.isInteger(value) ? "integer" : "number");
|
|
993
|
+
else types.add(typeof value);
|
|
994
|
+
}
|
|
995
|
+
return types;
|
|
996
|
+
}
|
|
997
|
+
function ownValues(object) {
|
|
998
|
+
let values = Array.isArray(object["enum"]) ? object["enum"] : void 0;
|
|
999
|
+
const consts = [...Object.hasOwn(object, "const") ? [object["const"]] : [], ...shadowedIn(object)?.keywords.get("const") ?? []];
|
|
1000
|
+
for (const value of consts) {
|
|
1001
|
+
const key = canonicalize(value);
|
|
1002
|
+
values = values === void 0 ? [value] : values.filter((member) => canonicalize(member) === key);
|
|
1003
|
+
}
|
|
1004
|
+
const typeValue = object["type"];
|
|
1005
|
+
let types = typeof typeValue === "string" ? /* @__PURE__ */ new Set([typeValue]) : Array.isArray(typeValue) ? new Set(typeValue.filter((entry) => typeof entry === "string")) : void 0;
|
|
1006
|
+
if (types === void 0 && values !== void 0) types = typesOf(values);
|
|
1007
|
+
return { types, members: values === void 0 ? void 0 : new Set(values.map((member) => canonicalize(member))) };
|
|
1008
|
+
}
|
|
1009
|
+
function unionOfBranches(branches, root) {
|
|
1010
|
+
let types = /* @__PURE__ */ new Set();
|
|
1011
|
+
let members = /* @__PURE__ */ new Set();
|
|
1012
|
+
let counted = 0;
|
|
1013
|
+
for (const branch of branches) {
|
|
1014
|
+
if (branch === false) continue;
|
|
1015
|
+
const object = effectiveSchema(branch, root);
|
|
1016
|
+
if (object === void 0) return {};
|
|
1017
|
+
const own2 = ownValues(object);
|
|
1018
|
+
const onlyNull = own2.members === void 0 ? own2.types?.size === 1 && own2.types.has("null") : own2.members.size === 1 && own2.members.has("null");
|
|
1019
|
+
if (onlyNull) continue;
|
|
1020
|
+
counted += 1;
|
|
1021
|
+
if (types) {
|
|
1022
|
+
if (own2.types) for (const type of own2.types) types.add(type);
|
|
1023
|
+
else types = void 0;
|
|
1024
|
+
}
|
|
1025
|
+
if (members) {
|
|
1026
|
+
if (own2.members) for (const member of own2.members) members.add(member);
|
|
1027
|
+
else members = void 0;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
return counted === 0 ? {} : { types, members };
|
|
1031
|
+
}
|
|
1032
|
+
var constraintCache = /* @__PURE__ */ new WeakMap();
|
|
1033
|
+
function constraintsOf(object, root) {
|
|
1034
|
+
const key = root !== null && typeof root === "object" ? root : constraintCache;
|
|
1035
|
+
let cache = constraintCache.get(key);
|
|
1036
|
+
if (!cache) {
|
|
1037
|
+
cache = /* @__PURE__ */ new WeakMap();
|
|
1038
|
+
constraintCache.set(key, cache);
|
|
1039
|
+
}
|
|
1040
|
+
const known = cache.get(object);
|
|
1041
|
+
if (known) return known;
|
|
1042
|
+
let { types, members } = ownValues(object);
|
|
1043
|
+
if (types === void 0 || members === void 0) {
|
|
1044
|
+
const anyOf = Array.isArray(object["anyOf"]) ? object["anyOf"] : void 0;
|
|
1045
|
+
const oneOf = Array.isArray(object["oneOf"]) ? object["oneOf"] : void 0;
|
|
1046
|
+
const branches = anyOf && !oneOf ? anyOf : oneOf && !anyOf ? oneOf : void 0;
|
|
1047
|
+
if (branches) {
|
|
1048
|
+
const union = unionOfBranches(branches, root);
|
|
1049
|
+
types ??= union.types;
|
|
1050
|
+
members ??= union.members;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
const lower = /* @__PURE__ */ new Map();
|
|
1054
|
+
const upper = /* @__PURE__ */ new Map();
|
|
1055
|
+
const opaque = /* @__PURE__ */ new Map();
|
|
1056
|
+
const constrain = (keyword, value) => {
|
|
1057
|
+
if (isVacuous(keyword, value)) return;
|
|
1058
|
+
let values = opaque.get(keyword);
|
|
1059
|
+
if (!values) {
|
|
1060
|
+
values = /* @__PURE__ */ new Set();
|
|
1061
|
+
opaque.set(keyword, values);
|
|
1062
|
+
}
|
|
1063
|
+
values.add(canonicalize(value));
|
|
1064
|
+
};
|
|
1065
|
+
for (const [keywords, bounds] of [[LOWER_BOUNDS2, lower], [UPPER_BOUNDS2, upper]]) {
|
|
1066
|
+
for (const keyword of keywords) {
|
|
1067
|
+
const value = object[keyword];
|
|
1068
|
+
if (typeof value === "number") bounds.set(keyword, value);
|
|
1069
|
+
else if (value !== void 0) constrain(keyword, value);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
for (const keyword of OPAQUE) if (object[keyword] !== void 0) constrain(keyword, object[keyword]);
|
|
1073
|
+
const shadow = shadowedIn(object);
|
|
1074
|
+
if (shadow) {
|
|
1075
|
+
for (const [keyword, values] of shadow.keywords) if (CONSIDERED.has(keyword)) for (const value of values) constrain(keyword, value);
|
|
1076
|
+
for (const [name, values] of shadow.properties) for (const value of values) constrain(`\0properties\0${name}`, value);
|
|
1077
|
+
}
|
|
1078
|
+
const slots = /* @__PURE__ */ new Set();
|
|
1079
|
+
const items = object["items"];
|
|
1080
|
+
if (items !== void 0 && !Array.isArray(items) && !isOpen(items)) slots.add("items");
|
|
1081
|
+
for (const keyword of ["anyOf", "oneOf"]) if (Array.isArray(object[keyword])) slots.add(keyword);
|
|
1082
|
+
for (const keyword of ["then", "else"]) if (object[keyword] !== void 0 && !isOpen(object[keyword])) slots.add(keyword);
|
|
1083
|
+
const additionalValue = object["additionalProperties"];
|
|
1084
|
+
const required = Array.isArray(object["required"]) ? object["required"] : [];
|
|
1085
|
+
const constraints = {
|
|
1086
|
+
additional: additionalValue === false ? 0 : asObject(additionalValue) !== void 0 && !isOpen(additionalValue) ? 1 : 2,
|
|
1087
|
+
enumMembers: members,
|
|
1088
|
+
types,
|
|
1089
|
+
lower,
|
|
1090
|
+
upper,
|
|
1091
|
+
opaque,
|
|
1092
|
+
slots,
|
|
1093
|
+
requiredNames: new Set(required.filter((entry) => typeof entry === "string"))
|
|
1094
|
+
};
|
|
1095
|
+
cache.set(object, constraints);
|
|
1096
|
+
return constraints;
|
|
1097
|
+
}
|
|
1098
|
+
var Routes = class {
|
|
1099
|
+
names = /* @__PURE__ */ new Map();
|
|
1100
|
+
ids = /* @__PURE__ */ new Map();
|
|
1101
|
+
child(parent, keyword, name) {
|
|
1102
|
+
let nameId = this.names.get(name);
|
|
1103
|
+
if (nameId === void 0) {
|
|
1104
|
+
nameId = this.names.size;
|
|
1105
|
+
this.names.set(name, nameId);
|
|
1106
|
+
}
|
|
1107
|
+
const key = `${parent} ${keyword} ${nameId}`;
|
|
1108
|
+
let id = this.ids.get(key);
|
|
1109
|
+
if (id === void 0) {
|
|
1110
|
+
id = this.ids.size + 1;
|
|
1111
|
+
this.ids.set(key, id);
|
|
1112
|
+
}
|
|
1113
|
+
return id;
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
function collectFacts(schema, routes) {
|
|
809
1117
|
const facts = /* @__PURE__ */ new Map();
|
|
810
|
-
|
|
811
|
-
|
|
1118
|
+
let budget = MAX_FACTS;
|
|
1119
|
+
const visit = (node, id, parent, via, required, depth) => {
|
|
1120
|
+
if (depth > MAX_VISIT_DEPTH || budget <= 0) return;
|
|
1121
|
+
budget -= 1;
|
|
812
1122
|
const object = effectiveSchema(node, schema);
|
|
813
1123
|
if (!object) return;
|
|
814
|
-
const
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
minimum: numberAt(object, "minimum"),
|
|
823
|
-
maximum: numberAt(object, "maximum"),
|
|
824
|
-
minLength: numberAt(object, "minLength"),
|
|
825
|
-
maxLength: numberAt(object, "maxLength")
|
|
826
|
-
});
|
|
1124
|
+
const constraints = constraintsOf(object, schema);
|
|
1125
|
+
facts.set(id, { parent, via, required, node: constraints });
|
|
1126
|
+
if (depth >= MAX_VISIT_DEPTH) return;
|
|
1127
|
+
const into = (keyword, name, child, isRequired = false) => {
|
|
1128
|
+
if (budget <= 0) return false;
|
|
1129
|
+
if (child !== void 0) visit(child, routes.child(id, keyword, name), id, keyword, isRequired, depth + 1);
|
|
1130
|
+
return true;
|
|
1131
|
+
};
|
|
827
1132
|
const properties = asObject(object["properties"]);
|
|
828
1133
|
if (properties) {
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1134
|
+
for (const [name, child] of entriesOf(properties)) if (!into("properties", name, child, constraints.requiredNames.has(name))) return;
|
|
1135
|
+
}
|
|
1136
|
+
const patternProperties = asObject(object["patternProperties"]);
|
|
1137
|
+
if (patternProperties) {
|
|
1138
|
+
for (const [pattern, child] of entriesOf(patternProperties)) if (!into("patternProperties", pattern, child)) return;
|
|
1139
|
+
}
|
|
1140
|
+
for (const keyword of ["prefixItems", "items"]) {
|
|
1141
|
+
const tuple = object[keyword];
|
|
1142
|
+
if (!Array.isArray(tuple)) continue;
|
|
1143
|
+
for (let index = 0; index < tuple.length; index += 1) if (!into("prefixItems", String(index), tuple[index])) return;
|
|
1144
|
+
}
|
|
1145
|
+
if (constraints.slots.has("items") && !into("items", "", object["items"])) return;
|
|
1146
|
+
if (constraints.additional === 1 && !into("additionalProperties", "", object["additionalProperties"])) return;
|
|
1147
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
1148
|
+
const branches = object[keyword];
|
|
1149
|
+
if (!Array.isArray(branches)) continue;
|
|
1150
|
+
for (let index = 0; index < branches.length; index += 1) if (!into(keyword, String(index), branches[index])) return;
|
|
834
1151
|
}
|
|
835
|
-
const
|
|
836
|
-
if (items !== void 0) visit(items, `${path}[]`, false, depth + 1);
|
|
837
|
-
const prefixItems = object["prefixItems"];
|
|
838
|
-
if (Array.isArray(prefixItems)) prefixItems.forEach((entry, index) => visit(entry, `${path}[${index}]`, false, depth + 1));
|
|
839
|
-
for (const branch of alternatives(object)) visit(branch.schema, `${path}|${branch.label}`, false, depth + 1);
|
|
1152
|
+
for (const keyword of ["then", "else"]) if (constraints.slots.has(keyword) && !into(keyword, "", object[keyword])) return;
|
|
840
1153
|
};
|
|
841
|
-
|
|
1154
|
+
beginWalk(schema);
|
|
1155
|
+
visit(schema, 0, void 0, "", true, 0);
|
|
842
1156
|
return facts;
|
|
843
1157
|
}
|
|
844
1158
|
function isSuperset(next, previous) {
|
|
845
|
-
|
|
846
|
-
|
|
1159
|
+
if (previous.size > next.size) return false;
|
|
1160
|
+
for (const entry of previous) if (!next.has(entry)) return false;
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1163
|
+
function covers(types, type) {
|
|
1164
|
+
return types.has(type) || type === "integer" && types.has("number");
|
|
1165
|
+
}
|
|
1166
|
+
function compareConstraints(a, b) {
|
|
1167
|
+
let widened = false;
|
|
1168
|
+
let narrowed = false;
|
|
1169
|
+
if (b.additional > a.additional) widened = true;
|
|
1170
|
+
else if (b.additional < a.additional) narrowed = true;
|
|
1171
|
+
if (a.enumMembers && b.enumMembers) {
|
|
1172
|
+
if (!isSuperset(b.enumMembers, a.enumMembers)) narrowed = true;
|
|
1173
|
+
if (!isSuperset(a.enumMembers, b.enumMembers)) widened = true;
|
|
1174
|
+
} else if (a.enumMembers && !b.enumMembers) widened = true;
|
|
1175
|
+
else if (!a.enumMembers && b.enumMembers) narrowed = true;
|
|
1176
|
+
if (a.types && b.types) {
|
|
1177
|
+
for (const type of b.types) if (!covers(a.types, type)) widened = true;
|
|
1178
|
+
for (const type of a.types) if (!covers(b.types, type)) narrowed = true;
|
|
1179
|
+
} else if (a.types && !b.types) widened = true;
|
|
1180
|
+
else if (!a.types && b.types) narrowed = true;
|
|
1181
|
+
for (const [keyword, before] of a.lower) {
|
|
1182
|
+
const after = b.lower.get(keyword);
|
|
1183
|
+
if (after === void 0 || after < before) widened = true;
|
|
1184
|
+
if (after !== void 0 && after > before) narrowed = true;
|
|
1185
|
+
}
|
|
1186
|
+
for (const keyword of b.lower.keys()) if (!a.lower.has(keyword)) narrowed = true;
|
|
1187
|
+
for (const [keyword, before] of a.upper) {
|
|
1188
|
+
const after = b.upper.get(keyword);
|
|
1189
|
+
if (after === void 0 || after > before) widened = true;
|
|
1190
|
+
if (after !== void 0 && after < before) narrowed = true;
|
|
1191
|
+
}
|
|
1192
|
+
for (const keyword of b.upper.keys()) if (!a.upper.has(keyword)) narrowed = true;
|
|
1193
|
+
for (const [keyword, before] of a.opaque) {
|
|
1194
|
+
const after = b.opaque.get(keyword);
|
|
1195
|
+
if (!after || !isSuperset(after, before)) widened = true;
|
|
1196
|
+
if (after && !isSuperset(before, after)) narrowed = true;
|
|
1197
|
+
}
|
|
1198
|
+
for (const keyword of b.opaque.keys()) if (!a.opaque.has(keyword)) narrowed = true;
|
|
1199
|
+
for (const keyword of a.slots) if (!b.slots.has(keyword)) widened = true;
|
|
1200
|
+
for (const keyword of b.slots) if (!a.slots.has(keyword)) narrowed = true;
|
|
1201
|
+
return { widened, narrowed };
|
|
847
1202
|
}
|
|
848
1203
|
function classifySchemaChange(before, after) {
|
|
849
1204
|
if (stableKey(before) === stableKey(after)) return "same";
|
|
850
|
-
const
|
|
851
|
-
const
|
|
1205
|
+
const routes = new Routes();
|
|
1206
|
+
const previous = collectFacts(before, routes);
|
|
1207
|
+
const next = collectFacts(after, routes);
|
|
852
1208
|
let widened = false;
|
|
853
1209
|
let narrowed = false;
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
const
|
|
857
|
-
if (
|
|
858
|
-
widened = true;
|
|
859
|
-
|
|
1210
|
+
const compared = /* @__PURE__ */ new Map();
|
|
1211
|
+
const oneSided = (fact, arrived) => {
|
|
1212
|
+
const counterpart = fact.parent === void 0 ? void 0 : (arrived ? previous : next).get(fact.parent);
|
|
1213
|
+
if (counterpart === void 0) {
|
|
1214
|
+
if (arrived && MEMBERS.has(fact.via)) widened = true;
|
|
1215
|
+
return;
|
|
860
1216
|
}
|
|
861
|
-
if (
|
|
862
|
-
|
|
863
|
-
|
|
1217
|
+
if (MEMBERS.has(fact.via) || counterpart.node.slots.has(fact.via)) {
|
|
1218
|
+
if (arrived) widened = true;
|
|
1219
|
+
else narrowed = true;
|
|
864
1220
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
if (
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
narrowed = true;
|
|
887
|
-
}
|
|
888
|
-
} else if (a.types && !b.types) widened = true;
|
|
889
|
-
else if (!a.types && b.types) narrowed = true;
|
|
890
|
-
const lowerBounds = [["minimum", a.minimum, b.minimum], ["minLength", a.minLength, b.minLength]];
|
|
891
|
-
for (const [, before_, after_] of lowerBounds) {
|
|
892
|
-
if (before_ !== void 0 && after_ === void 0) widened = true;
|
|
893
|
-
else if (before_ === void 0 && after_ !== void 0) narrowed = true;
|
|
894
|
-
else if (before_ !== void 0 && after_ !== void 0) {
|
|
895
|
-
if (after_ < before_) widened = true;
|
|
896
|
-
if (after_ > before_) narrowed = true;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
const upperBounds = [["maximum", a.maximum, b.maximum], ["maxLength", a.maxLength, b.maxLength]];
|
|
900
|
-
for (const [, before_, after_] of upperBounds) {
|
|
901
|
-
if (before_ !== void 0 && after_ === void 0) widened = true;
|
|
902
|
-
else if (before_ === void 0 && after_ !== void 0) narrowed = true;
|
|
903
|
-
else if (before_ !== void 0 && after_ !== void 0) {
|
|
904
|
-
if (after_ > before_) widened = true;
|
|
905
|
-
if (after_ < before_) narrowed = true;
|
|
1221
|
+
};
|
|
1222
|
+
for (const [id, a] of previous) {
|
|
1223
|
+
const b = next.get(id);
|
|
1224
|
+
if (!b) {
|
|
1225
|
+
oneSided(a, false);
|
|
1226
|
+
} else {
|
|
1227
|
+
if (a.required && !b.required) widened = true;
|
|
1228
|
+
if (!a.required && b.required) narrowed = true;
|
|
1229
|
+
if (a.node !== b.node) {
|
|
1230
|
+
let row2 = compared.get(a.node);
|
|
1231
|
+
if (!row2) {
|
|
1232
|
+
row2 = /* @__PURE__ */ new Map();
|
|
1233
|
+
compared.set(a.node, row2);
|
|
1234
|
+
}
|
|
1235
|
+
let direction = row2.get(b.node);
|
|
1236
|
+
if (!direction) {
|
|
1237
|
+
direction = compareConstraints(a.node, b.node);
|
|
1238
|
+
row2.set(b.node, direction);
|
|
1239
|
+
}
|
|
1240
|
+
if (direction.widened) widened = true;
|
|
1241
|
+
if (direction.narrowed) narrowed = true;
|
|
906
1242
|
}
|
|
907
1243
|
}
|
|
1244
|
+
if (widened && narrowed) return "changed";
|
|
908
1245
|
}
|
|
1246
|
+
for (const [id, b] of next) if (!previous.has(id)) oneSided(b, true);
|
|
909
1247
|
if (widened && !narrowed) return "widened";
|
|
910
1248
|
if (narrowed && !widened) return "narrowed";
|
|
911
1249
|
return "changed";
|
|
@@ -1016,13 +1354,15 @@ function compareTool(name, before, after) {
|
|
|
1016
1354
|
change("tool.header_params.changed", name, "arguments mirrored into HTTP headers changed", { ...at, before: before.headerParams ?? [], after: after.headerParams ?? [] })
|
|
1017
1355
|
);
|
|
1018
1356
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1357
|
+
const moved = [
|
|
1358
|
+
!same(before.title, after.title) ? "title" : "",
|
|
1359
|
+
// A second title a client shows in place of the name, and the same finding for the same reason.
|
|
1360
|
+
!same(before.annotations?.title, after.annotations?.title) ? "annotations.title" : "",
|
|
1361
|
+
!same(before.icons, after.icons) ? "icons" : "",
|
|
1362
|
+
!same(before.execution, after.execution) ? `how it may be run (${describeExecution(before.execution)} \u2192 ${describeExecution(after.execution)})` : "",
|
|
1363
|
+
!same(before.meta, after.meta) ? "_meta" : ""
|
|
1364
|
+
].filter(Boolean);
|
|
1365
|
+
if (moved.length > 0 || changes.length === 0) {
|
|
1026
1366
|
changes.push(change("tool.changed", name, `tool definition changed: ${moved.length > 0 ? moved.join(", ") : "a field this report has no finding for"}`, { ...at, before, after }));
|
|
1027
1367
|
}
|
|
1028
1368
|
return changes;
|
|
@@ -1238,15 +1578,18 @@ function compareServer(name, before, after) {
|
|
|
1238
1578
|
}
|
|
1239
1579
|
return changes;
|
|
1240
1580
|
}
|
|
1581
|
+
function subjectNamed(lock, name) {
|
|
1582
|
+
return Object.hasOwn(lock.subjects, name) ? lock.subjects[name] : void 0;
|
|
1583
|
+
}
|
|
1241
1584
|
function detectRenames(before, after, removed, added) {
|
|
1242
1585
|
const changes = [];
|
|
1243
1586
|
const renamed = /* @__PURE__ */ new Set();
|
|
1244
1587
|
const availableAdds = [...added];
|
|
1245
1588
|
for (const oldName of removed) {
|
|
1246
|
-
const oldEntry = before
|
|
1589
|
+
const oldEntry = subjectNamed(before, oldName);
|
|
1247
1590
|
if (!oldEntry) continue;
|
|
1248
1591
|
const match = availableAdds.find((newName) => {
|
|
1249
|
-
const candidate = after
|
|
1592
|
+
const candidate = subjectNamed(after, newName);
|
|
1250
1593
|
return candidate !== void 0 && candidate.digest === oldEntry.digest && same(candidate.transport, oldEntry.transport);
|
|
1251
1594
|
});
|
|
1252
1595
|
if (!match) continue;
|
|
@@ -1254,6 +1597,8 @@ function detectRenames(before, after, removed, added) {
|
|
|
1254
1597
|
renamed.add(oldName);
|
|
1255
1598
|
renamed.add(match);
|
|
1256
1599
|
changes.push(change("server.renamed", match, `renamed from "${oldName}"; capabilities are unchanged`, { before: oldName, after: match }));
|
|
1600
|
+
const newEntry = subjectNamed(after, match);
|
|
1601
|
+
if (newEntry) changes.push(...compareProvenance(match, oldEntry, newEntry));
|
|
1257
1602
|
}
|
|
1258
1603
|
return { changes, renamed };
|
|
1259
1604
|
}
|
|
@@ -1266,17 +1611,17 @@ function diffLockfiles(before, after) {
|
|
|
1266
1611
|
const changes = [...renameChanges];
|
|
1267
1612
|
for (const name of added) {
|
|
1268
1613
|
if (renamed.has(name)) continue;
|
|
1269
|
-
const entry = after
|
|
1614
|
+
const entry = subjectNamed(after, name);
|
|
1270
1615
|
const toolCount = entry?.tools?.length ?? 0;
|
|
1271
1616
|
changes.push(change("server.added", name, `new server with ${toolCount} tool${toolCount === 1 ? "" : "s"}`, { after: entry }));
|
|
1272
1617
|
}
|
|
1273
1618
|
for (const name of removed) {
|
|
1274
1619
|
if (renamed.has(name)) continue;
|
|
1275
|
-
changes.push(change("server.removed", name, "server is no longer configured", { before: before
|
|
1620
|
+
changes.push(change("server.removed", name, "server is no longer configured", { before: subjectNamed(before, name) }));
|
|
1276
1621
|
}
|
|
1277
1622
|
for (const name of afterNames) {
|
|
1278
|
-
const a = before
|
|
1279
|
-
const b = after
|
|
1623
|
+
const a = subjectNamed(before, name);
|
|
1624
|
+
const b = subjectNamed(after, name);
|
|
1280
1625
|
if (!a || !b) continue;
|
|
1281
1626
|
changes.push(...compareServer(name, a, b));
|
|
1282
1627
|
}
|
|
@@ -1381,25 +1726,49 @@ function capabilityViolations(lock, denied) {
|
|
|
1381
1726
|
|
|
1382
1727
|
// ../core/src/risk/surface-text.ts
|
|
1383
1728
|
var MAX_NODES = 2e4;
|
|
1729
|
+
var SINGLE_SCHEMAS = ["items", "additionalItems", "additionalProperties", "unevaluatedItems", "unevaluatedProperties", "contains", "propertyNames", "not", "if", "then", "else", "contentSchema"];
|
|
1730
|
+
var SCHEMA_LISTS = ["items", "prefixItems", "allOf", "anyOf", "oneOf"];
|
|
1731
|
+
var NAMED_SCHEMAS2 = ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"];
|
|
1732
|
+
var VALUES = ["enum", "const", "default", "examples"];
|
|
1384
1733
|
function schemaText(root, rootPath, out) {
|
|
1385
1734
|
const stack = [{ node: root, path: rootPath }];
|
|
1386
1735
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
1387
1736
|
let budget = MAX_NODES;
|
|
1737
|
+
let values = MAX_NODES;
|
|
1388
1738
|
while (stack.length > 0 && budget-- > 0) {
|
|
1389
1739
|
const { node, path } = stack.pop();
|
|
1390
|
-
if (typeof node !== "object" || node === null) continue;
|
|
1740
|
+
if (typeof node !== "object" || node === null || Array.isArray(node)) continue;
|
|
1391
1741
|
if (seen.has(node)) continue;
|
|
1392
1742
|
seen.add(node);
|
|
1393
1743
|
const schema = node;
|
|
1394
|
-
if (typeof schema
|
|
1395
|
-
if (typeof schema
|
|
1396
|
-
const
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1744
|
+
if (typeof schema["description"] === "string") out.push({ field: path, text: schema["description"] });
|
|
1745
|
+
if (typeof schema["title"] === "string") out.push({ field: `${path}.title`, text: schema["title"] });
|
|
1746
|
+
for (const keyword of VALUES) {
|
|
1747
|
+
const value = schema[keyword];
|
|
1748
|
+
const strings = Array.isArray(value) ? value : [value];
|
|
1749
|
+
for (const [index, entry] of strings.entries()) {
|
|
1750
|
+
if (values <= 0) break;
|
|
1751
|
+
if (typeof entry !== "string" || entry.length === 0) continue;
|
|
1752
|
+
values -= 1;
|
|
1753
|
+
out.push({ field: Array.isArray(value) ? `${path}.${keyword}[${index}]` : `${path}.${keyword}`, text: entry });
|
|
1400
1754
|
}
|
|
1401
1755
|
}
|
|
1402
|
-
|
|
1756
|
+
for (const keyword of NAMED_SCHEMAS2) {
|
|
1757
|
+
const named = schema[keyword];
|
|
1758
|
+
if (typeof named !== "object" || named === null || Array.isArray(named)) continue;
|
|
1759
|
+
const prefix = keyword === "properties" ? path : `${path}.${keyword}`;
|
|
1760
|
+
for (const [name, child] of Object.entries(named)) stack.push({ node: child, path: `${prefix}.${name}` });
|
|
1761
|
+
}
|
|
1762
|
+
for (const keyword of SCHEMA_LISTS) {
|
|
1763
|
+
const list = schema[keyword];
|
|
1764
|
+
if (!Array.isArray(list)) continue;
|
|
1765
|
+
list.forEach((child, index) => stack.push({ node: child, path: `${path}.${keyword}[${index}]` }));
|
|
1766
|
+
}
|
|
1767
|
+
for (const keyword of SINGLE_SCHEMAS) {
|
|
1768
|
+
const child = schema[keyword];
|
|
1769
|
+
if (child === void 0 || Array.isArray(child)) continue;
|
|
1770
|
+
stack.push({ node: child, path: keyword === "items" ? `${path}[]` : `${path}.${keyword}` });
|
|
1771
|
+
}
|
|
1403
1772
|
}
|
|
1404
1773
|
}
|
|
1405
1774
|
function surfaceText(subject) {
|
|
@@ -1437,8 +1806,8 @@ function surfaceText(subject) {
|
|
|
1437
1806
|
}
|
|
1438
1807
|
|
|
1439
1808
|
// ../core/src/risk/arrival.ts
|
|
1440
|
-
function identity(
|
|
1441
|
-
return `${
|
|
1809
|
+
function identity(signal2) {
|
|
1810
|
+
return `${signal2.field}\0${signal2.kind}\0${signal2.quote}`;
|
|
1442
1811
|
}
|
|
1443
1812
|
function signalsFor(subject) {
|
|
1444
1813
|
if (typeof subject !== "object" || subject === null) return [];
|
|
@@ -1449,8 +1818,9 @@ function signalsFor(subject) {
|
|
|
1449
1818
|
function newSteering(committed, observed) {
|
|
1450
1819
|
const found = [];
|
|
1451
1820
|
for (const [server2, subject] of Object.entries(observed.subjects ?? {})) {
|
|
1452
|
-
const
|
|
1453
|
-
const
|
|
1821
|
+
const approved = committed.subjects && Object.hasOwn(committed.subjects, server2) ? committed.subjects[server2] : void 0;
|
|
1822
|
+
const before = new Set(signalsFor(approved).map(identity));
|
|
1823
|
+
const signals = signalsFor(subject).filter((signal2) => !before.has(identity(signal2)));
|
|
1454
1824
|
if (signals.length > 0) found.push({ server: server2, signals });
|
|
1455
1825
|
}
|
|
1456
1826
|
return found.sort((a, b) => a.server.localeCompare(b.server));
|
|
@@ -1499,6 +1869,133 @@ import { readFile } from "fs/promises";
|
|
|
1499
1869
|
import { resolve } from "path";
|
|
1500
1870
|
import { z } from "zod";
|
|
1501
1871
|
|
|
1872
|
+
// src/lock/build.ts
|
|
1873
|
+
function byName(members) {
|
|
1874
|
+
return [...members].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1875
|
+
}
|
|
1876
|
+
function lockIcons(icons) {
|
|
1877
|
+
if (!icons || icons.length === 0) return void 0;
|
|
1878
|
+
return icons.map((icon2) => ({
|
|
1879
|
+
src: icon2.src,
|
|
1880
|
+
mimeType: icon2.mimeType,
|
|
1881
|
+
sizes: icon2.sizes,
|
|
1882
|
+
theme: icon2.theme
|
|
1883
|
+
}));
|
|
1884
|
+
}
|
|
1885
|
+
function sealed(entry) {
|
|
1886
|
+
return { ...entry, digest: digest(toJson(entry)) };
|
|
1887
|
+
}
|
|
1888
|
+
function lockTransport(server2) {
|
|
1889
|
+
const { transport: transport2 } = server2;
|
|
1890
|
+
if (transport2.type === "stdio") {
|
|
1891
|
+
const command = transport2.asWritten?.command ?? transport2.command;
|
|
1892
|
+
const args = redactArgs(transport2.asWritten?.args ?? transport2.args);
|
|
1893
|
+
return {
|
|
1894
|
+
type: "stdio",
|
|
1895
|
+
command,
|
|
1896
|
+
args: args.length > 0 ? args : void 0,
|
|
1897
|
+
envKeys: Object.keys(transport2.env).length > 0 ? Object.keys(transport2.env).sort() : void 0,
|
|
1898
|
+
cwd: transport2.asWritten ? transport2.asWritten.cwd : transport2.cwd
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
const headerKeys = Object.keys(transport2.headers);
|
|
1902
|
+
return {
|
|
1903
|
+
type: transport2.type,
|
|
1904
|
+
url: sanitizeUrl(transport2.asWritten?.url ?? transport2.url),
|
|
1905
|
+
headerKeys: headerKeys.length > 0 ? headerKeys.sort() : void 0
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
function lockTool(tool2, ignoredMeta) {
|
|
1909
|
+
const annotations2 = tool2.annotations;
|
|
1910
|
+
const inputSchema = normalizeSchema(toJson(tool2.inputSchema));
|
|
1911
|
+
const headerParams = extractHeaderParams(inputSchema);
|
|
1912
|
+
return sealed({
|
|
1913
|
+
name: tool2.name,
|
|
1914
|
+
title: tool2.title,
|
|
1915
|
+
description: tool2.description,
|
|
1916
|
+
inputSchema,
|
|
1917
|
+
outputSchema: tool2.outputSchema ? normalizeSchema(toJson(tool2.outputSchema)) : void 0,
|
|
1918
|
+
annotations: annotations2 ? { ...annotations2 } : void 0,
|
|
1919
|
+
behavior: resolveBehavior(annotations2),
|
|
1920
|
+
headerParams: headerParams.length > 0 ? headerParams : void 0,
|
|
1921
|
+
icons: lockIcons(tool2.icons),
|
|
1922
|
+
execution: tool2.execution ? toJson(tool2.execution) : void 0,
|
|
1923
|
+
meta: stripIgnoredMeta(toJson(tool2._meta), ignoredMeta)
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
function lockResource(resource2, ignoredMeta) {
|
|
1927
|
+
return sealed({
|
|
1928
|
+
uri: resource2.uri,
|
|
1929
|
+
name: resource2.name,
|
|
1930
|
+
title: resource2.title,
|
|
1931
|
+
description: resource2.description,
|
|
1932
|
+
mimeType: resource2.mimeType,
|
|
1933
|
+
annotations: resource2.annotations ? toJson(resource2.annotations) : void 0,
|
|
1934
|
+
icons: lockIcons(resource2.icons),
|
|
1935
|
+
meta: stripIgnoredMeta(toJson(resource2._meta), ignoredMeta)
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
function lockResourceTemplate(template, ignoredMeta) {
|
|
1939
|
+
return sealed({
|
|
1940
|
+
uriTemplate: template.uriTemplate,
|
|
1941
|
+
name: template.name,
|
|
1942
|
+
title: template.title,
|
|
1943
|
+
description: template.description,
|
|
1944
|
+
mimeType: template.mimeType,
|
|
1945
|
+
annotations: template.annotations ? toJson(template.annotations) : void 0,
|
|
1946
|
+
icons: lockIcons(template.icons),
|
|
1947
|
+
meta: stripIgnoredMeta(toJson(template._meta), ignoredMeta)
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
function lockPrompt(prompt2, ignoredMeta) {
|
|
1951
|
+
return sealed({
|
|
1952
|
+
name: prompt2.name,
|
|
1953
|
+
title: prompt2.title,
|
|
1954
|
+
description: prompt2.description,
|
|
1955
|
+
arguments: prompt2.arguments && prompt2.arguments.length > 0 ? prompt2.arguments.map((argument) => ({
|
|
1956
|
+
name: argument.name,
|
|
1957
|
+
// The spec gives PromptArgument a `title` (it extends BaseMetadata); the SDK's type
|
|
1958
|
+
// has not caught up, so it is read off the wire rather than skipped.
|
|
1959
|
+
title: argument.title,
|
|
1960
|
+
description: argument.description,
|
|
1961
|
+
required: argument.required
|
|
1962
|
+
})) : void 0,
|
|
1963
|
+
icons: lockIcons(prompt2.icons),
|
|
1964
|
+
meta: stripIgnoredMeta(toJson(prompt2._meta), ignoredMeta)
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
function buildLockedServer(server2, surface, policy) {
|
|
1968
|
+
const ignoredMeta = policy?.ignoreMetaPrefixes ?? [];
|
|
1969
|
+
const tools = byName(surface.tools).map((tool2) => lockTool(tool2, ignoredMeta));
|
|
1970
|
+
const resources = byName(surface.resources).map((resource2) => lockResource(resource2, ignoredMeta));
|
|
1971
|
+
const resourceTemplates = byName(surface.resourceTemplates).map((template) => lockResourceTemplate(template, ignoredMeta));
|
|
1972
|
+
const prompts = byName(surface.prompts).map((prompt2) => lockPrompt(prompt2, ignoredMeta));
|
|
1973
|
+
const entry = {
|
|
1974
|
+
source: server2.source,
|
|
1975
|
+
transport: lockTransport(server2),
|
|
1976
|
+
protocol: surface.protocol,
|
|
1977
|
+
serverInfo: surface.serverInfo,
|
|
1978
|
+
capabilities: surface.capabilities,
|
|
1979
|
+
instructions: surface.instructions,
|
|
1980
|
+
tools: tools.length > 0 ? tools : void 0,
|
|
1981
|
+
resources: resources.length > 0 ? resources : void 0,
|
|
1982
|
+
resourceTemplates: resourceTemplates.length > 0 ? resourceTemplates : void 0,
|
|
1983
|
+
prompts: prompts.length > 0 ? prompts : void 0
|
|
1984
|
+
};
|
|
1985
|
+
const covered = {
|
|
1986
|
+
transport: entry.transport,
|
|
1987
|
+
protocol: entry.protocol,
|
|
1988
|
+
serverInfo: entry.serverInfo,
|
|
1989
|
+
capabilities: entry.capabilities,
|
|
1990
|
+
instructions: entry.instructions,
|
|
1991
|
+
tools: tools.map((tool2) => tool2.digest),
|
|
1992
|
+
resources: resources.map((resource2) => resource2.digest),
|
|
1993
|
+
resourceTemplates: resourceTemplates.map((template) => template.digest),
|
|
1994
|
+
prompts: prompts.map((prompt2) => prompt2.digest)
|
|
1995
|
+
};
|
|
1996
|
+
return { kind: "mcp-server", ...entry, ...surface.coverage ? { coverage: surface.coverage } : {}, digest: digest(toJson(covered)) };
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1502
1999
|
// src/config/expand.ts
|
|
1503
2000
|
import { homedir } from "os";
|
|
1504
2001
|
var PLACEHOLDER2 = /\$\{([^}]+)\}/g;
|
|
@@ -1519,6 +2016,7 @@ function isRunCredential(name) {
|
|
|
1519
2016
|
function expand(input, context) {
|
|
1520
2017
|
const unresolved = [];
|
|
1521
2018
|
const refused = [];
|
|
2019
|
+
const filled = [];
|
|
1522
2020
|
const value = input.replace(PLACEHOLDER2, (match, body) => {
|
|
1523
2021
|
const named = body.startsWith("env:") ? body.slice(4) : body.includes(":-") ? body.slice(0, body.indexOf(":-")) : body;
|
|
1524
2022
|
if (isRunCredential(named)) {
|
|
@@ -1535,21 +2033,30 @@ function expand(input, context) {
|
|
|
1535
2033
|
if (body.startsWith("env:")) {
|
|
1536
2034
|
const name = body.slice(4);
|
|
1537
2035
|
const found2 = context.env[name];
|
|
1538
|
-
if (found2 !== void 0)
|
|
2036
|
+
if (found2 !== void 0) {
|
|
2037
|
+
filled.push({ name, value: found2 });
|
|
2038
|
+
return found2;
|
|
2039
|
+
}
|
|
1539
2040
|
unresolved.push(match);
|
|
1540
2041
|
return match;
|
|
1541
2042
|
}
|
|
1542
2043
|
const defaultAt = body.indexOf(":-");
|
|
1543
2044
|
if (defaultAt !== -1) {
|
|
1544
2045
|
const name = body.slice(0, defaultAt);
|
|
1545
|
-
|
|
2046
|
+
const found2 = context.env[name];
|
|
2047
|
+
if (found2 === void 0) return body.slice(defaultAt + 2);
|
|
2048
|
+
filled.push({ name, value: found2 });
|
|
2049
|
+
return found2;
|
|
1546
2050
|
}
|
|
1547
2051
|
const found = context.env[body];
|
|
1548
|
-
if (found !== void 0)
|
|
2052
|
+
if (found !== void 0) {
|
|
2053
|
+
filled.push({ name: body, value: found });
|
|
2054
|
+
return found;
|
|
2055
|
+
}
|
|
1549
2056
|
unresolved.push(match);
|
|
1550
2057
|
return match;
|
|
1551
2058
|
});
|
|
1552
|
-
return { value, unresolved, refused };
|
|
2059
|
+
return { value, unresolved, refused, filled };
|
|
1553
2060
|
}
|
|
1554
2061
|
|
|
1555
2062
|
// src/config/parsers.ts
|
|
@@ -1578,6 +2085,16 @@ var UnsupportedServerError = class extends Error {
|
|
|
1578
2085
|
this.name = "UnsupportedServerError";
|
|
1579
2086
|
}
|
|
1580
2087
|
serverName;
|
|
2088
|
+
/**
|
|
2089
|
+
* How the definition reaches its server, written down as the lock writes a pinned one, where
|
|
2090
|
+
* that could be read: unexpanded, with literal credentials left out. Absent for a definition
|
|
2091
|
+
* with no transport to read (WebSocket, no command, not a server definition at all).
|
|
2092
|
+
*
|
|
2093
|
+
* An agreement to leave the server unaudited is an agreement to this. It was `{}`, and `check`
|
|
2094
|
+
* compared nothing with nothing: a pull request could rewrite an agreed server to `bash -c
|
|
2095
|
+
* "curl ... | sh"`, keep the `${input:...}` placeholder that kept it from being run, and pass.
|
|
2096
|
+
*/
|
|
2097
|
+
transport;
|
|
1581
2098
|
};
|
|
1582
2099
|
function scalarsToStrings(record) {
|
|
1583
2100
|
const out = {};
|
|
@@ -1594,13 +2111,33 @@ function refusedCredentials(name, refused) {
|
|
|
1594
2111
|
`configuration uses ${names.join(", ")}, which ${names.length === 1 ? "holds" : "hold"} this run's own credentials (the CI job's token or identity, or Nulladrift's). They are never given to a server under audit. Give the server a credential of its own.`
|
|
1595
2112
|
);
|
|
1596
2113
|
}
|
|
2114
|
+
function writtenTransport(entry) {
|
|
2115
|
+
const declared = entry.type === "streamable-http" ? "http" : entry.type;
|
|
2116
|
+
if (declared === "ws") return void 0;
|
|
2117
|
+
if (declared === "http" || declared === "sse" || declared === void 0 && entry.url !== void 0) {
|
|
2118
|
+
if (entry.url === void 0) return void 0;
|
|
2119
|
+
return { type: declared === "sse" ? "sse" : "http", url: entry.url, asWritten: { url: entry.url }, headers: scalarsToStrings(entry.headers) };
|
|
2120
|
+
}
|
|
2121
|
+
if (entry.command === void 0) return void 0;
|
|
2122
|
+
const args = (entry.args ?? []).map((argument) => String(argument));
|
|
2123
|
+
return {
|
|
2124
|
+
type: "stdio",
|
|
2125
|
+
command: entry.command,
|
|
2126
|
+
args,
|
|
2127
|
+
asWritten: { command: entry.command, args, ...entry.cwd ? { cwd: entry.cwd } : {} },
|
|
2128
|
+
env: scalarsToStrings(entry.env),
|
|
2129
|
+
cwd: entry.cwd
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
1597
2132
|
function resolveTransport(name, entry, context) {
|
|
1598
2133
|
const unresolved = [];
|
|
1599
2134
|
const refused = [];
|
|
2135
|
+
const filled = [];
|
|
1600
2136
|
const take = (input) => {
|
|
1601
2137
|
const result = expand(input, context);
|
|
1602
2138
|
unresolved.push(...result.unresolved);
|
|
1603
2139
|
refused.push(...result.refused);
|
|
2140
|
+
filled.push(...result.filled);
|
|
1604
2141
|
return result.value;
|
|
1605
2142
|
};
|
|
1606
2143
|
const declared = entry.type === "streamable-http" ? "http" : entry.type;
|
|
@@ -1647,6 +2184,7 @@ function resolveTransport(name, entry, context) {
|
|
|
1647
2184
|
"oauth.clientSecret is set without oauth.issuer. Set oauth.issuer to the authorization server's issuer URL, so the secret can only be sent there and not to an authorization server the MCP server chooses."
|
|
1648
2185
|
);
|
|
1649
2186
|
}
|
|
2187
|
+
if (filled.length > 0) transport2.filled = filled;
|
|
1650
2188
|
if (refused.length > 0) throw refusedCredentials(name, refused);
|
|
1651
2189
|
if (unresolved.length > 0) {
|
|
1652
2190
|
const names = [...new Set(unresolved)].join(", ");
|
|
@@ -1727,8 +2265,10 @@ async function parseServerMap(raw, mapKey, source, context) {
|
|
|
1727
2265
|
}
|
|
1728
2266
|
servers.push({ name, source: { ...source }, transport: transport2 });
|
|
1729
2267
|
} catch (error) {
|
|
1730
|
-
if (error instanceof UnsupportedServerError)
|
|
1731
|
-
|
|
2268
|
+
if (!(error instanceof UnsupportedServerError)) throw error;
|
|
2269
|
+
const written = writtenTransport(entry.data);
|
|
2270
|
+
if (written) error.transport = lockTransport({ name, source: { ...source }, transport: written });
|
|
2271
|
+
skipped.push(error);
|
|
1732
2272
|
}
|
|
1733
2273
|
}
|
|
1734
2274
|
return { servers, skipped };
|
|
@@ -1895,140 +2435,13 @@ function lowercased(headers) {
|
|
|
1895
2435
|
return Object.fromEntries(Object.entries(headers).map(([name, value]) => [name.toLowerCase(), value]));
|
|
1896
2436
|
}
|
|
1897
2437
|
|
|
1898
|
-
// src/lock/build.ts
|
|
1899
|
-
function byName(members) {
|
|
1900
|
-
return [...members].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1901
|
-
}
|
|
1902
|
-
function lockIcons(icons) {
|
|
1903
|
-
if (!icons || icons.length === 0) return void 0;
|
|
1904
|
-
return icons.map((icon2) => ({
|
|
1905
|
-
src: icon2.src,
|
|
1906
|
-
mimeType: icon2.mimeType,
|
|
1907
|
-
sizes: icon2.sizes,
|
|
1908
|
-
theme: icon2.theme
|
|
1909
|
-
}));
|
|
1910
|
-
}
|
|
1911
|
-
function sealed(entry) {
|
|
1912
|
-
return { ...entry, digest: digest(toJson(entry)) };
|
|
1913
|
-
}
|
|
1914
|
-
function lockTransport(server2) {
|
|
1915
|
-
const { transport: transport2 } = server2;
|
|
1916
|
-
if (transport2.type === "stdio") {
|
|
1917
|
-
const command = transport2.asWritten?.command ?? transport2.command;
|
|
1918
|
-
const args = redactArgs(transport2.asWritten?.args ?? transport2.args);
|
|
1919
|
-
return {
|
|
1920
|
-
type: "stdio",
|
|
1921
|
-
command,
|
|
1922
|
-
args: args.length > 0 ? args : void 0,
|
|
1923
|
-
envKeys: Object.keys(transport2.env).length > 0 ? Object.keys(transport2.env).sort() : void 0,
|
|
1924
|
-
cwd: transport2.asWritten ? transport2.asWritten.cwd : transport2.cwd
|
|
1925
|
-
};
|
|
1926
|
-
}
|
|
1927
|
-
const headerKeys = Object.keys(transport2.headers);
|
|
1928
|
-
return {
|
|
1929
|
-
type: transport2.type,
|
|
1930
|
-
url: sanitizeUrl(transport2.asWritten?.url ?? transport2.url),
|
|
1931
|
-
headerKeys: headerKeys.length > 0 ? headerKeys.sort() : void 0
|
|
1932
|
-
};
|
|
1933
|
-
}
|
|
1934
|
-
function lockTool(tool2, ignoredMeta) {
|
|
1935
|
-
const annotations2 = tool2.annotations;
|
|
1936
|
-
const inputSchema = normalizeSchema(toJson(tool2.inputSchema));
|
|
1937
|
-
const headerParams = extractHeaderParams(inputSchema);
|
|
1938
|
-
return sealed({
|
|
1939
|
-
name: tool2.name,
|
|
1940
|
-
title: tool2.title,
|
|
1941
|
-
description: tool2.description,
|
|
1942
|
-
inputSchema,
|
|
1943
|
-
outputSchema: tool2.outputSchema ? normalizeSchema(toJson(tool2.outputSchema)) : void 0,
|
|
1944
|
-
annotations: annotations2 ? { ...annotations2 } : void 0,
|
|
1945
|
-
behavior: resolveBehavior(annotations2),
|
|
1946
|
-
headerParams: headerParams.length > 0 ? headerParams : void 0,
|
|
1947
|
-
icons: lockIcons(tool2.icons),
|
|
1948
|
-
execution: tool2.execution ? toJson(tool2.execution) : void 0,
|
|
1949
|
-
meta: stripIgnoredMeta(toJson(tool2._meta), ignoredMeta)
|
|
1950
|
-
});
|
|
1951
|
-
}
|
|
1952
|
-
function lockResource(resource2, ignoredMeta) {
|
|
1953
|
-
return sealed({
|
|
1954
|
-
uri: resource2.uri,
|
|
1955
|
-
name: resource2.name,
|
|
1956
|
-
title: resource2.title,
|
|
1957
|
-
description: resource2.description,
|
|
1958
|
-
mimeType: resource2.mimeType,
|
|
1959
|
-
annotations: resource2.annotations ? toJson(resource2.annotations) : void 0,
|
|
1960
|
-
icons: lockIcons(resource2.icons),
|
|
1961
|
-
meta: stripIgnoredMeta(toJson(resource2._meta), ignoredMeta)
|
|
1962
|
-
});
|
|
1963
|
-
}
|
|
1964
|
-
function lockResourceTemplate(template, ignoredMeta) {
|
|
1965
|
-
return sealed({
|
|
1966
|
-
uriTemplate: template.uriTemplate,
|
|
1967
|
-
name: template.name,
|
|
1968
|
-
title: template.title,
|
|
1969
|
-
description: template.description,
|
|
1970
|
-
mimeType: template.mimeType,
|
|
1971
|
-
annotations: template.annotations ? toJson(template.annotations) : void 0,
|
|
1972
|
-
icons: lockIcons(template.icons),
|
|
1973
|
-
meta: stripIgnoredMeta(toJson(template._meta), ignoredMeta)
|
|
1974
|
-
});
|
|
1975
|
-
}
|
|
1976
|
-
function lockPrompt(prompt2, ignoredMeta) {
|
|
1977
|
-
return sealed({
|
|
1978
|
-
name: prompt2.name,
|
|
1979
|
-
title: prompt2.title,
|
|
1980
|
-
description: prompt2.description,
|
|
1981
|
-
arguments: prompt2.arguments && prompt2.arguments.length > 0 ? prompt2.arguments.map((argument) => ({
|
|
1982
|
-
name: argument.name,
|
|
1983
|
-
// The spec gives PromptArgument a `title` (it extends BaseMetadata); the SDK's type
|
|
1984
|
-
// has not caught up, so it is read off the wire rather than skipped.
|
|
1985
|
-
title: argument.title,
|
|
1986
|
-
description: argument.description,
|
|
1987
|
-
required: argument.required
|
|
1988
|
-
})) : void 0,
|
|
1989
|
-
icons: lockIcons(prompt2.icons),
|
|
1990
|
-
meta: stripIgnoredMeta(toJson(prompt2._meta), ignoredMeta)
|
|
1991
|
-
});
|
|
1992
|
-
}
|
|
1993
|
-
function buildLockedServer(server2, surface, policy) {
|
|
1994
|
-
const ignoredMeta = policy?.ignoreMetaPrefixes ?? [];
|
|
1995
|
-
const tools = byName(surface.tools).map((tool2) => lockTool(tool2, ignoredMeta));
|
|
1996
|
-
const resources = byName(surface.resources).map((resource2) => lockResource(resource2, ignoredMeta));
|
|
1997
|
-
const resourceTemplates = byName(surface.resourceTemplates).map((template) => lockResourceTemplate(template, ignoredMeta));
|
|
1998
|
-
const prompts = byName(surface.prompts).map((prompt2) => lockPrompt(prompt2, ignoredMeta));
|
|
1999
|
-
const entry = {
|
|
2000
|
-
source: server2.source,
|
|
2001
|
-
transport: lockTransport(server2),
|
|
2002
|
-
protocol: surface.protocol,
|
|
2003
|
-
serverInfo: surface.serverInfo,
|
|
2004
|
-
capabilities: surface.capabilities,
|
|
2005
|
-
instructions: surface.instructions,
|
|
2006
|
-
tools: tools.length > 0 ? tools : void 0,
|
|
2007
|
-
resources: resources.length > 0 ? resources : void 0,
|
|
2008
|
-
resourceTemplates: resourceTemplates.length > 0 ? resourceTemplates : void 0,
|
|
2009
|
-
prompts: prompts.length > 0 ? prompts : void 0
|
|
2010
|
-
};
|
|
2011
|
-
const covered = {
|
|
2012
|
-
transport: entry.transport,
|
|
2013
|
-
protocol: entry.protocol,
|
|
2014
|
-
serverInfo: entry.serverInfo,
|
|
2015
|
-
capabilities: entry.capabilities,
|
|
2016
|
-
instructions: entry.instructions,
|
|
2017
|
-
tools: tools.map((tool2) => tool2.digest),
|
|
2018
|
-
resources: resources.map((resource2) => resource2.digest),
|
|
2019
|
-
resourceTemplates: resourceTemplates.map((template) => template.digest),
|
|
2020
|
-
prompts: prompts.map((prompt2) => prompt2.digest)
|
|
2021
|
-
};
|
|
2022
|
-
return { kind: "mcp-server", ...entry, ...surface.coverage ? { coverage: surface.coverage } : {}, digest: digest(toJson(covered)) };
|
|
2023
|
-
}
|
|
2024
|
-
|
|
2025
2438
|
// src/lock/provenance.ts
|
|
2026
2439
|
import { createHash as createHash2 } from "crypto";
|
|
2027
2440
|
import { readFile as readFile3 } from "fs/promises";
|
|
2028
2441
|
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
2029
2442
|
|
|
2030
2443
|
// src/lib/version.ts
|
|
2031
|
-
var VERSION = "0.
|
|
2444
|
+
var VERSION = "0.11.0";
|
|
2032
2445
|
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
2033
2446
|
|
|
2034
2447
|
// src/lock/provenance.ts
|
|
@@ -2309,6 +2722,35 @@ function isExact(reference) {
|
|
|
2309
2722
|
return false;
|
|
2310
2723
|
}
|
|
2311
2724
|
}
|
|
2725
|
+
function floatingRequest(reference, provenance2) {
|
|
2726
|
+
const found = provenance2?.ecosystem === reference.ecosystem && provenance2.name === reference.name ? provenance2 : void 0;
|
|
2727
|
+
switch (reference.ecosystem) {
|
|
2728
|
+
case "npm":
|
|
2729
|
+
if (isExact(reference)) return void 0;
|
|
2730
|
+
return {
|
|
2731
|
+
ecosystem: "npm",
|
|
2732
|
+
name: reference.name,
|
|
2733
|
+
asked: reference.requested === void 0 ? reference.name : `${reference.name}@${reference.requested}`,
|
|
2734
|
+
...found?.version === void 0 ? {} : { exact: `${reference.name}@${found.version}` }
|
|
2735
|
+
};
|
|
2736
|
+
case "pypi": {
|
|
2737
|
+
if (isExact(reference)) return void 0;
|
|
2738
|
+
const asked = reference.requested === void 0 ? reference.name : /^[=<>~!]/.test(reference.requested) ? `${reference.name}${reference.requested}` : `${reference.name}@${reference.requested}`;
|
|
2739
|
+
return { ecosystem: "pypi", name: reference.name, asked, ...found?.version === void 0 ? {} : { exact: `${reference.name}==${found.version}` } };
|
|
2740
|
+
}
|
|
2741
|
+
case "oci":
|
|
2742
|
+
if (reference.digest !== void 0 || reference.requested !== "latest") return void 0;
|
|
2743
|
+
return {
|
|
2744
|
+
ecosystem: "oci",
|
|
2745
|
+
name: reference.name,
|
|
2746
|
+
asked: `${reference.name}:latest`,
|
|
2747
|
+
// By digest, the only name for an image that cannot be pointed somewhere else.
|
|
2748
|
+
...found?.integrity === void 0 ? {} : { exact: `${reference.name}@${found.integrity}` }
|
|
2749
|
+
};
|
|
2750
|
+
case "file":
|
|
2751
|
+
return void 0;
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2312
2754
|
var NPM_PUBLIC = "https://registry.npmjs.org";
|
|
2313
2755
|
function npmEnv(env, name) {
|
|
2314
2756
|
const wanted = name.toLowerCase();
|
|
@@ -2521,6 +2963,14 @@ function ancestors(start) {
|
|
|
2521
2963
|
function npmPrefix(start) {
|
|
2522
2964
|
return ancestors(start).find((dir) => existsSync(join2(dir, "package.json")) || existsSync(join2(dir, "node_modules"))) ?? resolve4(start);
|
|
2523
2965
|
}
|
|
2966
|
+
function installedCopy(transport2, reference, context) {
|
|
2967
|
+
const name = commandName(transport2.command);
|
|
2968
|
+
if (name === "pnpm" || name === "yarn" || name === "pnpx") return false;
|
|
2969
|
+
const bin = reference.name.split("/").pop();
|
|
2970
|
+
return ancestors(transport2.cwd ?? context.projectRoot).some(
|
|
2971
|
+
(dir) => existsSync(join2(dir, "node_modules", ...reference.name.split("/"), "package.json")) || existsSync(join2(dir, "node_modules", ".bin", bin))
|
|
2972
|
+
);
|
|
2973
|
+
}
|
|
2524
2974
|
function npmElsewhere(transport2, reference, context) {
|
|
2525
2975
|
const env = context.env ?? process.env;
|
|
2526
2976
|
const name = commandName(transport2.command);
|
|
@@ -2528,14 +2978,7 @@ function npmElsewhere(transport2, reference, context) {
|
|
|
2528
2978
|
const launcherEnv = { ...env, ...transport2.env };
|
|
2529
2979
|
const options = launcherOptions(afterSubcommand(name, transport2.args), NPM_VALUE_FLAGS, ["-p", "--package"]);
|
|
2530
2980
|
const prefix = npmPrefix(base);
|
|
2531
|
-
if (
|
|
2532
|
-
const bin = reference.name.split("/").pop();
|
|
2533
|
-
for (const dir of ancestors(base)) {
|
|
2534
|
-
if (existsSync(join2(dir, "node_modules", ...reference.name.split("/"), "package.json")) || existsSync(join2(dir, "node_modules", ".bin", bin))) {
|
|
2535
|
-
return "a copy installed in node_modules runs instead of the registry's";
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2981
|
+
if (installedCopy(transport2, reference, context)) return "a copy installed in node_modules runs instead of the registry's";
|
|
2539
2982
|
const cli = new Map(options.filter(([flag]) => flag.startsWith("--")).map(([flag, value]) => [flag.slice(2), value ?? ""]));
|
|
2540
2983
|
const userconfig = cli.get("userconfig") ?? npmEnv(launcherEnv, "npm_config_userconfig");
|
|
2541
2984
|
const levels = [
|
|
@@ -2832,6 +3275,12 @@ function createAuthProvider(server2, options = {}) {
|
|
|
2832
3275
|
|
|
2833
3276
|
// src/mcp/types.ts
|
|
2834
3277
|
import { UnauthorizedError as UnauthorizedError2 } from "@modelcontextprotocol/client";
|
|
3278
|
+
var MAX_REASON_CHARS = 2048;
|
|
3279
|
+
function boundReason(text, limit = MAX_REASON_CHARS) {
|
|
3280
|
+
if (text.length <= limit) return text;
|
|
3281
|
+
const kept = text.slice(0, limit).replace(/\S*$/, "").trimEnd();
|
|
3282
|
+
return `${kept} \u2026 (${text.length - kept.length} more characters)`;
|
|
3283
|
+
}
|
|
2835
3284
|
var UnreachableServerError = class extends Error {
|
|
2836
3285
|
constructor(serverName, message, cause) {
|
|
2837
3286
|
super(message);
|
|
@@ -3071,13 +3520,50 @@ function buildTransport(server2, captureStderr = () => {
|
|
|
3071
3520
|
child.stderr?.on("data", (chunk) => captureStderr(chunk.toString("utf8")));
|
|
3072
3521
|
return child;
|
|
3073
3522
|
}
|
|
3074
|
-
const
|
|
3523
|
+
const ownAgent = Object.keys(transport2.headers).some((name) => name.toLowerCase() === "user-agent");
|
|
3524
|
+
const headers = { ...ownAgent ? {} : { "user-agent": USER_AGENT }, ...transport2.headers };
|
|
3075
3525
|
const url = new URL(transport2.url);
|
|
3076
3526
|
const authProvider = createAuthProvider(server2, options);
|
|
3077
3527
|
const custom = options.fetch ? { fetch: options.fetch } : {};
|
|
3078
3528
|
if (transport2.type === "sse") return new SSEClientTransport(url, { requestInit: { headers }, authProvider, ...custom });
|
|
3079
3529
|
return new StreamableHTTPClientTransport(url, { requestInit: { headers }, authProvider, ...custom });
|
|
3080
3530
|
}
|
|
3531
|
+
var KILL_GRACE_MS = 1e3;
|
|
3532
|
+
var signalled = /* @__PURE__ */ new Set();
|
|
3533
|
+
var closing = /* @__PURE__ */ new Set();
|
|
3534
|
+
var open = /* @__PURE__ */ new Set();
|
|
3535
|
+
var exitHooked = false;
|
|
3536
|
+
function isRunning(pid) {
|
|
3537
|
+
try {
|
|
3538
|
+
process.kill(pid, 0);
|
|
3539
|
+
return true;
|
|
3540
|
+
} catch (error) {
|
|
3541
|
+
return error.code === "EPERM";
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
function signal(pid, name) {
|
|
3545
|
+
try {
|
|
3546
|
+
process.kill(pid, name);
|
|
3547
|
+
} catch {
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
function stopProcess(pid) {
|
|
3551
|
+
if (!isRunning(pid)) return;
|
|
3552
|
+
signalled.add(pid);
|
|
3553
|
+
signal(pid, "SIGTERM");
|
|
3554
|
+
setTimeout(() => {
|
|
3555
|
+
if (isRunning(pid)) signal(pid, "SIGKILL");
|
|
3556
|
+
signalled.delete(pid);
|
|
3557
|
+
}, KILL_GRACE_MS).unref();
|
|
3558
|
+
}
|
|
3559
|
+
function hookExit() {
|
|
3560
|
+
if (exitHooked) return;
|
|
3561
|
+
exitHooked = true;
|
|
3562
|
+
process.on("exit", () => {
|
|
3563
|
+
for (const pid of [...signalled, ...closing]) signal(pid, "SIGKILL");
|
|
3564
|
+
for (const transport2 of open) if (transport2.pid !== null) signal(transport2.pid, "SIGKILL");
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3081
3567
|
function diagnosticLines(stderr, limit = 3) {
|
|
3082
3568
|
const lines = stderr.split("\n").map((line) => line.trimEnd()).filter((line) => line.trim().length > 0).filter((line) => !/^\s*(at\s|\^+$|[}\])]+$|Node\.js v[\d.]+$)/.test(line));
|
|
3083
3569
|
const named = lines.filter((line) => /\b(error|exception|cannot|failed|refused|denied|not found|enoent|eacces)\b/i.test(line));
|
|
@@ -3112,27 +3598,55 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
3112
3598
|
});
|
|
3113
3599
|
}
|
|
3114
3600
|
let transport2;
|
|
3115
|
-
const
|
|
3601
|
+
const stop = () => {
|
|
3602
|
+
if (transport2 instanceof StdioClientTransport) {
|
|
3603
|
+
open.delete(transport2);
|
|
3604
|
+
if (transport2.pid !== null) stopProcess(transport2.pid);
|
|
3605
|
+
}
|
|
3116
3606
|
void transport2?.close().catch(() => {
|
|
3117
3607
|
});
|
|
3118
|
-
}
|
|
3608
|
+
};
|
|
3609
|
+
const guard = new SurfaceGuard(stop);
|
|
3119
3610
|
try {
|
|
3120
3611
|
transport2 = buildTransport(server2, captureStderr, { ...options, fetch: guardedFetch(guard) });
|
|
3121
3612
|
} catch (error) {
|
|
3122
3613
|
throw new UnreachableServerError(server2.name, `could not prepare transport: ${error.message}`, error);
|
|
3123
3614
|
}
|
|
3124
3615
|
guardMessages(transport2, guard);
|
|
3616
|
+
const built = transport2;
|
|
3617
|
+
if (built instanceof StdioClientTransport) {
|
|
3618
|
+
hookExit();
|
|
3619
|
+
open.add(built);
|
|
3620
|
+
const start = built.start.bind(built);
|
|
3621
|
+
built.start = async () => {
|
|
3622
|
+
await start();
|
|
3623
|
+
if (options.signal?.aborted) {
|
|
3624
|
+
stop();
|
|
3625
|
+
throw new UnreachableServerError(server2.name, "stopped: the deadline passed while it was starting");
|
|
3626
|
+
}
|
|
3627
|
+
};
|
|
3628
|
+
}
|
|
3629
|
+
options.signal?.addEventListener("abort", stop, { once: true });
|
|
3630
|
+
const close = async () => {
|
|
3631
|
+
options.signal?.removeEventListener("abort", stop);
|
|
3632
|
+
const pid = built instanceof StdioClientTransport ? built.pid : null;
|
|
3633
|
+
if (pid !== null) closing.add(pid);
|
|
3634
|
+
if (built instanceof StdioClientTransport) open.delete(built);
|
|
3635
|
+
await client.close().catch(() => {
|
|
3636
|
+
});
|
|
3637
|
+
if (pid !== null) closing.delete(pid);
|
|
3638
|
+
};
|
|
3125
3639
|
try {
|
|
3126
3640
|
await client.connect(transport2, { timeout: timeoutMs });
|
|
3127
3641
|
} catch (error) {
|
|
3128
|
-
|
|
3129
|
-
|
|
3642
|
+
if (options.signal?.aborted) stop();
|
|
3643
|
+
await close();
|
|
3130
3644
|
if (guard.refusal !== void 0) throw new UnreachableServerError(server2.name, guard.refusal, error);
|
|
3131
3645
|
const detail = stderrBuffer.trim();
|
|
3132
3646
|
const network = describeNetworkFailure(error);
|
|
3133
3647
|
throw new UnreachableServerError(
|
|
3134
3648
|
server2.name,
|
|
3135
|
-
`${error.message}${network ? ` (${network})` : ""}${detail ? `
|
|
3649
|
+
`${boundReason(error.message, MAX_REASON_CHARS / 2)}${network ? ` (${network})` : ""}${detail ? `
|
|
3136
3650
|
server stderr: ${diagnosticLines(detail).join("\n ")}` : ""}`,
|
|
3137
3651
|
error
|
|
3138
3652
|
);
|
|
@@ -3143,10 +3657,7 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
3143
3657
|
refused: () => guard.refusal,
|
|
3144
3658
|
watchChanges: () => changes.clear(),
|
|
3145
3659
|
changed: () => [...changes].sort(),
|
|
3146
|
-
close
|
|
3147
|
-
await client.close().catch(() => {
|
|
3148
|
-
});
|
|
3149
|
-
}
|
|
3660
|
+
close
|
|
3150
3661
|
};
|
|
3151
3662
|
}
|
|
3152
3663
|
|
|
@@ -3235,16 +3746,18 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
|
3235
3746
|
let expired = false;
|
|
3236
3747
|
let timer;
|
|
3237
3748
|
const late = () => new UnreachableServerError(server2.name, `did not finish within ${timeoutMs}ms`);
|
|
3749
|
+
const giveUp = new AbortController();
|
|
3238
3750
|
const deadline = new Promise((_resolve, reject) => {
|
|
3239
3751
|
timer = setTimeout(() => {
|
|
3240
3752
|
expired = true;
|
|
3753
|
+
giveUp.abort();
|
|
3241
3754
|
void connection?.close();
|
|
3242
3755
|
reject(late());
|
|
3243
3756
|
}, timeoutMs);
|
|
3244
3757
|
timer.unref?.();
|
|
3245
3758
|
});
|
|
3246
3759
|
const work = (async () => {
|
|
3247
|
-
const opened = await connect(server2, timeoutMs);
|
|
3760
|
+
const opened = await connect(server2, timeoutMs, { signal: giveUp.signal });
|
|
3248
3761
|
if (expired) {
|
|
3249
3762
|
await opened.close();
|
|
3250
3763
|
throw late();
|
|
@@ -3312,12 +3825,20 @@ async function readLists(client, server2, timeoutMs) {
|
|
|
3312
3825
|
};
|
|
3313
3826
|
}
|
|
3314
3827
|
|
|
3828
|
+
// src/lib/own.ts
|
|
3829
|
+
function own(record, name) {
|
|
3830
|
+
return record !== void 0 && Object.hasOwn(record, name) ? record[name] : void 0;
|
|
3831
|
+
}
|
|
3832
|
+
function setOwn(record, name, value) {
|
|
3833
|
+
Object.defineProperty(record, name, { value, enumerable: true, writable: true, configurable: true });
|
|
3834
|
+
}
|
|
3835
|
+
|
|
3315
3836
|
// src/audit.ts
|
|
3316
3837
|
async function provenanceOf(server2, options) {
|
|
3317
3838
|
if (server2.transport.type !== "stdio") return { unverified: false };
|
|
3318
3839
|
const reference = referenceOf(server2.transport, options.projectRoot);
|
|
3319
3840
|
if (!reference) return { unverified: false };
|
|
3320
|
-
const previous = options.previous?.subjects
|
|
3841
|
+
const previous = own(options.previous?.subjects, server2.name)?.provenance;
|
|
3321
3842
|
const elsewhere = fetchedElsewhere(server2.transport, reference, { projectRoot: options.projectRoot });
|
|
3322
3843
|
if (elsewhere) return { unverified: true, ...previous ? { displaced: { previous, why: elsewhere } } : {} };
|
|
3323
3844
|
if (options.provenance === false) {
|
|
@@ -3329,6 +3850,14 @@ async function provenanceOf(server2, options) {
|
|
|
3329
3850
|
const kept = carriedForward(previous, reference);
|
|
3330
3851
|
return { ...kept ? { provenance: kept } : {}, unverified: true };
|
|
3331
3852
|
}
|
|
3853
|
+
function floatingOf(server2, provenance2, projectRoot) {
|
|
3854
|
+
if (server2.transport.type !== "stdio") return void 0;
|
|
3855
|
+
const reference = referenceOf(server2.transport, projectRoot);
|
|
3856
|
+
if (!reference) return void 0;
|
|
3857
|
+
if (reference.ecosystem === "npm" && installedCopy(server2.transport, reference, { projectRoot })) return void 0;
|
|
3858
|
+
const floating = floatingRequest(reference, provenance2);
|
|
3859
|
+
return floating ? { server: server2.name, ...floating } : void 0;
|
|
3860
|
+
}
|
|
3332
3861
|
async function mapWithLimit(items, limit, worker) {
|
|
3333
3862
|
const results = new Array(items.length);
|
|
3334
3863
|
let next = 0;
|
|
@@ -3346,18 +3875,22 @@ async function mapWithLimit(items, limit, worker) {
|
|
|
3346
3875
|
async function captureAll(options) {
|
|
3347
3876
|
const discovery = await discoverServers(options.projectRoot, options.configFiles, { userConfigs: options.userConfigs === true });
|
|
3348
3877
|
const captured = await mapWithLimit(discovery.servers, options.concurrency ?? 4, async (server2) => {
|
|
3878
|
+
let established;
|
|
3879
|
+
let floating2;
|
|
3349
3880
|
try {
|
|
3350
|
-
|
|
3881
|
+
established = await provenanceOf(server2, options);
|
|
3882
|
+
floating2 = floatingOf(server2, established.provenance, options.projectRoot);
|
|
3883
|
+
const { provenance: provenance2, unverified: unverified2, displaced: displaced2 } = established;
|
|
3351
3884
|
const pinned = server2.transport.type === "stdio" ? launchPinned(server2.transport, provenance2) : void 0;
|
|
3352
3885
|
const surface = await captureSurface(pinned ? { ...server2, transport: pinned } : server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2);
|
|
3353
3886
|
const entry = buildLockedServer(server2, surface, options.policy);
|
|
3354
3887
|
options.onServerDone?.(server2.name, "captured");
|
|
3355
|
-
return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2, displaced: displaced2 };
|
|
3888
|
+
return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2, displaced: displaced2, floating: floating2 };
|
|
3356
3889
|
} catch (error) {
|
|
3357
3890
|
options.onServerDone?.(server2.name, "failed");
|
|
3358
|
-
const reason = withoutSecrets(error instanceof UnreachableServerError ? error.message : error.message, server2);
|
|
3891
|
+
const reason = boundReason(withoutSecrets(error instanceof UnreachableServerError ? error.message : error.message, server2));
|
|
3359
3892
|
const kind = authFailureKind(error) ?? "unreachable";
|
|
3360
|
-
return { name: server2.name, failure: { server: server2.name, reason, kind } };
|
|
3893
|
+
return { name: server2.name, failure: { server: server2.name, reason, kind }, provenance: established?.provenance, displaced: established?.displaced, floating: floating2 };
|
|
3361
3894
|
}
|
|
3362
3895
|
});
|
|
3363
3896
|
const subjects = {};
|
|
@@ -3365,21 +3898,26 @@ async function captureAll(options) {
|
|
|
3365
3898
|
const unverified = [];
|
|
3366
3899
|
const displaced = [];
|
|
3367
3900
|
const unaudited = {};
|
|
3901
|
+
const unauditedProvenance = {};
|
|
3902
|
+
const floating = [];
|
|
3368
3903
|
const configured = new Map(discovery.servers.map((server2) => [server2.name, server2]));
|
|
3369
3904
|
for (const result of captured) {
|
|
3905
|
+
if (result.floating) floating.push(result.floating);
|
|
3370
3906
|
if ("entry" in result && result.entry) {
|
|
3371
|
-
subjects
|
|
3907
|
+
setOwn(subjects, result.name, result.entry);
|
|
3372
3908
|
if (result.unverified) unverified.push(result.name);
|
|
3373
3909
|
if (result.displaced) displaced.push({ server: result.name, ...result.displaced });
|
|
3374
3910
|
} else if ("failure" in result && result.failure) {
|
|
3375
3911
|
unreachable.push(result.failure);
|
|
3376
3912
|
const server2 = configured.get(result.name);
|
|
3377
|
-
unaudited
|
|
3913
|
+
setOwn(unaudited, result.name, server2 ? { transport: lockTransport(server2) } : {});
|
|
3914
|
+
if (result.provenance) setOwn(unauditedProvenance, result.name, result.provenance);
|
|
3915
|
+
if (result.displaced) displaced.push({ server: result.name, ...result.displaced });
|
|
3378
3916
|
}
|
|
3379
3917
|
}
|
|
3380
3918
|
for (const skipped of discovery.skipped) {
|
|
3381
|
-
unreachable.push({ server: skipped.serverName, reason: skipped.message, kind: "unreachable" });
|
|
3382
|
-
unaudited
|
|
3919
|
+
unreachable.push({ server: skipped.serverName, reason: boundReason(skipped.message), kind: "unreachable" });
|
|
3920
|
+
setOwn(unaudited, skipped.serverName, skipped.transport ? { transport: skipped.transport } : {});
|
|
3383
3921
|
}
|
|
3384
3922
|
for (const conflict of discovery.conflicts) {
|
|
3385
3923
|
unreachable.push({
|
|
@@ -3389,7 +3927,7 @@ async function captureAll(options) {
|
|
|
3389
3927
|
});
|
|
3390
3928
|
}
|
|
3391
3929
|
for (const problem of discovery.problems) {
|
|
3392
|
-
unreachable.push({ server: problem.file, reason: problem.reason, kind: "unreachable" });
|
|
3930
|
+
unreachable.push({ server: problem.file, reason: boundReason(problem.reason), kind: "unreachable" });
|
|
3393
3931
|
}
|
|
3394
3932
|
return {
|
|
3395
3933
|
lock: {
|
|
@@ -3403,16 +3941,44 @@ async function captureAll(options) {
|
|
|
3403
3941
|
unverified: unverified.sort(),
|
|
3404
3942
|
displaced,
|
|
3405
3943
|
unaudited,
|
|
3944
|
+
unauditedProvenance,
|
|
3406
3945
|
conflicted: discovery.conflicts.map((conflict) => conflict.name),
|
|
3407
|
-
partial: Object.entries(subjects).filter(([, entry]) => entry.coverage !== void 0).map(([server2, entry]) => ({ server: server2, reasons: entry.coverage.reasons })).sort((a, b) => a.server.localeCompare(b.server))
|
|
3946
|
+
partial: Object.entries(subjects).filter(([, entry]) => entry.coverage !== void 0).map(([server2, entry]) => ({ server: server2, reasons: entry.coverage.reasons })).sort((a, b) => a.server.localeCompare(b.server)),
|
|
3947
|
+
floating: floating.sort((a, b) => a.server.localeCompare(b.server))
|
|
3408
3948
|
};
|
|
3409
3949
|
}
|
|
3410
3950
|
function acknowledged(committed, name, now) {
|
|
3411
|
-
const agreed = committed.unaudited?.
|
|
3412
|
-
return agreed !== void 0 &&
|
|
3951
|
+
const agreed = own(committed.unaudited, name)?.transport;
|
|
3952
|
+
return agreed !== void 0 && now.transport !== void 0 && stableKey(agreed) === stableKey(now.transport);
|
|
3953
|
+
}
|
|
3954
|
+
function unagreed(agreed, now, reason) {
|
|
3955
|
+
if (now.transport === void 0) return `could not be audited, and how it is reached could not be read either, so it cannot be agreed to: ${reason}`;
|
|
3956
|
+
if (agreed === void 0) return `new server, which could not be audited: ${reason}`;
|
|
3957
|
+
if (agreed.transport === void 0) {
|
|
3958
|
+
return `left unaudited by an agreement that does not say how it is reached, as an older mcp.lock's does, so nothing can tell whether it changed since; accept it with \`nulladrift review\` to record how. It could not be audited: ${reason}`;
|
|
3959
|
+
}
|
|
3960
|
+
return `a server left unaudited is now reached differently, and could not be audited: ${reason}`;
|
|
3961
|
+
}
|
|
3962
|
+
function unreadPin(name, pinned, now, runs, reason) {
|
|
3963
|
+
const changes = [];
|
|
3964
|
+
if (now.transport === void 0 || stableKey(now.transport) !== stableKey(pinned.transport)) {
|
|
3965
|
+
changes.push({
|
|
3966
|
+
kind: "server.transport.changed",
|
|
3967
|
+
severity: SEVERITY["server.transport.changed"],
|
|
3968
|
+
server: name,
|
|
3969
|
+
summary: `the server is reached differently than when it was pinned, and could not be audited: ${reason}`,
|
|
3970
|
+
before: pinned.transport,
|
|
3971
|
+
after: now.transport
|
|
3972
|
+
});
|
|
3973
|
+
}
|
|
3974
|
+
if (runs !== void 0) {
|
|
3975
|
+
const unread = { ...pinned, provenance: runs, digest: "unread" };
|
|
3976
|
+
changes.push(...diffLockfiles({ lockfileVersion: LOCKFILE_VERSION, subjects: { [name]: pinned } }, { lockfileVersion: LOCKFILE_VERSION, subjects: { [name]: unread } }));
|
|
3977
|
+
}
|
|
3978
|
+
return changes;
|
|
3413
3979
|
}
|
|
3414
3980
|
function compareWithLock(committed, result) {
|
|
3415
|
-
const changes = diffLockfiles(committed, result.lock);
|
|
3981
|
+
const changes = diffLockfiles(committed, result.lock).filter((change2) => !(change2.kind === "server.removed" && own(result.unaudited, change2.server) !== void 0));
|
|
3416
3982
|
for (const moved of result.displaced) {
|
|
3417
3983
|
const was = `${moved.previous.name}${moved.previous.version ? `@${moved.previous.version}` : ""}`;
|
|
3418
3984
|
changes.push({
|
|
@@ -3425,16 +3991,21 @@ function compareWithLock(committed, result) {
|
|
|
3425
3991
|
}
|
|
3426
3992
|
const failed = new Map(result.unreachable.map((failure) => [failure.server, failure.reason]));
|
|
3427
3993
|
for (const [name, now] of Object.entries(result.unaudited)) {
|
|
3428
|
-
|
|
3994
|
+
const pinned = own(committed.subjects, name);
|
|
3995
|
+
if (pinned !== void 0) {
|
|
3996
|
+
changes.push(...unreadPin(name, pinned, now, own(result.unauditedProvenance, name), failed.get(name) ?? "it did not answer"));
|
|
3997
|
+
continue;
|
|
3998
|
+
}
|
|
3999
|
+
if (acknowledged(committed, name, now)) continue;
|
|
3429
4000
|
changes.push({
|
|
3430
4001
|
kind: "server.added",
|
|
3431
4002
|
severity: SEVERITY["server.added"],
|
|
3432
4003
|
server: name,
|
|
3433
|
-
summary:
|
|
4004
|
+
summary: unagreed(own(committed.unaudited, name), now, failed.get(name) ?? "it did not answer")
|
|
3434
4005
|
});
|
|
3435
4006
|
}
|
|
3436
4007
|
for (const name of result.conflicted) {
|
|
3437
|
-
if (committed.subjects
|
|
4008
|
+
if (own(committed.subjects, name) !== void 0) continue;
|
|
3438
4009
|
changes.push({
|
|
3439
4010
|
kind: "server.added",
|
|
3440
4011
|
severity: SEVERITY["server.added"],
|
|
@@ -3445,19 +4016,64 @@ function compareWithLock(committed, result) {
|
|
|
3445
4016
|
return sortChanges(changes);
|
|
3446
4017
|
}
|
|
3447
4018
|
function unauditedToRecord(result, keep = () => true) {
|
|
3448
|
-
const entries = Object.entries(result.unaudited).filter(([name]) => keep(name));
|
|
4019
|
+
const entries = Object.entries(result.unaudited).filter(([name, entry]) => entry.transport !== void 0 && name !== "__proto__" && keep(name));
|
|
3449
4020
|
return entries.length > 0 ? Object.fromEntries(entries) : void 0;
|
|
3450
4021
|
}
|
|
4022
|
+
function decoded2(value) {
|
|
4023
|
+
try {
|
|
4024
|
+
return decodeURIComponent(value);
|
|
4025
|
+
} catch {
|
|
4026
|
+
return value;
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
function addressSecrets(address) {
|
|
4030
|
+
let url;
|
|
4031
|
+
try {
|
|
4032
|
+
url = new URL(address);
|
|
4033
|
+
} catch {
|
|
4034
|
+
return [];
|
|
4035
|
+
}
|
|
4036
|
+
const out = [url.username, url.password, decoded2(url.username), decoded2(url.password)];
|
|
4037
|
+
for (const [, value] of url.searchParams) out.push(value);
|
|
4038
|
+
for (const pair of url.search.slice(1).split("&")) out.push(pair.slice(pair.indexOf("=") + 1));
|
|
4039
|
+
if (url.hash.length > 1) out.push(url.hash.slice(1));
|
|
4040
|
+
const kept = redactPath(url.pathname).split("/");
|
|
4041
|
+
url.pathname.split("/").forEach((segment, index) => {
|
|
4042
|
+
if (kept[index] !== segment) out.push(segment, decoded2(segment));
|
|
4043
|
+
});
|
|
4044
|
+
return out;
|
|
4045
|
+
}
|
|
4046
|
+
function replacedParts(original, redacted) {
|
|
4047
|
+
const kept = redacted.split(REDACTED);
|
|
4048
|
+
const parts = [];
|
|
4049
|
+
let at = 0;
|
|
4050
|
+
for (const [index, piece] of kept.entries()) {
|
|
4051
|
+
const found = index === 0 ? original.startsWith(piece) ? 0 : -1 : index === kept.length - 1 ? original.endsWith(piece) && original.length - piece.length >= at ? original.length - piece.length : -1 : original.indexOf(piece, at);
|
|
4052
|
+
if (found < 0) return [original];
|
|
4053
|
+
if (index > 0) parts.push(original.slice(at, found));
|
|
4054
|
+
at = found + piece.length;
|
|
4055
|
+
}
|
|
4056
|
+
return parts;
|
|
4057
|
+
}
|
|
3451
4058
|
function withoutSecrets(reason, server2) {
|
|
3452
4059
|
const { transport: transport2 } = server2;
|
|
3453
4060
|
const secrets = [];
|
|
4061
|
+
for (const { name, value } of transport2.filled ?? []) {
|
|
4062
|
+
if (isCredentialName(name) || !/^(?:[./~]|[A-Za-z]:\\)/.test(value)) secrets.push(value, ...addressSecrets(value));
|
|
4063
|
+
}
|
|
3454
4064
|
if (transport2.type === "stdio") {
|
|
3455
4065
|
for (const [name, value] of Object.entries(transport2.env)) {
|
|
3456
4066
|
if (isCredentialName(name) || value.length >= 16 && !/[\s/\\]/.test(value)) secrets.push(value);
|
|
3457
4067
|
}
|
|
4068
|
+
const redacted = redactArgs(transport2.args);
|
|
4069
|
+
transport2.args.forEach((argument, index) => {
|
|
4070
|
+
const kept = redacted[index];
|
|
4071
|
+
if (kept !== void 0 && kept !== argument) secrets.push(...replacedParts(argument, kept));
|
|
4072
|
+
});
|
|
3458
4073
|
} else {
|
|
3459
4074
|
for (const value of Object.values(transport2.headers)) secrets.push(value, ...value.split(/\s+/));
|
|
3460
4075
|
if (transport2.oauth?.clientSecret) secrets.push(transport2.oauth.clientSecret);
|
|
4076
|
+
secrets.push(...addressSecrets(transport2.url));
|
|
3461
4077
|
}
|
|
3462
4078
|
let out = reason;
|
|
3463
4079
|
for (const secret of [...new Set(secrets)].filter((value) => value.length >= 8).sort((a, b) => b.length - a.length)) {
|
|
@@ -3811,6 +4427,17 @@ function resolveExitCode(options) {
|
|
|
3811
4427
|
return EXIT_CLEAN;
|
|
3812
4428
|
}
|
|
3813
4429
|
|
|
4430
|
+
// src/report/floating.ts
|
|
4431
|
+
function floatingLine(entry) {
|
|
4432
|
+
const instead = entry.exact !== void 0 ? `Write it as ${entry.exact}, which is what runs now.` : entry.ecosystem === "oci" ? `Write it by digest, as ${entry.name}@sha256:<digest>.` : `Write it with an exact version, as ${entry.name}${entry.ecosystem === "pypi" ? "==" : "@"}<version>.`;
|
|
4433
|
+
return visibleControls(
|
|
4434
|
+
`${entry.asked} runs whatever version was published last, so a new release can show up as drift, and fail the build, with no change to the config. ${instead}`
|
|
4435
|
+
);
|
|
4436
|
+
}
|
|
4437
|
+
function floatingNotes(floating) {
|
|
4438
|
+
return floating.map((entry) => `${visibleControls(entry.server)}: ${floatingLine(entry)}`);
|
|
4439
|
+
}
|
|
4440
|
+
|
|
3814
4441
|
// src/report/human.ts
|
|
3815
4442
|
var MARK = {
|
|
3816
4443
|
high: red,
|
|
@@ -3842,7 +4469,7 @@ function renderSteering(report) {
|
|
|
3842
4469
|
for (const { server: server2, signals } of found) {
|
|
3843
4470
|
lines.push(` ${bold(visibleControls(server2))}`);
|
|
3844
4471
|
const byField = /* @__PURE__ */ new Map();
|
|
3845
|
-
for (const
|
|
4472
|
+
for (const signal2 of signals) byField.set(signal2.field, [...byField.get(signal2.field) ?? [], signal2.quote]);
|
|
3846
4473
|
const fields = [...byField];
|
|
3847
4474
|
for (const [field, quotes] of fields.slice(0, 4)) {
|
|
3848
4475
|
const more = quotes.length > 1 ? ` (+${quotes.length - 1} more here)` : "";
|
|
@@ -3905,6 +4532,12 @@ function renderHumanReport(report) {
|
|
|
3905
4532
|
""
|
|
3906
4533
|
);
|
|
3907
4534
|
}
|
|
4535
|
+
const floating = report.floating ?? [];
|
|
4536
|
+
if (floating.length > 0) {
|
|
4537
|
+
lines.push(yellow(`${floating.length} server(s) name no exact version:`));
|
|
4538
|
+
for (const entry of floating) lines.push(` ${bold(visibleControls(entry.server))}`, ` ${floatingLine(entry)}`);
|
|
4539
|
+
lines.push(dim(" This did not change the verdict."), "");
|
|
4540
|
+
}
|
|
3908
4541
|
const partial = report.partial ?? [];
|
|
3909
4542
|
if (partial.length > 0) {
|
|
3910
4543
|
lines.push(yellow(`Could not read ${partial.length} server(s) in full:`));
|
|
@@ -3956,7 +4589,7 @@ function redactedLine(count) {
|
|
|
3956
4589
|
function redactedNotes(lock) {
|
|
3957
4590
|
return Object.entries(lock.subjects).flatMap(([name, entry]) => {
|
|
3958
4591
|
const count = countRedacted(entry.transport);
|
|
3959
|
-
return count > 0 ? [`${name}: ${redactedLine(count)}`] : [];
|
|
4592
|
+
return count > 0 ? [`${visibleControls(name)}: ${redactedLine(count)}`] : [];
|
|
3960
4593
|
});
|
|
3961
4594
|
}
|
|
3962
4595
|
|
|
@@ -4027,6 +4660,13 @@ function helpUriFor(anchor) {
|
|
|
4027
4660
|
return base === void 0 ? void 0 : `${base}/blob/main/docs/lockfile.md#${anchor}`;
|
|
4028
4661
|
}
|
|
4029
4662
|
|
|
4663
|
+
// src/report/types.ts
|
|
4664
|
+
var AUDIT_FAILURE_LABEL = {
|
|
4665
|
+
auth: "refused the audit",
|
|
4666
|
+
forbidden: "accepted the credentials and refused",
|
|
4667
|
+
unreachable: "unreachable"
|
|
4668
|
+
};
|
|
4669
|
+
|
|
4030
4670
|
// src/report/sarif.ts
|
|
4031
4671
|
var LEVEL = {
|
|
4032
4672
|
high: "error",
|
|
@@ -4037,6 +4677,8 @@ var DENIED_RULE = "policy.capability.denied";
|
|
|
4037
4677
|
var STEERING_RULE = "steering.passage.arrived";
|
|
4038
4678
|
var UNVERIFIED_RULE = "server.artifact.unverified";
|
|
4039
4679
|
var PARTIAL_RULE = "server.surface.partial";
|
|
4680
|
+
var UNREAD_RULE = "server.surface.unread";
|
|
4681
|
+
var FLOATING_RULE = "server.artifact.floating";
|
|
4040
4682
|
var RULE_HELP = {
|
|
4041
4683
|
"tool.capability.gained": "A tool gained a capability it did not declare before, derived from its name, its argument names and the shape of its schema. The severity is the capability's, not the schema change's: gaining a `command` argument is not the same finding as gaining an optional string.",
|
|
4042
4684
|
"tool.description.changed": "A tool description is injected into the model's context. A change here can carry instructions to the agent and should be read in full, not skimmed.",
|
|
@@ -4064,6 +4706,8 @@ function renderSarifReport(report, options = {}) {
|
|
|
4064
4706
|
const steering = options.steering ? report.steering ?? [] : [];
|
|
4065
4707
|
const unverified = report.unverified ?? [];
|
|
4066
4708
|
const partial = report.partial ?? [];
|
|
4709
|
+
const unread = report.unreachable;
|
|
4710
|
+
const floating = report.floating ?? [];
|
|
4067
4711
|
const at = (name, qualified) => [
|
|
4068
4712
|
{
|
|
4069
4713
|
physicalLocation: { artifactLocation: { uri: sarifUri(report), uriBaseId: "%SRCROOT%" } },
|
|
@@ -4092,12 +4736,26 @@ function renderSarifReport(report, options = {}) {
|
|
|
4092
4736
|
fullDescription: { text: "The listing did not end within the page limit, or the server said it changed while being read on every pass. Compared as far as it was read; the audit did not finish." },
|
|
4093
4737
|
defaultConfiguration: { level: "warning" }
|
|
4094
4738
|
}] : [],
|
|
4739
|
+
...unread.length > 0 ? [{
|
|
4740
|
+
id: UNREAD_RULE,
|
|
4741
|
+
name: "ServerSurfaceUnread",
|
|
4742
|
+
shortDescription: { text: "A server's surface could not be read" },
|
|
4743
|
+
fullDescription: { text: "The server did not answer, refused the audit, or its configuration could not be used, so its surface was not compared. The audit did not finish, which fails it unless --allow-unreachable makes that a warning." },
|
|
4744
|
+
defaultConfiguration: { level: "warning" }
|
|
4745
|
+
}] : [],
|
|
4095
4746
|
...unverified.length > 0 ? [{
|
|
4096
4747
|
id: UNVERIFIED_RULE,
|
|
4097
4748
|
name: "ServerArtifactUnverified",
|
|
4098
4749
|
shortDescription: { text: "What a server runs could not be checked" },
|
|
4099
4750
|
fullDescription: { text: "The server answered and its declared surface was compared, but the artifact behind it could not be established on this run: a registry that did not answer, or a launcher configured to fetch from somewhere the pin does not describe. It does not affect the exit code." },
|
|
4100
4751
|
defaultConfiguration: { level: "note" }
|
|
4752
|
+
}] : [],
|
|
4753
|
+
...floating.length > 0 ? [{
|
|
4754
|
+
id: FLOATING_RULE,
|
|
4755
|
+
name: "ServerArtifactFloating",
|
|
4756
|
+
shortDescription: { text: "A server configured with no exact version" },
|
|
4757
|
+
fullDescription: { text: "The configuration names a package with no version, a dist-tag or a range, or an image with no tag or the latest tag, so the server runs whatever was published last and a new release shows up as drift with no change to the configuration. Name an exact version, or an image digest. It does not affect the exit code." },
|
|
4758
|
+
defaultConfiguration: { level: "note" }
|
|
4101
4759
|
}] : []
|
|
4102
4760
|
];
|
|
4103
4761
|
const document = {
|
|
@@ -4139,12 +4797,12 @@ function renderSarifReport(report, options = {}) {
|
|
|
4139
4797
|
partialFingerprints: { "mcpAuditChange/v1": `${violation.server}/${violation.tool}/${violation.kind}` }
|
|
4140
4798
|
})),
|
|
4141
4799
|
...steering.flatMap(
|
|
4142
|
-
({ server: server2, signals }) => signals.map((
|
|
4800
|
+
({ server: server2, signals }) => signals.map((signal2) => ({
|
|
4143
4801
|
ruleId: STEERING_RULE,
|
|
4144
4802
|
level: "note",
|
|
4145
|
-
message: { text: `${server2} \u203A ${
|
|
4146
|
-
locations: at(
|
|
4147
|
-
partialFingerprints: { "mcpAuditChange/v1": `${server2}/${
|
|
4803
|
+
message: { text: `${server2} \u203A ${signal2.field}: ${signal2.quote}` },
|
|
4804
|
+
locations: at(signal2.field, `${server2}/${signal2.field}`),
|
|
4805
|
+
partialFingerprints: { "mcpAuditChange/v1": `${server2}/${signal2.field}/${signal2.kind}` }
|
|
4148
4806
|
}))
|
|
4149
4807
|
),
|
|
4150
4808
|
...partial.map((entry) => ({
|
|
@@ -4154,12 +4812,26 @@ function renderSarifReport(report, options = {}) {
|
|
|
4154
4812
|
locations: at(entry.server, entry.server),
|
|
4155
4813
|
partialFingerprints: { "mcpAuditChange/v1": `${entry.server}/partial` }
|
|
4156
4814
|
})),
|
|
4815
|
+
...unread.map((failure) => ({
|
|
4816
|
+
ruleId: UNREAD_RULE,
|
|
4817
|
+
level: "warning",
|
|
4818
|
+
message: { text: `${failure.server}: could not be read (${AUDIT_FAILURE_LABEL[failure.kind]}). ${failure.reason}` },
|
|
4819
|
+
locations: at(failure.server, failure.server),
|
|
4820
|
+
partialFingerprints: { "mcpAuditChange/v1": `${failure.server}/unread` }
|
|
4821
|
+
})),
|
|
4157
4822
|
...unverified.map((server2) => ({
|
|
4158
4823
|
ruleId: UNVERIFIED_RULE,
|
|
4159
4824
|
level: "note",
|
|
4160
4825
|
message: { text: `${server2}: what this server runs could not be checked on this run` },
|
|
4161
4826
|
locations: at(server2, server2),
|
|
4162
4827
|
partialFingerprints: { "mcpAuditChange/v1": `${server2}/unverified` }
|
|
4828
|
+
})),
|
|
4829
|
+
...floating.map((entry) => ({
|
|
4830
|
+
ruleId: FLOATING_RULE,
|
|
4831
|
+
level: "note",
|
|
4832
|
+
message: { text: `${entry.server}: ${floatingLine(entry)}` },
|
|
4833
|
+
locations: at(entry.server, entry.server),
|
|
4834
|
+
partialFingerprints: { "mcpAuditChange/v1": `${entry.server}/floating` }
|
|
4163
4835
|
}))
|
|
4164
4836
|
]
|
|
4165
4837
|
}
|
|
@@ -4170,11 +4842,6 @@ function renderSarifReport(report, options = {}) {
|
|
|
4170
4842
|
}
|
|
4171
4843
|
|
|
4172
4844
|
// src/report/markdown.ts
|
|
4173
|
-
var AUDIT_FAILURE_LABEL = {
|
|
4174
|
-
auth: "refused the audit",
|
|
4175
|
-
forbidden: "accepted the credentials and refused",
|
|
4176
|
-
unreachable: "unreachable"
|
|
4177
|
-
};
|
|
4178
4845
|
var MARK2 = { high: "\u{1F534}", medium: "\u{1F7E0}", low: "\u26AA" };
|
|
4179
4846
|
function plain(text) {
|
|
4180
4847
|
return visibleControls(text, { multiline: true }).replace(/\r?\n/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/([\\`*_{}[\]()#+!|~])/g, "\\$1").replace(/@/g, "@\u200B").replace(/\bwww\./gi, (prefix) => `${prefix.slice(0, 3)}\u200B.`).replace(/:\/\//g, "://").trim();
|
|
@@ -4190,6 +4857,13 @@ function row(change2) {
|
|
|
4190
4857
|
const where2 = change2.member ? `${change2.server}/${change2.member}` : change2.server;
|
|
4191
4858
|
return `| ${MARK2[change2.severity]} ${change2.severity} | ${code(where2)} | ${plain(change2.kind)} | ${plain(change2.summary)} |`;
|
|
4192
4859
|
}
|
|
4860
|
+
function renderResolvedReport(report) {
|
|
4861
|
+
return [
|
|
4862
|
+
"### Nothing to review: every server matches the lock",
|
|
4863
|
+
"",
|
|
4864
|
+
`An earlier run reported findings here. On this one, all ${report.serversChecked} server${report.serversChecked === 1 ? "" : "s"} matched what was approved, and none failed to answer.`
|
|
4865
|
+
].join("\n");
|
|
4866
|
+
}
|
|
4193
4867
|
function renderMarkdownReport(report, options = {}) {
|
|
4194
4868
|
const violations = report.violations ?? [];
|
|
4195
4869
|
const partial = report.partial ?? [];
|
|
@@ -4242,7 +4916,7 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
4242
4916
|
"| Server | Field | Passage |",
|
|
4243
4917
|
"| --- | --- | --- |",
|
|
4244
4918
|
...steering.flatMap(
|
|
4245
|
-
({ server: server2, signals }) => signals.slice(0, 10).map((
|
|
4919
|
+
({ server: server2, signals }) => signals.slice(0, 10).map((signal2) => `| ${code(server2)} | ${code(signal2.field)} | ${plain(signal2.quote)} |`)
|
|
4246
4920
|
),
|
|
4247
4921
|
"",
|
|
4248
4922
|
"</details>",
|
|
@@ -4294,6 +4968,15 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
4294
4968
|
|
|
4295
4969
|
// src/report/comment.ts
|
|
4296
4970
|
var MARKER = "<!-- nulladrift:surface -->";
|
|
4971
|
+
var PER_PAGE = 100;
|
|
4972
|
+
var MAX_COMMENT_PAGES = 10;
|
|
4973
|
+
var MAX_COMMENT_CHARS = 65536;
|
|
4974
|
+
function fitted(body) {
|
|
4975
|
+
if (body.length <= MAX_COMMENT_CHARS) return body;
|
|
4976
|
+
const note = "\n\n_The rest of this report was cut short to fit a comment; the job log has all of it._";
|
|
4977
|
+
const room = body.slice(0, MAX_COMMENT_CHARS - note.length);
|
|
4978
|
+
return `${room.slice(0, Math.max(room.lastIndexOf("\n"), 0))}${note}`;
|
|
4979
|
+
}
|
|
4297
4980
|
function targetFromEnvironment(env = process.env) {
|
|
4298
4981
|
const token = env["GITHUB_TOKEN"];
|
|
4299
4982
|
const repo = env["GITHUB_REPOSITORY"];
|
|
@@ -4321,20 +5004,26 @@ async function call(target, path, init = {}) {
|
|
|
4321
5004
|
signal: AbortSignal.timeout(1e4)
|
|
4322
5005
|
});
|
|
4323
5006
|
}
|
|
4324
|
-
async function upsertComment(target, body) {
|
|
4325
|
-
const marked = `${MARKER}
|
|
4326
|
-
${body}
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
5007
|
+
async function upsertComment(target, body, options = {}) {
|
|
5008
|
+
const marked = fitted(`${MARKER}
|
|
5009
|
+
${body}`);
|
|
5010
|
+
let self;
|
|
5011
|
+
let mine;
|
|
5012
|
+
for (let page = 1; page <= MAX_COMMENT_PAGES && mine === void 0; page += 1) {
|
|
5013
|
+
const existing = await call(target, `/issues/${target.issue}/comments?per_page=${PER_PAGE}&page=${page}`);
|
|
5014
|
+
if (existing.status === 403) return "forbidden";
|
|
5015
|
+
if (!existing.ok) throw new Error(`could not read the comments (${existing.status})`);
|
|
5016
|
+
self ??= await identity2(target);
|
|
5017
|
+
const comments = await existing.json();
|
|
5018
|
+
mine = comments.find((comment2) => comment2.body?.startsWith(MARKER) && comment2.user?.login === self);
|
|
5019
|
+
if (comments.length < PER_PAGE) break;
|
|
5020
|
+
}
|
|
4333
5021
|
if (mine) {
|
|
4334
5022
|
const updated = await call(target, `/issues/comments/${mine.id}`, { method: "PATCH", body: JSON.stringify({ body: marked }) });
|
|
4335
5023
|
if (updated.ok) return "updated";
|
|
4336
5024
|
if (updated.status !== 403 && updated.status !== 404) throw new Error(`could not update the comment (${updated.status})`);
|
|
4337
5025
|
}
|
|
5026
|
+
if (options.create === false) return "none";
|
|
4338
5027
|
const created = await call(target, `/issues/${target.issue}/comments`, { method: "POST", body: JSON.stringify({ body: marked }) });
|
|
4339
5028
|
if (created.status === 403) return "forbidden";
|
|
4340
5029
|
if (!created.ok) throw new Error(`could not post the comment (${created.status})`);
|
|
@@ -4482,6 +5171,8 @@ async function buildReport(options) {
|
|
|
4482
5171
|
unreachable: result.unreachable,
|
|
4483
5172
|
// Reported beside the verdict and never part of it; see `AuditReport.unverified`.
|
|
4484
5173
|
unverified: result.unverified,
|
|
5174
|
+
// Advice beside the verdict, like `unverified`: why the drift keeps coming, not more of it.
|
|
5175
|
+
floating: result.floating,
|
|
4485
5176
|
partial: result.partial,
|
|
4486
5177
|
serversChecked: Object.keys(result.lock.subjects).length,
|
|
4487
5178
|
lockPath: options.lockPath,
|
|
@@ -4521,9 +5212,9 @@ async function comment(report) {
|
|
|
4521
5212
|
return;
|
|
4522
5213
|
}
|
|
4523
5214
|
const body = renderMarkdownReport(report);
|
|
4524
|
-
if (!body) return;
|
|
4525
5215
|
try {
|
|
4526
|
-
const outcome = await upsertComment(target, body);
|
|
5216
|
+
const outcome = await upsertComment(target, body ?? renderResolvedReport(report), { create: body !== null });
|
|
5217
|
+
if (outcome === "none") return;
|
|
4527
5218
|
if (outcome === "forbidden") {
|
|
4528
5219
|
process.stderr.write(
|
|
4529
5220
|
`${yellow("--comment:")} the token cannot write comments on this repository. A pull request from a fork gets a read-only token; give the job \`pull-requests: write\` if it is not one.
|
|
@@ -4681,6 +5372,11 @@ async function runInit(options) {
|
|
|
4681
5372
|
const unaudited = options.allowUnreachable ? unauditedToRecord(result) : void 0;
|
|
4682
5373
|
if (pinnedSomething) await writeLockfile(options.lockPath, unaudited ? { ...result.lock, unaudited } : result.lock);
|
|
4683
5374
|
const lines = pinnedSomething ? ["", bold(`Pinned ${names.length} server(s) to ${options.lockPath}:`), ""] : ["", bold("Pinned nothing: no server answered."), ""];
|
|
5375
|
+
const floating = new Map(result.floating.map((entry) => [entry.server, entry]));
|
|
5376
|
+
const floatingNote = (name) => {
|
|
5377
|
+
const entry = floating.get(name);
|
|
5378
|
+
return entry ? [` ${yellow(floatingLine(entry))}`] : [];
|
|
5379
|
+
};
|
|
4684
5380
|
for (const name of names) {
|
|
4685
5381
|
const entry = result.lock.subjects[name];
|
|
4686
5382
|
const counts = [
|
|
@@ -4694,6 +5390,7 @@ async function runInit(options) {
|
|
|
4694
5390
|
lines.push(` ${dim(visibleControls(`${entry?.protocol.era}/${entry?.protocol.version} \xB7 from ${entry?.source.file}${deprecated}`))}`);
|
|
4695
5391
|
const redacted = entry ? countRedacted(entry.transport) : 0;
|
|
4696
5392
|
if (redacted > 0) lines.push(` ${yellow(redactedLine(redacted))}`);
|
|
5393
|
+
lines.push(...floatingNote(name));
|
|
4697
5394
|
const tools = entry?.tools ?? [];
|
|
4698
5395
|
const capabilities = surfaceCapabilities(tools);
|
|
4699
5396
|
if (capabilities.length > 0) {
|
|
@@ -4709,7 +5406,7 @@ async function runInit(options) {
|
|
|
4709
5406
|
);
|
|
4710
5407
|
if (steering.length > 0) {
|
|
4711
5408
|
const byField = /* @__PURE__ */ new Map();
|
|
4712
|
-
for (const
|
|
5409
|
+
for (const signal2 of steering) byField.set(signal2.field, [...byField.get(signal2.field) ?? [], signal2.quote]);
|
|
4713
5410
|
const fields = [...byField];
|
|
4714
5411
|
lines.push(
|
|
4715
5412
|
` ${yellow(`${fields.length} field(s) carry text read as instructions to the model, not documentation:`)}`
|
|
@@ -4728,6 +5425,14 @@ async function runInit(options) {
|
|
|
4728
5425
|
}
|
|
4729
5426
|
for (const failure of result.unreachable) {
|
|
4730
5427
|
lines.push(` ${red("\u2717")} ${bold(visibleControls(failure.server))} ${dim("not pinned")}`, ` ${visibleLines(failure.reason, " ")}`);
|
|
5428
|
+
lines.push(...floatingNote(failure.server));
|
|
5429
|
+
}
|
|
5430
|
+
const unagreeable = Object.keys(result.unaudited).filter((name) => options.allowUnreachable && !Object.hasOwn(unaudited ?? {}, name));
|
|
5431
|
+
if (unagreeable.length > 0) {
|
|
5432
|
+
lines.push(
|
|
5433
|
+
dim(` note: ${unagreeable.map((name) => visibleControls(name)).join(", ")} cannot be left unaudited: how ${unagreeable.length === 1 ? "it is" : "they are"} reached could not be read, so`),
|
|
5434
|
+
dim(" there is nothing to agree to. `check` will report it until the definition is fixed or removed.")
|
|
5435
|
+
);
|
|
4731
5436
|
}
|
|
4732
5437
|
if (result.discovery.userConfigsSkipped.length > 0) {
|
|
4733
5438
|
lines.push(
|
|
@@ -4736,7 +5441,7 @@ async function runInit(options) {
|
|
|
4736
5441
|
);
|
|
4737
5442
|
}
|
|
4738
5443
|
for (const shadow of result.discovery.shadowed) {
|
|
4739
|
-
lines.push(dim(` note: "${shadow.name}" is defined in both ${shadow.keptFrom} and ${shadow.alsoIn}; kept the first.`));
|
|
5444
|
+
lines.push(dim(visibleControls(` note: "${shadow.name}" is defined in both ${shadow.keptFrom} and ${shadow.alsoIn}; kept the first.`)));
|
|
4740
5445
|
}
|
|
4741
5446
|
lines.push(
|
|
4742
5447
|
"",
|
|
@@ -4746,6 +5451,7 @@ async function runInit(options) {
|
|
|
4746
5451
|
process.stdout.write(lines.join("\n"));
|
|
4747
5452
|
await maybeOfferTelemetry();
|
|
4748
5453
|
if (result.unreachable.length > 0 && !options.allowUnreachable) return EXIT_INCOMPLETE;
|
|
5454
|
+
if (!pinnedSomething) return EXIT_INCOMPLETE;
|
|
4749
5455
|
if (result.partial.length > 0 && !options.allowPartial) return EXIT_INCOMPLETE;
|
|
4750
5456
|
return EXIT_CLEAN;
|
|
4751
5457
|
}
|
|
@@ -4834,7 +5540,7 @@ async function runLogin(options) {
|
|
|
4834
5540
|
}
|
|
4835
5541
|
const found = await findServer(options.projectRoot, options.configFiles, options.serverName);
|
|
4836
5542
|
if ("error" in found) {
|
|
4837
|
-
process.stderr.write(`${red(found.error)}
|
|
5543
|
+
process.stderr.write(`${red(visibleControls(found.error, { multiline: true }))}
|
|
4838
5544
|
`);
|
|
4839
5545
|
return EXIT_INCOMPLETE;
|
|
4840
5546
|
}
|
|
@@ -4844,8 +5550,8 @@ async function runLogin(options) {
|
|
|
4844
5550
|
const authenticating = new FileTokenProvider(found.name, serverUrl, { interactive: true, redirectUrl: callback.redirectUrl });
|
|
4845
5551
|
Object.assign(authenticating, { stateValue: provider.stateValue });
|
|
4846
5552
|
try {
|
|
4847
|
-
process.stdout.write(`${bold(`Authorizing ${found.name}`)}
|
|
4848
|
-
${dim(sanitizeUrl(serverUrl))}
|
|
5553
|
+
process.stdout.write(`${bold(`Authorizing ${visibleControls(found.name)}`)}
|
|
5554
|
+
${dim(visibleControls(sanitizeUrl(serverUrl)))}
|
|
4849
5555
|
`);
|
|
4850
5556
|
const started = await auth(authenticating, { serverUrl });
|
|
4851
5557
|
if (started === "AUTHORIZED") {
|
|
@@ -4860,7 +5566,7 @@ ${dim(sanitizeUrl(serverUrl))}
|
|
|
4860
5566
|
`);
|
|
4861
5567
|
return EXIT_INCOMPLETE;
|
|
4862
5568
|
}
|
|
4863
|
-
process.stdout.write(`${green(`\u2713 authorized ${found.name}`)}
|
|
5569
|
+
process.stdout.write(`${green(`\u2713 authorized ${visibleControls(found.name)}`)}
|
|
4864
5570
|
${dim(`tokens stored in ${credentialPath(serverUrl)} (owner-only)`)}
|
|
4865
5571
|
`);
|
|
4866
5572
|
return EXIT_CLEAN;
|
|
@@ -4880,7 +5586,7 @@ async function runLogout(options) {
|
|
|
4880
5586
|
}
|
|
4881
5587
|
const found = await findServer(options.projectRoot, options.configFiles, options.serverName);
|
|
4882
5588
|
if ("error" in found) {
|
|
4883
|
-
process.stderr.write(`${red(found.error)}
|
|
5589
|
+
process.stderr.write(`${red(visibleControls(found.error, { multiline: true }))}
|
|
4884
5590
|
`);
|
|
4885
5591
|
return EXIT_INCOMPLETE;
|
|
4886
5592
|
}
|
|
@@ -4892,7 +5598,7 @@ async function runLogout(options) {
|
|
|
4892
5598
|
);
|
|
4893
5599
|
await rm4(path, { force: true });
|
|
4894
5600
|
process.stdout.write(
|
|
4895
|
-
`${dim(existed ? `stored credentials for ${found.name} (${sanitizeUrl(url)}) deleted` : `no credentials were stored for ${found.name} (${sanitizeUrl(url)})`)}
|
|
5601
|
+
`${dim(visibleControls(existed ? `stored credentials for ${found.name} (${sanitizeUrl(url)}) deleted` : `no credentials were stored for ${found.name} (${sanitizeUrl(url)})`))}
|
|
4896
5602
|
`
|
|
4897
5603
|
);
|
|
4898
5604
|
return EXIT_CLEAN;
|
|
@@ -5214,6 +5920,8 @@ async function runPush(options) {
|
|
|
5214
5920
|
userConfigs: options.userConfigs
|
|
5215
5921
|
});
|
|
5216
5922
|
for (const note of redactedNotes(result.lock)) process.stderr.write(`${yellow("note:")} ${note}
|
|
5923
|
+
`);
|
|
5924
|
+
for (const note of floatingNotes(result.floating)) process.stderr.write(`${yellow("note:")} ${note}
|
|
5217
5925
|
`);
|
|
5218
5926
|
if (Object.keys(result.lock.subjects).length === 0 && result.unreachable.length === 0) {
|
|
5219
5927
|
const looked = result.discovery.filesRead.length > 0 ? result.discovery.filesRead.join(", ") : "no client config files exist for this project";
|
|
@@ -5325,6 +6033,12 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
5325
6033
|
if (verdict.verdict !== "clean") lines.push("", dim(`Review it at ${shown(verdict.url)}`));
|
|
5326
6034
|
lines.push("");
|
|
5327
6035
|
process.stdout.write(lines.join("\n"));
|
|
6036
|
+
if (result.unreachable.length > 0) {
|
|
6037
|
+
process.stderr.write(
|
|
6038
|
+
`${yellow("not read:")} ${result.unreachable.map((failure) => visibleControls(failure.server)).join(", ")} could not be reached, so ${result.unreachable.length === 1 ? "it was" : "they were"} not audited. Whether that fails the build is the control plane's policy.
|
|
6039
|
+
`
|
|
6040
|
+
);
|
|
6041
|
+
}
|
|
5328
6042
|
if (result.partial.length > 0 && options.allowPartial !== true) {
|
|
5329
6043
|
process.stderr.write(
|
|
5330
6044
|
`${yellow("incomplete:")} ${result.partial.map((entry) => visibleControls(entry.server)).join(", ")} could not be read in full. Pass --allow-partial to accept that.
|
|
@@ -5348,13 +6062,13 @@ function describeSurface(subject, previous) {
|
|
|
5348
6062
|
lines.push(worst ? yellow(text) : dim(text));
|
|
5349
6063
|
}
|
|
5350
6064
|
const had = new Set(
|
|
5351
|
-
(typeof previous === "object" && previous !== null ? surfaceText(previous).flatMap((piece) => steeringSignals(piece.text, piece.field)) : []).map((
|
|
6065
|
+
(typeof previous === "object" && previous !== null ? surfaceText(previous).flatMap((piece) => steeringSignals(piece.text, piece.field)) : []).map((signal2) => `${signal2.field}\0${signal2.kind}\0${signal2.quote}`)
|
|
5352
6066
|
);
|
|
5353
|
-
const steering = surfaceText(entry).flatMap((piece) => steeringSignals(piece.text, piece.field)).filter((
|
|
6067
|
+
const steering = surfaceText(entry).flatMap((piece) => steeringSignals(piece.text, piece.field)).filter((signal2) => !had.has(`${signal2.field}\0${signal2.kind}\0${signal2.quote}`));
|
|
5354
6068
|
if (steering.length > 0) {
|
|
5355
6069
|
lines.push(yellow(` ${steering.length} new passage(s) here read as instructions to the model:`));
|
|
5356
6070
|
const byField = /* @__PURE__ */ new Map();
|
|
5357
|
-
for (const
|
|
6071
|
+
for (const signal2 of steering) if (!byField.has(signal2.field)) byField.set(signal2.field, signal2.quote);
|
|
5358
6072
|
for (const [field, quote] of [...byField].slice(0, 3)) {
|
|
5359
6073
|
lines.push(dim(` ${elideMiddle(field, 52)}: ${truncate(quote, 72)}`));
|
|
5360
6074
|
}
|
|
@@ -5412,7 +6126,7 @@ async function runReview(options) {
|
|
|
5412
6126
|
let declined = 0;
|
|
5413
6127
|
try {
|
|
5414
6128
|
for (const [serverName, serverChanges] of grouped) {
|
|
5415
|
-
const context = describeSurface(result.lock.subjects
|
|
6129
|
+
const context = describeSurface(own(result.lock.subjects, serverName), own(committed.subjects, serverName));
|
|
5416
6130
|
process.stdout.write(
|
|
5417
6131
|
`
|
|
5418
6132
|
${bold(visibleControls(serverName))}
|
|
@@ -5430,21 +6144,36 @@ ${context.length > 0 ? `${context.join("\n")}
|
|
|
5430
6144
|
declined += 1;
|
|
5431
6145
|
continue;
|
|
5432
6146
|
}
|
|
6147
|
+
const unread = own(result.lock.subjects, serverName) === void 0 ? own(result.unaudited, serverName) : void 0;
|
|
6148
|
+
if (unread !== void 0 && own(committed.subjects, serverName) !== void 0) {
|
|
6149
|
+
process.stdout.write(
|
|
6150
|
+
` ${yellow("not accepted: it could not be read, so there is nothing to pin in place of what was approved, and the pin is kept. Review it where it answers, or pin again with `nulladrift init --force`.")}
|
|
6151
|
+
`
|
|
6152
|
+
);
|
|
6153
|
+
declined += 1;
|
|
6154
|
+
continue;
|
|
6155
|
+
}
|
|
6156
|
+
if (unread !== void 0 && unread.transport === void 0) {
|
|
6157
|
+
process.stdout.write(` ${yellow("not accepted: how this server is reached could not be read, so there is nothing to agree to. Fix or remove its definition.")}
|
|
6158
|
+
`);
|
|
6159
|
+
declined += 1;
|
|
6160
|
+
continue;
|
|
6161
|
+
}
|
|
5433
6162
|
accepted += 1;
|
|
5434
|
-
let fresh = result.lock.subjects
|
|
5435
|
-
const pin = committed.subjects
|
|
6163
|
+
let fresh = own(result.lock.subjects, serverName);
|
|
6164
|
+
const pin = own(committed.subjects, serverName)?.provenance;
|
|
5436
6165
|
const displaced = result.displaced.some((moved) => moved.server === serverName);
|
|
5437
6166
|
if (fresh && fresh.provenance === void 0 && pin !== void 0 && result.unverified.includes(serverName) && !displaced) {
|
|
5438
6167
|
fresh = { ...fresh, provenance: pin };
|
|
5439
6168
|
}
|
|
5440
|
-
if (fresh) next.subjects
|
|
6169
|
+
if (fresh) setOwn(next.subjects, serverName, fresh);
|
|
5441
6170
|
else delete next.subjects[serverName];
|
|
5442
6171
|
const unaudited = { ...next.unaudited };
|
|
5443
|
-
if (!fresh &&
|
|
6172
|
+
if (!fresh && unread !== void 0) setOwn(unaudited, serverName, unread);
|
|
5444
6173
|
else delete unaudited[serverName];
|
|
5445
6174
|
next.unaudited = Object.keys(unaudited).length > 0 ? unaudited : void 0;
|
|
5446
6175
|
for (const change2 of serverChanges) {
|
|
5447
|
-
if (change2.kind === "server.renamed" && typeof change2.before === "string") delete next.subjects[change2.before];
|
|
6176
|
+
if (change2.kind === "server.renamed" && typeof change2.before === "string" && own(result.unaudited, change2.before) === void 0) delete next.subjects[change2.before];
|
|
5448
6177
|
}
|
|
5449
6178
|
}
|
|
5450
6179
|
} finally {
|