Skip to main content

Module runtime

Module runtime 

Source
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:

  1. Spawns one event-pump task that converts the SessionHost’s callback subscription into a bounded mpsc of AgentSessionEvents.
  2. 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.
  3. Routes every UI event first to the live Editor component, then to InputMapper for app-level dispatch, then forwards the resulting [ViewAction] queue to dispatch_action.
  4. Projects each AgentSessionEvent into ViewState mutations and schedules a coalesced background paint (≤ 16 ms window). Input-driven paints bypass the coalescer and commit on the same loop turn.
  5. On Resize: coalesces to one Txn::Reanchor without clearing. On settle: emits Txn::Settle containing the scrollback block and the inline redraw in one stage-3 write.
  6. On Suspend / Exit / fatal I/O failure: restores terminal modes via the TerminalGuard (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§

AgentSessionHost
Production SessionHost over a live Arc<AgentSession> and the owning Arc<AgentSessionRuntime>.
EventSubscription
Subscription returned by SessionHost::subscribe.
InteractiveRuntime
Live interactive runtime.
InteractiveRuntimeOptions
Outcome of dispatching one [ViewAction].
SessionFooterSnapshot
Session-derived footer values that require async access to persisted history.
SessionSnapshot
Snapshot of session state used to project ViewState.
SharedWriter
Shared-buffer writer for tests so the pi_tui::terminal::guard::TerminalGuard and Tui can write to the same in-memory sink without owning the same Vec.

Enums§

InteractiveExit
Why the runtime exited.
SessionActivity
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::commit before 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§

SessionHost
Asynchronous session surface consumed by the runtime.

Functions§

mock_input
Build a TerminalInput backed by an in-memory channel for tests.
run_interactive_mode
Run interactive mode end-to-end against a real AgentSessionRuntime.

Type Aliases§

ScopedModelEntries
Scoped-model selector entries and their enabled-state map.