@nulladrift/core 0.1.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/dist/changes.d.ts +53 -0
  3. package/dist/changes.js +17 -0
  4. package/dist/changes.js.map +1 -0
  5. package/dist/chunk-3LIIW7B5.js +9 -0
  6. package/dist/chunk-3LIIW7B5.js.map +1 -0
  7. package/dist/chunk-42ZE5O5I.js +125 -0
  8. package/dist/chunk-42ZE5O5I.js.map +1 -0
  9. package/dist/chunk-ALHOTOM6.js +1 -0
  10. package/dist/chunk-ALHOTOM6.js.map +1 -0
  11. package/dist/chunk-DGEHI25T.js +46 -0
  12. package/dist/chunk-DGEHI25T.js.map +1 -0
  13. package/dist/chunk-DL6LTPYY.js +83 -0
  14. package/dist/chunk-DL6LTPYY.js.map +1 -0
  15. package/dist/chunk-DZHB25AC.js +237 -0
  16. package/dist/chunk-DZHB25AC.js.map +1 -0
  17. package/dist/chunk-GG2RYE4R.js +91 -0
  18. package/dist/chunk-GG2RYE4R.js.map +1 -0
  19. package/dist/chunk-HLTEHLNF.js +66 -0
  20. package/dist/chunk-HLTEHLNF.js.map +1 -0
  21. package/dist/chunk-SUY3NGZP.js +87 -0
  22. package/dist/chunk-SUY3NGZP.js.map +1 -0
  23. package/dist/diff/index.d.ts +6 -0
  24. package/dist/diff/index.js +13 -0
  25. package/dist/diff/index.js.map +1 -0
  26. package/dist/diff/schema.d.ts +6 -0
  27. package/dist/diff/schema.js +9 -0
  28. package/dist/diff/schema.js.map +1 -0
  29. package/dist/diff/types.d.ts +1 -0
  30. package/dist/diff/types.js +18 -0
  31. package/dist/diff/types.js.map +1 -0
  32. package/dist/index.d.ts +7 -0
  33. package/dist/index.js +65 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/lock/canonical.d.ts +52 -0
  36. package/dist/lock/canonical.js +17 -0
  37. package/dist/lock/canonical.js.map +1 -0
  38. package/dist/lock/jsonschema.d.ts +39 -0
  39. package/dist/lock/jsonschema.js +19 -0
  40. package/dist/lock/jsonschema.js.map +1 -0
  41. package/dist/lock/normalize.d.ts +44 -0
  42. package/dist/lock/normalize.js +18 -0
  43. package/dist/lock/normalize.js.map +1 -0
  44. package/dist/lock/reseal.d.ts +10 -0
  45. package/dist/lock/reseal.js +8 -0
  46. package/dist/lock/reseal.js.map +1 -0
  47. package/dist/lock/types.d.ts +178 -0
  48. package/dist/lock/types.js +9 -0
  49. package/dist/lock/types.js.map +1 -0
  50. package/package.json +60 -0
