Skip to content

armgit / kwant

Public Imported from GitHub
0

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.

12.9 KB
Raw Blame

Approvals

Each space has an approvals mode, and each bot can override it (inherit follows the space). Only the person changes it: PUT /api/spaces/:id/approvals and PUT /api/kwants/:id/approvals with {"approvals": "ask" | "smart" | "off"} (a bot also takes inherit). Bots' own tools refuse it.

Mode UI label What happens
ask Ask before running commands Every tool call outside the bot's folder shows an approval card.
smart (default for new spaces) Ask only when risky Ordinary work runs without a card; anything risky or unclear shows the card, with the reason.
off Don’t ask Everything runs, except payments: they always ask (see payments.md).

A new space, and a fresh install's Default space, start on smart. A space made before that default (it has no approvals row) keeps asking after an upgrade, so updating kwnt never loosens an install; switch it in Settings when you're ready. While the built-in password store holds passwords, a new space starts on ask instead (see below). An unknown bot always asks.

Whatever the mode, a call that looks like a payment shows a card, even when smart finds it safe or "Always this session" was given: see payments.md. That includes paid generations: a FLUX (Black Forest Labs) or Picsart tool that spends the person's credits asks every time, and its card says whose credits it uses, without a price. Their reads (a balance, a job's status) don't ask.

Whatever the mode, on a Home Assistant MCP server (it answers initialize with serverInfo.name home-assistant), a call that acts on a lock, a door, a garage door, a gate or an alarm shows a card (since 0.9.21), approvals off included, the way payments do: a domain of lock or alarm_control_panel; cover with a device_class of garage, door or gate, or none; or any string argument (a name, an area, a schedule_command command) with the whole word lock, unlock, door, garage, gate, alarm or disarm, plurals too, in any case. "Always this session" on such a card, and an earlier one for the tool, cover that one call; the lights still run on their grant. Reads (tools the server marks read-only, and GetLiveContext) never ask for this. The card carries details.home_always_ask: true and details.home_reason ("Locks, doors, garage doors, gates and alarms always ask. Always allow isn’t offered for them."). What the server is comes from what it said on kwnt's own connections, stored at its test (POST /api/mcp/servers/:id/test) so it holds after a restart, never from its address; a server kwnt never heard from asks for these calls.

Whatever the mode, a call that names kwnt's own secret files (the vault, its key, the API token) is refused and recorded as denied. Calls that run without a card are recorded as auto_allowed (GET /api/approvals?status=auto_allowed); under smart the row's details.smart_reason says why it was safe (e.g. "runs inside the bot's folder and does nothing risky"), and a card's details.smart_reason says why it asked.

smart and off both need Bitwarden while the built-in password store holds passwords, unless the person accepts the risk once for the server (0.7.3): see saved-passwords.md.

smart is a guard against accidents, not a sandbox. Scripts in the bot's folder (./run.sh, bash x.sh, python data.py), make, cargo run/cargo build (build scripts), a bare npm install/npm ci (the packages the project already lists, and their install scripts) and npm run (package scripts) run without a card, and can do anything the bot's user can, including the network and kwnt's own API. That includes a script the bot wrote a moment earlier in the same turn. Choose ask for bots or folders you don't trust.

