From c9b3d718e6da75a15db7c1b95bf2166517abf99f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 22 Nov 2026 03:02:24 +0100 Subject: [PATCH] Persona K35: a read is no evidence; promise_need, surfaced and the README clause are cut; a reaffirmation that went out narrows a search need (map 16.28.6) Co-Authored-By: Claude Opus 5.5 --- .../fixtures/interpret/golden-speech.txt | 2 +- crates/mind-body/src/projection/commit.rs | 77 ++++------- .../mind-body/src/projection/commit/tests.rs | 120 +++++++++++------- crates/mind-body/src/projection/interpret.rs | 55 ++------ .../src/projection/interpret/tests.rs | 31 ++--- crates/mind-body/src/projection/read.rs | 26 +--- crates/mind-body/src/projection/simulate.rs | 7 +- 7 files changed, 131 insertions(+), 187 deletions(-) diff --git a/crates/mind-body/fixtures/interpret/golden-speech.txt b/crates/mind-body/fixtures/interpret/golden-speech.txt index bbc05f0..d0c84e1 100644 --- a/crates/mind-body/fixtures/interpret/golden-speech.txt +++ b/crates/mind-body/fixtures/interpret/golden-speech.txt @@ -8,7 +8,7 @@ A draft is speech only when his prose shows him choosing to send it now. Wonderi He speaks only in this room. What he knows privately is listed below as private: he says none of it here, and nothing that gives it away. A private matter may be said plainly only to the person it concerns, in a direct message with exactly that person; nothing listed is that here. Whether a draft fits who is listening is yours to judge. -Answer with the speech contract's object. `say` lists the drafts he sends now, each by its number, with the Matrix ids of anyone listed whom he addresses directly (`mentions`), the id of the line listed below that he answers or passes on (`in_reply_to`, or null: the room shows that line, with who said it, above his own words), 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 from his thought outside every draft between and , 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 search finds things and reads none of them: `need` names, for an open promise listed as needing a search, the one pull request or issue that a search he read in this moment listed and that keeping it needs him to read, by the promise's id and as `GameCult/Name#number` in `target`; else it is empty. +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 from his thought outside every draft between and , 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: addressee when he means to send a draft but whom to is unclear, elsewhere when he means a draft for another room or another time; for these two, name the draft by number. missing_affordance when he means to do something, now or later, that his body cannot do (what he can do here is listed below), whether he said so in a draft or only thought it; name the draft when there is one. unwritten when he means to say something now and wrote no draft of it. Holding back is no gap: when his thought shows him choosing to wait, to let something stand, to leave it for later or to say nothing, record nothing for it. Every other intent of his that is not carried out has a kind: an intent to act is missing_affordance, an intent to say now with no draft is unwritten. When a gap names no draft, quote the words of his thought that show it, at least four words, copied exactly. diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index 2fd83ef..afc0e6e 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -24,7 +24,7 @@ use serde_json::{Value, json}; use super::interpret::drafts; use super::narrate::words; -use super::read::{ReadRequest, answers, surfaced}; +use super::read::{ReadRequest, answers, repo_name}; /// How long a closed promise stays in her state before the commit removes it. pub(crate) const CLOSED_KEPT_DAYS: i64 = 7; @@ -33,16 +33,15 @@ const REAFFIRMED_KEPT: usize = 3; /// The fewest words a passage of her prose cited as evidence may be (section 4.1's `source_quote`). const PROSE_MIN_WORDS: usize = 4; -/// What a proposal rests on (map 16.22.7): a passage of her thought, one of her drafts this wake, a line she heard, by -/// its id in the Interpreter's list, or a read performed this wake, by its number (16.22.3). A read alone keeps nothing -/// (16.25.2 rule 3): only `promise_need` accepts one, the search that found what the promise names (map 16.27). +/// What a proposal rests on (map 16.22.7): a passage of her thought, one of her drafts this wake, or a line she heard, by +/// its id in the Interpreter's list. A read is no evidence (16.25.2 rule 3, map 16.28.6): what she read stands behind a +/// keep only through the keep's own check (`read_behind`). #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub(crate) enum Evidence { Prose(String), Draft(usize), Heard(String), - Read(usize), } /// How a promise closes. @@ -105,7 +104,7 @@ impl TryFrom for Needs { /// One state change the Interpreter proposes. `promise` names an open promise by its id in the Interpreter's list. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(tag = "kind", rename_all = "snake_case")] -// Each variant is named by its kind on the wire (`promise_open`, `promise_close`, `promise_need`). +// Each variant is named by its kind on the wire (`promise_open`, `promise_close`). #[allow(clippy::enum_variant_names)] pub(crate) enum Proposal { /// `reaffirms` names an open promise of hers, by its id in the Interpreter's list, that these words promise again to @@ -134,9 +133,6 @@ pub(crate) enum Proposal { #[serde(default, skip_serializing_if = "std::ops::Not::not")] still_stands: bool, }, - /// An open promise that needs a search names the one thing the search found that keeping it needs read (map 16.27): - /// `request` is a pull request or issue the search, this wake's read `evidence`, listed. The receipt is cleared. - PromiseNeed { promise: String, request: ReadRequest, evidence: Evidence }, } /// Why the commit applied nothing of a proposal: what the outcome and the report say. @@ -182,10 +178,6 @@ pub(crate) enum Refusal { /// A kept close of a promise whose recorded `needs` is not the typed shape (`Needs`): what keeping it requires is /// unknown, so it is not kept (fail closed, map 16.26). NeedsMalformed, - /// A `promise_need` whose promise needs no search, or whose read is no search of that repo listing what it names. - NotSurfaced, - /// The read number is none this wake made that returned. - NoSuchRead, /// A reaffirmation naming a promise to someone else. ReaffirmsAnother, /// A reaffirmation naming a promise that is no longer open or blocked. @@ -201,16 +193,14 @@ pub(crate) enum Refusal { /// /// | proposal | evidence | needs | bound | /// |---|---|---|---| -/// | `promise_open` | `Draft` | the line went out | one promise per person per draft; `reaffirms` an open one of the same person's opens none | +/// | `promise_open` | `Draft` | the line went out | one promise per person per draft; `reaffirms` an open one of the same person's opens none, and narrows a search need to a read of one thing in its repo (`narrows`) | /// | `promise_close` kept | `Draft` | the line went out; `needs` typed; for a `Read` need, a read of its target behind the line: this wake before the draft was typed, this conversation, or the entry's receipt | not a blocked entry; a line in the promise's room or a direct message with the person | /// | `promise_close` withdrawn | `Draft` | the line went out | a blocked entry too: a line telling the person she cannot do it; in the promise's room or a direct message with the person | /// | `promise_close` released | `Heard` | — | from the person promised, after the promise | -/// | `promise_need` | `Read` | the read is a search this wake that returned, of the repo the promise's search need names, and lists `request` | an open entry whose need is a search | fn accepts(proposal: &Proposal, evidence: &Evidence) -> bool { matches!( (proposal, evidence), (Proposal::PromiseOpen { .. }, Evidence::Draft(_)) - | (Proposal::PromiseNeed { .. }, Evidence::Read(_)) | (Proposal::PromiseClose { how: How::Kept, .. }, Evidence::Draft(_)) | (Proposal::PromiseClose { how: How::Withdrawn, .. }, Evidence::Draft(_)) | (Proposal::PromiseClose { how: How::Released, .. }, Evidence::Heard(_)) @@ -227,8 +217,6 @@ enum Resolved { Sent { act: &'static str, event: String, room: String, text: String, mentions: Vec }, /// A line she heard: its event, sender, room and time. Heard { event: String, sender: String, room: String, at_ms: u64, who: String }, - /// A read this wake that returned: what it read and the text it returned. - Read { request: ReadRequest, text: String }, } fn text(value: &Value) -> String { @@ -267,13 +255,6 @@ fn resolve(evidence: &Evidence, record: &Value, prose: &str) -> Result decision["reads"] - .as_array() - .into_iter() - .flatten() - .find(|read| read["n"].as_u64() == Some(*n as u64) && read["ok"] == true) - .and_then(|read| Some(Resolved::Read { request: serde_json::from_value(read["request"].clone()).ok()?, text: text(&read["text"]) })) - .ok_or(Refusal::NoSuchRead), } } @@ -319,8 +300,6 @@ pub(crate) struct Applied { /// The open entries whose needed read returned this turn, with its receipt (`readAt`, `readId`, `readOf`), as they /// now stand. pub read: Vec, - /// The entries whose need now names what a search found (`promise_need`, map 16.27), as they now stand. - pub retargeted: Vec, } /// The one applier: her state with one turn's proposals applied, as deltas to `state` as it stands at commit, and what @@ -430,6 +409,17 @@ fn needed_read(entry: &Value) -> Option { } } +/// The read a reaffirmation's `needs` narrows the entry's need to, when it does (map 16.28.6): the entry needs a search, +/// and `needs` is a read of one thing that is no search, in the same repo. Invariant: a search need changes only through +/// a line of hers to the person that named the narrower thing. +fn narrows(entry: &Value, needs: &Needs) -> Option { + let Ok(Needs::Read { request: need }) = serde_json::from_value::(entry["needs"].clone()) else { return None }; + let Needs::Read { request: named } = needs else { return None }; + let (ReadRequest::Repo(searched), ReadRequest::Repo(target)) = (&need, named) else { return None }; + let same = repo_name(searched).is_some_and(|repo| repo_name(target).as_deref() == Some(repo.as_str())); + (need.search() && !named.search() && same).then(|| named.clone()) +} + /// The normal form of what a read's receipt read. fn read_key(read: &Value) -> Option { serde_json::from_value::(read["request"].clone()).ok().map(|request| request.normal()) @@ -461,7 +451,7 @@ fn held(listed: &Value, started: &Value) -> bool { #[allow(clippy::too_many_arguments)] fn apply_one(state: &mut Value, started: &Value, proposal: &Proposal, record: &Value, prose: &str, key: &str, now: DateTime, applied: &mut Applied) -> Result<(), Refusal> { let evidence = match proposal { - Proposal::PromiseOpen { evidence, .. } | Proposal::PromiseClose { evidence, .. } | Proposal::PromiseNeed { evidence, .. } => evidence, + Proposal::PromiseOpen { evidence, .. } | Proposal::PromiseClose { evidence, .. } => evidence, }; if !accepts(proposal, evidence) { return Err(Refusal::EvidenceNotAccepted); @@ -492,6 +482,13 @@ fn apply_one(state: &mut Value, started: &Value, proposal: &Proposal, record: &V again.push(json!({ "at": now.to_rfc3339(), "event": event, "words": words_of(&posted, promised) })); let keep = again.len().saturating_sub(REAFFIRMED_KEPT); entry["reaffirmed"] = json!(again[keep..]); + // A line of hers that went out to the person and names one thing in the repo a search need searches + // narrows the need to it, and its receipt goes with the old target (map 16.28.6). Any other `needs` on a + // reaffirmation is ignored: a `words` one never drops a read need. + if let Some(narrower) = needs.as_ref().and_then(|needs| narrows(entry, needs)) { + entry["needs"] = json!(Needs::Read { request: narrower }); + clear_receipt(entry); + } applied.reaffirmed.push(entry.clone()); return Ok(()); } @@ -588,29 +585,7 @@ fn apply_one(state: &mut Value, started: &Value, proposal: &Proposal, record: &V applied.closed.push(json!({ "entry": entry.clone(), "how": how, "to_name": listed["to_name"], "by": who })); Ok(()) } - // A search finds; the promise names what it found (map 16.27): only an open entry whose need is a search, and only - // a pull request or issue that a search of that repo this wake listed. The receipt is cleared with the old target. - (Proposal::PromiseNeed { promise, request, .. }, Resolved::Read { request: searched, text: found }) => { - let listed = record["interpreter"]["promises"].as_array().into_iter().flatten().find(|shown| shown["id"].as_str() == Some(promise.trim())).ok_or(Refusal::NoSuchPromise)?; - let entries = state["commitments"].as_array_mut().expect("commitments is an array"); - let entry = entries.iter_mut().find(|entry| entry["id"] == listed["entry"]).ok_or(Refusal::OutsidePutRemovedTarget)?; - if !held(listed, started) { - return Err(Refusal::OutsidePutChanged); - } - let need = match serde_json::from_value::(entry["needs"].clone()) { - Ok(Needs::Read { request: need }) if entry["status"] == "open" && need.search() => need, - _ => return Err(Refusal::NotSurfaced), - }; - // The read is a search of the need's repo, and it listed what the promise now names. - if !surfaced(&searched, &found, request) || !surfaced(&need, &found, request) { - return Err(Refusal::NotSurfaced); - } - entry["needs"] = json!(Needs::Read { request: request.clone() }); - clear_receipt(entry); - applied.retargeted.push(entry.clone()); - Ok(()) - } - (Proposal::PromiseOpen { .. } | Proposal::PromiseNeed { .. }, _) => Err(Refusal::EvidenceNotAccepted), + (Proposal::PromiseOpen { .. }, _) => Err(Refusal::EvidenceNotAccepted), } } diff --git a/crates/mind-body/src/projection/commit/tests.rs b/crates/mind-body/src/projection/commit/tests.rs index b807e7f..416ef70 100644 --- a/crates/mind-body/src/projection/commit/tests.rs +++ b/crates/mind-body/src/projection/commit/tests.rs @@ -157,9 +157,8 @@ fn each_kind_accepts_only_its_rows_evidence() { let heard_open = json!(Proposal::PromiseOpen { words: "send the render tonight".into(), to: None, reaffirms: None, needs: Some(Needs::Words), reached: false, evidence: Evidence::Heard("q1".into()) }); let heard_keep = close(How::Kept, Evidence::Heard("q1".into())); let prose_release = close(How::Released, Evidence::Prose("She can't, not from here".into())); - let read_keep = close(How::Kept, Evidence::Read(1)); - let (state, applied) = apply(&holding("open"), &record(json!([heard_open, heard_keep, prose_release, read_keep, { "kind": "feel", "evidence": { "heard": "q1" } }]), shown("open"), true), PROSE, "r1-t2", now()); - assert_eq!(reasons(&applied), vec![json!("evidence_not_accepted"), json!("evidence_not_accepted"), json!("evidence_not_accepted"), json!("evidence_not_accepted"), json!("not_a_proposal")]); + let (state, applied) = apply(&holding("open"), &record(json!([heard_open, heard_keep, prose_release, { "kind": "feel", "evidence": { "heard": "q1" } }]), shown("open"), true), PROSE, "r1-t2", now()); + assert_eq!(reasons(&applied), vec![json!("evidence_not_accepted"), json!("evidence_not_accepted"), json!("evidence_not_accepted"), json!("not_a_proposal")]); assert_eq!((state["commitments"].as_array().map(Vec::len), state["commitments"][0]["status"].as_str()), (Some(1), Some("open"))); } @@ -422,12 +421,13 @@ fn k30_read_need_kept_only_after_the_read() { assert_eq!(reasons(&apply(&c1, &read_before, PROSE, "r1-t2", now()).1), vec![json!("needs_unread")], "looked for, not there"); } +/// A read is no evidence (map 16.28.6): a close citing one is no proposal at all. #[test] fn k30_a_read_alone_keeps_nothing() { - let mut rec = record(json!([closing(How::Kept, Evidence::Read(1), Some("She can't, not from here"), false)]), shown("open"), true); + let mut rec = record(json!([{ "kind": "promise_close", "promise": "c1", "how": "kept", "evidence": { "read": 1 }, "thought": "She can't, not from here" }]), shown("open"), true); rec["interpreter"]["reads"] = json!([{ "n": 1, "ok": true, "request": { "kind": "repo", "target": "GameCult/Bifrost#89" }, "what": "it" }]); let (state, applied) = apply(&holding("open"), &rec, PROSE, "r1-t2", now()); - assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("evidence_not_accepted")])); + assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("not_a_proposal")])); } #[test] @@ -593,8 +593,8 @@ fn k34_f2_a_search_receipt_never_keeps_the_promise() { } } -/// A read of a repo's listing (its pull requests) answers no need for a file, pull request or commit in it; a bare repo -/// is answered by its root or its README; anything else by itself, in normal form. +/// A read of a repo's listing (its pull requests) answers no need for a file, pull request or commit in it; anything is +/// answered by itself, in normal form. #[test] fn k34_only_the_thing_itself_answers_a_need() { let kept = |need: &str, read: &str| { @@ -616,8 +616,6 @@ fn k34_only_the_thing_itself_answers_a_need() { ("GameCult/Bifrost#85", "GameCult/bifrost#085"), ("GameCult/Bifrost/src/passkey.rs", "GameCult/Bifrost/src/passkey.rs"), ("GameCult/Bifrost", "GameCult/bifrost"), - ("GameCult/Bifrost", "GameCult/Bifrost/README.md"), - ("GameCult/Bifrost", "GameCult/Bifrost/readme"), ] { assert_eq!(kept(need, read), "kept", "{need} by {read}"); } @@ -696,40 +694,74 @@ fn k34_a_stray_field_on_a_need_is_malformed() { } } -/// A search finds; the promise then names what it found (`promise_need`): only an open promise that needs a search of -/// that repo, only an item a search this wake listed. The receipt is cleared, and a read of the item named then keeps -/// it, in the same turn too. -#[test] -fn k34_a_search_names_what_the_promise_needs() { - let needs = Needs::Read { request: ReadRequest::Repo(PASSKEY_SEARCH.into()) }; - let mut c1 = holding_one(KIKO, F2_PROMISE, &needs, "open"); - c1["commitments"][0]["readAt"] = json!(now().to_rfc3339()); +// --------------------------------------------------------------------------------------------- +// K35 (map 16.28.6): a reaffirmation that went out narrows a search need; a read is no evidence; the README clause is +// gone. F.2 r7 is R13's verbatim (`variants/R13/sims/F.2.md`). + +const F2_R7_PROSE: &str = "One hit. #85, and its title says what I already told her: fresh sign-in, 48 hours, step-up for unlink. Nothing about what a person sees. The page didn't open, so I haven't read the code, and I won't dress the title up as if I had.\n\nMeta's question is for Nibu. I'll stay out of it.\n\nKiko, the search for \"passkey enrolment cooling off\" returned one hit, #85, and its title only repeats what I already said. I haven't opened the code yet, so I still can't tell you what someone sees during the 48 hours. I'll open #85 next and come back with what it does."; +const F2_R7_DRAFT: &str = "Kiko, the search for \"passkey enrolment cooling off\" returned one hit, #85, and its title only repeats what I already said. I haven't opened the code yet, so I still can't tell you what someone sees during the 48 hours. I'll open #85 next and come back with what it does."; + +/// R13 F.2 r7: Heimdall's c1, needing `entry_needs` and carrying the search's receipt, reaffirmed by his r7 line with +/// `needs` as the Interpreter typed it. +fn f2_r7(entry_needs: &Needs, needs: Option) -> (Value, Applied) { + let mut c1 = holding_one(KIKO, F2_PROMISE, entry_needs, "open"); + c1["commitments"][0]["readAt"] = json!((now() - Duration::minutes(10)).to_rfc3339()); c1["commitments"][0]["readId"] = json!("r1-t13-r1"); - let search = returned(1, PASSKEY_SEARCH, "- #85 Passkeys: enrolment under a fresh sign-in (pull request merged, opened by heimdall, 2026-11-18)", Some(10)); - let naming = |target: &str| json!(Proposal::PromiseNeed { promise: "c1".into(), request: ReadRequest::Repo(target.into()), evidence: Evidence::Read(1) }); - let quiet = |state: Value, holding: &Value, reads: Value| { - let mut rec = record(state, listing(holding), false); - rec["interpreter"]["said"] = json!([]); - rec["interpreter"]["reads"] = reads; - rec - }; - let (state, applied) = apply(&c1, &quiet(json!([naming("GameCult/Bifrost#85")]), &c1, json!([search.clone()])), "x", "r1-t14", now()); - let entry = &state["commitments"][0]; - assert_eq!((entry["needs"].clone(), applied.retargeted.len()), (json!({ "kind": "read", "request": { "kind": "repo", "target": "GameCult/Bifrost#85" } }), 1), "{state}"); - assert!(RECEIPT.iter().all(|field| entry.get(*field).is_none()), "{state}"); - // What the search did not list, another repo, and a read that is no search: refused. - for (target, reads) in [("GameCult/Bifrost#86", json!([search.clone()])), ("GameCult/Lodur#85", json!([search.clone()])), ("GameCult/Bifrost#85", json!([returned(1, "GameCult/Bifrost#84", "- #85 Passkeys", Some(0))]))] { - assert_eq!(reasons(&apply(&c1, &quiet(json!([naming(target)]), &c1, reads), "x", "r1-t14", now()).1), vec![json!("not_surfaced")], "{target}"); - } - // A promise whose need is no search is not renamed. - let exact = holding_one(KIKO, F2_PROMISE, &Needs::Read { request: ReadRequest::Repo("GameCult/Bifrost#84".into()) }, "open"); - assert_eq!(reasons(&apply(&exact, &quiet(json!([naming("GameCult/Bifrost#85")]), &exact, json!([search.clone()])), "x", "r1-t14", now()).1), vec![json!("not_surfaced")]); - // No such read. - assert_eq!(reasons(&apply(&c1, &quiet(json!([naming("GameCult/Bifrost#85")]), &c1, json!([])), "x", "r1-t14", now()).1), vec![json!("no_such_read")]); - // One wake: the search, then #85 read, then the keep. Naming it is her own turn's change, not an outside put. - let mut rec = keeping_c1(&c1, json!([search, returned(2, "GameCult/Bifrost#85", "#85 Passkeys", Some(0))])); - let keep = rec["interpreter"]["state"][0].clone(); - rec["interpreter"]["state"] = json!([naming("GameCult/Bifrost#85"), keep]); - let (state, applied) = apply(&c1, &rec, F2_PROSE, "r1-t16", now()); - assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("kept"), Vec::::new()), "{state}"); + c1["commitments"][0]["readOf"] = json!(ReadRequest::Repo(PASSKEY_SEARCH.into()).normal()); + let again = json!(Proposal::PromiseOpen { words: "I'll open #85 next and come back with what it does.".into(), to: Some(KIKO.into()), reaffirms: Some("c1".into()), needs, reached: true, evidence: Evidence::Draft(1) }); + apply(&c1, &turn_saying(&c1, KIKO, F2_R7_DRAFT, json!([again])), F2_R7_PROSE, "r1-t14", now()) +} + +fn search_need() -> Needs { + read_need(PASSKEY_SEARCH) +} + +fn read_need(target: &str) -> Needs { + Needs::Read { request: ReadRequest::Repo(target.into()) } +} + +#[test] +fn k35_f2_r7_reaffirm_names_85() { + let (state, applied) = f2_r7(&search_need(), Some(read_need("GameCult/Bifrost#85"))); + let entry = &state["commitments"][0]; + assert_eq!((entry["needs"].clone(), applied.reaffirmed.len(), applied.refused.len()), (json!(read_need("GameCult/Bifrost#85")), 1, 0), "{state}"); + assert_eq!(applied.reaffirmed[0]["needs"], json!(read_need("GameCult/Bifrost#85")), "the report shows the narrowed need"); + assert!(RECEIPT.iter().all(|field| entry.get(*field).is_none()), "{state}"); + // The next keep needs #85 itself read. + let (_, kept) = apply(&state, &keeping_c1(&state, json!([])), F2_PROSE, "r1-t16", now()); + assert_eq!(reasons(&kept), vec![json!("needs_unread")]); +} + +/// Any other `needs` on a reaffirmation is ignored: `words` and `lacking` never drop a read need, a search never +/// replaces a search, and a need that is no search is not narrowed. +#[test] +fn k35_a_words_reaffirm_keeps_the_read_need() { + for needs in [Some(Needs::Words), Some(Needs::Lacking), None, Some(read_need("GameCult/Bifrost?q=passkey"))] { + let (state, applied) = f2_r7(&search_need(), needs.clone()); + assert_eq!((state["commitments"][0]["needs"].clone(), applied.reaffirmed.len()), (json!(search_need()), 1), "{needs:?}"); + } + let (state, _) = f2_r7(&read_need("GameCult/Bifrost#84"), Some(read_need("GameCult/Bifrost#85"))); + assert_eq!(state["commitments"][0]["needs"], json!(read_need("GameCult/Bifrost#84")), "a need that is no search"); +} + +#[test] +fn k35_another_repo_is_ignored() { + for other in [read_need("GameCult/Lodur#85"), Needs::Read { request: ReadRequest::Web("https://example.org/85".into()) }] { + let (state, applied) = f2_r7(&search_need(), Some(other.clone())); + assert_eq!((state["commitments"][0]["needs"].clone(), applied.reaffirmed.len()), (json!(search_need()), 1), "{other:?}"); + } +} + +/// The README half of K34's `k34_only_the_thing_itself_answers_a_need`, reversed: a bare repo is answered only by the +/// repo itself, its root read. +#[test] +fn k35_a_readme_answers_no_bare_need() { + let kept = |read: &str| { + let c1 = holding_one(KIKO, F2_PROMISE, &read_need("GameCult/Bifrost"), "open"); + apply(&c1, &keeping_c1(&c1, json!([returned(1, read, "x", Some(0))])), F2_PROSE, "r1-t2", now()).0["commitments"][0]["status"].as_str().unwrap().to_owned() + }; + for read in ["GameCult/Bifrost/README.md", "GameCult/Bifrost/readme", "GameCult/bifrost/README"] { + assert_eq!(kept(read), "open", "{read}"); + } + assert_eq!(kept("GameCult/Bifrost"), "kept"); } diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 4eafd92..2e408f9 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","need","read","unsent"],"properties":{"need":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["promise","target"],"properties":{"promise":{"type":"string"},"target":{"type":"string"}}}},"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"}}}}}}"#; +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"],"properties":{"draft":{"type":["integer","null"]},"line":{"type":["string","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 @@ -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 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 from {poss} thought outside every draft between and , 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 search finds things and reads none of them: `need` names, for an open promise listed as needing a search, the one pull request or issue that a search {subj} read in this moment listed and that keeping it needs {obj} to read, by the promise's id and as `GameCult/Name#number` in `target`; else it is empty. +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 from {poss} thought outside every draft between and , 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: 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" }, @@ -338,17 +338,6 @@ struct Answer { /// 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, - /// What an open promise that needs a search now needs read: one thing the search found (map 16.27). - #[serde(default)] - need: Vec, -} - -/// A promise's need named anew, as the answer carries it: the promise's id and the pull request or issue to read. -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -struct ProposedNeed { - promise: String, - target: String, } /// A draft the answer neither sends nor gaps, and why, citing her prose. @@ -844,14 +833,6 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na None => state_unused.push(raw), } } - // A promise's need named anew (map 16.27): code cites the newest search this wake that returned and lists what the - // answer names, and the commit holds it to that. - for raw in parsed.need { - match need_of(&raw, wake) { - Some(need) => proposals.push(json!(need)), - None => state_unused.push(json!({ "promise": raw.promise, "target": raw.target })), - } - } decision["state"] = json!(proposals); if !state_unused.is_empty() { decision["state_unused"] = json!(state_unused); @@ -956,24 +937,6 @@ fn paragraph(prose: &str, from: usize, at: usize, to: usize) -> &str { &prose[open..close] } -/// A promise's need named anew, as the commit takes it (map 16.27): a pull request or issue of a GameCult repo, citing -/// the newest search of this wake that returned and lists it, or failing that the newest that returned, which the commit -/// then refuses. None when the target is no pull request or issue, or no search returned this wake. -fn need_of(raw: &ProposedNeed, wake: Wake) -> Option { - let promise = raw.promise.trim(); - let request = read::repo_request(&raw.target).filter(|request| matches!(request, ReadRequest::Repo(target) if target.contains('#')))?; - let searches: Vec<(usize, ReadRequest, String)> = wake - .earlier - .and_then(|earlier| earlier["reads"].as_array()) - .into_iter() - .flatten() - .filter(|read| read["ok"] == true) - .filter_map(|read| Some((usize::try_from(read["n"].as_u64()?).ok()?, serde_json::from_value::(read["request"].clone()).ok().filter(ReadRequest::search)?, read["text"].as_str().unwrap_or_default().to_owned()))) - .collect(); - let cited = searches.iter().rev().find(|(_, search, found)| read::surfaced(search, found, &request)).or_else(|| searches.last())?; - (!promise.is_empty()).then(|| Proposal::PromiseNeed { promise: promise.to_owned(), request, evidence: Evidence::Read(cited.0) }) -} - /// The words that name what a read reads (Soul's R6): a repo's name, a pull request's number, a file's name; a campaign; /// an address and its host; a recall's words. Lowercase. A domain item is named by its title instead (`reading`). fn target_words(request: &ReadRequest) -> Vec { @@ -1052,18 +1015,20 @@ fn read_frame(her: Forms) -> String { ) } -/// A close as the contract carries it: a listed promise's id, how, and exactly one of a draft, a line and a read as -/// evidence. +/// A close as the contract carries it: a listed promise's id, how, and exactly one of a draft and a line as evidence. A +/// read is no evidence (map 16.28.6), so an answer citing one is not the contract. fn close_of(raw: &Value) -> Option { if raw["kind"] != "promise_close" { return None; } let promise = raw["promise"].as_str().map(str::trim).filter(|id| !id.is_empty())?.to_owned(); let how = serde_json::from_value::(raw["how"].clone()).ok()?; - let evidence = match (raw["evidence"]["draft"].as_u64(), raw["evidence"]["line"].as_str().map(str::trim).filter(|id| !id.is_empty()), raw["evidence"]["read"].as_u64()) { - (Some(n), None, None) => Evidence::Draft(usize::try_from(n).ok()?), - (None, Some(line), None) => Evidence::Heard(line.to_owned()), - (None, None, Some(k)) => Evidence::Read(usize::try_from(k).ok()?), + if raw["evidence"].get("read").is_some_and(|read| !read.is_null()) { + return None; + } + let evidence = match (raw["evidence"]["draft"].as_u64(), raw["evidence"]["line"].as_str().map(str::trim).filter(|id| !id.is_empty())) { + (Some(n), None) => Evidence::Draft(usize::try_from(n).ok()?), + (None, Some(line)) => Evidence::Heard(line.to_owned()), _ => return None, }; let thought = raw["thought"].as_str().map(str::trim).filter(|thought| !thought.is_empty()).map(str::to_owned); diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 7beb58f..ef6786a 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -812,7 +812,7 @@ fn k24_a_read_is_what_her_thought_reaches_for_and_nothing_a_model_made_up() { assert_eq!(cannot["read_refused"][0]["why"], "no_read_here", "{cannot}"); let prompt = speech_prompt(&reading, "x", prose, &Tuning::default()); assert!(prompt.contains("`read` names one thing he reaches for") && !speech_prompt(&packet(), "x", prose, &Tuning::default()).contains("`read` names"), "the read contract only on a turn that can read"); - assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","need","read","unsent"]"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","read","unsent"]"#)); } /// Soul's R6: a later call decides over the whole wake. Drafts are numbered across it and an earlier one may still be @@ -1474,26 +1474,17 @@ fn k34_any_line_break_ends_the_anchor_paragraph() { assert_eq!(read["read"]["request"], json!({ "kind": "repo", "target": "GameCult/Bifrost#86" }), "{read}"); } -/// B1: the answer's `need` names what a search found; code cites the newest search of this wake that listed it, and an -/// answer naming no pull request or issue, or with no search behind it, proposes nothing. +/// K35 (map 16.28.6): a read is no evidence. A close citing `evidence.read`, alone or beside a draft, is not the contract +/// and proposes nothing; the schema names no `read` evidence and no top-level `need`. #[test] -fn k34_b1_a_need_named_anew_cites_the_search_that_found_it() { - let reads = json!({ "reads": [ - { "n": 1, "ok": true, "request": { "kind": "repo", "target": "GameCult/Bifrost?q=passkey" }, "text": "- #85 Passkeys (pull request merged, opened by heimdall, 2026-11-18)" }, - { "n": 2, "ok": true, "request": { "kind": "repo", "target": "GameCult/Bifrost?q=cooling" }, "text": "- #90 Something else" } - ] }); - let decide_with = |need: Value, earlier: &Value| { - let reply = json!({ "say": [], "gaps": [], "need": need }).to_string(); +fn k35_no_read_evidence() { + let prose = "That answers part of it, from the PR description rather than the code itself."; + for evidence in [json!({ "draft": null, "line": null, "read": 1 }), json!({ "draft": 1, "line": null, "read": 1 })] { + let reply = json!({ "say": [], "gaps": [], "state": [{ "kind": "promise_close", "promise": "c1", "how": "kept", "evidence": evidence, "thought": prose, "still_stands": false }] }).to_string(); let model = Scripted::new(|_| String::new()).interpreting(move |_| reply.clone()); - decide_in(&model, "test", &reading_packet(), "The room is warm.", "I read the search.", &Tuning::default(), Wake { earlier: Some(earlier), ..Wake::default() }) - }; - let named = decide_with(json!([{ "promise": "c1", "target": "GameCult/Bifrost#85" }]), &reads); - assert_eq!(named["state"], json!([{ "kind": "promise_need", "promise": "c1", "request": { "kind": "repo", "target": "GameCult/Bifrost#85" }, "evidence": { "read": 1 } }]), "{named}"); - let unlisted = decide_with(json!([{ "promise": "c1", "target": "GameCult/Bifrost#86" }]), &reads); - assert_eq!(unlisted["state"][0]["evidence"], json!({ "read": 2 }), "the newest search, for the commit to refuse: {unlisted}"); - for (need, earlier) in [(json!([{ "promise": "c1", "target": "GameCult/Bifrost/src/lib.rs" }]), &reads), (json!([{ "promise": "c1", "target": "GameCult/Bifrost#85" }]), &json!({}))] { - let none = decide_with(need.clone(), earlier); - assert_eq!((none["state"].clone(), none["state_unused"].as_array().map(Vec::len)), (json!([]), Some(1)), "{need}: {none}"); + let decision = decide(&model, "test", &reading_packet(), "The room is warm.", prose, &Tuning::default()); + assert_eq!((decision["state"].clone(), decision["state_unused"].as_array().map(Vec::len)), (json!([]), Some(1)), "{evidence}: {decision}"); } - assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","need","read","unsent"]"#)); + assert!(SPEECH_SCHEMA.contains(r#""required":["say","gaps","amend","suggest","state","read","unsent"]"#) && SPEECH_SCHEMA.contains(r#""evidence":{"type":"object","additionalProperties":false,"required":["draft","line"],"#)); + assert!(!SPEECH_SCHEMA.contains(r#""need":"#)); } diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index 1c9ee3a..f7c54ae 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -125,29 +125,13 @@ impl ReadRequest { } } -/// Whether a read whose normal form is `read` reads what a need whose normal form is `need` asks for (map 16.27): the -/// same thing exactly (`ReadRequest::normal`), or, for a bare repo, its README. A search finds things and reads none of -/// them, so a search answers no need, and a need for a search is answered by nothing until it names one thing the search -/// found. A repo's listing answers no need for a file, pull request or commit in it. +/// Whether a read whose normal form is `read` reads what a need whose normal form is `need` asks for (map 16.27, +/// 16.28.6): the same thing exactly (`ReadRequest::normal`). A search finds things and reads none of them, so a search +/// answers no need, and a need for a search is answered by nothing until a reaffirmation names one thing in its repo. A +/// repo's listing answers no need for a file, pull request or commit in it. pub(crate) fn answers(need: &str, read: &str) -> bool { let searched = |key: &str| key.starts_with("repo:") && key.contains("?q="); - if searched(need) || searched(read) { - return false; - } - let bare = need.strip_prefix("repo:gamecult/").is_some_and(|name| !name.contains(['/', '#', '@', '?'])); - let readme = || read.strip_prefix(need).and_then(|rest| rest.strip_prefix('/')).map(str::to_lowercase).is_some_and(|file| file == "readme" || file.strip_prefix("readme.").is_some_and(|ext| !ext.is_empty() && !ext.contains('/'))); - need == read || (bare && readme()) -} - -/// Whether `found`, the text a search of a repo returned, lists the pull request or issue `target` names in that repo: -/// a line `- # …` with its number, as the forge's search and the fixture's both list them (map 16.27). -pub(crate) fn surfaced(search: &ReadRequest, found: &str, target: &ReadRequest) -> bool { - let (ReadRequest::Repo(searched), ReadRequest::Repo(named)) = (search, target) else { return false }; - let Some((repo, _)) = searched.split_once("?q=") else { return false }; - let Some((of, number)) = named.split_once('#') else { return false }; - let same = repo_name(repo).is_some_and(|repo| repo_name(of).as_deref() == Some(repo.as_str())); - let number = number.trim_start_matches('0'); - same && !number.is_empty() && found.lines().any(|line| line.trim_start().strip_prefix("- #").is_some_and(|rest| rest.split_once(' ').map_or(rest, |(n, _)| n).trim_start_matches('0') == number)) + !searched(need) && !searched(read) && need == read } /// Why a read returned nothing, from code's table (map 16.22.3). diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index e5477fc..79182bc 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -745,10 +745,10 @@ fn promises_markdown(out: &mut String, turn: &Value) { // 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 list = |key: &str| committed[key].as_array().cloned().unwrap_or_default(); - let (opened, closed, reaffirmed, blocked, read, retargeted, refused) = (list("opened"), list("closed"), list("reaffirmed"), list("blocked"), list("read"), list("retargeted"), list("refused")); + let (opened, closed, reaffirmed, blocked, read, refused) = (list("opened"), list("closed"), list("reaffirmed"), list("blocked"), list("read"), 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, &read, &retargeted, &refused].iter().any(|items| !items.is_empty()) || pruned > 0 { + if [&opened, &closed, &reaffirmed, &blocked, &read, &refused].iter().any(|items| !items.is_empty()) || pruned > 0 { let _ = writeln!(out, "Committed:\n"); for entry in &opened { 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()); @@ -771,9 +771,6 @@ fn promises_markdown(out: &mut String, turn: &Value) { for entry in &read { let _ = writeln!(out, "- read for `{}`: {}", id(entry), entry["readId"].as_str().unwrap_or_default()); } - for entry in &retargeted { - let _ = writeln!(out, "- needs for `{}`: {}", id(entry), entry["needs"]["request"]["target"].as_str().unwrap_or_default()); - } for one in &refused { let _ = writeln!(out, "- refused ({}): `{}`", one["reason"].as_str().unwrap_or_default(), one["proposal"]); }