Skip to content

Commit 80091c7

Browse files
xianwwuXian Wu
andauthored
this contains bug fix from the bug bash for agent generate (#2732)
* fixing bugs * formatting --------- Co-authored-by: Xian Wu <[email protected]>
1 parent 1b5c223 commit 80091c7

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,31 +221,55 @@ impl AgentSubcommand {
221221
},
222222

223223
Self::Generate {} => {
224-
let agent_name = match session.read_user_input("Enter agent name: ", false) {
225-
Some(input) => input.trim().to_string(),
226-
None => {
224+
let agent_name = match crate::util::input("Enter agent name: ", None) {
225+
Ok(input) => input.trim().to_string(),
226+
Err(_) => {
227227
return Ok(ChatState::PromptUser {
228228
skip_printing_tools: true,
229229
});
230230
},
231231
};
232232

233-
let agent_description = match session.read_user_input("Enter agent description: ", false) {
234-
Some(input) => input.trim().to_string(),
235-
None => {
233+
let agent_description = match crate::util::input("Enter agent description: ", None) {
234+
Ok(input) => input.trim().to_string(),
235+
Err(_) => {
236236
return Ok(ChatState::PromptUser {
237237
skip_printing_tools: true,
238238
});
239239
},
240240
};
241241

242242
let scope_options = vec!["Local (current workspace)", "Global (all workspaces)"];
243-
let scope_selection = Select::new()
243+
let scope_selection = match Select::with_theme(&crate::util::dialoguer_theme())
244244
.with_prompt("Agent scope")
245245
.items(&scope_options)
246246
.default(0)
247-
.interact()
248-
.map_err(|e| ChatError::Custom(format!("Failed to get scope selection: {}", e).into()))?;
247+
.interact_on_opt(&dialoguer::console::Term::stdout())
248+
{
249+
Ok(sel) => {
250+
let _ = crossterm::execute!(
251+
std::io::stdout(),
252+
crossterm::style::SetForegroundColor(crossterm::style::Color::Magenta)
253+
);
254+
sel
255+
},
256+
// Ctrl‑C -> Err(Interrupted)
257+
Err(dialoguer::Error::IO(ref e)) if e.kind() == std::io::ErrorKind::Interrupted => {
258+
return Ok(ChatState::PromptUser {
259+
skip_printing_tools: true,
260+
});
261+
},
262+
Err(e) => return Err(ChatError::Custom(format!("Failed to get scope selection: {e}").into())),
263+
};
264+
265+
let scope_selection = match scope_selection {
266+
Some(selection) => selection,
267+
None => {
268+
return Ok(ChatState::PromptUser {
269+
skip_printing_tools: true,
270+
});
271+
},
272+
};
249273

250274
let is_global = scope_selection == 1;
251275

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,25 +1716,19 @@ impl ChatSession {
17161716
// Parse and validate the initial generated config
17171717
let initial_agent_config = match serde_json::from_str::<Agent>(&agent_config_json) {
17181718
Ok(config) => config,
1719-
Err(err) => {
1719+
Err(_) => {
17201720
execute!(
17211721
self.stderr,
17221722
style::SetForegroundColor(Color::Red),
1723-
style::Print(format!("✗ Failed to parse generated agent config: {}\n\n", err)),
1723+
style::Print("✗ The LLM did not generate a valid agent configuration. Please try again.\n\n"),
17241724
style::SetForegroundColor(Color::Reset)
17251725
)?;
1726-
return Err(ChatError::Custom(format!("Invalid agent config: {}", err).into()));
1726+
return Ok(ChatState::PromptUser {
1727+
skip_printing_tools: true,
1728+
});
17271729
},
17281730
};
17291731

1730-
// Display the generated agent config with syntax highlighting
1731-
execute!(
1732-
self.stderr,
1733-
style::SetForegroundColor(Color::Green),
1734-
style::Print(format!("✓ Generated agent config for '{}':\n\n", agent_name)),
1735-
style::SetForegroundColor(Color::Reset)
1736-
)?;
1737-
17381732
let formatted_json = serde_json::to_string_pretty(&initial_agent_config)
17391733
.map_err(|e| ChatError::Custom(format!("Failed to format JSON: {}", e).into()))?;
17401734

@@ -1750,9 +1744,9 @@ impl ChatSession {
17501744
style::Print(format!("✗ Invalid edited configuration: {}\n\n", err)),
17511745
style::SetForegroundColor(Color::Reset)
17521746
)?;
1753-
return Err(ChatError::Custom(
1754-
format!("Invalid agent config after editing: {}", err).into(),
1755-
));
1747+
return Ok(ChatState::PromptUser {
1748+
skip_printing_tools: true,
1749+
});
17561750
},
17571751
};
17581752

0 commit comments

Comments
 (0)