From 56a58e80a6c8d56e89ba50eccb7a1f5e8db6e4e2 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:02:33 +1000 Subject: [PATCH] fix(browser): do not attribute strip selection to page input --- packages/gui-plugins/src/browser/pane.ts | 6 ++---- packages/gui-plugins/src/browser/policy.ts | 5 +++++ .../gui-plugins/src/browser/refusal-notice.test.ts | 10 ++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/gui-plugins/src/browser/pane.ts b/packages/gui-plugins/src/browser/pane.ts index 6a6dfc16c41..54e108eed4d 100644 --- a/packages/gui-plugins/src/browser/pane.ts +++ b/packages/gui-plugins/src/browser/pane.ts @@ -11,7 +11,7 @@ import type { Embeds, Persisted, ServerEndpoints, Windows } from "@opencode/plug import { createBrowserPage, type BrowserPage, type Shared } from "./chromium" import { browserFailure, CodedError, missingArtifact } from "./errors" import { createBrowserNetwork, createDirectNetwork, type BrowserNetwork } from "./network" -import { agentDriven, agentRefusal, childActivity, destinationOrigin, normalizeURL, refusal, restoreRefusal, type TabActivity } from "./policy" +import { agentDriven, agentRefusal, childActivity, destinationOrigin, normalizeURL, recordTabFocus, refusal, restoreRefusal, type TabActivity } from "./policy" import type { Profile } from "./profile" import { createRefs } from "./refs" import type { FindAction, PaneEvent, PromptAnswer } from "./ipc" @@ -1021,9 +1021,7 @@ export function createBrowserPane(input: { const activities = handles.get(binding)?.activity const activity = activities?.get(action.tabID) ?? { agentRuns: 0 } - if (origin === "agent") activity.agentEndedAt = Date.now() - - if (origin === "user") activity.userInputAt = Date.now() + recordTabFocus(activity, origin) activities?.set(action.tabID, activity) if (origin === "user") dispatchBinding(binding, { type: "tab.focused", tabID: action.tabID, fromStrip: true }) diff --git a/packages/gui-plugins/src/browser/policy.ts b/packages/gui-plugins/src/browser/policy.ts index eb0e2b03da2..3dd9124dcbe 100644 --- a/packages/gui-plugins/src/browser/policy.ts +++ b/packages/gui-plugins/src/browser/policy.ts @@ -120,6 +120,11 @@ export const DOWNLOAD_GRACE_MS = 30_000 export type TabActivity = { agentRuns: number; agentEndedAt?: number; userInputAt?: number; agent?: string } +/** An agent focus is an agent operation. A strip selection (including auto-reveal) is not input to the page. */ +export function recordTabFocus(activity: TabActivity, origin: "agent" | "user") { + if (origin === "agent") activity.agentEndedAt = Date.now() +} + /** * Whether the agent drives a tab: the one rule for every "did the agent cause this". Without `now` it is sticky: true * from the tab's first agent command, or one inherited from its opener (`childActivity`), until the tab closes; site diff --git a/packages/gui-plugins/src/browser/refusal-notice.test.ts b/packages/gui-plugins/src/browser/refusal-notice.test.ts index 8f8e0bed877..2f4521b1f56 100644 --- a/packages/gui-plugins/src/browser/refusal-notice.test.ts +++ b/packages/gui-plugins/src/browser/refusal-notice.test.ts @@ -1,4 +1,5 @@ import { expect, test } from "bun:test" +import { activityOwner, downloadOwner, recordTabFocus, type TabActivity } from "./policy" import { externalTarget, navigationNotice, popupActivated } from "./refusal-notice" test("refusals describe the actual destination without displaying private, misleading or unbounded targets", () => { @@ -57,3 +58,12 @@ test("a popup needs Chromium's activation report for that same target", () => { expect(popupActivated({ url, userGesture: true }, `${url}other`)).toBe(false) expect(popupActivated(undefined, url)).toBe(false) }) + +test("selecting a revealed agent tab grants neither app-link activation nor a user download", () => { + const activity: TabActivity = { agentRuns: 0 } + recordTabFocus(activity, "agent") + recordTabFocus(activity, "user") + const event = { ...activity, agentRunning: false, now: Date.now() + 800 } + expect(navigationNotice("mailto:test@example.invalid", {}, activityOwner(event))).toMatchObject({ action: "copy" }) + expect(downloadOwner({ ...event, page: ["https://test.invalid"], chain: [] })).toBe("agent") +})