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

View File

@@ -221,7 +221,7 @@ fn test_large_fragment() {
// Stub should still be concise
let stub = fragment.generate_stub();
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