emd-agents 0.16.1 → 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 (53) 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 +2 -2
  17. package/dist/core/device/backend.js +36 -9
  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/simulator.js +5 -1
  49. package/dist/core/tool.d.ts +1 -0
  50. package/dist/core/tool.js +5 -0
  51. package/dist/mcp/server.js +21 -5
  52. package/package.json +2 -2
  53. package/skills/emd/SKILL.md +8 -3
package/dist/core/logs.js CHANGED
@@ -3,10 +3,10 @@ import { join } from "node:path";
3
3
  import { launchesIn } from "./jobstore.js";
4
4
  import { startLogged } from "./process.js";
5
5
  import { resolveRun } from "./run.js";
6
- import { runTool } from "./tool.js";
6
+ import { plistValue, runTool } from "./tool.js";
7
7
  // A tagged line is any log message with `[EMD:<tag>]` in it. The app writes it
8
- // with console.log (or NSLog); the simulator keeps it in its unified log at
9
- // Info level, so `log stream` needs --info to see it.
8
+ // with console.log, NSLog or Log.i; the simulator keeps it in its unified log
9
+ // at Info level, so `log stream` needs --info to see it.
10
10
  const taggedLine = /\[EMD:([A-Za-z0-9_.-]+)\]\s?(.*)$/s;
11
11
  export const tagPattern = /^[A-Za-z0-9_.-]{1,40}$/;
12
12
  const executable = /^[A-Za-z0-9_. -]+$/;
@@ -47,6 +47,25 @@ export function parseTagged(ndjson, tag) {
47
47
  }
48
48
  return lines;
49
49
  }
50
+ // `adb logcat -v epoch`: seconds.millis, pid, tid, priority, tag, then ": " and
51
+ // the message.
52
+ const logcatLine = /^\s*(\d+\.\d+)\s+\d+\s+\d+\s+[A-Z]\s+.*?: (.*)$/;
53
+ // Tagged lines from `adb logcat -v epoch` output, oldest first.
54
+ export function parseLogcat(text, tag) {
55
+ const lines = [];
56
+ for (const raw of text.split("\n")) {
57
+ const line = raw.match(logcatLine);
58
+ const match = line?.[2]?.match(taggedLine);
59
+ if (!line || !match?.[1] || (tag && match[1] !== tag))
60
+ continue;
61
+ lines.push({
62
+ time: new Date(Number(line[1]) * 1000).toISOString(),
63
+ tag: match[1],
64
+ message: match[2] ?? "",
65
+ });
66
+ }
67
+ return lines;
68
+ }
50
69
  // simctl can fail to answer for a while after a boot, even after bootstatus:
51
70
  // in the #14 pilot, a reused build fell back to a 194 s rebuild. So a few short
52
71
  // tries, 2 s apart, as other simulator tools retry such calls.
@@ -64,17 +83,10 @@ async function appExecutable(device, appId) {
64
83
  }
65
84
  async function readExecutable(device, appId) {
66
85
  const { stdout } = await runTool("simctl get_app_container", "xcrun", ["simctl", "get_app_container", device, appId], 20);
67
- const { stdout: name } = await runTool("plutil", "plutil", [
68
- "-extract",
69
- "CFBundleExecutable",
70
- "raw",
71
- "-o",
72
- "-",
73
- `${stdout.trim()}/Info.plist`,
74
- ], 30);
75
- return name.trim();
86
+ return plistValue(`${stdout.trim()}/Info.plist`, "CFBundleExecutable");
76
87
  }
77
- const capturePath = (logDir) => join(logDir, "app.ndjson");
88
+ // Where a run's captured log is: the simulator's ndjson stream or logcat's.
89
+ const capturePath = (logDir, platform = "ios") => join(logDir, platform === "android" ? "app.logcat" : "app.ndjson");
78
90
  // Info lines live only in the simulator's memory buffers and are purged as
79
91
  // they fill, so reading them after the fact can miss lines the app wrote
80
92
  // earlier in the run. The stream starts before the app does and writes to the
