emd-agents 0.0.0-stage → 0.14.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 (77) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +121 -2
  4. package/dist/adapters/expo/index.d.ts +3 -0
  5. package/dist/adapters/expo/index.js +55 -0
  6. package/dist/bin.d.ts +2 -0
  7. package/dist/bin.js +11 -0
  8. package/dist/cli/main.d.ts +1 -0
  9. package/dist/cli/main.js +265 -0
  10. package/dist/core/adapter.d.ts +32 -0
  11. package/dist/core/adapter.js +3 -0
  12. package/dist/core/check.d.ts +20 -0
  13. package/dist/core/check.js +214 -0
  14. package/dist/core/checkrecord.d.ts +22 -0
  15. package/dist/core/checkrecord.js +34 -0
  16. package/dist/core/detect.d.ts +2 -0
  17. package/dist/core/detect.js +27 -0
  18. package/dist/core/device/axe.d.ts +10 -0
  19. package/dist/core/device/axe.js +66 -0
  20. package/dist/core/device/backend.d.ts +43 -0
  21. package/dist/core/device/backend.js +72 -0
  22. package/dist/core/device/maestro.d.ts +4 -0
  23. package/dist/core/device/maestro.js +86 -0
  24. package/dist/core/device/screen.d.ts +9 -0
  25. package/dist/core/device/screen.js +7 -0
  26. package/dist/core/doctor.d.ts +12 -0
  27. package/dist/core/doctor.js +70 -0
  28. package/dist/core/evidence.d.ts +9 -0
  29. package/dist/core/evidence.js +107 -0
  30. package/dist/core/gc.d.ts +22 -0
  31. package/dist/core/gc.js +172 -0
  32. package/dist/core/index.d.ts +17 -0
  33. package/dist/core/index.js +16 -0
  34. package/dist/core/input.d.ts +15 -0
  35. package/dist/core/input.js +59 -0
  36. package/dist/core/isolate.d.ts +4 -0
  37. package/dist/core/isolate.js +43 -0
  38. package/dist/core/jobs.d.ts +21 -0
  39. package/dist/core/jobs.js +114 -0
  40. package/dist/core/jobstore.d.ts +21 -0
  41. package/dist/core/jobstore.js +45 -0
  42. package/dist/core/launch.d.ts +8 -0
  43. package/dist/core/launch.js +273 -0
  44. package/dist/core/log.d.ts +5 -0
  45. package/dist/core/log.js +54 -0
  46. package/dist/core/logs.d.ts +19 -0
  47. package/dist/core/logs.js +122 -0
  48. package/dist/core/owned.d.ts +19 -0
  49. package/dist/core/owned.js +91 -0
  50. package/dist/core/probe.d.ts +2 -0
  51. package/dist/core/probe.js +14 -0
  52. package/dist/core/process.d.ts +10 -0
  53. package/dist/core/process.js +32 -0
  54. package/dist/core/project.d.ts +6 -0
  55. package/dist/core/project.js +76 -0
  56. package/dist/core/registry.d.ts +3 -0
  57. package/dist/core/registry.js +13 -0
  58. package/dist/core/result.d.ts +248 -0
  59. package/dist/core/result.js +147 -0
  60. package/dist/core/run.d.ts +15 -0
  61. package/dist/core/run.js +22 -0
  62. package/dist/core/setup.d.ts +29 -0
  63. package/dist/core/setup.js +202 -0
  64. package/dist/core/simulator.d.ts +21 -0
  65. package/dist/core/simulator.js +107 -0
  66. package/dist/core/state.d.ts +2 -0
  67. package/dist/core/state.js +9 -0
  68. package/dist/core/tool.d.ts +5 -0
  69. package/dist/core/tool.js +54 -0
  70. package/dist/core/version.d.ts +1 -0
  71. package/dist/core/version.js +5 -0
  72. package/dist/core/workspace.d.ts +1 -0
  73. package/dist/core/workspace.js +109 -0
  74. package/dist/mcp/server.d.ts +1 -0
  75. package/dist/mcp/server.js +188 -0
  76. package/package.json +58 -4
  77. package/skills/emd/SKILL.md +35 -0
