diff --git a/crates/mind-body/src/bin/mind-persona.rs b/crates/mind-body/src/bin/mind-persona.rs index 23c1194..d33bc39 100644 --- a/crates/mind-body/src/bin/mind-persona.rs +++ b/crates/mind-body/src/bin/mind-persona.rs @@ -228,6 +228,7 @@ fn run_project(args: &[String]) -> Result { own_rooms: vec![], last_outcome, last_wake: None, + records: vec![], }; let report = project(&organs, &request, chrono::Utc::now())?; let addressing = &report["addressing"]; diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index e09480d..a687a1b 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -22,6 +22,7 @@ pub mod harness; mod commit; mod domain; +mod exchange; mod interpret; mod narrate; mod outcome; @@ -225,6 +226,10 @@ pub struct Request { /// When she last woke: her domain's window opens there, held to at least a day and at most a week (map 16.22.2). A /// simulation carries each Mind's; none, as live until the commit's trace (C3c) carries it, is a week. pub last_wake: Option>, + /// Her earlier turn records, oldest first (the commit's trace live, once C3c writes it; a simulation's own): what she + /// has said and read in this conversation is read from them (`exchange::exchange_of`, map 16.24.1). Empty live until + /// the trace exists. + pub records: Vec, } /// Her addressee: the heartbeat's row for her when its table holds one, else her own names (handle and public name). @@ -448,11 +453,13 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni let Ok(request) = serde_json::from_value::(read["request"].clone()) else { break }; let what = read["what"].as_str().unwrap_or_default().to_owned(); let result = reading.source.read(&request, reading.since).map(|text| read::clipped(&text, tuning.interpreter.read_bytes.min(bytes_left))); - let mut done = json!({ "n": reads.len() + 1, "kind": read["kind"], "target": read["target"], "what": what, "quote": read["quote"] }); + let mut done = json!({ "n": reads.len() + 1, "kind": read["kind"], "target": read["target"], "request": read["request"], "what": what, "quote": read["quote"] }); match &result { Ok(text) => { done["ok"] = json!(true); done["bytes"] = json!(text.len()); + // What it returned rides in the record: her side of the conversation shows it (K26). + done["text"] = json!(text); read_bytes += text.len(); read_texts.push(text.clone()); } @@ -548,7 +555,10 @@ pub fn project(organs: &Organs, request: &Request, now: DateTime) -> Result let people = People { operators: &request.operators, minds: &request.minds, own_sender: &request.own_sender }; let names = domain::Names::of(&state, &people, &request.instance); let (digest, domain_report) = read_domain(organs.domain, request.last_wake, now, &names); - let inputs = Inputs { kind: request.kind, state: &state, room: &room, history: &history, observation: None, people, now, seed: request.seed, affordances: &[], domain: digest.as_ref() }; + let inputs = Inputs { kind: request.kind, state: &state, room: &room, history: &history, observation: None, people, now, seed: request.seed, affordances: &[], domain: digest.as_ref(), exchange: None }; + // Her side of this conversation, from her turn records (K26). + let exchange = turn_room(&inputs).map(|here| exchange::exchange_of(&request.records, here, now, select::forms(&state))); + let inputs = Inputs { exchange: exchange.as_ref(), ..inputs }; let can = affordances(organs, room_report["read"] == true, turn_room(&inputs), request.through); let inputs = Inputs { affordances: &can, ..inputs }; diff --git a/crates/mind-body/src/projection/exchange.rs b/crates/mind-body/src/projection/exchange.rs new file mode 100644 index 0000000..e62d953 --- /dev/null +++ b/crates/mind-body/src/projection/exchange.rs @@ -0,0 +1,123 @@ +//! Her side of the conversation (map 16.24.1, K26): what she has said and read in this conversation, read from her turn +//! records by one function, `exchange_of`, beside `outcome::outcome_of`, and rendered whole in her view. +//! +//! The turn record owns what she did: the lines that went out (its receipts), the additions made, and each read with its +//! request and what it returned. This module reads it and nothing else; it writes nothing. The conversation is her turns +//! in the turn's room going back while each is within `EXCHANGE_MINUTES` of the next, from now: past a pause that long, +//! a conversation starts fresh, and what she keeps beyond it is what she chose to remember. The window is one constant, +//! the recommended answer to the operator's open question Q-G (a); if she rules otherwise, it is this number. +//! +//! In her view: her lines, oldest first, with when and what each replied to, her additions folded into them; then each +//! distinct thing she read once, its latest result whole, after a heading in code's words. Under `exchange_bytes`, with +//! the shrinking window of 16.23.5: whole lines and whole results drop from the old end and the heading says since when. +//! Nothing is counted. A read whose latest result is in her view is not performed again (`interpret::reading`). + +use chrono::{DateTime, Utc}; +use serde_json::Value; + +use super::domain::floor_minute; +use super::read::ReadRequest; +use super::select::{Forms, capitalized, spoken}; + +/// How long a pause ends a conversation (Q-G (a)): her turns in a room belong to one conversation while each is within +/// this many minutes of the next. +pub(crate) const EXCHANGE_MINUTES: i64 = 30; + +/// One thing she did in the conversation, in code's words: a line of hers, or a read and its result. +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct Did { + pub(crate) at: DateTime, + pub(crate) text: String, + /// The read this is, when it is one: a read whose result is shown is in her view. + pub(crate) read: Option, +} + +/// Her side of the conversation, oldest first: her lines, then each distinct read once with its latest result. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub(crate) struct Exchange { + pub(crate) lines: Vec, + pub(crate) reads: Vec, +} + +fn at_of(record: &Value) -> Option> { + record["interpreter"]["at_ms"].as_i64().and_then(DateTime::from_timestamp_millis) +} + +fn time_of(at: DateTime, now: DateTime) -> String { + if at.date_naive() == now.date_naive() { at.format("%H:%M UTC").to_string() } else { at.format("%A %-d %B, %H:%M UTC").to_string() } +} + +/// Her side of the conversation in `room` as `records` (her turn records, oldest first) hold it, at `now`. +pub(crate) fn exchange_of(records: &[Value], room: &str, now: DateTime, her: Forms) -> Exchange { + // Her turns in this room, newest first, while each is within the window of the one after it (now, for the newest). + let mut kept: Vec<(&Value, DateTime)> = Vec::new(); + let mut next = now; + for record in records.iter().rev() { + let Some(at) = at_of(record) else { continue }; + if record["interpreter"]["room"].as_str() != Some(room) { + continue; + } + if next - at > chrono::Duration::minutes(EXCHANGE_MINUTES) { + break; + } + kept.push((record, at)); + next = at; + } + kept.reverse(); + let mut exchange = Exchange::default(); + for (record, at) in &kept { + let decision = &record["interpreter"]; + for receipt in record["posted"].as_array().into_iter().flatten() { + let (Some(text), Some(event)) = (receipt["text"].as_str(), receipt["event"].as_str()) else { continue }; + if receipt["room"].as_str() != Some(room) { + continue; + } + let reply = decision["said"].as_array().into_iter().flatten().find(|line| line["text"].as_str() == Some(text)).and_then(|line| line["in_reply_to"]["who"].as_str()).map_or_else(String::new, |who| format!(", replying to {who}")); + // Her additions to this line, made in any turn of the conversation, folded into it. + let added: Vec = kept + .iter() + .flat_map(|(later, _)| later["interpreter"]["amended"].as_array().cloned().unwrap_or_default().into_iter().filter(move |amended| later["edited"].as_array().into_iter().flatten().any(|receipt| receipt["event"] == amended["event"] && receipt["refusal"].is_null()))) + .filter(|amended| amended["event"].as_str() == Some(event)) + .filter_map(|amended| amended["added"].as_str().map(|added| format!(" ({} added: {})", her.subj, spoken(added)))) + .collect(); + exchange.lines.push(Did { at: *at, text: format!("- {}{reply}: {}{}", time_of(*at, now), spoken(text), added.join("")), read: None }); + } + for read in decision["reads"].as_array().into_iter().flatten().filter(|read| read["ok"] == true) { + let (Ok(request), Some(what), Some(text)) = (serde_json::from_value::(read["request"].clone()), read["what"].as_str(), read["text"].as_str()) else { continue }; + // Each distinct thing once, its latest result. + exchange.reads.retain(|done| done.read.as_ref() != Some(&request)); + let longest = text.split(|c| c != '`').map(str::len).max().unwrap_or(0); + let fence = "`".repeat(longest.max(3) + 1); + exchange.reads.push(Did { at: *at, text: format!("{} read {what} ({}):\n{fence}\n{text}\n{fence}", capitalized(her.subj), time_of(*at, now)), read: Some(request) }); + } + } + exchange +} + +/// Her side of the conversation as her view shows it, under `budget` bytes, heading included, and the reads it shows: +/// everything, or, when it does not fit, the window shrunk from its old end a whole minute at a time, whole lines and +/// whole results only, the heading saying since when. Empty when she has done nothing here, or not even the newest fits. +pub(crate) fn render(exchange: &Exchange, her: Forms, budget: usize, now: DateTime) -> (String, Vec) { + let all: Vec<&Did> = exchange.lines.iter().chain(&exchange.reads).collect(); + let Some(mut start) = all.iter().map(|did| did.at).min() else { return (String::new(), Vec::new()) }; + let mut shrunk = false; + loop { + let lines: Vec<&Did> = exchange.lines.iter().filter(|did| did.at >= start).collect(); + let reads: Vec<&Did> = exchange.reads.iter().filter(|did| did.at >= start).collect(); + if lines.is_empty() && reads.is_empty() { + return (String::new(), Vec::new()); + } + let since = if shrunk { format!(" since {}", time_of(start, now)) } else { String::new() }; + let heading = format!("What {} {} said and read in this conversation{since}:", her.subj, her.has); + let block = std::iter::once(heading).chain(lines.iter().chain(&reads).map(|did| did.text.clone())).collect::>().join("\n"); + if block.len() <= budget { + return (block, reads.iter().filter_map(|did| did.read.clone()).collect()); + } + let oldest = lines.iter().chain(&reads).map(|did| did.at).min().unwrap_or(now); + start = floor_minute(oldest) + chrono::Duration::minutes(1); + shrunk = true; + } +} + +#[cfg(test)] +mod tests; diff --git a/crates/mind-body/src/projection/exchange/tests.rs b/crates/mind-body/src/projection/exchange/tests.rs new file mode 100644 index 0000000..b57d798 --- /dev/null +++ b/crates/mind-body/src/projection/exchange/tests.rs @@ -0,0 +1,57 @@ +//! Her side of the conversation (map 16.24.1, K26), read from her turn records. + +use chrono::{DateTime, Duration, Utc}; +use serde_json::{Value, json}; + +use super::*; + +const MINDS: &str = "#minds:gamecult.org"; + +fn now() -> DateTime { + DateTime::parse_from_rfc3339("2026-11-21T15:00:00Z").unwrap().with_timezone(&Utc) +} + +fn her() -> Forms { + Forms { subj: "he", cap_subj: "He", obj: "him", poss: "his", be: "is", has: "has", s: "s" } +} + +/// One turn record of his, `minutes` before now, in `room`: the lines that went out, additions, and reads. +fn turn(minutes: i64, room: &str, said: &[(&str, &str, Option<&str>)], reads: Value, amended: Value, edited: Value) -> Value { + let at = (now() - Duration::minutes(minutes)).timestamp_millis(); + let lines: Vec = said.iter().map(|(_, text, reply)| json!({ "room": room, "text": text, "in_reply_to": reply.map(|who| json!({ "who": who })) })).collect(); + let posted: Vec = said.iter().map(|(event, text, _)| json!({ "event": event, "room": room, "text": text })).collect(); + json!({ "interpreter": { "at_ms": at, "room": room, "said": lines, "reads": reads, "amended": amended }, "posted": posted, "edited": edited }) +} + +fn read(target: &str, text: &str) -> Value { + json!({ "ok": true, "request": { "kind": "repo", "target": target }, "what": format!("{target} on the forge"), "text": text }) +} + +#[test] +fn k26_her_side_of_the_conversation_is_her_lines_and_her_reads_while_it_lasts() { + let records = vec![ + turn(200, MINDS, &[("e0", "LONG-AGO line, before the pause.", None)], json!([]), json!([]), json!([])), + turn(50, MINDS, &[("e1", "The knee bends first, I think.", Some("Meta"))], json!([read("GameCult/Bifrost", "OLD Bifrost list")]), json!([]), json!([])), + turn(30, "#general:gamecult.org", &[("g1", "OTHER-ROOM line.", None)], json!([]), json!([]), json!([])), + turn(25, MINDS, &[], json!([read("GameCult/Bifrost", "NEW Bifrost list"), read("GameCult/Lodur#12", "Reflex: the knee bends first.")]), json!([{ "event": "e1", "added": "Checked: it does." }]), json!([{ "event": "e1", "refusal": null }])), + ]; + let exchange = exchange_of(&records, MINDS, now(), her()); + let (view, reads) = render(&exchange, her(), 3000, now()); + assert_eq!(view, "What he has said and read in this conversation:\n- 14:10 UTC, replying to Meta: \"The knee bends first, I think.\" (he added: \"Checked: it does.\")\nHe read GameCult/Bifrost on the forge (14:35 UTC):\n````\nNEW Bifrost list\n````\nHe read GameCult/Lodur#12 on the forge (14:35 UTC):\n````\nReflex: the knee bends first.\n````"); + assert!(!view.contains("LONG-AGO") && !view.contains("OTHER-ROOM") && !view.contains("OLD Bifrost"), "past the pause, another room, and an older result of the same read are not shown"); + assert_eq!(reads, [ReadRequest::Repo("GameCult/Bifrost".into()), ReadRequest::Repo("GameCult/Lodur#12".into())]); + // A pause of more than the window since her last turn: a fresh conversation. + assert!(exchange_of(&records, MINDS, now() + Duration::minutes(EXCHANGE_MINUTES), her()).lines.is_empty()); +} + +#[test] +fn k26_past_its_budget_the_window_shrinks_and_nothing_is_counted() { + let records = vec![ + turn(40, MINDS, &[("e1", "FIRST line of mine, the oldest one here.", None)], json!([]), json!([]), json!([])), + turn(20, MINDS, &[("e2", "SECOND line of mine.", None)], json!([]), json!([]), json!([])), + ]; + let exchange = exchange_of(&records, MINDS, now(), her()); + let (view, _) = render(&exchange, her(), 110, now()); + assert_eq!(view, "What he has said and read in this conversation since 14:21 UTC:\n- 14:40 UTC: \"SECOND line of mine.\""); + assert!(render(&exchange, her(), 20, now()).0.is_empty(), "not even the newest fits: none"); +} diff --git a/crates/mind-body/src/projection/harness.rs b/crates/mind-body/src/projection/harness.rs index 2206c59..8de2436 100644 --- a/crates/mind-body/src/projection/harness.rs +++ b/crates/mind-body/src/projection/harness.rs @@ -366,6 +366,7 @@ pub fn fixture_request(harness: &Harness, fixture: &Fixture, state: Option>().join("; ")) }; + let reading = if packet.affordances.contains(&Affordance::Read) { format!("{}{in_view}\n\n", read_frame(her)) } else { String::new() }; // Her earlier segments this wake, already decided on: context, never hers to send again. // 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). @@ -725,6 +727,11 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake // (Soul's p1b), so no page can steer her to the next. let reached: Vec = packet.bodies.iter().cloned().chain(std::iter::once(packet.heard.clone())).collect(); let request = resolve(&asked, packet, prose, &reached)?; + // What is in her view is not read again (K26): its latest result is there, from this conversation or this wake. + let read_this_wake = wake.earlier.into_iter().flat_map(|earlier| earlier["reads"].as_array().cloned().unwrap_or_default()).any(|done| done["ok"] == true && serde_json::from_value::(done["request"].clone()).is_ok_and(|done| done == request)); + if packet.in_view_reads.contains(&request) || read_this_wake { + return Err("in_view"); + } // The reach is located in her thought in this segment: the Interpreter's quote, or failing that the longest run of at // least `SPAN_MIN_WORDS` of its words found there (Soul's R5), and only where the sentence it stands in names what is // read: its repo, pull request, domain item, address or recall words, or a direct reference to it. A common run alone diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index e8fbaa0..4afd7ba 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -26,7 +26,7 @@ fn packet_in(kind: TurnKind, state: &Value, room: &Room, seed: u64) -> Packet { let minds = vec![HER.to_owned(), NIBU.to_owned(), VOID.to_owned(), LIBBY.to_owned(), KIKO.to_owned()]; let operators = vec!["@meta:gamecult.org".to_owned()]; let history = History::default(); - select(&Inputs { kind, state, room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: HER }, now: now(), seed, affordances: &[Affordance::Perceive, Affordance::Speak], domain: None }, &Tuning::default()) + select(&Inputs { kind, state, room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: HER }, now: now(), seed, affordances: &[Affordance::Perceive, Affordance::Speak], domain: None, exchange: None }, &Tuning::default()) } /// Heimdall: the control state, he/him. @@ -902,3 +902,17 @@ fn r6_anyone_named_gets_their_pronouns_in_view_or_not() { 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}"); } + +/// K26: what is in her view is never read again. A read whose latest result her view shows is refused as `in_view`, +/// reported and not told; the Interpreter is shown which targets those are. +#[test] +fn k26_a_read_already_in_her_view_is_not_read_again() { + let mut reading = reading_packet(); + reading.in_view_reads = vec![crate::projection::read::ReadRequest::Repo("GameCult/Lodur".into())]; + let prose = "I want to see what Nibu changed in Lodur."; + let again = asked(&reading, prose, json!({ "kind": "domain", "target": "d1", "quote": "I want to see what Nibu changed in Lodur" })); + assert_eq!((again["read"].clone(), again["read_refused"][0]["why"].as_str()), (Value::Null, Some("in_view")), "{again}"); + let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": again, "posted": [] })).unwrap(); + assert!(outcome.lines(packet().forms).is_empty(), "reported, never told"); + assert!(speech_prompt(&reading, "x", prose, &Tuning::default()).contains("Already in his view, so never named as a read: GameCult/Lodur on the forge.")); +} diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index 827ae51..0f7b230 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -81,9 +81,9 @@ enum Part { Closed { how: How, to: String, words: String, room: String, by: String }, /// A close the commit refused: the promise stands, and why. StillOpen { reason: StateRefusal, to: String, words: String }, - /// A read she performed (map 16.22.3): what, in code's words, and the passage of her thought that reached for it; - /// never its content. - Read { what: String, quote: String }, + /// A read she performed (map 16.22.3): what, in code's words; never its content, which is in her view while the + /// conversation lasts (K26), and no sentence about what she lacks. + Read { what: String }, /// A read that returned nothing, and why, from code's table. ReadFailed { what: String, failure: ReadFailure }, /// A read she reached for that a rule or a cap refused, and why; what it was only when a cap refused it, since a @@ -240,7 +240,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { // What she read last wake, without its content: what she made of it is in her memories if her commit wrote one. for read in decision["reads"].as_array().into_iter().flatten() { match (words(&read["what"]), read["ok"].as_bool(), words(&read["quote"]), serde_json::from_value::(read["failure"].clone())) { - (Some(what), Some(true), Some(quote), _) => outcome.parts.push(Part::Read { what, quote }), + (Some(what), Some(true), _, _) => outcome.parts.push(Part::Read { what }), (Some(what), Some(false), _, Ok(failure)) => outcome.parts.push(Part::ReadFailed { what, failure }), _ => outcome.omitted.push(format!("a read she cannot be told truly: {read}")), } @@ -330,7 +330,7 @@ impl Part { Self::Closed { how: How::Released, by, words, .. } => format!("{by} let {obj} off {poss} promise: {}.", quoted(words)), Self::Closed { to, words, .. } => format!("{} promise to {to}, {}, is closed:", capitalized(poss), quoted(words)), Self::StillOpen { to, words, .. } => format!("{} promise to {to}, {}, is still open:", capitalized(poss), quoted(words)), - Self::Read { what, quote } => format!("{cap_subj} read {what}, because of {poss} thought: {}.", quoted(quote)), + Self::Read { what } => format!("{cap_subj} read {what}."), Self::ReadFailed { what, .. } => format!("{cap_subj} reached for {what} and could not read it:"), Self::ReadRefused { what: Some(what), .. } => format!("{cap_subj} reached for {what} and it was not read:"), Self::ReadRefused { what: None, .. } => format!("{cap_subj} reached for something to read and it was not read:"), @@ -390,7 +390,7 @@ impl Part { Self::StillOpen { reason: StateRefusal::NotWherePromised, .. } => format!(" what {subj} said to close it was not where the person {subj} promised could read it."), Self::StillOpen { .. } => format!(" it was changed outside {poss} turn, and stands as it was changed."), Self::BrokeAfter { .. } => format!(" the rest of that turn broke off, not by {poss} choice."), - Self::Read { .. } => format!(" It is not in front of {obj} now."), + Self::Read { .. } => String::new(), Self::ReadFailed { failure, .. } => format!(" {}.", failure.words()), Self::ReadRefused { why, .. } => format!(" {}.", why.words(her)), } diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index 67b6c13..d4e1952 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -126,6 +126,8 @@ pub(crate) enum ReadRefusal { QuoteNotInHerThought, QuoteNotLocated, MalformedTarget, + /// Its latest result is in her view already (K26). + InView, NoSuchDomainLine, NoRecallWords, NotAGamecultRepo, @@ -155,6 +157,7 @@ impl ReadRefusal { Self::NotTheContract => "the read could not be named".to_owned(), Self::QuoteNotInHerThought | Self::QuoteNotLocated => format!("nothing in {poss} thought reached for it"), Self::MalformedTarget => "the read could not be named".to_owned(), + Self::InView => format!("it is in front of {obj} already"), Self::NoSuchDomainLine => format!("it is no line of what moved in {poss} domain"), Self::NoRecallWords => "there was nothing to recall by".to_owned(), Self::NotAGamecultRepo => "it is not a public GameCult repo".to_owned(), diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index 8afd924..79a41e6 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -36,6 +36,8 @@ use unicode_segmentation::UnicodeSegmentation; use super::Affordance; use super::domain::{About, Digest, Item, floor_minute}; +use super::exchange::{self, Exchange}; +use super::read::ReadRequest; use super::outcome::Outcome; use super::tuning::{LensWeights, Tuning}; use crate::address::localpart; @@ -226,6 +228,9 @@ pub(crate) struct Inputs<'a> { /// What moved in her domain lately, every item of the window, newest first (`domain::digest`, map 16.22.2): none when /// moved, and when the read failed, which the report says. pub domain: Option<&'a Digest>, + /// What she has said and read in this conversation (`exchange::exchange_of`, map 16.24.1, K26): none when the turn has + /// no room or no records. + pub exchange: Option<&'a Exchange>, } /// Where a turn begins. @@ -351,6 +356,8 @@ pub(crate) struct Packet { pub now_ms: u64, /// Her own Matrix id: her pronouns are not listed among the people named (`named_pronouns`). pub own_sender: String, + /// The reads whose latest result is in her view this turn: not read again (K26), and marked for the Interpreter. + pub in_view_reads: Vec, /// 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, @@ -2197,9 +2204,11 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { let selected = taken.into_iter().map(|candidate| Pick { id: candidate.id, pool: candidate.pool, log_score: candidate.log_score }).collect(); // Her view (map 16.23.1): promises, then her domain; the room follows them in what she reads (`narrate::read_after`). let promises_over = promises_view.len() > tuning.select.promises_bytes; - let in_view = [promises_view.as_str(), domain_view.as_str()].into_iter().filter(|part| !part.is_empty()).collect::>().join("\n\n"); + // Her side of the conversation, between her promises and her domain (map 16.24.1). + let (exchange_view, in_view_reads) = inputs.exchange.map(|exchange| exchange::render(exchange, her, tuning.select.exchange_bytes, inputs.now)).unwrap_or_default(); + let in_view = [promises_view.as_str(), exchange_view.as_str(), domain_view.as_str()].into_iter().filter(|part| !part.is_empty()).collect::>().join("\n\n"); 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, own_sender: inputs.people.own_sender.to_owned(), 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(), in_view_reads, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } } diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index 538c18c..f29a1ea 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -360,6 +360,8 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) let mut recent: Vec>> = vec![Vec::new(); members.len()]; // Each persona's last turn's record, as the commit's trace will hold it: what came of it opens her next packet. let mut last: Vec> = vec![None; members.len()]; + // Every turn record of hers, oldest first: what she has said and read in a conversation is read from them (K26). + let mut records: Vec> = vec![Vec::new(); members.len()]; let mut turns = Vec::new(); // Every note to Self the run's turns left, oldest first: what Self's inbox reader (C5) will list from the traces. let mut inbox: Vec = Vec::new(); @@ -419,6 +421,7 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) own_rooms: member.entry.own_rooms.clone(), last_outcome: last[at].take(), last_wake: last_turn[at], + records: records[at].clone(), }; let view = View { lines: &lines, viewer: &id, rooms: &member.rooms, seen: &seen[at] }; let names = Names(&member.addressee); @@ -490,6 +493,7 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) let (state, applied) = commit::apply(&members[at].state, &record, render["persona"]["prose"].as_str().unwrap_or_default(), &format!("r{}-t{counter}", repeat + 1), now); record["committed"] = json!(applied); last[at] = Some(record.clone()); + records[at].push(record.clone()); let line = (!spoken.is_empty()).then(|| spoken.join(" / ")); let outcome = if failed.is_some() { "failed" } else if line.is_some() { "spoke" } else { "silent" }; let (how, by) = why.map_or((None, vec![]), |why| (why.how, why.by)); diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 2040f39..a162ae2 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -101,7 +101,7 @@ fn packet_of(kind: TurnKind, state: &Value, room: &Room, history: &History, seed fn packet_tuned(kind: TurnKind, state: &Value, room: &Room, history: &History, seed: u64, tuning: &Tuning) -> Packet { let operators = operators(); let minds = minds(); - let inputs = Inputs { kind, state, room, history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed, affordances: CAN, domain: None }; + let inputs = Inputs { kind, state, room, history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed, affordances: CAN, domain: None, exchange: None }; select(&inputs, tuning) } @@ -575,7 +575,7 @@ fn reflection_and_follow_up_stimuli() { let operators = operators(); let room = Room::default(); let history = History::default(); - let inputs = Inputs { kind: TurnKind::FollowUp, state: &state(), room: &room, history: &history, observation: Some("Libby's change deleted 40 lines."), people: People { operators: &operators, minds: &[], own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: None }; + let inputs = Inputs { kind: TurnKind::FollowUp, state: &state(), room: &room, history: &history, observation: Some("Libby's change deleted 40 lines."), people: People { operators: &operators, minds: &[], own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: None, exchange: None }; let state_value = state(); let follow = select(&Inputs { state: &state_value, ..inputs }, &Tuning::default()); assert_eq!(follow.stimulus, "She just found: Libby's change deleted 40 lines."); @@ -942,7 +942,7 @@ impl PersonaSource for Stored { } fn request(dir: &std::path::Path, renders: Option, judge_against: Option) -> Request { - Request { instance: INSTANCE.into(), kind: TurnKind::Chat, state: None, room: Some("#swarm:gamecult.org".into()), seed: 5, renders, judge_against, operators: operators(), minds: minds(), own_sender: OWN.into(), tuning: dir.join(TUNING_FILE), through: Through::Projector, last_heard: vec![], recent: vec![], own_rooms: vec![], last_outcome: None, last_wake: None } + Request { instance: INSTANCE.into(), kind: TurnKind::Chat, state: None, room: Some("#swarm:gamecult.org".into()), seed: 5, renders, judge_against, operators: operators(), minds: minds(), own_sender: OWN.into(), tuning: dir.join(TUNING_FILE), through: Through::Projector, last_heard: vec![], recent: vec![], own_rooms: vec![], last_outcome: None, last_wake: None, records: vec![] } } /// A human's line in her own room is to her (the humans_pace ruling: it always wakes her), with no name and no tag: the arrival @@ -2641,7 +2641,7 @@ fn k22_a_closed_promise_is_told_once_in_the_next_outcome() { fn packet_with_domain(digest: Option<&domain::Digest>, tuning: &Tuning) -> Packet { let (operators, minds, history, room) = (operators(), minds(), History::default(), chat_room()); - let inputs = Inputs { kind: TurnKind::Chat, state: &state(), room: &room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: digest }; + let inputs = Inputs { kind: TurnKind::Chat, state: &state(), room: &room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: digest, exchange: None }; select(&inputs, tuning) } @@ -2721,7 +2721,7 @@ fn k25_the_outcome_guard_withholds_only_others_words() { 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 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, exchange: None }, &Tuning::default()); let echo = "Yes, the blue lantern sways at midnight."; let mine = "I'll send the render tonight, after the boil."; let model = crate::projection::harness::tests::Scripted::new(|_| String::new()).interpreting(|_| json!({ "say": [{ "draft": 1 }, { "draft": 2 }], "gaps": [] }).to_string()); diff --git a/crates/mind-body/src/projection/tuning.rs b/crates/mind-body/src/projection/tuning.rs index 565168f..fec7084 100644 --- a/crates/mind-body/src/projection/tuning.rs +++ b/crates/mind-body/src/projection/tuning.rs @@ -143,6 +143,9 @@ pub struct SelectTuning { /// Her domain in her view, in bytes, headings included (map 16.23.3): her main window on her domain, so generous, Soul's /// 3000 B log and a margin. A busier window does not crowd her view: it shrinks from its old end to what fits. pub domain_bytes: usize, + /// What she has said and read in this conversation, in her view, in bytes, heading included (map 16.24.1): past it the + /// window shrinks from its old end. + pub exchange_bytes: usize, pub stimulus_bytes: usize, /// What was said to her, verbatim, for the Persona stage: on a chat turn, the room's earlier lines too, before the new /// ones (map 16.20.3). @@ -248,6 +251,7 @@ impl Default for SelectTuning { outcome_bytes: 1200, promises_bytes: 2000, domain_bytes: 4000, + exchange_bytes: 3000, stimulus_bytes: 1500, heard_bytes: 2500, addressed_bytes: 8 * 1024, @@ -332,6 +336,7 @@ impl Tuning { ("select.outcome_bytes", select.outcome_bytes), ("select.promises_bytes", select.promises_bytes), ("select.domain_bytes", select.domain_bytes), + ("select.exchange_bytes", select.exchange_bytes), ("select.stimulus_bytes", select.stimulus_bytes), ("select.heard_bytes", select.heard_bytes), ("select.identity_bytes", select.identity_bytes),