agent_core_tui/lib.rs
1//! Agent Core TUI
2//!
3//! TUI frontend for agent-core, providing a ratatui-based terminal interface.
4//!
5//! This crate provides:
6//!
7//! - TuiRunner - Extension to run AgentCore with a TUI
8//! - App - Complete TUI application with chat, input, and command handling
9//! - ChatView - Chat message display with streaming support
10//! - Layout system - Flexible layout system with templates and custom layouts
11//! - Permission and question panels for tool interactions
12//! - Markdown rendering with theming support
13//! - Table rendering
14//! - Session pickers
15//! - Slash command system
16//! - Text input with cursor management
17//! - Theme system with 45+ built-in themes
18//!
19//! # Quick Start
20//!
21//! ```ignore
22//! use agent_core_runtime::agent::{AgentConfig, AgentCore};
23//! use agent_core_tui::AgentCoreExt;
24//!
25//! struct MyConfig;
26//! impl AgentConfig for MyConfig {
27//! fn config_path(&self) -> &str { ".myagent/config.yaml" }
28//! fn default_system_prompt(&self) -> &str { "You are helpful." }
29//! fn log_prefix(&self) -> &str { "myagent" }
30//! fn name(&self) -> &str { "MyAgent" }
31//! }
32//!
33//! fn main() -> std::io::Result<()> {
34//! let agent = AgentCore::new(&MyConfig)?;
35//! agent.into_tui().run()
36//! }
37//! ```
38
39mod app;
40mod runner;
41
42// Re-export runtime modules so crate:: paths in TUI code continue to work
43// This allows the TUI code to use `crate::controller`, `crate::permissions`, etc.
44pub use agent_core_runtime::agent;
45pub use agent_core_runtime::controller;
46pub use agent_core_runtime::permissions;
47pub use agent_core_runtime::client;
48
49// Re-export runner types
50pub use runner::{AgentCoreExt, TuiRunner};
51
52/// Slash command system.
53pub mod commands;
54/// Key handling and bindings.
55pub mod keys;
56/// Layout templates and providers.
57pub mod layout;
58/// Markdown rendering utilities.
59pub mod markdown;
60/// Table rendering utilities.
61pub mod table;
62/// Theme system and built-in themes.
63pub mod themes;
64/// TUI widgets (chat, input, panels).
65pub mod widgets;
66
67// Re-export App and related types
68pub use app::{App, AppConfig};
69
70// Re-export command system types
71pub use commands::{
72 // Standard commands
73 ClearCommand,
74 // Core types
75 CommandContext,
76 CommandRegistry,
77 CommandResult,
78 CompactCommand,
79 CustomCommand,
80 HelpCommand,
81 NewSessionCommand,
82 QuitCommand,
83 SessionsCommand,
84 SlashCommand,
85 StatusCommand,
86 ThemesCommand,
87 VersionCommand,
88 // Helper functions
89 default_commands,
90 filter_commands,
91 generate_help_message,
92 get_command_by_name,
93 is_slash_command,
94 parse_command,
95};
96
97// Re-export main types for convenience (now from widgets module)
98pub use markdown::{
99 ContentSegment, parse_to_spans, parse_to_styled_words, render_markdown_with_prefix,
100 split_content_segments, wrap_with_prefix,
101};
102pub use table::{PulldownRenderer, TableRenderer, is_table_line, is_table_separator, render_table};
103pub use widgets::{
104 // Registerable widgets
105 AnswerState,
106 BatchPermissionPanel,
107 // Core widgets
108 ChatView,
109 // ConversationView trait and factory
110 ConversationView,
111 ConversationViewFactory,
112 EnterAction,
113 FocusItem,
114 MessageRole,
115 PermissionKeyAction,
116 PermissionOption,
117 PermissionPanel,
118 QuestionKeyAction,
119 QuestionPanel,
120 RenderFn,
121 SessionInfo,
122 SessionPickerState,
123 SimpleCommand,
124 SlashCommandDisplay,
125 SlashPopupState,
126 StatusBar,
127 StatusBarConfig,
128 StatusBarData,
129 TextInput,
130 ToolMessageData,
131 ToolStatus,
132 render_session_picker,
133 render_slash_popup,
134};
135
136// Re-export theme types for convenience
137pub use themes::{
138 THEMES, Theme, ThemeInfo, ThemePickerState, current_theme_name, default_theme_name, get_theme,
139 init_theme, list_themes, render_theme_picker, set_theme, theme as app_theme,
140};
141
142// Re-export layout types for convenience
143pub use layout::{
144 LayoutContext, LayoutProvider, LayoutResult, LayoutTemplate, MinimalOptions, SidebarOptions,
145 SidebarPosition, SidebarWidth, SplitOptions, SplitRatio, StandardOptions, WidgetSizes,
146 helpers as layout_helpers,
147};
148
149// Re-export key handling types for convenience
150pub use keys::{
151 AppKeyAction, AppKeyResult, DefaultKeyHandler, ExitHandler, ExitState, KeyBindings, KeyCombo,
152 KeyContext, KeyHandler,
153};