Commit graph

44 commits

Author SHA1 Message Date
Luke Parker
90a267a750 docs(browser): the focus parameter names no implicit active tab 2026-11-18 14:24:53 +10:00
Luke Parker
964e73e849 fix(browser): the server agrees with the desktop on a file named .html, and reads a workspace address in any case
The server took a file named only .html for a page, which the desktop shows in the file panel, so tabs.open failed for want of a tab. A workspace address whose scheme or session ID was not in lower case named nothing, though the prefix it is compared with is written in lower case.
2026-11-18 14:24:21 +10:00
Luke Parker
bbdaf3d191 feat(browser): tabs.open and navigate take a workspace file in path, and browser.preview is removed
The server checks the path as it did for preview and sends the desktop the same preview action (navigate.path to move an existing tab). The permission check names the called operation and preview, so a deny of the old name still stops the path forms.
2026-11-18 10:27:12 +10:00
Luke Parker
6a53757a06 Merge remote-tracking branch 'origin/persisted-browser' into browser-pane-open 2026-11-17 11:06:21 +10:00
Luke Parker
551c5b4814 Merge branch 'browser-deep-snapshot' (ea08948131) into persisted-browser
Conflict in chromium.ts reload(): keep the held-restore retry from browser-ext-fix and drop the second navigation interrupt, as browser-deep-snapshot does: every reload now arrives through execute, which interrupts once, and a second interrupt would skip a hard reload of a held restore.
2026-11-17 10:58:12 +10:00
Luke Parker
7aa948ad0e test(browser): exercise plugin wake, activity marks and pane fit 2026-11-17 09:38:54 +10:00
Luke Parker
fd4afe780e fix(browser): hold hidden tabs awake through URL and delay waits 2026-11-17 09:35:18 +10:00
Luke Parker
8df4933923 fix(browser): reject conflicting scripts and describe file IDs 2026-11-17 09:29:27 +10:00
Luke Parker
27777efd13 fix(browser): stop granting the browser skill on attach
Confirmation review, the gap I reported. If the browser plugin was
removed (plugins: ["-opencode.browser"]) after a crash left a grant,
the grant's skill "browser" allow outranked a person's deny or ask on
their own skill named browser. Nothing sweeps a grant once the plugin
is gone.

The skill rule was not needed. The experimental.rules hook already
hides the built-in skill while the session holds no browser grant or
its agent is denied the browser. Allowed agents get the skill from
their own rules: the default agent rules allow "*".

Now:
- An attachment writes only browser "*" allow (BrowserMachine.GRANT).
- isGrant still matches the old skill allow. A revoke, the
  reconcile on attach and the startup sweep therefore remove grants
  written by earlier versions. The configured rules the hooks read
  still leave that allow out.
- The hook checks for the browser grant itself (holdsGrant), so a
  leftover skill allow does not count as attached.
- With no skill rule in any grant, the evaluate hook's skill branch
  and the hook's "configured skill deny" check are removed. Core's
  own rules decide every skill. A configured skill deny or ask is
  final again.

Tests:
- grant fixtures drop the skill rule. The startup-sweep test uses the
  old two-rule grant and still revokes it.
- A machine test: an old grant is revoked in full and replaced with
  the new one.
- The truth table and skill tests pass unchanged: with no skill rule
  in the grant, the built-in skill is listed and loads for an allowed
  agent with a desktop, and is hidden otherwise.
- New: with the plugin removed, a person's deny on their own browser
  skill holds against a grant left behind. An old-version grant there
  still outranks it, and the test pins that as the remaining case.
