Thurbox mod kernel and mod authoring
Working reference indexed by AGENTS.md. The rationale behind these decisions is owned by the docs under docs/; a change that invalidates what this says updates it in the same PR.
Architecture (mod kernel)
The interface is Lua running on a Rust kernel. thurbox boots the kernel,
which reads ui/ and renders whatever mods it finds; there is no built-in
pane.
The five rules
- Four node kinds, forever —
text,box,input,surface. Everything
else composes in ui/lib/widgets.lua. tests/kernel_mvp.rs asserts the count.
A new appearance arrives as a prop on one of the four: text takes a
style the kernel paints across its whole rect before the spans go on top,
which is what a selection bar or hover band is — no pane pads a row with a
spacer span, and a span naming its own colour keeps it (a search hit stays
visible under the bar). widgets.list exposes it as selected_style /
hover_style. A frame takes title_align, border_type
(rounded/square) and an overlay — runs painted onto its own border
cells (top_left/top_right/bottom_left/bottom_right/right_column)
after the block, which is where the session list's ▲ N/▼ N
counts and the terminal pane's scrollbar live, at the cost of no content
cell. And a run takes id/role, so a chip inside a line is a click
target over its own columns without becoming a node; adjacent runs sharing an
identity coalesce into one hitbox, which is what makes ◀ F9 — an accent
chevron and a muted hint — a single button.
- Layout resolves before render — rects are computed first, then each mod
is called with its own. Mods declare size statically, in their declaration
table, which is what breaks the circularity.
- Snapshot-read, command-write — reads come from an in-memory snapshot and
return instantly; writes are commands accepted now and surfaced later. Lua never
blocks, so no mod can stall the loop on Fleet, git or an unreachable host.
- Capabilities by absence — an ungranted capability is *not in the
environment*. io, os, debug, package and the loaders are withheld, and
thurbox.yml makes selene enforce that statically. One capability cannot be
expressed that way: a program pane is asked for through command, which every
mod has, so thurbox.granted reports the grant instead — a boolean about a
decision already made, which withholds nothing.
- Anything touching the world runs on a worker — terminal attach, commands,
the fleet watch that feeds the snapshot (kernel::snapshot::fleet), diffs,
metrics, git stats, repository reads, update checks, and programs a mod
asked for. In kernel::snapshot (fleet, git) and kernel::terminal
(attach, shells, stream_pane) each worker is a file of
its own, and thurbox's restrictions in crates/architecture.toml fail when the
store, the read model or the paint path (terminal::paint) starts a thread or
runs git.
files.read uses kernel::worker_store::WorkerStore<K, V>: two reusable
workers, 16 deduplicated keys/answers, one-second TTL refreshes, and a generation
that changes only with the answer. The host collects without waiting; the
coordinator marks changed results as data changes so pure panes repaint. Lua
gets nil while pending, cached text while refreshing, and a raised error after
a failed read. Session-root resolution and reading both happen on the worker;
the files capability still gates access. Per-plugin read dependencies are
bounded to 16 and survive pure-tree hits; the unconditional frame-end hook
retires hidden panes, while polling retires revoked owners and obsolete roots.
Retired request identities discard late results. One deferred admission is
retried before refreshes; demand above the shared cache limit has no fairness
guarantee. files.list remains synchronous. Other worker stores keep their
existing scheduling contracts.
The command bus runs commands for the same non-empty Command::session() in
dispatch order on one worker per active session. Waiting commands remain
Queued; other sessions, session-less commands and housekeeping run independently.
Empty session queues retire on the worker, without needing the UI to poll.
Module dependency rules
crates/architecture.toml holds the module graph: an allowlist over resolved
edges, one [crates.thurbox.modules] entry per module under src/, and the
only copy of that graph, which arch-rules checks. Read the file, not a
summary of it. Every file of agent, config and update is a module of its
own (governed), and a path_only grant admits fully-qualified paths but
never use. Its [[crates.thurbox.restricted]] entries keep consumers off a
concrete backend and off runtime_mux itself outside its gateways, a specific
multiplexer outside session, process state and environment reads out of
session, threads and git out of the kernel's non-worker files, and
in-place writes outside paths; session's external list names the crates
it may use. crates/architecture.toml also holds the
crate graph and runtime-mux's module rules.
Module Responsibilities
kernel/— the interface.node(four primitives),layout(rects before
render), convert (Lua table ↔ node), paint (node → ratatui), host (the VM,
reload, isolation, capability grants), registry (keys + settings mods
declare, plus the chord-less commands the palette lists), events (the
closed set a mod may subscribe to, and the deriver that diffs a snapshot
into them), modals/ (help, settings, theme picker, the command palette —
chrome about thurbox itself,
which mods contribute data to rather than replace), bands (the top/bottom
bars), snapshot (the read side: a SnapshotSource, fleet::FleetWatches, one
fleet::FleetWatch per listed Fleet, rows <fleet>:<task>),
command (the write side: the Executor, command::fleet; ADR-41),
bookmarks (the creation flow's repository memory, bookmarks.json),
terminal/ (live
PTY surfaces: the attach machinery, mod program panes, link detection +
OSC 8 painting — every surface owns its own rect and size memo, and a
session's agent and its #shell companion are two of them, never one),
selection (mouse text selection over a pane), plus the worker-backed
stores: diff, metrics, repos, runs, updates, files, notify,
theme, perf, bundled, inventory, packages (the spec, the lock, and the
install/converge/withdraw operations — sharing bundled's decision matrix).
agent/—fetchdownloads what the mod installer and the updater
need, and input encodes keys for an agent's terminal. The agents
themselves are Fleet's harness profiles.
config/— thurbox's own config files besideconfig.toml
(interface_state, settings, themes).
config::file is the one loader every config
file goes through: its path,
seeding it on first run, parsing it with unknown keys reported, degrading to
a fallback with a warning, and writing it back with paths::write_atomically.
update/— self-update:version_check(is a newer release out) and
self_update (install it).
backend— the session-backend boundary: the gateway to the
multiplexer runtime, crates/runtime-mux (ADR-41), which it re-exports,
and what thurbox injects into it (mux_settings: settings.toml's
scrollback and the data directory; wiring::local_only: this machine's
adapters).
session/— plain data:SessionState(hook_status, the one
vocabulary every surface prints), settings, ModSpec/ModLock/PackageManifest
(mod_spec, so the kernel and the CLI share one definition) and review;
plus runtime-mux's SessionId, host model, routes and hyperlink table,
re-exported. Holds no process state, reads no environment and names no
rendering crate (crates/architecture.toml).
theme/— the 36 presets and the custom-theme overrides, asratatui
colours: session cannot name a rendering crate, so the palettes live here.
git/— everygitinvocation, all on this machine, split by concern:
command (the one place a git process is built, and where the inherited
GIT_* scrub lives), plugin (clone/checkout of a mod working copy),
stderr (OpenSSH's advisory kept out of a reported error), discovery
(listings, path classification, child-repo scans), newrepo (a directory for
a repository that does not exist yet) and diff (diffs and worktree stats).
The runtime creates, syncs and removes worktrees, from the workspace URLs a
Task names. git::* is still one flat
surface; no caller names a submodule.
coordinator/—main's own body.Appand its state stay in
main.rs; its behaviour is here, grouped by what it is for: the loop and its
workers (mod), then commands, publish, draw, input, mouse, focus,
events (the one dispatch point, and the kernel events derived from the
loop's own signals) and interface — plus boot (the startup sequence main delegates to),
chrome (the terminal/error-panel/perf-HUD helpers), editor (the
Ctrl+O command resolution), control (applying thurbox-cli ui requests on
the loop, ADR-33) and paste (rebuilding a paste from the key stream the
Windows console delivers). Still one model and one loop — splitting App
itself is what ADR-23 rejects, and the invariants that matter hold across
these groups.
ui/(Lua, not Rust) —layout.luais the arrangement;lib/holds
widgets, theme roles, fuzzy match, text input, trees — plus the extracted
pane halves: chrome (every framed pane's focus styling), modal
(frame + footer), scroll,
order and session_model (the session list's model, with its memo),
pathpicker and repo_picker (the creation flow's); mods/ holds the
panes.
fleet_link—FleetLink, the one place afleet …call becomes a
process: the kernel's commands, watch, manager and attach and doctor's
probes all go through it, on this machine or through a shell
launcher (ssh, WSL), with stdin, stdout and exit codes unchanged. Nothing
else in kernel or cli starts Fleet. A link is built from a
[fleets.<name>] entry of settings.toml (FleetLink::of). The session
list follows every listed Fleet; commands go to FleetLink::in_force until
each reaches its row's own Fleet.
cli/—thurbox-clisubcommands (thethurbox-cliskill).
Event Loop (`src/main.rs` + `src/coordinator/`)
tokio::main → load config + settings
→ resolve ui/ → build the Lua host → follow `fleet watch` (and keep a
`fleet up`) → init terminal → loop {
resolve layout → call each mod with its rect → paint
→ poll workers (terminals, commands, diffs, metrics, repos, runs, updates)
→ dispatch events to the mods subscribed to them (kernel::events)
→ drain Lua's command queue → dispatch keys through the registry
} → restore terminal
- Logging goes to a daily
thurbox.log.<date>in the data directory (stdout
is the TUI's)
- A panic hook restores the terminal, pops the kitty flags and disables mouse
reporting before printing — otherwise the shell inherits a raw-mode terminal
streaming mouse reports. A signal gets the same treatment
(coordinator::boot::install_signal_restore): SIGHUP/SIGTERM/SIGINT
run restore_terminal and exit 128 + n, since the default action runs no
hook, and a terminal emulator closing, a session manager, or a machine waking
from a long sleep would leave the next shell printing \x1b[<64;…M on
every scroll. restore_terminal shows the cursor itself for the same
reason — a signal exits from the runtime's thread and drops no Terminal.
The one case no handler reaches is a dropped ssh connection to a remote
thurbox: the ?1003l has no pty to travel down, so the local emulator
keeps reporting — reset there, or run the ssh session inside a local tmux.
tests/tui_e2e.rs pins both exits' escapes.
Writing an interface mod
The bundled set is deliberately small: 10_sessions, 20_agent, 65_search, plus
four floats that occupy no slot — the creation flow (70_new_session), the
confirmation (60_confirm), the rename field (62_rename, Ctrl+E) and the
context menu (64_menu, opened at the pointer by a right press on a session).
thurbox-cli mod dir # which directory is live, and which rule chose it
thurbox-cli mod new notes # a starter that already loads
thurbox-cli mod check # load it the way thurbox does; non-zero on failure
thurbox-cli mod list # the inventory the Interface tab shows
thurbox-cli mod install top # a distributed pane, recorded in mods.toml
thurbox-cli mod sync # make the directory match the spec
Two panes are maintained out of tree, each its own repository, installed
by clone: