From 362753123b1caf0917dce3bbf034ed02ee0092df Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 21 Nov 2026 03:20:01 +0100 Subject: [PATCH] Persona anchors: a domain item by two title words, a generic word only for the one thing there, a recall by two content words Soul's R8 item 3. - A domain item anchors only where her sentence carries at least two content words of its title; stopwords ("with" among them) never count. Its repo name and opener no longer anchor it. - A word that only refers ("that page") anchors a read only when exactly one target of the read's kind is in front of her and the read is that target, so with one domain line in view it anchors that line's own target and nothing else. - The stopword list gains the light verbs and fillers a thought reaches with, so a recall like "want to sit" has no content words and is refused. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/interpret.rs | 73 ++++++++++++------- .../src/projection/interpret/tests.rs | 32 ++++++-- crates/mind-body/src/projection/read.rs | 15 +++- 3 files changed, 84 insertions(+), 36 deletions(-) diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index 41b2223..d70d048 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -760,17 +760,34 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake // 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 names = target_words(&request); // A word that only refers ("the page", "that diff") anchors a read only when one thing of its kind is in front of her - // (Soul's R7): with two pages there, "the page" names neither. - let generic = targets_in_view(&request, packet, prose, &reached) == 1; + // and that thing is what is read (Soul's R7, R8): with two pages there, "the page" names neither, and with one domain + // line there it names that line's own target and nothing else. + let in_view = targets_in_view(&request, packet, prose, &reached); + let generic = in_view.len() == 1 && in_view.contains(&request.normal()); + // A domain item is named by its title (Soul's R8): at least two of the title's words that carry content, in the + // sentence; a stopword such as "with" never counts. + let title: Option> = (asked.kind == Kind::Domain).then(|| { + let line = packet.domain.iter().find(|line| line.id == asked.target.trim()).map_or("", |line| line.line.split('"').nth(1).unwrap_or_default()); + let mut words: Vec = read::word_tokens(line).into_iter().filter(|word| read::content(word)).collect(); + words.dedup(); + words + }); + let anchors = |sentence: &str| match &title { + Some(title) => { + let said = read::word_tokens(sentence); + title.iter().filter(|word| said.contains(word)).collect::>().len() >= 2 || (generic && refers(sentence)) + } + None => names_target(sentence, &names, generic), + }; 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| (start + span.start_byte(), start + span.end_byte())) - .filter(|(at, to)| names_target(sentence_around(prose, *at, *to), &names, generic)) + .filter(|(at, to)| anchors(sentence_around(prose, *at, *to))) .map(|(at, to)| prose[at..to].to_owned()) }) }; @@ -781,11 +798,11 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake 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 { +/// The words that name what a read reads (Soul's R6): a repo's name, a pull request's number, a file's name; a campaign; +/// an address and its host; a recall's words. Lowercase. A domain item is named by its title instead (`reading`). +fn target_words(request: &ReadRequest) -> Vec { 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 { + match request { ReadRequest::Repo(target) => { let (target, searched) = target.split_once("?q=").unwrap_or((target, "")); let rest = target.trim_start_matches("GameCult/"); @@ -797,15 +814,7 @@ fn target_words(asked: &Asked, request: &ReadRequest, packet: &Packet) -> Vec 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 @@ -817,30 +826,38 @@ fn sentence_around(prose: &str, at: usize, to: usize) -> &str { &prose[start..stop] } -/// How many things of a read's kind are in front of her: web addresses in her prose and what reached her, for a web read; -/// her domain's lines and the GameCult repos named in her prose and what reached her, for a repo or campaign read; none -/// for a recall. -fn targets_in_view(request: &ReadRequest, packet: &Packet, prose: &str, reached: &[String]) -> usize { - let texts = || std::iter::once(prose).chain(reached.iter().map(String::as_str)); +/// The things of a read's kind in front of her, by normal form: web addresses in her prose and what reached her, for a +/// web read; her domain's lines' targets and the GameCult repo targets named in her prose and what reached her, for a +/// repo or campaign read; none for a recall. +fn targets_in_view(request: &ReadRequest, packet: &Packet, prose: &str, reached: &[String]) -> BTreeSet { + let words = || std::iter::once(prose).chain(reached.iter().map(String::as_str)).flat_map(str::split_whitespace); match request { - ReadRequest::Web(_) => texts().flat_map(str::split_whitespace).filter(|word| word.starts_with("http://") || word.starts_with("https://")).collect::>().len(), + ReadRequest::Web(_) => words().filter(|word| word.starts_with("http://") || word.starts_with("https://")).map(|url| ReadRequest::Web(url.to_owned()).normal()).collect(), ReadRequest::Repo(_) | ReadRequest::Campaign(_) => { - let named: BTreeSet = texts().flat_map(str::split_whitespace).filter_map(|word| read::repo_name(word.trim_matches(|c: char| !c.is_alphanumeric() && c != '/'))).collect(); - let domain: BTreeSet = packet.domain.iter().filter_map(|line| match &line.about { crate::projection::domain::About::Repo(repo) => read::repo_name(repo), crate::projection::domain::About::Campaign(_) => None }).collect(); - packet.domain.len() + named.difference(&domain).count() + let domain = packet.domain.iter().map(|line| match &line.about { + crate::projection::domain::About::Repo(repo) => ReadRequest::Repo(repo.clone()), + crate::projection::domain::About::Campaign(slug) => ReadRequest::Campaign(slug.clone()), + }); + let named = words().filter_map(|word| read::repo_request(word.trim_matches(|c: char| !c.is_alphanumeric() && c != '/'))); + domain.chain(named).map(|request| request.normal()).collect() } - ReadRequest::Mind(_) => 0, + ReadRequest::Mind(_) => BTreeSet::new(), } } +/// Whether a sentence holds a word that only refers to a thing that can be read: "that page", "the diff". +fn refers(sentence: &str) -> bool { + const REFERENCES: [&str; 8] = ["link", "page", "diff", "file", "repo", "commit", "pr", "address"]; + read::word_tokens(sentence).iter().any(|word| REFERENCES.contains(&word.as_str())) +} + /// Whether a sentence names what is read: one of its words, or, when `generic`, a direct reference to a thing that can /// be read. fn names_target(sentence: &str, names: &[String], generic: bool) -> 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()) }) - || (generic && tokens.iter().any(|word| REFERENCES.contains(word))) + || (generic && refers(sentence)) } /// What she can read and how the Interpreter names it (map 16.22.3), only on a turn that can read. diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 8b3d40a..c438ba0 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -762,7 +762,7 @@ fn b3_a_line_carries_several_promises_and_each_undoable_one_is_its_own_gap() { fn reading_packet() -> Packet { let mut packet = packet(); packet.affordances.push(Affordance::Read); - packet.domain = vec![crate::projection::select::DomainLine { id: "d1".into(), line: "- GameCult/Lodur: merged \"Reflex\", opened by nibu".into(), about: crate::projection::domain::About::Repo("GameCult/Lodur".into()) }]; + packet.domain = vec![crate::projection::select::DomainLine { id: "d1".into(), line: "- GameCult/Lodur: merged \"Reflex: the knee bends first\", opened by nibu".into(), about: crate::projection::domain::About::Repo("GameCult/Lodur".into()) }]; packet } @@ -775,7 +775,7 @@ fn asked(packet: &Packet, prose: &str, read: Value) -> Value { /// read, are refused and reported; the answer otherwise stands. #[test] fn k24_a_read_is_what_her_thought_reaches_for_and_nothing_a_model_made_up() { - let prose = "I want to see what Nibu actually changed in the knee. And that page at http://example.org/knee too."; + let prose = "I want to see what Nibu actually changed in the knee reflex. And that page at http://example.org/knee too."; let reading = reading_packet(); let domain = asked(&reading, prose, json!({ "kind": "domain", "target": "d1", "quote": "I want to see what Nibu actually changed" })); assert_eq!((domain["read"]["request"].clone(), domain["read"]["what"].as_str()), (json!({ "kind": "repo", "target": "GameCult/Lodur" }), Some("GameCult/Lodur on the forge")), "{domain}"); @@ -862,7 +862,7 @@ fn k24_a_read_never_chains_from_what_she_read() { /// it there, and a malformed target (a digest id inside a repo target), are refused and never told to her as hers. #[test] fn r5_a_loose_quote_is_located_and_an_interpreter_fault_is_never_hers() { - let prose = "I want to see what Nibu actually changed in the knee. And GameCult/Bifrost too."; + let prose = "I want to see what Nibu actually changed in the knee reflex. And GameCult/Bifrost too."; let reading = reading_packet(); let loose = asked(&reading, prose, json!({ "kind": "domain", "target": "d1", "quote": "she wants to see what Nibu actually changed today" })); assert_eq!(loose["read"]["quote"], "to see what Nibu actually changed", "the longest run found: {loose}"); @@ -889,8 +889,8 @@ fn r6_a_read_is_anchored_only_where_her_thought_names_it() { 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(why)), "{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}"); + let named = asked(&reading, "I want to see how the knee bends now.", json!({ "kind": "domain", "target": "d1", "quote": "I want to see how" })); + assert_eq!(named["read"]["quote"], "I want to see how", "{named}"); } /// Soul's R6 (E r6, Eureka said "him" for Kiko): the Interpreter and the Persona get the pronouns of anyone named, from @@ -1009,3 +1009,25 @@ fn r8_a_search_keeps_her_words_and_refused_reads_are_listed() { let prompt = speech_prompt_in(&seen, "x", prose, &Tuning::default(), "", &drafts(prose), &wake_refused); assert!(prompt.contains(" Refused earlier, so never named again as it was: repo GameCult/Bifrost?q=sign-in gate (search_words_not_in_her_thought); repo GameCult/Lodur#3 (quote_not_located)."), "{prompt}"); } + +/// Soul's R8: a domain item anchors only where her sentence carries two of its title's content words, a stopword never +/// counting; a generic "that page" with one domain line in view anchors that line's own target and nothing else; a +/// recall needs two content words ("want to sit" is none). +#[test] +fn r8_anchors_need_two_title_words_and_a_generic_word_names_only_the_one_thing_there() { + let reading = reading_packet(); + let domain = |prose: &str, quote: &str| asked(&reading, prose, json!({ "kind": "domain", "target": "d1", "quote": quote })); + assert!(domain("I keep thinking the knee bends wrong.", "I keep thinking the knee")["read"].is_object()); + for (prose, quote) in [("I keep thinking about Nibu and Lodur today.", "I keep thinking about Nibu"), ("I keep thinking about the knee with care.", "I keep thinking about the knee"), ("I keep thinking with the first of them.", "I keep thinking with the first")] { + assert_eq!(domain(prose, quote)["read_refused"][0]["why"], "quote_not_located", "{prose}"); + } + assert!(domain("I want to open that page and read it.", "I want to open that page")["read"].is_object(), "one domain line in view: that page is it"); + let other = asked(&reading, "I want to open that page and read it.", json!({ "kind": "repo", "target": "GameCult/Bifrost", "quote": "I want to open that page" })); + assert_eq!(other["read_refused"][0]["why"], "quote_not_located", "that page is the one line's target, not another: {other}"); + let mut two = reading_packet(); + two.domain.push(crate::projection::select::DomainLine { id: "d2".into(), line: "- GameCult/Bifrost: merged \"Merge pages and notices\", opened by heimdall".into(), about: crate::projection::domain::About::Repo("GameCult/Bifrost".into()) }); + let either = asked(&two, "I want to open that page and read it.", json!({ "kind": "domain", "target": "d1", "quote": "I want to open that page" })); + assert_eq!(either["read_refused"][0]["why"], "quote_not_located", "{either}"); + let sit = asked(&reading, "I want to sit with this a while.", json!({ "kind": "mind", "target": "want to sit", "quote": "I want to sit with this" })); + assert_eq!(sit["read_refused"][0]["why"], "no_recall_words", "{sit}"); +} diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index cfc9a70..a21c4d6 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -233,11 +233,15 @@ fn repo_target(target: &str) -> Option { (plain(name) && suffix_ok).then(|| format!("GameCult/{name}{suffix}")) } -/// Words that carry no content of their own: a recall or a search made of these alone names nothing (Soul's R7). -const STOPWORDS: [&str; 64] = [ +/// Words that carry no content of their own: a recall, a search or an anchor made of these alone names nothing (Soul's +/// R7, R8). The function words, and the light verbs and fillers a thought reaches with ("want to sit", "go look"). +const STOPWORDS: [&str; 111] = [ "a", "an", "the", "and", "or", "but", "of", "to", "in", "on", "at", "for", "with", "by", "from", "about", "as", "into", "is", "are", "was", "were", "be", "been", "it", "its", "this", "that", "these", "those", "i", "me", "my", "we", "our", "you", "your", "he", "him", "his", "she", "her", "they", "them", "their", "what", "which", "who", "how", "when", "where", "why", "do", "does", "did", "not", "no", "so", "if", "then", "there", "here", "just", "some", + "am", "has", "have", "had", "will", "would", "can", "could", "should", "may", "might", "must", "want", "need", "like", "get", "got", "go", "going", + "see", "look", "sit", "think", "know", "make", "take", "let", "say", "tell", "come", "thing", "things", "something", "really", "still", "while", "now", + "again", "also", "more", "very", "all", "any", "one", "out", "up", "over", ]; /// The words of `text`, lowercased, split at anything that is not a letter or a digit. @@ -255,7 +259,7 @@ fn stem(word: &str) -> String { } /// Whether a word carries content: not one of `STOPWORDS`. -fn content(word: &str) -> bool { +pub(crate) fn content(word: &str) -> bool { !STOPWORDS.contains(&word) } @@ -267,6 +271,11 @@ fn search_finds(query: &str, text: &str) -> bool { !wanted.is_empty() && wanted.iter().all(|word| held.contains(word)) } +/// A repo target as a read, when it is one. +pub(crate) fn repo_request(target: &str) -> Option { + repo_target(target.trim()).map(ReadRequest::Repo) +} + /// 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())?;