Spaces:
Runtime error
Runtime error
| /** | |
| * TIA-β Worker Loop (Heartbeat Engine) | |
| * Runs periodic scans, lineage mapping, drift detection, | |
| * resurrection planning, and guided queue generation. | |
| * Non-destructive. Safe. Approval-based. | |
| */ | |
| import { scanQGTNL } from "./scanner"; | |
| import { generateLineageReport } from "./lineage"; | |
| import { generateResurrectionPlan } from "./resurrection"; | |
| import { generateDriftReport } from "./drift"; | |
| import { buildGuidedQueue } from "./guided"; | |
| import { getMode } from "./mode"; | |
| export interface WorkerStatus { | |
| running: boolean; | |
| lastCycle: number | null; | |
| cyclesCompleted: number; | |
| } | |
| let status: WorkerStatus = { | |
| running: false, | |
| lastCycle: null, | |
| cyclesCompleted: 0, | |
| }; | |
| export function getWorkerStatus(): WorkerStatus { | |
| return status; | |
| } | |
| export async function startWorkerLoop(intervalMs = 30000) { | |
| if (status.running) { | |
| console.log("Worker loop already running."); | |
| return; | |
| } | |
| status.running = true; | |
| console.log("=== TIA-β Worker Loop Started ==="); | |
| while (status.running) { | |
| console.log("\n=== TIA-β Cycle Begin ==="); | |
| const mode = getMode().current; | |
| console.log("Mode:", mode); | |
| const scan = scanQGTNL(); | |
| if (scan.status !== "ok") { | |
| console.log("Scan failed:", scan.message); | |
| break; | |
| } | |
| const lineage = generateLineageReport(scan.structure); | |
| const resurrection = generateResurrectionPlan(lineage); | |
| const drift = generateDriftReport(lineage); | |
| const queue = buildGuidedQueue(resurrection, drift); | |
| console.log(`Cycle results: ${queue.prompts.length} actionable prompts.`); | |
| status.lastCycle = Date.now(); | |
| status.cyclesCompleted++; | |
| console.log("=== TIA-β Cycle End ==="); | |
| await new Promise((resolve) => setTimeout(resolve, intervalMs)); | |
| } | |
| console.log("=== TIA-β Worker Loop Stopped ==="); | |
| } | |
| export function stopWorkerLoop() { | |
| status.running = false; | |
| } | |