guanghu-ice-heart/gls/scripts/audit-protocol-execution-bindings.mjs

116 lines
3.4 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const registryPath = path.join(root, "gls/GLS-PROTOCOL-REGISTRY.json");
export const productionControlIds = new Set([
"GLS-0130",
"GLS-0131",
"GLS-0301",
"GLS-0302",
"GLS-0303",
"GLS-0304",
"GLS-0305",
"GLS-0306",
"GLS-0307",
"GLS-0308",
"GLS-0309",
"GLS-0310",
"GLS-0311",
"GLS-0411",
"GLS-0708",
"GLS-0709",
"GLS-0710",
"GLS-0803",
"GLS-0819",
"GLS-0827",
"GLS-0828",
"GLS-0836",
"GLS-0842"
]);
export const bareMetalResearchIds = new Set([
"GLS-0840",
"GLS-0841",
"GLS-0843",
"GLS-0844",
"GLS-0845",
"GLS-0846",
"GLS-0847",
"GLS-0848",
"GLS-0849"
]);
export function audit(registry, sourceExists = (source) => fs.existsSync(path.join(root, source))) {
const protocols = registry.registered_draft_protocols;
if (!Array.isArray(protocols)) {
throw new Error("registered_draft_protocols is missing");
}
const ids = new Set();
const entries = protocols.map((protocol) => {
if (ids.has(protocol.id)) {
throw new Error(`duplicate protocol id: ${protocol.id}`);
}
ids.add(protocol.id);
if (!sourceExists(protocol.source)) {
throw new Error(`missing protocol source: ${protocol.source}`);
}
const registryClaimsImplementation = protocol.implementation !== "NOT_STARTED";
const lane = productionControlIds.has(protocol.id)
? "PRODUCTION_COGNITIVE_CONTROL"
: bareMetalResearchIds.has(protocol.id)
? "BARE_METAL_RESEARCH_AND_RECOVERY"
: "LANGUAGE_WORLD_GOVERNANCE";
return {
id: protocol.id,
acronym: protocol.acronym,
lane,
registry_implementation: protocol.implementation,
registry_claims_implementation: registryClaimsImplementation,
executable_binding_state:
lane === "PRODUCTION_COGNITIVE_CONTROL"
? "REQUIRES_REPO_014_BINDING_AND_RUNTIME_RECEIPT"
: "SEPARATE_EVIDENCE_REQUIRED",
production_control_ready: false
};
});
const registeredOnly = entries.filter((entry) => !entry.registry_claims_implementation).length;
const implementationClaims = entries.length - registeredOnly;
const productionControlRegisteredOnly = entries.filter(
(entry) =>
entry.lane === "PRODUCTION_COGNITIVE_CONTROL" &&
!entry.registry_claims_implementation
).length;
return {
schema: "guanghu.protocol-execution-audit/v1",
registry_id: registry.registry_id,
registry_status: registry.status,
total_registered_draft_protocols: entries.length,
registered_only_count: registeredOnly,
registry_implementation_claim_count: implementationClaims,
production_control_registered_only_count: productionControlRegisteredOnly,
production_control_ready_count: 0,
aggregate_production_control_state: "FAIL_0",
rule:
"A registry implementation label is orientation only. Production readiness requires an exact REPO-014 executable binding, deployment receipt and target-side runtime readback.",
entries
};
}
function main() {
const registry = JSON.parse(fs.readFileSync(registryPath, "utf8"));
process.stdout.write(`${JSON.stringify(audit(registry), null, 2)}\n`);
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
main();
}