| 1566 | } |
| 1567 | |
| 1568 | fn loggable_evidence( |
| 1569 | mut fields: serde_json::Map<String, serde_json::Value>, |
| 1570 | ) -> serde_json::Map<String, serde_json::Value> { |
| 1571 | for repeated in ["interpretation", "version", "worktree_root"] { |
| 1572 | fields.remove(repeated); |
| 1573 | } |
| 1574 | if fields.remove("capture_token").is_some() { |
| 1575 | fields.insert("capture_token_present".into(), true.into()); |
| 1576 | } |
| 1577 | let long_lists: Vec<(String, usize)> = fields |
| 1578 | .iter() |
| 1579 | .filter_map(|(name, value)| value.as_array().map(|items| (name.clone(), items.len()))) |
| 1580 | .filter(|(_, len)| *len > LOGGED_EVIDENCE_ITEMS) |
| 1581 | .collect(); |
| 1582 | for (name, len) in long_lists { |
| 1583 | if let Some(serde_json::Value::Array(items)) = fields.get_mut(&name) { |
| 1584 | items.truncate(LOGGED_EVIDENCE_ITEMS); |
| 1585 | } |
| 1586 | fields.insert(format!("{name}_total"), len.into()); |
| 1587 | } |
| 1588 | fields |
| 1589 | } |
| 1590 | |
| 1591 | fn write_immutable_json<T: Serialize>(path: &Path, value: &T) -> CliResult<()> { |
| 1592 | let mut bytes = serde_json::to_vec(value) |