Build the unhashed turn data (transcript + reasoning) from the agent's transcript file and the recorded change's FileOps. Returns `None` if the transcript is not available, empty, or unparseable. Reasoning generation failure is logged and skipped (non-fatal).
(
options: &TurnRecordOptions<'_>,
recorded_files: &[String],
_outcome: &atomic_repository::record::RecordOutcome,
)
| 259 | /// Returns `None` if the transcript is not available, empty, or unparseable. |
| 260 | /// Reasoning generation failure is logged and skipped (non-fatal). |
| 261 | pub(crate) fn build_unhashed_turn_data( |
| 262 | options: &TurnRecordOptions<'_>, |
| 263 | recorded_files: &[String], |
| 264 | _outcome: &atomic_repository::record::RecordOutcome, |
| 265 | ) -> Option<transcript::UnhashedTurnData> { |
| 266 | // Check if we have a transcript file |
| 267 | let transcript_path = options.session.transcript_path.as_ref()?; |
| 268 | if !transcript_path.exists() { |
| 269 | log::debug!( |
| 270 | "Transcript file not found at {} — skipping", |
| 271 | transcript_path.display(), |
| 272 | ); |
| 273 | return None; |
| 274 | } |
| 275 | |
| 276 | // Read raw transcript |
| 277 | let raw = match std::fs::read(transcript_path) { |
| 278 | Ok(data) => data, |
| 279 | Err(e) => { |
| 280 | log::warn!( |
| 281 | "Failed to read transcript at {}: {}", |
| 282 | transcript_path.display(), |
| 283 | e |
| 284 | ); |
| 285 | return None; |
| 286 | } |
| 287 | }; |
| 288 | |
| 289 | if raw.is_empty() { |
| 290 | return None; |
| 291 | } |
| 292 | |
| 293 | // Determine format from agent name |
| 294 | let format = transcript::format_for_agent(&options.session.agent_name); |
| 295 | |
| 296 | // Condense into structured entries |
| 297 | let entries = transcript::condense_transcript(&raw, format); |
| 298 | if entries.is_empty() { |
| 299 | log::debug!("Condensed transcript is empty — skipping"); |
| 300 | return None; |
| 301 | } |
| 302 | |
| 303 | // Build the base unhashed data |
| 304 | let data = transcript::UnhashedTurnData::new( |
| 305 | &options.session.session_id, |
| 306 | options.turn_number, |
| 307 | format, |
| 308 | entries, |
| 309 | recorded_files, |
| 310 | ); |
| 311 | |
| 312 | // Reasoning generation is NOT done here — it's too slow for the hook |
| 313 | // hot path (calls Claude CLI, 30+ seconds) and potentially recursive |
| 314 | // when running inside a Claude Code hook. |
| 315 | // |
| 316 | // Use `atomic agent explain` to generate reasoning on demand after |
| 317 | // the turn is recorded. That command reads the change's unhashed |
| 318 | // transcript, calls Claude CLI, anchors learnings to the CRDT graph, |
no test coverage detected