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

Function validate_memory

atomic-canonical/src/gate.rs:412–485  ·  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

410/// and non-empty. As everywhere, presence is enforced and content left honest —
411/// no rule reads the memory prose.
412pub fn validate_memory(node: &MemoryNode) -> ValidationReport {
413 let mut out = Vec::new();
414 let focus = &node.id;
415
416 // memoryKind ∈ closed set, exactly one (single field ⇒ cardinality holds).
417 if !vocab::is_known_memory_kind(&node.memory_kind) {
418 out.push(Violation {
419 focus_node: focus.clone(),
420 shape: "MemoryShape".into(),
421 path: Some("memoryKind".into()),
422 message: format!(
423 "memoryKind '{}' is not one of {:?}",
424 node.memory_kind,
425 vocab::MEMORY_KIND
426 ),
427 });
428 }
429
430 // status ∈ closed set, exactly one.
431 if !vocab::is_known_memory_status(&node.status) {
432 out.push(Violation {
433 focus_node: focus.clone(),
434 shape: "MemoryShape".into(),
435 path: Some("status".into()),
436 message: format!(
437 "status '{}' is not one of {:?}",
438 node.status,
439 vocab::MEMORY_STATUS
440 ),
441 });
442 }
443
444 // attributedTo must be present (sh:class prov:Agent deferred — see M0 notes).
445 if node.attributed_to.as_deref().unwrap_or("").is_empty() {
446 out.push(Violation {
447 focus_node: focus.clone(),
448 shape: "MemoryShape".into(),
449 path: Some("attributedTo".into()),
450 message: "author (attributedTo) must be present as a DID".into(),
451 });
452 }
453
454 // proof must be present.
455 if node.proof.is_none() {
456 out.push(Violation {
457 focus_node: focus.clone(),
458 shape: "MemoryShape".into(),
459 path: Some("proof".into()),
460 message: "memory must carry a Data Integrity proof".into(),
461 });
462 }
463
464 // presence-enforced: the memory text must exist (content left honest).
465 if node.text.trim().is_empty() {
466 out.push(Violation {
467 focus_node: focus.clone(),
468 shape: "MemoryShape".into(),
469 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