// Conversation extraction from JSONL transcripts // // extract_conversation — parse JSONL transcript to messages // split_on_compaction — split messages at compaction boundaries /// Extract conversation messages from a JSONL transcript file. /// Returns (line_number, role, text, timestamp) tuples. pub fn extract_conversation(jsonl_path: &str) -> Result, String> { let path = std::path::Path::new(jsonl_path); let messages = super::transcript::parse_transcript(path)?; Ok(messages.into_iter() .map(|m| (m.line, m.role, m.text, m.timestamp)) .collect()) } pub const COMPACTION_MARKER: &str = "This session is being continued from a previous conversation that ran out of context"; /// Split extracted messages into segments at compaction boundaries. /// Each segment represents one continuous conversation before context was compacted. pub fn split_on_compaction(messages: Vec<(usize, String, String, String)>) -> Vec> { let mut segments: Vec> = Vec::new(); let mut current = Vec::new(); for msg in messages { if msg.1 == "user" && msg.2.starts_with(COMPACTION_MARKER) { if !current.is_empty() { segments.push(current); current = Vec::new(); } current.push(msg); } else { current.push(msg); } } if !current.is_empty() { segments.push(current); } segments }