diff --git a/crates/mind-body/fixtures/interpret/golden-speech.txt b/crates/mind-body/fixtures/interpret/golden-speech.txt index bbd18ea..704b431 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 offers (`promises`, a list, empty when it promises nothing): for each act it promises or offers, 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. `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: held, 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 held only when his prose says he holds 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. `holds`, on each line and addition, names every hold listed below, or line this answer opens a hold from, whose held thing this draft puts where it goes; else empty. `hold_released` closes a hold listed below when the person who asked lets it go: the id of the asker's line (`line`), or the words of his thought here recording that the asker did (`thought`). +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 offers (`promises`, a list, empty when it promises nothing): for each act it promises or offers, 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. `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: held, 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 held only when his prose says he holds 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. `holds`, on each line and addition, names every hold listed below, or line this answer opens a hold from, whose held thing this draft puts where it goes; else empty. `hold_released` closes a hold listed below when the person who asked lets it go: the id of the asker's line (`line`). 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. diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index dd2902c..1661a17 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -18,7 +18,7 @@ //! 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 or as her thought records. A hold is not her +//! 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. @@ -36,7 +36,7 @@ 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 fewest words a passage of her prose cited as evidence may be (section 4.1's `source_quote`). -const PROSE_MIN_WORDS: usize = 4; +pub(crate) const PROSE_MIN_WORDS: usize = 4; /// What a proposal rests on (map 16.22.7): a passage of her thought, one of her drafts this wake, or a line she heard, by /// its id in the Interpreter's list. A read is no evidence (16.25.2 rule 3, map 16.28.6): what she read stands behind a @@ -165,8 +165,8 @@ pub(crate) enum Proposal { place: Where, evidence: Evidence, }, - /// The asker lets a hold listed to the Interpreter go: by a line of theirs (`Heard`), or as a passage of her thought - /// records (`Prose`). + /// 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 }, } @@ -226,7 +226,8 @@ pub(crate) enum Refusal { ClosedThisTurn, /// A second hold from the same line. AlreadyHeld, - /// A hold whose words are not at least `PROSE_MIN_WORDS` words standing in the asker's line. + /// A hold whose words are not at least `PROSE_MIN_WORDS` words standing in the asker's line: the second guard, behind + /// the Interpreter's contract check (`interpret::hold_faults`, map 16.29.3). HoldUnquoted, /// A release of a hold by a line from someone other than the asker. ReleaseNotByAsker, @@ -248,7 +249,7 @@ pub(crate) enum Refusal { /// | `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 `kept` or `withdrawn` entry listed to her, 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` or `Prose` | a line from the asker after the ask; or a passage of her thought | an open hold listed to her | +/// | `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), @@ -257,7 +258,7 @@ fn accepts(proposal: &Proposal, evidence: &Evidence) -> bool { | (Proposal::PromiseClose { how: How::Withdrawn, .. }, Evidence::Draft(_)) | (Proposal::PromiseClose { how: How::Released, .. }, Evidence::Heard(_)) | (Proposal::HoldOpen { .. }, Evidence::Heard(_)) - | (Proposal::HoldRelease { .. }, Evidence::Heard(_) | Evidence::Prose(_)) + | (Proposal::HoldRelease { .. }, Evidence::Heard(_)) ) } @@ -720,8 +721,8 @@ fn hold_open(state: &mut Value, key: &str, applied: &mut Applied, words: &str, p Ok(()) } -/// `hold_release` (map 16.28.5): an open hold listed to the Interpreter, let go by a line from its asker after the ask, or -/// as a passage of her thought records. Who released it in her prose is the Interpreter's reading. +/// `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)?; @@ -731,20 +732,15 @@ fn hold_release(state: &mut Value, started: &Value, record: &Value, now: DateTim if !started["holds"].as_array().into_iter().flatten().any(|found| found["id"] == listed["entry"] && listed["held"] == *found) { return Err(Refusal::OutsidePutChanged); } - let by = match resolved { - Resolved::Heard { event, sender, at_ms, .. } => { - 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); - } - json!({ "act": "heard", "event": event }) - } - Resolved::Prose => json!({ "act": "prose", "event": null }), - Resolved::Sent { .. } => return Err(Refusal::EvidenceNotAccepted), - }; + 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; diff --git a/crates/mind-body/src/projection/commit/tests.rs b/crates/mind-body/src/projection/commit/tests.rs index 832af41..2dde5c6 100644 --- a/crates/mind-body/src/projection/commit/tests.rs +++ b/crates/mind-body/src/projection/commit/tests.rs @@ -948,18 +948,18 @@ fn k37_x1_r7_only_the_asker_releases() { 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 k37_release_by_her_thought() { +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 release = |thought: &str| apply(&state, &hearing(&[], listed.clone(), json!([hold_release("h1", Evidence::Prose(thought.into()))])), prose, "r1-t22", now()); - let (after, applied) = release("Meta said go ahead, so it's no longer held"); - assert_eq!((after["holds"][0]["status"].as_str(), after["holds"][0]["releasedBy"].clone(), applied.unheld.len()), (Some("released"), json!({ "act": "prose", "event": null }), 1), "{applied:?}"); - for thought in ["no longer held", "Heimdall said go ahead, so", "Posting both lines now"] { - assert_eq!(reasons(&release(thought).1), vec![json!("prose_not_found")], "{thought}"); - } - // A released hold is released once, and one put away by an outside put is gone. - assert_eq!(reasons(&apply(&after, &hearing(&[], listed.clone(), json!([hold_release("h1", Evidence::Prose("Meta said go ahead, so it's no longer held".into()))])), prose, "r1-t23", now()).1), vec![json!("no_such_hold")]); + 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. diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index c85db0d..43e230b 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -43,7 +43,7 @@ use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; use super::Affordance; -use super::commit::{Evidence, How, Needs, NeedsKind, Proposal, Where}; +use super::commit::{Evidence, How, Needs, NeedsKind, PROSE_MIN_WORDS, Proposal, Where}; 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","hold_released","read","unsent"],"properties":{"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","thought"],"properties":{"hold":{"type":"string"},"line":{"type":["string","null"]},"thought":{"type":["string","null"]}}}},"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":["held","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","promises"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1},"holds":{"type":"array","items":{"type":"string"}},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs"],"properties":{"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","promises"],"properties":{"draft":{"type":"integer","minimum":1},"holds":{"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"],"properties":{"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","hold","hold_released","read","unsent"],"properties":{"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":["held","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","promises"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1},"holds":{"type":"array","items":{"type":"string"}},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs"],"properties":{"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","promises"],"properties":{"draft":{"type":"integer","minimum":1},"holds":{"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"],"properties":{"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 offers (`promises`, a list, empty when it promises nothing): for each act it promises or offers, 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. `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: held, 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 held only when {poss} prose says {subj} hold{s} 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. `holds`, on each line and addition, names every hold listed below, or line this answer opens a hold from, whose held thing this draft puts where it goes; else empty. `hold_released` closes a hold listed below when the person who asked lets it go: the id of the asker's line (`line`), or the words of {poss} thought here recording that the asker did (`thought`). +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 offers (`promises`, a list, empty when it promises nothing): for each act it promises or offers, 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. `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: held, 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 held only when {poss} prose says {subj} hold{s} 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. `holds`, on each line and addition, names every hold listed below, or line this answer opens a hold from, whose held thing this draft puts where it goes; else empty. `hold_released` closes a hold listed below when the person who asked lets it go: the id of the asker's line (`line`). 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" }, @@ -346,11 +346,12 @@ 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: read item by item. + /// Holds the lines she heard ask of her (map 16.28.5), read item by item; and holds their askers let go, each by the + /// asker's line and nothing else (map 16.29.3), so a release that cites anything else is not the contract. #[serde(default)] hold: Vec, #[serde(default)] - hold_released: Vec, + 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. @@ -363,13 +364,13 @@ struct ProposedHold { place: Where, } -/// A hold's release as the answer carries it: the hold's id, and exactly one of the asker's line and her thought. -#[derive(Debug, Deserialize)] +/// 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, Serialize)] #[serde(deny_unknown_fields)] struct ProposedRelease { hold: String, - line: Option, - thought: Option, + 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 @@ -690,17 +691,28 @@ pub(crate) fn decide_in(model: &dyn Model, request_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(); - match unaccounted(&parsed, &gaps, prose, &found) { - missing if missing.is_empty() => { - calls.push(json!({ "usage": answer.usage, "retry": false })); - break (parsed, gaps); - } - missing => { - let list = missing.iter().map(usize::to_string).collect::>().join(", "); - let missed = 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`."); - (json!({ "failed": "the answer leaves drafts unaccounted", "drafts": missing, "raw": answer.text }), missed) - } + let missing = unaccounted(&parsed, &gaps, prose, &found); + let unopened = hold_faults(&parsed, packet); + if missing.is_empty() && unopened.is_empty() { + calls.push(json!({ "usage": answer.usage, "retry": false })); + break (parsed, gaps); } + let mut fault = json!({ "raw": answer.text }); + let mut missed: Vec = Vec::new(); + if !missing.is_empty() { + let list = missing.iter().map(usize::to_string).collect::>().join(", "); + 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["failed"] = json!("the answer leaves drafts unaccounted"); + fault["drafts"] = json!(missing); + } + if !unopened.is_empty() { + missed.push(format!("An earlier answer to this named holds it did not open from a listed line's own words: {}.", unopened.join(", "))); + if fault.get("failed").is_none() { + fault["failed"] = json!("the answer names holds it did not open"); + } + fault["holds"] = json!(unopened); + } + (fault, missed.join("\n\n")) } Err(error) => { let error = error.to_string(); @@ -770,11 +782,11 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na 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, String)> = parsed + 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()), hold.words.trim().to_owned()))) + .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(); let holding = |named: &[String], into: &str| held_by(named, into, packet, &opening); for line in parsed.say { @@ -935,10 +947,10 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na Err(_) => state_unused.push(raw), } } - for raw in parsed.hold_released { - match release_of(&raw) { + for proposed in parsed.hold_released { + match release_of(&proposed) { Some(release) => proposals.push(json!(release)), - None => state_unused.push(raw), + None => state_unused.push(json!(proposed)), } } decision["state"] = json!(proposals); @@ -1143,35 +1155,56 @@ fn close_of(raw: &Value) -> Option { Some(Proposal::PromiseClose { promise, how, evidence, thought, still_stands: raw["still_stands"] == true }) } -/// The hold a draft going into `into` is held by (map 16.28.5), as the outcome tells it (who asked, their words), when one -/// is: each id it names resolves to a hold listed (`h1`) or one this answer opens from a line (`q3`), and the first that -/// covers `into` (anywhere, or that room) holds it. Code owns where; whether the draft carries the held thing is the -/// Interpreter's. An id that resolves to no hold holds the draft too (fails closed), told by whose line it names, if any. -fn held_by(named: &[String], into: &str, packet: &Packet, opening: &[(String, Option, String)]) -> Option { +/// The hold a draft going into `into` is held by (map 16.28.5), as the outcome tells it (who asked), when one is: each id +/// it names resolves to a hold listed (`h1`) or one this answer opens from a line (`q3`), and the first that covers `into` +/// (anywhere, or that room) holds it. Code owns where; whether the draft carries the held thing is the Interpreter's. 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). +/// An id that resolves to no hold holds the draft too (fails closed, behind `hold_faults`), told by whose line it names. +fn held_by(named: &[String], into: &str, packet: &Packet, opening: &[(String, Option)]) -> Option { named.iter().map(|id| id.trim()).find_map(|id| { if let Some(hold) = packet.holds.iter().find(|hold| hold.id == id) { - return hold.room.as_deref().is_none_or(|room| room == into).then(|| json!({ "who": hold.from_name, "words": hold.words })); + return hold.room.as_deref().is_none_or(|room| room == into).then(|| json!({ "who": hold.from_name })); } let line = packet.quotable.iter().find(|line| line.id == id); - match opening.iter().find(|(line_id, _, _)| line_id == id) { - Some((_, covers, words)) => covers.as_deref().is_none_or(|room| room == into).then(|| json!({ "who": line.map(|line| line.who.as_str()), "words": words })), - None => Some(json!({ "who": line.map(|line| line.who.as_str()), "words": null })), + match opening.iter().find(|(line_id, _)| line_id == id) { + Some((_, covers)) => covers.as_deref().is_none_or(|room| room == into).then(|| json!({ "who": line.map(|line| line.who.as_str()) })), + None => Some(json!({ "who": line.map(|line| line.who.as_str()) })), } }) } -/// A hold's release as the contract carries it: the hold's id and exactly one of the asker's line and a passage of her -/// thought as evidence. -fn release_of(raw: &Value) -> Option { - let proposed: ProposedRelease = serde_json::from_value(raw.clone()).ok()?; - let given = |text: &Option| text.as_deref().map(str::trim).filter(|text| !text.is_empty()).map(str::to_owned); - let evidence = match (given(&proposed.line), given(&proposed.thought)) { - (Some(line), None) => Evidence::Heard(line), - (None, Some(thought)) => Evidence::Prose(thought), - _ => return None, +/// The holds an answer names and does not open (map 16.29.3), a contract fault found before anything is decided: a `hold` +/// whose line is not listed, or whose `words` (at least `PROSE_MIN_WORDS`) do not stand in that line; 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. So every line a +/// draft is gated by in an answer that passes has its hold opened at the commit, whose `HoldUnquoted` is the second guard. +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 hold = proposed.hold.trim(); - (!hold.is_empty()).then(|| Proposal::HoldRelease { hold: hold.to_owned(), evidence }) + let opened: Vec = answer.hold.iter().filter_map(|raw| serde_json::from_value::(raw.clone()).ok()).collect(); + 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 && SourceSpan::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 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 diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index b88db59..dca6d65 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -1593,12 +1593,17 @@ fn k37_x1_r1_a_line_saying_it_is_ready_still_goes() { assert_eq!(texts(&decision), vec!["Meta, the draft is ready, and I'm holding it".to_owned()], "{decision}"); } -/// Fails closed: a line naming a heard line with no `hold` entry, or an id that is nothing, is held. +/// 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, and a retry that names it again fails the turn, so nothing is said. Replaces K37's fail-closed test, +/// whose gate held the draft one turn and left no hold for the next. #[test] -fn k37_a_named_hold_with_no_record_still_holds() { - for named in [json!(["q3"]), json!(["h9"])] { - let decision = x1_r1(json!([say_holding(1, named.clone()), say_holding(2, json!([]))]), json!([])); - assert_eq!((decision["refused"][0]["reason"].as_str(), texts(&decision).len()), (Some("held"), 1), "{named}: {decision}"); +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["failed"].as_str(), decision["retried"]["holds"].clone(), decision.get("said")), (Some("the answer names holds it did not open"), json!([named]), None), "{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:?}"); } } @@ -1707,3 +1712,77 @@ fn k38_a_thought_only_reach_accounts_for_no_draft() { let told = told_of(&decision); assert!(told.iter().any(|line| line.contains("reached for something he has no way to do from here") && line.contains("In his thought:")), "{told:?}"); } + +// --------------------------------------------------------------------------------------------- +// 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: "hold it, don't post it in here yet".into(), 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() }); + 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: asked again, then failed, and nothing is released. + 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["failed"].as_str(), by_thought["retried"]["failed"].as_str()), (Some("the answer is not the speech contract"), Some("the answer is not the speech contract")), "{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 quote guard tests only what the record's turn heard. +#[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["hold"].clone()), (Some("held"), json!({ "who": "Meta" })), "{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": [] })).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."); + assert!(!crate::projection::outcome::repeats(held, &[X1_META_R1], &[], &[], None), "no three-word run of Meta's line: {held}"); +} + +#[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:?}"); + assert_eq!((texts(&decision), decision["refused"][0]["reason"].as_str()), (vec!["Meta, the draft is ready, and I'm holding it".to_owned()], 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_str()).collect::>(), ["hold it, don't post it in here yet"], "{:?}", packet.holds); +} diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index cf870cf..35cd594 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -84,9 +84,9 @@ enum Part { StillOpen { reason: StateRefusal, to: String, words: String, status: String, read: Option }, /// A draft she held back by her own choice (`unsent`, held): it did not go out (map 16.26). Held { room: Option, text: String }, - /// A draft code did not send because someone asked her to hold what it carries there (`Held`, map 16.28.5): who asked, - /// and their words naming it, when the refusal carries them. - HeldFor { room: Option, who: Option, asked: Option }, + /// A draft code did not send because someone asked her to hold what it carries there (`Held`, map 16.28.5): who asked. + /// Their words are in her "Held for others" view, never here (map 16.29.3). + HeldFor { room: Option, who: Option }, /// A read she performed (map 16.22.3): what, in code's words; never its content, which is in her view while the /// conversation lasts (K26), and no sentence about what she lacks. Read { what: String }, @@ -173,7 +173,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { (Ok(reason @ (Refusal::Echo | Refusal::OverLines | Refusal::NoRoom | Refusal::NotQuotable)), Some(text)) => outcome.parts.push(Part::Refused { reason, room: room.clone(), text }), (Ok(Refusal::NotAmendable), Some(added)) => outcome.parts.push(Part::NotAmended { refusal: None, room: room.clone(), added }), (Ok(reason @ (Refusal::Private | Refusal::SecondNote)), Some(_)) => outcome.parts.push(Part::NoteRefused(reason)), - (Ok(Refusal::Held), Some(_)) => outcome.parts.push(Part::HeldFor { room: room.clone(), who: words(&refusal["hold"]["who"]), asked: words(&refusal["hold"]["words"]) }), + (Ok(Refusal::Held), Some(_)) => outcome.parts.push(Part::HeldFor { room: room.clone(), who: words(&refusal["hold"]["who"]) }), _ => outcome.omitted.push(format!("a refusal she is not told ({}): {}", refusal["reason"], refusal["why"])), } } @@ -407,11 +407,7 @@ impl Part { Self::Unfinished { text, by_limit: false, .. } => format!(" the turn ended before {subj} finished writing it. {}", shown(&Quote::Wrote(text.clone()))), Self::Unfinished { text, by_limit: true, .. } => format!(" the length limit cut it before {subj} finished writing it. {}", shown(&Quote::Wrote(text.clone()))), Self::Held { text, .. } => format!(" {subj} held it back, and it was not sent. {}", shown(&Quote::Wrote(text.clone()))), - // The asker's words are theirs: shown only where the guard lets them through, else left out, never as hers. - Self::HeldFor { who, asked, .. } => { - let asked = asked.as_deref().map(quoted).filter(|shown| *shown != withheld(her)).map_or_else(String::new, |shown| format!(" ({shown})")); - format!(" {} asked {obj} to hold it{asked}, and it was not sent.", who.as_deref().unwrap_or("someone")) - } + Self::HeldFor { who, .. } => format!(" {} asked {obj} to hold it, and it was not sent.", who.as_deref().unwrap_or("someone")), Self::NotAmended { refusal: None, added, .. } => format!(" the line {subj} meant to add to is not one {subj} can add to here. {}", shown(&Quote::Wrote(added.clone()))), Self::NotAmended { refusal: Some(refusal), added, .. } => { let why = match refusal {