(
record: &Value,
meta: &CodexMeta,
model: Option<&str>,
path: &Path,
offset: i64,
depth: i64,
)
| 505 | } |
| 506 | |
| 507 | fn compacted_summary_from_line( |
| 508 | record: &Value, |
| 509 | meta: &CodexMeta, |
| 510 | model: Option<&str>, |
| 511 | path: &Path, |
| 512 | offset: i64, |
| 513 | depth: i64, |
| 514 | ) -> Option<SessionMessageRecord> { |
| 515 | if record.get("type").and_then(Value::as_str) != Some("compacted") { |
| 516 | return None; |
| 517 | } |
| 518 | let payload = record.get("payload")?; |
| 519 | let replacement_history_count = payload |
| 520 | .get("replacement_history") |
| 521 | .and_then(Value::as_array) |
| 522 | .map_or(0, Vec::len); |
| 523 | let compaction = payload |
| 524 | .get("replacement_history") |
| 525 | .and_then(Value::as_array) |
| 526 | .and_then(|history| { |
| 527 | history |
| 528 | .iter() |
| 529 | .rev() |
| 530 | .find(|entry| entry.get("type").and_then(Value::as_str) == Some("compaction")) |
| 531 | }); |
| 532 | let plaintext = payload |
| 533 | .get("message") |
| 534 | .and_then(Value::as_str) |
| 535 | .map(str::trim) |
| 536 | .filter(|message| !message.is_empty()); |
| 537 | let encrypted = compaction |
| 538 | .and_then(|entry| entry.get("encrypted_content")) |
| 539 | .and_then(Value::as_str) |
| 540 | .is_some_and(|content| !content.is_empty()); |
| 541 | let summary_body = if plaintext.is_some() { |
| 542 | "plaintext" |
| 543 | } else if encrypted { |
| 544 | "encrypted" |
| 545 | } else { |
| 546 | "unavailable" |
| 547 | }; |
| 548 | let timestamp_text = record |
| 549 | .get("timestamp") |
| 550 | .and_then(Value::as_str) |
| 551 | .unwrap_or("unknown time"); |
| 552 | let text = plaintext.map_or_else( |
| 553 | || { |
| 554 | format!( |
| 555 | "Codex context compaction at {timestamp_text}. Summary body is {summary_body} in the rollout; replacement history entries: {replacement_history_count}." |
| 556 | ) |
| 557 | }, |
| 558 | str::to_string, |
| 559 | ); |
| 560 | |
| 561 | let mut metadata = serde_json::Map::new(); |
| 562 | metadata.insert( |
| 563 | "source".to_string(), |
| 564 | Value::String("codex_context_compacted".to_string()), |
no test coverage detected