返回 CodeWhale
mod.rs
根目录 / crates / tui / src / commands / groups / core / mod.rs
1 //! Core command area: model/provider selection, help, navigation, and the
2 //! persistent RLM / sub-agent entry points.
3
4 #[cfg(all(test, feature = "long-running-tests"))]
5 mod acceptance;
6 mod advisor;
7 mod agent;
8 #[cfg(test)]
9 #[allow(clippy::module_inception)]
10 mod core;
11 mod exit;
12 #[cfg(test)]
13 mod feedback;
14 #[cfg(test)]
15 mod fleet;
16 #[cfg(test)]
17 mod lane;
18 pub(in crate::commands) mod navigation;
19 mod pin;
20 mod queue;
21 mod rlm;
22 mod stash;
23 mod subagents;
24 pub mod util;
25
26 pub(crate) use crate::commands::session_reset::reset_conversation_state;
27
28 #[cfg(test)]
29 use crate::commands::CommandResult;
30 use crate::commands::traits::{Command, CommandGroup, ContextualCommand};
31 use codewhale_commands::constitution::ConstitutionCmd;
32 use codewhale_commands::fleet_lane::{FleetCmd, LaneCmd};
33 use codewhale_commands::hooks::HooksCmd;
34 use codewhale_commands::model_setup::{
35 HfCmd, ModelCmd, ModelDbCmd, ModelsCmd, ProfileCmd, ProviderCmd, SetupCmd,
36 };
37
38 use codewhale_commands::workflow::{AutoCmd, WorkflowCmd, WorkflowsCmd};
39
40 pub struct CoreCommands;
41
42 impl CommandGroup for CoreCommands {
43 fn commands(&self) -> &'static [Box<dyn Command>] {
44 cached_command_list!(vec![
45 crate::commands::core_navigation_host::registration::<0>(),
46 Box::new(
47 ContextualCommand::from_contract::<advisor::AdvisorCmd>()
48 .expect("advisor registration")
49 ),
50 crate::commands::core_navigation_host::registration::<1>(),
51 Box::new(
52 ContextualCommand::from_contract::<codewhale_commands::core_policy::ClearCmd>()
53 .expect("clear registration")
54 ),
55 crate::commands::core_navigation_host::registration::<2>(),
56 Box::new(
57 ContextualCommand::from_contract::<exit::ExitCmd>().expect("exit registration")
58 ),
59 Box::new(ContextualCommand::from_contract::<ModelCmd>().expect("model registration")),
60 Box::new(
61 ContextualCommand::from_contract::<codewhale_commands::router::RouterCmd>()
62 .expect("router registration")
63 ),
64 Box::new(ContextualCommand::from_contract::<ModelsCmd>().expect("models registration")),
65 Box::new(
66 ContextualCommand::from_contract::<ModelDbCmd>().expect("modeldb registration")
67 ),
68 Box::new(
69 ContextualCommand::from_contract::<ProviderCmd>().expect("provider registration")
70 ),
71 Box::new(
72 ContextualCommand::from_contract::<queue::QueueCmd>().expect("queue registration")
73 ),
74 Box::new(
75 ContextualCommand::from_contract::<stash::StashCmd>().expect("stash registration")
76 ),
77 Box::new(ContextualCommand::from_contract::<HooksCmd>().expect("hooks registration")),
78 Box::new(
79 ContextualCommand::from_contract::<subagents::SubagentsCmd>()
80 .expect("subagents registration")
81 ),
82 Box::new(
83 ContextualCommand::from_contract::<subagents::AgentProfilesCmd>()
84 .expect("agent profiles registration")
85 ),
86 Box::new(ContextualCommand::from_contract::<FleetCmd>().expect("fleet registration")),
87 Box::new(ContextualCommand::from_contract::<LaneCmd>().expect("lane registration")),
88 Box::new(
89 ContextualCommand::from_contract::<WorkflowCmd>().expect("workflow registration")
90 ),
91 Box::new(
92 ContextualCommand::from_contract::<WorkflowsCmd>().expect("workflows registration")
93 ),
94 Box::new(ContextualCommand::from_contract::<AutoCmd>().expect("auto registration")),
95 crate::commands::core_navigation_host::registration::<3>(),
96 Box::new(ContextualCommand::from_contract::<SetupCmd>().expect("setup registration")),
97 Box::new(
98 ContextualCommand::from_contract::<ConstitutionCmd>()
99 .expect("constitution registration"),
100 ),
101 Box::new(
102 ContextualCommand::from_contract::<agent::AgentCmd>().expect("agent registration")
103 ),
104 crate::commands::core_navigation_host::registration::<4>(),
105 crate::commands::core_navigation_host::registration::<5>(),
106 crate::commands::core_navigation_host::registration::<6>(),
107 Box::new(
108 ContextualCommand::from_contract::<codewhale_commands::core_policy::FeedbackCmd>()
109 .expect("feedback registration")
110 ),
111 Box::new(ContextualCommand::from_contract::<HfCmd>().expect("hf registration")),
112 crate::commands::core_navigation_host::registration::<7>(),
113 crate::commands::core_navigation_host::registration::<8>(),
114 crate::commands::core_navigation_host::registration::<9>(),
115 Box::new(
116 ContextualCommand::from_contract::<ProfileCmd>().expect("profile registration")
117 ),
118 Box::new(ContextualCommand::from_contract::<rlm::RlmCmd>().expect("rlm registration")),
119 crate::commands::core_navigation_host::registration::<10>(),
120 crate::commands::core_navigation_host::registration::<11>(),
121 Box::new(
122 ContextualCommand::from_contract::<codewhale_commands::core_policy::EffortCmd>()
123 .expect("effort registration")
124 ),
125 crate::commands::core_navigation_host::registration::<12>(),
126 crate::commands::core_navigation_host::registration::<13>(),
127 crate::commands::core_navigation_host::registration::<14>(),
128 crate::commands::core_navigation_host::registration::<15>(),
129 Box::new(ContextualCommand::from_contract::<pin::PinCmd>().expect("pin registration")),
130 ])
131 }
132 }
133
134 impl TryFrom<codewhale_command_contract::fleet_lane::FleetAction> for crate::tui::app::AppAction {
135 type Error = String;
136
137 fn try_from(
138 action: codewhale_command_contract::fleet_lane::FleetAction,
139 ) -> Result<Self, String> {
140 use codewhale_command_contract::fleet_lane::FleetAction;
141 Ok(match action {
142 FleetAction::OpenMissions => Self::OpenFleetMissions,
143 FleetAction::OpenRoster => Self::OpenFleetRoster,
144 FleetAction::OpenSetup => Self::OpenFleetSetup,
145 FleetAction::OpenList => Self::OpenFleetList,
146 FleetAction::OpenWorkers => Self::ListSubAgents,
147 FleetAction::AddModel {
148 provider,
149 model,
150 roles,
151 } => Self::FleetAddModel {
152 provider,
153 model,
154 roles,
155 },
156 FleetAction::RemoveModel { provider, model } => {
157 Self::FleetRemoveModel { provider, model }
158 }
159 })
160 }
161 }
162
163 impl From<codewhale_command_contract::outcome::CoreAction> for crate::tui::app::AppAction {
164 fn from(action: codewhale_command_contract::outcome::CoreAction) -> Self {
165 use codewhale_command_contract::outcome::CoreAction;
166 match action {
167 CoreAction::ListSubAgents => Self::ListSubAgents,
168 CoreAction::AgentProfiles { arguments } => Self::AgentProfiles { arguments },
169 CoreAction::SendMessage(message) => Self::SendMessage(message),
170 CoreAction::LaunchSubAgent { task, max_depth } => {
171 Self::SendMessage(agent_dispatch_brief(&task, max_depth))
172 }
173 CoreAction::CancelSubAgent { agent_id } => Self::CancelSubAgent { agent_id },
174 CoreAction::Quit => Self::Quit,
175 CoreAction::FetchModels => Self::FetchModels,
176 CoreAction::SetAdvisorEnabled { enabled } => Self::SetAdvisorEnabled { enabled },
177 CoreAction::SwitchProfile { profile } => Self::SwitchProfile { profile },
178 }
179 }
180 }
181
182 /// The model-facing /agent brief (#6747).
183 fn agent_dispatch_brief(task: &str, max_depth: u32) -> String {
184 format!(
185 "Launch one sub-agent for this task by calling `agent` with name `slash_agent`, `prompt: {task:?}`, and `max_depth: {max_depth}`. Call `handle_read` on the returned transcript_handle if you need more detail. Verify any claimed side effects with `read` before reporting success."
186 )
187 }
188
189 #[cfg(test)]
190 mod agent_host_tests {
191 use crate::tui::app::{App, AppAction};
192 use std::path::PathBuf;
193
194 use crate::tui::app::TuiOptions;
195
196 fn test_app() -> App {
197 let options = TuiOptions {
198 ..crate::tui::test_support::test_tui_options(PathBuf::from("."))
199 };
200 App::new(options, &codewhale_runtime::config::Config::default())
201 }
202
203 /// #6747: the /agent brief names only callable tools.
204 #[test]
205 fn agent_dispatch_brief_names_only_callable_tools() {
206 codewhale_engine::tools::canonical_action_test_support::assert_text_names_only_callable_tools(
207 "/agent brief",
208 &super::agent_dispatch_brief("inspect the repo", 1),
209 );
210 }
211
212 #[test]
213 fn agent_control_actions_route_to_existing_agent_tool() {
214 let mut app = test_app();
215 let result = crate::commands::execute("/agent peek agent_123", &mut app);
216
217 assert!(!result.is_error);
218 let Some(AppAction::SendMessage(message)) = result.action else {
219 panic!("expected SendMessage action");
220 };
221 assert!(message.contains("action `peek`"));
222 assert!(message.contains("agent_id `agent_123`"));
223 assert!(message.contains("Do not start a new agent"));
224
225 let result = crate::commands::execute("/agent cancel agent_123", &mut app);
226 let Some(AppAction::CancelSubAgent { agent_id }) = result.action else {
227 panic!("expected CancelSubAgent action");
228 };
229 assert_eq!(agent_id, "agent_123");
230 }
231 }
232
232 lines RUST