(
record: &Value,
meta: &CodexMeta,
model: Option<&str>,
path: &Path,
offset: i64,
)
| 711 | } |
| 712 | |
| 713 | fn goal_context_from_line( |
| 714 | record: &Value, |
| 715 | meta: &CodexMeta, |
| 716 | model: Option<&str>, |
| 717 | path: &Path, |
| 718 | offset: i64, |
| 719 | ) -> Option<SessionMessageRecord> { |
| 720 | if record.get("type").and_then(Value::as_str) != Some("response_item") { |
| 721 | return None; |
| 722 | } |
| 723 | let payload = record.get("payload")?; |
| 724 | if payload.get("type").and_then(Value::as_str) != Some("message") |
| 725 | || payload.get("role").and_then(Value::as_str) != Some("user") |
| 726 | { |
| 727 | return None; |
| 728 | } |
| 729 | let text = collect_response_item_text(payload.get("content").unwrap_or(payload)); |
| 730 | if !is_goal_context_text(&text) { |
| 731 | return None; |
| 732 | } |
| 733 | |
| 734 | let mut metadata = serde_json::Map::new(); |
| 735 | metadata.insert( |
| 736 | "source".to_string(), |
| 737 | Value::String("codex_goal_context".to_string()), |
| 738 | ); |
| 739 | metadata.insert( |
| 740 | "source_event".to_string(), |
| 741 | Value::String("response_item".to_string()), |
| 742 | ); |
| 743 | metadata.insert("source_offset".to_string(), Value::from(offset)); |
| 744 | |
| 745 | Some(SessionMessageRecord { |
| 746 | provider: PROVIDER.to_string(), |
| 747 | message_id: format!("{}:{offset}", meta.session_id), |
| 748 | session_id: meta.session_id.clone(), |
| 749 | role: "system".to_string(), |
| 750 | timestamp: timestamp_from_record(record), |
| 751 | ordinal: offset, |
| 752 | text, |
| 753 | kind: Some("context".to_string()), |
| 754 | model: model.map(str::to_string), |
| 755 | tool_names: None, |
| 756 | source_path: Some(path.to_string_lossy().to_string()), |
| 757 | source_offset: Some(offset), |
| 758 | metadata_json: serde_json::to_string(&Value::Object(metadata)).ok(), |
| 759 | }) |
| 760 | } |
| 761 | |
| 762 | fn is_goal_context_text(text: &str) -> bool { |
| 763 | let mut lines = text.lines().map(str::trim).filter(|line| !line.is_empty()); |
no test coverage detected