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"]] { diff --git a/crates/huginn-mind/src/wire.rs b/crates/huginn-mind/src/wire.rs index daba414..8ac65dc 100644 --- a/crates/huginn-mind/src/wire.rs +++ b/crates/huginn-mind/src/wire.rs @@ -286,8 +286,9 @@ pub const CHAT_ROOMS_MAX: usize = 16; /// [after, before]. `texts` (none to `SOURCE_TEXTS_MAX`) is the meaning match, /// several fused as in a source search; with none the search is a listing: /// chunks oldest first, at most `top_k`, `ChatHits.truncated` saying more -/// exist, and the caller narrows with `after_ms` = the last hit's -/// `ts_end_ms + 1`. +/// exist. Within one room the caller narrows with `after_ms` = the last hit's +/// `ts_end_ms + 1`; across rooms spans overlap and that loses chunks, so list +/// one room at a time. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] pub struct ChatQuery { pub texts: Vec, diff --git a/schemas/cultnet/huginn.mind_request.v1.schema.json b/schemas/cultnet/huginn.mind_request.v1.schema.json index 705a4e2..bca4ea2 100644 --- a/schemas/cultnet/huginn.mind_request.v1.schema.json +++ b/schemas/cultnet/huginn.mind_request.v1.schema.json @@ -329,7 +329,7 @@ ] }, "ChatQuery": { - "description": "A chat search. The selectors compose as AND. `rooms` are any-of: a value\nbeginning `!` is a room id, `#` a canonical alias. `after_ms` and\n`before_ms` (Unix milliseconds) keep the chunks whose span overlaps\n[after, before]. `texts` (none to `SOURCE_TEXTS_MAX`) is the meaning match,\nseveral fused as in a source search; with none the search is a listing:\nchunks oldest first, at most `top_k`, `ChatHits.truncated` saying more\nexist, and the caller narrows with `after_ms` = the last hit's\n`ts_end_ms + 1`.", + "description": "A chat search. The selectors compose as AND. `rooms` are any-of: a value\nbeginning `!` is a room id, `#` a canonical alias. `after_ms` and\n`before_ms` (Unix milliseconds) keep the chunks whose span overlaps\n[after, before]. `texts` (none to `SOURCE_TEXTS_MAX`) is the meaning match,\nseveral fused as in a source search; with none the search is a listing:\nchunks oldest first, at most `top_k`, `ChatHits.truncated` saying more\nexist. Within one room the caller narrows with `after_ms` = the last hit's\n`ts_end_ms + 1`; across rooms spans overlap and that loses chunks, so list\none room at a time.", "type": "object", "properties": { "after_ms": {