Architecture

clients      terminal UI / line mode · ACP v2 stdio (oi rpc) · HTTP+SSE (oi serve) · C ABI (libharness)
                                   │ all drive one Kernel
kernel       event-sourced SQLite tree · capability gate · LLM supervisor (std.http SSE)
(Zig)        Turn state machines in Scopes (root agents + sub-agents) · worker-thread jobs
             + main-thread pump · MCP supervisor
                 │ host functions only                     │ re-exec `oi __sandbox`
planes       quickjs-ng isolates                         OS sandbox (Landlock / Seatbelt)
             plugins (per-plugin runtime, byte cap)      bash, stdio MCP servers
             Codemode (per-call isolate, 64 MB, 60 s)    write roots, network on/off
  • Loop. A turn is a state machine (Turn.zig) driven by continuations on the kernel's pump, so any number of turns — root agents on different sessions and their sub-agents — advance side by side on one thread. Each step rebuilds the model context from the event path, so rewind, branching and resume need no extra state. It applies plugin before_model hooks, streams one turn, records it verbatim (thinking blocks and signatures included), then runs every tool_use in parallel. Results go back in a single user message, in request order.
  • Scopes. Everything that belongs to one running agent rather than the process — its session, cwd, model, effort, permission policy and cancel token — lives in a reference-counted Scope that every model call, tool, Codemode script and approval carries.
  • Turn-1 surface. Turn 1 carries read, write, edit, bash, grep and glob, agent, plus the meta tools tool_search and codemode: about 1.5k tokens together with the system prompt (agent is about 330 of them; "subagents": false drops it). skill joins them when skills are installed. The deferred built-ins (web_fetch, web_search, bash_output, bash_kill, and with MCP servers list_mcp_resources, read_mcp_resource), plugin tools and MCP tools appear only after tool_search finds them; a background shell activates bash_output and bash_kill by itself. Each activation is recorded as an event, so rewinding past it undoes it.
  • Event log. Every model call, tool result, inner Codemode/plugin call, tool activation, plugin load/reload, sub-agent spawn and report, and compaction is an immutable row: events(id, parent_id, session_id, ts_ns, kind, plugin_id, tokens_in, tokens_out, tainted, payload). Compaction appends a summary event. It never rewrites history. A sub-agent's session records its parent session and the agent_spawn event that started it.
  • Async. Guest JS never blocks. A host call returns a Promise and the work runs on a worker thread. The completion runs on the main thread, which is the only thread that touches SQLite or a JS runtime, and resolves the Promise.