Make dehydration stub more compact

Change from multi-line verbose format to single-line compact format:

Before:
   DEHYDRATED CONTEXT (fragment_id: 188c7ac71613)
     • 8 messages (4 user, 4 assistant)
     • 3 tool calls (shell ×3)
     • ~299 tokens saved

     To restore this history, call: rehydrate(fragment_id: "188c7ac71613")

After:
   DEHYDRATED CONTEXT: 3 tool calls (shell x3), 8 total msgs. To restore, call: rehydrate(fragment_id: "188c7ac71613")

- Combine all info into single line
- Remove tokens saved (not essential for rehydration decision)
- Use ASCII 'x' instead of '×' for simplicity
- Add 'no tool calls' case for fragments without tools
- Update related tests
This commit is contained in:
Dhanji R. Prasanna
2026-01-20 21:26:42 +05:30
parent 4321503e89
commit 9a0a2a2726
2 changed files with 14 additions and 28 deletions

View File

@@ -116,37 +116,24 @@ impl Fragment {
stub.push_str(&format!("📋 Task: {}\n\n", task)); stub.push_str(&format!("📋 Task: {}\n\n", task));
} }
stub.push_str(&format!(
"⚡ DEHYDRATED CONTEXT (fragment_id: {})\n",
self.fragment_id
));
stub.push_str(&format!(
"{} messages ({} user, {} assistant)\n",
self.message_count, self.user_message_count, self.assistant_message_count
));
// Tool call summary // Tool call summary
if !self.tool_call_summary.is_empty() { let tool_part = if !self.tool_call_summary.is_empty() {
let total_calls: usize = self.tool_call_summary.values().sum(); let total_calls: usize = self.tool_call_summary.values().sum();
let tool_details: Vec<String> = self let tool_details: Vec<String> = self
.tool_call_summary .tool_call_summary
.iter() .iter()
.map(|(tool, count)| format!("{} ×{}", tool, count)) .map(|(tool, count)| format!("{} x{}", tool, count))
.collect(); .collect();
stub.push_str(&format!( format!("{} tool calls ({})", total_calls, tool_details.join(", "))
"{} tool calls ({})\n", } else {
total_calls, "no tool calls".to_string()
tool_details.join(", ") };
));
}
stub.push_str(&format!(" • ~{} tokens saved\n", self.estimated_tokens));
stub.push_str("\n");
stub.push_str(&format!( stub.push_str(&format!(
" To restore this history, call: rehydrate(fragment_id: \"{}\")\n", "⚡ DEHYDRATED CONTEXT: {}, {} total msgs. To restore, call: rehydrate(fragment_id: \"{}\")\n",
self.fragment_id tool_part, self.message_count, self.fragment_id
)); ));
stub.push_str("---"); stub.push_str("---");
stub stub
@@ -488,9 +475,8 @@ mod tests {
assert!(stub.contains("DEHYDRATED CONTEXT")); assert!(stub.contains("DEHYDRATED CONTEXT"));
assert!(stub.contains(&fragment.fragment_id)); assert!(stub.contains(&fragment.fragment_id));
assert!(stub.contains("2 messages")); assert!(stub.contains("2 total msgs"));
assert!(stub.contains("1 user")); assert!(stub.contains("1 tool calls"));
assert!(stub.contains("1 assistant"));
assert!(stub.contains("rehydrate")); assert!(stub.contains("rehydrate"));
} }
@@ -613,8 +599,8 @@ mod tests {
let fragment = Fragment::new(messages, None); let fragment = Fragment::new(messages, None);
let stub = fragment.generate_stub(); let stub = fragment.generate_stub();
// Should not have tool call line // Should have "no tool calls" in the compact format
assert!(!stub.contains("tool calls")); assert!(stub.contains("no tool calls"));
} }
#[test] #[test]

View File

@@ -221,7 +221,7 @@ fn test_large_fragment() {
// Stub should still be concise // Stub should still be concise
let stub = fragment.generate_stub(); let stub = fragment.generate_stub();
assert!(stub.len() < 1000, "Stub should be concise even for large fragments"); assert!(stub.len() < 1000, "Stub should be concise even for large fragments");
assert!(stub.contains("200 messages")); assert!(stub.contains("200 total msgs"));
} }
/// Test fragment with tool calls /// Test fragment with tool calls