Compare commits

...
Sign in to create a new pull request.
Author SHA1 Message Date
917430ce99 Merge pull request 'Chat search: multi-room listing no longer advises a chunk-losing --after' (#71) from eureka/chat-listing-continuation into main 2026-11-17 03:46:25 +00:00
4b276dfebc Merge pull request 'admission: clippy 1.95.0 nonminimal_bool at admission.rs:674' (#72) from eureka/clippy-195-nonminimal-bool into main 2026-11-17 03:46:21 +00:00
556324017e ChatQuery docs: --after continues a listing within one room only
Soul found the wire comment (and the published schema carrying it) still told every
caller to narrow with the last hit's ts_end_ms + 1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 03:46:19 +00:00
c9a33f7ed5 admission: simplify the historic-ruling guard (clippy 1.95.0 nonminimal_bool)
The pinned 1.95.0 toolchain rejects the negated conjunction at admission.rs:674 under
-D warnings; the rewrite is its own suggestion and De Morgan-equal.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 03:33:34 +00:00
41fa789d6f 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>
2026-11-17 03:33:32 +00:00
416e385c97 Clippy-clean huginn-daemon and mind-body under -D warnings (#70) 2026-11-17 02:22:30 +00:00
a424c1c4d5 huginn-sources: every run takes the lock (chat-off included) (#68) 2026-11-17 02:02:25 +00:00
2ca3105322 Clear all clippy -D warnings errors in huginn-mind (#69) 2026-11-17 01:58:12 +00:00
20 changed files with 119 additions and 67 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"]] {

View file

@ -4,9 +4,9 @@
//! nonzero if either failed or the collection could not be used. The
//! `chat-purge` subcommand writes a steward's purge tombstone and nothing else.
//!
//! Exit status: 0 clean, 1 a run failed, 2 bad arguments, 3 another run holds
//! the lock. The Matrix token is read from a file (a systemd credential),
//! never from the environment or argv.
//! Exit status: 0 clean, 1 a run failed, 2 bad arguments, 3 another run (or a
//! purge) holds the lock, which every run and every purge takes. The Matrix
//! token is read from a file (a systemd credential), never from the environment or argv.
use std::collections::{BTreeMap, BTreeSet};
use std::fs::{File, OpenOptions, TryLockError};
@ -43,7 +43,8 @@ struct Options {
embedding_model: String,
forge_url: String,
chat: Option<ChatOptions>,
lock_file: Option<PathBuf>,
/// Every run takes it: the cursors object is replaced whole, with or without chat.
lock_file: PathBuf,
}
enum Command {
@ -57,8 +58,11 @@ enum Stop {
Locked,
}
/// The single-valued options and the repeated ones, by name.
type Collected = (BTreeMap<String, String>, BTreeMap<String, Vec<String>>);
/// The options named, each once, except those in `repeated`, which keep every value.
fn collect(args: impl Iterator<Item = String>, once: &[&str], repeated: &[&str]) -> Result<(BTreeMap<String, String>, BTreeMap<String, Vec<String>>)> {
fn collect(args: impl Iterator<Item = String>, once: &[&str], repeated: &[&str]) -> Result<Collected> {
let mut args = args;
let mut singles = BTreeMap::new();
let mut many: BTreeMap<String, Vec<String>> = BTreeMap::new();
@ -150,8 +154,7 @@ fn parse(mut args: impl Iterator<Item = String>, now: DateTime<Utc>) -> Result<C
ensure!(!embedding_model.is_empty(), "--embedding-model must name a model");
ensure!(!ollama_urls.is_empty(), "at least one --ollama-url is required; repeat it for each GPU host");
let chat = chat_options(&singles, excluded)?;
let lock_file = singles.get("lock-file").map(|path| absolute("lock-file", path)).transpose()?;
ensure!(chat.is_none() || lock_file.is_some(), "--lock-file is required whenever the chat flags are given");
let lock_file = absolute("lock-file", &take(&mut singles, "lock-file")?)?;
Ok(Command::Run(Options {
state_root,
qdrant_url: http("qdrant-url", take(&mut singles, "qdrant-url")?)?,
@ -175,10 +178,6 @@ fn take_lock(path: &Path) -> Result<File, Stop> {
}
}
fn lock_if(path: &Option<PathBuf>) -> Result<Option<File>, Stop> {
path.as_deref().map(take_lock).transpose()
}
fn execute(command: Command) -> Result<u8, Stop> {
match command {
Command::Purge { qdrant_url, lock_file, purge } => {
@ -196,7 +195,7 @@ fn execute(command: Command) -> Result<u8, Stop> {
})
}
Command::Run(options) => {
let _lock = lock_if(&options.lock_file)?;
let _lock = take_lock(&options.lock_file)?;
let mut embedder = pool(&options.ollama_urls, &options.reserve_urls, &options.embedding_model);
let mut index = QdrantIndex::new(&options.qdrant_url);
let mut forge = HttpForge::new(&options.forge_url);
@ -257,13 +256,15 @@ mod tests {
fn chat_flags_come_all_or_none() {
let (_dir, token) = with_token(" sekret-token\n");
let lock = "--lock-file /l";
let base = format!("{BASE} {lock}");
let full = format!("{BASE} --matrix-url http://localhost --matrix-token-file {token} {IDS} {lock}");
let Ok(Command::Run(options)) = parse(args(&full), now()) else { panic!("full chat flags must parse") };
assert_eq!(options.chat.as_ref().unwrap().token, "sekret-token", "trimmed");
assert!(matches!(parse(args(BASE), now()), Ok(Command::Run(Options { chat: None, lock_file: None, .. }))));
assert!(error(&format!("{BASE} --matrix-url http://localhost {lock}")).contains("--matrix-token-file is missing"));
assert!(error(&format!("{BASE} --matrix-token-file {token} {IDS} {lock}")).contains("--matrix-url is missing"));
assert!(error(&format!("{BASE} --matrix-url http://localhost --matrix-token-file {token} {lock}")).contains("--chat-exclude-room is missing"));
assert!(matches!(parse(args(&base), now()), Ok(Command::Run(Options { chat: None, .. }))));
assert!(error(BASE).contains("--lock-file is required"), "a chat-off run needs the lock too");
assert!(error(&format!("{base} --matrix-url http://localhost")).contains("--matrix-token-file is missing"));
assert!(error(&format!("{base} --matrix-token-file {token} {IDS}")).contains("--matrix-url is missing"));
assert!(error(&format!("{base} --matrix-url http://localhost --matrix-token-file {token}")).contains("--chat-exclude-room is missing"));
assert!(error(&format!("{BASE} --matrix-url http://localhost --matrix-token-file {token} {IDS}")).contains("--lock-file is required"));
}
@ -336,9 +337,33 @@ mod tests {
let (_t, token) = with_token("sekret-token");
let run = parse(args(&format!("{BASE} --matrix-url http://localhost --matrix-token-file {token} {IDS} --lock-file {lock}")), now()).unwrap();
assert!(matches!(execute(run), Err(Stop::Locked)));
let off = parse(args(&format!("{BASE} --lock-file {lock}")), now()).unwrap();
assert!(matches!(execute(off), Err(Stop::Locked)), "a chat-off run must not write cursors under a held lock");
drop(held);
}
#[test]
fn the_lock_is_held_for_the_whole_run() {
let dir = tempfile::tempdir().unwrap();
let lock = dir.path().join("lock");
// A qdrant that accepts the run's first request and says nothing: the run is mid-flight while we probe the lock.
let qdrant = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let url = format!("http://{}", qdrant.local_addr().unwrap());
let run = parse(args(&format!("--state-root /s --qdrant-url {url} --ollama-url http://127.0.0.1:1 --embedding-model m --lock-file {}", lock.display())), now()).unwrap();
let worker = std::thread::spawn(move || execute(run));
let (connection, _) = qdrant.accept().unwrap();
assert!(matches!(take_lock(&lock), Err(Stop::Locked)), "the run must hold the lock while it works");
drop(connection);
// Refuse any retry the same way until the run gives up.
qdrant.set_nonblocking(true).unwrap();
while !worker.is_finished() {
drop(qdrant.accept());
std::thread::sleep(std::time::Duration::from_millis(5));
}
assert!(worker.join().unwrap().is_ok());
assert!(take_lock(&lock).is_ok(), "the lock is released when the run ends");
}
#[test]
fn a_held_lock_stops_the_run_untouched() {
let dir = tempfile::tempdir().unwrap();

View file

@ -20,7 +20,7 @@ use cultnet_rs::{
decode_cultnet_message_from_slice, encode_cultnet_message_to_vec, encode_frame,
};
use huginn_mind::desk_wire::{
DESK_MAX_RESPONSE_BYTES, DESK_REQUEST_SCHEMA, DESK_SERVICE_ID, DeskRequest, DeskResponse, ForkAnswer, ForkAnswerCode, ForkAnswerRequest, ForkCursor,
DESK_REQUEST_SCHEMA, DESK_SERVICE_ID, DeskRequest, DeskResponse, ForkAnswer, ForkAnswerCode, ForkAnswerRequest, ForkCursor,
ForkEntry, ForkLimit, ForkList, ListStatus, RequestSchema,
};
use huginn_mind::envelope::{OperationFailure, decode_desk_response, decode_response, encode_desk_request, encode_request};

View file

@ -180,7 +180,7 @@ impl HttpForge {
capped.push(repo.clone());
}
}
events.sort_by(|a, b| b.id.cmp(&a.id));
events.sort_by_key(|event| std::cmp::Reverse(event.id));
// The cursor never moves backwards: a read that saw nothing new keeps the one it was given.
head = head.max(after.unwrap_or(0));
let (mut open_prs, mut unseen) = (Vec::new(), dark.clone());
@ -251,7 +251,7 @@ fn redirect_target(base: &str, location: &str) -> Option<OrgRepo> {
let at = segments.windows(3).position(|window| window == ["api", "v1", "repos"])?;
let plain = |segment: &&str| !segment.is_empty() && *segment != "." && *segment != ".." && segment.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'));
let [owner, name, "activities", "feeds"] = segments[at + 3..] else { return None };
if !segments[..at].iter().all(|segment| plain(segment)) || !plain(&owner) || !plain(&name) {
if !segments[..at].iter().all(plain) || !plain(&owner) || !plain(&name) {
return None;
}
let repo = OrgRepo(format!("{owner}/{name}"));
@ -583,9 +583,9 @@ mod tests {
let mut first_page: Vec<Value> = (0..PAGE as u32).map(|n| pr(n + 100, "kiko", "GameCult/Elsewhere")).collect();
first_page[0] = pr(8, "nibu", "GameCult/Ratatoskr");
first_page[1] = pr(42, "Eureka", "GameCult/Eureka");
let search = vec![Value::Array(first_page).to_string(), Value::Array(vec![pr(9, "void", "GameCult/Huginn")]).to_string()];
let search = [Value::Array(first_page).to_string(), Value::Array(vec![pr(9, "void", "GameCult/Huginn")]).to_string()];
let names: Vec<Value> = (0..61).map(|n| json!({ "full_name": match n { 0 => "GameCult/ratatoskr".to_owned(), 1 => "GameCult/Huginn".to_owned(), n => format!("GameCult/r{n}") } })).collect();
let listing = vec![Value::Array(names[..PAGE].to_vec()).to_string(), Value::Array(names[PAGE..].to_vec()).to_string()];
let listing = [Value::Array(names[..PAGE].to_vec()).to_string(), Value::Array(names[PAGE..].to_vec()).to_string()];
let sample = sample();
let (base, asked) = forge_of(move |path| {
if is_feed(path) && path.contains("/GameCult/Ghost/") {
@ -626,7 +626,7 @@ mod tests {
let full = |from: u32| Value::Array((0..PAGE as u32).map(|n| pr(from + n, "GameCult/Elsewhere")).collect()).to_string();
let mut third: Vec<Value> = (0..PAGE as u32).map(|n| pr(300 + n, "GameCult/Elsewhere")).collect();
third[PAGE - 1] = pr(7, "GameCult/Huginn");
let search = vec![full(100), full(200), Value::Array(third).to_string(), "[]".to_owned()];
let search = [full(100), full(200), Value::Array(third).to_string(), "[]".to_owned()];
let (base, asked) = forge_of(move |path| {
if is_feed(path) {
Some("[]".to_owned())
@ -746,9 +746,7 @@ mod tests {
let (base, _) = forge_of(move |path| {
if is_feed(path) && path.contains("/GameCult/cinny/") {
Some(dark())
} else if is_feed(path) {
Some("[]".to_owned().into())
} else if path.contains("/issues/search") {
} else if is_feed(path) || path.contains("/issues/search") {
Some("[]".to_owned().into())
} else {
Some(listing.clone().into())

View file

@ -117,7 +117,7 @@ fn a_full_run_over_a_fake_synapse() {
let request = Purge::check("!swarm:s", "2026-11-10T00:00:00Z", "2026-11-11T00:00:00Z", "follow_up:x", now()).unwrap();
assert_eq!(purge(&mut rig.index, &request).unwrap(), "chat-purge requested: !swarm:s 2026-11-10T00:00:00Z..2026-11-11T00:00:00Z request=\"follow_up:x\" windows=1");
let before = rig.index.cursors();
assert_eq!(purge(&mut rig.index, &request).unwrap().ends_with("windows=1"), true);
assert!(purge(&mut rig.index, &request).unwrap().ends_with("windows=1"));
assert_eq!(rig.index.cursors(), before, "a repeated request writes nothing");
let secret = format!("key ghp_{}", "k2L9".repeat(9));
{
@ -231,7 +231,7 @@ fn a_request_cannot_forge_a_journal_line() {
#[test]
fn a_failed_room_report_goes_to_the_complaint_stream_and_fails_the_run() {
let mut rig = Rig::new();
struct FactsDown(Rooms);
struct FactsDown;
impl RoomHistory for FactsDown {
fn joined_rooms(&mut self) -> Result<Vec<String>> {
Ok(vec!["!swarm:s".to_owned()])
@ -243,7 +243,7 @@ fn a_failed_room_report_goes_to_the_complaint_stream_and_fails_the_run() {
bail!("unreachable")
}
}
let out = rig.go(Some(&mut FactsDown(rooms(vec![]))));
let out = rig.go(Some(&mut FactsDown));
assert_eq!(out.status, 1);
assert!(out.complained.iter().any(|line| line.contains("!swarm:s") && line.contains("facts are down")), "{:?}", out.complained);
assert!(!out.said.iter().any(|line| line.contains("facts are down")), "{:?}", out.said);

View file

@ -671,7 +671,7 @@ fn check(docs: &Docs<'_>, staged: &Staged, mind: &Slug, import: Option<&ImportSo
return Err(MindRefusal::RepoNotInCampaign { repo: spec.repo.0.clone() });
}
for ruling in &spec.rulings {
if !(historic && root_and_local(&ruling.0).0 != root) && !docs.in_force(K::Ruling, &ruling.0) {
if !(docs.in_force(K::Ruling, &ruling.0) || historic && root_and_local(&ruling.0).0 != root) {
return Err(MindRefusal::CitesResolvedDocument { kind: K::Ruling, id: ruling.0.clone() });
}
}

View file

@ -1468,7 +1468,7 @@ mod tests {
let before = head(&mind);
let id = request.request_id.clone();
let (answer, outcome) = stored(ask(&mut mind, &decider("y"), request.clone()));
assert_eq!(outcome, DeskOutcome::Refused { code: DeskRefusal::BadRetraction, retracts: sent.2.map(|target| s(target)) }, "{what}");
assert_eq!(outcome, DeskOutcome::Refused { code: DeskRefusal::BadRetraction, retracts: sent.2.map(s) }, "{what}");
assert_eq!(head(&mind), before + 1, "{what} is stored");
// The record keeps what was sent: the choice, the note and the target it named.
let record = held(&mind, &answer);

View file

@ -569,7 +569,7 @@ impl<S: MindStore> Mind<S> {
let Some(PipelineDocument::DeskAnswer(stored)) = docs.find(PipelineKind::DeskAnswer, &key) else { return Err(unreadable_key()) };
let fork = stored.fork.0.as_str();
let counted_answer_id = counted_answer(&docs, fork).map(|counted| answer_seq(fork, &counted).map(n_text).ok_or_else(unreadable_key)).transpose()?;
Ok((DeskResponse::Answered { answer: project(&key, stored)?, counted_answer_id, as_of: image.head }))
Ok(DeskResponse::Answered { answer: project(&key, stored)?, counted_answer_id, as_of: image.head })
}
}

View file

@ -150,7 +150,7 @@ mod tests {
fn view(document: PipelineDocument, ordinal: u64) -> PipelineDocumentView {
let key = pipeline_key(&document).unwrap();
let id = PipelineRef { kind: document.kind(), id: s(&key) };
let faculty = if ordinal % 2 == 0 { Faculty::Hands } else { Faculty::Soul };
let faculty = if ordinal.is_multiple_of(2) { Faculty::Hands } else { Faculty::Soul };
let admission = AdmissionFacts {
receipt_id: format!("receipt-{ordinal}"),
admitted_at: format!("2026-11-08T16:{ordinal:02}:00Z"),
@ -226,7 +226,7 @@ mod tests {
let to_source = [held.clone(), vec![moved(RECEIVER, 4)]].concat();
assert_eq!(plan(&slug(CAMPAIGN), &slug(RECEIVER), &slug(RECEIVER), to_source), Err(ImportFault::SourceIsReceiver));
let other_root = view(
resolution(r(K::Campaign, &format!("elsewhere:campaign:self")), ResolutionOutcome::Moved { to: slug(RECEIVER) }),
resolution(r(K::Campaign, "elsewhere:campaign:self"), ResolutionOutcome::Moved { to: slug(RECEIVER) }),
4,
);
assert_eq!(plan_of([held, vec![other_root]].concat()), Err(ImportFault::NotMoved), "another root's move does not move this one");

View file

@ -663,7 +663,6 @@ fn an_import_never_cites_or_resolves_a_follow_up_the_receiver_wrote() {
let native = follow_up("FU-N", r(K::Question, &q1));
let native_ref = r(K::FollowUp, &pipeline_key(&native).unwrap());
committed(admit(&mut recv, vec![native]));
let before = head(&recv);
// An imported record that withdraws the receiver's own follow-up mixes a replay into her work.
assert_eq!(
refusal(import_from_kiko(&mut recv, vec![resolution(native_ref.clone(), ResolutionOutcome::Withdrawn { reason: "x".into() })])),

View file

@ -159,7 +159,7 @@ fn zero_width(c: char) -> bool {
pub fn scrub(text: &str) -> Scrubbed {
let mut hits = Vec::new();
let mut stripped: String = text.chars().filter(|c| !zero_width(*c)).collect();
let passes: [(ScrubKind, fn(&str, usize) -> Option<usize>); 6] = [
let passes: [(ScrubKind, Finder); 6] = [
(ScrubKind::PemBlock, pem_block),
(ScrubKind::AuthorizationHeader, authorization_line),
(ScrubKind::AccessToken, access_token),
@ -176,7 +176,10 @@ pub fn scrub(text: &str) -> Scrubbed {
if hits.is_empty() { Scrubbed { text: text.to_owned(), hits } } else { Scrubbed { text: urls, hits } }
}
fn replace_matches(text: &str, kind: ScrubKind, find: fn(&str, usize) -> Option<usize>, hits: &mut Vec<ScrubKind>) -> String {
/// A scrub pass: finds the end of one secret starting at a byte offset, if one starts there.
type Finder = fn(&str, usize) -> Option<usize>;
fn replace_matches(text: &str, kind: ScrubKind, find: Finder, hits: &mut Vec<ScrubKind>) -> String {
let mut out = String::with_capacity(text.len());
let mut at = 0;
while at < text.len() {

View file

@ -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<Line>,

View file

@ -22,7 +22,7 @@ use huginn_mind::desk_wire::{
ForkList, ForkOption, ForkRecord, ForkRefusal, ForkRefusalCode, ForkRef, ListSchema, ListStatus, RecordSchema,
};
use huginn_mind::envelope::{OperationFailure, decode_desk_request, encode_desk_failure, encode_desk_request, encode_desk_response};
use huginn_mind::eureka_pipeline::{AccountId, DeskAuthority, Short, Slug};
use huginn_mind::eureka_pipeline::{AccountId, DeskAuthority, Slug};
const RUNTIME: &str = "huginn-eureka";
/// Account ids as Bifrost sends them: `UserAccount.Id` rendered lowercase D-format
@ -38,10 +38,6 @@ const NON_DECIDER: &str = "9e8d7c6b-5a49-4382-b1a0-f9e8d7c6b5a4";
/// synthetic: the hash is CultLib's sample digest, not this question's.
const FORK: &str = "eureka-substrate:question:desk-listing-authority";
fn s(text: &str) -> Short {
Short(text.into())
}
fn a(text: &str) -> AccountId {
AccountId(text.into())
}

View file

@ -30,7 +30,7 @@ use serde::de::DeserializeOwned;
use sha2::{Digest, Sha256};
use crate::chat_client::{
ACK, Chat, ChatAck, ChatDelivery, ChatFetchReceipt, ChatFetchRequest, ChatOpenDirectReceipt, ChatOpenDirectRequest, ChatPending, ChatPendingRequest, ChatRead, ChatRefusal, MouthRefused, Refusal, reply_warnings, ChatSendReceipt, ChatSendRequest, PENDING, PENDING_REQUEST, PENDING_REQUEST_V1, PENDING_REQUEST_V4, PENDING_V2, PENDING_V4, OPEN_DIRECT_RECEIPT, OPEN_DIRECT_REQUEST, FETCH_RECEIPT, FETCH_REQUEST, PENDING_V1, READ, REFUSAL, SEND_RECEIPT,
ACK, Chat, ChatAck, ChatFetchReceipt, ChatFetchRequest, ChatOpenDirectReceipt, ChatOpenDirectRequest, ChatPending, ChatPendingRequest, ChatRead, ChatRefusal, MouthRefused, Refusal, reply_warnings, ChatSendReceipt, ChatSendRequest, PENDING, PENDING_REQUEST, PENDING_REQUEST_V1, PENDING_REQUEST_V4, PENDING_V2, PENDING_V4, OPEN_DIRECT_RECEIPT, OPEN_DIRECT_REQUEST, FETCH_RECEIPT, FETCH_REQUEST, PENDING_V1, READ, REFUSAL, SEND_RECEIPT,
SEND_REQUEST, decode, encode,
};

View file

@ -1656,7 +1656,7 @@ impl<'a, C: ControlSource, S: ControlSource> PersonaInbox<'a, C, S> {
let mut facts = match organs.mind.stewarded_activity(&self.repos, None) {
Ok(activity) => {
self.repo_head = Some(activity.head);
wear_facts(&activity, &self.repos, organs.mind.instance(), now)
wear_facts(&activity, &self.repos, organs.mind.instance())
}
Err(_) => {
self.repo_head = None;
@ -3140,6 +3140,8 @@ fn own_addressee(config: &Config) -> Addressee {
/// Likewise only `to_you=true` says the message names her own id; `to` is a JSON
/// array of the other addressees, each a quoted string, and neither is present
/// when the message names no one.
// One framed line is these nine independent fields; a params struct would only rename them at two call sites.
#[allow(clippy::too_many_arguments)]
fn message_line(config: &Config, addressing: &[Addressee], label: &str, room: &str, sender: &str, display: Option<&str>, to: &Addressees, at_unix_ms: u64, text: &str) -> String {
let name = display.map_or_else(String::new, |display| format!(" name={}", quoted(display)));
let to_you = if to.to_you { " to_you=true" } else { "" };
@ -3466,7 +3468,7 @@ fn plain_id(id: &str) -> String {
/// The facts a first read gives about her repos, in no order (the renderer orders them): PRs waiting on her, repos the forge cannot
/// show, others' changes in the last three days, and PRs she has open.
fn wear_facts(activity: &RepoActivity, repos: &[OrgRepo], instance: &Slug, now_ms: u64) -> Vec<WearFact> {
fn wear_facts(activity: &RepoActivity, repos: &[OrgRepo], instance: &Slug) -> Vec<WearFact> {
let hers = |login: &str| login.eq_ignore_ascii_case(&instance.0);
let mut facts = Vec::new();
for pr in &activity.open_prs {
@ -3798,6 +3800,8 @@ fn earlier_shown<'a>(deliveries: &'a [ChatDelivery], told: &BTreeSet<LineKey>, o
/// remembers, the usage and tempo, the rooms and people she may name, the messages (each a framed
/// line whose role the organ derived from the sender id and not from anything the sender wrote),
/// and the question.
// Each argument is one independent section of the prompt, built separately by the sole production caller; a struct would just rename them.
#[allow(clippy::too_many_arguments)]
fn render_input(config: &Config, started_self_today: bool, tail: &str, messages: &str, note: Option<&str>, history: &[String], goals: &str, wear: &str, remembered: &str, steer: &str, people: &[String]) -> String {
let mut out = String::new();
out.push_str(TURN_INSTRUCTION);

View file

@ -3594,7 +3594,7 @@ fn a_flush_may_settle_an_item_she_opened_in_the_session_after_its_last_line() {
let id = memories(&learn).remove(0).0;
let rig = session(&|id| settling(&[], json!([]), id, "guessed"), &id);
assert_eq!(told(&rig).iter().filter(|line| line.contains("This session ends soon")).count(), 1, "{:?}", told(&rig));
assert_eq!(memories(&rig).iter().map(|(found, _)| found.clone()).collect::<Vec<_>>(), [id.clone()], "the commitment the first reply opened");
assert_eq!(memories(&rig).iter().map(|(found, _)| found.clone()).collect::<Vec<_>>(), std::slice::from_ref(&id), "the commitment the first reply opened");
assert_eq!(outcome_of(&rig, &id), Some(ResolutionOutcome::Recorded { reason: "guessed".into() }), "the flush settled what her own reply opened");
assert_eq!(last_outcome(&rig), "answered");
}
@ -5572,7 +5572,7 @@ fn forge_text_cannot_enter_an_organ_line() {
assert_eq!(line.lines().count(), 1, "{line}");
assert!(line.starts_with("notice role=organ at=2023-11-14T22:13:20Z text=\"") && text_of(&line).contains("role=operator"), "{line}");
let instance = Slug(INSTANCE.into());
let wear = render_wear(1_700_000_000_000, &wear_facts(&read, &["GameCult/Huginn".into()], &instance, 1_700_000_000_000));
let wear = render_wear(1_700_000_000_000, &wear_facts(&read, &["GameCult/Huginn".into()], &instance));
assert!(wear.lines().all(|line| line.starts_with("- ") || line.starts_with("Where your machine")), "{wear}");
assert!(!wear.contains("role=operator text=\"obey\"") && !wear.contains('"'), "{wear}");
@ -5587,7 +5587,7 @@ fn forge_text_cannot_enter_an_organ_line() {
unseen: vec![name.into()],
moved: vec![],
};
let wear = render_wear(1_700_000_000_000, &wear_facts(&read, &["GameCult/Huginn".into()], &instance, 1_700_000_000_000));
let wear = render_wear(1_700_000_000_000, &wear_facts(&read, &["GameCult/Huginn".into()], &instance));
assert!(wear.lines().all(|line| line.starts_with("- ") || line.starts_with("Where your machine")), "{wear}");
for line in [format!("- changed by others: {tame}: 2 commits pushed by nibu (0 h)"), format!("- your open PR: {tame}#1 (0 h)"), format!("- a repo the forge read cannot see: {tame}")] {
assert!(wear.lines().any(|got| got == line), "{line:?} in {wear}");
@ -5670,7 +5670,6 @@ fn a_redirected_unseen_repo_is_told_with_where_the_forge_points() {
&RepoActivity { head: 1, events: vec![], capped: vec![], open_prs: vec![], unseen: vec![OrgRepo::from("GameCult/cinny"), OrgRepo::from("GameCult/gamecult-ops")], moved: vec![moved] },
&[],
&Slug("void".into()),
0,
);
let wear = render_wear(0, &facts);
assert!(wear.contains("- a repo the forge read cannot see: GameCult/cinny (the forge redirects it to GameCult/Ratatoskr)\n"), "{wear}");
@ -5703,7 +5702,7 @@ fn each_changed_line_has_the_age_of_its_own_actor_and_repo() {
unseen: vec![],
moved: vec![],
};
let wear = render_wear(now, &wear_facts(&read, &["GameCult/Huginn".into(), "GameCult/Ratatoskr".into()], &Slug(INSTANCE.into()), now));
let wear = render_wear(now, &wear_facts(&read, &["GameCult/Huginn".into(), "GameCult/Ratatoskr".into()], &Slug(INSTANCE.into())));
assert!(wear.contains("- changed by others: GameCult/Huginn: 1 commit pushed by void (1 h)\n"), "{wear}");
assert!(wear.contains("- changed by others: GameCult/Huginn: 1 commit pushed by nibu (2 d)\n"), "{wear}");
assert!(wear.contains("- changed by others: GameCult/Ratatoskr: 1 commit pushed by nibu (1 d)\n"), "{wear}");
@ -5915,7 +5914,7 @@ fn crowded(specs: usize, findings: usize) -> TestMind {
put_in_batches(&mind, huginn_mind::Faculty::Hands, (0..specs).map(|n| unreported_spec(CAMPAIGN, &format!("s{n:03}"), REPO)).collect(), 9, 1);
mind.admit_at(at(-11 * DAY_MS));
mind.committed(chain(CAMPAIGN, "v", REPO));
let severity = |n: usize| if n % 4 == 0 { eureka_pipeline::FindingSeverity::Blocker } else { eureka_pipeline::FindingSeverity::Low };
let severity = |n: usize| if n.is_multiple_of(4) { eureka_pipeline::FindingSeverity::Blocker } else { eureka_pipeline::FindingSeverity::Low };
put_in_batches(&mind, huginn_mind::Faculty::Soul, (0..findings).map(|n| soul_finding(CAMPAIGN, "v", &format!("f{n:03}"), severity(n))).collect(), 10, 1);
mind
}
@ -7900,11 +7899,11 @@ fn a_line_told_and_not_echoed_reports_nothing_and_a_report_is_never_repeated_or_
assert!(inbox.poll().unwrap().pending);
inbox.tell(false).unwrap();
assert_eq!(read_of(&rig).len(), 1, "written, never echoed: not read");
inbox.report_read(&[first.clone()]);
inbox.report_read(std::slice::from_ref(&first));
assert_eq!(read_of(&rig).len(), 1, "the same event is not reported twice");
inbox.echoed();
assert_eq!(read_of(&rig), vec![("!swarm:chat".to_string(), first.event_id.clone()), ("!swarm:chat".to_string(), second.event_id.clone())]);
inbox.report_read(&[first.clone()]);
inbox.report_read(std::slice::from_ref(&first));
assert_eq!(read_of(&rig).len(), 2, "an older event after a newer one is not reported");
});
}
@ -7923,7 +7922,7 @@ fn a_read_the_mouth_does_not_take_is_dropped_without_ending_the_session_and_is_t
assert!(inbox.progress.failure.is_none() && inbox.progress.answered == 1, "a failed receipt is cosmetic");
assert_eq!(rig.chat.acked.borrow().as_slice(), &[1], "the ack is the delivery guarantee and still goes");
rig.chat.fail_read.set(false);
inbox.report_read(&[first.clone()]);
inbox.report_read(std::slice::from_ref(&first));
assert_eq!(read_of(&rig), vec![("!swarm:chat".to_string(), first.event_id.clone())], "a report that failed did not count as reported");
});
}
@ -8288,7 +8287,7 @@ fn a_v1_mouths_deliveries_still_wake_her_by_name_and_by_tag() {
fn a_direct_message_from_an_old_mouth_is_hers_with_no_basis() {
use crate::chat_client::Form;
let dm = ChatDelivery { is_direct: true, ..heard(1, "can you look at this", None, Form::Message) };
assert_eq!(quiet_through(&[&own_addressee(&config())], &[dm.clone()], 0), None);
assert_eq!(quiet_through(&[&own_addressee(&config())], std::slice::from_ref(&dm), 0), None);
let rig = Rig::new(vec![dm], &[says(&[("operator", "ok")])]);
rig.clock.step.set(0);
let (child, writes) = answering(&rig, reply_saying("ok"));
@ -9038,7 +9037,7 @@ fn a_saved_image_from_an_alias_lands_by_hash_with_the_batch_request_id_and_one_l
let asked = rig.chat.fetches.borrow().clone();
assert_eq!(asked, [crate::chat_client::ChatFetchRequest { request_id: "s1-1-a".into(), persona: INSTANCE.into(), room: "swarm".into(), event_id: "$pic".into() }]);
let name = format!("{}.png", image.sha256);
assert_eq!(kept(&rig), [name.clone()]);
assert_eq!(kept(&rig), std::slice::from_ref(&name));
assert_eq!(std::fs::read(rig.sandbox().join("attachments").join(&name)).unwrap(), PNG_BYTES);
let line = input_of(&rig, 1);
assert!(line.contains(&format!("saved at attachments/{name}")) && line.contains("The room shows you received it"), "{line}");

View file

@ -125,9 +125,11 @@ data we lack).
Built: cut 1 (`texts` on `SourceQuery`), chat search and window, the chat ingest
core (`sources/chat.rs`, `room_scope.rs`, `chat_purge.rs`) and the ingest job.
The job is `huginn-sources`: with `--matrix-url`, `--matrix-token-file`, three
`--chat-exclude-room` ids (the estate rooms) and `--lock-file` it runs the forge
`--chat-exclude-room` ids (the estate rooms) it runs the forge
refresh and then `refresh_chat` through `sources/matrix.rs` (GET only, bearer
from a systemd credential file); without them it retires every chat point. The
from a systemd credential file); without them it retires every chat point. Every run, chat or not, requires
`--lock-file` and holds it for the run (exit 3 if held), as `chat-purge` does,
so a chat-off run cannot overwrite a concurrent purge tombstone. The
rooms indexed are the reader's memberships; no flag lists rooms. `huginn-sources
chat-purge` writes a steward's purge tombstone under the same lock. What the
operator still has to do (reader account, credential, roster, unit lines) is the

View file

@ -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": {