Persona K71: a repo key keeps its org; K64's read_before skips searches

ReadRequest::normal writes repo:{org}/{name}, the org lowercased, so another
org's #125 is not GameCult's (Soul's K64d, inverted). A search need made after
the same search stays a search need, as in the other order: a search reads
none of what it finds (K64e, inverted; K64e2 unchanged). narrows compares
through normal() instead of a second spelling of the key.

Map 16.34.8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-22 23:37:17 +01:00
commit fed9094c69
3 changed files with 43 additions and 5 deletions

View file

@ -571,13 +571,18 @@ fn narrows(entry: &Value, needs: &Needs) -> Option<ReadRequest> {
let Needs::Read { request: named } = needs else { return None };
let (ReadRequest::Repo(searched), ReadRequest::Repo(target)) = (&need, named) else { return None };
let repo = repo_name(searched).filter(|repo| repo_name(target).as_deref() == Some(repo.as_str()))?;
let one_thing = named.normal() != format!("repo:gamecult/{repo}");
let one_thing = named.normal() != ReadRequest::Repo(format!("GameCult/{repo}")).normal();
(need.search() && !named.search() && one_thing).then(|| named.clone())
}
/// The read of this conversation that found what `request` reads, by its normal form, as `readBefore` records it (K64):
/// when it was made, and what it read. None when no read of it found anything, or the record gives no time.
/// when it was made, and what it read. None when no read of it found anything, or the record gives no time, and for a
/// search (K71, map 16.34.8): a search reads none of what it finds, so a search need stays a search need, narrowed only by
/// a reaffirmation naming one item (K40), whichever came first.
fn read_before(request: &ReadRequest, record: &Value) -> Option<Value> {
if request.search() {
return None;
}
let key = request.normal();
let read = record["interpreter"]["conversation_reads"].as_array()?.iter().find(|read| read["found"] == true && read["key"].as_str() == Some(key.as_str()))?;
let at = read["at"].as_str().and_then(|at| DateTime::parse_from_rfc3339(at).ok())?;

View file

@ -1120,3 +1120,34 @@ fn k64_a_reaffirm_narrowing_to_an_item_already_read_is_words() {
let entry = &state["commitments"][0];
assert_eq!((entry["needs"].clone(), entry["readBefore"]["of"].as_str(), applied.reaffirmed.len()), (json!(Needs::Words), Some(ReadRequest::Repo("GameCult/Bifrost#85".into()).normal().as_str()), 1), "{state}");
}
/// A promise opened over `needs`, after one read of this conversation that found `read_key` half an hour ago.
fn opened_after_read(needs: Needs, reached: bool, read_key: String) -> Value {
let reads = json!([{ "key": read_key, "found": true, "at": (now() - Duration::minutes(30)).to_rfc3339() }]);
let (state, _) = apply(&json!({}), &with_reads(record(json!([open_needing(META, Some(needs), reached)]), json!([]), true), reads), PROSE, "r1-t13", now());
state["commitments"][0].clone()
}
/// Soul's K64d, inverted (K71, map 16.34.8): a repo key keeps its org, so another org's repo of the same name and number
/// is not the read GameCult's made, and the need stays a read need.
#[test]
fn k71_k64d_another_org_does_not_match() {
let ops = ReadRequest::Repo("GameCult/gamecult-ops#125".into()).normal();
assert_eq!((ops.as_str(), ReadRequest::Repo("SomeoneElse/gamecult-ops#125".into()).normal().as_str()), ("repo:gamecult/gamecult-ops#125", "repo:someoneelse/gamecult-ops#125"));
let entry = opened_after_read(read_need("SomeoneElse/gamecult-ops#125"), false, ops.clone());
assert_eq!((entry["needs"]["kind"].as_str(), entry.get("readBefore")), (Some("read"), None), "{entry}");
// GameCult's own, in any case and with a leading zero, is the same read.
let entry = opened_after_read(read_need("gamecult/GameCult-Ops#0125"), true, ops);
assert_eq!(entry["needs"], json!(Needs::Words), "{entry}");
}
/// Soul's K64e, inverted (K71): a search need made after the same search stays a search need, as it does in the other
/// order, since a search reads none of what it finds; K64e2, an item need after the search, is unchanged.
#[test]
fn k71_k64e_a_search_need_after_the_same_search_stays_a_search() {
let search = ReadRequest::Repo("GameCult/Bifrost?q=merge pages".into()).normal();
let entry = opened_after_read(read_need("GameCult/Bifrost?q=the page merge"), true, search.clone());
assert_eq!((entry["needs"]["kind"].as_str(), entry["needs"]["request"]["target"].as_str(), entry.get("readBefore")), (Some("read"), Some("GameCult/Bifrost?q=the page merge"), None), "{entry}");
let entry = opened_after_read(read_need("GameCult/Bifrost#85"), true, search);
assert_eq!((entry["needs"]["kind"].as_str(), entry.get("readBefore")), (Some("read"), None), "K64e2: a search read no item: {entry}");
}

View file

@ -76,7 +76,7 @@ pub enum ReadRequest {
}
impl ReadRequest {
/// One normal form per thing read (Soul's R7, R8): the org and repo case-blind; a search's words lowercased, its
/// One normal form per thing read (Soul's R7, R8): the org and repo case-blind, the org kept (K71); a search's words lowercased, its
/// stopwords dropped, each lightly stemmed of a plural and the rest sorted, so "Merge pages" and "the page merge" are
/// one search; a number without its leading zeros (`#089` is `#89`); a recall's and a campaign's lowercased. Two
/// requests with the same form are the same read.
@ -90,14 +90,16 @@ impl ReadRequest {
};
match self {
Self::Repo(target) => {
let rest = target.split_once('/').map_or(target.as_str(), |(_, rest)| rest);
// The org is kept, lowercased (K71, map 16.34.8): another org's repo of the same name is another repo.
// A target with no org is GameCult's, as every key the answer path builds is.
let (org, rest) = target.split_once('/').unwrap_or(("GameCult", target.as_str()));
let end = rest.find(['/', '#', '@', '?']).unwrap_or(rest.len());
let (name, suffix) = rest.split_at(end);
let suffix = match suffix.strip_prefix("?q=") {
Some(words) => format!("?q={}", searched(words)),
None => suffix.strip_prefix('#').map_or_else(|| suffix.to_owned(), |number| format!("#{}", Some(number.trim_start_matches('0')).filter(|digits| !digits.is_empty()).unwrap_or("0"))),
};
format!("repo:gamecult/{}{suffix}", name.to_lowercase())
format!("repo:{}/{}{suffix}", org.to_lowercase(), name.to_lowercase())
}
Self::Campaign(slug) => format!("campaign:{}", slug.to_lowercase()),
Self::Mind(words) => format!("mind:{}", collapse(words)),