diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 034c023..aae09fb 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -44,7 +44,7 @@ use super::Affordance; use super::commit::{Evidence, How, Proposal}; use super::read::{Asked, Kind, QUOTE_MIN_WORDS, ReadRequest, SPAN_MIN_WORDS, resolve}; use super::narrate::{Model, heard_overlap, lived_stream, words}; -use super::select::{Forms, Packet, capitalized, spoken, turn_words, voiced}; +use super::select::{Forms, Packet, capitalized, named_pronouns, spoken, turn_words, voiced}; use super::tuning::Tuning; /// The most lines she says in one turn. @@ -465,6 +465,9 @@ pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tu // Her earlier segments this wake, already decided on: context, never hers to send again. let before = if before.is_empty() { String::new() } else { format!("Earlier in {} moment, already decided on (any draft in it is gone by):\n{before}\n\n", her.poss) }; let tail = format!("{reading}{}", speech_frame_tail(her)); + // The pronouns of anyone her prose names, in view or not (Soul's R6, E r6). + let named = named_pronouns(&format!("{before}\n{prose}"), tuning, &packet.own_sender); + let people = if named.is_empty() { people } else { format!("{people}Pronouns of the people {} prose names:\n{}\n", her.poss, named.iter().map(|line| format!("- {line}\n")).collect::()) }; format!( "{}\n\n{guidance}{}\n\nWho {} {}:\n{}\n\nWhat {} can do here:\n{}.\n\nThe room: {} ({}).\n{conversation}Who is in it, as label \u{2014} Matrix id:\n{people}\nWhat {} know{} privately, none of it to be said here:\n{private}\nLines in this room {} may reply to, as id \u{2014} who: line:\n{quotable}\n{poss} own lines in this room that {} may add to, as id \u{2014} line:\n{amendable}\n{poss} open promises, as id \u{2014} to whom: words:\n{promises}\n{domain}What reached {}:\n{}\n\n{poss} lived moment:\n{}\n\n{before}{poss} prose:\n{prose}\n\n{poss} drafts, by number:\n{numbered}", speech_frame_head(her), diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index bf6df77..303cf14 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -876,3 +876,14 @@ fn r6_a_read_is_anchored_only_where_her_thought_names_it() { let named = asked(&reading, "I want to see what Nibu changed in Lodur.", json!({ "kind": "domain", "target": "d1", "quote": "I want to see what" })); assert_eq!(named["read"]["quote"], "I want to see what", "{named}"); } + +/// Soul's R6 (E r6, Eureka said "him" for Kiko): the Interpreter and the Persona get the pronouns of anyone named, from +/// the tuning's table, not only the people in view. +#[test] +fn r6_anyone_named_gets_their_pronouns_in_view_or_not() { + let prose = "Kiko asked if it went out, which tells me something I said left her expecting it."; + let speech = speech_prompt(&packet(), "x", prose, &Tuning::default()); + assert!(speech.contains("Pronouns of the people his prose names:\n- Kiko \u{2014} she/her\n") && !speech.contains("Heimdall \u{2014}"), "{speech}"); + let persona = crate::projection::narrate::persona_prompt(&packet(), "Kiko is waiting on the file.", &Tuning::default()); + assert!(persona.contains("Pronouns of the people named here:") && persona.contains("Kiko \u{2014} she/her"), "{persona}"); +} diff --git a/crates/mind-body/src/projection/narrate.rs b/crates/mind-body/src/projection/narrate.rs index 803827f..2ce1320 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, voiced}; +use super::select::{Forms, Packet, 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. @@ -343,7 +343,11 @@ pub(crate) fn persona_prompt(packet: &Packet, narration: &str, tuning: &Tuning) let guidance = voiced(tuning.persona.guidance.trim(), packet.forms); let form = persona_speech_form(packet.forms); let domain_guidance = if guidance.is_empty() { form } else { format!("{form}\n\n{guidance}") }; - build_persona_prompt(&PersonaPrompt { identity: &packet.name, lived_stream: &lived_stream(narration, &read_after(packet)), domain_guidance: &domain_guidance, word_budget: tuning.persona.words }) + let after = read_after(packet); + // The pronouns of anyone named in what she reads, in view or not (Soul's R6). + let named = named_pronouns(&format!("{narration}\n{after}"), tuning, &packet.own_sender); + let domain_guidance = if named.is_empty() { domain_guidance } else { format!("{domain_guidance}\n\nPronouns of the people named here: {}.", named.join("; ")) }; + build_persona_prompt(&PersonaPrompt { identity: &packet.name, lived_stream: &lived_stream(narration, &after), domain_guidance: &domain_guidance, word_budget: tuning.persona.words }) } /// The share of the narration's word trigrams that also appear in what she heard: a lexical overlap, cheap and blind to diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index eaca4d1..8afd924 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -349,6 +349,8 @@ pub(crate) struct Packet { pub promises_over: bool, /// When the turn is, unix ms: when the lines she posts this turn were written, for the outcome guard (map 16.23.4). pub now_ms: u64, + /// Her own Matrix id: her pronouns are not listed among the people named (`named_pronouns`). + pub own_sender: String, /// 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, @@ -1558,6 +1560,13 @@ fn people_in_view(inputs: &Inputs, tuning: &Tuning) -> Vec<(String, String)> { people } +/// The pronouns of everyone `text` names by a handle (`Kiko`), from the tuning's table: anyone named, not only the +/// people in view (Soul's R6, E r6: "Kiko … I've told him"). Hers are not listed. `Kiko — she/her`, in the table's order. +pub(crate) fn named_pronouns(text: &str, tuning: &Tuning, own: &str) -> Vec { + let tokens: BTreeSet = text.split(|c: char| !c.is_alphanumeric()).filter(|word| !word.is_empty()).map(str::to_lowercase).collect(); + tuning.pronouns.iter().filter(|(id, _)| id.as_str() != own && tokens.contains(&localpart(id).to_lowercase())).map(|(id, pronouns)| format!("{} \u{2014} {pronouns}", capitalized(localpart(id)))).collect() +} + fn pronoun_line(inputs: &Inputs, tuning: &Tuning) -> Option { let parts: Vec = people_in_view(inputs, tuning).iter().map(|(label, id)| format!("{label} \u{2014} {}", tuning.pronouns.get(id).map_or(UNKNOWN_PRONOUNS, String::as_str))).collect(); (!parts.is_empty()).then(|| clip(&format!("- pronouns: {}", parts.join("; ")), ALSO_HERE_BYTES)) @@ -2192,5 +2201,5 @@ 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), 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, domain, domain_shown, in_view, promises_over, now_ms, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } + 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), 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, domain, domain_shown, in_view, promises_over, now_ms, own_sender: inputs.people.own_sender.to_owned(), arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } }