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

Function load_attestation

atomic-cli/src/commands/memory/bridge.rs:202–280  ·  view source on GitHub ↗

Load a memory's attestation and classify it against the current source (`inputs`). Prefers the tracked vault entry, falling back to the legacy sidecar. A missing attestation is `None`; a corrupt/malformed one is treated as `None`/skipped with a warning (fail-open, so a read still works on the raw node). Same mechanism as the intent bridge.

(
    repo: &Repository,
    id_or_path: &str,
    inputs: &MemLiftInputs,
)

Source from the content-addressed store, hash-verified

200/// as `None`/skipped with a warning (fail-open, so a read still works on the
201/// raw node). Same mechanism as the intent bridge.
202pub fn load_attestation(
203 repo: &Repository,
204 id_or_path: &str,
205 inputs: &MemLiftInputs,
206) -> CliResult<Attestation> {
207 // 1) Tracked vault entry (authoritative). The body is the pretty JSON-LD
208 // node (+ trailing '\n'); parse it straight to a MemoryNode.
209 let vpath = attestation_vault_path(id_or_path);
210 if let Some(entry) = repo.vault_retrieve(&vpath).map_err(CliError::Repository)? {
211 let raw = String::from_utf8_lossy(&entry.content_bytes);
212 match serde_json::from_str::<MemoryNode>(raw.trim_end()) {
213 Ok(node) => {
214 let recorded = serde_json::from_str::<Value>(&entry.frontmatter_json)
215 .ok()
216 .and_then(|v| {
217 v.get("sourceContentHash")
218 .and_then(Value::as_str)
219 .map(str::to_owned)
220 });
221 let current = source_content_hash(inputs);
222 return Ok(match recorded {
223 Some(h) if h == current => Attestation::Fresh(Box::new(node)),
224 _ => Attestation::Stale(Box::new(node)),
225 });
226 }
227 Err(e) => {
228 eprintln!("warning: ignoring malformed tracked attestation {vpath}: {e}");
229 // fall through to the legacy sidecar
230 }
231 }
232 }
233
234 // 2) Legacy sidecar fallback (pre-upgrade attestations). Memory has no
235 // PREFIX-N ambiguity, so there is exactly ONE candidate path.
236 let path = attested_sidecar_path(repo, id_or_path);
237 if !path.exists() {
238 return Ok(Attestation::None);
239 }
240 let raw = std::fs::read_to_string(&path).map_err(CliError::Io)?;
241 let artifact: Value = match serde_json::from_str(&raw) {
242 Ok(v) => v,
243 Err(e) => {
244 eprintln!(
245 "warning: ignoring unreadable attestation sidecar {}: {e}",
246 path.display()
247 );
248 return Ok(Attestation::None);
249 }
250 };
251 let node_val = match artifact.get("node") {
252 Some(n) => n.clone(),
253 None => {
254 eprintln!(
255 "warning: attestation sidecar {} has no 'node' — ignoring",
256 path.display()
257 );
258 return Ok(Attestation::None);
259 }

Callers 6

runMethod · 0.70
runMethod · 0.70
runMethod · 0.70
compute_rowFunction · 0.70

Calls 7

vault_retrieveMethod · 0.80
attestation_vault_pathFunction · 0.70
source_content_hashFunction · 0.70
attested_sidecar_pathFunction · 0.70
getMethod · 0.65
existsMethod · 0.45
cloneMethod · 0.45