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

Method save_provenance_graph

atomic-repository/src/repository/changes.rs:1060–1136  ·  view source on GitHub ↗

Save a provenance graph to the repository. Serializes the graph to disk, registers it in the pristine database with `node_type::PROVENANCE`, and records dependencies on the changes this graph explains. # Returns The content hash of the saved provenance graph.

(
        &self,
        graph: &atomic_core::change::ProvenanceGraph,
    )

Source from the content-addressed store, hash-verified

1058 ///
1059 /// The content hash of the saved provenance graph.
1060 pub fn save_provenance_graph(
1061 &self,
1062 graph: &atomic_core::change::ProvenanceGraph,
1063 ) -> Result<Hash, RepositoryError> {
1064 use atomic_core::pristine::MutTxnT;
1065
1066 // Save to disk
1067 let hash = self
1068 .change_store
1069 .save_provenance_graph(graph)
1070 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1071
1072 // Register in the graph
1073 let mut txn = self
1074 .pristine
1075 .write_txn()
1076 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1077
1078 let prov_id = txn
1079 .register_provenance(&hash)
1080 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1081
1082 // Register dependencies: provenance → explained changes. Sidecars can
1083 // arrive with `--download-only`, before their changes are inserted into
1084 // a view. Registering the content hash now gives the relationship a
1085 // stable internal ID; insertion reuses that registration later.
1086 for change_hash in &graph.changes_explained {
1087 let change_id = txn
1088 .register_change(change_hash)
1089 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1090 txn.put_dep(prov_id, change_id)
1091 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1092 }
1093
1094 // If chained, register dependency on previous provenance graph too
1095 if let Some(ref prev_hash) = graph.previous {
1096 if let Ok(Some(prev_id)) = txn.get_internal(prev_hash) {
1097 txn.put_dep(prov_id, prev_id)
1098 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1099 }
1100 }
1101
1102 // Populate session tables from the provenance graph, for any agent
1103 // (Sherpa, Claude Code, OpenCode, generic atomic-agent, ...). The
1104 // write transaction is still open, so this is atomic with the
1105 // provenance registration above.
1106 txn.populate_session_tables(prov_id.get(), graph)
1107 .map_err(|e| RepositoryError::Database(e.to_string()))?;
1108
1109 // Maintain the Atomic-native session ledger alongside the provenance
1110 // registration. The JSON file is a mutable runtime cache; this index
1111 // connects the external session identity to immutable turn objects.
1112 let json_path = self
1113 .dot_dir
1114 .join("sessions")
1115 .join(format!("{}.json", graph.session_id))
1116 .to_string_lossy()
1117 .to_string();

Calls 10

write_txnMethod · 0.80
register_provenanceMethod · 0.80
register_changeMethod · 0.80
put_depMethod · 0.80
index_session_turnMethod · 0.80
commitMethod · 0.80
getMethod · 0.65
get_internalMethod · 0.45