@reticlehq/computer 0.0.0-stage → 3.11.1
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 +237 -2
- package/bin/attach.mjs +333 -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 +16 -0
- package/dist/win/helper-launch.js +57 -0
- package/native/linux/Dockerfile +22 -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
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const OK = 'ok ';
|
|
2
|
+
const FIX = 'FIX ';
|
|
3
|
+
export function doctorReport(facts) {
|
|
4
|
+
const lines = [];
|
|
5
|
+
const stop = (line) => ({
|
|
6
|
+
ready: false,
|
|
7
|
+
lines: [...lines, `${FIX}${line}`],
|
|
8
|
+
});
|
|
9
|
+
if ('darwin' !== facts.platform) {
|
|
10
|
+
return stop(`reticle-computer runs on macOS only. This is ${facts.platform}.`);
|
|
11
|
+
}
|
|
12
|
+
lines.push(`${OK}macOS`);
|
|
13
|
+
if (!facts.compiler) {
|
|
14
|
+
return stop('The helper is built on this machine and needs the Swift compiler. Run: xcode-select --install');
|
|
15
|
+
}
|
|
16
|
+
lines.push(`${OK}the Swift compiler is here`);
|
|
17
|
+
if (false === facts.trusted) {
|
|
18
|
+
return stop('The terminal has no Accessibility permission. Open System Settings, Privacy & Security, Accessibility, and switch on the terminal you use. Then start the terminal again.');
|
|
19
|
+
}
|
|
20
|
+
lines.push(`${OK}Accessibility permission`);
|
|
21
|
+
if (true === facts.screenLocked) {
|
|
22
|
+
return stop('The screen is locked. macOS gives no window of an application while the screen is locked. Unlock the screen, and run this again.');
|
|
23
|
+
}
|
|
24
|
+
if (!facts.appOpen) {
|
|
25
|
+
return stop(facts.appHint ??
|
|
26
|
+
`No application named ${facts.app} is open. Open ${facts.app}, or give its exact name with --app.`);
|
|
27
|
+
}
|
|
28
|
+
if (0 === (facts.windows ?? 0)) {
|
|
29
|
+
const elsewhere = facts.windowsNotOnScreen ?? 0;
|
|
30
|
+
return stop(elsewhere > 0
|
|
31
|
+
? `${facts.app} has ${String(elsewhere)} window(s) on another Space, in another set of Stage Manager, or made small. Only the windows on the screen can be read. Bring ${facts.app} to the front.`
|
|
32
|
+
: `${facts.app} has no window. Open a window in it.`);
|
|
33
|
+
}
|
|
34
|
+
lines.push(`${OK}${facts.app} is open, with ${String(facts.windows)} window(s) on this screen`);
|
|
35
|
+
if (!facts.bridge) {
|
|
36
|
+
return stop(facts.token
|
|
37
|
+
? 'The Reticle daemon does not answer. Start it with: reticle serve'
|
|
38
|
+
: 'The Reticle daemon does not answer, and no pairing token was found. Start it with: reticle serve');
|
|
39
|
+
}
|
|
40
|
+
lines.push(`${OK}the Reticle daemon answers`);
|
|
41
|
+
return { ready: true, lines };
|
|
42
|
+
}
|
package/dist/driver.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the realm needs from an operating system: read an application, and act on one element.
|
|
3
|
+
* The realm knows the application only through this port, so a test gives it a driver that is
|
|
4
|
+
* not a real application.
|
|
5
|
+
*/
|
|
6
|
+
import type { Placed, UiNode } from './ui-node.js';
|
|
7
|
+
export declare const ActKind: {
|
|
8
|
+
readonly PRESS: "press";
|
|
9
|
+
/** Puts a value in the element. No key event is sent. */
|
|
10
|
+
readonly SET: "set";
|
|
11
|
+
/** Key events, one for each character of `value`. */
|
|
12
|
+
readonly TYPE: "type";
|
|
13
|
+
/** One key with its modifiers: `Return`, `Meta+s`. */
|
|
14
|
+
readonly KEY: "key";
|
|
15
|
+
/** The menu that a right-click gives, asked for by name. No pointer is used. */
|
|
16
|
+
readonly MENU: "menu";
|
|
17
|
+
/** Brings the application to the front and gives the element the keyboard. Foreground only. */
|
|
18
|
+
readonly RAISE: "raise";
|
|
19
|
+
/** The real pointer, at the middle of the element. Foreground only, each of these. */
|
|
20
|
+
readonly CLICK: "click";
|
|
21
|
+
readonly DBLCLICK: "dblclick";
|
|
22
|
+
readonly RIGHTCLICK: "rightclick";
|
|
23
|
+
/** Moves the pointer to the element and leaves it there. */
|
|
24
|
+
readonly HOVER: "hover";
|
|
25
|
+
/** From the element to the point in `value`, as "x,y" on the screen. */
|
|
26
|
+
readonly DRAG: "drag";
|
|
27
|
+
/** The real wheel over the element: `value` is lines, more than 0 down. */
|
|
28
|
+
readonly WHEEL: "wheel";
|
|
29
|
+
/** Arranges the window of the element: `value` is a `WindowArrangement`, or "frame:x,y,w,h". */
|
|
30
|
+
readonly WINDOW: "window";
|
|
31
|
+
};
|
|
32
|
+
export type ActKind = (typeof ActKind)[keyof typeof ActKind];
|
|
33
|
+
/** How an action reaches its element. */
|
|
34
|
+
export declare const Delivery: {
|
|
35
|
+
/** Only when a person could click the element. The default. */
|
|
36
|
+
readonly USER_PATH: "user-path";
|
|
37
|
+
/** Also when the element is under another view or window. It proves less. */
|
|
38
|
+
readonly DIRECT: "direct";
|
|
39
|
+
/**
|
|
40
|
+
* The application is brought to the front and the real pointer is used. It takes the pointer
|
|
41
|
+
* and the keyboard of the person at the machine for a moment, and puts them back.
|
|
42
|
+
*/
|
|
43
|
+
readonly FOREGROUND: "foreground";
|
|
44
|
+
};
|
|
45
|
+
export type Delivery = (typeof Delivery)[keyof typeof Delivery];
|
|
46
|
+
export declare const ActRefusal: {
|
|
47
|
+
/** A different element is where the chosen one was. */
|
|
48
|
+
readonly STALE: "stale";
|
|
49
|
+
readonly DISABLED: "disabled";
|
|
50
|
+
/** A person could not click it, and the caller did not ask for a direct action. */
|
|
51
|
+
readonly UNREACHABLE: "unreachable";
|
|
52
|
+
/** The operating system did not say whether a person could click it. Nothing is known. */
|
|
53
|
+
readonly REACH_UNKNOWN: "reach-unknown";
|
|
54
|
+
/** The action needs the real pointer, and the caller did not ask for the foreground. */
|
|
55
|
+
readonly NEEDS_FOREGROUND: "needs-foreground";
|
|
56
|
+
/**
|
|
57
|
+
* The foreground was asked for while the person at the machine was typing or moving the
|
|
58
|
+
* pointer. Their input would have gone to the application that is brought to the front.
|
|
59
|
+
*/
|
|
60
|
+
readonly PERSON_ACTIVE: "person-active";
|
|
61
|
+
/**
|
|
62
|
+
* Real keys were asked for, and the application did not take the keyboard. A real key goes to
|
|
63
|
+
* whatever application has it, so none was sent.
|
|
64
|
+
*/
|
|
65
|
+
readonly NO_KEYBOARD: "no-keyboard";
|
|
66
|
+
/**
|
|
67
|
+
* The desktop takes no pointer and no keys from a program: a Wayland session of Linux. The
|
|
68
|
+
* detail says why. The step can still be done through the accessibility interface.
|
|
69
|
+
*/
|
|
70
|
+
readonly NO_REAL_INPUT: "no-real-input";
|
|
71
|
+
};
|
|
72
|
+
export type ActRefusal = (typeof ActRefusal)[keyof typeof ActRefusal];
|
|
73
|
+
export interface UiRead {
|
|
74
|
+
root: UiNode;
|
|
75
|
+
/** Elements the operating system refused to describe. More than zero means holes in the tree. */
|
|
76
|
+
unread: number;
|
|
77
|
+
/** Roles the reader does not know. Each such element is kept, as a `group`. */
|
|
78
|
+
unmapped: readonly string[];
|
|
79
|
+
/**
|
|
80
|
+
* Windows of the application that are not on the screen now: on another Space, or made small.
|
|
81
|
+
* The reader cannot read them. Absent when the reader does not know.
|
|
82
|
+
*/
|
|
83
|
+
windowsNotOnScreen?: number;
|
|
84
|
+
}
|
|
85
|
+
export interface ActRequest {
|
|
86
|
+
target: Placed;
|
|
87
|
+
kind: ActKind;
|
|
88
|
+
value?: string;
|
|
89
|
+
delivery: Delivery;
|
|
90
|
+
budgetMs: number;
|
|
91
|
+
/**
|
|
92
|
+
* How long the application must show no change before the action is called finished. Absent:
|
|
93
|
+
* the driver's own time. A caller gives a shorter time only when it goes on looking after the
|
|
94
|
+
* action, so that a later change is still seen.
|
|
95
|
+
*/
|
|
96
|
+
quietMs?: number;
|
|
97
|
+
/** Folders where a written file is an effect too. The wait ends when they and the tree are quiet. */
|
|
98
|
+
watch: readonly string[];
|
|
99
|
+
}
|
|
100
|
+
export interface SettingChange {
|
|
101
|
+
key: string;
|
|
102
|
+
old: string;
|
|
103
|
+
new: string;
|
|
104
|
+
/** The values are longer than what is given here. They were compared whole. */
|
|
105
|
+
cut?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** A window after `window`: what a person sees of it. */
|
|
108
|
+
export interface WindowState {
|
|
109
|
+
minimized: boolean;
|
|
110
|
+
fullscreen: boolean;
|
|
111
|
+
/** Absent: the window gave no frame. */
|
|
112
|
+
frame?: readonly [number, number, number, number];
|
|
113
|
+
/** The frame the window was given (a half, a zoom, an exact frame). Absent for the others. */
|
|
114
|
+
wanted?: readonly [number, number, number, number];
|
|
115
|
+
}
|
|
116
|
+
export interface ActOutcome {
|
|
117
|
+
/** For `window`: the window after the change. Absent for every other action. */
|
|
118
|
+
windowState?: WindowState;
|
|
119
|
+
refused?: ActRefusal;
|
|
120
|
+
/** More about a refusal: for `unreachable`, the element that is on top. */
|
|
121
|
+
detail?: string;
|
|
122
|
+
/** The operating system accepted the action. It says nothing about an effect. */
|
|
123
|
+
delivered: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* The application ended while the action ran: it quit, or it crashed. `delivered` is then not
|
|
126
|
+
* to be believed: the application can end before it answers a press that it took.
|
|
127
|
+
*/
|
|
128
|
+
appGone?: true;
|
|
129
|
+
/** A person who clicks the middle of the element reaches it. */
|
|
130
|
+
reachable: boolean;
|
|
131
|
+
/** Two reads in a row agreed before the budget ran out. */
|
|
132
|
+
settled: boolean;
|
|
133
|
+
before: UiRead;
|
|
134
|
+
after: UiRead;
|
|
135
|
+
/**
|
|
136
|
+
* The bytes that the application's process, and the processes it started, wrote to disk in the
|
|
137
|
+
* action, as the operating system counts them. Zero says that they wrote nothing. It does not
|
|
138
|
+
* say that no file was written: a helper that the system runs for the application is not
|
|
139
|
+
* counted. Absent: the driver cannot count.
|
|
140
|
+
*/
|
|
141
|
+
bytesWritten?: number;
|
|
142
|
+
/**
|
|
143
|
+
* The settings of the application that are different after the action. An empty list says that
|
|
144
|
+
* the settings were read and none changed. Absent: the settings cannot be read from outside the
|
|
145
|
+
* application (an application in a sandbox), and nothing is known about them.
|
|
146
|
+
*/
|
|
147
|
+
settingsChanged?: readonly SettingChange[];
|
|
148
|
+
/**
|
|
149
|
+
* Something was put on the clipboard in the action. The driver reads only that it changed, never
|
|
150
|
+
* what is on it. Absent: the driver cannot tell.
|
|
151
|
+
*/
|
|
152
|
+
clipboardChanged?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* The part of the window whose pixels changed (0 to 1), and the box around the change in screen
|
|
155
|
+
* points. Read only when no element changed: a canvas shows its effect only in pixels. Absent:
|
|
156
|
+
* the pixels were not compared (not a pointer in the foreground, no picture, or elements changed).
|
|
157
|
+
* `moving`: the part of the window that changed with no action (a video, a spinner). It is left
|
|
158
|
+
* out of `changed`, because a change there cannot be told from an effect.
|
|
159
|
+
*/
|
|
160
|
+
pixels?: {
|
|
161
|
+
changed: number;
|
|
162
|
+
box?: readonly number[];
|
|
163
|
+
moving?: number;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** The signal for an action whose effect is only in the pixels: the part changed, and its box. */
|
|
167
|
+
export declare const PIXELS_CHANGED_SIGNAL = "pixels.changed";
|
|
168
|
+
/** Whether a person can see and click an element now. */
|
|
169
|
+
export declare const Reach: {
|
|
170
|
+
readonly YES: "yes";
|
|
171
|
+
/** Another element is on top of it: a view in the same window, or another window. */
|
|
172
|
+
readonly NO: "no";
|
|
173
|
+
/** The operating system did not answer. Nothing is known. */
|
|
174
|
+
readonly UNKNOWN: "unknown";
|
|
175
|
+
};
|
|
176
|
+
export type Reach = (typeof Reach)[keyof typeof Reach];
|
|
177
|
+
export interface ReachAnswer {
|
|
178
|
+
reach: Reach;
|
|
179
|
+
/** For `no`: what is on top. For `unknown`: why. */
|
|
180
|
+
detail?: string;
|
|
181
|
+
}
|
|
182
|
+
export interface UiDriver {
|
|
183
|
+
/** The application and the process: `Notes` and `4312`. */
|
|
184
|
+
subject(): {
|
|
185
|
+
app: string;
|
|
186
|
+
pid: number;
|
|
187
|
+
};
|
|
188
|
+
read(): Promise<UiRead>;
|
|
189
|
+
/** Asks about one element of the last read, and acts on nothing. */
|
|
190
|
+
reach(target: Placed): Promise<ReachAnswer>;
|
|
191
|
+
act(request: ActRequest): Promise<ActOutcome>;
|
|
192
|
+
/**
|
|
193
|
+
* A picture of the application's own window, as a PNG file. Absent: this driver takes none.
|
|
194
|
+
* For an application that gives no elements, the picture is what a caller reads.
|
|
195
|
+
*/
|
|
196
|
+
capture?(how?: CaptureHow): Promise<Captured>;
|
|
197
|
+
/**
|
|
198
|
+
* The words of a picture file, read on this machine, each with its box in the pixels of the
|
|
199
|
+
* picture. Undefined: this system has no reader.
|
|
200
|
+
*/
|
|
201
|
+
texts?(path: string): Promise<readonly PictureText[] | undefined>;
|
|
202
|
+
}
|
|
203
|
+
/** A word in a picture, its box in the pixels of the picture, and how sure the reader is. */
|
|
204
|
+
export interface PictureText {
|
|
205
|
+
text: string;
|
|
206
|
+
box: readonly number[];
|
|
207
|
+
confidence: number;
|
|
208
|
+
}
|
|
209
|
+
/** What a picture shows. Absent `screen`: the window of the application only. */
|
|
210
|
+
export interface CaptureHow {
|
|
211
|
+
/** The whole display that holds the application, with every application on it. */
|
|
212
|
+
screen?: boolean;
|
|
213
|
+
}
|
|
214
|
+
/** A picture that was taken, or the reason there is none. */
|
|
215
|
+
export type Captured = {
|
|
216
|
+
ok: true;
|
|
217
|
+
path: string;
|
|
218
|
+
/** What the picture shows on the screen, in points: x, y, width, height. */
|
|
219
|
+
window: readonly [number, number, number, number];
|
|
220
|
+
/** The pixels of the picture for each point of the screen. */
|
|
221
|
+
scale: number;
|
|
222
|
+
/** The application's window when the picture was taken. Absent: the picture is that window. */
|
|
223
|
+
appWindow?: readonly [number, number, number, number];
|
|
224
|
+
} | {
|
|
225
|
+
ok: false;
|
|
226
|
+
reason: string;
|
|
227
|
+
};
|
package/dist/driver.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const ActKind = {
|
|
2
|
+
PRESS: 'press',
|
|
3
|
+
/** Puts a value in the element. No key event is sent. */
|
|
4
|
+
SET: 'set',
|
|
5
|
+
/** Key events, one for each character of `value`. */
|
|
6
|
+
TYPE: 'type',
|
|
7
|
+
/** One key with its modifiers: `Return`, `Meta+s`. */
|
|
8
|
+
KEY: 'key',
|
|
9
|
+
/** The menu that a right-click gives, asked for by name. No pointer is used. */
|
|
10
|
+
MENU: 'menu',
|
|
11
|
+
/** Brings the application to the front and gives the element the keyboard. Foreground only. */
|
|
12
|
+
RAISE: 'raise',
|
|
13
|
+
/** The real pointer, at the middle of the element. Foreground only, each of these. */
|
|
14
|
+
CLICK: 'click',
|
|
15
|
+
DBLCLICK: 'dblclick',
|
|
16
|
+
RIGHTCLICK: 'rightclick',
|
|
17
|
+
/** Moves the pointer to the element and leaves it there. */
|
|
18
|
+
HOVER: 'hover',
|
|
19
|
+
/** From the element to the point in `value`, as "x,y" on the screen. */
|
|
20
|
+
DRAG: 'drag',
|
|
21
|
+
/** The real wheel over the element: `value` is lines, more than 0 down. */
|
|
22
|
+
WHEEL: 'wheel',
|
|
23
|
+
/** Arranges the window of the element: `value` is a `WindowArrangement`, or "frame:x,y,w,h". */
|
|
24
|
+
WINDOW: 'window',
|
|
25
|
+
};
|
|
26
|
+
/** How an action reaches its element. */
|
|
27
|
+
export const Delivery = {
|
|
28
|
+
/** Only when a person could click the element. The default. */
|
|
29
|
+
USER_PATH: 'user-path',
|
|
30
|
+
/** Also when the element is under another view or window. It proves less. */
|
|
31
|
+
DIRECT: 'direct',
|
|
32
|
+
/**
|
|
33
|
+
* The application is brought to the front and the real pointer is used. It takes the pointer
|
|
34
|
+
* and the keyboard of the person at the machine for a moment, and puts them back.
|
|
35
|
+
*/
|
|
36
|
+
FOREGROUND: 'foreground',
|
|
37
|
+
};
|
|
38
|
+
export const ActRefusal = {
|
|
39
|
+
/** A different element is where the chosen one was. */
|
|
40
|
+
STALE: 'stale',
|
|
41
|
+
DISABLED: 'disabled',
|
|
42
|
+
/** A person could not click it, and the caller did not ask for a direct action. */
|
|
43
|
+
UNREACHABLE: 'unreachable',
|
|
44
|
+
/** The operating system did not say whether a person could click it. Nothing is known. */
|
|
45
|
+
REACH_UNKNOWN: 'reach-unknown',
|
|
46
|
+
/** The action needs the real pointer, and the caller did not ask for the foreground. */
|
|
47
|
+
NEEDS_FOREGROUND: 'needs-foreground',
|
|
48
|
+
/**
|
|
49
|
+
* The foreground was asked for while the person at the machine was typing or moving the
|
|
50
|
+
* pointer. Their input would have gone to the application that is brought to the front.
|
|
51
|
+
*/
|
|
52
|
+
PERSON_ACTIVE: 'person-active',
|
|
53
|
+
/**
|
|
54
|
+
* Real keys were asked for, and the application did not take the keyboard. A real key goes to
|
|
55
|
+
* whatever application has it, so none was sent.
|
|
56
|
+
*/
|
|
57
|
+
NO_KEYBOARD: 'no-keyboard',
|
|
58
|
+
/**
|
|
59
|
+
* The desktop takes no pointer and no keys from a program: a Wayland session of Linux. The
|
|
60
|
+
* detail says why. The step can still be done through the accessibility interface.
|
|
61
|
+
*/
|
|
62
|
+
NO_REAL_INPUT: 'no-real-input',
|
|
63
|
+
};
|
|
64
|
+
/** The signal for an action whose effect is only in the pixels: the part changed, and its box. */
|
|
65
|
+
export const PIXELS_CHANGED_SIGNAL = 'pixels.changed';
|
|
66
|
+
/** Whether a person can see and click an element now. */
|
|
67
|
+
export const Reach = {
|
|
68
|
+
YES: 'yes',
|
|
69
|
+
/** Another element is on top of it: a view in the same window, or another window. */
|
|
70
|
+
NO: 'no',
|
|
71
|
+
/** The operating system did not answer. Nothing is known. */
|
|
72
|
+
UNKNOWN: 'unknown',
|
|
73
|
+
};
|
package/dist/effect.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { UiNode } from './ui-node.js';
|
|
2
|
+
export declare const EffectKind: {
|
|
3
|
+
/** No element appeared, went away or changed. */
|
|
4
|
+
readonly NONE: "none";
|
|
5
|
+
readonly CHANGED: "changed";
|
|
6
|
+
/**
|
|
7
|
+
* Something changed, and only in places that change with no action. The realm cannot say that
|
|
8
|
+
* the action did it, and cannot say that it did not.
|
|
9
|
+
*/
|
|
10
|
+
readonly AMBIENT_ONLY: "ambient-only";
|
|
11
|
+
};
|
|
12
|
+
export type EffectKind = (typeof EffectKind)[keyof typeof EffectKind];
|
|
13
|
+
export declare const ChangeKind: {
|
|
14
|
+
readonly GONE: "gone";
|
|
15
|
+
readonly DIFFERENT: "changed";
|
|
16
|
+
readonly NEW: "appeared";
|
|
17
|
+
};
|
|
18
|
+
export type ChangeKind = (typeof ChangeKind)[keyof typeof ChangeKind];
|
|
19
|
+
export interface Change {
|
|
20
|
+
kind: ChangeKind;
|
|
21
|
+
/** `button "Save"`: the role and the name of the element. */
|
|
22
|
+
element: string;
|
|
23
|
+
/** For a changed element: what was different. */
|
|
24
|
+
detail?: string;
|
|
25
|
+
role: string;
|
|
26
|
+
name: string;
|
|
27
|
+
/** For a changed element: the value before and after, when it changed. */
|
|
28
|
+
value?: readonly [string, string];
|
|
29
|
+
/** For a changed element: the states before and after, when they changed. */
|
|
30
|
+
states?: readonly [string, string];
|
|
31
|
+
/** The key of the element that holds this one. */
|
|
32
|
+
within: string;
|
|
33
|
+
/**
|
|
34
|
+
* Where the change is: the parent, the role and the corner of the element. An element that is
|
|
35
|
+
* given new words (a clock, a count) has a new name and so a new key, and keeps this.
|
|
36
|
+
*/
|
|
37
|
+
at: string;
|
|
38
|
+
/** The change is in a place that changes with no action. The action may not be its cause. */
|
|
39
|
+
ambient?: true;
|
|
40
|
+
}
|
|
41
|
+
export interface Effect {
|
|
42
|
+
kind: EffectKind;
|
|
43
|
+
/** What appeared, went away or changed. A move of the keyboard alone is not here. */
|
|
44
|
+
changes: Change[];
|
|
45
|
+
/**
|
|
46
|
+
* The element that has the keyboard after the action, when the keyboard moved. A press on a
|
|
47
|
+
* control in a web view moves the keyboard to it and can do nothing more. That is not an effect
|
|
48
|
+
* of the action, or every press in a web view has one, and an action that does nothing is never
|
|
49
|
+
* reported.
|
|
50
|
+
*/
|
|
51
|
+
focusMovedTo?: string;
|
|
52
|
+
/**
|
|
53
|
+
* How many elements changed, came or went with no place on the screen in both reads: an item
|
|
54
|
+
* of a closed menu. They are not in `changes`. This is the count of what was left out.
|
|
55
|
+
*/
|
|
56
|
+
offScreen: number;
|
|
57
|
+
}
|
|
58
|
+
/** One line for a change: `-` went away, `~` changed, `+` appeared. */
|
|
59
|
+
export declare function changeLine(change: Change): string;
|
|
60
|
+
export declare function effectOf(before: UiNode, after: UiNode, restless?: ReadonlySet<string>): Effect;
|
package/dist/effect.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an action changed: the difference between the tree before it and the tree after it.
|
|
3
|
+
*
|
|
4
|
+
* "Nothing changed" is a result here, not an absence of one. An agent that acts and gets no word
|
|
5
|
+
* back cannot tell a click that did nothing from a click that worked.
|
|
6
|
+
*/
|
|
7
|
+
import { label, place, placeShown, quoted } from './ui-node.js';
|
|
8
|
+
export const EffectKind = {
|
|
9
|
+
/** No element appeared, went away or changed. */
|
|
10
|
+
NONE: 'none',
|
|
11
|
+
CHANGED: 'changed',
|
|
12
|
+
/**
|
|
13
|
+
* Something changed, and only in places that change with no action. The realm cannot say that
|
|
14
|
+
* the action did it, and cannot say that it did not.
|
|
15
|
+
*/
|
|
16
|
+
AMBIENT_ONLY: 'ambient-only',
|
|
17
|
+
};
|
|
18
|
+
export const ChangeKind = { GONE: 'gone', DIFFERENT: 'changed', NEW: 'appeared' };
|
|
19
|
+
const MARK = {
|
|
20
|
+
[ChangeKind.GONE]: '-',
|
|
21
|
+
[ChangeKind.DIFFERENT]: '~',
|
|
22
|
+
[ChangeKind.NEW]: '+',
|
|
23
|
+
};
|
|
24
|
+
/** One line for a change: `-` went away, `~` changed, `+` appeared. */
|
|
25
|
+
export function changeLine(change) {
|
|
26
|
+
const detail = change.detail === undefined ? '' : `: ${change.detail}`;
|
|
27
|
+
return `${MARK[change.kind]} ${change.element}${detail}`;
|
|
28
|
+
}
|
|
29
|
+
function difference(before, after) {
|
|
30
|
+
const parts = [];
|
|
31
|
+
const out = {};
|
|
32
|
+
if ((before.value ?? '') !== (after.value ?? '')) {
|
|
33
|
+
out.value = [before.value ?? '', after.value ?? ''];
|
|
34
|
+
parts.push(`value ${quoted(out.value[0])} -> ${quoted(out.value[1])}`);
|
|
35
|
+
}
|
|
36
|
+
const was = before.states.join(',');
|
|
37
|
+
const is = after.states.join(',');
|
|
38
|
+
if (was !== is) {
|
|
39
|
+
out.states = [was, is];
|
|
40
|
+
parts.push(`states [${was}] -> [${is}]`);
|
|
41
|
+
}
|
|
42
|
+
return parts.length > 0 ? { ...out, detail: parts.join('; ') } : {};
|
|
43
|
+
}
|
|
44
|
+
/** A separator that is in no key: a key is made of roles and names. */
|
|
45
|
+
const AT = '\u0000';
|
|
46
|
+
/**
|
|
47
|
+
* Where an element is: its parent, its role, and its corner as seen from the corner of its
|
|
48
|
+
* parent. Not its corner on the screen: that is another one each time a person moves the window.
|
|
49
|
+
*/
|
|
50
|
+
function placeOf(p, side) {
|
|
51
|
+
const [x, y] = p.node.frame ?? [];
|
|
52
|
+
const [px, py] = (p.parentKey === undefined ? undefined : side.get(p.parentKey)?.node.frame) ?? [
|
|
53
|
+
0, 0,
|
|
54
|
+
];
|
|
55
|
+
const corner = x === undefined || y === undefined ? '' : `${String(x - (px ?? 0))},${String(y - (py ?? 0))}`;
|
|
56
|
+
return [p.parentKey ?? '', p.node.role, corner].join(AT);
|
|
57
|
+
}
|
|
58
|
+
function who(p, side) {
|
|
59
|
+
return {
|
|
60
|
+
element: label(p.node),
|
|
61
|
+
role: p.node.role,
|
|
62
|
+
name: p.node.name,
|
|
63
|
+
within: p.parentKey ?? '',
|
|
64
|
+
at: placeOf(p, side),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function byKey(placed) {
|
|
68
|
+
return new Map(placed.map((p) => [p.key, p]));
|
|
69
|
+
}
|
|
70
|
+
/** True when the element's parent is on the other side, so the element is the top of what moved. */
|
|
71
|
+
function isTopOf(p, other) {
|
|
72
|
+
return p.parentKey === undefined || other.has(p.parentKey);
|
|
73
|
+
}
|
|
74
|
+
export function effectOf(before, after, restless = new Set()) {
|
|
75
|
+
// Only what is on the screen. An element with no size was there in both reads, so a menu that
|
|
76
|
+
// opened was "no change", and an item put in a closed menu was an effect nobody saw.
|
|
77
|
+
const was = placeShown(before).shown;
|
|
78
|
+
const is = placeShown(after).shown;
|
|
79
|
+
const offScreen = offScreenChanges(before, was, after, is);
|
|
80
|
+
const wasByKey = byKey(was);
|
|
81
|
+
const isByKey = byKey(is);
|
|
82
|
+
const changes = [];
|
|
83
|
+
for (const p of was) {
|
|
84
|
+
const now = isByKey.get(p.key);
|
|
85
|
+
if (now === undefined) {
|
|
86
|
+
if (isTopOf(p, isByKey)) {
|
|
87
|
+
changes.push({ kind: ChangeKind.GONE, ...who(p, wasByKey) });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const diff = difference(p.node, now.node);
|
|
92
|
+
if (diff.detail !== undefined) {
|
|
93
|
+
changes.push({ kind: ChangeKind.DIFFERENT, ...who(p, wasByKey), ...diff });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const p of is) {
|
|
98
|
+
if (!wasByKey.has(p.key) && isTopOf(p, wasByKey)) {
|
|
99
|
+
changes.push({ kind: ChangeKind.NEW, ...who(p, isByKey) });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const real = changes
|
|
103
|
+
.filter((change) => !isFocusOnly(change))
|
|
104
|
+
.map((change) => restless.has(change.at) || restless.has(change.within)
|
|
105
|
+
? { ...change, ambient: true }
|
|
106
|
+
: change);
|
|
107
|
+
const caused = real.filter((change) => change.ambient === undefined);
|
|
108
|
+
const taker = changes.find((change) => isFocusOnly(change) && tookFocus(change));
|
|
109
|
+
return {
|
|
110
|
+
kind: kindOf(real.length, caused.length),
|
|
111
|
+
changes: real,
|
|
112
|
+
offScreen,
|
|
113
|
+
...(taker === undefined ? {} : { focusMovedTo: taker.element }),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* How many elements changed, came or went with no place on the screen in both reads.
|
|
118
|
+
* An element that is on the screen in one of the reads is not counted: it is in `changes`.
|
|
119
|
+
*/
|
|
120
|
+
function offScreenChanges(before, wasShown, after, isShown) {
|
|
121
|
+
const seen = new Set([...wasShown, ...isShown].map((p) => p.key));
|
|
122
|
+
const was = byKey(place(before).filter((p) => !seen.has(p.key)));
|
|
123
|
+
const is = byKey(place(after).filter((p) => !seen.has(p.key)));
|
|
124
|
+
let count = 0;
|
|
125
|
+
for (const [key, p] of was) {
|
|
126
|
+
const now = is.get(key);
|
|
127
|
+
if (now === undefined || difference(p.node, now.node).detail !== undefined) {
|
|
128
|
+
count += 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const key of is.keys()) {
|
|
132
|
+
if (!was.has(key)) {
|
|
133
|
+
count += 1;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return count;
|
|
137
|
+
}
|
|
138
|
+
function kindOf(all, caused) {
|
|
139
|
+
if (caused > 0) {
|
|
140
|
+
return EffectKind.CHANGED;
|
|
141
|
+
}
|
|
142
|
+
return all > 0 ? EffectKind.AMBIENT_ONLY : EffectKind.NONE;
|
|
143
|
+
}
|
|
144
|
+
const FOCUSED = 'focused';
|
|
145
|
+
const without = (states) => states
|
|
146
|
+
.split(',')
|
|
147
|
+
.filter((state) => state !== FOCUSED && state.length > 0)
|
|
148
|
+
.join(',');
|
|
149
|
+
/** A change that is the keyboard coming or going, and nothing else. */
|
|
150
|
+
function isFocusOnly(change) {
|
|
151
|
+
return (change.kind === ChangeKind.DIFFERENT &&
|
|
152
|
+
change.value === undefined &&
|
|
153
|
+
change.states !== undefined &&
|
|
154
|
+
without(change.states[0]) === without(change.states[1]));
|
|
155
|
+
}
|
|
156
|
+
function tookFocus(change) {
|
|
157
|
+
return change.states?.[1].split(',').includes(FOCUSED) ?? false;
|
|
158
|
+
}
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Snapshot } from '@reticlehq/terminal';
|
|
2
|
+
/** The kind of a write that left the same bytes. The snapshot has no word for it. */
|
|
3
|
+
export declare const REWRITTEN = "rewritten";
|
|
4
|
+
export type WriteTimeOf = (path: string) => number | undefined;
|
|
5
|
+
export type WriteTimes = ReadonlyMap<string, number | undefined>;
|
|
6
|
+
export declare const writeTimeOnDisk: WriteTimeOf;
|
|
7
|
+
/** When each file of a snapshot was last written. */
|
|
8
|
+
export declare function writeTimesOf(snapshot: Snapshot, timeOf: WriteTimeOf): WriteTimes;
|
|
9
|
+
/**
|
|
10
|
+
* The files that are in both looks with no change that the snapshot shows, and a new write time.
|
|
11
|
+
* `changed` holds the paths that the snapshot already reports, so that no file is said twice.
|
|
12
|
+
*/
|
|
13
|
+
export declare function rewrittenSince(times: WriteTimes, after: Snapshot, changed: ReadonlySet<string>, timeOf: WriteTimeOf): {
|
|
14
|
+
path: string;
|
|
15
|
+
size: number;
|
|
16
|
+
}[];
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file that was written again with the same bytes.
|
|
3
|
+
*
|
|
4
|
+
* The snapshot of a watched folder compares what each file holds. An application that writes the
|
|
5
|
+
* same bytes again did write, and the snapshot shows no change. The time of the write shows it.
|
|
6
|
+
* The realm and the peer both need this, so it is here once.
|
|
7
|
+
*/
|
|
8
|
+
import { statSync } from 'node:fs';
|
|
9
|
+
/** The kind of a write that left the same bytes. The snapshot has no word for it. */
|
|
10
|
+
export const REWRITTEN = 'rewritten';
|
|
11
|
+
export const writeTimeOnDisk = (path) => {
|
|
12
|
+
try {
|
|
13
|
+
return statSync(path).mtimeMs;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/** When each file of a snapshot was last written. */
|
|
20
|
+
export function writeTimesOf(snapshot, timeOf) {
|
|
21
|
+
return new Map([...snapshot.files.keys()].map((path) => [path, timeOf(path)]));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The files that are in both looks with no change that the snapshot shows, and a new write time.
|
|
25
|
+
* `changed` holds the paths that the snapshot already reports, so that no file is said twice.
|
|
26
|
+
*/
|
|
27
|
+
export function rewrittenSince(times, after, changed, timeOf) {
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const [path, was] of times) {
|
|
30
|
+
const fact = after.files.get(path);
|
|
31
|
+
if (fact === undefined || changed.has(path)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const now = timeOf(path);
|
|
35
|
+
if (now !== undefined && now !== was) {
|
|
36
|
+
out.push({ path, size: fact.size });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the person at the machine sees of the realm: a pointer of the realm's own, and a small
|
|
3
|
+
* window that says what the realm does and what that did. The port has no window in it: the
|
|
4
|
+
* macOS one starts a program that draws, and a test gives a list.
|
|
5
|
+
*/
|
|
6
|
+
export declare const HudEffect: {
|
|
7
|
+
readonly OK: "ok";
|
|
8
|
+
readonly NONE: "none";
|
|
9
|
+
readonly REFUSED: "refused";
|
|
10
|
+
};
|
|
11
|
+
export type HudEffect = (typeof HudEffect)[keyof typeof HudEffect];
|
|
12
|
+
export interface HudPort {
|
|
13
|
+
/** The application that is joined. */
|
|
14
|
+
app(name: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* The pointer goes to this point of the screen: the middle of the element to act on. A promise
|
|
17
|
+
* ends when the pointer is there, and the realm acts then, as a hand clicks when it arrives.
|
|
18
|
+
*/
|
|
19
|
+
move(x: number, y: number): void | Promise<void>;
|
|
20
|
+
/** A glow round the window the realm works in: x, y, width, height on the screen. */
|
|
21
|
+
glow(frame: readonly [number, number, number, number]): void;
|
|
22
|
+
/** What the realm does now, in a few words. */
|
|
23
|
+
act(text: string): void;
|
|
24
|
+
/** What that did. */
|
|
25
|
+
effect(text: string, kind: HudEffect): void;
|
|
26
|
+
/** The person pressed "Pause" in the window. The realm then does no action. */
|
|
27
|
+
paused(): boolean;
|
|
28
|
+
/** The person pressed "Stop" in the window. The realm does no action after it, and leaves. */
|
|
29
|
+
stopped(): boolean;
|
|
30
|
+
close(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Whose turn it is, from the agent's `yield`: tone "ask" is the person's turn, with the question
|
|
33
|
+
* in `text`. Absent: this HUD shows no turn.
|
|
34
|
+
*/
|
|
35
|
+
turn?(turn: HudTurn): void;
|
|
36
|
+
/** Calls `listener` when the person presses "Done" at the end of their turn. */
|
|
37
|
+
onDone?(listener: () => void): void;
|
|
38
|
+
}
|
|
39
|
+
/** The state of the session, as the agent's `yield` set it. */
|
|
40
|
+
export interface HudTurn {
|
|
41
|
+
state: string;
|
|
42
|
+
tone?: string;
|
|
43
|
+
text?: string;
|
|
44
|
+
}
|
package/dist/hud/port.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the person at the machine sees of the realm: a pointer of the realm's own, and a small
|
|
3
|
+
* window that says what the realm does and what that did. The port has no window in it: the
|
|
4
|
+
* macOS one starts a program that draws, and a test gives a list.
|
|
5
|
+
*/
|
|
6
|
+
export const HudEffect = { OK: 'ok', NONE: 'none', REFUSED: 'refused' };
|