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    /// Cumulative session stats updated (tool calls, total tokens).
78    StatsUpdate { tool_calls: u64, total_tokens: u64 },
79    /// Context window warning triggered (70%+ or 90%+).
80    ContextWarning { percentage: f64, critical: bool },
81    /// A system/info message to display.
82    SystemMessage(String),
83    /// The agent is requesting user confirmation for a tool call.
84    /// The TUI should show a confirmation prompt.
85    /// `diff_preview` contains a plain-text unified diff to display (for edit/write).
86    ConfirmTool {
87        name: String,
88        args_summary: String,
89        needs_approval: bool,
90        diff_preview: Option<String>,
91    },
92    /// The agent is asking a question (from the question signal tool).
93    Question {
94        question: String,
95        answers: Vec<String>,
96    },
97    /// The agent loop has exited (clean shutdown).
98    Done,
99}
100
101/// Actions sent FROM the TUI TO the background agent task.
102///
103/// These represent user interactions that the agent needs to know about.
104#[derive(Clone, Debug)]
105pub enum TuiUserAction {
106    /// The user submitted a message (text entered in the input bar).
107    SendMessage(String),
108    /// The user responded to a tool confirmation prompt.
109    ConfirmResponse { approved: bool, auto_accept: bool },
110    /// The user answered a question from the question signal tool.
111    QuestionAnswer(String),
112    /// The user requested to quit.
113    Quit,
114    /// The user interrupted the current generation (Ctrl+C).
115    Interrupt,
116}
117
118// Re-export key types at the module root for convenience
119pub use app::{Focus, TuiApp, TuiGuard, TuiState, spawn_stdin_reader};
120pub use backend::{Backend, StdioBackend, TestBackend};
121pub use cell::{Cell, Color, Style};
122pub use event::{Event, EventParser, Key, KeyEvent, Modifiers, MouseButton, MouseEvent};
123pub use layout::{Constraint, Direction, Layout, Rect};
124pub use screen::Screen;
125pub use terminal::{Size, Terminal};
126pub use widget::{Action, Widget};
127
128pub use widgets::conversation::{ContextWarningLevel, ConversationLine, ConversationWidget};
129pub use widgets::input_bar::InputBarWidget;
130pub use widgets::sidebar::SidebarWidget;
131pub use widgets::spinner::SpinnerWidget;
132pub use widgets::status_bar::StatusBarWidget;
133pub use widgets::tool_output::{ToolOutputWidget, ToolResult, ToolStatus};