From 55fc42d801b9f8cfec32ce637ffc93cad22b5518 Mon Sep 17 00:00:00 2001 From: Jack Amadeo Date: Thu, 31 Jul 2025 20:48:34 -0400 Subject: [PATCH] fix: cli tool logging (#3749) --- crates/goose-cli/src/session/mod.rs | 28 ++++++++++---------------- crates/goose-cli/src/session/output.rs | 9 ++++++++- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/crates/goose-cli/src/session/mod.rs b/crates/goose-cli/src/session/mod.rs index 94b655d2..61579085 100644 --- a/crates/goose-cli/src/session/mod.rs +++ b/crates/goose-cli/src/session/mod.rs @@ -1040,23 +1040,21 @@ impl Session { if let Some(Value::String(msg)) = o.get("message") { // Extract subagent info for better display let subagent_id = o.get("subagent_id") - .and_then(|v| v.as_str()) - .unwrap_or("unknown"); + .and_then(|v| v.as_str()); let notification_type = o.get("type") - .and_then(|v| v.as_str()) - .unwrap_or(""); + .and_then(|v| v.as_str()); let formatted = match notification_type { - "subagent_created" | "completed" | "terminated" => { + Some("subagent_created") | Some("completed") | Some("terminated") => { format!("🤖 {}", msg) } - "tool_usage" | "tool_completed" | "tool_error" => { + Some("tool_usage") | Some("tool_completed") | Some("tool_error") => { format!("🔧 {}", msg) } - "message_processing" | "turn_progress" => { + Some("message_processing") | Some("turn_progress") => { format!("💭 {}", msg) } - "response_generated" => { + Some("response_generated") => { // Check verbosity setting for subagent response content let config = Config::global(); let min_priority = config @@ -1080,7 +1078,7 @@ impl Session { msg.to_string() } }; - (formatted, Some(subagent_id.to_string()), Some(notification_type.to_string())) + (formatted, subagent_id.map(str::to_string), notification_type.map(str::to_string)) } else if let Some(Value::String(output)) = o.get("output") { // Fallback for other MCP notification types (output.to_owned(), None, None) @@ -1116,14 +1114,10 @@ impl Session { } } } - else { - // Non-subagent notification, display immediately with compact spacing - if interactive { - let _ = progress_bars.hide(); - println!("{}", console::style(&formatted_message).green().dim()); - } else { - progress_bars.log(&formatted_message); - } + else if output::is_showing_thinking() { + output::set_thinking_message(&formatted_message); + } else { + progress_bars.log(&formatted_message); } }, ServerNotification::ProgressNotification(notification) => { diff --git a/crates/goose-cli/src/session/output.rs b/crates/goose-cli/src/session/output.rs index 3b0420a3..9aa97f68 100644 --- a/crates/goose-cli/src/session/output.rs +++ b/crates/goose-cli/src/session/output.rs @@ -115,6 +115,10 @@ impl ThinkingIndicator { spinner.stop(""); } } + + pub fn is_shown(&self) -> bool { + self.spinner.is_some() + } } #[derive(Debug, Clone)] @@ -138,7 +142,10 @@ pub fn hide_thinking() { THINKING.with(|t| t.borrow_mut().hide()); } -#[allow(dead_code)] +pub fn is_showing_thinking() -> bool { + THINKING.with(|t| t.borrow().is_shown()) +} + pub fn set_thinking_message(s: &String) { THINKING.with(|t| { if let Some(spinner) = t.borrow_mut().spinner.as_mut() {