Persona reads: anchors and search words come from her own prose

Soul's R7 item 5.
- A recall reads by at least two content words, found as a contiguous run in
  her prose.
- A search's words are whole words of her prose, at least one carrying content:
  no fragments, no stopword-only query.
- A word that only refers (page, link, file, repo, pr, diff, commit, address)
  anchors a read only when exactly one target of the read's kind is in front of
  her.
- A promise's `needs` must name a repo that her prose or her view names; one
  that names none is dropped and reported in promise_to_dropped.
- promise_block applies only when the not-found read is of the needed item
  itself (same normal form); a search of its repo for something else does not
  count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-21 02:34:07 +01:00
commit 1729a35f5f
5 changed files with 138 additions and 21 deletions

View file

@ -24,6 +24,7 @@ use serde_json::{Value, json};
use super::interpret::drafts;
use super::narrate::words;
use super::read::ReadRequest;
/// How long a closed promise stays in her state before the commit removes it.
pub(crate) const CLOSED_KEPT_DAYS: i64 = 7;
@ -279,14 +280,13 @@ pub(crate) fn apply(state: &Value, record: &Value, prose: &str, key: &str, now:
/// read becomes `blocked` when this turn read that target, or searched the same repo, and found nothing. It cites the
/// read. A read that succeeded leaves the promise open: telling the person is the kept act.
fn block_on_failed_reads(state: &mut Value, record: &Value, applied: &mut Applied) {
let repo_of = |target: &str| target.split(['#', '?', '/', '@']).take(2).collect::<Vec<_>>().join("/");
let failed: Vec<&Value> = record["interpreter"]["reads"].as_array().into_iter().flatten().filter(|read| read["ok"] == false && read["failure"] == "not_found").collect();
for entry in state.get_mut("commitments").and_then(Value::as_array_mut).into_iter().flatten().filter(|entry| entry["status"] == "open") {
let Some(needs) = entry["needs"].as_str().map(str::to_owned) else { continue };
let Some(read) = failed.iter().find(|read| {
let target = read["request"]["target"].as_str().unwrap_or_default();
target == needs || (target.contains("?q=") && repo_of(target) == repo_of(&needs))
}) else {
// Only a read or search of the needed item itself blocks it (Soul's R7): a search of its repo for something else
// does not.
let key = ReadRequest::Repo(needs.clone()).normal();
let Some(read) = failed.iter().find(|read| read["request"]["target"].as_str().is_some_and(|target| ReadRequest::Repo(target.to_owned()).normal() == key)) else {
continue;
};
entry["status"] = json!("blocked");

View file

@ -269,8 +269,8 @@ fn k27_a_promise_said_again_reaffirms_the_entry_and_opens_none() {
assert_eq!((state["commitments"].as_array().unwrap().len(), state["commitments"][0]["reaffirmed"].as_array().unwrap().len()), (1, 3));
}
/// K28 (map 16.24.3): a promise that needs a read becomes blocked when that read, or a search of the same repo, finds
/// nothing, citing the read; a read that succeeds leaves it open.
/// K28 (map 16.24.3), Soul's R7: a promise that needs a read becomes blocked when the read of the needed item itself finds
/// nothing, citing the read; a search of the same repo for something else blocks nothing, nor does a read that succeeds.
#[test]
fn k28_a_promise_whose_read_finds_nothing_is_blocked_citing_the_read() {
let needs = json!(Proposal::PromiseOpen { words: "send the render tonight".into(), to: Some(META.into()), doable: true, reaffirms: None, needs: Some("GameCult/Bifrost#89".into()), evidence: Evidence::Draft(1) });
@ -280,7 +280,8 @@ fn k28_a_promise_whose_read_finds_nothing_is_blocked_citing_the_read() {
rec["interpreter"]["reads"] = json!([read]);
apply(&json!({}), &rec, PROSE, "r1-t1", now())
};
let (state, applied) = with_read(false, "GameCult/Bifrost?q=consent receipt");
assert_eq!(with_read(false, "GameCult/Bifrost?q=consent receipt").0["commitments"][0]["status"], "open", "a search of the repo for something else");
let (state, applied) = with_read(false, "gamecult/bifrost#89");
let entry = &state["commitments"][0];
assert_eq!((entry["status"].as_str(), entry["needs"].as_str(), entry["blockedBy"]["n"].as_u64(), applied.blocked.len()), (Some("blocked"), Some("GameCult/Bifrost#89"), Some(1), 1), "{state}");
assert_eq!(with_read(true, "GameCult/Bifrost#89").0["commitments"][0]["status"], "open", "found: telling is the kept act");

View file

@ -36,13 +36,15 @@
//! composes the edit), and leave Self one note (`suggest`, map 16.18; recorded in the turn's record, never a write to her
//! Mind). One draft goes one place across all three.
use std::collections::BTreeSet;
use ghostlight_persona_projection::SourceSpan;
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use super::Affordance;
use super::commit::{Evidence, How, Proposal};
use super::read::{Asked, Kind, QUOTE_MIN_WORDS, ReadRequest, SPAN_MIN_WORDS, resolve};
use super::read::{self, 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, named_pronouns, spoken, turn_words, voiced};
use super::tuning::Tuning;
@ -575,6 +577,8 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na
let mut unused: Vec<Value> = Vec::new();
let mut proposals: Vec<Value> = Vec::new();
let mut to_dropped: Vec<Value> = Vec::new();
let in_front = read::word_tokens(&format!("{}\n{}\n{}\n{}", prose, packet.in_view, packet.heard, packet.bodies.join("\n")));
let named = |repo: &str| in_front.iter().any(|word| word == repo) || packet.domain.iter().any(|line| line.line.to_lowercase().contains(&format!("gamecult/{repo}")));
for line in parsed.say {
let Some(draft) = line.draft.and_then(|n| found.numbered(n)) else {
refusals.push(refused(Act::Say, None, line.draft, Refusal::NoDraft));
@ -608,7 +612,7 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na
said_drafts.push(draft.n);
went.push(draft);
said.push(json!({ "room": room, "text": draft.text, "mentions": mentions, "in_reply_to": target.map(|line| json!({ "id": line.id, "event": line.event, "who": line.who, "text": line.text })), "rests_on": { "draft": draft.n, "start_byte": draft.start, "end_byte": draft.end }, "dropped": { "mentions": unknown } }));
promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped }, draft, &line.promises, &shown);
promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped, named: &named }, draft, &line.promises, &shown);
}
// An amendment adds a whole draft after a line of hers listed as one she may add to; the actuator composes it, so
// nothing here can rewrite the line (map 16.17).
@ -635,7 +639,7 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na
went.push(draft);
amended_drafts.push(draft.n);
amended.push(json!({ "target": line.id, "event": line.event, "room": line.room, "original": line.text, "added": draft.text, "draft": draft.n }));
promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped }, draft, &proposed.promises, &shown);
promised(&mut decision, Promising { unused: &mut unused, proposals: &mut proposals, to_dropped: &mut to_dropped, named: &named }, draft, &proposed.promises, &shown);
}
(reason, _) => refusals.push(refused(Act::Amend, Some(draft), None, reason.unwrap_or(Refusal::NotAmendable))),
}
@ -747,13 +751,16 @@ fn reading(raw: &Value, packet: &Packet, prose: &str, found: &Drafts, wake: Wake
// 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);
// 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;
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))
.filter(|(at, to)| names_target(sentence_around(prose, *at, *to), &names, generic))
.map(|(at, to)| prose[at..to].to_owned())
})
};
@ -800,13 +807,30 @@ fn sentence_around(prose: &str, at: usize, to: usize) -> &str {
&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 {
/// 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));
match request {
ReadRequest::Web(_) => texts().flat_map(str::split_whitespace).filter(|word| word.starts_with("http://") || word.starts_with("https://")).collect::<BTreeSet<_>>().len(),
ReadRequest::Repo(_) | ReadRequest::Campaign(_) => {
let named: BTreeSet<String> = 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<String> = 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()
}
ReadRequest::Mind(_) => 0,
}
}
/// 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()) })
|| tokens.iter().any(|word| REFERENCES.contains(word))
|| (generic && 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.
@ -860,6 +884,8 @@ struct Promising<'a> {
unused: &'a mut Vec<Value>,
proposals: &'a mut Vec<Value>,
to_dropped: &'a mut Vec<Value>,
/// Whether a repo, by its lowercased name, is named in her prose or in her view: what `needs` may name.
named: &'a dyn Fn(&str) -> bool,
}
/// The promises in a draft she says or adds (map 16.21, 16.22.1, B3): the list is required of every line and every
@ -870,11 +896,11 @@ struct Promising<'a> {
/// already gapped on this draft stands for the first of them, so none is recorded twice.
fn promised(decision: &mut Value, into: Promising, draft: &Draft, promises: &[ProposedPromise], shown: &dyn Fn(&str) -> bool) {
let answered_reach = decision["gaps"].as_array().is_some_and(|gaps| gaps.iter().any(|gap| gap["kind"] == json!(GapKind::MissingAffordance) && gap["from"] == "draft" && gap["draft"] == json!(draft.n) && gap.get("promises").is_none()));
let Promising { unused, proposals, to_dropped } = into;
let Promising { unused, proposals, to_dropped, named } = into;
let mut undoable = 0;
for promise in promises.iter().filter(|promise| !promise.words.trim().is_empty()) {
let words = promise.words.trim();
if !promised_one(Promising { unused: &mut *unused, proposals: &mut *proposals, to_dropped: &mut *to_dropped }, draft, promise, shown) || promise.doable {
if !promised_one(Promising { unused: &mut *unused, proposals: &mut *proposals, to_dropped: &mut *to_dropped, named }, draft, promise, shown) || promise.doable {
continue;
}
undoable += 1;
@ -904,7 +930,15 @@ fn promised_one(into: Promising, draft: &Draft, promise: &ProposedPromise, shown
None => None,
};
let reaffirms = promise.reaffirms.as_deref().map(str::trim).filter(|id| !id.is_empty()).map(str::to_owned);
let needs = promise.needs.as_deref().map(str::trim).filter(|target| !target.is_empty()).map(str::to_owned);
// What it needs read names a repo she named or has in front of her (Soul's R7); one that names none is dropped.
let needs = match promise.needs.as_deref().map(str::trim).filter(|target| !target.is_empty()) {
Some(target) if read::repo_name(target).is_some_and(|repo| (into.named)(&repo)) => Some(target.to_owned()),
Some(target) => {
into.to_dropped.push(json!({ "draft": draft.n, "needs": target }));
None
}
None => None,
};
into.proposals.push(json!(Proposal::PromiseOpen { words: words.to_owned(), to, doable: promise.doable, reaffirms, needs, evidence: Evidence::Draft(draft.n) }));
true
}

View file

@ -944,3 +944,48 @@ fn k28_a_search_reads_only_words_her_prose_uses() {
assert_eq!(invented["read_refused"][0]["why"], "search_words_not_in_her_thought", "{invented}");
assert!(crate::projection::outcome::outcome_of(&json!({ "interpreter": invented, "posted": [] })).unwrap().lines(packet().forms).is_empty());
}
/// Soul's R7: a recall is by at least two content words of her prose, as a run it has; a search by whole words of her
/// prose, one at least carrying content.
#[test]
fn r7_recall_and_search_words_are_her_own_whole_words() {
let reading = reading_packet();
let prose = "I keep thinking about the knee reflex Nibu built. I want to find the Bifrost change about the consent receipt.";
let quote = "I keep thinking about the knee reflex";
let recall = |words: &str| asked(&reading, prose, json!({ "kind": "mind", "target": words, "quote": quote }));
assert!(recall("knee reflex")["read_refused"].is_null(), "{}", recall("knee reflex"));
for bad in ["knee", "the knee", "reflex knee", "knee reflexes"] {
assert_eq!(recall(bad)["read_refused"][0]["why"], "no_recall_words", "{bad}");
}
let search = |words: &str| asked(&reading, prose, json!({ "kind": "repo", "target": format!("GameCult/Bifrost?q={words}"), "quote": "I want to find the Bifrost change" }));
assert!(search("consent receipt")["read_refused"].is_null(), "{}", search("consent receipt"));
for bad in ["consent rec", "the about", "consent signature"] {
assert_eq!(search(bad)["read_refused"][0]["why"], "search_words_not_in_her_thought", "{bad}");
}
}
/// Soul's R7: a word that only refers ("that page") anchors a read only when one thing of its kind is in front of her.
#[test]
fn r7_a_generic_word_anchors_a_read_only_when_one_target_of_its_kind_is_in_view() {
let reading = reading_packet();
let quote = "I want to open that page and read it";
let one = "There is http://a.example/x here. I want to open that page and read it all.";
let read = asked(&reading, one, json!({ "kind": "web", "target": "http://a.example/x", "quote": quote }));
assert_eq!(read["read"]["request"], json!({ "kind": "web", "target": "http://a.example/x" }), "{read}");
let two = "There is http://a.example/x and http://b.example/y here. I want to open that page and read it all.";
let either = asked(&reading, two, json!({ "kind": "web", "target": "http://a.example/x", "quote": quote }));
assert_eq!(either["read_refused"][0]["why"], "quote_not_located", "{either}");
}
/// Soul's R7: what a promise needs read names a repo she named or has in front of her; one that names none is dropped.
#[test]
fn r7_a_promise_needs_only_a_repo_in_her_prose_or_view() {
let reading = reading_packet();
let prose = "<typed>Meta, I'll check the Lodur change and tell you.</typed>";
let promise = |needs: &str| answered(&reading, prose, json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [{ "words": "I'll check the Lodur change and tell you.", "to": null, "doable": true, "needs": needs }] }], "gaps": [] }));
let named = promise("GameCult/Lodur#12");
assert_eq!(named["state"].as_array().and_then(|state| state.iter().find(|p| p["kind"] == "promise_open")).map(|p| p["needs"].clone()), Some(json!("GameCult/Lodur#12")), "{named}");
let invented = promise("GameCult/Nowhere#3");
assert_eq!(invented["promise_to_dropped"][0]["needs"], "GameCult/Nowhere#3", "{invented}");
assert!(invented["state"].as_array().into_iter().flatten().all(|p| p["needs"].is_null()), "{invented}");
}

