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
Person-only computer choice; more closing lines don't stick
Lin (kwant bot)8584d76e1cb8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9a05c82a..45d6b916 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,7 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).### Changed- A bot reply that ends with a closing line such as "Anything else?", "Should I continue?" or- "Want me to also…?" no longer pulls the person's next message back to that bot. Real questions+ "Want me to also…?" (and now also "Happy to help further?", "Any other questions?", "What else can+ I do for you?") no longer pulls the person's next message back to that bot. Real questions("Which city are you in?") still do, unless the next message clearly fits another bot better.- UK places (London, Belfast, Jersey, Guernsey, Isle of Man) get metric units with road distancesand speeds in miles and mph.@@ -27,6 +28,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).- A CAPTCHA step now holds the browser before the step appears, so a bot can't act on the page in between.### Security+- Only the person can switch which computer the bots run on (Settings → Computer) or open their+ browser as a window: `PUT /api/settings/computer` and `/api/settings/computer/window` now refuse+ a bot's turn token, like `POST /api/settings`.- Changing app-wide settings (`POST /api/settings`) is person-only. Bots change the settings theyare allowed to through their `settings_update` action.diff --git a/src/router/sticky.rs b/src/router/sticky.rsindex f479f630..9af5cf35 100644--- a/src/router/sticky.rs+++ b/src/router/sticky.rs@@ -87,6 +87,17 @@ const CLOSERS: &[&str] = &["shall i continue","should i keep going","let me know",+ "help further",+ "help you further",+ "anything further",+ "need more help",+ "need any more help",+ "need further help",+ "any other questions",+ "else i can help",+ "else i can do",+ "else can i help",+ "else can i do",];fn is_closer(question: &str) -> bool {@@ -229,6 +240,13 @@ mod tests {"Is there anything else I can help you with today?","Would you like me to also send it to the team?","Shall I continue?",+ "Happy to help further?",+ "Here's the chart.\n\nNeed anything else?",+ "Can I help you further with this?",+ "Need any more help with the chart?",+ "Any other questions?",+ "Is there something else I can help with?",+ "What else can I do for you?",] {assert_eq!(after(closer), None, "{closer:?}");}diff --git a/src/server/auth.rs b/src/server/auth.rsindex c910440a..4f025577 100644--- a/src/server/auth.rs+++ b/src/server/auth.rs@@ -330,9 +330,10 @@ pub fn person_only(method: &Method, path: &str) -> bool {["", "api", "signin", ..] => true,// Web Push: where the person's notifications go["", "api", "push", ..] => true,- // App-wide settings, including where notifications go (`notify_webhook_url`): bots change- // the allowed ones through their `settings_update` action, never this route- ["", "api", "settings"] => *method != Method::GET && *method != Method::HEAD,+ // App-wide settings, including where notifications go (`notify_webhook_url`), and the+ // sub-routes such as `/computer` (which machine the bots run on) and `/computer/window`:+ // bots change the allowed ones through their `settings_update` action, never these routes+ ["", "api", "settings", ..] => *method != Method::GET && *method != Method::HEAD,["", "api", "approvals", _, "resolve"] => *method == Method::POST,["", "api", "spaces" | "kwants", _, "approvals"] => *method != Method::GET && *method != Method::HEAD,["", "api", "kwants" | "teams", _] => *method == Method::DELETE,@@ -847,6 +848,10 @@ mod tests {assert!(person_only(&post, "/api/settings"));assert!(person_only(&put, "/api/settings/"));assert!(!person_only(&get, "/api/settings"));+ assert!(person_only(&put, "/api/settings/computer"));+ assert!(person_only(&put, "/api/settings/computer/"));+ assert!(person_only(&put, "/api/settings/computer/window"));+ assert!(!person_only(&get, "/api/settings/computer"));assert!(!person_only(&get, "/api/approvals"));assert!(!person_only(&get, "/api/sandbox/t1/status"));assert!(!person_only(&get, "/api/kwants"));diff --git a/tests/bot_actions_test.rs b/tests/bot_actions_test.rsindex 4e9b8903..99eef37c 100644--- a/tests/bot_actions_test.rs+++ b/tests/bot_actions_test.rs@@ -697,3 +697,55 @@ async fn settings_writes_are_person_only_but_bots_keep_settings_update() {let (_, s) = call(&e.app, "GET", "/api/settings", None, None).await;assert_eq!(s["location"], "Berlin");}++/// Lin's #71 follow-up: `PUT /api/settings/computer` (and `/computer/window`) took a bot's turn+/// token, so a bot's shell could move every bot between this computer and the VM. Bots never had+/// a legitimate way to do that (`settings_update` refuses `computer_mode`); now the routes are+/// person-only too, and reading the choice stays open.+#[tokio::test]+async fn computer_choice_is_person_only() {+ let e = setup().await;+ let token = turn(&e, "t-computer-route").await;+ let (status, view) = call(&e.app, "GET", "/api/settings/computer", Some(&token), None).await;+ assert_eq!(status, StatusCode::OK, "a bot still reads the choice: {view}");+ let before = e.state.db.get_setting("computer_mode").await.unwrap();++ for (uri, body) in [+ ("/api/settings/computer", json!({"mode": "vm"})),+ ("/api/settings/computer", json!({"mode": "local"})),+ ("/api/settings/computer/window", json!({"visible": true})),+ ] {+ let (status, v) = call(&e.app, "PUT", uri, Some(&token), Some(body.clone())).await;+ assert_eq!(status, StatusCode::FORBIDDEN, "{uri} {body} with a bot's turn token: {v}");+ }+ assert_eq!(e.state.db.get_setting("computer_mode").await.unwrap(), before, "nothing changed");+ refused(&e, &token, "settings_update", json!({"settings": {"computer_mode": "local"}})).await;++ // From another machine with no token: 401+ let req = Request::builder()+ .method("PUT")+ .uri("/api/settings/computer")+ .header("content-type", "application/json")+ .header("host", "kwnt.example.com")+ .body(Body::from(json!({"mode": "vm"}).to_string()))+ .unwrap();+ assert_eq!(e.app.clone().oneshot(req).await.unwrap().status(), StatusCode::UNAUTHORIZED);++ // The person's token gets past the guard to the handler (a bad mode is the handler's 400;+ // saving a real mode is covered in computer_mode_test.rs, which switches the browser)+ let person = e.state.api_token.reveal();+ let (status, v) = call(&e.app, "PUT", "/api/settings/computer", Some(person), Some(json!({"mode": "mars"}))).await;+ assert_eq!(status, StatusCode::BAD_REQUEST, "{v}");+ let (status, v) = call(&e.app, "PUT", "/api/settings/computer/window", Some(person), Some(json!({"visible": "yes"}))).await;+ assert_eq!(status, StatusCode::BAD_REQUEST, "{v}");+ // And the person's cookie from another machine+ let req = Request::builder()+ .method("PUT")+ .uri("/api/settings/computer")+ .header("content-type", "application/json")+ .header("host", "kwnt.example.com")+ .header("cookie", format!("kwnt_token={person}"))+ .body(Body::from(json!({"mode": "mars"}).to_string()))+ .unwrap();+ assert_eq!(e.app.clone().oneshot(req).await.unwrap().status(), StatusCode::BAD_REQUEST, "past the guard, into the handler");+}