From 5a7c686cda2518e1b4f7823a8d59fc01ba37af28 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 21 Nov 2026 23:12:35 +0100 Subject: [PATCH] Persona K32: read edges (map 16.25.8) link_of strips a closing ), ] or } only while the link holds more of it than of its opener (the GFM autolink rule), so A_(b) keeps its parens. In the simulator a campaign read is served from the cast's [cast.domain] campaigns (CastReads), the one owner of what her campaign holds, within the window, newest first, formatted by read::rulings_text, which LiveReads::rulings now uses too: "- {title}: {ruling}", or "- {title}" when no ruling text is held. Ruled gains optional ruling text. A plan with a [[cast.read]] of kind campaign is refused at load. Tests: k32_link_keeps_balanced_parens, k32_campaign_read_from_domain, k32_campaign_cast_read_refused. The public surface gains impl ReadFixture and impl ReadSource for CastReads. Plan F (persona-seeds variants/plans/plan-F.toml, outside this repo): Nibu's [[cast.read]] campaign entry is deleted and its ruling words moved onto her aetheria-release rulings. Heimdall's heimdall-body ruling text is not set: the record lives only in his mind (left open). Verified on Yggdrasil (ygg-verify, rust image): cargo test -p mind-body 818 passed 0 failed; clippy -p mind-body --all-targets -D warnings clean. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/domain.rs | 5 ++- .../mind-body/src/projection/domain/tests.rs | 4 +- crates/mind-body/src/projection/interpret.rs | 13 +++++- .../src/projection/interpret/tests.rs | 11 +++++ crates/mind-body/src/projection/read.rs | 32 +++++++++---- crates/mind-body/src/projection/simulate.rs | 26 ++++++++++- .../src/projection/simulate/tests.rs | 45 +++++++++++++++++++ crates/mind-body/tests/public_surface.txt | 2 + 8 files changed, 123 insertions(+), 15 deletions(-) diff --git a/crates/mind-body/src/projection/domain.rs b/crates/mind-body/src/projection/domain.rs index 1da7c32..f94ea69 100644 --- a/crates/mind-body/src/projection/domain.rs +++ b/crates/mind-body/src/projection/domain.rs @@ -108,6 +108,9 @@ pub(crate) struct Ruled { pub(crate) title: String, #[serde(default)] pub(crate) who: Who, + /// The ruling's own words, when the record holds them: what a campaign read shows after the title (map 16.25.8). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub(crate) ruling: Option, } /// Who ran an admission, as people and Minds: her own organs (her Persona turn, her Self runs and what they dispatch), @@ -306,7 +309,7 @@ pub(crate) fn read(ask: &Ask, her: &str, forge: &dyn ForgeGet, since: DateTime Option<&str> { - let link = word.trim_matches(|c: char| matches!(c, '"' | '\'' | '`' | '<' | '>' | '(' | ')' | '[' | ']' | '{' | '}' | ',' | '.' | ';' | ':' | '!' | '?' | '\u{201c}' | '\u{201d}' | '\u{2018}' | '\u{2019}')); + let mut link = word.trim_start_matches(['"', '\'', '`', '<', '(', '[', '{', '\u{201c}', '\u{2018}']); + loop { + link = link.trim_end_matches(['"', '\'', '`', '>', ',', '.', ';', ':', '!', '?', '\u{201d}', '\u{2019}']); + let unbalanced = [('(', ')'), ('[', ']'), ('{', '}')].iter().any(|&(open, close)| link.ends_with(close) && link.matches(close).count() > link.matches(open).count()); + if !unbalanced { + break; + } + link = &link[..link.len() - 1]; + } (link.starts_with("http://") || link.starts_with("https://")).then_some(link) } diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index 02b2a80..f55b5ee 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -1367,3 +1367,14 @@ fn k31_calls_counted_once() { } assert_eq!(outside(&decision, false), 0, "{decision}"); } + +/// K32 (map 16.25.8, Low 9): a link keeps its balanced parentheses; a closer is stripped only past its opener. +#[test] +fn k32_link_keeps_balanced_parens() { + fn links(text: &str) -> Vec<&str> { + text.split_whitespace().filter_map(link_of).collect() + } + assert_eq!(links("(see https://x.org/wiki/A_(b))"), ["https://x.org/wiki/A_(b)"]); + 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)"]); +} diff --git a/crates/mind-body/src/projection/read.rs b/crates/mind-body/src/projection/read.rs index d22452b..0d1ba5a 100644 --- a/crates/mind-body/src/projection/read.rs +++ b/crates/mind-body/src/projection/read.rs @@ -410,6 +410,13 @@ pub(crate) struct ReadEntry { #[serde(transparent)] pub struct ReadFixture(Vec); +impl ReadFixture { + /// Whether it records a read of this kind (`mind`, `campaign`, `repo`, `web`). + pub(crate) fn records(&self, kind: &str) -> bool { + self.0.iter().any(|entry| entry.kind == kind) + } +} + impl ReadSource for ReadFixture { fn read(&self, request: &ReadRequest, _since: DateTime) -> Result { let key = request.normal(); @@ -487,15 +494,15 @@ impl LiveReads { fn rulings(&self, slug: &str, since: DateTime) -> Result { let selection = Selection { projection: PROJECTION_DOCUMENT.to_owned(), descending: true, limit: Some(RULINGS_SHOWN), ..any_of(of_kind(PipelineKind::Ruling), "root", &[slug]) }; let PipelinePageItems::Documents(views) = self.ask(selection, None)? else { return Err(ReadFailure::Failed) }; - let shown: Vec = views - .iter() - .filter(|view| DateTime::parse_from_rfc3339(&view.admission.admitted_at).is_ok_and(|at| at.with_timezone(&Utc) >= since)) - .filter_map(|view| match &view.document { - PipelineDocument::Ruling(ruling) => Some(format!("- {}: {}", ruling.title.0, ruling.ruling.0)), - _ => None, - }) - .collect(); - if shown.is_empty() { Err(ReadFailure::NotFound) } else { Ok(shown.join("\n")) } + rulings_text( + views + .iter() + .filter(|view| DateTime::parse_from_rfc3339(&view.admission.admitted_at).is_ok_and(|at| at.with_timezone(&Utc) >= since)) + .filter_map(|view| match &view.document { + PipelineDocument::Ruling(ruling) => Some((ruling.title.0.as_str(), Some(ruling.ruling.0.as_str()))), + _ => None, + }), + ) } fn repo(&self, target: &str) -> Result { @@ -517,6 +524,13 @@ impl LiveReads { } } +/// What a campaign read shows, live and in the simulator alike (map 16.25.8): each ruling, newest first, at most +/// `RULINGS_SHOWN`, as `- {title}: {ruling}`, or `- {title}` when no ruling text is held. None is not found. +pub(crate) fn rulings_text<'a>(rulings: impl IntoIterator)>) -> Result { + let shown: Vec = rulings.into_iter().take(RULINGS_SHOWN as usize).map(|(title, ruling)| ruling.map_or_else(|| format!("- {title}"), |ruling| format!("- {title}: {ruling}"))).collect(); + if shown.is_empty() { Err(ReadFailure::NotFound) } else { Ok(shown.join("\n")) } +} + fn forge_text(forge: &dyn ForgeGet, path: &str) -> Result { let (status, body) = forge.get(path).map_err(|_| ReadFailure::Failed)?; match status { diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index fd6c1a3..6e6a267 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -35,6 +35,7 @@ use serde::Deserialize; use serde_json::{Value, json}; use super::commit; +use super::read::{self, ReadFailure, ReadRequest}; use super::harness::{Harness, Line, Message, OVERLAP_FLAG, cosine, pending_for, state_file, turn_markdown, usage_markdown, usage_total}; use super::select::Draw; use super::tuning; @@ -127,6 +128,24 @@ struct CastEntry { reads: Option, } +/// Her reads in a simulation (map 16.25.8): a campaign of hers from her domain fixture, the one owner of what her +/// campaign holds, formatted as a live read formats rulings (`read::rulings_text`); every other read from her recorded +/// reads. +struct CastReads<'a> { + recorded: &'a ReadFixture, + domain: Option<&'a DomainFacts>, +} + +impl ReadSource for CastReads<'_> { + fn read(&self, request: &ReadRequest, since: DateTime) -> Result { + let ReadRequest::Campaign(slug) = request else { return self.recorded.read(request, since) }; + let campaign = self.domain.and_then(|facts| facts.campaigns.iter().find(|campaign| campaign.slug.eq_ignore_ascii_case(slug))).ok_or(ReadFailure::NotFound)?; + let mut rulings: Vec<_> = campaign.rulings.iter().filter(|ruling| ruling.at >= since).collect(); + rulings.sort_by_key(|ruling| std::cmp::Reverse(ruling.at)); + read::rulings_text(rulings.into_iter().map(|ruling| (ruling.title.as_str(), ruling.ruling.as_deref()))) + } +} + struct Member { entry: CastEntry, state: Value, @@ -307,6 +326,10 @@ fn cast_of(plan: &SimFile, base: &Path) -> Result> { }; let mut members = Vec::new(); for entry in &plan.cast { + // One fixture owns what her campaign holds (map 16.25.8): her `[cast.domain]`, never a recorded read. + if entry.reads.as_ref().is_some_and(|reads| reads.records("campaign")) { + bail!("{}'s [[cast.read]] records a campaign read: what her campaign holds is her [cast.domain]'s campaigns, with each ruling's `ruling` text", entry.name); + } let state = state_file(&base.join(&entry.state), localpart(&entry.id))?; let rooms = if entry.rooms.is_empty() { plan.rooms.clone() } else { entry.rooms.clone() }; let (addressee, names_from) = match table.minds.iter().find(|row| row.matrix_id() == entry.id) { @@ -425,7 +448,8 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) }; let view = View { lines: &lines, viewer: &id, rooms: &member.rooms, seen: &seen[at] }; let names = Names(&member.addressee); - let organs = Organs { persona: None, chat: Some(&view), addressing: Some(&names), model: harness.model, domain: member.entry.domain.as_ref().map(|facts| facts as &dyn DomainSource), reads: member.entry.reads.as_ref().map(|reads| reads as &dyn ReadSource) }; + let reads = member.entry.reads.as_ref().map(|recorded| CastReads { recorded, domain: member.entry.domain.as_ref() }); + let organs = Organs { persona: None, chat: Some(&view), addressing: Some(&names), model: harness.model, domain: member.entry.domain.as_ref().map(|facts| facts as &dyn DomainSource), reads: reads.as_ref().map(|reads| reads as &dyn ReadSource) }; let report = project(&organs, &request, now).unwrap_or_else(|fault| json!({ "error": format!("{fault:#}") })); // Only the room she read is seen. seen[at].insert(here.clone(), lines.len()); diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index 4d85b69..44f9c09 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -805,3 +805,48 @@ fn k31_report_renders_accounting() { promises_markdown(&mut out, &turn); assert_eq!(out, "Committed:\n\n- closed c-r1-t1-1 kept by said: \"Thanks, Deru.\"\n- reaffirmed `c-r1-t1-2`: \"I'll send it tonight\"\n- blocked `c-r1-t1-3` by read 1: GameCult/Bifrost#89 on the forge\n- pruned 2 closed entries\n\n"); } + +/// K32 (map 16.25.8, Low 10): in the simulator, a campaign read is served from her `[cast.domain]`, the one owner of what +/// her campaign holds, formatted as a live read formats rulings: Plan F's Heimdall reads `heimdall-body` and gets its +/// ruling line, with the ruling's words when the fixture holds them, and nothing older than the window. +#[test] +fn k32_campaign_read_from_domain() { + let domain: DomainFacts = toml::from_str( + r#" +[[campaigns]] +slug = "heimdall-body" +[[campaigns.rulings]] +at = "2026-11-20T09:00:00Z" +title = "Account merge ships dark by default: notices and the merge pages stay off until the operator turns them on" +who = "operator_with_her" +[[campaigns.rulings]] +at = "2026-11-01T09:00:00Z" +title = "An old ruling, before the window" +who = "her" +"#, + ) + .unwrap(); + let recorded = ReadFixture::default(); + let since = DateTime::parse_from_rfc3339("2026-11-19T15:00:00Z").unwrap().with_timezone(&Utc); + let reads = CastReads { recorded: &recorded, domain: Some(&domain) }; + let read = |slug: &str| reads.read(&ReadRequest::Campaign(slug.into()), since); + assert_eq!(read("heimdall-body"), Ok("- Account merge ships dark by default: notices and the merge pages stay off until the operator turns them on".to_owned())); + assert_eq!(read("nowhere"), Err(ReadFailure::NotFound)); + let mut worded = domain.clone(); + worded.campaigns[0].rulings[0].ruling = Some("dark until the operator sets AccountMerge__Enabled".into()); + let reads = CastReads { recorded: &recorded, domain: Some(&worded) }; + assert_eq!(reads.read(&ReadRequest::Campaign("Heimdall-Body".into()), since), Ok("- Account merge ships dark by default: notices and the merge pages stay off until the operator turns them on: dark until the operator sets AccountMerge__Enabled".to_owned())); + // Every other read is her recorded one. + assert_eq!(reads.read(&ReadRequest::Repo("GameCult/Bifrost".into()), since), Err(ReadFailure::NotFound)); +} + +#[test] +fn k32_campaign_cast_read_refused() { + let dir = tempfile::tempdir().unwrap(); + let path = plan(dir.path(), "\"ruled\"", 2, ""); + let text = std::fs::read_to_string(&path).unwrap().replace("state = \"libby.json\"\n", "state = \"libby.json\"\n[[cast.read]]\nkind = \"campaign\"\ntarget = \"libby-body\"\ntext = \"- a ruling\"\n"); + std::fs::write(&path, text).unwrap(); + let model = silent(); + let harness = Harness { instance: "eureka".into(), persona: None, model: Some(&model), tuning: dir.path().join("persona-tuning.toml") }; + assert!(format!("{:#}", simulate(&harness, &path).unwrap_err()).contains("records a campaign read")); +} diff --git a/crates/mind-body/tests/public_surface.txt b/crates/mind-body/tests/public_surface.txt index 4204013..a3fe70a 100644 --- a/crates/mind-body/tests/public_surface.txt +++ b/crates/mind-body/tests/public_surface.txt @@ -305,6 +305,7 @@ mind_body::projection::read: # [derive (Clone , Debug , PartialEq , Eq , Seriali mind_body::projection::read: impl LiveReads mind_body::projection::read: impl LiveReads: fn new (client : HuginnClient , forge : Option < HttpForge >) -> Self mind_body::projection::read: impl ReadFailure +mind_body::projection::read: impl ReadFixture mind_body::projection::read: impl ReadRefusal mind_body::projection::read: impl ReadRequest mind_body::projection::read: impl ReadSource for LiveReads @@ -325,6 +326,7 @@ mind_body::projection::select: impl Section mind_body::projection::simulate: fn simulate (harness : & Harness , plan_path : & Path) -> Result < String > mind_body::projection::simulate: impl HeartbeatView for Names < '_ > mind_body::projection::simulate: impl MouthReader for View < '_ > +mind_body::projection::simulate: impl ReadSource for CastReads < '_ > mind_body::projection::tuning: const TUNING_FILE : & str mind_body::projection::tuning: const TUNING_ROOT : & str mind_body::projection::tuning: fn load (path : & Path) -> Result < Loaded >