Save reasoning back into the change's unhashed section. Reads the existing unhashed data, adds the reasoning, and writes the change back to the store. The change hash is NOT affected (unhashed section doesn't contribute to the hash).
(
repo: &Repository,
hash: &atomic_core::types::Hash,
change: &atomic_core::change::Change,
reasoning: &TurnReasoning,
)
| 500 | /// the change back to the store. The change hash is NOT affected |
| 501 | /// (unhashed section doesn't contribute to the hash). |
| 502 | fn save_reasoning_to_change( |
| 503 | repo: &Repository, |
| 504 | hash: &atomic_core::types::Hash, |
| 505 | change: &atomic_core::change::Change, |
| 506 | reasoning: &TurnReasoning, |
| 507 | ) -> CliResult<()> { |
| 508 | let mut updated_change = change.clone(); |
| 509 | |
| 510 | // Get or create the unhashed data |
| 511 | let mut unhashed_data = extract_unhashed(&updated_change).unwrap_or_else(|| { |
| 512 | // Create minimal unhashed data if none exists |
| 513 | UnhashedTurnData::new("", 0, "unknown", Vec::new(), &[]) |
| 514 | }); |
| 515 | |
| 516 | // Set the reasoning |
| 517 | unhashed_data = unhashed_data.with_reasoning(reasoning.clone()); |
| 518 | |
| 519 | // Attach to the change |
| 520 | attach_unhashed(&mut updated_change, &unhashed_data) |
| 521 | .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to attach reasoning: {}", e)))?; |
| 522 | |
| 523 | // Save the change back to the store. |
| 524 | // The hash doesn't change because the unhashed section doesn't affect it, |
| 525 | // so this overwrites the same file at the same content-addressed path. |
| 526 | let _ = hash; // same hash — save_change recomputes and writes to the same path |
| 527 | repo.save_change(&updated_change) |
| 528 | .map_err(CliError::Repository)?; |
| 529 | |
| 530 | Ok(()) |
| 531 | } |
| 532 | |
| 533 | // Tests |
| 534 |
no test coverage detected