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:
@@ -1,5 +1,5 @@
|
||||
//! The baseline: the fixed prefix of every request in an epoch — the system prompt, core memory
|
||||
//! and core tool schemas. It is snapshotted per session so an edit to `system.md` changes nothing
|
||||
//! The baseline: the fixed prefix of every request in an epoch — the system prompt, the memory
|
||||
//! block and core tool schemas. It is snapshotted per session so an edit to `system.md` changes nothing
|
||||
//! for a running session, and `messages` turns a session log back into the request's messages.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -25,7 +25,6 @@ pub enum BaselineError {
|
||||
Read(PathBuf, std::io::Error),
|
||||
Parse(PathBuf, serde_json::Error),
|
||||
Hash,
|
||||
Core(PathBuf, std::io::Error),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BaselineError {
|
||||
@@ -34,11 +33,6 @@ impl std::fmt::Display for BaselineError {
|
||||
BaselineError::Read(path, err) => write!(f, "{}: {err}", path.display()),
|
||||
BaselineError::Parse(path, err) => write!(f, "{}: {err}", path.display()),
|
||||
BaselineError::Hash => write!(f, "hashing the baseline failed"),
|
||||
BaselineError::Core(path, err) => write!(
|
||||
f,
|
||||
"{}: {err}; see docs/runbook.md#core-memory-unreadable",
|
||||
path.display()
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,29 +40,26 @@ impl std::fmt::Display for BaselineError {
|
||||
impl std::error::Error for BaselineError {}
|
||||
|
||||
impl Baseline {
|
||||
/// The system prompt trimmed, plus core memory if it has content; the core tool schemas.
|
||||
/// The system prompt trimmed, with no memory: for tests and the self-test.
|
||||
pub fn assemble(cfg: &Config, registry: &Registry) -> Result<Baseline, BaselineError> {
|
||||
Baseline::assemble_with(cfg, registry, "")
|
||||
}
|
||||
|
||||
/// The system prompt trimmed, then a blank line and the memory block `memoryd` rendered (M5a
|
||||
/// spec, section 4), when there is one; the core tool schemas.
|
||||
pub fn assemble_with(
|
||||
cfg: &Config,
|
||||
registry: &Registry,
|
||||
memory: &str,
|
||||
) -> Result<Baseline, BaselineError> {
|
||||
let system = std::fs::read_to_string(&cfg.baseline.system)
|
||||
.map_err(|e| BaselineError::Read(cfg.baseline.system.clone(), e))?;
|
||||
let mut system = system.trim_end().to_string();
|
||||
|
||||
let core = cfg.paths.home.join("memory/core.md");
|
||||
match std::fs::read_to_string(&core) {
|
||||
Ok(text) => {
|
||||
let trimmed = text.trim();
|
||||
if !trimmed.is_empty() {
|
||||
system.push_str("\n\n");
|
||||
system.push_str(trimmed);
|
||||
}
|
||||
}
|
||||
// A missing file is fine; an unreadable one is reported so the owner is not given a
|
||||
// session without the memory they curated and no sign of it.
|
||||
Err(e) if e.kind() != std::io::ErrorKind::NotFound => {
|
||||
return Err(BaselineError::Core(core.clone(), e));
|
||||
}
|
||||
Err(_) => {}
|
||||
let memory = memory.trim();
|
||||
if !memory.is_empty() {
|
||||
system.push_str("\n\n");
|
||||
system.push_str(memory);
|
||||
}
|
||||
|
||||
Ok(Baseline {
|
||||
system,
|
||||
tools: registry.core_schemas(),
|
||||
|
||||
Reference in New Issue
Block a user