From 34aeea6fe0addc0b3b9922e3c5b76408c773f2f8 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 21 Nov 2026 01:34:04 +0100 Subject: [PATCH] Reads: a located span anchors a read only where its sentence names what is read (repo, pull request, domain item, address, recall words, or a direct reference); a common run alone is not located, refused untold (Soul's R6) Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/interpret.rs | 64 ++++++++++++++++--- .../src/projection/interpret/tests.rs | 14 ++++ 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 475931c..034c023 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -42,7 +42,7 @@ use serde_json::{Value, json}; use super::Affordance; use super::commit::{Evidence, How, Proposal}; -use super::read::{Asked, QUOTE_MIN_WORDS, SPAN_MIN_WORDS, resolve}; +use super::read::{Asked, Kind, QUOTE_MIN_WORDS, ReadRequest, SPAN_MIN_WORDS, resolve}; use super::narrate::{Model, heard_overlap, lived_stream, words}; use super::select::{Forms, Packet, capitalized, spoken, turn_words, voiced}; use super::tuning::Tuning; @@ -712,27 +712,75 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake return Err("no_read_here"); } let asked: Asked = serde_json::from_value(raw.clone()).map_err(|_| "not_the_contract")?; + // 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. + let reached: Vec = packet.bodies.iter().cloned().chain(std::iter::once(packet.heard.clone())).collect(); + let request = resolve(&asked, packet, prose, &reached)?; // The reach is located in her thought in this segment: the Interpreter's quote, or failing that the longest run of at - // least `SPAN_MIN_WORDS` of its words found there (Soul's R5: a short or loose quote is the Interpreter's fault, not - // hers). When nothing of it is found, the read is refused, reported, and never told to her. + // least `SPAN_MIN_WORDS` of its words found there (Soul's R5), and only where the sentence it stands in names what is + // read: its repo, pull request, domain item, address or recall words, or a direct reference to it. A common run alone + // ("I want to") anchors nothing (Soul's R6). When nothing locates, the read is refused, reported, and never told to her. + let names = target_words(&asked, &request, packet); let quote: Vec<&str> = asked.quote.split_whitespace().collect(); let locate = |text: &str| { found.thought(prose).into_iter().filter(|(_, end)| *end > wake.from).find_map(|(start, end)| { let start = start.max(wake.from); - SourceSpan::locate(&prose[start..end], text).map(|span| prose[start + span.start_byte()..start + span.end_byte()].to_owned()) + SourceSpan::locate(&prose[start..end], text) + .map(|span| (start + span.start_byte(), start + span.end_byte())) + .filter(|(at, to)| names_target(sentence_around(prose, *at, *to), &names)) + .map(|(at, to)| prose[at..to].to_owned()) }) }; let whole = (quote.len() >= QUOTE_MIN_WORDS).then(|| locate("e.join(" "))).flatten(); let located = whole .or_else(|| (SPAN_MIN_WORDS..=quote.len()).rev().find_map(|size| quote.windows(size).find_map(|span| locate(&span.join(" "))))) .ok_or("quote_not_located")?; - // 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. - let reached: Vec = packet.bodies.iter().cloned().chain(std::iter::once(packet.heard.clone())).collect(); - let request = resolve(&asked, packet, prose, &reached)?; Ok(json!({ "kind": asked.kind, "target": asked.target.trim(), "request": request, "what": request.what(packet.forms), "quote": located })) } +/// The words that name what a read reads (Soul's R6): a repo's name, a pull request's number, a file's name; a domain +/// item's repo or campaign, its title's words and who opened it; an address and its host; a recall's words. Lowercase. +fn target_words(asked: &Asked, request: &ReadRequest, packet: &Packet) -> Vec { + let long = |text: &str| -> Vec { text.split(|c: char| !c.is_alphanumeric()).filter(|word| word.chars().count() >= 4).map(str::to_lowercase).collect() }; + let mut names = match request { + ReadRequest::Repo(target) => { + let rest = target.trim_start_matches("GameCult/"); + let mut words: Vec = rest.split(['/', '#', '@']).filter(|part| !part.is_empty()).map(str::to_lowercase).collect(); + words.push(target.to_lowercase()); + words + } + ReadRequest::Campaign(slug) => std::iter::once(slug.to_lowercase()).chain(long(slug)).collect(), + ReadRequest::Web(url) => std::iter::once(url.to_lowercase()).chain(url.split("://").nth(1).and_then(|rest| rest.split('/').next()).map(str::to_lowercase)).collect(), + ReadRequest::Mind(words) => long(words), + }; + if asked.kind == Kind::Domain + && let Some(line) = packet.domain.iter().find(|line| line.id == asked.target.trim()) + { + let title = line.line.split('"').nth(1).unwrap_or_default(); + names.extend(long(title)); + names.extend(line.line.split("opened by ").nth(1).map(str::to_lowercase)); + } + names +} + +/// The sentence of `prose` that holds the span `at..to`: back to the last sentence end or line break before it, on to the +/// next after it. +fn sentence_around(prose: &str, at: usize, to: usize) -> &str { + let ends = |c: char| matches!(c, '.' | '!' | '?' | '\n'); + let start = prose[..at].rfind(ends).map_or(0, |end| end + 1); + let stop = prose[to..].find(ends).map_or(prose.len(), |end| to + end + 1); + &prose[start..stop] +} + +/// Whether a sentence names what is read: one of its words, or a direct reference to a thing that can be read. +fn names_target(sentence: &str, names: &[String]) -> bool { + const REFERENCES: [&str; 8] = ["link", "page", "diff", "file", "repo", "commit", "pr", "address"]; + let lower = sentence.to_lowercase(); + let tokens: Vec<&str> = lower.split(|c: char| !c.is_alphanumeric()).filter(|word| !word.is_empty()).collect(); + names.iter().any(|name| if name.contains(|c: char| !c.is_alphanumeric()) { lower.contains(name.as_str()) } else { tokens.contains(&name.as_str()) }) + || tokens.iter().any(|word| REFERENCES.contains(word)) +} + /// What she can read and how the Interpreter names it (map 16.22.3), only on a turn that can read. fn read_frame(her: Forms) -> String { let Forms { subj, obj, poss, s, .. } = her; diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 7ce1503..bf6df77 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -862,3 +862,17 @@ fn r5_a_loose_quote_is_located_and_an_interpreter_fault_is_never_hers() { let outcome = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": [] })).unwrap(); assert!(outcome.lines(packet().forms).is_empty() && outcome.omitted.len() == 2, "reported, never told: {:?}", outcome.omitted); } + +/// Soul's R6: a common run of words ("I want to") anchors no read her thought never reached for. The located span's +/// sentence must name what is read; when none does, the read is refused as not located, and never told to her. +#[test] +fn r6_a_read_is_anchored_only_where_her_thought_names_it() { + let reading = reading_packet(); + let still = "I want to sit with this a while. Nothing else tonight."; + for (kind, target) in [("repo", "GameCult/Bifrost"), ("mind", "Bifrost merge pages"), ("domain", "d1")] { + let decision = asked(&reading, still, json!({ "kind": kind, "target": target, "quote": "I want to look at the Bifrost merge" })); + assert_eq!((decision["read"].clone(), decision["read_refused"][0]["why"].as_str()), (Value::Null, Some("quote_not_located")), "{kind}: {decision}"); + } + let named = asked(&reading, "I want to see what Nibu changed in Lodur.", json!({ "kind": "domain", "target": "d1", "quote": "I want to see what" })); + assert_eq!(named["read"]["quote"], "I want to see what", "{named}"); +}