@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.
- package/LICENSE +21 -0
- package/dist/changes.d.ts +53 -0
- package/dist/changes.js +17 -0
- package/dist/changes.js.map +1 -0
- package/dist/chunk-3LIIW7B5.js +9 -0
- package/dist/chunk-3LIIW7B5.js.map +1 -0
- package/dist/chunk-42ZE5O5I.js +125 -0
- package/dist/chunk-42ZE5O5I.js.map +1 -0
- package/dist/chunk-ALHOTOM6.js +1 -0
- package/dist/chunk-ALHOTOM6.js.map +1 -0
- package/dist/chunk-DGEHI25T.js +46 -0
- package/dist/chunk-DGEHI25T.js.map +1 -0
- package/dist/chunk-DL6LTPYY.js +83 -0
- package/dist/chunk-DL6LTPYY.js.map +1 -0
- package/dist/chunk-DZHB25AC.js +237 -0
- package/dist/chunk-DZHB25AC.js.map +1 -0
- package/dist/chunk-GG2RYE4R.js +91 -0
- package/dist/chunk-GG2RYE4R.js.map +1 -0
- package/dist/chunk-HLTEHLNF.js +66 -0
- package/dist/chunk-HLTEHLNF.js.map +1 -0
- package/dist/chunk-SUY3NGZP.js +87 -0
- package/dist/chunk-SUY3NGZP.js.map +1 -0
- package/dist/diff/index.d.ts +6 -0
- package/dist/diff/index.js +13 -0
- package/dist/diff/index.js.map +1 -0
- package/dist/diff/schema.d.ts +6 -0
- package/dist/diff/schema.js +9 -0
- package/dist/diff/schema.js.map +1 -0
- package/dist/diff/types.d.ts +1 -0
- package/dist/diff/types.js +18 -0
- package/dist/diff/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/lock/canonical.d.ts +52 -0
- package/dist/lock/canonical.js +17 -0
- package/dist/lock/canonical.js.map +1 -0
- package/dist/lock/jsonschema.d.ts +39 -0
- package/dist/lock/jsonschema.js +19 -0
- package/dist/lock/jsonschema.js.map +1 -0
- package/dist/lock/normalize.d.ts +44 -0
- package/dist/lock/normalize.js +18 -0
- package/dist/lock/normalize.js.map +1 -0
- package/dist/lock/reseal.d.ts +10 -0
- package/dist/lock/reseal.js +8 -0
- package/dist/lock/reseal.js.map +1 -0
- package/dist/lock/types.d.ts +178 -0
- package/dist/lock/types.js +9 -0
- package/dist/lock/types.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nulladrift
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The change taxonomy: the one vocabulary the collector, the API, the dashboard and every
|
|
3
|
+
* customer's SARIF consumer share.
|
|
4
|
+
*
|
|
5
|
+
* It lives here rather than in the CLI because it is a contract across process boundaries. A
|
|
6
|
+
* collector on an old version reports a kind the server has to understand, and a renamed kind
|
|
7
|
+
* breaks a SARIF rule id somebody has already suppressed. Renaming one is a major version.
|
|
8
|
+
*/
|
|
9
|
+
declare const CHANGE_KINDS: readonly ["server.added", "server.removed", "server.renamed", "server.transport.changed", "server.identity.changed", "server.protocol.changed", "server.instructions.changed", "server.capabilities.widened", "server.capabilities.narrowed", "server.capabilities.changed", "tool.added", "tool.removed", "tool.description.changed", "tool.input_schema.widened", "tool.input_schema.narrowed", "tool.input_schema.changed", "tool.output_schema.changed", "tool.behavior.escalated", "tool.behavior.relaxed", "tool.header_params.changed", "tool.changed", "resource.added", "resource.removed", "resource.changed", "resource_template.added", "resource_template.removed", "resource_template.changed", "prompt.added", "prompt.removed", "prompt.changed"];
|
|
10
|
+
type ChangeKind = (typeof CHANGE_KINDS)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Ranking only. Every kind is drift; severity decides what a reviewer reads first, what SARIF
|
|
13
|
+
* level an AppSec tool shows, and which changes a policy can be set to block. "high" is reserved
|
|
14
|
+
* for shapes an attacker would use -- text that reaches the model, a widened input, a new power --
|
|
15
|
+
* so that it keeps meaning something.
|
|
16
|
+
*/
|
|
17
|
+
declare const SEVERITIES: readonly ["high", "medium", "low"];
|
|
18
|
+
type Severity = (typeof SEVERITIES)[number];
|
|
19
|
+
declare const SEVERITY: Record<ChangeKind, Severity>;
|
|
20
|
+
declare const SEVERITY_RANK: Record<Severity, number>;
|
|
21
|
+
/** One change, as the collector reports it and as the dashboard renders it. */
|
|
22
|
+
interface Change {
|
|
23
|
+
kind: ChangeKind;
|
|
24
|
+
severity: Severity;
|
|
25
|
+
/** Name of the server in the lock. */
|
|
26
|
+
server: string;
|
|
27
|
+
/** Tool, resource, template or prompt name, where the change is scoped to one. */
|
|
28
|
+
member?: string;
|
|
29
|
+
/** One line, written for a reviewer who has not read the lockfile. */
|
|
30
|
+
summary: string;
|
|
31
|
+
before?: unknown;
|
|
32
|
+
after?: unknown;
|
|
33
|
+
}
|
|
34
|
+
declare function sortChanges(changes: Change[]): Change[];
|
|
35
|
+
/**
|
|
36
|
+
* Which servers moved without shipping anything.
|
|
37
|
+
*
|
|
38
|
+
* A surface that changes alongside a version bump is a release: somebody published something,
|
|
39
|
+
* and the change is attributable to it. A surface that changes while the version stays exactly
|
|
40
|
+
* where it was is the opposite, and it is the shape this product exists for: the same package,
|
|
41
|
+
* the same version, a different set of instructions reaching the model.
|
|
42
|
+
*
|
|
43
|
+
* Both halves are already recorded. `server.identity.changed` carries the version move, so the
|
|
44
|
+
* signal is the *absence* of one beside other changes, and a reviewer currently has to notice a
|
|
45
|
+
* thing that is not there. This names it so a report can say it out loud.
|
|
46
|
+
*
|
|
47
|
+
* It lives beside the taxonomy rather than in the engine because it reasons about a list of
|
|
48
|
+
* changes and nothing else: the dashboard asks the same question and has no business depending
|
|
49
|
+
* on a diff engine to do it.
|
|
50
|
+
*/
|
|
51
|
+
declare function serversThatShippedNothing(changes: readonly Change[]): string[];
|
|
52
|
+
|
|
53
|
+
export { CHANGE_KINDS, type Change, type ChangeKind, SEVERITIES, SEVERITY, SEVERITY_RANK, type Severity, serversThatShippedNothing, sortChanges };
|
package/dist/changes.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHANGE_KINDS,
|
|
3
|
+
SEVERITIES,
|
|
4
|
+
SEVERITY,
|
|
5
|
+
SEVERITY_RANK,
|
|
6
|
+
serversThatShippedNothing,
|
|
7
|
+
sortChanges
|
|
8
|
+
} from "./chunk-GG2RYE4R.js";
|
|
9
|
+
export {
|
|
10
|
+
CHANGE_KINDS,
|
|
11
|
+
SEVERITIES,
|
|
12
|
+
SEVERITY,
|
|
13
|
+
SEVERITY_RANK,
|
|
14
|
+
serversThatShippedNothing,
|
|
15
|
+
sortChanges
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lock/types.ts"],"sourcesContent":["/** The shape of `mcp.lock`. Mirrors schema/mcp.lock.schema.json, which is the published contract. */\n\n/**\n * Bumped to 2 when the root stopped naming a protocol.\n *\n * Version 1 keyed everything under `servers`, which made the format MCP's rather than the\n * product's: an agent's grants, an OpenAPI surface or a token's scopes had nowhere to live\n * without a second root key and a second diff path. Version 2 keys them all under `subjects`,\n * each tagged with what it is.\n *\n * A version 1 file is upgraded on read rather than refused, and the upgrade is lossless:\n * `kind` is not part of any digest (see `reseal.ts`, which covers an explicit field list), so\n * an upgraded lock reseals to exactly the digests it arrived with and nobody sees drift that\n * is really a format change.\n */\nexport const LOCKFILE_VERSION = 2;\n\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };\nexport type JsonObject = { [key: string]: JsonValue };\n\nexport interface Lockfile {\n lockfileVersion: number;\n generatedBy?: string;\n policy?: LockPolicy;\n /**\n * Everything this project has pinned, keyed by identity. One map rather than a key per kind,\n * so adding a kind is a new member of `LockedSubject` and not a new branch in every consumer.\n */\n subjects: Record<string, LockedSubject>;\n}\n\n/**\n * What a pinned thing is.\n *\n * The list is short because only one reader exists. The point of naming it at all is that the\n * diff engine, the policy evaluator and the audit log already do not care which one they are\n * looking at, so the cost of the second is a reader and a vocabulary rather than a redesign.\n */\nexport const SUBJECT_KINDS = [\"mcp-server\"] as const;\nexport type SubjectKind = (typeof SUBJECT_KINDS)[number];\n\nexport interface LockPolicy {\n /** Reverse-DNS `_meta` key prefixes to leave out, for servers that put build ids there. */\n ignoreMetaPrefixes?: string[];\n allowUnreachable?: boolean;\n}\n\nexport type ClientKind =\n | \"claude-code\"\n | \"claude-desktop\"\n | \"vscode\"\n | \"cursor\"\n | \"copilot\"\n | \"windsurf\"\n | \"generic\"\n | \"manual\";\n\nexport interface LockedSource {\n client: ClientKind;\n /** Repo-relative where possible, else with the home directory written as `~`. Never an absolute machine path. */\n file: string;\n scope?: \"project\" | \"user\" | \"local\";\n}\n\nexport interface LockedStdioTransport {\n type: \"stdio\";\n command: string;\n args?: string[];\n /** Names only. The lock is committed; the values are credentials. */\n envKeys?: string[];\n cwd?: string;\n}\n\nexport interface LockedHttpTransport {\n type: \"http\" | \"sse\";\n /** Query string removed: query strings routinely carry tokens. */\n url: string;\n headerKeys?: string[];\n}\n\nexport type LockedTransport = LockedStdioTransport | LockedHttpTransport;\n\nexport interface LockedProtocol {\n era: \"modern\" | \"legacy\";\n version: string;\n supportedVersions?: string[];\n}\n\nexport interface LockedServerInfo {\n name?: string;\n title?: string;\n version?: string;\n description?: string;\n websiteUrl?: string;\n}\n\nexport interface LockedAnnotations {\n title?: string;\n readOnlyHint?: boolean;\n destructiveHint?: boolean;\n idempotentHint?: boolean;\n openWorldHint?: boolean;\n}\n\n/** Annotations resolved against the spec's defaults. See docs/lockfile.md §4. */\nexport interface LockedBehavior {\n readOnly: boolean;\n destructive: boolean;\n idempotent: boolean;\n openWorld: boolean;\n}\n\nexport interface LockedIcon {\n src: string;\n mimeType?: string;\n sizes?: string[];\n theme?: \"light\" | \"dark\";\n}\n\nexport interface LockedTool {\n name: string;\n title?: string;\n description?: string;\n inputSchema: JsonObject;\n outputSchema?: JsonObject;\n annotations?: LockedAnnotations;\n behavior: LockedBehavior;\n /** `propertyPath -> HeaderName`, sorted. Derived from `x-mcp-header`. */\n headerParams?: string[];\n icons?: LockedIcon[];\n meta?: JsonObject;\n digest: string;\n}\n\nexport interface LockedResource {\n uri: string;\n name: string;\n title?: string;\n description?: string;\n mimeType?: string;\n annotations?: JsonObject;\n icons?: LockedIcon[];\n meta?: JsonObject;\n digest: string;\n}\n\nexport interface LockedResourceTemplate {\n uriTemplate: string;\n name: string;\n title?: string;\n description?: string;\n mimeType?: string;\n annotations?: JsonObject;\n icons?: LockedIcon[];\n meta?: JsonObject;\n digest: string;\n}\n\nexport interface LockedPromptArgument {\n name: string;\n title?: string;\n description?: string;\n required?: boolean;\n}\n\nexport interface LockedPrompt {\n name: string;\n title?: string;\n description?: string;\n arguments?: LockedPromptArgument[];\n icons?: LockedIcon[];\n meta?: JsonObject;\n digest: string;\n}\n\n/** What every pinned thing carries, whatever it is. */\nexport interface LockedSubjectBase {\n kind: SubjectKind;\n source: LockedSource;\n digest: string;\n}\n\n/** An MCP server's declared capability surface. The first subject kind, and so far the only one. */\nexport interface LockedMcpServer extends LockedSubjectBase {\n kind: \"mcp-server\";\n transport: LockedTransport;\n protocol: LockedProtocol;\n serverInfo?: LockedServerInfo;\n capabilities?: JsonObject;\n instructions?: string;\n tools?: LockedTool[];\n resources?: LockedResource[];\n resourceTemplates?: LockedResourceTemplate[];\n prompts?: LockedPrompt[];\n}\n\n/**\n * A union of one, deliberately. An agent's grants or an OpenAPI surface joins here, and every\n * consumer that switches on `kind` gets a compiler error pointing at the branch it is missing.\n */\nexport type LockedSubject = LockedMcpServer;\n\n/** Anything in the lock that carries its own digest and is matched by a stable key. */\nexport type LockedMember = LockedTool | LockedResource | LockedResourceTemplate | LockedPrompt;\n"],"mappings":";AAeO,IAAM,mBAAmB;AAuBzB,IAAM,gBAAgB,CAAC,YAAY;","names":[]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalize,
|
|
3
|
+
stableKey
|
|
4
|
+
} from "./chunk-HLTEHLNF.js";
|
|
5
|
+
import {
|
|
6
|
+
MAX_FACTS,
|
|
7
|
+
MAX_VISIT_DEPTH,
|
|
8
|
+
alternatives,
|
|
9
|
+
asObject,
|
|
10
|
+
effectiveSchema
|
|
11
|
+
} from "./chunk-SUY3NGZP.js";
|
|
12
|
+
|
|
13
|
+
// src/diff/schema.ts
|
|
14
|
+
function numberAt(node, key) {
|
|
15
|
+
const value = node[key];
|
|
16
|
+
return typeof value === "number" ? value : void 0;
|
|
17
|
+
}
|
|
18
|
+
function collectFacts(schema) {
|
|
19
|
+
const facts = /* @__PURE__ */ new Map();
|
|
20
|
+
const visit = (node, path, required, depth) => {
|
|
21
|
+
if (depth > MAX_VISIT_DEPTH || facts.size >= MAX_FACTS) return;
|
|
22
|
+
const object = effectiveSchema(node, schema);
|
|
23
|
+
if (!object) return;
|
|
24
|
+
const typeValue = object["type"];
|
|
25
|
+
const types = typeof typeValue === "string" ? [typeValue] : Array.isArray(typeValue) ? typeValue.filter((entry) => typeof entry === "string").sort() : void 0;
|
|
26
|
+
const enumValue = object["enum"];
|
|
27
|
+
facts.set(path, {
|
|
28
|
+
required,
|
|
29
|
+
additionalProperties: typeof object["additionalProperties"] === "boolean" ? object["additionalProperties"] : void 0,
|
|
30
|
+
enumMembers: Array.isArray(enumValue) ? enumValue.map((entry) => canonicalize(entry)).sort() : void 0,
|
|
31
|
+
types,
|
|
32
|
+
minimum: numberAt(object, "minimum"),
|
|
33
|
+
maximum: numberAt(object, "maximum"),
|
|
34
|
+
minLength: numberAt(object, "minLength"),
|
|
35
|
+
maxLength: numberAt(object, "maxLength")
|
|
36
|
+
});
|
|
37
|
+
const properties = asObject(object["properties"]);
|
|
38
|
+
if (properties) {
|
|
39
|
+
const requiredList = Array.isArray(object["required"]) ? object["required"].filter((entry) => typeof entry === "string") : [];
|
|
40
|
+
for (const [name, child] of Object.entries(properties)) {
|
|
41
|
+
visit(child, path === "" ? name : `${path}.${name}`, requiredList.includes(name), depth + 1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const items = object["items"];
|
|
45
|
+
if (items !== void 0) visit(items, `${path}[]`, false, depth + 1);
|
|
46
|
+
const prefixItems = object["prefixItems"];
|
|
47
|
+
if (Array.isArray(prefixItems)) prefixItems.forEach((entry, index) => visit(entry, `${path}[${index}]`, false, depth + 1));
|
|
48
|
+
for (const branch of alternatives(object)) visit(branch.schema, `${path}|${branch.label}`, false, depth + 1);
|
|
49
|
+
};
|
|
50
|
+
visit(schema, "", true, 0);
|
|
51
|
+
return facts;
|
|
52
|
+
}
|
|
53
|
+
function isSuperset(next, previous) {
|
|
54
|
+
return previous.every((entry) => next.includes(entry));
|
|
55
|
+
}
|
|
56
|
+
function classifySchemaChange(before, after) {
|
|
57
|
+
if (stableKey(before) === stableKey(after)) return "same";
|
|
58
|
+
const previous = collectFacts(before);
|
|
59
|
+
const next = collectFacts(after);
|
|
60
|
+
let widened = false;
|
|
61
|
+
let narrowed = false;
|
|
62
|
+
for (const path of /* @__PURE__ */ new Set([...previous.keys(), ...next.keys()])) {
|
|
63
|
+
const a = previous.get(path);
|
|
64
|
+
const b = next.get(path);
|
|
65
|
+
if (!a && b) {
|
|
66
|
+
widened = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (a && !b) {
|
|
70
|
+
narrowed = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!a || !b) continue;
|
|
74
|
+
if (a.required && !b.required) widened = true;
|
|
75
|
+
if (!a.required && b.required) narrowed = true;
|
|
76
|
+
const beforeAdditional = a.additionalProperties ?? true;
|
|
77
|
+
const afterAdditional = b.additionalProperties ?? true;
|
|
78
|
+
if (!beforeAdditional && afterAdditional) widened = true;
|
|
79
|
+
if (beforeAdditional && !afterAdditional) narrowed = true;
|
|
80
|
+
if (a.enumMembers && b.enumMembers) {
|
|
81
|
+
if (isSuperset(b.enumMembers, a.enumMembers) && b.enumMembers.length > a.enumMembers.length) widened = true;
|
|
82
|
+
else if (isSuperset(a.enumMembers, b.enumMembers) && a.enumMembers.length > b.enumMembers.length) narrowed = true;
|
|
83
|
+
else if (canonicalize(a.enumMembers) !== canonicalize(b.enumMembers)) {
|
|
84
|
+
widened = true;
|
|
85
|
+
narrowed = true;
|
|
86
|
+
}
|
|
87
|
+
} else if (a.enumMembers && !b.enumMembers) widened = true;
|
|
88
|
+
else if (!a.enumMembers && b.enumMembers) narrowed = true;
|
|
89
|
+
if (a.types && b.types) {
|
|
90
|
+
if (isSuperset(b.types, a.types) && b.types.length > a.types.length) widened = true;
|
|
91
|
+
else if (isSuperset(a.types, b.types) && a.types.length > b.types.length) narrowed = true;
|
|
92
|
+
else if (canonicalize(a.types) !== canonicalize(b.types)) {
|
|
93
|
+
widened = true;
|
|
94
|
+
narrowed = true;
|
|
95
|
+
}
|
|
96
|
+
} else if (a.types && !b.types) widened = true;
|
|
97
|
+
else if (!a.types && b.types) narrowed = true;
|
|
98
|
+
const lowerBounds = [["minimum", a.minimum, b.minimum], ["minLength", a.minLength, b.minLength]];
|
|
99
|
+
for (const [, before_, after_] of lowerBounds) {
|
|
100
|
+
if (before_ !== void 0 && after_ === void 0) widened = true;
|
|
101
|
+
else if (before_ === void 0 && after_ !== void 0) narrowed = true;
|
|
102
|
+
else if (before_ !== void 0 && after_ !== void 0) {
|
|
103
|
+
if (after_ < before_) widened = true;
|
|
104
|
+
if (after_ > before_) narrowed = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const upperBounds = [["maximum", a.maximum, b.maximum], ["maxLength", a.maxLength, b.maxLength]];
|
|
108
|
+
for (const [, before_, after_] of upperBounds) {
|
|
109
|
+
if (before_ !== void 0 && after_ === void 0) widened = true;
|
|
110
|
+
else if (before_ === void 0 && after_ !== void 0) narrowed = true;
|
|
111
|
+
else if (before_ !== void 0 && after_ !== void 0) {
|
|
112
|
+
if (after_ > before_) widened = true;
|
|
113
|
+
if (after_ < before_) narrowed = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (widened && !narrowed) return "widened";
|
|
118
|
+
if (narrowed && !widened) return "narrowed";
|
|
119
|
+
return "changed";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
classifySchemaChange
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=chunk-42ZE5O5I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/diff/schema.ts"],"sourcesContent":["/**\n * Labelling a JSON Schema change as a widening or a narrowing.\n *\n * Deciding whether one schema accepts a superset of another is not tractable in general, so this\n * is a heuristic over the keywords that carry almost all real changes. It is used only to rank\n * and describe a finding: every schema change fails `check` regardless of the label. A heuristic\n * is fine for sorting a list; it would not be fine for deciding whether CI goes green.\n */\nimport { canonicalize, stableKey } from \"../lock/canonical\";\nimport { alternatives, asObject, effectiveSchema, MAX_FACTS, MAX_VISIT_DEPTH } from \"../lock/jsonschema\";\nimport type { JsonObject, JsonValue } from \"../lock/types\";\n\nexport type SchemaVerdict = \"widened\" | \"narrowed\" | \"changed\" | \"same\";\n\ninterface Facts {\n required: boolean;\n additionalProperties?: boolean;\n enumMembers?: string[];\n types?: string[];\n minimum?: number;\n maximum?: number;\n minLength?: number;\n maxLength?: number;\n}\n\nfunction numberAt(node: JsonObject, key: string): number | undefined {\n const value = node[key];\n return typeof value === \"number\" ? value : undefined;\n}\n\n/**\n * Flattens a schema into per-path facts.\n *\n * `$ref` and `allOf` are resolved before a node is read, so a schema that keeps its properties\n * in `$defs` is compared on the same terms as one that inlines them. Alternation branches get\n * their own path segment (`arg|anyOf[1]`), which makes an added branch show up as new facts --\n * a widening -- and a removed one as a narrowing, without special-casing either.\n */\nfunction collectFacts(schema: JsonValue): Map<string, Facts> {\n const facts = new Map<string, Facts>();\n\n const visit = (node: JsonValue, path: string, required: boolean, depth: number): void => {\n if (depth > MAX_VISIT_DEPTH || facts.size >= MAX_FACTS) return;\n const object = effectiveSchema(node, schema);\n if (!object) return;\n\n const typeValue = object[\"type\"];\n const types =\n typeof typeValue === \"string\"\n ? [typeValue]\n : Array.isArray(typeValue)\n ? typeValue.filter((entry): entry is string => typeof entry === \"string\").sort()\n : undefined;\n const enumValue = object[\"enum\"];\n\n facts.set(path, {\n required,\n additionalProperties: typeof object[\"additionalProperties\"] === \"boolean\" ? object[\"additionalProperties\"] : undefined,\n enumMembers: Array.isArray(enumValue) ? enumValue.map((entry) => canonicalize(entry)).sort() : undefined,\n types,\n minimum: numberAt(object, \"minimum\"),\n maximum: numberAt(object, \"maximum\"),\n minLength: numberAt(object, \"minLength\"),\n maxLength: numberAt(object, \"maxLength\"),\n });\n\n const properties = asObject(object[\"properties\"]);\n if (properties) {\n const requiredList = Array.isArray(object[\"required\"])\n ? (object[\"required\"] as JsonValue[]).filter((entry): entry is string => typeof entry === \"string\")\n : [];\n for (const [name, child] of Object.entries(properties)) {\n visit(child, path === \"\" ? name : `${path}.${name}`, requiredList.includes(name), depth + 1);\n }\n }\n\n const items = object[\"items\"];\n if (items !== undefined) visit(items, `${path}[]`, false, depth + 1);\n\n const prefixItems = object[\"prefixItems\"];\n if (Array.isArray(prefixItems)) prefixItems.forEach((entry, index) => visit(entry, `${path}[${index}]`, false, depth + 1));\n\n for (const branch of alternatives(object)) visit(branch.schema, `${path}|${branch.label}`, false, depth + 1);\n };\n\n visit(schema, \"\", true, 0);\n return facts;\n}\n\nfunction isSuperset(next: readonly string[], previous: readonly string[]): boolean {\n return previous.every((entry) => next.includes(entry));\n}\n\nexport function classifySchemaChange(before: JsonValue, after: JsonValue): SchemaVerdict {\n if (stableKey(before) === stableKey(after)) return \"same\";\n\n const previous = collectFacts(before);\n const next = collectFacts(after);\n\n let widened = false;\n let narrowed = false;\n\n for (const path of new Set([...previous.keys(), ...next.keys()])) {\n const a = previous.get(path);\n const b = next.get(path);\n\n // A new property is a widening even when it is optional: it enlarges what the agent may be\n // induced to send.\n if (!a && b) { widened = true; continue; }\n if (a && !b) { narrowed = true; continue; }\n if (!a || !b) continue;\n\n if (a.required && !b.required) widened = true;\n if (!a.required && b.required) narrowed = true;\n\n const beforeAdditional = a.additionalProperties ?? true;\n const afterAdditional = b.additionalProperties ?? true;\n if (!beforeAdditional && afterAdditional) widened = true;\n if (beforeAdditional && !afterAdditional) narrowed = true;\n\n if (a.enumMembers && b.enumMembers) {\n if (isSuperset(b.enumMembers, a.enumMembers) && b.enumMembers.length > a.enumMembers.length) widened = true;\n else if (isSuperset(a.enumMembers, b.enumMembers) && a.enumMembers.length > b.enumMembers.length) narrowed = true;\n else if (canonicalize(a.enumMembers) !== canonicalize(b.enumMembers)) { widened = true; narrowed = true; }\n } else if (a.enumMembers && !b.enumMembers) widened = true;\n else if (!a.enumMembers && b.enumMembers) narrowed = true;\n\n if (a.types && b.types) {\n if (isSuperset(b.types, a.types) && b.types.length > a.types.length) widened = true;\n else if (isSuperset(a.types, b.types) && a.types.length > b.types.length) narrowed = true;\n else if (canonicalize(a.types) !== canonicalize(b.types)) { widened = true; narrowed = true; }\n } else if (a.types && !b.types) widened = true;\n else if (!a.types && b.types) narrowed = true;\n\n // A bound that disappears loosens; one that appears tightens.\n const lowerBounds = [[\"minimum\", a.minimum, b.minimum] as const, [\"minLength\", a.minLength, b.minLength] as const];\n for (const [, before_, after_] of lowerBounds) {\n if (before_ !== undefined && after_ === undefined) widened = true;\n else if (before_ === undefined && after_ !== undefined) narrowed = true;\n else if (before_ !== undefined && after_ !== undefined) {\n if (after_ < before_) widened = true;\n if (after_ > before_) narrowed = true;\n }\n }\n const upperBounds = [[\"maximum\", a.maximum, b.maximum] as const, [\"maxLength\", a.maxLength, b.maxLength] as const];\n for (const [, before_, after_] of upperBounds) {\n if (before_ !== undefined && after_ === undefined) widened = true;\n else if (before_ === undefined && after_ !== undefined) narrowed = true;\n else if (before_ !== undefined && after_ !== undefined) {\n if (after_ > before_) widened = true;\n if (after_ < before_) narrowed = true;\n }\n }\n }\n\n if (widened && !narrowed) return \"widened\";\n if (narrowed && !widened) return \"narrowed\";\n // Both directions at once, or a change in a keyword this heuristic does not model.\n return \"changed\";\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAS,SAAS,MAAkB,KAAiC;AACnE,QAAM,QAAQ,KAAK,GAAG;AACtB,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAUA,SAAS,aAAa,QAAuC;AAC3D,QAAM,QAAQ,oBAAI,IAAmB;AAErC,QAAM,QAAQ,CAAC,MAAiB,MAAc,UAAmB,UAAwB;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EAAE,SAAS,CAAU;AACjH,eAAW,CAAC,EAAE,SAAS,MAAM,KAAK,aAAa;AAC7C,UAAI,YAAY,UAAa,WAAW,OAAW,WAAU;AAAA,eACpD,YAAY,UAAa,WAAW,OAAW,YAAW;AAAA,eAC1D,YAAY,UAAa,WAAW,QAAW;AACtD,YAAI,SAAS,QAAS,WAAU;AAChC,YAAI,SAAS,QAAS,YAAW;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAEA,MAAI,WAAW,CAAC,SAAU,QAAO;AACjC,MAAI,YAAY,CAAC,QAAS,QAAO;AAEjC,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-ALHOTOM6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
digest,
|
|
3
|
+
toJson
|
|
4
|
+
} from "./chunk-HLTEHLNF.js";
|
|
5
|
+
|
|
6
|
+
// src/lock/reseal.ts
|
|
7
|
+
function sealMember(member) {
|
|
8
|
+
const { digest: _discarded, ...body } = member;
|
|
9
|
+
return { ...body, digest: digest(toJson(body)) };
|
|
10
|
+
}
|
|
11
|
+
function reseal(entry) {
|
|
12
|
+
switch (entry.kind) {
|
|
13
|
+
case "mcp-server":
|
|
14
|
+
return resealMcpServer(entry);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function resealMcpServer(entry) {
|
|
18
|
+
const tools = (entry.tools ?? []).map((tool) => sealMember(tool));
|
|
19
|
+
const resources = (entry.resources ?? []).map((resource) => sealMember(resource));
|
|
20
|
+
const resourceTemplates = (entry.resourceTemplates ?? []).map((template) => sealMember(template));
|
|
21
|
+
const prompts = (entry.prompts ?? []).map((prompt) => sealMember(prompt));
|
|
22
|
+
const covered = {
|
|
23
|
+
transport: entry.transport,
|
|
24
|
+
protocol: entry.protocol,
|
|
25
|
+
serverInfo: entry.serverInfo,
|
|
26
|
+
capabilities: entry.capabilities,
|
|
27
|
+
instructions: entry.instructions,
|
|
28
|
+
tools: tools.map((tool) => tool.digest),
|
|
29
|
+
resources: resources.map((resource) => resource.digest),
|
|
30
|
+
resourceTemplates: resourceTemplates.map((template) => template.digest),
|
|
31
|
+
prompts: prompts.map((prompt) => prompt.digest)
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
...entry,
|
|
35
|
+
tools: tools.length > 0 ? tools : void 0,
|
|
36
|
+
resources: resources.length > 0 ? resources : void 0,
|
|
37
|
+
resourceTemplates: resourceTemplates.length > 0 ? resourceTemplates : void 0,
|
|
38
|
+
prompts: prompts.length > 0 ? prompts : void 0,
|
|
39
|
+
digest: digest(toJson(covered))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
reseal
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=chunk-DGEHI25T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lock/reseal.ts"],"sourcesContent":["/**\n * Recomputing every digest in a locked server from its own content.\n *\n * The diff engine short-circuits on digests, which is right when the lockfile and the reading\n * were produced by the same trusted process. The control plane is not in that position: it is\n * handed a surface by a collector running on the machine under audit, and a surface whose text\n * changed while its digests stayed still would otherwise compare as unchanged -- a clean verdict\n * on a tampered reading.\n *\n * So the control plane reseals both sides before diffing. Any digest the collector sent is\n * discarded and recomputed here, using the same canonicalization the collector used, so an\n * honest reading reseals to exactly the digests it arrived with.\n */\nimport { digest, toJson } from \"./canonical\";\nimport type { LockedMcpServer, LockedPrompt, LockedResource, LockedResourceTemplate, LockedSubject, LockedTool } from \"./types\";\n\n/** Mirrors `sealed()` in the collector's builder: the digest covers the body without itself. */\nfunction sealMember<T extends { digest?: string }>(member: T): T & { digest: string } {\n const { digest: _discarded, ...body } = member;\n return { ...(body as Omit<T, \"digest\">), digest: digest(toJson(body)) } as T & { digest: string };\n}\n\n/**\n * Resealing dispatches on what the subject is. One branch today; a kind added without a branch\n * here is a compile error rather than a surface that silently passes through unsealed, which\n * is the failure that would matter most.\n */\nexport function reseal(entry: LockedSubject): LockedSubject {\n switch (entry.kind) {\n case \"mcp-server\":\n return resealMcpServer(entry);\n }\n}\n\nfunction resealMcpServer(entry: LockedMcpServer): LockedMcpServer {\n const tools = (entry.tools ?? []).map((tool) => sealMember<LockedTool>(tool));\n const resources = (entry.resources ?? []).map((resource) => sealMember<LockedResource>(resource));\n const resourceTemplates = (entry.resourceTemplates ?? []).map((template) => sealMember<LockedResourceTemplate>(template));\n const prompts = (entry.prompts ?? []).map((prompt) => sealMember<LockedPrompt>(prompt));\n\n /*\n * `source` and `kind` are deliberately outside the digest, exactly as in the collector:\n * moving a server between config files is not a capability change, and neither is the format\n * learning a word for what it already held. That second exclusion is what lets a version 1\n * lock upgrade without every project reporting drift. Members contribute their digests rather\n * than their bodies, so resealing a large server stays linear.\n */\n const covered = {\n transport: entry.transport,\n protocol: entry.protocol,\n serverInfo: entry.serverInfo,\n capabilities: entry.capabilities,\n instructions: entry.instructions,\n tools: tools.map((tool) => tool.digest),\n resources: resources.map((resource) => resource.digest),\n resourceTemplates: resourceTemplates.map((template) => template.digest),\n prompts: prompts.map((prompt) => prompt.digest),\n };\n\n return {\n ...entry,\n tools: tools.length > 0 ? tools : undefined,\n resources: resources.length > 0 ? resources : undefined,\n resourceTemplates: resourceTemplates.length > 0 ? resourceTemplates : undefined,\n prompts: prompts.length > 0 ? prompts : undefined,\n digest: digest(toJson(covered)),\n };\n}\n"],"mappings":";;;;;;AAiBA,SAAS,WAA0C,QAAmC;AACpF,QAAM,EAAE,QAAQ,YAAY,GAAG,KAAK,IAAI;AACxC,SAAO,EAAE,GAAI,MAA4B,QAAQ,OAAO,OAAO,IAAI,CAAC,EAAE;AACxE;AAOO,SAAS,OAAO,OAAqC;AAC1D,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACH,aAA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ock/normalize.ts
|
|
9
|
+
function resolveBehavior(annotations) {
|
|
10
|
+
const readOnly = annotations?.readOnlyHint ?? false;
|
|
11
|
+
return {
|
|
12
|
+
readOnly,
|
|
13
|
+
destructive: readOnly ? false : annotations?.destructiveHint ?? true,
|
|
14
|
+
idempotent: readOnly ? true : annotations?.idempotentHint ?? false,
|
|
15
|
+
openWorld: annotations?.openWorldHint ?? true
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function isEscalation(previous, next) {
|
|
19
|
+
return previous.readOnly && !next.readOnly || !previous.destructive && next.destructive || previous.idempotent && !next.idempotent || !previous.openWorld && next.openWorld;
|
|
20
|
+
}
|
|
21
|
+
function normalizeSchema(value) {
|
|
22
|
+
if (Array.isArray(value)) return value.map(normalizeSchema);
|
|
23
|
+
if (value === null || typeof value !== "object") return value;
|
|
24
|
+
const out = {};
|
|
25
|
+
for (const [key, member] of Object.entries(value)) {
|
|
26
|
+
if (key === "required" && Array.isArray(member) && member.every((entry) => typeof entry === "string")) {
|
|
27
|
+
out[key] = [...member].sort();
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
out[key] = normalizeSchema(member);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function extractHeaderParams(schema) {
|
|
35
|
+
const found = [];
|
|
36
|
+
const walk = (node, path, depth) => {
|
|
37
|
+
if (depth > MAX_VISIT_DEPTH) return;
|
|
38
|
+
const object = effectiveSchema(node, schema);
|
|
39
|
+
if (!object) return;
|
|
40
|
+
const properties = asObject(object["properties"]);
|
|
41
|
+
if (properties) {
|
|
42
|
+
for (const [name, child] of Object.entries(properties)) {
|
|
43
|
+
const resolved = effectiveSchema(child, schema);
|
|
44
|
+
if (!resolved) continue;
|
|
45
|
+
const header = resolved["x-mcp-header"];
|
|
46
|
+
if (typeof header === "string" && header.length > 0) found.push(`${[...path, name].join(".")} -> ${header}`);
|
|
47
|
+
walk(child, [...path, name], depth + 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const branch of alternatives(object)) walk(branch.schema, path, depth + 1);
|
|
51
|
+
};
|
|
52
|
+
walk(schema, [], 0);
|
|
53
|
+
return [...new Set(found)].sort();
|
|
54
|
+
}
|
|
55
|
+
function stripIgnoredMeta(meta, ignoredPrefixes) {
|
|
56
|
+
if (meta === null || meta === void 0 || typeof meta !== "object" || Array.isArray(meta)) return void 0;
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
59
|
+
if (ignoredPrefixes.some((prefix) => key.startsWith(prefix))) continue;
|
|
60
|
+
out[key] = value;
|
|
61
|
+
}
|
|
62
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
63
|
+
}
|
|
64
|
+
function sanitizeUrl(raw) {
|
|
65
|
+
try {
|
|
66
|
+
const url = new URL(raw);
|
|
67
|
+
url.search = "";
|
|
68
|
+
url.hash = "";
|
|
69
|
+
return url.toString();
|
|
70
|
+
} catch {
|
|
71
|
+
return raw;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
resolveBehavior,
|
|
77
|
+
isEscalation,
|
|
78
|
+
normalizeSchema,
|
|
79
|
+
extractHeaderParams,
|
|
80
|
+
stripIgnoredMeta,
|
|
81
|
+
sanitizeUrl
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=chunk-DL6LTPYY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lock/normalize.ts"],"sourcesContent":["/** Turning what a server sent into the stable, reviewable form the lock stores. */\nimport { alternatives, asObject, effectiveSchema, MAX_VISIT_DEPTH } from \"./jsonschema\";\nimport type { JsonObject, JsonValue, LockedAnnotations, LockedBehavior } from \"./types\";\n\n/**\n * Resolves the four behavioural annotations against the spec's defaults, which are not neutral:\n * an absent `readOnlyHint` means \"may modify\" and an absent `destructiveHint` means \"may\n * destroy\". A server deleting an annotation is therefore an escalation, and the lock has to be\n * able to show it as a changed value rather than a removed line. See docs/lockfile.md §4.\n *\n * `destructiveHint` and `idempotentHint` are defined to be meaningful only when `readOnlyHint`\n * is false, so a read-only tool resolves to non-destructive and idempotent regardless of what\n * it claims: a tool that changes nothing cannot destroy anything, and repeating it has no\n * additional effect.\n */\nexport function resolveBehavior(annotations: LockedAnnotations | undefined): LockedBehavior {\n const readOnly = annotations?.readOnlyHint ?? false;\n return {\n readOnly,\n destructive: readOnly ? false : (annotations?.destructiveHint ?? true),\n idempotent: readOnly ? true : (annotations?.idempotentHint ?? false),\n openWorld: annotations?.openWorldHint ?? true,\n };\n}\n\n/** True when `next` claims any power `previous` did not. */\nexport function isEscalation(previous: LockedBehavior, next: LockedBehavior): boolean {\n return (\n (previous.readOnly && !next.readOnly) ||\n (!previous.destructive && next.destructive) ||\n (previous.idempotent && !next.idempotent) ||\n (!previous.openWorld && next.openWorld)\n );\n}\n\n/**\n * Sorts `required` arrays wherever they appear. Member order there is semantically\n * insignificant and is the most common source of diffs that mean nothing. Every other array\n * keeps server order, because order *is* significant in `prefixItems`, `allOf` and `icons`, and\n * we only reorder where we can show it is safe.\n *\n * The rule is positional rather than schema-aware: a non-schema object with a string-array\n * member literally named `required` would also be sorted. That costs nothing we can observe and\n * avoids carrying a JSON Schema interpreter around.\n */\nexport function normalizeSchema(value: JsonValue): JsonValue {\n if (Array.isArray(value)) return value.map(normalizeSchema);\n if (value === null || typeof value !== \"object\") return value;\n\n const out: JsonObject = {};\n for (const [key, member] of Object.entries(value)) {\n if (key === \"required\" && Array.isArray(member) && member.every((entry) => typeof entry === \"string\")) {\n out[key] = [...(member as string[])].sort();\n continue;\n }\n out[key] = normalizeSchema(member);\n }\n return out;\n}\n\n/**\n * Finds input properties carrying an `x-mcp-header` annotation, which mirrors the argument's\n * value into an `Mcp-Param-*` HTTP header on Streamable HTTP, where proxies and WAFs can read\n * it. A server adding this to an existing parameter redirects that argument's data with no\n * visible change to the tool's signature, so it gets its own line in the lock.\n *\n * `$ref` and `allOf` are resolved first. Schema generators put properties behind `$defs` as a\n * matter of course, and a scan that only read literal nodes found nothing in those -- which is\n * the worst outcome for a field whose entire purpose is to move data somewhere new.\n */\nexport function extractHeaderParams(schema: JsonValue): string[] {\n const found: string[] = [];\n\n const walk = (node: JsonValue, path: string[], depth: number): void => {\n if (depth > MAX_VISIT_DEPTH) return;\n const object = effectiveSchema(node, schema);\n if (!object) return;\n\n const properties = asObject(object[\"properties\"]);\n if (properties) {\n for (const [name, child] of Object.entries(properties)) {\n const resolved = effectiveSchema(child, schema);\n if (!resolved) continue;\n const header = resolved[\"x-mcp-header\"];\n if (typeof header === \"string\" && header.length > 0) found.push(`${[...path, name].join(\".\")} -> ${header}`);\n walk(child, [...path, name], depth + 1);\n }\n }\n\n // A parameter reachable only through one branch of an `anyOf` is still reachable.\n for (const branch of alternatives(object)) walk(branch.schema, path, depth + 1);\n };\n\n walk(schema, [], 0);\n return [...new Set(found)].sort();\n}\n\n/** Drops `_meta` keys under any ignored prefix. Returns undefined when nothing is left to pin. */\nexport function stripIgnoredMeta(meta: JsonValue | undefined, ignoredPrefixes: readonly string[]): JsonObject | undefined {\n if (meta === null || meta === undefined || typeof meta !== \"object\" || Array.isArray(meta)) return undefined;\n const out: JsonObject = {};\n for (const [key, value] of Object.entries(meta)) {\n if (ignoredPrefixes.some((prefix) => key.startsWith(prefix))) continue;\n out[key] = value;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/** Strips the query string: query strings routinely carry tokens, and the lock is committed. */\nexport function sanitizeUrl(raw: string): string {\n try {\n const url = new URL(raw);\n url.search = \"\";\n url.hash = \"\";\n return url.toString();\n } catch {\n // Not a parseable URL. Keep it as configured so the mismatch is visible rather than silent.\n return raw;\n }\n}\n"],"mappings":";;;;;;;;AAeO,SAAS,gBAAgB,aAA4D;AAC1F,QAAM,WAAW,aAAa,gBAAgB;AAC9C,SAAO;AAAA,IACL;AAAA,IACA,aAAa,WAAW,QAAS,aAAa,mBAAmB;AA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