aae7f883cd
- EventBus: dumb wire, publish/subscribe, failures surface - Envelope: four schema planes, inject-only headers, content-addressed - TopicLog: owned SQLite ledger, replay + by-type/time/causality - Seed facade: durable=ledger+wire, ephemeral=wire only, fold-for-state - Rung 1 kernel: OELBR loop, DAG plans, durable cancellation tokens - Neuron v0 executable spec source; specs/event-bus.md citizen zero - Standing orders: design-before-code doctrine installed
59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
/**
|
|
* 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()
|