Expand description
The engine-agnostic render/reducer model: ReplApp.
Why: DOC-50 §3.2/§5 Slice 4 generalizes tagent’s ReplApp
(crates/trusty-agents/src/repl/tui/types.rs/app.rs) into the shape
both AgentEngine (tagent) and CodeEngine (tcode) can render against
without either product’s semantics leaking into the shared crate. The
original interleaves ~15 tagent-specific fields (OpenRouter cost
tracking, TM/claude-mpm session counts, model/provider pickers, agent
scope) with the genuinely generic chat/input/history/scroll state DOC-50
§3.2 calls out for extraction — this module keeps only the latter.
Product-specific data (statusline content, picker items, the
slash-command table) flows in through the Slice-1/1.5 seam
(crate::event::ReplEvent::StatuslineUpdate, crate::model) instead
of being hardcoded here, per the generalization mandate.
What: ReplApp is the M the shared crate::run::event_loop drives
(it implements crate::run::TuiModel). reduce::apply is the
apply: FnMut(&mut M, ReplEvent) reducer half of that contract; this
module owns the state and its primitive mutators (insert_char,
backspace, push_user, scroll, …). Most are direct ports; a few
(Up/Down/Ctrl-E key handling) are ports of tagent’s REAL production
behavior rather than its dead-code helpers — see the disclosure list
below, which spells out every point (not just those) where this module’s
behavior differs from tagent’s, since Slice 10’s cutover plans against
exactly this list. A product wiring run() (Slice 5+, tagent’s eventual
AgentEngine/tcode’s CodeEngine) supplies its own product-specific
fields (splash art, banner title, command table) via the public setters
below rather than this crate special-casing either product.
§Disclosed behavioral differences from tagent (DOC-50 §5 Slice 4)
Ported faithfully (same production behavior, verified against
tagent’s actual keys.rs/app.rs, not just its doc comments — one round
of review on this slice caught a doc/reality drift in tagent itself, see
history below):
- Up-arrow recalls
Self::last_prompt(the single most recent submission) and, whenSelf::busy, ALSO setsSelf::pending_cancel— mirrorscrates/trusty-agents/src/repl/tui/keys.rs’s realKeyCode::Uparm, not the multi-levelhistory_prev/history_next#[allow(dead_code)]helpers tagent’s own doc comment (misleadingly) attributes to production Up-handling. - Down-arrow calls
Self::history_next— tagent’s realKeyCode::Downarm does exactly this, even though nothing (including this crate’s Up handler) ever setshistory_idx, making it a functional no-op today in both tagent and here. Ported for fidelity, not because it currently does anything. - Ctrl-E, with an empty input buffer and a non-
NoneSelf::last_bash_block, pastes only that block’s first non-blank line (not the whole block) — matchescrates/trusty-agents/src/repl/tui/keys.rs’sKeyCode::Char('e')arm exactly (the REPL input is single-line; pasting a multi-line block would silently truncate at the first\non submit). - The input composer’s right-aligned
[thinking...]label renders wheneverSelf::busyis true, REGARDLESS of whether the input buffer is empty — mirrorscrates/trusty-agents/src/repl/tui/chat.rs::draw_input.busyis settrueat submit time (not on the first streamed chunk), so the pre-first-token latency window after Enter also shows the indicator.
Deliberately NOT ported (Phase 2 / later-slice / no-shared-crate- formula scope — not oversights):
- The three-row animated activity panel (spinner cycling, elapsed timer,
rust-rainbow shimmer, latest thinking-step echo —
repl/tui/layout.rs::draw_activity,repl/tui/status.rs’sSPINNER_FRAMES/rainbow_spans/hsl_to_rgb).busy: boolis this crate’s entire generalization of tagent’s two-fieldthinking: bool+busy_since: Option<Instant>— there is no elapsed- time derivation available here (no stored startInstant). - Inline token counters in the input row and ALL cost/usage tracking
(
tokens_in/tokens_out,daily_cost_start, usage-file persistence, the OpenRouter pricing formula) — DOC-50 Q9: no cost formula belongs in the shared crate; cost is engine-supplied, pre-formatted, viacrate::model::StatuslineSegment::Cost. - Model/provider pickers (
PickerState/PickerKind) and the inline LLM-offered/slash-completion choice list (choices/choices_context/update_slash_completions) — Phase 2 (DOC-50 §5 Slice 7 and later);crate::model::PickerItem/crate::model::PickerRequestexist (Slice 1.5) but no widget consumes them yet. AgentScope’s User/Project cyan/yellow semantic — replaced by a plainSelf::accent_colorfield with no “scope” concept; the engine decides what it means and when to change it.- The shared
trusty_common::bannersplash art, tagent’s hardcoded banner title/identity text, and its fixed/help//connect//clear//statuscommand list — all now engine-supplied fields (Self::banner_art,Self::banner_title,Self::commands,Self::recent_activity) rather than constants (this crate must not depend ontrusty_common, see DOC-50 §2.2’s dependency direction). - The literal
"[trusty-agents] "status prefix and its exact idle-hint copy ("Ask ctrl anything, or /connect <path> for project work") — generalized toSelf::status_prefix(defaulted fromlabel) and a genericcrate::widgets::input_composerhint string respectively.
Deliberately DIVERGES from tagent (Slice 5, DOC-50 §5 — an intentional improvement per spec, not an oversight or a parity gap):
- Ctrl-C cancels the in-flight request (see
reduce::apply_key’s'c'arm, stagingSelf::pending_cancelforcrate::run::run’s dispatch step to relay as a realTuiEngine::cancel_sessionRPC). Tagent’s actual Ctrl-c (crates/trusty-agents/src/repl/tui/keys.rs) only clears the input buffer — tagent’s cancel trigger is Up-arrow whilethinking. DOC-50 §5 Slice 5 specifies Ctrl-C as the cancel key (the conventional terminal interrupt), which this crate implements as written; Up-arrow-while-busy ALSO still signals cancel here (ported faithfully from tagent, see above), so both triggers work.
§Spec References
SPEC-TTUI-03~draft— §3.2, the generalization layer.SPEC-TTUI-05~draft— Slice 4 deliverable (§5, Slice 4):ReplAppstate.
Structs§
- Chat
Line - One rendered chat entry in the scrollback.
- ReplApp
- All mutable state the shared render/event loop needs to draw one frame.
Enums§
- Chat
Role - Source/role of a chat line — drives the leader glyph and color chosen by
crate::widgets::scrollback::build_chat_lines.