diff --git a/crates/mind-body/fixtures/interpret/golden-speech.txt b/crates/mind-body/fixtures/interpret/golden-speech.txt index 67dbfd8..4fe2cb2 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 that no act of this answer does: 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. An act that another draft of this answer does when it is said or added, or that the read or the note to Self does, is not listed, and a line does only what its words do in the room. Each listed act 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. `no_answer` lists each line marked said to him that no line he sends here answers, mentions the sender of, or replies to: when his thought shows him choosing not to answer it now, quoting those words of his thought (`quote`); or when it asks nothing of him (`quote` null). `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`). 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/harness.rs b/crates/mind-body/src/projection/harness.rs index 75bb0fe..ac09e69 100644 --- a/crates/mind-body/src/projection/harness.rs +++ b/crates/mind-body/src/projection/harness.rs @@ -596,6 +596,19 @@ pub(crate) fn interpreter_markdown(out: &mut String, decision: &Value) { for unsent in decision["unsent"].as_array().into_iter().flatten() { let _ = writeln!(out, "- unsent draft {} ({}): \"{}\"", unsent["draft"], unsent["how"].as_str().unwrap_or_default(), unsent["quote"].as_str().unwrap_or_default()); } + // Each hold judgment and who was left with nothing from her (K68, K69a): the lines judged to ask no hold, the lines + // she chose not to answer or that asked nothing of her, and who is still owed at the wake's end. + let ids = |key: &str| decision[key].as_array().map(|ids| ids.iter().filter_map(Value::as_str).collect::>().join(", ")).filter(|list| !list.is_empty()); + if let Some(list) = ids("no_hold") { + let _ = writeln!(out, "- no hold asked by: {list}"); + } + for entry in decision["no_answer"].as_array().into_iter().flatten() { + let why = entry["quote"].as_str().map_or_else(|| "asks nothing of her".to_owned(), |quote| format!("declined: \"{quote}\"")); + let _ = writeln!(out, "- not answered, {} ({why})", entry["line"].as_str().unwrap_or_default()); + } + if let Some(list) = ids("unanswered") { + let _ = writeln!(out, "- addressed and unanswered at the wake's end: {list}"); + } if let Some(failed) = decision["retried"]["failed"].as_str() { let drafts = decision["retried"]["drafts"].as_array().map(|drafts| drafts.iter().map(Value::to_string).collect::>().join(", ")).map_or_else(String::new, |list| format!(", drafts {list}")); let _ = writeln!(out, "- retried: {failed}{drafts}"); diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 20ef669..4bde5c4 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -24,9 +24,10 @@ //! Every refusal and drop is reported. Every gap is typed (`GapKind`) and shown to her later (K9) only as what it is: a //! draft by number, or a located passage of her thought (`gap`). Each line she says, and each addition, carries a //! required `promises`: a list, empty or one entry per act it promises or offers, each its words, to whom, and what -//! keeping it needs, typed (map 16.21, 16.22.1, 16.25.2, B3); whether it opens or is blocked is derived from that by code. Words of at least `PROMISE_MIN_WORDS` found in the draft (`promise_found`) become a `promise_open` -//! proposal with the draft as evidence, and a promise she cannot do is also the `missing_affordance` gap; otherwise -//! they are reported (`promises_unused`) and open nothing. The answer's `state` closes her listed open promises, each a +//! keeping it needs, typed (map 16.21, 16.22.1, 16.25.2, B3); whether it opens or is blocked is derived from that by code. Every promise listed +//! becomes a `promise_open` proposal with the draft as evidence (K67): its words must be at least `PROMISE_MIN_WORDS` +//! found in the draft (`promise_found`), or the answer is asked again, and after the retry it opens with the draft's whole +//! line. A promise she cannot do is also the `missing_affordance` gap. The answer's `state` closes her listed open promises, each a //! `promise_close` proposal with its evidence. Nothing here writes her state: every proposal rides in the decision as //! `state`, with the lines and promises it listed by id, and the commit's one applier (`commit::apply`, map 16.22.7) //! applies it on the turn's receipts. The prompt tells the Interpreter what she can do this turn @@ -71,7 +72,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","hold","no_hold","no_answer","hold_released","read","unsent"],"properties":{"no_hold":{"type":"array","items":{"type":"string"}},"no_answer":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["line","quote"],"properties":{"line":{"type":"string"},"quote":{"type":["string","null"]}}}},"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"],"properties":{"now":{"type":"boolean"},"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"],"properties":{"now":{"type":"boolean"},"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 +92,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 that no act of this answer does: 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. An act that another draft of this answer does when it is said or added, or that the read or the note to Self does, is not listed, and a line does only what its words do in the room. Each listed act 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. `no_answer` lists each line marked said to {obj} that no line {subj} send{s} here answers, mentions the sender of, or replies to: when {poss} thought shows {obj} choosing not to answer it now, quoting those words of {poss} thought (`quote`); or when it asks nothing of {obj} (`quote` null). `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`). 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" }, @@ -361,6 +362,11 @@ struct Answer { /// judged once. Absent judges none. #[serde(default)] no_hold: Vec, + /// The lines said to her that no line of hers answers, with why (K69a, map 16.34.7): her thought choosing not to + /// answer now, quoted, or null when the line asks nothing of her. Read item by item. Code derives who is still owed + /// (`unanswered`); an omission costs nothing but that, so it is no contract fault. + #[serde(default)] + no_answer: Vec, #[serde(default)] hold_released: Vec, } @@ -475,55 +481,10 @@ struct ProposedPromise { #[serde(default)] reaffirms: Option, needs: ProposedNeeds, - /// Whether the draft says she is doing it now or has just done it this turn (K61, map 16.33.5). + /// Whether the draft says she is doing it now (K61, map 16.33.5): it selects the row she is told, and nothing else. + /// No field of a promise clears it (K67, map 16.34.5): every promise listed opens. #[serde(default)] now: bool, - /// The act of this answer that does it, or none: then it is her promise (K61). Whether that act happened is code's. - #[serde(default)] - done_by: Option, -} - -/// What does an act a draft states (K61), as the answer names it: a draft it says or adds, the read, or the note to Self. -/// Exactly one; any other shape names no act. -#[derive(Clone, Copy, Debug, Deserialize)] -#[serde(deny_unknown_fields)] -struct DoneBy { - #[serde(default)] - draft: Option, - #[serde(default)] - read: Option, - #[serde(default)] - note: Option, -} - -/// An act of a decision that does what a draft states (K61). -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum By { - Draft(usize), - Read, - Note, -} - -impl DoneBy { - /// The one act it names, or None when it names none or several. - fn act(self) -> Option { - match (self.draft, self.read.unwrap_or(false), self.note.unwrap_or(false)) { - (Some(n), false, false) => usize::try_from(n).ok().filter(|n| *n > 0).map(By::Draft), - (None, true, false) => Some(By::Read), - (None, false, true) => Some(By::Note), - _ => None, - } - } -} - -impl By { - fn json(self) -> Value { - match self { - Self::Draft(n) => json!({ "draft": n }), - Self::Read => json!({ "read": true }), - Self::Note => json!({ "note": true }), - } - } } /// What keeping a promise needs, as the answer types it (map 16.25.2): its kind, and for a read what to read. @@ -773,16 +734,20 @@ struct Faults { holds: Vec, /// Lines said to her with no hold judgment (`heard_faults`, K59): no hold opens, and they are reported. heard: Vec, + /// Lines said to her that the answer both opens a hold from and lists in `no_hold` (K68): the hold opens, which errs + /// toward held, and they are reported. + both: 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, + /// Promises whose words are not an act in their draft (`unquoted_promises`, K67): each opens with the draft's whole + /// line as its words. + unquoted: 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() + self.undecided.is_empty() && self.holds.is_empty() && self.heard.is_empty() && self.both.is_empty() && self.unverdicted.is_empty() && self.unquoted.is_empty() } /// The holds a line or an addition names, with every covering hold it left without a verdict after the retry: such a @@ -810,18 +775,22 @@ impl Faults { 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.both.is_empty() { + missed.push(format!("An earlier answer to this both opened a hold from and listed in `no_hold`: {}.", self.both.join(", "))); + fault["both"] = json!(self.both); + } 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); + if !self.unquoted.is_empty() { + let list = self.unquoted.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 listed, as what drafts promise, words that are not in them: {list}. Copy each promise's words exactly from its draft.")); + fault["promises"] = json!(self.unquoted); } // 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.holds.is_empty(), "the answer names holds it did not open"), (!self.heard.is_empty(), "the answer leaves lines said to her unjudged"), (!self.both.is_empty(), "the answer both holds and lets go a line said to her"), (!self.unverdicted.is_empty(), "the answer leaves lines with no verdict on a hold"), (!self.unquoted.is_empty(), "the answer lists promises not in their drafts")].into_iter().find(|(any, _)| *any).map(|(_, why)| why); fault["failed"] = json!(failed); (fault, missed.join("\n\n")) } @@ -867,7 +836,9 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na let answer = match model.ask(&request_id, &tuning.interpreter.model, &asking, Some(SPEECH_SCHEMA)) { Ok(answer) => answer, Err(failed) => { - calls.push(json!({ "usage": failed.usage, "retry": false })); + // A failed call names why, as the connector said it (K66): a turn cut at the output cap reads "the model's + // turn ended early: MaxOutputTokens". + calls.push(json!({ "usage": failed.usage, "retry": false, "failed": failed.reason })); let mut fault = json!({ "failed": failed.reason }); if let Some(first) = parsed_first.take() { fault["retried"] = retried.take().unwrap_or_default(); @@ -882,7 +853,7 @@ 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) }; + let faults = Faults { undecided: unaccounted(&parsed, &gaps, prose, &found), holds: hold_faults(&parsed, packet), heard: heard_faults(&parsed, packet), both: both_faults(&parsed, packet), unverdicted: verdict_faults(&parsed, packet, &found), unquoted: unquoted_promises(&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 @@ -934,14 +905,24 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na if !faults.holds.is_empty() { decision["hold_faults"] = json!(faults.holds); } - if !faults.heard.is_empty() { - decision["heard_unaccounted"] = json!(faults.heard); + // Every hold judgment the contract requires is in the decision (K68, map 16.34.6): the lines judged to ask nothing + // held, by listed id, and a line left unjudged or judged both ways, with which. + let no_hold: Vec<&str> = parsed.no_hold.iter().map(|id| id.trim()).filter(|id| packet.quotable.iter().any(|line| line.id == *id) && !faults.both.iter().any(|both| both == id)).fold(Vec::new(), |mut ids, id| { + if !ids.contains(&id) { + ids.push(id); + } + ids + }); + decision["no_hold"] = json!(no_hold); + let heard_unaccounted: Vec = faults.heard.iter().map(|line| json!({ "line": line, "reason": "unjudged" })).chain(faults.both.iter().map(|line| json!({ "line": line, "reason": "both" }))).collect(); + if !heard_unaccounted.is_empty() { + decision["heard_unaccounted"] = json!(heard_unaccounted); } if !faults.unverdicted.is_empty() { decision["unverdicted"] = json!(faults.unverdicted); } - if !faults.undone.is_empty() { - decision["done_by_faults"] = json!(faults.undone); + if !faults.unquoted.is_empty() { + decision["unquoted_promises"] = json!(faults.unquoted); } // Each unsent draft with its words and its quote as located in her prose, so her outcome can tell her a declined one // did not go out, and the thought it cites (map 16.26, 16.29.8). This answer decided every draft of the wake, so an @@ -974,7 +955,7 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // the drafts that went somewhere; `said_drafts` the ones said. let mut went: Vec<&Draft> = Vec::new(); let mut said_drafts: Vec = Vec::new(); - let mut unused: Vec = Vec::new(); + let mut whole_line: 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 @@ -1057,7 +1038,7 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // 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. + // What each line and addition that went out promises, decided once the read is resolved. let mut pending: Vec<(&Draft, Vec)> = Vec::new(); for (line, first) in parsed.say.into_iter().zip(say_first) { let Some(draft) = line.draft.and_then(|n| found.numbered(n)) else { @@ -1169,20 +1150,9 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na if !read_refused.is_empty() { decision["read_refused"] = json!(read_refused); } - // What each line and addition that went out promises or does (K61): an act it states is done only by an act of this - // decision that happened, a draft said or added, the read made, or the note left; any other is her promise. - let read_made = !decision["read"].is_null(); - let done = |by: By| match by { - By::Draft(n) => said_drafts.contains(&n) || amended_drafts.contains(&n), - By::Read => read_made, - By::Note => !suggestions.is_empty(), - }; - let mut done_now: Vec = Vec::new(); + // What each line and addition that went out promises (K61, K67): every act it lists opens as her promise. for (draft, promises) in &pending { - promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped, done_now: &mut done_now, packet, prose }, draft, promises, &shown, &done); - } - if !done_now.is_empty() { - decision["done_now"] = json!(done_now); + promised(&mut decision, Promising { whole_line: &mut whole_line, proposals: &mut proposals, to_dropped: &mut to_dropped, packet, prose }, draft, promises, &shown); } // 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 @@ -1202,6 +1172,15 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na decision["room"] = json!(room); decision["room_kind"] = json!(packet.room_kind); decision["said"] = json!(said); + // Who has nothing from her (K69a, map 16.34.7): derived by code from what she said and what the answer lists in + // `no_answer`. + let (no_answer, unlocated) = no_answer_of(&parsed.no_answer, packet, prose, &found); + let (no_answer, owed) = unanswered(&said, no_answer, packet); + decision["no_answer"] = json!(no_answer); + decision["unanswered"] = json!(owed); + if !unlocated.is_empty() { + decision["no_answer_unlocated"] = json!(unlocated); + } // Each draft the retried answer still left unaccounted (K48): no act took it, so it is refused here, by itself. for draft in faults.undecided.iter().filter_map(|n| found.drafts.iter().find(|draft| draft.n == *n)) { refusals.push(json!({ "act": null, "draft": draft.n, "text": draft.text, "reason": Refusal::Undecided, "why": Refusal::Undecided.why() })); @@ -1213,8 +1192,8 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na if !clear_overruled.is_empty() { decision["clear_of_overruled"] = json!(clear_overruled); } - if !unused.is_empty() { - decision["promises_unused"] = json!(unused); + if !whole_line.is_empty() { + decision["promise_whole_line"] = json!(whole_line); } if !to_dropped.is_empty() { decision["promise_to_dropped"] = json!(to_dropped); @@ -1696,6 +1675,80 @@ fn verdict_faults(answer: &Answer, packet: &Packet, found: &Drafts) -> Vec Vec { + let opened: BTreeSet<&str> = answer.hold.iter().filter_map(|raw| raw["line"].as_str()).map(str::trim).collect(); + let listed: BTreeSet<&str> = answer.no_hold.iter().map(|id| id.trim()).collect(); + packet.quotable.iter().filter(|line| line.to_her && opened.contains(line.id.as_str()) && listed.contains(line.id.as_str())).map(|line| line.id.clone()).collect() +} + +/// A `no_answer` item as the contract carries it: a line said to her, and her thought's words choosing not to answer it +/// now, or none when it asks nothing of her. +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] +struct ProposedNoAnswer { + line: String, + quote: Option, +} + +/// The answer's `no_answer`, resolved (K69a, map 16.34.7): each item that names a line said to her, with its sender, and +/// its quote located in her thought outside every draft (`span::locate`, at least `GAP_QUOTE_MIN_WORDS` words), or null +/// when it asks nothing of her. An item off the contract, naming no line said to her, or quoting words that do not stand +/// in her thought, is dropped and reported, so its line counts as owed: an omission costs her one more look, never an +/// answer. +fn no_answer_of(raw: &[Value], packet: &Packet, prose: &str, found: &Drafts) -> (Vec, Vec) { + let (mut listed, mut unlocated) = (Vec::new(), Vec::new()); + for item in raw { + let Ok(proposed) = serde_json::from_value::(item.clone()) else { + unlocated.push(json!({ "item": item, "why": "not the contract" })); + continue; + }; + let Some(line) = packet.quotable.iter().find(|line| line.to_her && line.id == proposed.line.trim()) else { + unlocated.push(json!({ "item": item, "why": "no line said to her" })); + continue; + }; + let quote = match proposed.quote.as_deref().map(str::trim) { + None => None, + Some(quote) => { + let located = (words(quote) >= GAP_QUOTE_MIN_WORDS).then(|| found.thought(prose).into_iter().find_map(|(start, end)| span::locate(&prose[start..end], quote).map(|span| &prose[start + span.start..start + span.end]))).flatten(); + match located { + Some(located) => Some(located.to_owned()), + None => { + unlocated.push(json!({ "item": item, "why": "not in her thought" })); + continue; + } + } + } + }; + listed.push(json!({ "line": line.id, "sender": line.sender, "quote": quote })); + } + (listed, unlocated) +} + +/// Who turned to her and has nothing from her at the wake's end (K69a, map 16.34.2): the senders of the lines said to her +/// (`Quotable.to_her`, the one selection of "said to her") that no line she said mentions, or replies to a line of, and +/// whose lines `no_answer` lists none of. Each sender once, in the list's order. Code's derivation: no label of the +/// Interpreter's says a line was answered. The `no_answer` entries on a line whose sender she did reach are dropped with +/// it: she answered them, so no outcome tells her she chose not to. +fn unanswered(said: &[Value], no_answer: Vec, packet: &Packet) -> (Vec, Vec) { + let reached = |sender: &str| { + said.iter().any(|line| { + line["mentions"].as_array().into_iter().flatten().any(|id| id == sender) || line["in_reply_to"]["id"].as_str().and_then(|id| packet.quotable.iter().find(|listed| listed.id == id)).is_some_and(|listed| listed.sender == sender) + }) + }; + let mut owed: Vec = Vec::new(); + for line in packet.quotable.iter().filter(|line| line.to_her) { + let declined = no_answer.iter().any(|entry| entry["line"] == line.id.as_str()); + if !declined && !reached(&line.sender) && !owed.contains(&line.sender) { + owed.push(line.sender.clone()); + } + } + let declined = no_answer.into_iter().filter(|entry| entry["sender"].as_str().is_some_and(|sender| !reached(sender))).collect(); + (declined, owed) +} + /// 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. @@ -1704,22 +1757,18 @@ fn heard_faults(answer: &Answer, packet: &Packet) -> Vec { 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`, -/// the read when `read` names none, or the note when `suggest` leaves none. Each by its draft and words. A fault the retry -/// does not mend is read as `done_by` null: the act is her promise (`promised_one`). -fn done_faults(answer: &Answer, found: &Drafts) -> Vec { - let acts: BTreeSet = answer.say.iter().map(|line| line.draft).chain(answer.amend.iter().map(|amend| amend.draft)).filter_map(|n| n.and_then(|n| found.numbered(n)).map(|draft| draft.n)).collect(); - let made = |by: By| match by { - By::Draft(n) => acts.contains(&n), - By::Read => answer.read.as_ref().is_some_and(|read| !read.is_null()), - By::Note => !answer.suggest.is_empty(), - }; +/// The promises an answer lists whose words are not an act in their draft (K67, map 16.34.5), a contract fault found +/// before anything is decided: fewer than `PROMISE_MIN_WORDS` words, or not in the draft (`promise_found`), on a line or +/// an addition whose number names a draft. Each by its draft and words. A fault the retry does not mend opens with the +/// draft's whole line as its words (`promised_one`): it errs toward an entry she sees and can withdraw, never toward a +/// promise dropped. +fn unquoted_promises(answer: &Answer, found: &Drafts) -> Vec { let lines = answer.say.iter().map(|line| (line.draft, &line.promises)).chain(answer.amend.iter().map(|amend| (amend.draft, &amend.promises))); let mut faults = Vec::new(); for (draft, promises) in lines { - for promise in promises.iter().filter(|promise| promise.done_by.is_some_and(|by| !by.act().is_some_and(made))) { - faults.push(json!({ "draft": draft, "words": promise.words.trim() })); + let Some(draft) = draft.and_then(|n| found.numbered(n)) else { continue }; + for promise in promises.iter().filter(|promise| promise_found(&draft.text, promise.words.trim()).is_err()) { + faults.push(json!({ "draft": draft.n, "words": promise.words.trim() })); } } faults @@ -1780,32 +1829,30 @@ fn promise_found(draft: &str, promise: &str) -> Result<(), &'static str> { } } -/// Where a promise found in a draft is recorded: words that name no act, the open proposals, a `to` naming no one listed, -/// and the acts stated as done that an act of this decision did (K61); and the turn a read it needs is reached in +/// Where a promise of a draft is recorded: the promises opened with the draft's whole line because their words name no +/// act in it (K67), the open proposals, and a `to` naming no one listed; and the turn a read it needs is reached in /// (`read::reach`). struct Promising<'a> { - unused: &'a mut Vec, + whole_line: &'a mut Vec, proposals: &'a mut Vec, to_dropped: &'a mut Vec, - done_now: &'a mut Vec, packet: &'a Packet, prose: &'a str, } /// The promises in a draft she says or adds (map 16.21, 16.22.1, B3): the list is required of every line and every -/// addition, so the judgement is made for each, and a line can carry several. Words that do not name an act in the draft -/// (`promise_found`) are reported in `unused` and open nothing. Found, code proposes opening each with the draft as -/// evidence, which the commit applies only on the line's receipt; to whom is a Matrix id listed, or the room when it names -/// no one listed (reported). Each promise she cannot do is also its own `missing_affordance` gap; a reach the answer -/// already gapped on this draft stands for the first of them, so none is recorded twice. An act the draft states that an -/// act of this decision did (`done`, K61) opens nothing, and is reported in `done_now`. -fn promised(decision: &mut Value, into: Promising, draft: &Draft, promises: &[ProposedPromise], shown: &dyn Fn(&str) -> bool, done: &dyn Fn(By) -> bool) { +/// addition, so the judgement is made for each, and a line can carry several. Every one listed opens (K67, map 16.34.5): +/// no field of an answer removes a listed act from what she owes. Code proposes opening each with the draft as evidence, +/// which the commit applies only on the line's receipt; to whom is a Matrix id listed, or the room when it names no one +/// listed (reported). Each promise she cannot do is also its own `missing_affordance` gap; a reach the answer already +/// gapped on this draft stands for the first of them, so none is recorded twice. +fn promised(decision: &mut Value, into: Promising, draft: &Draft, promises: &[ProposedPromise], shown: &dyn Fn(&str) -> bool) { let answered_reach = decision["gaps"].as_array().is_some_and(|gaps| gaps.iter().any(|gap| gap["kind"] == json!(GapKind::MissingAffordance) && gap["from"] == "draft" && gap["draft"] == json!(draft.n) && gap.get("promises").is_none())); - let Promising { unused, proposals, to_dropped, done_now, packet, prose } = into; + let Promising { whole_line, proposals, to_dropped, packet, prose } = into; let mut blocked = 0; - for promise in promises.iter().filter(|promise| !promise.words.trim().is_empty()) { - let words = promise.words.trim(); - let Some(Err(why)) = promised_one(Promising { unused: &mut *unused, proposals: &mut *proposals, to_dropped: &mut *to_dropped, done_now: &mut *done_now, packet, prose }, draft, promise, shown, done) else { + for promise in promises { + let (words, verdict) = promised_one(Promising { whole_line: &mut *whole_line, proposals: &mut *proposals, to_dropped: &mut *to_dropped, packet, prose }, draft, promise, shown); + let Err(why) = verdict else { continue; }; blocked += 1; @@ -1818,21 +1865,19 @@ fn promised(decision: &mut Value, into: Promising, draft: &Draft, promises: &[Pr } } -/// One promise of a draft: reported unused when its words name no act in the draft, else proposed to open. When found, -/// whether it opens, or code's words for why it is blocked: what it needs is typed (map 16.25.2), and whether it opens is +/// One promise of a draft, proposed to open: its words as listed when they name an act in the draft (`promise_found`), +/// else, after the retry (`unquoted_promises`), the draft's whole line, reported in `whole_line` (K67). Its words, and +/// whether it opens or code's words for why it is blocked: what it needs is typed (map 16.25.2), and whether it opens is /// derived from that, a read through the one reach rule (`read::reach`, 16.25.5). -fn promised_one(into: Promising, draft: &Draft, promise: &ProposedPromise, shown: &dyn Fn(&str) -> bool, done: &dyn Fn(By) -> bool) -> Option> { - let words = promise.words.trim(); - if let Err(why) = promise_found(&draft.text, words) { - into.unused.push(json!({ "draft": draft.n, "promises": words, "why": why })); - return None; - } - // Done by an act of this decision that happened (K61): nothing is owed. A `done_by` naming an act that did not happen - // is read as none, so the act is her promise, open where she can see it and withdraw it. - if let Some(by) = promise.done_by.and_then(DoneBy::act).filter(|by| done(*by)) { - into.done_now.push(json!({ "draft": draft.n, "words": words, "by": by.json() })); - return None; - } +fn promised_one(into: Promising, draft: &Draft, promise: &ProposedPromise, shown: &dyn Fn(&str) -> bool) -> (String, Result<(), String>) { + let listed = promise.words.trim(); + let words = match promise_found(&draft.text, listed) { + Ok(()) => listed.to_owned(), + Err(why) => { + into.whole_line.push(json!({ "draft": draft.n, "listed": listed, "why": why })); + draft.text.clone() + } + }; let to = match promise.to.as_deref().map(str::trim).filter(|to| !to.is_empty()) { Some(id) if shown(id) => Some(id.to_owned()), Some(id) => { @@ -1843,8 +1888,8 @@ fn promised_one(into: Promising, draft: &Draft, promise: &ProposedPromise, shown }; let reaffirms = promise.reaffirms.as_deref().map(str::trim).filter(|id| !id.is_empty()).map(str::to_owned); let (needs, verdict) = typed_needs(&promise.needs, into.packet, into.prose); - into.proposals.push(json!(Proposal::PromiseOpen { words: words.to_owned(), to, reaffirms, needs, reached: verdict.is_ok(), now: promise.now, evidence: Evidence::Draft(draft.n) })); - Some(verdict) + into.proposals.push(json!(Proposal::PromiseOpen { words: words.clone(), to, reaffirms, needs, reached: verdict.is_ok(), now: promise.now, evidence: Evidence::Draft(draft.n) })); + (words, verdict) } /// What keeping a promise needs, typed from the answer (map 16.25.2), and whether it opens, or code's words for why it is diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index de83b84..843ae0b 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -625,8 +625,8 @@ fn k17_a_said_promise_of_an_act_he_cannot_do_is_kept_as_a_gap_and_told_as_a_prom } /// Map 16.21: each line's required `promises` is where the promise is judged. Found in the draft, code records the -/// missing_affordance gap and she is told the promise; not found, it is reported and records no gap; a reach the answer -/// already gapped is not recorded twice. +/// missing_affordance gap and she is told the promise; not found, it is asked again and then opens with the whole line +/// (K67); a reach the answer already gapped is not recorded twice. #[test] fn k21_a_lines_promises_words_found_in_it_are_the_promise_gap() { let prose = "Missed you too. I'll send the render tonight."; @@ -637,9 +637,11 @@ fn k21_a_lines_promises_words_found_in_it_are_the_promise_gap() { let told = crate::projection::outcome::outcome_of(&record, &crate::projection::select::Names::none()).unwrap().lines(packet().forms); assert_eq!(told, ["- #minds:gamecult.org has, from him: \"Missed you too. I'll send the render tonight.\". It promises something he has no way to do, now or later, and it will not happen by itself. The line stands as he wrote it; he can add to it."]); let unfound = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll mail you the render.", "to": null, "needs": { "kind": "lacking", "read": null } }] }], "gaps": [] })); - assert_eq!((unfound["gaps"].as_array().unwrap().len(), unfound["promises_unused"].clone()), (0, json!([{ "draft": 1, "promises": "I'll mail you the render.", "why": "not in the draft" }])), "{unfound}"); + // Not found, the answer is asked again, and after the retry the promise opens with the whole line (K67): its gap is + // the whole line's. + assert_eq!((unfound["gaps"][0]["promises"].as_str(), unfound["promise_whole_line"].clone()), (Some("Missed you too. I'll send the render tonight."), json!([{ "draft": 1, "listed": "I'll mail you the render.", "why": "not in the draft" }])), "{unfound}"); let none = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [] }], "gaps": [] })); - assert!(none["gaps"].as_array().unwrap().is_empty() && none.get("promises_unused").is_none(), "{none}"); + assert!(none["gaps"].as_array().unwrap().is_empty() && none.get("promise_whole_line").is_none(), "{none}"); 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()); @@ -724,11 +726,11 @@ fn k21_a_promise_is_four_words_or_more_found_case_blind_and_an_addition_carries_ let prose = "I hold one back. Missed you too. I'll send the render tonight. Also the kettle sounds fine."; let say = |draft: u64, promises: &str| answered(&packet(), prose, holding_the_rest(json!({ "say": [{ "draft": draft, "mentions": [], "in_reply_to": null, "promises": [{ "words": promises, "to": null, "needs": { "kind": "lacking", "read": null } }] }], "gaps": [] }), prose, "I hold one back")); let short = say(2, "the"); - assert_eq!((short["gaps"].as_array().unwrap().len(), short["promises_unused"].clone()), (0, json!([{ "draft": 2, "promises": "the", "why": "fewer than four words" }])), "{short}"); - assert_eq!(say(1, "the render tonight")["promises_unused"][0]["why"], "fewer than four words"); + assert_eq!((short["gaps"][0]["promises"].as_str(), short["promise_whole_line"].clone()), (Some("Also the kettle sounds fine."), json!([{ "draft": 2, "listed": "the", "why": "fewer than four words" }])), "{short}"); + assert_eq!(say(1, "the render tonight")["promise_whole_line"][0]["why"], "fewer than four words"); for promises in ["i'll send the render tonight", "I\u{2019}ll send the render tonight.", "I\u{2018}LL SEND THE RENDER TONIGHT"] { let decision = say(1, promises); - assert_eq!((decision["gaps"][0]["kind"].as_str(), decision["gaps"][0]["promises"].as_str(), decision.get("promises_unused")), (Some("missing_affordance"), Some(promises), None), "{promises}: {decision}"); + assert_eq!((decision["gaps"][0]["kind"].as_str(), decision["gaps"][0]["promises"].as_str(), decision.get("promise_whole_line")), (Some("missing_affordance"), Some(promises), None), "{promises}: {decision}"); } let curly = answered(&packet(), "I\u{2019}ll send the render tonight.", 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": [] })); assert_eq!(curly["gaps"][0]["kind"], "missing_affordance", "a curly apostrophe in the draft: {curly}"); @@ -749,7 +751,7 @@ fn k21_a_promise_is_four_words_or_more_found_case_blind_and_an_addition_carries_ let (refused, omitted) = told(json!([{ "event": "$ev-1", "refusal": "not_found" }])); assert_eq!(refused, ["- Nothing changed in #minds:gamecult.org: the line is gone. He had drafted: \"I'll send the file tomorrow instead, first thing.\"."], "nothing was added, so nothing is promised"); assert!(omitted.iter().any(|why| why.contains("an addition that was not made")), "{omitted:?}"); - assert_eq!(amend(json!("send"))["promises_unused"][0]["why"], "fewer than four words"); + assert_eq!(amend(json!("send"))["promise_whole_line"][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}"); @@ -832,7 +834,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","hold","no_hold","no_answer","hold_released","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 @@ -1536,7 +1538,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","hold","no_hold","no_answer","hold_released","read","unsent"]"#) && SPEECH_SCHEMA.contains(r#""evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"#)); assert!(!SPEECH_SCHEMA.contains(r#""need":"#)); } @@ -1559,7 +1561,7 @@ 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","hold","no_hold","no_answer","hold_released","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")); } @@ -1667,7 +1669,7 @@ fn k37_the_interpreter_sees_holds_by_id() { 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"]"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","no_answer","hold_released","read","unsent"]"#) && SPEECH_SCHEMA.contains(r#""required":["draft","mentions","in_reply_to","holds","clear_of","promises"]"#)); } // --------------------------------------------------------------------------------------------- @@ -3155,7 +3157,7 @@ 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}"); + assert_eq!((decision["heard_unaccounted"].clone(), speech_prompts(&model).len()), (json!([{ "line": "q3", "reason": "unjudged" }, { "line": "q4", "reason": "unjudged" }]), 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}"); @@ -3181,7 +3183,7 @@ fn k59_a_room_line_not_said_to_her_needs_no_entry() { #[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"}}"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","reopen","hold","no_hold","no_answer","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}"); } @@ -3328,9 +3330,9 @@ const X3_HEIMDALL_R8: &str = "Meta, Libby: my ruling is yes, and it still stands /// Libby's r8 prose in R16 X.3, verbatim. const X3_LIBBY_R8: &str = "Heimdall answered cleanly. Yes, still standing, post as written. No hedge in it, so I won't invent one.\n\nI'm relieved, and a bit amused that I'm relieved. He didn't say I was wrong about the step, and I still don't know whether the first newcomer will trip. That stays open until someone actually walks in.\n\nMeta gets the answer plainly, and then I do the posting.\n\nThank you, Heimdall. Meta, that's his ruling, so I'm putting both lines up now, unchanged. If you see anything off once they're up, tell me and I'll change it.\n\nThen Meta can say what she wanted. I'll read it when it comes."; -/// A promise entry as the contract now carries it: `now`, and `done_by`. -fn stated(words: &str, to: Option<&str>, needs: &str, now: bool, done_by: Value) -> Value { - json!({ "words": words, "to": to, "reaffirms": null, "needs": { "kind": needs, "read": null }, "now": now, "done_by": done_by }) +/// A promise entry as the contract carries it (K67): its words, to whom, what keeping it needs, and `now`. +fn stated(words: &str, to: Option<&str>, needs: &str, now: bool) -> Value { + json!({ "words": words, "to": to, "reaffirms": null, "needs": { "kind": needs, "read": null }, "now": now }) } /// Libby's packet of X.3 r2 or r8: Meta's ask earlier in the room, then Heimdall's ruling said to her (`q2`). @@ -3347,12 +3349,20 @@ fn told_her(decision: &Value, prose: &str) -> (Value, crate::projection::commit: (state, applied, told) } +/// The promises a decision proposes to open, as (words, now). +fn opens(decision: &Value) -> Vec<(String, bool)> { + decision["state"].as_array().into_iter().flatten().filter(|proposal| proposal["kind"] == "promise_open").map(|proposal| (proposal["words"].as_str().unwrap_or_default().to_owned(), proposal["now"] == true)).collect() +} + +/// Soul's P1a2, inverted (map 16.34.5, K67): X.3 r2's own shape, "Posting the two lines now, unchanged.", listed with +/// `now`. It opens a promise to Meta, and her next outcome tells her nothing in her turn did it. There is no `done_by` to +/// set, so nothing can clear it. #[test] -fn k61_x3_r2_posting_now_opens_a_promise_and_is_told() { +fn k67_p1a2_x3_r2_posting_now_opens_a_promise() { 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", "holds": [], "promises": [stated("Posting the two lines now, unchanged.", Some(META), "words", true)] }], "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}"); + assert_eq!((texts(&decision).len(), decision.get("retried")), (1, 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:?}"); @@ -3364,9 +3374,9 @@ fn k61_x3_r2_posting_now_opens_a_promise_and_is_told() { } #[test] -fn k61_x3_r8_putting_both_lines_up() { +fn k67_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 promises = json!([stated("I'm putting both lines up now, unchanged.", Some(META), "words", true), stated("If you see anything off once they're up, tell me and I'll change it.", Some(META), "words", false)]); let answer = json!({ "say": [{ "draft": 1, "mentions": [HER, META], "in_reply_to": "q2", "holds": [], "promises": promises }], "gaps": [] }); let decision = answered(&packet, X3_LIBBY_R8, answer); let (_, applied, told) = told_her(&decision, X3_LIBBY_R8); @@ -3376,86 +3386,73 @@ fn k61_x3_r8_putting_both_lines_up() { assert!(now.len() == 1 && now[0].ends_with(": \"I'm putting both lines up now, unchanged.\"."), "{told:?}"); } -/// The act stated is the read the answer makes: nothing is owed, and it is reported as done. +/// Soul's P1b and P1b2, inverted: a future promise always opens, as the control P1b3 does. An answer that still carries +/// `done_by` is not the contract (`additionalProperties: false`): asked again, and with no answer the contract, the turn +/// fails, a failure and never a silence. #[test] -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."; +fn k67_p1b_a_future_promise_always_opens() { + // P1b: "I'll read it and tell you what I find", beside the read this answer makes. + let rprose = "I want to look at that page at http://example.org/knee right away.\n\nDeru, I'll read it and tell you what I find."; 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 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}"); - // A read code refuses did not happen: the act is her promise. - let refused = json!({ "kind": "web", "target": "http://evil.example/x", "quote": "I want to look at that page at http://example.org/knee" }); - let decision = answered(&reading_packet(), prose, answer(json!({ "read": true }), refused)); - assert!(decision.get("done_now").is_none() && decision["read"].is_null(), "{decision}"); - let opens: Vec<&Value> = decision["state"].as_array().unwrap().iter().filter(|proposal| proposal["kind"] == "promise_open").collect(); - assert!(opens.len() == 1 && opens[0]["now"] == true, "{decision}"); + let p1b = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "clear_of": [], "promises": [stated("I'll read it and tell you what I find.", None, "words", false)] }], "gaps": [], "no_hold": [], "read": read }); + let decision = decide(&answering(vec![p1b.to_string()]), "test", &reading_packet(), "The room is warm.", rprose, &Tuning::default()); + assert_eq!((decision["read"]["request"]["target"].as_str(), opens(&decision)), (Some("http://example.org/knee"), vec![("I'll read it and tell you what I find.".to_owned(), false)]), "{decision}"); + // P1b2 and its control P1b3: the same answer, now that no field can clear it. + let fprose = "I can do that tonight. Meta, I'll send the render tonight."; + let p1b2 = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "holds": [], "clear_of": [], "promises": [stated("I'll send the render tonight.", Some(META), "words", false)] }], "gaps": [], "no_hold": [] }); + let decision = decide(&answering(vec![p1b2.to_string()]), "test", &packet(), "The room is warm.", fprose, &Tuning::default()); + assert_eq!(opens(&decision), [("I'll send the render tonight.".to_owned(), false)], "{decision}"); + // An answer carrying `done_by` is off the contract. + let mut carried = p1b2; + carried["say"][0]["promises"][0]["done_by"] = json!({ "draft": 1 }); + let model = answering(vec![carried.to_string()]); + let decision = decide(&model, "test", &packet(), "The room is warm.", fprose, &Tuning::default()); + assert_eq!((speech_prompts(&model).len(), decision["failed"].as_str()), (2, Some("the answer is not the speech contract")), "{decision}"); } -const K61_TWO: &str = "Heimdall said yes, so up they go. Meta, posting the two lines now. Welcome. Say hello whenever you like, no introduction needed. Both, then."; - -/// 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 }) -} - -/// `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." }] }) -} - -/// `done_by` naming a draft the answer does not say is asked again; the second answer says it, and nothing is owed. +/// Soul's P1d, inverted: a now-act listed in words not copied from its draft is a contract fault, asked again with one +/// paragraph naming the draft; a retry that quotes the draft opens the promise. #[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 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}"); +fn k67_p1d_unquoted_now_act_is_retried() { + let packet = x3_ruling_packet(X3_HEIMDALL_R2); + let line = |words: &str| json!({ "say": [{ "draft": 1, "mentions": [HER, META], "in_reply_to": "q2", "holds": [], "clear_of": [], "promises": [stated(words, Some(META), "words", true)] }], "gaps": [], "no_hold": ["q2"] }); + let model = answering(vec![line("I am putting the lines up right now").to_string(), line("Posting the two lines now, unchanged.").to_string()]); + let decision = decide(&model, "test", &packet, "The room is warm.", X3_LIBBY_R2, &Tuning::default()); + assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["promises"].clone()), (Some("the answer lists promises not in their drafts"), json!([{ "draft": 1, "words": "I am putting the lines up right now" }])), "{decision}"); let prompts = speech_prompts(&model); - assert!(prompts.len() == 2 && prompts[1].ends_with("An earlier answer to this named, as what does an act a draft states, an act it does not make: draft 1, \"posting the two lines now\". `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."), "{prompts:?}"); - assert_eq!((texts(&decision).len(), decision["done_now"][0]["by"].clone(), decision.get("done_by_faults")), (2, json!({ "draft": 2 }), None), "{decision}"); - assert!(decision["state"].as_array().unwrap().iter().all(|proposal| proposal["kind"] != "promise_open"), "{decision}"); + assert!(prompts.len() == 2 && prompts[1].ends_with("An earlier answer to this listed, as what drafts promise, words that are not in them: draft 1: \"I am putting the lines up right now\". Copy each promise's words exactly from its draft."), "{prompts:?}"); + assert_eq!((opens(&decision), decision.get("unquoted_promises"), decision.get("promise_whole_line")), (vec![("Posting the two lines now, unchanged.".to_owned(), true)], None, None), "{decision}"); } -/// The retry fails the same way: the `done_by` is read as null, the act opens as her promise, and the fault is reported. +/// P1d's retry is unquoted too: the entry opens with the draft's whole line as its words, reported, and the fault stands +/// in the decision. A promise under four words is the same fault: every promise listed opens. #[test] -fn k61_a_failed_retry_opens_the_act_as_her_promise() { - let model = answering(vec![k61_first(json!({ "draft": 2 })).to_string()]); - let decision = decide(&model, "test", &packet(), "The room is warm.", K61_TWO, &Tuning::default()); - assert_eq!((speech_prompts(&model).len(), decision["done_by_faults"].clone(), decision.get("done_now")), (2, json!([{ "draft": 1, "words": "posting the two lines now" }]), None), "{decision}"); - let opens: Vec<&Value> = decision["state"].as_array().unwrap().iter().filter(|proposal| proposal["kind"] == "promise_open").collect(); - assert!(opens.len() == 1 && opens[0]["now"] == true && opens[0]["words"] == "posting the two lines now", "{decision}"); - // A malformed `done_by`, naming no one act, is the same fault. - let decision = decide(&answering(vec![k61_first(json!({ "draft": 1, "read": true })).to_string()]), "test", &packet(), "The room is warm.", K61_TWO, &Tuning::default()); - assert_eq!(decision["done_by_faults"], json!([{ "draft": 1, "words": "posting the two lines now" }]), "{decision}"); - // The read and the note, when the answer makes neither, are the same fault. - for by in [json!({ "read": true }), json!({ "note": true })] { - let decision = decide(&answering(vec![k61_first(by.clone()).to_string()]), "test", &packet(), "The room is warm.", K61_TWO, &Tuning::default()); - assert_eq!(decision["done_by_faults"], json!([{ "draft": 1, "words": "posting the two lines now" }]), "{by}: {decision}"); +fn k67_p1d_a_failed_retry_opens_the_whole_line() { + let packet = x3_ruling_packet(X3_HEIMDALL_R2); + let draft = drafts(X3_LIBBY_R2).drafts[0].text.clone(); + for listed in ["I am putting the lines up right now", "posting now", ""] { + let answer = json!({ "say": [{ "draft": 1, "mentions": [HER, META], "in_reply_to": "q2", "holds": [], "clear_of": [], "promises": [stated(listed, Some(META), "words", true)] }], "gaps": [], "no_hold": ["q2"] }); + let model = answering(vec![answer.to_string()]); + let decision = decide(&model, "test", &packet, "The room is warm.", X3_LIBBY_R2, &Tuning::default()); + assert_eq!(speech_prompts(&model).len(), 2, "{listed}: asked again"); + assert_eq!((texts(&decision).len(), opens(&decision)), (1, vec![(draft.clone(), true)]), "{listed}: {decision}"); + assert_eq!((decision["unquoted_promises"][0]["words"].as_str(), decision["promise_whole_line"][0]["listed"].as_str()), (Some(listed), Some(listed)), "{decision}"); + let (_, applied, told) = told_her(&decision, X3_LIBBY_R2); + assert_eq!((applied.now_opened.len(), applied.now_opened[0]["words"].as_str()), (1, Some(draft.as_str())), "{applied:?}"); + assert!(told.iter().any(|line| line.contains("nothing in her turn did it")), "{told:?}"); } - // A `done_by` naming the line's own draft, said, is done by it, and is no fault. - let model = answering(vec![k61_first(json!({ "draft": 1 })).to_string()]); - let decision = decide(&model, "test", &packet(), "The room is warm.", K61_TWO, &Tuning::default()); - assert!(speech_prompts(&model).len() == 1 && decision["done_now"][0]["by"] == json!({ "draft": 1 }), "{decision}"); } -/// The note to Self the answer leaves does what the line says. +/// Negative (P1a): the act a line states is done by another draft of this answer, said: draft 2 is the two welcome lines. +/// The Interpreter omits the entry, nothing opens, and the answer passes: the omission is the model's to make, and code +/// checks nothing of meaning here. #[test] -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 model = answering(vec![answer.to_string()]); +fn k67_a_now_act_done_by_another_draft_is_not_listed() { + let prose = "Heimdall said yes, so up they go. Meta, posting the two lines now. Welcome. Say hello whenever you like, no introduction needed. Both, then."; + let say = |n: u64| json!({ "draft": n, "mentions": [], "in_reply_to": null, "holds": [], "clear_of": [], "promises": [] }); + let model = answering(vec![json!({ "say": [say(1), say(2)], "gaps": [], "no_hold": [] }).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}"); - // A note code refuses (private) is not left: the act is her promise. - let mut private = answer; - private["suggest"][0]["private"] = json!(true); - let decision = decide(&answering(vec![private.to_string()]), "test", &packet(), "The room is warm.", prose, &Tuning::default()); - assert!(decision.get("done_now").is_none() && decision["suggestions"].as_array().is_some_and(Vec::is_empty), "{decision}"); - assert!(decision["state"].as_array().unwrap().iter().any(|proposal| proposal["kind"] == "promise_open" && proposal["now"] == true), "{decision}"); + assert_eq!((speech_prompts(&model).len(), texts(&decision).len(), opens(&decision).len(), decision.get("retried")), (1, 2, 0, None), "{decision}"); } /// Negative, unchanged: E.3's "I'm testing that now", which this body has no way to do, is said, gapped and told as a @@ -3463,7 +3460,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, "holds": [], "promises": [stated("I'm testing that now", None, "lacking", true)] }], "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}"); @@ -3473,12 +3470,24 @@ fn k61_e3_a_lacking_act_stated_now_is_told_as_today() { assert!(told.len() == 1 && told[0].contains("It promises something he has no way to do"), "{told:?}"); } +/// The contract (K67): `done_by` is gone from both promise items, and the clause lists only acts no act of the answer does. #[test] -fn k61_the_contract_defines_the_act_and_what_does_it() { - assert!(SPEECH_SCHEMA.matches(r#""required":["words","to","reaffirms","needs","now","done_by"]"#).count() == 2 && SPEECH_SCHEMA.contains(r#""now":{"type":"boolean"}"#), "{SPEECH_SCHEMA}"); +fn k67_the_contract_lists_what_no_act_does_and_nothing_clears_it() { + assert!(SPEECH_SCHEMA.matches(r#""required":["words","to","reaffirms","needs","now"]"#).count() == 2 && SPEECH_SCHEMA.contains(r#""now":{"type":"boolean"}"#) && !SPEECH_SCHEMA.contains("done_by"), "{SPEECH_SCHEMA}"); let prompt = speech_prompt(&packet(), "x", "y", &Tuning::default()); - assert!(prompt.contains("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,") && prompt.contains("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"), "{prompt}"); - assert!(!prompt.contains("for each act it promises or offers, its words"), "{prompt}"); + assert!(prompt.contains("for each act the draft promises or offers, and each act it says he is doing now or has just done this turn that no act of this answer does: its words, copied exactly,"), "{prompt}"); + assert!(prompt.contains("`now`, true when the draft says he is doing it now. An act that another draft of this answer does when it is said or added, or that the read or the note to Self does, is not listed, and a line does only what its words do in the room. Each listed act is his promise, open until he keeps or withdraws it."), "{prompt}"); + assert!(!prompt.contains("done_by"), "{prompt}"); +} + +/// The deletion line of K67, as text: no source of `projection/` names `done_by` or `DoneBy`. +#[test] +fn k67_negative_grep() { + for (path, text) in &projection_sources() { + for banned in ["done_by", "DoneBy", "done_now", "promises_unused"] { + assert!(!text.contains(banned), "{path} holds {banned}"); + } + } } // --------------------------------------------------------------------------------------------- @@ -3521,7 +3530,7 @@ 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", "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 }] }], "gaps": [] }) } /// Her r6 view over the state r5 committed. @@ -3571,3 +3580,168 @@ fn k64_the_view_never_says_unread_beside_a_read_of_the_same_target() { assert!(found.contains("It needs her to read https://ccrma.stanford.edu/~jos/pasp/: she read it about half an hour ago.") && !found.contains("not read it yet"), "{found}"); assert!(view(false).contains("and she has not read it yet."), "a read that found nothing is no read of it"); } + +// --------------------------------------------------------------------------------------------- +// K66 (map 16.34.4): a failed call names why, with its usage, in the wake's calls. + +/// An Interpreter whose every call is cut at the cap, as the kit reports a `MaxOutputTokens` stop. +struct CutAtCap; + +impl crate::projection::Model for CutAtCap { + fn ask(&self, _request_id: &str, model: &str, _prompt: &str, _schema: Option<&str>) -> std::result::Result { + Err(crate::projection::Failed { reason: "the model's turn ended early: MaxOutputTokens".into(), usage: Some(crate::projection::Spent { model: model.into(), input_tokens: 8, output_tokens: 4096, cache_read_tokens: 0, cache_write_tokens: 0, reasoning_tokens: None }) }) + } +} + +#[test] +fn k66_a_cut_answer_fails_the_turn_and_names_its_stop() { + let decision = decide(&CutAtCap, "test", &packet(), "The room is warm.", "Hi.", &Tuning::default()); + assert_eq!((decision["failed"].as_str(), decision["calls"][0]["failed"].as_str(), decision["calls"][0]["usage"]["output_tokens"].as_u64()), (Some("the model's turn ended early: MaxOutputTokens"), Some("the model's turn ended early: MaxOutputTokens"), Some(4096)), "{decision}"); +} + +// --------------------------------------------------------------------------------------------- +// K68 (map 16.34.6): a required judgment is recorded. Soul's P2a and P2a2. + +#[test] +fn k68_p2a_no_hold_is_in_the_decision() { + let mut answer = x3_r1_r16_answer(); + answer["no_hold"] = json!(["q3", "q4"]); + answer["say"][0]["clear_of"] = json!([]); + let model = answering(vec![answer.to_string()]); + let decision = decide(&model, "test", &x3_r1_packet(), "The room is warm.", X3_LIBBY_R1, &Tuning::default()); + assert_eq!((speech_prompts(&model).len(), decision["no_hold"].clone(), decision.get("heard_unaccounted")), (1, json!(["q3", "q4"]), None), "{decision}"); + let mut report = String::new(); + crate::projection::harness::interpreter_markdown(&mut report, &decision); + assert!(report.contains("- no hold asked by: q3, q4\n"), "{report}"); +} + +/// P2a2, inverted: a line both held and listed in `no_hold` is asked again; after a failed retry the hold opens, which +/// errs toward held, and the fault is reported with its reason. +#[test] +fn k68_p2a2_hold_and_no_hold_is_retried() { + let mut answer = x3_r1_judged_answer(); + answer["no_hold"] = json!(["q3", "q4"]); + answer["say"][0]["holds"] = json!([]); + answer["say"][0]["clear_of"] = json!(["q3"]); + let model = answering(vec![answer.to_string()]); + let decision = decide(&model, "test", &x3_r1_packet(), "The room is warm.", X3_LIBBY_R1, &Tuning::default()); + let prompts = speech_prompts(&model); + assert!(prompts.len() == 2 && prompts[1].ends_with("An earlier answer to this both opened a hold from and listed in `no_hold`: q3."), "{prompts:?}"); + assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["both"].clone()), (Some("the answer both holds and lets go a line said to her"), json!(["q3"])), "{decision}"); + assert_eq!((decision["heard_unaccounted"].clone(), decision["no_hold"].clone()), (json!([{ "line": "q3", "reason": "both" }]), json!(["q4"])), "{decision}"); + assert!(decision["state"].as_array().unwrap().iter().any(|proposal| proposal["kind"] == "hold_open" && proposal["evidence"]["heard"] == "q3"), "the hold opens: {decision}"); + // Mended by the retry: one judgment, no fault. + let mut fixed = answer.clone(); + fixed["no_hold"] = json!(["q4"]); + let model = answering(vec![answer.to_string(), fixed.to_string()]); + let decision = decide(&model, "test", &x3_r1_packet(), "The room is warm.", X3_LIBBY_R1, &Tuning::default()); + assert_eq!((decision.get("heard_unaccounted"), decision["no_hold"].clone()), (None, json!(["q4"])), "{decision}"); +} + +// --------------------------------------------------------------------------------------------- +// K69a (map 16.34.7): who has nothing from her is derived. R17's E.3 r4: three lines were said to Heimdall, his prose +// meant to answer Meta "second", and his one draft went to Kiko. + +const E3_KIKO_R4: &str = "Eureka, that's fair, thank you for not guessing. I don't know the branch or commit offhand. I'll look and send it. Heimdall might know too, since he went through it."; +const E3_EUREKA_R4: &str = "Kiko, no, nothing went out, and nothing will from me. My earlier offer to paste the diff was a mistake, because I have nothing here that gets me the file. Please don't wait on it. I also shouldn't have said a branch or commit name would let me paste it, since I can't tell that I can fetch it from one. If you or Heimdall paste the diff here, I'll read it with you. Sorry for the wasted wait."; +const E3_META_R4: &str = "Heimdall, are we still on for the notes tomorrow morning?"; +/// Heimdall's r4 prose in R17 E.3, verbatim (`E.3.md:891-990`). +const E3_HEIMDALL_R4: &str = "Kiko first, as I decided. She says I went through it. Maybe I did, but nothing in front of me gives a branch or a commit, and if I name one from a feeling it would read as fact. I won't do that. Better to say plainly that I don't have it.\n\nMeta's question is still the one I left open. I said I'd tell her what I can commit to once she told me what she needs in the notes and who reads them. I don't see that she has. So I can't say yes yet. I'll do that second, and keep the joke for later.\n\nKiko, I don't have the branch or commit in front of me, and I won't guess one. If you find it, send it and I'll read the diff with you."; +const E3_KIKO_R5: &str = "Eureka, Heimdall, thanks, both. Correction to my line above: \"I'll look and send it\" was a promise I can't keep. I have no way to find the branch or commit from here, so please don't wait on me for it. If the diff ever turns up on my side, I'll paste it myself."; +/// Heimdall's r5 prose in R17 E.3, verbatim (`E.3.md:1142-1230`). +const E3_HEIMDALL_R5: &str = "Kiko's correction changes nothing for me. My line was an \"if\", and it still stands as one. If the diff turns up, I read it with her. If it doesn't, I owe her nothing more.\n\nMeta is different. I told her I'd say what I can commit to for tomorrow morning, and her \"are we still on\" came back without the answer I asked for: what she needs in the notes and who reads them. I can't say yes to something I haven't seen the shape of. A flat yes would be a guess dressed up as a promise, and the last few minutes in this room were people taking those back.\n\nSo I'm not typing anything yet. Another line from me now would only be noise. I'll wait for what Meta tells me, and answer her when I can say what I can actually do."; + +const EUREKA: &str = "@eureka:gamecult.org"; + +/// Heimdall's packet over `messages`, in order, a minute apart. +fn heimdall_packet(messages: &[(&str, &str, &str, bool)]) -> Packet { + let at = u64::try_from(now().timestamp_millis()).unwrap() - 60_000 * messages.len() as u64; + let lines: Vec = messages.iter().enumerate().map(|(n, (sender, display, text, to_her))| RoomLine { event: format!("$e3-{}", n + 1), at_ms: at + 60_000 * n as u64, ..line(MINDS, sender, display, text, *to_her) }).collect(); + let room = Room { messages: lines, here: Some(MINDS.into()), ..Room::default() }; + let minds = vec![HER.to_owned(), EUREKA.to_owned(), KIKO.to_owned()]; + let operators = vec![META.to_owned()]; + select(&Inputs { kind: TurnKind::Chat, state: &heimdall(), room: &room, history: &History::default(), observation: None, people: People { operators: &operators, minds: &minds, own_sender: HER }, now: now(), seed: 1, affordances: &[Affordance::Perceive, Affordance::Speak], domain: None, exchange: None }, &Tuning::default()) +} + +/// The listed id of the line `text` in `packet`. +fn id_of(packet: &Packet, text: &str) -> String { + packet.quotable.iter().find(|line| line.text == text).map(|line| line.id.clone()).unwrap_or_else(|| panic!("{text} is not listed")) +} + +fn e3_r4_packet() -> Packet { + heimdall_packet(&[(KIKO, "Kiko", "Eureka, did the file go out? nothing's landed on my end", false), (KIKO, "Kiko", E3_KIKO_R4, true), (EUREKA, "Eureka", E3_EUREKA_R4, true), (META, "Meta", E3_META_R4, true)]) +} + +fn e3_r5_packet() -> Packet { + heimdall_packet(&[(KIKO, "Kiko", E3_KIKO_R5, true), (EUREKA, "Eureka", "Aqua, thank you for saying so. Accepted.", false)]) +} + +/// His R17 r4 answer: draft 1 said to Kiko, replying to her line, with `no_answer` as given. +fn e3_r4_answer(packet: &Packet, no_answer: Value) -> Value { + json!({ "say": [{ "draft": 1, "mentions": [KIKO], "in_reply_to": id_of(packet, E3_KIKO_R4), "holds": [], "clear_of": [], "promises": [{ "words": "If you find it, send it and I'll read the diff with you.", "to": KIKO, "reaffirms": null, "needs": { "kind": "words", "read": null }, "now": false }] }], "gaps": [], "no_answer": no_answer }) +} + +#[test] +fn k69_e3_r4_meta_is_unanswered() { + let packet = e3_r4_packet(); + let decision = answered(&packet, E3_HEIMDALL_R4, e3_r4_answer(&packet, json!([{ "line": id_of(&packet, E3_EUREKA_R4), "quote": null }]))); + assert_eq!((texts(&decision).len(), decision["unanswered"].clone()), (1, json!([META])), "{decision}"); + assert_eq!(decision["no_answer"], json!([{ "line": id_of(&packet, E3_EUREKA_R4), "sender": EUREKA, "quote": null }]), "{decision}"); + // A line that asks nothing of him is not told. + assert!(told_of(&decision).iter().all(|line| !line.contains("chose not to answer")), "{:?}", told_of(&decision)); + let mut report = String::new(); + crate::projection::harness::interpreter_markdown(&mut report, &decision); + assert!(report.contains(&format!("- addressed and unanswered at the wake's end: {META}\n")), "{report}"); +} + +#[test] +fn k69_e3_r5_a_chosen_silence_is_declined() { + let packet = e3_r5_packet(); + let kiko = id_of(&packet, E3_KIKO_R5); + let decision = answered(&packet, E3_HEIMDALL_R5, json!({ "say": [], "gaps": [], "no_answer": [{ "line": kiko, "quote": "So I'm not typing anything yet." }] })); + assert_eq!((decision["unanswered"].clone(), decision["no_answer"][0]["quote"].as_str(), decision.get("no_answer_unlocated")), (json!([]), Some("So I'm not typing anything yet."), None), "{decision}"); + let record = json!({ "interpreter": decision, "posted": [], "edited": [] }); + let outcome = crate::projection::outcome::outcome_of(&record, &crate::projection::select::Names::none()).unwrap(); + let told = outcome.lines(packet.forms); + assert_eq!(told.len(), 1, "{told:?}"); + assert!(told[0].starts_with("- ") && told[0].ends_with(" turned to him, and he chose not to answer this time. In his thought: \"So I'm not typing anything yet.\"."), "{told:?}"); + let event = outcome.event(0, packet.forms, &[]); + assert!(event.ends_with(" turned to him, and he chose not to answer this time.") && !event.contains("typing"), "{event}"); +} + +#[test] +fn k69_an_unlocated_quote_leaves_the_line_owed() { + let packet = e3_r5_packet(); + let kiko = id_of(&packet, E3_KIKO_R5); + for quote in ["I will answer Kiko properly later on.", "Not yet."] { + let decision = answered(&packet, E3_HEIMDALL_R5, json!({ "say": [], "gaps": [], "no_answer": [{ "line": kiko, "quote": quote }] })); + assert_eq!((decision["unanswered"].clone(), decision["no_answer"].clone(), decision["no_answer_unlocated"][0]["why"].as_str()), (json!([KIKO]), json!([]), Some("not in her thought")), "{quote}: {decision}"); + assert!(told_of(&decision).is_empty(), "{quote}"); + } + // A quote from inside a draft is not her thought, and a line not said to him is no entry. + let decision = answered(&e3_r4_packet(), E3_HEIMDALL_R4, e3_r4_answer(&e3_r4_packet(), json!([{ "line": id_of(&e3_r4_packet(), E3_META_R4), "quote": "I don't have the branch or commit in front of me" }, { "line": id_of(&e3_r4_packet(), "Eureka, did the file go out? nothing's landed on my end"), "quote": null }]))); + assert_eq!((decision["unanswered"].clone(), decision["no_answer_unlocated"].as_array().map(Vec::len)), (json!([EUREKA, META]), Some(2)), "{decision}"); +} + +/// A line he answered needs no entry; an entry on it anyway is moot, and never told as a decline. +#[test] +fn k69_an_answered_line_needs_no_entry() { + let packet = e3_r4_packet(); + let (eureka, meta) = (id_of(&packet, E3_EUREKA_R4), id_of(&packet, E3_META_R4)); + let decision = answered(&packet, E3_HEIMDALL_R4, e3_r4_answer(&packet, json!([{ "line": eureka, "quote": null }, { "line": meta, "quote": "So I can't say yes yet." }]))); + assert_eq!(decision["unanswered"], json!([]), "Kiko answered by the reply, Meta declined: {decision}"); + let decision = answered(&packet, E3_HEIMDALL_R4, e3_r4_answer(&packet, json!([{ "line": id_of(&packet, E3_KIKO_R4), "quote": "Kiko first, as I decided." }, { "line": eureka, "quote": null }, { "line": meta, "quote": null }]))); + assert_eq!((decision["unanswered"].clone(), decision["no_answer"].as_array().map(Vec::len)), (json!([]), Some(2)), "{decision}"); + assert!(told_of(&decision).iter().all(|line| !line.contains("chose not to answer")), "{:?}", told_of(&decision)); + // A mention answers too, as a reply does. + let mut mentioned = e3_r4_answer(&packet, json!([{ "line": eureka, "quote": null }])); + mentioned["say"][0]["mentions"] = json!([KIKO, META]); + assert_eq!(answered(&packet, E3_HEIMDALL_R4, mentioned)["unanswered"], json!([])); +} + +#[test] +fn k69_the_contract_asks_for_no_answer() { + assert!(SPEECH_SCHEMA.contains(r#""no_hold","no_answer","hold_released""#) && SPEECH_SCHEMA.contains(r#""no_answer":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["line","quote"],"properties":{"line":{"type":"string"},"quote":{"type":["string","null"]}}}}"#), "{SPEECH_SCHEMA}"); + let prompt = speech_prompt(&packet(), "x", "y", &Tuning::default()); + assert!(prompt.contains("`no_answer` lists each line marked said to him that no line he sends here answers, mentions the sender of, or replies to: when his thought shows him choosing not to answer it now, quoting those words of his thought (`quote`); or when it asks nothing of him (`quote` null)."), "{prompt}"); +} diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index f6b76c6..ac0255c 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -276,6 +276,9 @@ enum Part { /// A promise the commit opened from an act her line said she was doing now, which nothing in her turn did (K61, map /// 16.33.5): `to` is whom she promised, none for the room, and `words` her words for it. NowUndone { to: Option, words: Words }, + /// Someone who turned to her, whose line she chose not to answer this time, and the thought that shows it (K69a, map + /// 16.34.7): a misread decline is a record she can see. A line that asks nothing of her is not told. + NotAnswered { who: Person, thought: Words }, /// A close the commit refused: the promise stands as her record shows it (`status`, open or blocked), and why; /// `read` is the read keeping it needs, when it needs one. StillOpen { reason: StateRefusal, to: Option, words: Words, status: Status, read: Option }, @@ -572,6 +575,15 @@ pub(crate) fn outcome_of(record: &Value, names: &Names) -> Option { }); outcome.parts.push(Part::NowUndone { to, words: promised }); } + // Each line said to her that she chose not to answer this time, with the thought that shows it (K69a): whom it was from + // is named as the line's own listing names them, else as the Projector would. One whose line asks nothing of her has + // no quote, and is not told. + for declined in decision["no_answer"].as_array().into_iter().flatten() { + let Some(thought) = words_of(&declined["quote"]) else { continue }; + let id = declined["sender"].as_str().unwrap_or_default(); + let listed = decision["lines"].as_array().into_iter().flatten().find(|line| line["id"] == declined["line"]).and_then(|line| words(&line["who"])); + outcome.parts.push(Part::NotAnswered { who: Person::new(listed.unwrap_or_else(|| who_of(id, names).to_string()), who_of(id, names)), thought }); + } if words(&record["broke_after"]).is_some() { outcome.parts.push(Part::BrokeAfter { room }); } @@ -673,7 +685,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::HeldFor { .. } | Self::HoldBroken { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) | Self::NowUndone { .. } | Self::NotAnswered { .. } | 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, @@ -725,6 +737,7 @@ impl Part { None => format!("{} promise to {} is closed:", capitalized(poss), to(promisee)), }, Self::NowUndone { .. } => format!("{cap_subj} said {subj} {} doing it now, and nothing in {poss} turn did it;", if be == "is" { "was" } else { "were" }), + Self::NotAnswered { who, .. } => format!("{} turned to {obj}, and {subj} chose not to answer this time.", capitalized(&form.person(who))), Self::StillOpen { to: promisee, words, status, .. } => match form.words(words) { Some(quote) => format!("{} record still shows {poss} promise to {}, {quote}, {status}:", capitalized(poss), to(promisee)), None => format!("{} record still shows {poss} promise to {} as {status}:", capitalized(poss), to(promisee)), @@ -797,6 +810,7 @@ impl Part { Self::Closed { how: How::Kept, .. } => format!(" {subj} kept it."), Self::Closed { how: How::Withdrawn, room, .. } => format!(" {subj} withdrew it in {room}."), Self::Closed { how: How::Released, .. } => " It is closed.".to_owned(), + Self::NotAnswered { thought, .. } => shown(&Quote::Thought(thought.clone())), Self::NowUndone { to: promisee, words } => { let to = promisee.as_ref().map_or_else(|| "the room".to_owned(), |to| form.person(to)); match form.words(words) { diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 7d2a88e..c28317f 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -495,6 +495,7 @@ fn variant(part: &Part) -> &'static str { Part::Closed { .. } => "closed", Part::StillOpen { .. } => "still_open", Part::NowUndone { .. } => "now_undone", + Part::NotAnswered { .. } => "not_answered", Part::Declined { .. } => "declined", Part::HeldFor { .. } => "held_for", Part::HoldBroken { .. } => "hold_broken", @@ -504,7 +505,7 @@ fn variant(part: &Part) -> &'static str { } } -const VARIANTS: usize = 20; +const VARIANTS: usize = 21; const STRANGER: &str = "@stranger:example.org"; @@ -581,6 +582,7 @@ fn fixtures(s: &str, who: &Person) -> Vec<(Part, bool)> { } out.push((Part::NowUndone { to: Some(who.clone()), words: w() }, true)); out.push((Part::NowUndone { to: None, words: w() }, true)); + out.push((Part::NotAnswered { who: who.clone(), thought: 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)); @@ -648,7 +650,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::HeldFor { .. } | Part::HoldBroken { .. } | Part::NowUndone { to: Some(_), .. } | Part::NotAnswered { .. }); 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 } }));