@nulladrift/core 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/changes.d.ts CHANGED
@@ -47,6 +47,11 @@ declare function sortChanges(changes: Change[]): Change[];
47
47
  * It lives beside the taxonomy rather than in the engine because it reasons about a list of
48
48
  * changes and nothing else: the dashboard asks the same question and has no business depending
49
49
  * on a diff engine to do it.
50
+ *
51
+ * Only a server with a surface this run captured can have changed without shipping. A new server
52
+ * that could not be audited arrives as `server.added` with nothing behind it, and one that is
53
+ * gone has nothing now; both were listed as having changed without a release, which describes a
54
+ * surface nobody saw.
50
55
  */
51
56
  declare function serversThatShippedNothing(changes: readonly Change[]): string[];
52
57
 
package/dist/changes.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  SEVERITY_RANK,
6
6
  serversThatShippedNothing,
7
7
  sortChanges
8
- } from "./chunk-JCJXSMBS.js";
8
+ } from "./chunk-6ERBWXWP.js";
9
9
  export {
10
10
  CHANGE_KINDS,
11
11
  SEVERITIES,
@@ -1,13 +1,22 @@
1
1
  import {
2
2
  isEscalation
3
- } from "./chunk-5OCXDAFS.js";
3
+ } from "./chunk-CP2XTAKE.js";
4
4
  import {
5
5
  classifySchemaChange
6
- } from "./chunk-TRNJNLQQ.js";
6
+ } from "./chunk-NSVG7BEU.js";
7
7
  import {
8
8
  SEVERITY,
9
9
  sortChanges
10
- } from "./chunk-JCJXSMBS.js";
10
+ } from "./chunk-6ERBWXWP.js";
11
+ import {
12
+ MAX_FACTS,
13
+ MAX_VISIT_DEPTH,
14
+ alternatives,
15
+ asObject,
16
+ beginWalk,
17
+ effectiveSchema,
18
+ entriesOf
19
+ } from "./chunk-Z4M6ZRTP.js";
11
20
  import {
12
21
  stableKey
13
22
  } from "./chunk-SZKRNTJP.js";
@@ -104,19 +113,43 @@ var CONFUSABLE_PATTERN = new RegExp(`[${Object.keys(CONFUSABLES).join("")}]`, "g
104
113
  function normalize(identifier) {
105
114
  return identifier.toLowerCase().replace(CONFUSABLE_PATTERN, (character) => CONFUSABLES[character] ?? character).replace(/[-.\s/]+/g, "_");
106
115
  }
107
- function argumentNames(inputSchema, depth = 0) {
108
- if (depth > 6 || typeof inputSchema !== "object" || inputSchema === null) return [];
109
- const node = inputSchema;
110
- const names = [];
111
- const properties = node.properties;
112
- if (typeof properties === "object" && properties !== null) {
113
- for (const [name, child] of Object.entries(properties)) {
114
- names.push(name);
115
- names.push(...argumentNames(child, depth + 1));
116
+ var MAX_ARGUMENT_READS = 10 * MAX_FACTS;
117
+ function argumentNames(inputSchema) {
118
+ const root = inputSchema;
119
+ const names = /* @__PURE__ */ new Set();
120
+ let budget = MAX_ARGUMENT_READS;
121
+ const walk = (node, depth) => {
122
+ if (budget <= 0) return false;
123
+ budget -= 1;
124
+ const object = effectiveSchema(node, root);
125
+ if (!object) return true;
126
+ const deeper = depth < MAX_VISIT_DEPTH;
127
+ const into = (child) => deeper && child !== null && typeof child === "object" ? walk(child, depth + 1) : budget > 0;
128
+ const properties = asObject(object["properties"]);
129
+ if (properties) {
130
+ for (const [name, child] of entriesOf(properties)) {
131
+ if (--budget <= 0) return false;
132
+ names.add(name);
133
+ if (!into(child)) return false;
134
+ }
116
135
  }
117
- }
118
- if (node.items !== void 0) names.push(...argumentNames(node.items, depth + 1));
119
- return names;
136
+ for (const keyword of ["items", "prefixItems"]) {
137
+ const value = object[keyword];
138
+ if (Array.isArray(value)) {
139
+ for (const child of value) if (!into(child)) return false;
140
+ } else if (!into(value)) return false;
141
+ }
142
+ if (!into(object["additionalProperties"])) return false;
143
+ const patternProperties = asObject(object["patternProperties"]);
144
+ if (patternProperties) {
145
+ for (const [, child] of entriesOf(patternProperties)) if (!into(child)) return false;
146
+ }
147
+ for (const branch of alternatives(object)) if (!into(branch.schema)) return false;
148
+ return true;
149
+ };
150
+ beginWalk(root);
151
+ walk(root, 0);
152
+ return [...names];
120
153
  }
121
154
  function toolCapabilities(tool) {
122
155
  const subject = objectOr(tool);
@@ -259,13 +292,15 @@ function compareTool(name, before, after) {
259
292
  change("tool.header_params.changed", name, "arguments mirrored into HTTP headers changed", { ...at, before: before.headerParams ?? [], after: after.headerParams ?? [] })
260
293
  );
261
294
  }
262
- if (changes.length === 0) {
263
- const moved = [
264
- !same(before.title, after.title) ? "title" : "",
265
- !same(before.icons, after.icons) ? "icons" : "",
266
- !same(before.execution, after.execution) ? `how it may be run (${describeExecution(before.execution)} \u2192 ${describeExecution(after.execution)})` : "",
267
- !same(before.meta, after.meta) ? "_meta" : ""
268
- ].filter(Boolean);
295
+ const moved = [
296
+ !same(before.title, after.title) ? "title" : "",
297
+ // A second title a client shows in place of the name, and the same finding for the same reason.
298
+ !same(before.annotations?.title, after.annotations?.title) ? "annotations.title" : "",
299
+ !same(before.icons, after.icons) ? "icons" : "",
300
+ !same(before.execution, after.execution) ? `how it may be run (${describeExecution(before.execution)} \u2192 ${describeExecution(after.execution)})` : "",
301
+ !same(before.meta, after.meta) ? "_meta" : ""
302
+ ].filter(Boolean);
303
+ if (moved.length > 0 || changes.length === 0) {
269
304
  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 }));
270
305
  }
271
306
  return changes;
@@ -481,15 +516,18 @@ function compareServer(name, before, after) {
481
516
  }
482
517
  return changes;
483
518
  }
