Skip to content

feat(desktop): keep an agentenv computer up and drive it through REA's MCP tools - #9041

Merged
morluto merged 4 commits into
morluto:mainfrom
earakely-scale:feat/desktop-build-computer
Nov 6, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
earakely-scale:feat/desktop-build-computer

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #9037, which is stacked on #8994 (containing #8988) and #8992. This branch contains them. Review only cdf3174be, 497d23a63, and 9d05a2b15 and 30d55a3f5, which fix the review findings. Once they merge, the diff shrinks to these. It is about 1,670 source lines, 1,100 of tests and 300 of docs, kept as one PR on purpose.

Summary

This lets Claude Code drive an agentenv computer through REA's own MCP tools. It is the second of four PRs for "a bundle from a request", where the requester's Claude builds a computer-app environment by using the app inside a computer. Claude Code can't attach a new MCP server mid-session, so REA forwards the computer's actions itself.

Problem and expected behavior

There was no way for an agent connected to REA to act on a computer. After this change:

  • start_build_computer brings up a computer, either from a request (an archive package, an apt repository or a .deb, with REA installed inside for building) or from an existing bundle folder. It returns the first screenshot.
  • act_on_build_computer forwards screenshot, click, drag, scroll, type, key and wait to the computer's own computer_* tools and returns their images unchanged.
  • close_build_computer tears it down.

Change and scope

  • Helper: bridge/agentenv/computer.py.
    • It keeps one computer up with agentenv's run_bundle(keep=True) and prints one JSON line: base URL, MCP URL, control token and sandbox id.
    • It tears down when stdin closes, or on SIGTERM or SIGINT.
    • REA finds its interpreter from REA_AGENT_ENV_COMMAND.
  • Lifecycle: AgentEnvComputer.ts and AgentEnvComputerHelper.ts.
    • The helper runs as an owned process. REA waits for readiness on /agentenv/ext/computer-ready/status and holds one MCP session to the computer's /mcp.
    • The token is never returned or logged.
    • When agentenv can't confirm a teardown, REA removes the sandbox's containers by exact name and by label.
    • Recording uses the computer-recording routes under REA's request id. It is internal, for the witness in PR 3.
  • Session owner: DesktopBuildComputers.ts keeps an action log per computer and closes every computer when the server closes.
  • Build bundle: appBuild.ts reuses the export's install planning and Python rendering.
    • The app opens on demand from the computer's Applications menu.
    • REA's build-only layer is Node 24.22.1 (pinned by sha256 per architecture) plus a REA archive. That archive is a local file (REA_BUILD_COMPUTER_REA_ARCHIVE) or a download, unpacked by a root RunScript into /opt/rea.
  • Actions: computerActions.ts translates ctrl+s into W3C key names and checks each action's arguments. ToolResultDelivery.toForwardedToolResult passes images through within the result budget.
  • Wiring: contracts, effects audit, the application family, a capability service, the MCP-only CLI-parity list and catalog entries.
  • Review fixes (9d05a2b15):
    • Start ownership: a start is owned from the helper's spawn. A failed start whose teardown is unconfirmed stays held under a computer_id that close can retry. closeAll refuses new starts and joins those in progress.
    • Oversized screenshots: an oversized first screenshot still returns the computer_id, and start_build_computer takes screenshot options.
    • Recordings: they are refused before reading when too large, then fetched one bounded segment at a time.
    • Helper output: the helper keeps the tail of its output (a new tail retention mode in ProviderProcessSupervisor).
    • Teardown race: a helper that reported no computer exits on its own before SIGTERM.
    • Bounded action log (30d55a3f5): a computer keeps its latest 256 actions within 256 KiB, each string cut to 1 KiB and each list to 64 items, with the total and the last applied index of each kind of action.
  • Docs: docs/desktop-build-computer.md and docs/specs/desktop-app-environments/build-computer/.

