Expand description
Live interactive runtime: owns the Tui writer, the TerminalInput
reader, a SessionHost, and the ViewState projection.
This module is the only stdout owner for the interactive mode and the
only place that translates [ViewAction]s into session calls. Everything
outside this file is pure (stateless compose, pure input mapping, view
data). The runtime:
- Spawns one event-pump task that converts the
SessionHost’s callback subscription into a boundedmpscofAgentSessionEvents. - Runs the main
tokio::select!loop over: UI events (keys / paste / resize / focus), session events, partial-message watch ticks, the background coalescer deadline, and shutdown signals. - Routes every UI event first to the live
Editorcomponent, then toInputMapperfor app-level dispatch, then forwards the resulting [ViewAction] queue todispatch_action. - Projects each
AgentSessionEventintoViewStatemutations and schedules a coalesced background paint (≤ 16 ms window). Input-driven paints bypass the coalescer and commit on the same loop turn. - On
Resize: coalesces to oneTxn::Reanchorwithout clearing. Onsettle: emitsTxn::Settlecontaining the scrollback block and the inline redraw in one stage-3 write. - On
Suspend/Exit/ fatal I/O failure: restores terminal modes via theTerminalGuard(owned by the caller) and returns.
The runtime is generic over the writer W (so tests can inject a
std::io::Cursor<Vec<u8>> or
TransactionRecorder) and the
session host S (so tests inject a [FakeSessionHost]). Production wires
W = io::Stdout and S = AgentSessionHost (a future thin wrapper around
Arc<AgentSession>).
§No stdout clone, no second stdin owner, no clears
The runtime owns exactly one Tui<W>, which owns the sole stdout handle.
TerminalInput owns the sole crossterm::event::EventStream. All
terminal mutations go through Tui::commit, whose stage-3 audit rejects
any banned clear sequence (CSI 2J / CSI 3J).
Structs§
- Agent
Session Host - Production
SessionHostover a liveArc<AgentSession>and the owningArc<AgentSessionRuntime>. - Event
Subscription - Subscription returned by
SessionHost::subscribe. - Interactive
Runtime - Live interactive runtime.
- Interactive
Runtime Options - Outcome of dispatching one [
ViewAction]. - Session
Footer Snapshot - Session-derived footer values that require async access to persisted history.
- Session
Snapshot - Snapshot of session state used to project
ViewState. - Shared
Writer - Shared-buffer writer for tests so the
pi_tui::terminal::guard::TerminalGuardandTuican write to the same in-memory sink without owning the sameVec.
Enums§
- Interactive
Exit - Why the runtime exited.
- Session
Activity - Mutually exclusive foreground activity reported by a session snapshot.
Constants§
- BACKGROUND_
COALESCE_ WINDOW - Background coalescing window for streaming / tool / plugin updates.
- DRAW_
TIMEOUT - Maximum time the runtime will wait for one
Tui::commitbefore declaring a draw deadlock (cursor-query trap, runaway probe, etc.). - EVENT_
CHANNEL_ CAPACITY - Bound on the runtime’s incoming event channel. Matches the agent crate’s extension-queue capacity so a lagging consumer surfaces backpressure early.
Traits§
- Session
Host - Asynchronous session surface consumed by the runtime.
Functions§
- mock_
input - Build a
TerminalInputbacked by an in-memory channel for tests. - run_
interactive_ mode - Run interactive mode end-to-end against a real
AgentSessionRuntime.
Type Aliases§
- Scoped
Model Entries - Scoped-model selector entries and their enabled-state map.