What smart runs without a card

  • Shell commands (claude's Bash, API drivers' execute_shell in Local mode) that src/mcp/shell_risk.rs finds safe in the bot's folder. It is an allowlist and fails closed: only programs it knows run (file and text tools like ls, cat, cp, mv, mkdir, sort, jq; build tools like cargo, npm, make, git with checks; programs inside the folder, except that a package manager there, like a venv's v/bin/pip or node_modules/.bin/npm, is judged by its name like any other), and anything else, or anything it can't read confidently, asks. It asks for:

    • $, $(…), backticks, unquoted ( ) { }, heredocs, newlines, eval, source, exec, shells with -c, a pipe into a shell, inline code (python -c, node -e, …);
    • wrappers other than env, command/builtin (-p too), nice, nohup, time, timeout, setsid, stdbuf, and wrapper options it doesn't know; the wrapped command is judged;
    • network tools (curl and wget run only for localhost/127.0.0.1 URLs with options from a short list: proxies -x/--proxy/--socks*, config files and @file ask), sudo/su, containers and cloud CLIs, mail senders, process and system tools, credential tools, xargs/parallel, env/printenv on their own;
    • git push, fetch, pull, clone, ls-remote, archive, remote other than -v/get-url/rename/remove, submodule other than status/summary/init, any git argument that is a URL or user@host:path, and git commands that touch global config or run a command (rebase -x/--exec, --upload-pack, ext::, grep -O, …); publish and login commands of npm/pnpm/yarn/bun/cargo/pip/uv/gem/poetry/twine/go; npx, bunx, npm exec/npm x, pnpm dlx, yarn dlx, bun x wherever the verb sits (npm --prefix x exec … too; a script named x asks as well, because npm run x looks like npm x; any other npm run script runs); starters (npm create vite, npm init vite, pnpm/yarn/bun create …; a bare npm init or npm init -y runs), deno run of a URL or npm:/jsr: spec, and uv run --with <pkg>, because they download and run package code;
    • adding a package the project doesn't list yet, because it downloads the package and runs its code (npm-style install scripts at once, the others when the project builds): npm install|i|add <pkg>, pnpm add|install <pkg>, yarn add <pkg>, bun add|install <pkg>, deno add|install <pkg>, cargo add <crate> (and --git), uv add <pkg> (and -r), poetry add <pkg>, go get <module>, dotnet add package <pkg>. The verb counts wherever it sits before a --, so an option kwnt doesn't know (npm --loglevel silent install x) or a workspace (yarn workspace app add x) can't hide it; that makes cargo test add x ask too. A package name, user/repo, github:… or a URL counts; a local path (npm install ./lib, cargo add --path ./x) is judged like any other path. Installing what the project already lists runs without a card: a bare npm install/npm i/npm ci, pnpm install, yarn/yarn install, bun install, deno install, with only options. pip and poetry always ask: every pip install (pip install -r requirements.txt too), uv pip install, uv pip sync and poetry install or add, even a bare one. So do gem install, go install and cargo install (they install outside the folder, or kwnt can't tell what they add). Updating packages the project already lists (npm update, pnpm up, yarn up, cargo update) runs without a card;
    • find -exec/-delete, sed scripts beyond print/delete/substitute (w, e, -f), awk programs that redirect print, pipe, read ENVIRON or call system/getline, and awk options other than -F/-v; tar options that run a program (--checkpoint-action, --to-command, -I, …) or a host:file archive; grep/rg options that run a program (--pre) or read a pattern file outside the folder (-f, -e stuck to its value is read correctly); sort --compress-program, zip -TT;
    • rm -r of the whole folder or of a wildcard straight under it (rm -rf ./*, rm -rf */);
    • any path argument, redirect target or cd that resolves outside the folder. Symlinks are followed, also for a plain name (cat link) and for links a wildcard could match; relative paths count from the folder after any cd; /dev/null is fine;
    • a leading VAR=value other than harmless names like RUST_LOG, CI, NODE_ENV.
  • Reads (Read, Glob, Grep, LS, NotebookRead) outside the folder, unless they touch:

    • live system data: /proc, /sys, /dev, /run (/proc/self/environ holds the gateway token);
    • the system's secrets: /etc/shadow*, /etc/gshadow, /etc/master.passwd, /etc/sudoers*, ssh host keys in /etc/ssh, /etc/ssl/private;
    • credentials, matched without regard to case: .ssh, .aws, .azure, .gnupg, .kube, .docker, .netrc, .pgpass, .vault-token, .claude, .codex, .cargo/credentials, .config/gh, .config/gcloud, password managers, browser profiles, keychains and keyrings, shell histories, .env* files, key files (.pem, .key, .p12, .kdbx, id_rsa, …) and files named credentials, secrets or token (the full list is in src/mcp/builtin_tools.rs);
    • for Grep and Glob, a search rooted at /, at a home folder or above one, or at a folder with any of the above (or a symlink, or more than 5,000 entries) somewhere below it.

    Paths are checked as written and with symlinks followed; relative paths count from the bot's folder, and a Glob/Grep root that is a symlink is judged where it points. A ~ path asks. A Glob's {a,b} alternatives are each checked (more than 64 ask). Input kwnt can't read (not an object, a path that is null, a number or a list, a Read with no file_path) asks under every mode; Grep/Glob/LS with no path search the folder, as before.

    Known gaps, left as they are: options that follow symlinks (grep -R, rg -L, find -L, ls -R, zip -r) run without a card, so a symlink already in the folder that points out of it can be read through them.

  • MCP tools the server marks readOnlyHint: true. As the MCP spec says, destructiveHint counts only when readOnlyHint is false, so a tool marked both (Home Assistant's reads, like GetLiveContext) runs too. That is the server's own claim. If kwnt can't check it, the call asks.

kwnt itself always asks. kwnt's person-only routes take no token from this computer, so a request to kwnt from a bot could turn approvals off or answer its own cards. A curl, wget or WebFetch to a loopback host (localhost, 127.x, 0.0.0.0, [::1], …) on kwnt's serve port, 8799 or 8800 (no port counts as 80/443), or to any loopback path starting with /api/ (after decoding %xx and working out ..), shows a card. For WebFetch this holds under ask too. Other local dev servers (localhost:3000, localhost:5173) still run.

Writes and edits outside the folder and unknown tools still ask. Under every mode, a Glob whose pattern is absolute, starts with ~ or contains .. counts as a read outside the folder.

"Always this session"

Under ask and smart, "Always this session" on a claude tool's card allows that tool (e.g. all Bash) for that bot and conversation, also after kwnt restarts (table always_allowed), until the person takes it back (DELETE /api/kwants/:id/always-allowed, see mcp-api.md). Under smart, API drivers' execute_shell is remembered the same way, per conversation; under ask it covers that one command only. Neither covers a payment or a Home Assistant lock, door or alarm, and "Always this session" on such a card allows that one call.

A no stays a no

When the person presses Deny, the bot is told not to try it again or another way, and for the rest of that conversation (a thread, else the channel or direct chat) kwnt refuses a call of the same family from that bot at once, with no card. A family is a shell program and its first subcommand (gh pr, git push), or a URL program and its host (curl to api.github.com); a file and whether it's read or written; a page's host; an MCP server's tool. Other built-in tools keep asking. The bot hears DECLINED_BEFORE_TEXT and the step shows as declined. It lasts until the person writes in that conversation again, and only in memory: a restart, another conversation or another bot asks as before. An unanswered card, a card its turn dropped, and kwnt's own refusals don't count, and a late Allow on an earlier card still runs that call (src/mcp/declined.rs). A Deny with a reason (the person says why on the card) isn't remembered: the bot hears the reason, may try the other way it points to, and that call gets its own card (29o).

Tests

cargo test --test smart_approvals_test --test approvals_off_test --test approvals_passwords_test --test payment_floor_test --test home_locks_always_ask_test --test mcp_media_test and the classifier tables in src/mcp/shell_risk.rs (cargo test --lib shell_risk); a no that stays a no: cargo test --lib declined.