Skip to main content

ReplApp

Struct ReplApp 

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

Current input line being edited.

§cursor_pos: usize

Byte offset within input_buf.

§scroll_offset: usize

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

§show_banner: bool

Whether to show the welcome banner in the scrollback.

§label: String

The 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: String

The user’s display name, shown in the banner’s identity line.

§accent_color: Color

Accent 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: String

Prefix 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: String

Banner title text (defaults to label).

§version: String

Version 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).

§banner_art: Vec<Line<'static>>

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

Whether 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: bool

Quit 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: bool

Set 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: String

The 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: u64

The 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

Source

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.

Source

pub fn push_user(&mut self, text: impl Into<String>)

Append a user prompt line to the chat scrollback.

Source

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.

Source

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.

Source

pub fn push_status(&mut self, text: impl Into<String>)

Append a status line (rendered with Self::status_prefix).

Source

pub fn clear_scrollback(&mut self)

Clear the scrollback (backs ReplEvent::ClearScrollback, the shared /clear built-in per DOC-50 §5 Slice 7).

Source

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

Source

pub fn close_picker(&mut self)

Close the active picker without a selection (e.g. Esc). No-op if none is open.

Source

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.

Source

pub fn remember_input(&mut self, line: &str)

Push a line onto history, deduping an immediate repeat.

Source

pub fn set_input(&mut self, s: String)

Set the input buffer + cursor in one shot (cursor moves to the end).

Source

pub fn insert_char(&mut self, c: char)

Insert a single character at the cursor.

Source

pub fn backspace(&mut self)

Backspace: delete the char before the cursor.

Source

pub fn cursor_left(&mut self)

Move the cursor left one char-boundary.

Source

pub fn cursor_right(&mut self)

Move the cursor right one char-boundary.

Source

pub fn history_prev(&mut self)

Up-arrow history navigation.

Source

pub fn history_next(&mut self)

Down-arrow history navigation.

Source

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

Source

pub fn scroll(&mut self, delta: isize)

Apply a scroll delta. Negative = older (up), positive = newer (down). Clamps to [0, last_max_scroll] so mouse-wheel scroll-up can’t accumulate past the actual scrollback height.

Trait Implementations§

Source§

impl Clone for ReplApp

Source§

fn clone(&self) -> ReplApp

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 ReplApp

Source§

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

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

impl TuiModel for ReplApp

Source§

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

Drain-and-clear Self::pending_cancel.

Source§

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)

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

Whether the render loop should exit after the current frame.

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