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

A4: browser_execute tool + workspace wiring by Alezander9 · Pull Request #6 · browser-use/browsercode · GitHub

A4: browser_execute tool + workspace wiring - #6

Merged
Alezander9 merged 2 commits into
mainfrom
a4/browser-execute-tool
Apr 26, 2026
Merged

Alezander9 merged 2 commits into
mainfrom
a4/browser-execute-tool

Conversation

Copy link
Copy Markdown
Contributor

Summary

Implements browser_execute — the single tool for all browser interaction (decisions.md §3.2). Three-level shape with minimal upstream-opencode diff.

What's added

Level 1 — packages/bcode-browser/src/

  • browser-execute.ts (~85 lines) — Effect factory. Spawns uv run --project <HARNESS_DIR> python run.py -c <code> via Effect's ChildProcessSpawner. BU_NAME = ctx.sessionID for daemon isolation (parallel sub-agents get isolated browsers). ENOENT on uv → one-line install hint per decisions.md §4.4.
  • harness.ts (5 lines) — HARNESS_DIR resolved from import.meta.url. Phase-C TODO when binary packaging lands.

Level 2 — packages/opencode/src/tool/

  • browser-execute.ts (~25 lines) — Tool.define adapter. Passes parameters through, translates Tool.Context.sessionID for the Level-1 factory, Effect.orDie for opencode's never-error contract.
  • browser-execute.txt — tool description shown to the model.
  • registry.ts — 4-line additions (import + init + builtin entry).

Workspace wiring

  • packages/opencode/package.json — one line: "@browser-use/bcode-browser": "workspace:*".

Total upstream-opencode diff: 6 lines (tool import, init line, builtin entry, package.json dep). Everything else lives in our package.

Replaces ROADMAP A3

The original A3 plan was to bootstrap ~/.cache/bcode/venv/ on first bcode run with a manifest. Replaced 2026-04-26 (decisions.md §4.4 update): uv run --project <HARNESS_DIR> builds a per-package venv at packages/bcode-browser/harness/.venv/ (gitignored) on first call, caches every subsequent call.

  • Cold call: ~3s (uv resolves + builds venv)
  • Warm call: ~50ms

No bootstrap step, no manifest, no first-run code path. Single source of truth for Python deps: harness/pyproject.toml. "Is uv on PATH?" is the only check, lazily evaluated via spawn ENOENT.

Verification

Typecheck: bun run typecheck (filtered F4) — 5/5 packages pass in ~5s. Pre-push hook runs clean without --no-verify.

End-to-end smoke test (no Chrome required):

const proc = ChildProcess.make('uv',
  ['run', '--project', HARNESS_DIR, 'python', '-c', 'print(42)'],
  { cwd: HARNESS_DIR, extendEnv: true, stdin: 'ignore' })
const handle = yield* spawner.spawn(proc)
const [out, code] = yield* Effect.all([
  Stream.mkString(Stream.decodeText(handle.all)),
  handle.exitCode
])
// out: "42\n", code: 0

Verifies the spawn pipeline: TS → uv → cached venv → python → captured stdout/exit-code.

A Chrome-required integration test (actually invoking goto(...)) is deferred; that needs the cloud-browser or a headed local Chrome and is the right thing for E1 (evals) to drive.

Out of scope (next PRs)

  • A5 (permission gating — session-level allow per decisions.md §9 leaning).
  • Screenshot → attachment plumbing. Will need a helpers.py divergence to surface the screenshot path; design after permission gating lands.
  • helpers.py editing protection (path allowlist for daemon.py/admin.py). Decisions §3.7/§4.5 — needs a hook in opencode's permission rules.
  • Streaming stdout/stderr to TUI (deferred per discussion thread).

bcode added 2 commits April 26, 2026 00:54
Implements the single browser tool per decisions.md §3.2.

Level 1 (packages/bcode-browser/src/):
- browser-execute.ts (~85 lines) — Effect factory spawning
  uv run --project <HARNESS_DIR> python run.py -c <code>
  via ChildProcessSpawner. BU_NAME=sessionID isolates daemons
  per session (sub-agents → own browser). ENOENT on uv yields
  the one-line install hint per decisions.md §4.4.
- harness.ts (5 lines) — HARNESS_DIR resolved from import.meta.url.
  Phase-C TODO when binary packaging lands.

Level 2 (packages/opencode/src/tool/):
- browser-execute.ts (~25 lines) — Tool.define adapter, passes
  through schema, translates Tool.Context.sessionID, Effect.orDie
  for opencode's error contract.
- browser-execute.txt — description.
- registry.ts — 4 line additions (import + init + builtin entry).

Workspace wiring:
- packages/opencode/package.json — '@browser-use/bcode-browser':
  'workspace:*'.

Replaces ROADMAP A3 (cache-dir bootstrap + manifest). Per decisions
§4.4 update: 'uv run --project <HARNESS_DIR>' builds the venv at
harness/.venv/ on first call (cold ~3s, warm ~50ms). No bootstrap
step, no manifest. Single source of truth for deps:
harness/pyproject.toml.

End-to-end verified: Effect.runPromise → spawned uv → python
'print(42)' → output '42\n', exit 0.

Typecheck: 5/5 packages pass via filtered turbo command.
Previous version called Effect.fail on ENOENT, which the Level-2 wrapper's
Effect.orDie converted to an unrecoverable defect. The agent never saw the
hint in tool output, only the user via TUI/logs.

Now returns { output: UV_MISSING_HINT, exitCode: 127 } — agent reads the
install hint and can tell the user; user still sees it in TUI. POSIX 127
mirrors 'command not found'. Other spawn failures still rethrow.

Detection walks the cause chain on PlatformError to find ENOENT regardless
of nesting depth (effect's spawn wraps ErrnoException in SystemError).
Alezander9 merged commit 8a795f0 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