Files
boxmaker/crates/memoryd/src/entries.rs
T
kyleandClaude Opus 5.5 2b3ae080b4 proto becomes bxcore, the one shared crate (M5b task 00)
Done the way the owner asked and the spike mapped: the crate and the
manifests renamed, then what the build reported fixed. Layers: 138
"proto unresolved" errors across 169 files; cargo fmt reordering
imports; six fixture paths built as strings in brokerd's and bxctl's
tests, which the compiler cannot see, and comments naming
crates/proto/; the crate-dependency check and its self-test. One more
the spike did not reach: a `\nproto =` key inside a printf format in
the self-test, which a word-boundary replacement skips because `n` and
`p` are both word characters.

make gate: gate: ok, 944 tests; no new entry in /tmp.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 01:48:38 -07:00

45 lines
1.4 KiB
Rust

//! The entries of `memory.md` and `user.md`: text separated by a line holding only `§` (M5a spec,
//! section 3). A file's size is the characters of its entries joined by separator lines, which
//! is what `render` writes, less the final newline.
use bxcore::memory::SEPARATOR;
/// The entries of a file's text: split at lines that are only `§` (spaces around it allowed),
/// each trimmed, empty ones left out.
pub fn parse(text: &str) -> Vec<String> {
let mut entries: Vec<String> = Vec::new();
let mut current: Vec<&str> = Vec::new();
for line in text.lines() {
if line.trim() == SEPARATOR {
push(&mut entries, &current);
current.clear();
} else {
current.push(line);
}
}
push(&mut entries, &current);
entries
}
fn push(entries: &mut Vec<String>, lines: &[&str]) {
let joined = lines.join("\n");
let trimmed = joined.trim();
if !trimmed.is_empty() {
entries.push(trimmed.to_string());
}
}
/// The entries joined by `\n§\n`, with a final newline; an empty list is an empty file.
pub fn render(entries: &[String]) -> String {
if entries.is_empty() {
return String::new();
}
let joined = entries.join(&format!("\n{SEPARATOR}\n"));
format!("{joined}\n")
}
/// A file's size in characters, the one its limit is measured against.
pub fn size(entries: &[String]) -> usize {
render(entries).trim_end_matches('\n').chars().count()
}