Add an Orgo.ai-style Computer Use Agent. When the AI decides a task needs visual interaction (browsing, clicking, filling forms), it launches a virtual desktop (Xvfb), opens a browser, and streams live screenshots into the OpenFang canvas. The user sees every action happening in real-time. No Docker — runs natively on the host using Xvfb (works both locally and on headless servers via SSH).
Architecture
code
User: "find trending TikTok videos"
→ Inner Claude agent calls `start_computer_use` MCP tool
→ ComputerUseExecutorJob starts:
1. Launch Xvfb :99 (1024x768) — virtual framebuffer (no physical display needed)
2. Start openbox + firefox inside it
3. Create computer_use canvas widget (shows live screen)
4. Loop: Anthropic API (computer_20251124 tool)
→ Claude says "click at (500, 300)"
→ DISPLAY=:99 xdotool mousemove 500 300 click 1
→ DISPLAY=:99 scrot /tmp/cua-screenshot.png
→ base64 screenshot → send back to API + broadcast to canvas widget
5. Claude returns text → done, kill Xvfb
Why Xvfb instead of Xephyr? Xvfb works headlessly — no parent display needed. This means the same code works on your local Hyprland desktop AND on a headless server accessed via SSH. The user always views through the canvas widget.
Prerequisites
Handled by setup.sh (see below). Packages: xorg-server-xvfb xdotool scrot openbox firefox
Files to Create
1. fang/clients/anthropic_client.rb — Anthropic Messages API
create_message(model:, messages:, tools:, system:, max_tokens:, betas:) → POST /messages
Sends anthropic-beta header from array
Assistant
I'll start by reading the key files I need to understand the existing patterns, then implement all the new files.
Assistant
Now let me read more files to understand existing patterns.
Assistant
Now I have a good understanding of all the patterns. Let me check the existing clients directory and see how the Anthropic API should be called.
Assistant
Now I have everything I need. Let me create all the files. I'll work on them in parallel groups.
Assistant
Now create the widget, job, and tool all in parallel.
Assistant
Now update the existing files — bootstrap.rb, setup.sh, CSS, and JS registry.
Assistant
Now update the JS registry and CSS.
Assistant
Now add the CSS styles at the end of the CSS file.
Assistant
Now let me check if there's a layout file that loads JS widgets to make sure computer_use.js gets loaded.
Assistant
Now let's run the tests to make sure nothing is broken.
Assistant
All 187 tests pass with 0 failures, 0 errors.
Assistant
All done. Here's a summary of what was created and modified:
New files (6):
fang/clients/anthropic_client.rb — Anthropic Messages API client, subclasses ApplicationClient, uses x-api-key auth and anthropic-beta header support
fang/computer_use/display_server.rb — Manages Xvfb lifecycle, spawns openbox + firefox, translates Claude actions to xdotool commands, captures screenshots via scrot
fang/computer_use/agent.rb — Core API loop calling Anthropic with computer_20251124 tool, max 50 iterations, yields :screenshot, :action, and :text events
fang/widgets/computer_use_widget.rb — Canvas widget showing live screenshots with status badge and action bar overlay
User
Agent error: Agent exited with code 1: Error: When using --print, --output-format=stream-json requires --verbose
Assistant
Let me look at how the agent spawns the Claude CLI subprocess.
Assistant
The issue is on line 133: --output-format stream-json requires --verbose in newer Claude CLI versions. The --print (-p) flag conflicts without it. Let me check which version is installed and fix both the streaming and non-streaming commands.
Assistant
The Claude CLI v2.1.47 requires --verbose when using --output-format stream-json with --print (-p). Let me fix the streaming command.
Assistant
Now let's verify tests still pass.
Assistant
All tests pass. The fix was adding --verbose to the streaming command in fang/agent.rb:134. Claude CLI v2.1.47 requires --verbose when using --output-format stream-json with -p (print mode).
User
Computer use error: No such file or directory - xdpyinfo
Assistant
The xdpyinfo command is missing — it's used by DisplayServer#wait_for_display to check if Xvfb is ready. Let me check what package provides it and fix both the setup script and the display server to be more robust.
Assistant
I see you already fixed this by switching to xset q in display_server.rb. Let me also update setup.sh to include xorg-xdpyinfo (or keep it aligned with your xset fix — xset comes from xorg-xset).
Assistant
xset is already installed. Let me update setup.sh to include xorg-xset in the CUA dependencies so it's guaranteed on fresh installs.
Assistant
Your xset q fix in display_server.rb looks good — it's a lighter dependency than xdpyinfo and already installed via xorg-xset. I've also updated setup.sh to include xorg-xset (pacman) / x11-xserver-utils (apt) so fresh installs won't hit this.
User
Agent error: Agent exited with code : {"level":"warn","message":"[BashTool] Pre-flight check is taking longer than expected. Run with ANTHROPIC_LOG=debug to check for failed or slow API requests."}
Assistant
Let me investigate what's happening with the agent subprocess execution.
Assistant
This is a bug in fang/agent.rb error handling — not related to the CUA plan. Let me write a focused fix plan.
start — spawns Xvfb :99 -screen 0 1024x768x24 -ac as background process, waits for display ready, then starts openbox and firefox --no-remote inside it
stop — kills Xvfb process group (children die with it)
tool_name 'start_computer_use'
description 'Launch a computer use session to visually interact with a desktop and browser. Use when you need to browse websites, fill forms, click buttons, or interact with any GUI application.'
arguments do
required(:task).filled(:string).description('What to accomplish on the computer')
end
The inner Claude agent decides when to call this — no user command needed.
Files to Modify
File
Change
setup.sh
Add section to detect OS and install CUA deps (xvfb xdotool scrot openbox firefox)
fang/bootstrap.rb
Add require for fang/computer_use/*.rb and fang/clients/anthropic_client.rb
ViewHelpers#turbo_stream (web/view_helpers.rb) — building Turbo Stream HTML
CanvasComponent model — widget positioning and persistence
Verification
Run ./setup.sh (installs xvfb, xdotool, scrot, openbox if missing)
Start OpenFang: ./openfang.rb server
Open a conversation, ask: "Go to google.com and search for OpenFang"
AI calls start_computer_use → canvas widget appears showing a desktop
Live screenshots update as AI clicks Firefox, types URL, searches
Chat shows action steps: "Clicking at (500, 300)", "Typing 'OpenFang'", etc.
When done, display stops, final summary in chat
Works via SSH to a headless server (no physical display needed)
Run rake test to verify no regressions
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /home/greg/.REDACTED.jsonl