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:
@@ -28,6 +28,10 @@ pub struct Record {
|
||||
/// The `notes.md` entries appended, as written.
|
||||
pub notes: Vec<String>,
|
||||
pub untrusted: bool,
|
||||
/// The flag rule the write matched, when it was saved as untrusted notes (M5b spec, section
|
||||
/// 6.3). Absent from the line otherwise, so earlier lines read as they are.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub flag: Option<String>,
|
||||
/// For an undo, the edit it reverted.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub undoes: Option<String>,
|
||||
@@ -103,7 +107,8 @@ pub fn record(store: &Store, ctx: &Context, outcome: &Outcome) -> Result<String,
|
||||
// `append` a Record: id empty (append sets it), time `ctx.now.to_rfc3339()`, session and call
|
||||
// from ctx, action `outcome.action`, file `change.file` as its name, to that name or "notes.md"
|
||||
// when there is no file, before and after from the change, notes the change's notes each
|
||||
// `render()`ed, untrusted `ctx.untrusted`, undoes None; `now` is ctx.now.
|
||||
// `render()`ed, untrusted `ctx.untrusted`, flag `outcome.flag` as a String, undoes None; `now`
|
||||
// is ctx.now.
|
||||
let change = &outcome.change;
|
||||
let notes: Vec<String> = change.notes.iter().map(|n| n.render()).collect();
|
||||
let file = change.file.map(|f| f.name().to_string());
|
||||
@@ -125,6 +130,7 @@ pub fn record(store: &Store, ctx: &Context, outcome: &Outcome) -> Result<String,
|
||||
after: change.after.clone(),
|
||||
notes,
|
||||
untrusted: ctx.untrusted,
|
||||
flag: outcome.flag.map(str::to_string),
|
||||
undoes: None,
|
||||
},
|
||||
ctx.now,
|
||||
@@ -134,8 +140,9 @@ pub fn record(store: &Store, ctx: &Context, outcome: &Outcome) -> Result<String,
|
||||
/// The last `count` records, one line each, oldest first.
|
||||
pub fn log(store: &Store, count: usize) -> Result<String, String> {
|
||||
// The last `count` of `records(store)?` (all of them when fewer), oldest first, one line each:
|
||||
// format!("{} {} {} {} {}{}", id, time, session, action, to, and " untrusted" when the
|
||||
// record is untrusted), joined by newlines. With no records at all: "no memory edits yet".
|
||||
// format!("{} {} {} {} {}", id, time, session, action, to), then " untrusted" when the
|
||||
// record is untrusted, then format!(" flagged {rule}") when it has a flag; joined by
|
||||
// newlines. With no records at all: "no memory edits yet".
|
||||
let all = records(store)?;
|
||||
if all.is_empty() {
|
||||
return Ok("no memory edits yet".to_string());
|
||||
@@ -144,17 +151,17 @@ pub fn log(store: &Store, count: usize) -> Result<String, String> {
|
||||
let lines: Vec<String> = selected
|
||||
.iter()
|
||||
.map(|r| {
|
||||
let mut line = format!(
|
||||
"{} {} {} {} {}",
|
||||
r.id, r.time, r.session, r.action, r.to
|
||||
);
|
||||
if r.untrusted {
|
||||
format!(
|
||||
"{} {} {} {} {} untrusted",
|
||||
r.id, r.time, r.session, r.action, r.to
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{} {} {} {} {}",
|
||||
r.id, r.time, r.session, r.action, r.to
|
||||
)
|
||||
line.push_str(" untrusted");
|
||||
}
|
||||
if let Some(rule) = &r.flag {
|
||||
line.push_str(&format!(" flagged {rule}"));
|
||||
}
|
||||
line
|
||||
})
|
||||
.collect();
|
||||
Ok(lines.join("\n"))
|
||||
@@ -172,7 +179,7 @@ pub fn undo(store: &Store, id: &str, now: Timestamp) -> Result<String, String> {
|
||||
// {id}; nothing was undone")).
|
||||
// 5. `store.write_entries(file, &record.before)?`, then `append` a Record: session "owner",
|
||||
// call 0, action "undo", file and to the name, before the current entries, after
|
||||
// record.before, no notes, untrusted false, undoes Some(id).
|
||||
// record.before, no notes, untrusted false, flag None, undoes Some(id).
|
||||
// 6. Ok(format!("undone: {id} ({name} restored; journalled as {undo_id})")).
|
||||
let all = records(store)?;
|
||||
let record = all
|
||||
@@ -218,6 +225,7 @@ pub fn undo(store: &Store, id: &str, now: Timestamp) -> Result<String, String> {
|
||||
after: record.before.clone(),
|
||||
notes: Vec::new(),
|
||||
untrusted: false,
|
||||
flag: None,
|
||||
undoes: Some(id.to_string()),
|
||||
},
|
||||
now,
|
||||
|
||||
Reference in New Issue
Block a user