From edcaf956e0c524cb755293495b780bd182a7f6a1 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 21 Nov 2026 19:50:49 +0100 Subject: [PATCH] Persona speech contract: every draft of hers is sent, held, superseded or gapped Soul's R10 item 1 (F.2 r5: Heimdall drafted to Meta after "Meta first, short.", the Interpreter sent only his draft to Kiko and recorded nothing for the other, and Meta got silence). The answer gains `unsent`: a draft neither sent (say, amend, suggest) nor gapped is held, by her own choice, quoting her thought, or superseded, quoting the later words that replace it. An answer that leaves a draft unaccounted is a contract failure: it is asked again once, as an answer off the contract now is too, and the first attempt rides in the decision (`retried`) with its usage. The frame: a draft to someone who spoke to her this turn is held only when her prose says so. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/interpret.rs | 83 +++++++++++++++++-- .../src/projection/interpret/tests.rs | 27 ++++++ 2 files changed, 102 insertions(+), 8 deletions(-) diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 4f13494..a9b27e1 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"],"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"}}},"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","doable","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"},"reaffirms":{"type":["string","null"]},"needs":{"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","doable","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"},"reaffirms":{"type":["string","null"]},"needs":{"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","doable","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"},"reaffirms":{"type":["string","null"]},"needs":{"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","doable","reaffirms","needs"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"},"reaffirms":{"type":["string","null"]},"needs":{"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"}}}}}}"#; /// The speech frame before the guidance: what to decide, from what, and the attribution rule. Code, not tuning (map /// 16.7), in her own pronouns (16.19.7). The tuning's `interpreter.guidance` (what counts as her choosing to send it @@ -91,7 +91,7 @@ fn speech_frame_tail(her: Forms) -> String { format!( "{cap_subj} speak{s} only in this room. What {subj} know{s} privately is listed below as private: {subj} say{s} none of it here, and nothing that gives it away. A private matter may be said plainly only to the person it concerns, in a direct message with exactly that person; nothing listed is that here. Whether a draft fits who is listening is yours to judge. -Answer with the speech contract's object. `say` lists the drafts {subj} send{s} now, each by its number, with the Matrix ids of anyone listed whom {subj} address{es} directly (`mentions`), the id of the line listed below that {subj} answer{s} or pass{es} on (`in_reply_to`, or null: the room shows that line, with who said it, above {poss} own words), and what the draft promises (`promises`, a list, empty when it promises nothing): for each act it promises, 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), whether {subj} can do it (`doable`), and, 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`): a read's target, when {subj} must read something to keep it, or `words_only` when {poss} words alone keep it; words only means {subj} can write it from what {subj} already {has} in view, so a promise to write up what {subj} {has} not got in front of {obj} is not words only. A promise is doable only when what {subj} can do here, listed below, carries it out, now or later, with no tool {subj} lack{s}: a promise to paste, quote or send something {subj} {has} not read is not doable while {subj} {has} no way to read it. `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, 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`) or the read by which {subj} did it this moment (`evidence.read`, its number); 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. A release also quotes in `thought` the words of {poss} prose here that take it up, copied exactly, and `still_stands` is true when that prose holds the promise as still standing (\"the promise stays open until I've read it\"): then it is not released. For kept and withdrawn, `thought` is null and `still_stands` false. 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. +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 (`promises`, a list, empty when it promises nothing): for each act it promises, 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), whether {subj} can do it (`doable`), and, 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`): a read's target, when {subj} must read something to keep it, or `words_only` when {poss} words alone keep it; words only means {subj} can write it from what {subj} already {has} in view, so a promise to write up what {subj} {has} not got in front of {obj} is not words only. A promise is doable only when what {subj} can do here, listed below, carries it out, now or later, with no tool {subj} lack{s}: a promise to paste, quote or send something {subj} {has} not read is not doable while {subj} {has} no way to read 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`) or the read by which {subj} did it this moment (`evidence.read`, its number); 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. A release also quotes in `thought` the words of {poss} prose here that take it up, copied exactly, and `still_stands` is true when that prose holds the promise as still standing (\"the promise stays open until I've read it\"): then it is not released. For kept and withdrawn, `thought` is null and `still_stands` false. 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.", es = if s.is_empty() { "" } else { "es" }, @@ -337,8 +337,53 @@ struct Answer { /// contract is reported and the rest of the answer stands. #[serde(default)] read: Option, + /// The drafts not sent and not gapped, each held 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. + Held, + /// 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 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 { + 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)))); + 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 + && 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(), + }; + if stands { + accounted.insert(draft.n); + } + } + 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 @@ -542,12 +587,28 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra pub(crate) fn decide_in(model: &dyn Model, request_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(); - let answer = match model.ask(request_id, &tuning.interpreter.model, &speech_prompt_in(packet, narration, segment, tuning, wake.before, &found, &wake.earlier.and_then(|earlier| earlier["read_refused"].as_array()).cloned().unwrap_or_default()), Some(SPEECH_SCHEMA)) { - Ok(answer) => answer, - Err(failed) => return json!({ "failed": failed.reason, "usage": failed.usage }), - }; - let Ok(parsed) = serde_json::from_str::(&answer.text) else { - return json!({ "failed": "the answer is not the speech contract", "raw": answer.text, "usage": answer.usage }); + 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. + let mut retried: Option = None; + let (answer, parsed) = loop { + let answer = match model.ask(request_id, &tuning.interpreter.model, &prompt, Some(SPEECH_SCHEMA)) { + Ok(answer) => answer, + Err(failed) => return json!({ "failed": failed.reason, "usage": failed.usage, "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 }), + }; + if retried.is_some() { + let mut fault = fault; + fault["retried"] = retried.take().unwrap_or_default(); + return fault; + } + retried = Some(fault); }; 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(); @@ -559,6 +620,12 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na // proposal's evidence against them (`commit::apply`), as the trace holds them live. let lines: Vec = packet.quotable.iter().map(|line| json!({ "id": line.id, "event": line.event, "room": line.room, "who": line.who, "sender": line.sender, "at_ms": line.at_ms })).collect(); let mut decision = json!({ "said": [], "refused": [], "gaps": gaps, "heard": bodies, "lines": lines, "promises": packet.promises, "usage": answer.usage, "read": null, "at_ms": packet.now_ms }); + if let Some(retried) = retried { + decision["retried"] = retried; + } + if !parsed.unsent.is_empty() { + decision["unsent"] = json!(parsed.unsent); + } if let Some(reads) = wake.earlier.map(|earlier| earlier["reads"].clone()).filter(Value::is_array) { decision["reads"] = reads; } diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index c3dd4c1..810a0ec 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -1105,3 +1105,30 @@ fn r10_one_link_heard_in_a_quoted_line_is_one_link() { let read = asked(&aqua, prose, json!({ "kind": "web", "target": "https://ccrma.stanford.edu/~jos/pasp/", "quote": "I'll open it before I say more" })); 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, is asked again once, and fails if again it accounts for nothing. 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, "promises": [] }], "gaps": [] }); + let both = json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [] }, { "draft": 2, "mentions": [], "in_reply_to": null, "promises": [] }], "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["failed"].as_str(), never["retried"]["drafts"].clone()), (Some("the answer leaves drafts unaccounted"), json!([1])), "{never}"); + let held = answered(&packet(), "I'll keep this one back for now. Meta, sorry.", json!({ "say": [], "gaps": [], "unsent": [{ "draft": 1, "how": "held", "quote": "keep this one back for now" }] })); + 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" }] })); + assert!(superseded.get("failed").is_none(), "{superseded}"); +}