codetether_rlm/context_trace/
summary_format.rs1use super::ContextTraceSummary;
2
3impl ContextTraceSummary {
4 pub fn format(&self) -> String {
6 let mut lines = self.header_lines();
7 self.push_event_lines(&mut lines);
8 lines.join("\n")
9 }
10
11 fn header_lines(&self) -> Vec<String> {
12 vec![
13 format!("Context Trace Summary (iteration {})", self.iteration),
14 format!(
15 " Budget: {}/{} tokens ({:.1}%)",
16 self.total_tokens, self.max_tokens, self.budget_used_percent
17 ),
18 format!(" Events: {}", self.events_len),
19 ]
20 }
21
22 fn push_event_lines(&self, lines: &mut Vec<String>) {
23 if self.event_counts.is_empty() {
24 return;
25 }
26 lines.push(" By type:".to_string());
27 for (label, count) in &self.event_counts {
28 let tokens = self.event_tokens.get(label).copied().unwrap_or(0);
29 lines.push(format!(" {label}: {count} events, {tokens} tokens"));
30 }
31 }
32}