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.

Sign-in screen: say a token must come from the machine running kwant

Pixel (kwant bot)62279dc161bb
diff --git a/README.md b/README.md
index 72a89272..d75d01c2 100644
--- a/README.md
+++ b/README.md
@@ -96,7 +96,7 @@ scp target/release/kwnt user@your-vps:/usr/local/bin/kwnt
ssh user@your-vps "kwnt serve --host 0.0.0.0 --port 8799"
```
-On your own computer there is nothing to sign in to. From another machine, open the link `kwnt serve` prints at startup once (`http://<this-host>:8799/#kwnt_token=...`, with `<this-host>` swapped for the server's address); the browser stays signed in for a year. Lost it? On the server, as the user that runs kwnt, `cat ~/.kwnt/api-token` (or `$KWNT_DATA_DIR/api-token`, e.g. `sudo cat /var/lib/kwnt/api-token` with the systemd unit below) prints the token to paste, and `kwnt token` the link (`./target/release/kwnt token` if kwnt isn't on your PATH). Run them as another user and you get that user's token, which the server doesn't accept. Or skip sign-in: `ssh -N -L 8799:127.0.0.1:8799 user@your-vps`, then open http://127.0.0.1:8799 on your computer (not with Docker, where requests always count as remote). The link signs in as you, so anyone who can read the server's output can use it. Put a TLS reverse proxy in front: see [browser service and VPS hosting](docs/browser-service.md).
+On your own computer there is nothing to sign in to. From another machine, open the link `kwnt serve` prints at startup once (`http://<this-host>:8799/#kwnt_token=...`, with `<this-host>` swapped for the server's address); the browser stays signed in for a year. Lost it? On the server, as the user that runs kwnt, `cat ~/.kwnt/api-token` (or `$KWNT_DATA_DIR/api-token`, e.g. `sudo cat /var/lib/kwnt/api-token` with the systemd unit below) prints the token to paste, and `kwnt token` the link (`./target/release/kwnt token` if kwnt isn't on your PATH). Run them as another user and you get that user's token, which the server doesn't accept. Each install has its own token, so one copied from your laptop won't open kwnt on the server. Or skip sign-in: `ssh -N -L 8799:127.0.0.1:8799 user@your-vps`, then open http://127.0.0.1:8799 on your computer (not with Docker, where requests always count as remote). The link signs in as you, so anyone who can read the server's output can use it. Put a TLS reverse proxy in front: see [browser service and VPS hosting](docs/browser-service.md).
<details>
<summary>A systemd unit</summary>
diff --git a/docs/llm-profiles.md b/docs/llm-profiles.md
index 2fd23734..88d339c2 100644
--- a/docs/llm-profiles.md
+++ b/docs/llm-profiles.md
@@ -78,7 +78,8 @@ with Docker) can use it.
`kwnt token --raw` just the token, for scripts, which send `Authorization: Bearer <token>`. The token
lives in `<data_dir>/api-token` (mode 0600), or set `KWNT_API_TOKEN` (16+ characters). Run `kwnt token` as the
user that runs `kwnt serve` (`./target/release/kwnt` from a source build without kwnt on the `PATH`):
-as any other user it creates and prints that user's own token, which the server doesn't accept. The
+as any other user it creates and prints that user's own token, which the server doesn't accept. Each
+install has its own token, so a token from another computer won't work either. The
sign-in screen asks where kwant runs (a server, Docker, or this computer) and shows the matching steps.
Person-only routes (saved passwords and the vault, answering approval cards, the approvals switch,
diff --git a/frontend/src/components/AuthGate.tsx b/frontend/src/components/AuthGate.tsx
index 1e3a2f49..9de58e62 100644
--- a/frontend/src/components/AuthGate.tsx
+++ b/frontend/src/components/AuthGate.tsx
@@ -306,7 +306,10 @@ export const TokenSteps: React.FC<{ place: TokenPlace; hostname: string; port: s
);
};
-const TokenForm: React.FC<{ notice: string | null; onSignedIn: () => void; personOnly?: boolean; onCancel?: () => void }> = ({
+/** Shown when the server rejects a pasted token. Exported for tests. */
+export const WRONG_TOKEN = "That token isn't right. It has to come from the machine running kwant bots, as the user running it.";
+
+export const TokenForm: React.FC<{ notice: string | null; onSignedIn: () => void; personOnly?: boolean; onCancel?: () => void }> = ({
notice,
onSignedIn,
personOnly = false,
@@ -331,7 +334,7 @@ const TokenForm: React.FC<{ notice: string | null; onSignedIn: () => void; perso
onSignedIn();
return;
}
- setError("That token isn't right. Copy it again with the steps above, as the user that runs kwant bots.");
+ setError(WRONG_TOKEN);
} catch (err) {
setError(err instanceof Error && err.message !== 'Failed to fetch' ? err.message : 'Could not reach the server.');
} finally {
@@ -381,6 +384,9 @@ const TokenForm: React.FC<{ notice: string | null; onSignedIn: () => void; perso
<label htmlFor="kwnt-token" className="block text-xs font-medium text-zinc-400 mb-1">
Token
</label>
+ <p id="kwnt-token-hint" className="text-[11px] text-zinc-500 leading-snug mb-1.5">
+ Each install has its own token, so a token copied from another computer won't work here.
+ </p>
<input
id="kwnt-token"
type="password"
@@ -390,7 +396,7 @@ const TokenForm: React.FC<{ notice: string | null; onSignedIn: () => void; perso
value={token}
onChange={(e) => setToken(e.target.value)}
aria-invalid={!!error}
- aria-describedby={error ? 'kwnt-token-error' : undefined}
+ aria-describedby={error ? ['kwnt-token-hint', 'kwnt-token-error'].join(' ') : 'kwnt-token-hint'}
className="w-full bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs font-mono text-zinc-100 placeholder-zinc-600 focus:border-sky-500 focus:outline-none transition-colors"
placeholder="Paste the token or the sign-in link"
/>
diff --git a/frontend/tests/tokenSteps.test.mjs b/frontend/tests/tokenSteps.test.mjs
index 665b041f..2936e8ec 100644
--- a/frontend/tests/tokenSteps.test.mjs
+++ b/frontend/tests/tokenSteps.test.mjs
@@ -6,8 +6,9 @@ import { loadBundled } from './bundle.mjs';
const m = await loadBundled(`
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server.browser';
- import { TokenSteps, guessPlace, tokenFromPaste } from './src/components/AuthGate';
- export { guessPlace, tokenFromPaste };
+ import { TokenForm, TokenSteps, WRONG_TOKEN, guessPlace, tokenFromPaste } from './src/components/AuthGate';
+ export { WRONG_TOKEN, guessPlace, tokenFromPaste };
+ export const form = () => renderToStaticMarkup(React.createElement(TokenForm, { notice: null, onSignedIn: () => {} }));
export const steps = (place, hostname = 'vps.example.com', port = '8799') =>
renderToStaticMarkup(React.createElement(TokenSteps, { place, hostname, port }));
`);
@@ -53,3 +54,10 @@ test('pasting the whole sign-in link works as well as the token', () => {
assert.equal(m.tokenFromPaste('http://1.2.3.4:8799/#kwnt_token=abc123def456abc123'), 'abc123def456abc123');
assert.equal(m.tokenFromPaste('http://<this-host>:8799/#kwnt_token=tok'), 'tok');
});
+
+test('a token from another computer: the screen and the error say where it has to come from', () => {
+ assert.match(m.WRONG_TOKEN, /machine running kwant bots, as the user running it/);
+ const html = m.form();
+ assert.match(text(html), /a token copied from another computer won't work here/);
+ assert.match(html, /aria-describedby="kwnt-token-hint"/);
+});
diff --git a/site-src/docs-install.html b/site-src/docs-install.html
index a0839a7e..7158ba02 100644
--- a/site-src/docs-install.html
+++ b/site-src/docs-install.html
@@ -33,6 +33,7 @@ ssh user@your-vps "kwnt serve --host 0.0.0.0 --port 8799"</code></pre>
<ul>
<li><strong>Lost the link?</strong> On the server, as the user that runs kwnt, <code>kwnt token</code> prints it again, and <code>cat ~/.kwnt/api-token</code> prints the token to paste on the sign-in screen. With the systemd unit below that's <code>sudo cat /var/lib/kwnt/api-token</code>. Built from source and kwnt isn't on your <code>PATH</code>? Use <code>./target/release/kwnt token</code> from the source folder.</li>
<li><strong>Same user:</strong> run as another user, <code>kwnt token</code> makes and prints that user's own token, which the server doesn't accept.</li>
+ <li><strong>Same machine:</strong> each install has its own token. A token from your laptop won't open kwnt on your server. Get it on the server.</li>
<li><strong>Scripts:</strong> <code>kwnt token --raw</code> prints just the token, to send as <code>Authorization: Bearer &lt;token&gt;</code>.</li>
<li>The token lives in <code>&lt;data dir&gt;/api-token</code> (mode 0600), or set <code>KWNT_API_TOKEN</code> (16+ characters).</li>
</ul>
diff --git a/site/docs/install.html b/site/docs/install.html
index 4bafce2b..f7f1ccf7 100644
--- a/site/docs/install.html
+++ b/site/docs/install.html
@@ -82,6 +82,7 @@ ssh user@your-vps "kwnt serve --host 0.0.0.0 --port 8799"</code></pre>
<ul>
<li><strong>Lost the link?</strong> On the server, as the user that runs kwnt, <code>kwnt token</code> prints it again, and <code>cat ~/.kwnt/api-token</code> prints the token to paste on the sign-in screen. With the systemd unit below that's <code>sudo cat /var/lib/kwnt/api-token</code>. Built from source and kwnt isn't on your <code>PATH</code>? Use <code>./target/release/kwnt token</code> from the source folder.</li>
<li><strong>Same user:</strong> run as another user, <code>kwnt token</code> makes and prints that user's own token, which the server doesn't accept.</li>
+ <li><strong>Same machine:</strong> each install has its own token. A token from your laptop won't open kwnt on your server. Get it on the server.</li>
<li><strong>Scripts:</strong> <code>kwnt token --raw</code> prints just the token, to send as <code>Authorization: Bearer &lt;token&gt;</code>.</li>
<li>The token lives in <code>&lt;data dir&gt;/api-token</code> (mode 0600), or set <code>KWNT_API_TOKEN</code> (16+ characters).</li>
</ul>