@namzu/computer-use 3.1.0 → 4.0.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/CHANGELOG.md +58 -1
- package/dist/SubprocessComputerUseHost.d.ts +57 -9
- package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
- package/dist/SubprocessComputerUseHost.js +213 -46
- package/dist/SubprocessComputerUseHost.js.map +1 -1
- package/dist/adapters/cua-driver/adapter.d.ts +171 -10
- package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
- package/dist/adapters/cua-driver/adapter.js +1476 -161
- package/dist/adapters/cua-driver/adapter.js.map +1 -1
- package/dist/adapters/cua-driver/client.d.ts +16 -0
- package/dist/adapters/cua-driver/client.d.ts.map +1 -1
- package/dist/adapters/cua-driver/client.js +54 -5
- package/dist/adapters/cua-driver/client.js.map +1 -1
- package/dist/adapters/cua-driver/escalation.d.ts +67 -0
- package/dist/adapters/cua-driver/escalation.d.ts.map +1 -0
- package/dist/adapters/cua-driver/escalation.js +82 -0
- package/dist/adapters/cua-driver/escalation.js.map +1 -0
- package/dist/adapters/cua-driver/keys.d.ts +5 -0
- package/dist/adapters/cua-driver/keys.d.ts.map +1 -1
- package/dist/adapters/cua-driver/keys.js +23 -0
- package/dist/adapters/cua-driver/keys.js.map +1 -1
- package/dist/adapters/cua-driver/observe.d.ts +99 -0
- package/dist/adapters/cua-driver/observe.d.ts.map +1 -0
- package/dist/adapters/cua-driver/observe.js +227 -0
- package/dist/adapters/cua-driver/observe.js.map +1 -0
- package/dist/adapters/cua-driver/ui-tree.d.ts +75 -2
- package/dist/adapters/cua-driver/ui-tree.d.ts.map +1 -1
- package/dist/adapters/cua-driver/ui-tree.js +142 -14
- package/dist/adapters/cua-driver/ui-tree.js.map +1 -1
- package/dist/adapters/types.d.ts +3 -3
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/adapters/win32.d.ts +10 -0
- package/dist/adapters/win32.d.ts.map +1 -1
- package/dist/adapters/win32.js +12 -2
- package/dist/adapters/win32.js.map +1 -1
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -1
- package/dist/foreground/guard.d.ts +31 -0
- package/dist/foreground/guard.d.ts.map +1 -0
- package/dist/foreground/guard.js +156 -0
- package/dist/foreground/guard.js.map +1 -0
- package/dist/foreground/index.d.ts +11 -0
- package/dist/foreground/index.d.ts.map +1 -0
- package/dist/foreground/index.js +7 -0
- package/dist/foreground/index.js.map +1 -0
- package/dist/foreground/ladder.d.ts +143 -0
- package/dist/foreground/ladder.d.ts.map +1 -0
- package/dist/foreground/ladder.js +505 -0
- package/dist/foreground/ladder.js.map +1 -0
- package/dist/foreground/lease.d.ts +69 -0
- package/dist/foreground/lease.d.ts.map +1 -0
- package/dist/foreground/lease.js +182 -0
- package/dist/foreground/lease.js.map +1 -0
- package/dist/foreground/types.d.ts +287 -0
- package/dist/foreground/types.d.ts.map +1 -0
- package/dist/foreground/types.js +32 -0
- package/dist/foreground/types.js.map +1 -0
- package/dist/foreground/windows-helper-script.d.ts +19 -0
- package/dist/foreground/windows-helper-script.d.ts.map +1 -0
- package/dist/foreground/windows-helper-script.js +472 -0
- package/dist/foreground/windows-helper-script.js.map +1 -0
- package/dist/foreground/windows-monitor.d.ts +75 -0
- package/dist/foreground/windows-monitor.d.ts.map +1 -0
- package/dist/foreground/windows-monitor.js +216 -0
- package/dist/foreground/windows-monitor.js.map +1 -0
- package/dist/foreground/windows.d.ts +21 -0
- package/dist/foreground/windows.d.ts.map +1 -0
- package/dist/foreground/windows.js +54 -0
- package/dist/foreground/windows.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/presence/helper-script.d.ts +39 -0
- package/dist/presence/helper-script.d.ts.map +1 -0
- package/dist/presence/helper-script.js +320 -0
- package/dist/presence/helper-script.js.map +1 -0
- package/dist/presence/index.d.ts +6 -0
- package/dist/presence/index.d.ts.map +1 -0
- package/dist/presence/index.js +4 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/presence/presence.d.ts +70 -0
- package/dist/presence/presence.d.ts.map +1 -0
- package/dist/presence/presence.js +147 -0
- package/dist/presence/presence.js.map +1 -0
- package/dist/presence/windows.d.ts +19 -0
- package/dist/presence/windows.d.ts.map +1 -0
- package/dist/presence/windows.js +39 -0
- package/dist/presence/windows.js.map +1 -0
- package/dist/util/call-scope.d.ts +34 -0
- package/dist/util/call-scope.d.ts.map +1 -0
- package/dist/util/call-scope.js +58 -0
- package/dist/util/call-scope.js.map +1 -0
- package/package.json +2 -2
- package/src/SubprocessComputerUseHost.ts +287 -45
- package/src/adapters/cua-driver/adapter.ts +1751 -175
- package/src/adapters/cua-driver/client.ts +59 -2
- package/src/adapters/cua-driver/escalation.ts +137 -0
- package/src/adapters/cua-driver/keys.ts +20 -0
- package/src/adapters/cua-driver/observe.ts +310 -0
- package/src/adapters/cua-driver/ui-tree.ts +219 -15
- package/src/adapters/types.ts +7 -2
- package/src/adapters/win32.ts +26 -3
- package/src/errors.ts +32 -0
- package/src/foreground/guard.ts +182 -0
- package/src/foreground/index.ts +45 -0
- package/src/foreground/ladder.ts +616 -0
- package/src/foreground/lease.ts +232 -0
- package/src/foreground/types.ts +318 -0
- package/src/foreground/windows-helper-script.ts +471 -0
- package/src/foreground/windows-monitor.ts +288 -0
- package/src/foreground/windows.ts +73 -0
- package/src/index.ts +15 -1
- package/src/presence/helper-script.ts +323 -0
- package/src/presence/index.ts +17 -0
- package/src/presence/presence.ts +195 -0
- package/src/presence/windows.ts +54 -0
- package/src/util/call-scope.ts +73 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { closeSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeSync, } from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
export const realLeaseFs = {
|
|
5
|
+
createExclusive(path, text) {
|
|
6
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
7
|
+
let fd;
|
|
8
|
+
try {
|
|
9
|
+
fd = openSync(path, 'wx');
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error.code === 'EEXIST')
|
|
13
|
+
return false;
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
writeSync(fd, text);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
closeSync(fd);
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
read(path) {
|
|
25
|
+
try {
|
|
26
|
+
return readFileSync(path, 'utf8');
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
remove(path) {
|
|
33
|
+
try {
|
|
34
|
+
unlinkSync(path);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Already gone.
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
rename(from, to) {
|
|
41
|
+
renameSync(from, to);
|
|
42
|
+
},
|
|
43
|
+
overwrite(path, text) {
|
|
44
|
+
// Write beside it and rename over it: a contender reading meanwhile sees
|
|
45
|
+
// the old whole record or the new one, never an empty file.
|
|
46
|
+
const temp = `${path}.tmp-${process.pid}`;
|
|
47
|
+
const fd = openSync(temp, 'w');
|
|
48
|
+
try {
|
|
49
|
+
writeSync(fd, text);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
closeSync(fd);
|
|
53
|
+
}
|
|
54
|
+
renameSync(temp, path);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
/** `/proc/<pid>/stat` field 22 (start time in ticks) on Linux; undefined elsewhere. */
|
|
58
|
+
export function processIdentity(pid) {
|
|
59
|
+
try {
|
|
60
|
+
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
61
|
+
const tail = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
62
|
+
return tail[19];
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function processAlive(pid) {
|
|
69
|
+
try {
|
|
70
|
+
process.kill(pid, 0);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return error.code === 'EPERM';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export class ScreenLease {
|
|
78
|
+
options;
|
|
79
|
+
path;
|
|
80
|
+
fs;
|
|
81
|
+
ttlMs;
|
|
82
|
+
pid;
|
|
83
|
+
identity;
|
|
84
|
+
alive;
|
|
85
|
+
constructor(options) {
|
|
86
|
+
this.options = options;
|
|
87
|
+
this.path = options.path;
|
|
88
|
+
this.fs = options.fs ?? realLeaseFs;
|
|
89
|
+
this.ttlMs = options.ttlMs ?? 30_000;
|
|
90
|
+
this.pid = options.pid ?? process.pid;
|
|
91
|
+
this.identity = options.identity ?? processIdentity;
|
|
92
|
+
this.alive = options.alive ?? processAlive;
|
|
93
|
+
}
|
|
94
|
+
/** One attempt. A stale lease is taken over; a live one is reported. */
|
|
95
|
+
tryAcquire() {
|
|
96
|
+
const token = randomUUID();
|
|
97
|
+
const now = this.options.now();
|
|
98
|
+
const record = {
|
|
99
|
+
pid: this.pid,
|
|
100
|
+
...(this.identity(this.pid) !== undefined ? { identity: this.identity(this.pid) } : {}),
|
|
101
|
+
session: this.options.session,
|
|
102
|
+
token,
|
|
103
|
+
acquiredAt: now,
|
|
104
|
+
heartbeatAt: now,
|
|
105
|
+
};
|
|
106
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
107
|
+
if (this.fs.createExclusive(this.path, JSON.stringify(record)))
|
|
108
|
+
return { held: true, token };
|
|
109
|
+
const owner = this.read();
|
|
110
|
+
if (owner && !this.stale(owner))
|
|
111
|
+
return { held: false, owner };
|
|
112
|
+
// Stale, or unreadable (half-written by a process that died): move it
|
|
113
|
+
// aside so exactly one contender removes it, then look again.
|
|
114
|
+
const aside = `${this.path}.stale-${token}`;
|
|
115
|
+
try {
|
|
116
|
+
this.fs.rename(this.path, aside);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const taken = this.fs.read(aside);
|
|
122
|
+
this.fs.remove(aside);
|
|
123
|
+
if (taken !== undefined && owner === undefined)
|
|
124
|
+
continue;
|
|
125
|
+
const movedOwner = taken === undefined ? undefined : parse(taken);
|
|
126
|
+
if (movedOwner && owner && movedOwner.token !== owner.token) {
|
|
127
|
+
// What was moved aside was a fresh lease someone took after our read.
|
|
128
|
+
this.fs.createExclusive(this.path, taken);
|
|
129
|
+
return { held: false, owner: movedOwner };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { held: false, owner: this.read() };
|
|
133
|
+
}
|
|
134
|
+
/** Marks the lease as alive. Returns false when it is no longer ours. */
|
|
135
|
+
heartbeat(token) {
|
|
136
|
+
const owner = this.read();
|
|
137
|
+
if (!owner || owner.token !== token)
|
|
138
|
+
return false;
|
|
139
|
+
this.fs.overwrite(this.path, JSON.stringify({
|
|
140
|
+
...owner,
|
|
141
|
+
heartbeatAt: this.options.now(),
|
|
142
|
+
}));
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
release(token) {
|
|
146
|
+
const owner = this.read();
|
|
147
|
+
if (owner?.token === token)
|
|
148
|
+
this.fs.remove(this.path);
|
|
149
|
+
}
|
|
150
|
+
read() {
|
|
151
|
+
const text = this.fs.read(this.path);
|
|
152
|
+
return text === undefined ? undefined : parse(text);
|
|
153
|
+
}
|
|
154
|
+
stale(owner) {
|
|
155
|
+
if (this.options.now() - owner.heartbeatAt > this.ttlMs)
|
|
156
|
+
return true;
|
|
157
|
+
if (owner.pid === this.pid)
|
|
158
|
+
return false;
|
|
159
|
+
if (!this.alive(owner.pid))
|
|
160
|
+
return true;
|
|
161
|
+
if (owner.identity !== undefined) {
|
|
162
|
+
const now = this.identity(owner.pid);
|
|
163
|
+
if (now !== undefined && now !== owner.identity)
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function parse(text) {
|
|
170
|
+
try {
|
|
171
|
+
const value = JSON.parse(text);
|
|
172
|
+
if (typeof value.pid === 'number' &&
|
|
173
|
+
typeof value.token === 'string' &&
|
|
174
|
+
typeof value.heartbeatAt === 'number')
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// Falls through.
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=lease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease.js","sourceRoot":"","sources":["../../src/foreground/lease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACN,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAkCnC,MAAM,CAAC,MAAM,WAAW,GAAY;IACnC,eAAe,CAAC,IAAI,EAAE,IAAI;QACzB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC7C,IAAI,EAAU,CAAA;QACd,IAAI,CAAC;YACJ,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC1B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO,KAAK,CAAA;YACpE,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pC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAEO,KAAK,CAAC,KAAkB;QAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAA;QACpE,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG;YAAE,OAAO,KAAK,CAAA;QACxC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAA;QACvC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAClC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACpC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,KAAK,CAAC,QAAQ;gBAAE,OAAO,IAAI,CAAA;QAC7D,CAAC;QACD,OAAO,KAAK,CAAA;IACb,CAAC;CACD;AAED,SAAS,KAAK,CAAC,IAAY;IAC1B,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAyB,CAAA;QACtD,IACC,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;YAC7B,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;YAC/B,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ;YAErC,OAAO,KAAoB,CAAA;IAC7B,CAAC;IAAC,MAAM,CAAC;QACR,iBAAiB;IAClB,CAAC;IACD,OAAO,SAAS,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The foreground ladder: what lets a computer-use action use the user's screen
|
|
3
|
+
* when it cannot be delivered in the background, without taking it from a
|
|
4
|
+
* person who is using it.
|
|
5
|
+
*
|
|
6
|
+
* The pieces are separate on purpose so each can be tested on its own:
|
|
7
|
+
* - {@link ForegroundMonitor}: a long-lived observer of the desktop (user
|
|
8
|
+
* input, the window in front, the cursor, the input desktop). On Windows it
|
|
9
|
+
* is a helper process; here it is an interface.
|
|
10
|
+
* - `ScreenLease`: one file under the Namzu home that says which session owns
|
|
11
|
+
* the screen.
|
|
12
|
+
* - `ForegroundLadder`: the policy that uses both.
|
|
13
|
+
*/
|
|
14
|
+
/** The application a burst is for: what the user is asked about, and what a refusal names. */
|
|
15
|
+
export interface ForegroundSubject {
|
|
16
|
+
/** Display name, as `list_windows` shows it. */
|
|
17
|
+
readonly app: string;
|
|
18
|
+
/** Executable file name, when known (`editor.exe`). */
|
|
19
|
+
readonly exe?: string;
|
|
20
|
+
/** Process id of the target window, when the burst has one. */
|
|
21
|
+
readonly pid?: number;
|
|
22
|
+
/** Window handle of the target, in hex. */
|
|
23
|
+
readonly hwnd?: string;
|
|
24
|
+
}
|
|
25
|
+
/** What a monitor sees at one moment. */
|
|
26
|
+
export interface MonitorState {
|
|
27
|
+
/**
|
|
28
|
+
* Milliseconds since the last input a person made. Input the machine
|
|
29
|
+
* injected (this program's own bursts included) does not count once the
|
|
30
|
+
* monitor has seen it go by; before that it counts, which only makes the
|
|
31
|
+
* gate wait longer.
|
|
32
|
+
*/
|
|
33
|
+
readonly userIdleMs: number;
|
|
34
|
+
/** Count of real keyboard and mouse events since the monitor started. Only goes up. */
|
|
35
|
+
readonly userInputs: number;
|
|
36
|
+
/** Count of real Escape key presses since the monitor started. */
|
|
37
|
+
readonly escapes: number;
|
|
38
|
+
readonly foreground: {
|
|
39
|
+
readonly hwnd: string;
|
|
40
|
+
readonly pid: number;
|
|
41
|
+
readonly exe: string;
|
|
42
|
+
/** Windows keeps this program's input from it: it runs above this program's rights, or cannot be inspected. */
|
|
43
|
+
readonly elevated: boolean;
|
|
44
|
+
/** Its mandatory integrity level as a RID (0x1000 low, 0x2000 medium, 0x3000 high, 0x4000 system); -1 when unreadable. */
|
|
45
|
+
readonly integrity?: number;
|
|
46
|
+
} | null;
|
|
47
|
+
readonly cursor: {
|
|
48
|
+
readonly x: number;
|
|
49
|
+
readonly y: number;
|
|
50
|
+
};
|
|
51
|
+
/** The input desktop's name. `Default` is the normal one; anything else is a lock screen or a prompt. */
|
|
52
|
+
readonly desktop: string;
|
|
53
|
+
/** This process runs with administrator rights. */
|
|
54
|
+
readonly selfElevated: boolean;
|
|
55
|
+
/** This process's integrity level (RID). */
|
|
56
|
+
readonly selfIntegrity?: number;
|
|
57
|
+
/** The system's last-input tick (`GetLastInputInfo`); it moves when any input, injected or real, is registered. */
|
|
58
|
+
readonly inputTick?: number;
|
|
59
|
+
/** The target process, when the state was asked for one. */
|
|
60
|
+
readonly target?: {
|
|
61
|
+
readonly exe: string;
|
|
62
|
+
readonly elevated: boolean;
|
|
63
|
+
readonly integrity?: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface MonitorBurstEnd {
|
|
67
|
+
/** Real input events that arrived between `begin` and `end`. */
|
|
68
|
+
readonly inputsDuring: number;
|
|
69
|
+
/** Real Escape presses between `begin` and `end`. */
|
|
70
|
+
readonly escapesDuring: number;
|
|
71
|
+
readonly restoredForeground: boolean;
|
|
72
|
+
readonly restoredCursor: boolean;
|
|
73
|
+
/** Why the window in front before the burst was not put back, when it was not. */
|
|
74
|
+
readonly restoreNote?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the system registered any input between the end of `begin` and
|
|
77
|
+
* `end`. False after a burst that sent input means Windows dropped it (a
|
|
78
|
+
* window above this program's rights was in front). Absent where the
|
|
79
|
+
* monitor cannot tell.
|
|
80
|
+
*/
|
|
81
|
+
readonly inputMoved?: boolean;
|
|
82
|
+
/** The window in front at `end` was positively read to be above this program's rights (unreadable is not a yes). */
|
|
83
|
+
readonly frontElevated?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/** One operation on a classic edit control, by window message (never by focus or keys). */
|
|
86
|
+
export interface EditTextRequest {
|
|
87
|
+
/** The window that holds the control, in hex. */
|
|
88
|
+
readonly hwnd: string;
|
|
89
|
+
/** `get` reads it, `set` replaces its text, `type` inserts at the caret. */
|
|
90
|
+
readonly op: 'get' | 'set' | 'type';
|
|
91
|
+
readonly text?: string;
|
|
92
|
+
/** Which control: the one with focus in that window, or the one at a screen point. A lone edit control is taken either way. */
|
|
93
|
+
readonly pick: 'focus' | 'bounds';
|
|
94
|
+
readonly at?: {
|
|
95
|
+
readonly x: number;
|
|
96
|
+
readonly y: number;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What the control reads afterwards. `found` without `done` means the message
|
|
101
|
+
* went out (or was refused: see `reason`) and the control does not read as
|
|
102
|
+
* intended.
|
|
103
|
+
*/
|
|
104
|
+
export interface EditTextResult {
|
|
105
|
+
readonly found: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Why nothing was done or read: `gone`, `uipi` (the program has higher
|
|
108
|
+
* rights), `no_edit`, `ambiguous`, `read_only`, `hung`, `refused`,
|
|
109
|
+
* `unreadable`. Empty on success.
|
|
110
|
+
*/
|
|
111
|
+
readonly reason: string;
|
|
112
|
+
readonly hwnd?: string;
|
|
113
|
+
readonly cls?: string;
|
|
114
|
+
/** The control reads as asked (`get` always). */
|
|
115
|
+
readonly done: boolean;
|
|
116
|
+
/** Characters in the control now. */
|
|
117
|
+
readonly len: number;
|
|
118
|
+
/** For `get`: the text (the first 65 536 characters). */
|
|
119
|
+
readonly text: string;
|
|
120
|
+
/** For `set` and `type`: the control's text around the change. */
|
|
121
|
+
readonly seen: string;
|
|
122
|
+
}
|
|
123
|
+
/** Select one item of a list or tree through its selection pattern, which selects without opening it. */
|
|
124
|
+
export interface SelectItemRequest {
|
|
125
|
+
/** The window that holds the item, in hex. */
|
|
126
|
+
readonly hwnd: string;
|
|
127
|
+
/** The item's role (`ListItem`, `TreeItem`, `DataItem`), name and, when it has one, automation id. */
|
|
128
|
+
readonly role: string;
|
|
129
|
+
readonly name: string;
|
|
130
|
+
readonly automationId?: string;
|
|
131
|
+
/** Where the item was read, in screen pixels: tells apart same-named items. */
|
|
132
|
+
readonly bounds?: {
|
|
133
|
+
readonly x: number;
|
|
134
|
+
readonly y: number;
|
|
135
|
+
readonly width: number;
|
|
136
|
+
readonly height: number;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* `found` is false with a `reason` (`gone`, `not_found`, `ambiguous`,
|
|
141
|
+
* `no_pattern`, `unreadable`, `refused`) when nothing was selected; `selected`
|
|
142
|
+
* is what the item reads as afterwards.
|
|
143
|
+
*/
|
|
144
|
+
export interface SelectItemResult {
|
|
145
|
+
readonly found: boolean;
|
|
146
|
+
readonly reason: string;
|
|
147
|
+
readonly selected: boolean;
|
|
148
|
+
/** `shell`: a folder window's own view (no focus, the window stays where it is); `pattern`: the accessibility selection pattern. */
|
|
149
|
+
readonly how?: 'shell' | 'pattern';
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A keyboard shortcut whose effect is a command of the window's classic menu
|
|
153
|
+
* (the item names the combination after a tab, such as "Open... Ctrl+O").
|
|
154
|
+
*/
|
|
155
|
+
export interface MenuCommandRequest {
|
|
156
|
+
/** The window, in hex. */
|
|
157
|
+
readonly hwnd: string;
|
|
158
|
+
/** The combination as a menu names it: `Ctrl+O`, `Ctrl+Shift+S`. */
|
|
159
|
+
readonly accelerator: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* `found` is false with a `reason` (`gone`, `none`: no classic menu or no item
|
|
163
|
+
* with that accelerator, `disabled`) when nothing was sent.
|
|
164
|
+
*/
|
|
165
|
+
export interface MenuCommandResult {
|
|
166
|
+
readonly found: boolean;
|
|
167
|
+
readonly reason: string;
|
|
168
|
+
/** The command's id and the item's text, when it was sent. */
|
|
169
|
+
readonly id?: number;
|
|
170
|
+
readonly label?: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Watches the desktop for a burst. Implementations must be cheap to poll (the
|
|
174
|
+
* Windows helper answers in under a millisecond) and must keep working when
|
|
175
|
+
* the program that started them dies: `begin` hands over what to put back.
|
|
176
|
+
*/
|
|
177
|
+
export interface ForegroundMonitor {
|
|
178
|
+
/** Starts watching. Rejects when real input cannot be observed: the burst is then refused. */
|
|
179
|
+
start(): Promise<void>;
|
|
180
|
+
state(query?: {
|
|
181
|
+
readonly pid?: number;
|
|
182
|
+
}): Promise<MonitorState>;
|
|
183
|
+
/**
|
|
184
|
+
* A burst is about to start. The monitor remembers the window in front, the
|
|
185
|
+
* cursor and the input count, and, should the program die before `end`,
|
|
186
|
+
* restores them and deletes the lease file (when `token` still matches).
|
|
187
|
+
*/
|
|
188
|
+
begin(args: {
|
|
189
|
+
readonly leasePath: string;
|
|
190
|
+
readonly token: string;
|
|
191
|
+
/**
|
|
192
|
+
* Window handle (hex) to bring to the front first. A driver that is not
|
|
193
|
+
* itself allowed to take focus (Windows' foreground lock) then finds its
|
|
194
|
+
* target already in front. `raised` on the answer says whether it worked.
|
|
195
|
+
*/
|
|
196
|
+
readonly raise?: string;
|
|
197
|
+
/**
|
|
198
|
+
* The user must have been still this long (ms). Checked before anything
|
|
199
|
+
* is raised; when they were not, nothing is moved and `refused` is true.
|
|
200
|
+
*/
|
|
201
|
+
readonly idleMs?: number;
|
|
202
|
+
}): Promise<MonitorState & {
|
|
203
|
+
readonly raised?: boolean;
|
|
204
|
+
readonly refused?: boolean;
|
|
205
|
+
}>;
|
|
206
|
+
/**
|
|
207
|
+
* The burst is over. With `restore`, the window that was in front is put
|
|
208
|
+
* back only if this burst raised a window and that window (or one of its
|
|
209
|
+
* program) is still in front; a burst that raised nothing restores no
|
|
210
|
+
* window, so a click that opened another window is not undone. The cursor
|
|
211
|
+
* is put back only when no person touched input meanwhile.
|
|
212
|
+
*/
|
|
213
|
+
end(args: {
|
|
214
|
+
readonly restore: boolean;
|
|
215
|
+
readonly keepCursor?: boolean;
|
|
216
|
+
}): Promise<MonitorBurstEnd>;
|
|
217
|
+
/** Deletes the lease file when its token still matches. */
|
|
218
|
+
release(args: {
|
|
219
|
+
readonly leasePath: string;
|
|
220
|
+
readonly token: string;
|
|
221
|
+
}): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Reads or changes a classic edit control by window message. Optional: a
|
|
224
|
+
* monitor that cannot reach controls leaves it out.
|
|
225
|
+
*/
|
|
226
|
+
editText?(request: EditTextRequest): Promise<EditTextResult>;
|
|
227
|
+
/** Selects a list or tree item by its selection pattern. Optional like `editText`. */
|
|
228
|
+
selectItem?(request: SelectItemRequest): Promise<SelectItemResult>;
|
|
229
|
+
/** Sends the menu command a shortcut stands for, as a window message. Optional like `editText`. */
|
|
230
|
+
menuCommand?(request: MenuCommandRequest): Promise<MenuCommandResult>;
|
|
231
|
+
dispose(): Promise<void>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Why a burst did not run. Nothing was sent to the target in any of these, so
|
|
235
|
+
* a retry is safe once the cause is gone.
|
|
236
|
+
*/
|
|
237
|
+
export type ForegroundBlockCode = 'user_active' | 'lease_busy' | 'declined' | 'stopped' | 'monitor_unavailable' | 'locked_desktop' | 'secure_desktop' | 'uac_prompt' | 'elevated_target';
|
|
238
|
+
export interface ForegroundBlock {
|
|
239
|
+
readonly code: ForegroundBlockCode;
|
|
240
|
+
/** In words the model can act on: what is blocking, and what to do next. */
|
|
241
|
+
readonly detail: string;
|
|
242
|
+
}
|
|
243
|
+
export type ForegroundOutcome<T> = {
|
|
244
|
+
readonly kind: 'ran';
|
|
245
|
+
readonly value: T;
|
|
246
|
+
/** A person used keyboard or mouse during the burst: the result is not proof either way. */
|
|
247
|
+
readonly interfered: boolean;
|
|
248
|
+
/** Escape was pressed during the burst: the turn is stopped. */
|
|
249
|
+
readonly stopped: boolean;
|
|
250
|
+
readonly restoredForeground: boolean;
|
|
251
|
+
readonly restoredCursor: boolean;
|
|
252
|
+
readonly restoreNote?: string;
|
|
253
|
+
/**
|
|
254
|
+
* For a burst declared as sending input: whether the system registered
|
|
255
|
+
* it. False means it was dropped before it reached any window; `why`
|
|
256
|
+
* then says in plain words. Absent when the burst did not send input
|
|
257
|
+
* or the monitor cannot tell.
|
|
258
|
+
*/
|
|
259
|
+
readonly inputLanded?: boolean;
|
|
260
|
+
readonly inputDroppedWhy?: string;
|
|
261
|
+
/** How long the screen was in use, from lease to release. */
|
|
262
|
+
readonly heldMs: number;
|
|
263
|
+
} | {
|
|
264
|
+
readonly kind: 'blocked';
|
|
265
|
+
readonly block: ForegroundBlock;
|
|
266
|
+
};
|
|
267
|
+
/** What the user answers when the screen is needed while they are using it. */
|
|
268
|
+
export type ForegroundAnswer = 'allow' | 'deny' | 'unavailable';
|
|
269
|
+
/**
|
|
270
|
+
* Asks the person, once, whether an application may use the screen for a
|
|
271
|
+
* moment. `unavailable` means nobody can answer (a run with no one watching):
|
|
272
|
+
* the ladder then waits and retries within its bound instead.
|
|
273
|
+
*/
|
|
274
|
+
export type ForegroundApprover = (subject: ForegroundSubject, signal?: AbortSignal) => Promise<ForegroundAnswer>;
|
|
275
|
+
/** What a burst function receives. */
|
|
276
|
+
export interface BurstContext {
|
|
277
|
+
/** Throws {@link BurstInterrupted} when a person has touched input since the burst began. */
|
|
278
|
+
checkpoint(): Promise<void>;
|
|
279
|
+
}
|
|
280
|
+
/** Thrown by {@link BurstContext.checkpoint}: the next step was not sent. */
|
|
281
|
+
export declare class BurstInterrupted extends Error {
|
|
282
|
+
readonly reason: 'person' | 'administrator_window';
|
|
283
|
+
constructor(reason?: 'person' | 'administrator_window');
|
|
284
|
+
}
|
|
285
|
+
/** The processes the ladder will not drive in the foreground. */
|
|
286
|
+
export declare const PROTECTED_PROCESSES: ReadonlyMap<string, 'locked_desktop' | 'uac_prompt'>;
|
|
287
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/foreground/types.ts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AA;CACtB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAAA;AAEhE,+EAA+E;AAC/E,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAA;AAE/D;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAChC,OAAO,EAAE,iBAAiB,EAC1B,MAAM,CAAC,EAAE,WAAW,KAChB,OAAO,CAAC,gBAAgB,CAAC,CAAA;AAE9B,sCAAsC;AACtC,MAAM,WAAW,YAAY;IAC5B,6FAA6F;IAC7F,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED,6EAA6E;AAC7E,qBAAa,gBAAiB,SAAQ,KAAK;IAC9B,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,sBAAsB;gBAAzC,MAAM,GAAE,QAAQ,GAAG,sBAAiC;CAQzE;AAED,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,CAQnF,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The foreground ladder: what lets a computer-use action use the user's screen
|
|
3
|
+
* when it cannot be delivered in the background, without taking it from a
|
|
4
|
+
* person who is using it.
|
|
5
|
+
*
|
|
6
|
+
* The pieces are separate on purpose so each can be tested on its own:
|
|
7
|
+
* - {@link ForegroundMonitor}: a long-lived observer of the desktop (user
|
|
8
|
+
* input, the window in front, the cursor, the input desktop). On Windows it
|
|
9
|
+
* is a helper process; here it is an interface.
|
|
10
|
+
* - `ScreenLease`: one file under the Namzu home that says which session owns
|
|
11
|
+
* the screen.
|
|
12
|
+
* - `ForegroundLadder`: the policy that uses both.
|
|
13
|
+
*/
|
|
14
|
+
/** Thrown by {@link BurstContext.checkpoint}: the next step was not sent. */
|
|
15
|
+
export class BurstInterrupted extends Error {
|
|
16
|
+
reason;
|
|
17
|
+
constructor(reason = 'person') {
|
|
18
|
+
super(reason === 'person'
|
|
19
|
+
? 'a person used the keyboard or mouse during the burst'
|
|
20
|
+
: 'an administrator window came to the front during the burst');
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
this.name = 'BurstInterrupted';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** The processes the ladder will not drive in the foreground. */
|
|
26
|
+
export const PROTECTED_PROCESSES = new Map([
|
|
27
|
+
['lockapp.exe', 'locked_desktop'],
|
|
28
|
+
['logonui.exe', 'locked_desktop'],
|
|
29
|
+
['winlogon.exe', 'locked_desktop'],
|
|
30
|
+
['consent.exe', 'uac_prompt'],
|
|
31
|
+
]);
|
|
32
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/foreground/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4RH,6EAA6E;AAC7E,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACrB;IAArB,YAAqB,SAA4C,QAAQ;QACxE,KAAK,CACJ,MAAM,KAAK,QAAQ;YAClB,CAAC,CAAC,sDAAsD;YACxD,CAAC,CAAC,4DAA4D,CAC/D,CAAA;QALmB,WAAM,GAAN,MAAM,CAA8C;QAMxE,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAC/B,CAAC;CACD;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAyD,IAAI,GAAG,CAG9F;IACD,CAAC,aAAa,EAAE,gBAAgB,CAAC;IACjC,CAAC,aAAa,EAAE,gBAAgB,CAAC;IACjC,CAAC,cAAc,EAAE,gBAAgB,CAAC;IAClC,CAAC,aAAa,EAAE,YAAY,CAAC;CAC7B,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Windows side of the foreground ladder: one long-lived PowerShell
|
|
3
|
+
* process that watches real keyboard and mouse input through low-level hooks
|
|
4
|
+
* (events the machine injected carry a flag and are not counted), reads the
|
|
5
|
+
* window in front, the cursor and the input desktop, and puts the window and
|
|
6
|
+
* cursor back after a burst.
|
|
7
|
+
*
|
|
8
|
+
* It is handed to PowerShell as an encoded command, never as a file: a file
|
|
9
|
+
* on the Linux side is reached through a network path on WSL, and compiling
|
|
10
|
+
* from there took 80 s the first time. The line protocol is one JSON object
|
|
11
|
+
* per line in each direction.
|
|
12
|
+
*
|
|
13
|
+
* Should the program that started it die, its input closes; the helper then
|
|
14
|
+
* puts back what a burst in progress had moved and deletes the lease file, so
|
|
15
|
+
* a crash cannot leave the user's window or cursor displaced or the screen
|
|
16
|
+
* leased.
|
|
17
|
+
*/
|
|
18
|
+
export declare const WINDOWS_HELPER_SCRIPT: string;
|
|
19
|
+
//# sourceMappingURL=windows-helper-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windows-helper-script.d.ts","sourceRoot":"","sources":["../../src/foreground/windows-helper-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,QAqcjC,CAAA"}
|