2026-11-17 09:06:57 +10:00
Luke Parker
3cbfdd88d4 feat(browser): accept recorded tool aliases and response-only bodies 2026-11-17 08:29:47 +10:00
Luke Parker
11bf34af21 fix(browser): keep a linked workspace's own path when preview finds its file
locate returned the file's real path. In a workspace reached through a link, as macOS's tmpdir under /private is, that path lies outside the workspace's spelling: preview asked again for it, and the tool sent the desktop a ../../private path. It now names the physical file under the workspace as the session spells it and asks only when a link inside the workspace points elsewhere in it.
2026-11-16 18:49:45 +10:00
Luke Parker
8d3b292ea2 fix(browser): authorize exact preview paths before lookup 2026-11-16 18:16:18 +10:00
Luke Parker
8b842aae0f fix(browser): remove private capture exports with their session 2026-11-16 15:15:46 +10:00
Luke Parker
5f165f9ac7 fix(browser): match URL waits without regex backtracking 2026-11-16 15:15:45 +10:00
Luke Parker
6a0adf289f fix(browser): authorize server file reads and capture exports 2026-11-16 14:53:41 +10:00
Luke Parker
5892aab6b4 fix(browser): retry failed previews on reattach and distinguish outdated servers 2026-11-16 14:33:04 +10:00
Luke Parker
9e4db6980f fix(browser): apply filename restrictions on the owning filesystem 2026-11-16 13:54:56 +10:00
Luke Parker
1d0e6a8599 fix(browser): point the agent to preview when it opens a workspace preview address 2026-11-16 12:57:40 +10:00
Luke Parker
d9f41d3167 feat(browser): stream workspace HTML in the session browser 2026-11-16 12:49:24 +10:00
Luke Parker
2830ba9b9e fix(browser): reject tool previews outside the real workspace 2026-11-13 18:30:08 +10:00
Luke Parker
9bb116eba0 fix(browser): report preview addresses consistently to browser tools 2026-11-13 16:59:35 +10:00
Luke Parker
0ccc95ce30 refactor(browser): share the extension-page check and loopback address rule between server and desktop
The server and the desktop each had their own extension-URL pattern, refusal message and localhost rule. They drifted: the server sent app.localhost:3000 to https while the address bar used http, and it missed blob: URLs of an extension. @opencode/plugin-browser/rpc now exports extensionOrigin, extensionPageRefusal and loopbackAddress, and both sides use them.
2026-11-13 13:16:38 +10:00
Luke Parker
30fb770d32 fix(browser): return awaited values, end waits on time, and act on failure codes
evaluate with a top-level await and no return, such as 'await fetch(x).then(r => r.status)', ran as an async function body and returned null; it now runs as the returned expression first. Element and URL waits checked their deadline only between probes, so a page in a long task held a 1 s wait for the 60 s request timeout and ended as [browser.timeout]; each probe is now cut at the deadline and cancelled on the desktop, and the wait returns met: false.

The server recognised a wait timeout, a changed document and a stale ref by matching the desktop's English messages. The desktop now sends codes for them (condition_unmet, document_changed, stale_ref) in the failure's existing code field, the server keeps the code on the Tool.Error, and the text matching is gone. An older desktop sends operation_failed, so an unmet wait then fails as it did before this branch.
2026-11-13 13:16:38 +10:00
Luke Parker
3c9459982e fix(browser): authorize a browser call before it reads tabs or files
A call that a tool.use policy blocks, or whose ask was not answered yet, could learn up to ten open tab IDs and URLs from the tab_unavailable message, and probe server paths through preview. Every tool now refuses configured denies, checks only its own input, requires an attached desktop ([browser.disconnected], which names no tab), runs the full permission check, and only then looks up the tab or the file. Without a desktop, preview names the path it was given without checking it.

An agent core cannot resolve, such as a disabled or removed one, now gets core's deny-all here too, so the attachment's grant no longer gives it the browser.

The wait plan carries what it waited for, the second tab lookup for wait is gone, and a pause reports waited: delay to match condition: delay.
2026-11-13 13:16:36 +10:00
Luke Parker
59145a728f fix(browser): read a backslash in a preview path as a separator on every server 2026-11-13 12:20:04 +10:00
Luke Parker
6da3b4f95a fix(browser): keep agent browser tools out of extension pages 2026-11-13 10:32:13 +10:00
Luke Parker
a7a65bd01e Merge branch 'browser-deny' (fbd7c7ed93) into persisted-browser 2026-11-13 08:40:05 +10:00
Luke Parker
91f4cf5dc6 Merge branch 'browser-tool-fixes' (01c3b90bd2) into persisted-browser 2026-11-13 08:39:19 +10:00
Luke Parker
fbd7c7ed93 fix(browser): honour per-operation browser denies and configured asks over the grant
The deny check only refused a call when the last rule for `browser` denied every
operation. A deny on one operation (for example `browser` on `tabs.open` or
`files.*`) and a configured `ask` still went through: the permission check
evaluates the session's `browser:* allow` grant after them, so the grant won and
answered silently.

The plugin now registers a `permission.evaluate` hook for the `browser` action.
It picks the rule for the call's operation from the agent's configured rules
and the session's rules without the grant, the way core's Permission.evaluate
picks it (last match on action and resource patterns). A deny refuses the call
with `[browser.denied]`, naming the operation when the deny is for one
operation. An ask makes the permission check prompt as it would without the
grant. No matching rule leaves the call allowed by the grant with no prompt.
Later hooks such as tool.use policies still apply. The matcher copies core's
Wildcard.match; a core test checks both pick the same rule.

