loopd: the memory block from memoryd, recall and memory as core tools

Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
2026-09-25 16:41:44 -07:00
committed by kyle
parent e167fc871b
commit 15ee4b8e3d
14 changed files with 484 additions and 87 deletions
+8 -32
View File
@@ -31,21 +31,22 @@ fn assembles_system_prompt_and_core_schemas() {
}
#[test]
fn core_memory_is_appended_when_present_and_only_then() {
fn the_memory_block_is_appended_when_present_and_only_then() {
let home = Home::new();
let cfg = home.config(Path::new("/tmp/unused.sock"));
home.write("memory/core.md", "The owner likes cork.\n\n");
let b = Baseline::assemble(&cfg, &Registry::m2b()).unwrap();
let block = "# soul.md\nYou are kind.\n\n# memory.md (0 of 2,200 characters)\n(empty)\n";
let b = Baseline::assemble_with(&cfg, &Registry::m2b(), block).unwrap();
assert_eq!(
b.system,
"You are Boxmaker, a test agent.\n\nThe owner likes cork."
"You are Boxmaker, a test agent.\n\n# soul.md\nYou are kind.\n\n# memory.md (0 of 2,200 characters)\n(empty)"
);
home.write("memory/core.md", " \n");
let b = Baseline::assemble(&cfg, &Registry::m2b()).unwrap();
home.write("memory/core.md", "An old core file is ignored.\n");
let b = Baseline::assemble_with(&cfg, &Registry::m2b(), " \n").unwrap();
assert_eq!(
b.system, "You are Boxmaker, a test agent.",
"an empty core file adds nothing"
"an empty block adds nothing, and core.md is no longer read"
);
assert_eq!(b, Baseline::assemble(&cfg, &Registry::m2b()).unwrap());
}
#[test]
@@ -232,28 +233,3 @@ fn replay_of_a_prefix_is_a_prefix() {
assert_eq!(whole[..part.len()], part[..], "prefix of {n} records");
}
}
/// A core memory file that exists but cannot be read is an error, not silently absent: the owner
/// would otherwise get a session without the memory they curated, and no sign of it.
#[test]
fn an_unreadable_core_memory_file_is_an_error() {
use std::os::unix::fs::PermissionsExt;
if running_as_root() {
return; // root can read anything; the check is meaningless there
}
let home = Home::new();
let cfg = home.config(Path::new("/tmp/unused.sock"));
home.write("memory/core.md", "secret memory\n");
let core = home.dir.join("memory/core.md");
std::fs::set_permissions(&core, std::fs::Permissions::from_mode(0o000)).unwrap();
let result = Baseline::assemble(&cfg, &Registry::m2b());
std::fs::set_permissions(&core, std::fs::Permissions::from_mode(0o644)).unwrap();
let e = result.expect_err("an unreadable core.md must not be ignored");
assert!(e.to_string().contains("core.md"), "{e}");
}
fn running_as_root() -> bool {
std::fs::read_to_string("/proc/self/status")
.map(|s| s.lines().any(|l| l.starts_with("Uid:\t0\t")))
.unwrap_or(false)
}