Skip to content

Commit 8733a51

Browse files
xianwwuXian Wu
andauthored
fix: CTRL+C handling during multi-select, auto completion for /agent generate (#2741)
* fixing bugs * formatting * fix: CTRL+C handling during multi-select, auto completion for /agent generate * set use legacy mcp config to false --------- Co-authored-by: Xian Wu <[email protected]>
1 parent 82fb2d7 commit 8733a51

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,31 @@ pub enum AgentSubcommand {
9696
Swap { name: Option<String> },
9797
}
9898

99-
fn prompt_mcp_server_selection(servers: &[McpServerInfo]) -> eyre::Result<Vec<&McpServerInfo>> {
99+
fn prompt_mcp_server_selection(servers: &[McpServerInfo]) -> eyre::Result<Option<Vec<&McpServerInfo>>> {
100100
let items: Vec<String> = servers
101101
.iter()
102102
.map(|server| format!("{} ({})", server.name, server.config.command))
103103
.collect();
104104

105-
let selections = MultiSelect::new()
105+
let selections = match MultiSelect::new()
106106
.with_prompt("Select MCP servers (use Space to toggle, Enter to confirm)")
107107
.items(&items)
108-
.interact()?;
109-
110-
let selected_servers: Vec<&McpServerInfo> = selections.iter().filter_map(|&i| servers.get(i)).collect();
108+
.interact_on_opt(&dialoguer::console::Term::stdout())
109+
{
110+
Ok(sel) => sel,
111+
Err(dialoguer::Error::IO(ref e)) if e.kind() == std::io::ErrorKind::Interrupted => {
112+
return Ok(None);
113+
},
114+
Err(e) => return Err(eyre::eyre!("Failed to get MCP server selection: {e}")),
115+
};
116+
117+
let selected_servers: Vec<&McpServerInfo> = selections
118+
.unwrap_or_default()
119+
.iter()
120+
.filter_map(|&i| servers.get(i))
121+
.collect();
111122

112-
Ok(selected_servers)
123+
Ok(Some(selected_servers))
113124
}
114125

115126
impl AgentSubcommand {
@@ -280,7 +291,12 @@ impl AgentSubcommand {
280291
let selected_servers = if mcp_servers.is_empty() {
281292
Vec::new()
282293
} else {
283-
prompt_mcp_server_selection(&mcp_servers).map_err(|e| ChatError::Custom(e.to_string().into()))?
294+
match prompt_mcp_server_selection(&mcp_servers)
295+
.map_err(|e| ChatError::Custom(e.to_string().into()))?
296+
{
297+
Some(servers) => servers,
298+
None => return Ok(ChatState::default()),
299+
}
284300
};
285301

286302
let mcp_servers_json = if !selected_servers.is_empty() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ IMPORTANT: Return ONLY raw JSON with NO markdown formatting, NO code blocks, NO
665665
Your task is to generate an agent configuration file for an agent named '{}' with the following description: {}\n\n\
666666
The configuration must conform to this JSON schema:\n{}\n\n\
667667
We have a prepopulated template: {} \n\n\
668+
Please change the useLegacyMcpJson field to false.
668669
Please generate the prompt field using user provided description, and fill in the MCP tools that user has selected {}.
669670
Return only the JSON configuration, no additional text.",
670671
agent_name, agent_description, schema, prepopulated_content, selected_servers

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub const COMMANDS: &[&str] = &[
6767
"/agent rename",
6868
"/agent set",
6969
"/agent schema",
70+
"/agent generate",
7071
"/prompts",
7172
"/context",
7273
"/context help",

0 commit comments

Comments
 (0)