agent_core/tui/commands/
standard.rs

1//! Framework-provided standard commands.
2//!
3//! These commands provide common functionality that most agents will want.
4//! Use them directly or as examples for custom commands.
5
6use super::context::CommandContext;
7use super::result::CommandResult;
8use super::traits::SlashCommand;
9
10// =============================================================================
11// Help Command
12// =============================================================================
13
14/// Show available commands and usage.
15pub struct HelpCommand;
16
17impl SlashCommand for HelpCommand {
18    fn name(&self) -> &str {
19        "help"
20    }
21
22    fn description(&self) -> &str {
23        "Show available commands and usage"
24    }
25
26    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
27        let mut help = String::from("Available commands:\n\n");
28        for cmd in ctx.commands() {
29            help.push_str(&format!("  /{} - {}\n", cmd.name(), cmd.description()));
30        }
31        CommandResult::Message(help)
32    }
33}
34
35// =============================================================================
36// Clear Command
37// =============================================================================
38
39/// Clear the conversation history.
40pub struct ClearCommand;
41
42impl SlashCommand for ClearCommand {
43    fn name(&self) -> &str {
44        "clear"
45    }
46
47    fn description(&self) -> &str {
48        "Clear the conversation history"
49    }
50
51    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
52        ctx.clear_conversation();
53        CommandResult::Handled
54    }
55}
56
57// =============================================================================
58// Compact Command
59// =============================================================================
60
61/// Compact the conversation history.
62pub struct CompactCommand;
63
64impl SlashCommand for CompactCommand {
65    fn name(&self) -> &str {
66        "compact"
67    }
68
69    fn description(&self) -> &str {
70        "Compact the conversation history"
71    }
72
73    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
74        ctx.compact_conversation();
75        CommandResult::Handled
76    }
77}
78
79// =============================================================================
80// Themes Command
81// =============================================================================
82
83/// Open the theme picker to change colors.
84pub struct ThemesCommand;
85
86impl SlashCommand for ThemesCommand {
87    fn name(&self) -> &str {
88        "themes"
89    }
90
91    fn description(&self) -> &str {
92        "Open theme picker to change colors"
93    }
94
95    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
96        ctx.open_theme_picker();
97        CommandResult::Handled
98    }
99}
100
101// =============================================================================
102// Sessions Command
103// =============================================================================
104
105/// View and switch between sessions.
106pub struct SessionsCommand;
107
108impl SlashCommand for SessionsCommand {
109    fn name(&self) -> &str {
110        "sessions"
111    }
112
113    fn description(&self) -> &str {
114        "View and switch between sessions"
115    }
116
117    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
118        ctx.open_session_picker();
119        CommandResult::Handled
120    }
121}
122
123// =============================================================================
124// Status Command
125// =============================================================================
126
127/// Show current session status.
128pub struct StatusCommand;
129
130impl SlashCommand for StatusCommand {
131    fn name(&self) -> &str {
132        "status"
133    }
134
135    fn description(&self) -> &str {
136        "Show current session status"
137    }
138
139    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
140        CommandResult::Message(format!(
141            "Session: {}\nAgent: {} v{}",
142            ctx.session_id(),
143            ctx.agent_name(),
144            ctx.version()
145        ))
146    }
147}
148
149// =============================================================================
150// Version Command
151// =============================================================================
152
153/// Show application version.
154pub struct VersionCommand;
155
156impl SlashCommand for VersionCommand {
157    fn name(&self) -> &str {
158        "version"
159    }
160
161    fn description(&self) -> &str {
162        "Show application version"
163    }
164
165    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
166        CommandResult::Message(format!("{} v{}", ctx.agent_name(), ctx.version()))
167    }
168}
169
170// =============================================================================
171// Quit Command
172// =============================================================================
173
174/// Exit the application.
175pub struct QuitCommand;
176
177impl SlashCommand for QuitCommand {
178    fn name(&self) -> &str {
179        "quit"
180    }
181
182    fn description(&self) -> &str {
183        "Exit the application"
184    }
185
186    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
187        ctx.request_quit();
188        CommandResult::Quit
189    }
190}
191
192// =============================================================================
193// New Session Command
194// =============================================================================
195
196/// Create a new LLM session.
197pub struct NewSessionCommand;
198
199impl SlashCommand for NewSessionCommand {
200    fn name(&self) -> &str {
201        "new-session"
202    }
203
204    fn description(&self) -> &str {
205        "Create a new LLM session"
206    }
207
208    fn execute(&self, _args: &str, ctx: &mut CommandContext) -> CommandResult {
209        ctx.create_new_session();
210        CommandResult::Handled
211    }
212}
213
214// =============================================================================
215// Default Commands
216// =============================================================================
217
218/// Returns the standard set of commands most agents will want.
219///
220/// Includes: help, clear, compact, themes, sessions, status, version,
221/// new-session, and quit.
222pub fn default_commands() -> Vec<Box<dyn SlashCommand>> {
223    vec![
224        Box::new(HelpCommand),
225        Box::new(ClearCommand),
226        Box::new(CompactCommand),
227        Box::new(ThemesCommand),
228        Box::new(SessionsCommand),
229        Box::new(StatusCommand),
230        Box::new(VersionCommand),
231        Box::new(NewSessionCommand),
232        Box::new(QuitCommand),
233    ]
234}