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): /context shows what a conversation carries
Shahriara33c1ed6f61f
diff --git a/docs/guide/features/conversations.md b/docs/guide/features/conversations.mdindex 051ae19..a9acade 100644--- a/docs/guide/features/conversations.md+++ b/docs/guide/features/conversations.md@@ -88,6 +88,22 @@ attempting it returns `TAB_IN_USE`.---+## What a conversation carries — `/context`++Type `/context` (or pick **context** from the `/` menu) and a **Session context** card appears in+the transcript: the message mix so far, the attached files and ready recordings that will ride+along with your next message, the tabs the session spans, and which agent holds the conversation —+plus whether it can resume where it left off.++The card also shows token counts, straight from the agent CLI's own reporting: roughly how many+tokens the model's context window held after its last reply, and how many it generated on the last+run. Claude Code and Codex report these; Antigravity does not, and the card says so.++It is answered by the extension itself, without waking an agent, so it also works mid-run. The card+describes what this browser holds; the agent's own working memory lives with the agent.++---+## HistoryConversations are saved and named automatically. The **History** tab reopens any of them, on anydiff --git a/src/extension/components/composer.tsx b/src/extension/components/composer.tsxindex bbdd4b1..97a9c2f 100644--- a/src/extension/components/composer.tsx+++ b/src/extension/components/composer.tsx@@ -30,6 +30,7 @@ export function Composer({focus,picking,onAttachSkill,+ onCommand,onSend,onStop,onToggleVoice,@@ -51,6 +52,7 @@ export function Composer({focus: FocusedElement | null;picking: boolean;onAttachSkill: (skill: AttachedSkill | null) => void;+ onCommand: (command: string) => void;onSend: () => void;onStop: () => void;onToggleVoice: () => void;@@ -79,7 +81,10 @@ export function Composer({}, [menuOpen, cancelPending]);function choose(item: SkillMenuItem) {- if (item.agentSkillId) {+ if (item.command) {+ voice.setInput('');+ onCommand(item.command);+ } else if (item.agentSkillId) {onAttachSkill({ id: item.agentSkillId, name: item.name });voice.setInput('');} else {@@ -258,7 +263,7 @@ export function Composer({<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 · / for skills'}+ : 'Enter to send · Shift + Enter for a new line · / for skills and commands'}</p></>);diff --git a/src/extension/components/context-card.tsx b/src/extension/components/context-card.tsxnew file mode 100644index 0000000..c8fee99--- /dev/null+++ b/src/extension/components/context-card.tsx@@ -0,0 +1,135 @@+import type { ReactNode } from 'react';+import { Clapperboard, Cpu, FileText, Globe, Layers, type LucideIcon } from 'lucide-react';++import { AGENTS } from '@/lib/agents/catalog';+import type { ContextBreakdown } from '@/lib/bridge/commands';+import { cn } from '@/lib/utils';++const SEGMENTS = [+ { key: 'user', label: 'you', color: 'bg-brand' },+ { key: 'assistant', label: 'replies', color: 'bg-magenta' },+ { key: 'tools', label: 'tools', color: 'bg-amber' },+ { key: 'notices', label: 'notices', color: 'bg-ink-faint' },+] as const;++export function ContextCard({ breakdown }: { breakdown: ContextBreakdown }) {+ const { messages, files, recordings, filesOmitted, recordingsOmitted } = breakdown;+ const total = SEGMENTS.reduce((sum, segment) => sum + messages[segment.key], 0);+ const empty = total === 0 && files.length === 0 && recordings.length === 0;++ return (+ <div className="enters panel-card min-w-0 rounded-2xl px-3 py-2.5">+ <div className="flex items-center gap-2">+ <Layers className="size-3.5 shrink-0 text-brand" />+ <span className="flex-1 truncate font-mono text-[10px] tracking-[0.14em] text-ink uppercase">+ Session context+ </span>+ <span className="shrink-0 rounded-full bg-ground/60 px-2 py-0.5 font-mono text-[9px] tracking-[0.1em] text-ink-faint uppercase">+ {agentLabel(breakdown)}+ </span>+ </div>++ {empty ? (+ <p className="mt-2 text-[11px] text-ink-dim">This conversation is empty — nothing rides along yet.</p>+ ) : (+ <>+ {total > 0 && (+ <>+ <div className="mt-2.5 flex h-1.5 gap-px overflow-hidden rounded-full">+ {SEGMENTS.filter((segment) => messages[segment.key] > 0).map((segment) => (+ <span key={segment.key} className={segment.color} style={{ flexGrow: messages[segment.key] }} />+ ))}+ </div>+ <div className="mt-1.5 flex flex-wrap gap-x-3 gap-y-0.5">+ {SEGMENTS.map((segment) => (+ <span key={segment.key} className="flex items-center gap-1 text-[10px] text-ink-dim">+ <span className={cn('size-1.5 shrink-0 rounded-full', segment.color)} />+ <span className="font-mono">{messages[segment.key]}</span> {segment.label}+ </span>+ ))}+ </div>+ </>+ )}++ <div className="mt-2.5 flex flex-col gap-1 border-t border-line pt-2">+ <Row icon={Globe}>+ {breakdown.tabCount === 1 ? '1 tab' : `${breakdown.tabCount} tabs`}+ {breakdown.host && <> · {breakdown.host}</>} · turn{' '}+ <span className="font-mono text-[10px]">{breakdown.turns}</span> ·{' '}+ <span className="font-mono text-[10px]">{compact(messages.chars)}</span> characters+ </Row>+ <Row icon={Cpu}>+ {breakdown.usage ? (+ <>+ Agent window ≈ <span className="font-mono text-[10px]">{compact(breakdown.usage.contextTokens)}</span>{' '}+ tokens · <span className="font-mono text-[10px]">{compact(breakdown.usage.outputTokens)}</span>{' '}+ generated last run+ </>+ ) : breakdown.agent === 'antigravity' ? (+ 'Antigravity does not report token counts.'+ ) : (+ 'Token counts appear after the agent’s first reply.'+ )}+ </Row>+ {files.map((file, index) => (+ <Row key={index} icon={FileText}>+ <span className="text-ink">{file.name}</span>+ <span className="font-mono text-[10px] text-ink-faint"> · {formatBytes(file.size)}</span>+ {file.status === 'pending' && <span className="text-ink-faint"> · analyzing</span>}+ {file.status === 'error' && <span className="text-destructive"> · analysis failed</span>}+ </Row>+ ))}+ {filesOmitted > 0 && (+ <p className="pl-[18px] text-[10px] text-ink-faint">+ {filesOmitted} more {filesOmitted === 1 ? 'file stays' : 'files stay'} behind — only the first{' '}+ {files.length} ride along.+ </p>+ )}+ {recordings.map((recording, index) => (+ <Row key={index} icon={Clapperboard}>+ <span className="text-ink">{recording.name}</span>+ {recording.steps !== undefined && (+ <span className="font-mono text-[10px] text-ink-faint"> · {recording.steps} steps</span>+ )}+ </Row>+ ))}+ {recordingsOmitted > 0 && (+ <p className="pl-[18px] text-[10px] text-ink-faint">+ {recordingsOmitted} more {recordingsOmitted === 1 ? 'recording stays' : 'recordings stay'} behind —+ only the first {recordings.length} ride along.+ </p>+ )}+ </div>+ </>+ )}++ <p className="mt-2 text-[10px] leading-relaxed text-ink-faint">+ Held in this browser — files and ready recordings ride along with your next message.+ </p>+ </div>+ );+}++function Row({ icon: Icon, children }: { icon: LucideIcon; children: ReactNode }) {+ return (+ <div className="flex min-w-0 items-start gap-1.5 text-[11px] text-ink-dim">+ <Icon className="mt-0.5 size-3 shrink-0 text-ink-faint" />+ <span className="min-w-0 flex-1 break-words">{children}</span>+ </div>+ );+}++function agentLabel(breakdown: ContextBreakdown): string {+ if (!breakdown.agent) return 'no agent yet';+ return `${AGENTS[breakdown.agent].label}${breakdown.resumes ? ' · resumes' : ''}`;+}++function compact(n: number): string {+ return n < 1000 ? String(n) : `${(n / 1000).toFixed(n < 10_000 ? 1 : 0)} k`;+}++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/src/extension/components/run-timeline.tsx b/src/extension/components/run-timeline.tsxindex b39dcb3..d51be6f 100644--- a/src/extension/components/run-timeline.tsx+++ b/src/extension/components/run-timeline.tsx@@ -26,6 +26,7 @@ import {type LucideIcon,} from 'lucide-react';+import { ContextCard } from '@/extension/components/context-card';import { Markdown } from '@/extension/components/markdown';import { Button } from '@/extension/components/ui/button';import { openScreenshot } from '@/lib/bridge/screenshot-preview';@@ -50,6 +51,8 @@ export function RunTimeline({ items, running, onDecide }: RunTimelineProps) {<ToolRow key={item.id} item={item} onDecide={onDecide} />) : item.kind === 'notice' ? (<Notice key={item.id} item={item} />+ ) : item.kind === 'context' ? (+ <ContextCard key={item.id} breakdown={item.breakdown} />) : item.kind === 'user' ? (<UserBubble key={item.id} text={item.text} focus={item.focus} />) : (diff --git a/src/extension/components/skill-menu.tsx b/src/extension/components/skill-menu.tsxindex 43d4b1a..b721bc4 100644--- a/src/extension/components/skill-menu.tsx+++ b/src/extension/components/skill-menu.tsx@@ -1,26 +1,42 @@-import { BookOpen, Globe, Sparkles } from 'lucide-react';+import { BookOpen, Globe, Sparkles, SquareSlash } from 'lucide-react';import type { SkillCatalog } from '@/lib/actions/protocol';import { AGENTS } from '@/lib/agents/catalog';+import { CONTEXT_COMMAND, CONTEXT_COMMAND_DESCRIPTION } from '@/lib/bridge/commands';import { hostMatchesDomains, hostnameOf } from '@/lib/skills/format';import { cn } from '@/lib/utils';export interface SkillMenuItem {key: string;- group: 'site' | 'general' | 'agent' | 'other-site';+ group: 'command' | 'site' | 'general' | 'agent' | 'other-site';name: string;description: string;/** Set on agent skills — choosing one attaches this id to the message instead of a text prefix. */agentSkillId?: string;+ /** Set on typed commands — choosing one sends this text right away instead of inserting a prefix. */+ command?: string;}-const GROUP_ORDER: Record<SkillMenuItem['group'], number> = { site: 0, general: 1, agent: 2, 'other-site': 3 };+const GROUP_ORDER: Record<SkillMenuItem['group'], number> = {+ command: 0,+ site: 1,+ general: 2,+ agent: 3,+ 'other-site': 4,+};export function skillMenuItems(catalog: SkillCatalog | undefined, tabUrl: string, query: string): SkillMenuItem[] {- if (!catalog) return [];const host = hostnameOf(tabUrl);- const items: SkillMenuItem[] = [];- for (const skill of catalog.skills) {+ const items: SkillMenuItem[] = [+ {+ key: 'command:context',+ group: 'command',+ name: 'context',+ description: CONTEXT_COMMAND_DESCRIPTION,+ command: CONTEXT_COMMAND,+ },+ ];+ for (const skill of catalog?.skills ?? []) {const group =skill.category !== 'site-exploration'? 'general'@@ -29,7 +45,7 @@ export function skillMenuItems(catalog: SkillCatalog | undefined, tabUrl: string: 'other-site';items.push({ key: `${group}:${skill.name}`, group, name: skill.name, description: skill.description });}- for (const skill of catalog.agentSkills) {+ for (const skill of catalog?.agentSkills ?? []) {items.push({ key: `agent:${skill.id}`, group: 'agent', name: skill.name, description: skill.description, agentSkillId: skill.id });}const needle = query.trim().toLowerCase();@@ -55,6 +71,7 @@ export function SkillMenu({onSelect: (item: SkillMenuItem) => void;}) {const labels: Record<SkillMenuItem['group'], string> = {+ command: 'Commands',site: 'On this site',general: 'Browsentic skills',agent: `${agent ? AGENTS[agent].label : 'Agent'} skills`,@@ -64,11 +81,11 @@ export function SkillMenu({return (<divrole="listbox"- aria-label="Skills"+ aria-label="Skills and commands"className="enters absolute inset-x-0 bottom-full z-20 mb-2 max-h-64 overflow-y-auto rounded-xl border border-line bg-surface shadow-lg">{items.length === 0 ? (- <p className="px-3 py-2.5 text-[11px] text-ink-faint">No skills match — keep typing, or press Escape.</p>+ <p className="px-3 py-2.5 text-[11px] text-ink-faint">Nothing matches — keep typing, or press Escape.</p>) : (items.map((item, index) => (<div key={item.key}>@@ -91,7 +108,9 @@ export function SkillMenu({index === highlight ? 'bg-brand/12' : 'hover:bg-ground/40',)}>- {item.group === 'agent' ? (+ {item.group === 'command' ? (+ <SquareSlash className="mt-0.5 size-3 shrink-0 text-amber" />+ ) : item.group === 'agent' ? (<Sparkles className="mt-0.5 size-3 shrink-0 text-brand" />) : item.group === 'general' ? (<BookOpen className="mt-0.5 size-3 shrink-0 text-ink-faint" />diff --git a/src/extension/entrypoints/sidepanel/App.tsx b/src/extension/entrypoints/sidepanel/App.tsxindex 27bf77e..7e2f198 100644--- a/src/extension/entrypoints/sidepanel/App.tsx+++ b/src/extension/entrypoints/sidepanel/App.tsx@@ -343,6 +343,10 @@ export default function App() {focus={focus}picking={picking}onAttachSkill={setAttachedSkill}+ onCommand={(command) => {+ open('chat');+ run.send(command);+ }}onSend={handleSend}onStop={run.cancel}onToggleVoice={toggleVoice}diff --git a/src/lib/bridge/commands.ts b/src/lib/bridge/commands.tsnew file mode 100644index 0000000..4fbf319--- /dev/null+++ b/src/lib/bridge/commands.ts@@ -0,0 +1,28 @@+import type { TokenUsage } from '@/lib/actions/protocol';+import type { AgentKind } from '@/lib/agents/catalog';+import type { FileStatus } from './file-store';++export const CONTEXT_COMMAND = '/context';++export const CONTEXT_COMMAND_DESCRIPTION =+ 'See what this conversation carries — messages, files, recordings, tabs.';++export const isContextCommand = (text: string): boolean => text.trim().toLowerCase() === CONTEXT_COMMAND;++export interface ContextBreakdown {+ agent?: AgentKind;+ /** The agent can pick its own conversation back up — an agent session id is held. */+ resumes: boolean;+ /** Token counts from the agent CLI's own reporting; absent until it reports, or when it never does. */+ usage?: TokenUsage;+ turns: number;+ tabCount: number;+ host?: string;+ messages: { user: number; assistant: number; tools: number; notices: number; chars: number };+ files: { name: string; size: number; status: FileStatus }[];+ /** Attached beyond the ride-along cap — stored, but not sent with the next message. */+ filesOmitted: number;+ recordings: { name: string; steps?: number }[];+ recordingsOmitted: number;+ capturedAt: number;+}diff --git a/src/lib/bridge/run-items.ts b/src/lib/bridge/run-items.tsindex abea697..162790c 100644--- a/src/lib/bridge/run-items.ts+++ b/src/lib/bridge/run-items.ts@@ -1,6 +1,7 @@import { screenshot } from '@/lib/actions/page/screenshot';import type { RunEvent } from '@/lib/actions/protocol';import type { MonitorState } from '@/lib/monitor/events';+import type { ContextBreakdown } from './commands';import { redactInput } from './redact';import type { ScreenshotPreview } from './screenshot-preview';@@ -8,6 +9,7 @@ export type RunItem =| { kind: 'user'; id: string; text: string; focus?: string }| { kind: 'assistant'; id: string; text: string }| { kind: 'notice'; id: string; tone: 'info' | 'error'; text: string }+ | { kind: 'context'; id: string; breakdown: ContextBreakdown }| {kind: 'tool';id: string;diff --git a/src/lib/bridge/run-port.ts b/src/lib/bridge/run-port.tsindex 879c1af..f96e4a6 100644--- a/src/lib/bridge/run-port.ts+++ b/src/lib/bridge/run-port.ts@@ -10,6 +10,7 @@ import type { MonitorState } from '@/lib/monitor/events';import type { RecordingState } from '@/lib/recordings/events';import type { SiteMapDraft } from '@/lib/skills/site-map';import { navigate } from '@/lib/actions/page/navigate';+import { CONTEXT_COMMAND, isContextCommand, type ContextBreakdown } from './commands';import { tryFastPath } from './fast-path';import { dropDiagnosticsForSession } from './diagnostics';import { listMeta } from './file-store';@@ -24,7 +25,7 @@ import {import { currentRecording, onRecordingState, startActiveTabRecording, stopRecording } from './recorder';import { asSavedRecording, listRecordings } from './recording-store';import { forgetTab, syncRunIndicator } from './run-indicator';-import { attachPreview, monitorNotice, notice, patchTool, reduce, type RunItem } from './run-items';+import { attachPreview, monitorNotice, nextId, notice, patchTool, reduce, type RunItem } from './run-items';import { onScreenshotPreview, type ScreenshotPreview } from './screenshot-preview';import {listSessions,@@ -324,6 +325,14 @@ async function instruct(return;}+ if (isContextCommand(text)) {+ const { sessionId } = ensured.session;+ const breakdown = await contextBreakdown(ensured.session, await bufferFor(sessionId));+ await append(sessionId, { kind: 'user', id: nextId(), text: CONTEXT_COMMAND });+ await append(sessionId, { kind: 'context', id: nextId(), breakdown });+ return;+ }+const outcome = await startTurn(ensured.session, text, { agentSkillId, focus, fastPath: true });if (outcome !== 'busy') return;await append(@@ -620,6 +629,38 @@ async function attachedRecordings(): Promise<SavedRecording[]> {}}+async function contextBreakdown(session: TabSession, items: RunItem[]): Promise<ContextBreakdown> {+ const messages = { user: 0, assistant: 0, tools: 0, notices: 0, chars: 0 };+ for (const item of items) {+ if (item.kind === 'user') {+ messages.user += 1;+ messages.chars += item.text.length;+ } else if (item.kind === 'assistant') {+ messages.assistant += 1;+ messages.chars += item.text.length;+ } else if (item.kind === 'tool') messages.tools += 1;+ else if (item.kind === 'notice') messages.notices += 1;+ }+ const files = await listMeta().catch(() => []);+ const ready = (await listRecordings().catch(() => [])).filter((recording) => recording.status === 'ready');+ return {+ agent: session.agent,+ resumes: session.agentSessionId !== undefined,+ usage: session.usage,+ turns: session.turns,+ tabCount: session.tabIds.length,+ host: session.host,+ messages,+ files: files.slice(0, MAX_CONTEXT_FILES).map((file) => ({ name: file.name, size: file.size, status: file.status })),+ filesOmitted: Math.max(0, files.length - MAX_CONTEXT_FILES),+ recordings: ready+ .slice(0, MAX_CONTEXT_RECORDINGS)+ .map((recording) => ({ name: recording.name, steps: recording.steps })),+ recordingsOmitted: Math.max(0, ready.length - MAX_CONTEXT_RECORDINGS),+ capturedAt: Date.now(),+ };+}+const noticeOf = (state: MonitorState): ['info' | 'error', string] => {const { tone, text } = monitorNotice(state);return [tone, text];