B5: a keep or a withdrawal closes a promise only where the person promised can read it: the promise's room, or a direct message with them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-20 22:57:08 +01:00
commit a5fed782c5
4 changed files with 62 additions and 10 deletions

View file

@ -96,6 +96,9 @@ pub(crate) enum Refusal {
ReleaseNotByPromisee,
/// A release cited to a line said before she made the promise.
ReleaseBeforePromise,
/// A keep or a withdrawal said where the person she promised was not: not the promise's room, nor a direct message
/// with them (B5).
NotWherePromised,
}
/// Which evidence each kind accepts: the table of map 16.22.7, one row per kind (and per close).
@ -103,8 +106,8 @@ pub(crate) enum Refusal {
/// | proposal | evidence | needs | bound |
/// |---|---|---|---|
/// | `promise_open` | `Draft` | the line went out | one entry per person and words |
/// | `promise_close` kept | `Draft`, `Read` | the act succeeded | not a blocked entry |
/// | `promise_close` withdrawn | `Draft` | the line went out | a blocked entry too: a line telling the person she cannot do it |
/// | `promise_close` kept | `Draft`, `Read` | the act succeeded | 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 {
matches!(
@ -121,9 +124,9 @@ fn accepts(proposal: &Proposal, evidence: &Evidence) -> bool {
enum Resolved {
/// A passage of her thought: its bytes in her prose.
Prose,
/// A draft whose act went out, by the actuator's receipt: the act (`said`, `amended`), the line's event, its room and
/// her words that went out.
Sent { act: &'static str, event: String, room: String, text: String },
/// A draft whose act went out, by the actuator's receipt: the act (`said`, `amended`), the line's event, its room, her
/// words that went out, and whom the line mentioned.
Sent { act: &'static str, event: String, room: String, text: String, mentions: Vec<String> },
/// A line she heard: its event, sender, room and time.
Heard { event: String, sender: String, room: String, at_ms: u64, who: String },
}
@ -145,13 +148,14 @@ fn resolve(evidence: &Evidence, record: &Value, prose: &str) -> Result<Resolved,
let posted = record["posted"].as_array().into_iter().flatten();
for line in decision["said"].as_array().into_iter().flatten().filter(|line| line["rests_on"]["draft"].as_u64() == Some(*n as u64)) {
if let Some(receipt) = posted.clone().find(|receipt| receipt["room"] == line["room"] && receipt["text"] == line["text"]) {
return Ok(Resolved::Sent { act: "said", event: text(&receipt["event"]), room: text(&receipt["room"]), text: text(&receipt["text"]) });
let mentions = line["mentions"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_owned).collect();
return Ok(Resolved::Sent { act: "said", event: text(&receipt["event"]), room: text(&receipt["room"]), text: text(&receipt["text"]), mentions });
}
}
for amended in decision["amended"].as_array().into_iter().flatten().filter(|amended| amended["draft"].as_u64() == Some(*n as u64)) {
let made = record["edited"].as_array().into_iter().flatten().any(|receipt| receipt["event"] == amended["event"] && receipt["refusal"].is_null());
if made {
return Ok(Resolved::Sent { act: "amended", event: text(&amended["event"]), room: text(&amended["room"]), text: text(&amended["added"]) });
return Ok(Resolved::Sent { act: "amended", event: text(&amended["event"]), room: text(&amended["room"]), text: text(&amended["added"]), mentions: Vec::new() });
}
}
if drafts(prose).drafts.iter().any(|draft| draft.n == *n) { Err(Refusal::DraftNotSent) } else { Err(Refusal::NoDraft) }
@ -177,6 +181,19 @@ fn millis(at: DateTime<Utc>) -> u64 {
u64::try_from(at.timestamp_millis()).unwrap_or_default()
}
/// Whether a line in `room` reached the person she promised (B5, map 16.22.1): it is in the promise's own room, or, for a
/// promise to a person, in a direct message with them, where they wrote or the line mentions them. A promise to the room
/// is reached only in its room.
fn reaches(entry: &Value, room: &str, mentions: &[String], record: &Value) -> bool {
if entry["room"].as_str() == Some(room) {
return true;
}
let Some(to) = entry["to"].as_str() else { return false };
let decision = &record["interpreter"];
let direct = decision["room"].as_str() == Some(room) && decision["room_kind"] == "direct";
direct && (mentions.iter().any(|id| id == to) || decision["lines"].as_array().into_iter().flatten().any(|line| line["room"].as_str() == Some(room) && line["sender"].as_str() == Some(to)))
}
fn closed(status: &str) -> bool {
matches!(status, "kept" | "withdrawn" | "released")
}
@ -260,7 +277,12 @@ fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str
}
let (act, event, words, who) = match (how, resolved) {
(How::Kept, _) if status == "blocked" => return Err(Refusal::BlockedNotKeepable),
(How::Kept | How::Withdrawn, Resolved::Sent { act, event, text, .. }) => (act, json!(event), json!(text), Value::Null),
(How::Kept | How::Withdrawn, Resolved::Sent { act, event, text, room, mentions }) => {
if !reaches(entry, &room, &mentions, record) {
return Err(Refusal::NotWherePromised);
}
(act, json!(event), json!(text), Value::Null)
}
(How::Released, Resolved::Heard { event, sender, room, at_ms, who }) => {
let by_promisee = match entry["to"].as_str() {
Some(to) => sender == to,

View file

@ -169,3 +169,32 @@ fn b3_one_line_opens_one_entry_per_promise() {
assert_eq!(words, ["send the render tonight", "the render tonight"], "{applied:?}");
assert_eq!(reasons(&applied), vec![json!("already_open")]);
}
/// B5: a keep or a withdrawal must reach the person promised: a line in the promise's room, or a direct message with them.
#[test]
fn b5_a_close_counts_only_where_the_person_promised_can_read_it() {
let elsewhere = |how: How, kind: &str, mentions: Value| {
let mut rec = record(json!([close(how, Evidence::Draft(1))]), shown("open"), true);
rec["interpreter"]["said"][0]["room"] = json!("!dm:gamecult.org");
rec["interpreter"]["said"][0]["mentions"] = mentions;
rec["interpreter"]["room"] = json!("!dm:gamecult.org");
rec["interpreter"]["room_kind"] = json!(kind);
rec["posted"][0]["room"] = json!("!dm:gamecult.org");
apply(&holding("open"), &rec, PROSE, "r1-t2", now())
};
for how in [How::Kept, How::Withdrawn] {
let (state, applied) = elsewhere(how, "public", json!([META]));
assert_eq!((state["commitments"][0]["status"].as_str(), reasons(&applied)), (Some("open"), vec![json!("not_where_promised")]), "another room: {how:?}");
let (_, applied) = elsewhere(how, "direct", json!([KIKO]));
assert_eq!(reasons(&applied), vec![json!("not_where_promised")], "a direct message with someone else: {how:?}");
let (state, applied) = elsewhere(how, "direct", json!([META]));
assert!(applied.refused.is_empty() && state["commitments"][0]["status"] != "open", "a direct message with Meta: {how:?} {applied:?}");
}
// A promise to the room closes only in its room.
let mut to_room = holding("open");
to_room["commitments"][0]["to"] = Value::Null;
let mut rec = record(json!([close(How::Withdrawn, Evidence::Draft(1))]), shown("open"), true);
rec["interpreter"]["said"][0]["room"] = json!("#general:gamecult.org");
rec["posted"][0]["room"] = json!("#general:gamecult.org");
assert_eq!(reasons(&apply(&to_room, &rec, PROSE, "r1-t2", now()).1), vec![json!("not_where_promised")]);
}

View file

@ -87,7 +87,7 @@ fn speech_frame_tail(her: Forms) -> String {
format!(
"{cap_subj} speak{s} only in this room. What {subj} know{s} privately is listed below as private: {subj} say{s} none of it here, and nothing that gives it away. A private matter may be said plainly only to the person it concerns, in a direct message with exactly that person; nothing listed is that here. Whether a draft fits who is listening is yours to judge.
Answer with the speech contract's object. `say` lists the drafts {subj} send{s} now, each by its number, with the Matrix ids of anyone listed whom {subj} address{es} directly (`mentions`), the id of the line listed below that {subj} answer{s} or pass{es} on (`in_reply_to`, or null: the room shows that line, with who said it, above {poss} own words), and what the draft promises (`promises`, a list, empty when it promises nothing): for each act it promises, its words, copied exactly, the Matrix id of the person listed to whom {subj} promise{s} it (`to`, null when {subj} promise{s} it to the room), and whether {subj} can do it (`doable`). A promise is doable only when what {subj} can do here, listed below, carries it out, now or later, with no tool {subj} lack{s}: a promise to paste, quote or send something {subj} {has} not read is not doable while {subj} {has} no way to read it. `gaps` records what {subj} meant and did not send. `amend` adds to one of {poss} own lines listed below, at most one a turn, only when {poss} thought shows {obj} choosing to correct or add to that line: name the line by its id, the draft that is {poss} addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; {subj} never take{s} a word back. `suggest` leaves Self one note, at most one a turn, only when {poss} thought shows {obj} choosing to: name the draft that is the note, its kind (feedback when {subj} pass{es} on what someone listed said, with that person's Matrix id in `about`; idea when it is {poss} own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes {poss} open promises listed below, each by its id: kept, citing the draft by which {subj} {does} it (`evidence.draft`); withdrawn, citing the draft in which {subj} take{s} it back to the person {subj} promised, or tell{s} them {subj} cannot do it; released, citing the id of the line listed below that {subj} may reply to in which the person {subj} promised lets {obj} off it (`evidence.line`). A draft cited closes the promise only when it goes out this turn, and a thought alone closes nothing. A promise {subj} {has} no way to do is never kept by {obj}: telling the person {subj} promised that {subj} cannot do it withdraws it, and they can release it.
Answer with the speech contract's object. `say` lists the drafts {subj} send{s} now, each by its number, with the Matrix ids of anyone listed whom {subj} address{es} directly (`mentions`), the id of the line listed below that {subj} answer{s} or pass{es} on (`in_reply_to`, or null: the room shows that line, with who said it, above {poss} own words), and what the draft promises (`promises`, a list, empty when it promises nothing): for each act it promises, its words, copied exactly, the Matrix id of the person listed to whom {subj} promise{s} it (`to`, null when {subj} promise{s} it to the room), and whether {subj} can do it (`doable`). A promise is doable only when what {subj} can do here, listed below, carries it out, now or later, with no tool {subj} lack{s}: a promise to paste, quote or send something {subj} {has} not read is not doable while {subj} {has} no way to read it. `gaps` records what {subj} meant and did not send. `amend` adds to one of {poss} own lines listed below, at most one a turn, only when {poss} thought shows {obj} choosing to correct or add to that line: name the line by its id, the draft that is {poss} addition, and what it promises, as a line's `promises`. The line stays as it was and the draft is added after it; {subj} never take{s} a word back. `suggest` leaves Self one note, at most one a turn, only when {poss} thought shows {obj} choosing to: name the draft that is the note, its kind (feedback when {subj} pass{es} on what someone listed said, with that person's Matrix id in `about`; idea when it is {poss} own, `about` null), and set `private` when it carries anything listed as private or gives it away; such a note is not left. `state` closes {poss} open promises listed below, each by its id: kept, citing the draft by which {subj} {does} it (`evidence.draft`); withdrawn, citing the draft in which {subj} take{s} it back to the person {subj} promised, or tell{s} them {subj} cannot do it; released, citing the id of the line listed below that {subj} may reply to in which the person {subj} promised lets {obj} off it (`evidence.line`). A draft cited closes the promise only when it goes out this turn 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 they can release it.
A draft is said whole or not at all, and only once. At most two drafts a turn. Record a gap instead of guessing: conditional when {subj} {has} drafted something {subj} might say but {has} not chosen to, addressee when {subj} mean{s} to send a draft but whom to is unclear, elsewhere when {subj} mean{s} a draft for another room or another time; for these three, name the draft by number. missing_affordance when {subj} mean{s} to do something, now or later, that {poss} body cannot do (what {subj} can do here is listed below), whether {subj} said so in a draft or only thought it; name the draft when there is one. unwritten when {subj} mean{s} to say something now and wrote no draft of it. Holding back is no gap: when {poss} thought shows {obj} choosing to wait, to let something stand, to leave it for later or to say nothing, record nothing for it. Every other intent of {poss} that is not carried out has a kind: an intent to act is missing_affordance, an intent to say now with no draft is unwritten. When a gap names no draft, quote the words of {poss} thought that show it, at least four words, copied exactly.",
es = if s.is_empty() { "" } else { "es" },

View file

@ -235,7 +235,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option<Outcome> {
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::<StateRefusal>(refused["reason"].clone()), listed) {
(Ok(reason @ (StateRefusal::DraftNotSent | StateRefusal::BlockedNotKeepable | StateRefusal::ReleaseNotByPromisee | StateRefusal::ReleaseBeforePromise | StateRefusal::OutsidePutSameField)), Some(listed)) if refused["proposal"]["kind"] == "promise_close" => {
(Ok(reason @ (StateRefusal::DraftNotSent | StateRefusal::BlockedNotKeepable | StateRefusal::ReleaseNotByPromisee | StateRefusal::ReleaseBeforePromise | StateRefusal::NotWherePromised | StateRefusal::OutsidePutSameField)), 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() });
}
_ => outcome.omitted.push(format!("a state change the commit refused that she is not told ({}): {}", refused["reason"], refused["proposal"])),
@ -348,6 +348,7 @@ impl Part {
Self::StillOpen { reason: StateRefusal::BlockedNotKeepable, .. } => format!(" {subj} {has} no way to do it, so it was not kept."),
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::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."),
}