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
Hand-offs: one card per line when a lead names a teammate on several lines
Lin (kwant bot)aef43db97612
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8bdaf97f..dee7c7e2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -15,6 +15,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).Mission board, Bots & teams, Browser and Skills docs cover them, with the hand-off caps and Settings →Usage → Hand-offs per request. The site also gains /llms.txt and the Grok Bot comparison page.+### Fixed+- **One card per hand-off line.** A lead's message that hands the same teammate several lines (five+ `@Frontend, please …` lines) now makes one task and board card per line instead of one card for the+ whole message. The per-teammate cap (4) still applies; the rest wait for Continue and are sent once.+## [Mac 0.4.0] - 2026-10-29### Addeddiff --git a/docs/mission-control.md b/docs/mission-control.mdindex 9872e074..be208d42 100644--- a/docs/mission-control.md+++ b/docs/mission-control.md@@ -653,6 +653,23 @@ event is logged; per stay in Review it's asked at most `listener::MAX_REVIEW_ASKAfter both asks the card waits, "Waiting for <lead> to review", for the lead or the person. Cardsfrom before this change (no result evidence) and cards whose lead was deleted are left for the person.+### One card per hand-off line++When a lead's message names the same teammate on two or more lines that each @mention only that+teammate (`@Frontend, please build the menu.` on one line, `@Frontend, please build the footer.` on+the next), each line is its own hand-off: its own delegation, thread and board card, titled after+its line, with the whole message as context and "Your task is this line of <lead>'s message only:+<line>". Each card gets its own review and checks. The lead is still resumed once, when the last+hand-off of the batch ends. Lines inside a code fence don't count.++Dedupe, and why: a teammate named on **one** line, or on lines that also name other teammates,+still gets one hand-off with the whole message, as before, since kwant can't tell which part of a+shared line is whose. The same line repeated word for word counts once (it's a repeat, not more+work). Lines past the per-teammate cap (4) wait for Continue; on Continue, lines already sent are+skipped, so no line is sent twice. The lead's open limit (`delegation::MAX_OPEN_PER_LEAD`, 5 unfinished)+still applies per hand-off: a line past it is refused with the usual `handoff_refused` note. A dependency wait+("after @X") on a teammate with several cards waits for the last of them started.+### Capped hand-offs: the Continue noticeOne person message starts at most `routes::MAX_DELEGATIONS_PER_REQUEST` (16) hand-offs by mention,diff --git a/src/server/routes.rs b/src/server/routes.rsindex 3526e3ca..89289667 100644--- a/src/server/routes.rs+++ b/src/server/routes.rs@@ -1302,6 +1302,7 @@ pub(super) async fn delegate_mentions(targets.insert(at, k);}let mut started: std::collections::HashMap<String, String> = std::collections::HashMap::new();+ let mut sent = 0;let user = truncate_chars(user_prompt.trim(), 3000);let task = match relay {None => format!(@@ -1326,13 +1327,48 @@ pub(super) async fn delegate_mentions(None => title.clone(),};let allowed: Vec<String> = scope.teammates.iter().map(|k| k.id.clone()).collect();+ // One line of several for the same teammate is a task of its own (Rigel's promo footage,+ // 2026-10-30: five "@Frontend, please …" lines made one card)+ let line_task = |line: &str| {+ format!(+ "{task}\n\nYour task is this line of {lead}'s message only:\n{line}\n{lead} sent each line that mentions you as a \+ task of its own, so the other lines are not part of this one.",+ lead = lead.name,+ )+ };+ let mut units: Vec<(&Kwant, Option<String>)> = Vec::new();for (n, specialist) in targets.into_iter().enumerate() {if n >= MAX_HANDOFFS {skipped.push((specialist.name.clone(), format!("a message hands work to at most {MAX_HANDOFFS} teammates")));continue;}+ let lines = handoff_lines(text, &specialist.name);+ if lines.len() < 2 {+ units.push((specialist, None));+ continue;+ }+ let mut left = MAX_MENTION_DELEGATIONS_PER_BOT.saturating_sub(asked(&specialist.id));+ for line in lines {+ // Continue sends only the lines that weren't sent before the cap+ let sent = |d: &crate::db::threads::Delegation| d.specialist_kwant_id == specialist.id && d.task.starts_with(&line_task(&line));+ if resumed.is_some() && mine.iter().any(sent) {+ continue;+ }+ if left == 0 {+ if !capped.iter().any(|c| c.id == specialist.id) {+ capped.push(specialist);+ }+ break;+ }+ left -= 1;+ units.push((specialist, Some(line)));+ }+ }+ for (specialist, line) in units {if room == 0 {- capped.push(specialist);+ if !capped.iter().any(|c| c.id == specialist.id) {+ capped.push(specialist);+ }continue;}// Waits for a teammate started here, or for one still on an earlier task from this chat@@ -1354,8 +1390,11 @@ pub(super) async fn delegate_mentions(let req = super::delegation::StartRequest {lead: lead.clone(),specialist: specialist.clone(),- task: task.clone(),- title: Some(handoff_title(text, &specialist.name).unwrap_or_else(|| title_for(specialist))),+ task: line.as_deref().map_or_else(|| task.clone(), line_task),+ title: Some(match &line {+ Some(l) => handoff_title(l, &specialist.name).unwrap_or_else(|| first_line(l)),+ None => handoff_title(text, &specialist.name).unwrap_or_else(|| title_for(specialist)),+ }),origin: super::delegation::Origin { channel_id: Some(cid.clone()), ..Default::default() },continue_lead: true,origin_depth: scope.delegation_depth,@@ -1366,6 +1405,7 @@ pub(super) async fn delegate_mentions(match super::delegation::start(&scope.state, req).await {Ok(d) => {started.insert(specialist.id.clone(), d.id);+ sent += 1;room -= 1;}Err((_, why)) => skipped.push((specialist.name.clone(), why.trim_end_matches('.').to_string())),@@ -1373,7 +1413,7 @@ pub(super) async fn delegate_mentions(}report_skipped(scope, skipped).await;if !capped.is_empty() {- super::budget::pause_capped(scope, lead, &capped, this_request.len() + started.len(), text, user_prompt).await;+ super::budget::pause_capped(scope, lead, &capped, this_request.len() + sent, text, user_prompt).await;}}@@ -1407,6 +1447,30 @@ pub fn handoff_title(text: &str, name: &str) -> Option<String> {Some(truncate_chars(&title, 80).to_string())}+/// The lines of `text` that each hand `name` a piece of work: they @mention `name` and nobody+/// else, outside ``` / ~~~ blocks; a line said twice counts once. Two or more of them are a task+/// (and a board card) each, so every piece is reviewed and verified on its own; one line, or a+/// line naming several teammates, leaves the whole message as one task, as before.+pub fn handoff_lines(text: &str, name: &str) -> Vec<String> {+ let tag = format!("@{}", name.to_lowercase());+ let mut fenced = false;+ let mut out: Vec<String> = Vec::new();+ for line in text.lines() {+ let trimmed = line.trim();+ if trimmed.starts_with("```") || trimmed.starts_with("~~~") {+ fenced = !fenced;+ continue;+ }+ let lower = trimmed.to_lowercase();+ let names_it = lower.match_indices(&tag).any(|(i, _)| !lower[i + tag.len()..].starts_with(|c: char| c.is_alphanumeric() || c == '_'));+ let mentions = trimmed.match_indices('@').filter(|&(i, _)| trimmed[i + 1..].starts_with(char::is_alphanumeric)).count();+ if !fenced && names_it && mentions == 1 && !out.iter().any(|l| l == trimmed) {+ out.push(trimmed.to_string());+ }+ }+ out+}+/// The first line of `text` that @mentions `name`, without its list marker, for a relayed task's title.fn mention_line(text: &str, name: &str) -> Option<String> {let tag = format!("@{}", name.to_lowercase());diff --git a/tests/delegation_test.rs b/tests/delegation_test.rsindex 5c66b212..78774993 100644--- a/tests/delegation_test.rs+++ b/tests/delegation_test.rs@@ -26,7 +26,9 @@ use tower::ServiceExt;/// "MENTION:<name>", and by "`@<name>` please revise your part." (inline code, as models write it)/// for a lead's results follow-up with "FOLLOWUP:<name>"; several names go as "<a>+<b>". A/// follow-up with "CREDIT:<name>" adds "As @<name> found, it's done." (a mention that asks nothing);-/// a "LONGTASK:<file>" prompt waits (up to 60 s) for that file first, and a "FAILTASK" prompt fails. Every prompt is saved under `$KWNT_TEST_PROMPTS`.+/// a "LONGTASK:<file>" prompt waits (up to 60 s) for that file first, and a "FAILTASK" prompt fails.+/// "LINES:<name>:<n>" adds n lines "@<name>, please build part <i>." to a reply that isn't a+/// delegated task or a results follow-up. Every prompt is saved under `$KWNT_TEST_PROMPTS`.const FAKE_CLAUDE: &str = r#"#!/bin/shcase "$1" inauth) echo '{"loggedIn":true}'; exit 0 ;;@@ -44,10 +46,16 @@ mention=$(printf '%s\n' "$last" | sed -n 's/.*MENTION:\([A-Za-z0-9_+]*\).*/\1/p'followup=$(printf '%s\n' "$last" | sed -n 's/.*FOLLOWUP:\([A-Za-z0-9_+]*\).*/\1/p' | head -n 1)credit=$(printf '%s\n' "$last" | sed -n 's/.*CREDIT:\([A-Za-z0-9_]*\).*/\1/p' | head -n 1)case "$last" in *"finished the task you delegated"*|*"tasks you delegated have ended"*) ;; *) followup=""; credit="" ;; esac+lines=$(printf '%s\n' "$last" | sed -n 's/.*LINES:\([A-Za-z0-9_]*:[0-9]*\).*/\1/p' | head -n 1)+case "$last" in *"finished the task you delegated"*|*"tasks you delegated have ended"*|*"mentioned you"*) lines="" ;; esacout="answer ${tag:-none}"for n in $(printf '%s' "$mention" | tr '+' ' '); do out="$out @$n"; donefor n in $(printf '%s' "$followup" | tr '+' ' '); do out="$out \`@$n\` please revise your part."; done[ -n "$credit" ] && out="$out As @$credit found, it's done."+if [ -n "$lines" ]; then+ i=1+ while [ $i -le "${lines##*:}" ]; do out="$out\\n@${lines%%:*}, please build part $i."; i=$((i+1)); done+fiecho "{\"type\":\"result\",\"is_error\":false,\"num_turns\":1,\"result\":\"$out\"}""#;@@ -1486,3 +1494,79 @@ async fn a_relayed_mention_past_the_cap_waits_for_continue() {let to_growth = env.state.db.list_delegations(Some(&env.lead), None, 50).await.unwrap().iter().filter(|d| d.specialist_kwant_id == growth).count();assert_eq!(to_growth, per_bot_limit(), "nothing past the cap until Continue");}++/// The lead's delegations from `channel`, oldest first.+async fn handoffs_from(env: &Env, channel: &str) -> Vec<kwnt::db::threads::Delegation> {+ let mut ds: Vec<_> = env+ .state+ .db+ .list_delegations(Some(&env.lead), None, 50)+ .await+ .unwrap()+ .into_iter()+ .filter(|d| d.origin_channel_id.as_deref() == Some(channel))+ .collect();+ ds.sort_by_key(|d| d.created_at);+ ds+}++/// Rigel's promo footage (2026-10-30): the lead wrote five "@Frontend, please …" lines and kwant+/// made one card, named after the first. Each line that hands the same teammate its own piece is+/// now a delegation (a board card) of its own, named after that line and carrying only that line+/// as its task; the lead is still resumed once, with every result.+#[tokio::test]+async fn each_line_for_the_same_teammate_is_its_own_hand_off() {+ let env = setup().await;+ let (lead, specialist) = (name(&env, &env.lead).await, name(&env, &env.specialist).await);+ let channel = team_channel(&env, "lines-squad").await;+ say_in(&env, &channel, &format!("@{lead} Build the site LINESMARK1 REPLYTAG:plan LINES:{specialist}:3")).await;++ wait_for("three hand-offs", || async { handoffs_from(&env, &channel).await.len() >= 3 }).await;+ wait_for("the lead's final answer", || async {+ prompts_with("LINESMARK1").iter().any(|p| p.contains("tasks you delegated have ended"))+ })+ .await;+ tokio::time::sleep(Duration::from_millis(1500)).await;+ let ds = handoffs_from(&env, &channel).await;+ assert_eq!(ds.len(), 3, "one hand-off per line: {:?}", ds.iter().map(|d| &d.title).collect::<Vec<_>>());+ for (i, d) in ds.iter().enumerate() {+ let part = format!("build part {}.", i + 1);+ assert_eq!(d.specialist_kwant_id, env.specialist);+ assert!(d.title.to_lowercase().contains(&part), "named after its own line: {}", d.title);+ let own = d.task.split("Your task is this line").nth(1).unwrap_or_default();+ assert!(own.contains(&part), "the task names its line: {}", d.task);+ for j in (1..=3).filter(|&j| j != i + 1) {+ assert!(!own.contains(&format!("build part {j}.")), "only its own line: {own}");+ }+ }+ let resumes = prompts_with("LINESMARK1").into_iter().filter(|p| p.contains("tasks you delegated have ended")).count();+ assert_eq!(resumes, 1, "the lead is resumed once for the whole batch");+ assert!(capped(&channel_messages(&env, &channel).await).is_empty());+}++/// Five lines for one teammate: the per-teammate cap sends four, a Continue notice holds the+/// fifth, and Continue sends just that one, not the four again.+#[tokio::test]+async fn lines_past_the_per_teammate_cap_wait_for_continue_and_are_sent_once() {+ let env = setup().await;+ let (lead, specialist) = (name(&env, &env.lead).await, name(&env, &env.specialist).await);+ let channel = team_channel(&env, "five-lines").await;+ say_in(&env, &channel, &format!("@{lead} Build the site LINESMARK2 REPLYTAG:plan LINES:{specialist}:5")).await;++ wait_for("the Continue notice", || async { !capped(&channel_messages(&env, &channel).await).is_empty() }).await;+ let ds = handoffs_from(&env, &channel).await;+ assert_eq!(ds.len(), per_bot_limit(), "up to the per-teammate cap");+ let notice = capped(&channel_messages(&env, &channel).await).remove(0);+ assert!(notice.text.contains(&format!("{specialist} not sent yet")), "{}", notice.text);+ for d in &ds {+ wait_for("a part to finish", || async { delegation_status(&env, &d.id).await == "completed" }).await;+ }++ let (s, v) = call(&env.app, "POST", &format!("/api/chains/{}/continue", notice.id), None).await;+ assert_eq!(s, StatusCode::OK, "{v}");+ wait_for("the fifth part", || async { handoffs_from(&env, &channel).await.len() > per_bot_limit() }).await;+ tokio::time::sleep(Duration::from_millis(1500)).await;+ let ds = handoffs_from(&env, &channel).await;+ assert_eq!(ds.len(), 5, "Continue sends only the line that waited: {:?}", ds.iter().map(|d| &d.title).collect::<Vec<_>>());+ assert!(ds[4].title.to_lowercase().contains("build part 5."), "{}", ds[4].title);+}