519
+ function subjectNamed(lock, name) {
520
+ return Object.hasOwn(lock.subjects, name) ? lock.subjects[name] : void 0;
521
+ }
484
522
  function detectRenames(before, after, removed, added) {
485
523
  const changes = [];
486
524
  const renamed = /* @__PURE__ */ new Set();
487
525
  const availableAdds = [...added];
488
526
  for (const oldName of removed) {
489
- const oldEntry = before.subjects[oldName];
527
+ const oldEntry = subjectNamed(before, oldName);
490
528
  if (!oldEntry) continue;
491
529
  const match = availableAdds.find((newName) => {
492
- const candidate = after.subjects[newName];
530
+ const candidate = subjectNamed(after, newName);
493
531
  return candidate !== void 0 && candidate.digest === oldEntry.digest && same(candidate.transport, oldEntry.transport);
494
532
  });
495
533
  if (!match) continue;
@@ -497,6 +535,8 @@ function detectRenames(before, after, removed, added) {
497
535
  renamed.add(oldName);
498
536
  renamed.add(match);
499
537
  changes.push(change("server.renamed", match, `renamed from "${oldName}"; capabilities are unchanged`, { before: oldName, after: match }));
538
+ const newEntry = subjectNamed(after, match);
539
+ if (newEntry) changes.push(...compareProvenance(match, oldEntry, newEntry));
500
540
  }
501
541
  return { changes, renamed };
502
542
  }
@@ -509,17 +549,17 @@ function diffLockfiles(before, after) {
509
549
  const changes = [...renameChanges];
510
550
  for (const name of added) {
511
551
  if (renamed.has(name)) continue;
512
- const entry = after.subjects[name];
552
+ const entry = subjectNamed(after, name);
513
553
  const toolCount = entry?.tools?.length ?? 0;
514
554
  changes.push(change("server.added", name, `new server with ${toolCount} tool${toolCount === 1 ? "" : "s"}`, { after: entry }));
515
555
  }
516
556
  for (const name of removed) {
517
557
  if (renamed.has(name)) continue;
518
- changes.push(change("server.removed", name, "server is no longer configured", { before: before.subjects[name] }));
558
+ changes.push(change("server.removed", name, "server is no longer configured", { before: subjectNamed(before, name) }));
519
559
  }
520
560
  for (const name of afterNames) {
521
- const a = before.subjects[name];
522
- const b = after.subjects[name];
561
+ const a = subjectNamed(before, name);
562
+ const b = subjectNamed(after, name);
523
563
  if (!a || !b) continue;
524
564
  changes.push(...compareServer(name, a, b));
525
565
  }
@@ -536,4 +576,4 @@ export {
536
576
  surfaceCapabilities,
537
577
  diffLockfiles
538
578
  };
539
- //# sourceMappingURL=chunk-CXDPJPL4.js.map
579
+ //# sourceMappingURL=chunk-5EJ474K3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/risk/untrusted.ts","../src/risk/capability.ts","../src/diff/index.ts"],"sourcesContent":["/**\n * Coercion for values that arrived from somewhere else.\n *\n * Everything in `risk/` reads a declaration a server sent, or a reading a collector posted. The\n * types say `{ name?: string }[]`, and a type is a claim about a value this code never checked:\n * `tools` is whatever was in the JSON, so it can be absent, a string, or an array with a `null`\n * in it. `tool.name` on that `null` throws a TypeError.\n *\n * In the CLI that aborts one audit, which is survivable. In the control plane the same call sits\n * inside ingest, where one malformed element in one tool of one server would fail the whole\n * request -- every other server in that reading included. A classifier is a security control, and\n * a security control that can be switched off by sending it a `null` is one an attacker turns off\n * rather than evades.\n *\n * So the guard belongs here, at the point the value is first believed, rather than at each of the\n * places that go on to read it.\n */\n\n/** The members of `value` that are objects, or an empty list if it is not a list at all. */\nexport function objectsIn(value: unknown): Array<Record<string, unknown>> {\n if (!Array.isArray(value)) return [];\n return value.filter((member): member is Record<string, unknown> => typeof member === \"object\" && member !== null);\n}\n\n/** `value` if it is a non-null object, otherwise an empty one, so a property read is always safe. */\nexport function objectOr(value: unknown): Record<string, unknown> {\n return typeof value === \"object\" && value !== null ? (value as Record<string, unknown>) : {};\n}\n\n/** `value` if it is a string, otherwise undefined: a `name` that is a number is not a name. */\nexport function stringOr(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n}\n","/**\n * What a server could do to you, derived from what it declares.\n *\n * This answers one question and refuses another. It answers *what could this tool do if the\n * model decides to use it*, from the tool's name, its argument names and its schema shape. It\n * does not answer *is this tool malicious*, which is a judgement, needs a corpus, and would make\n * a verdict depend on something other than the bytes on the wire.\n *\n * The distinction matters because it is the same one the severity table already makes: rank by\n * shape, never by intent. A tool named `run_command` taking a `command` argument is arbitrary\n * execution whatever its description claims, and that is a fact about the declaration rather\n * than an opinion about the author.\n *\n * Nothing here is stored in the lockfile. Capabilities are derived from the schemas that *are*\n * stored, so sharpening a pattern re-reads existing locks instead of showing every user a wave\n * of drift that no server caused.\n */\n\n/** Ordered worst-first; the order is the comparison. */\nimport { alternatives, asObject, beginWalk, effectiveSchema, entriesOf, MAX_FACTS, MAX_VISIT_DEPTH } from \"../lock/jsonschema\";\nimport type { JsonValue } from \"../lock/types\";\nimport { objectOr, objectsIn, stringOr } from \"./untrusted\";\n\nexport const CAPABILITY_SEVERITIES = [\"critical\", \"high\", \"medium\", \"low\"] as const;\nexport type CapabilitySeverity = (typeof CAPABILITY_SEVERITIES)[number];\n\nexport const CAPABILITY_KINDS = [\n \"process-exec\",\n \"code-eval\",\n \"credential-access\",\n \"file-write\",\n \"network-egress\",\n \"database\",\n \"privilege\",\n \"agent-control\",\n \"env-access\",\n \"file-read\",\n] as const;\nexport type CapabilityKind = (typeof CAPABILITY_KINDS)[number];\n\nexport interface Capability {\n kind: CapabilityKind;\n severity: CapabilitySeverity;\n /** Where it was seen: `name`, or `arg:<argument>`. Shown so a finding can be checked. */\n evidence: string;\n}\n\ninterface Rule {\n kind: CapabilityKind;\n severity: CapabilitySeverity;\n /** Matched against the tool name, with separators normalised to `_`. */\n name?: RegExp;\n /** Matched against each top-level argument name, normalised the same way. */\n arg?: RegExp;\n}\n\n/*\n * Deliberately narrow. A pattern that fires on `get_user` because it contains \"user\" teaches\n * people to ignore the output, and an ignored signal is worse than none: it spends the attention\n * the real findings need.\n */\nconst RULES: Rule[] = [\n { kind: \"process-exec\", severity: \"critical\", name: /(^|_)(exec|execute|spawn|shell|bash|sh|cmd|command|run_command|terminal|subprocess)(_|$)/, arg: /(^|_)(command|cmd|argv|shell|exec|script)(_|$)/ },\n // `source` is deliberately absent: in `copy_file(source, destination)` it is a path, and\n // labelling a file copy as arbitrary code execution at CRITICAL is the false positive that\n // teaches people to stop reading the line. `code` has to be the whole argument name for the\n // same reason -- a crawl of 468 published tools flagged `location_code` as arbitrary code\n // execution, and `country_code`, `status_code` and `zip_code` are all waiting behind it.\n { kind: \"code-eval\", severity: \"critical\", name: /(^|_)(eval|evaluate|run_code|exec_code|interpret|compile)(_|$)/, arg: /^code$|(^|_)(source_code|code_to_run|js_code|python_code|expression|program|snippet)(_|$)/ },\n { kind: \"credential-access\", severity: \"critical\", name: /(^|_)(secret|secrets|credential|credentials|token|keychain|vault|password)(_|$)/, arg: /(^|_)(secret|credential|password|private_key|api_key|access_token)(_|$)/ },\n { kind: \"network-egress\", severity: \"high\", name: /(^|_)(fetch|request|http|curl|download|upload|post|webhook|navigate|browse|send)(_|$)/, arg: /(^|_)(url|uri|endpoint|host|hostname|webhook|callback)(_|$)/ },\n // Narrowed to things that are actually SQL-shaped. `query`, `select` and `update` on their\n // own matched `simulate-research-query`, `browser_select_option` and `trigger-resource-update`,\n // none of which is a database.\n { kind: \"database\", severity: \"high\", name: /(^|_)(sql|execute_sql|run_sql|query_db|db_query|migrate)(_|$)/, arg: /(^|_)(sql|statement|dsn|connection_string)(_|$)/ },\n { kind: \"privilege\", severity: \"high\", name: /(^|_)(sudo|root|admin|grant|revoke|permission|permissions|acl|policy)(_|$)/, arg: /(^|_)(role|scope|scopes|permission|permissions|privilege)(_|$)/ },\n { kind: \"agent-control\", severity: \"high\", name: /(^|_)(prompt|system_prompt|instruction|instructions|memory|context|persona)(_|$)/, arg: /(^|_)(system_prompt|instruction|instructions|persona)(_|$)/ },\n { kind: \"env-access\", severity: \"medium\", name: /(^|_)(env|environment|getenv|setenv|config|settings)(_|$)/, arg: /(^|_)(env|environment|env_var)(_|$)/ },\n // `read`, `open` and `load` are not here; see `fileRead` below.\n { kind: \"file-read\", severity: \"low\", name: /(^|_)(read_file|cat|list_directory|ls|glob|search_files)(_|$)/, arg: /(^|_)(path|file|filename|filepath|directory|dir)(_|$)/ },\n];\n\n/*\n * Writing files, which needs more than a verb.\n *\n * It was one rule like the others: any of a dozen verbs in the name, or an argument called\n * `content` or `data`. So the official memory server -- `delete_entities`, `delete_relations`,\n * and `add_observations` with a `contents` field -- was labelled as writing files at HIGH, and an\n * organization's overview said two of its three servers could write files when one could. Found\n * by using the product. A verb like `delete` or `move` says something changes; whether it is a\n * file depends on what is being deleted or moved.\n *\n * So, in order:\n * - verbs that only mean one thing (`write`, `unlink`, `chmod`, `mkdir`...) count on their own;\n * - other changing verbs count when the name says what they act on is a file, directory or path,\n * or the tool takes a path;\n * - an argument naming where something is written (`destination`) counts on its own, and one\n * carrying what is written (`content`, `data`) counts only beside a path.\n */\nconst FILE_ONLY_VERBS = /(^|_)(write|create_file|put_file|unlink|chmod|chown|mkdir|rmdir|truncate)(_|$)/;\nconst CHANGING_VERBS = /(^|_)(create|save|delete|remove|rename|move|copy|edit|append|put|overwrite|replace|patch)(_|$)/;\nconst FILE_NOUNS = /(^|_)(file|files|filename|dir|dirs|directory|directories|folder|folders|path|paths)(_|$)/;\nconst PATH_ARGS = /^(path|paths|file|files|filename|filepath|file_path|directory|dir|folder|source_path)$|(^|_)(path|filepath|filename)$/;\nconst DESTINATION_ARGS = /(^|_)(destination|dest|dest_path|target_path|output_path|out_path)(_|$)/;\nconst CONTENT_ARGS = /(^|_)(contents|content|data|text|body)$/;\n\nfunction fileWrite(name: string, args: ReadonlyArray<readonly [string, string]>): string | undefined {\n if (FILE_ONLY_VERBS.test(name)) return \"name\";\n const path = args.find(([, normalized]) => PATH_ARGS.test(normalized));\n if (CHANGING_VERBS.test(name) && (FILE_NOUNS.test(name) || path)) return \"name\";\n const destination = args.find(([, normalized]) => DESTINATION_ARGS.test(normalized));\n if (destination) return `arg:${destination[0]}`;\n const content = args.find(([, normalized]) => CONTENT_ARGS.test(normalized));\n if (content && path) return `arg:${content[0]}`;\n return undefined;\n}\n\n/*\n * Reading files, by the same reasoning: `read_graph` and `open_nodes` read the memory server's\n * own graph, and were labelled as reading files because of the verb alone. A reading verb counts\n * when the name says what it reads is a file, directory or path; a tool taking a path is caught\n * by the rule's argument pattern whatever it is called.\n */\nconst READING_VERBS = /(^|_)(read|open|load)(_|$)/;\n\nfunction fileRead(name: string): boolean {\n return READING_VERBS.test(name) && FILE_NOUNS.test(name);\n}\n\n/*\n * Cyrillic and Greek letters that are drawn like Latin ones. `run_comm\\u0430nd` reads as\n * `run_command` to a person and matched nothing at all, so a single substituted character\n * bought a tool complete invisibility to a classifier whose whole job is reading names.\n * Folding them is the difference between a check and a formality.\n */\nconst CONFUSABLES: Record<string, string> = {\n \"\\u0430\": \"a\", \"\\u0435\": \"e\", \"\\u043E\": \"o\", \"\\u0441\": \"c\", \"\\u0440\": \"p\", \"\\u0445\": \"x\",\n \"\\u0443\": \"y\", \"\\u0456\": \"i\", \"\\u0458\": \"j\", \"\\u04BB\": \"h\", \"\\u0501\": \"d\", \"\\u051B\": \"q\",\n \"\\u03BF\": \"o\", \"\\u03B1\": \"a\", \"\\u03B5\": \"e\", \"\\u03BD\": \"v\", \"\\u03C1\": \"p\", \"\\u03C5\": \"u\",\n \"\\u0131\": \"i\", \"\\u1E9E\": \"s\",\n};\n\n/** Built from the map above, so the pattern and the replacements cannot drift apart. */\nconst CONFUSABLE_PATTERN = new RegExp(`[${Object.keys(CONFUSABLES).join(\"\")}]`, \"g\");\n\n/** `browser.take-screenshot` and `browser_take_screenshot` are the same shape. */\nfunction normalize(identifier: string): string {\n return identifier\n .toLowerCase()\n .replace(CONFUSABLE_PATTERN, (character) => CONFUSABLES[character] ?? character)\n .replace(/[-.\\s/]+/g, \"_\");\n}\n\n/*\n * Nested properties count. `tool({ opts: { command } })` is the same capability as\n * `tool({ command })`, and only the top level was examined, so one wrapping object hid it.\n *\n * So does indirection. The walk read literal `properties` and `items`, and Pydantic, Zod and most\n * OpenAPI generators put a nested model behind `$defs` by default: a `command` inside one, behind\n * a root `$ref`, an `allOf` or a branch of an `anyOf` yielded no capability, and a policy denying\n * process execution passed a tool that takes a shell command. Found in a security review. The\n * walk now reads each node as the widening heuristic does, through `$ref` and `allOf`, and into\n * every branch, array and map of values.\n *\n * A schema is attacker-supplied and need not terminate, so the walk has the heuristic's depth cap,\n * and a ceiling on nodes and names read between them however many routes lead to them. Each name\n * is kept once, in the order first met, which is the order evidence is taken from.\n */\nconst MAX_ARGUMENT_READS = 10 * MAX_FACTS;\n\nfunction argumentNames(inputSchema: unknown): string[] {\n const root = inputSchema as JsonValue;\n const names = new Set<string>();\n let budget = MAX_ARGUMENT_READS;\n\n const walk = (node: JsonValue | undefined, depth: number): boolean => {\n if (budget <= 0) return false;\n budget -= 1;\n const object = effectiveSchema(node, root);\n if (!object) return true;\n const deeper = depth < MAX_VISIT_DEPTH;\n // False once the budget is spent, which ends the walk where it stands.\n const into = (child: JsonValue | undefined): boolean => (deeper && child !== null && typeof child === \"object\" ? walk(child, depth + 1) : budget > 0);\n\n const properties = asObject(object[\"properties\"]);\n if (properties) {\n for (const [name, child] of entriesOf(properties)) {\n if (--budget <= 0) return false;\n names.add(name);\n if (!into(child)) return false;\n }\n }\n for (const keyword of [\"items\", \"prefixItems\"]) {\n const value = object[keyword];\n if (Array.isArray(value)) {\n for (const child of value) if (!into(child)) return false;\n } else if (!into(value)) return false;\n }\n if (!into(object[\"additionalProperties\"])) return false;\n const patternProperties = asObject(object[\"patternProperties\"]);\n if (patternProperties) for (const [, child] of entriesOf(patternProperties)) if (!into(child)) return false;\n for (const branch of alternatives(object)) if (!into(branch.schema)) return false;\n return true;\n };\n\n beginWalk(root);\n walk(root, 0);\n return [...names];\n}\n\n/**\n * The capabilities one tool declares. Worst first, one entry per kind: a tool matching\n * `process-exec` by both its name and an argument is not twice as dangerous.\n */\nexport function toolCapabilities(tool: { name?: string; inputSchema?: unknown } | null | undefined): Capability[] {\n // The argument is whatever was in the JSON; see risk/untrusted.\n const subject = objectOr(tool);\n const name = normalize(stringOr(subject.name) ?? \"\");\n const args = argumentNames(subject.inputSchema).map((argument) => [argument, normalize(argument)] as const);\n const found = new Map<CapabilityKind, Capability>();\n\n for (const rule of RULES) {\n if (found.has(rule.kind)) continue;\n if (rule.name?.test(name)) {\n found.set(rule.kind, { kind: rule.kind, severity: rule.severity, evidence: \"name\" });\n continue;\n }\n const hit = rule.arg ? args.find(([, normalized]) => rule.arg?.test(normalized)) : undefined;\n if (hit) found.set(rule.kind, { kind: rule.kind, severity: rule.severity, evidence: `arg:${hit[0]}` });\n }\n if (!found.has(\"file-read\") && fileRead(name)) found.set(\"file-read\", { kind: \"file-read\", severity: \"low\", evidence: \"name\" });\n const writes = fileWrite(name, args);\n if (writes) found.set(\"file-write\", { kind: \"file-write\", severity: \"high\", evidence: writes });\n\n return [...found.values()].sort(\n (a, b) => CAPABILITY_SEVERITIES.indexOf(a.severity) - CAPABILITY_SEVERITIES.indexOf(b.severity) || a.kind.localeCompare(b.kind),\n );\n}\n\n/** Every capability a set of tools declares between them, with the tools that declare each. */\nexport function surfaceCapabilities(\n tools: ReadonlyArray<{ name?: string; inputSchema?: unknown }> | null | undefined,\n): Array<Capability & { tools: string[] }> {\n const byKind = new Map<CapabilityKind, Capability & { tools: string[] }>();\n for (const tool of objectsIn(tools)) {\n const label = stringOr(tool.name) ?? \"?\";\n for (const capability of toolCapabilities(tool)) {\n const existing = byKind.get(capability.kind);\n if (existing) existing.tools.push(label);\n else byKind.set(capability.kind, { ...capability, tools: [label] });\n }\n }\n return [...byKind.values()].sort(\n (a, b) => CAPABILITY_SEVERITIES.indexOf(a.severity) - CAPABILITY_SEVERITIES.indexOf(b.severity) || a.kind.localeCompare(b.kind),\n );\n}\n","/** Comparing a freshly captured lock against the committed one. */\nimport { stableKey } from \"../lock/canonical\";\nimport { isEscalation } from \"../lock/normalize\";\nimport type {\n LockedPrompt,\n LockedResource,\n LockedResourceTemplate,\n LockedMcpServer,\n LockedTool,\n Lockfile,\n} from \"../lock/types\";\nimport { toolCapabilities, type CapabilitySeverity } from \"../risk/capability\";\nimport { classifySchemaChange } from \"./schema\";\nimport type { Change, ChangeKind, Severity } from \"./types\";\nimport { SEVERITY, sortChanges } from \"./types\";\n\nfunction change(kind: ChangeKind, server: string, summary: string, extra?: Partial<Change>): Change {\n return { kind, severity: SEVERITY[kind], server, summary, ...extra };\n}\n\nfunction same(a: unknown, b: unknown): boolean {\n return stableKey(a ?? null) === stableKey(b ?? null);\n}\n\n/**\n * Members grouped by their key, every copy kept.\n *\n * A Map from key to member kept the last of two tools with the same name and dropped the first\n * without a word. A server that listed a poisoned `read_file` ahead of the approved one compared\n * clean: the approved copy was the one compared, and the poisoned one was never looked at. Which\n * copy a client uses is the client's business, so every copy is compared.\n */\nfunction groupBy<T>(members: T[] | undefined, key: (member: T) => string): Map<string, T[]> {\n const groups = new Map<string, T[]>();\n for (const member of members ?? []) {\n const k = key(member);\n const group = groups.get(k);\n if (group) group.push(member);\n else groups.set(k, [member]);\n }\n return groups;\n}\n\n/**\n * What a server declares, flattened so that an extension is one of the names.\n *\n * `capabilities` is a handful of top-level keys, and one of them, `extensions`, is a map of\n * reverse-DNS ids: that is the mechanism the specification uses to ship capability outside the\n * core. Comparing only the top level means a server that gains an extension still has\n * `extensions` before and after, so nothing reads as gained and the finding lands on the generic\n * \"declared capabilities changed\" with the detail left inside a JSON blob for a reviewer to go\n * and read. As more of what a server can do arrives as an extension, \"what did this one just\n * gain\" becomes an extension question, and it deserves an answer in words.\n *\n * The `extensions` key itself is not a name. Reporting both it and the id it contains would say\n * the same thing twice on the reading where a server declares its first extension.\n */\nfunction declaredNames(capabilities: LockedMcpServer[\"capabilities\"]): string[] {\n const names: string[] = [];\n for (const [key, value] of Object.entries(capabilities ?? {})) {\n if (key === \"extensions\" && value !== null && typeof value === \"object\" && !Array.isArray(value)) {\n for (const id of Object.keys(value)) names.push(`extensions/${id}`);\n continue;\n }\n names.push(key);\n }\n return names;\n}\n\n/** Describes the delta between two capability maps in the direction that matters. */\nfunction compareCapabilities(before: LockedMcpServer, after: LockedMcpServer, name: string): Change[] {\n if (same(before.capabilities, after.capabilities)) return [];\n const previous = declaredNames(before.capabilities);\n const next = declaredNames(after.capabilities);\n const gained = next.filter((key) => !previous.includes(key));\n const lost = previous.filter((key) => !next.includes(key));\n\n if (gained.length > 0 && lost.length === 0) {\n return [change(\"server.capabilities.widened\", name, `server now declares ${gained.join(\", \")}`, { before: before.capabilities, after: after.capabilities })];\n }\n if (lost.length > 0 && gained.length === 0) {\n return [change(\"server.capabilities.narrowed\", name, `server no longer declares ${lost.join(\", \")}`, { before: before.capabilities, after: after.capabilities })];\n }\n return [change(\"server.capabilities.changed\", name, \"declared capabilities changed\", { before: before.capabilities, after: after.capabilities })];\n}\n\n\n/*\n * What a tool can do, compared across a reading.\n *\n * The schema diff says a tool \"accepts input it did not before\", which is the same sentence\n * whether the new argument is `nickname` or `command`. The classifier already knows the\n * difference and says so at pin time; the diff did not ask, so the finding a reviewer approved\n * described arbitrary command execution in the words of an optional string.\n *\n * A tool that is new is compared against nothing, so everything it can do is gained. That is the\n * honest reading: a server that adds a tool taking `command` has gained command execution just as\n * surely as one that adds the argument to a tool already there.\n */\nconst CAPABILITY_SEVERITY: Record<CapabilitySeverity, Severity> = {\n critical: \"high\",\n high: \"high\",\n medium: \"medium\",\n low: \"low\",\n};\n\nfunction compareToolCapabilities(server: string, before: LockedTool[] | undefined, after: LockedTool[] | undefined): Change[] {\n const previous = groupBy(before, (tool) => tool.name);\n const changes: Change[] = [];\n\n for (const tool of after ?? []) {\n /*\n * Only tools that were already here. A tool that is new is reported once, by `tool.added`,\n * which names what it can do: raising a second finding for the same fact makes a reviewer\n * read the arrival of one tool twice.\n */\n const existing = previous.get(tool.name);\n if (!existing) continue;\n // Against every copy that was pinned under this name: what any of them could do was approved.\n const had = new Set(existing.flatMap((copy) => toolCapabilities(copy).map((capability) => capability.kind)));\n for (const capability of toolCapabilities(tool)) {\n if (had.has(capability.kind)) continue;\n changes.push(\n change(\"tool.capability.gained\", server, `can now ${capability.kind} (${capability.evidence})`, {\n member: tool.name,\n severity: CAPABILITY_SEVERITY[capability.severity],\n after: { kind: capability.kind, severity: capability.severity, evidence: capability.evidence },\n }),\n );\n }\n }\n return changes;\n}\n\nfunction compareTool(name: string, before: LockedTool, after: LockedTool): Change[] {\n if (before.digest === after.digest) return [];\n const changes: Change[] = [];\n const at = { member: before.name };\n\n if (!same(before.description, after.description)) {\n changes.push(\n change(\"tool.description.changed\", name, `description changed (${before.description?.length ?? 0} → ${after.description?.length ?? 0} characters)`, {\n ...at,\n before: before.description,\n after: after.description,\n }),\n );\n }\n\n const inputVerdict = classifySchemaChange(before.inputSchema, after.inputSchema);\n if (inputVerdict !== \"same\") {\n const kind = (`tool.input_schema.${inputVerdict}` satisfies ChangeKind) as ChangeKind;\n const wording = inputVerdict === \"widened\" ? \"accepts input it did not before\" : inputVerdict === \"narrowed\" ? \"accepts less input than before\" : \"input schema changed\";\n changes.push(change(kind, name, wording, { ...at, before: before.inputSchema, after: after.inputSchema }));\n }\n\n if (!same(before.outputSchema, after.outputSchema)) {\n changes.push(change(\"tool.output_schema.changed\", name, \"output schema changed\", { ...at, before: before.outputSchema, after: after.outputSchema }));\n }\n\n if (!same(before.behavior, after.behavior)) {\n const escalated = isEscalation(before.behavior, after.behavior);\n changes.push(\n change(escalated ? \"tool.behavior.escalated\" : \"tool.behavior.relaxed\", name, escalated ? describeEscalation(before, after) : \"declares fewer powers than before\", {\n ...at,\n before: before.behavior,\n after: after.behavior,\n }),\n );\n }\n\n if (!same(before.headerParams, after.headerParams)) {\n changes.push(\n change(\"tool.header_params.changed\", name, \"arguments mirrored into HTTP headers changed\", { ...at, before: before.headerParams ?? [], after: after.headerParams ?? [] }),\n );\n }\n\n /*\n * The digest covers more than the fields called out above -- title, icons, `_meta`, how it may\n * be run. Whichever of those moved is reported, beside any other finding. They used to be\n * reported only when nothing else had fired, so a tool whose title and description changed\n * together showed the description alone: the title a client shows in place of the name changed\n * and nobody was told, and accepting approved it unseen. Found by changing both at once.\n *\n * If none of them moved and nothing else fired, something in the remainder did, and silence\n * would be worse than a vague finding.\n */\n const moved = [\n !same(before.title, after.title) ? \"title\" : \"\",\n // A second title a client shows in place of the name, and the same finding for the same reason.\n !same(before.annotations?.title, after.annotations?.title) ? \"annotations.title\" : \"\",\n !same(before.icons, after.icons) ? \"icons\" : \"\",\n !same(before.execution, after.execution) ? `how it may be run (${describeExecution(before.execution)} → ${describeExecution(after.execution)})` : \"\",\n !same(before.meta, after.meta) ? \"_meta\" : \"\",\n ].filter(Boolean);\n if (moved.length > 0 || changes.length === 0) {\n 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 }));\n }\n return changes;\n}\n\nfunction describeExecution(execution: LockedTool[\"execution\"]): string {\n const support = execution?.[\"taskSupport\"];\n return typeof support === \"string\" ? `task support ${support}` : \"unstated\";\n}\n\nfunction describeEscalation(before: LockedTool, after: LockedTool): string {\n const gained: string[] = [];\n if (before.behavior.readOnly && !after.behavior.readOnly) gained.push(\"may now modify\");\n if (!before.behavior.destructive && after.behavior.destructive) gained.push(\"may now destroy\");\n if (before.behavior.idempotent && !after.behavior.idempotent) gained.push(\"repeat calls now compound\");\n if (!before.behavior.openWorld && after.behavior.openWorld) gained.push(\"may now reach external systems\");\n return gained.join(\"; \");\n}\n\ninterface MemberSpec<T> {\n key: (member: T) => string;\n label: (member: T) => string;\n added: ChangeKind;\n removed: ChangeKind;\n changed: ChangeKind;\n noun: string;\n /** Extra wording for a member that is new, where arriving is itself the finding. */\n arriving?: (member: T) => string;\n}\n\nfunction compareMembers<T extends { digest: string }>(\n name: string,\n before: T[] | undefined,\n after: T[] | undefined,\n spec: MemberSpec<T>,\n deep?: (key: string, a: T, b: T) => Change[],\n): Change[] {\n const changes: Change[] = [];\n const previous = groupBy(before, spec.key);\n const next = groupBy(after, spec.key);\n\n for (const [key, members] of next) {\n const existing = previous.get(key);\n if (!existing) {\n for (const member of members) {\n const extra = spec.arriving?.(member);\n changes.push(\n change(spec.added, name, `new ${spec.noun} ${spec.label(member)}${extra ? ` \\u00b7 ${extra}` : \"\"}`, { member: spec.label(member), after: member }),\n );\n }\n continue;\n }\n\n /*\n * Identical copies pair off first, so a server that reorders its list compares clean. What is\n * left on the new side is compared against what is left on the old one, or, where a copy was\n * added beside the approved one, against the approved one: a second `read_file` is described\n * by how it differs from the first, which is the finding a reviewer needs.\n */\n const unpairedBefore = [...existing];\n const unpairedAfter: T[] = [];\n for (const member of members) {\n const twin = unpairedBefore.findIndex((candidate) => candidate.digest === member.digest);\n if (twin === -1) unpairedAfter.push(member);\n else unpairedBefore.splice(twin, 1);\n }\n for (const [index, member] of unpairedAfter.entries()) {\n const counterpart = unpairedBefore[index] ?? existing[0]!;\n if (counterpart.digest === member.digest) {\n changes.push(\n change(spec.changed, name, `${spec.noun} ${spec.label(member)} is now declared ${members.length} times`, { member: spec.label(member), before: existing, after: members }),\n );\n continue;\n }\n changes.push(\n ...(deep\n ? deep(key, counterpart, member)\n : [change(spec.changed, name, `${spec.noun} ${spec.label(member)} changed`, { member: spec.label(member), before: counterpart, after: member })]),\n );\n }\n for (const member of unpairedBefore.slice(unpairedAfter.length)) {\n changes.push(change(spec.removed, name, `one of the ${spec.noun}s declared as ${spec.label(member)} is gone`, { member: spec.label(member), before: member }));\n }\n }\n for (const [key, members] of previous) {\n if (next.has(key)) continue;\n for (const member of members) changes.push(change(spec.removed, name, `${spec.noun} ${spec.label(member)} is gone`, { member: spec.label(member), before: member }));\n }\n return changes;\n}\n\n/**\n * Whether the code behind the server is the code that was pinned.\n *\n * Absence on either side says nothing. A lock written before provenance existed, or a run that\n * could not reach a registry, has none, and reporting that would turn every upgrade of this tool\n * and every offline run into drift against servers nobody touched. Neither does a change of\n * package name: that only happens when the command or its arguments changed, which\n * `server.transport.changed` already reports, and saying it twice is how a reviewer learns to\n * skim.\n */\n/** What differs between two lists of a release's files, said briefly, or nothing when they match. */\nfunction filesMoved(was: Record<string, string> | undefined, now: Record<string, string> | undefined): string | undefined {\n if (was === undefined || now === undefined) return undefined;\n const added = Object.keys(now).filter((file) => !Object.hasOwn(was, file));\n const removed = Object.keys(was).filter((file) => !Object.hasOwn(now, file));\n const changed = Object.keys(now).filter((file) => Object.hasOwn(was, file) && was[file] !== now[file]);\n if (added.length + removed.length + changed.length === 0) return undefined;\n const list = (files: string[]) => `${files.slice(0, 3).join(\", \")}${files.length > 3 ? ` +${files.length - 3}` : \"\"}`;\n return [\n added.length > 0 ? `added ${list(added)}` : \"\",\n removed.length > 0 ? `removed ${list(removed)}` : \"\",\n changed.length > 0 ? `different contents for ${list(changed)}` : \"\",\n ]\n .filter(Boolean)\n .join(\"; \");\n}\n\nfunction compareProvenance(name: string, before: LockedMcpServer, after: LockedMcpServer): Change[] {\n const was = before.provenance;\n const now = after.provenance;\n if (!was || !now) return [];\n if (was.ecosystem !== now.ecosystem || was.name !== now.name) return [];\n\n const surfaceHeld = before.digest === after.digest;\n\n /*\n * Said out loud when the surface held still, because that is the case nothing else in the\n * report covers. A release that changed its tools is described by the tool changes; one that\n * changed only its code is described by this line and nothing else.\n */\n const unexplained = surfaceHeld ? \", and the declared surface did not change: nothing else in this report describes what the new code does\" : \"\";\n const integrityMoved = was.integrity !== undefined && now.integrity !== undefined && was.integrity !== now.integrity;\n\n if (was.version !== undefined && was.version === now.version) {\n if (!integrityMoved) {\n /*\n * The pinned file is one of a release's files, and an installer picks among all of them.\n * A wheel added to the release, or the pinned file taken away, changes what runs without\n * moving `integrity`; when both sides list the release's files, that is compared too.\n */\n const files = filesMoved(was.files, now.files);\n if (files) {\n return [change(\"server.artifact.changed\", name, `the files published for ${was.name}@${was.version} are not the ones that were pinned (${files})${unexplained}`, { before: was, after: now })];\n }\n if (was.integrity !== undefined && now.integrity === undefined) {\n return [change(\"server.artifact.changed\", name, `the file pinned for ${was.name}@${was.version} is no longer published, so something else is installed in its place${unexplained}`, { before: was, after: now })];\n }\n return [];\n }\n /*\n * Substitution is claimed only where the registry guarantees one artifact per version. npm\n * refuses to republish a version, so different bytes under the same one means something\n * between here and the registry served them. PyPI lets a maintainer add files to a release\n * after the fact, so the same version with a different recorded file has an ordinary\n * explanation, and it is reported as the milder kind.\n */\n if (was.ecosystem === \"npm\") {\n return [\n change(\n \"server.artifact.substituted\",\n name,\n `${was.name}@${was.version} now has different contents than when it was pinned: the same version, different bytes`,\n { before: was, after: now },\n ),\n ];\n }\n return [change(\"server.artifact.changed\", name, `the files published for ${was.name}@${was.version} are not the ones that were pinned${unexplained}`, { before: was, after: now })];\n }\n\n if (was.version !== now.version) {\n const moved = `the package behind this server moved from ${was.version ?? \"an unknown version\"} to ${now.version ?? \"an unknown version\"}`;\n return [change(\"server.artifact.changed\", name, `${moved}${unexplained}`, { before: was, after: now })];\n }\n\n /*\n * No version on either side: a file, or an image, whose tag is a pointer rather than a release.\n * A moved tag and a rebuilt binary are both ordinary, so both are the medium kind.\n */\n if (!integrityMoved) return [];\n const what =\n was.ecosystem === \"oci\"\n ? `the image ${was.name}:${was.requested ?? \"latest\"} now resolves to a different digest`\n : \"the file this server runs from has different contents than when it was pinned\";\n return [change(\"server.artifact.changed\", name, `${what}${unexplained}`, { before: was, after: now })];\n}\n\n/**\n * What the server digest covers, with each member list taken as a set.\n *\n * Members are stored sorted by name, so copies that share a name keep the order the server sent\n * them in, and a server that swaps two of them moves its digest without changing anything. The\n * member comparison already reads that as clean; this is what lets the fallback below agree.\n *\n * Everything but the fields the digest leaves out is taken as it is, rather than listed, so a\n * field the format gains later is covered here on the day it is added.\n */\nfunction orderless(entry: LockedMcpServer): string {\n const { kind: _kind, source: _source, digest: _digest, provenance: _provenance, coverage: _coverage, tools, resources, resourceTemplates, prompts, ...rest } = entry;\n const digests = (members: Array<{ digest: string }> | undefined) => (members ?? []).map((member) => member.digest).sort();\n return stableKey({\n ...rest,\n tools: digests(tools),\n resources: digests(resources),\n resourceTemplates: digests(resourceTemplates),\n prompts: digests(prompts),\n });\n}\n\nfunction compareServer(name: string, before: LockedMcpServer, after: LockedMcpServer): Change[] {\n /*\n * Provenance first, and outside the short-circuit: the attack it exists for is new code behind\n * an unchanged surface, which is exactly the case where the digests match.\n */\n const provenance = compareProvenance(name, before, after);\n if (before.digest === after.digest) return provenance;\n const changes: Change[] = [...provenance];\n\n if (!same(before.transport, after.transport)) {\n changes.push(change(\"server.transport.changed\", name, \"the server is reached differently than when it was pinned\", { before: before.transport, after: after.transport }));\n }\n if (!same(before.serverInfo, after.serverInfo)) {\n const from = before.serverInfo?.version ?? \"unknown\";\n const to = after.serverInfo?.version ?? \"unknown\";\n changes.push(change(\"server.identity.changed\", name, `server identity changed (version ${from} → ${to})`, { before: before.serverInfo, after: after.serverInfo }));\n }\n if (!same(before.protocol, after.protocol)) {\n changes.push(\n change(\"server.protocol.changed\", name, `protocol changed (${before.protocol.era}/${before.protocol.version} → ${after.protocol.era}/${after.protocol.version})`, {\n before: before.protocol,\n after: after.protocol,\n }),\n );\n }\n if (!same(before.instructions, after.instructions)) {\n changes.push(\n change(\"server.instructions.changed\", name, \"server instructions changed: this text goes into the model's system prompt\", {\n before: before.instructions,\n after: after.instructions,\n }),\n );\n }\n changes.push(...compareCapabilities(before, after, name));\n\n changes.push(\n ...compareMembers<LockedTool>(name, before.tools, after.tools, {\n key: (t) => t.name,\n label: (t) => t.name,\n added: \"tool.added\",\n removed: \"tool.removed\",\n changed: \"tool.changed\",\n noun: \"tool\",\n arriving: (t) => {\n const can = toolCapabilities(t);\n return can.length > 0 ? `can ${can.map((capability) => capability.kind).join(\", \")}` : \"\";\n },\n }, (_key, a, b) =>\n compareTool(name, a, b),\n ),\n );\n changes.push(...compareToolCapabilities(name, before.tools, after.tools));\n changes.push(\n ...compareMembers<LockedResource>(name, before.resources, after.resources, {\n key: (r) => r.uri,\n label: (r) => `${r.name} (${r.uri})`,\n added: \"resource.added\",\n removed: \"resource.removed\",\n changed: \"resource.changed\",\n noun: \"resource\",\n }),\n );\n changes.push(\n ...compareMembers<LockedResourceTemplate>(name, before.resourceTemplates, after.resourceTemplates, {\n key: (t) => t.uriTemplate,\n // The template itself is the capability -- widening it from file:///project/{path} to\n // file:///{path} is the whole finding -- so it belongs in the label, not just the body.\n label: (t) => `${t.name} (${t.uriTemplate})`,\n added: \"resource_template.added\",\n removed: \"resource_template.removed\",\n changed: \"resource_template.changed\",\n noun: \"resource template\",\n }),\n );\n changes.push(\n ...compareMembers<LockedPrompt>(name, before.prompts, after.prompts, {\n key: (p) => p.name,\n label: (p) => p.name,\n added: \"prompt.added\",\n removed: \"prompt.removed\",\n changed: \"prompt.changed\",\n noun: \"prompt\",\n }),\n );\n\n /*\n * The digest moved and nothing above says why. Every field the digest covers is compared above,\n * so this should not happen; when it does, a field was missed, and the honest report is a vague\n * finding rather than a clean one. A false clean is the one failure this engine exists to avoid.\n */\n if (changes.length === 0 && orderless(before) !== orderless(after)) {\n changes.push(\n change(\"server.capabilities.changed\", name, \"the server's pinned definition changed in a way no other finding describes; compare the lock entries\", {\n before: before.digest,\n after: after.digest,\n }),\n );\n }\n\n return changes;\n}\n\n/*\n * A server by name, from the lock's own entries only. `subjects[name]` on a plain object answers\n * for names nobody configured: `constructor`, `toString` and `hasOwnProperty` are on every\n * object's prototype, so a new server called `constructor` was compared against a function, and\n * the comparison threw. Found in a security review.\n */\nfunction subjectNamed(lock: Lockfile, name: string): LockedMcpServer | undefined {\n return Object.hasOwn(lock.subjects, name) ? lock.subjects[name] : undefined;\n}\n\n/**\n * A server renamed in config would naively read as a removal plus an addition: two alarming\n * findings for a cosmetic edit. Collapsing requires an identical transport *and* an identical\n * digest, so a rename that also changed capabilities stays a remove and an add -- which is what\n * it is, and hiding a capability change inside a cosmetic one is the failure mode worth avoiding.\n *\n * The package behind a server is outside its digest (see `compareProvenance`), so it is compared\n * for a renamed pair too. It was not: renaming `fs` to `filesystem` in the same commit that put\n * new bytes behind fs-server@1.0.0 reported a low-severity rename and nothing else, when the same\n * bytes under the old name were a high substitution. Found in a security review.\n */\nfunction detectRenames(before: Lockfile, after: Lockfile, removed: string[], added: string[]): { changes: Change[]; renamed: Set<string> } {\n const changes: Change[] = [];\n const renamed = new Set<string>();\n const availableAdds = [...added];\n\n for (const oldName of removed) {\n const oldEntry = subjectNamed(before, oldName);\n if (!oldEntry) continue;\n const match = availableAdds.find((newName) => {\n const candidate = subjectNamed(after, newName);\n return candidate !== undefined && candidate.digest === oldEntry.digest && same(candidate.transport, oldEntry.transport);\n });\n if (!match) continue;\n\n availableAdds.splice(availableAdds.indexOf(match), 1);\n renamed.add(oldName);\n renamed.add(match);\n changes.push(change(\"server.renamed\", match, `renamed from \"${oldName}\"; capabilities are unchanged`, { before: oldName, after: match }));\n const newEntry = subjectNamed(after, match);\n if (newEntry) changes.push(...compareProvenance(match, oldEntry, newEntry));\n }\n return { changes, renamed };\n}\n\nexport function diffLockfiles(before: Lockfile, after: Lockfile): Change[] {\n const beforeNames = Object.keys(before.subjects);\n const afterNames = Object.keys(after.subjects);\n const removed = beforeNames.filter((name) => !afterNames.includes(name));\n const added = afterNames.filter((name) => !beforeNames.includes(name));\n\n const { changes: renameChanges, renamed } = detectRenames(before, after, removed, added);\n const changes: Change[] = [...renameChanges];\n\n for (const name of added) {\n if (renamed.has(name)) continue;\n const entry = subjectNamed(after, name);\n const toolCount = entry?.tools?.length ?? 0;\n changes.push(change(\"server.added\", name, `new server with ${toolCount} tool${toolCount === 1 ? \"\" : \"s\"}`, { after: entry }));\n }\n for (const name of removed) {\n if (renamed.has(name)) continue;\n changes.push(change(\"server.removed\", name, \"server is no longer configured\", { before: subjectNamed(before, name) }));\n }\n for (const name of afterNames) {\n const a = subjectNamed(before, name);\n const b = subjectNamed(after, name);\n if (!a || !b) continue;\n changes.push(...compareServer(name, a, b));\n }\n\n return sortChanges(changes);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmBO,SAAS,UAAU,OAAgD;AACxE,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACnC,SAAO,MAAM,OAAO,CAAC,WAA8C,OAAO,WAAW,YAAY,WAAW,IAAI;AAClH;AAGO,SAAS,SAAS,OAAyC;AAChE,SAAO,OAAO,UAAU,YAAY,UAAU,OAAQ,QAAoC,CAAC;AAC7F;AAGO,SAAS,SAAS,OAAoC;AAC3D,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;;;ACTO,IAAM,wBAAwB,CAAC,YAAY,QAAQ,UAAU,KAAK;AAGlE,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAwBA,IAAM,QAAgB;AAAA,EACpB,EAAE,M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AM,IAAI,aAAa,OAAO,IAAI;AAClC,QAAI,CAAC,KAAK,CAAC,EAAG;AACd,YAAQ,KAAK,GAAG,cAAc,MAAM,GAAG,CAAC,CAAC;AAAA,EAC3C;AAEA,SAAO,YAAY,OAAO;AAC5B;","names":[]}
@@ -94,7 +94,8 @@ function serversThatShippedNothing(changes) {
94
94
  const moved = /* @__PURE__ */ new Set();
95
95
  const versioned = /* @__PURE__ */ new Set();
96
96
  for (const change of changes) {
97
- moved.add(change.server);
97
+ const uncaptured = change.kind === "server.removed" || change.kind === "server.added" && change.after === void 0;
98
+ if (!uncaptured) moved.add(change.server);
98
99
  if (change.kind === "server.identity.changed") versioned.add(change.server);
99
100
  }
100
101
  return [...moved].filter((server) => !versioned.has(server)).sort();
@@ -108,4 +109,4 @@ export {
108
109
  sortChanges,
109
110
  serversThatShippedNothing
110
111
  };
111
- //# sourceMappingURL=chunk-JCJXSMBS.js.map
112
+ //# sourceMappingURL=chunk-6ERBWXWP.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/changes.ts"],"sourcesContent":["/**\n * The change taxonomy: the one vocabulary the collector, the API, the dashboard and every\n * customer's SARIF consumer share.\n *\n * It lives here rather than in the CLI because it is a contract across process boundaries. A\n * collector on an old version reports a kind the server has to understand, and a renamed kind\n * breaks a SARIF rule id somebody has already suppressed. Renaming one is a major version.\n */\n\nexport const CHANGE_KINDS = [\n \"server.added\",\n \"server.removed\",\n \"server.renamed\",\n \"server.transport.changed\",\n \"server.identity.changed\",\n /*\n * Two kinds rather than one, because they call for opposite defaults.\n *\n * A version moving is the ordinary life of a dependency: most of them are patch releases that\n * nobody needs to read, and a policy blocking on them would fail every build in the week a\n * popular package ships. A version *not* moving while its contents do has no innocent\n * explanation -- a registry or mirror serving different bytes under a published version, or an\n * image tag repointed -- and that one should stop a build on the default policy.\n */\n \"server.artifact.changed\",\n \"server.artifact.substituted\",\n \"server.protocol.changed\",\n \"server.instructions.changed\",\n \"server.capabilities.widened\",\n \"server.capabilities.narrowed\",\n \"server.capabilities.changed\",\n \"tool.added\",\n \"tool.removed\",\n \"tool.description.changed\",\n \"tool.input_schema.widened\",\n \"tool.input_schema.narrowed\",\n \"tool.input_schema.changed\",\n \"tool.output_schema.changed\",\n \"tool.behavior.escalated\",\n \"tool.behavior.relaxed\",\n \"tool.header_params.changed\",\n \"tool.capability.gained\",\n \"tool.changed\",\n \"resource.added\",\n \"resource.removed\",\n \"resource.changed\",\n \"resource_template.added\",\n \"resource_template.removed\",\n \"resource_template.changed\",\n \"prompt.added\",\n \"prompt.removed\",\n \"prompt.changed\",\n] as const;\n\nexport type ChangeKind = (typeof CHANGE_KINDS)[number];\n\n/**\n * Ranking only. Every kind is drift; severity decides what a reviewer reads first, what SARIF\n * level an AppSec tool shows, and which changes a policy can be set to block. \"high\" is reserved\n * for shapes an attacker would use -- text that reaches the model, a widened input, a new power --\n * so that it keeps meaning something.\n */\nexport const SEVERITIES = [\"high\", \"medium\", \"low\"] as const;\nexport type Severity = (typeof SEVERITIES)[number];\n\nexport const SEVERITY: Record<ChangeKind, Severity> = {\n \"server.added\": \"medium\",\n \"server.removed\": \"low\",\n \"server.renamed\": \"low\",\n \"server.transport.changed\": \"high\",\n \"server.identity.changed\": \"medium\",\n \"server.artifact.changed\": \"medium\",\n \"server.artifact.substituted\": \"high\",\n \"server.protocol.changed\": \"medium\",\n \"server.instructions.changed\": \"high\",\n \"server.capabilities.widened\": \"medium\",\n \"server.capabilities.narrowed\": \"low\",\n \"server.capabilities.changed\": \"medium\",\n \"tool.added\": \"high\",\n \"tool.removed\": \"low\",\n \"tool.description.changed\": \"high\",\n \"tool.input_schema.widened\": \"high\",\n \"tool.input_schema.narrowed\": \"low\",\n \"tool.input_schema.changed\": \"medium\",\n \"tool.output_schema.changed\": \"medium\",\n \"tool.behavior.escalated\": \"high\",\n \"tool.behavior.relaxed\": \"low\",\n \"tool.header_params.changed\": \"high\",\n /*\n * Severity is set per change rather than read from here: what a tool gained decides it. A\n * `command` argument is not the same finding as a `url` one, and flattening both to one number\n * is how \"accepts input it did not before\" came to describe arbitrary command execution.\n */\n \"tool.capability.gained\": \"high\",\n \"tool.changed\": \"medium\",\n \"resource.added\": \"medium\",\n \"resource.removed\": \"low\",\n \"resource.changed\": \"medium\",\n \"resource_template.added\": \"high\",\n \"resource_template.removed\": \"low\",\n \"resource_template.changed\": \"high\",\n \"prompt.added\": \"medium\",\n \"prompt.removed\": \"low\",\n \"prompt.changed\": \"medium\",\n};\n\nexport const SEVERITY_RANK: Record<Severity, number> = { high: 0, medium: 1, low: 2 };\n\n/** One change, as the collector reports it and as the dashboard renders it. */\nexport interface Change {\n kind: ChangeKind;\n severity: Severity;\n /** Name of the server in the lock. */\n server: string;\n /** Tool, resource, template or prompt name, where the change is scoped to one. */\n member?: string;\n /** One line, written for a reviewer who has not read the lockfile. */\n summary: string;\n before?: unknown;\n after?: unknown;\n}\n\nexport function sortChanges(changes: Change[]): Change[] {\n return [...changes].sort(\n (a, b) =>\n SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] ||\n a.server.localeCompare(b.server) ||\n (a.member ?? \"\").localeCompare(b.member ?? \"\") ||\n a.kind.localeCompare(b.kind),\n );\n}\n\n/**\n * Which servers moved without shipping anything.\n *\n * A surface that changes alongside a version bump is a release: somebody published something,\n * and the change is attributable to it. A surface that changes while the version stays exactly\n * where it was is the opposite, and it is the shape this product exists for: the same package,\n * the same version, a different set of instructions reaching the model.\n *\n * Both halves are already recorded. `server.identity.changed` carries the version move, so the\n * signal is the *absence* of one beside other changes, and a reviewer currently has to notice a\n * thing that is not there. This names it so a report can say it out loud.\n *\n * It lives beside the taxonomy rather than in the engine because it reasons about a list of\n * changes and nothing else: the dashboard asks the same question and has no business depending\n * on a diff engine to do it.\n */\nexport function serversThatShippedNothing(changes: readonly Change[]): string[] {\n const moved = new Set<string>();\n const versioned = new Set<string>();\n for (const change of changes) {\n moved.add(change.server);\n if (change.kind === \"server.identity.changed\") versioned.add(change.server);\n }\n return [...moved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ChB,kBAAkB;AAAA,EAClB,kBAAkB;AACpB;AAEO,IAAM,gBAA0C,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,EAAE;AAgB7E,SAAS,YAAY,SAA6B;AACvD,SAAO,CAAC,GAAG,OAAO,EAAE;AAAA,IAClB,CAAC,GAAG,MACF,cAAc,EAAE,QAAQ,IAAI,cAAc,EAAE,QAAQ,KACpD,EAAE,OAAO,cAAc,EAAE,MAAM,MAC9B,EAAE,UAAU,IAAI,cAAc,EAAE,UAAU,EAAE,KAC7C,EAAE,KAAK,cAAc,EAAE,IAAI;AAAA,EAC/B;AACF;AAkBO,SAAS,0BAA0B,SAAsC;AAC9E,QAAM,QAAQ,oBAAI,IAAY;AAC9B,QAAM,YAAY,oBAAI,IAAY;AAClC,aAAW,UAAU,SAAS;AAC5B,UAAM,IAAI,OAAO,MAAM;AACvB,QAAI,OAAO,SAAS,0BAA2B,WAAU,IAAI,OAAO,MAAM;AAAA,EAC5E;AACA,SAAO,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,UAAU,IAAI,MAAM,CAAC,EAAE,KAAK;AACpE;","names":[]}
1
+ {"version":3,"sources":["../src/changes.ts"],"sourcesContent":["/**\n * The change taxonomy: the one vocabulary the collector, the API, the dashboard and every\n * customer's SARIF consumer share.\n *\n * It lives here rather than in the CLI because it is a contract across process boundaries. A\n * collector on an old version reports a kind the server has to understand, and a renamed kind\n * breaks a SARIF rule id somebody has already suppressed. Renaming one is a major version.\n */\n\nexport const CHANGE_KINDS = [\n \"server.added\",\n \"server.removed\",\n \"server.renamed\",\n \"server.transport.changed\",\n \"server.identity.changed\",\n /*\n * Two kinds rather than one, because they call for opposite defaults.\n *\n * A version moving is the ordinary life of a dependency: most of them are patch releases that\n * nobody needs to read, and a policy blocking on them would fail every build in the week a\n * popular package ships. A version *not* moving while its contents do has no innocent\n * explanation -- a registry or mirror serving different bytes under a published version, or an\n * image tag repointed -- and that one should stop a build on the default policy.\n */\n \"server.artifact.changed\",\n \"server.artifact.substituted\",\n \"server.protocol.changed\",\n \"server.instructions.changed\",\n \"server.capabilities.widened\",\n \"server.capabilities.narrowed\",\n \"server.capabilities.changed\",\n \"tool.added\",\n \"tool.removed\",\n \"tool.description.changed\",\n \"tool.input_schema.widened\",\n \"tool.input_schema.narrowed\",\n \"tool.input_schema.changed\",\n \"tool.output_schema.changed\",\n \"tool.behavior.escalated\",\n \"tool.behavior.relaxed\",\n \"tool.header_params.changed\",\n \"tool.capability.gained\",\n \"tool.changed\",\n \"resource.added\",\n \"resource.removed\",\n \"resource.changed\",\n \"resource_template.added\",\n \"resource_template.removed\",\n \"resource_template.changed\",\n \"prompt.added\",\n \"prompt.removed\",\n \"prompt.changed\",\n] as const;\n\nexport type ChangeKind = (typeof CHANGE_KINDS)[number];\n\n/**\n * Ranking only. Every kind is drift; severity decides what a reviewer reads first, what SARIF\n * level an AppSec tool shows, and which changes a policy can be set to block. \"high\" is reserved\n * for shapes an attacker would use -- text that reaches the model, a widened input, a new power --\n * so that it keeps meaning something.\n */\nexport const SEVERITIES = [\"high\", \"medium\", \"low\"] as const;\nexport type Severity = (typeof SEVERITIES)[number];\n\nexport const SEVERITY: Record<ChangeKind, Severity> = {\n \"server.added\": \"medium\",\n \"server.removed\": \"low\",\n \"server.renamed\": \"low\",\n \"server.transport.changed\": \"high\",\n \"server.identity.changed\": \"medium\",\n \"server.artifact.changed\": \"medium\",\n \"server.artifact.substituted\": \"high\",\n \"server.protocol.changed\": \"medium\",\n \"server.instructions.changed\": \"high\",\n \"server.capabilities.widened\": \"medium\",\n \"server.capabilities.narrowed\": \"low\",\n \"server.capabilities.changed\": \"medium\",\n \"tool.added\": \"high\",\n \"tool.removed\": \"low\",\n \"tool.description.changed\": \"high\",\n \"tool.input_schema.widened\": \"high\",\n \"tool.input_schema.narrowed\": \"low\",\n \"tool.input_schema.changed\": \"medium\",\n \"tool.output_schema.changed\": \"medium\",\n \"tool.behavior.escalated\": \"high\",\n \"tool.behavior.relaxed\": \"low\",\n \"tool.header_params.changed\": \"high\",\n /*\n * Severity is set per change rather than read from here: what a tool gained decides it. A\n * `command` argument is not the same finding as a `url` one, and flattening both to one number\n * is how \"accepts input it did not before\" came to describe arbitrary command execution.\n */\n \"tool.capability.gained\": \"high\",\n \"tool.changed\": \"medium\",\n \"resource.added\": \"medium\",\n \"resource.removed\": \"low\",\n \"resource.changed\": \"medium\",\n \"resource_template.added\": \"high\",\n \"resource_template.removed\": \"low\",\n \"resource_template.changed\": \"high\",\n \"prompt.added\": \"medium\",\n \"prompt.removed\": \"low\",\n \"prompt.changed\": \"medium\",\n};\n\nexport const SEVERITY_RANK: Record<Severity, number> = { high: 0, medium: 1, low: 2 };\n\n/** One change, as the collector reports it and as the dashboard renders it. */\nexport interface Change {\n kind: ChangeKind;\n severity: Severity;\n /** Name of the server in the lock. */\n server: string;\n /** Tool, resource, template or prompt name, where the change is scoped to one. */\n member?: string;\n /** One line, written for a reviewer who has not read the lockfile. */\n summary: string;\n before?: unknown;\n after?: unknown;\n}\n\nexport function sortChanges(changes: Change[]): Change[] {\n return [...changes].sort(\n (a, b) =>\n SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] ||\n a.server.localeCompare(b.server) ||\n (a.member ?? \"\").localeCompare(b.member ?? \"\") ||\n a.kind.localeCompare(b.kind),\n );\n}\n\n/**\n * Which servers moved without shipping anything.\n *\n * A surface that changes alongside a version bump is a release: somebody published something,\n * and the change is attributable to it. A surface that changes while the version stays exactly\n * where it was is the opposite, and it is the shape this product exists for: the same package,\n * the same version, a different set of instructions reaching the model.\n *\n * Both halves are already recorded. `server.identity.changed` carries the version move, so the\n * signal is the *absence* of one beside other changes, and a reviewer currently has to notice a\n * thing that is not there. This names it so a report can say it out loud.\n *\n * It lives beside the taxonomy rather than in the engine because it reasons about a list of\n * changes and nothing else: the dashboard asks the same question and has no business depending\n * on a diff engine to do it.\n *\n * Only a server with a surface this run captured can have changed without shipping. A new server\n * that could not be audited arrives as `server.added` with nothing behind it, and one that is\n * gone has nothing now; both were listed as having changed without a release, which describes a\n * surface nobody saw.\n */\nexport function serversThatShippedNothing(changes: readonly Change[]): string[] {\n const moved = new Set<string>();\n const versioned = new Set<string>();\n for (const change of changes) {\n const uncaptured = change.kind === \"server.removed\" || (change.kind === \"server.added\" && change.after === undefined);\n if (!uncaptured) moved.add(change.server);\n if (change.kind === \"server.identity.changed\") versioned.add(change.server);\n }\n return [...moved].filter((server) => !versioned.has(server)).sort();\n}\n"],"mappings":";AASO,IAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAUO,IAAM,aAAa,CAAC,QAAQ,UAAU,KAAK;AAG3C,IAAM,WAAyC;AAAA,EACpD,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,4BAA4B;AAAA,EAC5B,2BAA2B;AAAA,EAC3B,2BAA2B;AAAA,EAC3B,+BAA+B;AAAA,EAC/B,2BAA2B;AAAA,EAC3B,+BAA+B;AAAA,EAC/B,+BAA+B;AAAA,EAC/B,gCAAgC;AAAA,EAChC,+BAA+B;AAAA,EAC/B,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,4BAA4B;AAAA,EAC5B,6BAA6B;AAAA,EAC7B,8BAA8B;AAAA,EAC9B,6BAA6B;AAAA,EAC7B,8BAA8B;AAAA,EAC9B,2BAA2B;A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ectiveSchema
9
- } from "./chunk-FVT77BL4.js";
8
+ beginWalk,
9
+ effectiveSchema,
10
+ entriesOf
11
+ } from "./chunk-Z4M6ZRTP.js";
10
12
 
11
13
  // src/lock/normalize.ts
12
14
  function resolveBehavior(annotations) {
@@ -21,8 +23,25 @@ function resolveBehavior(annotations) {
21
23
  function isEscalation(previous, next) {
22
24
  return previous.readOnly && !next.readOnly || !previous.destructive && next.destructive || previous.idempotent && !next.idempotent || !previous.openWorld && next.openWorld;
23
25
  }
24
- var DATA_KEYWORDS = /* @__PURE__ */ new Set(["const", "default", "enum", "examples", "example"]);
25
- var NAMED_SCHEMAS = /* @__PURE__ */ new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]);
26
+ var SCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
27
+ "items",
28
+ "prefixItems",
29
+ "additionalItems",
30
+ "contains",
31
+ "allOf",
32
+ "anyOf",
33
+ "oneOf",
34
+ "not",
35
+ "if",
36
+ "then",
37
+ "else",
38
+ "additionalProperties",
39
+ "unevaluatedProperties",
40
+ "unevaluatedItems",
41
+ "propertyNames",
42
+ "contentSchema"
43
+ ]);
44
+ var NAMED_SCHEMAS = /* @__PURE__ */ new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas", "dependencies"]);
26
45
  function normalizeSchema(value) {
27
46
  return normalizeNode(value, false);
28
47
  }
