nulladrift 0.10.0 → 0.10.1
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/dist/index.js +985 -343
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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;
|
|
834
1144
|
}
|
|
835
|
-
|
|
836
|
-
if (
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
|
|
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;
|
|
1151
|
+
}
|
|
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
|
-
|
|
860
|
-
}
|
|
861
|
-
if (a && !b) {
|
|
862
|
-
narrowed = true;
|
|
863
|
-
continue;
|
|
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;
|
|
864
1216
|
}
|
|
865
|
-
if (
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
const beforeAdditional = a.additionalProperties ?? true;
|
|
869
|
-
const afterAdditional = b.additionalProperties ?? true;
|
|
870
|
-
if (!beforeAdditional && afterAdditional) widened = true;
|
|
871
|
-
if (beforeAdditional && !afterAdditional) narrowed = true;
|
|
872
|
-
if (a.enumMembers && b.enumMembers) {
|
|
873
|
-
if (isSuperset(b.enumMembers, a.enumMembers) && b.enumMembers.length > a.enumMembers.length) widened = true;
|
|
874
|
-
else if (isSuperset(a.enumMembers, b.enumMembers) && a.enumMembers.length > b.enumMembers.length) narrowed = true;
|
|
875
|
-
else if (canonicalize(a.enumMembers) !== canonicalize(b.enumMembers)) {
|
|
876
|
-
widened = true;
|
|
877
|
-
narrowed = true;
|
|
878
|
-
}
|
|
879
|
-
} else if (a.enumMembers && !b.enumMembers) widened = true;
|
|
880
|
-
else if (!a.enumMembers && b.enumMembers) narrowed = true;
|
|
881
|
-
if (a.types && b.types) {
|
|
882
|
-
if (isSuperset(b.types, a.types) && b.types.length > a.types.length) widened = true;
|
|
883
|
-
else if (isSuperset(a.types, b.types) && a.types.length > b.types.length) narrowed = true;
|
|
884
|
-
else if (canonicalize(a.types) !== canonicalize(b.types)) {
|
|
885
|
-
widened = true;
|
|
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
|
-
}
|
|
1217
|
+
if (MEMBERS.has(fact.via) || counterpart.node.slots.has(fact.via)) {
|
|
1218
|
+
if (arrived) widened = true;
|
|
1219
|
+
else narrowed = true;
|
|
898
1220
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
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.10.
|
|
2444
|
+
var VERSION = "0.10.1";
|
|
2032
2445
|
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
2033
2446
|
|
|
2034
2447
|
// src/lock/provenance.ts
|
|
@@ -2832,6 +3245,12 @@ function createAuthProvider(server2, options = {}) {
|
|
|
2832
3245
|
|
|
2833
3246
|
// src/mcp/types.ts
|
|
2834
3247
|
import { UnauthorizedError as UnauthorizedError2 } from "@modelcontextprotocol/client";
|
|
3248
|
+
var MAX_REASON_CHARS = 2048;
|
|
3249
|
+
function boundReason(text, limit = MAX_REASON_CHARS) {
|
|
3250
|
+
if (text.length <= limit) return text;
|
|
3251
|
+
const kept = text.slice(0, limit).replace(/\S*$/, "").trimEnd();
|
|
3252
|
+
return `${kept} \u2026 (${text.length - kept.length} more characters)`;
|
|
3253
|
+
}
|
|
2835
3254
|
var UnreachableServerError = class extends Error {
|
|
2836
3255
|
constructor(serverName, message, cause) {
|
|
2837
3256
|
super(message);
|
|
@@ -3071,13 +3490,50 @@ function buildTransport(server2, captureStderr = () => {
|
|
|
3071
3490
|
child.stderr?.on("data", (chunk) => captureStderr(chunk.toString("utf8")));
|
|
3072
3491
|
return child;
|
|
3073
3492
|
}
|
|
3074
|
-
const
|
|
3493
|
+
const ownAgent = Object.keys(transport2.headers).some((name) => name.toLowerCase() === "user-agent");
|
|
3494
|
+
const headers = { ...ownAgent ? {} : { "user-agent": USER_AGENT }, ...transport2.headers };
|
|
3075
3495
|
const url = new URL(transport2.url);
|
|
3076
3496
|
const authProvider = createAuthProvider(server2, options);
|
|
3077
3497
|
const custom = options.fetch ? { fetch: options.fetch } : {};
|
|
3078
3498
|
if (transport2.type === "sse") return new SSEClientTransport(url, { requestInit: { headers }, authProvider, ...custom });
|
|
3079
3499
|
return new StreamableHTTPClientTransport(url, { requestInit: { headers }, authProvider, ...custom });
|
|
3080
3500
|
}
|
|
3501
|
+
var KILL_GRACE_MS = 1e3;
|
|
3502
|
+
var signalled = /* @__PURE__ */ new Set();
|
|
3503
|
+
var closing = /* @__PURE__ */ new Set();
|
|
3504
|
+
var open = /* @__PURE__ */ new Set();
|
|
3505
|
+
var exitHooked = false;
|
|
3506
|
+
function isRunning(pid) {
|
|
3507
|
+
try {
|
|
3508
|
+
process.kill(pid, 0);
|
|
3509
|
+
return true;
|
|
3510
|
+
} catch (error) {
|
|
3511
|
+
return error.code === "EPERM";
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
function signal(pid, name) {
|
|
3515
|
+
try {
|
|
3516
|
+
process.kill(pid, name);
|
|
3517
|
+
} catch {
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
function stopProcess(pid) {
|
|
3521
|
+
if (!isRunning(pid)) return;
|
|
3522
|
+
signalled.add(pid);
|
|
3523
|
+
signal(pid, "SIGTERM");
|
|
3524
|
+
setTimeout(() => {
|
|
3525
|
+
if (isRunning(pid)) signal(pid, "SIGKILL");
|
|
3526
|
+
signalled.delete(pid);
|
|
3527
|
+
}, KILL_GRACE_MS).unref();
|
|
3528
|
+
}
|
|
3529
|
+
function hookExit() {
|
|
3530
|
+
if (exitHooked) return;
|
|
3531
|
+
exitHooked = true;
|
|
3532
|
+
process.on("exit", () => {
|
|
3533
|
+
for (const pid of [...signalled, ...closing]) signal(pid, "SIGKILL");
|
|
3534
|
+
for (const transport2 of open) if (transport2.pid !== null) signal(transport2.pid, "SIGKILL");
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3081
3537
|
function diagnosticLines(stderr, limit = 3) {
|
|
3082
3538
|
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
3539
|
const named = lines.filter((line) => /\b(error|exception|cannot|failed|refused|denied|not found|enoent|eacces)\b/i.test(line));
|
|
@@ -3112,27 +3568,55 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
3112
3568
|
});
|
|
3113
3569
|
}
|
|
3114
3570
|
let transport2;
|
|
3115
|
-
const
|
|
3571
|
+
const stop = () => {
|
|
3572
|
+
if (transport2 instanceof StdioClientTransport) {
|
|
3573
|
+
open.delete(transport2);
|
|
3574
|
+
if (transport2.pid !== null) stopProcess(transport2.pid);
|
|
3575
|
+
}
|
|
3116
3576
|
void transport2?.close().catch(() => {
|
|
3117
3577
|
});
|
|
3118
|
-
}
|
|
3578
|
+
};
|
|
3579
|
+
const guard = new SurfaceGuard(stop);
|
|
3119
3580
|
try {
|
|
3120
3581
|
transport2 = buildTransport(server2, captureStderr, { ...options, fetch: guardedFetch(guard) });
|
|
3121
3582
|
} catch (error) {
|
|
3122
3583
|
throw new UnreachableServerError(server2.name, `could not prepare transport: ${error.message}`, error);
|
|
3123
3584
|
}
|
|
3124
3585
|
guardMessages(transport2, guard);
|
|
3586
|
+
const built = transport2;
|
|
3587
|
+
if (built instanceof StdioClientTransport) {
|
|
3588
|
+
hookExit();
|
|
3589
|
+
open.add(built);
|
|
3590
|
+
const start = built.start.bind(built);
|
|
3591
|
+
built.start = async () => {
|
|
3592
|
+
await start();
|
|
3593
|
+
if (options.signal?.aborted) {
|
|
3594
|
+
stop();
|
|
3595
|
+
throw new UnreachableServerError(server2.name, "stopped: the deadline passed while it was starting");
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
}
|
|
3599
|
+
options.signal?.addEventListener("abort", stop, { once: true });
|
|
3600
|
+
const close = async () => {
|
|
3601
|
+
options.signal?.removeEventListener("abort", stop);
|
|
3602
|
+
const pid = built instanceof StdioClientTransport ? built.pid : null;
|
|
3603
|
+
if (pid !== null) closing.add(pid);
|
|
3604
|
+
if (built instanceof StdioClientTransport) open.delete(built);
|
|
3605
|
+
await client.close().catch(() => {
|
|
3606
|
+
});
|
|
3607
|
+
if (pid !== null) closing.delete(pid);
|
|
3608
|
+
};
|
|
3125
3609
|
try {
|
|
3126
3610
|
await client.connect(transport2, { timeout: timeoutMs });
|
|
3127
3611
|
} catch (error) {
|
|
3128
|
-
|
|
3129
|
-
|
|
3612
|
+
if (options.signal?.aborted) stop();
|
|
3613
|
+
await close();
|
|
3130
3614
|
if (guard.refusal !== void 0) throw new UnreachableServerError(server2.name, guard.refusal, error);
|
|
3131
3615
|
const detail = stderrBuffer.trim();
|
|
3132
3616
|
const network = describeNetworkFailure(error);
|
|
3133
3617
|
throw new UnreachableServerError(
|
|
3134
3618
|
server2.name,
|
|
3135
|
-
`${error.message}${network ? ` (${network})` : ""}${detail ? `
|
|
3619
|
+
`${boundReason(error.message, MAX_REASON_CHARS / 2)}${network ? ` (${network})` : ""}${detail ? `
|
|
3136
3620
|
server stderr: ${diagnosticLines(detail).join("\n ")}` : ""}`,
|
|
3137
3621
|
error
|
|
3138
3622
|
);
|
|
@@ -3143,10 +3627,7 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
3143
3627
|
refused: () => guard.refusal,
|
|
3144
3628
|
watchChanges: () => changes.clear(),
|
|
3145
3629
|
changed: () => [...changes].sort(),
|
|
3146
|
-
close
|
|
3147
|
-
await client.close().catch(() => {
|
|
3148
|
-
});
|
|
3149
|
-
}
|
|
3630
|
+
close
|
|
3150
3631
|
};
|
|
3151
3632
|
}
|
|
3152
3633
|
|
|
@@ -3235,16 +3716,18 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
|
3235
3716
|
let expired = false;
|
|
3236
3717
|
let timer;
|
|
3237
3718
|
const late = () => new UnreachableServerError(server2.name, `did not finish within ${timeoutMs}ms`);
|
|
3719
|
+
const giveUp = new AbortController();
|
|
3238
3720
|
const deadline = new Promise((_resolve, reject) => {
|
|
3239
3721
|
timer = setTimeout(() => {
|
|
3240
3722
|
expired = true;
|
|
3723
|
+
giveUp.abort();
|
|
3241
3724
|
void connection?.close();
|
|
3242
3725
|
reject(late());
|
|
3243
3726
|
}, timeoutMs);
|
|
3244
3727
|
timer.unref?.();
|
|
3245
3728
|
});
|
|
3246
3729
|
const work = (async () => {
|
|
3247
|
-
const opened = await connect(server2, timeoutMs);
|
|
3730
|
+
const opened = await connect(server2, timeoutMs, { signal: giveUp.signal });
|
|
3248
3731
|
if (expired) {
|
|
3249
3732
|
await opened.close();
|
|
3250
3733
|
throw late();
|
|
@@ -3312,12 +3795,20 @@ async function readLists(client, server2, timeoutMs) {
|
|
|
3312
3795
|
};
|
|
3313
3796
|
}
|
|
3314
3797
|
|
|
3798
|
+
// src/lib/own.ts
|
|
3799
|
+
function own(record, name) {
|
|
3800
|
+
return record !== void 0 && Object.hasOwn(record, name) ? record[name] : void 0;
|
|
3801
|
+
}
|
|
3802
|
+
function setOwn(record, name, value) {
|
|
3803
|
+
Object.defineProperty(record, name, { value, enumerable: true, writable: true, configurable: true });
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3315
3806
|
// src/audit.ts
|
|
3316
3807
|
async function provenanceOf(server2, options) {
|
|
3317
3808
|
if (server2.transport.type !== "stdio") return { unverified: false };
|
|
3318
3809
|
const reference = referenceOf(server2.transport, options.projectRoot);
|
|
3319
3810
|
if (!reference) return { unverified: false };
|
|
3320
|
-
const previous = options.previous?.subjects
|
|
3811
|
+
const previous = own(options.previous?.subjects, server2.name)?.provenance;
|
|
3321
3812
|
const elsewhere = fetchedElsewhere(server2.transport, reference, { projectRoot: options.projectRoot });
|
|
3322
3813
|
if (elsewhere) return { unverified: true, ...previous ? { displaced: { previous, why: elsewhere } } : {} };
|
|
3323
3814
|
if (options.provenance === false) {
|
|
@@ -3346,8 +3837,10 @@ async function mapWithLimit(items, limit, worker) {
|
|
|
3346
3837
|
async function captureAll(options) {
|
|
3347
3838
|
const discovery = await discoverServers(options.projectRoot, options.configFiles, { userConfigs: options.userConfigs === true });
|
|
3348
3839
|
const captured = await mapWithLimit(discovery.servers, options.concurrency ?? 4, async (server2) => {
|
|
3840
|
+
let established;
|
|
3349
3841
|
try {
|
|
3350
|
-
|
|
3842
|
+
established = await provenanceOf(server2, options);
|
|
3843
|
+
const { provenance: provenance2, unverified: unverified2, displaced: displaced2 } = established;
|
|
3351
3844
|
const pinned = server2.transport.type === "stdio" ? launchPinned(server2.transport, provenance2) : void 0;
|
|
3352
3845
|
const surface = await captureSurface(pinned ? { ...server2, transport: pinned } : server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2);
|
|
3353
3846
|
const entry = buildLockedServer(server2, surface, options.policy);
|
|
@@ -3355,9 +3848,9 @@ async function captureAll(options) {
|
|
|
3355
3848
|
return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2, displaced: displaced2 };
|
|
3356
3849
|
} catch (error) {
|
|
3357
3850
|
options.onServerDone?.(server2.name, "failed");
|
|
3358
|
-
const reason = withoutSecrets(error instanceof UnreachableServerError ? error.message : error.message, server2);
|
|
3851
|
+
const reason = boundReason(withoutSecrets(error instanceof UnreachableServerError ? error.message : error.message, server2));
|
|
3359
3852
|
const kind = authFailureKind(error) ?? "unreachable";
|
|
3360
|
-
return { name: server2.name, failure: { server: server2.name, reason, kind } };
|
|
3853
|
+
return { name: server2.name, failure: { server: server2.name, reason, kind }, provenance: established?.provenance, displaced: established?.displaced };
|
|
3361
3854
|
}
|
|
3362
3855
|
});
|
|
3363
3856
|
const subjects = {};
|
|
@@ -3365,21 +3858,24 @@ async function captureAll(options) {
|
|
|
3365
3858
|
const unverified = [];
|
|
3366
3859
|
const displaced = [];
|
|
3367
3860
|
const unaudited = {};
|
|
3861
|
+
const unauditedProvenance = {};
|
|
3368
3862
|
const configured = new Map(discovery.servers.map((server2) => [server2.name, server2]));
|
|
3369
3863
|
for (const result of captured) {
|
|
3370
3864
|
if ("entry" in result && result.entry) {
|
|
3371
|
-
subjects
|
|
3865
|
+
setOwn(subjects, result.name, result.entry);
|
|
3372
3866
|
if (result.unverified) unverified.push(result.name);
|
|
3373
3867
|
if (result.displaced) displaced.push({ server: result.name, ...result.displaced });
|
|
3374
3868
|
} else if ("failure" in result && result.failure) {
|
|
3375
3869
|
unreachable.push(result.failure);
|
|
3376
3870
|
const server2 = configured.get(result.name);
|
|
3377
|
-
unaudited
|
|
3871
|
+
setOwn(unaudited, result.name, server2 ? { transport: lockTransport(server2) } : {});
|
|
3872
|
+
if (result.provenance) setOwn(unauditedProvenance, result.name, result.provenance);
|
|
3873
|
+
if (result.displaced) displaced.push({ server: result.name, ...result.displaced });
|
|
3378
3874
|
}
|
|
3379
3875
|
}
|
|
3380
3876
|
for (const skipped of discovery.skipped) {
|
|
3381
|
-
unreachable.push({ server: skipped.serverName, reason: skipped.message, kind: "unreachable" });
|
|
3382
|
-
unaudited
|
|
3877
|
+
unreachable.push({ server: skipped.serverName, reason: boundReason(skipped.message), kind: "unreachable" });
|
|
3878
|
+
setOwn(unaudited, skipped.serverName, skipped.transport ? { transport: skipped.transport } : {});
|
|
3383
3879
|
}
|
|
3384
3880
|
for (const conflict of discovery.conflicts) {
|
|
3385
3881
|
unreachable.push({
|
|
@@ -3389,7 +3885,7 @@ async function captureAll(options) {
|
|
|
3389
3885
|
});
|
|
3390
3886
|
}
|
|
3391
3887
|
for (const problem of discovery.problems) {
|
|
3392
|
-
unreachable.push({ server: problem.file, reason: problem.reason, kind: "unreachable" });
|
|
3888
|
+
unreachable.push({ server: problem.file, reason: boundReason(problem.reason), kind: "unreachable" });
|
|
3393
3889
|
}
|
|
3394
3890
|
return {
|
|
3395
3891
|
lock: {
|
|
@@ -3403,16 +3899,43 @@ async function captureAll(options) {
|
|
|
3403
3899
|
unverified: unverified.sort(),
|
|
3404
3900
|
displaced,
|
|
3405
3901
|
unaudited,
|
|
3902
|
+
unauditedProvenance,
|
|
3406
3903
|
conflicted: discovery.conflicts.map((conflict) => conflict.name),
|
|
3407
3904
|
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))
|
|
3408
3905
|
};
|
|
3409
3906
|
}
|
|
3410
3907
|
function acknowledged(committed, name, now) {
|
|
3411
|
-
const agreed = committed.unaudited?.
|
|
3412
|
-
return agreed !== void 0 &&
|
|
3908
|
+
const agreed = own(committed.unaudited, name)?.transport;
|
|
3909
|
+
return agreed !== void 0 && now.transport !== void 0 && stableKey(agreed) === stableKey(now.transport);
|
|
3910
|
+
}
|
|
3911
|
+
function unagreed(agreed, now, reason) {
|
|
3912
|
+
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}`;
|
|
3913
|
+
if (agreed === void 0) return `new server, which could not be audited: ${reason}`;
|
|
3914
|
+
if (agreed.transport === void 0) {
|
|
3915
|
+
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}`;
|
|
3916
|
+
}
|
|
3917
|
+
return `a server left unaudited is now reached differently, and could not be audited: ${reason}`;
|
|
3918
|
+
}
|
|
3919
|
+
function unreadPin(name, pinned, now, runs, reason) {
|
|
3920
|
+
const changes = [];
|
|
3921
|
+
if (now.transport === void 0 || stableKey(now.transport) !== stableKey(pinned.transport)) {
|
|
3922
|
+
changes.push({
|
|
3923
|
+
kind: "server.transport.changed",
|
|
3924
|
+
severity: SEVERITY["server.transport.changed"],
|
|
3925
|
+
server: name,
|
|
3926
|
+
summary: `the server is reached differently than when it was pinned, and could not be audited: ${reason}`,
|
|
3927
|
+
before: pinned.transport,
|
|
3928
|
+
after: now.transport
|
|
3929
|
+
});
|
|
3930
|
+
}
|
|
3931
|
+
if (runs !== void 0) {
|
|
3932
|
+
const unread = { ...pinned, provenance: runs, digest: "unread" };
|
|
3933
|
+
changes.push(...diffLockfiles({ lockfileVersion: LOCKFILE_VERSION, subjects: { [name]: pinned } }, { lockfileVersion: LOCKFILE_VERSION, subjects: { [name]: unread } }));
|
|
3934
|
+
}
|
|
3935
|
+
return changes;
|
|
3413
3936
|
}
|
|
3414
3937
|
function compareWithLock(committed, result) {
|
|
3415
|
-
const changes = diffLockfiles(committed, result.lock);
|
|
3938
|
+
const changes = diffLockfiles(committed, result.lock).filter((change2) => !(change2.kind === "server.removed" && own(result.unaudited, change2.server) !== void 0));
|
|
3416
3939
|
for (const moved of result.displaced) {
|
|
3417
3940
|
const was = `${moved.previous.name}${moved.previous.version ? `@${moved.previous.version}` : ""}`;
|
|
3418
3941
|
changes.push({
|
|
@@ -3425,16 +3948,21 @@ function compareWithLock(committed, result) {
|
|
|
3425
3948
|
}
|
|
3426
3949
|
const failed = new Map(result.unreachable.map((failure) => [failure.server, failure.reason]));
|
|
3427
3950
|
for (const [name, now] of Object.entries(result.unaudited)) {
|
|
3428
|
-
|
|
3951
|
+
const pinned = own(committed.subjects, name);
|
|
3952
|
+
if (pinned !== void 0) {
|
|
3953
|
+
changes.push(...unreadPin(name, pinned, now, own(result.unauditedProvenance, name), failed.get(name) ?? "it did not answer"));
|
|
3954
|
+
continue;
|
|
3955
|
+
}
|
|
3956
|
+
if (acknowledged(committed, name, now)) continue;
|
|
3429
3957
|
changes.push({
|
|
3430
3958
|
kind: "server.added",
|
|
3431
3959
|
severity: SEVERITY["server.added"],
|
|
3432
3960
|
server: name,
|
|
3433
|
-
summary:
|
|
3961
|
+
summary: unagreed(own(committed.unaudited, name), now, failed.get(name) ?? "it did not answer")
|
|
3434
3962
|
});
|
|
3435
3963
|
}
|
|
3436
3964
|
for (const name of result.conflicted) {
|
|
3437
|
-
if (committed.subjects
|
|
3965
|
+
if (own(committed.subjects, name) !== void 0) continue;
|
|
3438
3966
|
changes.push({
|
|
3439
3967
|
kind: "server.added",
|
|
3440
3968
|
severity: SEVERITY["server.added"],
|
|
@@ -3445,19 +3973,64 @@ function compareWithLock(committed, result) {
|
|
|
3445
3973
|
return sortChanges(changes);
|
|
3446
3974
|
}
|
|
3447
3975
|
function unauditedToRecord(result, keep = () => true) {
|
|
3448
|
-
const entries = Object.entries(result.unaudited).filter(([name]) => keep(name));
|
|
3976
|
+
const entries = Object.entries(result.unaudited).filter(([name, entry]) => entry.transport !== void 0 && name !== "__proto__" && keep(name));
|
|
3449
3977
|
return entries.length > 0 ? Object.fromEntries(entries) : void 0;
|
|
3450
3978
|
}
|
|
3979
|
+
function decoded2(value) {
|
|
3980
|
+
try {
|
|
3981
|
+
return decodeURIComponent(value);
|
|
3982
|
+
} catch {
|
|
3983
|
+
return value;
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3986
|
+
function addressSecrets(address) {
|
|
3987
|
+
let url;
|
|
3988
|
+
try {
|
|
3989
|
+
url = new URL(address);
|
|
3990
|
+
} catch {
|
|
3991
|
+
return [];
|
|
3992
|
+
}
|
|
3993
|
+
const out = [url.username, url.password, decoded2(url.username), decoded2(url.password)];
|
|
3994
|
+
for (const [, value] of url.searchParams) out.push(value);
|
|
3995
|
+
for (const pair of url.search.slice(1).split("&")) out.push(pair.slice(pair.indexOf("=") + 1));
|
|
3996
|
+
if (url.hash.length > 1) out.push(url.hash.slice(1));
|
|
3997
|
+
const kept = redactPath(url.pathname).split("/");
|
|
3998
|
+
url.pathname.split("/").forEach((segment, index) => {
|
|
3999
|
+
if (kept[index] !== segment) out.push(segment, decoded2(segment));
|
|
4000
|
+
});
|
|
4001
|
+
return out;
|
|
4002
|
+
}
|
|
4003
|
+
function replacedParts(original, redacted) {
|
|
4004
|
+
const kept = redacted.split(REDACTED);
|
|
4005
|
+
const parts = [];
|
|
4006
|
+
let at = 0;
|
|
4007
|
+
for (const [index, piece] of kept.entries()) {
|
|
4008
|
+
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);
|
|
4009
|
+
if (found < 0) return [original];
|
|
4010
|
+
if (index > 0) parts.push(original.slice(at, found));
|
|
4011
|
+
at = found + piece.length;
|
|
4012
|
+
}
|
|
4013
|
+
return parts;
|
|
4014
|
+
}
|
|
3451
4015
|
function withoutSecrets(reason, server2) {
|
|
3452
4016
|
const { transport: transport2 } = server2;
|
|
3453
4017
|
const secrets = [];
|
|
4018
|
+
for (const { name, value } of transport2.filled ?? []) {
|
|
4019
|
+
if (isCredentialName(name) || !/^(?:[./~]|[A-Za-z]:\\)/.test(value)) secrets.push(value, ...addressSecrets(value));
|
|
4020
|
+
}
|
|
3454
4021
|
if (transport2.type === "stdio") {
|
|
3455
4022
|
for (const [name, value] of Object.entries(transport2.env)) {
|
|
3456
4023
|
if (isCredentialName(name) || value.length >= 16 && !/[\s/\\]/.test(value)) secrets.push(value);
|
|
3457
4024
|
}
|
|
4025
|
+
const redacted = redactArgs(transport2.args);
|
|
4026
|
+
transport2.args.forEach((argument, index) => {
|
|
4027
|
+
const kept = redacted[index];
|
|
4028
|
+
if (kept !== void 0 && kept !== argument) secrets.push(...replacedParts(argument, kept));
|
|
4029
|
+
});
|
|
3458
4030
|
} else {
|
|
3459
4031
|
for (const value of Object.values(transport2.headers)) secrets.push(value, ...value.split(/\s+/));
|
|
3460
4032
|
if (transport2.oauth?.clientSecret) secrets.push(transport2.oauth.clientSecret);
|
|
4033
|
+
secrets.push(...addressSecrets(transport2.url));
|
|
3461
4034
|
}
|
|
3462
4035
|
let out = reason;
|
|
3463
4036
|
for (const secret of [...new Set(secrets)].filter((value) => value.length >= 8).sort((a, b) => b.length - a.length)) {
|
|
@@ -3842,7 +4415,7 @@ function renderSteering(report) {
|
|
|
3842
4415
|
for (const { server: server2, signals } of found) {
|
|
3843
4416
|
lines.push(` ${bold(visibleControls(server2))}`);
|
|
3844
4417
|
const byField = /* @__PURE__ */ new Map();
|
|
3845
|
-
for (const
|
|
4418
|
+
for (const signal2 of signals) byField.set(signal2.field, [...byField.get(signal2.field) ?? [], signal2.quote]);
|
|
3846
4419
|
const fields = [...byField];
|
|
3847
4420
|
for (const [field, quotes] of fields.slice(0, 4)) {
|
|
3848
4421
|
const more = quotes.length > 1 ? ` (+${quotes.length - 1} more here)` : "";
|
|
@@ -3956,7 +4529,7 @@ function redactedLine(count) {
|
|
|
3956
4529
|
function redactedNotes(lock) {
|
|
3957
4530
|
return Object.entries(lock.subjects).flatMap(([name, entry]) => {
|
|
3958
4531
|
const count = countRedacted(entry.transport);
|
|
3959
|
-
return count > 0 ? [`${name}: ${redactedLine(count)}`] : [];
|
|
4532
|
+
return count > 0 ? [`${visibleControls(name)}: ${redactedLine(count)}`] : [];
|
|
3960
4533
|
});
|
|
3961
4534
|
}
|
|
3962
4535
|
|
|
@@ -4027,6 +4600,13 @@ function helpUriFor(anchor) {
|
|
|
4027
4600
|
return base === void 0 ? void 0 : `${base}/blob/main/docs/lockfile.md#${anchor}`;
|
|
4028
4601
|
}
|
|
4029
4602
|
|
|
4603
|
+
// src/report/types.ts
|
|
4604
|
+
var AUDIT_FAILURE_LABEL = {
|
|
4605
|
+
auth: "refused the audit",
|
|
4606
|
+
forbidden: "accepted the credentials and refused",
|
|
4607
|
+
unreachable: "unreachable"
|
|
4608
|
+
};
|
|
4609
|
+
|
|
4030
4610
|
// src/report/sarif.ts
|
|
4031
4611
|
var LEVEL = {
|
|
4032
4612
|
high: "error",
|
|
@@ -4037,6 +4617,7 @@ var DENIED_RULE = "policy.capability.denied";
|
|
|
4037
4617
|
var STEERING_RULE = "steering.passage.arrived";
|
|
4038
4618
|
var UNVERIFIED_RULE = "server.artifact.unverified";
|
|
4039
4619
|
var PARTIAL_RULE = "server.surface.partial";
|
|
4620
|
+
var UNREAD_RULE = "server.surface.unread";
|
|
4040
4621
|
var RULE_HELP = {
|
|
4041
4622
|
"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
4623
|
"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 +4645,7 @@ function renderSarifReport(report, options = {}) {
|
|
|
4064
4645
|
const steering = options.steering ? report.steering ?? [] : [];
|
|
4065
4646
|
const unverified = report.unverified ?? [];
|
|
4066
4647
|
const partial = report.partial ?? [];
|
|
4648
|
+
const unread = report.unreachable;
|
|
4067
4649
|
const at = (name, qualified) => [
|
|
4068
4650
|
{
|
|
4069
4651
|
physicalLocation: { artifactLocation: { uri: sarifUri(report), uriBaseId: "%SRCROOT%" } },
|
|
@@ -4092,6 +4674,13 @@ function renderSarifReport(report, options = {}) {
|
|
|
4092
4674
|
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
4675
|
defaultConfiguration: { level: "warning" }
|
|
4094
4676
|
}] : [],
|
|
4677
|
+
...unread.length > 0 ? [{
|
|
4678
|
+
id: UNREAD_RULE,
|
|
4679
|
+
name: "ServerSurfaceUnread",
|
|
4680
|
+
shortDescription: { text: "A server's surface could not be read" },
|
|
4681
|
+
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." },
|
|
4682
|
+
defaultConfiguration: { level: "warning" }
|
|
4683
|
+
}] : [],
|
|
4095
4684
|
...unverified.length > 0 ? [{
|
|
4096
4685
|
id: UNVERIFIED_RULE,
|
|
4097
4686
|
name: "ServerArtifactUnverified",
|
|
@@ -4139,12 +4728,12 @@ function renderSarifReport(report, options = {}) {
|
|
|
4139
4728
|
partialFingerprints: { "mcpAuditChange/v1": `${violation.server}/${violation.tool}/${violation.kind}` }
|
|
4140
4729
|
})),
|
|
4141
4730
|
...steering.flatMap(
|
|
4142
|
-
({ server: server2, signals }) => signals.map((
|
|
4731
|
+
({ server: server2, signals }) => signals.map((signal2) => ({
|
|
4143
4732
|
ruleId: STEERING_RULE,
|
|
4144
4733
|
level: "note",
|
|
4145
|
-
message: { text: `${server2} \u203A ${
|
|
4146
|
-
locations: at(
|
|
4147
|
-
partialFingerprints: { "mcpAuditChange/v1": `${server2}/${
|
|
4734
|
+
message: { text: `${server2} \u203A ${signal2.field}: ${signal2.quote}` },
|
|
4735
|
+
locations: at(signal2.field, `${server2}/${signal2.field}`),
|
|
4736
|
+
partialFingerprints: { "mcpAuditChange/v1": `${server2}/${signal2.field}/${signal2.kind}` }
|
|
4148
4737
|
}))
|
|
4149
4738
|
),
|
|
4150
4739
|
...partial.map((entry) => ({
|
|
@@ -4154,6 +4743,13 @@ function renderSarifReport(report, options = {}) {
|
|
|
4154
4743
|
locations: at(entry.server, entry.server),
|
|
4155
4744
|
partialFingerprints: { "mcpAuditChange/v1": `${entry.server}/partial` }
|
|
4156
4745
|
})),
|
|
4746
|
+
...unread.map((failure) => ({
|
|
4747
|
+
ruleId: UNREAD_RULE,
|
|
4748
|
+
level: "warning",
|
|
4749
|
+
message: { text: `${failure.server}: could not be read (${AUDIT_FAILURE_LABEL[failure.kind]}). ${failure.reason}` },
|
|
4750
|
+
locations: at(failure.server, failure.server),
|
|
4751
|
+
partialFingerprints: { "mcpAuditChange/v1": `${failure.server}/unread` }
|
|
4752
|
+
})),
|
|
4157
4753
|
...unverified.map((server2) => ({
|
|
4158
4754
|
ruleId: UNVERIFIED_RULE,
|
|
4159
4755
|
level: "note",
|
|
@@ -4170,11 +4766,6 @@ function renderSarifReport(report, options = {}) {
|
|
|
4170
4766
|
}
|
|
4171
4767
|
|
|
4172
4768
|
// 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
4769
|
var MARK2 = { high: "\u{1F534}", medium: "\u{1F7E0}", low: "\u26AA" };
|
|
4179
4770
|
function plain(text) {
|
|
4180
4771
|
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 +4781,13 @@ function row(change2) {
|
|
|
4190
4781
|
const where2 = change2.member ? `${change2.server}/${change2.member}` : change2.server;
|
|
4191
4782
|
return `| ${MARK2[change2.severity]} ${change2.severity} | ${code(where2)} | ${plain(change2.kind)} | ${plain(change2.summary)} |`;
|
|
4192
4783
|
}
|
|
4784
|
+
function renderResolvedReport(report) {
|
|
4785
|
+
return [
|
|
4786
|
+
"### Nothing to review: every server matches the lock",
|
|
4787
|
+
"",
|
|
4788
|
+
`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.`
|
|
4789
|
+
].join("\n");
|
|
4790
|
+
}
|
|
4193
4791
|
function renderMarkdownReport(report, options = {}) {
|
|
4194
4792
|
const violations = report.violations ?? [];
|
|
4195
4793
|
const partial = report.partial ?? [];
|
|
@@ -4242,7 +4840,7 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
4242
4840
|
"| Server | Field | Passage |",
|
|
4243
4841
|
"| --- | --- | --- |",
|
|
4244
4842
|
...steering.flatMap(
|
|
4245
|
-
({ server: server2, signals }) => signals.slice(0, 10).map((
|
|
4843
|
+
({ server: server2, signals }) => signals.slice(0, 10).map((signal2) => `| ${code(server2)} | ${code(signal2.field)} | ${plain(signal2.quote)} |`)
|
|
4246
4844
|
),
|
|
4247
4845
|
"",
|
|
4248
4846
|
"</details>",
|
|
@@ -4294,6 +4892,15 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
4294
4892
|
|
|
4295
4893
|
// src/report/comment.ts
|
|
4296
4894
|
var MARKER = "<!-- nulladrift:surface -->";
|
|
4895
|
+
var PER_PAGE = 100;
|
|
4896
|
+
var MAX_COMMENT_PAGES = 10;
|
|
4897
|
+
var MAX_COMMENT_CHARS = 65536;
|
|
4898
|
+
function fitted(body) {
|
|
4899
|
+
if (body.length <= MAX_COMMENT_CHARS) return body;
|
|
4900
|
+
const note = "\n\n_The rest of this report was cut short to fit a comment; the job log has all of it._";
|
|
4901
|
+
const room = body.slice(0, MAX_COMMENT_CHARS - note.length);
|
|
4902
|
+
return `${room.slice(0, Math.max(room.lastIndexOf("\n"), 0))}${note}`;
|
|
4903
|
+
}
|
|
4297
4904
|
function targetFromEnvironment(env = process.env) {
|
|
4298
4905
|
const token = env["GITHUB_TOKEN"];
|
|
4299
4906
|
const repo = env["GITHUB_REPOSITORY"];
|
|
@@ -4321,20 +4928,26 @@ async function call(target, path, init = {}) {
|
|
|
4321
4928
|
signal: AbortSignal.timeout(1e4)
|
|
4322
4929
|
});
|
|
4323
4930
|
}
|
|
4324
|
-
async function upsertComment(target, body) {
|
|
4325
|
-
const marked = `${MARKER}
|
|
4326
|
-
${body}
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4931
|
+
async function upsertComment(target, body, options = {}) {
|
|
4932
|
+
const marked = fitted(`${MARKER}
|
|
4933
|
+
${body}`);
|
|
4934
|
+
let self;
|
|
4935
|
+
let mine;
|
|
4936
|
+
for (let page = 1; page <= MAX_COMMENT_PAGES && mine === void 0; page += 1) {
|
|
4937
|
+
const existing = await call(target, `/issues/${target.issue}/comments?per_page=${PER_PAGE}&page=${page}`);
|
|
4938
|
+
if (existing.status === 403) return "forbidden";
|
|
4939
|
+
if (!existing.ok) throw new Error(`could not read the comments (${existing.status})`);
|
|
4940
|
+
self ??= await identity2(target);
|
|
4941
|
+
const comments = await existing.json();
|
|
4942
|
+
mine = comments.find((comment2) => comment2.body?.startsWith(MARKER) && comment2.user?.login === self);
|
|
4943
|
+
if (comments.length < PER_PAGE) break;
|
|
4944
|
+
}
|
|
4333
4945
|
if (mine) {
|
|
4334
4946
|
const updated = await call(target, `/issues/comments/${mine.id}`, { method: "PATCH", body: JSON.stringify({ body: marked }) });
|
|
4335
4947
|
if (updated.ok) return "updated";
|
|
4336
4948
|
if (updated.status !== 403 && updated.status !== 404) throw new Error(`could not update the comment (${updated.status})`);
|
|
4337
4949
|
}
|
|
4950
|
+
if (options.create === false) return "none";
|
|
4338
4951
|
const created = await call(target, `/issues/${target.issue}/comments`, { method: "POST", body: JSON.stringify({ body: marked }) });
|
|
4339
4952
|
if (created.status === 403) return "forbidden";
|
|
4340
4953
|
if (!created.ok) throw new Error(`could not post the comment (${created.status})`);
|
|
@@ -4521,9 +5134,9 @@ async function comment(report) {
|
|
|
4521
5134
|
return;
|
|
4522
5135
|
}
|
|
4523
5136
|
const body = renderMarkdownReport(report);
|
|
4524
|
-
if (!body) return;
|
|
4525
5137
|
try {
|
|
4526
|
-
const outcome = await upsertComment(target, body);
|
|
5138
|
+
const outcome = await upsertComment(target, body ?? renderResolvedReport(report), { create: body !== null });
|
|
5139
|
+
if (outcome === "none") return;
|
|
4527
5140
|
if (outcome === "forbidden") {
|
|
4528
5141
|
process.stderr.write(
|
|
4529
5142
|
`${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.
|
|
@@ -4709,7 +5322,7 @@ async function runInit(options) {
|
|
|
4709
5322
|
);
|
|
4710
5323
|
if (steering.length > 0) {
|
|
4711
5324
|
const byField = /* @__PURE__ */ new Map();
|
|
4712
|
-
for (const
|
|
5325
|
+
for (const signal2 of steering) byField.set(signal2.field, [...byField.get(signal2.field) ?? [], signal2.quote]);
|
|
4713
5326
|
const fields = [...byField];
|
|
4714
5327
|
lines.push(
|
|
4715
5328
|
` ${yellow(`${fields.length} field(s) carry text read as instructions to the model, not documentation:`)}`
|
|
@@ -4729,6 +5342,13 @@ async function runInit(options) {
|
|
|
4729
5342
|
for (const failure of result.unreachable) {
|
|
4730
5343
|
lines.push(` ${red("\u2717")} ${bold(visibleControls(failure.server))} ${dim("not pinned")}`, ` ${visibleLines(failure.reason, " ")}`);
|
|
4731
5344
|
}
|
|
5345
|
+
const unagreeable = Object.keys(result.unaudited).filter((name) => options.allowUnreachable && !Object.hasOwn(unaudited ?? {}, name));
|
|
5346
|
+
if (unagreeable.length > 0) {
|
|
5347
|
+
lines.push(
|
|
5348
|
+
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`),
|
|
5349
|
+
dim(" there is nothing to agree to. `check` will report it until the definition is fixed or removed.")
|
|
5350
|
+
);
|
|
5351
|
+
}
|
|
4732
5352
|
if (result.discovery.userConfigsSkipped.length > 0) {
|
|
4733
5353
|
lines.push(
|
|
4734
5354
|
dim(` note: your own configs were not pinned (${result.discovery.userConfigsSkipped.join(", ")}). mcp.lock is the project's and is committed;`),
|
|
@@ -4736,7 +5356,7 @@ async function runInit(options) {
|
|
|
4736
5356
|
);
|
|
4737
5357
|
}
|
|
4738
5358
|
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.`));
|
|
5359
|
+
lines.push(dim(visibleControls(` note: "${shadow.name}" is defined in both ${shadow.keptFrom} and ${shadow.alsoIn}; kept the first.`)));
|
|
4740
5360
|
}
|
|
4741
5361
|
lines.push(
|
|
4742
5362
|
"",
|
|
@@ -4746,6 +5366,7 @@ async function runInit(options) {
|
|
|
4746
5366
|
process.stdout.write(lines.join("\n"));
|
|
4747
5367
|
await maybeOfferTelemetry();
|
|
4748
5368
|
if (result.unreachable.length > 0 && !options.allowUnreachable) return EXIT_INCOMPLETE;
|
|
5369
|
+
if (!pinnedSomething) return EXIT_INCOMPLETE;
|
|
4749
5370
|
if (result.partial.length > 0 && !options.allowPartial) return EXIT_INCOMPLETE;
|
|
4750
5371
|
return EXIT_CLEAN;
|
|
4751
5372
|
}
|
|
@@ -4834,7 +5455,7 @@ async function runLogin(options) {
|
|
|
4834
5455
|
}
|
|
4835
5456
|
const found = await findServer(options.projectRoot, options.configFiles, options.serverName);
|
|
4836
5457
|
if ("error" in found) {
|
|
4837
|
-
process.stderr.write(`${red(found.error)}
|
|
5458
|
+
process.stderr.write(`${red(visibleControls(found.error, { multiline: true }))}
|
|
4838
5459
|
`);
|
|
4839
5460
|
return EXIT_INCOMPLETE;
|
|
4840
5461
|
}
|
|
@@ -4844,8 +5465,8 @@ async function runLogin(options) {
|
|
|
4844
5465
|
const authenticating = new FileTokenProvider(found.name, serverUrl, { interactive: true, redirectUrl: callback.redirectUrl });
|
|
4845
5466
|
Object.assign(authenticating, { stateValue: provider.stateValue });
|
|
4846
5467
|
try {
|
|
4847
|
-
process.stdout.write(`${bold(`Authorizing ${found.name}`)}
|
|
4848
|
-
${dim(sanitizeUrl(serverUrl))}
|
|
5468
|
+
process.stdout.write(`${bold(`Authorizing ${visibleControls(found.name)}`)}
|
|
5469
|
+
${dim(visibleControls(sanitizeUrl(serverUrl)))}
|
|
4849
5470
|
`);
|
|
4850
5471
|
const started = await auth(authenticating, { serverUrl });
|
|
4851
5472
|
if (started === "AUTHORIZED") {
|
|
@@ -4860,7 +5481,7 @@ ${dim(sanitizeUrl(serverUrl))}
|
|
|
4860
5481
|
`);
|
|
4861
5482
|
return EXIT_INCOMPLETE;
|
|
4862
5483
|
}
|
|
4863
|
-
process.stdout.write(`${green(`\u2713 authorized ${found.name}`)}
|
|
5484
|
+
process.stdout.write(`${green(`\u2713 authorized ${visibleControls(found.name)}`)}
|
|
4864
5485
|
${dim(`tokens stored in ${credentialPath(serverUrl)} (owner-only)`)}
|
|
4865
5486
|
`);
|
|
4866
5487
|
return EXIT_CLEAN;
|
|
@@ -4880,7 +5501,7 @@ async function runLogout(options) {
|
|
|
4880
5501
|
}
|
|
4881
5502
|
const found = await findServer(options.projectRoot, options.configFiles, options.serverName);
|
|
4882
5503
|
if ("error" in found) {
|
|
4883
|
-
process.stderr.write(`${red(found.error)}
|
|
5504
|
+
process.stderr.write(`${red(visibleControls(found.error, { multiline: true }))}
|
|
4884
5505
|
`);
|
|
4885
5506
|
return EXIT_INCOMPLETE;
|
|
4886
5507
|
}
|
|
@@ -4892,7 +5513,7 @@ async function runLogout(options) {
|
|
|
4892
5513
|
);
|
|
4893
5514
|
await rm4(path, { force: true });
|
|
4894
5515
|
process.stdout.write(
|
|
4895
|
-
`${dim(existed ? `stored credentials for ${found.name} (${sanitizeUrl(url)}) deleted` : `no credentials were stored for ${found.name} (${sanitizeUrl(url)})`)}
|
|
5516
|
+
`${dim(visibleControls(existed ? `stored credentials for ${found.name} (${sanitizeUrl(url)}) deleted` : `no credentials were stored for ${found.name} (${sanitizeUrl(url)})`))}
|
|
4896
5517
|
`
|
|
4897
5518
|
);
|
|
4898
5519
|
return EXIT_CLEAN;
|
|
@@ -5325,6 +5946,12 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
5325
5946
|
if (verdict.verdict !== "clean") lines.push("", dim(`Review it at ${shown(verdict.url)}`));
|
|
5326
5947
|
lines.push("");
|
|
5327
5948
|
process.stdout.write(lines.join("\n"));
|
|
5949
|
+
if (result.unreachable.length > 0) {
|
|
5950
|
+
process.stderr.write(
|
|
5951
|
+
`${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.
|
|
5952
|
+
`
|
|
5953
|
+
);
|
|
5954
|
+
}
|
|
5328
5955
|
if (result.partial.length > 0 && options.allowPartial !== true) {
|
|
5329
5956
|
process.stderr.write(
|
|
5330
5957
|
`${yellow("incomplete:")} ${result.partial.map((entry) => visibleControls(entry.server)).join(", ")} could not be read in full. Pass --allow-partial to accept that.
|
|
@@ -5348,13 +5975,13 @@ function describeSurface(subject, previous) {
|
|
|
5348
5975
|
lines.push(worst ? yellow(text) : dim(text));
|
|
5349
5976
|
}
|
|
5350
5977
|
const had = new Set(
|
|
5351
|
-
(typeof previous === "object" && previous !== null ? surfaceText(previous).flatMap((piece) => steeringSignals(piece.text, piece.field)) : []).map((
|
|
5978
|
+
(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
5979
|
);
|
|
5353
|
-
const steering = surfaceText(entry).flatMap((piece) => steeringSignals(piece.text, piece.field)).filter((
|
|
5980
|
+
const steering = surfaceText(entry).flatMap((piece) => steeringSignals(piece.text, piece.field)).filter((signal2) => !had.has(`${signal2.field}\0${signal2.kind}\0${signal2.quote}`));
|
|
5354
5981
|
if (steering.length > 0) {
|
|
5355
5982
|
lines.push(yellow(` ${steering.length} new passage(s) here read as instructions to the model:`));
|
|
5356
5983
|
const byField = /* @__PURE__ */ new Map();
|
|
5357
|
-
for (const
|
|
5984
|
+
for (const signal2 of steering) if (!byField.has(signal2.field)) byField.set(signal2.field, signal2.quote);
|
|
5358
5985
|
for (const [field, quote] of [...byField].slice(0, 3)) {
|
|
5359
5986
|
lines.push(dim(` ${elideMiddle(field, 52)}: ${truncate(quote, 72)}`));
|
|
5360
5987
|
}
|
|
@@ -5412,7 +6039,7 @@ async function runReview(options) {
|
|
|
5412
6039
|
let declined = 0;
|
|
5413
6040
|
try {
|
|
5414
6041
|
for (const [serverName, serverChanges] of grouped) {
|
|
5415
|
-
const context = describeSurface(result.lock.subjects
|
|
6042
|
+
const context = describeSurface(own(result.lock.subjects, serverName), own(committed.subjects, serverName));
|
|
5416
6043
|
process.stdout.write(
|
|
5417
6044
|
`
|
|
5418
6045
|
${bold(visibleControls(serverName))}
|
|
@@ -5430,21 +6057,36 @@ ${context.length > 0 ? `${context.join("\n")}
|
|
|
5430
6057
|
declined += 1;
|
|
5431
6058
|
continue;
|
|
5432
6059
|
}
|
|
6060
|
+
const unread = own(result.lock.subjects, serverName) === void 0 ? own(result.unaudited, serverName) : void 0;
|
|
6061
|
+
if (unread !== void 0 && own(committed.subjects, serverName) !== void 0) {
|
|
6062
|
+
process.stdout.write(
|
|
6063
|
+
` ${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`.")}
|
|
6064
|
+
`
|
|
6065
|
+
);
|
|
6066
|
+
declined += 1;
|
|
6067
|
+
continue;
|
|
6068
|
+
}
|
|
6069
|
+
if (unread !== void 0 && unread.transport === void 0) {
|
|
6070
|
+
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.")}
|
|
6071
|
+
`);
|
|
6072
|
+
declined += 1;
|
|
6073
|
+
continue;
|
|
6074
|
+
}
|
|
5433
6075
|
accepted += 1;
|
|
5434
|
-
let fresh = result.lock.subjects
|
|
5435
|
-
const pin = committed.subjects
|
|
6076
|
+
let fresh = own(result.lock.subjects, serverName);
|
|
6077
|
+
const pin = own(committed.subjects, serverName)?.provenance;
|
|
5436
6078
|
const displaced = result.displaced.some((moved) => moved.server === serverName);
|
|
5437
6079
|
if (fresh && fresh.provenance === void 0 && pin !== void 0 && result.unverified.includes(serverName) && !displaced) {
|
|
5438
6080
|
fresh = { ...fresh, provenance: pin };
|
|
5439
6081
|
}
|
|
5440
|
-
if (fresh) next.subjects
|
|
6082
|
+
if (fresh) setOwn(next.subjects, serverName, fresh);
|
|
5441
6083
|
else delete next.subjects[serverName];
|
|
5442
6084
|
const unaudited = { ...next.unaudited };
|
|
5443
|
-
if (!fresh &&
|
|
6085
|
+
if (!fresh && unread !== void 0) setOwn(unaudited, serverName, unread);
|
|
5444
6086
|
else delete unaudited[serverName];
|
|
5445
6087
|
next.unaudited = Object.keys(unaudited).length > 0 ? unaudited : void 0;
|
|
5446
6088
|
for (const change2 of serverChanges) {
|
|
5447
|
-
if (change2.kind === "server.renamed" && typeof change2.before === "string") delete next.subjects[change2.before];
|
|
6089
|
+
if (change2.kind === "server.renamed" && typeof change2.before === "string" && own(result.unaudited, change2.before) === void 0) delete next.subjects[change2.before];
|
|
5448
6090
|
}
|
|
5449
6091
|
}
|
|
5450
6092
|
} finally {
|