From b14a961c0ef0396ae90b10298fcb8cee9e80b6a3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 2 Nov 2026 10:15:53 +0100 Subject: [PATCH] flush-shown: a flush written alone records what it shows PersonaInbox.seen accumulates every person a write() showed; flush_text becomes fallible and, when no line awaits its echo, sets Written for the flush line from seen plus the open items and people read now. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/persona.rs | 21 +++++++++++++++++++-- crates/mind-body/src/self_run.rs | 4 ++-- crates/mind-body/src/self_run/session.rs | 6 ++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/mind-body/src/persona.rs b/crates/mind-body/src/persona.rs index cc26f3f..b8411b0 100644 --- a/crates/mind-body/src/persona.rs +++ b/crates/mind-body/src/persona.rs @@ -841,6 +841,7 @@ fn one_process( echoed: Vec::new(), shown: Shown::default(), echoed_refusals: 0, + seen: Vec::new(), retell: None, }; drive(organs.clock, child, &mut inbox, remaining_s, &mut std::io::stdout())?; @@ -965,6 +966,8 @@ struct PersonaInbox<'a, C: ControlSource, S: ControlSource> { /// The most refusals any line echoed since the last result had already had. echoed_refusals: u32, shown: Shown, + /// Every person a line this process wrote showed: the bound a flush written alone starts from. + seen: Vec, /// What refused results left to be told again. retell: Option, } @@ -993,6 +996,11 @@ impl PersonaInbox<'_, C, S> { if let Some(through) = batch.iter().map(|delivery| delivery.seq).max() { self.told_through = self.told_through.max(through); } + for person in &shown.people { + if !self.seen.contains(person) { + self.seen.push(person.clone()); + } + } self.written = Some(Written { batch, shown, refusals }); Ok(match prefix { Some(prefix) => format!("{prefix}\n\n{input}"), @@ -1045,13 +1053,22 @@ impl SessionInbox for PersonaInbox<'_, C, S> self.write(batch, None, 0) } - fn flush_text(&self, why: Why) -> String { + fn flush_text(&mut self, why: Why) -> Result { let cause = match why { Why::Ceiling => "its context is full", Why::Rotation => "the unit's time is nearly up", Why::Idle => "nothing is waiting and its cache would lapse", }; - format!("This session ends soon ({cause}). Put into `remember` whatever you must still know when it is gone and `settle` what is finished. Say nothing unless a message still needs an answer.") + let text = format!("This session ends soon ({cause}). Put into `remember` whatever you must still know when it is gone and `settle` what is finished. Say nothing unless a message still needs an answer."); + if self.written.is_none() { + // A flush alone is a line like any other: it shows the people the session showed and the items open now. + let organs = self.organs; + let goals = render_responsibilities(organs.mind, organs.mind.instance(), &BTreeMap::new())?; + let shown: Vec<&str> = self.seen.iter().map(String::as_str).chain(goals.people.iter().map(String::as_str)).collect(); + let people = people_she_may_name(self.config, &[], &shown); + self.written = Some(Written { batch: Vec::new(), shown: Shown { people, open: goals.open }, refusals: 0 }); + } + Ok(text) } fn echoed(&mut self) { diff --git a/crates/mind-body/src/self_run.rs b/crates/mind-body/src/self_run.rs index da6eb8d..d9a926b 100644 --- a/crates/mind-body/src/self_run.rs +++ b/crates/mind-body/src/self_run.rs @@ -597,8 +597,8 @@ impl SessionInbox for SelfInbox<'_> { Ok(text) } - fn flush_text(&self, why: Why) -> String { - flush_text(why) + fn flush_text(&mut self, why: Why) -> Result { + Ok(flush_text(why)) } fn line(&mut self, line: &str) { diff --git a/crates/mind-body/src/self_run/session.rs b/crates/mind-body/src/self_run/session.rs index ccbeb5d..5e46f42 100644 --- a/crates/mind-body/src/self_run/session.rs +++ b/crates/mind-body/src/self_run/session.rs @@ -35,7 +35,7 @@ pub(crate) trait SessionInbox { fn poll(&mut self) -> Result; /// The text of what waits, which is thereby told. fn tell(&mut self) -> Result; - fn flush_text(&self, why: Why) -> String; + fn flush_text(&mut self, why: Why) -> Result; /// Every line of the child's stream, before it is read. fn line(&mut self, _line: &str) {} /// The CLI took one of our lines into a request. @@ -116,7 +116,9 @@ pub(crate) fn drive(clock: &dyn Clock, mut child: Box, inbox: &mut dy if *tells { parts.push(inbox.tell()?); } - parts.extend(flush.map(|why| inbox.flush_text(why))); + if let Some(why) = *flush { + parts.push(inbox.flush_text(why)?); + } child.write_line(&user_line(&parts.join("\n\n"))); } Action::CloseStdin => {