pub struct ReplApp {Show 29 fields
pub chat: Vec<ChatLine>,
pub input_buf: String,
pub cursor_pos: usize,
pub scroll_offset: usize,
pub last_max_scroll: Arc<AtomicUsize>,
pub history: Vec<String>,
pub history_idx: Option<usize>,
pub saved_input: Option<String>,
pub show_banner: bool,
pub label: String,
pub user_label: String,
pub accent_color: Color,
pub status_prefix: String,
pub banner_title: String,
pub version: String,
pub recent_activity: Vec<String>,
pub banner_art: Vec<Line<'static>>,
pub commands: Vec<CommandDescriptor>,
pub active_picker: Option<PickerRequest>,
pub busy: bool,
pub streaming_idx: Option<usize>,
pub statusline: Vec<StatuslineSegment>,
pub active_workstream: Option<WorkstreamSummary>,
pub quit: bool,
pub pending_submit: Option<String>,
pub pending_cancel: bool,
pub last_prompt: String,
pub last_bash_block: Option<String>,
pub current_generation: u64,
}Expand description
All mutable state the shared render/event loop needs to draw one frame.
Why: kept separate from the render/event-loop machinery (mirroring
tagent’s original rationale) so unit tests can drive state transitions
without a Terminal. See the module doc comment for what was
deliberately left out of the generalized port.
What: every field is pub (matching tagent’s style — this is a plain
data/mutator struct, not an encapsulated type) so a product binary can
seed banner/branding fields at construction without a builder API.
Fields§
§chat: Vec<ChatLine>Scrollback history of user/assistant/status exchanges.
input_buf: StringCurrent input line being edited.
cursor_pos: usizeByte offset within input_buf.
scroll_offset: usizeNumber of lines scrolled up from the bottom (0 = pinned to newest).
last_max_scroll: Arc<AtomicUsize>Last-rendered maximum scroll offset (published by the scrollback
widget each frame; scroll() clamps against it). Arc so a render
snapshot and the authoritative instance behind a caller’s mutex (if
any) share the same cell — mirrors tagent’s last_max_scroll.
history: Vec<String>In-memory input history (Up-arrow recall).
history_idx: Option<usize>Index into history while navigating. None when not navigating.
saved_input: Option<String>Saved current input while navigating history.
Whether to show the welcome banner in the scrollback.
label: StringThe name shown in the chat leader (⏺ <label> · ) and the input
prompt (<label>> ). Generic replacement for tagent’s
project_name — any single display label a product wants there.
user_label: StringThe user’s display name, shown in the banner’s identity line.
accent_color: ColorAccent color for the chat leader glyph and label. Generic replacement
for tagent’s AgentScope-driven cyan/yellow — a product sets this to
whatever distinguishes its own contexts (or leaves the default).
status_prefix: StringPrefix rendered before every ChatRole::Status line (e.g.
"[tagent] "). Defaults to "[{label}] " in ReplApp::new;
override if a product wants different bracketed text than its
label.
Banner title text (defaults to label).
version: StringVersion string shown in the banner (defaults to this crate’s own version — a product should override with its own).
recent_activity: Vec<String>Recent-activity lines shown in the banner’s right column. Generic
replacement for tagent’s git_commits — a product decides what
“recent activity” means for it (or supplies none).
Optional pre-rendered left-column art (e.g. a splash logo). Empty by default — this crate has no branding assets of its own (see the dependency-direction constraint in the crate-level doc comment: this crate must not depend on a product-specific art asset).
commands: Vec<CommandDescriptor>Slash commands shown in the banner’s “Commands” section, sourced from
crate::engine::TuiEngine::commands plus any client-side built-ins.
active_picker: Option<PickerRequest>An inline picker currently open for selection (DOC-50 §3.2/§6 Q6),
staged by crate::commands::dispatch_forward when a bare /name
submission matches TuiEngine::picker(name). None when no picker
is open. The picker WIDGET itself (navigation/rendering) is a
follow-up slice’s concern (DOC-50 §5 Slice 7’s deliverable scopes
“routing correctness”, not the visual overlay); this field is the
data half of that contract.
busy: boolWhether a response is currently streaming in. Drives the input composer’s placeholder text.
streaming_idx: Option<usize>Index into chat of the in-progress streaming assistant entry, if
any. None when idle.
statusline: Vec<StatuslineSegment>Engine-supplied statusline segments, most recently pushed via
crate::event::ReplEvent::StatuslineUpdate.
active_workstream: Option<WorkstreamSummary>The active workstream, most recently pushed via
crate::event::ReplEvent::WorkstreamUpdated.
quit: boolQuit signal — set on Ctrl-D. Backs TuiModel::should_quit.
pending_submit: Option<String>A line the user just submitted (typed Enter, or a synthesized
ReplEvent::Submit), staged for the outer driver to forward to
TuiEngine::handle_input. apply cannot reach the engine or the
event channel itself (see [reduce]’s doc comment), so — mirroring
tagent’s pending_picker_selection/pending_submit pattern — it
stashes the line here instead. Drained (Option::take) by the
caller after each apply call.
pending_cancel: boolSet when the user pressed Ctrl-C. Drained by the caller, which should
call TuiEngine::cancel_session (thin-client axiom C-2 — cancellation
is the backend’s job, not just clearing local UI state).
last_prompt: StringThe most recently submitted line, restored to input_buf on
Up-arrow. Direct port of tagent’s last_prompt (single-level recall,
not the multi-level history/history_idx browser — see the module
doc comment’s disclosure list for why Up uses this field and not
history_prev).
last_bash_block: Option<String>The most recently seen executable-shell (bash/sh/zsh/fish) fenced
code block across all assistant messages, updated by
Self::update_last_bash_block. Ctrl-E pastes this block’s first
non-blank line into an empty input buffer — direct port of tagent’s
last_bash_block (crates/trusty-agents/src/repl/tui/types.rs).
current_generation: u64The generation number of the turn currently considered “live” —
mirrors crate::run::dispatch_pending’s AtomicU64 counter, updated
via TuiModel::set_current_generation on the SAME serial
event-loop task that owns that counter (never from a spawned task).
A ReplEvent::TurnFinished { generation } whose generation no
longer matches this field is a stale signal from a superseded turn
and is ignored — see that variant’s doc comment for the TOCTOU race
this by-construction design closes (the comparison happens here, in
the reducer, serially — never as a spawned task’s load-then-branch
against the shared counter).
Implementations§
Source§impl ReplApp
impl ReplApp
Sourcepub fn new(label: impl Into<String>, user_label: impl Into<String>) -> Self
pub fn new(label: impl Into<String>, user_label: impl Into<String>) -> Self
Construct a fresh app with sensible generic defaults.
Why: every field needs some value; the defaults chosen here (empty
scrollback, banner visible, cyan accent, no commands/art yet) mirror
tagent’s ReplApp::new starting state minus the fields that didn’t
survive generalization.
What: label/user_label seed both the derived status_prefix and
banner_title — override those two afterward if a product wants
different text than a straight derivation from label.
Sourcepub fn push_user(&mut self, text: impl Into<String>)
pub fn push_user(&mut self, text: impl Into<String>)
Append a user prompt line to the chat scrollback.
Sourcepub fn push_assistant(&mut self, text: impl Into<String>, is_error: bool)
pub fn push_assistant(&mut self, text: impl Into<String>, is_error: bool)
Append an assistant response to the chat scrollback, trimming surrounding and interior blank lines first.
Why: assistant/agent responses regularly arrive with leading/trailing
blank lines and markdown-style \n\n paragraph breaks; rendering
them verbatim leaves visible dead space. See crate::text for the
two trimming passes.
Test: reduce::tests::push_assistant_trims_surrounding_blanks.
Sourcepub fn update_last_bash_block(&mut self)
pub fn update_last_bash_block(&mut self)
Rescan self.chat and refresh Self::last_bash_block with the
last executable-shell fenced block seen across all assistant
messages, newest-first. Direct port of tagent’s
ReplApp::update_last_bash_block
(crates/trusty-agents/src/repl/tui/app.rs).
Why: called after every chat mutation that could introduce or
obsolete a shell block (Self::push_assistant, and the streaming
finalize path in [reduce]) so Ctrl-E’s paste buffer never goes
stale relative to chat.
What: walks chat newest-to-oldest; the first ChatRole::Assistant
entry containing an executable shell fence wins (errors and user/
status entries are skipped — an error entry is never a paste source).
None when no assistant entry has one.
Test: reduce::tests::push_assistant_updates_last_bash_block,
reduce::tests::push_assistant_skips_error_entries_for_bash_block.
Sourcepub fn push_status(&mut self, text: impl Into<String>)
pub fn push_status(&mut self, text: impl Into<String>)
Append a status line (rendered with Self::status_prefix).
Sourcepub fn clear_scrollback(&mut self)
pub fn clear_scrollback(&mut self)
Clear the scrollback (backs ReplEvent::ClearScrollback, the shared
/clear built-in per DOC-50 §5 Slice 7).
Sourcepub fn open_picker(&mut self, request: PickerRequest)
pub fn open_picker(&mut self, request: PickerRequest)
Open an inline picker (DOC-50 §3.2/§6 Q6), staged by
crate::commands::dispatch_forward for a bare command matching
TuiEngine::picker(name).
Sourcepub fn close_picker(&mut self)
pub fn close_picker(&mut self)
Close the active picker without a selection (e.g. Esc). No-op if none is open.
Sourcepub fn confirm_picker_selection(&mut self, index: usize) -> Option<String>
pub fn confirm_picker_selection(&mut self, index: usize) -> Option<String>
Confirm the picker item at index, closing the picker and returning
the composed "{dispatch_command} {selected.id}" line
(crate::commands::compose_selection) to resubmit — mirrors
crate::model::PickerRequest’s documented contract. Returns None
(leaving the picker untouched) when no picker is open or index is
out of range, so a stale/invalid confirmation is a no-op rather than
a panic.
Test: crate::commands::tests::confirm_picker_selection_composes_and_closes,
crate::commands::tests::confirm_picker_selection_out_of_range_is_noop.
Sourcepub fn remember_input(&mut self, line: &str)
pub fn remember_input(&mut self, line: &str)
Push a line onto history, deduping an immediate repeat.
Sourcepub fn set_input(&mut self, s: String)
pub fn set_input(&mut self, s: String)
Set the input buffer + cursor in one shot (cursor moves to the end).
Sourcepub fn insert_char(&mut self, c: char)
pub fn insert_char(&mut self, c: char)
Insert a single character at the cursor.
Sourcepub fn cursor_left(&mut self)
pub fn cursor_left(&mut self)
Move the cursor left one char-boundary.
Sourcepub fn cursor_right(&mut self)
pub fn cursor_right(&mut self)
Move the cursor right one char-boundary.
Sourcepub fn history_prev(&mut self)
pub fn history_prev(&mut self)
Up-arrow history navigation.
Sourcepub fn history_next(&mut self)
pub fn history_next(&mut self)
Down-arrow history navigation.
Sourcepub fn take_input(&mut self) -> Option<String>
pub fn take_input(&mut self) -> Option<String>
Take the current input buffer and reset the editor state. Returns
None if the trimmed buffer was empty (nothing to submit).
Trait Implementations§
Source§impl TuiModel for ReplApp
impl TuiModel for ReplApp
Source§fn take_pending_submit(&mut self) -> Option<String>
fn take_pending_submit(&mut self) -> Option<String>
Drain Self::pending_submit — see crate::run::dispatch_pending
(private to crate::run, called from crate::run::run) for the
caller that reads this after every apply call.
Source§fn take_pending_cancel(&mut self) -> bool
fn take_pending_cancel(&mut self) -> bool
Drain-and-clear Self::pending_cancel.
Source§fn on_cancelled(&mut self)
fn on_cancelled(&mut self)
Reset the in-flight-request UI state the moment a cancel is
dispatched (before the TuiEngine::cancel_session RPC even starts) —
direct parity with tagent’s real cancel path, which resets
thinking/busy_since synchronously ahead of h.abort()
(crates/trusty-agents/src/repl/tui/events.rs::process_event). See
crate::run::TuiModel::on_cancelled’s doc comment for why this is
synchronous rather than waiting on the RPC.
What: clears Self::busy and abandons the in-progress streaming
entry index (a future response starts a fresh chat entry rather than
appending to one no more chunks will ever arrive for), then pushes a
“cancelled” status line.
Test: reduce::tests::apply_ctrl_c_signals_pending_cancel covers
the reducer half; crate::run::tests covers this method being
invoked from the dispatch step.
Source§fn set_current_generation(&mut self, generation: u64)
fn set_current_generation(&mut self, generation: u64)
Record generation into Self::current_generation — see
crate::run::TuiModel::set_current_generation’s doc comment for
why this is called only from dispatch_pending on the serial
event-loop task, and ReplEvent::TurnFinished’s doc comment for
the race this by-construction design closes.
Test: reduce::tests::apply_turn_finished_with_stale_generation_is_ignored,
reduce::tests::apply_turn_finished_clears_busy_and_streaming_idx_without_touching_chat.
Source§fn should_quit(&self) -> bool
fn should_quit(&self) -> bool
Auto Trait Implementations§
impl Freeze for ReplApp
impl RefUnwindSafe for ReplApp
impl Send for ReplApp
impl Sync for ReplApp
impl Unpin for ReplApp
impl UnsafeUnpin for ReplApp
impl UnwindSafe for ReplApp
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