Skip to main content

zeph_commands/handlers/
experiment.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Experimental features handler: `/experiment`.
5
6use std::future::Future;
7use std::pin::Pin;
8
9use crate::context::CommandContext;
10use crate::{CommandError, CommandHandler, CommandOutput, SlashCategory};
11
12/// Experimental features handler for `/experiment`.
13///
14/// Delegates to `AgentAccess::handle_experiment` which is now Send-compatible:
15/// `handle_experiment_command_as_string` clones all `Arc` references before `.await`
16/// so no `&mut self` borrow is held across await boundaries.
17pub struct ExperimentCommand;
18
19impl CommandHandler<CommandContext<'_>> for ExperimentCommand {
20    fn name(&self) -> &'static str {
21        "/experiment"
22    }
23
24    fn description(&self) -> &'static str {
25        "Experimental features"
26    }
27
28    fn args_hint(&self) -> &'static str {
29        "[subcommand]"
30    }
31
32    fn category(&self) -> SlashCategory {
33        SlashCategory::Advanced
34    }
35
36    fn feature_gate(&self) -> Option<&'static str> {
37        Some("experiments")
38    }
39
40    fn handle<'a>(
41        &'a self,
42        ctx: &'a mut CommandContext<'_>,
43        args: &'a str,
44    ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>> {
45        Box::pin(async move {
46            let input = if args.is_empty() {
47                "/experiment".to_owned()
48            } else {
49                format!("/experiment {args}")
50            };
51            let result = ctx.agent.handle_experiment(&input).await?;
52            if result.is_empty() {
53                Ok(CommandOutput::Silent)
54            } else {
55                Ok(CommandOutput::Message(result))
56            }
57        })
58    }
59}