chat search: a multi-room listing no longer advises an --after that loses chunks

A truncated listing printed --after <last.ts_end+1>. Listing is ordered by chunk
start and chunks of different rooms overlap in time, so the next page skipped any
chunk starting before that instant and ending before it. Inside one room chunks do
not overlap, so the advice stays; with several rooms (or none named) the CLI now
says to list one room at a time.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Eureka 2026-11-17 03:33:32 +00:00
commit 41fa789d6f
3 changed files with 32 additions and 7 deletions

View file

@ -536,6 +536,7 @@ fn chat_search(
json: bool,
) -> Result<u8, Trouble> {
let now = chrono::Utc::now();
let one_room = rooms.len() == 1;
let query = ChatQuery {
texts: texts.into_iter().map(Line).collect(),
rooms: rooms.into_iter().map(Short).collect(),
@ -548,7 +549,7 @@ fn chat_search(
if json {
say(serde_json::to_string_pretty(&found).map_err(|error| Trouble::Internal(error.to_string()))?);
} else {
say(render::chat_hits(&found));
say(render::chat_hits(&found, one_room));
}
Ok(0)
}

View file

@ -152,8 +152,11 @@ pub fn source_hits(found: &SourceHits) -> String {
/// when there are some), then one `time sender event_id body` line per message,
/// the body as the room held it with line breaks written `\n`: quoted data
/// under our header, never a message framed as if sent to the reader. A blank line between hits; a
/// truncated listing ends with the `--after` that continues it.
pub fn chat_hits(found: &ChatHits) -> String {
/// truncated listing of one room ends with the `--after` that continues it. A
/// listing of several rooms (`one_room` false) cannot be continued by an instant,
/// because chunks of different rooms overlap in time and a later start can hold an
/// earlier end; it says to page one room at a time.
pub fn chat_hits(found: &ChatHits, one_room: bool) -> String {
let mut out: Vec<String> = found
.hits
.iter()
@ -173,10 +176,11 @@ pub fn chat_hits(found: &ChatHits) -> String {
text
})
.collect();
if found.truncated
&& let Some(last) = found.hits.last()
{
out.push(format!("truncated: more follow, continue with --after {}\n", crate::chat::shown(last.ts_end_ms + 1)));
if found.truncated {
match found.hits.last() {
Some(last) if one_room => out.push(format!("truncated: more follow, continue with --after {}\n", crate::chat::shown(last.ts_end_ms + 1))),
_ => out.push("truncated: more follow; --after cannot continue a listing of several rooms, list one --room at a time\n".to_string()),
}
}
out.join("\n")
}

View file

@ -2998,6 +2998,26 @@ fn chat_search_prints_cited_messages_and_sends_its_selectors() {
let rooms: Vec<&str> = query.rooms.iter().map(|room| room.0.as_str()).collect();
assert_eq!((texts, rooms, query.after_ms, query.before_ms, query.top_k), (vec!["a", "b"], vec!["!x:y", "#z:y"], Some(1_700_000_000_000), Some(1_700_000_060_000), 3));
// A truncated listing is continued by `--after` only inside one room; across rooms the spans overlap and an instant loses chunks.
let hit = |end| huginn_mind::ChatHit {
room_id: "!r:y".into(),
room_alias: None,
first_event_id: "$a".into(),
last_event_id: "$b".into(),
ts_start_ms: 1_700_000_000_000,
ts_end_ms: end,
score: None,
messages: vec![],
};
let cut_short = HuginnMindResponse::Chat(huginn_mind::ChatHits { indexed_under: huginn_mind::SourceModel { name: "m".into(), digest: "d".into() }, truncated: true, hits: vec![hit(1_700_000_060_000)] });
let (listing, _) = replying("search_chat", cut_short);
let one = at(listing.addr, &["chat", "search", "--room", "!r:y"], None);
assert!(one.out.contains("continue with --after 2023-11-14T22:14:20.001Z"), "{}", one.out);
for rooms in [&["chat", "search"][..], &["chat", "search", "--room", "!r:y", "--room", "!s:y"]] {
let many = at(listing.addr, rooms, None);
assert!(many.out.contains("--after cannot continue a listing of several rooms") && !many.out.contains("continue with --after"), "{rooms:?}: {}", many.out);
}
assert_ne!(at(spy.addr, &["chat", "search", "--after", "yesterday"], None).code, 0);
assert!(seen.lock().unwrap().is_empty(), "a bad instant never left the CLI");
for bad in [&["chat", "search", "--room", "swarm"][..], &["chat", "search", "--top-k", "0"]] {