auth-yes/archive/.forum/poc-g2/execution_flywheel_poc.ts

76 lines
2.4 KiB
TypeScript

/**
* Execution Flywheel PoC (Gen 2 - Production Tooling)
*
* This script proves the physical constraints of a 3-step feedback loop
* (Analyst -> Gatekeeper -> Reset) using actual file I/O to pass
* state between agents instead of purely in-memory objects.
*/
import {
dirname,
fromFileUrl,
join,
} from "https://deno.land/std@0.224.0/path/mod.ts";
const currentDir = dirname(fromFileUrl(import.meta.url));
const STATE_FILE = join(currentDir, "flywheel_state.json");
async function writeState(state: any) {
await Deno.writeTextFile(STATE_FILE, JSON.stringify(state, null, 2));
}
async function readState(): Promise<any> {
const content = await Deno.readTextFile(STATE_FILE);
return JSON.parse(content);
}
async function runFlywheel() {
console.log("Starting Execution Flywheel (Gen 2 - File I/O)\n");
// Initial State
await writeState({ constraintLevel: "low", iteration: 0, status: "INIT" });
console.log(`[Flywheel] Initialized state file: ${STATE_FILE}`);
for (let i = 1; i <= 3; i++) {
console.log(`\n=== Iteration ${i} ===`);
// Step 1: Analyst reads telemetry (simulated) and writes new protocol to disk
console.log("[Analyst] Reading state from disk...");
const analystState = await readState();
console.log("[Analyst] Updating protocol constraints...");
const newConstraintLevel = i === 1 ? "medium" : i === 2 ? "high" : "strict";
analystState.constraintLevel = newConstraintLevel;
analystState.iteration = i;
analystState.status = "ANALYST_UPDATED";
await writeState(analystState);
console.log(
`[Analyst] State written to disk with constraint: ${newConstraintLevel}`,
);
// Step 2: Gatekeeper reads constraints from disk
console.log("[Gatekeeper] Reading updated constraints from disk...");
const gatekeeperState = await readState();
console.log(
`[Gatekeeper] Enforcing constraint level: ${gatekeeperState.constraintLevel}`,
);
gatekeeperState.status = "GATEKEEPER_APPROVED";
await writeState(gatekeeperState);
// Step 3: Cycle executes
console.log("[Coder] Generating code under physical disk constraints...");
console.log("Cycle complete.");
}
console.log("\n[Flywheel] Cleaning up state file...");
await Deno.remove(STATE_FILE);
console.log("Gen 2 Flywheel execution completed successfully.");
}
if (import.meta.main) {
runFlywheel().catch(console.error);
}