diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 4844e97..96c8ff4 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -18,7 +18,9 @@ //! the turn's room. Whether a draft tells what she knows privately is a reading of its meaning, so it is the //! 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`). The prompt tells the Interpreter what she can do this +//! draft by number, or a located passage of her thought (`gap`). Each line she says carries a required `promises`: the +//! words of it that promise an act she cannot do, or null; found in the draft, code records them as the +//! `missing_affordance` gap (map 16.21), and not found, they are reported and record none. The prompt tells the Interpreter what she can do this //! turn (`select::turn_words`), so a reach past it is a `missing_affordance` gap. Nothing here posts: the commit (C3c) //! will. //! @@ -53,7 +55,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"],"properties":{"suggest":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","about","private"],"properties":{"kind":{"type":"string","enum":["feedback","idea"]},"draft":{"type":"integer","minimum":1},"about":{"type":["string","null"]},"private":{"type":"boolean"}}}},"amend":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["target","draft"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","reply_to"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"reply_to":{"type":["string","null"]}}}},"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"],"properties":{"suggest":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["kind","draft","about","private"],"properties":{"kind":{"type":"string","enum":["feedback","idea"]},"draft":{"type":"integer","minimum":1},"about":{"type":["string","null"]},"private":{"type":"boolean"}}}},"amend":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["target","draft"],"properties":{"target":{"type":"string"},"draft":{"type":"integer","minimum":1}}}},"say":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["draft","mentions","reply_to","promises"],"properties":{"draft":{"type":"integer","minimum":1},"mentions":{"type":"array","items":{"type":"string"}},"reply_to":{"type":["string","null"]},"promises":{"type":["string","null"]}}}},"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 @@ -73,7 +75,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`) and the Matrix id of the person whose message {subj} answer{s} (`reply_to`, or null). `gaps` records what {subj} meant and did not send. `amend` adds to one of {poss} own lines listed below, at most one a turn, only when {poss} thought shows {obj} choosing to correct or add to that line: name the line by its id, and the draft that is {poss} addition. The line stays as it was and the draft is added after it; {subj} never take{s} a word back. `suggest` leaves Self one note, at most one a turn, only when {poss} thought shows {obj} choosing to: name the draft that is the note, its kind (feedback when {subj} pass{es} on what someone listed said, with that person's Matrix id in `about`; idea when it is {poss} own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. +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 Matrix id of the person whose message {subj} answer{s} (`reply_to`, or null), and the words of the draft that promise an act {subj} {has} no way to do, now or later, copied exactly (`promises`, or null when it promises none). `gaps` records what {subj} meant and did not send. `amend` adds to one of {poss} own lines listed below, at most one a turn, only when {poss} thought shows {obj} choosing to correct or add to that line: name the line by its id, and the draft that is {poss} addition. The line stays as it was and the draft is added after it; {subj} never take{s} a word back. `suggest` leaves Self one note, at most one a turn, only when {poss} thought shows {obj} choosing to: name the draft that is the note, its kind (feedback when {subj} pass{es} on what someone listed said, with that person's Matrix id in `about`; idea when it is {poss} own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. A draft is said whole or not at all, and only once. At most two drafts a turn. Record a gap instead of guessing: 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 and wrote no draft of it. Every intent of {poss} that is not carried out has a kind: an intent to act is missing_affordance, an intent to say 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" }, @@ -338,6 +340,10 @@ struct Proposed { mentions: Vec, #[serde(default)] reply_to: Option, + /// The words of the draft that promise an act she has no way to do (map 16.21): code derives the `missing_affordance` + /// gap from them when they are found in the draft. + #[serde(default)] + promises: Option, } pub(crate) fn speech_prompt(packet: &Packet, narration: &str, prose: &str, tuning: &Tuning) -> String { @@ -432,6 +438,7 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra let mut used: Vec = Vec::new(); let mut went: Vec<&Draft> = Vec::new(); let mut said_drafts: Vec = Vec::new(); + let mut unfound: Vec = Vec::new(); for line in parsed.say { let Some(draft) = line.draft.and_then(|n| found.numbered(n)) else { refusals.push(refused(Act::Say, None, line.draft, Refusal::NoDraft)); @@ -464,6 +471,16 @@ 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, "reply_to": reply_to, "rests_on": { "draft": draft.n, "start_byte": draft.start, "end_byte": draft.end }, "dropped": { "mentions": unknown, "reply_to": unknown_reply } })); + // A promise in a line she says is a gap code derives (map 16.21): the field is required of every line, so the + // judgement is made for each. Words not found in the draft are reported and record no gap; a reach the answer + // already gapped on this draft is not recorded twice. + if let Some(promise) = line.promises.as_deref().map(str::trim).filter(|promise| !promise.is_empty()) { + if !draft.text.contains(promise) { + unfound.push(json!({ "draft": draft.n, "promises": promise })); + } else 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": promise, "detail": null })); + } + } } // 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). @@ -540,6 +557,9 @@ pub(crate) fn decide(model: &dyn Model, request_id: &str, packet: &Packet, narra decision["room_kind"] = json!(packet.room_kind); decision["said"] = json!(said); decision["refused"] = json!(refusals); + if !unfound.is_empty() { + decision["promises_not_found"] = json!(unfound); + } decision } diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 3efc458..3552f13 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -550,6 +550,28 @@ fn k17_a_said_promise_of_an_act_he_cannot_do_is_kept_as_a_gap_and_told_as_a_prom assert_eq!(told, ["- #minds:gamecult.org has, from him: \"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."]); } +/// Map 16.21: each line's required `promises` is where the promise is judged. Found in the draft, code records the +/// missing_affordance gap and she is told the promise; not found, it is reported and records no gap; a reach the answer +/// already gapped is not recorded twice. +#[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": [], "reply_to": null, "promises": "I'll send the render tonight." }], "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": [], "reply_to": null, "promises": "I'll mail you the render." }], "gaps": [] })); + assert_eq!((unfound["gaps"].as_array().unwrap().len(), unfound["promises_not_found"].clone()), (0, json!([{ "draft": 1, "promises": "I'll mail you the render." }])), "{unfound}"); + let none = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "reply_to": null, "promises": null }], "gaps": [] })); + assert!(none["gaps"].as_array().unwrap().is_empty() && none.get("promises_not_found").is_none(), "{none}"); + let twice = answered(&packet(), prose, json!({ "say": [{ "draft": 1, "mentions": [], "reply_to": null, "promises": "I'll send the render tonight." }], "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("(`promises`, or null when it promises none)") && SPEECH_SCHEMA.contains(r#""required":["draft","mentions","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, /// not `acted`. #[test]