@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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const CuChannel: {
|
|
2
|
+
readonly UI: "ui";
|
|
3
|
+
/** That a path exists and its size: the file system decided it. */
|
|
4
|
+
readonly FILES: "x-files";
|
|
5
|
+
/** The bytes in a path: the application wrote them. */
|
|
6
|
+
readonly FILES_CONTENT: "x-files-content";
|
|
7
|
+
/** How many bytes the application's process wrote to disk: the operating system counted them. */
|
|
8
|
+
readonly DISK: "x-disk";
|
|
9
|
+
/** The settings of the application, as the system's settings store holds them. */
|
|
10
|
+
readonly SETTINGS: "x-settings";
|
|
11
|
+
/** That something was put on the clipboard. Never what. */
|
|
12
|
+
readonly CLIPBOARD: "x-clipboard";
|
|
13
|
+
/** The pixels of the window: the window server drew them. */
|
|
14
|
+
readonly PIXELS: "x-pixels";
|
|
15
|
+
};
|
|
16
|
+
/** Stable labels. A claim matches on them exactly. */
|
|
17
|
+
export declare const CuSummary: {
|
|
18
|
+
readonly UI_APPEARED: "cu.ui.appeared";
|
|
19
|
+
readonly UI_GONE: "cu.ui.gone";
|
|
20
|
+
readonly UI_CHANGED: "cu.ui.changed";
|
|
21
|
+
/** The action was delivered and no element appeared, went away or changed. */
|
|
22
|
+
readonly UI_NO_EFFECT: "cu.ui.no-effect";
|
|
23
|
+
/** The keyboard moved to another element. It is not an effect by itself. */
|
|
24
|
+
readonly UI_FOCUS_MOVED: "cu.ui.focus-moved";
|
|
25
|
+
/** The action reached an element a person could not click. */
|
|
26
|
+
readonly ACT_NOT_REACHABLE: "cu.act.not-reachable";
|
|
27
|
+
readonly FS_WRITTEN: "cu.fs.written";
|
|
28
|
+
readonly FS_WRITTEN_EMPTY: "cu.fs.written-empty";
|
|
29
|
+
readonly FS_DELETED: "cu.fs.deleted";
|
|
30
|
+
readonly FS_CONTENT: "cu.fs.content";
|
|
31
|
+
/** The process wrote bytes to disk in the action. It does not say where. */
|
|
32
|
+
readonly DISK_WROTE: "cu.disk.wrote";
|
|
33
|
+
/** The application and the processes it started wrote nothing to disk in the action. */
|
|
34
|
+
readonly DISK_WROTE_NOTHING: "cu.disk.wrote-nothing";
|
|
35
|
+
/** One setting of the application has a new value, or is new, or is gone. */
|
|
36
|
+
readonly SETTINGS_CHANGED: "cu.settings.changed";
|
|
37
|
+
/** Something was put on the clipboard in the action. */
|
|
38
|
+
readonly CLIPBOARD_CHANGED: "cu.clipboard.changed";
|
|
39
|
+
/** No element changed, and the pixels of the window did: a canvas, a photo, a video frame. */
|
|
40
|
+
readonly PIXELS_CHANGED: "cu.pixels.changed";
|
|
41
|
+
};
|
|
42
|
+
export declare const CU_SURFACE = "computer";
|
package/dist/channels.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The channels this realm reports on, and the label of each kind of observation.
|
|
3
|
+
*/
|
|
4
|
+
import { ChannelId } from 'open-verification';
|
|
5
|
+
export const CuChannel = {
|
|
6
|
+
UI: ChannelId.UI,
|
|
7
|
+
/** That a path exists and its size: the file system decided it. */
|
|
8
|
+
FILES: 'x-files',
|
|
9
|
+
/** The bytes in a path: the application wrote them. */
|
|
10
|
+
FILES_CONTENT: 'x-files-content',
|
|
11
|
+
/** How many bytes the application's process wrote to disk: the operating system counted them. */
|
|
12
|
+
DISK: 'x-disk',
|
|
13
|
+
/** The settings of the application, as the system's settings store holds them. */
|
|
14
|
+
SETTINGS: 'x-settings',
|
|
15
|
+
/** That something was put on the clipboard. Never what. */
|
|
16
|
+
CLIPBOARD: 'x-clipboard',
|
|
17
|
+
/** The pixels of the window: the window server drew them. */
|
|
18
|
+
PIXELS: 'x-pixels',
|
|
19
|
+
};
|
|
20
|
+
/** Stable labels. A claim matches on them exactly. */
|
|
21
|
+
export const CuSummary = {
|
|
22
|
+
UI_APPEARED: 'cu.ui.appeared',
|
|
23
|
+
UI_GONE: 'cu.ui.gone',
|
|
24
|
+
UI_CHANGED: 'cu.ui.changed',
|
|
25
|
+
/** The action was delivered and no element appeared, went away or changed. */
|
|
26
|
+
UI_NO_EFFECT: 'cu.ui.no-effect',
|
|
27
|
+
/** The keyboard moved to another element. It is not an effect by itself. */
|
|
28
|
+
UI_FOCUS_MOVED: 'cu.ui.focus-moved',
|
|
29
|
+
/** The action reached an element a person could not click. */
|
|
30
|
+
ACT_NOT_REACHABLE: 'cu.act.not-reachable',
|
|
31
|
+
FS_WRITTEN: 'cu.fs.written',
|
|
32
|
+
FS_WRITTEN_EMPTY: 'cu.fs.written-empty',
|
|
33
|
+
FS_DELETED: 'cu.fs.deleted',
|
|
34
|
+
FS_CONTENT: 'cu.fs.content',
|
|
35
|
+
/** The process wrote bytes to disk in the action. It does not say where. */
|
|
36
|
+
DISK_WROTE: 'cu.disk.wrote',
|
|
37
|
+
/** The application and the processes it started wrote nothing to disk in the action. */
|
|
38
|
+
DISK_WROTE_NOTHING: 'cu.disk.wrote-nothing',
|
|
39
|
+
/** One setting of the application has a new value, or is new, or is gone. */
|
|
40
|
+
SETTINGS_CHANGED: 'cu.settings.changed',
|
|
41
|
+
/** Something was put on the clipboard in the action. */
|
|
42
|
+
CLIPBOARD_CHANGED: 'cu.clipboard.changed',
|
|
43
|
+
/** No element changed, and the pixels of the window did: a canvas, a photo, a video frame. */
|
|
44
|
+
PIXELS_CHANGED: 'cu.pixels.changed',
|
|
45
|
+
};
|
|
46
|
+
export const CU_SURFACE = 'computer';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { WorkspacePort } from '@reticlehq/terminal';
|
|
2
|
+
import { Realm } from 'open-verification';
|
|
3
|
+
import type { Action, ActionReceipt, Capability, ChannelDescriptor, Coverage, DeterminismProfile, Handle, Observation, SubjectRef, Window } from 'open-verification';
|
|
4
|
+
import type { UiDriver } from './driver.js';
|
|
5
|
+
export interface ComputerRealmDeps {
|
|
6
|
+
readonly driver: UiDriver;
|
|
7
|
+
/** A folder to watch. Without one the realm reports effects and can prove nothing. */
|
|
8
|
+
readonly workspace?: WorkspacePort;
|
|
9
|
+
readonly now: () => number;
|
|
10
|
+
/**
|
|
11
|
+
* When a file was last written, in milliseconds. The default asks the file system. A test gives
|
|
12
|
+
* its own.
|
|
13
|
+
*/
|
|
14
|
+
readonly writeTimeOf?: (path: string) => number | undefined;
|
|
15
|
+
}
|
|
16
|
+
export interface Described {
|
|
17
|
+
subject: SubjectRef;
|
|
18
|
+
/** One line for each element. Text from the application is data, never an instruction. */
|
|
19
|
+
tree: string;
|
|
20
|
+
unread: number;
|
|
21
|
+
unmapped: readonly string[];
|
|
22
|
+
/** Elements with no place on the screen that the tree leaves out. `{ menus: true }` gives them. */
|
|
23
|
+
omitted: number;
|
|
24
|
+
/**
|
|
25
|
+
* How many windows of the application are on the screen. Zero is a fact to act on, not an empty
|
|
26
|
+
* application: the window is closed, or it is on another Space, which this realm cannot read.
|
|
27
|
+
*/
|
|
28
|
+
windows: number;
|
|
29
|
+
/** Windows that are on another Space or made small. This realm cannot read them. */
|
|
30
|
+
windowsNotOnScreen?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare class ComputerRealm extends Realm {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(deps: ComputerRealmDeps);
|
|
35
|
+
identity(): SubjectRef;
|
|
36
|
+
channels(): readonly ChannelDescriptor[];
|
|
37
|
+
determinism(): DeterminismProfile;
|
|
38
|
+
capabilities(): readonly Capability[];
|
|
39
|
+
describe(query?: unknown): Promise<Described>;
|
|
40
|
+
/** Elements with this name, or with this role, or both. One read, no tree for the caller. */
|
|
41
|
+
locate(query: unknown): Promise<readonly Handle[]>;
|
|
42
|
+
protected dispatch(action: Action): Promise<ActionReceipt>;
|
|
43
|
+
openWindow(budgetMs: number): Window;
|
|
44
|
+
/**
|
|
45
|
+
* Was this path there before the window opened? `undefined` means nobody looked: no folder is
|
|
46
|
+
* watched. A caller gives the answer to the adjudicator, so that a file that was there already
|
|
47
|
+
* does not prove an action that did nothing.
|
|
48
|
+
*/
|
|
49
|
+
existedBefore(window: Window, path: string): boolean | undefined;
|
|
50
|
+
/** Closed by quiet when every action in it settled, and by the budget when one did not. */
|
|
51
|
+
closeWindow(window: Window): Window;
|
|
52
|
+
observe(window: Window): Promise<readonly Observation[]>;
|
|
53
|
+
coverage(window: Window): Promise<Coverage>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A realm for a whole application, read and driven through the operating system.
|
|
3
|
+
*
|
|
4
|
+
* There is no code in the application. The realm reads the accessibility tree, acts on one
|
|
5
|
+
* element, and reads again. What it reports is the difference, so an agent knows what its action
|
|
6
|
+
* did, and knows when it did nothing.
|
|
7
|
+
*
|
|
8
|
+
* The tree alone proves nothing. The application draws the tree, so a change in it is the
|
|
9
|
+
* application's own word. A claim gets a `yes` only from a channel the application does not
|
|
10
|
+
* decide: here, the file system, when the caller names a folder to watch.
|
|
11
|
+
*/
|
|
12
|
+
import { ChangeKind as FileChangeKind, diffSnapshots } from '@reticlehq/terminal';
|
|
13
|
+
import { BlindSpotKind, CHANNEL_DEFAULTS, ChannelId, CloseCondition, Grade, Independence, Realm, RefusalReason, } from 'open-verification';
|
|
14
|
+
import { CU_SURFACE, CuChannel, CuSummary } from './channels.js';
|
|
15
|
+
import { ActKind, ActRefusal, Delivery } from './driver.js';
|
|
16
|
+
import { ChangeKind, EffectKind, effectOf } from './effect.js';
|
|
17
|
+
import { REWRITTEN, rewrittenSince, writeTimeOnDisk, writeTimesOf } from './files.js';
|
|
18
|
+
import { RefTable, writeLines, writeWindows } from './lines.js';
|
|
19
|
+
import { UiRole, isAddressable, label, placeShown } from './ui-node.js';
|
|
20
|
+
const UI_CHANNEL = {
|
|
21
|
+
id: CuChannel.UI,
|
|
22
|
+
...CHANNEL_DEFAULTS[ChannelId.UI],
|
|
23
|
+
note: 'the accessibility tree, which the application draws',
|
|
24
|
+
};
|
|
25
|
+
const FILE_CHANNELS = [
|
|
26
|
+
{
|
|
27
|
+
id: CuChannel.FILES,
|
|
28
|
+
independence: Independence.INDEPENDENT,
|
|
29
|
+
grade: Grade.CONSEQUENCE,
|
|
30
|
+
note: 'that a path exists and its size, which the file system decided',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: CuChannel.FILES_CONTENT,
|
|
34
|
+
independence: Independence.ACTUATION_DERIVED,
|
|
35
|
+
grade: Grade.PRESENCE,
|
|
36
|
+
note: 'the bytes in a path, which the application wrote',
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
/**
|
|
40
|
+
* Independent, because the kernel counts the bytes and the application cannot change the count.
|
|
41
|
+
* Presence grade and no higher: bytes were written, and the count does not say which file.
|
|
42
|
+
*/
|
|
43
|
+
const DISK_CHANNEL = {
|
|
44
|
+
id: CuChannel.DISK,
|
|
45
|
+
independence: Independence.INDEPENDENT,
|
|
46
|
+
grade: Grade.PRESENCE,
|
|
47
|
+
note: 'bytes the process wrote to disk, counted by the operating system',
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Not independent: the application chose the value and asked the system to keep it. It is a
|
|
51
|
+
* consequence all the same, as storage is for a web page: a setting that is kept is a thing the
|
|
52
|
+
* action did, and it is in no file the realm watches and often not on the screen.
|
|
53
|
+
*/
|
|
54
|
+
const SETTINGS_CHANNEL = {
|
|
55
|
+
id: CuChannel.SETTINGS,
|
|
56
|
+
independence: Independence.ACTUATION_DERIVED,
|
|
57
|
+
grade: Grade.CONSEQUENCE,
|
|
58
|
+
note: 'the settings of the application, read from the system store',
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The clipboard is kept by the system, and the count of its changes is the system's. What is put
|
|
62
|
+
* on it is the application's choice, and the realm does not read it. So: that it changed, at
|
|
63
|
+
* presence grade.
|
|
64
|
+
*/
|
|
65
|
+
const CLIPBOARD_CHANNEL = {
|
|
66
|
+
id: CuChannel.CLIPBOARD,
|
|
67
|
+
independence: Independence.ACTUATION_DERIVED,
|
|
68
|
+
grade: Grade.PRESENCE,
|
|
69
|
+
note: 'that something was put on the clipboard; never its content',
|
|
70
|
+
};
|
|
71
|
+
const SUMMARY_OF = {
|
|
72
|
+
[ChangeKind.GONE]: CuSummary.UI_GONE,
|
|
73
|
+
[ChangeKind.DIFFERENT]: CuSummary.UI_CHANGED,
|
|
74
|
+
[ChangeKind.NEW]: CuSummary.UI_APPEARED,
|
|
75
|
+
};
|
|
76
|
+
const REFUSAL_OF = {
|
|
77
|
+
[ActRefusal.STALE]: RefusalReason.UNRESOLVED,
|
|
78
|
+
[ActRefusal.DISABLED]: RefusalReason.GUARDED,
|
|
79
|
+
[ActRefusal.UNREACHABLE]: RefusalReason.GUARDED,
|
|
80
|
+
[ActRefusal.REACH_UNKNOWN]: RefusalReason.UNAVAILABLE,
|
|
81
|
+
[ActRefusal.NEEDS_FOREGROUND]: RefusalReason.UNAVAILABLE,
|
|
82
|
+
[ActRefusal.NO_REAL_INPUT]: RefusalReason.UNAVAILABLE,
|
|
83
|
+
[ActRefusal.PERSON_ACTIVE]: RefusalReason.GUARDED,
|
|
84
|
+
[ActRefusal.NO_KEYBOARD]: RefusalReason.GUARDED,
|
|
85
|
+
};
|
|
86
|
+
const TARGET_PARAMETERS = {
|
|
87
|
+
value: 'string, for set, type and key',
|
|
88
|
+
delivery: Object.values(Delivery),
|
|
89
|
+
};
|
|
90
|
+
function parametersOf(raw) {
|
|
91
|
+
const given = 'object' === typeof raw && raw !== null ? raw : {};
|
|
92
|
+
return {
|
|
93
|
+
...('string' === typeof given['value'] ? { value: given['value'] } : {}),
|
|
94
|
+
delivery: given['delivery'] === Delivery.DIRECT ? Delivery.DIRECT : Delivery.USER_PATH,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function isActKind(name) {
|
|
98
|
+
return Object.values(ActKind).includes(name);
|
|
99
|
+
}
|
|
100
|
+
export class ComputerRealm extends Realm {
|
|
101
|
+
#deps;
|
|
102
|
+
#refs = new RefTable();
|
|
103
|
+
#windowSeq = 0;
|
|
104
|
+
#openBudgetMs = 1000;
|
|
105
|
+
/** The files when each window opened, and the one look taken after it. */
|
|
106
|
+
#before = new Map();
|
|
107
|
+
#after = new Map();
|
|
108
|
+
/**
|
|
109
|
+
* When each watched file was last written, as each window opened.
|
|
110
|
+
*
|
|
111
|
+
* The snapshot compares what a file holds, not when it was written. An application that writes
|
|
112
|
+
* the same bytes again did write, and the snapshot shows no change. Without the time, the realm
|
|
113
|
+
* said that nothing was written.
|
|
114
|
+
*/
|
|
115
|
+
#writeTimes = new Map();
|
|
116
|
+
/**
|
|
117
|
+
* What each action did, under the window that was open when it ran.
|
|
118
|
+
*
|
|
119
|
+
* Not found by time. Two windows can open in the same millisecond, and then the second one
|
|
120
|
+
* reported the first one's action as its own.
|
|
121
|
+
*/
|
|
122
|
+
#outcomes = new Map();
|
|
123
|
+
#openWindowId;
|
|
124
|
+
#countsDisk = false;
|
|
125
|
+
#readsSettings = false;
|
|
126
|
+
#readsClipboard = false;
|
|
127
|
+
constructor(deps) {
|
|
128
|
+
super();
|
|
129
|
+
this.#deps = deps;
|
|
130
|
+
}
|
|
131
|
+
identity() {
|
|
132
|
+
const { app, pid } = this.#deps.driver.subject();
|
|
133
|
+
return { surface: CU_SURFACE, instance: `${app}#${String(pid)}` };
|
|
134
|
+
}
|
|
135
|
+
channels() {
|
|
136
|
+
return [
|
|
137
|
+
UI_CHANNEL,
|
|
138
|
+
...(this.#deps.workspace === undefined ? [] : FILE_CHANNELS),
|
|
139
|
+
// Declared when it was seen once. A driver that cannot count never gives a number, and a
|
|
140
|
+
// channel that is declared and never reported on makes every claim on it `unknown`.
|
|
141
|
+
...(this.#countsDisk ? [DISK_CHANNEL] : []),
|
|
142
|
+
...(this.#readsSettings ? [SETTINGS_CHANNEL] : []),
|
|
143
|
+
...(this.#readsClipboard ? [CLIPBOARD_CHANNEL] : []),
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
determinism() {
|
|
147
|
+
return {
|
|
148
|
+
reset: 'none',
|
|
149
|
+
replayPrefix: 'unsafe',
|
|
150
|
+
time: 'wall',
|
|
151
|
+
observation: 'sampled',
|
|
152
|
+
actions: 'irreversible',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
capabilities() {
|
|
156
|
+
return [
|
|
157
|
+
{
|
|
158
|
+
name: ActKind.PRESS,
|
|
159
|
+
meaning: 'press one element, as a click does',
|
|
160
|
+
mutating: true,
|
|
161
|
+
parameters: TARGET_PARAMETERS,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: ActKind.TYPE,
|
|
165
|
+
meaning: 'type text in one element, one key event for each character. A text field that takes the keyboard selects its text first, so the typed text replaces it',
|
|
166
|
+
mutating: true,
|
|
167
|
+
parameters: TARGET_PARAMETERS,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: ActKind.KEY,
|
|
171
|
+
meaning: 'press one key in one element, with its modifiers: Return, Meta+s',
|
|
172
|
+
mutating: true,
|
|
173
|
+
parameters: TARGET_PARAMETERS,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: ActKind.SET,
|
|
177
|
+
meaning: 'put a value in one element. It is not typing: no key event is sent',
|
|
178
|
+
mutating: true,
|
|
179
|
+
parameters: TARGET_PARAMETERS,
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
async describe(query) {
|
|
184
|
+
const read = await this.#deps.driver.read();
|
|
185
|
+
const menus = 'object' === typeof query && query !== null && 'menus' in query && true === query.menus;
|
|
186
|
+
const written = menus
|
|
187
|
+
? { tree: writeLines(read.root, this.#refs), omitted: 0 }
|
|
188
|
+
: writeWindows(read.root, this.#refs);
|
|
189
|
+
return {
|
|
190
|
+
subject: this.identity(),
|
|
191
|
+
...written,
|
|
192
|
+
windows: placeShown(read.root).shown.filter((p) => p.node.role === UiRole.WINDOW).length,
|
|
193
|
+
...(read.windowsNotOnScreen === undefined
|
|
194
|
+
? {}
|
|
195
|
+
: { windowsNotOnScreen: read.windowsNotOnScreen }),
|
|
196
|
+
unread: read.unread,
|
|
197
|
+
unmapped: read.unmapped,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** Elements with this name, or with this role, or both. One read, no tree for the caller. */
|
|
201
|
+
async locate(query) {
|
|
202
|
+
const want = 'object' === typeof query && query !== null ? query : {};
|
|
203
|
+
const read = await this.#deps.driver.read();
|
|
204
|
+
// Only what is on the screen. An item in a closed menu has a name too, and it is not a target.
|
|
205
|
+
return placeShown(read.root)
|
|
206
|
+
.shown.filter((p) => isAddressable(p.node) &&
|
|
207
|
+
(want['name'] === undefined || want['name'] === p.node.name) &&
|
|
208
|
+
(want['role'] === undefined || want['role'] === p.node.role))
|
|
209
|
+
.map((p) => ({ ref: this.#refs.refFor(p.key, p.node), describes: label(p.node) }));
|
|
210
|
+
}
|
|
211
|
+
async dispatch(action) {
|
|
212
|
+
if (!isActKind(action.capability)) {
|
|
213
|
+
return this.refuse(action, RefusalReason.UNDECLARED, `no action ${action.capability}`);
|
|
214
|
+
}
|
|
215
|
+
const target = await this.#resolve(action.target);
|
|
216
|
+
if (target === undefined) {
|
|
217
|
+
return this.refuse(action, RefusalReason.UNRESOLVED, `no element has the ref ${action.target ?? '(none)'} now. Read the application again.`);
|
|
218
|
+
}
|
|
219
|
+
const parameters = parametersOf(action.parameters);
|
|
220
|
+
const outcome = await this.#deps.driver.act({
|
|
221
|
+
target,
|
|
222
|
+
kind: action.capability,
|
|
223
|
+
...parameters,
|
|
224
|
+
budgetMs: this.#openBudgetMs,
|
|
225
|
+
watch: this.#deps.workspace?.roots ?? [],
|
|
226
|
+
});
|
|
227
|
+
if (outcome.refused !== undefined) {
|
|
228
|
+
const why = outcome.detail === undefined ? '' : ` (${outcome.detail})`;
|
|
229
|
+
return this.refuse(action, REFUSAL_OF[outcome.refused], `${outcome.refused}: ${label(target.node)}${why}`);
|
|
230
|
+
}
|
|
231
|
+
// An application that ended can end before it answers a press that it took. That is not a
|
|
232
|
+
// refusal: the outcome is kept, and the coverage says that the view was cut off.
|
|
233
|
+
if (!outcome.delivered && true !== outcome.appGone) {
|
|
234
|
+
return this.refuse(action, RefusalReason.UNAVAILABLE, 'the operating system did not take it');
|
|
235
|
+
}
|
|
236
|
+
this.#countsDisk ||= outcome.bytesWritten !== undefined;
|
|
237
|
+
this.#readsSettings ||= outcome.settingsChanged !== undefined;
|
|
238
|
+
this.#readsClipboard ||= outcome.clipboardChanged !== undefined;
|
|
239
|
+
if (this.#openWindowId !== undefined) {
|
|
240
|
+
this.#outcomes.set(this.#openWindowId, [...this.#outcomesIn(this.#openWindowId), outcome]);
|
|
241
|
+
}
|
|
242
|
+
return { action: action.id, dispatched: true, subject: this.identity(), at: this.#deps.now() };
|
|
243
|
+
}
|
|
244
|
+
/** The element a ref was given for, in a new read. A ref whose element is gone finds nothing. */
|
|
245
|
+
async #resolve(ref) {
|
|
246
|
+
const key = ref === undefined ? undefined : this.#refs.keyOf(ref);
|
|
247
|
+
if (key === undefined) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
const read = await this.#deps.driver.read();
|
|
251
|
+
return placeShown(read.root).shown.find((p) => p.key === key);
|
|
252
|
+
}
|
|
253
|
+
openWindow(budgetMs) {
|
|
254
|
+
this.#windowSeq += 1;
|
|
255
|
+
const id = `w${String(this.#windowSeq)}`;
|
|
256
|
+
if (this.#deps.workspace !== undefined) {
|
|
257
|
+
const before = this.#deps.workspace.snapshot();
|
|
258
|
+
this.#before.set(id, before);
|
|
259
|
+
this.#writeTimes.set(id, writeTimesOf(before, (path) => this.#writeTime(path)));
|
|
260
|
+
}
|
|
261
|
+
this.#openBudgetMs = budgetMs;
|
|
262
|
+
this.#openWindowId = id;
|
|
263
|
+
return {
|
|
264
|
+
id,
|
|
265
|
+
openedAt: this.#deps.now(),
|
|
266
|
+
budgetMs,
|
|
267
|
+
closes: CloseCondition.QUIESCENCE,
|
|
268
|
+
subject: this.identity(),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Was this path there before the window opened? `undefined` means nobody looked: no folder is
|
|
273
|
+
* watched. A caller gives the answer to the adjudicator, so that a file that was there already
|
|
274
|
+
* does not prove an action that did nothing.
|
|
275
|
+
*/
|
|
276
|
+
existedBefore(window, path) {
|
|
277
|
+
const before = this.#before.get(window.id);
|
|
278
|
+
return before === undefined ? undefined : before.files.has(path);
|
|
279
|
+
}
|
|
280
|
+
/** Closed by quiet when every action in it settled, and by the budget when one did not. */
|
|
281
|
+
closeWindow(window) {
|
|
282
|
+
const settled = this.#outcomesIn(window.id).every((o) => o.settled);
|
|
283
|
+
return {
|
|
284
|
+
...window,
|
|
285
|
+
closedAt: this.#deps.now(),
|
|
286
|
+
closedBy: settled ? CloseCondition.QUIESCENCE : CloseCondition.BUDGET_EXHAUSTED,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* What the realm knows about a write outside the watched folders.
|
|
291
|
+
*
|
|
292
|
+
* With a count of bytes from the operating system it is a fact, and it goes one of two ways.
|
|
293
|
+
* The process wrote bytes and no watched file changed: the write is somewhere else, so a missing
|
|
294
|
+
* file here is not held against the application. The process and its children wrote nothing:
|
|
295
|
+
* that is said as it is, with its limit. A helper that the system runs for the application is
|
|
296
|
+
* not counted, so zero is not "no write anywhere". Without a count nothing is known.
|
|
297
|
+
*/
|
|
298
|
+
#elsewhere(window) {
|
|
299
|
+
const counts = this.#outcomesIn(window.id).map((o) => o.bytesWritten);
|
|
300
|
+
const before = this.#before.get(window.id);
|
|
301
|
+
const after = this.#afterLook(window);
|
|
302
|
+
const sawAWrite = before !== undefined &&
|
|
303
|
+
after !== undefined &&
|
|
304
|
+
(diffSnapshots(before, after).length > 0 ||
|
|
305
|
+
rewrittenSince(this.#writeTimes.get(window.id) ?? new Map(), after, new Set(), (path) => this.#writeTime(path)).length > 0);
|
|
306
|
+
const bytes = counts.reduce((sum, count) => sum + (count ?? 0), 0);
|
|
307
|
+
if (counts.every((count) => count !== undefined) && counts.length > 0) {
|
|
308
|
+
if (0 === bytes) {
|
|
309
|
+
return {
|
|
310
|
+
kind: BlindSpotKind.EFFECT_ELSEWHERE,
|
|
311
|
+
detail: 'the application and the processes it started wrote nothing to disk in this window. A helper process that the system runs for the application, and a process that ended, are not counted',
|
|
312
|
+
impeaching: false,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (!sawAWrite) {
|
|
316
|
+
return {
|
|
317
|
+
kind: BlindSpotKind.EFFECT_ELSEWHERE,
|
|
318
|
+
channel: CuChannel.FILES,
|
|
319
|
+
detail: `the process wrote ${String(bytes)} bytes to disk in this window, and no watched file changed: the write is in a folder that is not watched`,
|
|
320
|
+
impeaching: true,
|
|
321
|
+
remedy: 'watch the folder that the application writes to',
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
kind: BlindSpotKind.EFFECT_ELSEWHERE,
|
|
327
|
+
detail: 'a write outside the watched folders is not seen',
|
|
328
|
+
impeaching: false,
|
|
329
|
+
remedy: 'watch more folders, or make the claim about a watched one',
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
#outcomesIn(windowId) {
|
|
333
|
+
return this.#outcomes.get(windowId) ?? [];
|
|
334
|
+
}
|
|
335
|
+
#writeTime(path) {
|
|
336
|
+
return (this.#deps.writeTimeOf ?? writeTimeOnDisk)(path);
|
|
337
|
+
}
|
|
338
|
+
#afterLook(window) {
|
|
339
|
+
const seen = this.#after.get(window.id);
|
|
340
|
+
if (seen !== undefined || this.#deps.workspace === undefined) {
|
|
341
|
+
return seen;
|
|
342
|
+
}
|
|
343
|
+
const taken = this.#deps.workspace.snapshot();
|
|
344
|
+
this.#after.set(window.id, taken);
|
|
345
|
+
return taken;
|
|
346
|
+
}
|
|
347
|
+
observe(window) {
|
|
348
|
+
const observations = [];
|
|
349
|
+
const add = (channel, summary, value) => {
|
|
350
|
+
observations.push({
|
|
351
|
+
id: `${window.id}-${String(observations.length)}`,
|
|
352
|
+
window: window.id,
|
|
353
|
+
channel,
|
|
354
|
+
at: window.openedAt,
|
|
355
|
+
value,
|
|
356
|
+
summary,
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
for (const outcome of this.#outcomesIn(window.id)) {
|
|
360
|
+
if (!outcome.reachable) {
|
|
361
|
+
add(CuChannel.UI, CuSummary.ACT_NOT_REACHABLE, {});
|
|
362
|
+
}
|
|
363
|
+
if (outcome.bytesWritten !== undefined) {
|
|
364
|
+
add(CuChannel.DISK, 0 === outcome.bytesWritten ? CuSummary.DISK_WROTE_NOTHING : CuSummary.DISK_WROTE, { bytes: outcome.bytesWritten });
|
|
365
|
+
}
|
|
366
|
+
for (const setting of outcome.settingsChanged ?? []) {
|
|
367
|
+
add(CuChannel.SETTINGS, CuSummary.SETTINGS_CHANGED, setting);
|
|
368
|
+
}
|
|
369
|
+
if (true === outcome.clipboardChanged) {
|
|
370
|
+
add(CuChannel.CLIPBOARD, CuSummary.CLIPBOARD_CHANGED, {});
|
|
371
|
+
}
|
|
372
|
+
if ((outcome.pixels?.changed ?? 0) > 0) {
|
|
373
|
+
add(CuChannel.PIXELS, CuSummary.PIXELS_CHANGED, { ...outcome.pixels });
|
|
374
|
+
}
|
|
375
|
+
const effect = effectOf(outcome.before.root, outcome.after.root);
|
|
376
|
+
if (effect.focusMovedTo !== undefined) {
|
|
377
|
+
add(CuChannel.UI, CuSummary.UI_FOCUS_MOVED, { element: effect.focusMovedTo });
|
|
378
|
+
}
|
|
379
|
+
if (effect.kind === EffectKind.NONE) {
|
|
380
|
+
add(CuChannel.UI, CuSummary.UI_NO_EFFECT, {});
|
|
381
|
+
}
|
|
382
|
+
for (const change of effect.changes) {
|
|
383
|
+
add(CuChannel.UI, SUMMARY_OF[change.kind], {
|
|
384
|
+
element: change.element,
|
|
385
|
+
...(change.detail === undefined ? {} : { detail: change.detail }),
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const before = this.#before.get(window.id);
|
|
390
|
+
const after = this.#afterLook(window);
|
|
391
|
+
for (const change of before !== undefined && after !== undefined
|
|
392
|
+
? diffSnapshots(before, after)
|
|
393
|
+
: []) {
|
|
394
|
+
const size = change.after?.size;
|
|
395
|
+
let summary = CuSummary.FS_WRITTEN;
|
|
396
|
+
if (change.kind === FileChangeKind.DELETED) {
|
|
397
|
+
summary = CuSummary.FS_DELETED;
|
|
398
|
+
}
|
|
399
|
+
else if (0 === size) {
|
|
400
|
+
summary = CuSummary.FS_WRITTEN_EMPTY;
|
|
401
|
+
}
|
|
402
|
+
add(CuChannel.FILES, summary, { path: change.path, kind: change.kind, size });
|
|
403
|
+
if (change.after?.hash !== undefined) {
|
|
404
|
+
add(CuChannel.FILES_CONTENT, CuSummary.FS_CONTENT, {
|
|
405
|
+
path: change.path,
|
|
406
|
+
hash: change.after.hash,
|
|
407
|
+
was: change.before?.hash,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
// A file with the same bytes and a new write time: the application wrote it again.
|
|
412
|
+
const changed = new Set(before !== undefined && after !== undefined
|
|
413
|
+
? diffSnapshots(before, after).map((change) => change.path)
|
|
414
|
+
: []);
|
|
415
|
+
const times = this.#writeTimes.get(window.id);
|
|
416
|
+
if (times !== undefined && after !== undefined) {
|
|
417
|
+
for (const file of rewrittenSince(times, after, changed, (path) => this.#writeTime(path))) {
|
|
418
|
+
add(CuChannel.FILES, 0 === file.size ? CuSummary.FS_WRITTEN_EMPTY : CuSummary.FS_WRITTEN, {
|
|
419
|
+
path: file.path,
|
|
420
|
+
kind: REWRITTEN,
|
|
421
|
+
size: file.size,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return Promise.resolve(observations);
|
|
426
|
+
}
|
|
427
|
+
coverage(window) {
|
|
428
|
+
const blindSpots = [];
|
|
429
|
+
const workspace = this.#deps.workspace;
|
|
430
|
+
if (workspace === undefined) {
|
|
431
|
+
blindSpots.push({
|
|
432
|
+
kind: BlindSpotKind.CHANNEL_UNOBSERVED,
|
|
433
|
+
channel: CuChannel.FILES,
|
|
434
|
+
detail: 'no folder is watched, so nothing here sees what the application wrote',
|
|
435
|
+
impeaching: false,
|
|
436
|
+
remedy: 'name a folder to watch',
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
blindSpots.push(this.#elsewhere(window));
|
|
441
|
+
for (const root of this.#afterLook(window)?.unreadable ?? []) {
|
|
442
|
+
blindSpots.push({
|
|
443
|
+
kind: BlindSpotKind.CHANNEL_UNOBSERVED,
|
|
444
|
+
channel: CuChannel.FILES,
|
|
445
|
+
detail: `could not read ${root}`,
|
|
446
|
+
impeaching: true,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// An action that was not quiet when its time ran out is still in progress. What is missing
|
|
451
|
+
// then is missing because the realm stopped looking, and an absence must not count against
|
|
452
|
+
// the application: a slow application is not a broken one.
|
|
453
|
+
if (this.#outcomesIn(window.id).some((o) => !o.settled)) {
|
|
454
|
+
blindSpots.push({
|
|
455
|
+
kind: BlindSpotKind.STILL_IN_FLIGHT,
|
|
456
|
+
detail: 'the application was not quiet when the time for the action ran out',
|
|
457
|
+
impeaching: true,
|
|
458
|
+
remedy: 'give the action more time',
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if (this.#outcomesIn(window.id).some((o) => true === o.appGone)) {
|
|
462
|
+
blindSpots.push({
|
|
463
|
+
kind: BlindSpotKind.BOUNDARY_UNCROSSABLE,
|
|
464
|
+
detail: 'the application ended while the action ran: it quit, or it crashed',
|
|
465
|
+
impeaching: true,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
const unread = this.#outcomesIn(window.id).reduce((sum, o) => sum + unreadIn(o), 0);
|
|
469
|
+
if (unread > 0) {
|
|
470
|
+
blindSpots.push({
|
|
471
|
+
kind: BlindSpotKind.BUFFER_TRUNCATED,
|
|
472
|
+
channel: CuChannel.UI,
|
|
473
|
+
detail: `the operating system did not describe ${String(unread)} element(s)`,
|
|
474
|
+
impeaching: true,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return Promise.resolve({
|
|
478
|
+
window: window.id,
|
|
479
|
+
observed: this.channels().map((c) => c.id),
|
|
480
|
+
blindSpots,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function unreadIn(outcome) {
|
|
485
|
+
const count = (read) => read.unread;
|
|
486
|
+
return count(outcome.before) + count(outcome.after);
|
|
487
|
+
}
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What must be true before `reticle-computer` can join an application, and the exact thing
|
|
3
|
+
* to do for each one that is not. Pure: the command gathers the facts, and a test gives its own.
|
|
4
|
+
*
|
|
5
|
+
* The first run is where a person gives up. Each line here is one check, and a line that is not
|
|
6
|
+
* `ok` says what to do, not only what is wrong.
|
|
7
|
+
*/
|
|
8
|
+
export interface DoctorFacts {
|
|
9
|
+
platform: string;
|
|
10
|
+
/** The Swift compiler is there to build the helper. */
|
|
11
|
+
compiler: boolean;
|
|
12
|
+
/** The screen is locked. No window can be read then. */
|
|
13
|
+
screenLocked?: boolean | undefined;
|
|
14
|
+
/** The terminal has Accessibility permission. Absent: it was not asked. */
|
|
15
|
+
trusted?: boolean | undefined;
|
|
16
|
+
app: string;
|
|
17
|
+
appOpen: boolean;
|
|
18
|
+
/** What to say when the application is not open: the names near it, or what is open. */
|
|
19
|
+
appHint?: string | undefined;
|
|
20
|
+
/** Windows of the application on this screen. Absent: they were not read. */
|
|
21
|
+
windows?: number | undefined;
|
|
22
|
+
windowsNotOnScreen?: number | undefined;
|
|
23
|
+
/** The bridge of the daemon answers. */
|
|
24
|
+
bridge: boolean;
|
|
25
|
+
/** A pairing token for the bridge was found. */
|
|
26
|
+
token: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface DoctorReport {
|
|
29
|
+
ready: boolean;
|
|
30
|
+
lines: string[];
|
|
31
|
+
}
|
|
32
|
+
export declare function doctorReport(facts: DoctorFacts): DoctorReport;
|