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

Function classify_attestation

atomic-repository/src/intent_bridge.rs:280–351  ·  view source on GitHub ↗

The dual-read classification, pure over its inputs: the tracked entry parses to a `CanonicalNode` and its `sourceContentHash` anchor decides fresh vs stale; a malformed tracked entry warns and falls through to the sidecar; a missing or unreadable sidecar degrades to `None` with a warning. Both the local body (repo-read sources) and the routed path (wire-carried sources) run this SAME code.

(sources: AttestationSources, inputs: &LiftInputs)

Source from the content-addressed store, hash-verified

278/// warning. Both the local body (repo-read sources) and the routed path
279/// (wire-carried sources) run this SAME code.
280pub fn classify_attestation(sources: AttestationSources, inputs: &LiftInputs) -> Attestation {
281 if let Some(tracked) = sources.tracked {
282 let raw = String::from_utf8_lossy(&tracked.content);
283 match serde_json::from_str::<CanonicalNode>(raw.trim_end()) {
284 Ok(node) => {
285 // Staleness: prefer the frontmatter anchor `sourceContentHash`;
286 // frontmatter_json round-trips as a flat-scalar JSON object.
287 let recorded = serde_json::from_str::<Value>(&tracked.frontmatter_json)
288 .ok()
289 .and_then(|v| {
290 v.get("sourceContentHash")
291 .and_then(Value::as_str)
292 .map(str::to_owned)
293 });
294 let current = source_content_hash(inputs);
295 return match recorded {
296 Some(h) if h == current => Attestation::Fresh(Box::new(node)),
297 _ => Attestation::Stale(Box::new(node)),
298 };
299 }
300 Err(e) => {
301 eprintln!(
302 "warning: ignoring malformed tracked attestation {}: {e}",
303 tracked.vault_path
304 );
305 // fall through to the legacy sidecar
306 }
307 }
308 }
309 let Some(sidecar) = sources.sidecar else {
310 return Attestation::None;
311 };
312 let artifact: Value = match serde_json::from_str(&sidecar.text) {
313 Ok(v) => v,
314 Err(e) => {
315 eprintln!(
316 "warning: ignoring unreadable attestation sidecar {}: {e}",
317 sidecar.path
318 );
319 return Attestation::None;
320 }
321 };
322 let node_val = match artifact.get("node") {
323 Some(n) => n.clone(),
324 None => {
325 eprintln!(
326 "warning: attestation sidecar {} has no 'node' — ignoring",
327 sidecar.path
328 );
329 return Attestation::None;
330 }
331 };
332 let node: CanonicalNode = match serde_json::from_value(node_val) {
333 Ok(n) => n,
334 Err(e) => {
335 eprintln!(
336 "warning: ignoring malformed attestation node in {}: {e}",
337 sidecar.path

Callers 1

load_attestationFunction · 0.70

Calls 4

source_content_hashFunction · 0.70
getMethod · 0.65
okMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected