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
Engines & accounts: one card per engine with its accounts; drop LLM profiles
Lin (kwant bot)e2adac2688bd
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 7e6e5a4d..c7ba5667 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -64,7 +64,6 @@ import { AwayItem, affectsAway, awayApi, awayTarget } from './away';// so both load right after start-up and opening them never waits.const NewAgentModal = lazy(() => import('./components/NewAgentModal').then((m) => ({ default: m.NewAgentModal })));const McpServersModal = lazy(() => import('./components/McpServersModal').then((m) => ({ default: m.McpServersModal })));-const ProfilesModal = lazy(() => import('./components/ProfilesModal').then((m) => ({ default: m.ProfilesModal })));const SettingsModal = lazy(() => import('./components/SettingsModal').then((m) => ({ default: m.SettingsModal })));const ChannelInstructionsModal = lazy(() =>import('./components/ChannelInstructionsModal').then((m) => ({ default: m.ChannelInstructionsModal })),@@ -148,7 +147,6 @@ export const App: React.FC = () => {setIsSettingsOpen(true);};const [isMcpOpen, setIsMcpOpen] = useState(false);- const [isProfilesOpen, setIsProfilesOpen] = useState(false);const [isSearchOpen, setIsSearchOpen] = useState(false);const [isRoutinesOpen, setIsRoutinesOpen] = useState(false);const [editingChannelInstructions, setEditingChannelInstructions] = useState<Channel | null>(null);@@ -1690,7 +1688,6 @@ export const App: React.FC = () => {}};- const closeProfiles = useCallback(() => setIsProfilesOpen(false), []);const isCurrentContextStreaming = openCtx in live;const openTurns = turnsIn(turns, openCtx);@@ -1959,7 +1956,7 @@ export const App: React.FC = () => {joinTeamName={newAgentTeam?.name}takenNames={kwants.map((k) => k.name)}profiles={profiles}- onManageProfiles={() => setIsProfilesOpen(true)}+ onManageProfiles={openSettings}onManageServers={() => setIsMcpOpen(true)}onOpenSettings={openSettings}onSignInClaude={openClaudeSignIn}@@ -1975,7 +1972,7 @@ export const App: React.FC = () => {kwants={kwants}channels={channels}profiles={profiles}- onManageProfiles={() => setIsProfilesOpen(true)}+ onManageProfiles={openSettings}onManageServers={() => setIsMcpOpen(true)}onOpenSettings={openSettings}onSignInClaude={openClaudeSignIn}@@ -2018,17 +2015,13 @@ export const App: React.FC = () => {setIsSettingsOpen(false);setIsMcpOpen(true);}}- onOpenProfiles={() => {- setIsSettingsOpen(false);- setIsProfilesOpen(true);- }}+ onProfilesChanged={setProfiles}/></Suspense>{/* MCP tool servers (opened last so it sits above the agent modal) */}<Suspense fallback={null}><McpServersModal isOpen={isMcpOpen} onClose={() => setIsMcpOpen(false)} kwants={kwants} />- <ProfilesModal isOpen={isProfilesOpen} onClose={closeProfiles} onProfilesChanged={setProfiles} />{isSearchOpen && <SearchModal isOpen onClose={() => setIsSearchOpen(false)} kwants={kwants} onJump={handleJump} />}{isRoutinesOpen && <RoutinesModal isOpen onClose={() => setIsRoutinesOpen(false)} kwants={kwants} channels={channels} />}</Suspense>diff --git a/frontend/src/claudeLogin.ts b/frontend/src/claudeLogin.tsindex c979723f..3d93c3d4 100644--- a/frontend/src/claudeLogin.ts+++ b/frontend/src/claudeLogin.ts@@ -83,6 +83,6 @@ export function isClaudeSignInUrl(url: string | null | undefined): url is string}}-/** The Claude Code CLI is installed and switched on but signed out, so "Sign in with Claude" fixes it. */+/** The Claude Code CLI is on but signed out and no other Claude account is ready, so "Sign in with Claude" fixes it. */export const claudeNeedsSignIn = (engines: EngineInfo[] | null | undefined) =>- !!engines?.some((e) => e.id === 'claude' && e.enabled !== false && e.status === 'signed_out');+ !!engines?.some((e) => e.id === 'claude' && e.enabled !== false && e.status === 'signed_out' && e.ready !== true);diff --git a/frontend/src/components/ProfilesModal.tsx b/frontend/src/components/EngineAccounts.tsxsimilarity index 51%rename from frontend/src/components/ProfilesModal.tsxrename to frontend/src/components/EngineAccounts.tsxindex 9b283872..468e81b6 100644--- a/frontend/src/components/ProfilesModal.tsx+++ b/frontend/src/components/EngineAccounts.tsx@@ -1,191 +1,134 @@-import React, { useCallback, useEffect, useRef, useState } from 'react';-import {- X,- UserRound,- Plus,- Trash2,- Pencil,- Check,- Star,- KeyRound,- LogIn,- LogOut,- Loader2,- ExternalLink,- Copy,- RefreshCw,-} from 'lucide-react';+import React, { useEffect, useRef, useState } from 'react';+import { Check, Copy, ExternalLink, KeyRound, Loader2, LogIn, LogOut, Pencil, Plus, Star, Trash2 } from 'lucide-react';import { playSfx } from '../audio/chiptune';-import {- ENGINES,- Engine,- KIND_LABELS,- Login,- Profile,- isLoginDone,- profileStatus,- profilesApi,- profilesForEngine,- safeExternalUrl,-} from '../profiles';--interface ProfilesModalProps {- isOpen: boolean;- onClose: () => void;- /** Called with the fresh list after every change, so kwant pickers stay current. */- onProfilesChanged?: (profiles: Profile[]) => void;-}+import type { EngineInfo, Tone } from '../engines';+import { KIND_LABELS, Login, Profile, isLoginDone, newAccountFor, profileStatus, 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';const smallBtn =- 'inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium border transition-colors disabled:opacity-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-500';+ 'inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium border transition-colors disabled:opacity-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-sky-400';const quietBtn = `${smallBtn} border-zinc-700/70 bg-zinc-800/70 text-zinc-200 hover:bg-zinc-700`;-const toneClass = { ok: 'text-emerald-300', warn: 'text-amber-300', error: 'text-rose-300', muted: 'text-zinc-500' };-const dotClass = { ok: 'bg-emerald-400', warn: 'bg-amber-400', error: 'bg-rose-500', muted: 'bg-zinc-600' };--export const ProfilesModal: React.FC<ProfilesModalProps> = ({ isOpen, onClose, onProfilesChanged }) => {- const [profiles, setProfiles] = useState<Profile[] | null>(null);- const [loadError, setLoadError] = useState<string | null>(null);- const [adding, setAdding] = useState<Engine | null>(null);- const changedRef = useRef(onProfilesChanged);- changedRef.current = onProfilesChanged;- const closeRef = useRef(onClose);- closeRef.current = onClose;-- const reload = useCallback(async () => {- try {- const list = await profilesApi.list();- setProfiles(list);- setLoadError(null);- changedRef.current?.(list);- } catch (e) {- setLoadError(e instanceof Error ? e.message : 'Could not load profiles.');- }- }, []);-- useEffect(() => {- if (!isOpen) return;- setProfiles(null);- setAdding(null);- reload();- const onKey = (e: KeyboardEvent) => {- if (e.key === 'Escape') closeRef.current();- };- window.addEventListener('keydown', onKey);- return () => window.removeEventListener('keydown', onKey);- }, [isOpen, reload]);+const primaryBtn = `${smallBtn} border-sky-500/40 bg-sky-600 text-white hover:bg-sky-500`;++const PILL: Record<Tone, string> = {+ ok: 'border-emerald-500/30 bg-emerald-500/10 text-emerald-200',+ warn: 'border-amber-500/30 bg-amber-500/10 text-amber-200',+ 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',+};+const PILL_DOT: Record<Tone, string> = {+ ok: 'bg-emerald-400',+ warn: 'bg-amber-400',+ error: 'bg-rose-400',+ muted: 'bg-zinc-500',+ busy: 'bg-sky-400 animate-pulse motion-reduce:animate-none',+};- if (!isOpen) return null;+/** A status in words with a colored dot, so it never relies on color alone. */+export const StatusPill: React.FC<{ tone: Tone; children: React.ReactNode; className?: string }> = ({ tone, children, className = '' }) => (+ <span className={`inline-flex items-center gap-1.5 px-1.5 py-0.5 rounded-full border text-[10.5px] font-medium whitespace-nowrap ${PILL[tone]} ${className}`}>+ <span className={`w-1.5 h-1.5 rounded-full ${PILL_DOT[tone]}`} aria-hidden="true" />+ {children}+ </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' };+ switch (engine.status) {+ case 'ready':+ return { tone: 'ok', text: p.account_label ? `Signed in as ${p.account_label}` : 'Signed in' };+ case 'signed_out':+ return { tone: 'warn', text: 'Not signed in' };+ case 'not_installed':+ return { tone: 'muted', text: 'Not installed' };+ case 'checking':+ return { tone: 'busy', text: 'Checking…' };+ case 'error':+ return { tone: 'error', text: 'Check failed' };+ default:+ return profileStatus(p);+ }+}+/**+ * 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).+ */+export const AccountList: React.FC<{+ engine: EngineInfo;+ accounts: Profile[];+ onChanged: () => Promise<void>;+ hostAction?: React.ReactNode;+}> = ({ engine, accounts, onChanged, hostAction }) => {+ const [adding, setAdding] = useState(false);+ const addRef = useRef<HTMLButtonElement>(null);+ const spec = newAccountFor(engine.id);return (- <div className="fixed inset-0 z-50 bg-black/70 backdrop-blur-sm flex items-center justify-center p-2 sm:p-4" onMouseDown={(e) => e.target === e.currentTarget && onClose()}>- <div- role="dialog"- aria-modal="true"- aria-labelledby="profiles-title"- className="bg-zinc-900 border border-zinc-800 rounded-2xl max-w-2xl w-full max-h-[94vh] overflow-y-auto p-4 sm:p-6 text-zinc-100 shadow-2xl space-y-5"- >- <div className="flex items-center justify-between border-b border-zinc-800 pb-4">- <div className="flex items-center gap-2.5">- <div className="w-8 h-8 rounded-lg bg-sky-500/10 border border-sky-500/20 flex items-center justify-center text-sky-400">- <UserRound size={16} />- </div>- <div>- <h2 id="profiles-title" className="text-sm font-semibold text-zinc-100">LLM profiles</h2>- <p className="text-xs text-zinc-400">Accounts each engine can use, like a work and a personal subscription</p>- </div>- </div>+ <div className="space-y-2">+ {accounts.length > 0 ? (+ <ul className="space-y-1.5" aria-label={`${engine.name} accounts`}>+ {accounts.map((p) => (+ <AccountRow+ key={p.id}+ profile={p}+ engine={engine}+ inUse={engine.uses?.profile_id === p.id}+ onChanged={onChanged}+ hostAction={p.kind === 'system' ? hostAction : undefined}+ />+ ))}+ </ul>+ ) : (+ <p className="text-[11px] text-zinc-500">{spec?.kind === 'api_key' ? 'No accounts with a key yet.' : 'No accounts yet.'}</p>+ )}+ {spec &&+ (adding ? (+ <AddAccountForm+ spec={spec}+ onCancel={() => {+ setAdding(false);+ requestAnimationFrame(() => addRef.current?.focus());+ }}+ onCreated={async () => {+ setAdding(false);+ playSfx('coin');+ await onChanged();+ }}+ />+ ) : (<button+ ref={addRef}type="button"onClick={() => {playSfx('click');- onClose();+ setAdding(true);}}- aria-label="Close"- className="p-1.5 rounded-lg text-zinc-400 hover:text-zinc-100 hover:bg-zinc-800 transition-colors"+ className={quietBtn}>- <X size={18} />+ <Plus size={12} aria-hidden="true" /> {spec.kind === 'api_key' ? 'Add an account with a key' : 'Add account'}</button>- </div>-- <p className="text-[11px] text-zinc-500 leading-relaxed">- Kwants use their engine's <span className="text-zinc-300">default</span> profile unless you pick one for them. When a profile runs out- of usage or is signed out before anything happened in a turn, the turn moves to the next enabled profile (lowest priority number- first).- </p>-- {loadError && (- <div className="flex items-center justify-between gap-2 bg-rose-500/10 border border-rose-500/20 text-rose-300 px-3 py-2 rounded-lg text-xs" role="alert">- <span>{loadError}</span>- <button type="button" onClick={reload} className={quietBtn}>- <RefreshCw size={12} /> Retry- </button>- </div>- )}-- {!profiles && !loadError && (- <p className="flex items-center gap-2 text-xs text-zinc-400" role="status">- <Loader2 size={14} className="animate-spin motion-reduce:animate-none" /> Loading profiles…- </p>- )}-- {profiles &&- ENGINES.map((engine) => {- const list = profilesForEngine(profiles, engine.id);- return (- <section key={engine.id} aria-labelledby={`engine-${engine.id}`} className="space-y-2">- <div className="flex items-center justify-between">- <h3 id={`engine-${engine.id}`} className="text-xs font-semibold text-zinc-300">- {engine.label}- </h3>- {adding !== engine.id && (- <button- type="button"- onClick={() => {- playSfx('click');- setAdding(engine.id);- }}- className={quietBtn}- >- <Plus size={12} /> Add profile- </button>- )}- </div>- {list.length === 0 && adding !== engine.id && <p className="text-[11px] text-zinc-500">No profiles yet.</p>}- <ul className="space-y-2">- {list.map((p) => (- <ProfileCard key={p.id} profile={p} onChanged={reload} />- ))}- </ul>- {adding === engine.id && (- <AddProfileForm- engine={engine.id}- onCancel={() => setAdding(null)}- onCreated={async () => {- setAdding(null);- playSfx('coin');- await reload();- }}- />- )}- </section>- );- })}- </div>+ ))}</div>);};-const AddProfileForm: React.FC<{ engine: Engine; onCancel: () => void; onCreated: () => void }> = ({ engine, onCancel, onCreated }) => {+const AddAccountForm: React.FC<{+ spec: { engine: Profile['engine']; kind: 'cli_home' | 'api_key' };+ onCancel: () => void;+ onCreated: () => void;+}> = ({ spec, onCancel, onCreated }) => {+ const { engine, kind } = spec;const [name, setName] = useState('');- const [kind, setKind] = useState<'cli_home' | 'api_key'>('cli_home');const [apiKey, setApiKey] = useState('');const [homeDir, setHomeDir] = useState('');const [isDefault, setIsDefault] = useState(false);const [busy, setBusy] = useState(false);const [error, setError] = useState<string | null>(null);- const id = `new-${engine}`;+ const id = `new-${engine}-${kind}`;const submit = async (e: React.FormEvent) => {e.preventDefault();@@ -204,76 +147,74 @@ const AddProfileForm: React.FC<{ engine: Engine; onCancel: () => void; onCreatedsetApiKey('');onCreated();} catch (err) {- setError(err instanceof Error ? err.message : 'Could not create the profile.');+ setError(err instanceof Error ? err.message : 'Could not add the account.');} finally {setBusy(false);}};return (- <form onSubmit={submit} className="bg-zinc-950/60 border border-sky-500/30 rounded-xl p-3 space-y-3">- <div className="grid sm:grid-cols-2 gap-3">- <div>- <label htmlFor={`${id}-name`} className="block text-[11px] font-medium text-zinc-400 mb-1">- Name- </label>- <input id={`${id}-name`} autoFocus required maxLength={60} value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Work" className={input} />- </div>- <fieldset>- <legend className="block text-[11px] font-medium text-zinc-400 mb-1">Signs in with</legend>- <div className="flex p-0.5 rounded-lg bg-zinc-950 border border-zinc-800">- {(['cli_home', 'api_key'] as const).map((k) => (- <label- key={k}- className={`flex-1 text-center px-2 py-1.5 rounded-md text-[11px] font-medium cursor-pointer transition-colors has-[:focus-visible]:outline has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-sky-500 ${- kind === k ? 'bg-sky-500/15 text-sky-200' : 'text-zinc-500 hover:text-zinc-300'- }`}- >- <input type="radio" name={`${id}-kind`} value={k} checked={kind === k} onChange={() => setKind(k)} className="sr-only" />- {KIND_LABELS[k]}- </label>- ))}- </div>- </fieldset>+ <form+ onSubmit={submit}+ onKeyDown={(e) => {+ if (e.key === 'Escape') {+ e.stopPropagation();+ onCancel();+ }+ }}+ className="bg-zinc-950/60 border border-sky-500/30 rounded-lg p-3 space-y-3"+ aria-label="New account"+ >+ <div>+ <label htmlFor={`${id}-name`} className="block text-[11px] font-medium text-zinc-400 mb-1">+ Name+ </label>+ <input id={`${id}-name`} autoFocus required maxLength={60} value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Work" className={input} /></div>{kind === 'api_key' ? (<div><label htmlFor={`${id}-key`} className="block text-[11px] font-medium text-zinc-400 mb-1">- API key <span className="text-zinc-600 font-normal">· optional now, stored write-only</span>+ API key <span className="text-zinc-600 font-normal">· can be added later, never shown again</span></label><input id={`${id}-key`} type="password" autoComplete="off" spellCheck={false} value={apiKey} onChange={(e) => setApiKey(e.target.value)} className={input} /></div>) : (<div><label htmlFor={`${id}-home`} className="block text-[11px] font-medium text-zinc-400 mb-1">- Config folder <span className="text-zinc-600 font-normal">· optional; empty keeps a private one kwnt manages</span>+ Config folder <span className="text-zinc-600 font-normal">· optional; leave empty and kwnt keeps its own</span></label><input id={`${id}-home`} value={homeDir} onChange={(e) => setHomeDir(e.target.value)} placeholder="/home/me/.claude-work" className={`${input} font-mono`} />- <p className="mt-1 text-[11px] text-zinc-500">After creating it, use “Sign in” to log this profile into its own account.</p>+ <p className="mt-1 text-[11px] text-zinc-500">Next, use “Sign in” on the new account to log it in.</p></div>)}<label className="flex items-center gap-2 text-[11px] text-zinc-300"><input type="checkbox" checked={isDefault} onChange={(e) => setIsDefault(e.target.checked)} className="accent-sky-500" />- Make it the default for this engine+ Make it the default</label>- {error && <p className="text-[11px] text-rose-400" role="alert">{error}</p>}+ {error && (+ <p className="text-[11px] text-rose-300" role="alert">+ {error}+ </p>+ )}<div className="flex justify-end gap-2">- <button type="button" onClick={onCancel} className="px-3 py-1.5 rounded-lg text-xs font-medium text-zinc-300 hover:bg-zinc-800 transition-colors">+ <button type="button" onClick={onCancel} className={quietBtn}>Cancel</button>- <button- type="submit"- disabled={busy || !name.trim()}- className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-sky-600 hover:bg-sky-500 transition-colors disabled:opacity-50"- >- {busy && <Loader2 size={12} className="animate-spin motion-reduce:animate-none" />} Create profile+ <button type="submit" disabled={busy || !name.trim()} className={primaryBtn}>+ {busy && <Loader2 size={12} className="animate-spin motion-reduce:animate-none" aria-hidden="true" />} Add account</button></div></form>);};-const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }> = ({ profile: p, onChanged }) => {+const AccountRow: React.FC<{+ profile: Profile;+ engine: EngineInfo;+ inUse: boolean;+ onChanged: () => Promise<void>;+ hostAction?: React.ReactNode;+}> = ({ profile: p, engine, inUse, onChanged, hostAction }) => {const [editingName, setEditingName] = useState(false);const [name, setName] = useState(p.name);const [priority, setPriority] = useState(String(p.priority));@@ -283,8 +224,9 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }const [keyOpen, setKeyOpen] = useState(false);const [keyValue, setKeyValue] = useState('');const [login, setLogin] = useState<Login | null>(null);- const status = profileStatus(p);+ const status = accountStatus(p, engine);const isSystem = p.kind === 'system';+ const nameId = `account-${p.id}-name`;useEffect(() => setName(p.name), [p.name]);useEffect(() => setPriority(String(p.priority)), [p.priority]);@@ -297,7 +239,7 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }after?.();await onChanged();} catch (e) {- setError(e instanceof Error ? e.message : 'That didn’t work.');+ setError(e instanceof Error ? e.message : 'That didn’t work. Try again.');} finally {setBusy(false);}@@ -323,8 +265,12 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }};return (- <li className={`rounded-xl border p-3 space-y-2 ${p.enabled ? 'border-zinc-800 bg-zinc-950/60' : 'border-zinc-800/60 bg-zinc-950/30'}`}>- <div className="flex flex-wrap items-center gap-2">+ <li+ data-account={p.kind}+ 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'}`}+ >+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1">{editingName ? (<formclassName="flex items-center gap-1.5"@@ -334,7 +280,7 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }}}><label htmlFor={`name-${p.id}`} className="sr-only">- Profile name+ Account name</label><inputid={`name-${p.id}`}@@ -349,46 +295,82 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }setEditingName(false);}}}- className={`${input} py-1 w-40`}+ className={`${input} py-1 w-36`}/><button type="submit" disabled={busy} className={quietBtn} aria-label="Save name"><Check size={12} /></button></form>) : (- <>- <span className="text-xs font-semibold text-zinc-100 truncate max-w-[14rem]">{p.name}</span>- <button type="button" onClick={() => setEditingName(true)} className="p-0.5 rounded text-zinc-500 hover:text-zinc-200" aria-label={`Rename ${p.name}`}>- <Pencil size={11} />- </button>- </>+ <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}`}+ >+ <Pencil size={11} />+ </button>+ )}+ </span>)}- <span className="px-1.5 py-0.5 rounded-md bg-zinc-800 text-[10px] text-zinc-400">{KIND_LABELS[p.kind]}</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} /> Default+ <Star size={9} aria-hidden="true" /> Default</span>)}- <span className={`ml-auto inline-flex items-center gap-1.5 text-[11px] ${toneClass[status.tone]}`}>- <span className={`w-1.5 h-1.5 rounded-full ${dotClass[status.tone]}`} aria-hidden="true" />+ {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}- </span>+ </StatusPill></div>- {p.home_dir && <p className="text-[10px] font-mono text-zinc-600 truncate" title={p.home_dir}>{p.home_dir}</p>}+ {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>+ )}- <div className="flex flex-wrap items-center gap-2">- <label className="inline-flex items-center gap-1.5 text-[11px] text-zinc-400">- <input- type="checkbox"- checked={p.enabled}+ {hostAction && <div>{hostAction}</div>}++ <div className="flex flex-wrap items-center gap-x-2 gap-y-1.5">+ {p.kind === 'cli_home' && !login && (+ <button+ type="button"disabled={busy}- onChange={(e) => run(() => profilesApi.update(p.id, { enabled: e.target.checked }))}- className="accent-sky-500"- />- Enabled- </label>- <label className="inline-flex items-center gap-1 text-[11px] text-zinc-400">+ onClick={() => run(async () => setLogin(await profilesApi.startLogin(p.id)))}+ className={p.signed_in ? quietBtn : primaryBtn}+ >+ <LogIn size={11} aria-hidden="true" /> {p.signed_in ? 'Sign in again' : 'Sign in'}+ </button>+ )}+ {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+ </button>+ )}+ {p.kind === 'api_key' && (+ <button type="button" disabled={busy} onClick={() => setKeyOpen((v) => !v)} className={p.has_key ? quietBtn : primaryBtn} aria-expanded={keyOpen}>+ <KeyRound size={11} aria-hidden="true" /> {p.has_key ? 'Replace key' : 'Add key'}+ </button>+ )}+ {p.kind === 'api_key' && p.has_key && (+ <button type="button" disabled={busy} onClick={() => run(() => profilesApi.removeKey(p.id))} className={quietBtn}>+ Remove key+ </button>+ )}+ {!p.is_default && (+ <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<inputtype="number"@@ -399,57 +381,47 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }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"+ 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>- <div className="ml-auto flex flex-wrap items-center gap-1.5">- {!p.is_default && (- <button type="button" disabled={busy} onClick={() => run(() => profilesApi.update(p.id, { is_default: true }))} className={quietBtn}>- <Star size={11} /> Make default- </button>- )}- {p.kind === 'cli_home' && !login && (- <button type="button" disabled={busy} onClick={() => run(async () => setLogin(await profilesApi.startLogin(p.id)))} className={quietBtn}>- <LogIn size={11} /> {p.signed_in ? 'Sign in again' : 'Sign in'}- </button>- )}- {p.kind === 'cli_home' && p.signed_in && (- <button type="button" disabled={busy} onClick={() => run(() => profilesApi.logout(p.id))} className={quietBtn}>- <LogOut size={11} /> Sign out- </button>- )}- {p.kind === 'api_key' && (- <button type="button" disabled={busy} onClick={() => setKeyOpen((v) => !v)} className={quietBtn} aria-expanded={keyOpen}>- <KeyRound size={11} /> {p.has_key ? 'Replace key' : 'Set key'}- </button>- )}- {p.kind === 'api_key' && p.has_key && (- <button type="button" disabled={busy} onClick={() => run(() => profilesApi.removeKey(p.id))} className={quietBtn}>- Remove key- </button>- )}- {!isSystem &&- (confirmDelete ? (- <span className="inline-flex items-center gap-1">- <span className="text-[11px] text-rose-300">Delete?</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`}- >- Delete- </button>- <button type="button" onClick={() => setConfirmDelete(false)} className={quietBtn}>- Keep- </button>- </span>- ) : (- <button type="button" disabled={busy} onClick={() => setConfirmDelete(true)} className={`${quietBtn} hover:text-rose-200`} aria-label={`Delete ${p.name}`}>- <Trash2 size={11} />+ <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>+ <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>- ))}- </div>+ <button type="button" onClick={() => setConfirmDelete(false)} className={quietBtn}>+ Keep+ </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>+ ))}</div>{confirmDelete && <p className="text-[11px] text-zinc-500">Kwants pinned to it go back to the default. Its folder stays on disk.</p>}@@ -484,7 +456,7 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }placeholder="Paste the key (it can't be shown again)"className={`${input} py-1`}/>- <button type="submit" disabled={busy || !keyValue.trim()} className={`${smallBtn} border-sky-500/40 bg-sky-600 text-white hover:bg-sky-500`}>+ <button type="submit" disabled={busy || !keyValue.trim()} className={primaryBtn}>Save</button></form>@@ -503,7 +475,11 @@ const ProfileCard: React.FC<{ profile: Profile; onChanged: () => Promise<void> }/>)}- {error && <p className="text-[11px] text-rose-400" role="alert">{error}</p>}+ {error && (+ <p className="text-[11px] text-rose-300" role="alert">+ {error}+ </p>+ )}</li>);};@@ -581,7 +557,7 @@ const LoginPanel: React.FC<{const failure =login.status === 'failed'- ? login.error || 'Sign-in failed.'+ ? login.error || 'Sign-in failed. Start it again.': login.status === 'expired'? 'The sign-in expired. Start it again.': login.status === 'cancelled'@@ -645,7 +621,7 @@ const LoginPanel: React.FC<{placeholder="Code"className={`${input} py-1 font-mono`}/>- <button type="submit" disabled={busy || !code.trim()} className={`${smallBtn} border-sky-500/40 bg-sky-600 text-white hover:bg-sky-500`}>+ <button type="submit" disabled={busy || !code.trim()} className={primaryBtn}>Submit</button></form>@@ -655,8 +631,16 @@ const LoginPanel: React.FC<{</p></>)}- {failure && <p className="text-[11px] text-rose-300" role="alert">{failure}</p>}- {error && <p className="text-[11px] text-rose-400" role="alert">{error}</p>}+ {failure && (+ <p className="text-[11px] text-rose-300" role="alert">+ {failure}+ </p>+ )}+ {error && (+ <p className="text-[11px] text-rose-300" role="alert">+ {error}+ </p>+ )}<div className="flex justify-end"><button type="button" disabled={busy} onClick={cancel} className={quietBtn}>{done ? 'Close' : 'Cancel sign-in'}diff --git a/frontend/src/components/EnginesPanel.tsx b/frontend/src/components/EnginesPanel.tsxindex d9d2d8e8..e1129936 100644--- a/frontend/src/components/EnginesPanel.tsx+++ b/frontend/src/components/EnginesPanel.tsx@@ -1,25 +1,21 @@import React, { useState } from 'react';import { AlertTriangle, ChevronDown, ChevronRight, Cpu, Key, Loader2, RefreshCw, Server } from 'lucide-react';-import { EngineInfo, Tone, checkedAgo, isAbsent, onlyCliReady, sortEngines, statusView } from '../engines';+import { EngineInfo, checkedAgo, engineSummary, isAbsent, isUsable, onlyCliReady, sortEngines, statusView } from '../engines';import { playSfx } from '../audio/chiptune';import type { EnginesApi } from '../useEngines';import { claudeNeedsSignIn } from '../claudeLogin';import { ClaudeSignIn, ClaudeSignOut } from './ClaudeSignIn';+import { AccountList, StatusPill } from './EngineAccounts';+import { Profile, accountUsable, accountsForCard, activeLimit, formatUntil } from '../profiles';+import type { ProfilesState } from '../useProfiles';-const DOT: Record<Tone, string> = {- ok: 'bg-emerald-400 shadow-sm shadow-emerald-500/50',- warn: 'bg-amber-400',- error: 'bg-rose-400',- muted: 'bg-zinc-600',- busy: 'bg-sky-400 animate-pulse motion-reduce:animate-none',-};-const TEXT: Record<Tone, string> = {+const SUMMARY_TEXT = {ok: 'text-emerald-300',- warn: 'text-amber-300',+ warn: 'text-amber-200',error: 'text-rose-300',- muted: 'text-zinc-500',+ muted: 'text-zinc-400',busy: 'text-sky-300',-};+} as const;const KIND_ICON = { cli: Cpu, api: Key, local: Server } as const;/** Inline `code` in a reason like "Not signed in: run `claude login`". */@@ -34,40 +30,63 @@ const withCode = (text: string) =>),);-export const EngineRow: React.FC<{ engine: EngineInfo; onToggle?: (on: boolean) => void; children?: React.ReactNode }> = ({ engine, onToggle, children }) => {+/** What the card summary needs from each account. */+const summaryAccounts = (accounts: Profile[], now: number) =>+ accounts.map((p) => {+ const limit = activeLimit(p.limited_until, now);+ return { name: p.kind === 'system' ? 'This machine' : p.name, usable: accountUsable(p, now), is_default: p.is_default, priority: p.priority, outUntil: limit ? formatUntil(limit, now) : null };+ });++/** One engine: its status, switch and models up top, and the accounts it can run on underneath. */+export const EngineCard: React.FC<{+ engine: EngineInfo;+ onToggle?: (on: boolean) => void;+ /** Its accounts, or undefined when they aren't known (still loading, or an older server). */+ accounts?: Profile[];+ onAccountsChanged?: () => Promise<void>;+ /** Sign in or out of "This machine". */+ hostAction?: React.ReactNode;+ now?: number;+}> = ({ engine, onToggle, accounts, onAccountsChanged, hostAction, now = Date.now() }) => {const view = statusView(engine);const Icon = KIND_ICON[engine.kind] ?? Cpu;const off = engine.enabled === false;+ const usable = isUsable(engine);const labelId = `engine-${engine.id}-name`;- // A sign-in button replaces "run `claude auth login`".- const showDetail = !off && engine.detail && engine.status !== 'ready' && !(children && engine.status === 'signed_out');+ const hasMachineRow = !!accounts?.some((p) => p.kind === 'system');+ // With no "This machine" row, Claude's sign-in button sits under the name and replaces "run `claude login`".+ const signInHere = !hasMachineRow && engine.id === 'claude' && !!hostAction;+ const summary =+ signInHere && engine.status === 'signed_out' && !usable && !off+ ? { text: 'Not signed in · Sign in below', tone: 'warn' as const }+ : engineSummary(engine, accounts ? summaryAccounts(accounts, now) : []);+ const showAccounts = engine.kind !== 'local' && accounts !== undefined && !!onAccountsChanged;return (- <li- data-engine={engine.id}- data-status={off ? 'off' : engine.status}- className="bg-zinc-900/90 px-3 py-2 rounded-lg border border-zinc-800 text-xs"- >- <div className="flex items-start gap-2.5">- <span className={`mt-1 w-2 h-2 shrink-0 rounded-full ${DOT[view.tone]}`} aria-hidden="true" />- <div className="flex-1 min-w-0">- <div className="flex items-center gap-1.5 flex-wrap">- <Icon size={12} className="text-zinc-500 shrink-0" aria-hidden="true" />- <span id={labelId} className={`font-medium ${off ? 'text-zinc-500' : 'text-zinc-200'}`}>+ <li data-engine={engine.id} data-status={off ? 'off' : usable ? 'ready' : engine.status} aria-labelledby={labelId} className="rounded-xl border border-zinc-800 bg-zinc-900/90 text-xs">+ <div className="flex items-start gap-2.5 p-3">+ <Icon size={14} className={`mt-0.5 shrink-0 ${usable ? 'text-sky-400' : 'text-zinc-500'}`} aria-hidden="true" />+ <div className="flex-1 min-w-0 space-y-1">+ <div className="flex items-center gap-x-1.5 gap-y-1 flex-wrap">+ <h4 id={labelId} className={`font-semibold ${off ? 'text-zinc-400' : 'text-zinc-100'}`}>{engine.name}- </span>+ </h4>{engine.version && <span className="text-[10px] font-mono text-zinc-500">v{engine.version}</span>}+ <StatusPill tone={view.tone}>{view.label}</StatusPill></div>- {showDetail && <p className="mt-0.5 text-[11px] text-zinc-400 leading-snug break-words">{withCode(engine.detail!)}</p>}- {!off && engine.status === 'ready' && engine.models.length > 0 && (- <p className="mt-0.5 text-[11px] text-zinc-500 truncate" title={engine.models.map((m) => m.label).join(', ')}>+ <p data-summary className={`text-[11px] leading-snug break-words ${SUMMARY_TEXT[summary.tone]}`}>+ {withCode(summary.text)}+ </p>+ {usable && engine.models.length > 0 && (+ <p className="text-[11px] text-zinc-500 truncate" title={engine.models.map((m) => m.label).join(', ')}>{engine.models.length === 1 ? '1 model' : `${engine.models.length} models`}{' · '}{engine.models.slice(0, 3).map((m) => m.label).join(', ')}{engine.models.length > 3 ? '…' : ''}</p>)}+ {/* Without a "This machine" row to hold it, the sign-in sits here. */}+ {signInHere && <div className="pt-0.5">{hostAction}</div>}</div>- <span className={`shrink-0 text-[11px] font-mono ${TEXT[view.tone]}`}>{view.label}</span>{onToggle && typeof engine.enabled === 'boolean' && (<buttontype="button"@@ -79,57 +98,111 @@ export const EngineRow: React.FC<{ engine: EngineInfo; onToggle?: (on: boolean)playSfx('click');onToggle(off);}}- className={`relative shrink-0 mt-px w-8 h-[18px] rounded-full transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-500 ${+ className={`relative shrink-0 mt-px w-8 h-[18px] rounded-full transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400 ${off ? 'bg-zinc-700' : 'bg-sky-600'}`}>+ <span className="sr-only">{off ? 'Off' : 'On'}</span><span+ aria-hidden="true"className={`absolute top-[2px] left-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform motion-reduce:transition-none ${off ? '' : 'translate-x-[14px]'}`}/></button>)}</div>- {/* Full width under the name, lined up with it */}- {!off && children && <div className="pl-[18px]">{children}</div>}+ {showAccounts && (+ <div className="border-t border-zinc-800/80 px-3 pt-2 pb-3">+ <AccountList engine={engine} accounts={accounts!} onChanged={onAccountsChanged!} hostAction={hostAction} />+ </div>+ )}</li>);};-/** Sign in or out of Claude Code from its row; nothing for other engines. */-const accountAction = (e: EngineInfo, api: EnginesApi, focusClaudeSignIn?: number) => {- if (e.id !== 'claude' || e.enabled === false) return null;- if (e.status === 'signed_out') return <ClaudeSignIn onSignedIn={api.reload} focusRequest={focusClaudeSignIn} />;- if (e.status === 'ready') return <ClaudeSignOut onSignedOut={api.apply} />;+/** "This machine"'s sign-in or sign-out: Claude's in the page, the other CLIs' as the command to run. */+const hostAction = (e: EngineInfo, api: EnginesApi, onSignedIn: () => void, focusClaudeSignIn?: number) => {+ if (e.enabled === false || e.kind !== 'cli') return null;+ if (e.id === 'claude') {+ if (e.status === 'signed_out') return <ClaudeSignIn onSignedIn={onSignedIn} focusRequest={focusClaudeSignIn} />;+ if (e.status === 'ready') return <ClaudeSignOut onSignedOut={api.apply} />;+ return null;+ }+ if (e.status === 'signed_out' && e.detail) return <p className="text-[11px] text-zinc-400 leading-snug">{withCode(e.detail)}</p>;return null;};-/** The Settings "Engines" list: honest status per engine, ready ones first, with Re-check.+/** The headline over the cards: how many can run, or the one thing to do when none can. */+function headline(engines: EngineInfo[], profiles: Profile[] | null, now: number): string {+ const ready = engines.filter(isUsable).length;+ if (ready > 0) {+ return `${ready} ready${onlyCliReady(engines) ? ', all through your signed-in CLIs, so no API keys are needed' : ''}. Kwants only use engines that are ready.`;+ }+ // An engine that's off but has an account ready is the quickest fix.+ for (const e of sortEngines(engines)) {+ if (e.enabled !== false || !profiles) continue;+ const s = engineSummary(e, summaryAccounts(accountsForCard(profiles, e.id), now));+ if (s.text.startsWith('Off · Turn on to use ') && !s.text.endsWith(' it')) return `No engine can run right now. ${e.name} is off: turn it on to use ${s.text.slice('Off · Turn on to use '.length)}.`;+ }+ return claudeNeedsSignIn(engines)+ ? 'No engine can run right now. Sign in with Claude below, or add an account.'+ : 'No engine can run right now. Turn on an engine and sign in to one of its accounts below.';+}++/** 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; now?: number; focusClaudeSignIn?: number }> = ({ api, now = Date.now(), focusClaudeSignIn }) => {- const { engines, error, rechecking, recheck, setEnabled } = api;+export const EnginesPanel: React.FC<{ api: EnginesApi; accounts?: ProfilesState; now?: number; focusClaudeSignIn?: number }> = ({+ api,+ accounts,+ now = Date.now(),+ focusClaudeSignIn,+}) => {+ const { engines, error, rechecking, recheck, setEnabled, reload } = api;const [showAbsent, setShowAbsent] = useState(false);+ const profiles = accounts?.profiles ?? null;const sorted = engines ? sortEngines(engines) : [];- const present = sorted.filter((e) => !isAbsent(e));- const absent = sorted.filter(isAbsent);- const readyCount = sorted.filter((e) => e.status === 'ready' && e.enabled !== false).length;+ const cardAccounts = (e: EngineInfo) => (profiles ? accountsForCard(profiles, e.id) : undefined);+ // An engine missing here but with accounts of its own (an API key account, say) still gets a card.+ const present = sorted.filter((e) => !isAbsent(e) || (cardAccounts(e)?.length ?? 0) > 0);+ 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);+ // 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.+ const accountsChanged = async () => {+ await Promise.all([accounts?.reload(), reload()]);+ window.setTimeout(reload, 1500);+ };+ const signedIn = () => void accountsChanged();++ const card = (e: EngineInfo) => (+ <EngineCard+ key={e.id}+ engine={e}+ now={now}+ onToggle={(on) => setEnabled(e.id, on)}+ accounts={cardAccounts(e)}+ onAccountsChanged={accounts ? accountsChanged : undefined}+ hostAction={hostAction(e, api, signedIn, focusClaudeSignIn)}+ />+ );+return (- <section aria-labelledby="engines-title" className="bg-zinc-950/60 p-4 rounded-xl border border-zinc-800 space-y-3">+ <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</h3>+ <h3 id="engines-title" className="text-xs font-medium text-zinc-300">Engines & accounts</h3><buttontype="button"onClick={() => {playSfx('click');recheck();+ 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"+ 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">- {rechecking ? <Loader2 size={12} className="animate-spin motion-reduce:animate-none" /> : <RefreshCw size={12} />}+ {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>@@ -139,27 +212,37 @@ export const EnginesPanel: React.FC<{ api: EnginesApi; now?: number; focusClaude? 'Checking which engines can run…': engines.length === 0? 'This server doesn’t report engine status yet.'- : readyCount === 0- ? claudeNeedsSignIn(engines)- ? 'No engine can run right now. Sign in with Claude below, or add an API key.'- : 'No engine can run right now. Sign in to a CLI below or add an API key.'- : `${readyCount} ready${onlyCliReady(engines) ? ', all through your signed-in CLIs, so no API keys are needed' : ''}. Kwants only use engines that are ready.`}+ : headline(engines, profiles, now)}{ago && <span className="text-zinc-500"> Checked {ago}.</span>}</p>{error && (<p role="alert" className="flex items-center gap-1.5 text-[11px] text-rose-300">- <AlertTriangle size={12} /> {error}+ <AlertTriangle size={12} aria-hidden="true" /> {error}+ </p>+ )}+ {accounts?.error && (+ <div role="alert" className="flex flex-wrap items-center gap-2 rounded-lg border border-rose-500/20 bg-rose-500/10 px-3 py-2 text-[11px] text-rose-200">+ <AlertTriangle size={12} aria-hidden="true" />+ <span className="flex-1 min-w-0">Couldn’t load accounts: {accounts.error}</span>+ <button+ type="button"+ onClick={() => accounts.reload()}+ className="inline-flex items-center gap-1 px-2 py-1 rounded-md border border-rose-500/30 text-rose-100 hover:bg-rose-500/20 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"+ >+ <RefreshCw size={11} aria-hidden="true" /> Try again+ </button>+ </div>+ )}+ {accounts && !profiles && !accounts.error && engines && engines.length > 0 && (+ <p role="status" className="flex items-center gap-1.5 text-[11px] text-zinc-500">+ <Loader2 size={11} className="animate-spin motion-reduce:animate-none" aria-hidden="true" /> Loading accounts…</p>)}{present.length > 0 && (- <ul className="grid grid-cols-1 gap-2" aria-label="Engines on this computer">- {present.map((e) => (- <EngineRow key={e.id} engine={e} onToggle={(on) => setEnabled(e.id, on)}>- {accountAction(e, api, focusClaudeSignIn)}- </EngineRow>- ))}+ <ul className="grid grid-cols-1 gap-2.5" aria-label="Engines on this computer">+ {present.map(card)}</ul>)}@@ -170,16 +253,14 @@ export const EnginesPanel: React.FC<{ api: EnginesApi; now?: number; focusClaudearia-expanded={showAbsent}aria-controls="engines-absent"onClick={() => setShowAbsent((v) => !v)}- className="flex items-center gap-1 text-[11px] text-zinc-500 hover:text-zinc-300 transition-colors"+ className="flex items-center gap-1 text-[11px] text-zinc-500 hover:text-zinc-300 transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400 rounded">- {showAbsent ? <ChevronDown size={12} /> : <ChevronRight size={12} />}+ {showAbsent ? <ChevronDown size={12} aria-hidden="true" /> : <ChevronRight size={12} aria-hidden="true" />}Not available on this computer ({absent.length})</button>{showAbsent && (- <ul id="engines-absent" className="mt-2 grid grid-cols-1 gap-2">- {absent.map((e) => (- <EngineRow key={e.id} engine={e} onToggle={(on) => setEnabled(e.id, on)} />- ))}+ <ul id="engines-absent" className="mt-2 grid grid-cols-1 gap-2.5">+ {absent.map(card)}</ul>)}</div>diff --git a/frontend/src/components/NewAgentModal.tsx b/frontend/src/components/NewAgentModal.tsxindex a81241d7..ee80cdcf 100644--- a/frontend/src/components/NewAgentModal.tsx+++ b/frontend/src/components/NewAgentModal.tsx@@ -50,7 +50,7 @@ interface NewAgentModalProps {onManageServers?: () => void;/** Every LLM profile, for the profile picker. */profiles?: Profile[];- /** Opens the LLM profiles screen. */+ /** Opens Settings → Engines & accounts. */onManageProfiles?: () => void;/** Opens Settings → Engines. */onOpenSettings?: () => void;@@ -376,7 +376,7 @@ export const NewAgentModal: React.FC<NewAgentModalProps> = ({<div><div className="flex items-center justify-between mb-1"><label htmlFor="agent-profile" className="text-xs font-medium text-zinc-400">- Account (LLM profile)+ Account</label>{onManageProfiles && (<button@@ -384,7 +384,7 @@ export const NewAgentModal: React.FC<NewAgentModalProps> = ({onClick={onManageProfiles}className="flex items-center gap-0.5 text-[11px] text-zinc-500 hover:text-sky-300 transition-colors">- Manage profiles <ChevronRight size={11} />+ Manage accounts <ChevronRight size={11} /></button>)}</div>@@ -405,12 +405,12 @@ export const NewAgentModal: React.FC<NewAgentModalProps> = ({</option>))}{profileId && !engineProfiles.some((p) => p.id === profileId) && (- <option value={profileId}>Another engine's profile (cleared on save)</option>+ <option value={profileId}>Another engine's account (cleared on save)</option>)}</select><label className="mt-1.5 flex items-start gap-2 text-[11px] text-zinc-400"><input type="checkbox" checked={failover} onChange={(e) => setFailover(e.target.checked)} className="mt-0.5 accent-sky-500" />- <span>Switch to the engine's next profile when this one runs out of usage or is signed out</span>+ <span>Switch to the engine's next account when this one runs out of usage or is signed out</span></label></div>)}diff --git a/frontend/src/components/SettingsModal.tsx b/frontend/src/components/SettingsModal.tsxindex edd9f95d..9d8e62cd 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, UserRound, LogOut, Bell, AlertTriangle, Layers, Monitor } from 'lucide-react';+import { Key, Globe, X, Sparkles, Check, Plug, ChevronRight, LogOut, Bell, AlertTriangle, Layers, Monitor } from 'lucide-react';import { TURN_LIMITS, TurnLimitKey, limitError } from '../threads';import {BROWSER_NOTIFY_KEY,@@ -15,6 +15,8 @@ import { useAuth } from './AuthGate';import { ComputerModeControl, useComputerMode } from './ComputerModeSwitch';import { EnginesPanel } from './EnginesPanel';import { useEngines } from '../useEngines';+import { useProfiles } from '../useProfiles';+import type { Profile } from '../profiles';interface SettingsData {anthropic_api_key: string;@@ -47,15 +49,17 @@ interface SettingsModalProps {isOpen: boolean;onClose: () => void;onOpenTools?: () => void;- onOpenProfiles?: () => void;+ /** Gets the accounts list after every change, so kwant pickers stay current. */+ onProfilesChanged?: (profiles: Profile[]) => void;/** Changes to focus "Sign in with Claude" in Engines. */focusClaudeSignIn?: number;}-export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, onOpenTools, onOpenProfiles, focusClaudeSignIn }) => {+export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, onOpenTools, onProfilesChanged, focusClaudeSignIn }) => {const { authRequired, signOut } = useAuth();const computer = useComputerMode(isOpen);const engines = useEngines(isOpen);+ const accounts = useProfiles(isOpen, onProfilesChanged);const [settings, setSettings] = useState<SettingsData | null>(null);const [anthropicKey, setAnthropicKey] = useState('');const [xaiKey, setXaiKey] = useState('');@@ -198,7 +202,7 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o</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">Which engines can run, and the keys and accounts they use</p>+ <p className="text-xs text-zinc-400">Engines, the accounts they run on, and API keys</p></div></div>@@ -213,7 +217,7 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o</button></div>- <EnginesPanel api={engines} focusClaudeSignIn={focusClaudeSignIn} />+ <EnginesPanel api={engines} accounts={accounts} focusClaudeSignIn={focusClaudeSignIn} />{computer.state.settings && (<div className="bg-zinc-950/60 p-4 rounded-xl border border-zinc-800 space-y-3">@@ -228,26 +232,6 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, o</div>)}- {onOpenProfiles && (- <button- type="button"- onClick={() => {- playSfx('click');- onOpenProfiles();- }}- className="w-full flex items-center gap-3 p-3 rounded-xl border border-zinc-800 bg-zinc-950/60 hover:border-sky-500/40 text-left transition-colors group"- >- <span className="w-8 h-8 rounded-lg bg-sky-500/10 border border-sky-500/20 flex items-center justify-center text-sky-400">- <UserRound size={15} />- </span>- <span className="flex-1">- <span className="block text-xs font-medium text-zinc-200">LLM profiles</span>- <span className="block text-[11px] text-zinc-500">Work and personal accounts per engine, with automatic failover</span>- </span>- <ChevronRight size={15} className="text-zinc-500 group-hover:text-sky-300" />- </button>- )}-{onOpenTools && (<buttontype="button"diff --git a/frontend/src/engines.ts b/frontend/src/engines.tsindex d5714b1a..2f53ab99 100644--- a/frontend/src/engines.ts+++ b/frontend/src/engines.ts@@ -25,6 +25,10 @@ export interface EngineInfo {checked_at: string | null;/** Off in Settings: never checked or used. Missing on servers without the switch. */enabled?: boolean;+ /** On, and its own login or one of its accounts can run a kwant. Missing on older servers. */+ ready?: boolean;+ /** The account kwants run on now; null when not ready or the engine has no accounts. */+ uses?: { profile_id: string; label: string } | null;}/** What a kwant picks: the model family, whichever of its engines (CLI or key) can run it. */@@ -51,8 +55,12 @@ export const familyLabel = (f: Family) => FAMILIES.find((x) => x.id === f)?.labeexport type Tone = 'ok' | 'warn' | 'error' | 'muted' | 'busy';-export function statusView(e: Pick<EngineInfo, 'status' | 'enabled'> & { kind?: EngineKind }): { label: string; tone: Tone } {+/** 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');++export function statusView(e: Pick<EngineInfo, 'status' | 'enabled' | 'ready'> & { kind?: EngineKind }): { label: string; tone: Tone } {if (e.enabled === false || e.status === 'disabled') return { label: 'Off', tone: 'muted' };+ if (isUsable(e)) return { label: 'Ready', tone: 'ok' };switch (e.status) {case 'ready':return { label: 'Ready', tone: 'ok' };@@ -68,13 +76,11 @@ export function statusView(e: Pick<EngineInfo, 'status' | 'enabled'> & { kind?:}}-export const isUsable = (e: EngineInfo) => e.status === 'ready' && e.enabled !== false;-const RANK: Record<EngineStatus, number> = { ready: 0, checking: 1, error: 2, signed_out: 3, disabled: 4, not_installed: 5 };/** Ready first, then ones that need attention, switched-off ones, and not installed last. Stable. */export function sortEngines(list: EngineInfo[]): EngineInfo[] {- const rank = (e: EngineInfo) => (e.enabled === false ? 4 : RANK[e.status] ?? 1);+ const rank = (e: EngineInfo) => (e.enabled === false ? 4 : isUsable(e) ? 0 : RANK[e.status] === 0 ? 3 : RANK[e.status] ?? 1);return list.map((e, i) => ({ e, i })).sort((a, b) => rank(a.e) - rank(b.e) || a.i - b.i)@@ -82,7 +88,7 @@ export function sortEngines(list: EngineInfo[]): EngineInfo[] {}/** Engines that aren't on this computer at all, to fold away. An API engine with no key is "not installed". */-export const isAbsent = (e: EngineInfo) => e.status === 'not_installed' && e.enabled !== false;+export const isAbsent = (e: EngineInfo) => e.status === 'not_installed' && e.enabled !== false && !isUsable(e);/** Whether only CLIs can run things right now (so "no API keys needed" is true). */export const onlyCliReady = (list: EngineInfo[]) => {@@ -206,7 +212,11 @@ export function pickHealth(value: string, engines: EngineInfo[] | null): PickHea// Still being checked isn't broken yet.const mine = engines.filter((e) => FAMILY_OF[e.id] === family);if (mine.some((e) => e.status === 'checking' && e.enabled !== false)) return { kind: 'loading' };- const reason = mine.find((e) => e.enabled !== false && e.detail)?.detail ?? (mine.every((e) => e.enabled === false) && mine.length ? 'Switched off in Settings' : null);+ // The CLI that's installed but off says more than "No API key" on its API sibling.+ const installed = mine.filter((e) => e.status !== 'not_installed');+ const reason = installed.some((e) => e.enabled === false) || (mine.length > 0 && mine.every((e) => e.enabled === false))+ ? 'Switched off in Settings'+ : (installed.find((e) => e.detail) ?? mine.find((e) => e.enabled !== false && e.detail))?.detail ?? null;return { kind: 'engine_unavailable', family, reason };}// A model list we can't see (a CLI that lists none) can't prove a model is gone.@@ -267,3 +277,42 @@ export function checkedAgo(at: string | null, now = Date.now()): string | null {const h = Math.round(m / 60);return h < 24 ? `${h} h ago` : `${Math.round(h / 24)} d ago`;}++/** An account as the card summary needs it. */+export interface SummaryAccount {+ name: string;+ /** Signed in (or keyed), on, and not out of usage. */+ usable: boolean;+ is_default: boolean;+ priority: number;+ /** "back in 2 h" when it's out of usage. */+ outUntil?: string | null;+}++/** The line under an engine's name: which account kwants use, or the one next step. */+export function engineSummary(e: EngineInfo, accounts: SummaryAccount[] = []): { text: string; tone: Tone } {+ // The order turns try them: the default, then by priority.+ const next = [...accounts]+ .sort((a, b) => Number(b.is_default) - Number(a.is_default) || a.priority - b.priority)+ .find((a) => a.usable);+ if (e.enabled === false || e.status === 'disabled') {+ if (next) return { text: `Off · Turn on to use ${next.name}`, tone: 'muted' };+ return { text: e.kind === 'local' || accounts.length === 0 ? 'Off · Turn on to use it' : 'Off · Turn on, then sign in to an account', tone: 'muted' };+ }+ if (isUsable(e)) return e.uses ? { text: `Kwants use ${e.uses.label}`, tone: 'ok' } : { text: 'Kwants can use it', tone: 'ok' };+ switch (e.status) {+ case 'checking':+ return { text: 'Checking…', tone: 'busy' };+ case 'not_installed':+ if (e.kind === 'api') return { text: 'No key yet · Add a key below to use it', tone: 'muted' };+ return { text: e.detail ?? (e.kind === 'local' ? 'Not running on this computer' : 'Not installed on this computer'), tone: 'muted' };+ case 'error':+ return { text: `${e.detail ?? 'The check failed'} · Try Re-check`, tone: 'error' };+ default: {+ const out = accounts.find((a) => a.outUntil);+ if (out) return { text: `${out.name} is out of usage, back ${out.outUntil} · Sign in to another account below`, tone: 'warn' };+ if (accounts.length === 0) return { text: e.detail ?? 'Not signed in', tone: 'warn' };+ return { text: 'No account is signed in · Sign in to one below', tone: 'warn' };+ }+ }+}diff --git a/frontend/src/profiles.ts b/frontend/src/profiles.tsindex c43f4fe8..5fd152b7 100644--- a/frontend/src/profiles.ts+++ b/frontend/src/profiles.ts@@ -173,3 +173,35 @@ export function describeProfileSwitch(e: ProfileSwitchedEvent, kwantName: string: `${e.from_name} is out of usage.`;return { title: `${who} switched to ${e.to_name}`, detail: why };}++// ---- Accounts on the "Engines & accounts" cards ----++type EngineCardId = 'claude' | 'codex' | 'grok' | 'anthropic_api' | 'openai_api' | 'xai_api' | 'ollama';+const API_CARD: Record<Engine, EngineCardId> = { claude: 'anthropic_api', codex: 'openai_api', grok: 'xai_api' };++/** The engine card an account sits on: API-key accounts on the API engine, the rest on the CLI. */+export const cardOf = (p: Pick<Profile, 'engine' | 'kind'>): EngineCardId => (p.kind === 'api_key' ? API_CARD[p.engine] : p.engine);++/** The account family and kind a new account on this card gets; null where accounts can't be added. */+export function newAccountFor(card: string): { engine: Engine; kind: 'cli_home' | 'api_key' } | null {+ if (card === 'claude' || card === 'codex' || card === 'grok') return { engine: card, kind: 'cli_home' };+ const api = (Object.keys(API_CARD) as Engine[]).find((e) => API_CARD[e] === card);+ return api ? { engine: api, kind: 'api_key' } : null;+}++/** A card's accounts: "This machine" first, then the order turns try them (default, then priority). */+export function accountsForCard(profiles: Profile[], card: string): Profile[] {+ return profiles+ .filter((p) => cardOf(p) === card)+ .sort(+ (a, b) =>+ Number(b.kind === 'system') - Number(a.kind === 'system') ||+ Number(b.is_default) - Number(a.is_default) ||+ a.priority - b.priority ||+ a.name.localeCompare(b.name),+ );+}++/** Could run a turn as last checked: on, signed in (or keyed), not out of usage. */+export const accountUsable = (p: Profile, now = Date.now()) =>+ p.enabled && !activeLimit(p.limited_until, now) && p.last_error !== 'auth' && (p.kind === 'api_key' ? p.has_key : p.signed_in === true);diff --git a/frontend/src/useProfiles.ts b/frontend/src/useProfiles.tsnew file mode 100644index 00000000..453570e7--- /dev/null+++ b/frontend/src/useProfiles.ts@@ -0,0 +1,41 @@+// LLM accounts (GET /api/profiles) for the Engines & accounts cards.+import { useCallback, useEffect, useRef, useState } from 'react';+import { Profile, profilesApi } from './profiles';++export interface ProfilesState {+ /** null until the first load. */+ profiles: Profile[] | null;+ error: string | null;+ reload: () => Promise<void>;+}++/** Loads the accounts while `active`; `onChanged` gets every fresh list, so kwant pickers stay current. */+export function useProfiles(active: boolean, onChanged?: (profiles: Profile[]) => void): ProfilesState {+ const [profiles, setProfiles] = useState<Profile[] | null>(null);+ const [error, setError] = useState<string | null>(null);+ const changed = useRef(onChanged);+ changed.current = onChanged;+ const alive = useRef(true);+ useEffect(() => {+ alive.current = true;+ return () => void (alive.current = false);+ }, []);++ const reload = useCallback(async () => {+ try {+ const list = await profilesApi.list();+ if (!alive.current) return;+ setProfiles(list);+ setError(null);+ changed.current?.(list);+ } catch (e) {+ if (alive.current) setError(e instanceof Error ? e.message : 'Could not load accounts.');+ }+ }, []);++ useEffect(() => {+ if (active) reload();+ }, [active, reload]);++ return { profiles, error, reload };+}diff --git a/frontend/tests/claudeLogin.test.mjs b/frontend/tests/claudeLogin.test.mjsindex eb6e3b67..82f084fb 100644--- a/frontend/tests/claudeLogin.test.mjs+++ b/frontend/tests/claudeLogin.test.mjs@@ -136,7 +136,7 @@ test('a signed-out Claude row offers "Sign in with Claude"; the summary points aconst html = panel([signedOut, engine('codex', { status: 'not_installed' })]);assert.match(html, /Sign in with Claude<\/button>/);assert.match(html, /Opens claude.ai in a new tab/);- assert.match(html, /No engine can run right now\. Sign in with Claude below, or add an API key\./);+ assert.match(html, /No engine can run right now\. Sign in with Claude below, or add an account\./);assert.doesNotMatch(html, />Sign out</);// The button replaces "run `claude login`".assert.doesNotMatch(html, /claude login/);diff --git a/frontend/tests/enginesAccounts.test.mjs b/frontend/tests/enginesAccounts.test.mjsnew file mode 100644index 00000000..f5f99b3f--- /dev/null+++ b/frontend/tests/enginesAccounts.test.mjs@@ -0,0 +1,160 @@+import assert from 'node:assert/strict';+import test from 'node:test';+import { loadBundled } from './bundle.mjs';++// The sound effects module reads its mute flag on load.+globalThis.localStorage ??= { getItem: () => null, setItem: () => {} };++const m = await loadBundled(`+ export * from './src/engines';+ export { claudeNeedsSignIn } from './src/claudeLogin';+ export { accountsForCard, cardOf, newAccountFor, accountUsable } from './src/profiles';+ export { EnginesPanel } from './src/components/EnginesPanel';+ export { ModelPicker } from './src/components/ModelPicker';+ export { renderToStaticMarkup } from 'react-dom/server.browser';+ export { createElement } from 'react';+`);+const h = m.createElement;++// Shaped like EngineReport with Lin's `ready` and `uses` (36b0810).+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: '2.1.296',+ models: [],+ checked_at: '2026-10-17T19:00:00Z',+ enabled: true,+ ready: true,+ uses: null,+ ...over,+});+// Shaped like GET /api/profiles.+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,+});+const machine = profile({ id: 'prf_system_claude', name: 'This machine', kind: 'system', signed_in: null, priority: 0 });+const personal = profile({ id: 'prf_personal', name: 'Personal', is_default: true, priority: 10 });++const api = (engines) => ({ engines, error: null, rechecking: false, recheck: async () => {}, reload: async () => {}, setEnabled: async () => {}, apply: () => {} });+const accounts = (profiles, error = null) => ({ profiles, error, reload: async () => {} });+const NOW = Date.parse('2026-10-17T19:01:00Z');+const panel = (engines, profiles = [machine, personal], error = null) =>+ m.renderToStaticMarkup(h(m.EnginesPanel, { api: api(engines), accounts: accounts(profiles, error), now: NOW }));+const card = (html, id) => html.split(`data-engine="${id}"`)[1].split('</li></ul></div></li>')[0];+const summary = (html, id) => card(html, id).match(/data-summary="true"[^>]*>(.*?)<\/p>/)[1].replace(/<[^>]+>/g, '');++// Oleks's setup: Claude on, the host login signed out, Personal signed in and Default.+const oleksOn = engine('claude', { status: 'signed_out', detail: 'Not signed in: run `claude auth login`', uses: { profile_id: 'prf_personal', label: 'Personal' } });++test('ready comes from `ready`, not the host login or the model list', () => {+ assert.ok(m.isUsable(oleksOn));+ assert.equal(m.statusView(oleksOn).label, 'Ready');+ assert.ok(!m.isUsable({ ...oleksOn, enabled: false }));+ assert.ok(!m.isUsable(engine('claude', { ready: false })));+ // An older server without `ready` still reads the host check.+ assert.ok(m.isUsable(engine('claude', { ready: undefined })));+ assert.ok(!m.isUsable(engine('claude', { ready: undefined, status: 'signed_out' })));+ // Claude is fine through Personal, so nothing nags to sign in.+ assert.ok(!m.claudeNeedsSignIn([oleksOn]));+ assert.ok(m.claudeNeedsSignIn([{ ...oleksOn, ready: false, uses: null }]));+});++test('Oleks: one Claude card says kwants use Personal, with This machine first and signed out', () => {+ const html = panel([oleksOn]);+ assert.match(html, /Engines & accounts/);+ assert.match(html, /1 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], /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], /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);+ assert.doesNotMatch(html, /claude auth login/);+});++test('switched off with Personal signed in: "Off · Turn on to use Personal"', () => {+ const html = panel([engine('claude', { enabled: false, status: 'disabled', ready: false, uses: null })]);+ assert.match(html, /data-status="off"/);+ 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/);+ // Nothing to sign in to while it's off.+ assert.doesNotMatch(html, /Sign in with Claude/);+});++test('nothing signed in: the card and headline name the next step', () => {+ const out = engine('claude', { status: 'signed_out', ready: false, uses: null });+ const html = panel([out], [machine, { ...personal, signed_in: false }]);+ assert.equal(summary(html, 'claude'), 'No account is signed in · Sign in to one below');+ assert.match(html, /No engine can run right now\. Sign in with Claude below, or add an account\./);+ assert.match(html, /Not signed in/);+ assert.match(html, /Sign in with Claude<\/button>/);+ // Personal offers its own sign-in.+ assert.match(card(html, 'claude').split('data-account=')[2], />Sign in<\/button>|<\/svg> Sign in<\/button>/);+});++test('an account out of usage says when it is back', () => {+ const out = engine('claude', { status: 'signed_out', ready: false, uses: null });+ const html = panel([out], [machine, { ...personal, limited_until: '2026-10-17T21:01:00Z' }]);+ assert.equal(summary(html, 'claude'), 'Personal is out of usage, back in 2 h · Sign in to another account below');+});++test('API-key accounts sit on the API engine card; an engine missing but with an account still shows', () => {+ const key = profile({ id: 'prf_key', name: 'Team key', kind: 'api_key', has_key: true, signed_in: null });+ assert.equal(m.cardOf(key), 'anthropic_api');+ assert.equal(m.cardOf(personal), 'claude');+ assert.deepEqual(m.newAccountFor('anthropic_api'), { engine: 'claude', kind: 'api_key' });+ assert.deepEqual(m.newAccountFor('claude'), { engine: 'claude', kind: 'cli_home' });+ assert.equal(m.newAccountFor('ollama'), null);+ const apiEngine = engine('anthropic_api', { status: 'not_installed', ready: true, uses: { profile_id: 'prf_key', label: 'Team key' } });+ const html = panel([oleksOn, apiEngine, engine('ollama', { status: 'not_installed', ready: false })], [machine, personal, key]);+ assert.match(html, /data-engine="anthropic_api" data-status="ready"/);+ assert.equal(summary(html, 'anthropic_api'), 'Kwants use Team key');+ assert.match(html, /Not available on this computer \(1\)/);+ // Ollama has no accounts section.+ assert.doesNotMatch(html, /Ollama accounts/);+});++test('accounts load and fail with a next step', () => {+ assert.match(m.renderToStaticMarkup(h(m.EnginesPanel, { api: api([oleksOn]), accounts: accounts(null), now: NOW })), /Loading accounts…/);+ const html = panel([oleksOn], null, 'Request failed (HTTP 500).');+ assert.match(html, /role="alert"[^>]*>.*Couldn’t load accounts: Request failed \(HTTP 500\)\./);+ assert.match(html, /Try again<\/button>/);+});++test('accounts list This machine first, then the order turns try them', () => {+ const list = m.accountsForCard(+ [profile({ id: 'b', name: 'B', priority: 5 }), personal, machine, profile({ id: 'a', name: 'A', priority: 1 }), profile({ id: 'k', kind: 'api_key' })],+ 'claude',+ );+ assert.deepEqual(list.map((p) => p.name), ['This machine', 'Personal', 'A', 'B']);+ assert.ok(m.accountUsable(personal));+ assert.ok(!m.accountUsable({ ...personal, signed_in: null }), 'unknown sign-in is not ready, like the server');+ assert.ok(!m.accountUsable({ ...personal, enabled: false }));+});++const picker = (value, engines) =>+ m.renderToStaticMarkup(h(m.ModelPicker, { value, onChange: () => {}, engines, onOpenSettings: () => {}, onSignInClaude: () => {} }));++test('the kwant form takes Claude as ready through Personal, even with no model list', () => {+ const html = picker('claude', [oleksOn]);+ assert.doesNotMatch(html, /can't run right now/);+ assert.match(html, /<option value="claude"[^>]*>Claude · Claude Code CLI<\/option>/);+ assert.deepEqual(m.pickHealth('auto', [oleksOn]), { kind: 'ok' });+ // Switched off: the hint says so instead of "No API key".+ const off = [{ ...oleksOn, enabled: false, status: 'disabled', ready: false }, engine('anthropic_api', { status: 'not_installed', ready: false, detail: 'No API key: add one in Settings' })];+ assert.deepEqual(m.pickHealth('claude', off), { kind: 'engine_unavailable', family: 'claude', reason: 'Switched off in Settings' });+});