import { mkdir, readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import { registrySnapshotDigest } from "./lib/registry-compatibility.ts"; const inputPath = process.argv[2] ?? "artifacts/quality/registry-current-snapshot.json"; const outputPath = process.argv[3] ?? "config/contracts/registry-baseline.json"; const owner = process.env.REGISTRY_BASELINE_OWNER; const reason = process.env.REGISTRY_BASELINE_REASON; if (!owner || !reason) { process.stderr.write( "REGISTRY_BASELINE_OWNER and REGISTRY_BASELINE_REASON are required.\n", ); process.exit(1); } const input = JSON.parse(await readFile(inputPath, "utf8")); const snapshot = input.registries ? { schemaVersion: 2, registries: input.registries } : input; const digest = registrySnapshotDigest(snapshot); await mkdir(path.dirname(outputPath), { recursive: true }); await writeFile(outputPath, `${JSON.stringify(snapshot, null, 2)}\n`); await writeFile( "config/contracts/registry-baseline.approval.json", `${JSON.stringify( { schemaVersion: 1, snapshotDigest: digest, owner, reason, approvedAt: new Date().toISOString(), }, null, 2, )}\n`, ); process.stdout.write(`Registry baseline updated: ${digest}\n`);