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

Function lift_memory

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

Lift a memory from its frontmatter spine and markdown body. `memoryKind`, `status`, `about`, `derivedFrom`, `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

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