Every stored capture for one turn, oldest first (legacy single file first, then per-attempt files in attempt order).
(sessions_dir: &Path, session_id: &str, turn: u32)
| 102 | /// Every stored capture for one turn, oldest first (legacy single file |
| 103 | /// first, then per-attempt files in attempt order). |
| 104 | fn capture_files(sessions_dir: &Path, session_id: &str, turn: u32) -> AgentResult<Vec<PathBuf>> { |
| 105 | let mut files = Vec::new(); |
| 106 | let legacy = capture_path(sessions_dir, session_id, turn)?; |
| 107 | if legacy.exists() { |
| 108 | files.push(legacy); |
| 109 | } |
| 110 | let prefix = format!("turn-{turn}.attempt-"); |
| 111 | if let Ok(entries) = std::fs::read_dir(capture_dir(sessions_dir, session_id)?) { |
| 112 | let mut attempts: Vec<(u32, PathBuf)> = entries |
| 113 | .flatten() |
| 114 | .filter_map(|entry| { |
| 115 | let name = entry.file_name().to_string_lossy().to_string(); |
| 116 | let rest = name |
| 117 | .strip_prefix(&prefix)? |
| 118 | .strip_suffix(".json")? |
| 119 | .to_string(); |
| 120 | rest.parse::<u32>() |
| 121 | .ok() |
| 122 | .map(|attempt| (attempt, entry.path())) |
| 123 | }) |
| 124 | .collect(); |
| 125 | attempts.sort_by_key(|(attempt, _)| *attempt); |
| 126 | files.extend(attempts.into_iter().map(|(_, path)| path)); |
| 127 | } |
| 128 | Ok(files) |
| 129 | } |
| 130 | |
| 131 | /// The most recent capture file for one turn (the latest commit attempt), |
| 132 | /// when any exists. |