@@ -0,0 +1,237 @@
1
+ import {
2
+ classifySchemaChange
3
+ } from "./chunk-42ZE5O5I.js";
4
+ import {
5
+ SEVERITY,
6
+ sortChanges
7
+ } from "./chunk-GG2RYE4R.js";
8
+ import {
9
+ stableKey
10
+ } from "./chunk-HLTEHLNF.js";
11
+ import {
12
+ isEscalation
13
+ } from "./chunk-DL6LTPYY.js";
14
+
15
+ // src/diff/index.ts
16
+ function change(kind, server, summary, extra) {
17
+ return { kind, severity: SEVERITY[kind], server, summary, ...extra };
18
+ }
19
+ function same(a, b) {
20
+ return stableKey(a ?? null) === stableKey(b ?? null);
21
+ }
22
+ function indexBy(members, key) {
23
+ return new Map((members ?? []).map((member) => [key(member), member]));
24
+ }
25
+ function declaredNames(capabilities) {
26
+ const names = [];
27
+ for (const [key, value] of Object.entries(capabilities ?? {})) {
28
+ if (key === "extensions" && value !== null && typeof value === "object" && !Array.isArray(value)) {
29
+ for (const id of Object.keys(value)) names.push(`extensions/${id}`);
30
+ continue;
31
+ }
32
+ names.push(key);
33
+ }
34
+ return names;
35
+ }
36
+ function compareCapabilities(before, after, name) {
37
+ if (same(before.capabilities, after.capabilities)) return [];
38
+ const previous = declaredNames(before.capabilities);
39
+ const next = declaredNames(after.capabilities);
40
+ const gained = next.filter((key) => !previous.includes(key));
41
+ const lost = previous.filter((key) => !next.includes(key));
42
+ if (gained.length > 0 && lost.length === 0) {
43
+ return [change("server.capabilities.widened", name, `server now declares ${gained.join(", ")}`, { before: before.capabilities, after: after.capabilities })];
44
+ }
45
+ if (lost.length > 0 && gained.length === 0) {
46
+ return [change("server.capabilities.narrowed", name, `server no longer declares ${lost.join(", ")}`, { before: before.capabilities, after: after.capabilities })];
47
+ }
48
+ return [change("server.capabilities.changed", name, "declared capabilities changed", { before: before.capabilities, after: after.capabilities })];
49
+ }
50
+ function compareTool(name, before, after) {
51
+ if (before.digest === after.digest) return [];
52
+ const changes = [];
53
+ const at = { member: before.name };
54
+ if (!same(before.description, after.description)) {
55
+ changes.push(
56
+ change("tool.description.changed", name, `description changed (${before.description?.length ?? 0} \u2192 ${after.description?.length ?? 0} characters)`, {
57
+ ...at,
58
+ before: before.description,
59
+ after: after.description
60
+ })
61
+ );
62
+ }
63
+ const inputVerdict = classifySchemaChange(before.inputSchema, after.inputSchema);
64
+ if (inputVerdict !== "same") {
65
+ const kind = `tool.input_schema.${inputVerdict}`;
66
+ const wording = inputVerdict === "widened" ? "accepts input it did not before" : inputVerdict === "narrowed" ? "accepts less input than before" : "input schema changed";
67
+ changes.push(change(kind, name, wording, { ...at, before: before.inputSchema, after: after.inputSchema }));
68
+ }
69
+ if (!same(before.outputSchema, after.outputSchema)) {
70
+ changes.push(change("tool.output_schema.changed", name, "output schema changed", { ...at, before: before.outputSchema, after: after.outputSchema }));
71
+ }
72
+ if (!same(before.behavior, after.behavior)) {
73
+ const escalated = isEscalation(before.behavior, after.behavior);
74
+ changes.push(
75
+ change(escalated ? "tool.behavior.escalated" : "tool.behavior.relaxed", name, escalated ? describeEscalation(before, after) : "declares fewer powers than before", {
76
+ ...at,
77
+ before: before.behavior,
78
+ after: after.behavior
79
+ })
80
+ );
81
+ }
82
+ if (!same(before.headerParams, after.headerParams)) {
83
+ changes.push(
84
+ change("tool.header_params.changed", name, "arguments mirrored into HTTP headers changed", { ...at, before: before.headerParams ?? [], after: after.headerParams ?? [] })
85
+ );
86
+ }
87
+ if (changes.length === 0) {
88
+ changes.push(change("tool.changed", name, "tool definition changed (title, icons or _meta)", { ...at, before, after }));
89
+ }
90
+ return changes;
91
+ }
92
+ function describeEscalation(before, after) {
93
+ const gained = [];
94
+ if (before.behavior.readOnly && !after.behavior.readOnly) gained.push("may now modify");
95
+ if (!before.behavior.destructive && after.behavior.destructive) gained.push("may now destroy");
96
+ if (before.behavior.idempotent && !after.behavior.idempotent) gained.push("repeat calls now compound");
97
+ if (!before.behavior.openWorld && after.behavior.openWorld) gained.push("may now reach external systems");
98
+ return gained.join("; ");
99
+ }
100
+ function compareMembers(name, before, after, spec, deep) {
101
+ const changes = [];
102
+ const previous = indexBy(before, spec.key);
103
+ const next = indexBy(after, spec.key);
104
+ for (const [key, member] of next) {
105
+ const existing = previous.get(key);
106
+ if (!existing) {
107
+ changes.push(change(spec.added, name, `new ${spec.noun} ${spec.label(member)}`, { member: spec.label(member), after: member }));
108
+ continue;
109
+ }
110
+ if (existing.digest === member.digest) continue;
111
+ 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 })]);
112
+ }
113
+ for (const [key, member] of previous) {
114
+ if (!next.has(key)) changes.push(change(spec.removed, name, `${spec.noun} ${spec.label(member)} is gone`, { member: spec.label(member), before: member }));
115
+ }
116
+ return changes;
117
+ }
118
+ function compareServer(name, before, after) {
119
+ if (before.digest === after.digest) return [];
120
+ const changes = [];
121
+ if (!same(before.transport, after.transport)) {
122
+ changes.push(change("server.transport.changed", name, "the server is reached differently than when it was pinned", { before: before.transport, after: after.transport }));
123
+ }
124
+ if (!same(before.serverInfo, after.serverInfo)) {
125
+ const from = before.serverInfo?.version ?? "unknown";
126
+ const to = after.serverInfo?.version ?? "unknown";
127
+ changes.push(change("server.identity.changed", name, `server identity changed (version ${from} \u2192 ${to})`, { before: before.serverInfo, after: after.serverInfo }));
128
+ }
129
+ if (!same(before.protocol, after.protocol)) {
130
+ changes.push(
131
+ change("server.protocol.changed", name, `protocol changed (${before.protocol.era}/${before.protocol.version} \u2192 ${after.protocol.era}/${after.protocol.version})`, {
132
+ before: before.protocol,
133
+ after: after.protocol
134
+ })
135
+ );
136
+ }
137
+ if (!same(before.instructions, after.instructions)) {
138
+ changes.push(
139
+ change("server.instructions.changed", name, "server instructions changed: this text goes into the model's system prompt", {
140
+ before: before.instructions,
141
+ after: after.instructions
142
+ })
143
+ );
144
+ }
145
+ changes.push(...compareCapabilities(before, after, name));
146
+ changes.push(
147
+ ...compareMembers(
148
+ name,
149
+ before.tools,
150
+ after.tools,
151
+ { key: (t) => t.name, label: (t) => t.name, added: "tool.added", removed: "tool.removed", changed: "tool.changed", noun: "tool" },
152
+ (_key, a, b) => compareTool(name, a, b)
153
+ )
154
+ );
155
+ changes.push(
156
+ ...compareMembers(name, before.resources, after.resources, {
157
+ key: (r) => r.uri,
158
+ label: (r) => `${r.name} (${r.uri})`,
159
+ added: "resource.added",
160
+ removed: "resource.removed",
161
+ changed: "resource.changed",
162
+ noun: "resource"
163
+ })
164
+ );
165
+ changes.push(
166
+ ...compareMembers(name, before.resourceTemplates, after.resourceTemplates, {
167
+ key: (t) => t.uriTemplate,
168
+ // The template itself is the capability -- widening it from file:///project/{path} to
169
+ // file:///{path} is the whole finding -- so it belongs in the label, not just the body.
170
+ label: (t) => `${t.name} (${t.uriTemplate})`,
171
+ added: "resource_template.added",
172
+ removed: "resource_template.removed",
173
+ changed: "resource_template.changed",
174
+ noun: "resource template"
175
+ })
176
+ );
177
+ changes.push(
178
+ ...compareMembers(name, before.prompts, after.prompts, {
179
+ key: (p) => p.name,
180
+ label: (p) => p.name,
181
+ added: "prompt.added",
182
+ removed: "prompt.removed",
183
+ changed: "prompt.changed",
184
+ noun: "prompt"
185
+ })
186
+ );
187
+ return changes;
188
+ }
189
+ function detectRenames(before, after, removed, added) {
190
+ const changes = [];
191
+ const renamed = /* @__PURE__ */ new Set();
192
+ const availableAdds = [...added];
193
+ for (const oldName of removed) {
194
+ const oldEntry = before.subjects[oldName];
195
+ if (!oldEntry) continue;
196
+ const match = availableAdds.find((newName) => {
197
+ const candidate = after.subjects[newName];
198
+ return candidate !== void 0 && candidate.digest === oldEntry.digest && same(candidate.transport, oldEntry.transport);
199
+ });
200
+ if (!match) continue;
201
+ availableAdds.splice(availableAdds.indexOf(match), 1);
202
+ renamed.add(oldName);
203
+ renamed.add(match);
204
+ changes.push(change("server.renamed", match, `renamed from "${oldName}"; capabilities are unchanged`, { before: oldName, after: match }));
205
+ }
206
+ return { changes, renamed };
207
+ }
208
+ function diffLockfiles(before, after) {
209
+ const beforeNames = Object.keys(before.subjects);
210
+ const afterNames = Object.keys(after.subjects);
211
+ const removed = beforeNames.filter((name) => !afterNames.includes(name));
212
+ const added = afterNames.filter((name) => !beforeNames.includes(name));
213
+ const { changes: renameChanges, renamed } = detectRenames(before, after, removed, added);
214
+ const changes = [...renameChanges];
215
+ for (const name of added) {
216
+ if (renamed.has(name)) continue;
217
+ const entry = after.subjects[name];
218
+ const toolCount = entry?.tools?.length ?? 0;
219
+ changes.push(change("server.added", name, `new server with ${toolCount} tool${toolCount === 1 ? "" : "s"}`, { after: entry }));
220
+ }
221
+ for (const name of removed) {
222
+ if (renamed.has(name)) continue;
223
+ changes.push(change("server.removed", name, "server is no longer configured", { before: before.subjects[name] }));
224
+ }
225
+ for (const name of afterNames) {
226
+ const a = before.subjects[name];
227
+ const b = after.subjects[name];
228
+ if (!a || !b) continue;
229
+ changes.push(...compareServer(name, a, b));
230
+ }
231
+ return sortChanges(changes);
232
+ }
233
+
234
+ export {
235
+ diffLockfiles
236
+ };
237
+ //# sourceMappingURL=chunk-DZHB25AC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/diff/index.ts"],"sourcesContent":["/** 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 { classifySchemaChange } from \"./schema\";\nimport type { Change, ChangeKind } 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\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}\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 changes.push(change(spec.added, name, `new ${spec.noun} ${spec.label(member)}`, { member: spec.label(member), after: member }));\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, { key: (t) => t.name, label: (t) => t.name, added: \"tool.added\", removed: \"tool.removed\", changed: \"tool.changed\", noun: \"tool\" }, (_key, a, b) =>\n compareTool(name, a, b),\n ),\n );\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":";;;;;;;;;;;;;;;AAeA,SAAS,OAAO,MAAkB,QAAgB,SAAiB,OAAiC;AAClG,SAAO,EAAE,MAAM,UAAU,SAAS,IAAI,GAAG,QAAQ,SAAS,GAAG,MAAM;AAC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C7C,QAAM,UAAU,YAAY,OAAO,CAAC,SAAS,CAAC,WAAW,SAAS,IAAI,CAAC;AACvE,QAAM,QAAQ,WAAW,OAAO,CAAC,SAAS,CAAC,YAAY,SAAS,IAAI,CAAC;AAErE,QAAM,EAAE,SAAS,eAAe,QAAQ,IAAI,cAAc,QAAQ,OAAO,SAAS,KAAK;AACvF,QAAM,UAAoB,CAAC,GAAG,aAAa;AAE3C,aAAW,QAAQ,OAAO;AACxB,QAAI,QAAQ,IAAI,IAAI,EAAG;AACvB,UAAM,QAAQ,MAAM,SAAS,IAAI;AACjC,UAAM,YAAY,OAAO,OAAO,UAAU;AAC1C,YAAQ,KAAK,OAAO,gBAAgB,MAAM,mBAAmB,SAAS,QAAQ,cAAc,IAAI,KAAK,GAAG,IAAI,EAAE,OAAO,MAAM,CAAC,CAAC;AAAA,EAC/H;AACA,aAAW,QAAQ,SAAS;AAC1B,QAAI,QAAQ,IAAI,IAAI,EAAG;AACvB,YAAQ,KAAK,OAAO,kBAAkB,MAAM,kCAAkC,EAAE,QAAQ,OAAO,SAAS,IAAI,EAAE,CAAC,CAAC;AAAA,EAClH;AACA,aAAW,QAAQ,YAAY;AAC7B,UAAM,IAAI,OAAO,SAAS,IAAI;AAC9B,UAAM,IAAI,MAAM,SAAS,IAAI;AAC7B,QAAI,CAAC,KAAK,CAAC,EAAG;AACd,YAAQ,KAAK,GAAG,cAAc,MAAM,GAAG,CAAC,CAAC;AAAA,EAC3C;AAEA,SAAO,YAAY,OAAO;AAC5B;","names":[]}
@@ -0,0 +1,91 @@
1
+ // src/changes.ts
2
+ var CHANGE_KINDS = [
3
+ "server.added",
4
+ "server.removed",
5
+ "server.renamed",
6
+ "server.transport.changed",
7
+ "server.identity.changed",
8
+ "server.protocol.changed",
9
+ "server.instructions.changed",
10
+ "server.capabilities.widened",
11
+ "server.capabilities.narrowed",
12
+ "server.capabilities.changed",
13
+ "tool.added",
14
+ "tool.removed",
15
+ "tool.description.changed",
16
+ "tool.input_schema.widened",
17
+ "tool.input_schema.narrowed",
18
+ "tool.input_schema.changed",
19
+ "tool.output_schema.changed",
20
+ "tool.behavior.escalated",
21
+ "tool.behavior.relaxed",
22
+ "tool.header_params.changed",
23
+ "tool.changed",
24
+ "resource.added",
25
+ "resource.removed",
26
+ "resource.changed",
27
+ "resource_template.added",
28
+ "resource_template.removed",
29
+ "resource_template.changed",
30
+ "prompt.added",
31
+ "prompt.removed",
32
+ "prompt.changed"
33
+ ];
34
+ var SEVERITIES = ["high", "medium", "low"];
35
+ var SEVERITY = {
36
+ "server.added": "medium",
37
+ "server.removed": "low",
38
+ "server.renamed": "low",
39
+ "server.transport.changed": "high",
40
+ "server.identity.changed": "medium",
41
+ "server.protocol.changed": "medium",
42
+ "server.instructions.changed": "high",
43
+ "server.capabilities.widened": "medium",
44
+ "server.capabilities.narrowed": "low",
45
+ "server.capabilities.changed": "medium",
46
+ "tool.added": "high",
47
+ "tool.removed": "low",
48
+ "tool.description.changed": "high",
49
+ "tool.input_schema.widened": "high",
50
+ "tool.input_schema.narrowed": "low",
51
+ "tool.input_schema.changed": "medium",
52
+ "tool.output_schema.changed": "medium",
53
+ "tool.behavior.escalated": "high",
54
+ "tool.behavior.relaxed": "low",
55
+ "tool.header_params.changed": "high",
56
+ "tool.changed": "medium",
57
+ "resource.added": "medium",
58
+ "resource.removed": "low",
59
+ "resource.changed": "medium",
60
+ "resource_template.added": "high",
61
+ "resource_template.removed": "low",
62
+ "resource_template.changed": "high",
63
+ "prompt.added": "medium",
64
+ "prompt.removed": "low",
65
+ "prompt.changed": "medium"
66
+ };
67
+ var SEVERITY_RANK = { high: 0, medium: 1, low: 2 };
68
+ function sortChanges(changes) {
69
+ return [...changes].sort(
70
+ (a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] || a.server.localeCompare(b.server) || (a.member ?? "").localeCompare(b.member ?? "") || a.kind.localeCompare(b.kind)
71
+ );
72
+ }
73
+ function serversThatShippedNothing(changes) {
74
+ const moved = /* @__PURE__ */ new Set();
75
+ const versioned = /* @__PURE__ */ new Set();
76
+ for (const change of changes) {
77
+ moved.add(change.server);
78
+ if (change.kind === "server.identity.changed") versioned.add(change.server);
79
+ }
80
+ return [...moved].filter((server) => !versioned.has(server)).sort();
81
+ }
82
+
83
+ export {
84
+ CHANGE_KINDS,
85
+ SEVERITIES,
86
+ SEVERITY,
87
+ SEVERITY_RANK,
88
+ sortChanges,
89
+ serversThatShippedNothing
90
+ };
91
+ //# sourceMappingURL=chunk-GG2RYE4R.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/changes.ts"],"sourcesContent":["/**\n * The change taxonomy: the one vocabulary the collector, the API, the dashboard and every\n * customer's SARIF consumer share.\n *\n * It lives here rather than in the CLI because it is a contract across process boundaries. A\n * collector on an old version reports a kind the server has to understand, and a renamed kind\n * breaks a SARIF rule id somebody has already suppressed. Renaming one is a major version.\n */\n\nexport const CHANGE_KINDS = [\n \"server.added\",\n \"server.removed\",\n \"server.renamed\",\n \"server.transport.changed\",\n \"server.identity.changed\",\n \"server.protocol.changed\",\n \"server.instructions.changed\",\n \"server.capabilities.widened\",\n \"server.capabilities.narrowed\",\n \"server.capabilities.changed\",\n \"tool.added\",\n \"tool.removed\",\n \"tool.description.changed\",\n \"tool.input_schema.widened\",\n \"tool.input_schema.narrowed\",\n \"tool.input_schema.changed\",\n \"tool.output_schema.changed\",\n \"tool.behavior.escalated\",\n \"tool.behavior.relaxed\",\n \"tool.header_params.changed\",\n \"tool.changed\",\n \"resource.added\",\n \"resource.removed\",\n \"resource.changed\",\n \"resource_template.added\",\n \"resource_template.removed\",\n \"resource_template.changed\",\n \"prompt.added\",\n \"prompt.removed\",\n \"prompt.changed\",\n] as const;\n\nexport type ChangeKind = (typeof CHANGE_KINDS)[number];\n\n/**\n * Ranking only. Every kind is drift; severity decides what a reviewer reads first, what SARIF\n * level an AppSec tool shows, and which changes a policy can be set to block. \"high\" is reserved\n * for shapes an attacker would use -- text that reaches the model, a widened input, a new power --\n * so that it keeps meaning something.\n */\nexport const SEVERITIES = [\"high\", \"medium\", \"low\"] as const;\nexport type Severity = (typeof SEVERITIES)[number];\n\nexport const SEVERITY: Record<ChangeKind, Severity> = {\n \"server.added\": \"medium\",\n \"server.removed\": \"low\",\n \"server.renamed\": \"low\",\n \"server.transport.changed\": \"high\",\n \"server.identity.changed\": \"medium\",\n \"server.protocol.changed\": \"medium\",\n \"server.instructions.changed\": \"high\",\n \"server.capabilities.widened\": \"medium\",\n \"server.capabilities.narrowed\": \"low\",\n \"server.capabilities.changed\": \"medium\",\n \"tool.added\": \"high\",\n \"tool.removed\": \"low\",\n \"tool.description.changed\": \"high\",\n \"tool.input_schema.widened\": \"high\",\n \"tool.input_schema.narrowed\": \"low\",\n \"tool.input_schema.changed\": \"medium\",\n \"tool.output_schema.changed\": \"medium\",\n \"tool.behavior.escalated\": \"high\",\n \"tool.behavior.relaxed\": \"low\",\n \"tool.header_params.changed\": \"high\",\n \"tool.changed\": \"medium\",\n \"resource.added\": \"medium\",\n \"resource.removed\": \"low\",\n \"resource.changed\": \"medium\",\n \"resource_template.added\": \"high\",\n \"resource_template.removed\": \"low\",\n \"resource_template.changed\": \"high\",\n \"prompt.added\": \"medium\",\n \"prompt.removed\": \"low\",\n \"prompt.changed\": \"medium\",\n};\n\nexport const SEVERITY_RANK: Record<Severity, number> = { high: 0, medium: 1, low: 2 };\n\n/** One change, as the collector reports it and as the dashboard renders it. */\nexport interface Change {\n kind: ChangeKind;\n severity: Severity;\n /** Name of the server in the lock. */\n server: string;\n /** Tool, resource, template or prompt name, where the change is scoped to one. */\n member?: string;\n /** One line, written for a reviewer who has not read the lockfile. */\n summary: string;\n before?: unknown;\n after?: unknown;\n}\n\nexport function sortChanges(changes: Change[]): Change[] {\n return [...changes].sort(\n (a, b) =>\n SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] ||\n a.server.localeCompare(b.server) ||\n (a.member ?? \"\").localeCompare(b.member ?? \"\") ||\n a.kind.localeCompare(b.kind),\n );\n}\n\n/**\n * Which servers moved without shipping anything.\n *\n * A surface that changes alongside a version bump is a release: somebody published something,\n * and the change is attributable to it. A surface that changes while the version stays exactly\n * where it was is the opposite, and it is the shape this product exists for: the same package,\n * the same version, a different set of instructions reaching the model.\n *\n * Both halves are already recorded. `server.identity.changed` carries the version move, so the\n * signal is the *absence* of one beside other changes, and a reviewer currently has to notice a\n * thing that is not there. This names it so a report can say it out loud.\n *\n * It lives beside the taxonomy rather than in the engine because it reasons about a list of\n * changes and nothing else: the dashboard asks the same question and has no business depending\n * on a diff engine to do it.\n */\nexport function serversThatShippedNothing(changes: readonly Change[]): string[] {\n const moved = new Set<string>();\n const versioned = new Set<string>();\n for (const change of changes) {\n moved.add(change.server);\n if (change.kind === \"server.identity.changed\") versioned.add(change.server);\n }\n return [...moved].filter((server) => !versioned.has(server)).sort();\n}\n"],"mappings":";AASO,IAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAUO,IAAM,aAAa,CAAC,QAAQ,UAAU,KAAK;AAG3C,IAAM,WAAyC;AAAA,EACpD,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,4BAA4B;AAAA,EAC5B,2BAA2B;AAAA,EAC3B,2BAA2B;AAAA,EAC3B,+BAA+B;AAAA,EAC/B,+BAA+B;AAAA,EAC/B,gCAAgC;AAAA,EAChC,+BAA+B;AAAA,EAC/B,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,4BAA4B;AAAA,EAC5B,6BAA6B;AAAA,EAC7B,8BAA8B;AAAA,EAC9B,6BAA6B;AAAA,EAC7B,8BAA8B;AAAA,EAC9B,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,8BAA8B;AAAA,EAC9B,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,kBAAkB;AACpB;AAEO,IAAM,gBAA0C,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,EAAE;AAgB7E,SAAS,YAAY,SAA6B;AACvD,SAAO,CAAC,GAAG,OAAO,EAAE;AAAA,IAClB,CAAC,GAAG,MACF,cAAc,EAAE,QAAQ,IAAI,cAAc,EAAE,QAAQ,KACpD,EAAE,OAAO,cAAc,EAAE,MAAM,MAC9B,EAAE,UAAU,IAAI,cAAc,EAAE,UAAU,EAAE,KAC7C,EAAE,KAAK,cAAc,EAAE,IAAI;AAAA,EAC/B;AACF;AAkBO,SAAS,0BAA0B,SAAsC;AAC9E,QAAM,QAAQ,oBAAI,IAAY;AAC9B,QAAM,YAAY,oBAAI,IAAY;AAClC,aAAW,UAAU,SAAS;AAC5B,UAAM,IAAI,OAAO,MAAM;AACvB,QAAI,OAAO,SAAS,0BAA2B,WAAU,IAAI,OAAO,MAAM;AAAA,EAC5E;AACA,SAAO,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,UAAU,IAAI,MAAM,CAAC,EAAE,KAAK;AACpE;","names":[]}
@@ -0,0 +1,66 @@
1
+ // src/lock/canonical.ts
2
+ import { createHash } from "crypto";
3
+ var MAX_DEPTH = 100;
4
+ var tooDeep = () => new TypeError(`cannot canonicalize JSON nested deeper than ${MAX_DEPTH} levels; this is not a surface we can hash`);
5
+ function canonicalize(value, depth = 0) {
6
+ if (depth > MAX_DEPTH) throw tooDeep();
7
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
8
+ return JSON.stringify(value);
9
+ }
10
+ if (value === void 0) {
11
+ throw new TypeError("cannot canonicalize undefined; pass the value through toJson first");
12
+ }
13
+ if (typeof value === "number") {
14
+ if (!Number.isFinite(value)) throw new TypeError(`cannot canonicalize non-finite number: ${value}`);
15
+ return JSON.stringify(value === 0 ? 0 : value);
16
+ }
17
+ if (Array.isArray(value)) {
18
+ return `[${value.map((member) => canonicalize(member, depth + 1)).join(",")}]`;
19
+ }
20
+ const keys = Object.keys(value).sort();
21
+ const members = keys.map((key) => `${JSON.stringify(key)}:${canonicalize(value[key], depth + 1)}`);
22
+ return `{${members.join(",")}}`;
23
+ }
24
+ function exceedsMaxDepth(value) {
25
+ const pending = [{ node: value, depth: 0 }];
26
+ while (pending.length > 0) {
27
+ const next = pending.pop();
28
+ if (next === void 0) break;
29
+ if (next.depth > MAX_DEPTH) return true;
30
+ if (next.node === null || typeof next.node !== "object") continue;
31
+ const members = Array.isArray(next.node) ? next.node : Object.values(next.node);
32
+ for (const member of members) pending.push({ node: member, depth: next.depth + 1 });
33
+ }
34
+ return false;
35
+ }
36
+ function digest(value) {
37
+ return `sha256:${createHash("sha256").update(canonicalize(value), "utf8").digest("hex")}`;
38
+ }
39
+ function toJson(value, depth = 0) {
40
+ if (depth > MAX_DEPTH) throw tooDeep();
41
+ if (value === null) return null;
42
+ if (Array.isArray(value)) return value.map((member) => toJson(member, depth + 1));
43
+ if (typeof value === "object") {
44
+ const out = {};
45
+ for (const [key, member] of Object.entries(value)) {
46
+ if (member === void 0) continue;
47
+ out[key] = toJson(member, depth + 1);
48
+ }
49
+ return out;
50
+ }
51
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") return value;
52
+ return null;
53
+ }
54
+ function stableKey(value) {
55
+ return canonicalize(toJson(value));
56
+ }
57
+
58
+ export {
59
+ MAX_DEPTH,
60
+ canonicalize,
61
+ exceedsMaxDepth,
62
+ digest,
63
+ toJson,
64
+ stableKey
65
+ };
66
+ //# sourceMappingURL=chunk-HLTEHLNF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lock/canonical.ts"],"sourcesContent":["/**\n * RFC 8785 (JSON Canonicalization Scheme) and the digests built on it.\n *\n * JCS rather than a scheme of our own: the hard parts -- key ordering, string escaping, number\n * formatting -- are already specified, so a second implementation can reproduce our digests from\n * the RFC alone rather than from our source.\n *\n * This is separate from how the lockfile is laid out on disk (see io.ts). Hashing sorts every\n * key; the file keeps a declared, readable order. One is for machines, the other for reviewers.\n */\nimport { createHash } from \"node:crypto\";\nimport type { JsonValue } from \"./types\";\n\n/**\n * How deep a surface is allowed to be before we refuse to hash it.\n *\n * Both functions below walk their argument with ordinary recursion, and both are handed JSON\n * that came from somewhere we do not control: a third-party MCP server answering the collector,\n * or a reading posted to the control plane. V8 parses deeply nested JSON iteratively, so a body\n * that nests further than the call stack reaches arrives intact and the overflow happens here.\n * At 16 MB, the ingest allowance, that costs an attacker about a hundred kilobytes.\n *\n * Neither caller breaks when it happens -- the collector reports the server unreachable and the\n * control plane answers 500 -- but both report a stack overflow, which describes our\n * implementation rather than their input. A bound makes it a fact about the input, and a limit\n * the caller can act on.\n *\n * A hundred is far above any real surface. A tool's input schema is JSON Schema, and the\n * elaborate ones nest tens of levels, not hundreds.\n */\nexport const MAX_DEPTH = 100;\n\nconst tooDeep = () =>\n new TypeError(`cannot canonicalize JSON nested deeper than ${MAX_DEPTH} levels; this is not a surface we can hash`);\n\n/**\n * JCS sorts object members by the UTF-16 code units of their keys, which is exactly what\n * `Array.prototype.sort` does by default. Numbers go through `JSON.stringify`, whose output\n * for finite numbers is the ES6 Number-to-String the RFC requires.\n */\nexport function canonicalize(value: JsonValue, depth = 0): string {\n if (depth > MAX_DEPTH) throw tooDeep();\n if (value === null || typeof value === \"boolean\" || typeof value === \"string\") {\n return JSON.stringify(value);\n }\n if (value === undefined) {\n // JSON has no undefined. Reaching here means a caller skipped `toJson`, which would\n // otherwise surface much later as a digest that silently disagrees with itself.\n throw new TypeError(\"cannot canonicalize undefined; pass the value through toJson first\");\n }\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) throw new TypeError(`cannot canonicalize non-finite number: ${value}`);\n // `-0` serializes as `0`, matching the RFC.\n return JSON.stringify(value === 0 ? 0 : value);\n }\n if (Array.isArray(value)) {\n // `map(canonicalize)` would hand the callback the array index as the second argument, which\n // is now the depth. Passing it explicitly is the whole reason this is not point-free.\n return `[${value.map((member) => canonicalize(member, depth + 1)).join(\",\")}]`;\n }\n const keys = Object.keys(value).sort();\n const members = keys.map((key) => `${JSON.stringify(key)}:${canonicalize(value[key] as JsonValue, depth + 1)}`);\n return `{${members.join(\",\")}}`;\n}\n\n/**\n * Whether a value is too deep to hash, answered without recursing.\n *\n * Deliberately iterative: a guard against stack exhaustion that walks the value recursively\n * exhausts the stack on exactly the input it exists to catch. An explicit stack moves the\n * problem to the heap, where the body-size limit already bounds it.\n *\n * This is for request validation, so that a reading too deep to hash is refused at the edge\n * with a message naming the field, rather than hashed and refused as an internal error.\n */\nexport function exceedsMaxDepth(value: unknown): boolean {\n const pending: Array<{ node: unknown; depth: number }> = [{ node: value, depth: 0 }];\n while (pending.length > 0) {\n const next = pending.pop();\n if (next === undefined) break;\n if (next.depth > MAX_DEPTH) return true;\n if (next.node === null || typeof next.node !== \"object\") continue;\n const members = Array.isArray(next.node) ? next.node : Object.values(next.node);\n for (const member of members) pending.push({ node: member, depth: next.depth + 1 });\n }\n return false;\n}\n\nexport function digest(value: JsonValue): string {\n return `sha256:${createHash(\"sha256\").update(canonicalize(value), \"utf8\").digest(\"hex\")}`;\n}\n\n/**\n * Drops `undefined` members so that an absent optional field and a field explicitly set to\n * `undefined` hash identically. Without this, building the same tool through two code paths could\n * produce two digests for one capability.\n */\nexport function toJson(value: unknown, depth = 0): JsonValue {\n // Bounded for the same reason `canonicalize` is, and it matters more here: `digest` and\n // `stableKey` both run this first, so this is where an oversized surface lands.\n if (depth > MAX_DEPTH) throw tooDeep();\n if (value === null) return null;\n // Not `map(toJson)`: that would pass the array index as the depth.\n if (Array.isArray(value)) return value.map((member) => toJson(member, depth + 1));\n if (typeof value === \"object\") {\n const out: Record<string, JsonValue> = {};\n for (const [key, member] of Object.entries(value as Record<string, unknown>)) {\n if (member === undefined) continue;\n out[key] = toJson(member, depth + 1);\n }\n return out;\n }\n if (typeof value === \"number\" || typeof value === \"string\" || typeof value === \"boolean\") return value;\n // Functions, symbols and bigints cannot reach here from parsed JSON; treat as absent.\n return null;\n}\n\n/**\n * Canonical form of a value that may carry `undefined` members -- an in-memory lock entry, say,\n * where optional fields are present but unset. Comparing two of those directly is the common\n * case in the diff engine, and it must agree with the digest of the same value.\n */\nexport function stableKey(value: unknown): string {\n return canonicalize(toJson(value));\n}\n"],"mappings":";AAUA,SAAS,kBAAkB;AAoBpB,IAAM,YAAY;AAEzB,IAAM,UAAU,MACd,IAAI,UAAU,+CAA+C,SAAS,4CAA4C;AAO7G,SAAS,aAAa,OAAkB,QAAQ,GAAW;AAChE,MAAI,QAAQ,UAAW,OAAM,QAAQ;AACrC,MAAI,UAAU,QAAQ,OAAO,UAAU,aAAa,OAAO,UAAU,UAAU;AAC7E,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AACA,MAAI,UAAU,QAAW;AAGvB,UAAM,IAAI,UAAU,oEAAoE;AAAA,EAC1F;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,CAAC,OAAO,SAAS,KAAK,EAAG,OAAM,IAAI,UAAU,0CAA0C,KAAK,EAAE;AAElG,WAAO,KAAK,UAAU,UAAU,IAAI,IAAI,KAAK;AAAA,EAC/C;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AAGxB,WAAO,IAAI,MAAM,IAAI,CAAC,WAAW,aAAa,QAAQ,QAAQ,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC;AAAA,EAC7E;AACA,QAAM,OAAO,OAAO,KAAK,KAAK,EAAE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,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,QAAO;AAEjG,SAAO;AACT;AAOO,SAAS,UAAU,OAAwB;AAChD,SAAO,aAAa,OAAO,KAAK,CAAC;AACnC;","names":[]}
@@ -0,0 +1,87 @@
1
+ // src/lock/jsonschema.ts
2
+ var MAX_REF_DEPTH = 32;
3
+ var MAX_VISIT_DEPTH = 12;
4
+ var MAX_FACTS = 5e3;
5
+ function asObject(value) {
6
+ return value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value) ? value : void 0;
7
+ }
8
+ function decodeToken(token) {
9
+ let decoded = token;
10
+ try {
11
+ decoded = decodeURIComponent(token);
12
+ } catch {
13
+ }
14
+ return decoded.replace(/~1/g, "/").replace(/~0/g, "~");
15
+ }
16
+ function resolvePointer(root, ref) {
17
+ if (!ref.startsWith("#")) return void 0;
18
+ const pointer = ref.slice(1);
19
+ if (pointer !== "" && !pointer.startsWith("/")) return void 0;
20
+ let node = root;
21
+ for (const token of pointer.split("/").slice(1)) {
22
+ const object = asObject(node);
23
+ if (object === void 0) return void 0;
24
+ node = object[decodeToken(token)];
25
+ }
26
+ return node;
27
+ }
28
+ function effectiveSchema(node, root, seenRefs = /* @__PURE__ */ new Set(), depth = 0) {
29
+ const object = asObject(node);
30
+ if (object === void 0) return void 0;
31
+ if (depth > MAX_REF_DEPTH) return object;
32
+ const out = {};
33
+ const merge = (source) => {
34
+ for (const [key, value] of Object.entries(source)) {
35
+ if (key === "$ref" || key === "allOf") continue;
36
+ if (key === "properties") {
37
+ const merged = { ...asObject(out["properties"]) ?? {} };
38
+ for (const [name, schema] of Object.entries(asObject(value) ?? {})) {
39
+ if (!(name in merged)) merged[name] = schema;
40
+ }
41
+ out["properties"] = merged;
42
+ } else if (key === "required" && Array.isArray(value)) {
43
+ const already = Array.isArray(out["required"]) ? out["required"] : [];
44
+ out["required"] = [...new Set([...already, ...value].filter((entry) => typeof entry === "string"))];
45
+ } else if (!(key in out)) {
46
+ out[key] = value;
47
+ }
48
+ }
49
+ };
50
+ merge(object);
51
+ const ref = object["$ref"];
52
+ if (typeof ref === "string" && !seenRefs.has(ref)) {
53
+ const resolved = effectiveSchema(resolvePointer(root, ref), root, /* @__PURE__ */ new Set([...seenRefs, ref]), depth + 1);
54
+ if (resolved) merge(resolved);
55
+ }
56
+ const allOf = object["allOf"];
57
+ if (Array.isArray(allOf)) {
58
+ for (const branch of allOf) {
59
+ const resolved = effectiveSchema(branch, root, seenRefs, depth + 1);
60
+ if (resolved) merge(resolved);
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+ function alternatives(object) {
66
+ const branches = [];
67
+ for (const keyword of ["anyOf", "oneOf"]) {
68
+ const value = object[keyword];
69
+ if (!Array.isArray(value)) continue;
70
+ value.forEach((schema, index) => branches.push({ label: `${keyword}[${index}]`, schema }));
71
+ }
72
+ for (const keyword of ["then", "else", "not"]) {
73
+ if (object[keyword] !== void 0) branches.push({ label: keyword, schema: object[keyword] });
74
+ }
75
+ return branches;
76
+ }
77
+
78
+ export {
79
+ MAX_REF_DEPTH,
80
+ MAX_VISIT_DEPTH,
81
+ MAX_FACTS,
82
+ asObject,
83
+ resolvePointer,
84
+ effectiveSchema,
85
+ alternatives
86
+ };
87
+ //# sourceMappingURL=chunk-SUY3NGZP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lock/jsonschema.ts"],"sourcesContent":["/**\n * Just enough JSON Schema to see through the indirection servers actually use.\n *\n * Two parts of this tool have to look inside a tool's `inputSchema`: the widening heuristic and\n * the `x-mcp-header` scan. Both used to read only the literal node in front of them, so a schema\n * that put its properties behind `$ref` or `allOf` -- which the generators for Pydantic, Zod and\n * most OpenAPI toolchains do by default -- looked empty to both. A widened parameter went out as\n * a bare `.changed`, and a parameter newly mirrored into an HTTP header was missed entirely.\n *\n * This is not a validator. It resolves local `$ref`, flattens `allOf`, and leaves the\n * alternation keywords for the caller to branch on. Remote `$ref` is never fetched: an audit\n * that reaches out to a URL named by the thing it is auditing is not an audit.\n */\nimport type { JsonObject, JsonValue } from \"./types\";\n\n/** Depth caps. A hostile or merely recursive schema must not be able to hang the run. */\nexport const MAX_REF_DEPTH = 32;\nexport const MAX_VISIT_DEPTH = 12;\nexport const MAX_FACTS = 5_000;\n\nexport function asObject(value: JsonValue | undefined): JsonObject | undefined {\n return value !== null && value !== undefined && typeof value === \"object\" && !Array.isArray(value) ? (value as JsonObject) : undefined;\n}\n\n/** RFC 6901 token decoding: `~1` is `/` and `~0` is `~`, in that order. */\nfunction decodeToken(token: string): string {\n let decoded = token;\n try {\n decoded = decodeURIComponent(token);\n } catch {\n // A malformed escape is a literal, not a reason to abandon the schema.\n }\n return decoded.replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n}\n\n/** Resolves a local JSON pointer. Anything with a non-empty URI part is left unresolved. */\nexport function resolvePointer(root: JsonValue, ref: string): JsonValue | undefined {\n if (!ref.startsWith(\"#\")) return undefined;\n const pointer = ref.slice(1);\n if (pointer !== \"\" && !pointer.startsWith(\"/\")) return undefined; // `#anchor`, which needs an anchor index.\n\n let node: JsonValue | undefined = root;\n for (const token of pointer.split(\"/\").slice(1)) {\n const object = asObject(node);\n if (object === undefined) return undefined;\n node = object[decodeToken(token)];\n }\n return node;\n}\n\n/**\n * The keywords in effect at a node, with `$ref` followed and `allOf` folded in.\n *\n * The node's own keywords win over anything it inherits, `properties` are unioned, and\n * `required` is the union of every contributor -- which is what `allOf` means. Alternation\n * (`anyOf` / `oneOf` / `then` / `else`) is deliberately left in place: a caller that wants to\n * treat branches as separate possibilities can, and one that does not is no worse off.\n */\nexport function effectiveSchema(node: JsonValue | undefined, root: JsonValue, seenRefs: ReadonlySet<string> = new Set(), depth = 0): JsonObject | undefined {\n const object = asObject(node);\n if (object === undefined) return undefined;\n if (depth > MAX_REF_DEPTH) return object;\n\n const out: JsonObject = {};\n const merge = (source: JsonObject): void => {\n for (const [key, value] of Object.entries(source)) {\n if (key === \"$ref\" || key === \"allOf\") continue;\n if (key === \"properties\") {\n // First contributor wins on a conflict, and keeps its position: the merged object reads\n // in the order a person wrote it, not inside-out from the inheritance chain.\n const merged: JsonObject = { ...(asObject(out[\"properties\"]) ?? {}) };\n for (const [name, schema] of Object.entries(asObject(value) ?? {})) {\n if (!(name in merged)) merged[name] = schema;\n }\n out[\"properties\"] = merged;\n } else if (key === \"required\" && Array.isArray(value)) {\n const already = Array.isArray(out[\"required\"]) ? (out[\"required\"] as JsonValue[]) : [];\n out[\"required\"] = [...new Set([...already, ...value].filter((entry): entry is string => typeof entry === \"string\"))];\n } else if (!(key in out)) {\n out[key] = value;\n }\n }\n };\n\n // The node itself first, so its own keywords take precedence over what it inherits.\n merge(object);\n\n const ref = object[\"$ref\"];\n if (typeof ref === \"string\" && !seenRefs.has(ref)) {\n const resolved = effectiveSchema(resolvePointer(root, ref), root, new Set([...seenRefs, ref]), depth + 1);\n if (resolved) merge(resolved);\n }\n\n const allOf = object[\"allOf\"];\n if (Array.isArray(allOf)) {\n for (const branch of allOf) {\n const resolved = effectiveSchema(branch, root, seenRefs, depth + 1);\n if (resolved) merge(resolved);\n }\n }\n\n return out;\n}\n\n/** The alternation branches at a node, labelled so a caller can key facts by them. */\nexport function alternatives(object: JsonObject): Array<{ label: string; schema: JsonValue }> {\n const branches: Array<{ label: string; schema: JsonValue }> = [];\n for (const keyword of [\"anyOf\", \"oneOf\"] as const) {\n const value = object[keyword];\n if (!Array.isArray(value)) continue;\n value.forEach((schema, index) => branches.push({ label: `${keyword}[${index}]`, schema }));\n }\n for (const keyword of [\"then\", \"else\", \"not\"] as const) {\n if (object[keyword] !== undefined) branches.push({ label: keyword, schema: object[keyword] as JsonValue });\n }\n return branches;\n}\n"],"mappings":";AAgBO,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;AACxB,IAAM,YAAY;AAElB,SAAS,SAAS,OAAsD;AAC7E,SAAO,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAK,QA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AO,OAAO,EAAe,CAAC;AAAA,EAC3G;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,6 @@
1
+ import { Lockfile } from '../lock/types.js';
2
+ import { Change } from '../changes.js';
3
+
4
+ declare function diffLockfiles(before: Lockfile, after: Lockfile): Change[];
5
+
6
+ export { diffLockfiles };
@@ -0,0 +1,13 @@
1
+ import {
2
+ diffLockfiles
3
+ } from "../chunk-DZHB25AC.js";
4
+ import "../chunk-42ZE5O5I.js";
5
+ import "../chunk-ALHOTOM6.js";
6
+ import "../chunk-GG2RYE4R.js";
7
+ import "../chunk-HLTEHLNF.js";
8
+ import "../chunk-DL6LTPYY.js";
9
+ import "../chunk-SUY3NGZP.js";
10
+ export {
11
+ diffLockfiles
12
+ };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,6 @@
1
+ import { JsonValue } from '../lock/types.js';
2
+
3
+ type SchemaVerdict = "widened" | "narrowed" | "changed" | "same";
4
+ declare function classifySchemaChange(before: JsonValue, after: JsonValue): SchemaVerdict;
5
+
6
+ export { type SchemaVerdict, classifySchemaChange };
@@ -0,0 +1,9 @@
1
+ import {
2
+ classifySchemaChange
3
+ } from "../chunk-42ZE5O5I.js";
4
+ import "../chunk-HLTEHLNF.js";
5
+ import "../chunk-SUY3NGZP.js";
6
+ export {
7
+ classifySchemaChange
8
+ };
9
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ export { CHANGE_KINDS, Change, ChangeKind, SEVERITIES, SEVERITY, SEVERITY_RANK, Severity, serversThatShippedNothing, sortChanges } from '../changes.js';