From b19e612d2f61e3aba971d0c22dd3094db0d19f19 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 22 Nov 2026 00:02:48 +0100 Subject: [PATCH] Persona K33: fail closed on untyped needs, receive reads on the promise, tell refused closes and held drafts (map 16.26) B3: a kept close of an entry whose needs is not the typed Needs (or absent) is refused NeedsMalformed. L2: a read of an open promise's target that returns, on any turn, records readAt/readId on the entry, and a keep accepts that receipt. L3: this wake's read stands behind a keep only for a draft typed after the read returned (after_byte on the read). L1: thought is defined as quoted outside her drafts; CloseUnquoted, NeedsUnread and NeedsMalformed are told to her as her record still showing the promise, and why. L4: a held draft is told to her as not sent. L5: an unreached read whose target is no repo or address opens as lacking. L7: a release renders by whom. B2: the simulator holds every in-run commit to P1-P3 and fails the run. Her view shows what an open promise needs read and whether she read it. Co-Authored-By: Claude Opus 5.5 --- .../fixtures/interpret/golden-speech.txt | 2 +- crates/mind-body/src/projection.rs | 4 + crates/mind-body/src/projection/commit.rs | 63 +++++++++--- .../mind-body/src/projection/commit/tests.rs | 95 ++++++++++++++++++- crates/mind-body/src/projection/interpret.rs | 32 +++++-- .../src/projection/interpret/tests.rs | 16 ++++ crates/mind-body/src/projection/outcome.rs | 55 +++++++++-- .../mind-body/src/projection/outcome/tests.rs | 32 +++++++ crates/mind-body/src/projection/read.rs | 14 ++- crates/mind-body/src/projection/select.rs | 10 +- crates/mind-body/src/projection/simulate.rs | 24 ++++- .../src/projection/simulate/tests.rs | 38 ++++++++ crates/mind-body/src/projection/tests.rs | 2 +- 13 files changed, 347 insertions(+), 40 deletions(-) diff --git a/crates/mind-body/fixtures/interpret/golden-speech.txt b/crates/mind-body/fixtures/interpret/golden-speech.txt index c290474..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, 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. +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.rs b/crates/mind-body/src/projection.rs index b4fb699..edf002c 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -487,6 +487,10 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni before = format!("{before}{}\n\n{bridge}\n\n", &prose[from..]); prose = format!("{prose}\n\n{segment}"); from = prose.len() - segment.len(); + // Where her thought after the read begins: a draft before it was typed without the read (map 16.26). + if let Some(done) = reads.last_mut() { + done["after_byte"] = json!(from); + } decision["reads"] = json!(reads); let wake = interpret::Wake { earlier: Some(&decision), from, read: &read_texts, before: &before }; let next = interpret::decide_in(model, &request_id(instance, "interpreter", &format!("{tag}{}", reads.len()), packet.seed), packet, &narration, &prose, tuning, wake); diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index 35aef23..db5ce01 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -138,8 +138,12 @@ pub(crate) enum Refusal { CloseUnquoted, /// A close her own prose contradicts: it holds the promise as still owed (Soul's R9, map 16.25.2). CloseContradicted, - /// A kept close of a promise that needs a read, with no read of its target that returned in this conversation. + /// A kept close of a promise that needs a read, with no read of its target behind the line: none returned before the + /// draft was typed this wake, none in this conversation, and no receipt on the entry (map 16.26). NeedsUnread, + /// 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 reaffirmation naming a promise to someone else. ReaffirmsAnother, /// A reaffirmation naming a promise that is no longer open or blocked. @@ -156,7 +160,7 @@ 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_close` kept | `Draft` | the line went out; for a `Read` need, a read of its target returned in this conversation | not a blocked entry; a line in the promise's room or a direct message with the person | +/// | `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 | fn accepts(proposal: &Proposal, evidence: &Evidence) -> bool { @@ -261,6 +265,8 @@ pub(crate) struct Applied { pub reaffirmed: Vec, /// The entries a failed read blocked (`promise_block`, map 16.24.3), as they now stand. pub blocked: Vec, + /// The open entries whose needed read returned this turn, with its receipt (`readAt`, `readId`), as they now stand. + pub read: Vec, } /// The one applier: her state with one turn's proposals applied, as deltas to `state` as it stands at commit, and what @@ -295,9 +301,26 @@ pub(crate) fn apply(state: &Value, record: &Value, prose: &str, key: &str, now: } } block_on_failed_reads(&mut state, record, &mut applied); + receive_reads(&mut state, record, key, now, &mut applied); (state, applied) } +/// The receipt of a read on the promise that needs it (map 16.26): when a read of an open promise's target returns, in +/// any room and at any time, the entry records when (`readAt`) and which read (`readId`, `-r`). A kept close +/// later accepts it, so a read made in another room or after the conversation's window still stands behind the keep. +fn receive_reads(state: &mut Value, record: &Value, key: &str, now: DateTime, applied: &mut Applied) { + let returned: Vec<&Value> = record["interpreter"]["reads"].as_array().into_iter().flatten().filter(|read| read["ok"] == true).collect(); + for entry in state.get_mut("commitments").and_then(Value::as_array_mut).into_iter().flatten().filter(|entry| entry["status"] == "open") { + let Some(needed) = needed_read(entry) else { continue }; + let Some(read) = returned.iter().find(|read| read_key(read).as_deref() == Some(needed.as_str())) else { + continue; + }; + entry["readAt"] = json!(now.to_rfc3339()); + entry["readId"] = json!(format!("{key}-r{}", read["n"])); + applied.read.push(entry.clone()); + } +} + /// `promise_block` (map 16.24.3), a row of the applier with its evidence a read's receipt: an open promise that needs a /// read becomes `blocked` when this turn read that target, of any kind, and found nothing. It cites the read. A read that /// succeeded leaves the promise open: telling the person is the kept act. @@ -329,12 +352,20 @@ fn read_key(read: &Value) -> Option { serde_json::from_value::(read["request"].clone()).ok().map(|request| request.normal()) } -/// Whether a read of `key` returned in this conversation: one of this wake's reads that came back, or one of the -/// conversation's receipts that found it (`conversation_reads`, from her `already_read`, K26). -fn read_returned(record: &Value, key: &str) -> bool { +/// Whether a read of `key` stands behind a keep citing `draft` (map 16.25.2, 16.26): the entry's own receipt of a read +/// that returned on an earlier turn (`readAt`), one of the conversation's reads that found it (`conversation_reads`, from +/// her `already_read`, K26), or one of this wake's that came back before she typed the draft: her thought after a read +/// begins at its `after_byte`, and a draft typed before that was written without it. +fn read_behind(entry: &Value, key: &str, record: &Value, prose: &str, draft: &Evidence) -> bool { let decision = &record["interpreter"]; - decision["reads"].as_array().into_iter().flatten().any(|read| read["ok"] == true && read_key(read).as_deref() == Some(key)) - || decision["conversation_reads"].as_array().into_iter().flatten().any(|read| read["found"] == true && read["key"].as_str() == Some(key)) + if entry["readAt"].is_string() || decision["conversation_reads"].as_array().into_iter().flatten().any(|read| read["found"] == true && read["key"].as_str() == Some(key)) { + return true; + } + let Evidence::Draft(n) = draft else { return false }; + let Some(typed_at) = drafts(prose).drafts.iter().find(|found| found.n == *n).map(|found| found.start) else { + return false; + }; + decision["reads"].as_array().into_iter().flatten().any(|read| read["ok"] == true && read_key(read).as_deref() == Some(key) && read["after_byte"].as_u64().and_then(|at| usize::try_from(at).ok()).is_some_and(|at| at <= typed_at)) } fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str, key: &str, now: DateTime, applied: &mut Applied) -> Result<(), Refusal> { @@ -397,7 +428,7 @@ fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str applied.opened.push(entry); Ok(()) } - (Proposal::PromiseClose { promise, how, thought, still_stands, .. }, resolved) => { + (Proposal::PromiseClose { promise, how, thought, still_stands, evidence }, resolved) => { 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)?; @@ -420,10 +451,20 @@ fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str if *still_stands { return Err(Refusal::CloseContradicted); } + // A keep rests on what keeping it needs (map 16.25.2, 16.26): not a blocked entry; a typed `needs`, since a + // `needs` that does not parse as `Needs`, or none at all, says nothing of what a keep requires; and for a + // read, a read of its target behind the line. + if *how == How::Kept { + if status == "blocked" { + return Err(Refusal::BlockedNotKeepable); + } + match serde_json::from_value::(entry["needs"].clone()) { + Err(_) => return Err(Refusal::NeedsMalformed), + Ok(Needs::Read { request }) if !read_behind(entry, &request.normal(), record, prose, evidence) => return Err(Refusal::NeedsUnread), + Ok(_) => {} + } + } let (act, event, words, who) = match (how, resolved) { - (How::Kept, _) if status == "blocked" => return Err(Refusal::BlockedNotKeepable), - // A promise that needs a read is kept only with a read of its target behind the line (map 16.25.2). - (How::Kept, _) if needed_read(entry).is_some_and(|key| !read_returned(record, &key)) => return Err(Refusal::NeedsUnread), (How::Kept | How::Withdrawn, Resolved::Sent { act, event, text, room, mentions }) => { if !reaches(entry, &room, &mentions, record) { return Err(Refusal::NotWherePromised); diff --git a/crates/mind-body/src/projection/commit/tests.rs b/crates/mind-body/src/projection/commit/tests.rs index 570c7e6..6d659eb 100644 --- a/crates/mind-body/src/projection/commit/tests.rs +++ b/crates/mind-body/src/projection/commit/tests.rs @@ -52,7 +52,7 @@ fn close(how: How, evidence: Evidence) -> Value { /// Her state holding one entry, as the commit opened it. fn holding(status: &str) -> Value { - json!({ "commitments": [{ "id": "c-r1-t1-1", "to": META, "room": MINDS, "event": "7", "madeAt": now().to_rfc3339(), "words": "send the render tonight", "status": status, "closedAt": null, "closedBy": null, "extensions": {} }] }) + json!({ "commitments": [{ "id": "c-r1-t1-1", "to": META, "room": MINDS, "event": "7", "madeAt": now().to_rfc3339(), "words": "send the render tonight", "status": status, "needs": { "kind": "words" }, "closedAt": null, "closedBy": null, "extensions": {} }] }) } /// The Interpreter's list as a packet shows the entry `holding(status)` holds: with the whole entry as the turn began. @@ -410,7 +410,7 @@ fn k30_read_need_kept_only_after_the_read() { let (state, applied) = apply(&c1, &turn(), PROSE, "r1-t2", now()); assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("needs_unread")])); let mut read_now = turn(); - read_now["interpreter"]["reads"] = json!([{ "n": 1, "ok": true, "request": { "kind": "repo", "target": "GameCult/Bifrost#089" }, "what": "GameCult/Bifrost#089 on the forge" }]); + read_now["interpreter"]["reads"] = json!([{ "n": 1, "ok": true, "request": { "kind": "repo", "target": "GameCult/Bifrost#089" }, "what": "GameCult/Bifrost#089 on the forge", "after_byte": 0 }]); assert_eq!(apply(&c1, &read_now, PROSE, "r1-t2", now()).0["commitments"][0]["status"], "kept"); let mut failed_now = turn(); failed_now["interpreter"]["reads"] = json!([{ "n": 1, "ok": false, "failure": "failed", "request": { "kind": "repo", "target": "GameCult/Bifrost#89" }, "what": "it" }]); @@ -454,3 +454,94 @@ fn k30_block_on_failed_read_any_kind() { let unreached = Some(Needs::Read { request: ReadRequest::Web("https://x.org/".into()) }); assert_eq!(apply(&json!({}), &record(json!([open_needing(META, unreached, false)]), json!([]), true), PROSE, "r1-t1", now()).0["commitments"][0]["status"], "blocked"); } + +// --------------------------------------------------------------------------------------------- +// K33 (map 16.26): Soul's R12 blockers and lows in the applier. + +/// B3, Soul's probe 1: a `needs` that is not the typed shape is never kept, whatever line went out: a bare string, a read +/// with no request, a request given as a string, and none at all. She can still withdraw it. +#[test] +fn k33_b3_an_untyped_needs_is_never_kept() { + let kept = || closing(How::Kept, Evidence::Draft(1), Some("She can't, not from here"), false); + for needs in [json!("GameCult/Bifrost#89"), json!({ "kind": "read" }), json!({ "kind": "read", "request": "GameCult/Bifrost#89" }), Value::Null] { + let mut c1 = holding("open"); + c1["commitments"][0]["needs"] = needs.clone(); + let (state, applied) = apply(&c1, &record(json!([kept()]), listing(&c1), true), PROSE, "r1-t2", now()); + assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("needs_malformed")]), "{needs}"); + let withdrawn = closing(How::Withdrawn, Evidence::Draft(1), Some("She can't, not from here"), false); + assert_eq!(apply(&c1, &record(json!([withdrawn]), listing(&c1), true), PROSE, "r1-t2", now()).0["commitments"][0]["status"], "withdrawn", "{needs}"); + } +} + +/// L2: a read of an open promise's target that returns, on any turn, is received on the entry; a later keep rests on it +/// with no read that turn and none in the conversation's window. +#[test] +fn k33_l2_a_read_is_received_on_the_promise_that_needs_it() { + let needs = Needs::Read { request: ReadRequest::Repo("GameCult/Bifrost#89".into()) }; + let c1 = holding_one(META, "send the render tonight", &needs, "open"); + let mut elsewhere = record(json!([]), listing(&c1), false); + elsewhere["interpreter"]["said"] = json!([]); + elsewhere["interpreter"]["reads"] = json!([{ "n": 2, "ok": true, "request": { "kind": "repo", "target": "GameCult/bifrost#089" }, "what": "it", "after_byte": 0 }]); + let (read, applied) = apply(&c1, &elsewhere, "She reads it in another room.", "r2-t3", now()); + let entry = &read["commitments"][0]; + assert_eq!((entry["status"].as_str(), entry["readAt"].as_str(), entry["readId"].as_str(), applied.read.len()), (Some("open"), Some(now().to_rfc3339().as_str()), Some("r2-t3-r2"), 1), "{read}"); + // A read of something else is no receipt. + let mut other = elsewhere.clone(); + other["interpreter"]["reads"][0]["request"]["target"] = json!("GameCult/Bifrost#90"); + assert!(apply(&c1, &other, "x", "r2-t3", now()).0["commitments"][0].get("readAt").is_none()); + let keep = turn_saying(&read, META, "I'll send the render tonight.", json!([closing(How::Kept, Evidence::Draft(1), Some("She can't, not from here"), false)])); + assert_eq!(apply(&read, &keep, PROSE, "r3-t1", now()).0["commitments"][0]["status"], "kept"); +} + +/// L3: this wake's read stands behind a keep only when the cited draft was typed after the read returned. +#[test] +fn k33_l3_a_draft_typed_before_the_read_keeps_nothing() { + let needs = Needs::Read { request: ReadRequest::Repo("GameCult/Bifrost#89".into()) }; + let c1 = holding_one(META, "send the render tonight", &needs, "open"); + let before = "She hasn't read it yet. Meta, it looks fine."; + let prose = format!("{before}\n\nShe has read it now, and it holds. Meta, I read #89 and it's fine."); + let keep = |n: usize, text: &str| { + let mut rec = turn_saying(&c1, META, text, json!([closing(How::Kept, Evidence::Draft(n), Some("She has read it now, and it holds"), false)])); + rec["interpreter"]["said"][0]["rests_on"]["draft"] = json!(n); + rec["interpreter"]["reads"] = json!([{ "n": 1, "ok": true, "request": { "kind": "repo", "target": "GameCult/Bifrost#89" }, "what": "it", "after_byte": before.len() + 2 }]); + apply(&c1, &rec, &prose, "r1-t2", now()) + }; + let (state, applied) = keep(1, "Meta, it looks fine."); + assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("needs_unread")]), "typed before the read"); + assert_eq!(keep(2, "Meta, I read #89 and it's fine.").0["commitments"][0]["status"], "kept", "typed after it"); +} + +/// B2: a state carrying each kind of `needs`, each kind of read, a block, reaffirmations and a read receipt passes P1, +/// as the commit writes them; the untyped shapes of probe 1, and a repo read that is no repo, fail it. +#[test] +fn k33_b2_the_published_schema_carries_what_the_commit_writes() { + let base = crate::projection::harness::tests::control(); + let me = eureka_pipeline::Slug(base["personaId"].as_str().unwrap().to_owned()); + let reads = [ReadRequest::Repo("GameCult/gamecult-ops#125".into()), ReadRequest::Web("https://ccrma.stanford.edu/~jos/pasp/".into()), ReadRequest::Mind("the knee reflex".into()), ReadRequest::Campaign("heimdall-body".into())]; + let kinds: Vec = [Needs::Words, Needs::Lacking].into_iter().chain(reads.iter().map(|request| Needs::Read { request: request.clone() })).collect(); + let mut entries: Vec = kinds.iter().map(|needs| holding_one(META, "send the render tonight", needs, "open")["commitments"][0].clone()).collect(); + entries[1]["status"] = json!("blocked"); + entries[2]["status"] = json!("blocked"); + entries[2]["blockedBy"] = json!({ "act": "read", "n": 1, "what": "GameCult/gamecult-ops#125 on the forge" }); + entries[3]["reaffirmed"] = json!([{ "at": now().to_rfc3339(), "event": "8", "words": "I'll read it" }]); + entries[3]["readAt"] = json!(now().to_rfc3339()); + entries[3]["readId"] = json!("r1-t2-r1"); + for (at, entry) in entries.iter_mut().enumerate() { + entry["id"] = json!(format!("c-r1-t1-{at}")); + } + let mut state = base.clone(); + state["commitments"] = json!(entries); + huginn_mind::persona::validate_document(&me, &state).unwrap(); + // What the applier itself writes passes too: opens on a read need, and their receipts. + let needs = Some(Needs::Read { request: ReadRequest::Repo("GameCult/Bifrost#89".into()) }); + let mut rec = record(json!([open_needing(META, needs.clone(), true), open_needing(KIKO, needs, true)]), json!([]), true); + rec["interpreter"]["reads"] = json!([{ "n": 1, "ok": true, "request": { "kind": "repo", "target": "GameCult/Bifrost#89" }, "what": "it", "after_byte": 0 }]); + let (written, done) = apply(&base, &rec, PROSE, "r1-t1", now()); + assert_eq!(done.read.len(), 2, "{written}"); + huginn_mind::persona::validate_document(&me, &written).unwrap(); + for needs in [json!("GameCult/Bifrost#89"), json!({ "kind": "read" }), json!({ "kind": "read", "request": "GameCult/Bifrost#89" }), json!({ "kind": "read", "request": { "kind": "repo", "target": "release notes" } })] { + let mut bad = state.clone(); + bad["commitments"][0]["needs"] = needs.clone(); + assert!(huginn_mind::persona::validate_document(&me, &bad).is_err(), "{needs}"); + } +} diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index ef6b47a..3c01ab6 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -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, 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. +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" }, @@ -678,8 +678,18 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na if let Some(retried) = retried { decision["retried"] = retried; } - if !parsed.unsent.is_empty() { - decision["unsent"] = json!(parsed.unsent); + // Each unsent draft with its words, so her outcome can tell her a held one did not go out (map 16.26); her earlier + // segments' first. + let mut unsent = earlier("unsent"); + unsent.extend(parsed.unsent.iter().map(|one| { + let mut held = json!(one); + if let Some(draft) = found.numbered(one.draft) { + held["words"] = json!(draft.text); + } + held + })); + if !unsent.is_empty() { + decision["unsent"] = json!(unsent); } if let Some(reads) = wake.earlier.map(|earlier| earlier["reads"].clone()).filter(Value::is_array) { decision["reads"] = reads; @@ -1111,17 +1121,19 @@ fn promised_one(into: Promising, draft: &Draft, promise: &ProposedPromise, shown let reached: Vec = into.packet.bodies.iter().cloned().chain(std::iter::once(into.packet.heard.clone())).collect(); match read::reach(&asked, into.packet, into.prose, &reached) { Ok(request) => (Some(Needs::Read { request }), Ok(())), - // Not reached: kept as named, so what it needs is still said; a domain line not listed names nothing. - Err(_) => { - let named = serde_json::from_value::(json!({ "kind": named.kind, "target": named.target.trim() })).ok(); - match named { + // Not reached: kept as named when it is a read at all, so what it needs is still said; a repo or web target + // that is no repo or address ("release notes", a path on a disk) is no read, so it is what this body lacks + // (map 16.26); a domain line not listed names nothing. + Err(_) => match named.kind { + Kind::Domain => (None, Err("what it needs was not named".to_owned())), + _ => match read::well_formed(named.kind, &named.target) { Some(request) => { let why = format!("it needs a read this body cannot reach: {}", request.what(her)); (Some(Needs::Read { request }), Err(why)) } - None => (None, Err("what it needs was not named".to_owned())), - } - } + None => (Some(Needs::Lacking), Err("this body has no way to do it".to_owned())), + }, + }, } } }; diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index d9bee1f..0577cc9 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -1408,3 +1408,19 @@ fn k33_b1_a_repo_name_keeps_its_hyphen_dot_and_underscore() { assert_eq!(read::reach(&repo_asked("GameCult/ops"), &eureka, prose, std::slice::from_ref(&heard)), Err("repo_not_in_front_of_her")); assert_eq!(read::reach(&repo_asked("GameCult/gamecult"), &eureka, prose, std::slice::from_ref(&heard)), Err("repo_not_in_front_of_her")); } + +/// L5 (Soul's R12): a read target that is no repo or address ("release notes", a path on a disk) is no read: the promise +/// opens as what this body lacks, in code's words. A well-formed read not in front of her stays a read, blocked. +#[test] +fn k33_l5_a_junk_read_target_opens_as_lacking() { + let prose = "Thanks, Deru. I'll read it properly before I say anything about it."; + for (kind, target) in [("repo", "release notes"), ("repo", "/var/tmp/notes.md"), ("web", "/var/tmp/notes.md"), ("web", "release notes")] { + let junk = answered(&reading_packet(), prose, saying_a_promise(json!({ "kind": "read", "read": { "kind": kind, "target": target } }))); + assert_eq!(junk["gaps"][0]["detail"], "this body has no way to do it", "{kind} {target}: {junk}"); + let entry = &committed(&junk, prose).0["commitments"][0]; + assert_eq!((entry["status"].as_str(), entry["needs"].clone()), (Some("blocked"), json!({ "kind": "lacking" })), "{kind} {target}"); + } + let away = answered(&reading_packet(), prose, saying_a_promise(json!({ "kind": "read", "read": { "kind": "repo", "target": "gamecult/Heimdall#3" } }))); + let entry = &committed(&away, prose).0["commitments"][0]; + assert_eq!((entry["status"].as_str(), entry["needs"].clone()), (Some("blocked"), json!({ "kind": "read", "request": { "kind": "repo", "target": "GameCult/Heimdall#3" } })), "{away}"); +} diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index 63b3083..4b81f2b 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -19,9 +19,9 @@ use serde_json::Value; -use super::commit::{How, Refusal as StateRefusal}; +use super::commit::{How, Needs, Refusal as StateRefusal}; use super::interpret::{GapKind, MAX_LINES, Refusal}; -use super::read::{ReadFailure, ReadRefusal}; +use super::read::{ReadFailure, ReadRefusal, ReadRequest}; use super::select::{Forms, capitalized, clip, spoken}; /// A line of hers that went out, as the actuator's receipt names it. @@ -79,8 +79,11 @@ enum Part { /// A promise of hers the commit closed (map 16.22.1, 16.22.7): told once, here, and never again. `by` is who let her /// off it, for a release. Closed { how: How, to: String, words: String, room: String, by: String }, - /// A close the commit refused: the promise stands, and why. - StillOpen { reason: StateRefusal, to: String, words: String }, + /// A close the commit refused: the promise stands as her record shows it (`status`, open or blocked), and why; + /// `read` is the read keeping it needs, when it needs one. + StillOpen { reason: StateRefusal, to: String, words: String, status: String, read: Option }, + /// A draft she held back by her own choice (`unsent`, held): it did not go out (map 16.26). + Held { room: Option, text: String }, /// A read she performed (map 16.22.3): what, in code's words; never its content, which is in her view while the /// conversation lasts (K26), and no sentence about what she lacks. Read { what: String }, @@ -259,6 +262,14 @@ pub(crate) fn outcome_of(record: &Value) -> Option { for cut in decision["cut_by_cap"].as_array().into_iter().flatten().filter_map(words) { outcome.parts.push(Part::Unfinished { room: room.clone(), text: cut, by_limit: true }); } + // Each draft she held back by her own choice, told as not sent (map 16.26); a superseded one is not, since a later + // draft or later prose of hers stands in its place. + for unsent in decision["unsent"].as_array().into_iter().flatten().filter(|unsent| unsent["how"] == "held") { + match words(&unsent["words"]) { + Some(text) => outcome.parts.push(Part::Held { room: room.clone(), text }), + None => outcome.omitted.push(format!("a held draft without its words: {unsent}")), + } + } // What the commit did with her promises (`commit::apply`): each close it applied, and each close it refused for a // reason she can be told. An open is told by the promise's own section from her next packet on. for done in record["committed"]["closed"].as_array().into_iter().flatten() { @@ -272,8 +283,27 @@ pub(crate) fn outcome_of(record: &Value) -> Option { for refused in record["committed"]["refused"].as_array().into_iter().flatten() { let listed = decision["promises"].as_array().into_iter().flatten().find(|listed| listed["id"] == refused["proposal"]["promise"]); match (serde_json::from_value::(refused["reason"].clone()), listed) { - (Ok(reason @ (StateRefusal::DraftNotSent | StateRefusal::BlockedNotKeepable | StateRefusal::ReleaseNotByPromisee | StateRefusal::ReleaseBeforePromise | StateRefusal::CloseContradicted | StateRefusal::NotWherePromised | StateRefusal::OutsidePutChanged)), Some(listed)) if refused["proposal"]["kind"] == "promise_close" => { - outcome.parts.push(Part::StillOpen { reason, to: listed["to_name"].as_str().unwrap_or("the room").to_owned(), words: listed["words"].as_str().unwrap_or_default().to_owned() }); + ( + Ok( + reason @ (StateRefusal::DraftNotSent + | StateRefusal::BlockedNotKeepable + | StateRefusal::ReleaseNotByPromisee + | StateRefusal::ReleaseBeforePromise + | StateRefusal::CloseUnquoted + | StateRefusal::CloseContradicted + | StateRefusal::NeedsUnread + | StateRefusal::NeedsMalformed + | StateRefusal::NotWherePromised + | StateRefusal::OutsidePutChanged), + ), + Some(listed), + ) if refused["proposal"]["kind"] == "promise_close" => { + let read = match serde_json::from_value::(listed["needs"].clone()) { + Ok(Needs::Read { request }) => Some(request), + _ => None, + }; + let status = listed["status"].as_str().unwrap_or("open").to_owned(); + outcome.parts.push(Part::StillOpen { reason, to: listed["to_name"].as_str().unwrap_or("the room").to_owned(), words: listed["words"].as_str().unwrap_or_default().to_owned(), status, read }); } _ => outcome.omitted.push(format!("a state change the commit refused that she is not told ({}): {}", refused["reason"], refused["proposal"])), } @@ -302,7 +332,7 @@ impl Part { fn rank(&self) -> u8 { match self { Self::Failed => 0, - Self::Refused { .. } | Self::Gap { .. } | Self::Unfinished { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) | Self::StillOpen { .. } | Self::ReadFailed { .. } | Self::ReadRefused { .. } => 1, + Self::Refused { .. } | Self::Gap { .. } | Self::Unfinished { .. } | Self::Held { .. } | Self::NotAmended { .. } | Self::NoteRefused(_) | Self::StillOpen { .. } | Self::ReadFailed { .. } | Self::ReadRefused { .. } => 1, Self::Promise { .. } | Self::Amended { promise: true, .. } => 2, Self::Said { .. } | Self::Amended { .. } | Self::NoteLeft(_) | Self::Closed { .. } | Self::Read { .. } => 3, Self::BrokeAfter { .. } => 4, @@ -321,7 +351,7 @@ impl Part { Self::NoteLeft(text) => format!("{cap_subj} left Self a note: {}.", quoted(text)), Self::Refused { reason: Refusal::Echo, room, .. } | Self::Gap { kind: GapKind::Unwritten | GapKind::Unresolved, room, .. } => format!("Nothing reached {}.", place(room)), Self::Refused { reason: Refusal::NoRoom, .. } => "Nothing reached anyone.".to_owned(), - Self::Refused { room, .. } | Self::Unfinished { room, .. } => format!("Nothing of this reached {}:", place(room)), + Self::Refused { room, .. } | Self::Unfinished { room, .. } | Self::Held { room, .. } => format!("Nothing of this reached {}:", place(room)), Self::Gap { kind: GapKind::Addressee | GapKind::Elsewhere, .. } => "Nothing reached anyone.".to_owned(), Self::Gap { kind: GapKind::MissingAffordance, .. } => "Nothing happened.".to_owned(), Self::NotAmended { refusal: None, room, .. } => format!("Nothing changed, and nothing reached {}:", place(room)), @@ -332,7 +362,7 @@ impl Part { Self::BrokeAfter { room } => format!("Nothing more reached {}:", place(room)), Self::Closed { how: How::Released, by, words, .. } => format!("{by} let {obj} off {poss} promise: {}.", quoted(words)), Self::Closed { to, words, .. } => format!("{} promise to {to}, {}, is closed:", capitalized(poss), quoted(words)), - Self::StillOpen { to, words, .. } => format!("{} promise to {to}, {}, is still open:", capitalized(poss), quoted(words)), + Self::StillOpen { to, words, status, .. } => format!("{} record still shows {poss} promise to {to}, {}, {status}:", capitalized(poss), quoted(words)), Self::Read { what } => format!("{cap_subj} read {what}."), Self::ReadFailed { what, .. } => format!("{cap_subj} reached for {what} and could not read it:"), Self::ReadRefused { what: Some(what), why: ReadRefusal::InView } => format!("{cap_subj} already read {what} earlier in this conversation."), @@ -372,6 +402,7 @@ impl Part { Self::Gap { quote, .. } => format!(" {cap_subj} meant to say something and wrote no words to send. {}", shown(quote)), Self::Unfinished { text, by_limit: false, .. } => format!(" the turn ended before {subj} finished writing it. {}", shown(&Quote::Wrote(text.clone()))), Self::Unfinished { text, by_limit: true, .. } => format!(" the length limit cut it before {subj} finished writing it. {}", shown(&Quote::Wrote(text.clone()))), + Self::Held { text, .. } => format!(" {subj} held it back, and it was not sent. {}", shown(&Quote::Wrote(text.clone()))), Self::NotAmended { refusal: None, added, .. } => format!(" the line {subj} meant to add to is not one {subj} can add to here. {}", shown(&Quote::Wrote(added.clone()))), Self::NotAmended { refusal: Some(refusal), added, .. } => { let why = match refusal { @@ -392,6 +423,12 @@ impl Part { Self::StillOpen { reason: StateRefusal::ReleaseNotByPromisee, .. } => format!(" the line read as letting {obj} off it was not from the person {subj} promised."), Self::StillOpen { reason: StateRefusal::ReleaseBeforePromise, .. } => format!(" the line read as letting {obj} off it came before {subj} made it."), Self::StillOpen { reason: StateRefusal::CloseContradicted, .. } => format!(" {poss} own thought held it as still owed, so it was not closed."), + Self::StillOpen { reason: StateRefusal::CloseUnquoted, .. } => format!(" no words of {poss} own thought that turn, outside what {subj} wrote to send, took the close up, so it was not closed."), + Self::StillOpen { reason: StateRefusal::NeedsUnread, read, .. } => match read { + Some(read) => format!(" keeping it needs {obj} to read {}, and no read of it had come back to {obj} before {subj} wrote that line, so it was not kept.", read.what(her)), + None => format!(" keeping it needs a read, and none had come back to {obj} before {subj} wrote that line, so it was not kept."), + }, + Self::StillOpen { reason: StateRefusal::NeedsMalformed, .. } => format!(" what keeping it needs was never recorded plainly, so it cannot be kept; {subj} can withdraw it."), Self::StillOpen { reason: StateRefusal::NotWherePromised, .. } => format!(" what {subj} said to close it was not where the person {subj} promised could read it."), Self::StillOpen { .. } => format!(" it was changed outside {poss} turn, and stands as it was changed."), Self::BrokeAfter { .. } => format!(" the rest of that turn broke off, not by {poss} choice."), diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index 6f50af5..f2e866b 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -56,6 +56,7 @@ fn each_gap_is_told_by_its_kind_with_a_draft_as_written_and_a_thought_as_thought [ "- Nothing happened. He reached for something he has no way to do from here, now or later, and it will not happen by itself. In his thought: \"I want to see the shape of that sound.\". That he wanted it is kept in his record; no one has taken it up.", "- Nothing reached #minds:gamecult.org. He meant to say something and wrote no words to send. In his thought: \"I'll tell Meta I'm fine, more or less.\".", + "- Nothing of this reached #minds:gamecult.org: he held it back, and it was not sent. He wrote: \"Fine, you win.\".", ] ); assert!(lines.iter().all(|line| !line.contains("MODEL-DETAIL")), "the model's detail is never what he is told"); @@ -335,3 +336,34 @@ fn a_record_that_does_not_say_what_its_turn_heard_withholds_every_quote() { record["interpreter"]["heard"] = json!([]); assert_eq!(told(&record).0, shown, "an empty `heard` says the turn heard nothing"); } + +// --------------------------------------------------------------------------------------------- +// K33 (map 16.26): a refused close and a held draft are told, by the fixed table. + +/// L1: each refused close she can correct is told as her record still showing the promise, and why; L4: a held draft is +/// told as not sent. +#[test] +fn k33_a_refused_close_and_a_held_draft_are_told() { + let listed = json!([ + { "id": "c1", "entry": "e1", "status": "open", "to_name": "Deru", "words": "I'll read it properly.", "needs": { "kind": "read", "request": { "kind": "web", "target": "https://ccrma.stanford.edu/~jos/pasp/" } } }, + { "id": "c2", "entry": "e2", "status": "open", "to_name": "Meta", "words": "I'll look at #125.", "needs": null }, + ]); + let refused = |promise: &str, reason: &str| json!({ "proposal": { "kind": "promise_close", "promise": promise, "how": "kept", "evidence": { "draft": 1 } }, "reason": reason }); + let record = json!({ + "interpreter": { "said": [], "refused": [], "gaps": [], "heard": [], "room": MINDS, "promises": listed, "unsent": [{ "draft": 2, "how": "held", "quote": "I hold that one back", "words": "Deru, the waveguide part first." }, { "draft": 3, "how": "superseded", "quote": "later words", "words": "Deru, never mind." }] }, + "posted": [], + "committed": { "closed": [], "refused": [refused("c1", "close_unquoted"), refused("c1", "needs_unread"), refused("c2", "needs_malformed"), refused("c2", "close_contradicted")] } + }); + let (lines, omitted) = told(&record); + assert_eq!( + lines, + [ + "- Nothing of this reached #minds:gamecult.org: he held it back, and it was not sent. He wrote: \"Deru, the waveguide part first.\".", + "- His record still shows his promise to Deru, \"I'll read it properly.\", open: no words of his own thought that turn, outside what he wrote to send, took the close up, so it was not closed.", + "- His record still shows his promise to Deru, \"I'll read it properly.\", open: keeping it needs him to read https://ccrma.stanford.edu/~jos/pasp/, and no read of it had come back to him before he wrote that line, so it was not kept.", + "- His record still shows his promise to Meta, \"I'll look at #125.\", open: what keeping it needs was never recorded plainly, so it cannot be kept; he can withdraw it.", + "- His record still shows his promise to Meta, \"I'll look at #125.\", open: his own thought held it as still owed, so it was not closed.", + ], + "{omitted:?}" + ); +} diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index 8068f53..6031253 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -282,6 +282,18 @@ pub(crate) fn repo_request(target: &str) -> Option { repo_target(target.trim()).map(ReadRequest::Repo) } +/// A read of `kind` and `target` in its own shape, reached or not (map 16.26): a repo target passes `repo_target`, a web +/// target is one address, a recall says something. None for a domain line, which resolves only against a packet. +pub(crate) fn well_formed(kind: Kind, target: &str) -> Option { + let target = target.trim(); + match kind { + Kind::Repo => repo_request(target), + Kind::Web => ((target.starts_with("http://") || target.starts_with("https://")) && !target.contains(char::is_whitespace)).then(|| ReadRequest::Web(target.to_owned())), + Kind::Mind => (!target.is_empty()).then(|| ReadRequest::Mind(target.to_owned())), + Kind::Domain => None, + } +} + /// The repo a repo target names, lowercased: `GameCult/Bifrost#89` names `bifrost`. None when it is no repo target. pub(crate) fn repo_name(target: &str) -> Option { let target = repo_target(target.trim())?; @@ -329,7 +341,7 @@ pub(crate) fn resolve(asked: &Asked, packet: &Packet, prose: &str, reached: &[St None => Err("not_a_gamecult_repo"), }, Kind::Web => { - let url = (target.starts_with("http://") || target.starts_with("https://")) && !target.contains(char::is_whitespace); + let url = well_formed(Kind::Web, target).is_some(); let reached_for = prose.contains(target) || reached.iter().any(|text| text.contains(target)); if url && reached_for { Ok(ReadRequest::Web(target.to_owned())) } else { Err("web_address_not_in_front_of_her") } } diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index 6567492..9f6cefd 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -1885,9 +1885,17 @@ fn open_promises(inputs: &Inputs, her: Forms) -> (Vec, String) { ("blocked", _) => format!(" {} {} no way to do it yet.", her.cap_subj, her.has), _ => String::new(), }; + // What an open promise needs read, and whether she has read it: her receipt on the entry (map 16.26). + let reading = match (&promise.needs, promise.status.as_str()) { + (Some(Needs::Read { request }), "open") => match promise.held["readAt"].as_str().and_then(|at| DateTime::parse_from_rfc3339(at).ok()) { + Some(at) => format!(" It needs {} to read {}: {} read it {}.", her.obj, request.what(her), her.subj, coarse(at.with_timezone(&Utc), inputs.now)), + None => format!(" It needs {} to read {}, and {} {} not read it yet.", her.obj, request.what(her), her.subj, her.has), + }, + _ => String::new(), + }; // Each time she said it again, verbatim (map 16.24.2). let again: String = promise.held["reaffirmed"].as_array().into_iter().flatten().map(|said| format!(" Said again {}: {}.", said["at"].as_str().and_then(|at| DateTime::parse_from_rfc3339(at).ok()).map_or_else(|| "since".to_owned(), |at| coarse(at.with_timezone(&Utc), inputs.now)), spoken(said["words"].as_str().unwrap_or_default()))).collect(); - format!("- to {}, {}, {}, {} promise: {}.{again}{blocked}{closed}", promise.to_name, coarse(promise.made, inputs.now), promise.place, her.poss, spoken(&promise.words)) + format!("- to {}, {}, {}, {} promise: {}.{again}{reading}{blocked}{closed}", promise.to_name, coarse(promise.made, inputs.now), promise.place, her.poss, spoken(&promise.words)) }) .collect(); let block = format!("{} promises:\n{}", capitalized(her.poss), lines.join("\n")); diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index 6e6a267..79182bc 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -515,6 +515,7 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) // The commit: her turn's proposals applied to her in-run state on the receipts above, as C3c's will be live, and // what it did kept in the record her next outcome reads. let (state, applied) = commit::apply(&members[at].state, &record, render["persona"]["prose"].as_str().unwrap_or_default(), &format!("r{}-t{counter}", repeat + 1), now); + held_to_schema(&member.entry.name, &id, &state, &format!("r{}-t{counter}", repeat + 1))?; record["committed"] = json!(applied); last[at] = Some(record.clone()); records[at].push(record.clone()); @@ -531,6 +532,15 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) Ok(json!({ "repeat": repeat + 1, "seed": seed, "transcript": transcript, "turns": turns, "metrics": metrics, "inbox": inbox })) } +/// Her in-run state held to what a put would accept (P1 to P3), after every commit (Soul's R12 B2): a commit that writes +/// a field the published schema does not carry fails the run here, not at the live put. +fn held_to_schema(name: &str, id: &str, state: &Value, turn: &str) -> Result<()> { + match huginn_mind::persona::validate_document(&eureka_pipeline::Slug(localpart(id).to_owned()), state) { + Ok(()) => Ok(()), + Err(refusal) => bail!("{name}'s state after the commit of {turn} would be refused by a put: {refusal}"), + } +} + /// The line a reply of hers answers, by the event the room gave it (`$fixture-{index}`, as `harness::Line::delivery` names /// it), when it is a line of `room`: the mouth's check under B3. None refuses the send. fn replied(lines: &[Line], event: &str, room: &str) -> Option { @@ -735,18 +745,21 @@ 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, refused) = (list("opened"), list("closed"), list("reaffirmed"), list("blocked"), 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, &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()); } for done in &closed { let by = &done["entry"]["closedBy"]; - let words = by["words"].as_str().map_or_else(|| done["by"].as_str().unwrap_or_default().to_owned(), str::to_owned); - let _ = writeln!(out, "- closed {} {} by {}: \"{words}\"", id(&done["entry"]), done["how"].as_str().unwrap_or_default(), by["act"].as_str().unwrap_or_default()); + // A release is by the person, whose words her state does not copy (Soul's R12 L7); her own act is by its words. + let _ = match done["how"].as_str() { + Some("released") => writeln!(out, "- closed {} released by {}", id(&done["entry"]), done["by"].as_str().unwrap_or_default()), + how => writeln!(out, "- closed {} {} by {}: \"{}\"", id(&done["entry"]), how.unwrap_or_default(), by["act"].as_str().unwrap_or_default(), by["words"].as_str().unwrap_or_default()), + }; } for entry in &reaffirmed { let again = entry["reaffirmed"].as_array().and_then(|said| said.last()).map_or("", |said| said["words"].as_str().unwrap_or_default()); @@ -755,6 +768,9 @@ fn promises_markdown(out: &mut String, turn: &Value) { for entry in &blocked { let _ = writeln!(out, "- blocked `{}` by read {}: {}", id(entry), entry["blockedBy"]["n"], entry["blockedBy"]["what"].as_str().unwrap_or_default()); } + for entry in &read { + let _ = writeln!(out, "- read for `{}`: {}", id(entry), entry["readId"].as_str().unwrap_or_default()); + } for one in &refused { let _ = writeln!(out, "- refused ({}): `{}`", one["reason"].as_str().unwrap_or_default(), one["proposal"]); } diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index 44f9c09..f479f67 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -850,3 +850,41 @@ fn k32_campaign_cast_read_refused() { let harness = Harness { instance: "eureka".into(), persona: None, model: Some(&model), tuning: dir.path().join("persona-tuning.toml") }; assert!(format!("{:#}", simulate(&harness, &path).unwrap_err()).contains("records a campaign read")); } + +/// K33 (Soul's R12 B2): after every commit the simulator holds her in-run state to what a put would accept, so a commit +/// writing a field the published schema does not carry fails the run. +#[test] +fn k33_the_simulator_holds_each_commit_to_the_schema() { + let mut state = control(); + let id = "@eureka:gamecult.org"; + let entry = json!({ "id": "c-r1-t1-1", "to": null, "room": "#minds:gamecult.org", "event": "7", "madeAt": "2026-11-20T15:00:00Z", "words": "I'll read it", "status": "open", "needs": { "kind": "read", "request": { "kind": "repo", "target": "GameCult/gamecult-ops#125" } }, "readAt": "2026-11-20T15:05:00Z", "readId": "r1-t2-r1", "closedAt": null, "closedBy": null, "extensions": {} }); + state["commitments"] = json!([entry]); + held_to_schema("Eureka", id, &state, "r1-t2").unwrap(); + state["commitments"][0]["needs"] = json!({ "kind": "read", "request": "GameCult/gamecult-ops#125" }); + let refused = held_to_schema("Eureka", id, &state, "r1-t3").unwrap_err().to_string(); + assert!(refused.starts_with("Eureka's state after the commit of r1-t3 would be refused by a put"), "{refused}"); + state["commitments"][0]["needs"] = json!({ "kind": "words" }); + state["commitments"][0]["unknownField"] = json!(1); + assert!(held_to_schema("Eureka", id, &state, "r1-t4").is_err()); +} + +/// L7 (Soul's R12): a release renders who released it, never "released by released". +#[test] +fn k33_a_release_renders_by_whom() { + let turn = json!({ + "report": { "packet": { "in_view": "" }, "renders": [{ "interpreter": { "state": [] } }] }, + "committed": { + "opened": [], "refused": [], "pruned": 0, "reaffirmed": [], "blocked": [], + "closed": [{ "entry": { "id": "c-r1-t1-1", "closedBy": { "act": "released", "event": "$m", "words": null } }, "how": "released", "to_name": "Meta", "by": "Meta" }], + "read": [{ "id": "c-r1-t1-2", "readId": "r1-t3-r1" }] + } + }); + let mut out = String::new(); + promises_markdown(&mut out, &turn); + assert_eq!(out, "Committed: + +- closed c-r1-t1-1 released by Meta +- read for `c-r1-t1-2`: r1-t3-r1 + +"); +} diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 5fcc104..e5ed65e 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -2629,7 +2629,7 @@ fn k22_a_closed_promise_is_told_once_in_the_next_outcome() { } }); let told = outcome::outcome_of(&record).unwrap().lines(select::forms(&state())); assert_eq!(told, [ - "- Her promise to Meta, \"I'll send the render tonight.\", is still open: she has no way to do it, so it was not kept.", + "- Her record still shows her promise to Meta, \"I'll send the render tonight.\", blocked: she has no way to do it, so it was not kept.", "- Meta let her off her promise: \"I'll send the render tonight.\". It is closed.", ]); let withdrawn = json!({ "interpreter": { "said": [], "heard": [] }, "posted": [], "committed": { "closed": [{ "entry": entry("withdrawn"), "how": "withdrawn", "to_name": "Meta", "by": null }], "refused": [] } });