diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index 6506d0d..2421875 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -299,6 +299,14 @@ fn packet_json(packet: &Packet) -> Value { }) } +/// What of her last turn the packet's outcome guard left out (counted in its last line) is listed with what the record held +/// that she is not told (map 16.20.5, I16.11). +fn unshown_omitted(report: &mut Value, packet: &Packet) { + if let Some(omitted) = report.get_mut("last_outcome").and_then(|last| last.get_mut("omitted")).and_then(Value::as_array_mut) { + omitted.extend(packet.unshown.iter().map(|line| json!(format!("not shown past the outcome's guard: {line}")))); + } +} + /// A request id no earlier call carried: the kit's replay store answers a repeated id with its first answer, and a /// turn's clock may be a fixture's, the same on every run, so the id takes the wall clock. fn request_id(instance: &str, stage: &str, tag: &str, seed: u64) -> String { @@ -401,7 +409,9 @@ pub fn project(organs: &Organs, request: &Request, now: DateTime) -> Result "last_outcome": history.last.as_ref().map_or_else(|| json!("none"), |last| json!({ "told": last.lines(select::forms(&state)), "omitted": last.omitted })), }); let Some(renders) = request.renders else { - report["packet"] = packet_json(&select(&inputs, tuning)); + let packet = select(&inputs, tuning); + unshown_omitted(&mut report, &packet); + report["packet"] = packet_json(&packet); return Ok(report); }; let model = organs.model.ok_or_else(|| anyhow!("renders need the connector, and none is configured"))?; @@ -413,6 +423,7 @@ pub fn project(organs: &Organs, request: &Request, now: DateTime) -> Result report["interpreter_model"] = json!(tuning.interpreter.model); } let packets = successive(&inputs, tuning, renders.max(1)); + unshown_omitted(&mut report, &packets[0]); report["packet"] = packet_json(&packets[0]); let narrations: Vec = packets.iter().map(|packet| narrate_one(model, &request.instance, packet, tuning, "a", request.through)).collect(); let texts = |narrations: &[Value]| narrations.iter().filter_map(|one| one["narration"].as_str().map(str::to_owned)).collect::>(); diff --git a/crates/mind-body/src/projection/harness/tests.rs b/crates/mind-body/src/projection/harness/tests.rs index 15a95e0..e6fab8e 100644 --- a/crates/mind-body/src/projection/harness/tests.rs +++ b/crates/mind-body/src/projection/harness/tests.rs @@ -310,10 +310,10 @@ fn soul_k9_each_outcome_fixture_opens_the_packet_with_his_words_verbatim() { let dir = tempfile::tempdir().unwrap(); let fixture = room("operator-warm.toml"); for (file, told) in [ - ("posted.json", "- He said in !dm-meta:gamecult.org: \"Missed you too. I'll send the render tonight.\""), - ("refused.json", "so they did not go out as his own. He wrote: \"I know where you live, and busy doesn't count as an answer.\""), - ("conditional.json", "- He wrote words for !dm-meta:gamecult.org and did not say them. He wrote: \"Honestly? Tired. Good tired, mostly.\""), - ("missing-affordance.json", "it is recorded as a request. In his thought: \"I want to show her the render, not describe it.\""), + ("posted.json", "- !dm-meta:gamecult.org has, from him: \"Missed you too. I'll send the render tonight.\"."), + ("refused.json", "- Nothing reached !dm-meta:gamecult.org. What he wrote was mostly the words he had just been sent, so none of it was sent."), + ("conditional.json", "- Nothing reached !dm-meta:gamecult.org. He wrote this and did not send it, and it is not sent unless he sends it: \"Honestly? Tired. Good tired, mostly.\"."), + ("missing-affordance.json", "it will not happen by itself. In his thought: \"I want to show her the render, not describe it.\"."), ] { let record: Value = serde_json::from_str(&std::fs::read_to_string(fixtures().join("outcomes").join(file)).unwrap()).unwrap(); let organs = Organs { persona: None, chat: Some(&fixture), addressing: fixture.addressee(), model: None }; diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index e5a3d61..2116a75 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -38,7 +38,7 @@ pub(crate) const MAX_LINES: usize = 2; /// A line of at least this many words whose word trigrams are at least this share of what she heard is an echo, not /// her speech. const ECHO_MIN_WORDS: usize = 8; -const ECHO_OVERLAP: f64 = 0.8; +pub(crate) const ECHO_OVERLAP: f64 = 0.8; /// The fewest words a passage of her thought shown back to her may be: a shorter quote ("tell") says nothing of what /// she meant, and is kept as unlocated. const GAP_QUOTE_MIN_WORDS: usize = 4; diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index 41eaa8e..4007d6c 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -1,22 +1,26 @@ -//! What came of her last turn (map 16.16, as amended by 16.19): what she meant to do, and what happened, which she finds -//! out only now. She acts only by intent in her prose; the Interpreter and the actuator turn it into effects she never -//! sees, so her next packet opens with them, first and under its own guard (`select`). +//! What came of her last turn (map 16.16, as amended by 16.19 and 16.20): what she meant to do, and what happened, which +//! she finds out only now. She acts only by intent in her prose; the Interpreter and the actuator turn it into effects she +//! never sees, so her next packet opens with them, first and under its own guard (`select`). //! //! `outcome_of` derives it from one turn's record, and nothing else writes it: no persona-state field, no file. The -//! record is the Interpreter's decision unchanged under `interpreter`, with the actuator's receipts beside it under -//! `posted` (each line that went out: `{event, room, text}`), or `failed` when the turn broke off. The simulator builds -//! it from a turn's report and the lines its room appended; live, it is the C3c commit's trace record, which must carry -//! that shape. +//! record is one of two shapes, never both (map 16.20.7): the Interpreter's decision unchanged under `interpreter`, with +//! the actuator's receipts beside it (`posted`, each line that went out as `{event, room, text}`; `edited`) and +//! `broke_after` when a later step broke; or `failed` alone, when the turn sent nothing and broke off. The simulator +//! builds it from a turn's report and the lines its room appended; live, it is the C3c commit's trace record, which must +//! carry that shape. //! -//! What she is told is this module's table, keyed by typed reasons (`Refusal`, `GapKind`), in the packet's one person -//! (her `Forms`). Model text is never what she is told: a gap's `detail` is not read. Her words are shown only as what -//! they are: a draft (she wrote it) or a located passage of her thought. What she cannot be told truly is omitted and -//! reported: an unlocated gap, a kind the contract does not name, a line the record holds no receipt for. +//! Every line she is told says two things, in this order (map 16.20.5): what reached the room, which `Part::reached` +//! derives from the receipts alone (I16.10), and then what will not happen by itself, from the typed reason (`Refusal`, +//! `GapKind`), in the packet's one person (her `Forms`). No other clause says what reached the room. Model text is +//! never what she is told: a gap's `detail` is not read. Her words are shown only as what they are: a draft (she wrote +//! it) or a located passage of her thought. What she cannot be told truly is omitted and reported: an unlocated gap, a +//! kind the contract does not name, a line the record holds no receipt for, a malformed record. use serde_json::Value; -use super::interpret::{GapKind, Refusal}; -use super::select::{Forms, clip, spoken}; +use super::interpret::{ECHO_OVERLAP, GapKind, MAX_LINES, Refusal}; +use super::narrate::heard_overlap; +use super::select::{Forms, capitalized, clip, spoken}; /// A line of hers that went out, as the actuator's receipt names it. #[derive(Clone, Debug, PartialEq, Eq)] @@ -43,22 +47,29 @@ enum EditRefusal { TooLong, } -/// One thing that came of her last turn, by its typed reason. +/// One thing that came of her last turn, by its typed reason. A part that reached the room carries the receipt that says +/// so (`Said`, `Promise`, `Amended`; a note's receipt is the record that holds it); every other part names the room that +/// nothing reached, when the record names one. #[derive(Clone, Debug, PartialEq, Eq)] enum Part { + /// A posted receipt. Said { room: String, text: String }, - Refused(Refusal, String), + /// A posted receipt whose line promises an act she has no way to do: a `missing_affordance` gap naming it (16.20.6). + Promise { room: String, text: String }, + Refused { reason: Refusal, room: Option, text: String }, Gap { kind: GapKind, room: Option, quote: Quote }, - Unfinished(String), - /// Her words were added after a line of hers. + Unfinished { room: Option, text: String }, + /// An edited receipt with no refusal: her words were added after a line of hers. Amended { room: String, added: String }, /// An addition that changed nothing: refused by code (None) or by the actuator. - NotAmended(Option, String), + NotAmended { refusal: Option, room: Option, added: String }, /// A note to Self, recorded in her turn's record: never claimed read. NoteLeft(String), /// A note not left: private, or a second one. - NoteRefused(Refusal, String), + NoteRefused(Refusal), Failed, + /// Receipts went out, and a later step of the turn broke (C3c's `broke_after`, 16.20.7). + BrokeAfter { room: Option }, } /// What came of her last turn: what she is told, what she is not and why, and the lines that went out. @@ -74,55 +85,72 @@ fn words(value: &Value) -> Option { value.as_str().map(str::trim).filter(|text| !text.is_empty()).map(str::to_owned) } +/// Whether the record holds a receipt of anything having happened: a line that went out, or an edit the actuator answered. +fn has_receipts(record: &Value) -> bool { + ["posted", "edited"].iter().any(|key| record[*key].as_array().is_some_and(|receipts| !receipts.is_empty())) +} + /// What came of the turn `record` records; None when there is no record. A record with nothing to tell (a chosen silence, /// nothing drafted, nothing reached for) is an empty outcome, and no section is rendered from it. +/// +/// The record is one of two shapes, never both (C3c, map 16.20.7): `failed`, when the turn sent nothing and broke off; or +/// the decision with its receipts, and `broke_after` naming the step when a later step broke. A record with both `failed` +/// and receipts is malformed: she is told nothing of it, and it is reported. pub(crate) fn outcome_of(record: &Value) -> Option { if !record.is_object() { return None; } let mut outcome = Outcome::default(); let decision = &record["interpreter"]; - if record.get("failed").is_some() || decision.get("failed").is_some() { + let failed = record.get("failed").is_some() || decision.get("failed").is_some(); + if failed && has_receipts(record) { + outcome.omitted.push("a malformed record: it says the turn failed and carries receipts".to_owned()); + return Some(outcome); + } + if failed { outcome.parts.push(Part::Failed); return Some(outcome); } let room = words(&decision["room"]); + let mut receipts: Vec = Vec::new(); for receipt in record["posted"].as_array().into_iter().flatten() { let (Some(event), Some(room), Some(text)) = (words(&receipt["event"]), words(&receipt["room"]), words(&receipt["text"])) else { outcome.omitted.push(format!("a receipt without its event, room or text: {receipt}")); continue; }; - outcome.parts.push(Part::Said { room: room.clone(), text: text.clone() }); - outcome.posted.push(Posted { event, room, text }); + receipts.push(Posted { event, room, text }); } for line in decision["said"].as_array().into_iter().flatten() { - let went = outcome.posted.iter().any(|posted| Some(posted.room.as_str()) == line["room"].as_str() && Some(posted.text.as_str()) == line["text"].as_str()); + let went = receipts.iter().any(|posted| Some(posted.room.as_str()) == line["room"].as_str() && Some(posted.text.as_str()) == line["text"].as_str()); if !went { outcome.omitted.push(format!("a line said with no receipt that it went out: {}", line["text"])); } } for refusal in decision["refused"].as_array().into_iter().flatten() { match (serde_json::from_value::(refusal["reason"].clone()), words(&refusal["text"])) { - (Ok(reason @ (Refusal::Echo | Refusal::OverLines)), Some(text)) => outcome.parts.push(Part::Refused(reason, text)), - (Ok(Refusal::NotAmendable), Some(text)) => outcome.parts.push(Part::NotAmended(None, text)), - (Ok(reason @ (Refusal::Private | Refusal::SecondNote)), Some(text)) => outcome.parts.push(Part::NoteRefused(reason, text)), + (Ok(reason @ (Refusal::Echo | Refusal::OverLines)), Some(text)) => outcome.parts.push(Part::Refused { reason, room: room.clone(), text }), + (Ok(Refusal::NotAmendable), Some(added)) => outcome.parts.push(Part::NotAmended { refusal: None, room: room.clone(), added }), + (Ok(reason @ (Refusal::Private | Refusal::SecondNote)), Some(_)) => outcome.parts.push(Part::NoteRefused(reason)), _ => outcome.omitted.push(format!("a refusal that is no act of hers: {}", refusal["why"])), } } // An amendment is told by the actuator's receipt (`edited`: `{event, refusal}`), never by the decision alone. for amended in decision["amended"].as_array().into_iter().flatten() { - let (Some(room), Some(added)) = (words(&amended["room"]), words(&amended["added"])) else { + let (Some(at), Some(added)) = (words(&amended["room"]), words(&amended["added"])) else { outcome.omitted.push(format!("an amendment without its room or words: {amended}")); continue; }; let receipt = record["edited"].as_array().into_iter().flatten().find(|receipt| receipt["event"] == amended["event"]); match receipt.map(|receipt| (receipt["refusal"].is_null(), serde_json::from_value::(receipt["refusal"].clone()))) { - Some((true, _)) => outcome.parts.push(Part::Amended { room, added }), - Some((false, Ok(refusal))) => outcome.parts.push(Part::NotAmended(Some(refusal), added)), + Some((true, _)) => outcome.parts.push(Part::Amended { room: at, added }), + Some((false, Ok(refusal))) => outcome.parts.push(Part::NotAmended { refusal: Some(refusal), room: Some(at), added }), Some((false, Err(_))) => outcome.omitted.push(format!("an amendment refused for a reason no table names: {}", receipt.map_or(Value::Null, |receipt| receipt["refusal"].clone()))), None => outcome.omitted.push(format!("an amendment with no receipt that it was made: {}", amended["added"])), } } + // A reach that names a line which went out is a promise: the receipt says it reached the room, and she is told what + // it promises (16.20.6). Each receipt is told once, as a promise or as said. + let mut promised: Vec = Vec::new(); for gap in decision["gaps"].as_array().into_iter().flatten() { let kind = serde_json::from_value::(gap["kind"].clone()).unwrap_or(GapKind::Unresolved); let quote = match (gap["from"].as_str(), words(&gap["words"])) { @@ -130,11 +158,22 @@ pub(crate) fn outcome_of(record: &Value) -> Option { (Some("thought"), Some(text)) => Some(Quote::Thought(text)), _ => None, }; - match quote { - Some(quote) if kind != GapKind::Unresolved => outcome.parts.push(Part::Gap { kind, room: room.clone(), quote }), + let sent = match "e { + Some(Quote::Wrote(text)) if kind == GapKind::MissingAffordance => (0..receipts.len()).find(|at| receipts[*at].text == *text && !promised.contains(at)), + _ => None, + }; + match (quote, sent) { + (_, Some(at)) => { + promised.push(at); + outcome.parts.push(Part::Promise { room: receipts[at].room.clone(), text: receipts[at].text.clone() }); + } + (Some(quote), None) if kind != GapKind::Unresolved => outcome.parts.push(Part::Gap { kind, room: room.clone(), quote }), _ => outcome.omitted.push(format!("a gap she cannot be shown truly (kind {}, from {}): {}", gap["kind"], gap["from"], gap["quote"])), } } + for (_, posted) in receipts.iter().enumerate().filter(|(at, _)| !promised.contains(at)) { + outcome.parts.push(Part::Said { room: posted.room.clone(), text: posted.text.clone() }); + } // A note is recorded by the record that holds it: the turn's record is Self's inbox. for note in decision["suggestions"].as_array().into_iter().flatten() { match words(¬e["text"]) { @@ -143,51 +182,113 @@ pub(crate) fn outcome_of(record: &Value) -> Option { } } if let Some(text) = words(&decision["unfinished"]) { - outcome.parts.push(Part::Unfinished(text)); + outcome.parts.push(Part::Unfinished { room: room.clone(), text }); } + if words(&record["broke_after"]).is_some() { + outcome.parts.push(Part::BrokeAfter { room }); + } + outcome.parts.sort_by_key(Part::rank); + outcome.posted = receipts; Some(outcome) } +/// The lines one turn may say, in words. +fn lines_word() -> String { + match MAX_LINES { + 1 => "one line".into(), + 2 => "two lines".into(), + 3 => "three lines".into(), + n => format!("{n} lines"), + } +} + impl Part { - /// The line she is told: the table's sentence, in her pronouns, then her words, held to `quote_max` bytes. - fn line(&self, her: Forms, quote_max: usize) -> String { - let Forms { subj, cap_subj, poss, .. } = her; - let quoted = |text: &str| spoken(&clip(text, quote_max)); + /// Where the part falls in what she is told (16.20.5): what broke, then what did not happen, then promises, then what + /// reached the room, then a later step that broke. + fn rank(&self) -> u8 { + match self { + Self::Failed => 0, + Self::Refused { .. } | Self::Gap { .. } | Self::Unfinished { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) => 1, + Self::Promise { .. } => 2, + Self::Said { .. } | Self::Amended { .. } | Self::NoteLeft(_) => 3, + Self::BrokeAfter { .. } => 4, + } + } + + /// What reached the room, from the part's receipt alone (16.20.5, I16.10): "{Room} has …" only where a receipt says a + /// line went out or was added to, a note only where the record holds it, and otherwise what reached no one. No other + /// clause of a line says what reached the room. + fn reached(&self, her: Forms, quoted: &dyn Fn(&str) -> String) -> String { + let Forms { subj, cap_subj, obj, poss, .. } = her; + let place = |room: &Option| room.clone().unwrap_or_else(|| "the room".to_owned()); + match self { + Self::Said { room, text } | Self::Promise { room, text } => format!("{} has, from {obj}: {}.", capitalized(room), quoted(text)), + Self::Amended { room, added } => format!("{} has {poss} line, now ending with: {}.", capitalized(room), quoted(added)), + Self::NoteLeft(text) => format!("{cap_subj} left Self a note: {}.", quoted(text)), + Self::Refused { reason: Refusal::Echo, room, .. } | Self::Gap { kind: GapKind::Conditional | GapKind::Unwritten | GapKind::Unresolved, room, .. } => format!("Nothing reached {}.", place(room)), + Self::Refused { room, .. } | Self::Unfinished { room, .. } => format!("Nothing of this reached {}:", place(room)), + Self::Gap { kind: GapKind::Addressee | GapKind::Elsewhere, .. } => "Nothing reached anyone.".to_owned(), + Self::Gap { kind: GapKind::MissingAffordance, .. } => "Nothing happened.".to_owned(), + Self::NotAmended { refusal: None, room, .. } => format!("Nothing changed, and nothing reached {}:", place(room)), + Self::NotAmended { refusal: Some(_), room, .. } => format!("Nothing changed in {}:", place(room)), + Self::NoteRefused(Refusal::SecondNote) => "No second note was left:".to_owned(), + Self::NoteRefused(_) => "No note was left:".to_owned(), + Self::Failed => format!("Nothing reached the room, and nothing {subj} meant last time happened:"), + Self::BrokeAfter { room } => format!("Nothing more reached {}:", place(room)), + } + } + + /// Why, and what will not happen by itself (16.20.5), from the part's typed reason: never a word about what reached + /// the room, which is `reached`'s alone. + fn rest(&self, her: Forms, quoted: &dyn Fn(&str) -> String) -> String { + let Forms { subj, cap_subj, obj, poss, has, s, .. } = her; let shown = |quote: &Quote| match quote { - Quote::Wrote(text) => format!("{cap_subj} wrote: {}", quoted(text)), - Quote::Thought(text) => format!("In {poss} thought: {}", quoted(text)), + Quote::Wrote(text) => format!("{cap_subj} wrote: {}.", quoted(text)), + Quote::Thought(text) => format!("In {poss} thought: {}.", quoted(text)), + }; + // A draft gap's words follow its sentence after a colon; a passage of her thought is shown as her thought. + let after = |sentence: String, quote: &Quote| match quote { + Quote::Wrote(text) => format!(" {sentence}: {}.", quoted(text)), + Quote::Thought(_) => format!(" {sentence}. {}", shown(quote)), }; match self { - Self::Said { room, text } => format!("- {cap_subj} said in {room}: {}", quoted(text)), - Self::Refused(Refusal::Echo, text) => format!("- These were mostly the words {subj} had just heard, so they did not go out as {poss} own. {}", shown(&Quote::Wrote(text.clone()))), - Self::Refused(_, text) => format!("- {cap_subj} had already said enough that turn; this did not go out. {}", shown(&Quote::Wrote(text.clone()))), - Self::Gap { kind, room, quote } => { - let sentence = match kind { - GapKind::Conditional => format!("{cap_subj} wrote words for {} and did not say them.", room.as_deref().unwrap_or("the room")), - GapKind::Addressee => format!("{cap_subj} meant this for someone, and it was unclear whom; nothing reached them."), - GapKind::Elsewhere => format!("{cap_subj} meant this for another room or another time; nothing reached anyone."), - GapKind::MissingAffordance => format!("{cap_subj} reached for this; there is no way to do it from a chat turn yet; it is recorded as a request."), - GapKind::Unwritten | GapKind::Unresolved => format!("{cap_subj} meant to say something and did not write the words {subj} would type, so nothing went out."), - }; - format!("- {sentence} {}", shown(quote)) - } - Self::Unfinished(text) => format!("- The turn ended before {subj} finished writing it; it did not go out. {}", shown(&Quote::Wrote(text.clone()))), - Self::Amended { room, added } => format!("- {cap_subj} added to what {subj} said in {room}: {}", quoted(added)), - Self::NotAmended(refusal, added) => { + Self::Said { .. } => String::new(), + Self::Amended { .. } => " The rest of the line is as it was.".to_owned(), + Self::Promise { .. } => format!(" It promises something {subj} {has} no way to do, now or later, and it will not happen by itself. The line stands as {subj} wrote it; {subj} can add to it."), + Self::NoteLeft(_) => format!(" It waits in Self's inbox until Self reads it; nothing tells {obj} when, and nothing in it happens by itself."), + Self::Refused { reason: Refusal::Echo, .. } => format!(" What {subj} wrote was mostly the words {subj} had just been sent, so none of it was sent."), + Self::Refused { text, .. } => format!(" {subj} had already sent {} that turn. {}", lines_word(), shown(&Quote::Wrote(text.clone()))), + Self::Gap { kind: GapKind::Conditional, quote, .. } => after(format!("{cap_subj} wrote this and did not send it, and it is not sent unless {subj} send{s} it"), quote), + Self::Gap { kind: GapKind::Addressee, quote, .. } => after(format!("{cap_subj} meant to send this and it was unclear to whom"), quote), + Self::Gap { kind: GapKind::Elsewhere, quote, .. } => after(format!("{cap_subj} meant this for another room or another time, and nothing carries it there; it arrives only if {subj} send{s} it there"), quote), + Self::Gap { kind: GapKind::MissingAffordance, quote, .. } => format!(" {cap_subj} reached for something {subj} {has} no way to do from here, now or later, and it will not happen by itself. {} That {subj} wanted it is kept in {poss} record; no one has taken it up.", shown(quote)), + Self::Gap { quote, .. } => format!(" {cap_subj} meant to say something and wrote no words to send. {}", shown(quote)), + Self::Unfinished { text, .. } => format!(" the turn ended before {subj} finished writing it. {}", shown(&Quote::Wrote(text.clone()))), + Self::NotAmended { refusal: None, added, .. } => format!(" the line {subj} meant to add to is not one {subj} can add to here. {}", shown(&Quote::Wrote(added.clone()))), + Self::NotAmended { refusal: Some(refusal), added, .. } => { let why = match refusal { - None => format!("{cap_subj} meant to add to something {subj} said, and it was not changed."), - Some(EditRefusal::NotFound) => format!("The line {subj} meant to add to could not be changed: it is gone."), - Some(EditRefusal::NotHers) => format!("The line {subj} meant to add to could not be changed: it is not a line of {poss}."), - Some(EditRefusal::TooLong) => format!("The line {subj} meant to add to could not be changed: it would be too long."), + EditRefusal::NotFound => "the line is gone.".to_owned(), + EditRefusal::NotHers => format!("the line is not {poss}."), + EditRefusal::TooLong => "the line would be too long.".to_owned(), }; - format!("- {why} {}", shown(&Quote::Wrote(added.clone()))) + format!(" {why} {}", shown(&Quote::Wrote(added.clone()))) } - Self::NoteLeft(text) => format!("- {cap_subj} left a note for Self: {}. It is in Self's inbox, for when Self next reads it.", quoted(text)), - Self::NoteRefused(Refusal::SecondNote, text) => format!("- {cap_subj} had already left Self a note that turn. {}", shown(&Quote::Wrote(text.clone()))), - Self::NoteRefused(_, text) => format!("- {cap_subj} meant to leave Self a note, and it was not left: it carried something {subj} may not pass on. {}", shown(&Quote::Wrote(text.clone()))), - Self::Failed => format!("- Nothing came of {poss} last moment: it broke off before anything happened, not by {poss} choice."), + Self::NoteRefused(Refusal::SecondNote) => " one a turn.".to_owned(), + Self::NoteRefused(_) => format!(" it carried something {subj} may not pass on."), + Self::Failed => format!(" the turn broke off, not by {poss} choice."), + Self::BrokeAfter { .. } => format!(" the rest of that turn broke off, not by {poss} choice."), } } + + /// The line she is told: what reached the room, then why and what will not happen by itself, her words held to + /// `quote_max` bytes. A quote that is mostly words she was sent this turn (`sent`, the turn's bodies, by the echo + /// check's metric) is shown as "(words she had been sent)", so no run of words said to her this turn reaches the + /// Projector through her outcome (16.20.4, I16.7). + fn line(&self, her: Forms, quote_max: usize, sent: &[String]) -> String { + let sent = sent.join("\n"); + let quoted = |text: &str| if !sent.is_empty() && heard_overlap(text, &sent) >= ECHO_OVERLAP { format!("(words {} had been sent)", her.subj) } else { spoken(&clip(text, quote_max)) }; + format!("- {}{}", self.reached(her, "ed), self.rest(her, "ed)) + } } impl Outcome { @@ -196,14 +297,14 @@ impl Outcome { self.parts.len() } - /// The `at`th line she is told, its quotes held to `quote_max` bytes. - pub(crate) fn line(&self, at: usize, her: Forms, quote_max: usize) -> String { - self.parts[at].line(her, quote_max) + /// The `at`th line she is told, its quotes held to `quote_max` bytes and none of them mostly the words in `sent`. + pub(crate) fn line(&self, at: usize, her: Forms, quote_max: usize, sent: &[String]) -> String { + self.parts[at].line(her, quote_max, sent) } - /// Every line she is told, whole. + /// Every line she is told, whole: the report's. pub(crate) fn lines(&self, her: Forms) -> Vec { - (0..self.len()).map(|at| self.line(at, her, usize::MAX)).collect() + (0..self.len()).map(|at| self.line(at, her, usize::MAX, &[])).collect() } } diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 94c8fd3..6eeae2d 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -19,22 +19,23 @@ fn told(record: &Value) -> (Vec, Vec) { } #[test] -fn a_line_that_went_out_is_told_verbatim_where_it_went() { +fn a_line_that_went_out_is_told_as_the_room_having_it() { let (lines, omitted) = told(&record("I nod. Hi Nibu.\n\nGood tag.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu.\n\nGood tag."])); - assert_eq!(lines, ["- He said in #minds:gamecult.org: \"Hi Nibu.\\n\\nGood tag.\""], "escaped as every packet line is"); + assert_eq!(lines, ["- #minds:gamecult.org has, from him: \"Hi Nibu.\\n\\nGood tag.\"."], "escaped as every packet line is"); assert!(omitted.is_empty(), "{omitted:?}"); } #[test] -fn a_refused_echo_and_a_line_past_the_turns_lines_are_told_with_her_draft() { +fn a_refused_echo_quotes_nothing_and_a_line_past_the_turns_lines_is_told_with_his_draft() { let (echo, _) = told(&record("The economy is still the least-built part! I say it back.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &[])); - assert_eq!(echo, ["- These were mostly the words he had just heard, so they did not go out as his own. He wrote: \"The economy is still the least-built part!\""]); + assert_eq!(echo, ["- Nothing reached #minds:gamecult.org. What he wrote was mostly the words he had just been sent, so none of it was sent."]); + assert!(!echo[0].contains("economy"), "an echo row shows none of their words (16.20.4)"); let (over, _) = told(&record("One. Two. Three.", json!({ "say": [{ "draft": 1 }, { "draft": 2 }, { "draft": 3 }], "gaps": [] }), &["One.", "Two."])); - assert_eq!(over[2], "- He had already said enough that turn; this did not go out. He wrote: \"Three.\"", "{over:?}"); + assert_eq!(over, ["- Nothing of this reached #minds:gamecult.org: he had already sent two lines that turn. He wrote: \"Three.\".", "- #minds:gamecult.org has, from him: \"One.\".", "- #minds:gamecult.org has, from him: \"Two.\"."], "what did not happen first, then what did"); } #[test] -fn a_gap_is_told_by_its_kind_with_a_draft_as_written_and_a_thought_as_thought() { +fn each_gap_is_told_by_its_kind_with_a_draft_as_written_and_a_thought_as_thought() { let prose = "If Kiko asks again: Fine, you win. I want to see the shape of that sound. I'll tell Meta I'm fine, more or less."; let gaps = json!([ { "kind": "conditional", "draft": 1, "quote": null, "detail": "only if asked" }, @@ -46,27 +47,53 @@ fn a_gap_is_told_by_its_kind_with_a_draft_as_written_and_a_thought_as_thought() assert_eq!( lines, [ - "- He wrote words for #minds:gamecult.org and did not say them. He wrote: \"Fine, you win.\"", - "- He reached for this; there is no way to do it from a chat turn yet; it is recorded as a request. In his thought: \"I want to see the shape of that sound.\"", - "- He meant to say something and did not write the words he would type, so nothing went out. In his thought: \"I'll tell Meta I'm fine, more or less.\"", + "- Nothing reached #minds:gamecult.org. He wrote this and did not send it, and it is not sent unless he sends it: \"Fine, you win.\".", + "- Nothing happened. He reached for something he has no way to do from here, now or later, and it will not happen by itself. In his thought: \"I want to see the shape of that sound.\". That he wanted it is kept in his record; no one has taken it up.", + "- Nothing reached #minds:gamecult.org. He meant to say something and wrote no words to send. In his thought: \"I'll tell Meta I'm fine, more or less.\".", ] ); assert!(lines.iter().all(|line| !line.contains("MODEL-DETAIL")), "the model's detail is never what he is told"); assert_eq!(omitted.len(), 1, "the unlocated gap is omitted and reported: {omitted:?}"); assert!(omitted[0].contains("\"tell\""), "{omitted:?}"); + let drafted = |kind: &str| told(&record("Tell her the render is late.", json!({ "say": [], "gaps": [{ "kind": kind, "draft": 1, "quote": null, "detail": "" }] }), &[])).0; + assert_eq!(drafted("addressee"), ["- Nothing reached anyone. He meant to send this and it was unclear to whom: \"Tell her the render is late.\"."]); + assert_eq!(drafted("elsewhere"), ["- Nothing reached anyone. He meant this for another room or another time, and nothing carries it there; it arrives only if he sends it there: \"Tell her the render is late.\"."]); } #[test] -fn an_unfinished_draft_and_a_failed_turn_are_told_as_what_they_were() { +fn a_promise_is_told_as_the_room_having_it_and_what_will_not_happen_by_itself() { + let text = "Missed you too. I'll send the render tonight."; + let promise = json!({ "interpreter": { "room": MINDS, "said": [{ "room": MINDS, "text": text }], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "draft", "draft": 1, "words": text }] }, "posted": [{ "event": "40", "room": MINDS, "text": text }] }); + let (lines, omitted) = told(&promise); + assert_eq!(lines, ["- #minds:gamecult.org has, from him: \"Missed you too. I'll send the render tonight.\". It promises something he has no way to do, now or later, and it will not happen by itself. The line stands as he wrote it; he can add to it."], "told once, as a promise"); + assert!(omitted.is_empty(), "{omitted:?}"); + let unsent = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "draft", "draft": 1, "words": text }] }, "posted": [] }); + assert_eq!(told(&unsent).0, ["- Nothing happened. He reached for something he has no way to do from here, now or later, and it will not happen by itself. He wrote: \"Missed you too. I'll send the render tonight.\". That he wanted it is kept in his record; no one has taken it up."], "no receipt, no promise row"); +} + +#[test] +fn an_unfinished_draft_a_failed_turn_and_a_later_break_are_told_as_what_they_were() { let (lines, _) = told(&record("I was about to tell you that", json!({ "say": [], "gaps": [] }), &[])); - assert_eq!(lines, ["- The turn ended before he finished writing it; it did not go out. He wrote: \"I was about to tell you that\""]); - let failed = "- Nothing came of his last moment: it broke off before anything happened, not by his choice."; + assert_eq!(lines, ["- Nothing of this reached #minds:gamecult.org: the turn ended before he finished writing it. He wrote: \"I was about to tell you that\"."]); + let failed = "- Nothing reached the room, and nothing he meant last time happened: the turn broke off, not by his choice."; assert_eq!(told(&json!({ "failed": "the provider failed the call: Overloaded" })).0, [failed]); assert_eq!(told(&json!({ "interpreter": { "failed": "the answer is not the speech contract" }, "posted": [] })).0, [failed]); + let mut broke = record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu."]); + broke["broke_after"] = json!("commit"); + assert_eq!(told(&broke).0, ["- #minds:gamecult.org has, from him: \"Hi Nibu.\".", "- Nothing more reached #minds:gamecult.org: the rest of that turn broke off, not by his choice."], "the receipts, then the rest of that turn broke off (C3c, 16.20.7)"); } #[test] -fn a_chosen_silence_tells_her_nothing_and_no_record_is_no_outcome() { +fn a_record_that_failed_and_carries_receipts_is_malformed_told_nothing_and_reported() { + let mut both = record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu."]); + both["failed"] = json!("the commit broke"); + let (lines, omitted) = told(&both); + assert!(lines.is_empty(), "{lines:?}"); + assert!(omitted.len() == 1 && omitted[0].contains("malformed"), "{omitted:?}"); +} + +#[test] +fn a_chosen_silence_tells_him_nothing_and_no_record_is_no_outcome() { let silent = outcome_of(&record("The quiet is fine. I let it be.", json!({ "say": [], "gaps": [] }), &[])).unwrap(); assert_eq!((silent.len(), silent.omitted.len()), (0, 0)); assert_eq!(outcome_of(&Value::Null), None); @@ -82,9 +109,9 @@ fn a_line_said_with_no_receipt_is_not_told_as_said() { #[test] fn the_table_speaks_of_her_in_her_own_pronouns() { let outcome = outcome_of(&record("Hi. There. Again.", json!({ "say": [{ "draft": 1 }, { "draft": 2 }, { "draft": 3 }], "gaps": [] }), &["Hi.", "There."])).unwrap(); - for (pronouns, line) in [("she/her", "- She had already said enough that turn"), ("any", "- They had already said enough that turn")] { + for (pronouns, line) in [("she/her", "she had already sent two lines"), ("any", "they had already sent two lines")] { let her = crate::projection::select::forms(&json!({ "presentation": { "pronouns": pronouns } })); - assert!(outcome.lines(her)[2].starts_with(line), "{pronouns}: {:?}", outcome.lines(her)); + assert!(outcome.lines(her)[0].contains(line), "{pronouns}: {:?}", outcome.lines(her)); } } @@ -102,7 +129,7 @@ fn no_other_source_builds_her_outcome_and_this_one_writes_nothing() { ("harness.rs", include_str!("../harness.rs")), ("projection.rs", include_str!("../../projection.rs")), ] { - for told in ["recorded as a request", "broke off before anything happened", "did not go out"] { + for told in ["will not happen by itself", "so none of it was sent", "now ending with", "has, from "] { assert!(!source.contains(told), "{name} builds outcome text: {told}"); } } @@ -117,27 +144,26 @@ fn amended(target: &str, edited: Value) -> Value { #[test] fn an_amendment_is_told_by_the_actuators_receipt() { let made = told(&amended("a1", json!([{ "event": "$ev-1", "refusal": null }]))); - assert_eq!(made.0, ["- He added to what he said in #minds:gamecult.org: \"Couldn't send it after all.\""]); - for (refusal, why) in [("not_found", "it is gone."), ("not_hers", "it is not a line of his."), ("too_long", "it would be too long.")] { + assert_eq!(made.0, ["- #minds:gamecult.org has his line, now ending with: \"Couldn't send it after all.\". The rest of the line is as it was."]); + for (refusal, why) in [("not_found", "the line is gone."), ("not_hers", "the line is not his."), ("too_long", "the line would be too long.")] { let (lines, _) = told(&amended("a1", json!([{ "event": "$ev-1", "refusal": refusal }]))); - assert_eq!(lines, [format!("- The line he meant to add to could not be changed: {why} He wrote: \"Couldn't send it after all.\"")]); + assert_eq!(lines, [format!("- Nothing changed in #minds:gamecult.org: {why} He wrote: \"Couldn't send it after all.\".")]); } let (lines, omitted) = told(&amended("a1", json!([]))); assert!(lines.is_empty() && omitted[0].contains("no receipt"), "an amendment nothing says was made is not told as made: {lines:?} {omitted:?}"); let (off, _) = told(&amended("zz", json!([]))); - assert_eq!(off, ["- He meant to add to something he said, and it was not changed. He wrote: \"Couldn't send it after all.\""]); + assert_eq!(off, ["- Nothing changed, and nothing reached #minds:gamecult.org: the line he meant to add to is not one he can add to here. He wrote: \"Couldn't send it after all.\"."]); } #[test] fn a_note_to_self_is_told_as_left_and_never_as_read() { let note = |suggest: Value| record("The kettle wants a softer attack. And the door.", json!({ "say": [], "gaps": [], "suggest": suggest }), &[]); let (left, _) = told(¬e(json!([{ "kind": "idea", "draft": 1, "about": null, "private": false }]))); - assert_eq!(left, ["- He left a note for Self: \"The kettle wants a softer attack.\". It is in Self's inbox, for when Self next reads it."]); + assert_eq!(left, ["- He left Self a note: \"The kettle wants a softer attack.\". It waits in Self's inbox until Self reads it; nothing tells him when, and nothing in it happens by itself."]); let (private, _) = told(¬e(json!([{ "kind": "idea", "draft": 1, "about": null, "private": true }]))); - assert_eq!(private, ["- He meant to leave Self a note, and it was not left: it carried something he may not pass on. He wrote: \"The kettle wants a softer attack.\""]); + assert_eq!(private, ["- No note was left: it carried something he may not pass on."]); let (second, _) = told(¬e(json!([{ "kind": "idea", "draft": 1, "about": null, "private": false }, { "kind": "idea", "draft": 2, "about": null, "private": false }]))); - assert!(second.contains(&"- He had already left Self a note that turn. He wrote: \"And the door.\"".to_owned()) && second.len() == 2, "{second:?}"); - assert!(left.iter().chain(&private).chain(&second).all(|line| !line.contains(" read it") || line.contains("next reads it")), "read is never claimed"); + assert_eq!(second, ["- No second note was left: one a turn.", "- He left Self a note: \"The kettle wants a softer attack.\". It waits in Self's inbox until Self reads it; nothing tells him when, and nothing in it happens by itself."]); } #[test] @@ -145,12 +171,89 @@ fn soul_someone_elses_words_in_his_thought_are_shown_as_his_thought_never_as_his let prose = "Meta said, \"Nobody touches the release branch tonight.\" I keep turning that over."; let (lines, _) = told(&record(prose, json!({ "say": [], "gaps": [{ "kind": "unwritten", "draft": null, "quote": "Nobody touches the release branch tonight.", "detail": "" }] }), &[])); assert_eq!(lines.len(), 1, "{lines:?}"); - assert!(lines[0].ends_with("In his thought: \"Nobody touches the release branch tonight.\"") && !lines[0].contains("He wrote"), "{lines:?}"); + assert!(lines[0].ends_with("In his thought: \"Nobody touches the release branch tonight.\".") && !lines[0].contains("He wrote"), "{lines:?}"); } #[test] fn soul_a_gap_that_contradicts_what_went_out_is_not_told() { let (lines, omitted) = told(&record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [{ "kind": "conditional", "draft": 1, "quote": null, "detail": "" }] }), &["Hi Nibu."])); - assert_eq!(lines, ["- He said in #minds:gamecult.org: \"Hi Nibu.\""]); + assert_eq!(lines, ["- #minds:gamecult.org has, from him: \"Hi Nibu.\"."]); assert!(omitted.iter().any(|why| why.contains("acted")), "{omitted:?}"); } + +/// Every row of the table (16.20.5), each record with what it was built to show. +fn every_row() -> Vec { + let text = "Missed you too. I'll send the render tonight."; + let mut broke = record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu."]); + broke["broke_after"] = json!("commit"); + let note = |suggest: Value| record("The kettle wants a softer attack. And the door.", json!({ "say": [], "gaps": [], "suggest": suggest }), &[]); + vec![ + record("The economy is still the least-built part!", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &[]), + record("One. Two. Three.", json!({ "say": [{ "draft": 1 }, { "draft": 2 }, { "draft": 3 }], "gaps": [] }), &["One.", "Two."]), + record( + "If Kiko asks again: Fine, you win. Tell her. Later, maybe. I want to see the shape of that sound. I'll tell Meta I'm fine, more or less. And then", + json!({ "say": [], "gaps": [ + { "kind": "conditional", "draft": 1, "quote": null, "detail": "" }, + { "kind": "addressee", "draft": 2, "quote": null, "detail": "" }, + { "kind": "elsewhere", "draft": 3, "quote": null, "detail": "" }, + { "kind": "missing_affordance", "draft": null, "quote": "I want to see the shape of that sound.", "detail": "" }, + { "kind": "unwritten", "draft": null, "quote": "I'll tell Meta I'm fine, more or less.", "detail": "" }, + ] }), + &[], + ), + json!({ "interpreter": { "room": MINDS, "said": [{ "room": MINDS, "text": text }], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "draft", "draft": 1, "words": text }] }, "posted": [{ "event": "40", "room": MINDS, "text": text }] }), + amended("a1", json!([{ "event": "$ev-1", "refusal": null }])), + amended("a1", json!([{ "event": "$ev-1", "refusal": "too_long" }])), + amended("zz", json!([])), + note(json!([{ "kind": "idea", "draft": 1, "about": null, "private": false }, { "kind": "idea", "draft": 2, "about": null, "private": false }])), + note(json!([{ "kind": "idea", "draft": 1, "about": null, "private": true }])), + json!({ "failed": "the provider failed the call: Overloaded" }), + broke, + ] +} + +#[test] +fn i16_10_every_lines_first_clause_is_what_its_receipt_says_reached_the_room() { + let her = packet().forms; + let mut rows = 0; + for record in every_row() { + let outcome = outcome_of(&record).unwrap(); + for part in &outcome.parts { + let quoted = |text: &str| spoken(text); + let (reached, rest) = (part.reached(her, "ed), part.rest(her, "ed)); + assert_eq!(part.line(her, usize::MAX, &[]), format!("- {reached}{rest}"), "{part:?}"); + // "{Room} has" only on a receipt that a line went out or was added to. + let receipt = matches!(part, Part::Said { .. } | Part::Promise { .. } | Part::Amended { .. }); + assert_eq!(reached.starts_with("#minds:gamecult.org has"), receipt, "{part:?}: {reached}"); + assert!(receipt || matches!(part, Part::NoteLeft(_)) || reached.starts_with("Nothing") || reached.starts_with("No "), "{part:?}: {reached}"); + for claim in ["Nothing reached", "reached the room", "reached anyone", " has, from", "now ending with", "went out"] { + assert!(!rest.contains(claim), "{part:?}: only the first clause says what reached the room: {rest}"); + } + rows += 1; + } + } + assert!(rows >= 16, "{rows}"); +} + +#[test] +fn no_row_says_as_her_own_recorded_as_queued_or_landed() { + for pronouns in ["she/her", "he/him", "any"] { + let her = crate::projection::select::forms(&json!({ "presentation": { "pronouns": pronouns } })); + for record in every_row() { + for line in outcome_of(&record).unwrap().lines(her) { + for banned in ["as her own", "as his own", "as their own", "recorded as", "queue", "landed"] { + assert!(!line.contains(banned), "{pronouns}: {banned} in {line}"); + } + } + } + } +} + +#[test] +fn a_quote_that_is_mostly_words_she_was_sent_this_turn_is_not_shown_to_the_projector() { + let said = "QUARTZ-HERON-SENTINEL is back at the door."; + let outcome = outcome_of(&record(&format!("{said}"), json!({ "say": [{ "draft": 1 }], "gaps": [] }), &[said])).unwrap(); + let her = packet().forms; + assert_eq!(outcome.line(0, her, usize::MAX, &["Heimdall, QUARTZ-HERON-SENTINEL is back at the door.".to_owned()]), "- #minds:gamecult.org has, from him: (words he had been sent)."); + assert_eq!(outcome.line(0, her, usize::MAX, &["Something else entirely, said today.".to_owned()]), format!("- #minds:gamecult.org has, from him: {}.", spoken(said)), "his own words are shown"); +} diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index 118fdfb..a42c1f7 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -306,6 +306,9 @@ pub(crate) struct Packet { pub clipped: Vec, /// The lines of hers she may add to this turn, for the Interpreter alone (map 16.17). pub amendable: Vec, + /// What came of her last turn that the outcome's guard left out, whole: counted in the packet's last outcome line and + /// reported here (map 16.20.5, I16.11), never shown to a model. + pub unshown: Vec, } /// A line of hers she may add to (map 16.17): one her last turn posted, or a `Said` line this packet shows, in the turn's @@ -1550,19 +1553,31 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { // the notes. let her = forms(inputs.state); let mut context = Context::new(guards(tuning, her), her); - // What came of her last turn, first and under its own guard, so nothing else can crowd it out. A line past the guard - // keeps its sentence and has its quote clipped, leaving each later line room for its sentence and the least quote: - // she is told every part, shortened when it must be. + let bodies: Vec = match inputs.kind { + TurnKind::Chat => inputs.room.messages.iter().map(|line| line.text.clone()).collect(), + TurnKind::Beat => beat_tail(inputs, tuning).iter().map(|line| line.text.clone()).collect(), + TurnKind::FollowUp | TurnKind::Reflection => Vec::new(), + }; + // What came of her last turn, first and under its own guard, so nothing else can crowd it out (map 16.20.5, I16.11). + // Quotes are clipped first: a line past the guard keeps its sentence and has its quote clipped, leaving each later + // line room for its sentence and the least quote. Whatever still does not fit is counted in a last line and reported + // (`unshown`), never dropped silently. No quote in it is mostly the words said to her this turn (I16.7). + let mut unshown: Vec = Vec::new(); if let Some(outcome) = &inputs.history.last { - let least: Vec = (0..outcome.len()).map(|at| outcome.line(at, her, OUTCOME_QUOTE_MIN).len() + 1).collect(); - for at in 0..outcome.len() { - let reserve: usize = least[at + 1..].iter().sum(); + let count = |more: usize| format!("- {more} more {} from {} last turn {} not shown here.", if more == 1 { "thing" } else { "things" }, her.poss, if more == 1 { "is" } else { "are" }); + let least: Vec = (0..outcome.len()).map(|at| outcome.line(at, her, OUTCOME_QUOTE_MIN, &bodies).len() + 1).collect(); + let room = context.room(Section::Outcome).saturating_sub(Section::Outcome.heading(her).len() + 1); + // The most parts, in order, whose least lines fit beside the count of the rest. + let shown = (0..=outcome.len()).rev().find(|&shown| least[..shown].iter().sum::() + if shown < outcome.len() { count(outcome.len() - shown).len() + 1 } else { 0 } <= room).unwrap_or(0); + let counted = if shown < outcome.len() { count(outcome.len() - shown).len() + 1 } else { 0 }; + for at in 0..shown { + let reserve: usize = least[at + 1..shown].iter().sum::() + counted; let past = |context: &Context, line: &str| (context.cost(Section::Outcome, line) + reserve).saturating_sub(context.room(Section::Outcome)); - let mut line = outcome.line(at, her, usize::MAX); + let mut line = outcome.line(at, her, usize::MAX, &bodies); let mut quote_max = line.len(); while past(&context, &line) > 0 && quote_max > OUTCOME_QUOTE_MIN { quote_max = quote_max.saturating_sub(past(&context, &line)).max(OUTCOME_QUOTE_MIN); - line = outcome.line(at, her, quote_max); + line = outcome.line(at, her, quote_max, &bodies); context.bound[Section::Outcome as usize] = true; if !clipped.iter().any(|id| id == "(outcome)") { clipped.push("(outcome)".to_owned()); @@ -1570,6 +1585,11 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { } context.push(Section::Outcome, line); } + if shown < outcome.len() { + context.bound[Section::Outcome as usize] = true; + context.push(Section::Outcome, count(outcome.len() - shown)); + unshown = (shown..outcome.len()).map(|at| outcome.line(at, her, usize::MAX, &bodies)).collect(); + } } let present = present_people(inputs, tuning); let present_ids: BTreeSet = present.iter().map(|(id, _)| id.clone()).collect(); @@ -1674,11 +1694,6 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { .enumerate() .map(|(at, (event, room, text))| Amendable { id: format!("a{}", at + 1), event: event.clone(), room: room.clone(), text: text.clone() }) .collect(); - let bodies = match inputs.kind { - TurnKind::Chat => inputs.room.messages.iter().map(|line| line.text.clone()).collect(), - TurnKind::Beat => beat_tail(inputs, tuning).iter().map(|line| line.text.clone()).collect(), - TurnKind::FollowUp | TurnKind::Reflection => Vec::new(), - }; let selected = taken.into_iter().map(|candidate| Pick { id: candidate.id, pool: candidate.pool, log_score: candidate.log_score }).collect(); - Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections: context.sizes(), stimulus, heard, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning), affordances: inputs.affordances.to_vec(), room: turn_room(inputs).map(str::to_owned), room_kind: turn_room(inputs).map_or(RoomKind::Public, |room| room_kind(inputs, room)), bodies, private, clipped, amendable, arrival, speaking: conversation.speaking.unwrap_or_default() } + Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections: context.sizes(), stimulus, heard, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning), affordances: inputs.affordances.to_vec(), room: turn_room(inputs).map(str::to_owned), room_kind: turn_room(inputs).map_or(RoomKind::Public, |room| room_kind(inputs, room)), bodies, private, clipped, amendable, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } } diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index 9772286..28b42cf 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -447,7 +447,7 @@ fn soul_k9_each_turn_opens_with_what_came_of_her_last_and_only_her_last() { assert!(!projected[0].contains("What came of his last turn:"), "a first turn has no last: {}", projected[0]); for (at, prompt) in projected.iter().enumerate().skip(1) { let (last, other) = (at, if at == 1 { 2 } else { 1 }); - assert!(prompt.contains(&format!("What came of his last turn:\n- He said in #minds:gamecult.org: \"line {last}\"\n- He reached for this;")), "turn {}: {prompt}", at + 1); + assert!(prompt.contains("What came of his last turn:\n- Nothing happened. He reached for something") && prompt.contains(&format!("\n- #minds:gamecult.org has, from him: \"line {last}\".\n")), "turn {}: {prompt}", at + 1); assert!(prompt.contains(&format!("In his thought: \"I want to see shape number {last} right now.\"")), "turn {}: {prompt}", at + 1); assert!(!prompt.contains(&format!("shape number {other}")), "turn {} carries only his last turn's: {prompt}", at + 1); } @@ -463,7 +463,7 @@ fn soul_k9_a_failed_turn_is_told_as_a_failure_next_turn() { let later: Vec<&Value> = run["turns"].as_array().unwrap().iter().filter(|turn| turn["round"].as_u64() > Some(1)).collect(); assert!(!later.is_empty(), "{}", run["turns"]); for turn in later { - assert_eq!(turn["report"]["last_outcome"]["told"], json!(["- Nothing came of his last moment: it broke off before anything happened, not by his choice."]), "{turn}"); + assert_eq!(turn["report"]["last_outcome"]["told"], json!(["- Nothing reached the room, and nothing he meant last time happened: the turn broke off, not by his choice."]), "{turn}"); } } @@ -508,7 +508,7 @@ fn soul_k10_an_amendment_keeps_the_line_whole_adds_her_words_and_wakes_no_one() let (_, unsent) = run_plan(&path, &correcting(false)); assert_eq!(turns(&run), turns(&unsent), "an edit wakes no one"); let third = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Tobiah" && turn["round"] == 3).expect("Meta's line wakes him in round 3"); - assert!(third["report"]["last_outcome"]["told"].as_array().unwrap().contains(&json!("- He added to what he said in #minds:gamecult.org: \"Couldn't send it after all; there's no way to yet.\"")), "{}", third["report"]["last_outcome"]); + assert!(third["report"]["last_outcome"]["told"].as_array().unwrap().contains(&json!("- #minds:gamecult.org has his line, now ending with: \"Couldn't send it after all; there's no way to yet.\". The rest of the line is as it was.")), "{}", third["report"]["last_outcome"]); } #[test] @@ -543,7 +543,7 @@ fn soul_k12_notes_to_self_are_collected_into_the_runs_inbox_and_told_as_left() { assert!(!inbox.is_empty() && inbox.iter().all(|note| note["mind"] == "eureka" && note["kind"] == "feedback" && note["about"] == "@meta:gamecult.org" && note["text"] == "Meta wants the kettle softer."), "{inbox:?}"); assert!(inbox[0]["key"].as_str().unwrap().starts_with("r1-t") && inbox[0]["key"].as_str().unwrap().ends_with("-s0"), "{inbox:?}"); let second = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Tobiah" && turn["round"] == 2).expect("Meta's line wakes him in round 2"); - assert!(second["report"]["last_outcome"]["told"].as_array().unwrap().contains(&json!("- He left a note for Self: \"Meta wants the kettle softer.\". It is in Self's inbox, for when Self next reads it.")), "{}", second["report"]["last_outcome"]); + assert!(second["report"]["last_outcome"]["told"].as_array().unwrap().contains(&json!("- He left Self a note: \"Meta wants the kettle softer.\". It waits in Self's inbox until Self reads it; nothing tells him when, and nothing in it happens by itself.")), "{}", second["report"]["last_outcome"]); let model = noting(); let harness = Harness { instance: "eureka".into(), persona: None, model: Some(&model), tuning: dir.path().join("persona-tuning.toml") }; let report = simulate(&harness, &path).unwrap(); diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index d266578..4bb3d6a 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -1946,7 +1946,7 @@ fn with_last(record: &Value) -> History { fn what_came_of_her_last_turn_opens_the_packet_under_its_own_guard() { let packet = packet_of(TurnKind::Chat, &state(), &chat_room(), &with_last(&last_turn("Sending the file now.")), 1); assert!( - packet.context.starts_with("What came of her last turn:\n- She said in #swarm:gamecult.org: \"Sending the file now.\"\n- She reached for this; there is no way to do it from a chat turn yet; it is recorded as a request. In her thought: \"I want to hear the kettle for myself.\"\nHere and now:\n"), + packet.context.starts_with("What came of her last turn:\n- Nothing happened. She reached for something she has no way to do from here, now or later, and it will not happen by itself. In her thought: \"I want to hear the kettle for myself.\". That she wanted it is kept in her record; no one has taken it up.\n- #swarm:gamecult.org has, from her: \"Sending the file now.\".\nHere and now:\n"), "{}", packet.context ); @@ -1958,9 +1958,9 @@ fn what_came_of_her_last_turn_opens_the_packet_under_its_own_guard() { assert!(tight_packet.context.starts_with(&packet.context[..packet.context.find("Here and now:").unwrap()]), "{}", tight_packet.context); // A line past its guard keeps its sentence, its quote clipped to the room left, and is reported. let long = packet_of(TurnKind::Chat, &state(), &chat_room(), &with_last(&last_turn(&"word ".repeat(400))), 1); - let first = long.context.lines().nth(1).unwrap(); - assert!(first.starts_with("- She said in #swarm:gamecult.org: \"word word") && first.ends_with("…\""), "{first}"); - assert!(long.context.lines().nth(2).unwrap().starts_with("- She reached for this;"), "the long line leaves the next its room: {}", long.context); + let said = long.context.lines().nth(2).unwrap(); + assert!(said.starts_with("- #swarm:gamecult.org has, from her: \"word word") && said.ends_with("…\"."), "{said}"); + assert!(long.context.lines().nth(1).unwrap().starts_with("- Nothing happened. She reached for something"), "the long line leaves the one before it its room: {}", long.context); assert!(long.clipped.contains(&"(outcome)".to_owned()) && long.sections.bound.contains(&"outcome"), "{:?} {:?}", long.clipped, long.sections.bound); within_guards(&long, &Tuning::default()); } @@ -2017,6 +2017,34 @@ fn soul_k13_the_projector_sees_who_said_something_and_never_the_words() { assert!(!tuning.projector.guidance.contains("retell"), "the retelling sentence is dead: the Projector never sees the words"); } +#[test] +fn k16_ten_parts_past_the_guard_are_counted_and_reported_never_dropped_silently() { + let refused: Vec = (0..10).map(|at| json!({ "draft": at + 3, "text": format!("{at} {}", "word ".repeat(60)), "reason": "over_lines", "why": "" })).collect(); + let record = json!({ "interpreter": { "room": "#swarm:gamecult.org", "said": [], "refused": refused, "gaps": [] }, "posted": [] }); + let packet = packet_of(TurnKind::Chat, &state(), &chat_room(), &with_last(&record), 1); + within_guards(&packet, &Tuning::default()); + let section: Vec<&str> = packet.context.lines().take_while(|line| *line != "Here and now:").collect(); + let shown = section.iter().filter(|line| line.starts_with("- Nothing of this reached")).count(); + let more = 10 - shown; + assert!(shown >= 1 && more >= 1, "{}", packet.context); + assert_eq!(section.last().copied(), Some(format!("- {more} more things from her last turn are not shown here.").as_str()), "{}", packet.context); + assert_eq!(packet.unshown.len(), more, "{:?}", packet.unshown); + assert!(packet.unshown.iter().all(|line| line.starts_with("- Nothing of this reached")), "{:?}", packet.unshown); + assert!(packet.sections.bound.contains(&"outcome")); +} + +#[test] +fn k16_i16_7_holds_over_the_whole_projector_prompt_outcome_included() { + const SENTINEL: &str = "QUARTZ-HERON-SENTINEL is back at the door"; + let room = Room { messages: vec![message("#swarm:gamecult.org", "@libby:gamecult.org", "Libby", &format!("Eureka, {SENTINEL}."), 3, true)], here: Some("#swarm:gamecult.org".into()), ..Room::default() }; + // Her last turn said a draft that repeated it, and a reach quoted it in her thought. + let record = json!({ "interpreter": { "room": "#swarm:gamecult.org", "said": [{ "room": "#swarm:gamecult.org", "text": format!("{SENTINEL}!") }], "refused": [], "gaps": [{ "kind": "unwritten", "from": "thought", "words": format!("{SENTINEL}.") }] }, "posted": [{ "event": "e1", "room": "#swarm:gamecult.org", "text": format!("{SENTINEL}!") }] }); + let packet = packet_of(TurnKind::Chat, &state(), &room, &with_last(&record), 1); + let projector = narrate::projector_prompt(&packet, &Tuning::default()); + assert!(!projector.contains("QUARTZ-HERON-SENTINEL"), "{projector}"); + assert!(projector.contains("- #swarm:gamecult.org has, from her: (words she had been sent).") && projector.contains("In her thought: (words she had been sent)."), "{projector}"); +} + #[test] fn k15_the_speaking_cues_reach_the_persona_and_the_interpreter_and_never_the_projector() { let waiting = Room { messages: vec![message("#swarm:gamecult.org", OPERATOR, "Meta", "Eureka, are you around?", 2, true), message("#swarm:gamecult.org", "@kiko:gamecult.org", "Kiko", "hi", 1, false)], here: Some("#swarm:gamecult.org".into()), ..Room::default() }; diff --git a/crates/mind-body/src/projection/tuning.rs b/crates/mind-body/src/projection/tuning.rs index 44ae9bd..38b9a2d 100644 --- a/crates/mind-body/src/projection/tuning.rs +++ b/crates/mind-body/src/projection/tuning.rs @@ -226,7 +226,7 @@ impl Default for SelectTuning { inclusion_score: 0.5, notes_bytes: 5120, here_bytes: 768, - outcome_bytes: 800, + outcome_bytes: 1200, stimulus_bytes: 1500, heard_bytes: 1500, addressed_bytes: 8 * 1024,