Interpreter: a later call decides over the whole wake; a draft from earlier is sent only if nothing she wrote after it says it is superseded or wrong (a judgement rule in the frame), and earlier calls' acts are not carried (Soul's R6)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-21 01:35:31 +01:00
commit 010a2e15ba
2 changed files with 44 additions and 23 deletions

View file

@ -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<Value> = 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<String> = 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<Value> = earlier("said");
let mut refusals: Vec<Value> = earlier("refused");
let mut said: Vec<Value> = Vec::new();
let mut refusals: Vec<Value> = 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<usize> = Vec::new();
let mut went: Vec<&Draft> = Vec::new();
let mut said_drafts: Vec<usize> = Vec::new();
let mut unused: Vec<Value> = earlier("promises_unused");
let mut proposals: Vec<Value> = earlier("state");
let mut to_dropped: Vec<Value> = earlier("promise_to_dropped");
let mut unused: Vec<Value> = Vec::new();
let mut proposals: Vec<Value> = Vec::new();
let mut to_dropped: Vec<Value> = 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<Value> = earlier("amended");
let mut amended: Vec<Value> = Vec::new();
let mut amended_drafts: Vec<usize> = 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<Value> = earlier("suggestions");
let mut suggestions: Vec<Value> = 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));

View file

@ -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. <typed>Looking now.</typed>";
@ -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. <typed>Meta, my read came back empty.</typed>";
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. <typed>Meta, the read worked: the knee bends first.</typed>");
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)
}