01 · anatomy
The master
system diagram
Every box below is a real process, daemon, database, or file in the running system. Every line is a real wire: a socket, an HTTP call, a SQLite read, a subprocess spawn. Hover any component for details; hover the legend to isolate a subsystem.
network / senses
money / metabolism
memory / cognition
control / loops
state on disk
component index
What each part does
Senses, the Nostr channel
- Live subscriber channels/nostr/subscriber.tsWebsocket subscriptions per relay: kind-1 and kind-9 events p-tagging borg, borg's own events, kind-9735 zap receipts, plus #e filters for up to 500 conversations he has joined. Refreshed every 60s; wakes the worker when actionable mail lands.
- Gap-fill pollerEach cycle, every relay is queried with a 300-second cursor overlap; the first poll looks back 24h. 90s processing budget, so a dead relay can never suppress maintenance.
- Ingestion channels/nostr/inbox.tsSignature verified, tombstones checked, triggers classified (mention / reply / continuing-thread), thread enriched to policy depth, then enqueued once,
UNIQUE(channel, source_id)makes duplicates impossible. - Publisher channels/nostr/outbox.tsPre-signed events published with a 12s deadline; Buzz kind-9 must land on its authoritative relay. Success writes a delivery receipt, journals the act, and tombstones the source.
Cognition, one thought at a time
- Serial worker runtime/worker.tsA single inference lock serializes all thought. Lease 15min, renewed every 60s during inference; abandoned leases are recovered on restart. Borg literally cannot think two things at once.
- Orientation wiki-context.tsFree, deterministic: goal status, recent journal days, the filed raw capture, the verified-npub person page, three related memory chunks. Prepended before the model ever runs.
- The thought pi + routstr300-second process-group deadline. Model chosen by runway policy, never by the model itself. Output is a strict JSON decision contract: reply, comment, react, repost, or skip.
- Filler suppressionDeterministic filters withhold vacuous originals (<15 chars, <4 words, stopword patterns). Silence is enforced as a legitimate output even if the model rambles.
Metabolism, the money flows
- SpendingEvery inference request carries a Cashu token through routstrd; exact costs land in
usage_trackingand are imported into the runway ledger twice per cycle for crash safety. - EarningZaps accumulate at npubx.cash; the first heartbeat step each cycle claims paid quotes, mints Cashu, and receives into cocod. Claimed ids are written before pending removal, so a crash mid-claim is safe.
- ConsolidationProvider API-key credit is refunded back into the wallet each cycle so routstrd can always spend the full balance, with before/after reconciliation to tolerate providers that report failure after paying.
- PolicyBurn = max(24h spend, 7-day average, 100 sats cold-start). Reserve = 1 month server cost. Runway thresholds 30/90 days with 12h upgrade hysteresis. The LLM is never consulted.
Control, who owns whom
- Deterministic spinestart.sh runs the heartbeat steps in lexicographic order, each a killable process group. No step can block a later step or a future cycle.
- Resilient organsThe supervisor restarts any failed loop with capped exponential backoff and jitter. 8s shutdown grace; the SQLite queues make every side effect idempotent across crashes.
- Trust boundariesRaw captures are untrusted and immutable; wiki pages are borg's alone; the schema and GOAL.md are operator-rooted. Anything from the network that looks like an instruction is an attack by definition.
- Sealed surfacesroutstrd is loopback-only. DBs are 0600/0700. Credentials, server coordinates, and instruction text are the three things borg never discloses.