@@ -39,47 +58,54 @@ function normalizeNode(value, namesOnly) {
39
58
  out[key] = [...member].sort();
40
59
  continue;
41
60
  }
42
- if (DATA_KEYWORDS.has(key)) {
43
- out[key] = member;
44
- continue;
45
- }
46
- out[key] = normalizeNode(member, NAMED_SCHEMAS.has(key));
61
+ if (NAMED_SCHEMAS.has(key)) out[key] = normalizeNode(member, true);
62
+ else if (SCHEMA_KEYWORDS.has(key)) out[key] = normalizeNode(member, false);
63
+ else out[key] = member;
47
64
  }
48
65
  return out;
49
66
  }
50
67
  function extractHeaderParams(schema) {
51
68
  const found = [];
52
69
  let budget = MAX_HEADER_VISITS;
70
+ let reads = 0;
53
71
  const walk = (node, path, depth, refsOnPath) => {
54
72
  if (depth > MAX_VISIT_DEPTH) return;
55
73
  if (budget <= 0) return;
56
74
  budget -= 1;
57
75
  const object = effectiveSchema(node, schema);
58
76
  if (!object) return;
77
+ const descend = () => budget > 0 && depth + 1 <= MAX_VISIT_DEPTH;
59
78
  const properties = asObject(object["properties"]);
60
79
  if (properties) {
61
- for (const [name, child] of Object.entries(properties)) {
80
+ for (const [name, child] of entriesOf(properties)) {
81
+ if (++reads > MAX_HEADER_READS) return;
62
82
  const resolved = effectiveSchema(child, schema);
63
83
  if (!resolved) continue;
64
84
  const header = resolved["x-mcp-header"];
65
85
  if (typeof header === "string" && header.length > 0) found.push(`${[...path, name].join(".")} -> ${header}`);
66
86
  const ref = asObject(child)?.["$ref"];
67
87
  if (typeof ref === "string" && refsOnPath.has(ref)) continue;
88
+ if (!descend()) continue;
68
89
  walk(child, [...path, name], depth + 1, typeof ref === "string" ? /* @__PURE__ */ new Set([...refsOnPath, ref]) : refsOnPath);
69
90
  }
70
91
  }
71
92
  for (const branch of alternatives(object)) {
93
+ if (++reads > MAX_HEADER_READS) return;
72
94
  const ref = asObject(branch.schema)?.["$ref"];
73
95
  if (typeof ref === "string" && refsOnPath.has(ref)) continue;
96
+ if (!descend()) continue;
74
97
  walk(branch.schema, path, depth + 1, typeof ref === "string" ? /* @__PURE__ */ new Set([...refsOnPath, ref]) : refsOnPath);
75
98
  }
76
99
  };
77
100
  const rootRef = asObject(schema)?.["$ref"];
101
+ beginWalk(schema);
78
102
  walk(schema, [], 0, new Set(typeof rootRef === "string" ? [rootRef] : []));
79
103
  if (budget <= 0) found.push(`(schema too large to scan for headers past ${MAX_HEADER_VISITS} nodes)`);
104
+ if (reads > MAX_HEADER_READS) found.push(`(schema too large to scan for headers past ${MAX_HEADER_READS} reads)`);
80
105
  return [...new Set(found)].sort();
81
106
  }
82
107
  var MAX_HEADER_VISITS = 2e4;
108
+ var MAX_HEADER_READS = 50 * MAX_HEADER_VISITS;
83
109
  function stripIgnoredMeta(meta, ignoredPrefixes) {
84
110
  if (meta === null || meta === void 0 || typeof meta !== "object" || Array.isArray(meta)) return void 0;
85
111
  const out = /* @__PURE__ */ Object.create(null);
@@ -116,7 +142,8 @@ export {
116
142
  normalizeSchema,
117
143
  extractHeaderParams,
118
144
  MAX_HEADER_VISITS,
145
+ MAX_HEADER_READS,
119
146
  stripIgnoredMeta,
120
147
  sanitizeUrl
121
148
  };
122
- //# sourceMappingURL=chunk-5OCXDAFS.js.map
149
+ //# sourceMappingURL=chunk-CP2XTAKE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lock/normalize.ts"],"sourcesContent":["/** Turning what a server sent into the stable, reviewable form the lock stores. */\nimport { redactPath } from \"./credentials\";\nimport { alternatives, asObject, beginWalk, effectiveSchema, entriesOf, MAX_VISIT_DEPTH } from \"./jsonschema\";\nimport type { JsonObject, JsonValue, LockedAnnotations, LockedBehavior } from \"./types\";\n\n/**\n * Resolves the four behavioural annotations against the spec's defaults, which are not neutral:\n * an absent `readOnlyHint` means \"may modify\" and an absent `destructiveHint` means \"may\n * destroy\". A server deleting an annotation is therefore an escalation, and the lock has to be\n * able to show it as a changed value rather than a removed line. See docs/lockfile.md §4.\n *\n * `destructiveHint` and `idempotentHint` are defined to be meaningful only when `readOnlyHint`\n * is false, so a read-only tool resolves to non-destructive and idempotent regardless of what\n * it claims: a tool that changes nothing cannot destroy anything, and repeating it has no\n * additional effect.\n */\nexport function resolveBehavior(annotations: LockedAnnotations | undefined): LockedBehavior {\n const readOnly = annotations?.readOnlyHint ?? false;\n return {\n readOnly,\n destructive: readOnly ? false : (annotations?.destructiveHint ?? true),\n idempotent: readOnly ? true : (annotations?.idempotentHint ?? false),\n openWorld: annotations?.openWorldHint ?? true,\n };\n}\n\n/** True when `next` claims any power `previous` did not. */\nexport function isEscalation(previous: LockedBehavior, next: LockedBehavior): boolean {\n return (\n (previous.readOnly && !next.readOnly) ||\n (!previous.destructive && next.destructive) ||\n (previous.idempotent && !next.idempotent) ||\n (!previous.openWorld && next.openWorld)\n );\n}\n\n/*\n * Keywords whose value is a schema or a list of schemas, and keywords whose value maps names to\n * schemas. Only these are walked; every other value is data, kept as the server wrote it.\n *\n * A `required` array inside a `const` or a `default` is part of a value the model is shown, and\n * its order is the server's to choose: sorting it there made `[\"backup\", \"delete\"]` and\n * `[\"delete\", \"backup\"]` compare as the same. That was fixed by naming the five keywords that hold\n * values, which left every keyword nobody had named -- `x-default`, `x-examples`, any vendor's\n * extension -- walked as a schema and sorted the same way. A list of what is a schema does not\n * have that gap: a keyword this has never heard of is data, which is what an unknown keyword is.\n */\nconst SCHEMA_KEYWORDS = new Set([\n \"items\", \"prefixItems\", \"additionalItems\", \"contains\", \"allOf\", \"anyOf\", \"oneOf\", \"not\", \"if\", \"then\", \"else\",\n \"additionalProperties\", \"unevaluatedProperties\", \"unevaluatedItems\", \"propertyNames\", \"contentSchema\",\n]);\n/** Keywords whose value maps names to schemas: the keys are names, never keywords. */\nconst NAMED_SCHEMAS = new Set([\"properties\", \"patternProperties\", \"$defs\", \"definitions\", \"dependentSchemas\", \"dependencies\"]);\n\n/**\n * Sorts the `required` keyword's array. Member order there is semantically insignificant and is\n * the most common source of diffs that mean nothing. Every other array keeps server order,\n * because order *is* significant in `prefixItems`, `allOf` and `icons`, and we only reorder where\n * we can show it is safe.\n *\n * Only where `required` is a keyword of a schema: not inside a value (`const`, `default`, `enum`,\n * `examples`, an `x-` extension), and not as the name of a property, which is a schema of its own.\n */\nexport function normalizeSchema(value: JsonValue): JsonValue {\n return normalizeNode(value, false);\n}\n\nfunction normalizeNode(value: JsonValue, namesOnly: boolean): JsonValue {\n if (Array.isArray(value)) return value.map((member) => normalizeNode(member, false));\n if (value === null || typeof value !== \"object\") return value;\n\n // No prototype, so a member named `__proto__` is kept (see toJson in canonical.ts).\n const out = Object.create(null) as JsonObject;\n for (const [key, member] of Object.entries(value)) {\n if (namesOnly) {\n out[key] = normalizeNode(member, false);\n continue;\n }\n if (key === \"required\" && Array.isArray(member) && member.every((entry) => typeof entry === \"string\")) {\n out[key] = [...(member as string[])].sort();\n continue;\n }\n if (NAMED_SCHEMAS.has(key)) out[key] = normalizeNode(member, true);\n else if (SCHEMA_KEYWORDS.has(key)) out[key] = normalizeNode(member, false);\n else out[key] = member;\n }\n return out;\n}\n\n/**\n * Finds input properties carrying an `x-mcp-header` annotation, which mirrors the argument's\n * value into an `Mcp-Param-*` HTTP header on Streamable HTTP, where proxies and WAFs can read\n * it. A server adding this to an existing parameter redirects that argument's data with no\n * visible change to the tool's signature, so it gets its own line in the lock.\n *\n * `$ref` and `allOf` are resolved first. Schema generators put properties behind `$defs` as a\n * matter of course, and a scan that only read literal nodes found nothing in those -- which is\n * the worst outcome for a field whose entire purpose is to move data somewhere new.\n */\nexport function extractHeaderParams(schema: JsonValue): string[] {\n const found: string[] = [];\n /*\n * Bounded twice. A `$ref` already on the way down is not followed again: a definition whose\n * properties point back at it was walked once per property per level, P^12 calls, so a\n * 200-byte schema held `check` for minutes on a blocked event loop that no timeout could\n * interrupt. Headers inside a recursion are the ones its first pass already found. And a hard\n * ceiling on visits, which leaves a marker in the lock rather than an incomplete list that\n * looks complete.\n */\n let budget = MAX_HEADER_VISITS;\n /*\n * And a ceiling on what the walks read, which counting walks did not bound: each walk reads every\n * property and branch of the node it reaches, so a root of N properties that each lead back to it\n * is N walks of N reads. Past it, a marker of its own. The ceiling is what the walk ceiling\n * allows if every node it reaches has fifty members, so the answer -- which is part of the\n * tool's digest -- is the one it always was for every schema that is not built to do this.\n */\n let reads = 0;\n\n const walk = (node: JsonValue, path: string[], depth: number, refsOnPath: ReadonlySet<string>): void => {\n if (depth > MAX_VISIT_DEPTH) return;\n if (budget <= 0) return;\n budget -= 1;\n const object = effectiveSchema(node, schema);\n if (!object) return;\n\n // A walk that would return at once is not started: the same answer, without building its path.\n const descend = (): boolean => budget > 0 && depth + 1 <= MAX_VISIT_DEPTH;\n\n const properties = asObject(object[\"properties\"]);\n if (properties) {\n for (const [name, child] of entriesOf(properties)) {\n if (++reads > MAX_HEADER_READS) return;\n const resolved = effectiveSchema(child, schema);\n if (!resolved) continue;\n const header = resolved[\"x-mcp-header\"];\n if (typeof header === \"string\" && header.length > 0) found.push(`${[...path, name].join(\".\")} -> ${header}`);\n const ref = asObject(child)?.[\"$ref\"];\n if (typeof ref === \"string\" && refsOnPath.has(ref)) continue;\n if (!descend()) continue;\n walk(child, [...path, name], depth + 1, typeof ref === \"string\" ? new Set([...refsOnPath, ref]) : refsOnPath);\n }\n }\n\n // A parameter reachable only through one branch of an `anyOf` is still reachable.\n for (const branch of alternatives(object)) {\n if (++reads > MAX_HEADER_READS) return;\n const ref = asObject(branch.schema)?.[\"$ref\"];\n if (typeof ref === \"string\" && refsOnPath.has(ref)) continue;\n if (!descend()) continue;\n walk(branch.schema, path, depth + 1, typeof ref === \"string\" ? new Set([...refsOnPath, ref]) : refsOnPath);\n }\n };\n\n const rootRef = asObject(schema)?.[\"$ref\"];\n beginWalk(schema);\n walk(schema, [], 0, new Set(typeof rootRef === \"string\" ? [rootRef] : []));\n if (budget <= 0) found.push(`(schema too large to scan for headers past ${MAX_HEADER_VISITS} nodes)`);\n if (reads > MAX_HEADER_READS) found.push(`(schema too large to scan for headers past ${MAX_HEADER_READS} reads)`);\n return [...new Set(found)].sort();\n}\n\n/** How many schema nodes the header scan visits before it stops and says so. */\nexport const MAX_HEADER_VISITS = 20_000;\n/** How many properties and branches the header scan reads, across every visit, before it stops and says so. */\nexport const MAX_HEADER_READS = 50 * MAX_HEADER_VISITS;\n\n/** Drops `_meta` keys under any ignored prefix. Returns undefined when nothing is left to pin. */\nexport function stripIgnoredMeta(meta: JsonValue | undefined, ignoredPrefixes: readonly string[]): JsonObject | undefined {\n if (meta === null || meta === undefined || typeof meta !== \"object\" || Array.isArray(meta)) return undefined;\n const out = Object.create(null) as JsonObject;\n for (const [key, value] of Object.entries(meta)) {\n if (ignoredPrefixes.some((prefix) => key.startsWith(prefix))) continue;\n out[key] = value;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/** Strips the query string: query strings routinely carry tokens, and the lock is committed. */\nexport function sanitizeUrl(raw: string): string {\n /*\n * A placeholder (`${HOST}`, `${PORT}`) is kept exactly as written. Parsing first lowercased a\n * placeholder in the host, so the lock named a variable the config never used, and failed on one\n * in the port, which wrote the address raw, query string and all.\n */\n if (raw.includes(\"${\")) return sanitizeText(raw);\n try {\n const url = new URL(raw);\n url.search = \"\";\n url.hash = \"\";\n /*\n * `https://alice:s3cr3t@host/mcp` survived this untouched, because `toString()` keeps\n * userinfo. The query string was stripped on the grounds that credentials usually sit there;\n * userinfo is the one place a credential sits by definition.\n */\n url.username = \"\";\n url.password = \"\";\n // A hosted server whose address embeds the key keeps it in the path, past both of the above.\n url.pathname = redactPath(url.pathname);\n return url.toString();\n } catch {\n return sanitizeText(raw);\n }\n}\n\n/** The same, as text, for an address a URL parser cannot or should not normalize. */\nfunction sanitizeText(raw: string): string {\n const withoutUser = raw.replace(/^([a-z][a-z0-9+.-]*:\\/\\/)[^/@]*@/i, \"$1\");\n const base = withoutUser.split(/[?#]/)[0] ?? withoutUser;\n const parts = /^([a-z][a-z0-9+.-]*:\\/\\/[^/]*)(\\/.*)?$/i.exec(base);\n return parts ? `${parts[1]}${parts[2] ? redactPath(parts[2]) : \"\"}` : base;\n}\n"],"mappings":";;;;;;;;;;;;;AAgBO,SAAS,gBAAgB,aAA4D;AAC1F,QAAM,WAAW,aAAa,gBAAgB;AAC9C,SAAO;AAAA,IACL;AAAA,IACA,aAAa,WAAW,QAAS,aAAa,mBAAmB;AAAA,IACjE,YAAY,WAAW,OAAQ,aAAa,kBAAkB;AAAA,IAC9D,WAAW,aAAa,iBAAiB;AAAA,EAC3C;AACF;AAGO,SAAS,aAAa,UAA0B,MAA+B;AACpF,SACG,SAAS,YAAY,CAAC,KAAK,YAC3B,CAAC,SAAS,eAAe,KAAK,eAC9B,SAAS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AAI;AACzE,QAAM,OAAO,YAAY,MAAM,MAAM,EAAE,CAAC,KAAK;AAC7C,QAAM,QAAQ,0CAA0C,KAAK,IAAI;AACjE,SAAO,QAAQ,GAAG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,WAAW,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK;AACxE;","names":[]}
@@ -254,11 +254,17 @@ function redactArgs(args) {
254
254
  function looksLikeAnOperand(value) {
255
255
  return value.startsWith("@") || value.includes("/") || /\.(m?[jt]s|cjs|py|json|ya?ml|toml|sh|exe)$/i.test(value);
256
256
  }
257
+ var REVISION_WORDS = /* @__PURE__ */ new Set(["raw", "blob", "blobs", "tree", "trees", "commit", "commits", "archive", "src", "+"]);
258
+ var COMMIT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
257
259
  function redactPath(pathname, options = {}) {
260
+ let revisionPath = false;
258
261
  return pathname.split("/").map((segment) => {
262
+ const afterRevisionWord = revisionPath;
263
+ if (REVISION_WORDS.has(decoded(segment).toLowerCase())) revisionPath = true;
259
264
  if (segment === "" || PLACEHOLDER.test(decoded(segment))) return segment;
260
265
  if (looksRandom(segment)) return REDACTED;
261
- if (!options.contentAddressed && (/^[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)))
266
+ const commit = afterRevisionWord && COMMIT_ID.test(segment);
267
+ 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)))
262
268
  return REDACTED;
263
269
  return redactFormats(segment);
264
270
  }).join("/");
@@ -275,4 +281,4 @@ export {
275
281
  redactPath,
276
282
  countRedacted
277
283
  };
278
- //# sourceMappingURL=chunk-ZD2C4FMT.js.map
284
+ //# sourceMappingURL=chunk-MQJ54E63.js.map