@@ -11,6 +11,7 @@ use crossterm::{
1111 execute,
1212 queue,
1313} ;
14+ use dialoguer:: Select ;
1415use syntect:: easy:: HighlightLines ;
1516use syntect:: highlighting:: {
1617 Style ,
@@ -78,7 +79,8 @@ pub enum AgentSubcommand {
7879 name : String ,
7980 } ,
8081 /// Swap to a new agent at runtime
81- Swap { name : String } ,
82+ #[ command( alias = "switch" ) ]
83+ Swap { name : Option < String > } ,
8284}
8385
8486impl AgentSubcommand {
@@ -227,7 +229,47 @@ impl AgentSubcommand {
227229 } ,
228230 } ,
229231 Self :: Swap { name } => {
230- session. conversation . swap_agent ( os, & mut session. stderr , & name) . await ?;
232+ if let Some ( name) = name {
233+ session. conversation . swap_agent ( os, & mut session. stderr , & name) . await ?;
234+ } else {
235+ let labels = session
236+ . conversation
237+ . agents
238+ . agents
239+ . keys ( )
240+ . map ( |name| name. as_str ( ) )
241+ . collect :: < Vec < _ > > ( ) ;
242+
243+ let name = {
244+ let idx = match Select :: with_theme ( & crate :: util:: dialoguer_theme ( ) )
245+ . with_prompt ( "Choose one of the following agents" )
246+ . items ( & labels)
247+ . default ( 1 )
248+ . interact_on_opt ( & dialoguer:: console:: Term :: stdout ( ) )
249+ {
250+ Ok ( sel) => {
251+ let _ = crossterm:: execute!(
252+ std:: io:: stdout( ) ,
253+ crossterm:: style:: SetForegroundColor ( crossterm:: style:: Color :: Magenta )
254+ ) ;
255+ sel
256+ } ,
257+ // Ctrl‑C -> Err(Interrupted)
258+ Err ( dialoguer:: Error :: IO ( ref e) ) if e. kind ( ) == std:: io:: ErrorKind :: Interrupted => None ,
259+ Err ( e) => {
260+ return Err ( ChatError :: Custom (
261+ format ! ( "Dialog has failed to make a selection {e}" ) . into ( ) ,
262+ ) ) ;
263+ } ,
264+ } ;
265+
266+ idx. and_then ( |idx| labels. get ( idx) . cloned ( ) . map ( str:: to_string) )
267+ } ;
268+
269+ if let Some ( name) = name {
270+ session. conversation . swap_agent ( os, & mut session. stderr , & name) . await ?;
271+ }
272+ }
231273 } ,
232274 }
233275
0 commit comments