Contract and boundary impact

  • Semantic owner and earliest changed stage: new MCP-only session tools in the application family.
  • Contribution scope fit and linked maintainer decision: same approved desktop-environments work as feat(desktop): capture a Linux desktop application in use #8874.
  • CLI and MCP/tool-catalog contract: three new MCP tools, adding about 13 KB to the full catalog. No CLI change; they are on the MCP-only list.
  • Provider, bridge, target-format, or platform compatibility: a new Python bridge for agentenv-framework 0.9.1431's runner. Image results are new in REA's tool delivery.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details:
    • starts and removes local Docker containers through agentenv;
    • uses loopback network calls to the computer;
    • removes containers by name and label only for sandbox ids this REA process started.
  • Generated metadata: the MCP catalog.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Boundary tests: buildComputerMcp.test.ts (8 scenarios) and buildComputerRecording.test.ts run REA's real helper against a fake agent_env package and a fake driver, with no Docker or network. appBuild.test.ts and computerActions.test.ts cover the bundle and the actions.
  • Opt-in real test (buildComputerReal.test.ts, REA_BUILD_COMPUTER_REAL=1): passes on an Ubuntu 24.04 amd64 VM with agentenv-framework 0.9.1431, in 24–27 s with the image cached.
  • Real MCP run on that VM (rea mcp over stdio):
    • Start: a Mousepad request started in 22–31 s, and the first screenshot came back as a 1280×800 PNG.
    • Actions only: opened Mousepad from the menu, typed a line, pressed ctrl+s, chose Documents and saved. ~/Documents/build-note.txt holds the line.
    • Latency: clicks 6–18 ms, screenshots about 35 ms.
    • Inside the computer: rea --version answers from /opt/rea.
    • Close: about 475 ms, with nothing left by name or label.
    • Bundle-folder start: an exported Inkscape bundle started in 59 s cold, including its image build.
    • Lifecycle: a cancelled start, a server close and a SIGKILL of REA's server each left no computer behind. The control token appeared in no output or log.
  • Found and fixed in that run: agentenv's local provider names an ordinary computer agent-<sandbox id> without a label. So a label-only fallback reported a running computer as removed. The fallback now uses name and label, and a boundary test covers both.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • Passed with no new lint diagnostics in this PR's files: npm run typecheck, format:check, build:cached then knip, jscpd, docs:check, docs:build, verify:test-discovery, verify:architecture-guards, verify:module-boundaries and mcp-catalog:check.
  • Pre-existing lint: createServer.ts and toolEffects.ts already carry the same size warnings on main. lint fails only on main's tests/acceptance/webSourceLocationCli.test.ts.
  • Tests: desktop, server, contract, build-computer, catalog and CLI-coverage tests: 1,838 passed and 30 skipped on macOS with the review fixes, process supervision included. The review fixes have not yet been rerun on the VM. On the VM, the build-computer files with the real variables passed: 5 files, 19 tests.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: a real Ubuntu 24.04 amd64 agentenv computer.
  • Package or release metadata impact: bridge/agentenv/computer.py is added to the package's files.
  • Security, privacy, process, or containment review:
    • the control token stays inside REA's process and is redacted from the helper's stderr;
    • only containers of sandboxes this process started are removed.

Known gaps:

  • Nothing in the repo builds the REA archive yet. The VM run built it with npm pack plus a production install, as last night's spike did.
  • A cold first start (60–110 s) can outlast a 60 s MCP client timeout. Progress notifications would keep the call alive.
  • The app's working folder is /opt/agentenv/apps/<name>, so its Save As dialog opens on build-only files.
  • After a SIGKILL of REA, its private bundle folder in /tmp stays behind.

Author readiness

Human owner: @earakely-scale

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5 Tier: apex

[Medium impact] The PR adds a locally configured desktop-computer workflow to REA's MCP server.

Fix the request-build launch paths before merging; valid archive names and Electron apps can leave the computer without a working application.

