Skip to content

Commit e992ab0

Browse files
authored
Feat: Add display name action (#722)
1 parent c7935a2 commit e992ab0

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,18 @@ Hi, I'm <g>Amazon Q</g>, your AI Developer Assistant.
447447
execute!(
448448
self.output,
449449
style::SetForegroundColor(Color::DarkGrey),
450-
style::Print("▁".repeat(terminal_width)),
451-
style::ResetColor,
452-
style::Print("\n\nEnter "),
450+
style::Print("\nEnter "),
453451
style::SetForegroundColor(Color::Green),
454452
style::Print("y"),
455-
style::ResetColor,
453+
style::SetForegroundColor(Color::DarkGrey),
456454
style::Print(format!(
457-
" to run {}, or otherwise continue your conversation.\n\n",
455+
" to run {}, otherwise continue without.\n\n",
458456
match tool_uses.len() == 1 {
459457
true => "this tool",
460458
false => "these tools",
461459
}
462460
)),
461+
style::SetForegroundColor(Color::Reset),
463462
)?;
464463
}
465464
let user_input = match self.input_source.read_line(Some("> "))? {
@@ -489,7 +488,7 @@ Hi, I'm <g>Amazon Q</g>, your AI Developer Assistant.
489488
let tool_uses = tool_uses.unwrap_or_default();
490489
Ok(match command {
491490
Command::Ask { prompt } => {
492-
if ["y", "Y"].contains(&prompt.as_str()) {
491+
if ["y", "Y"].contains(&prompt.as_str()) && !tool_uses.is_empty() {
493492
return Ok(ChatState::ExecuteTools(tool_uses));
494493
}
495494

@@ -555,16 +554,15 @@ Hi, I'm <g>Amazon Q</g>, your AI Developer Assistant.
555554
// Execute the requested tools.
556555
let terminal_width = self.terminal_width();
557556
let mut tool_results = vec![];
558-
for tool in tool_uses {
557+
for (i, tool) in tool_uses.into_iter().enumerate() {
559558
let mut tool_telemetry = self.tool_use_telemetry_events.entry(tool.0.clone());
560559
tool_telemetry = tool_telemetry.and_modify(|ev| ev.is_accepted = true);
561560

562561
let tool_start = std::time::Instant::now();
563562
queue!(
564563
self.output,
565-
style::Print("\n\nExecuting "),
566564
style::SetForegroundColor(Color::Cyan),
567-
style::Print(format!("{}...\n", tool.1.display_name())),
565+
style::Print(format!("\n{}. {}...\n", i + 1, tool.1.display_name_action())),
568566
style::SetForegroundColor(Color::DarkGrey),
569567
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
570568
style::SetForegroundColor(Color::Reset),

crates/q_cli/src/cli/chat/tools/execute_bash.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ use std::collections::VecDeque;
22
use std::io::Write;
33
use std::process::Stdio;
44

5+
use crossterm::queue;
56
use crossterm::style::{
67
self,
78
Color,
89
};
9-
use crossterm::{
10-
execute,
11-
queue,
12-
};
1310
use eyre::{
1411
Context as EyreContext,
1512
Result,
@@ -34,14 +31,6 @@ pub struct ExecuteBash {
3431

3532
impl ExecuteBash {
3633
pub async fn invoke(&self, mut updates: impl Write) -> Result<InvokeOutput> {
37-
execute!(
38-
updates,
39-
style::SetForegroundColor(Color::Green),
40-
style::Print(format!("Executing `{}`", &self.command)),
41-
style::ResetColor,
42-
style::Print("\n"),
43-
)?;
44-
4534
// We need to maintain a handle on stderr and stdout, but pipe it to the terminal as well
4635
let mut child = tokio::process::Command::new("bash")
4736
.arg("-c")
@@ -64,31 +53,31 @@ impl ExecuteBash {
6453
let mut stdout_buf = VecDeque::with_capacity(LINE_COUNT);
6554
let mut stderr_buf = VecDeque::with_capacity(LINE_COUNT);
6655

56+
let mut stdout_done = false;
57+
let mut stderr_done = false;
6758
let exit_status = loop {
68-
child.stdin.take();
69-
7059
select! {
7160
biased;
72-
line = stdout.next_line() => match line {
61+
line = stdout.next_line(), if !stdout_done => match line {
7362
Ok(Some(line)) => {
7463
writeln!(updates, "{line}")?;
7564
if stdout_buf.len() >= LINE_COUNT {
7665
stdout_buf.pop_front();
7766
}
7867
stdout_buf.push_back(line);
7968
},
80-
Ok(None) => {},
69+
Ok(None) => stdout_done = true,
8170
Err(err) => error!(%err, "Failed to read stdout of child process"),
8271
},
83-
line = stderr.next_line() => match line {
72+
line = stderr.next_line(), if !stderr_done => match line {
8473
Ok(Some(line)) => {
8574
writeln!(updates, "{line}")?;
8675
if stderr_buf.len() >= LINE_COUNT {
8776
stderr_buf.pop_front();
8877
}
8978
stderr_buf.push_back(line);
9079
},
91-
Ok(None) => {},
80+
Ok(None) => stderr_done = true,
9281
Err(err) => error!(%err, "Failed to read stderr of child process"),
9382
},
9483
exit_status = child.wait() => {

crates/q_cli/src/cli/chat/tools/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ impl Tool {
6969
}
7070
}
7171

72+
// TODO: Remove, just roll with it for now ya?
73+
pub fn display_name_action(&self) -> String {
74+
match self {
75+
Tool::FsRead(_) => "Reading from filesystem",
76+
Tool::FsWrite(_) => "Writing to filesystem",
77+
Tool::ExecuteBash(execute_bash) => return format!("Executing `{}`", execute_bash.command),
78+
Tool::UseAws(_) => "Using AWS CLI",
79+
}
80+
.to_owned()
81+
}
82+
7283
/// Whether or not the tool should prompt the user for consent before [Self::invoke] is called.
7384
pub fn requires_consent(&self, _ctx: &Context) -> bool {
7485
match self {

0 commit comments

Comments
 (0)