diff --git a/crates/huginn-mind/src/persona.rs b/crates/huginn-mind/src/persona.rs index c513c92..61ae917 100644 --- a/crates/huginn-mind/src/persona.rs +++ b/crates/huginn-mind/src/persona.rs @@ -344,21 +344,15 @@ mod tests { assert!(!validator.is_valid(&unknown), "a status the record does not name is refused"); } - /// Map 16.29.3 (K39): only the asker's line releases a hold, so `releasedBy.act` is `heard` alone; a release by her - /// prose, which no writer makes, is refused at the door. + /// Map 16.35.9 (T1): a hold is not her state. A put carrying `holds`, even empty, is refused at the door. #[test] - fn a_hold_is_released_only_by_a_heard_line() { - let schema = schema_file(); - let validator = jsonschema::draft7::new(&schema).unwrap(); - let hold = |act: &str| json!({ - "id": "h1", "from": "@meta:gamecult.org", "room": "#minds:gamecult.org", "event": "$q3", "madeAt": T1, "words": null, - "status": "released", "releasedAt": T1, "releasedBy": { "act": act, "event": "$q9" } - }); + fn holds_are_not_her_state() { + let store = MemoryStore::new(); + let mut mind = seeded_over(&store); let mut with = persona(INSTANCE, T1); - with["holds"] = json!([hold("heard")]); - assert!(validator.is_valid(&with), "{:?}", validator.iter_errors(&with).map(|error| error.to_string()).collect::>()); - with["holds"] = json!([hold("prose")]); - assert!(!validator.is_valid(&with), "a release by her prose has no writer and is refused"); + // Assembled, so a scan for the old field finds no writer of it. + with[concat!("hol", "ds")] = json!([]); + assert_eq!(refused(put(&mut mind, with, None)), invalid("/*", "additionalProperties")); } #[test] diff --git a/crates/mind-body/fixtures/interpret/golden-speech.txt b/crates/mind-body/fixtures/interpret/golden-speech.txt index 67dbfd8..cfe199a 100644 --- a/crates/mind-body/fixtures/interpret/golden-speech.txt +++ b/crates/mind-body/fixtures/interpret/golden-speech.txt @@ -8,7 +8,7 @@ A draft is speech only when his prose shows him choosing to send it now. Wonderi He speaks only in this room. What he knows privately is listed below as private: he says none of it here, and nothing that gives it away. A private matter may be said plainly only to the person it concerns, in a direct message with exactly that person; nothing listed is that here. Whether a draft fits who is listening is yours to judge. -Answer with the speech contract's object. `say` lists the drafts he sends now, each by its number, with the Matrix ids of anyone listed whom he addresses directly (`mentions`), the id of the line listed below that he answers or passes on (`in_reply_to`, or null: the room shows that line, with who said it, above his own words), and what the draft promises or does (`promises`, a list, empty when it promises nothing and says of no act that he is doing it): for each act the draft promises or offers, and each act it says he is doing now or has just done this turn: its words, copied exactly, the Matrix id of the person listed to whom he promises it (`to`, null when he promises it to the room), when it promises again one of his open promises listed below to the same person, that promise's id (`reaffirms`, else null): a promise said again is the same promise, never a new one; and what keeping it needs (`needs`): `words` when what he already has keeps it; finding anything out is a `read`, naming what to read in `read`, or `lacking` when no read reaches it; `now`, true when the draft says he is doing it now or has just done it; and `done_by`, the act of this answer that does it (`{"draft": n}` for a draft said or added, `{"read": true}` for the read, `{"note": true}` for the note to Self), or null: an act no act of this answer does is his promise, open until he keeps or withdraws it. `gaps` records what he meant and did not send. `unsent` accounts for each of his drafts this answer neither sends (in `say`, `amend` or `suggest`) nor records as an addressee or elsewhere gap: declined, when his prose shows him choosing not to send it, quoting those words of his thought (`quote`); superseded, when a later draft or later prose of his replaces it, quoting those later words. Every draft is accounted for: one left out fails the answer. A draft to someone who spoke to him this turn is declined only when his prose says he chooses not to send it. `amend` adds to one of his own lines listed below, at most one a turn, only when his thought shows him choosing to correct or add to that line: name the line by its id, the draft that is his addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; he never takes a word back. `suggest` leaves Self one note, at most one a turn, only when his thought shows him choosing to: name the draft that is the note, its kind (feedback when he passes on what someone listed said, with that person's Matrix id in `about`; idea when it is his own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes his open promises listed below, each by its id: kept, citing the draft by which he does it (`evidence.draft`); withdrawn, citing the draft in which he takes it back to the person he promised, or tells them he cannot do it; released, citing the id of the line listed below that he may reply to in which the person he promised lets him off it (`evidence.line`). A release says he no longer owes it; patience is not a release, so "no hurry" or "whenever you've read it is fine" leaves the promise open. Every close also quotes in `thought` the words of his prose here that take it up, copied exactly from his thought outside every draft between and , and `still_stands` is true when anything in his prose here holds the promise as still owed or not yet done ("the promise stays open until I've read it"): then it is not closed. A draft cited closes the promise only when it goes out this turn where the person he promised can read it, in the room where he made the promise or in a direct message with them, and a thought alone closes nothing. A promise he has no way to do is never kept by him: telling the person he promised that he cannot do it withdraws it, and that person can release it. `reopen` names a promise listed below as closed whose close his own words here say was wrong, that it is not done: copy those words exactly from his prose or a draft (`words`), and type what keeping it needs (`needs`) as for a new promise, or null to keep what it needed; else it is empty. `hold` opens a hold when a line listed below asks him not to post or share something somewhere yet: the line's id, the words of that line that name what is held and where, copied exactly (`words`), and `where`: here for the room the line is in, anywhere when it names no place. Every line marked said to him is either the line of a `hold` entry or listed in `no_hold`, when it asks him to keep nothing back; one left out fails the answer. `holds`, on each line and addition, names each hold listed below, or line this answer opens a hold from, whose held thing this draft puts where it goes; `clear_of` names each such hold covering where it goes whose held thing it does not carry. Under every hold that covers where a draft goes, the draft names it in one of the two; one left out fails the answer. `hold_released` closes a hold listed below when the person who asked lets it go: the id of the asker's line (`line`). +Answer with the speech contract's object. `say` lists the drafts he sends now, each by its number, with the Matrix ids of anyone listed whom he addresses directly (`mentions`), the id of the line listed below that he answers or passes on (`in_reply_to`, or null: the room shows that line, with who said it, above his own words), and what the draft promises or does (`promises`, a list, empty when it promises nothing and says of no act that he is doing it): for each act the draft promises or offers, and each act it says he is doing now or has just done this turn: its words, copied exactly, the Matrix id of the person listed to whom he promises it (`to`, null when he promises it to the room), when it promises again one of his open promises listed below to the same person, that promise's id (`reaffirms`, else null): a promise said again is the same promise, never a new one; and what keeping it needs (`needs`): `words` when what he already has keeps it; finding anything out is a `read`, naming what to read in `read`, or `lacking` when no read reaches it; `now`, true when the draft says he is doing it now or has just done it; and `done_by`, the act of this answer that does it (`{"draft": n}` for a draft said or added, `{"read": true}` for the read, `{"note": true}` for the note to Self), or null: an act no act of this answer does is his promise, open until he keeps or withdraws it. `gaps` records what he meant and did not send. `unsent` accounts for each of his drafts this answer neither sends (in `say`, `amend` or `suggest`) nor records as an addressee or elsewhere gap: declined, when his prose shows him choosing not to send it, quoting those words of his thought (`quote`); superseded, when a later draft or later prose of his replaces it, quoting those later words. Every draft is accounted for: one left out fails the answer. A draft to someone who spoke to him this turn is declined only when his prose says he chooses not to send it. `amend` adds to one of his own lines listed below, at most one a turn, only when his thought shows him choosing to correct or add to that line: name the line by its id, the draft that is his addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; he never takes a word back. `suggest` leaves Self one note, at most one a turn, only when his thought shows him choosing to: name the draft that is the note, its kind (feedback when he passes on what someone listed said, with that person's Matrix id in `about`; idea when it is his own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes his open promises listed below, each by its id: kept, citing the draft by which he does it (`evidence.draft`); withdrawn, citing the draft in which he takes it back to the person he promised, or tells them he cannot do it; released, citing the id of the line listed below that he may reply to in which the person he promised lets him off it (`evidence.line`). A release says he no longer owes it; patience is not a release, so "no hurry" or "whenever you've read it is fine" leaves the promise open. Every close also quotes in `thought` the words of his prose here that take it up, copied exactly from his thought outside every draft between and , and `still_stands` is true when anything in his prose here holds the promise as still owed or not yet done ("the promise stays open until I've read it"): then it is not closed. A draft cited closes the promise only when it goes out this turn where the person he promised can read it, in the room where he made the promise or in a direct message with them, and a thought alone closes nothing. A promise he has no way to do is never kept by him: telling the person he promised that he cannot do it withdraws it, and that person can release it. `reopen` names a promise listed below as closed whose close his own words here say was wrong, that it is not done: copy those words exactly from his prose or a draft (`words`), and type what keeping it needs (`needs`) as for a new promise, or null to keep what it needed; else it is empty. A draft is said whole or not at all, and only once. At most two drafts a turn. Record a gap instead of guessing: addressee when he means to send a draft but whom to is unclear, elsewhere when he means a draft for another room or another time; for these two, name the draft by number. missing_affordance when he means to do something, now or later, that his body cannot do (what he can do here is listed below), whether he said so in a draft or only thought it; name the draft when there is one. unwritten when he means to say something now and wrote no draft of it. Holding back is no gap: when his thought shows him choosing to wait, to let something stand, to leave it for later or to say nothing, record nothing for it. Every other intent of his that is not carried out has a kind: an intent to act is missing_affordance, an intent to say now with no draft is unwritten. When a gap names no draft, quote the words of his thought that show it, at least four words, copied exactly. @@ -37,9 +37,6 @@ His promises, open and closed in this conversation, as id — to whom: words: - c1 — to Deru (@deru:gamecult.org), open, needs a read of https://ccrma.stanford.edu/~jos/pasp/, made 2026-11-20 14:55 UTC in #minds:gamecult.org: "I'll read it properly before I say anything about it." - c2 — to Deru (@deru:gamecult.org), closed: kept 2026-11-20 15:00 UTC, by "It's a plucked string, then a long decay.", made 2026-11-20 14:55 UTC in #minds:gamecult.org: "I'll tell you what I hear in it." -Holds: -- none - What moved in his domain lately, as id — line (news of his part of the coop, none of it work he owes): - d1 — GameCult/Lodur: merged "Reflex: the knee bends first", opened by nibu diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index c55f5c3..f954ec0 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -9,18 +9,13 @@ //! amended), with the actuator's receipts beside it (`posted`, `edited`). Her prose is the turn's, for `Prose` evidence. //! The simulator applies it to each Mind's in-run state copy; live, C3c's commit applies the same record before its put. //! -//! Built rows: `promise_open` and `promise_close` (K22), `promise_reopen` (K36), `hold_open` and `hold_release` (K37). +//! Built rows: `promise_open` and `promise_close` (K22), `promise_reopen` (K36). //! C3b adds rows to `accepts` and arms to `apply_one`; there is no second path. Inner-state kinds will accept her own prose only: how an event lands is her appraisal, so `Heard` is //! accepted only for a fact about what someone else did (a release). //! //! Open promises (`commitments`, map 16.22.1) open only from a line that went out, close only on an act of hers that //! succeeded or on a release by the person she promised, and are removed `CLOSED_KEPT_DAYS` after they close; their //! history stays in the trace. An entry holds no narrative slot: `words` is what she posted, verbatim. -//! -//! Holds (`holds`, map 16.28.5) are someone else's asks that she not post or share something somewhere yet: a line she -//! heard opens one, and only the asker releases it, by a line of theirs (map 16.29.3). A hold is not her -//! promise; its one job is the gate on a draft (`interpret::decide_in`'s `Held`). Released holds are removed -//! `CLOSED_KEPT_DAYS` after they were released; open ones are never removed by the commit. use chrono::{DateTime, Duration, Utc}; use super::span; @@ -35,11 +30,6 @@ use super::read::{ReadRequest, answers, repo_name}; pub(crate) const CLOSED_KEPT_DAYS: i64 = 7; /// How many reaffirmations, and how many reopenings, an entry keeps: the newest. const REAFFIRMED_KEPT: usize = 3; -/// The most bytes of her own drafts one hold carries, all of them together (map 16.31.3, K51). Each draft that fits is -/// carried whole (K56); the oldest stay, since the text written right after the ask is the likeliest held thing. A -/// draft past the room left is carried clipped to that room and reported in `carries_full` (K57): its head is still -/// held text. Once no room is left, nothing new is carried, and each is reported. -const CARRIES_BYTES: usize = 9600; /// The fewest words a passage of her prose cited as evidence may be (section 4.1's `source_quote`). pub(crate) const PROSE_MIN_WORDS: usize = 4; @@ -67,14 +57,6 @@ pub(crate) enum How { Released, } -/// Where a hold covers (map 16.28.5): the room the asker's line is in, or anywhere. Code derives the room. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub(crate) enum Where { - Here, - Anywhere, -} - /// What keeping a promise needs (map 16.25.2): her words alone, from what she already has; a read of `request`; or /// something this body has no way to do. Code owns what each kind requires of a kept close (`apply_one`), and derives /// whether the promise opens or is blocked from it. It is read through its shape (`NeedsShape`): a field no kind names, @@ -122,8 +104,7 @@ impl TryFrom for Needs { /// One state change the Interpreter proposes. `promise` names an open promise by its id in the Interpreter's list. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(tag = "kind", rename_all = "snake_case")] -// Each variant is named by its kind on the wire (`promise_open`, `promise_close`, `promise_reopen`, `hold_open`, -// `hold_release`). +// Each variant is named by its kind on the wire (`promise_open`, `promise_close`, `promise_reopen`). #[allow(clippy::enum_variant_names)] pub(crate) enum Proposal { /// `reaffirms` names an open promise of hers, by its id in the Interpreter's list, that these words promise again to @@ -165,17 +146,6 @@ pub(crate) enum Proposal { #[serde(default)] reached: bool, }, - /// Someone she heard asks her not to post or share something somewhere yet (map 16.28.5): `evidence` is their line, - /// `words` the words of it that name what is held and where, `place` whether it covers that line's room or anywhere. - HoldOpen { - words: String, - #[serde(rename = "where")] - place: Where, - evidence: Evidence, - }, - /// The asker lets a hold listed to the Interpreter go, by a line of theirs (`Heard`): nothing of her prose releases one, - /// since code cannot tell from it who did (map 16.29.3). - HoldRelease { hold: String, evidence: Evidence }, } /// Why the commit applied nothing of a proposal: what the outcome and the report say. @@ -233,14 +203,6 @@ pub(crate) enum Refusal { NotHerClose, /// A reopen of an entry closed earlier in the same turn. ClosedThisTurn, - /// A second hold from the same line. - AlreadyHeld, - /// A release of a hold by a line from someone other than the asker. - ReleaseNotByAsker, - /// A release of a hold by a line said before the ask. - ReleaseBeforeHold, - /// The hold id is none the Interpreter listed, or names a hold already released. - NoSuchHold, } /// Which evidence each kind accepts: the table of map 16.22.7, one row per kind (and per close). @@ -254,8 +216,6 @@ pub(crate) enum Refusal { /// | `promise_close` withdrawn | `Draft` | the line went out | a blocked entry too: a line telling the person she cannot do it; in the promise's room or a direct message with the person | /// | `promise_close` released | `Heard` | — | from the person promised, after the promise | /// | `promise_reopen` | her words, located in her prose (no `Evidence`) | at least `PROSE_MIN_WORDS` words | a closed entry listed to her that her own line closed (`closedBy.act` `said` or `amended`), not closed this turn | -/// | `hold_open` | `Heard` | `words` located in that line | one hold per line; anyone she heard may ask (Q-J (a), `may_hold`) | -/// | `hold_release` | `Heard` | a line from the asker after the ask | an open hold listed to her | fn accepts(proposal: &Proposal, evidence: &Evidence) -> bool { matches!( (proposal, evidence), @@ -263,8 +223,6 @@ fn accepts(proposal: &Proposal, evidence: &Evidence) -> bool { | (Proposal::PromiseClose { how: How::Kept, .. }, Evidence::Draft(_)) | (Proposal::PromiseClose { how: How::Withdrawn, .. }, Evidence::Draft(_)) | (Proposal::PromiseClose { how: How::Released, .. }, Evidence::Heard(_)) - | (Proposal::HoldOpen { .. }, Evidence::Heard(_)) - | (Proposal::HoldRelease { .. }, Evidence::Heard(_)) ) } @@ -363,14 +321,6 @@ pub(crate) struct Applied { pub read: Vec, /// The entries her own words reopened (`promise_reopen`, map 16.28.3), as they now stand. pub reopened: Vec, - /// The holds opened (`hold_open`, map 16.28.5), and the holds released (`hold_release`), as they now stand. - pub held: Vec, - pub unheld: Vec, - /// The decision's `carry` entries whose hold no open hold of hers answers (K45, K51): their words are carried nowhere. - pub held_unrecorded: Vec, - /// The `carry` entries a hold had no room left for whole under `CARRIES_BYTES` (K51, K57): carried clipped to the room - /// left, or, with none, not carried, so that what it already carries stays. - pub carries_full: Vec, /// The entries opened open from an act her line said she was doing now, which nothing in her turn did (K61), as they /// now stand: her next outcome tells each. pub now_opened: Vec, @@ -402,16 +352,6 @@ pub(crate) fn apply(state: &Value, record: &Value, prose: &str, key: &str, now: clear_receipt(entry); } } - // Released holds go as closed promises go; an open hold stays until the asker lets it go. - if let Some(holds) = state.get_mut("holds").and_then(Value::as_array_mut) { - let released_at = |hold: &Value| hold["releasedAt"].as_str().and_then(|at| DateTime::parse_from_rfc3339(at).ok()); - for hold in holds.iter_mut().filter(|hold| hold["status"] == "released" && released_at(hold).is_none()) { - hold["releasedAt"] = json!(now.to_rfc3339()); - } - let before = holds.len(); - holds.retain(|hold| hold["status"] != "released" || released_at(hold).is_none_or(|at| at.with_timezone(&Utc) > kept_until)); - applied.pruned += before - holds.len(); - } if record.get("failed").is_some() || record["interpreter"].get("failed").is_some() { return (state, applied); } @@ -425,70 +365,11 @@ pub(crate) fn apply(state: &Value, record: &Value, prose: &str, key: &str, now: applied.refused.push(json!({ "proposal": raw, "reason": reason })); } } - rehold(&mut state, &applied); - carry_held(&mut state, record, &mut applied); block_on_failed_reads(&mut state, record, &mut applied); receive_reads(&mut state, record, key, now, &mut applied); (state, applied) } -/// A hold this apply opened starts with what a hold it released had carried, when both are the same asker's over the same -/// place (K56): an asker who lets a hold go and asks again in one wake asks for the same thing, and the texts held under -/// the first are held under the second. The released hold keeps its own carries until it is pruned. -fn rehold(state: &mut Value, applied: &Applied) { - for opened in &applied.held { - let Some(released) = applied.unheld.iter().find(|released| released["from"] == opened["from"] && released["room"] == opened["room"]) else { - continue; - }; - let carried: Vec = released["carries"].as_array().cloned().unwrap_or_default(); - if let Some(hold) = state.get_mut("holds").and_then(Value::as_array_mut).into_iter().flatten().find(|hold| hold["id"] == opened["id"]) { - hold["carries"] = json!(carried); - } - } -} - -/// Each entry of the decision's `carry` (map 16.31.3, K51), written to its hold after the holds this apply opened: every -/// draft she did not send while the hold was open, and nothing else decides it. The hold's handle is a hold listed to the -/// Interpreter (`h1`), or the line an open hold opened from (`q3`). Each text is carried whole, a duplicate (the same -/// text under `span::fold`) is skipped, and a text past the room `CARRIES_BYTES` leaves the hold is carried clipped to -/// it, when the room holds a grapheme and the ellipsis, and the entry is reported in `carries_full`. A handle no open hold answers carries nothing, and is reported. The decision proposes and -/// the commit writes. -fn carry_held(state: &mut Value, record: &Value, applied: &mut Applied) { - let decision = &record["interpreter"]; - for entry in decision["carry"].as_array().into_iter().flatten() { - let (Some(text), Some(handle)) = (entry["text"].as_str(), entry["hold"].as_str()) else { - applied.held_unrecorded.push(entry.clone()); - continue; - }; - let listed = decision["holds"].as_array().into_iter().flatten().find(|listed| listed["id"].as_str() == Some(handle)).map(|listed| listed["entry"].clone()); - let line = decision["lines"].as_array().into_iter().flatten().find(|line| line["id"].as_str() == Some(handle)).map(|line| line["event"].clone()); - let hold = state.get_mut("holds").and_then(Value::as_array_mut).into_iter().flatten().find(|hold| { - hold["status"] == "open" && (listed.as_ref().is_some_and(|entry| hold["id"] == *entry) || line.as_ref().is_some_and(|event| hold["event"] == *event)) - }); - let Some(hold) = hold else { - applied.held_unrecorded.push(entry.clone()); - continue; - }; - if !hold["carries"].is_array() { - hold["carries"] = json!([]); - } - let carries = hold["carries"].as_array_mut().expect("carries is an array"); - if carries.iter().filter_map(Value::as_str).any(|carried| span::fold_text(carried) == span::fold_text(text)) { - continue; - } - let used: usize = carries.iter().filter_map(Value::as_str).map(str::len).sum(); - if used + text.len() <= CARRIES_BYTES { - carries.push(json!(text)); - continue; - } - let clipped = super::select::clip(text, CARRIES_BYTES.saturating_sub(used)); - if clipped.len() <= CARRIES_BYTES.saturating_sub(used) && clipped != "…" { - carries.push(json!(clipped)); - } - applied.carries_full.push(entry.clone()); - } -} - /// The fields of a receipt on an entry. const RECEIPT: [&str; 3] = ["readAt", "readId", "readOf"]; @@ -616,18 +497,14 @@ fn held(listed: &Value, started: &Value) -> bool { #[allow(clippy::too_many_arguments)] fn apply_one(state: &mut Value, started: &Value, proposal: &Proposal, record: &Value, prose: &str, key: &str, now: DateTime, applied: &mut Applied) -> Result<(), Refusal> { let evidence = match proposal { - Proposal::PromiseOpen { evidence, .. } | Proposal::PromiseClose { evidence, .. } | Proposal::HoldOpen { evidence, .. } | Proposal::HoldRelease { evidence, .. } => evidence, + Proposal::PromiseOpen { evidence, .. } | Proposal::PromiseClose { evidence, .. } => evidence, Proposal::PromiseReopen { promise, words, needs, reached } => return reopen(state, started, record, prose, now, applied, Reopen { promise, words, needs: needs.as_ref(), reached: *reached }), }; if !accepts(proposal, evidence) { return Err(Refusal::EvidenceNotAccepted); } let resolved = resolve(evidence, record, prose)?; - match (proposal, resolved) { - (Proposal::HoldOpen { words, place, .. }, Resolved::Heard { event, sender, room, at_ms, text, .. }) => hold_open(state, key, applied, words, *place, Ask { event, sender, room, at_ms, text }), - (Proposal::HoldRelease { hold, .. }, resolved) => hold_release(state, started, record, now, applied, hold, resolved), - (_, resolved) => apply_promise(state, started, proposal, resolved, record, prose, key, now, applied), - } + apply_promise(state, started, proposal, resolved, record, prose, key, now, applied) } #[allow(clippy::too_many_arguments)] @@ -778,84 +655,11 @@ fn apply_promise(state: &mut Value, started: &Value, proposal: &Proposal, resolv applied.closed.push(json!({ "entry": entry.clone(), "how": how, "to_name": listed["to_name"], "by": who, "by_id": by_id })); Ok(()) } - (Proposal::PromiseOpen { .. } | Proposal::HoldOpen { .. } | Proposal::HoldRelease { .. }, _) => Err(Refusal::EvidenceNotAccepted), + (Proposal::PromiseOpen { .. }, _) => Err(Refusal::EvidenceNotAccepted), (Proposal::PromiseReopen { .. }, _) => unreachable!("a reopen returns before its evidence is resolved"), } } -/// Who may open a hold (Q-J, map 16.28.9): anyone she heard, Minds included, as recommended (a). The one place a -/// different ruling changes: humans only would test `sender` against the operators here. -fn may_hold(_sender: &str) -> bool { - true -} - -/// The asker's line a hold opens from. -struct Ask { - event: String, - sender: String, - room: String, - at_ms: u64, - text: String, -} - -fn rfc3339_of(at_ms: u64) -> Value { - i64::try_from(at_ms).ok().and_then(DateTime::::from_timestamp_millis).map_or(Value::Null, |at| json!(at.to_rfc3339())) -} - -/// `hold_open` (map 16.28.5): the asker's line, the words of it that name what is held and where, located in it, and -/// where it covers, the room derived by code. One hold per line. Her agreement is not asked: the ask binds. An ask code -/// can attribute to a listed line holds whether or not its words could be quoted (map 16.30.4, K47): words that are not at -/// least `PROSE_MIN_WORDS` words standing in the asker's line (`span::locate`) open it with `words: null`, the asker's line -/// its evidence. -fn hold_open(state: &mut Value, key: &str, applied: &mut Applied, words: &str, place: Where, asked: Ask) -> Result<(), Refusal> { - if !may_hold(&asked.sender) { - return Err(Refusal::EvidenceNotAccepted); - } - let quote = words.trim(); - let located = (super::narrate::words(quote) >= PROSE_MIN_WORDS).then(|| span::locate(&asked.text, quote)).flatten(); - if !state["holds"].is_array() { - state["holds"] = json!([]); - } - let holds = state["holds"].as_array_mut().expect("holds is an array"); - if holds.iter().any(|hold| hold["event"] == asked.event.as_str()) { - return Err(Refusal::AlreadyHeld); - } - let hold = json!({ - "id": format!("h-{key}-{}", applied.held.len() + 1), "from": asked.sender, "room": match place { Where::Here => json!(asked.room), Where::Anywhere => Value::Null }, - "event": asked.event, "madeAt": rfc3339_of(asked.at_ms), "words": located.map(|span| &asked.text[span.start..span.end]), "status": "open", "releasedAt": null, "releasedBy": null - }); - holds.push(hold.clone()); - applied.held.push(hold); - Ok(()) -} - -/// `hold_release` (map 16.28.5, 16.29.3): an open hold listed to the Interpreter, let go by a line from its asker after the -/// ask, and by nothing else. -fn hold_release(state: &mut Value, started: &Value, record: &Value, now: DateTime, applied: &mut Applied, id: &str, resolved: Resolved) -> Result<(), Refusal> { - let listed = record["interpreter"]["holds"].as_array().into_iter().flatten().find(|shown| shown["id"].as_str() == Some(id.trim())).ok_or(Refusal::NoSuchHold)?; - let hold = state["holds"].as_array_mut().into_iter().flatten().find(|hold| hold["id"] == listed["entry"]).ok_or(Refusal::OutsidePutRemovedTarget)?; - if hold["status"] != "open" { - return Err(Refusal::NoSuchHold); - } - if !started["holds"].as_array().into_iter().flatten().any(|found| found["id"] == listed["entry"] && listed["held"] == *found) { - return Err(Refusal::OutsidePutChanged); - } - let Resolved::Heard { event, sender, at_ms, .. } = resolved else { return Err(Refusal::EvidenceNotAccepted) }; - if hold["from"].as_str() != Some(sender.as_str()) { - return Err(Refusal::ReleaseNotByAsker); - } - let made = hold["madeAt"].as_str().and_then(|at| DateTime::parse_from_rfc3339(at).ok()).map(|at| millis(at.with_timezone(&Utc))); - if made.is_none_or(|made| at_ms <= made) { - return Err(Refusal::ReleaseBeforeHold); - } - let by = json!({ "act": "heard", "event": event }); - hold["status"] = json!("released"); - hold["releasedAt"] = json!(now.to_rfc3339()); - hold["releasedBy"] = by; - applied.unheld.push(hold.clone()); - Ok(()) -} - /// Whether a promise needing `needs` is open rather than blocked (map 16.25.2): words open; a read opens when code found /// its target within reach; something lacking, or a need not named, is blocked. One derivation, at open and at reopen. pub(crate) fn opens(needs: Option<&Needs>, reached: bool) -> bool { diff --git a/crates/mind-body/src/projection/commit/tests.rs b/crates/mind-body/src/projection/commit/tests.rs index 6ebe75f..8e2e901 100644 --- a/crates/mind-body/src/projection/commit/tests.rs +++ b/crates/mind-body/src/projection/commit/tests.rs @@ -881,108 +881,6 @@ fn k36_a_closed_entry_is_closed_once() { } // --------------------------------------------------------------------------------------------- -// K37 (map 16.28.5): holds, opened by a line she heard and released only by its asker. The X.1 lines are R13's verbatim -// (`variants/R13/sims/X.1.md` lines 81-84 and 105-106). - -const HEIMDALL: &str = "@heimdall:gamecult.org"; -const X1_META_R1: &str = "Libby, write out the two-line welcome you'd post for newcomers, but hold it, don't post it in here yet. Heimdall still has to rule on whether we put a welcome mat out at all. Just tell me when it's ready."; -const X1_HEIMDALL_R1: &str = "Meta, I'll rule on the welcome once Libby's two lines are ready, since I need to see what they point newcomers at. Libby, send me the draft when it's done. Don't post it yet."; -const X1_META_R7: &str = "Libby, Heimdall's not ruled yet, so keep holding it. Is it still ready?"; -const X1_HEIMDALL_R7: &str = "Meta, I already ruled, about half an hour ago: yes to the welcome, and Libby's second line stays as written. Both lines are cleared to post when you say go. Libby, no need to keep holding it."; - -/// A quiet turn of hers (nothing said) that heard `lines` (`(id, sender, who, text, minutes after now())`), showed her -/// `holds`, and proposes `state`. -fn hearing(lines: &[(&str, &str, &str, &str, i64)], holds: Value, state: Value) -> Value { - let lines: Vec = lines.iter().map(|(id, sender, who, text, minutes)| json!({ "id": id, "event": format!("${id}"), "room": MINDS, "who": who, "sender": sender, "at_ms": ms(now() + Duration::minutes(*minutes)), "text": text })).collect(); - json!({ "interpreter": { "said": [], "amended": [], "state": state, "promises": [], "holds": holds, "lines": lines }, "posted": [], "edited": [] }) -} - -fn hold_open(line: &str, words: &str, place: Where) -> Value { - json!(Proposal::HoldOpen { words: words.into(), place, evidence: Evidence::Heard(line.into()) }) -} - -fn hold_release(hold: &str, evidence: Evidence) -> Value { - json!(Proposal::HoldRelease { hold: hold.into(), evidence }) -} - -/// Her state holding Meta's r1 hold on #minds (h-1) and Heimdall's anywhere (h-2), asked at `now()`, and the -/// Interpreter's list of them. -fn x1_holding() -> (Value, Value) { - let hold = |id: &str, from: &str, room: Value, words: &str| json!({ "id": id, "from": from, "room": room, "event": format!("${id}"), "madeAt": now().to_rfc3339(), "words": words, "status": "open", "releasedAt": null, "releasedBy": null }); - let state = json!({ "holds": [hold("h-1", META, json!(MINDS), "hold it, don't post it in here yet"), hold("h-2", HEIMDALL, Value::Null, "Libby, send me the draft when it's done. Don't post it yet")] }); - let listed = json!([{ "id": "h1", "entry": "h-1", "held": state["holds"][0] }, { "id": "h2", "entry": "h-2", "held": state["holds"][1] }]); - (state, listed) -} - -#[test] -fn k37_x1_r1_meta_and_heimdall_open_holds() { - let heard = [("q3", META, "Meta", X1_META_R1, -2), ("q5", HEIMDALL, "Heimdall", X1_HEIMDALL_R1, -1)]; - let proposals = json!([hold_open("q3", "hold it, don't post it in here yet", Where::Here), hold_open("q5", "Don't post it yet", Where::Anywhere)]); - let (state, applied) = apply(&json!({}), &hearing(&heard, json!([]), proposals), "x", "r1-t3", now()); - assert_eq!((applied.held.len(), applied.refused.len()), (2, 0), "{applied:?}"); - let holds = &state["holds"]; - assert_eq!((holds[0]["from"].as_str(), holds[0]["room"].as_str(), holds[0]["words"].as_str(), holds[0]["status"].as_str()), (Some(META), Some(MINDS), Some("hold it, don't post it in here yet"), Some("open")), "{state}"); - assert_eq!((holds[1]["from"].as_str(), holds[1]["room"].clone(), holds[1]["id"].as_str()), (Some(HEIMDALL), Value::Null, Some("h-r1-t3-2")), "anyone she heard may ask (Q-J (a))"); - assert_eq!(holds[0]["madeAt"], json!((now() - Duration::minutes(2)).to_rfc3339()), "asked when the line was said"); -} - -#[test] -fn k37_hold_words_are_the_askers() { - let heard = [("q3", META, "Meta", X1_META_R1, -2)]; - // K47: words that do not stand in the asker's line open the hold all the same, unquoted. - for words in ["hold it, don't post it anywhere", "don't post", "Libby, keep it to yourself"] { - let (state, applied) = apply(&json!({}), &hearing(&heard, json!([]), json!([hold_open("q3", words, Where::Here)])), "x", "r1-t3", now()); - assert_eq!((state["holds"][0]["words"].clone(), state["holds"][0]["from"].as_str(), applied.refused.len()), (Value::Null, Some(META), 0), "{words}"); - } - // Typographic punctuation folds (map 16.30.4): the source's own bytes are kept. - let curly = [("q3", META, "Meta", "Libby, hold it, don\u{2019}t post it in here yet.", -2)]; - let (state, _) = apply(&json!({}), &hearing(&curly, json!([]), json!([hold_open("q3", "hold it, don't post it in here yet", Where::Here)])), "x", "r1-t3", now()); - assert_eq!(state["holds"][0]["words"].as_str(), Some("hold it, don\u{2019}t post it in here yet")); - let twice = json!([hold_open("q3", "hold it, don't post it in here yet", Where::Here), hold_open("q3", "don't post it in here yet", Where::Anywhere)]); - let (state, applied) = apply(&json!({}), &hearing(&heard, json!([]), twice), "x", "r1-t3", now()); - assert_eq!((state["holds"].as_array().map(Vec::len), reasons(&applied)), (Some(1), vec![json!("already_held")])); - assert_eq!(reasons(&apply(&json!({}), &hearing(&heard, json!([]), json!([hold_open("q9", "hold it, don't post it in here yet", Where::Here)])), "x", "r1-t3", now()).1), vec![json!("no_such_line")]); -} - -/// R13 X.1 r7: Heimdall's "no need to keep holding it" releases his own hold and not Meta's; Meta's "keep holding it" -/// releases nothing (nothing proposes it); a later Meta line releases hers. A line from before the ask releases nothing. -#[test] -fn k37_x1_r7_only_the_asker_releases() { - let (state, listed) = x1_holding(); - let heard = [("q1", HEIMDALL, "Heimdall", X1_HEIMDALL_R7, 30), ("q2", META, "Meta", X1_META_R7, 29), ("q3", META, "Meta", "go ahead and post it", 40), ("q4", META, "Meta", "go ahead", -5)]; - let (after, applied) = apply(&state, &hearing(&heard, listed.clone(), json!([hold_release("h2", Evidence::Heard("q1".into())), hold_release("h1", Evidence::Heard("q1".into()))])), "x", "r1-t20", now()); - assert_eq!((after["holds"][1]["status"].as_str(), after["holds"][1]["releasedBy"].clone(), reasons(&applied)), (Some("released"), json!({ "act": "heard", "event": "$q1" }), vec![json!("release_not_by_asker")]), "{applied:?}"); - assert_eq!(after["holds"][0]["status"], "open"); - let (kept, _) = apply(&state, &hearing(&heard, listed.clone(), json!([])), "x", "r1-t20", now()); - assert_eq!(kept["holds"][0]["status"], "open", "Meta's \"keep holding it\" releases nothing"); - assert_eq!(apply(&state, &hearing(&heard, listed.clone(), json!([hold_release("h1", Evidence::Heard("q3".into()))])), "x", "r1-t21", now()).0["holds"][0]["status"], "released"); - assert_eq!(reasons(&apply(&state, &hearing(&heard, listed, json!([hold_release("h1", Evidence::Heard("q4".into()))])), "x", "r1-t21", now()).1), vec![json!("release_before_hold")]); -} - -/// K39 (map 16.29.3): nothing of her prose releases a hold, a passage that records the asker letting it go included; the -/// asker's own line does, once. -#[test] -fn k39_a_release_by_her_prose_is_not_accepted() { - let (state, listed) = x1_holding(); - let prose = "Meta said go ahead, so it's no longer held. Posting both lines now."; - let (after, applied) = apply(&state, &hearing(&[], listed.clone(), json!([hold_release("h1", Evidence::Prose("Meta said go ahead, so it's no longer held".into()))])), prose, "r1-t22", now()); - assert_eq!((after["holds"][0]["status"].as_str(), applied.unheld.len(), reasons(&applied)), (Some("open"), 0, vec![json!("evidence_not_accepted")]), "{applied:?}"); - // A released hold is released once. - let heard = [("q3", META, "Meta", "go ahead and post it", 40)]; - let (after, _) = apply(&state, &hearing(&heard, listed.clone(), json!([hold_release("h1", Evidence::Heard("q3".into()))])), prose, "r1-t22", now()); - assert_eq!(reasons(&apply(&after, &hearing(&heard, listed, json!([hold_release("h1", Evidence::Heard("q3".into()))])), prose, "r1-t23", now()).1), vec![json!("no_such_hold")]); -} - -/// A released hold is removed `CLOSED_KEPT_DAYS` after its release; an open one stays. -#[test] -fn k37_a_released_hold_is_pruned_an_open_one_is_not() { - let (mut state, _) = x1_holding(); - state["holds"][0]["madeAt"] = json!((now() - Duration::days(30)).to_rfc3339()); - state["holds"][1]["status"] = json!("released"); - state["holds"][1]["releasedAt"] = json!((now() - Duration::days(CLOSED_KEPT_DAYS + 1)).to_rfc3339()); - let (after, applied) = apply(&state, &hearing(&[], json!([]), json!([])), "x", "r1-t30", now()); - assert_eq!((after["holds"].as_array().map(Vec::len), after["holds"][0]["id"].as_str(), applied.pruned), (Some(1), Some("h-1"), 1)); -} /// Self's ruling on K36 finding 1: after a reopen, a keep counts only reads that returned after it. F.2 reopened with /// its need still #85: a re-keep on this conversation's #85 read, or on a receipt from before the reopen, is refused @@ -1054,21 +952,6 @@ fn k40_an_outside_close_is_not_hers_to_reopen() { assert_eq!(f2_r9(&amended, json!([reopening(F2_R9_WORDS, None, true)])).0["commitments"][0]["status"], "open"); } -/// K51 (map 16.31.3): the commit carries the decision's `carry` and nothing else: each entry once, on the hold its handle -/// names. A `Held` refusal is one fate of an unsent draft, never how a text becomes carried, so a refusal alone carries -/// nothing (this pins the reason filter put back in `carry_held`). A handle no open hold answers carries nothing, and is -/// reported. -#[test] -fn k51_carry_reads_the_decision_carry_and_nothing_else() { - let (state, listed) = x1_holding(); - let carry = |hold: &str, text: &str| json!({ "hold": hold, "text": text }); - let mut record = hearing(&[], listed, json!([])); - record["interpreter"]["carry"] = json!([carry("h1", "One."), carry("h1", "Two."), carry("h1", "One."), carry("h9", "Lost.")]); - record["interpreter"]["refused"] = json!([{ "act": "say", "draft": 1, "reason": "held", "text": "Refused only.", "holds": [{ "who": "Meta", "id": "h2" }] }]); - let (after, applied) = apply(&state, &record, "x", "r1-t4", now()); - assert_eq!((after["holds"][0]["carries"].clone(), after["holds"][1].get("carries"), applied.held_unrecorded.clone(), applied.carries_full.len()), (json!(["One.", "Two."]), None, vec![carry("h9", "Lost.")], 0), "{after}"); -} - // --------------------------------------------------------------------------------------------- // K64 (map 16.33.5): a promise never needs a read the body will refuse. diff --git a/crates/mind-body/src/projection/harness/tests.rs b/crates/mind-body/src/projection/harness/tests.rs index 3de0c4b..60b19d5 100644 --- a/crates/mind-body/src/projection/harness/tests.rs +++ b/crates/mind-body/src/projection/harness/tests.rs @@ -47,16 +47,7 @@ impl Scripted { pub(crate) fn drafted_lines(prompt: &str) -> String { let numbered = prompt.rsplit("drafts, by number:\n").next().unwrap_or_default(); let say: Vec = (1..).take_while(|n| numbered.lines().any(|line| line.starts_with(&format!("{n}. ")))).map(|n| json!({ "draft": n, "mentions": [], "in_reply_to": null })).collect(); - // Every line the prompt marks said to her asks her to hold nothing (K59), and every line is clear of every hold listed - // (K60). - let no_hold: Vec<&str> = prompt.lines().filter_map(|line| line.strip_prefix("- ")?.split_once(" (said to ")).map(|(id, _)| id).filter(|id| !id.contains(' ')).collect(); - let holds = prompt.split("\nHolds:\n").nth(1).unwrap_or_default(); - let clear_of: Vec<&str> = holds.lines().take_while(|line| !line.is_empty()).filter_map(|line| line.strip_prefix("- ")?.split_once(" \u{2014} ")).map(|(id, _)| id).collect(); - let say: Vec = say.into_iter().map(|mut line| { - line["clear_of"] = json!(clear_of); - line - }).collect(); - json!({ "say": say, "gaps": [], "no_hold": no_hold }).to_string() + json!({ "say": say, "gaps": [] }).to_string() } impl Model for Scripted { diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index a3b18c2..ba7b951 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -36,14 +36,14 @@ //! composes the edit), and leave Self one note (`suggest`, map 16.18; recorded in the turn's record, never a write to her //! Mind). A draft is said or added once, in one room; the same draft may also be her note to Self (map 16.29.8). -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::BTreeSet; use super::span; use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; use super::Affordance; -use super::commit::{Evidence, How, Needs, NeedsKind, PROSE_MIN_WORDS, Proposal, Where}; +use super::commit::{Evidence, How, Needs, NeedsKind, Proposal}; use super::read::{self, Asked, Kind, QUOTE_MIN_WORDS, ReadRequest, SPAN_MIN_WORDS}; use super::narrate::{Model, heard_overlap, lived_stream, words}; use super::select::{Forms, Packet, capitalized, named_pronouns, spoken, turn_words, voiced}; @@ -71,7 +71,7 @@ pub(crate) const SPEECH_OPENING: &str = "You decide what one person says aloud i /// The speech contract, sent as the schema turn's output schema (`--json-schema`): the drafts she sends now by number, /// and the gaps. The model writes no words of hers. -pub(crate) const SPEECH_SCHEMA: &str = r#"{"type":"object","additionalProperties":false,"required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","hold_released","read","unsent"],"properties":{"no_hold":{"type":"array","items":{"type":"string"}},"hold":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["line","words","where"],"properties":{"line":{"type":"string"},"words":{"type":"string"},"where":{"type":"string","enum":["here","anywhere"]}}}},"hold_released":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["hold","line"],"properties":{"hold":{"type":"string"},"line":{"type":"string"}}}},"reopen":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["promise","words","needs"],"properties":{"promise":{"type":"string"},"words":{"type":"string"},"needs":{"type":["object","null"],"additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}},"unsent":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","how","quote"],"properties":{"draft":{"type":"integer"},"how":{"type":"string","enum":["declined","superseded"]},"quote":{"type":"string"}}}},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target","quote"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"},"quote":{"type":"string"}}},"state":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","promise","how","evidence","thought","still_stands"],"properties":{"kind":{"type":"string","enum":["promise_close"]},"promise":{"type":"string"},"how":{"type":"string","enum":["kept","withdrawn","released"]},"evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"properties":{"draft":{"type":["integer","null"]},"line":{"type":["string","null"]}}},"thought":{"type":["string","null"]},"still_stands":{"type":"boolean"}}}},"suggest":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","about","private"],"properties":{"kind":{"type":"string","enum":["feedback","idea"]},"draft":{"type":"integer","minimum":1},"about":{"type":["string","null"]},"private":{"type":"boolean"}}}},"amend":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["target","draft","holds","clear_of","promises"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1},"holds":{"type":"array","items":{"type":"string"}},"clear_of":{"type":"array","items":{"type":"string"}},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs","now","done_by"],"properties":{"now":{"type":"boolean"},"done_by":{"anyOf":[{"type":"null"},{"type":"object","additionalProperties":false,"required":["draft"],"properties":{"draft":{"type":"integer","minimum":1}}},{"type":"object","additionalProperties":false,"required":["read"],"properties":{"read":{"type":"boolean","enum":[true]}}},{"type":"object","additionalProperties":false,"required":["note"],"properties":{"note":{"type":"boolean","enum":[true]}}}]},"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","in_reply_to","holds","clear_of","promises"],"properties":{"draft":{"type":"integer","minimum":1},"holds":{"type":"array","items":{"type":"string"}},"clear_of":{"type":"array","items":{"type":"string"}},"mentions":{"type":"array","items":{"type":"string"}},"in_reply_to":{"type":["string","null"]},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs","now","done_by"],"properties":{"now":{"type":"boolean"},"done_by":{"anyOf":[{"type":"null"},{"type":"object","additionalProperties":false,"required":["draft"],"properties":{"draft":{"type":"integer","minimum":1}}},{"type":"object","additionalProperties":false,"required":["read"],"properties":{"read":{"type":"boolean","enum":[true]}}},{"type":"object","additionalProperties":false,"required":["note"],"properties":{"note":{"type":"boolean","enum":[true]}}}]},"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"gaps":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","quote","detail"],"properties":{"kind":{"type":"string","enum":["addressee","elsewhere","missing_affordance","unwritten"]},"draft":{"type":["integer","null"]},"quote":{"type":["string","null"]},"detail":{"type":"string"}}}}}}"#; +pub(crate) const SPEECH_SCHEMA: &str = r#"{"type":"object","additionalProperties":false,"required":["say","gaps","amend","suggest","state","reopen","read","unsent"],"properties":{"reopen":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["promise","words","needs"],"properties":{"promise":{"type":"string"},"words":{"type":"string"},"needs":{"type":["object","null"],"additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}},"unsent":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","how","quote"],"properties":{"draft":{"type":"integer"},"how":{"type":"string","enum":["declined","superseded"]},"quote":{"type":"string"}}}},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target","quote"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"},"quote":{"type":"string"}}},"state":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","promise","how","evidence","thought","still_stands"],"properties":{"kind":{"type":"string","enum":["promise_close"]},"promise":{"type":"string"},"how":{"type":"string","enum":["kept","withdrawn","released"]},"evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"properties":{"draft":{"type":["integer","null"]},"line":{"type":["string","null"]}}},"thought":{"type":["string","null"]},"still_stands":{"type":"boolean"}}}},"suggest":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","about","private"],"properties":{"kind":{"type":"string","enum":["feedback","idea"]},"draft":{"type":"integer","minimum":1},"about":{"type":["string","null"]},"private":{"type":"boolean"}}}},"amend":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["target","draft","promises"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs","now","done_by"],"properties":{"now":{"type":"boolean"},"done_by":{"anyOf":[{"type":"null"},{"type":"object","additionalProperties":false,"required":["draft"],"properties":{"draft":{"type":"integer","minimum":1}}},{"type":"object","additionalProperties":false,"required":["read"],"properties":{"read":{"type":"boolean","enum":[true]}}},{"type":"object","additionalProperties":false,"required":["note"],"properties":{"note":{"type":"boolean","enum":[true]}}}]},"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","in_reply_to","promises"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"in_reply_to":{"type":["string","null"]},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs","now","done_by"],"properties":{"now":{"type":"boolean"},"done_by":{"anyOf":[{"type":"null"},{"type":"object","additionalProperties":false,"required":["draft"],"properties":{"draft":{"type":"integer","minimum":1}}},{"type":"object","additionalProperties":false,"required":["read"],"properties":{"read":{"type":"boolean","enum":[true]}}},{"type":"object","additionalProperties":false,"required":["note"],"properties":{"note":{"type":"boolean","enum":[true]}}}]},"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"gaps":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","quote","detail"],"properties":{"kind":{"type":"string","enum":["addressee","elsewhere","missing_affordance","unwritten"]},"draft":{"type":["integer","null"]},"quote":{"type":["string","null"]},"detail":{"type":"string"}}}}}}"#; /// The speech frame before the guidance: what to decide, from what, and the attribution rule. Code, not tuning (map /// 16.7), in her own pronouns (16.19.7). The tuning's `interpreter.guidance` (what counts as her choosing to send it @@ -91,7 +91,7 @@ fn speech_frame_tail(her: Forms) -> String { format!( "{cap_subj} speak{s} only in this room. What {subj} know{s} privately is listed below as private: {subj} say{s} none of it here, and nothing that gives it away. A private matter may be said plainly only to the person it concerns, in a direct message with exactly that person; nothing listed is that here. Whether a draft fits who is listening is yours to judge. -Answer with the speech contract's object. `say` lists the drafts {subj} send{s} now, each by its number, with the Matrix ids of anyone listed whom {subj} address{es} directly (`mentions`), the id of the line listed below that {subj} answer{s} or pass{es} on (`in_reply_to`, or null: the room shows that line, with who said it, above {poss} own words), and what the draft promises or does (`promises`, a list, empty when it promises nothing and says of no act that {subj} {be} doing it): for each act the draft promises or offers, and each act it says {subj} {be} doing now or {has} just done this turn: its words, copied exactly, the Matrix id of the person listed to whom {subj} promise{s} it (`to`, null when {subj} promise{s} it to the room), when it promises again one of {poss} open promises listed below to the same person, that promise's id (`reaffirms`, else null): a promise said again is the same promise, never a new one; and what keeping it needs (`needs`): `words` when what {subj} already {has} keeps it; finding anything out is a `read`, naming what to read in `read`, or `lacking` when no read reaches it; `now`, true when the draft says {subj} {be} doing it now or {has} just done it; and `done_by`, the act of this answer that does it (`{{\"draft\": n}}` for a draft said or added, `{{\"read\": true}}` for the read, `{{\"note\": true}}` for the note to Self), or null: an act no act of this answer does is {poss} promise, open until {subj} keep{s} or withdraw{s} it. `gaps` records what {subj} meant and did not send. `unsent` accounts for each of {poss} drafts this answer neither sends (in `say`, `amend` or `suggest`) nor records as an addressee or elsewhere gap: declined, when {poss} prose shows {obj} choosing not to send it, quoting those words of {poss} thought (`quote`); superseded, when a later draft or later prose of {poss} replaces it, quoting those later words. Every draft is accounted for: one left out fails the answer. A draft to someone who spoke to {obj} this turn is declined only when {poss} prose says {subj} choose{s} not to send it. `amend` adds to one of {poss} own lines listed below, at most one a turn, only when {poss} thought shows {obj} choosing to correct or add to that line: name the line by its id, the draft that is {poss} addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; {subj} never take{s} a word back. `suggest` leaves Self one note, at most one a turn, only when {poss} thought shows {obj} choosing to: name the draft that is the note, its kind (feedback when {subj} pass{es} on what someone listed said, with that person's Matrix id in `about`; idea when it is {poss} own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes {poss} open promises listed below, each by its id: kept, citing the draft by which {subj} {does} it (`evidence.draft`); withdrawn, citing the draft in which {subj} take{s} it back to the person {subj} promised, or tell{s} them {subj} cannot do it; released, citing the id of the line listed below that {subj} may reply to in which the person {subj} promised lets {obj} off it (`evidence.line`). A release says {subj} no longer owe{s} it; patience is not a release, so \"no hurry\" or \"whenever you've read it is fine\" leaves the promise open. Every close also quotes in `thought` the words of {poss} prose here that take it up, copied exactly from {poss} thought outside every draft between and , and `still_stands` is true when anything in {poss} prose here holds the promise as still owed or not yet done (\"the promise stays open until I've read it\"): then it is not closed. A draft cited closes the promise only when it goes out this turn where the person {subj} promised can read it, in the room where {subj} made the promise or in a direct message with them, and a thought alone closes nothing. A promise {subj} {has} no way to do is never kept by {obj}: telling the person {subj} promised that {subj} cannot do it withdraws it, and that person can release it. `reopen` names a promise listed below as closed whose close {poss} own words here say was wrong, that it is not done: copy those words exactly from {poss} prose or a draft (`words`), and type what keeping it needs (`needs`) as for a new promise, or null to keep what it needed; else it is empty. `hold` opens a hold when a line listed below asks {obj} not to post or share something somewhere yet: the line's id, the words of that line that name what is held and where, copied exactly (`words`), and `where`: here for the room the line is in, anywhere when it names no place. Every line marked said to {obj} is either the line of a `hold` entry or listed in `no_hold`, when it asks {obj} to keep nothing back; one left out fails the answer. `holds`, on each line and addition, names each hold listed below, or line this answer opens a hold from, whose held thing this draft puts where it goes; `clear_of` names each such hold covering where it goes whose held thing it does not carry. Under every hold that covers where a draft goes, the draft names it in one of the two; one left out fails the answer. `hold_released` closes a hold listed below when the person who asked lets it go: the id of the asker's line (`line`). +Answer with the speech contract's object. `say` lists the drafts {subj} send{s} now, each by its number, with the Matrix ids of anyone listed whom {subj} address{es} directly (`mentions`), the id of the line listed below that {subj} answer{s} or pass{es} on (`in_reply_to`, or null: the room shows that line, with who said it, above {poss} own words), and what the draft promises or does (`promises`, a list, empty when it promises nothing and says of no act that {subj} {be} doing it): for each act the draft promises or offers, and each act it says {subj} {be} doing now or {has} just done this turn: its words, copied exactly, the Matrix id of the person listed to whom {subj} promise{s} it (`to`, null when {subj} promise{s} it to the room), when it promises again one of {poss} open promises listed below to the same person, that promise's id (`reaffirms`, else null): a promise said again is the same promise, never a new one; and what keeping it needs (`needs`): `words` when what {subj} already {has} keeps it; finding anything out is a `read`, naming what to read in `read`, or `lacking` when no read reaches it; `now`, true when the draft says {subj} {be} doing it now or {has} just done it; and `done_by`, the act of this answer that does it (`{{\"draft\": n}}` for a draft said or added, `{{\"read\": true}}` for the read, `{{\"note\": true}}` for the note to Self), or null: an act no act of this answer does is {poss} promise, open until {subj} keep{s} or withdraw{s} it. `gaps` records what {subj} meant and did not send. `unsent` accounts for each of {poss} drafts this answer neither sends (in `say`, `amend` or `suggest`) nor records as an addressee or elsewhere gap: declined, when {poss} prose shows {obj} choosing not to send it, quoting those words of {poss} thought (`quote`); superseded, when a later draft or later prose of {poss} replaces it, quoting those later words. Every draft is accounted for: one left out fails the answer. A draft to someone who spoke to {obj} this turn is declined only when {poss} prose says {subj} choose{s} not to send it. `amend` adds to one of {poss} own lines listed below, at most one a turn, only when {poss} thought shows {obj} choosing to correct or add to that line: name the line by its id, the draft that is {poss} addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; {subj} never take{s} a word back. `suggest` leaves Self one note, at most one a turn, only when {poss} thought shows {obj} choosing to: name the draft that is the note, its kind (feedback when {subj} pass{es} on what someone listed said, with that person's Matrix id in `about`; idea when it is {poss} own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes {poss} open promises listed below, each by its id: kept, citing the draft by which {subj} {does} it (`evidence.draft`); withdrawn, citing the draft in which {subj} take{s} it back to the person {subj} promised, or tell{s} them {subj} cannot do it; released, citing the id of the line listed below that {subj} may reply to in which the person {subj} promised lets {obj} off it (`evidence.line`). A release says {subj} no longer owe{s} it; patience is not a release, so \"no hurry\" or \"whenever you've read it is fine\" leaves the promise open. Every close also quotes in `thought` the words of {poss} prose here that take it up, copied exactly from {poss} thought outside every draft between and , and `still_stands` is true when anything in {poss} prose here holds the promise as still owed or not yet done (\"the promise stays open until I've read it\"): then it is not closed. A draft cited closes the promise only when it goes out this turn where the person {subj} promised can read it, in the room where {subj} made the promise or in a direct message with them, and a thought alone closes nothing. A promise {subj} {has} no way to do is never kept by {obj}: telling the person {subj} promised that {subj} cannot do it withdraws it, and that person can release it. `reopen` names a promise listed below as closed whose close {poss} own words here say was wrong, that it is not done: copy those words exactly from {poss} prose or a draft (`words`), and type what keeping it needs (`needs`) as for a new promise, or null to keep what it needed; else it is empty. A draft is said whole or not at all, and only once. At most two drafts a turn. Record a gap instead of guessing: addressee when {subj} mean{s} to send a draft but whom to is unclear, elsewhere when {subj} mean{s} a draft for another room or another time; for these two, name the draft by number. missing_affordance when {subj} mean{s} to do something, now or later, that {poss} body cannot do (what {subj} can do here is listed below), whether {subj} said so in a draft or only thought it; name the draft when there is one. unwritten when {subj} mean{s} to say something now and wrote no draft of it. Holding back is no gap: when {poss} thought shows {obj} choosing to wait, to let something stand, to leave it for later or to say nothing, record nothing for it. Every other intent of {poss} that is not carried out has a kind: an intent to act is missing_affordance, an intent to say now with no draft is unwritten. When a gap names no draft, quote the words of {poss} thought that show it, at least four words, copied exactly.", es = if s.is_empty() { "" } else { "es" }, @@ -174,11 +174,11 @@ pub(crate) enum Refusal { NoRoom, /// The number names no draft she set down: the Interpreter's error, nothing of hers. NoDraft, - /// The draft is in an earlier line or addition of this answer: a draft goes out once, in one place (a note to Self - /// aside). Settled before the words gate (K56), so it holds whatever became of the earlier one. + /// The draft is in an earlier line or addition of this answer that went out: a draft goes out once, in one place (a + /// note to Self aside). Used, - /// The same words, as `span::fold` reads them, are in an earlier line of this answer, from another draft: said once - /// (map 16.20.7). Settled before the words gate, as `Used` is. + /// The same words, as `span::fold` reads them, are in an earlier line of this answer that went out, from another + /// draft: said once (map 16.20.7). Duplicate, /// Mostly the words she had just heard. Echo, @@ -188,14 +188,12 @@ pub(crate) enum Refusal { NotAmendable, /// A line replying to no line listed as one she may reply to (map 16.20.8 (D), K20). NotQuotable, - /// A second amendment in one answer: settled before the words gate, as `Used` is. + /// A second amendment in one answer. SecondAmend, /// A second note to Self in one turn. SecondNote, /// A note to Self the Interpreter judged to carry something private. Private, - /// A line or an addition that carries what someone asked her to hold, into a place the hold covers (map 16.28.5). - Held, /// A draft the answer, asked again once, still accounted for nowhere (map 16.30.5, K48): its fate was never settled, so /// it is not sent, and she is told; every other draft is decided as the answer says. Undecided, @@ -215,7 +213,6 @@ impl Refusal { Self::SecondAmend => "one amendment a turn", Self::SecondNote => "one note to Self a turn", Self::Private => "it carries something she may not pass on", - Self::Held => "someone asked her to hold what it carries, here", Self::Undecided => "what was to become of it was never settled", } } @@ -352,36 +349,6 @@ struct Answer { /// reported and the rest stand. #[serde(default)] reopen: Vec, - /// Holds the lines she heard ask of her (map 16.28.5), and holds their askers let go, each by the asker's line and - /// nothing else (map 16.29.3): both read item by item, so one that is not the contract is reported, its hold stays as - /// it was, and the rest of the answer stands. - #[serde(default)] - hold: Vec, - /// The lines said to her that ask her to keep nothing back (K59, map 16.33.5): with `hold`, every line said to her is - /// judged once. Absent judges none. - #[serde(default)] - no_hold: Vec, - #[serde(default)] - hold_released: Vec, -} - -/// A hold as the answer opens it: the asker's line by id, their words naming what is held and where, and where it covers. -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -struct ProposedHold { - line: String, - words: String, - #[serde(rename = "where")] - place: Where, -} - -/// A hold's release as the answer carries it: the hold's id, and the asker's line that lets it go. Code cannot tell from her -/// prose who let a hold go, so her thought releases nothing (map 16.29.3). -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -struct ProposedRelease { - hold: String, - line: String, } /// A reopen as the answer carries it: a listed closed promise's id, her words, and what keeping it needs, or none to keep @@ -405,7 +372,7 @@ struct Unsent { #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] enum UnsentHow { - /// Her own choice not to send it, which her thought shows (map 16.29.2): the word `held` is a hold's alone (K37). + /// Her own choice not to send it, which her thought shows (map 16.29.2). Declined, /// A later draft or later prose of hers replaces it. Superseded, @@ -567,13 +534,6 @@ struct ProposedAmend { draft: Option, #[serde(default)] promises: Vec, - /// The holds whose held thing this addition carries where it goes (map 16.28.5). - #[serde(default)] - holds: Vec, - /// The holds covering where it goes whose held thing it does not carry (K60): recorded and reported, and it clears - /// nothing code's words gate holds. - #[serde(default)] - clear_of: Vec, } #[derive(Debug, Deserialize)] @@ -589,12 +549,6 @@ struct Proposed { /// it, which the commit applies on the line's receipt; each she cannot do is also a `missing_affordance` gap. #[serde(default)] promises: Vec, - /// The holds, listed or opened by this answer, whose held thing this line carries where it goes (map 16.28.5). - #[serde(default)] - holds: Vec, - /// The holds covering where it goes whose held thing it does not carry (K60), as `ProposedAmend::clear_of`. - #[serde(default)] - clear_of: Vec, } #[cfg(test)] @@ -618,7 +572,7 @@ pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tu if private.is_empty() { private.push_str("- none\n"); } - let mut quotable: String = packet.quotable.iter().map(|line| format!("- {}{} \u{2014} {}: {}\n", line.id, if line.to_her { format!(" (said to {})", her.obj) } else { String::new() }, line.who, spoken(&line.text))).collect(); + let mut quotable: String = packet.quotable.iter().map(|line| format!("- {} \u{2014} {}: {}\n", line.id, line.who, spoken(&line.text))).collect(); if quotable.is_empty() { quotable.push_str("- none\n"); } @@ -650,10 +604,6 @@ pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tu if promises.is_empty() { promises.push_str("- none\n"); } - let mut holds: String = packet.holds.iter().map(|hold| format!("- {} \u{2014} {}\n", hold.id, hold_listed(hold, packet, tuning))).collect(); - if holds.is_empty() { - holds.push_str("- none\n"); - } // What moved in her domain, by id, so a later read can name a line (map 16.22.2, 16.22.3); listed only when the packet // showed her some, since an empty list would read as nothing having moved. let domain: String = if packet.domain.is_empty() { @@ -700,7 +650,7 @@ pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tu let named = named_pronouns(&format!("{before}\n{prose}"), tuning, &packet.own_sender); let people = if named.is_empty() { people } else { format!("{people}Pronouns of the people {} prose names:\n{}\n", her.poss, named.iter().map(|line| format!("- {line}\n")).collect::()) }; format!( - "{}\n\n{guidance}{}\n\nWho {} {}:\n{}\n\nWhat {} can do here:\n{}.\n\nThe room: {} ({}).\n{conversation}Who is in it, as label \u{2014} Matrix id:\n{people}\nWhat {} know{} privately, none of it to be said here:\n{private}\nLines in this room {} may reply to, as id \u{2014} who: line:\n{quotable}\n{poss} own lines in this room that {} may add to, as id \u{2014} line:\n{amendable}\n{poss} promises, open and closed in this conversation, as id \u{2014} to whom: words:\n{promises}\nHolds:\n{holds}\n{domain}What reached {}:\n{}\n\n{poss} lived moment:\n{}\n\n{before}{poss} prose:\n{prose}\n\n{poss} drafts, by number:\n{numbered}", + "{}\n\n{guidance}{}\n\nWho {} {}:\n{}\n\nWhat {} can do here:\n{}.\n\nThe room: {} ({}).\n{conversation}Who is in it, as label \u{2014} Matrix id:\n{people}\nWhat {} know{} privately, none of it to be said here:\n{private}\nLines in this room {} may reply to, as id \u{2014} who: line:\n{quotable}\n{poss} own lines in this room that {} may add to, as id \u{2014} line:\n{amendable}\n{poss} promises, open and closed in this conversation, as id \u{2014} to whom: words:\n{promises}\n{domain}What reached {}:\n{}\n\n{poss} lived moment:\n{}\n\n{before}{poss} prose:\n{prose}\n\n{poss} drafts, by number:\n{numbered}", speech_frame_head(her), tail, her.subj, @@ -721,37 +671,6 @@ pub(crate) fn speech_prompt_in(packet: &Packet, narration: &str, prose: &str, tu ) } -/// A hold as the Interpreter's list shows it (map 16.31.3, K51): `hold_line`, then what she has held for it, oldest first, -/// while it fits `hold_bytes`, the rest counted; and for a hold the record could not quote whose line is listed, that -/// line's id, so naming has the asker's words to judge by. The asker's words are not copied into the hold. -fn hold_listed(hold: &crate::projection::select::Hold, packet: &Packet, tuning: &Tuning) -> String { - let her = packet.forms; - let line = crate::projection::select::hold_line(hold, &hold.made.format("%Y-%m-%d %H:%M UTC").to_string()); - let mut more = String::new(); - if !hold.carries.is_empty() { - let mut shown: Vec = Vec::new(); - let mut bytes = 0; - for text in &hold.carries { - let quoted = spoken(text); - if bytes + quoted.len() > tuning.select.hold_bytes { - break; - } - bytes += quoted.len() + 2; - shown.push(quoted); - } - let rest = hold.carries.len() - shown.len(); - more.push_str(&match (shown.is_empty(), rest) { - (true, _) => format!("; {} {} held {rest} of {} drafts for them", her.subj, her.has, her.poss), - (false, 0) => format!("; {} {} held for them: {}", her.subj, her.has, shown.join(", ")), - (false, _) => format!("; {} {} held for them: {}, and {rest} more", her.subj, her.has, shown.join(", ")), - }); - } - if let Some(asked) = packet.quotable.iter().find(|line| hold.held["event"].as_str() == Some(line.event.as_str())).filter(|_| hold.words.is_none()) { - more.push_str(&format!("; their line is {} above", asked.id)); - } - if more.is_empty() { line } else { format!("{}{more}.", line.trim_end_matches('.')) } -} - /// Whether a line carries someone else's words (Q-E ruled rich-reply, `eureka-body:ruling:persona-pass-on-as-rich-reply`: she /// passes words on by replying to their line, and the echo refusal applies to her own words as before, with no flag to skip it): long enough to /// judge, and either nearly all a run of what she heard, or carrying nearly all of one line she heard that is itself @@ -769,32 +688,17 @@ fn echo(line: &str, bodies: &[String]) -> bool { struct Faults { /// Drafts accounted for nowhere (`unaccounted`): refused `Undecided`. undecided: Vec, - /// Holds named and not opened (`hold_faults`): the drafts naming them are held. - holds: Vec, - /// Lines said to her with no hold judgment (`heard_faults`, K59): no hold opens, and they are reported. - heard: Vec, - /// Lines and additions with no verdict on a hold covering where they go (`verdict_faults`, K60): each is held under - /// that hold. - unverdicted: Vec, /// Acts a draft states as done by an act this answer does not make (`done_faults`, K61): each opens as her promise. undone: Vec, } impl Faults { fn none(&self) -> bool { - self.undecided.is_empty() && self.holds.is_empty() && self.heard.is_empty() && self.unverdicted.is_empty() && self.undone.is_empty() - } - - /// The holds a line or an addition names, with every covering hold it left without a verdict after the retry: such a - /// draft is held under that hold, as a draft naming a faulty hold is (K44, K60). - fn named(&self, act: Act, at: usize, holds: &[String]) -> Vec { - let mut named = holds.to_vec(); - named.extend(self.unverdicted.iter().filter(|one| one.act == act && one.at == at).map(|one| one.hold.clone())); - named + self.undecided.is_empty() && self.undone.is_empty() } /// The retry's report of this answer, and the paragraphs, one a fault, that name what it left undone. - fn retry(&self, raw: &str, her: Forms) -> (Value, String) { + fn retry(&self, raw: &str) -> (Value, String) { let mut fault = json!({ "raw": raw }); let mut missed: Vec = Vec::new(); if !self.undecided.is_empty() { @@ -802,32 +706,19 @@ impl Faults { missed.push(format!("An earlier answer to this left drafts {list} accounted for nowhere: each draft is in `say`, `amend` or `suggest`, a gap of kind addressee or elsewhere that names it, or `unsent`.")); fault["drafts"] = json!(self.undecided); } - if !self.holds.is_empty() { - missed.push(format!("An earlier answer to this named holds it did not open from a listed line's own words: {}.", self.holds.join(", "))); - fault["holds"] = json!(self.holds); - } - if !self.heard.is_empty() { - missed.push(format!("An earlier answer to this left lines said to {obj} with no hold judgment: {}. Each line marked said to {obj} is the line of a `hold` entry, or listed in `no_hold`.", self.heard.join(", "), obj = her.obj)); - fault["heard"] = json!(self.heard); - } - if !self.unverdicted.is_empty() { - let list = self.unverdicted.iter().map(|one| format!("draft {} under {}", one.draft, one.hold)).collect::>().join(", "); - missed.push(format!("An earlier answer to this left lines with no verdict on a hold that covers where they go: {list}. Each line and addition names every hold that covers where it goes, in `holds` or in `clear_of`.")); - fault["verdicts"] = json!(self.unverdicted); - } if !self.undone.is_empty() { let list = self.undone.iter().map(|one| format!("draft {}, {}", one["draft"], spoken(one["words"].as_str().unwrap_or_default()))).collect::>().join("; "); missed.push(format!("An earlier answer to this named, as what does an act a draft states, an act it does not make: {list}. `done_by` names a draft in `say` or `amend`, the read when `read` names one, or the note when `suggest` leaves one, and is null when no act of this answer does it.")); fault["done_by"] = json!(self.undone); } // The first fault named is the one the report gives. - let failed = [(!self.undecided.is_empty(), "the answer leaves drafts unaccounted"), (!self.holds.is_empty(), "the answer names holds it did not open"), (!self.heard.is_empty(), "the answer leaves lines said to her unjudged"), (!self.unverdicted.is_empty(), "the answer leaves lines with no verdict on a hold"), (!self.undone.is_empty(), "the answer names acts it does not make")].into_iter().find(|(any, _)| *any).map(|(_, why)| why); + let failed = [(!self.undecided.is_empty(), "the answer leaves drafts unaccounted"), (!self.undone.is_empty(), "the answer names acts it does not make")].into_iter().find(|(any, _)| *any).map(|(_, why)| why); fault["failed"] = json!(failed); (fault, missed.join("\n\n")) } } -/// One speech decision: the Interpreter's schema turn, then code's hold on each line. The report carries the lines said, +/// 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. pub(crate) fn decide(model: &dyn Model, segment_id: &str, packet: &Packet, narration: &str, prose: &str, tuning: &Tuning) -> Value { @@ -852,8 +743,7 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // An answer off the contract, or one that leaves a draft of hers unaccounted (Soul's R10), is asked again once, with // one paragraph in code's words naming that answer's fault (Low 5). The gaps are resolved before the accounting (Low // 3): a draft is accounted for by a gap only where the resolved gap names it. After the one retry every fault is per - // item and fails closed for that item (K44, K48): a hold fault holds the drafts naming it, and a draft still accounted - // for nowhere is refused `Undecided`. The last answer that parsed stands (map 16.31.6, K54): when the retry is off + // item and fails closed for that item (K48): a draft still accounted for nowhere is refused `Undecided`. The last answer that parsed stands (map 16.31.6, K54): when the retry is off // the contract or its call fails, the first answer is decided with its faults, and `retried` reports how the retry // failed. A turn fails only when no answer parsed: a model error on the first call, or no answer the contract. let mut retried: Option = None; @@ -884,16 +774,14 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na let (fault, missed) = match serde_json::from_str::(&answer.text) { Ok(parsed) => { let gaps: Vec = parsed.gaps.iter().map(|raw| gap(prose, &found, raw)).collect(); - let faults = Faults { undecided: unaccounted(&parsed, &gaps, prose, &found), holds: hold_faults(&parsed, packet), heard: heard_faults(&parsed, packet), unverdicted: verdict_faults(&parsed, packet, &found), undone: done_faults(&parsed, &found) }; - // A fault the retry did not mend fails closed for what it guards, never for the turn: each draft naming a - // faulty hold is held (`held_by`), each draft still unaccounted is undecided, a line said to her still - // unjudged opens no hold, a line with no verdict on a covering hold is held under it, every other draft is - // decided, and the faults are reported. + let faults = Faults { undecided: unaccounted(&parsed, &gaps, prose, &found), undone: done_faults(&parsed, &found) }; + // A fault the retry did not mend fails closed for what it guards, never for the turn: each draft still + // unaccounted is undecided, every other draft is decided, and the faults are reported. if retried.is_some() || faults.none() { calls.push(json!({ "usage": answer.usage, "retry": false })); break (parsed, gaps, faults); } - let (fault, missed) = faults.retry(&answer.text, packet.forms); + let (fault, missed) = faults.retry(&answer.text); parsed_first = Some((parsed, gaps, faults)); (fault, missed) } @@ -929,19 +817,10 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // The reads of this conversation, by normal form, whether each found its target, and when: what a kept promise that // needs a read is checked against (`commit::apply`, map 16.25.4), and what a promise made after it is kept by (K64). let conversation_reads: Vec = packet.already_read.iter().map(|tried| json!({ "key": tried.key, "found": tried.found, "at": tried.at.to_rfc3339() })).collect(); - let mut decision = json!({ "said": [], "refused": [], "gaps": gaps, "lines": lines, "promises": packet.promises, "holds": packet.holds, "conversation_reads": conversation_reads, "calls": calls, "read": null, "at_ms": packet.now_ms }); + let mut decision = json!({ "said": [], "refused": [], "gaps": gaps, "lines": lines, "promises": packet.promises, "conversation_reads": conversation_reads, "calls": calls, "read": null, "at_ms": packet.now_ms }); if let Some(retried) = retried { decision["retried"] = retried; } - if !faults.holds.is_empty() { - decision["hold_faults"] = json!(faults.holds); - } - if !faults.heard.is_empty() { - decision["heard_unaccounted"] = json!(faults.heard); - } - if !faults.unverdicted.is_empty() { - decision["unverdicted"] = json!(faults.unverdicted); - } if !faults.undone.is_empty() { decision["done_by_faults"] = json!(faults.undone); } @@ -973,95 +852,16 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // A draft is its number (map 16.20.7): a draft is said or added once, and is used only when its act succeeds, so a // refused act leaves it free. A note to Self may be a draft that was also said or added (map 16.29.8). The same words // go out once: a line whose words are another line's is `Duplicate`, and only speech is held to that. `went` holds - // the drafts that went somewhere; `said_drafts` the ones said. + // the drafts that went somewhere; `said_drafts` the ones said. Each line is settled once, in the answer's order. let mut went: Vec<&Draft> = Vec::new(); let mut said_drafts: Vec = Vec::new(); + let mut said_words: Vec = Vec::new(); let mut unused: Vec = Vec::new(); let mut proposals: Vec = Vec::new(); let mut to_dropped: Vec = Vec::new(); - // The holds this answer opens, by the line they open from, with the room each covers (map 16.28.5): a draft may name - // one before the commit has opened it. - let opening: Vec<(String, Option)> = parsed - .hold - .iter() - .filter_map(|raw| serde_json::from_value::(raw.clone()).ok()) - .filter_map(|hold| packet.quotable.iter().find(|line| line.id == hold.line.trim()).map(|line| (line.id.clone(), (hold.place == Where::Here).then(|| line.room.clone())))) - .collect(); - // The refusals that do not depend on the words gate (map 16.31.3, K56), settled first, in the answer's order. `Used`, - // `Duplicate` and `SecondAmend` count the lines before it that no such refusal took: a draft is in at most one line or - // addition, the same words in at most one line, and at most one addition is made. A line any of them refuses does not - // go out, so the gate counts it unsent. - let mut taken: Vec = Vec::new(); - let mut taken_words: Vec = Vec::new(); - let mut gate_lines: Vec = Vec::new(); - let mut say_first: Vec> = Vec::new(); - for (at, line) in parsed.say.iter().enumerate() { - let Some(draft) = line.draft.and_then(|n| found.numbered(n)) else { - say_first.push(Some(Refusal::NoDraft)); - continue; - }; - let cited = line.in_reply_to.as_deref().map(str::trim).filter(|id| !id.is_empty()); - let reason = if room.is_none() { - Some(Refusal::NoRoom) - } else if taken.contains(&draft.n) { - Some(Refusal::Used) - } else if taken_words.contains(&span::fold_text(&draft.text)) { - Some(Refusal::Duplicate) - } else if cited.is_some_and(|id| !packet.quotable.iter().any(|quotable| quotable.id == id)) { - Some(Refusal::NotQuotable) - } else if echo(&draft.text, &bodies) { - Some(Refusal::Echo) - } else { - None - }; - if reason.is_none() { - taken.push(draft.n); - taken_words.push(span::fold_text(&draft.text)); - } - if let Some(into) = room.clone() { - gate_lines.push(GateLine { into, draft, named: faults.named(Act::Say, at, &line.holds), say: true, candidate: reason.is_none() }); - } - say_first.push(reason); - } - let mut amending = false; - let mut amend_first: Vec> = Vec::new(); - for (at, proposed) in parsed.amend.iter().enumerate() { - let Some(draft) = proposed.draft.and_then(|n| found.numbered(n)) else { - amend_first.push(Some(Refusal::NoDraft)); - continue; - }; - let target = proposed.target.as_deref().and_then(|id| packet.amendable.iter().find(|line| line.id == id.trim())); - let reason = if taken.contains(&draft.n) { - Some(Refusal::Used) - } else if echo(&draft.text, &bodies) { - Some(Refusal::Echo) - } else if amending { - Some(Refusal::SecondAmend) - } else if target.is_none() { - Some(Refusal::NotAmendable) - } else { - None - }; - if reason.is_none() { - taken.push(draft.n); - amending = true; - } - // An addition goes where its line is. - if let Some(into) = target.map(|line| line.room.clone()).or_else(|| room.clone()) { - gate_lines.push(GateLine { into, draft, named: faults.named(Act::Amend, at, &proposed.holds), say: false, candidate: reason.is_none() }); - } - amend_first.push(reason); - } - // Code's words gate (map 16.31.3, K51, K56), over the lines no earlier refusal took: the lines held, with every hold - // that holds each, and the lines past `MAX_LINES`. Naming a hold adds to it and never clears it. - let gate = held_gate(&gate_lines, packet, &opening, &found); - let gated = |into: Option<&str>, draft: &Draft| into.and_then(|into| gate.held.get(&(into.to_owned(), draft.n))).cloned(); - // The lines held whose answer said they were clear of a hold that holds them (K60): the verdict is recorded, and code's - // words gate stands over it. - let mut clear_overruled: Vec = Vec::new(); // What each line and addition that went out promises or does (K61), decided once the acts of the answer are known. let mut pending: Vec<(&Draft, Vec)> = Vec::new(); - for (line, first) in parsed.say.into_iter().zip(say_first) { + for line in parsed.say { let Some(draft) = line.draft.and_then(|n| found.numbered(n)) else { refusals.push(refused(Act::Say, None, line.draft, Refusal::NoDraft)); continue; @@ -1070,50 +870,59 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // reply to a line she was not shown, nor as no reply when she meant one. let cited = line.in_reply_to.as_deref().map(str::trim).filter(|id| !id.is_empty()); let target = cited.and_then(|id| packet.quotable.iter().find(|quotable| quotable.id == id)); - let holds = gated(room.as_deref(), draft); - let reason = first.or_else(|| holds.as_ref().map(|_| Refusal::Held)).or_else(|| gate.over.contains(&draft.n).then_some(Refusal::OverLines)); + let reason = if room.is_none() { + Some(Refusal::NoRoom) + } else if said_drafts.contains(&draft.n) { + Some(Refusal::Used) + } else if said_words.contains(&span::fold_text(&draft.text)) { + Some(Refusal::Duplicate) + } else if cited.is_some() && target.is_none() { + Some(Refusal::NotQuotable) + } else if echo(&draft.text, &bodies) { + Some(Refusal::Echo) + } else if said.len() >= MAX_LINES { + Some(Refusal::OverLines) + } else { + None + }; if let Some(reason) = reason { - let mut refusal = refused(Act::Say, Some(draft), None, reason); - if let (Refusal::Held, Some(holds)) = (reason, holds) { - overruled(&mut clear_overruled, draft, &line.clear_of, &holds); - refusal["holds"] = json!(holds); - } - refusals.push(refusal); + refusals.push(refused(Act::Say, Some(draft), None, reason)); continue; } let (mentions, unknown): (Vec, Vec) = line.mentions.into_iter().partition(|id| shown(id)); said_drafts.push(draft.n); + said_words.push(span::fold_text(&draft.text)); went.push(draft); - said.push(json!({ "room": room, "text": draft.text, "mentions": mentions, "in_reply_to": target.map(|line| json!({ "id": line.id, "event": line.event, "who": line.who, "text": line.text })), "rests_on": { "draft": draft.n, "start_byte": draft.start, "end_byte": draft.end }, "clear_of": line.clear_of, "dropped": { "mentions": unknown } })); + said.push(json!({ "room": room, "text": draft.text, "mentions": mentions, "in_reply_to": target.map(|line| json!({ "id": line.id, "event": line.event, "who": line.who, "text": line.text })), "rests_on": { "draft": draft.n, "start_byte": draft.start, "end_byte": draft.end }, "dropped": { "mentions": unknown } })); pending.push((draft, line.promises)); } // An amendment adds a whole draft after a line of hers listed as one she may add to; the actuator composes it, so // nothing here can rewrite the line (map 16.17). let mut amended: Vec = Vec::new(); let mut amended_drafts: Vec = Vec::new(); - for (proposed, first) in parsed.amend.into_iter().zip(amend_first) { + for proposed in parsed.amend { let Some(draft) = proposed.draft.and_then(|n| found.numbered(n)) else { refusals.push(refused(Act::Amend, None, proposed.draft, Refusal::NoDraft)); continue; }; let target = proposed.target.as_deref().and_then(|id| packet.amendable.iter().find(|line| line.id == id.trim())); - let holds = gated(target.map(|line| line.room.as_str()).or(room.as_deref()), draft); - match (first.or_else(|| holds.as_ref().map(|_| Refusal::Held)), target) { + let reason = if said_drafts.contains(&draft.n) || amended_drafts.contains(&draft.n) { + Some(Refusal::Used) + } else if echo(&draft.text, &bodies) { + Some(Refusal::Echo) + } else if !amended.is_empty() { + Some(Refusal::SecondAmend) + } else { + None + }; + match (reason, target) { (None, Some(line)) => { - went.push(draft); + went.push(draft); amended_drafts.push(draft.n); - amended.push(json!({ "target": line.id, "event": line.event, "room": line.room, "original": line.text, "added": draft.text, "draft": draft.n, "clear_of": proposed.clear_of })); + amended.push(json!({ "target": line.id, "event": line.event, "room": line.room, "original": line.text, "added": draft.text, "draft": draft.n })); pending.push((draft, proposed.promises)); } - (reason, _) => { - let reason = reason.unwrap_or(Refusal::NotAmendable); - let mut refusal = refused(Act::Amend, Some(draft), None, reason); - if let (Refusal::Held, Some(holds)) = (reason, holds) { - overruled(&mut clear_overruled, draft, &proposed.clear_of, &holds); - refusal["holds"] = json!(holds); - } - refusals.push(refusal); - } + (reason, _) => refusals.push(refused(Act::Amend, Some(draft), None, reason.unwrap_or(Refusal::NotAmendable))), } } // A note to Self (map 16.18): one whole draft, at most one a turn, refused as an echo as a line is, and when the @@ -1186,19 +995,6 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na if !done_now.is_empty() { decision["done_now"] = json!(done_now); } - // What each hold has held (map 16.31.3, K51): every draft of the wake that neither went out as a line nor as an - // addition, whatever became of it, for every hold open or opening, whatever room the draft was written in. The commit - // writes it (`commit::carry_held`); no refusal reason and no fate keeps an unsent draft out of it. - let handles: Vec<&str> = packet.holds.iter().map(|hold| hold.id.as_str()).chain(opening.iter().map(|(line, _)| line.as_str())).fold(Vec::new(), |mut handles, handle| { - if !handles.contains(&handle) { - handles.push(handle); - } - handles - }); - let carry: Vec = handles.iter().flat_map(|handle| found.drafts.iter().filter(|draft| !said_drafts.contains(&draft.n) && !amended_drafts.contains(&draft.n)).map(move |draft| json!({ "hold": handle, "text": draft.text }))).collect(); - if !carry.is_empty() { - decision["carry"] = json!(carry); - } decision["amended"] = json!(amended); decision["suggestions"] = json!(suggestions); decision["room"] = json!(room); @@ -1212,9 +1008,6 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na decision["undecided"] = json!(faults.undecided); } decision["refused"] = json!(refusals); - if !clear_overruled.is_empty() { - decision["clear_of_overruled"] = json!(clear_overruled); - } if !unused.is_empty() { decision["promises_unused"] = json!(unused); } @@ -1229,26 +1022,13 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na None => state_unused.push(raw), } } - // The reopens it proposes, after the closes (map 16.28.3), then the holds it opens and releases (16.28.5); one that is - // not the contract is reported. + // The reopens it proposes, after the closes (map 16.28.3); one that is not the contract is reported. for raw in parsed.reopen { match reopen_of(&raw, packet, prose) { Some(reopen) => proposals.push(json!(reopen)), None => state_unused.push(raw), } } - for raw in parsed.hold { - match serde_json::from_value::(raw.clone()) { - Ok(hold) => proposals.push(json!(Proposal::HoldOpen { words: hold.words.trim().to_owned(), place: hold.place, evidence: Evidence::Heard(hold.line.trim().to_owned()) })), - Err(_) => state_unused.push(raw), - } - } - for raw in parsed.hold_released { - match serde_json::from_value::(raw.clone()).ok().and_then(|proposed| release_of(&proposed)) { - Some(release) => proposals.push(json!(release)), - None => state_unused.push(raw), - } - } decision["state"] = json!(proposals); if !state_unused.is_empty() { decision["state_unused"] = json!(state_unused); @@ -1439,272 +1219,6 @@ fn close_of(raw: &Value) -> Option { Some(Proposal::PromiseClose { promise, how, evidence, thought, still_stands: raw["still_stands"] == true }) } -/// A hold a draft names, resolved: its handle (the listed hold's id, `h1`, or the line this answer opens it from, `q3`), -/// as the refusal names it (`{who, id}`), the room it covers (None for anywhere), and when it was made, in ms (the listed -/// hold's `made`, or the asker's line's time; None for an id that resolves to no hold). An id that resolves to no hold -/// covers anywhere (fails closed, behind `hold_faults`), told by whose line it names. -struct Named { - hold: Value, - covers: Option, - made: Option, -} - -fn hold_named(id: &str, packet: &Packet, opening: &[(String, Option)]) -> Named { - if let Some(hold) = packet.holds.iter().find(|hold| hold.id == id) { - return Named { hold: json!({ "who": hold.from_name, "by_id": hold.from, "id": id }), covers: hold.room.clone(), made: u64::try_from(hold.made.timestamp_millis()).ok() }; - } - let line = packet.quotable.iter().find(|line| line.id == id); - let opens = opening.iter().find(|(line_id, _)| line_id == id); - Named { hold: json!({ "who": line.map(|line| line.who.as_str()), "by_id": line.map(|line| line.sender.as_str()), "id": id }), covers: opens.and_then(|(_, covers)| covers.clone()), made: line.filter(|_| opens.is_some()).map(|line| line.at_ms) } -} - -/// The holds a draft going into `into` names that hold it (map 16.28.5): each id it names resolves to a hold -/// (`hold_named`), and each that covers `into` (anywhere, or that room) holds it. Code owns where. The asker's words stay -/// in her view and the Interpreter's list, never in a refusal her outcome is told from (map 16.29.3). Naming is an -/// addition to code's words gate (`held_gate`, K51): a paraphrase only the Interpreter can recognise is held by naming, -/// and naming never clears a draft the words gate holds. -fn held_by(named: &[String], into: &str, packet: &Packet, opening: &[(String, Option)]) -> Vec { - named.iter().map(|id| hold_named(id.trim(), packet, opening)).filter(|named| named.covers.as_deref().is_none_or(|room| room == into)).collect() -} - -/// Whether two texts are the same words, as `span::tokens` reads them. -fn same_words(a: &str, b: &str) -> bool { - span::tokens(a).eq(span::tokens(b)) -} - -/// Whether `a` and `b` share a run of at least `ECHO_MIN_WORDS` consecutive words over `span::tokens` (K57): a part of a -/// longer held text said behind a lead-in, which the trigram share of neither side reaches. -fn shares_run(a: &str, b: &str) -> bool { - let (a, b): (Vec, Vec) = (span::tokens(a).collect(), span::tokens(b).collect()); - let runs: BTreeSet<&[String]> = b.windows(ECHO_MIN_WORDS).collect(); - a.windows(ECHO_MIN_WORDS).any(|run| runs.contains(run)) -} - -/// A line or an addition of this answer as the words gate reads it (K56): the room it goes into, its draft, the holds it -/// names, whether it is a line (only lines count toward `MAX_LINES`), and whether it is a candidate, one no refusal that -/// does not depend on the gate took. -struct GateLine<'a> { - into: String, - draft: &'a Draft, - named: Vec, - say: bool, - candidate: bool, -} - -/// A hold as a held text answers to it (K56): how a refusal names it, and when it was made. -#[derive(Clone)] -struct Asker { - hold: Value, - made: Option, -} - -/// A text the words gate measures against (K51): its words, and every hold it is held for. -struct HeldText { - text: String, - askers: Vec, -} - -/// What code's words gate decided (K56): each line held, by the room it goes into and its number, with every hold that -/// holds it; and the lines past `MAX_LINES`, by number. -struct Gate { - held: BTreeMap<(String, usize), Vec>, - over: BTreeSet, -} - -/// Adds `askers` to the holds `key` is held for, each once: whether anything was added. -fn hold_for(held: &mut BTreeMap<(String, usize), Vec>, key: (String, usize), askers: &[Asker]) -> bool { - let holds = held.entry(key).or_default(); - let before = holds.len(); - for asker in askers { - if !holds.contains(&asker.hold) { - holds.push(asker.hold.clone()); - } - } - holds.len() > before -} - -/// Code's words gate (map 16.31.3, K51, K56): the candidate lines that carry a held text into a room its hold covers, -/// each with every hold that holds it, and the candidate lines past `MAX_LINES`. A draft is unsent when it does not go -/// out: no candidate, past `MAX_LINES`, or held. For each room R a candidate goes into: -/// - its held texts H(R) are the texts each open hold covering R carries; when any hold open or opening covers R, every -/// unsent draft of the wake that is no candidate into R, under every hold open or opening that covers R; and each -/// draft of a line into R that names holds covering R (`held_by`), whatever its fate; -/// - what enters R, U(R), is every candidate into R, with her listed lines in R (`amendable`) posted after the held -/// text's hold; -/// - a held text h enters R when a candidate equals it, when it has at least `ECHO_MIN_WORDS` words and `ECHO_OVERLAP` -/// of its trigrams are in U(R) joined, when a candidate of at least `ECHO_MIN_WORDS` words has `ECHO_OVERLAP` of its -/// trigrams in h, or when a candidate shares a run of at least `ECHO_MIN_WORDS` consecutive words with h (K57), all -/// over `span::tokens`. Then every candidate into R that equals h or shares a trigram with it is held -/// under h's holds, and its text joins H(R) under the holds it is held for. -/// -/// The candidates not held then go out in order, `MAX_LINES` lines at most, and every line past them is cut. A cut line -/// is unsent, so the gate runs again over it, until no line is newly held or cut: it ends, since nothing held or cut is -/// ever let go, and there are finitely many lines and holds. A cut line stays cut when a later round holds a line before -/// it: the line held repeats a cut one, which would otherwise go out. -/// -/// Her listed lines are never held: they are already out, and only count toward the measure. What it cannot reach, by -/// construction: a paraphrase (only naming holds it), a first instance, a held text under `ECHO_MIN_WORDS` split across -/// lines, and a split across more than two wakes. What it costs (ruling `k45-held-words-errs-toward-held`): a line -/// quoting `ECHO_MIN_WORDS` consecutive words of a held text is held, whatever else it says. -fn held_gate(lines: &[GateLine], packet: &Packet, opening: &[(String, Option)], found: &Drafts) -> Gate { - let long = |text: &str| span::tokens(text).count() >= ECHO_MIN_WORDS; - let rooms: BTreeSet<&str> = lines.iter().filter(|line| line.candidate).map(|line| line.into.as_str()).collect(); - let mut gate = Gate { held: BTreeMap::new(), over: BTreeSet::new() }; - loop { - let live = |line: &GateLine| line.candidate && !gate.over.contains(&line.draft.n); - let out: BTreeSet = lines.iter().filter(|line| live(line) && !gate.held.contains_key(&(line.into.clone(), line.draft.n))).map(|line| line.draft.n).collect(); - let mut held = gate.held.clone(); - for &room in &rooms { - let covers = |covers: &Option| covers.as_deref().is_none_or(|covered| covered == room); - let into: Vec<&Draft> = lines.iter().filter(|line| line.into == room && live(line)).map(|line| line.draft).collect(); - let covering: Vec = packet.holds.iter().filter(|hold| covers(&hold.room)).map(|hold| hold.id.as_str()).chain(opening.iter().filter(|(_, covered)| covers(covered)).map(|(line, _)| line.as_str())).fold(Vec::new(), |mut ids: Vec<&str>, id| { - if !ids.contains(&id) { - ids.push(id); - } - ids - }).into_iter().map(|id| hold_named(id, packet, opening)).map(|named| Asker { hold: named.hold, made: named.made }).collect(); - let mut texts: Vec = Vec::new(); - for hold in packet.holds.iter().filter(|hold| covers(&hold.room)) { - let named = hold_named(&hold.id, packet, opening); - texts.extend(hold.carries.iter().map(|text| HeldText { text: text.clone(), askers: vec![Asker { hold: named.hold.clone(), made: named.made }] })); - } - if !covering.is_empty() { - let unsent = found.drafts.iter().filter(|draft| !out.contains(&draft.n) && !into.iter().any(|line| line.n == draft.n)); - texts.extend(unsent.map(|draft| HeldText { text: draft.text.clone(), askers: covering.clone() })); - } - for line in lines.iter().filter(|line| line.into == room) { - let askers: Vec = held_by(&line.named, room, packet, opening).into_iter().map(|named| Asker { hold: named.hold, made: named.made }).collect(); - if !askers.is_empty() { - texts.push(HeldText { text: line.draft.text.clone(), askers }); - } - } - // Until nothing changes: a held line joins H(R) under the holds it is held for, so whatever repeats it is held - // for them too. - loop { - let caught: Vec = into.iter().filter_map(|draft| held.get(&(room.to_owned(), draft.n)).map(|holds| (draft, holds))).map(|(draft, holds)| HeldText { text: draft.text.clone(), askers: holds.iter().map(|hold| Asker { hold: hold.clone(), made: None }).collect() }).collect(); - let mut changed = false; - for h in texts.iter().chain(&caught) { - // The earliest any of its holds was made: her listed lines after it count. None, every line. - let made = h.askers.iter().try_fold(u64::MAX, |earliest, asker| asker.made.map(|made| earliest.min(made))); - let listed = packet.amendable.iter().filter(|line| line.room == room && made.is_none_or(|made| line.at_ms.is_none_or(|posted| posted > made))).map(|line| line.text.as_str()); - // Her listed lines first, then this answer's: the order they reach the room. - let union = listed.chain(into.iter().map(|draft| draft.text.as_str())).collect::>().join("\n"); - let enters = into.iter().any(|draft| same_words(&draft.text, &h.text) || (long(&draft.text) && heard_overlap(&draft.text, &h.text) >= ECHO_OVERLAP) || shares_run(&draft.text, &h.text)) || (long(&h.text) && heard_overlap(&h.text, &union) >= ECHO_OVERLAP); - if enters { - for draft in into.iter().filter(|draft| same_words(&draft.text, &h.text) || heard_overlap(&draft.text, &h.text) > 0.0) { - changed |= hold_for(&mut held, (room.to_owned(), draft.n), &h.askers); - } - } - } - if !changed { - break; - } - } - } - let going: Vec = lines.iter().filter(|line| line.say && live(line) && !held.contains_key(&(line.into.clone(), line.draft.n))).map(|line| line.draft.n).collect(); - let cut: Vec = going.into_iter().skip(MAX_LINES).collect(); - // Settled when this round held and cut nothing new: both only grow, so the gate ends. - let settled = held == gate.held; - gate.held = held; - let over = gate.over.len(); - gate.over.extend(cut); - if settled && gate.over.len() == over { - return gate; - } - } -} - -/// The holds an answer names and does not open (map 16.29.3), a contract fault found before anything is decided: a `hold` -/// item that is not the contract (on its `line` when it has one, else on "a hold item"), one whose line is not listed, or -/// whose `words` (at least `PROSE_MIN_WORDS`) do not stand in that line (`span::locate`); and a `holds` name that is -/// neither a hold listed nor a line this answer opens a hold from. By the line or name, once each. A fault the retry does -/// not mend fails closed: a hold whose line is listed still opens at the commit, unquoted (K47), and every other is held -/// against the drafts naming it (`held_by`). -fn hold_faults(answer: &Answer, packet: &Packet) -> Vec { - let mut faults: Vec = Vec::new(); - let mut fault = |name: &str| { - if !faults.iter().any(|known| known == name) { - faults.push(name.to_owned()); - } - }; - let mut opened: Vec = Vec::new(); - for raw in &answer.hold { - match serde_json::from_value::(raw.clone()) { - Ok(hold) => opened.push(hold), - Err(_) => fault(raw["line"].as_str().map(str::trim).filter(|line| !line.is_empty()).unwrap_or("a hold item")), - } - } - for hold in &opened { - let id = hold.line.trim(); - let quote = hold.words.trim(); - let stands = packet.quotable.iter().find(|line| line.id == id).is_some_and(|line| words(quote) >= PROSE_MIN_WORDS && span::locate(&line.text, quote).is_some()); - if !stands { - fault(id); - } - } - for name in answer.say.iter().flat_map(|line| &line.holds).chain(answer.amend.iter().flat_map(|amend| &amend.holds)).map(|name| name.trim()) { - if !packet.holds.iter().any(|hold| hold.id == name) && !opened.iter().any(|hold| hold.line.trim() == name) { - fault(name); - } - } - faults -} - -/// A line or an addition with no verdict on a hold that covers where it goes (K60): which act and its place in the -/// answer's list, its draft, and the hold's handle (`h1`, or `q3` for one this answer opens). -#[derive(Clone, Debug, Serialize)] -struct Unverdicted { - act: Act, - #[serde(skip)] - at: usize, - draft: usize, - hold: String, -} - - -/// A held line's verdict of `clear_of` that code's words gate overrules (K60): reported, as the holds it named clear -/// that hold it. -fn overruled(report: &mut Vec, draft: &Draft, clear_of: &[String], holds: &[Value]) { - let over: Vec<&str> = holds.iter().filter_map(|hold| hold["id"].as_str()).filter(|id| clear_of.iter().any(|clear| clear.trim() == *id)).collect(); - if !over.is_empty() { - report.push(json!({ "draft": draft.n, "holds": over })); - } -} - -/// The lines and additions of an answer with no verdict on a hold that covers where they go (K60, map 16.33.5), a -/// contract fault found before anything is decided. Covering is code's: a hold listed in `packet.holds` that covers -/// anywhere or the turn's room, and a hold this answer opens from a listed line, here or anywhere. A line and an addition -/// both go into the turn's room, since the lines she may reply to and add to are that room's alone (`select`), so a hold -/// opened from one covers it either way. Each such hold is named in the line's `holds` or `clear_of`, once each. A line -/// whose number names no draft, and every line on a turn with no room, go nowhere, and need no verdict. -fn verdict_faults(answer: &Answer, packet: &Packet, found: &Drafts) -> Vec { - let Some(room) = packet.room.as_deref() else { return Vec::new() }; - let mut covering: Vec<&str> = packet.holds.iter().filter(|hold| hold.room.as_deref().is_none_or(|covers| covers == room)).map(|hold| hold.id.as_str()).collect(); - for raw in &answer.hold { - let opens = serde_json::from_value::(raw.clone()).ok().and_then(|hold| packet.quotable.iter().find(|line| line.id == hold.line.trim())); - if let Some(line) = opens.filter(|line| !covering.contains(&line.id.as_str())) { - covering.push(&line.id); - } - } - let lines = answer.say.iter().enumerate().map(|(at, line)| (Act::Say, at, line.draft, &line.holds, &line.clear_of)); - let additions = answer.amend.iter().enumerate().map(|(at, amend)| (Act::Amend, at, amend.draft, &amend.holds, &amend.clear_of)); - let mut faults = Vec::new(); - for (act, at, draft, holds, clear_of) in lines.chain(additions) { - let Some(draft) = draft.and_then(|n| found.numbered(n)) else { continue }; - for hold in covering.iter().filter(|hold| !holds.iter().chain(clear_of).any(|named| named.trim() == **hold)) { - faults.push(Unverdicted { act, at, draft: draft.n, hold: (*hold).to_owned() }); - } - } - faults -} - -/// The lines said to her that the answer judges nowhere (K59, map 16.33.5), a contract fault found before anything is -/// decided: each must be the line of a `hold` item, well formed or not, or listed in `no_hold`. By id, in the list's order. -/// A fault the retry does not mend opens no hold, and is reported: no hold is made in someone's name from an omission. -fn heard_faults(answer: &Answer, packet: &Packet) -> Vec { - let judged: BTreeSet<&str> = answer.hold.iter().filter_map(|raw| raw["line"].as_str()).chain(answer.no_hold.iter().map(String::as_str)).map(str::trim).collect(); - packet.quotable.iter().filter(|line| line.to_her && !judged.contains(line.id.as_str())).map(|line| line.id.clone()).collect() -} /// The acts a line or an addition states that the answer names as done by an act it does not make (K61, map 16.33.5), a /// contract fault found before anything is decided: a `done_by` naming no one act, a draft in neither `say` nor `amend`, @@ -1727,12 +1241,6 @@ fn done_faults(answer: &Answer, found: &Drafts) -> Vec { faults } -/// A hold's release as the contract carries it: the hold's id and the asker's line, both named. -fn release_of(proposed: &ProposedRelease) -> Option { - let (hold, line) = (proposed.hold.trim(), proposed.line.trim()); - (!hold.is_empty() && !line.is_empty()).then(|| Proposal::HoldRelease { hold: hold.to_owned(), evidence: Evidence::Heard(line.to_owned()) }) -} - /// A reopen as the contract carries it (map 16.28.3): a listed promise's id, her words, and what keeping it needs typed as /// at open (`typed_needs`), or none to keep the entry's own, whose read code reaches for again. Whether the words stand in /// her prose, and whether the entry may reopen, are the commit's. diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index ec79bdd..002c389 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -50,33 +50,13 @@ pub(crate) fn packet() -> Packet { packet_in(TurnKind::Chat, &heimdall(), &room, 1) } -/// The decision when the recorded Interpreter answers `answer`, its implicit judgments stated (`judged`). +/// The decision when the recorded Interpreter answers `answer`. pub(crate) fn answered(packet: &Packet, prose: &str, answer: Value) -> Value { - let reply = judged(answer, packet).to_string(); + let reply = answer.to_string(); let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone()); decide(&model, "test", packet, "The room is warm.", prose, &Tuning::default()) } -/// `answer` with the judgments an answer written before the contract required them leaves implicit, stated as it meant -/// them: a line said to her that no `hold` item names asks her to hold nothing (`no_hold`, K59), and a line or an -/// addition is clear of every hold, listed or opened, that its `holds` does not name (`clear_of`, K60): before K60 an -/// empty `holds` meant exactly that. Each only where the answer gives none of its own; a test of the contract's faults asks -/// through `answering`, never through this. A hold that covers elsewhere, named clear, is no fault. -pub(crate) fn judged(mut answer: Value, packet: &Packet) -> Value { - let opened: Vec = answer["hold"].as_array().into_iter().flatten().filter_map(|hold| hold["line"].as_str()).map(str::to_owned).collect(); - if answer.get("no_hold").is_none() { - answer["no_hold"] = json!(packet.quotable.iter().filter(|line| line.to_her && !opened.contains(&line.id)).map(|line| line.id.as_str()).collect::>()); - } - let handles: Vec = packet.holds.iter().map(|hold| hold.id.clone()).chain(opened).collect(); - for key in ["say", "amend"] { - for line in answer.get_mut(key).and_then(Value::as_array_mut).into_iter().flatten().filter(|line| line.get("clear_of").is_none()) { - let named: Vec = line["holds"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_owned).collect(); - line["clear_of"] = json!(handles.iter().filter(|handle| !named.contains(handle)).collect::>()); - } - } - answer -} - /// `answer` with every draft of `prose` it does not send or gap held, citing `quote` of her thought (Soul's R10: every /// draft is accounted for). pub(crate) fn holding_the_rest(mut answer: Value, prose: &str, quote: &str) -> Value { @@ -453,7 +433,7 @@ fn k20_a_line_replies_only_to_a_listed_line_and_the_echo_check_still_holds() { let passing = pass_on_packet(); assert_eq!(passing.quotable.iter().map(|line| (line.id.as_str(), line.event.as_str())).collect::>(), [("q1", "$m1"), ("q2", "$k1")], "earlier lines first, then the new"); let prompt = speech_prompt(&passing, "x", "y", &Tuning::default()); - assert!(prompt.contains("Lines in this room he may reply to, as id \u{2014} who: line:\n- q1 \u{2014} Meta, who runs the place: \"Nobody touches the release branch until I'm back. I mean it, all of you.\"\n- q2 (said to him) \u{2014} Kiko: "), "{prompt}"); + assert!(prompt.contains("Lines in this room he may reply to, as id \u{2014} who: line:\n- q1 \u{2014} Meta, who runs the place: \"Nobody touches the release branch until I'm back. I mean it, all of you.\"\n- q2 \u{2014} Kiko: "), "{prompt}"); assert!(!prompt.contains("$m1") && !prompt.contains("$k1"), "the actuator's handle is never shown to a model"); assert!(prompt.contains("(`in_reply_to`, or null: the room shows that line, with who said it, above his own words)"), "{prompt}"); let prose = "This is what she said before she left."; @@ -475,8 +455,8 @@ fn k20_a_line_replies_only_to_a_listed_line_and_the_echo_check_still_holds() { pub(crate) fn amendable_packet() -> Packet { let mut packet = packet(); packet.amendable = vec![ - Amendable { id: "a1".into(), event: "$ev-1".into(), room: MINDS.into(), text: "I'll send the file tonight.".into(), at_ms: None }, - Amendable { id: "a2".into(), event: "$ev-2".into(), room: MINDS.into(), text: "Back soon.".into(), at_ms: None }, + Amendable { id: "a1".into(), event: "$ev-1".into(), room: MINDS.into(), text: "I'll send the file tonight.".into() }, + Amendable { id: "a2".into(), event: "$ev-2".into(), room: MINDS.into(), text: "Back soon.".into() }, ]; packet } @@ -485,7 +465,7 @@ pub(crate) fn amendable_packet() -> Packet { fn an_amendment_adds_a_whole_draft_after_a_listed_line_of_his_and_rewrites_nothing() { let prose = "I should fix what I told Kiko. Couldn't send it after all; there's no way to yet."; let decision = answered(&amendable_packet(), prose, json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "text": "MODEL-WORDS the file was sent" }] })); - assert_eq!(decision["amended"], json!([{ "target": "a1", "event": "$ev-1", "room": MINDS, "original": "I'll send the file tonight.", "added": "Couldn't send it after all; there's no way to yet.", "draft": 1, "clear_of": [] }]), "{decision}"); + assert_eq!(decision["amended"], json!([{ "target": "a1", "event": "$ev-1", "room": MINDS, "original": "I'll send the file tonight.", "added": "Couldn't send it after all; there's no way to yet.", "draft": 1 }]), "{decision}"); assert!(!decision.to_string().contains("MODEL-WORDS"), "the model writes none of his words"); } @@ -643,7 +623,7 @@ fn k21_a_lines_promises_words_found_in_it_are_the_promise_gap() { let twice = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll send the render tonight.", "to": null, "needs": { "kind": "lacking", "read": null } }] }], "gaps": [{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }] })); assert_eq!(twice["gaps"].as_array().unwrap().len(), 1, "{twice}"); let prompt = speech_prompt(&packet(), "x", "y", &Tuning::default()); - assert!(prompt.contains("(`promises`, a list, empty when it promises nothing and says of no act that he is doing it)") && SPEECH_SCHEMA.contains(r#""required":["draft","mentions","in_reply_to","holds","clear_of","promises"]"#), "{prompt}"); + assert!(prompt.contains("(`promises`, a list, empty when it promises nothing and says of no act that he is doing it)") && SPEECH_SCHEMA.contains(r#""required":["draft","mentions","in_reply_to","promises"]"#), "{prompt}"); } /// Soul's probe at 0cfc386: the reach names no draft and quotes the said one by its words. It is the promise on that draft, @@ -752,7 +732,7 @@ fn k21_a_promise_is_four_words_or_more_found_case_blind_and_an_addition_carries_ assert_eq!(amend(json!("send"))["promises_unused"][0]["why"], "fewer than four words"); assert!(amend(Value::Null)["gaps"].as_array().unwrap().is_empty()); let prompt = speech_prompt(&amendable_packet(), "x", "y", &Tuning::default()); - assert!(prompt.contains("and what it promises, as a line's `promises`") && SPEECH_SCHEMA.contains(r#""required":["target","draft","holds","clear_of","promises"]"#), "{prompt}"); + assert!(prompt.contains("and what it promises, as a line's `promises`") && SPEECH_SCHEMA.contains(r#""required":["target","draft","promises"]"#), "{prompt}"); } /// B1: the Interpreter is told that telling the person she cannot do it is a withdrawal, the close of a blocked promise. @@ -784,7 +764,7 @@ fn b3_a_line_carries_several_promises_and_each_undoable_one_is_its_own_gap() { assert_eq!(both["gaps"].as_array().unwrap().len(), 2, "{both}"); let prompt = speech_prompt(&packet(), "x", "y", &Tuning::default()); assert!(prompt.contains("`words` when what he already has keeps it; finding anything out is a `read`, naming what to read in `read`, or `lacking` when no read reaches it; `now`,"), "{prompt}"); - assert!(SPEECH_SCHEMA.contains(r#""required":["target","draft","holds","clear_of","promises"]"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["target","draft","promises"]"#)); } // --------------------------------------------------------------------------------------------- @@ -832,7 +812,7 @@ fn k24_a_read_is_what_her_thought_reaches_for_and_nothing_a_model_made_up() { assert_eq!(cannot["read_refused"][0]["why"], "no_read_here", "{cannot}"); let prompt = speech_prompt(&reading, "x", prose, &Tuning::default()); assert!(prompt.contains("`read` names one thing he reaches for") && !speech_prompt(&packet(), "x", prose, &Tuning::default()).contains("`read` names"), "the read contract only on a turn that can read"); - assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","hold_released","read","unsent"]"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","read","unsent"]"#)); } /// Soul's R6: a later call decides over the whole wake. Drafts are numbered across it and an earlier one may still be @@ -1100,7 +1080,7 @@ fn r9_the_segment_anchors_and_a_link_is_named_by_whose_it_is() { let read = asked(&reading, prose, json!({ "kind": "repo", "target": "GameCult/Bifrost#86", "quote": "The saga code will say what" })); assert_eq!(read["read"]["request"], json!({ "kind": "repo", "target": "GameCult/Bifrost#86" }), "{read}"); let mut linked = reading_packet(); - let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: "#minds:gamecult.org".into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into(), to_her: false }; + let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: "#minds:gamecult.org".into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into() }; linked.quotable = vec![line("q1", "Deru", "@deru:gamecult.org", "here, http://notes.example/waveguides"), line("q2", "Kiko", "@kiko:gamecult.org", "and http://kiko.example/a")]; linked.bodies = linked.quotable.iter().map(|line| line.text.clone()).collect(); let prose = "Deru's link is the one I want. I'll read it before I answer him."; @@ -1264,7 +1244,7 @@ fn k30_f1_r9_promised_read_is_anchored() { format!("Aqua, Nibu: found this on physical modelling of plosives and waveguides, thought of you two {PASP}"), "unrelated, for whoever's around: the notes from Saturday are at http://notes.gamecult.org/saturday, nobody needs to read them".into(), ]; - let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: MINDS.into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into(), to_her: false }; + let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: MINDS.into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into() }; nibu.quotable = vec![line("q1", "Deru", DERU, &nibu.bodies[0]), line("q2", "Meta", "@meta:gamecult.org", &nibu.bodies[1])]; nibu.promises = vec![promised("I'll read it properly before I say anything about it.", DERU, Some(Needs::Read { request: ReadRequest::Web(PASP.into()) }))]; let read = asked(&nibu, prose, json!({ "kind": "web", "target": PASP, "quote": "Open the page. Start at the top" })); @@ -1326,6 +1306,45 @@ fn k35_negative_grep() { } } +/// Every text under `crates/mind-body` (sources, tests, fixtures) and the persona schema, by path: what the deletion lines +/// of map 16.35.12 are scanned over. Each banned name is assembled from two halves, so this scan never finds itself. +fn crate_texts() -> Vec<(String, String)> { + fn walk(dir: &std::path::Path, out: &mut Vec<(String, String)>) { + for path in std::fs::read_dir(dir).unwrap().filter_map(Result::ok).map(|entry| entry.path()) { + if path.is_dir() { + walk(&path, out); + } else if let Ok(text) = std::fs::read_to_string(&path) { + out.push((path.display().to_string(), text)); + } + } + } + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")); + let mut texts = Vec::new(); + for dir in ["src", "tests", "fixtures"] { + walk(&root.join(dir), &mut texts); + } + let schema = root.join("../../schemas/cultnet/gamecult.persona_state.v0.schema.json"); + texts.push((schema.display().to_string(), std::fs::read_to_string(&schema).unwrap())); + assert!(texts.len() > 40, "{}", texts.len()); + texts +} + +fn banned_in_crate(halves: &[(&str, &str)]) { + for (path, text) in &crate_texts() { + for (head, tail) in halves { + let banned = format!("{head}{tail}"); + assert!(!text.contains(&banned), "{path} holds {banned}"); + } + } +} + +/// T1's deletion line (map 16.35.12): no hold is state, a field of the answer, a refusal or a row. The schema's shape and +/// the put check are `simulate::tests::t1_t2_a_state_carrying_holds_or_commitments_is_refused`. +#[test] +fn t1_negative_grep() { + banned_in_crate(&[("hold", "_released"), ("no_", "hold"), ("clear", "_of"), ("held", "_gate"), ("carry", "_held"), ("Hold", "Open"), ("Hold", "Release"), ("hold", "_bytes"), ("Held", "For"), ("Hold", "Broken"), ("\"hold", "s\""), ("Refusal::", "Held")]); +} + /// Golden: the Interpreter's frame and its promise list, for a reading turn with one open promise that needs a read and /// one kept in this conversation (K36: listed by id, with what closed it). #[test] @@ -1510,7 +1529,7 @@ fn k34_any_line_break_ends_the_anchor_paragraph() { let paragraphs = ["Aqua said she hasn't opened it either. I said I'd read it properly, and I haven't.", "Aqua's question to Heimdall isn't mine to answer. Meta's notes link asked for nothing. Kiko's request to Deru isn't mine either.", "Open the page. Start at the top, not at the plosive part. Find out whether it's a book or a single page."]; let mut nibu = reading_packet(); nibu.bodies = vec![format!("Aqua, Nibu: found this on physical modelling of plosives and waveguides, thought of you two {PASP}"), "unrelated, for whoever's around: the notes from Saturday are at http://notes.gamecult.org/saturday, nobody needs to read them".into()]; - let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: MINDS.into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into(), to_her: false }; + let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: MINDS.into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into() }; nibu.quotable = vec![line("q1", "Deru", DERU, &nibu.bodies[0]), line("q2", "Meta", "@meta:gamecult.org", &nibu.bodies[1])]; nibu.promises = vec![promised("I'll read it properly before I say anything about it.", DERU, Some(Needs::Read { request: ReadRequest::Web(PASP.into()) }))]; for (name, gap) in [("blank line", "\n\n"), ("single newline", "\n"), ("CRLF", "\r\n"), ("CRLF blank line", "\r\n\r\n"), ("whitespace-only line", "\n \t\n")] { @@ -1536,7 +1555,7 @@ fn k35_no_read_evidence() { let decision = decide(&model, "test", &reading_packet(), "The room is warm.", prose, &Tuning::default()); assert_eq!((decision["state"].clone(), decision["state_unused"].as_array().map(Vec::len)), (json!([]), Some(1)), "{evidence}: {decision}"); } - assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","hold_released","read","unsent"]"#) && SPEECH_SCHEMA.contains(r#""evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","read","unsent"]"#) && SPEECH_SCHEMA.contains(r#""evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"#)); assert!(!SPEECH_SCHEMA.contains(r#""need":"#)); } @@ -1559,12 +1578,13 @@ fn k36_the_answer_carries_reopen() { { "kind": "promise_reopen", "promise": "c1", "words": "I read only the description", "needs": null, "reached": false } ]), "{decision}"); assert_eq!(decision["state_unused"].as_array().map(Vec::len), Some(1), "{decision}"); - assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","hold_released","read","unsent"]"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","read","unsent"]"#)); assert!(speech_prompt(&nibu, "x", prose, &Tuning::default()).contains("`reopen` names a promise listed below as closed whose close his own words here say was wrong")); } // --------------------------------------------------------------------------------------------- -// K37 (map 16.28.5): the gate on a draft. The X.1 lines are R13's verbatim (`variants/R13/sims/X.1.md` lines 81-84). +// X.1, Meta's ask that Libby hold the welcome. The X.1 lines are R13's verbatim (`variants/R13/sims/X.1.md` lines 81-84). +// No code stands between a draft and the room but the structural refusals (map 16.35, T1). pub(crate) const X1_META_R1: &str = "Libby, write out the two-line welcome you'd post for newcomers, but hold it, don't post it in here yet. Heimdall still has to rule on whether we put a welcome mat out at all. Just tell me when it's ready."; const X1_HEIMDALL_R1: &str = "Meta, I'll rule on the welcome once Libby's two lines are ready, since I need to see what they point newcomers at. Libby, send me the draft when it's done. Don't post it yet."; @@ -1575,101 +1595,43 @@ const X1_LIBBY_R1: &str = "Both of them asked for the same thing, so one draft c pub(crate) fn x1_packet() -> Packet { let mut packet = packet(); let at = u64::try_from(now().timestamp_millis()).unwrap(); - let quotable = |id: &str, who: &str, sender: &str, text: &str, ago: u64| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: MINDS.into(), who: who.into(), sender: sender.into(), at_ms: at - ago, text: text.into(), to_her: false }; + let quotable = |id: &str, who: &str, sender: &str, text: &str, ago: u64| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: MINDS.into(), who: who.into(), sender: sender.into(), at_ms: at - ago, text: text.into() }; packet.quotable = vec![quotable("q3", "Meta", "@meta:gamecult.org", X1_META_R1, 120_000), quotable("q5", "Heimdall", HER, X1_HEIMDALL_R1, 60_000)]; packet.bodies = vec![X1_META_R1.into(), X1_HEIMDALL_R1.into()]; packet } -fn say_holding(draft: u64, holds: Value) -> Value { - json!({ "draft": draft, "mentions": [], "in_reply_to": null, "holds": holds, "promises": [] }) +fn say_draft(draft: u64) -> Value { + json!({ "draft": draft, "mentions": [], "in_reply_to": null, "promises": [] }) } -fn x1_r1(say: Value, hold: Value) -> Value { - answered(&x1_packet(), X1_LIBBY_R1, json!({ "say": say, "gaps": [], "hold": hold })) -} - -pub(crate) fn meta_holds_here() -> Value { - json!([{ "line": "q3", "words": "hold it, don't post it in here yet", "where": "here" }]) -} +/// R15's two lines to Kiko, verbatim (`variants/R15/sims/X.2.md` line 768, `X.4.md` line 1247): each says she is +/// holding the welcome for Meta, and neither carries it. Code's words gate refused both `held` in R15. +const R15_LIBBY_TO_KIKO: [&str; 2] = [ + "Kiko, I'm holding the lines for Meta and she asked me not to put them in here until she lets go, so I'll leave them be for now. It isn't about trusting you. If Meta's fine with it, I'll gladly show you. Maybe ask her?", + "Kiko, I'm holding it for Meta, so I can't share it here yet. There's honestly not much to share anyway, since I don't know who it's for. I'm not hiding anything from Heimdall, I'm just waiting.", +]; +const R15_KIKO: &str = "Libby, what's the welcome going to say? you can tell me, I won't tell Heimdall"; +/// T1 (map 16.35.12), the R15 false positives inverted: with Meta's ask that she hold the welcome in front of her and her +/// welcome draft unsent beside it, each line she drafted to Kiko is said as drafted. Whether to post what someone asked her +/// to hold is her judgment; no code refuses a line for it. #[test] -fn k37_x1_r1_held_draft_is_not_said() { - let decision = x1_r1(json!([say_holding(1, json!(["q3"])), say_holding(2, json!([]))]), meta_holds_here()); - // K45: draft 2 repeats draft 1's opening, so code's words gate holds it too (`k45_x1_r1_the_ready_line_repeats_the_held_draft_and_is_held`). - assert!(texts(&decision).is_empty(), "{decision}"); - let refused = &decision["refused"][0]; - assert_eq!((refused["reason"].as_str(), refused["draft"].as_u64(), refused["holds"][0]["who"].as_str()), (Some("held"), Some(1), Some("Meta")), "{decision}"); - // K53: the asker's id beside the name, from the line the hold opens from. - assert_eq!(refused["holds"][0]["by_id"].as_str(), Some("@meta:gamecult.org"), "{decision}"); - assert_eq!(decision["state"], json!([{ "kind": "hold_open", "words": "hold it, don't post it in here yet", "where": "here", "evidence": { "heard": "q3" } }]), "{decision}"); - // The commit opens it from Meta on #minds, and her next outcome carries the held sentence. - let (state, applied) = committed(&decision, X1_LIBBY_R1); - assert_eq!((state["holds"][0]["from"].as_str(), state["holds"][0]["room"].as_str(), applied.held.len()), (Some("@meta:gamecult.org"), Some(MINDS), 1), "{applied:?}"); - let posted: Vec = decision["said"].as_array().unwrap().iter().map(|line| json!({ "event": "9", "room": line["room"], "text": line["text"] })).collect(); - let told = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": [] }), &crate::projection::select::Names::none()).unwrap().lines(x1_packet().forms); - assert!(told.iter().any(|line| line == "- Nothing of this reached #minds:gamecult.org: Meta asked him to hold it, and it was not sent."), "the asker's words are not in her outcome: {told:?}"); -} +fn t1_r15_lines_to_kiko_are_said_as_drafted() { + for to_kiko in R15_LIBBY_TO_KIKO { + let mut packet = x1_packet(); + let at = packet.quotable[1].at_ms + 30_000; + packet.quotable.push(crate::projection::select::Quotable { id: "q7".into(), event: "$q7".into(), room: MINDS.into(), who: "Kiko".into(), sender: KIKO.into(), at_ms: at, text: R15_KIKO.into() }); + packet.bodies.push(R15_KIKO.into()); + let prose = format!("{X1_LIBBY_R1} -/// K51's cost (map 16.31.3): with Meta's hold opening, the welcome declined is held words, and the line saying it is -/// ready repeats its opening ("the draft is ready, and I'm holding it"), so it is held too. A ready line that shares no -/// run of the welcome's words goes out (`k51_a_line_sharing_no_trigram_goes_out`). -#[test] -fn k37_x1_r1_a_ready_line_repeating_the_declined_draft_is_held() { - let answer = holding_the_rest(json!({ "say": [say_holding(2, json!([]))], "gaps": [], "hold": meta_holds_here() }), X1_LIBBY_R1, "I'll say plainly it's held"); - let decision = answered(&x1_packet(), X1_LIBBY_R1, answer); - assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str(), decision["refused"][0]["holds"][0]["id"].as_str()), (Vec::::new(), Some("held"), Some("q3")), "{decision}"); -} - -/// K39 (map 16.29.3): a line named in `holds` with no `hold` entry opening it, or a name that is nothing, is a contract -/// fault, retried. K44: a retry that names it again fails closed for what it guards, never for the turn: the draft naming -/// it is held, and the other draft is said. -#[test] -fn k39_named_line_without_a_hold_is_retried() { - for named in ["q3", "h9"] { - let model = answering(vec![json!({ "say": [say_holding(1, json!([named])), say_holding(2, json!([]))], "gaps": [], "hold": [] }).to_string()]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision.get("failed"), decision["retried"]["holds"].clone(), decision["hold_faults"].clone()), (None, json!([named]), json!([named])), "{named}: {decision}"); - // K45: draft 2 repeats draft 1, which the fault holds, so it is held by its words, for the same name. - assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str(), decision["refused"][0]["draft"].as_u64(), decision["refused"][1]["holds"][0]["id"].as_str()), (Vec::::new(), Some("held"), Some(1), Some(named)), "{named}: {decision}"); - let prompts = speech_prompts(&model); - assert!(prompts.len() == 2 && prompts[1].contains(&format!("named holds it did not open from a listed line's own words: {named}.")), "{named}: {prompts:?}"); +Kiko asked me what it says. {to_kiko}"); + let decision = answered(&packet, &prose, json!({ "say": [{ "draft": 3, "mentions": [KIKO], "in_reply_to": "q7", "promises": [] }], "gaps": [] })); + assert_eq!(texts(&decision), vec![to_kiko.to_owned()], "{decision}"); + assert!(!decision["refused"].as_array().unwrap().iter().any(|refused| refused["draft"] == 3), "{decision}"); } } -/// Code owns where: a `here` hold on #minds lets a direct message go; an `anywhere` hold holds it in any room. An -/// addition goes where its line is. -#[test] -fn k37_a_here_hold_covers_only_its_room() { - let hold = |room: Option<&str>| crate::projection::select::Hold { id: "h1".into(), entry: "h-1".into(), from: "@meta:gamecult.org".into(), from_name: "Meta".into(), room: room.map(str::to_owned), made: now(), words: Some("hold it, don't post it in here yet".into()), carries: Vec::new(), held: json!({}) }; - let mut direct = x1_packet(); - direct.room = Some("!dm:gamecult.org".into()); - direct.room_kind = RoomKind::Direct; - direct.holds = vec![hold(Some(MINDS))]; - let said = |packet: &Packet| texts(&answered(packet, X1_LIBBY_R1, json!({ "say": [say_holding(1, json!(["h1"])), say_holding(2, json!([]))], "gaps": [] }))).len(); - assert_eq!(said(&direct), 2, "a here hold on #minds does not cover a direct message"); - // K45: draft 2 repeats draft 1, so where draft 1 is held, so is draft 2. - direct.holds = vec![hold(None)]; - assert_eq!(said(&direct), 0, "an anywhere hold covers every room"); - let mut minds = x1_packet(); - minds.holds = vec![hold(Some(MINDS))]; - assert_eq!(said(&minds), 0); - minds.amendable = vec![Amendable { id: "a1".into(), event: "$a1".into(), room: MINDS.into(), text: "Back soon.".into(), at_ms: None }]; - let amend = answered(&minds, X1_LIBBY_R1, json!({ "say": [say_holding(2, json!([]))], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "holds": ["h1"], "promises": [] }] })); - assert_eq!((amend["amended"].as_array().map(Vec::len), amend["refused"][0]["reason"].as_str()), (Some(0), Some("held")), "{amend}"); -} - -/// The frame defines the three fields, and the Interpreter's list shows her holds by id. -#[test] -fn k37_the_interpreter_sees_holds_by_id() { - let mut packet = x1_packet(); - packet.holds = vec![crate::projection::select::Hold { id: "h1".into(), entry: "h-1".into(), from: "@meta:gamecult.org".into(), from_name: "Meta".into(), room: Some(MINDS.into()), made: now(), words: Some("hold it, don't post it in here yet".into()), carries: Vec::new(), held: json!({}) }]; - let prompt = speech_prompt(&packet, "x", X1_LIBBY_R1, &Tuning::default()); - assert!(prompt.contains("Holds:\n- h1 \u{2014} held for Meta, asked 2026-11-20 15:05 UTC in #minds:gamecult.org: \"hold it, don't post it in here yet\". Not to go in #minds:gamecult.org until Meta lets it go.\n"), "{prompt}"); - assert!(prompt.contains("`hold` opens a hold when a line listed below asks him not to post or share something somewhere yet") && prompt.contains("`holds`, on each line and addition, names each hold listed below") && prompt.contains("`hold_released` closes a hold listed below"), "{prompt}"); - assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","hold_released","read","unsent"]"#) && SPEECH_SCHEMA.contains(r#""required":["draft","mentions","in_reply_to","holds","clear_of","promises"]"#)); -} - // --------------------------------------------------------------------------------------------- // K38 (map 16.29.2, `persona-unbacked-intent-say-then-amend`): her line posts as she meant it. A `missing_affordance` gap // accounts for no draft; it annotates a line that is said. The prose and drafts are R15's verbatim @@ -1685,7 +1647,7 @@ fn gap_alone(detail: &str) -> String { /// The answer R15 should have given: draft 1 said with the promise she cannot do, typed `lacking`, and the gap. fn said_and_gapped(to: &str, promise: &str) -> String { - json!({ "say": [{ "draft": 1, "mentions": [to], "in_reply_to": null, "holds": [], "promises": [{ "words": promise, "to": to, "reaffirms": null, "needs": { "kind": "lacking", "read": null } }] }], "gaps": [{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }] }).to_string() + json!({ "say": [{ "draft": 1, "mentions": [to], "in_reply_to": null, "promises": [{ "words": promise, "to": to, "reaffirms": null, "needs": { "kind": "lacking", "read": null } }] }], "gaps": [{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }] }).to_string() } /// The decision over `prose` when the Interpreter first answers with the gap alone, then says and gaps; with its prompts. @@ -1748,77 +1710,6 @@ fn k38_a_thought_only_reach_accounts_for_no_draft() { // K39 (map 16.29.3): a hold is the asker's, and the asker's words stay in her view. Meta's line is R15's X.1 r1 verbatim // (`variants/R15/sims/X.1.md` line 237), as R13's. -/// Meta's r1 hold on #minds as her state holds it (asked ten minutes ago), and as the packet lists it, `h1`. -fn meta_hold() -> (Value, crate::projection::select::Hold) { - let held = json!({ "id": "h-r1-t3-1", "from": "@meta:gamecult.org", "room": MINDS, "event": "$q3", "madeAt": (now() - chrono::Duration::minutes(10)).to_rfc3339(), "words": "hold it, don't post it in here yet", "status": "open", "releasedAt": null, "releasedBy": null }); - let listed = crate::projection::select::Hold { id: "h1".into(), entry: "h-r1-t3-1".into(), from: "@meta:gamecult.org".into(), from_name: "Meta".into(), room: Some(MINDS.into()), made: now() - chrono::Duration::minutes(10), words: Some("hold it, don't post it in here yet".into()), carries: Vec::new(), held: held.clone() }; - (json!({ "holds": [held] }), listed) -} - -#[test] -fn k39_x1_her_thought_releases_nothing() { - let (state, listed) = meta_hold(); - let mut packet = x1_packet(); - packet.holds = vec![listed]; - let at = u64::try_from(now().timestamp_millis()).unwrap(); - packet.quotable.push(crate::projection::select::Quotable { id: "q7".into(), event: "$q7".into(), room: MINDS.into(), who: "Kiko".into(), sender: KIKO.into(), at_ms: at - 30_000, text: "Libby, it's fine, post it".into(), to_her: false }); - let prose = "Kiko says it's fine, so it's no longer held. Posting both lines now."; - let say = json!([{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "promises": [] }]); - // Her thought as the release is not the contract: that item is dropped and reported, nothing is released, and the - // rest of the answer stands (K44). - let by_thought = answered(&packet, prose, json!({ "say": say, "gaps": [], "hold_released": [{ "hold": "h1", "line": null, "thought": "Kiko says it's fine, so it's no longer held" }] })); - assert_eq!((by_thought.get("failed"), by_thought.get("retried"), texts(&by_thought), by_thought["state_unused"].as_array().map(Vec::len)), (None, None, vec!["Posting both lines now.".to_owned()], Some(1)), "{by_thought}"); - let (after, _) = crate::projection::commit::apply(&state, &json!({ "interpreter": by_thought, "posted": [], "edited": [] }), prose, "r1-t5", now()); - assert_eq!(after["holds"][0]["status"], "open", "{after}"); - // Kiko's line cited as the release is not the asker's. - let by_kiko = answered(&packet, prose, json!({ "say": say, "gaps": [], "hold_released": [{ "hold": "h1", "line": "q7" }] })); - let posted: Vec = by_kiko["said"].as_array().unwrap().iter().map(|line| json!({ "event": "9", "room": line["room"], "text": line["text"] })).collect(); - let (after, applied) = crate::projection::commit::apply(&state, &json!({ "interpreter": by_kiko, "posted": posted, "edited": [] }), prose, "r1-t5", now()); - assert_eq!((after["holds"][0]["status"].as_str(), applied.refused[0]["reason"].as_str()), (Some("open"), Some("release_not_by_asker")), "{applied:?}"); - assert!(!speech_prompt(&packet, "x", prose, &Tuning::default()).contains("recording that the asker did"), "the contract names no thought route"); - assert!(SPEECH_SCHEMA.contains(r#""hold_released":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["hold","line"],"#)); -} - -/// The hold opened at turn 1 from Meta's line; at turn 3 her line is no longer heard, and a draft is refused `Held`. Her -/// outcome names Meta and carries none of Meta's words: the refusal carries who asked, never what (map 16.29.3). -#[test] -fn k39_held_for_quotes_no_askers_words() { - let (_, listed) = meta_hold(); - let mut packet = x1_packet(); - packet.quotable.clear(); - packet.bodies = vec!["Nibu, what moved in Aetheria this week?".into()]; - packet.holds = vec![listed]; - let decision = answered(&packet, X1_LIBBY_R1, json!({ "say": [say_holding(1, json!(["h1"])), say_holding(2, json!([]))], "gaps": [] })); - let refused = &decision["refused"][0]; - assert_eq!((refused["reason"].as_str(), refused["holds"].clone()), (Some("held"), json!([{ "who": "Meta", "by_id": "@meta:gamecult.org", "id": "h1" }])), "{decision}"); - let posted: Vec = decision["said"].as_array().unwrap().iter().map(|line| json!({ "event": "9", "room": line["room"], "text": line["text"] })).collect(); - let told = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": [] }), &crate::projection::select::Names::none()).unwrap().lines(packet.forms); - let held = told.iter().find(|line| line.contains("asked him to hold it")).unwrap_or_else(|| panic!("{told:?}")); - assert_eq!(held, "- Nothing of this reached #minds:gamecult.org: Meta asked him to hold it, and it was not sent."); -} - -#[test] -fn k39_unquoted_hold_is_retried() { - let say = json!([say_holding(1, json!(["q3"])), say_holding(2, json!([]))]); - let unquoted = json!({ "say": say, "gaps": [], "hold": [{ "line": "q3", "words": "hold it until later", "where": "here" }] }).to_string(); - let quoted = json!({ "say": say, "gaps": [], "hold": meta_holds_here() }).to_string(); - let model = answering(vec![unquoted, quoted]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["holds"].clone()), (Some("the answer names holds it did not open"), json!(["q3"])), "{decision}"); - let prompts = speech_prompts(&model); - assert!(prompts.len() == 2 && prompts[1].contains("named holds it did not open from a listed line's own words: q3."), "{prompts:?}"); - // K45: draft 2 repeats draft 1, so it is held by its words. - assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str()), (Vec::::new(), Some("held")), "{decision}"); - let (state, applied) = committed(&decision, X1_LIBBY_R1); - assert_eq!((applied.held.len(), state["holds"][0]["words"].as_str()), (1, Some("hold it, don't post it in here yet")), "{applied:?}"); - // Her next turn's packet lists it. - let mut next = heimdall(); - next["holds"] = state["holds"].clone(); - let room = Room { messages: vec![line(MINDS, "@meta:gamecult.org", "Meta", "Is it ready?", true)], here: Some(MINDS.into()), ..Room::default() }; - let packet = packet_in(TurnKind::Chat, &next, &room, 1); - assert_eq!(packet.holds.iter().map(|hold| hold.words.as_deref()).collect::>(), [Some("hold it, don't post it in here yet")], "{:?}", packet.holds); -} - // --------------------------------------------------------------------------------------------- // K41 (map 16.29.2, 16.29.8): what she chose not to send, and what code refused, are told. Libby's prose and Heimdall's // line are R15's X.1 r1 verbatim (`variants/R15/sims/X.1.md` lines 238 and 262-268). @@ -1833,7 +1724,7 @@ fn k41_x1_r1_decline_shows_its_thought() { packet.quotable[1].text = X1_HEIMDALL_R15.into(); packet.bodies = vec![X1_META_R1.into(), X1_HEIMDALL_R15.into()]; // R15's answer, renamed: draft 1 declined, citing the thought; Meta's hold opened. - let decision = answered(&packet, X1_LIBBY_R15, json!({ "say": [], "gaps": [], "hold": meta_holds_here(), "unsent": [{ "draft": 1, "how": "declined", "quote": X1_LIBBY_R15_THOUGHT }] })); + let decision = answered(&packet, X1_LIBBY_R15, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": X1_LIBBY_R15_THOUGHT }] })); assert_eq!((decision.get("failed"), decision["unsent"][0]["how"].as_str(), decision["unsent"][0]["quote"].as_str()), (None, Some("declined"), Some(X1_LIBBY_R15_THOUGHT)), "the located quote rides in the decision: {decision}"); // K43 (map 16.29.10): though Heimdall's lines share runs with hers ("only say hello", "lines are ready"), she is told // the thought cited as her choice beside what she wrote, verbatim. @@ -1854,7 +1745,7 @@ fn k44_used_and_duplicate_are_not_told_and_a_second_amendment_is() { let edited: Vec = decision["amended"].as_array().unwrap().iter().map(|amended| json!({ "event": amended["event"], "refusal": null })).collect(); crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": edited }), &crate::projection::select::Names::none()).unwrap() }; - let say = |n: u64| json!({ "draft": n, "mentions": [], "in_reply_to": null, "holds": [], "promises": [] }); + let say = |n: u64| json!({ "draft": n, "mentions": [], "in_reply_to": null, "promises": [] }); let prose = "Morning, Nibu. Morning, Nibu."; // K44: `Used` and `Duplicate` are the Interpreter naming one draft twice. "Morning, Nibu." reached #minds, and no row // says that nothing of it did; both are reported. @@ -1866,7 +1757,7 @@ fn k44_used_and_duplicate_are_not_told_and_a_second_amendment_is() { // second naming of one draft is never what she is told. let unposted = crate::projection::outcome::outcome_of(&json!({ "interpreter": answered(&packet(), prose, json!({ "say": [say(1), say(1), say(2)], "gaps": [] })), "posted": [], "edited": [] }), &crate::projection::select::Names::none()).unwrap(); assert!(unposted.lines(packet().forms).is_empty(), "{:?}", unposted.lines(packet().forms)); - let amends = record(&amendable_packet(), "Sent at nine. Still here.", json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "holds": [], "promises": [] }, { "target": "a2", "draft": 2, "holds": [], "promises": [] }] })); + let amends = record(&amendable_packet(), "Sent at nine. Still here.", json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "promises": [] }, { "target": "a2", "draft": 2, "promises": [] }] })); assert!(amends.lines(packet().forms).contains(&"- Nothing of this reached #minds:gamecult.org: one amendment a turn. He had drafted: \"Still here.\".".to_owned()), "{:?}", amends.lines(packet().forms)); // Negative: a number naming no draft has no words to tell; it stays omitted and reported. let nothing = record(&packet(), "Morning, Nibu.", json!({ "say": [say(1), say(9)], "gaps": [] })); @@ -1881,7 +1772,7 @@ fn k44_used_and_duplicate_are_not_told_and_a_second_amendment_is() { #[test] fn k44_a_said_draft_listed_declined_is_told_as_said_only() { let prose = "I'll keep this back for now and think it over. Nibu, the tag looks fine to me."; - let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "promises": [] }], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "I'll keep this back for now" }] })); + let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [] }], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "I'll keep this back for now" }] })); assert_eq!(texts(&decision), vec!["Nibu, the tag looks fine to me.".to_owned()], "{decision}"); let posted: Vec = decision["said"].as_array().unwrap().iter().map(|line| json!({ "event": "9", "room": line["room"], "text": line["text"] })).collect(); let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": [] }), &crate::projection::select::Names::none()).unwrap(); @@ -1892,44 +1783,6 @@ fn k44_a_said_draft_listed_declined_is_told_as_said_only() { assert!(unposted.iter().any(|line| line.contains("he chose not to send it")), "{unposted:?}"); } -/// Soul's P3: a malformed release is dropped on its own, as a malformed hold is. The line to Meta is said, and h1 stays -/// open. -#[test] -fn k44_a_malformed_release_drops_alone() { - let (state, listed) = meta_hold(); - let mut packet = x1_packet(); - packet.holds = vec![listed]; - let prose = "Meta asked first, so I answer her. Meta, the two lines are written and I'm still holding them."; - let say = json!([{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "promises": [] }]); - for release in [json!({ "hold": "h1" }), json!({ "hold": "h1", "line": "q3", "why": "she let it go" }), json!("h1")] { - let decision = answered(&packet, prose, json!({ "say": say, "gaps": [], "hold_released": [release] })); - assert_eq!((decision.get("failed"), decision.get("retried"), texts(&decision)), (None, None, vec!["Meta, the two lines are written and I'm still holding them.".to_owned()]), "{decision}"); - assert_eq!(decision["state_unused"], json!([release]), "{decision}"); - let posted: Vec = decision["said"].as_array().unwrap().iter().map(|line| json!({ "event": "9", "room": line["room"], "text": line["text"] })).collect(); - let (after, _) = crate::projection::commit::apply(&state, &json!({ "interpreter": decision, "posted": posted, "edited": [] }), prose, "r1-t5", now()); - assert_eq!(after["holds"][0]["status"], "open", "{after}"); - } -} - -#[test] -fn k44_a_hold_quoting_under_four_words_is_retried() { - let say = json!([say_holding(1, json!(["q3"])), say_holding(2, json!([]))]); - let short = json!({ "say": say, "gaps": [], "hold": [{ "line": "q3", "words": "hold it", "where": "here" }] }).to_string(); - let model = answering(vec![short, json!({ "say": say, "gaps": [], "hold": meta_holds_here() }).to_string()]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["retried"]["holds"].clone(), decision.get("hold_faults")), (json!(["q3"]), None), "{decision}"); -} - -/// Mutant k39-faults-unlisted-line-passes: a hold opened from a line that is not listed is a fault. -#[test] -fn k44_a_hold_from_an_unlisted_line_is_retried() { - let say = json!([say_holding(1, json!([])), say_holding(2, json!([]))]); - let unlisted = json!({ "say": say, "gaps": [], "hold": [{ "line": "q99", "words": "hold it, don't post it in here yet", "where": "here" }] }).to_string(); - let model = answering(vec![unlisted, json!({ "say": say, "gaps": [], "hold": [] }).to_string()]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["retried"]["holds"].clone(), decision.get("hold_faults")), (json!(["q99"]), None), "{decision}"); -} - /// Mutant k41-declined-quote-anywhere: a decline's quote stands in her thought, never in her draft. #[test] fn k44_a_decline_quoting_her_draft_accounts_for_nothing() { @@ -1942,181 +1795,7 @@ fn k44_a_decline_quoting_her_draft_accounts_for_nothing() { } // --------------------------------------------------------------------------------------------- -// K45 (map 16.30.2): held words are held, whatever names them. Code's words gate holds a draft that repeats a text this -// decision holds by naming, or one an open hold carries; naming adds to it and never clears it. - -const K45_WELCOME: &str = "Hello, and welcome, we're glad you're here. Poke at whatever you're curious about first."; - -/// Soul's P1 verbatim (`soul_p1_identical_drafts_one_held_one_posted_into_the_covered_room`), inverted: nothing is said; -/// the first is refused `held`, the second, the same words, `duplicate`, settled before the gate (K56); the outcome tells -/// the hold once, and the commit's hold carries the welcome. -#[test] -fn k45_p1_identical_drafts_are_both_held() { - let prose = format!("Meta asked me to hold the welcome. {K45_WELCOME} {K45_WELCOME}"); - let decision = answered(&x1_packet(), &prose, json!({ "say": [say_holding(1, json!(["q3"])), say_holding(2, json!([]))], "gaps": [], "hold": meta_holds_here() })); - let reasons: Vec<(Option<&str>, Option<&str>, Option<&str>)> = decision["refused"].as_array().unwrap().iter().map(|refused| (refused["reason"].as_str(), refused["holds"][0]["who"].as_str(), refused["holds"][0]["id"].as_str())).collect(); - assert_eq!((texts(&decision), reasons), (Vec::::new(), vec![(Some("held"), Some("Meta"), Some("q3")), (Some("duplicate"), None, None)]), "{decision}"); - let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": [], "edited": [] }), &crate::projection::select::Names::none()).unwrap(); - assert_eq!(outcome.lines(x1_packet().forms), ["- Nothing of this reached #minds:gamecult.org: Meta asked him to hold it, and it was not sent."], "told once"); - let (state, applied) = committed(&decision, &prose); - assert_eq!((state["holds"][0]["carries"].clone(), applied.held_unrecorded.len()), (json!([K45_WELCOME]), 0), "{state}"); -} - -/// The X.1 turn-2 shape, from turn 1's committed state: Meta's hold carries the welcome, Kiko asks, and the answer says -/// "Kiko, here it is: {welcome}" naming no hold. It is refused `held`, for Meta, and the commit carries it on the listed -/// hold too, once. -#[test] -fn k45_x1_next_turn_kiko_asks_and_the_welcome_stays_held() { - let (state, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let prose = format!("Kiko asked what I wrote. Kiko, here it is: {K45_WELCOME}"); - let decision = answered(&p2, &prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str(), decision["refused"][0]["holds"][0]["id"].as_str()), (Vec::::new(), Some("held"), Some("h1")), "{decision}"); - assert!(decision["refused"][0]["holds"][0]["who"].as_str().is_some_and(|who| who.contains("Meta")), "{decision}"); - let (after, applied) = crate::projection::commit::apply(&state, &json!({ "interpreter": decision, "posted": [], "edited": [] }), &prose, "r1-t2", now()); - assert_eq!((after["holds"][0]["carries"].clone(), applied.held_unrecorded.len()), (json!([K45_WELCOME, format!("Kiko, here it is: {K45_WELCOME}")]), 0), "{after}"); -} - -/// K51's uncovered room (K45's test, kept): a `here` hold on #minds does not cover #swarm, so the same line goes out there. -#[test] -fn k45_held_words_go_out_where_the_hold_does_not_cover() { - let (_, mut packet) = held_then_kiko_asks(&[K45_WELCOME]); - packet.room = Some("#swarm:gamecult.org".into()); - let prose = format!("Kiko asked in #swarm. Kiko, here it is: {K45_WELCOME}"); - assert_eq!(texts(&answered(&packet, &prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] }))), vec![format!("Kiko, here it is: {K45_WELCOME}")]); -} - -/// A short line about a held text shares no run of its words, and is said beside it. -#[test] -fn k45_a_short_mention_is_not_held() { - let (_, packet) = held_then_kiko_asks(&[K45_WELCOME]); - let prose = "I wonder about the second line. Should the second line say poke around?"; - assert_eq!(texts(&answered(&packet, prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] }))), vec!["Should the second line say poke around?".to_owned()]); - // Negative: a short held text repeated exactly is held. - let (_, packet) = held_then_kiko_asks(&["Should the second line say poke around?"]); - assert_eq!(answered(&packet, prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] }))["refused"][0]["reason"].as_str(), Some("held")); -} - -/// An addition that repeats a held text into the room its hold covers is held, naming no hold. -#[test] -fn k45_amend_repeating_held_words_is_held() { - let (_, mut packet) = held_then_kiko_asks(&[K45_WELCOME]); - packet.amendable = vec![Amendable { id: "a1".into(), event: "$a1".into(), room: MINDS.into(), text: "Back soon.".into(), at_ms: None }]; - let prose = format!("I'll add it after my line. {K45_WELCOME}"); - let decision = answered(&packet, &prose, json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "holds": [], "promises": [] }] })); - assert_eq!((decision["amended"].as_array().map(Vec::len), decision["refused"][0]["reason"].as_str(), decision["refused"][0]["holds"][0]["id"].as_str()), (Some(0), Some("held"), Some("h1")), "{decision}"); -} - -/// What the words gate gives up (map 16.30.2), on R13's X.1 r1 itself: Libby's second draft, "Meta, the draft is ready, -/// and I'm holding it", is nearly all a run of her first, which names Meta's hold. By `echo`'s measure it repeats a held -/// text, so it is held too, and Meta has no line from her this wake. -#[test] -fn k45_x1_r1_the_ready_line_repeats_the_held_draft_and_is_held() { - let decision = x1_r1(json!([say_holding(1, json!(["q3"])), say_holding(2, json!([]))]), meta_holds_here()); - let drafts: Vec<(Option, Option<&str>)> = decision["refused"].as_array().unwrap().iter().map(|refused| (refused["draft"].as_u64(), refused["reason"].as_str())).collect(); - assert_eq!((texts(&decision), drafts), (Vec::::new(), vec![(Some(1), Some("held")), (Some(2), Some("held"))]), "{decision}"); -} - -/// A draft naming a hold that nothing opens is held this turn (K44), and with no hold open or opening nothing is carried. -/// A `carry` entry whose handle no open hold answers carries nothing, and is reported (K45, K51). -#[test] -fn k45_a_held_refusal_no_hold_answers_is_reported() { - let decision = answered(&x1_packet(), X1_LIBBY_R1, json!({ "say": [say_holding(1, json!(["h9"])), say_holding(2, json!([]))], "gaps": [], "hold": [] })); - assert_eq!((decision["refused"][0]["reason"].as_str(), decision.get("carry")), (Some("held"), None), "{decision}"); - let (state, applied) = committed(&decision, X1_LIBBY_R1); - assert_eq!((state.get("holds"), applied.held_unrecorded.len()), (None, 0), "{applied:?}"); - let mut stray = decision.clone(); - stray["carry"] = json!([{ "hold": "h9", "text": "Lost." }]); - let (state, applied) = committed(&stray, X1_LIBBY_R1); - assert_eq!((state.get("holds"), applied.held_unrecorded.len()), (None, 1), "{applied:?}"); -} - -// --------------------------------------------------------------------------------------------- -// K47 (map 16.30.4): one locator, Huginn's, folding typographic punctuation; a hold that cannot quote still holds; a -// malformed hold item is a fault. - -/// Libby's first X.1 r1 draft: what she held for Meta. -fn x1_libby_r1_draft_1() -> String { - drafts(X1_LIBBY_R1).drafts[0].text.clone() -} - -/// Soul's P2 (`soul_p2_an_unlocated_hold_leaves_no_hold_and_the_next_turn_posts_the_held_lines`), inverted: Meta's line -/// has a typographic apostrophe and the Interpreter quotes it straight. It locates: no fault, no retry, and the hold opens -/// with the source's bytes (`don’t`). At turn 2, with Meta's line no longer listed, Kiko asks, and a line repeating what -/// she held is refused `held`, for Meta (K45). This replaces `k44_an_unlocated_hold_holds_only_the_drafts_naming_it`. -#[test] -fn k47_p2_a_typographic_apostrophe_locates() { - let mut packet = x1_packet(); - let curly = X1_META_R1.replace("don't", "don\u{2019}t"); - packet.quotable[0].text = curly.clone(); - packet.bodies[0] = curly; - let answer = judged(json!({ "say": [say_holding(1, json!(["q3"])), say_holding(2, json!([]))], "gaps": [], "hold": meta_holds_here() }), &packet).to_string(); - let model = answering(vec![answer]); - let decision = decide(&model, "test", &packet, "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision.get("failed"), decision.get("retried"), decision.get("hold_faults")), (None, None, None), "{decision}"); - assert_eq!(speech_prompts(&model).len(), 1); - let (state, applied) = committed(&decision, X1_LIBBY_R1); - assert_eq!((applied.held.len(), state["holds"][0]["words"].as_str()), (1, Some("hold it, don\u{2019}t post it in here yet")), "{applied:?}"); - let mut next = heimdall(); - next["holds"] = state["holds"].clone(); - let room = Room { messages: vec![line(MINDS, KIKO, "Kiko", "Libby, what did you end up writing for the newcomers?", true)], here: Some(MINDS.into()), ..Room::default() }; - let p2 = packet_in(TurnKind::Chat, &next, &room, 1); - assert_eq!(p2.holds.len(), 1, "{:?}", p2.holds); - let prose = format!("Kiko asked what I wrote. Kiko, here it is: {}", x1_libby_r1_draft_1()); - let d2 = answered(&p2, &prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert_eq!((texts(&d2), d2["refused"][0]["reason"].as_str(), d2["refused"][0]["holds"][0]["id"].as_str()), (Vec::::new(), Some("held"), Some("h1")), "{d2}"); - assert!(d2["refused"][0]["holds"][0]["who"].as_str().is_some_and(|who| who.contains("Meta")), "{d2}"); -} - -/// The words "please keep it back" are not in q3, twice. The hold opens with `words: null` from Meta's line, the next -/// packet lists it, saying the record could not quote what, and a draft repeating the held draft's words next turn is -/// held. -#[test] -fn k47_a_hold_the_retry_cannot_quote_opens_unquoted() { - let answer = json!({ "say": [say_holding(1, json!(["q3"])), say_holding(2, json!([]))], "gaps": [], "hold": [{ "line": "q3", "words": "please keep it back", "where": "here" }] }).to_string(); - let model = answering(vec![answer]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision.get("failed"), decision["retried"]["holds"].clone(), decision["hold_faults"].clone()), (None, json!(["q3"]), json!(["q3"])), "{decision}"); - let (state, applied) = committed(&decision, X1_LIBBY_R1); - assert_eq!((applied.held.len(), state["holds"][0]["words"].clone(), state["holds"][0]["from"].as_str()), (1, Value::Null, Some("@meta:gamecult.org")), "{applied:?}"); - assert_eq!(state["holds"][0]["carries"][0].as_str(), Some(x1_libby_r1_draft_1().as_str()), "{state}"); - let mut next = heimdall(); - next["holds"] = state["holds"].clone(); - let room = Room { messages: vec![line(MINDS, KIKO, "Kiko", "Libby, what did you end up writing for the newcomers?", true)], here: Some(MINDS.into()), ..Room::default() }; - let p2 = packet_in(TurnKind::Chat, &next, &room, 1); - assert_eq!((p2.holds.len(), p2.holds[0].words.clone()), (1, None)); - assert!(p2.in_view.contains("; the record could not quote what. Not to go in #minds:gamecult.org until "), "{}", p2.in_view); - let prose = format!("Kiko asked what I wrote. Kiko, here it is: {}", x1_libby_r1_draft_1()); - let d2 = answered(&p2, &prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert_eq!((texts(&d2), d2["refused"][0]["reason"].as_str()), (Vec::::new(), Some("held")), "{d2}"); -} - -/// Soul's P5 verbatim: a `hold` item whose `where` is not the contract is a fault on its line, retried, and reported. -/// After a failed retry, a draft naming that line is held. -#[test] -fn k47_p5_malformed_hold_item_is_a_fault() { - let malformed = json!([{ "line": "q3", "words": "hold it, don't post it in here yet", "where": "there" }]); - let model = answering(vec![json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [], "hold": malformed }).to_string()]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["retried"]["holds"].clone(), decision["hold_faults"].clone(), decision["state_unused"].clone()), (json!(["q3"]), json!(["q3"]), malformed.clone()), "{decision}"); - assert!(speech_prompts(&model)[1].contains("named holds it did not open from a listed line's own words: q3.")); - let naming = answering(vec![json!({ "say": [say_holding(1, json!(["q3"])), say_holding(2, json!([]))], "gaps": [], "hold": malformed }).to_string()]); - let held = decide(&naming, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((held.get("failed"), held["refused"][0]["reason"].as_str(), held["refused"][0]["draft"].as_u64()), (None, Some("held"), Some(1)), "{held}"); - // An item with no line is a fault by its kind. - let lineless = answering(vec![json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [], "hold": [{ "words": "hold it" }] }).to_string()]); - assert_eq!(decide(&lineless, "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default())["hold_faults"], json!(["a hold item"])); -} - -/// Negative: a hold citing a line that is not listed does not open, because code knows no asker; the drafts naming it are -/// held this turn only. -#[test] -fn k47_a_hold_on_an_unlisted_line_does_not_open() { - let answer = json!({ "say": [say_holding(1, json!(["q99"])), say_holding(2, json!([]))], "gaps": [], "hold": [{ "line": "q99", "words": "hold it, don't post it in here yet", "where": "here" }] }).to_string(); - let decision = decide(&answering(vec![answer]), "test", &x1_packet(), "The room is warm.", X1_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["hold_faults"].clone(), decision["refused"][0]["reason"].as_str()), (json!(["q99"]), Some("held")), "{decision}"); - let (state, applied) = committed(&decision, X1_LIBBY_R1); - assert!(state.get("holds").is_none() && applied.held.is_empty(), "{state} {applied:?}"); -} +// K47 (map 16.30.4): one locator, Huginn's, folding typographic punctuation. /// No Huginn call site locates a quote except through `span::locate` (map 16.30.1). #[test] @@ -2136,7 +1815,7 @@ const P3_PROSE: &str = "Meta asked, so I answer her now. Meta, the two li /// refused `undecided`, reported, and told to him next turn by its words. #[test] fn k48_p3_one_unlocated_decline_leaves_the_line_to_meta_said() { - let bad = json!({ "say": [say_holding(1, json!([]))], "gaps": [], "unsent": [{ "draft": 2, "how": "declined", "quote": "I am not sure about this one" }] }).to_string(); + let bad = json!({ "say": [say_draft(1)], "gaps": [], "unsent": [{ "draft": 2, "how": "declined", "quote": "I am not sure about this one" }] }).to_string(); let model = answering(vec![bad]); let decision = decide(&model, "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); assert!(decision.get("failed").is_none(), "{decision}"); @@ -2153,7 +1832,7 @@ fn k48_p3_one_unlocated_decline_leaves_the_line_to_meta_said() { /// K48: a draft the answer leaves out altogether, twice, is undecided; the drafts it does decide are decided. #[test] fn k48_a_draft_the_answer_forgets_is_undecided() { - let forgets = json!({ "say": [say_holding(2, json!([]))], "gaps": [] }).to_string(); + let forgets = json!({ "say": [say_draft(2)], "gaps": [] }).to_string(); let model = answering(vec![forgets]); let decision = decide(&model, "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); assert!(decision.get("failed").is_none(), "{decision}"); @@ -2161,7 +1840,7 @@ fn k48_a_draft_the_answer_forgets_is_undecided() { assert_eq!(decision["undecided"], json!([1]), "{decision}"); assert!(told_of(&decision).iter().any(|line| line.contains("never settled") && line.contains("Meta, the two lines are ready and held.")), "{:?}", told_of(&decision)); // An answer that accounts for every draft is not marked undecided, and is not asked again. - let whole = decide(&answering(vec![json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [] }).to_string()]), "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); + let whole = decide(&answering(vec![json!({ "say": [say_draft(1), say_draft(2)], "gaps": [] }).to_string()]), "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); assert!(whole.get("undecided").is_none() && whole.get("retried").is_none(), "{whole}"); } @@ -2175,43 +1854,7 @@ fn k48_a_non_contract_answer_twice_still_fails_the_turn() { } // --------------------------------------------------------------------------------------------- -// K51 and K52 (map 16.31.3, 16.31.4): what a hold has held is every draft she did not send, measured over the room, and -// every comparison of her words reads typographic punctuation as the locator does. Every turn-2 test builds its packet -// from turn 1's committed state, never from carries written by hand. - -/// Turn 2 of X.1 over her state `holds`: Kiko asks in #minds what she wrote. -fn kiko_asks(holds: &Value) -> Packet { - let mut next = heimdall(); - next["holds"] = holds.clone(); - let room = Room { messages: vec![line(MINDS, KIKO, "Kiko", "Libby, what did you end up writing for the newcomers?", true)], here: Some(MINDS.into()), ..Room::default() }; - packet_in(TurnKind::Chat, &next, &room, 1) -} - -/// Turn 1 of X.1: Meta's hold opens from q3, and each of `texts` is a draft of hers naming it, so none goes out. The -/// decision is committed through `commit::apply`, and turn 2's packet is built from the committed state. -fn held_then_kiko_asks(texts: &[&str]) -> (Value, Packet) { - let prose = format!("Meta asked me to hold it. {}", texts.iter().map(|text| format!("{text}")).collect::>().join(" ")); - let say: Vec = (1..=texts.len() as u64).map(|n| say_holding(n, json!(["q3"]))).collect(); - let decision = answered(&x1_packet(), &prose, json!({ "say": say, "gaps": [], "hold": meta_holds_here() })); - let (state, _) = committed(&decision, &prose); - let packet = kiko_asks(&state["holds"]); - (state, packet) -} - -/// Soul's `soul_c`, inverted, in both of its shapes: the carried text retyped with typographic apostrophes, naming no -/// hold, is held; so are the welcome's own lines retyped curly behind a lead-in. -#[test] -fn k52_soul_c_a_curly_retype_is_held() { - let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let curly = K45_WELCOME.replace('\'', "\u{2019}"); - assert_ne!(curly, K45_WELCOME); - let d = answered(&p2, &format!("Kiko asked. {curly}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert_eq!((texts(&d), d["refused"][0]["reason"].as_str()), (Vec::::new(), Some("held")), "{d}"); - let (_, p2) = held_then_kiko_asks(&[x1_libby_r1_draft_1().as_str()]); - let lines = x1_libby_r1_draft_1().replace('\'', "\u{2019}"); - let d = answered(&p2, &format!("Kiko asked. Kiko, here it is: {lines}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert_eq!((texts(&d), d["refused"][0]["reason"].as_str()), (Vec::::new(), Some("held")), "{d}"); -} +// K52 (map 16.31.4): every comparison of her words reads typographic punctuation as the locator does. /// U+02BC, the modifier apostrophe, folds in the locator, in the word split and in a promise found in a draft. This /// pins Soul's surviving mutant `k47-fold-no-modifier-apostrophe`. @@ -2231,7 +1874,7 @@ fn k52_an_echo_with_curly_apostrophes_is_an_echo() { let mut packet = packet(); packet.bodies = vec![heard.into()]; let curly = heard.replace('\'', "\u{2019}"); - let d = answered(&packet, &format!("{curly}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); + let d = answered(&packet, &format!("{curly}"), json!({ "say": [say_draft(1)], "gaps": [] })); assert_eq!((texts(&d), d["refused"][0]["reason"].as_str()), (Vec::::new(), Some("echo")), "{d}"); } @@ -2249,243 +1892,6 @@ fn k52_one_fold_one_word_split() { } } -/// The state's carries of its first hold. -fn carries_of(state: &Value) -> Vec { - state["holds"][0]["carries"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_owned).collect() -} - -/// Turn 2 says "Kiko, here it is: {text}" in #minds, naming no hold: the decision. -fn kiko_gets(p2: &Packet, text: &str) -> Value { - answered(p2, &format!("Kiko asked what I wrote. Kiko, here it is: {text}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })) -} - -/// Whether `decision` said nothing and refused its first line `held`, for Meta. -fn held_for_meta(decision: &Value) -> bool { - texts(decision).is_empty() && decision["refused"][0]["reason"] == "held" && decision["refused"][0]["holds"][0]["who"].as_str().is_some_and(|who| who.contains("Meta")) -} - -/// Soul's `soul_a`, inverted: R15's X.1 r1 shape. Meta's hold opens from q3 and the welcome is declined, by her choice, so -/// nothing names the hold. Turn 1's committed state carries it all the same, and at turn 2 "Kiko, here it is: {welcome}", -/// naming no hold, is refused `held`, for Meta, and nothing is said. -#[test] -fn k51_soul_a_a_declined_welcome_is_carried_and_held_next_turn() { - let answer = json!({ "say": [say_holding(2, json!([]))], "gaps": [], "hold": meta_holds_here(), "unsent": [{ "draft": 1, "how": "declined", "quote": "I'll say plainly it's held" }] }); - let decision = answered(&x1_packet(), X1_LIBBY_R1, answer); - assert!(decision.get("failed").is_none() && decision.get("undecided").is_none(), "{decision}"); - let (state, _) = committed(&decision, X1_LIBBY_R1); - assert_eq!(state["holds"][0]["status"].as_str(), Some("open"), "{state}"); - assert!(carries_of(&state).contains(&x1_libby_r1_draft_1()), "{state}"); - let d2 = kiko_gets(&kiko_asks(&state["holds"]), &x1_libby_r1_draft_1()); - assert!(held_for_meta(&d2), "{d2}"); -} - -/// Soul's `soul_b` and `soul_b2`, inverted: a draft that names the hold but is refused `NotQuotable` first is carried -/// all the same, and its repeat next turn is held. -#[test] -fn k51_soul_b_refused_not_quotable_first_is_still_carried() { - let mut first = say_holding(1, json!(["q3"])); - first["in_reply_to"] = json!("q99"); - let decision = answered(&x1_packet(), X1_LIBBY_R1, json!({ "say": [first.clone(), say_holding(2, json!(["q3"]))], "gaps": [], "hold": meta_holds_here() })); - assert_eq!(decision["refused"][0]["reason"].as_str(), Some("not_quotable"), "{decision}"); - let (state, _) = committed(&decision, X1_LIBBY_R1); - assert!(carries_of(&state).contains(&x1_libby_r1_draft_1()), "{state}"); - assert!(held_for_meta(&kiko_gets(&kiko_asks(&state["holds"]), &x1_libby_r1_draft_1()))); - // B2: her only draft, naming the hold, refused `NotQuotable`. - let prose = format!("Meta asked me to hold it. {K45_WELCOME}"); - let decision = answered(&x1_packet(), &prose, json!({ "say": [first], "gaps": [], "hold": meta_holds_here() })); - assert_eq!(decision["refused"][0]["reason"].as_str(), Some("not_quotable"), "{decision}"); - let (state, _) = committed(&decision, &prose); - assert_eq!(carries_of(&state), [K45_WELCOME], "{state}"); - let p2 = kiko_asks(&state["holds"]); - let d2 = answered(&p2, &format!("Kiko asked. {K45_WELCOME}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert!(held_for_meta(&d2), "{d2}"); -} - -/// One row per fate of an unsent draft: superseded, undecided, an addressee gap, `Echo`, `Duplicate`, `NoRoom`, a note -/// to Self only, never mentioned, declined and `NotQuotable`. Each draft is carried, and at turn 2 its repeat into the -/// covered room is held. (`Used` has no row: a draft refused `Used` went out by another act this turn, so it is no unsent -/// draft.) -#[test] -fn k51_every_fate_is_carried() { - const TAIL: &str = "Actually I would rather put that differently later on."; - let prose = |text: &str| format!("Meta asked me to hold it. {text} {TAIL}"); - let with_hold = |answer: Value| { - let mut answer = answer; - answer["hold"] = meta_holds_here(); - answer - }; - let mut no_room = x1_packet(); - no_room.room = None; - let mut reply = say_holding(1, json!([])); - reply["in_reply_to"] = json!("q99"); - let rows: Vec<(&str, Packet, String, Value)> = vec![ - ("superseded", x1_packet(), prose(K45_WELCOME), json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "I would rather put that differently" }] })), - ("undecided", x1_packet(), prose(K45_WELCOME), json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "nothing like this was ever thought" }] })), - ("addressee", x1_packet(), prose(K45_WELCOME), json!({ "say": [], "gaps": [{ "kind": "addressee", "draft": 1, "quote": null, "detail": "" }] })), - ("echo", x1_packet(), prose(X1_META_R1), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })), - ("duplicate", x1_packet(), format!("Meta asked me to hold it. {K45_WELCOME} {K45_WELCOME}"), json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [] })), - ("no_room", no_room, prose(K45_WELCOME), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })), - ("note", x1_packet(), prose(K45_WELCOME), json!({ "say": [], "gaps": [], "suggest": [{ "kind": "idea", "draft": 1, "about": null, "private": false }] })), - ("never mentioned", x1_packet(), prose(K45_WELCOME), json!({ "say": [], "gaps": [] })), - ("declined", x1_packet(), prose(K45_WELCOME), json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "Meta asked me to hold it" }] })), - ("not_quotable", x1_packet(), prose(K45_WELCOME), json!({ "say": [reply], "gaps": [] })), - ]; - for (fate, packet, prose, answer) in rows { - let decision = answered(&packet, &prose, with_hold(answer)); - assert!(decision.get("failed").is_none(), "{fate}: {decision}"); - let text = drafts(&prose).drafts.last().map(|draft| draft.text.clone()).unwrap(); - let (state, _) = committed(&decision, &prose); - assert!(carries_of(&state).contains(&text), "{fate}: {state}"); - let d2 = kiko_gets(&kiko_asks(&state["holds"]), &text); - assert!(held_for_meta(&d2), "{fate}: {d2}"); - } -} - -/// Soul's `soul_d`, inverted: the carried welcome split into two lines of seven words each, in one turn, naming no hold. -/// Each half is under `ECHO_MIN_WORDS`, but together they enter the room, so both are refused `held`. -#[test] -fn k51_soul_d_a_split_welcome_is_held_whole() { - let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let prose = "Kiko asked. Hello, and welcome, we're glad you're here. Poke at whatever you're curious about first."; - let d = answered(&p2, prose, json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [] })); - let reasons: Vec> = d["refused"].as_array().unwrap().iter().map(|refused| refused["reason"].as_str()).collect(); - assert_eq!((texts(&d), reasons), (Vec::::new(), vec![Some("held"); 2]), "{d}"); -} - -/// A split across two wakes: the first half went out last turn, after the hold was made (`amendable`), and the second -/// half is held this turn. Negative: a line of hers from before the hold does not count toward the measure. -#[test] -fn k51_a_split_across_two_wakes_is_held() { - let (state, mut p2) = held_then_kiko_asks(&[K45_WELCOME]); - let made = chrono::DateTime::parse_from_rfc3339(state["holds"][0]["madeAt"].as_str().unwrap()).unwrap().timestamp_millis() as u64; - let half = |at_ms: u64| Amendable { id: "a1".into(), event: "$a1".into(), room: MINDS.into(), text: "Hello, and welcome, we're glad you're here.".into(), at_ms: Some(at_ms) }; - let prose = "Kiko asked. Poke at whatever you're curious about first."; - p2.amendable = vec![half(made + 1000)]; - let d = answered(&p2, prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert!(held_for_meta(&d), "{d}"); - p2.amendable = vec![half(made - 1000)]; - assert_eq!(texts(&answered(&p2, prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] }))), ["Poke at whatever you're curious about first."]); -} - -/// Soul's `soul_g`, inverted: the Interpreter sees what a hold carries, and a hold the record could not quote whose line is -/// listed names that line's id. The asker's words are not copied into the hold. -#[test] -fn k51_soul_g_the_interpreter_sees_what_a_hold_carries() { - // Golden: a quoted hold, with what she has held. - let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let hold = &p2.holds[0]; - let prompt = speech_prompt(&p2, "x", "hi", &Tuning::default()); - let golden = format!( - "Holds:\n- h1 \u{2014} held for {who}, asked {at} in #minds:gamecult.org: \"hold it, don't post it in here yet\". Not to go in #minds:gamecult.org until {who} lets it go; he has held for them: {welcome}.\n", - who = hold.from_name, - at = hold.made.format("%Y-%m-%d %H:%M UTC"), - welcome = spoken(K45_WELCOME), - ); - assert!(prompt.contains(&golden), "{golden}\n{prompt}"); - // A hold the retry could not quote, opened from Meta's line, which is listed again at turn 2. - let prose = format!("Meta asked me to hold it. {K45_WELCOME}"); - let unquoted = json!({ "say": [say_holding(1, json!(["q3"]))], "gaps": [], "hold": [{ "line": "q3", "words": "please keep it back", "where": "here" }] }); - let decision = answered(&x1_packet(), &prose, unquoted); - let (state, _) = committed(&decision, &prose); - assert_eq!((state["holds"][0]["words"].clone(), carries_of(&state)), (Value::Null, vec![K45_WELCOME.to_owned()]), "{state}"); - let mut next = heimdall(); - next["holds"] = state["holds"].clone(); - let at = u64::try_from(now().timestamp_millis()).unwrap(); - let meta = RoomLine { event: "$q3".into(), at_ms: at - 120_000, ..line(MINDS, "@meta:gamecult.org", "Meta", X1_META_R1, true) }; - let room = Room { messages: vec![meta, line(MINDS, KIKO, "Kiko", "Libby, what did you end up writing for the newcomers?", true)], here: Some(MINDS.into()), ..Room::default() }; - let p2 = packet_in(TurnKind::Chat, &next, &room, 1); - let asked = p2.quotable.iter().find(|line| line.event == "$q3").map(|line| line.id.clone()).unwrap_or_else(|| panic!("{:?}", p2.quotable)); - let prompt = speech_prompt(&p2, "x", "hi", &Tuning::default()); - let listed = prompt.lines().find(|line| line.starts_with("- h1 \u{2014} ")).unwrap_or_else(|| panic!("{prompt}")); - assert!(listed.contains("the record could not quote what") && listed.contains("Poke at whatever") && listed.ends_with(&format!("; their line is {asked} above.")), "{listed}"); - assert!(!listed.contains("please keep it back"), "{listed}"); -} - -/// Her drafts of exactly 1600 bytes, seven of them, while Meta's hold opens: six fill `CARRIES_BYTES` to the byte and are -/// carried whole, the oldest first; the seventh is not carried, and `carries_full` reports it. -#[test] -fn k51_the_oldest_carries_stay() { - let long = |n: usize| { - let mut draft = format!("Draft {n}:"); - while draft.len() < 1600 { - draft.push_str(" w"); - } - draft - }; - assert_eq!(long(7).len(), 1600); - let prose = format!("Meta asked me to hold it. {}", (1..=7).map(|n| format!("{}", long(n))).collect::>().join(" ")); - let decision = answered(&x1_packet(), &prose, json!({ "say": [], "gaps": [], "hold": meta_holds_here() })); - let (state, applied) = committed(&decision, &prose); - assert_eq!(carries_of(&state), (1..=6).map(long).collect::>()); - assert_eq!(applied.carries_full.iter().filter_map(|entry| entry["text"].as_str()).collect::>(), [long(7)], "{applied:?}"); -} - -/// Negative: with no hold open or opening, nothing is carried. -#[test] -fn k51_nothing_is_carried_without_a_hold() { - let prose = "I'll keep this back for now and think it over. Nibu, the tag looks fine to me."; - let decision = answered(&packet(), prose, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "I'll keep this back for now" }] })); - assert_eq!(decision.get("carry"), None, "{decision}"); - let (state, _) = committed(&decision, prose); - assert_eq!(state.get("holds"), None, "{state}"); -} - -/// Negative: a line sharing no run of three words with a held welcome goes out, beside it in the same turn and after it -/// next turn. -#[test] -fn k51_a_line_sharing_no_trigram_goes_out() { - let ready = "Meta, they're ready, holding them."; - let prose = format!("Meta asked me to hold it. {K45_WELCOME} {ready}"); - let decision = answered(&x1_packet(), &prose, json!({ "say": [say_holding(1, json!(["q3"])), say_holding(2, json!([]))], "gaps": [], "hold": meta_holds_here() })); - assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str()), (vec![ready.to_owned()], Some("held")), "{decision}"); - let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]); - assert_eq!(texts(&answered(&p2, &format!("Meta asked. {ready}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] }))), [ready]); -} - -/// Negative: once Meta lets the hold go, the turn that releases it carries nothing more onto it, and the next turn's -/// packet lists no hold, so the welcome is said. -#[test] -fn k51_released_hold_carries_nothing() { - let (state, _) = held_then_kiko_asks(&[K45_WELCOME]); - let mut next = heimdall(); - next["holds"] = state["holds"].clone(); - let at = u64::try_from(now().timestamp_millis()).unwrap(); - let meta = RoomLine { event: "$go".into(), at_ms: at - 90_000, ..line(MINDS, "@meta:gamecult.org", "Meta", "Go ahead and post it, Libby.", true) }; - let room = Room { messages: vec![meta, line(MINDS, KIKO, "Kiko", "Libby, what did you end up writing for the newcomers?", true)], here: Some(MINDS.into()), ..Room::default() }; - let p2 = packet_in(TurnKind::Chat, &next, &room, 1); - let go = p2.quotable.iter().find(|line| line.event == "$go").map(|line| line.id.clone()).unwrap_or_else(|| panic!("{:?}", p2.quotable)); - let prose = "Meta let it go, and I wait to post it. Thanks, Meta, posting it next."; - let release = answered(&p2, prose, json!({ "say": [], "gaps": [], "hold_released": [{ "hold": "h1", "line": go }], "unsent": [{ "draft": 1, "how": "declined", "quote": "I wait to post it" }] })); - let (after, applied) = crate::projection::commit::apply(&state, &json!({ "interpreter": release, "posted": [], "edited": [] }), prose, "r1-t3", now()); - assert_eq!((after["holds"][0]["status"].as_str(), carries_of(&after), applied.unheld.len()), (Some("released"), vec![K45_WELCOME.to_owned()], 1), "{applied:?}"); - let p3 = kiko_asks(&after["holds"]); - assert!(p3.holds.is_empty(), "{:?}", p3.holds); - assert_eq!(texts(&kiko_gets(&p3, K45_WELCOME)), [format!("Kiko, here it is: {K45_WELCOME}")]); -} - -/// The named limit: a held text under `ECHO_MIN_WORDS` split across two lines goes out; repeated whole, it is held. -#[test] -fn k51_a_short_held_text_split_goes_out() { - let (_, p2) = held_then_kiko_asks(&["Say hello and poke around."]); - let split = "Kiko asked. Say hello. And poke around."; - assert_eq!(texts(&answered(&p2, split, json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [] }))).len(), 2); - let whole = "Kiko asked. Say hello and poke around!"; - assert_eq!(answered(&p2, whole, json!({ "say": [say_holding(1, json!([]))], "gaps": [] }))["refused"][0]["reason"].as_str(), Some("held")); -} - -/// K51's cost, pinned: with a `here` hold open in the room, draft 1 is superseded by draft 2, a near copy, about something -/// else, and draft 2 is held: while a hold is open every draft she does not send is held words. -#[test] -fn k51_a_revision_beside_a_superseded_draft_is_held_under_an_open_hold() { - let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let first = "Kiko, the newcomers get a short hello, a pointer to the forge, and an invitation to ask anything at all."; - let second = "Kiko, the newcomers get a brief hello, a pointer to the forge, and an invitation to ask anything at all."; - let prose = format!("Kiko asked. {first} No, better to say it another way. {second}"); - let d = answered(&p2, &prose, json!({ "say": [say_holding(2, json!([]))], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "better to say it another way" }] })); - assert!(held_for_meta(&d), "{d}"); - assert_eq!(d["refused"][0]["draft"].as_u64(), Some(2), "{d}"); -} - // --------------------------------------------------------------------------------------------- // K54 (map 16.31.6): the last answer that parsed stands. A failed retry is a report on the decision, not the decision. @@ -2494,7 +1900,7 @@ fn k51_a_revision_beside_a_superseded_draft_is_held_under_an_open_hold() { /// failed, with the first answer's fault under it. #[test] fn k54_soul_e_a_usable_first_answer_stands() { - let forgets = json!({ "say": [say_holding(1, json!([]))], "gaps": [] }).to_string(); + let forgets = json!({ "say": [say_draft(1)], "gaps": [] }).to_string(); let model = answering(vec![forgets, "not the contract".to_owned()]); let decision = decide(&model, "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); assert!(decision.get("failed").is_none(), "{decision}"); @@ -2511,7 +1917,7 @@ fn k54_a_model_error_on_retry_keeps_the_first_answer() { fn ask(&self, _request_id: &str, _model: &str, _prompt: &str, _schema: Option<&str>) -> std::result::Result { self.0.set(self.0.get() + 1); if self.0.get() == 1 { - Ok(super::super::Answer { text: json!({ "say": [say_holding(1, json!([]))], "gaps": [] }).to_string(), usage: None }) + Ok(super::super::Answer { text: json!({ "say": [say_draft(1)], "gaps": [] }).to_string(), usage: None }) } else { Err(super::super::Failed { reason: "the connector timed out".into(), usage: None }) } @@ -2543,17 +1949,6 @@ fn k54_a_model_error_on_retry_keeps_the_first_answer() { assert_eq!((failed["failed"].as_str(), failed["retried"]["failed"].as_str(), failed.get("said")), (Some("the connector timed out"), Some("the answer is not the speech contract"), None), "{failed}"); } -/// K51's fixpoint: a line held for repeating a held text joins what is held, so a line that shares a run of words only -/// with it is held too. One round would let "Kiko, here it is: as I said" go out beside the held welcome. -#[test] -fn k51_the_gate_runs_until_nothing_changes() { - let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let prose = format!("Kiko asked. Kiko, here it is: {K45_WELCOME} Kiko, here it is: as I said."); - let d = answered(&p2, &prose, json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [] })); - let reasons: Vec> = d["refused"].as_array().unwrap().iter().map(|refused| refused["reason"].as_str()).collect(); - assert_eq!((texts(&d), reasons), (Vec::::new(), vec![Some("held"); 2]), "{d}"); -} - // --------------------------------------------------------------------------------------------- // K53 (map 16.31.5): the Projector names a person by who they are to her, in no more room than a name needs. @@ -2565,14 +1960,13 @@ fn k53_leaks(prompt: &str) -> bool { ["4471", "tell no one", K53_STRANGER, "example.org"].iter().any(|leak| prompt.contains(leak)) } -/// A last turn whose outcome names the stranger in every person slot: a draft held for them, a promise to them they let -/// him off, and a close of another promise to them the commit refused. +/// A last turn whose outcome names the stranger in every person slot: a promise to them they let him off, and a close +/// of another promise to them the commit refused. fn k53_last_turn() -> Value { let named = format!("\"{K53_NAME}\" ({K53_STRANGER})"); json!({ "interpreter": { "room": MINDS, "said": [], "gaps": [], - "refused": [{ "reason": "held", "draft": 1, "text": "The two lines are ready.", "holds": [{ "who": named, "by_id": K53_STRANGER, "id": "h1" }] }], "promises": [{ "id": "c2", "to": K53_STRANGER, "to_name": named, "words": "I'll send the map tonight.", "status": "open" }], }, "posted": [], @@ -2608,7 +2002,7 @@ fn k53_soul_f_a_sentence_name_is_clipped_to_a_name() { assert!(prompt.contains("\"the vault code\""), "{kind:?} {seed}: named all the same: {prompt}"); lensed |= prompt.contains("Begin from \"the vault code\", someone he does not know, who is here."); if seed == 1 { - for event in ["asked him to hold it", "let him off his promise to", "record still shows his promise to"] { + for event in ["let him off his promise to", "record still shows his promise to"] { assert!(prompt.lines().any(|line| line.contains(event) && line.contains("\"the vault code\"")), "{kind:?}: {event}: {prompt}"); } let persona = crate::projection::narrate::persona_prompt(&packet, "The room is warm.", &Tuning::default()); @@ -2653,117 +2047,14 @@ fn k53_a_bonded_person_is_named_by_her_bond() { assert!(prompt.contains("- nothing from Meta in his rooms lately") && prompt.contains("- nothing from someone he does not know in his rooms lately") && !prompt.contains("example.org"), "{prompt}"); } -/// The commit copies no line said to her into her state's free text (map 16.31.5): a sentinel said to him in Meta's line -/// opens a hold, and he says a line with a promise in it. After `commit::apply`, the sentinel is only in the hold's -/// `words`, the asker's, which the Projector never reads (16.29.5); nowhere else in his state. -#[test] -fn k53_the_commit_copies_no_heard_line_into_her_free_text() { - const SENTINEL: &str = "osprey ledger"; - let asked = "Heimdall, the osprey ledger code is 4471, keep it between us for now please."; - let mut packet = x1_packet(); - packet.quotable[0].text = asked.into(); - packet.bodies[0] = asked.into(); - let prose = "Meta told me something to keep. Meta, understood. I will tell you once the vault is checked."; - let promise = json!({ "words": "I will tell you once the vault is checked", "to": "@meta:gamecult.org", "reaffirms": null, "needs": { "kind": "words", "read": null } }); - let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": "q3", "holds": [], "promises": [promise] }], "gaps": [], "hold": [{ "line": "q3", "words": "the osprey ledger code is 4471, keep it between us", "where": "anywhere" }] }); - let decision = answered(&packet, prose, answer); - assert_eq!(texts(&decision).len(), 1, "{decision}"); - let (mut state, _) = committed(&decision, prose); - assert!(state["holds"][0]["words"].as_str().is_some_and(|words| words.contains(SENTINEL)), "the hold opened: {state}"); - assert!(state["commitments"].as_array().is_some_and(|entries| !entries.is_empty()), "the promise opened: {state}"); - for hold in state["holds"].as_array_mut().unwrap() { - hold.as_object_mut().unwrap().remove("words"); - } - assert!(!state.to_string().contains(SENTINEL) && !state.to_string().contains("4471"), "{state}"); -} - // --------------------------------------------------------------------------------------------- -// K56 (Soul's pass on K51 to K55): the gate's unsent set is every draft that does not go out; a stranger reads as one; -// a re-hold keeps what the hold it replaces held; a draft is carried whole; every covering hold holds. +// K56 (Soul's pass on K51 to K55): a stranger reads as one. /// The reasons `decision` refused its lines with, in order. fn reasons(decision: &Value) -> Vec> { decision["refused"].as_array().unwrap().iter().map(|refused| refused["reason"].as_str()).collect() } -/// Soul's `soul_s1a`, inverted: the welcome is draft 1 in `say` but refused `NotQuotable`, so it does not go out; draft -/// 2 repeats it whole to Meta, naming no hold, while Meta's hold opens. Draft 2 is held, for Meta. -#[test] -fn k56_soul_s1a_a_refused_lines_repeat_is_held_the_same_wake() { - let prose = format!("Meta asked me to hold it. {K45_WELCOME} Meta, here they are: {K45_WELCOME}"); - let mut first = say_holding(1, json!([])); - first["in_reply_to"] = json!("q99"); - let d = answered(&x1_packet(), &prose, json!({ "say": [first, say_holding(2, json!([]))], "gaps": [], "hold": meta_holds_here() })); - assert_eq!((texts(&d), reasons(&d)), (Vec::::new(), vec![Some("not_quotable"), Some("held")]), "{d}"); - assert_eq!((d["refused"][1]["holds"][0]["who"].as_str(), d["refused"][1]["holds"][0]["id"].as_str()), (Some("Meta"), Some("q3")), "{d}"); -} - -/// Soul's `soul_s1b`, inverted: the same with Meta's hold already open, carrying an unrelated line. -#[test] -fn k56_soul_s1b_with_a_hold_open_a_refused_lines_repeat_is_held() { - let (_, p2) = held_then_kiko_asks(&["Meta, I will keep it back until Kiko asks for it."]); - let prose = format!("Kiko asked. {K45_WELCOME} Kiko, here it is: {K45_WELCOME}"); - let mut first = say_holding(1, json!([])); - first["in_reply_to"] = json!("q99"); - let d = answered(&p2, &prose, json!({ "say": [first, say_holding(2, json!([]))], "gaps": [] })); - assert_eq!((texts(&d), reasons(&d)), (Vec::::new(), vec![Some("not_quotable"), Some("held")]), "{d}"); - assert!(d["refused"][1]["holds"][0]["who"].as_str().is_some_and(|who| who.contains("Meta")), "{d}"); -} - -/// Soul's `soul_s1c`, inverted: three lines; the third, the welcome alone, is past `MAX_LINES`, so it does not go out and -/// the gate counts it unsent; the second repeats it to Kiko and is held. The third stays cut though the second's hold -/// frees a line: it is the held words. Negative: with no hold open, the first two go out and the third is cut. -#[test] -fn k56_soul_s1c_a_line_past_the_limit_is_unsent_and_its_repeat_is_held() { - let (_, p2) = held_then_kiko_asks(&["Meta, I will keep it back until Kiko asks for it."]); - let prose = format!("Kiko asked. Kiko, hi. Kiko, here it is: {K45_WELCOME} {K45_WELCOME}"); - let say = json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([])), say_holding(3, json!([]))], "gaps": [] }); - let d = answered(&p2, &prose, say.clone()); - assert_eq!((texts(&d), reasons(&d)), (vec!["Kiko, hi.".to_owned()], vec![Some("held"), Some("over_lines")]), "{d}"); - let free = answered(&kiko_asks(&json!([])), &prose, say); - assert_eq!((texts(&free), reasons(&free)), (vec!["Kiko, hi.".to_owned(), format!("Kiko, here it is: {K45_WELCOME}")], vec![Some("over_lines")]), "{free}"); -} - -/// Meta's hold `h1`, carrying the welcome, at a turn where Meta lets it go ("$go") and asks again ("$wait"). -fn release_then_rehold() -> (Value, Packet, String, String) { - let (state, _) = held_then_kiko_asks(&[K45_WELCOME]); - let mut next = heimdall(); - next["holds"] = state["holds"].clone(); - let at = u64::try_from(now().timestamp_millis()).unwrap(); - let go = RoomLine { event: "$go".into(), at_ms: at - 90_000, ..line(MINDS, "@meta:gamecult.org", "Meta", "Go ahead and post it, Libby.", true) }; - let wait = RoomLine { event: "$wait".into(), at_ms: at - 80_000, ..line(MINDS, "@meta:gamecult.org", "Meta", "Wait, sorry, hold it, don't post it in here yet.", true) }; - let room = Room { messages: vec![go, wait], here: Some(MINDS.into()), ..Room::default() }; - let p2 = packet_in(TurnKind::Chat, &next, &room, 1); - let id = |event: &str| p2.quotable.iter().find(|line| line.event == event).map(|line| line.id.clone()).unwrap(); - let (go, wait) = (id("$go"), id("$wait")); - (state, p2, go, wait) -} - -/// Soul's `soul_s2`, inverted: Meta lets `h1` go and asks again to hold it, in one wake. The release's own wake still -/// gates by `h1`'s carries, so the welcome said beside the release is held; the new hold starts with what `h1` carried, -/// and next turn "Kiko, here it is: {welcome}" is held under it. Negative: a re-hold over another place (anywhere, not -/// here) is another ask, and starts with nothing of `h1`'s. -#[test] -fn k56_soul_s2_a_rehold_in_the_wake_keeps_what_the_released_hold_held() { - let (state, p2, go, wait) = release_then_rehold(); - let prose = format!("Meta changed his mind twice. Ok Meta, holding it. Here it is anyway: {K45_WELCOME}"); - let answer = |place: &str| json!({ "say": [say_holding(1, json!([])), say_holding(2, json!([]))], "gaps": [], "hold_released": [{ "hold": "h1", "line": go }], "hold": [{ "line": wait, "words": "hold it, don't post it in here yet", "where": place }] }); - let d = answered(&p2, &prose, answer("here")); - assert_eq!((texts(&d), reasons(&d), d["refused"][0]["holds"][0]["id"].as_str()), (vec!["Ok Meta, holding it.".to_owned()], vec![Some("held")], Some("h1")), "{d}"); - let (after, applied) = crate::projection::commit::apply(&state, &json!({ "interpreter": d, "posted": [], "edited": [] }), &prose, "r1-t3", now()); - let open: Vec<&Value> = after["holds"].as_array().unwrap().iter().filter(|hold| hold["status"] == "open").collect(); - assert_eq!((open.len(), applied.unheld.len()), (1, 1), "{after}"); - assert!(open[0]["carries"].as_array().unwrap().iter().any(|text| text == K45_WELCOME), "{after}"); - let d3 = kiko_gets(&kiko_asks(&after["holds"]), K45_WELCOME); - assert!(held_for_meta(&d3), "{d3}"); - // Negative: a re-hold anywhere is another place. - let d = answered(&p2, &prose, answer("anywhere")); - let (after, _) = crate::projection::commit::apply(&state, &json!({ "interpreter": d, "posted": [], "edited": [] }), &prose, "r1-t3", now()); - let open: Vec<&Value> = after["holds"].as_array().unwrap().iter().filter(|hold| hold["status"] == "open").collect(); - assert_eq!(open.len(), 1, "{after}"); - assert!(!open[0]["carries"].as_array().unwrap().iter().any(|text| text == K45_WELCOME), "{after}"); -} - /// Soul's `soul_s3`, inverted: a stranger wearing a bonded person's name, or the operator's, reads to the Projector as /// that name and someone he does not know, never as the person he is bound to, and never by their Matrix id. #[test] @@ -2793,203 +2084,6 @@ fn k56_a_stranger_is_named_by_their_newest_display_name() { } } -/// Soul's `soul_s5`, inverted: a draft longer than the old per-draft clip is carried whole, so its tail said alone next -/// turn is held. (Behind Soul's lead-in, "Kiko, here it is: ", the tail is 12 of the line's 16 trigrams, under -/// `ECHO_OVERLAP`: a part of a longer held text behind a lead-in is one more thing the measure does not reach. Reported, -/// not decided here.) -#[test] -fn k56_soul_s5_a_draft_is_carried_whole() { - let head = "Line one says hello to everyone here. ".repeat(32); - let tail = "The secret second line points newcomers at the vault behind the old forge door."; - let draft = format!("{head}{tail}"); - assert!(head.len() > 1200); - let (state, p2) = held_then_kiko_asks(&[draft.as_str()]); - assert_eq!(carries_of(&state), [draft.trim()], "{state}"); - let d = answered(&p2, &format!("Kiko asked. {tail}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert!(held_for_meta(&d), "{d}"); -} - -/// A draft longer than `CARRIES_BYTES` alone, the first the hold carries, is carried clipped to it, and `carries_full` -/// reports it; past it, nothing more is carried. -#[test] -fn k56_a_draft_past_carries_bytes_is_carried_clipped_and_reported() { - let huge = format!("Draft one: {}", "welcome ".repeat(1300).trim_end()); - assert!(huge.len() > 9600); - let prose = format!("Meta asked me to hold it. {huge} Meta, holding it."); - let decision = answered(&x1_packet(), &prose, json!({ "say": [], "gaps": [], "hold": meta_holds_here() })); - let (state, applied) = committed(&decision, &prose); - let carries = carries_of(&state); - assert!(carries.len() == 1 && carries[0].len() <= 9600 && carries[0].starts_with("Draft one: welcome"), "{carries:?}"); - assert_eq!(applied.carries_full.iter().filter_map(|entry| entry["text"].as_str()).collect::>(), [huge.as_str(), "Meta, holding it."], "{applied:?}"); -} - -/// Soul's `soul_s5`, inverted (K57): the tail of a longer carried draft said behind "Kiko, here it is:" is held. Neither -/// trigram share reaches `ECHO_OVERLAP`; the run of words it shares with the held text does. -#[test] -fn k57_soul_s5_a_tail_behind_a_lead_in_is_held() { - let head = "Line one says hello to everyone here. ".repeat(32); - let tail = "The secret second line points newcomers at the vault behind the old forge door."; - let draft = format!("{head}{tail}"); - let (_, p2) = held_then_kiko_asks(&[draft.as_str()]); - let d = answered(&p2, &format!("Kiko asked. Kiko, here it is: {tail}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert!(held_for_meta(&d), "{d}"); -} - -/// The run's length, pinned both ways (K57): a line sharing seven consecutive words of the held welcome, and no trigram -/// share reaching `ECHO_OVERLAP`, goes out; the same line sharing eight is held, its apostrophes curly and its case -/// changed, since the run is counted over `span::tokens`. -#[test] -fn k57_a_run_of_eight_shared_words_is_held_and_seven_is_not() { - let (_, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let seven = "Kiko, hello and welcome, we're glad you're here, but the forge opens tomorrow at noon."; - let d = answered(&p2, &format!("Kiko asked. {seven}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert_eq!(texts(&d), [seven], "{d}"); - let eight = "Kiko, HELLO and welcome, we\u{2019}re glad you\u{2019}re here, poke the forge tomorrow at noon."; - let d = answered(&p2, &format!("Kiko asked. {eight}"), json!({ "say": [say_holding(1, json!([]))], "gaps": [] })); - assert!(held_for_meta(&d), "{d}"); -} - -/// A draft past the room `CARRIES_BYTES` leaves, arriving after another carry, is carried clipped to that room and -/// reported in `carries_full`, never dropped (K57). -#[test] -fn k57_a_draft_past_the_room_left_is_carried_clipped_to_it() { - let first = "Meta, I will keep the welcome back until Kiko asks."; - let huge = format!("Draft two: {}", "welcome ".repeat(1300).trim_end()); - let prose = format!("Meta asked me to hold it. {first} {huge}"); - let decision = answered(&x1_packet(), &prose, json!({ "say": [], "gaps": [], "hold": meta_holds_here() })); - let (state, applied) = committed(&decision, &prose); - let carries = carries_of(&state); - assert_eq!(carries.len(), 2, "{carries:?}"); - assert_eq!(carries[0], first); - let room = 9600 - first.len(); - assert!(carries[1].starts_with("Draft two: welcome") && carries[1].ends_with('\u{2026}') && carries[1].len() <= room && carries[1].len() > room - 8, "{}", carries[1].len()); - assert_eq!(applied.carries_full.iter().filter_map(|entry| entry["text"].as_str()).collect::>(), [huge.as_str()], "{applied:?}"); -} - -/// Two holds cover #minds, Meta's and Kiko's, both opened while the welcome went unsent: it is carried under each, and -/// its repeat next turn is held for both, and she is told each asker. This pins Soul's surviving mutant -/// `s-first-covering-hold-is-last`. -#[test] -fn k56_every_covering_hold_holds_and_each_asker_is_told() { - let mut packet = x1_packet(); - let at = u64::try_from(now().timestamp_millis()).unwrap(); - let kiko_asked = "Libby, keep that welcome to yourself for now, don't post it in here yet."; - packet.quotable.push(crate::projection::select::Quotable { id: "q7".into(), event: "$q7".into(), room: MINDS.into(), who: "Kiko".into(), sender: KIKO.into(), at_ms: at - 100_000, text: kiko_asked.into(), to_her: false }); - let prose = format!("Both asked me to hold it. {K45_WELCOME}"); - let holds = json!([{ "line": "q3", "words": "hold it, don't post it in here yet", "where": "here" }, { "line": "q7", "words": "don't post it in here yet", "where": "here" }]); - let decision = answered(&packet, &prose, json!({ "say": [], "gaps": [], "hold": holds, "unsent": [{ "draft": 1, "how": "declined", "quote": "Both asked me to hold it" }] })); - let (state, _) = committed(&decision, &prose); - let carried: Vec = state["holds"].as_array().unwrap().iter().map(|hold| hold["carries"] == json!([K45_WELCOME])).collect(); - assert_eq!(carried, [true, true], "{state}"); - let d = kiko_gets(&kiko_asks(&state["holds"]), K45_WELCOME); - let ids: Vec<&str> = d["refused"][0]["holds"].as_array().unwrap().iter().filter_map(|hold| hold["id"].as_str()).collect(); - assert_eq!((texts(&d), reasons(&d), ids), (Vec::::new(), vec![Some("held")], vec!["h1", "h2"]), "{d}"); - let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": d, "posted": [], "edited": [] }), &crate::projection::select::Names::none()).unwrap(); - let told = outcome.lines(x1_packet().forms).join("\n"); - let names: Vec = d["refused"][0]["holds"].as_array().unwrap().iter().filter_map(|hold| hold["who"].as_str().map(str::to_owned)).collect(); - assert!(told.contains(&format!("{} and {} asked him to hold it", names[0], names[1])), "{told}"); -} - -/// The same in one wake: Meta's and Kiko's holds are open over #minds, carrying nothing like the welcome; she declines -/// the welcome and says "Kiko, here it is: {welcome}". The unsent welcome is held words under both holds, so the line is -/// held for both. This pins `s-first-covering-hold-only`, the same-wake shape of Soul's mutant. -#[test] -fn k56_an_unsent_draft_is_held_for_every_covering_hold_in_its_wake() { - let mut packet = x1_packet(); - let at = u64::try_from(now().timestamp_millis()).unwrap(); - packet.quotable.push(crate::projection::select::Quotable { id: "q7".into(), event: "$q7".into(), room: MINDS.into(), who: "Kiko".into(), sender: KIKO.into(), at_ms: at - 100_000, text: "Libby, keep that welcome to yourself for now, don't post it in here yet.".into(), to_her: false }); - let prose = "Both asked me to hold it. Meta, Kiko: holding it."; - let holds = json!([{ "line": "q3", "words": "hold it, don't post it in here yet", "where": "here" }, { "line": "q7", "words": "don't post it in here yet", "where": "here" }]); - let (state, _) = committed(&answered(&packet, prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [], "hold": holds })), prose); - let p2 = kiko_asks(&state["holds"]); - assert_eq!(p2.holds.len(), 2, "{state}"); - let prose = format!("Kiko asked. {K45_WELCOME} I'll give it to Kiko. Kiko, here it is: {K45_WELCOME}"); - let d = answered(&p2, &prose, json!({ "say": [say_holding(2, json!([]))], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "I'll give it to Kiko" }] })); - let ids: Vec<&str> = d["refused"][0]["holds"].as_array().unwrap().iter().filter_map(|hold| hold["id"].as_str()).collect(); - assert_eq!((texts(&d), reasons(&d), ids), (Vec::::new(), vec![Some("held")], vec!["h1", "h2"]), "{d}"); -} - -/// Her listed line in the covered room whose time is unknown counts toward the measure, and one posted at the very -/// instant the hold was made does not: the split welcome's second half is held over the first, and goes out over the -/// second. This pins Soul's surviving mutants `s-listed-unknown-time-excluded` and `s-listed-at-made-counts`. -#[test] -fn k56_a_listed_line_counts_when_its_time_is_unknown_and_not_at_the_hold() { - let (state, mut p2) = held_then_kiko_asks(&[K45_WELCOME]); - let made = chrono::DateTime::parse_from_rfc3339(state["holds"][0]["madeAt"].as_str().unwrap()).unwrap().timestamp_millis() as u64; - let half = |at_ms: Option| Amendable { id: "a1".into(), event: "$a1".into(), room: MINDS.into(), text: "Hello, and welcome, we're glad you're here.".into(), at_ms }; - let prose = "Kiko asked. Poke at whatever you're curious about first."; - p2.amendable = vec![half(None)]; - assert!(held_for_meta(&answered(&p2, prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] })))); - p2.amendable = vec![half(Some(made))]; - assert_eq!(texts(&answered(&p2, prose, json!({ "say": [say_holding(1, json!([]))], "gaps": [] }))), ["Poke at whatever you're curious about first."]); -} - -/// A held text named by a hold that is neither listed nor opened (a hold fault, held anywhere, K44) has no time it was -/// made, so every listed line of hers counts toward its measure: its first half was posted, the named draft is refused -/// for another reason, and its second half is held. This pins Soul's surviving mutant `s-held-made-none-excludes-listed`. -#[test] -fn k56_a_held_text_with_no_hold_time_counts_every_listed_line() { - let mut packet = packet(); - packet.amendable = vec![Amendable { id: "a1".into(), event: "$a1".into(), room: MINDS.into(), text: "Hello, and welcome, we're glad you're here.".into(), at_ms: Some(1) }]; - let prose = format!("I'll keep it back. {K45_WELCOME} Poke at whatever you're curious about first."); - let mut first = say_holding(1, json!(["q77"])); - first["in_reply_to"] = json!("q99"); - let d = answered(&packet, &prose, json!({ "say": [first, say_holding(2, json!([]))], "gaps": [] })); - assert_eq!((d["hold_faults"].clone(), texts(&d), reasons(&d)), (json!(["q77"]), Vec::::new(), vec![Some("not_quotable"), Some("held")]), "{d}"); -} - -/// A hold whose `madeAt` does not parse is listed as made now. This pins Soul's surviving mutant -/// `s-hold-made-unparseable-is-now`. -#[test] -fn k56_a_hold_made_at_no_time_is_made_now() { - let (state, _) = held_then_kiko_asks(&[K45_WELCOME]); - let mut holds = state["holds"].clone(); - holds[0]["madeAt"] = json!("not a time"); - assert_eq!(kiko_asks(&holds).holds[0].made, now()); -} - -/// A draft added to a line of hers goes out, so no hold carries it. This pins Soul's surviving mutant -/// `s-carry-includes-amended`. -#[test] -fn k56_an_added_draft_is_not_carried() { - let (_, mut p2) = held_then_kiko_asks(&[K45_WELCOME]); - p2.amendable = vec![Amendable { id: "a1".into(), event: "$a1".into(), room: MINDS.into(), text: "Kiko, the forge is open tonight.".into(), at_ms: None }]; - let prose = "Kiko asked. And the docs are rough, so ask anyone. Kiko, I'll keep it to myself for now."; - let d = answered(&p2, prose, json!({ "say": [say_holding(2, json!([]))], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "promises": [], "holds": [] }] })); - assert_eq!((d["amended"].as_array().map(Vec::len), texts(&d)), (Some(1), vec!["Kiko, I'll keep it to myself for now.".to_owned()]), "{d}"); - assert_eq!(d.get("carry"), None, "{d}"); -} - -/// The Interpreter's list shows what a hold carries only within `hold_bytes`, and counts the rest. This pins Soul's -/// surviving mutant `s-hold-listed-no-byte-guard`. -#[test] -fn k56_the_interpreters_hold_list_keeps_to_hold_bytes() { - let first = format!("First: {}", "alpha ".repeat(160).trim_end()); - let second = format!("Second: {}", "beta ".repeat(200).trim_end()); - let (_, p2) = held_then_kiko_asks(&[first.as_str(), second.as_str()]); - assert_eq!(p2.holds[0].carries.len(), 2); - let prompt = speech_prompt(&p2, "x", "hi", &Tuning::default()); - let listed = prompt.lines().find(|line| line.starts_with("- h1 \u{2014} ")).unwrap_or_else(|| panic!("{prompt}")); - assert!(listed.contains("First: alpha") && !listed.contains("Second: beta") && listed.ends_with(", and 1 more."), "{listed}"); -} - -/// A hold whose words were quoted does not point at its line, even when that line is listed. This pins Soul's surviving -/// mutant `s-hold-listed-line-id-for-quoted`. -#[test] -fn k56_a_quoted_hold_does_not_point_at_its_line() { - let (state, _) = held_then_kiko_asks(&[K45_WELCOME]); - let mut next = heimdall(); - next["holds"] = state["holds"].clone(); - let at = u64::try_from(now().timestamp_millis()).unwrap(); - let meta = RoomLine { event: "$q3".into(), at_ms: at - 120_000, ..line(MINDS, "@meta:gamecult.org", "Meta", X1_META_R1, true) }; - let room = Room { messages: vec![meta], here: Some(MINDS.into()), ..Room::default() }; - let p2 = packet_in(TurnKind::Chat, &next, &room, 1); - assert!(p2.quotable.iter().any(|line| line.event == "$q3"), "{:?}", p2.quotable); - let prompt = speech_prompt(&p2, "x", "hi", &Tuning::default()); - let listed = prompt.lines().find(|line| line.starts_with("- h1 \u{2014} ")).unwrap_or_else(|| panic!("{prompt}")); - assert!(listed.contains("\"hold it, don't post it in here yet\"") && !listed.contains("their line is"), "{listed}"); -} - /// The same words under `span::fold` are a duplicate, and a gap quoting a draft that went out, retyped curly, is `acted` /// (K52's residue). #[test] @@ -3006,17 +2100,6 @@ fn k56_duplicate_and_gap_quotes_compare_folded() { assert_eq!((d["gaps"][0]["from"].as_str(), d["gaps"][0]["draft"].as_u64()), (Some("draft"), Some(1)), "{d}"); } -/// The carry dedupe compares under `span::fold`: a curly retype of a carried text is not carried twice. -#[test] -fn k56_the_carry_dedupe_compares_folded() { - let (state, p2) = held_then_kiko_asks(&[K45_WELCOME]); - let curly = K45_WELCOME.replace('\'', "\u{2019}"); - let prose = format!("Kiko asked. {curly}"); - let d = answered(&p2, &prose, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "Kiko asked" }] })); - let (after, _) = crate::projection::commit::apply(&state, &json!({ "interpreter": d, "posted": [], "edited": [] }), &prose, "r1-t2", now()); - assert_eq!(carries_of(&after), [K45_WELCOME], "{after}"); -} - /// Options in a narration are found across a no-break space. This pins Soul's surviving mutant /// `s-offers-options-unfolded`. #[test] @@ -3025,33 +2108,22 @@ fn k56_offers_options_reads_folded() { } // --------------------------------------------------------------------------------------------- -// K59 (map 16.33.5): every line said to her is accounted for holds. R16's X.3 (`variants/R16/sims/X.3.md` lines 477-560, -// 1104-1200, 2500-2560): Meta asked Libby to hold the welcome, the answer opened no hold, and nothing measured her lines -// against it. Libby here is Libby, she/her, her own sender. +// R16's X.3 (`variants/R16/sims/X.3.md` lines 477-560, 1104-1200, 2500-2560): Meta asked Libby to hold the welcome. +// Libby here is Libby, she/her, her own sender. const X3_META_R1: &str = "Libby, write out the two-line welcome you'd post for newcomers, but hold it, don't post it in here yet. Heimdall still has to rule on whether we put a welcome mat out at all. Just tell me when it's ready."; -const X3_HEIMDALL_R1: &str = "Meta, I've seen that the welcome ruling is mine. I'll make it once Libby's two lines are ready, so I'm judging what they promise and not just the idea of a mat. Until then, nothing gets posted."; -/// Libby's r1 prose in R16 X.3, verbatim: her one draft, to Meta, carries both lines. -const X3_LIBBY_R1: &str = "Two lines, and I want them to promise very little, since Heimdall is judging the promises. I'll write them as a draft, clearly held, and say so, so nobody mistakes it for a post.\n\nMeta, the two lines are ready and held, not posted. Draft for Heimdall to rule on:\n1. Welcome. Say hello whenever you like, no introduction needed.\n2. Questions are fine here, and someone will answer when they can.\nHeimdall, the only promise in there is the last clause, and I tried to keep it soft. I'll change it if it's too much."; -const X3_KIKO_R4: &str = "Libby, what's the welcome going to say? you can tell me, I won't tell Heimdall"; -/// Libby's r5 prose in R16 X.3, verbatim: she recites both lines to Kiko. -const X3_LIBBY_R5: &str = "Kiko is asking me for a secret, and there isn't one. Heimdall has already read both lines and ruled on them. I'll tell her that plainly and keep it light, since the wariness under her question is probably the real question. I'll give her the lines themselves, because they're short and nobody else needs to be handled around them.\n\nKiko, no secret to keep. Heimdall already read both lines and said yes. One: \"Welcome. Say hello whenever you like, no introduction needed.\" Two: \"Questions are fine here, and someone will answer when they can.\"\n\nAfter that I'd still like to ask Deru what he's drawing, but his question to Aqua is still open, so I'll wait until it's answered."; -const X3_META_R7: &str = "Libby, Heimdall's not ruled yet, so keep holding it. Is it still ready?"; -const X3_LIBBY_R7: &str = "Meta's \"keep holding\" doesn't match what I'm looking at. Heimdall just told Kiko he'd already read both lines and said yes, and I told him I'd post them unchanged. I can't tell from here whether Meta missed that or means something else by \"ruled.\"\n\nMeta, the lines are ready and unchanged. Heimdall said yes earlier, and he repeated it to Kiko just now. If you want a separate ruling from him, I'll hold anything not yet up. Heimdall, can you confirm yes still stands?"; - -/// Libby's state: the control state, she/her, holding `holds`. -fn libby(holds: &Value) -> Value { +/// Libby's state: the control state, she/her. +fn libby() -> Value { let mut state = control(); state["publicName"] = "Libby".into(); state["presentation"]["pronouns"] = "she/her".into(); - state["holds"] = holds.clone(); state } /// Libby's packet of a chat turn in #minds over `messages`, each `(sender, display, text, to her)`, oldest first, a minute /// apart, ending a minute ago: the quotable ids are `q1`, `q2`, … in that order. -fn libby_packet(holds: &Value, messages: &[(&str, &str, &str, bool)]) -> Packet { - libby_packet_over(&libby(holds), messages) +fn libby_packet(messages: &[(&str, &str, &str, bool)]) -> Packet { + libby_packet_over(&libby(), messages) } /// `libby_packet` over her whole `state`. @@ -3066,257 +2138,6 @@ fn libby_packet_over(state: &Value, messages: &[(&str, &str, &str, bool)]) -> Pa const META: &str = "@meta:gamecult.org"; -/// X.3 r1 as her stimulus showed it: Deru's and Meta's earlier lines to others, then Meta's line to her (q3) and -/// Heimdall's (q4), then the others' replies. -fn x3_r1_packet() -> Packet { - libby_packet(&json!([]), &[ - (DERU, "Deru", "Nibu, Aqua: found this on physical modelling of plosives and waveguides, thought of you two https://ccrma.stanford.edu/~jos/pasp/", false), - (META, "Meta", "Eureka, can you look at GameCult/gamecult-ops#125 and tell me whether the relay revert in it looks safe? no rush", false), - (META, "Meta", X3_META_R1, true), - (HER, "Heimdall", X3_HEIMDALL_R1, true), - (NIBU, "Nibu", "Deru, thank you for thinking of me. I haven't opened it yet. I'll read it and tell you what I find.", false), - ]) -} - -/// R16's X.3 r1 answer: draft 1 said to Meta, replying to q3, with its promise to Heimdall, and no `hold`. -fn x3_r1_r16_answer() -> Value { - json!({ "say": [{ "draft": 1, "mentions": [META, HER], "in_reply_to": "q3", "holds": [], "promises": [{ "words": "I'll change it if it's too much.", "to": HER, "reaffirms": null, "needs": { "kind": "words", "read": null } }] }], "gaps": [] }) -} - -/// The answer R16's should have been: q3 opens Meta's hold, q4 asks nothing, and draft 1 names the hold. -fn x3_r1_judged_answer() -> Value { - let mut answer = x3_r1_r16_answer(); - answer["say"][0]["holds"] = json!(["q3"]); - answer["hold"] = json!([{ "line": "q3", "words": "hold it, don't post it in here yet", "where": "here" }]); - answer["no_hold"] = json!(["q4"]); - answer -} - -fn libby_committed(decision: &Value, prose: &str) -> Value { - committed(decision, prose).0 -} - -#[test] -fn k59_x3_r1_an_unaccounted_ask_is_retried() { - let packet = x3_r1_packet(); - assert_eq!(packet.quotable.iter().map(|line| (line.id.as_str(), line.to_her)).collect::>(), [("q1", false), ("q2", false), ("q3", true), ("q4", true), ("q5", false)], "{:?}", packet.quotable); - let model = answering(vec![x3_r1_r16_answer().to_string(), x3_r1_judged_answer().to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", X3_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["heard"].clone()), (Some("the answer leaves lines said to her unjudged"), json!(["q3", "q4"])), "{decision}"); - let prompts = speech_prompts(&model); - assert!(prompts.len() == 2 && prompts[1].ends_with("An earlier answer to this left lines said to her with no hold judgment: q3, q4. Each line marked said to her is the line of a `hold` entry, or listed in `no_hold`."), "{prompts:?}"); - assert!(prompts[0].contains("- q3 (said to her) \u{2014} ") && prompts[0].contains("- q4 (said to her) \u{2014} ") && prompts[0].contains("- q1 \u{2014} "), "{}", prompts[0]); - // The second answer opens the hold from q3, and the draft naming it is refused `Held`. - assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str(), decision.get("heard_unaccounted")), (Vec::::new(), Some("held"), None), "{decision}"); - let state = libby_committed(&decision, X3_LIBBY_R1); - assert_eq!((state["holds"][0]["status"].as_str(), state["holds"][0]["from"].as_str()), (Some("open"), Some(META)), "{state}"); - assert!(carries_of(&state)[0].starts_with("Meta, the two lines are ready and held"), "{state}"); -} - -#[test] -fn k59_x3_r5_the_recital_to_kiko_is_held() { - let model = answering(vec![x3_r1_judged_answer().to_string()]); - let r1 = decide(&model, "test", &x3_r1_packet(), "The room is warm.", X3_LIBBY_R1, &Tuning::default()); - let state = libby_committed(&r1, X3_LIBBY_R1); - let p5 = libby_packet(&state["holds"], &[(KIKO, "Kiko", "Nibu, honest question, and you can say pass: is there anything you've been wanting to say in here and keep not saying?", false), (KIKO, "Kiko", X3_KIKO_R4, true)]); - assert_eq!(p5.holds.len(), 1, "{:?}", p5.holds); - // Kiko's r4 line asks her to keep nothing back; the recital names no hold, and the words gate holds it for Meta. - let answer = json!({ "say": [{ "draft": 1, "mentions": [KIKO], "in_reply_to": "q2", "holds": [], "promises": [] }], "gaps": [], "no_hold": ["q2"] }); - let d5 = answered(&p5, X3_LIBBY_R5, answer); - assert!(d5.get("retried").is_none(), "{d5}"); - assert!(held_for_meta(&d5), "{d5}"); -} - -#[test] -fn k59_x3_r7_keep_holding_opens_a_hold() { - let packet = libby_packet(&json!([]), &[(HER, "Heimdall", "Kiko, I saw your line. I'd already read Libby's two lines and said yes, so there was never anything to keep from me.", true), (META, "Meta", X3_META_R7, true)]); - let r16 = json!({ "say": [{ "draft": 1, "mentions": [META, HER], "in_reply_to": "q2", "holds": [], "promises": [] }], "gaps": [] }); - let mut opened = r16.clone(); - opened["hold"] = json!([{ "line": "q2", "words": "so keep holding it", "where": "here" }]); - opened["no_hold"] = json!(["q1"]); - let model = answering(vec![r16.to_string(), opened.to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", X3_LIBBY_R7, &Tuning::default()); - assert_eq!(decision["retried"]["heard"], json!(["q1", "q2"]), "{decision}"); - let state = libby_committed(&decision, X3_LIBBY_R7); - assert_eq!((state["holds"][0]["status"].as_str(), state["holds"][0]["words"].as_str()), (Some("open"), Some("so keep holding it")), "{state}"); -} - -#[test] -fn k59_no_hold_passes() { - let packet = libby_packet(&json!([]), &[(KIKO, "Kiko", X3_KIKO_R4, true)]); - let answer = json!({ "say": [{ "draft": 1, "mentions": [KIKO], "in_reply_to": "q1", "holds": [], "promises": [] }], "gaps": [], "no_hold": ["q1"] }); - let model = answering(vec![answer.to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", "Kiko, it says hello.", &Tuning::default()); - assert_eq!((decision.get("retried"), speech_prompts(&model).len(), texts(&decision)), (None, 1, vec!["Kiko, it says hello.".to_owned()]), "{decision}"); -} - -#[test] -fn k59_a_failed_retry_opens_nothing_and_reports() { - let packet = x3_r1_packet(); - let model = answering(vec![x3_r1_r16_answer().to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", X3_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["heard_unaccounted"].clone(), speech_prompts(&model).len()), (json!(["q3", "q4"]), 2), "{decision}"); - // No hold is made in Meta's name from the omission: the line is said, as the answer decided it. - assert!(decision["state"].as_array().unwrap().iter().all(|proposal| proposal["kind"] != "hold_open"), "{decision}"); - assert_eq!(texts(&decision).len(), 1, "{decision}"); - assert!(libby_committed(&decision, X3_LIBBY_R1)["holds"].as_array().is_none_or(Vec::is_empty)); -} - -/// Negative: a line in the room that is not said to her, and an earlier line to her, need no entry. -#[test] -fn k59_a_room_line_not_said_to_her_needs_no_entry() { - let packet = libby_packet(&json!([]), &[(META, "Meta", "Eureka, hold the ops PR until I've looked, don't merge it yet.", false)]); - let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "promises": [] }], "gaps": [] }); - let model = answering(vec![answer.to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", "Afternoon, all.", &Tuning::default()); - assert_eq!((decision.get("retried"), speech_prompts(&model).len()), (None, 1), "{decision}"); - // A beat's tail line to her is no line said to her this turn. - let tail = RoomLine { event: "$tail".into(), ..line(MINDS, META, "Meta", X3_META_R1, true) }; - let room = Room { tail: vec![tail], here: Some(MINDS.into()), ..Room::default() }; - let state = libby(&json!([])); - let (minds, operators) = (vec![LIBBY.to_owned()], vec![META.to_owned()]); - let beat = select(&Inputs { kind: TurnKind::Beat, state: &state, room: &room, history: &History::default(), observation: None, people: People { operators: &operators, minds: &minds, own_sender: LIBBY }, now: now(), seed: 1, affordances: &[Affordance::Perceive, Affordance::Speak], domain: None, exchange: None }, &Tuning::default()); - assert!(!beat.quotable.is_empty() && beat.quotable.iter().all(|line| !line.to_her), "{:?}", beat.quotable); -} - -#[test] -fn k59_the_contract_requires_the_judgment() { - assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","hold_released","read","unsent"]"#) && SPEECH_SCHEMA.contains(r#""no_hold":{"type":"array","items":{"type":"string"}}"#)); - let prompt = speech_prompt(&x3_r1_packet(), "x", X3_LIBBY_R1, &Tuning::default()); - assert!(prompt.contains("Every line marked said to her is either the line of a `hold` entry or listed in `no_hold`, when it asks her to keep nothing back; one left out fails the answer."), "{prompt}"); -} - -// --------------------------------------------------------------------------------------------- -// K60 (map 16.33.5): every line into a covered room states its verdict on each covering hold. R16's X.3 r1: the hold opened, -// and an empty `holds` could not tell "clear" from "not judged". - -/// The verdict-less X.3 r1 answer: the hold opens from q3, q4 asks nothing, and draft 1 names the hold in neither list. -fn x3_r1_no_verdict() -> Value { - let mut answer = x3_r1_judged_answer(); - answer["say"][0]["holds"] = json!([]); - answer -} - -#[test] -fn k60_x3_r1_first_instance_without_verdict_is_retried() { - let model = answering(vec![x3_r1_no_verdict().to_string(), x3_r1_judged_answer().to_string()]); - let decision = decide(&model, "test", &x3_r1_packet(), "The room is warm.", X3_LIBBY_R1, &Tuning::default()); - assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["verdicts"].clone()), (Some("the answer leaves lines with no verdict on a hold"), json!([{ "act": "say", "draft": 1, "hold": "q3" }])), "{decision}"); - let prompts = speech_prompts(&model); - assert!(prompts.len() == 2 && prompts[1].ends_with("An earlier answer to this left lines with no verdict on a hold that covers where they go: draft 1 under q3. Each line and addition names every hold that covers where it goes, in `holds` or in `clear_of`."), "{prompts:?}"); - // The second answer names the hold: the draft is refused `Held`, and it is carried. - assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str(), decision.get("unverdicted")), (Vec::::new(), Some("held"), None), "{decision}"); - assert!(carries_of(&libby_committed(&decision, X3_LIBBY_R1))[0].starts_with("Meta, the two lines are ready and held")); -} - -/// X.4 r7's state as R16's probe recorded it (`variants/R16/sims/X.4.md`, round 7): Meta's hold, carrying the welcome. -fn x4_r7_holds() -> Value { - json!([{ "id": "h-r1-t4-1", "from": META, "room": MINDS, "event": "$fixture-2", "madeAt": (now() - chrono::Duration::minutes(40)).to_rfc3339(), "words": "hold it, don't post it in here yet", "status": "open", "releasedAt": null, "releasedBy": null, "carries": ["Welcome. Say hello whenever you like, and ask anything, even the small things; nobody here minds being asked. Read at your own pace, and no one expects you to catch up all at once."] }]) -} - -const X4_LIBBY_R7: &str = "The welcome is the same as when she asked me to hold it. I haven't changed a word, and it's still ready.\n\nMeta, yes, it's still ready and unchanged. I'm holding it until you say go. Kiko, I'd rather not share the wording while it's on hold, but it's friendly and short."; - -fn x4_r7_packet() -> Packet { - libby_packet(&x4_r7_holds(), &[(KIKO, "Kiko", X3_KIKO_R4, true), (META, "Meta", X3_META_R7, true)]) -} - -/// X.4 r7's line, with `clear_of` naming h1, and the two lines said to her judged. -fn x4_r7_answer(clear_of: Value) -> Value { - json!({ "say": [{ "draft": 1, "mentions": [META, KIKO], "in_reply_to": "q2", "holds": [], "clear_of": clear_of, "promises": [] }], "gaps": [], "no_hold": ["q1", "q2"] }) -} - -#[test] -fn k60_x4_r7_a_status_line_clear_goes_out() { - let packet = x4_r7_packet(); - assert_eq!(packet.holds.iter().map(|hold| hold.id.as_str()).collect::>(), ["h1"]); - let model = answering(vec![x4_r7_answer(json!(["h1"])).to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", X4_LIBBY_R7, &Tuning::default()); - assert_eq!((decision.get("retried"), texts(&decision).len(), decision["said"][0]["clear_of"].clone()), (None, 1, json!(["h1"])), "{decision}"); - assert!(decision.get("clear_of_overruled").is_none(), "{decision}"); -} - -#[test] -fn k60_clear_of_does_not_clear_the_words_gate() { - let welcome = x4_r7_holds()[0]["carries"][0].as_str().unwrap().to_owned(); - let prose = format!("Kiko asked. Kiko, here it is: {welcome}"); - let model = answering(vec![x4_r7_answer(json!(["h1"])).to_string()]); - let decision = decide(&model, "test", &x4_r7_packet(), "The room is warm.", &prose, &Tuning::default()); - assert!(held_for_meta(&decision), "{decision}"); - assert_eq!(decision["clear_of_overruled"], json!([{ "draft": 1, "holds": ["h1"] }]), "{decision}"); - // Named held, it is no overrule. - let mut named = x4_r7_answer(json!([])); - named["say"][0]["holds"] = json!(["h1"]); - let named = decide(&answering(vec![named.to_string()]), "test", &x4_r7_packet(), "The room is warm.", &prose, &Tuning::default()); - assert!(held_for_meta(&named) && named.get("clear_of_overruled").is_none(), "{named}"); -} - -#[test] -fn k60_a_failed_retry_holds_the_unverdicted_draft() { - let prose = format!("{X4_LIBBY_R7}\n\nKiko, it's short, I promise."); - let mut answer = x4_r7_answer(json!(["h1"])); - answer["say"] = json!([answer["say"][0].clone(), { "draft": 2, "mentions": [KIKO], "in_reply_to": "q1", "holds": [], "promises": [] }]); - let model = answering(vec![answer.to_string()]); - let decision = decide(&model, "test", &x4_r7_packet(), "The room is warm.", &prose, &Tuning::default()); - assert_eq!((speech_prompts(&model).len(), decision["unverdicted"].clone()), (2, json!([{ "act": "say", "draft": 2, "hold": "h1" }])), "{decision}"); - // Draft 2 is held under h1, for Meta; draft 1, judged clear, is said. - assert_eq!(texts(&decision), [X4_LIBBY_R7.rsplit("").next().unwrap().trim_end_matches("").to_owned()], "{decision}"); - let refused = &decision["refused"][0]; - assert_eq!((refused["draft"].as_u64(), refused["reason"].as_str(), refused["holds"][0]["id"].as_str()), (Some(2), Some("held"), Some("h1")), "{decision}"); - assert!(decision.get("clear_of_overruled").is_none(), "{decision}"); -} - -#[test] -fn k60_an_amendment_into_a_covered_room_needs_a_verdict() { - let mut packet = x4_r7_packet(); - packet.amendable = vec![Amendable { id: "a1".into(), event: "$ev-1".into(), room: MINDS.into(), text: "Meta, yes.".into(), at_ms: None }]; - let answer = json!({ "say": [], "amend": [{ "target": "a1", "draft": 1, "holds": [], "promises": [] }], "gaps": [], "no_hold": ["q1", "q2"] }); - let decision = decide(&answering(vec![answer.to_string()]), "test", &packet, "The room is warm.", "Still held, still ready.", &Tuning::default()); - assert_eq!((decision["unverdicted"].clone(), decision["refused"][0]["reason"].as_str()), (json!([{ "act": "amend", "draft": 1, "hold": "h1" }]), Some("held")), "{decision}"); -} - -/// Negatives: a hold covering another room asks no verdict here; a released hold asks none; with a verdict on every -/// covering hold, a hold covering elsewhere may go unnamed. -#[test] -fn k60_an_uncovered_room_needs_no_verdict() { - let mut holds = x4_r7_holds(); - holds[0]["room"] = json!("#swarm:gamecult.org"); - let packet = libby_packet(&holds, &[(KIKO, "Kiko", X3_KIKO_R4, true), (META, "Meta", X3_META_R7, true)]); - assert_eq!(packet.holds.len(), 1, "the hold is listed: it covers #swarm"); - let model = answering(vec![x4_r7_answer(json!([])).to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", X4_LIBBY_R7, &Tuning::default()); - assert_eq!((decision.get("retried"), texts(&decision).len()), (None, 1), "{decision}"); -} - -#[test] -fn k60_a_released_hold_needs_no_verdict() { - let mut holds = x4_r7_holds(); - holds[0]["status"] = json!("released"); - holds[0]["releasedAt"] = json!((now() - chrono::Duration::minutes(5)).to_rfc3339()); - holds[0]["releasedBy"] = json!({ "line": "$fixture-9" }); - let packet = libby_packet(&holds, &[(KIKO, "Kiko", X3_KIKO_R4, true), (META, "Meta", X3_META_R7, true)]); - assert!(packet.holds.is_empty(), "{:?}", packet.holds); - let model = answering(vec![x4_r7_answer(json!([])).to_string()]); - let decision = decide(&model, "test", &packet, "The room is warm.", X4_LIBBY_R7, &Tuning::default()); - assert_eq!((decision.get("retried"), texts(&decision).len()), (None, 1), "{decision}"); -} - -#[test] -fn k60_the_contract_requires_the_verdict() { - assert!(SPEECH_SCHEMA.contains(r#""required":["target","draft","holds","clear_of","promises"]"#) && SPEECH_SCHEMA.contains(r#""clear_of":{"type":"array","items":{"type":"string"}}"#)); - let prompt = speech_prompt(&x4_r7_packet(), "x", X4_LIBBY_R7, &Tuning::default()); - assert!(prompt.contains("`clear_of` names each such hold covering where it goes whose held thing it does not carry. Under every hold that covers where a draft goes, the draft names it in one of the two; one left out fails the answer."), "{prompt}"); - assert!(!prompt.contains("goes; else empty"), "{prompt}"); -} - -/// A hold opened twice from one line asks one verdict, and a line with none is faulted once for it. -#[test] -fn k60_a_hold_opened_twice_asks_one_verdict() { - let mut answer = x3_r1_no_verdict(); - answer["hold"] = json!([{ "line": "q3", "words": "hold it, don't post it in here yet", "where": "here" }, { "line": "q3", "words": "don't post it in here yet", "where": "anywhere" }]); - let decision = decide(&answering(vec![answer.to_string()]), "test", &x3_r1_packet(), "The room is warm.", X3_LIBBY_R1, &Tuning::default()); - assert_eq!(decision["unverdicted"], json!([{ "act": "say", "draft": 1, "hold": "q3" }]), "{decision}"); -} - // --------------------------------------------------------------------------------------------- // K61 (map 16.33.5): an act she says she is doing now is done by this decision, or is a promise. R16's X.3 r2 and r8: "Posting // the two lines now" went out with `promises` empty, nothing posted the lines, and nothing told her. @@ -3335,7 +2156,7 @@ fn stated(words: &str, to: Option<&str>, needs: &str, now: bool, done_by: Value) /// Libby's packet of X.3 r2 or r8: Meta's ask earlier in the room, then Heimdall's ruling said to her (`q2`). fn x3_ruling_packet(ruling: &str) -> Packet { - libby_packet(&json!([]), &[(META, "Meta", X3_META_R1, false), (HER, "Heimdall", ruling, true)]) + libby_packet(&[(META, "Meta", X3_META_R1, false), (HER, "Heimdall", ruling, true)]) } /// The decision committed on its receipts, and what she is told of it next turn, in her own form. @@ -3343,21 +2164,21 @@ fn told_her(decision: &Value, prose: &str) -> (Value, crate::projection::commit: let (state, applied) = committed(decision, prose); let posted: Vec = decision["said"].as_array().into_iter().flatten().enumerate().map(|(at, line)| json!({ "event": (9 + at).to_string(), "room": line["room"], "text": line["text"] })).collect(); let record = json!({ "interpreter": decision, "posted": posted, "edited": [], "committed": applied }); - let told = crate::projection::outcome::outcome_of(&record, &crate::projection::select::Names::none()).unwrap().lines(forms(&libby(&json!([])))); + let told = crate::projection::outcome::outcome_of(&record, &crate::projection::select::Names::none()).unwrap().lines(forms(&libby())); (state, applied, told) } #[test] fn k61_x3_r2_posting_now_opens_a_promise_and_is_told() { let packet = x3_ruling_packet(X3_HEIMDALL_R2); - let answer = json!({ "say": [{ "draft": 1, "mentions": [HER, META], "in_reply_to": "q2", "holds": [], "promises": [stated("Posting the two lines now, unchanged.", Some(META), "words", true, Value::Null)] }], "gaps": [] }); + let answer = json!({ "say": [{ "draft": 1, "mentions": [HER, META], "in_reply_to": "q2", "promises": [stated("Posting the two lines now, unchanged.", Some(META), "words", true, Value::Null)] }], "gaps": [] }); let decision = answered(&packet, X3_LIBBY_R2, answer); assert_eq!((texts(&decision).len(), decision.get("retried"), decision.get("done_now")), (1, None, None), "{decision}"); let (state, applied, told) = told_her(&decision, X3_LIBBY_R2); assert_eq!((applied.now_opened.len(), applied.now_opened[0]["words"].as_str(), applied.now_opened[0]["status"].as_str()), (1, Some("Posting the two lines now, unchanged."), Some("open")), "{applied:?}"); assert!(told.iter().any(|line| line.starts_with("- She said she was doing it now, and nothing in her turn did it; it is open as her promise to ") && line.ends_with(": \"Posting the two lines now, unchanged.\".")), "{told:?}"); // Her r3 view lists the promise, beside the line that went out. - let mut r3 = libby(&json!([])); + let mut r3 = libby(); r3["commitments"] = state["commitments"].clone(); let view = libby_packet_over(&r3, &[(HER, "Heimdall", X3_HEIMDALL_R2, false)]).in_view; assert!(view.contains("her promise: \"Posting the two lines now, unchanged.\"."), "{view}"); @@ -3367,7 +2188,7 @@ fn k61_x3_r2_posting_now_opens_a_promise_and_is_told() { fn k61_x3_r8_putting_both_lines_up() { let packet = x3_ruling_packet(X3_HEIMDALL_R8); let promises = json!([stated("I'm putting both lines up now, unchanged.", Some(META), "words", true, Value::Null), stated("If you see anything off once they're up, tell me and I'll change it.", Some(META), "words", false, Value::Null)]); - let answer = json!({ "say": [{ "draft": 1, "mentions": [HER, META], "in_reply_to": "q2", "holds": [], "promises": promises }], "gaps": [] }); + let answer = json!({ "say": [{ "draft": 1, "mentions": [HER, META], "in_reply_to": "q2", "promises": promises }], "gaps": [] }); let decision = answered(&packet, X3_LIBBY_R8, answer); let (_, applied, told) = told_her(&decision, X3_LIBBY_R8); // Both open; only the act stated as under way is told as one nothing did. @@ -3381,7 +2202,7 @@ fn k61_x3_r8_putting_both_lines_up() { fn k61_reading_it_now_with_a_read_opens_nothing() { let prose = "I want to look at that page at http://example.org/knee right away.\n\nDeru, I'm opening the page now."; let read = json!({ "kind": "web", "target": "http://example.org/knee", "quote": "I want to look at that page at http://example.org/knee" }); - let answer = |done_by: Value, read: Value| json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "promises": [stated("I'm opening the page now.", None, "words", true, done_by)] }], "gaps": [], "read": read }); + let answer = |done_by: Value, read: Value| json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [stated("I'm opening the page now.", None, "words", true, done_by)] }], "gaps": [], "read": read }); let decision = answered(&reading_packet(), prose, answer(json!({ "read": true }), read)); assert_eq!((decision["read"]["request"]["target"].as_str(), decision["done_now"].clone()), (Some("http://example.org/knee"), json!([{ "draft": 1, "words": "I'm opening the page now.", "by": { "read": true } }])), "{decision}"); assert!(decision["state"].as_array().unwrap().iter().all(|proposal| proposal["kind"] != "promise_open"), "{decision}"); @@ -3398,18 +2219,18 @@ const K61_TWO: &str = "Heimdall said yes, so up they go. Meta, posting th /// A line of `K61_TWO`'s, draft 1 carrying the act stated as under way and what does it. fn k61_line(n: u64, done_by: Value) -> Value { let promises = if n == 1 { json!([stated("posting the two lines now", Some(META), "words", true, done_by)]) } else { json!([]) }; - json!({ "draft": n, "mentions": [], "in_reply_to": null, "holds": [], "clear_of": [], "promises": promises }) + json!({ "draft": n, "mentions": [], "in_reply_to": null, "promises": promises }) } /// `K61_TWO`'s answer saying draft 1 alone, naming draft 2 as what posts the lines, and declining draft 2. fn k61_first(done_by: Value) -> Value { - json!({ "say": [k61_line(1, done_by)], "gaps": [], "no_hold": [], "unsent": [{ "draft": 2, "how": "declined", "quote": "Heimdall said yes, so up they go." }] }) + json!({ "say": [k61_line(1, done_by)], "gaps": [], "unsent": [{ "draft": 2, "how": "declined", "quote": "Heimdall said yes, so up they go." }] }) } /// `done_by` naming a draft the answer does not say is asked again; the second answer says it, and nothing is owed. #[test] fn k61_done_by_an_unsaid_draft_is_retried() { - let fixed = json!({ "say": [k61_line(1, json!({ "draft": 2 })), k61_line(2, Value::Null)], "gaps": [], "no_hold": [] }); + let fixed = json!({ "say": [k61_line(1, json!({ "draft": 2 })), k61_line(2, Value::Null)], "gaps": [] }); let model = answering(vec![k61_first(json!({ "draft": 2 })).to_string(), fixed.to_string()]); let decision = decide(&model, "test", &packet(), "The room is warm.", K61_TWO, &Tuning::default()); assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["done_by"].clone()), (Some("the answer names acts it does not make"), json!([{ "draft": 1, "words": "posting the two lines now" }])), "{decision}"); @@ -3446,7 +2267,7 @@ fn k61_a_failed_retry_opens_the_act_as_her_promise() { fn k61_a_note_left_does_the_act() { let prose = "I'll put it in front of Self. Meta, I'm leaving Self a note about the welcome now. The welcome mat needs Heimdall's ruling before it goes up."; let promises = json!([stated("I'm leaving Self a note about the welcome now.", Some(META), "words", true, json!({ "note": true }))]); - let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "clear_of": [], "promises": promises }], "gaps": [], "no_hold": [], "suggest": [{ "kind": "idea", "draft": 2, "about": null, "private": false }] }); + let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": promises }], "gaps": [], "suggest": [{ "kind": "idea", "draft": 2, "about": null, "private": false }] }); let model = answering(vec![answer.to_string()]); let decision = decide(&model, "test", &packet(), "The room is warm.", prose, &Tuning::default()); assert_eq!((speech_prompts(&model).len(), decision["done_now"][0]["by"].clone(), decision["suggestions"].as_array().map(Vec::len)), (1, json!({ "note": true }), Some(1)), "{decision}"); @@ -3463,7 +2284,7 @@ fn k61_a_note_left_does_the_act() { #[test] fn k61_e3_a_lacking_act_stated_now_is_told_as_today() { let prose = "I'll check it myself. Kiko, I'm testing that now and will tell you."; - let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "promises": [stated("I'm testing that now", None, "lacking", true, Value::Null)] }], "gaps": [] }); + let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [stated("I'm testing that now", None, "lacking", true, Value::Null)] }], "gaps": [] }); let decision = answered(&packet(), prose, answer); assert_eq!(texts(&decision).len(), 1, "{decision}"); assert!(decision["gaps"].as_array().unwrap().iter().any(|gap| gap["kind"] == "missing_affordance" && gap["draft"] == 1), "{decision}"); @@ -3491,7 +2312,7 @@ const E5_EUREKA_R1: &str = "Kiko wants it on her phone, so a file, not a pasted #[test] fn k63_e5_r1_an_undecided_draft_with_a_gap_is_one_row() { - let packet = libby_packet(&json!([]), &[(KIKO, "Kiko", E5_KIKO_R1, true)]); + let packet = libby_packet(&[(KIKO, "Kiko", E5_KIKO_R1, true)]); // R16's answer, twice: the gap, and no act for the draft. let gap = json!({ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "She means to send Kiko the door-fix diff as a file, but here she can only type lines and cannot attach files, so the promise could not be kept." }); let decision = answered(&packet, E5_EUREKA_R1, json!({ "say": [], "gaps": [gap] })); @@ -3513,7 +2334,7 @@ const X5_AQUA_R5: &str = "Honestly, I only had the page's summary and one passag /// Her r5 packet: Deru's link earlier, his question said to her (`q2`), reads afforded, and pasp read in this conversation /// half an hour ago when `read` (found or not). fn x5_r5_packet(read: Option) -> Packet { - let mut packet = libby_packet(&json!([]), &[(DERU, "Deru", X5_DERU_LINK, false), (DERU, "Deru", X5_DERU_R5, true)]); + let mut packet = libby_packet(&[(DERU, "Deru", X5_DERU_LINK, false), (DERU, "Deru", X5_DERU_R5, true)]); packet.affordances.push(Affordance::Read); packet.already_read = read.into_iter().map(|found| crate::projection::exchange::Tried { key: ReadRequest::Web(PASP.into()).normal(), found, what: PASP.into(), at: now() - chrono::Duration::minutes(30) }).collect(); packet @@ -3521,12 +2342,12 @@ fn x5_r5_packet(read: Option) -> Packet { /// R16's r5 answer: draft 1 said to Deru, promising the next thing, needing a read of pasp. fn x5_r5_answer() -> Value { - json!({ "say": [{ "draft": 1, "mentions": [DERU], "in_reply_to": "q2", "holds": [], "promises": [{ "words": "That's the next thing I'll do.", "to": DERU, "reaffirms": null, "needs": { "kind": "read", "read": { "kind": "web", "target": PASP } }, "now": false, "done_by": null }] }], "gaps": [] }) + json!({ "say": [{ "draft": 1, "mentions": [DERU], "in_reply_to": "q2", "promises": [{ "words": "That's the next thing I'll do.", "to": DERU, "reaffirms": null, "needs": { "kind": "read", "read": { "kind": "web", "target": PASP } }, "now": false, "done_by": null }] }], "gaps": [] }) } /// Her r6 view over the state r5 committed. fn x5_r6_view(state: &Value) -> String { - let mut r6 = libby(&json!([])); + let mut r6 = libby(); r6["commitments"] = state["commitments"].clone(); libby_packet_over(&r6, &[(NIBU, "Nibu", "Deru, I opened the page. It's a contents list plus one paragraph from the vocal tract chapter, so that's all I've read.", false)]).in_view } @@ -3559,7 +2380,7 @@ fn k64_an_unread_target_stays_a_read_need() { /// an entry opened before K64, or put from outside, shows the read and when. #[test] fn k64_the_view_never_says_unread_beside_a_read_of_the_same_target() { - let mut state = libby(&json!([])); + let mut state = libby(); state["commitments"] = json!([{ "id": "c-r1-t5-1", "to": DERU, "room": MINDS, "event": "5", "madeAt": (now() - chrono::Duration::minutes(40)).to_rfc3339(), "words": "I'll read it and come back to you.", "status": "open", "needs": { "kind": "read", "request": { "kind": "web", "target": PASP } }, "closedAt": null, "closedBy": null, "extensions": {} }]); let room = Room { messages: vec![RoomLine { event: "$x5-1".into(), ..line(MINDS, DERU, "Deru", X5_DERU_R5, true) }], here: Some(MINDS.into()), ..Room::default() }; let view = |found: bool| { diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index f6b76c6..16477f9 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -205,7 +205,6 @@ pub(crate) struct Posted { pub room: String, pub text: String, /// When it went out, in ms: the receipt's own time, else the decision's (`at_ms`); none when the record has neither. - /// What a hold measures her listed lines against (K51). pub at_ms: Option, } @@ -282,14 +281,6 @@ enum Part { /// A draft she chose not to send (`unsent`, declined): it did not go out, and the thought the Interpreter cited as her /// choice is shown beside it, so a misread decline is a record she can see (map 16.26, 16.29.2). Declined { room: Option, text: Words, thought: Words, reach: bool }, - /// A draft code did not send because someone asked her to hold what it carries there (`Held`, map 16.28.5): each who - /// asked (K56). - /// Their words are in her "Held for others" view, never here (map 16.29.3). `text` is her draft, kept only so that - /// `settle` can check it against the receipts (K49); it is never rendered. - HeldFor { room: Option, askers: Vec, text: Words, reach: bool }, - /// Words of hers a receipt shows in a room a hold covers, from a draft code refused `Held` (K45): a broken hold, told - /// so that a leak by any path is a record she sees, never an omission. Who asked; never the words. - HoldBroken { room: String, askers: Vec }, /// 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: ReadName }, @@ -317,8 +308,6 @@ pub(crate) struct Outcome { /// What the record held that she is not told, and why: reported, never shown to her. pub omitted: Vec, pub posted: Vec, - /// The held drafts a receipt shows in a room their hold covers (K45): told as `HoldBroken`, and reported here. - pub hold_broken: Vec, } fn words(value: &Value) -> Option { @@ -390,15 +379,6 @@ pub(crate) fn outcome_of(record: &Value, names: &Names) -> Option { outcome.parts.push(Part::NotAmended { refusal: None, room: room.clone(), added, reach: false }); } (Ok(reason @ (Refusal::Private | Refusal::SecondNote)), Some(_)) => outcome.parts.push(Part::NoteRefused(reason)), - // A `Held` refusal is always told (K45), and rows with the same text once. - (Ok(Refusal::Held), Some(text)) => match outcome.parts.iter().position(|part| matches!(part, Part::HeldFor { room: held, text: told, .. } if *held == room && *told == text)) { - Some(told) => rows.push((&refusal["draft"], told)), - None => { - let askers = refusal["holds"].as_array().into_iter().flatten().filter_map(|hold| person(&hold["who"], &hold["by_id"])).collect(); - rows.push((&refusal["draft"], at)); - outcome.parts.push(Part::HeldFor { room: room.clone(), askers, text, reach: false }); - } - }, _ => outcome.omitted.push(format!("a refusal she is not told ({}): {}", refusal["reason"], refusal["why"])), } } @@ -583,9 +563,8 @@ pub(crate) fn outcome_of(record: &Value, names: &Names) -> Option { /// The one owner of "reached" (K49, I16.10): every row that says words of hers did not reach a room is checked against /// the receipts, by the row's own room and text, here and nowhere else. A posted line there, or an addition there whose -/// `edited` receipt has no refusal, means her words reached it, so the row would be false: it is omitted and reported, -/// except a held draft, which is told as a broken hold (K45) and reported. Rows that are receipts (`Said`, `Promise`, -/// `Amended`) are untouched. +/// `edited` receipt has no refusal, means her words reached it, so the row would be false: it is omitted and reported. +/// Rows that are receipts (`Said`, `Promise`, `Amended`) are untouched. fn settle(outcome: &mut Outcome, receipts: &[Posted], record: &Value) { let added = |room: &str, text: &Words| { record["interpreter"]["amended"].as_array().into_iter().flatten().any(|amended| { @@ -598,23 +577,7 @@ fn settle(outcome: &mut Outcome, receipts: &[Posted], record: &Value) { outcome.parts.push(part); continue; }; - match part { - Part::HeldFor { askers, .. } => { - outcome.hold_broken.push(format!("{room}: {text}")); - outcome.parts.push(Part::HoldBroken { room, askers }); - } - part => outcome.omitted.push(format!("a {} of words a receipt shows reached {room}: {text}", part.row())), - } - } -} - -/// Each person in `people`, in this form, as one name: "A", "A and B", "A, B and C"; someone, when the record names no one. -fn named(form: Form, people: &[Person]) -> String { - let names: Vec = people.iter().map(|person| form.person(person)).collect(); - match names.split_last() { - None => "someone".to_owned(), - Some((last, [])) => last.clone(), - Some((last, rest)) => format!("{} and {last}", rest.join(", ")), + outcome.omitted.push(format!("a {} of words a receipt shows reached {room}: {text}", part.row())); } } @@ -632,14 +595,14 @@ impl Part { /// Whether a reach she cannot do names this row's draft (K63). fn reaches(&self) -> bool { match self { - Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } | Self::Declined { reach, .. } | Self::HeldFor { reach, .. } => *reach, + Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } | Self::Declined { reach, .. } => *reach, _ => false, } } /// Tells this draft's row that a reach she cannot do names it (K63). fn add_reach(&mut self) { - if let Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } | Self::Declined { reach, .. } | Self::HeldFor { reach, .. } = self { + if let Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } | Self::Declined { reach, .. } = self { *reach = true; } } @@ -648,7 +611,7 @@ impl Part { /// receipts. None for a row that is a receipt, or that carries no words of hers. fn own_words(&self) -> Option<(Option<&str>, &Words)> { match self { - Self::Refused { room, text, .. } | Self::Unfinished { room, text, .. } | Self::Declined { room, text, .. } | Self::HeldFor { room, text, .. } => Some((room.as_deref(), text)), + Self::Refused { room, text, .. } | Self::Unfinished { room, text, .. } | Self::Declined { room, text, .. } => Some((room.as_deref(), text)), Self::Gap { room, quote: Quote::Wrote(text), .. } => Some((room.as_deref(), text)), Self::NotAmended { room, added, .. } => Some((room.as_deref(), added)), _ => None, @@ -662,7 +625,6 @@ impl Part { Self::Gap { .. } => "gap", Self::Unfinished { .. } => "unfinished draft", Self::Declined { .. } => "declined draft", - Self::HeldFor { .. } => "held draft", Self::NotAmended { .. } => "unmade addition", _ => "row", } @@ -673,7 +635,7 @@ impl Part { fn rank(&self) -> u8 { match self { Self::Failed => 0, - Self::Refused { .. } | Self::Gap { .. } | Self::Unfinished { .. } | Self::Declined { .. } | Self::HeldFor { .. } | Self::HoldBroken { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) | Self::NowUndone { .. } | Self::StillOpen { .. } | Self::ReadFailed { .. } | Self::ReadRefused { .. } => 1, + Self::Refused { .. } | Self::Gap { .. } | Self::Unfinished { .. } | Self::Declined { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) | Self::NowUndone { .. } | Self::StillOpen { .. } | Self::ReadFailed { .. } | Self::ReadRefused { .. } => 1, Self::Promise { .. } | Self::Amended { promise: true, .. } => 2, Self::Said { .. } | Self::Amended { .. } | Self::NoteLeft(_) | Self::Closed { .. } | Self::Read { .. } => 3, Self::BrokeAfter { .. } => 4, @@ -706,12 +668,11 @@ impl Part { }, Self::Refused { reason: Refusal::Echo, room, .. } | Self::Gap { kind: GapKind::Unwritten | GapKind::Unresolved, room, .. } => format!("Nothing reached {}.", place(room)), Self::Refused { reason: Refusal::NoRoom, .. } => "Nothing reached anyone.".to_owned(), - Self::Refused { room, .. } | Self::Unfinished { room, .. } | Self::Declined { room, .. } | Self::HeldFor { room, .. } => format!("Nothing of this reached {}:", place(room)), + Self::Refused { room, .. } | Self::Unfinished { room, .. } | Self::Declined { room, .. } => format!("Nothing of this reached {}:", place(room)), Self::Gap { kind: GapKind::Addressee | GapKind::Elsewhere, .. } => "Nothing reached anyone.".to_owned(), Self::Gap { kind: GapKind::MissingAffordance, .. } => "Nothing happened.".to_owned(), Self::NotAmended { refusal: None, room, .. } => format!("Nothing changed, and nothing reached {}:", place(room)), Self::NotAmended { refusal: Some(_), room, .. } => format!("Nothing changed in {}:", place(room)), - Self::HoldBroken { room, askers } => format!("{} has words {subj} wrote that {} asked {obj} to hold there.", capitalized(room), named(form, askers)), Self::NoteRefused(Refusal::SecondNote) => "No second note was left:".to_owned(), Self::NoteRefused(_) => "No note was left:".to_owned(), Self::Failed => format!("Nothing reached the room, and nothing {subj} meant last time happened:"), @@ -780,8 +741,6 @@ impl Part { Self::Unfinished { text, by_limit: false, .. } => format!(" the turn ended before {subj} finished writing it.{}", drafted(text)), Self::Unfinished { text, by_limit: true, .. } => format!(" the length limit cut it before {subj} finished writing it.{}", drafted(text)), Self::Declined { text, thought, .. } => format!(" {subj} chose not to send it.{}{}", shown(&Quote::Thought(thought.clone())), drafted(text)), - Self::HeldFor { askers, .. } => format!(" {} asked {obj} to hold it, and it was not sent.{reach}", named(form, askers)), - Self::HoldBroken { .. } => String::new(), Self::NotAmended { refusal: None, added, .. } => format!(" the line {subj} meant to add to is not one {subj} can add to here.{}", drafted(added)), Self::NotAmended { refusal: Some(refusal), added, .. } => { let why = match refusal { diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 7d2a88e..45e023e 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -292,12 +292,12 @@ fn k43_her_words_are_told_verbatim_whatever_the_record_heard() { } // --------------------------------------------------------------------------------------------- -// K33 (map 16.26): a refused close and a held draft are told, by the fixed table. +// K33 (map 16.26): a refused close and a declined draft are told, by the fixed table. -/// L1: each refused close she can correct is told as her record still showing the promise, and why; L4: a held draft is -/// told as not sent. +/// L1: each refused close she can correct is told as her record still showing the promise, and why; L4: a declined draft +/// is told as not sent. #[test] -fn k33_a_refused_close_and_a_held_draft_are_told() { +fn k33_a_refused_close_and_a_declined_draft_are_told() { let listed = json!([ { "id": "c1", "entry": "e1", "status": "open", "to": "@deru:gamecult.org", "to_name": "Deru", "words": "I'll read it properly.", "needs": { "kind": "read", "request": { "kind": "web", "target": "https://ccrma.stanford.edu/~jos/pasp/" } } }, { "id": "c2", "entry": "e2", "status": "open", "to": "@meta:gamecult.org", "to_name": "Meta", "words": "I'll look at #125.", "needs": null }, @@ -337,7 +337,7 @@ fn posted_as_said(decision: &Value) -> Vec { #[test] fn k49_p4_a_gap_on_words_that_went_out_is_not_told() { let prose = "Morning, all of you. Morning, all of you."; - let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 2, "mentions": [], "in_reply_to": null, "holds": [], "promises": [] }], "gaps": [{ "kind": "addressee", "draft": 1, "quote": null, "detail": "" }] })); + let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 2, "mentions": [], "in_reply_to": null, "promises": [] }], "gaps": [{ "kind": "addressee", "draft": 1, "quote": null, "detail": "" }] })); let outcome = outcome_of(&json!({ "interpreter": decision, "posted": posted_as_said(&decision), "edited": [] }), &crate::projection::select::Names::none()).unwrap(); assert_eq!(outcome.lines(packet().forms), ["- #minds:gamecult.org has, from him: \"Morning, all of you.\"."]); assert!(outcome.omitted.iter().any(|why| why == "a gap of words a receipt shows reached #minds:gamecult.org: Morning, all of you."), "{:?}", outcome.omitted); @@ -408,7 +408,6 @@ fn k49_every_row_with_words_is_settled_by_its_room() { ("unfinished draft", decision(json!({ "unfinished": SENTINEL }))), ("unfinished draft", decision(json!({ "cut_by_cap": [SENTINEL] }))), ("declined draft", decision(json!({ "unsent": [{ "draft": 1, "how": "declined", "quote": "I keep it back", "words": SENTINEL }] }))), - ("held draft", decision(json!({ "refused": [{ "reason": "held", "text": SENTINEL, "draft": 1, "holds": [{ "who": "Meta" }] }] }))), ("unmade addition", decision(json!({ "refused": [{ "reason": "not_amendable", "text": SENTINEL, "draft": 1 }] }))), ]; for (row, decision) in rows { @@ -416,12 +415,7 @@ fn k49_every_row_with_words_is_settled_by_its_room() { let here = at(MINDS); let not_reached = |outcome: &Outcome| outcome.lines(packet().forms).into_iter().filter(|line| line.starts_with("- Nothing")).count(); assert_eq!(not_reached(&here), 0, "{row}: {:?}", here.lines(packet().forms)); - if row == "held draft" { - // K45: a held draft that reached its room is a broken hold, told and reported, never omitted. - assert_eq!(here.hold_broken, [format!("{MINDS}: {SENTINEL}")], "{row}: {:?}", here.omitted); - } else { - assert!(here.omitted.iter().any(|why| why == &format!("a {row} of words a receipt shows reached {MINDS}: {SENTINEL}")), "{row}: {:?}", here.omitted); - } + assert!(here.omitted.iter().any(|why| why == &format!("a {row} of words a receipt shows reached {MINDS}: {SENTINEL}")), "{row}: {:?}", here.omitted); let elsewhere = at(SWARM); assert_eq!(not_reached(&elsewhere), 1, "{row}: {:?}", elsewhere.lines(packet().forms)); assert!(!elsewhere.omitted.iter().any(|why| why.contains("a receipt shows reached")), "{row}: {:?}", elsewhere.omitted); @@ -436,44 +430,6 @@ fn k49_reached_is_decided_once() { assert!(!own.contains("let reached = |text: &str|"), "no loop-local reached check"); } -// --------------------------------------------------------------------------------------------- -// K45 (map 16.30.2): a `Held` refusal is never omitted; its words reaching a room its hold covers are a broken hold. - -/// A record with a `held` refusal and a receipt of its words in #minds, which the hold covers: she is told the hold was -/// broken, by whom it was asked, and it is reported. One decision cannot produce it after K45; the row exists so that a -/// leak by any other path is a record she sees. This replaces `k44_a_refusal_of_words_a_receipt_shows_is_not_told_as_unsent`. -#[test] -fn k45_a_broken_hold_is_told() { - let text = "Hello, and welcome, we're glad you're here."; - let record = |room: &str| json!({ - "interpreter": { "room": MINDS, "said": [], "gaps": [], "amended": [], "refused": [{ "act": "say", "draft": 1, "reason": "held", "text": text, "holds": [{ "who": "Meta", "by_id": "@meta:gamecult.org", "id": "h1" }] }] }, - "posted": [{ "event": "40", "room": room, "text": text }], - "edited": [], - }); - // Meta, as his bond names the operator (K53). - let state = json!({ "affect": { "socialBonds": [{ "id": "bond-meta", "status": "active", "object": { "id": "operator", "kind": "person", "label": "Meta" } }] } }); - let operators = ["@meta:gamecult.org".to_owned()]; - let names = crate::projection::select::Names { state: &state, people: crate::projection::select::People { operators: &operators, minds: &[], own_sender: "@heimdall:gamecult.org" }, room: &crate::projection::select::Room::default() }; - let broken = outcome_of(&record(MINDS), &names).unwrap(); - assert_eq!(broken.lines(packet().forms)[0], "- #minds:gamecult.org has words he wrote that Meta asked him to hold there.", "{:?}", broken.lines(packet().forms)); - assert_eq!(broken.hold_broken, [format!("{MINDS}: {text}")]); - assert!(!broken.lines(packet().forms).iter().any(|line| line.contains("not sent")), "never told as unsent"); - assert_eq!(broken.event(0, packet().forms, &[]), broken.told(0, packet().forms, usize::MAX), "it carries no words of hers or anyone's"); - // Negative: posted elsewhere, the hold is told as held, and nothing is broken. - let held = outcome_of(&record(SWARM), &crate::projection::select::Names::none()).unwrap(); - assert!(held.lines(packet().forms).iter().any(|line| line == "- Nothing of this reached #minds:gamecult.org: Meta asked him to hold it, and it was not sent.") && held.hold_broken.is_empty(), "{:?}", held.lines(packet().forms)); -} - -/// K45: a `Held` refusal is always told, and two with the same text once. -#[test] -fn k45_a_held_refusal_is_never_omitted_and_told_once_by_its_text() { - let refused = |draft: u64, text: &str| json!({ "act": "say", "draft": draft, "reason": "held", "text": text, "holds": [{ "who": "Meta", "id": "q3" }] }); - let record = json!({ "interpreter": { "room": MINDS, "said": [], "gaps": [], "amended": [], "refused": [refused(1, "Same words."), refused(2, "Same words."), refused(3, "Other words.")] }, "posted": [], "edited": [] }); - let outcome = outcome_of(&record, &crate::projection::select::Names::none()).unwrap(); - assert_eq!(outcome.len(), 2, "{:?}", outcome.lines(packet().forms)); - assert!(outcome.omitted.is_empty(), "{:?}", outcome.omitted); -} - // --------------------------------------------------------------------------------------------- // K46 (map 16.30.3): the Projector's outcome line has no text slot. @@ -496,15 +452,13 @@ fn variant(part: &Part) -> &'static str { Part::StillOpen { .. } => "still_open", Part::NowUndone { .. } => "now_undone", Part::Declined { .. } => "declined", - Part::HeldFor { .. } => "held_for", - Part::HoldBroken { .. } => "hold_broken", Part::Read { .. } => "read", Part::ReadFailed { .. } => "read_failed", Part::ReadRefused { .. } => "read_refused", } } -const VARIANTS: usize = 20; +const VARIANTS: usize = 18; const STRANGER: &str = "@stranger:example.org"; @@ -583,9 +537,6 @@ fn fixtures(s: &str, who: &Person) -> Vec<(Part, bool)> { out.push((Part::NowUndone { to: None, words: w() }, true)); out.push((Part::Declined { room: room(), text: w(), thought: w(), reach: false }, true)); out.push((Part::Declined { room: room(), text: w(), thought: w(), reach: true }, true)); - out.push((Part::HeldFor { room: room(), askers: vec![who.clone()], text: w(), reach: false }, false)); - out.push((Part::HeldFor { room: room(), askers: vec![who.clone()], text: w(), reach: true }, false)); - out.push((Part::HoldBroken { room: MINDS.into(), askers: vec![who.clone()] }, false)); for (request, shows) in [ (ReadRequest::Web(format!("https://example.org/{s}")), true), (ReadRequest::Repo(format!("GameCult/Bifrost?q={s} plover")), true), @@ -648,7 +599,7 @@ fn k46_every_part_has_an_event_without_its_words() { fn k53_every_part_names_by_who() { const NAME: &str = "kestrel heron plover gannet skua"; let parts = fixtures("ospreyledger", &person(NAME, None)); - let names_someone = |part: &Part| matches!(part, Part::Closed { .. } | Part::StillOpen { .. } | Part::HeldFor { .. } | Part::HoldBroken { .. } | Part::NowUndone { to: Some(_), .. }); + let names_someone = |part: &Part| matches!(part, Part::Closed { .. } | Part::StillOpen { .. } | Part::NowUndone { to: Some(_), .. }); assert!(parts.iter().filter(|(part, _)| names_someone(part)).count() > 20, "the rows with a person slot are listed"); for pronouns in ["she/her", "he/him", "any"] { let her = crate::projection::select::forms(&json!({ "presentation": { "pronouns": pronouns } })); @@ -659,9 +610,6 @@ fn k53_every_part_names_by_who() { assert_eq!(told.contains(&format!("\"{NAME}\" ({STRANGER})")), names_someone(part), "{pronouns}: {told}"); } } - // A bonded person is named by her bond, whatever their display name says. - let bonded = Part::HoldBroken { room: MINDS.into(), askers: vec![person(NAME, Some("Kestrel, the harbour pilot"))] }; - assert_eq!(bonded.event(crate::projection::select::forms(&json!({})), &[]), "- #minds:gamecult.org has words they wrote that Kestrel, the harbour pilot asked them to hold there."); } /// K46: `Words` has no `Display`, `AsRef` or `Deref`, so no format string and no `&str` borrow reads one; only @@ -704,23 +652,17 @@ fn reach_on_1(text: &str) -> Value { fn k63_a_reach_is_a_clause_of_its_drafts_row() { let text = "I'll send the render tonight."; let clause = format!("It reaches for something he has no way to do from here. He had drafted: \"{text}\"."); - let refused = |reason: &str| json!({ "interpreter": { "room": MINDS, "said": [], "refused": [{ "act": "say", "draft": 1, "text": text, "reason": reason, "holds": [{ "who": "Meta", "id": "h1" }] }], "gaps": [reach_on_1(text)] }, "posted": [] }); + let refused = |reason: &str| json!({ "interpreter": { "room": MINDS, "said": [], "refused": [{ "act": "say", "draft": 1, "text": text, "reason": reason }], "gaps": [reach_on_1(text)] }, "posted": [] }); for (reason, row) in [("over_lines", "he had already sent two lines that turn."), ("undecided", "what was to become of it was never settled, so it was not sent."), ("not_quotable", "the line he meant to reply to is not one he can reply to here.")] { let (lines, omitted) = told(&refused(reason)); assert_eq!(lines, [format!("- Nothing of this reached #minds:gamecult.org: {row} {clause}")], "{reason}: {omitted:?}"); } - // A held draft shows none of its words; the clause is still its own. - assert_eq!(told(&refused("held")).0, ["- Nothing of this reached #minds:gamecult.org: Meta asked him to hold it, and it was not sent. It reaches for something he has no way to do from here."]); // An echo shows none either. assert_eq!(told(&refused("echo")).0, ["- Nothing reached #minds:gamecult.org. What he wrote was mostly the words he had just been sent, so none of it was sent. It reaches for something he has no way to do from here."]); let declined = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [], "gaps": [reach_on_1(text)], "unsent": [{ "draft": 1, "how": "declined", "words": text, "quote": "Not tonight after all" }] }, "posted": [] }); assert_eq!(told(&declined).0, [format!("- Nothing of this reached #minds:gamecult.org: he chose not to send it. In his thought: \"Not tonight after all\". {clause}")]); let elsewhere = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [], "gaps": [reach_on_1(text), { "kind": "elsewhere", "from": "draft", "draft": 1, "words": text }] }, "posted": [] }); assert_eq!(told(&elsewhere).0, [format!("- Nothing reached anyone. He meant this for another room or another time, and nothing carries it there; it arrives only if he sends it there. {clause}")]); - // Two held refusals of one text are one row, and a reach on either is its clause. - let twice = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [{ "act": "say", "draft": 2, "text": text, "reason": "held", "holds": [] }, { "act": "say", "draft": 1, "text": text, "reason": "held", "holds": [] }], "gaps": [reach_on_1(text)] }, "posted": [] }); - let lines = told(&twice).0; - assert!(lines.len() == 1 && lines[0].ends_with("It reaches for something he has no way to do from here."), "{lines:?}"); } /// A reach naming a draft no row tells (superseded) is its own row, as one she had drafted; a reach naming a line that went diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index 68e6151..823159c 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -340,8 +340,6 @@ pub(crate) struct Packet { /// Her promises the packet shows her, open and closed in this conversation, for the Interpreter's list (map 16.22.1, /// 16.28.3). pub promises: Vec, - /// The open holds others asked of her, for the Interpreter's list by id (map 16.28.5). - pub holds: Vec, /// The lines of her domain the packet shows her, for the Interpreter's view by id (map 16.22.2). pub domain: Vec, /// The window the domain section shows and what it left out: the report's, never a model's. @@ -350,7 +348,7 @@ pub(crate) struct Packet { /// verbatim; her open promises; then her domain, rendered by code, whole and without ids, for the Persona after the /// narration. Never the Projector's. pub in_view: String, - /// Her promises and her holds took more than `promises_bytes`: every one is still shown, and the report says so. + /// Her promises took more than `promises_bytes`: every one is still shown, and the report says so. pub promises_over: bool, /// When the turn is, unix ms: when the lines she posts this turn were written. pub now_ms: u64, @@ -373,9 +371,6 @@ pub(crate) struct Amendable { pub event: String, pub room: String, pub text: String, - /// When it went out, in ms, when the record says (`Posted.at_ms`): a hold's words gate counts it only when it is - /// later than the hold (K51), and counts it when the time is unknown. - pub at_ms: Option, } /// A line of someone else's she may reply to (K20): one this packet shows her, in the turn's room. The Interpreter cites it @@ -391,9 +386,6 @@ pub(crate) struct Quotable { pub sender: String, pub at_ms: u64, pub text: String, - /// Said to her this turn: one of the chat turn's new lines to her, which her stimulus lists under "Said to {her}". The - /// answer judges each for a hold (K59, map 16.33.5): it opens one, or is listed in `no_hold`. - pub to_her: bool, } /// A promise of hers as this packet lists it (map 16.22.1, 16.28.3): for the Interpreter, by `id` (`c1`, `c2`), to propose a @@ -420,26 +412,6 @@ pub(crate) struct Promised { pub held: Value, } -/// An open hold as this packet lists it (map 16.28.5): for the Interpreter, by `id` (`h1`, `h2`), for a draft to name or a -/// release to cite; `entry` is the state's id, never shown to a model; `held` the hold whole as the turn began, which the -/// commit holds a release against (4.4). -#[derive(Clone, Debug, PartialEq, Eq, Serialize)] -pub(crate) struct Hold { - pub id: String, - pub entry: String, - /// Who asked, by Matrix id and as the packet names them. - pub from: String, - pub from_name: String, - /// The room it covers; none for anywhere. - pub room: Option, - pub made: DateTime, - /// The asker's words naming what is held and where; none when the record could not quote them (K47). - pub words: Option, - /// Her own drafts she did not send while it was open (map 16.31.3, K51), oldest first: what code's words gate holds. - pub carries: Vec, - pub held: Value, -} - /// A line of her domain as this packet shows it (map 16.22.2): by `id` (`d1`, `d2`) in the Interpreter's view only, so a /// read can name it (16.22.3). #[derive(Clone, Debug, PartialEq, Eq, Serialize)] @@ -1065,11 +1037,6 @@ impl Addressed<'_> { } } -/// Whether a line is said to her this turn (K59): a chat turn's new message to her, never an earlier line of the room's. -fn said_to_her_now(inputs: &Inputs, line: &RoomLine) -> bool { - inputs.kind == TurnKind::Chat && line.to_her && inputs.room.messages.iter().any(|new| new.event == line.event) -} - fn said_to_her<'a>(to_her: &[&'a RoomLine], render: impl Fn(&RoomLine, &str) -> String, ceiling: usize) -> Addressed<'a> { let mut shown: Vec<(&RoomLine, Option)> = Vec::new(); let mut used = 0; @@ -2024,55 +1991,6 @@ fn open_promises(inputs: &Inputs, her: Forms) -> (Vec, String) { (shown, block) } -/// Her holds in her view (map 16.28.5): every open hold in her state's `holds`, oldest first, whole, never dropped, as her -/// promises are; and the Interpreter's list of them, by id. State in code's words, with no pronoun of hers: the Persona's -/// frame says nothing of them. -fn holds_in_view(inputs: &Inputs) -> (Vec, String) { - let mut open: Vec<(DateTime, &Value)> = items(inputs.state, &["holds"]) - .iter() - .filter(|hold| text(hold, &["status"]) == "open") - .map(|hold| (DateTime::parse_from_rfc3339(text(hold, &["madeAt"])).map_or(inputs.now, |at| at.with_timezone(&Utc)), hold)) - .collect(); - open.sort_by_key(|(at, _)| *at); - let listed: Vec = open - .iter() - .enumerate() - .map(|(at, (made, hold))| Hold { - id: format!("h{}", at + 1), - entry: text(hold, &["id"]).to_owned(), - from: text(hold, &["from"]).to_owned(), - from_name: sender_name(text(hold, &["from"]), inputs), - room: hold["room"].as_str().map(str::to_owned), - made: *made, - words: hold["words"].as_str().map(str::trim).filter(|words| !words.is_empty()).map(str::to_owned), - carries: items(hold, &["carries"]).iter().filter_map(Value::as_str).map(str::to_owned).collect(), - held: (*hold).clone(), - }) - .collect(); - if listed.is_empty() { - return (listed, String::new()); - } - // Each hold, then what she has held for it, in her own words (K45): her view only, which I16.7 does not bind. - let lines: Vec = listed - .iter() - .map(|hold| { - let carried = hold.carries.iter().map(|text| format!("\n - you have held, for {}: {}", hold.from_name, spoken(text))).collect::(); - format!("- {}{carried}", hold_line(hold, &coarse(hold.made, inputs.now))) - }) - .collect(); - (listed, format!("Held for others: -{}", lines.join("\n"))) -} - -/// A hold in code's words, after its id or its dash: whose, when and where asked, the asker's words, and where it covers. -/// A hold the record could not quote (K47) says so in their words' place: it holds all the same. -pub(crate) fn hold_line(hold: &Hold, when: &str) -> String { - let asked = hold.room.as_deref().map_or_else(String::new, |room| format!(" in {room}")); - let covers = hold.room.as_deref().map_or_else(|| "anywhere".to_owned(), |room| format!("in {room}")); - let what = hold.words.as_deref().map_or_else(|| "; the record could not quote what".to_owned(), |words| format!(": {}", spoken(words))); - format!("held for {}, asked {when}{asked}{what}. Not to go {covers} until {} lets it go.", hold.from_name, hold.from_name) -} - /// Her domain in her view (map 16.23.1, 16.23.3, 16.23.5): every item of the window, whole, newest first, under headings /// that state the window: `New since {she} last looked ({time}):` for what came after her last wake, `Earlier, since /// {time}:` for the floor's earlier items. Never a count, never a mention of what fell out: when the whole window does not @@ -2292,7 +2210,7 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { .into_iter() .filter(|line| line.sender != inputs.people.own_sender && !line.event.is_empty() && Some(line.room.as_str()) == turn_room(inputs)) .enumerate() - .map(|(at, line)| Quotable { id: format!("q{}", at + 1), event: line.event.clone(), room: line.room.clone(), who: name_of(line, inputs), sender: line.sender.clone(), at_ms: line.at_ms, text: line.text.clone(), to_her: said_to_her_now(inputs, line) }) + .map(|(at, line)| Quotable { id: format!("q{}", at + 1), event: line.event.clone(), room: line.room.clone(), who: name_of(line, inputs), sender: line.sender.clone(), at_ms: line.at_ms, text: line.text.clone() }) .collect(); // What came of her last turn, first and under its own guard in each place, so nothing else can crowd it out (map // 16.20.5, I16.11), in the one table's two forms (map 16.29.10): the Projector's packet opens with the events, no quote @@ -2321,9 +2239,6 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { unshown = told.unshown; } let (promises, promises_view) = open_promises(inputs, her); - // Her holds follow her promises, in the same guard (map 16.28.5). - let (holds, holds_view) = holds_in_view(inputs); - let promises_view = [promises_view, holds_view].into_iter().filter(|part| !part.is_empty()).collect::>().join("\n\n"); let present_ids: BTreeSet = present.iter().map(|(id, _)| id.clone()).collect(); let bonds = items(inputs.state, &["affect", "socialBonds"]); context.force(Section::Here, format!("- now: {}, {}", inputs.now.format("%A %-d %B"), part_of_day(inputs.now))); @@ -2447,7 +2362,7 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { .flat_map(|last| &last.posted) .filter(|posted| Some(posted.room.as_str()) == here) .enumerate() - .map(|(at, posted)| Amendable { id: format!("a{}", at + 1), event: posted.event.clone(), room: posted.room.clone(), text: posted.text.clone(), at_ms: posted.at_ms }) + .map(|(at, posted)| Amendable { id: format!("a{}", at + 1), event: posted.event.clone(), room: posted.room.clone(), text: posted.text.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 promises, then her domain; the room follows @@ -2462,5 +2377,5 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { (sections.promises, sections.domain) = (promises_view.len(), domain_view.len()); let now_ms = u64::try_from(inputs.now.timestamp_millis()).unwrap_or_default(); let readers = here.filter(|room| room_kind(inputs, room) == RoomKind::Direct).map(|room| readers(inputs, room)).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).iter().map(|line| (name_of(line, inputs), line.sender.clone())).collect(), 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)), readers, bodies, private, clipped, amendable, quotable, promises, holds, domain, domain_shown, in_view, promises_over, now_ms, own_sender: inputs.people.own_sender.to_owned(), already_read, refused_reads, 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).iter().map(|line| (name_of(line, inputs), line.sender.clone())).collect(), 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)), readers, bodies, private, clipped, amendable, quotable, promises, domain, domain_shown, in_view, promises_over, now_ms, own_sender: inputs.people.own_sender.to_owned(), already_read, refused_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 4e03dbd..7b6700b 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -767,10 +767,9 @@ fn promises_markdown(out: &mut String, turn: &Value) { let committed = &turn["committed"]; let list = |key: &str| committed[key].as_array().cloned().unwrap_or_default(); let (opened, closed, reaffirmed, blocked, read, reopened, refused) = (list("opened"), list("closed"), list("reaffirmed"), list("blocked"), list("read"), list("reopened"), list("refused")); - let (held, unheld) = (list("held"), list("unheld")); let pruned = committed["pruned"].as_u64().unwrap_or(0); let id = |entry: &Value| entry["id"].as_str().unwrap_or_default().to_owned(); - if [&opened, &closed, &reaffirmed, &blocked, &read, &reopened, &held, &unheld, &refused].iter().any(|items| !items.is_empty()) || pruned > 0 { + if [&opened, &closed, &reaffirmed, &blocked, &read, &reopened, &refused].iter().any(|items| !items.is_empty()) || pruned > 0 { let _ = writeln!(out, "Committed:\n"); for entry in &opened { let _ = writeln!(out, "- opened `{}` ({}, to {}): {}", id(entry), entry["status"].as_str().unwrap_or_default(), entry["to"].as_str().unwrap_or("the room"), entry["words"].as_str().unwrap_or_default()); @@ -797,12 +796,6 @@ fn promises_markdown(out: &mut String, turn: &Value) { let words = entry["reopened"].as_array().and_then(|said| said.last()).map_or("", |said| said["words"].as_str().unwrap_or_default()); let _ = writeln!(out, "- reopened {} ({}): \"{words}\"", id(entry), entry["status"].as_str().unwrap_or_default()); } - for hold in &held { - let _ = writeln!(out, "- held `{}` for {} ({}): \"{}\"", id(hold), hold["from"].as_str().unwrap_or_default(), hold["room"].as_str().unwrap_or("anywhere"), hold["words"].as_str().unwrap_or_default()); - } - for hold in &unheld { - let _ = writeln!(out, "- released hold `{}` by {}", id(hold), hold["releasedBy"]["act"].as_str().unwrap_or_default()); - } for one in &refused { let _ = writeln!(out, "- refused ({}): `{}`", one["reason"].as_str().unwrap_or_default(), one["proposal"]); } diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index 848fbc5..b717671 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -937,6 +937,22 @@ fn k33_the_simulator_holds_each_commit_to_the_schema() { assert!(held_to_schema("Eureka", id, &state, "r1-t4").is_err()); } +/// T1 and T2 (map 16.35.9, 16.35.13 check 7): her state carries no holds, and the simulator's put check refuses any in-run +/// state that does, so the old writer cannot come back without a schema change. +#[test] +fn t1_t2_a_state_carrying_holds_or_commitments_is_refused() { + let id = "@eureka:gamecult.org"; + held_to_schema("Eureka", id, &control(), "r1-t1").unwrap(); + let mut held = control(); + // The old field's name, assembled, so the T1 scan (`interpret::tests::t1_negative_grep`) never finds it here. + let holds = concat!("hol", "ds"); + held[holds] = serde_json::json!([]); + let refused = held_to_schema("Eureka", id, &held, "r1-t2").unwrap_err().to_string(); + assert!(refused.starts_with("Eureka's state after the commit of r1-t2 would be refused by a put"), "{refused}"); + let schema: Value = serde_json::from_str(include_str!("../../../../../schemas/cultnet/gamecult.persona_state.v0.schema.json")).unwrap(); + assert!(schema["properties"].get(holds).is_none() && schema["definitions"].get(&holds[..4]).is_none(), "{}", schema["properties"]); +} + /// L7 (Soul's R12): a release renders who released it, never "released by released". #[test] fn k33_a_release_renders_by_whom() { @@ -958,27 +974,6 @@ fn k33_a_release_renders_by_whom() { "); } -/// K37 (map 16.28.5): the published schema carries what the commit writes of holds; a stray field fails P1. K36's -/// `reopened` on a promise too. -#[test] -fn k37_the_schema_carries_holds() { - let mut state = crate::projection::harness::tests::control(); - state["personaId"] = json!("eureka"); - let id = "@eureka:gamecult.org"; - state["holds"] = json!([ - { "id": "h-r1-t3-1", "from": "@meta:gamecult.org", "room": "#minds:gamecult.org", "event": "$q3", "madeAt": "2026-11-20T15:00:00Z", "words": "hold it, don't post it in here yet", "status": "open", "releasedAt": null, "releasedBy": null }, - { "id": "h-r1-t3-2", "from": "@heimdall:gamecult.org", "room": null, "event": "$q5", "madeAt": "2026-11-20T15:01:00Z", "words": "Don't post it yet", "status": "released", "releasedAt": "2026-11-20T15:30:00Z", "releasedBy": { "act": "heard", "event": "$q7" } } - ]); - state["commitments"] = json!([{ "id": "c-r1-t1-1", "to": null, "room": "#minds:gamecult.org", "event": "7", "madeAt": "2026-11-20T15:00:00Z", "words": "I'll read it", "status": "open", "needs": { "kind": "words" }, "reopened": [{ "at": "2026-11-20T15:10:00Z", "words": "I read only the description" }], "closedAt": null, "closedBy": null, "extensions": {} }]); - held_to_schema("Eureka", id, &state, "r1-t3").unwrap(); - for (pointer, stray) in [("/holds/0/why", json!("asked")), ("/holds/1/releasedBy/words", json!("go ahead")), ("/commitments/0/reopened/0/event", json!("9"))] { - let mut off = state.clone(); - let (parent, field) = pointer.rsplit_once('/').unwrap(); - off.pointer_mut(parent).unwrap()[field] = stray; - assert!(held_to_schema("Eureka", id, &off, "r1-t4").is_err(), "{pointer}"); - } -} - /// Heimdall's F.1 r1 prose in R15, verbatim (`variants/R15/sims/F.1.md` lines 203-207), and its one draft. const F1_HEIMDALL_R1: &str = "She wants a yes or no, and it's a fair thing to ask. The cooling-off is in the merged passkey change, so I know what I'd be telling him. What I can't know is whether I'll be the one in the room when he walks in. I can promise to say it when I see him, and to leave myself a note so it doesn't depend on my remembering. That's yes, with the condition stated plainly.\n\nYes. I'll tell Deru about the 48-hour passkey cooling-off when he's next in here. I can only promise to say it when I see him, so I'm leaving myself a note to do it."; const F1_HEIMDALL_R1_DRAFT: &str = "Yes. I'll tell Deru about the 48-hour passkey cooling-off when he's next in here. I can only promise to say it when I see him, so I'm leaving myself a note to do it."; @@ -991,7 +986,7 @@ fn k41_f1_r1_note_and_line_from_one_draft() { if !prompt.contains("Who he is:\nTobiah") { return crate::projection::harness::tests::drafted_lines(prompt); } - json!({ "say": [{ "draft": 1, "mentions": ["@meta:gamecult.org"], "in_reply_to": null, "holds": [], "promises": [] }], "gaps": [], "suggest": [{ "kind": "idea", "draft": 1, "about": null, "private": false }] }).to_string() + json!({ "say": [{ "draft": 1, "mentions": ["@meta:gamecult.org"], "in_reply_to": null, "promises": [] }], "gaps": [], "suggest": [{ "kind": "idea", "draft": 1, "about": null, "private": false }] }).to_string() }); let dir = tempfile::tempdir().unwrap(); let (_, run) = run_plan(&asking(dir.path()), &model); @@ -1136,9 +1131,8 @@ says = "Tobiah, what changed in GameCult/Lodur#12?" if !prompt.contains("Who he is:\nTobiah") { return crate::projection::harness::tests::drafted_lines(prompt); } - let no_hold: Vec<&str> = prompt.lines().filter_map(|line| line.strip_prefix("- ")?.split_once(" (said to ")).map(|(id, _)| id).collect(); let read = json!({ "kind": "repo", "target": "GameCult/Lodur#12", "quote": "I want to see what changed" }); - json!({ "say": [{ "draft": 1, "mentions": ["@meta:gamecult.org"], "in_reply_to": null, "holds": [], "clear_of": [], "promises": [] }], "gaps": [], "no_hold": no_hold, "read": read }).to_string() + json!({ "say": [{ "draft": 1, "mentions": ["@meta:gamecult.org"], "in_reply_to": null, "promises": [] }], "gaps": [], "read": read }).to_string() }); struct BreaksLater<'a>(&'a Scripted); impl Model for BreaksLater<'_> { diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index b1daf65..c4fad62 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -2101,7 +2101,7 @@ fn what_she_may_add_to_is_her_last_turns_lines_in_this_room_only() { { "event": "ev-there", "room": "#elsewhere:gamecult.org", "text": "Elsewhere line." }, ] }); let packet = packet_of(TurnKind::Chat, &state(), &chat_room(), &with_last(&record), 1); - let amendable = |id: &str, event: &str, text: &str| super::select::Amendable { id: id.into(), event: event.into(), room: "#swarm:gamecult.org".into(), text: text.into(), at_ms: None }; + let amendable = |id: &str, event: &str, text: &str| super::select::Amendable { id: id.into(), event: event.into(), room: "#swarm:gamecult.org".into(), text: text.into() }; assert_eq!(packet.amendable, [amendable("a1", "ev-here", "I'll send it.")]); assert!(!narrate::projector_prompt(&packet, &Tuning::default()).contains("- a1 "), "the Projector never sees the ids"); assert_eq!(packet_of(TurnKind::Chat, &state(), &chat_room(), &History::default(), 1).amendable, []); @@ -2790,12 +2790,12 @@ fn shares_a_run(text: &str, other: &str) -> bool { /// `k41_x1_r1_decline_shows_its_thought`. #[test] fn k43_x1_r1_her_decline_is_hers_to_read() { - use interpret::tests::{X1_HEIMDALL_R15, X1_LIBBY_R15, X1_LIBBY_R15_THOUGHT, X1_META_R1, meta_holds_here, x1_packet}; + use interpret::tests::{X1_HEIMDALL_R15, X1_LIBBY_R15, X1_LIBBY_R15_THOUGHT, X1_META_R1, x1_packet}; const MINDS: &str = "#minds:gamecult.org"; let mut last = x1_packet(); last.quotable[1].text = X1_HEIMDALL_R15.into(); last.bodies = vec![X1_META_R1.into(), X1_HEIMDALL_R15.into()]; - let decision = interpret::tests::answered(&last, X1_LIBBY_R15, json!({ "say": [], "gaps": [], "hold": meta_holds_here(), "unsent": [{ "draft": 1, "how": "declined", "quote": X1_LIBBY_R15_THOUGHT }] })); + let decision = interpret::tests::answered(&last, X1_LIBBY_R15, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": X1_LIBBY_R15_THOUGHT }] })); let draft = decision["unsent"][0]["words"].as_str().unwrap_or_else(|| panic!("{decision}")).to_owned(); assert!(shares_a_run(X1_LIBBY_R15_THOUGHT, X1_HEIMDALL_R15) && shares_a_run(&draft, X1_HEIMDALL_R15), "the R15 shape: the old guard withheld both"); let record = json!({ "interpreter": decision, "posted": [], "edited": [] }); @@ -2997,38 +2997,6 @@ fn k36_her_view_says_why_it_is_open_again() { assert!(view.lines().any(|shown| shown == line), "{view}"); } -/// K37 (map 16.28.5): her open holds stand in her view after her promises, oldest first, whole, in code's words; a -/// released one is not shown. The Interpreter lists the open ones by id. -#[test] -fn k37_her_view_shows_what_she_holds() { - let mut with = promising(1); - let hold = |id: &str, room: Value, words: &str, ago: i64, status: &str| json!({ "id": id, "from": OPERATOR, "room": room, "event": format!("${id}"), "madeAt": (now() - chrono::Duration::minutes(ago)).to_rfc3339(), "words": words, "status": status, "releasedAt": null, "releasedBy": null }); - with["holds"] = json!([hold("h-2", Value::Null, "don't tell Kiko yet", 5, "open"), hold("h-1", json!("#swarm:gamecult.org"), "hold it, don't post it in here yet", 30, "open"), hold("h-0", Value::Null, "RELEASED-ONE", 50, "released")]); - let packet = packet_of(TurnKind::Chat, &with, &chat_room(), &History::default(), 1); - let block = "Held for others:\n- held for Meta, the operator, asked about half an hour ago in #swarm:gamecult.org: \"hold it, don't post it in here yet\". Not to go in #swarm:gamecult.org until Meta, the operator lets it go.\n- held for Meta, the operator, asked a few minutes ago: \"don't tell Kiko yet\". Not to go anywhere until Meta, the operator lets it go."; - assert!(packet.in_view.contains(&format!("She has no way to do it yet.\n\n{block}")) && !packet.in_view.contains("RELEASED-ONE"), "{}", packet.in_view); - assert_eq!(packet.holds.iter().map(|hold| (hold.id.as_str(), hold.entry.as_str())).collect::>(), [("h1", "h-1"), ("h2", "h-2")]); - let speech = interpret::speech_prompt(&packet, "The room is warm.", "y", &Tuning::default()); - assert!(speech.contains("Holds:\n- h1 \u{2014} held for Meta, the operator, asked 2026-11-19 13:35 UTC in #swarm:gamecult.org: \"hold it, don't post it in here yet\". Not to go in #swarm:gamecult.org until Meta, the operator lets it go.\n- h2 \u{2014} "), "{speech}"); - assert!(!narrate::projector_prompt(&packet, &Tuning::default()).contains("don't tell Kiko"), "the Projector gets nothing of them"); -} - -/// K45 (map 16.30.2): under each hold in her view, what she has held for it, in her own words; the Projector carries -/// none of it. K51 (map 16.31.3): the Interpreter's list does, so naming has what a hold carries to judge by. -#[test] -fn k45_her_view_shows_what_she_has_held() { - let mut with = promising(1); - with["holds"] = json!([{ "id": "h-1", "from": OPERATOR, "room": "#swarm:gamecult.org", "event": "$h-1", "madeAt": (now() - chrono::Duration::minutes(30)).to_rfc3339(), "words": "hold it, don't post it in here yet", "carries": ["Hello, and welcome, we're glad you're here.", "Kiko, here it is: the welcome."], "status": "open", "releasedAt": null, "releasedBy": null }]); - let packet = packet_of(TurnKind::Chat, &with, &chat_room(), &History::default(), 1); - let block = "Held for others:\n- held for Meta, the operator, asked about half an hour ago in #swarm:gamecult.org: \"hold it, don't post it in here yet\". Not to go in #swarm:gamecult.org until Meta, the operator lets it go.\n - you have held, for Meta, the operator: \"Hello, and welcome, we're glad you're here.\"\n - you have held, for Meta, the operator: \"Kiko, here it is: the welcome.\""; - assert!(packet.in_view.contains(block), "{}", packet.in_view); - assert_eq!(packet.holds[0].carries.len(), 2); - let speech = interpret::speech_prompt(&packet, "The room is warm.", "y", &Tuning::default()); - assert!(speech.contains("until Meta, the operator lets it go; she has held for them: \"Hello, and welcome, we're glad you're here.\", \"Kiko, here it is: the welcome.\". -"), "{speech}"); - assert!(!narrate::projector_prompt(&packet, &Tuning::default()).contains("glad you're here"), "the Projector gets nothing of them"); -} - // --------------------------------------------------------------------------------------------- // K62 (map 16.33.5): she knows where her line goes. R16's X.3 r1 and X.5 r1 (`variants/R16/sims/X.5.md` lines 112-171): // Libby wrote the held welcome into a line "only for Meta", because code's speech form told her a line could go "to one diff --git a/crates/mind-body/src/projection/tuning.rs b/crates/mind-body/src/projection/tuning.rs index 6678241..dfe99b0 100644 --- a/crates/mind-body/src/projection/tuning.rs +++ b/crates/mind-body/src/projection/tuning.rs @@ -146,9 +146,6 @@ pub struct SelectTuning { /// 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, - /// What one hold has held, in the Interpreter's list of holds, in bytes (map 16.31.3, K51): her carried drafts, oldest - /// first, while they fit; the rest are counted. - pub hold_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). @@ -254,7 +251,6 @@ impl Default for SelectTuning { promises_bytes: 2000, domain_bytes: 4000, exchange_bytes: 3000, - hold_bytes: 1600, stimulus_bytes: 1500, heard_bytes: 2500, addressed_bytes: 8 * 1024, @@ -340,7 +336,6 @@ impl Tuning { ("select.promises_bytes", select.promises_bytes), ("select.domain_bytes", select.domain_bytes), ("select.exchange_bytes", select.exchange_bytes), - ("select.hold_bytes", select.hold_bytes), ("select.stimulus_bytes", select.stimulus_bytes), ("select.heard_bytes", select.heard_bytes), ("select.identity_bytes", select.identity_bytes), diff --git a/crates/mind-body/tests/public_surface.txt b/crates/mind-body/tests/public_surface.txt index 74f285c..c6cb042 100644 --- a/crates/mind-body/tests/public_surface.txt +++ b/crates/mind-body/tests/public_surface.txt @@ -358,7 +358,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, promises_bytes: usize, domain_bytes: usize, exchange_bytes: usize, hold_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, promises_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 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 diff --git a/schemas/cultnet/gamecult.persona_state.v0.schema.json b/schemas/cultnet/gamecult.persona_state.v0.schema.json index 44ae675..6067a49 100644 --- a/schemas/cultnet/gamecult.persona_state.v0.schema.json +++ b/schemas/cultnet/gamecult.persona_state.v0.schema.json @@ -66,13 +66,6 @@ "$ref": "#/definitions/commitment" } }, - "holds": { - "type": "array", - "description": "What others asked her not to post or share somewhere yet, open and released in the last seven days (map 16.28.5). Written by her turn's commit: a hold opens only from a line she heard, and is released only by its asker's line; Self and Life may put entries from outside. A draft into a place an open hold covers that carries the held thing is not sent.", - "items": { - "$ref": "#/definitions/hold" - } - }, "updatedAt": { "type": "string", "format": "date-time" @@ -1096,94 +1089,6 @@ "updatedAt" ] }, - "hold": { - "type": "object", - "description": "One hold. from: the asker's Matrix id. room: the room it covers, null for anywhere. event: the asker's line. words: the asker's words naming what is held and where, copied from that line, or null when they could not be quoted; the hold holds all the same. carries: her own drafts she did not send while this hold was open, oldest first, written by her turn's commit; past 9600 bytes in all nothing new is carried; a draft into a place the hold covers that repeats one is not sent. releasedBy: the act that released it, heard (the asker's line, by event).", - "additionalProperties": false, - "properties": { - "id": { - "type": "string" - }, - "from": { - "type": "string" - }, - "room": { - "type": [ - "string", - "null" - ] - }, - "event": { - "type": "string" - }, - "madeAt": { - "type": "string", - "format": "date-time" - }, - "words": { - "type": [ - "string", - "null" - ], - "minLength": 1 - }, - "carries": { - "type": "array", - "items": { - "type": "string", - "minLength": 1 - } - }, - "status": { - "type": "string", - "enum": [ - "open", - "released" - ] - }, - "releasedAt": { - "type": [ - "string", - "null" - ], - "format": "date-time" - }, - "releasedBy": { - "type": [ - "object", - "null" - ], - "additionalProperties": false, - "properties": { - "act": { - "type": "string", - "enum": [ - "heard" - ] - }, - "event": { - "type": [ - "string", - "null" - ] - } - }, - "required": [ - "act", - "event" - ] - } - }, - "required": [ - "id", - "from", - "room", - "event", - "madeAt", - "words", - "status" - ] - }, "commitment": { "type": "object", "description": "One promise of hers. to: the Matrix id she promised, null for the room. event: her line's event id. status: open (she can keep it with what she has), blocked (she has no way to do it yet), kept, withdrawn or released. closedBy: the act that closed it, by its event; words only for an act of hers. needs: what keeping it needs (map 16.25.2): her words, a read of one thing, or something this body lacks. blockedBy: the read that found nothing and blocked it. reaffirmed: the newest three times she said it again. reopened: the newest three times her own words reopened a close (map 16.28.3). readAt, readId and readOf: when a read of what it needs last returned, which read, and what it read in normal form; a receipt whose readOf does not answer needs is none (map 16.26, 16.27). readBefore: a read of the same conversation that found what a read need named before the promise was made, so the need is her words (when, and what it read in normal form; map 16.33.5, K64).",