@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,505 @@
|
|
|
1
|
+
import { CallAbortedError, abortable } from '../util/call-scope.js';
|
|
2
|
+
import { ScreenLease } from './lease.js';
|
|
3
|
+
import { BurstInterrupted, PROTECTED_PROCESSES, } from './types.js';
|
|
4
|
+
export const realClock = {
|
|
5
|
+
now: () => Date.now(),
|
|
6
|
+
sleep(ms, signal) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
if (signal?.aborted)
|
|
9
|
+
return resolve();
|
|
10
|
+
const timer = setTimeout(done, ms);
|
|
11
|
+
function done() {
|
|
12
|
+
clearTimeout(timer);
|
|
13
|
+
signal?.removeEventListener('abort', done);
|
|
14
|
+
resolve();
|
|
15
|
+
}
|
|
16
|
+
signal?.addEventListener('abort', done, { once: true });
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export const DEFAULT_TIMING = {
|
|
21
|
+
idleMs: 2_000,
|
|
22
|
+
approvedIdleMs: 500,
|
|
23
|
+
pollMs: 50,
|
|
24
|
+
userActiveWaitMs: 15_000,
|
|
25
|
+
approvedWaitMs: 30_000,
|
|
26
|
+
parkMs: 120_000,
|
|
27
|
+
parkPollMs: 250,
|
|
28
|
+
leaseWaitMs: 30_000,
|
|
29
|
+
leasePollMs: 200,
|
|
30
|
+
leaseBeatMs: 8_000,
|
|
31
|
+
parkTurnMs: 600_000,
|
|
32
|
+
};
|
|
33
|
+
/** What the model reads once Escape has stopped the turn. Fixed on purpose. */
|
|
34
|
+
export const STOPPED_TEXT = 'The user pressed Escape, so computer use is stopped for the rest of this turn. Stop now: tell the user what is still undone, and do not call computer_use again until they send a new message.';
|
|
35
|
+
const seconds = (ms) => `${Math.max(1, Math.round(ms / 1000))} s`;
|
|
36
|
+
const BLOCKS = {
|
|
37
|
+
locked_desktop: () => ({
|
|
38
|
+
code: 'locked_desktop',
|
|
39
|
+
detail: 'The computer is locked or showing a sign-in screen, so nothing was sent. Ask the user to unlock it, then continue. Do not try to work around it.',
|
|
40
|
+
}),
|
|
41
|
+
secure_desktop: () => ({
|
|
42
|
+
code: 'secure_desktop',
|
|
43
|
+
detail: 'A system prompt that only the user can answer has the screen (an administrator-permission prompt, for example), so nothing was sent. Ask the user to answer it themselves. Never try to work around it.',
|
|
44
|
+
}),
|
|
45
|
+
uac_prompt: () => ({
|
|
46
|
+
code: 'uac_prompt',
|
|
47
|
+
detail: 'An administrator-permission prompt is in front, so nothing was sent. Ask the user to answer it themselves. Never try to work around it.',
|
|
48
|
+
}),
|
|
49
|
+
elevated_target: (inFront = false) => ({
|
|
50
|
+
code: 'elevated_target',
|
|
51
|
+
detail: inFront
|
|
52
|
+
? 'An administrator window is in front; Namzu cannot type into it, so nothing was sent. Ask the user to click away from it, or to do this step themselves. Do not try to work around it.'
|
|
53
|
+
: 'This program runs with administrator rights, so input from here is blocked and nothing was sent. Ask the user to act in it, or to restart it without administrator rights. Do not try to work around it.',
|
|
54
|
+
}),
|
|
55
|
+
monitor_unavailable: (reason) => ({
|
|
56
|
+
code: 'monitor_unavailable',
|
|
57
|
+
detail: `This computer cannot watch for the user's keyboard and mouse (${reason}), so the screen is not used and nothing was sent. Use controls by ref (ui_act) in the background, or ask the user to do this step.`,
|
|
58
|
+
}),
|
|
59
|
+
declined: (app) => ({
|
|
60
|
+
code: 'declined',
|
|
61
|
+
detail: `The user did not allow ${app} to use the screen for this, so nothing was sent. Do not ask again this turn; tell them what you could not do.`,
|
|
62
|
+
}),
|
|
63
|
+
stopped: () => ({ code: 'stopped', detail: STOPPED_TEXT }),
|
|
64
|
+
lease_busy: (waited) => ({
|
|
65
|
+
code: 'lease_busy',
|
|
66
|
+
detail: `Another Namzu session has been using the screen for the last ${seconds(waited)}, so nothing was sent. Try this action again in a moment.`,
|
|
67
|
+
}),
|
|
68
|
+
user_active: (waited, asked) => ({
|
|
69
|
+
code: 'user_active',
|
|
70
|
+
detail: `The user kept using the keyboard or mouse for ${seconds(waited)}${asked ? ' even after agreeing' : ''}, so the screen was not taken and nothing was sent. Do other work that does not need the screen, or try this action again later.`,
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
/** Times a burst start is retried because input arrived between the last look and the start. */
|
|
74
|
+
const MAX_INTERFERED_STARTS = 3;
|
|
75
|
+
/**
|
|
76
|
+
* The foreground ladder. `run` takes a burst (a function that sends input
|
|
77
|
+
* which can only be delivered in the foreground) through:
|
|
78
|
+
*
|
|
79
|
+
* 1. the lease: one session at a time, a stale lease taken over;
|
|
80
|
+
* 2. the safety checks: lock screen, system prompts, administrator windows;
|
|
81
|
+
* 3. the idle gate: the user still for `idleMs`;
|
|
82
|
+
* 4. if the user stays busy for `userActiveWaitMs`: one question to them, or,
|
|
83
|
+
* where nobody can be asked, a bounded wait that retries;
|
|
84
|
+
* 5. the burst, watched for real input from start to end;
|
|
85
|
+
* 6. a conditional restore of the window and cursor that were there before.
|
|
86
|
+
*
|
|
87
|
+
* Nothing here sends input itself and nothing waits without a bound.
|
|
88
|
+
*/
|
|
89
|
+
export class ForegroundLadder {
|
|
90
|
+
options;
|
|
91
|
+
timing;
|
|
92
|
+
clock;
|
|
93
|
+
lease;
|
|
94
|
+
monitor;
|
|
95
|
+
queue = Promise.resolve();
|
|
96
|
+
/** The restore of a cancelled burst, which runs after its caller has been answered. */
|
|
97
|
+
background = Promise.resolve();
|
|
98
|
+
stop;
|
|
99
|
+
leaseBeatMs;
|
|
100
|
+
parkedMs = 0;
|
|
101
|
+
turn;
|
|
102
|
+
allowed = new Set();
|
|
103
|
+
denied = new Set();
|
|
104
|
+
constructor(options) {
|
|
105
|
+
this.options = options;
|
|
106
|
+
this.timing = { ...DEFAULT_TIMING, ...options.timing };
|
|
107
|
+
this.clock = options.clock ?? realClock;
|
|
108
|
+
this.leaseBeatMs = this.timing.leaseBeatMs;
|
|
109
|
+
this.lease =
|
|
110
|
+
options.lease ??
|
|
111
|
+
new ScreenLease({
|
|
112
|
+
path: options.leasePath,
|
|
113
|
+
session: options.session ?? 'session',
|
|
114
|
+
now: () => this.clock.now(),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** True after a physical Escape, until the next user turn. */
|
|
118
|
+
get stopped() {
|
|
119
|
+
return this.stop !== undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The model's turn `turnId` is starting a tool call. A new turn lifts an
|
|
123
|
+
* Escape stop and forgets refused permissions. A caller that has no turn id
|
|
124
|
+
* passes undefined, which always counts as a new turn.
|
|
125
|
+
*/
|
|
126
|
+
beginTurn(turnId) {
|
|
127
|
+
if (this.stop && (turnId === undefined || turnId !== this.stop.turnId))
|
|
128
|
+
this.stop = undefined;
|
|
129
|
+
if (turnId === undefined || turnId !== this.turn) {
|
|
130
|
+
this.denied.clear();
|
|
131
|
+
this.parkedMs = 0;
|
|
132
|
+
}
|
|
133
|
+
this.turn = turnId;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Reads or changes a classic edit control by window message through the
|
|
137
|
+
* monitor. It uses neither the screen nor the lease: nothing is raised and
|
|
138
|
+
* no input is sent. Undefined where no monitor can reach controls.
|
|
139
|
+
*/
|
|
140
|
+
async editText(request) {
|
|
141
|
+
const monitor = await this.ensureMonitor();
|
|
142
|
+
if (!monitor.ok || !monitor.monitor.editText)
|
|
143
|
+
return undefined;
|
|
144
|
+
try {
|
|
145
|
+
return await abortable('edit_text', monitor.monitor.editText(request));
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (error instanceof CallAbortedError)
|
|
149
|
+
throw error;
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Selects one list or tree item through its selection pattern. Like
|
|
155
|
+
* `editText` it uses neither the screen nor the lease. Undefined where no
|
|
156
|
+
* monitor can reach controls.
|
|
157
|
+
*/
|
|
158
|
+
async selectItem(request) {
|
|
159
|
+
const monitor = await this.ensureMonitor();
|
|
160
|
+
if (!monitor.ok || !monitor.monitor.selectItem)
|
|
161
|
+
return undefined;
|
|
162
|
+
try {
|
|
163
|
+
return await abortable('select_item', monitor.monitor.selectItem(request));
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (error instanceof CallAbortedError)
|
|
167
|
+
throw error;
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Sends the menu command a shortcut stands for, as a window message: no
|
|
173
|
+
* screen, no lease, no key. Undefined where no monitor can reach windows.
|
|
174
|
+
*/
|
|
175
|
+
async menuCommand(request) {
|
|
176
|
+
const monitor = await this.ensureMonitor();
|
|
177
|
+
if (!monitor.ok || !monitor.monitor.menuCommand)
|
|
178
|
+
return undefined;
|
|
179
|
+
try {
|
|
180
|
+
return await abortable('menu_command', monitor.monitor.menuCommand(request));
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (error instanceof CallAbortedError)
|
|
184
|
+
throw error;
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Whether the computer is locked, read from the long-lived helper (cheap once
|
|
190
|
+
* it runs): the input desktop is not the normal one, or the lock screen's own
|
|
191
|
+
* program is in front. `null` when unsure (no helper, or a state that is not
|
|
192
|
+
* clearly either), so a caller treats it as unlocked.
|
|
193
|
+
*/
|
|
194
|
+
async lockState() {
|
|
195
|
+
const monitor = await this.ensureMonitor();
|
|
196
|
+
if (!monitor.ok)
|
|
197
|
+
return null;
|
|
198
|
+
try {
|
|
199
|
+
const state = await abortable('lock_state', monitor.monitor.state());
|
|
200
|
+
const desktop = state.desktop.toLowerCase();
|
|
201
|
+
if (desktop === 'default') {
|
|
202
|
+
const front = state.foreground?.exe.toLowerCase();
|
|
203
|
+
return front !== undefined && PROTECTED_PROCESSES.get(front) === 'locked_desktop'
|
|
204
|
+
? 'locked'
|
|
205
|
+
: 'unlocked';
|
|
206
|
+
}
|
|
207
|
+
// A desktop that cannot be read says nothing; a named one that is not the normal one is a lock or sign-in screen.
|
|
208
|
+
return desktop === '(unreadable)' ? null : 'locked';
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
if (error instanceof CallAbortedError)
|
|
212
|
+
throw error;
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** The model's turn ended or was interrupted: nothing stays watched or held. */
|
|
217
|
+
async endTurn() {
|
|
218
|
+
this.denied.clear();
|
|
219
|
+
// A burst in flight puts its window and cursor back through the monitor
|
|
220
|
+
// when it ends; dropping the monitor first would restore under it.
|
|
221
|
+
await this.queue;
|
|
222
|
+
await this.dropMonitor();
|
|
223
|
+
}
|
|
224
|
+
async dispose() {
|
|
225
|
+
this.allowed.clear();
|
|
226
|
+
await this.endTurn();
|
|
227
|
+
}
|
|
228
|
+
run(request, burst) {
|
|
229
|
+
const run = this.queue.then(() => this.runOne(request, burst));
|
|
230
|
+
// The next burst, and the end of the turn, wait for the restore a cancelled burst left running.
|
|
231
|
+
this.queue = run.catch(() => undefined).then(() => this.background);
|
|
232
|
+
return run;
|
|
233
|
+
}
|
|
234
|
+
async runOne(request, burst, attempt = 0) {
|
|
235
|
+
const { subject, signal } = request;
|
|
236
|
+
if (this.stop)
|
|
237
|
+
return { kind: 'blocked', block: BLOCKS.stopped() };
|
|
238
|
+
const monitor = await this.ensureMonitor();
|
|
239
|
+
if (!monitor.ok)
|
|
240
|
+
return {
|
|
241
|
+
kind: 'blocked',
|
|
242
|
+
block: BLOCKS.monitor_unavailable(monitor.reason),
|
|
243
|
+
};
|
|
244
|
+
const leaseStart = this.clock.now();
|
|
245
|
+
const token = await this.acquireLease(signal);
|
|
246
|
+
if (token === undefined)
|
|
247
|
+
return {
|
|
248
|
+
kind: 'blocked',
|
|
249
|
+
block: BLOCKS.lease_busy(this.clock.now() - leaseStart),
|
|
250
|
+
};
|
|
251
|
+
let deferred = false;
|
|
252
|
+
try {
|
|
253
|
+
const state = await this.gate(monitor.monitor, subject, signal);
|
|
254
|
+
if ('block' in state)
|
|
255
|
+
return { kind: 'blocked', block: state.block };
|
|
256
|
+
const startedAt = this.clock.now();
|
|
257
|
+
const begun = await monitor.monitor.begin({
|
|
258
|
+
leasePath: this.lease.path,
|
|
259
|
+
token,
|
|
260
|
+
// Checked by the monitor before it raises anything, so a person who
|
|
261
|
+
// started typing after the last look is not displaced.
|
|
262
|
+
idleMs: state.needed,
|
|
263
|
+
...(subject.hwnd !== undefined ? { raise: subject.hwnd } : {}),
|
|
264
|
+
});
|
|
265
|
+
// A person touched input between the last look and now: not yet.
|
|
266
|
+
if (begun.refused === true || begun.userInputs !== state.state.userInputs) {
|
|
267
|
+
if (attempt >= MAX_INTERFERED_STARTS) {
|
|
268
|
+
await monitor.monitor.end({ restore: true }).catch(() => undefined);
|
|
269
|
+
return {
|
|
270
|
+
kind: 'blocked',
|
|
271
|
+
block: BLOCKS.user_active(this.clock.now() - startedAt, false),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
return await this.retryAfterInterference(monitor.monitor, request, burst, token, attempt + 1);
|
|
275
|
+
}
|
|
276
|
+
const beat = setInterval(() => void this.lease.heartbeat(token), Math.max(1, Math.floor(this.leaseBeatMs)));
|
|
277
|
+
beat.unref?.();
|
|
278
|
+
let value;
|
|
279
|
+
let failure;
|
|
280
|
+
try {
|
|
281
|
+
value = await burst({
|
|
282
|
+
checkpoint: async () => {
|
|
283
|
+
if (!this.lease.heartbeat(token))
|
|
284
|
+
throw new BurstInterrupted();
|
|
285
|
+
const now = await monitor.monitor.state();
|
|
286
|
+
if (now.userInputs !== begun.userInputs)
|
|
287
|
+
throw new BurstInterrupted();
|
|
288
|
+
// The hooks see nothing typed into a window above this program's rights,
|
|
289
|
+
// so a person there cannot be told from silence: stop rather than guess.
|
|
290
|
+
// Only a window positively read above this program's rights counts; one
|
|
291
|
+
// that cannot be read (no front window, a closing menu) is not a reason.
|
|
292
|
+
const above = now.foreground?.integrity;
|
|
293
|
+
if (!now.selfElevated &&
|
|
294
|
+
above !== undefined &&
|
|
295
|
+
above >= 0 &&
|
|
296
|
+
above > (now.selfIntegrity ?? Number.MAX_SAFE_INTEGER))
|
|
297
|
+
throw new BurstInterrupted('administrator_window');
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
failure = { error };
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
clearInterval(beat);
|
|
306
|
+
}
|
|
307
|
+
// Calls the burst abandoned (an abort) may still be sending: they finish
|
|
308
|
+
// before the window and cursor are put back. The burst ends, and what it
|
|
309
|
+
// moved is put back, whether it returned or threw; an Escape pressed on
|
|
310
|
+
// the way stops the turn either way.
|
|
311
|
+
const finish = async () => {
|
|
312
|
+
await request.settle?.().catch(() => undefined);
|
|
313
|
+
const result = await monitor.monitor
|
|
314
|
+
.end({
|
|
315
|
+
restore: true,
|
|
316
|
+
...(request.keepCursor ? { keepCursor: true } : {}),
|
|
317
|
+
})
|
|
318
|
+
.catch(() => undefined);
|
|
319
|
+
if ((result?.escapesDuring ?? 0) > 0)
|
|
320
|
+
this.stop = { turnId: this.turn };
|
|
321
|
+
return result;
|
|
322
|
+
};
|
|
323
|
+
if (failure && request.signal?.aborted) {
|
|
324
|
+
// A cancelled turn does not wait for the driver to let go: the caller gets
|
|
325
|
+
// its answer now, and the screen is given back, and the lease released,
|
|
326
|
+
// once the abandoned calls have finished. The next burst and the end of
|
|
327
|
+
// the turn wait for that (see `background`).
|
|
328
|
+
deferred = true;
|
|
329
|
+
this.background = finish()
|
|
330
|
+
.then(() => undefined)
|
|
331
|
+
.finally(() => {
|
|
332
|
+
this.lease.release(token);
|
|
333
|
+
return this.monitor
|
|
334
|
+
?.release({ leasePath: this.lease.path, token })
|
|
335
|
+
.catch(() => undefined);
|
|
336
|
+
});
|
|
337
|
+
throw failure.error;
|
|
338
|
+
}
|
|
339
|
+
const ended = await finish();
|
|
340
|
+
const stopped = (ended?.escapesDuring ?? 0) > 0;
|
|
341
|
+
if (failure)
|
|
342
|
+
throw failure.error;
|
|
343
|
+
// A tick that did not move proves a drop only when a window above this
|
|
344
|
+
// program's rights was positively in front: input posted as messages
|
|
345
|
+
// does not move it, and calling that dropped would invite a duplicate.
|
|
346
|
+
const dropped = request.sendsInput === true &&
|
|
347
|
+
ended?.inputMoved === false &&
|
|
348
|
+
ended.inputsDuring === 0 &&
|
|
349
|
+
ended.frontElevated === true;
|
|
350
|
+
return {
|
|
351
|
+
kind: 'ran',
|
|
352
|
+
value: value,
|
|
353
|
+
// Input went out; if the monitor cannot say what happened around it,
|
|
354
|
+
// the result is not proof either way.
|
|
355
|
+
interfered: ended === undefined || ended.inputsDuring > 0,
|
|
356
|
+
stopped,
|
|
357
|
+
restoredForeground: ended?.restoredForeground ?? false,
|
|
358
|
+
restoredCursor: ended?.restoredCursor ?? false,
|
|
359
|
+
...(ended?.restoreNote ? { restoreNote: ended.restoreNote } : {}),
|
|
360
|
+
...(request.sendsInput === true && (dropped || ended?.inputMoved === true)
|
|
361
|
+
? { inputLanded: !dropped }
|
|
362
|
+
: {}),
|
|
363
|
+
...(dropped
|
|
364
|
+
? {
|
|
365
|
+
inputDroppedWhy: 'An administrator window is in front; Namzu cannot type into it.',
|
|
366
|
+
}
|
|
367
|
+
: {}),
|
|
368
|
+
heldMs: this.clock.now() - startedAt,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
finally {
|
|
372
|
+
if (!deferred) {
|
|
373
|
+
this.lease.release(token);
|
|
374
|
+
await this.monitor?.release({ leasePath: this.lease.path, token }).catch(() => undefined);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
async retryAfterInterference(monitor, request, burst, token, attempt) {
|
|
379
|
+
// A raise that happened just before a person's input is undone too.
|
|
380
|
+
await monitor.end({ restore: true }).catch(() => undefined);
|
|
381
|
+
// The lease is ours until runOne's finally; release it so the nested run takes it afresh.
|
|
382
|
+
this.lease.release(token);
|
|
383
|
+
return this.runOne(request, burst, attempt);
|
|
384
|
+
}
|
|
385
|
+
async ensureMonitor() {
|
|
386
|
+
if (this.monitor)
|
|
387
|
+
return { ok: true, monitor: this.monitor };
|
|
388
|
+
const monitor = this.options.createMonitor();
|
|
389
|
+
try {
|
|
390
|
+
await monitor.start();
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
await monitor.dispose().catch(() => undefined);
|
|
394
|
+
return {
|
|
395
|
+
ok: false,
|
|
396
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
this.monitor = monitor;
|
|
400
|
+
return { ok: true, monitor };
|
|
401
|
+
}
|
|
402
|
+
async dropMonitor() {
|
|
403
|
+
const monitor = this.monitor;
|
|
404
|
+
this.monitor = undefined;
|
|
405
|
+
await monitor?.dispose().catch(() => undefined);
|
|
406
|
+
}
|
|
407
|
+
async acquireLease(signal) {
|
|
408
|
+
const deadline = this.clock.now() + this.timing.leaseWaitMs;
|
|
409
|
+
for (;;) {
|
|
410
|
+
const attempt = this.lease.tryAcquire();
|
|
411
|
+
if (attempt.held)
|
|
412
|
+
return attempt.token;
|
|
413
|
+
if (this.clock.now() >= deadline || signal?.aborted)
|
|
414
|
+
return undefined;
|
|
415
|
+
await this.clock.sleep(this.timing.leasePollMs, signal);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/** Safety checks and the idle gate, with the one question to the user. */
|
|
419
|
+
async gate(monitor, subject, signal) {
|
|
420
|
+
const started = this.clock.now();
|
|
421
|
+
let phase = 'gate';
|
|
422
|
+
let phaseStart = started;
|
|
423
|
+
let asked = false;
|
|
424
|
+
let first = true;
|
|
425
|
+
for (;;) {
|
|
426
|
+
const state = await monitor.state(subject.pid !== undefined ? { pid: subject.pid } : {});
|
|
427
|
+
const unsafe = this.unsafe(state);
|
|
428
|
+
if (unsafe)
|
|
429
|
+
return { block: unsafe };
|
|
430
|
+
const who = effectiveSubject(subject, state);
|
|
431
|
+
const key = (who.exe ?? who.app).toLowerCase();
|
|
432
|
+
if (first && this.allowed.has(key)) {
|
|
433
|
+
phase = 'approved';
|
|
434
|
+
asked = true;
|
|
435
|
+
}
|
|
436
|
+
first = false;
|
|
437
|
+
const needed = phase === 'approved' ? this.timing.approvedIdleMs : this.timing.idleMs;
|
|
438
|
+
if (state.userIdleMs >= needed)
|
|
439
|
+
return { state, needed };
|
|
440
|
+
const now = this.clock.now();
|
|
441
|
+
const limit = phase === 'gate'
|
|
442
|
+
? this.timing.userActiveWaitMs
|
|
443
|
+
: phase === 'approved'
|
|
444
|
+
? this.timing.approvedWaitMs
|
|
445
|
+
: this.timing.parkMs;
|
|
446
|
+
if (now - phaseStart >= limit ||
|
|
447
|
+
signal?.aborted ||
|
|
448
|
+
(phase === 'parked' && this.parkedMs >= this.timing.parkTurnMs)) {
|
|
449
|
+
if (phase === 'gate' && !signal?.aborted) {
|
|
450
|
+
if (this.denied.has(key))
|
|
451
|
+
return { block: BLOCKS.declined(who.app) };
|
|
452
|
+
const answer = (await this.options.approve?.(who, signal)) ?? 'unavailable';
|
|
453
|
+
if (answer === 'deny') {
|
|
454
|
+
this.denied.add(key);
|
|
455
|
+
return { block: BLOCKS.declined(who.app) };
|
|
456
|
+
}
|
|
457
|
+
if (answer === 'allow') {
|
|
458
|
+
this.allowed.add(key);
|
|
459
|
+
phase = 'approved';
|
|
460
|
+
asked = true;
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
phase = 'parked';
|
|
464
|
+
}
|
|
465
|
+
phaseStart = this.clock.now();
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
return { block: BLOCKS.user_active(now - started, asked) };
|
|
469
|
+
}
|
|
470
|
+
const wait = phase === 'parked' ? this.timing.parkPollMs : this.timing.pollMs;
|
|
471
|
+
if (phase === 'parked')
|
|
472
|
+
this.parkedMs += wait;
|
|
473
|
+
await this.clock.sleep(wait, signal);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
unsafe(state) {
|
|
477
|
+
if (state.desktop.toLowerCase() !== 'default')
|
|
478
|
+
return BLOCKS.secure_desktop();
|
|
479
|
+
const front = state.foreground?.exe.toLowerCase();
|
|
480
|
+
const protectedKind = front === undefined ? undefined : PROTECTED_PROCESSES.get(front);
|
|
481
|
+
if (protectedKind)
|
|
482
|
+
return BLOCKS[protectedKind]();
|
|
483
|
+
if (state.selfElevated)
|
|
484
|
+
return undefined;
|
|
485
|
+
if (state.target?.elevated)
|
|
486
|
+
return BLOCKS.elevated_target();
|
|
487
|
+
// Windows will not let a program with lower rights take the front from one
|
|
488
|
+
// with higher rights, so the burst could neither raise its target nor type.
|
|
489
|
+
if (state.foreground?.elevated)
|
|
490
|
+
return BLOCKS.elevated_target(true);
|
|
491
|
+
return undefined;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/** A burst for the desktop as such is for whichever program is in front when it starts. */
|
|
495
|
+
function effectiveSubject(subject, state) {
|
|
496
|
+
if (subject.exe !== undefined || subject.pid !== undefined || !state.foreground)
|
|
497
|
+
return subject;
|
|
498
|
+
const exe = state.foreground.exe;
|
|
499
|
+
return {
|
|
500
|
+
app: exe.replace(/\.exe$/i, '') || subject.app,
|
|
501
|
+
exe,
|
|
502
|
+
pid: state.foreground.pid,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
//# sourceMappingURL=ladder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ladder.js","sourceRoot":"","sources":["../../src/foreground/ladder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAqB,WAAW,EAAE,MAAM,YAAY,CAAA;AAC3D,OAAO,EAEN,gBAAgB,EAYhB,mBAAmB,GAGnB,MAAM,YAAY,CAAA;AAQnB,MAAM,CAAC,MAAM,SAAS,GAAgB;IACrC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IACrB,KAAK,CAAC,EAAE,EAAE,MAAM;QACf,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,IAAI,MAAM,EAAE,OAAO;gBAAE,OAAO,OAAO,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ED,2FAA2F;AAC3F,SAAS,gBAAgB,CAAC,OAA0B,EAAE,KAAmB;IACxE,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,UAAU;QAAE,OAAO,OAAO,CAAA;IAC/F,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAA;IAChC,OAAO;QACN,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,GAAG;QAC9C,GAAG;QACH,GAAG,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG;KACzB,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cross-session screen lease: one file that says which session may use
|
|
3
|
+
* the user's screen right now, so two sessions never interleave foreground
|
|
4
|
+
* bursts.
|
|
5
|
+
*
|
|
6
|
+
* A lease is stale, and may be taken over, when its owner process is gone,
|
|
7
|
+
* when a process with that id exists but started at another time (the id was
|
|
8
|
+
* reused), or when nobody refreshed it within the time-to-live. The last rule
|
|
9
|
+
* covers owners on a machine this process cannot inspect.
|
|
10
|
+
*/
|
|
11
|
+
export interface LeaseRecord {
|
|
12
|
+
readonly pid: number;
|
|
13
|
+
/** The owner's process start time as the OS reports it; absent where unknown. */
|
|
14
|
+
readonly identity?: string;
|
|
15
|
+
readonly session: string;
|
|
16
|
+
readonly token: string;
|
|
17
|
+
readonly acquiredAt: number;
|
|
18
|
+
readonly heartbeatAt: number;
|
|
19
|
+
}
|
|
20
|
+
/** The file operations the lease needs; replaced in tests. */
|
|
21
|
+
export interface LeaseFs {
|
|
22
|
+
/** Creates the file with `text`; false when it already exists. */
|
|
23
|
+
createExclusive(path: string, text: string): boolean;
|
|
24
|
+
read(path: string): string | undefined;
|
|
25
|
+
remove(path: string): void;
|
|
26
|
+
rename(from: string, to: string): void;
|
|
27
|
+
/** Replaces the text of an existing file. */
|
|
28
|
+
overwrite(path: string, text: string): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const realLeaseFs: LeaseFs;
|
|
31
|
+
/** `/proc/<pid>/stat` field 22 (start time in ticks) on Linux; undefined elsewhere. */
|
|
32
|
+
export declare function processIdentity(pid: number): string | undefined;
|
|
33
|
+
export declare function processAlive(pid: number): boolean;
|
|
34
|
+
export interface ScreenLeaseOptions {
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly session: string;
|
|
37
|
+
readonly now: () => number;
|
|
38
|
+
/** Milliseconds after the last refresh at which a lease is stale. Default 30 000. */
|
|
39
|
+
readonly ttlMs?: number;
|
|
40
|
+
readonly pid?: number;
|
|
41
|
+
readonly fs?: LeaseFs;
|
|
42
|
+
readonly identity?: (pid: number) => string | undefined;
|
|
43
|
+
readonly alive?: (pid: number) => boolean;
|
|
44
|
+
}
|
|
45
|
+
export type LeaseAttempt = {
|
|
46
|
+
readonly held: true;
|
|
47
|
+
readonly token: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly held: false;
|
|
50
|
+
readonly owner: LeaseRecord | undefined;
|
|
51
|
+
};
|
|
52
|
+
export declare class ScreenLease {
|
|
53
|
+
private readonly options;
|
|
54
|
+
readonly path: string;
|
|
55
|
+
private readonly fs;
|
|
56
|
+
private readonly ttlMs;
|
|
57
|
+
private readonly pid;
|
|
58
|
+
private readonly identity;
|
|
59
|
+
private readonly alive;
|
|
60
|
+
constructor(options: ScreenLeaseOptions);
|
|
61
|
+
/** One attempt. A stale lease is taken over; a live one is reported. */
|
|
62
|
+
tryAcquire(): LeaseAttempt;
|
|
63
|
+
/** Marks the lease as alive. Returns false when it is no longer ours. */
|
|
64
|
+
heartbeat(token: string): boolean;
|
|
65
|
+
release(token: string): void;
|
|
66
|
+
read(): LeaseRecord | undefined;
|
|
67
|
+
private stale;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=lease.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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