@namzu/computer-use 4.2.0 → 4.3.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 +16 -0
- package/dist/adapters/cua-driver/adapter.d.ts +1 -1
- package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
- package/dist/adapters/cua-driver/adapter.js +7 -3
- package/dist/adapters/cua-driver/adapter.js.map +1 -1
- package/dist/foreground/guard.js +3 -3
- package/dist/foreground/guard.js.map +1 -1
- package/dist/foreground/ladder.d.ts +15 -1
- package/dist/foreground/ladder.d.ts.map +1 -1
- package/dist/foreground/ladder.js +131 -33
- package/dist/foreground/ladder.js.map +1 -1
- package/dist/foreground/types.d.ts +15 -0
- package/dist/foreground/types.d.ts.map +1 -1
- package/dist/foreground/types.js.map +1 -1
- package/dist/foreground/windows-helper-script.d.ts.map +1 -1
- package/dist/foreground/windows-helper-script.js +8 -1
- package/dist/foreground/windows-helper-script.js.map +1 -1
- package/dist/foreground/windows-monitor.d.ts +33 -1
- package/dist/foreground/windows-monitor.d.ts.map +1 -1
- package/dist/foreground/windows-monitor.js +129 -6
- package/dist/foreground/windows-monitor.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/cua-driver/adapter.ts +12 -4
- package/src/foreground/guard.ts +3 -3
- package/src/foreground/ladder.ts +128 -27
- package/src/foreground/types.ts +15 -0
- package/src/foreground/windows-helper-script.ts +8 -1
- package/src/foreground/windows-monitor.ts +150 -7
|
@@ -1,6 +1,87 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
3
|
import { WINDOWS_HELPER_SCRIPT } from './windows-helper-script.js';
|
|
4
|
+
/** Most of the helper's error stream that is kept. */
|
|
5
|
+
const STDERR_KEEP = 2_048;
|
|
6
|
+
/** How long after the process ends its streams get to close before the exit is reported anyway, ms. */
|
|
7
|
+
const EXIT_GRACE_MS = 500;
|
|
8
|
+
/** Longest cause line put in a reason. */
|
|
9
|
+
const CAUSE_MAX = 200;
|
|
10
|
+
function xmlText(text) {
|
|
11
|
+
return text
|
|
12
|
+
.replace(/_x([0-9A-Fa-f]{4})_/g, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)))
|
|
13
|
+
.replace(/</g, '<')
|
|
14
|
+
.replace(/>/g, '>')
|
|
15
|
+
.replace(/"/g, '"')
|
|
16
|
+
.replace(/'/g, "'")
|
|
17
|
+
.replace(/&/g, '&');
|
|
18
|
+
}
|
|
19
|
+
/** Lines of a PowerShell error record that are location and category detail, not the message. */
|
|
20
|
+
function isRecordDetail(line) {
|
|
21
|
+
return line.startsWith('+ ') || line.startsWith('At line:');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What the helper wrote to its error stream, reduced to its cause, or
|
|
25
|
+
* undefined. PowerShell wraps non-interactive output in a CLIXML envelope; its
|
|
26
|
+
* progress records ("Preparing modules for first use") are noise, its error
|
|
27
|
+
* records are the cause. The kept tail may begin in the middle of the envelope,
|
|
28
|
+
* so a fragment of it counts as CLIXML too. Of an error record the message
|
|
29
|
+
* (its first line) is reported, not the `+ CategoryInfo` lines after it.
|
|
30
|
+
*/
|
|
31
|
+
export function stderrCause(stderr) {
|
|
32
|
+
if (!stderr)
|
|
33
|
+
return undefined;
|
|
34
|
+
let text = stderr;
|
|
35
|
+
let clixml = false;
|
|
36
|
+
if (/CLIXML|<Objs[\s>]|<\/Objs>|<Obj |S="progress"/.test(text)) {
|
|
37
|
+
const errors = [];
|
|
38
|
+
for (const match of text.matchAll(/<S S="Error">([\s\S]*?)<\/S>/g))
|
|
39
|
+
errors.push(xmlText(match[1] ?? ''));
|
|
40
|
+
// What is outside the error records is progress; none of it is a cause.
|
|
41
|
+
text = errors.join('');
|
|
42
|
+
clixml = true;
|
|
43
|
+
}
|
|
44
|
+
const lines = text
|
|
45
|
+
.split(/\r?\n/)
|
|
46
|
+
.map((line) => line.trim())
|
|
47
|
+
.filter((line) => line && !line.startsWith('<'));
|
|
48
|
+
let cause;
|
|
49
|
+
if (!clixml) {
|
|
50
|
+
cause = lines.filter((line) => !isRecordDetail(line)).pop();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
cause = lastRecordMessage(lines);
|
|
54
|
+
}
|
|
55
|
+
if (!cause)
|
|
56
|
+
return undefined;
|
|
57
|
+
return cause.length > CAUSE_MAX ? `${cause.slice(0, CAUSE_MAX - 1)}…` : cause;
|
|
58
|
+
}
|
|
59
|
+
/** An error record ends at its FullyQualifiedErrorId line; the message of the last one. */
|
|
60
|
+
function lastRecordMessage(lines) {
|
|
61
|
+
const records = [[]];
|
|
62
|
+
for (const line of lines) {
|
|
63
|
+
const current = records[records.length - 1];
|
|
64
|
+
if (!isRecordDetail(line))
|
|
65
|
+
current.push(line);
|
|
66
|
+
if (line.startsWith('+ FullyQualifiedErrorId'))
|
|
67
|
+
records.push([]);
|
|
68
|
+
}
|
|
69
|
+
return [...records].reverse().find((r) => r.length > 0)?.[0];
|
|
70
|
+
}
|
|
71
|
+
/** Why the helper is gone, in words the model can pass on. */
|
|
72
|
+
export function describeHelperExit(info, greeted) {
|
|
73
|
+
if (!info)
|
|
74
|
+
return 'the Windows helper exited';
|
|
75
|
+
if (info.spawnError)
|
|
76
|
+
return `could not start Windows PowerShell (${info.spawnError.message})`;
|
|
77
|
+
const how = info.code !== null && info.code !== undefined
|
|
78
|
+
? `exit code ${info.code}`
|
|
79
|
+
: info.signal
|
|
80
|
+
? `signal ${info.signal}`
|
|
81
|
+
: undefined;
|
|
82
|
+
const cause = stderrCause(info.stderr);
|
|
83
|
+
return `${greeted ? 'the Windows helper stopped' : 'the Windows helper stopped while starting'}${how ? ` (${how})` : ''}${cause ? `: ${cause}` : ''}`;
|
|
84
|
+
}
|
|
4
85
|
/**
|
|
5
86
|
* What PowerShell is started with: a bootstrap that reads the helper script
|
|
6
87
|
* from the first line of its input (UTF-8, base64) and runs it, so the script
|
|
@@ -24,7 +105,14 @@ function spawnPowerShell(options) {
|
|
|
24
105
|
'Bypass',
|
|
25
106
|
'-EncodedCommand',
|
|
26
107
|
encodeHelperCommand(),
|
|
27
|
-
], { env: options.env, stdio: ['pipe', 'pipe', '
|
|
108
|
+
], { env: options.env, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true });
|
|
109
|
+
// Only the tail is kept, and the stream is always drained so a chatty helper cannot block.
|
|
110
|
+
let stderr = '';
|
|
111
|
+
child.stderr.setEncoding('utf8');
|
|
112
|
+
child.stderr.on('data', (chunk) => {
|
|
113
|
+
stderr = (stderr + chunk).slice(-STDERR_KEEP);
|
|
114
|
+
});
|
|
115
|
+
child.stderr.on('error', () => undefined);
|
|
28
116
|
// Without a listener a helper that exits first turns a write into an uncaught error.
|
|
29
117
|
child.stdin.on('error', () => undefined);
|
|
30
118
|
child.stdin.write(`${helperScriptLine()}\n`);
|
|
@@ -34,8 +122,24 @@ function spawnPowerShell(options) {
|
|
|
34
122
|
},
|
|
35
123
|
onLine: (handler) => createInterface({ input: child.stdout }).on('line', handler),
|
|
36
124
|
onExit: (handler) => {
|
|
125
|
+
let done = false;
|
|
126
|
+
const finish = (info) => {
|
|
127
|
+
if (done)
|
|
128
|
+
return;
|
|
129
|
+
done = true;
|
|
130
|
+
handler(info);
|
|
131
|
+
};
|
|
132
|
+
// `close` follows the end of the error stream, so its tail is complete.
|
|
133
|
+
child.once('close', (code, signal) => finish({ code, signal, stderr }));
|
|
134
|
+
// A grandchild holding the pipes can keep `close` from coming: after the
|
|
135
|
+
// process has ended, what was read so far is the answer.
|
|
136
|
+
child.once('exit', (code, signal) => {
|
|
137
|
+
setTimeout(() => finish({ code, signal, stderr }), EXIT_GRACE_MS).unref();
|
|
138
|
+
});
|
|
139
|
+
child.once('error', (spawnError) => finish({ spawnError, stderr }));
|
|
140
|
+
},
|
|
141
|
+
onEnded: (handler) => {
|
|
37
142
|
child.once('exit', handler);
|
|
38
|
-
child.once('error', handler);
|
|
39
143
|
},
|
|
40
144
|
kill: () => {
|
|
41
145
|
try {
|
|
@@ -60,6 +164,13 @@ export class WindowsInputMonitor {
|
|
|
60
164
|
nextId = 1;
|
|
61
165
|
waiting = [];
|
|
62
166
|
exited = false;
|
|
167
|
+
exitReason;
|
|
168
|
+
/** The helper has sent its first line. */
|
|
169
|
+
greeted = false;
|
|
170
|
+
/** The helper process is started and has not ended. */
|
|
171
|
+
get running() {
|
|
172
|
+
return this.proc !== undefined && !this.exited;
|
|
173
|
+
}
|
|
63
174
|
constructor(options) {
|
|
64
175
|
this.options = options;
|
|
65
176
|
}
|
|
@@ -69,17 +180,27 @@ export class WindowsInputMonitor {
|
|
|
69
180
|
const proc = (this.options.spawnHelper ?? (() => spawnPowerShell(this.options)))(WINDOWS_HELPER_SCRIPT);
|
|
70
181
|
this.proc = proc;
|
|
71
182
|
proc.onLine((line) => this.onLine(line));
|
|
72
|
-
|
|
183
|
+
// Not running from the moment the process ends; the reason follows when its streams close.
|
|
184
|
+
proc.onEnded?.(() => {
|
|
185
|
+
this.exited = true;
|
|
186
|
+
});
|
|
187
|
+
proc.onExit((info) => {
|
|
73
188
|
this.exited = true;
|
|
189
|
+
const reason = describeHelperExit(info, this.greeted);
|
|
190
|
+
if (info)
|
|
191
|
+
this.exitReason = reason;
|
|
74
192
|
for (const waiter of this.waiting.splice(0)) {
|
|
75
193
|
clearTimeout(waiter.timer);
|
|
76
|
-
waiter.resolve({ ok: false, error:
|
|
194
|
+
waiter.resolve({ ok: false, error: reason });
|
|
77
195
|
}
|
|
78
196
|
});
|
|
79
197
|
const hello = await this.expect(this.options.startTimeoutMs ?? 60_000);
|
|
80
198
|
if (!hello.ok || hello.hooks !== true) {
|
|
81
199
|
await this.dispose();
|
|
82
|
-
|
|
200
|
+
const why = hello.hookError || hello.error || 'the keyboard and mouse hooks did not start';
|
|
201
|
+
throw new Error(hello.languageMode && hello.languageMode !== 'FullLanguage'
|
|
202
|
+
? `${why} (PowerShell language mode: ${hello.languageMode})`
|
|
203
|
+
: why);
|
|
83
204
|
}
|
|
84
205
|
}
|
|
85
206
|
state(query = {}) {
|
|
@@ -176,6 +297,8 @@ export class WindowsInputMonitor {
|
|
|
176
297
|
});
|
|
177
298
|
return;
|
|
178
299
|
}
|
|
300
|
+
if (reply.id == null)
|
|
301
|
+
this.greeted = true;
|
|
179
302
|
// A reply to a request that already timed out must not answer the next one.
|
|
180
303
|
const index = reply.id == null ? 0 : this.waiting.findIndex((w) => w.id === reply.id);
|
|
181
304
|
if (index < 0)
|
|
@@ -203,7 +326,7 @@ export class WindowsInputMonitor {
|
|
|
203
326
|
async call(command) {
|
|
204
327
|
const proc = this.proc;
|
|
205
328
|
if (!proc || this.exited)
|
|
206
|
-
throw new Error('the Windows helper is not running');
|
|
329
|
+
throw new Error(this.exitReason ?? 'the Windows helper is not running');
|
|
207
330
|
const id = this.nextId++;
|
|
208
331
|
const reply = this.expect(this.options.requestTimeoutMs ?? 10_000, id);
|
|
209
332
|
proc.write(JSON.stringify({ ...command, id }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windows-monitor.js","sourceRoot":"","sources":["../../src/foreground/windows-monitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAY/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAkClE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC5B,kHAAkH,CAAA;AAEnH,gEAAgE;AAChE,MAAM,UAAU,mBAAmB,CAAC,SAAiB,gBAAgB;IACpE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AACzD,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,gBAAgB,CAAC,SAAiB,qBAAqB;IACtE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC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AG,IAAI,CAAC,MAAM,EAAE,CAAA;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,IAAI,MAAM,EAAE,EAAE,CAAC,CAAA;QACtE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;QAC9C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAA;QAC1B,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,2BAA2B,CAAC,CAAA;QAC5E,OAAO,MAAM,CAAC,CAAM,CAAA;IACrB,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/computer-use",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Subprocess-based computer-use host for @namzu/sdk. Screenshot, mouse, and keyboard control via platform-native CLIs (screencapture/osascript on darwin, xdotool/maim on Linux X11, grim/wtype/ydotool on Wayland, PowerShell on Windows).",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"engines": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/node": "^22.19.17",
|
|
54
54
|
"typescript": "^5.5.0",
|
|
55
55
|
"vitest": "^4.1.11",
|
|
56
|
-
"@namzu/sdk": "^
|
|
56
|
+
"@namzu/sdk": "^62.1.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsc --build",
|
|
@@ -22,7 +22,12 @@ import type {
|
|
|
22
22
|
} from '@namzu/sdk'
|
|
23
23
|
import type { A11ySeq, A11yWindow, AccessibilityBackend } from '../../a11y/interface.js'
|
|
24
24
|
import { droppedInputNote, foregroundNote, interferenceNote } from '../../foreground/guard.js'
|
|
25
|
-
import
|
|
25
|
+
import {
|
|
26
|
+
type ForegroundLadder,
|
|
27
|
+
type LadderRequest,
|
|
28
|
+
blockDetailWithRefAdvice,
|
|
29
|
+
uiActBlockDetail,
|
|
30
|
+
} from '../../foreground/ladder.js'
|
|
26
31
|
import { BurstInterrupted, type ForegroundSubject } from '../../foreground/types.js'
|
|
27
32
|
import type { Presence } from '../../presence/presence.js'
|
|
28
33
|
import { CallAbortedError, currentCallSignal, markSent } from '../../util/call-scope.js'
|
|
@@ -1227,7 +1232,7 @@ export class CuaDriverAdapter implements Adapter {
|
|
|
1227
1232
|
}
|
|
1228
1233
|
if (outcome.kind === 'blocked') {
|
|
1229
1234
|
route.blocked = outcome.block.code
|
|
1230
|
-
return verdict('not_delivered', 'safe', outcome.block
|
|
1235
|
+
return verdict('not_delivered', 'safe', blockDetailWithRefAdvice(outcome.block))
|
|
1231
1236
|
}
|
|
1232
1237
|
route.onScreen = true
|
|
1233
1238
|
const dropped = droppedInputNote(outcome)
|
|
@@ -1652,6 +1657,9 @@ export class CuaDriverAdapter implements Adapter {
|
|
|
1652
1657
|
const facts = resolved.entry
|
|
1653
1658
|
const { pid, token } = facts
|
|
1654
1659
|
const uiRef = { ref, facts }
|
|
1660
|
+
// The window's change marker is taken before the control is acted on, so the wait that follows
|
|
1661
|
+
// counts what this action changed rather than the quiet before it.
|
|
1662
|
+
await this.markForSettle(facts.hwnd)
|
|
1655
1663
|
this.tryPresence((presence) =>
|
|
1656
1664
|
presence.mark({
|
|
1657
1665
|
hwnd: facts.hwnd,
|
|
@@ -1825,7 +1833,7 @@ export class CuaDriverAdapter implements Adapter {
|
|
|
1825
1833
|
ok: false,
|
|
1826
1834
|
delivery: 'not_delivered',
|
|
1827
1835
|
retrySafety: 'safe',
|
|
1828
|
-
detail: `${outcome.block
|
|
1836
|
+
detail: `${uiActBlockDetail(outcome.block)} ${instead}`,
|
|
1829
1837
|
}
|
|
1830
1838
|
const dropped = droppedInputNote(outcome)
|
|
1831
1839
|
if (dropped)
|
|
@@ -2058,7 +2066,7 @@ export class CuaDriverAdapter implements Adapter {
|
|
|
2058
2066
|
ok: false,
|
|
2059
2067
|
delivery: 'not_delivered',
|
|
2060
2068
|
retrySafety: 'safe',
|
|
2061
|
-
detail: outcome.block
|
|
2069
|
+
detail: uiActBlockDetail(outcome.block),
|
|
2062
2070
|
}
|
|
2063
2071
|
const dropped = droppedInputNote(outcome)
|
|
2064
2072
|
if (dropped)
|
package/src/foreground/guard.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import type { Adapter } from '../adapters/types.js'
|
|
8
8
|
import { currentCallSignal } from '../util/call-scope.js'
|
|
9
9
|
import type { ForegroundLadder } from './ladder.js'
|
|
10
|
-
import { STOPPED_TEXT } from './ladder.js'
|
|
10
|
+
import { STOPPED_TEXT, blockDetailWithRefAdvice } from './ladder.js'
|
|
11
11
|
import type { ForegroundOutcome, ForegroundSubject } from './types.js'
|
|
12
12
|
|
|
13
13
|
/** Display actions that put input on the user's screen. */
|
|
@@ -98,7 +98,7 @@ export function guardForeground(adapter: Adapter, ladder: ForegroundLadder): Ada
|
|
|
98
98
|
type: 'ok',
|
|
99
99
|
delivery: 'not_delivered',
|
|
100
100
|
retrySafety: 'safe',
|
|
101
|
-
detail: outcome.block
|
|
101
|
+
detail: blockDetailWithRefAdvice(outcome.block),
|
|
102
102
|
}
|
|
103
103
|
const dropped = droppedInputNote(outcome)
|
|
104
104
|
if (dropped)
|
|
@@ -150,7 +150,7 @@ export function guardForeground(adapter: Adapter, ladder: ForegroundLadder): Ada
|
|
|
150
150
|
focusedId: null,
|
|
151
151
|
delivery: 'not_delivered',
|
|
152
152
|
retrySafety: 'safe',
|
|
153
|
-
detail: outcome.block
|
|
153
|
+
detail: blockDetailWithRefAdvice(outcome.block),
|
|
154
154
|
}
|
|
155
155
|
const note = interferenceNote(outcome)
|
|
156
156
|
return note ? { ...outcome.value, detail: note } : outcome.value
|
package/src/foreground/ladder.ts
CHANGED
|
@@ -101,6 +101,23 @@ export interface ForegroundLadderOptions {
|
|
|
101
101
|
export const STOPPED_TEXT =
|
|
102
102
|
'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.'
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* A block's detail for a caller where controls by ref (ui_act) are a real
|
|
106
|
+
* alternative to the screen (display actions, window actions): the helper
|
|
107
|
+
* being down does not touch them, so it says so.
|
|
108
|
+
*/
|
|
109
|
+
export function blockDetailWithRefAdvice(block: ForegroundBlock): string {
|
|
110
|
+
return block.code === 'monitor_unavailable'
|
|
111
|
+
? `${block.detail} Controls by ref (ui_act) still work in the background.`
|
|
112
|
+
: block.detail
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A block's detail for ui_act's own fallbacks to the screen: the model must not be sent back into ui_act. */
|
|
116
|
+
export function uiActBlockDetail(block: ForegroundBlock): string {
|
|
117
|
+
if (block.code !== 'monitor_unavailable') return block.detail
|
|
118
|
+
return `The control could not be pressed in the background, and the screen could not be used because this computer cannot watch for the user's keyboard and mouse (${block.reason ?? 'the helper is not available'}). Nothing was sent. Try another control, or ask the user to do this step.`
|
|
119
|
+
}
|
|
120
|
+
|
|
104
121
|
const seconds = (ms: number): string => `${Math.max(1, Math.round(ms / 1000))} s`
|
|
105
122
|
|
|
106
123
|
const BLOCKS = {
|
|
@@ -127,7 +144,8 @@ const BLOCKS = {
|
|
|
127
144
|
}),
|
|
128
145
|
monitor_unavailable: (reason: string): ForegroundBlock => ({
|
|
129
146
|
code: 'monitor_unavailable',
|
|
130
|
-
detail: `This computer cannot watch for the user's keyboard and mouse (${reason}), so the screen is not used and nothing was sent.
|
|
147
|
+
detail: `This computer cannot watch for the user's keyboard and mouse (${reason}), so the screen is not used and nothing was sent. Ask the user to do this step if it needs the screen.`,
|
|
148
|
+
reason,
|
|
131
149
|
}),
|
|
132
150
|
declined: (app: string): ForegroundBlock => ({
|
|
133
151
|
code: 'declined',
|
|
@@ -147,6 +165,25 @@ const BLOCKS = {
|
|
|
147
165
|
/** Times a burst start is retried because input arrived between the last look and the start. */
|
|
148
166
|
const MAX_INTERFERED_STARTS = 3
|
|
149
167
|
|
|
168
|
+
/** What the monitor says when a request or the start gets no answer. */
|
|
169
|
+
const NO_ANSWER = 'did not answer in time'
|
|
170
|
+
|
|
171
|
+
function isNoAnswer(error: unknown): boolean {
|
|
172
|
+
return error instanceof Error && error.message.includes(NO_ANSWER)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* A call made before anything was sent failed because the helper is gone or
|
|
177
|
+
* hung, so it can be replaced and the run repeated. An error the helper
|
|
178
|
+
* reports about one command while it runs is not this.
|
|
179
|
+
*/
|
|
180
|
+
function helperGone(monitor: ForegroundMonitor, error: unknown): boolean {
|
|
181
|
+
return monitor.running === false || isNoAnswer(error)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The helper ended while a burst was sending; said to the caller as the burst's failure. */
|
|
185
|
+
export const HELPER_STOPPED_MID_BURST = 'the keyboard-and-mouse helper stopped during the action'
|
|
186
|
+
|
|
150
187
|
interface Stop {
|
|
151
188
|
readonly turnId: string | undefined
|
|
152
189
|
}
|
|
@@ -196,6 +233,10 @@ export class ForegroundLadder {
|
|
|
196
233
|
private turn: string | undefined
|
|
197
234
|
private readonly allowed = new Set<string>()
|
|
198
235
|
private readonly denied = new Set<string>()
|
|
236
|
+
/** Programs the user could not be asked about this turn; they are not asked again. */
|
|
237
|
+
private readonly unanswered = new Set<string>()
|
|
238
|
+
/** Why the helper could not be started twice in a row; answered until the turn ends. */
|
|
239
|
+
private startFailure: string | undefined
|
|
199
240
|
|
|
200
241
|
constructor(private readonly options: ForegroundLadderOptions) {
|
|
201
242
|
this.timing = { ...DEFAULT_TIMING, ...options.timing }
|
|
@@ -224,6 +265,8 @@ export class ForegroundLadder {
|
|
|
224
265
|
if (this.stop && (turnId === undefined || turnId !== this.stop.turnId)) this.stop = undefined
|
|
225
266
|
if (turnId === undefined || turnId !== this.turn) {
|
|
226
267
|
this.denied.clear()
|
|
268
|
+
this.unanswered.clear()
|
|
269
|
+
this.startFailure = undefined
|
|
227
270
|
this.parkedMs = 0
|
|
228
271
|
}
|
|
229
272
|
this.turn = turnId
|
|
@@ -305,9 +348,12 @@ export class ForegroundLadder {
|
|
|
305
348
|
/** The model's turn ended or was interrupted: nothing stays watched or held. */
|
|
306
349
|
async endTurn(): Promise<void> {
|
|
307
350
|
this.denied.clear()
|
|
351
|
+
this.unanswered.clear()
|
|
308
352
|
// A burst in flight puts its window and cursor back through the monitor
|
|
309
353
|
// when it ends; dropping the monitor first would restore under it.
|
|
310
354
|
await this.queue
|
|
355
|
+
// After the wait: a queued run that finished meanwhile may have set it.
|
|
356
|
+
this.startFailure = undefined
|
|
311
357
|
await this.dropMonitor()
|
|
312
358
|
}
|
|
313
359
|
|
|
@@ -330,6 +376,7 @@ export class ForegroundLadder {
|
|
|
330
376
|
request: LadderRequest,
|
|
331
377
|
burst: (context: BurstContext) => Promise<T>,
|
|
332
378
|
attempt = 0,
|
|
379
|
+
restarted = false,
|
|
333
380
|
): Promise<ForegroundOutcome<T>> {
|
|
334
381
|
const { subject, signal } = request
|
|
335
382
|
if (this.stop) return { kind: 'blocked', block: BLOCKS.stopped() }
|
|
@@ -349,17 +396,44 @@ export class ForegroundLadder {
|
|
|
349
396
|
}
|
|
350
397
|
let deferred = false
|
|
351
398
|
try {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
399
|
+
let state: Awaited<ReturnType<ForegroundLadder['gate']>>
|
|
400
|
+
let begun: Awaited<ReturnType<ForegroundMonitor['begin']>>
|
|
401
|
+
let startedAt: number
|
|
402
|
+
let beginSent = false
|
|
403
|
+
try {
|
|
404
|
+
state = await this.gate(monitor.monitor, subject, signal)
|
|
405
|
+
if ('block' in state) return { kind: 'blocked', block: state.block }
|
|
406
|
+
startedAt = this.clock.now()
|
|
407
|
+
beginSent = true
|
|
408
|
+
begun = await monitor.monitor.begin({
|
|
409
|
+
leasePath: this.lease.path,
|
|
410
|
+
token,
|
|
411
|
+
// Checked by the monitor before it raises anything, so a person who
|
|
412
|
+
// started typing after the last look is not displaced.
|
|
413
|
+
idleMs: state.needed,
|
|
414
|
+
...(subject.hwnd !== undefined ? { raise: subject.hwnd } : {}),
|
|
415
|
+
})
|
|
416
|
+
} catch (error) {
|
|
417
|
+
if (error instanceof CallAbortedError) throw error
|
|
418
|
+
const gone = helperGone(monitor.monitor, error)
|
|
419
|
+
// A helper that is still answering may have raised the target window
|
|
420
|
+
// before it failed: put it back, as an interfered start does.
|
|
421
|
+
if (beginSent && !gone) await monitor.monitor.end({ restore: true }).catch(() => undefined)
|
|
422
|
+
// An error the live helper reported about this command is the caller's.
|
|
423
|
+
if (!gone) throw error
|
|
424
|
+
// Nothing has been sent yet: a helper that died or hung here is replaced,
|
|
425
|
+
// once, and the run goes again. A second failure is a block, never a throw.
|
|
426
|
+
await this.dropMonitor()
|
|
427
|
+
if (restarted)
|
|
428
|
+
return {
|
|
429
|
+
kind: 'blocked',
|
|
430
|
+
block: BLOCKS.monitor_unavailable(
|
|
431
|
+
error instanceof Error ? error.message : String(error),
|
|
432
|
+
),
|
|
433
|
+
}
|
|
434
|
+
this.lease.release(token)
|
|
435
|
+
return await this.runOne(request, burst, attempt, true)
|
|
436
|
+
}
|
|
363
437
|
// A person touched input between the last look and now: not yet.
|
|
364
438
|
if (begun.refused === true || begun.userInputs !== state.state.userInputs) {
|
|
365
439
|
if (attempt >= MAX_INTERFERED_STARTS) {
|
|
@@ -375,6 +449,7 @@ export class ForegroundLadder {
|
|
|
375
449
|
burst,
|
|
376
450
|
token,
|
|
377
451
|
attempt + 1,
|
|
452
|
+
restarted,
|
|
378
453
|
)
|
|
379
454
|
}
|
|
380
455
|
const beat = setInterval(
|
|
@@ -388,7 +463,11 @@ export class ForegroundLadder {
|
|
|
388
463
|
value = await burst({
|
|
389
464
|
checkpoint: async () => {
|
|
390
465
|
if (!this.lease.heartbeat(token)) throw new BurstInterrupted()
|
|
391
|
-
const now = await monitor.monitor.state()
|
|
466
|
+
const now = await monitor.monitor.state().catch((error: unknown) => {
|
|
467
|
+
// A helper that ended mid-burst is never restarted inside it: the burst stops here.
|
|
468
|
+
if (monitor.monitor.running === false) throw new Error(HELPER_STOPPED_MID_BURST)
|
|
469
|
+
throw error
|
|
470
|
+
})
|
|
392
471
|
if (now.userInputs !== begun.userInputs) throw new BurstInterrupted()
|
|
393
472
|
// The hooks see nothing typed into a window above this program's rights,
|
|
394
473
|
// so a person there cannot be told from silence: stop rather than guess.
|
|
@@ -405,7 +484,13 @@ export class ForegroundLadder {
|
|
|
405
484
|
},
|
|
406
485
|
})
|
|
407
486
|
} catch (error) {
|
|
408
|
-
failure
|
|
487
|
+
// A helper that ended during the burst's own calls is the burst's failure, in the same words.
|
|
488
|
+
failure = {
|
|
489
|
+
error:
|
|
490
|
+
monitor.monitor.running === false && !(error instanceof BurstInterrupted)
|
|
491
|
+
? new Error(HELPER_STOPPED_MID_BURST)
|
|
492
|
+
: error,
|
|
493
|
+
}
|
|
409
494
|
} finally {
|
|
410
495
|
clearInterval(beat)
|
|
411
496
|
}
|
|
@@ -485,30 +570,42 @@ export class ForegroundLadder {
|
|
|
485
570
|
burst: (context: BurstContext) => Promise<T>,
|
|
486
571
|
token: string,
|
|
487
572
|
attempt: number,
|
|
573
|
+
restarted: boolean,
|
|
488
574
|
): Promise<ForegroundOutcome<T>> {
|
|
489
575
|
// A raise that happened just before a person's input is undone too.
|
|
490
576
|
await monitor.end({ restore: true }).catch(() => undefined)
|
|
491
577
|
// The lease is ours until runOne's finally; release it so the nested run takes it afresh.
|
|
492
578
|
this.lease.release(token)
|
|
493
|
-
return this.runOne(request, burst, attempt)
|
|
579
|
+
return this.runOne(request, burst, attempt, restarted)
|
|
494
580
|
}
|
|
495
581
|
|
|
496
582
|
private async ensureMonitor(): Promise<
|
|
497
583
|
{ readonly ok: true; readonly monitor: ForegroundMonitor } | { ok: false; reason: string }
|
|
498
584
|
> {
|
|
499
|
-
if (this.monitor)
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
await
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
585
|
+
if (this.monitor) {
|
|
586
|
+
if (this.monitor.running !== false) return { ok: true, monitor: this.monitor }
|
|
587
|
+
// The helper ended since it was last used: it is replaced, not reported.
|
|
588
|
+
await this.dropMonitor()
|
|
589
|
+
}
|
|
590
|
+
if (this.startFailure !== undefined) return { ok: false, reason: this.startFailure }
|
|
591
|
+
let reason = ''
|
|
592
|
+
// A transient spawn or pipe failure gets one more try before it costs the user the action.
|
|
593
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
594
|
+
const monitor = this.options.createMonitor()
|
|
595
|
+
try {
|
|
596
|
+
await monitor.start()
|
|
597
|
+
} catch (error) {
|
|
598
|
+
await monitor.dispose().catch(() => undefined)
|
|
599
|
+
reason = error instanceof Error ? error.message : String(error)
|
|
600
|
+
// A start that waited out its whole timeout is not tried again: that would wait twice as long.
|
|
601
|
+
if (isNoAnswer(error)) break
|
|
602
|
+
continue
|
|
508
603
|
}
|
|
604
|
+
this.monitor = monitor
|
|
605
|
+
return { ok: true, monitor }
|
|
509
606
|
}
|
|
510
|
-
this.
|
|
511
|
-
return { ok:
|
|
607
|
+
this.startFailure = reason
|
|
608
|
+
return { ok: false, reason }
|
|
512
609
|
}
|
|
513
610
|
|
|
514
611
|
private async dropMonitor(): Promise<void> {
|
|
@@ -567,7 +664,11 @@ export class ForegroundLadder {
|
|
|
567
664
|
) {
|
|
568
665
|
if (phase === 'gate' && !signal?.aborted) {
|
|
569
666
|
if (this.denied.has(key)) return { block: BLOCKS.declined(who.app) }
|
|
570
|
-
|
|
667
|
+
// A run repeated with a fresh helper does not put the question again.
|
|
668
|
+
const answer = this.unanswered.has(key)
|
|
669
|
+
? 'unavailable'
|
|
670
|
+
: ((await this.options.approve?.(who, signal)) ?? 'unavailable')
|
|
671
|
+
if (answer === 'unavailable') this.unanswered.add(key)
|
|
571
672
|
if (answer === 'deny') {
|
|
572
673
|
this.denied.add(key)
|
|
573
674
|
return { block: BLOCKS.declined(who.app) }
|
package/src/foreground/types.ts
CHANGED
|
@@ -181,6 +181,15 @@ export interface MenuCommandResult {
|
|
|
181
181
|
export interface ForegroundMonitor {
|
|
182
182
|
/** Starts watching. Rejects when real input cannot be observed: the burst is then refused. */
|
|
183
183
|
start(): Promise<void>
|
|
184
|
+
/**
|
|
185
|
+
* False once a started monitor can no longer answer (the helper process
|
|
186
|
+
* ended). The ladder then replaces it before its next use. Optional: a
|
|
187
|
+
* monitor that leaves it out is taken to keep running.
|
|
188
|
+
*
|
|
189
|
+
* A helper that ends in the middle of a burst cannot put the window and
|
|
190
|
+
* cursor back: the burst fails with a clear error and is never restarted.
|
|
191
|
+
*/
|
|
192
|
+
readonly running?: boolean
|
|
184
193
|
state(query?: { readonly pid?: number }): Promise<MonitorState>
|
|
185
194
|
/**
|
|
186
195
|
* A burst is about to start. The monitor remembers the window in front, the
|
|
@@ -249,6 +258,12 @@ export interface ForegroundBlock {
|
|
|
249
258
|
readonly code: ForegroundBlockCode
|
|
250
259
|
/** In words the model can act on: what is blocking, and what to do next. */
|
|
251
260
|
readonly detail: string
|
|
261
|
+
/**
|
|
262
|
+
* For `monitor_unavailable`: the bare cause ("the Windows helper stopped
|
|
263
|
+
* while starting (exit code 1): ..."), for a caller that words the advice
|
|
264
|
+
* itself.
|
|
265
|
+
*/
|
|
266
|
+
readonly reason?: string
|
|
252
267
|
}
|
|
253
268
|
|
|
254
269
|
export type ForegroundOutcome<T> =
|
|
@@ -19,6 +19,12 @@ export const WINDOWS_HELPER_SCRIPT = String.raw`
|
|
|
19
19
|
$ErrorActionPreference = 'Stop'
|
|
20
20
|
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
21
21
|
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
22
|
+
function NzFail($what, $e) {
|
|
23
|
+
$o = @{ ok = $false; hooks = $false; hookError = ('{0}: {1}' -f $what, $e.Exception.Message); languageMode = [string]$ExecutionContext.SessionState.LanguageMode }
|
|
24
|
+
[Console]::Out.WriteLine((ConvertTo-Json -InputObject $o -Compress))
|
|
25
|
+
exit 1
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
22
28
|
Add-Type -TypeDefinition @"
|
|
23
29
|
using System; using System.Text; using System.Threading; using System.Runtime.InteropServices;
|
|
24
30
|
public static class NzG {
|
|
@@ -301,7 +307,8 @@ public static class NzG {
|
|
|
301
307
|
}
|
|
302
308
|
}
|
|
303
309
|
"@
|
|
304
|
-
$
|
|
310
|
+
} catch { NzFail 'the hook library did not compile' $_ }
|
|
311
|
+
try { $hooks = [NzG]::StartHooks() } catch { NzFail 'the hooks did not start' $_ }
|
|
305
312
|
$selfIntegrity = [NzG]::SelfIntegrity()
|
|
306
313
|
$selfElevated = ($selfIntegrity -ge 12288)
|
|
307
314
|
$ownStart = 0; $ownEnd = 0
|