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

Method load_or_create

atomic-agent/src/provenance/accumulator/mod.rs:171–189  ·  view source on GitHub ↗

Load from disk, or create a new empty accumulator if no persisted graph exists. The graph file is expected at `{session_dir}/graph.json`.

(session_dir: &Path, session_id: &str)

Source from the content-addressed store, hash-verified

169 ///
170 /// The graph file is expected at `{session_dir}/graph.json`.
171 pub fn load_or_create(session_dir: &Path, session_id: &str) -> AgentResult<Self> {
172 let path = session_dir.join(GRAPH_FILENAME);
173
174 match std::fs::read(&path) {
175 Ok(data) => {
176 let serialized: SerializedGraph =
177 serde_json::from_slice(&data).map_err(|e| AgentError::SessionLoadFailed {
178 session_id: session_id.to_string(),
179 reason: format!("provenance graph parse error: {}", e),
180 })?;
181 Ok(Self::from_serialized(serialized))
182 }
183 Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(Self::new(session_id)),
184 Err(e) => Err(AgentError::SessionLoadFailed {
185 session_id: session_id.to_string(),
186 reason: format!("provenance graph read error: {}", e),
187 }),
188 }
189 }
190
191 /// Reconstruct an accumulator from a serialized graph.
192 fn from_serialized(s: SerializedGraph) -> Self {

Callers

nothing calls this directly

Calls 2

readFunction · 0.50
kindMethod · 0.45

Tested by

no test coverage detected