@namzu/computer-use 1.2.0 → 1.4.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 +26 -0
- package/README.md +21 -3
- package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
- package/dist/SubprocessComputerUseHost.js +24 -1
- package/dist/SubprocessComputerUseHost.js.map +1 -1
- package/dist/adapters/win32.d.ts +1 -0
- package/dist/adapters/win32.d.ts.map +1 -1
- package/dist/adapters/win32.js +25 -28
- package/dist/adapters/win32.js.map +1 -1
- package/dist/detect/index.d.ts.map +1 -1
- package/dist/detect/index.js +9 -0
- package/dist/detect/index.js.map +1 -1
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/SubprocessComputerUseHost.ts +24 -1
- package/src/adapters/win32.ts +24 -36
- package/src/detect/index.ts +9 -0
- package/src/errors.ts +27 -0
- package/src/index.ts +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 354b7a1: Ship and mount desktop computer use in the interactive CLI when its adapter
|
|
8
|
+
initializes, with the host lifetime owned by the agent session and no exposure
|
|
9
|
+
on unattended surfaces. WSL now targets the paired Windows desktop through
|
|
10
|
+
`powershell.exe` instead of misclassifying WSLg as a Linux compositor session.
|
|
11
|
+
- 5854b4d: Expose a stable computer-use unknown-outcome contract and preserve it in tool results. A host can now report that a desktop action started without proving its final state, and models receive explicit unsafe-to-retry guidance plus structured action, timeout, and exit evidence.
|
|
12
|
+
|
|
13
|
+
Classify subprocess failures after click, drag, scroll, text-entry, and key actions as unknown outcomes. Consumers can catch `ComputerUseOutcomeUnknownError`; ordinary read failures, idempotent pointer moves, and process-start failures keep their existing error behavior.
|
|
14
|
+
|
|
15
|
+
## 1.3.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- bb8cb05: Export the 45 types that exported signatures already named.
|
|
20
|
+
|
|
21
|
+
Each is the parameter or the result of a function that was already public, and none of them was reachable. A consumer could call `createLogger` and had no name for its options or its return; could call `compactRegion`, `runBidi`, the handoff helpers, the replay helpers, and had to inline every shape or reach for `any`. The package's vocabulary stopped at the function name.
|
|
22
|
+
|
|
23
|
+
Additive: the original 28 function-signature types plus constructor contracts including `AgentManagerDeps`, `TopicManagerDeps`, `ProjectManagerDeps`, `DiskTopicStateStoreConfig`, `DiskMessageFeedbackStoreConfig`, `MessageExistenceCheck`, `EnvCredentialProviderOptions`, `FileLockManagerConfig`, `GitWorktreeDriverConfig`, `CapacityDimension`, `HandoffLockRejectedReason`, `SessionSummaryMaterializerDeps`, `ArchivalManagerDeps`, `ArchiveBackendRef`, `DiskArchiveBackendConfig`, `SlidingWindowManagerConfig`, and `SubprocessComputerUseHostOptions`.
|
|
24
|
+
|
|
25
|
+
Nothing changes for existing code.
|
|
26
|
+
|
|
27
|
+
A CI step keeps it that way. `check-signature-types-exported.mjs` resolves exported function signatures and public class constructors, then fails when a type they name is declared in the package and not exported. The constructor branch has its own self-check so removing it cannot turn the gate silently green.
|
|
28
|
+
|
|
3
29
|
## 1.2.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ description: >-
|
|
|
6
6
|
Which backend serves a call depends on the platform, and what a platform
|
|
7
7
|
cannot do is reported as a capability rather than discovered as a failure.
|
|
8
8
|
tags: [readme, package, computer-use, adapters]
|
|
9
|
-
timestamp: 2026-08-
|
|
9
|
+
timestamp: 2026-08-20T00:00:00Z
|
|
10
10
|
status: active
|
|
11
11
|
diataxis: reference
|
|
12
12
|
-->
|
|
@@ -42,10 +42,17 @@ pnpm add @namzu/sdk @namzu/computer-use
|
|
|
42
42
|
## Usage
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
SubprocessComputerUseHost,
|
|
47
|
+
type SubprocessComputerUseHostOptions,
|
|
48
|
+
} from '@namzu/computer-use'
|
|
46
49
|
import { createComputerUseTool, ToolRegistry } from '@namzu/sdk'
|
|
47
50
|
|
|
48
|
-
const
|
|
51
|
+
const options: SubprocessComputerUseHostOptions = {
|
|
52
|
+
env: process.env,
|
|
53
|
+
platform: process.platform,
|
|
54
|
+
}
|
|
55
|
+
const host = new SubprocessComputerUseHost(options)
|
|
49
56
|
await host.initialize()
|
|
50
57
|
|
|
51
58
|
console.log(host.capabilities)
|
|
@@ -62,6 +69,17 @@ const registry = new ToolRegistry()
|
|
|
62
69
|
registry.register(createComputerUseTool(host))
|
|
63
70
|
```
|
|
64
71
|
|
|
72
|
+
If a click, drag, scroll, text entry or key subprocess starts but does not
|
|
73
|
+
report a clean completion, the host throws
|
|
74
|
+
`ComputerUseOutcomeUnknownError`. The desktop may already have changed; the
|
|
75
|
+
SDK returns that state to the model with `retrySafety: 'unsafe'` instead of
|
|
76
|
+
inviting an automatic replay.
|
|
77
|
+
|
|
78
|
+
When Namzu runs inside WSL, the host selects the paired Windows desktop and
|
|
79
|
+
uses `powershell.exe` through WSL interop. This takes precedence over WSLg's
|
|
80
|
+
`DISPLAY`/`WAYLAND_DISPLAY`, which describe Linux GUI applications rather than
|
|
81
|
+
the Windows desktop containing the terminal.
|
|
82
|
+
|
|
65
83
|
## Documentation
|
|
66
84
|
|
|
67
85
|
- [Computer use — the platform matrix, capability flags and error surface](https://github.com/cogitave/namzu/blob/main/docs/packages/computer-use.md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubprocessComputerUseHost.d.ts","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"SubprocessComputerUseHost.d.ts","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAsBlD,MAAM,WAAW,gCAAgC;IAChD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;IACnC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,yBAA0B,YAAW,eAAe;IAChE,QAAQ,CAAC,EAAE,kCAAiC;IAC5C,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,OAAO,CAAuB;gBAE1B,OAAO,GAAE,gCAAqC;IAY1D,IAAI,YAAY,IAAI,uBAAuB,CAE1C;IAEK,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;IAK9C,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkB9D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,OAAO,CAAC,cAAc;CAQtB"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { detectDisplayServer } from './detect/index.js';
|
|
2
|
+
import { ComputerUseOutcomeUnknownError } from './errors.js';
|
|
3
|
+
import { SpawnError } from './util/spawn.js';
|
|
2
4
|
const UNINITIALISED_CAPABILITIES = {
|
|
3
5
|
displayServer: 'unknown',
|
|
4
6
|
screenshot: false,
|
|
@@ -7,6 +9,13 @@ const UNINITIALISED_CAPABILITIES = {
|
|
|
7
9
|
cursorPosition: false,
|
|
8
10
|
clipboard: false,
|
|
9
11
|
};
|
|
12
|
+
const UNSAFE_TO_REPLAY_AFTER_START = new Set([
|
|
13
|
+
'mouse_click',
|
|
14
|
+
'mouse_drag',
|
|
15
|
+
'scroll',
|
|
16
|
+
'type_text',
|
|
17
|
+
'key',
|
|
18
|
+
]);
|
|
10
19
|
/**
|
|
11
20
|
* Subprocess-backed ComputerUseHost. Delegates platform-specific work to
|
|
12
21
|
* adapters that spawn system CLIs (`screencapture`, `osascript`, `xdotool`,
|
|
@@ -50,7 +59,21 @@ export class SubprocessComputerUseHost {
|
|
|
50
59
|
}
|
|
51
60
|
async execute(action) {
|
|
52
61
|
const adapter = this.requireAdapter();
|
|
53
|
-
|
|
62
|
+
try {
|
|
63
|
+
return await adapter.execute(action);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
// SpawnError is produced only after the subprocess started and then
|
|
67
|
+
// timed out or closed non-zero. An unsafe action may have taken effect
|
|
68
|
+
// before that terminal status (a multi-command drag is the clearest
|
|
69
|
+
// example), so replaying it could duplicate or compound the change.
|
|
70
|
+
// A raw spawn error means the process never established that boundary;
|
|
71
|
+
// safe reads and idempotent mouse_move keep their ordinary diagnosis.
|
|
72
|
+
if (error instanceof SpawnError && UNSAFE_TO_REPLAY_AFTER_START.has(action.type)) {
|
|
73
|
+
throw new ComputerUseOutcomeUnknownError(action.type, error);
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
54
77
|
}
|
|
55
78
|
async dispose() {
|
|
56
79
|
this.adapter = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubprocessComputerUseHost.js","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"SubprocessComputerUseHost.js","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,0BAA0B,GAA4B;IAC3D,aAAa,EAAE,SAAS;IACxB,UAAU,EAAE,KAAK;IACjB,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,KAAK;CAChB,CAAA;AAED,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAA4B;IACvE,aAAa;IACb,YAAY;IACZ,QAAQ;IACR,WAAW;IACX,KAAK;CACL,CAAC,CAAA;AAaF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,yBAAyB;IAC5B,EAAE,GAAG,8BAA8B,CAAA;IACpC,aAAa,CAAyB;IACtC,OAAO,GAAmB,IAAI,CAAA;IAEtC,YAAY,UAA4C,EAAE;QACzD,MAAM,aAAa,GAAG,mBAAmB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;QACxE,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;YAClC,GAAG,0BAA0B;YAC7B,aAAa;SACb,CAAC,CAAA;QACF,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;YAC9B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAA;QAClD,CAAC;IACF,CAAC;IAED,IAAI,YAAY;QACf,OAAO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IACpB,CAAC;CACD;AAED,KAAK,UAAU,WAAW,CACzB,aAAuD;IAEvD,QAAQ,aAAa,EAAE,CAAC;QACvB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACf,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAA;YAC9D,OAAO,aAAa,CAAC,MAAM,EAAE,CAAA;QAC9B,CAAC;QACD,KAAK,KAAK,CAAC,CAAC,CAAC;YACZ,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAA;YACnE,OAAO,eAAe,CAAC,MAAM,EAAE,CAAA;QAChC,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YAChB,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAA;YAC3E,OAAO,mBAAmB,CAAC,MAAM,EAAE,CAAA;QACpC,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACd,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAA;YAC5D,OAAO,YAAY,CAAC,MAAM,EAAE,CAAA;QAC7B,CAAC;QACD,KAAK,SAAS;YACb,MAAM,IAAI,KAAK,CACd,sEAAsE,aAAa,OAAO,CAC1F,CAAA;IACH,CAAC;AACF,CAAC"}
|
package/dist/adapters/win32.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { runCommand } from '../util/spawn.js';
|
|
|
3
3
|
import { type Adapter } from './types.js';
|
|
4
4
|
export declare function translateKeyToSendKeys(combo: string): string;
|
|
5
5
|
export declare class Win32Adapter implements Adapter {
|
|
6
|
+
private readonly powershell;
|
|
6
7
|
readonly capabilities: ComputerUseCapabilities;
|
|
7
8
|
private constructor();
|
|
8
9
|
static create(): Promise<Win32Adapter>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/adapters/win32.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EAIf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAiB,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AAC/E,OAAO,EAAE,KAAK,OAAO,EAA2B,MAAM,YAAY,CAAA;AAoDlE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAoB5D;
|
|
1
|
+
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/adapters/win32.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EAIf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAiB,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AAC/E,OAAO,EAAE,KAAK,OAAO,EAA2B,MAAM,YAAY,CAAA;AAoDlE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAoB5D;AA0LD,qBAAa,YAAa,YAAW,OAAO;IAGvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAF/C,QAAQ,CAAC,YAAY,EAAE,uBAAuB,CAAA;IAE9C,OAAO;WAWM,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;IAWtC,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;IAU9C,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA2CpE;AAYD,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,CAAA"}
|
package/dist/adapters/win32.js
CHANGED
|
@@ -77,14 +77,8 @@ export function translateKeyToSendKeys(combo) {
|
|
|
77
77
|
// data crosses the boundary as JSON where possible.
|
|
78
78
|
// ---------------------------------------------------------------------------
|
|
79
79
|
const POWERSHELL_BASE_ARGS = ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass'];
|
|
80
|
-
async function runPowerShell(script) {
|
|
81
|
-
|
|
82
|
-
const [hasPwsh, hasPs] = await Promise.all([hasExecutable('pwsh'), hasExecutable('powershell')]);
|
|
83
|
-
const exe = hasPwsh ? 'pwsh' : hasPs ? 'powershell' : null;
|
|
84
|
-
if (!exe) {
|
|
85
|
-
throw new AdapterUnavailableError('Win32Adapter: neither pwsh nor powershell is available on PATH', ['pwsh', 'powershell']);
|
|
86
|
-
}
|
|
87
|
-
const result = await runCommandOrThrow(exe, [...POWERSHELL_BASE_ARGS, '-Command', script]);
|
|
80
|
+
async function runPowerShell(executable, script) {
|
|
81
|
+
const result = await runCommandOrThrow(executable, [...POWERSHELL_BASE_ARGS, '-Command', script]);
|
|
88
82
|
return result.stdout;
|
|
89
83
|
}
|
|
90
84
|
// ---------------------------------------------------------------------------
|
|
@@ -232,16 +226,19 @@ const MOUSE_DOWN_UP_FLAGS = {
|
|
|
232
226
|
right: ['[Namzu.User32]::MOUSEEVENTF_RIGHTDOWN', '[Namzu.User32]::MOUSEEVENTF_RIGHTUP'],
|
|
233
227
|
middle: ['[Namzu.User32]::MOUSEEVENTF_MIDDLEDOWN', '[Namzu.User32]::MOUSEEVENTF_MIDDLEUP'],
|
|
234
228
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
// Adapter
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
const POWERSHELL_CANDIDATES = ['pwsh', 'powershell', 'pwsh.exe', 'powershell.exe'];
|
|
233
|
+
async function findPowerShell() {
|
|
234
|
+
const present = await Promise.all(POWERSHELL_CANDIDATES.map((name) => hasExecutable(name)));
|
|
235
|
+
return POWERSHELL_CANDIDATES.find((_name, index) => present[index]) ?? null;
|
|
241
236
|
}
|
|
242
237
|
export class Win32Adapter {
|
|
238
|
+
powershell;
|
|
243
239
|
capabilities;
|
|
244
|
-
constructor() {
|
|
240
|
+
constructor(powershell) {
|
|
241
|
+
this.powershell = powershell;
|
|
245
242
|
this.capabilities = Object.freeze({
|
|
246
243
|
displayServer: 'win32',
|
|
247
244
|
screenshot: true,
|
|
@@ -252,21 +249,21 @@ export class Win32Adapter {
|
|
|
252
249
|
});
|
|
253
250
|
}
|
|
254
251
|
static async create() {
|
|
255
|
-
const
|
|
256
|
-
if (!
|
|
257
|
-
throw new AdapterUnavailableError('Win32Adapter: neither
|
|
252
|
+
const powershell = await findPowerShell();
|
|
253
|
+
if (!powershell) {
|
|
254
|
+
throw new AdapterUnavailableError('Win32Adapter: neither PowerShell Core nor Windows PowerShell is available on PATH', [...POWERSHELL_CANDIDATES]);
|
|
258
255
|
}
|
|
259
|
-
return new Win32Adapter();
|
|
256
|
+
return new Win32Adapter(powershell);
|
|
260
257
|
}
|
|
261
258
|
async getDisplayGeometry() {
|
|
262
|
-
const stdout = await runPowerShell(GEOMETRY_SCRIPT);
|
|
259
|
+
const stdout = await runPowerShell(this.powershell, GEOMETRY_SCRIPT);
|
|
263
260
|
const parsed = JSON.parse(stdout.toString('utf8'));
|
|
264
261
|
return { width: parsed.width, height: parsed.height, scaleFactor: parsed.scaleFactor };
|
|
265
262
|
}
|
|
266
263
|
async execute(action) {
|
|
267
264
|
switch (action.type) {
|
|
268
265
|
case 'screenshot': {
|
|
269
|
-
const data = await runPowerShell(SCREENSHOT_SCRIPT);
|
|
266
|
+
const data = await runPowerShell(this.powershell, SCREENSHOT_SCRIPT);
|
|
270
267
|
const dims = decodePngDims(data);
|
|
271
268
|
return {
|
|
272
269
|
type: 'screenshot',
|
|
@@ -279,27 +276,27 @@ export class Win32Adapter {
|
|
|
279
276
|
};
|
|
280
277
|
}
|
|
281
278
|
case 'cursor_position': {
|
|
282
|
-
const stdout = await runPowerShell(CURSOR_POSITION_SCRIPT);
|
|
279
|
+
const stdout = await runPowerShell(this.powershell, CURSOR_POSITION_SCRIPT);
|
|
283
280
|
const parsed = JSON.parse(stdout.toString('utf8'));
|
|
284
281
|
return { type: 'cursor_position', point: parsed };
|
|
285
282
|
}
|
|
286
283
|
case 'mouse_move':
|
|
287
|
-
await runPowerShell(mouseMoveScript(action.to));
|
|
284
|
+
await runPowerShell(this.powershell, mouseMoveScript(action.to));
|
|
288
285
|
return { type: 'ok' };
|
|
289
286
|
case 'mouse_click':
|
|
290
|
-
await runPowerShell(mouseClickScript(action.at, action.button));
|
|
287
|
+
await runPowerShell(this.powershell, mouseClickScript(action.at, action.button));
|
|
291
288
|
return { type: 'ok' };
|
|
292
289
|
case 'mouse_drag':
|
|
293
|
-
await runPowerShell(mouseDragScript(action.from, action.to, action.button));
|
|
290
|
+
await runPowerShell(this.powershell, mouseDragScript(action.from, action.to, action.button));
|
|
294
291
|
return { type: 'ok' };
|
|
295
292
|
case 'scroll':
|
|
296
|
-
await runPowerShell(scrollScript(action.at, action.direction, action.amount));
|
|
293
|
+
await runPowerShell(this.powershell, scrollScript(action.at, action.direction, action.amount));
|
|
297
294
|
return { type: 'ok' };
|
|
298
295
|
case 'type_text':
|
|
299
|
-
await runPowerShell(typeTextScript(action.text));
|
|
296
|
+
await runPowerShell(this.powershell, typeTextScript(action.text));
|
|
300
297
|
return { type: 'ok' };
|
|
301
298
|
case 'key':
|
|
302
|
-
await runPowerShell(pressKeyScript(action.keys));
|
|
299
|
+
await runPowerShell(this.powershell, pressKeyScript(action.keys));
|
|
303
300
|
return { type: 'ok' };
|
|
304
301
|
}
|
|
305
302
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"win32.js","sourceRoot":"","sources":["../../src/adapters/win32.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAC/E,OAAO,EAAgB,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAElE,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAE9E,MAAM,iBAAiB,GAAqC;IAC3D,GAAG,EAAE,GAA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{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/detect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC1C,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/detect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC1C,aAAa,CAsBf"}
|
package/dist/detect/index.js
CHANGED
|
@@ -11,6 +11,15 @@ export function detectDisplayServer(env = process.env, platform = process.platfo
|
|
|
11
11
|
return 'win32';
|
|
12
12
|
if (platform !== 'linux')
|
|
13
13
|
return 'unknown';
|
|
14
|
+
// WSL is a Linux process attached to a Windows interactive desktop. WSLg
|
|
15
|
+
// also publishes DISPLAY and WAYLAND_DISPLAY, but those sockets describe
|
|
16
|
+
// the Linux application surface, not the Windows desktop the operator asked
|
|
17
|
+
// the terminal agent to see. Windows PowerShell is available through the
|
|
18
|
+
// interop bridge and the Win32 adapter can therefore serve the complete
|
|
19
|
+
// desktop capability without asking the user to install Linux compositor
|
|
20
|
+
// tools that still would not control the host desktop.
|
|
21
|
+
if (env.WSL_DISTRO_NAME || env.WSL_INTEROP)
|
|
22
|
+
return 'win32';
|
|
14
23
|
const sessionType = env.XDG_SESSION_TYPE?.toLowerCase();
|
|
15
24
|
if (sessionType === 'wayland')
|
|
16
25
|
return 'wayland';
|
package/dist/detect/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/detect/index.ts"],"names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AW,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC/C,IAAI,WAAW,KAAK,KAAK;QAAE,OAAO,KAAK,CAAA;IAEvC,IAAI,GAAG,CAAC,eAAe;QAAE,OAAO,SAAS,CAAA;IACzC,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAE7B,OAAO,SAAS,CAAA;AACjB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComputerUseAction, ComputerUseOutcomeUnknown } from '@namzu/sdk';
|
|
2
|
+
import type { SpawnError } from './util/spawn.js';
|
|
3
|
+
/**
|
|
4
|
+
* A state-changing desktop subprocess started but did not report a clean
|
|
5
|
+
* completion. The action must not be replayed automatically because the
|
|
6
|
+
* desktop may already reflect all or part of it.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ComputerUseOutcomeUnknownError extends Error implements ComputerUseOutcomeUnknown {
|
|
9
|
+
readonly action: ComputerUseAction['type'];
|
|
10
|
+
readonly code: "computer_use_outcome_unknown";
|
|
11
|
+
readonly outcome: "unknown";
|
|
12
|
+
readonly retrySafety: "unsafe";
|
|
13
|
+
readonly timedOut: boolean;
|
|
14
|
+
readonly exitCode: number;
|
|
15
|
+
constructor(action: ComputerUseAction['type'], failure: SpawnError);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD;;;;GAIG;AACH,qBAAa,8BAA+B,SAAQ,KAAM,YAAW,yBAAyB;IAQ5F,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC;IAP3C,QAAQ,CAAC,IAAI,EAAG,8BAA8B,CAAS;IACvD,QAAQ,CAAC,OAAO,EAAG,SAAS,CAAS;IACrC,QAAQ,CAAC,WAAW,EAAG,QAAQ,CAAS;IACxC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;gBAGf,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAC1C,OAAO,EAAE,UAAU;CASpB"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A state-changing desktop subprocess started but did not report a clean
|
|
3
|
+
* completion. The action must not be replayed automatically because the
|
|
4
|
+
* desktop may already reflect all or part of it.
|
|
5
|
+
*/
|
|
6
|
+
export class ComputerUseOutcomeUnknownError extends Error {
|
|
7
|
+
action;
|
|
8
|
+
code = 'computer_use_outcome_unknown';
|
|
9
|
+
outcome = 'unknown';
|
|
10
|
+
retrySafety = 'unsafe';
|
|
11
|
+
timedOut;
|
|
12
|
+
exitCode;
|
|
13
|
+
constructor(action, failure) {
|
|
14
|
+
super(`Computer-use action "${action}" did not complete cleanly after it started. It may have changed the desktop; the outcome is unknown. Take fresh screen or cursor state before deciding what to do, and do not automatically retry the action.`);
|
|
15
|
+
this.action = action;
|
|
16
|
+
this.name = 'ComputerUseOutcomeUnknownError';
|
|
17
|
+
this.timedOut = failure.result.timedOut;
|
|
18
|
+
this.exitCode = failure.result.exitCode;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAQ9C;IAPD,IAAI,GAAG,8BAAuC,CAAA;IAC9C,OAAO,GAAG,SAAkB,CAAA;IAC5B,WAAW,GAAG,QAAiB,CAAA;IAC/B,QAAQ,CAAS;IACjB,QAAQ,CAAQ;IAEzB,YACU,MAAiC,EAC1C,OAAmB;QAEnB,KAAK,CACJ,wBAAwB,MAAM,gNAAgN,CAC9O,CAAA;QALQ,WAAM,GAAN,MAAM,CAA2B;QAM1C,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAA;QAC5C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAA;IACxC,CAAC;CACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { SubprocessComputerUseHost } from './SubprocessComputerUseHost.js';
|
|
2
|
+
export type { SubprocessComputerUseHostOptions } from './SubprocessComputerUseHost.js';
|
|
2
3
|
export { detectDisplayServer } from './detect/index.js';
|
|
4
|
+
export { ComputerUseOutcomeUnknownError } from './errors.js';
|
|
3
5
|
/**
|
|
4
6
|
* The three failures a caller has to tell apart.
|
|
5
7
|
*
|
|
@@ -12,7 +14,7 @@ export { detectDisplayServer } from './detect/index.js';
|
|
|
12
14
|
* `AdapterUnavailableError` also carries `missing`, the list of binaries to
|
|
13
15
|
* install, which is the actionable half and was unreachable without the type.
|
|
14
16
|
*/
|
|
15
|
-
export { ActionCapabilityError, AdapterUnavailableError } from './adapters/types.js';
|
|
17
|
+
export { ActionCapabilityError, AdapterUnavailableError, } from './adapters/types.js';
|
|
16
18
|
export { SpawnError } from './util/spawn.js';
|
|
17
19
|
export type { SpawnOptions, SpawnResult } from './util/spawn.js';
|
|
18
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,YAAY,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAA;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAE5D;;;;;;;;;;;GAWG;AACH,OAAO,EACN,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { SubprocessComputerUseHost } from './SubprocessComputerUseHost.js';
|
|
2
2
|
export { detectDisplayServer } from './detect/index.js';
|
|
3
|
+
export { ComputerUseOutcomeUnknownError } from './errors.js';
|
|
3
4
|
/**
|
|
4
5
|
* The three failures a caller has to tell apart.
|
|
5
6
|
*
|
|
@@ -12,6 +13,6 @@ export { detectDisplayServer } from './detect/index.js';
|
|
|
12
13
|
* `AdapterUnavailableError` also carries `missing`, the list of binaries to
|
|
13
14
|
* install, which is the actionable half and was unreachable without the type.
|
|
14
15
|
*/
|
|
15
|
-
export { ActionCapabilityError, AdapterUnavailableError } from './adapters/types.js';
|
|
16
|
+
export { ActionCapabilityError, AdapterUnavailableError, } from './adapters/types.js';
|
|
16
17
|
export { SpawnError } from './util/spawn.js';
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAE5D;;;;;;;;;;;GAWG;AACH,OAAO,EACN,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/computer-use",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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": "^3.2.6",
|
|
56
|
-
"@namzu/sdk": "^
|
|
56
|
+
"@namzu/sdk": "^33.0.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsc --build",
|
|
@@ -7,6 +7,8 @@ import type {
|
|
|
7
7
|
} from '@namzu/sdk'
|
|
8
8
|
import type { Adapter } from './adapters/types.js'
|
|
9
9
|
import { detectDisplayServer } from './detect/index.js'
|
|
10
|
+
import { ComputerUseOutcomeUnknownError } from './errors.js'
|
|
11
|
+
import { SpawnError } from './util/spawn.js'
|
|
10
12
|
|
|
11
13
|
const UNINITIALISED_CAPABILITIES: ComputerUseCapabilities = {
|
|
12
14
|
displayServer: 'unknown',
|
|
@@ -17,6 +19,14 @@ const UNINITIALISED_CAPABILITIES: ComputerUseCapabilities = {
|
|
|
17
19
|
clipboard: false,
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
const UNSAFE_TO_REPLAY_AFTER_START = new Set<ComputerUseAction['type']>([
|
|
23
|
+
'mouse_click',
|
|
24
|
+
'mouse_drag',
|
|
25
|
+
'scroll',
|
|
26
|
+
'type_text',
|
|
27
|
+
'key',
|
|
28
|
+
])
|
|
29
|
+
|
|
20
30
|
export interface SubprocessComputerUseHostOptions {
|
|
21
31
|
readonly env?: NodeJS.ProcessEnv
|
|
22
32
|
readonly platform?: NodeJS.Platform
|
|
@@ -75,7 +85,20 @@ export class SubprocessComputerUseHost implements ComputerUseHost {
|
|
|
75
85
|
|
|
76
86
|
async execute(action: ComputerUseAction): Promise<ComputerUseResult> {
|
|
77
87
|
const adapter = this.requireAdapter()
|
|
78
|
-
|
|
88
|
+
try {
|
|
89
|
+
return await adapter.execute(action)
|
|
90
|
+
} catch (error) {
|
|
91
|
+
// SpawnError is produced only after the subprocess started and then
|
|
92
|
+
// timed out or closed non-zero. An unsafe action may have taken effect
|
|
93
|
+
// before that terminal status (a multi-command drag is the clearest
|
|
94
|
+
// example), so replaying it could duplicate or compound the change.
|
|
95
|
+
// A raw spawn error means the process never established that boundary;
|
|
96
|
+
// safe reads and idempotent mouse_move keep their ordinary diagnosis.
|
|
97
|
+
if (error instanceof SpawnError && UNSAFE_TO_REPLAY_AFTER_START.has(action.type)) {
|
|
98
|
+
throw new ComputerUseOutcomeUnknownError(action.type, error)
|
|
99
|
+
}
|
|
100
|
+
throw error
|
|
101
|
+
}
|
|
79
102
|
}
|
|
80
103
|
|
|
81
104
|
async dispose(): Promise<void> {
|
package/src/adapters/win32.ts
CHANGED
|
@@ -90,17 +90,8 @@ export function translateKeyToSendKeys(combo: string): string {
|
|
|
90
90
|
|
|
91
91
|
const POWERSHELL_BASE_ARGS = ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass']
|
|
92
92
|
|
|
93
|
-
async function runPowerShell(script: string): Promise<Buffer> {
|
|
94
|
-
|
|
95
|
-
const [hasPwsh, hasPs] = await Promise.all([hasExecutable('pwsh'), hasExecutable('powershell')])
|
|
96
|
-
const exe = hasPwsh ? 'pwsh' : hasPs ? 'powershell' : null
|
|
97
|
-
if (!exe) {
|
|
98
|
-
throw new AdapterUnavailableError(
|
|
99
|
-
'Win32Adapter: neither pwsh nor powershell is available on PATH',
|
|
100
|
-
['pwsh', 'powershell'],
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
const result = await runCommandOrThrow(exe, [...POWERSHELL_BASE_ARGS, '-Command', script])
|
|
93
|
+
async function runPowerShell(executable: string, script: string): Promise<Buffer> {
|
|
94
|
+
const result = await runCommandOrThrow(executable, [...POWERSHELL_BASE_ARGS, '-Command', script])
|
|
104
95
|
return result.stdout
|
|
105
96
|
}
|
|
106
97
|
|
|
@@ -268,23 +259,17 @@ const MOUSE_DOWN_UP_FLAGS: Readonly<Record<MouseButton, readonly [string, string
|
|
|
268
259
|
// Adapter
|
|
269
260
|
// ---------------------------------------------------------------------------
|
|
270
261
|
|
|
271
|
-
|
|
272
|
-
readonly hasPwsh: boolean
|
|
273
|
-
readonly hasPowerShell: boolean
|
|
274
|
-
}
|
|
262
|
+
const POWERSHELL_CANDIDATES = ['pwsh', 'powershell', 'pwsh.exe', 'powershell.exe'] as const
|
|
275
263
|
|
|
276
|
-
async function
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
hasExecutable('powershell'),
|
|
280
|
-
])
|
|
281
|
-
return { hasPwsh, hasPowerShell }
|
|
264
|
+
async function findPowerShell(): Promise<string | null> {
|
|
265
|
+
const present = await Promise.all(POWERSHELL_CANDIDATES.map((name) => hasExecutable(name)))
|
|
266
|
+
return POWERSHELL_CANDIDATES.find((_name, index) => present[index]) ?? null
|
|
282
267
|
}
|
|
283
268
|
|
|
284
269
|
export class Win32Adapter implements Adapter {
|
|
285
270
|
readonly capabilities: ComputerUseCapabilities
|
|
286
271
|
|
|
287
|
-
private constructor() {
|
|
272
|
+
private constructor(private readonly powershell: string) {
|
|
288
273
|
this.capabilities = Object.freeze({
|
|
289
274
|
displayServer: 'win32',
|
|
290
275
|
screenshot: true,
|
|
@@ -296,18 +281,18 @@ export class Win32Adapter implements Adapter {
|
|
|
296
281
|
}
|
|
297
282
|
|
|
298
283
|
static async create(): Promise<Win32Adapter> {
|
|
299
|
-
const
|
|
300
|
-
if (!
|
|
284
|
+
const powershell = await findPowerShell()
|
|
285
|
+
if (!powershell) {
|
|
301
286
|
throw new AdapterUnavailableError(
|
|
302
|
-
'Win32Adapter: neither
|
|
303
|
-
[
|
|
287
|
+
'Win32Adapter: neither PowerShell Core nor Windows PowerShell is available on PATH',
|
|
288
|
+
[...POWERSHELL_CANDIDATES],
|
|
304
289
|
)
|
|
305
290
|
}
|
|
306
|
-
return new Win32Adapter()
|
|
291
|
+
return new Win32Adapter(powershell)
|
|
307
292
|
}
|
|
308
293
|
|
|
309
294
|
async getDisplayGeometry(): Promise<DisplayGeometry> {
|
|
310
|
-
const stdout = await runPowerShell(GEOMETRY_SCRIPT)
|
|
295
|
+
const stdout = await runPowerShell(this.powershell, GEOMETRY_SCRIPT)
|
|
311
296
|
const parsed = JSON.parse(stdout.toString('utf8')) as {
|
|
312
297
|
width: number
|
|
313
298
|
height: number
|
|
@@ -319,7 +304,7 @@ export class Win32Adapter implements Adapter {
|
|
|
319
304
|
async execute(action: ComputerUseAction): Promise<ComputerUseResult> {
|
|
320
305
|
switch (action.type) {
|
|
321
306
|
case 'screenshot': {
|
|
322
|
-
const data = await runPowerShell(SCREENSHOT_SCRIPT)
|
|
307
|
+
const data = await runPowerShell(this.powershell, SCREENSHOT_SCRIPT)
|
|
323
308
|
const dims = decodePngDims(data)
|
|
324
309
|
return {
|
|
325
310
|
type: 'screenshot',
|
|
@@ -332,27 +317,30 @@ export class Win32Adapter implements Adapter {
|
|
|
332
317
|
}
|
|
333
318
|
}
|
|
334
319
|
case 'cursor_position': {
|
|
335
|
-
const stdout = await runPowerShell(CURSOR_POSITION_SCRIPT)
|
|
320
|
+
const stdout = await runPowerShell(this.powershell, CURSOR_POSITION_SCRIPT)
|
|
336
321
|
const parsed = JSON.parse(stdout.toString('utf8')) as { x: number; y: number }
|
|
337
322
|
return { type: 'cursor_position', point: parsed }
|
|
338
323
|
}
|
|
339
324
|
case 'mouse_move':
|
|
340
|
-
await runPowerShell(mouseMoveScript(action.to))
|
|
325
|
+
await runPowerShell(this.powershell, mouseMoveScript(action.to))
|
|
341
326
|
return { type: 'ok' }
|
|
342
327
|
case 'mouse_click':
|
|
343
|
-
await runPowerShell(mouseClickScript(action.at, action.button))
|
|
328
|
+
await runPowerShell(this.powershell, mouseClickScript(action.at, action.button))
|
|
344
329
|
return { type: 'ok' }
|
|
345
330
|
case 'mouse_drag':
|
|
346
|
-
await runPowerShell(mouseDragScript(action.from, action.to, action.button))
|
|
331
|
+
await runPowerShell(this.powershell, mouseDragScript(action.from, action.to, action.button))
|
|
347
332
|
return { type: 'ok' }
|
|
348
333
|
case 'scroll':
|
|
349
|
-
await runPowerShell(
|
|
334
|
+
await runPowerShell(
|
|
335
|
+
this.powershell,
|
|
336
|
+
scrollScript(action.at, action.direction, action.amount),
|
|
337
|
+
)
|
|
350
338
|
return { type: 'ok' }
|
|
351
339
|
case 'type_text':
|
|
352
|
-
await runPowerShell(typeTextScript(action.text))
|
|
340
|
+
await runPowerShell(this.powershell, typeTextScript(action.text))
|
|
353
341
|
return { type: 'ok' }
|
|
354
342
|
case 'key':
|
|
355
|
-
await runPowerShell(pressKeyScript(action.keys))
|
|
343
|
+
await runPowerShell(this.powershell, pressKeyScript(action.keys))
|
|
356
344
|
return { type: 'ok' }
|
|
357
345
|
}
|
|
358
346
|
}
|
package/src/detect/index.ts
CHANGED
|
@@ -14,6 +14,15 @@ export function detectDisplayServer(
|
|
|
14
14
|
if (platform === 'win32') return 'win32'
|
|
15
15
|
if (platform !== 'linux') return 'unknown'
|
|
16
16
|
|
|
17
|
+
// WSL is a Linux process attached to a Windows interactive desktop. WSLg
|
|
18
|
+
// also publishes DISPLAY and WAYLAND_DISPLAY, but those sockets describe
|
|
19
|
+
// the Linux application surface, not the Windows desktop the operator asked
|
|
20
|
+
// the terminal agent to see. Windows PowerShell is available through the
|
|
21
|
+
// interop bridge and the Win32 adapter can therefore serve the complete
|
|
22
|
+
// desktop capability without asking the user to install Linux compositor
|
|
23
|
+
// tools that still would not control the host desktop.
|
|
24
|
+
if (env.WSL_DISTRO_NAME || env.WSL_INTEROP) return 'win32'
|
|
25
|
+
|
|
17
26
|
const sessionType = env.XDG_SESSION_TYPE?.toLowerCase()
|
|
18
27
|
if (sessionType === 'wayland') return 'wayland'
|
|
19
28
|
if (sessionType === 'x11') return 'x11'
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ComputerUseAction, ComputerUseOutcomeUnknown } from '@namzu/sdk'
|
|
2
|
+
import type { SpawnError } from './util/spawn.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A state-changing desktop subprocess started but did not report a clean
|
|
6
|
+
* completion. The action must not be replayed automatically because the
|
|
7
|
+
* desktop may already reflect all or part of it.
|
|
8
|
+
*/
|
|
9
|
+
export class ComputerUseOutcomeUnknownError extends Error implements ComputerUseOutcomeUnknown {
|
|
10
|
+
readonly code = 'computer_use_outcome_unknown' as const
|
|
11
|
+
readonly outcome = 'unknown' as const
|
|
12
|
+
readonly retrySafety = 'unsafe' as const
|
|
13
|
+
readonly timedOut: boolean
|
|
14
|
+
readonly exitCode: number
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
readonly action: ComputerUseAction['type'],
|
|
18
|
+
failure: SpawnError,
|
|
19
|
+
) {
|
|
20
|
+
super(
|
|
21
|
+
`Computer-use action "${action}" did not complete cleanly after it started. It may have changed the desktop; the outcome is unknown. Take fresh screen or cursor state before deciding what to do, and do not automatically retry the action.`,
|
|
22
|
+
)
|
|
23
|
+
this.name = 'ComputerUseOutcomeUnknownError'
|
|
24
|
+
this.timedOut = failure.result.timedOut
|
|
25
|
+
this.exitCode = failure.result.exitCode
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { SubprocessComputerUseHost } from './SubprocessComputerUseHost.js'
|
|
2
|
+
export type { SubprocessComputerUseHostOptions } from './SubprocessComputerUseHost.js'
|
|
2
3
|
export { detectDisplayServer } from './detect/index.js'
|
|
4
|
+
export { ComputerUseOutcomeUnknownError } from './errors.js'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* The three failures a caller has to tell apart.
|
|
@@ -13,6 +15,9 @@ export { detectDisplayServer } from './detect/index.js'
|
|
|
13
15
|
* `AdapterUnavailableError` also carries `missing`, the list of binaries to
|
|
14
16
|
* install, which is the actionable half and was unreachable without the type.
|
|
15
17
|
*/
|
|
16
|
-
export {
|
|
18
|
+
export {
|
|
19
|
+
ActionCapabilityError,
|
|
20
|
+
AdapterUnavailableError,
|
|
21
|
+
} from './adapters/types.js'
|
|
17
22
|
export { SpawnError } from './util/spawn.js'
|
|
18
23
|
export type { SpawnOptions, SpawnResult } from './util/spawn.js'
|