The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 00:45 UTC
fix(server): capture iOS screenshots on Xcode 26's simctl (#28353)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Nov 10, 2026 at 18:59 UTC
41443e5706c4605bc3efc17bcf431970488a146d
5 files changed
+64
-14
apps/server/src/device/DeviceHost.ts
+6
-1
@@ -162,7 +162,12 @@ export interface DeviceHostReady {
162
readonly run: (
163
command: string,
164
args: ReadonlyArray<string>,
165
- options?: { readonly timeoutMs?: number; readonly stdin?: string },
165
+ options?: {
166
+ readonly timeoutMs?: number;
167
+ readonly stdin?: string;
168
+ /** Local output cap; SSH output is not capped. */
169
+ readonly maxOutputBytes?: number;
170
+ },
171
) => Effect.Effect<{ readonly stdout: string; readonly stderr: string; readonly code: number }>;
172
readonly helpers: {
173
readonly serveSimAxSettings: string | null;
apps/server/src/device/DeviceHubOperations.ts
+30
@@ -19,6 +19,11 @@ const LIST_TIMEOUT_SECONDS = 40;
19
// expo-device-hub 0.19.1 reports a failed simulator listing only as text; its error ids are hashes.
20
const SIMULATOR_LIST_FAILED =
21
/^\[apple-utils\] (?:Failed to (?:run `xcrun simctl list devices|parse JSON output:|list devices:)|`xcrun simctl list devices --json` did not respond within )/;
22
+// The hub passes numeric display IDs that Xcode 26 rejects; iOS 27 needs them for multiple displays.
23
+const runsOnXcode26Runtime = (version: string) => Number(/^iOS (\d+)/.exec(version)?.[1]) <= 26;
24
+const DEFAULT_DISPLAY_SCREENSHOT = `f=$(mktemp -t t3-screenshot) || exit 1
25
+trap 'rm -f "$f"' 0
26
+xcrun simctl io "$1" screenshot --type=png "$f" >/dev/null && base64 -i "$f"`;
27
28
const HubDevice = Schema.Struct({
29
id: Schema.String,
@@ -265,6 +270,24 @@ export const makeDeviceHubOperations = (options: {
270
},
271
);
272
273
+ const defaultDisplayScreenshot = Effect.fn("DeviceHubOperations.defaultDisplayScreenshot")(
274
+ function* (udid: string) {
275
+ const capture = yield* run("sh", ["-c", DEFAULT_DISPLAY_SCREENSHOT, "sh", udid], {
276
+ timeoutMs: Duration.toMillis(SCREENSHOT_TIMEOUT),
277
+ maxOutputBytes: 64 * 1024 * 1024,
278
+ });
279
+ if (capture.code !== 0) {
280
+ return yield* new DeviceOperationError({
281
+ operation: "screenshot",
282
+ reason: "command_failed",
283
+ exitCode: capture.code,
284
+ cause: capture.stderr.trim(),
285
+ });
286
+ }
287
+ return new Uint8Array(Buffer.from(capture.stdout, "base64"));
288
+ },
289
+ );
290
+
291
const screenshot: DeviceOperations["screenshot"] = (device) =>
292
httpClient
293
.execute(
@@ -289,6 +312,13 @@ export const makeDeviceHubOperations = (options: {
312
cause,
313
}),
314
),
315
+ Effect.catchIf(
316
+ (error) =>
317
+ device.platform === "ios" &&
318
+ runsOnXcode26Runtime(device.version) &&
319
+ error.reason === "hub_rejected",
320
+ () => defaultDisplayScreenshot(device.id),
321
+ ),
322
Effect.withSpan("DeviceHubOperations.screenshot"),
323
);
324
apps/server/src/device/DeviceHubProxy.ts
+8
@@ -213,6 +213,14 @@ const handler = Effect.gen(function* () {
213
upstreamSearch.delete("wsTicket");
214
upstreamSearch.delete("hostId");
215
const search = upstreamSearch.size > 0 ? `?${upstreamSearch.toString()}` : "";
216
+ const screenshotDevice = upstreamSearch.get("device");
217
+ if (!ready.upstream && hubPath === "/vendor/serve-sim/api/screenshot" && screenshotDevice) {
218
+ const { png } = yield* devices.screenshot({ hostId: ready.hostId, deviceId: screenshotDevice });
219
+ return HttpServerResponse.uint8Array(png, {
220
+ contentType: "image/png",
221
+ headers: { "cache-control": "no-store, no-transform" },
222
+ });
223
+ }
224
// Hosts with several upstreams (one per cloud session) route and authenticate requests themselves.
225
const routed = ready.upstream ? yield* ready.upstream(hubPath, upstreamSearch) : undefined;
226
if (routed === null) {
apps/server/src/device/DeviceService.test.ts
+17
-13
@@ -48,7 +48,7 @@ const decodeBootError = Schema.decodeUnknownSync(Schema.fromJsonString(DeviceBoo
48
const encodeBootError = Schema.encodeSync(Schema.fromJsonString(DeviceBootError));
49
50
it.effect.each([400, 500])(
51
- "distinguishes screenshot HTTP rejection (%s) from transport failure",
51
+ "retries a hub-rejected (%s) screenshot with simctl only on iOS 26 and older",
52
(status) =>
53
Effect.gen(function* () {
54
const operations = makeDeviceHubOperations({
@@ -59,22 +59,26 @@ it.effect.each([400, 500])(
59
HttpClientResponse.fromWeb(request, new Response("private hub output", { status })),
60
),
61
),
62
- run: () => Effect.die("Screenshot does not run a command"),
62
+ run: () => Effect.succeed({ code: 0, stdout: "iVBORw==", stderr: "" }),
63
platformAvailable: () => Effect.succeed(false),
64
});
65
- const result = yield* operations
66
- .screenshot({
67
- id: "phone",
68
- name: "Phone",
69
- version: "iOS 26.3",
70
- platform: "ios",
71
- booted: true,
72
- physical: false,
73
- })
74
- .pipe(Effect.result);
75
- expect(result).toMatchObject({
65
+ const screenshot = (version: string) =>
66
+ operations
67
+ .screenshot({
68
+ id: "phone",
69
+ name: "Phone",
70
+ version,
71
+ platform: "ios",
72
+ booted: true,
73
+ physical: false,
74
+ })
75
+ .pipe(Effect.result);
76
+ expect(yield* screenshot("iOS 27.0")).toMatchObject({
77
failure: { _tag: "DeviceOperationError", reason: "hub_rejected" },
78
});
79
+ expect(yield* screenshot("iOS 26.3")).toMatchObject({
80
+ success: new Uint8Array([137, 80, 78, 71]),
81
+ });
82
}),
83
);
84
apps/server/src/device/LocalDeviceHost.ts
+3
@@ -806,6 +806,9 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () {
806
timeout: Duration.millis(options?.timeoutMs ?? 20_000),
807
timeoutBehavior: "timedOutResult",
808
...(options?.stdin === undefined ? {} : { stdin: options.stdin }),
809
+ ...(options?.maxOutputBytes === undefined
810
+ ? {}
811
+ : { maxOutputBytes: options.maxOutputBytes }),
812
})
813
.pipe(
814
Effect.map((result) => ({