memoryd (files, the check, edits, journal, index, recall, serving), the memory tools and built-in grants in brokerd, the memory block in loopd, bxctl reindex and memory, and the device checks with memoryd. Each task was built as a reference and gated. Each was replayed on its own at its end state (854 to 936 tests) and mutation-checked. Each skeleton compiles and fails its tests. Every todo comment was read beside its signature. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
136 lines
4.0 KiB
Rust
136 lines
4.0 KiB
Rust
//! `memoryd` configuration: read `memoryd.toml` into a typed `Config` (M5a spec, section 11).
|
|
//!
|
|
//! Unknown keys are errors in every table, as in the other roles: a misspelt key that silently
|
|
//! fell back to its default would be a setting the owner believes is set and is not.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use proto::DataClass;
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
|
#[serde(deny_unknown_fields, default)]
|
|
pub struct Paths {
|
|
pub home: PathBuf,
|
|
}
|
|
|
|
impl Default for Paths {
|
|
fn default() -> Self {
|
|
Self {
|
|
home: std::env::var_os("BOXMAKER_HOME")
|
|
.map(PathBuf::from)
|
|
.unwrap_or_else(|| PathBuf::from("/var/lib/boxmaker")),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// `[memory]`: the starter `soul.md`, and whether identity writes wait for the owner.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
|
#[serde(deny_unknown_fields, default)]
|
|
pub struct Memory {
|
|
/// A relative path is resolved next to the config file by `Config::load`.
|
|
pub soul_starter: PathBuf,
|
|
pub review: bool,
|
|
}
|
|
|
|
impl Default for Memory {
|
|
fn default() -> Self {
|
|
Self {
|
|
soul_starter: PathBuf::from("soul.md"),
|
|
review: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// `[index]`: records above `max_class` are not indexed.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
|
#[serde(deny_unknown_fields, default)]
|
|
pub struct Index {
|
|
pub max_class: DataClass,
|
|
}
|
|
|
|
impl Default for Index {
|
|
fn default() -> Self {
|
|
Self {
|
|
max_class: DataClass::Private,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// An empty path means "the default under `home`".
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
|
|
#[serde(deny_unknown_fields, default)]
|
|
pub struct Sockets {
|
|
#[serde(rename = "loop")]
|
|
pub loopd: PathBuf,
|
|
pub broker: PathBuf,
|
|
pub admin: PathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
|
|
#[serde(deny_unknown_fields, default)]
|
|
pub struct Config {
|
|
pub paths: Paths,
|
|
pub memory: Memory,
|
|
pub index: Index,
|
|
pub sockets: Sockets,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum ConfigError {
|
|
Read(PathBuf, std::io::Error),
|
|
Parse(PathBuf, toml::de::Error),
|
|
}
|
|
|
|
impl std::fmt::Display for ConfigError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
match self {
|
|
ConfigError::Read(path, err) => write!(f, "{}: {err}", path.display()),
|
|
ConfigError::Parse(path, err) => write!(f, "{}: {err}", path.display()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for ConfigError {}
|
|
|
|
impl Config {
|
|
pub fn parse(text: &str) -> Result<Config, toml::de::Error> {
|
|
toml::from_str(text)
|
|
}
|
|
|
|
/// Read and parse `path`; a relative `soul_starter` is taken to be next to it.
|
|
pub fn load(path: &Path) -> Result<Config, ConfigError> {
|
|
// 1. std::fs::read_to_string(path), an error as ConfigError::Read(path.to_path_buf(), e).
|
|
// 2. `Config::parse(&text)`, an error as ConfigError::Parse(path.to_path_buf(), e).
|
|
// 3. If `config.memory.soul_starter.is_relative()`, replace it with the directory of the
|
|
// config file (`path.parent()`, or `Path::new(".")` when there is none) joined with it.
|
|
// Ok(config).
|
|
todo!()
|
|
}
|
|
|
|
fn socket(&self, set: &Path, default: &str) -> PathBuf {
|
|
// An empty `set` (`set.as_os_str().is_empty()`) means `self.paths.home.join(default)`;
|
|
// otherwise `set.to_path_buf()`.
|
|
todo!()
|
|
}
|
|
|
|
pub fn loop_socket(&self) -> PathBuf {
|
|
self.socket(&self.sockets.loopd, "run/loop-memory/memory.sock")
|
|
}
|
|
pub fn broker_socket(&self) -> PathBuf {
|
|
self.socket(&self.sockets.broker, "run/broker-memory/memory.sock")
|
|
}
|
|
pub fn admin_socket(&self) -> PathBuf {
|
|
self.socket(&self.sockets.admin, "run/owner-memory/admin.sock")
|
|
}
|
|
pub fn memory_dir(&self) -> PathBuf {
|
|
self.paths.home.join("memory")
|
|
}
|
|
pub fn index_path(&self) -> PathBuf {
|
|
self.paths.home.join("index/memory.sqlite3")
|
|
}
|
|
pub fn sessions_dir(&self) -> PathBuf {
|
|
self.paths.home.join("sessions")
|
|
}
|
|
}
|