Skip to content

Commit 6aa05b6

Browse files
committed
adds interactive menu for swapping agent
1 parent ffbfbb8 commit 6aa05b6

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

crates/chat-cli/src/cli/chat/cli/profile.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crossterm::{
1111
execute,
1212
queue,
1313
};
14+
use dialoguer::Select;
1415
use syntect::easy::HighlightLines;
1516
use 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

8486
impl 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

Comments
 (0)