Skip to main content

ReplEvent

Enum ReplEvent 

Source
pub enum ReplEvent {
Show 15 variants Key(KeyInput), Resize(u16, u16), Scroll(isize), Submit(String), Cancel, Quit, TurnFinished { generation: u64, }, AssistantOutput { chunk: String, done: bool, is_error: bool, }, ToolInvocation { id: String, tool_name: String, args: Value, result: Option<String>, }, StatusMessage(String), ClearScrollback, StatuslineUpdate(Vec<StatuslineSegment>), WorkstreamUpdated(WorkstreamSummary), WorkstreamActivationChanged { new_active_id: Option<String>, prior_id: Option<String>, }, ConnectionLost { reason: String, },
}
Expand description

Every event that can flow through the shared TUI’s event channel.

Why: one mpsc::UnboundedSender<ReplEvent> is threaded through the whole stack (engine adapters, the key-reader task, the render loop), mirroring tagent’s proven design in crates/trusty-agents/src/repl/tui/run.rs. A single enum keeps that channel typed and keeps TuiEngine implementors from needing bespoke channels per concern. What: variants are grouped below by who produces them. Terminal-origin variants (Key, Resize, Scroll) are produced by the Slice 2 terminal layer; engine-origin variants (AssistantOutput and later) are produced by TuiEngine implementations; Submit is synthesized by the shared event loop itself (echoed input, picker selection, etc. — see tagent’s process_event for the precedent). The enum is exhaustive per DOC-50 §5 Slice 1’s acceptance criterion (“ReplEvent enum covers all expected event types”); new variants are additive as later slices land (tool cards in Slice 8, permission prompts in Slice 9).

§Spec References

Variants§

§

Key(KeyInput)

Raw keyboard input from the terminal’s key-reader task.

§

Resize(u16, u16)

The terminal was resized to (cols, rows).

§

Scroll(isize)

Mouse-wheel scroll delta. Negative scrolls toward older history (up), positive toward newer (down) — same convention as tagent’s ReplEvent::Scroll.

§

Submit(String)

A line was submitted for the engine to process — either typed and confirmed with Enter, or synthesized (e.g. a picker selection resolving to a slash command). Consumed by TuiEngine::handle_input.

§

Cancel

The user requested cancellation of the in-flight request (Ctrl-C). The shared event loop relays this to TuiEngine::cancel_session (DOC-50 §5 Slice 5) rather than only clearing local UI state, per the thin-client axiom (C-2).

§

Quit

The engine’s handle_input returned Ok(false) (DOC-50 §5 Slice 5) — synthesized by crate::run::run’s dispatch step, never by a key press directly (Ctrl-D sets ReplApp::quit straight from the reducer since it needs no round-trip through the engine). Exists because the dispatch step only holds &mut M synchronously inside apply; the spawned handle_input task that later learns “the engine wants to quit” can reach the model only by pushing an event back onto the shared channel, same as every other engine-originated signal here.

§

TurnFinished

A submitted turn’s TuiEngine::handle_input call has returned, and crate::run::dispatch_pending determined no terminal signal (AssistantOutput { done: true, .. } or Quit) was ever relayed for it — synthesized as a safety net, never by a key press or a TuiEngine implementation directly.

Why: ReplApp::busy is cleared ONLY by a terminal AssistantOutput/Quit reaching the reducer — but three real, spec-required CodeEngine paths return Ok(true) from handle_input without ever sending one (/workstream list/ activate, which only push StatusMessage/WorkstreamUpdated; a reconnect-exhausted pump_session_events return; a daemon-initiated SessionCancelled that only pushes a StatusMessage). Combined with Slice 5’s busy-gating (ReplApp::submit_line refuses a second turn while busy), any such path left busy stuck true forever — input permanently bricked, recoverable only by the accident of Ctrl-C’s on_cancelled reset. This variant is the fix: a dedicated, minimal reset that touches ONLY busy/streaming_idx, deliberately NOT reusing an empty AssistantOutput { done: true, .. } for this (that would push a stray blank chat entry via the None- streaming_idx branch of apply_assistant_output — corrupting scrollback to fix a different bug).

