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).
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 }).
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.
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.
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).
Trait Implementations§
impl StructuralPartialEq for ReplEvent
Auto Trait Implementations§
impl Freeze for ReplEvent
impl RefUnwindSafe for ReplEvent
impl Send for ReplEvent
impl Sync for ReplEvent
impl Unpin for ReplEvent
impl UnsafeUnpin for ReplEvent
impl UnwindSafe for ReplEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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