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
fix(site-maps): keep map reviews with their conversation
Shahriare6db4557aaf0
diff --git a/docs/guide/features/site-maps.md b/docs/guide/features/site-maps.mdindex b847583..75099f1 100644--- a/docs/guide/features/site-maps.md+++ b/docs/guide/features/site-maps.md@@ -43,7 +43,9 @@ A map in flight is written to a staging directory the skill loader **cannot readmap is not merely unused — it is never opened.The panel shows you the exact markdown as plain text, never rendered, along with the domain it will-match. **Activate** arms it; **Discard** deletes it.+match. **Activate** arms it; **Discard** deletes it. The review appears on the conversation that+mapped the site — switch back to that tab to decide. If that tab closes first, the review follows+you so an unsaved map is never lost.> A map is written from pages an agent read, so read it before activating, as you would any> generated content.diff --git a/src/lib/bridge/run-port.ts b/src/lib/bridge/run-port.tsindex c316925..ee418a4 100644--- a/src/lib/bridge/run-port.ts+++ b/src/lib/bridge/run-port.ts@@ -90,8 +90,8 @@ export type RunMessage =| { op: 'event'; sessionId?: string; runId: string; event: RunEvent }| { op: 'item'; sessionId?: string; item: RunItem }| { op: 'items'; sessionId?: string; items: RunItem[] }- | { op: 'mapDraft'; draft: SiteMapDraft }- | { op: 'mapSettled'; stagingId: string; ok: boolean; message?: string }+ | { op: 'mapDraft'; sessionId?: string; draft: SiteMapDraft }+ | { op: 'mapSettled'; sessionId?: string; stagingId: string; ok: boolean; message?: string }| { op: 'recording'; state: RecordingState | null }| { op: 'preview'; sessionId?: string; preview: ScreenshotPreview }| { op: 'monitor'; state: MonitorState }@@ -105,7 +105,7 @@ const busy = new Set<string>();const persistTimers = new Map<string, ReturnType<typeof setTimeout>>();const cancelTimers = new Map<string, ReturnType<typeof setTimeout>>();let externalItems: RunItem[] = [];-let pendingDraft: SiteMapDraft | null = null;+const pendingDrafts = new Map<string, { sessionId?: string; draft: SiteMapDraft }>();let queue: Promise<unknown> = Promise.resolve();function serialized<T>(task: () => Promise<T>): Promise<T> {@@ -152,9 +152,17 @@ export function serveRunPorts(): void {}),);- onSiteMapDraft((_runId, draft) => {- pendingDraft = draft;- broadcast({ op: 'mapDraft', draft });+ onSiteMapDraft((runId, draft) => {+ void serialized(async () => {+ const session = await sessionForRun(runId);+ if (session) {+ for (const [stagingId, held] of pendingDrafts) {+ if (held.sessionId === session.sessionId) pendingDrafts.delete(stagingId);+ }+ }+ pendingDrafts.set(draft.stagingId, { sessionId: session?.sessionId, draft });+ broadcast({ op: 'mapDraft', sessionId: session?.sessionId, draft });+ });});onWelcome(() => {@@ -184,7 +192,9 @@ export function serveRunPorts(): void {panelPorts.add(port);if (panelPorts.size === 1) for (const watch of panelWatchers) watch(true);}- if (pendingDraft) post(port, { op: 'mapDraft', draft: pendingDraft });+ for (const held of pendingDrafts.values()) {+ post(port, { op: 'mapDraft', sessionId: held.sessionId, draft: held.draft });+ }void currentRecording().then((state) => post(port, { op: 'recording', state }));void activeMonitorStates().then((states) => {for (const state of states) post(port, { op: 'monitor', state });@@ -243,13 +253,14 @@ function handle(command: RunCommand): void {return;case 'activateMap':case 'discardMap': {- const draft = pendingDraft;+ const held = pendingDrafts.get(command.stagingId);const settle =command.op === 'activateMap'? activateSiteMap(command.stagingId, command.exactHost): discardSiteMap(command.stagingId);void settle.then((result) => {- if (result.ok && command.op === 'activateMap' && draft?.stagingId === command.stagingId) {+ if (result.ok && command.op === 'activateMap' && held) {+ const { draft } = held;void recordGeneratedSkill({name: draft.name,domain: command.exactHost ? draft.host : draft.domain,@@ -258,9 +269,10 @@ function handle(command: RunCommand): void {generatedAt: draft.generatedAt,});}- if (pendingDraft?.stagingId === command.stagingId) pendingDraft = null;+ pendingDrafts.delete(command.stagingId);broadcast({op: 'mapSettled',+ sessionId: held?.sessionId,stagingId: command.stagingId,ok: result.ok,message: result.ok ? undefined : `${result.error.code}: ${result.error.message}`,@@ -456,6 +468,14 @@ async function endRun(sessionId: string, message: string): Promise<void> {await settle(sessionId);}+function orphanDrafts(sessionId: string): void {+ for (const held of pendingDrafts.values()) {+ if (held.sessionId !== sessionId) continue;+ held.sessionId = undefined;+ broadcast({ op: 'mapDraft', draft: held.draft });+ }+}+async function endSession(sessionId: string): Promise<void> {const session = (await readTabSessions())[sessionId];if (session?.runId) cancelRun(session.runId);@@ -467,6 +487,7 @@ async function endSession(sessionId: string): Promise<void> {await dropSession(sessionId);buffers.delete(sessionId);busy.delete(sessionId);+ orphanDrafts(sessionId);resetConversation(sessionId);await syncRunIndicator();}@@ -487,6 +508,7 @@ async function restore(sessionId: string, anchor: TabAnchor): Promise<void> {await persist(owner.sessionId);await dropSession(owner.sessionId);buffers.delete(owner.sessionId);+ orphanDrafts(owner.sessionId);}const meta = (await listSessions()).find((s) => s.id === sessionId);@@ -579,6 +601,7 @@ export function serveTabSessions(): void {await persist(closed.sessionId);buffers.delete(closed.sessionId);busy.delete(closed.sessionId);+ orphanDrafts(closed.sessionId);if (closed.runId) resetConversation(closed.sessionId);await syncRunIndicator();});diff --git a/src/lib/bridge/use-run.ts b/src/lib/bridge/use-run.tsindex c1e7783..df9c76c 100644--- a/src/lib/bridge/use-run.ts+++ b/src/lib/bridge/use-run.ts@@ -45,7 +45,7 @@ export interface Run {}export function useRun(): Run {- const [draft, setDraft] = useState<SiteMapDraft | null>(null);+ const [drafts, setDrafts] = useState<Record<string, SiteMapDraft>>({});const [recording, setRecording] = useState<RecordingState | null>(null);const [monitors, setMonitors] = useState<MonitorState[]>([]);const [bySession, setBySession] = useState<Record<string, RunItem[]>>({});@@ -88,11 +88,14 @@ export function useRun(): Run {connected.onMessage.addListener((message) => {const runMessage = message as RunMessage;- if (runMessage.op === 'mapDraft') setDraft(runMessage.draft);- else if (runMessage.op === 'mapSettled') {- setDraft((current) => (current?.stagingId === runMessage.stagingId ? null : current));+ if (runMessage.op === 'mapDraft') {+ setDrafts((previous) => ({ ...previous, [runMessage.sessionId ?? EXTERNAL_VIEW]: runMessage.draft }));+ } else if (runMessage.op === 'mapSettled') {+ setDrafts((previous) =>+ Object.fromEntries(Object.entries(previous).filter(([, held]) => held.stagingId !== runMessage.stagingId)),+ );if (!runMessage.ok && runMessage.message) {- write(EXTERNAL_VIEW, (items) => [...items, notice('error', runMessage.message!)]);+ write(runMessage.sessionId ?? EXTERNAL_VIEW, (items) => [...items, notice('error', runMessage.message!)]);}} else if (runMessage.op === 'recording') setRecording(runMessage.state);else if (runMessage.op === 'monitor') {@@ -152,6 +155,8 @@ export function useRun(): Run {return external.length ? [...own, ...external] : own;}, [sessionId, bySession]);+ const draft = (sessionId ? drafts[sessionId] : undefined) ?? drafts[EXTERNAL_VIEW] ?? null;+const send = useCallback((text: string, opts?: SendOptions) => {const trimmed = text.trim();