@@ -94,7 +106,7 @@ export async function stopCaptures(root) {
94
106
  continue;
95
107
  try {
96
108
  const { stdout } = await runTool("ps", "ps", ["-o", "command=", "-p", `${pid}`], 60);
97
- if (stdout.includes("log stream"))
109
+ if (/log stream|logcat/.test(stdout))
98
110
  process.kill(-pid, "SIGTERM");
99
111
  }
100
112
  catch { }
@@ -112,11 +124,14 @@ export async function allLines(options) {
112
124
  const resolved = resolveRun(options);
113
125
  if ("reason" in resolved)
114
126
  return failed(resolved.reason);
115
- const { since, logDir } = resolved.run;
116
- const file = capturePath(logDir);
127
+ const { since, logDir, platform } = resolved.run;
128
+ const file = capturePath(logDir, platform);
117
129
  if (!existsSync(file))
118
130
  return failed("This run has no captured log.");
119
- const lines = parseTagged(readFileSync(file, "utf8"), options.tag);
131
+ const text = readFileSync(file, "utf8");
132
+ const lines = platform === "android"
133
+ ? parseLogcat(text, options.tag)
134
+ : parseTagged(text, options.tag);
120
135
  return {
121
136
  verdict: "ok",
122
137
  since: since.toISOString(),
@@ -1,4 +1,4 @@
1
- export type Kind = "simulator" | "derivedData" | "port";
1
+ export type Kind = "simulator" | "derivedData" | "port" | "emulator";
2
2
  export type Entry = {
3
3
  kind: Kind;
4
4
  id: string;
@@ -1,2 +1,3 @@
1
1
  import type { StackId } from "./adapter.js";
2
+ export declare const xcodeGenerators: [file: RegExp, tool: string][];
2
3
  export declare function probeStack(dir: string): Promise<StackId | undefined>;
@@ -1,14 +1,28 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { readdir, readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ // Tools that generate or replace the Xcode project. The xcode adapter names
4
+ // the one it finds as the reason launch stops.
5
+ export const xcodeGenerators = [
6
+ [/^Project\.swift$/, "Tuist"],
7
+ [/^project\.yml$/, "XcodeGen"],
8
+ [/^(MODULE\.bazel|WORKSPACE(\.bazel)?)$/, "Bazel"],
9
+ ];
10
+ const xcodeProject = /\.(xcworkspace|xcodeproj)$/;
11
+ const gradleSettings = /^settings\.gradle(\.kts)?$/;
3
12
  // Cheap file probe that decides which adapter to load. No adapter code runs here.
13
+ // Expo comes first: its ios/ and android/ folders hold Xcode and Gradle files
14
+ // that do not make the app native. Native markers count only in the root folder.
4
15
  export async function probeStack(dir) {
5
- let pkg;
6
16
  try {
7
- pkg = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
17
+ const pkg = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
18
+ if ("expo" in { ...pkg.dependencies, ...pkg.devDependencies }) {
19
+ return "expo";
20
+ }
8
21
  }
9
- catch {
10
- return undefined;
11
- }
12
- const deps = { ...pkg.dependencies, ...pkg.devDependencies };
13
- return "expo" in deps ? "expo" : undefined;
22
+ catch { }
23
+ const names = await readdir(dir).catch(() => []);
24
+ const marker = (n) => xcodeProject.test(n) || xcodeGenerators.some(([file]) => file.test(n));
25
+ if (names.some(marker))
26
+ return "xcode";
27
+ return names.some((n) => gradleSettings.test(n)) ? "gradle" : undefined;
14
28
  }
@@ -8,3 +8,4 @@ export declare function startLogged(command: string, options: {
8
8
  logPath: string;
9
9
  env?: NodeJS.ProcessEnv;
10
10
  }): LoggedProcess;
11
+ export declare function untilExitOrIdle(exited: Promise<number>, logPath: string, idleSeconds: number, totalSeconds: number): Promise<number | "idle" | "timeout">;
@@ -1,5 +1,5 @@
1
1
  import { spawn } from "node:child_process";
2
- import { closeSync, mkdirSync, openSync } from "node:fs";
2
+ import { closeSync, mkdirSync, openSync, statSync } from "node:fs";
3
3
  import { dirname } from "node:path";
4
4
  // Runs a shell command in its own process group with stdout and stderr in a
5
5
  // log file, so it can outlive this process (a dev server) and be stopped whole.
@@ -30,3 +30,32 @@ export function startLogged(command, options) {
30
30
  },
31
31
  };
32
32
  }
33
+ // Resolves with the exit code; "idle" when the log has not grown for
34
+ // idleSeconds, so the process looks hung; or "timeout" after totalSeconds. A
35
+ // process that still writes its log is not stopped for being slow (decision 0014).
36
+ export async function untilExitOrIdle(exited, logPath, idleSeconds, totalSeconds) {
37
+ const started = Date.now();
38
+ let size;
39
+ let grew = started;
40
+ let timer;
41
+ const stopped = new Promise((resolve) => {
42
+ timer = setInterval(() => {
43
+ const now = Date.now();
44
+ const current = statSync(logPath, { throwIfNoEntry: false })?.size;
45
+ if (current !== size) {
46
+ size = current;
47
+ grew = now;
48
+ }
49
+ if (now - started >= totalSeconds * 1000)
50
+ resolve("timeout");
51
+ else if (now - grew >= idleSeconds * 1000)
52
+ resolve("idle");
53
+ }, 1000);
54
+ });
55
+ try {
56
+ return await Promise.race([exited, stopped]);
57
+ }
58
+ finally {
59
+ clearInterval(timer);
60
+ }
61
+ }
@@ -1,6 +1,8 @@
1
1
  // The only place that may import an adapter, and only dynamically (decision 0001).
2
2
  const loaders = {
3
3
  expo: () => import("../adapters/expo/index.js"),
4
+ xcode: () => import("../adapters/xcode/index.js"),
5
+ gradle: () => import("../adapters/gradle/index.js"),
4
6
  };
5
7
  const loaded = new Set();
6
8
  export async function loadAdapter(id) {
@@ -3,5 +3,5 @@ import type { Device } from "./simulator.js";
3
3
  export declare function sendReload(port: number): Promise<void>;
4
4
  export declare function runningPid(device: Device, appId: string): Promise<number | undefined>;
5
5
  export declare const earlierLaunch: (root: string, port: number, listening: number[]) => LaunchResult | undefined;
6
- export declare function untilBundled(logDir: string, before: number, seconds: number): Promise<boolean>;
6
+ export declare function untilBundled(logDir: string, before: number, seconds: number, failedBefore?: number): Promise<"bundled" | "failed" | "timeout">;
7
7
  export declare const bundlesServed: (logDir: string) => Promise<number>;
@@ -46,23 +46,30 @@ export const earlierLaunch = (root, port, listening) =>
46
46
  // Reloads share one dev server, so the newest run (its folder name starts
47
47
  // with its start time) is the one whose log window is open.
48
48
  launchesIn(root)
49
- .filter(({ verdict, metro, device, logDir }) => verdict === "launched" &&
49
+ .filter(({ verdict, platform, metro, device, logDir }) => verdict === "launched" &&
50
+ (platform ?? "ios") === "ios" &&
50
51
  metro?.port === port &&
51
52
  listening.includes(metro.pid) &&
52
53
  device &&
53
54
  logDir)
54
55
  .sort((a, b) => basename(b.logDir ?? "").localeCompare(basename(a.logDir ?? "")))[0];
55
56
  const bundled = /Bundled \d+ms/g;
56
- const count = async (path) => ((await readFile(path, "utf8").catch(() => "")).match(bundled) ?? []).length;
57
- // Resolves when the dev server log shows a bundle served after `before` bundles.
58
- export async function untilBundled(logDir, before, seconds) {
57
+ const bundleFailed = /Bundling failed/g;
58
+ const read = (path) => readFile(path, "utf8").catch(() => "");
59
+ const count = async (path) => ((await read(path)).match(bundled) ?? []).length;
60
+ // Resolves when the dev server log shows a bundle served after `before`
61
+ // bundles, or a bundle that failed to build after `failedBefore` failures.
62
+ export async function untilBundled(logDir, before, seconds, failedBefore = Number.POSITIVE_INFINITY) {
59
63
  const path = join(logDir, "metro.log");
60
64
  const deadline = Date.now() + seconds * 1000;
61
65
  while (Date.now() < deadline) {
62
- if ((await count(path)) > before)
63
- return true;
66
+ const text = await read(path);
67
+ if ((text.match(bundled) ?? []).length > before)
68
+ return "bundled";
69
+ if ((text.match(bundleFailed) ?? []).length > failedBefore)
70
+ return "failed";
64
71
  await new Promise((resolve) => setTimeout(resolve, 500));
65
72
  }
66
- return false;
73
+ return "timeout";
67
74
  }
68
75
  export const bundlesServed = (logDir) => count(join(logDir, "metro.log"));
@@ -7,6 +7,8 @@ export declare const detectResultSchema: z.ZodObject<{
7
7
  root: z.ZodString;
8
8
  stack: z.ZodOptional<z.ZodEnum<{
9
9
  expo: "expo";
10
+ xcode: "xcode";
11
+ gradle: "gradle";
10
12
  }>>;
11
13
  platforms: z.ZodOptional<z.ZodArray<z.ZodEnum<{
12
14
  ios: "ios";
@@ -17,6 +19,7 @@ export declare const detectResultSchema: z.ZodObject<{
17
19
  android: z.ZodOptional<z.ZodString>;
18
20
  }, z.core.$strip>>;
19
21
  problem: z.ZodOptional<z.ZodString>;
22
+ needsPrepare: z.ZodOptional<z.ZodString>;
20
23
  commands: z.ZodOptional<z.ZodObject<{
21
24
  run: z.ZodObject<{
22
25
  ios: z.ZodOptional<z.ZodString>;
@@ -44,6 +47,11 @@ export declare const launchResultSchema: z.ZodObject<{
44
47
  root: z.ZodString;
45
48
  reason: z.ZodOptional<z.ZodString>;
46
49
  errors: z.ZodOptional<z.ZodArray<z.ZodString>>;
50
+ lastLines: z.ZodOptional<z.ZodArray<z.ZodString>>;
51
+ platform: z.ZodOptional<z.ZodEnum<{
52
+ ios: "ios";
53
+ android: "android";
54
+ }>>;
47
55
  device: z.ZodOptional<z.ZodObject<{
48
56
  id: z.ZodString;
49
57
  name: z.ZodString;
@@ -91,11 +99,13 @@ export declare const inputResultSchema: z.ZodObject<{
91
99
  }>;
92
100
  reason: z.ZodOptional<z.ZodString>;
93
101
  backend: z.ZodOptional<z.ZodEnum<{
102
+ adb: "adb";
94
103
  axe: "axe";
95
104
  maestro: "maestro";
96
105
  }>>;
97
106
  fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
98
107
  backend: z.ZodEnum<{
108
+ adb: "adb";
99
109
  axe: "axe";
100
110
  maestro: "maestro";
101
111
  }>;
@@ -129,11 +139,13 @@ export declare const checkResultSchema: z.ZodObject<{
129
139
  found: z.ZodBoolean;
130
140
  }, z.core.$strip>>>;
131
141
  backend: z.ZodOptional<z.ZodEnum<{
142
+ adb: "adb";
132
143
  axe: "axe";
133
144
  maestro: "maestro";
134
145
  }>>;
135
146
  fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
136
147
  backend: z.ZodEnum<{
148
+ adb: "adb";
137
149
  axe: "axe";
138
150
  maestro: "maestro";
139
151
  }>;
@@ -157,11 +169,13 @@ export declare const checkResultSchema: z.ZodObject<{
157
169
  }>;
158
170
  reason: z.ZodOptional<z.ZodString>;
159
171
  backend: z.ZodOptional<z.ZodEnum<{
172
+ adb: "adb";
160
173
  axe: "axe";
161
174
  maestro: "maestro";
162
175
  }>>;
163
176
  fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
164
177
  backend: z.ZodEnum<{
178
+ adb: "adb";
165
179
  axe: "axe";
166
180
  maestro: "maestro";
167
181
  }>;
@@ -211,6 +225,11 @@ export declare const jobViewSchema: z.ZodObject<{
211
225
  root: z.ZodString;
212
226
  reason: z.ZodOptional<z.ZodString>;
213
227
  errors: z.ZodOptional<z.ZodArray<z.ZodString>>;
228
+ lastLines: z.ZodOptional<z.ZodArray<z.ZodString>>;
229
+ platform: z.ZodOptional<z.ZodEnum<{
230
+ ios: "ios";
231
+ android: "android";
232
+ }>>;
214
233
  device: z.ZodOptional<z.ZodObject<{
215
234
  id: z.ZodString;
216
235
  name: z.ZodString;
@@ -272,11 +291,13 @@ export declare const jobViewSchema: z.ZodObject<{
272
291
  found: z.ZodBoolean;
273
292
  }, z.core.$strip>>>;
274
293
  backend: z.ZodOptional<z.ZodEnum<{
294
+ adb: "adb";
275
295
  axe: "axe";
276
296
  maestro: "maestro";
277
297
  }>>;
278
298
  fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
279
299
  backend: z.ZodEnum<{
300
+ adb: "adb";
280
301
  axe: "axe";
281
302
  maestro: "maestro";
282
303
  }>;
@@ -300,11 +321,13 @@ export declare const jobViewSchema: z.ZodObject<{
300
321
  }>;
301
322
  reason: z.ZodOptional<z.ZodString>;
302
323
  backend: z.ZodOptional<z.ZodEnum<{
324
+ adb: "adb";
303
325
  axe: "axe";
304
326
  maestro: "maestro";
305
327
  }>>;
306
328
  fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
307
329
  backend: z.ZodEnum<{
330
+ adb: "adb";
308
331
  axe: "axe";
309
332
  maestro: "maestro";
310
333
  }>;
@@ -16,6 +16,7 @@ export const detectResultSchema = z.object({
16
16
  // dependencies are not installed), or an ios/ folder exists with no iOS app ID
17
17
  // in the config.
18
18
  problem: z.string().optional(),
19
+ needsPrepare: z.string().optional(),
19
20
  commands: z.object({ run: perPlatform, server: z.string() }).optional(),
20
21
  packageManager: z.enum(packageManagers).optional(),
21
22
  maestroFlows: z.array(z.string()).optional(),
@@ -31,6 +32,12 @@ export const launchResultSchema = z.object({
31
32
  reason: z.string().optional(),
32
33
  // First relevant error lines from the build or server log.
33
34
  errors: z.array(z.string()).optional(),
35
+ // The build log's last lines, when a build was stopped for time and no line
36
+ // looked like an error. Progress, not errors.
37
+ lastLines: z.array(z.string()).optional(),
38
+ // The platform and device this launch used: a simulator UDID and name, or an
39
+ // emulator serial and its AVD.
40
+ platform: z.enum(platforms).optional(),
34
41
  device: z.object({ id: z.string(), name: z.string() }).optional(),
35
42
  appId: z.string().optional(),
36
43
  appPid: z.number().optional(),
@@ -1,7 +1,9 @@
1
+ import type { Platform } from "./adapter.js";
1
2
  export type RunRef = {
2
3
  jobId: string;
3
4
  };
4
5
  export type Run = {
6
+ platform: Platform;
5
7
  device: string;
6
8
  appId: string;
7
9
  since: Date;
package/dist/core/run.js CHANGED
@@ -12,6 +12,8 @@ export function resolveRun({ jobId, }) {
12
12
  }
13
13
  return {
14
14
  run: {
15
+ // Launches before Android support carry no platform.
16
+ platform: result.platform ?? "ios",
15
17
  device: result.device.id,
16
18
  appId: result.appId,
17
19
  since: new Date(job.startedAt),
@@ -18,6 +18,7 @@ export type SetupResult = {
18
18
  };
19
19
  export type SetupOptions = {
20
20
  apply?: boolean;
21
+ dir?: string;
21
22
  only?: string[];
22
23
  };
23
24
  export type SetupDeps = {
@@ -3,6 +3,7 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync,
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join, sep } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
+ import { detect } from "./detect.js";
6
7
  import { axeDir, axePin } from "./device/axe.js";
7
8
  import { detectEnvironment } from "./device/backend.js";
8
9
  import { doctor } from "./doctor.js";
@@ -137,8 +138,13 @@ export async function setup(options = {}, deps = realDeps) {
137
138
  };
138
139
  }
139
140
  const steps = commands(picked.map((a) => a.id));
140
- // Every supported stack on macOS is iOS today, so a Mac gets AXe.
141
- const axe = deps.platform === "darwin" && !(await detectEnvironment()).axe
141
+ // AXe is for iOS: a Mac gets it unless the project here targets only
142
+ // Android, which needs nothing installed (adb comes with the SDK).
143
+ const detected = await detect(options.dir).catch(() => undefined);
144
+ const iosOff = detected?.verdict === "detected" &&
145
+ detected.platforms !== undefined &&
146
+ !detected.platforms.includes("ios");
147
+ const axe = deps.platform === "darwin" && !iosOff && !(await detectEnvironment()).axe
142
148
  ? { ...deps.axe, dir: axeDir() }
143
149
  : undefined;
144
150
  const plan = {
@@ -210,6 +216,6 @@ export async function setup(options = {}, deps = realDeps) {
210
216
  ...plan,
211
217
  agents: withBackups,
212
218
  restart: listed.map((a) => a.id),
213
- doctor: await doctor(),
219
+ doctor: await doctor({ dir: options.dir }),
214
220
  };
215
221
  }
@@ -116,7 +116,11 @@ export async function enableAppAccessibility(device) {
116
116
  // text to the screen while `type` waits for its keys, and corrections change
117
117
  // the typed text.
118
118
  export async function plainKeyboard(device) {
119
- await Promise.all(["KeyboardPrediction", "KeyboardAutocorrection"].map((key) => writeBool(device, "com.apple.Preferences", key, false)));
119
+ await Promise.all(
120
+ // iOS 26 reads them from com.apple.keyboard.preferences: written only to
121
+ // com.apple.Preferences, the bar still showed in 40 of 40 typing attempts,
122
+ // and 0 of 20 with both (experiments/input-probe.md).
123
+ ["com.apple.Preferences", "com.apple.keyboard.preferences"].flatMap((domain) => ["KeyboardPrediction", "KeyboardAutocorrection"].map((key) => writeBool(device, domain, key, false))));
120
124
  }
121
125
  // Stops the app if it runs; a later launch then starts it fresh. Not running is
122
126
  // not a failure.
@@ -3,3 +3,4 @@ export declare function runTool(step: string, file: string, args: string[], seco
3
3
  }): Promise<{
4
4
  stdout: string;
5
5
  }>;
6
+ export declare function plistValue(path: string, key: string): Promise<string>;
package/dist/core/tool.js CHANGED
@@ -52,3 +52,8 @@ export function runTool(step, file, args, seconds, options = {}) {
52
52
  });
53
53
  });
54
54
  }
55
+ // One value of a property list (an app's Info.plist), as text. macOS only.
56
+ export async function plistValue(path, key) {
57
+ const { stdout } = await runTool("plutil", "plutil", ["-extract", key, "raw", "-o", "-", path], 30);
58
+ return stdout.trim();
59
+ }
@@ -1,7 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/server";
2
2
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
3
3
  import { z } from "zod";
4
- import { detect, detectResultSchema, directions, evidence, evidenceResultSchema, inputResultSchema, jobStatus, jobViewSchema, logs, logsResultSchema, startJob, swipe, tap, typeText, version, waitForJob, } from "../core/index.js";
4
+ import { detect, detectResultSchema, directions, evidence, evidenceResultSchema, inputResultSchema, jobStatus, jobViewSchema, logs, logsResultSchema, platforms, startJob, swipe, tap, typeText, version, waitForJob, } from "../core/index.js";
5
5
  // Fast work returns its result in the same call, so the agent needs no
6
6
  // job_status call (#207). 25 s keeps a 2x margin under a 60 s client timeout.
7
7
  const waitSeconds = z
@@ -112,21 +112,37 @@ function buildServer() {
112
112
  };
113
113
  });
114
114
  server.registerTool("launch", {
115
- description: "Build the app, install it on an iOS simulator and launch it, leaving its dev server running. Waits up to waitSeconds (default 25, or longer where setup allowed it): a relaunch or reload often ends in time and returns its result. A build takes minutes: then it returns the job, and you call job_status with the jobId until status is succeeded or failed.",
115
+ description: "Build the app, install it on an iOS simulator or Android emulator and launch it, leaving its dev server running when the app has one (Expo). Android: Expo apps and native Gradle apps. Waits up to waitSeconds (default 25, or longer where setup allowed it): a relaunch or reload often ends in time and returns its result. A build takes minutes: then it returns the job, and you call job_status with the jobId until status is succeeded or failed.",
116
116
  inputSchema: z.object({
117
117
  dir: z
118
118
  .string()
119
119
  .optional()
120
120
  .describe("Project directory. Defaults to the server's working directory."),
121
+ platform: z
122
+ .enum(platforms)
123
+ .optional()
124
+ .describe("Default: ios when the project targets iOS, else android."),
125
+ prepare: z
126
+ .string()
127
+ .optional()
128
+ .describe("A command run in the project folder first, such as `make`, when a setup step makes the native project (XcodeGen, Tuist, Bazel). detect says when it is needed; the project's docs name it."),
129
+ scheme: z
130
+ .string()
131
+ .optional()
132
+ .describe("iOS: the scheme to build. Default: the one named like the project, or the only one."),
133
+ configuration: z
134
+ .string()
135
+ .optional()
136
+ .describe("iOS: the build configuration. Default: the one the scheme's Run action uses."),
121
137
  device: z
122
138
  .string()
123
139
  .optional()
124
- .describe("Simulator name or UDID. Default: a booted iPhone, else the newest iPhone."),
140
+ .describe("iOS: the simulator to clone, by name or UDID. Default: the newest shut-down iPhone. Android: the AVD to run. Default: the first one."),
125
141
  timeoutSeconds: z
126
142
  .number()
127
143
  .positive()
128
144
  .optional()
129
- .describe("How long the build may take. Default 900."),
145
+ .describe("How long the build may take in total. Default 3600. A build whose log stops growing for 600 s stops sooner."),
130
146
  waitSeconds,
131
147
  }),
132
148
  outputSchema: jobViewSchema,
@@ -185,7 +201,7 @@ function buildServer() {
185
201
  };
186
202
  });
187
203
  server.registerTool("check", {
188
- description: "Check a run against what you expect, from signals a machine can read, not your own judgment: tagged log events the app wrote ([EMD:<tag>] lines) and elements on the simulator's screen (by testID or by text). Give the taps, typing and swipes that lead to the moment as actions, or check right after them; a check reads again for up to 10 s what is still missing. Waits up to waitSeconds (default 25, or longer where setup allowed it) and returns the finished result when the check ends in time; otherwise returns the job: call job_status until it finishes. The result's verdict is passed, failed (fix the cause and check again), stopped (the retry limit is reached: stop and report what is missing) or error (the check could not run; not counted). Your reading of the returned screenshot may be passed as agentReading; it is recorded as a second opinion and never changes the verdict. Each check rewrites the run's evidence folder and returns its path (evidenceDir) and the check names whose last verdict is not passed (notPassed).",
204
+ description: "Check a run against what you expect, from signals a machine can read, not your own judgment: tagged log events the app wrote ([EMD:<tag>] lines) and elements on the device's screen (by testID or by text; on Android a resource-id, or a Compose test tag with testTagsAsResourceId). Give the taps, typing and swipes that lead to the moment as actions, or check right after them; a check reads again for up to 10 s what is still missing, and the log up to 5 s longer once the expected elements show. Waits up to waitSeconds (default 25, or longer where setup allowed it) and returns the finished result when the check ends in time; otherwise returns the job: call job_status until it finishes. The result's verdict is passed, failed (fix the cause and check again), stopped (the retry limit is reached: stop and report what is missing) or error (the check could not run; not counted). Your reading of the returned screenshot may be passed as agentReading; it is recorded as a second opinion and never changes the verdict. Each check rewrites the run's evidence folder and returns its path (evidenceDir) and the check names whose last verdict is not passed (notPassed).",
189
205
  inputSchema: z.object({
190
206
  jobId: z.string().describe("The launch job whose run to check."),
191
207
  logs: z
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emd-agents",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "description": "Build, run, check and prove mobile changes from any coding agent.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "typecheck": "tsc --noEmit",
28
28
  "test": "npm run build && vitest run",
29
29
  "test:fast": "npm run build && vitest run",
30
- "test:e2e": "npm run build && EMD_E2E_SANDBOX=${EMD_E2E_SANDBOX:-$PWD/fixtures/expo} vitest run test/e2e",
30
+ "test:e2e": "npm run build && EMD_E2E_SANDBOX=${EMD_E2E_SANDBOX:-$PWD/fixtures/expo} vitest run test/e2e --no-file-parallelism",
31
31
  "check:sizes": "node --experimental-strip-types scripts/check-doc-sizes.ts",
32
32
  "check:imports": "node --experimental-strip-types scripts/check-imports.ts",
33
33
  "check:pr-title": "commitlint",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: emd
3
- description: Build, run and check a change to a mobile app (Expo on the iOS simulator today) with EMD's MCP tools, and prove it with screenshots and log lines. Use when a task changes a mobile app and the result must be seen on a simulator.
3
+ description: Build, run and check a change to a mobile app (Expo or native iOS apps on the iOS simulator, native Android apps on an emulator) with EMD's MCP tools, and prove it with screenshots and log lines. Use when a task changes a mobile app and the result must be seen on a simulator or emulator.
4
4
  ---
5
5
 
6
6
  # EMD
@@ -14,11 +14,16 @@ Run `npx -y emd-agents@latest setup --dry-run` and show the user its plan. Run i
14
14
  ## Before you change code
15
15
 
16
16
  1. Call `detect` with the app folder. At a workspace root it lists the app folders (`apps`): call it again with one of them.
17
- 2. In the code you change, log each event a check needs: `console.log("[EMD:<tag>] <message>")`. Give a testID to each element a check needs.
17
+ - If it gives `needsPrepare`, a setup step makes the native project. Find in the project's docs (README, AGENTS.md, CLAUDE.md, Makefile) the command that makes it, and for iOS the scheme you run and its configuration. Pass them to every `launch` as `prepare`, `scheme` and `configuration`. If the docs don't say, ask the user once, then offer to add them to the project's agent notes.
18
+ - A native iOS app with several schemes stops with a list. Pass `scheme` the same way.
19
+ 2. In the code you change, log each event a check needs, and give a testID to each element a check needs:
20
+ - Expo: `console.log("[EMD:<tag>] <message>")` and `testID`.
21
+ - Native iOS (Swift): `NSLog("[EMD:<tag>] <message>")` and `accessibilityIdentifier`. Swift's `print` doesn't reach the log EMD reads.
22
+ - Native Android (Kotlin): `Log.i("EMD", "[EMD:<tag>] <message>")`. Compose: `Modifier.testTag("<id>")`, with `Modifier.semantics { testTagsAsResourceId = true }` once on a parent, or EMD can't see the tags. Views: an `android:id`; give its name without the package.
18
23
 
19
24
  ## The loop
20
25
 
21
- After you change code, call `launch` again before you `check` or `tap`. When nothing native changed, `launch` reloads the running app from the dev server in seconds (`build.action: "reloaded"`).
26
+ After you change code, call `launch` again before you `check` or `tap`. Expo on iOS: when nothing native changed, `launch` reloads the running app from the dev server in seconds (`build.action: "reloaded"`). Expo on Android and native apps: `launch` builds every time. For an Expo app, `launch` picks iOS; pass `platform: "android"` for Android.
22
27
 
23
28
  1. `launch` with `dir` set to the app folder. It waits up to 25 s (100 s in Claude Code): a reload or relaunch usually returns its result.
24
29
  2. If it returned a job still running, `job_status` with the `jobId`, until `succeeded` or `failed`. A first build takes minutes. A failed launch gives the reason and the first error lines: fix the cause and launch again.