From 41fa789d6f8a699d0c35b1b1657614d61da980a0 Mon Sep 17 00:00:00 2001 From: Eureka Date: Tue, 17 Nov 2026 03:33:32 +0000 Subject: [PATCH] chat search: a multi-room listing no longer advises an --after that loses chunks A truncated listing printed --after . 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 --- crates/eureka-state/src/bin/huginn/main.rs | 3 ++- crates/eureka-state/src/bin/huginn/render.rs | 16 ++++++++++------ crates/eureka-state/tests/cli.rs | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/crates/eureka-state/src/bin/huginn/main.rs b/crates/eureka-state/src/bin/huginn/main.rs index 388b76f..8cc6380 100644 --- a/crates/eureka-state/src/bin/huginn/main.rs +++ b/crates/eureka-state/src/bin/huginn/main.rs @@ -536,6 +536,7 @@ fn chat_search( json: bool, ) -> Result { 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) } diff --git a/crates/eureka-state/src/bin/huginn/render.rs b/crates/eureka-state/src/bin/huginn/render.rs index 3fd7d3d..5da647e 100644 --- a/crates/eureka-state/src/bin/huginn/render.rs +++ b/crates/eureka-state/src/bin/huginn/render.rs @@ -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 = 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") } diff --git a/crates/eureka-state/tests/cli.rs b/crates/eureka-state/tests/cli.rs index ad9ea32..b513b5d 100644 --- a/crates/eureka-state/tests/cli.rs +++ b/crates/eureka-state/tests/cli.rs @@ -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"]] {