diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index f7ccc8a..d896375 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -51,9 +51,15 @@ pub use domain::{DomainFacts, DomainSource, HttpForge, MindDomain}; pub use narrate::{Answer, Failed, KitModel, Model, Spent, StepRequest, Stepped, ToolCall, connector_key}; pub use read::{LiveReads, ReadFailure, ReadFixture, ReadRequest, ReadSource}; pub use select::TurnKind; -pub(crate) use commit::{Applied, Heard, apply as apply_commit}; -pub(crate) use interpret::{heard_of, interpret_and_put, put_applied}; -pub(crate) use turn::{DAY_CAP_HOLD, Taken, decided, failed, failed_run, history, is_wake}; +pub(crate) use commit::Applied; +#[cfg(test)] +pub(crate) use commit::Heard; +pub(crate) use interpret::{heard_of, interpret_and_put}; +#[cfg(test)] +pub(crate) use interpret::put_applied; +pub(crate) use turn::{DAY_CAP_HOLD, decided, failed, failed_run, history, is_wake}; +#[cfg(test)] +pub(crate) use turn::Taken; pub(crate) use agent::say::{Mouth, settle_handed}; pub(crate) use wake::{Fault, Waked, wake}; pub use tuning::{TUNING_FILE, TUNING_ROOT}; diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index 4e48f63..9d10934 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -139,6 +139,7 @@ impl ReadSource for CastReads<'_> { } } +#[derive(Clone)] struct Member { entry: CastEntry, state: Value, @@ -547,8 +548,9 @@ fn run(harness: &Harness, plan: &SimFile, members: &[Member], repeat: usize) -> turns.push(turn); } } - let states: Vec = held.iter().map(|held| held.0.borrow().clone()).collect(); - let metrics = metrics(members, &states, &lines, &rounds_of, &causes, opening, &turns, plan.rounds); + // The cast as the run ended: each Mind with the state its Interpreter left her. + let ended: Vec = members.iter().zip(&held).map(|(member, held)| Member { state: held.0.borrow().clone(), ..member.clone() }).collect(); + let metrics = metrics(&ended, &lines, &rounds_of, &causes, opening, &turns, plan.rounds); let transcript: Vec = lines.iter().zip(&rounds_of).zip(&causes).map(|((line, round), cause)| json!({ "round": round, "room": line.room, "from": line.from, "name": line.name, "says": line.says, "mind": cast.contains(&line.from), "woke": cause })).collect(); Ok(json!({ "repeat": repeat + 1, "seed": seed, "transcript": transcript, "turns": turns, "metrics": metrics })) } @@ -606,11 +608,11 @@ fn reply_chains(lines: &[Line], causes: &[Option<&str>], opening: usize, cast: & json!(out) } -fn metrics(members: &[Member], states: &[Value], lines: &[Line], rounds_of: &[usize], causes: &[Option<&str>], opening: usize, turns: &[Value], rounds: usize) -> Value { +fn metrics(members: &[Member], lines: &[Line], rounds_of: &[usize], causes: &[Option<&str>], opening: usize, turns: &[Value], rounds: usize) -> Value { let cast: Vec<&str> = members.iter().map(|member| member.entry.id.as_str()).collect(); let outcome = |turn: &&Value, what: &str| turn["outcome"] == what; let mut per = BTreeMap::new(); - for (index, member) in members.iter().enumerate() { + for member in members { let mine: Vec<&Value> = turns.iter().filter(|turn| turn["id"] == member.entry.id.as_str()).collect(); let (spoke, silent, failed) = (mine.iter().filter(|turn| outcome(turn, "spoke")).count(), mine.iter().filter(|turn| outcome(turn, "silent")).count(), mine.iter().filter(|turn| outcome(turn, "failed")).count()); let mut addressed = BTreeMap::new(); @@ -640,7 +642,7 @@ fn metrics(members: &[Member], states: &[Value], lines: &[Line], rounds_of: &[us "intentions_ready": intentions("ready"), "identity_changes": interpreted.iter().map(|did| did["identity"].as_array().map_or(0, Vec::len)).sum::(), "refused": interpreted.iter().map(|did| did["refused"].as_array().map_or(0, Vec::len)).sum::(), - "short_term_at_end": states[index]["thoughtMemory"]["shortTerm"].as_array().map_or(0, Vec::len), + "short_term_at_end": member.state["thoughtMemory"]["shortTerm"].as_array().map_or(0, Vec::len), }); per.insert(member.entry.name.clone(), json!({ "turns": mine.len(), "messages": spoke, "failed": failed, "silence_rate": if answered == 0 { Value::Null } else { json!(silent as f64 / answered as f64) }, "addressed": addressed, "interpreter": interpreter })); } diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 31efbab..5805f60 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -2486,7 +2486,7 @@ fn a_line_in_her_own_room_is_said_to_her_only_when_it_is_not_for_another_mind() assert!(to_her, "the control: a human's line in her own room that names no one is to her"); let (to_her, heard, arrival) = said_to_her(meta("Give Libby a yes or no by tonight")); assert!(!to_her, "a line naming another Mind is not said to her"); - assert!(heard.starts_with("Meta, in #swarm:gamecult.org: \"Give Libby a yes or no"), "it is heard in the room: {heard}"); + assert!(heard.starts_with("Meta, the operator, in #swarm:gamecult.org: \"Give Libby a yes or no"), "it is heard in the room: {heard}"); assert!(!arrival.contains("Meta"), "and no one turned to her: {arrival}"); let (to_her, _, _) = said_to_her(ChatDelivery { mentions: vec!["@kiko:gamecult.org".into()], ..meta("a playable file, please") }); assert!(!to_her, "a tag of another Mind");