Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(browser): drive --screenshot/--cookies through the gate + write-unreachable guard (S8 PR9 Task 9.4)
Claude Code06fe9d798406
diff --git a/src/main/browser-cookie-write-guard.test.ts b/src/main/browser-cookie-write-guard.test.tsnew file mode 100644index 000000000..467204f7c--- /dev/null+++ b/src/main/browser-cookie-write-guard.test.ts@@ -0,0 +1,126 @@+import { describe, it, expect, vi } from 'vitest'+import fsp from 'node:fs/promises'+import os from 'node:os'+import path from 'node:path'+import { driveBrowser, type BrowserResolve, type DriveDeps, type LiveGuest } from './browser-drive'+import { CdpEventBus, type Driver, type LayoutMetrics } from './browser-actions'+import { COOKIE_WRITE_METHODS } from './browser-cdp-allowlist'+import { BrowserControlLedger } from './browser-control-ledger'+import { RefTable } from './browser-refs'+import { BROWSER_ACTION_KEYS, parseBrowserArgs, type BrowserCall } from '../core/browser-verb'++const OWNER = 'claude-1'+const NODE = 'browser-3'++const okResolve: BrowserResolve = {+ ok: true,+ projectId: 'proj-1',+ projectCwd: '/proj',+ sourceControlCapable: true,+ capabilityOn: true,+ sourceTitle: 'claude-1',+ browserTitle: 'browser-3'+}++/** A Driver that RECORDS every method it is asked to send — INTENT, before any allowlist — and+ * answers generically so each action runs far enough to emit its full method set. */+function recordingGuest(): { guest: LiveGuest; sent: string[] } {+ const sent: string[] = []+ const m: LayoutMetrics = { width: 800, height: 600, scrollX: 0, scrollY: 0, contentWidth: 800, contentHeight: 2000 }+ const session: Driver = {+ async send(method) {+ sent.push(method)+ switch (method) {+ case 'DOM.getDocument':+ return { root: { nodeId: 1 } }+ case 'DOM.resolveNode':+ return { object: { objectId: 'o' } }+ case 'Runtime.callFunctionOn':+ // Satisfy the readers that need coordinates AND the ones that need a value; a superset object.+ return { result: { value: { x: 10, y: 10, tag: 'button', text: 'ok' } } }+ case 'Page.getNavigationHistory':+ return { currentIndex: 0, entries: [{ url: 'https://x.test/' }] }+ case 'Page.captureScreenshot':+ return { data: Buffer.from('PNG').toString('base64') }+ case 'Network.getCookies':+ return { cookies: [] }+ case 'Page.getLayoutMetrics':+ return { cssLayoutViewport: { clientWidth: 800, clientHeight: 600 }, cssContentSize: { width: 800, height: 2000 } }+ default:+ return {}+ }+ },+ async refreshViewport() {+ return m+ }+ }+ return { guest: { session, bus: new CdpEventBus() }, sent }+}++function ledgerOwning(): BrowserControlLedger {+ const l = new BrowserControlLedger()+ l.claim(NODE, { ownerNodeId: OWNER, projectId: 'proj-1', partition: 'p', navGeneration: 0, leaseActiveUntil: 0, openedAt: 0 })+ return l+}++/** One representative call per action key — the whole action surface parseBrowserArgs admits. */+function callFor(action: string): BrowserCall {+ const base: Record<string, string> = { node: NODE, timeout: '10' }+ const args: Record<string, Record<string, string>> = {+ nav: { ...base, nav: 'https://x.test/' },+ read: { ...base, read: 'map' },+ click: { ...base, click: '#go' },+ type: { ...base, type: 'hello', into: '#f' },+ press: { ...base, press: 'Enter' },+ scroll: { ...base, scroll: 'down' },+ wait: { ...base, wait: '#done' },+ screenshot: { ...base, screenshot: 'shot.png' },+ cookies: { ...base, cookies: 'github.com' }+ }+ const parsed = parseBrowserArgs(args[action])+ if ('error' in parsed) throw new Error(`could not build a call for ${action}: ${parsed.error}`)+ return parsed+}++describe('Task 9.4 — no verb reaches a cookie WRITE (the set is listed & unreachable)', () => {+ it('enumerates every action and records the CDP methods each emits; the write intersection is empty', async () => {+ // A real project dir so the screenshot jail resolves; writeFile is a no-op spy.+ const project = await fsp.mkdtemp(path.join(os.tmpdir(), 'guard-'))+ const screenshotIO = {+ realpath: (p: string) => fsp.realpath(p),+ lstat: (p: string) => fsp.lstat(p),+ writeFile: vi.fn(async () => {})+ }+ const resolve: BrowserResolve = { ...okResolve, projectCwd: project }++ const emittedByAction: Record<string, string[]> = {}+ for (const action of BROWSER_ACTION_KEYS) {+ const { guest, sent } = recordingGuest()+ const deps: DriveDeps = {+ ledger: ledgerOwning(),+ refs: new RefTable(),+ sessionFor: () => guest,+ revoke: vi.fn(),+ appendBoardLog: async () => true, // the cookie trace succeeds so the read is reached+ screenshotIO+ }+ await driveBrowser({ call: callFor(action), ownerNodeId: OWNER, verified: true, resolve }, deps)+ emittedByAction[action] = sent+ }++ // Every action was actually exercised (a new action can't be added without appearing here).+ expect(Object.keys(emittedByAction).sort()).toEqual([...BROWSER_ACTION_KEYS].sort())++ // The union of everything any verb emits, intersected with the write set, must be empty.+ const writeSet = new Set<string>(COOKIE_WRITE_METHODS)+ const allEmitted = new Set<string>(Object.values(emittedByAction).flat())+ const reachableWrites = [...allEmitted].filter((m) => writeSet.has(m))+ expect(reachableWrites).toEqual([])++ // And, positively: the cookie READ path DID reach getCookies (so the emptiness above is not just+ // because nothing ran).+ expect(emittedByAction.cookies).toContain('Network.getCookies')++ await fsp.rm(project, { recursive: true, force: true })+ })+})diff --git a/src/main/browser-drive.test.ts b/src/main/browser-drive.test.tsindex a7da0d180..83bd638f0 100644--- a/src/main/browser-drive.test.ts+++ b/src/main/browser-drive.test.ts@@ -195,6 +195,105 @@ describe('a user-Stopped node refuses to re-drive until a fresh verified claim (})})+// ── PR 9: --cookies drives through the SAME gate and is loudly traced ───────────────────────────+describe('--cookies drives through the gate and traces BEFORE it reads (Task 9.3)', () => {+ function cookiesCall(): BrowserCall {+ const c = parseBrowserArgs({ node: NODE, cookies: 'github.com' })+ if ('error' in c) throw new Error(c.error)+ return c+ }++ it('the owner reads cookies, and the board-log trace is appended before the read', async () => {+ const ledger = freshLedgerOwning()+ const { guest, dbg } = makeGuest()+ const order: string[] = []+ const origSend = dbg.sendCommand.bind(dbg)+ dbg.sendCommand = async (m: string, p?: object) => {+ if (m === 'Network.getCookies') order.push('read')+ return m === 'Network.getCookies' ? { cookies: [{}, {}, {}, {}] } : origSend(m, p)+ }+ const appendBoardLog = vi.fn(async (_projectId: string, _entry: unknown) => {+ order.push('trace')+ return true+ })+ const deps: DriveDeps = { ledger, refs: new RefTable(), sessionFor: () => guest, revoke: vi.fn(), appendBoardLog }+ const r = await driveBrowser(+ { call: cookiesCall(), ownerNodeId: OWNER, verified: true, resolve: { ...okResolve, sourceTitle: 'claude-1', browserTitle: 'browser-3' } },+ deps+ )+ expect(r).toEqual({ ok: true, message: "read 4 cookies for github.com — this was recorded in the project's activity log." })+ expect(order).toEqual(['trace', 'read']) // the trace strictly precedes the read+ // The entry files under the OWNER's card, names the owner in `from`, the domain in `to`.+ const entry = appendBoardLog.mock.calls[0][1]+ expect(entry).toMatchObject({+ nodeId: OWNER,+ kind: 'event',+ event: { type: 'agent-read-cookies', from: 'claude-1', to: 'github.com', title: 'browser-3' }+ })+ })++ it('if the trace cannot be recorded, the read does not happen (fail-closed)', async () => {+ const ledger = freshLedgerOwning()+ const { guest, dbg } = makeGuest()+ const reads: string[] = []+ const origSend = dbg.sendCommand.bind(dbg)+ dbg.sendCommand = async (m: string, p?: object) => {+ if (m === 'Network.getCookies') reads.push(m)+ return origSend(m, p)+ }+ // No appendBoardLog wired at all ⇒ the read cannot be recorded ⇒ refuse without reading.+ const deps: DriveDeps = { ledger, refs: new RefTable(), sessionFor: () => guest, revoke: vi.fn() }+ const r = await driveBrowser({ call: cookiesCall(), ownerNodeId: OWNER, verified: true, resolve: okResolve }, deps)+ expect(r.ok).toBe(false)+ expect(reads).toEqual([]) // the jar was never read+ })+})++// ── PR 9: --screenshot is jailed to the project dir end-to-end ───────────────────────────────────+describe('--screenshot is jailed to the project dir through the gate (Task 9.1)', () => {+ function shotCall(p: string): BrowserCall {+ const c = parseBrowserArgs({ node: NODE, screenshot: p })+ if ('error' in c) throw new Error(c.error)+ return c+ }+ const screenshotIO = () => ({+ realpath: async (p: string) => p, // identity: no symlinks in this unit+ lstat: async () => ({ isSymbolicLink: () => false }),+ writeFile: vi.fn(async () => {})+ })++ it('a path inside the project writes and replies with the show-image line', async () => {+ const ledger = freshLedgerOwning()+ const { guest, dbg } = makeGuest()+ const origSend = dbg.sendCommand.bind(dbg)+ dbg.sendCommand = async (m: string, p?: object) =>+ m === 'Page.captureScreenshot' ? { data: Buffer.from('PNG').toString('base64') } : origSend(m, p)+ const io = screenshotIO()+ const deps: DriveDeps = { ledger, refs: new RefTable(), sessionFor: () => guest, revoke: vi.fn(), screenshotIO: io }+ const r = await driveBrowser(+ { call: shotCall('shot.png'), ownerNodeId: OWNER, verified: true, resolve: { ...okResolve, projectCwd: '/proj' } },+ deps+ )+ expect(r.ok).toBe(true)+ expect(r.message).toContain('/proj/shot.png')+ expect(r.message).toContain('show-image /proj/shot.png')+ expect(io.writeFile).toHaveBeenCalled()+ })++ it('a traversal path is refused and never writes', async () => {+ const ledger = freshLedgerOwning()+ const { guest } = makeGuest()+ const io = screenshotIO()+ const deps: DriveDeps = { ledger, refs: new RefTable(), sessionFor: () => guest, revoke: vi.fn(), screenshotIO: io }+ const r = await driveBrowser(+ { call: shotCall('../../etc/x.png'), ownerNodeId: OWNER, verified: true, resolve: { ...okResolve, projectCwd: '/proj' } },+ deps+ )+ expect(r).toEqual({ ok: false, message: 'browser: --screenshot path must be inside the project directory' })+ expect(io.writeFile).not.toHaveBeenCalled()+ })+})+describe('driveBrowser end-to-end refusals', () => {it('a discarded guest (sessionFor → null) is the named discard refusal', async () => {const ledger = freshLedgerOwning()diff --git a/src/main/browser-drive.ts b/src/main/browser-drive.tsindex 3412051a0..bbccf4fff 100644--- a/src/main/browser-drive.ts+++ b/src/main/browser-drive.ts@@ -43,8 +43,12 @@ import {type Driver,type CdpEventBus} from './browser-actions'+import { browserScreenshot, type ScreenshotDeps } from './browser-screenshot'+import { browserCookies } from './browser-cookies'import type { RefTable } from './browser-refs'import type { BrowserCall } from '../core/browser-verb'+import type { BoardLogEntry } from '../shared/types'+import { randomUUID } from 'node:crypto'/** The design's verbatim capability-off sentence. The last clause STOPS an agent burning a turn* trying to enable it. Exported so the wiring and the tests share the one string. */@@ -63,7 +67,18 @@ export const noDrivableNodeMessage = (id: string): string => `no drivable browse* source, whether the source is control-capable, and the LIVE per-project capability value. Main* makes the security DECISION from this; the renderer never runs a CDP command. */export type BrowserResolve =- | { ok: true; projectId: string; projectCwd?: string; sourceControlCapable: boolean; capabilityOn: boolean }+ | {+ ok: true+ projectId: string+ projectCwd?: string+ sourceControlCapable: boolean+ capabilityOn: boolean+ /** The owner agent node's title and the browser node's title — what the renderer alone knows,+ * used ONLY to make the cookie-read trace human-readable (`from` / `title`). Never a security+ * input; the gate decides from projectId/capability/ownership. */+ sourceTitle?: string+ browserTitle?: string+ }| { ok: false; refusal: string }/** The resolve round-trip's own short ceiling. Kept far under main's 120s pending-control budget and@@ -157,15 +172,53 @@ export interface DriveDeps {sessionFor(browserNodeId: string): LiveGuest | null/** Detach + drop ownership + tombstone — invoked when a live capability read comes back OFF. */revoke(browserNodeId: string): void+ /** Append one line to a project's board log, in-process (no IPC round-trip) — the cookie-read+ * trace (PR 9). Returns false when there is no reachable log or the write failed; the cookie read+ * is refused in that case (fail-closed). Absent ⇒ tracing is unavailable and `--cookies` refuses. */+ appendBoardLog?(projectId: string, entry: BoardLogEntry): Promise<boolean>+ /** The filesystem the screenshot path-jail + write use (PR 9). Absent ⇒ `--screenshot` refuses. */+ screenshotIO?: ScreenshotDeps+}++/** What only the resolve knows, threaded to the two PR-9 actions: the project the trace/screenshot+ * belong to, its cwd (the screenshot jail root), and the titles the cookie trace reads. */+interface RunContext {+ browserNodeId: string+ ownerNodeId: string+ projectId: string+ projectCwd?: string+ sourceTitle?: string+ browserTitle?: string+}++/** Build the cookie-read trace entry: it files under the OWNER agent node's card (`nodeId`), names+ * the owner in `from`, the domain in `to`, and the browser node in `title`. */+function cookieTraceEntry(ctx: RunContext, domain: string): BoardLogEntry {+ const from = ctx.sourceTitle || ctx.ownerNodeId+ return {+ id: randomUUID(),+ ts: Date.now(),+ author: { name: from, color: '#c2703d' },+ nodeId: ctx.ownerNodeId,+ kind: 'event',+ event: {+ type: 'agent-read-cookies',+ from,+ to: domain,+ title: ctx.browserTitle || ctx.browserNodeId+ }+ }}async function runAction(call: BrowserCall,guest: LiveGuest,refs: RefTable,- nodeId: string+ ctx: RunContext,+ deps: DriveDeps): Promise<ActionResult> {const a = call.action+ const nodeId = ctx.browserNodeId// The pointer verbs need the viewport-refreshing capability; the session is a Driver at runtime.const driver = guest.session as Driverswitch (a.kind) {@@ -186,10 +239,18 @@ async function runAction(return browserScroll(driver, nodeId, a.where)case 'wait':return browserWait(guest.session, refs, nodeId, a.target, call.timeoutMs)- default:- // cookies/screenshot (PR 9) parse today but do not drive yet: a NAMED, non-retryable refusal,- // never a silent success.- return { ok: false, message: `browser: --${a.kind} is not available yet (it lands in a later update)` }+ case 'screenshot':+ if (!deps.screenshotIO) return { ok: false, message: 'browser: screenshots are unavailable in this build' }+ return browserScreenshot(driver, nodeId, ctx.projectCwd, a.path, { full: call.full }, deps.screenshotIO)+ case 'cookies':+ // The trace goes through the board log; if there is no appender wired, the read cannot be+ // recorded, so it must not happen (fail-closed, same as an append that returns false).+ return browserCookies(guest.session, nodeId, a.domain, {+ recordTrace: (domain) =>+ deps.appendBoardLog+ ? deps.appendBoardLog(ctx.projectId, cookieTraceEntry(ctx, domain))+ : Promise.resolve(false)+ })}}@@ -217,8 +278,16 @@ export async function driveBrowser(}// guestPresent was true, so `guest` is non-null; the check keeps the type honest.if (!guest) return { ok: false, message: browserDiscardedMessage(input.call.node) }+ const ctx: RunContext = {+ browserNodeId: input.call.node,+ ownerNodeId: input.ownerNodeId,+ projectId: gate.entry.projectId,+ projectCwd: input.resolve.ok ? input.resolve.projectCwd : undefined,+ sourceTitle: input.resolve.ok ? input.resolve.sourceTitle : undefined,+ browserTitle: input.resolve.ok ? input.resolve.browserTitle : undefined+ }try {- return await runAction(input.call, guest, deps.refs, input.call.node)+ return await runAction(input.call, guest, deps.refs, ctx, deps)} catch (e) {return { ok: false, message: e instanceof Error ? e.message : 'browser: the command failed' }}diff --git a/src/main/index.ts b/src/main/index.tsindex 512844493..7f4aba1f7 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -1,7 +1,7 @@import { join, resolve, posix } from 'path'import { startSessionNameSweep, displayNodeTitle } from '../core/session-name-sweep'import { readAgentSessionName, type AgentSessionNameDeps } from '../core/agent-session-name'-import { readFile } from 'fs/promises'+import { readFile, realpath as fsRealpath, lstat as fsLstat, writeFile as fsWriteFile } from 'fs/promises'import { existsSync, statSync } from 'fs'import { homedir, hostname } from 'os'import { randomUUID } from 'crypto'@@ -1149,7 +1149,7 @@ app.whenReady().then(async () => {return { kind: 'unsupported' }}}- registerBoardLogHandlers(corePlatform, boardLogRouter)+ const boardLog = registerBoardLogHandlers(corePlatform, boardLogRouter)registerLogHandlers(corePlatform, logBuffer, () => settingsStore.get().debugLogPanel)// Agent messaging (the `send`/`reply` control verbs). Canvas.tsx forwards the validated verb@@ -2530,6 +2530,8 @@ app.whenReady().then(async () => {projectCwd?: stringsourceControlCapable?: booleancapabilityOn?: boolean+ sourceTitle?: string+ browserTitle?: string}) => {const resolve = pendingBrowserResolve.get(payload.requestId)@@ -2542,7 +2544,9 @@ app.whenReady().then(async () => {projectId: payload.projectId ?? '',projectCwd: payload.projectCwd,sourceControlCapable: payload.sourceControlCapable === true,- capabilityOn: payload.capabilityOn === true+ capabilityOn: payload.capabilityOn === true,+ sourceTitle: payload.sourceTitle,+ browserTitle: payload.browserTitle}: { ok: false, refusal: payload.refusal ?? 'source node is not on an open canvas' })@@ -2551,7 +2555,7 @@ app.whenReady().then(async () => {// Ask the renderer to resolve a source node — the `ask` closure `resolveBrowserTarget` races// against its own 2s timeout. The renderer NEVER runs a CDP command; it answers existence + project// + capability only.- const askRendererResolve = (sourceNodeId: string): Promise<BrowserResolve> => {+ const askRendererResolve = (sourceNodeId: string, browserNodeId: string): Promise<BrowserResolve> => {const w = getMainWindow()if (!w || w.isDestroyed()) {return Promise.resolve({ ok: false, refusal: 'source node is not on an open canvas' })@@ -2560,7 +2564,9 @@ app.whenReady().then(async () => {const answered = new Promise<BrowserResolve>((resolve) => {pendingBrowserResolve.set(requestId, resolve)})- w.webContents.send(IPC.browserControlResolve, { requestId, sourceNodeId })+ // `browserNodeId` rides along so the renderer can report the browser node's title for the cookie+ // trace; it is NOT part of the security decision (owner + capability + allowlist stay main-side).+ w.webContents.send(IPC.browserControlResolve, { requestId, sourceNodeId, browserNodeId })return answered.finally(() => pendingBrowserResolve.delete(requestId))}// The `browser` verb's whole main-side drive: parse (pure), identity belt, resolve round-trip, then@@ -2576,14 +2582,24 @@ app.whenReady().then(async () => {// Identity is checked first (the belt to hook-server's verified-only gate for STRICT verbs): a// non-verified caller learns nothing, and no resolve round-trip is even made.if (!verified) return { ok: false, error: STRICT_CONTROL_REFUSAL, message: STRICT_CONTROL_REFUSAL }- const resolve = await resolveBrowserTarget(parsed.node, () => askRendererResolve(nodeId))+ const resolve = await resolveBrowserTarget(parsed.node, () => askRendererResolve(nodeId, parsed.node))const result = await driveBrowser({ call: parsed, ownerNodeId: nodeId, verified, resolve },{ledger: browserLedger,refs: browserRefs,sessionFor: browserSessionFor,- revoke: (id) => pushBrowserLeases(revokeBrowserNode(id, browserRevocation, { userStopped: true }))+ revoke: (id) => pushBrowserLeases(revokeBrowserNode(id, browserRevocation, { userStopped: true })),+ // The cookie-read trace (PR 9): appended in-process, BEFORE the read, through the same board-log+ // routing the IPC handler uses. A false return (no reachable log / write failed) refuses the read.+ appendBoardLog: (projectId, entry) => boardLog.append(projectId, entry),+ // The screenshot jail + write (PR 9). realpath/lstat canonicalize the project-dir jail; writeFile+ // lands the PNG. All node:fs — never a caller path reaching CDP.+ screenshotIO: {+ realpath: (p) => fsRealpath(p),+ lstat: (p) => fsLstat(p),+ writeFile: (p, d) => fsWriteFile(p, d)+ }})return result.okdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex cd19af59d..1c477e0f5 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -6392,14 +6392,16 @@ export function Canvas() {// drive — and we NEVER run a CDP command. Main makes the security decision (owner + capability +// the CDP allowlist) and does the driving itself (browser-drive.ts / browser-actions.ts).useEffect(() => {- return api.onBrowserControlResolve(({ requestId, sourceNodeId }) => {+ return api.onBrowserControlResolve(({ requestId, sourceNodeId, browserNodeId }) => {const { projects, activeProjectId } = useProjects.getState()const route = routeControlSource(projects, activeProjectId, sourceNodeId)// Bring the owning project's canvas up so main can find the live guest (needsLiveCanvas is true// for `browser`). A closed/blocked/unknown owner just yields the refusal below.if (route.kind === 'switch' || route.kind === 'reopen') travelToProjectRef.current(route.projectId)const owner = projects.find((p) => p.nodes.some((n) => n.id === sourceNodeId))- const answer = answerBrowserResolve(owner as unknown as BrowserResolveProject | undefined, sourceNodeId)+ // `browserNodeId` is passed so the answer can carry the browser node's title for the cookie+ // trace; the security decision main makes never reads it.+ const answer = answerBrowserResolve(owner as unknown as BrowserResolveProject | undefined, sourceNodeId, browserNodeId)api.sendBrowserControlResolveResult({ requestId, ...answer })})// eslint-disable-next-line react-hooks/exhaustive-depsdiff --git a/src/renderer/lib/controlRouting.test.ts b/src/renderer/lib/controlRouting.test.tsindex a29cb5e22..a97fb7aa2 100644--- a/src/renderer/lib/controlRouting.test.ts+++ b/src/renderer/lib/controlRouting.test.ts@@ -147,10 +147,30 @@ describe('answerBrowserResolve — the renderer answers ONLY what it alone knowsprojectId: 'proj-1',projectCwd: '/home/u/p',sourceControlCapable: true,- capabilityOn: true+ capabilityOn: true,+ sourceTitle: '',+ browserTitle: ''})})+ it('reports the source and browser node titles for the cookie trace (PR 9)', () => {+ const granted = proj({+ agentBrowserControl: true,+ capabilityAck: { agentBrowserControl: 'kept' },+ nodes: [+ { id: 'claude-1', agentId: 'claude', title: 'Research agent' },+ { id: 'browser-3', title: 'GitHub' }+ ]+ })+ expect(answerBrowserResolve(granted, 'claude-1', 'browser-3')).toMatchObject({+ ok: true,+ sourceTitle: 'Research agent',+ browserTitle: 'GitHub'+ })+ // An unknown browser node is an empty string (main falls back to the id), never a throw.+ expect(answerBrowserResolve(granted, 'claude-1', 'browser-nope')).toMatchObject({ browserTitle: '' })+ })+it('a switch that is ON in the file but only PENDING (never kept) is not on — a pending notice is a refusal', () => {const pending = proj({ agentBrowserControl: true })expect(answerBrowserResolve(pending, 'claude-1')).toMatchObject({ ok: true, capabilityOn: false })diff --git a/src/renderer/lib/controlRouting.ts b/src/renderer/lib/controlRouting.tsindex e802ddaef..4745bcb6b 100644--- a/src/renderer/lib/controlRouting.ts+++ b/src/renderer/lib/controlRouting.ts@@ -138,6 +138,9 @@ export function sourceIsControlCapable(agentId: unknown): boolean {export interface BrowserResolveNode {id: stringagentId?: unknown+ /** The node's display title — reported so main can make the cookie-read trace human-readable+ * (PR 9). Never a security input. */+ title?: string}export interface BrowserResolveProject {id: string@@ -154,17 +157,23 @@ export type BrowserResolveAnswer =projectCwd?: stringsourceControlCapable: booleancapabilityOn: boolean+ /** The owner (source) agent node's title and the driven browser node's title — for the cookie+ * trace only. Empty string when unknown; main falls back to the node id. */+ sourceTitle: string+ browserTitle: string}export function answerBrowserResolve(project: BrowserResolveProject | undefined,- sourceNodeId: string+ sourceNodeId: string,+ browserNodeId?: string): BrowserResolveAnswer {// No open project owns the source, or the node is not on its canvas: a named, non-revoking// refusal. (Same class as every other verb's "source node is not on an open canvas".)if (!project) return { ok: false, refusal: 'source node is not on an open canvas' }const node = project.nodes.find((n) => n.id === sourceNodeId)if (!node) return { ok: false, refusal: 'source node is not on an open canvas' }+ const browserNode = browserNodeId ? project.nodes.find((n) => n.id === browserNodeId) : undefinedreturn {ok: true,projectId: project.id,@@ -173,7 +182,9 @@ export function answerBrowserResolve(// LIVE read — the drive-time capability check the whole feature's safety rests on. A project.json// hand-edit that flipped the switch off is reflected here the next time an agent drives, which is// exactly drive time.- capabilityOn: projectCapabilityGrantedFor(project, 'agentBrowserControl')+ capabilityOn: projectCapabilityGrantedFor(project, 'agentBrowserControl'),+ sourceTitle: typeof node.title === 'string' ? node.title : '',+ browserTitle: typeof browserNode?.title === 'string' ? browserNode.title : ''}}