Add tokens consumed and context percentage to per-tool timing footer

The per-tool timing line now shows:
- Tokens delta (tokens added to context by this tool call)
- Context window usage percentage

Example: └─ ️ 1ms  523tk | 49% ctx

Changes:
- Updated UiWriter trait print_tool_timing signature
- Track tokens before/after adding tool messages to calculate delta
- Updated ConsoleUiWriter, MachineUiWriter, PlannerUiWriter, and test mocks
This commit is contained in:
Dhanji R. Prasanna
2025-12-24 15:44:19 +11:00
parent fd22ce9890
commit cd64ebbf87
6 changed files with 16 additions and 8 deletions

View File

@@ -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!();
}

View File

@@ -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;