@devries-cameron20 / t3code-1 / commits / 27ccbe9dd5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(devices): skip Apple device discovery on non-Mac hosts (#18159)

Tristan Knight committed Oct 18, 2026 at 20:19 UTC 27ccbe9dd542ef655d9712ca4822346fbe55f2a8
4 files changed +76 -6
apps/server/src/device/LocalDeviceHost.test.ts
+42 -1
@@ -12,7 +12,7 @@ import * as Stream from "effect/Stream";
12 import * as LocalDeviceHost from "./LocalDeviceHost.ts";
13 import * as NodeServices from "@effect/platform-node/NodeServices";
14 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
15 -import { HttpClient, HttpClientResponse } from "effect/http";
15 +import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/http";
16 import * as NetService from "@t3tools/shared/Net";
17 import * as ServerConfig from "../config.ts";
18 import * as ProcessRunner from "../processRunner.ts";
@@ -461,6 +461,47 @@ it.effect(
461 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
462 );
463
464 +it.live("limits hub discovery to Android unless the host is a Mac", () =>
465 + Effect.gen(function* () {
466 + if ((yield* HostProcess.Platform) === "win32") return;
467 + const fs = yield* FileSystem.FileSystem;
468 + const path = yield* Path.Path;
469 + const environment = yield* HostProcess.Environment;
470 + const hubArguments = Effect.fn(function* (platform: NodeJS.Platform) {
471 + const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-device-hub-" });
472 + const installDir = path.join(baseDir, "tools/expo-device-hub", DEVICE_HUB_VERSION);
473 + const entryPath = path.join(installDir, "node_modules/expo-device-hub/dist/server/cli.mjs");
474 + const argumentsPath = path.join(baseDir, "hub-args.json");
475 + yield* fs.makeDirectory(path.dirname(entryPath), { recursive: true });
476 + yield* fs.writeFileString(path.join(installDir, ".install-complete"), DEVICE_HUB_VERSION);
477 + yield* fs.writeFileString(
478 + entryPath,
479 + `import http from 'node:http'; import fs from 'node:fs';
480 +const args=process.argv.slice(2); fs.writeFileSync(${JSON.stringify(argumentsPath)},JSON.stringify(args));
481 +http.createServer((req,res)=>res.end('ok')).listen(Number(args[args.indexOf('--port')+1]),'127.0.0.1');`,
482 + );
483 + const host = yield* LocalDeviceHost.make().pipe(
484 + Effect.provide(
485 + Layer.mergeAll(
486 + ServerConfig.layerTest(baseDir, baseDir),
487 + NetService.layer,
488 + ProcessRunner.layer,
489 + FetchHttpClient.layer,
490 + ),
491 + ),
492 + Effect.provideService(HostProcess.Environment, { ...environment, HOME: baseDir }),
493 + Effect.provideService(HostProcess.Platform, platform),
494 + );
495 + yield* host.ensureReady(() => Effect.void).pipe(Effect.ensuring(host.stop));
496 + return (yield* fs
497 + .readFileString(argumentsPath)
498 + .pipe(Effect.map((contents) => JSON.parse(contents)))) as ReadonlyArray<string>;
499 + });
500 + expect((yield* hubArguments("linux")).slice(-2)).toEqual(["--platform", "android"]);
501 + expect(yield* hubArguments("darwin")).not.toContain("--platform");
502 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
503 +);
504 +
505 it.effect(
506 "constructs and inspects an unconfigured host without installing or starting helpers",
507 () =>
apps/server/src/device/LocalDeviceHost.ts
+5
@@ -224,6 +224,10 @@ const hubEnvironment = Effect.fn("LocalDeviceHost.hubEnvironment")(function* (
224 return env;
225 });
226
227 +/** Only a Mac can list Apple simulators; elsewhere the hub's attempt surfaces as an error. */
228 +const hubPlatformArguments = (hostPlatform: NodeJS.Platform) =>
229 + hostPlatform === "darwin" ? [] : ["--platform", "android"];
230 +
231 export const make = Effect.fn("LocalDeviceHost.make")(function* () {
232 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
233 const config = yield* ServerConfig.ServerConfig;
@@ -394,6 +398,7 @@ export const make = Effect.fn("LocalDeviceHost.make")(function* () {
398 "127.0.0.1",
399 "--hide-sidebar",
400 "--hide-boot-device",
401 + ...hubPlatformArguments(hostPlatform),
402 ],
403 {
404 detached: false,
apps/server/src/device/sshDeviceScript.test.ts
+24 -2
@@ -73,7 +73,7 @@ describe("remote helper lifecycle", () => {
73 hub,
74 `import http from 'node:http'; import fs from 'node:fs';
75 if(fs.existsSync('fail-start-once')) {fs.unlinkSync('fail-start-once');process.exit(1);}
76 -const args=process.argv.slice(2); http.createServer((req,res)=>{res.statusCode=fs.existsSync('unhealthy-'+process.pid)?503:200;res.end('ok');}).listen(Number(args[args.indexOf('--port')+1]),'127.0.0.1');`,
76 +const args=process.argv.slice(2); fs.writeFileSync('hub-args.json',JSON.stringify(args)); http.createServer((req,res)=>{res.statusCode=fs.existsSync('unhealthy-'+process.pid)?503:200;res.end('ok');}).listen(Number(args[args.indexOf('--port')+1]),'127.0.0.1');`,
77 );
78 await NodeFSP.writeFile(
79 agent,
@@ -89,6 +89,12 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
89 await NodeFSP.copyFile(agent, NodePath.join(NodePath.dirname(agent), "daemon.mjs"));
90 const nextHubVersion = DEVICE_HUB_VERSION + "-upgrade";
91 const nextAgentVersion = AGENT_DEVICE_VERSION + "-upgrade";
92 + // Each owner stands in for a host on a different platform.
93 + const hostPlatforms: Record<string, NodeJS.Platform> = { one: "linux", two: "darwin" };
94 + const hubArgs = async (owner: string): Promise<ReadonlyArray<string>> =>
95 + JSON.parse(
96 + await NodeFSP.readFile(NodePath.join(root, `hosts/${owner}/hub-args.json`), "utf8"),
97 + );
98 let invocation = 0;
99 const invoke = async (
100 owner: string,
@@ -98,7 +104,8 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
104 const file = NodePath.join(home, `${owner}-${mode}-${invocation++}.cjs`);
105 await NodeFSP.writeFile(
106 file,
101 - `const originalKill = process.kill; process.kill = (pid, signal) => { if (signal === 'SIGTERM') require('node:fs').appendFileSync(${JSON.stringify(NodePath.join(home, "stops"))}, pid+'\\n'); return originalKill(pid, signal); };\n` +
107 + `Object.defineProperty(process, 'platform', { value: ${JSON.stringify(hostPlatforms[owner])} });\n` +
108 + `const originalKill = process.kill; process.kill = (pid, signal) => { if (signal === 'SIGTERM') require('node:fs').appendFileSync(${JSON.stringify(NodePath.join(home, "stops"))}, pid+'\\n'); return originalKill(pid, signal); };\n` +
109 remoteDeviceScript(owner, mode)
110 .replace(DEVICE_HUB_VERSION, upgraded ? nextHubVersion : DEVICE_HUB_VERSION)
111 .replace(AGENT_DEVICE_VERSION, upgraded ? nextAgentVersion : AGENT_DEVICE_VERSION),
@@ -134,6 +141,19 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
141 ]);
142 expect(concurrent.hubPort).toBe(manual.hubPort);
143 expect(manual.daemonPort).toBeUndefined();
144 + expect((await hubArgs("one")).slice(-2)).toEqual(["--platform", "android"]);
145 + // A hub started before discovery was filtered has no recorded platform.
146 + const hubFile = NodePath.join(root, "hosts/one/hub.json");
147 + const { platform: _platform, ...unfilteredHub } = JSON.parse(
148 + await NodeFSP.readFile(hubFile, "utf8"),
149 + );
150 + await NodeFSP.writeFile(hubFile, JSON.stringify(unfilteredHub));
151 + const filtered = await invoke("one", "start");
152 + expect(filtered.hubPort).not.toBe(manual.hubPort);
153 + expect(await NodeFSP.readFile(NodePath.join(home, "stops"), "utf8")).toContain(
154 + `${unfilteredHub.pid}\n`,
155 + );
156 + expect((await invoke("one", "start")).hubPort).toBe(filtered.hubPort);
157 await expect(
158 NodeFSP.stat(NodePath.join(root, "hosts/one/daemon.json")),
159 ).rejects.toThrow();
@@ -149,6 +169,8 @@ else { const child=spawn(process.execPath,[path.join(path.dirname(process.argv[1
169 const second = await invoke("two", "agent-start");
170 const reused = await invoke("one", "agent-start");
171 expect(reused.hubPort).toBe(first.hubPort);
172 + expect(await hubArgs("two")).not.toContain("--platform");
173 + expect((await invoke("two", "start")).hubPort).toBe(second.hubPort);
174 expect(reused.daemonPort).toBe(first.daemonPort);
175 expect(second.hubPort).not.toBe(first.hubPort);
176 expect(second.daemonPort).not.toBe(first.daemonPort);
apps/server/src/device/sshDeviceScript.ts
+5 -3
@@ -164,19 +164,21 @@ async function install(name, version, entry) {
164 if (!ios && !android) throw Error(platforms.map(p => p.reason).join(' '));
165 fs.mkdirSync(state, { recursive: true, mode: 0o700 });
166 const hubEntry = await install('expo-device-hub', hubVersion, 'dist/server/cli.mjs');
167 + // Only a Mac can list Apple simulators. Recording the filter replaces hubs started without it.
168 + const hubPlatform = process.platform === 'darwin' ? undefined : 'android';
169 let hub = read(hubFile);
168 - if (!hub || hub.owner !== owner || hub.entryPath !== hubEntry || !await healthy(hub.port, '/readyz')) {
170 + if (!hub || hub.owner !== owner || hub.entryPath !== hubEntry || hub.platform !== hubPlatform || !await healthy(hub.port, '/readyz')) {
171 stopHub(hub);
172 for (let attempt = 0; attempt < 5; attempt++) {
173 const hubPort = await port();
174 const log = fs.openSync(path.join(state, 'hub.log'), 'a');
173 - const child = spawn(process.execPath, [hubEntry, '--port', String(hubPort), '--host', '127.0.0.1', '--hide-sidebar', '--hide-boot-device'], {
175 + const child = spawn(process.execPath, [hubEntry, '--port', String(hubPort), '--host', '127.0.0.1', '--hide-sidebar', '--hide-boot-device', ...(hubPlatform ? ['--platform', hubPlatform] : [])], {
176 cwd: state, detached: true, stdio: ['ignore', log, log], env: { ...process.env, FORCE_COLOR: '0', NO_COLOR: '1' },
177 });
178 try { await new Promise((resolve, reject) => { child.once('spawn', resolve); child.once('error', reject); }); }
179 finally { fs.closeSync(log); }
180 child.unref();
179 - hub = { owner, pid: child.pid, port: hubPort, entryPath: hubEntry };
181 + hub = { owner, pid: child.pid, port: hubPort, entryPath: hubEntry, platform: hubPlatform };
182 write(hubFile, hub);
183 const deadline = Date.now() + 30000;
184 let listening = false;