GitHub pages
I start an agent with one line. orch spawn articles-c ~/Desktop/notes orchestrator/briefs/2026-11-27/articles-c.md copies the brief into that day’s folder, starts a new tmux window, and writes a row into SQLite. That is the whole trick of this machine: a body you can list, and a ledger entry that outlives whatever the agent does next. Everything else in magi is scaffolding around those two facts.
The bodies are tmux windows. Session magi, window 1 orchestrator, then one window per worker plus three house windows: bus running orch-bus live, chrome running the agent browser, listen for the local listener. I can see them with magi-agent agents: window, state, agent, idle minutes, pane. The states come from agent/lib/magi_agents.py, the adapter layer that knows how each supported agent looks from the outside. Opencode is the default since #7; Claude Code, Codex and a custom command stay supported, and the orchestrator and the workers can each use a different one.
Each adapter answers the same four questions: how to install, how to sign in, how to launch, and whether the process in this pane is idle, busy, or asking. Where the agent offers something machine-readable, the adapter reads it. For Claude Code that is ~/.claude/sessions/<pid>.json. For opencode it is the local server API: active sessions plus pending permission requests per session, checked against opencode 2.2.5 behavior. For Codex it is the rollout file, where task_started opens a turn and task_complete or turn_aborted closes it. Otherwise the adapter reads the pane itself: a permission regex means asking, a working indicator means busy, anything else with the process alive means idle. Pane-read idle time is tracked in ~/.local/state/magi/agent/panes.json by screen hash, so output the patterns miss still counts as activity. If an agent update changes what the adapter reads, that agent reads as not idle. That failure mode is deliberate. Nothing closes that should not.
The meaning lives in one SQLite file, ~/notes/orchestrator/orch.db, managed by agent/bin/orch. The schema is small: agents, threads, watchers, decisions, deliverables, events, nudges, meta. The notes folder itself is a local git repository, and orch doctor commits it. Nothing is pushed. Backups are one consistent copy a day in orchestrator/backups/, fourteen kept, via the SQLite backup API with WAL checkpointed before the commit so the database is self-contained in git.
agents records what spawn started: name, pane id, cwd, brief path, task first line, agent name, started and ended timestamps, status, result, resume command. Status is running, done, lost, or reaped. threads are open threads, but the human view is not the table. It is the ## Open threads checklist in that day’s daily note under # Tasks. orch thread add appends an unticked box there and inserts the row; orch sync re-reads the last thirty days of notes, and a ticked box closes the thread here. I tick boxes. The ledger follows. watchers are standing watches with a name, a kind, a purpose, an optional command, an until date, and a last-ok timestamp: probes, monitors, anything with an end I would otherwise forget. decisions exists so I am asked once. deliverables records PRs, deploys, releases, messages sent. events mirrors the bus log. orch status prints one screen from all of it: running agents, open threads, active watchers, recent decisions.
A spawn is cheap because finishing is explicit. agent/lib/magi_agents.py runs a watch process per worker, detached at spawn time unless NOTIFY=0. It polls the adapter state every three seconds and yields three events. asking fires the first time the pane shows a prompt. exited fires when the agent process is gone but the window is still there. done fires once the worker has visibly worked and then stayed idle for the settle interval, fifteen seconds by default through MAGI_EVENT_SETTLE. A worker that finished between two polls still counts after a minute of idle. A worker sent back to work and finishing again yields another done.
Each event becomes one line to the orchestrator: [magi] window <name> (<agent>) finished and is idle. Read it: tmux capture-pane -p -t <pane> -S -80, with the variants for waiting on a prompt and exited. Delivery goes through deliver_to_orchestrator, which exists because typing into a pane can garble and interleave. If the orchestrator is opencode with a known session id, delivery is a POST /api/session/{id}/prompt with the text as JSON, queued server-side. That path arrived in #9 and the logging around it in #12: success and return code go to events.log, and there is no draft check on this path because it never touches the TUI input box. Every other case falls back to tmux: send-keys -l plus a separate Enter, only when the orchestrator reads idle and its input box reads empty. The draft check is per agent. Opencode’s reads the run of box lines above the mode line and treats grey placeholder text as empty; Claude’s looks past the prompt character. The function waits up to ten minutes, polling every three seconds. If the orchestrator stayed busy or held a draft the whole time, the event is logged as undelivered. Either way the same line is appended to the bus with source agent <window>, marked delivered only if it was typed in.
The bus is the second path into the orchestrator, for everything that is not a worker. agent/bin/orch-bus appends one JSON line per event to ~/.local/state/orchestrator/events.jsonl: timestamp, source, text, optional dedupe key. No broker, no port. Anything that can run a command can publish: workers, shell scripts, systemd timers, browser probes. The design is written up in docs/event-bus.md. Delivery is the orch-bus.service user unit running dispatch. It watches the file size against a stored offset, waits three seconds so a burst coalesces, formats everything pending as one [event bus] ... line capped at 1500 characters, and types it through the same idle-and-empty gate. The offset moves only on success, so a busy orchestrator keeps its events. The loop polls every fifteen seconds; that interval moved from two seconds in #11 after voice-health logging went change-only and the hot poll stopped buying anything. BUS_DELIVERY=off turns typing off entirely and the orchestrator reads with orch-bus unread, which keeps its own offset. orch-bus live follows the log for the bus window. Dedup keys make retries safe. --urgent, from #10, adds a desktop notification through notify-send while keeping normal queueing; deduped emits do not re-notify.
Probes are how the outside world gets on the bus without an API. browser-bus attaches to the agent browser over CDP on 127.0.0.1:9222 and runs small scripts inside matching tabs in an isolated world. A probe declares its match patterns, the sources it may emit under, and a purpose, then calls emit({text, key}). The page I am already signed in to becomes an event source. The shipped example is agent/browser-bus/examples/page-title.js, which fires when a local dev server’s page title changes. Sources starting with wa-, tg-, or r/ are reserved for these probes and need the probe token.
That reservation exists because bus text is untrusted input to an LLM, and #1 is the PR that treats it that way. Every event gets a trust level, owner, internal, or external, and a risk score with reasons, computed in agent/lib/bus_guard.py and written through agent/lib/bus_store.py. External text is normalised before scoring: control, zero-width and bidi characters stripped, homoglyphs folded, encoded payloads decoded, then scanned for role tags, fake approvals, commands, fake bus frames, split attacks across messages. External text is always stored and shown inside a fixed frame marked as data, never instructions. High-risk text never reaches the bus. The full text goes to quarantine.jsonl and the bus gets a one-line notice with an id. The first high-risk event trips a circuit breaker: from then on everything except owner-authored lines goes to held.jsonl instead of the bus, one fixed bus-guard line announces the pause, and I get a critical desktop notification plus a SECURITY message in the WhatsApp self-chat, built from fixed text plus source, sanitised sender and reason codes, never the payload. Nothing is typed or shown until I run orch-bus resume, which releases the held events and notes the count. orch-bus status, quarantine list, and the quarantine read path are the rest of the interface.
Stall and idleness are separate watches, and they close the loop back to the ledger. orch watch add <name> <kind> <purpose> --until <date> registers anything standing: a probe, a build I am waiting on, a timer. orch watches lists them with last-ok times. doctor flags any watcher past its end time by name. The same doctor checks every user unit is active, every script is executable, the core windows exist, the agent browser answers on its port, the browser-bus is connected, the ledger passes integrity check, the bus file is writable, the notes system layer is linked, and today’s note exists. It reports new problems on the bus once per distinct set, and fixes what is safe: restarting units, recreating a missing window, restarting the browser in place, refreshing the system layer after an image update when I have not edited it.
Idle agents do not accumulate. agent/bin/tmux-reap-stale closes agent panes that have sat idle for sixty minutes, twenty when available memory drops under 2500 MB. All of the conditions must hold: the process alive and idle by its adapter, idle longer than the limit, window not in the exempt set, no question or menu on screen, no typed draft in the box. The exempt set is orchestrator,notes,listen,hud-listen,bus,chrome. Every close is appended to ~/.local/state/tmux-reap/closed.log with the exact resume command or the note that the agent starts fresh, and becomes an open thread with the last screen as details, so the next open-threads reminder raises it until I tick it. orch sync also reads that log and marks matching running rows reaped. Running agents whose window vanished some other way become lost, plus an open thread with the task’s first line, so a killed window is never silent.
Reboot is the same story. agent/bin/tmux-snapshot saves the layout every minute to ~/.local/state/tmux-snapshot/layout.json, keeping thirty changed copies: per window the session, index, name, and per pane the cwd plus how to restart it. Agent panes store the adapter’s resume command with the same flags, claude --resume <id> or opencode --session <id> or codex resume <id>, or a fresh start when the agent cannot resume. The orchestrator stores magi-agent orchestrator --resume. Panes with a start command store that; editor panes store the editor; everything else comes back as a shell in the same folder. agent/bin/tmux-restore rebuilds it at boot, idempotently: a window is only created if no window with that name exists, so running it under an already-up tmux is safe. The three-hourly orch-open-threads.timer runs orch nudge-threads, which caps the logs, counts open threads, and puts one line on the bus telling the orchestrator to raise every one in plain words. That is the backstop for everything the reaper, the sync, and the watchers noticed.
The install layer is why a fresh machine behaves the same. #13 teaches install.sh to mirror the agent tree to /usr/share/magi, write IMAGE_VERSION, link the bins into /usr/bin, and install the user units, with uninstall.sh removing exactly what the step added. The sibling from the same week, #8, is worth naming for what it refuses: the reflex runner’s structural guard allowlists its practice surfaces and aborts when a tab leaves the entry domain. New automation on this desktop arrives gated by default.
The default state of the machine is a running conversation. magi-agent on enables magi-agents.service and the reaper timer at every login. Window 1 runs the orchestrator in a loop: if the agent is missing it waits, if I am not signed in it prints the sign-in link and waits, if the network is down it says so and waits, and when the session exits it prints that Enter restarts it. Restored windows come back in order with the orchestrator pinned to index 1. I log in and the twelve agents are where I left them, the ledger says what each one was doing, the bus holds what happened while I was away, and the open threads list says what still needs me. Spawning the thirteenth is one line.