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 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-21 23:12:35 +01:00
commit 5a7c686cda
8 changed files with 123 additions and 15 deletions

View file

@ -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<String>,
}
/// 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<U
let PipelineFacts::Ruling { title, .. } = &item.facts else { continue };
let at = admitted_at(&item)?;
if let Some(campaign) = campaigns.iter_mut().find(|campaign| campaign.slug == root(&item)) {
campaign.rulings.push(Ruled { at, title: title.0.clone(), who: who(&item.admission.provenance, her) });
campaign.rulings.push(Ruled { at, title: title.0.clone(), who: who(&item.admission.provenance, her), ruling: None });
}
}
}

View file

@ -231,7 +231,7 @@ fn k23_a_failed_read_fails_whole_and_project_leaves_the_section_out_and_reports_
fn k23_what_moved_before_the_window_is_not_in_the_digest() {
let facts = DomainFacts {
repos: vec![RepoFacts { repo: HUGINN.into(), pulls: vec![Pull { title: "Old".into(), opener: "kiko".into(), merged_at: Some(since() - Duration::hours(1)) }] }],
campaigns: vec![CampaignFacts { slug: "eureka-body".into(), rulings: vec![Ruled { at: since() - Duration::hours(1), title: "Old".into(), who: Who::Her }] }],
campaigns: vec![CampaignFacts { slug: "eureka-body".into(), rulings: vec![Ruled { at: since() - Duration::hours(1), title: "Old".into(), who: Who::Her, ruling: None }] }],
skipped: vec![],
};
assert!(texts(&facts).is_empty());
@ -300,7 +300,7 @@ fn who_is_the_mind_or_person_that_ran_it_never_a_faculty() {
}
// In words: people and Minds only.
let facts = DomainFacts {
campaigns: [Who::Unknown, Who::Her, Who::OperatorWithHer, Who::Operator].into_iter().enumerate().map(|(at, who)| CampaignFacts { slug: format!("camp-{at}"), rulings: vec![Ruled { at: now() - Duration::hours(at as i64 + 1), title: format!("Hated standing is kill on sight, part {at}"), who }] }).collect(),
campaigns: [Who::Unknown, Who::Her, Who::OperatorWithHer, Who::Operator].into_iter().enumerate().map(|(at, who)| CampaignFacts { slug: format!("camp-{at}"), rulings: vec![Ruled { at: now() - Duration::hours(at as i64 + 1), title: format!("Hated standing is kill on sight, part {at}"), who, ruling: None }] }).collect(),
..DomainFacts::default()
};
assert_eq!(texts(&facts), vec![

View file

@ -963,9 +963,18 @@ fn targets_in_view(request: &ReadRequest, packet: &Packet, prose: &str, reached:
}
/// The web address a word of text is, without the quotes and punctuation around it (Soul's R10: a line quoted in what
/// she heard ends its address with `"`, which made one link two).
/// she heard ends its address with `"`, which made one link two). A closing `)`, `]` or `}` is stripped only while the
/// link holds more of it than of its opener, the GFM autolink rule, so `A_(b)` keeps its parentheses (map 16.25.8).
fn link_of(word: &str) -> 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)
}

View file

@ -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)"]);
}

View file

@ -410,6 +410,13 @@ pub(crate) struct ReadEntry {
#[serde(transparent)]
pub struct ReadFixture(Vec<ReadEntry>);
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<Utc>) -> Result<String, ReadFailure> {
let key = request.normal();
@ -487,15 +494,15 @@ impl LiveReads {
fn rulings(&self, slug: &str, since: DateTime<Utc>) -> Result<String, ReadFailure> {
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<String> = 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<String, ReadFailure> {
@ -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<Item = (&'a str, Option<&'a str>)>) -> Result<String, ReadFailure> {
let shown: Vec<String> = 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<String, ReadFailure> {
let (status, body) = forge.get(path).map_err(|_| ReadFailure::Failed)?;
match status {

View file

@ -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<ReadFixture>,
}
/// 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<Utc>) -> Result<String, ReadFailure> {
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<Vec<Member>> {
};
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());

View file

@ -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"));
}

View file

@ -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 >