Repository navigation
feat: host-side automation socket for programmatic VM control - #261
Merged
Merged
Conversation
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]>
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vm/vphone.sock) that accepts JSON commands from external processesProtocol
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.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":falseto skip it, or"delay":1500to wait longer for animations (default 500ms).Files changed
VPhoneHostControl.swift(new) — Unix domain socket server, command dispatch, compact screenshot captureVPhoneScreenRecorder.swift— addsaveScreenshot(view:to:)with PNG/JPEG format detectionVPhoneVirtualMachineView.swift— addinjectTap/injectSwipevia synthetic NSEventsVPhoneAppDelegate.swift— wire up VPhoneHostControl lifecycle (start on boot, stop on exit)Test plan
<button worksscreen:falseskips inline screenshot,delayadjusts capture timing🤖 Generated with Claude Code