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
Flight School: Sandbox says commands that can change things ask; an answered card frees the task
Lin (kwant bot)45d80e41dd3a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 46b79615..ce2a3b0d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,8 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).### Added- **Flight School: give each bot only as much freedom as it has earned.** With the new `flight_school`setting on (off by default), you can set a bot's tier per kind of task: Observe (every change asks),- Sandbox (it may change files in its task folder when kwant took a checkpoint it can undo; every command- asks) or Act (its normal approvals). A tier only adds approval cards, even with approvals off, and+ Sandbox (it may change files in its task folder when kwant took a checkpoint it can undo; commands that+ can change things ask, while read-only ones in its own folder, such as `ls` or `cat`, run without+ asking) or Act (its normal approvals). A tier only adds approval cards, even with approvals off, andpayments still always ask. Lowering a tier applies from the bot's next action. Bots already there keepAct; bots hired after you switch it on start at Sandbox. A bot on Codex or a custom engine that is belowAct doesn't run its task, because kwant can't see its own tools.@@ -130,6 +131,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).with it, so on a phone the buttons sat below the box until you scrolled. While you follow the chat itnow stays pinned to the bottom. If you've scrolled up to read, it stays where you are and shows an"Approval waiting" button above the message box that takes you to the card.+- **A task no longer sits in "Working" with no bot on it after you answer a card.** When you allowed an+ action on a task's card, the bot's "done, please review" right after it could be refused as "waiting+ on you", and the task then stayed in Working with nothing running it. Answering a card now moves the+ task back at once, and a bot's hand-in or the end of its turn no longer waits for that.- **Mission board: "To fix" no longer repeats the failure's name.** A usage-limit failure read "Usagelimit reached" on its badge and again at the start of "To fix"; "To fix" now starts with what to do.- **Mission board: AutoFix hides passwords without hiding command names.** A check's command name or adiff --git a/docs/mission-control.md b/docs/mission-control.mdindex 0e5c7067..c00a97d3 100644--- a/docs/mission-control.md+++ b/docs/mission-control.md@@ -541,10 +541,25 @@ every call. In order:| `workspace` (file tool in the task folder) | card | runs if this run has a `before_run` checkpoint, else card | today's path || `external` (`Bash`, MCP tools, outside files, other self tools) | card | card | today's path |-A forced card carries `details.tier_reason` ("Sandbox: commands always ask", "Observe: every change+A forced card carries `details.tier_reason` ("Sandbox: commands that can change things ask", "Observe: every changeasks", …). Approvals `off`, smart Allow and `always_ask` don't skip it; a session "always allow" for thattool in that chat does (D9), except on a payment.+**Known gap (waived): read-only commands in the bot's own folder.** The Claude CLI runs with+`--permission-mode default`, and its own allow-list runs read-only commands such as `ls`, `cat`, `pwd`+and `date` inside the turn's folder without asking kwnt. They never reach the gate, with Flight School+on or off, and no ledger row is written. A command that changes something, or that reads outside the+folder, still asks, so at `sandbox` "commands that can change things ask" is what holds, not "every+command". The API drivers' `execute_shell` goes through `approve_local_shell_in`, so there every+command asks below `act`. Accepted 2026-10-28 (Rigel's C3 check, Ada's decision): nothing can be written+this way, and the bot can read only its own folder.++**A card answered in time** sends no event of its own. `POST /api/approvals/:id/resolve` re-runs+`listener::refresh_needs_you`, and `task_update` and the runner's `after_turn` first move a task that+waits in `needs_you` on nothing back to `working` (`listener::settle_needs_you`). Before this, a bot's+`task_update review` right after an answered card was refused ("the task is waiting on the person"),+the turn ended, and the next tick put the task back in `working` with no turn running it.+### Revoke and engines- `POST /api/capabilities/:kwant_id/revoke` writes the lower tier in one transaction; the running turn'sdiff --git a/src/server/computer.rs b/src/server/computer.rsindex b2d0d286..2c72ab5d 100644--- a/src/server/computer.rs+++ b/src/server/computer.rs@@ -201,7 +201,7 @@ pub async fn approve_local_shell_in(if let Some(why) = &payment {details["payment_reason"] = json!(why);}- // Flight School (C3): below act, a command always asks, approvals off or not+ // Flight School (C3): below act, a command kwant runs always asks, approvals off or notlet tier = match payment {Some(_) => None,None => super::missions::flight_school::shell_gate(&state.db, target_id).await,diff --git a/src/server/missions/flight_school.rs b/src/server/missions/flight_school.rsindex 7ad8a0e7..a19e47b5 100644--- a/src/server/missions/flight_school.rs+++ b/src/server/missions/flight_school.rs@@ -80,7 +80,7 @@ pub fn decide(tier: &str, effect: &str, bash: bool, checkpoint: bool) -> Option<("act", _) | (_, "none") => None,("sandbox", "workspace") if checkpoint => None,("sandbox", "workspace") => Some("Sandbox: this run has no checkpoint to undo file changes, so they ask"),- ("sandbox", _) if bash => Some("Sandbox: commands always ask"),+ ("sandbox", _) if bash => Some("Sandbox: commands that can change things ask"),("sandbox", _) => Some("Sandbox: only files in the task folder change without asking"),_ => Some("Observe: every change asks"),}@@ -349,7 +349,7 @@ mod tests {] {assert_eq!(decide(tier, effect, bash, cp).is_some(), card, "{tier} {effect} bash={bash} cp={cp}");}- assert_eq!(decide("sandbox", "external", true, true), Some("Sandbox: commands always ask"));+ assert_eq!(decide("sandbox", "external", true, true), Some("Sandbox: commands that can change things ask"));}#[test]diff --git a/src/server/missions/listener.rs b/src/server/missions/listener.rsindex 418d9c02..03e5be0d 100644--- a/src/server/missions/listener.rs+++ b/src/server/missions/listener.rs@@ -270,6 +270,23 @@ pub async fn refresh_needs_you(state: &AppState) {}}+/// `task_id` as it stands, after moving it back to `working` if it waits in `needs_you` on+/// nothing: a card answered in time sends no event, so a bot's hand-in or the turn's end can+/// come before [`refresh_needs_you`] has run.+pub async fn settle_needs_you(state: &AppState, task_id: &str) -> Option<Task> {+ let _serial = SERIAL.lock().await;+ let t = state.db.get_task(task_id).await.ok().flatten()?;+ if t.state != "needs_you" || !super::needs_you(state, &t).await.is_empty() {+ return Some(t);+ }+ let _ = state.db.refresh_claim(&t.id, lease_ms(state).await).await;+ let change = TaskChange { reason: Some("the person answered".into()), ..Default::default() };+ match transition(state, &t.id, "needs_you", "working", Actor::Kwant, "kwant", change).await {+ Ok(t) => Some(t),+ Err(_) => state.db.get_task(task_id).await.ok().flatten(),+ }+}+/// A work-ahead run posted `text`: a task in `review` owned by the lead, so the person sees it on/// the board and verifies it (or a teammate reviews it).pub async fn on_work_ahead_posted(state: &AppState, lead: &crate::db::models::Kwant, place: (Option<String>, Option<String>, Option<String>), run_id: &str, text: &str) {diff --git a/src/server/missions/runner.rs b/src/server/missions/runner.rsindex 1e77f7d0..4af36901 100644--- a/src/server/missions/runner.rs+++ b/src/server/missions/runner.rs@@ -191,7 +191,8 @@ async fn run_one(state: &AppState, m: &Mission, task: &Task, bot: &crate::db::mo/// `failed` for it (§13), and the failure is recorded: the turn's error, a denied action since/// `started`, or a stall; a task left waiting on the person records `needs_input`.pub async fn after_turn(state: &AppState, task_id: &str, err: Option<&str>, started: chrono::DateTime<chrono::Utc>) {- let Ok(Some(t)) = state.db.get_task(task_id).await else { return };+ // Waiting on nothing (its cards were answered or withdrawn) is still working: release it+ let Some(t) = super::listener::settle_needs_you(state, task_id).await else { return };if t.state == "needs_you" {super::autofix::record(state, &t.id, "turn", "needs_input", "", "the bot is waiting on the person").await;return;diff --git a/src/server/missions/tools.rs b/src/server/missions/tools.rsindex ac1ed460..f23a684c 100644--- a/src/server/missions/tools.rs+++ b/src/server/missions/tools.rs@@ -315,6 +315,9 @@ async fn holds(state: &AppState, scope: &SelfScope, task: &Task) -> bool {}async fn update(state: &AppState, scope: &SelfScope, task: &Task, args: &Value) -> ToolResult {+ // A card answered a moment ago may not have moved the task back from needs_you yet+ let settled = super::listener::settle_needs_you(state, &task.id).await;+ let task = settled.as_ref().unwrap_or(task);if !holds(state, scope, task).await {return fail("You don't hold this task (claim it first, or your lease ran out).");}diff --git a/src/server/routes.rs b/src/server/routes.rsindex d6ccad33..a10a4e8e 100644--- a/src/server/routes.rs+++ b/src/server/routes.rs@@ -3219,6 +3219,8 @@ pub async fn resolve_approval(};}let _ = state.db.update_approval_status(&ticket_id, status_str).await;+ // The card is answered: a task that waited on it is working again (Mission Control)+ super::missions::listener::refresh_needs_you(&state).await;Ok(Json(json!({"ticket_id": ticket_id,diff --git a/tests/flight_school_test.rs b/tests/flight_school_test.rsindex a493686a..b0637721 100644--- a/tests/flight_school_test.rs+++ b/tests/flight_school_test.rs@@ -21,6 +21,7 @@ use kwnt::{server::{continuity::{SelfScope, SelfToolsApprover, TurnOrigin},create_router, mcp_runtime,+ missions::{listener, runner},turns::ActiveTurn,AppState,},@@ -297,7 +298,7 @@ async fn sandbox_cards_every_command_and_outside_write_and_needs_a_checkpoint_foassert_eq!(claude_asks(&e, &dir, "Read", json!({"file_path": dir.join("notes.md").display().to_string()})).await, Ok("allow".into()));for command in ["touch x", "ls", "echo hi"] {let Err(d) = claude_asks(&e, &dir, "Bash", json!({"command": command})).await else { panic!("sandbox: {command} must ask") };- assert_eq!(reason(&d), "Sandbox: commands always ask");+ assert_eq!(reason(&d), "Sandbox: commands that can change things ask");}let Err(d) = claude_asks(&e, &dir, "Write", json!({"file_path": "/tmp/fs-outside.txt", "content": "x"})).await else { panic!("outside write") };assert!(reason(&d).starts_with("Sandbox"), "{d}");@@ -386,7 +387,7 @@ async fn revoke_mid_turn_gates_the_very_next_call() {assert_eq!(r["unchanged"], false, "{r}");// Same turn, next calllet Err(d) = ask_in(&e, &token, "Bash", json!({"command": "touch b"})).await else { panic!("revoked: the next call asks") };- assert_eq!(reason(&d), "Sandbox: commands always ask");+ assert_eq!(reason(&d), "Sandbox: commands that can change things ask");// Revoking again (or to a higher tier) changes nothinglet again = person(&e, "POST", &format!("/api/capabilities/{}/revoke", e.bot.id), json!({"task_class": "*", "to_tier": "sandbox"})).await;assert_eq!(again["unchanged"], true);@@ -469,3 +470,89 @@ async fn a_codex_bot_below_act_blocks_its_task_instead_of_running_it() {let caps = person(&e, "GET", &format!("/api/capabilities?kwant_id={cody}"), json!(null)).await;assert_eq!(caps["default_tier"], "act", "{caps}");}++/// A Bash card in the turn behind `token`, left open: (its id, the permission prompt still waiting).+async fn open_card(e: &Env, token: &str, command: &str) -> (String, tokio::task::JoinHandle<(StatusCode, Value)>) {+ let mut events = e.state.event_sender.subscribe();+ let ask = json!({"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "approve",+ "arguments": {"tool_name": "Bash", "input": {"command": command}, "tool_use_id": "tu_1"}}});+ let app = e.app.clone();+ let path = format!("/api/mcp/permission/{token}");+ let prompt = tokio::spawn(async move { call(&app, "POST", &path, None, Some(ask)).await });+ let card = tokio::time::timeout(Duration::from_secs(5), async {+ loop {+ if let Ok(RuntimeEvent::ApprovalRequired { id, .. }) = events.recv().await {+ break id;+ }+ }+ });+ (card.await.expect("a card"), prompt)+}++async fn state_of(e: &Env, task_id: &str) -> String {+ e.state.db.get_task(task_id).await.unwrap().unwrap().state+}++/// Answers a card the way the resolve route does, minus its board refresh: a bot whose next call+/// comes before the listener has moved the task back from needs_you.+async fn answer_quietly(e: &Env, card: &str, prompt: tokio::task::JoinHandle<(StatusCode, Value)>) {+ assert!(e.state.broker.resolve(card, ApprovalDecision::AllowOnce).await);+ e.state.db.update_approval_status(card, "allowed_once").await.unwrap();+ let (status, _) = prompt.await.unwrap();+ assert_eq!(status, StatusCode::OK);+}++/// Rigel's stuck run: a card put the task in needs_you, the person answered it in time (no event),+/// the bot's `task_update review` was refused as "waiting on the person", the turn ended, and the+/// next tick moved the task back to working with no turn running it.+#[tokio::test]+async fn a_card_answered_in_time_lets_the_bot_hand_in() {+ let e = setup().await;+ set_approvals(&e, "off").await;+ flight_school(&e, true).await;+ set_tier(&e, "*", "sandbox").await;+ let (tid, dir) = claimed_task(&e, "general", true).await;+ let (turn_id, token) = turn(&e, &dir).await;+ // Answered on the card: the resolve route moves the board back at once+ let (card, prompt) = open_card(&e, &token, "touch c.txt").await;+ listener::refresh_needs_you(&e.state).await;+ assert_eq!(state_of(&e, &tid).await, "needs_you");+ person(&e, "POST", &format!("/api/approvals/{card}/resolve"), json!({"decision": "allow_once"})).await;+ prompt.await.unwrap();+ assert_eq!(state_of(&e, &tid).await, "working");+ // The bot is faster than the refresh: its hand-in still goes through+ let (card, prompt) = open_card(&e, &token, "touch d.txt").await;+ listener::refresh_needs_you(&e.state).await;+ answer_quietly(&e, &card, prompt).await;+ assert_eq!(state_of(&e, &tid).await, "needs_you");+ let (err, text) = self_tool(&e, &token, "task_update", json!({"task_id": tid, "status": "review", "note": "done"})).await;+ assert!(!err, "{text}");+ assert_eq!(state_of(&e, &tid).await, "review");+ end(&e, &turn_id, &token).await;+}++#[tokio::test]+async fn a_turn_that_ends_with_its_card_answered_releases_the_task() {+ let e = setup().await;+ set_approvals(&e, "off").await;+ flight_school(&e, true).await;+ set_tier(&e, "*", "sandbox").await;+ let (tid, dir) = claimed_task(&e, "general", true).await;+ let started = Utc::now();+ let (turn_id, token) = turn(&e, &dir).await;+ let (card, prompt) = open_card(&e, &token, "touch c.txt").await;+ listener::refresh_needs_you(&e.state).await;+ answer_quietly(&e, &card, prompt).await;+ end(&e, &turn_id, &token).await;+ runner::after_turn(&e.state, &tid, None, started).await;+ // Not left in needs_you to come back as working with nothing running it+ assert_eq!(state_of(&e, &tid).await, "ready");+ // A card still open at the turn's end keeps it waiting on the person+ let (tid2, dir2) = claimed_task(&e, "general", true).await;+ let (turn2, token2) = turn(&e, &dir2).await;+ let (_card, _prompt) = open_card(&e, &token2, "touch e.txt").await;+ listener::refresh_needs_you(&e.state).await;+ runner::after_turn(&e.state, &tid2, None, started).await;+ assert_eq!(state_of(&e, &tid2).await, "needs_you");+ end(&e, &turn2, &token2).await;+}