/** * Rung 1 demo executable - isolated, standalone, own universe. * bun runs/rung1/main.ts * * Proves: DAG execution, durable pause/resume/cancel, crash-resume from * fold, and the loop's transitions all landing in the ledger. */ import { Seed } from "../../packages/core/src/seed" import { runLoop, command } from "./kernel" const dbPath = process.argv[2] ?? new URL("./universe.db", import.meta.url).pathname // --- two agents, one kernel each --- const seed = Seed.open(dbPath) seed.topic({ id: "agent.worker-1.work", durability: "durable", author: "orchestrator" }) seed.topic({ id: "agent.worker-1.control", durability: "durable", author: "system" }) const worker = { token: "worker-1", workTopic: "agent.worker-1.work", orchestrate: async () => ({ steps: [ { id: "s1", title: "survey ground", dependsOn: [] }, { id: "s2", title: "dig foundation", dependsOn: ["s1"] }, { id: "s3", title: "raise walls", dependsOn: ["s2"] }, ], }), executeStep: async (step) => { console.log(` [worker-1] executing: ${step.title}`) return [{ ref: `artifacts/${step.id}.md`, kind: "output" }] }, } async function main() { const mode = process.argv[2] ?? "fresh" const db = mode === "resume" ? dbPath : dbPath if (mode === "cancel-mid") { // cancel between steps 1 and 2 by issuing command after first completes const seedX = Seed.open(db) setTimeout(() => command(seedX, "worker-1", { type: "cancel", author: "will" }), 30) } if (mode === "pause-resume") { const seedX = Seed.open(db) setTimeout(() => command(seedX, "worker-1", { type: "pause" }), 20) setTimeout(() => command(seedX, "worker-1", { type: "resume" }), 120) } console.log(`mode=${mode}`) const result = await runLoop(Seed.open(db), worker, { goal: "build the thing" }) console.log("status:", result.status, "| completed:", [...result.doneSteps].sort().join(",")) console.log("ledger:") for (const e of Seed.open(db).replay("agent.worker-1.work")) console.log(` ${e.seq}. ${e.body.type}`) } main()