emd-agents 0.16.2 → 0.17.0

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.
Files changed (52) hide show
  1. package/README.md +31 -21
  2. package/dist/adapters/expo/index.js +17 -5
  3. package/dist/adapters/gradle/index.d.ts +3 -0
  4. package/dist/adapters/gradle/index.js +63 -0
  5. package/dist/adapters/xcode/index.d.ts +16 -0
  6. package/dist/adapters/xcode/index.js +116 -0
  7. package/dist/cli/main.js +17 -2
  8. package/dist/core/adapter.d.ts +12 -5
  9. package/dist/core/adapter.js +1 -1
  10. package/dist/core/buildrecord.d.ts +5 -0
  11. package/dist/core/buildrecord.js +22 -0
  12. package/dist/core/check.d.ts +4 -2
  13. package/dist/core/check.js +22 -9
  14. package/dist/core/device/adb.d.ts +23 -0
  15. package/dist/core/device/adb.js +128 -0
  16. package/dist/core/device/backend.d.ts +1 -1
  17. package/dist/core/device/backend.js +18 -2
  18. package/dist/core/doctor.d.ts +6 -1
  19. package/dist/core/doctor.js +100 -19
  20. package/dist/core/emulator.d.ts +29 -0
  21. package/dist/core/emulator.js +144 -0
  22. package/dist/core/gc.d.ts +1 -0
  23. package/dist/core/gc.js +6 -0
  24. package/dist/core/index.d.ts +2 -0
  25. package/dist/core/index.js +2 -0
  26. package/dist/core/input.d.ts +3 -0
  27. package/dist/core/input.js +7 -2
  28. package/dist/core/launch.d.ts +5 -0
  29. package/dist/core/launch.js +332 -69
  30. package/dist/core/log.d.ts +2 -0
  31. package/dist/core/log.js +20 -9
  32. package/dist/core/logs.d.ts +1 -0
  33. package/dist/core/logs.js +32 -17
  34. package/dist/core/owned.d.ts +1 -1
  35. package/dist/core/probe.d.ts +1 -0
  36. package/dist/core/probe.js +22 -8
  37. package/dist/core/process.d.ts +1 -0
  38. package/dist/core/process.js +30 -1
  39. package/dist/core/registry.js +2 -0
  40. package/dist/core/reload.d.ts +1 -1
  41. package/dist/core/reload.js +14 -7
  42. package/dist/core/result.d.ts +23 -0
  43. package/dist/core/result.js +7 -0
  44. package/dist/core/run.d.ts +2 -0
  45. package/dist/core/run.js +2 -0
  46. package/dist/core/setup.d.ts +1 -0
  47. package/dist/core/setup.js +9 -3
  48. package/dist/core/tool.d.ts +1 -0
  49. package/dist/core/tool.js +5 -0
  50. package/dist/mcp/server.js +21 -5
  51. package/package.json +2 -2
  52. package/skills/emd/SKILL.md +8 -3
package/README.md CHANGED
@@ -4,17 +4,18 @@
4
4
 
5
5
  An MCP server, CLI and agent skill for coding agents that change mobile apps.
6
6
 
7
- Your coding agent shouldn't grade its own mobile work. EMD builds the app, launches it on the iOS simulator, and passes or fails each change from the app's own log lines and screen. It keeps the evidence: checks, log lines and screenshots.
7
+ Your coding agent shouldn't grade its own mobile work. EMD builds the app, launches it on an iOS simulator or Android emulator, and passes or fails each change from the app's own log lines and screen. It keeps the evidence: checks, log lines and screenshots.
8
8
 
9
9
  `setup` registers EMD with Claude Code, Codex and Cursor. Tested end to end in Claude Code.
10
10
 
11
- Status: early. Expo apps on the iOS simulator only.
11
+ Status: early. Expo apps on the iOS simulator and an Android emulator, native iOS apps (SwiftUI or UIKit) on the iOS simulator, and native Android apps (Kotlin, Compose or Views) on an Android emulator.
12
12
 
13
13
  ## Requirements
14
14
 
15
- - A Mac with Xcode 26 or 27 and at least one iPhone simulator.
15
+ - iOS: a Mac with Xcode 26 or 27 and at least one iPhone simulator.
16
+ - Android: the Android SDK with `ANDROID_HOME` set, at least one AVD, and JDK 17 or newer. Tested on Linux.
16
17
  - Node 22 or newer.
