fix(browser): do not attribute strip selection to page input

This commit is contained in:
Luke Parker 2026-11-17 09:02:33 +10:00
parent 498d7c0299
commit 56a58e80a6
3 changed files with 17 additions and 4 deletions

View file

@ -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 })

View file

@ -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

View file

@ -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")
})