diff --git a/crates/mind-body/src/persona.rs b/crates/mind-body/src/persona.rs index a2fbae7..313d6a9 100644 --- a/crates/mind-body/src/persona.rs +++ b/crates/mind-body/src/persona.rs @@ -268,6 +268,9 @@ struct Waking<'a> { seq: u64, room: &'a str, event: &'a str, + /// Who sent it, as the mouth names them, and what they said. + sender: &'a str, + text: &'a str, } /// The events her trace shows she is done with: every line a turn held that did not fail (`held`, the room's event ids @@ -318,7 +321,7 @@ fn drain(instance: &Slug, start: &Start) -> Outcome { .iter() .zip(&facts) .filter(|(delivery, facts)| wakes(&her, delivery, speaker(config, delivery), **facts).is_some()) - .map(|(delivery, _)| Waking { seq: delivery.seq, room: delivery.room_alias.as_str(), event: delivery.event_id.as_str() }) + .map(|(delivery, _)| Waking { seq: delivery.seq, room: delivery.room_alias.as_str(), event: delivery.event_id.as_str(), sender: if delivery.sender_display.is_empty() { delivery.sender.as_str() } else { delivery.sender_display.as_str() }, text: delivery.text.as_str() }) .collect(); let woken = !waking_all.is_empty(); // A line her trace shows decided is not waking again, whatever else in the queue is still stuck. The oldest line of a @@ -370,7 +373,7 @@ fn drain(instance: &Slug, start: &Start) -> Outcome { }; // A line set aside is recorded, then acked past before the room's turn, so that turn reads the room without it. if !aside.is_empty() { - let lines: Vec = aside.iter().map(|line| json!({ "room": line.room, "event": line.event })).collect(); + let lines: Vec = aside.iter().map(|line| json!({ "room": line.room, "event": line.event, "sender": line.sender, "text": line.text })).collect(); eprintln!("mind-persona: {} waking line(s) failed {STRIKES} turns and were set aside: {lines:?}", lines.len()); if let Err(fault) = start.trace.record(&format!("{stem}-a"), &json!({ "set_aside": lines, "at": began.to_rfc3339() })) { eprintln!("mind-persona: the record of the lines set aside was not appended: {fault:#}"); diff --git a/crates/mind-body/src/persona/drain_tests.rs b/crates/mind-body/src/persona/drain_tests.rs index ca1aecb..800aff5 100644 --- a/crates/mind-body/src/persona/drain_tests.rs +++ b/crates/mind-body/src/persona/drain_tests.rs @@ -394,13 +394,14 @@ fn t_l2_a_poison_room_does_not_take_the_answered_rooms_again_and_is_set_aside_af let rows = rig.trace.rows.borrow(); assert_eq!(rows.iter().filter(|(_, record)| record.get("failed").is_some()).count(), 2, "exactly two failed turns, never a third"); let (_, aside) = rows.last().unwrap(); - assert_eq!(aside["set_aside"], json!([{ "room": room(2), "event": "$e2" }]), "the line set aside is in her trace: {aside}"); + assert_eq!(aside["set_aside"], json!([{ "room": room(2), "event": "$e2", "sender": META, "text": "FAILME bravo" }]), "the line set aside is in her trace: {aside}"); } /// The line is not dropped silently: her next turn is told, in the outcome's own words, that it failed and was set aside. #[test] fn t_l2_she_is_told_the_next_wake_that_her_turn_on_the_line_failed_and_it_was_set_aside() { let rig = Rig::new(vec![line(1, &room(2), META, "FAILME bravo")]); + rig.mouth.held.borrow_mut()[0].sender_display = "Meta".into(); for _ in 0..3 { rig.run(Flaky { inner: scripted(false), marker: "FAILME", reason: REFUSED }); } @@ -408,7 +409,7 @@ fn t_l2_she_is_told_the_next_wake_that_her_turn_on_the_line_failed_and_it_was_se rig.mouth.held.borrow_mut().push(line(2, &room(1), META, "hello again")); let prompts = Rc::new(RefCell::new(Vec::new())); rig.run(Spy { inner: scripted(false), prompts: prompts.clone() }); - let told = prompts.borrow().iter().any(|prompt| prompt.contains("failed twice, so the line was set aside")); + let told = prompts.borrow().iter().any(|prompt| prompt.contains("turn on Meta's line \"FAILME bravo\" failed twice, so it was set aside")); assert!(told, "her next wake says so: {:?}", prompts.borrow()); } @@ -563,14 +564,27 @@ fn t_l2_the_outages_are_one_list_and_every_other_failure_is_a_strike() { } } +/// The model refusing a turn whose input holds the poison line. Her being told of a line set aside quotes it, which is not +/// the line in her input. +struct RefusesThePoisonLine(Scripted); + +impl Model for RefusesThePoisonLine { + fn ask(&self, request_id: &str, model: &str, prompt: &str, schema: Option<&str>) -> std::result::Result { + if prompt.contains("FAILME") && !prompt.contains("so it was set aside") { + return Err(Failed { reason: REFUSED.into(), usage: None }); + } + self.0.ask(request_id, model, prompt, schema) + } +} + /// Soul's probe: a later line that shares the room with a poison line is not struck for it. #[test] fn t_l2_a_line_that_arrived_after_the_poison_line_is_not_set_aside_for_sharing_its_room() { let rig = Rig::new(vec![line(1, &room(1), META, "FAILME one")]); - rig.run(failing(REFUSED)); + rig.run(RefusesThePoisonLine(scripted(false))); rig.mouth.held.borrow_mut().push(line(2, &room(1), META, "two")); - rig.run(failing(REFUSED)); - rig.run(failing(REFUSED)); + rig.run(RefusesThePoisonLine(scripted(false))); + rig.run(RefusesThePoisonLine(scripted(false))); let aside: Vec = rig.trace.rows.borrow().iter().filter_map(|(_, record)| record.get("set_aside").cloned()).collect(); assert_eq!(aside.len(), 1, "one set-aside record: {aside:?}"); assert_eq!(aside[0][0]["event"], "$e1", "the poison line, and only it"); diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index b93cbd9..3ad283a 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -162,6 +162,14 @@ mod form { } } + /// A person's name in this form: the told and reported forms name them, the event form names no one. + pub(super) fn name(&self, who: &str) -> Option { + match self { + Self::Told(_) | Self::Report => Some(who.to_owned()), + Self::Event(_) => None, + } + } + /// What a read was, in this form. pub(super) fn read(&self, name: &ReadName, her: Forms) -> String { match (self, &name.told) { @@ -237,9 +245,9 @@ enum Part { /// Her state after the turn was put and refused twice: what she meant to keep from that turn was not kept (the drain's /// `put_refused`). NotKept, - /// A waking line whose turn failed twice, acked past with no third try (the drain's `set_aside`): it is told by the room - /// it was in, and nothing reached it. - SetAside { room: Option }, + /// A waking line whose turn failed twice, acked past with no third try (the drain's `set_aside`): told by the room it was + /// in and, when the record names them, whose line it was and its words. + SetAside { room: Option, line: Option<(String, Words)> }, /// Receipts went out, and a later step of the turn broke (C3c's `broke_after`, 16.20.7). BrokeAfter { room: Option }, /// A read she performed (map 16.22.3): what, in code's words; never its content, which is in her view while the @@ -303,7 +311,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { } // A record the drain wrote when it set lines aside carries no decision: it says only which rooms' lines it left. for set_aside in record["set_aside"].as_array().into_iter().flatten() { - outcome.parts.push(Part::SetAside { room: words(&set_aside["room"]) }); + outcome.parts.push(Part::SetAside { room: words(&set_aside["room"]), line: words(&set_aside["sender"]).zip(words_of(&set_aside["text"])) }); } if record.get("set_aside").is_some() { return Some(outcome); @@ -607,7 +615,7 @@ impl Part { Self::NoteRefused(_) => "No note was left:".to_owned(), Self::Failed => format!("Nothing reached the room, and nothing {subj} meant last time happened:"), Self::NotKept => format!("What {subj} meant to keep from that turn was not kept."), - Self::SetAside { room } => format!("Nothing reached {}.", place(room)), + Self::SetAside { room, .. } => format!("Nothing reached {}.", place(room)), Self::BrokeAfter { room } => format!("Nothing more reached {}:", place(room)), Self::Read { what } => format!("{cap_subj} read {}.", form.read(what, her)), Self::ReadFailed { what, .. } => format!("{cap_subj} reached for {} and could not read it:", form.read(what, her)), @@ -672,7 +680,10 @@ impl Part { Self::NoteRefused(_) => format!(" it carried something {subj} may not pass on."), Self::Failed => format!(" the turn broke off, not by {poss} choice."), Self::NotKept => String::new(), - Self::SetAside { .. } => format!(" {} turn on a line there failed twice, so the line was set aside, and it will not be tried again.", capitalized(poss)), + Self::SetAside { line, .. } => match line.as_ref().and_then(|(sender, text)| form.name(sender).zip(form.words(text))) { + Some((sender, quote)) => format!(" {} turn on {sender}'s line {quote} failed twice, so it was set aside.", capitalized(poss)), + None => format!(" {} turn on a line there failed twice, so it was set aside.", capitalized(poss)), + }, Self::BrokeAfter { .. } => format!(" the rest of that turn broke off, not by {poss} choice."), Self::Read { .. } => String::new(), Self::ReadFailed { failure, .. } => format!(" {}.", failure.words()), diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 69ff779..dce3a20 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -466,7 +466,8 @@ fn fixtures(s: &str) -> Vec<(Part, bool)> { out.push((Part::NoteRefused(Refusal::SecondNote), false)); out.push((Part::Failed, false)); out.push((Part::NotKept, false)); - out.push((Part::SetAside { room: room() }, false)); + out.push((Part::SetAside { room: room(), line: Some(("Nibu".to_owned(), w())) }, true)); + out.push((Part::SetAside { room: room(), line: None }, false)); out.push((Part::BrokeAfter { room: room() }, false)); for (request, shows) in [ (ReadRequest::Web(format!("https://example.org/{s}")), true), @@ -654,6 +655,8 @@ fn a_put_refused_twice_and_a_set_aside_line_are_told_plainly() { let mut refused = record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu."]); refused["put_refused"] = json!("stale again"); assert_eq!(told(&refused).0, ["- What he meant to keep from that turn was not kept.", "- #minds:gamecult.org has, from him: \"Hi Nibu.\"."], "the refusal's words are the mind's, not hers: she is told only that it was not kept"); - let aside = json!({ "set_aside": [{ "room": MINDS, "event": "$e1" }], "at": "2026-11-27T10:00:00Z" }); - assert_eq!(told(&aside).0, ["- Nothing reached #minds:gamecult.org. His turn on a line there failed twice, so the line was set aside, and it will not be tried again."]); + let aside = json!({ "set_aside": [{ "room": MINDS, "event": "$e1", "sender": "Nibu", "text": "are you there" }], "at": "2026-11-27T10:00:00Z" }); + assert_eq!(told(&aside).0, ["- Nothing reached #minds:gamecult.org. His turn on Nibu's line \"are you there\" failed twice, so it was set aside."]); + let unnamed = json!({ "set_aside": [{ "room": MINDS, "event": "$e1" }], "at": "2026-11-27T10:00:00Z" }); + assert_eq!(told(&unnamed).0, ["- Nothing reached #minds:gamecult.org. His turn on a line there failed twice, so it was set aside."]); }