Files
rea/scripts/record-catalog-digests.mjs
gensokyo-devandKaoru0822 c23e161629 perf(mcp): record catalog identities for all schema profiles (#5415)
Share compiled schema conversion while recording all four built-in catalog profiles. Preserve canonical hashes, output validation and custom-budget fallback. Refs #723.

Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-20 10:09:28 +00:00

33 lines
1.3 KiB
JavaScript

import { writeFile } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
// Record built-in catalog profile digests into the compiled runtime. Run after
// `tsc` and before bundling, so the digests come from the same compiled
// contracts and pinned schema converter that the runtime serves.
const compiledRoot = resolve(
dirname(fileURLToPath(import.meta.url)),
"../dist",
);
const { createCatalogDigestProfiles } = await import(
pathToFileURL(join(compiledRoot, "catalogIdentity.js")).href
);
// Retain only hashes, with every shared record frozen. Schemas remain owned by
// the compiled contracts and are converted once for all four identities.
const profiles = Object.entries(createCatalogDigestProfiles())
.map(
([input, outputs]) =>
`${JSON.stringify(input)}: Object.freeze({${Object.entries(outputs)
.map(
([output, digests]) =>
`${JSON.stringify(output)}: Object.freeze(${JSON.stringify(digests)})`,
)
.join(",")}})`,
)
.join(",");
await writeFile(
join(compiledRoot, "recordedCatalogDigests.js"),
`/** Recorded from compiled catalog profiles by scripts/record-catalog-digests.mjs; do not edit. */\nexport const RECORDED_CATALOG_DIGEST_PROFILES = Object.freeze({${profiles}});\n`,
"utf8",
);