| 1 | //! Portable config command group metadata and inventory (FEAT-028). |
| 2 | //! |
| 3 | //! Mirrors `groups/session/mod.rs`: this module is part of the movable source |
| 4 | //! closure and imports only `codewhale-command-contract` — no `App`, no |
| 5 | //! `crate::tui`, no TUI `Command`/`CommandGroup` traits. Host registration, |
| 6 | //! concrete logic and action conversion live in |
| 7 | //! `crate::commands::config_group` and `crate::commands::config_main_host`. |
| 8 | |
| 9 | // This group dir intentionally has a `config.rs` child module with the same |
| 10 | // name. The module_inception allow is a permanent structure rationale, not |
| 11 | // migration scaffolding; see docs/architecture/command-dispatch.md. |
| 12 | #[allow(clippy::module_inception)] |
| 13 | pub mod config; |
| 14 | pub mod import_claude; |
| 15 | pub mod policy; |
| 16 | |
| 17 | use codewhale_command_contract::handler::{CommandCapabilities, CommandContexts, CommandHandler}; |
| 18 | use codewhale_command_contract::metadata::CommandInfo; |
| 19 | use codewhale_command_contract::outcome::ConfigCommandResult; |
| 20 | |
| 21 | static CONFIG_INFO: CommandInfo = CommandInfo { |
| 22 | name: "config", |
| 23 | aliases: &[], |
| 24 | usage: "/config [ask-rules|status|<key> [value]]", |
| 25 | description_key: "cmd_config_description", |
| 26 | }; |
| 27 | static IMPORT_CLAUDE_INFO: CommandInfo = CommandInfo { |
| 28 | name: "import-claude", |
| 29 | aliases: &["import_claude"], |
| 30 | usage: "/import-claude [--apply]", |
| 31 | description_key: "cmd_import_claude_description", |
| 32 | }; |
| 33 | static LOGIN_INFO: CommandInfo = CommandInfo { |
| 34 | name: "login", |
| 35 | aliases: &[], |
| 36 | usage: "/login [status|account|key]", |
| 37 | description_key: "cmd_login_description", |
| 38 | }; |
| 39 | static CONNECT_INFO: CommandInfo = CommandInfo { |
| 40 | name: "connect", |
| 41 | aliases: &[], |
| 42 | usage: "/connect [account|<provider>]", |
| 43 | description_key: "cmd_connect_description", |
| 44 | }; |
| 45 | static DISCONNECT_INFO: CommandInfo = CommandInfo { |
| 46 | name: "disconnect", |
| 47 | aliases: &[], |
| 48 | usage: "/disconnect <provider>", |
| 49 | description_key: "cmd_disconnect_description", |
| 50 | }; |
| 51 | static AUTH_INFO: CommandInfo = CommandInfo { |
| 52 | name: "auth", |
| 53 | aliases: &[], |
| 54 | usage: "/auth xai-device|chatgpt|chatgpt-revoke|orcarouter|orcarouter-revoke", |
| 55 | description_key: "cmd_auth_description", |
| 56 | }; |
| 57 | static RAIL_INFO: CommandInfo = CommandInfo { |
| 58 | name: "workbar", |
| 59 | // /rail and /sidebar are the names users already know; both now drive |
| 60 | // the one workbar. |
| 61 | aliases: &["rail", "sidebar"], |
| 62 | usage: config::WORKBAR_USAGE, |
| 63 | description_key: "cmd_sidebar_description", |
| 64 | }; |
| 65 | static WHALE_INFO: CommandInfo = CommandInfo { |
| 66 | name: "whale", |
| 67 | aliases: &[], |
| 68 | usage: config::WHALE_USAGE, |
| 69 | description_key: "cmd_pet_description", |
| 70 | }; |
| 71 | static SETTINGS_INFO: CommandInfo = CommandInfo { |
| 72 | name: "settings", |
| 73 | aliases: &[], |
| 74 | usage: "/settings [text]", |
| 75 | description_key: "cmd_settings_description", |
| 76 | }; |
| 77 | static STATUSLINE_INFO: CommandInfo = CommandInfo { |
| 78 | name: "statusline", |
| 79 | aliases: &[], |
| 80 | usage: "/statusline", |
| 81 | description_key: "cmd_statusline_description", |
| 82 | }; |
| 83 | static MODE_INFO: CommandInfo = CommandInfo { |
| 84 | name: "mode", |
| 85 | aliases: &["jihua"], |
| 86 | usage: config::MODE_USAGE, |
| 87 | description_key: "cmd_mode_description", |
| 88 | }; |
| 89 | static VIEW_PLAN_INFO: CommandInfo = CommandInfo { |
| 90 | name: "view-plan", |
| 91 | aliases: &["view_plan"], |
| 92 | usage: "/view-plan [view|save|edit|build]", |
| 93 | description_key: "cmd_view_plan_description", |
| 94 | }; |
| 95 | static THEME_INFO: CommandInfo = CommandInfo { |
| 96 | name: "theme", |
| 97 | aliases: &[], |
| 98 | usage: "/theme [name|underwater|custom:<name>|schema|path]", |
| 99 | description_key: "cmd_theme_description", |
| 100 | }; |
| 101 | static VERBOSE_INFO: CommandInfo = CommandInfo { |
| 102 | name: "verbose", |
| 103 | aliases: &[], |
| 104 | usage: "/verbose [on|off]", |
| 105 | description_key: "cmd_verbose_description", |
| 106 | }; |
| 107 | static TRUST_INFO: CommandInfo = CommandInfo { |
| 108 | name: "trust", |
| 109 | aliases: &["xinren"], |
| 110 | usage: "/trust [on|off [--save]|add <path>|remove <path>|list]", |
| 111 | description_key: "cmd_trust_description", |
| 112 | }; |
| 113 | static LOGOUT_INFO: CommandInfo = CommandInfo { |
| 114 | name: "logout", |
| 115 | aliases: &[], |
| 116 | usage: "/logout", |
| 117 | description_key: "cmd_logout_description", |
| 118 | }; |
| 119 | |
| 120 | fn contextual( |
| 121 | capabilities: CommandCapabilities, |
| 122 | handler: fn(CommandContexts<'_>, Option<&str>) -> ConfigCommandResult, |
| 123 | ) -> CommandHandler<ConfigCommandResult> { |
| 124 | CommandHandler::Contextual { |
| 125 | capabilities, |
| 126 | handler, |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /// Complete group inventory, shared by the host registration and |
| 131 | /// the extraction proof. Order is the registration order. |
| 132 | pub fn portable_handlers() -> [(&'static CommandInfo, CommandHandler<ConfigCommandResult>); 18] { |
| 133 | // The policy slice (permissions, status) already exposes a portable |
| 134 | // inventory; re-publish its metadata through this group's inventory. |
| 135 | let [permissions, status] = policy::portable_handlers(); |
| 136 | [ |
| 137 | ( |
| 138 | &CONFIG_INFO, |
| 139 | contextual(config::CONFIG_CAPS, config::config), |
| 140 | ), |
| 141 | ( |
| 142 | &IMPORT_CLAUDE_INFO, |
| 143 | contextual(config::CONFIG_ONLY_CAPS, config::import_claude), |
| 144 | ), |
| 145 | permissions, |
| 146 | (&LOGIN_INFO, contextual(config::LOGIN_CAPS, config::login)), |
| 147 | ( |
| 148 | &CONNECT_INFO, |
| 149 | contextual(config::LOGIN_CAPS, config::connect), |
| 150 | ), |
| 151 | ( |
| 152 | &DISCONNECT_INFO, |
| 153 | contextual(config::LOGIN_CAPS, config::disconnect), |
| 154 | ), |
| 155 | (&AUTH_INFO, CommandHandler::Pure(config::auth)), |
| 156 | ( |
| 157 | &RAIL_INFO, |
| 158 | contextual(config::WORK_SURFACE_CAPS, config::workbar), |
| 159 | ), |
| 160 | (&WHALE_INFO, contextual(config::WHALE_CAPS, config::whale)), |
| 161 | ( |
| 162 | &SETTINGS_INFO, |
| 163 | contextual(config::CONFIG_PRESENTATION_CAPS, config::settings), |
| 164 | ), |
| 165 | status, |
| 166 | (&STATUSLINE_INFO, CommandHandler::Pure(config::statusline)), |
| 167 | (&MODE_INFO, contextual(config::MODE_CAPS, config::mode)), |
| 168 | ( |
| 169 | &THEME_INFO, |
| 170 | contextual(config::CONFIG_PRESENTATION_CAPS, config::theme), |
| 171 | ), |
| 172 | ( |
| 173 | &VERBOSE_INFO, |
| 174 | contextual(config::CONFIG_ONLY_CAPS, config::verbose), |
| 175 | ), |
| 176 | (&TRUST_INFO, contextual(config::TRUST_CAPS, config::trust)), |
| 177 | (&LOGOUT_INFO, contextual(config::LOGIN_CAPS, config::logout)), |
| 178 | (&VIEW_PLAN_INFO, CommandHandler::Pure(config::view_plan)), |
| 179 | ] |
| 180 | } |
| 181 |