Skip to main content

zeph_commands/handlers/
agent_cmd.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Sub-agent management handler: `/agent`.
5
6use std::future::Future;
7use std::pin::Pin;
8
9use crate::context::CommandContext;
10use crate::{CommandError, CommandHandler, CommandOutput, SlashCategory};
11
12/// Manage sub-agents or dispatch `@mention` commands.
13///
14/// Delegates to `AgentAccess::handle_agent_dispatch`, which handles both `/agent`
15/// subcommands and `@name` mentions. Returns `Continue` when the dispatch returns
16/// `None` (no agent matched an `@mention` — fall through to LLM processing).
17pub struct AgentCommand;
18
19impl CommandHandler<CommandContext<'_>> for AgentCommand {
20    fn name(&self) -> &'static str {
21        "/agent"
22    }
23
24    fn description(&self) -> &'static str {
25        "Manage sub-agents"
26    }
27
28    fn args_hint(&self) -> &'static str {
29        "[subcommand]"
30    }
31
32    fn category(&self) -> SlashCategory {
33        SlashCategory::Integration
34    }
35
36    fn handle<'a>(
37        &'a self,
38        ctx: &'a mut CommandContext<'_>,
39        args: &'a str,
40    ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>> {
41        Box::pin(async move {
42            let input = if args.is_empty() {
43                "/agent".to_owned()
44            } else {
45                format!("/agent {args}")
46            };
47            match ctx.agent.handle_agent_dispatch(&input).await? {
48                Some(msg) => Ok(CommandOutput::Message(msg)),
49                None => Ok(CommandOutput::Silent),
50            }
51        })
52    }
53}