From 4fe98f56b790ce5b131dd6b195e7abf70603f440 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 21 Nov 2026 23:02:14 +0100 Subject: [PATCH] Persona K31: every draft accounted for, once, and shown (map 16.25.7) Deleted first: the conditional gap kind (contract enum, GapKind, both outcome arms, the frame clause, the conditional.json outcome fixture), UNSENT_QUOTE_MIN_WORDS, decision.usage, retried.usage and earlier_calls. decide_in resolves the gaps before accounting, and a gap accounts for a draft only where the resolved gap names it (from == draft); unwritten and unresolved gaps name none. Held and superseded quotes need four words (GAP_QUOTE_MIN_WORDS). The retry is the first prompt plus one paragraph in code's words naming that answer's fault (the drafts left out, or the serde error clipped at 200 B). A decision carries calls: earlier segments' calls, then this segment's attempts, each with usage and retry; later_failed keeps only its own calls. The harness sums calls for the Interpreter's usage line and renders unsent drafts and the retry; the simulation's report renders every Applied field (closed, reaffirmed, blocked, pruned). Tests: k31_unwritten_names_no_draft, k31_conditional_is_no_kind, k31_held_quote_is_four_words, k31_retry_names_its_fault, k31_calls_counted_once, k31_report_renders_accounting; existing fixtures moved off conditional and onto four-word held quotes; golden frame updated. Verified on Yggdrasil (ygg-verify, rust image): cargo test -p mind-body 814 passed 0 failed; clippy -p mind-body --all-targets -D warnings clean. Co-Authored-By: Claude Opus 5.5 --- .../harness/outcomes/conditional.json | 10 -- .../fixtures/interpret/golden-speech.txt | 2 +- crates/mind-body/src/projection.rs | 5 +- crates/mind-body/src/projection/harness.rs | 24 +++- .../mind-body/src/projection/harness/tests.rs | 1 - crates/mind-body/src/projection/interpret.rs | 84 ++++++++------ .../src/projection/interpret/tests.rs | 108 ++++++++++++++++-- crates/mind-body/src/projection/outcome.rs | 3 +- .../mind-body/src/projection/outcome/tests.rs | 19 ++- crates/mind-body/src/projection/simulate.rs | 26 ++++- .../src/projection/simulate/tests.rs | 26 +++++ crates/mind-body/src/projection/tests.rs | 2 +- 12 files changed, 232 insertions(+), 78 deletions(-) delete mode 100644 crates/mind-body/fixtures/harness/outcomes/conditional.json diff --git a/crates/mind-body/fixtures/harness/outcomes/conditional.json b/crates/mind-body/fixtures/harness/outcomes/conditional.json deleted file mode 100644 index a432917..0000000 --- a/crates/mind-body/fixtures/harness/outcomes/conditional.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "interpreter": { - "room": "!dm-meta:gamecult.org", - "heard": ["hey you. I missed talking to you this week. how are you, really? and no, \"busy\" doesn't count as an answer, I know where you live"], - "said": [], - "refused": [], - "gaps": [{ "kind": "conditional", "from": "draft", "draft": 1, "words": "Honestly? Tired. Good tired, mostly.", "detail": "only if she asks again" }] - }, - "posted": [] -} diff --git a/crates/mind-body/fixtures/interpret/golden-speech.txt b/crates/mind-body/fixtures/interpret/golden-speech.txt index de00f87..c290474 100644 --- a/crates/mind-body/fixtures/interpret/golden-speech.txt +++ b/crates/mind-body/fixtures/interpret/golden-speech.txt @@ -10,7 +10,7 @@ He speaks only in this room. What he knows privately is listed below as private: Answer with the speech contract's object. `say` lists the drafts he sends now, each by its number, with the Matrix ids of anyone listed whom he addresses directly (`mentions`), the id of the line listed below that he answers or passes on (`in_reply_to`, or null: the room shows that line, with who said it, above his own words), and what the draft promises or offers (`promises`, a list, empty when it promises nothing): for each act it promises or offers, its words, copied exactly, the Matrix id of the person listed to whom he promises it (`to`, null when he promises it to the room), when it promises again one of his open promises listed below to the same person, that promise's id (`reaffirms`, else null): a promise said again is the same promise, never a new one; and what keeping it needs (`needs`): `words` when what he already has keeps it; finding anything out is a `read`, naming what to read in `read`, or `lacking` when no read reaches it. `gaps` records what he meant and did not send. `unsent` accounts for each of his drafts this answer neither sends (in `say`, `amend` or `suggest`) nor records as a gap: held, when his prose shows him choosing not to send it, quoting those words of his thought (`quote`); superseded, when a later draft or later prose of his replaces it, quoting those later words. Every draft is accounted for: one left out fails the answer. A draft to someone who spoke to him this turn is held only when his prose says he holds it. `amend` adds to one of his own lines listed below, at most one a turn, only when his thought shows him choosing to correct or add to that line: name the line by its id, the draft that is his addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; he never takes a word back. `suggest` leaves Self one note, at most one a turn, only when his thought shows him choosing to: name the draft that is the note, its kind (feedback when he passes on what someone listed said, with that person's Matrix id in `about`; idea when it is his own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes his open promises listed below, each by its id: kept, citing the draft by which he does it (`evidence.draft`); withdrawn, citing the draft in which he takes it back to the person he promised, or tells them he cannot do it; released, citing the id of the line listed below that he may reply to in which the person he promised lets him off it (`evidence.line`). A release says he no longer owes it; patience is not a release, so "no hurry" or "whenever you've read it is fine" leaves the promise open. Every close also quotes in `thought` the words of his prose here that take it up, copied exactly, and `still_stands` is true when anything in his prose here holds the promise as still owed or not yet done ("the promise stays open until I've read it"): then it is not closed. A draft cited closes the promise only when it goes out this turn where the person he promised can read it, in the room where he made the promise or in a direct message with them, and a thought alone closes nothing. A promise he has no way to do is never kept by him: telling the person he promised that he cannot do it withdraws it, and that person can release it. -A draft is said whole or not at all, and only once. At most two drafts a turn. Record a gap instead of guessing: conditional when he has drafted something he might say but has not chosen to, 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 three, 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. +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. Who he is: Heimdall (he/him) diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index 08f938c..b4fb699 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -493,7 +493,10 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni // A failed call on a later segment fails that segment only: what was decided before it stands, and posts and // applies (Soul p5); the failure, with what it cost, is recorded beside it. if next.get("failed").is_some() { - decision["later_failed"] = json!({ "segment": reads.len() + 1, "failed": next["failed"], "raw": next.get("raw"), "usage": next["usage"] }); + // Its own calls only: the earlier ones ride in `decision` already, so each is counted once. + let before = decision["calls"].as_array().map_or(0, Vec::len); + let own: Vec = next["calls"].as_array().into_iter().flatten().skip(before).cloned().collect(); + decision["later_failed"] = json!({ "segment": reads.len() + 1, "failed": next["failed"], "raw": next.get("raw"), "calls": own }); break; } decision = next; diff --git a/crates/mind-body/src/projection/harness.rs b/crates/mind-body/src/projection/harness.rs index 8de2436..907d5a0 100644 --- a/crates/mind-body/src/projection/harness.rs +++ b/crates/mind-body/src/projection/harness.rs @@ -537,7 +537,21 @@ Usage: {} quoted(out, persona["prose"].as_str().unwrap_or_default()); } interpreter_markdown(out, &render["interpreter"]); - let _ = writeln!(out, "Usage: projector {}; persona {}; interpreter {}\n", usage_line(&render["usage"]), usage_line(&persona["usage"]), usage_line(&render["interpreter"]["usage"])); + let _ = writeln!(out, "Usage: projector {}; persona {}; interpreter {}\n", usage_line(&render["usage"]), usage_line(&persona["usage"]), usage_line(&calls_usage(&render["interpreter"]))); +} + +/// The Interpreter's usage over a wake: every call in its `calls`, summed field by field (map 16.25.7, Low 6). None when +/// it made no call. +fn calls_usage(decision: &Value) -> Value { + let calls: Vec<&Value> = decision["calls"].as_array().into_iter().flatten().map(|call| &call["usage"]).filter(|usage| usage.is_object()).collect(); + if calls.is_empty() { + return Value::Null; + } + let mut sum = serde_json::Map::new(); + for field in USAGE_FIELDS { + sum.insert(field.to_owned(), calls.iter().map(|usage| usage[field].as_u64().unwrap_or(0)).sum::().into()); + } + Value::Object(sum) } /// The Interpreter's speech decision: each line said with its room, mentions, reply target and the draft it is; each @@ -577,6 +591,14 @@ pub(crate) fn interpreter_markdown(out: &mut String, decision: &Value) { 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()); + } + 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}"); + } // 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() { let how = if read["ok"] == true { format!("{} bytes", read["bytes"]) } else { format!("failed: {}", read["failure"].as_str().unwrap_or_default()) }; diff --git a/crates/mind-body/src/projection/harness/tests.rs b/crates/mind-body/src/projection/harness/tests.rs index 60f2b16..b2249be 100644 --- a/crates/mind-body/src/projection/harness/tests.rs +++ b/crates/mind-body/src/projection/harness/tests.rs @@ -357,7 +357,6 @@ fn soul_k9_each_outcome_fixture_opens_the_packet_with_his_words_verbatim() { for (file, told) in [ ("posted.json", "- !dm-meta:gamecult.org has, from him: \"Missed you too. I'll send the render tonight.\"."), ("refused.json", "- Nothing reached !dm-meta:gamecult.org. What he wrote was mostly the words he had just been sent, so none of it was sent."), - ("conditional.json", "- Nothing reached !dm-meta:gamecult.org. He wrote this and did not send it, and it is not sent unless he sends it: \"Honestly? Tired. Good tired, mostly.\"."), ("missing-affordance.json", "it will not happen by itself. In his thought: \"I want to show her the render, not describe it.\"."), ] { let record: Value = serde_json::from_str(&std::fs::read_to_string(fixtures().join("outcomes").join(file)).unwrap()).unwrap(); diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index f00d160..22ffa79 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -71,7 +71,7 @@ pub(crate) const SPEECH_OPENING: &str = "You decide what one person says aloud i /// The speech contract, sent as the schema turn's output schema (`--json-schema`): the drafts she sends now by number, /// and the gaps. The model writes no words of hers. -pub(crate) const SPEECH_SCHEMA: &str = r#"{"type":"object","additionalProperties":false,"required":["say","gaps","amend","suggest","state","read","unsent"],"properties":{"unsent":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","how","quote"],"properties":{"draft":{"type":"integer"},"how":{"type":"string","enum":["held","superseded"]},"quote":{"type":"string"}}}},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target","quote"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"},"quote":{"type":"string"}}},"state":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","promise","how","evidence","thought","still_stands"],"properties":{"kind":{"type":"string","enum":["promise_close"]},"promise":{"type":"string"},"how":{"type":"string","enum":["kept","withdrawn","released"]},"evidence":{"type":"object","additionalProperties":false,"required":["draft","line","read"],"properties":{"draft":{"type":["integer","null"]},"line":{"type":["string","null"]},"read":{"type":["integer","null"]}}},"thought":{"type":["string","null"]},"still_stands":{"type":"boolean"}}}},"suggest":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","about","private"],"properties":{"kind":{"type":"string","enum":["feedback","idea"]},"draft":{"type":"integer","minimum":1},"about":{"type":["string","null"]},"private":{"type":"boolean"}}}},"amend":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["target","draft","promises"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","in_reply_to","promises"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"in_reply_to":{"type":["string","null"]},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"gaps":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","quote","detail"],"properties":{"kind":{"type":"string","enum":["conditional","addressee","elsewhere","missing_affordance","unwritten"]},"draft":{"type":["integer","null"]},"quote":{"type":["string","null"]},"detail":{"type":"string"}}}}}}"#; +pub(crate) const SPEECH_SCHEMA: &str = r#"{"type":"object","additionalProperties":false,"required":["say","gaps","amend","suggest","state","read","unsent"],"properties":{"unsent":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","how","quote"],"properties":{"draft":{"type":"integer"},"how":{"type":"string","enum":["held","superseded"]},"quote":{"type":"string"}}}},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target","quote"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"},"quote":{"type":"string"}}},"state":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","promise","how","evidence","thought","still_stands"],"properties":{"kind":{"type":"string","enum":["promise_close"]},"promise":{"type":"string"},"how":{"type":"string","enum":["kept","withdrawn","released"]},"evidence":{"type":"object","additionalProperties":false,"required":["draft","line","read"],"properties":{"draft":{"type":["integer","null"]},"line":{"type":["string","null"]},"read":{"type":["integer","null"]}}},"thought":{"type":["string","null"]},"still_stands":{"type":"boolean"}}}},"suggest":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","about","private"],"properties":{"kind":{"type":"string","enum":["feedback","idea"]},"draft":{"type":"integer","minimum":1},"about":{"type":["string","null"]},"private":{"type":"boolean"}}}},"amend":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["target","draft","promises"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","in_reply_to","promises"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"in_reply_to":{"type":["string","null"]},"promises":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["words","to","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"reaffirms":{"type":["string","null"]},"needs":{"type":"object","additionalProperties":false,"required":["kind","read"],"properties":{"kind":{"type":"string","enum":["words","read","lacking"]},"read":{"type":["object","null"],"additionalProperties":false,"required":["kind","target"],"properties":{"kind":{"type":"string","enum":["domain","mind","repo","web"]},"target":{"type":"string"}}}}}}}}}}},"gaps":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","quote","detail"],"properties":{"kind":{"type":"string","enum":["addressee","elsewhere","missing_affordance","unwritten"]},"draft":{"type":["integer","null"]},"quote":{"type":["string","null"]},"detail":{"type":"string"}}}}}}"#; /// The speech frame before the guidance: what to decide, from what, and the attribution rule. Code, not tuning (map /// 16.7), in her own pronouns (16.19.7). The tuning's `interpreter.guidance` (what counts as her choosing to send it @@ -93,7 +93,7 @@ fn speech_frame_tail(her: Forms) -> String { Answer with the speech contract's object. `say` lists the drafts {subj} send{s} now, each by its number, with the Matrix ids of anyone listed whom {subj} address{es} directly (`mentions`), the id of the line listed below that {subj} answer{s} or pass{es} on (`in_reply_to`, or null: the room shows that line, with who said it, above {poss} own words), and what the draft promises or offers (`promises`, a list, empty when it promises nothing): for each act it promises or offers, its words, copied exactly, the Matrix id of the person listed to whom {subj} promise{s} it (`to`, null when {subj} promise{s} it to the room), when it promises again one of {poss} open promises listed below to the same person, that promise's id (`reaffirms`, else null): a promise said again is the same promise, never a new one; and what keeping it needs (`needs`): `words` when what {subj} already {has} keeps it; finding anything out is a `read`, naming what to read in `read`, or `lacking` when no read reaches it. `gaps` records what {subj} meant and did not send. `unsent` accounts for each of {poss} drafts this answer neither sends (in `say`, `amend` or `suggest`) nor records as a gap: held, when {poss} prose shows {obj} choosing not to send it, quoting those words of {poss} thought (`quote`); superseded, when a later draft or later prose of {poss} replaces it, quoting those later words. Every draft is accounted for: one left out fails the answer. A draft to someone who spoke to {obj} this turn is held only when {poss} prose says {subj} hold{s} it. `amend` adds to one of {poss} own lines listed below, at most one a turn, only when {poss} thought shows {obj} choosing to correct or add to that line: name the line by its id, the draft that is {poss} addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; {subj} never take{s} a word back. `suggest` leaves Self one note, at most one a turn, only when {poss} thought shows {obj} choosing to: name the draft that is the note, its kind (feedback when {subj} pass{es} on what someone listed said, with that person's Matrix id in `about`; idea when it is {poss} own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes {poss} open promises listed below, each by its id: kept, citing the draft by which {subj} {does} it (`evidence.draft`); withdrawn, citing the draft in which {subj} take{s} it back to the person {subj} promised, or tell{s} them {subj} cannot do it; released, citing the id of the line listed below that {subj} may reply to in which the person {subj} promised lets {obj} off it (`evidence.line`). A release says {subj} no longer owe{s} it; patience is not a release, so \"no hurry\" or \"whenever you've read it is fine\" leaves the promise open. Every close also quotes in `thought` the words of {poss} prose here that take it up, copied exactly, and `still_stands` is true when anything in {poss} prose here holds the promise as still owed or not yet done (\"the promise stays open until I've read it\"): then it is not closed. A draft cited closes the promise only when it goes out this turn where the person {subj} promised can read it, in the room where {subj} made the promise or in a direct message with them, and a thought alone closes nothing. A promise {subj} {has} no way to do is never kept by {obj}: telling the person {subj} promised that {subj} cannot do it withdraws it, and that person can release it. -A draft is said whole or not at all, and only once. At most two drafts a turn. Record a gap instead of guessing: conditional when {subj} {has} drafted something {subj} might say but {has} not chosen to, 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 three, 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.", +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" }, does = if s.is_empty() { "do" } else { "does" }, ) @@ -239,8 +239,6 @@ fn refused(act: Act, draft: Option<&Draft>, cited: Option, reason: Refusal) #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub(crate) enum GapKind { - /// She drafted something she might say, and has not chosen to. - Conditional, /// She means to send a draft, and whom to is unclear. Addressee, /// She means a draft for another room or another time. @@ -258,7 +256,6 @@ pub(crate) enum GapKind { impl GapKind { fn of(kind: &str) -> Self { match kind.trim() { - "conditional" => Self::Conditional, "addressee" => Self::Addressee, "elsewhere" => Self::Elsewhere, "missing_affordance" => Self::MissingAffordance, @@ -281,7 +278,8 @@ impl GapKind { /// names a draft she said is a promise of an act she cannot do, 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 reach (`missing_affordance`) names the draft that promises +/// 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 promises /// it when there is one, said or not (map 16.20.6), 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. /// @@ -292,7 +290,7 @@ fn gap(prose: &str, found: &Drafts, raw: &Value) -> Value { if kind == GapKind::Unresolved { gap["declared"] = raw.get("kind").cloned().unwrap_or_else(|| raw.clone()); } - let names_a_draft = kind != GapKind::Unwritten; + let names_a_draft = !matches!(kind, GapKind::Unwritten | GapKind::Unresolved); let quote = raw.get("quote").and_then(Value::as_str).unwrap_or_default().trim(); // A reach that quotes a draft by its words, with no number, is about that draft: a promise in it (map 16.20.6). let quoted_draft = || (kind == GapKind::MissingAffordance && words(quote) >= GAP_QUOTE_MIN_WORDS).then(|| found.drafts.iter().find(|draft| draft.text.contains(quote))).flatten(); @@ -360,16 +358,17 @@ enum UnsentHow { } /// The drafts of her wake the answer leaves unaccounted (Soul's R10): not proposed in `say`, `amend` or `suggest`, not -/// named by a gap, and not `unsent` with a quote of her prose that stands where it must (her thought for a held one, -/// after the draft for a superseded one). -fn unaccounted(answer: &Answer, prose: &str, found: &Drafts) -> Vec { +/// named by a resolved gap (`gaps`, from `gap`: only one whose `from` is `draft`, so an `unwritten` or unresolved gap +/// accounts for none, map 16.25.7), 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(); - accounted.extend(answer.gaps.iter().filter_map(|gap| numbered(gap.get("draft").and_then(Value::as_i64)))); + accounted.extend(gaps.iter().filter(|gap| gap["from"] == "draft").filter_map(|gap| gap["draft"].as_u64()).filter_map(|n| usize::try_from(n).ok())); for unsent in &answer.unsent { let Some(draft) = found.numbered(unsent.draft) else { continue }; let quote = unsent.quote.trim(); - let stands = words(quote) >= UNSENT_QUOTE_MIN_WORDS + let stands = words(quote) >= GAP_QUOTE_MIN_WORDS && match unsent.how { UnsentHow::Held => found.thought(prose).into_iter().any(|(start, end)| SourceSpan::locate(&prose[start..end], quote).is_some()), UnsentHow::Superseded => SourceSpan::locate(&prose[draft.end.min(prose.len())..], quote).is_some(), @@ -381,9 +380,6 @@ fn unaccounted(answer: &Answer, prose: &str, found: &Drafts) -> Vec { found.drafts.iter().map(|draft| draft.n).filter(|n| !accounted.contains(n)).collect() } -/// The fewest words an `unsent` citation of her prose may be. -const UNSENT_QUOTE_MIN_WORDS: usize = 2; - /// Where in her wake a decision falls (map 16.22.3): what was decided earlier this wake (none for her first segment), /// where her new segment begins in her prose, what she has read so far this wake, and her earlier segments with their /// bridges, as the Interpreter is shown them. The Interpreter judges only the new segment; drafts are numbered across the @@ -618,30 +614,56 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na let found = drafts(prose); let segment = prose.get(wake.from..).unwrap_or_default(); let prompt = speech_prompt_in(packet, narration, segment, tuning, wake.before, &found, &wake.earlier.and_then(|earlier| earlier["read_refused"].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; the - // first attempt rides in the decision with its usage, so every call is counted. + // 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. let mut retried: Option = None; - let (answer, parsed) = loop { - let answer = match model.ask(request_id, &tuning.interpreter.model, &prompt, Some(SPEECH_SCHEMA)) { + let mut asking = prompt.clone(); + let (parsed, gaps) = loop { + let answer = match model.ask(request_id, &tuning.interpreter.model, &asking, Some(SPEECH_SCHEMA)) { Ok(answer) => answer, - Err(failed) => return json!({ "failed": failed.reason, "usage": failed.usage, "retried": retried }), + Err(failed) => { + calls.push(json!({ "usage": failed.usage, "retry": false })); + return json!({ "failed": failed.reason, "calls": calls, "retried": retried }); + } }; - let fault = match serde_json::from_str::(&answer.text) { - Ok(parsed) => match unaccounted(&parsed, prose, &found) { - missing if missing.is_empty() => break (answer, parsed), - missing => json!({ "failed": "the answer leaves drafts unaccounted", "drafts": missing, "raw": answer.text, "usage": answer.usage }), - }, - Err(_) => json!({ "failed": "the answer is not the speech contract", "raw": answer.text, "usage": answer.usage }), + let (fault, missed) = match serde_json::from_str::(&answer.text) { + Ok(parsed) => { + let gaps: Vec = parsed.gaps.iter().map(|raw| gap(prose, &found, raw)).collect(); + match unaccounted(&parsed, &gaps, prose, &found) { + missing if missing.is_empty() => { + calls.push(json!({ "usage": answer.usage, "retry": false })); + break (parsed, gaps); + } + missing => { + let list = missing.iter().map(usize::to_string).collect::>().join(", "); + let missed = format!("An earlier answer to this left drafts {list} accounted for nowhere: each draft is in `say`, `amend` or `suggest`, a gap that names it, or `unsent`."); + (json!({ "failed": "the answer leaves drafts unaccounted", "drafts": missing, "raw": answer.text }), missed) + } + } + } + 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(); + fault["calls"] = json!(calls); return fault; } + calls.push(json!({ "usage": answer.usage, "retry": true })); retried = Some(fault); + asking = format!("{prompt}\n\n{missed}"); }; let earlier = |key: &str| wake.earlier.and_then(|earlier| earlier[key].as_array()).cloned().unwrap_or_default(); - let gaps: Vec = parsed.gaps.iter().map(|raw| gap(prose, &found, raw)).collect(); // What she was sent and what she has read this wake: what an echo is measured against, and what no quote she is told // repeats a run of (map 16.22.3). let bodies: Vec = packet.bodies.iter().cloned().chain(wake.read.iter().cloned()).collect(); @@ -652,7 +674,7 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na // The reads of this conversation, by normal form and whether each found its target: what a kept promise that needs a // read is checked against (`commit::apply`, map 16.25.4). let conversation_reads: Vec = packet.already_read.iter().map(|tried| json!({ "key": tried.key, "found": tried.found })).collect(); - let mut decision = json!({ "said": [], "refused": [], "gaps": gaps, "heard": bodies, "lines": lines, "promises": packet.promises, "conversation_reads": conversation_reads, "usage": answer.usage, "read": null, "at_ms": packet.now_ms }); + let mut decision = json!({ "said": [], "refused": [], "gaps": gaps, "heard": bodies, "lines": lines, "promises": packet.promises, "conversation_reads": conversation_reads, "calls": calls, "read": null, "at_ms": packet.now_ms }); if let Some(retried) = retried { decision["retried"] = retried; } @@ -662,12 +684,6 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na if let Some(reads) = wake.earlier.map(|earlier| earlier["reads"].clone()).filter(Value::is_array) { decision["reads"] = reads; } - // The earlier calls of this wake, each with its usage, so the report's totals count every call (Soul: 72 of 76). - if let Some(before) = wake.earlier { - let mut calls = before["earlier_calls"].as_array().cloned().unwrap_or_default(); - calls.push(json!({ "usage": before["usage"] })); - decision["earlier_calls"] = json!(calls); - } if let Some(open) = found.unfinished { decision["unfinished"] = json!(prose[open + DRAFT_OPEN.len()..].trim()); } diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 2b32143..02b2a80 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -341,20 +341,20 @@ fn an_unwritten_gap_keeps_its_located_passage_and_says_nothing() { #[test] fn a_draft_gap_names_its_draft_and_carries_its_words() { let prose = "If Kiko asks again: Fine, you win. Not yet, though."; - let gaps = gaps_of(&packet(), prose, json!([{ "kind": "conditional", "draft": 1, "quote": null, "detail": "only if asked" }, { "kind": "elsewhere", "draft": 2, "quote": null, "detail": "" }])); + let gaps = gaps_of(&packet(), prose, json!([{ "kind": "addressee", "draft": 1, "quote": null, "detail": "only if asked" }, { "kind": "elsewhere", "draft": 2, "quote": null, "detail": "" }])); assert_eq!((gaps[0]["from"].as_str(), gaps[0]["draft"].as_u64(), gaps[0]["words"].as_str()), (Some("draft"), Some(1), Some("Fine, you win.")), "{}", gaps[0]); assert_eq!(gaps[1]["from"], "unlocated", "draft 2 names no draft and no passage of his thought: {}", gaps[1]); } #[test] fn a_gap_quote_shown_back_is_four_words_of_thought_outside_every_draft() { - let prose = "I could tell Nibu. I could tell Nibu the truth. Not yet."; + let prose = "I could tell Nibu. I could tell Nibu the truth. Not yet, not tonight."; let answer = json!({ "say": [], "gaps": [ { "kind": "unwritten", "draft": null, "quote": "tell", "detail": "" }, { "kind": "unwritten", "draft": null, "quote": "I could tell Nibu the truth.", "detail": "" }, - { "kind": "conditional", "draft": null, "quote": "I could tell Nibu.", "detail": "" }, - { "kind": "conditional", "draft": null, "quote": "I will tell Nibu tomorrow.", "detail": "" }, - ], "unsent": [{ "draft": 1, "how": "held", "quote": "Not yet" }] }); + { "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": "held", "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"); @@ -472,7 +472,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, "hold the rest")); + 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 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 +497,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, "And then")) + answered(packet, &prose, holding_the_rest(json!({ "say": say, "gaps": [], "suggest": suggest }), &prose, "I'll leave Self a note")) } fn refusals(decision: &Value) -> Vec<(String, String)> { @@ -584,7 +584,7 @@ fn soul_an_amendment_that_echoes_what_he_heard_is_refused() { fn soul_a_gap_never_contradicts_what_went_out() { let prose = "I'm fine, more or less. And I'll tell her the rest tomorrow, honestly."; let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1 }], "gaps": [ - { "kind": "conditional", "draft": 1, "quote": null, "detail": "" }, + { "kind": "addressee", "draft": 1, "quote": null, "detail": "" }, { "kind": "unwritten", "draft": 1, "quote": "I'm fine, more or less.", "detail": "" }, { "kind": "unwritten", "draft": 1, "quote": "I'll tell her the rest tomorrow, honestly.", "detail": "" }, ] })); @@ -647,11 +647,11 @@ fn k17_a_thought_only_intent_is_a_reach_and_any_other_gap_on_an_acted_draft_is_a let prose = "Meta's question is a good one. I'll look into it. Good question. Note: look into it."; let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1 }], "gaps": [ { "kind": "missing_affordance", "draft": null, "quote": "I'll look into it.", "detail": "" }, - { "kind": "conditional", "draft": 1, "quote": null, "detail": "" }, + { "kind": "addressee", "draft": 1, "quote": null, "detail": "" }, { "kind": "missing_affordance", "draft": 2, "quote": null, "detail": "" }, ], "suggest": [{ "kind": "idea", "draft": 2, "about": null, "private": false }] })); let from: Vec<&str> = decision["gaps"].as_array().unwrap().iter().map(|gap| gap["from"].as_str().unwrap()).collect(); - assert_eq!(from, ["thought", "acted", "acted"], "a reach in his thought; a conditional on the said draft; a reach naming the draft left for Self: {decision}"); + assert_eq!(from, ["thought", "acted", "acted"], "a reach in his thought; an addressee gap on the said draft; a reach naming the draft left for Self: {decision}"); assert_eq!(decision["gaps"][0]["words"], "I'll look into it."); let prompt = speech_prompt(&packet(), "x", "y", &Tuning::default()); assert!(prompt.contains("missing_affordance when he means to do something, now or later, that his body cannot do") && prompt.contains("an intent to act is missing_affordance, an intent to say now with no draft is unwritten"), "{prompt}"); @@ -702,7 +702,7 @@ fn k18_a_note_whose_answer_does_not_say_private_is_refused_as_private() { #[test] fn k21_a_promise_is_four_words_or_more_found_case_blind_and_an_addition_carries_one_too() { let prose = "I hold one back. Missed you too. I'll send the render tonight. Also the kettle sounds fine."; - let say = |draft: u64, promises: &str| answered(&packet(), prose, holding_the_rest(json!({ "say": [{ "draft": draft, "mentions": [], "in_reply_to": null, "promises": [{ "words": promises, "to": null, "needs": { "kind": "lacking", "read": null } }] }], "gaps": [] }), prose, "hold one back")); + let say = |draft: u64, promises: &str| answered(&packet(), prose, holding_the_rest(json!({ "say": [{ "draft": draft, "mentions": [], "in_reply_to": null, "promises": [{ "words": promises, "to": null, "needs": { "kind": "lacking", "read": null } }] }], "gaps": [] }), prose, "I hold one back")); let short = say(2, "the"); assert_eq!((short["gaps"].as_array().unwrap().len(), short["promises_unused"].clone()), (0, json!([{ "draft": 2, "promises": "the", "why": "fewer than four words" }])), "{short}"); assert_eq!(say(1, "the render tonight")["promises_unused"][0]["why"], "fewer than four words"); @@ -1150,7 +1150,7 @@ fn r10_every_draft_is_sent_held_superseded_or_gapped() { assert!(held.get("failed").is_none() && held["unsent"][0]["how"] == "held", "{held}"); let uncited = answered(&packet(), "I'll keep this one back for now. Meta, sorry.", json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "held", "quote": "words she never wrote" }] })); assert!(uncited.get("failed").is_some(), "{uncited}"); - let superseded = answered(&packet(), "Meta, it's Tuesday. No, wrong day. Meta, it's Wednesday.", json!({ "say": [{ "draft": 2, "mentions": [], "in_reply_to": null, "promises": [] }], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "No, wrong day" }] })); + 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, "promises": [] }], "gaps": [], "unsent": [{ "draft": 1, "how": "superseded", "quote": "No, that's the wrong day" }] })); assert!(superseded.get("failed").is_none(), "{superseded}"); } @@ -1283,3 +1283,87 @@ fn k30_golden_frame_and_promise_list() { let golden = include_str!("../../../fixtures/interpret/golden-speech.txt").replace("\r\n", "\n"); assert_eq!(prompt, golden, "the Interpreter's frame moved; if deliberately, the new golden file is:\n<<>>"); } + +// --------------------------------------------------------------------------------------------- +// K31 (map 16.25.7): every draft accounted for once, by a resolved act, gap or quoted `unsent`; the retry names its +// fault; every call counted once. + +/// The Interpreter's prompts, in the order it was asked. +fn speech_prompts(model: &Scripted) -> Vec { + model.calls.borrow().iter().filter(|(_, prompt)| prompt.starts_with(SPEECH_OPENING)).map(|(_, prompt)| prompt.clone()).collect() +} + +/// A model whose Interpreter answers `answers` in turn, the last one again once they run out. +fn answering(answers: Vec) -> Scripted { + let asked = std::cell::Cell::new(0usize); + Scripted::new(|_| String::new()).interpreting(move |_| { + asked.set(asked.get() + 1); + answers[(asked.get() - 1).min(answers.len() - 1)].clone() + }) +} + +#[test] +fn k31_unwritten_names_no_draft() { + let prose = "I say the first now. Hi Meta. And Kiko, later on."; + let answer = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [] }], "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["failed"].as_str(), decision["retried"]["drafts"].clone()), (Some("the answer leaves drafts unaccounted"), 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]); +} + +#[test] +fn k31_conditional_is_no_kind() { + let prose = "Fine, you win."; + 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["failed"].as_str(), decision["retried"]["drafts"].clone()), (Some("the answer leaves drafts unaccounted"), json!([1])), "{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": "held", "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."; + let good = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [] }], "gaps": [] }).to_string(); + let model = answering(vec!["not the contract".into(), good]); + let decision = decide(&model, "test", &packet(), "The room is warm.", prose, &Tuning::default()); + assert_eq!((texts(&decision), decision["retried"]["failed"].as_str()), (vec!["Hi Meta.".to_owned()], Some("the answer is not the speech contract")), "{decision}"); + let prompts = speech_prompts(&model); + assert!(!prompts[0].contains("An earlier answer to this"), "the first ask carries no fault"); + let fault = prompts[1].strip_prefix(prompts[0].as_str()).unwrap_or_default(); + assert!(fault.starts_with("\n\nAn earlier answer to this was not the speech contract: expected ") && fault.ends_with('.') && fault.len() < 300, "{fault}"); +} + +#[test] +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, "promises": [] })).collect::>(), "gaps": [] }).to_string(); + let model = answering(vec![say(&[]), 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 }); + let counted: u64 = crate::projection::harness::usage_total(std::slice::from_ref(&decision)).values().map(|row| row["calls"]).sum(); + assert_eq!((counted, decision["calls"].as_array().map(Vec::len)), (3, Some(3)), "{decision}"); + // No usage outside `calls`. + fn outside(value: &Value, in_calls: bool) -> usize { + match value { + Value::Object(map) => map.iter().map(|(key, inner)| usize::from(key == "usage" && !in_calls) + outside(inner, in_calls || key == "calls")).sum(), + Value::Array(items) => items.iter().map(|inner| outside(inner, in_calls)).sum(), + _ => 0, + } + } + assert_eq!(outside(&decision, false), 0, "{decision}"); +} diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index b2efc8f..63b3083 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -319,7 +319,7 @@ impl Part { Self::Said { room, text } | Self::Promise { room, text } => format!("{} has, from {obj}: {}.", capitalized(room), quoted(text)), Self::Amended { room, added, .. } => format!("{} has {poss} line, now ending with: {}.", capitalized(room), quoted(added)), Self::NoteLeft(text) => format!("{cap_subj} left Self a note: {}.", quoted(text)), - Self::Refused { reason: Refusal::Echo, room, .. } | Self::Gap { kind: GapKind::Conditional | GapKind::Unwritten | GapKind::Unresolved, room, .. } => format!("Nothing reached {}.", place(room)), + 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, .. } => format!("Nothing of this reached {}:", place(room)), Self::Gap { kind: GapKind::Addressee | GapKind::Elsewhere, .. } => "Nothing reached anyone.".to_owned(), @@ -366,7 +366,6 @@ impl Part { Self::Refused { reason: Refusal::NoRoom, text, .. } => format!(" That turn had no room for {obj} to speak in, so it was not sent: {}.", quoted(text)), Self::Refused { reason: Refusal::NotQuotable, text, .. } => format!(" the line {subj} meant to reply to is not one {subj} can reply to here. {}", shown(&Quote::Wrote(text.clone()))), Self::Refused { text, .. } => format!(" {subj} had already sent {} that turn. {}", lines_word(), shown(&Quote::Wrote(text.clone()))), - Self::Gap { kind: GapKind::Conditional, quote, .. } => after(format!("{cap_subj} wrote this and did not send it, and it is not sent unless {subj} send{s} it"), quote), 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), Self::Gap { kind: GapKind::MissingAffordance, quote, .. } => format!(" {cap_subj} reached for something {subj} {has} no way to do from here, now or later, and it will not happen by itself. {} That {subj} wanted it is kept in {poss} record; no one has taken it up.", shown(quote)), diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index d17a0ec..6f50af5 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -46,16 +46,14 @@ fn a_line_replying_to_no_listed_line_is_told_with_his_draft() { fn each_gap_is_told_by_its_kind_with_a_draft_as_written_and_a_thought_as_thought() { let prose = "If Kiko asks again: Fine, you win. I want to see the shape of that sound. I'll tell Meta I'm fine, more or less."; let gaps = json!([ - { "kind": "conditional", "draft": 1, "quote": null, "detail": "only if asked" }, { "kind": "missing_affordance", "draft": null, "quote": "I want to see the shape of that sound.", "detail": "MODEL-DETAIL he has no spectrogram" }, { "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 }), &[])); + let (lines, omitted) = told(&record(prose, json!({ "say": [], "gaps": gaps, "unsent": [{ "draft": 1, "how": "held", "quote": "If Kiko asks again" }] }), &[])); assert_eq!( lines, [ - "- Nothing reached #minds:gamecult.org. He wrote this and did not send it, and it is not sent unless he sends it: \"Fine, you win.\".", "- 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.\".", ] @@ -178,8 +176,8 @@ 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. 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"), &[]); + 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 (left, _) = told(¬e(json!([{ "kind": "idea", "draft": 1, "about": null, "private": false }]))); 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 }]))); @@ -198,7 +196,7 @@ fn soul_someone_elses_words_in_his_thought_are_shown_as_his_thought_never_as_his #[test] fn soul_a_gap_that_contradicts_what_went_out_is_not_told() { - let (lines, omitted) = told(&record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [{ "kind": "conditional", "draft": 1, "quote": null, "detail": "" }] }), &["Hi Nibu."])); + let (lines, omitted) = told(&record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [{ "kind": "addressee", "draft": 1, "quote": null, "detail": "" }] }), &["Hi Nibu."])); assert_eq!(lines, ["- #minds:gamecult.org has, from him: \"Hi Nibu.\"."]); assert!(omitted.iter().any(|why| why.contains("acted")), "{omitted:?}"); } @@ -208,16 +206,15 @@ fn every_row() -> Vec { let text = "Missed you too. I'll send the render tonight."; let mut broke = record("Hi Nibu.", json!({ "say": [{ "draft": 1 }], "gaps": [] }), &["Hi Nibu."]); broke["broke_after"] = json!("commit"); - let prose = "Then I stop. 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"), &[]); + 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"), &[]); 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": [], "gaps": [ - { "kind": "conditional", "draft": 1, "quote": null, "detail": "" }, + json!({ "say": [], "unsent": [{ "draft": 1, "how": "held", "quote": "If Kiko asks again" }], "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": "" }, @@ -323,7 +320,7 @@ fn a_withheld_quote_claims_nothing_about_where_its_words_came_from() { #[test] fn a_record_that_does_not_say_what_its_turn_heard_withholds_every_quote() { let prose = "Back at the kettle. Fine, you win. I want to see the shape of that sound."; - let gaps = json!([{ "kind": "conditional", "draft": 2, "quote": null, "detail": "" }, { "kind": "missing_affordance", "draft": null, "quote": "I want to see the shape of that sound.", "detail": "" }]); + let gaps = json!([{ "kind": "elsewhere", "draft": 2, "quote": null, "detail": "" }, { "kind": "missing_affordance", "draft": null, "quote": "I want to see the shape of that sound.", "detail": "" }]); let mut record = record(prose, json!({ "say": [{ "draft": 1 }], "gaps": gaps }), &["Back at the kettle."]); let (shown, _) = told(&record); assert!(shown.iter().any(|line| line.contains("\"Back at the kettle.\"")) && shown.iter().any(|line| line.contains("\"Fine, you win.\"")) && shown.iter().any(|line| line.contains("\"I want to see the shape of that sound.\"")), "with `heard`, his words are shown: {shown:?}"); diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index 2ce19e8..fd6c1a3 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -708,17 +708,35 @@ fn promises_markdown(out: &mut String, turn: &Value) { } out.push('\n'); } + // Every field of what the commit applied (map 16.25.7, Low 7): a close is never seen only in a later view. let committed = &turn["committed"]; - let opened = committed["opened"].as_array().cloned().unwrap_or_default(); - let refused = committed["refused"].as_array().cloned().unwrap_or_default(); - if !opened.is_empty() || !refused.is_empty() { + let list = |key: &str| committed[key].as_array().cloned().unwrap_or_default(); + let (opened, closed, reaffirmed, blocked, refused) = (list("opened"), list("closed"), list("reaffirmed"), list("blocked"), list("refused")); + let pruned = committed["pruned"].as_u64().unwrap_or(0); + let id = |entry: &Value| entry["id"].as_str().unwrap_or_default().to_owned(); + if [&opened, &closed, &reaffirmed, &blocked, &refused].iter().any(|items| !items.is_empty()) || pruned > 0 { let _ = writeln!(out, "Committed:\n"); for entry in &opened { - let _ = writeln!(out, "- opened `{}` ({}, to {}): {}", entry["id"].as_str().unwrap_or_default(), entry["status"].as_str().unwrap_or_default(), entry["to"].as_str().unwrap_or("the room"), entry["words"].as_str().unwrap_or_default()); + let _ = writeln!(out, "- opened `{}` ({}, to {}): {}", id(entry), entry["status"].as_str().unwrap_or_default(), entry["to"].as_str().unwrap_or("the room"), entry["words"].as_str().unwrap_or_default()); + } + for done in &closed { + let by = &done["entry"]["closedBy"]; + let words = by["words"].as_str().map_or_else(|| done["by"].as_str().unwrap_or_default().to_owned(), str::to_owned); + let _ = writeln!(out, "- closed {} {} by {}: \"{words}\"", id(&done["entry"]), done["how"].as_str().unwrap_or_default(), by["act"].as_str().unwrap_or_default()); + } + for entry in &reaffirmed { + let again = entry["reaffirmed"].as_array().and_then(|said| said.last()).map_or("", |said| said["words"].as_str().unwrap_or_default()); + let _ = writeln!(out, "- reaffirmed `{}`: \"{again}\"", id(entry)); + } + for entry in &blocked { + let _ = writeln!(out, "- blocked `{}` by read {}: {}", id(entry), entry["blockedBy"]["n"], entry["blockedBy"]["what"].as_str().unwrap_or_default()); } for one in &refused { let _ = writeln!(out, "- refused ({}): `{}`", one["reason"].as_str().unwrap_or_default(), one["proposal"]); } + if pruned > 0 { + let _ = writeln!(out, "- pruned {pruned} closed {}", if pruned == 1 { "entry" } else { "entries" }); + } out.push('\n'); } } diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index e794826..4d85b69 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -779,3 +779,29 @@ fn r5_the_report_shows_the_packets_flags() { flags_markdown(&mut out, &turn); assert_eq!(out, "Packet flags: promises over their guard: yes (all shown); 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, a retry, a kept close, a +/// reaffirmation, a block and a prune renders each, so no commit effect is seen only in a later view. +#[test] +fn k31_report_renders_accounting() { + let decision = json!({ + "said": [], "gaps": [], + "unsent": [{ "draft": 2, "how": "held", "quote": "I hold that one back" }], + "retried": { "failed": "the answer leaves drafts unaccounted", "drafts": [2] } + }); + let mut out = String::new(); + crate::projection::harness::interpreter_markdown(&mut out, &decision); + assert_eq!(out, "**Interpreter: nothing said.**\n\n- unsent draft 2 (held): \"I hold that one back\"\n- retried: the answer leaves drafts unaccounted, drafts 2\n\n"); + let turn = json!({ + "report": { "packet": { "in_view": "" }, "renders": [{ "interpreter": { "state": [] } }] }, + "committed": { + "opened": [], "refused": [], "pruned": 2, + "closed": [{ "entry": { "id": "c-r1-t1-1", "closedBy": { "act": "said", "event": "9", "words": "Thanks, Deru." } }, "how": "kept", "to_name": "Deru", "by": null }], + "reaffirmed": [{ "id": "c-r1-t1-2", "reaffirmed": [{ "at": "2026-11-20T15:00:00Z", "event": "8", "words": "I'll send it tonight" }] }], + "blocked": [{ "id": "c-r1-t1-3", "blockedBy": { "act": "read", "n": 1, "what": "GameCult/Bifrost#89 on the forge" } }] + } + }); + let mut out = String::new(); + promises_markdown(&mut out, &turn); + assert_eq!(out, "Committed:\n\n- closed c-r1-t1-1 kept by said: \"Thanks, Deru.\"\n- reaffirmed `c-r1-t1-2`: \"I'll send it tonight\"\n- blocked `c-r1-t1-3` by read 1: GameCult/Bifrost#89 on the forge\n- pruned 2 closed entries\n\n"); +} diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 2f22527..5fcc104 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -2148,7 +2148,7 @@ fn a_gap_naming_an_echo_refused_draft_quotes_nothing_next_turn() { here: Some("#swarm:gamecult.org".into()), ..Room::default() }; - for kind in ["conditional", "addressee", "elsewhere", "missing_affordance"] { + for kind in ["addressee", "elsewhere", "missing_affordance"] { let decision = interpret::tests::answered(&last, &format!("{words}"), json!({ "say": [{ "draft": 1 }], "gaps": [{ "kind": kind, "draft": 1, "quote": null, "detail": "" }] })); assert_eq!(decision["refused"][0]["reason"], "echo", "{kind}"); let record = json!({ "interpreter": decision, "posted": [] });