Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Router: a route no one's words won shows no matched words (#261)

Oleksandr Ivanchenko5a986ea58e97
diff --git a/src/router/team.rs b/src/router/team.rs
index 62e4b946..302f5e0b 100644
--- a/src/router/team.rs
+++ b/src/router/team.rs
@@ -1156,10 +1156,17 @@ fn is_code_request(prompt: &str) -> bool {
words.iter().take(3).any(|w| VERBS.contains(&w.as_str()))
}
+/// The words a route shows as "matched". A route no one's words won (`lead`, `last`) or the
+/// Concierge took shows none: a step-5 tie keeps its words only so [`settle`] asks, and
+/// "No one's role matched this · matched 'macro', 'bread'" read wrong.
+pub fn shown_terms(basis: &str, terms: Vec<String>) -> Vec<String> {
+ if matches!(basis, "lead" | "last" | "concierge") { Vec::new() } else { terms }
+}
+
/// A Direct decision from a pick. A message nobody can take goes to the lead.
fn direct(pick: Option<Pick<'_>>, team: &Team) -> TeamDecision {
match pick {
- Some(p) => TeamDecision::Direct { kwant_id: p.kwant.id.clone(), reason: p.reason, basis: p.basis.into(), matched_terms: p.terms },
+ Some(p) => TeamDecision::Direct { kwant_id: p.kwant.id.clone(), reason: p.reason, basis: p.basis.into(), matched_terms: shown_terms(p.basis, p.terms) },
None => TeamDecision::Direct {
kwant_id: team.lead_kwant_id.clone(),
reason: "No team members available; routed to team lead".into(),
@@ -1440,7 +1447,7 @@ fn generate_discussion_plan(speakers: &[String], members: &[Kwant]) -> Vec<Strin
mod tests {
use super::*;
- fn make_test_fixture() -> (Team, Vec<Kwant>) {
+ pub(super) fn make_test_fixture() -> (Team, Vec<Kwant>) {
let team = Team {
space_id: crate::db::spaces::DEFAULT_SPACE_ID.into(),
id: "team-1".into(),
@@ -1779,6 +1786,21 @@ mod fit_tests {
]
}
+ /// A step-5 word tie asks in #general, but routed on to the lead it shows no matched words.
+ #[test]
+ fn a_route_no_words_won_shows_no_matched_words() {
+ let members = kitchen();
+ let p = pick_member_after("bread macros", "k-tl", &members, None, "channel lead", None).unwrap();
+ assert!(matches!(p.basis, "lead" | "last"), "{p:?}");
+ assert!(!p.terms.is_empty(), "{p:?}");
+ assert!(matches!(settle(&route_of(&p), true, true), Settle::Ask(_)), "{p:?}");
+ let team = Team { lead_kwant_id: "k-tl".into(), ..super::tests::make_test_fixture().0 };
+ let TeamDecision::Direct { matched_terms, basis, .. } = direct(Some(p), &team) else { panic!("not direct") };
+ assert!(matched_terms.is_empty(), "{basis}: {matched_terms:?}");
+ assert_eq!(shown_terms("skills", vec!["dough".into()]), vec!["dough".to_string()]);
+ assert!(shown_terms("concierge", vec!["dough".into()]).is_empty());
+ }
+
/// The first fit score sent a specialist question with one word only its bot has, and no
/// runner-up, to the Concierge (0.5, nobody to ask about). Corn dogs still have no fit.
#[test]
diff --git a/src/server/routes.rs b/src/server/routes.rs
index 9b5b531a..80f88b28 100644
--- a/src/server/routes.rs
+++ b/src/server/routes.rs
@@ -3592,6 +3592,8 @@ async fn send_chat_inner(
}
crate::router::team::Settle::Route => {}
}
+ // Words only `settle` needed (a step-5 tie routed on) aren't shown as matched
+ route.matched_terms = crate::router::team::shown_terms(&route.basis, std::mem::take(&mut route.matched_terms));
if let Some(ref k) = chosen {
routing = Some(routing_meta(k, &route.reason, members.len(), route.fallback, &route.matched_terms, &route.basis, &saved_user_msg.id));
if let Some(m) = routing.as_mut() {