Skip to content

Commit 7cafb71

Browse files
authored
refactor(tools): simplify tool display names and improve output formatting (#999)
1 parent c7106bf commit 7cafb71

File tree

7 files changed

+47
-51
lines changed

7 files changed

+47
-51
lines changed

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ where
20802080
play_notification_bell(!allowed);
20812081
}
20822082

2083-
self.print_tool_description(tool, allowed).await?;
2083+
self.print_tool_descriptions(tool, allowed).await?;
20842084

20852085
if allowed {
20862086
tool.accepted = true;
@@ -2101,22 +2101,13 @@ where
21012101
}
21022102

21032103
// Execute the requested tools.
2104-
let terminal_width = self.terminal_width();
21052104
let mut tool_results = vec![];
21062105

21072106
for tool in tool_uses {
21082107
let mut tool_telemetry = self.tool_use_telemetry_events.entry(tool.id.clone());
21092108
tool_telemetry = tool_telemetry.and_modify(|ev| ev.is_accepted = true);
21102109

21112110
let tool_start = std::time::Instant::now();
2112-
queue!(
2113-
self.output,
2114-
style::SetForegroundColor(Color::Cyan),
2115-
style::Print(format!("\n{}...\n", tool.tool.display_name_action())),
2116-
style::SetForegroundColor(Color::DarkGrey),
2117-
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
2118-
style::SetForegroundColor(Color::Reset),
2119-
)?;
21202111
let invoke_result = tool.tool.invoke(&self.ctx, &mut self.output).await;
21212112

21222113
if self.interactive && self.spinner.is_some() {
@@ -2131,14 +2122,18 @@ where
21312122

21322123
let tool_time = std::time::Instant::now().duration_since(tool_start);
21332124
let tool_time = format!("{}.{}", tool_time.as_secs(), tool_time.subsec_millis());
2125+
const CONTINUATION_LINE: &str = " ⋮ ";
21342126

21352127
match invoke_result {
21362128
Ok(result) => {
21372129
debug!("tool result output: {:#?}", result);
21382130
execute!(
21392131
self.output,
2132+
style::Print(CONTINUATION_LINE),
2133+
style::Print("\n"),
21402134
style::SetForegroundColor(Color::Green),
2141-
style::Print(format!("🟢 Completed in {}s", tool_time)),
2135+
style::SetAttribute(Attribute::Bold),
2136+
style::Print(format!(" ● Completed in {}s", tool_time)),
21422137
style::SetForegroundColor(Color::Reset),
21432138
style::Print("\n"),
21442139
)?;
@@ -2154,9 +2149,11 @@ where
21542149
error!(?err, "An error occurred processing the tool");
21552150
execute!(
21562151
self.output,
2152+
style::Print(CONTINUATION_LINE),
2153+
style::Print("\n"),
21572154
style::SetAttribute(Attribute::Bold),
21582155
style::SetForegroundColor(Color::Red),
2159-
style::Print(format!("🔴 Execution failed after {}s:\n", tool_time)),
2156+
style::Print(format!(" Execution failed after {}s:\n", tool_time)),
21602157
style::SetAttribute(Attribute::Reset),
21612158
style::SetForegroundColor(Color::Red),
21622159
style::Print(&err),
@@ -2644,25 +2641,32 @@ where
26442641
};
26452642
}
26462643

2647-
async fn print_tool_description(&mut self, tool_use: &QueuedTool, trusted: bool) -> Result<(), ChatError> {
2648-
let terminal_width = self.terminal_width();
2644+
async fn print_tool_descriptions(&mut self, tool_use: &QueuedTool, trusted: bool) -> Result<(), ChatError> {
2645+
const TOOL_BULLET: &str = " ● ";
2646+
const CONTINUATION_LINE: &str = " ⋮ ";
2647+
26492648
queue!(
26502649
self.output,
2651-
style::SetForegroundColor(Color::Green),
2652-
style::Print(format!("[Tool Request{}] ", if trusted { " - Trusted" } else { "" })),
2653-
style::SetForegroundColor(Color::Cyan),
2654-
style::Print(format!("{}\n", tool_use.tool.display_name())),
2655-
style::SetForegroundColor(Color::Reset),
2656-
style::SetForegroundColor(Color::DarkGrey),
2657-
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
2658-
style::SetForegroundColor(Color::Reset),
2650+
style::SetForegroundColor(Color::Magenta),
2651+
style::Print(format!(
2652+
"🛠️ Using tool: {} {}\n",
2653+
tool_use.tool.display_name(),
2654+
if trusted { "(trusted)".dark_green() } else { "".reset() }
2655+
)),
2656+
style::SetForegroundColor(Color::Reset)
26592657
)?;
2658+
queue!(self.output, style::Print(CONTINUATION_LINE))?;
2659+
queue!(self.output, style::Print("\n"))?;
2660+
queue!(self.output, style::Print(TOOL_BULLET))?;
2661+
2662+
self.output.flush()?;
2663+
26602664
tool_use
26612665
.tool
26622666
.queue_description(&self.ctx, &mut self.output)
26632667
.await
26642668
.map_err(|e| ChatError::Custom(format!("failed to print tool: {}", e).into()))?;
2665-
queue!(self.output, style::Print("\n"))?;
2669+
26662670
Ok(())
26672671
}
26682672

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl ExecuteBash {
114114
updates,
115115
style::SetForegroundColor(Color::Green),
116116
style::Print(&self.command),
117+
style::Print("\n\n"),
117118
style::ResetColor
118119
)?)
119120
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,16 @@ impl FsDirectory {
341341
break;
342342
}
343343
let relative_path = format_path(&cwd, &path);
344-
queue!(
345-
updates,
346-
style::Print("Reading: "),
347-
style::SetForegroundColor(Color::Green),
348-
style::Print(&relative_path),
349-
style::ResetColor,
350-
style::Print("\n"),
351-
)?;
344+
if !relative_path.is_empty() {
345+
queue!(
346+
updates,
347+
style::Print("Reading: "),
348+
style::SetForegroundColor(Color::Green),
349+
style::Print(&relative_path),
350+
style::ResetColor,
351+
style::Print("\n"),
352+
)?;
353+
}
352354
let mut read_dir = ctx.fs().read_dir(path).await?;
353355
while let Some(ent) = read_dir.next_entry().await? {
354356
use std::os::unix::fs::MetadataExt;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl GhIssue {
199199
pub fn queue_description(&self, updates: &mut impl Write) -> Result<()> {
200200
Ok(queue!(
201201
updates,
202-
style::Print("I will prepare a github issue with our conversation history.\n"),
202+
style::Print("I will prepare a github issue with our conversation history.\n\n"),
203203
style::SetForegroundColor(Color::Green),
204204
style::Print(format!("Title: {}\n", &self.title)),
205205
style::ResetColor

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,14 @@ impl Tool {
4848
/// The display name of a tool
4949
pub fn display_name(&self) -> &'static str {
5050
match self {
51-
Tool::FsRead(_) => "Read from filesystem",
52-
Tool::FsWrite(_) => "Write to filesystem",
53-
Tool::ExecuteBash(_) => "Execute shell command",
54-
Tool::UseAws(_) => "Use AWS CLI",
55-
Tool::GhIssue(_) => "Prepare GitHub issue",
51+
Tool::FsRead(_) => "fs_read",
52+
Tool::FsWrite(_) => "fs_write",
53+
Tool::ExecuteBash(_) => "execute_bash",
54+
Tool::UseAws(_) => "use_aws",
55+
Tool::GhIssue(_) => "gh_issue",
5656
}
5757
}
5858

59-
// TODO: Remove, just roll with it for now ya?
60-
pub fn display_name_action(&self) -> String {
61-
match self {
62-
Tool::FsRead(_) => "Reading from filesystem",
63-
Tool::FsWrite(_) => "Writing to filesystem",
64-
Tool::ExecuteBash(execute_bash) => return format!("Executing `{}`", execute_bash.command),
65-
Tool::UseAws(_) => "Using AWS CLI",
66-
Tool::GhIssue(_) => "Preparing GitHub issue",
67-
}
68-
.to_owned()
69-
}
70-
7159
/// Whether or not the tool should prompt the user to accept before [Self::invoke] is called.
7260
pub fn requires_acceptance(&self, _ctx: &Context) -> bool {
7361
match self {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl UseAws {
106106
pub fn queue_description(&self, updates: &mut impl Write) -> Result<()> {
107107
queue!(
108108
updates,
109-
style::Print("Running aws cli command:\n"),
109+
style::Print("Running aws cli command:\n\n"),
110110
style::Print(format!("Service name: {}\n", self.service_name)),
111111
style::Print(format!("Operation name: {}\n", self.operation_name)),
112112
)?;

crates/q_cli/src/cli/issue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub struct IssueCreator {
3232

3333
impl IssueCreator {
3434
pub async fn create_url(&self) -> Result<url::Url> {
35+
println!("Heading over to GitHub...");
36+
3537
let warning = |text: &String| {
3638
format!("<This will be visible to anyone. Do not include personal or sensitive information>\n\n{text}")
3739
};
@@ -78,7 +80,6 @@ impl IssueCreator {
7880
params.iter(),
7981
)?;
8082

81-
println!("Heading over to GitHub...");
8283
if is_remote() || fig_util::open_url_async(url.as_str()).await.is_err() {
8384
println!("Issue Url: {}", url.as_str().underlined());
8485
}

0 commit comments

Comments
 (0)