Threads, Storage & Agent Protocol
Lumiere's review loop is designed so the interactive TUI (lumiere diff) and external agent commands (lumiere thread ...) can safely read and mutate the same conversation concurrently.
Data model (src/review/thread.rs)
A repository's review state is a list of Thread records:
id: 8-hex-character random identifier (e.g.1a2b3c4d).filename: Repository-relative path.target: EitherAnnotationTarget::FileorAnnotationTarget::LineRange { panel: Old | New, start_line, end_line }(1-indexed inclusive).anchor_text: Exact text of the anchored lines captured when the thread was created, used for relocating the thread across edits and showing context to agents.outdated/resolved: Lifecycle flags.comments: Ordered list ofComment { id, author: Human | Agent, author_name, body, created_at, queued }.
Visibility and turn-taking semantics
- Queued drafts (
queued: true): Newly created reviewer comments start queued until sent viaEnterors. Alllumiere threadsubcommands ignore queued comments, and a thread containing only queued comments is invisible to agents. - Awaiting agent (
thread.awaiting_agent()): True when a thread is open (!resolved) and its most recent non-queued comment was written byAuthor::Human. - Outdated anchor refresh (
refresh_anchors): On every diff reload:- File-level threads are outdated only if the file left the diff.
- Line-range threads check if the lines at
start_line..=end_linestill matchanchor_text. If not, Lumiere searches the file on the same panel side foranchor_text: a unique match updatesstart_line..=end_lineseamlessly; zero or multiple matches flagoutdated = true.
Concurrent persistence (src/review/store.rs)
Threads are stored outside the repository working tree so Git status stays completely clean:
<state_dir>/lumiere/<sha256(canonical_repo_root)[..16]>/threads.json
Where <state_dir> is $XDG_STATE_HOME (default ~/.local/state) on Linux and ~/Library/Application Support on macOS.
Schema (v1)
{
"version": 1,
"threads": [
{
"id": "1a2b3c4d",
"filename": "src/ui/mod.rs",
"target": {
"kind": "line_range",
"panel": "new",
"start_line": 42,
"end_line": 48
},
"anchor_text": "...",
"created_at": 1764000000,
"resolved": false,
"outdated": false,
"comments": [
{
"id": "9f8e7d6c",
"author": "human",
"author_name": "you",
"body": "Should this restore flags on panic?",
"created_at": 1764000000,
"queued": false
}
]
}
]
}
Lock-and-rename concurrency protocol
Every write goes through ThreadStore::update:
- Acquire an exclusive OS advisory lock (
File::lock, Rust 1.89+) on a siblingthreads.lockfile. - Re-read the latest
threads.jsonfrom disk inside the lock (so concurrent replies written by an agent seconds earlier are never clobbered). - Reject files whose
version != 1without overwriting them (forward-compatibility safety). - Apply the mutation closure.
- Write serialized JSON to a unique sibling temp file (
threads.<pid>.<rand>.tmp) and atomicallyfs::renameit overthreads.json.
Live TUI pickup without filesystem watches
On every loop tick, AppState::reload_threads_if_changed() compares StoreStamp ((len, modified_time) from a single stat() call) against the last loaded stamp. Whenever an agent runs lumiere thread reply, the stamp changes, Lumiere reloads threads.json, marks the frame dirty, and renders the reply live — even when --watch is off.
Agent host architecture (src/review/agent/)
Live coding-agent integration is decoupled from any single terminal or multiplexer via the AgentHost trait in src/review/agent/mod.rs (mirroring how vcs::VcsBackend abstracts Git and Jujutsu):
AgentHostexposes four host operations:list_agents(review_roots),find_agent(target_hint),inspect_agent(id), andsend_message(id, message).AgentTarget/AgentStatus/AgentStaterepresent an opaque host-owned target ID, human-readable location label, working directory, app name, and semantic state (Idle,Working,Blocked,Done,Error,Other,Unknown).AgentLinkowns attachment state,Blockedsend refusal, prompt formatting, and control-character stripping without importing any host-specific types.RexHost(src/review/agent/rex.rs) is the currentAgentHostimplementation; future hosts (such as Herdr or tmux) plug in by implementingAgentHostand selecting the active host indefault_host().
Non-blocking AgentWorker
Shelling out to a multiplexer CLI takes tens to hundreds of milliseconds. To keep startup and typing completely stall-free, AgentWorker::spawn runs a dedicated background thread sharing an Arc<dyn AgentHost> over std::sync::mpsc channels:
AgentRequest::Attach— dispatched immediately on startup before the first frame; updates the footer as soon as the host responds.AgentRequest::Refresh— dispatched every 3 seconds while an agent target is attached (never overlapping an in-flight refresh; stale responses for a previously attached target are ignored by opaqueidcomparison).AgentRequest::FindCandidates— dispatched when the user presses A, opening the picker immediately with cached candidates and refreshing it live when discovery finishes.
Rex host discovery & delivery (src/review/agent/rex.rs)
- Discovery executes a single Lua script via
rex do -s <session> --jsonto read each terminal block'sprocess(foreground PID and CWD) andprogram_status(OSC 7501 records). - Only panes where a recognized coding agent's status
owner.pid == foreground.pidand whose CWD is inside one of thereview_rootsqualify. - Delivery (
AgentLink::send_comments) performs a liveinspect_agentrefresh first, aborts if the agent exited or its state isAgentState::Blocked, strips non-newline control characters, and delegates toRexHost::send_message, which wraps the prompt in bracketed paste (\x1b[200~...\x1b[201~) and submits withrex send-key ... enter.