diff --git a/crates/goose-cli/src/session/output.rs b/crates/goose-cli/src/session/output.rs index 6e410ab5..f8792c81 100644 --- a/crates/goose-cli/src/session/output.rs +++ b/crates/goose-cli/src/session/output.rs @@ -621,12 +621,19 @@ pub fn display_greeting() { pub fn display_context_usage(total_tokens: usize, context_limit: usize) { use console::style; - // Calculate percentage used - let percentage = (total_tokens as f64 / context_limit as f64 * 100.0).round() as usize; + if context_limit == 0 { + println!("Context: Error - context limit is zero"); + return; + } - // Create dot visualization + // Calculate percentage used with bounds checking + let percentage = + (((total_tokens as f64 / context_limit as f64) * 100.0).round() as usize).min(100); + + // Create dot visualization with safety bounds let dot_count = 10; - let filled_dots = ((percentage as f64 / 100.0) * dot_count as f64).round() as usize; + let filled_dots = + (((percentage as f64 / 100.0) * dot_count as f64).round() as usize).min(dot_count); let empty_dots = dot_count - filled_dots; let filled = "●".repeat(filled_dots); diff --git a/ui/desktop/openapi.json b/ui/desktop/openapi.json index 7ad0e79d..ffd9dca2 100644 --- a/ui/desktop/openapi.json +++ b/ui/desktop/openapi.json @@ -10,7 +10,7 @@ "license": { "name": "Apache-2.0" }, - "version": "1.0.26" + "version": "1.0.27" }, "paths": { "/agent/tools": {