diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index f55b5ee..9273bd6 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -1220,9 +1220,8 @@ fn k30_doable_is_derived() { /// F.1 r9, Nibu: her prose verbatim. Her open promise to Deru needs his page; the room holds his link and Meta's notes /// link, so "the page" names neither by itself. Her promise anchors the reach for its own target, and only that one. /// -/// The room's lines are in what reached her (`bodies`) and not among the lines she may reply to: with Meta's line -/// listed, R9's possessive ("Meta's notes link", in her own prose) would name Meta's link, and the negative would -/// resolve. +/// The room's lines are in what reached her and among the lines she may reply to, as a real packet has them (K33, +/// Soul's R12 deviation 4). #[test] fn k30_f1_r9_promised_read_is_anchored() { let prose = "Aqua said she hasn't opened it either. I said I'd read it properly, and I haven't. Same bill, two names on it. Hers is honest about it. Mine was a promise made while it was still unopened.\n\nI don't need to say anything to the room about that. Opening the link is the only thing that pays it. When I've read enough to say which part is about plosives and which about waveguides, I'll speak. Until then, anything I said would just be the promise again.\n\nAqua's question to Heimdall isn't mine to answer. Meta's notes link asked for nothing. Kiko's request to Deru isn't mine either.\n\nOpen the page. Start at the top, not at the plosive part. Find out whether it's a book or a single page. Then I'll know how long \"properly\" is."; @@ -1231,6 +1230,8 @@ fn k30_f1_r9_promised_read_is_anchored() { format!("Aqua, Nibu: found this on physical modelling of plosives and waveguides, thought of you two {PASP}"), "unrelated, for whoever's around: the notes from Saturday are at http://notes.gamecult.org/saturday, nobody needs to read them".into(), ]; + let line = |id: &str, who: &str, sender: &str, text: &str| crate::projection::select::Quotable { id: id.into(), event: format!("${id}"), room: MINDS.into(), who: who.into(), sender: sender.into(), at_ms: 1, text: text.into() }; + nibu.quotable = vec![line("q1", "Deru", DERU, &nibu.bodies[0]), line("q2", "Meta", "@meta:gamecult.org", &nibu.bodies[1])]; nibu.promises = vec![promised("I'll read it properly before I say anything about it.", DERU, Some(Needs::Read { request: ReadRequest::Web(PASP.into()) }))]; let read = asked(&nibu, prose, json!({ "kind": "web", "target": PASP, "quote": "Open the page. Start at the top" })); assert_eq!(read["read"]["request"], json!({ "kind": "web", "target": PASP }), "{read}"); @@ -1378,3 +1379,31 @@ fn k32_link_keeps_balanced_parens() { assert_eq!(links("(https://x.org/a)"), ["https://x.org/a"]); assert_eq!(links("[https://x.org/a]. \"https://x.org/q?a=(1)\","), ["https://x.org/a", "https://x.org/q?a=(1)"]); } + +// --------------------------------------------------------------------------------------------- +// K33 (map 16.26): Soul's R12 blockers and lows. + +fn repo_asked(target: &str) -> Asked { + Asked { kind: Kind::Repo, target: target.into(), quote: String::new() } +} + +/// B1, probe 3's shape (X.1 r1, Eureka): `GameCult/gamecult-ops#125` in what she heard and `gamecult-ops#125` in her +/// prose. A repo name is one token with its `-`, `.` and `_`, case-blind, so it is in front of her; a name in front of +/// her nowhere, or only as part of a longer name, is still refused. +#[test] +fn k33_b1_a_repo_name_keeps_its_hyphen_dot_and_underscore() { + let heard = "Eureka, can you look at GameCult/gamecult-ops#125 and tell me whether the relay revert in it looks safe? no rush".to_owned(); + let prose = "Meta wants me to look at gamecult-ops#125 before I say anything about the relay revert."; + let ops = ReadRequest::Repo("GameCult/gamecult-ops#125".into()); + let eureka = reading_packet(); + assert_eq!(read::reach(&repo_asked("GameCult/gamecult-ops#125"), &eureka, prose, std::slice::from_ref(&heard)), Ok(ops.clone())); + assert_eq!(read::reach(&repo_asked("GameCult/gamecult-ops#125"), &eureka, "I'll look.", std::slice::from_ref(&heard)), Ok(ops.clone()), "in what she heard alone"); + assert_eq!(read::reach(&repo_asked("GameCult/Gamecult-Ops#125"), &eureka, prose, &[]), Ok(ReadRequest::Repo("GameCult/Gamecult-Ops#125".into())), "in her prose alone, case-blind"); + for (target, text) in [("GameCult/GameCult.Geometry.Csg", "the csg kernel is in gamecult.geometry.csg."), ("GameCult/cult_net@4b2c9e1", "I'd start with cult_net, then the mesh.")] { + assert!(read::reach(&repo_asked(target), &eureka, text, &[]).is_ok(), "{target} in {text:?}"); + } + // Named nowhere, or only inside a longer name: refused. + assert_eq!(read::reach(&repo_asked("GameCult/Heimdall"), &eureka, prose, std::slice::from_ref(&heard)), Err("repo_not_in_front_of_her")); + assert_eq!(read::reach(&repo_asked("GameCult/ops"), &eureka, prose, std::slice::from_ref(&heard)), Err("repo_not_in_front_of_her")); + assert_eq!(read::reach(&repo_asked("GameCult/gamecult"), &eureka, prose, std::slice::from_ref(&heard)), Err("repo_not_in_front_of_her")); +} diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index 0d1ba5a..71a4f23 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -351,15 +351,25 @@ pub(crate) fn reach(asked: &Asked, packet: &Packet, prose: &str, reached: &[Stri let reached: Vec = reached.iter().cloned().chain(promised).collect(); let request = resolve(asked, packet, prose, &reached)?; if let ReadRequest::Repo(target) = &request { - let in_front = word_tokens(&format!("{prose}\n{}\n{}", packet.in_view, reached.join("\n"))); - let named = repo_name(target).is_some_and(|repo| in_front.contains(&repo) || packet.domain.iter().any(|line| line.line.to_lowercase().contains(&format!("gamecult/{repo}")))); - if !named { + let domain = packet.domain.iter().map(|line| line.line.as_str()); + let in_front = [prose, packet.in_view.as_str()].into_iter().chain(reached.iter().map(String::as_str)).chain(domain); + if !repo_name(target).is_some_and(|repo| in_front.into_iter().any(|text| names_repo(text, &repo))) { return Err("repo_not_in_front_of_her"); } } Ok(request) } +/// Whether `text` names the repo `repo` (lowercase): as a whole repo-name token, case-blind, where a token runs over +/// letters, digits, `-`, `.` and `_`, as a repo name does (`repo_target`), so `GameCult/gamecult-ops#125` names +/// `gamecult-ops` and "ops" names nothing of it. A token's trailing `.`, `-` or `_` (a sentence's full stop) is not part +/// of the name. The one matcher of what repo is in front of her (map 16.25.5), at open and at read. +fn names_repo(text: &str, repo: &str) -> bool { + text.split(|c: char| !(c.is_alphanumeric() || matches!(c, '-' | '.' | '_'))) + .filter(|token| !token.is_empty()) + .any(|token| token.eq_ignore_ascii_case(repo) || token.trim_end_matches(['.', '-', '_']).eq_ignore_ascii_case(repo)) +} + /// Whether `target` is a digest id: `d` and a number. fn digest_id(target: &str) -> bool { target.strip_prefix('d').is_some_and(|number| !number.is_empty() && number.chars().all(|c| c.is_ascii_digit()))