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
18c: the island's Allow once closes the deny-list gaps still allowed after 253bacc9 (#672)
Oleksandr Ivanchenkoe82f92a46a4e
diff --git a/src/server/glance.rs b/src/server/glance.rsindex a661b881..4ee89a31 100644--- a/src/server/glance.rs+++ b/src/server/glance.rs@@ -97,6 +97,15 @@ pub fn app_path(space: &str, link: &Value, kwant_id: &str, card: Option<&str>) -/// [`mcp_writes`]: super::dev::prepush::mcp_writesconst PUSH_WORDS: &[&str] = &["MERGE", "PUSH", "UPDATE_BRANCH", "UPDATE_A_REFERENCE", "UPDATE_REF", "CREATE_A_REFERENCE", "DELETE_A_REFERENCE", "RELEASE"];+/// Whole words of a tool name ([`words`]) that make a commit or a branch: `commit_files`,+/// `create_commit`, `create_branch`, `GITHUB_CREATE_A_BRANCH` (18c, Rigel's B55–B56). Whole words, so+/// `list_branches` and `list_commits` stay out, and a name with a [`READ_VERBS`] word+/// (`get_commit`, `GITHUB_GET_A_BRANCH`) only reads.+const COMMIT_NAME_WORDS: &[&str] = &["commit", "branch"];++/// Whole words of a tool name that only read; they keep [`COMMIT_NAME_WORDS`] from refusing.+const READ_VERBS: &[&str] = &["get", "list", "search", "read", "view", "show", "describe", "find", "compare"];+/// Parts of a tool or server name (any case) that mark a tool taking free text to run: a command,/// a script, code or a query. A one-line peek can't show what that text does, and a list of bad/// commands is never complete, so all of them need the full card.@@ -112,7 +121,13 @@ const RUNS_TEXT_KEY_PARTS: &[&str] = &["command", "cmd", "shell", "exec", "argv"/// Whole words of an argument key (split at `_`, `-`, camelCase) that carry a script. Not by/// containment, which would catch `description`, `subscription` and `transcript`.-const RUNS_TEXT_KEY_WORDS: &[&str] = &["script", "scripts", "javascript", "applescript", "stdin"];+///+/// 18c (Rigel's B10–B13, B17, B52–B53, H06–H08): a command typed under `input`, `line`,+/// `statement`, `code_snippet` or `arguments_list` on a tool whose name says nothing.+const RUNS_TEXT_KEY_WORDS: &[&str] = &[+ "script", "scripts", "javascript", "applescript", "stdin", //+ "input", "inputs", "line", "lines", "statement", "statements", "snippet", "snippets", "args", "arguments",+];/// HTTP verbs that change something, in a `method` argument (any depth, any case).const WRITE_METHODS: &[&str] = &["DELETE", "PUT", "PATCH", "POST"];@@ -131,12 +146,27 @@ const OUTWARD_NAMES: &[&str] = &["PUBLISH", "DEPLOY", "SEND", "EMAIL", "MAIL", "DELETE", "REMOVE", "DESTROY", "DROP", "POST", "PAY",// 0.9.14 (Rigel's hole 3)"TRANSFER", "SUBMIT", "TWEET", "SHARE", "INVITE", "FORWARD", "UPLOAD", "WIPE", "TERMINATE", "REVOKE", "PURCHASE",+ // 18c (Rigel's B34)+ "BROADCAST",];+/// Whole words of a tool name ([`words`]) that act outside kwant but sit inside ordinary words as+/// parts (`ship` in `membership`, `relationship`), so they can't join [`OUTWARD_NAMES`]: `ship_it`,+/// `rollout` (18c, Rigel's B54).+const OUTWARD_NAME_WORDS: &[&str] = &["ship", "rollout"];++/// Whole words in the value of an `action`, `operation` or `op` argument ([`is_action_key`]) that+/// change or destroy something (18c, Rigel's H01–H02): the [`WRITE_METHODS`] verbs, plus these.+const ACTION_WRITE_WORDS: &[&str] = &["delete", "put", "patch", "post", "remove", "destroy", "drop", "purge", "wipe", "truncate", "erase"];++/// Argument keys (flattened, [`flat`]) that carry a request body; on an HTTP-shaped call with no+/// method key, such a key means the tool sends it, usually as a POST (18c, Rigel's H04).+const BODY_KEYS: &[&str] = &["body", "data", "json", "payload", "form", "formdata", "requestbody", "postdata", "jsonbody"];+pub const PUSHES: &str = "This pushes code, so it needs the full card.";pub const RUNS: &str = "This runs a command, so it needs the full card.";pub const RISKY: &str = "kwant flagged this step as risky.";-const OUTWARD: &str = "This acts outside kwant, so it needs the full card.";+pub const OUTWARD: &str = "This acts outside kwant, so it needs the full card.";/// Every argument key and string value, at any depth, in document order (array items in turn).fn texts<'a>(v: &'a Value, out: &mut Vec<&'a str>) {@@ -215,18 +245,38 @@ fn has_push_word(text: &str) -> bool {PUSH_FAMILY.iter().any(|phrase| words.windows(phrase.len()).any(|w| w.iter().zip(phrase.iter()).all(|(a, b)| a == b)))}-/// Whether the arguments ask for an HTTP verb that changes something. A `method` key (any depth;-/// `method`, `http_method`, `httpMethod`, `verb`) whose value is one of [`WRITE_METHODS`] always-/// does. On an HTTP-shaped call (a `url`, `uri` or `endpoint` key anywhere) a method that isn't a-/// plain [`READ_METHODS`] string does too: `CONNECT`, a made-up verb, a list or a number.+/// Whether a flattened argument key names an HTTP verb: `method`, `http_method`, `httpMethod`,+/// `verb`, `request_verb` (18c, H03), or an `X-HTTP-Method-Override` header (18c, H05).+fn is_method_key(f: &str) -> bool {+ f.ends_with("method") || f.ends_with("verb") || f.contains("methodoverride")+}++/// Whether a flattened argument key names what a generic tool does: `action`, `operation`, `op`+/// (18c, H01–H02). Exact, so `transaction` and `cooperation` stay out.+fn is_action_key(f: &str) -> bool {+ matches!(f, "action" | "operation" | "op")+}++/// Whether the arguments ask for an HTTP verb that changes something. A method key at any depth+/// ([`is_method_key`]) whose value is one of [`WRITE_METHODS`] always does. On an HTTP-shaped call+/// (a `url`, `uri` or `endpoint` key anywhere) a method that isn't a plain [`READ_METHODS`] string+/// does too: `CONNECT`, a made-up verb, a list or a number. An action key ([`is_action_key`]) whose+/// value has an [`ACTION_WRITE_WORDS`] word does (`delete`, `DELETE`, `remove_item`). And an+/// HTTP-shaped call with a body ([`BODY_KEYS`]) but no method key at all does, since such tools+/// send it as a POST.fn writes_by_method(args: &Value) -> bool {let http = any_key(args, &|k, _| {let f = flat(k);f == "uri" || f == "endpoint" || f.ends_with("url")});- any_key(args, &|k, v| {+ let by_key = any_key(args, &|k, v| {let f = flat(k);- if !(f.ends_with("method") || f == "verb" || f == "httpverb") {+ if is_action_key(&f) {+ let mut all = Vec::new();+ texts(v, &mut all);+ return words(&all.join(" ")).iter().any(|w| ACTION_WRITE_WORDS.contains(&w.as_str()));+ }+ if !is_method_key(&f) {return false;}match v.as_str() {@@ -236,7 +286,11 @@ fn writes_by_method(args: &Value) -> bool {}None => http && !v.is_null(),}- })+ });+ by_key+ || (http+ && !any_key(args, &|k, _| is_method_key(&flat(k)))+ && any_key(args, &|k, v| !v.is_null() && BODY_KEYS.contains(&flat(k).as_str())))}/// Why an approval may only be answered on its full card, from its stored details alone; `None`@@ -251,8 +305,10 @@ fn writes_by_method(args: &Value) -> bool {/// value, as a whole word, camelCase humps included ([`words`]);/// 2. a tool that runs free text: its tool or server name says so ([`RUNS_TEXT_NAMES`]) or an/// argument key at any depth does ([`is_run_key`]: exact, by containment, or by word);-/// 3. a tool whose name acts outside kwant or destroys something ([`OUTWARD_NAMES`]);-/// 4. an HTTP verb that changes something in a `method` argument ([`writes_by_method`]).+/// 3. a tool whose name acts outside kwant or destroys something ([`OUTWARD_NAMES`], or a whole+/// word of [`OUTWARD_NAME_WORDS`]);+/// 4. an HTTP verb that changes something in a method or action argument, or a body sent to a URL+/// with no method ([`writes_by_method`]).pub fn inline_refusal(details: &Value) -> Option<&'static str> {if !details.is_object() {return Some("Open it to see what it does.");@@ -282,7 +338,7 @@ pub fn inline_refusal(details: &Value) -> Option<&'static str> {return Some(RUNS);}// 3. Acts outside kwant or destroys something- if OUTWARD_NAMES.iter().any(|w| upper.contains(w)) {+ if OUTWARD_NAMES.iter().any(|w| upper.contains(w)) || words(tool).iter().any(|w| OUTWARD_NAME_WORDS.contains(&w.as_str())) {return Some(OUTWARD);}// 4. An HTTP call that changes something, whatever the tool is called@@ -294,7 +350,8 @@ pub fn inline_refusal(details: &Value) -> Option<&'static str> {/// A risky step or the push floor, from the details alone: a step smart approvals flagged/// ([`RISKY`]); a prepush grant, a strict ask, a GitHub write [`mcp_writes`] sees, or a-/// [`PUSH_WORDS`] part in the tool name ([`PUSHES`]). The first layers of [`inline_refusal`], in its+/// [`PUSH_WORDS`] part in the tool name, or a [`COMMIT_NAME_WORDS`] word in a name with no+/// [`READ_VERBS`] word ([`PUSHES`]). The first layers of [`inline_refusal`], in its/// order.////// [`mcp_writes`]: super::dev::prepush::mcp_writes@@ -314,6 +371,11 @@ fn ships(details: &Value) -> Option<&'static str> {if PUSH_WORDS.iter().any(|w| upper.contains(w)) {return Some(PUSHES);}+ let name = words(tool);+ let has = |list: &[&str]| name.iter().any(|w| list.contains(&w.as_str()));+ if has(COMMIT_NAME_WORDS) && !has(READ_VERBS) {+ return Some(PUSHES);+ }None}@@ -329,7 +391,8 @@ const TELEGRAM_RUN_KEYS: &[&str] = &["command", "cmd", "argv", "script", "sql"];/// is exactly one of [`TELEGRAM_RUN_KEYS`] ([`RUNS`]). Whatever it refuses,/// [`inline_refusal`] refuses too; the island's other layers (outward names, HTTP verbs, push words/// inside values, the broad run keys) stay off Telegram on purpose, so an email that says-/// "press release" keeps Allow once there.+/// "press release" keeps Allow once there. Since 18c [`ships`] also refuses a tool named for a+/// commit or a branch (`create_commit`, `create_branch`), so Telegram refuses those too.pub fn ships_or_runs(details: &Value) -> Option<&'static str> {if let Some(why) = ships(details) {return Some(why);diff --git a/tests/glance_test.rs b/tests/glance_test.rsindex e7495214..9e80c1a9 100644--- a/tests/glance_test.rs+++ b/tests/glance_test.rs@@ -600,8 +600,8 @@ async fn thirty_busy_spaces_glance_quickly() {assert!(f50 < 1000.0, "{f50} ms");}-/// Rigel's round-2 risk-4 rows (#646) plus one row per 0.9.14 rule, read back through-/// `GET /api/glance`: twenty-three steps that must never get Allow once inline, and four ordinary+/// Rigel's round-2 risk-4 rows (#646) plus one row per 0.9.14 and 18c rule, read back through+/// `GET /api/glance`: twenty-seven steps that must never get Allow once inline, and four ordinary/// ones that still do.#[tokio::test]async fn risky_steps_never_get_allow_once_and_ordinary_ones_still_do() {@@ -634,6 +634,11 @@ async fn risky_steps_never_get_allow_once_and_ordinary_ones_still_do() {("key pushToOrigin", mcp("notes", "save_note", json!({"pushToOrigin": true})), false),("transfer_funds", mcp("bank", "transfer_funds", json!({})), false),("method DELETE", mcp("http", "http_request", json!({"url": "https://api.example.com/items/1", "method": "DELETE"})), false),+ // 18c, one row per new rule+ ("key input", mcp("x", "do", json!({"input": "git reset --hard HEAD~5"})), false),+ ("tool create_branch", mcp("gh", "create_branch", json!({"branch": "x"})), false),+ ("action delete", mcp("linear", "manage_issue", json!({"action": "delete", "id": "A-1"})), false),+ ("a URL with a body and no method", mcp("http", "fetch", json!({"url": "https://api.example.com/items/1", "body": {"a": 1}})), false),("method GET", mcp("http", "http_request", json!({"url": "https://api.example.com/items/1", "method": "GET"})), true),("a file write inside the bot's folder",@@ -643,7 +648,7 @@ async fn risky_steps_never_get_allow_once_and_ordinary_ones_still_do() {("a read-only fetch", mcp("fetch", "fetch", json!({"url": "https://example.com/docs", "max_length": 5000})), true),("a page that mentions Pushkin", mcp("notion", "create_page", json!({"title": "Pushkin reading list", "parent": {"page_id": "abc"}})), true),];- assert_eq!(rows.iter().filter(|r| !r.2).count(), 23);+ assert_eq!(rows.iter().filter(|r| !r.2).count(), 27);let person = |body: Value| Req { body: Some(body), remote: true, cookie: Some(TOKEN), ..Default::default() };// Ten at a time keeps them under the Needs-you cap; each batch is denied before the nextfor batch in rows.chunks(10) {@@ -665,3 +670,72 @@ async fn risky_steps_never_get_allow_once_and_ordinary_ones_still_do() {}}}++/// 18c: every row Rigel's r10/r11 still allowed at 253bacc9 ("Still allowed after 253bacc9" in+/// desktop-island/qa-server-review.md), with the reason the island now gives, and the steps that+/// must keep Allow once. Same details as his probes. The Telegram column is `ships_or_runs`: only+/// the commit and branch names reach Telegram's floor; the rest stay island-only, as 18b chose.+#[test]+fn the_rows_still_allowed_after_253bacc9_now_need_the_full_card() {+ use kwnt::server::glance::{inline_refusal, ships_or_runs, OUTWARD, PUSHES, RUNS};+ let mcp = |server: &str, tool: &str, args: Value| json!({"source": "mcp", "server": server, "tool": tool, "arguments": args});+ let url = "https://api.example.com/items/1";+ // (row, details, island reason, Telegram's floor)+ type Row = (&'static str, Value, &'static str, Option<&'static str>);+ let rows: Vec<Row> = vec![+ // Command text under keys no older rule read+ ("B10 input, quoted push", mcp("x", "do", json!({"input": "git pu''sh origin main"})), RUNS, None),+ ("B11 input, base64", mcp("x", "do", json!({"input": "echo Z2l0IHB1c2g= | base64 -d | sh"})), RUNS, None),+ ("B12 input, env-var split", mcp("x", "do", json!({"input": "p=pu; git ${p}sh origin main"})), RUNS, None),+ ("B13 line, rm -rf", mcp("x", "do", json!({"line": "rm -rf /home"})), RUNS, None),+ ("B17 statement on invoke", mcp("x", "invoke", json!({"statement": "DROP TABLE users"})), RUNS, None),+ ("B52 input, gh pr close", mcp("x", "do", json!({"input": "gh pr close 5"})), RUNS, None),+ ("B53 input, git reset --hard", mcp("x", "do", json!({"input": "git reset --hard HEAD~5"})), RUNS, None),+ ("H06 code_snippet", mcp("x", "do", json!({"code_snippet": "import os; os.system('x')"})), RUNS, None),+ ("H07 arguments_list", mcp("x", "do", json!({"arguments_list": ["rm", "-rf", "/"]})), RUNS, None),+ ("H08 statement, nested", mcp("x", "invoke", json!({"q": {"statement": "DROP TABLE users"}})), RUNS, None),+ // Tool names+ ("B34 broadcast", mcp("x", "broadcast", json!({})), OUTWARD, None),+ ("B54 ship_it", mcp("x", "ship_it", json!({"env": "prod"})), OUTWARD, None),+ ("B54 rollout", mcp("x", "rollout", json!({})), OUTWARD, None),+ ("B55 commit_files", mcp("gh", "commit_files", json!({"branch": "main"})), PUSHES, Some(PUSHES)),+ ("B56 create_commit", mcp("gh", "create_commit", json!({"message": "m"})), PUSHES, Some(PUSHES)),+ ("B56 create_branch", mcp("gh", "create_branch", json!({"branch": "x"})), PUSHES, Some(PUSHES)),+ ("B56 GITHUB_CREATE_A_BRANCH", mcp("composio", "GITHUB_CREATE_A_BRANCH", json!({})), PUSHES, Some(PUSHES)),+ // Verbs under other keys, and a body with no verb+ ("H01 action: delete", mcp("linear", "manage_issue", json!({"action": "delete", "id": "A-1"})), OUTWARD, None),+ ("H02 operation: DELETE", mcp("x", "do", json!({"operation": "DELETE", "id": "1"})), OUTWARD, None),+ ("H02 op: remove_item", mcp("x", "do", json!({"op": "remove_item"})), OUTWARD, None),+ ("H03 request_verb DELETE", mcp("http", "fetch", json!({"url": url, "request_verb": "DELETE"})), OUTWARD, None),+ ("H04 URL + body, no method", mcp("http", "fetch", json!({"url": url, "body": {"a": 1}})), OUTWARD, None),+ ("H04 URL + json, no method", mcp("http", "fetch", json!({"url": url, "json": "{}"})), OUTWARD, None),+ ("H05 X-HTTP-Method-Override", mcp("http", "fetch", json!({"url": url, "method": "GET", "headers": {"X-HTTP-Method-Override": "DELETE"}})), OUTWARD, None),+ ];+ assert_eq!(rows.len(), 24);+ for (name, d, why, telegram) in &rows {+ assert_eq!(inline_refusal(d), Some(*why), "{name}");+ assert_eq!(ships_or_runs(d), *telegram, "{name}: Telegram");+ }++ // Still Allow once: the brief's keep-inline steps, and the near misses of each new rule+ let keep: Vec<(&str, Value)> = vec![+ ("a Write in the bot's folder", json!({"source": "claude_builtin", "tool": "Write", "outside_folder": false, "arguments": {"file_path": "notes/todo.md", "content": "Buy milk\nCall Ana"}})),+ ("a fetch of a URL", mcp("fetch", "fetch", json!({"url": "https://example.com/docs", "max_length": 5000}))),+ ("a GET of a URL", mcp("http", "fetch", json!({"url": url, "method": "GET"}))),+ ("Notion Pushkin reading list", mcp("notion", "create_page", json!({"title": "Pushkin reading list", "parent": {"page_id": "abc"}}))),+ ("description + transcript_id", mcp("linear", "create_issue", json!({"description": "x", "transcript_id": "t"}))),+ ("method median, not HTTP", mcp("stats", "summarize", json!({"method": "median"}))),+ // near misses+ ("get_commit reads", mcp("github", "get_commit", json!({"sha": "abc"}))),+ ("list_commits / list_branches read", mcp("github", "list_branches", json!({"repo": "r"}))),+ ("GITHUB_GET_A_BRANCH reads", mcp("composio", "GITHUB_GET_A_BRANCH", json!({"branch": "main"}))),+ ("membership is not ship", mcp("x", "get_membership", json!({}))),+ ("a transaction key is not an action", mcp("ledger", "summarize", json!({"transaction": "delete me"}))),+ ("action: summarize", mcp("x", "do", json!({"action": "summarize"}))),+ ("a body with no URL", mcp("notes", "save_note", json!({"body": "x"}))),+ ("headline / deadline keys", mcp("notion", "create_page", json!({"headline": "x", "deadline": "Fri"}))),+ ];+ for (name, d) in &keep {+ assert_eq!(inline_refusal(d), None, "{name}");+ }+}