serve-sim 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # serve-sim
2
+
3
+ The `npx serve` of Apple Simulators.
4
+
5
+ Host your simulator for use with Agent tools like Codex, Cursor, or Claude Desktop — locally, over your LAN, or host on a remote mac and tunnel anywhere.
6
+
7
+ ```sh
8
+ npx serve-sim
9
+ # → Preview at http://localhost:3200
10
+ ```
11
+
12
+ https://github.com/user-attachments/assets/fbf890f4-c8c7-4684-82be-d677b8a188f8
13
+
14
+ `serve-sim` spawns a small Swift helper that captures the simulator's framebuffer via `simctl io`, exposes it as an MJPEG stream + WebSocket control channel, and serves a React preview UI on top. It works with any booted iOS Simulator — no Xcode plugin, no instrumentation in your app.
15
+
16
+ ## Features
17
+
18
+ - Full 60 FPS video stream in the browser.
19
+ - Swipe from the bottom to go home.
20
+ - gestures like pinch to zoom by holding the option key.
21
+ - Simulator logs are forwarded to the browser for browser-use MCP tools to read from.
22
+ - Drag and drop videos and images to add them to the simulator device.
23
+ - Keyboard commands and hot keys are forwarded to the simulator, including CMD+SHIFT+H to go home.
24
+ - Apple Watch, iPad, and iOS support.
25
+
26
+ ## Why?
27
+
28
+ Hosted simulators can be hard to test, `serve-sim` enables you to test the hosted infra locally first for faster iteration. When you're ready to host a simulator remotely, simply tunnel the served URL and users can interact with the simulator as if it were running locally on their device.
29
+
30
+ I develop the Expo framework, but this tool is completely agnostic to React Native and can be used for any iOS interaction you need.
31
+
32
+ ## Install
33
+
34
+ Requires macOS with Xcode command line tools (`xcrun simctl`).
35
+
36
+ ## CLI
37
+
38
+ ```
39
+ serve-sim [device...] Start preview server (default: localhost:3200)
40
+ serve-sim --no-preview [device...] Stream in foreground without a preview server
41
+ serve-sim gesture '<json>' [-d udid] Send a touch gesture
42
+ serve-sim button [name] [-d udid] Send a button press (default: home)
43
+ serve-sim rotate <orientation> [-d udid]
44
+ portrait | portrait_upside_down |
45
+ landscape_left | landscape_right
46
+ serve-sim ca-debug <option> <on|off> [-d udid]
47
+ Toggle a CoreAnimation debug flag
48
+ (blended|copies|misaligned|offscreen|slow-animations)
49
+ serve-sim memory-warning [-d udid] Simulate a memory warning
50
+
51
+ Options:
52
+ -p, --port <port> Starting port (preview default: 3200, stream default: 3100)
53
+ -d, --detach Spawn helper and exit (daemon mode)
54
+ -q, --quiet JSON-only output
55
+ --no-preview Skip the web UI; stream in foreground only
56
+ --list [device] List running streams
57
+ --kill [device] Kill running stream(s)
58
+ ```
59
+
60
+ ### Examples
61
+
62
+ ```sh
63
+ serve-sim # auto-detect booted sim, open preview
64
+ serve-sim "iPhone 16 Pro" # target a specific device
65
+ serve-sim --detach # start a background helper, return JSON
66
+ serve-sim --list # show running streams
67
+ serve-sim --kill # stop all helpers
68
+ ```
69
+
70
+ Multiple booted simulators are supported — pass several device names, or leave it empty to attach to all of them.
71
+
72
+ ## Connectors
73
+
74
+ `serve-sim` can be used with dev servers, browser, and AI editors for more seamless integration.
75
+
76
+ ### Claude Code Desktop
77
+
78
+ Create a `.claude/launch.json` and define a server:
79
+
80
+ ```json
81
+ {
82
+ "version": "0.0.1",
83
+ "configurations": [
84
+ {
85
+ "name": "ios",
86
+ "runtimeExecutable": "npx",
87
+ "runtimeArgs": ["serve-sim"],
88
+ "port": 3200,
89
+ }
90
+ ]
91
+ }
92
+ ```
93
+
94
+ ### Expo
95
+
96
+ Automatically start the serve-sim process with `npx expo start` and access the URL at `http://localhost:8081/.sim`.
97
+
98
+ First, customize the `metro.config.js` file (`bunx expo customize`):
99
+
100
+ ```js
101
+ // Learn more https://docs.expo.io/guides/customizing-metro
102
+ const { getDefaultConfig } = require("expo/metro-config");
103
+ const connect = require("connect");
104
+ const { simMiddleware } = require("serve-sim/middleware");
105
+
106
+ /** @type {import('expo/metro-config').MetroConfig} */
107
+ const config = getDefaultConfig(__dirname);
108
+
109
+ config.server = config.server || {};
110
+ const originalEnhanceMiddleware = config.server.enhanceMiddleware;
111
+ config.server.enhanceMiddleware = (metroMiddleware, server) => {
112
+ const middleware = originalEnhanceMiddleware
113
+ ? originalEnhanceMiddleware(metroMiddleware, server)
114
+ : metroMiddleware;
115
+ const app = connect();
116
+ app.use(simMiddleware({ basePath: "/.sim" }));
117
+ app.use(middleware);
118
+ return app;
119
+ };
120
+
121
+ module.exports = config;
122
+ ```
123
+
124
+ ## Embed in your dev server
125
+
126
+ `serve-sim/middleware` is a Connect-style middleware that mounts the same preview UI inside your existing dev server (Metro, Vite, Next, plain Express, etc.). Run `serve-sim --detach` once to start the streaming helper, then add the middleware:
127
+
128
+ ```ts
129
+ import { simMiddleware } from "serve-sim/middleware";
130
+
131
+ app.use(simMiddleware({ basePath: "/.sim" }));
132
+ // → preview HTML at /.sim
133
+ // → state JSON at /.sim/api
134
+ // → SSE logs at /.sim/logs
135
+ ```
136
+
137
+ The middleware reads the helper's state from `$TMPDIR/serve-sim/` and forwards the user's browser to the live MJPEG + WebSocket endpoints. CORS is wide-open on the helper, so the page renders without a proxy.
138
+
139
+ ## How it works
140
+
141
+ ```
142
+ ┌──────────────┐ simctl io ┌─────────────────┐ MJPEG / WS ┌─────────┐
143
+ │ iOS Simulator│ ────────────► │ serve-sim-bin │ ───────────► │ Browser │
144
+ └──────────────┘ (Swift) │ (per-device) │ └─────────┘
145
+ └─────────────────┘
146
+
147
+ state file in
148
+ $TMPDIR/serve-sim/
149
+
150
+ ┌──────────────────┐
151
+ │ serve-sim CLI / │
152
+ │ middleware │
153
+ └──────────────────┘
154
+ ```
155
+
156
+ The Swift helper (`bin/serve-sim-bin`) is a tiny standalone binary — no Xcode dependency at runtime. The CLI embeds it via `bun build --compile`, so installing the npm package is enough.
157
+
158
+ ## Development
159
+
160
+ ```sh
161
+ bun install
162
+ bun run --filter serve-sim build # build the JS bundles
163
+ bun run --filter serve-sim build:swift # rebuild the Swift helper
164
+ bun run --filter serve-sim dev # watch mode
165
+ ```
166
+
167
+ ## License
168
+
169
+ Apache-2.0
package/bin/serve-sim-bin CHANGED
Binary file