Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve agentic execution UI #999

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions crates/q_cli/src/cli/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,21 +1011,12 @@ where

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

let tool_start = std::time::Instant::now();
queue!(
self.output,
style::SetForegroundColor(Color::Cyan),
style::Print(format!("\n{}...\n", tool.1.display_name_action())),
style::SetForegroundColor(Color::DarkGrey),
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
style::SetForegroundColor(Color::Reset),
)?;
let invoke_result = tool.1.invoke(&self.ctx, &mut self.output).await;

if self.interactive && self.spinner.is_some() {
Expand All @@ -1047,7 +1038,8 @@ where
execute!(
self.output,
style::SetForegroundColor(Color::Green),
style::Print(format!("🟢 Completed in {}s", tool_time)),
style::SetAttribute(Attribute::Bold),
style::Print(format!(" ● Completed in {}s", tool_time)),
style::SetForegroundColor(Color::Reset),
style::Print("\n"),
)?;
Expand Down Expand Up @@ -1434,22 +1426,28 @@ where
}

async fn print_tool_descriptions(&mut self, tool_uses: &[QueuedTool]) -> Result<(), ChatError> {
let terminal_width = self.terminal_width();
const TOOL_BULLET: &str = " ● ";
const CONTINUATION_LINE: &str = " ⋮ ";

for (_, tool) in tool_uses.iter() {
queue!(
self.output,
style::SetForegroundColor(Color::Cyan),
style::Print(format!("{}\n", tool.display_name())),
style::SetForegroundColor(Color::Reset),
style::SetForegroundColor(Color::DarkGrey),
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
style::SetForegroundColor(Color::Reset),
style::SetForegroundColor(Color::Blue),
style::Print(format!("🛠️ using tool: {}\n", tool.display_name())),
style::SetForegroundColor(Color::Reset)
)?;
queue!(self.output, style::Print(CONTINUATION_LINE))?;
queue!(self.output, style::Print("\n"))?;
queue!(self.output, style::Print(TOOL_BULLET))?;

tool.queue_description(&self.ctx, &mut self.output)
.await
.map_err(|e| ChatError::Custom(format!("failed to print tool: {}", e).into()))?;

queue!(self.output, style::Print("\n"))?;
queue!(self.output, style::Print(CONTINUATION_LINE))?;
}

Ok(())
}

Expand Down
18 changes: 10 additions & 8 deletions crates/q_cli/src/cli/chat/tools/fs_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,16 @@ impl FsDirectory {
break;
}
let relative_path = format_path(&cwd, &path);
queue!(
updates,
style::Print("Reading: "),
style::SetForegroundColor(Color::Green),
style::Print(&relative_path),
style::ResetColor,
style::Print("\n"),
)?;
if !relative_path.is_empty() {
queue!(
updates,
style::Print("Reading: "),
style::SetForegroundColor(Color::Green),
style::Print(&relative_path),
style::ResetColor,
style::Print("\n"),
)?;
}
let mut read_dir = ctx.fs().read_dir(path).await?;
while let Some(ent) = read_dir.next_entry().await? {
use std::os::unix::fs::MetadataExt;
Expand Down
22 changes: 5 additions & 17 deletions crates/q_cli/src/cli/chat/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,14 @@ impl Tool {
/// The display name of a tool
pub fn display_name(&self) -> &'static str {
match self {
Tool::FsRead(_) => "Read from filesystem",
Tool::FsWrite(_) => "Write to filesystem",
Tool::ExecuteBash(_) => "Execute shell command",
Tool::UseAws(_) => "Use AWS CLI",
Tool::GhIssue(_) => "Prepare GitHub issue",
Tool::FsRead(_) => "fs_read",
Tool::FsWrite(_) => "fs_write",
Tool::ExecuteBash(_) => "execute_bash",
Tool::UseAws(_) => "use_aws",
Tool::GhIssue(_) => "gh_issue",
}
}

// TODO: Remove, just roll with it for now ya?
pub fn display_name_action(&self) -> String {
match self {
Tool::FsRead(_) => "Reading from filesystem",
Tool::FsWrite(_) => "Writing to filesystem",
Tool::ExecuteBash(execute_bash) => return format!("Executing `{}`", execute_bash.command),
Tool::UseAws(_) => "Using AWS CLI",
Tool::GhIssue(_) => "Preparing GitHub issue",
}
.to_owned()
}

/// Whether or not the tool should prompt the user to accept before [Self::invoke] is called.
pub fn requires_acceptance(&self, _ctx: &Context) -> bool {
match self {
Expand Down
Loading