Files
boxmaker/crates/brokerd/src/builtin.rs
T
2026-09-28 22:28:41 -07:00

50 lines
2.3 KiB
Rust

//! The built-in grants of `recall`, `memory` and `ask_memory` (M5a spec, section 8; M5c spec,
//! section 9). Reading and writing memory is what an agent is, so no grant file can turn it off or
//! put questions in front of it; the prompt is protected by `memoryd`, which lets only clean
//! sessions edit identity.
use bxcore::{Grant, GrantProblem, sha256};
use crate::grants::LoadedGrant;
/// Ids starting with this are the built-ins'; an owner's grant file may not use one.
pub const RESERVED: &str = "builtin-";
/// The built-in grants' text, hashed for the audit log like a grant file's bytes.
pub const RECALL: &str = "tool = \"recall\"\nmode = \"auto\"\nmax_taint = \"secret\"\nresult_class = \"private\"\nuntrusted = false\n";
pub const MEMORY: &str = "tool = \"memory\"\nmode = \"auto\"\nmax_taint = \"secret\"\nresult_class = \"private\"\nuntrusted = false\n";
pub const ASK_MEMORY: &str = "tool = \"ask_memory\"\nmode = \"auto\"\nmax_taint = \"secret\"\nresult_class = \"private\"\nuntrusted = false\n";
/// The sentence for an owner's grant naming a memory tool.
pub const BUILT_IN: &str =
"the policy of recall, memory and ask_memory is built in; remove this grant";
/// The three built-in grants, `builtin-memory`, `builtin-recall` and `builtin-ask-memory`.
pub fn grants() -> Result<Vec<LoadedGrant>, GrantProblem> {
// For each (id, text) of `sources`:
// `toml::from_str::<Grant>(text)` and `sha256(text.as_bytes())`, each error as a GrantProblem {
// file: id, line: None, problem: e.to_string() }; build LoadedGrant { id, grant, sha256 }.
// Collect into Result<Vec<LoadedGrant>, GrantProblem> (the first error wins).
let sources: &[(&str, &str)] = &[
("builtin-memory", MEMORY),
("builtin-recall", RECALL),
("builtin-ask-memory", ASK_MEMORY),
];
let mut out: Vec<LoadedGrant> = Vec::new();
for (id, text) in sources {
let problem = |error: String| GrantProblem {
file: id.to_string(),
line: None,
problem: error,
};
let grant = toml::from_str::<Grant>(text).map_err(|e| problem(e.to_string()))?;
let sha256 = sha256(text.as_bytes()).map_err(|e| problem(e.to_string()))?;
out.push(LoadedGrant {
id: id.to_string(),
grant,
sha256,
});
}
Ok(out)
}