Skip to main content

ReplEvent

Enum ReplEvent 

Source
pub enum ReplEvent {
Show 23 variants Key(KeyInput), Resize(u16, u16), Scroll(isize), Submit(String), Cancel, CancelSettled(CancelReply), Quit, TurnFinished { generation: u64, }, AssistantOutput { chunk: String, done: bool, is_error: bool, }, ToolInvocation { id: String, agent_id: String, tool_name: String, args: Value, result: Option<String>, failed: bool, }, AgentOutput { agent_id: String, turn_id: String, chunk: String, done: bool, }, DelegationStarted { agent_id: String, agent: String, task: String, }, DelegationFinished { agent_id: String, agent: String, outcome: DelegationOutcome, }, PermissionRequested { request_id: String, agent: String, agent_id: String, tool: String, subject: String, rule: String, }, PermissionResolved { request_id: String, agent: String, agent_id: String, decision: String, source: String, }, PermissionAnswerFailed { pending: PendingPermission, error: String, }, StatusMessage(String), SplashUpdated(Vec<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_reply (DOC-50 §5 Slice 5) rather than only clearing local UI state, per the thin-client axiom (C-2).

§

CancelSettled(CancelReply)

The reply to that relay landed (#8207) — synthesized by crate::run::dispatch_pending’s spawned cancel task, never by a key press or a TuiEngine implementation directly.

Why: the cancel RPC runs on its own task so a slow backend cannot freeze the render loop, and a spawned task cannot reach &mut ReplApp — so the answer comes back as an event, like every other backend-originated signal here. It exists at all because the TUI must not say “cancelled” on request: until this event arrives the run may still be going, and accepting a prompt in that window is what produced #8207’s -32003 already has a task running. What: the payload names which of the three outcomes came back — see CancelReply. A reply arriving when no cancel is outstanding is ignored by the reducer (crate::app::reduce), so a straggler from an already-settled cancel cannot clobber a newer turn’s state.

§

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 own 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.

agent_id (#7940) is the opaque id of the agent that dispatched the call, matching Self::DelegationStarted’s agent_id when the caller is a delegated sub-agent. Empty when the engine has no attribution to offer. It is what lets the reducer render a delegated agent’s tool calls INSIDE that agent’s block rather than at the top level beside the primary agent’s own.

failed (#4596) is the backend’s own verdict on the call, carried as data. Producers also write a human marker into result (trusty-code sends FAILED: … / ERROR: …), but that text is for the reader — rewording it must never change how the TUI renders the card, which is why the fact travels in its own field. Meaningless while result is None: a call that has not finished has not failed, so a start event sets false. Set true ONLY on a completion the backend reported as unsuccessful.

Fields

§agent_id: String
§tool_name: String
§args: Value
§result: Option<String>
§failed: bool
§

AgentOutput

A chunk of streamed output attributed to a specific agent turn (#7940).

Why: Self::AssistantOutput carries no attribution and the reducer accumulates it into ONE unkeyed in-progress bubble, so a primary agent and a delegated sub-agent streaming at the same time interleave their words into a single chat entry. This variant carries the (agent_id, turn_id) pair the reducer keys a separate bubble on, so concurrent streams stay separate by construction. What: agent_id is the opaque per-spawn agent id; turn_id is the producer’s own per-turn id. Append every chunk sharing one (agent_id, turn_id) key in arrival order; done: true closes that bubble and no further chunk for the key will arrive. Unlike AssistantOutput, this variant never clears the model’s busy flag: one agent’s turn ending is not the human turn ending.

Fields

§agent_id: String
§turn_id: String
§chunk: String
§done: bool
§

DelegationStarted

A delegated sub-agent started working on a task (#7940).

Why: delegation is invisible in the scrollback without it — the sub-agent’s output and tool calls arrive indistinguishable from the primary agent’s. This opens a rendered block the sub-agent’s activity hangs under. What: agent_id is an opaque, producer-minted id, unique per spawn (agent alone cannot separate two concurrent delegations of the same kind). It MAY be empty when the producer announces an intent to delegate before the sub-agent exists; a later DelegationStarted naming the same agent with a non-empty agent_id adopts the already-open block rather than opening a second one. task is a short human summary of what was delegated.

Fields

§agent_id: String
§agent: String
§task: String
§

DelegationFinished

A delegated sub-agent’s run ended (#7940) — closes the block Self::DelegationStarted opened, keyed by the same agent_id.

Fields

§agent_id: String
§agent: String
§

PermissionRequested

A tool call matched an ask permission rule and is SUSPENDED on the backend until this client answers (#3422, wire event from #7948).

Why: the backend has already stopped the call and is waiting; the TUI has to say so and collect an answer, because silence resolves as a deny after the backend’s timeout. The reducer opens a modal prompt on this event — see crate::app::ReplApp::pending_permission. What: request_id is the correlation key the answer goes back on (NOT a tool-call id — the call has not run). agent/agent_id are the same attribution pair Self::DelegationStarted carries, so a prompt raised inside a delegation can name its sub-agent. subject is what the tool would act on, ALREADY redacted and length-bounded by the producer — this crate renders it verbatim and never re-derives it. rule is the matching policy pattern, shown so the user can see why they are being asked.

Fields

§request_id: String
§agent: String
§agent_id: String
§tool: String
§subject: String
§rule: String
§

PermissionResolved

A suspended permission request reached a decision (#3422, wire event from #7948) — the explicit close for the prompt Self::PermissionRequested opened.

Why: the backend decides, not the TUI (thin-client axiom, ADR-0063): a request can resolve without this client answering at all (another client answered, the backend timed out, a remembered grant or an auto-allow mode covered it). This event — not the local key press — is what puts the outcome in the scrollback. What: decision and source are the producer’s own words, rendered verbatim; this crate parses neither. A request_id matching the open prompt closes it, and one that does not is still recorded.

Fields

§request_id: String
§agent: String
§agent_id: String
§decision: String
§source: String
§

PermissionAnswerFailed

Relaying an answer to TuiEngine::respond_permission FAILED (#3422) — the suspended call never heard it.

Why: the prompt closes the moment a key is pressed, before the RPC even starts, so the keyboard is never held hostage by a slow backend. That optimism is only safe if a failure is reversible: without this event the operator loses the modal while the backend keeps holding the call until it times out, with no way to answer again. This is the undo. What: carries the original request verbatim, so the reducer can reopen exactly the prompt that was answered, plus the engine’s own error text for the retry line and the transcript. Emitted ONLY by crate::run::dispatch_pending’s relay task, never by an engine.

Fields

§error: String
§

StatusMessage(String)

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

§

SplashUpdated(Vec<String>)

Engine-supplied startup splash lines, replacing the banner’s generic {banner_title} v{version} identity row (#8164).

Why: the only launch facts this crate can name on its own are the ones a product set on crate::app::ReplApp at construction. Everything an operator actually needs at a glance — the daemon’s build, the session id, the project the session is homed in — is learned from the backend during TuiEngine::setup, after the app was built. This is how those reach the banner. What: a pre-rendered, pre-ordered block of plain lines. This crate composes none of it and parses none of it; the first line is rendered as the header and the rest as body. An empty vector restores the generic identity row.

§

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) -> Self

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: &Self) -> 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, !>

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