@techsavvyash/bus is the event bus dough’s pieces use to tell each other what happened. A component emits an event, such as pad.task.created or agent.run.completed. The bus checks the event against a registry of known types, stores it and hands it to every subscriber whose filter matches.
It comes from the bus in clanker, dough-quiver’s agent runtime, and is the first of clanker’s building blocks to move into dough. Ported from clanker lists what changed on the way. The library is built on Effect 4 and has a Promise facade for code that isn’t on Effect.
What it does
- Typed vocabulary: every event type is either registered exactly (
agent.run.started) or sits under a namespace you’ve allowed (custom.). A registered type can carry a JSON Schema for its payload. An unknown or misspelt type, or a payload that breaks its schema, fails at emit time with an error that names the problem. It’s never silently dropped. - Idempotent emits: give an event a
dedupeKey, and emitting it again fails withDuplicateEventError, which carries the id of the original event. - Threading:
subject(usually a task or run id),correlationId(the root job) andcausationId(the event that caused this one) let consumers follow a whole multi-agent job and guard against loops. - Subscribers: run in subscription order, one after another, after the event is stored. A failing subscriber is reported through
onSubscriberError. It never fails the emit and never stops the subscribers after it. - Stores: an in-memory store and an append-only JSONL store are included. Any other store, such as Postgres, implements the four-method store contract and proves itself against the conformance suite.
A first event
npm install @techsavvyash/bus effect @effect/platform-node-sharedWith the Promise facade and an in-memory store:
import { EventBus, EventTypeRegistry, MemoryEventStore } from "@techsavvyash/bus/promise";
const registry = new EventTypeRegistry();
registry.allowNamespace("custom.");
const bus = new EventBus({ store: new MemoryEventStore(), registry });
bus.subscribe(async (event) => console.log(event.type, event.data), { source: "deployer" });
const event = await bus.emit({ type: "custom.deploy.finished", source: "deployer", data: { ok: true } });
await bus.list({ source: "deployer" }); // [event]Using the bus has the Effect version, the registry and every option.
How dough will use it
Today the bus is a library, and nothing in dough consumes it yet. The plan:
- Pad: dough's shared task list emits
pad.*events on the bus, and rules react to them. - Agents: an agent run’s events are republished as
agent.*events through the agent sink (makeBusEventSink, orcreateBusEventSinkin the facade). That way pad, rules and other agents can follow a run without depending on the runtime. - Gateway and worker: the NestJS gateway and the worker aren’t on Effect. They’ll use
@techsavvyash/bus/promisewith their own store, held to the same conformance suite. - Tools: a
dough busCLI command, Claude Code plugin tools and Pi tools to emit, list and follow events come later, once the CLI rename lands.
Related packages
- Pad depends on the bus: it emits a
pad.*orexecutor.run.*event for every change it makes. - Messages, Sesh and Threads don’t use it.
Read next
- Using the bus: the Effect API and the Promise facade.
- Stores: the store contract, the memory and JSONL stores, and the conformance suite.
- Ported from clanker: what changed in the move, and why.