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

Method index_session_turn

atomic-core/src/pristine/txn/write/mod.rs:740–804  ·  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

738 /// full BLAKE3 namespace only for local ordering; the serialized value
739 /// retains the original session ID so the index is self-describing.
740 pub fn index_session_turn(
741 &mut self,
742 session_id: &str,
743 json_path: &str,
744 provenance_hash: &Hash,
745 graph: &crate::change::ProvenanceGraph,
746 ) -> PristineResult<()> {
747 use crate::change::session::{SessionRecord, SessionTurn};
748
749 // Idempotency is session-local because forked sessions legitimately
750 // share provenance hashes.
751 let turns = self.load_session_turns_for_write(session_id)?;
752 if turns
753 .iter()
754 .any(|turn| turn.provenance_hash == *provenance_hash)
755 {
756 return Ok(());
757 }
758
759 let mut record = self
760 .load_session_record_for_write(session_id)?
761 .unwrap_or_else(|| SessionRecord {
762 session_id: session_id.to_string(),
763 json_path: json_path.to_string(),
764 view_name: None,
765 parent_view: None,
766 first_provenance: None,
767 latest_provenance: None,
768 turn_count: 0,
769 started_at: graph.timestamp,
770 ended_at: None,
771 status: crate::change::session::SessionStatus::Active,
772 });
773
774 if record.json_path.is_empty() {
775 record.json_path = json_path.to_string();
776 }
777
778 let candidate = SessionTurn {
779 session_id: session_id.to_string(),
780 // Canonical numbering is assigned from the complete turn set.
781 turn_number: 0,
782 goal: graph
783 .nodes
784 .iter()
785 .find(|node| {
786 matches!(
787 node.kind,
788 crate::change::provenance_graph::ProvenanceNodeKind::Goal
789 )
790 })
791 .map(|node| node.summary.clone()),
792 provenance_hash: *provenance_hash,
793 change_hashes: graph.changes_explained.clone(),
794 previous_provenance: graph.previous,
795 timestamp: graph.timestamp,
796 plan_id: graph.plan_id.clone(),
797 todos: graph.todos.clone(),

Calls 6

iterMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45