Carries its own generation (the turn number crate::run:: dispatch_pending assigned it) so the reducer — not the spawned completion task — decides whether it’s still relevant. A prior revision had the spawned task load-and-compare the live generation counter itself before deciding whether to send this event at all; that compare-then-send was a genuine TOCTOU race under multi-threaded tokio (a cancel + new submit could both run in the gap between the load and the send), letting a stale terminal signal from turn N clear busy/streaming_idx for a genuinely in-flight turn N+2. Fixed by construction: the completion task now always sends this event (stamped with its own generation, no load-then- branch), and the reducer — which runs serially on the same task that bumps the generation counter, so no cross-thread race is possible — applies it only if generation still matches ReplApp::current_generation. What: engine implementations should never construct this directly; it exists purely as crate::run::dispatch_pending’s per-turn completion safety net (see that function’s doc comment).

Fields

§generation: u64
§

AssistantOutput

A chunk of streamed assistant output. done marks the final chunk of a response so the scrollback can stop showing a “thinking” indicator; is_error marks the text as an error message rather than a normal response (mirrors tagent’s LlmResponse { text, is_error }).

Fields

§chunk: String
§done: bool
§is_error: bool
§

ToolInvocation

A tool was invoked by the backend agent. result is None while the call is in flight and Some(..) once it completes. Rendering (text vs. fancy card) is a Slice 8 (#TBD, Phase 2) concern; the event shape is defined now so TuiEngine implementations don’t need a breaking change later.

id correlates a call’s start (result: None) with its completion (result: Some(..)) — two separate ToolInvocation events sharing the same id. Required because tool_name alone can’t disambiguate repeated or parallel calls to the same tool (e.g. two concurrent fs.read calls); the engine adapter mints this id (a UUID or a backend-supplied call id, whichever it has) and must reuse it across the start/complete pair.

Fields

§tool_name: String
§args: Value
§result: Option<String>
§

StatusMessage(String)

A one-line status message (e.g. “cancelled”, “Switched to: izzie”).

§

ClearScrollback

Clear the scrollback buffer. Emitted by the shared /clear built-in slash command (DOC-50 §5 Slice 7) rather than handled ad hoc by each engine, so TuiEngine implementations never touch scrollback state directly.

§

StatuslineUpdate(Vec<StatuslineSegment>)

Engine-supplied statusline segments replacing the current set (session id, model, project, workstream, …). See StatuslineSegment (crate::model) for the full, Slice-1.5 segment taxonomy.

§

WorkstreamUpdated(WorkstreamSummary)

The active workstream’s summary changed (initial load or refetch after an activation change).

§

WorkstreamActivationChanged

The daemon activated a different workstream (DOC-48 §5.3 WorkstreamActivationChanged), pushed via TuiEngine::subscribe_workstream_events. prior_id is None on the very first activation observed in this session. new_active_id is None when the active workstream was deactivated and none is now active (DOC-48 §4.2/§4.3) — a real, daemon-published state, not an absence of data; distinct from prior_id: None, which means “no activation happened before this one.”

Field names are chosen to match the DOC-48 §5.3 SSE wire event exactly (new_active_id, prior_id) — NOT DOC-50 §5 Slice 6’s prose (new_id), which drifted from the actual wire schema. Since engine adapters deserialize this from JSON (Slice 3/6), a Rust/wire name mismatch here would not be caught at compile time, only at runtime deserialization — so the Rust field is kept byte-identical to the wire field on purpose, including its optionality: the wire event (crate::events::Event::WorkstreamActivationChanged in trusty-code) declares new_active_id: Option<String> for exactly this reason, and this variant now mirrors that shape rather than forcing a lossy StatusMessage fallback for the None case.

Fields

§new_active_id: Option<String>
§prior_id: Option<String>
§

ConnectionLost

The backend connection was lost (daemon restart, SSE stream closed, HTTP timeout/502/503). The TUI shows a “Connection lost” status; input remains live and the next handle_input/ subscribe_workstream_events call attempts to reconnect (DOC-50 §2.4).

Fields

§reason: String

Trait Implementations§

Source§

impl Clone for ReplEvent

Source§

fn clone(&self) -> ReplEvent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReplEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ReplEvent

Source§

fn eq(&self, other: &ReplEvent) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ReplEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more