forked from kent/consciousness
agents/*.agent definitions and prompts/ now live under src/subconscious/ alongside the code that uses them. No more intermediate agents/ subdirectory. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
40 lines
1.5 KiB
Rust
40 lines
1.5 KiB
Rust
// 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<Vec<(usize, String, String, String)>, 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<Vec<(usize, String, String, String)>> {
|
|
let mut segments: Vec<Vec<(usize, String, String, String)>> = 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
|
|
}
|