diff --git a/crates/mind-body/fixtures/harness/outcomes/conditional.json b/crates/mind-body/fixtures/harness/outcomes/conditional.json index 0fe85e9..a432917 100644 --- a/crates/mind-body/fixtures/harness/outcomes/conditional.json +++ b/crates/mind-body/fixtures/harness/outcomes/conditional.json @@ -1,6 +1,7 @@ { "interpreter": { "room": "!dm-meta:gamecult.org", + "heard": ["hey you. I missed talking to you this week. how are you, really? and no, \"busy\" doesn't count as an answer, I know where you live"], "said": [], "refused": [], "gaps": [{ "kind": "conditional", "from": "draft", "draft": 1, "words": "Honestly? Tired. Good tired, mostly.", "detail": "only if she asks again" }] diff --git a/crates/mind-body/fixtures/harness/outcomes/missing-affordance.json b/crates/mind-body/fixtures/harness/outcomes/missing-affordance.json index 8067bf6..6219546 100644 --- a/crates/mind-body/fixtures/harness/outcomes/missing-affordance.json +++ b/crates/mind-body/fixtures/harness/outcomes/missing-affordance.json @@ -1,6 +1,7 @@ { "interpreter": { "room": "!dm-meta:gamecult.org", + "heard": ["hey you. I missed talking to you this week. how are you, really? and no, \"busy\" doesn't count as an answer, I know where you live"], "said": [], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "thought", "words": "I want to show her the render, not describe it.", "start_byte": 0, "end_byte": 48, "detail": "no way to attach a file" }] diff --git a/crates/mind-body/fixtures/harness/outcomes/posted.json b/crates/mind-body/fixtures/harness/outcomes/posted.json index 012dba5..c0f5dee 100644 --- a/crates/mind-body/fixtures/harness/outcomes/posted.json +++ b/crates/mind-body/fixtures/harness/outcomes/posted.json @@ -1,6 +1,7 @@ { "interpreter": { "room": "!dm-meta:gamecult.org", + "heard": ["hey you. I missed talking to you this week. how are you, really? and no, \"busy\" doesn't count as an answer, I know where you live"], "said": [{ "room": "!dm-meta:gamecult.org", "text": "Missed you too. I'll send the render tonight.", "mentions": [], "reply_to": null, "rests_on": { "draft": 1, "start_byte": 9, "end_byte": 54 } }], "refused": [], "gaps": [] diff --git a/crates/mind-body/fixtures/harness/outcomes/refused.json b/crates/mind-body/fixtures/harness/outcomes/refused.json index a264646..6cdcc9c 100644 --- a/crates/mind-body/fixtures/harness/outcomes/refused.json +++ b/crates/mind-body/fixtures/harness/outcomes/refused.json @@ -1,6 +1,7 @@ { "interpreter": { "room": "!dm-meta:gamecult.org", + "heard": ["hey you. I missed talking to you this week. how are you, really? and no, \"busy\" doesn't count as an answer, I know where you live"], "said": [], "refused": [{ "draft": 1, "text": "I know where you live, and busy doesn't count as an answer.", "reason": "echo", "why": "mostly words she heard: an echo, not her speech" }], "gaps": [] diff --git a/crates/mind-body/src/bin/mind-persona.rs b/crates/mind-body/src/bin/mind-persona.rs index ae95f49..088b098 100644 --- a/crates/mind-body/src/bin/mind-persona.rs +++ b/crates/mind-body/src/bin/mind-persona.rs @@ -88,7 +88,8 @@ fn credential(name: &str) -> Result { std::fs::read_to_string(required(name)?).with_context(|| format!("the file named by {name} could not be read")) } -/// A turn record from a file (`--last-outcome`): JSON, the shape `project` reads what came of her last turn from. +/// A turn record from a file (`--last-outcome`): JSON, the shape `project` reads what came of her last turn from. A record +/// whose decision carries no `heard` has every quote in her outcome withheld. fn record_file(path: &Path) -> Result { let text = std::fs::read_to_string(path).with_context(|| format!("{} could not be read", path.display()))?; serde_json::from_str(&text).with_context(|| format!("{} is not JSON", path.display())) diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index e38e2b5..0c2a290 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -82,8 +82,9 @@ pub(crate) struct Outcome { pub omitted: Vec, pub posted: Vec, /// The bodies of the lines she was shown on the turn the record is from (the decision's `heard`): no quote she is - /// told repeats a run of them (`line`). - heard: Vec, + /// told repeats a run of them (`line`). None when the record does not carry them (a record older than the field, a + /// hand-made one): then what she was sent is unknown, and every quote is withheld. + heard: Option>, } fn words(value: &Value) -> Option { @@ -117,7 +118,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { return Some(outcome); } let room = words(&decision["room"]); - outcome.heard = decision["heard"].as_array().into_iter().flatten().filter_map(|body| body.as_str().map(str::to_owned)).collect(); + outcome.heard = decision["heard"].as_array().map(|heard| heard.iter().filter_map(|body| body.as_str().map(str::to_owned)).collect()); // A draft refused as an echo is shown by no row: the echo's line quotes none of it, and a gap naming it quotes nothing. let echoes: Vec<&Value> = decision["refused"].as_array().into_iter().flatten().filter(|refusal| refusal["reason"] == "echo").map(|refusal| &refusal["draft"]).collect(); let mut receipts: Vec = Vec::new(); @@ -301,9 +302,11 @@ impl Part { /// this turn (`sent`), is shown as "(her words, not shown here)" (`repeats`, `WITHHELD`), so no one else's words /// reach the Projector through her outcome (16.20.4, I16.7). The rest of the line is told as it is: a withheld /// promise is still told as a promise she has no way to keep, which she can add to. - fn line(&self, her: Forms, quote_max: usize, heard: &[String], sent: &[String]) -> String { - let sent: Vec<&str> = heard.iter().chain(sent).map(String::as_str).collect(); - let quoted = |text: &str| if repeats(text, &sent) { withheld(her) } else { spoken(&clip(text, quote_max)) }; + /// + /// A record that does not say what she was sent on its turn (`heard` None) fails closed: every quote is withheld. + fn line(&self, her: Forms, quote_max: usize, heard: Option<&[String]>, sent: &[String]) -> String { + let sent: Vec<&str> = heard.into_iter().flatten().chain(sent).map(String::as_str).collect(); + let quoted = |text: &str| if heard.is_none() || repeats(text, &sent) { withheld(her) } else { spoken(&clip(text, quote_max)) }; format!("- {}{}", self.reached(her, "ed), self.rest(her, "ed)) } } @@ -351,7 +354,7 @@ impl Outcome { /// The `at`th line she is told, its quotes held to `quote_max` bytes, none repeating a run of the words she was sent /// on the record's turn or this one (`sent`, this turn's bodies). pub(crate) fn line(&self, at: usize, her: Forms, quote_max: usize, sent: &[String]) -> String { - self.parts[at].line(her, quote_max, &self.heard, sent) + self.parts[at].line(her, quote_max, self.heard.as_deref(), sent) } /// Every line she is told, whole: the report's. diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 16aa909..cdeb934 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -63,11 +63,11 @@ fn each_gap_is_told_by_its_kind_with_a_draft_as_written_and_a_thought_as_thought #[test] 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 promise = json!({ "interpreter": { "heard": [], "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": [] }); + let unsent = json!({ "interpreter": { "heard": [], "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"); } @@ -76,7 +76,7 @@ fn a_promise_is_told_as_the_room_having_it_and_what_will_not_happen_by_itself() #[test] fn a_promise_in_a_said_line_with_no_matching_receipt_is_not_told_as_nothing_happening() { let text = "I'll send it tonight."; - let promise = |posted: Value| json!({ "interpreter": { "room": MINDS, "said": [{ "room": MINDS, "text": text }], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "draft", "draft": 1, "words": text }] }, "posted": posted }); + let promise = |posted: Value| json!({ "interpreter": { "heard": [], "room": MINDS, "said": [{ "room": MINDS, "text": text }], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "draft", "draft": 1, "words": text }] }, "posted": posted }); let (lines, omitted) = told(&promise(json!([{ "event": "40", "room": MINDS, "text": "I'll send it tonight!" }]))); assert_eq!(lines, ["- #minds:gamecult.org has, from him: \"I'll send it tonight!\"."], "the receipt alone"); assert!(omitted.len() == 2 && omitted[1].starts_with("a promise in a line said with no receipt"), "{omitted:?}"); @@ -214,7 +214,7 @@ fn every_row() -> Vec { ] }), &[], ), - 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 }] }), + json!({ "interpreter": { "heard": [], "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!([])), @@ -234,7 +234,7 @@ fn i16_10_every_lines_first_clause_is_what_its_receipt_says_reached_the_room() { 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:?}"); + assert_eq!(part.line(her, usize::MAX, Some(&[]), &[]), 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}"); @@ -304,3 +304,24 @@ fn a_withheld_quote_claims_nothing_about_where_its_words_came_from() { let they = Forms { subj: "they", cap_subj: "They", obj: "them", poss: "their", ..her }; assert_eq!(said.line(0, they, usize::MAX, "ed_back), "- #minds:gamecult.org has, from them: (their words, not shown here)."); } + +/// Soul at 964ee50: a record without `heard` (older than the field, or a `--last-outcome` fixture) let every quote +/// through unchecked against what its turn was sent. What she was sent is then unknown, so every quote is withheld. +#[test] +fn a_record_that_does_not_say_what_its_turn_heard_withholds_every_quote() { + let prose = "Back at the kettle. Fine, you win. I want to see the shape of that sound."; + let gaps = json!([{ "kind": "conditional", "draft": 2, "quote": null, "detail": "" }, { "kind": "missing_affordance", "draft": null, "quote": "I want to see the shape of that sound.", "detail": "" }]); + let mut record = record(prose, json!({ "say": [{ "draft": 1 }], "gaps": gaps }), &["Back at the kettle."]); + let (shown, _) = told(&record); + assert!(shown.iter().any(|line| line.contains("\"Back at the kettle.\"")) && shown.iter().any(|line| line.contains("\"Fine, you win.\"")) && shown.iter().any(|line| line.contains("\"I want to see the shape of that sound.\"")), "with `heard`, his words are shown: {shown:?}"); + record["interpreter"].as_object_mut().unwrap().remove("heard"); + let (withheld, omitted) = told(&record); + assert_eq!(withheld.len(), shown.len(), "every row is still told: {withheld:?}"); + assert_eq!(withheld.iter().map(|line| line.matches("(his words, not shown here)").count()).sum::(), 3, "{withheld:?}"); + for words in ["kettle", "Fine, you win", "shape of that sound"] { + assert!(withheld.iter().all(|line| !line.contains(words)), "{words}: {withheld:?}"); + } + assert!(omitted.is_empty(), "{omitted:?}"); + record["interpreter"]["heard"] = json!([]); + assert_eq!(told(&record).0, shown, "an empty `heard` says the turn heard nothing"); +} diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index c1ce0be..ce87354 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -1937,7 +1937,7 @@ fn what_she_said_in_a_direct_message_stays_in_it() { /// A record of her last turn: one line that went out in #swarm, and a reach for what her body cannot do. fn last_turn(said: &str) -> Value { json!({ - "interpreter": { "room": "#swarm:gamecult.org", "said": [{ "room": "#swarm:gamecult.org", "text": said }], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "thought", "words": "I want to hear the kettle for myself." }] }, + "interpreter": { "heard": [], "room": "#swarm:gamecult.org", "said": [{ "room": "#swarm:gamecult.org", "text": said }], "refused": [], "gaps": [{ "kind": "missing_affordance", "from": "thought", "words": "I want to hear the kettle for myself." }] }, "posted": [{ "event": "said-last", "room": "#swarm:gamecult.org", "text": said }], }) } @@ -1971,7 +1971,7 @@ fn what_came_of_her_last_turn_opens_the_packet_under_its_own_guard() { #[test] fn a_chosen_silence_opens_no_section_and_no_record_none() { - let silence = json!({ "interpreter": { "room": "#swarm:gamecult.org", "said": [], "refused": [], "gaps": [] }, "posted": [] }); + let silence = json!({ "interpreter": { "heard": [], "room": "#swarm:gamecult.org", "said": [], "refused": [], "gaps": [] }, "posted": [] }); for history in [with_last(&silence), History::default()] { let packet = packet_of(TurnKind::Chat, &state(), &chat_room(), &history, 1); assert!(packet.context.starts_with("Here and now:\n"), "{}", packet.context); @@ -1988,7 +1988,7 @@ fn her_last_turns_line_is_the_outcomes_and_not_the_said_pools() { #[test] fn what_she_may_add_to_is_her_last_turns_lines_and_the_said_lines_shown_in_this_room_only() { - let record = json!({ "interpreter": { "room": "#swarm:gamecult.org", "said": [], "refused": [], "gaps": [] }, "posted": [ + let record = json!({ "interpreter": { "heard": [], "room": "#swarm:gamecult.org", "said": [], "refused": [], "gaps": [] }, "posted": [ { "event": "ev-here", "room": "#swarm:gamecult.org", "text": "I'll send it." }, { "event": "ev-there", "room": "#elsewhere:gamecult.org", "text": "Elsewhere line." }, ] }); @@ -2024,7 +2024,7 @@ fn soul_k13_the_projector_sees_who_said_something_and_never_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 record = json!({ "interpreter": { "heard": [], "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(); @@ -2091,8 +2091,8 @@ fn a_quote_repeating_part_of_what_she_was_sent_is_withheld_from_the_record_turn_ let elsewhere = Room { messages: vec![message("#swarm:gamecult.org", OPERATOR, "Meta", "Eureka, you there?", 1, true)], here: Some("#swarm:gamecult.org".into()), ..Room::default() }; let projector = narrate::projector_prompt(&packet_of(TurnKind::Chat, &state(), &elsewhere, &with_last(&record), 1), &Tuning::default()); assert!(!projector.contains(S) && projector.contains("has, from her: (her words, not shown here)."), "{projector}"); - // A record without them, and Libby's words this turn. - let record = json!({ "interpreter": { "room": "#swarm:gamecult.org", "said": [{ "room": "#swarm:gamecult.org", "text": said }], "refused": [], "gaps": [] }, "posted": posted }); + // A record whose turn heard nothing of them, and Libby's words this turn. + let record = json!({ "interpreter": { "room": "#swarm:gamecult.org", "said": [{ "room": "#swarm:gamecult.org", "text": said }], "refused": [], "gaps": [], "heard": [] }, "posted": posted }); let here = Room { messages: vec![libby], here: Some("#swarm:gamecult.org".into()), ..Room::default() }; assert!(!narrate::projector_prompt(&packet_of(TurnKind::Chat, &state(), &here, &with_last(&record), 1), &Tuning::default()).contains(S)); // Her own words, sharing no run of three, are shown.