Parse a synthesized OpenCode JSONL transcript into condensed entries. The line shape is produced by `crate::transcript::opencode` from OpenCode's SQLite store: `user`/`assistant` lines carry `text`, `tool` lines carry the tool name and an optional title. `reasoning` lines are skipped — reasoning is carried separately by the change provenance and the session graph's Decision nodes.
(raw: &[u8])
| 108 | /// skipped — reasoning is carried separately by the change provenance and |
| 109 | /// the session graph's Decision nodes. |
| 110 | pub fn condense_opencode_transcript(raw: &[u8]) -> Vec<CondensedEntry> { |
| 111 | let mut entries = Vec::new(); |
| 112 | |
| 113 | for line in raw.split(|&b| b == b'\n') { |
| 114 | if line.is_empty() { |
| 115 | continue; |
| 116 | } |
| 117 | let Ok(parsed) = serde_json::from_slice::<serde_json::Value>(line) else { |
| 118 | continue; |
| 119 | }; |
| 120 | |
| 121 | match parsed.get("type").and_then(|v| v.as_str()) { |
| 122 | Some("user") | Some("assistant") => { |
| 123 | let Some(text) = parsed.get("text").and_then(|v| v.as_str()) else { |
| 124 | continue; |
| 125 | }; |
| 126 | if text.trim().is_empty() { |
| 127 | continue; |
| 128 | } |
| 129 | if parsed["type"] == "user" { |
| 130 | entries.push(CondensedEntry::user(text)); |
| 131 | } else { |
| 132 | entries.push(CondensedEntry::assistant(text)); |
| 133 | } |
| 134 | } |
| 135 | Some("tool") => { |
| 136 | let name = parsed |
| 137 | .get("tool") |
| 138 | .and_then(|v| v.as_str()) |
| 139 | .unwrap_or("tool"); |
| 140 | let title = parsed |
| 141 | .get("title") |
| 142 | .and_then(|v| v.as_str()) |
| 143 | .map(|s| s.to_string()); |
| 144 | entries.push(CondensedEntry::tool(name, title)); |
| 145 | } |
| 146 | _ => {} |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | entries |
| 151 | } |
| 152 | |
| 153 | /// Extract the agent's final response text from a transcript. |
| 154 | /// |