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.

Settings UX: "What runs your kwants" summary, one account status vocabulary

Lin (kwant bot)8458637eb397
diff --git a/frontend/src/components/ClaudeSignIn.tsx b/frontend/src/components/ClaudeSignIn.tsx
index e45a7fb5..aa530734 100644
--- a/frontend/src/components/ClaudeSignIn.tsx
+++ b/frontend/src/components/ClaudeSignIn.tsx
@@ -199,7 +199,7 @@ export const ClaudeSignIn: React.FC<{ onSignedIn: () => void; focusRequest?: num
{busy === 'start' ? <Loader2 size={12} className="animate-spin motion-reduce:animate-none" aria-hidden="true" /> : <LogIn size={12} aria-hidden="true" />}
{busy === 'start' ? 'Starting…' : 'Sign in with Claude'}
</button>
- <span className="text-[10.5px] text-zinc-500">Opens claude.ai in a new tab.</span>
+ <span className="text-[10.5px] text-zinc-500">Opens claude.ai in a new tab, then you paste back a one-time code.</span>
</div>
)}
@@ -253,6 +253,9 @@ export const ClaudeSignIn: React.FC<{ onSignedIn: () => void; focusRequest?: num
Cancel
</button>
</div>
+ <p className="text-[10.5px] text-zinc-500 leading-snug">
+ Why a code? kwnt runs the sign-in in the background, so claude.ai can’t hand the login back by itself. The code works once and isn’t kept.
+ </p>
<p className="sr-only" role="status">
{state === 'verifying' ? 'Checking the code with Claude…' : ''}
</p>
diff --git a/frontend/src/components/EngineAccounts.tsx b/frontend/src/components/EngineAccounts.tsx
index 468e81b6..b8203243 100644
--- a/frontend/src/components/EngineAccounts.tsx
+++ b/frontend/src/components/EngineAccounts.tsx
@@ -1,8 +1,8 @@
import React, { useEffect, useRef, useState } from 'react';
-import { Check, Copy, ExternalLink, KeyRound, Loader2, LogIn, LogOut, Pencil, Plus, Star, Trash2 } from 'lucide-react';
+import { Check, ChevronDown, ChevronRight, Copy, ExternalLink, KeyRound, Loader2, LogIn, LogOut, Pencil, Plus, Star, Trash2 } from 'lucide-react';
import { playSfx } from '../audio/chiptune';
import type { EngineInfo, Tone } from '../engines';
-import { KIND_LABELS, Login, Profile, isLoginDone, newAccountFor, profileStatus, profilesApi, safeExternalUrl } from '../profiles';
+import { KIND_LABELS, Login, Profile, accountState, isLoginDone, isThirdPartyLabel, newAccountFor, profilesApi, safeExternalUrl } from '../profiles';
const input =
'w-full bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-100 placeholder-zinc-600 focus:border-sky-500 focus:outline-none transition-colors';
@@ -17,6 +17,7 @@ const PILL: Record<Tone, string> = {
error: 'border-rose-500/30 bg-rose-500/10 text-rose-200',
muted: 'border-zinc-700 bg-zinc-800/60 text-zinc-400',
busy: 'border-sky-500/30 bg-sky-500/10 text-sky-200',
+ info: 'border-cyan-500/30 bg-cyan-500/10 text-cyan-200',
};
const PILL_DOT: Record<Tone, string> = {
ok: 'bg-emerald-400',
@@ -24,6 +25,7 @@ const PILL_DOT: Record<Tone, string> = {
error: 'bg-rose-400',
muted: 'bg-zinc-500',
busy: 'bg-sky-400 animate-pulse motion-reduce:animate-none',
+ info: 'bg-cyan-400',
};
/** A status in words with a colored dot, so it never relies on color alone. */
@@ -34,26 +36,58 @@ export const StatusPill: React.FC<{ tone: Tone; children: React.ReactNode; class
</span>
);
-/** "This machine" is the engine's own login, so its state comes from the engine's check. */
-export function accountStatus(p: Profile, engine: EngineInfo): { tone: Tone; text: string } {
- if (p.kind !== 'system') return profileStatus(p);
- if (engine.enabled === false || engine.status === 'disabled') return { tone: 'muted', text: 'Not checked while off' };
+/** An account's chip and the line under its name. */
+export interface RowStatus {
+ tone: Tone;
+ label: string;
+ detail: string | null;
+}
+
+/** "This machine" is the engine's own login, so its state comes from the engine's check; Off wins either way. */
+export function accountStatus(p: Profile, engine: EngineInfo, now = Date.now()): RowStatus {
+ if (engine.enabled === false || engine.status === 'disabled') return { tone: 'muted', label: 'Off', detail: `Not checked while ${engine.name} is off` };
+ if (p.kind !== 'system') return accountState(p, now);
+ if (!p.enabled) return { tone: 'muted', label: 'Off', detail: 'Kwants skip it while another account here is on' };
switch (engine.status) {
case 'ready':
- return { tone: 'ok', text: p.account_label ? `Signed in as ${p.account_label}` : 'Signed in' };
+ return isThirdPartyLabel(p.account_label) ? accountState(p, now) : { tone: 'ok', label: 'Ready', detail: p.account_label };
case 'signed_out':
- return { tone: 'warn', text: 'Not signed in' };
+ return { tone: 'warn', label: 'Needs sign-in', detail: null };
case 'not_installed':
- return { tone: 'muted', text: 'Not installed' };
+ return { tone: 'muted', label: 'Not installed', detail: null };
case 'checking':
- return { tone: 'busy', text: 'Checking…' };
+ return { tone: 'busy', label: 'Checking…', detail: null };
case 'error':
- return { tone: 'error', text: 'Check failed' };
+ return { tone: 'error', label: 'Check failed', detail: engine.detail };
default:
- return profileStatus(p);
+ return accountState(p, now);
}
}
+/** A small on/off switch with its name for screen readers. */
+const Switch: React.FC<{ on: boolean; label: string; disabled?: boolean; onChange: (on: boolean) => void }> = ({ on, label, disabled, onChange }) => (
+ <button
+ type="button"
+ role="switch"
+ aria-checked={on}
+ aria-label={label}
+ title={on ? 'On: kwants may use it' : 'Off: kwants skip it'}
+ disabled={disabled}
+ onClick={() => {
+ playSfx('click');
+ onChange(!on);
+ }}
+ className={`relative shrink-0 w-8 h-[18px] rounded-full transition-colors disabled:opacity-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400 ${
+ on ? 'bg-sky-600' : 'bg-zinc-700'
+ }`}
+ >
+ <span
+ aria-hidden="true"
+ className={`absolute top-[2px] left-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform motion-reduce:transition-none ${on ? 'translate-x-[14px]' : ''}`}
+ />
+ </button>
+);
+
/**
* An engine's accounts: "This machine" first, then any added ones. `hostAction` is the sign-in or
* sign-out for "This machine" (Claude's runs through the engine's own login).
@@ -224,6 +258,7 @@ const AccountRow: React.FC<{
const [keyOpen, setKeyOpen] = useState(false);
const [keyValue, setKeyValue] = useState('');
const [login, setLogin] = useState<Login | null>(null);
+ const [detailsOpen, setDetailsOpen] = useState(false);
const status = accountStatus(p, engine);
const isSystem = p.kind === 'system';
const nameId = `account-${p.id}-name`;
@@ -264,79 +299,94 @@ const AccountRow: React.FC<{
run(() => profilesApi.update(p.id, { priority: Math.min(10000, Math.max(0, n)) }));
};
+ const off = status.label === 'Off';
+ const isClaude = p.engine === 'claude';
+ const kindText = isSystem ? `The ${engine.name.replace(/ CLI$/, '')} login on this computer` : p.kind === 'api_key' ? 'API key' : `${engine.name.replace(/ CLI$/, '')} subscription`;
+ const needsSignIn = p.kind === 'cli_home' && !p.signed_in && !login;
+
return (
<li
data-account={p.kind}
+ data-state={status.label}
aria-labelledby={nameId}
- className={`rounded-lg border px-2.5 py-2 space-y-1.5 ${inUse ? 'border-emerald-500/30 bg-emerald-500/[0.04]' : 'border-zinc-800 bg-zinc-950/50'}`}
+ className={`rounded-lg border px-3 py-2.5 space-y-2 transition-colors ${
+ inUse ? 'border-emerald-500/35 bg-emerald-500/[0.05]' : off ? 'border-zinc-800/70 bg-zinc-950/30' : 'border-zinc-800 bg-zinc-950/50'
+ }`}
>
- <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
- {editingName ? (
- <form
- className="flex items-center gap-1.5"
- onSubmit={(e) => {
- e.preventDefault();
- saveName();
- }}
- >
- <label htmlFor={`name-${p.id}`} className="sr-only">
- Account name
- </label>
- <input
- id={`name-${p.id}`}
- autoFocus
- maxLength={60}
- value={name}
- onChange={(e) => setName(e.target.value)}
- onKeyDown={(e) => {
- if (e.key === 'Escape') {
- e.stopPropagation();
- setName(p.name);
- setEditingName(false);
- }
- }}
- className={`${input} py-1 w-36`}
- />
- <button type="submit" disabled={busy} className={quietBtn} aria-label="Save name">
- <Check size={12} />
- </button>
- </form>
- ) : (
- <span className="inline-flex items-center gap-1 min-w-0">
- <span id={nameId} className={`text-xs font-semibold truncate max-w-[11rem] ${p.enabled ? 'text-zinc-100' : 'text-zinc-400'}`}>
- {isSystem ? KIND_LABELS.system : p.name}
- </span>
- {!isSystem && (
- <button
- type="button"
- onClick={() => setEditingName(true)}
- className="p-0.5 rounded text-zinc-500 hover:text-zinc-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"
- aria-label={`Rename ${p.name}`}
+ <div className="flex items-start gap-2">
+ <div className={`flex-1 min-w-0 space-y-0.5 ${off ? 'opacity-70' : ''}`}>
+ <div className="flex flex-wrap items-center gap-x-1.5 gap-y-1">
+ {editingName ? (
+ <form
+ className="flex items-center gap-1.5"
+ onSubmit={(e) => {
+ e.preventDefault();
+ saveName();
+ }}
>
- <Pencil size={11} />
- </button>
+ <label htmlFor={`name-${p.id}`} className="sr-only">
+ Account name
+ </label>
+ <input
+ id={`name-${p.id}`}
+ autoFocus
+ maxLength={60}
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Escape') {
+ e.stopPropagation();
+ setName(p.name);
+ setEditingName(false);
+ }
+ }}
+ className={`${input} py-1 w-36`}
+ />
+ <button type="submit" disabled={busy} className={quietBtn} aria-label="Save name">
+ <Check size={12} />
+ </button>
+ </form>
+ ) : (
+ <span className="inline-flex items-center gap-1 min-w-0">
+ <span id={nameId} className={`text-xs font-semibold truncate max-w-[12rem] ${off ? 'text-zinc-400' : 'text-zinc-100'}`}>
+ {isSystem ? KIND_LABELS.system : p.name}
+ </span>
+ {!isSystem && (
+ <button
+ type="button"
+ onClick={() => setEditingName(true)}
+ className="p-0.5 rounded text-zinc-500 hover:text-zinc-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"
+ aria-label={`Rename ${p.name}`}
+ >
+ <Pencil size={11} />
+ </button>
+ )}
+ </span>
)}
- </span>
- )}
- {!isSystem && <span className="px-1.5 py-0.5 rounded-md bg-zinc-800 text-[10px] text-zinc-400">{KIND_LABELS[p.kind]}</span>}
- {p.is_default && (
- <span className="inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-md bg-sky-500/15 text-[10px] text-sky-200">
- <Star size={9} aria-hidden="true" /> Default
- </span>
- )}
- {inUse && <span className="px-1.5 py-0.5 rounded-md bg-emerald-500/15 text-[10px] font-medium text-emerald-200">In use</span>}
- <StatusPill tone={status.tone} className="ml-auto">
- {status.text}
+ {p.is_default && (
+ <span className="inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-md bg-sky-500/15 text-[10px] text-sky-200" title="Kwants try this account first">
+ <Star size={9} aria-hidden="true" /> Default
+ </span>
+ )}
+ {inUse && <span className="px-1.5 py-0.5 rounded-md bg-emerald-500/15 text-[10px] font-medium text-emerald-200">In use</span>}
+ </div>
+ <p className="text-[11px] leading-snug text-zinc-400 break-words">
+ {status.detail && <span className={status.tone === 'warn' || status.tone === 'error' ? 'text-amber-200' : status.tone === 'ok' ? 'text-zinc-200' : ''}>{status.detail}</span>}
+ {status.detail && <span className="text-zinc-600"> · </span>}
+ <span className="text-zinc-500">{kindText}</span>
+ </p>
+ </div>
+ <StatusPill tone={status.tone} className="mt-px">
+ {status.label}
</StatusPill>
+ <Switch
+ on={p.enabled}
+ disabled={busy}
+ label={`Use ${isSystem ? KIND_LABELS.system : p.name} for kwants`}
+ onChange={(on) => run(() => profilesApi.update(p.id, { enabled: on }))}
+ />
</div>
- {isSystem && <p className="text-[10.5px] text-zinc-500">The {engine.name.replace(/ CLI$/, '')} login on this computer</p>}
- {p.home_dir && (
- <p className="text-[10px] font-mono text-zinc-600 truncate" title={p.home_dir}>
- {p.home_dir}
- </p>
- )}
-
{hostAction && <div>{hostAction}</div>}
<div className="flex flex-wrap items-center gap-x-2 gap-y-1.5">
@@ -346,10 +396,16 @@ const AccountRow: React.FC<{
disabled={busy}
onClick={() => run(async () => setLogin(await profilesApi.startLogin(p.id)))}
className={p.signed_in ? quietBtn : primaryBtn}
+ aria-describedby={needsSignIn ? `signin-hint-${p.id}` : undefined}
>
<LogIn size={11} aria-hidden="true" /> {p.signed_in ? 'Sign in again' : 'Sign in'}
</button>
)}
+ {needsSignIn && (
+ <span id={`signin-hint-${p.id}`} className="text-[10.5px] text-zinc-500">
+ {isClaude ? 'Opens claude.ai, then you paste back a one-time code.' : 'Opens the sign-in page; you may copy a code between it and here.'}
+ </span>
+ )}
{p.kind === 'cli_home' && p.signed_in && (
<button type="button" disabled={busy} onClick={() => run(() => profilesApi.logout(p.id))} className={quietBtn}>
<LogOut size={11} aria-hidden="true" /> Sign out
@@ -365,65 +421,77 @@ const AccountRow: React.FC<{
Remove key
</button>
)}
- {!p.is_default && (
+ {!p.is_default && p.enabled && (
<button type="button" disabled={busy} onClick={() => run(() => profilesApi.update(p.id, { is_default: true }))} className={quietBtn}>
<Star size={11} aria-hidden="true" /> Make default
</button>
)}
- <label className="inline-flex items-center gap-1 text-[11px] text-zinc-400" title="After the default, lower numbers are tried first">
- Priority
- <input
- type="number"
- min={0}
- max={10000}
- value={priority}
- disabled={busy}
- onChange={(e) => setPriority(e.target.value)}
- onBlur={savePriority}
- onKeyDown={(e) => e.key === 'Enter' && (e.currentTarget as HTMLInputElement).blur()}
- className="w-14 bg-zinc-950 border border-zinc-800 rounded-md px-1.5 py-0.5 text-[11px] text-zinc-100 focus:border-sky-500 focus:outline-none"
- />
- </label>
- <label className="inline-flex items-center gap-1.5 text-[11px] text-zinc-400">
- <input
- type="checkbox"
- checked={p.enabled}
- disabled={busy}
- onChange={(e) => run(() => profilesApi.update(p.id, { enabled: e.target.checked }))}
- className="accent-sky-500"
- />
- Use
- </label>
{busy && <Loader2 size={12} className="text-sky-400 animate-spin motion-reduce:animate-none" aria-label="Saving" />}
- {!isSystem &&
- (confirmDelete ? (
- <span className="ml-auto inline-flex items-center gap-1">
- <span className="text-[11px] text-rose-300">Remove?</span>
+ <span className="ml-auto inline-flex items-center gap-1">
+ <button
+ type="button"
+ aria-expanded={detailsOpen}
+ aria-controls={`account-${p.id}-details`}
+ onClick={() => setDetailsOpen((v) => !v)}
+ className="inline-flex items-center gap-0.5 px-1.5 py-1 rounded-md text-[11px] text-zinc-500 hover:text-zinc-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"
+ >
+ {detailsOpen ? <ChevronDown size={12} aria-hidden="true" /> : <ChevronRight size={12} aria-hidden="true" />} Details
+ </button>
+ {!isSystem &&
+ (confirmDelete ? (
+ <>
+ <span className="text-[11px] text-rose-300">Remove?</span>
+ <button
+ type="button"
+ disabled={busy}
+ onClick={() => run(() => profilesApi.remove(p.id))}
+ className={`${smallBtn} border-rose-500/40 bg-rose-500/15 text-rose-200 hover:bg-rose-500/25`}
+ >
+ Remove
+ </button>
+ <button type="button" onClick={() => setConfirmDelete(false)} className={quietBtn}>
+ Keep
+ </button>
+ </>
+ ) : (
<button
type="button"
disabled={busy}
- onClick={() => run(() => profilesApi.remove(p.id))}
- className={`${smallBtn} border-rose-500/40 bg-rose-500/15 text-rose-200 hover:bg-rose-500/25`}
+ onClick={() => setConfirmDelete(true)}
+ className={`${quietBtn} hover:text-rose-200`}
+ aria-label={`Remove ${p.name}`}
>
- Remove
- </button>
- <button type="button" onClick={() => setConfirmDelete(false)} className={quietBtn}>
- Keep
+ <Trash2 size={11} />
</button>
- </span>
- ) : (
- <button
- type="button"
- disabled={busy}
- onClick={() => setConfirmDelete(true)}
- className={`${quietBtn} ml-auto hover:text-rose-200`}
- aria-label={`Remove ${p.name}`}
- >
- <Trash2 size={11} />
- </button>
- ))}
+ ))}
+ </span>
</div>
+ {detailsOpen && (
+ <div id={`account-${p.id}-details`} className="rounded-md border border-zinc-800 bg-zinc-950/60 px-2.5 py-2 space-y-1.5">
+ <label className="flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-zinc-400">
+ <span>Priority</span>
+ <input
+ type="number"
+ min={0}
+ max={10000}
+ value={priority}
+ disabled={busy}
+ onChange={(e) => setPriority(e.target.value)}
+ onBlur={savePriority}
+ onKeyDown={(e) => e.key === 'Enter' && (e.currentTarget as HTMLInputElement).blur()}
+ className="w-16 bg-zinc-950 border border-zinc-800 rounded-md px-1.5 py-0.5 text-[11px] text-zinc-100 focus:border-sky-500 focus:outline-none"
+ />
+ <span className="text-zinc-500">After the default, kwants try lower numbers first.</span>
+ </label>
+ {p.home_dir && (
+ <p className="text-[10.5px] text-zinc-500">
+ Login folder: <span className="font-mono text-zinc-400 break-all select-text">{p.home_dir}</span>
+ </p>
+ )}
+ </div>
+ )}
+
{confirmDelete && <p className="text-[11px] text-zinc-500">Kwants pinned to it go back to the default. Its folder stays on disk.</p>}
{keyOpen && p.kind === 'api_key' && (
@@ -465,6 +533,7 @@ const AccountRow: React.FC<{
{login && (
<LoginPanel
profileId={p.id}
+ accountName={p.name}
login={login}
onUpdate={setLogin}
onDone={async (succeeded) => {
@@ -488,10 +557,11 @@ const LOGIN_POLL_MS = 1500;
const LoginPanel: React.FC<{
profileId: string;
+ accountName: string;
login: Login;
onUpdate: (l: Login) => void;
onDone: (succeeded: boolean) => void;
-}> = ({ profileId, login, onUpdate, onDone }) => {
+}> = ({ profileId, accountName, login, onUpdate, onDone }) => {
const [code, setCode] = useState('');
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -573,7 +643,8 @@ const LoginPanel: React.FC<{
)}
{login.status === 'waiting' && (
<>
- <ol className="list-decimal list-inside space-y-1 text-[11px] text-zinc-300">
+ <p className="text-[11px] font-medium text-zinc-100">Sign in to {accountName}</p>
+ <ol className="list-decimal list-outside pl-4 space-y-1 text-[11px] text-zinc-300 marker:text-zinc-500">
<li>
{url ? (
<a href={url} target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-1 text-sky-300 underline underline-offset-2 hover:text-sky-200">
@@ -582,7 +653,7 @@ const LoginPanel: React.FC<{
) : (
'Waiting for the sign-in link…'
)}{' '}
- and sign in with the account for this profile.
+ and sign in with the account you want for {accountName}.
</li>
{login.user_code && (
<li>
@@ -605,7 +676,12 @@ const LoginPanel: React.FC<{
</button>
</li>
)}
- {login.needs_code && <li>Paste the code the page shows you:</li>}
+ {login.needs_code && (
+ <>
+ <li>The page then shows a one-time code. Copy it.</li>
+ <li>Paste it below and press Finish sign-in.</li>
+ </>
+ )}
</ol>
{login.needs_code && (
<form onSubmit={submitCode} className="flex items-center gap-1.5">
@@ -618,14 +694,19 @@ const LoginPanel: React.FC<{
spellCheck={false}
value={code}
onChange={(e) => setCode(e.target.value)}
- placeholder="Code"
+ placeholder="Paste the code"
className={`${input} py-1 font-mono`}
/>
- <button type="submit" disabled={busy || !code.trim()} className={primaryBtn}>
- Submit
+ <button type="submit" disabled={busy || !code.trim()} className={`${primaryBtn} shrink-0`}>
+ {busy && <Loader2 size={12} className="animate-spin motion-reduce:animate-none" aria-hidden="true" />} Finish sign-in
</button>
</form>
)}
+ {login.needs_code && (
+ <p className="text-[10.5px] text-zinc-500 leading-snug">
+ Why a code? kwnt runs the sign-in in the background, so the page can’t hand the login back by itself. The code works once and isn’t kept.
+ </p>
+ )}
<p className="flex items-center gap-1.5 text-[10px] text-zinc-500">
<Loader2 size={10} className="animate-spin motion-reduce:animate-none" /> Waiting for you to finish…
</p>
diff --git a/frontend/src/components/EnginesPanel.tsx b/frontend/src/components/EnginesPanel.tsx
index e1129936..56aa4a90 100644
--- a/frontend/src/components/EnginesPanel.tsx
+++ b/frontend/src/components/EnginesPanel.tsx
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
-import { AlertTriangle, ChevronDown, ChevronRight, Cpu, Key, Loader2, RefreshCw, Server } from 'lucide-react';
+import { AlertTriangle, ArrowRight, ChevronDown, ChevronRight, Cpu, Key, Loader2, RefreshCw, Route, Server } from 'lucide-react';
import { EngineInfo, checkedAgo, engineSummary, isAbsent, isUsable, onlyCliReady, sortEngines, statusView } from '../engines';
import { playSfx } from '../audio/chiptune';
import type { EnginesApi } from '../useEngines';
@@ -8,6 +8,7 @@ import { ClaudeSignIn, ClaudeSignOut } from './ClaudeSignIn';
import { AccountList, StatusPill } from './EngineAccounts';
import { Profile, accountUsable, accountsForCard, activeLimit, formatUntil } from '../profiles';
import type { ProfilesState } from '../useProfiles';
+import { RouteRow, routeSummary } from '../routing';
const SUMMARY_TEXT = {
ok: 'text-emerald-300',
@@ -15,6 +16,7 @@ const SUMMARY_TEXT = {
error: 'text-rose-300',
muted: 'text-zinc-400',
busy: 'text-sky-300',
+ info: 'text-cyan-200',
} as const;
const KIND_ICON = { cli: Cpu, api: Key, local: Server } as const;
@@ -148,6 +150,38 @@ function headline(engines: EngineInfo[], profiles: Profile[] | null, now: number
: 'No engine can run right now. Turn on an engine and sign in to one of its accounts below.';
}
+/** The answer to "what will run my next kwant?": engine → account → model per family, and the fallback. */
+export const RouteSummary: React.FC<{ rows: RouteRow[]; pending: boolean }> = ({ rows, pending }) => (
+ <div data-route-summary className="rounded-xl border border-sky-500/25 bg-gradient-to-b from-sky-500/[0.07] to-transparent p-3 space-y-2.5">
+ <h4 className="flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-sky-200">
+ <Route size={13} aria-hidden="true" /> What runs your kwants
+ </h4>
+ <ul className="space-y-2.5">
+ {rows.map((r) => (
+ <li key={r.family} data-route={r.family} className="text-[11px] leading-snug">
+ <div className="flex flex-wrap items-center gap-x-1.5 gap-y-1">
+ <span className="w-14 shrink-0 font-semibold text-zinc-100">{r.label}</span>
+ <span className="px-1.5 py-0.5 rounded-md bg-zinc-800/80 text-zinc-300">{r.engine}</span>
+ <ArrowRight size={11} className="text-zinc-500" aria-label="on" />
+ <span className={`px-1.5 py-0.5 rounded-md font-medium ${r.account.otherProvider ? 'bg-amber-500/15 text-amber-100' : 'bg-emerald-500/15 text-emerald-100'}`}>
+ {r.account.name}
+ </span>
+ {r.account.detail && <span className={r.account.otherProvider ? 'text-amber-200' : 'text-zinc-400'}>{r.account.detail}</span>}
+ </div>
+ <p className="mt-1 pl-0 sm:pl-[3.875rem] text-zinc-500">
+ {r.then.length > 0 ? `If it’s out of usage or signed out: ${r.then.join(', then ')}.` : 'No backup account is ready.'}
+ {r.defaultModel && <> Kwants on Auto get {r.defaultModel}.</>}
+ </p>
+ {r.fallback && <p className="pl-0 sm:pl-[3.875rem] text-zinc-500">{r.fallback}</p>}
+ </li>
+ ))}
+ </ul>
+ <p className="text-[10.5px] text-zinc-500 border-t border-zinc-800/80 pt-2">
+ {pending ? 'Loading accounts… ' : ''}A kwant set to a specific account in its own settings starts with that account instead.
+ </p>
+ </div>
+);
+
/** Settings → "Engines & accounts": one card per engine with the accounts it runs on, ready ones first.
* `focusClaudeSignIn` changes to bring "Sign in with Claude" into view and focus it. */
export const EnginesPanel: React.FC<{ api: EnginesApi; accounts?: ProfilesState; now?: number; focusClaudeSignIn?: number }> = ({
@@ -166,6 +200,7 @@ export const EnginesPanel: React.FC<{ api: EnginesApi; accounts?: ProfilesState;
const absent = sorted.filter((e) => !present.includes(e));
const lastChecked = sorted.map((e) => e.checked_at).filter(Boolean).sort().pop() ?? null;
const ago = checkedAgo(lastChecked, now);
+ const routes = engines ? routeSummary(engines, profiles, now) : [];
// An account change can change whether its engine is ready; the server re-checks accounts in the
// background after a read, so look once more shortly after.
@@ -190,8 +225,9 @@ export const EnginesPanel: React.FC<{ api: EnginesApi; accounts?: ProfilesState;
return (
<section aria-labelledby="engines-title" className="bg-zinc-950/60 p-3 sm:p-4 rounded-xl border border-zinc-800 space-y-3">
<div className="flex items-center gap-2">
- <Cpu size={15} className="text-sky-400" aria-hidden="true" />
- <h3 id="engines-title" className="text-xs font-medium text-zinc-300">Engines &amp; accounts</h3>
+ <Cpu size={15} className="shrink-0 text-sky-400" aria-hidden="true" />
+ <h3 id="engines-title" className="text-xs font-semibold text-zinc-200 whitespace-nowrap">Engines &amp; accounts</h3>
+ {ago && <span className="ml-auto min-w-0 truncate text-[10.5px] text-zinc-500" title={`Checked ${ago}`}><span className="hidden sm:inline">Checked </span>{ago}</span>}
<button
type="button"
onClick={() => {
@@ -200,21 +236,24 @@ export const EnginesPanel: React.FC<{ api: EnginesApi; accounts?: ProfilesState;
accounts?.reload();
}}
disabled={rechecking || engines === null}
- className="ml-auto flex items-center gap-1.5 px-2 py-1 rounded-md text-[11px] font-medium text-zinc-300 border border-zinc-800 hover:text-sky-200 hover:border-sky-500/40 disabled:opacity-50 transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"
+ className={`${ago ? '' : 'ml-auto '}shrink-0 whitespace-nowrap flex items-center gap-1.5 px-2 py-1 rounded-md text-[11px] font-medium text-zinc-300 border border-zinc-800 hover:text-sky-200 hover:border-sky-500/40 disabled:opacity-50 transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400`}
>
{rechecking ? <Loader2 size={12} className="animate-spin motion-reduce:animate-none" aria-hidden="true" /> : <RefreshCw size={12} aria-hidden="true" />}
{rechecking ? 'Checking…' : 'Re-check'}
</button>
</div>
- <p className="text-[11px] text-zinc-400 leading-relaxed" aria-live="polite">
- {engines === null
- ? 'Checking which engines can run…'
- : engines.length === 0
- ? 'This server doesn’t report engine status yet.'
- : headline(engines, profiles, now)}
- {ago && <span className="text-zinc-500"> Checked {ago}.</span>}
- </p>
+ {routes.length > 0 ? (
+ <RouteSummary rows={routes} pending={!!accounts && !profiles && !accounts.error} />
+ ) : (
+ <p className="text-[11px] text-zinc-400 leading-relaxed" aria-live="polite">
+ {engines === null
+ ? 'Checking which engines can run…'
+ : engines.length === 0
+ ? 'This server doesn’t report engine status yet.'
+ : headline(engines, profiles, now)}
+ </p>
+ )}
{error && (
<p role="alert" className="flex items-center gap-1.5 text-[11px] text-rose-300">
diff --git a/frontend/src/components/SettingsModal.tsx b/frontend/src/components/SettingsModal.tsx
index 9d8e62cd..ee498a6f 100644
--- a/frontend/src/components/SettingsModal.tsx
+++ b/frontend/src/components/SettingsModal.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef } from 'react';
-import { Key, Globe, X, Sparkles, Check, Plug, ChevronRight, LogOut, Bell, AlertTriangle, Layers, Monitor } from 'lucide-react';
+import { Key, Globe, X, Sparkles, Check, Plug, ChevronDown, ChevronRight, LogOut, Bell, AlertTriangle, Layers, Monitor } from 'lucide-react';
import { TURN_LIMITS, TurnLimitKey, limitError } from '../threads';
import {
BROWSER_NOTIFY_KEY,
@@ -65,6 +65,7 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o
const [xaiKey, setXaiKey] = useState('');
const [openaiKey, setOpenaiKey] = useState('');
const [ollamaUrl, setOllamaUrl] = useState('http://localhost:11434/v1');
+ const [keysOpen, setKeysOpen] = useState(false);
const [saving, setSaving] = useState(false);
const [saveSuccess, setSaveSuccess] = useState(false);
const [saveError, setSaveError] = useState<string | null>(null);
@@ -80,6 +81,7 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o
const limitErrors = Object.fromEntries(
LIMIT_FIELDS.map(({ key }) => [key, limits ? limitError(key, limits[key]) : null]),
) as Record<TurnLimitKey, string | null>;
+ const keysSaved = [anthropicKey, xaiKey, openaiKey].filter((k) => k.trim()).length;
const limitsInvalid = Object.values(limitErrors).some(Boolean);
const perAgentOverGlobal =
!!limits && !limitsInvalid && Number(limits.max_turns_per_agent) > Number(limits.max_turns_global);
@@ -193,7 +195,7 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o
return (
<div className="fixed inset-0 z-50 bg-black/70 backdrop-blur-sm flex items-center justify-center p-4 select-none">
- <div role="dialog" aria-modal="true" aria-labelledby="settings-title" className="bg-zinc-900 border border-zinc-800 rounded-2xl max-w-lg w-full max-h-[92vh] overflow-y-auto p-4 sm:p-6 text-zinc-100 shadow-2xl space-y-6">
+ <div role="dialog" aria-modal="true" aria-labelledby="settings-title" className="bg-zinc-900 border border-zinc-800 rounded-2xl max-w-lg sm:max-w-2xl w-full max-h-[92vh] overflow-y-auto p-4 sm:p-6 text-zinc-100 shadow-2xl space-y-6">
{/* Header */}
<div className="flex items-center justify-between border-b border-zinc-800 pb-4">
<div className="flex items-center gap-2.5">
@@ -201,8 +203,8 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o
<Sparkles size={17} />
</div>
<div>
- <h2 id="settings-title" className="text-sm font-semibold text-zinc-100">Fleet & Engine Settings</h2>
- <p className="text-xs text-zinc-400">Engines, the accounts they run on, and API keys</p>
+ <h2 id="settings-title" className="text-sm font-semibold text-zinc-100">Settings</h2>
+ <p className="text-xs text-zinc-400">What runs your kwants, the accounts they use, and how they work</p>
</div>
</div>
@@ -211,7 +213,8 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o
playSfx('click');
onClose();
}}
- className="p-1.5 rounded-lg text-zinc-400 hover:text-zinc-100 hover:bg-zinc-800 transition-colors"
+ aria-label="Close settings"
+ className="p-1.5 rounded-lg text-zinc-400 hover:text-zinc-100 hover:bg-zinc-800 transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"
>
<X size={18} />
</button>
@@ -254,12 +257,28 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o
{/* Cloud API Keys Form */}
<form onSubmit={handleSave} className="space-y-4">
- <div className="flex items-center gap-2 text-xs font-medium text-zinc-300">
- <Key size={14} className="text-violet-400" />
- <span>Direct Cloud API Keys (Optional)</span>
- </div>
+ <div className="rounded-xl border border-zinc-800 bg-zinc-950/60">
+ <button
+ type="button"
+ aria-expanded={keysOpen}
+ aria-controls="settings-api-keys"
+ onClick={() => setKeysOpen((v) => !v)}
+ className="w-full flex items-center gap-2 p-3 text-left rounded-xl focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"
+ >
+ <Key size={14} className="text-violet-400" aria-hidden="true" />
+ <span className="flex-1">
+ <span className="block text-xs font-medium text-zinc-200">API keys and Ollama</span>
+ <span className="block text-[11px] text-zinc-500">
+ Optional. {keysSaved ? `${keysSaved} saved. ` : ''}Not needed when you sign in to a CLI above.
+ </span>
+ </span>
+ {keysOpen ? <ChevronDown size={15} className="text-zinc-500" aria-hidden="true" /> : <ChevronRight size={15} className="text-zinc-500" aria-hidden="true" />}
+ </button>
- <div className="space-y-3">
+ <div id="settings-api-keys" hidden={!keysOpen} className="space-y-3 px-3 pb-3">
+ <p className="text-[11px] text-zinc-500">
+ One key per provider for the API-key engines. To keep several keys for one provider, add them as accounts on its engine card above.
+ </p>
<div>
<label className="block text-xs font-medium text-zinc-400 mb-1">
Anthropic API Key
@@ -313,6 +332,7 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o
/>
</div>
</div>
+ </div>
{limits && (
<fieldset className="space-y-3 pt-2 border-t border-zinc-800">
diff --git a/frontend/src/engines.ts b/frontend/src/engines.ts
index 2f53ab99..b1f30201 100644
--- a/frontend/src/engines.ts
+++ b/frontend/src/engines.ts
@@ -53,7 +53,8 @@ export const FAMILIES: Array<{ id: Family; label: string }> = [
export const familyLabel = (f: Family) => FAMILIES.find((x) => x.id === f)?.label ?? f;
-export type Tone = 'ok' | 'warn' | 'error' | 'muted' | 'busy';
+/** `info`: neither good nor bad, e.g. This machine set up for another provider. */
+export type Tone = 'ok' | 'warn' | 'error' | 'muted' | 'busy' | 'info';
/** Whether kwants can run on it: the server's `ready` (which counts its accounts), else the host check. */
export const isUsable = (e: Pick<EngineInfo, 'status' | 'enabled' | 'ready'>) => e.enabled !== false && (e.ready ?? e.status === 'ready');
diff --git a/frontend/src/profiles.ts b/frontend/src/profiles.ts
index 5fd152b7..99953963 100644
--- a/frontend/src/profiles.ts
+++ b/frontend/src/profiles.ts
@@ -91,16 +91,47 @@ export function formatUntil(at: Date, now = Date.now()): string {
return at.toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
}
-/** Short status for a profile: what a person needs to know before relying on it. */
-export function profileStatus(p: Profile, now = Date.now()): { tone: 'ok' | 'warn' | 'error' | 'muted'; text: string } {
- if (!p.enabled) return { tone: 'muted', text: 'Turned off' };
+/** What the server's account label says when Claude Code is set up for another provider, not a Claude login. */
+const THIRD_PARTY_LABELS = new Set(['Amazon Bedrock', 'Google Vertex AI', 'Microsoft Foundry', 'a third-party provider', 'third_party']);
+export const isThirdPartyLabel = (label: string | null | undefined) => !!label && THIRD_PARTY_LABELS.has(label);
+const providerName = (label: string) => (label === 'third_party' ? 'a third-party provider' : label);
+
+export type AccountTone = 'ok' | 'warn' | 'error' | 'muted' | 'info';
+
+/** An account's state in the words every screen uses: a one-word chip, and a line saying who or why. */
+export interface AccountState {
+ label: 'Ready' | 'Needs sign-in' | 'Off' | 'Out of usage' | 'Other provider' | 'No key' | 'Unknown';
+ tone: AccountTone;
+ /** The email or provider when it's ready, else what to do; null when there's nothing to add. */
+ detail: string | null;
+}
+
+/** The state of an added account (This machine's comes from its engine's check; see accountStatus). */
+export function accountState(p: Profile, now = Date.now()): AccountState {
+ if (!p.enabled) return { label: 'Off', tone: 'muted', detail: 'Kwants skip this account' };
const limit = activeLimit(p.limited_until, now);
- if (limit) return { tone: 'warn', text: `Out of usage · back ${formatUntil(limit, now)}` };
- if (p.last_error === 'auth') return { tone: 'error', text: 'Signed out · sign in again' };
- if (p.kind === 'api_key') return p.has_key ? { tone: 'ok', text: 'Key saved' } : { tone: 'error', text: 'No key yet' };
- if (p.signed_in === true) return { tone: 'ok', text: p.account_label ? `Signed in as ${p.account_label}` : 'Signed in' };
- if (p.signed_in === false) return { tone: 'error', text: 'Not signed in' };
- return { tone: 'muted', text: p.kind === 'system' ? 'Uses this machine’s login' : 'Sign-in unknown (CLI missing?)' };
+ if (limit) return { label: 'Out of usage', tone: 'warn', detail: `Back ${formatUntil(limit, now)}` };
+ if (p.last_error === 'auth') return { label: 'Needs sign-in', tone: 'error', detail: 'Its login stopped working. Sign in again.' };
+ if (p.kind === 'api_key') return p.has_key ? { label: 'Ready', tone: 'ok', detail: 'Key saved' } : { label: 'No key', tone: 'warn', detail: 'Add a key to use it' };
+ if (p.signed_in === true) {
+ if (isThirdPartyLabel(p.account_label)) {
+ const via = providerName(p.account_label!);
+ return p.kind === 'system'
+ ? { label: 'Other provider', tone: 'info', detail: `Runs through ${via}, not a Claude login` }
+ : { label: 'Other provider', tone: 'warn', detail: `Runs through ${via} instead of its own Claude login` };
+ }
+ return { label: 'Ready', tone: 'ok', detail: p.account_label };
+ }
+ if (p.signed_in === false) return { label: 'Needs sign-in', tone: 'warn', detail: null };
+ return { label: 'Unknown', tone: 'muted', detail: p.kind === 'system' ? 'Uses this computer’s login' : 'Couldn’t check the sign-in (is the CLI installed?)' };
+}
+
+/** Short status for a profile, e.g. "Ready · [email protected]" or "Out of usage · Back in 45 min", for pickers. */
+export function profileStatus(p: Profile, now = Date.now()): { tone: AccountTone; text: string } {
+ const s = accountState(p, now);
+ // The email tells two ready accounts apart; Off and Needs sign-in say enough on their own.
+ const withDetail = s.label === 'Out of usage' || s.label === 'Other provider' || (s.label === 'Ready' && p.kind !== 'api_key');
+ return { tone: s.tone, text: withDetail && s.detail ? `${s.label} · ${s.detail}` : s.label };
}
async function request<T>(method: string, url: string, body?: unknown): Promise<T> {
diff --git a/frontend/src/routing.ts b/frontend/src/routing.ts
new file mode 100644
index 00000000..498ab678
--- /dev/null
+++ b/frontend/src/routing.ts
@@ -0,0 +1,92 @@
+// "What runs your kwants": for each model family that can run, the engine and account a turn starts
+// on and the accounts it falls back to, in the server's order (src/profiles/mod.rs failover_order):
+// the family's switched-on accounts, the default first, then by priority; at most 3 tries.
+
+import { EngineInfo, FAMILIES, FAMILY_OF, Family, isUsable } from './engines';
+import { Profile, accountUsable, cardOf, isThirdPartyLabel } from './profiles';
+
+/** Turns try at most this many accounts (MAX_ATTEMPTS on the server). */
+const MAX_TRIES = 3;
+
+export interface RouteAccount {
+ name: string;
+ /** Email, provider or "API key", to tell accounts apart. */
+ detail: string | null;
+ /** Runs through Bedrock, Vertex or the like instead of a Claude login. */
+ otherProvider: boolean;
+}
+
+export interface RouteRow {
+ family: Family;
+ /** "Claude", "Codex", … */
+ label: string;
+ /** The engine the first account runs on, e.g. "Claude Code CLI". */
+ engine: string;
+ /** The account a turn starts on. */
+ account: RouteAccount;
+ /** Then these, if the first is out of usage or signed out. */
+ then: string[];
+ /** The model a kwant on "Auto" for this family gets, when the engine says. */
+ defaultModel: string | null;
+ /** One sentence on what happens when every account is off, when it matters. */
+ fallback: string | null;
+}
+
+const hostName = 'This machine';
+const accountName = (p: Profile) => (p.kind === 'system' ? hostName : p.name);
+const familyName = (f: Family) => FAMILIES.find((x) => x.id === f)!.label.replace(/ \(.*\)$/, '');
+
+function describe(p: Profile): RouteAccount {
+ const otherProvider = isThirdPartyLabel(p.account_label);
+ const detail = p.kind === 'api_key' ? 'API key' : otherProvider ? `via ${p.account_label === 'third_party' ? 'another provider' : p.account_label}` : p.account_label;
+ return { name: accountName(p), detail, otherProvider };
+}
+
+/** The family's accounts in the order a turn tries them; empty when none is switched on. */
+export function tryOrder(profiles: Profile[], family: Family, now = Date.now()): Profile[] {
+ const on = profiles
+ .filter((p) => p.engine === family && p.enabled)
+ .sort((a, b) => Number(b.is_default) - Number(a.is_default) || a.priority - b.priority || a.name.localeCompare(b.name));
+ const [first, ...rest] = on;
+ if (!first) return [];
+ const usableRest = rest.filter((p) => accountUsable(p, now));
+ const order = accountUsable(first, now) || usableRest.length === 0 ? [first, ...usableRest] : usableRest;
+ return order.slice(0, MAX_TRIES);
+}
+
+/** One row per family that has a ready engine; [] when nothing can run. */
+export function routeSummary(engines: EngineInfo[], profiles: Profile[] | null, now = Date.now()): RouteRow[] {
+ return FAMILIES.flatMap(({ id: family }) => {
+ const ready = engines.filter((e) => FAMILY_OF[e.id] === family && isUsable(e));
+ if (ready.length === 0) return [];
+ const mine = profiles?.filter((p) => p.engine === family) ?? [];
+ const order = profiles ? tryOrder(profiles, family, now) : [];
+ // Accounts on an engine that's off can't run, so skip them like the server's plan does.
+ const onEngine = (p: Profile) => ready.some((e) => e.id === cardOf(p));
+ const usable = order.filter((p) => accountUsable(p, now) && onEngine(p));
+ const start = usable[0];
+ const cli = ready.find((e) => e.kind === 'cli');
+ const host = mine.find((p) => p.kind === 'system');
+ let account: RouteAccount;
+ let engine: EngineInfo;
+ if (start) {
+ account = describe(start);
+ engine = ready.find((e) => e.id === cardOf(start)) ?? ready[0];
+ } else if (profiles && cli && order.length === 0) {
+ // No account switched on: the turn runs on the CLI's own login.
+ account = host ? describe(host) : { name: hostName, detail: null, otherProvider: false };
+ engine = cli;
+ } else {
+ // A ready engine with no account of its own (an API key from Settings, Ollama).
+ engine = ready[0];
+ account = { name: engine.uses?.label ?? (engine.kind === 'local' ? 'This computer' : engine.kind === 'api' ? 'API key in Settings' : hostName), detail: null, otherProvider: false };
+ }
+ const then = usable.slice(1).map(accountName);
+ const hostOff = !!host && !host.enabled;
+ const fallback = hostOff && engine.kind === 'cli' && mine.some((p) => p.kind !== 'system')
+ ? `If you switch off every ${familyName(family)} account, kwants use This machine.`
+ : null;
+ const defaultModel = engine.models.find((m) => m.default)?.label ?? null;
+ return [{ family, label: familyName(family), engine: engine.name, account, then, defaultModel, fallback }];
+ });
+}
diff --git a/frontend/tests/engines.test.mjs b/frontend/tests/engines.test.mjs
index 41840c3f..d24dfb1c 100644
--- a/frontend/tests/engines.test.mjs
+++ b/frontend/tests/engines.test.mjs
@@ -109,10 +109,10 @@ test('ready engines come first; not-installed ones fold under "Not available on
assert.match(html, /aria-expanded="false"/);
});
-test('"no API keys needed" is only claimed when only CLIs are ready', () => {
- assert.match(panel(live), /all through your signed-in CLIs, so no API keys are needed/);
- const withKey = live.map((e) => (e.id === 'anthropic_api' ? { ...e, status: 'ready', detail: null } : e));
- assert.doesNotMatch(panel(withKey), /no API keys are needed/);
+test('the headline gives way to the route summary once something is ready', () => {
+ // With something ready, the route summary answers "what runs" instead of a count.
+ assert.match(panel(live), /What runs your kwants/);
+ assert.doesNotMatch(panel(live), /no API keys are needed/);
assert.match(panel(live.map((e) => ({ ...e, status: 'signed_out' }))), /No engine can run right now/);
assert.match(panel(null), /Checking which engines can run/);
});
diff --git a/frontend/tests/enginesAccounts.test.mjs b/frontend/tests/enginesAccounts.test.mjs
index f5f99b3f..0aabfdf5 100644
--- a/frontend/tests/enginesAccounts.test.mjs
+++ b/frontend/tests/enginesAccounts.test.mjs
@@ -66,18 +66,21 @@ test('ready comes from `ready`, not the host login or the model list', () => {
test('Oleks: one Claude card says kwants use Personal, with This machine first and signed out', () => {
const html = panel([oleksOn]);
assert.match(html, /Engines &amp; accounts/);
- assert.match(html, /1 ready/);
+ // The summary replaces the headline: Claude runs on Claude Code CLI through Personal.
+ assert.match(html, /What runs your kwants/);
+ assert.match(html, /data-route="claude"[\s\S]*?Claude Code CLI[\s\S]*?>Personal</);
+ assert.match(html, /No backup account is ready\./);
assert.match(html, /data-engine="claude" data-status="ready"/);
assert.equal(summary(html, 'claude'), 'Kwants use Personal');
const names = [...card(html, 'claude').matchAll(/id="account-[^"]+-name"[^>]*>([^<]+)</g)].map((x) => x[1]);
assert.deepEqual(names, ['This machine', 'Personal']);
// This machine: not signed in, with the Batch 9 sign-in on its row; Personal is in use.
const rows = card(html, 'claude').split('data-account=');
- assert.match(rows[1], /Not signed in/);
+ assert.match(rows[1], /Needs sign-in/);
assert.match(rows[1], /Sign in with Claude<\/button>/);
assert.match(rows[2], /Default/);
assert.match(rows[2], /In use/);
- assert.match(rows[2], /Signed in/);
+ assert.match(rows[2], /Ready/);
assert.match(rows[2], /Sign out/);
// Only one way to sign in to Claude's host login, and no "run claude auth login".
assert.equal(html.split('Sign in with Claude</button>').length, 2);
@@ -90,7 +93,8 @@ test('switched off with Personal signed in: "Off · Turn on to use Personal"', (
assert.equal(summary(html, 'claude'), 'Off · Turn on to use Personal');
assert.match(html, /No engine can run right now\. Claude Code CLI is off: turn it on to use Personal\./);
assert.match(html, /role="switch" aria-checked="false"/);
- assert.match(html, /Not checked while off/);
+ assert.match(html, /Not checked while Claude Code CLI is off/);
+ assert.doesNotMatch(html, /What runs your kwants/);
// Nothing to sign in to while it's off.
assert.doesNotMatch(html, /Sign in with Claude/);
});
diff --git a/frontend/tests/profiles.test.mjs b/frontend/tests/profiles.test.mjs
index c1ca408a..6f716946 100644
--- a/frontend/tests/profiles.test.mjs
+++ b/frontend/tests/profiles.test.mjs
@@ -43,15 +43,32 @@ test('lists an engine default first, then by ascending priority', () => {
test('status explains usage limits, sign-in and keys without showing secrets', () => {
const now = Date.parse('2026-10-16T12:00:00Z');
const { profileStatus } = profiles;
- assert.deepEqual(profileStatus(profile({ limited_until: '2026-10-16T12:45:00Z' }), now), { tone: 'warn', text: 'Out of usage · back in 45 min' });
- assert.equal(profileStatus(profile({ limited_until: '2026-10-16T11:00:00Z', account_label: '[email protected]' }), now).text, 'Signed in as [email protected]');
+ assert.deepEqual(profileStatus(profile({ limited_until: '2026-10-16T12:45:00Z' }), now), { tone: 'warn', text: 'Out of usage · Back in 45 min' });
+ assert.equal(profileStatus(profile({ limited_until: '2026-10-16T11:00:00Z', account_label: '[email protected]' }), now).text, 'Ready · [email protected]');
+ assert.equal(profileStatus(profile({}), now).text, 'Ready');
assert.equal(profileStatus(profile({ last_error: 'auth' }), now).tone, 'error');
- assert.equal(profileStatus(profile({ kind: 'api_key', has_key: false }), now).text, 'No key yet');
- assert.equal(profileStatus(profile({ kind: 'api_key', has_key: true }), now).text, 'Key saved');
- assert.equal(profileStatus(profile({ enabled: false, last_error: 'quota' }), now).text, 'Turned off');
+ assert.equal(profileStatus(profile({ last_error: 'auth' }), now).text, 'Needs sign-in');
+ assert.equal(profileStatus(profile({ signed_in: false }), now).text, 'Needs sign-in');
+ assert.equal(profileStatus(profile({ kind: 'api_key', has_key: false }), now).text, 'No key');
+ assert.equal(profileStatus(profile({ kind: 'api_key', has_key: true }), now).text, 'Ready');
+ assert.equal(profileStatus(profile({ enabled: false, last_error: 'quota' }), now).text, 'Off');
assert.equal(profileStatus(profile({ signed_in: null, kind: 'system' }), now).tone, 'muted');
});
+test('a Claude Code set up for another provider reads as "Other provider", never "Signed in as"', () => {
+ const { accountState, isThirdPartyLabel } = profiles;
+ const bedrock = profile({ account_label: 'Amazon Bedrock' });
+ assert.deepEqual(accountState(bedrock), { label: 'Other provider', tone: 'warn', detail: 'Runs through Amazon Bedrock instead of its own Claude login' });
+ // On This machine it's a setup, not a problem.
+ assert.equal(accountState(profile({ kind: 'system', account_label: 'Google Vertex AI' })).tone, 'info');
+ // An older server's raw auth method.
+ assert.equal(accountState(profile({ account_label: 'third_party' })).detail, 'Runs through a third-party provider instead of its own Claude login');
+ assert.equal(profiles.profileStatus(bedrock).text, 'Other provider · Runs through Amazon Bedrock instead of its own Claude login');
+ assert.ok(!isThirdPartyLabel('[email protected]'));
+ // Off wins over everything, so a switched-off account never looks in use.
+ assert.equal(accountState(profile({ enabled: false, account_label: 'Amazon Bedrock' })).label, 'Off');
+});
+
test('only opens https sign-in links', () => {
assert.equal(profiles.safeExternalUrl('https://claude.ai/oauth/authorize?x=1'), 'https://claude.ai/oauth/authorize?x=1');
assert.equal(profiles.safeExternalUrl('javascript:alert(1)'), null);
diff --git a/frontend/tests/routing.test.mjs b/frontend/tests/routing.test.mjs
new file mode 100644
index 00000000..0f0b92ad
--- /dev/null
+++ b/frontend/tests/routing.test.mjs
@@ -0,0 +1,74 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { loadBundled } from './bundle.mjs';
+
+const m = await loadBundled(`export * from './src/routing';`);
+
+const NOW = Date.parse('2026-10-17T19:01:00Z');
+const engine = (id, over = {}) => ({
+ id,
+ name: { claude: 'Claude Code CLI', codex: 'Codex CLI', anthropic_api: 'Anthropic API key', ollama: 'Ollama' }[id],
+ kind: id.endsWith('_api') ? 'api' : id === 'ollama' ? 'local' : 'cli',
+ status: 'ready', detail: null, version: null, checked_at: '2026-10-17T19:00:00Z', enabled: true, ready: true, uses: null,
+ models: id === 'claude' ? [{ id: 'sonnet', label: 'Claude Sonnet', default: true }] : [],
+ ...over,
+});
+const profile = (over) => ({
+ id: 'prf_x', engine: 'claude', name: 'Work', kind: 'cli_home', enabled: true, is_default: false, priority: 100,
+ home_dir: null, has_key: false, signed_in: true, account_label: null, limited_until: null, last_error: null, ...over,
+});
+// Oleks's setup: This machine off and on Bedrock, Personal default and signed in.
+const machine = profile({ id: 'prf_system_claude', name: 'This machine', kind: 'system', enabled: false, priority: 0, account_label: 'Amazon Bedrock' });
+const personal = profile({ id: 'prf_personal', name: 'Personal', is_default: true, priority: 100, account_label: '[email protected]' });
+const work = profile({ id: 'prf_work', name: 'Work', priority: 50, account_label: '[email protected]' });
+
+test('turns try the default first, then by priority, at most 3, skipping off accounts', () => {
+ const extra = profile({ id: 'prf_z', name: 'Zed', priority: 200 });
+ const names = m.tryOrder([machine, personal, work, extra, profile({ id: 'p4', name: 'Four', priority: 300 })], 'claude', NOW).map((p) => p.name);
+ assert.deepEqual(names, ['Personal', 'Work', 'Zed']);
+ assert.deepEqual(m.tryOrder([machine], 'claude', NOW), []);
+});
+
+test('an unusable default is skipped when a backup can run', () => {
+ const out = { ...personal, limited_until: '2026-10-17T21:00:00Z' };
+ assert.deepEqual(m.tryOrder([out, work], 'claude', NOW).map((p) => p.name), ['Work']);
+ // Nothing else to try: the default stays, so the turn reports why.
+ assert.deepEqual(m.tryOrder([out], 'claude', NOW).map((p) => p.name), ['Personal']);
+});
+
+test("Oleks: Claude runs on Claude Code CLI through Personal, with the This machine fallback spelled out", () => {
+ const [row, ...rest] = m.routeSummary([engine('claude'), engine('codex', { ready: false, status: 'signed_out' })], [machine, personal], NOW);
+ assert.equal(rest.length, 0);
+ assert.equal(row.label, 'Claude');
+ assert.equal(row.engine, 'Claude Code CLI');
+ assert.deepEqual(row.account, { name: 'Personal', detail: '[email protected]', otherProvider: false });
+ assert.deepEqual(row.then, []);
+ assert.equal(row.defaultModel, 'Claude Sonnet');
+ assert.equal(row.fallback, 'If you switch off every Claude account, kwants use This machine.');
+});
+
+test('backups are listed in order', () => {
+ const [row] = m.routeSummary([engine('claude')], [machine, personal, work], NOW);
+ assert.equal(row.account.name, 'Personal');
+ assert.deepEqual(row.then, ['Work']);
+});
+
+test('an account on another provider is marked as such', () => {
+ const bedrock = { ...personal, account_label: 'Amazon Bedrock' };
+ const [row] = m.routeSummary([engine('claude')], [machine, bedrock], NOW);
+ assert.deepEqual(row.account, { name: 'Personal', detail: 'via Amazon Bedrock', otherProvider: true });
+});
+
+test('with every account off, turns use This machine', () => {
+ const [row] = m.routeSummary([engine('claude')], [machine, { ...personal, enabled: false }], NOW);
+ assert.equal(row.account.name, 'This machine');
+ assert.equal(row.account.otherProvider, true);
+ assert.equal(row.engine, 'Claude Code CLI');
+});
+
+test('nothing ready means no rows; an API key from Settings shows as such', () => {
+ assert.deepEqual(m.routeSummary([engine('claude', { ready: false })], [machine, personal], NOW), []);
+ const [row] = m.routeSummary([engine('anthropic_api')], [], NOW);
+ assert.equal(row.engine, 'Anthropic API key');
+ assert.equal(row.account.name, 'API key in Settings');
+});