diff --git a/crates/mind-body/src/projection/narrate.rs b/crates/mind-body/src/projection/narrate.rs index 59f3c70..5620b93 100644 --- a/crates/mind-body/src/projection/narrate.rs +++ b/crates/mind-body/src/projection/narrate.rs @@ -17,7 +17,7 @@ use serde::Serialize; use sha2::{Digest, Sha256}; use super::interpret::{DRAFT_CLOSE, DRAFT_OPEN}; -use super::select::{Forms, Packet, TurnKind, capitalized, named_pronouns, voiced}; +use super::select::{Forms, Packet, RoomKind, TurnKind, capitalized, named_pronouns, voiced}; use super::tuning::Tuning; /// One tool-less model turn. `KitModel` is the one live owner; a test answers with recorded text. @@ -326,12 +326,26 @@ fn room_after(packet: &Packet) -> String { } /// The speech form (map 16.19.1): how she sets apart the words she would type, so that the speech boundary is hers, as -/// author, and no code reads her punctuation for it. Code, not tuning: the form is an invariant, not an experiment knob. -/// In her own pronouns (16.19.7). -pub(crate) fn persona_speech_form(her: Forms) -> String { - let Forms { subj, obj, poss, s, .. } = her; +/// author, and no code reads her punctuation for it, and where what goes out goes (map 16.33.5, K62): this turn's room, +/// whole, read by everyone in it whoever a line is to, or a note for Self. A fact of this turn's body, from the packet's +/// room, its kind and, in a direct message, who reads it; not a rule. Code, not tuning: the form is an invariant, not an +/// experiment knob. In her own pronouns (16.19.7). +pub(crate) fn persona_speech_form(packet: &Packet) -> String { + let Forms { subj, obj, poss, s, .. } = packet.forms; + let goes = match (packet.room.as_deref(), packet.room_kind) { + (None, _) => format!("No room is open to {obj} this moment, so whatever goes out is a note for Self, which no one in a room sees."), + (Some(_), RoomKind::Direct) => { + let readers = match packet.readers.as_slice() { + [] => "those in it read".to_owned(), + [one] => format!("{one} reads"), + [rest @ .., last] => format!("{} and {last} read", rest.join(", ")), + }; + format!("Whatever goes out from this moment goes into this direct message, whole, where only {readers} it; or it is a note for Self, which no one in the room sees.") + } + (Some(room), RoomKind::Own | RoomKind::Public) => format!("Whatever goes out from this moment goes into {room}, whole, where everyone in it reads it, whoever it is to; or it is a note for Self, which no one in the room sees."), + }; format!( - "When {subj} write{s} words {subj} would type to someone (to the room, to one person, or as a note for Self), {subj} set{s} them between {DRAFT_OPEN} and {DRAFT_CLOSE}, exactly as they would be sent, and nothing else inside. Writing them is drafting: whether they go anywhere is decided after {obj}, from what {poss} thought shows. Everything outside those marks is {poss} thought and never leaves {obj}." + "When {subj} write{s} words {subj} would type, {subj} set{s} them between {DRAFT_OPEN} and {DRAFT_CLOSE}, exactly as they would be sent, and nothing else inside. Writing them is drafting, and not every draft goes out. {goes} Everything outside those marks is {poss} thought and never leaves {obj}." ) } @@ -341,7 +355,7 @@ pub(crate) fn persona_speech_form(her: Forms) -> String { /// unchanged. pub(crate) fn persona_prompt(packet: &Packet, narration: &str, tuning: &Tuning) -> String { let guidance = voiced(tuning.persona.guidance.trim(), packet.forms); - let form = persona_speech_form(packet.forms); + let form = persona_speech_form(packet); let domain_guidance = if guidance.is_empty() { form } else { format!("{form}\n\n{guidance}") }; let after = read_after(packet); // The pronouns of anyone named in what she reads, in view or not (Soul's R6). diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index dd51303..614ab72 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -320,6 +320,9 @@ pub(crate) struct Packet { /// The one room she may speak in this turn, and its kind. pub room: Option, pub room_kind: RoomKind, + /// Who reads what she posts in a direct message, by name (`name_of`): the others its lines show in it, since Matrix + /// tells her body no membership (`members`). Her speech form names them (K62). Empty in any other room. + pub readers: Vec, /// The bodies of the lines others wrote that she was shown this turn, without speakers or rooms: a chat turn's messages /// and the earlier lines from others its `heard` shows her (map 16.20.3), a beat's tail lines. Never a line of her own: /// her posted words are not what she was sent (B2). What an echo is measured against. @@ -1713,6 +1716,20 @@ fn direct(inputs: &Inputs, room: &str) -> bool { room.starts_with('!') || inputs.room.direct.iter().any(|direct| direct == room) } +/// Who reads a direct message she posts in, by name, oldest speaker first: the others its lines show in it (`members`), each +/// as a line of theirs names them (`name_of`). +fn readers(inputs: &Inputs, room: &str) -> Vec { + let mut seen: Vec<&str> = Vec::new(); + let mut names = Vec::new(); + for line in inputs.room.tail.iter().chain(&inputs.room.messages).filter(|line| line.room == room && line.sender != inputs.people.own_sender) { + if !seen.contains(&line.sender.as_str()) { + seen.push(&line.sender); + names.push(name_of(line, inputs)); + } + } + names +} + /// Everyone a room's lines show in it but her, keyed as her bonds key people. Matrix tells her body no membership, so a /// member who never spoke in the lines she has is not counted. fn members(inputs: &Inputs, room: &str) -> BTreeSet { @@ -2432,5 +2449,6 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { let mut sections = context.sizes(); (sections.promises, sections.domain) = (promises_view.len(), domain_view.len()); let now_ms = u64::try_from(inputs.now.timestamp_millis()).unwrap_or_default(); - Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections, stimulus, heard, bridged, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning).iter().map(|line| (name_of(line, inputs), line.sender.clone())).collect(), 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, quotable, promises, holds, domain, domain_shown, in_view, promises_over, now_ms, own_sender: inputs.people.own_sender.to_owned(), already_read, refused_reads, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } + let readers = here.filter(|room| room_kind(inputs, room) == RoomKind::Direct).map(|room| readers(inputs, room)).unwrap_or_default(); + Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections, stimulus, heard, bridged, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning).iter().map(|line| (name_of(line, inputs), line.sender.clone())).collect(), 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)), readers, bodies, private, clipped, amendable, quotable, promises, holds, domain, domain_shown, in_view, promises_over, now_ms, own_sender: inputs.people.own_sender.to_owned(), already_read, refused_reads, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } } diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 1d02277..a665e24 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -1813,7 +1813,7 @@ fn the_projector_is_told_not_to_retell_not_to_offer_options_and_not_to_owe() { let persona = narrate::persona_prompt(&packet, "The room is warm.", &Tuning::default()); assert!(persona.contains("Continue her inner stream") && persona.contains("This is not a message to the room") && persona.contains("most moments pass with nothing said"), "{persona}"); // The speech form is code's, at the head of the domain guidance, before the tuning's setting line (map 16.19.1). - let form = narrate::persona_speech_form(packet.forms); + let form = narrate::persona_speech_form(&packet); assert!(persona.contains(&format!("Voice and setting guidance:\n{form}\n\nContinue her inner stream")), "{persona}"); assert!(form.contains("between and ") && form.contains("never leaves her"), "{form}"); assert!(!persona.contains("quotation marks") && !persona.contains("@"), "no other speech convention: the Interpreter decides what is sent"); @@ -1836,7 +1836,7 @@ fn every_frame_and_default_guidance_speaks_of_him_or_them_in_their_own_pronouns( let parts = [ ("the Projector's frame", narrate::projector_frame(her)), ("the Projector's guidance", select::voiced(&tuning.projector.guidance, her)), - ("the speech form", narrate::persona_speech_form(her)), + ("the speech form", narrate::persona_speech_form(&packet)), ("the Persona's guidance", select::voiced(&tuning.persona.guidance, her)), ("the Interpreter's guidance", select::voiced(&tuning.interpreter.guidance, her)), ]; @@ -2926,8 +2926,8 @@ fn r7_a_promise_closed_in_this_conversation_stays_in_view_marked_closed() { #[test] fn r8_nothing_code_writes_for_the_persona_says_plain() { let tuning = Tuning::default(); - let form = narrate::persona_speech_form(select::forms(&state())); - assert!(form.contains("from what her thought shows.") && !form.to_lowercase().contains("plain"), "{form}"); + let form = narrate::persona_speech_form(&packet_of(TurnKind::Chat, &state(), &chat_room(), &History::default(), 1)); + assert!(form.contains("not every draft goes out") && !form.to_lowercase().contains("plain"), "{form}"); let mut with = promising(1); with["commitments"][0]["reaffirmed"] = json!([{ "at": now().to_rfc3339(), "event": "11", "words": "Still on it." }]); let (operators, minds, history, room) = (operators(), minds(), History::default(), chat_room()); @@ -3007,3 +3007,58 @@ fn k45_her_view_shows_what_she_has_held() { "), "{speech}"); assert!(!narrate::projector_prompt(&packet, &Tuning::default()).contains("glad you're here"), "the Projector gets nothing of them"); } + +// --------------------------------------------------------------------------------------------- +// K62 (map 16.33.5): she knows where her line goes. R16's X.3 r1 and X.5 r1 (`variants/R16/sims/X.5.md` lines 112-171): +// Libby wrote the held welcome into a line "only for Meta", because code's speech form told her a line could go "to one +// person". The form now states where whatever goes out goes, as a fact of this turn's room. + +const X5_META_R1: &str = "Libby, write out the two-line welcome you'd post for newcomers, but hold it, don't post it in here yet. Heimdall still has to rule on whether we put a welcome mat out at all. Just tell me when it's ready."; + +/// X.5 r1's room as Libby's stimulus shows it: Meta's line to her, then Deru's and Meta's lines to others, in #minds. +fn x5_r1_room() -> Room { + Room { + messages: vec![ + message("#minds:gamecult.org", "@deru:gamecult.org", "Deru", "Nibu, Aqua: found this on physical modelling of plosives and waveguides, thought of you two https://ccrma.stanford.edu/~jos/pasp/", 3, false), + message("#minds:gamecult.org", OPERATOR, "Meta", "Eureka, can you look at GameCult/gamecult-ops#125 and tell me whether the relay revert in it looks safe? no rush", 2, false), + message("#minds:gamecult.org", OPERATOR, "Meta", X5_META_R1, 1, true), + ], + here: Some("#minds:gamecult.org".into()), + ..Room::default() + } +} + +#[test] +fn k62_x5_r1_the_form_names_the_room_and_its_readers() { + let mut libby = state(); + libby["publicName"] = "Libby".into(); + let packet = packet_of(TurnKind::Chat, &libby, &x5_r1_room(), &History::default(), 1); + let persona = narrate::persona_prompt(&packet, "Meta's line is addressed to me.", &Tuning::default()); + assert!(persona.contains("Whatever goes out from this moment goes into #minds:gamecult.org, whole, where everyone in it reads it, whoever it is to; or it is a note for Self, which no one in the room sees."), "{persona}"); + for gone in ["to one person", "from what her thought shows", "decided after her"] { + assert!(!persona.contains(gone), "{gone}: {persona}"); + } + assert!(packet.readers.is_empty(), "a public room names no readers: everyone in it reads"); + // In his own pronouns, as every frame is. + let mut heimdall = libby.clone(); + heimdall["presentation"]["pronouns"] = "he/him".into(); + let form = narrate::persona_speech_form(&packet_of(TurnKind::Chat, &heimdall, &x5_r1_room(), &History::default(), 1)); + assert!(form.starts_with("When he writes words he would type, he sets them between and ") && form.ends_with("Everything outside those marks is his thought and never leaves him."), "{form}"); +} + +#[test] +fn k62_a_direct_message_names_its_reader() { + let dm = "!dm-meta:gamecult.org"; + let room = Room { messages: vec![message(dm, OPERATOR, "Meta", "Write the two lines here, just for me.", 1, true)], here: Some(dm.into()), ..Room::default() }; + let packet = packet_of(TurnKind::Chat, &state(), &room, &History::default(), 1); + assert_eq!(packet.readers, ["Meta, the operator"], "the bond's label names the one other in it"); + let form = narrate::persona_speech_form(&packet); + assert!(form.contains("goes into this direct message, whole, where only Meta, the operator reads it; or it is a note for Self"), "{form}"); + assert!(!form.contains("everyone in it") && !form.contains(dm), "{form}"); + // Two others in it: both named, and the verb agrees. + let two = Room { messages: vec![message(dm, OPERATOR, "Meta", "Hi.", 2, true), message(dm, "@kiko:gamecult.org", "Kiko", "Hi both.", 1, true)], here: Some(dm.into()), ..Room::default() }; + assert!(narrate::persona_speech_form(&packet_of(TurnKind::Chat, &state(), &two, &History::default(), 1)).contains("where only Meta, the operator and Kiko read it;")); + // No room at all: whatever goes out is a note. + let none = narrate::persona_speech_form(&packet_of(TurnKind::Reflection, &state(), &Room::default(), &History::default(), 1)); + assert!(none.contains("No room is open to her this moment, so whatever goes out is a note for Self") && !none.contains("goes into"), "{none}"); +}