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

Method index_session_turn

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

543 /// full BLAKE3 namespace only for local ordering; the serialized value
544 /// retains the original session ID so the index is self-describing.
545 pub fn index_session_turn(
546 &mut self,
547 session_id: &str,
548 json_path: &str,
549 provenance_hash: &Hash,
550 graph: &crate::change::ProvenanceGraph,
551 ) -> PristineResult<()> {
552 use crate::change::session::{SessionRecord, SessionTurn};
553
554 // Idempotency is session-local because forked sessions legitimately
555 // share provenance hashes.
556 let turns = self.load_session_turns_for_write(session_id)?;
557 if turns
558 .iter()
559 .any(|turn| turn.provenance_hash == *provenance_hash)
560 {
561 return Ok(());
562 }
563
564 let mut record = self
565 .load_session_record_for_write(session_id)?
566 .unwrap_or_else(|| SessionRecord {
567 session_id: session_id.to_string(),
568 json_path: json_path.to_string(),
569 view_name: None,
570 parent_view: None,
571 first_provenance: None,
572 latest_provenance: None,
573 turn_count: 0,
574 started_at: graph.timestamp,
575 ended_at: None,
576 });
577
578 if record.json_path.is_empty() {
579 record.json_path = json_path.to_string();
580 }
581
582 let candidate = SessionTurn {
583 session_id: session_id.to_string(),
584 // Canonical numbering is assigned from the complete turn set.
585 turn_number: 0,
586 goal: graph
587 .nodes
588 .iter()
589 .find(|node| {
590 matches!(
591 node.kind,
592 crate::change::provenance_graph::ProvenanceNodeKind::Goal
593 )
594 })
595 .map(|node| node.summary.clone()),
596 provenance_hash: *provenance_hash,
597 change_hashes: graph.changes_explained.clone(),
598 previous_provenance: graph.previous,
599 timestamp: graph.timestamp,
600 plan_id: graph.plan_id.clone(),
601 todos: graph.todos.clone(),
602 };

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