MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / save_reasoning_to_change

Function save_reasoning_to_change

atomic-cli/src/commands/agent/explain.rs:511–540  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.85

Calls 5

extract_unhashedFunction · 0.85
attach_unhashedFunction · 0.85
with_reasoningMethod · 0.80
cloneMethod · 0.45
save_changeMethod · 0.45

Tested by

no test coverage detected