@@ -0,0 +1,66 @@
1
+ import { join } from "node:path";
2
+ import { homeDir } from "../state.js";
3
+ import { runTool } from "../tool.js";
4
+ // The AXe release `setup` installs. e2e gets AXe through `setup`, so this is
5
+ // its only pin. Its release archive, not Homebrew: Homebrew floats the version
6
+ // and refused AXe on older Xcode (decision 0005).
7
+ export const axePin = {
8
+ version: "1.8.0",
9
+ sha256: "7b76340b72e90d0f211bc7c4636f15009076eff07acef2f2b632b175debd8834",
10
+ url: "https://github.com/cameroncooke/AXe/releases/download/v1.8.0/AXe-macOS-v1.8.0-universal.tar.gz",
11
+ };
12
+ // Where `setup` puts it, with its frameworks: a user folder, so no admin rights.
13
+ export const axeDir = () => join(homeDir(), "tools", `axe-${axePin.version}`);
14
+ const str = (value) => typeof value === "string" ? value : "";
15
+ // The tree from `axe describe-ui`, flattened to the nodes worth matching. AXe
16
+ // names the accessibility identifier (the testID) AXUniqueId, and the visible
17
+ // text or label AXLabel, with AXValue and title as other places for text. Empty
18
+ // fields are null.
19
+ export function parseAxe(output) {
20
+ const start = output.search(/[[{]/);
21
+ const root = JSON.parse(start >= 0 ? output.slice(start) : output);
22
+ const nodes = [];
23
+ const walk = (node) => {
24
+ const id = str(node.AXUniqueId);
25
+ const texts = [
26
+ ...new Set([str(node.AXLabel), str(node.AXValue), str(node.title)].filter(Boolean)),
27
+ ];
28
+ if (id !== "" || texts.length > 0)
29
+ nodes.push({ id, texts });
30
+ if (Array.isArray(node.children)) {
31
+ for (const child of node.children)
32
+ walk(child);
33
+ }
34
+ };
35
+ for (const top of Array.isArray(root) ? root : [root])
36
+ walk(top);
37
+ return nodes;
38
+ }
39
+ // The accessibility tree of what is on the simulator's screen now. AXe talks to
40
+ // the simulator directly, with no driver to start.
41
+ async function readScreen(device, bin) {
42
+ const { stdout } = await runTool("axe describe-ui", bin, ["describe-ui", "--udid", device], 120);
43
+ return parseAxe(stdout);
44
+ }
45
+ // One AXe command on the simulator. AXe needs no driver, so a gesture takes
46
+ // about a second (experiments/tap-tools.md).
47
+ const run = async (bin, { device }, command, args) => {
48
+ await runTool(`axe ${command}`, bin, [command, "--udid", device, ...args], 60);
49
+ };
50
+ // By testID (AXUniqueId) or label (AXLabel), AXe waits up to 5 s for the
51
+ // element to appear, then taps its activation point.
52
+ const targetArgs = (target) => "id" in target
53
+ ? ["--id", target.id, "--wait-timeout", "5"]
54
+ : "text" in target
55
+ ? ["--label", target.text, "--wait-timeout", "5"]
56
+ : ["-x", String(target.x), "-y", String(target.y)];
57
+ export const axeBackend = {
58
+ id: "axe",
59
+ readScreen,
60
+ tap: (where, bin, target) => run(bin, where, "tap", targetArgs(target)),
61
+ // `--` so text that starts with a dash is typed, not read as an option.
62
+ type: (where, bin, text) => run(bin, where, "type", ["--", text]),
63
+ // AXe's preset scrolls 200 points through the screen's centre, the finger
64
+ // moving the way named.
65
+ swipe: (where, bin, direction) => run(bin, where, "gesture", [`scroll-${direction}`]),
66
+ };
@@ -0,0 +1,43 @@
1
+ import type { UiNode } from "./screen.js";
2
+ export declare const backendIds: readonly ["axe", "maestro"];
3
+ export type BackendId = (typeof backendIds)[number];
4
+ export type Target = {
5
+ id: string;
6
+ } | {
7
+ text: string;
8
+ } | {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ export declare const directions: readonly ["up", "down", "left", "right"];
13
+ export type Direction = (typeof directions)[number];
14
+ export type Where = {
15
+ device: string;
16
+ appId: string;
17
+ };
18
+ export interface DeviceBackend {
19
+ id: BackendId;
20
+ readScreen(device: string, bin: string): Promise<UiNode[]>;
21
+ tap(where: Where, bin: string, target: Target): Promise<void>;
22
+ type(where: Where, bin: string, text: string): Promise<void>;
23
+ swipe(where: Where, bin: string, direction: Direction): Promise<void>;
24
+ }
25
+ export type Environment = Partial<Record<BackendId, string>>;
26
+ type Fallback = {
27
+ backend: BackendId;
28
+ reason: string;
29
+ };
30
+ export type Acted<T> = {
31
+ value: T;
32
+ backend: BackendId;
33
+ fellBack?: Fallback[];
34
+ };
35
+ export declare function firstWorking<B extends {
36
+ id: BackendId;
37
+ }, T>(what: string, env: Environment, backends: B[], act: (backend: B, bin: string) => Promise<T>): Promise<Acted<T>>;
38
+ export type ScreenRead = Omit<Acted<UiNode[]>, "value"> & {
39
+ nodes: UiNode[];
40
+ };
41
+ export declare function readScreen(device: string, env: Environment, backends: Pick<DeviceBackend, "id" | "readScreen">[]): Promise<ScreenRead>;
42
+ export declare function detectEnvironment(): Promise<Environment>;
43
+ export {};
@@ -0,0 +1,72 @@
1
+ import { accessSync, constants } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { delimiter, join } from "node:path";
4
+ import { firstLine } from "../log.js";
5
+ import { axeDir } from "./axe.js";
6
+ // Decision 0004: device actions go through backends, and core picks the best
7
+ // one that is available on this machine, falling back to the next. Tap, type
8
+ // and swipe joined reading the screen in decision 0009.
9
+ export const backendIds = ["axe", "maestro"];
10
+ // The way the finger moves: "up" shows what is further down.
11
+ export const directions = ["up", "down", "left", "right"];
12
+ // Tries the backends in the order given (best first), skipping any that cannot
13
+ // run here and moving on from any that fails, and says which one answered.
14
+ export async function firstWorking(what, env, backends, act) {
15
+ const fellBack = [];
16
+ for (const backend of backends) {
17
+ const bin = env[backend.id];
18
+ if (!bin) {
19
+ fellBack.push({
20
+ backend: backend.id,
21
+ reason: `${backend.id} is not installed`,
22
+ });
23
+ continue;
24
+ }
25
+ try {
26
+ const value = await act(backend, bin);
27
+ return {
28
+ value,
29
+ backend: backend.id,
30
+ ...(fellBack.length > 0 ? { fellBack } : {}),
31
+ };
32
+ }
33
+ catch (error) {
34
+ fellBack.push({ backend: backend.id, reason: firstLine(error) });
35
+ }
36
+ }
37
+ throw new Error(`no backend could ${what} (${fellBack.map((f) => `${f.backend}: ${f.reason}`).join("; ")})`);
38
+ }
39
+ export async function readScreen(device, env, backends) {
40
+ const { value, ...rest } = await firstWorking("read the screen", env, backends, async (backend, bin) => {
41
+ const nodes = await backend.readScreen(device, bin);
42
+ // Every good read includes the app's root node, so none means the read
43
+ // failed (AXe sometimes reads nothing right after a relaunch).
44
+ if (nodes.length === 0)
45
+ throw new Error("returned an empty tree");
46
+ return nodes;
47
+ });
48
+ return { nodes: value, ...rest };
49
+ }
50
+ function findExecutable(name, extraDirs) {
51
+ const dirs = [
52
+ ...(process.env.PATH ?? "").split(delimiter),
53
+ ...extraDirs,
54
+ "/opt/homebrew/bin",
55
+ "/usr/local/bin",
56
+ ];
57
+ for (const dir of dirs) {
58
+ const path = join(dir, name);
59
+ try {
60
+ accessSync(path, constants.X_OK);
61
+ return path;
62
+ }
63
+ catch { }
64
+ }
65
+ return undefined;
66
+ }
67
+ export async function detectEnvironment() {
68
+ return {
69
+ axe: findExecutable("axe", [axeDir()]),
70
+ maestro: findExecutable("maestro", [join(homedir(), ".maestro", "bin")]),
71
+ };
72
+ }
@@ -0,0 +1,4 @@
1
+ import type { DeviceBackend } from "./backend.js";
2
+ import type { UiNode } from "./screen.js";
3
+ export declare function parseMaestro(output: string): UiNode[];
4
+ export declare const maestroBackend: DeviceBackend;
@@ -0,0 +1,86 @@
1
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { runTool } from "../tool.js";
5
+ // Where Maestro puts a node's visible text or label.
6
+ const textKeys = ["text", "accessibilityText", "value", "title"];
7
+ // The tree from `maestro hierarchy`, flattened to the nodes worth matching.
8
+ export function parseMaestro(output) {
9
+ const start = output.indexOf("{");
10
+ const root = JSON.parse(start >= 0 ? output.slice(start) : output);
11
+ const nodes = [];
12
+ const walk = (node) => {
13
+ const attributes = node.attributes ?? {};
14
+ const id = attributes["resource-id"];
15
+ const texts = [
16
+ ...new Set(textKeys
17
+ .map((key) => attributes[key])
18
+ .filter((value) => typeof value === "string" && value !== "")),
19
+ ];
20
+ if (typeof id === "string" && id !== "")
21
+ nodes.push({ id, texts });
22
+ else if (texts.length > 0)
23
+ nodes.push({ id: "", texts });
24
+ for (const child of node.children ?? [])
25
+ walk(child);
26
+ };
27
+ walk(root);
28
+ return nodes;
29
+ }
30
+ // Maestro's driver can take minutes to start on a busy host.
31
+ const driverEnv = () => ({
32
+ MAESTRO_DRIVER_STARTUP_TIMEOUT: process.env.MAESTRO_DRIVER_STARTUP_TIMEOUT ?? "300000",
33
+ });
34
+ // The accessibility tree of what is on the simulator's screen now. Maestro
35
+ // starts and stops its XCUITest driver on every call, which takes about 20 s,
36
+ // and about 50 s for the first call after an app launch.
37
+ async function readScreen(device, bin) {
38
+ try {
39
+ const { stdout } = await runTool("maestro hierarchy", bin, ["--device", device, "hierarchy"], 240, { env: driverEnv() });
40
+ return parseMaestro(stdout);
41
+ }
42
+ catch (error) {
43
+ // Maestro can print the tree and still exit badly while shutting its
44
+ // driver down; a tree on stdout is the answer either way.
45
+ const { stdout } = error;
46
+ if (stdout) {
47
+ try {
48
+ return parseMaestro(stdout);
49
+ }
50
+ catch { }
51
+ }
52
+ throw error;
53
+ }
54
+ }
55
+ // One step as a Maestro flow for the app. JSON strings are valid YAML
56
+ // strings. A run takes 80 to 100 s (experiments/tap-tools.md).
57
+ async function runStep({ device, appId }, bin, step) {
58
+ const dir = mkdtempSync(join(tmpdir(), "emd-maestro-"));
59
+ try {
60
+ const flow = join(dir, "step.yaml");
61
+ writeFileSync(flow, `appId: ${JSON.stringify(appId)}\n---\n- ${step}\n`);
62
+ await runTool("maestro test", bin, ["--device", device, "test", flow], 240, {
63
+ env: driverEnv(),
64
+ });
65
+ }
66
+ finally {
67
+ rmSync(dir, { recursive: true, force: true });
68
+ }
69
+ }
70
+ // Maestro matches `id` and `text` as regular expressions, so both are escaped.
71
+ const literal = (text) => JSON.stringify(text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
72
+ const tapStep = (target) => {
73
+ if ("id" in target)
74
+ return `tapOn: { id: ${literal(target.id)} }`;
75
+ if ("text" in target)
76
+ return `tapOn: { text: ${literal(target.text)} }`;
77
+ // Unchecked whether Maestro's iOS points match AXe's, so points stay with AXe.
78
+ throw new Error("taps at a point need AXe");
79
+ };
80
+ export const maestroBackend = {
81
+ id: "maestro",
82
+ readScreen,
83
+ tap: (where, bin, target) => runStep(where, bin, tapStep(target)),
84
+ type: (where, bin, text) => runStep(where, bin, `inputText: ${JSON.stringify(text)}`),
85
+ swipe: (where, bin, direction) => runStep(where, bin, `swipe: { direction: ${direction.toUpperCase()} }`),
86
+ };
@@ -0,0 +1,9 @@
1
+ export type UiNode = {
2
+ id: string;
3
+ texts: string[];
4
+ };
5
+ export type ElementSpec = {
6
+ id?: string;
7
+ text?: string;
8
+ };
9
+ export declare function hasElement(nodes: UiNode[], spec: ElementSpec): boolean;
@@ -0,0 +1,7 @@
1
+ // What every backend returns for a screen read: the nodes of the accessibility
2
+ // tree that have something to match on, in one shape.
3
+ // Found when one node has the id and the text asked for. Exact matches.
4
+ export function hasElement(nodes, spec) {
5
+ return nodes.some((node) => (spec.id === undefined || node.id === spec.id) &&
6
+ (spec.text === undefined || node.texts.includes(spec.text)));
7
+ }
@@ -0,0 +1,12 @@
1
+ type Check = {
2
+ name: string;
3
+ status: "ok" | "missing";
4
+ detail?: string;
5
+ fix?: string;
6
+ };
7
+ export type DoctorResult = {
8
+ verdict: "ready" | "missing";
9
+ checks: Check[];
10
+ };
11
+ export declare function doctor(): Promise<DoctorResult>;
12
+ export {};
@@ -0,0 +1,70 @@
1
+ import { detectEnvironment } from "./device/backend.js";
2
+ import { firstLine } from "./log.js";
3
+ import { listDevices } from "./simulator.js";
4
+ import { runTool } from "./tool.js";
5
+ const minNode = 22;
6
+ // What EMD needs on this machine to launch and check an Expo app on the iOS
7
+ // simulator (vision.md). It only reads; it never installs.
8
+ export async function doctor() {
9
+ const checks = [];
10
+ const major = Number(process.versions.node.split(".")[0]);
11
+ checks.push(major >= minNode
12
+ ? { name: "node", status: "ok", detail: process.versions.node }
13
+ : {
14
+ name: "node",
15
+ status: "missing",
16
+ detail: process.versions.node,
17
+ fix: `Install Node ${minNode} or newer.`,
18
+ });
19
+ if (process.platform !== "darwin") {
20
+ checks.push({
21
+ name: "macos",
22
+ status: "missing",
23
+ detail: process.platform,
24
+ fix: "iOS simulators need macOS. `detect` still works here.",
25
+ });
26
+ return done(checks);
27
+ }
28
+ checks.push({ name: "macos", status: "ok" });
29
+ try {
30
+ const { stdout } = await runTool("xcodebuild -version", "xcodebuild", ["-version"], 60);
31
+ checks.push({ name: "xcode", status: "ok", detail: firstLine(stdout) });
32
+ }
33
+ catch (error) {
34
+ checks.push({
35
+ name: "xcode",
36
+ status: "missing",
37
+ detail: firstLine(error),
38
+ fix: "Install Xcode from the App Store, open it once, then run `sudo xcode-select -s /Applications/Xcode.app`.",
39
+ });
40
+ return done(checks);
41
+ }
42
+ const iphones = await listDevices().then((devices) => devices.filter((d) => d.name.startsWith("iPhone")).length, () => 0);
43
+ checks.push(iphones > 0
44
+ ? {
45
+ name: "simulator",
46
+ status: "ok",
47
+ detail: `${iphones} iPhone simulators`,
48
+ }
49
+ : {
50
+ name: "simulator",
51
+ status: "missing",
52
+ fix: "In Xcode, Settings > Components, add an iOS simulator runtime. It comes with iPhone simulators.",
53
+ });
54
+ // Taps, typing, swipes and element checks go through AXe or Maestro
55
+ // (decisions 0004, 0009).
56
+ const { axe, maestro } = await detectEnvironment();
57
+ checks.push(axe || maestro
58
+ ? { name: "device tool", status: "ok", detail: axe ? "axe" : "maestro" }
59
+ : {
60
+ name: "device tool",
61
+ status: "missing",
62
+ detail: "Taps, typing, swipes and element checks need AXe or Maestro.",
63
+ fix: "Run `emd setup`. It installs AXe.",
64
+ });
65
+ return done(checks);
66
+ }
67
+ const done = (checks) => ({
68
+ verdict: checks.some((c) => c.status === "missing") ? "missing" : "ready",
69
+ checks,
70
+ });
@@ -0,0 +1,9 @@
1
+ import { type LogsOptions } from "./logs.js";
2
+ import type { CheckResult, EvidenceResult, LogsResult } from "./result.js";
3
+ import { type RunRef } from "./run.js";
4
+ export declare function recordCheck(logDir: string, name: string, result: CheckResult): void;
5
+ type Deps = {
6
+ logs: (options: LogsOptions) => Promise<LogsResult>;
7
+ };
8
+ export declare function evidence(ref: RunRef, deps?: Deps): Promise<EvidenceResult>;
9
+ export {};
@@ -0,0 +1,107 @@
1
+ import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
2
+ import { basename, join } from "node:path";
3
+ import { readRecord } from "./checkrecord.js";
4
+ import { logs as readLogs } from "./logs.js";
5
+ import { worktreeKey } from "./owned.js";
6
+ import { inspectProject } from "./project.js";
7
+ import { resolveRun } from "./run.js";
8
+ // Every check that ran against a run is appended here, in the run's folder, so
9
+ // the bundle lists what was checked and nothing else.
10
+ const checksFile = (logDir) => join(logDir, "checks.jsonl");
11
+ export function recordCheck(logDir, name, result) {
12
+ mkdirSync(logDir, { recursive: true });
13
+ const line = { time: new Date().toISOString(), name, result };
14
+ appendFileSync(checksFile(logDir), `${JSON.stringify(line)}\n`);
15
+ }
16
+ function recordedChecks(logDir) {
17
+ try {
18
+ return readFileSync(checksFile(logDir), "utf8")
19
+ .split("\n")
20
+ .filter(Boolean)
21
+ .map((line) => JSON.parse(line));
22
+ }
23
+ catch {
24
+ return [];
25
+ }
26
+ }
27
+ // The layout is part of the tool result, so no agent has to look it up.
28
+ const layout = {
29
+ "manifest.json": "The run, every check that ran with its result, the worktree's checks whose last verdict is not passed (notPassed), and the files below.",
30
+ "logs.json": "Tagged log lines the app wrote during the run, oldest first.",
31
+ "screenshots/": "The screenshot each check took, named as in the manifest.",
32
+ "flows/": "The project's Maestro flow files, copied as they are.",
33
+ };
34
+ // Gathers a run's evidence into <run folder>/evidence. Nothing is timestamped
35
+ // with the time of writing, so the same run gives the same bundle.
36
+ export async function evidence(ref, deps = { logs: readLogs }) {
37
+ const failed = (reason) => ({
38
+ verdict: "failed",
39
+ reason,
40
+ });
41
+ const resolved = resolveRun(ref);
42
+ if ("reason" in resolved)
43
+ return failed(resolved.reason);
44
+ const { device, appId, since, root, logDir } = resolved.run;
45
+ const lines = await deps.logs({ jobId: ref.jobId, limit: 500 });
46
+ if (lines.verdict !== "ok") {
47
+ return failed(lines.reason ?? "Could not read the logs.");
48
+ }
49
+ const dir = join(logDir, "evidence");
50
+ rmSync(dir, { recursive: true, force: true });
51
+ mkdirSync(join(dir, "screenshots"), { recursive: true });
52
+ const screenshots = [];
53
+ const checks = recordedChecks(logDir).map(({ time, name, result }) => {
54
+ const shot = result.secondOpinion?.screenshot;
55
+ if (!shot || !existsSync(shot))
56
+ return { time, name, result };
57
+ const file = `screenshots/${basename(shot)}`;
58
+ copyFileSync(shot, join(dir, file));
59
+ screenshots.push(file);
60
+ return {
61
+ time,
62
+ name,
63
+ result: {
64
+ ...result,
65
+ secondOpinion: { ...result.secondOpinion, screenshot: file },
66
+ },
67
+ };
68
+ });
69
+ const flows = [];
70
+ for (const flow of (await inspectProject(root)).maestroFlows ?? []) {
71
+ mkdirSync(join(dir, "flows"), { recursive: true });
72
+ copyFileSync(join(root, flow), join(dir, "flows", basename(flow)));
73
+ flows.push(`flows/${basename(flow)}`);
74
+ }
75
+ // Checks in this worktree, from any run, that never got back to a pass:
76
+ // one an agent gave up on stays in view (decision 0010).
77
+ const notPassed = Object.entries(readRecord(worktreeKey(root)).names)
78
+ .filter(([, { last }]) => last !== "passed")
79
+ .map(([name, { last, expected }]) => ({ name, verdict: last, expected }));
80
+ const logLines = lines.lines ?? [];
81
+ writeFileSync(join(dir, "logs.json"), JSON.stringify(logLines, null, 2));
82
+ const manifest = {
83
+ run: {
84
+ jobId: ref.jobId,
85
+ device,
86
+ appId,
87
+ since: since.toISOString(),
88
+ root,
89
+ },
90
+ checks,
91
+ notPassed,
92
+ logs: { file: "logs.json", total: lines.total ?? logLines.length },
93
+ screenshots,
94
+ flows,
95
+ };
96
+ writeFileSync(join(dir, "manifest.json"), JSON.stringify(manifest, null, 2));
97
+ return {
98
+ verdict: "written",
99
+ dir,
100
+ layout,
101
+ checks: checks.length,
102
+ ...(notPassed.length > 0 && { notPassed: notPassed.map((n) => n.name) }),
103
+ logLines: logLines.length,
104
+ screenshots: screenshots.length,
105
+ flows: flows.length,
106
+ };
107
+ }
@@ -0,0 +1,22 @@
1
+ export type GcResult = {
2
+ verdict: "dry-run" | "applied" | "failed";
3
+ reason?: string;
4
+ entries: {
5
+ key: string;
6
+ root: string;
7
+ simulator?: string;
8
+ derivedData?: string;
9
+ mb: number;
10
+ status: "stale" | "removed" | "skipped" | "failed";
11
+ reason?: string;
12
+ }[];
13
+ unreferencedSimulators: {
14
+ id: string;
15
+ name: string;
16
+ }[];
17
+ totalMB: number;
18
+ freedMB?: number;
19
+ };
20
+ export declare function gc(options?: {
21
+ apply?: boolean;
22
+ }): Promise<GcResult>;