diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index aae09fb..1081df6 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -463,7 +463,13 @@ pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tu // What she can read, and how to name it, only when this turn can read (map 16.22.3). let reading = if packet.affordances.contains(&Affordance::Read) { format!("{}\n\n", read_frame(her)) } else { String::new() }; // 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) }; + // Her earlier segments this wake and what she read between them. Her drafts are numbered across the whole moment, and + // a draft from earlier is sent only if nothing she wrote after it says it is superseded or wrong (Soul's R6). + let before = if before.is_empty() { + String::new() + } else { + format!("Earlier in {} moment, before what follows:\n{before}\n\n{} drafts are numbered across the whole moment. A draft from earlier in it is sent only if nothing {} wrote after it says it is superseded or wrong.\n\n", her.poss, capitalized(her.poss), her.subj) + }; 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); @@ -509,12 +515,13 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra decide_in(model, request_id, packet, narration, prose, tuning, Wake::default()) } -/// One speech decision on the new segment of her wake (`wake`): the acts of earlier segments carry over whole, the caps -/// (lines, one addition, one note) hold across the wake, what she read joins what an echo is measured against, and -/// `read` is the one read this segment reaches for, resolved, or none. +/// One speech decision after the newest segment of her wake (`wake`), over the whole wake (Soul's R6): the Interpreter +/// sees all of her prose and every draft, numbered across the wake, and decides afresh what goes out, so a draft written +/// before a read that her later prose says is superseded or wrong is not sent. Earlier calls' acts are not carried; their +/// reads, refused reads and usage are. What she read joins what an echo is measured against, and `read` is the one read +/// the newest segment reaches for, resolved, or none. pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, narration: &str, prose: &str, tuning: &Tuning, wake: Wake) -> Value { - let whole = drafts(prose); - let found = Drafts { drafts: whole.drafts.iter().filter(|draft| draft.start >= wake.from).cloned().collect(), unfinished: whole.unfinished, regions: whole.regions.clone() }; + let found = drafts(prose); let segment = prose.get(wake.from..).unwrap_or_default(); let answer = match model.ask(request_id, &tuning.interpreter.model, &speech_prompt_in(packet, narration, segment, tuning, wake.before, &found), Some(SPEECH_SCHEMA)) { Ok(answer) => answer, @@ -524,8 +531,7 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na return json!({ "failed": "the answer is not the speech contract", "raw": answer.text, "usage": answer.usage }); }; let earlier = |key: &str| wake.earlier.and_then(|earlier| earlier[key].as_array()).cloned().unwrap_or_default(); - let mut gaps = earlier("gaps"); - gaps.extend(parsed.gaps.iter().map(|raw| gap(prose, &found, raw))); + let gaps: Vec = parsed.gaps.iter().map(|raw| gap(prose, &found, raw)).collect(); // What she was sent and what she has read this wake: what an echo is measured against, and what no quote she is told // repeats a run of (map 16.22.3). let bodies: Vec = packet.bodies.iter().cloned().chain(wake.read.iter().cloned()).collect(); @@ -549,8 +555,8 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na // Only speech needs a room: a note to Self does not. let room = packet.room.clone(); let shown = |id: &str| packet.people.iter().any(|(_, person)| person == id); - let mut said: Vec = earlier("said"); - let mut refusals: Vec = earlier("refused"); + let mut said: Vec = Vec::new(); + let mut refusals: Vec = Vec::new(); // A draft is its number (map 16.20.7): one draft goes one place, and a draft is used only when its act succeeds, so a // refused act leaves it free. The same words go out once: a said draft whose words already went out is `Duplicate`, // and only speech is held to that, so two identical drafts may still be a line and a note. `went` holds the drafts @@ -558,9 +564,9 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na let mut used: Vec = Vec::new(); let mut went: Vec<&Draft> = Vec::new(); let mut said_drafts: Vec = Vec::new(); - let mut unused: Vec = earlier("promises_unused"); - let mut proposals: Vec = earlier("state"); - let mut to_dropped: Vec = earlier("promise_to_dropped"); + let mut unused: Vec = Vec::new(); + let mut proposals: Vec = Vec::new(); + let mut to_dropped: Vec = Vec::new(); for line in parsed.say { let Some(draft) = line.draft.and_then(|n| found.numbered(n)) else { refusals.push(refused(Act::Say, None, line.draft, Refusal::NoDraft)); @@ -598,7 +604,7 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na } // An amendment adds a whole draft after a line of hers listed as one she may add to; the actuator composes it, so // nothing here can rewrite the line (map 16.17). - let mut amended: Vec = earlier("amended"); + let mut amended: Vec = Vec::new(); let mut amended_drafts: Vec = Vec::new(); for proposed in parsed.amend { let Some(draft) = proposed.draft.and_then(|n| found.numbered(n)) else { @@ -628,7 +634,7 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na } // A note to Self (map 16.18): one whole draft, at most one a turn, refused as an echo as a line is, and when the // Interpreter judges it carries something private. It is recorded in the turn's record and nowhere else; nothing here writes her Mind. - let mut suggestions: Vec = earlier("suggestions"); + let mut suggestions: Vec = Vec::new(); for proposed in parsed.suggest { let Some(draft) = proposed.draft.and_then(|n| found.numbered(n)) else { refusals.push(refused(Act::Suggest, None, proposed.draft, Refusal::NoDraft)); diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 303cf14..e8fbaa0 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -795,10 +795,11 @@ fn k24_a_read_is_what_her_thought_reaches_for_and_nothing_a_model_made_up() { assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","read"]"#)); } -/// A later call judges only the new segment: drafts are numbered across the wake, an earlier one cannot be sent again, -/// the earlier acts carry over whole with the caps across the wake, and a draft that copies what she read is an echo. +/// Soul's R6: a later call decides over the whole wake. Drafts are numbered across it and an earlier one may still be +/// sent; what earlier calls decided is not carried, so a draft the later prose supersedes goes out only if this call says +/// so; and a draft that copies what she read is an echo. #[test] -fn k24_a_later_segment_is_judged_alone_and_what_she_read_joins_the_echo_check() { +fn k24_a_later_call_decides_over_the_whole_wake_and_what_she_read_joins_the_echo_check() { let packet = reading_packet(); let read = "Reflex: the knee bends first, before the hip, so the fall reads as a fall and not as a fold.".to_owned(); let first = "I want to see it. Looking now."; @@ -813,17 +814,31 @@ fn k24_a_later_segment_is_judged_alone_and_what_she_read_joins_the_echo_check() let wake = Wake { earlier: Some(&earlier), from, read: &reads, before: &before }; let decision = decide_in(&model, "test", &packet, "The room is warm.", &prose, &Tuning::default(), wake); assert_eq!(texts(&decision), ["Looking now.", "Nibu, the knee goes first. That is lovely."], "{decision}"); - let why: Vec<(String, String)> = refusals(&decision); - assert!(why.contains(&("say".to_owned(), "no_draft".to_owned())) && why.contains(&("say".to_owned(), "echo".to_owned())), "draft 1 was the earlier segment's; draft 2 copies the read: {why:?}"); + assert_eq!(refusals(&decision), [("say".to_owned(), "echo".to_owned())], "draft 2 copies the read: {decision}"); assert!(decision["heard"].as_array().unwrap().iter().any(|body| body == read.as_str()), "what she read is what her outcome's quotes are guarded against"); let prompt = model_prompt(&packet, &prose, wake); - assert!(prompt.contains("Earlier in his moment, already decided on") && prompt.contains("His drafts, by number:\n2. ") && !prompt.contains("1. Looking now."), "{prompt}"); + assert!(prompt.contains("Earlier in his moment, before what follows") && prompt.contains("A draft from earlier in it is sent only if nothing he wrote after it says it is superseded or wrong.") && prompt.contains("His drafts, by number:\n1. Looking now.\n2. "), "{prompt}"); +} + +/// Soul's R6: a draft written before a read that the later prose says is wrong is not sent when the later call does not +/// say it; the earlier call's decision to send it is not carried. +#[test] +fn r6_a_draft_the_later_prose_supersedes_is_not_sent() { + let packet = reading_packet(); + let first = "I want to see what changed in Lodur. Meta, my read came back empty."; + let earlier = answered(&packet, first, json!({ "say": [{ "draft": 1 }], "gaps": [] })); + assert_eq!(texts(&earlier), ["Meta, my read came back empty."]); + let prose = format!("{first}\n\nNo, the read worked; that draft is wrong. Meta, the read worked: the knee bends first."); + let reply = json!({ "say": [{ "draft": 2 }], "gaps": [] }).to_string(); + let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone()); + let reads = ["The knee bends first.".to_owned()]; + let decision = decide_in(&model, "test", &packet, "The room is warm.", &prose, &Tuning::default(), Wake { earlier: Some(&earlier), from: first.len() + 2, read: &reads, before: first }); + assert_eq!(texts(&decision), ["Meta, the read worked: the knee bends first."], "{decision}"); } /// The prompt a decision on `wake` sends. fn model_prompt(packet: &Packet, prose: &str, wake: Wake) -> String { - let whole = drafts(prose); - let found = Drafts { drafts: whole.drafts.iter().filter(|draft| draft.start >= wake.from).cloned().collect(), unfinished: whole.unfinished, regions: whole.regions.clone() }; + let found = drafts(prose); speech_prompt_in(packet, "The room is warm.", &prose[wake.from..], &Tuning::default(), wake.before, &found) }