Skip to main content

tinyharness_ui/tui/
mod.rs

1#[allow(
2    clippy::too_many_arguments,
3    clippy::collapsible_if,
4    clippy::cast_lossless,
5    clippy::new_without_default
6)]
7pub mod app;
8#[allow(
9    clippy::too_many_arguments,
10    clippy::collapsible_if,
11    clippy::cast_lossless,
12    clippy::new_without_default
13)]
14pub mod backend;
15#[allow(
16    clippy::too_many_arguments,
17    clippy::collapsible_if,
18    clippy::cast_lossless,
19    clippy::new_without_default
20)]
21pub mod cell;
22#[allow(clippy::too_many_arguments)]
23pub mod event;
24pub mod layout;
25#[allow(
26    clippy::too_many_arguments,
27    clippy::collapsible_if,
28    clippy::cast_lossless
29)]
30pub mod screen;
31pub mod terminal;
32pub mod widget;
33pub mod widgets {
34    pub mod conversation;
35    pub mod input_bar;
36    pub mod sidebar;
37    pub mod spinner;
38    pub mod status_bar;
39    pub mod tool_output;
40}
41
42// ── TUI Agent Integration Types ──────────────────────────────────────────────
43//
44// These types define the communication protocol between the TUI event loop
45// (main thread) and the background agent task (tokio runtime).
46
47/// Events sent FROM the background agent task TO the TUI.
48///
49/// These drive UI updates: streaming text, tool call notifications,
50/// status changes, etc.
51#[derive(Clone, Debug)]
52pub enum TuiAgentEvent {
53    /// The agent started streaming a response.
54    StreamingStarted,
55    /// A chunk of assistant text arrived during streaming.
56    StreamingText(String),
57    /// A chunk of thinking/reasoning text arrived during streaming.
58    StreamingThinking(String),
59    /// The agent finished streaming a response.
60    StreamingDone,
61    /// The agent encountered an error.
62    Error(String),
63    /// A tool call was made by the assistant.
64    ToolCall { name: String, args_summary: String },
65    /// A tool produced a result.
66    ToolResult {
67        name: String,
68        content: String,
69        is_error: bool,
70    },
71    /// The agent mode changed.
72    ModeChanged(String),
73    /// The model name changed.
74    ModelChanged(String),
75    /// Token usage was updated.
76    TokenUpdate { count: u64, limit: Option<u64> },
77    /// Context window warning triggered (70%+ or 90%+).
78    ContextWarning { percentage: f64, critical: bool },
79    /// A system/info message to display.
80    SystemMessage(String),
81    /// The agent is requesting user confirmation for a tool call.
82    /// The TUI should show a confirmation prompt.
83    /// `diff_preview` contains a plain-text unified diff to display (for edit/write).
84    ConfirmTool {
85        name: String,
86        args_summary: String,
87        needs_approval: bool,
88        diff_preview: Option<String>,
89    },
90    /// The agent is asking a question (from the question signal tool).
91    Question {
92        question: String,
93        answers: Vec<String>,
94    },
95    /// The agent loop has exited (clean shutdown).
96    Done,
97}
98
99/// Actions sent FROM the TUI TO the background agent task.
100///
101/// These represent user interactions that the agent needs to know about.
102#[derive(Clone, Debug)]
103pub enum TuiUserAction {
104    /// The user submitted a message (text entered in the input bar).
105    SendMessage(String),
106    /// The user responded to a tool confirmation prompt.
107    ConfirmResponse { approved: bool, auto_accept: bool },
108    /// The user answered a question from the question signal tool.
109    QuestionAnswer(String),
110    /// The user requested to quit.
111    Quit,
112    /// The user interrupted the current generation (Ctrl+C).
113    Interrupt,
114}
115
116// Re-export key types at the module root for convenience
117pub use app::{Focus, TuiApp, TuiGuard, TuiState, spawn_stdin_reader};
118pub use backend::{Backend, StdioBackend, TestBackend};
119pub use cell::{Cell, Color, Style};
120pub use event::{Event, EventParser, Key, KeyEvent, Modifiers, MouseButton, MouseEvent};
121pub use layout::{Constraint, Direction, Layout, Rect};
122pub use screen::Screen;
123pub use terminal::{Size, Terminal};
124pub use widget::{Action, Widget};
125
126pub use widgets::conversation::{ContextWarningLevel, ConversationLine, ConversationWidget};
127pub use widgets::input_bar::InputBarWidget;
128pub use widgets::sidebar::SidebarWidget;
129pub use widgets::spinner::SpinnerWidget;
130pub use widgets::status_bar::StatusBarWidget;
131pub use widgets::tool_output::{ToolOutputWidget, ToolResult, ToolStatus};