View file

@ -232,6 +232,30 @@ fn repo_target(target: &str) -> Option<String> {
(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] = [
"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",
];
/// The words of `text`, lowercased, split at anything that is not a letter or a digit.
pub(crate) fn word_tokens(text: &str) -> Vec<String> {
text.split(|c: char| !c.is_alphanumeric()).filter(|word| !word.is_empty()).map(str::to_lowercase).collect()
}
/// Whether a word carries content: not one of `STOPWORDS`.
fn content(word: &str) -> bool {
!STOPWORDS.contains(&word)
}
/// 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<String> {
let target = repo_target(target.trim())?;
let rest = &target["GameCult/".len()..];
Some(rest[..rest.find(['/', '#', '@', '?']).unwrap_or(rest.len())].to_lowercase())
}
/// What the Interpreter named, resolved, or why not: a domain line's id must be one the packet listed; a web address must
/// stand verbatim in her prose or in what reached her (`reached`); a repo target must be a public GameCult one; a recall
/// must say something.
@ -243,12 +267,25 @@ pub(crate) fn resolve(asked: &Asked, packet: &Packet, prose: &str, reached: &[St
About::Repo(repo) => ReadRequest::Repo(repo.clone()),
About::Campaign(slug) => ReadRequest::Campaign(slug.clone()),
}).ok_or("no_such_domain_line"),
Kind::Mind if !target.is_empty() && target.len() <= 200 => Ok(ReadRequest::Mind(target.to_owned())),
Kind::Mind => Err("no_recall_words"),
// A recall is by her own words (Soul's R7): at least two that carry content, as a run her prose has.
Kind::Mind => {
let words = word_tokens(target);
let said = word_tokens(prose);
let run = !words.is_empty() && said.windows(words.len()).any(|window| window == words.as_slice());
if target.len() <= 200 && words.iter().filter(|word| content(word)).count() >= 2 && run { Ok(ReadRequest::Mind(target.to_owned())) } else { Err("no_recall_words") }
}
// A digest id resolves only as a domain item, never inside a repo target (`GameCult/Bifrost#d3`, Soul's R5).
// A search's words must stand in her prose (map 16.24.3), as a quote must.
Kind::Repo => match repo_target(target) {
Some(target) if target.split_once("?q=").is_some_and(|(_, words)| !prose.to_lowercase().contains(&words.trim().to_lowercase())) => Err("search_words_not_in_her_thought"),
// A search is by whole words of her prose, at least one that carries content (Soul's R7).
Some(target)
if target.split_once("?q=").is_some_and(|(_, words)| {
let (words, said) = (word_tokens(words), word_tokens(prose));
!words.iter().all(|word| said.contains(word)) || !words.iter().any(|word| content(word))
}) =>
{
Err("search_words_not_in_her_thought")
}
Some(target) => Ok(ReadRequest::Repo(target)),
None if target.to_lowercase().starts_with("gamecult/") || digest_id(target) => Err("malformed_target"),
None => Err("not_a_gamecult_repo"),