use anyhow::Result;
use clap::{Args, Subcommand, ValueEnum};
use crate::commands::agent as agent_cmd;
pub fn handle_agent(args: AgentArgs, force: bool) -> Result<()> {
agent_cmd::handle(args, force)
}
#[derive(Args)]
pub struct AgentArgs {
#[command(subcommand)]
pub command: AgentCommand,
}
#[derive(Subcommand)]
pub enum AgentCommand {
#[command(
after_long_help = "Examples:\n cueloop agent overview\n cueloop agent overview --format json\n cueloop agent overview --include-done --done-limit 5"
)]
Overview(AgentOverviewArgs),
#[command(
after_long_help = "Examples:\n cueloop agent next\n cueloop agent next --format json\n cueloop agent next --with-title"
)]
Next(AgentNextArgs),
#[command(
after_long_help = "Examples:\n cueloop agent show CL-0001\n cueloop agent show CL-0001 --format json"
)]
Show(AgentTaskReadArgs),
#[command(
after_long_help = "Different active owners are rejected unless the existing claim is expired or --force is supplied.\n\nExamples:\n cueloop agent claim CL-0001 --owner pi-session-123\n cueloop agent claim CL-0001 --owner codex --ttl-minutes 120\n cueloop agent --force claim CL-0001 --owner replacement-agent"
)]
Claim(AgentClaimArgs),
#[command(
after_long_help = "Examples:\n cueloop agent release CL-0001\n cueloop agent release CL-0001 --owner pi-session-123"
)]
Release(AgentReleaseArgs),
#[command(
after_long_help = "Examples:\n cueloop agent start CL-0001 --note 'Started in current agent session'\n cueloop agent start CL-0001 --evidence 'Reproduced failing test'"
)]
Start(AgentProgressArgs),
#[command(
after_long_help = "Examples:\n cueloop agent note CL-0001 'Found root cause in queue validation'"
)]
Note(AgentTextArgs),
#[command(
after_long_help = "Examples:\n cueloop agent evidence CL-0001 'make agent-ci passed'\n cueloop agent evidence CL-0001 'cargo test -p cueloop machine_contract_test passed'"
)]
Evidence(AgentTextArgs),
#[command(
name = "plan-append",
after_long_help = "Examples:\n cueloop agent plan-append CL-0001 'Run targeted contract tests'"
)]
PlanAppend(AgentTextArgs),
#[command(
after_long_help = "Examples:\n cueloop agent handoff CL-0001\n cueloop agent handoff CL-0001 --next 'Run make agent-ci' --format json"
)]
Handoff(AgentHandoffArgs),
#[command(aliases = ["done"], after_long_help = "Examples:\n cueloop agent complete CL-0001 --evidence 'make agent-ci passed'\n cueloop agent done CL-0001 --note 'No residual risks' --evidence 'cargo test passed'")]
Complete(AgentCompleteArgs),
#[command(
after_long_help = "Examples:\n cueloop agent reject CL-0001 --reason 'Duplicate of CL-0002'"
)]
Reject(AgentRejectArgs),
#[command(
after_long_help = "Examples:\n cueloop agent validate\n cueloop agent validate --format json"
)]
Validate(AgentFormatArgs),
}
#[derive(Args)]
pub struct AgentOverviewArgs {
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
#[arg(long)]
pub include_done: bool,
#[arg(long, default_value_t = 5)]
pub done_limit: usize,
}
#[derive(Args)]
pub struct AgentNextArgs {
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
#[arg(long)]
pub with_title: bool,
}
#[derive(Args)]
pub struct AgentTaskReadArgs {
pub task_id: String,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentClaimArgs {
pub task_id: String,
#[arg(long)]
pub owner: String,
#[arg(long)]
pub ttl_minutes: Option<u32>,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentReleaseArgs {
pub task_id: String,
#[arg(long)]
pub owner: Option<String>,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentProgressArgs {
pub task_id: String,
#[arg(long = "note")]
pub notes: Vec<String>,
#[arg(long = "evidence")]
pub evidence: Vec<String>,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentTextArgs {
pub task_id: String,
pub text: String,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentHandoffArgs {
pub task_id: String,
#[arg(long = "note")]
pub notes: Vec<String>,
#[arg(long)]
pub next: Option<String>,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentCompleteArgs {
pub task_id: String,
#[arg(long = "evidence", required = true)]
pub evidence: Vec<String>,
#[arg(long = "note")]
pub notes: Vec<String>,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentRejectArgs {
pub task_id: String,
#[arg(long)]
pub reason: String,
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Args)]
pub struct AgentFormatArgs {
#[arg(long, value_enum, default_value_t = AgentOutputFormat::Text)]
pub format: AgentOutputFormat,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum AgentOutputFormat {
Text,
Json,
}