emd-agents 0.14.0 → 0.16.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.
- package/README.md +133 -64
- package/dist/adapters/expo/index.js +37 -4
- package/dist/cli/main.js +2 -2
- package/dist/core/adapter.d.ts +3 -0
- package/dist/core/buildrecord.d.ts +8 -0
- package/dist/core/buildrecord.js +45 -0
- package/dist/core/check.d.ts +13 -1
- package/dist/core/check.js +45 -4
- package/dist/core/detect.js +3 -2
- package/dist/core/device/axe.js +11 -9
- package/dist/core/device/backend.d.ts +11 -3
- package/dist/core/device/backend.js +50 -2
- package/dist/core/device/maestro.js +5 -5
- package/dist/core/device/typing.d.ts +20 -0
- package/dist/core/device/typing.js +120 -0
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.js +1 -2
- package/dist/core/input.js +53 -8
- package/dist/core/isolate.js +4 -2
- package/dist/core/jobs.d.ts +2 -0
- package/dist/core/jobs.js +31 -0
- package/dist/core/launch.d.ts +1 -0
- package/dist/core/launch.js +295 -38
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +22 -0
- package/dist/core/reload.d.ts +7 -0
- package/dist/core/reload.js +68 -0
- package/dist/core/result.d.ts +101 -17
- package/dist/core/result.js +52 -8
- package/dist/core/setup.js +16 -3
- package/dist/core/simulator.d.ts +6 -0
- package/dist/core/simulator.js +71 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +109 -22
- package/package.json +3 -1
- package/skills/emd/SKILL.md +7 -5
package/dist/core/result.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const detectResultSchema: z.ZodObject<{
|
|
|
16
16
|
ios: z.ZodOptional<z.ZodString>;
|
|
17
17
|
android: z.ZodOptional<z.ZodString>;
|
|
18
18
|
}, z.core.$strip>>;
|
|
19
|
+
problem: z.ZodOptional<z.ZodString>;
|
|
19
20
|
commands: z.ZodOptional<z.ZodObject<{
|
|
20
21
|
run: z.ZodObject<{
|
|
21
22
|
ios: z.ZodOptional<z.ZodString>;
|
|
@@ -49,6 +50,8 @@ export declare const launchResultSchema: z.ZodObject<{
|
|
|
49
50
|
}, z.core.$strip>>;
|
|
50
51
|
appId: z.ZodOptional<z.ZodString>;
|
|
51
52
|
appPid: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
appIdSet: z.ZodOptional<z.ZodString>;
|
|
54
|
+
reloadFailed: z.ZodOptional<z.ZodString>;
|
|
52
55
|
port: z.ZodOptional<z.ZodNumber>;
|
|
53
56
|
metro: z.ZodOptional<z.ZodObject<{
|
|
54
57
|
pid: z.ZodNumber;
|
|
@@ -57,6 +60,20 @@ export declare const launchResultSchema: z.ZodObject<{
|
|
|
57
60
|
logStream: z.ZodOptional<z.ZodObject<{
|
|
58
61
|
pid: z.ZodNumber;
|
|
59
62
|
}, z.core.$strip>>;
|
|
63
|
+
build: z.ZodOptional<z.ZodObject<{
|
|
64
|
+
action: z.ZodEnum<{
|
|
65
|
+
built: "built";
|
|
66
|
+
reused: "reused";
|
|
67
|
+
installed: "installed";
|
|
68
|
+
reloaded: "reloaded";
|
|
69
|
+
}>;
|
|
70
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
71
|
+
xcodebuildSeconds: z.ZodOptional<z.ZodNumber>;
|
|
72
|
+
}, z.core.$strip>>;
|
|
73
|
+
screen: z.ZodOptional<z.ZodObject<{
|
|
74
|
+
waited: z.ZodNumber;
|
|
75
|
+
error: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, z.core.$strip>>;
|
|
60
77
|
derivedData: z.ZodOptional<z.ZodString>;
|
|
61
78
|
diskMB: z.ZodOptional<z.ZodObject<{
|
|
62
79
|
derivedData: z.ZodNumber;
|
|
@@ -64,8 +81,31 @@ export declare const launchResultSchema: z.ZodObject<{
|
|
|
64
81
|
}, z.core.$strip>>;
|
|
65
82
|
logDir: z.ZodOptional<z.ZodString>;
|
|
66
83
|
seconds: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
phases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
67
85
|
}, z.core.$strip>;
|
|
68
86
|
export type LaunchResult = z.infer<typeof launchResultSchema>;
|
|
87
|
+
export declare const inputResultSchema: z.ZodObject<{
|
|
88
|
+
verdict: z.ZodEnum<{
|
|
89
|
+
failed: "failed";
|
|
90
|
+
ok: "ok";
|
|
91
|
+
}>;
|
|
92
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
93
|
+
backend: z.ZodOptional<z.ZodEnum<{
|
|
94
|
+
axe: "axe";
|
|
95
|
+
maestro: "maestro";
|
|
96
|
+
}>>;
|
|
97
|
+
fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
98
|
+
backend: z.ZodEnum<{
|
|
99
|
+
axe: "axe";
|
|
100
|
+
maestro: "maestro";
|
|
101
|
+
}>;
|
|
102
|
+
reason: z.ZodString;
|
|
103
|
+
}, z.core.$strip>>>;
|
|
104
|
+
seconds: z.ZodOptional<z.ZodNumber>;
|
|
105
|
+
retyped: z.ZodOptional<z.ZodString>;
|
|
106
|
+
note: z.ZodOptional<z.ZodString>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
export type InputResult = z.infer<typeof inputResultSchema>;
|
|
69
109
|
export declare const checkResultSchema: z.ZodObject<{
|
|
70
110
|
verdict: z.ZodEnum<{
|
|
71
111
|
error: "error";
|
|
@@ -107,27 +147,31 @@ export declare const checkResultSchema: z.ZodObject<{
|
|
|
107
147
|
}>>;
|
|
108
148
|
agrees: z.ZodOptional<z.ZodBoolean>;
|
|
109
149
|
}, z.core.$strip>>;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
axe: "axe";
|
|
120
|
-
maestro: "maestro";
|
|
121
|
-
}>>;
|
|
122
|
-
fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
123
|
-
backend: z.ZodEnum<{
|
|
150
|
+
evidenceDir: z.ZodOptional<z.ZodString>;
|
|
151
|
+
notPassed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
152
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
153
|
+
verdict: z.ZodEnum<{
|
|
154
|
+
failed: "failed";
|
|
155
|
+
ok: "ok";
|
|
156
|
+
}>;
|
|
157
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
158
|
+
backend: z.ZodOptional<z.ZodEnum<{
|
|
124
159
|
axe: "axe";
|
|
125
160
|
maestro: "maestro";
|
|
126
|
-
}
|
|
127
|
-
|
|
161
|
+
}>>;
|
|
162
|
+
fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
163
|
+
backend: z.ZodEnum<{
|
|
164
|
+
axe: "axe";
|
|
165
|
+
maestro: "maestro";
|
|
166
|
+
}>;
|
|
167
|
+
reason: z.ZodString;
|
|
168
|
+
}, z.core.$strip>>>;
|
|
169
|
+
seconds: z.ZodOptional<z.ZodNumber>;
|
|
170
|
+
retyped: z.ZodOptional<z.ZodString>;
|
|
171
|
+
note: z.ZodOptional<z.ZodString>;
|
|
128
172
|
}, z.core.$strip>>>;
|
|
129
173
|
}, z.core.$strip>;
|
|
130
|
-
export type
|
|
174
|
+
export type CheckResult = z.infer<typeof checkResultSchema>;
|
|
131
175
|
export declare const evidenceResultSchema: z.ZodObject<{
|
|
132
176
|
verdict: z.ZodEnum<{
|
|
133
177
|
failed: "failed";
|
|
@@ -172,6 +216,8 @@ export declare const jobViewSchema: z.ZodObject<{
|
|
|
172
216
|
}, z.core.$strip>>;
|
|
173
217
|
appId: z.ZodOptional<z.ZodString>;
|
|
174
218
|
appPid: z.ZodOptional<z.ZodNumber>;
|
|
219
|
+
appIdSet: z.ZodOptional<z.ZodString>;
|
|
220
|
+
reloadFailed: z.ZodOptional<z.ZodString>;
|
|
175
221
|
port: z.ZodOptional<z.ZodNumber>;
|
|
176
222
|
metro: z.ZodOptional<z.ZodObject<{
|
|
177
223
|
pid: z.ZodNumber;
|
|
@@ -180,6 +226,20 @@ export declare const jobViewSchema: z.ZodObject<{
|
|
|
180
226
|
logStream: z.ZodOptional<z.ZodObject<{
|
|
181
227
|
pid: z.ZodNumber;
|
|
182
228
|
}, z.core.$strip>>;
|
|
229
|
+
build: z.ZodOptional<z.ZodObject<{
|
|
230
|
+
action: z.ZodEnum<{
|
|
231
|
+
built: "built";
|
|
232
|
+
reused: "reused";
|
|
233
|
+
installed: "installed";
|
|
234
|
+
reloaded: "reloaded";
|
|
235
|
+
}>;
|
|
236
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
237
|
+
xcodebuildSeconds: z.ZodOptional<z.ZodNumber>;
|
|
238
|
+
}, z.core.$strip>>;
|
|
239
|
+
screen: z.ZodOptional<z.ZodObject<{
|
|
240
|
+
waited: z.ZodNumber;
|
|
241
|
+
error: z.ZodOptional<z.ZodString>;
|
|
242
|
+
}, z.core.$strip>>;
|
|
183
243
|
derivedData: z.ZodOptional<z.ZodString>;
|
|
184
244
|
diskMB: z.ZodOptional<z.ZodObject<{
|
|
185
245
|
derivedData: z.ZodNumber;
|
|
@@ -187,6 +247,7 @@ export declare const jobViewSchema: z.ZodObject<{
|
|
|
187
247
|
}, z.core.$strip>>;
|
|
188
248
|
logDir: z.ZodOptional<z.ZodString>;
|
|
189
249
|
seconds: z.ZodOptional<z.ZodNumber>;
|
|
250
|
+
phases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
190
251
|
}, z.core.$strip>, z.ZodObject<{
|
|
191
252
|
verdict: z.ZodEnum<{
|
|
192
253
|
error: "error";
|
|
@@ -228,6 +289,29 @@ export declare const jobViewSchema: z.ZodObject<{
|
|
|
228
289
|
}>>;
|
|
229
290
|
agrees: z.ZodOptional<z.ZodBoolean>;
|
|
230
291
|
}, z.core.$strip>>;
|
|
292
|
+
evidenceDir: z.ZodOptional<z.ZodString>;
|
|
293
|
+
notPassed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
294
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
295
|
+
verdict: z.ZodEnum<{
|
|
296
|
+
failed: "failed";
|
|
297
|
+
ok: "ok";
|
|
298
|
+
}>;
|
|
299
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
300
|
+
backend: z.ZodOptional<z.ZodEnum<{
|
|
301
|
+
axe: "axe";
|
|
302
|
+
maestro: "maestro";
|
|
303
|
+
}>>;
|
|
304
|
+
fellBack: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
305
|
+
backend: z.ZodEnum<{
|
|
306
|
+
axe: "axe";
|
|
307
|
+
maestro: "maestro";
|
|
308
|
+
}>;
|
|
309
|
+
reason: z.ZodString;
|
|
310
|
+
}, z.core.$strip>>>;
|
|
311
|
+
seconds: z.ZodOptional<z.ZodNumber>;
|
|
312
|
+
retyped: z.ZodOptional<z.ZodString>;
|
|
313
|
+
note: z.ZodOptional<z.ZodString>;
|
|
314
|
+
}, z.core.$strip>>>;
|
|
231
315
|
}, z.core.$strip>]>>;
|
|
232
316
|
}, z.core.$strip>;
|
|
233
317
|
export type JobView = z.infer<typeof jobViewSchema>;
|
package/dist/core/result.js
CHANGED
|
@@ -12,6 +12,10 @@ export const detectResultSchema = z.object({
|
|
|
12
12
|
stack: z.enum(stackIds).optional(),
|
|
13
13
|
platforms: z.array(z.enum(platforms)).optional(),
|
|
14
14
|
appIds: perPlatform.optional(),
|
|
15
|
+
// Why `launch` cannot go on: the app config could not be read (for example,
|
|
16
|
+
// dependencies are not installed), or an ios/ folder exists with no iOS app ID
|
|
17
|
+
// in the config.
|
|
18
|
+
problem: z.string().optional(),
|
|
15
19
|
commands: z.object({ run: perPlatform, server: z.string() }).optional(),
|
|
16
20
|
packageManager: z.enum(packageManagers).optional(),
|
|
17
21
|
maestroFlows: z.array(z.string()).optional(),
|
|
@@ -30,6 +34,11 @@ export const launchResultSchema = z.object({
|
|
|
30
34
|
device: z.object({ id: z.string(), name: z.string() }).optional(),
|
|
31
35
|
appId: z.string().optional(),
|
|
32
36
|
appPid: z.number().optional(),
|
|
37
|
+
// The iOS app ID that Expo's build wrote to the app config (ios.bundleIdentifier)
|
|
38
|
+
// because the app had none. Absent when the app already had one.
|
|
39
|
+
appIdSet: z.string().optional(),
|
|
40
|
+
// Why a reload did not work and the app was relaunched instead.
|
|
41
|
+
reloadFailed: z.string().optional(),
|
|
33
42
|
// The Metro port reserved for this worktree; set on a failure after it was.
|
|
34
43
|
port: z.number().optional(),
|
|
35
44
|
// The dev server left running for the app; the next launch in this worktree
|
|
@@ -38,6 +47,24 @@ export const launchResultSchema = z.object({
|
|
|
38
47
|
// The log stream that captures the app's tagged lines; the next launch in
|
|
39
48
|
// this worktree stops it.
|
|
40
49
|
logStream: z.object({ pid: z.number() }).optional(),
|
|
50
|
+
// Whether the Xcode build ran, an installed build was reused, an earlier
|
|
51
|
+
// build was installed again, or the running app was reloaded from the dev
|
|
52
|
+
// server; why it was not reused.
|
|
53
|
+
build: z
|
|
54
|
+
.object({
|
|
55
|
+
action: z.enum(["built", "reused", "installed", "reloaded"]),
|
|
56
|
+
reason: z.string().optional(),
|
|
57
|
+
// xcodebuild's own seconds, from its timing summary (#208). Its slowest
|
|
58
|
+
// steps are at the end of build.log.
|
|
59
|
+
xcodebuildSeconds: z.number().optional(),
|
|
60
|
+
})
|
|
61
|
+
.optional(),
|
|
62
|
+
// Set when AXe is installed: seconds `launch` waited until AXe could read the
|
|
63
|
+
// app's screen, and AXe's last error when the time ran out (the verdict stays
|
|
64
|
+
// launched).
|
|
65
|
+
screen: z
|
|
66
|
+
.object({ waited: z.number(), error: z.string().optional() })
|
|
67
|
+
.optional(),
|
|
41
68
|
// This worktree's own build folder, and what it and its simulator weigh.
|
|
42
69
|
derivedData: z.string().optional(),
|
|
43
70
|
diskMB: z
|
|
@@ -46,10 +73,28 @@ export const launchResultSchema = z.object({
|
|
|
46
73
|
// Full build and server logs live here; read them only when needed.
|
|
47
74
|
logDir: z.string().optional(),
|
|
48
75
|
seconds: z.number().optional(),
|
|
76
|
+
// Seconds each phase took, in order (#203): project, replace, clone, boot,
|
|
77
|
+
// server, reuse or build, open, screen. Only the phases that ran.
|
|
78
|
+
phases: z.record(z.string(), z.number()).optional(),
|
|
49
79
|
});
|
|
50
80
|
const fellBackSchema = z
|
|
51
81
|
.array(z.object({ backend: z.enum(backendIds), reason: z.string() }))
|
|
52
82
|
.optional();
|
|
83
|
+
// A tap, typing or swipe (decision 0009). ok: the backend did it; only a check
|
|
84
|
+
// shows whether the app reacted. failed: it could not, and `reason` says why.
|
|
85
|
+
export const inputResultSchema = z.object({
|
|
86
|
+
verdict: z.enum(["ok", "failed"]),
|
|
87
|
+
reason: z.string().optional(),
|
|
88
|
+
backend: z.enum(backendIds).optional(),
|
|
89
|
+
fellBack: fellBackSchema,
|
|
90
|
+
// A tap by testID or text: seconds from start to finish, which includes
|
|
91
|
+
// the wait for the element. `type`: seconds until the text showed.
|
|
92
|
+
seconds: z.number().optional(),
|
|
93
|
+
// `type`: the rest of the text, when it had to be typed a second time.
|
|
94
|
+
retyped: z.string().optional(),
|
|
95
|
+
// `type` in a secure field: what could and could not be confirmed.
|
|
96
|
+
note: z.string().optional(),
|
|
97
|
+
});
|
|
53
98
|
// The verdict comes only from log events and UI elements. The agent's own
|
|
54
99
|
// reading of a screenshot is recorded next to it as a second opinion and never
|
|
55
100
|
// changes the verdict.
|
|
@@ -95,14 +140,13 @@ export const checkResultSchema = z.object({
|
|
|
95
140
|
agrees: z.boolean().optional(),
|
|
96
141
|
})
|
|
97
142
|
.optional(),
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
fellBack: fellBackSchema,
|
|
143
|
+
// The run's evidence folder, rewritten after this check (#207), and the
|
|
144
|
+
// worktree's check names whose last verdict is not passed. Report each.
|
|
145
|
+
evidenceDir: z.string().optional(),
|
|
146
|
+
notPassed: z.array(z.string()).optional(),
|
|
147
|
+
// The actions the check ran before it read, in order, with each outcome
|
|
148
|
+
// (#207). A failed action stops the rest and the read.
|
|
149
|
+
actions: z.array(inputResultSchema).optional(),
|
|
106
150
|
});
|
|
107
151
|
export const evidenceResultSchema = z.object({
|
|
108
152
|
verdict: z.enum(["written", "failed"]),
|
package/dist/core/setup.js
CHANGED
|
@@ -67,11 +67,24 @@ const skillSource = () => fileURLToPath(new URL("../../", import.meta.url));
|
|
|
67
67
|
const emdServer = () => skillSource().split(sep).includes("node_modules")
|
|
68
68
|
? `npx -y emd-agents@${version()} mcp`
|
|
69
69
|
: `${process.execPath} ${fileURLToPath(new URL("../bin.js", import.meta.url))} mcp`;
|
|
70
|
+
// Claude Code's CLI lets one stdio tool call run for hours, so EMD waits up to
|
|
71
|
+
// this long per call there and an agent polls less (#223). Codex and Cursor
|
|
72
|
+
// stop a call at 60 s by default and keep EMD's short waits.
|
|
73
|
+
const longWaitSeconds = 100;
|
|
70
74
|
function commands(ids) {
|
|
71
|
-
const to =
|
|
75
|
+
const to = (some) => some.flatMap((id) => ["-a", id]);
|
|
76
|
+
const add = (some, env = []) => [
|
|
77
|
+
"npx",
|
|
78
|
+
["-y", addMcp, emdServer(), "-n", "emd", "-g", ...to(some), ...env, "-y"],
|
|
79
|
+
];
|
|
80
|
+
const long = ids.filter((id) => id === "claude-code");
|
|
81
|
+
const short = ids.filter((id) => id !== "claude-code");
|
|
72
82
|
return [
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
...(long.length > 0
|
|
84
|
+
? [add(long, ["--env", `EMD_WAIT_SECONDS=${longWaitSeconds}`])]
|
|
85
|
+
: []),
|
|
86
|
+
...(short.length > 0 ? [add(short)] : []),
|
|
87
|
+
["npx", ["-y", skillsCli, "add", skillSource(), "-g", ...to(ids), "-y"]],
|
|
75
88
|
];
|
|
76
89
|
}
|
|
77
90
|
const shown = ([command, args]) => [command, ...args.map((a) => (/\s/.test(a) ? `"${a}"` : a))].join(" ");
|
package/dist/core/simulator.d.ts
CHANGED
|
@@ -10,7 +10,13 @@ export declare function newerThan(device: Device, sdk: number[]): boolean;
|
|
|
10
10
|
export declare function simulatorSdk(): Promise<number[] | undefined>;
|
|
11
11
|
export declare function parseSdkVersion(output: string): number[] | undefined;
|
|
12
12
|
export declare function boot(device: Device): Promise<void>;
|
|
13
|
+
export declare function appAccessibilityOn(device: Device): Promise<boolean>;
|
|
14
|
+
export declare function enableAppAccessibility(device: Device): Promise<void>;
|
|
15
|
+
export declare function plainKeyboard(device: Device): Promise<void>;
|
|
16
|
+
export declare function terminateApp(device: Device, appId: string): Promise<void>;
|
|
13
17
|
export declare function launchApp(device: Device, appId: string): Promise<number>;
|
|
18
|
+
export declare function appInstalled(device: Device, appId: string): Promise<boolean>;
|
|
19
|
+
export declare function installApp(device: Device, appPath: string): Promise<void>;
|
|
14
20
|
export declare function cloneDevice(base: Device, name: string): Promise<string>;
|
|
15
21
|
export type Simulator = {
|
|
16
22
|
id: string;
|
package/dist/core/simulator.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
1
3
|
import { runTool } from "./tool.js";
|
|
2
4
|
export async function listDevices() {
|
|
3
5
|
const { stdout } = await runTool("simctl list", "xcrun", ["simctl", "list", "devices", "available", "--json"], 60);
|
|
@@ -70,6 +72,60 @@ export async function boot(device) {
|
|
|
70
72
|
}
|
|
71
73
|
await runTool("simctl bootstatus", "xcrun", ["simctl", "bootstatus", device.id, "-b"], 300);
|
|
72
74
|
}
|
|
75
|
+
const accessibilityKey = "ApplicationAccessibilityEnabled";
|
|
76
|
+
// Whether application accessibility is on. An app that starts while it is off
|
|
77
|
+
// can show AXe an empty tree on some iOS versions (docs/findings.md).
|
|
78
|
+
export async function appAccessibilityOn(device) {
|
|
79
|
+
try {
|
|
80
|
+
const { stdout } = await runTool("simctl spawn defaults read", "xcrun", [
|
|
81
|
+
"simctl",
|
|
82
|
+
"spawn",
|
|
83
|
+
device.id,
|
|
84
|
+
"defaults",
|
|
85
|
+
"read",
|
|
86
|
+
"com.apple.Accessibility",
|
|
87
|
+
accessibilityKey,
|
|
88
|
+
], 60);
|
|
89
|
+
return stdout.trim() === "1";
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Sets a boolean preference inside the simulator. It stays on the device; an
|
|
96
|
+
// app that is already running must restart to see it.
|
|
97
|
+
async function writeBool(device, domain, key, value) {
|
|
98
|
+
await runTool("simctl spawn defaults write", "xcrun", [
|
|
99
|
+
"simctl",
|
|
100
|
+
"spawn",
|
|
101
|
+
device.id,
|
|
102
|
+
"defaults",
|
|
103
|
+
"write",
|
|
104
|
+
domain,
|
|
105
|
+
key,
|
|
106
|
+
"-bool",
|
|
107
|
+
String(value),
|
|
108
|
+
], 60);
|
|
109
|
+
}
|
|
110
|
+
// Turns it on, on a simulator EMD made.
|
|
111
|
+
export async function enableAppAccessibility(device) {
|
|
112
|
+
await writeBool(device, "com.apple.Accessibility", accessibilityKey, true);
|
|
113
|
+
}
|
|
114
|
+
// Turns off Predictive Text and Auto-Correction on a simulator EMD made, as
|
|
115
|
+
// Appium's WebDriverAgent does before tests (same keys). Predictions add new
|
|
116
|
+
// text to the screen while `type` waits for its keys, and corrections change
|
|
117
|
+
// the typed text.
|
|
118
|
+
export async function plainKeyboard(device) {
|
|
119
|
+
await Promise.all(["KeyboardPrediction", "KeyboardAutocorrection"].map((key) => writeBool(device, "com.apple.Preferences", key, false)));
|
|
120
|
+
}
|
|
121
|
+
// Stops the app if it runs; a later launch then starts it fresh. Not running is
|
|
122
|
+
// not a failure.
|
|
123
|
+
export async function terminateApp(device, appId) {
|
|
124
|
+
try {
|
|
125
|
+
await runTool("simctl terminate", "xcrun", ["simctl", "terminate", device.id, appId], 60);
|
|
126
|
+
}
|
|
127
|
+
catch { }
|
|
128
|
+
}
|
|
73
129
|
// Returns the app's pid. Brings the app forward if it is already running.
|
|
74
130
|
export async function launchApp(device, appId) {
|
|
75
131
|
const { stdout } = await runTool("simctl launch", "xcrun", ["simctl", "launch", device.id, appId], 120);
|
|
@@ -78,6 +134,21 @@ export async function launchApp(device, appId) {
|
|
|
78
134
|
throw new Error(`unexpected output: ${stdout}`);
|
|
79
135
|
return pid;
|
|
80
136
|
}
|
|
137
|
+
// True when the app is installed on the device. `simctl` can name a container
|
|
138
|
+
// whose app files are gone, so the app's Info.plist must exist.
|
|
139
|
+
export async function appInstalled(device, appId) {
|
|
140
|
+
try {
|
|
141
|
+
const { stdout } = await runTool("simctl get_app_container", "xcrun", ["simctl", "get_app_container", device.id, appId], 60);
|
|
142
|
+
return existsSync(join(stdout.trim(), "Info.plist"));
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Installs a built `.app` on the device.
|
|
149
|
+
export async function installApp(device, appPath) {
|
|
150
|
+
await runTool("simctl install", "xcrun", ["simctl", "install", device.id, appPath], 120);
|
|
151
|
+
}
|
|
81
152
|
// A new simulator with the same type and runtime as `base`; returns its UDID.
|
|
82
153
|
// The base must be shut down.
|
|
83
154
|
export async function cloneDevice(base, name) {
|
package/dist/mcp/server.d.ts
CHANGED
package/dist/mcp/server.js
CHANGED
|
@@ -1,13 +1,100 @@
|
|
|
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, } from "../core/index.js";
|
|
4
|
+
import { detect, detectResultSchema, directions, evidence, evidenceResultSchema, inputResultSchema, jobStatus, jobViewSchema, logs, logsResultSchema, startJob, swipe, tap, typeText, version, waitForJob, } from "../core/index.js";
|
|
5
|
+
// Fast work returns its result in the same call, so the agent needs no
|
|
6
|
+
// job_status call (#207). 25 s keeps a 2x margin under a 60 s client timeout.
|
|
7
|
+
const waitSeconds = z
|
|
8
|
+
.number()
|
|
9
|
+
.min(0)
|
|
10
|
+
.max(110)
|
|
11
|
+
.optional()
|
|
12
|
+
.describe("How long to wait for the work to end before returning the job. Default 25, or longer where setup allowed it.");
|
|
13
|
+
// The default wait, in seconds, of a tool whose own default is `short`. setup
|
|
14
|
+
// sets EMD_WAIT_SECONDS (0 to 110) for clients that let one call run that long
|
|
15
|
+
// (#223). Once a client has cancelled a call, the session keeps `short`.
|
|
16
|
+
export function defaultWait(short, cancelled, configured = process.env.EMD_WAIT_SECONDS) {
|
|
17
|
+
const seconds = Number(configured);
|
|
18
|
+
return cancelled ||
|
|
19
|
+
!configured ||
|
|
20
|
+
!Number.isFinite(seconds) ||
|
|
21
|
+
seconds < 0 ||
|
|
22
|
+
seconds > 110
|
|
23
|
+
? short
|
|
24
|
+
: seconds;
|
|
25
|
+
}
|
|
26
|
+
// How often a wait reports progress, when the call asks for it (#223).
|
|
27
|
+
const progressSeconds = 15;
|
|
28
|
+
// Waits for a job like waitForJob. While it waits it sends the job's step as
|
|
29
|
+
// progress, at once and then every 15 s, when the call carries a progress
|
|
30
|
+
// token: a client that resets its timeout on progress keeps the call alive.
|
|
31
|
+
// A cancelled call ends at once and calls `onCancel`. A call more than 2 s
|
|
32
|
+
// past its wait means this process got no CPU: one stderr line says so, and
|
|
33
|
+
// stderr reaches the client's log even after the client has given up (#198).
|
|
34
|
+
async function waitTimed(tool, jobId, wait, ctx, onCancel, since = Date.now()) {
|
|
35
|
+
const { signal, notify, _meta } = ctx.mcpReq;
|
|
36
|
+
const token = _meta?.progressToken;
|
|
37
|
+
const report = () => {
|
|
38
|
+
if (token === undefined)
|
|
39
|
+
return;
|
|
40
|
+
const view = jobStatus(jobId);
|
|
41
|
+
notify({
|
|
42
|
+
method: "notifications/progress",
|
|
43
|
+
params: {
|
|
44
|
+
progressToken: token,
|
|
45
|
+
progress: Math.round((Date.now() - since) / 1000),
|
|
46
|
+
message: view?.step ?? view?.status,
|
|
47
|
+
},
|
|
48
|
+
}).catch(() => { });
|
|
49
|
+
};
|
|
50
|
+
report();
|
|
51
|
+
const timer = setInterval(report, progressSeconds * 1000);
|
|
52
|
+
signal.addEventListener("abort", onCancel, { once: true });
|
|
53
|
+
try {
|
|
54
|
+
const job = await waitForJob(jobId, wait, jobStatus, signal);
|
|
55
|
+
const took = (Date.now() - since) / 1000;
|
|
56
|
+
if (took > wait + 2) {
|
|
57
|
+
console.error(`emd: ${tool} took ${took.toFixed(1)} s with a ${wait} s wait.`);
|
|
58
|
+
}
|
|
59
|
+
return job;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
clearInterval(timer);
|
|
63
|
+
signal.removeEventListener("abort", onCancel);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// A tap's target, for the tap tool and a check's actions.
|
|
67
|
+
const tapTarget = {
|
|
68
|
+
id: z.string().optional().describe("The element's testID."),
|
|
69
|
+
text: z
|
|
70
|
+
.string()
|
|
71
|
+
.optional()
|
|
72
|
+
.describe("Its visible text or accessibility label, exactly."),
|
|
73
|
+
x: z.number().optional().describe("A point's x, in points."),
|
|
74
|
+
y: z.number().optional().describe("A point's y, in points."),
|
|
75
|
+
};
|
|
76
|
+
// Actions a check runs before it reads, with the tap, type and swipe tools'
|
|
77
|
+
// inputs (#207).
|
|
78
|
+
const actions = z
|
|
79
|
+
.array(z.union([
|
|
80
|
+
z.object({ tap: z.object(tapTarget) }).strict(),
|
|
81
|
+
z.object({ type: z.string() }).strict(),
|
|
82
|
+
z.object({ swipe: z.enum(directions) }).strict(),
|
|
83
|
+
]))
|
|
84
|
+
.max(10)
|
|
85
|
+
.optional()
|
|
86
|
+
.describe('Taps, typing and swipes to run first, in order, each as the tap, type or swipe tool would: e.g. [{"tap":{"id":"name-field"}},{"type":"Ada"},{"tap":{"text":"Save"}}]. A failed one stops the rest and the check does not count.');
|
|
5
87
|
const reply = (result) => ({
|
|
6
88
|
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
7
89
|
structuredContent: result,
|
|
8
90
|
});
|
|
9
91
|
function buildServer() {
|
|
10
92
|
const server = new McpServer({ name: "emd", version: version() });
|
|
93
|
+
// Set once the client cancels one of EMD's calls (#223).
|
|
94
|
+
let cancelled = false;
|
|
95
|
+
const onCancel = () => {
|
|
96
|
+
cancelled = true;
|
|
97
|
+
};
|
|
11
98
|
server.registerTool("detect", {
|
|
12
99
|
description: "Detect the mobile stack of a project directory and what launching it needs: platforms, app IDs, run commands, package manager. At a workspace root, `apps` lists the app folders to detect instead. Returns a small result, not file contents.",
|
|
13
100
|
inputSchema: z.object({
|
|
@@ -25,7 +112,7 @@ function buildServer() {
|
|
|
25
112
|
};
|
|
26
113
|
});
|
|
27
114
|
server.registerTool("launch", {
|
|
28
|
-
description: "
|
|
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.",
|
|
29
116
|
inputSchema: z.object({
|
|
30
117
|
dir: z
|
|
31
118
|
.string()
|
|
@@ -40,23 +127,28 @@ function buildServer() {
|
|
|
40
127
|
.positive()
|
|
41
128
|
.optional()
|
|
42
129
|
.describe("How long the build may take. Default 900."),
|
|
130
|
+
waitSeconds,
|
|
43
131
|
}),
|
|
44
132
|
outputSchema: jobViewSchema,
|
|
45
|
-
}, async (input) => {
|
|
46
|
-
const
|
|
133
|
+
}, async ({ waitSeconds: wait, ...input }, ctx) => {
|
|
134
|
+
const since = Date.now();
|
|
135
|
+
const started = startJob("launch", input);
|
|
136
|
+
const job = (await waitTimed("launch", started.jobId, wait ?? defaultWait(25, cancelled), ctx, onCancel, since)) ?? started;
|
|
47
137
|
return {
|
|
48
138
|
content: [{ type: "text", text: JSON.stringify(job) }],
|
|
49
139
|
structuredContent: job,
|
|
50
140
|
};
|
|
51
141
|
});
|
|
52
142
|
server.registerTool("job_status", {
|
|
53
|
-
description: "Where a job is: queued, running (with the current step and seconds), succeeded or failed. When finished, includes the result. For launch: the device, app ID and log directory, or on failure the reason and the first relevant error lines, not the log. For check: the verdict, which expectations were found, and a screenshot path.",
|
|
143
|
+
description: "Where a job is: queued, running (with the current step and seconds), succeeded or failed. Waits up to waitSeconds (default 30, or longer where setup allowed it) and returns as soon as the job ends, so call it again right away if it is still running; do not sleep or poll in between. When finished, includes the result. For launch: the device, app ID and log directory, or on failure the reason and the first relevant error lines, not the log. For check: the verdict, which expectations were found, and a screenshot path.",
|
|
54
144
|
inputSchema: z.object({
|
|
55
145
|
jobId: z.string().describe("The jobId a tool such as launch returned."),
|
|
146
|
+
waitSeconds: z.number().min(0).max(110).optional(),
|
|
56
147
|
}),
|
|
57
148
|
outputSchema: jobViewSchema,
|
|
58
|
-
}, async ({ jobId }) => {
|
|
59
|
-
|
|
149
|
+
}, async ({ jobId, waitSeconds }, ctx) => {
|
|
150
|
+
// 30 s: a 2x margin under a 60 s client timeout (#198).
|
|
151
|
+
const job = await waitTimed("job_status", jobId, waitSeconds ?? defaultWait(30, cancelled), ctx, onCancel);
|
|
60
152
|
if (!job) {
|
|
61
153
|
return {
|
|
62
154
|
isError: true,
|
|
@@ -93,7 +185,7 @@ function buildServer() {
|
|
|
93
185
|
};
|
|
94
186
|
});
|
|
95
187
|
server.registerTool("check", {
|
|
96
|
-
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).
|
|
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).",
|
|
97
189
|
inputSchema: z.object({
|
|
98
190
|
jobId: z.string().describe("The launch job whose run to check."),
|
|
99
191
|
logs: z
|
|
@@ -126,10 +218,14 @@ function buildServer() {
|
|
|
126
218
|
.enum(["pass", "fail"])
|
|
127
219
|
.optional()
|
|
128
220
|
.describe("Your reading of the screenshot. Second opinion only."),
|
|
221
|
+
actions,
|
|
222
|
+
waitSeconds,
|
|
129
223
|
}),
|
|
130
224
|
outputSchema: jobViewSchema,
|
|
131
|
-
}, async (input) => {
|
|
132
|
-
const
|
|
225
|
+
}, async ({ waitSeconds: wait, ...input }, ctx) => {
|
|
226
|
+
const since = Date.now();
|
|
227
|
+
const started = startJob("check", input);
|
|
228
|
+
const job = (await waitTimed("check", started.jobId, wait ?? defaultWait(25, cancelled), ctx, onCancel, since)) ?? started;
|
|
133
229
|
return {
|
|
134
230
|
content: [{ type: "text", text: JSON.stringify(job) }],
|
|
135
231
|
structuredContent: job,
|
|
@@ -137,21 +233,12 @@ function buildServer() {
|
|
|
137
233
|
});
|
|
138
234
|
const jobId = z.string().describe("The launch job whose app to act on.");
|
|
139
235
|
server.registerTool("tap", {
|
|
140
|
-
description: "Tap the launched app: an element by testID or by visible text, or a point. Give one target. Waits up to
|
|
141
|
-
inputSchema: z.object({
|
|
142
|
-
jobId,
|
|
143
|
-
id: z.string().optional().describe("The element's testID."),
|
|
144
|
-
text: z
|
|
145
|
-
.string()
|
|
146
|
-
.optional()
|
|
147
|
-
.describe("Its visible text or accessibility label, exactly."),
|
|
148
|
-
x: z.number().optional().describe("A point's x, in points."),
|
|
149
|
-
y: z.number().optional().describe("A point's y, in points."),
|
|
150
|
-
}),
|
|
236
|
+
description: "Tap the launched app: an element by testID or by visible text, or a point. Give one target. Waits up to 10 s for the element, and the result's seconds says how long the tap took. If it never appears, nothing is tapped. A result of ok means the tap was sent; call check to see what the app did.",
|
|
237
|
+
inputSchema: z.object({ jobId, ...tapTarget }),
|
|
151
238
|
outputSchema: inputResultSchema,
|
|
152
239
|
}, async (input) => reply(await tap(input)));
|
|
153
240
|
server.registerTool("type", {
|
|
154
|
-
description: "Type text into the field that has focus. Tap the field first. Letters, digits and US keyboard symbols only.",
|
|
241
|
+
description: "Type text into the field that has focus. Tap the field first. Letters, digits and US keyboard symbols only. ok means the text shows on screen (secure fields: bullets grew by its length); this can take up to 40 s. failed says what the screen shows.",
|
|
155
242
|
inputSchema: z.object({
|
|
156
243
|
jobId,
|
|
157
244
|
text: z.string().describe("The text to type."),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emd-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Build, run, check and prove mobile changes from any coding agent.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"@biomejs/biome": "^2.6.4",
|
|
43
43
|
"@commitlint/cli": "^21.2.4",
|
|
44
44
|
"@commitlint/config-conventional": "^21.2.4",
|
|
45
|
+
"@commitlint/lint": "^21.2.4",
|
|
46
|
+
"@commitlint/load": "^21.2.4",
|
|
45
47
|
"@modelcontextprotocol/client": "^2.4.0",
|
|
46
48
|
"@types/node": "^22.0.0",
|
|
47
49
|
"@types/proper-lockfile": "^4.1.4",
|