Tool listing is unchanged.
2026-11-13 08:38:56 +10:00
Luke Parker
01c3b90bd2 fix(browser): pause when wait gets only a timeout, and say what it waited for
wait({ tabID, timeout }) with no condition key was a load wait, which returns at once on a loaded page; the 21 such calls in the data were attempted pauses. A lone timeout or timeoutMs now pauses for that long, capped at 30 s; wait({ tabID }) still waits for load. Results carry waited (load, text, textGone, element, elementGone, url or pause). The description also states that time up to 60 counts as seconds.
2026-11-13 08:37:37 +10:00
Luke Parker
7cb3ee8324 docs(browser): teach the browser tools as they now work
The skill and tool descriptions now show evaluate with return and await, wait with its implied conditions, met: false and delayMs, preview as the way to show a local HTML file, and what to do on disconnected and tab_unavailable errors. Optional parameters such as tabs.open focus, frameID and limit had descriptions the model never saw: optional() does not carry annotations to the encoded JSON Schema, so they now sit on the inner schema.
2026-11-13 08:32:05 +10:00
Luke Parker
3b3761500a fix(browser): fail preview for a missing file and name the file when no desktop is connected
preview acknowledged dispatch before the pane opened anything, so a path that existed nowhere returned success (#61625). The server now resolves the path the way the Review pane does (workspace-relative or absolute, file:// URLs, :line and #L suffixes, and the one workspace file whose path ends with it) and fails with the resolved path when no file is there or it is a folder. Without a desktop app, preview now says the file was not shown and gives its absolute path for the model to pass to the user, instead of the generic disconnected advice (28 of the 38 disconnected errors on this machine were previews).
2026-11-13 08:32:04 +10:00
Luke Parker
3912f39561 fix(browser): name the bad value and the next step in browser errors
- A session with no desktop no longer says 'Repeating browser actions while disconnected will not help' (#55795): it says the browser runs in the desktop app, to tell the user, and to continue without it until they open the session there.

- A closed or foreign tabID lists the session's open tabs (at most ten), so the next call can use one.

- A local path or file: URL passed to tabs.open or navigate is named and answered with browser.preview({ path }) or serving it over HTTP; other invalid URLs are named too.

- The reconnect advice no longer asks the model to reconnect the desktop, which it cannot do.
2026-11-13 08:32:02 +10:00
Luke Parker
2070e0a68a fix(browser): infer the wait condition and report a timeout as met: false
browser.wait without condition was 2,138 of 3,099 browser errors across four devices. Models write Playwright-style keys: text with timeout, state, selector, url, time, ms. wait now reads the condition from whichever key is present (none means load), accepts timeout for timeoutMs, shortens waits above 30 s instead of rejecting them, pauses for delayMs, time or ms, and polls for a selector, ref or URL from the server with actions every desktop already supports. A condition that does not hold in time returns met: false with what the page showed instead of throwing. Waits also no longer fail when the document changed since the server last saw the tab.
2026-11-13 08:23:17 +10:00
Luke Parker
5a066a4635 fix(browser): accept expression and code for evaluate and run top-level return and await
Models passed expression (and code) where evaluate required script; every such call failed. Scripts with a top-level return or await failed with a SyntaxError in the page. The server now folds expression and code into script, and sends a script that does not compile as a classic script but does as an async function body as (async () => { ... })(). Scripts that compile today reach the page unchanged.
2026-11-13 08:19:05 +10:00
Luke Parker
d476f4c9d0 fix(browser): reject unknown tool parameters and name the valid ones
A key the schema did not declare was dropped silently: input repair deletes undeclared keys of a closed object, and Effect structs ignore excess keys. A call such as evaluate({ tabID, expression }) then failed with 'script: Missing key' and no hint that expression was the problem. Every browser tool now fails with 'Not a parameter of browser.X. Valid parameters: ...'.
2026-11-13 08:17:45 +10:00
Luke Parker
34490b7c7d fix(browser): let a configured browser deny win over the desktop's attach grant
Attaching a desktop browser writes browser:* and skill:browser allows into the
session's permissions. Session rules are evaluated after agent rules, so the
grant overrode a browser deny from config, an agent definition (for example a
"*" deny) or the session itself. Browser tools never called the permission
check either, so tool.use policies did not apply.

The plugin now records each agent's rules before it appends its own default
deny. A browser call is refused when those rules, plus the session's rules
without the grant, deny the browser, decided the way core's tool filter decides.
The call then runs the permission check with the operation as its resource, so
permission.evaluate hooks such as tool.use policies apply. Sessions without a
deny behave as before: the grant allows the check, so nothing prompts.

Refs #54044, #53294, #56869
2026-11-13 08:16:25 +10:00
Luke Parker
8b29d45ec1
fix(browser): drive tunnel, proxy and network hop lifecycles through state machines (#61996) 2026-11-05 01:00:23 -06:00
Luke Parker
dd39237ddf
fix(plugin-browser): drive browser attachments through one state machine (#61985) 2026-11-05 00:56:59 -06:00
Aiden Cline
69269e4ebe
feat(core): support in-memory skill:// URIs (#60921) 2026-11-01 01:07:13 -05:00
Kit Langton
1aae67e853
chore: upgrade Effect to rc.118 (#50231) 2026-10-09 01:36:06 -07:00
Luke Parker
01efd22b2a
feat(desktop): comment on page elements from the in-app browser (#52217) 2026-09-30 16:52:42 +10:00
Luke Parker
60ed84ecd1
feat(app): open agent-referenced files as rich artifact tabs (#49882) 2026-09-21 15:20:15 +10:00
Luke Parker
3ebc4b01b9
feat(browser): add a public-API browser plugin (#46531) 2026-09-07 17:16:01 +10:00