import { assert } from "https://deno.land/std@0.224.0/assert/mod.ts"; /** * Proof of Concept: State Machine (Gen 2) * * Demonstrates Bounded Model Checking (BMC) for pipeline governance by actually * reading and parsing a transitions.json file from the filesystem. */ interface TransitionRule { requires: string[]; } type TransitionsConfig = Record; function canAgentExecute( roleName: string, config: TransitionsConfig, currentState: Set, ): boolean { const rule = config[roleName]; if (!rule) { throw new Error(`Role ${roleName} is not defined in the transitions matrix. Execution denied.`); } return rule.requires.every((req) => currentState.has(req)); } if (import.meta.main) { console.log("Running State Machine PoC (Gen 2) tests..."); try { const tempFile = await Deno.makeTempFile({ suffix: ".json" }); await Deno.writeTextFile(tempFile, JSON.stringify({ "Coder": { "requires": ["Gatekeeper_Approval"] }, "Gatekeeper": { "requires": [] }, "Evaluator": { "requires": ["Coder_Completion"] } })); const matrix: TransitionsConfig = JSON.parse(await Deno.readTextFile(tempFile)); await Deno.remove(tempFile); const currentState = new Set(); assert(canAgentExecute("Coder", matrix, currentState) === false); assert(canAgentExecute("Gatekeeper", matrix, currentState) === true); currentState.add("Gatekeeper_Approval"); assert(canAgentExecute("Coder", matrix, currentState) === true); assert(canAgentExecute("Evaluator", matrix, currentState) === false); console.log("✅ State Machine PoC (Gen 2) successful: Real File I/O BMC constraints enforced."); } catch (err) { console.error("❌ State Machine PoC (Gen 2) failed:", err); Deno.exit(1); } }