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(mcp): keep a conversation's tool list from changing between messages, because the list leads the cached prefix and a follow-up re-bills the whole history
Shahriard084438194f6
diff --git a/src/daemon/agent/service.test.ts b/src/daemon/agent/service.test.tsnew file mode 100644index 0000000..0e39baf--- /dev/null+++ b/src/daemon/agent/service.test.ts@@ -0,0 +1,53 @@+import { mkdirSync, writeFileSync } from 'node:fs';+import { dirname } from 'node:path';+import { beforeEach, describe, expect, test, vi } from 'vitest';+import { FOCUS_SHOT_ACTION } from '@/lib/actions/reserved';+import type { RunEvent } from '@/lib/actions/protocol';+import { failure } from '@/lib/actions/protocol';+import { configPath } from './config';+import { AgentSession } from './service';++const CODE_TOOLS = ['page.injectCode', 'page.runCode'];++let session: AgentSession;+let ended: string[];++beforeEach(() => {+ // No agent to find, so every run is refused once it has been admitted — after its offer can be read.+ mkdirSync(dirname(configPath), { recursive: true });+ writeFileSync(configPath, JSON.stringify({ claudeBin: '/nonexistent/claude' }));+ ended = [];+ session = new AgentSession({+ invoke: async () => failure('EXTENSION_OFFLINE', 'no browser'),+ emit: (runId: string, event: RunEvent) => void (event.kind === 'error' && ended.push(runId)),+ draft: () => {},+ });+});++async function offerTo(runId: string, context: { sessionId?: string; liveTools?: boolean }) {+ session.handle({ t: 'instruct', id: runId, text: 'click Sign in', context });+ const offer = session.offerFor(runId);+ await vi.waitFor(() => expect(ended).toContain(runId));+ return offer;+}++describe("what a run's tool list holds", () => {+ test('nothing, for a run that is not active', () => {+ expect(session.offerFor('gone')).toBeNull();+ });++ test('the page-code tools only with Live tool on, and the pick’s screenshot either way', async () => {+ expect([await offerTo('a', { sessionId: 's1' }), await offerTo('b', { sessionId: 's2', liveTools: true })]).toEqual([+ { withheld: CODE_TOOLS, reserved: [FOCUS_SHOT_ACTION] },+ { withheld: [], reserved: [FOCUS_SHOT_ACTION] },+ ]);+ });++ test('a conversation that was shown the page-code tools keeps them, until it is reset', async () => {+ await offerTo('a', { sessionId: 's1', liveTools: true });+ const switchedOff = await offerTo('b', { sessionId: 's1' });+ session.handle({ t: 'reset', sessionId: 's1' });+ const afterReset = await offerTo('c', { sessionId: 's1' });+ expect([switchedOff?.withheld, afterReset?.withheld]).toEqual([[], CODE_TOOLS]);+ });+});diff --git a/src/daemon/agent/service.ts b/src/daemon/agent/service.tsindex 404bed3..74d407c 100644--- a/src/daemon/agent/service.ts+++ b/src/daemon/agent/service.ts@@ -91,6 +91,12 @@ export class AgentSession {/** Per session, the conversation its agent is holding open. Switching agents drops them all. */private held = new Map<string, { agent: AgentKind; sessionId: string }>();private runs = new Map<string, ActiveRun>();+ /**+ * Conversations that have been shown the page-code tools. The tool list leads the+ * prefix an agent caches, so it may grow once within a conversation and never shrink:+ * a follow-up lands while the cache is warm, and a changed list re-bills its history.+ */+ private codeListed = new Set<string>();constructor(private readonly deps: AgentSessionDeps) {}@@ -109,8 +115,13 @@ export class AgentSession {});return;case 'reset':- if (request.sessionId) this.held.delete(request.sessionId);- else this.held.clear();+ if (request.sessionId) {+ this.held.delete(request.sessionId);+ this.codeListed.delete(request.sessionId);+ } else {+ this.held.clear();+ this.codeListed.clear();+ }log(request.sessionId ? `agent conversation reset for session ${request.sessionId}` : 'agent conversations reset');return;}@@ -123,9 +134,12 @@ export class AgentSession {offerFor(runId: string): { withheld: string[]; reserved: string[] } | null {const run = this.runs.get(runId);if (!run) return null;+ const codeListed = run.liveTools || (run.sessionId !== undefined && this.codeListed.has(run.sessionId));return {- withheld: run.liveTools ? [] : [INJECT_ACTION, RUN_CODE_ACTION],- reserved: [...(run.map ? [SAVE_SITE_MAP_ACTION] : []), ...(run.focusShot ? [FOCUS_SHOT_ACTION] : [])],+ withheld: codeListed ? [] : [INJECT_ACTION, RUN_CODE_ACTION],+ // A mapping run never resumes a conversation, so its tool can come and go. A pick+ // comes and goes between the messages of one, so the tool that shows it stays.+ reserved: [...(run.map ? [SAVE_SITE_MAP_ACTION] : []), FOCUS_SHOT_ACTION],};}@@ -214,6 +228,7 @@ export class AgentSession {dispose(): void {for (const runId of [...this.runs.keys()]) this.cancel(runId);this.held.clear();+ this.codeListed.clear();}private async start(runId: string, instruction: string, context?: RunContext): Promise<void> {@@ -296,6 +311,7 @@ export class AgentSession {liveTools: context?.liveTools === true,};this.runs.set(runId, run);+ if (run.liveTools && sessionId) this.codeListed.add(sessionId);// Claim the slot before probing, so a second instruction still meets RUN_IN_PROGRESS.const runner = activeRunner(await agentState(config));