@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.
- package/LICENSE +202 -0
- package/NOTICE +12 -0
- package/README.md +217 -2
- package/bin/attach.mjs +330 -0
- package/dist/attach.d.ts +105 -0
- package/dist/attach.js +234 -0
- package/dist/channels.d.ts +42 -0
- package/dist/channels.js +46 -0
- package/dist/computer-realm.d.ts +54 -0
- package/dist/computer-realm.js +487 -0
- package/dist/doctor.d.ts +32 -0
- package/dist/doctor.js +42 -0
- package/dist/driver.d.ts +227 -0
- package/dist/driver.js +73 -0
- package/dist/effect.d.ts +60 -0
- package/dist/effect.js +158 -0
- package/dist/files.d.ts +16 -0
- package/dist/files.js +40 -0
- package/dist/hud/port.d.ts +44 -0
- package/dist/hud/port.js +6 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +22 -0
- package/dist/lines.d.ts +34 -0
- package/dist/lines.js +80 -0
- package/dist/mac/from-ax.d.ts +27 -0
- package/dist/mac/from-ax.js +275 -0
- package/dist/mac/mac-driver.d.ts +42 -0
- package/dist/mac/mac-driver.js +355 -0
- package/dist/mac/mac-hud.d.ts +10 -0
- package/dist/mac/mac-hud.js +142 -0
- package/dist/peer/act-effect.d.ts +9 -0
- package/dist/peer/act-effect.js +13 -0
- package/dist/peer/commands.d.ts +87 -0
- package/dist/peer/commands.js +811 -0
- package/dist/peer/form.d.ts +62 -0
- package/dist/peer/form.js +103 -0
- package/dist/peer/link-switch.d.ts +12 -0
- package/dist/peer/link-switch.js +38 -0
- package/dist/peer/peer.d.ts +43 -0
- package/dist/peer/peer.js +216 -0
- package/dist/peer/pointer.d.ts +97 -0
- package/dist/peer/pointer.js +289 -0
- package/dist/peer/scroll.d.ts +12 -0
- package/dist/peer/scroll.js +157 -0
- package/dist/peer/seen.d.ts +18 -0
- package/dist/peer/seen.js +61 -0
- package/dist/peer/select.d.ts +27 -0
- package/dist/peer/select.js +78 -0
- package/dist/peer/window.d.ts +25 -0
- package/dist/peer/window.js +111 -0
- package/dist/ui-node.d.ts +93 -0
- package/dist/ui-node.js +192 -0
- package/dist/win/helper-launch.d.ts +10 -0
- package/dist/win/helper-launch.js +34 -0
- package/native/linux/Dockerfile +12 -0
- package/native/linux/reticle-atspi.py +933 -0
- package/native/linux/sandbox.mjs +127 -0
- package/native/mac/build/reticle-ax +0 -0
- package/native/mac/build/reticle-hud +0 -0
- package/native/mac/hud.swift +749 -0
- package/native/mac/reticle-ax.swift +1786 -0
- package/native/win/reticle-uia.ps1 +620 -0
- package/package.json +65 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Seen } from './seen.js';
|
|
2
|
+
import type { ActResult } from './form.js';
|
|
3
|
+
import type { SelectContext } from './select.js';
|
|
4
|
+
/** What the helper is asked to do with the window, from `args.arrange` or `args.frame`. */
|
|
5
|
+
export declare function windowValue(more: Record<string, unknown>): string;
|
|
6
|
+
/** The window as the answer gives it: from the helper's read of it, or from the tree after. */
|
|
7
|
+
export interface WindowAnswer {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
minimized: boolean;
|
|
13
|
+
fullscreen: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* On the application element it arranges the main window, and `restore` brings back the window
|
|
17
|
+
* that is minimized or in full screen: a minimized window is not on the screen and has no ref.
|
|
18
|
+
*
|
|
19
|
+
* Arranges the window of the element, as a person does with the buttons of a window and the
|
|
20
|
+
* Window menu. No pointer is used: the helper sets the window through the Accessibility API, so it
|
|
21
|
+
* works in the background too. The answer gives the frame of the window after the change, which
|
|
22
|
+
* is the proof, with `minimized` and `fullscreen`: a minimized window keeps its frame, so the
|
|
23
|
+
* frame alone does not say that it went to the Dock.
|
|
24
|
+
*/
|
|
25
|
+
export declare function arrangeWindow(ctx: Pick<SelectContext, 'drive'>, target: Seen, ref: string, more: Record<string, unknown>): Promise<ActResult>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ActionType, WindowArrangement } from '@reticlehq/core';
|
|
2
|
+
import { ActKind, Delivery } from '../driver.js';
|
|
3
|
+
import { UiRole } from '../ui-node.js';
|
|
4
|
+
import { see } from './seen.js';
|
|
5
|
+
/** How long the window may move before the answer: macOS animates a zoom and a minimize. */
|
|
6
|
+
const WINDOW_SETTLE_MS = 1200;
|
|
7
|
+
const ARRANGEMENTS = Object.values(WindowArrangement);
|
|
8
|
+
/** The value the helper takes for an exact frame: "frame:x,y,width,height". */
|
|
9
|
+
const FRAME_PREFIX = 'frame:';
|
|
10
|
+
/** What the helper is asked to do with the window, from `args.arrange` or `args.frame`. */
|
|
11
|
+
export function windowValue(more) {
|
|
12
|
+
const arrange = more['arrange'];
|
|
13
|
+
if ('string' === typeof arrange && ARRANGEMENTS.includes(arrange)) {
|
|
14
|
+
return arrange;
|
|
15
|
+
}
|
|
16
|
+
const frame = more['frame'];
|
|
17
|
+
if ('object' === typeof frame && null !== frame) {
|
|
18
|
+
const { x, y, width, height } = frame;
|
|
19
|
+
const numbers = [x, y, width, height];
|
|
20
|
+
if (numbers.every((n) => 'number' === typeof n && Number.isFinite(n))) {
|
|
21
|
+
return `${FRAME_PREFIX}${numbers.map(String).join(',')}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`window needs args.arrange, one of: ${ARRANGEMENTS.join(', ')}; or args.frame: { x, y, width, height } in screen points.`);
|
|
25
|
+
}
|
|
26
|
+
/** The frame of the window that holds the element: the window whose path starts the element's. */
|
|
27
|
+
function frameInTree(root, target) {
|
|
28
|
+
const holds = (path) => path.length <= target.path.length && path.every((step, i) => step === target.path[i]);
|
|
29
|
+
return see(root)
|
|
30
|
+
.filter((s) => s.node.role === UiRole.WINDOW && holds(s.path))
|
|
31
|
+
.sort((a, b) => b.path.length - a.path.length)[0]?.node.frame;
|
|
32
|
+
}
|
|
33
|
+
function answerOf(outcome, target) {
|
|
34
|
+
const state = outcome.windowState;
|
|
35
|
+
const frame = state?.frame ?? frameInTree(outcome.after.root, target);
|
|
36
|
+
if (frame === undefined) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
x: frame[0],
|
|
41
|
+
y: frame[1],
|
|
42
|
+
width: frame[2],
|
|
43
|
+
height: frame[3],
|
|
44
|
+
minimized: state?.minimized ?? false,
|
|
45
|
+
fullscreen: state?.fullscreen ?? false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** How far a frame may be from the one asked for: the system rounds to whole points. */
|
|
49
|
+
const FRAME_SLACK = 2;
|
|
50
|
+
/**
|
|
51
|
+
* What is not as asked, after the change, in words. Absent: the window is as asked. The answer of
|
|
52
|
+
* the system to the set is not the proof: an application with no tile in the Dock says yes to
|
|
53
|
+
* minimize, and its window stays where it was. A window with a smallest size does not take half
|
|
54
|
+
* of a small screen.
|
|
55
|
+
*/
|
|
56
|
+
function notAsAsked(value, state) {
|
|
57
|
+
if (state === undefined) {
|
|
58
|
+
return 'was not read after the change, so nothing proves that it changed.';
|
|
59
|
+
}
|
|
60
|
+
if (value === WindowArrangement.MINIMIZE && !state.minimized) {
|
|
61
|
+
return 'did not go to the Dock: it is still on the screen.';
|
|
62
|
+
}
|
|
63
|
+
if (value === WindowArrangement.FULLSCREEN && !state.fullscreen) {
|
|
64
|
+
return 'did not go to full screen.';
|
|
65
|
+
}
|
|
66
|
+
if (value === WindowArrangement.RESTORE && (state.minimized || state.fullscreen)) {
|
|
67
|
+
return `is still ${state.minimized ? 'minimized' : 'in full screen'}.`;
|
|
68
|
+
}
|
|
69
|
+
const { frame, wanted } = state;
|
|
70
|
+
if (wanted !== undefined) {
|
|
71
|
+
const off = frame === undefined || wanted.some((n, i) => Math.abs(n - (frame[i] ?? n)) > FRAME_SLACK);
|
|
72
|
+
if (off) {
|
|
73
|
+
return `did not take the frame ${wanted.join(',')}: it is ${frame?.join(',') ?? 'not on the screen'}. The window can have a smallest or a largest size.`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* On the application element it arranges the main window, and `restore` brings back the window
|
|
80
|
+
* that is minimized or in full screen: a minimized window is not on the screen and has no ref.
|
|
81
|
+
*
|
|
82
|
+
* Arranges the window of the element, as a person does with the buttons of a window and the
|
|
83
|
+
* Window menu. No pointer is used: the helper sets the window through the Accessibility API, so it
|
|
84
|
+
* works in the background too. The answer gives the frame of the window after the change, which
|
|
85
|
+
* is the proof, with `minimized` and `fullscreen`: a minimized window keeps its frame, so the
|
|
86
|
+
* frame alone does not say that it went to the Dock.
|
|
87
|
+
*/
|
|
88
|
+
export async function arrangeWindow(ctx, target, ref, more) {
|
|
89
|
+
const value = windowValue(more);
|
|
90
|
+
const { outcome, changes } = await ctx.drive(target, ref, ActKind.WINDOW, value, {
|
|
91
|
+
delivery: Delivery.DIRECT,
|
|
92
|
+
budgetMs: WINDOW_SETTLE_MS,
|
|
93
|
+
});
|
|
94
|
+
const window = answerOf(outcome, target);
|
|
95
|
+
const wrong = notAsAsked(value, outcome.windowState);
|
|
96
|
+
if (wrong !== undefined) {
|
|
97
|
+
throw new Error(`the window of ${target.node.name || 'the element'} ${wrong}`);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...(window === undefined ? {} : { window }),
|
|
101
|
+
ok: true,
|
|
102
|
+
ref,
|
|
103
|
+
action: ActionType.WINDOW,
|
|
104
|
+
dispatched: true,
|
|
105
|
+
settled: outcome.settled,
|
|
106
|
+
settleReason: null,
|
|
107
|
+
effect: { dispatched: true, targetMatched: true, domMutatedWithin: changes.length },
|
|
108
|
+
role: target.node.role,
|
|
109
|
+
name: target.node.name,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One element of an application's user interface, as the operating system's accessibility tree
|
|
3
|
+
* describes it. Every reader (macOS AX, Windows UI Automation, Linux AT-SPI) gives this one shape,
|
|
4
|
+
* so nothing after the reader knows which operating system the element came from.
|
|
5
|
+
*/
|
|
6
|
+
import type { ElementState } from '@reticlehq/core';
|
|
7
|
+
/** Roles are lower-case letters only: the tree parsers in `core` and the Harness read `[a-z]+`. */
|
|
8
|
+
export declare const UiRole: {
|
|
9
|
+
readonly APPLICATION: "application";
|
|
10
|
+
readonly WINDOW: "window";
|
|
11
|
+
readonly DIALOG: "dialog";
|
|
12
|
+
readonly BUTTON: "button";
|
|
13
|
+
readonly CHECKBOX: "checkbox";
|
|
14
|
+
readonly RADIO: "radio";
|
|
15
|
+
readonly TEXTBOX: "textbox";
|
|
16
|
+
readonly COMBOBOX: "combobox";
|
|
17
|
+
readonly SLIDER: "slider";
|
|
18
|
+
readonly SCROLLBAR: "scrollbar";
|
|
19
|
+
readonly LINK: "link";
|
|
20
|
+
readonly MENU: "menu";
|
|
21
|
+
readonly MENUITEM: "menuitem";
|
|
22
|
+
readonly TAB: "tab";
|
|
23
|
+
readonly ROW: "row";
|
|
24
|
+
readonly CELL: "cell";
|
|
25
|
+
readonly LIST: "list";
|
|
26
|
+
readonly IMAGE: "img";
|
|
27
|
+
readonly TEXT: "text";
|
|
28
|
+
readonly HEADING: "heading";
|
|
29
|
+
/** The page in a web view. */
|
|
30
|
+
readonly DOCUMENT: "document";
|
|
31
|
+
readonly GROUP: "group";
|
|
32
|
+
};
|
|
33
|
+
export type UiRole = (typeof UiRole)[keyof typeof UiRole];
|
|
34
|
+
export interface UiNode {
|
|
35
|
+
role: UiRole;
|
|
36
|
+
/** The accessible name. Empty when the application gives none. */
|
|
37
|
+
name: string;
|
|
38
|
+
value?: string;
|
|
39
|
+
states: readonly ElementState[];
|
|
40
|
+
/** Where the element is on the screen: x, y, width, height. Absent when the reader has none. */
|
|
41
|
+
frame?: readonly [number, number, number, number];
|
|
42
|
+
/**
|
|
43
|
+
* The place of the element among ALL the children of its parent, when the reader left some out.
|
|
44
|
+
* Absent: the reader gave every child, and the place is the order here.
|
|
45
|
+
*/
|
|
46
|
+
index?: number;
|
|
47
|
+
/** Children the reader left out: the rows of a table that are not on the screen. */
|
|
48
|
+
notShown?: number;
|
|
49
|
+
/**
|
|
50
|
+
* A scroll area: what it holds is seen only inside its frame. Absent: the element clips nothing.
|
|
51
|
+
*/
|
|
52
|
+
clips?: true;
|
|
53
|
+
/**
|
|
54
|
+
* The identifier the maker of the application gave the element. It does not change when the
|
|
55
|
+
* words on the element change, so a saved flow finds the element by it. Absent: none was given.
|
|
56
|
+
*/
|
|
57
|
+
id?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The words a person gets when the pointer rests on the element: its tooltip. The realm reads
|
|
60
|
+
* them from the tree. It does not move a pointer.
|
|
61
|
+
*/
|
|
62
|
+
help?: string;
|
|
63
|
+
/**
|
|
64
|
+
* True when the application gave no name, and the realm took the name from the nearest named
|
|
65
|
+
* thing beside the element. It is a guess, and the lines say so.
|
|
66
|
+
*/
|
|
67
|
+
nameGuessed?: boolean;
|
|
68
|
+
children: readonly UiNode[];
|
|
69
|
+
}
|
|
70
|
+
export declare function isAddressable(node: UiNode): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* A string in double quotes, with the escapes the tree parsers read back. A line break is written
|
|
73
|
+
* as \n: the element stays on one line of the tree, and the agent still sees each line of a text.
|
|
74
|
+
*/
|
|
75
|
+
export declare function quoted(text: string): string;
|
|
76
|
+
/** `button "Save"`: the role, and the name when there is one. */
|
|
77
|
+
export declare function label(node: UiNode): string;
|
|
78
|
+
export interface Placed {
|
|
79
|
+
node: UiNode;
|
|
80
|
+
depth: number;
|
|
81
|
+
/** Where the element is: the labels from the root down, each with its place among its twins. */
|
|
82
|
+
key: string;
|
|
83
|
+
parentKey: string | undefined;
|
|
84
|
+
/** The child index at each level from the root. A reader finds the element again with it. */
|
|
85
|
+
path: readonly number[];
|
|
86
|
+
}
|
|
87
|
+
export declare function place(root: UiNode): Placed[];
|
|
88
|
+
export declare function placeShown(root: UiNode): {
|
|
89
|
+
shown: Placed[];
|
|
90
|
+
omitted: number;
|
|
91
|
+
/** For an element on the screen: how many of its children are scrolled out of the window. */
|
|
92
|
+
outOfView: Map<string, number>;
|
|
93
|
+
};
|
package/dist/ui-node.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/** Roles are lower-case letters only: the tree parsers in `core` and the Harness read `[a-z]+`. */
|
|
2
|
+
export const UiRole = {
|
|
3
|
+
APPLICATION: 'application',
|
|
4
|
+
WINDOW: 'window',
|
|
5
|
+
DIALOG: 'dialog',
|
|
6
|
+
BUTTON: 'button',
|
|
7
|
+
CHECKBOX: 'checkbox',
|
|
8
|
+
RADIO: 'radio',
|
|
9
|
+
TEXTBOX: 'textbox',
|
|
10
|
+
COMBOBOX: 'combobox',
|
|
11
|
+
SLIDER: 'slider',
|
|
12
|
+
SCROLLBAR: 'scrollbar',
|
|
13
|
+
LINK: 'link',
|
|
14
|
+
MENU: 'menu',
|
|
15
|
+
MENUITEM: 'menuitem',
|
|
16
|
+
TAB: 'tab',
|
|
17
|
+
ROW: 'row',
|
|
18
|
+
CELL: 'cell',
|
|
19
|
+
LIST: 'list',
|
|
20
|
+
IMAGE: 'img',
|
|
21
|
+
TEXT: 'text',
|
|
22
|
+
HEADING: 'heading',
|
|
23
|
+
/** The page in a web view. */
|
|
24
|
+
DOCUMENT: 'document',
|
|
25
|
+
GROUP: 'group',
|
|
26
|
+
};
|
|
27
|
+
/** A person can act on these, so each one gets a ref even when it has no name. */
|
|
28
|
+
const INTERACTIVE = new Set([
|
|
29
|
+
UiRole.BUTTON,
|
|
30
|
+
UiRole.CHECKBOX,
|
|
31
|
+
UiRole.RADIO,
|
|
32
|
+
UiRole.TEXTBOX,
|
|
33
|
+
UiRole.COMBOBOX,
|
|
34
|
+
UiRole.SLIDER,
|
|
35
|
+
UiRole.LINK,
|
|
36
|
+
UiRole.MENUITEM,
|
|
37
|
+
UiRole.TAB,
|
|
38
|
+
// A row has no name of its own, and a person clicks it to choose it.
|
|
39
|
+
UiRole.ROW,
|
|
40
|
+
// An empty cell of a sheet has no name, and it is where a person types a value.
|
|
41
|
+
UiRole.CELL,
|
|
42
|
+
]);
|
|
43
|
+
export function isAddressable(node) {
|
|
44
|
+
return INTERACTIVE.has(node.role) || node.name.length > 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A string in double quotes, with the escapes the tree parsers read back. A line break is written
|
|
48
|
+
* as \n: the element stays on one line of the tree, and the agent still sees each line of a text.
|
|
49
|
+
*/
|
|
50
|
+
export function quoted(text) {
|
|
51
|
+
return `"${text.replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\r', '').replaceAll('\n', '\\n')}"`;
|
|
52
|
+
}
|
|
53
|
+
/** `button "Save"`: the role, and the name when there is one. */
|
|
54
|
+
export function label(node) {
|
|
55
|
+
return node.name.length > 0 ? `${node.role} ${quoted(node.name)}` : node.role;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Every element in document order, each with a key that stays the same from one read to the next.
|
|
59
|
+
*
|
|
60
|
+
* The accessibility tree gives no stable id, so the key is the path. Two siblings with the same
|
|
61
|
+
* role and name differ by their order.
|
|
62
|
+
* ponytail: a path key changes when an ancestor is renamed. Use the operating system's own
|
|
63
|
+
* identifier (`AXIdentifier`, `AutomationId`) when the reader has one.
|
|
64
|
+
*/
|
|
65
|
+
/** A group with no name: the item of a list, when it has twins beside it. */
|
|
66
|
+
function isListItem(node) {
|
|
67
|
+
return node.role === UiRole.GROUP && 0 === node.name.length;
|
|
68
|
+
}
|
|
69
|
+
/** The roles of the children of an element, in order. Two items of one list have the same. */
|
|
70
|
+
function shapeOf(node) {
|
|
71
|
+
return node.children.map((child) => child.role).join(' ');
|
|
72
|
+
}
|
|
73
|
+
/** The first words in an element, from a text or a field below it. Only for a key. */
|
|
74
|
+
function firstWords(node) {
|
|
75
|
+
for (const child of node.children) {
|
|
76
|
+
const holds = child.role === UiRole.TEXT || child.role === UiRole.TEXTBOX;
|
|
77
|
+
const own = holds ? child.name || (child.value ?? '') : '';
|
|
78
|
+
const found = 0 === own.length ? firstWords(child) : own;
|
|
79
|
+
if (found.length > 0) {
|
|
80
|
+
return found;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
export function place(root) {
|
|
86
|
+
const out = [];
|
|
87
|
+
const visit = (node, path, key, parentKey) => {
|
|
88
|
+
out.push({ node, depth: path.length, key, parentKey, path });
|
|
89
|
+
const seen = new Map();
|
|
90
|
+
// Groups with no name, two or more side by side, are the items of a list. Their place among
|
|
91
|
+
// their twins is not who they are: a row that comes above them moves each one down, and the
|
|
92
|
+
// key of the second row was then the key of the row that took its place. A ref given for the
|
|
93
|
+
// Delete of "beta" pressed the Delete of "alpha". So each such item is known by its words.
|
|
94
|
+
// Only twins of the same shape: a group of keys beside a toolbar is no list, and the words of
|
|
95
|
+
// the display in it change with each key.
|
|
96
|
+
const shapes = new Map();
|
|
97
|
+
for (const child of node.children.filter(isListItem)) {
|
|
98
|
+
shapes.set(shapeOf(child), (shapes.get(shapeOf(child)) ?? 0) + 1);
|
|
99
|
+
}
|
|
100
|
+
node.children.forEach((child, order) => {
|
|
101
|
+
const item = isListItem(child) && (shapes.get(shapeOf(child)) ?? 0) > 1;
|
|
102
|
+
const words = item ? firstWords(child) : '';
|
|
103
|
+
const own = 0 === words.length ? label(child) : `${label(child)} ${quoted(words)}`;
|
|
104
|
+
const twin = seen.get(own) ?? 0;
|
|
105
|
+
seen.set(own, twin + 1);
|
|
106
|
+
// A row of a table keeps its place in the whole table. After a scroll the first row that
|
|
107
|
+
// shows is another row, and it must not get the key, and so the ref, of the row before it.
|
|
108
|
+
const nth = child.index === undefined ? String(twin) : `i${String(child.index)}`;
|
|
109
|
+
visit(child, [...path, child.index ?? order], `${key}/${own}#${nth}`, key);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
visit(root, [], label(root), undefined);
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The elements that have a place on the screen, and how many do not.
|
|
117
|
+
*
|
|
118
|
+
* An element with a frame of no size is not drawn: the items of a closed menu are the usual case,
|
|
119
|
+
* and they are most of an application's elements. A person cannot see or click them, so they are
|
|
120
|
+
* not shown and not offered as a target. When the menu is open its items have a size, and they
|
|
121
|
+
* are here. An element with no frame at all is kept: the reader did not say where it is.
|
|
122
|
+
*
|
|
123
|
+
* An element of a page that is wholly outside its window is scrolled out, and it is not shown.
|
|
124
|
+
* Safari gives the text below the window with its true place. The rule is for a page alone: a
|
|
125
|
+
* menu of the application can open past the edge of its window, and a person sees it there.
|
|
126
|
+
*
|
|
127
|
+
* One pixel counts as no size. A Chromium browser gives the text that is scrolled out of a page
|
|
128
|
+
* as a strip one pixel high at the edge of the window, and a person cannot see or click that.
|
|
129
|
+
*/
|
|
130
|
+
/** The most pixels, of a width or a height, that still count as no size. */
|
|
131
|
+
const THIN = 1;
|
|
132
|
+
export function placeShown(root) {
|
|
133
|
+
const outOfView = new Map();
|
|
134
|
+
const hidden = new Set();
|
|
135
|
+
// Hidden elements that give no place at all: they hide nothing that they hold.
|
|
136
|
+
const noPlace = new Set();
|
|
137
|
+
const shown = [];
|
|
138
|
+
// For each element: the frame of its window, and true when it is in a page.
|
|
139
|
+
const windows = new Map();
|
|
140
|
+
const inPage = new Set();
|
|
141
|
+
const clipOf = new Map();
|
|
142
|
+
for (const p of place(root)) {
|
|
143
|
+
const frame = p.node.frame;
|
|
144
|
+
const above = p.parentKey;
|
|
145
|
+
const fromAbove = above === undefined ? undefined : windows.get(above);
|
|
146
|
+
windows.set(p.key, p.node.role === UiRole.WINDOW ? frame : fromAbove);
|
|
147
|
+
// The frame that clips this element: of its nearest scroll area, or of its window.
|
|
148
|
+
const clipAbove = above === undefined ? undefined : clipOf.get(above);
|
|
149
|
+
clipOf.set(p.key, true === p.node.clips && frame !== undefined ? frame : clipAbove);
|
|
150
|
+
if (p.node.role === UiRole.DOCUMENT || (above !== undefined && inPage.has(above))) {
|
|
151
|
+
inPage.add(p.key);
|
|
152
|
+
}
|
|
153
|
+
// An application is not a thing on the screen: the Dock gives its own 0,0,0,0, and that hid
|
|
154
|
+
// every item of the Dock.
|
|
155
|
+
const noSize = p.node.role !== UiRole.APPLICATION &&
|
|
156
|
+
frame !== undefined &&
|
|
157
|
+
(frame[2] <= THIN || frame[3] <= THIN);
|
|
158
|
+
const scrolledOut = frame !== undefined &&
|
|
159
|
+
p.node.role !== UiRole.DOCUMENT &&
|
|
160
|
+
((inPage.has(p.key) && outside(frame, windows.get(p.key))) || outside(frame, clipAbove));
|
|
161
|
+
const parentHides = above !== undefined && hidden.has(above) && !noPlace.has(above);
|
|
162
|
+
if (noSize || scrolledOut || parentHides) {
|
|
163
|
+
hidden.add(p.key);
|
|
164
|
+
// In a page, no size is out of view too: Chrome gives an item scrolled out as a strip one
|
|
165
|
+
// pixel high at the edge. A closed menu is not in a page.
|
|
166
|
+
const outside = scrolledOut || (noSize && inPage.has(p.key));
|
|
167
|
+
if (outside && !parentHides && above !== undefined && !hidden.has(above)) {
|
|
168
|
+
outOfView.set(above, (outOfView.get(above) ?? 0) + 1);
|
|
169
|
+
}
|
|
170
|
+
// An element at 0,0,0,0 gives no place at all, not a closed one: the list of an open stack of
|
|
171
|
+
// the Dock does, and its files are on the screen above the Dock. What it holds is judged by
|
|
172
|
+
// its own place. A closed menu is at the place of its item, and its items have no size.
|
|
173
|
+
if (!parentHides && true === frame?.every((n) => 0 === n)) {
|
|
174
|
+
noPlace.add(p.key);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
shown.push(p);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return { shown, omitted: hidden.size, outOfView };
|
|
182
|
+
}
|
|
183
|
+
/** True when no part of the frame is in the window. A window with no frame hides nothing. */
|
|
184
|
+
function outside(frame, window) {
|
|
185
|
+
if (window === undefined) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return (frame[0] >= window[0] + window[2] ||
|
|
189
|
+
frame[0] + frame[2] <= window[0] ||
|
|
190
|
+
frame[1] >= window[1] + window[3] ||
|
|
191
|
+
frame[1] + frame[3] <= window[1]);
|
|
192
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface HelperLaunch {
|
|
2
|
+
/** The program to start. */
|
|
3
|
+
file: string;
|
|
4
|
+
/** The words before the command: the script, for PowerShell. */
|
|
5
|
+
prefix: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const WINDOWS_HELPER_SCRIPT = "reticle-uia.ps1";
|
|
8
|
+
export declare const LINUX_HELPER_SCRIPT = "reticle-atspi.py";
|
|
9
|
+
/** The helper for `platform` (a value of `process.platform`), or undefined when there is none. */
|
|
10
|
+
export declare function helperLaunch(platform: string, nativeDir: string): HelperLaunch | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How to start the helper on each operating system. macOS runs `reticle-ax`, built from Swift.
|
|
3
|
+
* Windows runs `reticle-uia.ps1` in PowerShell, which reads UI Automation and answers in the same
|
|
4
|
+
* shape, so the same driver (`MacDriver`) and the same reader work on both. Linux runs
|
|
5
|
+
* `reticle-atspi.py` in Python, which reads AT-SPI, the accessibility bus of the Linux desktop.
|
|
6
|
+
*/
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
export const WINDOWS_HELPER_SCRIPT = 'reticle-uia.ps1';
|
|
9
|
+
const POWERSHELL = 'powershell.exe';
|
|
10
|
+
export const LINUX_HELPER_SCRIPT = 'reticle-atspi.py';
|
|
11
|
+
const PYTHON = 'python3';
|
|
12
|
+
/** The helper for `platform` (a value of `process.platform`), or undefined when there is none. */
|
|
13
|
+
export function helperLaunch(platform, nativeDir) {
|
|
14
|
+
if ('darwin' === platform) {
|
|
15
|
+
return { file: join(nativeDir, 'mac', 'build', 'reticle-ax'), prefix: [] };
|
|
16
|
+
}
|
|
17
|
+
if ('win32' === platform) {
|
|
18
|
+
return {
|
|
19
|
+
file: POWERSHELL,
|
|
20
|
+
prefix: [
|
|
21
|
+
'-NoProfile',
|
|
22
|
+
'-NonInteractive',
|
|
23
|
+
'-ExecutionPolicy',
|
|
24
|
+
'Bypass',
|
|
25
|
+
'-File',
|
|
26
|
+
join(nativeDir, 'win', WINDOWS_HELPER_SCRIPT),
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if ('linux' === platform) {
|
|
31
|
+
return { file: PYTHON, prefix: [join(nativeDir, 'linux', LINUX_HELPER_SCRIPT)] };
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# A Linux desktop of its own for the agent: an X screen in memory, the accessibility bus, and the
|
|
2
|
+
# helper's needs. `reticle-computer --sandbox linux` builds it once and runs the application in
|
|
3
|
+
# it, so the agent works on its own screen and the person keeps theirs. Add your own applications
|
|
4
|
+
# with a Dockerfile that starts FROM this image.
|
|
5
|
+
FROM ubuntu:24.04
|
|
6
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
7
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
8
|
+
python3 python3-gi python3-gi-cairo gir1.2-atspi-2.0 gir1.2-gtk-3.0 at-spi2-core libatk-adaptor \
|
|
9
|
+
xvfb xauth xdotool xprintidle dbus dbus-x11 curl ca-certificates \
|
|
10
|
+
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
|
|
11
|
+
&& apt-get install -y --no-install-recommends nodejs \
|
|
12
|
+
&& rm -rf /var/lib/apt/lists/*
|