agent_core/tui/commands/
standard.rs1use super::context::CommandContext;
7use super::result::CommandResult;
8use super::traits::SlashCommand;
9
10pub 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
35pub 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
57pub 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
79pub 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
101pub 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
123pub 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
149pub 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
170pub 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
192pub 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
214pub 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}