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

Function extract_memory_container

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

Lenient scan for a single `:::memory` container fence, returning its inner body if present. Unlike the closed-vocabulary [`crate::directive`] parser, this never errors on unrelated `::`/`:::` tokens in the open memory prose — only a recognized fence (a name in [`LIFTED_MEMORY_DIRECTIVES`]) is treated as structure; everything else is content. An unterminated fence falls back to the whole body (fail

(body: &str)

Source from the content-addressed store, hash-verified

183/// as structure; everything else is content. An unterminated fence falls back
184/// to the whole body (fail-open, preserving content).
185fn extract_memory_container(body: &str) -> Option<String> {
186 let lines: Vec<&str> = body.lines().collect();
187 let mut i = 0;
188 while i < lines.len() {
189 if let Some(name) = container_open_name(lines[i].trim_start()) {
190 if LIFTED_MEMORY_DIRECTIVES.contains(&name) {
191 let mut collected: Vec<&str> = Vec::new();
192 i += 1;
193 while i < lines.len() {
194 if lines[i].trim() == ":::" {
195 return Some(collected.join("\n").trim().to_string());
196 }
197 collected.push(lines[i]);
198 i += 1;
199 }
200 return None; // unterminated → fall back to whole body
201 }
202 }
203 i += 1;
204 }
205 None
206}
207
208/// If `line` opens a container directive (`:::name` optionally with `{...}`),
209/// return the directive name. A bare `:::` (a close) yields `None`.

Callers 1

lift_memoryFunction · 0.85

Calls 5

container_open_nameFunction · 0.85
linesMethod · 0.45
lenMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected