Persona wake: the Mind run lapses with the exchange window, only a new message wakes, one DM check, the drain reads her rooms as the poll does
The Mind run ends after a silence of the exchange window, so a tag in #minds or a Mind-to-Mind DM wakes her again. An edit or a notice wakes no one on any path. A direct message is hers by address::is_for alone. The drain's own rooms come from heartbeat::own_rooms_among (the poll's stewardship reader, no forge URL), and an unread mind or mouth is named in the run's report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4e0df42e85
commit
c320966315
7 changed files with 215 additions and 51 deletions
|
|
@ -56,7 +56,8 @@ 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, own_rooms};
|
||||
use mind_body::heartbeat::{FileStore, HeartbeatView, own_rooms_among};
|
||||
use mind_body::queue::HuginnMind;
|
||||
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,13 +200,17 @@ 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![],
|
||||
// Her own rooms, as the heartbeat reads them: the rooms the mouth names for a repo she stewards. An unread mind or mouth is
|
||||
// said in the report, not read as no rooms.
|
||||
let (own, own_unread) = match (address, &chat) {
|
||||
(Some(address), Some(chat)) => match chat.pending() {
|
||||
Ok(pending) => match own_rooms_among(&HuginnMind::new(HuginnClient::new(address, instance.clone(), TIMEOUT)), pending.deliveries.iter().map(|delivery| delivery.room_alias.as_str())) {
|
||||
Ok(rooms) => (rooms, None),
|
||||
Err(error) => (vec![], Some(format!("her stewardships unread: {error}"))),
|
||||
},
|
||||
Err(error) => (vec![], Some(format!("the mouth's pending unread: {error}"))),
|
||||
},
|
||||
_ => vec![],
|
||||
_ => (vec![], None),
|
||||
};
|
||||
// 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))));
|
||||
|
|
@ -237,7 +242,10 @@ fn run_project(args: &[String]) -> Result<String> {
|
|||
last_wake: None,
|
||||
records: vec![],
|
||||
};
|
||||
let report = project(&organs, &request, chrono::Utc::now())?;
|
||||
let mut report = project(&organs, &request, chrono::Utc::now())?;
|
||||
if let Some(unread) = own_unread {
|
||||
report["own_rooms_unread"] = unread.into();
|
||||
}
|
||||
let addressing = &report["addressing"];
|
||||
// The addressing source is what decides "said to her": said first, where a person running this by hand sees it.
|
||||
eprintln!(
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ use eureka_pipeline::{OrgRepo, PipelineKind, RunTurn, Slug};
|
|||
use huginn_mind::PipelineFacts;
|
||||
|
||||
use crate::address::{Addressee, Name, is_for, project_names};
|
||||
use crate::chat_client::{Basis, Chat, ChatDelivery};
|
||||
use crate::chat_client::{Basis, Chat, ChatDelivery, Form};
|
||||
use crate::control::{ControlSource, Effective, FileSource, HeldReason, SwarmEffective, read_effective, read_envelope, set_mode_world_readable};
|
||||
use crate::launch::{Clock, Launcher};
|
||||
use crate::queue::{MindPort, headers, in_force, of_kind};
|
||||
|
|
@ -441,10 +441,11 @@ pub(crate) enum WakeCause {
|
|||
/// 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.
|
||||
/// How many lines her current Mind-only run held before this one: one run across every line the caller gives, so a
|
||||
/// loop cannot dodge the backstop by changing rooms. A human's line in a room the run has lines in ends it, and so
|
||||
/// does a silence of the exchange window: no line within it, and the next Mind's tag starts afresh.
|
||||
pub mind_run: usize,
|
||||
/// The line is in a room of hers: a direct message, or a room named for a repo she stewards (`own_rooms`).
|
||||
/// The line is in a room named for a repo she stewards (`own_rooms`). A direct message is hers by `address::is_for`.
|
||||
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,
|
||||
|
|
@ -464,18 +465,28 @@ 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.
|
||||
/// Both count over the lines they are given and no others: the simulator gives every line of every room she is in; the poll
|
||||
/// gives the pending deliveries and the mouth's context of each (at most 20 earlier lines of its room), because the mouth
|
||||
/// shows her no room that has nothing pending. So live, a run that alternates rooms is counted per room that has
|
||||
/// something pending, and an exchange 20 lines back is not seen; the simulator overstates the bound by that much.
|
||||
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();
|
||||
let mut last_at: Option<u64> = None;
|
||||
lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(at, line)| {
|
||||
// The run lapses with time: no line within the window before this one, and no run is left to count.
|
||||
if last_at.is_some_and(|last| line.at_ms.saturating_sub(last) > window_ms) {
|
||||
run = 0;
|
||||
run_rooms.clear();
|
||||
}
|
||||
last_at = Some(line.at_ms);
|
||||
let mind_run = run;
|
||||
if minds.iter().any(|mind| mind == line.sender) {
|
||||
run += 1;
|
||||
|
|
@ -487,16 +498,23 @@ pub(crate) fn line_facts(lines: &[FactLine], her: &str, minds: &[String], own_ro
|
|||
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),
|
||||
own_room: 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()
|
||||
}
|
||||
|
||||
/// Her own rooms among `aliases`, read from her mind the way the poll reads her stewardships (`stewardships_of`): the drain's
|
||||
/// input. An unreadable mind is an error for the caller to report, never an empty answer.
|
||||
pub fn own_rooms_among<'a>(mind: &dyn MindPort, aliases: impl IntoIterator<Item = &'a str>) -> Result<Vec<String>> {
|
||||
let (_, repos) = stewardships_of(mind)?;
|
||||
Ok(own_rooms(repos.iter().map(|repo| repo.0.as_str()), aliases))
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
/// case-blind. A direct message is hers by `address::is_for`, not by name.
|
||||
pub(crate) 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 {
|
||||
|
|
@ -514,12 +532,13 @@ pub fn own_rooms<'a>(repos: impl IntoIterator<Item = &'a str>, aliases: impl Int
|
|||
/// 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 {
|
||||
// Only a new message wakes her: an edit of a line, or a notice, never does, whoever sent it.
|
||||
if speaker == Speaker::Her || delivery.form != Form::Message {
|
||||
return None;
|
||||
}
|
||||
let addressed = is_for(who, delivery);
|
||||
if speaker.human() {
|
||||
let wakes = addressed || delivery.is_direct || facts.own_room || facts.in_exchange;
|
||||
let wakes = addressed || 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));
|
||||
|
|
@ -550,12 +569,12 @@ pub(crate) fn pending_facts(pending: &[&ChatDelivery], her: &str, minds: &[Strin
|
|||
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));
|
||||
lines.push((FactLine { sender: &context.sender, room, at_ms: context.at_unix_ms }, 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))),
|
||||
None => lines.push((FactLine { sender: &delivery.sender, room, at_ms: delivery.at_unix_ms }, Some(index))),
|
||||
}
|
||||
}
|
||||
lines.sort_by_key(|(line, _)| line.at_ms);
|
||||
|
|
|
|||
|
|
@ -733,3 +733,154 @@ fn a_member_line_in_a_room_named_for_her_repo_wakes_her_off_the_beat() {
|
|||
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");
|
||||
}
|
||||
|
||||
/// The wake rule over the facts the poll builds: the pending deliveries and their context, as Bob (`@bob:chat`) reads them.
|
||||
mod wake_rule {
|
||||
use super::*;
|
||||
use crate::chat_client::ContextLine;
|
||||
|
||||
const DAY: u64 = 86_400_000;
|
||||
const MINUTE: u64 = 60_000;
|
||||
|
||||
fn bob() -> Addressee {
|
||||
Addressee::new("@bob:chat", ["Bob"])
|
||||
}
|
||||
|
||||
fn minds() -> Vec<String> {
|
||||
vec!["@ann:chat".into(), "@bob:chat".into()]
|
||||
}
|
||||
|
||||
fn said(sender: &str, at: u64) -> ContextLine {
|
||||
ContextLine { sender: sender.into(), text: "x".into(), at_unix_ms: at }
|
||||
}
|
||||
|
||||
/// What the poll concludes for one delivery (its context is its own); `own` are her rooms.
|
||||
fn woken(line: &ChatDelivery, speaker: Speaker, own: &[&str]) -> Option<WakeCause> {
|
||||
let own: Vec<String> = own.iter().map(|room| (*room).to_owned()).collect();
|
||||
let facts = pending_facts(&[line], "@bob:chat", &minds(), &own);
|
||||
wakes(&bob(), line, speaker, facts[0])
|
||||
}
|
||||
|
||||
/// Four alternating Mind lines, the last of them `ago` before `at`, a minute apart.
|
||||
fn four_minds(at: u64, ago: u64) -> Vec<ContextLine> {
|
||||
(0..4).map(|index| said(if index % 2 == 0 { "@ann:chat" } else { "@bob:chat" }, at - ago - (4 - index) * MINUTE)).collect()
|
||||
}
|
||||
|
||||
fn tag(room: &str, at: u64, context: Vec<ContextLine>) -> ChatDelivery {
|
||||
ChatDelivery { room_alias: room.into(), at_unix_ms: at, context, ..delivery(1, "@ann:chat", "a word", &["@bob:chat"]) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_minds_tag_wakes_her_after_a_silence_in_a_room_no_human_speaks_in() {
|
||||
let now = 2 * DAY;
|
||||
let old = four_minds(now, now - 10 * MINUTE);
|
||||
assert_eq!(woken(&tag("#minds:chat", now, old.clone()), Speaker::Mind, &[]), Some(WakeCause::AddressedByMind), "four Mind lines two days ago are no run now");
|
||||
let reply = ChatDelivery { basis: Some(Basis::Reply), is_direct: true, room_alias: "!dm:chat".into(), context: old, at_unix_ms: now, ..delivery(2, "@ann:chat", "a word", &[]) };
|
||||
assert_eq!(woken(&reply, Speaker::Mind, &[]), Some(WakeCause::AddressedByMind), "a Mind-to-Mind DM reply the same");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_backstop_is_four_mind_lines_in_a_row_within_the_exchange_window() {
|
||||
let now = 3 * DAY;
|
||||
let three = four_minds(now, MINUTE)[1..].to_vec();
|
||||
assert_eq!(woken(&tag("#minds:chat", now, three), Speaker::Mind, &[]), Some(WakeCause::AddressedByMind), "three before it still wake");
|
||||
assert_eq!(woken(&tag("#minds:chat", now, four_minds(now, MINUTE)), Speaker::Mind, &[]), None, "four in a row wake no one");
|
||||
let after = |ago: u64| woken(&tag("#minds:chat", now, four_minds(now, ago)), Speaker::Mind, &[]);
|
||||
assert_eq!(after(29 * MINUTE), None, "the last of the four came exactly a window before: the run stands");
|
||||
assert_eq!(after(29 * MINUTE + 1), Some(WakeCause::AddressedByMind), "a moment longer and it is over");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_minds_reply_or_tag_wakes_her_with_no_matrix_mention() {
|
||||
for basis in [Basis::Reply, Basis::Tag] {
|
||||
let line = ChatDelivery { basis: Some(basis), ..delivery(1, "@ann:chat", "a word", &[]) };
|
||||
assert_eq!(woken(&line, Speaker::Mind, &[]), Some(WakeCause::AddressedByMind), "{basis:?}");
|
||||
}
|
||||
assert_eq!(woken(&delivery(1, "@ann:chat", "a word", &[]), Speaker::Mind, &[]), None, "no mention, no basis");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_new_message_wakes_her_on_every_path() {
|
||||
let own = ["#swarm:chat"];
|
||||
let exchange = ChatDelivery { room_alias: "#general:chat".into(), at_unix_ms: 10 * MINUTE, context: vec![said("@bob:chat", 5 * MINUTE)], ..delivery(3, "@member:chat", "fixed", &[]) };
|
||||
assert_eq!(woken(&exchange, Speaker::Member, &[]), Some(WakeCause::Human), "as a message, the line is in her exchange");
|
||||
assert_eq!(woken(&delivery(2, "@ci-bot:chat", "build green", &[]), Speaker::Member, &own), Some(WakeCause::Human), "and in her project room");
|
||||
for form in [Form::Edit, Form::Notice] {
|
||||
let formed = |line: ChatDelivery| ChatDelivery { form, ..line };
|
||||
assert_eq!(woken(&formed(ChatDelivery { is_direct: true, room_alias: "!dm:chat".into(), ..delivery(1, "@member:chat", "fixed", &[]) }), Speaker::Member, &[]), None, "{form:?} in a DM");
|
||||
assert_eq!(woken(&formed(delivery(2, "@ci-bot:chat", "build green", &[])), Speaker::Member, &own), None, "{form:?} in her project room");
|
||||
assert_eq!(woken(&formed(exchange.clone()), Speaker::Member, &[]), None, "{form:?} in her exchange");
|
||||
assert_eq!(woken(&formed(delivery(4, "@member:chat", "Bob?", &["@bob:chat"])), Speaker::Member, &[]), None, "{form:?} naming her");
|
||||
assert_eq!(woken(&formed(delivery(5, "@ann:chat", "a word", &["@bob:chat"])), Speaker::Mind, &[]), None, "{form:?} from a Mind carrying her mention");
|
||||
}
|
||||
let rig = quiet_rig();
|
||||
steward(&rig, BOB, "GameCult/Swarm", &[]);
|
||||
rig.say(BOB, ChatDelivery { form: Form::Notice, ..delivery(1, "@ci-bot:chat", "build green", &[]) });
|
||||
rig.say(BOB, ChatDelivery { form: Form::Edit, is_direct: true, room_alias: "!dm:chat".into(), ..delivery(2, "@member:chat", "fixed", &[]) });
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "off the beat, a notice and an edit start no turn");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_direct_message_wakes_her_as_addressed_by_the_one_check_in_is_for() {
|
||||
let dm = ChatDelivery { is_direct: true, room_alias: "!dm:chat".into(), ..delivery(1, "@member:chat", "psst", &[]) };
|
||||
assert_eq!(woken(&dm, Speaker::Member, &[]), Some(WakeCause::AddressedByHuman));
|
||||
}
|
||||
|
||||
/// Ruling persona-attention-and-initiative (2) wants an open hello answered by some Mind; the rule has no fact for it.
|
||||
#[test]
|
||||
fn a_member_naming_her_untagged_in_a_public_room_wakes_her_and_a_hello_to_everyone_wakes_no_one() {
|
||||
let general = |text: &str| ChatDelivery { room_alias: "#general:chat".into(), ..delivery(1, "@member:chat", text, &[]) };
|
||||
assert_eq!(woken(&general("Bob, can you look at this?"), Speaker::Member, &[]), Some(WakeCause::AddressedByHuman));
|
||||
assert_eq!(woken(&general("hello everyone!"), Speaker::Member, &[]), None);
|
||||
let rig = quiet_rig();
|
||||
for who in [ANN, BOB] {
|
||||
rig.say(who, ChatDelivery { room_alias: "#general:chat".into(), ..delivery(1, "@newcomer:chat", "hello everyone!", &[]) });
|
||||
}
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "no Mind is woken by it off the beat");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_exchange_holds_to_the_millisecond_of_the_window() {
|
||||
let window = 30 * MINUTE;
|
||||
let line = |sender, at_ms| FactLine { sender, room: "#general:chat", at_ms };
|
||||
let in_exchange = |gap: u64| line_facts(&[line("@bob:chat", 0), line("@member:chat", gap)], "@bob:chat", &minds(), &[], window)[1].in_exchange;
|
||||
assert!(in_exchange(window), "a line exactly one window after hers is in her exchange");
|
||||
assert!(!in_exchange(window + 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_mind_run_lapses_after_a_silence_longer_than_the_window_and_not_before() {
|
||||
let window = 30 * MINUTE;
|
||||
let line = |sender, at_ms| FactLine { sender, room: "#minds:chat", at_ms };
|
||||
let run = |gap: u64| {
|
||||
let lines = [line("@ann:chat", 0), line("@bob:chat", MINUTE), line("@ann:chat", 2 * MINUTE), line("@bob:chat", 3 * MINUTE), line("@ann:chat", 3 * MINUTE + gap)];
|
||||
line_facts(&lines, "@bob:chat", &minds(), &[], window)[4].mind_run
|
||||
};
|
||||
assert_eq!(run(window), 4, "a silence of exactly the window keeps the run");
|
||||
assert_eq!(run(window + 1), 0, "a longer one ends it, in a room no human speaks in");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn her_own_rooms_are_read_from_her_mind_as_the_poll_reads_them_and_an_unreadable_mind_is_an_error() {
|
||||
let rig = quiet_rig();
|
||||
steward(&rig, BOB, "GameCult/Swarm", &[]);
|
||||
// A stewardship of another instance held in her mind: the poll's reader counts it, so the drain's does.
|
||||
rig.minds[BOB].committed(vec![PipelineDocument::Stewardship(eureka_pipeline::PipelineStewardship {
|
||||
instance: Slug("ann".into()),
|
||||
repo: "GameCult/Annwork".into(),
|
||||
sequence: 1,
|
||||
assigned_on: eureka_pipeline::Date("2026-11-06".into()),
|
||||
note: "assigned".into(),
|
||||
names: vec![],
|
||||
})]);
|
||||
let aliases = ["#SWARM:chat", "#annwork:chat", "#general:chat", "!dm:chat"];
|
||||
let rooms = |down: bool| {
|
||||
let (calls, admits, reads, stewardship_down) = (Cell::new(0), Cell::new(0), Cell::new(0), Cell::new(down));
|
||||
own_rooms_among(&Counting { inner: &rig.minds[BOB], calls: &calls, admits: &admits, stewardship_reads: &reads, stewardship_down: &stewardship_down }, aliases)
|
||||
};
|
||||
assert_eq!(rooms(false).unwrap(), vec!["#SWARM:chat".to_owned(), "#annwork:chat".to_owned()]);
|
||||
assert!(rooms(true).is_err(), "unread is an error the caller reports, not no rooms");
|
||||
rig.say(BOB, ChatDelivery { room_alias: "#annwork:chat".into(), ..delivery(1, "@member:chat", "what a day", &[]) });
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("bob".into())] }, "the poll reads the same room as hers");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,25 +190,17 @@ 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> {
|
||||
read(&|selection| self.ask(selection), &self.client.instance().0, &self.forge, since, now)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -296,8 +288,10 @@ fn who(provenance: &PipelineProvenance, her: &str) -> Who {
|
|||
}
|
||||
}
|
||||
|
||||
/// The repos `her` stewards in force, each once.
|
||||
pub(crate) fn stewarded(ask: &Ask, her: &str) -> Result<Vec<String>> {
|
||||
/// 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 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
|
||||
|
|
@ -307,14 +301,6 @@ pub(crate) fn stewarded(ask: &Ask, her: &str) -> Result<Vec<String>> {
|
|||
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() {
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ struct 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 seeing: Vec<FactLine> = visible.iter().map(|at| FactLine { sender: &lines[*at].from, room: &lines[*at].room, at_ms: lines[*at].at_ms }).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, facts) in visible.into_iter().zip(facts) {
|
||||
|
|
|
|||
|
|
@ -178,8 +178,9 @@ fn t_w1_same_facts_both_paths() {
|
|||
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}");
|
||||
assert_eq!((facts.mind_run, facts.own_room, facts.in_exchange), (simulated[*at].mind_run, simulated[*at].own_room, simulated[*at].in_exchange), "line {at}");
|
||||
}
|
||||
assert_eq!(polled.iter().map(|facts| facts.mind_run).collect::<Vec<_>>(), vec![0, 1, 0, 0, 0], "her line, then a human's line that ends the run, then a Mind's tag after both");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -149,7 +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 own_rooms_among < 'a > (mind : & dyn MindPort , aliases : impl IntoIterator < Item = & 'a str >) -> Result < 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 >
|
||||
|
|
@ -261,7 +261,6 @@ 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