Findings

  1. P1 Archive spaces break `rea` ▶
  2. P1 Electron apps cannot open ▶
Fix with agent prompt
### Issue 1
src/domain/desktop/appBuild.ts:159
`renderReaInstallScript` writes the archive's entrypoint path into the `rea` launcher without shell quoting. An otherwise valid archive with a top folder such as `REA Build` passes the file check, but the generated launcher makes Node open `/opt/rea/payload/REA` instead of `scripts/rea.mjs`. Copy the entrypoint to a fixed path, or shell-quote it when generating the launcher.

### Issue 2
src/domain/desktop/appBuild.ts:272
If an Electron app's desktop command does not include `--no-sandbox`, `renderBuildModule` launches it unchanged and the app exits. The existing export path adds that flag because the computer's container does not grant the user namespaces Chromium needs. The request path neither applies that adjustment nor offers a launch override, so installing the app can succeed while opening it from the Applications menu fails. Reuse the Electron launch policy when preparing the installed app's command.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds three MCP tools that start, drive and close a local agentenv computer.

  • REA can start an app computer and keep it for the session.
  • MCP callers can drive the desktop and receive its screenshots.
  • Failed helper runs can keep the last part of their output.

Diagram

sequenceDiagram
  participant A as MCP caller
  participant R as REA
  participant H as Python helper
  participant C as agentenv computer
  A->>R: start_build_computer
  R->>H: "run_bundle(keep=True)"
  H-->>R: Private URLs, token and sandbox id
  R->>C: Connect MCP and wait for readiness
  R->>C: computer_screenshot
  R-->>A: computer_id and image
  A->>R: act_on_build_computer
  R->>C: computer action
  C-->>R: Driver result
  R-->>A: Result and images
  A->>R: close_build_computer
  R->>H: Close stdin
  H->>C: Teardown
  alt Teardown is unconfirmed
    R->>C: Remove exact sandbox containers
  end
Loading

Reviews (8) · Last reviewed commit: "fix(desktop): bound a build computer's a..." · Reviewed by Greptile

Comment thread src/server/ToolResultDelivery.ts Resolved
Comment thread src/domain/desktop/seedScrub.ts Resolved
Comment thread src/desktop/AgentEnvComputer.ts Resolved
Comment thread src/desktop/AgentEnvComputerHelper.ts Resolved
Comment thread src/domain/desktop/seedScrub.ts Resolved
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 6, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	docs/desktop-build-computer.md
#	src/application/desktop/DesktopApplicationExport.ts
#	src/application/desktop/DesktopBuildComputers.ts
Comment thread src/domain/desktop/viewPointer.ts Resolved
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 6, 2026
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 6, 2026
@earakely-scale
earakely-scale marked this pull request as ready for review November 6, 2026 01:26
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-06T01:26:10.572322Z
We couldn’t complete this review. Comment @codex review to try again.
f01cc95 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

earakely-scale and others added 4 commits November 6, 2026 02:52
…s MCP tools

- A Python helper keeps one agentenv computer up per build with
  run_bundle(keep=True) and reports its address, MCP URL, control token
  and sandbox id; it tears the computer down when stdin closes.
- AgentEnvComputer owns the helper, waits for readiness, holds one MCP
  session to the computer's computer_* tools, records through the
  computer-recording routes, and removes the sandbox's containers by
  label when agentenv cannot confirm teardown. The token never leaves it.
- start_build_computer starts a computer from a request (archive package,
  apt repository or .deb, opened on demand with REA in /opt/rea) or from
  a bundle folder; act_on_build_computer forwards screenshot, click,
  drag, scroll, type, key and wait and returns the driver's images
  unchanged; close_build_computer tears it down.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nv cannot confirm teardown

