How Modules Communicate
The corpus callosum connects all brain regions. Modules broadcast “this happened” notifications through typed events on the corpus — no module needs to know who is listening. When something needs a direct request/response (the prefrontal asking the cerebellum for the capability index, or the cortex for search results), that goes through module references injected at startup, not the bus. This keeps the system modular, inspectable, and easy to extend.Architecture
Built on mitt — a lightweight typed event emitter (200 bytes). Every module receives the corpus singleton in its constructor:imports between modules.
Usage
The corpus itself installs an internal wildcard handler on construction — every event that flows through it is captured, buffered, and flushed to the daily log files. Modules get logging for free.
Event Categories
Over 80 typed events are defined in theCorpusEvents type map. The main categories:
Message & Context Events
LLM Events
turn.usage is the whole-turn roll-up, with the cache split priced separately so caching wins are measurable straight from the corpus log.
Tool & Task Events
Safety Events
Memory & Learning Events
Health & Index Events
Scheduler Events
Beyond these, whole families cover dependency installation (
dependency.*), channels (telegram.*, whatsapp.*), voice and speech (voice.*, stt.*), file uploads (upload.*), and conversation switches (conversation.changed). All follow the same pattern: typed payload, automatic logging.
Event Logging
Every event is logged to daily markdown files atbrain/corpus/YYYY-MM-DD.log.md. A 2-second buffer flush batches writes for performance — each event lands as a timestamped block:
run-history.md), and the logs themselves are indexed by the cortex while they exist.
Subscribing and Unsubscribing
finally block.
Adding New Events
To add a new event type:- Add the event name and its payload type to the
CorpusEventstype map insrc/main/runtime/corpus.ts - Emit it from the relevant module
- Subscribe to it from any module that needs to react
Design Benefits
The event bus architecture provides:- Module independence: modules can be developed, tested, and upgraded independently
- Full observability: every interaction is logged and timestamped
- Easy extension: new modules subscribe to existing events without modifying producers
- Testability: mock the corpus in tests and verify events are emitted correctly