agent_core/tui/commands/traits.rs
1//! Core trait for slash commands.
2
3use super::context::CommandContext;
4use super::result::CommandResult;
5
6/// Trait for slash commands.
7///
8/// Implement this for full control over command behavior, or use
9/// [`CustomCommand`](super::CustomCommand) for simple closure-based commands.
10///
11/// # Example
12///
13/// ```ignore
14/// use agent_core::tui::commands::{SlashCommand, CommandContext, CommandResult};
15///
16/// struct CounterCommand {
17/// count: std::sync::atomic::AtomicUsize,
18/// }
19///
20/// impl SlashCommand for CounterCommand {
21/// fn name(&self) -> &str { "count" }
22/// fn description(&self) -> &str { "Increment and show counter" }
23///
24/// fn execute(&self, _args: &str, _ctx: &mut CommandContext) -> CommandResult {
25/// let n = self.count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
26/// CommandResult::Message(format!("Count: {}", n + 1))
27/// }
28/// }
29/// ```
30pub trait SlashCommand: Send + Sync {
31 /// Command name without the leading slash (e.g., "clear").
32 fn name(&self) -> &str;
33
34 /// Short description shown in the slash popup.
35 fn description(&self) -> &str;
36
37 /// Execute the command.
38 ///
39 /// # Arguments
40 /// * `args` - Everything after the command name, trimmed
41 /// * `ctx` - Context providing access to app functionality
42 ///
43 /// # Returns
44 /// A [`CommandResult`] indicating what happened
45 fn execute(&self, args: &str, ctx: &mut CommandContext) -> CommandResult;
46}