robodev mobile worksThe same src/pages that build the web app run as a native iOS and Android app. This walks through what the command does on your Mac, what runs on the phone, and what's still missing. All code is from the local branch (packages/cli/src/mobile*.ts and packages/app/src/native*.tsx).
$ robodev mobile
Mobile routes: 14 files in mobile/app (from src/pages)
Metro http://127.0.0.1:19437
App http://127.0.0.1:18437 (Metro + API through one port)
API http://localhost:4000
Running on iPhone 17 Pro (4.1 s). Edit src/pages and it reloads; Ctrl-C stops.
Example output; ports, file count and time vary. It assumes robodev dev is already running in another terminal (the backend on port 4000). Then, in order:
mobile/ on the first run: an Expo project.mobile/app/** from src/pages/**, and src/api.gen.ts from robodev/api/**.
flowchart LR
subgraph mac["Your Mac"]
pages["src/pages/**"] -->|generateExpoRoutes| app["mobile/app/** (generated)"]
api["robodev/api/**"] -->|writeApiHooks| gen["src/api.gen.ts"]
app --> metro["Metro :19xxx"]
gen --> metro
dev["robodev dev :4000
(API, sockets, Postgres)"]
proxy["proxy :18xxx
one origin"]
metro --- proxy
dev --- proxy
end
proxy -->|"exp://127.0.0.1:18xxx"| sim["iOS Simulator
Expo Go"]
proxy -->|"adb reverse"| emu["Android emulator
Expo Go"]
proxy -->|"--tunnel https"| phone["Real phone
Expo Go"]
mobile/If mobile/package.json doesn't exist, the CLI writes one and installs Expo. Nothing in here is meant to be edited by hand.
| File | What it is |
|---|---|
package.json | Expo SDK 58, React 19.3, React Native 0.88. Main entry is expo-router/entry. |
app.json | Name, URL scheme, bundle ids (dev.robodev.<name>), the expo-router plugin. |
metro.config.js | Rewritten every run. Lets Metro build ../src (step 3). |
tsconfig.json | Plain, because Metro reads its paths. |
tsconfig.check.json | Rewritten every run. For typechecking the screens the way Metro bundles them. |
.gitignore | node_modules/ .expo/ app/ ios/ android/. The generated routes are never committed. |
Install is npm install then npx expo install expo-router expo-linking expo-constants expo-status-bar react-native-safe-area-context react-native-screens @react-native-async-storage/async-storage, so Expo picks versions that match the SDK.
src/pages becomes Expo Router's app/Expo Router uses the same file conventions as our pages: [id], [...rest], _layout, (group). So each page gets a generated file of two lines that points back at the real page. The page stays the only source.
_layout.tsx
index.tsx
login.tsx
todos/index.tsx
todos/[id].tsx
board/[id].tsx
board/[id].native.tsx
_layout.tsx ← rootLayout(app, Layout)
index.tsx ← screen(page, "index.tsx")
login.tsx
todos/index.tsx
todos/[id].tsx
board/[id].tsx ← one file; Metro picks .native
+not-found.tsx ← built in if you have no 404
// Generated by `robodev mobile` from src/pages. Do not edit; edit the page instead.
import { screen } from "@robodev-ai/app/native";
import * as page from "../../../src/pages/todos/[id]";
export default screen(page, "todos/[id].tsx");
import { rootLayout } from "@robodev-ai/app/native";
import app from "../../src/app";
import Layout from "../../src/pages/_layout";
export default rootLayout(app, Layout);
todos/[id]), so Metro chooses [id].ios.tsx, [id].native.tsx or [id].tsx per platform.import * as page, not the default export, so screen() can also read export const auth and title._ (like _board-list.native.tsx) are helpers, not routes.login.tsx or 404.tsx? The built-in LoginScreen and NotFoundScreen are used.src/pages regenerates mobile/app when a page is added or removed (150 ms debounce). Edits to existing pages don't need this; Metro picks them up.../src with one copy of ReactMetro normally only builds files inside its own project. Our pages live one folder up, and the web app has its own React in the project's node_modules. Two copies of React in one bundle breaks hooks, so the generated config does three things:
config.watchFolders = [path.join(projectRoot, "src"), appPkg, clientPkg]; // 1. see ../src
const ROBODEV_ENTRIES = { // 2. the native build
"@robodev-ai/app": appNative, // → packages/app/src/native.ts
"@robodev-ai/app/native": appNative,
"@robodev-ai/client": path.join(clientPkg, "src", "index.ts"),
};
config.resolver.resolveRequest = (context, moduleName, platform) => {
const entry = ROBODEV_ENTRIES[moduleName];
if (entry) return { type: "sourceFile", filePath: entry };
// 3. a bare import from ../src (react, expo-router, …) resolves from mobile/node_modules
if (isBare(moduleName) && !inside(context.originModulePath)) {
return context.resolveRequest(
{ ...context, originModulePath: path.join(mobileRoot, "package.json") }, moduleName, platform);
}
return context.resolveRequest(context, moduleName, platform);
};
A page writes import { Button, Stack, useNavigate } from "@robodev-ai/app". On the web that's the DOM kit. On the phone, rule 2 swaps in native.ts, which exports the same names built on React Native. That's what lets one page file run on both.
The app needs to reach two servers: Metro (bundle, assets, hot reload, debugger) and robodev dev (API, sockets). Instead of telling the app two URLs, the CLI starts a small proxy and sends everything through one port:
const API_PREFIXES = ["/api/", "/api?", "/sockets/", "/_robodev/", "/.well-known/"];
const upstreamFor = (path) => (isApiPath(path) ? input.api : input.metro);
// HTTP: pipe the request to the right upstream.
// WebSockets (Metro /hot, /message, /inspector/*; Robodev /sockets/*): replay the upgrade
// request upstream and splice the two TCP connections together.
server.on("upgrade", (req, socket, head) => { ... upstream.pipe(socket); socket.pipe(upstream); });
projectUrl() reads the host the bundle came from (Constants.expoConfig.hostUri) and calls the API there. Same simulator, emulator, LAN phone or tunnel, no env file.adb reverse, the LAN and --tunnel all forward that single port.Forwarded: host=…;proto=… header, and Metro builds the manifest's bundle URL from it, so the bundle URL points at the proxy, or the tunnel, without rewriting anything.--url https://… sets EXPO_PUBLIC_ROBODEV_URL instead.Bun 1.3's node:http server never fires the upgrade event. HTTP works, but every WebSocket dies: no live sync, no hot reload, no --logs. The CLI prints a warning on 1.3.
The app runs inside Expo Go, a prebuilt app that loads a JavaScript bundle from a URL. So there is no Xcode build and no Gradle build. The CLI just makes sure the right Expo Go is installed and opens the URL.
| Step | iOS (mobile-ios.ts) | Android (mobile-android.ts) |
|---|---|---|
| Pick device | simctl list, newest iPhone runtime, or --device | first online adb devices, or boot an AVD (creates one if none) |
| Boot | simctl bootstatus -b (returns when usable) | emulator -avd …, wait for sys.boot_completed=1 |
| Window | open -a Simulator, skipped with --headless | -no-window -gpu swiftshader_indirect with --headless |
| Reach the Mac | shares the Mac's network, nothing to do | adb reverse tcp:PORT tcp:PORT |
| Expo Go | Ask Metro which SDK it serves, look up the matching Expo Go build on api.expo.dev (cached in ~/.expo for offline), download once, install if the version differs | |
| Skip prompts | pre-approve exp:// and exps:// in the device's scheme-approval plist | open with an explicit package: am start -p host.exp.exponent |
| Open | simctl terminate, then simctl openurl | am force-stop, wait for the process to exit, then am start -d exp://… |
The URL includes __expo_disable_fab=1&__expo_disable_onboarding=1 so Expo Go's onboarding sheet and floating dev button stay out of the way, the same as Expo's own CLI does.
Before opening the app, the CLI notes the JS runtimes Metro's debugger knows about (GET /json/list). After opening it, it polls every 100 ms until a new one appears. A new runtime means the bundle has loaded and React Native is executing it. That's when it prints "Running … (4.1 s)".
// Expo Go's JS console never reaches the simulator's system log, so read it over the
// Chrome DevTools Protocol, through Metro's inspector proxy.
const ws = new WebSocket(target.webSocketDebuggerUrl, { headers: { Origin: origin } });
ws.onopen = () => ws.send(JSON.stringify({ id: 1, method: "Runtime.enable" }));
ws.onmessage = (event) => {
if (msg.method !== "Runtime.consoleAPICalled") return;
print(`[app ${msg.params.type}] ${text}`); // [app error] TypeError: …
};
This works the same on iOS and Android, and it's what makes the command usable by an agent: a clear ready line, then the app's errors as plain text.
@robodev-ai/app/native does at runtimecreateClient({ url, storage: AsyncStorage }), so the session survives app restarts.RobodevProvider (auth, data cache), the theme from defineApp({ theme }) resolved for light/dark, and a safe-area view.src/pages/_layout.tsx around an Expo Router native stack with headers off, so the app's own layout draws the chrome.auth and title, same as the web (pageFromModule).auth = "required" and signed out: <Redirect href="/login?next=…">. "guest" and signed in: redirect to next or afterSignIn.params (names from the file, like [id]) and search (the rest), then renders <Page params search />, the same props as on the web.| Page uses | Web | Phone |
|---|---|---|
Stack, Text, Button, Input, Card… | DOM elements + CSS | View, Text, Pressable, TextInput with theme styles (native-ui.tsx) |
Link to="/todos" | router link | Expo Router Link |
useNavigate() | web history | router.push / replace / back, same signature |
useGetTodos() | fetch, same-origin cookie | fetch to the proxy host, token in AsyncStorage |
useSocket() | WebSocket | WebSocket through the proxy |
className, DOM props | applied | accepted and ignored |
Most pages run unchanged. When a screen needs native APIs or a different layout, add a sibling file; the web bundle ignores .native/.ios/.android files and Metro prefers them.
board/[id].tsx web: SVG canvas, mouse, keyboard shortcuts
board/[id].native.tsx phone: touch drawing, pinch zoom, react-native-view-shot thumbnails
_layout.native.tsx phone: account sheet instead of a dropdown menu
The Diagrams port has five .native files: _layout, index, auth, diagrams and the _board-list helper, plus the board screens. Everything else, including all API hooks, is shared.
npx tsc -p mobile/tsconfig.check.json
That config typechecks the screens the way Metro bundles them: moduleSuffixes: [".ios", ".native", ""], @robodev-ai/app mapped to native.ts, and React and React Native types from mobile/node_modules. It's a separate file because putting those paths in tsconfig.json made Metro resolve react to its type package and fail to bundle.
Save a page and Metro sends the changed module over its /hot socket (through the proxy). React Fast Refresh swaps it in place. One catch: a module that exports auth or title next to its component isn't a refresh boundary on its own, so the edit re-runs the generated route file, which calls screen() again. To keep state, screen() remembers one wrapper per file:
const screens = new Map<string, { page: PageDefinition; Screen: () => ReactNode }>();
export function screen(pageModule: PageModule, file: string) {
const known = screens.get(file);
if (known) {
known.page = pageFromModule(pageModule, file); // new component inside
return known.Screen; // same wrapper → no remount
}
...
}
--lanThe proxy listens on 0.0.0.0. The CLI prints exp://192.168.x.x:18xxx and a QR code. Same Wi-Fi only, and some office networks block it.
--tunnelThe proxy port goes out through Starbase's tunnel as https://<random id>.<tunnel host>. The app opens with exps://. Works from any network, public while the command runs, and the id is remembered per project so the QR code stays the same.
Scan with the iPhone camera or Expo Go on Android. Because the API goes through the same port, the phone talks to your local backend with no extra setup.
robodev mobile --ios --headless --logs
[app error] … lines on stdout to read and fix.The iOS Simulator needs macOS, and the Android emulator needs KVM, which a microVM usually doesn't expose. The design that works: the app (Metro, proxy, backend) runs in the agent's VM with --tunnel, and a separate device host (a Mac for iOS, a Linux box with KVM for Android) opens the tunnel URL. The agent drives the device host over an API and reads screenshots and logs back.
useSyncExternalStorenative.ts re-exports useApi/useMutation from the shared data.ts, which Urban has ruled out. Option: give mobile its own small store on useState/useEffect behind the same hook names until the web design is settled. No page code changes either way.
Everything runs inside Expo Go, which is a development app. Shipping a real app needs a native build (Expo prebuild or EAS Build), signing, icons and store metadata. app.json already has bundle ids, but no build step exists.
Libraries with their own native code must be in Expo Go's set (react-native-view-shot is). Anything else needs a development build instead of Expo Go, which the CLI doesn't make yet.
Described above; nothing exists yet.
The proxy needs Bun 1.4 for WebSockets. The first run per SDK downloads Expo Go from Expo; later runs use the cache in ~/.expo.
Mobile doesn't use react-router. useNavigate and useSearchParams only mention its signature in comments; those can be reworded.