memoryd: refuse and flag memory writes through bxcore::sanitize

Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
2026-09-27 19:08:42 -07:00
co-authored by ornith-1.5-35b-a3b
parent b3e9af7586
commit ca8b50cd69
15 changed files with 1001 additions and 249 deletions
+28 -6
View File
@@ -169,12 +169,12 @@ impl Memoryd {
let _state = self.lock();
match self.store.block() {
Ok(block) => {
for (file, refused) in &block.left_out {
for (file, refusal) in &block.left_out {
(self.log)(
format!(
"memoryd: an entry of {} was left out of the block: {}",
"memoryd: an entry of {} was left out of the block by the rule {}; see docs/runbook.md#memory-entry-excluded",
file.name(),
refused.sentence()
refusal.rule
)
.as_str(),
);
@@ -239,8 +239,9 @@ impl Memoryd {
)
}
/// `memory`: staged for review, or applied and journalled; then what it appended to `notes.md`
/// is indexed. Its answer is labelled private and trusted: it is `memoryd`'s own sentence.
/// `memory`: refused, staged for review, or applied and journalled; then what it appended to
/// `notes.md` is indexed. Its answer is labelled private and trusted: it is `memoryd`'s own
/// sentence. A refusal and a flag are logged with the rule's name, never with the text.
fn memory(&self, state: &State, call: &MemoryCall) -> Result<Recalled, String> {
let args: MemoryArgs = match serde_json::from_str(&call.request.arguments) {
Ok(args) => args,
@@ -253,14 +254,35 @@ impl Memoryd {
untrusted: call.untrusted,
now: Timestamp::now(),
};
if let Some(refusal) = edit::refused(&args) {
(self.log)(
format!(
"memoryd: a memory write from session {} was refused by the rule {}; see docs/runbook.md#memory-write-refused",
ctx.session, refusal.rule
)
.as_str(),
);
return Err(refusal.sentence.to_string());
}
// A write that matches a flag rule becomes notes, and notes are never staged.
let answer = if self.config.memory.review
&& !matches!(args, MemoryArgs::Note { .. })
&& !call.untrusted
&& edit::flagged(&args).is_none()
{
review::submit(&self.store, &args, &call.request.arguments, &ctx)?
} else {
let outcome = edit::apply(&self.store, &args, &ctx)?;
journal::record(&self.store, &ctx, &outcome)?;
let id = journal::record(&self.store, &ctx, &outcome)?;
if let Some(rule) = outcome.flag {
(self.log)(
format!(
"memoryd: a memory write from session {} matches the rule {rule}; it was saved in notes.md as an untrusted note (edit {id}); see docs/runbook.md#memory-write-flagged",
ctx.session
)
.as_str(),
);
}
outcome.answer
};
self.index_notes(state);