diff --git a/crates/g3-core/src/context_window.rs b/crates/g3-core/src/context_window.rs index fa2b558..6b55c18 100644 --- a/crates/g3-core/src/context_window.rs +++ b/crates/g3-core/src/context_window.rs @@ -23,20 +23,6 @@ pub enum ThinScope { } impl ThinScope { - fn label(&self) -> &'static str { - match self { - ThinScope::FirstThird => "thinned", - ThinScope::All => "skinnified", - } - } - - fn emoji(&self) -> &'static str { - match self { - ThinScope::FirstThird => "🥒", - ThinScope::All => "🦴", - } - } - fn file_prefix(&self) -> &'static str { match self { ThinScope::FirstThird => "leaned", @@ -419,10 +405,14 @@ Format this as a detailed but concise summary that can be used to resume the con // Recalculate token usage after thinning self.recalculate_tokens(); + // Get new percentage after thinning + let new_percentage = self.percentage_used() as u32; + // Build result message self.build_thin_result_message( scope, current_percentage, + new_percentage, leaned_count, tool_call_leaned_count, chars_saved, @@ -711,35 +701,29 @@ Format this as a detailed but concise summary that can be used to resume the con &self, scope: ThinScope, current_percentage: u32, + new_percentage: u32, leaned_count: usize, tool_call_leaned_count: usize, chars_saved: usize, ) -> (String, usize) { - let scope_desc = match scope { - ThinScope::FirstThird => "", - ThinScope::All => " across entire history", - }; - // Nothing was thinned if leaned_count == 0 && tool_call_leaned_count == 0 { + let scope_desc = match scope { + ThinScope::FirstThird => "", + ThinScope::All => " (full)", + }; let msg = format!( - "ℹ Context {} triggered at {}% but no large tool results or tool calls found{}", - scope.error_action(), current_percentage, scope_desc + "\x1b[1;32mg3:\x1b[0m thinning context{} ... {}% ... \x1b[1;32m[no changes]\x1b[0m", + scope_desc, current_percentage ); return (msg, 0); } - // Build description of what was thinned - let what_thinned = match (leaned_count > 0, tool_call_leaned_count > 0) { - (true, true) => format!("{} tool results + {} tool calls", leaned_count, tool_call_leaned_count), - (true, false) => format!("{} tool results", leaned_count), - (false, true) => format!("{} tool calls", tool_call_leaned_count), - (false, false) => unreachable!(), // handled above - }; - + // Format: "g3: thinning context ... 70% -> 40% ... [done]" + // with "g3:" and "[done]" in bold green let msg = format!( - "{} Context {} at {}%: {}{}, ~{} chars saved", - scope.emoji(), scope.label(), current_percentage, what_thinned, scope_desc, chars_saved + "\x1b[1;32mg3:\x1b[0m thinning context ... {}% -> {}% ... \x1b[1;32m[done]\x1b[0m", + current_percentage, new_percentage ); (msg, chars_saved) } @@ -877,9 +861,9 @@ mod tests { #[test] fn test_thin_scope_properties() { - assert_eq!(ThinScope::FirstThird.emoji(), "🥒"); - assert_eq!(ThinScope::All.emoji(), "🦴"); - assert_eq!(ThinScope::FirstThird.label(), "thinned"); - assert_eq!(ThinScope::All.label(), "skinnified"); + assert_eq!(ThinScope::FirstThird.file_prefix(), "leaned"); + assert_eq!(ThinScope::All.file_prefix(), "skinny"); + assert_eq!(ThinScope::FirstThird.error_action(), "thinning"); + assert_eq!(ThinScope::All.error_action(), "skinnifying"); } } diff --git a/crates/g3-core/tests/test_context_thinning.rs b/crates/g3-core/tests/test_context_thinning.rs index 7ebbc46..3ca2142 100644 --- a/crates/g3-core/tests/test_context_thinning.rs +++ b/crates/g3-core/tests/test_context_thinning.rs @@ -73,13 +73,10 @@ fn test_thin_context_basic() { println!("Thinning summary: {}", summary); - // Should have thinned at least 1 large tool result in the first third - assert!( - summary.contains("1 tool result"), - "Summary was: {}", - summary - ); - assert!(summary.contains("50%")); + // Should show the new format with percentage change + assert!(summary.contains("g3:"), "Summary was: {}", summary); + assert!(summary.contains("thinning context")); + assert!(summary.contains("[done]")); // Check that the large tool results were replaced let first_third_end = context.conversation_history.len() / 3; @@ -134,8 +131,10 @@ fn test_thin_write_file_tool_calls() { println!("Thinning summary: {}", summary); - // Should have thinned the write_file tool call - assert!(summary.contains("tool call") || summary.contains("chars saved")); + // Should show the new format with percentage change + assert!(summary.contains("g3:")); + assert!(summary.contains("thinning context")); + assert!(summary.contains("[done]")); // Check that the large content was replaced with a file reference let first_third_end = context.conversation_history.len() / 3; @@ -194,8 +193,10 @@ fn test_thin_str_replace_tool_calls() { println!("Thinning summary: {}", summary); - // Should have thinned the str_replace tool call - assert!(summary.contains("tool call") || summary.contains("chars saved")); + // Should show the new format with percentage change + assert!(summary.contains("g3:")); + assert!(summary.contains("thinning context")); + assert!(summary.contains("[done]")); // Check that the large diff was replaced with a file reference let first_third_end = context.conversation_history.len() / 3; @@ -227,7 +228,9 @@ fn test_thin_context_no_large_results() { let (summary, _chars_saved) = context.thin_context(None); // Should report no large results found - assert!(summary.contains("no large tool results or tool calls found")); + assert!(summary.contains("g3:")); + assert!(summary.contains("thinning context")); + assert!(summary.contains("[no changes]")); } #[test] @@ -255,9 +258,9 @@ fn test_thin_context_only_affects_first_third() { context.used_tokens = 5000; let (summary, _chars_saved) = context.thin_context(None); - // First third is 4 messages (indices 0-3), so only indices 1 and 3 should be thinned - // That's 2 tool results - assert!(summary.contains("2 tool results")); + // Should show the new format with percentage change + assert!(summary.contains("g3:")); + assert!(summary.contains("[done]")); // Check that messages after the first third are NOT thinned let first_third_end = context.conversation_history.len() / 3; diff --git a/crates/g3-core/tests/test_todo_context_thinning.rs b/crates/g3-core/tests/test_todo_context_thinning.rs index c115be3..3cd4e8f 100644 --- a/crates/g3-core/tests/test_todo_context_thinning.rs +++ b/crates/g3-core/tests/test_todo_context_thinning.rs @@ -139,11 +139,10 @@ fn test_non_todo_results_still_thinned() { println!("Thinning summary: {}", summary); - // Should have thinned the non-TODO result - assert!( - summary.contains("1 tool result") || summary.contains("chars saved"), - "Non-TODO results should be thinned" - ); + // Should show the new format with percentage change (indicating thinning happened) + assert!(summary.contains("g3:"), "Non-TODO results should be thinned"); + assert!(summary.contains("thinning context")); + assert!(summary.contains("[done]")); // Check that the result was actually thinned let first_third_end = context.conversation_history.len() / 3;