trusty_code_tui/lib.rs
1//! `trusty-code-tui` — the engine-agnostic terminal-UI seam shared by
2//! trusty-code's `tcode tui` and trusty-agents' tagent REPL.
3//!
4//! Why: today, tagent owns a mature ratatui-based REPL
5//! (`crates/trusty-agents/src/repl/tui/`) and trusty-code has no interactive
6//! TUI at all. Forking tagent's REPL for trusty-code would duplicate ~2,500
7//! lines of event-loop, widget, and line-editing code and let the two drift.
8//! DOC-50 §2.2 resolves this by extracting the engine-agnostic parts into
9//! this crate; each product supplies a thin [`TuiEngine`] adapter instead.
10//!
11//! What: **Slice 1** (#3412, epic #3411) shipped the seam itself — the
12//! [`TuiEngine`] trait and the [`ReplEvent`] enum both products' adapters
13//! and the shared event loop speak. **Slice 1.5** (#3413) added the
14//! [`model`] module: the engine-supplied data types ([`StatuslineSegment`],
15//! [`PickerItem`]/[`PickerRequest`], [`CommandDescriptor`]) that keep the
16//! statusline, pickers, and slash-command help free of any product-specific
17//! constant (no hardcoded model lists, no hardcoded `/model`/`/provider`
18//! strings, no cost formula). **Slice 2** (#3414) adds the terminal layer
19//! this doc comment used to say was missing: the panic-safe
20//! [`TerminalGuard`] ([`terminal`]), the generic-over-`TuiEngine` render/event
21//! loop ([`run`](mod@crate::run)), and the `crossterm` → [`KeyInput`] translation boundary
22//! ([`keys`]). `ratatui`/`crossterm` are now real dependencies of this crate
23//! (0.30/0.29 — see `Cargo.toml`'s comment on why that diverges from the
24//! rest of the workspace's 0.29/0.28 pin during the migration window) but
25//! stay confined to `terminal`/`run`/`keys`; [`event`] and [`model`]
26//! themselves still have zero terminal-library dependency, by design.
27//! **Slice 4** (#3416, epic #3411, DOC-50 §5 Slice 4) adds the render/reducer
28//! model ([`app`]), the widgets that draw it ([`widgets`]), the pure
29//! markdown-rendering helpers those widgets call into ([`render`]), and the
30//! top-level frame composition ([`layout`]) — generalized, behavior-
31//! preserving ports of tagent's `repl/tui/{chat,banner,markdown,layout}.rs`.
32//! **Slice 7** (#3420, epic #3411, DOC-50 §5 Slice 7 / §6 Q4) adds the
33//! [`commands`] module: the slash-command parser/dispatcher implementing
34//! "mixed routing" — `/help`/`/clear`/`/quit`/`/exit` are client-side
35//! built-ins that never reach `TuiEngine::handle_input`; every other
36//! command (domain commands like `/model`/`/workstream`, plain chat, and
37//! any command this crate doesn't recognize) forwards verbatim, per the
38//! thin-client axiom. Also adds the inline-picker half of that routing
39//! (DOC-50 §3.2/§6 Q6): a bare `/name` matching `TuiEngine::picker(name)`
40//! opens [`ReplApp::active_picker`] instead of forwarding.
41//! See DOC-50 §5 for the full slice breakdown (Slice 10 is the tagent
42//! cutover this crate is building toward).
43//!
44//! Dependency direction (DOC-50 §2.2, binding): `trusty-code` and
45//! `trusty-agents` depend on `trusty-code-tui`; `trusty-code-tui` depends on neither.
46//! This crate's public API therefore never references a product-specific
47//! type.
48//!
49//! # Spec References
50//! - [`SPEC-TTUI-02~draft`](docs/specs/DOC-50-tcode-tui-claude-code-clone.md#SPEC-TTUI-02~draft) — architecture, the engine-adapter seam.
51//! - [`SPEC-TTUI-03~draft`](docs/specs/DOC-50-tcode-tui-claude-code-clone.md#SPEC-TTUI-03~draft) — extraction and migration plan.
52//! - [`SPEC-TTUI-05~draft`](docs/specs/DOC-50-tcode-tui-claude-code-clone.md#SPEC-TTUI-05~draft) — Slice 1, 2, and 4 deliverables and acceptance criteria.
53
54// docs.rs builds a release's documentation once, from the uploaded tarball,
55// so a broken intra-doc link is baked into that version forever and only a new
56// release can correct it. Deny keeps this crate at zero rather than letting the
57// ratchet in `scripts/check_rustdoc_links.sh` absorb a new one.
58#![deny(rustdoc::broken_intra_doc_links)]
59
60pub mod app;
61pub mod commands;
62pub mod engine;
63pub mod event;
64pub mod keys;
65pub mod layout;
66pub mod model;
67pub mod render;
68pub mod run;
69pub mod terminal;
70pub mod text;
71pub mod widgets;
72
73pub use app::{ChatLine, ChatRole, ReplApp};
74pub use commands::{BuiltIn, Forward, Route, dispatch_forward, resolve_forward, route};
75pub use engine::TuiEngine;
76pub use event::{KeyCode, KeyInput, KeyModifiers, ReplEvent, WorkstreamSummary};
77pub use keys::translate_key_event;
78pub use layout::draw;
79pub use model::{CommandDescriptor, CommandRouting, PickerItem, PickerRequest, StatuslineSegment};
80pub use run::{KeyReaderGuard, TuiModel, event_loop, run, spawn_key_reader};
81pub use terminal::TerminalGuard;