Reads the session `cwd` from an early line of a Claude transcript.
(path: &Path)
| 182 | |
| 183 | /// Reads the session `cwd` from an early line of a Claude transcript. |
| 184 | pub(crate) fn transcript_cwd(path: &Path) -> Option<PathBuf> { |
| 185 | use std::io::BufRead; |
| 186 | let file = std::fs::File::open(path).ok()?; |
| 187 | let reader = std::io::BufReader::new(file); |
| 188 | for line in reader.lines().take(CWD_PROBE_LINES).map_while(Result::ok) { |
| 189 | let trimmed = line.trim(); |
| 190 | if trimmed.is_empty() { |
| 191 | continue; |
| 192 | } |
| 193 | if let Ok(value) = serde_json::from_str::<Value>(trimmed) { |
| 194 | if let Some(cwd) = value.get("cwd").and_then(Value::as_str) { |
| 195 | if !cwd.is_empty() { |
| 196 | return Some(PathBuf::from(cwd)); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | None |
| 202 | } |
| 203 | |
| 204 | /// Map one Claude transcript line to a provider-neutral message, or `None` for |
| 205 | /// lines that carry no conversational text (tool-result-only, meta lines, …). |