From 6aeebf8d45b46acb8f47c1ae3e869b3884b9d028 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 23:16:35 +0100 Subject: [PATCH] Digest: everything in a stated window, whole; no counts and no "and N more" Every ruling admitted and every pull request merged in the window, one item each with its whole title and who (people and Minds). Nothing open, no follow-up, no cut report or verdict. Live, the window opens at her last wake (a week at most). When the window's contents do not fit the guard, the window shrinks from its old end a whole minute at a time, never dropping an item inside it, and the section states the window shown; when not even the newest item fits, the section is left out and reported. domain_bytes 3000: her main window on her domain. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection.rs | 17 +- crates/mind-body/src/projection/domain.rs | 236 ++++++------------ .../mind-body/src/projection/domain/tests.rs | 104 ++++---- .../mind-body/src/projection/harness/tests.rs | 4 +- .../src/projection/interpret/tests.rs | 2 +- crates/mind-body/src/projection/select.rs | 82 ++++-- .../src/projection/simulate/tests.rs | 3 +- crates/mind-body/src/projection/tests.rs | 77 +++--- crates/mind-body/src/projection/tuning.rs | 6 +- crates/mind-body/tests/public_surface.txt | 1 + 10 files changed, 252 insertions(+), 280 deletions(-) diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index 4955ec1..98a5f91 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -244,18 +244,18 @@ fn own_addressee(addressing: Option<&dyn HeartbeatView>, own_sender: &str, publi /// What moved in her domain since her last wake, as lines, and what the read did: from when, how many lines, the repos it /// skipped (archived, not found, moved), or why it failed. A failed read shows her nothing and says so here; it is never /// rendered as nothing having moved (map 16.22.2). -fn read_domain(source: Option<&dyn DomainSource>, last_wake: Option>, now: DateTime, names: &domain::Names) -> (Vec, Value) { +fn read_domain(source: Option<&dyn DomainSource>, last_wake: Option>, now: DateTime, names: &domain::Names) -> (Option, Value) { let since = domain::since(last_wake, now); let Some(source) = source else { - return (Vec::new(), json!({ "read": false, "why": "no domain source is configured" })); + return (None, json!({ "read": false, "why": "no domain source is configured" })); }; match source.read(since, now) { Ok(facts) => { - let lines = domain::lines(&facts, since, now, names); - let report = json!({ "read": true, "since": since.to_rfc3339(), "lines": lines.len(), "skipped": facts.skipped }); - (lines, report) + let digest = domain::digest(&facts, since, now, names); + let report = json!({ "read": true, "since": digest.since.to_rfc3339(), "items": digest.items.len(), "skipped": facts.skipped }); + (Some(digest), report) } - Err(fault) => (Vec::new(), json!({ "read": false, "since": since.to_rfc3339(), "why": format!("{fault:#}") })), + Err(fault) => (None, json!({ "read": false, "since": since.to_rfc3339(), "why": format!("{fault:#}") })), } } @@ -331,6 +331,7 @@ fn packet_json(packet: &Packet) -> Value { "quotable": packet.quotable, "promises": packet.promises, "domain": packet.domain, + "domain_shown": packet.domain_shown, "context": packet.context, "stimulus": packet.stimulus, "arrival": packet.arrival, @@ -434,8 +435,8 @@ pub fn project(organs: &Organs, request: &Request, now: DateTime) -> Result let history = History { recent: request.recent.clone(), last: request.last_outcome.as_ref().and_then(outcome::outcome_of), ..History::default() }; let people = People { operators: &request.operators, minds: &request.minds, own_sender: &request.own_sender }; let names = domain::Names::of(&state, &people, &request.instance); - let (domain_lines, domain_report) = read_domain(organs.domain, request.last_wake, now, &names); - let inputs = Inputs { kind: request.kind, state: &state, room: &room, history: &history, observation: None, people, now, seed: request.seed, affordances: &[], domain: &domain_lines }; + let (digest, domain_report) = read_domain(organs.domain, request.last_wake, now, &names); + let inputs = Inputs { kind: request.kind, state: &state, room: &room, history: &history, observation: None, people, now, seed: request.seed, affordances: &[], domain: digest.as_ref() }; let can = affordances(organs, room_report["read"] == true, turn_room(&inputs), request.through); let inputs = Inputs { affordances: &can, ..inputs }; diff --git a/crates/mind-body/src/projection/domain.rs b/crates/mind-body/src/projection/domain.rs index 6cda6b2..cce7526 100644 --- a/crates/mind-body/src/projection/domain.rs +++ b/crates/mind-body/src/projection/domain.rs @@ -4,16 +4,17 @@ //! Sources: //! - Her repos are her in-force stewardship records, read through her own read door. A campaign's `repos` list is never //! read: it does not own what she stewards, and K23a found it disagreeing with the records that do. -//! - Campaigns enter only through their own documents held in her own mind: rulings admitted, follow-ups opened and -//! closed, cut reports and verdicts. A campaign in another Mind's mind is not in hers, whatever repo it names. -//! - The forge gives each stewarded repo's pull requests: title, opening account, when opened and when merged. A commit -//! is never read: every agent commit is the operator's account, so its author says nothing about who worked. +//! - Campaigns enter only through their own documents held in her own mind: the rulings admitted under them. A campaign in +//! another Mind's mind is not in hers, whatever repo it names. +//! - The forge gives each stewarded repo's merged pull requests: title, opening account, when merged. A commit is never +//! read: every agent commit is the operator's account, so its author says nothing about who worked. //! -//! Past tense only, and meaning over counts: merged and ruled titles are shown, because they happened, at most two a line -//! and the rest counted. What is still open (a pull request, a follow-up) is a count, never a title, so the section is -//! never a task queue. Cut reports and verdicts are never counted: a digest of the pipeline's machinery is the status -//! talk the Persona-only turn removed. "Who" is people and Minds, never a faculty: a pull request's opener, and for an -//! admission the Mind or person that ran it, read from its provenance (`Who`); when that cannot be told, no one is named. +//! Everything, in full, in a stated window (the operator: "Either show the full commit log or don't show it at all, +//! telling it a bunch of stuff moved without saying what is anti-signal"). The digest is one item per ruling admitted and +//! per pull request merged in the window, each with its whole title and who: people and Minds, never a faculty (`Who`). +//! It carries no count and no "and N more": nothing open, no follow-up, no cut report or verdict. Completeness comes from +//! the window, not from the item count: when the whole window does not fit the section's guard, Select shrinks the window +//! from its old end (`select::domain_lines`), never drops an item inside it, and states the window it shows. //! //! A stewarded repo that is archived, that the forge does not find, or that it answers with a redirect is skipped and //! reported, never shown to her. Any other failed read fails the whole read: `project` leaves the section out and its @@ -23,7 +24,7 @@ use std::collections::BTreeSet; use std::time::Duration; use anyhow::{Context, Result, anyhow, bail, ensure}; -use chrono::{DateTime, Utc}; +use chrono::{DateTime, DurationRound, Utc}; use cultnet_rs::Selection; use eureka_pipeline::PipelineKind; use eureka_state::HuginnClient; @@ -32,33 +33,24 @@ use huginn_mind::{Faculty, HuginnMindRequest, HuginnMindResponse, PipelineDocume use serde::{Deserialize, Serialize}; use serde_json::Value; -use super::select::{People, capitalized, clip, spoken}; +use super::select::{People, capitalized, spoken}; use crate::queue::{any_of, in_force, of_kind}; -/// The most lines the section shows, a counted line included (map 16.22.2). -pub(crate) const DOMAIN_LINES: usize = 6; -/// A merged or ruled title is clipped to this, with a mark where it was cut. -const TITLE_BYTES: usize = 120; -/// The most titles one line quotes; the rest of its titles are counted. -const TITLES_PER_LINE: usize = 2; -/// The window: since her last wake, at least a day and at most a week. -const WINDOW_MIN_HOURS: i64 = 24; +/// The window when she has not woken before, and the furthest back it ever reaches. const WINDOW_MAX_DAYS: i64 = 7; /// One page of the forge's pull requests, and how many pages of one repo a read takes: 200 moved in a week is past /// anything the coop has seen, and a repo past it fails the read rather than show part of it. const PULLS_PAGE: usize = 50; const PULLS_PAGES: usize = 4; -/// The page the mind's event read asks for. +/// The page the mind's ruling read asks for. const EVENTS_PAGE: u32 = 200; /// The whole of one forge call. const FORGE_TIMEOUT: Duration = Duration::from_secs(10); -/// Where the window opens: her last wake, held to at least a day and at most a week before `now`; a week when she has -/// not woken before. +/// Where the window opens: her last wake, at most a week before `now`; a week when she has not woken before. pub(crate) fn since(last_wake: Option>, now: DateTime) -> DateTime { let earliest = now - chrono::Duration::days(WINDOW_MAX_DAYS); - let latest = now - chrono::Duration::hours(WINDOW_MIN_HOURS); - last_wake.map_or(earliest, |at| at.clamp(earliest, latest)) + last_wake.map_or(earliest, |at| at.clamp(earliest, now)) } /// What moved in her domain, as read: the facts the section is rendered from. A harness fixture carries the same @@ -85,55 +77,35 @@ pub(crate) struct RepoFacts { pub(crate) pulls: Vec, } -/// A pull request as the forge lists it: its title, the account that opened it, when, and when it merged. +/// A pull request as the forge lists it: its title, the account that opened it, and when it merged (none when it has not). #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub(crate) struct Pull { pub(crate) title: String, pub(crate) opener: String, - pub(crate) opened_at: DateTime, #[serde(default)] pub(crate) merged_at: Option>, - /// Still open on the forge. - #[serde(default)] - pub(crate) open: bool, } -/// A campaign held in her mind, what was admitted under it in the window, and how many of its follow-ups stand open now. +/// A campaign held in her mind and the rulings admitted under it. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub(crate) struct CampaignFacts { pub(crate) slug: String, #[serde(default)] - pub(crate) events: Vec, - /// Its follow-ups in force now: told as "N things still open", never by name. - #[serde(default)] - pub(crate) open: usize, + pub(crate) rulings: Vec, } -/// One admission under a campaign: what it was, when, a ruling's title, and who ran it. +/// A ruling admitted: when, its whole title, and who ran the admission. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] -pub(crate) struct Admitted { - pub(crate) what: Moved, +pub(crate) struct Ruled { pub(crate) at: DateTime, - /// A ruling's title; nothing else carries one here, so no open item's words can reach her. - #[serde(default)] - pub(crate) title: Option, + pub(crate) title: String, #[serde(default)] pub(crate) who: Who, } -/// What an admission was. `Worked` is a cut report or a verdict: it says who worked on the campaign and is never counted. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub(crate) enum Moved { - Ruled, - FollowUpOpened, - FollowUpClosed, - Worked, -} - /// Who ran an admission, as people and Minds: her own organs (her Persona turn, her Self runs and what they dispatch), /// the operator driving a session on her behalf, or the operator; never a faculty. `Unknown` names no one. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] @@ -323,31 +295,14 @@ pub(crate) fn read(ask: &Ask, her: &str, forge: &dyn ForgeGet, since: DateTime = all(ask, &in_force(of_kind(PipelineKind::Campaign)))?.iter().map(|item| root(item).to_owned()).collect::>().into_iter().collect(); - let mut campaigns: Vec = slugs.iter().map(|slug| CampaignFacts { slug: slug.clone(), events: Vec::new(), open: 0 }).collect(); + let mut campaigns: Vec = slugs.iter().map(|slug| CampaignFacts { slug: slug.clone(), rulings: Vec::new() }).collect(); if !slugs.is_empty() { - let kinds = [PipelineKind::Ruling, PipelineKind::FollowUp, PipelineKind::CutReport, PipelineKind::Verdict, PipelineKind::Resolution]; - let selection = Selection { schemas: Some(kinds.iter().map(|kind| kind.type_id().to_owned()).collect()), ..Selection::default() }; let roots: Vec<&str> = slugs.iter().map(String::as_str).collect(); - for item in all(ask, &any_of(in_force(of_kind(PipelineKind::FollowUp)), "root", &roots))? { - if let Some(campaign) = campaigns.iter_mut().find(|campaign| campaign.slug == root(&item)) { - campaign.open += 1; - } - } - for item in newest(ask, &any_of(selection, "root", &roots), since)? { - let what = match &item.facts { - PipelineFacts::Ruling { .. } => Moved::Ruled, - PipelineFacts::FollowUp { .. } => Moved::FollowUpOpened, - PipelineFacts::CutReport { .. } | PipelineFacts::Verdict { .. } => Moved::Worked, - PipelineFacts::Resolution { subject, .. } if subject.kind == PipelineKind::FollowUp => Moved::FollowUpClosed, - _ => continue, - }; - let title = match &item.facts { - PipelineFacts::Ruling { title, .. } => Some(title.0.clone()), - _ => None, - }; + for item in newest(ask, &any_of(of_kind(PipelineKind::Ruling), "root", &roots), since)? { + 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.events.push(Admitted { what, at, title, who: who(&item.admission.provenance, her) }); + campaign.rulings.push(Ruled { at, title: title.0.clone(), who: who(&item.admission.provenance, her) }); } } } @@ -400,9 +355,8 @@ fn pulls(forge: &dyn ForgeGet, repo: &str, since: DateTime, now: DateTime, now: DateTime, now: DateTime) -> String { - let days = (now.date_naive() - since.date_naive()).num_days(); - match days { - ..=1 => "since yesterday".to_owned(), - 2..=6 => format!("since {}", since.format("%A")), - _ => format!("since last {}", since.format("%A")), +/// What a digest item is about: a stewarded repo or a campaign of hers, so a read can name it (16.22.3). +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] +#[serde(tag = "kind", content = "name", rename_all = "snake_case")] +pub(crate) enum About { + Repo(String), + Campaign(String), +} + +/// One thing that happened in her domain, in code's words, whole: a ruling admitted or a pull request merged. +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] +pub(crate) struct Item { + pub(crate) at: DateTime, + pub(crate) text: String, + pub(crate) about: About, +} + +/// `at` down to its whole minute: a window opens on a minute, so the minute it states holds everything after it. +pub(crate) fn floor_minute(at: DateTime) -> DateTime { + at.duration_trunc(chrono::Duration::minutes(1)).unwrap_or(at) +} + +/// What a read of her domain gave the packet: every item from `since` (a whole minute) to `now`, newest first. +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct Digest { + pub(crate) since: DateTime, + pub(crate) now: DateTime, + pub(crate) items: Vec, +} + +/// Who ran a ruling's admission, in words after "ruled": by the operator and her where the operator drove a session of +/// hers, by the operator, in her own session; nothing when no one can be told. +fn by(who: Who, names: &Names) -> String { + match who { + Who::OperatorWithHer => format!(" by {} and {}", names.operator, names.her), + Who::Operator => format!(" by {}", names.operator), + Who::Her => format!(" in {}'s own session", names.her), + Who::Unknown => String::new(), } } -fn plural(n: usize, one: &str, many: &str) -> String { - format!("{n} {}", if n == 1 { one } else { many }) -} - -/// Names joined as a sentence says them: "a", "a and b", "a, b and c". -fn joined(names: &[String]) -> String { - match names { - [] => String::new(), - [one] => one.clone(), - [rest @ .., last] => format!("{} and {last}", rest.join(", ")), - } -} - -/// At most `TITLES_PER_LINE` titles, each clipped and quoted, and the rest counted. -fn titles(all: &[&str]) -> String { - let mut shown: Vec = all.iter().take(TITLES_PER_LINE).map(|title| spoken(&clip(title, TITLE_BYTES))).collect(); - if all.len() > TITLES_PER_LINE { - shown.push(format!("{} more", all.len() - TITLES_PER_LINE)); - } - joined(&shown) -} - -fn within(at: DateTime, since: DateTime, now: DateTime) -> bool { - since <= at && at <= now -} - -/// Who worked on a campaign, in words, from who ran what moved: "Meta and Nibu" where the operator drove, "Nibu's own -/// sessions" where only hers ran, "Meta" alone; none when no one can be told. -fn workers(events: &[&Admitted], names: &Names) -> Option { - let has = |who: Who| events.iter().any(|event| event.who == who); - let operator = has(Who::Operator) || has(Who::OperatorWithHer); - let her = has(Who::Her) || has(Who::OperatorWithHer); - match (operator, her) { - (true, true) => Some(format!("{} and {}", names.operator, names.her)), - (true, false) => Some(names.operator.clone()), - (false, true) => Some(format!("{}'s own sessions", names.her)), - (false, false) => None, - } -} - -/// One line per stewarded repo and per campaign that moved from `since` to `now`, newest activity first, each in code's -/// words: merged and ruled titles, at most two and the rest counted, and what still stands open as a count. A repo or -/// campaign where nothing moved, or where nothing moved that can be told (no title and no one to name), has no line. -pub(crate) fn lines(facts: &DomainFacts, since: DateTime, now: DateTime, names: &Names) -> Vec { - let when = since_words(since, now); - let mut dated: Vec<(DateTime, String)> = Vec::new(); +/// Every ruling admitted and every pull request merged from `since` to `now`, one item each, newest first, each whole: +/// `- lodur: ruled by Meta and Nibu: "…"` and `- GameCult/AquaSynth: merged "…", opened by aqua`. Nothing is counted. +pub(crate) fn digest(facts: &DomainFacts, since: DateTime, now: DateTime, names: &Names) -> Digest { + let since = floor_minute(since); + let within = |at: DateTime| since <= at && at <= now; + let mut items: Vec = Vec::new(); for repo in &facts.repos { - let merged: Vec<&Pull> = repo.pulls.iter().filter(|pull| pull.merged_at.is_some_and(|at| within(at, since, now))).collect(); - let opened = repo.pulls.iter().filter(|pull| pull.open && within(pull.opened_at, since, now)).count(); - let latest = merged.iter().filter_map(|pull| pull.merged_at).chain(repo.pulls.iter().filter(|pull| pull.open && within(pull.opened_at, since, now)).map(|pull| pull.opened_at)).max(); - let Some(latest) = latest else { continue }; - let mut parts = Vec::new(); - if !merged.is_empty() { - let openers: Vec = merged.iter().map(|pull| pull.opener.clone()).collect::>().into_iter().collect(); - let named: Vec<&str> = merged.iter().map(|pull| pull.title.as_str()).collect(); - parts.push(format!("{} merged {when} ({}), opened by {}", plural(merged.len(), "pull request", "pull requests"), titles(&named), joined(&openers))); + for pull in &repo.pulls { + if let Some(at) = pull.merged_at.filter(|at| within(*at)) { + items.push(Item { at, text: format!("- {}: merged {}, opened by {}", repo.repo, spoken(pull.title.trim()), pull.opener), about: About::Repo(repo.repo.clone()) }); + } } - if opened > 0 { - parts.push(format!("{} opened {when} and not merged yet", plural(opened, "pull request", "pull requests"))); - } - dated.push((latest, format!("- {}: {}.", repo.repo, parts.join("; ")))); } for campaign in &facts.campaigns { - let events: Vec<&Admitted> = campaign.events.iter().filter(|event| within(event.at, since, now)).collect(); - let Some(latest) = events.iter().map(|event| event.at).max() else { continue }; - let ruled: Vec<&str> = events.iter().filter(|event| event.what == Moved::Ruled).filter_map(|event| event.title.as_deref()).collect(); - let mut parts = Vec::new(); - match (workers(&events, names), ruled.is_empty()) { - (Some(who), true) => parts.push(format!("{who} worked on it {when}")), - (Some(who), false) => parts.push(format!("{who} worked on it {when}; ruled {}", titles(&ruled))), - (None, false) => parts.push(format!("ruled {when} {}", titles(&ruled))), - (None, true) => continue, + for ruled in campaign.rulings.iter().filter(|ruled| within(ruled.at)) { + items.push(Item { at: ruled.at, text: format!("- {}: ruled{}: {}", campaign.slug, by(ruled.who, names), spoken(ruled.title.trim())), about: About::Campaign(campaign.slug.clone()) }); } - if campaign.open > 0 { - parts.push(plural(campaign.open, "thing still open", "things still open")); - } - dated.push((latest, format!("- {}: {}.", campaign.slug, parts.join("; ")))); } - // Newest activity first; a tie keeps the order read. - dated.sort_by_key(|(at, _)| std::cmp::Reverse(*at)); - dated.into_iter().map(|(_, line)| line).collect() + // Newest first; a tie keeps the order read. + items.sort_by_key(|item| std::cmp::Reverse(item.at)); + Digest { since, now, items } } #[cfg(test)] diff --git a/crates/mind-body/src/projection/domain/tests.rs b/crates/mind-body/src/projection/domain/tests.rs index 11c2f5b..dbab7b4 100644 --- a/crates/mind-body/src/projection/domain/tests.rs +++ b/crates/mind-body/src/projection/domain/tests.rs @@ -91,6 +91,11 @@ fn names() -> Names { Names { her: "Eureka".into(), operator: "Meta".into() } } +/// The digest's items, as text, from `since()` to `now()`. +fn texts(facts: &DomainFacts) -> Vec { + digest(facts, since(), now(), &names()).items.into_iter().map(|item| item.text).collect() +} + fn read_through(mind: &TestMind, forge: &dyn ForgeGet) -> Result { read(&|selection: &Selection| mind.query(selection), &mind.instance().0, forge, since(), now()) } @@ -111,7 +116,7 @@ fn ruled(label: &str, title: &str) -> PipelineDocument { } /// A mind where an unnamed agent opened two follow-ups and closed one, and her own Self run's Soul ruled once, all inside -/// the window. +/// the window: the follow-ups are never shown, the ruling is. fn worked_on() -> TestMind { let mind = TestMind::seeded(); mind.committed(vec![spec("x")]); @@ -124,29 +129,27 @@ fn worked_on() -> TestMind { } #[test] -fn the_window_opens_at_her_last_wake_within_a_day_and_a_week() { +fn the_window_opens_at_her_last_wake_at_most_a_week_back() { let now = now(); assert_eq!(super::since(None, now), now - Duration::days(7), "never woken: a week"); assert_eq!(super::since(Some(now - Duration::days(30)), now), now - Duration::days(7)); - assert_eq!(super::since(Some(now - Duration::minutes(10)), now), now - Duration::hours(24)); - assert_eq!(super::since(Some(now - Duration::days(2)), now), now - Duration::days(2)); + assert_eq!(super::since(Some(now - Duration::minutes(10)), now), now - Duration::minutes(10), "her last wake, however recent"); } #[test] -fn k23_her_door_and_the_forge_render_merged_and_ruled_titles_and_counts_of_what_is_open() { +fn k23_her_door_and_the_forge_give_every_merged_and_ruled_item_whole_and_nothing_open() { let mind = worked_on(); let forge = Forge::default().live(HUGINN, json!([ pull("Persona: the domain digest", "kiko", now() - Duration::days(2), Some(now() - Duration::minutes(30))), pull("OPEN-PR-TITLE-SENTINEL", "nibu", now() - Duration::hours(3), None), ])); let facts = read_through(&mind, &forge).unwrap(); - let lines = lines(&facts, since(), now(), &names()); - assert_eq!(lines, vec![ - "- GameCult/Huginn: 1 pull request merged since Tuesday (\"Persona: the domain digest\"), opened by kiko; 1 pull request opened since Tuesday and not merged yet.".to_owned(), - "- eureka-body: Eureka's own sessions worked on it since Tuesday; ruled \"The digest shows what merged\"; 1 thing still open.".to_owned(), + assert_eq!(texts(&facts), vec![ + "- GameCult/Huginn: merged \"Persona: the domain digest\", opened by kiko".to_owned(), + "- eureka-body: ruled in Eureka's own session: \"The digest shows what merged\"".to_owned(), ]); - let all = lines.join("\n"); - assert!(!all.contains("SEALED-FOLLOW-UP-ITEM") && !all.contains("OPEN-PR-TITLE-SENTINEL"), "nothing open is shown by name: {all}"); + let all = texts(&facts).join("\n"); + assert!(!all.contains("SEALED-FOLLOW-UP-ITEM") && !all.contains("OPEN-PR-TITLE-SENTINEL"), "nothing open is shown: {all}"); // "Who" is the pull request's opener; no commit is ever read, so a commit's author can say nothing. assert!(forge.asked.borrow().iter().all(|path| !path.contains("/commits") && !path.contains("/git/")), "{:?}", forge.asked.borrow()); } @@ -162,8 +165,7 @@ fn k23_only_her_in_force_stewardships_name_her_repos_never_a_campaign_list() { .live("GameCult/NotHers", json!([pull("NOT-HERS-SENTINEL", "void", now() - Duration::days(1), Some(now() - Duration::hours(5)))])); let facts = read_through(&mind, &forge).unwrap(); assert!(!forge.asked_about("NotHers"), "a campaign's repo list is never read: {:?}", forge.asked.borrow()); - let all = lines(&facts, since(), now(), &names()).join("\n"); - assert!(all.contains("- GameCult/Lonely: 1 pull request merged since Tuesday (\"Lonely: first light\"), opened by aqua.") && !all.contains("NOT-HERS"), "{all}"); + assert_eq!(texts(&facts), vec!["- GameCult/Lonely: merged \"Lonely: first light\", opened by aqua".to_owned()]); } #[test] @@ -182,8 +184,7 @@ fn k23_a_campaign_held_in_another_minds_mind_never_appears_in_hers() { theirs.committed(vec![ruled("r1", "THEIR-RULING-SENTINEL")]); let forge = Forge::default().live(HUGINN, json!([])); let facts = read_through(&hers, &forge).unwrap(); - assert!(facts.campaigns.is_empty(), "{facts:?}"); - assert!(!lines(&facts, since(), now(), &names()).join("\n").contains("THEIR-RULING-SENTINEL")); + assert!(facts.campaigns.is_empty() && texts(&facts).is_empty(), "{facts:?}"); } #[test] @@ -202,7 +203,7 @@ fn k23_an_archived_or_missing_or_moved_repo_renders_nothing_and_is_reported() { ); assert!(facts.repos.is_empty(), "a skipped repo's pull requests are not read: {facts:?}"); assert!(!forge.asked.borrow().iter().any(|path| path.contains("/pulls")), "{:?}", forge.asked.borrow()); - assert!(lines(&facts, since(), now(), &names()).is_empty()); + assert!(texts(&facts).is_empty()); } #[test] @@ -218,27 +219,28 @@ fn k23_a_failed_read_fails_whole_and_project_leaves_the_section_out_and_reports_ read(&|selection: &Selection| self.0.query(selection), &self.0.instance().0, &Down, since, now) } } - let (lines, report) = crate::projection::read_domain(Some(&Live(&mind)), None, now(), &names()); - assert!(lines.is_empty(), "{lines:?}"); + let (digest, report) = crate::projection::read_domain(Some(&Live(&mind)), None, now(), &names()); + assert!(digest.is_none()); assert_eq!((report["read"].clone(), report["why"].as_str().is_some_and(|why| why.contains("forge"))), (json!(false), true), "{report}"); - let (lines, report) = crate::projection::read_domain(None, None, now(), &names()); - assert!(lines.is_empty() && report["read"] == json!(false), "{report}"); + let (digest, report) = crate::projection::read_domain(None, None, now(), &names()); + assert!(digest.is_none() && report["read"] == json!(false), "{report}"); } #[test] -fn k23_what_moved_before_the_window_is_not_shown() { +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(), opened_at: since() - Duration::days(3), merged_at: Some(since() - Duration::hours(1)), open: false }] }], - campaigns: vec![CampaignFacts { slug: "eureka-body".into(), events: vec![Admitted { what: Moved::Ruled, at: since() - Duration::hours(1), title: Some("Old".into()), who: Who::Her }], open: 0 }], + 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 }] }], skipped: vec![], }; - assert!(lines(&facts, since(), now(), &names()).is_empty()); + assert!(texts(&facts).is_empty()); } +/// Every item whole, newest first: no title is clipped, and nothing is counted. #[test] -fn k23_lines_run_newest_first_and_clip_long_titles_and_count_past_two() { +fn k23_items_run_newest_first_whole_and_uncounted() { let long = "x".repeat(300); - let merged = |hours: i64, title: &str| Pull { title: title.into(), opener: "kiko".into(), opened_at: now() - Duration::days(2), merged_at: Some(now() - Duration::hours(hours)), open: false }; + let merged = |hours: i64, title: &str| Pull { title: title.into(), opener: "kiko".into(), merged_at: Some(now() - Duration::hours(hours)) }; let facts = DomainFacts { repos: vec![ RepoFacts { repo: "GameCult/Older".into(), pulls: vec![merged(30, "a")] }, @@ -246,10 +248,10 @@ fn k23_lines_run_newest_first_and_clip_long_titles_and_count_past_two() { ], ..DomainFacts::default() }; - let lines = lines(&facts, since(), now(), &names()); - assert!(lines[0].starts_with("- GameCult/Newer: 4 pull requests merged since Tuesday (") && lines[1].starts_with("- GameCult/Older"), "{lines:?}"); - let clipped = format!("{}…", "x".repeat(TITLE_BYTES - '…'.len_utf8())); - assert!(lines[0].contains(&format!("\"{clipped}\", \"b\" and 2 more), opened by kiko.")), "{}", lines[0]); + let texts = texts(&facts); + assert_eq!(texts.len(), 5, "{texts:?}"); + assert_eq!(texts[0], format!("- GameCult/Newer: merged \"{long}\", opened by kiko")); + assert!(texts[4].starts_with("- GameCult/Older"), "{texts:?}"); } #[test] @@ -261,12 +263,10 @@ fn a_fixture_reads_as_the_live_facts_do() { [[repos.pulls]] title = "Docs: passages made true" opener = "nibu" - opened_at = "2026-10-08T10:00:00Z" merged_at = "2026-10-09T09:00:00Z" [[campaigns]] slug = "aetheria-release" - [[campaigns.events]] - what = "ruled" + [[campaigns.rulings]] at = "2026-10-09T08:00:00Z" title = "Ship v0.2.0" who = "operator_with_her" @@ -277,9 +277,9 @@ fn a_fixture_reads_as_the_live_facts_do() { ) .unwrap(); assert_eq!(DomainSource::read(&facts, since(), now()).unwrap(), facts); - assert_eq!(lines(&facts, since(), now(), &names()), vec![ - "- GameCult/Aetheria: 1 pull request merged since Tuesday (\"Docs: passages made true\"), opened by nibu.".to_owned(), - "- aetheria-release: Meta and Eureka worked on it since Tuesday; ruled \"Ship v0.2.0\".".to_owned(), + assert_eq!(texts(&facts), vec![ + "- GameCult/Aetheria: merged \"Docs: passages made true\", opened by nibu".to_owned(), + "- aetheria-release: ruled by Meta and Eureka: \"Ship v0.2.0\"".to_owned(), ]); assert!(toml::from_str::("[[repos]]\nrepo = \"x\"\nwho = \"y\"\n").is_err(), "an unknown key refuses the fixture"); } @@ -297,25 +297,15 @@ fn who_is_the_mind_or_person_that_ran_it_never_a_faculty() { for (agent, session) in [("eureka-self", "swarm-shakedown-2026-10-31"), ("hands", "x"), ("aqua", "x"), ("nibuish-hands", "x")] { assert_eq!(super::who(&provenance(Faculty::Hands, agent, session), "nibu"), Who::Unknown, "{agent}"); } -} - -/// The coordinator's rule for the digest's words: no faculty name and no count of the pipeline's machinery in any line, -/// whoever ran what moved; ruling titles and "N things still open" are what it says. -#[test] -fn no_rendered_digest_names_a_faculty_or_counts_cut_reports_or_verdicts() { - let at = |hours: i64| now() - Duration::hours(hours); - let mut campaigns = Vec::new(); - for (index, who) in [Who::Unknown, Who::Her, Who::OperatorWithHer, Who::Operator].into_iter().enumerate() { - let events = [Moved::Ruled, Moved::FollowUpOpened, Moved::FollowUpClosed, Moved::Worked].into_iter().map(|what| Admitted { what, at: at(index as i64 + 1), title: (what == Moved::Ruled).then(|| format!("Hated standing is kill on sight, part {index}")), who }).collect(); - campaigns.push(CampaignFacts { slug: format!("camp-{index}"), events, open: 3 }); - } - campaigns.push(CampaignFacts { slug: "quiet-machinery".into(), events: vec![Admitted { what: Moved::Worked, at: at(1), title: None, who: Who::Unknown }], open: 9 }); - let facts = DomainFacts { campaigns, ..DomainFacts::default() }; - let all = lines(&facts, since(), now(), &names()).join("\n"); - for banned in ["Hands", "Soul", "Imagination", "Self session", "Eyes", "Life", "cut report", "verdict", "follow-up"] { - assert!(!all.contains(banned), "{banned}: {all}"); - } - assert!(all.contains("- camp-1: Eureka's own sessions worked on it since Tuesday; ruled \"Hated standing is kill on sight, part 1\"; 3 things still open."), "{all}"); - assert!(all.contains("- camp-2: Meta and Eureka worked on it") && all.contains("- camp-3: Meta worked on it") && all.contains("- camp-0: ruled since Tuesday \"Hated standing"), "{all}"); - assert!(!all.contains("quiet-machinery"), "machinery alone with no one to name and no title is no line: {all}"); + // 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(), + ..DomainFacts::default() + }; + assert_eq!(texts(&facts), vec![ + "- camp-0: ruled: \"Hated standing is kill on sight, part 0\"".to_owned(), + "- camp-1: ruled in Eureka's own session: \"Hated standing is kill on sight, part 1\"".to_owned(), + "- camp-2: ruled by Meta and Eureka: \"Hated standing is kill on sight, part 2\"".to_owned(), + "- camp-3: ruled by Meta: \"Hated standing is kill on sight, part 3\"".to_owned(), + ]); } diff --git a/crates/mind-body/src/projection/harness/tests.rs b/crates/mind-body/src/projection/harness/tests.rs index a5ebb52..99828f9 100644 --- a/crates/mind-body/src/projection/harness/tests.rs +++ b/crates/mind-body/src/projection/harness/tests.rs @@ -377,14 +377,14 @@ fn soul_k9_each_outcome_fixture_opens_the_packet_with_his_words_verbatim() { fn k23_a_room_fixtures_domain_renders_without_the_forge() { let dir = tempfile::tempdir().unwrap(); let text = format!( - "{}\n[[domain.repos]]\nrepo = \"GameCult/Lodur\"\n[[domain.repos.pulls]]\ntitle = \"Reflex: the knee bends first\"\nopener = \"nibu\"\nopened_at = \"2026-11-18T10:00:00Z\"\nmerged_at = \"2026-11-19T12:00:00Z\"\n[[domain.skipped]]\nrepo = \"GameCult/Aetheria-legacy\"\nwhy = \"archived\"\n", + "{}\n[[domain.repos]]\nrepo = \"GameCult/Lodur\"\n[[domain.repos.pulls]]\ntitle = \"Reflex: the knee bends first\"\nopener = \"nibu\"\nmerged_at = \"2026-11-19T12:00:00Z\"\n[[domain.skipped]]\nrepo = \"GameCult/Aetheria-legacy\"\nwhy = \"archived\"\n", std::fs::read_to_string(fixtures().join("rooms/quiet-beat.toml")).unwrap() ); let fixture = Fixture::parse(&text).unwrap(); let organs = Organs { persona: None, chat: Some(&fixture), addressing: fixture.addressee(), model: None, domain: fixture.domain() }; let report = project(&organs, &fixture_request(&harness(dir.path(), None, None), &fixture, Some(control()), 1, None, Through::Projector), fixture.now).unwrap(); let context = report["packet"]["context"].as_str().unwrap(); - assert!(context.contains("domain lately:\n- GameCult/Lodur: 1 pull request merged since last Friday (\"Reflex: the knee bends first\"), opened by nibu."), "{context}"); + assert!(context.contains("domain lately:\n- Everything merged and ruled since Friday 13 November, 15:00 UTC:\n- GameCult/Lodur: merged \"Reflex: the knee bends first\", opened by nibu"), "{context}"); assert_eq!((report["domain"]["read"].clone(), report["domain"]["skipped"][0]["why"].clone()), (json!(true), json!("archived")), "{}", report["domain"]); assert!(!context.contains("Aetheria-legacy"), "a skipped repo is reported, never shown to her"); diff --git a/crates/mind-body/src/projection/interpret/tests.rs b/crates/mind-body/src/projection/interpret/tests.rs index f2e1cbe..0057b45 100644 --- a/crates/mind-body/src/projection/interpret/tests.rs +++ b/crates/mind-body/src/projection/interpret/tests.rs @@ -26,7 +26,7 @@ fn packet_in(kind: TurnKind, state: &Value, room: &Room, seed: u64) -> Packet { let minds = vec![HER.to_owned(), NIBU.to_owned(), VOID.to_owned(), LIBBY.to_owned(), KIKO.to_owned()]; let operators = vec!["@meta:gamecult.org".to_owned()]; let history = History::default(); - select(&Inputs { kind, state, room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: HER }, now: now(), seed, affordances: &[Affordance::Perceive, Affordance::Speak], domain: &[] }, &Tuning::default()) + select(&Inputs { kind, state, room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: HER }, now: now(), seed, affordances: &[Affordance::Perceive, Affordance::Speak], domain: None }, &Tuning::default()) } /// Heimdall: the control state, he/him. diff --git a/crates/mind-body/src/projection/select.rs b/crates/mind-body/src/projection/select.rs index 642b528..def2cb7 100644 --- a/crates/mind-body/src/projection/select.rs +++ b/crates/mind-body/src/projection/select.rs @@ -35,7 +35,7 @@ use serde_json::Value; use unicode_segmentation::UnicodeSegmentation; use super::Affordance; -use super::domain::DOMAIN_LINES; +use super::domain::{About, Digest, Item, floor_minute}; use super::outcome::{self, Outcome}; use super::tuning::{LensWeights, Tuning}; use crate::address::localpart; @@ -223,9 +223,9 @@ pub(crate) struct Inputs<'a> { pub seed: u64, /// What this turn can do (`super::affordances`). pub affordances: &'a [Affordance], - /// What moved in her domain lately, one line each, newest first (`domain::lines`, map 16.22.2): empty when nothing + /// What moved in her domain lately, every item of the window, newest first (`domain::digest`, map 16.22.2): none when /// moved, and when the read failed, which the report says. - pub domain: &'a [String], + pub domain: Option<&'a Digest>, } /// Where a turn begins. @@ -340,6 +340,8 @@ pub(crate) struct Packet { pub promises: Vec, /// The lines of her domain the packet shows her, for the Interpreter's view by id (map 16.22.2). pub domain: Vec, + /// The window the domain section shows and what it left out: the report's, never a model's. + pub domain_shown: DomainShown, /// What came of her last turn that the outcome's guard left out, whole: counted in the packet's last outcome line and /// reported here (map 16.20.5, I16.11), never shown to a model. pub unshown: Vec, @@ -396,6 +398,17 @@ pub(crate) struct Promised { pub(crate) struct DomainLine { pub id: String, pub line: String, + /// What it is about, for a read of it (16.22.3). + pub about: About, +} + +/// The window the domain section shows (its opening, none when no section), how many items of the read it left out by +/// shrinking the window, and why it was left out whole, when it was. +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)] +pub(crate) struct DomainShown { + pub since: Option, + pub left_out: usize, + pub omitted: Option<&'static str>, } /// What the messages to her cost past the caps: bytes over the stimulus and heard caps, the older messages to her the @@ -1824,27 +1837,50 @@ fn open_promises(inputs: &Inputs, her: Forms, bodies: &[String], context: &mut C listed } -/// What moved in her domain lately (map 16.22.2): the lines `domain::lines` rendered, newest first, under the section's -/// own guard (`domain_bytes`, I16.8) and at most `DOMAIN_LINES` lines. Past either the newest that fit are shown and the -/// rest counted, never dropped silently (I16.11). The lines shown are the Interpreter's, by id. -fn domain_lines(inputs: &Inputs, her: Forms, context: &mut Context) -> Vec { - let lines = inputs.domain; - let count = |more: usize| format!("- {more} more {} of {} domain moved, not shown here.", if more == 1 { "part" } else { "parts" }, her.poss); +/// The window a digest shows, in words from where `now` stands: "since 14:00 UTC today", "since yesterday, 21:30 UTC", +/// "since Tuesday 17 November, 09:00 UTC". +fn window_words(start: DateTime, now: DateTime) -> String { + let time = start.format("%H:%M UTC"); + match (now.date_naive() - start.date_naive()).num_days() { + ..=0 => format!("since {time} today"), + 1 => format!("since yesterday, {time}"), + _ => format!("since {}, {time}", start.format("%A %-d %B")), + } +} + +/// What moved in her domain lately (map 16.22.2): every item of the digest, whole, newest first, under a line that states +/// the window, all under the section's own guard (`domain_bytes`, I16.8). Nothing is counted and no item inside the window +/// is dropped: when the whole window does not fit, the window shrinks from its old end, a whole minute at a time, until +/// everything in it fits, and the line states the window shown. When not even the newest item fits, the section is left +/// out and the report says so. The items shown are the Interpreter's, by id. +fn domain_lines(inputs: &Inputs, her: Forms, context: &mut Context) -> (Vec, DomainShown) { + let mut shown = DomainShown::default(); + let Some(digest) = inputs.domain.filter(|digest| !digest.items.is_empty()) else { return (Vec::new(), shown) }; let room = context.room(Section::Domain).saturating_sub(Section::Domain.heading(her).len() + 1); - let cost = |shown: usize| lines[..shown].iter().map(|line| line.len() + 1).sum::() + if shown < lines.len() { count(lines.len() - shown).len() + 1 } else { 0 }; - let fits = |shown: usize| cost(shown) <= room && shown + usize::from(shown < lines.len()) <= DOMAIN_LINES; - let shown = (0..=lines.len()).rev().find(|&shown| fits(shown)).unwrap_or(0); - let mut listed = Vec::new(); - for line in &lines[..shown] { - if context.push(Section::Domain, line.clone()) { - listed.push(DomainLine { id: format!("d{}", listed.len() + 1), line: line.clone() }); + let mut start = digest.since; + loop { + let kept: Vec<&Item> = digest.items.iter().filter(|item| item.at >= start).collect(); + let Some(oldest) = kept.last() else { + context.bound[Section::Domain as usize] = true; + shown.omitted = Some("not even the newest item fits the section's guard"); + shown.left_out = digest.items.len(); + return (Vec::new(), shown); + }; + let head = format!("- Everything merged and ruled {}:", window_words(start, digest.now)); + if head.len() + 1 + kept.iter().map(|item| item.text.len() + 1).sum::() <= room { + context.push(Section::Domain, head); + let listed = kept.iter().enumerate().map(|(at, item)| { + context.push(Section::Domain, item.text.clone()); + DomainLine { id: format!("d{}", at + 1), line: item.text.clone(), about: item.about.clone() } + }); + let listed: Vec = listed.collect(); + shown.since = Some(start.to_rfc3339()); + shown.left_out = digest.items.len() - kept.len(); + context.bound[Section::Domain as usize] |= shown.left_out > 0; + return (listed, shown); } + start = floor_minute(oldest.at) + chrono::Duration::minutes(1); } - if shown < lines.len() { - context.bound[Section::Domain as usize] = true; - context.push(Section::Domain, count(lines.len() - shown)); - } - listed } /// The people's guard: its heading and the bonds a packet shows in full, each a summary, its head, the act of turning to @@ -2063,7 +2099,7 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { _ => named.push((also, turned.is_some())), } } - let domain = domain_lines(inputs, her, &mut context); + let (domain, domain_shown) = domain_lines(inputs, her, &mut context); // Here's room lines take its room by priority (map 16.21): the conversation, which opens with whoever turned to her // here; the arrivals on the also-here line (its least line, reserved); the pronouns, clipped to what is left; the // other names present. They are rendered in reading order: the pronouns, the conversation, the also-here line. @@ -2143,5 +2179,5 @@ pub(crate) fn select(inputs: &Inputs, tuning: &Tuning) -> Packet { .map(|(at, (event, room, text))| Amendable { id: format!("a{}", at + 1), event: event.clone(), room: room.clone(), text: text.clone() }) .collect(); let selected = taken.into_iter().map(|candidate| Pick { id: candidate.id, pool: candidate.pool, log_score: candidate.log_score }).collect(); - Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections: context.sizes(), stimulus, heard, bridged, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning), affordances: inputs.affordances.to_vec(), room: turn_room(inputs).map(str::to_owned), room_kind: turn_room(inputs).map_or(RoomKind::Public, |room| room_kind(inputs, room)), bodies, private, clipped, amendable, quotable, promises, domain, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } + Packet { kind: inputs.kind, seed: inputs.seed, lens, name, voice, context: context.render(), sections: context.sizes(), stimulus, heard, bridged, overflow, present: present_names, ids, selected, forms: her, people: people_in_view(inputs, tuning), affordances: inputs.affordances.to_vec(), room: turn_room(inputs).map(str::to_owned), room_kind: turn_room(inputs).map_or(RoomKind::Public, |room| room_kind(inputs, room)), bodies, private, clipped, amendable, quotable, promises, domain, domain_shown, arrival, speaking: conversation.speaking.unwrap_or_default(), unshown } } diff --git a/crates/mind-body/src/projection/simulate/tests.rs b/crates/mind-body/src/projection/simulate/tests.rs index 4acf6df..374fec2 100644 --- a/crates/mind-body/src/projection/simulate/tests.rs +++ b/crates/mind-body/src/projection/simulate/tests.rs @@ -666,7 +666,6 @@ repo = "GameCult/Lodur" [[cast.domain.repos.pulls]] title = "Reflex: the knee bends first" opener = "nibu" -opened_at = "2026-11-18T10:00:00Z" merged_at = "2026-11-19T12:00:00Z" [[cast]] id = "{LIBBY}" @@ -684,7 +683,7 @@ says = "good afternoon, everyone" let model = silent(); run_plan(&path, &model); let projector: Vec = model.calls.borrow().iter().filter(|(_, prompt)| prompt.starts_with(PROJECTOR_OPENING)).map(|(_, prompt)| prompt.clone()).collect(); - let with: Vec<&String> = projector.iter().filter(|prompt| prompt.contains("GameCult/Lodur: 1 pull request merged")).collect(); + let with: Vec<&String> = projector.iter().filter(|prompt| prompt.contains("GameCult/Lodur: merged \"Reflex: the knee bends first\"")).collect(); assert!(!with.is_empty() && with.len() < projector.len(), "{} of {}", with.len(), projector.len()); assert!(with.iter().all(|prompt| !prompt.contains("Libby Test")), "only his packets carry his domain"); } diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 8c16a47..d70bf35 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -101,7 +101,7 @@ fn packet_of(kind: TurnKind, state: &Value, room: &Room, history: &History, seed fn packet_tuned(kind: TurnKind, state: &Value, room: &Room, history: &History, seed: u64, tuning: &Tuning) -> Packet { let operators = operators(); let minds = minds(); - let inputs = Inputs { kind, state, room, history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed, affordances: CAN, domain: &[] }; + let inputs = Inputs { kind, state, room, history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed, affordances: CAN, domain: None }; select(&inputs, tuning) } @@ -575,7 +575,7 @@ fn reflection_and_follow_up_stimuli() { let operators = operators(); let room = Room::default(); let history = History::default(); - let inputs = Inputs { kind: TurnKind::FollowUp, state: &state(), room: &room, history: &history, observation: Some("Libby's change deleted 40 lines."), people: People { operators: &operators, minds: &[], own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: &[] }; + let inputs = Inputs { kind: TurnKind::FollowUp, state: &state(), room: &room, history: &history, observation: Some("Libby's change deleted 40 lines."), people: People { operators: &operators, minds: &[], own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: None }; let state_value = state(); let follow = select(&Inputs { state: &state_value, ..inputs }, &Tuning::default()); assert_eq!(follow.stimulus, "She just found: Libby's change deleted 40 lines."); @@ -2580,9 +2580,9 @@ fn k22_a_closed_promise_is_told_once_in_the_next_outcome() { // --------------------------------------------------------------------------------------------- // K23: her domain (map 16.22.2). -fn packet_with_domain(lines: &[String], tuning: &Tuning) -> Packet { +fn packet_with_domain(digest: Option<&domain::Digest>, tuning: &Tuning) -> Packet { let (operators, minds, history, room) = (operators(), minds(), History::default(), chat_room()); - let inputs = Inputs { kind: TurnKind::Chat, state: &state(), room: &room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: lines }; + let inputs = Inputs { kind: TurnKind::Chat, state: &state(), room: &room, history: &history, observation: None, people: People { operators: &operators, minds: &minds, own_sender: OWN }, now: now(), seed: 1, affordances: CAN, domain: digest }; select(&inputs, tuning) } @@ -2591,42 +2591,61 @@ fn domain_section(packet: &Packet) -> Vec { packet.context.lines().skip_while(|line| *line != "In her domain lately:").skip(1).take_while(|line| line.starts_with("- ")).map(str::to_owned).collect() } -/// What moved in her domain is its own section under its own guard, the Projector's as news and the Interpreter's by id; -/// past six lines or past the guard the newest are shown and the rest counted; nothing moved, and there is no heading. +/// Nine merged pull requests, one an hour back from an hour ago, in a window that opened two days ago. +fn nine() -> domain::Digest { + let items = (1..=9) + .map(|n| domain::Item { at: now() - chrono::Duration::hours(n), text: format!("- GameCult/Repo{n}: merged \"Change {n}, made whole\", opened by kiko"), about: domain::About::Repo(format!("GameCult/Repo{n}")) }) + .collect(); + domain::Digest { since: now() - chrono::Duration::days(2), now: now(), items } +} + +/// What moved in her domain is its own section under its own guard: a line stating the window, then every item in it, +/// whole; the Projector's as news and the Interpreter's by id. No count, no "more". Past the guard the window shrinks +/// from its old end until everything in it fits, never dropping an item inside it; when not even the newest fits, the +/// section is left out and the report says so. #[test] -fn k23_her_domain_is_a_section_under_its_own_guard_with_ids_for_the_interpreter_alone() { - let lines: Vec = (1..=9).map(|n| format!("- GameCult/Repo{n}: 1 pull request merged since Tuesday (\"Change {n}\"), opened by kiko.")).collect(); +fn k23_her_domain_shows_everything_in_a_stated_window_and_shrinks_the_window_never_the_items() { let tuning = Tuning::default(); - let packet = packet_with_domain(&lines[..2], &tuning); - assert_eq!(domain_section(&packet), lines[..2].to_vec(), "{}", packet.context); - assert_eq!(packet.domain.iter().map(|line| line.id.as_str()).collect::>(), ["d1", "d2"]); + let digest = nine(); + let packet = packet_with_domain(Some(&digest), &tuning); + let shown = domain_section(&packet); + assert_eq!(shown[0], format!("- Everything merged and ruled since {}:", (now() - chrono::Duration::days(2)).format("%A %-d %B, %H:%M UTC")), "{shown:?}"); + assert_eq!(shown[1..].to_vec(), digest.items.iter().map(|item| item.text.clone()).collect::>(), "every item in the window, whole, newest first"); + assert_eq!(packet.domain.iter().map(|line| line.id.as_str()).collect::>(), ["d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"]); + assert_eq!((packet.domain_shown.left_out, packet.domain_shown.omitted), (0, None)); within_guards(&packet, &tuning); let speech = interpret::speech_prompt(&packet, "The room is warm.", "y", &tuning); - assert!(speech.contains("What moved in her domain lately, as id \u{2014} line (news of her part of the coop, none of it work she owes):\n- d1 \u{2014} GameCult/Repo1: 1 pull request merged since Tuesday (\"Change 1\"), opened by kiko.\n- d2 \u{2014} GameCult/Repo2"), "{speech}"); + assert!(speech.contains("What moved in her domain lately, as id \u{2014} line (news of her part of the coop, none of it work she owes):\n- d1 \u{2014} GameCult/Repo1: merged \"Change 1, made whole\", opened by kiko\n- d2 \u{2014} GameCult/Repo2"), "{speech}"); let projector = narrate::projector_prompt(&packet, &tuning); - assert!(projector.contains("In her domain lately:\n- GameCult/Repo1") && !projector.contains("d1 \u{2014}"), "ids are the Interpreter's alone"); - assert!(projector.contains("What is in her domain lately is news of her part of the coop, what was merged and ruled there and by whom: never a task, and none of it work she owes."), "the frame says what the heading is"); + assert!(projector.contains("In her domain lately:\n- Everything merged and ruled since") && !projector.contains("d1 \u{2014}"), "ids are the Interpreter's alone"); - // Past six lines: five and a count, never a silent drop. - let crowded = packet_with_domain(&lines, &tuning); - let shown = domain_section(&crowded); - assert_eq!(shown.len(), 6, "{shown:?}"); - assert_eq!(shown[..5], lines[..5]); - assert_eq!(shown[5], "- 4 more parts of her domain moved, not shown here."); - assert_eq!(crowded.domain.len(), 5); - - // Past the guard: the newest that fit and a count, within the guard. + // Past the guard: the window shrinks to the newest whole minutes that fit, and says so; every item inside it is there. let mut tight = Tuning::default(); - tight.select.domain_bytes = 200; - let bound = packet_with_domain(&lines[..4], &tight); + tight.select.domain_bytes = 300; + let bound = packet_with_domain(Some(&digest), &tight); within_guards(&bound, &tight); let shown = domain_section(&bound); - let counted: usize = shown.last().and_then(|line| line.strip_prefix("- ")).and_then(|rest| rest.split(" more parts").next()).and_then(|n| n.parse().ok()).expect("a counted line"); - assert_eq!(counted + bound.domain.len(), 4, "{shown:?}"); - assert!(bound.sections.bound.contains(&"domain"), "{:?}", bound.sections.bound); + let start = DateTime::parse_from_rfc3339(bound.domain_shown.since.as_deref().unwrap()).unwrap().with_timezone(&Utc); + assert!(start > digest.since && shown[0] == format!("- Everything merged and ruled {}:", if start.date_naive() == now().date_naive() { format!("since {} today", start.format("%H:%M UTC")) } else { format!("since yesterday, {}", start.format("%H:%M UTC")) }), "{shown:?}"); + let inside: Vec = digest.items.iter().filter(|item| item.at >= start).map(|item| item.text.clone()).collect(); + assert!(!inside.is_empty() && inside.len() < 9 && shown[1..] == inside[..], "everything inside the stated window, nothing outside it: {shown:?}"); + assert_eq!(bound.domain_shown.left_out, 9 - inside.len()); + + // Not even the newest item fits: no section, and the report says why. + let mut tiny = Tuning::default(); + tiny.select.domain_bytes = 128; + let long = domain::Digest { items: vec![domain::Item { at: now() - chrono::Duration::hours(1), text: format!("- GameCult/Long: merged \"{}\", opened by kiko", "y".repeat(200)), about: domain::About::Repo("GameCult/Long".into()) }], ..nine() }; + let none = packet_with_domain(Some(&long), &tiny); + assert!(!none.context.contains("domain lately") && none.domain.is_empty() && none.domain_shown.omitted.is_some(), "{}", none.context); + + // No count and no "more", in any of them. + for packet in [&packet, &bound] { + let section = domain_section(packet).join("\n"); + assert!(!section.contains(" more") && !section.contains("pull requests") && !section.contains("things"), "{section}"); + } // Nothing moved (or the read failed, which `project` reports): no heading at all, and no "nothing moved". - let quiet = packet_with_domain(&[], &tuning); + let quiet = packet_with_domain(None, &tuning); assert!(!quiet.context.contains("domain lately") && !interpret::speech_prompt(&quiet, "x", "y", &tuning).contains("domain lately"), "{}", quiet.context); } diff --git a/crates/mind-body/src/projection/tuning.rs b/crates/mind-body/src/projection/tuning.rs index 1b37e44..3ff6fc0 100644 --- a/crates/mind-body/src/projection/tuning.rs +++ b/crates/mind-body/src/projection/tuning.rs @@ -137,7 +137,9 @@ pub struct SelectTuning { pub outcome_bytes: usize, /// Her open promises, in bytes, heading included: under their own guard (map 16.22.1, I16.8). pub promises_bytes: usize, - /// What moved in her domain lately, in bytes, heading included: under its own guard (map 16.22.2, I16.8). + /// What moved in her domain lately, in bytes, heading included: under its own guard (map 16.22.2, I16.8). It is her + /// main window on her domain, so it is generous: about twenty whole items at their usual length. A busier window does + /// not crowd the packet: it shrinks to the newest whole minutes that fit. pub domain_bytes: usize, pub stimulus_bytes: usize, /// What was said to her, verbatim, for the Persona stage: on a chat turn, the room's earlier lines too, before the new @@ -238,7 +240,7 @@ impl Default for SelectTuning { here_bytes: 768, outcome_bytes: 1200, promises_bytes: 600, - domain_bytes: 900, + domain_bytes: 3000, stimulus_bytes: 1500, heard_bytes: 2500, addressed_bytes: 8 * 1024, diff --git a/crates/mind-body/tests/public_surface.txt b/crates/mind-body/tests/public_surface.txt index 79b4d68..f2f1c40 100644 --- a/crates/mind-body/tests/public_surface.txt +++ b/crates/mind-body/tests/public_surface.txt @@ -259,6 +259,7 @@ mind_body::projection::domain: impl HttpForge mind_body::projection::domain: impl HttpForge: fn new (base_url : & str) -> Self mind_body::projection::domain: impl MindDomain mind_body::projection::domain: impl MindDomain: fn new (client : HuginnClient , forge : HttpForge) -> Self +mind_body::projection::domain: impl Names mind_body::projection::domain: pub trait DomainSource { fn read (& self , since : DateTime < Utc > , now : DateTime < Utc >) -> Result < DomainFacts > ; } mind_body::projection::domain: struct DomainFacts # [derive (Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize)] pub-fields[] mind_body::projection::domain: struct HttpForge pub-fields[]