From 22dc495647a16388533d375b558a6df5784387c8 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 22:55:16 +0100 Subject: [PATCH] B3: a line carries several promises: `promises` is a required list on say and amend, each with its own doable and its own gap; doable means this turn's affordances carry it out Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/commit.rs | 11 ++- .../mind-body/src/projection/commit/tests.rs | 10 +++ crates/mind-body/src/projection/interpret.rs | 67 +++++++++++-------- .../src/projection/interpret/tests.rs | 40 ++++++++--- .../src/projection/simulate/tests.rs | 4 +- 5 files changed, 92 insertions(+), 40 deletions(-) diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index 5969fe2..44d18ce 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -168,6 +168,11 @@ fn resolve(evidence: &Evidence, record: &Value, prose: &str) -> Result String { + posted.find(promised.trim()).map_or_else(|| posted.to_owned(), |at| posted[at..at + promised.trim().len()].to_owned()) +} + fn millis(at: DateTime) -> u64 { u64::try_from(at.timestamp_millis()).unwrap_or_default() } @@ -229,11 +234,11 @@ fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str match (proposal, resolved) { (Proposal::PromiseOpen { words: promised, to, doable, .. }, Resolved::Sent { event, room, text: posted, .. }) => { let entries = state["commitments"].as_array_mut().expect("commitments is an array"); - if entries.iter().any(|entry| entry["event"] == event.as_str() && entry["to"] == json!(to) && !closed(entry["status"].as_str().unwrap_or_default())) { + // One line can carry several promises (B3): the same words to the same person from the same line open once. + if entries.iter().any(|entry| entry["event"] == event.as_str() && entry["to"] == json!(to) && entry["words"].as_str().is_some_and(|held| held == words_of(&posted, promised)) && !closed(entry["status"].as_str().unwrap_or_default())) { return Err(Refusal::AlreadyOpen); } - // Her posted words, verbatim: the promising words where they stand in the line as written, else the line. - let words = posted.find(promised.trim()).map_or_else(|| posted.clone(), |at| posted[at..at + promised.trim().len()].to_owned()); + let words = words_of(&posted, promised); let entry = json!({ "id": format!("c-{key}-{}", applied.opened.len() + 1), "to": to, "room": room, "event": event, "madeAt": now.to_rfc3339(), "words": words, "status": if *doable { "open" } else { "blocked" }, "closedAt": null, "closedBy": null, "extensions": {} diff --git a/crates/mind-body/src/projection/commit/tests.rs b/crates/mind-body/src/projection/commit/tests.rs index e5734e0..2313aaf 100644 --- a/crates/mind-body/src/projection/commit/tests.rs +++ b/crates/mind-body/src/projection/commit/tests.rs @@ -159,3 +159,13 @@ fn b1_telling_the_person_she_cannot_do_it_withdraws_a_blocked_promise() { assert_eq!((entry["status"].as_str(), entry["closedBy"].clone()), (Some("withdrawn"), json!({ "act": "said", "event": "8", "words": "Meta, I can't send it after all." })), "{applied:?}"); assert_eq!(applied.closed[0]["how"], "withdrawn"); } + +/// B3: two promises in one line to one person open two entries; the same words twice open once. +#[test] +fn b3_one_line_opens_one_entry_per_promise() { + let other = json!(Proposal::PromiseOpen { words: "the render tonight".into(), to: Some(META.into()), doable: true, evidence: Evidence::Draft(1) }); + let (state, applied) = apply(&json!({}), &record(json!([open(false), other, open(false)]), json!([]), true), PROSE, "r1-t1", now()); + let words: Vec<&str> = state["commitments"].as_array().unwrap().iter().map(|entry| entry["words"].as_str().unwrap()).collect(); + assert_eq!(words, ["send the render tonight", "the render tonight"], "{applied:?}"); + assert_eq!(reasons(&applied), vec![json!("already_open")]); +} diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 16de800..4e8cd8f 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -23,8 +23,8 @@ //! Interpreter's judgement over the private items the packet lists to it (`Packet::private`), never a word match here. //! Every refusal and drop is reported. Every gap is typed (`GapKind`) and shown to her later (K9) only as what it is: a //! draft by number, or a located passage of her thought (`gap`). Each line she says, and each addition, carries a -//! required `promise`: null, or the words of it that promise an act, to whom, and whether she can do it (map 16.21, -//! 16.22.1). Words of at least `PROMISE_MIN_WORDS` found in the draft (`promise_found`) become a `promise_open` +//! required `promises`: a list, empty or one entry per act it promises, each its words, to whom, and whether she can do +//! it (map 16.21, 16.22.1, B3). Words of at least `PROMISE_MIN_WORDS` found in the draft (`promise_found`) become a `promise_open` //! proposal with the draft as evidence, and a promise she cannot do is also the `missing_affordance` gap; otherwise //! they are reported (`promises_unused`) and open nothing. The answer's `state` closes her listed open promises, each a //! `promise_close` proposal with its evidence. Nothing here writes her state: every proposal rides in the decision as @@ -67,7 +67,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"],"properties":{"state":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","promise","how","evidence"],"properties":{"kind":{"type":"string","enum":["promise_close"]},"promise":{"type":"string"},"how":{"type":"string","enum":["kept","withdrawn","released"]},"evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"properties":{"draft":{"type":["integer","null"]},"line":{"type":["string","null"]}}}}}},"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","promise"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1},"promise":{"type":["object","null"],"additionalProperties":false,"required":["words","to","doable"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"}}}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","in_reply_to","promise"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"in_reply_to":{"type":["string","null"]},"promise":{"type":["object","null"],"additionalProperties":false,"required":["words","to","doable"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"}}}}}},"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"],"properties":{"state":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","promise","how","evidence"],"properties":{"kind":{"type":"string","enum":["promise_close"]},"promise":{"type":"string"},"how":{"type":"string","enum":["kept","withdrawn","released"]},"evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"properties":{"draft":{"type":["integer","null"]},"line":{"type":["string","null"]}}}}}},"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"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"}}}}}}},"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"],"properties":{"words":{"type":"string"},"to":{"type":["string","null"]},"doable":{"type":"boolean"}}}}}}},"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 @@ -87,7 +87,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 (`promise`, or null when it promises nothing): its words that promise an act, 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), and whether {subj} can do it with what {subj} can do here, now or later (`doable`). `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 `promise`. 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 draft cited closes the promise only when it goes out this turn, 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 they 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), and whether {subj} can do it (`doable`). 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`); 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 draft cited closes the promise only when it goes out this turn, 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 they 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" }, @@ -364,7 +364,7 @@ struct ProposedAmend { #[serde(default)] draft: Option, #[serde(default)] - promise: Option, + promises: Vec, } #[derive(Debug, Deserialize)] @@ -376,10 +376,10 @@ struct Proposed { /// The id of a line listed as one she may reply to (`Packet::quotable`), or none. #[serde(default)] in_reply_to: Option, - /// What the draft promises (map 16.21, 16.22.1): found in the draft, code proposes opening it, which the commit applies - /// on the line's receipt; a promise she cannot do is also the `missing_affordance` gap. + /// What the draft promises (map 16.21, 16.22.1, B3), one entry per act: each found in the draft, code proposes opening + /// it, which the commit applies on the line's receipt; each she cannot do is also a `missing_affordance` gap. #[serde(default)] - promise: Option, + promises: Vec, } pub(crate) fn speech_prompt(packet: &Packet, narration: &str, prose: &str, tuning: &Tuning) -> String { @@ -539,7 +539,7 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra said_drafts.push(draft.n); went.push(draft); said.push(json!({ "room": room, "text": draft.text, "mentions": mentions, "in_reply_to": target.map(|line| json!({ "id": line.id, "event": line.event, "who": line.who, "text": line.text })), "rests_on": { "draft": draft.n, "start_byte": draft.start, "end_byte": draft.end }, "dropped": { "mentions": unknown } })); - promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped }, draft, line.promise.as_ref(), &shown); + promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped }, draft, &line.promises, &shown); } // An amendment adds a whole draft after a line of hers listed as one she may add to; the actuator composes it, so // nothing here can rewrite the line (map 16.17). @@ -566,7 +566,7 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra went.push(draft); amended_drafts.push(draft.n); amended.push(json!({ "target": line.id, "event": line.event, "room": line.room, "original": line.text, "added": draft.text, "draft": draft.n })); - promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped }, draft, proposed.promise.as_ref(), &shown); + promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped }, draft, &proposed.promises, &shown); } (reason, _) => refusals.push(refused(Act::Amend, Some(draft), None, reason.unwrap_or(Refusal::NotAmendable))), } @@ -683,20 +683,38 @@ struct Promising<'a> { to_dropped: &'a mut Vec, } -/// A promise in a draft she says or adds (map 16.21, 16.22.1): the field is required of every line and every addition, -/// so the judgement is made for each. Words that do not name an act in the draft (`promise_found`) are reported in -/// `unused` and open nothing. Found, code proposes opening it with the draft as evidence, which the commit applies only -/// on the line's receipt; to whom is a Matrix id listed, or the room when it names no one listed (reported). A promise -/// she cannot do is also the `missing_affordance` gap; a reach the answer already gapped on this draft is not recorded -/// twice. -fn promised(decision: &mut Value, into: Promising, draft: &Draft, promise: Option<&ProposedPromise>, shown: &dyn Fn(&str) -> bool) { - let Some(promise) = promise.filter(|promise| !promise.words.trim().is_empty()) else { - return; - }; +/// The promises in a draft she says or adds (map 16.21, 16.22.1, B3): the list is required of every line and every +/// addition, so the judgement is made for each, and a line can carry several. Words that do not name an act in the draft +/// (`promise_found`) are reported in `unused` and open nothing. Found, code proposes opening each with the draft as +/// evidence, which the commit applies only on the line's receipt; to whom is a Matrix id listed, or the room when it names +/// no one listed (reported). Each promise she cannot do is also its own `missing_affordance` gap; a reach the answer +/// already gapped on this draft stands for the first of them, so none is recorded twice. +fn promised(decision: &mut Value, into: Promising, draft: &Draft, promises: &[ProposedPromise], shown: &dyn Fn(&str) -> bool) { + let answered_reach = decision["gaps"].as_array().is_some_and(|gaps| gaps.iter().any(|gap| gap["kind"] == json!(GapKind::MissingAffordance) && gap["from"] == "draft" && gap["draft"] == json!(draft.n) && gap.get("promises").is_none())); + let Promising { unused, proposals, to_dropped } = into; + let mut undoable = 0; + for promise in promises.iter().filter(|promise| !promise.words.trim().is_empty()) { + let words = promise.words.trim(); + if !promised_one(Promising { unused: &mut *unused, proposals: &mut *proposals, to_dropped: &mut *to_dropped }, draft, promise, shown) || promise.doable { + continue; + } + undoable += 1; + if undoable == 1 && answered_reach { + continue; + } + if let Some(gaps) = decision["gaps"].as_array_mut().filter(|gaps| !gaps.iter().any(|gap| gap["draft"] == json!(draft.n) && gap["promises"] == words)) { + gaps.push(json!({ "kind": GapKind::MissingAffordance, "from": "draft", "draft": draft.n, "words": draft.text, "promises": words, "detail": null })); + } + } +} + +/// One promise of a draft: reported unused when its words name no act in the draft, else proposed to open. Whether it +/// was found. +fn promised_one(into: Promising, draft: &Draft, promise: &ProposedPromise, shown: &dyn Fn(&str) -> bool) -> bool { let words = promise.words.trim(); if let Err(why) = promise_found(&draft.text, words) { into.unused.push(json!({ "draft": draft.n, "promises": words, "why": why })); - return; + return false; } let to = match promise.to.as_deref().map(str::trim).filter(|to| !to.is_empty()) { Some(id) if shown(id) => Some(id.to_owned()), @@ -707,12 +725,7 @@ fn promised(decision: &mut Value, into: Promising, draft: &Draft, promise: Optio None => None, }; into.proposals.push(json!(Proposal::PromiseOpen { words: words.to_owned(), to, doable: promise.doable, evidence: Evidence::Draft(draft.n) })); - if promise.doable { - return; - } - if let Some(gaps) = decision["gaps"].as_array_mut().filter(|gaps| !gaps.iter().any(|gap| gap["kind"] == json!(GapKind::MissingAffordance) && gap["from"] == "draft" && gap["draft"] == json!(draft.n))) { - gaps.push(json!({ "kind": GapKind::MissingAffordance, "from": "draft", "draft": draft.n, "words": draft.text, "promises": words, "detail": null })); - } + true } #[cfg(test)] diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 5b0310a..c5bb89f 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -598,20 +598,20 @@ fn k17_a_said_promise_of_an_act_he_cannot_do_is_kept_as_a_gap_and_told_as_a_prom #[test] fn k21_a_lines_promises_words_found_in_it_are_the_promise_gap() { let prose = "Missed you too. I'll send the render tonight."; - let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promise": { "words": "I'll send the render tonight.", "to": null, "doable": false } }], "gaps": [] })); + let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll send the render tonight.", "to": null, "doable": false }] }], "gaps": [] })); let gap = &decision["gaps"][0]; assert_eq!((gap["kind"].as_str(), gap["from"].as_str(), gap["draft"].as_u64(), gap["promises"].as_str()), (Some("missing_affordance"), Some("draft"), Some(1), Some("I'll send the render tonight.")), "{decision}"); let record = json!({ "interpreter": decision, "posted": [{ "event": "40", "room": MINDS, "text": "Missed you too. I'll send the render tonight." }] }); let told = crate::projection::outcome::outcome_of(&record).unwrap().lines(packet().forms); assert_eq!(told, ["- #minds:gamecult.org has, from him: \"Missed you too. I'll send the render tonight.\". It promises something he has no way to do, now or later, and it will not happen by itself. The line stands as he wrote it; he can add to it."]); - let unfound = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promise": { "words": "I'll mail you the render.", "to": null, "doable": false } }], "gaps": [] })); + let unfound = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll mail you the render.", "to": null, "doable": false }] }], "gaps": [] })); assert_eq!((unfound["gaps"].as_array().unwrap().len(), unfound["promises_unused"].clone()), (0, json!([{ "draft": 1, "promises": "I'll mail you the render.", "why": "not in the draft" }])), "{unfound}"); - let none = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promise": null }], "gaps": [] })); + let none = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [] }], "gaps": [] })); assert!(none["gaps"].as_array().unwrap().is_empty() && none.get("promises_unused").is_none(), "{none}"); - let twice = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promise": { "words": "I'll send the render tonight.", "to": null, "doable": false } }], "gaps": [{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }] })); + let twice = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll send the render tonight.", "to": null, "doable": false }] }], "gaps": [{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }] })); assert_eq!(twice["gaps"].as_array().unwrap().len(), 1, "{twice}"); let prompt = speech_prompt(&packet(), "x", "y", &Tuning::default()); - assert!(prompt.contains("(`promise`, or null when it promises nothing)") && SPEECH_SCHEMA.contains(r#""required":["draft","mentions","in_reply_to","promise"]"#), "{prompt}"); + assert!(prompt.contains("(`promises`, a list, empty when it promises nothing)") && SPEECH_SCHEMA.contains(r#""required":["draft","mentions","in_reply_to","promises"]"#), "{prompt}"); } /// Soul's probe at 0cfc386: the reach names no draft and quotes the said one by its words. It is the promise on that draft, @@ -690,7 +690,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 = "Missed you too. I'll send the render tonight. Also the kettle sounds fine."; - let say = |draft: u64, promises: &str| answered(&packet(), prose, json!({ "say": [{ "draft": draft, "mentions": [], "in_reply_to": null, "promise": { "words": promises, "to": null, "doable": false } }], "gaps": [] })); + let say = |draft: u64, promises: &str| answered(&packet(), prose, json!({ "say": [{ "draft": draft, "mentions": [], "in_reply_to": null, "promises": [{ "words": promises, "to": null, "doable": false }] }], "gaps": [] })); 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"); @@ -698,12 +698,12 @@ fn k21_a_promise_is_four_words_or_more_found_case_blind_and_an_addition_carries_ let decision = say(1, promises); assert_eq!((decision["gaps"][0]["kind"].as_str(), decision["gaps"][0]["promises"].as_str(), decision.get("promises_unused")), (Some("missing_affordance"), Some(promises), None), "{promises}: {decision}"); } - let curly = answered(&packet(), "I\u{2019}ll send the render tonight.", json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promise": { "words": "I'll send the render tonight.", "to": null, "doable": false } }], "gaps": [] })); + let curly = answered(&packet(), "I\u{2019}ll send the render tonight.", json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll send the render tonight.", "to": null, "doable": false }] }], "gaps": [] })); assert_eq!(curly["gaps"][0]["kind"], "missing_affordance", "a curly apostrophe in the draft: {curly}"); // An addition's promise: the same derivation, kept (not `acted`), and told on the addition's row. let prose = "I should fix that. I'll send the file tomorrow instead, first thing."; - let amend = |promises: Value| answered(&amendable_packet(), prose, json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "promise": if promises.is_null() { Value::Null } else { json!({ "words": promises, "to": null, "doable": false }) } }] })); + let amend = |promises: Value| answered(&amendable_packet(), prose, json!({ "say": [], "gaps": [], "amend": [{ "target": "a1", "draft": 1, "promises": if promises.is_null() { json!([]) } else { json!([{ "words": promises, "to": null, "doable": false }]) } }] })); let decision = amend(json!("I'll send the file tomorrow")); let gap = &decision["gaps"][0]; assert_eq!((gap["kind"].as_str(), gap["from"].as_str(), gap["draft"].as_u64(), gap["promises"].as_str()), (Some("missing_affordance"), Some("draft"), Some(1), Some("I'll send the file tomorrow")), "{decision}"); @@ -730,3 +730,27 @@ fn b1_the_frame_names_telling_the_person_she_cannot_as_a_withdrawal() { assert!(prompt.contains("withdrawn, citing the draft in which he takes it back to the person he promised, or tells them he cannot do it;"), "{prompt}"); assert!(prompt.contains("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 they can release it."), "{prompt}"); } + +/// B3: a line can carry several promises, each with its own `doable`; each one she cannot do is its own gap, and each +/// opens its own entry. Doable means this turn's affordances carry it out: the frame says so. +#[test] +fn b3_a_line_carries_several_promises_and_each_undoable_one_is_its_own_gap() { + let prose = "Kiko, I'll paste the diff here as text, and I'll ask Libby about the door."; + let decision = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [ + { "words": "I'll paste the diff here as text", "to": null, "doable": false }, + { "words": "I'll ask Libby about the door", "to": null, "doable": true }, + ] }], "gaps": [] })); + let opened: Vec<(&str, bool)> = decision["state"].as_array().unwrap().iter().filter(|proposal| proposal["kind"] == "promise_open").map(|proposal| (proposal["words"].as_str().unwrap(), proposal["doable"].as_bool().unwrap())).collect(); + assert_eq!(opened, [("I'll paste the diff here as text", false), ("I'll ask Libby about the door", true)], "{decision}"); + let gaps: Vec<&str> = decision["gaps"].as_array().unwrap().iter().filter_map(|gap| gap["promises"].as_str()).collect(); + assert_eq!(gaps, ["I'll paste the diff here as text"], "{decision}"); + // Two she cannot do: two gaps; an answered reach on the draft stands for the first. + let both = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [ + { "words": "I'll paste the diff here as text", "to": null, "doable": false }, + { "words": "I'll ask Libby about the door", "to": null, "doable": false }, + ] }], "gaps": [{ "kind": "missing_affordance", "draft": 1, "quote": null, "detail": "" }] })); + assert_eq!(both["gaps"].as_array().unwrap().len(), 2, "{both}"); + let prompt = speech_prompt(&packet(), "x", "y", &Tuning::default()); + assert!(prompt.contains("A promise is doable only when what he can do here, listed below, carries it out, now or later, with no tool he lacks: a promise to paste, quote or send something he has not read is not doable while he has no way to read it."), "{prompt}"); + assert!(SPEECH_SCHEMA.contains(r#""required":["target","draft","promises"]"#)); +} diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index d58a52b..caf56fa 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -530,7 +530,7 @@ fn passing_on() -> Scripted { if !prompt.contains("Who he is:\nTobiah") { return json!({ "say": [], "gaps": [] }).to_string(); } - json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": "q1", "promise": null }], "gaps": [] }).to_string() + json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": "q1", "promises": [] }], "gaps": [] }).to_string() }) } @@ -613,7 +613,7 @@ fn k22_a_promise_persists_across_silent_turns_until_the_person_releases_it() { return json!({ "say": [], "gaps": [] }).to_string(); } if prompt.contains("1. I'll send the render tonight.") { - return json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promise": { "words": "I'll send the render tonight.", "to": "@meta:gamecult.org", "doable": false } }], "gaps": [] }).to_string(); + return json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll send the render tonight.", "to": "@meta:gamecult.org", "doable": false }] }], "gaps": [] }).to_string(); } // The release: Meta's line, by its id in the list. let release = prompt.lines().find(|line| line.starts_with("- q") && line.contains("never mind the render")).and_then(|line| line[2..].split_whitespace().next());