Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

feat(ui): new panel building blocks

Shahriaref516db610f7
diff --git a/components/agent-picker.tsx b/components/agent-picker.tsx
new file mode 100644
index 0000000..15a2edb
--- /dev/null
+++ b/components/agent-picker.tsx
@@ -0,0 +1,152 @@
+import { useEffect, useState } from 'react';
+import { Check, Loader2, RefreshCw, ShieldCheck, TriangleAlert } from 'lucide-react';
+import { browser } from 'wxt/browser';
+
+import { StatusDot } from '@/components/status-pill';
+import { Button } from '@/components/ui/button';
+import { BRIDGE_CHANNEL, type ActionResult } from '@/lib/actions/protocol';
+import { AGENTS, AGENT_LIST, type AgentKind, type AgentState, type RunnerStatus } from '@/lib/agents/catalog';
+import { useDaemonState } from '@/lib/bridge/use-daemon-state';
+import { cn } from '@/lib/utils';
+
+type Request =
+ | { op: 'agentState'; refresh?: boolean }
+ | { op: 'setAgent'; agent: AgentKind }
+ | { op: 'grantAgent'; agent: AgentKind };
+
+export function AgentPicker() {
+ const daemon = useDaemonState();
+ const state = daemon?.agent;
+ const connected = daemon?.connected ?? false;
+ const [busy, setBusy] = useState<string | null>(null);
+ const [error, setError] = useState<string | null>(null);
+
+ useEffect(() => {
+ if (connected && !state) void ask({ op: 'agentState' });
+ // The daemon pushes its agent state on connect; this only covers a panel opened later.
+ }, [connected, state]);
+
+ async function ask(request: Request): Promise<void> {
+ setBusy(request.op === 'agentState' ? 'refresh' : request.agent);
+ setError(null);
+ const result = (await browser.runtime
+ .sendMessage({ channel: BRIDGE_CHANNEL, ...request })
+ .catch(() => null)) as ActionResult<AgentState> | null;
+ setBusy(null);
+ if (!result?.ok) setError(result?.error.message ?? 'The daemon did not answer.');
+ }
+
+ if (!daemon?.paired) return null;
+
+ const runners = AGENT_LIST.map(
+ (agent) => state?.runners.find((runner) => runner.kind === agent.kind) ?? unknownRunner(agent.kind),
+ );
+ const active = state?.active;
+ const problem = runners.find((runner) => runner.kind === active)?.problem;
+
+ return (
+ <section className="space-y-2">
+ <div className="flex items-center justify-between gap-2">
+ <h2 className="font-mono text-[10px] tracking-[0.14em] text-ink-faint uppercase">Agent</h2>
+ <button
+ type="button"
+ onClick={() => void ask({ op: 'agentState', refresh: true })}
+ disabled={!connected || busy !== null}
+ className="flex items-center gap-1 font-mono text-[10px] tracking-[0.14em] text-ink-faint uppercase transition-colors hover:text-brand disabled:opacity-40"
+ >
+ <RefreshCw className={cn('size-3', busy === 'refresh' && 'animate-spin')} /> Recheck
+ </button>
+ </div>
+
+ <div className="grid gap-1">
+ {runners.map((runner) => (
+ <AgentRow
+ key={runner.kind}
+ runner={runner}
+ active={runner.kind === active}
+ busy={busy === runner.kind}
+ disabled={!connected || busy !== null}
+ onSelect={() => void ask({ op: 'setAgent', agent: runner.kind })}
+ />
+ ))}
+ </div>
+
+ {problem && active && (
+ <div className="space-y-1.5 rounded-lg border border-amber/40 bg-amber/10 p-2">
+ <p className="flex gap-1.5 text-[11px] leading-snug text-amber">
+ <TriangleAlert className="mt-px size-3.5 shrink-0" />
+ <span>{problem.message}</span>
+ </p>
+ {problem.fix && (
+ <p className="font-mono text-[10px] leading-snug break-all text-ink-faint">{problem.fix}</p>
+ )}
+ {problem.grantable && (
+ <Button
+ size="sm"
+ className="w-full"
+ disabled={!connected || busy !== null}
+ onClick={() => void ask({ op: 'grantAgent', agent: active })}
+ >
+ {busy === active ? <Loader2 className="animate-spin" /> : <ShieldCheck />}
+ Let Browsentic fix it
+ </Button>
+ )}
+ </div>
+ )}
+
+ {error && <p className="text-[11px] text-destructive">{error}</p>}
+ </section>
+ );
+}
+
+function AgentRow({
+ runner,
+ active,
+ busy,
+ disabled,
+ onSelect,
+}: {
+ runner: RunnerStatus;
+ active: boolean;
+ busy: boolean;
+ disabled: boolean;
+ onSelect: () => void;
+}) {
+ const agent = AGENTS[runner.kind];
+ return (
+ <button
+ type="button"
+ onClick={onSelect}
+ disabled={disabled || active}
+ aria-pressed={active}
+ className={cn(
+ 'flex items-center gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors',
+ active
+ ? 'border-brand/45 bg-brand/10 text-brand'
+ : 'border-line text-ink-dim enabled:hover:border-line-strong enabled:hover:bg-surface/60 enabled:hover:text-ink',
+ disabled && !active && 'opacity-50',
+ )}
+ >
+ <StatusDot tone={runner.ready ? 'live' : 'warn'} />
+ <span className="min-w-0 flex-1 truncate text-xs">{agent.label}</span>
+ <span className="font-mono text-[10px] tracking-wider uppercase opacity-70">{describe(runner)}</span>
+ {busy ? <Loader2 className="size-3 animate-spin" /> : active && <Check className="size-3" />}
+ </button>
+ );
+}
+
+function describe(runner: RunnerStatus): string {
+ if (runner.ready) return 'ready';
+ switch (runner.problem?.code) {
+ case 'AGENT_MISSING':
+ return 'not installed';
+ case 'AGENT_NEEDS_PERMISSION':
+ return 'needs setup';
+ case 'AGENT_UNUSABLE':
+ return 'broken';
+ default:
+ return 'checking…';
+ }
+}
+
+const unknownRunner = (kind: AgentKind): RunnerStatus => ({ kind, bin: AGENTS[kind].bin, ready: false });
diff --git a/components/brand.tsx b/components/brand.tsx
new file mode 100644
index 0000000..e2de545
--- /dev/null
+++ b/components/brand.tsx
@@ -0,0 +1,41 @@
+import { cn } from '@/lib/utils';
+
+export function Logo({ className }: { className?: string }) {
+ return (
+ <svg viewBox="0 0 32 32" fill="none" className={cn('size-7', className)} aria-hidden>
+ <rect
+ x="2.25"
+ y="4.25"
+ width="27.5"
+ height="23.5"
+ rx="6"
+ stroke="currentColor"
+ strokeOpacity="0.55"
+ strokeWidth="1.5"
+ />
+ <path d="M2.5 10.5h27" stroke="currentColor" strokeOpacity="0.35" strokeWidth="1.25" />
+ <circle cx="6.4" cy="7.4" r="1" fill="currentColor" fillOpacity="0.5" />
+ <circle cx="9.8" cy="7.4" r="1" fill="currentColor" fillOpacity="0.35" />
+ <path
+ d="M9 22.2c2.4 0 2.4-6.4 6.9-6.4s4.6 6.4 7 6.4"
+ stroke="currentColor"
+ strokeWidth="1.75"
+ strokeLinecap="round"
+ />
+ <circle cx="9" cy="22.2" r="2.35" fill="var(--ground)" stroke="currentColor" strokeWidth="1.6" />
+ <circle cx="15.9" cy="15.8" r="2.55" fill="currentColor" />
+ <circle cx="22.9" cy="22.2" r="2.35" fill="var(--ground)" stroke="currentColor" strokeWidth="1.6" />
+ </svg>
+ );
+}
+
+export function Wordmark({ className }: { className?: string }) {
+ return (
+ <span className={cn('flex min-w-0 items-center gap-2', className)}>
+ <Logo className="size-6 shrink-0 text-brand" />
+ <span className="font-display text-[0.9375rem] leading-none font-semibold tracking-tight text-ink">
+ Browsentic
+ </span>
+ </span>
+ );
+}
diff --git a/components/composer.tsx b/components/composer.tsx
new file mode 100644
index 0000000..c93417e
--- /dev/null
+++ b/components/composer.tsx
@@ -0,0 +1,247 @@
+import { useRef, type MouseEvent } from 'react';
+import { FileText, FileUp, Loader2, Mic, MicOff, Paperclip, Send, Square, X } from 'lucide-react';
+
+import { Button } from '@/components/ui/button';
+import { Textarea } from '@/components/ui/textarea';
+import type { StoredFileMeta } from '@/lib/bridge/file-store';
+import type { useVoiceComposer } from '@/lib/bridge/use-voice-composer';
+import { cn } from '@/lib/utils';
+
+type Voice = ReturnType<typeof useVoiceComposer>;
+
+export function Composer({
+ voice,
+ voiceEnabled,
+ connected,
+ running,
+ files,
+ attachError,
+ onSend,
+ onStop,
+ onToggleVoice,
+ onAttachPage,
+ onAttachFile,
+ onRemoveFile,
+}: {
+ voice: Voice;
+ voiceEnabled: boolean;
+ connected: boolean;
+ running: boolean;
+ files: StoredFileMeta[];
+ attachError: string | null;
+ onSend: () => void;
+ onStop: () => void;
+ onToggleVoice: () => void;
+ onAttachPage: () => void;
+ onAttachFile: (file: File) => void;
+ onRemoveFile: (fileId: string) => void;
+}) {
+ const fileInputRef = useRef<HTMLInputElement>(null);
+ const composerRef = useRef<HTMLTextAreaElement>(null);
+
+ function focusComposer(event: MouseEvent<HTMLDivElement>) {
+ if ((event.target as HTMLElement).closest('button, textarea')) return;
+ composerRef.current?.focus();
+ }
+
+ return (
+ <>
+ {attachError && (
+ <p className="mb-2 rounded-lg border border-amber/40 bg-amber/10 px-2.5 py-1.5 text-[11px] text-amber">
+ {attachError}
+ </p>
+ )}
+
+ <FileChips files={files} onRemove={onRemoveFile} />
+ <VoiceStatus voice={voice} voiceEnabled={voiceEnabled} />
+
+ <div
+ onClick={focusComposer}
+ className={cn(
+ 'panel-card flex flex-col rounded-2xl transition-colors has-[textarea:focus]:border-brand/50',
+ connected && 'cursor-text',
+ )}
+ >
+ <Textarea
+ ref={composerRef}
+ value={voice.input}
+ onChange={(event) => voice.setInput(event.target.value)}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' && !event.shiftKey) {
+ event.preventDefault();
+ onSend();
+ }
+ }}
+ placeholder={connected ? 'Tell me what to do on this page…' : 'Pair the browser to get started'}
+ disabled={!connected}
+ rows={2}
+ className="max-h-48 min-h-14 resize-none rounded-none border-0 bg-transparent px-3 pt-2.5 pb-0 focus-visible:border-0"
+ />
+
+ <div className="flex items-center gap-0.5 px-1.5 pb-1.5">
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ title="Add this page’s title, URL and selection to the message"
+ aria-label="Attach page context"
+ onClick={onAttachPage}
+ disabled={!connected}
+ >
+ <Paperclip className="size-3.5" />
+ </Button>
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ title="Attach a file for the agent to read"
+ aria-label="Attach a file"
+ onClick={() => fileInputRef.current?.click()}
+ disabled={!connected}
+ >
+ <FileUp className="size-3.5" />
+ </Button>
+ <Button
+ variant={voiceEnabled && !voice.error ? 'subtle' : 'ghost'}
+ size="icon-sm"
+ aria-label={voiceEnabled ? 'Turn voice off' : 'Turn voice on'}
+ title={voice.supported ? 'Speak instead of typing' : 'Voice input is not available in this browser'}
+ onClick={onToggleVoice}
+ disabled={!voice.supported}
+ className="relative"
+ >
+ {voiceEnabled && voice.listening && (
+ <span className="absolute inset-0 animate-ping rounded-full bg-magenta/30" />
+ )}
+ {voiceEnabled && !voice.error ? <Mic className="size-3.5" /> : <MicOff className="size-3.5" />}
+ </Button>
+
+ {running ? (
+ <Button size="icon-sm" variant="destructive" className="ml-auto" aria-label="Stop the agent" onClick={onStop}>
+ <Square className="size-3 fill-current" />
+ </Button>
+ ) : (
+ <Button
+ size="icon-sm"
+ className="ml-auto"
+ aria-label="Send message"
+ onClick={onSend}
+ disabled={!voice.input.trim() || !connected}
+ >
+ <Send className="size-3.5" />
+ </Button>
+ )}
+ </div>
+ </div>
+
+ <input
+ ref={fileInputRef}
+ type="file"
+ className="hidden"
+ onChange={(event) => {
+ const file = event.target.files?.[0];
+ event.target.value = '';
+ if (file) onAttachFile(file);
+ }}
+ />
+
+ <p className="mt-2 text-center font-mono text-[10px] text-ink-faint">
+ {voiceEnabled && voice.supported
+ ? 'Speak and pause to send · Enter sends now'
+ : 'Enter to send · Shift + Enter for a new line'}
+ </p>
+ </>
+ );
+}
+
+function VoiceStatus({ voice, voiceEnabled }: { voice: Voice; voiceEnabled: boolean }) {
+ if (voiceEnabled && voice.error) {
+ return (
+ <p className="mb-2 rounded-lg border border-amber/40 bg-amber/10 px-2.5 py-1.5 text-[11px] text-amber">
+ {voice.error}
+ </p>
+ );
+ }
+
+ if (voice.pendingSend) {
+ return (
+ <div className="mb-2 flex items-center gap-2 rounded-lg bg-brand/10 px-2.5 py-1.5 text-[11px] text-brand">
+ <span className="relative flex-1 overflow-hidden rounded-full bg-brand/20">
+ <span
+ className="block h-1 rounded-full bg-brand"
+ style={{ animation: `browsentic-countdown ${voice.autoSendMs}ms linear forwards` }}
+ />
+ </span>
+ <span className="shrink-0">Sending…</span>
+ <button
+ type="button"
+ onClick={voice.cancelPending}
+ className="flex shrink-0 items-center gap-0.5 rounded-full px-1.5 py-0.5 transition-colors hover:bg-brand/15"
+ aria-label="Cancel sending"
+ >
+ <X className="size-3" /> Edit
+ </button>
+ </div>
+ );
+ }
+
+ if (voiceEnabled && voice.listening) {
+ return (
+ <p className="mb-2 flex items-center gap-1.5 px-1 text-[11px] text-ink-dim">
+ <span className="glow-dot inline-flex size-1.5 shrink-0 animate-pulse rounded-full bg-magenta text-magenta" />
+ {voice.interim ? <span className="truncate italic">{voice.interim}</span> : <span>Listening…</span>}
+ </p>
+ );
+ }
+
+ if (voiceEnabled && !voice.supported) {
+ return <p className="mb-2 px-1 text-[11px] text-ink-faint">Voice input isn’t available in this browser.</p>;
+ }
+
+ return null;
+}
+
+function FileChips({ files, onRemove }: { files: StoredFileMeta[]; onRemove: (fileId: string) => void }) {
+ if (files.length === 0) return null;
+ return (
+ <div className="mb-2 flex max-h-40 flex-col gap-1.5 overflow-y-auto">
+ {files.map((file) => (
+ <div
+ key={file.id}
+ className="flex items-start gap-2 rounded-xl border border-line bg-ground/40 px-2.5 py-1.5 text-xs"
+ >
+ <FileText className="mt-0.5 size-3.5 shrink-0 text-ink-faint" />
+ <div className="min-w-0 flex-1">
+ <div className="flex items-center gap-1.5">
+ <span className="truncate font-medium text-ink">{file.name}</span>
+ <span className="shrink-0 font-mono text-[10px] text-ink-faint">{formatBytes(file.size)}</span>
+ </div>
+ {file.status === 'pending' && (
+ <span className="mt-0.5 flex items-center gap-1 text-[11px] text-ink-faint">
+ <Loader2 className="size-3 animate-spin" /> Analyzing…
+ </span>
+ )}
+ {file.status === 'ready' && file.summary && (
+ <p className="mt-0.5 line-clamp-2 text-[11px] text-ink-dim">{file.summary}</p>
+ )}
+ {file.status === 'error' && (
+ <span className="mt-0.5 block text-[11px] text-destructive">{file.error ?? 'Analysis failed'}</span>
+ )}
+ </div>
+ <button
+ type="button"
+ onClick={() => onRemove(file.id)}
+ aria-label={`Remove ${file.name}`}
+ className="mt-0.5 shrink-0 rounded-full p-1 text-ink-faint transition-colors hover:bg-surface hover:text-ink"
+ >
+ <X className="size-3" />
+ </button>
+ </div>
+ ))}
+ </div>
+ );
+}
+
+function formatBytes(n: number): string {
+ if (n < 1024) return `${n} B`;
+ if (n < 1024 * 1024) return `${Math.round(n / 1024)} KB`;
+ return `${(n / 1024 / 1024).toFixed(1)} MB`;
+}
diff --git a/components/connection-sheet.tsx b/components/connection-sheet.tsx
new file mode 100644
index 0000000..933a0a4
--- /dev/null
+++ b/components/connection-sheet.tsx
@@ -0,0 +1,22 @@
+import { X } from 'lucide-react';
+
+import { AgentPicker } from '@/components/agent-picker';
+import { DaemonLink } from '@/components/daemon-link';
+import { Button } from '@/components/ui/button';
+
+export function ConnectionSheet({ onClose }: { onClose: () => void }) {
+ return (
+ <div className="enters max-h-[60%] shrink-0 overflow-y-auto border-b border-line bg-ground-2/80 px-3 py-3 backdrop-blur">
+ <div className="mb-3 flex items-center justify-between gap-2">
+ <p className="text-xs font-medium text-ink">Connection</p>
+ <Button variant="ghost" size="icon-sm" aria-label="Close connection settings" onClick={onClose}>
+ <X className="size-3.5" />
+ </Button>
+ </div>
+ <div className="space-y-4">
+ <DaemonLink />
+ <AgentPicker />
+ </div>
+ </div>
+ );
+}
diff --git a/components/greeting.tsx b/components/greeting.tsx
new file mode 100644
index 0000000..1595746
--- /dev/null
+++ b/components/greeting.tsx
@@ -0,0 +1,93 @@
+import { BookOpen, Clapperboard, History, Settings2, type LucideIcon } from 'lucide-react';
+
+import { Logo } from '@/components/brand';
+import type { PanelTab } from '@/components/panel-nav';
+import type { StatusBlocker } from '@/components/status-pill';
+
+const SUGGESTIONS = [
+ 'Summarise what this page says',
+ 'Fill this form in with my details',
+ 'Find the unpaid invoices and open the newest',
+];
+
+const BLOCKED: Record<StatusBlocker, string> = {
+ unpaired: 'This browser isn’t paired yet, so nothing can drive it. Pairing takes one command and one code.',
+ offline: 'Paired, but the daemon isn’t answering. Start browsentic-mcp and this reconnects on its own.',
+ agent: 'The chosen agent can’t run on this machine. Pick another one, or let Browsentic fix it.',
+};
+
+export function Greeting({
+ blocker,
+ voiceOn,
+ onGo,
+ onFix,
+ onUse,
+}: {
+ blocker?: StatusBlocker;
+ voiceOn: boolean;
+ onGo: (tab: PanelTab) => void;
+ onFix: () => void;
+ onUse: (text: string) => void;
+}) {
+ return (
+ <div className="dot-grid fade-bottom flex flex-col gap-4 p-4">
+ <div className="flex items-start gap-2.5">
+ <Logo className="mt-0.5 size-7 shrink-0 text-brand" />
+ <div className="panel-card min-w-0 rounded-2xl rounded-tl-md px-3 py-2.5 text-sm leading-relaxed text-ink">
+ {blocker ? (
+ BLOCKED[blocker]
+ ) : (
+ <>
+ {voiceOn ? 'Just talk' : 'Tell me'} what to do on this page — read it, fill something in, click through a
+ flow — and every action shows up here as I take it.
+ </>
+ )}
+ </div>
+ </div>
+
+ {blocker ? (
+ <div className="flex flex-wrap gap-1.5">
+ <Quick
+ icon={Settings2}
+ label={blocker === 'agent' ? 'Choose an agent' : 'Set up the link'}
+ onClick={onFix}
+ />
+ </div>
+ ) : (
+ <>
+ <div className="flex flex-col gap-1.5">
+ {SUGGESTIONS.map((text) => (
+ <button
+ key={text}
+ type="button"
+ onClick={() => onUse(text)}
+ className="rounded-xl border border-line bg-ground/40 px-3 py-2 text-left text-xs text-ink-dim transition-colors hover:border-brand/40 hover:bg-surface/60 hover:text-ink"
+ >
+ {text}
+ </button>
+ ))}
+ </div>
+
+ <div className="flex flex-wrap gap-1.5">
+ <Quick icon={BookOpen} label="Teach it this site" onClick={() => onGo('skills')} />
+ <Quick icon={Clapperboard} label="Record a flow" onClick={() => onGo('recordings')} />
+ <Quick icon={History} label="Past chats" onClick={() => onGo('history')} />
+ </div>
+ </>
+ )}
+ </div>
+ );
+}
+
+function Quick({ icon: Icon, label, onClick }: { icon: LucideIcon; label: string; onClick: () => void }) {
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ className="inline-flex items-center gap-1.5 rounded-full border border-line bg-ground-2/70 px-2.5 py-1 text-[11px] text-ink-dim transition-colors hover:border-brand/40 hover:text-ink"
+ >
+ <Icon className="size-3" />
+ {label}
+ </button>
+ );
+}
diff --git a/components/panel-nav.tsx b/components/panel-nav.tsx
new file mode 100644
index 0000000..aa39416
--- /dev/null
+++ b/components/panel-nav.tsx
@@ -0,0 +1,61 @@
+import { BookOpen, Clapperboard, History, MessagesSquare, type LucideIcon } from 'lucide-react';
+
+import { cn } from '@/lib/utils';
+
+export type PanelTab = 'chat' | 'history' | 'skills' | 'recordings';
+
+const TABS: { id: PanelTab; label: string; icon: LucideIcon }[] = [
+ { id: 'chat', label: 'Chat', icon: MessagesSquare },
+ { id: 'history', label: 'History', icon: History },
+ { id: 'skills', label: 'Skills', icon: BookOpen },
+ { id: 'recordings', label: 'Recordings', icon: Clapperboard },
+];
+
+export function PanelNav({
+ tab,
+ counts,
+ onSelect,
+}: {
+ tab: PanelTab;
+ counts: Partial<Record<PanelTab, number>>;
+ onSelect: (tab: PanelTab) => void;
+}) {
+ return (
+ <nav
+ aria-label="Panel sections"
+ className="flex shrink-0 gap-1 overflow-x-auto border-b border-line px-2 pb-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
+ >
+ {TABS.map(({ id, label, icon: Icon }) => {
+ const active = tab === id;
+ const count = counts[id] ?? 0;
+ return (
+ <button
+ key={id}
+ type="button"
+ onClick={() => onSelect(id)}
+ aria-current={active ? 'page' : undefined}
+ className={cn(
+ 'inline-flex shrink-0 items-center gap-1.5 rounded-full px-2.5 py-1.5 text-[11px] font-medium transition-colors',
+ active
+ ? 'bg-brand/12 text-brand'
+ : 'text-ink-faint hover:bg-surface/60 hover:text-ink-dim',
+ )}
+ >
+ <Icon className="size-3.5" />
+ {label}
+ {count > 0 && (
+ <span
+ className={cn(
+ 'rounded-full px-1 font-mono text-[9px] tabular-nums',
+ active ? 'bg-brand/20' : 'bg-surface text-ink-faint',
+ )}
+ >
+ {count}
+ </span>
+ )}
+ </button>
+ );
+ })}
+ </nav>
+ );
+}
diff --git a/components/status-pill.tsx b/components/status-pill.tsx
new file mode 100644
index 0000000..d894dac
--- /dev/null
+++ b/components/status-pill.tsx
@@ -0,0 +1,102 @@
+import type { ReactNode } from 'react';
+import { ChevronDown } from 'lucide-react';
+
+import { activeRunner } from '@/lib/agents/catalog';
+import type { DaemonState } from '@/lib/bridge/socket';
+import { cn } from '@/lib/utils';
+
+export type StatusTone = 'off' | 'pending' | 'live' | 'busy' | 'listening' | 'warn';
+
+export type StatusBlocker = 'unpaired' | 'offline' | 'agent';
+
+export interface Status {
+ tone: StatusTone;
+ label: string;
+ /** The link is up and the chosen agent can run — everything else is disabled without it. */
+ ready: boolean;
+ blocker?: StatusBlocker;
+}
+
+/** One reading of the link, the agent and the run — the header pill on both surfaces. */
+export function describeStatus(
+ daemon: DaemonState | null,
+ { running, listening }: { running?: boolean; listening?: boolean } = {},
+): Status {
+ const agentReady = activeRunner(daemon?.agent)?.ready !== false;
+ const ready = (daemon?.connected ?? false) && agentReady;
+
+ if (!daemon?.paired) return { tone: 'off', label: 'Not paired', ready, blocker: 'unpaired' };
+ if (!daemon.connected) return { tone: 'pending', label: 'Reconnecting', ready, blocker: 'offline' };
+ if (!agentReady) return { tone: 'warn', label: 'Agent blocked', ready, blocker: 'agent' };
+ if (running) return { tone: 'busy', label: 'Working', ready };
+ if (listening) return { tone: 'listening', label: 'Listening', ready };
+ return { tone: 'live', label: 'Online', ready };
+}
+
+const DOT: Record<StatusTone, string> = {
+ off: 'bg-ink-faint/50',
+ pending: 'glow-dot animate-pulse bg-amber text-amber',
+ live: 'glow-dot bg-lime text-lime',
+ busy: 'glow-dot animate-pulse bg-brand text-brand',
+ listening: 'glow-dot animate-pulse bg-magenta text-magenta',
+ warn: 'glow-dot bg-ember text-ember',
+};
+
+const TEXT: Record<StatusTone, string> = {
+ off: 'text-ink-faint',
+ pending: 'text-amber',
+ live: 'text-ink-dim',
+ busy: 'text-brand',
+ listening: 'text-magenta',
+ warn: 'text-ember',
+};
+
+export function StatusDot({ tone, className }: { tone: StatusTone; className?: string }) {
+ return <span className={cn('size-1.5 shrink-0 rounded-full', DOT[tone], className)} />;
+}
+
+export function StatusPill({
+ tone,
+ children,
+ onClick,
+ expanded,
+ className,
+}: {
+ tone: StatusTone;
+ children: ReactNode;
+ onClick?: () => void;
+ expanded?: boolean;
+ className?: string;
+}) {
+ const body = (
+ <>
+ <StatusDot tone={tone} />
+ <span className="min-w-0 truncate">{children}</span>
+ {onClick && (
+ <ChevronDown
+ className={cn('size-3 shrink-0 text-ink-faint transition-transform', expanded && 'rotate-180')}
+ />
+ )}
+ </>
+ );
+
+ const shell = cn(
+ 'inline-flex max-w-full items-center gap-1.5 rounded-full border border-line bg-ground-2/70 px-2.5 py-1',
+ 'font-mono text-[10px] tracking-[0.12em] uppercase',
+ TEXT[tone],
+ className,
+ );
+
+ if (!onClick) return <span className={shell}>{body}</span>;
+
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ aria-expanded={expanded}
+ className={cn(shell, 'transition-colors hover:border-brand/40 hover:bg-surface/60')}
+ >
+ {body}
+ </button>
+ );
+}