Capture one durable turn boundary from a live repository handle. Observation only: nothing is interpreted, reconciled or materialized (RFC §12.1/§12.2 — reconciliation happens in repository command boundaries; the agent boundary observes). Fields the repository cannot compute yet stay `None` and are documented on `TurnBoundary`.
(
repo: &atomic_repository::Repository,
repo_root: &Path,
session_id: &str,
turn: u32,
)
| 128 | /// boundaries; the agent boundary observes). Fields the repository cannot |
| 129 | /// compute yet stay `None` and are documented on `TurnBoundary`. |
| 130 | pub fn capture_turn_boundary( |
| 131 | repo: &atomic_repository::Repository, |
| 132 | repo_root: &Path, |
| 133 | session_id: &str, |
| 134 | turn: u32, |
| 135 | ) -> Option<TurnBoundary> { |
| 136 | let working_copy = match repo.require_working_copy_id() { |
| 137 | Ok(working_copy) => working_copy.to_string(), |
| 138 | Err(error) => { |
| 139 | log::warn!( |
| 140 | "Boundary capture: cannot resolve working-copy identity: {}", |
| 141 | error |
| 142 | ); |
| 143 | return None; |
| 144 | } |
| 145 | }; |
| 146 | |
| 147 | let view = repo.current_view().to_string(); |
| 148 | let (view_state, set_id) = match repo.view_identity(&view) { |
| 149 | Ok(identity) => (Some(identity.merkle), Some(identity.set_id)), |
| 150 | Err(error) => { |
| 151 | // The view does not exist yet (e.g. a session view forked at |
| 152 | // first record) — record the boundary with unknown identity. |
| 153 | log::debug!( |
| 154 | "Boundary capture: view '{}' identity unavailable: {}", |
| 155 | view, |
| 156 | error |
| 157 | ); |
| 158 | (None, None) |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | let git = match atomic_repository::observe_git_metadata(repo_root) { |
| 163 | Ok(observation) => Some(git_checkpoint(&observation.token())), |
| 164 | Err(error) => { |
| 165 | log::warn!("Boundary capture: git observation failed: {}", error); |
| 166 | None |
| 167 | } |
| 168 | }; |
| 169 | |
| 170 | Some(TurnBoundary { |
| 171 | working_copy, |
| 172 | operation: (|| { |
| 173 | use atomic_core::pristine::OperationTxnT; |
| 174 | let id = repo.require_working_copy_id().ok()?; |
| 175 | let txn = repo.pristine().read_txn().ok()?; |
| 176 | let heads = txn |
| 177 | .get_operation_heads(atomic_core::operation::OperationScope::WorkingCopy(id)) |
| 178 | .ok()?; |
| 179 | match heads.as_slice() { |
| 180 | [head] => Some(head.to_string()), |
| 181 | _ => None, |
| 182 | } |
| 183 | })(), |
| 184 | view, |
| 185 | view_state, |
| 186 | set_id, |
| 187 | snapshot: None, |