Outcome guard: her own words are the record turn's receipts, and a run is hers only when she wrote it before the other person said it; Meta's words she echoed stay withheld (Soul's R5, after_echo_withheld). The test builds the record through the real pipeline
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2caae36673
commit
2dde3b0c3a
5 changed files with 61 additions and 36 deletions
|
|
@ -530,7 +530,7 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na
|
|||
// The lines it listed by id and her open promises it listed by id ride in the record too: the commit resolves a
|
||||
// proposal's evidence against them (`commit::apply`), as the trace holds them live.
|
||||
let lines: Vec<Value> = packet.quotable.iter().map(|line| json!({ "id": line.id, "event": line.event, "room": line.room, "who": line.who, "sender": line.sender, "at_ms": line.at_ms })).collect();
|
||||
let mut decision = json!({ "said": [], "refused": [], "gaps": gaps, "heard": bodies, "lines": lines, "promises": packet.promises, "usage": answer.usage, "read": null, "own": packet.own_words });
|
||||
let mut decision = json!({ "said": [], "refused": [], "gaps": gaps, "heard": bodies, "lines": lines, "promises": packet.promises, "usage": answer.usage, "read": null, "at_ms": packet.now_ms });
|
||||
if let Some(reads) = wake.earlier.map(|earlier| earlier["reads"].clone()).filter(Value::is_array) {
|
||||
decision["reads"] = reads;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,9 +101,11 @@ pub(crate) struct Outcome {
|
|||
/// 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<Vec<String>>,
|
||||
/// Her own words on the turn the record is from (the decision's `own`: her lines in the room, her promises' words): a
|
||||
/// run of them quoted back by someone is hers, and is not withheld (map 16.23.4).
|
||||
/// Her own words on the turn the record is from, by its receipts (the lines that went out, the additions made), and
|
||||
/// when she wrote them (the decision's `at_ms`): a run of them someone said after that is hers, quoted back, and is not
|
||||
/// withheld; a run someone said before it stays withheld, however she echoed it (map 16.23.4, Soul's R5).
|
||||
own: Vec<String>,
|
||||
own_at: Option<u64>,
|
||||
}
|
||||
|
||||
fn words(value: &Value) -> Option<String> {
|
||||
|
|
@ -138,7 +140,9 @@ pub(crate) fn outcome_of(record: &Value) -> Option<Outcome> {
|
|||
}
|
||||
let room = words(&decision["room"]);
|
||||
outcome.heard = decision["heard"].as_array().map(|heard| heard.iter().filter_map(|body| body.as_str().map(str::to_owned)).collect());
|
||||
outcome.own = decision["own"].as_array().into_iter().flatten().filter_map(|words| words.as_str().map(str::to_owned)).collect();
|
||||
outcome.own_at = decision["at_ms"].as_u64();
|
||||
let made = |amended: &Value| record["edited"].as_array().into_iter().flatten().any(|receipt| receipt["event"] == amended["event"] && receipt["refusal"].is_null());
|
||||
outcome.own = record["posted"].as_array().into_iter().flatten().filter_map(|receipt| words(&receipt["text"])).chain(decision["amended"].as_array().into_iter().flatten().filter(|amended| made(amended)).filter_map(|amended| words(&amended["added"]))).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();
|
||||
// Each addition's draft, and the part that tells it when the actuator made it.
|
||||
|
|
@ -396,10 +400,11 @@ impl Part {
|
|||
/// promise is still told as a promise she has no way to keep, which she can add to.
|
||||
///
|
||||
/// 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], own: &[String]) -> String {
|
||||
let sent: Vec<&str> = heard.into_iter().flatten().chain(sent).map(String::as_str).collect();
|
||||
fn line(&self, her: Forms, quote_max: usize, heard: Option<&[String]>, sent: &[(u64, String)], own: &[String], own_at: Option<u64>) -> String {
|
||||
let earlier: Vec<&str> = heard.into_iter().flatten().map(String::as_str).collect();
|
||||
let later: Vec<(u64, &str)> = sent.iter().map(|(at, words)| (*at, words.as_str())).collect();
|
||||
let own: Vec<&str> = own.iter().map(String::as_str).collect();
|
||||
let quoted = |text: &str| if heard.is_none() || repeats(text, &sent, &own) { withheld(her) } else { spoken(&clip(text, quote_max)) };
|
||||
let quoted = |text: &str| if heard.is_none() || repeats(text, &earlier, &later, &own, own_at) { withheld(her) } else { spoken(&clip(text, quote_max)) };
|
||||
format!("- {}{}", self.reached(her, "ed), self.rest(her, "ed))
|
||||
}
|
||||
}
|
||||
|
|
@ -428,13 +433,22 @@ const REPEAT_RUN: usize = 3;
|
|||
/// ("of the", "I think"). What it gives up: a quote of hers that shares three words in a row with what she was sent,
|
||||
/// or with what was said to her this turn (her own words quoted back included), is withheld; and someone's words of
|
||||
/// one or two words reach the Projector inside a short quote of hers.
|
||||
pub(crate) fn repeats(text: &str, sent: &[&str], own: &[&str]) -> bool {
|
||||
pub(crate) fn repeats(text: &str, earlier: &[&str], later: &[(u64, &str)], own: &[&str], own_at: Option<u64>) -> bool {
|
||||
let tokens = |text: &str| -> Vec<String> { text.split(|c: char| !c.is_alphanumeric() && c != '\'').filter(|word| !word.is_empty()).map(str::to_lowercase).collect() };
|
||||
let runs = |texts: &[&str]| -> std::collections::BTreeSet<Vec<String>> { texts.iter().flat_map(|text| tokens(text).windows(REPEAT_RUN).map(<[String]>::to_vec).collect::<Vec<_>>()).collect() };
|
||||
// Others' words only (map 16.23.4): a run that also occurs in her own lines or promises is hers, quoted back.
|
||||
let mine = runs(&[text]);
|
||||
let (theirs, own) = (runs(sent), runs(own));
|
||||
mine.iter().any(|run| theirs.contains(run) && !own.contains(run))
|
||||
// What the record's turn heard was said before she wrote: a run of it is someone else's, whatever she did with it.
|
||||
let before = runs(earlier);
|
||||
if mine.iter().any(|run| before.contains(run)) {
|
||||
return true;
|
||||
}
|
||||
// Said since: a run of hers is exempt only when she wrote it first (map 16.23.4, Soul's R5 `after_echo_withheld`).
|
||||
let own = runs(own);
|
||||
later.iter().any(|(at, body)| {
|
||||
let theirs = runs(&[body]);
|
||||
let hers_first = own_at.is_some_and(|own_at| own_at < *at);
|
||||
mine.iter().any(|run| theirs.contains(run) && !(hers_first && own.contains(run)))
|
||||
})
|
||||
}
|
||||
|
||||
impl Outcome {
|
||||
|
|
@ -445,8 +459,8 @@ 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.as_deref(), sent, &self.own)
|
||||
pub(crate) fn line(&self, at: usize, her: Forms, quote_max: usize, sent: &[(u64, String)]) -> String {
|
||||
self.parts[at].line(her, quote_max, self.heard.as_deref(), sent, &self.own, self.own_at)
|
||||
}
|
||||
|
||||
/// Every line she is told, whole: the report's.
|
||||
|
|
|
|||
|
|
@ -243,7 +243,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, Some(&[]), &[], &[]), format!("- {reached}{rest}"), "{part:?}");
|
||||
assert_eq!(part.line(her, usize::MAX, Some(&[]), &[], &[], None), 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}");
|
||||
|
|
@ -276,8 +276,8 @@ fn a_quote_that_is_mostly_words_she_was_sent_this_turn_is_not_shown_to_the_proje
|
|||
let said = "QUARTZ-HERON-SENTINEL is back at the door.";
|
||||
let outcome = outcome_of(&record(&format!("<typed>{said}</typed>"), json!({ "say": [{ "draft": 1 }], "gaps": [] }), &[said])).unwrap();
|
||||
let her = packet().forms;
|
||||
assert_eq!(outcome.line(0, her, usize::MAX, &["Heimdall, QUARTZ-HERON-SENTINEL is back at the door.".to_owned()]), "- #minds:gamecult.org has, from him: (his words, not shown here).");
|
||||
assert_eq!(outcome.line(0, her, usize::MAX, &["Something else entirely, said today.".to_owned()]), format!("- #minds:gamecult.org has, from him: {}.", spoken(said)), "his own words are shown");
|
||||
assert_eq!(outcome.line(0, her, usize::MAX, &[(u64::MAX, "Heimdall, QUARTZ-HERON-SENTINEL is back at the door.".to_owned())]), "- #minds:gamecult.org has, from him: (his words, not shown here).");
|
||||
assert_eq!(outcome.line(0, her, usize::MAX, &[(u64::MAX, "Something else entirely, said today.".to_owned())]), format!("- #minds:gamecult.org has, from him: {}.", spoken(said)), "his own words are shown");
|
||||
}
|
||||
|
||||
/// Soul's oposted case at 964ee50: Meta quoted his own posted promise back to him ("the render! tonight-tonight?"), the
|
||||
|
|
@ -293,7 +293,7 @@ fn a_withheld_quote_claims_nothing_about_where_its_words_came_from() {
|
|||
outcome_of(&record).unwrap()
|
||||
};
|
||||
let mine = "Missed you too. I'll send the render tonight.";
|
||||
let quoted_back = ["ooh, the render! tonight-tonight? I'll stay up for it".to_owned()];
|
||||
let quoted_back = [(u64::MAX, "ooh, the render! tonight-tonight? I'll stay up for it".to_owned())];
|
||||
let said = posted(mine, "missed you this week. you doing ok?", false);
|
||||
assert_eq!(said.line(0, her, usize::MAX, &[]), format!("- #minds:gamecult.org has, from him: {}.", spoken(mine)), "nothing he was sent shares a run of three");
|
||||
assert_eq!(said.line(0, her, usize::MAX, "ed_back), "- #minds:gamecult.org has, from him: (his words, not shown here).");
|
||||
|
|
|
|||
|
|
@ -347,9 +347,8 @@ pub(crate) struct Packet {
|
|||
pub in_view: String,
|
||||
/// Her open promises took more than `promises_bytes`: every one is still shown, and the report says so.
|
||||
pub promises_over: bool,
|
||||
/// Lines of hers in the room and her promises' words: no outcome quote is withheld for a run of words she wrote first
|
||||
/// (map 16.23.4).
|
||||
pub own_words: Vec<String>,
|
||||
/// 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,
|
||||
/// 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<String>,
|
||||
|
|
@ -2005,11 +2004,13 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
let mut context = Context::new(guards(tuning, her), her);
|
||||
// Her own posted lines are never what she was sent: the quote guard and the echo check compare against others' words only.
|
||||
let others = |line: &RoomLine| line.sender != inputs.people.own_sender;
|
||||
let bodies: Vec<String> = match inputs.kind {
|
||||
TurnKind::Chat => inputs.room.messages.iter().chain(earlier_shown.iter().copied()).filter(|line| others(line)).flat_map(|line| shown_words(line, inputs.people.own_sender)).collect(),
|
||||
TurnKind::Beat => beat_tail(inputs, tuning).iter().filter(|line| others(line)).flat_map(|line| shown_words(line, inputs.people.own_sender)).collect(),
|
||||
// Each with when it was said, so the outcome guard can tell a run she wrote first from one she repeated (map 16.23.4).
|
||||
let timed: Vec<(u64, String)> = match inputs.kind {
|
||||
TurnKind::Chat => inputs.room.messages.iter().chain(earlier_shown.iter().copied()).filter(|line| others(line)).flat_map(|line| shown_words(line, inputs.people.own_sender).map(|words| (line.at_ms, words))).collect(),
|
||||
TurnKind::Beat => beat_tail(inputs, tuning).iter().filter(|line| others(line)).flat_map(|line| shown_words(line, inputs.people.own_sender).map(|words| (line.at_ms, words))).collect(),
|
||||
TurnKind::FollowUp | TurnKind::Reflection => Vec::new(),
|
||||
};
|
||||
let bodies: Vec<String> = timed.iter().map(|(_, words)| words.clone()).collect();
|
||||
// What she may reply to (map 16.20.8 (D), K20): the lines of others in the turn's room whose words this packet shows
|
||||
// her, oldest first, as K19's earlier lines then the new ones; a beat's tail lines. Each by a short id; the mouth's event
|
||||
// is the actuator's handle, never shown to a model.
|
||||
|
|
@ -2031,7 +2032,7 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
let mut unshown: Vec<String> = Vec::new();
|
||||
if let Some(outcome) = &inputs.history.last {
|
||||
let count = |more: usize| format!("- {more} more {} from {} last turn {} not shown here.", if more == 1 { "thing" } else { "things" }, her.poss, if more == 1 { "is" } else { "are" });
|
||||
let least: Vec<usize> = (0..outcome.len()).map(|at| outcome.line(at, her, OUTCOME_QUOTE_MIN, &bodies).len() + 1).collect();
|
||||
let least: Vec<usize> = (0..outcome.len()).map(|at| outcome.line(at, her, OUTCOME_QUOTE_MIN, &timed).len() + 1).collect();
|
||||
let room = context.room(Section::Outcome).saturating_sub(Section::Outcome.heading(her).len() + 1);
|
||||
// The most parts, in order, whose least lines fit beside the count of the rest.
|
||||
let shown = (0..=outcome.len()).rev().find(|&shown| least[..shown].iter().sum::<usize>() + if shown < outcome.len() { count(outcome.len() - shown).len() + 1 } else { 0 } <= room).unwrap_or(0);
|
||||
|
|
@ -2039,11 +2040,11 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
for at in 0..shown {
|
||||
let reserve: usize = least[at + 1..shown].iter().sum::<usize>() + counted;
|
||||
let past = |context: &Context, line: &str| (context.cost(Section::Outcome, line) + reserve).saturating_sub(context.room(Section::Outcome));
|
||||
let mut line = outcome.line(at, her, usize::MAX, &bodies);
|
||||
let mut line = outcome.line(at, her, usize::MAX, &timed);
|
||||
let mut quote_max = line.len();
|
||||
while past(&context, &line) > 0 && quote_max > OUTCOME_QUOTE_MIN {
|
||||
quote_max = quote_max.saturating_sub(past(&context, &line)).max(OUTCOME_QUOTE_MIN);
|
||||
line = outcome.line(at, her, quote_max, &bodies);
|
||||
line = outcome.line(at, her, quote_max, &timed);
|
||||
context.bound[Section::Outcome as usize] = true;
|
||||
if !clipped.iter().any(|id| id == "(outcome)") {
|
||||
clipped.push("(outcome)".to_owned());
|
||||
|
|
@ -2054,7 +2055,7 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
if shown < outcome.len() {
|
||||
context.bound[Section::Outcome as usize] = true;
|
||||
context.push(Section::Outcome, count(outcome.len() - shown));
|
||||
unshown = (shown..outcome.len()).map(|at| outcome.line(at, her, usize::MAX, &bodies)).collect();
|
||||
unshown = (shown..outcome.len()).map(|at| outcome.line(at, her, usize::MAX, &timed)).collect();
|
||||
}
|
||||
}
|
||||
let (promises, promises_view) = open_promises(inputs, her);
|
||||
|
|
@ -2190,7 +2191,6 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet {
|
|||
let in_view = [promises_view.as_str(), domain_view.as_str()].into_iter().filter(|part| !part.is_empty()).collect::<Vec<_>>().join("\n\n");
|
||||
let mut sections = context.sizes();
|
||||
(sections.promises, sections.domain) = (promises_view.len(), domain_view.len());
|
||||
// Her own words: her lines in the room and her promises', for the outcome guard (map 16.23.4).
|
||||
let own_words: Vec<String> = inputs.room.messages.iter().chain(&inputs.room.tail).filter(|line| line.sender == inputs.people.own_sender).map(|line| line.text.clone()).chain(items(inputs.state, &["commitments"]).iter().map(|entry| text(entry, &["words"]).to_owned())).filter(|words| !words.is_empty()).collect();
|
||||
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, own_words, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown }
|
||||
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 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2712,15 +2712,26 @@ fn k25_her_domain_is_in_her_view_whole_in_a_stated_window_that_shrinks_and_never
|
|||
assert!(quiet.in_view.is_empty() && !interpret::speech_prompt(&quiet, "x", "y", &tuning).contains("domain lately"), "{}", quiet.in_view);
|
||||
}
|
||||
|
||||
/// Map 16.23.4: the outcome guard compares against others' words only, minus any run she wrote first. Her line that
|
||||
/// Meta quotes back is hers and is shown; a quote that repeats Meta's own words is still withheld.
|
||||
/// Map 16.23.4 as Soul's R5 settles it, through the real pipeline: the record turn's own words are its receipts, and a
|
||||
/// run is hers only when she wrote it before the other person said it. Her line that Meta quotes back afterwards is shown;
|
||||
/// Meta's words she echoed are still withheld, because Meta said them first (`after_echo_withheld`).
|
||||
#[test]
|
||||
fn k25_the_outcome_guard_withholds_only_others_words() {
|
||||
const SW: &str = "#swarm:gamecult.org";
|
||||
let (operators, minds, history) = (operators(), minds(), History::default());
|
||||
let earlier = now() - chrono::Duration::minutes(30);
|
||||
let first_room = Room { messages: vec![message(SW, OPERATOR, "Meta", "the blue lantern sways at midnight over the harbour", 40, true)], here: Some(SW.into()), ..Room::default() };
|
||||
let first = select(&Inputs { kind: TurnKind::Chat, state: &state(), room: &first_room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: earlier, seed: 1, affordances: CAN, domain: None }, &Tuning::default());
|
||||
let echo = "Yes, the blue lantern sways at midnight.";
|
||||
let mine = "I'll send the render tonight, after the boil.";
|
||||
let record = |own: Value| json!({ "interpreter": { "room": "#swarm:gamecult.org", "said": [{ "room": "#swarm:gamecult.org", "text": mine }], "refused": [], "gaps": [], "heard": ["Meta: you said I'll send the render tonight, after the boil, and I believe you"], "own": own }, "posted": [{ "event": "e1", "room": "#swarm:gamecult.org", "text": mine }] });
|
||||
let told = |record: &Value| outcome::outcome_of(record).unwrap().lines(select::forms(&state()));
|
||||
assert_eq!(told(&record(json!([mine]))), [format!("- #swarm:gamecult.org has, from her: \"{mine}\".")], "quoted back, still hers");
|
||||
assert_eq!(told(&record(json!([]))), ["- #swarm:gamecult.org has, from her: (her words, not shown here).".to_owned()], "Meta's words with no line of hers behind them are withheld");
|
||||
let model = crate::projection::harness::tests::Scripted::new(|_| String::new()).interpreting(|_| json!({ "say": [{ "draft": 1 }, { "draft": 2 }], "gaps": [] }).to_string());
|
||||
let decision = interpret::decide(&model, "test", &first, "The room is warm.", &format!("<typed>{echo}</typed> <typed>{mine}</typed>"), &Tuning::default());
|
||||
let record = json!({ "interpreter": decision, "posted": [{ "event": "e1", "room": SW, "text": echo }, { "event": "e2", "room": SW, "text": mine }] });
|
||||
// Now, after she wrote, Meta quotes her back, and says the lantern line again.
|
||||
let room = Room { messages: vec![message(SW, OPERATOR, "Meta", "you said I'll send the render tonight, after the boil. and the blue lantern sways at midnight", 5, true)], here: Some(SW.into()), ..Room::default() };
|
||||
let packet = packet_of(TurnKind::Chat, &state(), &room, &with_last(&record), 1);
|
||||
let outcome: Vec<&str> = packet.context.lines().skip_while(|line| !line.starts_with("What came of her last turn:")).skip(1).take_while(|line| line.starts_with("- ")).collect();
|
||||
assert_eq!(outcome, ["- #swarm:gamecult.org has, from her: (her words, not shown here).", &format!("- #swarm:gamecult.org has, from her: \"{mine}\".")], "{}", packet.context);
|
||||
}
|
||||
|
||||
/// B2, and 16.23.4: her own posted lines are never what she was sent, and her promises are in her view whole: not
|
||||
|
|
|
|||
Loading…
Reference in a new issue