agentenv's local provider runs an ordinary computer as agent-<sandbox id>
without the agentenv.sandbox label, so the label-only fallback found
nothing and reported a running computer as removed. The fallback now
lists containers by exact name and by label. The real test holds its
recording open long enough for a first frame, checks the container by
name, and runs rea inside the computer; the guide and tool descriptions
say the app opens from the Applications menu and that a screenshot after
opening a menu should come from a wait.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed screenshots, bound recordings

- A start is owned from the helper's spawn. One that fails and whose
  teardown is unconfirmed stays held under a computer_id close can retry;
  closeAll refuses new starts, cancels and joins starts in progress, then
  closes every held computer.
- When the first screenshot is too large, the error carries REA's result
  with the computer_id, and start_build_computer takes screenshot region,
  format and quality.
- Recordings are refused before reading when the manifest's total exceeds
  the allowance, then fetched one segment at a time, each read bounded and
  checked against its size and sha256.
- The helper keeps the tail of its output (a new tail retention mode in
  ProviderProcessSupervisor), so a build's own error is not crowded out.
- A helper that reported no computer exits on its own before SIGTERM, so
  no phantom owner is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every action kept its full arguments for the computer's whole life, so a long
session grew REA's memory without limit. The log now keeps the latest 256
actions within 256 KiB, cuts each string to 1 KiB and each list to 64 items
(naming what it cut), and keeps the total and the last applied index of each
kind of action, so rules over the whole session hold after entries drop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cursor
cursor Bot force-pushed the feat/desktop-build-computer branch from f01cc95 to d950792 Compare November 6, 2026 02:53
@morluto
morluto merged commit fc4c381 into morluto:main Nov 6, 2026
46 checks passed
exit 1
fi
ln -sf /opt/rea/node-v${BUILD_NODE_VERSION}-linux-*/bin/node /usr/local/bin/node
printf '#!/bin/sh\\nexec /usr/local/bin/node %s "$@"\\n' "$1" > /usr/local/bin/rea

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Archive spaces break rea

renderReaInstallScript writes the archive's entrypoint path into the rea launcher without shell quoting. An otherwise valid archive with a top folder such as REA Build passes the file check, but the generated launcher makes Node open /opt/rea/payload/REA instead of scripts/rea.mjs. Copy the entrypoint to a fixed path, or shell-quote it when generating the launcher.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/desktop/appBuild.ts
Line: 159

Comment:
**Archive spaces break `rea`**

`renderReaInstallScript` writes the archive's entrypoint path into the `rea` launcher without shell quoting. An otherwise valid archive with a top folder such as `REA Build` passes the file check, but the generated launcher makes Node open `/opt/rea/payload/REA` instead of `scripts/rea.mjs`. Copy the entrypoint to a fixed path, or shell-quote it when generating the launcher.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

packages=Packages(apt=${pyList(install.packages)}),${sources}
downloads=[${install.downloads.join(", ")}],
run=[${install.scripts.map((script) => `RunScript(script=${py(script)})`).join(", ")}],
launch=Launch(at="demand", command=${pyList(["gtk-launch", entry])}${window}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Electron apps cannot open

If an Electron app's desktop command does not include --no-sandbox, renderBuildModule launches it unchanged and the app exits. The existing export path adds that flag because the computer's container does not grant the user namespaces Chromium needs. The request path neither applies that adjustment nor offers a launch override, so installing the app can succeed while opening it from the Applications menu fails. Reuse the Electron launch policy when preparing the installed app's command.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/desktop/appBuild.ts
Line: 272

Comment:
**Electron apps cannot open**

If an Electron app's desktop command does not include `--no-sandbox`, `renderBuildModule` launches it unchanged and the app exits. The existing export path adds that flag because the computer's container does not grant the user namespaces Chromium needs. The request path neither applies that adjustment nor offers a launch override, so installing the app can succeed while opening it from the Applications menu fails. Reuse the Electron launch policy when preparing the installed app's command.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@morluto morluto added area: mcp MCP server, transport, and tool registration enhancement New feature or request labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants