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

Function build_files_and_metadata

atomic-agent/src/export.rs:242–436  ·  view source on GitHub ↗

Walk the graph nodes and build: - `files` — per-file `FileEntry` list (from `Commitment` nodes) - `dev_atomic` — the Sherpa-specific metadata object

(graph: &ProvenanceGraph)

Source from the content-addressed store, hash-verified

240/// - `files` — per-file `FileEntry` list (from `Commitment` nodes)
241/// - `dev_atomic` — the Sherpa-specific metadata object
242fn build_files_and_metadata(graph: &ProvenanceGraph) -> (Vec<FileEntry>, Value) {
243 // Collect nodes by kind
244 let goal_node = graph
245 .nodes
246 .iter()
247 .find(|n| n.kind == ProvenanceNodeKind::Goal);
248
249 let commitment_nodes: Vec<_> = graph
250 .nodes
251 .iter()
252 .filter(|n| n.kind == ProvenanceNodeKind::Commitment)
253 .collect();
254
255 let execution_nodes: Vec<_> = graph
256 .nodes
257 .iter()
258 .filter(|n| n.kind == ProvenanceNodeKind::Execution)
259 .collect();
260
261 let verification_node = graph
262 .nodes
263 .iter()
264 .find(|n| n.kind == ProvenanceNodeKind::Verification);
265
266 // Parse detail JSON strings into typed structs (best-effort — None on any
267 // parse error so a malformed node never blocks the export).
268 let goal_detail: Option<GoalDetail> = goal_node
269 .and_then(|n| n.detail.as_deref())
270 .and_then(|s| serde_json::from_str(s).ok());
271
272 let commitment_details: Vec<CommitmentDetail> = commitment_nodes
273 .iter()
274 .filter_map(|n| n.detail.as_deref())
275 .filter_map(|s| serde_json::from_str(s).ok())
276 .collect();
277
278 let verification_detail: Option<VerificationDetail> = verification_node
279 .and_then(|n| n.detail.as_deref())
280 .and_then(|s| serde_json::from_str(s).ok());
281
282 // Extract turn/session identifiers from GoalDetail
283 let session_id = goal_detail
284 .as_ref()
285 .map(|g| g.session_id.as_str())
286 .unwrap_or(&graph.session_id)
287 .to_string();
288
289 let turn_id = goal_detail
290 .as_ref()
291 .map(|g| g.intent_turn_id as u64)
292 .unwrap_or(0);
293
294 let model = goal_detail
295 .as_ref()
296 .map(|g| g.model.as_str())
297 .unwrap_or("")
298 .to_string();
299

Callers 1

to_agent_trace_recordFunction · 0.85

Calls 10

as_refMethod · 0.80
iter_mutMethod · 0.80
getMethod · 0.65
iterMethod · 0.45
collectMethod · 0.45
okMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected