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

Method index_session_turn

atomic-core/src/pristine/txn/write/mod.rs:640–700  ·  view source on GitHub ↗

Index an immutable provenance graph as the next turn of its session. The session ID is the portable external identity. The turn key uses the full BLAKE3 namespace only for local ordering; the serialized value retains the original session ID so the index is self-describing.

(
        &mut self,
        session_id: &str,
        json_path: &str,
        provenance_hash: &Hash,
        graph: &crate::change::ProvenanceGraph,
    )

Source from the content-addressed store, hash-verified

638 /// full BLAKE3 namespace only for local ordering; the serialized value
639 /// retains the original session ID so the index is self-describing.
640 pub fn index_session_turn(
641 &mut self,
642 session_id: &str,
643 json_path: &str,
644 provenance_hash: &Hash,
645 graph: &crate::change::ProvenanceGraph,
646 ) -> PristineResult<()> {
647 use crate::change::session::{SessionRecord, SessionTurn};
648
649 // Idempotency is session-local because forked sessions legitimately
650 // share provenance hashes.
651 let turns = self.load_session_turns_for_write(session_id)?;
652 if turns
653 .iter()
654 .any(|turn| turn.provenance_hash == *provenance_hash)
655 {
656 return Ok(());
657 }
658
659 let mut record = self
660 .load_session_record_for_write(session_id)?
661 .unwrap_or_else(|| SessionRecord {
662 session_id: session_id.to_string(),
663 json_path: json_path.to_string(),
664 view_name: None,
665 parent_view: None,
666 first_provenance: None,
667 latest_provenance: None,
668 turn_count: 0,
669 started_at: graph.timestamp,
670 ended_at: None,
671 });
672
673 if record.json_path.is_empty() {
674 record.json_path = json_path.to_string();
675 }
676
677 let candidate = SessionTurn {
678 session_id: session_id.to_string(),
679 // Canonical numbering is assigned from the complete turn set.
680 turn_number: 0,
681 goal: graph
682 .nodes
683 .iter()
684 .find(|node| {
685 matches!(
686 node.kind,
687 crate::change::provenance_graph::ProvenanceNodeKind::Goal
688 )
689 })
690 .map(|node| node.summary.clone()),
691 provenance_hash: *provenance_hash,
692 change_hashes: graph.changes_explained.clone(),
693 previous_provenance: graph.previous,
694 timestamp: graph.timestamp,
695 plan_id: graph.plan_id.clone(),
696 todos: graph.todos.clone(),
697 };

Callers 2

rebuild_session_indexMethod · 0.80
save_provenance_graphMethod · 0.80

Calls 6

iterMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected