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.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Routing polish: 'my private' only for personal records, clause-bounded negation, Art/logo test
Lin (kwant bot)4c76a1b78c42
diff --git a/src/router/fallback.rs b/src/router/fallback.rsindex 7b8bb72f..243eebdf 100644--- a/src/router/fallback.rs+++ b/src/router/fallback.rs@@ -21,6 +21,12 @@ const NEGATIONS: &[&str] = &["don't", "dont", "do not", "not", "no", "never", "w/// After a negation, these turn it back into a request: "don't ignore security warnings" wants them looked at.const UNDO_NEGATION: &[&str] = &["ignore", "skip", "forget", "overlook", "neglect", "miss", "underestimate"];+/// How far back a negation reaches: "don't worry about the refactor" is four words.+const NEGATION_WINDOW: usize = 4;++/// After a negation, these say the person is confused, not declining: "I don't understand the architecture".+const NOT_A_REFUSAL: &[&str] = &["know", "understand", "get", "see", "sure"];+/// Lower-case words of `text`. Apostrophes stay inside a word ("don't") but a possessive "'s" is/// dropped ("Rust's" is "rust"). Hyphens split a word ("code-review" is "code review"), and keyword/// phrases are split the same way, so "trade-off" still matches "trade-off" and "trade off".@@ -64,22 +70,38 @@ fn has_any(words: &[String], phrases: &[&str]) -> bool {phrases.iter().any(|p| has_phrase(words, p))}-/// A deep signal that isn't part of an everyday phrase and isn't negated just before it.+/// The clauses of `text`, as [`words`]. A clause ends at punctuation or at "but"/"just", so a+/// negation in one ("don't refactor it, just…") doesn't reach into the next.+fn clauses(text: &str) -> Vec<Vec<String>> {+ text.split([',', '.', ';', ':', '!', '?', '\n'])+ .flat_map(|c| words(c).split(|w| w == "but" || w == "just").map(<[String]>::to_vec).collect::<Vec<_>>())+ .filter(|c| !c.is_empty())+ .collect()+}++/// A deep signal that isn't part of an everyday phrase and isn't negated earlier in its clause.fn has_deep_signal(text: &str) -> bool {- let mut ws = words(text);- for idiom in NOT_DEEP {- let len = idiom.split([' ', '-']).count();- for i in phrase_at(&ws, idiom) {- for w in &mut ws[i..i + len] {- w.clear();+ clauses(text).into_iter().any(|mut ws| {+ for idiom in NOT_DEEP {+ let len = idiom.split([' ', '-']).count();+ for i in phrase_at(&ws, idiom) {+ for w in &mut ws[i..i + len] {+ w.clear();+ }}}- }- let negated = |i: usize| {- let before = &ws[i.saturating_sub(2)..i];- NEGATIONS.iter().any(|n| has_phrase(before, n)) && !has_any(before, UNDO_NEGATION)- };- DEEP_SIGNALS.iter().any(|s| phrase_at(&ws, s).into_iter().any(|i| !negated(i)))+ let negated = |i: usize| {+ let before = &ws[i.saturating_sub(NEGATION_WINDOW)..i];+ let refusal = NEGATIONS.iter().any(|n| {+ phrase_at(before, n).into_iter().any(|j| {+ let next = before.get(j + n.split(' ').count()).map(String::as_str).unwrap_or("");+ !NOT_A_REFUSAL.contains(&next)+ })+ });+ refusal && !has_any(before, UNDO_NEGATION)+ };+ DEEP_SIGNALS.iter().any(|s| phrase_at(&ws, s).into_iter().any(|i| !negated(i)))+ })}/// Chinese, Japanese and Korean text has no spaces between words.@@ -145,7 +167,10 @@ pub fn blend_effort(prompt: &str, laya_effort: &str) -> String {const PRIVATE: &[&str] = &["confidential", "sensitive", "offline", "ollama", "local model", "local llm", "locally", "on-device","on my machine", "private data", "private files", "private documents", "private info",- "private information", "my private", "keep it private", "keep this private",+ "private information", "keep it private", "keep this private",+ // "my private" only before the person's own records: "my private repo" and "my private method" are code+ "my private file", "my private document", "my private note", "my private diary", "my private record",+ "my private health", "my private medical",];/// Needs long reasoning or writing.diff --git a/tests/router_test.rs b/tests/router_test.rsindex 5a5b2209..9447970e 100644--- a/tests/router_test.rs+++ b/tests/router_test.rs@@ -819,3 +819,40 @@ fn roles_come_from_titles_in_any_spelling_not_from_names() {let p = kwnt::router::team::pick_member("Plan our SEO keyword strategy for Q4", "dev", &members, None, "channel lead").unwrap();assert_eq!(p.kwant.name, "Mia", "hb05");}++#[test]+fn my_private_code_is_not_a_request_for_the_local_model() {+ assert_ne!(offline_model("My private method throws a NullPointerException when the list is empty"), "local_ollama");+ assert_ne!(offline_model("My private repo on GitHub fails to clone over SSH"), "local_ollama");+ // The person's own records still stay here+ assert_eq!(offline_model("Summarize my private medical lab results: total cholesterol 240, LDL 160, HDL 38"), "local_ollama", "m14");+ assert_eq!(offline_model("Go through my private notes and list the open todos"), "local_ollama");+ assert_eq!(offline_model("Read my private diary entries from June and summarize my mood"), "local_ollama");+ assert_eq!(offline_model("Sort my private health records by date"), "local_ollama");+}++#[test]+fn a_bot_named_art_doesnt_get_design_work_by_its_name() {+ // No designer here, so nobody's role matches and the lead decides+ let members = [agent("art", "Art", "Software Engineer"), agent("lee", "Lee", "Tech Lead")];+ let pick = kwnt::router::team::pick_member("Sketch a logo for the landing page", "lee", &members, None, "channel lead").unwrap();+ assert_ne!(pick.kwant.name, "Art", "{}", pick.reason);+}++#[test]+fn a_negation_reaches_to_the_end_of_its_clause() {+ use kwnt::router::fallback::{blend_effort, heuristic_effort};+ let prompt = "Don't worry about the refactor, just rename this variable";+ assert_ne!(heuristic_effort(prompt, "chat"), "high");+ assert_eq!(blend_effort(prompt, "medium"), "medium");+ // Still high: the negation is undone, or it sits in another clause+ assert_eq!(heuristic_effort("Don't ignore security warnings from npm audit", "chat"), "high");+ assert_eq!(heuristic_effort("Don't forget about the security review before release", "chat"), "high");+ assert_eq!(heuristic_effort("Don't rename anything, but investigate the root cause of the crash", "chat"), "high");+ assert_eq!(heuristic_effort("No rush. Investigate why the cache misses", "chat"), "high");+ // Confusion isn't a refusal+ assert_eq!(heuristic_effort("I don't understand the architecture of this service", "chat"), "high");+ // Still not high+ assert_ne!(heuristic_effort("Don't refactor the module yet, just rename it", "chat"), "high");+ assert_eq!(heuristic_effort("Please don't refactor anything, just tell me what time zone Paris is in", "chat"), "low", "a01");+}