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:502–531  ·  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

500/// the change back to the store. The change hash is NOT affected
501/// (unhashed section doesn't contribute to the hash).
502fn 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

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