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 <noreply@anthropic.com>
This commit is contained in:
parent
d70d029f95
commit
b14a961c0e
3 changed files with 25 additions and 6 deletions
|
|
@ -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<String>,
|
||||
/// What refused results left to be told again.
|
||||
retell: Option<Retell>,
|
||||
}
|
||||
|
|
@ -993,6 +996,11 @@ impl<C: ControlSource, S: ControlSource> 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<C: ControlSource, S: ControlSource> 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<String> {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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<String> {
|
||||
Ok(flush_text(why))
|
||||
}
|
||||
|
||||
fn line(&mut self, line: &str) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ pub(crate) trait SessionInbox {
|
|||
fn poll(&mut self) -> Result<Polled>;
|
||||
/// The text of what waits, which is thereby told.
|
||||
fn tell(&mut self) -> Result<String>;
|
||||
fn flush_text(&self, why: Why) -> String;
|
||||
fn flush_text(&mut self, why: Why) -> Result<String>;
|
||||
/// 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<dyn Child>, 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 => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue