Skip to content

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.

feat(browser): Stop — in the chip, in the menu, in Settings, and on six automatic triggers

Claude Code24d22bda79f4
diff --git a/src/main/browser-control-ledger.ts b/src/main/browser-control-ledger.ts
index c82e5e887..ca0b91f51 100644
--- a/src/main/browser-control-ledger.ts
+++ b/src/main/browser-control-ledger.ts
@@ -26,6 +26,14 @@
* never needed on the Server Edition, where browser control cannot exist.
*/
+/**
+ * The refusal a drive gets after the USER stopped control of a node (PR 6 Task 6.4). Named after the
+ * human act, not a permissions verdict, so the agent REPORTS it ("the user stopped me") instead of
+ * retrying an outage. Consulted by the drive path in PR 7 via {@link BrowserControlLedger.wasStoppedByUser};
+ * the `browser-3:` prefix matches the numbered refusal family (`browser-1`/`browser-2` in the shim).
+ */
+export const BROWSER_USER_STOPPED = 'browser-3: the user stopped agent control of this node'
+
export interface AgentBrowserEntry {
/** The agent node that ran open-browser. Drives are admitted only for THIS owner. */
ownerNodeId: string
@@ -43,6 +51,15 @@ export interface AgentBrowserEntry {
export class BrowserControlLedger {
/** browserNodeId → its ownership entry, for browser nodes an agent opened THIS run. */
private readonly entries = new Map<string, AgentBrowserEntry>()
+ /**
+ * browserNodeId → the owner the USER stopped control for. A tombstone, not an entry: it outlives
+ * the deleted ownership so a subsequent drive from that same owner answers {@link BROWSER_USER_STOPPED}
+ * instead of the generic not-owned null (which reads as "retryable"). Set ONLY by {@link stopByUser}
+ * (chip/menu/Settings/switch-off — the human acts), never by lifecycle revocation (node/project
+ * close, owner gone, quit), and cleared by a fresh {@link claim} so re-opening a node is a clean
+ * slate. In-memory like the ledger itself — a restart forgets it, which is correct.
+ */
+ private readonly userStopped = new Map<string, string>()
/**
* Record ownership of a freshly opened browser node. Returns false — and changes NOTHING — if the
@@ -56,6 +73,10 @@ export class BrowserControlLedger {
if (!browserNodeId || !e.ownerNodeId || !e.projectId) return false
if (this.entries.has(browserNodeId)) return false
this.entries.set(browserNodeId, { ...e })
+ // A fresh, verified open is a clean slate: a node the user stopped earlier and then genuinely
+ // re-opened is drivable again. (Ids are not reused within a run, so in practice this clears a
+ // stale tombstone rather than masking a live refusal.)
+ this.userStopped.delete(browserNodeId)
return true
}
@@ -105,6 +126,65 @@ export class BrowserControlLedger {
return live
}
+ /** The same live set, shaped for the renderer push (adds `leaseActiveUntil` so the chip can apply
+ * its linger). Separate from {@link activeLeases} so that method's asserted shape is untouched. */
+ activeLeasesForPush(now: number): {
+ browserNodeId: string
+ ownerNodeId: string
+ leaseActiveUntil: number
+ }[] {
+ const live: { browserNodeId: string; ownerNodeId: string; leaseActiveUntil: number }[] = []
+ for (const [browserNodeId, e] of this.entries) {
+ if (e.leaseActiveUntil > now) {
+ live.push({ browserNodeId, ownerNodeId: e.ownerNodeId, leaseActiveUntil: e.leaseActiveUntil })
+ }
+ }
+ return live
+ }
+
+ /**
+ * The USER stopped control of this node (chip/menu/Settings/switch-off). Records the tombstone
+ * against its current owner FIRST, then drops the entry — so a later drive from that owner is
+ * refused with the named human act, not the generic null. A no-op tombstone-wise if the node was
+ * already unclaimed (nothing to name an owner). Lifecycle revocation uses {@link release}, which
+ * leaves no tombstone.
+ */
+ stopByUser(browserNodeId: string): void {
+ const entry = this.entries.get(browserNodeId)
+ if (entry) this.userStopped.set(browserNodeId, entry.ownerNodeId)
+ this.entries.delete(browserNodeId)
+ }
+
+ /** Did the user stop control of this node for THIS exact owner? The drive path (PR 7) asks this to
+ * choose {@link BROWSER_USER_STOPPED} over a retry. Owner-scoped so it can never leak node
+ * existence to a different agent than the one that was driving. */
+ wasStoppedByUser(browserNodeId: string, ownerNodeId: string): boolean {
+ return this.userStopped.get(browserNodeId) === ownerNodeId
+ }
+
+ /** Every browser node this owner opened (claimed, live-lease or not) — the set to revoke when the
+ * owner node closes or restarts. */
+ idsByOwner(ownerNodeId: string): string[] {
+ return this.idsWhere((e) => e.ownerNodeId === ownerNodeId)
+ }
+
+ /** Every browser node opened under this project — the set to revoke when the project's switch goes
+ * off (a project close revokes per-node via the guest teardown instead). */
+ idsByProject(projectId: string): string[] {
+ return this.idsWhere((e) => e.projectId === projectId)
+ }
+
+ /** Every claimed browser node — the set to revoke on app quit. */
+ allIds(): string[] {
+ return [...this.entries.keys()]
+ }
+
+ private idsWhere(pred: (e: AgentBrowserEntry) => boolean): string[] {
+ const ids: string[] = []
+ for (const [browserNodeId, e] of this.entries) if (pred(e)) ids.push(browserNodeId)
+ return ids
+ }
+
private releaseWhere(pred: (e: AgentBrowserEntry) => boolean): string[] {
const released: string[] = []
for (const [browserNodeId, e] of this.entries) {
diff --git a/src/main/browser-revocation.test.ts b/src/main/browser-revocation.test.ts
new file mode 100644
index 000000000..213abded9
--- /dev/null
+++ b/src/main/browser-revocation.test.ts
@@ -0,0 +1,196 @@
+import { describe, it, expect } from 'vitest'
+import {
+ revokeBrowserNode,
+ revokeBrowserByOwner,
+ revokeBrowserByProject,
+ revokeAllBrowser,
+ type RevocationTargets
+} from './browser-revocation'
+import { BrowserControlLedger, BROWSER_USER_STOPPED } from './browser-control-ledger'
+import { BrowserSession, BrowserLeaseManager, BROWSER_LEASE_DETACHED } from './browser-lease'
+import type { DebuggerLike } from './browser-cdp-send'
+import type { CdpContext } from './browser-cdp-allowlist'
+
+// A debugger that records attach/detach and can hold a command in flight — the same shape
+// browser-lease.test.ts drives, because a revocation is only proven if it hits a REAL
+// BrowserSession's real detach/reject, not a stub.
+class FakeDebugger implements DebuggerLike {
+ attached = false
+ detachCalls = 0
+ hangNext = false
+ private detachListener: ((e: unknown, reason: string) => void) | null = null
+ isAttached(): boolean {
+ return this.attached
+ }
+ attach(): void {
+ this.attached = true
+ }
+ detach(): void {
+ this.detachCalls++
+ this.attached = false
+ }
+ sendCommand(_m: string, _p?: object): Promise<unknown> {
+ if (this.hangNext) {
+ this.hangNext = false
+ return new Promise<never>(() => {}) // never settles — an in-flight verb
+ }
+ return Promise.resolve({ ok: true })
+ }
+ on(event: 'detach' | 'message', listener: (...a: never[]) => void): void {
+ if (event === 'detach') this.detachListener = listener as (e: unknown, reason: string) => void
+ }
+}
+
+const VIEWPORT: CdpContext = { viewport: { width: 1280, height: 800 } }
+
+/** A ledger + lease manager wired to one DRIVEN node: entry claimed, a live BrowserSession attached,
+ * and a command left in flight so the rejection is observable. */
+function drivenNode(opts: {
+ browserNodeId: string
+ ownerNodeId: string
+ projectId: string
+}): { targets: RevocationTargets; dbg: FakeDebugger; inFlight: Promise<unknown>; ledger: BrowserControlLedger } {
+ const ledger = new BrowserControlLedger()
+ ledger.claim(opts.browserNodeId, {
+ ownerNodeId: opts.ownerNodeId,
+ projectId: opts.projectId,
+ partition: `persist:nt-agent-browser-${opts.projectId}`,
+ navGeneration: 0,
+ leaseActiveUntil: 0,
+ openedAt: 1_000
+ })
+ const leases = new BrowserLeaseManager()
+ const dbg = new FakeDebugger()
+ const session = new BrowserSession({
+ nodeId: opts.browserNodeId,
+ debugger: dbg,
+ viewport: () => VIEWPORT,
+ now: () => 1_000_000
+ })
+ leases.set(opts.browserNodeId, session)
+ // Drive it: attaches, and leaves a command hanging so revocation must reject it.
+ dbg.hangNext = true
+ const inFlight = session.send('Page.navigate', { url: 'https://x.test/' })
+ ledger.touchLease(opts.browserNodeId, 1_000_000 + 60_000)
+ expect(session.isAttached()).toBe(true)
+ return { targets: { leases, ledger }, dbg, inFlight, ledger }
+}
+
+const NODE = { browserNodeId: 'browser-3', ownerNodeId: 'claude-2', projectId: 'p-1' }
+
+describe('Stop actually revokes — every surface drops the entry, detaches, and cancels in flight', () => {
+ it('1. Stop in the chip / context menu: entry gone, debugger detached, in-flight rejected', async () => {
+ const { targets, dbg, inFlight, ledger } = drivenNode(NODE)
+
+ revokeBrowserNode(NODE.browserNodeId, targets, { userStopped: true })
+
+ // The lease is provably GONE, not merely hidden:
+ expect(dbg.detachCalls).toBe(1) // the debugger let go of the page
+ await expect(inFlight).rejects.toThrow(BROWSER_LEASE_DETACHED) // the pending verb was cancelled
+ expect(ledger.get(NODE.browserNodeId, NODE.ownerNodeId)).toBe(null) // ownership dropped
+ })
+
+ it('and every subsequent call from that owner answers the human-act refusal, not a retry', () => {
+ const { targets, ledger, inFlight } = drivenNode(NODE)
+ inFlight.catch(() => {}) // this test asserts the refusal, not the (also-cancelled) in-flight verb
+ revokeBrowserNode(NODE.browserNodeId, targets, { userStopped: true })
+
+ expect(ledger.wasStoppedByUser(NODE.browserNodeId, NODE.ownerNodeId)).toBe(true)
+ expect(BROWSER_USER_STOPPED).toBe('browser-3: the user stopped agent control of this node')
+ // Owner-scoped: a DIFFERENT agent gets no signal that the node ever existed.
+ expect(ledger.wasStoppedByUser(NODE.browserNodeId, 'claude-9')).toBe(false)
+ })
+
+ it('2. closing the node (lifecycle): detaches + drops, but leaves NO human-act tombstone', async () => {
+ const { targets, dbg, inFlight, ledger } = drivenNode(NODE)
+
+ revokeBrowserNode(NODE.browserNodeId, targets, { userStopped: false })
+
+ expect(dbg.detachCalls).toBe(1)
+ await expect(inFlight).rejects.toThrow(BROWSER_LEASE_DETACHED)
+ expect(ledger.get(NODE.browserNodeId, NODE.ownerNodeId)).toBe(null)
+ // Closing a node is not "the user stopped control" — no browser-3 tombstone.
+ expect(ledger.wasStoppedByUser(NODE.browserNodeId, NODE.ownerNodeId)).toBe(false)
+ })
+
+ it('4. the project switch off: revoke-by-project detaches, drops, and IS a human act (tombstone)', async () => {
+ const { targets, dbg, inFlight, ledger } = drivenNode(NODE)
+
+ revokeBrowserByProject(NODE.projectId, targets)
+
+ expect(dbg.detachCalls).toBe(1)
+ await expect(inFlight).rejects.toThrow(BROWSER_LEASE_DETACHED)
+ expect(ledger.get(NODE.browserNodeId, NODE.ownerNodeId)).toBe(null)
+ expect(ledger.wasStoppedByUser(NODE.browserNodeId, NODE.ownerNodeId)).toBe(true)
+ })
+
+ it('5. the owner node closing/restarting: revoke-by-owner detaches + drops (lifecycle, no tombstone)', async () => {
+ const { targets, dbg, inFlight, ledger } = drivenNode(NODE)
+
+ revokeBrowserByOwner(NODE.ownerNodeId, targets)
+
+ expect(dbg.detachCalls).toBe(1)
+ await expect(inFlight).rejects.toThrow(BROWSER_LEASE_DETACHED)
+ expect(ledger.get(NODE.browserNodeId, NODE.ownerNodeId)).toBe(null)
+ expect(ledger.wasStoppedByUser(NODE.browserNodeId, NODE.ownerNodeId)).toBe(false)
+ })
+
+ it('6. app quit: revoke-all detaches + drops every claimed node', async () => {
+ const { targets, dbg, inFlight, ledger } = drivenNode(NODE)
+
+ revokeAllBrowser(targets, { userStopped: false })
+
+ expect(dbg.detachCalls).toBe(1)
+ await expect(inFlight).rejects.toThrow(BROWSER_LEASE_DETACHED)
+ expect(ledger.get(NODE.browserNodeId, NODE.ownerNodeId)).toBe(null)
+ })
+
+ it('the Settings kill row Stop-all detaches EVERY driven node and tombstones each', async () => {
+ // Two owners, two projects, both driven — Stop-all is the one obvious place.
+ const a = drivenNode({ browserNodeId: 'browser-1', ownerNodeId: 'claude-1', projectId: 'p-1' })
+ // Reuse a's ledger + leases so allIds() spans both.
+ const ledger = a.ledger
+ const leases = a.targets.leases
+ ledger.claim('browser-2', {
+ ownerNodeId: 'codex-4',
+ projectId: 'p-2',
+ partition: 'persist:nt-agent-browser-p-2',
+ navGeneration: 0,
+ leaseActiveUntil: 0,
+ openedAt: 1_000
+ })
+ const dbg2 = new FakeDebugger()
+ const s2 = new BrowserSession({ nodeId: 'browser-2', debugger: dbg2, viewport: () => VIEWPORT, now: () => 1_000_000 })
+ ;(leases as BrowserLeaseManager).set('browser-2', s2)
+ dbg2.hangNext = true
+ const inFlight2 = s2.send('Page.navigate', { url: 'https://y.test/' })
+
+ const stopped = revokeAllBrowser({ leases, ledger }, { userStopped: true })
+
+ expect(new Set(stopped)).toEqual(new Set(['browser-1', 'browser-2']))
+ expect(a.dbg.detachCalls).toBe(1)
+ expect(dbg2.detachCalls).toBe(1)
+ await expect(a.inFlight).rejects.toThrow(BROWSER_LEASE_DETACHED)
+ await expect(inFlight2).rejects.toThrow(BROWSER_LEASE_DETACHED)
+ expect(ledger.allIds()).toEqual([])
+ expect(ledger.wasStoppedByUser('browser-1', 'claude-1')).toBe(true)
+ expect(ledger.wasStoppedByUser('browser-2', 'codex-4')).toBe(true)
+ })
+
+ it('a fresh verified claim clears a prior user-stop tombstone (a genuine re-open is drivable)', () => {
+ const { targets, ledger, inFlight } = drivenNode(NODE)
+ inFlight.catch(() => {}) // the cancelled verb is proven elsewhere; here we test re-claim
+ revokeBrowserNode(NODE.browserNodeId, targets, { userStopped: true })
+ expect(ledger.wasStoppedByUser(NODE.browserNodeId, NODE.ownerNodeId)).toBe(true)
+
+ ledger.claim(NODE.browserNodeId, {
+ ownerNodeId: NODE.ownerNodeId,
+ projectId: NODE.projectId,
+ partition: 'persist:nt-agent-browser-p-1',
+ navGeneration: 0,
+ leaseActiveUntil: 0,
+ openedAt: 2_000
+ })
+ expect(ledger.wasStoppedByUser(NODE.browserNodeId, NODE.ownerNodeId)).toBe(false)
+ })
+})
diff --git a/src/main/browser-revocation.ts b/src/main/browser-revocation.ts
new file mode 100644
index 000000000..7a0f49af5
--- /dev/null
+++ b/src/main/browser-revocation.ts
@@ -0,0 +1,77 @@
+/**
+ * Revoking browser control — the security-relevant half of the indicator (S8 PR 6 of #112, @Corvin).
+ *
+ * A Stop that only hides the chip is a Critical-class bug: the debugger would stay attached and the
+ * page still drivable. So every revocation here does BOTH, in one place, whatever triggered it:
+ * 1. drop the ownership entry (undrivable — the ledger's `get` now returns null), and
+ * 2. release the lease, which DETACHES the debugger and rejects any in-flight verb with a named
+ * outcome (`BrowserSession.release` → `detach()` + `BROWSER_LEASE_DETACHED`).
+ *
+ * A USER-initiated stop (chip, node menu, Settings kill row, the project switch going off) also
+ * leaves a tombstone, so the next drive from that owner is refused with {@link BROWSER_USER_STOPPED}
+ * — a message naming the human act, so the agent reports it rather than retrying. LIFECYCLE
+ * revocation (node close, project close, owner gone, app quit) leaves no tombstone: nothing there is
+ * "the user stopped control of this node".
+ *
+ * Ownership is read ONLY from the injected ledger — never from `Project` edges (that identifier is
+ * forbidden in every `src/main/browser-*.ts`, pinned by browser-ownership-source.test.ts). This file
+ * knows nothing of project.json.
+ *
+ * `src/main`, never Server Edition: it releases a `webContents.debugger`, which cannot exist there.
+ */
+import type { BrowserControlLedger } from './browser-control-ledger'
+
+/** The two runtime holders a revocation touches, injected so the whole thing unit-tests against a
+ * real {@link BrowserControlLedger} and a real `BrowserLeaseManager` (or fakes) with no Electron. */
+export interface RevocationTargets {
+ /** The lease manager. `release(nodeId)` detaches the debugger + rejects in-flight (a no-op for a
+ * node with no live session — true today, before PR 7 attaches any). */
+ leases: { release(nodeId: string): void }
+ /** The ownership + tombstone ledger. */
+ ledger: BrowserControlLedger
+}
+
+/** Revoke a set of browser nodes. `userStopped` chooses the tombstone (human act) vs a plain drop
+ * (lifecycle). Returns the ids acted on, so the caller can push them to the renderer as `stopped`
+ * (drop the chip at once, skipping the linger). */
+export function revokeBrowserNodes(
+ browserNodeIds: readonly string[],
+ t: RevocationTargets,
+ opts: { userStopped: boolean }
+): string[] {
+ for (const id of browserNodeIds) {
+ // Ledger first so the node is undrivable the instant the debugger lets go; the tombstone must be
+ // recorded BEFORE the entry is dropped, which `stopByUser` does internally.
+ if (opts.userStopped) t.ledger.stopByUser(id)
+ else t.ledger.release(id)
+ t.leases.release(id)
+ }
+ return [...browserNodeIds]
+}
+
+/** One node — the chip's Stop and the node context menu (userStopped), or a single node closing
+ * (lifecycle). */
+export function revokeBrowserNode(
+ browserNodeId: string,
+ t: RevocationTargets,
+ opts: { userStopped: boolean }
+): string[] {
+ return revokeBrowserNodes([browserNodeId], t, opts)
+}
+
+/** Every node an owner opened — the owner agent node closing or restarting (lifecycle). */
+export function revokeBrowserByOwner(ownerNodeId: string, t: RevocationTargets): string[] {
+ return revokeBrowserNodes(t.ledger.idsByOwner(ownerNodeId), t, { userStopped: false })
+}
+
+/** Every node in a project — the project switch going OFF (userStopped: a human act, refused with
+ * the named message afterwards). A project CLOSE is handled per-node by the guest teardown instead,
+ * and is not a "stop", so it does not come through here. */
+export function revokeBrowserByProject(projectId: string, t: RevocationTargets): string[] {
+ return revokeBrowserNodes(t.ledger.idsByProject(projectId), t, { userStopped: true })
+}
+
+/** Every claimed node — the Settings kill row's Stop-all (userStopped). */
+export function revokeAllBrowser(t: RevocationTargets, opts: { userStopped: boolean }): string[] {
+ return revokeBrowserNodes(t.ledger.allIds(), t, opts)
+}
diff --git a/src/main/index.ts b/src/main/index.ts
index 1025c3a86..1ea058c15 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -17,6 +17,13 @@ import { writeFilesToClipboard } from './clipboard-files'
import { allowGuestNavigation } from './webview-nav'
import { BrowserControlLedger } from './browser-control-ledger'
import { BrowserLeaseManager } from './browser-lease'
+import {
+ revokeBrowserNode,
+ revokeBrowserByOwner,
+ revokeBrowserByProject,
+ revokeAllBrowser,
+ type RevocationTargets
+} from './browser-revocation'
import { registerFsHandlers } from '../core/fs-handlers'
import { LogBuffer } from '../core/log-buffer'
import { installLogSink, splitTag } from '../core/log-sink'
@@ -817,7 +824,12 @@ app.whenReady().then(async () => {
}
)
ipcMain.on(IPC.browserUnregister, (_e, webContentsId: number) => {
+ // The browser node's guest is going away (node closed, project closed/switched, or a discard).
+ // Revoke any control lease on it — LIFECYCLE, so no user-stop tombstone. Read the node id BEFORE
+ // dropping the guest. A no-op for a node that was never driven.
+ const nodeId = browserNodeIdForGuest(webContentsId)
browserGuests.delete(webContentsId)
+ if (nodeId) pushBrowserLeases(revokeBrowserNode(nodeId, browserRevocation, { userStopped: false }))
})
// The naming agent runs LOCALLY on captured output, so it needs a cwd that exists on THIS
@@ -2327,12 +2339,59 @@ app.whenReady().then(async () => {
// Who owns which agent-opened browser node, THIS app run only. In-memory, never persisted, never
// read from project.json (Task 4.3/4.4). Consumed by PR 5 (attach/lease), PR 6 (indicator/Stop).
const browserLedger = new BrowserControlLedger()
- // Holds the debugger lease per driven browser node. Built and unit-tested in PR 5 but INERT here:
- // no `browser` verb exists until PR 7, so nothing attaches a guest to it yet. PR 7 wires each
- // guest's `webContents.debugger` into a BrowserSession, starts the idle sweep, and releases on
- // owner/project/app teardown. Owned here so that wiring has one home. See browser-lease.ts.
+ // Holds the debugger lease per driven browser node. Built and unit-tested in PR 5. PR 7 wires each
+ // guest's `webContents.debugger` into a BrowserSession and starts the idle sweep; a driving verb
+ // there will call `browserLedger.touchLease(...)` + `pushBrowserLeases()` so the chip lights up.
+ // No verb attaches a guest yet, so nothing sets a live lease today — but revocation (Stop + the
+ // automatic triggers) is fully live, because `release` is a no-op-safe detach for a node with no
+ // session. Owned here so all the wiring has one home. See browser-lease.ts / browser-revocation.ts.
const browserLeases = new BrowserLeaseManager()
- void browserLeases
+ const browserRevocation: RevocationTargets = { leases: browserLeases, ledger: browserLedger }
+ // Push the current driven-lease set to the renderer (chip / rope / kill row). `stopped` ids drop
+ // from the chip immediately, skipping the anti-flicker linger — that is how an explicit Stop hides
+ // at once while a merely-idle lease fades.
+ const pushBrowserLeases = (stopped: string[] = []): void => {
+ const w = getMainWindow()
+ if (!w || w.isDestroyed()) return
+ w.webContents.send(IPC.browserLeaseChanged, {
+ active: browserLedger.activeLeasesForPush(Date.now()),
+ stopped
+ })
+ }
+ // Reverse the guest map: which node id owns this <webview> guest? Used to revoke on a browser
+ // node's teardown (its guest unregisters). Absent guest → no id → nothing to revoke.
+ const browserNodeIdForGuest = (webContentsId: number): string | undefined =>
+ browserGuests.get(webContentsId)?.nodeId
+ // Stop agent control of ONE node — the chip button and the node context menu. USER-initiated, so
+ // it leaves the tombstone: a later drive from that owner is refused by the named human act.
+ ipcMain.on(IPC.browserStop, (_e, nodeId: string) => {
+ pushBrowserLeases(revokeBrowserNode(nodeId, browserRevocation, { userStopped: true }))
+ })
+ // Stop-all — the Settings kill row. Also user-initiated.
+ ipcMain.on(IPC.browserStopAll, () => {
+ pushBrowserLeases(revokeAllBrowser(browserRevocation, { userStopped: true }))
+ })
+ // A project's browser-control switch went OFF (read live in the renderer, never cached at lease
+ // start). User-initiated: a human turned it off.
+ ipcMain.on(IPC.browserStopProject, (_e, projectId: string) => {
+ pushBrowserLeases(revokeBrowserByProject(projectId, browserRevocation))
+ })
+ // The OWNER agent node closed or restarted (pty teardown/recycle) → its browser leases die with
+ // its verified identity. A SECOND listener on these channels alongside releaseNodeTails above;
+ // both fire. LIFECYCLE, so no user-stop tombstone. A restart mints a fresh identity that cannot
+ // drive the old node anyway, so revoking is the honest state.
+ corePlatform.on(IPC.ptyDestroy, (nodeId: string) =>
+ pushBrowserLeases(revokeBrowserByOwner(nodeId, browserRevocation))
+ )
+ corePlatform.on(IPC.ptyRecycle, (nodeId: string) =>
+ pushBrowserLeases(revokeBrowserByOwner(nodeId, browserRevocation))
+ )
+ // App quit: detach every debugger lease. A second `before-quit` listener alongside the module-
+ // level flush one (both fire); scoped here so it can reach `browserRevocation`. No push — the
+ // window is going away. LIFECYCLE, so no tombstone (the in-memory ledger is gone on quit anyway).
+ app.on('before-quit', () => {
+ revokeAllBrowser(browserRevocation, { userStopped: false })
+ })
ipcMain.on(
IPC.agentControlResult,
(
@@ -2380,6 +2439,9 @@ app.whenReady().then(async () => {
leaseActiveUntil: 0,
openedAt: Date.now()
})
+ // A claim carries no live lease (a verb sets that in PR 7), so this does not light the chip;
+ // it keeps the renderer's view consistent from the moment ownership exists.
+ pushBrowserLeases()
}
}
return result
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index a49239ce0..8045f411b 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -5339,8 +5339,22 @@ export function Canvas() {
// Destructive/recovery rows (Delete, Restart agent, Branch/Transfer) are not hideable at all:
// `isHidden` only answers for ids in its own inventory.
const hidden = useSettings.getState().settings.hiddenNodeMenuItems
+ // Stop agent control — the node context-menu surface for Stop (Task 6.4). Shown only for a
+ // single browser node that is actually being driven; it revokes for real (main detaches the
+ // debugger + drops the ledger entry), not just hides the chip. Read fresh, like every other row.
+ const drivenHere =
+ ids.length === 1 && drivingNodeIds(useBrowserLease.getState().entries, Date.now()).has(ids[0])
return tidySeparators([
{ type: 'label', label: ids.length > 1 ? `${ids.length} nodes` : '1 node' },
+ ...(drivenHere
+ ? ([
+ {
+ label: 'Stop agent control',
+ onClick: () => window.nodeTerminal.browser.stop(ids[0])
+ },
+ { type: 'separator' }
+ ] as MenuItem[])
+ : []),
...((): MenuItem[] => {
// "Group …" wraps objects that share ONE container — existing frames are valid members
// now that frames nest. A box-selection that caught a frame AND its children is
diff --git a/src/renderer/components/settings/sections/AgentsSection.tsx b/src/renderer/components/settings/sections/AgentsSection.tsx
index 5767d1b37..8baab9995 100644
--- a/src/renderer/components/settings/sections/AgentsSection.tsx
+++ b/src/renderer/components/settings/sections/AgentsSection.tsx
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { useSettings } from '../../../state/settings'
import { useProjects } from '../../../state/projects'
+import { useBrowserLease, drivingNodeIds } from '../../../state/browserLease'
import {
PROJECT_CAPABILITIES,
PROJECT_CAPABILITY_COPY,
@@ -106,6 +107,21 @@ const ROWS = {
'refused'
]
},
+ browserControl: {
+ title: 'Browser control',
+ keywords: [
+ 'browser',
+ 'control',
+ 'drive',
+ 'driving',
+ 'stop',
+ 'revoke',
+ 'agent',
+ 'web',
+ 'page',
+ 'security'
+ ]
+ },
hibernation: {
title: 'Hibernate idle agents',
keywords: [
@@ -203,6 +219,25 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El
const activeProjectId = useProjects((s) => s.activeProjectId)
const activeProject = useProjects((s) => s.projects.find((p) => p.id === activeProjectId))
const setProjectCapability = useProjects((s) => s.setProjectCapability)
+ // The kill row (Task 6.4): browser nodes an agent is driving RIGHT NOW, across every open project,
+ // each with a Stop and one Stop-all. The precedent is the identity escape hatch — a user who
+ // notices their browser doing something needs one obvious place to end it, not a per-node hunt.
+ // Stop revokes for real in main (detach + drop), and there is deliberately NO global "disable
+ // browser control" toggle here: one concept, one switch (the per-project capability below).
+ const browserLeaseEntries = useBrowserLease((s) => s.entries)
+ const allProjects = useProjects((s) => s.projects)
+ const nodeTitleById = (id: string): string => {
+ for (const p of allProjects) {
+ const n = p.nodes.find((node) => node.id === id)
+ if (n) return n.title || id
+ }
+ return id
+ }
+ const drivenRows = [...drivingNodeIds(browserLeaseEntries, Date.now())].map((nodeId) => ({
+ nodeId,
+ nodeTitle: nodeTitleById(nodeId),
+ ownerTitle: nodeTitleById(browserLeaseEntries[nodeId].ownerNodeId)
+ }))
const rows: { id: AgentId; label: string; isBuiltin: boolean }[] = [
...BUILTIN_AGENT_IDS.map((id) => ({ id, label: AGENT_CONFIG[id].label, isBuiltin: true })),
...settings.customAgents.map((c) => ({ id: c.id, label: c.label || c.id, isBuiltin: false }))
@@ -376,6 +411,37 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El
}
/>
</SearchableRow>
+ <SearchableRow {...ROWS.browserControl}>
+ <FieldRow
+ label="Browser control"
+ description="Browser nodes an agent is driving right now, across every open project. Stop ends it immediately — the debugger is detached and the agent is told you stopped it, so it reports that instead of retrying. One place to stop it, so you never have to hunt from node to node."
+ control={
+ <Button
+ variant="default"
+ disabled={drivenRows.length === 0}
+ onClick={() => window.nodeTerminal.browser.stopAll()}
+ >
+ Stop all
+ </Button>
+ }
+ />
+ <div className="space-y-2">
+ {drivenRows.length === 0 ? (
+ <span className="text-[13px] text-muted">No agent is driving a browser node right now.</span>
+ ) : (
+ drivenRows.map((r) => (
+ <div key={r.nodeId} className="flex items-center gap-3 py-1">
+ <span className="flex-1 text-[13px] text-text">
+ {r.ownerTitle} is driving {r.nodeTitle}
+ </span>
+ <Button variant="default" onClick={() => window.nodeTerminal.browser.stop(r.nodeId)}>
+ Stop
+ </Button>
+ </div>
+ ))
+ )}
+ </div>
+ </SearchableRow>
{CAPABILITY_ROWS.map(({ cap, title, keywords }) => (
<SearchableRow key={cap} title={title} keywords={keywords}>
<FieldRow
@@ -402,6 +468,12 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El
// value any other way (a string, a stored false) is the bug the validators
// exist to refuse.
if (activeProject) setProjectCapability(activeProject.id, cap, on)
+ // Turning browser control OFF revokes any live lease in this project immediately
+ // (Task 6.4) — detach now, don't wait for the next drive to read the switch. Read
+ // live off this toggle, never cached at lease start.
+ if (activeProject && cap === 'agentBrowserControl' && !on) {
+ window.nodeTerminal?.browser?.stopProject?.(activeProject.id)
+ }
}}
/>
}