@reticlehq/computer 0.0.0-stage → 3.11.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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +12 -0
  3. package/README.md +217 -2
  4. package/bin/attach.mjs +330 -0
  5. package/dist/attach.d.ts +105 -0
  6. package/dist/attach.js +234 -0
  7. package/dist/channels.d.ts +42 -0
  8. package/dist/channels.js +46 -0
  9. package/dist/computer-realm.d.ts +54 -0
  10. package/dist/computer-realm.js +487 -0
  11. package/dist/doctor.d.ts +32 -0
  12. package/dist/doctor.js +42 -0
  13. package/dist/driver.d.ts +227 -0
  14. package/dist/driver.js +73 -0
  15. package/dist/effect.d.ts +60 -0
  16. package/dist/effect.js +158 -0
  17. package/dist/files.d.ts +16 -0
  18. package/dist/files.js +40 -0
  19. package/dist/hud/port.d.ts +44 -0
  20. package/dist/hud/port.js +6 -0
  21. package/dist/index.d.ts +34 -0
  22. package/dist/index.js +22 -0
  23. package/dist/lines.d.ts +34 -0
  24. package/dist/lines.js +80 -0
  25. package/dist/mac/from-ax.d.ts +27 -0
  26. package/dist/mac/from-ax.js +275 -0
  27. package/dist/mac/mac-driver.d.ts +42 -0
  28. package/dist/mac/mac-driver.js +355 -0
  29. package/dist/mac/mac-hud.d.ts +10 -0
  30. package/dist/mac/mac-hud.js +142 -0
  31. package/dist/peer/act-effect.d.ts +9 -0
  32. package/dist/peer/act-effect.js +13 -0
  33. package/dist/peer/commands.d.ts +87 -0
  34. package/dist/peer/commands.js +811 -0
  35. package/dist/peer/form.d.ts +62 -0
  36. package/dist/peer/form.js +103 -0
  37. package/dist/peer/link-switch.d.ts +12 -0
  38. package/dist/peer/link-switch.js +38 -0
  39. package/dist/peer/peer.d.ts +43 -0
  40. package/dist/peer/peer.js +216 -0
  41. package/dist/peer/pointer.d.ts +97 -0
  42. package/dist/peer/pointer.js +289 -0
  43. package/dist/peer/scroll.d.ts +12 -0
  44. package/dist/peer/scroll.js +157 -0
  45. package/dist/peer/seen.d.ts +18 -0
  46. package/dist/peer/seen.js +61 -0
  47. package/dist/peer/select.d.ts +27 -0
  48. package/dist/peer/select.js +78 -0
  49. package/dist/peer/window.d.ts +25 -0
  50. package/dist/peer/window.js +111 -0
  51. package/dist/ui-node.d.ts +93 -0
  52. package/dist/ui-node.js +192 -0
  53. package/dist/win/helper-launch.d.ts +10 -0
  54. package/dist/win/helper-launch.js +34 -0
  55. package/native/linux/Dockerfile +12 -0
  56. package/native/linux/reticle-atspi.py +933 -0
  57. package/native/linux/sandbox.mjs +127 -0
  58. package/native/mac/build/reticle-ax +0 -0
  59. package/native/mac/build/reticle-hud +0 -0
  60. package/native/mac/hud.swift +749 -0
  61. package/native/mac/reticle-ax.swift +1786 -0
  62. package/native/win/reticle-uia.ps1 +620 -0
  63. package/package.json +65 -3
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The front door.
3
+ *
4
+ * The part of the computer realm that needs no operating system: the element shape every
5
+ * reader gives, the tree text an agent reads, and the effect of an action.
6
+ */
7
+ export { UiRole, place } from './ui-node.js';
8
+ export type { Placed, UiNode } from './ui-node.js';
9
+ export { AxNodeSchema, fromAx } from './mac/from-ax.js';
10
+ export type { AxNode, FromAx } from './mac/from-ax.js';
11
+ export { RefTable, writeLines } from './lines.js';
12
+ export { ChangeKind, EffectKind, changeLine, effectOf } from './effect.js';
13
+ export type { Change, Effect } from './effect.js';
14
+ export { ComputerRealm } from './computer-realm.js';
15
+ export type { ComputerRealmDeps, Described } from './computer-realm.js';
16
+ export { CU_SURFACE, CuChannel, CuSummary } from './channels.js';
17
+ export { ActKind, ActRefusal, Delivery } from './driver.js';
18
+ export type { ActOutcome, ActRequest, SettingChange, UiDriver, UiRead } from './driver.js';
19
+ export { MacDriver, servingHelper } from './mac/mac-driver.js';
20
+ export { PIXELS_CHANGED_SIGNAL } from './driver.js';
21
+ export { helperLaunch, WINDOWS_HELPER_SCRIPT } from './win/helper-launch.js';
22
+ export type { HelperLaunch } from './win/helper-launch.js';
23
+ export type { MacDriverInput, RunHelper } from './mac/mac-driver.js';
24
+ export { CLIPBOARD_CHANGED_SIGNAL, DISK_WROTE_SIGNAL, FILE_SIGNAL_PREFIX, HUMAN_DONE, PEER_ACTIONS, PEER_COMMANDS, PeerCommands, SETTINGS_CHANGED_SIGNAL, } from './peer/commands.js';
25
+ export type { Emit, PeerCommandsDeps } from './peer/commands.js';
26
+ export { connectPeer } from './peer/peer.js';
27
+ export type { Peer, PeerInput } from './peer/peer.js';
28
+ export { OWNER_SETTINGS_FILE, STOPPED_FILE, attachPlan, electronWarning, isElectron, joinedAnswer, pickApp, withOwnerLimits, } from './attach.js';
29
+ export type { AttachPlan } from './attach.js';
30
+ export { doctorReport } from './doctor.js';
31
+ export type { DoctorFacts, DoctorReport } from './doctor.js';
32
+ export { HudEffect } from './hud/port.js';
33
+ export type { HudPort } from './hud/port.js';
34
+ export { macHud } from './mac/mac-hud.js';
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The front door.
3
+ *
4
+ * The part of the computer realm that needs no operating system: the element shape every
5
+ * reader gives, the tree text an agent reads, and the effect of an action.
6
+ */
7
+ export { UiRole, place } from './ui-node.js';
8
+ export { AxNodeSchema, fromAx } from './mac/from-ax.js';
9
+ export { RefTable, writeLines } from './lines.js';
10
+ export { ChangeKind, EffectKind, changeLine, effectOf } from './effect.js';
11
+ export { ComputerRealm } from './computer-realm.js';
12
+ export { CU_SURFACE, CuChannel, CuSummary } from './channels.js';
13
+ export { ActKind, ActRefusal, Delivery } from './driver.js';
14
+ export { MacDriver, servingHelper } from './mac/mac-driver.js';
15
+ export { PIXELS_CHANGED_SIGNAL } from './driver.js';
16
+ export { helperLaunch, WINDOWS_HELPER_SCRIPT } from './win/helper-launch.js';
17
+ export { CLIPBOARD_CHANGED_SIGNAL, DISK_WROTE_SIGNAL, FILE_SIGNAL_PREFIX, HUMAN_DONE, PEER_ACTIONS, PEER_COMMANDS, PeerCommands, SETTINGS_CHANGED_SIGNAL, } from './peer/commands.js';
18
+ export { connectPeer } from './peer/peer.js';
19
+ export { OWNER_SETTINGS_FILE, STOPPED_FILE, attachPlan, electronWarning, isElectron, joinedAnswer, pickApp, withOwnerLimits, } from './attach.js';
20
+ export { doctorReport } from './doctor.js';
21
+ export { HudEffect } from './hud/port.js';
22
+ export { macHud } from './mac/mac-hud.js';
@@ -0,0 +1,34 @@
1
+ import type { UiNode } from './ui-node.js';
2
+ /**
3
+ * Gives each element one ref for the life of a session. An element that goes away keeps its ref,
4
+ * so a ref from an old read never points at a different element.
5
+ */
6
+ export declare class RefTable {
7
+ private readonly refOfKey;
8
+ private readonly keyOfRef;
9
+ /** Refs given so far. Not the size of a map: a ref that moved leaves no key behind. */
10
+ private given;
11
+ /** What each ref named when it was given: to know the element again at another key. */
12
+ private readonly whoOfRef;
13
+ refFor(key: string, node?: UiNode): string;
14
+ /** The element a ref named when it was given or last seen. Absent: not known. */
15
+ whoOf(ref: string): UiNode | undefined;
16
+ /**
17
+ * The element of a ref is at another key now: the application changed the tree round it. The
18
+ * ref goes with the element. The old key is forgotten, so that another element that comes to
19
+ * that place gets a ref of its own.
20
+ */
21
+ move(ref: string, key: string): void;
22
+ /** The key a ref was given for, to find the element again in a new read. */
23
+ keyOf(ref: string): string | undefined;
24
+ }
25
+ /** Said on the line of an element whose name the realm took from the thing beside it. */
26
+ export declare const NAME_FROM_NEIGHBOUR = "name from neighbour";
27
+ export interface Written {
28
+ tree: string;
29
+ /** Elements left out because they have no place on the screen: closed menus, for the most part. */
30
+ omitted: number;
31
+ }
32
+ /** The tree of what is on the screen. See `placeShown`. */
33
+ export declare function writeWindows(root: UiNode, refs: RefTable): Written;
34
+ export declare function writeLines(root: UiNode, refs: RefTable): string;
package/dist/lines.js ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Writes a tree as the one-line-per-element text that `core`'s `parseInteractive` and the Harness
3
+ * read. The browser realm writes the same format from the DOM.
4
+ *
5
+ * ponytail: the format has two writers now. Move one pure writer into `core` when the browser
6
+ * adopts it.
7
+ */
8
+ import { isAddressable, label, place, placeShown, quoted } from './ui-node.js';
9
+ const INDENT = ' ';
10
+ /**
11
+ * Gives each element one ref for the life of a session. An element that goes away keeps its ref,
12
+ * so a ref from an old read never points at a different element.
13
+ */
14
+ export class RefTable {
15
+ refOfKey = new Map();
16
+ keyOfRef = new Map();
17
+ /** Refs given so far. Not the size of a map: a ref that moved leaves no key behind. */
18
+ given = 0;
19
+ /** What each ref named when it was given: to know the element again at another key. */
20
+ whoOfRef = new Map();
21
+ refFor(key, node) {
22
+ const known = this.refOfKey.get(key);
23
+ const ref = known ?? `e${String(this.given + 1)}`;
24
+ if (known === undefined) {
25
+ this.given += 1;
26
+ this.refOfKey.set(key, ref);
27
+ this.keyOfRef.set(ref, key);
28
+ }
29
+ if (node !== undefined) {
30
+ this.whoOfRef.set(ref, node);
31
+ }
32
+ return ref;
33
+ }
34
+ /** The element a ref named when it was given or last seen. Absent: not known. */
35
+ whoOf(ref) {
36
+ return this.whoOfRef.get(ref);
37
+ }
38
+ /**
39
+ * The element of a ref is at another key now: the application changed the tree round it. The
40
+ * ref goes with the element. The old key is forgotten, so that another element that comes to
41
+ * that place gets a ref of its own.
42
+ */
43
+ move(ref, key) {
44
+ const old = this.keyOfRef.get(ref);
45
+ if (old !== undefined) {
46
+ this.refOfKey.delete(old);
47
+ }
48
+ this.refOfKey.set(key, ref);
49
+ this.keyOfRef.set(ref, key);
50
+ }
51
+ /** The key a ref was given for, to find the element again in a new read. */
52
+ keyOf(ref) {
53
+ return this.keyOfRef.get(ref);
54
+ }
55
+ }
56
+ /** Said on the line of an element whose name the realm took from the thing beside it. */
57
+ export const NAME_FROM_NEIGHBOUR = 'name from neighbour';
58
+ /** The tree of what is on the screen. See `placeShown`. */
59
+ export function writeWindows(root, refs) {
60
+ const { shown, omitted, outOfView } = placeShown(root);
61
+ return { tree: writePlaced(shown, refs, outOfView), omitted };
62
+ }
63
+ export function writeLines(root, refs) {
64
+ return writePlaced(place(root), refs);
65
+ }
66
+ function writePlaced(placed, refs, outOfView = new Map()) {
67
+ return placed
68
+ .map(({ node, depth, key }) => {
69
+ const ref = isAddressable(node) ? ` (ref=${refs.refFor(key, node)})` : '';
70
+ const value = node.value !== undefined && node.value.length > 0 ? ` [value=${quoted(node.value)}]` : '';
71
+ // A loss is said on the line that has it: scroll to read the rows that are not here.
72
+ // A list of a page with items scrolled out of the window says so too.
73
+ const notShown = node.notShown ?? outOfView.get(key);
74
+ const left = notShown === undefined ? '' : ` [not shown: ${String(notShown)}]`;
75
+ const states = node.states.length > 0 ? ` [${node.states.join(',')}]` : '';
76
+ const guessed = true === node.nameGuessed ? ` [${NAME_FROM_NEIGHBOUR}]` : '';
77
+ return `${INDENT.repeat(depth)}- ${label(node)}${ref}${guessed}${value}${left}${states}`;
78
+ })
79
+ .join('\n');
80
+ }
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import type { UiNode } from '../ui-node.js';
3
+ export interface AxNode {
4
+ role: string;
5
+ subrole?: string | undefined;
6
+ title?: string | undefined;
7
+ description?: string | undefined;
8
+ value?: string | undefined;
9
+ enabled?: boolean | undefined;
10
+ focused?: boolean | undefined;
11
+ selected?: boolean | undefined;
12
+ id?: string | undefined;
13
+ help?: string | undefined;
14
+ frame?: number[] | undefined;
15
+ /** The place among all the children of the parent, when the helper left some out. */
16
+ i?: number | undefined;
17
+ /** Children the helper left out. */
18
+ notShown?: number | undefined;
19
+ children: AxNode[];
20
+ }
21
+ export declare const AxNodeSchema: z.ZodType<AxNode>;
22
+ export interface FromAx {
23
+ root: UiNode;
24
+ /** The macOS roles this reader does not know. Each such element is kept, as a `group`. */
25
+ unmapped: string[];
26
+ }
27
+ export declare function fromAx(ax: AxNode): FromAx;
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Turns the tree that `reticle-ax` reads from the macOS Accessibility API into `UiNode`.
3
+ *
4
+ * It keeps every element, in order. The helper finds an element by its child index at each level,
5
+ * so an element dropped here would move every index after it.
6
+ */
7
+ import { ElementState } from '@reticlehq/core';
8
+ import { z } from 'zod';
9
+ import { UiRole } from '../ui-node.js';
10
+ export const AxNodeSchema = z.lazy(() => z.object({
11
+ role: z.string(),
12
+ subrole: z.string().optional(),
13
+ title: z.string().optional(),
14
+ description: z.string().optional(),
15
+ value: z.string().optional(),
16
+ enabled: z.boolean().optional(),
17
+ focused: z.boolean().optional(),
18
+ selected: z.boolean().optional(),
19
+ id: z.string().optional(),
20
+ help: z.string().optional(),
21
+ frame: z.array(z.number()).optional(),
22
+ i: z.number().optional(),
23
+ notShown: z.number().optional(),
24
+ children: z.array(AxNodeSchema),
25
+ }));
26
+ const AxRole = {
27
+ SCROLL_AREA: 'AXScrollArea',
28
+ STATIC_TEXT: 'AXStaticText',
29
+ TEXT_FIELD: 'AXTextField',
30
+ CHECKBOX: 'AXCheckBox',
31
+ RADIO: 'AXRadioButton',
32
+ MENU_ITEM: 'AXMenuItem',
33
+ ROW: 'AXRow',
34
+ DISCLOSURE: 'AXDisclosureTriangle',
35
+ };
36
+ const AX_ON = '1';
37
+ /** The roles whose value 1 says "on": a ticked box, the current tab, the current profile. */
38
+ const ON_ROLES = new Set([AxRole.CHECKBOX, AxRole.RADIO, AxRole.MENU_ITEM]);
39
+ const SELECTED = 'selected';
40
+ const ROLE_OF = {
41
+ AXApplication: UiRole.APPLICATION,
42
+ AXWindow: UiRole.WINDOW,
43
+ AXSheet: UiRole.DIALOG,
44
+ AXDialog: UiRole.DIALOG,
45
+ AXButton: UiRole.BUTTON,
46
+ [AxRole.CHECKBOX]: UiRole.CHECKBOX,
47
+ AXRadioButton: UiRole.RADIO,
48
+ AXTextField: UiRole.TEXTBOX,
49
+ AXTextArea: UiRole.TEXTBOX,
50
+ AXSearchField: UiRole.TEXTBOX,
51
+ AXComboBox: UiRole.COMBOBOX,
52
+ AXPopUpButton: UiRole.COMBOBOX,
53
+ AXSlider: UiRole.SLIDER,
54
+ AXScrollBar: UiRole.SCROLLBAR,
55
+ AXLink: UiRole.LINK,
56
+ AXMenu: UiRole.MENU,
57
+ AXMenuBar: UiRole.MENU,
58
+ AXMenuItem: UiRole.MENUITEM,
59
+ AXMenuBarItem: UiRole.MENUITEM,
60
+ AXMenuButton: UiRole.MENUITEM,
61
+ AXRow: UiRole.ROW,
62
+ // The arrow that opens a row. A press on it opens or closes the row.
63
+ [AxRole.DISCLOSURE]: UiRole.BUTTON,
64
+ AXSplitter: UiRole.GROUP,
65
+ AXCell: UiRole.CELL,
66
+ AXList: UiRole.LIST,
67
+ AXTable: UiRole.LIST,
68
+ AXOutline: UiRole.LIST,
69
+ AXImage: UiRole.IMAGE,
70
+ [AxRole.STATIC_TEXT]: UiRole.TEXT,
71
+ AXHeading: UiRole.HEADING,
72
+ // The bullet or the number before a list item in a web view.
73
+ AXListMarker: UiRole.GROUP,
74
+ AXWebArea: UiRole.DOCUMENT,
75
+ AXGroup: UiRole.GROUP,
76
+ AXScrollArea: UiRole.GROUP,
77
+ AXSplitGroup: UiRole.GROUP,
78
+ AXTabGroup: UiRole.GROUP,
79
+ AXRadioGroup: UiRole.GROUP,
80
+ AXValueIndicator: UiRole.GROUP,
81
+ AXToolbar: UiRole.GROUP,
82
+ AXUnknown: UiRole.GROUP,
83
+ };
84
+ function statesOf(ax) {
85
+ const states = [];
86
+ if (false === ax.enabled) {
87
+ states.push(ElementState.DISABLED);
88
+ }
89
+ if (ON_ROLES.has(ax.role) && ax.value === AX_ON) {
90
+ states.push(ElementState.CHECKED);
91
+ }
92
+ if (ax.role === AxRole.DISCLOSURE && ax.value === AX_ON) {
93
+ states.push(ElementState.EXPANDED);
94
+ }
95
+ if (true === ax.focused) {
96
+ states.push(ElementState.FOCUSED);
97
+ }
98
+ return states;
99
+ }
100
+ /** The start of an identifier that AppKit makes by itself. It changes when the window is built again. */
101
+ const MADE_BY_APPKIT = '_NS:';
102
+ /**
103
+ * An identifier that a web framework makes by itself. It is another one after the next change to
104
+ * the page, so a saved flow that finds an element by it does not find the element again.
105
+ * ponytail: a list of the makers that are known. An identifier of another maker is kept, and a
106
+ * flow that is saved by it then goes "not found", which is a failure a person can see.
107
+ */
108
+ const MADE_BY_A_FRAMEWORK = new RegExp([
109
+ // React: a colon, the letter r and a count, in small letters in the browser and in capital
110
+ // letters from the server. React 19 puts the same between « and ».
111
+ ':r[0-9a-z]+:',
112
+ '«r[0-9a-z]+»',
113
+ // A count that a library puts after its own name: Angular Material and its CDK, Ember,
114
+ // Headless UI, React Aria.
115
+ '^(mat|cdk|headlessui|react-aria)-.*\\d+$',
116
+ '^ember\\d+$',
117
+ ].join('|'), 'i');
118
+ /** The identifier, when a person gave it. One that a toolkit made is not a name for anything. */
119
+ function givenId(id) {
120
+ if (id === undefined || 0 === id.length) {
121
+ return undefined;
122
+ }
123
+ return id.startsWith(MADE_BY_APPKIT) || MADE_BY_A_FRAMEWORK.test(id) ? undefined : id;
124
+ }
125
+ /**
126
+ * A name for an element that has none, from its subrole. The buttons at the top of a window are
127
+ * the case: the system says what each one is, and gives it no title.
128
+ */
129
+ const NAME_OF_SUBROLE = {
130
+ AXCloseButton: 'Close window',
131
+ AXMinimizeButton: 'Minimize window',
132
+ AXZoomButton: 'Zoom window',
133
+ AXFullScreenButton: 'Full screen',
134
+ };
135
+ /** The name of the arrow that opens a row. The system gives it none. */
136
+ const DISCLOSURE_NAME = 'Show or hide rows';
137
+ /**
138
+ * The first words inside an element: the value of a text or of a field, in the order of the
139
+ * tree. A row of an outline or of a table has no title, and a person names it by these words.
140
+ */
141
+ function wordsIn(node) {
142
+ for (const child of node.children) {
143
+ const holdsWords = AxRole.STATIC_TEXT === child.role || AxRole.TEXT_FIELD === child.role;
144
+ const own = holdsWords ? (child.value ?? '') : '';
145
+ const found = 0 === own.length ? wordsIn(child) : own;
146
+ if (found.length > 0) {
147
+ return found;
148
+ }
149
+ }
150
+ return '';
151
+ }
152
+ /** The controls that are named by what is beside them, when the application gives no name. */
153
+ const WORD_OF_ROLE = {
154
+ [UiRole.COMBOBOX]: 'Menu',
155
+ [UiRole.BUTTON]: 'Button',
156
+ [UiRole.CHECKBOX]: 'Box',
157
+ [UiRole.RADIO]: 'Choice',
158
+ [UiRole.LINK]: 'Link',
159
+ };
160
+ /** The roles whose name can name a neighbour: what a person reads beside a control. */
161
+ const NAMING_ROLES = new Set([
162
+ UiRole.BUTTON,
163
+ UiRole.TEXT,
164
+ UiRole.CHECKBOX,
165
+ UiRole.LINK,
166
+ UiRole.HEADING,
167
+ UiRole.COMBOBOX,
168
+ UiRole.RADIO,
169
+ ]);
170
+ /** How many parents up a name is looked for. Farther up, it is the name of the whole list. */
171
+ const NEIGHBOUR_LEVELS = 4;
172
+ /** True when the child at `at` is a row of a list: a group with no name, with a twin of its shape. */
173
+ function isRowOfList(kids, at) {
174
+ const row = kids[at];
175
+ const shape = (n) => n.children.map((c) => c.role).join(' ');
176
+ const isGroup = (n) => n.role === UiRole.GROUP && 0 === n.name.length;
177
+ return (row !== undefined &&
178
+ isGroup(row) &&
179
+ kids.some((other, i) => i !== at && isGroup(other) && shape(other) === shape(row)));
180
+ }
181
+ /** The first name in an element, in the order of the tree, or from its end. */
182
+ function nameIn(node, fromEnd) {
183
+ if (node.name.length > 0 && NAMING_ROLES.has(node.role)) {
184
+ return node.name;
185
+ }
186
+ const order = fromEnd ? [...node.children].reverse() : node.children;
187
+ for (const child of order) {
188
+ const found = nameIn(child, fromEnd);
189
+ if (found.length > 0) {
190
+ return found;
191
+ }
192
+ }
193
+ return '';
194
+ }
195
+ /**
196
+ * A name for each control that has none, from the nearest named thing beside it: first what comes
197
+ * before it, nearest first, then what comes after it, then the same one parent up. Granola gives
198
+ * the menu of each meeting with no name, no text and no tip, and a person tells them apart by the
199
+ * meeting beside each one. Not farther than a few parents: the name of the whole list would give
200
+ * every menu in it the same name. A control with nothing named near it keeps no name.
201
+ */
202
+ function nameByNeighbours(node, chain = [], at = []) {
203
+ const word = WORD_OF_ROLE[node.role];
204
+ let name = node.name;
205
+ let guessed = false;
206
+ if (0 === name.length && word !== undefined) {
207
+ for (let up = chain.length - 1; up >= 0 && chain.length - up <= NEIGHBOUR_LEVELS; up -= 1) {
208
+ const kids = chain[up]?.children ?? [];
209
+ const i = at[up] ?? 0;
210
+ // Not into another row of the same list: a row with nothing named in it would take the
211
+ // name of the row above, and an agent would open the menu of another meeting.
212
+ if (isRowOfList(kids, i)) {
213
+ break;
214
+ }
215
+ const before = kids
216
+ .slice(0, i)
217
+ .reverse()
218
+ .map((s) => nameIn(s, true));
219
+ const after = kids.slice(i + 1).map((s) => nameIn(s, false));
220
+ const found = [...before, ...after].find((one) => one.length > 0);
221
+ if (found !== undefined) {
222
+ name = `${word} by ${found}`;
223
+ guessed = true;
224
+ break;
225
+ }
226
+ }
227
+ }
228
+ return {
229
+ ...node,
230
+ name,
231
+ ...(guessed ? { nameGuessed: true } : {}),
232
+ children: node.children.map((child, index) => nameByNeighbours(child, [...chain, node], [...at, index])),
233
+ };
234
+ }
235
+ export function fromAx(ax) {
236
+ const unmapped = new Set();
237
+ const convert = (node) => {
238
+ const role = ROLE_OF[node.role];
239
+ if (role === undefined && node.role.length > 0) {
240
+ unmapped.add(node.role);
241
+ }
242
+ // A static text has no title: its words are its value, and they are what a person reads.
243
+ const isText = node.role === AxRole.STATIC_TEXT;
244
+ const said = (isText ? node.value : undefined) ?? node.title ?? node.description ?? '';
245
+ const fromRow = 0 === said.length && AxRole.ROW === node.role ? wordsIn(node) : '';
246
+ const fromRole = AxRole.DISCLOSURE === node.role ? DISCLOSURE_NAME : fromRow;
247
+ const name = 0 === said.length ? (NAME_OF_SUBROLE[node.subrole ?? ''] ?? fromRole) : said;
248
+ // ponytail: the wire has no "selected" state, so a chosen row says it in its value. Add the
249
+ // state to `ElementState` in core when a second realm needs it.
250
+ const chosen = true === node.selected ? SELECTED : undefined;
251
+ // The value of a checkbox and of the arrow of a row is said as a state, and not twice.
252
+ const asState = AxRole.CHECKBOX === node.role || AxRole.DISCLOSURE === node.role;
253
+ const value = isText || asState ? undefined : (chosen ?? node.value);
254
+ const id = givenId(node.id);
255
+ const [x, y, w, h] = node.frame ?? [];
256
+ const frame = x === undefined || y === undefined || w === undefined || h === undefined
257
+ ? undefined
258
+ : [x, y, w, h];
259
+ return {
260
+ role: role ?? UiRole.GROUP,
261
+ name,
262
+ ...(value === undefined ? {} : { value }),
263
+ states: statesOf(node),
264
+ ...(frame === undefined ? {} : { frame }),
265
+ ...(node.i === undefined ? {} : { index: node.i }),
266
+ ...(id === undefined ? {} : { id }),
267
+ ...(node.help === undefined ? {} : { help: node.help }),
268
+ ...(node.notShown === undefined || 0 === node.notShown ? {} : { notShown: node.notShown }),
269
+ ...(AxRole.SCROLL_AREA === node.role ? { clips: true } : {}),
270
+ children: node.children.map(convert),
271
+ };
272
+ };
273
+ const root = nameByNeighbours(convert(ax));
274
+ return { root, unmapped: [...unmapped].sort() };
275
+ }
@@ -0,0 +1,42 @@
1
+ import type { ActOutcome, ActRequest, CaptureHow, Captured, PictureText, ReachAnswer, UiDriver, UiRead } from '../driver.js';
2
+ import type { Placed } from '../ui-node.js';
3
+ export type RunHelper = (file: string, args: readonly string[]) => Promise<string>;
4
+ /**
5
+ * One helper process for the life of a driver. A command is one line to it, and its answer is one
6
+ * line back.
7
+ *
8
+ * A process for each command took about 70 ms to read a small window, and 5 ms of that was the
9
+ * read: the rest was the start of the process and its first word with the application.
10
+ *
11
+ * Commands go one at a time. The helper answers in order, and an answer has no name on it.
12
+ */
13
+ export declare function servingHelper(prefix?: readonly string[]): RunHelper;
14
+ export interface MacDriverInput {
15
+ /** The path of the `reticle-ax` program. */
16
+ helper: string;
17
+ app: string;
18
+ pid: number;
19
+ run?: RunHelper;
20
+ /**
21
+ * Try the switch a screen reader sets, once, at the first read that shows a window, and keep it
22
+ * when it fills a container that was empty (the sheet of Numbers). Not before a window: under
23
+ * Stage Manager an application opened in the background has none, and there is nothing to test.
24
+ */
25
+ screenReaderSwitch?: boolean;
26
+ }
27
+ /** Removes every picture this process wrote. It runs when the process ends. */
28
+ export declare function removeCaptures(): void;
29
+ export declare class MacDriver implements UiDriver {
30
+ #private;
31
+ constructor(input: MacDriverInput);
32
+ subject(): {
33
+ app: string;
34
+ pid: number;
35
+ };
36
+ read(): Promise<UiRead>;
37
+ capture(how?: CaptureHow): Promise<Captured>;
38
+ /** The words of a picture file. Undefined from a helper that has no reader (Windows, Linux). */
39
+ texts(path: string): Promise<readonly PictureText[] | undefined>;
40
+ reach(target: Placed): Promise<ReachAnswer>;
41
+ act(request: ActRequest): Promise<ActOutcome>;
42
+ }