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
|
@@ -17,9 +17,9 @@ export type Where = {
|
|
|
17
17
|
};
|
|
18
18
|
export interface DeviceBackend {
|
|
19
19
|
id: BackendId;
|
|
20
|
-
readScreen(device: string, bin: string): Promise<UiNode[]>;
|
|
20
|
+
readScreen(device: string, bin: string, seconds?: number): Promise<UiNode[]>;
|
|
21
21
|
tap(where: Where, bin: string, target: Target): Promise<void>;
|
|
22
|
-
type(where: Where, bin: string, text: string): Promise<void>;
|
|
22
|
+
type(where: Where, bin: string, text: string, seconds?: number): Promise<void>;
|
|
23
23
|
swipe(where: Where, bin: string, direction: Direction): Promise<void>;
|
|
24
24
|
}
|
|
25
25
|
export type Environment = Partial<Record<BackendId, string>>;
|
|
@@ -35,9 +35,17 @@ export type Acted<T> = {
|
|
|
35
35
|
export declare function firstWorking<B extends {
|
|
36
36
|
id: BackendId;
|
|
37
37
|
}, T>(what: string, env: Environment, backends: B[], act: (backend: B, bin: string) => Promise<T>): Promise<Acted<T>>;
|
|
38
|
+
export declare function secondsTo(until: number): number;
|
|
38
39
|
export type ScreenRead = Omit<Acted<UiNode[]>, "value"> & {
|
|
39
40
|
nodes: UiNode[];
|
|
40
41
|
};
|
|
41
|
-
export declare function readScreen(device: string, env: Environment, backends: Pick<DeviceBackend, "id" | "readScreen">[]): Promise<ScreenRead>;
|
|
42
|
+
export declare function readScreen(device: string, env: Environment, backends: Pick<DeviceBackend, "id" | "readScreen">[], until?: number): Promise<ScreenRead>;
|
|
43
|
+
export declare function untilReadable(read: () => Promise<UiNode[]>, limitSeconds: number, whenEmpty?: {
|
|
44
|
+
afterSeconds: number;
|
|
45
|
+
act: () => Promise<void>;
|
|
46
|
+
}, pauseMs?: number): Promise<{
|
|
47
|
+
waited: number;
|
|
48
|
+
error?: string;
|
|
49
|
+
}>;
|
|
42
50
|
export declare function detectEnvironment(): Promise<Environment>;
|
|
43
51
|
export {};
|
|
@@ -36,9 +36,19 @@ export async function firstWorking(what, env, backends, act) {
|
|
|
36
36
|
}
|
|
37
37
|
throw new Error(`no backend could ${what} (${fellBack.map((f) => `${f.backend}: ${f.reason}`).join("; ")})`);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
// Seconds left until `until` (a Date.now() time), for one backend's call. When
|
|
40
|
+
// none are left, it throws, so no backend starts after a caller's deadline.
|
|
41
|
+
export function secondsTo(until) {
|
|
42
|
+
const seconds = (until - Date.now()) / 1000;
|
|
43
|
+
if (seconds <= 0)
|
|
44
|
+
throw new Error("no time left");
|
|
45
|
+
return seconds;
|
|
46
|
+
}
|
|
47
|
+
export async function readScreen(device, env, backends,
|
|
48
|
+
// A Date.now() time that no backend's read may pass.
|
|
49
|
+
until) {
|
|
40
50
|
const { value, ...rest } = await firstWorking("read the screen", env, backends, async (backend, bin) => {
|
|
41
|
-
const nodes = await backend.readScreen(device, bin);
|
|
51
|
+
const nodes = await backend.readScreen(device, bin, until === undefined ? undefined : secondsTo(until));
|
|
42
52
|
// Every good read includes the app's root node, so none means the read
|
|
43
53
|
// failed (AXe sometimes reads nothing right after a relaunch).
|
|
44
54
|
if (nodes.length === 0)
|
|
@@ -47,6 +57,44 @@ export async function readScreen(device, env, backends) {
|
|
|
47
57
|
});
|
|
48
58
|
return { nodes: value, ...rest };
|
|
49
59
|
}
|
|
60
|
+
// Reads the screen again until a read gives nodes or `limitSeconds` pass.
|
|
61
|
+
// Returns the seconds it took, and the last problem (in one short sentence)
|
|
62
|
+
// when time ran out. When every read so far gave an empty tree, not an error,
|
|
63
|
+
// `whenEmpty.act` runs once after `whenEmpty.afterSeconds` (the first sign of
|
|
64
|
+
// the shape that application accessibility fixes).
|
|
65
|
+
export async function untilReadable(read, limitSeconds, whenEmpty, pauseMs = 1000) {
|
|
66
|
+
const start = Date.now();
|
|
67
|
+
const elapsed = () => Date.now() - start;
|
|
68
|
+
const short = (text) => text
|
|
69
|
+
.replace(/^Error: /, "")
|
|
70
|
+
.split(/[.\n]/)[0]
|
|
71
|
+
?.slice(0, 80) ?? "";
|
|
72
|
+
let error = "returned an empty tree";
|
|
73
|
+
let onlyEmpty = true;
|
|
74
|
+
let acted = false;
|
|
75
|
+
for (;;) {
|
|
76
|
+
try {
|
|
77
|
+
if ((await read()).length > 0) {
|
|
78
|
+
return { waited: Math.round(elapsed() / 100) / 10 };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (failure) {
|
|
82
|
+
onlyEmpty = false;
|
|
83
|
+
error = short(firstLine(failure));
|
|
84
|
+
}
|
|
85
|
+
if (whenEmpty &&
|
|
86
|
+
!acted &&
|
|
87
|
+
onlyEmpty &&
|
|
88
|
+
elapsed() >= whenEmpty.afterSeconds * 1000) {
|
|
89
|
+
acted = true;
|
|
90
|
+
await whenEmpty.act().catch(() => { });
|
|
91
|
+
}
|
|
92
|
+
if (elapsed() >= limitSeconds * 1000) {
|
|
93
|
+
return { waited: Math.round(elapsed() / 100) / 10, error };
|
|
94
|
+
}
|
|
95
|
+
await new Promise((resolve) => setTimeout(resolve, pauseMs));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
50
98
|
function findExecutable(name, extraDirs) {
|
|
51
99
|
const dirs = [
|
|
52
100
|
...(process.env.PATH ?? "").split(delimiter),
|
|
@@ -34,9 +34,9 @@ const driverEnv = () => ({
|
|
|
34
34
|
// The accessibility tree of what is on the simulator's screen now. Maestro
|
|
35
35
|
// starts and stops its XCUITest driver on every call, which takes about 20 s,
|
|
36
36
|
// and about 50 s for the first call after an app launch.
|
|
37
|
-
async function readScreen(device, bin) {
|
|
37
|
+
async function readScreen(device, bin, seconds = 240) {
|
|
38
38
|
try {
|
|
39
|
-
const { stdout } = await runTool("maestro hierarchy", bin, ["--device", device, "hierarchy"],
|
|
39
|
+
const { stdout } = await runTool("maestro hierarchy", bin, ["--device", device, "hierarchy"], seconds, { env: driverEnv() });
|
|
40
40
|
return parseMaestro(stdout);
|
|
41
41
|
}
|
|
42
42
|
catch (error) {
|
|
@@ -54,12 +54,12 @@ async function readScreen(device, bin) {
|
|
|
54
54
|
}
|
|
55
55
|
// One step as a Maestro flow for the app. JSON strings are valid YAML
|
|
56
56
|
// strings. A run takes 80 to 100 s (experiments/tap-tools.md).
|
|
57
|
-
async function runStep({ device, appId }, bin, step) {
|
|
57
|
+
async function runStep({ device, appId }, bin, step, seconds = 240) {
|
|
58
58
|
const dir = mkdtempSync(join(tmpdir(), "emd-maestro-"));
|
|
59
59
|
try {
|
|
60
60
|
const flow = join(dir, "step.yaml");
|
|
61
61
|
writeFileSync(flow, `appId: ${JSON.stringify(appId)}\n---\n- ${step}\n`);
|
|
62
|
-
await runTool("maestro test", bin, ["--device", device, "test", flow],
|
|
62
|
+
await runTool("maestro test", bin, ["--device", device, "test", flow], seconds, {
|
|
63
63
|
env: driverEnv(),
|
|
64
64
|
});
|
|
65
65
|
}
|
|
@@ -81,6 +81,6 @@ export const maestroBackend = {
|
|
|
81
81
|
id: "maestro",
|
|
82
82
|
readScreen,
|
|
83
83
|
tap: (where, bin, target) => runStep(where, bin, tapStep(target)),
|
|
84
|
-
type: (where, bin, text) => runStep(where, bin, `inputText: ${JSON.stringify(text)}
|
|
84
|
+
type: (where, bin, text, seconds) => runStep(where, bin, `inputText: ${JSON.stringify(text)}`, seconds),
|
|
85
85
|
swipe: (where, bin, direction) => runStep(where, bin, `swipe: { direction: ${direction.toUpperCase()} }`),
|
|
86
86
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { UiNode } from "./screen.js";
|
|
2
|
+
type Typing = {
|
|
3
|
+
type(text: string, seconds: number): Promise<void>;
|
|
4
|
+
read(seconds: number): Promise<UiNode[]>;
|
|
5
|
+
sleep(ms: number): Promise<void>;
|
|
6
|
+
now(): number;
|
|
7
|
+
};
|
|
8
|
+
type Typed = {
|
|
9
|
+
seconds: number;
|
|
10
|
+
retyped?: string;
|
|
11
|
+
} & ({
|
|
12
|
+
verdict: "shown";
|
|
13
|
+
} | {
|
|
14
|
+
verdict: "secure";
|
|
15
|
+
} | {
|
|
16
|
+
verdict: "failed";
|
|
17
|
+
reason: string;
|
|
18
|
+
});
|
|
19
|
+
export declare function typeUntilShown(io: Typing, text: string, limitSeconds?: number, pauseMs?: number): Promise<Typed>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const bullets = /^•+$/;
|
|
2
|
+
// A node is its id plus its place among nodes with that id.
|
|
3
|
+
function keyed(nodes) {
|
|
4
|
+
const seen = new Map();
|
|
5
|
+
const out = new Map();
|
|
6
|
+
for (const node of nodes) {
|
|
7
|
+
const n = seen.get(node.id) ?? 0;
|
|
8
|
+
seen.set(node.id, n + 1);
|
|
9
|
+
out.set(`${node.id}#${n}`, node.texts);
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
function judge(before, nodes, text) {
|
|
14
|
+
let found = { kind: "none" };
|
|
15
|
+
for (const [key, texts] of keyed(nodes)) {
|
|
16
|
+
const old = before.get(key) ?? [];
|
|
17
|
+
const olds = ["", ...old];
|
|
18
|
+
for (const shown of texts.filter((t) => !old.includes(t))) {
|
|
19
|
+
if (olds.some((o) => shown === o + text || shown === text)) {
|
|
20
|
+
return { kind: "shown" };
|
|
21
|
+
}
|
|
22
|
+
const oldBullets = Math.max(0, ...old.filter((o) => bullets.test(o)).map((o) => o.length));
|
|
23
|
+
if (bullets.test(shown) && shown.length === oldBullets + text.length) {
|
|
24
|
+
return { kind: "secure" };
|
|
25
|
+
}
|
|
26
|
+
if (shown.includes(text))
|
|
27
|
+
found = { kind: "extra", shown };
|
|
28
|
+
else if (found.kind === "none") {
|
|
29
|
+
for (const o of olds) {
|
|
30
|
+
const rest = shown.startsWith(o) ? shown.slice(o.length) : "";
|
|
31
|
+
if (rest && rest.length < text.length && text.startsWith(rest)) {
|
|
32
|
+
found = { kind: "partial", key, have: rest.length, shown };
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return found;
|
|
40
|
+
}
|
|
41
|
+
// What the screen shows, in one short phrase, for a failure message.
|
|
42
|
+
function describeScreen(nodes) {
|
|
43
|
+
const texts = [...new Set(nodes.flatMap((node) => node.texts))].slice(0, 8);
|
|
44
|
+
return texts.length > 0
|
|
45
|
+
? `the screen shows ${texts.map((t) => JSON.stringify(t.slice(0, 40))).join(", ")}`
|
|
46
|
+
: "the screen shows no text";
|
|
47
|
+
}
|
|
48
|
+
// Types `text`, then reads until it shows. The whole call, from the read before
|
|
49
|
+
// typing, takes at most `limitSeconds`: each step gets only the time left, and
|
|
50
|
+
// no step starts after the limit. The MCP client gives up at 60 s.
|
|
51
|
+
//
|
|
52
|
+
// If the screen stays the same for half the limit, types the missing rest once
|
|
53
|
+
// (all of it when no key arrived). Late keys come 10 to 27 s late, so a shorter
|
|
54
|
+
// wait doubles text. Doubled text fails the exact match, so a retype can never
|
|
55
|
+
// give a false `ok`.
|
|
56
|
+
export async function typeUntilShown(io, text, limitSeconds = 40, pauseMs = 1000) {
|
|
57
|
+
const start = io.now();
|
|
58
|
+
const end = start + limitSeconds * 1000;
|
|
59
|
+
const left = () => Math.max(0, (end - io.now()) / 1000);
|
|
60
|
+
const seconds = () => Math.round((io.now() - start) / 100) / 10;
|
|
61
|
+
let retyped;
|
|
62
|
+
const failed = (reason) => ({
|
|
63
|
+
verdict: "failed",
|
|
64
|
+
seconds: seconds(),
|
|
65
|
+
...(retyped ? { retyped } : {}),
|
|
66
|
+
reason,
|
|
67
|
+
});
|
|
68
|
+
let last = await io.read(left());
|
|
69
|
+
const before = keyed(last);
|
|
70
|
+
if (left() === 0) {
|
|
71
|
+
return failed(`Reading the screen before typing took ${seconds()} s.`);
|
|
72
|
+
}
|
|
73
|
+
await io.type(text, left());
|
|
74
|
+
let lastError = "";
|
|
75
|
+
let state = "";
|
|
76
|
+
let since = io.now();
|
|
77
|
+
for (;;) {
|
|
78
|
+
if (left() === 0) {
|
|
79
|
+
const error = lastError
|
|
80
|
+
? `; the last read failed: ${lastError.split("\n")[0]}`
|
|
81
|
+
: "";
|
|
82
|
+
return failed(`The text did not show on screen after ${seconds()} s${retyped ? " and one retype" : ""}; ${describeScreen(last)}${error}.`);
|
|
83
|
+
}
|
|
84
|
+
let rest;
|
|
85
|
+
try {
|
|
86
|
+
last = await io.read(left());
|
|
87
|
+
lastError = "";
|
|
88
|
+
const judged = judge(before, last, text);
|
|
89
|
+
if (judged.kind === "shown" || judged.kind === "secure") {
|
|
90
|
+
return {
|
|
91
|
+
verdict: judged.kind,
|
|
92
|
+
seconds: seconds(),
|
|
93
|
+
...(retyped ? { retyped } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (judged.kind === "extra") {
|
|
97
|
+
return failed(`The field shows ${JSON.stringify(judged.shown.slice(0, 80))}: more than the typed text.`);
|
|
98
|
+
}
|
|
99
|
+
const now = judged.kind === "partial" ? `${judged.key}=${judged.shown}` : "";
|
|
100
|
+
if (now !== state) {
|
|
101
|
+
state = now;
|
|
102
|
+
since = io.now();
|
|
103
|
+
}
|
|
104
|
+
else if (!retyped && io.now() - since >= (end - start) / 2) {
|
|
105
|
+
rest = text.slice(judged.kind === "partial" ? judged.have : 0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
// A failed read says nothing about the text; read again.
|
|
110
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
111
|
+
}
|
|
112
|
+
// Outside the try: a failed retype must fail the call, not be read again.
|
|
113
|
+
if (rest && left() > 0) {
|
|
114
|
+
retyped = rest;
|
|
115
|
+
await io.type(rest, left());
|
|
116
|
+
}
|
|
117
|
+
if (left() > 0)
|
|
118
|
+
await io.sleep(Math.min(pauseMs, left() * 1000));
|
|
119
|
+
}
|
|
120
|
+
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -7,8 +7,7 @@ export { type DoctorResult, doctor } from "./doctor.js";
|
|
|
7
7
|
export { evidence } from "./evidence.js";
|
|
8
8
|
export { type GcResult, gc } from "./gc.js";
|
|
9
9
|
export { swipe, tap, typeText } from "./input.js";
|
|
10
|
-
export { jobStatus, runJob, startJob } from "./jobs.js";
|
|
11
|
-
export { launch } from "./launch.js";
|
|
10
|
+
export { jobStatus, launchInline, runJob, startJob, waitForJob, } from "./jobs.js";
|
|
12
11
|
export { logs } from "./logs.js";
|
|
13
12
|
export { loadedAdapters } from "./registry.js";
|
|
14
13
|
export { type CheckResult, checkResultSchema, type DetectResult, detectResultSchema, type EvidenceResult, evidenceResultSchema, type InputResult, inputResultSchema, type JobView, jobViewSchema, type LaunchResult, type LogsResult, launchResultSchema, logsResultSchema, } from "./result.js";
|
package/dist/core/index.js
CHANGED
|
@@ -6,8 +6,7 @@ export { doctor } from "./doctor.js";
|
|
|
6
6
|
export { evidence } from "./evidence.js";
|
|
7
7
|
export { gc } from "./gc.js";
|
|
8
8
|
export { swipe, tap, typeText } from "./input.js";
|
|
9
|
-
export { jobStatus, runJob, startJob } from "./jobs.js";
|
|
10
|
-
export { launch } from "./launch.js";
|
|
9
|
+
export { jobStatus, launchInline, runJob, startJob, waitForJob, } from "./jobs.js";
|
|
11
10
|
export { logs } from "./logs.js";
|
|
12
11
|
export { loadedAdapters } from "./registry.js";
|
|
13
12
|
export { checkResultSchema, detectResultSchema, evidenceResultSchema, inputResultSchema, jobViewSchema, launchResultSchema, logsResultSchema, } from "./result.js";
|
package/dist/core/input.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import { axeBackend } from "./device/axe.js";
|
|
2
|
-
import { detectEnvironment, directions, firstWorking, } from "./device/backend.js";
|
|
2
|
+
import { detectEnvironment, directions, firstWorking, readScreen, secondsTo, } from "./device/backend.js";
|
|
3
3
|
import { maestroBackend } from "./device/maestro.js";
|
|
4
|
+
import { typeUntilShown } from "./device/typing.js";
|
|
4
5
|
import { firstLine } from "./log.js";
|
|
5
6
|
import { resolveRun } from "./run.js";
|
|
6
7
|
// Taps, typing and swipes on a launched app (decision 0009). Each acts once
|
|
7
8
|
// and says which backend did it; whether the app reacted is for `check`.
|
|
8
|
-
|
|
9
|
+
const backends = [axeBackend, maestroBackend];
|
|
10
|
+
const until = (seconds) => Date.now() + seconds * 1000;
|
|
11
|
+
// Runs `run` against the launched app. `run` returns extra result fields, or
|
|
12
|
+
// a `reason` when it failed.
|
|
13
|
+
async function act(what, { jobId }, run) {
|
|
9
14
|
const resolved = resolveRun({ jobId });
|
|
10
15
|
if ("reason" in resolved)
|
|
11
16
|
return { verdict: "failed", reason: resolved.reason };
|
|
12
|
-
const
|
|
17
|
+
const { device, appId } = resolved.run;
|
|
18
|
+
let first = {};
|
|
13
19
|
try {
|
|
14
|
-
const
|
|
15
|
-
|
|
20
|
+
const env = await detectEnvironment();
|
|
21
|
+
const extra = await run({
|
|
22
|
+
send: async (gesture) => {
|
|
23
|
+
const { backend, fellBack } = await firstWorking(what, env, backends, (b, bin) => gesture(b, { device, appId }, bin));
|
|
24
|
+
if (!first.backend) {
|
|
25
|
+
first = { backend, ...(fellBack ? { fellBack } : {}) };
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
read: (seconds) => readScreen(device, env, backends, until(seconds)).then((r) => r.nodes),
|
|
29
|
+
});
|
|
30
|
+
return { verdict: extra.reason ? "failed" : "ok", ...first, ...extra };
|
|
16
31
|
}
|
|
17
32
|
catch (error) {
|
|
18
33
|
return { verdict: "failed", reason: firstLine(error) };
|
|
@@ -37,14 +52,44 @@ export function tap(options) {
|
|
|
37
52
|
reason: "Give one target: id, text, or both x and y.",
|
|
38
53
|
});
|
|
39
54
|
}
|
|
40
|
-
|
|
55
|
+
const started = Date.now();
|
|
56
|
+
const done = act("tap", options, ({ send }) => send((b, where, bin) => b.tap(where, bin, target)).then(() => ({})));
|
|
57
|
+
if ("x" in target)
|
|
58
|
+
return done;
|
|
59
|
+
// The backends wait for an element: AXe up to 10 s, Maestro its own limit.
|
|
60
|
+
return done.then((result) => ({
|
|
61
|
+
...result,
|
|
62
|
+
seconds: Math.round((Date.now() - started) / 100) / 10,
|
|
63
|
+
}));
|
|
41
64
|
}
|
|
42
65
|
export function typeText(options) {
|
|
43
66
|
const { text } = options;
|
|
44
67
|
if (text.length === 0) {
|
|
45
68
|
return Promise.resolve({ verdict: "failed", reason: "Give text to type." });
|
|
46
69
|
}
|
|
47
|
-
|
|
70
|
+
// `ok` means the text shows on screen (issue 163, decision 0013). Tap and
|
|
71
|
+
// swipe cannot say that.
|
|
72
|
+
return act("type", options, async ({ send, read }) => {
|
|
73
|
+
const typed = await typeUntilShown({
|
|
74
|
+
type: (part, seconds) => {
|
|
75
|
+
const end = until(seconds);
|
|
76
|
+
return send((b, where, bin) => b.type(where, bin, part, secondsTo(end)));
|
|
77
|
+
},
|
|
78
|
+
read,
|
|
79
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
80
|
+
now: Date.now,
|
|
81
|
+
}, text);
|
|
82
|
+
return {
|
|
83
|
+
seconds: typed.seconds,
|
|
84
|
+
...(typed.retyped ? { retyped: typed.retyped } : {}),
|
|
85
|
+
...(typed.verdict === "failed" ? { reason: typed.reason } : {}),
|
|
86
|
+
...(typed.verdict === "secure"
|
|
87
|
+
? {
|
|
88
|
+
note: "Secure field: bullets grew by the text length; the text itself cannot be read.",
|
|
89
|
+
}
|
|
90
|
+
: {}),
|
|
91
|
+
};
|
|
92
|
+
});
|
|
48
93
|
}
|
|
49
94
|
const isDirection = (value) => directions.includes(value);
|
|
50
95
|
export function swipe(options) {
|
|
@@ -55,5 +100,5 @@ export function swipe(options) {
|
|
|
55
100
|
reason: `Give a direction: ${directions.join(", ")}.`,
|
|
56
101
|
});
|
|
57
102
|
}
|
|
58
|
-
return act("swipe", options, (b, where, bin) => b.swipe(where, bin, direction));
|
|
103
|
+
return act("swipe", options, ({ send }) => send((b, where, bin) => b.swipe(where, bin, direction)).then(() => ({})));
|
|
59
104
|
}
|
package/dist/core/isolate.js
CHANGED
|
@@ -22,13 +22,15 @@ export async function pickPort(taken) {
|
|
|
22
22
|
// matching `/Developer/Xcode/DerivedData/<name>/Build/Products/`.
|
|
23
23
|
export const derivedDataPath = (root) => join(homeDir(), "derived", worktreeKey(root), "Developer/Xcode/DerivedData", basename(root));
|
|
24
24
|
// Expo's build has no DerivedData option, so a directory placed first on PATH
|
|
25
|
-
// holds an xcodebuild that adds it.
|
|
25
|
+
// holds an xcodebuild that adds it. It also asks for xcodebuild's timing summary
|
|
26
|
+
// (#208) and, with ShowBuildOperationDuration, the total on the "** BUILD
|
|
27
|
+
// SUCCEEDED **" line; both land in Expo's raw log. Returns that directory.
|
|
26
28
|
export function xcodebuildShim(root, derivedData) {
|
|
27
29
|
const dir = join(homeDir(), "bin", worktreeKey(root));
|
|
28
30
|
mkdirSync(dir, { recursive: true });
|
|
29
31
|
const path = join(dir, "xcodebuild");
|
|
30
32
|
const quoted = `'${derivedData.replaceAll("'", "'\\''")}'`;
|
|
31
|
-
writeFileSync(path, `#!/bin/sh\nexec /usr/bin/xcodebuild -derivedDataPath ${quoted} "$@"\n`, { mode: 0o755 });
|
|
33
|
+
writeFileSync(path, `#!/bin/sh\nexec /usr/bin/xcodebuild -derivedDataPath ${quoted} -showBuildTimingSummary -ShowBuildOperationDuration=YES "$@"\n`, { mode: 0o755 });
|
|
32
34
|
return dir;
|
|
33
35
|
}
|
|
34
36
|
// Disk use of a folder in MB; absent counts as 0.
|
package/dist/core/jobs.d.ts
CHANGED
|
@@ -17,5 +17,7 @@ export type Handlers = {
|
|
|
17
17
|
};
|
|
18
18
|
export declare function createJob<K extends JobKind>(kind: K, input: Inputs[K]): Job;
|
|
19
19
|
export declare function startJob<K extends JobKind>(kind: K, input: Inputs[K], worker?: string): JobView;
|
|
20
|
+
export declare function launchInline(input: LaunchOptions, run?: Handlers): Promise<LaunchResult>;
|
|
20
21
|
export declare function runJob(id: string, run?: Handlers): Promise<void>;
|
|
21
22
|
export declare function jobStatus(id: string): JobView | undefined;
|
|
23
|
+
export declare function waitForJob(id: string, waitSeconds: number, read?: (id: string) => JobView | undefined, signal?: AbortSignal): Promise<JobView | undefined>;
|
package/dist/core/jobs.js
CHANGED
|
@@ -72,6 +72,13 @@ export function startJob(kind, input, worker = defaultWorker) {
|
|
|
72
72
|
child.unref();
|
|
73
73
|
return view(job);
|
|
74
74
|
}
|
|
75
|
+
// Runs a launch in this process and leaves the same job record as a started
|
|
76
|
+
// job, so a later launch finds its dev server and log stream.
|
|
77
|
+
export async function launchInline(input, run = handlers) {
|
|
78
|
+
const { id } = createJob("launch", input);
|
|
79
|
+
await runJob(id, run);
|
|
80
|
+
return readJob(id)?.result;
|
|
81
|
+
}
|
|
75
82
|
const execute = (job, run, report) => job.kind === "launch"
|
|
76
83
|
? run.launch(job.input, report)
|
|
77
84
|
: run.check(job.input, report);
|
|
@@ -112,3 +119,27 @@ export function jobStatus(id) {
|
|
|
112
119
|
const current = readJob(id);
|
|
113
120
|
return current && view(current);
|
|
114
121
|
}
|
|
122
|
+
// Like jobStatus, but when the job is queued or running, reads it again every
|
|
123
|
+
// half second until it ends or `waitSeconds` pass. A wait of 0 answers at once.
|
|
124
|
+
// No read starts after the deadline, so a slow read can't push the answer past
|
|
125
|
+
// it (#198). An aborted `signal` (the caller cancelled) ends the wait at once.
|
|
126
|
+
export async function waitForJob(id, waitSeconds, read = jobStatus, signal) {
|
|
127
|
+
const deadline = Date.now() + waitSeconds * 1000;
|
|
128
|
+
let job = read(id);
|
|
129
|
+
while (job && (job.status === "queued" || job.status === "running")) {
|
|
130
|
+
const left = deadline - Date.now();
|
|
131
|
+
await new Promise((resolve) => {
|
|
132
|
+
const done = () => {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
signal?.removeEventListener("abort", done);
|
|
135
|
+
resolve();
|
|
136
|
+
};
|
|
137
|
+
const timer = setTimeout(done, Math.min(500, left));
|
|
138
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
139
|
+
});
|
|
140
|
+
if (signal?.aborted || Date.now() >= deadline)
|
|
141
|
+
break;
|
|
142
|
+
job = read(id);
|
|
143
|
+
}
|
|
144
|
+
return job;
|
|
145
|
+
}
|
package/dist/core/launch.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export type LaunchOptions = {
|
|
|
5
5
|
timeoutSeconds?: number;
|
|
6
6
|
};
|
|
7
7
|
export declare function stopEarlierServer(root: string, port: number): Promise<void>;
|
|
8
|
+
export declare function recordTiming(root: string, buildLog: string, since: number): Promise<number | undefined>;
|
|
8
9
|
export declare function launch(options?: LaunchOptions, report?: (step: string) => void): Promise<LaunchResult>;
|