diff --git a/crates/g3-cli/src/machine_ui_writer.rs b/crates/g3-cli/src/machine_ui_writer.rs index 19b894f..b9084cc 100644 --- a/crates/g3-cli/src/machine_ui_writer.rs +++ b/crates/g3-cli/src/machine_ui_writer.rs @@ -64,8 +64,10 @@ impl UiWriter for MachineUiWriter { println!("TOOL_OUTPUT_LINES: {}", count); } - fn print_tool_timing(&self, duration_str: &str) { + fn print_tool_timing(&self, duration_str: &str, tokens_delta: u32, context_percentage: f32) { println!("TOOL_DURATION: {}", duration_str); + println!("TOKENS_DELTA: {}", tokens_delta); + println!("CONTEXT_PERCENTAGE: {:.0}", context_percentage); println!("END_TOOL_OUTPUT"); println!(); } diff --git a/crates/g3-cli/src/ui_writer_impl.rs b/crates/g3-cli/src/ui_writer_impl.rs index 71e7d26..d7f6e2e 100644 --- a/crates/g3-cli/src/ui_writer_impl.rs +++ b/crates/g3-cli/src/ui_writer_impl.rs @@ -209,7 +209,7 @@ impl UiWriter for ConsoleUiWriter { ); } - fn print_tool_timing(&self, duration_str: &str) { + fn print_tool_timing(&self, duration_str: &str, tokens_delta: u32, context_percentage: f32) { // Parse the duration string to determine color // Format is like "1.5s", "500ms", "2m 30.0s" let color_code = if duration_str.ends_with("ms") { @@ -251,7 +251,7 @@ impl UiWriter for ConsoleUiWriter { "" }; - println!("└─ ⚡️ {}{}\x1b[0m", color_code, duration_str); + println!("└─ ⚡️ {}{}\x1b[0m \x1b[2m{}tk | {:.0}% ctx\x1b[0m", color_code, duration_str, tokens_delta, context_percentage); println!(); // Clear the stored tool info *self.current_tool_name.lock().unwrap() = None; diff --git a/crates/g3-core/src/lib.rs b/crates/g3-core/src/lib.rs index f5f1e4e..6ff44f1 100644 --- a/crates/g3-core/src/lib.rs +++ b/crates/g3-core/src/lib.rs @@ -4072,6 +4072,9 @@ impl Agent { } }; + // Track tokens before adding messages + let tokens_before = self.context_window.used_tokens; + self.context_window.add_message(tool_message); self.context_window.add_message(result_message); @@ -4107,8 +4110,11 @@ impl Agent { // Closure marker with timing if tool_call.tool != "final_output" { + let tokens_delta = self.context_window.used_tokens.saturating_sub(tokens_before); self.ui_writer - .print_tool_timing(&Self::format_duration(exec_duration)); + .print_tool_timing(&Self::format_duration(exec_duration), + tokens_delta, + self.context_window.percentage_used()); self.ui_writer.print_agent_prompt(); } diff --git a/crates/g3-core/src/ui_writer.rs b/crates/g3-core/src/ui_writer.rs index 0454c06..ea69375 100644 --- a/crates/g3-core/src/ui_writer.rs +++ b/crates/g3-core/src/ui_writer.rs @@ -39,7 +39,7 @@ pub trait UiWriter: Send + Sync { fn print_tool_output_summary(&self, hidden_count: usize); /// Print tool execution timing - fn print_tool_timing(&self, duration_str: &str); + fn print_tool_timing(&self, duration_str: &str, tokens_delta: u32, context_percentage: f32); /// Print the agent prompt indicator fn print_agent_prompt(&self); @@ -99,7 +99,7 @@ impl UiWriter for NullUiWriter { fn update_tool_output_line(&self, _line: &str) {} fn print_tool_output_line(&self, _line: &str) {} fn print_tool_output_summary(&self, _hidden_count: usize) {} - fn print_tool_timing(&self, _duration_str: &str) {} + fn print_tool_timing(&self, _duration_str: &str, _tokens_delta: u32, _context_percentage: f32) {} fn print_agent_prompt(&self) {} fn print_agent_response(&self, _content: &str) {} fn notify_sse_received(&self) {} diff --git a/crates/g3-core/tests/todo_staleness_test.rs b/crates/g3-core/tests/todo_staleness_test.rs index 51ef38a..d9e7785 100644 --- a/crates/g3-core/tests/todo_staleness_test.rs +++ b/crates/g3-core/tests/todo_staleness_test.rs @@ -59,7 +59,7 @@ impl UiWriter for MockUiWriter { fn update_tool_output_line(&self, _line: &str) {} fn print_tool_output_line(&self, _line: &str) {} fn print_tool_output_summary(&self, _hidden_count: usize) {} - fn print_tool_timing(&self, _duration_str: &str) {} + fn print_tool_timing(&self, _duration_str: &str, _tokens_delta: u32, _context_percentage: f32) {} fn print_agent_prompt(&self) {} fn print_agent_response(&self, _content: &str) {} fn notify_sse_received(&self) {} diff --git a/crates/g3-planner/src/llm.rs b/crates/g3-planner/src/llm.rs index 9eb610b..dfa0b4e 100644 --- a/crates/g3-planner/src/llm.rs +++ b/crates/g3-planner/src/llm.rs @@ -265,7 +265,7 @@ impl g3_core::ui_writer::UiWriter for PlannerUiWriter { fn update_tool_output_line(&self, _line: &str) {} fn print_tool_output_line(&self, _line: &str) {} fn print_tool_output_summary(&self, _hidden_count: usize) {} - fn print_tool_timing(&self, _duration_str: &str) {} + fn print_tool_timing(&self, _duration_str: &str, _tokens_delta: u32, _context_percentage: f32) {} fn print_agent_prompt(&self) { // No-op - don't add extra blank lines