Skip to main content

CommandHandler

Trait CommandHandler 

Source
pub trait CommandHandler<Ctx: ?Sized>: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn description(&self) -> &'static str;
    fn category(&self) -> SlashCategory;
    fn handle<'a>(
        &'a self,
        ctx: &'a mut Ctx,
        args: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>>;

    // Provided methods
    fn args_hint(&self) -> &'static str { ... }
    fn feature_gate(&self) -> Option<&'static str> { ... }
    fn requires_auth(&self) -> bool { ... }
}
Expand description

A slash command handler that can be registered with CommandRegistry.

Implementors must be Send + Sync because the registry is constructed at agent initialization time and handlers may be invoked from async contexts.

§Object safety

The handle method uses Pin<Box<dyn Future>> instead of async fn to remain object-safe, enabling the registry to store Box<dyn CommandHandler<Ctx>>. Slash commands are user-initiated so the box allocation is negligible.

Required Methods§

Source

fn name(&self) -> &'static str

Command name including the leading slash, e.g. "/help".

Must be unique per registry. Used as the dispatch key.

Source

fn description(&self) -> &'static str

One-line description shown in /help output.

Source

fn category(&self) -> SlashCategory

Category for grouping in /help.

Source

fn handle<'a>( &'a self, ctx: &'a mut Ctx, args: &'a str, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>>

Execute the command.

§Arguments
  • ctx: Typed access to agent subsystems.
  • args: Trimmed text after the command name. Empty string when no args given.
§Errors

Returns Err(CommandError) when the command fails. The dispatch site logs and reports the error to the user.

Provided Methods§

Source

fn args_hint(&self) -> &'static str

Argument hint shown after the command name in help, e.g. "[path]".

Return an empty string if the command takes no arguments.

Source

fn feature_gate(&self) -> Option<&'static str>

Feature gate label, if this command is conditionally compiled.

Source

fn requires_auth(&self) -> bool

Returns true if this command requires a trusted (local) caller.

When true, CommandRegistry::dispatch rejects the command with an authorization error if the dispatch site passes trusted = false.

The default returns true (fail-closed): a handler that does not override this method requires a trusted session. Read-only or self-gated commands that are safe to expose on remote channels (Telegram, Discord, Slack) must explicitly opt out by overriding this to return false.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl CommandHandler<CommandContext<'_>> for AcpCommand

Source§

impl CommandHandler<CommandContext<'_>> for AgentCommand

Source§

impl CommandHandler<CommandContext<'_>> for AgentsFleetCommand

Source§

impl CommandHandler<CommandContext<'_>> for CacheStatsCommand

Source§

impl CommandHandler<CommandContext<'_>> for CavemanCommand

Source§

impl CommandHandler<CommandContext<'_>> for CdCommand

Source§

impl CommandHandler<CommandContext<'_>> for ClearCommand

Source§

impl CommandHandler<CommandContext<'_>> for ClearQueueCommand

Source§

impl CommandHandler<CommandContext<'_>> for CompactCommand

Source§

impl CommandHandler<CommandContext<'_>> for ConvCommand

Source§

impl CommandHandler<CommandContext<'_>> for DebugDumpCommand

Source§

impl CommandHandler<CommandContext<'_>> for DumpFormatCommand

Source§

impl CommandHandler<CommandContext<'_>> for ExitCommand

Source§

impl CommandHandler<CommandContext<'_>> for ExperimentCommand

Source§

impl CommandHandler<CommandContext<'_>> for FeedbackCommand

Source§

impl CommandHandler<CommandContext<'_>> for FocusCommand

Source§

impl CommandHandler<CommandContext<'_>> for GoalCommand

Source§

impl CommandHandler<CommandContext<'_>> for GraphCommand

Source§

impl CommandHandler<CommandContext<'_>> for GuardrailCommand

Source§

impl CommandHandler<CommandContext<'_>> for GuidelinesCommand

Source§

impl CommandHandler<CommandContext<'_>> for HelpCommand

Source§

impl CommandHandler<CommandContext<'_>> for HistoryCommand

Source§

impl CommandHandler<CommandContext<'_>> for ImageCommand

Source§

impl CommandHandler<CommandContext<'_>> for KnowledgeSlashCommand

Source§

impl CommandHandler<CommandContext<'_>> for LogCommand

Source§

impl CommandHandler<CommandContext<'_>> for LoopCommand

Source§

impl CommandHandler<CommandContext<'_>> for LspCommand

Source§

impl CommandHandler<CommandContext<'_>> for McpCommand

Source§

impl CommandHandler<CommandContext<'_>> for MemoryCommand

Source§

impl CommandHandler<CommandContext<'_>> for ModelCommand

Source§

impl CommandHandler<CommandContext<'_>> for NewConversationCommand

Source§

impl CommandHandler<CommandContext<'_>> for NotifyTestCommand

Source§

impl CommandHandler<CommandContext<'_>> for PlanCommand

Source§

impl CommandHandler<CommandContext<'_>> for PluginsCommand

Source§

impl CommandHandler<CommandContext<'_>> for PolicyCommand

Source§

impl CommandHandler<CommandContext<'_>> for ProviderCommand

Source§

impl CommandHandler<CommandContext<'_>> for QuitCommand

Source§

impl CommandHandler<CommandContext<'_>> for ReasoningEffortCommand

Source§

impl CommandHandler<CommandContext<'_>> for RecapCommand

Source§

impl CommandHandler<CommandContext<'_>> for RedoCommand

Source§

impl CommandHandler<CommandContext<'_>> for ResetCommand

Source§

impl CommandHandler<CommandContext<'_>> for SchedulerCommand

Source§

impl CommandHandler<CommandContext<'_>> for ScopeCommand

Source§

impl CommandHandler<CommandContext<'_>> for SearchCommand

Source§

impl CommandHandler<CommandContext<'_>> for SideQuestCommand

Source§

impl CommandHandler<CommandContext<'_>> for SkillCommand

Source§

impl CommandHandler<CommandContext<'_>> for SkillsCommand

Source§

impl CommandHandler<CommandContext<'_>> for StatusCommand

Source§

impl CommandHandler<CommandContext<'_>> for StoreSlashCommand

Source§

impl CommandHandler<CommandContext<'_>> for ThinkTokensCommand

Source§

impl CommandHandler<CommandContext<'_>> for TrajectoryCommand

Source§

impl CommandHandler<CommandContext<'_>> for UndoCommand

Source§

impl CommandHandler<CommandContext<'_>> for WorktreeCommand