@e2e-dev/desktop 0.0.0 → 0.0.1-nightly-20261123030205

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 CHANGED
@@ -52,7 +52,8 @@ test('signs in', async ({ app, screen }) => {
52
52
 
53
53
  ## How it works
54
54
 
55
- - `app.open()` launches the app fresh, in the background, after quitting the
55
+ - `app.open()` launches the app fresh, in the background (in the foreground
56
+ with `desktop({ headed: true })` or `e2e run --headed`), after quitting the
56
57
  copy the engine launched before. A copy you opened yourself is never read,
57
58
  driven, or quit. Every test ends with the app quit.
58
59
  - The app gets only `HOME`, `USER`, `LOGNAME`, `SHELL`, `PATH`, `TMPDIR`,
package/dist/.build.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.0.0"}
1
+ {"version":"0.0.1-nightly-20261123030205"}
package/dist/binary.js CHANGED
@@ -7,7 +7,7 @@
7
7
  import { createHash, randomUUID } from 'node:crypto';
8
8
  import { execFile } from 'node:child_process';
9
9
  import { constants } from 'node:fs';
10
- import { access, chmod, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
10
+ import { access, chmod, mkdir, mkdtemp, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
11
11
  import { homedir } from 'node:os';
12
12
  import path from 'node:path';
13
13
  import { promisify } from 'node:util';
@@ -46,6 +46,16 @@ function executableName() {
46
46
  }
47
47
  /** The file an unpacked release is stamped with once its archive's digest checked out: the digest itself. */
48
48
  const STAMP = '.verified';
49
+ /** Whether `file` is a regular file this process may run: a directory passes the execute check on macOS, being searchable, but cannot be run. */
50
+ async function executableFile(file) {
51
+ try {
52
+ await access(file, constants.X_OK);
53
+ return (await stat(file)).isFile();
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ }
49
59
  /**
50
60
  * Whether the cache entry is a whole, checked release: stamped with the
51
61
  * pinned digest, its executable still executable, and on macOS the helper
@@ -56,9 +66,10 @@ async function usable(directory, digest) {
56
66
  try {
57
67
  if ((await readFile(path.join(directory, STAMP), 'utf8')).trim() !== digest)
58
68
  return false;
59
- await access(path.join(directory, executableName()), constants.X_OK);
60
- if (process.platform === 'darwin')
61
- await access(path.join(directory, 'agent-desktop-macos-helper'), constants.X_OK);
69
+ if (!(await executableFile(path.join(directory, executableName()))))
70
+ return false;
71
+ if (process.platform === 'darwin' && !(await executableFile(path.join(directory, 'agent-desktop-macos-helper'))))
72
+ return false;
62
73
  return true;
63
74
  }
64
75
  catch {
@@ -99,12 +110,8 @@ export function pinnedExecutable(env) {
99
110
  export async function resolveExecutable(binary, projectRoot, env) {
100
111
  if (binary !== undefined) {
101
112
  const resolved = path.resolve(projectRoot, binary);
102
- try {
103
- await access(resolved, constants.X_OK);
104
- }
105
- catch {
113
+ if (!(await executableFile(resolved)))
106
114
  throw new ConfigurationError('INVALID_CONFIG', `desktop({ binary }) names ${resolved}, which is not an executable file`);
107
- }
108
115
  return resolved;
109
116
  }
110
117
  const target = releaseTarget();
@@ -132,6 +139,7 @@ export async function installPinned(env, signal, log, digests = ARCHIVE_DIGESTS)
132
139
  }
133
140
  const directory = cacheDirectory(env, target);
134
141
  const executable = path.join(directory, executableName());
142
+ await sweepLeftovers(directory);
135
143
  if (await usable(directory, digest))
136
144
  return executable;
137
145
  const archive = `agent-desktop-v${AGENT_DESKTOP_VERSION}-${target}.tar.gz`;
@@ -179,6 +187,26 @@ async function download(url, archive, digest, directory, signal) {
179
187
  await rm(staging, { recursive: true, force: true });
180
188
  }
181
189
  }
190
+ /** How old an unpack or a moved-aside entry must be before a later install removes it: no install still running is using one that old. */
191
+ const LEFTOVER_AGE_MS = 24 * 60 * 60 * 1000;
192
+ /**
193
+ * Removes the unpacks (`.partial-*`) and moved-aside entries (`.stale-*`)
194
+ * beside the cache entry that an install killed mid-way left behind, each
195
+ * a whole copy of agent-desktop. Only ones a day old go: an install running
196
+ * now may still be using a newer one. Best effort; a failure leaves them.
197
+ */
198
+ async function sweepLeftovers(directory) {
199
+ const parent = path.dirname(directory);
200
+ const base = path.basename(directory);
201
+ for (const entry of await readdir(parent).catch(() => [])) {
202
+ if (!entry.startsWith(`${base}.partial-`) && !entry.startsWith(`${base}.stale-`))
203
+ continue;
204
+ const leftover = path.join(parent, entry);
205
+ const old = await stat(leftover).then((info) => Date.now() - info.mtimeMs > LEFTOVER_AGE_MS, () => false);
206
+ if (old)
207
+ await rm(leftover, { recursive: true, force: true }).catch(() => undefined);
208
+ }
209
+ }
182
210
  /** How many times a publish looks again after another run changed the cache entry under it. */
183
211
  const PUBLISH_TRIES = 10;
184
212
  /**
@@ -190,8 +218,10 @@ const PUBLISH_TRIES = 10;
190
218
  * whole once moved (another run put it there meanwhile) goes back.
191
219
  */
192
220
  async function publish(staging, directory, digest) {
221
+ // Why the last rename into place failed: an entry another run put there, or something else (permissions, a full disk), which the error names.
222
+ let failure;
193
223
  for (let tries = 0; tries < PUBLISH_TRIES; tries += 1) {
194
- if (await rename(staging, directory).then(() => true, () => false))
224
+ if (await rename(staging, directory).then(() => true, (cause) => ((failure = cause), false)))
195
225
  return;
196
226
  if (await usable(directory, digest))
197
227
  return;
@@ -205,5 +235,6 @@ async function publish(staging, directory, digest) {
205
235
  }
206
236
  if (await usable(directory, digest))
207
237
  return;
208
- throw new InfrastructureError('AGENT_DESKTOP_INSTALL_FAILED', `could not put agent-desktop in place at ${directory}: other runs kept changing it`);
238
+ const raced = failure === undefined || failure.code === 'EEXIST' || failure.code === 'ENOTEMPTY';
239
+ throw new InfrastructureError('AGENT_DESKTOP_INSTALL_FAILED', `could not put agent-desktop in place at ${directory}: ${raced ? 'other runs kept changing it' : failure?.message}`, failure === undefined ? {} : { cause: failure });
209
240
  }
@@ -4,6 +4,7 @@
4
4
  * loads the test runner. The main entry re-exports all of it beside `test`.
5
5
  */
6
6
  export { desktop } from './engine.ts';
7
+ export type { DesktopEngine } from './engine.ts';
7
8
  /** The engine factory again, as the default export: what `e2e mcp` calls when `open_session` names this package as its `engine`. */
8
9
  export { desktop as default } from './engine.ts';
9
10
  export type { DesktopOptions, DesktopPlatform } from './options.ts';
package/dist/engine.d.ts CHANGED
@@ -8,6 +8,13 @@
8
8
  import { type EngineHandle } from '@e2e-dev/core/engine';
9
9
  import type { DesktopFixtures } from './fixtures.ts';
10
10
  import { type DesktopOptions } from './options.ts';
11
+ /**
12
+ * The handle `desktop()` returns. Declared here so a config's inferred type
13
+ * names this package: a project sees `@e2e-dev/core` only through its
14
+ * dependencies, and TypeScript cannot write that path in a declaration.
15
+ */
16
+ export interface DesktopEngine extends EngineHandle<DesktopFixtures> {
17
+ }
11
18
  /**
12
19
  * Creates one desktop engine: it drives the target's macOS app on this
13
20
  * machine, one worker at a time. A test launches the app with `app.open()`;
@@ -15,4 +22,4 @@ import { type DesktopOptions } from './options.ts';
15
22
  * so its other targets still run elsewhere; the target itself fails to start
16
23
  * on any OS but macOS.
17
24
  */
18
- export declare function desktop(options?: DesktopOptions): EngineHandle<DesktopFixtures>;
25
+ export declare function desktop(options?: DesktopOptions): DesktopEngine;
package/dist/index.d.ts CHANGED
@@ -15,7 +15,4 @@ export { default } from './engine-entry.ts';
15
15
  */
16
16
  export declare const test: import("e2e").TestAPI<import("e2e").TestFixtures & DesktopFixtures, import("e2e").WorkerFixtures>;
17
17
  /** `describe` and the hooks, the same functions as `test.describe` and `test.beforeEach`, typed with the `desktop` fixture. */
18
- export declare const describe: {
19
- <Result>(title: string, body: import("e2e").SynchronousBody<Result>): void;
20
- <Result>(title: string, options: import("e2e").DescribeOptions, body: import("e2e").SynchronousBody<Result>): void;
21
- }, beforeEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & DesktopFixtures & import("e2e").WorkerFixtures>) => void, afterEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & DesktopFixtures & import("e2e").WorkerFixtures>) => void, beforeAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void, afterAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void;
18
+ export declare const describe: import("e2e").DescribeAPI, beforeEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & DesktopFixtures & import("e2e").WorkerFixtures>) => void, afterEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & DesktopFixtures & import("e2e").WorkerFixtures>) => void, beforeAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void, afterAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void;
package/dist/keys.js CHANGED
@@ -34,6 +34,13 @@ const KEY_NAMES = {
34
34
  F11: 'f11',
35
35
  F12: 'f12',
36
36
  };
37
+ /**
38
+ * The characters agent-desktop's macOS key map presses besides letters and
39
+ * digits. Any other one (`!`, `é`) has no key of its own there, and is
40
+ * refused before a locator's press focuses its control. `+` is not one: the
41
+ * combo syntax uses it as the separator.
42
+ */
43
+ const PUNCTUATION = new Set([',', '.', '/', ';', "'", '[', ']', '\\', '-', '=', '`']);
37
44
  function modifierName(modifier) {
38
45
  switch (modifier) {
39
46
  case 'Shift':
@@ -64,7 +71,7 @@ export function toCombo(key) {
64
71
  else if (parsed.key.char === ' ') {
65
72
  name = 'space';
66
73
  }
67
- else if (parsed.key.char !== '+') {
74
+ else if (/^[A-Za-z0-9]$/.test(parsed.key.char) || PUNCTUATION.has(parsed.key.char)) {
68
75
  // agent-desktop lower-cases a combo and adds Shift for a lone capital letter, so a capital needs no help.
69
76
  name = parsed.key.char;
70
77
  }
package/dist/nodes.d.ts CHANGED
@@ -64,6 +64,12 @@ export interface NodeBinding {
64
64
  readonly rect?: Rect;
65
65
  /** Whether the id comes from the node's identity and every ancestor's, and so names it in the next snapshot too; a look-alike's, or one inside a look-alike, is new in every snapshot. */
66
66
  readonly stable: boolean;
67
+ /**
68
+ * How many look-alikes the node and each of its ancestors have among their
69
+ * siblings, root first (`/1/2/1`): a look-alike found again by its role and
70
+ * place is the same one only if no twin around it came or went.
71
+ */
72
+ readonly likeness: string;
67
73
  }
68
74
  /** A snapshot as the engine keeps it: the tree the harness sees, and a binding for every node in it. */
69
75
  export interface ProjectedScreen {
package/dist/nodes.js CHANGED
@@ -98,16 +98,20 @@ function label(value) {
98
98
  const WINDOW_CONTROLS = new Set(['Close', 'Minimize', 'Zoom', 'Full Screen']);
99
99
  /** The largest a title-bar button is, in points: macOS draws them 14 to 16 points across. */
100
100
  const WINDOW_CONTROL_SIZE = 20;
101
+ /** How far down from the window's top edge a title-bar button can reach, in points: the title bar, or a unified title bar and toolbar, is at most this tall. */
102
+ const TITLE_BAR_HEIGHT = 52;
101
103
  /**
102
104
  * A window's own title-bar button: a button straight under the window, with
103
- * no developer id, named only for what it does to the window, and the size
104
- * of a title-bar button. Left out, so `getByRole('button', 'Close')` finds
105
- * the app's Close button and not the window's; an app's own button of the
106
- * same name is larger, and one with no bounds is kept.
105
+ * no developer id, named only for what it does to the window, the size of a
106
+ * title-bar button, and in the window's title bar. Left out, so
107
+ * `getByRole('button', 'Close')` finds the app's Close button and not the
108
+ * window's; an app's own button of the same name is larger or lower in the
109
+ * window, and one with no bounds, or in a window with none, is kept.
107
110
  */
108
- function windowControl(raw) {
111
+ function windowControl(raw, window) {
109
112
  const bounds = raw.bounds;
110
- return (raw.role === 'button' &&
113
+ return (window !== undefined &&
114
+ raw.role === 'button' &&
111
115
  raw.native_id === undefined &&
112
116
  raw.name !== undefined &&
113
117
  WINDOW_CONTROLS.has(raw.name) &&
@@ -115,7 +119,23 @@ function windowControl(raw) {
115
119
  label(raw.description) === undefined &&
116
120
  bounds !== undefined &&
117
121
  bounds.width <= WINDOW_CONTROL_SIZE &&
118
- bounds.height <= WINDOW_CONTROL_SIZE);
122
+ bounds.height <= WINDOW_CONTROL_SIZE &&
123
+ bounds.y >= window.y &&
124
+ bounds.y + bounds.height <= window.y + TITLE_BAR_HEIGHT);
125
+ }
126
+ /** How far apart, at most, two neighbouring title-bar buttons are, left edge to left edge, in points: macOS spaces them about 23. */
127
+ const WINDOW_CONTROL_GAP = 30;
128
+ /**
129
+ * The window's own title-bar buttons among its direct children: each a
130
+ * `windowControl` beside another of a different name, in one row, as macOS
131
+ * draws Close, Minimize, and Zoom together. agent-desktop reports no subrole
132
+ * that names them, so a lone small Close button, such as an app's own in a
133
+ * corner of the title bar, is kept.
134
+ */
135
+ function titleBarButtons(tree) {
136
+ const candidates = (tree.children ?? []).filter((child) => windowControl(child, tree.bounds));
137
+ const beside = (a, b) => a !== b && a.name !== b.name && a.bounds !== undefined && b.bounds !== undefined && Math.abs(a.bounds.y - b.bounds.y) <= 2 && Math.abs(a.bounds.x - b.bounds.x) <= WINDOW_CONTROL_GAP;
138
+ return new Set(candidates.filter((candidate) => candidates.some((other) => beside(candidate, other))));
119
139
  }
120
140
  /** A node agent-desktop reports but nothing reads: a wrapper with no name, value, id, ref, or text of its own. */
121
141
  function transparent(raw) {
@@ -157,11 +177,12 @@ function identityOf(node, named = false) {
157
177
  */
158
178
  export function projectSnapshot(raw, idFor) {
159
179
  const window = raw.tree.bounds ?? { x: 0, y: 0, width: 0, height: 0 };
180
+ const titleBar = titleBarButtons(raw.tree);
160
181
  const bindings = new Map();
161
182
  const secureRects = [];
162
183
  let unmaskable = false;
163
184
  let scrollTarget;
164
- const project = (node, id, stable) => {
185
+ const project = (node, id, stable, likeness) => {
165
186
  const rawStates = new Set(node.states ?? []);
166
187
  const role = ROLE_MAP[node.role] ?? (node.role === 'unknown' ? undefined : node.role);
167
188
  const secure = rawStates.has('secure');
@@ -185,7 +206,8 @@ export function projectSnapshot(raw, idFor) {
185
206
  // A control shows its name (a button's title) as its text, as on a device; an input's name is a label, not what it holds.
186
207
  const text = isText ? label(node.value ?? node.name) : INPUT_ROLES.has(node.role) ? undefined : name;
187
208
  // A checkbox's value is its state ("0", "1"), already in `checked`; a secure field's is never reported.
188
- const value = secure || isText || CHECKABLE_ROLES.has(node.role) ? undefined : node.value;
209
+ // agent-desktop leaves out the value of an empty text field; it is the empty string, as inputValue() reads it, so getByDisplayValue('') finds the field.
210
+ const value = secure || isText || CHECKABLE_ROLES.has(node.role) ? undefined : node.role === 'textfield' ? (node.value ?? '') : node.value;
189
211
  const rect = node.bounds === undefined ? undefined : { x: node.bounds.x - window.x, y: node.bounds.y - window.y, width: node.bounds.width, height: node.bounds.height };
190
212
  if (secure) {
191
213
  // A box with no area masks nothing, so it proves nothing about a field that may still show.
@@ -218,6 +240,7 @@ export function projectSnapshot(raw, idFor) {
218
240
  ...(raw.window === undefined ? {} : { windowId: raw.window.id }),
219
241
  ...(rect === undefined ? {} : { rect }),
220
242
  stable,
243
+ likeness,
221
244
  });
222
245
  const kept = [];
223
246
  const collect = (child) => {
@@ -228,7 +251,7 @@ export function projectSnapshot(raw, idFor) {
228
251
  kept.push(child);
229
252
  };
230
253
  for (const child of node.children ?? [])
231
- if (id !== ROOT_ID || !windowControl(child))
254
+ if (id !== ROOT_ID || !titleBar.has(child))
232
255
  collect(child);
233
256
  const tally = (named) => {
234
257
  const counts = new Map();
@@ -245,7 +268,7 @@ export function projectSnapshot(raw, idFor) {
245
268
  const children = kept.map((child) => {
246
269
  const identity = plain.get(identityOf(child)) === 1 ? identityOf(child) : named.get(identityOf(child, true)) === 1 ? identityOf(child, true) : undefined;
247
270
  // A child's id is built on its parent's: under a look-alike, whose id is new every snapshot, so is the child's.
248
- return project(child, idFor(identity === undefined ? undefined : `${id}/${identity}`), stable && identity !== undefined);
271
+ return project(child, idFor(identity === undefined ? undefined : `${id}/${identity}`), stable && identity !== undefined, `${likeness}/${plain.get(identityOf(child)) ?? 1}`);
249
272
  });
250
273
  return {
251
274
  ref: { id, revision: '' },
@@ -262,7 +285,7 @@ export function projectSnapshot(raw, idFor) {
262
285
  ...(children.length === 0 ? {} : { children }),
263
286
  };
264
287
  };
265
- const root = project(raw.tree, ROOT_ID, true);
288
+ const root = project(raw.tree, ROOT_ID, true, '');
266
289
  return {
267
290
  root,
268
291
  bindings,
package/dist/surface.d.ts CHANGED
@@ -23,6 +23,8 @@ export declare class DesktopSurface {
23
23
  private projectRoot;
24
24
  /** The app's bundle id or name: the target's `bundleId`, or the bundle id read from its `appPath`. */
25
25
  private launchTarget;
26
+ /** Whether the app is launched in the foreground: with `desktop({ headed })`, or a run that asked for a visible surface (`--headed`). Physical input stays with `desktop({ headed })` alone, since the engine declares it when it is created. */
27
+ private foreground;
26
28
  /** The `.app` bundle an `appPath` names, resolved; the launched process must run from it. */
27
29
  private bundle;
28
30
  /** The process name agent-desktop reported at launch, which window lookups filter by before they keep the launched process's own. */
@@ -31,6 +33,9 @@ export declare class DesktopSurface {
31
33
  private pid;
32
34
  /** agent-desktop's identity of that process, which a later process given the same id does not share. */
33
35
  private instance;
36
+ /** When that process started, as `ps` prints it, and the token its launch put in its environment: what shows it is still the launch's once the app list no longer shows it. */
37
+ private started;
38
+ private token;
34
39
  /**
35
40
  * A launch whose outcome is unknown (it timed out, or failed after it may
36
41
  * have started the app): its token, so the next quit can still find and
@@ -74,7 +79,8 @@ export declare class DesktopSurface {
74
79
  doctor(info: EngineDoctorInfo): Promise<readonly EngineDoctorCheck[]>;
75
80
  /**
76
81
  * `app.open()`: the copy of the app the engine launched is quit, and the
77
- * app launched fresh, in the background unless `headed`, with the target's
82
+ * app launched fresh, in the background unless `headed` or the run's
83
+ * `--headed`, with the target's
78
84
  * launch arguments. A copy the engine did not launch (the developer's own)
79
85
  * is left alone, and never read or driven. A launch that failed after the
80
86
  * app started still leaves the engine owning the new process, so the end
@@ -114,6 +120,7 @@ export declare class DesktopSurface {
114
120
  * may be the one that just started.
115
121
  */
116
122
  private claim;
123
+ /** Takes a process shown to carry the launch's token as the engine's own, the token with it, which shows it is still the launch's once the app list leaves it out. */
117
124
  private take;
118
125
  /**
119
126
  * Waits until the launched app's window can be read: a window exists soon
@@ -137,6 +144,14 @@ export declare class DesktopSurface {
137
144
  private chosenClosed;
138
145
  /** `desktop.closeApp()`: the app quit, as at the end of every test. */
139
146
  closeApp(signal: AbortSignal, timeoutMs: number): Promise<void>;
147
+ /**
148
+ * Runs launches and quits of this surface one at a time: two at once would
149
+ * each launch a copy into the one process id and launch record the engine
150
+ * keeps, and the end of the attempt would quit only one of them.
151
+ */
152
+ private serially;
153
+ /** `quitNow` once no other launch or quit of this surface is running. */
154
+ private quit;
140
155
  /**
141
156
  * Quits the app the engine launched, forcefully: a test needs it gone, not
142
157
  * asked to save. It is ended by its process id, so another instance of the
@@ -147,15 +162,16 @@ export declare class DesktopSurface {
147
162
  * process is known to be gone, the engine keeps it as its own, so a quit
148
163
  * that failed is tried again.
149
164
  */
165
+ private quitNow;
150
166
  /**
151
- * Runs launches and quits of this surface one at a time: two at once would
152
- * each launch a copy into the one process id and launch record the engine
153
- * keeps, and the end of the attempt would quit only one of them.
167
+ * Whether a live process the app list left out is still the one the
168
+ * launch started. A complete list leaves out a process macOS no longer
169
+ * presents as an app (one that set its activation policy to prohibited),
170
+ * so its absence does not show it exited: its start time, or else its
171
+ * launch token, does. A process that cannot be looked up throws, and stays
172
+ * the engine's, so a quit tries again and the launch record stays.
154
173
  */
155
- private serially;
156
- /** `quitNow` once no other launch or quit of this surface is running. */
157
- private quit;
158
- private quitNow;
174
+ private stillLaunched;
159
175
  /** Every binding of the screen before: after a launch or a quit, none names a control that still exists. */
160
176
  private forget;
161
177
  /** The node id for an identity: the one it had before, else a new one, never handed out before since the app launched. */
@@ -192,7 +208,15 @@ export declare class DesktopSurface {
192
208
  * that left copies out shows nothing, and the read is tried again.
193
209
  */
194
210
  private requireRunning;
195
- /** The windows of the process the engine launched; none before `app.open()` or after the app quit. */
211
+ /**
212
+ * The windows of the process the engine launched; none before
213
+ * `app.open()` or after the app quit. agent-desktop lists a running app
214
+ * with no window as an empty list, and answers `APP_NOT_FOUND` only when
215
+ * no running app has the name. `strict` is for a read of the screen,
216
+ * where that answer must not pass for an empty one: an app that quit is
217
+ * `INVALID_STATE`, and one that still runs, which the list missed, a
218
+ * retryable `NODE_STALE`.
219
+ */
196
220
  private ownWindows;
197
221
  /** The window of the launched process a command reads or acts in: the one the test chose, else the focused one, else the first visible one. */
198
222
  private ownWindow;
@@ -215,21 +239,36 @@ export declare class DesktopSurface {
215
239
  private refCommand;
216
240
  /** One command on a node's ref, a failure left as agent-desktop reported it so a caller can try another way when nothing was sent. */
217
241
  private tryRef;
242
+ /**
243
+ * Whether the control a binding names holds keyboard focus in a fresh read
244
+ * of its window. A control with an identity keeps its id; a look-alike has
245
+ * a new id in every read, so it is found by role and place, with as many
246
+ * twins around it as before: a twin that went could have let another take
247
+ * its place.
248
+ */
249
+ private holdsFocus;
218
250
  /**
219
251
  * Chooses an option of a list or dropdown with agent-desktop's `select`,
220
252
  * never by setting the value, which would put a missing option in an
221
- * editable combo box as free text. A stale ref is `NODE_STALE`, so the
253
+ * editable combo box as free text: agent-desktop's select does just that
254
+ * for a combo box whose value is settable, so one is refused. A stale ref is `NODE_STALE`, so the
222
255
  * harness locates the list again. For a pop-up button agent-desktop opens
223
- * the menu to find the option; when it cannot, it leaves the menu open,
224
- * which is closed again here. A failure after the menu opened stays one
225
- * that may have chosen something: a menu left open does not show which
226
- * control opened it, or that the option is missing.
256
+ * the menu to find the option; when it cannot, it may leave the menu open,
257
+ * which is closed again here with Escape. A failure after the menu opened
258
+ * stays one that may have chosen something: a menu left open does not show
259
+ * which control opened it, or that the option is missing. A menu Escape
260
+ * cannot close (an app in the background takes no key) is named in the
261
+ * error, since it covers the window for the steps after.
227
262
  */
228
263
  private select;
229
264
  /**
230
- * Closes a menu the launched process has open, with Escape. True only when
231
- * a menu was open and is closed now; false when there was none, or it
232
- * cannot be told whose it is (another copy shares the app's name).
265
+ * Closes a menu the launched process has open, with Escape: `closed` when
266
+ * one was open and is closed now, `none` when there was none, `open` when
267
+ * one is still open after the Escape, `unconfirmed` when the Escape went
268
+ * but whether the menu closed cannot be told, `refused` when no Escape could be
269
+ * sent (agent-desktop sends a key only to the active window), and
270
+ * `unknown` when it cannot be told whose a menu is (another copy shares
271
+ * the app's name).
233
272
  */
234
273
  private closeOpenMenu;
235
274
  private scroll;
package/dist/surface.js CHANGED
@@ -8,11 +8,11 @@
8
8
  import { execFile } from 'node:child_process';
9
9
  import { randomUUID } from 'node:crypto';
10
10
  import { existsSync } from 'node:fs';
11
- import { mkdir, mkdtemp, readdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
11
+ import { lstat, mkdir, mkdtemp, readdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
12
12
  import { tmpdir } from 'node:os';
13
13
  import path from 'node:path';
14
14
  import { promisify } from 'node:util';
15
- import { EngineError, resolveExpression, } from '@e2e-dev/core/engine';
15
+ import { ConfigurationError, EngineError, OBSERVED_NAME_LIMIT, OBSERVED_TEXT_LIMIT, resolveExpression, } from '@e2e-dev/core/engine';
16
16
  import { AGENT_DESKTOP_VERSION, installPinned, pinnedExecutable, pinnedInstalled, resolveExecutable } from './binary.js';
17
17
  import { AgentDesktopCli, AgentDesktopFailure, translate } from './cli.js';
18
18
  import { toCombo } from './keys.js';
@@ -49,12 +49,16 @@ const NOT_SENT = new Error('the operation ran out of budget before anything was
49
49
  const NOT_STARTED = new Error('open started nothing');
50
50
  /** The cause of a read that found the app's windows but could read none of them. */
51
51
  const UNREADABLE = new Error('no window of the app could be read');
52
+ /** The cause of a read whose window list did not find the app, while its process still runs. */
53
+ const UNLISTED = new Error('the window list did not find the running app');
52
54
  /** The cause of a read of an app that quit since it launched. */
53
55
  const QUIT = new Error('the app quit');
54
56
  /** The prefix of every worker's private agent-desktop state directory, which a later run sweeps once its worker is gone. */
55
57
  const STATE_PREFIX = 'e2e-agent-desktop-';
56
58
  /** The file in a state directory that names the process that owns it. */
57
59
  const OWNER_FILE = 'owner';
60
+ /** What the owner file holds once its worker gave the directory up: a later sweep takes it, though the process that wrote it may still run another worker. */
61
+ const ABANDONED = 'abandoned';
58
62
  /** The file in a state directory that names the app the worker launched and its launch token, so a sweep can quit an app a killed worker left running. */
59
63
  const APP_FILE = 'app.json';
60
64
  /** How old a state directory with no owner file must be before a sweep removes it. */
@@ -68,6 +72,8 @@ const ORPHAN_AGE_MS = 24 * 60 * 60 * 1000;
68
72
  const INHERITED_ENV = new Set(['HOME', 'USER', 'LOGNAME', 'SHELL', 'PATH', 'TMPDIR', 'LANG', '__CF_USER_TEXT_ENCODING']);
69
73
  /** Launch arguments every launch gets first: no window or document the app saved at its last quit comes back. */
70
74
  const FRESH_STATE_ARGUMENTS = ['-ApplePersistenceIgnoreState', 'YES'];
75
+ /** The most text agent-desktop's `type` takes, in UTF-8 bytes (its `MAX_TEXT_LEN`). */
76
+ const MAX_TYPE_BYTES = 10_000;
71
77
  /** How many node bindings stay usable; the oldest go first. */
72
78
  const MAX_BINDINGS = 4096;
73
79
  /** Codes a snapshot fails with while the app has no window to read: not launched yet, or still opening. */
@@ -160,6 +166,8 @@ export class DesktopSurface {
160
166
  projectRoot = process.cwd();
161
167
  /** The app's bundle id or name: the target's `bundleId`, or the bundle id read from its `appPath`. */
162
168
  launchTarget;
169
+ /** Whether the app is launched in the foreground: with `desktop({ headed })`, or a run that asked for a visible surface (`--headed`). Physical input stays with `desktop({ headed })` alone, since the engine declares it when it is created. */
170
+ foreground = false;
163
171
  /** The `.app` bundle an `appPath` names, resolved; the launched process must run from it. */
164
172
  bundle;
165
173
  /** The process name agent-desktop reported at launch, which window lookups filter by before they keep the launched process's own. */
@@ -168,6 +176,9 @@ export class DesktopSurface {
168
176
  pid;
169
177
  /** agent-desktop's identity of that process, which a later process given the same id does not share. */
170
178
  instance;
179
+ /** When that process started, as `ps` prints it, and the token its launch put in its environment: what shows it is still the launch's once the app list no longer shows it. */
180
+ started;
181
+ token;
171
182
  /**
172
183
  * A launch whose outcome is unknown (it timed out, or failed after it may
173
184
  * have started the app): its token, so the next quit can still find and
@@ -204,6 +215,16 @@ export class DesktopSurface {
204
215
  async init(info) {
205
216
  this.projectRoot = info.projectRoot;
206
217
  this.app = info.app;
218
+ // An engine handle can serve one host after another: nothing of the last one's app carries over. A launch it could not settle stays in its launch record, which the sweep below takes.
219
+ this.bundle = undefined;
220
+ this.appName = undefined;
221
+ this.pid = undefined;
222
+ this.instance = undefined;
223
+ this.started = undefined;
224
+ this.token = undefined;
225
+ this.pending = undefined;
226
+ this.forget();
227
+ this.foreground = this.options.headed || info.headed;
207
228
  const executable = await resolveExecutable(this.options.binary, info.projectRoot, info.env);
208
229
  this.appEnv = inheritedEnv(info.env);
209
230
  // agent-desktop keeps the text of plain fields in its state directory: a worker that was killed left its own behind.
@@ -266,7 +287,7 @@ export class DesktopSurface {
266
287
  // An app that would not quit, or a launch whose process was never found, stays named in the launch record, which the next run's sweep quits; the text agent-desktop kept of the app's fields goes either way.
267
288
  const leftRunning = !quit && (this.pid !== undefined || this.pending !== undefined);
268
289
  if (this.home !== undefined)
269
- await (leftRunning ? keepOnlyRecord(this.home) : rm(this.home, { recursive: true, force: true })).catch(() => undefined);
290
+ await (leftRunning ? abandon(this.home) : rm(this.home, { recursive: true, force: true })).catch(() => undefined);
270
291
  this.home = undefined;
271
292
  this.cli = undefined;
272
293
  this.attempt = undefined;
@@ -315,7 +336,8 @@ export class DesktopSurface {
315
336
  // --- the app ---
316
337
  /**
317
338
  * `app.open()`: the copy of the app the engine launched is quit, and the
318
- * app launched fresh, in the background unless `headed`, with the target's
339
+ * app launched fresh, in the background unless `headed` or the run's
340
+ * `--headed`, with the target's
319
341
  * launch arguments. A copy the engine did not launch (the developer's own)
320
342
  * is left alone, and never read or driven. A launch that failed after the
321
343
  * app started still leaves the engine owning the new process, so the end
@@ -351,6 +373,8 @@ export class DesktopSurface {
351
373
  }
352
374
  // The process now shown to be the launch's, with when it started, so a later run can quit it even when its environment cannot be read, and never a later process given the same id.
353
375
  const started = this.pid === undefined ? undefined : await startedAt(this.pid, operation.signal);
376
+ this.started = started;
377
+ this.token = launch.token;
354
378
  if (this.pid !== undefined && started !== undefined)
355
379
  await this.writeRecord({ token: launch.token, pid: this.pid, started });
356
380
  this.forget();
@@ -371,7 +395,7 @@ export class DesktopSurface {
371
395
  */
372
396
  async runningCopies(target, operation) {
373
397
  // agent-desktop matches the app the way its launch does (any case, the localized name too), so every copy the launch could hand over to is listed.
374
- const { apps, complete } = await this.run(['list-apps', '--app', target], { label: 'list apps', input: false, signal: operation.signal, timeoutMs: operation.timeoutMs });
398
+ const { apps, complete } = await this.run(['list-apps', '--app', target, '--timeout-ms', String(this.toolBudget(operation))], { label: 'list apps', input: false, signal: operation.signal, timeoutMs: operation.timeoutMs });
375
399
  if (complete === false)
376
400
  return undefined;
377
401
  return new Set((apps ?? []).filter((app) => typeof app.pid === 'number').map((app) => app.pid));
@@ -379,8 +403,8 @@ export class DesktopSurface {
379
403
  /** Launches an installed app by bundle id or name through agent-desktop, which reports the process it started. */
380
404
  async launchById(launch, operation) {
381
405
  const { target, token } = launch;
382
- // In the background unless physical input is on: the app never takes the keyboard from whoever is at the Mac.
383
- const args = ['launch', target, '--no-attach', ...(this.options.headed ? ['--activate'] : []), '--timeout', String(this.toolBudget(operation)), `--env=${LAUNCH_TOKEN}=${token}`];
406
+ // In the background unless `headed` or the run's `--headed`: otherwise the app never takes the keyboard from whoever is at the Mac.
407
+ const args = ['launch', target, '--no-attach', ...(this.foreground ? ['--activate'] : []), '--timeout', String(this.toolBudget(operation)), `--env=${LAUNCH_TOKEN}=${token}`];
384
408
  for (const argument of [...FRESH_STATE_ARGUMENTS, ...(this.app.launchArguments ?? [])])
385
409
  args.push(`--arg=${argument}`);
386
410
  let launched;
@@ -421,8 +445,8 @@ export class DesktopSurface {
421
445
  async openBundle(bundle, launch, operation) {
422
446
  if (operation.timeoutMs <= 0)
423
447
  throw new EngineError('OPERATION_TIMEOUT', `opening ${bundle}: the operation's budget ran out before it was sent`, { retryable: false, cause: NOT_SENT });
424
- // `-g` keeps the app in the background unless physical input is on; `open` hands the app its own environment, so it runs with the trimmed one.
425
- const args = [...(this.options.headed ? [] : ['-g']), '-n', '--env', `${LAUNCH_TOKEN}=${launch.token}`, bundle, '--args', ...FRESH_STATE_ARGUMENTS, ...(this.app.launchArguments ?? [])];
448
+ // `-g` keeps the app in the background unless `headed` or the run's `--headed`; `open` hands the app its own environment, so it runs with the trimmed one.
449
+ const args = [...(this.foreground ? [] : ['-g']), '-n', '--env', `${LAUNCH_TOKEN}=${launch.token}`, bundle, '--args', ...FRESH_STATE_ARGUMENTS, ...(this.app.launchArguments ?? [])];
426
450
  try {
427
451
  await execFileAsync('open', args, { signal: operation.signal, timeout: operation.timeoutMs, env: this.appEnv });
428
452
  }
@@ -469,7 +493,7 @@ export class DesktopSurface {
469
493
  */
470
494
  async claim(launch, operation) {
471
495
  const { target, token, before } = launch;
472
- const { apps, complete } = await this.run(['list-apps', '--app', target], { label: 'list apps', input: false, signal: operation.signal, timeoutMs: operation.timeoutMs });
496
+ const { apps, complete } = await this.run(['list-apps', '--app', target, '--timeout-ms', String(this.toolBudget(operation))], { label: 'list apps', input: false, signal: operation.signal, timeoutMs: operation.timeoutMs });
473
497
  for (const app of apps ?? []) {
474
498
  if (typeof app.pid !== 'number')
475
499
  continue;
@@ -477,14 +501,17 @@ export class DesktopSurface {
477
501
  if (before?.has(app.pid) === true)
478
502
  continue;
479
503
  if ((await carriesToken(app.pid, token, operation.signal)) === true)
480
- return this.take(app, target);
504
+ return this.take(app, target, token);
481
505
  }
482
506
  return complete === false ? undefined : false;
483
507
  }
484
- take(app, target) {
508
+ /** Takes a process shown to carry the launch's token as the engine's own, the token with it, which shows it is still the launch's once the app list leaves it out. */
509
+ take(app, target, token) {
485
510
  this.appName = app.name ?? target;
486
511
  this.pid = app.pid;
487
512
  this.instance = app.process_instance;
513
+ this.token = token;
514
+ this.started = undefined;
488
515
  return true;
489
516
  }
490
517
  /**
@@ -501,31 +528,42 @@ export class DesktopSurface {
501
528
  const budgetBound = operation.timeoutMs < LAUNCH_READY_MS;
502
529
  const deadline = Date.now() + Math.min(operation.timeoutMs, LAUNCH_READY_MS);
503
530
  let sawWindow = false;
531
+ // Whether a read finished and listed no window of the app: only that shows it opened none. A read that ran out of time saw nothing.
532
+ let listedNone = false;
533
+ let timedOut = false;
504
534
  while (Date.now() < deadline) {
505
535
  if (operation.signal.aborted)
506
536
  throw new EngineError('CANCELLED', `opening ${this.appName ?? 'the app'} was cancelled`, { retryable: false });
507
537
  let screen;
538
+ let read = false;
508
539
  try {
509
540
  // Each read gets what is left of the readiness wait, not of the whole operation, shared by its commands.
510
541
  screen = await this.capture(withDeadline({ ...operation, timeoutMs: Math.max(deadline - Date.now(), 0) }));
542
+ read = true;
511
543
  }
512
544
  catch (cause) {
513
545
  // The last read ran out of budget: the window never became readable in time.
514
- if (cause instanceof EngineError && cause.code === 'OPERATION_TIMEOUT')
546
+ if (cause instanceof EngineError && cause.code === 'OPERATION_TIMEOUT') {
547
+ timedOut = true;
515
548
  break;
516
- // A window not readable yet, or an app that quit, is what this wait looks at below.
517
- if (!(cause instanceof EngineError && (cause.cause === UNREADABLE || cause.cause === QUIT)))
549
+ }
550
+ // A window not readable yet, an app the window list missed, or an app that quit, is what this wait looks at below.
551
+ if (!(cause instanceof EngineError && (cause.cause === UNREADABLE || cause.cause === QUIT || cause.cause === UNLISTED)))
518
552
  throw cause;
519
553
  if (cause.cause === UNREADABLE)
520
554
  sawWindow = true;
521
555
  }
522
556
  if (screen !== undefined)
523
557
  return;
558
+ if (read)
559
+ listedNone = true;
524
560
  // An app that quit (or crashed) on its own never shows a window.
525
561
  if (this.pid !== undefined && !alive(this.pid)) {
526
562
  this.forget();
527
563
  this.pid = undefined;
528
564
  this.instance = undefined;
565
+ this.started = undefined;
566
+ this.token = undefined;
529
567
  throw new EngineError('ENGINE_FAILURE', `${this.appName ?? 'the app'} quit right after it launched, before it showed a window`, { retryable: false });
530
568
  }
531
569
  await sleep(Math.min(LAUNCH_POLL_MS, Math.max(deadline - Date.now(), 0)), operation.signal);
@@ -533,10 +571,18 @@ export class DesktopSurface {
533
571
  // The open's own budget ran out first: that is a timeout, not a window that cannot be read.
534
572
  if (budgetBound)
535
573
  throw new EngineError('OPERATION_TIMEOUT', `${this.appName ?? 'the app'} launched, but the open ran out of time before its window could be read`, { retryable: false });
536
- if (!sawWindow && !this.options.headed) {
537
- throw new EngineError('ENGINE_FAILURE', `${this.appName ?? 'the app'} launched in the background and opened no window. Some apps, such as document-based ones, show a window only once they come forward; set desktop({ headed: true }) for them`, { retryable: false });
574
+ // A locked screen hides every window from accessibility, and can list none or time out: neither read tells it from an app with no window, so macOS is asked.
575
+ if ((await screenLocked(operation.signal)) === true) {
576
+ throw new EngineError('ENGINE_FAILURE', `${this.appName ?? 'the app'} launched, but the Mac's screen is locked, so no window can be read through accessibility; unlock it and run again`, { retryable: false });
577
+ }
578
+ if (!sawWindow && listedNone && !this.foreground) {
579
+ throw new EngineError('ENGINE_FAILURE', `${this.appName ?? 'the app'} launched in the background and opened no window. Some apps, such as document-based ones, show a window only once they come forward; set desktop({ headed: true }) for them, or run with --headed`, { retryable: false });
538
580
  }
539
- throw new EngineError('ENGINE_FAILURE', `${this.appName ?? 'the app'} launched, but its window cannot be read through accessibility. On macOS the screen may be locked, or the window may be off screen`, { retryable: false });
581
+ // In the foreground there is no background to blame: the app listed no window at all, which a locked screen can cause too.
582
+ if (!sawWindow && listedNone) {
583
+ throw new EngineError('ENGINE_FAILURE', `${this.appName ?? 'the app'} launched, but listed no window within ${LAUNCH_READY_MS / 1000} s: it may open none (a menu-bar app) or take longer to, or on macOS the screen may be locked`, { retryable: false });
584
+ }
585
+ throw new EngineError('ENGINE_FAILURE', `${this.appName ?? 'the app'} launched, but its window cannot be read through accessibility${timedOut ? ' (a read ran out of time)' : ''}. On macOS the screen may be locked, or the window may be off screen`, { retryable: false });
540
586
  }
541
587
  /** The windows of the app the engine launched, for the `desktop` fixture; none while it is not running. */
542
588
  async windows(signal, timeoutMs) {
@@ -565,16 +611,6 @@ export class DesktopSurface {
565
611
  async closeApp(signal, timeoutMs) {
566
612
  await this.quit(signal, timeoutMs);
567
613
  }
568
- /**
569
- * Quits the app the engine launched, forcefully: a test needs it gone, not
570
- * asked to save. It is ended by its process id, so another instance of the
571
- * same app (the developer's own copy) is left alone, and waited for, so the
572
- * next launch cannot find it still running. The process is looked up
573
- * first: one that exited on its own, or whose id the OS gave to another
574
- * process since, is not running any more, and nothing is killed. Until the
575
- * process is known to be gone, the engine keeps it as its own, so a quit
576
- * that failed is tried again.
577
- */
578
614
  /**
579
615
  * Runs launches and quits of this surface one at a time: two at once would
580
616
  * each launch a copy into the one process id and launch record the engine
@@ -589,6 +625,16 @@ export class DesktopSurface {
589
625
  quit(signal, timeoutMs) {
590
626
  return this.serially(() => this.quitNow(signal, timeoutMs));
591
627
  }
628
+ /**
629
+ * Quits the app the engine launched, forcefully: a test needs it gone, not
630
+ * asked to save. It is ended by its process id, so another instance of the
631
+ * same app (the developer's own copy) is left alone, and waited for, so the
632
+ * next launch cannot find it still running. The process is looked up
633
+ * first: one that exited on its own, or whose id the OS gave to another
634
+ * process since, is not running any more, and nothing is killed. Until the
635
+ * process is known to be gone, the engine keeps it as its own, so a quit
636
+ * that failed is tried again.
637
+ */
592
638
  async quitNow(signal, timeoutMs) {
593
639
  const deadline = Date.now() + timeoutMs;
594
640
  const pending = this.pending;
@@ -637,18 +683,49 @@ export class DesktopSurface {
637
683
  this.forget();
638
684
  if (pid === undefined || appName === undefined)
639
685
  return;
640
- const { apps, complete } = await this.run(['list-apps', '--app', appName], { label: `find ${appName}`, input: false, signal, timeoutMs });
641
- const running = apps?.some((app) => app.pid === pid && (instance === undefined || app.process_instance === instance)) === true;
686
+ const { apps, complete } = await this.run(['list-apps', '--app', appName, '--timeout-ms', String(this.toolBudget({ timeoutMs }))], { label: `find ${appName}`, input: false, signal, timeoutMs });
687
+ const listed = apps?.some((app) => app.pid === pid && (instance === undefined || app.process_instance === instance)) === true;
642
688
  // An inventory that skipped some processes cannot say the app is gone; it stays the engine's, to quit again.
643
- if (!running && complete === false)
689
+ if (!listed && complete === false)
644
690
  throw new EngineError('ENGINE_FAILURE', `could not tell whether the app (process ${pid}) is still running: agent-desktop listed the apps only in part`, { retryable: false });
691
+ // The list showing the id as another process is evidence it is not the launch's; the list leaving it out is not.
692
+ const reused = instance !== undefined && apps?.some((app) => app.pid === pid && app.process_instance !== instance) === true;
693
+ const running = listed || (!reused && alive(pid) && (await this.stillLaunched(pid, signal)));
645
694
  if (running && !(await killed([pid], deadline, signal)))
646
695
  throw new EngineError('ENGINE_FAILURE', `the app (process ${pid}) did not exit`, { retryable: false });
647
696
  this.pid = undefined;
648
697
  this.instance = undefined;
698
+ this.started = undefined;
699
+ this.token = undefined;
649
700
  if (this.home !== undefined)
650
701
  await rm(path.join(this.home, APP_FILE), { force: true }).catch(() => undefined);
651
702
  }
703
+ /**
704
+ * Whether a live process the app list left out is still the one the
705
+ * launch started. A complete list leaves out a process macOS no longer
706
+ * presents as an app (one that set its activation policy to prohibited),
707
+ * so its absence does not show it exited: its start time, or else its
708
+ * launch token, does. A process that cannot be looked up throws, and stays
709
+ * the engine's, so a quit tries again and the launch record stays.
710
+ */
711
+ async stillLaunched(pid, signal) {
712
+ const unknown = () => new EngineError('ENGINE_FAILURE', `could not tell whether process ${pid}, which the app list no longer shows, is still the app the engine launched; quitting tries again`, { retryable: false });
713
+ if (this.started !== undefined) {
714
+ const now = await startedAt(pid, signal);
715
+ if (now === undefined) {
716
+ if (!alive(pid))
717
+ return false;
718
+ throw unknown();
719
+ }
720
+ return now === this.started;
721
+ }
722
+ if (this.token === undefined)
723
+ throw unknown();
724
+ const carriers = await processesCarrying(this.token, signal);
725
+ if (carriers === undefined)
726
+ throw unknown();
727
+ return carriers.includes(pid);
728
+ }
652
729
  /** Every binding of the screen before: after a launch or a quit, none names a control that still exists. */
653
730
  forget() {
654
731
  this.pointWindow = undefined;
@@ -706,7 +783,7 @@ export class DesktopSurface {
706
783
  * again until its deadline.
707
784
  */
708
785
  async capture(operation, windowId = this.chosenWindow, forMask = false) {
709
- const windows = await this.ownWindows(operation);
786
+ const windows = await this.ownWindows(operation, true);
710
787
  const chosen = windowId !== undefined && windowId === this.chosenWindow;
711
788
  if (chosen && !windows.some((window) => window.id === windowId))
712
789
  throw this.chosenClosed();
@@ -757,25 +834,42 @@ export class DesktopSurface {
757
834
  throw quit();
758
835
  if (instance === undefined || appName === undefined)
759
836
  return;
760
- const { apps, complete } = await this.run(['list-apps', '--app', appName], { label: `find ${appName}`, input: false, signal: operation.signal, timeoutMs: operation.timeoutMs });
837
+ const { apps, complete } = await this.run(['list-apps', '--app', appName, '--timeout-ms', String(this.toolBudget(operation))], { label: `find ${appName}`, input: false, signal: operation.signal, timeoutMs: operation.timeoutMs });
761
838
  if (apps?.some((app) => app.pid === pid && app.process_instance === instance) === true)
762
839
  return;
763
840
  if (complete === false)
764
841
  throw new EngineError('NODE_STALE', `could not tell whether ${appName} still runs: agent-desktop listed the apps only in part`, { retryable: true, cause: UNREADABLE });
842
+ // A complete list leaves out a process macOS no longer presents as an app (a prohibited activation policy), which may come back: while it is still the launch's, the read is tried again.
843
+ const reused = apps?.some((app) => app.pid === pid && app.process_instance !== instance) === true;
844
+ if (!reused && alive(pid) && (await this.stillLaunched(pid, operation.signal))) {
845
+ throw new EngineError('NODE_STALE', `${appName} (process ${pid}) still runs, but agent-desktop does not list it as an app now; reading again`, { retryable: true, cause: UNLISTED });
846
+ }
765
847
  throw quit();
766
848
  }
767
- /** The windows of the process the engine launched; none before `app.open()` or after the app quit. */
768
- async ownWindows(operation) {
849
+ /**
850
+ * The windows of the process the engine launched; none before
851
+ * `app.open()` or after the app quit. agent-desktop lists a running app
852
+ * with no window as an empty list, and answers `APP_NOT_FOUND` only when
853
+ * no running app has the name. `strict` is for a read of the screen,
854
+ * where that answer must not pass for an empty one: an app that quit is
855
+ * `INVALID_STATE`, and one that still runs, which the list missed, a
856
+ * retryable `NODE_STALE`.
857
+ */
858
+ async ownWindows(operation, strict = false) {
769
859
  const { pid, appName } = this;
770
860
  if (pid === undefined || appName === undefined)
771
861
  return [];
772
862
  let listed;
773
863
  try {
774
- listed = await this.run(['list-windows', '--app', appName], { label: 'list windows', input: false, signal: operation.signal, timeoutMs: operation.timeoutMs, raw: true });
864
+ listed = await this.run(['list-windows', '--app', appName, '--timeout-ms', String(this.toolBudget(operation))], { label: 'list windows', input: false, signal: operation.signal, timeoutMs: operation.timeoutMs, raw: true });
775
865
  }
776
866
  catch (cause) {
777
- if (cause instanceof AgentDesktopFailure && NO_WINDOW_CODES.has(cause.code))
778
- return [];
867
+ if (cause instanceof AgentDesktopFailure && NO_WINDOW_CODES.has(cause.code)) {
868
+ if (!strict)
869
+ return [];
870
+ await this.requireRunning(operation);
871
+ throw new EngineError('NODE_STALE', `agent-desktop found no running app named ${appName}, though process ${pid} still runs; reading again`, { retryable: true, cause: UNLISTED });
872
+ }
779
873
  throw translate(cause, 'list windows', false);
780
874
  }
781
875
  const { instance } = this;
@@ -796,21 +890,24 @@ export class DesktopSurface {
796
890
  }
797
891
  this.pointWindow = screen.windowId;
798
892
  this.remember(screen.bindings.values());
893
+ let withheld = false;
799
894
  const pixels = options?.pixels === true ? await this.pixelsFor(screen, operation).catch((cause) => {
800
895
  if (cause instanceof EngineError && cause.code === 'OPERATION_TIMEOUT')
801
896
  throw cause;
897
+ withheld = true;
802
898
  return undefined;
803
899
  }) : undefined;
900
+ // Pixels withheld still report the regions masked, none, so the harness reads masking it could not prove (MASKING_UNPROVEN), not a missing screenshot.
804
901
  return {
805
902
  ...this.snapshotOf(screen),
806
- ...(pixels === undefined ? {} : { pixels: pixels.pixels, maskedRegionCount: pixels.masked }),
903
+ ...(pixels === undefined ? (withheld ? { maskedRegionCount: 0 } : {}) : { pixels: pixels.pixels, maskedRegionCount: pixels.masked }),
807
904
  };
808
905
  }
809
906
  snapshotOf(screen) {
810
907
  const app = this.appName;
811
908
  const location = app === undefined ? screen.title : screen.title === undefined ? app : `${app} › ${screen.title}`;
812
909
  return {
813
- root: screen.root,
910
+ root: bounded(screen.root),
814
911
  viewport: screen.viewport,
815
912
  ...(screen.truncated ? { truncated: true } : {}),
816
913
  ...(location === undefined ? {} : { location }),
@@ -943,10 +1040,8 @@ export class DesktopSurface {
943
1040
  if (windows.length > 1 && home.is_focused !== true) {
944
1041
  throw notActionable(`node ${binding.id} is in a window that cannot be shown to be the app's key window, so the key could land in another window`);
945
1042
  }
946
- // Focusing can hand focus on (a dialog it opens): the key goes only when the control still holds it. A control with an identity keeps its id; a look-alike has a new id in every read, so it is found by role and place.
947
- const now = await this.capture(operation, window);
948
- const held = [...(now?.bindings.values() ?? [])].some((candidate) => candidate.states?.focused === true && (binding.stable ? candidate.id === binding.id : candidate.role === binding.role && sameRect(candidate.rect, binding.rect)));
949
- if (!held)
1043
+ // Focusing can hand focus on (a dialog it opens): the key goes only when the control still holds it.
1044
+ if (!(await this.holdsFocus(binding, window, operation)))
950
1045
  throw notActionable(`node ${binding.id} did not keep keyboard focus, so the key would land on another control`);
951
1046
  await this.sendKey(combo, window, `press ${action.key}`, operation);
952
1047
  }
@@ -998,17 +1093,36 @@ export class DesktopSurface {
998
1093
  args.push(...extra);
999
1094
  return await this.run(args, { label: command, input: true, signal: operation.signal, timeoutMs: operation.timeoutMs, raw: true, ...(stdin === undefined ? {} : { stdin }) });
1000
1095
  }
1096
+ /**
1097
+ * Whether the control a binding names holds keyboard focus in a fresh read
1098
+ * of its window. A control with an identity keeps its id; a look-alike has
1099
+ * a new id in every read, so it is found by role and place, with as many
1100
+ * twins around it as before: a twin that went could have let another take
1101
+ * its place.
1102
+ */
1103
+ async holdsFocus(binding, window, operation) {
1104
+ const now = await this.capture(operation, window);
1105
+ return [...(now?.bindings.values() ?? [])].some((candidate) => candidate.states?.focused === true &&
1106
+ (binding.stable ? candidate.id === binding.id : candidate.role === binding.role && sameRect(candidate.rect, binding.rect) && candidate.likeness === binding.likeness));
1107
+ }
1001
1108
  /**
1002
1109
  * Chooses an option of a list or dropdown with agent-desktop's `select`,
1003
1110
  * never by setting the value, which would put a missing option in an
1004
- * editable combo box as free text. A stale ref is `NODE_STALE`, so the
1111
+ * editable combo box as free text: agent-desktop's select does just that
1112
+ * for a combo box whose value is settable, so one is refused. A stale ref is `NODE_STALE`, so the
1005
1113
  * harness locates the list again. For a pop-up button agent-desktop opens
1006
- * the menu to find the option; when it cannot, it leaves the menu open,
1007
- * which is closed again here. A failure after the menu opened stays one
1008
- * that may have chosen something: a menu left open does not show which
1009
- * control opened it, or that the option is missing.
1114
+ * the menu to find the option; when it cannot, it may leave the menu open,
1115
+ * which is closed again here with Escape. A failure after the menu opened
1116
+ * stays one that may have chosen something: a menu left open does not show
1117
+ * which control opened it, or that the option is missing. A menu Escape
1118
+ * cannot close (an app in the background takes no key) is named in the
1119
+ * error, since it covers the window for the steps after.
1010
1120
  */
1011
1121
  async select(binding, label, operation) {
1122
+ // An editable combo box takes any text: agent-desktop's select sets its value and reads it back, which a missing option passes as well.
1123
+ if (binding.role === 'combobox' && binding.actions.includes('SetValue')) {
1124
+ throw unsupported(`this combo box is editable and takes any text, so a select of "${label}" could not tell a missing option from a chosen one; fill() it and check its value`);
1125
+ }
1012
1126
  const ref = this.refOf(binding, 'select');
1013
1127
  try {
1014
1128
  await this.run(['select', ref, '--timeout-ms', String(Math.min(this.toolBudget(operation), SELECT_WAIT_MS)), '--', label], { label: 'select', input: true, signal: operation.signal, timeoutMs: operation.timeoutMs, raw: true });
@@ -1017,38 +1131,66 @@ export class DesktopSurface {
1017
1131
  // `select` answers ELEMENT_NOT_FOUND for an option it cannot find; a list that is gone is a stale ref.
1018
1132
  if (cause instanceof AgentDesktopFailure && cause.notDelivered && cause.code === 'ELEMENT_NOT_FOUND')
1019
1133
  throw notActionable(`the list has no option "${label}"`);
1020
- // A menu that cannot be closed leaves the select's own failure to report.
1021
- if (cause instanceof AgentDesktopFailure && !cause.notDelivered && (await this.closeOpenMenu(binding.windowId, operation).catch(() => false))) {
1022
- throw new EngineError('ACTION_MAY_HAVE_COMMITTED', `select "${label}": agent-desktop opened the list's menu and did not choose it; the list may have no option "${label}". The menu was closed`, { retryable: false, cause });
1134
+ if (cause instanceof AgentDesktopFailure && !cause.notDelivered) {
1135
+ const menu = await this.closeOpenMenu(binding.windowId, operation).catch(() => 'unknown');
1136
+ if (menu === 'closed') {
1137
+ throw new EngineError('ACTION_MAY_HAVE_COMMITTED', `select "${label}": agent-desktop opened the list's menu and could not confirm a choice, so whether "${label}" was chosen is unknown; the list may have no option "${label}". The menu was closed`, { retryable: false, cause });
1138
+ }
1139
+ if (menu === 'unconfirmed') {
1140
+ throw new EngineError('ACTION_MAY_HAVE_COMMITTED', `select "${label}": ${cause.message} (the input may have reached the app). Escape was sent to close the list's menu, but whether it closed could not be told`, { retryable: false, cause });
1141
+ }
1142
+ if (menu === 'open' || menu === 'refused') {
1143
+ const why = menu === 'open'
1144
+ ? 'Escape did not close it'
1145
+ : this.options.headed
1146
+ ? 'agent-desktop sent no Escape to close it'
1147
+ : "the app's window is not the active one, so no Escape could be sent to close it; desktop({ headed: true }) closes it with Escape";
1148
+ throw new EngineError('ACTION_MAY_HAVE_COMMITTED', `select "${label}": ${cause.message} (the input may have reached the app). The list's menu is still open: ${why}`, { retryable: false, cause });
1149
+ }
1023
1150
  }
1024
1151
  throw translate(cause, `select "${label}"`, true);
1025
1152
  }
1026
1153
  }
1027
1154
  /**
1028
- * Closes a menu the launched process has open, with Escape. True only when
1029
- * a menu was open and is closed now; false when there was none, or it
1030
- * cannot be told whose it is (another copy shares the app's name).
1155
+ * Closes a menu the launched process has open, with Escape: `closed` when
1156
+ * one was open and is closed now, `none` when there was none, `open` when
1157
+ * one is still open after the Escape, `unconfirmed` when the Escape went
1158
+ * but whether the menu closed cannot be told, `refused` when no Escape could be
1159
+ * sent (agent-desktop sends a key only to the active window), and
1160
+ * `unknown` when it cannot be told whose a menu is (another copy shares
1161
+ * the app's name).
1031
1162
  */
1032
1163
  async closeOpenMenu(window, operation) {
1033
1164
  const { appName, pid } = this;
1034
1165
  if (appName === undefined || pid === undefined || window === undefined)
1035
- return false;
1166
+ return 'unknown';
1036
1167
  const menus = async () => {
1037
1168
  const listed = await this.run(['list-surfaces', '--app', appName], { label: 'list surfaces', input: false, signal: operation.signal, timeoutMs: operation.timeoutMs }).catch(() => undefined);
1038
1169
  if (listed?.pid !== pid)
1039
1170
  return undefined;
1171
+ // A window agent-desktop could not check for a menu (a busy app) says so in `unclassified`: whether a menu is open there is unknown, not no.
1172
+ if ((listed.surfaces ?? []).some((surface) => surface.unclassified?.includes('menu') === true))
1173
+ return undefined;
1040
1174
  return (listed.surfaces ?? []).filter((surface) => surface.type?.includes('menu') === true).length;
1041
1175
  };
1042
- if (((await menus()) ?? 0) === 0)
1043
- return false;
1044
- await this.sendKey('escape', window, 'close menu', operation);
1045
- // A menu takes a moment to close after Escape.
1176
+ const before = await menus();
1177
+ if (before === undefined)
1178
+ return 'unknown';
1179
+ if (before === 0)
1180
+ return 'none';
1181
+ const sent = await this.sendKey('escape', window, 'close menu', operation).then(() => 'sent',
1182
+ // A failure that may have reached the app is an Escape sent; any other sent nothing.
1183
+ (cause) => (cause instanceof EngineError && cause.code === 'ACTION_MAY_HAVE_COMMITTED' ? 'sent' : 'refused'));
1184
+ if (sent === 'refused')
1185
+ return 'refused';
1186
+ // A menu takes a moment to close after Escape. The last look decides: one that could not tell leaves it unknown.
1046
1187
  const until = Date.now() + Math.min(MENU_CLOSE_MS, operation.timeoutMs);
1047
1188
  for (;;) {
1048
- if ((await menus()) === 0)
1049
- return true;
1189
+ const open = await menus();
1190
+ if (open === 0)
1191
+ return 'closed';
1050
1192
  if (Date.now() + LAUNCH_POLL_MS >= until)
1051
- return false;
1193
+ return open === undefined ? 'unconfirmed' : 'open';
1052
1194
  await sleep(LAUNCH_POLL_MS, operation.signal);
1053
1195
  }
1054
1196
  }
@@ -1071,9 +1213,13 @@ export class DesktopSurface {
1071
1213
  // Physical input lands on whatever is frontmost at the point: bring the window forward first.
1072
1214
  await this.run(['focus-window', '--window-id', target.id, '--headed'], { label: 'focus window', input: true, signal: operation.signal, timeoutMs: operation.timeoutMs });
1073
1215
  // Coming forward can move the window (onto another space, out from under the menu bar): the click is measured from where it is now.
1074
- const focused = (await this.ownWindows(operation)).find((candidate) => candidate.id === target.id)?.bounds;
1075
- if (focused === undefined)
1216
+ const forward = (await this.ownWindows(operation)).find((candidate) => candidate.id === target.id);
1217
+ const focused = forward?.bounds;
1218
+ if (forward === undefined || focused === undefined)
1076
1219
  throw notActionable('the window the point was taken from closed as it was brought forward; observe again');
1220
+ // A click carries no window, only screen coordinates: if another window (a sheet, a panel the app raised) took focus as this one came forward, it could be the one under the point.
1221
+ if (forward.is_focused !== true)
1222
+ throw notActionable('another window took focus as the window the point was taken from was brought forward, and could be under the point; observe again');
1077
1223
  if (point.x >= focused.width || point.y >= focused.height) {
1078
1224
  throw notActionable(`(${point.x}, ${point.y}) is outside the ${focused.width}x${focused.height} window; a click there would land on another app`);
1079
1225
  }
@@ -1090,13 +1236,33 @@ export class DesktopSurface {
1090
1236
  }
1091
1237
  /** The keyboard capability's `type` (declared with `headed` only): keystrokes into the focused field, which a fresh snapshot names. */
1092
1238
  async typeText(text, options, context) {
1239
+ // What agent-desktop's type refuses, refused before anything is sent: with replace, the select-all and delete would already have emptied the field.
1240
+ if (Buffer.byteLength(text, 'utf8') > MAX_TYPE_BYTES)
1241
+ throw notActionable(`agent-desktop types at most ${MAX_TYPE_BYTES} bytes of text at once; this is ${Buffer.byteLength(text, 'utf8')}`);
1242
+ if (text.includes('\0'))
1243
+ throw notActionable('agent-desktop cannot type a NUL character');
1093
1244
  const operation = withDeadline(context);
1094
1245
  const screen = await this.capture(operation);
1095
1246
  const focused = screen === undefined ? undefined : [...screen.bindings.values()].find((binding) => binding.ref !== undefined && binding.states?.focused === true);
1096
1247
  if (focused === undefined)
1097
1248
  throw notActionable('no field has keyboard focus; tap or focus the field first');
1098
- if (options.replace)
1099
- await this.refCommand('clear', focused, operation);
1249
+ // agent-desktop types only into a control that offers TypeText; a list or button with focus would take the select-all and delete as commands.
1250
+ if (!focused.actions.includes('TypeText')) {
1251
+ throw notActionable(`the ${focused.role ?? 'control'}${focused.name === undefined ? '' : ` "${focused.name}"`} that has keyboard focus takes no text; tap or focus a text field first`);
1252
+ }
1253
+ if (options.replace) {
1254
+ // Cleared as on a keyboard, select all and then delete: the app's key handlers see it, and a field that takes keys but refuses an accessibility write is cleared too.
1255
+ const window = focused.windowId ?? (await this.ownWindow(operation))?.id;
1256
+ if (window === undefined)
1257
+ throw this.chosenWindow === undefined ? invalidState('the app is not running; open it with app.open()') : this.chosenClosed();
1258
+ await this.sendKey('cmd+a', window, 'select all', operation);
1259
+ // The app may move focus on select all: the delete goes only to the field that still holds it.
1260
+ await afterChange('delete the selection', async () => {
1261
+ if (!(await this.holdsFocus(focused, window, operation)))
1262
+ throw notActionable('the field lost keyboard focus after select all, so no delete was sent');
1263
+ await this.sendKey('backspace', window, 'delete the selection', operation);
1264
+ });
1265
+ }
1100
1266
  // Keystrokes, which only physical input sends: without it agent-desktop sets the text, and the app's key handlers never run.
1101
1267
  const type = () => this.tryRef('type', focused, operation, [], text, true);
1102
1268
  if (options.replace)
@@ -1113,6 +1279,8 @@ export class DesktopSurface {
1113
1279
  if (window === undefined)
1114
1280
  throw this.chosenWindow === undefined ? invalidState('the app is not running; open it with app.open()') : this.chosenClosed();
1115
1281
  await this.sendKey(combo, window.id, `press ${key}`, operation);
1282
+ // As after every other agent action: the app reacts to the key before the agent reads the screen again.
1283
+ await this.settle(operation);
1116
1284
  }
1117
1285
  /**
1118
1286
  * Sends one key combo to the launched process's window. agent-desktop
@@ -1169,8 +1337,9 @@ export class DesktopSurface {
1169
1337
  if (screen?.windowId === undefined)
1170
1338
  throw new EngineError('ENGINE_FAILURE', 'the window could not be read whole to find its secure fields; screenshot withheld', { retryable: false });
1171
1339
  const secure = screen.secureRects;
1340
+ // A refusal of policy, as on the mobile engine: the image could hold a credential, so it never leaves the engine.
1172
1341
  if (secure === undefined)
1173
- throw new EngineError('ENGINE_FAILURE', 'a secure field on screen has no bounds to mask; screenshot withheld', { retryable: false });
1342
+ throw new ConfigurationError('POLICY_DENIED', 'a secure field on screen has no bounds to mask, so the screenshot is withheld');
1174
1343
  // A snapshot cut short can leave out a secure field, which would then go unmasked.
1175
1344
  if (screen.truncated)
1176
1345
  throw new EngineError('ENGINE_FAILURE', 'the snapshot did not read the whole window, so a secure field may be missing from it; screenshot withheld', { retryable: false });
@@ -1338,8 +1507,12 @@ async function sweepStateDirectories() {
1338
1507
  if (!entry.startsWith(STATE_PREFIX))
1339
1508
  continue;
1340
1509
  const directory = path.join(root, entry);
1341
- const owner = Number((await readFile(path.join(directory, OWNER_FILE), 'utf8').catch(() => '')).trim());
1342
- const stale = Number.isInteger(owner) && owner > 0 ? !alive(owner) : await stat(directory).then((info) => Date.now() - info.mtimeMs > ORPHAN_AGE_MS, () => false);
1510
+ // A shared temporary directory (`/tmp` when TMPDIR is unset) holds other users' entries too: a record this user did not write names no launch of its own, and its process id must not be killed with this user's rights.
1511
+ if (!(await ownDirectory(directory)))
1512
+ continue;
1513
+ const ownerText = (await readFile(path.join(directory, OWNER_FILE), 'utf8').catch(() => '')).trim();
1514
+ const owner = Number(ownerText);
1515
+ const stale = ownerText === ABANDONED || (Number.isInteger(owner) && owner > 0 ? !alive(owner) : await stat(directory).then((info) => Date.now() - info.mtimeMs > ORPHAN_AGE_MS, () => false));
1343
1516
  if (!stale)
1344
1517
  continue;
1345
1518
  // A record cut short by the kill that left it names no process: the directory still goes.
@@ -1368,6 +1541,23 @@ async function sweepStateDirectories() {
1368
1541
  await (settled ? rm(directory, { recursive: true, force: true }) : keepOnlyRecord(directory)).catch(() => undefined);
1369
1542
  }
1370
1543
  }
1544
+ /** Whether `directory` is a real directory (not a symlink) that belongs to the user this process runs as. */
1545
+ async function ownDirectory(directory) {
1546
+ const info = await lstat(directory).catch(() => undefined);
1547
+ if (info === undefined || !info.isDirectory())
1548
+ return false;
1549
+ return process.getuid === undefined || info.uid === process.getuid();
1550
+ }
1551
+ /**
1552
+ * Gives up a state directory whose launch record still names an app: only
1553
+ * the record stays, and the owner file says the directory has no worker any
1554
+ * more, so the next sweep takes it even while this process runs on, as a
1555
+ * program that opens one host after another does.
1556
+ */
1557
+ async function abandon(directory) {
1558
+ await keepOnlyRecord(directory);
1559
+ await writeFile(path.join(directory, OWNER_FILE), ABANDONED);
1560
+ }
1371
1561
  /** Removes everything in a state directory but its owner file and launch record: the text agent-desktop kept of the app's fields. */
1372
1562
  async function keepOnlyRecord(directory) {
1373
1563
  for (const entry of await readdir(directory).catch(() => [])) {
@@ -1392,6 +1582,16 @@ async function killed(pids, until, signal) {
1392
1582
  }
1393
1583
  return true;
1394
1584
  }
1585
+ /**
1586
+ * Whether macOS reports the console session's screen locked (ioreg's
1587
+ * `CGSSessionScreenIsLocked`); undefined when that cannot be told, off macOS
1588
+ * or when ioreg fails.
1589
+ */
1590
+ async function screenLocked(signal) {
1591
+ const listed = await execFileAsync('ioreg', ['-n', 'Root', '-d1', '-a'], { signal, maxBuffer: 16 * 1024 * 1024 }).catch(() => undefined);
1592
+ const match = /<key>CGSSessionScreenIsLocked<\/key>\s*<(true|false)\/>/.exec(listed?.stdout ?? '');
1593
+ return match === null ? undefined : match[1] === 'true';
1594
+ }
1395
1595
  /**
1396
1596
  * When a process started, as `ps` prints it: with its id, what tells it
1397
1597
  * from a later process the OS gives the same id. Undefined when it is not
@@ -1416,6 +1616,30 @@ async function afterChange(label, run) {
1416
1616
  throw new EngineError('ACTION_MAY_HAVE_COMMITTED', `${label}: ${cause.message} (an earlier command of this step changed the app)`, { retryable: false, cause });
1417
1617
  }
1418
1618
  }
1619
+ /**
1620
+ * An observation tree with each field cut at the contract's limit, the end
1621
+ * dropped: a name at `OBSERVED_NAME_LIMIT`, text, a value, and a selection at
1622
+ * `OBSERVED_TEXT_LIMIT`. The harness reads a field exactly at its limit as
1623
+ * one that may have been cut (and redacts a secret it may end with), and one
1624
+ * long label can no longer crowd the controls after it out of what the agent
1625
+ * reads. `locate` matches on the whole tree, and single-node reads carry the
1626
+ * whole value.
1627
+ */
1628
+ function bounded(node) {
1629
+ const cut = (text, limit) => (text === undefined ? {} : { text: text.length > limit ? text.slice(0, limit) : text });
1630
+ const name = cut(node.name, OBSERVED_NAME_LIMIT).text;
1631
+ const text = cut(node.text, OBSERVED_TEXT_LIMIT).text;
1632
+ const value = cut(node.value, OBSERVED_TEXT_LIMIT).text;
1633
+ const selection = cut(node.selection, OBSERVED_TEXT_LIMIT).text;
1634
+ return {
1635
+ ...node,
1636
+ ...(name === undefined ? {} : { name }),
1637
+ ...(text === undefined ? {} : { text }),
1638
+ ...(value === undefined ? {} : { value }),
1639
+ ...(selection === undefined ? {} : { selection }),
1640
+ ...(node.children === undefined ? {} : { children: node.children.map(bounded) }),
1641
+ };
1642
+ }
1419
1643
  /** Whether two rects are the same; two missing rects are not. */
1420
1644
  function sameRect(a, b) {
1421
1645
  return a !== undefined && b !== undefined && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2e-dev/desktop",
3
- "version": "0.0.0",
3
+ "version": "0.0.1-nightly-20261123030205",
4
4
  "description": "Desktop engine for e2e agentic end-to-end testing, built on agent-desktop: native apps, a prototype tested on macOS",
5
5
  "keywords": [
6
6
  "e2e",
@@ -46,8 +46,8 @@
46
46
  "@napi-rs/image": "1.16.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@e2e-dev/core": ">=0.23.2 <1",
50
- "e2e": ">=0.23.2 <1"
49
+ "@e2e-dev/core": "0.25.0-nightly-20261123030205",
50
+ "e2e": "0.25.0-nightly-20261123030205"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "e2e": {
@@ -55,9 +55,9 @@
55
55
  }
56
56
  },
57
57
  "devDependencies": {
58
- "@e2e-dev/core": "0.24.0",
58
+ "@e2e-dev/core": "0.25.0-nightly-20261123030205",
59
59
  "@types/node": "26.6.6",
60
- "e2e": "0.24.0",
60
+ "e2e": "0.25.0-nightly-20261123030205",
61
61
  "typescript": "7.0.2",
62
62
  "vitest": "5.1.1"
63
63
  },