| 1 | //! `/setup` command. `/setup fleet` opens the fleet readiness step. |
| 2 | |
| 3 | use codewhale_command_contract::handler::CommandHandler; |
| 4 | use codewhale_command_contract::metadata::{CommandInfo, RegisterCommand}; |
| 5 | use codewhale_command_contract::model_setup::resolve_action; |
| 6 | use codewhale_command_contract::model_setup::{SetupAction, SetupStep}; |
| 7 | use codewhale_command_contract::outcome::CommandResult; |
| 8 | |
| 9 | const COMMAND_INFO: CommandInfo = CommandInfo { |
| 10 | name: "setup", |
| 11 | aliases: &[], |
| 12 | usage: "/setup [fleet|provider|runtime|constitution|status|hotbar|tools|remote|persistence]", |
| 13 | description_key: "cmd_setup_description", |
| 14 | }; |
| 15 | |
| 16 | pub struct SetupCmd; |
| 17 | |
| 18 | impl<A: for<'a> TryFrom<SetupAction<'a>, Error = String>> RegisterCommand<CommandResult<A>> |
| 19 | for SetupCmd |
| 20 | { |
| 21 | fn info() -> &'static CommandInfo { |
| 22 | &COMMAND_INFO |
| 23 | } |
| 24 | fn handler() -> CommandHandler<CommandResult<A>> { |
| 25 | CommandHandler::Pure(setup) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | fn setup<A: for<'a> TryFrom<SetupAction<'a>, Error = String>>( |
| 30 | arg: Option<&str>, |
| 31 | ) -> CommandResult<A> { |
| 32 | let target = arg.map(str::trim).filter(|arg| !arg.is_empty()); |
| 33 | if let Some(arg) = target { |
| 34 | let mut parts = arg.split_whitespace(); |
| 35 | if matches!(parts.next(), Some("provider" | "providers")) |
| 36 | && let Some(raw_provider) = parts.next() |
| 37 | { |
| 38 | if parts.next().is_some() { |
| 39 | return CommandResult::error("Usage: /setup provider [provider-name]".to_string()); |
| 40 | } |
| 41 | return resolve_action(SetupAction::Provider(raw_provider), None); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | let step = match target { |
| 46 | None | Some("open" | "wizard" | "checkpoint") => None, |
| 47 | Some("provider" | "providers" | "model" | "models" | "route") => { |
| 48 | Some(SetupStep::ProviderModel) |
| 49 | } |
| 50 | Some("runtime" | "posture" | "trust" | "sandbox") => Some(SetupStep::TrustSandbox), |
| 51 | Some("constitution" | "law") => Some(SetupStep::Constitution), |
| 52 | Some("status" | "report" | "verification" | "verify") => Some(SetupStep::Verification), |
| 53 | Some("fleet" | "operate" | "operate-fleet" | "operate_fleet") => { |
| 54 | Some(SetupStep::OperateFleet) |
| 55 | } |
| 56 | Some("hotbar" | "hotkeys" | "shortcuts" | "keys") => Some(SetupStep::Hotbar), |
| 57 | Some("tools" | "tool" | "mcp" | "tools-mcp" | "tools_mcp" | "skills" | "plugins") => { |
| 58 | Some(SetupStep::ToolsMcp) |
| 59 | } |
| 60 | Some( |
| 61 | "remote" | "remote-runtime" | "remote_runtime" | "cloud" | "bridge" | "mobile" |
| 62 | | "phone", |
| 63 | ) => Some(SetupStep::RemoteRuntime), |
| 64 | Some("persistence" | "persist" | "storage") => Some(SetupStep::Persistence), |
| 65 | Some(other) => { |
| 66 | return CommandResult::error(format!( |
| 67 | "Unknown /setup target '{other}'. Try `/setup fleet` to configure saved teams, or \ |
| 68 | `/setup` to open the full setup wizard." |
| 69 | )); |
| 70 | } |
| 71 | }; |
| 72 | resolve_action(SetupAction::OpenWizard(step), None) |
| 73 | } |
| 74 |