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(monitor): show live monitor bars in the side panel
Shahriare59131e63c6c
diff --git a/components/monitor-bar.tsx b/components/monitor-bar.tsxnew file mode 100644index 0000000..9c10b8f--- /dev/null+++ b/components/monitor-bar.tsx@@ -0,0 +1,57 @@+import { useEffect, useState } from 'react';+import { Square } from 'lucide-react';+import { Button } from '@/components/ui/button';+import { formatEta, type MonitorState } from '@/lib/monitor/events';++export function MonitorBar({ state, onStop }: { state: MonitorState; onStop: () => void }) {+ const elapsed = useElapsed(state.startedAt);+ const left = Math.max(0, state.timeoutMs - elapsed);+ const percent = state.percent != null ? Math.round(state.percent) : null;++ return (+ <div className="mb-2 rounded-md border border-sky-500/40 bg-sky-500/5 p-2.5">+ <div className="flex items-center gap-2">+ <span className="size-2 shrink-0 animate-pulse rounded-full bg-sky-500" />+ <span className="min-w-0 truncate text-xs font-medium">Watching {state.label ?? state.host}</span>+ <span className="font-mono text-xs tabular-nums text-muted-foreground">{clock(elapsed)}</span>+ <span className="flex-1 text-right font-mono text-[11px] tabular-nums text-muted-foreground">+ {percent != null ? `${percent}%` : ''}+ </span>+ <Button+ size="sm"+ className="h-6 shrink-0 bg-sky-600 px-2 text-xs text-white shadow-xs hover:bg-sky-700"+ onClick={onStop}+ >+ <Square className="size-3 fill-current" /> Stop+ </Button>+ </div>+ {percent != null && (+ <div className="mt-1.5 h-1 overflow-hidden rounded-full bg-sky-500/15">+ <div className="h-full rounded-full bg-sky-500 transition-[width]" style={{ width: `${percent}%` }} />+ </div>+ )}+ <p className="mt-1.5 text-[11px] leading-relaxed text-muted-foreground">{statusLine(state, left)}</p>+ </div>+ );+}++function statusLine(state: MonitorState, left: number): string {+ if (state.stalledForMs != null) return `No change for ${clock(state.stalledForMs)}.`;+ if (state.percent != null && state.etaMs != null) return `${Math.round(state.percent)}% · ${formatEta(state.etaMs)} left`;+ const lastLog = state.logs.at(-1)?.text;+ return lastLog ?? `Stops automatically in ${clock(left)}.`;+}++function useElapsed(startedAt: number): number {+ const [now, setNow] = useState(() => Date.now());+ useEffect(() => {+ const timer = setInterval(() => setNow(Date.now()), 1_000);+ return () => clearInterval(timer);+ }, []);+ return Math.max(0, now - startedAt);+}++function clock(ms: number): string {+ const total = Math.floor(ms / 1000);+ return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, '0')}`;+}diff --git a/entrypoints/sidepanel/App.tsx b/entrypoints/sidepanel/App.tsxindex 66990fc..c41edbe 100644--- a/entrypoints/sidepanel/App.tsx+++ b/entrypoints/sidepanel/App.tsx@@ -5,6 +5,7 @@ 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 { MonitorBar } from '@/components/monitor-bar';import { RecordingBar } from '@/components/recording-bar';import { RecordingPanel } from '@/components/recording-panel';import { RunTimeline } from '@/components/run-timeline';@@ -190,6 +191,9 @@ export default function App() {</p>)}{run.recording && <RecordingBar state={run.recording} onStop={run.stopRecording} />}+ {run.monitors.map((monitor) => (+ <MonitorBar key={monitor.monitorId} state={monitor} onStop={() => run.stopMonitor(monitor.monitorId)} />+ ))}{run.draft && (<SiteMapReview draft={run.draft} onActivate={run.activateMap} onDiscard={run.discardMap} />)}diff --git a/lib/bridge/run-port.ts b/lib/bridge/run-port.tsindex 80696c0..593bb4e 100644--- a/lib/bridge/run-port.ts+++ b/lib/bridge/run-port.ts@@ -6,10 +6,18 @@ import {type RunEvent,type SavedRecording,} from '@/lib/actions/protocol';+import type { MonitorState } from '@/lib/monitor/events';import type { RecordingState } from '@/lib/recordings/events';import type { SiteMapDraft } from '@/lib/skills/site-map';import { tryFastPath } from './fast-path';import { listMeta } from './file-store';+import {+ acknowledgeCompleted,+ activeMonitorStates,+ completedMonitorStates,+ onMonitorState,+ stopTabMonitor,+} from './monitor';import { currentRecording, onRecordingState, startActiveTabRecording, stopRecording } from './recorder';import { asSavedRecording, listRecordings } from './recording-store';import { onScreenshotPreview, type ScreenshotPreview } from './screenshot-preview';@@ -42,7 +50,8 @@ export type RunCommand =| { op: 'activateMap'; stagingId: string; exactHost?: boolean }| { op: 'discardMap'; stagingId: string }| { op: 'startRecording'; captureValues: boolean }- | { op: 'stopRecording' };+ | { op: 'stopRecording' }+ | { op: 'stopMonitor'; monitorId: string };export type RunMessage =| { op: 'event'; runId: string; event: RunEvent }@@ -50,7 +59,8 @@ export type RunMessage =| { op: 'mapDraft'; draft: SiteMapDraft }| { op: 'mapSettled'; stagingId: string; ok: boolean; message?: string }| { op: 'recording'; state: RecordingState | null }- | { op: 'preview'; preview: ScreenshotPreview };+ | { op: 'preview'; preview: ScreenshotPreview }+ | { op: 'monitor'; state: MonitorState };const ports = new Set<Browser.runtime.Port>();let activeRunId: string | null = null;@@ -69,6 +79,11 @@ export function serveRunPorts(): void {onScreenshotPreview((preview) => broadcast({ op: 'preview', preview }));+ onMonitorState((state) => {+ broadcast({ op: 'monitor', state });+ if (state.phase !== 'watching' && ports.size > 0) void acknowledgeCompleted(state.monitorId);+ });+onSiteMapDraft((_runId, draft) => {pendingDraft = draft;broadcast({ op: 'mapDraft', draft });@@ -96,6 +111,14 @@ export function serveRunPorts(): void {post(port, { op: 'active', runId: activeRunId });if (pendingDraft) post(port, { op: 'mapDraft', draft: pendingDraft });void currentRecording().then((state) => post(port, { op: 'recording', state }));+ void activeMonitorStates().then((states) => {+ for (const state of states) post(port, { op: 'monitor', state });+ });+ void completedMonitorStates().then((states) => {+ if (!states.length) return;+ for (const state of states) post(port, { op: 'monitor', state });+ void acknowledgeCompleted();+ });port.onMessage.addListener((message) => handle(message as RunCommand));port.onDisconnect.addListener(() => {@@ -162,6 +185,9 @@ function handle(command: RunCommand): void {case 'stopRecording':void stopRecording('user');return;+ case 'stopMonitor':+ void stopTabMonitor(command.monitorId);+ return;case 'reset':resetConversation();return;diff --git a/lib/bridge/use-run.ts b/lib/bridge/use-run.tsindex fd1c81a..d6990c8 100644--- a/lib/bridge/use-run.ts+++ b/lib/bridge/use-run.ts@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';import { browser, type Browser } from 'wxt/browser';import { screenshot } from '@/lib/actions/page/screenshot';import { BRIDGE_CHANNEL, type RunEvent } from '@/lib/actions/protocol';+import type { MonitorState } from '@/lib/monitor/events';import type { RecordingState } from '@/lib/recordings/events';import { SITE_MAPPER_SKILL, type SiteMapDraft } from '@/lib/skills/site-map';import { redactInput } from './redact';@@ -45,6 +46,8 @@ export interface Run {recording: RecordingState | null;startRecording: (captureValues: boolean) => void;stopRecording: () => void;+ monitors: MonitorState[];+ stopMonitor: (monitorId: string) => void;}type SessionState = SessionFields;@@ -59,6 +62,7 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {const [running, setRunning] = useState(false);const [draft, setDraft] = useState<SiteMapDraft | null>(null);const [recording, setRecording] = useState<RecordingState | null>(null);+ const [monitors, setMonitors] = useState<MonitorState[]>([]);const port = useRef<Browser.runtime.Port | null>(null);const session = useRef<SessionState>(freshSession());@@ -101,7 +105,19 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {]);}} else if (runMessage.op === 'recording') setRecording(runMessage.state);- else if (runMessage.op === 'preview') {+ else if (runMessage.op === 'monitor') {+ const state = runMessage.state;+ if (state.phase === 'watching') {+ setMonitors((previous) => {+ const others = previous.filter((m) => m.monitorId !== state.monitorId);+ return [...others, state];+ });+ } else {+ setMonitors((previous) => previous.filter((m) => m.monitorId !== state.monitorId));+ const notice = monitorNotice(state);+ setItems((previous) => [...previous, { kind: 'notice', id: nextId(), ...notice }]);+ }+ } else if (runMessage.op === 'preview') {setItems((previous) => attachPreview(previous, runMessage.preview));} else {if (runMessage.event.kind === 'session') {@@ -268,6 +284,13 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {stopRecording: useCallback(() => {post({ op: 'stopRecording' });}, [post]),+ monitors,+ stopMonitor: useCallback(+ (monitorId: string) => {+ post({ op: 'stopMonitor', monitorId });+ },+ [post],+ ),cancel: useCallback(() => {if (!post({ op: 'cancel' })) lost('Lost the connection to the extension, so this run is no longer being watched.');}, [post, lost]),@@ -283,6 +306,28 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {};}+function monitorNotice(state: MonitorState): { tone: 'info' | 'error'; text: string } {+ const name = state.label ?? state.host;+ const elapsed = clock(state.elapsedMs);+ switch (state.phase) {+ case 'done':+ return { tone: 'info', text: `Monitor “${name}” finished after ${elapsed}.` };+ case 'stopped':+ return { tone: 'info', text: `Monitor “${name}” stopped.` };+ case 'timeout':+ return { tone: 'error', text: `Monitor “${name}” gave up after ${elapsed} without completing.` };+ case 'tab-closed':+ return { tone: 'error', text: `Monitor “${name}” ended — the tab was closed.` };+ default:+ return { tone: 'error', text: `Monitor “${name}” ended — ${state.message ?? 'the tab left the watched site.'}` };+ }+}++function clock(ms: number): string {+ const total = Math.floor(ms / 1000);+ return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, '0')}`;+}+function hostOf(url: string): string | null {try {return new URL(url).host || null;