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.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
feat(panel): add conversation history with restore
Shahriard1cfb262def3
diff --git a/components/session-list.tsx b/components/session-list.tsxnew file mode 100644index 0000000..c293fd6--- /dev/null+++ b/components/session-list.tsx@@ -0,0 +1,138 @@+import { Globe, Loader2, MessageSquare, X } from 'lucide-react';+import { Badge } from '@/components/ui/badge';+import { isNaming, type StoredSessionMeta } from '@/lib/bridge/session-store';+import { cn } from '@/lib/utils';++/**+ * The session library, shown in place of the chat. Rows are conversations, newest first; picking one+ * reopens it — its messages, the agent's memory of it, and the page it was left on.+ *+ * Titles are model-written, so they are rendered as text and never through `Markdown`: this is a+ * list, not the transcript, and a name is not a place markup should be able to appear.+ */+export function SessionList({+ sessions,+ currentId,+ busy,+ onOpen,+ onRemove,+}: {+ sessions: StoredSessionMeta[];+ /** The conversation on screen, so reopening it is not offered as if it were somewhere else. */+ currentId?: string;+ /** A run is in flight, so reopening anything is refused — say so rather than ignoring the click. */+ busy?: boolean;+ onOpen: (sessionId: string) => void;+ onRemove: (sessionId: string) => void;+}) {+ if (sessions.length === 0) {+ return (+ <p className="p-4 text-xs leading-relaxed text-muted-foreground">+ No saved conversations yet. Every conversation is kept here automatically — the button beside this one closes+ the current conversation out and starts a fresh one.+ </p>+ );+ }+ return (+ <div className="flex min-w-0 flex-col gap-1.5 p-3">+ {busy && (+ <p className="px-1 pb-1 text-[11px] text-muted-foreground">+ Waiting on the current run — stop it to reopen another conversation.+ </p>+ )}+ {sessions.map((session) => (+ <SessionRow+ key={session.id}+ session={session}+ current={session.id === currentId}+ busy={busy === true}+ onOpen={onOpen}+ onRemove={onRemove}+ />+ ))}+ </div>+ );+}++function SessionRow({+ session,+ current,+ busy,+ onOpen,+ onRemove,+}: {+ session: StoredSessionMeta;+ current: boolean;+ busy: boolean;+ onOpen: (sessionId: string) => void;+ onRemove: (sessionId: string) => void;+}) {+ const label = session.title ?? (session.host ? `Conversation on ${session.host}` : 'Untitled conversation');+ return (+ <div+ className={cn(+ 'flex items-start gap-2 rounded-md border bg-background/60 px-2.5 py-1.5 text-xs',+ current && 'border-primary/40 bg-primary/5',+ )}+ >+ <button+ type="button"+ onClick={() => onOpen(session.id)}+ disabled={busy}+ className="flex min-w-0 flex-1 items-start gap-2 text-left disabled:opacity-50"+ title={session.url}+ >+ <MessageSquare className="mt-0.5 size-3.5 shrink-0 text-muted-foreground" />+ <span className="min-w-0 flex-1">+ <span className="flex items-center gap-1.5">+ <span className="truncate font-medium">{label}</span>+ {current && (+ <Badge variant="secondary" className="h-4 shrink-0 px-1 text-[10px]">+ open+ </Badge>+ )}+ </span>+ {session.host && (+ <span className="mt-0.5 flex items-center gap-1 font-mono text-[10px] text-muted-foreground">+ <Globe className="size-2.5 shrink-0" />+ <span className="truncate">{session.host}</span>+ </span>+ )}+ <span className="mt-0.5 flex items-center gap-1 text-[11px] text-muted-foreground">+ {isNaming(session) && !session.title ? (+ <>+ <Loader2 className="size-3 animate-spin" /> Naming…+ </>+ ) : (+ <>+ {session.turns} {session.turns === 1 ? 'message' : 'messages'} · {formatWhen(session.updatedAt)}+ </>+ )}+ </span>+ </span>+ </button>+ <button+ type="button"+ onClick={() => onRemove(session.id)}+ aria-label={`Delete ${label}`}+ className="mt-0.5 shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground"+ >+ <X className="size-3" />+ </button>+ </div>+ );+}++const MINUTE = 60_000;+const HOUR = 60 * MINUTE;+const DAY = 24 * HOUR;++/** Coarse and relative: on a row this narrow, "3h ago" reads faster than a timestamp. */+function formatWhen(at: number): string {+ const ago = Date.now() - at;+ if (ago < MINUTE) return 'just now';+ if (ago < HOUR) return `${Math.floor(ago / MINUTE)}m ago`;+ if (ago < DAY) return `${Math.floor(ago / HOUR)}h ago`;+ if (ago < 7 * DAY) return `${Math.floor(ago / DAY)}d ago`;+ return new Date(at).toLocaleDateString(undefined, { month: 'short', day: 'numeric' });+}diff --git a/entrypoints/sidepanel/App.tsx b/entrypoints/sidepanel/App.tsxindex 039c41c..38a2a5f 100644--- a/entrypoints/sidepanel/App.tsx+++ b/entrypoints/sidepanel/App.tsx@@ -1,21 +1,24 @@-import { useEffect, useRef, useState } from 'react';-import { AudioLines, Bot, BookOpen, FileText, FileUp, Loader2, Mic, MicOff, Paperclip, RotateCcw, Send, Square, X } from 'lucide-react';+import { useEffect, useRef, useState, type MouseEvent } from 'react';+import { AudioLines, Bot, BookOpen, FileText, FileUp, History, Loader2, Mic, MicOff, Paperclip, RotateCcw, Send, Square, X } from 'lucide-react';import { browser } from 'wxt/browser';import { invokeInActiveTab } from '@/lib/actions/client';import { getPageInfo } from '@/lib/actions/page/get-page-info';import { BRIDGE_CHANNEL } from '@/lib/actions/protocol';import { RunTimeline } from '@/components/run-timeline';+import { SessionList } from '@/components/session-list';import { SiteMapReview } from '@/components/site-map-review';import { SkillsPanel } from '@/components/skills-panel';import { Button } from '@/components/ui/button';import { ScrollArea } from '@/components/ui/scroll-area';import { Textarea } from '@/components/ui/textarea';import { putFile, removeFile, type StoredFileMeta } from '@/lib/bridge/file-store';+import { removeSession } from '@/lib/bridge/session-store';import { useActiveTabUrl } from '@/lib/bridge/use-active-tab-url';import { useDaemonState } from '@/lib/bridge/use-daemon-state';import { useRun } from '@/lib/bridge/use-run';import { useStoredFiles } from '@/lib/bridge/use-stored-files';+import { useStoredSessions } from '@/lib/bridge/use-stored-sessions';import { useVoiceComposer } from '@/lib/bridge/use-voice-composer';import { useVoiceEnabled } from '@/lib/bridge/use-speech';import { cn } from '@/lib/utils';@@ -25,14 +28,18 @@ const MAX_FILE_BYTES = 10 * 1024 * 1024;export default function App() {const daemon = useDaemonState();- const run = useRun();+ // The panel is the surface that owns a conversation, so it is the one that saves it.+ const run = useRun({ persist: true });const [voiceEnabled, setVoiceEnabled] = useVoiceEnabled();const bottomRef = useRef<HTMLDivElement>(null);const fileInputRef = useRef<HTMLInputElement>(null);+ const composerRef = useRef<HTMLTextAreaElement>(null);const files = useStoredFiles();+ const sessions = useStoredSessions();const tabUrl = useActiveTabUrl();const [attachError, setAttachError] = useState<string | null>(null);const [skillsOpen, setSkillsOpen] = useState(false);+ const [historyOpen, setHistoryOpen] = useState(false);const connected = daemon?.connected ?? false;@@ -49,9 +56,27 @@ export default function App() {function handleSend() {if (run.running || !connected) return;+ // Sending while the history is open would leave the composer talking to a view that is not the+ // conversation it is writing into.+ setHistoryOpen(false);voice.submitNow();}+ function openSession(sessionId: string) {+ setHistoryOpen(false);+ void run.restore(sessionId);+ }++ /**+ * Clicking the composer's padding lands in the input, the way it would if this were one control+ * rather than a box with a textarea in it — but not when the click was meant for a button+ * sitting inside that box. The textarea is focusable on its own, so this adds no keyboard path.+ */+ function focusComposer(event: MouseEvent<HTMLDivElement>) {+ if ((event.target as HTMLElement).closest('button, textarea')) return;+ composerRef.current?.focus();+ }+async function attachPageContext() {const result = await invokeInActiveTab(getPageInfo, {});if (!result.ok) {@@ -130,13 +155,29 @@ export default function App() {{status}</p></div>- <Button variant="ghost" size="icon" aria-label="Clear conversation" onClick={run.clear}>+ <Button+ variant={historyOpen ? 'default' : 'ghost'}+ size="icon"+ aria-label={historyOpen ? 'Back to the conversation' : 'Saved conversations'}+ onClick={() => setHistoryOpen(!historyOpen)}+ >+ <History />+ </Button>+ <Button variant="ghost" size="icon" aria-label="Start a new conversation" onClick={run.clear}><RotateCcw /></Button></header><ScrollArea className="min-h-0 flex-1">- {run.items.length === 0 ? (+ {historyOpen ? (+ <SessionList+ sessions={sessions}+ currentId={run.sessionId}+ busy={run.running}+ onOpen={openSession}+ onRemove={(id) => void removeSession(id)}+ />+ ) : run.items.length === 0 ? (<Greeting connected={connected} voiceOn={voiceEnabled && voice.supported} />) : (<RunTimeline items={run.items} onDecide={run.decide} />@@ -167,8 +208,22 @@ export default function App() {<FilesList files={files} onRemove={(id) => void removeFile(id)} /><VoiceStatus voice={voice} voiceEnabled={voiceEnabled} connected={connected} />- <div className="flex items-end gap-2">+ {/*+ One composer, not an input beside a toolbar: the container carries the border and the+ focus ring, the textarea inside it is transparent and full width, and the buttons sit on+ their own row within the same box. `has-[textarea:focus]` rather than `focus-within`, so+ tabbing to one of those buttons doesn't ring the whole thing.+ */}+ <div+ onClick={focusComposer}+ className={cn(+ 'flex flex-col rounded-xl border border-input shadow-xs transition-[color,box-shadow] dark:bg-input/30',+ 'has-[textarea:focus]:border-ring has-[textarea:focus]:ring-[3px] has-[textarea:focus]:ring-ring/50',+ connected && 'cursor-text',+ )}+ ><Textarea+ ref={composerRef}value={voice.input}onChange={(e) => voice.setInput(e.target.value)}onKeyDown={(e) => {@@ -179,12 +234,19 @@ export default function App() {}}placeholder={connected ? 'Speak, or type what to do on this page…' : 'Pair the browser to get started'}disabled={!connected}- className="max-h-32 min-h-10 flex-1 resize-none"+ rows={2}+ // The container owns the frame now, so every part of it is turned off here. `text-sm`+ // is not only smaller: the base is `text-base md:text-sm`, and this panel is never wide+ // enough for `md`, so the input was rendering at 16px while every message that came out+ // of it rendered at 14px. `min-h-16` is the resting height, ~3 lines at this size.+ className="max-h-48 min-h-16 resize-none rounded-none border-0 bg-transparent px-3 pt-2.5 pb-0 text-sm shadow-none focus-visible:ring-0 dark:bg-transparent"/>- <div className="flex gap-1">++ <div className="flex items-center gap-0.5 px-1.5 pb-1.5"><Buttonvariant="ghost"size="icon"+ className="size-8"aria-label="Attach page context"onClick={attachPageContext}disabled={!connected}@@ -194,6 +256,7 @@ export default function App() {<Buttonvariant="ghost"size="icon"+ className="size-8"aria-label="Attach a file"onClick={() => fileInputRef.current?.click()}disabled={!connected}@@ -203,6 +266,7 @@ export default function App() {<Buttonvariant={skillsOpen ? 'default' : 'ghost'}size="icon"+ className="size-8"aria-label={skillsOpen ? 'Hide skills' : 'Show skills'}onClick={() => setSkillsOpen(!skillsOpen)}>@@ -215,7 +279,7 @@ export default function App() {title={voice.supported ? undefined : 'Voice input is not available in this browser'}onClick={toggleVoice}disabled={!voice.supported}- className={cn(voiceEnabled && voice.listening && 'relative')}+ className={cn('size-8', voiceEnabled && voice.listening && 'relative')}>{voiceEnabled && voice.listening && (<span className="absolute inset-0 animate-ping rounded-md bg-primary/30" />@@ -223,12 +287,19 @@ export default function App() {{voiceEnabled && !voice.error ? <Mic /> : <MicOff />}</Button>{run.running ? (- <Button size="icon" variant="destructive" aria-label="Stop the agent" onClick={run.cancel}>+ <Button+ size="icon"+ variant="destructive"+ className="ml-auto size-8"+ aria-label="Stop the agent"+ onClick={run.cancel}+ ><Square /></Button>) : (<Buttonsize="icon"+ className="ml-auto size-8"aria-label="Send message"onClick={handleSend}disabled={!voice.input.trim() || !connected}@@ -375,7 +446,7 @@ function Greeting({ connected, voiceOn }: { connected: boolean; voiceOn: boolean<div className="flex size-7 shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-violet-500 to-indigo-600 text-white"><Bot className="size-4" /></div>- <div className="max-w-[85%] rounded-2xl rounded-tl-sm bg-muted px-3 py-2 text-sm">+ <div className="min-w-0 max-w-[85%] rounded-2xl rounded-tl-sm bg-muted px-3 py-2 text-sm wrap-anywhere">{connected ? (<>Hi, I'm VoiceLink.{' '}