Skip to content

Commit 25b3062

Browse files
committed
refactor(tools): simplify tool display names and improve output formatting
1 parent f4b1edd commit 25b3062

File tree

3 files changed

+30
-42
lines changed

3 files changed

+30
-42
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,21 +1011,12 @@ where
10111011

10121012
async fn tool_use_execute(&mut self, tool_uses: Vec<QueuedTool>) -> Result<ChatState, ChatError> {
10131013
// Execute the requested tools.
1014-
let terminal_width = self.terminal_width();
10151014
let mut tool_results = vec![];
10161015
for tool in tool_uses {
10171016
let mut tool_telemetry = self.tool_use_telemetry_events.entry(tool.0.clone());
10181017
tool_telemetry = tool_telemetry.and_modify(|ev| ev.is_accepted = true);
10191018

10201019
let tool_start = std::time::Instant::now();
1021-
queue!(
1022-
self.output,
1023-
style::SetForegroundColor(Color::Cyan),
1024-
style::Print(format!("\n{}...\n", tool.1.display_name_action())),
1025-
style::SetForegroundColor(Color::DarkGrey),
1026-
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
1027-
style::SetForegroundColor(Color::Reset),
1028-
)?;
10291020
let invoke_result = tool.1.invoke(&self.ctx, &mut self.output).await;
10301021

10311022
if self.interactive && self.spinner.is_some() {
@@ -1047,7 +1038,8 @@ where
10471038
execute!(
10481039
self.output,
10491040
style::SetForegroundColor(Color::Green),
1050-
style::Print(format!("🟢 Completed in {}s", tool_time)),
1041+
style::SetAttribute(Attribute::Bold),
1042+
style::Print(format!(" ● Completed in {}s", tool_time)),
10511043
style::SetForegroundColor(Color::Reset),
10521044
style::Print("\n"),
10531045
)?;
@@ -1434,22 +1426,28 @@ where
14341426
}
14351427

14361428
async fn print_tool_descriptions(&mut self, tool_uses: &[QueuedTool]) -> Result<(), ChatError> {
1437-
let terminal_width = self.terminal_width();
1429+
const TOOL_BULLET: &str = " ● ";
1430+
const CONTINUATION_LINE: &str = " ⋮ ";
1431+
14381432
for (_, tool) in tool_uses.iter() {
14391433
queue!(
14401434
self.output,
1441-
style::SetForegroundColor(Color::Cyan),
1442-
style::Print(format!("{}\n", tool.display_name())),
1443-
style::SetForegroundColor(Color::Reset),
1444-
style::SetForegroundColor(Color::DarkGrey),
1445-
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
1446-
style::SetForegroundColor(Color::Reset),
1435+
style::SetForegroundColor(Color::Blue),
1436+
style::Print(format!("🛠️ using tool: {}\n", tool.display_name())),
1437+
style::SetForegroundColor(Color::Reset)
14471438
)?;
1439+
queue!(self.output, style::Print(CONTINUATION_LINE))?;
1440+
queue!(self.output, style::Print("\n"))?;
1441+
queue!(self.output, style::Print(TOOL_BULLET))?;
1442+
14481443
tool.queue_description(&self.ctx, &mut self.output)
14491444
.await
14501445
.map_err(|e| ChatError::Custom(format!("failed to print tool: {}", e).into()))?;
1446+
14511447
queue!(self.output, style::Print("\n"))?;
1448+
queue!(self.output, style::Print(CONTINUATION_LINE))?;
14521449
}
1450+
14531451
Ok(())
14541452
}
14551453

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/mod.rs

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

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

0 commit comments

Comments
 (0)