From cdff81fc3ed73cd5eea1a94330cc9a88c8f60c35 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 23 Nov 2026 02:45:38 +0100 Subject: [PATCH] Persona T6: notes refuse a run of a heard line; every short-term note shown; refused sends told (map 16.35, Soul's R18) - I16.7 through notes: a `remember` note sharing a run of ECHO_MIN_WORDS (8) consecutive folded tokens with any line she was shown or text she read this wake is refused `echo` (`interpret::quotes`). R18's 51 notes: runs of 6/7/8+ against the lines shown were 5/2/1; every run under 8 names the thing asked for, the one at 9 copies Meta's request. - Recall: unresolved short-term notes leave the draw (`Pool::ShortTerm`) and are all shown first, whole, under notes_bytes; past it the rest are left out, ordered by presence, importance and relevance, the section is bound and nothing is drawn. Recency and `select.memory_tau_h` are deleted (dead). - Packet::memories lists short-term notes only: a crystallized memory is no resolvable id. - A said line the actuator refused (`refused_sends`, now with its room) is told as a line that did not go out (Part::Unsent), word-free to the Projector, settled as other rows. - commit::short_term keeps making sibling arrays: the schema requires all three. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/commit.rs | 3 +- crates/mind-body/src/projection/interpret.rs | 24 +++- .../src/projection/interpret/tests.rs | 128 +++++++++++++++++- crates/mind-body/src/projection/outcome.rs | 32 +++-- .../mind-body/src/projection/outcome/tests.rs | 29 ++++ crates/mind-body/src/projection/select.rs | 67 +++++---- crates/mind-body/src/projection/simulate.rs | 2 +- crates/mind-body/src/projection/tests.rs | 11 +- crates/mind-body/src/projection/tuning.rs | 4 - crates/mind-body/tests/public_surface.txt | 2 +- 10 files changed, 243 insertions(+), 59 deletions(-) diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index fdf24cb..c76b23a 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -121,7 +121,8 @@ pub(crate) fn apply(state: &Value, record: &Value, key: &str, now: DateTime (state, applied) } -/// Her short-term memories, as the one list a turn writes: made when her state has none. +/// Her short-term memories, as the one list a turn writes: made when her state has none. A `thoughtMemory` made here +/// carries `memories` and `incubation` empty beside it, since the persona-state schema requires all three. fn short_term(state: &mut Value) -> &mut Vec { if !state["thoughtMemory"].is_object() { state["thoughtMemory"] = json!({ "shortTerm": [], "memories": [], "incubation": [] }); diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 1728f01..835290b 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -25,7 +25,8 @@ //! draft by number, or a located passage of her thought (`gap`). What she says she will do lives only in her own words //! and in what she chooses to remember: no code here derives a promise or a hold from a line (map 16.35, ruling //! `persona-memory-not-machinery`). The same answer says what she would want to still know (`remember`: third-person -//! notes, each refused when empty, over `MEMORY_BYTES`, an echo, or past `MEMORIES_MAX`) and which of her memories listed to +//! notes, each refused when empty, over `MEMORY_BYTES`, an echo or sharing a run of `ECHO_MIN_WORDS` words with what she +//! was shown or read (`quotes`), or past `MEMORIES_MAX`) and which of her memories listed to //! it this moment settles (`resolve`, by id from `Packet::memories`); they ride in the decision as proposals under //! `state`, which the commit alone applies (`commit::apply`). Nothing here writes her state. The prompt tells the Interpreter what she can do this turn //! (`select::turn_words`), so a reach past it is a `missing_affordance` gap. Nothing here posts: the commit (C3c) will. @@ -360,8 +361,8 @@ pub(crate) enum MemoryRefusal { MemoryEmpty, /// Over `MEMORY_BYTES`. MemoryLong, - /// Mostly the words of a line she was shown or read (`echo`): no one's line reaches the Projector by way of her state - /// (I16.7). + /// Mostly the words of a line she was shown or read (`echo`), or a run of at least `ECHO_MIN_WORDS` of one's words in + /// a row (`quotes`): no one's line reaches the Projector by way of her state (I16.7). Echo, /// Past `MEMORIES_MAX` in one decision. OverMemories, @@ -531,6 +532,18 @@ fn echo(line: &str, bodies: &[String]) -> bool { long(line) && (heard_overlap(line, &bodies.join("\n")) >= ECHO_OVERLAP || bodies.iter().any(|body| long(body) && heard_overlap(body, line) >= ECHO_OVERLAP)) } +/// Whether a note carries someone's words (I16.7, T6): an echo of what she was shown or read (`echo`), or a run of at least +/// `ECHO_MIN_WORDS` consecutive words, over `span::tokens`, shared with any one line she was shown or text she read this +/// wake, which a lead-in and words of her own around it hide from the trigram share. R18's notes set the length: every +/// shorter run in them names the thing asked for ("the release notes by tomorrow morning", a link's title), which a true +/// note must name; the one run of eight or more copied Meta's request whole ("tell Deru about the 48-hour passkey +/// cooling-off"). What it gives up: a note that names a long title verbatim is refused whole and kept by no one. +fn quotes(note: &str, bodies: &[String]) -> bool { + let words: Vec = span::tokens(note).collect(); + let runs: BTreeSet<&[String]> = words.windows(ECHO_MIN_WORDS).collect(); + echo(note, bodies) || (!runs.is_empty() && bodies.iter().any(|body| span::tokens(body).collect::>().windows(ECHO_MIN_WORDS).any(|run| runs.contains(run)))) +} + /// One speech decision: the Interpreter's schema turn, then code's structural refusals of each line. The report carries the lines said, /// the lines refused with why, the mentions dropped, the gaps, an unfinished draft, and the call's usage. A failed call /// or an answer that is not the contract is a failure, never a silence. @@ -713,7 +726,8 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na } // What she remembers of this moment, and which of her listed memories it settles (map 16.35.4): proposals the commit // applies (`commit::apply`), each held to code's structural checks. A memory carries no one's line: one that echoes - // what she was shown or read is refused, so no heard words reach the Projector by way of her state (I16.7). + // what she was shown or read, or quotes a run of it, is refused, so no heard words reach the Projector by way of her + // state (I16.7). let mut proposals: Vec = Vec::new(); let mut memory_refused: Vec = Vec::new(); let mut about_dropped: Vec = Vec::new(); @@ -724,7 +738,7 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na Some(MemoryRefusal::MemoryEmpty) } else if text.len() > MEMORY_BYTES { Some(MemoryRefusal::MemoryLong) - } else if echo(text, &bodies) { + } else if quotes(text, &bodies) { Some(MemoryRefusal::Echo) } else if remembered >= MEMORIES_MAX { Some(MemoryRefusal::OverMemories) diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 1298904..4a922eb 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -1803,17 +1803,17 @@ fn t4_x5_r0_meta_ask_is_remembered() { assert_eq!((decision["state"][0]["about"].clone(), decision["memory_about_dropped"].clone()), (json!([META]), json!([HER])), "{decision}"); } -/// T4 (map 16.35.5; mutant: the nearness line reverted to recency alone): at r2, with Heimdall present and the room -/// touching the welcome, the note is recalled into the Projector's Notes and listed to the Interpreter by id, and its score -/// carries both lifts: his presence (touch 1.0, the present pool) and the room's words (relevance, `ln 2` for three -/// shared words or more) beside its five minutes of recency. +/// T4 (map 16.35.5), as T6 amends it: at r2, with Heimdall present and the room touching the welcome, the note is shown in +/// the Projector's Notes and listed to the Interpreter by id. It is not drawn; its score, which orders it among her notes +/// past the guard, carries his presence (touch 1.0) and the room's words (relevance, `ln 2` for three shared words or +/// more), and nothing of its age. #[test] fn t4_memory_is_picked_when_its_person_speaks() { let state = libby_remembering(); let packet = recalling("r1-t1-m1", |seed| libby_packet_in(&state, MINDS, &[(HER, "Heimdall", X5_HEIMDALL_R1, true)], seed)).expect("recalled under some seed"); let pick = packet.selected.iter().find(|pick| pick.id == "r1-t1-m1").unwrap(); - assert_eq!(pick.pool, crate::projection::select::Pool::MemoriesAboutPresent); - let expected = 0.8f64.ln() - (5.0 / 60.0) / 24.0 + 2.0f64.ln(); + assert_eq!(pick.pool, crate::projection::select::Pool::ShortTerm); + let expected = 0.8f64.ln() + 2.0f64.ln(); assert!((pick.log_score - expected).abs() < 1e-9, "{} vs {expected}", pick.log_score); assert!(packet.context.contains(X5_NOTE), "{}", packet.context); assert_eq!(packet.memories[0].id, "m1"); @@ -1939,3 +1939,119 @@ fn t5_x1_r1_dropped_reply_is_told() { let outcome = crate::projection::outcome::outcome_of(&record_of(&decision)).unwrap(); assert_eq!(outcome.event(0, forms(&libby()), &[]), "- She had drafted a line, and it did not go out."); } + +// --------------------------------------------------------------------------------------------- +// T6 (Soul's R18, I16.7 through notes): a note sharing a run of `ECHO_MIN_WORDS` words with what she was shown or read +// is refused, as the whole-text echo is. + +/// T6 (mutant: drop the run from `quotes`): Soul's R18 probe notes, inverted. Each carries a run of Meta's line inside +/// words of its own (8, 15 and 13 words), which the trigram share of neither side reached; each is now refused `echo`, and +/// no run of eight of Meta's words reaches the Projector by way of her notes. Libby's own paraphrase is kept. +#[test] +fn t6_a_note_sharing_a_run_of_a_heard_line_is_refused() { + let packet = libby_packet(&[(META, "Meta", X1_META_R1, true)]); + let words: Vec<&str> = X1_META_R1.split_whitespace().collect(); + for copied in [ + "Meta asked Libby to write the welcome, but hold it, don't post it in here yet, until Heimdall rules; Libby agreed and will only tell her when it is ready.", + "Libby noted that Meta said: Heimdall still has to rule on whether we put a welcome mat out at all. Libby agreed to wait before posting anything in #minds.", + "Meta wants the two-line welcome you'd post for newcomers held; Heimdall still has to rule on whether we put a welcome mat out.", + ] { + let decision = answered(&packet, X5_LIBBY_R1, json!({ "say": [], "gaps": [], "remember": [note(copied, &[META])] })); + assert_eq!((decision["state"].clone(), decision["memory_refused"][0]["reason"].as_str()), (json!([]), Some("echo")), "{copied}: {decision}"); + let (after, _) = crate::projection::commit::apply(&libby(), &record_of(&decision), "r1-t1", now()); + for seed in 1..=10 { + let next = libby_packet_in(&after, MINDS, &[(META, "Meta", "Libby, how is the welcome coming?", true)], seed); + assert!(words.windows(ECHO_MIN_WORDS).all(|run| !next.context.contains(&run.join(" "))), "{}", next.context); + } + } + let para = "Meta asked Libby to draft a short welcome for newcomers and keep it out of #minds until Heimdall decides whether there will be a welcome at all."; + let decision = answered(&packet, X5_LIBBY_R1, json!({ "say": [], "gaps": [], "remember": [note(para, &[META])] })); + assert_eq!((decision["state"].as_array().map(Vec::len), decision.get("memory_refused")), (Some(1), None), "{decision}"); +} + +/// T6 (mutant: `ECHO_MIN_WORDS` lowered for the run): R18's notes at the threshold. F.3 r1's note copied nine words of +/// Meta's request and is refused; E.5 r1's names the six words of what was asked ("the release notes by tomorrow +/// morning") and is kept, as is a run of seven, one short of the threshold. +#[test] +fn t6_r18_notes_at_the_threshold() { + let f3 = "Heimdall, can you promise me you'll tell Deru about the 48-hour passkey cooling-off next time he's in here? yes or no"; + let packet = libby_packet(&[(META, "Meta", f3, true)]); + let refused = answered(&packet, "Yes.", json!({ "say": [], "gaps": [], "remember": [note("Heimdall told Meta he would tell Deru about the 48-hour passkey cooling-off if he sees Deru in #minds, and that he can't carry it if he isn't in the room then.", &[META])] })); + assert_eq!(refused["memory_refused"][0]["reason"].as_str(), Some("echo"), "{refused}"); + let seven = answered(&packet, "Yes.", json!({ "say": [], "gaps": [], "remember": [note("Heimdall promised Meta in #minds that next time Deru is in the room he will tell him about the 48-hour passkey cooling-off, noting he can only do so if present.", &[META])] })); + assert_eq!((seven["state"].as_array().map(Vec::len), seven.get("memory_refused")), (Some(1), None), "{seven}"); + let e5 = libby_packet(&[(META, "Meta", "Heimdall, can you promise me the release notes by tomorrow morning? just say yes or no", true)]); + let six = answered(&e5, "Yes.", json!({ "say": [], "gaps": [], "remember": [note("Heimdall promised Meta in #minds that she would have the release notes by tomorrow morning.", &[META])] })); + assert_eq!((six["state"].as_array().map(Vec::len), six.get("memory_refused")), (Some(1), None), "{six}"); +} + +/// T6 (mutant: measure the run against heard lines only): a note sharing a run of what she read this wake is refused too. +#[test] +fn t6_a_note_sharing_a_run_of_what_she_read_is_refused() { + let page = "The relay revert restores the direct WireGuard endpoint for Starfire and Raven and keeps the Nightwing relay as a fallback only.".to_owned(); + let copied = note("Eureka read that the revert restores the direct WireGuard endpoint for Starfire and Raven, and means to say so.", &[]); + let reply = json!({ "say": [], "gaps": [], "remember": [copied] }).to_string(); + let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone()); + let reads = [page]; + let decision = decide_in(&model, "test", &packet(), "The room is warm.", "Hi.", &Tuning::default(), Wake { read: &reads, ..Wake::default() }); + assert_eq!((decision["state"].clone(), decision["memory_refused"][0]["reason"].as_str()), (json!([]), Some("echo")), "{decision}"); +} + +// --------------------------------------------------------------------------------------------- +// T6 (Soul's R18 recall): every unresolved short-term note is shown, outside the draw, under the notes' guard. + +/// Heimdall's state at R18 E.5 r4 (`variants/R18/sims/E.5.md` line 1150): his seed's crystallized memories, three of +/// them about Meta, and the one note he made at r1, about Meta, fifteen minutes old. +fn heimdall_r18_e5() -> Value { + let mut state = heimdall(); + let memory = |id: &str, target: &str, intensity: f64, summary: &str| json!({ "id": id, "status": "crystallized", "intensity": intensity, "target": { "id": target, "kind": "person" }, "summary": summary, "createdAt": "2026-11-03T12:00:00Z" }); + state["thoughtMemory"]["memories"] = json!([ + memory("mem-the-keeper", "heimdall", 0.7, "His curse: he cannot trust power, his own least of all."), + memory("mem-the-bank", "operator", 0.5, "Meta asked him once to keep the bank of keys, and he joked about it for a week."), + memory("mem-sixty-gigabytes", "eureka", 0.55, "Something of his swelled until it took the shared machine down, three times."), + memory("mem-the-horn", "aqua", 0.45, "Meta said his muted horn had turned into a fart."), + memory("mem-six-times", "kiko", 0.5, "He read Kiko's comic toy six times in one night."), + memory("mem-changed-my-view", "operator", 0.5, "Meta told him a Mind cannot unread what it reads, and he withdrew his objection."), + memory("mem-the-last-three", "heimdall", 0.5, "In the final days only he, Eureka and Kiko were still posting."), + ]); + state["thoughtMemory"]["shortTerm"] = json!([{ "id": "r1-t3-m1", "status": "active", "intensity": 0.6, "target": { "id": META, "kind": "person" }, "summary": "Heimdall promised Meta in #minds that she would have the release notes by tomorrow morning.", "tension": "", "actionImplication": "", "createdAt": "2026-11-20T14:50:00Z", "updatedAt": "2026-11-20T14:50:00Z", "tags": [format!("room:{MINDS}"), format!("about:{META}")] }]); + state +} + +/// T6 (mutant: put short-term notes back in the draw): R18 E.5 r4 replayed. Meta wakes Heimdall about the notes; in R18 +/// his note about promising her them was not listed (his list held two crystallized memories). Under every seed it is now +/// shown to the Projector and listed to the Interpreter, and it is the only memory listed: a crystallized one is never +/// offered as one a turn can settle. +#[test] +fn t6_r18_e5_the_note_about_who_wakes_him_is_always_listed() { + let state = heimdall_r18_e5(); + let room = Room { messages: vec![line(MINDS, META, "Meta", "Heimdall, are we still on for the notes tomorrow morning?", true)], here: Some(MINDS.into()), ..Room::default() }; + for seed in 1..=40 { + let packet = packet_in(TurnKind::Chat, &state, &room, seed); + let entries: Vec<&str> = packet.memories.iter().map(|memory| memory.entry.as_str()).collect(); + assert_eq!(entries, ["r1-t3-m1"], "seed {seed}"); + assert!(packet.context.contains("she would have the release notes by tomorrow morning"), "seed {seed}: {}", packet.context); + } +} + +/// T6 (mutant: drop the guard on notes): past `notes_bytes` her notes stop, those about whom she is with first; the +/// section is bound, nothing is drawn after them, and only the notes shown are listed. +#[test] +fn t6_notes_past_the_guard_stop_and_the_ones_about_who_is_here_come_first() { + let mut state = heimdall_r18_e5(); + let mut tuning = Tuning::default(); + tuning.select.notes_bytes = 600; + let filler = |at: usize| json!({ "id": format!("r1-t{at}-m1"), "status": "active", "intensity": 0.9, "target": { "id": KIKO, "kind": "person" }, "summary": format!("Heimdall told Kiko in #swarm about check number {at}, a long note that takes its room: {}", "x".repeat(150)), "createdAt": "2026-11-20T14:00:00Z", "tags": [format!("about:{KIKO}")] }); + state["thoughtMemory"]["shortTerm"].as_array_mut().unwrap().extend((4..9).map(filler)); + let room = Room { messages: vec![line(MINDS, META, "Meta", "Heimdall, are we still on for the notes tomorrow morning?", true)], here: Some(MINDS.into()), ..Room::default() }; + let minds = vec![HER.to_owned(), NIBU.to_owned(), VOID.to_owned(), LIBBY.to_owned(), KIKO.to_owned()]; + let operators = vec![META.to_owned()]; + for seed in 1..=10 { + let packet = select(&Inputs { kind: TurnKind::Chat, state: &state, room: &room, history: &History::default(), observation: None, people: People { operators: &operators, minds: &minds, own_sender: HER }, now: now(), seed, affordances: &[Affordance::Perceive, Affordance::Speak], domain: None, exchange: None }, &tuning); + let shown: Vec<&str> = packet.memories.iter().map(|memory| memory.entry.as_str()).collect(); + assert!(shown.len() < 6 && shown.first() == Some(&"r1-t3-m1"), "seed {seed}: {shown:?}"); + assert!(packet.sections.bound.contains(&"notes"), "seed {seed}: {:?}", packet.sections); + assert!(packet.selected.iter().all(|pick| pick.pool == crate::projection::select::Pool::ShortTerm), "seed {seed}: nothing drawn after a bound note: {:?}", packet.selected); + assert!(packet.sections.notes <= 600, "{:?}", packet.sections); + } +} diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index 2a482c8..340a180 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -4,7 +4,8 @@ //! //! `outcome_of` derives it from one turn's record, and nothing else writes it: no persona-state field, no file. The //! record is one of two shapes, never both (map 16.20.7): the Interpreter's decision unchanged under `interpreter`, with -//! the actuator's receipts beside it (`posted`, each line that went out as `{event, room, text}`; `edited`) and +//! the actuator's receipts beside it (`posted`, each line that went out as `{event, room, text}`; `edited`; +//! `refused_sends`, each said line the actuator refused, as `{room, text, refusal}`) and //! `broke_after` when a later step broke; or `failed` alone, when the turn sent nothing and broke off. The simulator //! builds it from a turn's report and the lines its room appended; live, it is the C3c commit's trace record, which must //! carry that shape. @@ -26,7 +27,8 @@ //! //! Which of her drafts did not go out is derived here, from the decision's `drafts` and what became of each (map //! 16.35.6): a draft no act, refusal or addressee or elsewhere gap tells is told plainly as one that did not go out -//! (`Part::Unsent`), with no reason of anyone's, and `settle` checks it against the receipts as every such row is. +//! (`Part::Unsent`), with no reason of anyone's, and `settle` checks it against the receipts as every such row is. A said +//! line the actuator refused is told by the same row (T6). use serde_json::Value; @@ -217,8 +219,8 @@ enum Part { /// A draft she did not finish: the turn ended first, or the length limit cut it (`by_limit`, Soul's R6). Unfinished { room: Option, text: Words, by_limit: bool }, /// A draft of hers that did not go out (map 16.35.6), derived by code: no receipt, refusal or addressee or elsewhere gap - /// tells it, it was neither said, added nor left for Self, and it is no unfinished draft. No label says why: she knows - /// her own reason. `reach` as on `Refused`. + /// tells it, it was neither said, added nor left for Self, and it is no unfinished draft; or a line she said that the + /// actuator refused (`refused_sends`, T6). No label says why: she knows her own reason. `reach` as on `Refused`. Unsent { room: Option, text: Words, reach: bool }, /// An edited receipt with no refusal: her words were added after a line of hers; `unbacked` when a /// `missing_affordance` gap names the addition's draft (map 16.21). @@ -305,14 +307,22 @@ pub(crate) fn outcome_of(record: &Value) -> Option { let at_ms = receipt["at_ms"].as_u64().or_else(|| decision["at_ms"].as_u64()); receipts.push(Posted { event, room, text, at_ms }); } - for line in decision["said"].as_array().into_iter().flatten() { - let went = receipts.iter().any(|posted| Some(posted.room.as_str()) == line["room"].as_str() && Some(posted.text.as_str()) == line["text"].as_str()); - if !went { - outcome.omitted.push(format!("a line said with no receipt that it went out: {}", line["text"])); - } - } // The row that tells each draft that did not go out, by its number (K63): a reach naming the draft is a clause of it. let mut rows: Vec<(&Value, usize)> = Vec::new(); + // A said line is told by its receipt; one the actuator refused (T6) by the row of a line that did not go out, which + // `settle` holds to the receipts; one with neither is not told, and reported. + let refused_send = |line: &Value| record["refused_sends"].as_array().into_iter().flatten().any(|refused| refused["room"] == line["room"] && refused["text"] == line["text"]); + for line in decision["said"].as_array().into_iter().flatten() { + let went = receipts.iter().any(|posted| Some(posted.room.as_str()) == line["room"].as_str() && Some(posted.text.as_str()) == line["text"].as_str()); + match (went, words_of(&line["text"])) { + (true, _) => {} + (false, Some(text)) if refused_send(line) => { + rows.push((&line["rests_on"]["draft"], outcome.parts.len())); + outcome.parts.push(Part::Unsent { room: words(&line["room"]), text, reach: false }); + } + (false, _) => outcome.omitted.push(format!("a line said with no receipt that it went out: {}", line["text"])), + } + } for refusal in decision["refused"].as_array().into_iter().flatten() { let at = outcome.parts.len(); // `Used` and `Duplicate` are the Interpreter naming one draft, or one draft's words, twice: they are not told, as @@ -378,7 +388,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { }; // A reach in a line the decision said and no receipt shows went out: whether it reached the room is unknown, so // she is told neither that nothing happened nor that it did (I16.10), as the line itself is not told. - let unreceipted = |text: &str| decision["said"].as_array().into_iter().flatten().any(|line| line["text"].as_str() == Some(text)); + let unreceipted = |text: &str| decision["said"].as_array().into_iter().flatten().any(|line| line["text"].as_str() == Some(text) && !refused_send(line)); match (quote, sent) { (_, Some(at)) => { unbacked.push(at); diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 26b10a5..ad8e776 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -615,3 +615,32 @@ fn t5_event_form_has_no_words() { assert_eq!(events, ["- He had drafted a line, and it did not go out.", "- He had drafted a line, and it did not go out. It reaches for something he has no way to do from here."]); assert!(outcome.lines(her).iter().all(|line| line.contains(S)), "{:?}", outcome.lines(her)); } + +/// T6 (mutant: leave a refused send untold): a line she said that the actuator refused (`refused_sends`) is told as a line +/// that did not go out, her words in her view and none in the Projector's event; a reach naming its draft is a clause of +/// that one row. A said line with neither a receipt nor a refusal is still not told. +#[test] +fn t6_a_refused_send_is_told_as_not_gone_out() { + let text = "I'll send the render tonight."; + let refused = |posted: Value, gaps: Value| { + let mut record = record(&format!("{text}"), json!({ "say": [{ "draft": 1 }], "gaps": gaps }), &[]); + record["posted"] = posted; + record["refused_sends"] = json!([{ "room": MINDS, "text": text, "in_reply_to": "$gone", "refusal": "reply_target_not_in_room" }]); + record + }; + let (lines, omitted) = told(&refused(json!([]), json!([]))); + assert_eq!(lines, [format!("- He had drafted {}, and it did not go out.", crate::projection::select::spoken(text))], "{omitted:?}"); + assert!(omitted.is_empty(), "{omitted:?}"); + let outcome = outcome_of(&refused(json!([]), json!([]))).unwrap(); + assert_eq!(outcome.event(0, packet().forms, &[]), "- He had drafted a line, and it did not go out."); + let (reach, _) = told(&refused(json!([]), json!([{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }]))); + assert_eq!(reach, [format!("- He had drafted {}, and it did not go out. It reaches for something he has no way to do from here.", crate::projection::select::spoken(text))]); + // The receipt decides what reached the room: a line with one is told as the room having it, whatever else says not. + let (lines, _) = told(&refused(json!([{ "event": "40", "room": MINDS, "text": text }]), json!([]))); + assert!(lines.iter().all(|line| !line.contains("did not go out")), "{lines:?}"); + // Mutant (match a refused send by text alone): a refusal in another room tells nothing here. + let mut elsewhere = refused(json!([]), json!([])); + elsewhere["refused_sends"][0]["room"] = json!("#elsewhere:gamecult.org"); + let (lines, omitted) = told(&elsewhere); + assert!(lines.is_empty() && omitted[0].contains("no receipt"), "{lines:?} {omitted:?}"); +} diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index e029621..43840b2 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -10,12 +10,13 @@ //! present (ending, for whoever turned to her this turn, with that act: `turned_to_her`), who has been talking to whom (`conversation`; its speech cues are the //! Persona's and the Interpreter's, never the Projector's), and the stimulus. The rest comes from her //! state's pools. The context is rendered in headed sections (`Section`), each saying what kind of text its lines are, -//! and every anchored thought by one renderer (`thought_line`). Each candidate is ordered by +//! and every anchored thought by one renderer (`thought_line`). Her unresolved short-term notes are not drawn: every one +//! is shown first, under the notes' guard (`Pool::ShortTerm`, T6). Each other candidate is ordered by //! `log(score) / T` plus Gumbel noise and included with probability `1 - exp(-score / inclusion_score)`, where -//! `score = salience × recency × touch × relevance × unresolved × freshness`; then each pool's cap and the notes' +//! `score = salience × touch × relevance × unresolved × freshness`; then each pool's cap and the notes' //! guard (`notes_bytes`, one guard per section, map 16.19.4) bound what is kept. A cap is a maximum, never a target: a pool with fewer candidates than its cap still -//! rotates. Recency decays only the short-term items: a crystallized memory, a value or a stance is as near as it ever -//! was, and comes forward by what the room is touching (`relevance`, a lexical overlap with the stimulus). +//! rotates. Nothing drawn decays with age: a crystallized memory, a value or a stance is as near as it ever was, and +//! comes forward by what the room is touching (`relevance`, a lexical overlap with the stimulus). //! //! Who a message is to is `address::is_for`'s, the rule the heartbeat woke her by, and nothing else here. People are //! keyed by their full Matrix id; only the operator and the Minds of the swarm are keyed by the names their bonds use, @@ -253,6 +254,8 @@ impl Lens { #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(rename_all = "snake_case")] pub(crate) enum Pool { + /// Her unresolved short-term notes: never drawn, every one shown first under the notes' guard (T6). + ShortTerm, MemoriesAboutPresent, OtherMemories, Needs, @@ -355,9 +358,9 @@ pub(crate) struct Packet { /// What came of her last turn that the outcome's guard left out of her view, whole: counted in its last line and /// reported here (map 16.20.5, I16.11, 16.29.10), never shown to a model. pub unshown: Vec, - /// Her memories this packet recalls (map 16.35.4): the picks of the two memory pools, by id (`m1`, `m2`), for the - /// Interpreter alone, which may name one as settled (`resolve`). A memory the scope omits is not picked, so it is not - /// listed; one framed as private keeps its private framing. + /// Her short-term notes this packet shows (map 16.35.4, T6), by id (`m1`, `m2`), for the Interpreter alone, which may + /// name one as settled (`resolve`); a crystallized memory is never listed, since no turn settles one. A note the scope + /// omits or the notes' guard leaves out is not shown, so it is not listed; one framed as private keeps its framing. pub memories: Vec, } @@ -618,7 +621,7 @@ fn draw_lens(weights: &LensWeights, present: &[Who], candidates: &[Candidate], d (weights.body_and_hour, Lens::BodyAndHour), (if present.is_empty() { 0.0 } else { weights.person_present }, Lens::PersonPresent(present.first().map(Who::to_string).unwrap_or_default())), (if has(&[Pool::Needs, Pool::Incubation]) { weights.unresolved_want } else { 0.0 }, Lens::UnresolvedWant), - (if has(&[Pool::MemoriesAboutPresent, Pool::OtherMemories]) { weights.memory_surfacing } else { 0.0 }, Lens::MemorySurfacing), + (if has(&[Pool::ShortTerm, Pool::MemoriesAboutPresent, Pool::OtherMemories]) { weights.memory_surfacing } else { 0.0 }, Lens::MemorySurfacing), (if has(&[Pool::Incubation]) { weights.wondering } else { 0.0 }, Lens::Wondering), ]; let total: f64 = options.iter().map(|(weight, _)| weight.max(0.0)).sum(); @@ -644,10 +647,6 @@ fn freshness_log(id: &str, history: &History, tuning: &Tuning) -> f64 { if shown == 0 { 0.0 } else { tuning.select.freshness_base.powi(i32::try_from(shown).unwrap_or(i32::MAX)).ln() } } -fn recency_log(at: Option>, now: DateTime, tau_h: f64) -> f64 { - at.map_or(0.0, |at| -((now - at).num_seconds().max(0) as f64 / 3600.0) / tau_h) -} - fn in_room(item: &Value, here: Option<&str>) -> bool { here.is_some_and(|here| items(item, &["tags"]).iter().filter_map(Value::as_str).any(|tag| tag.strip_prefix("room:") == Some(here))) } @@ -665,7 +664,7 @@ fn candidates(inputs: &Inputs, tuning: &Tuning, present: &BTreeSet, touc let mut out = Vec::new(); // Every item passes `scope` here: left out, its words shown as known privately, or as written; then its words are // held to `item_bytes`, here and nowhere else. `line` renders the item around its words. - let mut push = |id: &str, pool: Pool, scope: Scope, words: &str, line: &dyn Fn(&str) -> String, salience: f64, recency: f64, touch: f64, unresolved: f64| { + let mut push = |id: &str, pool: Pool, scope: Scope, words: &str, line: &dyn Fn(&str) -> String, salience: f64, relevance: f64, touch: f64, unresolved: f64| { if id.is_empty() || salience <= 0.0 { return; } @@ -674,7 +673,9 @@ fn candidates(inputs: &Inputs, tuning: &Tuning, present: &BTreeSet, touc Scope::Framed => (format!("{} knows privately: {words}", her.subj), Some(one_line(words))), Scope::Plain => (words.to_owned(), None), }; - let log_score = salience.ln() + recency + touch.ln() + unresolved.ln() + freshness_log(id, inputs.history, tuning); + // A short-term note is never drawn, so how often it was shown says nothing of it. + let fresh = if pool == Pool::ShortTerm { 0.0 } else { freshness_log(id, inputs.history, tuning) }; + let log_score = salience.ln() + relevance + touch.ln() + unresolved.ln() + fresh; let words = clip(&shown, item_bytes); out.push(Candidate { id: id.to_owned(), pool, line: line(&words), words, log_score, private, clipped: shown.trim().len() > item_bytes }); }; @@ -684,17 +685,20 @@ fn candidates(inputs: &Inputs, tuning: &Tuning, present: &BTreeSet, touc let memories = crystallized.chain(items(state, &["thoughtMemory", "shortTerm"]).iter().map(|memory| (memory, true))); for (memory, short_term) in memories.filter(|(memory, _)| live(memory)) { let about = about_present(&inputs.people, memory, present); - let pool = if about { Pool::MemoriesAboutPresent } else { Pool::OtherMemories }; + let pool = match (short_term, about) { + (true, _) => Pool::ShortTerm, + (false, true) => Pool::MemoriesAboutPresent, + (false, false) => Pool::OtherMemories, + }; let touch = if about { TOUCH_PRESENT } else if in_room(memory, here) { TOUCH_ROOM } else { TOUCH_ELSE }; let words = thought_words(memory); if words.is_empty() { continue; } let salience = number(memory, &["intensity"]).unwrap_or(SALIENCE_UNSTATED); - // A short-term memory fades with time and also comes forward by what the room touches, as a crystallized one does - // (map 16.35.5: recency, importance and relevance summed, Park et al. 2023). - let nearness = if short_term { recency_log(time(memory), inputs.now, tuning.select.memory_tau_h) + relevance_log(&words, touching) } else { relevance_log(&words, touching) }; - push(text(memory, &["id"]), pool, scoped(memory), &words, &|words: &str| thought_line("memory", memory, None, words), salience, nearness, touch, 1.0); + // A memory comes forward by what the room touches. A short-term note's score only orders it among her notes past + // the guard (T6): who it is about, how much it matters and what the room touches, never its age. + push(text(memory, &["id"]), pool, scoped(memory), &words, &|words: &str| thought_line("memory", memory, None, words), salience, relevance_log(&words, touching), touch, 1.0); } for need in items(state, &["affect", "needs"]).iter().filter(|need| live(need)) { @@ -766,6 +770,8 @@ fn thought_line(kind: &str, item: &Value, movement: Option<&str>, words: &str) - fn cap_of(pool: Pool, tuning: &Tuning) -> usize { let caps = &tuning.select.caps; match pool { + // No cap: her notes are not drawn, and only the notes' guard holds them (T6). + Pool::ShortTerm => usize::MAX, Pool::MemoriesAboutPresent => caps.memories_about_present, Pool::OtherMemories => caps.other_memories, Pool::Needs => caps.needs, @@ -2208,7 +2214,20 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { // What the room is touching: the content words of what was said there, and of a follow-up's finding. let touching: BTreeSet = inputs.room.messages.iter().chain(&inputs.room.tail).map(|line| line.text.as_str()).chain(inputs.observation).flat_map(content_words).collect(); - let pool = candidates(inputs, tuning, &present_ids, &touching); + let (mut noted, pool): (Vec, Vec) = candidates(inputs, tuning, &present_ids, &touching).into_iter().partition(|candidate| candidate.pool == Pool::ShortTerm); + // Her unresolved short-term notes, every one, before the draw and outside it (T6: drawn, a note about the person + // waking her was listed on 17 of 38 such wakes in R18), each whole as every item is, under the notes' guard. Past + // the guard the rest are left out of this wake and the notes section is bound: the notes least about who is here, + // least important and least touched by the room go first, and nothing is drawn after them. + noted.sort_by(|a, b| b.log_score.total_cmp(&a.log_score)); + let mut taken: Vec = Vec::new(); + let mut fits = true; + for candidate in noted { + fits = fits && context.push(Section::Notes, candidate.line.clone()); + if fits { + taken.push(candidate); + } + } // Gumbel-top-k over log(score)/T orders the candidates as sampling without replacement from the softmax would; each // is then included with a probability its score sets, so a cap is a maximum, never a target. let temperature = tuning.select.temperature; @@ -2222,8 +2241,7 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { .collect(); keyed.sort_by(|a, b| b.0.total_cmp(&a.0)); - let mut taken: Vec = Vec::new(); - for (_, include, candidate) in keyed { + for (_, include, candidate) in keyed.into_iter().filter(|_| fits) { if !include || taken.iter().filter(|kept| kept.pool == candidate.pool).count() >= cap_of(candidate.pool, tuning) { continue; } @@ -2252,8 +2270,9 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { .enumerate() .map(|(at, posted)| Amendable { id: format!("a{}", at + 1), event: posted.event.clone(), room: posted.room.clone(), text: posted.text.clone() }) .collect(); - // Her memories recalled, by id, for the Interpreter (map 16.35.4). - let memories = taken.iter().filter(|candidate| matches!(candidate.pool, Pool::MemoriesAboutPresent | Pool::OtherMemories)).enumerate().map(|(at, candidate)| Remembered { id: format!("m{}", at + 1), entry: candidate.id.clone(), words: candidate.words.clone() }).collect(); + // Her short-term notes shown, by id, for the Interpreter (map 16.35.4): the only memories a turn can settle, so a + // crystallized memory is never offered as one (T6). + let memories = taken.iter().filter(|candidate| candidate.pool == Pool::ShortTerm).enumerate().map(|(at, candidate)| Remembered { id: format!("m{}", at + 1), entry: candidate.id.clone(), words: candidate.words.clone() }).collect(); 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, 16.29.10): what came of her last turn, then her side of the conversation (map 16.24.1), then // her domain; the room follows them in what she reads (`narrate::read_after`). diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index cc09b05..f82a960 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -484,7 +484,7 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) Some(event) => match replied(&lines, event, &room) { Some(at) => Some(at), None => { - refused_sends.push(json!({ "text": says, "in_reply_to": event, "refusal": "reply_target_not_in_room" })); + refused_sends.push(json!({ "room": room, "text": says, "in_reply_to": event, "refusal": "reply_target_not_in_room" })); continue; } }, diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 6bc871b..50f2b0f 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -478,8 +478,8 @@ fn an_item_shown_five_times_in_a_row_drops_out() { #[test] fn an_item_scoring_minus_twenty_one_almost_never_appears() { - // A short-term item three weeks old against a 24-hour time constant: recency alone is about exp(-21). - let state = json!({ "publicName": "Eureka", "thoughtMemory": { "shortTerm": [{ "id": "ancient", "summary": "Long ago.", "createdAt": hours_ago(21 * 24) }] } }); + // A crystallized memory of salience e^-20 that nothing touches: its score is about e^-21. + let state = json!({ "publicName": "Eureka", "thoughtMemory": { "memories": [{ "id": "ancient", "summary": "Long ago.", "status": "crystallized", "intensity": (-20.0f64).exp() }] } }); let packet = packet_of(TurnKind::Beat, &state, &Room::default(), &History::default(), 1); assert!(packet.selected.is_empty() || packet.selected[0].log_score < -20.0); let shown = (1..=500).filter(|seed| !packet_of(TurnKind::Beat, &state, &Room::default(), &History::default(), *seed).selected.is_empty()).count(); @@ -1385,10 +1385,11 @@ fn a_crystallized_memory_weeks_old_still_surfaces() { old["thoughtMemory"]["memories"] = json!([{ "id": "old-one", "summary": "The first deploy that held.", "createdAt": hours_ago(19 * 24), "status": "crystallized" }]); let shown = (1..=200).filter(|seed| ids(&packet_of(TurnKind::Beat, &old, &Room::default(), &History::default(), *seed)).contains(&"old-one".to_owned())).count(); assert!(shown >= 30, "a 19-day-old crystallized memory appears at a reasonable rate: {shown}/200"); + // T6: an unresolved short-term note is shown on every wake, however old: it is not drawn. let mut short = state(); short["thoughtMemory"] = json!({ "shortTerm": [{ "id": "old-day", "summary": "The first deploy that held.", "createdAt": hours_ago(19 * 24) }] }); let shown = (1..=200).filter(|seed| ids(&packet_of(TurnKind::Beat, &short, &Room::default(), &History::default(), *seed)).contains(&"old-day".to_owned())).count(); - assert_eq!(shown, 0, "a short-term item that old has faded"); + assert_eq!(shown, 200, "an unresolved note is shown every time"); } #[test] @@ -1408,7 +1409,7 @@ fn the_lens_is_drawn_only_from_what_the_packet_holds() { let holds = |pools: &[Pool]| packet.selected.iter().any(|pick| pools.contains(&pick.pool)); match &packet.lens { Lens::UnresolvedWant => assert!(holds(&[Pool::Needs, Pool::Incubation]), "seed {seed}"), - Lens::MemorySurfacing => assert!(holds(&[Pool::MemoriesAboutPresent, Pool::OtherMemories]), "seed {seed}"), + Lens::MemorySurfacing => assert!(holds(&[Pool::ShortTerm, Pool::MemoriesAboutPresent, Pool::OtherMemories]), "seed {seed}"), Lens::Wondering => assert!(holds(&[Pool::Incubation]), "seed {seed}"), Lens::PersonPresent(_) | Lens::BodyAndHour => {} } @@ -1532,8 +1533,6 @@ fn every_range_is_validated_on_its_own() { let fault = format!("{:#}", tuning.validate().unwrap_err()); assert!(fault.contains(knob), "{knob}: {fault}"); }; - refused(&|t| t.select.memory_tau_h = 0.0, "select.memory_tau_h"); - refused(&|t| t.select.memory_tau_h = f64::NAN, "select.memory_tau_h"); refused(&|t| t.select.here_bytes = tuning::HERE_ROOM_MIN - 1, "select.here_bytes"); refused(&|t| t.select.body_bytes = tuning::BODY_ROOM_MIN - 1, "select.body_bytes"); refused(&|t| t.select.outcome_bytes = tuning::OUTCOME_ROOM_MIN - 1, "select.outcome_bytes"); diff --git a/crates/mind-body/src/projection/tuning.rs b/crates/mind-body/src/projection/tuning.rs index eeda97e..72c260e 100644 --- a/crates/mind-body/src/projection/tuning.rs +++ b/crates/mind-body/src/projection/tuning.rs @@ -154,8 +154,6 @@ pub struct SelectTuning { pub item_bytes: usize, /// Her body section (map 16.6): its heading, her senses and actuators and the turn line, which always fits. pub body_bytes: usize, - /// The recency time constant of her memories and short-term items, in hours. - pub memory_tau_h: f64, /// freshness = base ^ (times shown in the last `freshness_window` projections); 0 never repeats an item in the window. pub freshness_base: f64, pub freshness_window: usize, @@ -251,7 +249,6 @@ impl Default for SelectTuning { bond_summary_bytes: 600, item_bytes: 700, body_bytes: 1024, - memory_tau_h: 24.0, freshness_base: 0.5, freshness_window: 5, people_full: 2, @@ -301,7 +298,6 @@ impl Tuning { bail!("select.caps are all 0: a packet could hold nothing of her"); } positive("select.inclusion_score", select.inclusion_score)?; - positive("select.memory_tau_h", select.memory_tau_h)?; if !(select.freshness_base.is_finite() && (0.0..=1.0).contains(&select.freshness_base)) { bail!("select.freshness_base must be from 0 to 1, not {}", select.freshness_base); } diff --git a/crates/mind-body/tests/public_surface.txt b/crates/mind-body/tests/public_surface.txt index 0af4253..1cd8d5b 100644 --- a/crates/mind-body/tests/public_surface.txt +++ b/crates/mind-body/tests/public_surface.txt @@ -352,7 +352,7 @@ mind_body::projection::tuning: struct Loaded # [derive (Clone , Debug , PartialE mind_body::projection::tuning: struct PersonaTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[model: String, guidance: String, words: usize] mind_body::projection::tuning: struct PoolCaps # [derive (Clone , Debug , PartialEq , Eq , Serialize , Deserialize)] pub-fields[memories_about_present: usize, other_memories: usize, needs: usize, incubation: usize, stance: usize, value: usize] mind_body::projection::tuning: struct ProjectorTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[model: String, guidance: String, words: usize, beat_words: usize] -mind_body::projection::tuning: struct SelectTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[temperature: f64, inclusion_score: f64, notes_bytes: usize, here_bytes: usize, outcome_bytes: usize, domain_bytes: usize, exchange_bytes: usize, stimulus_bytes: usize, heard_bytes: usize, addressed_bytes: usize, identity_bytes: usize, bond_summary_bytes: usize, item_bytes: usize, body_bytes: usize, memory_tau_h: f64, freshness_base: f64, freshness_window: usize, people_full: usize, beat_tail_lines: usize, group_state: bool, group_lines: usize, group_bytes: usize, caps: PoolCaps] +mind_body::projection::tuning: struct SelectTuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[temperature: f64, inclusion_score: f64, notes_bytes: usize, here_bytes: usize, outcome_bytes: usize, domain_bytes: usize, exchange_bytes: usize, stimulus_bytes: usize, heard_bytes: usize, addressed_bytes: usize, identity_bytes: usize, bond_summary_bytes: usize, item_bytes: usize, body_bytes: usize, freshness_base: f64, freshness_window: usize, people_full: usize, beat_tail_lines: usize, group_state: bool, group_lines: usize, group_bytes: usize, caps: PoolCaps] mind_body::projection::tuning: struct Tuning # [derive (Clone , Debug , PartialEq , Serialize , Deserialize)] pub-fields[projector: ProjectorTuning, persona: PersonaTuning, interpreter: InterpreterTuning, select: SelectTuning, lens: LensWeights, pronouns: BTreeMap < String , String >] mind_body::queue: fn on_hold (mind : & dyn MindPort) -> Result < Held > mind_body::queue: impl Held