Merge branch 'hands/persona-wake-humans-pace' into hands/persona-live-drain
# Conflicts: # crates/mind-body/src/projection/simulate/tests.rs
This commit is contained in:
commit
9e06fb9745
8 changed files with 340 additions and 253 deletions
|
|
@ -56,7 +56,7 @@ use mind_body::chat_rudp::{RudpChat, connection_id};
|
|||
use mind_body::cli::{instance_and_endpoint, instance_and_maybe_endpoint};
|
||||
use mind_body::control::{CONTROL_ROOT, FileSource, control_path, swarm_path};
|
||||
use mind_body::persona::{Config, carry};
|
||||
use mind_body::heartbeat::{FileStore, HeartbeatView};
|
||||
use mind_body::heartbeat::{FileStore, HeartbeatView, own_rooms};
|
||||
use mind_body::projection::harness::{Fixture, Harness, batch, fixture_request, simulate, state_file};
|
||||
use mind_body::projection::{DomainSource, HttpForge, HuginnPersonaSource, KitModel, LiveReads, MindDomain, Model, MouthReader, ReadSource, Organs as ProjectOrgans, PersonaSource, Request as ProjectRequest, TUNING_FILE, TUNING_ROOT, Through, TurnKind, connector_key, project};
|
||||
|
||||
|
|
@ -199,6 +199,14 @@ fn run_project(args: &[String]) -> Result<String> {
|
|||
(Some(address), Some(forge)) => Some(MindDomain::new(HuginnClient::new(address, instance.clone(), TIMEOUT), HttpForge::new(&forge))),
|
||||
_ => None,
|
||||
};
|
||||
// Her own rooms, as the heartbeat reads them: the rooms the mouth names for a repo she stewards. Unread, she has none.
|
||||
let own = match (&domain, &chat) {
|
||||
(Some(domain), Some(chat)) => match (domain.stewarded(), chat.pending()) {
|
||||
(Ok(repos), Ok(pending)) => own_rooms(repos.iter().map(String::as_str), pending.deliveries.iter().map(|delivery| delivery.room_alias.as_str())),
|
||||
_ => vec![],
|
||||
},
|
||||
_ => vec![],
|
||||
};
|
||||
// Her reads by intent (map 16.22.3): her mind through the same endpoint, the forge when it is named, the web.
|
||||
let reads = address.map(|address| LiveReads::new(HuginnClient::new(address, instance.clone(), TIMEOUT), setting("MIND_PERSONA_FORGE_URL").map(|forge| HttpForge::new(&forge))));
|
||||
let organs = ProjectOrgans {
|
||||
|
|
@ -224,7 +232,7 @@ fn run_project(args: &[String]) -> Result<String> {
|
|||
through,
|
||||
last_heard: vec![],
|
||||
recent: vec![],
|
||||
own_rooms: vec![],
|
||||
own_rooms: own,
|
||||
last_outcome,
|
||||
last_wake: None,
|
||||
records: vec![],
|
||||
|
|
|
|||
|
|
@ -421,28 +421,13 @@ impl Speaker {
|
|||
}
|
||||
}
|
||||
|
||||
/// Which lines wake a Persona off the beat. `Live` is the heartbeat's rule today and the only one `poll` uses; the rest
|
||||
/// are what desk question `po-mind-wakes-mind` weighs, run in `mind-persona project --simulate` until it is answered.
|
||||
/// The beat is not here: every policy has it, and it wakes one Persona by `tempo::pick`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub(crate) enum WakePolicy {
|
||||
/// The operator or another Mind addressing her (`is_for`). A member's line does not.
|
||||
Live,
|
||||
/// Ruling `persona-only-wake-humans-in-rooms`: a line addressing her, from anyone, and any human line in her rooms.
|
||||
Ruled,
|
||||
/// Ruling `persona-only-humans-pace`: a human's line wakes her in her own room (a direct message, or a room that is
|
||||
/// hers); in a public room only when it addresses her or continues an exchange she is in. A Mind's line wakes her
|
||||
/// only by an explicit mention (a Matrix mention of her or a reply to her, never a name in prose), in any room, and
|
||||
/// only while fewer than this many Mind lines in a row came before it across her rooms (`LineFacts::mind_run`): the
|
||||
/// backstop.
|
||||
HumansPace(usize),
|
||||
/// `Ruled`, with at most this many lines in her current Mind-only run (`LineFacts::mind_run`) before a human must
|
||||
/// speak where it runs: a Mind's line past the cap wakes no one.
|
||||
NamesWithCap(usize),
|
||||
/// The swarm's old loop, a control: any line in her rooms but her own.
|
||||
AllMessages,
|
||||
}
|
||||
/// The backstop of the wake rule: a Mind's explicit mention wakes her only while fewer than this many Mind lines in a row
|
||||
/// came before it across her rooms (`LineFacts::mind_run`).
|
||||
pub(crate) const MIND_RUN_BACKSTOP: usize = 4;
|
||||
|
||||
/// She is in a room's exchange when she has spoken there within this many minutes before the line: others talking on does
|
||||
/// not keep her in it. A simulation plan may set another window; the live poll uses this one.
|
||||
pub(crate) const EXCHANGE_MINUTES: i64 = 30;
|
||||
|
||||
/// Why a line wakes her, strongest first.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, serde::Serialize)]
|
||||
|
|
@ -451,18 +436,15 @@ pub(crate) enum WakeCause {
|
|||
AddressedByHuman,
|
||||
Human,
|
||||
AddressedByMind,
|
||||
/// A Mind's line that does not address her: only the control wakes on it.
|
||||
Mind,
|
||||
}
|
||||
|
||||
/// What the room says about a line, beside the line: the facts a policy may weigh. The live poll knows none of them yet
|
||||
/// and passes the default; `Live` reads none.
|
||||
/// What the room says about a line, beside the line: the facts `wakes` weighs, from `line_facts`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct LineFacts {
|
||||
/// How many lines her current Mind-only run held before this one: one run across every room she sees, so a loop
|
||||
/// cannot dodge the backstop by changing rooms, and ended only by a human's line in a room the run has lines in.
|
||||
pub mind_run: usize,
|
||||
/// The line is in a room of hers: a direct message (the delivery says so) or a room configured as hers.
|
||||
/// The line is in a room of hers: a direct message, or a room named for a repo she stewards (`own_rooms`).
|
||||
pub own_room: bool,
|
||||
/// She has spoken in the room's current exchange: the lines before this one that follow each other without a long gap.
|
||||
pub in_exchange: bool,
|
||||
|
|
@ -476,31 +458,72 @@ impl Default for LineFacts {
|
|||
}
|
||||
}
|
||||
|
||||
/// Whether a line in her rooms wakes `who` off the beat under `policy`, and why. The one owner of the wake rule: the
|
||||
/// heartbeat's poll asks it with `Live`, the simulator with the policy under test.
|
||||
pub(crate) fn wakes(policy: WakePolicy, who: &Addressee, delivery: &ChatDelivery, speaker: Speaker, facts: LineFacts) -> Option<WakeCause> {
|
||||
/// One line of the rooms she sees, as `line_facts` weighs it: who said it, where, and when.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct FactLine<'a> {
|
||||
pub sender: &'a str,
|
||||
pub room: &'a str,
|
||||
pub at_ms: u64,
|
||||
pub is_direct: bool,
|
||||
}
|
||||
|
||||
/// The facts of every line of an ordered list of the lines she sees, hers included: the one owner of the Mind run, her
|
||||
/// rooms and her exchange, for the live poll and the simulator alike. `minds` is every Mind of the roster, her too.
|
||||
pub(crate) fn line_facts(lines: &[FactLine], her: &str, minds: &[String], own_rooms: &[String], window_ms: u64) -> Vec<LineFacts> {
|
||||
let mut run = 0usize;
|
||||
let mut run_rooms: Vec<&str> = Vec::new();
|
||||
lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(at, line)| {
|
||||
let mind_run = run;
|
||||
if minds.iter().any(|mind| mind == line.sender) {
|
||||
run += 1;
|
||||
run_rooms.push(line.room);
|
||||
} else if run_rooms.contains(&line.room) {
|
||||
run = 0;
|
||||
run_rooms.clear();
|
||||
}
|
||||
let since = line.at_ms.saturating_sub(window_ms);
|
||||
LineFacts {
|
||||
mind_run,
|
||||
own_room: line.is_direct || own_rooms.iter().any(|room| room == line.room),
|
||||
in_exchange: lines[..at].iter().any(|earlier| earlier.room == line.room && earlier.sender == her && earlier.at_ms >= since),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Which of `aliases` are her own rooms: those named for a repo she stewards (`#huginn:gamecult.org` for `GameCult/Huginn`),
|
||||
/// case-blind. A direct message is hers by `FactLine::is_direct`, not by name.
|
||||
pub fn own_rooms<'a>(repos: impl IntoIterator<Item = &'a str>, aliases: impl IntoIterator<Item = &'a str>) -> Vec<String> {
|
||||
let names: Vec<&str> = repos.into_iter().map(|repo| repo.rsplit_once('/').map_or(repo, |(_, name)| name)).collect();
|
||||
let mut found: Vec<String> = Vec::new();
|
||||
for alias in aliases {
|
||||
let local = alias.strip_prefix('#').map(|rest| rest.split_once(':').map_or(rest, |(local, _)| local));
|
||||
if local.is_some_and(|local| names.iter().any(|name| name.eq_ignore_ascii_case(local))) && !found.iter().any(|held| held == alias) {
|
||||
found.push(alias.to_owned());
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
/// Whether a line in her rooms wakes `who` off the beat, and why: the one owner of the wake rule, asked by the heartbeat's
|
||||
/// poll and by the simulator. A human's line wakes her in her own room (a direct message, or a room named for a repo she
|
||||
/// stewards), and in a public room only when it addresses her or continues an exchange she is in. A Mind's line wakes
|
||||
/// her only by an explicit mention (a Matrix mention of her or a reply to her, never a name in prose), in any room, and
|
||||
/// only while fewer than `MIND_RUN_BACKSTOP` Mind lines in a row came before it across her rooms.
|
||||
pub(crate) fn wakes(who: &Addressee, delivery: &ChatDelivery, speaker: Speaker, facts: LineFacts) -> Option<WakeCause> {
|
||||
if speaker == Speaker::Her {
|
||||
return None;
|
||||
}
|
||||
let addressed = is_for(who, delivery);
|
||||
let human = speaker.human();
|
||||
let cause = match (human, addressed) {
|
||||
(true, true) => WakeCause::AddressedByHuman,
|
||||
(true, false) => WakeCause::Human,
|
||||
(false, true) => WakeCause::AddressedByMind,
|
||||
(false, false) => WakeCause::Mind,
|
||||
};
|
||||
let wakes = match policy {
|
||||
WakePolicy::Live => addressed && matches!(speaker, Speaker::Operator | Speaker::Mind),
|
||||
WakePolicy::Ruled => human || addressed,
|
||||
WakePolicy::HumansPace(cap) => {
|
||||
let explicit = delivery.mentions.iter().any(|id| id == who.matrix_id()) || matches!(delivery.basis, Some(Basis::Tag | Basis::Reply));
|
||||
if human { addressed || delivery.is_direct || facts.own_room || facts.in_exchange } else { explicit && facts.mind_run < cap }
|
||||
}
|
||||
WakePolicy::NamesWithCap(cap) => human || (addressed && facts.mind_run < cap),
|
||||
WakePolicy::AllMessages => true,
|
||||
};
|
||||
wakes.then_some(cause)
|
||||
if speaker.human() {
|
||||
let wakes = addressed || delivery.is_direct || facts.own_room || facts.in_exchange;
|
||||
return wakes.then_some(if addressed { WakeCause::AddressedByHuman } else { WakeCause::Human });
|
||||
}
|
||||
let explicit = delivery.mentions.iter().any(|id| id == who.matrix_id()) || matches!(delivery.basis, Some(Basis::Tag | Basis::Reply));
|
||||
(explicit && facts.mind_run < MIND_RUN_BACKSTOP).then_some(WakeCause::AddressedByMind)
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
|
@ -518,6 +541,34 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
/// The facts of each of `pending` (in seq order), over the lines she can see: every delivery's context lines before it,
|
||||
/// then the delivery, merged in time order and each line once. The mouth's context is the room's own earlier lines, hers
|
||||
/// among them, so the Mind run and her exchange read as the simulator's room gives them.
|
||||
pub(crate) fn pending_facts(pending: &[&ChatDelivery], her: &str, minds: &[String], own_rooms: &[String]) -> Vec<LineFacts> {
|
||||
let mut lines: Vec<(FactLine, Option<usize>)> = Vec::new();
|
||||
for (index, delivery) in pending.iter().enumerate() {
|
||||
let room = delivery.room_alias.as_str();
|
||||
for context in &delivery.context {
|
||||
if !lines.iter().any(|(held, _)| held.room == room && held.sender == context.sender && held.at_ms == context.at_unix_ms) {
|
||||
lines.push((FactLine { sender: &context.sender, room, at_ms: context.at_unix_ms, is_direct: delivery.is_direct }, None));
|
||||
}
|
||||
}
|
||||
match lines.iter_mut().find(|(held, _)| held.room == room && held.sender == delivery.sender && held.at_ms == delivery.at_unix_ms) {
|
||||
Some((_, slot)) => *slot = Some(index),
|
||||
None => lines.push((FactLine { sender: &delivery.sender, room, at_ms: delivery.at_unix_ms, is_direct: delivery.is_direct }, Some(index))),
|
||||
}
|
||||
}
|
||||
lines.sort_by_key(|(line, _)| line.at_ms);
|
||||
let facts = line_facts(&lines.iter().map(|(line, _)| *line).collect::<Vec<_>>(), her, minds, own_rooms, u64::try_from(EXCHANGE_MINUTES * 60_000).unwrap_or_default());
|
||||
let mut of = vec![LineFacts::default(); pending.len()];
|
||||
for ((_, slot), facts) in lines.iter().zip(facts) {
|
||||
if let Some(index) = slot {
|
||||
of[*index] = facts;
|
||||
}
|
||||
}
|
||||
of
|
||||
}
|
||||
|
||||
/// The mouth pages a pending answer, so fewer deliveries may come than wait.
|
||||
/// The heartbeat acks nothing: it asks again after the highest seq it has until
|
||||
/// the answer is empty. A mouth that never empties is cut off at `PENDING_PAGES`.
|
||||
|
|
@ -546,6 +597,8 @@ struct Row<'a> {
|
|||
pending: Vec<ChatDelivery>,
|
||||
/// Whom a delivery may address in her: her roster names and her projects' names as the last poll that read her pending chat left them.
|
||||
addressee: Addressee,
|
||||
/// Her rooms among the pending deliveries': those named for a repo she stewards, as the last poll read her stewardships.
|
||||
own_rooms: Vec<String>,
|
||||
note: String,
|
||||
}
|
||||
|
||||
|
|
@ -608,7 +661,7 @@ pub fn poll(organs: &Organs, config: &Config) -> Result<Outcome> {
|
|||
// Her last-read names when the table holds her, else her roster names alone.
|
||||
let roster = Addressee::new(&seat.who.matrix_id, [seat.who.public_name.as_str(), seat.who.handle.as_str()]);
|
||||
let kept = stored_addressing.minds.iter().find(|stored| stored.matrix_id() == seat.who.matrix_id).cloned().unwrap_or_else(|| roster.clone());
|
||||
let mut row = Row { seat, released, busy, pending: vec![], addressee: kept, note: String::new() };
|
||||
let mut row = Row { seat, released, busy, pending: vec![], addressee: kept, own_rooms: vec![], note: String::new() };
|
||||
// Pending chat, read-only, for a released Mind.
|
||||
if row.released {
|
||||
match read_pending(seat.chat) {
|
||||
|
|
@ -621,7 +674,10 @@ pub fn poll(organs: &Organs, config: &Config) -> Result<Outcome> {
|
|||
// Her projects' names address her too; read only when something is pending. A failed read keeps her last-read row.
|
||||
if !row.pending.is_empty() {
|
||||
match stewardships_of(seat.mind) {
|
||||
Ok((names, repos)) => row.addressee = roster.with_stewardships(names, repos),
|
||||
Ok((names, repos)) => {
|
||||
row.own_rooms = own_rooms(repos.iter().map(|repo| repo.0.as_str()), row.pending.iter().map(|delivery| delivery.room_alias.as_str()));
|
||||
row.addressee = roster.with_stewardships(names, repos);
|
||||
}
|
||||
Err(error) => row.note = format!("{} stewardship names unread: {error}", row.note).trim().to_string(),
|
||||
}
|
||||
}
|
||||
|
|
@ -643,10 +699,13 @@ pub fn poll(organs: &Organs, config: &Config) -> Result<Outcome> {
|
|||
let mentioned = {
|
||||
let mut pending: Vec<&ChatDelivery> = row.pending.iter().collect();
|
||||
pending.sort_by_key(|delivery| delivery.seq);
|
||||
let minds: Vec<String> = config.personas.iter().map(|mind| mind.matrix_id.clone()).collect();
|
||||
let facts = pending_facts(&pending, row.addressee.matrix_id(), &minds, &row.own_rooms);
|
||||
pending
|
||||
.into_iter()
|
||||
.filter(|delivery| wakes(WakePolicy::Live, &row.addressee, delivery, config.speaker(&row.addressee, delivery), LineFacts::default()).is_some())
|
||||
.map(|delivery| format!("{}:{}", slug.0, delivery.event_id))
|
||||
.zip(facts)
|
||||
.filter(|(delivery, facts)| wakes(&row.addressee, delivery, config.speaker(&row.addressee, delivery), *facts).is_some())
|
||||
.map(|(delivery, _)| format!("{}:{}", slug.0, delivery.event_id))
|
||||
.find(|key| !state.handled_mentions.contains(key))
|
||||
};
|
||||
let Some(key) = mentioned else { continue };
|
||||
|
|
|
|||
|
|
@ -391,10 +391,12 @@ fn the_operator_naming_a_persona_wakes_her_at_once_off_the_beat_and_once_per_mes
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn another_mind_naming_a_persona_wakes_her_once_off_the_beat() {
|
||||
fn another_mind_tagging_a_persona_wakes_her_once_off_the_beat_and_a_name_in_prose_does_not() {
|
||||
let rig = quiet_rig();
|
||||
rig.say(BOB, delivery(1, "@ann:chat", "Bob, a word", &[]));
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a Mind of the roster wakes her at once");
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a name in a Mind's prose wakes no one");
|
||||
rig.say(BOB, delivery(2, "@ann:chat", "a word", &["@bob:chat"]));
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a Mind of the roster tagging her wakes her at once");
|
||||
rig.end_unit(BOB);
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "the same message polled again wakes nobody");
|
||||
}
|
||||
|
|
@ -408,16 +410,13 @@ fn a_mind_naming_no_one_or_herself_wakes_nobody() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn a_member_naming_a_persona_wakes_nobody_off_the_beat_but_counts_as_full_urgency_on_it() {
|
||||
fn a_member_naming_a_persona_wakes_her_at_once() {
|
||||
let rig = Rig::new();
|
||||
rig.turn(ANN, 1000);
|
||||
rig.turn(BOB, 90);
|
||||
rig.beat_fell();
|
||||
rig.say(BOB, delivery(1, "@member:chat", "Bob, are you there?", &[]));
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a member does not start a turn");
|
||||
rig.advance(900);
|
||||
// Bob waited 990 s x ten for the member addressing him; Ann waited 1900 s x one: Bob wins the beat.
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] });
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a member addressing her wakes her off the beat");
|
||||
assert_eq!(rig.store.traces.borrow().last().unwrap().instances[BOB].urgency_permille, 1000);
|
||||
}
|
||||
|
||||
|
|
@ -473,20 +472,18 @@ fn a_listed_name_wakes_on_its_exact_spelling_only_and_a_derived_name_in_any_case
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn another_mind_naming_a_project_wakes_its_steward_and_a_member_scores_her_without_waking_her() {
|
||||
fn a_member_naming_a_project_wakes_its_steward_and_a_mind_naming_it_in_prose_does_not() {
|
||||
let rig = quiet_rig();
|
||||
steward(&rig, BOB, "GameCult/BadDaySimulator", &["BDS"]);
|
||||
rig.say(BOB, delivery(1, "@ann:chat", "BDS needs a look", &[]));
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a Mind of the roster naming her project wakes her");
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a Mind's prose naming her project wakes no one");
|
||||
let rig = Rig::new();
|
||||
rig.turn(ANN, 1000);
|
||||
rig.turn(BOB, 90);
|
||||
steward(&rig, BOB, "GameCult/BadDaySimulator", &["BDS"]);
|
||||
rig.beat_fell();
|
||||
rig.say(BOB, delivery(1, "@member:chat", "is BDS green?", &[]));
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a member does not start a turn");
|
||||
rig.advance(900);
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "the member's naming scores her at full urgency");
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a member naming her project wakes her");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -699,7 +696,7 @@ fn the_file_store_reads_back_the_addressing_it_wrote_to_the_view() {
|
|||
}
|
||||
|
||||
/// Matrix's word that a message is her DM, a tag or a reply wakes her off the beat from the operator; a notice or an edit never does,
|
||||
/// whatever its basis, and a stranger's direct message is delivered but wakes no one.
|
||||
/// whatever its basis, and a member's direct message wakes her too.
|
||||
#[test]
|
||||
fn matrixs_addressing_facts_wake_her_off_the_beat_only_on_a_message_from_the_roster() {
|
||||
use crate::chat_client::{Basis, Form};
|
||||
|
|
@ -722,5 +719,17 @@ fn matrixs_addressing_facts_wake_her_off_the_beat_only_on_a_message_from_the_ros
|
|||
}
|
||||
let rig = quiet_rig();
|
||||
rig.say(BOB, with(1, "@stranger:chat", Some(Basis::Direct), Form::Message));
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "the sender gate stays: a stranger's DM is delivered and wakes no one off the beat");
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "a member's direct message wakes her: no sender gate");
|
||||
}
|
||||
|
||||
/// The fact the live poll lacked: a member's unaddressed line in a room named for a repo she stewards wakes her, and the same line
|
||||
/// in a room named for nothing of hers does not.
|
||||
#[test]
|
||||
fn a_member_line_in_a_room_named_for_her_repo_wakes_her_off_the_beat() {
|
||||
let rig = quiet_rig();
|
||||
steward(&rig, BOB, "GameCult/Swarm", &["Zed"]);
|
||||
rig.say(BOB, ChatDelivery { room_alias: "#elsewhere:chat".into(), ..delivery(1, "@member:chat", "what a day", &[]) });
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "a public room that is not hers wakes her only by address");
|
||||
rig.say(BOB, delivery(2, "@member:chat", "what a day", &[]));
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "#swarm is named for her repo");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ pub struct Request {
|
|||
pub last_heard: Vec<(String, u64)>,
|
||||
/// The ids each earlier projection selected, oldest first, for freshness: read from her records (`turn::history`).
|
||||
pub recent: Vec<Vec<String>>,
|
||||
/// The rooms that are hers, by the key the lines carry: a simulation's plan. The live body records none yet.
|
||||
/// The rooms that are hers, by the key the lines carry: live from `heartbeat::own_rooms` (the rooms named for her stewarded repos), simulated from the plan.
|
||||
pub own_rooms: Vec<String>,
|
||||
/// The record of her last turn, which her packet opens with what came of (`outcome::outcome_of`): the Interpreter's
|
||||
/// decision under `interpreter` and the receipts of the lines that went out under `posted`, or `failed`. Read from her
|
||||
|
|
@ -296,7 +296,7 @@ fn read_room(chat: &dyn MouthReader, request: &Request, own: &Addressee) -> (Roo
|
|||
display: delivery.sender_display.clone(),
|
||||
text: delivery.text.clone(),
|
||||
at_ms: delivery.at_unix_ms,
|
||||
// The heartbeat's rule, the one that woke her: never a second opinion here. Under humans_pace a human's line in
|
||||
// The heartbeat's rule, the one that woke her: never a second opinion here. A human's line in
|
||||
// her own room always wakes her, so it is to her, as a direct message is (the plan's or unit's `own_rooms`).
|
||||
to_her: is_for(own, delivery) || (request.own_rooms.contains(&delivery.room_alias) && delivery.sender != request.own_sender && !request.minds.contains(&delivery.sender)),
|
||||
event: delivery.event_id.clone(),
|
||||
|
|
|
|||
|
|
@ -190,17 +190,25 @@ impl MindDomain {
|
|||
}
|
||||
}
|
||||
|
||||
impl MindDomain {
|
||||
fn ask(&self, selection: &Selection) -> Result<PipelineSelectionPage> {
|
||||
let request = HuginnMindRequest::Query { instance: self.client.instance().clone(), selection: selection.clone(), semantic: None };
|
||||
match self.client.call(request).map_err(|_| anyhow!("her mind could not be asked"))? {
|
||||
HuginnMindResponse::Query(page) => Ok(page),
|
||||
HuginnMindResponse::Refused(_) => bail!("her mind refused the read"),
|
||||
_ => bail!("her mind answered a read with something else"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The repos she stewards in force (`Org/Repo`), through her read door: the drain's input to `heartbeat::own_rooms`.
|
||||
pub fn stewarded(&self) -> Result<Vec<String>> {
|
||||
stewarded(&|selection| self.ask(selection), &self.client.instance().0)
|
||||
}
|
||||
}
|
||||
|
||||
impl DomainSource for MindDomain {
|
||||
fn read(&self, since: DateTime<Utc>, now: DateTime<Utc>) -> Result<DomainFacts> {
|
||||
let ask = |selection: &Selection| -> Result<PipelineSelectionPage> {
|
||||
let request = HuginnMindRequest::Query { instance: self.client.instance().clone(), selection: selection.clone(), semantic: None };
|
||||
match self.client.call(request).map_err(|_| anyhow!("her mind could not be asked"))? {
|
||||
HuginnMindResponse::Query(page) => Ok(page),
|
||||
HuginnMindResponse::Refused(_) => bail!("her mind refused the read"),
|
||||
_ => bail!("her mind answered a read with something else"),
|
||||
}
|
||||
};
|
||||
read(&ask, &self.client.instance().0, &self.forge, since, now)
|
||||
read(&|selection| self.ask(selection), &self.client.instance().0, &self.forge, since, now)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -288,10 +296,8 @@ fn who(provenance: &PipelineProvenance, her: &str) -> Who {
|
|||
}
|
||||
}
|
||||
|
||||
/// Her domain from `since`: her in-force stewardships and her campaigns through `ask` (her door), each stewarded repo's
|
||||
/// pull requests through `forge`. Any failure fails the whole read, except a repo that is archived, missing or moved,
|
||||
/// which is skipped and named.
|
||||
pub(crate) fn read(ask: &Ask, her: &str, forge: &dyn ForgeGet, since: DateTime<Utc>, now: DateTime<Utc>) -> Result<DomainFacts> {
|
||||
/// The repos `her` stewards in force, each once.
|
||||
pub(crate) fn stewarded(ask: &Ask, her: &str) -> Result<Vec<String>> {
|
||||
let mut repos: Vec<String> = Vec::new();
|
||||
for item in all(ask, &in_force(of_kind(PipelineKind::Stewardship)))? {
|
||||
if let PipelineFacts::Stewardship { instance, repo, .. } = &item.facts
|
||||
|
|
@ -301,6 +307,14 @@ pub(crate) fn read(ask: &Ask, her: &str, forge: &dyn ForgeGet, since: DateTime<U
|
|||
repos.push(repo.0.clone());
|
||||
}
|
||||
}
|
||||
Ok(repos)
|
||||
}
|
||||
|
||||
/// Her domain from `since`: her in-force stewardships and her campaigns through `ask` (her door), each stewarded repo's
|
||||
/// pull requests through `forge`. Any failure fails the whole read, except a repo that is archived, missing or moved,
|
||||
/// which is skipped and named.
|
||||
pub(crate) fn read(ask: &Ask, her: &str, forge: &dyn ForgeGet, since: DateTime<Utc>, now: DateTime<Utc>) -> Result<DomainFacts> {
|
||||
let repos = stewarded(ask, her)?;
|
||||
let slugs: Vec<String> = all(ask, &in_force(of_kind(PipelineKind::Campaign)))?.iter().map(|item| root(item).to_owned()).collect::<BTreeSet<_>>().into_iter().collect();
|
||||
let mut campaigns: Vec<CampaignFacts> = slugs.iter().map(|slug| CampaignFacts { slug: slug.clone(), rulings: Vec::new() }).collect();
|
||||
if !slugs.is_empty() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//! one `project` through the Persona stage, and each one's drafts the Interpreter sends join the room as from her Matrix id, so the
|
||||
//! next one hears them.
|
||||
//!
|
||||
//! Who wakes is the heartbeat's: `heartbeat::wakes` under the plan's `WakePolicy`, over each persona's addressee as the
|
||||
//! Who wakes is the heartbeat's: `heartbeat::wakes` over each persona's addressee as the
|
||||
//! heartbeat's addressing table holds it (her stewarded projects' names included) when the plan names the table. The
|
||||
//! beat is the heartbeat's too: when it falls, one Persona wakes, the winner of `tempo::pick`. Who wakes in a round is
|
||||
//! decided from the room as the round opens, as one heartbeat poll decides from the pending it read: a line spoken by a
|
||||
|
|
@ -43,7 +43,7 @@ use super::turn::{self, Actuator, Edited, Sent, history, last_wake};
|
|||
use super::{DomainFacts, DomainSource, MouthReader, Organs, ReadFixture, ReadSource, Request, Through, TurnKind};
|
||||
use crate::address::{Addressee, is_for, localpart};
|
||||
use crate::chat_client::ChatPending;
|
||||
use crate::heartbeat::{Addressing, DEFAULT_BEAT_S, FileStore, HeartbeatView, LineFacts, Speaker, WakeCause, WakePolicy, addressed_by_member, wakes};
|
||||
use crate::heartbeat::{Addressing, DEFAULT_BEAT_S, EXCHANGE_MINUTES, FactLine, FileStore, HeartbeatView, Speaker, WakeCause, addressed_by_member, line_facts, wakes};
|
||||
use crate::tempo::{Standing, pick};
|
||||
|
||||
/// The most personas a simulation holds: the swarm.
|
||||
|
|
@ -62,14 +62,12 @@ struct SimFile {
|
|||
repeats: usize,
|
||||
#[serde(default)]
|
||||
seed: u64,
|
||||
#[serde(default = "ruled")]
|
||||
wake: WakePolicy,
|
||||
/// The heartbeat's beat, in seconds of simulated time; 0 is no beat.
|
||||
#[serde(default = "beat_s")]
|
||||
beat_s: u32,
|
||||
#[serde(default = "two")]
|
||||
round_minutes: i64,
|
||||
/// She is in a room's exchange when she has spoken there within this many minutes before the line (`humans_pace`):
|
||||
/// She is in a room's exchange when she has spoken there within this many minutes before the line:
|
||||
/// others talking on does not keep her in it.
|
||||
#[serde(default = "exchange_minutes")]
|
||||
exchange_minutes: i64,
|
||||
|
|
@ -95,11 +93,7 @@ fn two() -> i64 {
|
|||
}
|
||||
|
||||
fn exchange_minutes() -> i64 {
|
||||
30
|
||||
}
|
||||
|
||||
fn ruled() -> WakePolicy {
|
||||
WakePolicy::Ruled
|
||||
EXCHANGE_MINUTES
|
||||
}
|
||||
|
||||
fn beat_s() -> u32 {
|
||||
|
|
@ -116,7 +110,7 @@ struct CastEntry {
|
|||
/// Her rooms; none is every room of the plan.
|
||||
#[serde(default)]
|
||||
rooms: Vec<String>,
|
||||
/// The rooms that are hers, where any human line wakes her under `humans_pace`. Neither the heartbeat's table nor
|
||||
/// The rooms that are hers, where any human line wakes her. Neither the heartbeat's table nor
|
||||
/// `persona.env` records which rooms a Mind owns, so the plan says; a direct message is always hers.
|
||||
#[serde(default)]
|
||||
own_rooms: Vec<String>,
|
||||
|
|
@ -239,30 +233,6 @@ fn speaker(line: &Line, member: &Member, operators: &[String], cast: &[String])
|
|||
}
|
||||
}
|
||||
|
||||
/// For each line, how many Mind lines in a row came before it in her current Mind-only run: one run across every room
|
||||
/// she sees, which a human's line ends only when it is in a room the run has lines in. Meta chatting in #eureka does not
|
||||
/// end a loop in #minds.
|
||||
fn mind_runs(lines: &[Line], cast: &[String], member: &Member) -> Vec<usize> {
|
||||
let mut run = 0usize;
|
||||
let mut run_rooms: Vec<&str> = Vec::new();
|
||||
lines
|
||||
.iter()
|
||||
.map(|line| {
|
||||
let before = run;
|
||||
if line.visible_to(&member.entry.id, &member.rooms) {
|
||||
if cast.contains(&line.from) {
|
||||
run += 1;
|
||||
run_rooms.push(&line.room);
|
||||
} else if run_rooms.contains(&line.room.as_str()) {
|
||||
run = 0;
|
||||
run_rooms.clear();
|
||||
}
|
||||
}
|
||||
before
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// How a Mind's line addressed her, by the evidence `is_for` had, strongest first: a Matrix tag or a reply to her, her
|
||||
/// Matrix id written as plain text, or one of her names in the text.
|
||||
fn how_addressed(line: &Line, at: usize, member: &Member, lines: &[Line]) -> &'static str {
|
||||
|
|
@ -276,7 +246,7 @@ fn how_addressed(line: &Line, at: usize, member: &Member, lines: &[Line]) -> &'s
|
|||
}
|
||||
}
|
||||
|
||||
/// One wake: why (the strongest cause among her new lines, under the plan's policy) and, when only Minds' lines caused
|
||||
/// One wake: why (the strongest cause among her new lines) and, when only Minds' lines caused
|
||||
/// it, the strongest evidence that addressed her and the lines that did.
|
||||
struct Woken {
|
||||
cause: WakeCause,
|
||||
|
|
@ -286,25 +256,20 @@ struct Woken {
|
|||
by: Vec<Value>,
|
||||
}
|
||||
|
||||
/// Whether she is in the exchange a line belongs to: she spoke in its room within `window` before it.
|
||||
fn in_exchange(lines: &[Line], at: usize, her: &str, window: Duration) -> bool {
|
||||
let line = &lines[at];
|
||||
let since = line.at_ms.saturating_sub(u64::try_from(window.num_milliseconds()).unwrap_or(0));
|
||||
lines[..at].iter().any(|earlier| earlier.room == line.room && earlier.from == her && earlier.at_ms >= since)
|
||||
}
|
||||
|
||||
/// Her wake, if a line she has not seen wakes her: in the room of the earliest such line, with the strongest cause among
|
||||
/// that room's waking lines.
|
||||
#[allow(clippy::too_many_arguments, reason = "one wake decision's inputs, each a plan or room fact")]
|
||||
fn woken(lines: &[Line], runs: &[usize], seen: &Seen, member: &Member, operators: &[String], cast: &[String], policy: WakePolicy, gap: Duration) -> Option<Woken> {
|
||||
fn woken(lines: &[Line], seen: &Seen, member: &Member, operators: &[String], cast: &[String], gap: Duration) -> Option<Woken> {
|
||||
// The lines she sees, and their facts from the heartbeat's one owner of them.
|
||||
let visible: Vec<usize> = (0..lines.len()).filter(|at| lines[*at].visible_to(&member.entry.id, &member.rooms)).collect();
|
||||
let seeing: Vec<FactLine> = visible.iter().map(|at| FactLine { sender: &lines[*at].from, room: &lines[*at].room, at_ms: lines[*at].at_ms, is_direct: lines[*at].dm_to.is_some() }).collect();
|
||||
let facts = line_facts(&seeing, &member.entry.id, cast, &member.entry.own_rooms, u64::try_from(gap.num_milliseconds()).unwrap_or(0));
|
||||
let mut found: Vec<(usize, WakeCause)> = Vec::new();
|
||||
for (at, line) in lines.iter().enumerate() {
|
||||
if !unseen(seen, lines, at) || !line.visible_to(&member.entry.id, &member.rooms) {
|
||||
for (at, facts) in visible.into_iter().zip(facts) {
|
||||
if !unseen(seen, lines, at) {
|
||||
continue;
|
||||
}
|
||||
let delivery = line.delivery(at, &member.entry.id, lines);
|
||||
let facts = LineFacts { mind_run: runs[at], own_room: member.entry.own_rooms.contains(&line.room), in_exchange: in_exchange(lines, at, &member.entry.id, gap) };
|
||||
if let Some(cause) = wakes(policy, &member.addressee, &delivery, speaker(line, member, operators, cast), facts) {
|
||||
let delivery = lines[at].delivery(at, &member.entry.id, lines);
|
||||
if let Some(cause) = wakes(&member.addressee, &delivery, speaker(&lines[at], member, operators, cast), facts) {
|
||||
found.push((at, cause));
|
||||
}
|
||||
}
|
||||
|
|
@ -328,7 +293,6 @@ fn cause_word(cause: Option<WakeCause>) -> &'static str {
|
|||
Some(WakeCause::AddressedByHuman) => "addressed_by_human",
|
||||
Some(WakeCause::Human) => "human",
|
||||
Some(WakeCause::AddressedByMind) => "addressed_by_mind",
|
||||
Some(WakeCause::Mind) => "mind",
|
||||
None => "beat",
|
||||
}
|
||||
}
|
||||
|
|
@ -433,7 +397,7 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize)
|
|||
scripted(round, &mut lines, &mut rounds_of, &mut causes)?;
|
||||
let round_at = at_round(round);
|
||||
// Decided from the room as the round opens, as a poll decides from the pending it read.
|
||||
let mut woke: Vec<(usize, Option<Woken>)> = members.iter().enumerate().filter_map(|(at, member)| woken(&lines, &mind_runs(&lines, &cast, member), &seen[at], member, &plan.operators, &cast, plan.wake, Duration::minutes(plan.exchange_minutes)).map(|why| (at, Some(why)))).collect();
|
||||
let mut woke: Vec<(usize, Option<Woken>)> = members.iter().enumerate().filter_map(|(at, member)| woken(&lines, &seen[at], member, &plan.operators, &cast, Duration::minutes(plan.exchange_minutes)).map(|why| (at, Some(why)))).collect();
|
||||
// The beat, as the heartbeat's: when it has fallen, one more wake for the winner of `tempo::pick` among those
|
||||
// not already woken.
|
||||
if plan.beat_s > 0 && (round_at - last_beat).num_seconds() >= i64::from(plan.beat_s) {
|
||||
|
|
@ -717,16 +681,6 @@ fn number(value: &Value) -> String {
|
|||
value.as_f64().map_or_else(|| "n/a".into(), |number| format!("{number:.3}"))
|
||||
}
|
||||
|
||||
fn policy_words(policy: WakePolicy) -> String {
|
||||
match policy {
|
||||
WakePolicy::Live => "live: the operator or another Mind addressing her (the heartbeat's rule today)".into(),
|
||||
WakePolicy::Ruled => "ruled: a line addressing her, from anyone, and any human line in her rooms".into(),
|
||||
WakePolicy::HumansPace(cap) => format!("humans_pace (cap {cap}): a human's line wakes a Mind in her own room always, and in a public room when it addresses her or continues an exchange she is in; a Mind's line wakes another only by an explicit mention or a reply, while her current Mind-only run, across her rooms, is under {cap} lines, never by a name in prose"),
|
||||
WakePolicy::NamesWithCap(cap) => format!("names_with_cap {cap}: ruled, but a Mind's line wakes no one once her current Mind-only run, across her rooms, has {cap} lines, until a human speaks where it runs"),
|
||||
WakePolicy::AllMessages => "all_messages: any line in her rooms, a Mind's too (the old loop, the control)".into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// `count` lines spread evenly over the transcript, the first and the last included.
|
||||
fn representative(transcript: &[Value], count: usize) -> Vec<&Value> {
|
||||
if transcript.len() <= count {
|
||||
|
|
@ -798,7 +752,7 @@ fn markdown(plan_path: &Path, plan: &SimFile, members: &[Member], group_state: O
|
|||
let _ = writeln!(out, "- rooms: {}; rounds: {}; repeats: {}; seed: {}; minutes a round: {}; she is in a room's exchange when she spoke there within {} min", plan.rooms.join(", "), plan.rounds, plan.repeats, plan.seed, plan.round_minutes, plan.exchange_minutes);
|
||||
let owners: Vec<String> = members.iter().filter(|member| !member.entry.own_rooms.is_empty()).map(|member| format!("{}: {}", member.entry.name, member.entry.own_rooms.join(", "))).collect();
|
||||
let _ = writeln!(out, "- own rooms (from the plan: neither the heartbeat's table nor `persona.env` records room ownership): {}", if owners.is_empty() { "none".to_owned() } else { owners.join("; ") });
|
||||
let _ = writeln!(out, "- wake: {}; beat: {}", policy_words(plan.wake), if plan.beat_s == 0 { "off".to_owned() } else { format!("every {} s of simulated time, one Persona by `tempo::pick`", plan.beat_s) });
|
||||
let _ = writeln!(out, "- wake: humans pace (`heartbeat::wakes`); beat: {}", if plan.beat_s == 0 { "off".to_owned() } else { format!("every {} s of simulated time, one Persona by `tempo::pick`", plan.beat_s) });
|
||||
let _ = writeln!(out, "- group state in the Projector's packet: {}", match group_state { Some(true) => "on", Some(false) => "off", None => "unknown (the tuning did not load)" });
|
||||
let _ = writeln!(out, "- speech: the Interpreter's lines, each posted to its room; none is silence");
|
||||
let _ = writeln!(out, "- wakes are counted per wake, by its strongest cause: addressed by a human, a human line, addressed by a Mind, a Mind's line (control only), the beat. A Mind-addressed wake's evidence is its strongest: a Matrix mention or reply, her id written as text, a name in the text");
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use crate::projection::harness::tests::{Replaying, Scripted, control};
|
|||
use serde_json::json;
|
||||
use crate::projection::narrate::PROJECTOR_OPENING;
|
||||
use crate::projection::{Answer, Failed, Model, Spent};
|
||||
use crate::chat_client::{ChatDelivery, ContextLine};
|
||||
use crate::heartbeat::{MIND_RUN_BACKSTOP, LineFacts, own_rooms, pending_facts};
|
||||
|
||||
const TOBIAH: &str = "@eureka:gamecult.org";
|
||||
const LIBBY: &str = "@libby:gamecult.org";
|
||||
|
|
@ -22,8 +24,8 @@ fn cast(dir: &Path) {
|
|||
std::fs::write(dir.join("libby.json"), libby.to_string()).unwrap();
|
||||
}
|
||||
|
||||
/// A plan over the two, the operator opening; `wake` is the TOML value of the policy; no beat unless `extra` sets one.
|
||||
fn plan(dir: &Path, wake: &str, rounds: usize, extra: &str) -> PathBuf {
|
||||
/// A plan over the two, the operator opening in #minds, which is the room of both; no beat unless `extra` sets one.
|
||||
fn plan(dir: &Path, rounds: usize, extra: &str) -> PathBuf {
|
||||
cast(dir);
|
||||
let path = dir.join("plan.toml");
|
||||
let beat = if extra.contains("beat_s") { "" } else { "beat_s = 0\n" };
|
||||
|
|
@ -32,7 +34,6 @@ fn plan(dir: &Path, wake: &str, rounds: usize, extra: &str) -> PathBuf {
|
|||
format!(
|
||||
r##"rounds = {rounds}
|
||||
seed = 11
|
||||
wake = {wake}
|
||||
start = "2026-11-20T15:00:00Z"
|
||||
rooms = ["#minds:gamecult.org"]
|
||||
operators = ["@meta:gamecult.org"]
|
||||
|
|
@ -40,10 +41,12 @@ operators = ["@meta:gamecult.org"]
|
|||
[[cast]]
|
||||
id = "{TOBIAH}"
|
||||
name = "Tobiah"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "tobiah.json"
|
||||
[[cast]]
|
||||
id = "{LIBBY}"
|
||||
name = "Libby"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "libby.json"
|
||||
[[message]]
|
||||
from = "@meta:gamecult.org"
|
||||
|
|
@ -57,6 +60,14 @@ says = "good afternoon, everyone"
|
|||
path
|
||||
}
|
||||
|
||||
/// The same plan with no room hers: a public room's human line wakes her only by address or her exchange.
|
||||
fn bare_plan(dir: &Path, rounds: usize, extra: &str) -> PathBuf {
|
||||
let path = plan(dir, rounds, extra);
|
||||
std::fs::write(&path, std::fs::read_to_string(&path).unwrap().replace("own_rooms = [\"#minds:gamecult.org\"]
|
||||
", "")).unwrap();
|
||||
path
|
||||
}
|
||||
|
||||
fn is_tobiah(prompt: &str) -> bool {
|
||||
prompt.contains("Who you are:\nTobiah")
|
||||
}
|
||||
|
|
@ -88,48 +99,92 @@ fn turns(run: &Value) -> Vec<(u64, String, String)> {
|
|||
run["turns"].as_array().unwrap().iter().map(|turn| (turn["round"].as_u64().unwrap(), turn["persona"].as_str().unwrap().to_owned(), turn["woke"].as_str().unwrap().to_owned())).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_wake_policies_are_the_heartbeats_one_function() {
|
||||
/// One line to Libby as a delivery, with the facts a caller gives it.
|
||||
fn ask(from: &str, says: &str, speaker: Speaker, facts: LineFacts) -> Option<WakeCause> {
|
||||
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
|
||||
let line = |from: &str, says: &str| Line { from: from.into(), name: String::new(), room: "#minds:x".into(), at_ms: 0, says: says.into(), mentions: vec![], dm_to: None, follow_up: false, reply_to: None, new: false };
|
||||
let ask = |policy: WakePolicy, from: &str, says: &str, speaker: Speaker, run: usize| wakes(policy, &libby, &line(from, says).delivery(0, LIBBY, &[]), speaker, LineFacts { mind_run: run, ..LineFacts::default() });
|
||||
let paced = |says: &str, own_room: bool, in_exchange: bool| wakes(WakePolicy::HumansPace(4), &libby, &line("@meta:x", says).delivery(0, LIBBY, &[]), Speaker::Operator, LineFacts { mind_run: 0, own_room, in_exchange });
|
||||
let (named, unnamed) = ("Libby, tea?", "what a day");
|
||||
use WakeCause::*;
|
||||
// Ruled: anyone addressing her, any human line.
|
||||
assert_eq!(ask(WakePolicy::Ruled, TOBIAH, named, Speaker::Mind, 0), Some(AddressedByMind));
|
||||
assert_eq!(ask(WakePolicy::Ruled, TOBIAH, unnamed, Speaker::Mind, 0), None, "another Mind's unaddressed line wakes no one");
|
||||
assert_eq!(ask(WakePolicy::Ruled, "@deru:x", unnamed, Speaker::Member, 0), Some(Human));
|
||||
assert_eq!(ask(WakePolicy::Ruled, "@deru:x", named, Speaker::Member, 0), Some(AddressedByHuman));
|
||||
// Live, the heartbeat's today: a member's line does not wake her, the operator's or a Mind's address does.
|
||||
assert_eq!(ask(WakePolicy::Live, "@deru:x", named, Speaker::Member, 0), None);
|
||||
assert_eq!(ask(WakePolicy::Live, "@meta:x", named, Speaker::Operator, 0), Some(AddressedByHuman));
|
||||
assert_eq!(ask(WakePolicy::Live, TOBIAH, named, Speaker::Mind, 0), Some(AddressedByMind));
|
||||
assert_eq!(ask(WakePolicy::Live, "@meta:x", unnamed, Speaker::Operator, 0), None);
|
||||
// Humans pace: a Mind's line never wakes a Mind; a human's wakes her in her own room, or in a public room when it
|
||||
// addresses her or continues an exchange she is in.
|
||||
assert_eq!(ask(WakePolicy::HumansPace(4), TOBIAH, named, Speaker::Mind, 0), None, "a name in prose wakes no one");
|
||||
let tagged = Line { mentions: vec![LIBBY.into()], ..line(TOBIAH, unnamed) };
|
||||
let explicit = |run: usize| wakes(WakePolicy::HumansPace(4), &libby, &tagged.delivery(0, LIBBY, &[]), Speaker::Mind, LineFacts { mind_run: run, ..LineFacts::default() });
|
||||
assert_eq!(explicit(3), Some(AddressedByMind), "a Matrix mention by a Mind wakes her, in any room");
|
||||
assert_eq!(explicit(4), None, "the backstop: past the cap of Mind lines in a row, no Mind wakes another");
|
||||
assert_eq!(paced(unnamed, false, false), None, "a public room's human line that is not hers to answer");
|
||||
assert_eq!(paced(unnamed, true, false), Some(Human));
|
||||
assert_eq!(paced(unnamed, false, true), Some(Human));
|
||||
assert_eq!(paced(named, false, false), Some(AddressedByHuman));
|
||||
// The cap: a Mind's address wakes her only while the Mind run before the line is under it.
|
||||
assert_eq!(ask(WakePolicy::NamesWithCap(2), TOBIAH, named, Speaker::Mind, 1), Some(AddressedByMind));
|
||||
assert_eq!(ask(WakePolicy::NamesWithCap(2), TOBIAH, named, Speaker::Mind, 2), None);
|
||||
assert_eq!(ask(WakePolicy::NamesWithCap(2), "@meta:x", unnamed, Speaker::Operator, 9), Some(Human), "a human always may");
|
||||
// The control, and her own line never.
|
||||
assert_eq!(ask(WakePolicy::AllMessages, TOBIAH, unnamed, Speaker::Mind, 0), Some(Mind));
|
||||
assert_eq!(ask(WakePolicy::AllMessages, LIBBY, named, Speaker::Her, 0), None);
|
||||
let line = Line { from: from.into(), name: String::new(), room: "#minds:x".into(), at_ms: 0, says: says.into(), mentions: vec![], dm_to: None, follow_up: false, reply_to: None, new: false };
|
||||
wakes(&libby, &line.delivery(0, LIBBY, &[]), speaker, facts)
|
||||
}
|
||||
|
||||
fn facts(own_room: bool, in_exchange: bool) -> LineFacts {
|
||||
LineFacts { mind_run: 0, own_room, in_exchange }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn under_the_ruled_set_unaddressed_mind_lines_wake_no_one() {
|
||||
fn t_w1_member_in_own_room_wakes() {
|
||||
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, facts(true, false)), Some(WakeCause::Human));
|
||||
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, LineFacts::default()), None, "no fact of hers, no wake");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_w1_member_in_shared_room_needs_address_or_exchange() {
|
||||
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, facts(false, false)), None);
|
||||
assert_eq!(ask("@deru:x", "Libby, tea?", Speaker::Member, facts(false, false)), Some(WakeCause::AddressedByHuman));
|
||||
assert_eq!(ask("@deru:x", "what a day", Speaker::Member, facts(false, true)), Some(WakeCause::Human));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_w1_mind_line_backstop() {
|
||||
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
|
||||
let tagged = Line { from: TOBIAH.into(), name: String::new(), room: "#minds:x".into(), at_ms: 0, says: "what a day".into(), mentions: vec![LIBBY.into()], dm_to: None, follow_up: false, reply_to: None, new: false };
|
||||
let explicit = |run: usize| wakes(&libby, &tagged.delivery(0, LIBBY, &[]), Speaker::Mind, LineFacts { mind_run: run, ..LineFacts::default() });
|
||||
assert_eq!(explicit(MIND_RUN_BACKSTOP - 1), Some(WakeCause::AddressedByMind), "a Matrix mention by a Mind wakes her, in any room");
|
||||
assert_eq!(explicit(MIND_RUN_BACKSTOP), None, "the backstop: at the cap of Mind lines in a row, no Mind wakes another");
|
||||
assert_eq!(ask(TOBIAH, "Libby, tea?", Speaker::Mind, facts(true, true)), None, "a name in prose wakes no Mind");
|
||||
assert_eq!(ask(LIBBY, "Libby, tea?", Speaker::Her, facts(true, true)), None, "her own line never");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_w1_dm_wakes() {
|
||||
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
|
||||
let dm = Line { from: "@deru:x".into(), name: String::new(), room: "!dm:x".into(), at_ms: 0, says: "psst".into(), mentions: vec![], dm_to: Some(LIBBY.into()), follow_up: false, reply_to: None, new: false };
|
||||
assert_eq!(wakes(&libby, &dm.delivery(0, LIBBY, &[]), Speaker::Member, LineFacts::default()), Some(WakeCause::AddressedByHuman));
|
||||
}
|
||||
|
||||
/// One fixture of lines, read by the simulator's room and by the poll's pending deliveries, gives the same facts and the same wakes.
|
||||
#[test]
|
||||
fn t_w1_same_facts_both_paths() {
|
||||
let cast = vec![TOBIAH.to_owned(), LIBBY.to_owned()];
|
||||
let own = vec!["#libby:x".to_owned()];
|
||||
let line = |from: &str, room: &str, minutes: u64, mentions: Vec<String>| Line { from: from.into(), name: String::new(), room: room.into(), at_ms: minutes * 60_000, says: "hi".into(), mentions, dm_to: None, follow_up: false, reply_to: None, new: false };
|
||||
let lines = [
|
||||
line("@deru:x", "#general:x", 0, vec![]),
|
||||
line(LIBBY, "#general:x", 1, vec![]),
|
||||
line("@deru:x", "#general:x", 2, vec![]),
|
||||
line("@deru:x", "#libby:x", 3, vec![]),
|
||||
line(TOBIAH, "#general:x", 4, vec![LIBBY.into()]),
|
||||
line("@deru:x", "#general:x", 100, vec![]),
|
||||
];
|
||||
let libby = Addressee::new(LIBBY, ["libby", "Libby"]);
|
||||
let speaker = |line: &Line| if line.from == TOBIAH { Speaker::Mind } else { Speaker::Member };
|
||||
// The simulator's path: the lines she sees, in order.
|
||||
let seeing: Vec<FactLine> = lines.iter().map(|line| FactLine { sender: &line.from, room: &line.room, at_ms: line.at_ms, is_direct: false }).collect();
|
||||
let simulated = line_facts(&seeing, LIBBY, &cast, &own, 30 * 60_000);
|
||||
// The poll's path: the deliveries pending (not her own lines), each with the room's earlier lines as its context.
|
||||
let heard: Vec<usize> = (0..lines.len()).filter(|at| lines[*at].from != LIBBY).collect();
|
||||
let deliveries: Vec<ChatDelivery> = heard
|
||||
.iter()
|
||||
.map(|at| {
|
||||
let mut delivery = lines[*at].delivery(*at, LIBBY, &lines);
|
||||
delivery.context = lines[..*at].iter().filter(|earlier| earlier.room == lines[*at].room).map(|earlier| ContextLine { sender: earlier.from.clone(), text: String::new(), at_unix_ms: earlier.at_ms }).collect();
|
||||
delivery
|
||||
})
|
||||
.collect();
|
||||
let pending: Vec<&ChatDelivery> = deliveries.iter().collect();
|
||||
let polled = pending_facts(&pending, LIBBY, &cast, &own);
|
||||
let by_sim: Vec<Option<WakeCause>> = heard.iter().map(|at| wakes(&libby, &lines[*at].delivery(*at, LIBBY, &lines), speaker(&lines[*at]), simulated[*at])).collect();
|
||||
let by_poll: Vec<Option<WakeCause>> = heard.iter().zip(&polled).map(|(at, facts)| wakes(&libby, &lines[*at].delivery(*at, LIBBY, &lines), speaker(&lines[*at]), *facts)).collect();
|
||||
assert_eq!(by_sim, by_poll);
|
||||
assert_eq!(by_sim, vec![None, Some(WakeCause::Human), Some(WakeCause::Human), Some(WakeCause::AddressedByMind), None], "a general line before she spoke, one in her exchange, her room, a Mind's tag, a general line after the exchange lapsed");
|
||||
for (at, facts) in heard.iter().zip(&polled) {
|
||||
assert_eq!((facts.own_room, facts.in_exchange), (simulated[*at].own_room, simulated[*at].in_exchange), "line {at}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unaddressed_mind_lines_wake_no_one() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 6, ""), &chatty());
|
||||
let (_, run) = run_plan(&plan(dir.path(), 6, ""), &chatty());
|
||||
let turns = turns(&run);
|
||||
assert_eq!(turns.len(), 2, "the operator's opening wakes both in round 1, and then nothing does: {turns:?}");
|
||||
assert!(turns.iter().all(|(round, _, why)| *round == 1 && why == "human"), "{turns:?}");
|
||||
|
|
@ -137,32 +192,11 @@ fn under_the_ruled_set_unaddressed_mind_lines_wake_no_one() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn the_control_lets_minds_wake_each_other_into_a_reply_chain_counted_per_room() {
|
||||
fn a_name_in_prose_wakes_no_mind_and_a_chain_of_names_never_starts() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, run) = run_plan(&plan(dir.path(), "\"all_messages\"", 6, ""), &chatty());
|
||||
let metrics = &run["metrics"];
|
||||
assert!(metrics["wakes"]["mind"].as_u64().unwrap() >= 5, "{metrics}");
|
||||
let chain = &metrics["reply_chains"]["#minds:gamecult.org"];
|
||||
// The two round-1 answers are to the operator; every later line is a reply to a Mind.
|
||||
assert_eq!(chain["mind_to_mind_replies"].as_u64(), Some(metrics["mind_messages"].as_u64().unwrap() - 2), "{metrics}");
|
||||
assert!(chain["longest"].as_u64().unwrap() >= 5 && chain["chains_of_3_or_more"] == 1, "{chain}");
|
||||
let work = metrics["work_talk_share"].as_f64().unwrap();
|
||||
assert!(work > 0.3 && work < 0.7, "Libby's lines name the deploy, Tobiah's do not: {work}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn naming_runs_away_under_the_ruled_set_and_stops_at_the_cap() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, ruled) = run_plan(&plan(dir.path(), "\"ruled\"", 6, ""), &namers());
|
||||
assert!(turns(&ruled).iter().filter(|(_, _, why)| why == "addressed_by_mind").count() >= 5, "{:?}", turns(&ruled));
|
||||
assert_eq!(ruled["metrics"]["mind_addressed_wakes"]["name_in_text"], ruled["metrics"]["mind_addressed_wakes"]["total"]);
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, capped) = run_plan(&plan(dir.path(), "{ names_with_cap = 2 }", 6, ""), &namers());
|
||||
let capped = turns(&capped);
|
||||
assert!(capped.iter().all(|(round, _, _)| *round <= 2), "after two Mind lines in a row no Mind's address wakes anyone: {capped:?}");
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, paced) = run_plan(&plan(dir.path(), "{ humans_pace = 4 }", 6, ""), &namers());
|
||||
assert!(turns(&paced).is_empty(), "under humans_pace an unaddressed public line wakes no one, and no Mind's line ever does");
|
||||
let (_, run) = run_plan(&plan(dir.path(), 6, ""), &namers());
|
||||
assert_eq!(turns(&run).len(), 2, "the opening wakes both in round 1; their names for each other wake no one: {:?}", turns(&run));
|
||||
assert_eq!(run["metrics"]["mind_addressed_wakes"]["total"], 0, "{}", run["metrics"]["mind_addressed_wakes"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -174,7 +208,7 @@ fn under_humans_pace_her_own_room_wakes_her_and_a_public_room_only_by_address_or
|
|||
std::fs::write(
|
||||
&path,
|
||||
format!(
|
||||
"rounds = 4\nseed = 11\nwake = {{ humans_pace = 4 }}\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}{}",
|
||||
"rounds = 4\nseed = 11\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}{}",
|
||||
line(0, "#minds:gamecult.org", "Libby, how was the gig?"),
|
||||
line(2, "#minds:gamecult.org", "and the rest of you?"),
|
||||
line(3, "#tobiah:gamecult.org", "quiet in here today")
|
||||
|
|
@ -194,7 +228,7 @@ fn under_humans_pace_her_own_room_wakes_her_and_a_public_room_only_by_address_or
|
|||
#[test]
|
||||
fn the_beat_wakes_one_persona_by_the_heartbeats_pick() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 4, "beat_s = 120"), &silent());
|
||||
let (_, run) = run_plan(&plan(dir.path(), 4, "beat_s = 120"), &silent());
|
||||
let turns = turns(&run);
|
||||
for round in 2..=4 {
|
||||
let beats: Vec<&(u64, String, String)> = turns.iter().filter(|(at, _, _)| *at == round).collect();
|
||||
|
|
@ -222,7 +256,7 @@ impl Model for FailingPersona {
|
|||
#[test]
|
||||
fn a_failed_call_is_a_failure_and_not_a_silence() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 2, ""), &FailingPersona);
|
||||
let (_, run) = run_plan(&plan(dir.path(), 2, ""), &FailingPersona);
|
||||
let metrics = &run["metrics"];
|
||||
// A failed wake sees nothing (K65), so the line that woke each wakes her again the next round: two each.
|
||||
assert_eq!((metrics["failed"].as_u64(), metrics["silence_rate"].is_null()), (Some(4), true), "{metrics}");
|
||||
|
|
@ -238,7 +272,7 @@ fn a_seed_replays_its_order_and_another_seed_changes_it() {
|
|||
sorted.sort_unstable();
|
||||
assert_eq!(sorted, items, "a shuffle, nothing lost");
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), "\"all_messages\"", 4, "");
|
||||
let path = plan(dir.path(), 4, "");
|
||||
assert_eq!(turns(&run_plan(&path, &chatty()).1), turns(&run_plan(&path, &chatty()).1));
|
||||
}
|
||||
|
||||
|
|
@ -257,25 +291,25 @@ fn tagging(mention: bool) -> Scripted {
|
|||
fn only_the_interpreters_structured_mention_is_a_mention_and_an_at_in_the_text_is_not() {
|
||||
// Libby says hello first, so the packet shows her to Tobiah: a mention reaches only someone shown.
|
||||
let hello = "[[message]]\nround = 0\nfrom = \"@libby:gamecult.org\"\nname = \"Libby\"\nroom = \"#minds:gamecult.org\"\nsays = \"hello all\"\n";
|
||||
let plan = |dir: &Path, wake: &str, rounds: usize| {
|
||||
let path = plan(dir, wake, rounds, "");
|
||||
let plan = |dir: &Path, rounds: usize| {
|
||||
let path = plan(dir, rounds, "");
|
||||
std::fs::write(&path, format!("{}{hello}", std::fs::read_to_string(&path).unwrap())).unwrap();
|
||||
path
|
||||
};
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, plain) = run_plan(&plan(dir.path(), "\"ruled\"", 3), &tagging(false));
|
||||
let (_, plain) = run_plan(&plan(dir.path(), 3), &tagging(false));
|
||||
let addressed = &plain["metrics"]["mind_addressed_wakes"];
|
||||
assert_eq!(addressed["mention_or_reply"].as_u64(), Some(0), "an @id in the words tags no one: {addressed}");
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, tagged) = run_plan(&plan(dir.path(), "\"ruled\"", 3), &tagging(true));
|
||||
let (_, tagged) = run_plan(&plan(dir.path(), 3), &tagging(true));
|
||||
let addressed = &tagged["metrics"]["mind_addressed_wakes"];
|
||||
let libby_mind_wakes = turns(&tagged).iter().filter(|(_, who, why)| who == "Libby" && why == "addressed_by_mind").count();
|
||||
assert_eq!(addressed["mention_or_reply"].as_u64().unwrap() as usize, libby_mind_wakes, "{addressed}");
|
||||
// Under humans_pace a name or an @ in the words wakes no one; the structured mention does.
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), "{ humans_pace = 4 }", 3);
|
||||
let path = plan(dir.path(), 3);
|
||||
let opening = "says = \"good afternoon, everyone\"\n";
|
||||
std::fs::write(&path, std::fs::read_to_string(&path).unwrap().replace(opening, &format!("{opening}mentions = [\"{TOBIAH}\"]\n"))).unwrap();
|
||||
std::fs::write(&path, std::fs::read_to_string(&path).unwrap().replace("own_rooms = [\"#minds:gamecult.org\"]\n", "").replace(opening, &format!("{opening}mentions = [\"{TOBIAH}\"]\n"))).unwrap();
|
||||
let woken_libby = |model: &Scripted| turns(&run_plan(&path, model).1).iter().any(|(_, who, _)| who == "Libby");
|
||||
assert!(!woken_libby(&tagging(false)));
|
||||
assert!(woken_libby(&tagging(true)));
|
||||
|
|
@ -284,7 +318,7 @@ fn only_the_interpreters_structured_mention_is_a_mention_and_an_at_in_the_text_i
|
|||
#[test]
|
||||
fn a_direct_message_in_one_of_the_plans_rooms_is_refused() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), "\"ruled\"", 2, "");
|
||||
let path = plan(dir.path(), 2, "");
|
||||
let dm = "[[message]]\nround = 1\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\ndm = true\nto = \"@libby:gamecult.org\"\nsays = \"psst\"\n";
|
||||
std::fs::write(&path, format!("{}{dm}", std::fs::read_to_string(&path).unwrap())).unwrap();
|
||||
let model = silent();
|
||||
|
|
@ -294,18 +328,20 @@ fn a_direct_message_in_one_of_the_plans_rooms_is_refused() {
|
|||
|
||||
#[test]
|
||||
fn the_mind_run_is_counted_across_her_rooms_and_an_uncounted_run_is_at_the_cap() {
|
||||
let her = Member { names_from: "test", addressee: Addressee::new("@kiko:x", ["kiko"]), entry: CastEntry { id: "@kiko:x".into(), name: "Kiko".into(), state: PathBuf::new(), rooms: vec![], own_rooms: vec![], domain: None, reads: None }, state: Value::Null, rooms: vec!["#a:x".into(), "#b:x".into()] };
|
||||
let cast = vec![TOBIAH.to_owned(), LIBBY.to_owned(), "@kiko:x".to_owned(), "@other:x".to_owned()];
|
||||
let line = |from: &str, room: &str| Line { from: from.into(), name: String::new(), room: room.into(), at_ms: 0, says: "hi".into(), mentions: vec![], dm_to: None, follow_up: false, reply_to: None, new: false };
|
||||
let lines = [line("@meta:x", "#a:x"), line(TOBIAH, "#a:x"), line("@other:x", "#b:x"), line(TOBIAH, "#b:x"), line("@meta:x", "#c:x")];
|
||||
assert_eq!(mind_runs(&lines, &cast, &her), vec![0, 0, 1, 2, 3], "one run across #a and #b; a room she is not in does not break it");
|
||||
let line = |from: &'static str, room: &'static str| FactLine { sender: from, room, at_ms: 0, is_direct: false };
|
||||
let run = |lines: &[FactLine]| line_facts(lines, "@kiko:x", &cast, &[], 0).iter().map(|facts| facts.mind_run).collect::<Vec<_>>();
|
||||
assert_eq!(run(&[line("@meta:x", "#a:x"), line(TOBIAH, "#a:x"), line("@other:x", "#b:x"), line(TOBIAH, "#b:x")]), vec![0, 0, 1, 2]);
|
||||
// Soul's case: Meta chatting in #eureka does not end a loop in #minds; a word from Meta in #minds does.
|
||||
let kiko = Member { rooms: vec!["#minds:x".into(), "#eureka:x".into()], ..her };
|
||||
let lines = [line(TOBIAH, "#minds:x"), line(LIBBY, "#minds:x"), line("@meta:x", "#eureka:x"), line(TOBIAH, "#minds:x"), line("@meta:x", "#minds:x"), line(LIBBY, "#minds:x")];
|
||||
assert_eq!(mind_runs(&lines, &cast, &kiko), vec![0, 1, 2, 2, 3, 0]);
|
||||
assert_eq!(run(&[line(TOBIAH, "#minds:x"), line(LIBBY, "#minds:x"), line("@meta:x", "#eureka:x"), line(TOBIAH, "#minds:x"), line("@meta:x", "#minds:x"), line(LIBBY, "#minds:x")]), vec![0, 1, 2, 2, 3, 0]);
|
||||
assert_eq!(LineFacts::default().mind_run, usize::MAX, "fail-safe: an uncounted run is at the cap");
|
||||
let tagged = Line { mentions: vec!["@kiko:x".into()], ..line(TOBIAH, "#a:x") };
|
||||
assert_eq!(wakes(WakePolicy::HumansPace(4), &kiko.addressee, &tagged.delivery(0, "@kiko:x", &[]), Speaker::Mind, LineFacts::default()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn her_own_rooms_are_the_rooms_named_for_her_repos() {
|
||||
let aliases = ["#huginn:gamecult.org", "#general:gamecult.org", "#Cultlib:gamecult.org", "!abc:gamecult.org"];
|
||||
assert_eq!(own_rooms(["GameCult/Huginn", "GameCult/CultLib"], aliases), vec!["#huginn:gamecult.org".to_owned(), "#Cultlib:gamecult.org".to_owned()]);
|
||||
assert!(own_rooms([], aliases).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -313,7 +349,7 @@ fn the_report_names_its_gaps_and_carries_representative_lines_and_usage() {
|
|||
let dir = tempfile::tempdir().unwrap();
|
||||
let model = chatty();
|
||||
let harness = Harness { instance: "eureka".into(), persona: None, model: Some(&model), tuning: dir.path().join("persona-tuning.toml") };
|
||||
let report = simulate(&harness, &plan(dir.path(), "\"ruled\"", 3, "")).unwrap();
|
||||
let report = simulate(&harness, &plan(dir.path(), 3, "")).unwrap();
|
||||
for part in ["# Swarm simulation", "Speech is the Interpreter's", "group state in the Projector's packet: on", "### Representative lines", "**Meta (human)**: good afternoon, everyone", "**Tobiah** _(woke: human)_: what a day", "### Wakes by round", "| 1 | 0 | 2 | 0 | 0 | 0 |", "## Total usage", "| claude-sonnet-5-5 | 6 |"] {
|
||||
assert!(report.contains(part), "{part}\n{report}");
|
||||
}
|
||||
|
|
@ -324,7 +360,7 @@ fn a_cast_past_eight_or_a_foreign_state_is_refused() {
|
|||
let dir = tempfile::tempdir().unwrap();
|
||||
let model = chatty();
|
||||
let harness = Harness { instance: "eureka".into(), persona: None, model: Some(&model), tuning: dir.path().join("persona-tuning.toml") };
|
||||
let path = plan(dir.path(), "\"ruled\"", 2, "");
|
||||
let path = plan(dir.path(), 2, "");
|
||||
let text = std::fs::read_to_string(&path).unwrap().replace("state = \"libby.json\"", "state = \"tobiah.json\"");
|
||||
std::fs::write(&path, text).unwrap();
|
||||
assert!(format!("{:#}", simulate(&harness, &path).unwrap_err()).contains("refused by a put"), "Libby cannot hold Eureka's state");
|
||||
|
|
@ -336,7 +372,7 @@ fn a_cast_past_eight_or_a_foreign_state_is_refused() {
|
|||
#[test]
|
||||
fn a_scripted_direct_message_reaches_and_wakes_only_its_recipient() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), "\"ruled\"", 2, "");
|
||||
let path = plan(dir.path(), 2, "");
|
||||
let dm = "[[message]]\nround = 1\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"!dm-libby:gamecult.org\"\ndm = true\nto = \"@libby:gamecult.org\"\nsays = \"just you, how are you?\"\n";
|
||||
let text = std::fs::read_to_string(&path).unwrap().replace("[[message]]\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\nsays = \"good afternoon, everyone\"\n", dm);
|
||||
std::fs::write(&path, &text).unwrap();
|
||||
|
|
@ -358,7 +394,7 @@ fn the_turn_is_in_the_room_of_the_line_that_woke_her() {
|
|||
std::fs::write(
|
||||
&path,
|
||||
format!(
|
||||
"rounds = 1\nseed = 11\nwake = {{ humans_pace = 4 }}\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}",
|
||||
"rounds = 1\nseed = 11\nbeat_s = 0\nstart = \"2026-11-20T15:00:00Z\"\nrooms = [\"#minds:gamecult.org\", \"#tobiah:gamecult.org\"]\noperators = [\"@meta:gamecult.org\"]\n[[cast]]\nid = \"{TOBIAH}\"\nname = \"Tobiah\"\nstate = \"tobiah.json\"\nown_rooms = [\"#tobiah:gamecult.org\"]\n[[cast]]\nid = \"{LIBBY}\"\nname = \"Libby\"\nstate = \"libby.json\"\n{}{}",
|
||||
line(0, "@meta:gamecult.org", "#tobiah:gamecult.org", "quiet in here"),
|
||||
line(0, LIBBY, "#minds:gamecult.org", "hello all")
|
||||
),
|
||||
|
|
@ -380,7 +416,7 @@ fn turns_by_persona(run: &Value) -> BTreeMap<String, Vec<(u64, String)>> {
|
|||
#[test]
|
||||
fn soul_f5_one_turn_a_round_and_a_room_that_woke_her_waits_for_the_next() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), "\"ruled\"", 2, "");
|
||||
let path = plan(dir.path(), 2, "");
|
||||
let line = |room: &str, dm: bool, says: &str| format!("[[message]]\nround = 1\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"{room}\"\n{}says = \"{says}\"\n", if dm { "dm = true\nto = \"@libby:gamecult.org\"\n" } else { "" });
|
||||
let opening = "[[message]]\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\nsays = \"good afternoon, everyone\"\n";
|
||||
let text = std::fs::read_to_string(&path).unwrap().replace(opening, &format!("{}{}", line("!dm-libby:gamecult.org", true, "just you: how are you, really?"), line("#minds:gamecult.org", false, "Libby, how was the gig?")));
|
||||
|
|
@ -398,21 +434,22 @@ fn soul_f5_one_turn_a_round_and_a_room_that_woke_her_waits_for_the_next() {
|
|||
|
||||
#[test]
|
||||
fn soul_f5_three_rooms_open_at_once_take_three_rounds_not_one() {
|
||||
for wake in ["\"ruled\"", "{ names_with_cap = 2 }"] {
|
||||
{
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), wake, 6, "");
|
||||
let path = plan(dir.path(), 6, "");
|
||||
let more = |room: &str, says: &str| format!("[[message]]\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"{room}\"\nsays = \"{says}\"\n");
|
||||
let text = std::fs::read_to_string(&path)
|
||||
.unwrap()
|
||||
.replace("rooms = [\"#minds:gamecult.org\"]", "rooms = [\"#minds:gamecult.org\", \"#lab:gamecult.org\", \"#ops:gamecult.org\"]")
|
||||
.replace("own_rooms = [\"#minds:gamecult.org\"]", "own_rooms = [\"#minds:gamecult.org\", \"#lab:gamecult.org\", \"#ops:gamecult.org\"]")
|
||||
.replace("rooms = [\"#minds:gamecult.org\"]\noperators", "rooms = [\"#minds:gamecult.org\", \"#lab:gamecult.org\", \"#ops:gamecult.org\"]\noperators")
|
||||
.replace("says = \"good afternoon, everyone\"\n", &format!("says = \"good afternoon, everyone\"\n{}{}", more("#lab:gamecult.org", "lab is open"), more("#ops:gamecult.org", "ops is open")));
|
||||
std::fs::write(&path, text).unwrap();
|
||||
let (_, run) = run_plan(&path, &namers());
|
||||
for (who, turns) in turns_by_persona(&run) {
|
||||
let rounds: Vec<u64> = turns.iter().map(|(round, _)| *round).collect();
|
||||
assert!(rounds.windows(2).all(|pair| pair[0] < pair[1]), "{wake}: {who} took two turns in one round: {turns:?}");
|
||||
assert!(rounds.windows(2).all(|pair| pair[0] < pair[1]), "{who} took two turns in one round: {turns:?}");
|
||||
let rooms: Vec<&str> = turns.iter().take(3).map(|(_, room)| room.as_str()).collect();
|
||||
assert_eq!(rooms, ["#minds:gamecult.org", "#lab:gamecult.org", "#ops:gamecult.org"], "{wake}: {who} answers each room in the order it opened");
|
||||
assert_eq!(rooms, ["#minds:gamecult.org", "#lab:gamecult.org", "#ops:gamecult.org"], "{who} answers each room in the order it opened");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -442,7 +479,7 @@ fn reaching() -> Scripted {
|
|||
fn soul_k9_each_turn_opens_with_what_came_of_her_last_and_only_her_last() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let model = reaching();
|
||||
let (_, run) = run_plan(&plan(dir.path(), "\"all_messages\"", 6, ""), &model);
|
||||
let (_, run) = run_plan(&plan(dir.path(), 8, "beat_s = 120"), &model);
|
||||
let projected: Vec<String> = model.calls.borrow().iter().map(|(_, prompt)| prompt.clone()).filter(|prompt| prompt.starts_with(PROJECTOR_OPENING) && prompt.contains("Who he is:\nTobiah")).take(3).collect();
|
||||
assert_eq!(projected.len(), 3, "{}", run["turns"]);
|
||||
assert!(!projected[0].contains("What came of his last turn:"), "a first turn has no last: {}", projected[0]);
|
||||
|
|
@ -466,7 +503,7 @@ fn soul_k9_each_turn_opens_with_what_came_of_her_last_and_only_her_last() {
|
|||
#[test]
|
||||
fn soul_k9_a_failed_turn_is_told_as_a_failure_next_turn() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (_, run) = run_plan(&plan(dir.path(), "\"ruled\"", 3, "beat_s = 120"), &FailingPersona);
|
||||
let (_, run) = run_plan(&plan(dir.path(), 3, "beat_s = 120"), &FailingPersona);
|
||||
let later: Vec<&Value> = run["turns"].as_array().unwrap().iter().filter(|turn| turn["round"].as_u64() > Some(1)).collect();
|
||||
assert!(!later.is_empty(), "{}", run["turns"]);
|
||||
for turn in later {
|
||||
|
|
@ -497,7 +534,7 @@ fn correcting(amends: bool) -> Scripted {
|
|||
|
||||
/// The plan, with Meta asking Tobiah in round 2 and Libby in round 3.
|
||||
fn asking(dir: &Path) -> PathBuf {
|
||||
let path = plan(dir, "\"ruled\"", 3, "");
|
||||
let path = plan(dir, 3, "");
|
||||
let ask = |round: usize, says: &str| format!("[[message]]\nround = {round}\nfrom = \"@meta:gamecult.org\"\nname = \"Meta\"\nroom = \"#minds:gamecult.org\"\nsays = \"{says}\"\n");
|
||||
std::fs::write(&path, format!("{}{}{}", std::fs::read_to_string(&path).unwrap(), ask(2, "Tobiah, did the file arrive?"), ask(3, "Libby, anything new?"))).unwrap();
|
||||
path
|
||||
|
|
@ -537,7 +574,7 @@ fn passing_on() -> Scripted {
|
|||
if !prompt.contains("Who he is:\nTobiah") {
|
||||
return json!({ "say": [], "gaps": [] }).to_string();
|
||||
}
|
||||
json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": "q1" }], "gaps": [] }).to_string()
|
||||
json!({ "say": [{ "draft": 1, "mentions": [LIBBY], "in_reply_to": "q1" }], "gaps": [] }).to_string()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -547,15 +584,17 @@ fn passing_on() -> Scripted {
|
|||
#[test]
|
||||
fn k20_the_room_records_a_reply_and_another_minds_packet_shows_the_line_above_it() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), "\"all_messages\"", 2, "");
|
||||
let path = plan(dir.path(), 2, "");
|
||||
let hello = "[[message]]\nround = 0\nfrom = \"@libby:gamecult.org\"\nname = \"Libby\"\nroom = \"#minds:gamecult.org\"\nsays = \"hello all\"\n";
|
||||
std::fs::write(&path, format!("{}{hello}", std::fs::read_to_string(&path).unwrap())).unwrap();
|
||||
let (_, run) = run_plan(&path, &passing_on());
|
||||
let first = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Tobiah").expect("Meta's line wakes him");
|
||||
assert_eq!(first["report"]["renders"][0]["interpreter"]["said"][0]["in_reply_to"]["event"], "$fixture-0", "{}", first["report"]["renders"][0]["interpreter"]);
|
||||
let transcript = run["transcript"].as_array().unwrap();
|
||||
assert!(transcript.iter().filter(|line| line["from"] == TOBIAH).all(|line| line["says"] == "She greeted all of us, Libby."), "his line holds his words alone: {transcript:?}");
|
||||
let libby = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Libby" && turn["round"] == 2).expect("his line wakes her under all_messages");
|
||||
let libby = run["turns"].as_array().unwrap().iter().find(|turn| turn["persona"] == "Libby" && turn["round"] == 2).expect("his tag of her wakes her");
|
||||
let heard = libby["report"]["packet"]["heard"].as_str().unwrap();
|
||||
assert!(heard.contains("Meta, who runs the place, a few minutes ago: \"good afternoon, everyone\"\nJust now:\n\"Tobiah\" (@eureka:gamecult.org), replying to a line shown here (Meta, who runs the place, a few minutes ago), in #minds:gamecult.org: \"She greeted all of us, Libby.\""), "{heard}");
|
||||
assert!(heard.contains("Meta, who runs the place, a few minutes ago: \"good afternoon, everyone\"\nLibby Test, a few minutes ago: \"hello all\"\nJust now:\n\"Tobiah\" (@eureka:gamecult.org), replying to a line shown here (Meta, who runs the place, a few minutes ago), in #minds:gamecult.org: \"She greeted all of us, Libby.\""), "{heard}");
|
||||
assert_eq!(heard.matches("good afternoon, everyone").count(), 1, "Meta's line is listed once: {heard}");
|
||||
}
|
||||
|
||||
|
|
@ -603,7 +642,6 @@ fn k23_a_cast_members_domain_reaches_her_packets_alone() {
|
|||
format!(
|
||||
r##"rounds = 1
|
||||
seed = 11
|
||||
wake = "ruled"
|
||||
beat_s = 0
|
||||
start = "2026-11-20T15:00:00Z"
|
||||
rooms = ["#minds:gamecult.org"]
|
||||
|
|
@ -611,6 +649,7 @@ operators = ["@meta:gamecult.org"]
|
|||
[[cast]]
|
||||
id = "{TOBIAH}"
|
||||
name = "Tobiah"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "tobiah.json"
|
||||
[[cast.domain.repos]]
|
||||
repo = "GameCult/Lodur"
|
||||
|
|
@ -621,6 +660,7 @@ merged_at = "2026-11-19T12:00:00Z"
|
|||
[[cast]]
|
||||
id = "{LIBBY}"
|
||||
name = "Libby"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "libby.json"
|
||||
[[message]]
|
||||
from = "@meta:gamecult.org"
|
||||
|
|
@ -653,7 +693,6 @@ fn k24_a_cast_members_reads_come_from_her_fixture() {
|
|||
format!(
|
||||
r##"rounds = 1
|
||||
seed = 11
|
||||
wake = "ruled"
|
||||
beat_s = 0
|
||||
start = "2026-11-20T15:00:00Z"
|
||||
rooms = ["#minds:gamecult.org"]
|
||||
|
|
@ -661,6 +700,7 @@ operators = ["@meta:gamecult.org"]
|
|||
[[cast]]
|
||||
id = "{TOBIAH}"
|
||||
name = "Tobiah"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "tobiah.json"
|
||||
[[cast.read]]
|
||||
kind = "repo"
|
||||
|
|
@ -669,6 +709,7 @@ text = "SIM-READ: the knee bends first."
|
|||
[[cast]]
|
||||
id = "{LIBBY}"
|
||||
name = "Libby"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "libby.json"
|
||||
[[message]]
|
||||
from = "@meta:gamecult.org"
|
||||
|
|
@ -706,7 +747,6 @@ fn k58_every_call_of_a_wake_has_its_own_id_so_no_retry_or_continuation_is_a_repl
|
|||
format!(
|
||||
r##"rounds = 1
|
||||
seed = 11
|
||||
wake = "ruled"
|
||||
beat_s = 0
|
||||
start = "2026-11-20T15:00:00Z"
|
||||
rooms = ["#minds:gamecult.org"]
|
||||
|
|
@ -714,6 +754,7 @@ operators = ["@meta:gamecult.org"]
|
|||
[[cast]]
|
||||
id = "{TOBIAH}"
|
||||
name = "Tobiah"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "tobiah.json"
|
||||
[[cast.read]]
|
||||
kind = "repo"
|
||||
|
|
@ -722,6 +763,7 @@ text = "SIM-READ: the knee bends first."
|
|||
[[cast]]
|
||||
id = "{LIBBY}"
|
||||
name = "Libby"
|
||||
own_rooms = ["#minds:gamecult.org"]
|
||||
state = "libby.json"
|
||||
[[message]]
|
||||
from = "@meta:gamecult.org"
|
||||
|
|
@ -813,7 +855,7 @@ who = "her"
|
|||
#[test]
|
||||
fn k32_campaign_cast_read_refused() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = plan(dir.path(), "\"ruled\"", 2, "");
|
||||
let path = plan(dir.path(), 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();
|
||||
|
|
@ -874,7 +916,7 @@ fn x5_plan(dir: &Path) -> PathBuf {
|
|||
line(1, "@meta:gamecult.org", "Meta", "Libby, write out the two-line welcome you'd post for newcomers, but hold it, don't post it in here yet. Heimdall still has to rule on whether we put a welcome mat out at all. Just tell me when it's ready."),
|
||||
line(2, "@heimdall:gamecult.org", "Heimdall", "Meta, yes, put the welcome out. Libby, post your two lines.")
|
||||
);
|
||||
plan(dir, "{ humans_pace = 4 }", 3, &extra)
|
||||
bare_plan(dir, 3, &extra)
|
||||
}
|
||||
|
||||
const X5_HEIMDALL: &str = "Libby, post your two lines.";
|
||||
|
|
@ -959,7 +1001,6 @@ fn k65_a_broken_later_step_still_marks_seen() {
|
|||
format!(
|
||||
r##"rounds = 3
|
||||
seed = 11
|
||||
wake = {{ humans_pace = 4 }}
|
||||
beat_s = 0
|
||||
start = "2026-11-20T15:00:00Z"
|
||||
rooms = ["#minds:gamecult.org"]
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ mind_body::control: struct SwarmWriter pub-fields[]
|
|||
mind_body::control: struct UnsafeStore # [derive (Debug)] pub-fields[path: PathBuf, mode: u32, uid: u32]
|
||||
mind_body::heartbeat: # [derive (Clone , Debug , PartialEq , Eq)] pub enum Outcome { Held (HeldReason) , Polled { launched : Vec < Slug > , } , }
|
||||
mind_body::heartbeat: const DEFAULT_BEAT_S : u32
|
||||
mind_body::heartbeat: fn own_rooms < 'a > (repos : impl IntoIterator < Item = & 'a str > , aliases : impl IntoIterator < Item = & 'a str >) -> Vec < String >
|
||||
mind_body::heartbeat: fn poll (organs : & Organs , config : & Config) -> Result < Outcome >
|
||||
mind_body::heartbeat: impl Config
|
||||
mind_body::heartbeat: impl Config: fn new (personas : Vec < PersonaId > , operators : Vec < String > , beat_s : u32) -> Result < Self >
|
||||
|
|
@ -259,6 +260,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 MindDomain: fn stewarded (& self) -> Result < Vec < String > >
|
||||
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[]
|
||||
|
|
|
|||
Loading…
Reference in a new issue