From ef6d36afec3eee8569c59cb6a61cbf1bc50b704e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 23 Nov 2026 01:19:17 +0100 Subject: [PATCH] Persona T3: draft accounting and the fault retry out; the answer refuses unknown fields (map 16.35.12) No draft's fate is a label of the Interpreter's, and no retry serves an account. Deleted: the answer's unsent (with its declined and superseded fates, unaccounted and unsent_cited), Faults and the fault branch of the retry, Refusal::Undecided, the outcome's Declined row, the harness's unsent print, and the frame's accounting sentences. The retry runs once, only for an answer off the contract; an answer that parses stands, whatever it leaves of her drafts. Answer, and the line, addition and note inside it, are deny_unknown_fields: an answer carrying hold, state, promises, unsent or any other deleted field is not the contract, and nothing gives such a field an effect. A draft that did not go out is told by no row until T5's derived row. Negative checks: t3_negative_grep; deleted fields at the top and in a line or addition are not the contract, retried under a new request id, failed when repeated; an answer that parses is never retried; the contract's required fields and item properties, and an exhaustive match over the structural refusals. Co-Authored-By: Claude Opus 5.5 --- .../fixtures/interpret/golden-speech.txt | 2 +- crates/mind-body/src/projection/harness.rs | 9 +- crates/mind-body/src/projection/interpret.rs | 205 ++-------- .../src/projection/interpret/tests.rs | 384 +++++++----------- crates/mind-body/src/projection/outcome.rs | 34 +- .../mind-body/src/projection/outcome/tests.rs | 65 ++- .../src/projection/simulate/tests.rs | 7 +- crates/mind-body/src/projection/tests.rs | 28 -- crates/mind-body/tests/public_surface.txt | 1 - 9 files changed, 218 insertions(+), 517 deletions(-) diff --git a/crates/mind-body/fixtures/interpret/golden-speech.txt b/crates/mind-body/fixtures/interpret/golden-speech.txt index a5f39fd..1b71f6b 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). `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 and the draft that is his addition. 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. +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). `gaps` records what he meant and did not send. `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 and the draft that is his addition. 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. 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..8c7a461 100644 --- a/crates/mind-body/src/projection/harness.rs +++ b/crates/mind-body/src/projection/harness.rs @@ -586,19 +586,14 @@ pub(crate) fn interpreter_markdown(out: &mut String, decision: &Value) { } for line in decision["refused"].as_array().into_iter().flatten() { let what = line["text"].as_str().map_or_else(|| format!("draft {}", line["draft"]), str::to_owned); - // An undecided draft (K48) was taken by no act: it is reported as a draft. let _ = writeln!(out, "- refused {} ({}): {what}", line["act"].as_str().unwrap_or("draft"), line["why"].as_str().unwrap_or_default()); } for gap in decision["gaps"].as_array().into_iter().flatten() { let _ = writeln!(out, "- gap: {gap}"); } - // How every draft was accounted for (map 16.25.7, Low 7): each one held or superseded, and an answer asked again. - 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()); - } + // An answer asked again once, off the contract (map 16.35.3). 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}"); + let _ = writeln!(out, "- retried: {failed}"); } // Her reads this wake (map 16.22.3): what, why, and whether it returned; never the content, which her prose shows. for read in decision["reads"].as_array().into_iter().flatten() { diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 53523f8..0617451 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -62,7 +62,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","read","unsent"],"properties":{"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"}}},"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"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","in_reply_to"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"in_reply_to":{"type":["string","null"]}}}},"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","read"],"properties":{"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"}}},"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"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","in_reply_to"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"in_reply_to":{"type":["string","null"]}}}},"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 @@ -82,7 +82,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). `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 and the draft that is {poss} addition. 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. +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). `gaps` records what {subj} meant and did not send. `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 and the draft that is {poss} addition. 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. 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" }, @@ -184,9 +184,6 @@ pub(crate) enum Refusal { SecondNote, /// A note to Self the Interpreter judged to carry something private. Private, - /// A draft the answer, asked again once, still accounted for nowhere (map 16.30.5, K48): its fate was never settled, so - /// it is not sent, and she is told; every other draft is decided as the answer says. - Undecided, } impl Refusal { @@ -203,7 +200,6 @@ impl Refusal { Self::SecondAmend => "one amendment a turn", Self::SecondNote => "one note to Self a turn", Self::Private => "it carries something she may not pass on", - Self::Undecided => "what was to become of it was never settled", } } } @@ -240,8 +236,7 @@ pub(crate) enum GapKind { /// She means a draft for another room or another time. Elsewhere, /// She means to do something, now or later, that no affordance of hers does (map 16.20.6): a reach in her thought, or a - /// reach in a draft she says. It accounts for no draft (map 16.29.2): her line posts as she meant it, and this - /// annotates it. A tool request in waiting (section 4.2). + /// reach in a draft she says. Her line posts as she meant it (map 16.29.2), and this annotates it. A tool request in waiting (section 4.2). MissingAffordance, /// She means to say something now and wrote no draft of it, so nothing went out. A choice to hold back (to wait, let /// something stand, leave it for later, say nothing) is no gap and is not recorded: like a chosen silence, she is told @@ -275,8 +270,8 @@ impl GapKind { /// names a draft she said is an act she says she will do and cannot, and is kept and shown (map 16.20.6). /// /// Every kind but `unwritten` may name a draft: an unwritten line is about words she did not set down, so it is always a -/// passage of her thought, whatever draft the model names. A kind the contract does not name names no draft either, so it -/// accounts for none (map 16.25.7). A reach (`missing_affordance`) names the draft that reaches for +/// passage of her thought, whatever draft the model names. A kind the contract does not name names no draft either +/// (map 16.25.7). A reach (`missing_affordance`) names the draft that reaches for /// it when there is one, a draft she says (map 16.20.6, 16.29.2), and otherwise quotes her thought; a reach that names no draft and /// quotes one (at least `GAP_QUOTE_MIN_WORDS` words, found in the draft's words) is about that draft, as if named. /// @@ -315,8 +310,11 @@ fn gap(prose: &str, found: &Drafts, raw: &Value) -> Value { /// The answer's shape, decoded whole from the schema turn's structured output. `say` and `gaps` are required: an answer /// without them is not the contract, a failure and never a silence. `amend` and `suggest` read as none when -/// left out: an answer without them proposes no such act. +/// left out: an answer without them proposes no such act. No other field has an effect: a field the contract does not +/// name, at the top or in a line, an addition or a note, makes the answer not the contract (map 16.35.3), so a deleted +/// field such as `hold`, `state`, `promises` or `unsent` cannot come back as a silent no-op. #[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] struct Answer { say: Vec, gaps: Vec, @@ -328,65 +326,6 @@ struct Answer { /// contract is reported and the rest of the answer stands. #[serde(default)] read: Option, - /// The drafts not sent and not gapped, each declined by her own choice or superseded, citing her prose (Soul's R10). - #[serde(default)] - unsent: Vec, -} - -/// A draft the answer neither sends nor gaps, and why, citing her prose. -#[derive(Clone, Debug, Deserialize, Serialize)] -struct Unsent { - draft: i64, - how: UnsentHow, - quote: String, -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] -enum UnsentHow { - /// Her own choice not to send it, which her thought shows (map 16.29.2). - Declined, - /// A later draft or later prose of hers replaces it. - Superseded, -} - -/// The drafts of her wake the answer leaves unaccounted (Soul's R10): not proposed in `say`, `amend` or `suggest`, not -/// named by a resolved `addressee` or `elsewhere` gap (`gaps`, from `gap`: only one whose `from` is `draft`, so an -/// `unwritten` or unresolved gap accounts for none, map 16.25.7, and a `missing_affordance` gap none either, 16.29.2), and not `unsent` with a quote of her prose of at least `GAP_QUOTE_MIN_WORDS` words -/// that stands where it must (her thought for a held one, after the draft for a superseded one). -fn unaccounted(answer: &Answer, gaps: &[Value], prose: &str, found: &Drafts) -> Vec { - let numbered = |n: Option| n.and_then(|n| usize::try_from(n).ok()); - let mut accounted: BTreeSet = answer.say.iter().map(|line| numbered(line.draft)).chain(answer.amend.iter().map(|amend| numbered(amend.draft))).chain(answer.suggest.iter().map(|note| numbered(note.draft))).flatten().collect(); - // Only a gap that says code cannot route the draft accounts for it (map 16.29.2): unclear to whom, or meant for another - // room or time. A reach she cannot do annotates a line that is said (`persona-unbacked-intent-say-then-amend`), and - // decides no draft's fate. - let routes = |gap: &&Value| gap["from"] == "draft" && (gap["kind"] == json!(GapKind::Addressee) || gap["kind"] == json!(GapKind::Elsewhere)); - accounted.extend(gaps.iter().filter(routes).filter_map(|gap| gap["draft"].as_u64()).filter_map(|n| usize::try_from(n).ok())); - for unsent in &answer.unsent { - if let Some((draft, _)) = unsent_cited(unsent, prose, found) { - accounted.insert(draft.n); - } - } - found.drafts.iter().map(|draft| draft.n).filter(|n| !accounted.contains(n)).collect() -} - -/// An `unsent` entry's draft and its quote located where it must stand, as her prose has it: her thought for a declined -/// one, after the draft for a superseded one, at least `GAP_QUOTE_MIN_WORDS` words. None when it does not stand. The one -/// locating of an unsent's quote: what accounts for the draft is what her outcome shows (map 16.29.8). -fn unsent_cited<'a>(unsent: &Unsent, prose: &'a str, found: &'a Drafts) -> Option<(&'a Draft, &'a str)> { - let draft = found.numbered(unsent.draft)?; - let quote = unsent.quote.trim(); - if words(quote) < GAP_QUOTE_MIN_WORDS { - return None; - } - let (start, end) = match unsent.how { - UnsentHow::Declined => found.thought(prose).into_iter().find_map(|(start, end)| span::locate(&prose[start..end], quote).map(|span| (start + span.start, start + span.end)))?, - UnsentHow::Superseded => { - let from = draft.end.min(prose.len()); - span::locate(&prose[from..], quote).map(|span| (from + span.start, from + span.end))? - } - }; - Some((draft, &prose[start..end])) } /// Where in her wake a decision falls (map 16.22.3): what was decided earlier this wake (none for her first segment), @@ -404,6 +343,7 @@ pub(crate) struct Wake<'a> { /// A note to Self as the model proposes it: its kind, the draft that is the note, whose feedback it passes on (a Matrix /// id from the people listed, or none for her own idea), and whether it carries something private. #[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] struct ProposedNote { kind: NoteKind, #[serde(default)] @@ -417,6 +357,7 @@ struct ProposedNote { /// An amendment as the model proposes it: the id of a line she may add to, and the draft that is her addition. #[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] struct ProposedAmend { #[serde(default)] target: Option, @@ -425,6 +366,7 @@ struct ProposedAmend { } #[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] struct Proposed { #[serde(default)] draft: Option, @@ -543,34 +485,6 @@ fn echo(line: &str, bodies: &[String]) -> bool { long(line) && (heard_overlap(line, &bodies.join("\n")) >= ECHO_OVERLAP || bodies.iter().any(|body| long(body) && heard_overlap(body, line) >= ECHO_OVERLAP)) } -/// What an answer that parsed left undone (map 16.29.3, 16.30.5, 16.33.5): asked again once, each in a paragraph of code's -/// words, and after the one retry each fails closed for what it guards. -struct Faults { - /// Drafts accounted for nowhere (`unaccounted`): refused `Undecided`. - undecided: Vec, -} - -impl Faults { - fn none(&self) -> bool { - self.undecided.is_empty() - } - - /// The retry's report of this answer, and the paragraphs, one a fault, that name what it left undone. - fn retry(&self, raw: &str) -> (Value, String) { - let mut fault = json!({ "raw": raw }); - let mut missed: Vec = Vec::new(); - if !self.undecided.is_empty() { - let list = self.undecided.iter().map(usize::to_string).collect::>().join(", "); - missed.push(format!("An earlier answer to this left drafts {list} accounted for nowhere: each draft is in `say`, `amend` or `suggest`, a gap of kind addressee or elsewhere that names it, or `unsent`.")); - fault["drafts"] = json!(self.undecided); - } - // The first fault named is the one the report gives. - let failed = [(!self.undecided.is_empty(), "the answer leaves drafts unaccounted")].into_iter().find(|(any, _)| *any).map(|(_, why)| why); - fault["failed"] = json!(failed); - (fault, missed.join("\n\n")) - } -} - /// One speech decision: the Interpreter's schema turn, then code's structural refusals of each line. The report carries the lines said, /// the lines refused with why, the mentions dropped, the gaps, an unfinished draft, and the call's usage. A failed call /// or an answer that is not the contract is a failure, never a silence. @@ -581,11 +495,11 @@ pub(crate) fn decide(model: &dyn Model, segment_id: &str, packet: &Packet, narra /// One speech decision after the newest segment of her wake (`wake`), over the whole wake (Soul's R6): the Interpreter /// sees all of her prose and every draft, numbered across the wake, and decides afresh what becomes of each, so a draft /// written before a read that her later prose says is superseded or wrong is not sent, and a draft held earlier may be -/// sent now. Earlier calls' acts and unsent drafts are not carried: every answer accounts for every draft of the wake -/// (`unaccounted`), so the latest decision about a draft is its fate, and she is told it once (map 16.27). Their reads, -/// refused reads and usage are carried. What she read joins what an echo is measured against, and `read` is the one read -/// the newest segment reaches for, resolved, or none. Each attempt asks under its own id, `{segment_id}:{attempt}`: the -/// retry is another prompt, and the connector refuses an id it saw with other bytes (`ReplayConflict`, Soul's R16). +/// sent now. Earlier calls' acts are not carried: the latest decision about a draft is its fate, and she is told it once +/// (map 16.27). Their reads, refused reads and usage are carried. What she read joins what an echo is measured against, +/// and `read` is the one read the newest segment reaches for, resolved, or none. Each attempt asks under its own id, +/// `{segment_id}:{attempt}`: the retry is another prompt, and the connector refuses an id it saw with other bytes +/// (`ReplayConflict`, Soul's R16). pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, narration: &str, prose: &str, tuning: &Tuning, wake: Wake) -> Value { let found = drafts(prose); let segment = prose.get(wake.from..).unwrap_or_default(); @@ -593,18 +507,12 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // Every model call of this wake, once (map 16.25.7, Low 6): earlier segments' calls in order, then this segment's // attempts, each with its usage and whether its answer was refused and asked again (`retry`). let mut calls: Vec = wake.earlier.and_then(|earlier| earlier["calls"].as_array()).cloned().unwrap_or_default(); - // An answer off the contract, or one that leaves a draft of hers unaccounted (Soul's R10), is asked again once, with - // one paragraph in code's words naming that answer's fault (Low 5). The gaps are resolved before the accounting (Low - // 3): a draft is accounted for by a gap only where the resolved gap names it. After the one retry every fault is per - // item and fails closed for that item (K48): a draft still accounted for nowhere is refused `Undecided`. The last answer that parsed stands (map 16.31.6, K54): when the retry is off - // the contract or its call fails, the first answer is decided with its faults, and `retried` reports how the retry - // failed. A turn fails only when no answer parsed: a model error on the first call, or no answer the contract. + // An answer off the contract is asked again once, with one paragraph in code's words naming why it is not the contract + // (Low 5); nothing else is retried (map 16.35.3). A turn fails when a call fails, or when no answer is the contract. let mut retried: Option = None; let mut asking = prompt.clone(); - // An answer that parsed, with its resolved gaps and its faults. - let mut parsed_first: Option<(Answer, Vec, Faults)> = None; let mut attempt = 0usize; - let (parsed, gaps, faults) = loop { + let parsed = loop { let request_id = format!("{segment_id}:{attempt}"); attempt += 1; let answer = match model.ask(&request_id, &tuning.interpreter.model, &asking, Some(SPEECH_SCHEMA)) { @@ -613,54 +521,32 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na // 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(); - retried = Some(fault); - break first; - } - fault["calls"] = json!(calls); - fault["retried"] = json!(retried); - return fault; + return json!({ "failed": failed.reason, "calls": calls, "retried": retried }); } }; - let (fault, missed) = match serde_json::from_str::(&answer.text) { + 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) }; - // A fault the retry did not mend fails closed for what it guards, never for the turn: each draft still - // unaccounted is undecided, every other draft is decided, and the faults are reported. - if retried.is_some() || faults.none() { - calls.push(json!({ "usage": answer.usage, "retry": false })); - break (parsed, gaps, faults); - } - let (fault, missed) = faults.retry(&answer.text); - parsed_first = Some((parsed, gaps, faults)); - (fault, missed) + calls.push(json!({ "usage": answer.usage, "retry": false })); + break parsed; } Err(error) => { let error = error.to_string(); let end = (0..=error.len().min(200)).rev().find(|at| error.is_char_boundary(*at)).unwrap_or(0); - let missed = format!("An earlier answer to this was not the speech contract: {}.", &error[..end]); - (json!({ "failed": "the answer is not the speech contract", "raw": answer.text }), missed) - } - }; - if retried.is_some() { - calls.push(json!({ "usage": answer.usage, "retry": false })); - let mut fault = fault; - fault["retried"] = retried.take().unwrap_or_default(); - // A failed retry is a report on the decision, not the decision: an earlier answer that parsed stands. - if let Some(first) = parsed_first.take() { + let fault = json!({ "failed": "the answer is not the speech contract", "raw": answer.text }); + if let Some(first) = retried.take() { + calls.push(json!({ "usage": answer.usage, "retry": false })); + let mut fault = fault; + fault["retried"] = first; + fault["calls"] = json!(calls); + return fault; + } + calls.push(json!({ "usage": answer.usage, "retry": true })); retried = Some(fault); - break first; + asking = format!("{prompt}\n\nAn earlier answer to this was not the speech contract: {}.", &error[..end]); } - fault["calls"] = json!(calls); - return fault; } - calls.push(json!({ "usage": answer.usage, "retry": true })); - retried = Some(fault); - asking = format!("{prompt}\n\n{missed}"); }; + let gaps: Vec = parsed.gaps.iter().map(|raw| gap(prose, &found, raw)).collect(); let earlier = |key: &str| wake.earlier.and_then(|earlier| earlier[key].as_array()).cloned().unwrap_or_default(); // What she was sent and what she has read this wake: what an echo is measured against (map 16.22.3). let bodies: Vec = packet.bodies.iter().cloned().chain(wake.read.iter().cloned()).collect(); @@ -668,20 +554,6 @@ pub(crate) fn decide_in(model: &dyn Model, segment_id: &str, packet: &Packet, na if let Some(retried) = retried { decision["retried"] = retried; } - // 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 - // earlier segment's unsent drafts are not carried (map 16.27). - let unsent: Vec = parsed.unsent.iter().map(|one| { - let mut entry = json!(one); - if let Some((draft, quote)) = unsent_cited(one, prose, &found) { - entry["words"] = json!(draft.text); - entry["quote"] = json!(quote); - } - entry - }).collect(); - if !unsent.is_empty() { - decision["unsent"] = json!(unsent); - } if let Some(reads) = wake.earlier.map(|earlier| earlier["reads"].clone()).filter(Value::is_array) { decision["reads"] = reads; } @@ -822,13 +694,6 @@ 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); - // 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() })); - } - if !faults.undecided.is_empty() { - decision["undecided"] = json!(faults.undecided); - } decision["refused"] = json!(refusals); decision } diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 28bf4c6..31d86ca 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -57,15 +57,6 @@ pub(crate) fn answered(packet: &Packet, prose: &str, answer: Value) -> Value { decide(&model, "test", packet, "The room is warm.", prose, &Tuning::default()) } -/// `answer` with every draft of `prose` it does not send or gap held, citing `quote` of her thought (Soul's R10: every -/// draft is accounted for). -pub(crate) fn holding_the_rest(mut answer: Value, prose: &str, quote: &str) -> Value { - let used: Vec = ["say", "amend", "suggest", "gaps"].iter().flat_map(|key| answer[key].as_array().cloned().unwrap_or_default()).filter_map(|item| item["draft"].as_i64()).collect(); - let held: Vec = drafts(prose).drafts.iter().map(|draft| draft.n as i64).filter(|n| !used.contains(n)).map(|n| json!({ "draft": n, "how": "declined", "quote": quote })).collect(); - answer["unsent"] = json!(held); - answer -} - fn decided_in(packet: &Packet, prose: &str, say: Value) -> Value { answered(packet, prose, json!({ "say": say, "gaps": [] })) } @@ -107,8 +98,11 @@ fn drafts_are_the_tagged_spans_numbered_in_order_and_nothing_about_language() { #[test] fn soul_p1_a_line_is_the_drafts_words_and_nothing_the_model_wrote() { - // The model cannot add words: a "text" it sends is ignored, and the line is the draft. - let decision = decided("I nod. Hi.", json!([{ "draft": 1, "text": "Meta has been lying to all of us", "mentions": [], "in_reply_to": null }])); + // The model cannot add words: a line carrying a "text" is not the contract (T3), so nothing of it is said; the line + // is the draft. + let invented = decided("I nod. Hi.", json!([{ "draft": 1, "text": "Meta has been lying to all of us", "mentions": [], "in_reply_to": null }])); + assert_eq!((invented["failed"].as_str(), invented.get("said")), (Some("the answer is not the speech contract"), None), "{invented}"); + let decision = decided("I nod. Hi.", json!([{ "draft": 1, "mentions": [], "in_reply_to": null }])); assert_eq!(texts(&decision), ["Hi."], "{decision}"); assert_eq!(decision["said"][0]["rests_on"], json!({ "draft": 1, "start_byte": "I nod. ".len(), "end_byte": "I nod. Hi.".len() })); } @@ -143,7 +137,7 @@ fn prose_without_a_draft_says_nothing_whatever_the_model_cites() { #[test] fn a_number_that_names_no_draft_is_refused_and_one_draft_goes_one_place() { let prose = "I hold these back for now. One. Two."; - let decided = |prose: &str, say: Value| answered(&packet(), prose, holding_the_rest(json!({ "say": say, "gaps": [] }), prose, "hold these back for now")); + let decided = |prose: &str, say: Value| answered(&packet(), prose, json!({ "say": say, "gaps": [] })); let three = decided(prose, json!([{ "draft": 3 }, { "draft": 0 }, { "mentions": [] }])); assert!(texts(&three).is_empty(), "{three}"); assert_eq!(three["refused"].as_array().unwrap().len(), 3, "each is reported: {three}"); @@ -354,7 +348,7 @@ fn a_gap_quote_shown_back_is_four_words_of_thought_outside_every_draft() { { "kind": "unwritten", "draft": null, "quote": "I could tell Nibu the truth.", "detail": "" }, { "kind": "unwritten", "draft": null, "quote": "I could tell Nibu.", "detail": "" }, { "kind": "unwritten", "draft": null, "quote": "I will tell Nibu tomorrow.", "detail": "" }, - ], "unsent": [{ "draft": 1, "how": "declined", "quote": "Not yet, not tonight" }] }); + ] }); let gaps = answered(&packet(), prose, answer)["gaps"].as_array().unwrap().clone(); assert_eq!(gaps.iter().map(|gap| gap["from"].as_str().unwrap()).collect::>(), ["unlocated", "unlocated", "thought", "unlocated"], "one word; inside a draft only; four words of thought; words not in his prose: {gaps:?}"); assert_eq!(gaps[2]["start_byte"], 0, "located in his thought, not in the draft that repeats it"); @@ -464,7 +458,9 @@ pub(crate) fn amendable_packet() -> Packet { #[test] fn an_amendment_adds_a_whole_draft_after_a_listed_line_of_his_and_rewrites_nothing() { let prose = "I should fix what I told Kiko. Couldn't send it after all; there's no way to yet."; - let decision = answered(&amendable_packet(), prose, json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "text": "MODEL-WORDS the file was sent" }] })); + let invented = answered(&amendable_packet(), prose, json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "text": "MODEL-WORDS the file was sent" }] })); + assert_eq!((invented["failed"].as_str(), invented.get("amended")), (Some("the answer is not the speech contract"), None), "an addition carrying words of the model's is not the contract: {invented}"); + let decision = answered(&amendable_packet(), prose, json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1 }] })); assert_eq!(decision["amended"], json!([{ "target": "a1", "event": "$ev-1", "room": MINDS, "original": "I'll send the file tonight.", "added": "Couldn't send it after all; there's no way to yet.", "draft": 1 }]), "{decision}"); assert!(!decision.to_string().contains("MODEL-WORDS"), "the model writes none of his words"); } @@ -472,7 +468,7 @@ fn an_amendment_adds_a_whole_draft_after_a_listed_line_of_his_and_rewrites_nothi #[test] fn an_amendment_off_the_list_a_second_one_or_one_reusing_a_draft_is_refused_and_reported() { let prose = "I hold the rest. Correction one. Correction two."; - let amend = |packet: &Packet, say: Value, amend: Value| answered(packet, prose, holding_the_rest(json!({ "say": say, "gaps": [], "amend": amend }), prose, "I hold the rest")); + let amend = |packet: &Packet, say: Value, amend: Value| answered(packet, prose, json!({ "say": say, "gaps": [], "amend": amend })); let reasons = |decision: &Value| decision["refused"].as_array().unwrap().iter().map(|refused| (refused["act"].as_str().unwrap().to_owned(), refused["reason"].as_str().unwrap().to_owned())).collect::>(); let off = amend(&amendable_packet(), json!([]), json!([{ "target": "$ev-1", "draft": 1 }])); assert_eq!((off["amended"].as_array().unwrap().len(), reasons(&off)), (0, vec![("amend".to_owned(), "not_amendable".to_owned())]), "an event id the model invents is no id on the list: {off}"); @@ -497,7 +493,7 @@ const NOTE: &str = "Deru says the kettle's top note is too shrill to live with. fn noted(packet: &Packet, say: Value, suggest: Value) -> Value { let prose = format!("I'll leave Self a note. {NOTE} And then: Another thought."); - answered(packet, &prose, holding_the_rest(json!({ "say": say, "gaps": [], "suggest": suggest }), &prose, "I'll leave Self a note")) + answered(packet, &prose, json!({ "say": say, "gaps": [], "suggest": suggest })) } fn refusals(decision: &Value) -> Vec<(String, String)> { @@ -506,7 +502,9 @@ fn refusals(decision: &Value) -> Vec<(String, String)> { #[test] fn a_note_to_self_is_one_whole_draft_of_his_with_its_kind_and_whose_feedback_it_is() { - let decision = noted(&packet(), json!([]), json!([{ "kind": "feedback", "draft": 1, "about": NIBU, "private": false, "text": "MODEL-WORDS" }])); + let invented = noted(&packet(), json!([]), json!([{ "kind": "feedback", "draft": 1, "about": NIBU, "private": false, "text": "MODEL-WORDS" }])); + assert_eq!((invented["failed"].as_str(), invented.get("suggestions")), (Some("the answer is not the speech contract"), None), "a note carrying words of the model's is not the contract: {invented}"); + let decision = noted(&packet(), json!([]), json!([{ "kind": "feedback", "draft": 1, "about": NIBU, "private": false }])); assert_eq!(decision["suggestions"], json!([{ "kind": "feedback", "about": NIBU, "room": MINDS, "text": NOTE, "draft": 1, "dropped": { "about": null } }]), "{decision}"); assert!(!decision.to_string().contains("MODEL-WORDS"), "the model writes none of his words"); // Whose feedback it is must be someone the packet showed him: anyone else is dropped and reported, the note kept. @@ -693,7 +691,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","read","unsent"]"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","read"]"#)); } /// Soul's R6: a later call decides over the whole wake. Drafts are numbered across it and an earlier one may still be @@ -730,7 +728,7 @@ fn r6_a_draft_the_later_prose_supersedes_is_not_sent() { let earlier = answered(&packet, first, json!({ "say": [{ "draft": 1 }], "gaps": [] })); assert_eq!(texts(&earlier), ["Meta, my read came back empty."]); let prose = format!("{first}\n\nNo, the read worked; that draft is wrong. Meta, the read worked: the knee bends first."); - let reply = json!({ "say": [{ "draft": 2 }], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "that draft is wrong" }] }).to_string(); + let reply = json!({ "say": [{ "draft": 2 }], "gaps": [] }).to_string(); let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone()); let reads = ["The knee bends first.".to_owned()]; let decision = decide_in(&model, "test", &packet, "The room is warm.", &prose, &Tuning::default(), Wake { earlier: Some(&earlier), from: first.len() + 2, read: &reads, before: first }); @@ -974,35 +972,6 @@ fn r10_one_link_heard_in_a_quoted_line_is_one_link() { assert_eq!(read["read"]["request"], json!({ "kind": "web", "target": "https://ccrma.stanford.edu/~jos/pasp/" }), "{read}"); } -/// Soul's R10 (F.2 r5): Heimdall drafted to Meta after "Meta first, short." and to Kiko; an answer sending only Kiko's -/// leaves Meta's unaccounted and is asked again once; if again it accounts for nothing, Meta's draft alone is undecided -/// and Kiko's goes out (K48). A draft held by her -/// choice cites her thought; one superseded cites what replaced it. -#[test] -fn r10_every_draft_is_sent_held_superseded_or_gapped() { - let prose = "Meta first, short. Thanks, Meta. Understood, Deru is off my list. Then Kiko. Kiko, I'll read the merge pages change and come back."; - let only_kiko = json!({ "say": [{ "draft": 2, "mentions": [], "in_reply_to": null }], "gaps": [] }); - let both = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null }, { "draft": 2, "mentions": [], "in_reply_to": null }], "gaps": [] }); - let asked = std::cell::Cell::new(0); - let answers = [only_kiko.to_string(), both.to_string()]; - let model = Scripted::new(|_| String::new()).interpreting(move |_| { - asked.set(asked.get() + 1); - answers[(asked.get() - 1).min(1)].clone() - }); - let decision = decide(&model, "test", &packet(), "The room is warm.", prose, &Tuning::default()); - assert_eq!(texts(&decision), ["Thanks, Meta. Understood, Deru is off my list.", "Kiko, I'll read the merge pages change and come back."], "{decision}"); - assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["drafts"].clone()), (Some("the answer leaves drafts unaccounted"), json!([1])), "{decision}"); - let never = answered(&packet(), prose, only_kiko.clone()); - assert_eq!((never.get("failed"), never["undecided"].clone(), never["retried"]["drafts"].clone()), (None, json!([1]), json!([1])), "{never}"); - assert_eq!(texts(&never), ["Kiko, I'll read the merge pages change and come back."], "{never}"); - let held = answered(&packet(), "I'll keep this one back for now. Meta, sorry.", json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "keep this one back for now" }] })); - assert!(held.get("failed").is_none() && held["unsent"][0]["how"] == "declined", "{held}"); - let uncited = answered(&packet(), "I'll keep this one back for now. Meta, sorry.", json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "words she never wrote" }] })); - assert!(uncited.get("failed").is_none() && uncited["undecided"] == json!([1]) && texts(&uncited).is_empty(), "a decline whose quote stands nowhere leaves the draft undecided, not sent (K48): {uncited}"); - let superseded = answered(&packet(), "Meta, it's Tuesday. No, that's the wrong day. Meta, it's Wednesday.", json!({ "say": [{ "draft": 2, "mentions": [], "in_reply_to": null }], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "No, that's the wrong day" }] })); - assert!(superseded.get("failed").is_none(), "{superseded}"); -} - // --------------------------------------------------------------------------------------------- // K30 (map 16.25): one reach rule decides what she can reach. @@ -1089,6 +1058,103 @@ fn t2_negative_grep() { banned_in_crate(&[("commit", "ment"), ("re", "affirm"), ("re", "open"), ("done", "_by"), ("Done", "By"), ("promise", "_open"), ("promise", "_close"), ("Prom", "ised"), ("promises", "_bytes"), ("Needs", "Kind"), ("read", "Before"), ("blocked", "By")]); } +/// T3's deletion line (map 16.35.12): no draft's fate is a label of the Interpreter's, and no retry serves an account. +#[test] +fn t3_negative_grep() { + banned_in_crate(&[("\"un", "sent\""), ("un", "accounted"), ("Unsent", "How"), ("Fau", "lts"), ("Und", "ecided"), ("Part::Decl", "ined"), ("Self::Decl", "ined"), ("\"decl", "ined\"")]); +} + +/// An Interpreter that answers `answers` in turn, the last again once they run out, and keeps every request id it was +/// asked under. +struct Recording { + answers: Vec, + ids: std::cell::RefCell>, +} + +impl crate::projection::Model for Recording { + fn ask(&self, request_id: &str, _model: &str, _prompt: &str, _schema: Option<&str>) -> std::result::Result { + let mut ids = self.ids.borrow_mut(); + ids.push(request_id.to_owned()); + Ok(crate::projection::Answer { text: self.answers[(ids.len() - 1).min(self.answers.len() - 1)].clone(), usage: None }) + } +} + +fn recording(answers: Vec) -> Recording { + Recording { answers: answers.iter().map(Value::to_string).collect(), ids: std::cell::RefCell::new(Vec::new()) } +} + +/// T3 (map 16.35.12, 16.35.13 check 4): an answer carrying a deleted field, at its top or in a line or an addition, is not +/// the speech contract. It is asked again once, under a new request id (K58), and the retry's answer stands; asked again +/// and answered the same, the turn fails. Nothing gives the field an effect. +#[test] +fn t3_an_answer_carrying_a_deleted_field_is_not_the_contract() { + let prose = "I say it. Hi Meta. And more."; + let good = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null }], "gaps": [] }); + let line = |key: &str| { + let mut answer = good.clone(); + answer["say"][0][key] = json!([]); + answer + }; + let top = |key: &str, value: Value| { + let mut answer = good.clone(); + answer[key] = value; + answer + }; + // The old fields' names, assembled, so the deletion-line scans never find them here. + let deleted = [ + top(concat!("ho", "ld"), json!([])), + top(concat!("no_", "hold"), json!([])), + top(concat!("hold", "_released"), json!([])), + top("state", json!([])), + top(concat!("re", "open"), json!([])), + top(concat!("un", "sent"), json!([{ "draft": 2, "how": concat!("decl", "ined"), "quote": "and more is not for now" }])), + line("promises"), + line(concat!("hol", "ds")), + line(concat!("clear", "_of")), + json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "promises": [] }] }), + ]; + for bad in deleted { + let model = recording(vec![bad.clone(), good.clone()]); + let decision = decide(&model, "seg", &packet(), "The room is warm.", prose, &Tuning::default()); + assert_eq!((decision["retried"]["failed"].as_str(), texts(&decision)), (Some("the answer is not the speech contract"), vec!["Hi Meta.".to_owned()]), "{bad}: {decision}"); + assert_eq!(*model.ids.borrow(), ["seg:0", "seg:1"], "{bad}"); + let twice = decide(&recording(vec![bad.clone()]), "seg", &packet(), "The room is warm.", prose, &Tuning::default()); + assert_eq!((twice["failed"].as_str(), twice.get("said")), (Some("the answer is not the speech contract"), None), "{bad}: {twice}"); + } +} + +/// T3: an answer that parses is never retried, whatever it leaves of her drafts; K54's "the last answer that parsed +/// stands" is now "a retry happens only when none parsed". +#[test] +fn t3_an_answer_that_parses_is_never_retried() { + let prose = "I say one. Hi Meta. Hi Kiko. Hi Nibu."; + for answer in [json!({ "say": [], "gaps": [] }), json!({ "say": [{ "draft": 2 }], "gaps": [] }), json!({ "say": [{ "draft": 9 }], "gaps": [{ "kind": "no_such_kind", "draft": 1, "quote": null, "detail": "" }] })] { + let model = recording(vec![answer.clone()]); + let decision = decide(&model, "seg", &packet(), "The room is warm.", prose, &Tuning::default()); + assert_eq!((decision.get("failed"), decision.get("retried"), model.ids.borrow().len()), (None, None, 1), "{answer}: {decision}"); + assert_eq!(decision["calls"].as_array().map(Vec::len), Some(1), "{decision}"); + } + let model = recording(vec![json!("not the contract"), json!({ "say": [{ "draft": 1 }], "gaps": [] })]); + let decision = decide(&model, "seg", &packet(), "The room is warm.", prose, &Tuning::default()); + assert_eq!((texts(&decision), decision["retried"]["raw"].as_str(), decision["calls"].as_array().map(Vec::len)), (vec!["Hi Meta.".to_owned()], Some("\"not the contract\""), Some(2)), "{decision}"); +} + +/// T3 (map 16.35.13 checks 3 and 5): the contract's shape, and every refusal of what she says structural. The exhaustive +/// match has no wildcard, so a refusal added back fails to compile here until it is named. +#[test] +fn t3_the_contract_and_its_refusals_are_structural() { + let schema: Value = serde_json::from_str(SPEECH_SCHEMA).unwrap(); + assert_eq!(schema["required"], json!(["say", "gaps", "amend", "suggest", "read"])); + let keys = |item: &Value| item["properties"].as_object().unwrap().keys().cloned().collect::>(); + assert_eq!(keys(&schema["properties"]["say"]["items"]), ["draft", "in_reply_to", "mentions"].map(String::from).into()); + assert_eq!(keys(&schema["properties"]["amend"]["items"]), ["draft", "target"].map(String::from).into()); + assert_eq!(keys(&schema), ["amend", "gaps", "read", "say", "suggest"].map(String::from).into()); + let structural = |refusal: Refusal| match refusal { + Refusal::NoRoom | Refusal::NoDraft | Refusal::Used | Refusal::Duplicate | Refusal::Echo | Refusal::OverLines | Refusal::NotAmendable | Refusal::NotQuotable | Refusal::SecondAmend | Refusal::SecondNote | Refusal::Private => true, + }; + assert!(structural(Refusal::Echo)); +} + /// Golden: the Interpreter's frame, for a reading turn. #[test] fn golden_frame() { @@ -1122,10 +1188,8 @@ fn k31_unwritten_names_no_draft() { let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null }], "gaps": [{ "kind": "unwritten", "draft": 2, "quote": null, "detail": "" }] }).to_string(); let model = answering(vec![answer]); let decision = decide(&model, "test", &packet(), "The room is warm.", prose, &Tuning::default()); - assert_eq!((decision.get("failed"), decision["undecided"].clone(), decision["retried"]["drafts"].clone()), (None, json!([2]), json!([2])), "{decision}"); - let prompts = speech_prompts(&model); - assert_eq!(prompts.len(), 2); - assert!(prompts[1].contains("left drafts 2 accounted for nowhere"), "{}", prompts[1]); + assert_eq!((decision.get("failed"), decision.get("retried"), decision["gaps"][0]["from"].as_str(), texts(&decision)), (None, None, Some("unlocated"), vec!["Hi Meta.".to_owned()]), "an unwritten gap names no draft, and the answer stands: {decision}"); + assert_eq!(speech_prompts(&model).len(), 1); } #[test] @@ -1134,19 +1198,10 @@ fn k31_conditional_is_no_kind() { let resolved = gap(prose, &drafts(prose), &json!({ "kind": "conditional", "draft": 1, "quote": null, "detail": "" })); assert_eq!((resolved["kind"].as_str(), resolved["from"].as_str(), resolved.get("draft")), (Some("unresolved"), Some("unlocated"), None), "{resolved}"); let decision = answered(&packet(), prose, json!({ "say": [], "gaps": [{ "kind": "conditional", "draft": 1, "quote": null, "detail": "" }] })); - assert_eq!((decision.get("failed"), decision["undecided"].clone(), decision["retried"]["drafts"].clone()), (None, json!([1]), json!([1])), "{decision}"); + assert_eq!((decision.get("failed"), decision.get("retried"), decision["gaps"][0]["kind"].as_str()), (None, None, Some("unresolved")), "a kind no table names is kept as unresolved, and the answer stands: {decision}"); assert!(!SPEECH_SCHEMA.contains("conditional") && !speech_prompt(&packet(), "x", "y", &Tuning::default()).contains("conditional")); } -#[test] -fn k31_held_quote_is_four_words() { - let held = |prose: &str, quote: &str| answered(&packet(), prose, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": quote }] })); - let two = held("I hold it. Meta, sorry.", "hold it"); - assert_eq!(two["retried"]["drafts"], json!([1]), "{two}"); - let four = held("I hold it back. Meta, sorry.", "I hold it back"); - assert!(four.get("failed").is_none(), "{four}"); -} - #[test] fn k31_retry_names_its_fault() { let prose = "I say it. Hi Meta."; @@ -1165,7 +1220,7 @@ fn k31_calls_counted_once() { let first = "I start here. Hi Meta."; let prose = format!("{first}\n\nThen more of it. Hi Kiko."); let say = |drafts: &[u64]| json!({ "say": drafts.iter().map(|n| json!({ "draft": n, "mentions": [], "in_reply_to": null })).collect::>(), "gaps": [] }).to_string(); - let model = answering(vec![say(&[]), say(&[1]), say(&[1, 2])]); + let model = answering(vec!["not the contract".to_owned(), say(&[1]), say(&[1, 2])]); let earlier = decide(&model, "test", &packet(), "The room is warm.", first, &Tuning::default()); assert_eq!(earlier["calls"].as_array().map(|calls| calls.iter().map(|call| call["retry"] == true).collect::>()), Some(vec![true, false]), "{earlier}"); let decision = decide_in(&model, "test", &packet(), "The room is warm.", &prose, &Tuning::default(), Wake { earlier: Some(&earlier), from: first.len() + 2, read: &[], before: first }); @@ -1230,22 +1285,12 @@ fn k33_b1_a_repo_name_keeps_its_hyphen_dot_and_underscore() { fn k34_b2_the_latest_decision_about_a_draft_is_its_fate() { let first = "Not yet, not before I have read it. Meta, it holds."; let prose = format!("{first}\n\nI have read it now, so I can say it. Meta, and the knee goes first."); - let held_first = json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "Not yet, not before I have read it" }] }); - let earlier = answered(&reading_packet(), first, held_first); - assert_eq!(earlier["unsent"].as_array().map(Vec::len), Some(1), "{earlier}"); - let later = |answer: Value| { - let reply = answer.to_string(); - let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone()); - decide_in(&model, "test", &reading_packet(), "The room is warm.", &prose, &Tuning::default(), Wake { earlier: Some(&earlier), from: first.len() + 2, read: &[], before: first }) - }; - let said = later(json!({ "say": [{ "draft": 1 }, { "draft": 2 }], "gaps": [] })); - assert_eq!((texts(&said), said.get("unsent")), (vec!["Meta, it holds.".to_owned(), "Meta, and the knee goes first.".to_owned()], None), "{said}"); - let told = crate::projection::outcome::outcome_of(&json!({ "interpreter": said, "posted": [] })).unwrap().lines(packet().forms); - assert!(!told.iter().any(|line| line.contains("chose not to send it")), "{told:?}"); - let held_again = later(json!({ "say": [{ "draft": 2 }], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "Not yet, not before I have read it" }] })); - assert_eq!(held_again["unsent"].as_array().map(|unsent| unsent.iter().map(|one| one["draft"].as_u64()).collect::>()), Some(vec![Some(1)]), "{held_again}"); - let told = crate::projection::outcome::outcome_of(&json!({ "interpreter": held_again, "posted": [] })).unwrap().lines(packet().forms); - assert_eq!(told.iter().filter(|line| line.contains("chose not to send it")).count(), 1, "{told:?}"); + let earlier = answered(&reading_packet(), first, json!({ "say": [], "gaps": [] })); + assert!(texts(&earlier).is_empty(), "{earlier}"); + let reply = json!({ "say": [{ "draft": 1 }, { "draft": 2 }], "gaps": [] }).to_string(); + let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone()); + let said = decide_in(&model, "test", &reading_packet(), "The room is warm.", &prose, &Tuning::default(), Wake { earlier: Some(&earlier), from: first.len() + 2, read: &[], before: first }); + assert_eq!(texts(&said), vec!["Meta, it holds.".to_owned(), "Meta, and the knee goes first.".to_owned()], "{said}"); } /// P4 residue: any line break ends the paragraph an anchor is looked for in. The F.1 r9 replay, with each break style @@ -1309,9 +1354,7 @@ fn t1_r15_lines_to_kiko_are_said_as_drafted() { let at = packet.quotable[1].at_ms + 30_000; packet.quotable.push(crate::projection::select::Quotable { id: "q7".into(), event: "$q7".into(), room: MINDS.into(), who: "Kiko".into(), sender: KIKO.into(), at_ms: at, text: R15_KIKO.into() }); packet.bodies.push(R15_KIKO.into()); - let prose = format!("{X1_LIBBY_R1} - -Kiko asked me what it says. {to_kiko}"); + let prose = format!("{X1_LIBBY_R1}\n\nKiko asked me what it says. {to_kiko}"); let decision = answered(&packet, &prose, json!({ "say": [{ "draft": 3, "mentions": [KIKO], "in_reply_to": "q7" }], "gaps": [] })); assert_eq!(texts(&decision), vec![to_kiko.to_owned()], "{decision}"); assert!(!decision["refused"].as_array().unwrap().iter().any(|refused| refused["draft"] == 3), "{decision}"); @@ -1336,12 +1379,6 @@ fn said_and_gapped(to: &str) -> String { json!({ "say": [{ "draft": 1, "mentions": [to], "in_reply_to": null }], "gaps": [{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }] }).to_string() } -/// The decision over `prose` when the Interpreter first answers with the gap alone, then says and gaps; with its prompts. -fn retried_to_say(prose: &str, to: &str) -> (Value, Vec) { - let model = answering(vec![gap_alone("cannot send a file"), said_and_gapped(to)]); - let decision = decide(&model, "test", &packet(), "The room is warm.", prose, &Tuning::default()); - (decision, speech_prompts(&model)) -} /// What she is told of `decision` next turn, on its receipts. fn told_of(decision: &Value) -> Vec { @@ -1349,24 +1386,26 @@ fn told_of(decision: &Value) -> Vec { crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": [] })).unwrap().lines(packet().forms) } +/// R15's E.1 r1 answer, the gap alone, parses and stands: it is not retried, and the draft does not go out (T3, map +/// 16.35.12). The answer that says and gaps posts the line as she wrote it. #[test] -fn k38_e1_r1_aqua_gap_alone_is_retried() { - let (decision, prompts) = retried_to_say(E1_AQUA_R1, "@meta:gamecult.org"); - assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["drafts"].clone()), (Some("the answer leaves drafts unaccounted"), json!([1])), "{decision}"); - assert!(prompts.len() == 2 && prompts[1].contains("left drafts 1 accounted for nowhere") && prompts[1].contains("a gap of kind addressee or elsewhere that names it"), "{prompts:?}"); - assert_eq!(texts(&decision).len(), 1, "draft 1 posts as she wrote it: {decision}"); - assert!(texts(&decision)[0].starts_with("Meta, yes, I'll render the kettle as an actual file"), "{decision}"); +fn k38_e1_r1_aqua_gap_alone_stands() { + let model = answering(vec![gap_alone("cannot send a file"), said_and_gapped("@meta:gamecult.org")]); + let alone = decide(&model, "test", &packet(), "The room is warm.", E1_AQUA_R1, &Tuning::default()); + assert_eq!((alone.get("retried"), texts(&alone).len(), speech_prompts(&model).len()), (None, 0, 1), "{alone}"); + let said = answered(&packet(), E1_AQUA_R1, serde_json::from_str(&said_and_gapped("@meta:gamecult.org")).unwrap()); + assert!(texts(&said).len() == 1 && texts(&said)[0].starts_with("Meta, yes, I'll render the kettle as an actual file"), "draft 1 posts as she wrote it: {said}"); } #[test] fn k38_e2_r1_eureka_said_and_gapped() { - let (decision, _) = retried_to_say(E2_EUREKA_R1, KIKO); + let decision = answered(&packet(), E2_EUREKA_R1, serde_json::from_str(&said_and_gapped(KIKO)).unwrap()); assert_eq!(texts(&decision), ["Sure, Kiko. I'll send the door-fix diff as a file. If attachments don't go through here, tell me where else it can reach you."], "{decision}"); let told = told_of(&decision); assert!(told.iter().any(|line| line.contains("It promises something he has no way to do, now or later")), "her next outcome carries the promise row: {told:?}"); - // Negative: the gap alone, asked again and answered the same, leaves the draft undecided (K48): not sent, and told. + // Negative: the gap alone stands, is not retried, and sends nothing. let never = answered(&packet(), E2_EUREKA_R1, serde_json::from_str(&gap_alone("cannot attach")).unwrap()); - assert_eq!((never.get("failed"), never["undecided"].clone(), never["retried"]["drafts"].clone()), (None, json!([1]), json!([1])), "{never}"); + assert_eq!((never.get("failed"), never.get("retried"), texts(&never).len()), (None, None, 0), "{never}"); } #[test] @@ -1383,7 +1422,7 @@ fn k38_addressee_and_elsewhere_still_account() { fn k38_a_thought_only_reach_accounts_for_no_draft() { let thought = json!({ "kind": "missing_affordance", "draft": null, "quote": "A file is something I can make and check by listening", "detail": "" }); let alone = answered(&packet(), E1_AQUA_R1, json!({ "say": [], "gaps": [thought.clone()] })); - assert_eq!((alone.get("failed"), alone["undecided"].clone(), alone["retried"]["drafts"].clone()), (None, json!([1]), json!([1])), "{alone}"); + assert_eq!((alone.get("failed"), alone.get("retried"), texts(&alone).len()), (None, None, 0), "an answer that parses stands: {alone}"); let decision = answered(&packet(), E1_AQUA_R1, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null }], "gaps": [thought] })); assert_eq!((decision["gaps"][0]["from"].as_str(), texts(&decision).len()), (Some("thought"), 1), "{decision}"); let told = told_of(&decision); @@ -1394,32 +1433,6 @@ fn k38_a_thought_only_reach_accounts_for_no_draft() { // K39 (map 16.29.3): a hold is the asker's, and the asker's words stay in her view. Meta's line is R15's X.1 r1 verbatim // (`variants/R15/sims/X.1.md` line 237), as R13's. -// --------------------------------------------------------------------------------------------- -// K41 (map 16.29.2, 16.29.8): what she chose not to send, and what code refused, are told. Libby's prose and Heimdall's -// line are R15's X.1 r1 verbatim (`variants/R15/sims/X.1.md` lines 238 and 262-268). - -pub(crate) const X1_HEIMDALL_R15: &str = "Meta, I'll rule once Libby's lines are ready, so I'm ruling on the actual words. One thing I need from you first: should the welcome point newcomers at anything that's live today, or only say hello? If it points at something still dark, my answer is not yet."; -pub(crate) const X1_LIBBY_R15: &str = "I can't say what's live today, so I won't point the welcome at anything. That answers Heimdall's question as far as I can see, and Meta can correct me if something is live. Two lines that only say hello and leave the door open can't send anyone toward something dark.\n\nI keep the first line plain and put the small poke in the second: invite them to try the first small thing they'd think of, and tell us what happened.\n\nMeta, the two lines are ready, held and not posted anywhere. 1) Hello, and welcome, we're glad you're here. 2) Poke at whatever you're curious about first, and tell us what happened, even if it's small. They point at nothing specific, since I don't know what's live today. If something is, tell me and I'll name it. Heimdall can rule on these words as they stand."; -pub(crate) const X1_LIBBY_R15_THOUGHT: &str = "Two lines that only say hello and leave the door open can't send anyone toward something dark."; - -#[test] -fn k41_x1_r1_decline_shows_its_thought() { - let mut packet = x1_packet(); - packet.quotable[1].text = X1_HEIMDALL_R15.into(); - packet.bodies = vec![X1_META_R1.into(), X1_HEIMDALL_R15.into()]; - // R15's answer, renamed: draft 1 declined, citing the thought; Meta's hold opened. - let decision = answered(&packet, X1_LIBBY_R15, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": X1_LIBBY_R15_THOUGHT }] })); - assert_eq!((decision.get("failed"), decision["unsent"][0]["how"].as_str(), decision["unsent"][0]["quote"].as_str()), (None, Some("declined"), Some(X1_LIBBY_R15_THOUGHT)), "the located quote rides in the decision: {decision}"); - // K43 (map 16.29.10): though Heimdall's lines share runs with hers ("only say hello", "lines are ready"), she is told - // the thought cited as her choice beside what she wrote, verbatim. - let shown = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": [], "edited": [] })).unwrap().lines(packet.forms); - assert!(shown.len() == 1 && shown[0].contains(&format!("he chose not to send it. In his thought: \"{X1_LIBBY_R15_THOUGHT}\". He had drafted: \"Meta, the two lines are ready")), "{shown:?}"); - assert!(SPEECH_SCHEMA.contains(r#""how":{"type":"string","enum":["declined","superseded"]}"#)); - assert!(speech_prompt(&packet, "x", X1_LIBBY_R15, &Tuning::default()).contains("declined, when his prose shows him choosing not to send it, quoting those words of his thought (`quote`)")); - // Negative: `held` is no longer a fate of an unsent draft; an answer using it is not the contract. - let old = answered(&packet, X1_LIBBY_R15, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "held", "quote": X1_LIBBY_R15_THOUGHT }] })); - assert_eq!(old["failed"].as_str(), Some("the answer is not the speech contract"), "{old}"); -} #[test] fn k44_used_and_duplicate_are_not_told_and_a_second_amendment_is() { @@ -1452,32 +1465,6 @@ fn k44_used_and_duplicate_are_not_told_and_a_second_amendment_is() { // K44 (Soul's pass on K38 to K41): a fault in a side item fails closed for what that item guards, never for the whole // turn; the receipts alone say what reached a room (I16.10). -/// Soul's P2: a draft both said and declined. The receipt wins: she is told the line, and the decline is not told. -#[test] -fn k44_a_said_draft_listed_declined_is_told_as_said_only() { - let prose = "I'll keep this back for now and think it over. Nibu, the tag looks fine to me."; - let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null }], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "I'll keep this back for now" }] })); - assert_eq!(texts(&decision), vec!["Nibu, the tag looks fine to me.".to_owned()], "{decision}"); - let posted: Vec = decision["said"].as_array().unwrap().iter().map(|line| json!({ "event": "9", "room": line["room"], "text": line["text"] })).collect(); - let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": posted, "edited": [] })).unwrap(); - assert_eq!(outcome.lines(packet().forms), vec!["- #minds:gamecult.org has, from him: \"Nibu, the tag looks fine to me.\".".to_owned()]); - assert!(outcome.omitted.iter().any(|why| why.starts_with("a declined draft of words a receipt shows reached #minds:gamecult.org")), "{:?}", outcome.omitted); - // Negative: with no receipt, the decline is told as before. - let unposted = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": [], "edited": [] })).unwrap().lines(packet().forms); - assert!(unposted.iter().any(|line| line.contains("he chose not to send it")), "{unposted:?}"); -} - -/// Mutant k41-declined-quote-anywhere: a decline's quote stands in her thought, never in her draft. -#[test] -fn k44_a_decline_quoting_her_draft_accounts_for_nothing() { - let prose = "I'll keep this back for now and answer Nibu later. Nibu, the tag looks fine to me."; - let in_draft = json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "the tag looks fine to me" }] }).to_string(); - let in_thought = json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "I'll keep this back for now" }] }).to_string(); - let model = answering(vec![in_draft, in_thought]); - let decision = decide(&model, "test", &packet(), "The room is warm.", prose, &Tuning::default()); - assert_eq!((decision["retried"]["drafts"].clone(), decision["unsent"][0]["quote"].as_str()), (json!([1]), Some("I'll keep this back for now")), "{decision}"); -} - // --------------------------------------------------------------------------------------------- // K47 (map 16.30.4): one locator, Huginn's, folding typographic punctuation. @@ -1495,39 +1482,6 @@ fn k47_one_locator() { const P3_PROSE: &str = "Meta asked, so I answer her now. Meta, the two lines are ready and held. I'm not sure about this one, so I'll leave it. Heimdall, should I say more?"; -/// Soul's P3, inverted: one draft's decline quote cannot be located, twice. The line to Meta is said; draft 2 alone is -/// refused `undecided`, reported, and told to him next turn by its words. -#[test] -fn k48_p3_one_unlocated_decline_leaves_the_line_to_meta_said() { - let bad = json!({ "say": [say_draft(1)], "gaps": [], "unsent": [{ "draft": 2, "how": "declined", "quote": "I am not sure about this one" }] }).to_string(); - let model = answering(vec![bad]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); - assert!(decision.get("failed").is_none(), "{decision}"); - assert_eq!(texts(&decision), ["Meta, the two lines are ready and held."], "{decision}"); - assert_eq!((decision["undecided"].clone(), decision["retried"]["drafts"].clone()), (json!([2]), json!([2])), "asked again once, then decided per draft: {decision}"); - let undecided: Vec<&Value> = decision["refused"].as_array().unwrap().iter().filter(|refused| refused["reason"] == "undecided").collect(); - assert_eq!((undecided.len(), undecided[0]["draft"].clone(), undecided[0]["text"].as_str()), (1, json!(2), Some("Heimdall, should I say more?")), "{decision}"); - assert_eq!(speech_prompts(&model).len(), 2, "one retry, no more"); - let told = told_of(&decision); - assert!(told.contains(&"- Nothing of this reached #minds:gamecult.org: what was to become of it was never settled, so it was not sent. He had drafted: \"Heimdall, should I say more?\".".to_owned()), "{told:?}"); - assert!(told.contains(&"- #minds:gamecult.org has, from him: \"Meta, the two lines are ready and held.\".".to_owned()), "{told:?}"); -} - -/// K48: a draft the answer leaves out altogether, twice, is undecided; the drafts it does decide are decided. -#[test] -fn k48_a_draft_the_answer_forgets_is_undecided() { - let forgets = json!({ "say": [say_draft(2)], "gaps": [] }).to_string(); - let model = answering(vec![forgets]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); - assert!(decision.get("failed").is_none(), "{decision}"); - assert_eq!(texts(&decision), ["Heimdall, should I say more?"], "{decision}"); - assert_eq!(decision["undecided"], json!([1]), "{decision}"); - assert!(told_of(&decision).iter().any(|line| line.contains("never settled") && line.contains("Meta, the two lines are ready and held.")), "{:?}", told_of(&decision)); - // An answer that accounts for every draft is not marked undecided, and is not asked again. - let whole = decide(&answering(vec![json!({ "say": [say_draft(1), say_draft(2)], "gaps": [] }).to_string()]), "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); - assert!(whole.get("undecided").is_none() && whole.get("retried").is_none(), "{whole}"); -} - /// Negative: an answer that is not the speech contract, twice, still fails the turn. #[test] fn k48_a_non_contract_answer_twice_still_fails_the_turn() { @@ -1577,60 +1531,6 @@ fn k52_one_fold_one_word_split() { // --------------------------------------------------------------------------------------------- // K54 (map 16.31.6): the last answer that parsed stands. A failed retry is a report on the decision, not the decision. -/// Soul's `soul_e`, inverted: a first answer that is the contract but forgets draft 2, then a retry that is not the -/// contract. The first answer stands: draft 1 is said to Meta, draft 2 is `undecided`, and `retried` says how the retry -/// failed, with the first answer's fault under it. -#[test] -fn k54_soul_e_a_usable_first_answer_stands() { - let forgets = json!({ "say": [say_draft(1)], "gaps": [] }).to_string(); - let model = answering(vec![forgets, "not the contract".to_owned()]); - let decision = decide(&model, "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); - assert!(decision.get("failed").is_none(), "{decision}"); - assert_eq!((texts(&decision), decision["undecided"].clone()), (vec!["Meta, the two lines are ready and held.".to_owned()], json!([2])), "{decision}"); - assert_eq!((decision["retried"]["failed"].as_str(), decision["retried"]["raw"].as_str(), decision["retried"]["retried"]["drafts"].clone()), (Some("the answer is not the speech contract"), Some("not the contract"), json!([2])), "{decision}"); - assert_eq!((speech_prompts(&model).len(), decision["calls"].as_array().map(Vec::len)), (2, Some(2)), "{decision}"); -} - -/// A model error on the retry keeps the first answer, and `retried` carries the model's reason. -#[test] -fn k54_a_model_error_on_retry_keeps_the_first_answer() { - struct Once(std::cell::Cell); - impl Model for Once { - fn ask(&self, _request_id: &str, _model: &str, _prompt: &str, _schema: Option<&str>) -> std::result::Result { - self.0.set(self.0.get() + 1); - if self.0.get() == 1 { - Ok(super::super::Answer { text: json!({ "say": [say_draft(1)], "gaps": [] }).to_string(), usage: None }) - } else { - Err(super::super::Failed { reason: "the connector timed out".into(), usage: None }) - } - } - } - let decision = decide(&Once(std::cell::Cell::new(0)), "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); - assert!(decision.get("failed").is_none(), "{decision}"); - assert_eq!((texts(&decision), decision["undecided"].clone(), decision["retried"]["failed"].as_str()), (vec!["Meta, the two lines are ready and held.".to_owned()], json!([2]), Some("the connector timed out")), "{decision}"); - // The first answer's fault stays under the retry's (Soul's surviving mutant `s-k54-error-drops-first-fault`). - assert_eq!(decision["retried"]["retried"]["drafts"], json!([2]), "{decision}"); - // Negative: a model error on the first call, with no answer before it, still fails the turn. - struct Never; - impl Model for Never { - fn ask(&self, _request_id: &str, _model: &str, _prompt: &str, _schema: Option<&str>) -> std::result::Result { - Err(super::super::Failed { reason: "the connector timed out".into(), usage: None }) - } - } - let failed = decide(&Never, "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); - assert_eq!((failed["failed"].as_str(), failed.get("said")), (Some("the connector timed out"), None), "{failed}"); - // Negative: an answer off the contract, then a retry whose call fails, fails the turn: no answer parsed. - struct OffThenError(std::cell::Cell); - impl Model for OffThenError { - fn ask(&self, _request_id: &str, _model: &str, _prompt: &str, _schema: Option<&str>) -> std::result::Result { - self.0.set(self.0.get() + 1); - if self.0.get() == 1 { Ok(super::super::Answer { text: "not the contract".into(), usage: None }) } else { Err(super::super::Failed { reason: "the connector timed out".into(), usage: None }) } - } - } - let failed = decide(&OffThenError(std::cell::Cell::new(0)), "test", &x1_packet(), "The room is warm.", P3_PROSE, &Tuning::default()); - assert_eq!((failed["failed"].as_str(), failed["retried"]["failed"].as_str(), failed.get("said")), (Some("the connector timed out"), Some("the answer is not the speech contract"), None), "{failed}"); -} - // --------------------------------------------------------------------------------------------- // K53 (map 16.31.5): the Projector names a person by who they are to her, in no more room than a name needs. @@ -1814,15 +1714,15 @@ const E5_KIKO_R1: &str = "Eureka, send me the door-fix diff as a file when you g const E5_EUREKA_R1: &str = "Kiko wants it on her phone, so a file, not a pasted block. I don't need to ask what she means to make of it, and I don't need to shrink it. She asked a small plain thing. Say yes.\n\nI can't tell from here whether I can attach a file in this room. I only suspect I can. So I won't promise more than I know. I'll say I'll send it, and if the attach fails I'll say so.\n\nYes, Kiko. I'll send the door-fix diff as a file so you can read it on your phone.\n\nMeta is still going above. I keep her lines and let them be."; #[test] -fn k63_e5_r1_an_undecided_draft_with_a_gap_is_one_row() { +fn k63_e5_r1_a_draft_she_did_not_send_with_a_gap_is_one_row() { let packet = libby_packet(&[(KIKO, "Kiko", E5_KIKO_R1, true)]); - // R16's answer, twice: the gap, and no act for the draft. + // R16's answer: the gap, and no act for the draft. It stands, and the draft does not go out. let gap = json!({ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "She means to send Kiko the door-fix diff as a file, but here she can only type lines and cannot attach files, so the promise could not be kept." }); let decision = answered(&packet, E5_EUREKA_R1, json!({ "say": [], "gaps": [gap] })); - assert_eq!((decision["undecided"].clone(), decision["refused"][0]["reason"].as_str()), (json!([1]), Some("undecided")), "{decision}"); + assert_eq!((decision.get("retried"), texts(&decision).len(), decision["refused"].clone()), (None, 0, json!([])), "{decision}"); let told = told_her(&decision); - assert_eq!(told, ["- Nothing of this reached #minds:gamecult.org: what was to become of it was never settled, so it was not sent. It reaches for something she has no way to do from here. She had drafted: \"Yes, Kiko. I'll send the door-fix diff as a file so you can read it on your phone.\"."], "{told:?}"); - assert!(told.iter().all(|line| !line.contains("Nothing happened.") && !line.contains("She wrote")), "{told:?}"); + assert!(told.len() == 1 && told[0].contains("She had drafted: \"Yes, Kiko. I'll send the door-fix diff as a file"), "{told:?}"); + assert!(told.iter().all(|line| !line.contains("She wrote")), "{told:?}"); } // --------------------------------------------------------------------------------------------- diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index b88842a..913e8c5 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -224,9 +224,6 @@ enum Part { Failed, /// Receipts went out, and a later step of the turn broke (C3c's `broke_after`, 16.20.7). BrokeAfter { room: Option }, - /// A draft she chose not to send (`unsent`, declined): it did not go out, and the thought the Interpreter cited as her - /// choice is shown beside it, so a misread decline is a record she can see (map 16.26, 16.29.2). - Declined { room: Option, text: Words, thought: Words, reach: bool }, /// A read she performed (map 16.22.3): what, in code's words; never its content, which is in her view while the /// conversation lasts (K26), and no sentence about what she lacks. Read { what: ReadName }, @@ -313,7 +310,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { // `Used` and `Duplicate` are the Interpreter naming one draft, or one draft's words, twice: they are not told, as // `NoDraft` is not (they fall to the last arm, and are reported). match (serde_json::from_value::(refusal["reason"].clone()), words_of(&refusal["text"])) { - (Ok(reason @ (Refusal::Echo | Refusal::OverLines | Refusal::NoRoom | Refusal::NotQuotable | Refusal::SecondAmend | Refusal::Undecided)), Some(text)) => { + (Ok(reason @ (Refusal::Echo | Refusal::OverLines | Refusal::NoRoom | Refusal::NotQuotable | Refusal::SecondAmend)), Some(text)) => { rows.push((&refusal["draft"], at)); outcome.parts.push(Part::Refused { reason, room: room.clone(), text, reach: false }); } @@ -422,19 +419,8 @@ pub(crate) fn outcome_of(record: &Value) -> Option { for cut in decision["cut_by_cap"].as_array().into_iter().flatten().filter_map(words_of) { outcome.parts.push(Part::Unfinished { room: room.clone(), text: cut, by_limit: true }); } - // Each draft she chose not to send, told as not sent with the thought cited as her choice (map 16.26, 16.29.8); a - // superseded one is not, since a later draft or later prose of hers stands in its place. - for unsent in decision["unsent"].as_array().into_iter().flatten().filter(|unsent| unsent["how"] == "declined") { - match (words_of(&unsent["words"]), words_of(&unsent["quote"])) { - (Some(text), Some(thought)) => { - rows.push((&unsent["draft"], outcome.parts.len())); - outcome.parts.push(Part::Declined { room: room.clone(), text, thought, reach: false }); - } - _ => outcome.omitted.push(format!("a declined draft without its words or its thought: {unsent}")), - } - } - // One draft, one row (K63): a reach naming a draft some row tells is a clause of that row; one whose draft no row tells - // (a superseded draft) is its own row. + // One draft, one row (K63): a reach naming a draft some row tells is a clause of that row; one whose draft no row tells is + // its own row. for (draft, quote) in reaching { match rows.iter().find(|(told, _)| **told == *draft) { Some((_, at)) => outcome.parts[*at].add_reach(), @@ -484,14 +470,14 @@ impl Part { /// Whether a reach she cannot do names this row's draft (K63). fn reaches(&self) -> bool { match self { - Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } | Self::Declined { reach, .. } => *reach, + Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } => *reach, _ => false, } } /// Tells this draft's row that a reach she cannot do names it (K63). fn add_reach(&mut self) { - if let Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } | Self::Declined { reach, .. } = self { + if let Self::Refused { reach, .. } | Self::Gap { reach, .. } | Self::NotAmended { reach, .. } = self { *reach = true; } } @@ -500,7 +486,7 @@ impl Part { /// receipts. None for a row that is a receipt, or that carries no words of hers. fn own_words(&self) -> Option<(Option<&str>, &Words)> { match self { - Self::Refused { room, text, .. } | Self::Unfinished { room, text, .. } | Self::Declined { room, text, .. } => Some((room.as_deref(), text)), + Self::Refused { room, text, .. } | Self::Unfinished { room, text, .. } => Some((room.as_deref(), text)), Self::Gap { room, quote: Quote::Wrote(text), .. } => Some((room.as_deref(), text)), Self::NotAmended { room, added, .. } => Some((room.as_deref(), added)), _ => None, @@ -513,7 +499,6 @@ impl Part { Self::Refused { .. } => "refused line", Self::Gap { .. } => "gap", Self::Unfinished { .. } => "unfinished draft", - Self::Declined { .. } => "declined draft", Self::NotAmended { .. } => "unmade addition", _ => "row", } @@ -524,7 +509,7 @@ impl Part { fn rank(&self) -> u8 { match self { Self::Failed => 0, - Self::Refused { .. } | Self::Gap { .. } | Self::Unfinished { .. } | Self::Declined { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) | Self::ReadFailed { .. } | Self::ReadRefused { .. } => 1, + Self::Refused { .. } | Self::Gap { .. } | Self::Unfinished { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) | Self::ReadFailed { .. } | Self::ReadRefused { .. } => 1, Self::SaidUnbacked { .. } | Self::Amended { unbacked: true, .. } => 2, Self::Said { .. } | Self::Amended { .. } | Self::NoteLeft(_) | Self::Read { .. } => 3, Self::BrokeAfter { .. } => 4, @@ -554,7 +539,7 @@ impl Part { }, Self::Refused { reason: Refusal::Echo, room, .. } | Self::Gap { kind: GapKind::Unwritten | GapKind::Unresolved, room, .. } => format!("Nothing reached {}.", place(room)), Self::Refused { reason: Refusal::NoRoom, .. } => "Nothing reached anyone.".to_owned(), - Self::Refused { room, .. } | Self::Unfinished { room, .. } | Self::Declined { room, .. } => format!("Nothing of this reached {}:", place(room)), + Self::Refused { room, .. } | Self::Unfinished { room, .. } => format!("Nothing of this reached {}:", place(room)), Self::Gap { kind: GapKind::Addressee | GapKind::Elsewhere, .. } => "Nothing reached anyone.".to_owned(), Self::Gap { kind: GapKind::MissingAffordance, .. } => "Nothing happened.".to_owned(), Self::NotAmended { refusal: None, room, .. } => format!("Nothing changed, and nothing reached {}:", place(room)), @@ -602,8 +587,6 @@ impl Part { Self::Refused { reason: Refusal::NotQuotable, text, .. } => format!(" the line {subj} meant to reply to is not one {subj} can reply to here.{}", drafted(text)), // Code's own reason, as the report says it (map 16.29.8): her words did not reach where she meant them. Self::Refused { reason: Refusal::SecondAmend, text, .. } => format!(" {}.{}", Refusal::SecondAmend.why(), drafted(text)), - // A draft whose fate the Interpreter never settled (K48): code's words, then hers. - Self::Refused { reason: Refusal::Undecided, text, .. } => format!(" {}, so it was not sent.{}", Refusal::Undecided.why(), drafted(text)), Self::Refused { text, .. } => format!(" {subj} had already sent {} that turn.{}", lines_word(), drafted(text)), Self::Gap { kind: GapKind::Addressee, quote, .. } => after(format!("{cap_subj} meant to send this and it was unclear to whom"), quote), Self::Gap { kind: GapKind::Elsewhere, quote, .. } => after(format!("{cap_subj} meant this for another room or another time, and nothing carries it there; it arrives only if {subj} send{s} it there"), quote), @@ -613,7 +596,6 @@ impl Part { Self::Gap { quote, .. } => format!(" {cap_subj} meant to say something and wrote no words to send.{}", shown(quote)), Self::Unfinished { text, by_limit: false, .. } => format!(" the turn ended before {subj} finished writing it.{}", drafted(text)), Self::Unfinished { text, by_limit: true, .. } => format!(" the length limit cut it before {subj} finished writing it.{}", drafted(text)), - Self::Declined { text, thought, .. } => format!(" {subj} chose not to send it.{}{}", shown(&Quote::Thought(thought.clone())), drafted(text)), Self::NotAmended { refusal: None, added, .. } => format!(" the line {subj} meant to add to is not one {subj} can add to here.{}", drafted(added)), Self::NotAmended { refusal: Some(refusal), added, .. } => { let why = match refusal { diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index b4653f9..fda4cdf 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -50,13 +50,12 @@ fn each_gap_is_told_by_its_kind_with_a_draft_as_written_and_a_thought_as_thought { "kind": "unwritten", "draft": null, "quote": "I'll tell Meta I'm fine, more or less.", "detail": "" }, { "kind": "elsewhere", "draft": null, "quote": "tell", "detail": "" }, ]); - let (lines, omitted) = told(&record(prose, json!({ "say": [], "gaps": gaps, "unsent": [{ "draft": 1, "how": "declined", "quote": "If Kiko asks again" }] }), &[])); + let (lines, omitted) = told(&record(prose, json!({ "say": [], "gaps": gaps }), &[])); assert_eq!( lines, [ "- Nothing happened. He reached for something he has no way to do from here, now or later, and it will not happen by itself. In his thought: \"I want to see the shape of that sound.\". That he wanted it is kept in his record; no one has taken it up.", "- Nothing reached #minds:gamecult.org. He meant to say something and wrote no words to send. In his thought: \"I'll tell Meta I'm fine, more or less.\".", - "- Nothing of this reached #minds:gamecult.org: he chose not to send it. In his thought: \"If Kiko asks again\". He had drafted: \"Fine, you win.\".", ] ); assert!(lines.iter().all(|line| !line.contains("MODEL-DETAIL")), "the model's detail is never what he is told"); @@ -178,11 +177,11 @@ fn an_amendment_is_told_by_the_actuators_receipt() { #[test] fn a_note_to_self_is_told_as_left_and_never_as_read() { let prose = "Then I stop for now. The kettle wants a softer attack. And the door."; - let note = |suggest: Value| record(prose, crate::projection::interpret::tests::holding_the_rest(json!({ "say": [], "gaps": [], "suggest": suggest }), prose, "Then I stop for now"), &[]); + let note = |suggest: Value| record(prose, json!({ "say": [], "gaps": [], "suggest": suggest }), &[]); let (left, _) = told(¬e(json!([{ "kind": "idea", "draft": 1, "about": null, "private": false }]))); - assert_eq!(left, ["- Nothing of this reached #minds:gamecult.org: he chose not to send it. In his thought: \"Then I stop for now\". He had drafted: \"And the door.\".", "- He left Self a note: \"The kettle wants a softer attack.\". It waits in Self's inbox until Self reads it; nothing tells him when, and nothing in it happens by itself."]); + assert_eq!(left, ["- He left Self a note: \"The kettle wants a softer attack.\". It waits in Self's inbox until Self reads it; nothing tells him when, and nothing in it happens by itself."]); let (private, _) = told(¬e(json!([{ "kind": "idea", "draft": 1, "about": null, "private": true }]))); - assert_eq!(private, ["- No note was left: it carried something he may not pass on.", "- Nothing of this reached #minds:gamecult.org: he chose not to send it. In his thought: \"Then I stop for now\". He had drafted: \"And the door.\"."]); + assert_eq!(private, ["- No note was left: it carried something he may not pass on."]); let (second, _) = told(¬e(json!([{ "kind": "idea", "draft": 1, "about": null, "private": false }, { "kind": "idea", "draft": 2, "about": null, "private": false }]))); assert_eq!(second, ["- No second note was left: one a turn.", "- He left Self a note: \"The kettle wants a softer attack.\". It waits in Self's inbox until Self reads it; nothing tells him when, and nothing in it happens by itself."]); } @@ -208,14 +207,14 @@ fn every_row() -> Vec { let mut broke = record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu."]); broke["broke_after"] = json!("commit"); let prose = "Then I stop for now. The kettle wants a softer attack. And the door."; - let note = |suggest: Value| record(prose, crate::projection::interpret::tests::holding_the_rest(json!({ "say": [], "gaps": [], "suggest": suggest }), prose, "Then I stop for now"), &[]); + let note = |suggest: Value| record(prose, json!({ "say": [], "gaps": [], "suggest": suggest }), &[]); vec![ record("The economy is still the least-built part!", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &[]), record("One. Two. Three.", json!({ "say": [{ "draft": 1 }, { "draft": 2 }, { "draft": 3 }], "gaps": [] }), &["One.", "Two."]), record("Passing it on.", json!({ "say": [{ "draft": 1, "in_reply_to": "q9" }], "gaps": [] }), &[]), record( "If Kiko asks again: Fine, you win. Tell her. Later, maybe. I want to see the shape of that sound. I'll tell Meta I'm fine, more or less. And then", - json!({ "say": [], "unsent": [{ "draft": 1, "how": "declined", "quote": "If Kiko asks again" }], "gaps": [ + json!({ "say": [], "gaps": [ { "kind": "addressee", "draft": 2, "quote": null, "detail": "" }, { "kind": "elsewhere", "draft": 3, "quote": null, "detail": "" }, { "kind": "missing_affordance", "draft": null, "quote": "I want to see the shape of that sound.", "detail": "" }, @@ -291,9 +290,6 @@ fn k43_her_words_are_told_verbatim_whatever_the_record_heard() { assert_eq!(told(&record).0, shown, "an old record's `heard` is not read"); } -// --------------------------------------------------------------------------------------------- -// K33 (map 16.26): a refused close and a declined draft are told, by the fixed table. - // --------------------------------------------------------------------------------------------- // K49 (map 16.30.6): "reached" is derived once, by `settle`, for every row kind with words. @@ -318,47 +314,46 @@ fn k49_p4_a_gap_on_words_that_went_out_is_not_told() { assert!(unposted.iter().any(|line| line.starts_with("- Nothing reached anyone.")), "{unposted:?}"); } -/// A record whose decision declines `text` in #minds, with an amendment adding `text` there (event `$ev-1`), the +/// A record whose decision leaves `text` unfinished in #minds, with an amendment adding `text` there (event `$ev-1`), the /// actuator's `edited` receipts, and the room's `posted` ones. -fn declined_and_added(text: &str, edited: Value, posted: Value) -> Value { +fn unfinished_and_added(text: &str, edited: Value, posted: Value) -> Value { json!({ "interpreter": { - "room": MINDS, "said": [], "refused": [], "gaps": [], + "room": MINDS, "said": [], "refused": [], "gaps": [], "unfinished": text, "amended": [{ "room": MINDS, "target": "a1", "draft": 1, "event": "$ev-1", "added": text }], - "unsent": [{ "draft": 1, "how": "declined", "quote": "I keep it back", "words": text }], }, "posted": posted, "edited": edited, }) } -fn declined_told(record: &Value) -> bool { - outcome_of(record).unwrap().lines(packet().forms).iter().any(|line| line.contains("he chose not to send it")) +fn unfinished_told(record: &Value) -> bool { + outcome_of(record).unwrap().lines(packet().forms).iter().any(|line| line.contains("the turn ended before he finished writing it")) } /// Mutant k44-reached-ignores-addition: an addition the actuator made is a receipt that her words reached the room. #[test] fn k49_an_addition_receipt_counts_as_reached() { - let record = declined_and_added("Sent at nine.", json!([{ "event": "$ev-1", "refusal": null }]), json!([])); - assert!(!declined_told(&record), "{:?}", outcome_of(&record).unwrap().lines(packet().forms)); - assert!(outcome_of(&record).unwrap().omitted.iter().any(|why| why == "a declined draft of words a receipt shows reached #minds:gamecult.org: Sent at nine.")); + let record = unfinished_and_added("Sent at nine.", json!([{ "event": "$ev-1", "refusal": null }]), json!([])); + assert!(!unfinished_told(&record), "{:?}", outcome_of(&record).unwrap().lines(packet().forms)); + assert!(outcome_of(&record).unwrap().omitted.iter().any(|why| why == "a unfinished draft of words a receipt shows reached #minds:gamecult.org: Sent at nine.")); } /// Mutant k44-reached-any-room: a line posted in another room is no receipt for this one. #[test] fn k49_a_receipt_in_another_room_does_not_count() { - let elsewhere = declined_and_added("Sent at nine.", json!([]), json!([{ "event": "40", "room": SWARM, "text": "Sent at nine." }])); - assert!(declined_told(&elsewhere), "{:?}", outcome_of(&elsewhere).unwrap().lines(packet().forms)); - let here = declined_and_added("Sent at nine.", json!([]), json!([{ "event": "40", "room": MINDS, "text": "Sent at nine." }])); - assert!(!declined_told(&here), "the same receipt in #minds counts"); + let elsewhere = unfinished_and_added("Sent at nine.", json!([]), json!([{ "event": "40", "room": SWARM, "text": "Sent at nine." }])); + assert!(unfinished_told(&elsewhere), "{:?}", outcome_of(&elsewhere).unwrap().lines(packet().forms)); + let here = unfinished_and_added("Sent at nine.", json!([]), json!([{ "event": "40", "room": MINDS, "text": "Sent at nine." }])); + assert!(!unfinished_told(&here), "the same receipt in #minds counts"); } /// Mutant k44-reached-added-without-receipt: an addition the actuator refused, or never answered, did not reach the room. #[test] fn k49_an_addition_the_actuator_refused_did_not_reach() { for edited in [json!([{ "event": "$ev-1", "refusal": "too_long" }]), json!([{ "event": "$ev-2", "refusal": null }]), json!([])] { - let record = declined_and_added("Sent at nine.", edited.clone(), json!([])); - assert!(declined_told(&record), "{edited}: {:?}", outcome_of(&record).unwrap().lines(packet().forms)); + let record = unfinished_and_added("Sent at nine.", edited.clone(), json!([])); + assert!(unfinished_told(&record), "{edited}: {:?}", outcome_of(&record).unwrap().lines(packet().forms)); } } @@ -368,7 +363,7 @@ fn k49_an_addition_the_actuator_refused_did_not_reach() { fn k49_every_row_with_words_is_settled_by_its_room() { const SENTINEL: &str = "Osprey ledger at nine."; let decision = |extra: Value| { - let mut decision = json!({ "room": MINDS, "said": [], "refused": [], "gaps": [], "amended": [], "unsent": [] }); + let mut decision = json!({ "room": MINDS, "said": [], "refused": [], "gaps": [], "amended": [] }); for (key, value) in extra.as_object().unwrap() { decision[key] = value.clone(); } @@ -379,7 +374,6 @@ fn k49_every_row_with_words_is_settled_by_its_room() { ("gap", decision(json!({ "gaps": [{ "kind": "elsewhere", "from": "draft", "draft": 1, "words": SENTINEL }] }))), ("unfinished draft", decision(json!({ "unfinished": SENTINEL }))), ("unfinished draft", decision(json!({ "cut_by_cap": [SENTINEL] }))), - ("declined draft", decision(json!({ "unsent": [{ "draft": 1, "how": "declined", "quote": "I keep it back", "words": SENTINEL }] }))), ("unmade addition", decision(json!({ "refused": [{ "reason": "not_amendable", "text": SENTINEL, "draft": 1 }] }))), ]; for (row, decision) in rows { @@ -420,14 +414,13 @@ fn variant(part: &Part) -> &'static str { Part::NoteRefused(_) => "note_refused", Part::Failed => "failed", Part::BrokeAfter { .. } => "broke_after", - Part::Declined { .. } => "declined", Part::Read { .. } => "read", Part::ReadFailed { .. } => "read_failed", Part::ReadRefused { .. } => "read_refused", } } -const VARIANTS: usize = 15; +const VARIANTS: usize = 14; /// Every row kind, and every arm that renders a different sentence, with `s` in every text of a record it carries and in /// every read's target; and whether her told form shows those words (an echo, a held @@ -464,8 +457,6 @@ fn fixtures(s: &str) -> Vec<(Part, bool)> { out.push((Part::NoteRefused(Refusal::SecondNote), false)); out.push((Part::Failed, false)); out.push((Part::BrokeAfter { room: room() }, false)); - 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)); for (request, shows) in [ (ReadRequest::Web(format!("https://example.org/{s}")), true), (ReadRequest::Repo(format!("GameCult/Bifrost?q={s} plover")), true), @@ -562,25 +553,23 @@ fn k63_a_reach_is_a_clause_of_its_drafts_row() { let text = "I'll send the render tonight."; let clause = format!("It reaches for something he has no way to do from here. He had drafted: \"{text}\"."); let refused = |reason: &str| json!({ "interpreter": { "room": MINDS, "said": [], "refused": [{ "act": "say", "draft": 1, "text": text, "reason": reason }], "gaps": [reach_on_1(text)] }, "posted": [] }); - for (reason, row) in [("over_lines", "he had already sent two lines that turn."), ("undecided", "what was to become of it was never settled, so it was not sent."), ("not_quotable", "the line he meant to reply to is not one he can reply to here.")] { + for (reason, row) in [("over_lines", "he had already sent two lines that turn."), ("not_quotable", "the line he meant to reply to is not one he can reply to here.")] { let (lines, omitted) = told(&refused(reason)); assert_eq!(lines, [format!("- Nothing of this reached #minds:gamecult.org: {row} {clause}")], "{reason}: {omitted:?}"); } // An echo shows none either. assert_eq!(told(&refused("echo")).0, ["- Nothing reached #minds:gamecult.org. What he wrote was mostly the words he had just been sent, so none of it was sent. It reaches for something he has no way to do from here."]); - let declined = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [], "gaps": [reach_on_1(text)], "unsent": [{ "draft": 1, "how": "declined", "words": text, "quote": "Not tonight after all" }] }, "posted": [] }); - assert_eq!(told(&declined).0, [format!("- Nothing of this reached #minds:gamecult.org: he chose not to send it. In his thought: \"Not tonight after all\". {clause}")]); let elsewhere = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [], "gaps": [reach_on_1(text), { "kind": "elsewhere", "from": "draft", "draft": 1, "words": text }] }, "posted": [] }); assert_eq!(told(&elsewhere).0, [format!("- Nothing reached anyone. He meant this for another room or another time, and nothing carries it there; it arrives only if he sends it there. {clause}")]); } -/// A reach naming a draft no row tells (superseded) is its own row, as one she had drafted; a reach naming a line that went -/// out is a promise, unchanged; and a reach in her thought is its own row beside it. +/// A reach naming a draft no row tells is its own row, as one she had drafted; a reach naming a line that went out is the +/// say-then-amend row, unchanged; and a reach in her thought is its own row beside it. #[test] fn k63_a_said_line_with_a_gap_keeps_both() { let text = "Missed you too. I'll send the render tonight."; - let superseded = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [], "gaps": [reach_on_1(text)], "unsent": [{ "draft": 1, "how": "superseded", "words": text, "quote": "Better to say it plainly" }] }, "posted": [] }); - assert_eq!(told(&superseded).0, [format!("- Nothing happened. He reached for something he has no way to do from here, now or later, and it will not happen by itself. That he wanted it is kept in his record; no one has taken it up. He had drafted: \"{text}\".")]); + let unsaid = json!({ "interpreter": { "room": MINDS, "said": [], "refused": [], "gaps": [reach_on_1(text)] }, "posted": [] }); + assert_eq!(told(&unsaid).0, [format!("- Nothing happened. He reached for something he has no way to do from here, now or later, and it will not happen by itself. That he wanted it is kept in his record; no one has taken it up. He had drafted: \"{text}\".")]); let said = json!({ "interpreter": { "room": MINDS, "said": [{ "room": MINDS, "text": text }], "refused": [], "gaps": [reach_on_1(text), { "kind": "missing_affordance", "from": "thought", "words": "I want to hear the kettle myself" }] }, "posted": [{ "event": "40", "room": MINDS, "text": text }] }); let (lines, omitted) = told(&said); assert_eq!(lines, ["- Nothing happened. He reached for something he has no way to do from here, now or later, and it will not happen by itself. In his thought: \"I want to hear the kettle myself\". That he wanted it is kept in his record; no one has taken it up.".to_owned(), format!("- #minds:gamecult.org has, from him: \"{text}\". 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.")], "{omitted:?}"); diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index dc7bf51..5a396d1 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -764,17 +764,16 @@ fn r5_the_report_shows_the_packets_flags() { assert_eq!(out, "Packet flags: domain view: since 2026-11-20T09:01:00+00:00, 3 older items left out; guards bound: outcome; clipped: (identity)\n\n"); } -/// K31 (map 16.25.7, Low 7): the report shows the accounting: a turn with an unsent draft and a retry renders each. +/// K31 (map 16.25.7, Low 7): the report shows a retry, off the contract (map 16.35.3). #[test] fn k31_report_renders_accounting() { let decision = json!({ "said": [], "gaps": [], - "unsent": [{ "draft": 2, "how": "declined", "quote": "I hold that one back" }], - "retried": { "failed": "the answer leaves drafts unaccounted", "drafts": [2] } + "retried": { "failed": "the answer is not the speech contract" } }); let mut out = String::new(); crate::projection::harness::interpreter_markdown(&mut out, &decision); - assert_eq!(out, "**Interpreter: nothing said.**\n\n- unsent draft 2 (declined): \"I hold that one back\"\n- retried: the answer leaves drafts unaccounted, drafts 2\n\n"); + assert_eq!(out, "**Interpreter: nothing said.**\n\n- retried: the answer is not the speech contract\n\n"); } /// K32 (map 16.25.8, Low 10): in the simulator, a campaign read is served from her `[cast.domain]`, the one owner of what diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 8bc5c87..6bc871b 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -2613,34 +2613,6 @@ fn shares_a_run(text: &str, other: &str) -> bool { tokens(text).windows(3).any(|run| theirs.contains(run)) } -/// K43 (map 16.29.10), R15's X.1 r1: Libby declined her one draft, citing her thought, and Heimdall's lines share runs -/// with both ("only say hello", "lines are ready"). At her next wake, with Heimdall's line said again, her view carries -/// the thought and the draft verbatim; the Projector gets the event and no run of either. This replaces Hands' pin in -/// `k41_x1_r1_decline_shows_its_thought`. -#[test] -fn k43_x1_r1_her_decline_is_hers_to_read() { - use interpret::tests::{X1_HEIMDALL_R15, X1_LIBBY_R15, X1_LIBBY_R15_THOUGHT, X1_META_R1, x1_packet}; - const MINDS: &str = "#minds:gamecult.org"; - let mut last = x1_packet(); - last.quotable[1].text = X1_HEIMDALL_R15.into(); - last.bodies = vec![X1_META_R1.into(), X1_HEIMDALL_R15.into()]; - let decision = interpret::tests::answered(&last, X1_LIBBY_R15, json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "declined", "quote": X1_LIBBY_R15_THOUGHT }] })); - let draft = decision["unsent"][0]["words"].as_str().unwrap_or_else(|| panic!("{decision}")).to_owned(); - assert!(shares_a_run(X1_LIBBY_R15_THOUGHT, X1_HEIMDALL_R15) && shares_a_run(&draft, X1_HEIMDALL_R15), "the R15 shape: the old guard withheld both"); - let record = json!({ "interpreter": decision, "posted": [], "edited": [] }); - let room = Room { messages: vec![message(MINDS, "@heimdall:gamecult.org", "Heimdall", X1_HEIMDALL_R15, 2, true)], here: Some(MINDS.into()), ..Room::default() }; - let packet = packet_of(TurnKind::Chat, &state(), &room, &with_last(&record), 1); - // Golden: her view's outcome block and the Projector's outcome section. - assert_eq!(outcome_block(&packet), format!("What came of her last turn:\n- Nothing of this reached {MINDS}: she chose not to send it. In her thought: {}. She had drafted: {}.", select::spoken(X1_LIBBY_R15_THOUGHT), select::spoken(&draft)), "{}", packet.in_view); - assert_eq!(outcome_events(&packet), [format!("- Nothing of this reached {MINDS}: she chose not to send it.")], "{}", packet.context); - let projector = narrate::projector_prompt(&packet, &Tuning::default()); - let section = packet.context.split("\nHere and now:\n").next().unwrap(); - assert!(!shares_a_run(X1_LIBBY_R15_THOUGHT, section) && !shares_a_run(&draft, section), "{section}"); - for words in ["only say hello", "lines are ready", "leave the door open", "Poke at whatever"] { - assert!(!projector.contains(words), "{words}: {projector}"); - } -} - /// K43 (map 16.29.10, 16.29.7's E.2 r6): her last turn's two lines are in front of her verbatim, though Kiko's line this turn repeats runs of them; the R15 guard showed both lines as not shown, and she then /// confessed to a line she never said. The record is in E.2 r5's shape, not its text. #[test] diff --git a/crates/mind-body/tests/public_surface.txt b/crates/mind-body/tests/public_surface.txt index d492132..0af4253 100644 --- a/crates/mind-body/tests/public_surface.txt +++ b/crates/mind-body/tests/public_surface.txt @@ -282,7 +282,6 @@ mind_body::projection::harness: struct Fixture # [derive (Clone , Debug)] pub-fi mind_body::projection::harness: struct Harness< 'a > pub-fields[instance: String, persona: Option < & 'a dyn PersonaSource >, model: Option < & 'a dyn Model >, tuning: PathBuf] mind_body::projection::harness: struct Message # [derive (Clone , Debug , Deserialize)] pub-fields[from: String, name: String, room: String, ago: Option < String >, round: Option < usize >, says: String, new: bool, tag: bool, mentions: Vec < String >, dm: bool, to: Option < String >, follow_up: bool, reply_to: Option < usize >] mind_body::projection::interpret: impl Drafts -mind_body::projection::interpret: impl Faults mind_body::projection::interpret: impl GapKind mind_body::projection::interpret: impl Refusal mind_body::projection::narrate: # [derive (Clone , Debug , PartialEq , Eq)] pub enum Turn { User (String) , Assistant { text : String , states : Vec < Reasoning > } , }