stream: the stimulus bound is one cut and the reads follow it; the newest thought is read newest-first

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Eureka Hands 2026-11-07 00:01:04 +00:00
commit 75d48b1fbd
2 changed files with 10 additions and 13 deletions

View file

@ -415,17 +415,12 @@ fn build_seed(mind: &dyn MindPort, persona: &PersonaRead, since: Option<DateTime
let fresh = news(mind, &instance, since, &responsibilities, now)?;
let has_news = !fresh.is_empty();
let stimulus = if has_news {
let mut lines = Vec::new();
let mut used = 0;
for (line, id) in fresh {
if used + line.len() + 1 > SECTION_MAX_BYTES {
break;
}
used += line.len() + 1;
lines.push(line);
id.into_iter().for_each(&mut cite);
}
format!("Since your last thought:\n{}", lines.join("\n"))
let body: Vec<&str> = fresh.iter().map(|(line, _)| line.as_str()).collect();
let kept = cap(&format!("Since your last thought:\n{}", body.join("\n")), SECTION_MAX_BYTES);
// Each line is one line (`quoted` escapes newlines), so the lines the bound kept are what the thought read.
let shown = kept.lines().count().saturating_sub(1);
fresh.into_iter().take(shown).filter_map(|(_, id)| id).for_each(&mut cite);
kept
} else if let Some((line, id)) = unbidden(mind, &instance, now, u64::try_from(now.timestamp()).unwrap_or(0))? {
cite(id);
line
@ -511,7 +506,7 @@ fn due(since: Option<DateTime<Utc>>, now: DateTime<Utc>, news: bool) -> bool {
fn newest_thought(mind: &dyn MindPort) -> Result<Option<DateTime<Utc>>> {
let newest = cultnet_rs::Selection { descending: true, limit: Some(1), ..mine(PipelineKind::Thought, mind.instance()) };
let found = headers(mind, &newest)?;
let PipelinePageItems::Headers(found) = mind.query(&newest)?.items else { bail!("the mind answered documents to a header selection") };
Ok(found.iter().filter_map(|header| DateTime::parse_from_rfc3339(&header.admission.admitted_at).ok()).map(|at| at.with_timezone(&Utc)).max())
}

View file

@ -5,7 +5,7 @@ use std::net::TcpListener;
use std::sync::{Arc, Mutex};
use anyhow::{Result, anyhow};
use chrono::{DateTime, Duration, Utc};
use chrono::{DateTime, Utc};
use cultnet_rs::Selection;
use eureka_pipeline::{MemorySort, PipelineDocument, PipelineKind, PipelineReply, PipelineThought, RunOperator, RunTurn, Slug};
use huginn_mind::{PipelineAdmissionOutcome, PipelineSelectionPage};
@ -575,6 +575,8 @@ fn a_flood_of_news_fills_the_stimulus_with_whole_lines_newest_first() {
assert!(seed.stimulus.len() <= SECTION_MAX_BYTES && seed.stimulus.len() > SECTION_MAX_BYTES - 250, "{}", seed.stimulus.len());
assert!(lines.iter().all(|line| line.starts_with("- You noted") && line.ends_with('"')), "a line was cut: {lines:?}");
assert!(lines.len() > 10 && lines.len() < 30, "{}", lines.len());
let cited = seed.reads.iter().filter(|read| read.kind == PipelineKind::Memory).count();
assert!(cited >= lines.len() && cited <= lines.len() + 12, "the thought cites what its stimulus showed: {cited} reads for {} lines", lines.len());
let newest = lines[0];
assert!(newest.contains("\"29 ") || newest.contains("\"59 "), "newest first: {newest}");
}