Aggregate tool usage from condensed entries.
(entries: &[CondensedEntry])
| 231 | |
| 232 | /// Aggregate tool usage from condensed entries. |
| 233 | pub fn aggregate_tool_usage(entries: &[CondensedEntry]) -> Vec<ToolUseSummary> { |
| 234 | let mut tools: HashMap<String, ToolUseSummary> = HashMap::new(); |
| 235 | |
| 236 | for entry in entries.iter().filter(|e| e.is_tool()) { |
| 237 | let name = entry.tool_name.as_deref().unwrap_or("Unknown"); |
| 238 | |
| 239 | let summary = tools |
| 240 | .entry(name.to_string()) |
| 241 | .or_insert_with(|| ToolUseSummary::new(name, 0, Vec::new())); |
| 242 | |
| 243 | summary.invocation_count += 1; |
| 244 | |
| 245 | // Track files affected by file-modifying tools |
| 246 | if let Some(detail) = &entry.tool_detail { |
| 247 | if matches!(name, "Edit" | "Write" | "MultiEdit" | "NotebookEdit") |
| 248 | && !summary.files_affected.contains(detail) |
| 249 | { |
| 250 | summary.files_affected.push(detail.clone()); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | let mut result: Vec<_> = tools.into_values().collect(); |
| 256 | result.sort_by(|a, b| a.tool_name.cmp(&b.tool_name)); |
| 257 | result |
| 258 | } |
| 259 | |
| 260 | /// Extract user content from a transcript message value. |
| 261 | fn extract_user_content(message: &serde_json::Value) -> Option<String> { |