| 1 | //! `/subagents` compatibility command. |
| 2 | |
| 3 | use codewhale_command_contract::handler::{CommandCapabilities, CommandHandler}; |
| 4 | use codewhale_command_contract::metadata::{CommandInfo, RegisterCommand}; |
| 5 | use codewhale_command_contract::navigation::SubagentRosterDisplay; |
| 6 | use codewhale_command_contract::outcome::{CommandResult, CoreAction}; |
| 7 | |
| 8 | const COMMAND_INFO: CommandInfo = CommandInfo { |
| 9 | name: "subagents", |
| 10 | aliases: &["zhinengti"], |
| 11 | usage: "/subagents [list]", |
| 12 | description_key: "cmd_subagents_description", |
| 13 | }; |
| 14 | |
| 15 | pub(super) struct SubagentsCmd; |
| 16 | |
| 17 | impl<A: From<CoreAction>> RegisterCommand<CommandResult<A>> for SubagentsCmd { |
| 18 | fn info() -> &'static CommandInfo { |
| 19 | &COMMAND_INFO |
| 20 | } |
| 21 | |
| 22 | fn handler() -> CommandHandler<CommandResult<A>> { |
| 23 | CommandHandler::Contextual { |
| 24 | capabilities: CommandCapabilities::NAVIGATION, |
| 25 | handler: |contexts, arg| { |
| 26 | let display = match arg.map(str::trim).unwrap_or_default() { |
| 27 | "" => SubagentRosterDisplay::Modal, |
| 28 | "list" | "roster" | "ls" => SubagentRosterDisplay::Transcript, |
| 29 | other => { |
| 30 | return CommandResult::error(format!( |
| 31 | "Unknown /subagents argument {other:?}. Usage: /subagents [list]" |
| 32 | )); |
| 33 | } |
| 34 | }; |
| 35 | let Some(navigation) = contexts.into_parts().navigation else { |
| 36 | return CommandResult::error("Command capability unavailable: navigation"); |
| 37 | }; |
| 38 | navigation.prepare_subagent_roster(display); |
| 39 | CommandResult::action(CoreAction::ListSubAgents.into()) |
| 40 | }, |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | const PROFILES: CommandInfo = CommandInfo { |
| 46 | name: "agents", |
| 47 | aliases: &["whales"], |
| 48 | usage: "/agents [list | show <id> | route <id> <provider> <model>]", |
| 49 | description_key: "cmd_agent_profiles_description", |
| 50 | }; |
| 51 | |
| 52 | pub(super) struct AgentProfilesCmd; |
| 53 | |
| 54 | impl<A: From<CoreAction>> RegisterCommand<CommandResult<A>> for AgentProfilesCmd { |
| 55 | fn info() -> &'static CommandInfo { |
| 56 | &PROFILES |
| 57 | } |
| 58 | |
| 59 | fn handler() -> CommandHandler<CommandResult<A>> { |
| 60 | CommandHandler::Contextual { |
| 61 | capabilities: CommandCapabilities::NAVIGATION, |
| 62 | handler: |_, arg| { |
| 63 | CommandResult::action( |
| 64 | CoreAction::AgentProfiles { |
| 65 | arguments: arg.unwrap_or_default().to_owned(), |
| 66 | } |
| 67 | .into(), |
| 68 | ) |
| 69 | }, |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 |