diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index 75177d4..bee49de 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -447,7 +447,7 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni ended = Some(cap); // A read a cap refuses is recorded with what it was, and told to her next wake (`outcome`). let mut refused = decision["read_refused"].as_array().cloned().unwrap_or_default(); - refused.push(json!({ "read": read, "why": cap, "what": read["what"] })); + refused.push(json!({ "read": read, "why": cap, "what": read["what"], "request": read["request"] })); decision["read_refused"] = json!(refused); break; } diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index b312f0f..29cf997 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -985,7 +985,8 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na if let Some(raw) = parsed.read.filter(|raw| !raw.is_null()) { match reading(&raw, packet, prose, &found, wake) { Ok(read) => decision["read"] = read, - Err((why, what)) => read_refused.push(json!({ "read": raw, "why": why, "what": what })), + // A refused read that resolved carries its request, so her outcome names it in each form by type (K46). + Err((why, request)) => read_refused.push(json!({ "read": raw, "why": why, "what": request.as_ref().map(|request| request.what(packet.forms)), "request": request })), } } if !read_refused.is_empty() { @@ -995,9 +996,9 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na } /// A read the answer names, resolved: its request, what it is in code's words, and the passage of her thought in this -/// segment that reaches for it. Why not, when not, with what it was in code's words when it resolved (Soul's R7: a read -/// she already made is told by name). -fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake) -> Result)> { +/// segment that reaches for it. Why not, when not, with its request when it resolved (Soul's R7: a read she already made +/// is told by name). +fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake) -> Result)> { let asked: Asked = serde_json::from_value(raw.clone()).map_err(|_| ("not_the_contract", None))?; // In front of her is her prose and what she was sent, never what she read: a read cannot chain from a fetched page // (Soul's p1b), so no page can steer her to the next. The one reach rule decides it, as at a promise's open (16.25.5). @@ -1007,8 +1008,8 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake let key = request.normal(); let this_wake = wake.earlier.into_iter().flat_map(|earlier| earlier["reads"].as_array().cloned().unwrap_or_default()).find(|done| (done["ok"] == true || done["failure"] == "not_found") && serde_json::from_value::(done["request"].clone()).is_ok_and(|done| done.normal() == key)).map(|done| done["ok"] == true); match packet.already_read.iter().find(|tried| tried.key == key).map(|tried| tried.found).or(this_wake) { - Some(true) => return Err(("in_view", Some(request.what(packet.forms)))), - Some(false) => return Err(("in_view_not_found", Some(request.what(packet.forms)))), + Some(true) => return Err(("in_view", Some(request))), + Some(false) => return Err(("in_view_not_found", Some(request))), None => {} } // The reach is located in her thought in this segment: the Interpreter's quote, or failing that the longest run of at diff --git a/crates/mind-body/src/projection/outcome.rs b/crates/mind-body/src/projection/outcome.rs index 742e69e..dc616a9 100644 --- a/crates/mind-body/src/projection/outcome.rs +++ b/crates/mind-body/src/projection/outcome.rs @@ -19,13 +19,159 @@ //! Each row renders in two forms from the one table (map 16.29.10): `told`, her words verbatim, which opens her view (the //! Persona's, never bound by I16.7); and `event`, the same sentence with every quote clause removed, which opens the //! Projector's packet. The Projector sees what came of her intent, never her words or anyone's. +//! +//! That holds by type (map 16.30.3, K46): every text of a record a row carries is `Words`, which only `Form::words` reads, +//! and the event form reads none; a read is named to the Projector by a closed `EventPhrase`, never by its address or +//! search words. use serde_json::Value; +use self::form::{EventPhrase, Form, ReadName, Words}; use super::commit::{How, Needs, Refusal as StateRefusal}; use super::interpret::{GapKind, MAX_LINES, Refusal}; use super::read::{ReadFailure, ReadRefusal, ReadRequest}; -use super::select::{Forms, capitalized, clip, spoken}; +use super::select::{Forms, capitalized}; + +/// Her words in a row, and the forms a row is rendered in (K46). The text a `Words` holds is private to this module, so +/// nothing outside it can format one: a row's sentence asks its `Form` for each slot, and the event form answers none. +mod form { + use super::super::read::ReadRequest; + use super::super::select::{Forms, clip, spoken}; + + /// Words of a record's text: a draft, a line, a passage of her thought, a promise's words. No `Display`, `Deref`, + /// `AsRef` or accessor; its only reader is `Form::words`. + #[derive(Clone, PartialEq, Eq)] + pub(super) struct Words(String); + + impl std::fmt::Debug for Words { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Words({} bytes)", self.0.len()) + } + } + + impl Words { + pub(super) fn new(text: String) -> Self { + Self(text) + } + + /// Whether these words are exactly `text`: `settle`'s check against a receipt, which reads none of them out. + pub(super) fn is(&self, text: &str) -> bool { + self.0 == text + } + } + + /// A repo or a campaign, named to the Projector only when it is in her domain (map 16.30.3). + #[derive(Clone, Debug, PartialEq, Eq)] + pub(super) struct Name(String); + + impl Name { + fn named<'a>(&'a self, domain: &[String]) -> Option<&'a str> { + domain.iter().any(|mine| mine.eq_ignore_ascii_case(&self.0)).then_some(self.0.as_str()) + } + } + + /// What she read, as the Projector is told it: its kind, and for her own repos and campaigns its name. No search + /// words, address or host survive into it. + #[derive(Clone, Debug, PartialEq, Eq)] + pub(super) enum EventPhrase { + WebPage, + RepoListing(Name), + RepoFile(Name), + PullRequest(Name, u32), + Commit(Name), + RepoSearch(Name), + Campaign(Name), + OwnMind, + } + + impl EventPhrase { + fn of(request: &ReadRequest) -> Self { + match request { + ReadRequest::Mind(_) => Self::OwnMind, + ReadRequest::Campaign(slug) => Self::Campaign(Name(slug.clone())), + ReadRequest::Web(_) => Self::WebPage, + ReadRequest::Repo(target) => { + let start = target.find('/').map_or(0, |at| at + 1); + let end = target[start..].find(['/', '#', '@', '?']).map_or(target.len(), |at| start + at); + let (repo, suffix) = (Name(target[..end].to_owned()), &target[end..]); + match suffix.chars().next() { + Some('/') => Self::RepoFile(repo), + Some('@') => Self::Commit(repo), + Some('?') => Self::RepoSearch(repo), + Some('#') => suffix[1..].parse().map_or(Self::RepoListing(repo.clone()), |number| Self::PullRequest(repo, number)), + _ => Self::RepoListing(repo), + } + } + } + } + + fn phrase(&self, her: Forms, domain: &[String]) -> String { + let repo = |name: &Name| name.named(domain).unwrap_or("a GameCult repo").to_owned(); + match self { + Self::WebPage => "a web page".to_owned(), + Self::RepoListing(name) => format!("{} on the forge", repo(name)), + Self::RepoFile(name) => format!("a file in {}", repo(name)), + Self::PullRequest(name, number) => match name.named(domain) { + Some(name) => format!("pull request #{number} in {name}"), + None => "a pull request in a GameCult repo".to_owned(), + }, + Self::Commit(name) => format!("a commit in {}", repo(name)), + Self::RepoSearch(name) => format!("a search of {}", repo(name)), + Self::Campaign(name) => format!("what was ruled lately in {}", name.named(domain).unwrap_or("a campaign")), + Self::OwnMind => format!("{} own mind", her.poss), + } + } + } + + /// A read as a row names it, built once from its request: `told`, code's words for it in her view (none for her own + /// mind, whose words are her pronoun's), and `event`, the Projector's. + #[derive(Clone, Debug, PartialEq, Eq)] + pub(super) struct ReadName { + told: Option, + event: EventPhrase, + } + + impl ReadName { + pub(super) fn of(request: &ReadRequest) -> Self { + Self { told: request.named().map(Words), event: EventPhrase::of(request) } + } + + /// Whether it is a search: it finds things and reads none of them. + pub(super) fn search(&self) -> bool { + matches!(self.event, EventPhrase::RepoSearch(_)) + } + } + + /// The form a row is rendered in: `Told`, her view, her words verbatim and held to a byte count; `Event`, the + /// Projector's, no words at all and each read by its phrase, under her domain; `Report`, what is reported and never + /// shown to anyone, her words raw. + #[derive(Clone, Copy, Debug)] + pub(super) enum Form<'a> { + Told(usize), + Event(&'a [String]), + Report, + } + + impl Form<'_> { + /// A slot's words in this form, or None and the row's sentence without them. + pub(super) fn words(&self, words: &Words) -> Option { + match self { + Self::Told(quote_max) => Some(spoken(&clip(&words.0, *quote_max))), + Self::Report => Some(words.0.clone()), + Self::Event(_) => None, + } + } + + /// What a read was, in this form. + pub(super) fn read(&self, name: &ReadName, her: Forms) -> String { + match (self, &name.told) { + (Self::Event(domain), _) => name.event.phrase(her, domain), + (_, Some(told)) => told.0.clone(), + (_, None) => name.event.phrase(her, &[]), + } + } + } +} /// A line of hers that went out, as the actuator's receipt names it. #[derive(Clone, Debug, PartialEq, Eq)] @@ -40,11 +186,27 @@ pub(crate) struct Posted { /// none of its words (`Sent`), as the echo's own line shows none. #[derive(Clone, Debug, PartialEq, Eq)] enum Quote { - Wrote(String), - Thought(String), + Wrote(Words), + Thought(Words), Sent, } +/// A promise's status as her record shows it, when a close was refused. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Status { + Open, + Blocked, +} + +impl std::fmt::Display for Status { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + Self::Open => "open", + Self::Blocked => "blocked", + }) + } +} + /// Why the actuator did not change a line she meant to add to (B1's refusals; the simulated room's too). #[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Deserialize)] #[serde(rename_all = "snake_case")] @@ -60,20 +222,20 @@ enum EditRefusal { #[derive(Clone, Debug, PartialEq, Eq)] enum Part { /// A posted receipt. - Said { room: String, text: String }, + Said { room: String, text: Words }, /// A posted receipt whose line promises an act she has no way to do: a `missing_affordance` gap naming it (16.20.6). - Promise { room: String, text: String }, - Refused { reason: Refusal, room: Option, text: String }, + Promise { room: String, text: Words }, + Refused { reason: Refusal, room: Option, text: Words }, Gap { kind: GapKind, room: Option, quote: Quote }, /// A draft she did not finish: the turn ended first, or the length limit cut it (`by_limit`, Soul's R6). - Unfinished { room: Option, text: String, by_limit: bool }, + Unfinished { room: Option, text: Words, by_limit: bool }, /// An edited receipt with no refusal: her words were added after a line of hers; `promise` when a /// `missing_affordance` gap names the addition's draft (map 16.21). - Amended { room: String, added: String, promise: bool }, + Amended { room: String, added: Words, promise: bool }, /// An addition that changed nothing: refused by code (None) or by the actuator. - NotAmended { refusal: Option, room: Option, added: String }, + NotAmended { refusal: Option, room: Option, added: Words }, /// A note to Self, recorded in her turn's record: never claimed read. - NoteLeft(String), + NoteLeft(Words), /// A note not left: private, or a second one. NoteRefused(Refusal), Failed, @@ -81,28 +243,38 @@ enum Part { BrokeAfter { room: Option }, /// 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 }, + Closed { how: How, to: String, words: Words, room: String, by: 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 }, + StillOpen { reason: StateRefusal, to: String, words: Words, status: Status, read: Option }, /// A draft she chose not to send (`unsent`, declined): it did not go out, and the thought the Interpreter cited as her /// choice is shown beside it, so a misread decline is a record she can see (map 16.26, 16.29.2). - Declined { room: Option, text: String, thought: String }, + Declined { room: Option, text: Words, thought: Words }, /// A draft code did not send because someone asked her to hold what it carries there (`Held`, map 16.28.5): who asked. /// Their words are in her "Held for others" view, never here (map 16.29.3). `text` is her draft, kept only so that /// `settle` can check it against the receipts (K49); it is never rendered. - HeldFor { room: Option, who: Option, text: String }, + HeldFor { room: Option, who: Option, text: Words }, /// Words of hers a receipt shows in a room a hold covers, from a draft code refused `Held` (K45): a broken hold, told /// so that a leak by any path is a record she sees, never an omission. Who asked; never the words. HoldBroken { room: String, who: Option }, /// 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 }, + Read { what: ReadName }, /// A read that returned nothing, and why, from code's table. - ReadFailed { what: String, failure: ReadFailure }, + ReadFailed { what: ReadName, failure: ReadFailure }, /// A read she reached for that a rule or a cap refused, and why; what it was only when a cap refused it, since a /// read a rule refused was never resolved. - ReadRefused { what: Option, why: ReadRefusal }, + ReadRefused { what: Option, why: ReadRefusal }, +} + +/// A record's text as a row's words, when it has any. +fn words_of(value: &Value) -> Option { + words(value).map(Words::new) +} + +/// A recorded read's request, named as a row names it. +fn read_name(value: &Value) -> Option { + serde_json::from_value::(value.clone()).ok().map(|request| ReadName::of(&request)) } /// What came of her last turn: what she is told, what she is not and why, and the lines that went out. @@ -168,7 +340,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { for refusal in decision["refused"].as_array().into_iter().flatten() { // `Used` and `Duplicate` are the Interpreter naming one draft, or one draft's words, twice: they are not told, as // `NoDraft` is not (they fall to the last arm, and are reported). - match (serde_json::from_value::(refusal["reason"].clone()), words(&refusal["text"])) { + match (serde_json::from_value::(refusal["reason"].clone()), words_of(&refusal["text"])) { (Ok(reason @ (Refusal::Echo | Refusal::OverLines | Refusal::NoRoom | Refusal::NotQuotable | Refusal::SecondAmend)), Some(text)) => outcome.parts.push(Part::Refused { reason, room: room.clone(), text }), (Ok(Refusal::NotAmendable), Some(added)) => outcome.parts.push(Part::NotAmended { refusal: None, room: room.clone(), added }), (Ok(reason @ (Refusal::Private | Refusal::SecondNote)), Some(_)) => outcome.parts.push(Part::NoteRefused(reason)), @@ -183,7 +355,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { } // An amendment is told by the actuator's receipt (`edited`: `{event, refusal}`), never by the decision alone. for amended in decision["amended"].as_array().into_iter().flatten() { - let (Some(at), Some(added)) = (words(&amended["room"]), words(&amended["added"])) else { + let (Some(at), Some(added)) = (words(&amended["room"]), words_of(&amended["added"])) else { outcome.omitted.push(format!("an amendment without its room or words: {amended}")); continue; }; @@ -215,14 +387,14 @@ pub(crate) fn outcome_of(record: &Value) -> Option { } continue; } - let quote = match (gap["from"].as_str(), words(&gap["words"])) { + let quote = match (gap["from"].as_str(), words_of(&gap["words"])) { (Some("draft"), Some(_)) if echoes.contains(&&gap["draft"]) => Some(Quote::Sent), (Some("draft"), Some(text)) => Some(Quote::Wrote(text)), (Some("thought"), Some(text)) => Some(Quote::Thought(text)), _ => None, }; - let sent = match "e { - Some(Quote::Wrote(text)) if kind == GapKind::MissingAffordance => (0..receipts.len()).find(|at| receipts[*at].text == *text && !promised.contains(at)), + let sent = match ("e, words(&gap["words"])) { + (Some(Quote::Wrote(_)), Some(text)) if kind == GapKind::MissingAffordance => (0..receipts.len()).find(|at| receipts[*at].text == text && !promised.contains(at)), _ => None, }; // A promise in a line the decision said and no receipt shows went out: whether it reached the room is unknown, so @@ -231,49 +403,49 @@ pub(crate) fn outcome_of(record: &Value) -> Option { match (quote, sent) { (_, Some(at)) => { promised.push(at); - outcome.parts.push(Part::Promise { room: receipts[at].room.clone(), text: receipts[at].text.clone() }); + outcome.parts.push(Part::Promise { room: receipts[at].room.clone(), text: Words::new(receipts[at].text.clone()) }); } - (Some(Quote::Wrote(text)), None) if kind == GapKind::MissingAffordance && unreceipted(&text) => outcome.omitted.push(format!("a promise in a line said with no receipt that it went out: {}", gap["words"])), + (Some(Quote::Wrote(_)), None) if kind == GapKind::MissingAffordance && words(&gap["words"]).is_some_and(|text| unreceipted(&text)) => outcome.omitted.push(format!("a promise in a line said with no receipt that it went out: {}", gap["words"])), (Some(quote), None) if kind != GapKind::Unresolved => outcome.parts.push(Part::Gap { kind, room: room.clone(), quote }), _ => outcome.omitted.push(format!("a gap she cannot be shown truly (kind {}, from {}): {}", gap["kind"], gap["from"], gap["quote"])), } } for (_, posted) in receipts.iter().enumerate().filter(|(at, _)| !promised.contains(at)) { - outcome.parts.push(Part::Said { room: posted.room.clone(), text: posted.text.clone() }); + outcome.parts.push(Part::Said { room: posted.room.clone(), text: Words::new(posted.text.clone()) }); } // A note is recorded by the record that holds it: the turn's record is Self's inbox. for note in decision["suggestions"].as_array().into_iter().flatten() { - match words(¬e["text"]) { + match words_of(¬e["text"]) { Some(text) => outcome.parts.push(Part::NoteLeft(text)), None => outcome.omitted.push(format!("a note without its words: {note}")), } } // What she read last wake, without its content: what she made of it is in her memories if her commit wrote one. for read in decision["reads"].as_array().into_iter().flatten() { - match (words(&read["what"]), read["ok"].as_bool(), words(&read["quote"]), serde_json::from_value::(read["failure"].clone())) { - (Some(what), Some(true), _, _) => outcome.parts.push(Part::Read { what }), - (Some(what), Some(false), _, Ok(failure)) => outcome.parts.push(Part::ReadFailed { what, failure }), + match (read_name(&read["request"]), read["ok"].as_bool(), serde_json::from_value::(read["failure"].clone())) { + (Some(what), Some(true), _) => outcome.parts.push(Part::Read { what }), + (Some(what), Some(false), Ok(failure)) => outcome.parts.push(Part::ReadFailed { what, failure }), _ => outcome.omitted.push(format!("a read she cannot be told truly: {read}")), } } for refused in decision["read_refused"].as_array().into_iter().flatten() { match serde_json::from_value::(refused["why"].clone()) { - Ok(why) if why.told() => outcome.parts.push(Part::ReadRefused { what: words(&refused["what"]).filter(|_| why.names_what()), why }), + Ok(why) if why.told() => outcome.parts.push(Part::ReadRefused { what: read_name(&refused["request"]).filter(|_| why.names_what()), why }), Ok(_) => outcome.omitted.push(format!("a read refused for the Interpreter's fault, not hers: {refused}")), Err(_) => outcome.omitted.push(format!("a refused read she cannot be told truly: {refused}")), } } - if let Some(text) = words(&decision["unfinished"]) { + if let Some(text) = words_of(&decision["unfinished"]) { outcome.parts.push(Part::Unfinished { room: room.clone(), text, by_limit: false }); } // Each draft the length limit cut off, told as that (Soul's R7 #10: every one, not only the first). - for cut in decision["cut_by_cap"].as_array().into_iter().flatten().filter_map(words) { + for cut in decision["cut_by_cap"].as_array().into_iter().flatten().filter_map(words_of) { outcome.parts.push(Part::Unfinished { room: room.clone(), text: cut, by_limit: true }); } // Each draft she chose not to send, told as not sent with the thought cited as her choice (map 16.26, 16.29.8); 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"] == "declined") { - match (words(&unsent["words"]), words(&unsent["quote"])) { + match (words_of(&unsent["words"]), words_of(&unsent["quote"])) { (Some(text), Some(thought)) => outcome.parts.push(Part::Declined { room: room.clone(), text, thought }), _ => outcome.omitted.push(format!("a declined draft without its words or its thought: {unsent}")), } @@ -281,7 +453,7 @@ pub(crate) fn outcome_of(record: &Value) -> Option { // 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() { - let (Ok(how), Some(words)) = (serde_json::from_value::(done["how"].clone()), words(&done["entry"]["words"])) else { + let (Ok(how), Some(words)) = (serde_json::from_value::(done["how"].clone()), words_of(&done["entry"]["words"])) else { outcome.omitted.push(format!("a close without its kind or words: {done}")); continue; }; @@ -307,11 +479,11 @@ pub(crate) fn outcome_of(record: &Value) -> Option { Some(listed), ) if refused["proposal"]["kind"] == "promise_close" => { let read = match serde_json::from_value::(listed["needs"].clone()) { - Ok(Needs::Read { request }) => Some(request), + Ok(Needs::Read { request }) => Some(ReadName::of(&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 }); + let status = if listed["status"] == "blocked" { Status::Blocked } else { Status::Open }; + outcome.parts.push(Part::StillOpen { reason, to: listed["to_name"].as_str().unwrap_or("the room").to_owned(), words: Words::new(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"])), } @@ -331,14 +503,14 @@ pub(crate) fn outcome_of(record: &Value) -> Option { /// except a held draft, which is told as a broken hold (K45) and reported. Rows that are receipts (`Said`, `Promise`, /// `Amended`) are untouched. fn settle(outcome: &mut Outcome, receipts: &[Posted], record: &Value) { - let added = |room: &str, text: &str| { + let added = |room: &str, text: &Words| { record["interpreter"]["amended"].as_array().into_iter().flatten().any(|amended| { - amended["room"].as_str() == Some(room) && amended["added"].as_str() == Some(text) && record["edited"].as_array().into_iter().flatten().any(|receipt| receipt["event"] == amended["event"] && receipt["refusal"].is_null()) + amended["room"].as_str() == Some(room) && amended["added"].as_str().is_some_and(|added| text.is(added)) && record["edited"].as_array().into_iter().flatten().any(|receipt| receipt["event"] == amended["event"] && receipt["refusal"].is_null()) }) }; - let reached = |room: &str, text: &str| receipts.iter().any(|posted| posted.room == room && posted.text == text) || added(room, text); + let reached = |room: &str, text: &Words| receipts.iter().any(|posted| posted.room == room && text.is(&posted.text)) || added(room, text); for part in std::mem::take(&mut outcome.parts) { - let Some((room, text)) = part.own_words().and_then(|(room, text)| room.filter(|room| reached(room, text)).map(|room| (room.to_owned(), text.to_owned()))) else { + let Some((room, text)) = part.own_words().and_then(|(room, text)| room.filter(|room| reached(room, text)).map(|room| (room.to_owned(), Form::Report.words(text).unwrap_or_default()))) else { outcome.parts.push(part); continue; }; @@ -365,7 +537,7 @@ fn lines_word() -> String { impl Part { /// The words of hers this row says did not reach its room, and that room (K49): what `settle` checks against the /// receipts. None for a row that is a receipt, or that carries no words of hers. - fn own_words(&self) -> Option<(Option<&str>, &str)> { + fn own_words(&self) -> Option<(Option<&str>, &Words)> { match self { Self::Refused { room, text, .. } | Self::Unfinished { room, text, .. } | Self::Declined { room, text, .. } | Self::HeldFor { room, text, .. } => Some((room.as_deref(), text)), Self::Gap { room, quote: Quote::Wrote(text), .. } => Some((room.as_deref(), text)), @@ -401,21 +573,22 @@ impl Part { /// What reached the room, from the part's receipt alone (16.20.5, I16.10): "{Room} has …" only where a receipt says a /// line went out or was added to, a note only where the record holds it, and otherwise what reached no one. No other - /// clause of a line says what reached the room. `quoted` is the form's: her words verbatim (`told`), or None and the - /// row's sentence without them (`event`). Each row writes both, so no sentence has a second author (map 16.29.10). - fn reached(&self, her: Forms, quoted: &dyn Fn(&str) -> Option) -> String { + /// clause of a line says what reached the room. Each slot of words is the form's (K46): her words verbatim (`Told`), or + /// None and the row's sentence without them (`Event`). Each row writes both, so no sentence has a second author (map + /// 16.29.10). + fn reached(&self, her: Forms, form: Form) -> String { let Forms { subj, cap_subj, obj, poss, .. } = her; let place = |room: &Option| room.clone().unwrap_or_else(|| "the room".to_owned()); match self { - Self::Said { room, text } | Self::Promise { room, text } => match quoted(text) { + Self::Said { room, text } | Self::Promise { room, text } => match form.words(text) { Some(quote) => format!("{} has, from {obj}: {quote}.", capitalized(room)), None => format!("{} has a line from {obj}.", capitalized(room)), }, - Self::Amended { room, added, .. } => match quoted(added) { + Self::Amended { room, added, .. } => match form.words(added) { Some(quote) => format!("{} has {poss} line, now ending with: {quote}.", capitalized(room)), None => format!("{} has {poss} line, now added to.", capitalized(room)), }, - Self::NoteLeft(text) => match quoted(text) { + Self::NoteLeft(text) => match form.words(text) { Some(quote) => format!("{cap_subj} left Self a note: {quote}."), None => format!("{cap_subj} left Self a note."), }, @@ -431,41 +604,41 @@ impl Part { Self::NoteRefused(_) => "No note was left:".to_owned(), Self::Failed => format!("Nothing reached the room, and nothing {subj} meant last time happened:"), Self::BrokeAfter { room } => format!("Nothing more reached {}:", place(room)), - Self::Closed { how: How::Released, by, to, words, .. } => match quoted(words) { + Self::Closed { how: How::Released, by, to, words, .. } => match form.words(words) { Some(quote) => format!("{by} let {obj} off {poss} promise: {quote}."), None => format!("{by} let {obj} off {poss} promise to {to}."), }, - Self::Closed { to, words, .. } => match quoted(words) { + Self::Closed { to, words, .. } => match form.words(words) { Some(quote) => format!("{} promise to {to}, {quote}, is closed:", capitalized(poss)), None => format!("{} promise to {to} is closed:", capitalized(poss)), }, - Self::StillOpen { to, words, status, .. } => match quoted(words) { + Self::StillOpen { to, words, status, .. } => match form.words(words) { Some(quote) => format!("{} record still shows {poss} promise to {to}, {quote}, {status}:", capitalized(poss)), None => format!("{} record still shows {poss} promise to {to} as {status}:", capitalized(poss)), }, - 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."), - Self::ReadRefused { what: Some(what), why: ReadRefusal::InViewNotFound } => format!("{cap_subj} already looked for {what} earlier in this conversation, and it was not there."), - Self::ReadRefused { what: Some(what), .. } => format!("{cap_subj} reached for {what} and it was not read:"), + Self::Read { what } => format!("{cap_subj} read {}.", form.read(what, her)), + Self::ReadFailed { what, .. } => format!("{cap_subj} reached for {} and could not read it:", form.read(what, her)), + Self::ReadRefused { what: Some(what), why: ReadRefusal::InView } => format!("{cap_subj} already read {} earlier in this conversation.", form.read(what, her)), + Self::ReadRefused { what: Some(what), why: ReadRefusal::InViewNotFound } => format!("{cap_subj} already looked for {} earlier in this conversation, and it was not there.", form.read(what, her)), + Self::ReadRefused { what: Some(what), .. } => format!("{cap_subj} reached for {} and it was not read:", form.read(what, her)), Self::ReadRefused { what: None, .. } => format!("{cap_subj} reached for something to read and it was not read:"), } } /// Why, and what will not happen by itself (16.20.5), from the part's typed reason: never a word about what reached /// the room, which is `reached`'s alone. A quote clause is the told form's only; the event form drops it whole. - fn rest(&self, her: Forms, quoted: &dyn Fn(&str) -> Option) -> String { + fn rest(&self, her: Forms, form: Form) -> String { let Forms { subj, cap_subj, obj, poss, has, s, .. } = her; // Her words as a clause of their own, with its leading space; nothing in the event form. let shown = |quote: &Quote| match quote { - Quote::Wrote(text) => quoted(text).map(|quote| format!(" {cap_subj} wrote: {quote}.")).unwrap_or_default(), - Quote::Thought(text) => quoted(text).map(|quote| format!(" In {poss} thought: {quote}.")).unwrap_or_default(), + Quote::Wrote(text) => form.words(text).map(|quote| format!(" {cap_subj} wrote: {quote}.")).unwrap_or_default(), + Quote::Thought(text) => form.words(text).map(|quote| format!(" In {poss} thought: {quote}.")).unwrap_or_default(), Quote::Sent => format!(" What {subj} wrote was mostly the words {subj} had just been sent."), }; - let wrote = |text: &str| shown(&Quote::Wrote(text.to_owned())); + let wrote = |text: &Words| shown(&Quote::Wrote(text.clone())); // A draft gap's words follow its sentence after a colon; a passage of her thought is shown as her thought. let after = |sentence: String, quote: &Quote| match quote { - Quote::Wrote(text) => match quoted(text) { + Quote::Wrote(text) => match form.words(text) { Some(quote) => format!(" {sentence}: {quote}."), None => format!(" {sentence}."), }, @@ -478,7 +651,7 @@ impl Part { Self::Promise { .. } => format!(" It promises something {subj} {has} no way to do, now or later, and it will not happen by itself. The line stands as {subj} wrote it; {subj} can add to it."), Self::NoteLeft(_) => format!(" It waits in Self's inbox until Self reads it; nothing tells {obj} when, and nothing in it happens by itself."), Self::Refused { reason: Refusal::Echo, .. } => format!(" What {subj} wrote was mostly the words {subj} had just been sent, so none of it was sent."), - Self::Refused { reason: Refusal::NoRoom, text, .. } => match quoted(text) { + Self::Refused { reason: Refusal::NoRoom, text, .. } => match form.words(text) { Some(quote) => format!(" That turn had no room for {obj} to speak in, so it was not sent: {quote}."), None => format!(" That turn had no room for {obj} to speak in, so it was not sent."), }, @@ -517,8 +690,8 @@ impl Part { 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) if read.search() => format!(" keeping it needs {obj} to read what {} finds, and a search reads none of what it finds, so it was not kept.", read.what(her)), - 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)), + Some(read) if read.search() => format!(" keeping it needs {obj} to read what {} finds, and a search reads none of what it finds, so it was not kept.", form.read(read, her)), + 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.", form.read(read, 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."), @@ -536,15 +709,16 @@ impl Part { /// of hers verbatim, held to `quote_max` bytes. She reads it in her view, which I16.7 does not bind: she already reads /// every word said to her. fn told(&self, her: Forms, quote_max: usize) -> String { - let quoted = |text: &str| Some(spoken(&clip(text, quote_max))); - format!("- {}{}", self.reached(her, "ed), self.rest(her, "ed)) + let form = Form::Told(quote_max); + format!("- {}{}", self.reached(her, form), self.rest(her, form)) } /// The Projector's form (map 16.29.10): the same row with its quote clauses removed, as code's sentence. It carries no - /// quoted text, so no one's words reach the Projector through her outcome (I16.7, by construction). - fn event(&self, her: Forms) -> String { - let quoted = |_: &str| None; - format!("- {}{}", self.reached(her, "ed), self.rest(her, "ed)) + /// quoted text, so no one's words reach the Projector through her outcome (I16.7, by type, K46): `Form::Event` reads + /// no `Words`, and names a read by its phrase, a repo or campaign only when it is in her `domain`. + fn event(&self, her: Forms, domain: &[String]) -> String { + let form = Form::Event(domain); + format!("- {}{}", self.reached(her, form), self.rest(her, form)) } } @@ -559,9 +733,10 @@ impl Outcome { self.parts[at].told(her, quote_max) } - /// The `at`th line in the Projector's form: no quote. - pub(crate) fn event(&self, at: usize, her: Forms) -> String { - self.parts[at].event(her) + /// The `at`th line in the Projector's form: no words, and a read named only by its kind and, when it is in her + /// `domain` (repo and campaign names), its name. + pub(crate) fn event(&self, at: usize, her: Forms, domain: &[String]) -> String { + self.parts[at].event(her, domain) } /// Every line she is told, whole: the report's. diff --git a/crates/mind-body/src/projection/outcome/tests.rs b/crates/mind-body/src/projection/outcome/tests.rs index cd0c720..d334ee0 100644 --- a/crates/mind-body/src/projection/outcome/tests.rs +++ b/crates/mind-body/src/projection/outcome/tests.rs @@ -238,14 +238,12 @@ fn every_row() -> Vec { fn i16_10_every_lines_first_clause_is_what_its_receipt_says_reached_the_room() { let her = packet().forms; let mut rows = 0; - let told = |text: &str| Some(spoken(text)); - let event = |_: &str| -> Option { None }; for record in every_row() { let outcome = outcome_of(&record).unwrap(); for part in &outcome.parts { - for (form, quoted) in [("told", &told as &dyn Fn(&str) -> Option), ("event", &event)] { - let (reached, rest) = (part.reached(her, quoted), part.rest(her, quoted)); - let line = if form == "told" { part.told(her, usize::MAX) } else { part.event(her) }; + for (form, rendered) in [("told", Form::Told(usize::MAX)), ("event", Form::Event(&[]))] { + let (reached, rest) = (part.reached(her, rendered), part.rest(her, rendered)); + let line = if form == "told" { part.told(her, usize::MAX) } else { part.event(her, &[]) }; assert_eq!(line, format!("- {reached}{rest}"), "{form}: {part:?}"); // "{Room} has" only on a receipt that a line went out or was added to. let receipt = matches!(part, Part::Said { .. } | Part::Promise { .. } | Part::Amended { .. }); @@ -261,30 +259,6 @@ fn i16_10_every_lines_first_clause_is_what_its_receipt_says_reached_the_room() { assert!(rows >= 16, "{rows}"); } -/// K43 (map 16.29.10): one table, two forms. The told form carries her words; the event form is the same row with every -/// quote clause removed, so it holds no quotation and none of her words, and a row with no quote is the same in both. -#[test] -fn k43_every_row_tells_her_words_and_its_event_carries_none() { - for pronouns in ["she/her", "he/him", "any"] { - let her = crate::projection::select::forms(&json!({ "presentation": { "pronouns": pronouns } })); - let mut quoted = 0; - for record in every_row() { - let outcome = outcome_of(&record).unwrap(); - for at in 0..outcome.len() { - let (told, event) = (outcome.told(at, her, usize::MAX), outcome.event(at, her)); - assert!(!event.contains('"') && !event.contains(" ") && !event.contains(" .") && !event.contains("..") && event.ends_with(['.', ':']), "{pronouns}: {event}"); - if told.contains('"') { - quoted += 1; - assert_ne!(told, event, "{pronouns}"); - } else { - assert_eq!(told, event, "{pronouns}: a row with no quote has one form"); - } - } - } - assert!(quoted >= 10, "{pronouns}: {quoted}"); - } -} - #[test] fn no_row_says_as_her_own_recorded_as_queued_or_landed() { for pronouns in ["she/her", "he/him", "any"] { @@ -480,7 +454,7 @@ fn k45_a_broken_hold_is_told() { assert_eq!(broken.lines(packet().forms)[0], "- #minds:gamecult.org has words he wrote that Meta asked him to hold there.", "{:?}", broken.lines(packet().forms)); assert_eq!(broken.hold_broken, [format!("{MINDS}: {text}")]); assert!(!broken.lines(packet().forms).iter().any(|line| line.contains("not sent")), "never told as unsent"); - assert_eq!(broken.event(0, packet().forms), broken.told(0, packet().forms, usize::MAX), "it carries no words of hers or anyone's"); + assert_eq!(broken.event(0, packet().forms, &[]), broken.told(0, packet().forms, usize::MAX), "it carries no words of hers or anyone's"); // Negative: posted elsewhere, the hold is told as held, and nothing is broken. let held = outcome_of(&record(SWARM)).unwrap(); assert!(held.lines(packet().forms).iter().any(|line| line == "- Nothing of this reached #minds:gamecult.org: Meta asked him to hold it, and it was not sent.") && held.hold_broken.is_empty(), "{:?}", held.lines(packet().forms)); @@ -495,3 +469,172 @@ fn k45_a_held_refusal_is_never_omitted_and_told_once_by_its_text() { assert_eq!(outcome.len(), 2, "{:?}", outcome.lines(packet().forms)); assert!(outcome.omitted.is_empty(), "{:?}", outcome.omitted); } + +// --------------------------------------------------------------------------------------------- +// K46 (map 16.30.3): the Projector's outcome line has no text slot. + +/// The kind of a part, by an exhaustive match with no wildcard: a new variant of `Part` fails to compile here until it is +/// named, and `k46_every_part_has_an_event_without_its_words` then fails until `fixtures` lists it. +fn variant(part: &Part) -> &'static str { + match part { + Part::Said { .. } => "said", + Part::Promise { .. } => "promise", + Part::Refused { .. } => "refused", + Part::Gap { .. } => "gap", + Part::Unfinished { .. } => "unfinished", + Part::Amended { .. } => "amended", + Part::NotAmended { .. } => "not_amended", + Part::NoteLeft(_) => "note_left", + Part::NoteRefused(_) => "note_refused", + Part::Failed => "failed", + Part::BrokeAfter { .. } => "broke_after", + Part::Closed { .. } => "closed", + Part::StillOpen { .. } => "still_open", + Part::Declined { .. } => "declined", + Part::HeldFor { .. } => "held_for", + Part::HoldBroken { .. } => "hold_broken", + Part::Read { .. } => "read", + Part::ReadFailed { .. } => "read_failed", + Part::ReadRefused { .. } => "read_refused", + } +} + +const VARIANTS: usize = 19; + +/// Every row kind, and every arm that renders a different sentence, with `s` in every text of a record it carries and in +/// every read's target; and whether her told form shows those words (an echo, a held draft, a pull request or commit +/// read and a read of her own mind show none, by design). +fn fixtures(s: &str) -> Vec<(Part, bool)> { + let w = || Words::new(format!("{s} at the door")); + let room = || Some(MINDS.to_owned()); + let web = || ReadName::of(&ReadRequest::Web(format!("https://example.org/{s}"))); + let search = || ReadName::of(&ReadRequest::Repo(format!("GameCult/Bifrost?q={s} plover"))); + let mut out: Vec<(Part, bool)> = vec![(Part::Said { room: MINDS.into(), text: w() }, true), (Part::Promise { room: MINDS.into(), text: w() }, true)]; + for reason in [Refusal::OverLines, Refusal::NoRoom, Refusal::NotQuotable, Refusal::SecondAmend] { + out.push((Part::Refused { reason, room: room(), text: w() }, true)); + } + out.push((Part::Refused { reason: Refusal::Echo, room: room(), text: w() }, false)); + for kind in [GapKind::Addressee, GapKind::Elsewhere, GapKind::MissingAffordance, GapKind::Unwritten] { + out.push((Part::Gap { kind, room: room(), quote: Quote::Wrote(w()) }, true)); + out.push((Part::Gap { kind, room: room(), quote: Quote::Thought(w()) }, true)); + } + out.push((Part::Gap { kind: GapKind::Addressee, room: room(), quote: Quote::Sent }, false)); + for by_limit in [false, true] { + out.push((Part::Unfinished { room: room(), text: w(), by_limit }, true)); + } + for promise in [false, true] { + out.push((Part::Amended { room: MINDS.into(), added: w(), promise }, true)); + } + for refusal in [None, Some(EditRefusal::NotFound), Some(EditRefusal::NotHers), Some(EditRefusal::TooLong)] { + out.push((Part::NotAmended { refusal, room: room(), added: w() }, true)); + } + out.push((Part::NoteLeft(w()), true)); + out.push((Part::NoteRefused(Refusal::Private), false)); + out.push((Part::NoteRefused(Refusal::SecondNote), false)); + out.push((Part::Failed, false)); + out.push((Part::BrokeAfter { room: room() }, false)); + for how in [How::Kept, How::Withdrawn, How::Released] { + out.push((Part::Closed { how, to: "Meta".into(), words: w(), room: MINDS.into(), by: "Meta".into() }, true)); + } + for (reason, read) in [ + (StateRefusal::DraftNotSent, None), + (StateRefusal::BlockedNotKeepable, None), + (StateRefusal::ReleaseNotByPromisee, None), + (StateRefusal::ReleaseBeforePromise, None), + (StateRefusal::CloseContradicted, None), + (StateRefusal::CloseUnquoted, None), + (StateRefusal::NeedsUnread, Some(search())), + (StateRefusal::NeedsUnread, Some(web())), + (StateRefusal::NeedsUnread, None), + (StateRefusal::NeedsMalformed, None), + (StateRefusal::NotWherePromised, None), + (StateRefusal::OutsidePutChanged, None), + ] { + for status in [Status::Open, Status::Blocked] { + out.push((Part::StillOpen { reason, to: "Meta".into(), words: w(), status, read: read.clone() }, true)); + } + } + out.push((Part::Declined { room: room(), text: w(), thought: w() }, true)); + out.push((Part::HeldFor { room: room(), who: Some("Meta".into()), text: w() }, false)); + out.push((Part::HoldBroken { room: MINDS.into(), who: Some("Meta".into()) }, false)); + for (request, shows) in [ + (ReadRequest::Web(format!("https://example.org/{s}")), true), + (ReadRequest::Repo(format!("GameCult/Bifrost?q={s} plover")), true), + (ReadRequest::Repo(format!("GameCult/Bifrost/docs/{s}.md")), true), + (ReadRequest::Repo("GameCult/Bifrost#85".into()), false), + (ReadRequest::Repo("GameCult/Bifrost@abc1234".into()), false), + (ReadRequest::Repo(format!("GameCult/{s}")), true), + (ReadRequest::Campaign(s.to_owned()), true), + (ReadRequest::Mind(format!("{s} words")), false), + ] { + out.push((Part::Read { what: ReadName::of(&request) }, shows)); + } + out.push((Part::ReadFailed { what: web(), failure: ReadFailure::NotFound }, true)); + for why in [ReadRefusal::InView, ReadRefusal::InViewNotFound, ReadRefusal::ReadsPerWake] { + out.push((Part::ReadRefused { what: Some(search()), why }, true)); + } + out.push((Part::ReadRefused { what: None, why: ReadRefusal::WebAddressNotInFrontOfHer }, false)); + out +} + +/// K46: every part's event is free of the sentinel its record's texts and read targets carry, and its told form shows it +/// wherever the row shows her words. This replaces `k43_every_row_tells_her_words_and_its_event_carries_none`, and keeps +/// its check that an event is a whole sentence with no quote left in it. +#[test] +fn k46_every_part_has_an_event_without_its_words() { + const S: &str = "ospreyledger"; + let parts = fixtures(S); + let kinds: std::collections::BTreeSet<&str> = parts.iter().map(|(part, _)| variant(part)).collect(); + assert_eq!(kinds.len(), VARIANTS, "fixtures lists every variant: {kinds:?}"); + for pronouns in ["she/her", "he/him", "any"] { + let her = crate::projection::select::forms(&json!({ "presentation": { "pronouns": pronouns } })); + for (part, shows) in &parts { + let (told, event) = (part.told(her, usize::MAX), part.event(her, &[])); + assert!(!event.to_lowercase().contains(S), "{pronouns}: {part:?}: {event}"); + assert!(!event.contains('"') && !event.contains(" ") && !event.contains(" .") && !event.contains("..") && event.ends_with(['.', ':']), "{pronouns}: {event}"); + assert!(!event.contains("example.org") && !event.contains("plover") && !event.contains("Bifrost"), "{pronouns}: no address, search word or repo outside her domain: {event}"); + assert_eq!(told.contains(S), *shows, "{pronouns}: {part:?}: {told}"); + } + } + // Her own repos and campaigns are named to the Projector, and only hers. + let her = packet().forms; + let read = |request: ReadRequest| Part::Read { what: ReadName::of(&request) }; + let repo = |target: &str| read(ReadRequest::Repo(target.into())); + let domain = ["GameCult/Bifrost".to_owned(), "a-campaign".to_owned()]; + assert_eq!(repo(&format!("GameCult/Bifrost?q={S} plover")).event(her, &domain), "- He read a search of GameCult/Bifrost."); + assert_eq!(repo(&format!("GameCult/bifrost/docs/{S}.md")).event(her, &domain), "- He read a file in GameCult/bifrost."); + assert_eq!(repo("GameCult/Bifrost#85").event(her, &domain), "- He read pull request #85 in GameCult/Bifrost."); + assert_eq!(repo("GameCult/Bifrost#85").event(her, &[]), "- He read a pull request in a GameCult repo."); + assert_eq!(repo("GameCult/Bifrost").event(her, &domain), "- He read GameCult/Bifrost on the forge."); + assert_eq!(repo(&format!("GameCult/{S}")).event(her, &domain), "- He read a GameCult repo on the forge."); + assert_eq!(read(ReadRequest::Campaign("a-campaign".into())).event(her, &domain), "- He read what was ruled lately in a-campaign."); + assert_eq!(read(ReadRequest::Campaign("b-campaign".into())).event(her, &domain), "- He read what was ruled lately in a campaign."); + assert_eq!(read(ReadRequest::Mind("the kettle".into())).event(her, &domain), "- He read his own mind."); +} + +/// K46: `Words` has no `Display`, `AsRef` or `Deref`, so no format string and no `&str` borrow reads one; only +/// `Form::words` does. Checked when this module compiles, as `static_assertions::assert_not_impl_any!` does: a probe trait +/// is implemented twice for a type that has the trait, so its `_` cannot be inferred and the module does not compile. (A +/// `compile_fail` doctest cannot name a private type, so it would pass for the wrong reason.) +#[test] +fn k46_words_cannot_be_formatted_or_borrowed_as_text() { + trait NotDisplay { + fn probe() {} + } + impl NotDisplay<()> for T {} + impl NotDisplay for T {} + let () = >::probe(); + trait NotAsStr { + fn probe() {} + } + impl NotAsStr<()> for T {} + impl> NotAsStr for T {} + let () = >::probe(); + trait NotDeref { + fn probe() {} + } + impl NotDeref<()> for T {} + impl NotDeref for T {} + let () = >::probe(); + assert_eq!(format!("{:?}", Words::new("ospreyledger".into())), "Words(12 bytes)", "its Debug shows no words either"); +} diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index f7c54ae..bf50685 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -113,14 +113,20 @@ impl ReadRequest { /// What she read, in code's words for her outcome and her bridge: never a model's words (a recall's query is the /// Interpreter's, so it is not repeated). pub(crate) fn what(&self, her: Forms) -> String { + self.named().unwrap_or_else(|| format!("{} own mind", her.poss)) + } + + /// `what`, for every read but one of her own mind, whose words are her pronoun's: what her outcome's told form names + /// it by (`outcome::ReadName`). + pub(crate) fn named(&self) -> Option { match self { - Self::Mind(_) => format!("{} own mind", her.poss), - Self::Campaign(slug) => format!("what was ruled lately in {slug}"), - Self::Repo(target) => match target.split_once("?q=") { + Self::Mind(_) => None, + Self::Campaign(slug) => Some(format!("what was ruled lately in {slug}")), + Self::Repo(target) => Some(match target.split_once("?q=") { Some((repo, words)) => format!("a search of {repo} for {}", spoken(words.trim())), None => format!("{target} on the forge"), - }, - Self::Web(url) => url.clone(), + }), + Self::Web(url) => Some(url.clone()), } } } diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index 5bafe49..ea0837b 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -2209,7 +2209,11 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { if let Some(outcome) = &inputs.history.last { let heading = Section::Outcome.heading(her); let room = tuning.select.outcome_bytes.saturating_sub(heading.len()); - let events = guarded_outcome(outcome.len(), &|at, _| outcome.event(at, her), room, her); + // Her domain's repos and campaigns: the only ones the Projector is told a read by name (K46). + let domain: Vec = inputs.domain.into_iter().flat_map(|digest| &digest.items).map(|item| match &item.about { + About::Repo(name) | About::Campaign(name) => name.clone(), + }).collect(); + let events = guarded_outcome(outcome.len(), &|at, _| outcome.event(at, her, &domain), room, her); for line in events.lines { context.force(Section::Outcome, line); } diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 5c2212c..23c431c 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -2172,6 +2172,53 @@ fn k43_sentinel_never_reaches_the_projector() { assert!(persona.contains(block), "her view reaches her: {persona}"); } +/// K46 (map 16.30.3): Soul's P6 replayed with its assertion inverted. Words said to her reached the Projector through a +/// read's `what` in her outcome's event form: a search's words, a web address, a refused read, a need's read. Each read +/// is now named to the Projector by its kind, and a repo by name only when it is in her domain. +#[test] +fn k46_p6_no_read_carries_words_to_the_projector() { + use crate::projection::read::ReadRequest; + const SW: &str = "#swarm:gamecult.org"; + let her = select::forms(&state()); + let search = ReadRequest::Repo("GameCult/Bifrost?q=quartzheron plover".into()); + let web = ReadRequest::Web("https://example.org/osprey-ledger-secret".into()); + let capped = ReadRequest::Web("https://example.org/gannet-key-under-mat".into()); + let need = ReadRequest::Repo("GameCult/Bifrost?q=kestrel passphrase".into()); + let record = json!({ + "interpreter": { + "room": SW, "said": [], "refused": [], "gaps": [], + "reads": [{ "what": search.what(her), "ok": true, "request": search }, { "what": web.what(her), "ok": false, "failure": "not_found", "request": web }], + "read_refused": [{ "why": "reads_per_wake", "what": capped.what(her), "read": { "kind": "web", "target": "https://example.org/gannet-key-under-mat" }, "request": capped }], + "promises": [{ "id": "c1", "status": "open", "to_name": "Meta", "words": "I'll look it up.", "needs": { "kind": "read", "request": need } }], + }, + "posted": [], + "committed": { "closed": [], "refused": [{ "reason": "needs_unread", "proposal": { "kind": "promise_close", "promise": "c1" } }] }, + }); + let room = Room { messages: vec![message(SW, OPERATOR, "Meta", "Eureka, search Bifrost for quartzheron plover and kestrel passphrase, and read https://example.org/osprey-ledger-secret and https://example.org/gannet-key-under-mat", 2, true)], here: Some(SW.into()), ..Room::default() }; + let words = ["quartzheron", "plover", "osprey-ledger-secret", "gannet-key-under-mat", "kestrel", "passphrase", "example.org"]; + let history = with_last(&record); + let packet = packet_of(TurnKind::Chat, &state(), &room, &history, 1); + let projector = narrate::projector_prompt(&packet, &Tuning::default()); + let leaked: Vec<&str> = words.into_iter().filter(|word| projector.contains(word)).collect(); + assert!(leaked.is_empty(), "{leaked:?}: {projector}"); + let events = outcome_events(&packet); + for event in ["- She reached for a web page and could not read it: it is not there.", "- She read a search of a GameCult repo."] { + assert!(events.contains(&event), "{event}: {events:?}"); + } + assert!(events.iter().any(|event| event.contains("keeping it needs her to read what a search of a GameCult repo finds")), "{events:?}"); + // Her view still names each read in code's words, the search's words included. + let block = outcome_block(&packet); + assert!(block.contains("a search of GameCult/Bifrost for \"quartzheron plover\"") && block.contains("https://example.org/osprey-ledger-secret"), "{block}"); + // With Bifrost in her domain, the Projector is told the repo by name, and still none of the words. + let digest = domain::Digest { since: now() - chrono::Duration::days(2), last_look: None, now: now(), items: vec![domain::Item { at: now() - chrono::Duration::hours(1), text: "- GameCult/Bifrost: merged \"Passkeys\", opened by kiko".into(), about: domain::About::Repo("GameCult/Bifrost".into()) }] }; + let (operators, minds) = (operators(), minds()); + let inputs = Inputs { kind: TurnKind::Chat, state: &state(), room: &room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: Some(&digest), exchange: None }; + let mine = select(&inputs, &Tuning::default()); + let projector = narrate::projector_prompt(&mine, &Tuning::default()); + assert!(outcome_events(&mine).contains(&"- She read a search of GameCult/Bifrost."), "{:?}", outcome_events(&mine)); + assert!(words.iter().all(|word| !projector.contains(word)), "{projector}"); +} + /// Soul's GANNET probe at 0cfc386: last turn Libby told her a secret, her draft repeating it was refused as an echo, and a /// gap named that draft. This turn the words are only an earlier line, which the Projector never sees; nor may her /// outcome carry them, whatever gap names the draft.