use std::future::Future;
use std::pin::Pin;
use crate::context::CommandContext;
use crate::{CommandError, CommandHandler, CommandOutput, SlashCategory};
pub struct GoalCommand;
impl CommandHandler<CommandContext<'_>> for GoalCommand {
fn name(&self) -> &'static str {
"/goal"
}
fn description(&self) -> &'static str {
"Manage long-horizon goals that persist across conversation turns"
}
fn args_hint(&self) -> &'static str {
"create <text> [--budget N] | pause | resume | complete | clear | status | list"
}
fn category(&self) -> SlashCategory {
SlashCategory::Session
}
fn handle<'a>(
&'a self,
ctx: &'a mut CommandContext<'_>,
args: &'a str,
) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>> {
use tracing::Instrument as _;
let span = tracing::info_span!("commands.goal.handle");
Box::pin(
async move {
let result = ctx.agent.handle_goal(args).await?;
Ok(CommandOutput::Message(result))
}
.instrument(span),
)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::handlers::test_helpers::{MockDebug, MockMessages, MockSession, make_ctx};
use crate::sink::NullSink;
#[test]
fn goal_name_and_description() {
assert_eq!(GoalCommand.name(), "/goal");
assert!(!GoalCommand.description().is_empty());
}
#[tokio::test]
async fn goal_propagates_error_from_agent() {
let mut sink = NullSink;
let mut debug = MockDebug;
let mut messages = MockMessages;
let session = MockSession;
let mut agent = crate::NullAgent;
let mut ctx = make_ctx(&mut sink, &mut debug, &mut messages, &session, &mut agent);
let result = GoalCommand.handle(&mut ctx, "status").await;
assert!(result.is_err());
}
#[tokio::test]
async fn goal_with_empty_args_propagates_error() {
let mut sink = NullSink;
let mut debug = MockDebug;
let mut messages = MockMessages;
let session = MockSession;
let mut agent = crate::NullAgent;
let mut ctx = make_ctx(&mut sink, &mut debug, &mut messages, &session, &mut agent);
let result = GoalCommand.handle(&mut ctx, "").await;
assert!(result.is_err());
}
}