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

Function validate_memory

atomic-canonical/src/gate.rs:367–440  ·  view source on GitHub ↗

Validate a canonical Memory node against `MemoryShape`. Mirrors the doc's shape: `memoryKind` and `status` are closed value sets (exactly one each), `attributedTo` and `proof` must be present, and the `text` must be present and non-empty. As everywhere, presence is enforced and content left honest — no rule reads the memory prose.

(node: &MemoryNode)

Source from the content-addressed store, hash-verified

365/// and non-empty. As everywhere, presence is enforced and content left honest —
366/// no rule reads the memory prose.
367pub fn validate_memory(node: &MemoryNode) -> ValidationReport {
368 let mut out = Vec::new();
369 let focus = &node.id;
370
371 // memoryKind ∈ closed set, exactly one (single field ⇒ cardinality holds).
372 if !vocab::is_known_memory_kind(&node.memory_kind) {
373 out.push(Violation {
374 focus_node: focus.clone(),
375 shape: "MemoryShape".into(),
376 path: Some("memoryKind".into()),
377 message: format!(
378 "memoryKind '{}' is not one of {:?}",
379 node.memory_kind,
380 vocab::MEMORY_KIND
381 ),
382 });
383 }
384
385 // status ∈ closed set, exactly one.
386 if !vocab::is_known_memory_status(&node.status) {
387 out.push(Violation {
388 focus_node: focus.clone(),
389 shape: "MemoryShape".into(),
390 path: Some("status".into()),
391 message: format!(
392 "status '{}' is not one of {:?}",
393 node.status,
394 vocab::MEMORY_STATUS
395 ),
396 });
397 }
398
399 // attributedTo must be present (sh:class prov:Agent deferred — see M0 notes).
400 if node.attributed_to.as_deref().unwrap_or("").is_empty() {
401 out.push(Violation {
402 focus_node: focus.clone(),
403 shape: "MemoryShape".into(),
404 path: Some("attributedTo".into()),
405 message: "author (attributedTo) must be present as a DID".into(),
406 });
407 }
408
409 // proof must be present.
410 if node.proof.is_none() {
411 out.push(Violation {
412 focus_node: focus.clone(),
413 shape: "MemoryShape".into(),
414 path: Some("proof".into()),
415 message: "memory must carry a Data Integrity proof".into(),
416 });
417 }
418
419 // presence-enforced: the memory text must exist (content left honest).
420 if node.text.trim().is_empty() {
421 out.push(Violation {
422 focus_node: focus.clone(),
423 shape: "MemoryShape".into(),
424 path: Some("text".into()),

Calls 6

is_known_memory_kindFunction · 0.85
is_known_memory_statusFunction · 0.85
is_noneMethod · 0.80
pushMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45