@nulladrift/core 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/changes.d.ts +5 -0
- package/dist/changes.js +1 -1
- package/dist/{chunk-CXDPJPL4.js → chunk-5EJ474K3.js} +69 -29
- package/dist/chunk-5EJ474K3.js.map +1 -0
- package/dist/{chunk-JCJXSMBS.js → chunk-6ERBWXWP.js} +3 -2
- package/dist/{chunk-JCJXSMBS.js.map → chunk-6ERBWXWP.js.map} +1 -1
- package/dist/{chunk-5OCXDAFS.js → chunk-CP2XTAKE.js} +39 -12
- package/dist/chunk-CP2XTAKE.js.map +1 -0
- package/dist/{chunk-ZD2C4FMT.js → chunk-MQJ54E63.js} +8 -2
- package/dist/{chunk-ZD2C4FMT.js.map → chunk-MQJ54E63.js.map} +1 -1
- package/dist/chunk-NSVG7BEU.js +315 -0
- package/dist/chunk-NSVG7BEU.js.map +1 -0
- package/dist/chunk-Z4M6ZRTP.js +212 -0
- package/dist/chunk-Z4M6ZRTP.js.map +1 -0
- package/dist/diff/index.js +6 -6
- package/dist/diff/schema.js +2 -2
- package/dist/diff/types.js +1 -1
- package/dist/index.js +46 -21
- package/dist/index.js.map +1 -1
- package/dist/lock/credentials.js +1 -1
- package/dist/lock/jsonschema.d.ts +39 -20
- package/dist/lock/jsonschema.js +12 -3
- package/dist/lock/normalize.d.ts +5 -3
- package/dist/lock/normalize.js +6 -3
- package/package.json +1 -1
- package/dist/chunk-5OCXDAFS.js.map +0 -1
- package/dist/chunk-CXDPJPL4.js.map +0 -1
- package/dist/chunk-FVT77BL4.js +0 -107
- package/dist/chunk-FVT77BL4.js.map +0 -1
- package/dist/chunk-TRNJNLQQ.js +0 -127
- package/dist/chunk-TRNJNLQQ.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lock/credentials.ts"],"sourcesContent":["/**\n * Credentials a config writes literally, found so the lock can leave them out.\n *\n * Environment and header values were never written to the lock, only their names, and a URL\n * loses its query string and its user:password. That covered every place a credential belongs.\n * It did not cover the places configs actually put them: `--api-key sk-...` in `args`,\n * `-e GITHUB_TOKEN=ghp_...` in a `docker run`, a connection string with a password, a token as a\n * segment of a hosted server's URL. The lock is the file the README tells you to commit, and the\n * reading `push` sends is the same data, so each of those went into git and over the wire.\n *\n * A credential is replaced, not hashed. A rotated key is not a change to what a server can do,\n * so there is nothing for drift to see in it, and a hash of a short password is something a\n * dictionary can be run against. This matches what already happens to an `env` value.\n *\n * Everything here errs toward leaving a value alone. A false positive hides a real change to how\n * a server is started, which is the thing the lock exists to show; a value is only replaced when\n * its name says it is a credential, its issuer's format does, or it is too random to be anything\n * else. A `${VAR}` placeholder is never touched: that is how a config is supposed to do this.\n */\n\n/** What a credential is replaced with. Plain ASCII, so it survives a URL path unescaped. */\nexport const REDACTED = \"REDACTED\";\n\n/**\n * Whether a name says its value is a credential: a flag (`--github-token`, `--key`), an\n * environment assignment (`GITHUB_PAT=`, `DD_API_KEY_SECONDARY=`), a JSON key (`braveApiKey`), a\n * query or connection-string parameter (`api_key=`, `Password=`).\n *\n * Read as words, camelCase split, so the credential word can sit anywhere in the name. It was a\n * suffix match, which missed `--key`, `GITHUB_PAT`, `braveApiKey` and every name with a word after\n * the credential one. A name whose last word says it holds something *about* a credential (where\n * it is, what kind it is) is left alone: `--token-file`, `--key-id`, `--auth-type`, `--max-tokens`.\n */\nconst CREDENTIAL_WORDS = new Set([\n \"key\", \"apikey\", \"token\", \"secret\", \"password\", \"passwd\", \"pwd\", \"pass\", \"pat\", \"auth\", \"bearer\",\n \"credential\", \"credentials\", \"privatekey\", \"accesskey\", \"clientsecret\", \"sig\", \"signature\", \"jwt\", \"cookie\",\n]);\nconst DESCRIBES_IT = new Set([\n \"file\", \"path\", \"dir\", \"directory\", \"url\", \"uri\", \"endpoint\", \"host\", \"type\", \"mode\", \"method\", \"header\",\n \"name\", \"id\", \"env\", \"var\", \"length\", \"limit\", \"count\", \"max\", \"min\", \"size\", \"timeout\", \"ttl\", \"format\",\n \"prefix\", \"location\", \"store\", \"provider\", \"region\", \"scope\", \"scopes\", \"version\", \"algorithm\", \"kind\", \"expiry\",\n]);\n\nfunction nameWords(name: string): string[] {\n return name\n .replace(/^-+/, \"\")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter(Boolean);\n}\n\nexport function isCredentialName(name: string): boolean {\n const words = nameWords(name);\n const last = words[words.length - 1];\n if (last === undefined || DESCRIBES_IT.has(last) || words[0] === \"no\") return false;\n return words.some((word) => CREDENTIAL_WORDS.has(word));\n}\n\n/** Headers that carry a credential whatever their value looks like. */\nconst CREDENTIAL_HEADERS = new Set([\"authorization\", \"proxy-authorization\", \"cookie\", \"set-cookie\"]);\n\n/**\n * Formats a credential has wherever it appears, because its issuer made it recognisable on\n * purpose (so leaked ones can be found). Each is specific enough not to match a package name.\n */\nconst ISSUER_FORMATS: RegExp[] = [\n /\\b(?:AKIA|ASIA)[0-9A-Z]{16}\\b/g, // AWS access key id\n /\\bgh[pousr]_[A-Za-z0-9]{36,}\\b/g, // GitHub\n /\\bgithub_pat_[A-Za-z0-9_]{40,}\\b/g,\n /\\bglpat-[A-Za-z0-9_-]{20,}/g, // GitLab\n /\\bxox[abprs]-[A-Za-z0-9-]{10,}/g, // Slack\n /\\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}\\b/g, // Stripe\n /\\bsk-ant-[A-Za-z0-9_-]{20,}/g, // Anthropic\n /\\bsk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{32,}/g, // OpenAI\n /\\bAIza[0-9A-Za-z_-]{35}\\b/g, // Google API key\n /\\bnpm_[A-Za-z0-9]{36}\\b/g,\n /\\beyJ[A-Za-z0-9_-]{8,}\\.eyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}/g, // JWT\n];\n\n/** A value written as a placeholder for the client to fill in, which is the safe way to do this. */\nconst PLACEHOLDER = /\\$\\{|^\\$[A-Za-z_]/;\n\n/**\n * A token with no issuer format: long, URL-safe, mixing upper case, lower case and digits, and\n * switching between them constantly.\n *\n * Requiring all three classes leaves out UUIDs, hex digests and commit hashes, which are lower\n * case and far more often an identifier than a secret. Requiring the switching leaves out long\n * names: `AnthropicClaudeDesktopExtension2025` has every class but changes class six times in\n * thirty-five characters, where a random token changes on most of them.\n */\nfunction looksRandom(value: string): boolean {\n if (value.length < 32 || !/^[A-Za-z0-9_-]+$/.test(value)) return false;\n if (!/[a-z]/.test(value) || !/[A-Z]/.test(value) || !/[0-9]/.test(value)) return false;\n const kind = (character: string) => (/[a-z]/.test(character) ? 0 : /[A-Z]/.test(character) ? 1 : /[0-9]/.test(character) ? 2 : 3);\n let switches = 0;\n for (let index = 1; index < value.length; index += 1) {\n if (kind(value[index] ?? \"\") !== kind(value[index - 1] ?? \"\")) switches += 1;\n }\n return switches >= value.length / 3;\n}\n\n/** `decodeURIComponent`, for a check: a malformed escape is just text. */\nfunction decoded(value: string): string {\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\n/** A value worth replacing when its name already says it is a credential. */\nfunction isSecretValue(value: string): boolean {\n if (value === \"\" || value === REDACTED || PLACEHOLDER.test(value)) return false;\n // A path or a URL names where the secret lives, not the secret: `--token-file`-style use.\n if (/^(?:[./~]|[A-Za-z]:\\\\|[a-z][a-z0-9+.-]*:\\/\\/)/i.test(value)) return false;\n return true;\n}\n\n/** Replaces each issuer-formatted credential inside a value, leaving the rest of it readable. */\nfunction redactFormats(value: string): string {\n let out = value;\n for (const format of ISSUER_FORMATS) out = out.replace(format, REDACTED);\n return out;\n}\n\n/*\n * Hosts that serve code from a path naming what it is: a commit (`/acme/server/1f2e...4c/main.ts`),\n * a gist, a tarball of a ref. The long hex segment there is the version being run, not a key, and\n * replacing it made a launcher that swapped one commit for another compare clean. Credentials on\n * these hosts travel in the query or the userinfo, which are still redacted, as is any segment in\n * an issuer's credential format.\n */\nconst CODE_HOSTS = new Set([\n \"github.com\",\n \"raw.githubusercontent.com\",\n \"codeload.github.com\",\n \"gist.github.com\",\n \"gist.githubusercontent.com\",\n \"api.github.com\",\n \"gitlab.com\",\n \"bitbucket.org\",\n \"cdn.jsdelivr.net\",\n \"esm.sh\",\n \"deno.land\",\n]);\n\n/** In a URL inside an argument: the password, credential parameters in the query or fragment, key path segments. */\nfunction redactUrl(value: string): string {\n if (!/^[a-z][a-z0-9+.-]*:\\/\\//i.test(value)) return value;\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return redactPairs(value);\n }\n let changed = false;\n if (url.password && !PLACEHOLDER.test(decoded(url.password))) {\n url.password = REDACTED;\n changed = true;\n }\n for (const [key, parameter] of [...url.searchParams]) {\n if (isCredentialName(key) && isSecretValue(parameter)) {\n url.searchParams.set(key, REDACTED);\n changed = true;\n }\n }\n const path = redactPath(url.pathname, { contentAddressed: CODE_HOSTS.has(url.hostname.toLowerCase()) });\n if (path !== url.pathname) {\n url.pathname = path;\n changed = true;\n }\n const hash = url.hash ? redactPairs(url.hash) : url.hash;\n if (hash !== url.hash) {\n url.hash = hash;\n changed = true;\n }\n return changed ? url.toString() : value;\n}\n\n/**\n * `name=value` pairs inside a larger string whose name is a credential: a query string a URL\n * parser would not take (`jdbc:postgresql://...&password=`), a fragment (`#access_token=`), a\n * connection string (`Server=db;Password=...`).\n */\nfunction redactPairs(text: string): string {\n return text.replace(/(^|[?&;#\\s,])([A-Za-z_][A-Za-z0-9_.-]*)=([^&;#\\s,]*)/g, (whole, lead: string, name: string, value: string) =>\n isCredentialName(name) && isSecretValue(value) ? `${lead}${name}=${REDACTED}` : whole,\n );\n}\n\n/** A header written as `Name: value`, for a header that is a credential. */\nfunction redactHeader(text: string): string | undefined {\n const header = /^([A-Za-z][A-Za-z0-9-]*)\\s*:\\s*(\\S.*)$/s.exec(text);\n if (!header) return undefined;\n const [, name = \"\", value = \"\"] = header;\n if (!(CREDENTIAL_HEADERS.has(name.toLowerCase()) || isCredentialName(name)) || PLACEHOLDER.test(value)) return undefined;\n return `${name}: ${REDACTED}`;\n}\n\n/** JSON in an argument (`--config {\"braveApiKey\":\"...\"}`), its credential-named values replaced. */\nfunction redactJson(text: string): string | undefined {\n if (!/^\\s*[[{]/.test(text)) return undefined;\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n return undefined;\n }\n let changed = false;\n const walk = (node: unknown): unknown => {\n if (Array.isArray(node)) return node.map(walk);\n if (node !== null && typeof node === \"object\") {\n const out: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n for (const [key, child] of Object.entries(node)) {\n if (typeof child === \"string\" && isCredentialName(key) && isSecretValue(child)) {\n out[key] = REDACTED;\n changed = true;\n } else if (typeof child === \"string\") {\n const next = redactText(child);\n if (next !== child) changed = true;\n out[key] = next;\n } else {\n out[key] = walk(child);\n }\n }\n return out;\n }\n return node;\n };\n const result = walk(parsed);\n return changed ? JSON.stringify(result) : undefined;\n}\n\n/** Everything that can hide a credential inside one string, in the order that keeps the rest readable. */\nfunction redactText(text: string): string {\n if (PLACEHOLDER.test(text) && !/[?&;#]/.test(text)) return text;\n if (looksRandom(text)) return REDACTED;\n const json = redactJson(text);\n if (json !== undefined) return json;\n const header = redactHeader(text);\n if (header !== undefined) return header;\n return redactFormats(redactPairs(redactUrl(text)));\n}\n\n/**\n * `args` with every credential written literally in them replaced by {@link REDACTED}.\n *\n * Handles a flag and its value (`--api-key KEY`, `--api-key=KEY`), an environment assignment in\n * an argument (`-e GITHUB_TOKEN=ghp_...`, as `docker run` takes them), a URL's password or\n * credential query parameter, an issuer-formatted token anywhere, and an argument that is nothing\n * but a long random token. Arguments are returned in place and in order, so a change to anything\n * else about how a server is started is still drift.\n */\nexport function redactArgs(args: readonly string[]): string[] {\n const out = [...args];\n for (let index = 0; index < out.length; index += 1) {\n const argument = out[index] ?? \"\";\n\n // `--name=value`, `-n=value`, and `NAME=value` (an environment assignment).\n const assignment = /^(-{0,2}[A-Za-z][A-Za-z0-9_.-]*)=(.*)$/s.exec(argument);\n if (assignment) {\n const [, name = \"\", value = \"\"] = assignment;\n if (isCredentialName(name) && isSecretValue(value)) {\n out[index] = `${name}=${REDACTED}`;\n continue;\n }\n // Any other assignment: its value can still hold a header, a URL with a password, JSON, a token.\n if (!PLACEHOLDER.test(value) || /[?&;#]/.test(value)) out[index] = `${name}=${redactText(value)}`;\n continue;\n }\n\n // `--name value`: the flag names a credential, so the next argument is one.\n const flag = /^-{1,2}([A-Za-z][A-Za-z0-9_.-]*)$/.exec(argument);\n const next = out[index + 1];\n if (flag && next !== undefined && !next.startsWith(\"-\")) {\n const name = flag[1] ?? \"\";\n if (isCredentialName(name) && isSecretValue(next) && !looksLikeAnOperand(next)) {\n out[index + 1] = REDACTED;\n index += 1;\n continue;\n }\n // `-u user:password`, `--user user:password`: curl's form, and every tool that copied it.\n if ([\"u\", \"user\", \"basic-auth\"].includes(name.toLowerCase()) && /^[^:\\s]+:[^\\s]+$/.test(next) && !PLACEHOLDER.test(next)) {\n out[index + 1] = `${next.slice(0, next.indexOf(\":\"))}:${REDACTED}`;\n index += 1;\n continue;\n }\n }\n\n out[index] = redactText(argument);\n }\n return out;\n}\n\n/**\n * Whether the word after a flag is more likely the next operand than the flag's value: a script, a\n * package, a path. A boolean credential flag (`--auth`) followed by `server.js` is not a key.\n */\nfunction looksLikeAnOperand(value: string): boolean {\n return value.startsWith(\"@\") || value.includes(\"/\") || /\\.(m?[jt]s|cjs|py|json|ya?ml|toml|sh|exe)$/i.test(value);\n}\n\n/**\n * A URL path with any segment that is a credential replaced, for hosted servers whose address\n * embeds the key (`https://host/api/<token>/mcp`). The rest of the path stays, so a server that\n * moves to a different path or host is still drift.\n */\nexport function redactPath(pathname: string, options: { contentAddressed?: boolean } = {}): string {\n return pathname\n .split(\"/\")\n .map((segment) => {\n if (segment === \"\" || PLACEHOLDER.test(decoded(segment))) return segment;\n if (looksRandom(segment)) return REDACTED;\n // A UUID or a long hex string in a hosted server's address is its key far more often than\n // not (Pipedream, Composio and the like put the account's key there). On a code host it is\n // a commit or a gist, and it is the thing being pinned.\n if (\n !options.contentAddressed &&\n (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(segment) || /^[0-9a-f]{32,}$/i.test(segment))\n )\n return REDACTED;\n return redactFormats(segment);\n })\n .join(\"/\");\n}\n\n/** How many credentials were left out of a locked transport, for saying so. */\nexport function countRedacted(transport: { args?: readonly string[]; url?: string }): number {\n const occurrences = (text: string) => text.split(REDACTED).length - 1;\n return (transport.args ?? []).reduce((total, argument) => total + occurrences(argument), 0) + occurrences(transport.url ?? \"\");\n}\n"],"mappings":";AAqBO,IAAM,WAAW;AAYxB,IAAM,mBAAmB,oBAAI,IAAI;AAAA,EAC/B;AAAA,EAAO;AAAA,EAAU;AAAA,EAAS;AAAA,EAAU;AAAA,EAAY;AAAA,EAAU;AAAA,EAAO;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAQ;AAAA,EACxF;AAAA,EAAc;AAAA,EAAe;AAAA,EAAc;AAAA,EAAa;AAAA,EAAgB;AAAA,EAAO;AAAA,EAAa;AAAA,EAAO;AACrG,CAAC;AACD,IAAM,eAAe,oBAAI,IAAI;AAAA,EAC3B;AAAA,EAAQ;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAa;AAAA,EAAO;AAAA,EAAO;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAQ;AAAA,EAAQ;AAAA,EAAU;AAAA,EAChG;AAAA,EAAQ;AAAA,EAAM;AAAA,EAAO;AAAA,EAAO;AAAA,EAAU;AAAA,EAAS;AAAA,EAAS;AAAA,EAAO;AAAA,EAAO;AAAA,EAAQ;AAAA,EAAW;AAAA,EAAO;AAAA,EAChG;AAAA,EAAU;AAAA,EAAY;AAAA,EAAS;AAAA,EAAY;AAAA,EAAU;AAAA,EAAS;AAAA,EAAU;AAAA,EAAW;AAAA,EAAa;AAAA,EAAQ;AAC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AO,EAAE;AAC/H;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/lock/credentials.ts"],"sourcesContent":["/**\n * Credentials a config writes literally, found so the lock can leave them out.\n *\n * Environment and header values were never written to the lock, only their names, and a URL\n * loses its query string and its user:password. That covered every place a credential belongs.\n * It did not cover the places configs actually put them: `--api-key sk-...` in `args`,\n * `-e GITHUB_TOKEN=ghp_...` in a `docker run`, a connection string with a password, a token as a\n * segment of a hosted server's URL. The lock is the file the README tells you to commit, and the\n * reading `push` sends is the same data, so each of those went into git and over the wire.\n *\n * A credential is replaced, not hashed. A rotated key is not a change to what a server can do,\n * so there is nothing for drift to see in it, and a hash of a short password is something a\n * dictionary can be run against. This matches what already happens to an `env` value.\n *\n * Everything here errs toward leaving a value alone. A false positive hides a real change to how\n * a server is started, which is the thing the lock exists to show; a value is only replaced when\n * its name says it is a credential, its issuer's format does, or it is too random to be anything\n * else. A `${VAR}` placeholder is never touched: that is how a config is supposed to do this.\n */\n\n/** What a credential is replaced with. Plain ASCII, so it survives a URL path unescaped. */\nexport const REDACTED = \"REDACTED\";\n\n/**\n * Whether a name says its value is a credential: a flag (`--github-token`, `--key`), an\n * environment assignment (`GITHUB_PAT=`, `DD_API_KEY_SECONDARY=`), a JSON key (`braveApiKey`), a\n * query or connection-string parameter (`api_key=`, `Password=`).\n *\n * Read as words, camelCase split, so the credential word can sit anywhere in the name. It was a\n * suffix match, which missed `--key`, `GITHUB_PAT`, `braveApiKey` and every name with a word after\n * the credential one. A name whose last word says it holds something *about* a credential (where\n * it is, what kind it is) is left alone: `--token-file`, `--key-id`, `--auth-type`, `--max-tokens`.\n */\nconst CREDENTIAL_WORDS = new Set([\n \"key\", \"apikey\", \"token\", \"secret\", \"password\", \"passwd\", \"pwd\", \"pass\", \"pat\", \"auth\", \"bearer\",\n \"credential\", \"credentials\", \"privatekey\", \"accesskey\", \"clientsecret\", \"sig\", \"signature\", \"jwt\", \"cookie\",\n]);\nconst DESCRIBES_IT = new Set([\n \"file\", \"path\", \"dir\", \"directory\", \"url\", \"uri\", \"endpoint\", \"host\", \"type\", \"mode\", \"method\", \"header\",\n \"name\", \"id\", \"env\", \"var\", \"length\", \"limit\", \"count\", \"max\", \"min\", \"size\", \"timeout\", \"ttl\", \"format\",\n \"prefix\", \"location\", \"store\", \"provider\", \"region\", \"scope\", \"scopes\", \"version\", \"algorithm\", \"kind\", \"expiry\",\n]);\n\nfunction nameWords(name: string): string[] {\n return name\n .replace(/^-+/, \"\")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter(Boolean);\n}\n\nexport function isCredentialName(name: string): boolean {\n const words = nameWords(name);\n const last = words[words.length - 1];\n if (last === undefined || DESCRIBES_IT.has(last) || words[0] === \"no\") return false;\n return words.some((word) => CREDENTIAL_WORDS.has(word));\n}\n\n/** Headers that carry a credential whatever their value looks like. */\nconst CREDENTIAL_HEADERS = new Set([\"authorization\", \"proxy-authorization\", \"cookie\", \"set-cookie\"]);\n\n/**\n * Formats a credential has wherever it appears, because its issuer made it recognisable on\n * purpose (so leaked ones can be found). Each is specific enough not to match a package name.\n */\nconst ISSUER_FORMATS: RegExp[] = [\n /\\b(?:AKIA|ASIA)[0-9A-Z]{16}\\b/g, // AWS access key id\n /\\bgh[pousr]_[A-Za-z0-9]{36,}\\b/g, // GitHub\n /\\bgithub_pat_[A-Za-z0-9_]{40,}\\b/g,\n /\\bglpat-[A-Za-z0-9_-]{20,}/g, // GitLab\n /\\bxox[abprs]-[A-Za-z0-9-]{10,}/g, // Slack\n /\\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}\\b/g, // Stripe\n /\\bsk-ant-[A-Za-z0-9_-]{20,}/g, // Anthropic\n /\\bsk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{32,}/g, // OpenAI\n /\\bAIza[0-9A-Za-z_-]{35}\\b/g, // Google API key\n /\\bnpm_[A-Za-z0-9]{36}\\b/g,\n /\\beyJ[A-Za-z0-9_-]{8,}\\.eyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}/g, // JWT\n];\n\n/** A value written as a placeholder for the client to fill in, which is the safe way to do this. */\nconst PLACEHOLDER = /\\$\\{|^\\$[A-Za-z_]/;\n\n/**\n * A token with no issuer format: long, URL-safe, mixing upper case, lower case and digits, and\n * switching between them constantly.\n *\n * Requiring all three classes leaves out UUIDs, hex digests and commit hashes, which are lower\n * case and far more often an identifier than a secret. Requiring the switching leaves out long\n * names: `AnthropicClaudeDesktopExtension2025` has every class but changes class six times in\n * thirty-five characters, where a random token changes on most of them.\n */\nfunction looksRandom(value: string): boolean {\n if (value.length < 32 || !/^[A-Za-z0-9_-]+$/.test(value)) return false;\n if (!/[a-z]/.test(value) || !/[A-Z]/.test(value) || !/[0-9]/.test(value)) return false;\n const kind = (character: string) => (/[a-z]/.test(character) ? 0 : /[A-Z]/.test(character) ? 1 : /[0-9]/.test(character) ? 2 : 3);\n let switches = 0;\n for (let index = 1; index < value.length; index += 1) {\n if (kind(value[index] ?? \"\") !== kind(value[index - 1] ?? \"\")) switches += 1;\n }\n return switches >= value.length / 3;\n}\n\n/** `decodeURIComponent`, for a check: a malformed escape is just text. */\nfunction decoded(value: string): string {\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\n/** A value worth replacing when its name already says it is a credential. */\nfunction isSecretValue(value: string): boolean {\n if (value === \"\" || value === REDACTED || PLACEHOLDER.test(value)) return false;\n // A path or a URL names where the secret lives, not the secret: `--token-file`-style use.\n if (/^(?:[./~]|[A-Za-z]:\\\\|[a-z][a-z0-9+.-]*:\\/\\/)/i.test(value)) return false;\n return true;\n}\n\n/** Replaces each issuer-formatted credential inside a value, leaving the rest of it readable. */\nfunction redactFormats(value: string): string {\n let out = value;\n for (const format of ISSUER_FORMATS) out = out.replace(format, REDACTED);\n return out;\n}\n\n/*\n * Hosts that serve code from a path naming what it is: a commit (`/acme/server/1f2e...4c/main.ts`),\n * a gist, a tarball of a ref. The long hex segment there is the version being run, not a key, and\n * replacing it made a launcher that swapped one commit for another compare clean. Credentials on\n * these hosts travel in the query or the userinfo, which are still redacted, as is any segment in\n * an issuer's credential format.\n */\nconst CODE_HOSTS = new Set([\n \"github.com\",\n \"raw.githubusercontent.com\",\n \"codeload.github.com\",\n \"gist.github.com\",\n \"gist.githubusercontent.com\",\n \"api.github.com\",\n \"gitlab.com\",\n \"bitbucket.org\",\n \"cdn.jsdelivr.net\",\n \"esm.sh\",\n \"deno.land\",\n]);\n\n/** In a URL inside an argument: the password, credential parameters in the query or fragment, key path segments. */\nfunction redactUrl(value: string): string {\n if (!/^[a-z][a-z0-9+.-]*:\\/\\//i.test(value)) return value;\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return redactPairs(value);\n }\n let changed = false;\n if (url.password && !PLACEHOLDER.test(decoded(url.password))) {\n url.password = REDACTED;\n changed = true;\n }\n for (const [key, parameter] of [...url.searchParams]) {\n if (isCredentialName(key) && isSecretValue(parameter)) {\n url.searchParams.set(key, REDACTED);\n changed = true;\n }\n }\n const path = redactPath(url.pathname, { contentAddressed: CODE_HOSTS.has(url.hostname.toLowerCase()) });\n if (path !== url.pathname) {\n url.pathname = path;\n changed = true;\n }\n const hash = url.hash ? redactPairs(url.hash) : url.hash;\n if (hash !== url.hash) {\n url.hash = hash;\n changed = true;\n }\n return changed ? url.toString() : value;\n}\n\n/**\n * `name=value` pairs inside a larger string whose name is a credential: a query string a URL\n * parser would not take (`jdbc:postgresql://...&password=`), a fragment (`#access_token=`), a\n * connection string (`Server=db;Password=...`).\n */\nfunction redactPairs(text: string): string {\n return text.replace(/(^|[?&;#\\s,])([A-Za-z_][A-Za-z0-9_.-]*)=([^&;#\\s,]*)/g, (whole, lead: string, name: string, value: string) =>\n isCredentialName(name) && isSecretValue(value) ? `${lead}${name}=${REDACTED}` : whole,\n );\n}\n\n/** A header written as `Name: value`, for a header that is a credential. */\nfunction redactHeader(text: string): string | undefined {\n const header = /^([A-Za-z][A-Za-z0-9-]*)\\s*:\\s*(\\S.*)$/s.exec(text);\n if (!header) return undefined;\n const [, name = \"\", value = \"\"] = header;\n if (!(CREDENTIAL_HEADERS.has(name.toLowerCase()) || isCredentialName(name)) || PLACEHOLDER.test(value)) return undefined;\n return `${name}: ${REDACTED}`;\n}\n\n/** JSON in an argument (`--config {\"braveApiKey\":\"...\"}`), its credential-named values replaced. */\nfunction redactJson(text: string): string | undefined {\n if (!/^\\s*[[{]/.test(text)) return undefined;\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n return undefined;\n }\n let changed = false;\n const walk = (node: unknown): unknown => {\n if (Array.isArray(node)) return node.map(walk);\n if (node !== null && typeof node === \"object\") {\n const out: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n for (const [key, child] of Object.entries(node)) {\n if (typeof child === \"string\" && isCredentialName(key) && isSecretValue(child)) {\n out[key] = REDACTED;\n changed = true;\n } else if (typeof child === \"string\") {\n const next = redactText(child);\n if (next !== child) changed = true;\n out[key] = next;\n } else {\n out[key] = walk(child);\n }\n }\n return out;\n }\n return node;\n };\n const result = walk(parsed);\n return changed ? JSON.stringify(result) : undefined;\n}\n\n/** Everything that can hide a credential inside one string, in the order that keeps the rest readable. */\nfunction redactText(text: string): string {\n if (PLACEHOLDER.test(text) && !/[?&;#]/.test(text)) return text;\n if (looksRandom(text)) return REDACTED;\n const json = redactJson(text);\n if (json !== undefined) return json;\n const header = redactHeader(text);\n if (header !== undefined) return header;\n return redactFormats(redactPairs(redactUrl(text)));\n}\n\n/**\n * `args` with every credential written literally in them replaced by {@link REDACTED}.\n *\n * Handles a flag and its value (`--api-key KEY`, `--api-key=KEY`), an environment assignment in\n * an argument (`-e GITHUB_TOKEN=ghp_...`, as `docker run` takes them), a URL's password or\n * credential query parameter, an issuer-formatted token anywhere, and an argument that is nothing\n * but a long random token. Arguments are returned in place and in order, so a change to anything\n * else about how a server is started is still drift.\n */\nexport function redactArgs(args: readonly string[]): string[] {\n const out = [...args];\n for (let index = 0; index < out.length; index += 1) {\n const argument = out[index] ?? \"\";\n\n // `--name=value`, `-n=value`, and `NAME=value` (an environment assignment).\n const assignment = /^(-{0,2}[A-Za-z][A-Za-z0-9_.-]*)=(.*)$/s.exec(argument);\n if (assignment) {\n const [, name = \"\", value = \"\"] = assignment;\n if (isCredentialName(name) && isSecretValue(value)) {\n out[index] = `${name}=${REDACTED}`;\n continue;\n }\n // Any other assignment: its value can still hold a header, a URL with a password, JSON, a token.\n if (!PLACEHOLDER.test(value) || /[?&;#]/.test(value)) out[index] = `${name}=${redactText(value)}`;\n continue;\n }\n\n // `--name value`: the flag names a credential, so the next argument is one.\n const flag = /^-{1,2}([A-Za-z][A-Za-z0-9_.-]*)$/.exec(argument);\n const next = out[index + 1];\n if (flag && next !== undefined && !next.startsWith(\"-\")) {\n const name = flag[1] ?? \"\";\n if (isCredentialName(name) && isSecretValue(next) && !looksLikeAnOperand(next)) {\n out[index + 1] = REDACTED;\n index += 1;\n continue;\n }\n // `-u user:password`, `--user user:password`: curl's form, and every tool that copied it.\n if ([\"u\", \"user\", \"basic-auth\"].includes(name.toLowerCase()) && /^[^:\\s]+:[^\\s]+$/.test(next) && !PLACEHOLDER.test(next)) {\n out[index + 1] = `${next.slice(0, next.indexOf(\":\"))}:${REDACTED}`;\n index += 1;\n continue;\n }\n }\n\n out[index] = redactText(argument);\n }\n return out;\n}\n\n/**\n * Whether the word after a flag is more likely the next operand than the flag's value: a script, a\n * package, a path. A boolean credential flag (`--auth`) followed by `server.js` is not a key.\n */\nfunction looksLikeAnOperand(value: string): boolean {\n return value.startsWith(\"@\") || value.includes(\"/\") || /\\.(m?[jt]s|cjs|py|json|ya?ml|toml|sh|exe)$/i.test(value);\n}\n\n/*\n * Path words that say the next part of the path names a revision: `raw`, `blob`, `tree`, `commit`\n * on GitHub and every forge that copied its URLs (GitHub Enterprise, GitLab, Gitea, Forgejo,\n * sourcehut), `archive` for a tarball of one, and gitiles' `+`.\n *\n * The code-host list above covers the public forges by name, and a self-hosted one has a name no\n * list can hold: `github.acme-corp.com/raw/acme/srv/<sha>/server.py` had its commit replaced as a\n * key, so swapping one commit for another compared clean. Found in a security review. A segment\n * is kept only when it is exactly the length of a commit id -- 40 hex characters for SHA-1, 64\n * for SHA-256 -- and follows one of these words, so a 32-character key under `/raw/` is still a key.\n */\nconst REVISION_WORDS = new Set([\"raw\", \"blob\", \"blobs\", \"tree\", \"trees\", \"commit\", \"commits\", \"archive\", \"src\", \"+\"]);\nconst COMMIT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;\n\n/**\n * A URL path with any segment that is a credential replaced, for hosted servers whose address\n * embeds the key (`https://host/api/<token>/mcp`). The rest of the path stays, so a server that\n * moves to a different path or host is still drift.\n */\nexport function redactPath(pathname: string, options: { contentAddressed?: boolean } = {}): string {\n let revisionPath = false;\n return pathname\n .split(\"/\")\n .map((segment) => {\n const afterRevisionWord = revisionPath;\n if (REVISION_WORDS.has(decoded(segment).toLowerCase())) revisionPath = true;\n if (segment === \"\" || PLACEHOLDER.test(decoded(segment))) return segment;\n if (looksRandom(segment)) return REDACTED;\n // A UUID or a long hex string in a hosted server's address is its key far more often than\n // not (Pipedream, Composio and the like put the account's key there). On a code host it is\n // a commit or a gist, and it is the thing being pinned; so is a commit id under a path word\n // that says a revision comes next, on any host.\n const commit = afterRevisionWord && COMMIT_ID.test(segment);\n if (\n !options.contentAddressed &&\n !commit &&\n (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(segment) || /^[0-9a-f]{32,}$/i.test(segment))\n )\n return REDACTED;\n return redactFormats(segment);\n })\n .join(\"/\");\n}\n\n/** How many credentials were left out of a locked transport, for saying so. */\nexport function countRedacted(transport: { args?: readonly string[]; url?: string }): number {\n const occurrences = (text: string) => text.split(REDACTED).length - 1;\n return (transport.args ?? []).reduce((total, argument) => total + occurrences(argument), 0) + occurrences(transport.url ?? \"\");\n}\n"],"m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
|
+
beginWalk,
|
|
6
|
+
effectiveSchema,
|
|
7
|
+
entriesOf,
|
|
8
|
+
shadowedIn
|
|
9
|
+
} from "./chunk-Z4M6ZRTP.js";
|
|
10
|
+
import {
|
|
11
|
+
canonicalize,
|
|
12
|
+
stableKey
|
|
13
|
+
} from "./chunk-SZKRNTJP.js";
|
|
14
|
+
|
|
15
|
+
// src/diff/schema.ts
|
|
16
|
+
var LOWER_BOUNDS = ["minimum", "exclusiveMinimum", "minLength", "minItems", "minProperties", "minContains"];
|
|
17
|
+
var UPPER_BOUNDS = ["maximum", "exclusiveMaximum", "maxLength", "maxItems", "maxProperties", "maxContains"];
|
|
18
|
+
var OPAQUE = [
|
|
19
|
+
"pattern",
|
|
20
|
+
"format",
|
|
21
|
+
"multipleOf",
|
|
22
|
+
"uniqueItems",
|
|
23
|
+
"not",
|
|
24
|
+
"if",
|
|
25
|
+
"contains",
|
|
26
|
+
"propertyNames",
|
|
27
|
+
"dependentRequired",
|
|
28
|
+
"dependentSchemas",
|
|
29
|
+
"dependencies",
|
|
30
|
+
"unevaluatedProperties",
|
|
31
|
+
"unevaluatedItems",
|
|
32
|
+
"additionalItems"
|
|
33
|
+
];
|
|
34
|
+
var OPEN_WHEN_EMPTY = /* @__PURE__ */ new Set(["unevaluatedProperties", "unevaluatedItems", "additionalItems", "propertyNames"]);
|
|
35
|
+
var SLOT_KEYWORDS = ["items", "anyOf", "oneOf", "then", "else"];
|
|
36
|
+
var CONSIDERED = /* @__PURE__ */ new Set([...LOWER_BOUNDS, ...UPPER_BOUNDS, ...OPAQUE, ...SLOT_KEYWORDS]);
|
|
37
|
+
var MEMBERS = /* @__PURE__ */ new Set(["properties", "patternProperties", "prefixItems"]);
|
|
38
|
+
function isOpen(value) {
|
|
39
|
+
if (value === true) return true;
|
|
40
|
+
const object = asObject(value);
|
|
41
|
+
return object !== void 0 && Object.keys(object).length === 0;
|
|
42
|
+
}
|
|
43
|
+
function isVacuous(keyword, value) {
|
|
44
|
+
if (value === false) return keyword === "uniqueItems" || keyword === "exclusiveMinimum" || keyword === "exclusiveMaximum";
|
|
45
|
+
return OPEN_WHEN_EMPTY.has(keyword) && isOpen(value);
|
|
46
|
+
}
|
|
47
|
+
function typesOf(values) {
|
|
48
|
+
const types = /* @__PURE__ */ new Set();
|
|
49
|
+
for (const value of values) {
|
|
50
|
+
if (value === null) types.add("null");
|
|
51
|
+
else if (Array.isArray(value)) types.add("array");
|
|
52
|
+
else if (typeof value === "number") types.add(Number.isInteger(value) ? "integer" : "number");
|
|
53
|
+
else types.add(typeof value);
|
|
54
|
+
}
|
|
55
|
+
return types;
|
|
56
|
+
}
|
|
57
|
+
function ownValues(object) {
|
|
58
|
+
let values = Array.isArray(object["enum"]) ? object["enum"] : void 0;
|
|
59
|
+
const consts = [...Object.hasOwn(object, "const") ? [object["const"]] : [], ...shadowedIn(object)?.keywords.get("const") ?? []];
|
|
60
|
+
for (const value of consts) {
|
|
61
|
+
const key = canonicalize(value);
|
|
62
|
+
values = values === void 0 ? [value] : values.filter((member) => canonicalize(member) === key);
|
|
63
|
+
}
|
|
64
|
+
const typeValue = object["type"];
|
|
65
|
+
let types = typeof typeValue === "string" ? /* @__PURE__ */ new Set([typeValue]) : Array.isArray(typeValue) ? new Set(typeValue.filter((entry) => typeof entry === "string")) : void 0;
|
|
66
|
+
if (types === void 0 && values !== void 0) types = typesOf(values);
|
|
67
|
+
return { types, members: values === void 0 ? void 0 : new Set(values.map((member) => canonicalize(member))) };
|
|
68
|
+
}
|
|
69
|
+
function unionOfBranches(branches, root) {
|
|
70
|
+
let types = /* @__PURE__ */ new Set();
|
|
71
|
+
let members = /* @__PURE__ */ new Set();
|
|
72
|
+
let counted = 0;
|
|
73
|
+
for (const branch of branches) {
|
|
74
|
+
if (branch === false) continue;
|
|
75
|
+
const object = effectiveSchema(branch, root);
|
|
76
|
+
if (object === void 0) return {};
|
|
77
|
+
const own = ownValues(object);
|
|
78
|
+
const onlyNull = own.members === void 0 ? own.types?.size === 1 && own.types.has("null") : own.members.size === 1 && own.members.has("null");
|
|
79
|
+
if (onlyNull) continue;
|
|
80
|
+
counted += 1;
|
|
81
|
+
if (types) {
|
|
82
|
+
if (own.types) for (const type of own.types) types.add(type);
|
|
83
|
+
else types = void 0;
|
|
84
|
+
}
|
|
85
|
+
if (members) {
|
|
86
|
+
if (own.members) for (const member of own.members) members.add(member);
|
|
87
|
+
else members = void 0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return counted === 0 ? {} : { types, members };
|
|
91
|
+
}
|
|
92
|
+
var constraintCache = /* @__PURE__ */ new WeakMap();
|
|
93
|
+
function constraintsOf(object, root) {
|
|
94
|
+
const key = root !== null && typeof root === "object" ? root : constraintCache;
|
|
95
|
+
let cache = constraintCache.get(key);
|
|
96
|
+
if (!cache) {
|
|
97
|
+
cache = /* @__PURE__ */ new WeakMap();
|
|
98
|
+
constraintCache.set(key, cache);
|
|
99
|
+
}
|
|
100
|
+
const known = cache.get(object);
|
|
101
|
+
if (known) return known;
|
|
102
|
+
let { types, members } = ownValues(object);
|
|
103
|
+
if (types === void 0 || members === void 0) {
|
|
104
|
+
const anyOf = Array.isArray(object["anyOf"]) ? object["anyOf"] : void 0;
|
|
105
|
+
const oneOf = Array.isArray(object["oneOf"]) ? object["oneOf"] : void 0;
|
|
106
|
+
const branches = anyOf && !oneOf ? anyOf : oneOf && !anyOf ? oneOf : void 0;
|
|
107
|
+
if (branches) {
|
|
108
|
+
const union = unionOfBranches(branches, root);
|
|
109
|
+
types ??= union.types;
|
|
110
|
+
members ??= union.members;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const lower = /* @__PURE__ */ new Map();
|
|
114
|
+
const upper = /* @__PURE__ */ new Map();
|
|
115
|
+
const opaque = /* @__PURE__ */ new Map();
|
|
116
|
+
const constrain = (keyword, value) => {
|
|
117
|
+
if (isVacuous(keyword, value)) return;
|
|
118
|
+
let values = opaque.get(keyword);
|
|
119
|
+
if (!values) {
|
|
120
|
+
values = /* @__PURE__ */ new Set();
|
|
121
|
+
opaque.set(keyword, values);
|
|
122
|
+
}
|
|
123
|
+
values.add(canonicalize(value));
|
|
124
|
+
};
|
|
125
|
+
for (const [keywords, bounds] of [[LOWER_BOUNDS, lower], [UPPER_BOUNDS, upper]]) {
|
|
126
|
+
for (const keyword of keywords) {
|
|
127
|
+
const value = object[keyword];
|
|
128
|
+
if (typeof value === "number") bounds.set(keyword, value);
|
|
129
|
+
else if (value !== void 0) constrain(keyword, value);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const keyword of OPAQUE) if (object[keyword] !== void 0) constrain(keyword, object[keyword]);
|
|
133
|
+
const shadow = shadowedIn(object);
|
|
134
|
+
if (shadow) {
|
|
135
|
+
for (const [keyword, values] of shadow.keywords) if (CONSIDERED.has(keyword)) for (const value of values) constrain(keyword, value);
|
|
136
|
+
for (const [name, values] of shadow.properties) for (const value of values) constrain(`\0properties\0${name}`, value);
|
|
137
|
+
}
|
|
138
|
+
const slots = /* @__PURE__ */ new Set();
|
|
139
|
+
const items = object["items"];
|
|
140
|
+
if (items !== void 0 && !Array.isArray(items) && !isOpen(items)) slots.add("items");
|
|
141
|
+
for (const keyword of ["anyOf", "oneOf"]) if (Array.isArray(object[keyword])) slots.add(keyword);
|
|
142
|
+
for (const keyword of ["then", "else"]) if (object[keyword] !== void 0 && !isOpen(object[keyword])) slots.add(keyword);
|
|
143
|
+
const additionalValue = object["additionalProperties"];
|
|
144
|
+
const required = Array.isArray(object["required"]) ? object["required"] : [];
|
|
145
|
+
const constraints = {
|
|
146
|
+
additional: additionalValue === false ? 0 : asObject(additionalValue) !== void 0 && !isOpen(additionalValue) ? 1 : 2,
|
|
147
|
+
enumMembers: members,
|
|
148
|
+
types,
|
|
149
|
+
lower,
|
|
150
|
+
upper,
|
|
151
|
+
opaque,
|
|
152
|
+
slots,
|
|
153
|
+
requiredNames: new Set(required.filter((entry) => typeof entry === "string"))
|
|
154
|
+
};
|
|
155
|
+
cache.set(object, constraints);
|
|
156
|
+
return constraints;
|
|
157
|
+
}
|
|
158
|
+
var Routes = class {
|
|
159
|
+
names = /* @__PURE__ */ new Map();
|
|
160
|
+
ids = /* @__PURE__ */ new Map();
|
|
161
|
+
child(parent, keyword, name) {
|
|
162
|
+
let nameId = this.names.get(name);
|
|
163
|
+
if (nameId === void 0) {
|
|
164
|
+
nameId = this.names.size;
|
|
165
|
+
this.names.set(name, nameId);
|
|
166
|
+
}
|
|
167
|
+
const key = `${parent} ${keyword} ${nameId}`;
|
|
168
|
+
let id = this.ids.get(key);
|
|
169
|
+
if (id === void 0) {
|
|
170
|
+
id = this.ids.size + 1;
|
|
171
|
+
this.ids.set(key, id);
|
|
172
|
+
}
|
|
173
|
+
return id;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
function collectFacts(schema, routes) {
|
|
177
|
+
const facts = /* @__PURE__ */ new Map();
|
|
178
|
+
let budget = MAX_FACTS;
|
|
179
|
+
const visit = (node, id, parent, via, required, depth) => {
|
|
180
|
+
if (depth > MAX_VISIT_DEPTH || budget <= 0) return;
|
|
181
|
+
budget -= 1;
|
|
182
|
+
const object = effectiveSchema(node, schema);
|
|
183
|
+
if (!object) return;
|
|
184
|
+
const constraints = constraintsOf(object, schema);
|
|
185
|
+
facts.set(id, { parent, via, required, node: constraints });
|
|
186
|
+
if (depth >= MAX_VISIT_DEPTH) return;
|
|
187
|
+
const into = (keyword, name, child, isRequired = false) => {
|
|
188
|
+
if (budget <= 0) return false;
|
|
189
|
+
if (child !== void 0) visit(child, routes.child(id, keyword, name), id, keyword, isRequired, depth + 1);
|
|
190
|
+
return true;
|
|
191
|
+
};
|
|
192
|
+
const properties = asObject(object["properties"]);
|
|
193
|
+
if (properties) {
|
|
194
|
+
for (const [name, child] of entriesOf(properties)) if (!into("properties", name, child, constraints.requiredNames.has(name))) return;
|
|
195
|
+
}
|
|
196
|
+
const patternProperties = asObject(object["patternProperties"]);
|
|
197
|
+
if (patternProperties) {
|
|
198
|
+
for (const [pattern, child] of entriesOf(patternProperties)) if (!into("patternProperties", pattern, child)) return;
|
|
199
|
+
}
|
|
200
|
+
for (const keyword of ["prefixItems", "items"]) {
|
|
201
|
+
const tuple = object[keyword];
|
|
202
|
+
if (!Array.isArray(tuple)) continue;
|
|
203
|
+
for (let index = 0; index < tuple.length; index += 1) if (!into("prefixItems", String(index), tuple[index])) return;
|
|
204
|
+
}
|
|
205
|
+
if (constraints.slots.has("items") && !into("items", "", object["items"])) return;
|
|
206
|
+
if (constraints.additional === 1 && !into("additionalProperties", "", object["additionalProperties"])) return;
|
|
207
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
208
|
+
const branches = object[keyword];
|
|
209
|
+
if (!Array.isArray(branches)) continue;
|
|
210
|
+
for (let index = 0; index < branches.length; index += 1) if (!into(keyword, String(index), branches[index])) return;
|
|
211
|
+
}
|
|
212
|
+
for (const keyword of ["then", "else"]) if (constraints.slots.has(keyword) && !into(keyword, "", object[keyword])) return;
|
|
213
|
+
};
|
|
214
|
+
beginWalk(schema);
|
|
215
|
+
visit(schema, 0, void 0, "", true, 0);
|
|
216
|
+
return facts;
|
|
217
|
+
}
|
|
218
|
+
function isSuperset(next, previous) {
|
|
219
|
+
if (previous.size > next.size) return false;
|
|
220
|
+
for (const entry of previous) if (!next.has(entry)) return false;
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
function covers(types, type) {
|
|
224
|
+
return types.has(type) || type === "integer" && types.has("number");
|
|
225
|
+
}
|
|
226
|
+
function compareConstraints(a, b) {
|
|
227
|
+
let widened = false;
|
|
228
|
+
let narrowed = false;
|
|
229
|
+
if (b.additional > a.additional) widened = true;
|
|
230
|
+
else if (b.additional < a.additional) narrowed = true;
|
|
231
|
+
if (a.enumMembers && b.enumMembers) {
|
|
232
|
+
if (!isSuperset(b.enumMembers, a.enumMembers)) narrowed = true;
|
|
233
|
+
if (!isSuperset(a.enumMembers, b.enumMembers)) widened = true;
|
|
234
|
+
} else if (a.enumMembers && !b.enumMembers) widened = true;
|
|
235
|
+
else if (!a.enumMembers && b.enumMembers) narrowed = true;
|
|
236
|
+
if (a.types && b.types) {
|
|
237
|
+
for (const type of b.types) if (!covers(a.types, type)) widened = true;
|
|
238
|
+
for (const type of a.types) if (!covers(b.types, type)) narrowed = true;
|
|
239
|
+
} else if (a.types && !b.types) widened = true;
|
|
240
|
+
else if (!a.types && b.types) narrowed = true;
|
|
241
|
+
for (const [keyword, before] of a.lower) {
|
|
242
|
+
const after = b.lower.get(keyword);
|
|
243
|
+
if (after === void 0 || after < before) widened = true;
|
|
244
|
+
if (after !== void 0 && after > before) narrowed = true;
|
|
245
|
+
}
|
|
246
|
+
for (const keyword of b.lower.keys()) if (!a.lower.has(keyword)) narrowed = true;
|
|
247
|
+
for (const [keyword, before] of a.upper) {
|
|
248
|
+
const after = b.upper.get(keyword);
|
|
249
|
+
if (after === void 0 || after > before) widened = true;
|
|
250
|
+
if (after !== void 0 && after < before) narrowed = true;
|
|
251
|
+
}
|
|
252
|
+
for (const keyword of b.upper.keys()) if (!a.upper.has(keyword)) narrowed = true;
|
|
253
|
+
for (const [keyword, before] of a.opaque) {
|
|
254
|
+
const after = b.opaque.get(keyword);
|
|
255
|
+
if (!after || !isSuperset(after, before)) widened = true;
|
|
256
|
+
if (after && !isSuperset(before, after)) narrowed = true;
|
|
257
|
+
}
|
|
258
|
+
for (const keyword of b.opaque.keys()) if (!a.opaque.has(keyword)) narrowed = true;
|
|
259
|
+
for (const keyword of a.slots) if (!b.slots.has(keyword)) widened = true;
|
|
260
|
+
for (const keyword of b.slots) if (!a.slots.has(keyword)) narrowed = true;
|
|
261
|
+
return { widened, narrowed };
|
|
262
|
+
}
|
|
263
|
+
function classifySchemaChange(before, after) {
|
|
264
|
+
if (stableKey(before) === stableKey(after)) return "same";
|
|
265
|
+
const routes = new Routes();
|
|
266
|
+
const previous = collectFacts(before, routes);
|
|
267
|
+
const next = collectFacts(after, routes);
|
|
268
|
+
let widened = false;
|
|
269
|
+
let narrowed = false;
|
|
270
|
+
const compared = /* @__PURE__ */ new Map();
|
|
271
|
+
const oneSided = (fact, arrived) => {
|
|
272
|
+
const counterpart = fact.parent === void 0 ? void 0 : (arrived ? previous : next).get(fact.parent);
|
|
273
|
+
if (counterpart === void 0) {
|
|
274
|
+
if (arrived && MEMBERS.has(fact.via)) widened = true;
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (MEMBERS.has(fact.via) || counterpart.node.slots.has(fact.via)) {
|
|
278
|
+
if (arrived) widened = true;
|
|
279
|
+
else narrowed = true;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
for (const [id, a] of previous) {
|
|
283
|
+
const b = next.get(id);
|
|
284
|
+
if (!b) {
|
|
285
|
+
oneSided(a, false);
|
|
286
|
+
} else {
|
|
287
|
+
if (a.required && !b.required) widened = true;
|
|
288
|
+
if (!a.required && b.required) narrowed = true;
|
|
289
|
+
if (a.node !== b.node) {
|
|
290
|
+
let row = compared.get(a.node);
|
|
291
|
+
if (!row) {
|
|
292
|
+
row = /* @__PURE__ */ new Map();
|
|
293
|
+
compared.set(a.node, row);
|
|
294
|
+
}
|
|
295
|
+
let direction = row.get(b.node);
|
|
296
|
+
if (!direction) {
|
|
297
|
+
direction = compareConstraints(a.node, b.node);
|
|
298
|
+
row.set(b.node, direction);
|
|
299
|
+
}
|
|
300
|
+
if (direction.widened) widened = true;
|
|
301
|
+
if (direction.narrowed) narrowed = true;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (widened && narrowed) return "changed";
|
|
305
|
+
}
|
|
306
|
+
for (const [id, b] of next) if (!previous.has(id)) oneSided(b, true);
|
|
307
|
+
if (widened && !narrowed) return "widened";
|
|
308
|
+
if (narrowed && !widened) return "narrowed";
|
|
309
|
+
return "changed";
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export {
|
|
313
|
+
classifySchemaChange
|
|
314
|
+
};
|
|
315
|
+
//# sourceMappingURL=chunk-NSVG7BEU.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 { asObject, beginWalk, effectiveSchema, entriesOf, MAX_FACTS, MAX_VISIT_DEPTH, shadowedIn } from \"../lock/jsonschema\";\nimport type { JsonObject, JsonValue } from \"../lock/types\";\n\nexport type SchemaVerdict = \"widened\" | \"narrowed\" | \"changed\" | \"same\";\n\n/** What one node accepts, read from its effective schema. Shared by every route that reaches the node. */\ninterface Constraints {\n /** `additionalProperties`: `false`, a schema, or anything -- in order of how much each lets through. */\n additional: 0 | 1 | 2;\n enumMembers?: ReadonlySet<string>;\n types?: ReadonlySet<string>;\n lower: ReadonlyMap<string, number>;\n upper: ReadonlyMap<string, number>;\n /** Keywords read only as present, absent or different, with every value of each that applies. */\n opaque: ReadonlyMap<string, ReadonlySet<string>>;\n /** Keywords holding a subschema the input must also match: `items`, `anyOf`, `oneOf`, `then`, `else`. */\n slots: ReadonlySet<string>;\n requiredNames: ReadonlySet<string>;\n}\n\ninterface Fact {\n /** The route of the fact this one hangs from; undefined at the root. */\n parent?: number;\n /** The keyword it was reached through. */\n via: string;\n required: boolean;\n node: Constraints;\n}\n\nconst LOWER_BOUNDS = [\"minimum\", \"exclusiveMinimum\", \"minLength\", \"minItems\", \"minProperties\", \"minContains\"];\nconst UPPER_BOUNDS = [\"maximum\", \"exclusiveMaximum\", \"maxLength\", \"maxItems\", \"maxProperties\", \"maxContains\"];\n\n/*\n * Keywords the heuristic does not read inside, but whose direction is not in doubt: each one only\n * ever excludes input. One that disappears lets more through and one that appears lets less, and\n * one that changes could go either way. They had no slot at all, so taking a path guard off a file\n * tool -- `pattern: \"^/srv/data/[a-z]+$\"` -- was a bare `changed`, and beside any narrowing\n * elsewhere it read as a narrowing.\n *\n * `not` is among them rather than walked as a branch. Walked, a `not` added read as new facts, a\n * widening, when it excludes input.\n */\nconst OPAQUE = [\n \"pattern\", \"format\", \"multipleOf\", \"uniqueItems\", \"not\", \"if\", \"contains\", \"propertyNames\", \"dependentRequired\",\n \"dependentSchemas\", \"dependencies\", \"unevaluatedProperties\", \"unevaluatedItems\", \"additionalItems\",\n];\n/** Opaque keywords whose `true` or `{}` constrains nothing, and so is the same as their absence. */\nconst OPEN_WHEN_EMPTY = new Set([\"unevaluatedProperties\", \"unevaluatedItems\", \"additionalItems\", \"propertyNames\"]);\nconst SLOT_KEYWORDS = [\"items\", \"anyOf\", \"oneOf\", \"then\", \"else\"];\nconst CONSIDERED = new Set([...LOWER_BOUNDS, ...UPPER_BOUNDS, ...OPAQUE, ...SLOT_KEYWORDS]);\n\n/*\n * Reached through one of these, a node is one more thing the input may hold, so its arrival is a\n * widening and its departure a narrowing. A new property is a widening even when it is optional:\n * it enlarges what the agent may be induced to send.\n *\n * Reached through anything else -- `items`, a branch of `anyOf`, `then` -- a node is a constraint\n * the input must also meet, and whether that constraint came or went is read off the parent.\n */\nconst MEMBERS = new Set([\"properties\", \"patternProperties\", \"prefixItems\"]);\n\nfunction isOpen(value: JsonValue | undefined): boolean {\n if (value === true) return true;\n const object = asObject(value);\n return object !== undefined && Object.keys(object).length === 0;\n}\n\nfunction isVacuous(keyword: string, value: JsonValue): boolean {\n if (value === false) return keyword === \"uniqueItems\" || keyword === \"exclusiveMinimum\" || keyword === \"exclusiveMaximum\";\n return OPEN_WHEN_EMPTY.has(keyword) && isOpen(value);\n}\n\n/** The JSON types of some values: what an `enum` or a `const` says about `type`. */\nfunction typesOf(values: readonly JsonValue[]): Set<string> {\n const types = new Set<string>();\n for (const value of values) {\n if (value === null) types.add(\"null\");\n else if (Array.isArray(value)) types.add(\"array\");\n else if (typeof value === \"number\") types.add(Number.isInteger(value) ? \"integer\" : \"number\");\n else types.add(typeof value);\n }\n return types;\n}\n\n/** `type`, `enum` and `const` at one node, before anything is inferred from its branches. */\nfunction ownValues(object: JsonObject): { types?: Set<string>; members?: Set<string> } {\n let values = Array.isArray(object[\"enum\"]) ? (object[\"enum\"] as JsonValue[]) : undefined;\n // A `const` is an enum of one, and every `const` that applies must hold.\n const consts = [...(Object.hasOwn(object, \"const\") ? [object[\"const\"] as JsonValue] : []), ...(shadowedIn(object)?.keywords.get(\"const\") ?? [])];\n for (const value of consts) {\n const key = canonicalize(value);\n values = values === undefined ? [value] : values.filter((member) => canonicalize(member) === key);\n }\n const typeValue = object[\"type\"];\n let types =\n typeof typeValue === \"string\"\n ? new Set([typeValue])\n : Array.isArray(typeValue)\n ? new Set(typeValue.filter((entry): entry is string => typeof entry === \"string\"))\n : undefined;\n if (types === undefined && values !== undefined) types = typesOf(values);\n return { types, members: values === undefined ? undefined : new Set(values.map((member) => canonicalize(member))) };\n}\n\n/*\n * What an alternation allows, for a node that says nothing itself: the union over its branches.\n * Without it, `anyOf: [{const: \"users\"}, {const: \"orders\"}]` replaced by `type: \"string\"` gained a\n * type and lost nothing anyone could see. A branch that is only `null` is how Pydantic writes\n * `Optional[...]` -- the argument may be left out -- and is not counted as a value the tool takes,\n * so `Optional[Literal[\"read\"]]` reads as \"read\", and its replacement by any string as a widening.\n */\nfunction unionOfBranches(branches: readonly JsonValue[], root: JsonValue): { types?: Set<string>; members?: Set<string> } {\n let types: Set<string> | undefined = new Set();\n let members: Set<string> | undefined = new Set();\n let counted = 0;\n for (const branch of branches) {\n if (branch === false) continue;\n const object = effectiveSchema(branch, root);\n // `true`, or not a schema at all: this branch allows anything.\n if (object === undefined) return {};\n const own = ownValues(object);\n const onlyNull = own.members === undefined ? own.types?.size === 1 && own.types.has(\"null\") : own.members.size === 1 && own.members.has(\"null\");\n if (onlyNull) continue;\n counted += 1;\n if (types) {\n if (own.types) for (const type of own.types) types.add(type);\n else types = undefined;\n }\n if (members) {\n if (own.members) for (const member of own.members) members.add(member);\n else members = undefined;\n }\n }\n return counted === 0 ? {} : { types, members };\n}\n\nconst constraintCache = new WeakMap<object, WeakMap<JsonObject, Constraints>>();\n\n/*\n * Worked out once per node and schema. A node reached by a thousand routes is the same node, and\n * reading a long enum or a long `required` again for each of them is how a schema of a few\n * kilobytes costs minutes.\n */\nfunction constraintsOf(object: JsonObject, root: JsonValue): Constraints {\n const key = root !== null && typeof root === \"object\" ? root : constraintCache;\n let cache = constraintCache.get(key);\n if (!cache) {\n cache = new WeakMap();\n constraintCache.set(key, cache);\n }\n const known = cache.get(object);\n if (known) return known;\n\n let { types, members } = ownValues(object);\n if (types === undefined || members === undefined) {\n const anyOf = Array.isArray(object[\"anyOf\"]) ? (object[\"anyOf\"] as JsonValue[]) : undefined;\n const oneOf = Array.isArray(object[\"oneOf\"]) ? (object[\"oneOf\"] as JsonValue[]) : undefined;\n const branches = anyOf && !oneOf ? anyOf : oneOf && !anyOf ? oneOf : undefined;\n if (branches) {\n const union = unionOfBranches(branches, root);\n types ??= union.types;\n members ??= union.members;\n }\n }\n\n const lower = new Map<string, number>();\n const upper = new Map<string, number>();\n const opaque = new Map<string, Set<string>>();\n const constrain = (keyword: string, value: JsonValue): void => {\n if (isVacuous(keyword, value)) return;\n let values = opaque.get(keyword);\n if (!values) {\n values = new Set();\n opaque.set(keyword, values);\n }\n values.add(canonicalize(value));\n };\n for (const [keywords, bounds] of [[LOWER_BOUNDS, lower], [UPPER_BOUNDS, upper]] as const) {\n for (const keyword of keywords) {\n const value = object[keyword];\n if (typeof value === \"number\") bounds.set(keyword, value);\n else if (value !== undefined) constrain(keyword, value); // draft 4's boolean `exclusiveMaximum`\n }\n }\n for (const keyword of OPAQUE) if (object[keyword] !== undefined) constrain(keyword, object[keyword] as JsonValue);\n\n /*\n * What a second `allOf` branch said that the merged node could not hold: a second pattern, a\n * second schema for a property. Each is one more constraint, so it is counted like one.\n */\n const shadow = shadowedIn(object);\n if (shadow) {\n for (const [keyword, values] of shadow.keywords) if (CONSIDERED.has(keyword)) for (const value of values) constrain(keyword, value);\n for (const [name, values] of shadow.properties) for (const value of values) constrain(`\\u0000properties\\u0000${name}`, value);\n }\n\n const slots = new Set<string>();\n const items = object[\"items\"];\n if (items !== undefined && !Array.isArray(items) && !isOpen(items)) slots.add(\"items\");\n for (const keyword of [\"anyOf\", \"oneOf\"]) if (Array.isArray(object[keyword])) slots.add(keyword);\n for (const keyword of [\"then\", \"else\"]) if (object[keyword] !== undefined && !isOpen(object[keyword])) slots.add(keyword);\n\n const additionalValue = object[\"additionalProperties\"];\n const required = Array.isArray(object[\"required\"]) ? (object[\"required\"] as JsonValue[]) : [];\n const constraints: Constraints = {\n additional: additionalValue === false ? 0 : asObject(additionalValue) !== undefined && !isOpen(additionalValue) ? 1 : 2,\n enumMembers: members,\n types,\n lower,\n upper,\n opaque,\n slots,\n requiredNames: new Set(required.filter((entry): entry is string => typeof entry === \"string\")),\n };\n cache.set(object, constraints);\n return constraints;\n}\n\n/*\n * Routes through a schema, numbered, and shared by both sides of a comparison so the same route\n * gets the same number on each.\n *\n * Facts were keyed by property names joined with \".\", \"[]\" and \"|anyOf[0]\", and names may contain\n * any of those. So a property named \"opts.mode\" was the same fact as `mode` inside `opts`: a new\n * argument of that name overwrote the facts of the nested one it mimicked, and a dropped enum\n * there vanished. Worse, every route of the same spelling collapsed into one fact, and the ceiling\n * counted facts: properties \"a\", \"a.a\", \"a.a.a\" and \"a.a.a.a\", each the whole schema again, kept\n * the facts in single figures while the routes to them grew as m^12 -- 112 bytes held `check` for\n * 82 seconds. A number per (parent, keyword, name) cannot be spelled by a name.\n */\nclass Routes {\n private readonly names = new Map<string, number>();\n private readonly ids = new Map<string, number>();\n\n child(parent: number, keyword: string, name: string): number {\n let nameId = this.names.get(name);\n if (nameId === undefined) {\n nameId = this.names.size;\n this.names.set(name, nameId);\n }\n const key = `${parent} ${keyword} ${nameId}`;\n let id = this.ids.get(key);\n if (id === undefined) {\n id = this.ids.size + 1;\n this.ids.set(key, id);\n }\n return id;\n }\n}\n\n/**\n * Flattens a schema into per-route 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 a\n * route of their own, so a branch added to an alternation both sides have shows up as new facts\n * -- a widening -- and a removed one as a narrowing. The alternation as a whole is a constraint,\n * read on its parent (see `slots`).\n *\n * The ceiling counts visits, not facts: a visit is the work, and the facts are only what it\n * leaves behind.\n */\nfunction collectFacts(schema: JsonValue, routes: Routes): Map<number, Fact> {\n const facts = new Map<number, Fact>();\n let budget = MAX_FACTS;\n\n const visit = (node: JsonValue, id: number, parent: number | undefined, via: string, required: boolean, depth: number): void => {\n if (depth > MAX_VISIT_DEPTH || budget <= 0) return;\n budget -= 1;\n const object = effectiveSchema(node, schema);\n if (!object) return;\n const constraints = constraintsOf(object, schema);\n facts.set(id, { parent, via, required, node: constraints });\n // Its children would be past the depth ceiling, and naming a route to each one is the cost.\n if (depth >= MAX_VISIT_DEPTH) return;\n\n // False once the budget is spent, so a node with a million children stops at the first.\n const into = (keyword: string, name: string, child: JsonValue | undefined, isRequired = false): boolean => {\n if (budget <= 0) return false;\n if (child !== undefined) visit(child, routes.child(id, keyword, name), id, keyword, isRequired, depth + 1);\n return true;\n };\n\n const properties = asObject(object[\"properties\"]);\n if (properties) {\n for (const [name, child] of entriesOf(properties)) if (!into(\"properties\", name, child, constraints.requiredNames.has(name))) return;\n }\n const patternProperties = asObject(object[\"patternProperties\"]);\n if (patternProperties) {\n for (const [pattern, child] of entriesOf(patternProperties)) if (!into(\"patternProperties\", pattern, child)) return;\n }\n // `items` as a list is draft 4's `prefixItems`.\n for (const keyword of [\"prefixItems\", \"items\"]) {\n const tuple = object[keyword];\n if (!Array.isArray(tuple)) continue;\n for (let index = 0; index < tuple.length; index += 1) if (!into(\"prefixItems\", String(index), tuple[index])) return;\n }\n if (constraints.slots.has(\"items\") && !into(\"items\", \"\", object[\"items\"])) return;\n if (constraints.additional === 1 && !into(\"additionalProperties\", \"\", object[\"additionalProperties\"])) return;\n for (const keyword of [\"anyOf\", \"oneOf\"]) {\n const branches = object[keyword];\n if (!Array.isArray(branches)) continue;\n for (let index = 0; index < branches.length; index += 1) if (!into(keyword, String(index), branches[index])) return;\n }\n for (const keyword of [\"then\", \"else\"]) if (constraints.slots.has(keyword) && !into(keyword, \"\", object[keyword])) return;\n };\n\n beginWalk(schema);\n visit(schema, 0, undefined, \"\", true, 0);\n return facts;\n}\n\n/**\n * Whether every member of `previous` is in `next`. A set, not `includes` in a loop: that was\n * quadratic, and a server's own schema decides the length, so one enum of a few hundred thousand\n * members held whatever compared it -- the CLI, or a control plane serving every tenant from one\n * thread -- for minutes.\n */\nfunction isSuperset(next: ReadonlySet<string>, previous: ReadonlySet<string>): boolean {\n if (previous.size > next.size) return false;\n for (const entry of previous) if (!next.has(entry)) return false;\n return true;\n}\n\ninterface Direction {\n widened: boolean;\n narrowed: boolean;\n}\n\n/** `integer` is a `number`, so a type that became `number` was widened, not swapped. */\nfunction covers(types: ReadonlySet<string>, type: string): boolean {\n return types.has(type) || (type === \"integer\" && types.has(\"number\"));\n}\n\nfunction compareConstraints(a: Constraints, b: Constraints): Direction {\n let widened = false;\n let narrowed = false;\n\n if (b.additional > a.additional) widened = true;\n else if (b.additional < a.additional) narrowed = true;\n\n // Allowed values: one that appears widens, one that goes narrows, and no list at all allows anything.\n if (a.enumMembers && b.enumMembers) {\n if (!isSuperset(b.enumMembers, a.enumMembers)) narrowed = true;\n if (!isSuperset(a.enumMembers, b.enumMembers)) widened = 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 for (const type of b.types) if (!covers(a.types, type)) widened = true;\n for (const type of a.types) if (!covers(b.types, type)) 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 for (const [keyword, before] of a.lower) {\n const after = b.lower.get(keyword);\n if (after === undefined || after < before) widened = true;\n if (after !== undefined && after > before) narrowed = true;\n }\n for (const keyword of b.lower.keys()) if (!a.lower.has(keyword)) narrowed = true;\n for (const [keyword, before] of a.upper) {\n const after = b.upper.get(keyword);\n if (after === undefined || after > before) widened = true;\n if (after !== undefined && after < before) narrowed = true;\n }\n for (const keyword of b.upper.keys()) if (!a.upper.has(keyword)) narrowed = true;\n\n // A constraint that goes lets more through, and one that arrives lets less.\n for (const [keyword, before] of a.opaque) {\n const after = b.opaque.get(keyword);\n if (!after || !isSuperset(after, before)) widened = true;\n if (after && !isSuperset(before, after)) narrowed = true;\n }\n for (const keyword of b.opaque.keys()) if (!a.opaque.has(keyword)) narrowed = true;\n\n /*\n * An alternation, an `items` schema, a `then`: present before and gone after is a constraint\n * lifted. Its branches used to be compared as extra facts, so removing a whole `anyOf` read as\n * removing facts -- a narrowing -- and `run_query` going from two allowed tables to any string\n * was reported as `tool.input_schema.narrowed`, low. Found in a security review.\n */\n for (const keyword of a.slots) if (!b.slots.has(keyword)) widened = true;\n for (const keyword of b.slots) if (!a.slots.has(keyword)) narrowed = true;\n\n return { widened, narrowed };\n}\n\nexport function classifySchemaChange(before: JsonValue, after: JsonValue): SchemaVerdict {\n if (stableKey(before) === stableKey(after)) return \"same\";\n\n const routes = new Routes();\n const previous = collectFacts(before, routes);\n const next = collectFacts(after, routes);\n\n let widened = false;\n let narrowed = false;\n // Nodes reached by many routes are compared once per pair, not once per route.\n const compared = new Map<Constraints, Map<Constraints, Direction>>();\n\n const oneSided = (fact: Fact, arrived: boolean): void => {\n const counterpart = fact.parent === undefined ? undefined : (arrived ? previous : next).get(fact.parent);\n if (counterpart === undefined) {\n // Beneath something that is itself on one side only, and has been counted. A property\n // declared there is still one more thing the agent may be asked for.\n if (arrived && MEMBERS.has(fact.via)) widened = true;\n return;\n }\n // A member, or a branch added to (or taken from) an alternation the other side also has.\n if (MEMBERS.has(fact.via) || counterpart.node.slots.has(fact.via)) {\n if (arrived) widened = true;\n else narrowed = true;\n }\n // Otherwise the keyword holding it came or went, and comparing the parent said which way.\n };\n\n for (const [id, a] of previous) {\n const b = next.get(id);\n if (!b) {\n oneSided(a, false);\n } else {\n if (a.required && !b.required) widened = true;\n if (!a.required && b.required) narrowed = true;\n if (a.node !== b.node) {\n let row = compared.get(a.node);\n if (!row) {\n row = new Map();\n compared.set(a.node, row);\n }\n let direction = row.get(b.node);\n if (!direction) {\n direction = compareConstraints(a.node, b.node);\n row.set(b.node, direction);\n }\n if (direction.widened) widened = true;\n if (direction.narrowed) narrowed = true;\n }\n }\n if (widened && narrowed) return \"changed\";\n }\n for (const [id, b] of next) if (!previous.has(id)) oneSided(b, true);\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":";;;;;;;;;;;;;;;AAsCA,IAAM,eAAe,CAAC,WAAW,oBAAoB,aAAa,YAAY,iBAAiB,aAAa;AAC5G,IAAM,eAAe,CAAC,WAAW,oBAAoB,aAAa,YAAY,iBAAiB,aAAa;AAY5G,IAAM,SAAS;AAAA,EACb;AAAA,EAAW;AAAA,EAAU;AAAA,EAAc;AAAA,EAAe;AAAA,EAAO;AAAA,EAAM;AAAA,EAAY;AAAA,EAAiB;AAAA,EAC5F;AAAA,EAAoB;AAAA,EAAgB;AAAA,EAAyB;AAAA,EAAoB;AACnF;AAEA,IAAM,kBAAkB,oBAAI,IAAI,CAAC,yBAAyB,oBAAoB,mBAAmB,eAAe,CAAC;AACjH,IAAM,gBAAgB,CAAC,SAAS,SAAS,SAAS,QAAQ,MAAM;AAChE,IAAM,aAAa,oBAAI,IAAI,CAAC,GAAG,cAAc,GAAG,cAAc,GAAG,QAAQ,GAAG,aAAa,CAAC;AAU1F,IAAM,UAAU,oBAAI,IAAI,CAAC,cAAc,qBAAqB,aAAa,C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