Skip to content

feat: host-side automation socket for programmatic VM control - #261

Merged
zqxwce merged 3 commits into
Lakr233:mainfrom
pluginslab:feat/host-control-automation
Apr 4, 2026
Merged

zqxwce merged 3 commits into
Lakr233:mainfrom
pluginslab:feat/host-control-automation

Conversation

@pluginslab

@pluginslab pluginslab commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a Unix domain socket server (vm/vphone.sock) that accepts JSON commands from external processes
  • Enables programmatic E2E testing of iOS apps running in the VM without GUI interaction
  • Supports: screenshot, tap, swipe, key (home/power/volume), type (clipboard set)
  • Every action returns a compact grayscale screenshot (~20-30KB base64 JPEG) inline in the response

Protocol

One-line JSON per connection — connect, send, receive, disconnect. Every response includes an "image" field with a base64-encoded grayscale JPEG of the screen after the action.

# Take screenshot (compact inline + optional full-res save)
echo '{"t":"screenshot"}' | nc -U vm/vphone.sock
# → {"ok":true,"image":"<base64 grayscale JPEG ~20KB>"}

echo '{"t":"screenshot","path":"/tmp/screen.png"}' | nc -U vm/vphone.sock
# → {"ok":true,"path":"/tmp/screen.png","image":"<base64>"}

# Tap — returns screenshot after action
echo '{"t":"tap","x":500,"y":1900}' | nc -U vm/vphone.sock
# → {"ok":true,"image":"<base64>"}

# Swipe gesture
echo '{"t":"swipe","x1":645,"y1":2790,"x2":645,"y2":1400,"ms":200}' | nc -U vm/vphone.sock

# Hardware keys
echo '{"t":"key","name":"home"}' | nc -U vm/vphone.sock

# Set guest clipboard (for paste workflows)
echo '{"t":"type","text":"Hello from automation"}' | nc -U vm/vphone.sock

# Skip inline screenshot or adjust delay
echo '{"t":"tap","x":500,"y":1900,"screen":false}' | nc -U vm/vphone.sock
echo '{"t":"tap","x":500,"y":1900,"delay":1500}' | nc -U vm/vphone.sock

Response format

{"ok": true, "image": "<base64 grayscale JPEG>"}
{"ok": true, "path": "/tmp/screen.png", "image": "<base64>"}
{"ok": false, "error": "no active VM view"}

The inline image is grayscale, 1/3 resolution (430x932), JPEG quality 0.35 — typically 20-30KB. Pass "screen":false to skip it, or "delay":1500 to wait longer for animations (default 500ms).

Files changed

  • VPhoneHostControl.swift (new) — Unix domain socket server, command dispatch, compact screenshot capture
  • VPhoneScreenRecorder.swift — add saveScreenshot(view:to:) with PNG/JPEG format detection
  • VPhoneVirtualMachineView.swift — add injectTap/injectSwipe via synthetic NSEvents
  • VPhoneAppDelegate.swift — wire up VPhoneHostControl lifecycle (start on boot, stop on exit)

Test plan

  • Screenshot command captures VM display and saves to specified path (PNG and JPEG)
  • Compact grayscale image returned inline with every action (~20-30KB)
  • Tap command opens apps from home screen (Settings, App Store confirmed)
  • Tap navigates within apps (Settings > General > About confirmed)
  • Key command sends home button to return to home screen
  • Type command sets guest clipboard for paste workflows
  • Back navigation via tap on < button works
  • Full E2E test: home → Settings → General → back → home → Notes → write note → home
  • screen:false skips inline screenshot, delay adjusts capture timing
  • Socket auto-cleans stale file on startup
  • Builds clean with Swift 6 strict concurrency (no new warnings)

🤖 Generated with Claude Code

pluginslab and others added 3 commits March 28, 2026 23:42
Add a Unix domain socket server (vm/vphone.sock) that accepts JSON
commands from external processes, enabling programmatic E2E testing
of iOS apps running in the VM.

Supported commands:
- screenshot: capture VM display to file (PNG/JPEG by extension)
- tap: inject touch at pixel coordinates (matching screenshot dims)
- swipe: inject swipe gesture between two points
- key: send hardware keys (home/power/volup/voldown) via HID

The socket uses a simple one-line JSON protocol: connect, send request,
receive response, disconnect.  Example usage from CLI:

  echo '{"t":"screenshot","path":"/tmp/s.png"}' | nc -U vm/vphone.sock
  echo '{"t":"tap","x":500,"y":1900}' | nc -U vm/vphone.sock
  echo '{"t":"key","name":"home"}' | nc -U vm/vphone.sock

New files:
- VPhoneHostControl.swift: socket server, command dispatch

Modified:
- VPhoneScreenRecorder: add saveScreenshot(view:to:) with PNG support
- VPhoneVirtualMachineView: add injectTap/injectSwipe via synthetic
  NSEvents routed through the existing mouse event handlers
- VPhoneAppDelegate: wire up VPhoneHostControl lifecycle

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sets the guest clipboard via the vsock control channel, enabling
text input from external automation. Callers can then tap Paste in
the iOS context menu to insert the text.

  echo '{"t":"type","text":"Hello"}' | nc -U vm/vphone.sock

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Every command response now includes an "image" field with a base64-
encoded grayscale JPEG of the current screen (~40-60KB vs multi-MB PNG).
This eliminates the need for a separate screenshot call after each action.

The image is:
- Downscaled to 1/3 resolution (430x932)
- Converted to grayscale for high contrast
- JPEG compressed at quality 0.35

Optional parameters on any command:
- "screen":false  → skip the screenshot capture
- "delay":800     → ms to wait before capture (default 500)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.

2 participants