FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

A5+A7: permission gate + stream output to TUI for browser_execute by Alezander9 · Pull Request #7 · browser-use/browsercode · GitHub

A5+A7: permission gate + stream output to TUI for browser_execute - #7

Merged
Alezander9 merged 1 commit into
mainfrom
a5-a7/permission-and-streaming
Apr 26, 2026
Merged

Alezander9 merged 1 commit into
mainfrom
a5-a7/permission-and-streaming

Conversation

Copy link
Copy Markdown
Contributor

What

Two small additions to browser_execute:

A5 (light) — adds ctx.ask({ permission: "browser_execute", patterns: ["*"], always: ["*"], metadata: {} }) to the Level-2 wrapper. The default agent ruleset has "*": "allow" (agent.ts:88) so this auto-allows by default — no user-visible change. But it makes opencode.json's existing controls work:

{
  "tools": { "browser_execute": false }       // deny
  "permission": { "browser_execute": "ask" }  // prompt every call
}

A7 — streaming output to TUI. Adds an optional onChunk hook on Level-1 ExecuteContext invoked with the accumulated output on every stream chunk. Level 2 supplies a hook that calls ctx.metadata({ metadata: { output: preview(...) }}), mirroring bash.ts exactly (preview tail-truncates to 30k chars). The TUI's existing metadata subscription renders incremental output live.

Why this shape

  • Level 1 stays free of opencode types (Tool.Context, ctx.metadata). The hook is a generic Effect.Effect<void> callback, keeping the Level-1 surface portable.
  • onChunk receives full accumulated output, not deltas. Simpler for "set current output" semantics; matches how bash drives ctx.metadata.
  • Stream.runForEach instead of Stream.mkString. Same Effect.all([drain, exitCode], { concurrency: 2 }) shape.

Tests on the sprite

  • bun run typecheck (filtered turbo) — 5/5 pass.
  • Streaming smoke (Level-1 with onChunk): 4 chunks delivered during a run; final output and exitCode unchanged.
  • uv-missing path: 0 chunks (short-circuits before stream), exit 127, hint returned.
  • Happy path: full output captured, real exit code returned.

Roadmap

  • A5 (full session-level permission prompt) deferred — browser tools are on by default; users disable via opencode.json.
  • A6 (helpers.py allowlist) deferred — revisit when binary distribution lands and the file path question reopens.
  • This closes Phase A for now.

A5 (light): Level-2 wrapper now calls ctx.ask({permission: 'browser_execute'}).
The default agent ruleset has '"*": "allow"' so this auto-allows by default —
no user-visible change. But it makes opencode.json's existing controls work:
  "tools": { "browser_execute": false }     -> deny
  "permission": { "browser_execute": "ask" } -> prompt each call

A7: Level 1 grew an optional onChunk hook on ExecuteContext that's invoked
with the accumulated output on every stream chunk. Level 2 supplies a hook
that calls ctx.metadata({metadata: {output: preview(...)}}), matching the
exact pattern bash.ts uses (preview tail-truncates to 30k chars). The TUI's
existing metadata subscription renders incremental output as it streams.

Implementation notes:
- Level 1 stays free of opencode types (Tool.Context, ctx.metadata) — the
  hook is a generic Effect callback. Keeps the Level-1 surface portable.
- onChunk receives the full accumulated string, not just the delta. Simpler
  for consumers that just want "set current output" semantics; matches how
  bash drives ctx.metadata.
- Uses Stream.runForEach instead of Stream.mkString. Stream.all on
  [drain, exitCode] keeps the same concurrency model.

Verified on this sprite:
- typecheck 5/5 pass
- streaming: 4 chunks delivered to onChunk during a run; final output and
  exitCode unchanged
- uv-missing path still returns exit 127 with hint, 0 chunks (short-circuits
  before stream)
- happy path: full output captured, real exit code returned
Alezander9 merged commit a7c3d86 into main Apr 26, 2026
2 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL