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

Function lift_memory

atomic-canonical/src/memory.rs:129–168  ·  view source on GitHub ↗

Lift a memory from its frontmatter spine and markdown body. `memoryKind`, `status`, `about`, `supersedes`, and `previousRevision` are read from the frontmatter. The text is lifted from the FIRST `:::memory` container directive if present (single authoring site), else falls back to the whole trimmed body.

(frontmatter: &Map<String, Value>, body: &str)

Source from the content-addressed store, hash-verified

127/// container directive if present (single authoring site), else falls back to
128/// the whole trimmed body.
129pub fn lift_memory(frontmatter: &Map<String, Value>, body: &str) -> Result<MemoryNode> {
130 crate::directive::check_embedded_directives(body)?;
131 let uid = opt_str(frontmatter, "uid")
132 .or_else(|| opt_str(frontmatter, "id"))
133 .ok_or_else(|| CanonicalError::Lift("memory frontmatter missing 'uid' (or 'id')".into()))?;
134 let node_id = as_memory_urn(&uid);
135
136 let memory_kind =
137 require_str(frontmatter, "memoryKind").or_else(|_| require_str(frontmatter, "kind"))?;
138 let status = opt_str(frontmatter, "status").unwrap_or_else(|| "active".to_string());
139
140 // Single authoring site: the first `:::memory` container's body is
141 // authoritative; the surrounding prose is ignored. Only when no container
142 // is present does the whole trimmed body become the text — never both.
143 //
144 // The memory text is OPEN prose (presence enforced, content honest), so we
145 // must NOT run it through the closed-vocabulary directive parser: a body
146 // that legitimately begins a line with `::` (a Rust turbofish `::<T>`, or
147 // prose discussing `:::why`) is valid memory content, not a directive
148 // error. We do a lenient fence scan instead, which never rejects.
149 let text = extract_memory_container(body).unwrap_or_else(|| body.trim().to_string());
150
151 Ok(MemoryNode {
152 context: CONTEXT_URL.to_string(),
153 type_: NodeType::Memory.as_str().to_string(),
154 id: node_id,
155 memory_kind,
156 text,
157 about: str_array(frontmatter, "about"),
158 status,
159 supersedes: opt_str(frontmatter, "supersedes"),
160 previous_revision: opt_str(frontmatter, "previousRevision"),
161 content_hash: None,
162 attributed_to: opt_str(frontmatter, "attributedTo"),
163 created_at: opt_str(frontmatter, "createdAt")
164 .or_else(|| opt_str(frontmatter, "created_at"))
165 .unwrap_or_default(),
166 proof: None,
167 })
168}
169
170/// Lenient scan for a single `:::memory` container fence, returning its inner
171/// body if present. Unlike the closed-vocabulary [`crate::directive`] parser,

Calls 7

as_memory_urnFunction · 0.85
extract_memory_containerFunction · 0.85
opt_strFunction · 0.70
require_strFunction · 0.70
str_arrayFunction · 0.70
as_strMethod · 0.45