refactor: simplify context thinning status message
Change format from verbose emoji-based message to cleaner status line: Before: ✨ 🥒 Context thinned at 70%: 7 tool results, ~33839 chars saved ✨ After: g3: thinning context ... 70% -> 40% ... [done] The new format shows before/after percentages and uses bold green for 'g3:' and '[done]' to match other status messages. Also removes unused emoji() and label() methods from ThinScope.
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user