17
- - An Expo app with its dependencies installed. [Check your app](#check-your-app) shows how to check it.
18
+ - An Expo app with its dependencies installed, a native iOS app with an `.xcworkspace` or `.xcodeproj` in its root folder, or a native Android app with a Gradle wrapper. [Check your app](#check-your-app) shows how to check it.
18
19
 
19
20
  Tested: Expo SDK 58 on Xcode 26 and 27. On Xcode 27, apps below Expo SDK 56 can't build (Expo's bug). Use Xcode 26, or upgrade the app to SDK 56 or newer.
20
21
 
@@ -26,7 +27,7 @@ More detail: [Requirements in detail](#requirements-in-detail).
26
27
  npx -y emd-agents@latest setup
27
28
  ```
28
29
 
29
- It finds Claude Code, Codex and Cursor, prints its plan and asks once. On a Mac without AXe, it installs AXe, the tool EMD uses to tap and read the screen. Then it registers EMD with each agent and installs EMD's skill, which tells the agent how to use EMD. It backs up each agent config to `~/.emd/backups/` first.
30
+ It finds Claude Code, Codex and Cursor, prints its plan and asks once. On a Mac without AXe, it installs AXe, the tool EMD uses to tap and read the screen on iOS, unless the app targets only Android. Android needs nothing more: EMD uses the SDK's adb. Then it registers EMD with each agent and installs EMD's skill, which tells the agent how to use EMD. It backs up each agent config to `~/.emd/backups/` first.
30
31
 
31
32
  At the end it runs `doctor`. For each check marked `missing`, do what its `fix` says. Then restart your agents.
32
33
 
@@ -43,13 +44,17 @@ npx -y emd-agents@latest detect /path/to/my-app
43
44
 
44
45
  It must print `"verdict":"detected"` and no `problem`. For example, `"appIds":{"ios":"com.example.myapp"}`. If the app has no iOS app ID, `detect` says so in `notes`: new Expo apps (from `create-expo-app`) have none, and `launch` lets Expo's build set one in the app config (`ios.bundleIdentifier`). EMD writes nothing to the config. Expo's first `run:ios` also creates the `ios/` folder and points the `ios` and `android` scripts in package.json at `expo run:ios` and `expo run:android`. If `problem` appears, install the app's dependencies: EMD reads the config with the app's own Expo CLI.
45
46
 
47
+ A native iOS app detects as `"stack":"xcode"`, with no app ID: `launch` reads the ID from the app it builds. It builds the scheme named like the workspace or project, or the only scheme, or the one in `scheme`, with the configuration its Run action uses, as Xcode does.
48
+
49
+ A native Android app detects as `"stack":"gradle"`, with no app ID: `launch` builds the debug APK of the one app module and reads the ID that the build records.
50
+
46
51
  ## First run
47
52
 
48
53
  Ask your agent for a small change, with the full path of your app:
49
54
 
50
55
  > In /path/to/my-app, add a button that shows "Saved" when tapped. Prove it on the iOS simulator with EMD, then tell me the evidence folder.
51
56
 
52
- The agent follows EMD's skill. It adds a tagged log line, such as `console.log("[EMD:saved] button tapped")`, and a testID. Then it launches the app, taps, checks the log line and the screen, and gathers the evidence. A first build takes minutes.
57
+ The agent follows EMD's skill. It adds a tagged log line, such as `console.log("[EMD:saved] button tapped")` (Expo), `NSLog("[EMD:saved] button tapped")` (Swift) or `Log.i("EMD", "[EMD:saved] button tapped")` (Kotlin), and a testID. Then it launches the app, taps, checks the log line and the screen, and gathers the evidence. A first build takes minutes.
53
58
 
54
59
  Each check ends with one verdict:
55
60
 
@@ -60,18 +65,21 @@ Each check ends with one verdict:
60
65
 
61
66
  A check name keeps its first expectations. A later check with the same name can add expectations, but not drop them. The evidence lists each check name whose last verdict is not `passed`.
62
67
 
63
- Output stays on your Mac:
68
+ Output stays on your machine:
64
69
 
65
- - Each launch has a run folder, `$TMPDIR/emd/runs/<time>-<app folder>/`. The launch result gives it as `logDir`. It holds `build.log`, `metro.log`, the app's log (`app.ndjson`), the check screenshots, and `evidence/` (`manifest.json`, `logs.json`, `screenshots/`, `flows/`).
70
+ - Each launch has a run folder, `$TMPDIR/emd/runs/<time>-<app folder>/`. The launch result gives it as `logDir`. It holds `build.log`, `metro.log`, the app's log (`app.ndjson`, or `app.logcat` on Android), the check screenshots, and `evidence/` (`manifest.json`, `logs.json`, `screenshots/`, `flows/`).
66
71
  - Jobs are in `$TMPDIR/emd/jobs/<jobId>.json`.
67
72
  - Data that must stay after a restart is in `~/.emd/`: the record of what EMD made (`owned/`), build folders (`derived/`) and failed-check counts (`checks/`).
68
73
 
69
74
  ## Limits today
70
75
 
71
- - Expo apps on the iOS simulator only. No native iOS or Android projects, no Android launch, no physical devices.
76
+ - No physical devices.
77
+ - Expo on Android: `launch` builds on every call, with no reload yet. When the app has no `android/` folder, the first Android launch runs `expo prebuild --platform android` to make it, as `expo run:android` does.
78
+ - Native Android: one app module and its debug build, with no product flavors. `launch` builds on every call; Gradle's own build is incremental. Through adb, `type` types ASCII text only; other text goes through Maestro.
79
+ - Native iOS: with several schemes and none named like the workspace or project, `launch` needs `scheme`. A project made by a setup step (Tuist, XcodeGen, Bazel, or a `make` around them) shows `needsPrepare`: pass the setup command as `prepare`, and EMD runs it before each build. An app that Bazel builds with no Xcode project doesn't work yet. `launch` builds on every call; there is no build reuse yet.
72
80
  - `launch` leaves the dev server running. The next `launch` of the same folder stops it and starts a new one. A dev server that EMD did not start on that port still blocks `launch` ("Port N already serves a dev server").
73
81
  - `EMD_RETRY_LIMIT` (1 to 10) changes the limit of 3 failed checks.
74
- - A build can take 900 seconds by default (`timeoutSeconds`, or `--timeout` in the CLI). Two cold builds at the same time can take longer.
82
+ - A build stops when its log has not grown for 600 seconds, or after 3600 seconds in total (`timeoutSeconds`, or `--timeout` in the CLI). Two cold builds at the same time take longer.
75
83
  - The CLI `launch` waits and does not make a job. `logs`, `check` and `evidence` need the `jobId` of a `launch` that the agent started.
76
84
 
77
85
  ## FAQ
@@ -84,7 +92,7 @@ Each project's README says what it does. [agent-device](https://github.com/calls
84
92
  - A check name keeps its first expectations, so the agent can't pass it by dropping one.
85
93
  - After 3 failed checks, every later check returns `stopped` until a person resets the count.
86
94
 
87
- For taps and screen reads, EMD uses AXe, with Maestro as the fallback.
95
+ For taps and screen reads, EMD uses AXe on iOS and adb on Android, with Maestro as the fallback.
88
96
 
89
97
  ### How do I upgrade?
90
98
 
@@ -102,9 +110,9 @@ npx -y skills@1.7.6 remove emd -g -y
102
110
 
103
111
  In Cursor, delete the `emd` entry from `~/.cursor/mcp.json`.
104
112
 
105
- To remove what EMD made on your Mac:
113
+ To remove what EMD made on your machine:
106
114
 
107
- 1. Delete its simulators. `xcrun simctl list devices | grep emd-` lists them. `xcrun simctl delete <id>` deletes one.
115
+ 1. Delete its simulators. `xcrun simctl list devices | grep emd-` lists them. `xcrun simctl delete <id>` deletes one. Stop its Android emulators: `adb devices` lists them, and `adb -s <serial> emu kill` stops one. EMD makes no AVDs.
108
116
  2. Delete `~/.emd/`. It holds AXe, build folders, EMD's records and the config backups from setup. Copy a backup first if you want to keep it.
109
117
 
110
118
  ## Report a problem
@@ -113,7 +121,7 @@ Open an [issue](https://github.com/andrewhenin/emd/issues) with:
113
121
 
114
122
  - What you asked the agent, and the tool or command that failed, with its JSON result.
115
123
  - The output of `npx -y emd-agents@latest doctor` and `npx -y emd-agents@latest detect /path/to/my-app`.
116
- - Versions: EMD's (the `emd-agents@<version>` in your agent's MCP config, or `node dist/bin.js` and `git rev-parse --short HEAD` in a clone), `sw_vers` (macOS), `xcodebuild -version`, `node --version`, and `axe --version` or `maestro --version` if you use them.
124
+ - Versions: EMD's (the `emd-agents@<version>` in your agent's MCP config, or `node dist/bin.js` and `git rev-parse --short HEAD` in a clone), `sw_vers` (macOS), `xcodebuild -version`, `node --version`, and `axe --version` or `maestro --version` if you use them. On Android: `adb version` and `java --version`.
117
125
  - From the run folder: `build.log` and `metro.log`, or the lines near the error.
118
126
  - Before you attach logs or screenshots, remove private details: names, tokens, keys, internal URLs and user data.
119
127
 
@@ -128,10 +136,10 @@ EMD is open source but does not accept pull requests from outside contributors y
128
136
  `emd mcp` serves these tools:
129
137
 
130
138
  - `detect`: finds the stack, platforms, app IDs, run commands and package manager of a folder. At a workspace root, it lists the app folders instead (`apps`).
131
- - `launch`: builds the app, installs and opens it on an iOS simulator, and keeps its dev server running. Waits up to 25 s (`waitSeconds`): a reload or relaunch returns its result, a build returns a job.
139
+ - `launch`: builds the app, installs and opens it on an iOS simulator or Android emulator (`platform`), and keeps its dev server running. Waits up to 25 s (`waitSeconds`): a reload or relaunch returns its result, a build returns a job.
132
140
  - `job_status`: the state of a job (queued, running, succeeded, failed) and, at the end, its result. It waits up to 30 s (`waitSeconds`) and returns when the job ends. In Claude Code, `setup` raises the default wait of `launch`, `check` and `job_status` to 100 s (`EMD_WAIT_SECONDS`), so a build takes fewer calls; a client that cancels a call gets the short waits again.
133
141
  - `logs`: the `[EMD:<tag>]` lines that the app wrote during the run of a launch job.
134
- - `tap`, `type`, `swipe`: act on the launched app. `tap` takes a testID, a visible text or a point. Each says which tool did it (AXe or Maestro).
142
+ - `tap`, `type`, `swipe`: act on the launched app. `tap` takes a testID, a visible text or a point. Each says which tool did it (AXe, adb or Maestro).
135
143
  - `check`: passes or fails a run from tagged log lines and on-screen elements (by testID or text). Waits up to 25 s (`waitSeconds`) and usually returns the verdict; a longer check returns a job. It can run taps, typing and swipes first (`actions`). Each check rewrites the run's evidence folder and returns its path.
136
144
  - `evidence`: puts the checks, log lines, screenshots and Maestro flows of a run in one folder.
137
145
 
@@ -140,7 +148,7 @@ EMD is open source but does not accept pull requests from outside contributors y
140
148
  Run them as `npx -y emd-agents@latest <command>`, or `node dist/bin.js <command>` in a clone. Below, `emd` means either.
141
149
 
142
150
  - `detect [dir]`: same as the tool.
143
- - `launch [dir] [--device X] [--timeout N]`: same as the tool, but waits for the result.
151
+ - `launch [dir] [--platform ios|android] [--prepare CMD] [--scheme S] [--configuration C] [--device X] [--timeout N]`: same as the tool, but waits for the result.
144
152
  - `job status <id>`: reads a job.
145
153
  - `logs <jobId> [--tag T] [--limit N]`: same as the tool.
146
154
  - `check <jobId> [--log TAG[=TEXT]] [--element id=X|text=Y] [--name N] [--agent pass|fail]`: same as the tool, but waits.
@@ -149,20 +157,22 @@ Run them as `npx -y emd-agents@latest <command>`, or `node dist/bin.js <command>
149
157
  - `gc [--apply]`: lists, then removes, what EMD made for app folders that no longer exist.
150
158
  - `tap <jobId> --id X|--text Y|--x N --y N`, `type <jobId> <text>`, `swipe <jobId> up|down|left|right`: same as the tools.
151
159
  - `setup [--dry-run] [--yes] [--agent X]`: registers EMD with your agents and installs the skill.
152
- - `doctor`: checks that this Mac has what EMD needs (Node, macOS, Xcode, an iPhone simulator, AXe or Maestro) and says how to add what is missing.
160
+ - `doctor [dir]`: checks that this machine has what the app's platforms need (iOS: macOS, Xcode, an iPhone simulator, AXe or Maestro; Android: adb, an AVD, JDK 17), and says how to add what is missing.
153
161
  - `mcp`: starts the MCP server on stdio.
154
162
 
155
163
  ### Requirements in detail
156
164
 
157
165
  - An Expo app with `expo` in package.json. EMD reads its app config (app.json, app.config.js or app.config.ts) with the app's own `expo config`. Without `ios.bundleIdentifier`, Expo's build sets one and `launch` reports it (`appIdSet`).
158
166
  - The app's dependencies, installed. EMD does not install them.
159
- - macOS. On other systems `detect` works, and `launch` returns "iOS simulators need macOS."
167
+ - iOS: macOS. On other systems `detect` and Android work, and an iOS `launch` returns "iOS simulators need macOS."
160
168
  - Xcode, tested with Xcode 26 and 27. Expo SDK 58 apps need Xcode 26 or newer. Without Xcode, `launch` fails: "Could not set up this worktree's simulator and build folders."
161
169
  - An iOS simulator runtime and at least one shut-down iPhone simulator. EMD clones it once per app folder, as `emd-<key>`. Without one, `launch` fails: "No shut-down iPhone simulator is available to clone."
162
170
  - AXe or Maestro, for taps, typing, swipes and element checks. EMD tries AXe first, then Maestro.
163
171
  - AXe (about 40 times faster for checks, 60 for taps): `setup` installs it into `~/.emd/tools/`, from AXe's pinned release archive, checked by SHA-256. With Xcode 27, Device Hub must be running.
164
172
  - Maestro: `curl -fsSL "https://get.maestro.mobile.dev" | bash`. It needs Java 17 or newer, with `JAVA_HOME` set.
165
173
  - With neither, taps, typing and swipes fail, and a check with elements returns `error`. `launch`, `logs`, log checks and `evidence` still work.
174
+ - Android: the SDK's `platform-tools` and `emulator`, found through `ANDROID_HOME` (or `ANDROID_SDK_ROOT`). EMD runs an AVD read-only on its own port for each app folder, so it never changes the AVD. `device` names the AVD; the default is the first one `emulator -list-avds` prints.
175
+ - Android: JDK 17 or newer, in `JAVA_HOME` or on PATH, for Gradle. Screen reads and input use `uiautomator` and `input` through adb, with Maestro as the fallback.
166
176
 
167
177
  ### Install from source
168
178
 
@@ -174,11 +184,11 @@ npm run build
174
184
  node dist/bin.js detect fixtures/expo
175
185
  ```
176
186
 
177
- The last line must print `"verdict":"detected"` and `"appIds":{"ios":"com.emd.sandbox"}`. Then `node dist/bin.js setup` registers this clone's build with your agents.
187
+ The last line must print `"verdict":"detected"` and `"appIds":{"ios":"com.emd.sandbox","android":"com.emd.sandbox"}`. Then `node dist/bin.js setup` registers this clone's build with your agents.
178
188
 
179
189
  ### Clean up
180
190
 
181
- `gc` removes what EMD made for app folders that no longer exist, for example a deleted git worktree: the simulator clone and its `~/.emd/` folders. It removes only what EMD recorded as its own. For a folder that still exists, it removes nothing. It is a CLI command only, not an MCP tool.
191
+ `gc` removes what EMD made for app folders that no longer exist, for example a deleted git worktree: the simulator clone, its Android emulator and its `~/.emd/` folders. It removes only what EMD recorded as its own. For a folder that still exists, it removes nothing. It is a CLI command only, not an MCP tool.
182
192
 
183
193
  ```sh
184
194
  emd gc # dry run: lists what it would remove, and the size
@@ -31,6 +31,7 @@ const isPlatform = (value) => value === "ios" || value === "android";
31
31
  const nonEmpty = (value) => typeof value === "string" && value !== "" ? value : undefined;
32
32
  const adapter = {
33
33
  id: "expo",
34
+ launches: ["ios", "android"],
34
35
  async detect(dir, project) {
35
36
  const { config, error } = await readExpoConfig(dir);
36
37
  const declared = Array.isArray(config.platforms)
@@ -74,13 +75,24 @@ const adapter = {
74
75
  commands: { run, server: `${expo} start` },
75
76
  };
76
77
  },
77
- launchPlan(project, { platform, deviceId, port }) {
78
- if (platform !== "ios")
79
- return undefined;
78
+ async launchPlan(project, { platform, deviceId, port, abi }) {
80
79
  const expo = `${project.exec} expo`;
80
+ const server = `${expo} start --port ${port}`;
81
+ if (platform === "ios") {
82
+ return {
83
+ server,
84
+ build: `${expo} run:ios --device ${deviceId} --no-bundler`,
85
+ };
86
+ }
87
+ // The build `expo run:android` runs, without its device pick: the AVD
88
+ // name it matches by is the same for every worktree's emulator. Prebuild
89
+ // makes android/ when it is missing, as run:android does. Gradle bakes the
90
+ // dev server port into the debug build.
91
+ const abis = abi ? ` -PreactNativeArchitectures=${abi}` : "";
81
92
  return {
82
- server: `${expo} start --port ${port}`,
83
- build: `${expo} run:ios --device ${deviceId} --no-bundler`,
93
+ server,
94
+ build: `{ [ -d android ] || ${expo} prebuild --platform android --no-install; } && cd android && ./gradlew --console=plain app:assembleDebug -PreactNativeDevServerPort=${port}${abis}`,
95
+ output: join("android", "app", "build", "outputs", "apk", "debug"),
84
96
  };
85
97
  },
86
98
  fingerprint: expoFingerprint,
@@ -0,0 +1,3 @@
1
+ import type { StackAdapter } from "../../core/index.js";
2
+ declare const adapter: StackAdapter;
3
+ export default adapter;
@@ -0,0 +1,63 @@
1
+ import { access, readdir, readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ // The Android Gradle plugin's application plugin, by id or by a version
4
+ // catalog alias such as libs.plugins.android.application.
5
+ const appPlugin = /com\.android\.application|plugins\.android\.application/;
6
+ const buildFiles = ["build.gradle.kts", "build.gradle"];
7
+ // Folders that hold outputs or packages, never a module of the app.
8
+ const notModules = new Set(["build", "node_modules"]);
9
+ // The subfolders whose build file applies the app plugin.
10
+ async function appModules(dir) {
11
+ const subs = (await readdir(dir, { withFileTypes: true }))
12
+ .filter((e) => e.isDirectory() && !e.name.startsWith(".") && !notModules.has(e.name))
13
+ .map((e) => e.name);
14
+ const found = [];
15
+ for (const module of subs) {
16
+ for (const file of buildFiles) {
17
+ const text = await readFile(join(dir, module, file), "utf8").catch(() => "");
18
+ if (appPlugin.test(text)) {
19
+ found.push(module);
20
+ break;
21
+ }
22
+ }
23
+ }
24
+ return found;
25
+ }
26
+ const adapter = {
27
+ id: "gradle",
28
+ launches: ["android"],
29
+ // A Gradle build with no Android app module is not a mobile app.
30
+ async detect(dir) {
31
+ const modules = await appModules(dir);
32
+ if (modules.length === 0)
33
+ return undefined;
34
+ // No app ID: build types and flavors change it, so launch reads it after
35
+ // the build.
36
+ return {
37
+ stack: "gradle",
38
+ platforms: ["android"],
39
+ appIds: {},
40
+ notes: [`Android app module: ${modules.join(", ")}.`],
41
+ };
42
+ },
43
+ // The Gradle wrapper builds the debug APK of the one app module.
44
+ async launchPlan(_project, { dir, platform }) {
45
+ if (platform !== "android")
46
+ return undefined;
47
+ const modules = await appModules(dir);
48
+ if (modules.length > 1) {
49
+ return `This project has several Android app modules: ${modules.join(", ")}. EMD launches a project with one.`;
50
+ }
51
+ const [module] = modules;
52
+ if (!module)
53
+ return undefined;
54
+ if (!(await access(join(dir, "gradlew")).then(() => true, () => false))) {
55
+ return "This project has no Gradle wrapper (gradlew). Add one with `gradle wrapper`.";
56
+ }
57
+ return {
58
+ build: `./gradlew --console=plain :${module}:assembleDebug`,
59
+ output: join(module, "build", "outputs", "apk", "debug"),
60
+ };
61
+ },
62
+ };
63
+ export default adapter;
@@ -0,0 +1,16 @@
1
+ import { type StackAdapter } from "../../core/index.js";
2
+ type ListInfo = {
3
+ name?: string;
4
+ schemes?: string[];
5
+ };
6
+ export declare function pickScheme(list: {
7
+ project?: ListInfo;
8
+ workspace?: ListInfo;
9
+ }): {
10
+ scheme: string;
11
+ } | {
12
+ schemes: string[];
13
+ };
14
+ export declare function sharedSchemes(dir: string, container: string): Promise<Map<string, string>>;
15
+ declare const adapter: StackAdapter;
16
+ export default adapter;
@@ -0,0 +1,116 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { runTool, xcodeGenerators, } from "../../core/index.js";
4
+ // The scheme named like the project or workspace, else the only one. Several
5
+ // schemes and none named so: no guess, the caller says which exist.
6
+ export function pickScheme(list) {
7
+ const info = list.workspace ?? list.project ?? {};
8
+ const schemes = info.schemes ?? [];
9
+ const scheme = schemes.find((s) => s === info.name) ??
10
+ (schemes.length === 1 ? schemes[0] : undefined);
11
+ return scheme ? { scheme } : { schemes };
12
+ }
13
+ // A workspace wins over a project: it can hold the project and its pods.
14
+ async function xcodeProject(dir) {
15
+ const names = await readdir(dir);
16
+ return (names.find((n) => n.endsWith(".xcworkspace")) ??
17
+ names.find((n) => n.endsWith(".xcodeproj")));
18
+ }
19
+ const read = (path) => readFile(path, "utf8").catch(() => "");
20
+ // The shared schemes of a project or workspace, by name, with the
21
+ // configuration each one's Run action builds. A workspace adds the shared
22
+ // schemes of the projects it lists. Reading the files skips `xcodebuild
23
+ // -list`, which can take minutes on a large project.
24
+ export async function sharedSchemes(dir, container) {
25
+ const containers = [join(dir, container)];
26
+ if (container.endsWith(".xcworkspace")) {
27
+ const contents = await read(join(dir, container, "contents.xcworkspacedata"));
28
+ for (const [, kind, path = ""] of contents.matchAll(/location\s*=\s*"(group|container|absolute):([^"]+\.xcodeproj)"/g)) {
29
+ containers.push(kind === "absolute" ? path : join(dir, path));
30
+ }
31
+ }
32
+ const schemes = new Map();
33
+ for (const folder of containers) {
34
+ const schemeDir = join(folder, "xcshareddata", "xcschemes");
35
+ const files = await readdir(schemeDir).catch(() => []);
36
+ for (const file of files.filter((f) => f.endsWith(".xcscheme")).sort()) {
37
+ const xml = await read(join(schemeDir, file));
38
+ const config = xml.match(/<LaunchAction\b[^>]*\bbuildConfiguration\s*=\s*"([^"]+)"/)?.[1];
39
+ schemes.set(file.slice(0, -".xcscheme".length), config ?? "Debug");
40
+ }
41
+ }
42
+ return schemes;
43
+ }
44
+ // A long list costs the agent tokens: the first names, then a count.
45
+ const someOf = (names, shown = 15) => names.length > shown
46
+ ? `${names.slice(0, shown).join(", ")} and ${names.length - shown} more`
47
+ : names.join(", ");
48
+ const quote = (s) => `'${s.replaceAll("'", "'\\''")}'`;
49
+ const adapter = {
50
+ id: "xcode",
51
+ launches: ["ios"],
52
+ async detect(dir) {
53
+ const names = await readdir(dir);
54
+ const tool = xcodeGenerators
55
+ .map(([file, name]) => [names.find((n) => file.test(n)), name])
56
+ .find(([file]) => file);
57
+ const project = await xcodeProject(dir);
58
+ // No app ID: real apps set it through variables, xcconfig files and
59
+ // several targets, so launch reads it from the built app.
60
+ return {
61
+ stack: "xcode",
62
+ platforms: ["ios"],
63
+ appIds: {},
64
+ ...(tool && {
65
+ needsPrepare: `This project makes its Xcode project with ${tool[1]} (${tool[0]}). Pass prepare: the command that makes it, as the project's docs name it.`,
66
+ }),
67
+ ...(project && { notes: [`Xcode project: ${project}.`] }),
68
+ };
69
+ },
70
+ // No dev server: core installs the built app. Core's xcodebuild shim adds
71
+ // the worktree's DerivedData.
72
+ async launchPlan(_project, { dir, platform, deviceId, scheme, configuration }) {
73
+ if (platform !== "ios")
74
+ return undefined;
75
+ const project = await xcodeProject(dir);
76
+ if (!project)
77
+ return `${dir} has no Xcode project or workspace.`;
78
+ const kind = project.endsWith(".xcworkspace") ? "-workspace" : "-project";
79
+ const name = project.replace(/\.(xcworkspace|xcodeproj)$/, "");
80
+ // Shared scheme files first. Without any, Xcode makes a scheme per target,
81
+ // and only xcodebuild lists those.
82
+ let schemes = await sharedSchemes(dir, project);
83
+ if (schemes.size === 0) {
84
+ const { stdout } = await runTool("xcodebuild -list", "xcodebuild", ["-list", "-json", kind, join(dir, project)], 120);
85
+ const list = JSON.parse(stdout);
86
+ const info = list.workspace ?? list.project ?? {};
87
+ schemes = new Map((info.schemes ?? []).map((s) => [s, "Debug"]));
88
+ }
89
+ const names = [...schemes.keys()];
90
+ const picked = scheme
91
+ ? schemes.has(scheme)
92
+ ? { scheme }
93
+ : undefined
94
+ : pickScheme({ project: { name, schemes: names } });
95
+ if (!picked) {
96
+ return `${project} has no scheme named "${scheme}". Schemes: ${someOf(names)}.`;
97
+ }
98
+ if (!("scheme" in picked)) {
99
+ return `${project} has ${names.length} schemes and none is named like it: ${someOf(names)}. Pass scheme: the project's docs usually name the one to run.`;
100
+ }
101
+ return {
102
+ build: [
103
+ "xcodebuild",
104
+ kind,
105
+ quote(project),
106
+ "-scheme",
107
+ quote(picked.scheme),
108
+ "-configuration",
109
+ quote(configuration ?? schemes.get(picked.scheme) ?? "Debug"),
110
+ `-destination id=${deviceId}`,
111
+ "build",
112
+ ].join(" "),
113
+ };
114
+ },
115
+ };
116
+ export default adapter;
package/dist/cli/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createInterface } from "node:readline/promises";
2
2
  import { parseArgs } from "node:util";
3
3
  import { check, detect, doctor, evidence, gc, jobStatus, launchInline, logs, resetChecks, runJob, setup, swipe, tap, typeText, version, } from "../core/index.js";
4
- const usage = "Commands: detect [dir], launch [dir] [--device X] [--timeout N], job status <id>, logs <jobId> [--tag T] [--limit N], check <jobId> [--log TAG[=TEXT]] [--element id=X|text=Y] [--name N] [--agent pass|fail], check reset [dir], tap <jobId> --id X|--text Y|--x N --y N, type <jobId> [--] <text>, swipe <jobId> up|down|left|right, evidence <jobId>, gc [--apply], setup [--dry-run] [--yes] [--agent claude-code|codex|cursor], doctor, mcp";
4
+ const usage = "Commands: detect [dir], launch [dir] [--platform ios|android] [--prepare CMD] [--scheme S] [--configuration C] [--device X] [--timeout N], job status <id>, logs <jobId> [--tag T] [--limit N], check <jobId> [--log TAG[=TEXT]] [--element id=X|text=Y] [--name N] [--agent pass|fail], check reset [dir], tap <jobId> --id X|--text Y|--x N --y N, type <jobId> [--] <text>, swipe <jobId> up|down|left|right, evidence <jobId>, gc [--apply], setup [--dry-run] [--yes] [--agent claude-code|codex|cursor], doctor [dir], mcp";
5
5
  // --log smoke or --log smoke=tapped
6
6
  const logSpec = (raw) => {
7
7
  const at = raw.indexOf("=");
@@ -60,10 +60,21 @@ export async function run(argv) {
60
60
  args,
61
61
  allowPositionals: true,
62
62
  options: {
63
+ platform: { type: "string" },
64
+ prepare: { type: "string" },
65
+ scheme: { type: "string" },
66
+ configuration: { type: "string" },
63
67
  device: { type: "string" },
64
68
  timeout: { type: "string" },
65
69
  },
66
70
  });
71
+ const platform = values.platform;
72
+ if (platform !== undefined &&
73
+ platform !== "ios" &&
74
+ platform !== "android") {
75
+ console.error(`emd: --platform must be ios or android. ${usage}`);
76
+ return 2;
77
+ }
67
78
  const timeoutSeconds = values.timeout
68
79
  ? Number(values.timeout)
69
80
  : undefined;
@@ -73,6 +84,10 @@ export async function run(argv) {
73
84
  }
74
85
  const result = await launchInline({
75
86
  dir: positionals[0],
87
+ platform,
88
+ prepare: values.prepare,
89
+ scheme: values.scheme,
90
+ configuration: values.configuration,
76
91
  device: values.device,
77
92
  timeoutSeconds,
78
93
  });
@@ -214,7 +229,7 @@ export async function run(argv) {
214
229
  return failed ? 1 : 0;
215
230
  }
216
231
  case "doctor": {
217
- const result = await doctor();
232
+ const result = await doctor({ dir: args[0] });
218
233
  console.log(JSON.stringify(result));
219
234
  return result.verdict === "ready" ? 0 : 1;
220
235
  }
@@ -1,4 +1,4 @@
1
- export declare const stackIds: readonly ["expo"];
1
+ export declare const stackIds: readonly ["expo", "xcode", "gradle"];
2
2
  export declare const platforms: readonly ["ios", "android"];
3
3
  export declare const packageManagers: readonly ["npm", "yarn", "pnpm", "bun"];
4
4
  export type StackId = (typeof stackIds)[number];
@@ -13,23 +13,30 @@ export type StackDetection = {
13
13
  platforms: Platform[];
14
14
  appIds: Partial<Record<Platform, string>>;
15
15
  problem?: string;
16
+ needsPrepare?: string;
16
17
  notes?: string[];
17
- commands: {
18
+ commands?: {
18
19
  run: Partial<Record<Platform, string>>;
19
20
  server: string;
20
21
  };
21
22
  };
22
23
  export type LaunchPlan = {
23
- server: string;
24
+ server?: string;
24
25
  build: string;
26
+ output?: string;
25
27
  };
26
28
  export interface StackAdapter {
27
29
  id: StackId;
30
+ launches: Platform[];
28
31
  detect(projectDir: string, project: ProjectInfo): Promise<StackDetection | undefined>;
29
32
  launchPlan(project: ProjectInfo, request: {
33
+ dir: string;
30
34
  platform: Platform;
31
35
  deviceId: string;
32
36
  port: number;
33
- }): LaunchPlan | undefined;
34
- fingerprint(projectDir: string, platform: Platform): Promise<string>;
37
+ abi?: string;
38
+ scheme?: string;
39
+ configuration?: string;
40
+ }): Promise<LaunchPlan | string | undefined>;
41
+ fingerprint?(projectDir: string, platform: Platform): Promise<string>;
35
42
  }
@@ -1,3 +1,3 @@
1
- export const stackIds = ["expo"];
1
+ export const stackIds = ["expo", "xcode", "gradle"];
2
2
  export const platforms = ["ios", "android"];
3
3
  export const packageManagers = ["npm", "yarn", "pnpm", "bun"];
@@ -6,3 +6,8 @@ export declare function readBuildRecord(derivedData: string): BuildRecord | unde
6
6
  export declare function writeBuildRecord(derivedData: string, record: BuildRecord): void;
7
7
  export declare function whyBuild(record: BuildRecord | undefined, now: BuildRecord, installed: boolean): string | undefined;
8
8
  export declare function builtApp(derivedData: string): string | undefined;
9
+ export declare function builtApk(dir: string): {
10
+ apk: string;
11
+ appId: string;
12
+ };
13
+ export declare function builtAppId(derivedData: string): Promise<string | undefined>;
@@ -1,5 +1,6 @@
1
1
  import { readdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
+ import { plistValue } from "./tool.js";
3
4
  const file = (derivedData) => join(derivedData, "emd-build.json");
4
5
  export function readBuildRecord(derivedData) {
5
6
  try {
@@ -43,3 +44,24 @@ export function builtApp(derivedData) {
43
44
  throw error;
44
45
  }
45
46
  }
47
+ // The APK in an Android build's output folder and its app ID. The Android Gradle
48
+ // plugin writes both to output-metadata.json next to the APK, after build types
49
+ // and flavors changed the ID, so no SDK tool has to read the APK.
50
+ export function builtApk(dir) {
51
+ const path = join(dir, "output-metadata.json");
52
+ const metadata = JSON.parse(readFileSync(path, "utf8"));
53
+ const files = (metadata.elements ?? []).flatMap((e) => e.outputFile ? [e.outputFile] : []);
54
+ const [file] = files;
55
+ if (!metadata.applicationId || !file || files.length > 1) {
56
+ throw new Error(`${path} must name one APK and its applicationId; it names ${files.length} APKs.`);
57
+ }
58
+ return { apk: join(dir, file), appId: metadata.applicationId };
59
+ }
60
+ // The built app's own ID (CFBundleIdentifier), whatever set it: the app config,
61
+ // build settings or an xcconfig file.
62
+ export async function builtAppId(derivedData) {
63
+ const app = builtApp(derivedData);
64
+ if (!app)
65
+ return undefined;
66
+ return ((await plistValue(join(app, "Info.plist"), "CFBundleIdentifier").catch(() => "")) || undefined);
67
+ }
@@ -1,3 +1,4 @@
1
+ import type { Platform } from "./adapter.js";
1
2
  import { type LogSpec } from "./checkrecord.js";
2
3
  import { type ScreenRead } from "./device/backend.js";
3
4
  import { type ElementSpec } from "./device/screen.js";
@@ -21,9 +22,10 @@ type CheckAction = {
21
22
  };
22
23
  export type Deps = {
23
24
  logs: (options: Omit<LogsOptions, "limit">) => Promise<LogsResult>;
24
- screen: (device: string) => Promise<ScreenRead>;
25
- screenshot: (device: string, path: string) => Promise<string | undefined>;
25
+ screen: (device: string, platform: Platform) => Promise<ScreenRead>;
26
+ screenshot: (device: string, path: string, platform: Platform) => Promise<string | undefined>;
26
27
  recheckSeconds: number;
28
+ logGraceSeconds: number;
27
29
  evidence: (ref: RunRef) => Promise<EvidenceResult>;
28
30
  act: (action: CheckAction, ref: RunRef) => Promise<InputResult>;
29
31
  };