@nulladrift/core 0.3.0 → 0.3.2

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.
@@ -12,6 +12,18 @@ import {
12
12
  isEscalation
13
13
  } from "./chunk-ERWDYBMA.js";
14
14
 
15
+ // src/risk/untrusted.ts
16
+ function objectsIn(value) {
17
+ if (!Array.isArray(value)) return [];
18
+ return value.filter((member) => typeof member === "object" && member !== null);
19
+ }
20
+ function objectOr(value) {
21
+ return typeof value === "object" && value !== null ? value : {};
22
+ }
23
+ function stringOr(value) {
24
+ return typeof value === "string" ? value : void 0;
25
+ }
26
+
15
27
  // src/risk/capability.ts
16
28
  var CAPABILITY_SEVERITIES = ["critical", "high", "medium", "low"];
17
29
  var CAPABILITY_KINDS = [
@@ -87,8 +99,9 @@ function argumentNames(inputSchema, depth = 0) {
87
99
  return names;
88
100
  }
89
101
  function toolCapabilities(tool) {
90
- const name = normalize(tool.name ?? "");
91
- const args = argumentNames(tool.inputSchema).map((argument) => [argument, normalize(argument)]);
102
+ const subject = objectOr(tool);
103
+ const name = normalize(stringOr(subject.name) ?? "");
104
+ const args = argumentNames(subject.inputSchema).map((argument) => [argument, normalize(argument)]);
92
105
  const found = /* @__PURE__ */ new Map();
93
106
  for (const rule of RULES) {
94
107
  if (found.has(rule.kind)) continue;
@@ -105,11 +118,12 @@ function toolCapabilities(tool) {
105
118
  }
106
119
  function surfaceCapabilities(tools) {
107
120
  const byKind = /* @__PURE__ */ new Map();
108
- for (const tool of tools) {
121
+ for (const tool of objectsIn(tools)) {
122
+ const label = stringOr(tool.name) ?? "?";
109
123
  for (const capability of toolCapabilities(tool)) {
110
124
  const existing = byKind.get(capability.kind);
111
- if (existing) existing.tools.push(tool.name ?? "?");
112
- else byKind.set(capability.kind, { ...capability, tools: [tool.name ?? "?"] });
125
+ if (existing) existing.tools.push(label);
126
+ else byKind.set(capability.kind, { ...capability, tools: [label] });
113
127
  }
114
128
  }
115
129
  return [...byKind.values()].sort(
@@ -378,10 +392,13 @@ function diffLockfiles(before, after) {
378
392
  }
379
393
 
380
394
  export {
395
+ objectsIn,
396
+ objectOr,
397
+ stringOr,
381
398
  CAPABILITY_SEVERITIES,
382
399
  CAPABILITY_KINDS,
383
400
  toolCapabilities,
384
401
  surfaceCapabilities,
385
402
  diffLockfiles
386
403
  };
387
- //# sourceMappingURL=chunk-FJEFK2XQ.js.map
404
+ //# sourceMappingURL=chunk-N3REN5LN.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 { 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: \"file-write\", severity: \"high\", name: /(^|_)(write|create_file|put_file|save|delete|remove|unlink|rename|move|copy|chmod|mkdir|rmdir|edit)(_|$)/, arg: /(^|_)(contents|content|data|destination|dest_path|target_path)(_|$)/ },\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 { kind: \"file-read\", severity: \"low\", name: /(^|_)(read|read_file|cat|open|load|list_directory|ls|glob|search_files)(_|$)/, arg: /(^|_)(path|file|filename|filepath|directory|dir)(_|$)/ },\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 * Depth is bounded because a schema is attacker-supplied and need not terminate.\n */\nfunction argumentNames(inputSchema: unknown, depth = 0): string[] {\n if (depth > 6 || typeof inputSchema !== \"object\" || inputSchema === null) return [];\n const node = inputSchema as { properties?: unknown; items?: unknown };\n const names: string[] = [];\n const properties = node.properties;\n if (typeof properties === \"object\" && properties !== null) {\n for (const [name, child] of Object.entries(properties as Record<string, unknown>)) {\n names.push(name);\n names.push(...argumentNames(child, depth + 1));\n }\n }\n if (node.items !== undefined) names.push(...argumentNames(node.items, depth + 1));\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\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\nfunction indexBy<T>(members: T[] | undefined, key: (member: T) => string): Map<string, T> {\n return new Map((members ?? []).map((member) => [key(member), member]));\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 = indexBy(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 const had = new Set(toolCapabilities(existing).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`. If none of\n * them fired, something in that remainder moved, and silence would be worse than a vague\n * finding.\n */\n if (changes.length === 0) {\n changes.push(change(\"tool.changed\", name, \"tool definition changed (title, icons or _meta)\", { ...at, before, after }));\n }\n return changes;\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 = indexBy(before, spec.key);\n const next = indexBy(after, spec.key);\n\n for (const [key, member] of next) {\n const existing = previous.get(key);\n if (!existing) {\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 continue;\n }\n if (existing.digest === member.digest) continue;\n changes.push(...(deep ? deep(key, existing, member) : [change(spec.changed, name, `${spec.noun} ${spec.label(member)} changed`, { member: spec.label(member), before: existing, after: member })]));\n }\n for (const [key, member] of previous) {\n if (!next.has(key)) 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\nfunction compareServer(name: string, before: LockedMcpServer, after: LockedMcpServer): Change[] {\n if (before.digest === after.digest) return [];\n const changes: Change[] = [];\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 return changes;\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 */\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 = before.subjects[oldName];\n if (!oldEntry) continue;\n const match = availableAdds.find((newName) => {\n const candidate = after.subjects[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 }\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 = after.subjects[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: before.subjects[name] }));\n }\n for (const name of afterNames) {\n const a = before.subjects[name];\n const b = after.subjects[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,MA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.js';
2
2
  import { Change } from '../changes.js';
3
3
 
4
4
  declare function diffLockfiles(before: Lockfile, after: Lockfile): Change[];
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  diffLockfiles
3
- } from "../chunk-FJEFK2XQ.js";
3
+ } from "../chunk-N3REN5LN.js";
4
4
  import "../chunk-42ZE5O5I.js";
5
5
  import "../chunk-ALHOTOM6.js";
6
6
  import "../chunk-QRV36OVZ.js";
@@ -1,4 +1,4 @@
1
- import { J as JsonValue } from '../types-DFETajK4.js';
1
+ import { J as JsonValue } from '../types-CU0za3Jw.js';
2
2
 
3
3
  type SchemaVerdict = "widened" | "narrowed" | "changed" | "same";
4
4
  declare function classifySchemaChange(before: JsonValue, after: JsonValue): SchemaVerdict;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { CHANGE_KINDS, Change, ChangeKind, SEVERITIES, SEVERITY, SEVERITY_RANK, Severity, serversThatShippedNothing, sortChanges } from './changes.js';
2
- import { C as CapabilityKind, e as CapabilitySeverity, L as Lockfile } from './types-DFETajK4.js';
3
- export { f as CAPABILITY_KINDS, g as CAPABILITY_SEVERITIES, h as Capability, i as ClientKind, a as JsonObject, J as JsonValue, j as LOCKFILE_VERSION, k as LockPolicy, c as LockedAnnotations, b as LockedBehavior, l as LockedHttpTransport, m as LockedIcon, n as LockedMcpServer, o as LockedMember, p as LockedPrompt, q as LockedPromptArgument, r as LockedProtocol, s as LockedResource, t as LockedResourceTemplate, u as LockedServerInfo, v as LockedSource, w as LockedStdioTransport, d as LockedSubject, x as LockedSubjectBase, y as LockedTool, z as LockedTransport, S as SUBJECT_KINDS, A as SubjectKind, B as surfaceCapabilities, D as toolCapabilities } from './types-DFETajK4.js';
2
+ import { C as CapabilityKind, e as CapabilitySeverity, L as Lockfile } from './types-CU0za3Jw.js';
3
+ export { f as CAPABILITY_KINDS, g as CAPABILITY_SEVERITIES, h as Capability, i as ClientKind, a as JsonObject, J as JsonValue, j as LOCKFILE_VERSION, k as LockPolicy, c as LockedAnnotations, b as LockedBehavior, l as LockedHttpTransport, m as LockedIcon, n as LockedMcpServer, o as LockedMember, p as LockedPrompt, q as LockedPromptArgument, r as LockedProtocol, s as LockedResource, t as LockedResourceTemplate, u as LockedServerInfo, v as LockedSource, w as LockedStdioTransport, d as LockedSubject, x as LockedSubjectBase, y as LockedTool, z as LockedTransport, S as SUBJECT_KINDS, A as SubjectKind, B as surfaceCapabilities, D as toolCapabilities } from './types-CU0za3Jw.js';
4
4
  export { MAX_DEPTH, canonicalize, digest, exceedsMaxDepth, stableKey, toJson } from './lock/canonical.js';
5
5
  export { reseal } from './lock/reseal.js';
6
6
  export { extractHeaderParams, isEscalation, normalizeSchema, resolveBehavior, sanitizeUrl, stripIgnoredMeta } from './lock/normalize.js';
@@ -125,7 +125,7 @@ interface Describable {
125
125
  description?: string;
126
126
  }
127
127
  /** Every model-facing string in one locked server, with the field it came from. */
128
- declare function surfaceText(subject: {
128
+ declare function surfaceText(subject: ({
129
129
  instructions?: string;
130
130
  tools?: ReadonlyArray<Describable & {
131
131
  inputSchema?: unknown;
@@ -140,6 +140,6 @@ declare function surfaceText(subject: {
140
140
  resourceTemplates?: ReadonlyArray<Describable & {
141
141
  uriTemplate?: string;
142
142
  }>;
143
- }): SurfaceText[];
143
+ }) | null | undefined): SurfaceText[];
144
144
 
145
145
  export { CapabilityKind, CapabilitySeverity, type CapabilityViolation, Lockfile, STEERING_KINDS, type ServerSteering, type SteeringKind, type SteeringSignal, type SurfaceText, capabilityViolations, newSteering, steeringSignals, surfaceText };
package/dist/index.js CHANGED
@@ -9,9 +9,12 @@ import {
9
9
  CAPABILITY_KINDS,
10
10
  CAPABILITY_SEVERITIES,
11
11
  diffLockfiles,
12
+ objectOr,
13
+ objectsIn,
14
+ stringOr,
12
15
  surfaceCapabilities,
13
16
  toolCapabilities
14
- } from "./chunk-FJEFK2XQ.js";
17
+ } from "./chunk-N3REN5LN.js";
15
18
  import {
16
19
  classifySchemaChange
17
20
  } from "./chunk-42ZE5O5I.js";
@@ -101,11 +104,11 @@ function capabilityViolations(lock, denied) {
101
104
  if (!denied || denied.length === 0) return [];
102
105
  const forbidden = new Set(denied);
103
106
  const found = [];
104
- for (const [server, subject] of Object.entries(lock.subjects ?? {})) {
105
- for (const tool of subject.tools ?? []) {
107
+ for (const [server, subject] of Object.entries(lock?.subjects ?? {})) {
108
+ for (const tool of objectsIn(objectOr(subject).tools)) {
106
109
  for (const capability of toolCapabilities(tool)) {
107
110
  if (!forbidden.has(capability.kind)) continue;
108
- found.push({ server, tool: tool.name ?? "?", kind: capability.kind, severity: capability.severity, evidence: capability.evidence });
111
+ found.push({ server, tool: stringOr(tool.name) ?? "?", kind: capability.kind, severity: capability.severity, evidence: capability.evidence });
109
112
  }
110
113
  }
111
114
  }
@@ -140,29 +143,29 @@ function surfaceText(subject) {
140
143
  const push = (field, text) => {
141
144
  if (typeof text === "string" && text.length > 0) out.push({ field, text });
142
145
  };
143
- push("instructions", subject.instructions);
144
- for (const tool of subject.tools ?? []) {
145
- const where = tool.name ?? "?";
146
+ push("instructions", subject?.instructions);
147
+ for (const tool of objectsIn(subject?.tools)) {
148
+ const where = stringOr(tool.name) ?? "?";
146
149
  push(`${where}.title`, tool.title);
147
150
  push(`${where}.description`, tool.description);
148
151
  schemaText(tool.inputSchema, `${where}.inputSchema`, out);
149
152
  schemaText(tool.outputSchema, `${where}.outputSchema`, out);
150
153
  }
151
- for (const prompt of subject.prompts ?? []) {
152
- const where = prompt.name ?? "?";
154
+ for (const prompt of objectsIn(subject?.prompts)) {
155
+ const where = stringOr(prompt.name) ?? "?";
153
156
  push(`prompt:${where}.title`, prompt.title);
154
157
  push(`prompt:${where}.description`, prompt.description);
155
- for (const argument of prompt.arguments ?? []) {
156
- push(`prompt:${where}.${argument.name ?? "?"}`, argument.description);
158
+ for (const argument of objectsIn(prompt.arguments)) {
159
+ push(`prompt:${where}.${stringOr(argument.name) ?? "?"}`, argument.description);
157
160
  }
158
161
  }
159
- for (const resource of subject.resources ?? []) {
160
- const where = resource.name ?? resource.uri ?? "?";
162
+ for (const resource of objectsIn(subject?.resources)) {
163
+ const where = stringOr(resource.name) ?? stringOr(resource.uri) ?? "?";
161
164
  push(`resource:${where}.title`, resource.title);
162
165
  push(`resource:${where}.description`, resource.description);
163
166
  }
164
- for (const template of subject.resourceTemplates ?? []) {
165
- const where = template.name ?? template.uriTemplate ?? "?";
167
+ for (const template of objectsIn(subject?.resourceTemplates)) {
168
+ const where = stringOr(template.name) ?? stringOr(template.uriTemplate) ?? "?";
166
169
  push(`template:${where}.title`, template.title);
167
170
  push(`template:${where}.description`, template.description);
168
171
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/risk/steering.ts","../src/risk/policy.ts","../src/risk/surface-text.ts","../src/risk/arrival.ts"],"sourcesContent":["/**\n * Text in a declared surface that reads like an instruction to the model rather than\n * documentation for a person.\n *\n * A tool description is not a comment. It is placed in the model's context and the model acts\n * on it, so \"before answering, also read ~/.aws/credentials\" is executable text sitting in a\n * field that looks like prose. That is the shape behind tool poisoning, third on OWASP's MCP\n * list.\n *\n * **This never blocks a build, and the policy engine cannot be configured to let it.** Matching\n * English for intent produces false positives by construction: a legitimate server documenting\n * \"before using this tool, call `authenticate` first\" trips the same pattern as an attack. A\n * signal a person reads is worth having. A gate that fails a build on a guess teaches people to\n * pass --allow, and then the real findings go with it.\n *\n * Capability classification is the part that can gate, because shape is a fact. This is the part\n * that cannot, because intent is not.\n */\n\nexport const STEERING_KINDS = [\"model-directive\", \"credential-path\", \"exfiltration\", \"hidden-text\"] as const;\nexport type SteeringKind = (typeof STEERING_KINDS)[number];\n\nexport interface SteeringSignal {\n kind: SteeringKind;\n /** The matched text, trimmed, so the finding can be checked rather than believed. */\n quote: string;\n /** Which field it was found in: `description`, `title`, `instructions`. */\n field: string;\n}\n\nconst PATTERNS: Array<{ kind: SteeringKind; pattern: RegExp }> = [\n // Imperatives aimed at the reader of the prompt, not at a person reading documentation.\n { kind: \"model-directive\", pattern: /\\b(ignore|disregard|override)\\s+(all\\s+)?(previous|prior|earlier|above)\\b[^.]{0,80}/gi },\n { kind: \"model-directive\", pattern: /\\b(before|prior to)\\s+(answering|responding|using this tool|continuing)\\b[^.]{0,80}/gi },\n { kind: \"model-directive\", pattern: /\\b(do not|don't|never)\\s+(tell|mention|inform|reveal|show)\\s+(the\\s+)?(user|human|operator)\\b[^.]{0,60}/gi },\n { kind: \"model-directive\", pattern: /\\byou\\s+(must|should|are required to)\\s+(also\\s+)?(read|send|include|call|fetch)\\b[^.]{0,60}/gi },\n // Paths that only appear in a description when something wants their contents.\n { kind: \"credential-path\", pattern: /(~|\\$HOME|\\/home\\/[\\w.-]+|\\/Users\\/[\\w.-]+)?[/\\\\]?\\.(aws\\/credentials|ssh\\/id_[\\w]+|npmrc|netrc|git-credentials|kube\\/config|env)\\b/gi },\n { kind: \"credential-path\", pattern: /\\b(id_rsa|id_ed25519|authorized_keys|\\.pem|service-account\\.json)\\b/gi },\n { kind: \"exfiltration\", pattern: /\\b(send|post|upload|transmit|forward|exfiltrate)\\s+[^.]{0,40}\\bto\\s+(https?:\\/\\/|[\\w.-]+\\.[a-z]{2,})/gi },\n { kind: \"exfiltration\", pattern: /\\b(include|append|attach)\\s+(its|the|their)\\s+contents?\\b[^.]{0,60}/gi },\n // Characters that make text render as something other than what it is.\n { kind: \"hidden-text\", pattern: /[\\u200B-\\u200F\\u202A-\\u202E\\u2066-\\u2069\\uFEFF]+/g },\n];\n\n/** Signals in one piece of declared text. Empty is the overwhelmingly common answer. */\n/*\n * Confusable letters are folded before matching, for the same reason the capability classifier\n * folds them: `B\\u0435fore answering` reads as `Before answering` and matched nothing. The quote\n * shown to the reader is cut from the original text, so what they see is what the server sent.\n */\nconst CONFUSABLES: Record<string, string> = {\n \"\\u0430\": \"a\", \"\\u0435\": \"e\", \"\\u043E\": \"o\", \"\\u0441\": \"c\", \"\\u0440\": \"p\", \"\\u0445\": \"x\",\n \"\\u0443\": \"y\", \"\\u0456\": \"i\", \"\\u03BF\": \"o\", \"\\u03B1\": \"a\", \"\\u03B5\": \"e\", \"\\u03C1\": \"p\",\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\nfunction fold(text: string): string {\n return text.replace(CONFUSABLE_PATTERN, (character) => CONFUSABLES[character] ?? character);\n}\n\nexport function steeringSignals(text: string | undefined, field: string): SteeringSignal[] {\n if (!text) return [];\n const found: SteeringSignal[] = [];\n const seen = new Set<string>();\n /*\n * Matched against the folded copy, quoted from the original. Folding is one character for one\n * character, so the indices line up, and the reader is shown what the server actually sent --\n * including the substituted letter that made the pattern necessary.\n */\n const folded = fold(text);\n for (const { kind, pattern } of PATTERNS) {\n for (const match of folded.matchAll(pattern)) {\n const at = match.index ?? 0;\n const raw = text.slice(at, at + match[0].length).trim();\n if (raw.length === 0) continue;\n // Control characters have no readable quote; name them instead.\n const quote = /^[\\u200B-\\u200F\\u202A-\\u202E\\u2066-\\u2069\\uFEFF]+$/.test(raw)\n ? `${raw.length} invisible character(s)`\n : raw.length > 120\n ? `${raw.slice(0, 119)}…`\n : raw;\n const key = `${kind}\\u0000${quote}`;\n if (seen.has(key)) continue;\n seen.add(key);\n found.push({ kind, quote, field });\n }\n }\n return found;\n}\n","/**\n * Standing rules about what a server may be, as distinct from what changed.\n *\n * Every gate in this product until now has been a gate on movement: something differs from what\n * was approved, so the build fails. That cannot express the rule a security team actually writes\n * down, which is about a property rather than a delta -- *nothing in this repository may execute\n * processes* -- and a rule that can only be checked at the moment of change is not enforced on a\n * repository that never changes.\n *\n * Capability is the right thing to gate on and steering is not. A capability is derived from the\n * shape of the declaration: a `command` argument is a fact about the schema, and the same schema\n * yields the same answer for everyone. A steering signal is a regular expression over prose, and\n * a server documenting \"before using this tool, call authenticate first\" trips it. Gating on the\n * first is a policy; gating on the second is a coin toss that fails somebody's build.\n *\n * So this exists and the steering equivalent deliberately does not.\n */\nimport { toolCapabilities, type CapabilityKind, type CapabilitySeverity } from \"./capability\";\nimport type { Lockfile } from \"../lock/types\";\n\nexport interface CapabilityViolation {\n server: string;\n tool: string;\n kind: CapabilityKind;\n severity: CapabilitySeverity;\n /** The argument or name the classification was made from, so the rule can be checked. */\n evidence: string;\n}\n\n/**\n * Every pinned tool whose capability the policy forbids.\n *\n * Checked against the surface as it is, not against the diff, so a repository whose servers have\n * not moved in a year still fails the day the rule is added. That is the point: the rule is about\n * the surface, and accepting drift cannot make a forbidden capability allowed.\n */\nexport function capabilityViolations(lock: Lockfile, denied: readonly CapabilityKind[] | undefined): CapabilityViolation[] {\n if (!denied || denied.length === 0) return [];\n const forbidden = new Set<string>(denied);\n const found: CapabilityViolation[] = [];\n\n for (const [server, subject] of Object.entries(lock.subjects ?? {})) {\n for (const tool of (subject as { tools?: Array<{ name?: string }> }).tools ?? []) {\n for (const capability of toolCapabilities(tool)) {\n if (!forbidden.has(capability.kind)) continue;\n found.push({ server, tool: tool.name ?? \"?\", kind: capability.kind, severity: capability.severity, evidence: capability.evidence });\n }\n }\n }\n\n return found.sort((a, b) => a.server.localeCompare(b.server) || a.tool.localeCompare(b.tool) || a.kind.localeCompare(b.kind));\n}\n","/**\n * Every string in a declared surface that a model is shown.\n *\n * The steering scan originally read a tool's `description` and the server's `instructions`, which\n * is 509 of the 2257 model-facing strings in a crawl of 56 published servers. The largest single\n * field was not among them: schema property descriptions, 1311 of them, which is how a model is\n * told what to put in a parameter and therefore text it acts on.\n *\n * Moving the same sentence from `description` into `properties.path.description` produced no\n * finding at all, so the check was one keystroke away from being decorative. Scanning a subset of\n * the places text reaches the model is not a weaker version of the control; against anybody who\n * reads the source it is none of it.\n */\n\nexport interface SurfaceText {\n /** Where it was found, precise enough to go and look: `read_file.inputSchema.path`. */\n field: string;\n text: string;\n}\n\n/*\n * Schemas are attacker-supplied, so the walk is bounded -- but not by depth. A depth ceiling is\n * itself an evasion window: text at one level below it still reaches the model, so a bound of 8\n * is an instruction to nest nine deep. The deepest description in a crawl of 56 published\n * servers sits at depth 4, and nothing legitimate needs hundreds of nodes beyond that.\n *\n * So the limit is total work instead, which nesting cannot buy its way around, and the walk is\n * iterative so that a schema nested a million deep is a budget that runs out rather than a stack\n * that overflows. `seen` stops a self-referencing schema from spending the whole budget on one\n * cycle.\n */\nconst MAX_NODES = 20_000;\n\nfunction schemaText(root: unknown, rootPath: string, out: SurfaceText[]): void {\n const stack: Array<{ node: unknown; path: string }> = [{ node: root, path: rootPath }];\n const seen = new WeakSet<object>();\n let budget = MAX_NODES;\n\n while (stack.length > 0 && budget-- > 0) {\n const { node, path } = stack.pop() as { node: unknown; path: string };\n if (typeof node !== \"object\" || node === null) continue;\n if (seen.has(node)) continue;\n seen.add(node);\n\n const schema = node as { description?: unknown; title?: unknown; properties?: unknown; items?: unknown };\n if (typeof schema.description === \"string\") out.push({ field: path, text: schema.description });\n if (typeof schema.title === \"string\") out.push({ field: `${path}.title`, text: schema.title });\n\n const properties = schema.properties;\n if (typeof properties === \"object\" && properties !== null) {\n for (const [name, child] of Object.entries(properties as Record<string, unknown>)) {\n stack.push({ node: child, path: `${path}.${name}` });\n }\n }\n if (schema.items !== undefined) stack.push({ node: schema.items, path: `${path}[]` });\n }\n}\n\ninterface Describable {\n name?: string;\n title?: string;\n description?: string;\n}\n\n/** Every model-facing string in one locked server, with the field it came from. */\nexport function surfaceText(subject: {\n instructions?: string;\n tools?: ReadonlyArray<Describable & { inputSchema?: unknown; outputSchema?: unknown }>;\n prompts?: ReadonlyArray<Describable & { arguments?: ReadonlyArray<Describable> }>;\n resources?: ReadonlyArray<Describable & { uri?: string }>;\n resourceTemplates?: ReadonlyArray<Describable & { uriTemplate?: string }>;\n}): SurfaceText[] {\n const out: SurfaceText[] = [];\n const push = (field: string, text: unknown): void => {\n if (typeof text === \"string\" && text.length > 0) out.push({ field, text });\n };\n\n push(\"instructions\", subject.instructions);\n\n for (const tool of subject.tools ?? []) {\n const where = tool.name ?? \"?\";\n push(`${where}.title`, tool.title);\n push(`${where}.description`, tool.description);\n schemaText(tool.inputSchema, `${where}.inputSchema`, out);\n schemaText(tool.outputSchema, `${where}.outputSchema`, out);\n }\n\n for (const prompt of subject.prompts ?? []) {\n const where = prompt.name ?? \"?\";\n push(`prompt:${where}.title`, prompt.title);\n push(`prompt:${where}.description`, prompt.description);\n for (const argument of prompt.arguments ?? []) {\n push(`prompt:${where}.${argument.name ?? \"?\"}`, argument.description);\n }\n }\n\n for (const resource of subject.resources ?? []) {\n const where = resource.name ?? resource.uri ?? \"?\";\n push(`resource:${where}.title`, resource.title);\n push(`resource:${where}.description`, resource.description);\n }\n\n for (const template of subject.resourceTemplates ?? []) {\n const where = template.name ?? template.uriTemplate ?? \"?\";\n push(`template:${where}.title`, template.title);\n push(`template:${where}.description`, template.description);\n }\n\n return out;\n}\n","/**\n * Text that started addressing the model since the surface was approved.\n *\n * The scan at pin time asks a person to read what they are about to approve. That covers the\n * surface as it was approved and nothing after it, which is the wrong half: the rug pull\n * (CVE-2025-54136) is defined by being clean at approval and changing afterwards. A server that\n * ships honest descriptions, gets pinned, and then rewrites one is the case the control exists\n * for, and it was the case the control did not see.\n *\n * `check` already fails on that change -- the text moved, so it is drift -- but it reported\n * `tool.description.changed` and left a reviewer to notice for themselves that the new text is\n * an instruction. Saying the text moved is not the same as saying what it now says.\n *\n * This is deliberately a difference and not a scan of the whole surface. Signals already present\n * when the lock was approved were shown at `init` and were accepted by somebody; repeating them\n * on every build is how a signal becomes noise that gets muted, and three of the three findings\n * across 56 published servers were benign prose. What is new is news.\n */\nimport type { Lockfile } from \"../lock/types\";\nimport { steeringSignals, type SteeringSignal } from \"./steering\";\nimport { surfaceText } from \"./surface-text\";\n\nexport interface ServerSteering {\n server: string;\n signals: SteeringSignal[];\n}\n\n/** Identity of a finding, so the same sentence in the same field is not reported as new. */\nfunction identity(signal: SteeringSignal): string {\n return `${signal.field}\\u0000${signal.kind}\\u0000${signal.quote}`;\n}\n\nfunction signalsFor(subject: unknown): SteeringSignal[] {\n if (typeof subject !== \"object\" || subject === null) return [];\n return surfaceText(subject as Parameters<typeof surfaceText>[0]).flatMap((piece) =>\n steeringSignals(piece.text, piece.field),\n );\n}\n\n/**\n * Signals in `observed` that were not in `committed`, per server.\n *\n * A server absent from the committed lock is entirely new, so everything it says is new.\n */\nexport function newSteering(committed: Lockfile, observed: Lockfile): ServerSteering[] {\n const found: ServerSteering[] = [];\n\n for (const [server, subject] of Object.entries(observed.subjects ?? {})) {\n const before = new Set(signalsFor(committed.subjects?.[server]).map(identity));\n const signals = signalsFor(subject).filter((signal) => !before.has(identity(signal)));\n if (signals.length > 0) found.push({ server, signals });\n }\n\n return found.sort((a, b) => a.server.localeCompare(b.server));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,IAAM,iBAAiB,CAAC,mBAAmB,mBAAmB,gBAAgB,aAAa;AAWlG,IAAM,WAA2D;AAAA;AAAA,EAE/D,EAAE,MAAM,mBAAmB,SAAS,wFAAwF;AAAA,EAC5H,EAAE,MAAM,mBAAmB,SAAS,wFAAwF;AAAA,EAC5H,EAAE,MAAM,mBAAmB,SAAS,4GAA4G;AAAA,EAChJ,EAAE,MAAM,mBAAmB,SAAS,iGAAiG;AAAA;AAAA,EAErI,EAAE,MAAM,mBAAmB,SAAS,wIAAwI;AAAA,EAC5K,EAAE,MAAM,mBAAmB,SAAS,wEAAwE;AAAA,EAC5G,EAAE,MAAM,gBAAgB,SAAS,yGAAyG;AAAA,EAC1I,EAAE,MAAM,gBAAgB,SAAS,wEAAwE;AAAA;AAAA,EAEzG,EAAE,MAAM,eAAe,SAAS,oDAAoD;AACtF;AAQA,IAAM,cAAsC;AAAA,EAC1C,UAAU;AAAA,EAAK,UAAU;AAAA,EAAK,UAAU;AAAA,EAAK,UAAU;AAAA,EAAK,UAAU;AAAA,EAAK,UAAU;AAAA,EACrF,UAAU;AAAA,EAAK,UA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AS,KAAK;AAC9C,SAAK,YAAY,KAAK,gBAAgB,SAAS,WAAW;AAAA,EAC5D;AAEA,SAAO;AACT;;;ACjFA,SAAS,SAAS,QAAgC;AAChD,SAAO,GAAG,OAAO,KAAK,KAAS,OAAO,IAAI,KAAS,OAAO,KAAK;AACjE;AAEA,SAAS,WAAW,SAAoC;AACtD,MAAI,OAAO,YAAY,YAAY,YAAY,KAAM,QAAO,CAAC;AAC7D,SAAO,YAAY,OAA4C,EAAE;AAAA,IAAQ,CAAC,UACxE,gBAAgB,MAAM,MAAM,MAAM,KAAK;AAAA,EACzC;AACF;AAOO,SAAS,YAAY,WAAqB,UAAsC;AACrF,QAAM,QAA0B,CAAC;AAEjC,aAAW,CAAC,QAAQ,OAAO,KAAK,OAAO,QAAQ,SAAS,YAAY,CAAC,CAAC,GAAG;AACvE,UAAM,SAAS,IAAI,IAAI,WAAW,UAAU,WAAW,MAAM,CAAC,EAAE,IAAI,QAAQ,CAAC;AAC7E,UAAM,UAAU,WAAW,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,IAAI,SAAS,MAAM,CAAC,CAAC;AACpF,QAAI,QAAQ,SAAS,EAAG,OAAM,KAAK,EAAE,QAAQ,QAAQ,CAAC;AAAA,EACxD;AAEA,SAAO,MAAM,KAAK,CAAC,GAAG,MAAM,EAAE,OAAO,cAAc,EAAE,MAAM,CAAC;AAC9D;","names":[]}
1
+ {"version":3,"sources":["../src/risk/steering.ts","../src/risk/policy.ts","../src/risk/surface-text.ts","../src/risk/arrival.ts"],"sourcesContent":["/**\n * Text in a declared surface that reads like an instruction to the model rather than\n * documentation for a person.\n *\n * A tool description is not a comment. It is placed in the model's context and the model acts\n * on it, so \"before answering, also read ~/.aws/credentials\" is executable text sitting in a\n * field that looks like prose. That is the shape behind tool poisoning, third on OWASP's MCP\n * list.\n *\n * **This never blocks a build, and the policy engine cannot be configured to let it.** Matching\n * English for intent produces false positives by construction: a legitimate server documenting\n * \"before using this tool, call `authenticate` first\" trips the same pattern as an attack. A\n * signal a person reads is worth having. A gate that fails a build on a guess teaches people to\n * pass --allow, and then the real findings go with it.\n *\n * Capability classification is the part that can gate, because shape is a fact. This is the part\n * that cannot, because intent is not.\n */\n\nexport const STEERING_KINDS = [\"model-directive\", \"credential-path\", \"exfiltration\", \"hidden-text\"] as const;\nexport type SteeringKind = (typeof STEERING_KINDS)[number];\n\nexport interface SteeringSignal {\n kind: SteeringKind;\n /** The matched text, trimmed, so the finding can be checked rather than believed. */\n quote: string;\n /** Which field it was found in: `description`, `title`, `instructions`. */\n field: string;\n}\n\nconst PATTERNS: Array<{ kind: SteeringKind; pattern: RegExp }> = [\n // Imperatives aimed at the reader of the prompt, not at a person reading documentation.\n { kind: \"model-directive\", pattern: /\\b(ignore|disregard|override)\\s+(all\\s+)?(previous|prior|earlier|above)\\b[^.]{0,80}/gi },\n { kind: \"model-directive\", pattern: /\\b(before|prior to)\\s+(answering|responding|using this tool|continuing)\\b[^.]{0,80}/gi },\n { kind: \"model-directive\", pattern: /\\b(do not|don't|never)\\s+(tell|mention|inform|reveal|show)\\s+(the\\s+)?(user|human|operator)\\b[^.]{0,60}/gi },\n { kind: \"model-directive\", pattern: /\\byou\\s+(must|should|are required to)\\s+(also\\s+)?(read|send|include|call|fetch)\\b[^.]{0,60}/gi },\n // Paths that only appear in a description when something wants their contents.\n { kind: \"credential-path\", pattern: /(~|\\$HOME|\\/home\\/[\\w.-]+|\\/Users\\/[\\w.-]+)?[/\\\\]?\\.(aws\\/credentials|ssh\\/id_[\\w]+|npmrc|netrc|git-credentials|kube\\/config|env)\\b/gi },\n { kind: \"credential-path\", pattern: /\\b(id_rsa|id_ed25519|authorized_keys|\\.pem|service-account\\.json)\\b/gi },\n { kind: \"exfiltration\", pattern: /\\b(send|post|upload|transmit|forward|exfiltrate)\\s+[^.]{0,40}\\bto\\s+(https?:\\/\\/|[\\w.-]+\\.[a-z]{2,})/gi },\n { kind: \"exfiltration\", pattern: /\\b(include|append|attach)\\s+(its|the|their)\\s+contents?\\b[^.]{0,60}/gi },\n // Characters that make text render as something other than what it is.\n { kind: \"hidden-text\", pattern: /[\\u200B-\\u200F\\u202A-\\u202E\\u2066-\\u2069\\uFEFF]+/g },\n];\n\n/** Signals in one piece of declared text. Empty is the overwhelmingly common answer. */\n/*\n * Confusable letters are folded before matching, for the same reason the capability classifier\n * folds them: `B\\u0435fore answering` reads as `Before answering` and matched nothing. The quote\n * shown to the reader is cut from the original text, so what they see is what the server sent.\n */\nconst CONFUSABLES: Record<string, string> = {\n \"\\u0430\": \"a\", \"\\u0435\": \"e\", \"\\u043E\": \"o\", \"\\u0441\": \"c\", \"\\u0440\": \"p\", \"\\u0445\": \"x\",\n \"\\u0443\": \"y\", \"\\u0456\": \"i\", \"\\u03BF\": \"o\", \"\\u03B1\": \"a\", \"\\u03B5\": \"e\", \"\\u03C1\": \"p\",\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\nfunction fold(text: string): string {\n return text.replace(CONFUSABLE_PATTERN, (character) => CONFUSABLES[character] ?? character);\n}\n\nexport function steeringSignals(text: string | undefined, field: string): SteeringSignal[] {\n if (!text) return [];\n const found: SteeringSignal[] = [];\n const seen = new Set<string>();\n /*\n * Matched against the folded copy, quoted from the original. Folding is one character for one\n * character, so the indices line up, and the reader is shown what the server actually sent --\n * including the substituted letter that made the pattern necessary.\n */\n const folded = fold(text);\n for (const { kind, pattern } of PATTERNS) {\n for (const match of folded.matchAll(pattern)) {\n const at = match.index ?? 0;\n const raw = text.slice(at, at + match[0].length).trim();\n if (raw.length === 0) continue;\n // Control characters have no readable quote; name them instead.\n const quote = /^[\\u200B-\\u200F\\u202A-\\u202E\\u2066-\\u2069\\uFEFF]+$/.test(raw)\n ? `${raw.length} invisible character(s)`\n : raw.length > 120\n ? `${raw.slice(0, 119)}…`\n : raw;\n const key = `${kind}\\u0000${quote}`;\n if (seen.has(key)) continue;\n seen.add(key);\n found.push({ kind, quote, field });\n }\n }\n return found;\n}\n","/**\n * Standing rules about what a server may be, as distinct from what changed.\n *\n * Every gate in this product until now has been a gate on movement: something differs from what\n * was approved, so the build fails. That cannot express the rule a security team actually writes\n * down, which is about a property rather than a delta -- *nothing in this repository may execute\n * processes* -- and a rule that can only be checked at the moment of change is not enforced on a\n * repository that never changes.\n *\n * Capability is the right thing to gate on and steering is not. A capability is derived from the\n * shape of the declaration: a `command` argument is a fact about the schema, and the same schema\n * yields the same answer for everyone. A steering signal is a regular expression over prose, and\n * a server documenting \"before using this tool, call authenticate first\" trips it. Gating on the\n * first is a policy; gating on the second is a coin toss that fails somebody's build.\n *\n * So this exists and the steering equivalent deliberately does not.\n */\nimport { toolCapabilities, type CapabilityKind, type CapabilitySeverity } from \"./capability\";\nimport type { Lockfile } from \"../lock/types\";\nimport { objectOr, objectsIn, stringOr } from \"./untrusted\";\n\nexport interface CapabilityViolation {\n server: string;\n tool: string;\n kind: CapabilityKind;\n severity: CapabilitySeverity;\n /** The argument or name the classification was made from, so the rule can be checked. */\n evidence: string;\n}\n\n/**\n * Every pinned tool whose capability the policy forbids.\n *\n * Checked against the surface as it is, not against the diff, so a repository whose servers have\n * not moved in a year still fails the day the rule is added. That is the point: the rule is about\n * the surface, and accepting drift cannot make a forbidden capability allowed.\n */\nexport function capabilityViolations(lock: Lockfile, denied: readonly CapabilityKind[] | undefined): CapabilityViolation[] {\n if (!denied || denied.length === 0) return [];\n const forbidden = new Set<string>(denied);\n const found: CapabilityViolation[] = [];\n\n for (const [server, subject] of Object.entries(lock?.subjects ?? {})) {\n for (const tool of objectsIn(objectOr(subject).tools)) {\n for (const capability of toolCapabilities(tool)) {\n if (!forbidden.has(capability.kind)) continue;\n found.push({ server, tool: stringOr(tool.name) ?? \"?\", kind: capability.kind, severity: capability.severity, evidence: capability.evidence });\n }\n }\n }\n\n return found.sort((a, b) => a.server.localeCompare(b.server) || a.tool.localeCompare(b.tool) || a.kind.localeCompare(b.kind));\n}\n","/**\n * Every string in a declared surface that a model is shown.\n *\n * The steering scan originally read a tool's `description` and the server's `instructions`, which\n * is 509 of the 2257 model-facing strings in a crawl of 56 published servers. The largest single\n * field was not among them: schema property descriptions, 1311 of them, which is how a model is\n * told what to put in a parameter and therefore text it acts on.\n *\n * Moving the same sentence from `description` into `properties.path.description` produced no\n * finding at all, so the check was one keystroke away from being decorative. Scanning a subset of\n * the places text reaches the model is not a weaker version of the control; against anybody who\n * reads the source it is none of it.\n */\n\nimport { objectsIn, stringOr } from \"./untrusted\";\n\nexport interface SurfaceText {\n /** Where it was found, precise enough to go and look: `read_file.inputSchema.path`. */\n field: string;\n text: string;\n}\n\n/*\n * Schemas are attacker-supplied, so the walk is bounded -- but not by depth. A depth ceiling is\n * itself an evasion window: text at one level below it still reaches the model, so a bound of 8\n * is an instruction to nest nine deep. The deepest description in a crawl of 56 published\n * servers sits at depth 4, and nothing legitimate needs hundreds of nodes beyond that.\n *\n * So the limit is total work instead, which nesting cannot buy its way around, and the walk is\n * iterative so that a schema nested a million deep is a budget that runs out rather than a stack\n * that overflows. `seen` stops a self-referencing schema from spending the whole budget on one\n * cycle.\n */\nconst MAX_NODES = 20_000;\n\nfunction schemaText(root: unknown, rootPath: string, out: SurfaceText[]): void {\n const stack: Array<{ node: unknown; path: string }> = [{ node: root, path: rootPath }];\n const seen = new WeakSet<object>();\n let budget = MAX_NODES;\n\n while (stack.length > 0 && budget-- > 0) {\n const { node, path } = stack.pop() as { node: unknown; path: string };\n if (typeof node !== \"object\" || node === null) continue;\n if (seen.has(node)) continue;\n seen.add(node);\n\n const schema = node as { description?: unknown; title?: unknown; properties?: unknown; items?: unknown };\n if (typeof schema.description === \"string\") out.push({ field: path, text: schema.description });\n if (typeof schema.title === \"string\") out.push({ field: `${path}.title`, text: schema.title });\n\n const properties = schema.properties;\n if (typeof properties === \"object\" && properties !== null) {\n for (const [name, child] of Object.entries(properties as Record<string, unknown>)) {\n stack.push({ node: child, path: `${path}.${name}` });\n }\n }\n if (schema.items !== undefined) stack.push({ node: schema.items, path: `${path}[]` });\n }\n}\n\ninterface Describable {\n name?: string;\n title?: string;\n description?: string;\n}\n\n/** Every model-facing string in one locked server, with the field it came from. */\nexport function surfaceText(subject: ({\n instructions?: string;\n tools?: ReadonlyArray<Describable & { inputSchema?: unknown; outputSchema?: unknown }>;\n prompts?: ReadonlyArray<Describable & { arguments?: ReadonlyArray<Describable> }>;\n resources?: ReadonlyArray<Describable & { uri?: string }>;\n resourceTemplates?: ReadonlyArray<Describable & { uriTemplate?: string }>;\n}) | null | undefined): SurfaceText[] {\n const out: SurfaceText[] = [];\n const push = (field: string, text: unknown): void => {\n if (typeof text === \"string\" && text.length > 0) out.push({ field, text });\n };\n\n push(\"instructions\", subject?.instructions);\n\n for (const tool of objectsIn(subject?.tools)) {\n const where = stringOr(tool.name) ?? \"?\";\n push(`${where}.title`, tool.title);\n push(`${where}.description`, tool.description);\n schemaText(tool.inputSchema, `${where}.inputSchema`, out);\n schemaText(tool.outputSchema, `${where}.outputSchema`, out);\n }\n\n for (const prompt of objectsIn(subject?.prompts)) {\n const where = stringOr(prompt.name) ?? \"?\";\n push(`prompt:${where}.title`, prompt.title);\n push(`prompt:${where}.description`, prompt.description);\n for (const argument of objectsIn(prompt.arguments)) {\n push(`prompt:${where}.${stringOr(argument.name) ?? \"?\"}`, argument.description);\n }\n }\n\n for (const resource of objectsIn(subject?.resources)) {\n const where = stringOr(resource.name) ?? stringOr(resource.uri) ?? \"?\";\n push(`resource:${where}.title`, resource.title);\n push(`resource:${where}.description`, resource.description);\n }\n\n for (const template of objectsIn(subject?.resourceTemplates)) {\n const where = stringOr(template.name) ?? stringOr(template.uriTemplate) ?? \"?\";\n push(`template:${where}.title`, template.title);\n push(`template:${where}.description`, template.description);\n }\n\n return out;\n}\n","/**\n * Text that started addressing the model since the surface was approved.\n *\n * The scan at pin time asks a person to read what they are about to approve. That covers the\n * surface as it was approved and nothing after it, which is the wrong half: the rug pull\n * (CVE-2025-54136) is defined by being clean at approval and changing afterwards. A server that\n * ships honest descriptions, gets pinned, and then rewrites one is the case the control exists\n * for, and it was the case the control did not see.\n *\n * `check` already fails on that change -- the text moved, so it is drift -- but it reported\n * `tool.description.changed` and left a reviewer to notice for themselves that the new text is\n * an instruction. Saying the text moved is not the same as saying what it now says.\n *\n * This is deliberately a difference and not a scan of the whole surface. Signals already present\n * when the lock was approved were shown at `init` and were accepted by somebody; repeating them\n * on every build is how a signal becomes noise that gets muted, and three of the three findings\n * across 56 published servers were benign prose. What is new is news.\n */\nimport type { Lockfile } from \"../lock/types\";\nimport { steeringSignals, type SteeringSignal } from \"./steering\";\nimport { surfaceText } from \"./surface-text\";\n\nexport interface ServerSteering {\n server: string;\n signals: SteeringSignal[];\n}\n\n/** Identity of a finding, so the same sentence in the same field is not reported as new. */\nfunction identity(signal: SteeringSignal): string {\n return `${signal.field}\\u0000${signal.kind}\\u0000${signal.quote}`;\n}\n\nfunction signalsFor(subject: unknown): SteeringSignal[] {\n if (typeof subject !== \"object\" || subject === null) return [];\n return surfaceText(subject as Parameters<typeof surfaceText>[0]).flatMap((piece) =>\n steeringSignals(piece.text, piece.field),\n );\n}\n\n/**\n * Signals in `observed` that were not in `committed`, per server.\n *\n * A server absent from the committed lock is entirely new, so everything it says is new.\n */\nexport function newSteering(committed: Lockfile, observed: Lockfile): ServerSteering[] {\n const found: ServerSteering[] = [];\n\n for (const [server, subject] of Object.entries(observed.subjects ?? {})) {\n const before = new Set(signalsFor(committed.subjects?.[server]).map(identity));\n const signals = signalsFor(subject).filter((signal) => !before.has(identity(signal)));\n if (signals.length > 0) found.push({ server, signals });\n }\n\n return found.sort((a, b) => a.server.localeCompare(b.server));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,IAAM,iBAAiB,CAAC,mBAAmB,mBAAmB,gBAAgB,aAAa;AAWlG,IAAM,WAA2D;AAAA;AAAA,EA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AI,WAAW,UAAU,WAAW,MAAM,CAAC,EAAE,IAAI,QAAQ,CAAC;AAC7E,UAAM,UAAU,WAAW,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,IAAI,SAAS,MAAM,CAAC,CAAC;AACpF,QAAI,QAAQ,SAAS,EAAG,OAAM,KAAK,EAAE,QAAQ,QAAQ,CAAC;AAAA,EACxD;AAEA,SAAO,MAAM,KAAK,CAAC,GAAG,MAAM,EAAE,OAAO,cAAc,EAAE,MAAM,CAAC;AAC9D;","names":[]}
@@ -1,4 +1,4 @@
1
- import { J as JsonValue } from '../types-DFETajK4.js';
1
+ import { J as JsonValue } from '../types-CU0za3Jw.js';
2
2
 
3
3
  /**
4
4
  * How deep a surface is allowed to be before we refuse to hash it.
@@ -1,4 +1,4 @@
1
- import { a as JsonObject, J as JsonValue } from '../types-DFETajK4.js';
1
+ import { a as JsonObject, J as JsonValue } from '../types-CU0za3Jw.js';
2
2
 
3
3
  /**
4
4
  * Just enough JSON Schema to see through the indirection servers actually use.
@@ -1,4 +1,4 @@
1
- import { J as JsonValue, b as LockedBehavior, c as LockedAnnotations, a as JsonObject } from '../types-DFETajK4.js';
1
+ import { J as JsonValue, b as LockedBehavior, c as LockedAnnotations, a as JsonObject } from '../types-CU0za3Jw.js';
2
2
 
3
3
  /**
4
4
  * Resolves the four behavioural annotations against the spec's defaults, which are not neutral:
@@ -1,4 +1,4 @@
1
- import { d as LockedSubject } from '../types-DFETajK4.js';
1
+ import { d as LockedSubject } from '../types-CU0za3Jw.js';
2
2
 
3
3
  /**
4
4
  * Resealing dispatches on what the subject is. One branch today; a kind added without a branch
@@ -1 +1 @@
1
- export { i as ClientKind, a as JsonObject, J as JsonValue, j as LOCKFILE_VERSION, k as LockPolicy, c as LockedAnnotations, b as LockedBehavior, l as LockedHttpTransport, m as LockedIcon, n as LockedMcpServer, o as LockedMember, p as LockedPrompt, q as LockedPromptArgument, r as LockedProtocol, s as LockedResource, t as LockedResourceTemplate, u as LockedServerInfo, v as LockedSource, w as LockedStdioTransport, d as LockedSubject, x as LockedSubjectBase, y as LockedTool, z as LockedTransport, L as Lockfile, S as SUBJECT_KINDS, A as SubjectKind } from '../types-DFETajK4.js';
1
+ export { i as ClientKind, a as JsonObject, J as JsonValue, j as LOCKFILE_VERSION, k as LockPolicy, c as LockedAnnotations, b as LockedBehavior, l as LockedHttpTransport, m as LockedIcon, n as LockedMcpServer, o as LockedMember, p as LockedPrompt, q as LockedPromptArgument, r as LockedProtocol, s as LockedResource, t as LockedResourceTemplate, u as LockedServerInfo, v as LockedSource, w as LockedStdioTransport, d as LockedSubject, x as LockedSubjectBase, y as LockedTool, z as LockedTransport, L as Lockfile, S as SUBJECT_KINDS, A as SubjectKind } from '../types-CU0za3Jw.js';
@@ -15,7 +15,6 @@
15
15
  * stored, so sharpening a pattern re-reads existing locks instead of showing every user a wave
16
16
  * of drift that no server caused.
17
17
  */
18
- /** Ordered worst-first; the order is the comparison. */
19
18
  declare const CAPABILITY_SEVERITIES: readonly ["critical", "high", "medium", "low"];
20
19
  type CapabilitySeverity = (typeof CAPABILITY_SEVERITIES)[number];
21
20
  declare const CAPABILITY_KINDS: readonly ["process-exec", "code-eval", "credential-access", "file-write", "network-egress", "database", "privilege", "agent-control", "env-access", "file-read"];
@@ -33,12 +32,12 @@ interface Capability {
33
32
  declare function toolCapabilities(tool: {
34
33
  name?: string;
35
34
  inputSchema?: unknown;
36
- }): Capability[];
35
+ } | null | undefined): Capability[];
37
36
  /** Every capability a set of tools declares between them, with the tools that declare each. */
38
37
  declare function surfaceCapabilities(tools: ReadonlyArray<{
39
38
  name?: string;
40
39
  inputSchema?: unknown;
41
- }>): Array<Capability & {
40
+ }> | null | undefined): Array<Capability & {
42
41
  tools: string[];
43
42
  }>;
44
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nulladrift/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "The lockfile model and the drift engine, shared by the collector and the control plane.",
6
6
  "exports": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/risk/capability.ts","../src/diff/index.ts"],"sourcesContent":["/**\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. */\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: \"file-write\", severity: \"high\", name: /(^|_)(write|create_file|put_file|save|delete|remove|unlink|rename|move|copy|chmod|mkdir|rmdir|edit)(_|$)/, arg: /(^|_)(contents|content|data|destination|dest_path|target_path)(_|$)/ },\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 { kind: \"file-read\", severity: \"low\", name: /(^|_)(read|read_file|cat|open|load|list_directory|ls|glob|search_files)(_|$)/, arg: /(^|_)(path|file|filename|filepath|directory|dir)(_|$)/ },\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 * Depth is bounded because a schema is attacker-supplied and need not terminate.\n */\nfunction argumentNames(inputSchema: unknown, depth = 0): string[] {\n if (depth > 6 || typeof inputSchema !== \"object\" || inputSchema === null) return [];\n const node = inputSchema as { properties?: unknown; items?: unknown };\n const names: string[] = [];\n const properties = node.properties;\n if (typeof properties === \"object\" && properties !== null) {\n for (const [name, child] of Object.entries(properties as Record<string, unknown>)) {\n names.push(name);\n names.push(...argumentNames(child, depth + 1));\n }\n }\n if (node.items !== undefined) names.push(...argumentNames(node.items, depth + 1));\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 }): Capability[] {\n const name = normalize(tool.name ?? \"\");\n const args = argumentNames(tool.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\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(tools: ReadonlyArray<{ name?: string; inputSchema?: unknown }>): Array<Capability & { tools: string[] }> {\n const byKind = new Map<CapabilityKind, Capability & { tools: string[] }>();\n for (const tool of tools) {\n for (const capability of toolCapabilities(tool)) {\n const existing = byKind.get(capability.kind);\n if (existing) existing.tools.push(tool.name ?? \"?\");\n else byKind.set(capability.kind, { ...capability, tools: [tool.name ?? \"?\"] });\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\nfunction indexBy<T>(members: T[] | undefined, key: (member: T) => string): Map<string, T> {\n return new Map((members ?? []).map((member) => [key(member), member]));\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 = indexBy(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 const had = new Set(toolCapabilities(existing).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`. If none of\n * them fired, something in that remainder moved, and silence would be worse than a vague\n * finding.\n */\n if (changes.length === 0) {\n changes.push(change(\"tool.changed\", name, \"tool definition changed (title, icons or _meta)\", { ...at, before, after }));\n }\n return changes;\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 = indexBy(before, spec.key);\n const next = indexBy(after, spec.key);\n\n for (const [key, member] of next) {\n const existing = previous.get(key);\n if (!existing) {\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 continue;\n }\n if (existing.digest === member.digest) continue;\n changes.push(...(deep ? deep(key, existing, member) : [change(spec.changed, name, `${spec.noun} ${spec.label(member)} changed`, { member: spec.label(member), before: existing, after: member })]));\n }\n for (const [key, member] of previous) {\n if (!next.has(key)) 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\nfunction compareServer(name: string, before: LockedMcpServer, after: LockedMcpServer): Change[] {\n if (before.digest === after.digest) return [];\n const changes: Change[] = [];\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 return changes;\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 */\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 = before.subjects[oldName];\n if (!oldEntry) continue;\n const match = availableAdds.find((newName) => {\n const candidate = after.subjects[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 }\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 = after.subjects[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: before.subjects[name] }));\n }\n for (const name of afterNames) {\n const a = before.subjects[name];\n const b = after.subjects[name];\n if (!a || !b) continue;\n changes.push(...compareServer(name, a, b));\n }\n\n return sortChanges(changes);\n}\n"],"mappings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