Stream scout agent output to CLI during research

The research tool now streams the underlying scout agent's output
to the CLI in real-time for visual indication of progress. This
output is displayed but not added to the conversation context.
This commit is contained in:
Dhanji R. Prasanna
2026-01-09 20:39:53 +11:00
parent 91239ae2ca
commit cab2fb187a

View File

@@ -4,7 +4,6 @@ use anyhow::Result;
use std::process::Stdio; use std::process::Stdio;
use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::process::Command; use tokio::process::Command;
use tracing::debug;
use crate::ui_writer::UiWriter; use crate::ui_writer::UiWriter;
use crate::ToolCall; use crate::ToolCall;
@@ -27,7 +26,6 @@ pub async fn execute_research<W: UiWriter>(
.and_then(|v| v.as_str()) .and_then(|v| v.as_str())
.ok_or_else(|| anyhow::anyhow!("Missing required 'query' parameter"))?; .ok_or_else(|| anyhow::anyhow!("Missing required 'query' parameter"))?;
debug!("Research tool called with query: {}", query);
ctx.ui_writer.print_tool_header("research", None); ctx.ui_writer.print_tool_header("research", None);
ctx.ui_writer.print_tool_arg("query", query); ctx.ui_writer.print_tool_arg("query", query);
@@ -55,9 +53,12 @@ pub async fn execute_research<W: UiWriter>(
let mut reader = BufReader::new(stdout).lines(); let mut reader = BufReader::new(stdout).lines();
let mut last_line = String::new(); let mut last_line = String::new();
// Read all lines, keeping track of the last one // Print a header for the scout output
ctx.ui_writer.println("\n📡 Scout agent output:");
// Stream all lines to UI, keeping track of the last one for the report path
while let Some(line) = reader.next_line().await? { while let Some(line) = reader.next_line().await? {
debug!("Scout output: {}", line); ctx.ui_writer.println(&format!(" {}", line));
last_line = line; last_line = line;
} }
@@ -76,8 +77,6 @@ pub async fn execute_research<W: UiWriter>(
return Ok("❌ Scout agent did not output a report file path".to_string()); return Ok("❌ Scout agent did not output a report file path".to_string());
} }
debug!("Report file path: {}", report_path);
// Expand tilde if present // Expand tilde if present
let expanded_path = if report_path.starts_with('~') { let expanded_path = if report_path.starts_with('~') {
if let Ok(home) = std::env::var("HOME") { if let Ok(home) = std::env::var("HOME") {
@@ -92,7 +91,6 @@ pub async fn execute_research<W: UiWriter>(
// Read the report file // Read the report file
match std::fs::read_to_string(&expanded_path) { match std::fs::read_to_string(&expanded_path) {
Ok(content) => { Ok(content) => {
debug!("Report loaded: {} chars", content.len());
Ok(format!("📋 Research Report:\n\n{}", content)) Ok(format!("📋 Research Report:\n\n{}", content))
} }
Err(e) => { Err(e) => {