emd-agents 0.15.0 → 0.16.1
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 +6 -9
- package/dist/adapters/expo/index.js +27 -4
- package/dist/cli/main.js +2 -2
- package/dist/core/adapter.d.ts +2 -0
- package/dist/core/buildrecord.d.ts +1 -0
- package/dist/core/buildrecord.js +15 -1
- package/dist/core/check.d.ts +13 -1
- package/dist/core/check.js +62 -8
- package/dist/core/detect.js +3 -2
- package/dist/core/device/axe.js +5 -5
- package/dist/core/device/backend.d.ts +4 -3
- package/dist/core/device/backend.js +12 -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 +45 -8
- package/dist/core/isolate.js +4 -2
- package/dist/core/jobs.d.ts +2 -1
- package/dist/core/jobs.js +25 -7
- package/dist/core/launch.d.ts +1 -0
- package/dist/core/launch.js +233 -41
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +22 -0
- package/dist/core/logs.js +16 -1
- package/dist/core/reload.d.ts +7 -0
- package/dist/core/reload.js +68 -0
- package/dist/core/result.d.ts +81 -18
- package/dist/core/result.js +44 -13
- package/dist/core/setup.js +16 -3
- package/dist/core/simulator.d.ts +2 -0
- package/dist/core/simulator.js +26 -8
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +107 -21
- package/package.json +1 -1
- package/skills/emd/SKILL.md +6 -6
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, 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, 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,24 +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. Waits up to waitSeconds (default
|
|
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."),
|
|
56
146
|
waitSeconds: z.number().min(0).max(110).optional(),
|
|
57
147
|
}),
|
|
58
148
|
outputSchema: jobViewSchema,
|
|
59
|
-
}, async ({ jobId, waitSeconds }) => {
|
|
60
|
-
|
|
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);
|
|
61
152
|
if (!job) {
|
|
62
153
|
return {
|
|
63
154
|
isError: true,
|
|
@@ -94,7 +185,7 @@ function buildServer() {
|
|
|
94
185
|
};
|
|
95
186
|
});
|
|
96
187
|
server.registerTool("check", {
|
|
97
|
-
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).",
|
|
98
189
|
inputSchema: z.object({
|
|
99
190
|
jobId: z.string().describe("The launch job whose run to check."),
|
|
100
191
|
logs: z
|
|
@@ -127,10 +218,14 @@ function buildServer() {
|
|
|
127
218
|
.enum(["pass", "fail"])
|
|
128
219
|
.optional()
|
|
129
220
|
.describe("Your reading of the screenshot. Second opinion only."),
|
|
221
|
+
actions,
|
|
222
|
+
waitSeconds,
|
|
130
223
|
}),
|
|
131
224
|
outputSchema: jobViewSchema,
|
|
132
|
-
}, async (input) => {
|
|
133
|
-
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;
|
|
134
229
|
return {
|
|
135
230
|
content: [{ type: "text", text: JSON.stringify(job) }],
|
|
136
231
|
structuredContent: job,
|
|
@@ -139,20 +234,11 @@ function buildServer() {
|
|
|
139
234
|
const jobId = z.string().describe("The launch job whose app to act on.");
|
|
140
235
|
server.registerTool("tap", {
|
|
141
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.",
|
|
142
|
-
inputSchema: z.object({
|
|
143
|
-
jobId,
|
|
144
|
-
id: z.string().optional().describe("The element's testID."),
|
|
145
|
-
text: z
|
|
146
|
-
.string()
|
|
147
|
-
.optional()
|
|
148
|
-
.describe("Its visible text or accessibility label, exactly."),
|
|
149
|
-
x: z.number().optional().describe("A point's x, in points."),
|
|
150
|
-
y: z.number().optional().describe("A point's y, in points."),
|
|
151
|
-
}),
|
|
237
|
+
inputSchema: z.object({ jobId, ...tapTarget }),
|
|
152
238
|
outputSchema: inputResultSchema,
|
|
153
239
|
}, async (input) => reply(await tap(input)));
|
|
154
240
|
server.registerTool("type", {
|
|
155
|
-
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.",
|
|
156
242
|
inputSchema: z.object({
|
|
157
243
|
jobId,
|
|
158
244
|
text: z.string().describe("The text to type."),
|
package/package.json
CHANGED
package/skills/emd/SKILL.md
CHANGED
|
@@ -18,18 +18,18 @@ Run `npx -y emd-agents@latest setup --dry-run` and show the user its plan. Run i
|
|
|
18
18
|
|
|
19
19
|
## The loop
|
|
20
20
|
|
|
21
|
-
After you change code, call `launch` again before you `check` or `tap`.
|
|
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"`).
|
|
22
22
|
|
|
23
|
-
1. `launch` with `dir` set to the app folder. It
|
|
24
|
-
2. `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.
|
|
25
|
-
3. `tap` with the `jobId`, and a testID (`id`) or a visible `text`. Use a point only when the element has neither. `type` types into the field that has focus, so tap the field first. `swipe` scrolls.
|
|
23
|
+
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
|
+
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.
|
|
25
|
+
3. `tap` with the `jobId`, and a testID (`id`) or a visible `text`. Use a point only when the element has neither. `type` types into the field that has focus, so tap the field first. `swipe` scrolls. For `tap` and `swipe`, `ok` means the gesture was sent; the next `check` shows what the app did. For `type`, `ok` means the text shows on screen; it can take up to 40 s. A secure field shows bullets, so `ok` there has a `note`.
|
|
26
26
|
4. `logs`, to read the tagged lines of this run.
|
|
27
|
-
5. `check` with the expected log events and elements and a `name` for the moment, e.g. `after-save`. A later check under that name must keep the first expectations unchanged; it can add more.
|
|
27
|
+
5. `check` with the expected log events and elements and a `name` for the moment, e.g. `after-save`. Put the taps, typing and swipes that lead to that moment in its `actions`, so one call acts and checks. A later check under that name must keep the first expectations unchanged; it can add more. It usually returns its verdict in the same call; if it returns a job, `job_status` until it ends:
|
|
28
28
|
- `passed`: done.
|
|
29
29
|
- `failed`: fix the cause, then check again.
|
|
30
30
|
- `stopped`: the retry limit is reached. Stop and report what is missing. Only a person can reset the count.
|
|
31
31
|
- `error`: the check could not run. Read its reason.
|
|
32
|
-
6.
|
|
32
|
+
6. Each check rewrites the run's evidence folder and returns its path (`evidenceDir`). Put that path, the screenshots and the matching log lines in your report or PR, and each name in `notPassed`. Call `evidence` only to rewrite the folder on its own.
|
|
33
33
|
|
|
34
34
|
## Rules
|
|
35
35
|
|