Skip to main content

zeph_commands/handlers/
plan.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Planning handler: `/plan`.
5
6use std::future::Future;
7use std::pin::Pin;
8
9use crate::context::CommandContext;
10use crate::{CommandError, CommandHandler, CommandOutput, SlashCategory};
11
12/// Planning handler for `/plan`.
13///
14/// Delegates to `AgentAccess::handle_plan` which dispatches to `dispatch_plan_command`.
15/// The future is Send because `Agent<C>: Send` and no non-Send guards are held across
16/// await boundaries.
17pub struct PlanCommand;
18
19impl CommandHandler<CommandContext<'_>> for PlanCommand {
20    fn name(&self) -> &'static str {
21        "/plan"
22    }
23
24    fn description(&self) -> &'static str {
25        "Create or manage execution plans"
26    }
27
28    fn args_hint(&self) -> &'static str {
29        "[goal|confirm|cancel|status|list|resume|retry]"
30    }
31
32    fn category(&self) -> SlashCategory {
33        SlashCategory::Planning
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            // Reconstruct the full command string so the plan parser can parse it.
43            let input = if args.is_empty() {
44                "/plan".to_owned()
45            } else {
46                format!("/plan {args}")
47            };
48            let result = ctx.agent.handle_plan(&input).await?;
49            if result.is_empty() {
50                Ok(CommandOutput::Silent)
51            } else {
52                Ok(CommandOutput::Message(result))
53            }
54        })
55    }
56}