@agent-sh/computer-use-linux 0.7.38 → 0.7.39

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/README.md CHANGED
@@ -500,13 +500,13 @@ bundle): `CUL_GNOME_EXTENSION_UUID`, `CUL_DBUS_SERVICE`, and
500
500
  UUID and DBus endpoint in both the Rust probes and the generated extension
501
501
  files.
502
502
 
503
- **npm wrapper** (set during `npm install`, or before running):
503
+ **npm wrapper** (set during `npm install`, or before running). The package's install script downloads the release binaries. When npm skipped it (npm 12 runs only install scripts it is told to allow), the wrapper runs the same download on first launch, with its output on stderr. A download that receives no data for 30 s fails:
504
504
 
505
505
  | Variable | Effect |
506
506
  | --- | --- |
507
507
  | `COMPUTER_USE_LINUX_BIN` | Run this absolute binary path instead of the one bundled by the npm package. Relative paths are ignored. |
508
508
  | `COMPUTER_USE_LINUX_DOWNLOAD_BASE` | Override the GitHub release base URL the installer downloads from (mirrors, air-gapped hosts). |
509
- | `COMPUTER_USE_LINUX_SKIP_DOWNLOAD=1` | Skip the post-install binary download entirely. |
509
+ | `COMPUTER_USE_LINUX_SKIP_DOWNLOAD=1` | Skip the binary download entirely, at install and at first launch. |
510
510
  | `COMPUTER_USE_LINUX_LOCAL_BINARY` / `…_LOCAL_COSMIC_HELPER` / `…_LOCAL_INDICATOR` | Install from a local build instead of downloading (used by CI and local testing). |
511
511
 
512
512
  ## Architecture
@@ -3,7 +3,7 @@
3
3
 
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
- const { spawn } = require('node:child_process');
6
+ const { spawn, spawnSync } = require('node:child_process');
7
7
 
8
8
  const binaryName = `computer-use-linux-${process.platform}-${process.arch}`;
9
9
  const bundledBinary = path.join(__dirname, binaryName);
@@ -11,11 +11,20 @@ const binary = process.env.COMPUTER_USE_LINUX_BIN || bundledBinary;
11
11
  const bundledCosmicHelper = path.join(__dirname, 'computer-use-linux-cosmic');
12
12
  const bundledIndicator = path.join(__dirname, 'computer-use-linux-indicator');
13
13
 
14
- if (!fs.existsSync(binary)) {
14
+ // npm 12 skips install scripts it has not been told to allow, so a global
15
+ // install can arrive without the native binary. Run the installer on first
16
+ // launch. Its output goes to stderr: stdout is the MCP channel.
17
+ function installBinary() {
18
+ const installer = path.join(__dirname, '..', 'install.js');
19
+ const result = spawnSync(process.execPath, [installer], { stdio: ['ignore', 2, 2] });
20
+ return result.status === 0 && fs.existsSync(binary);
21
+ }
22
+
23
+ if (!fs.existsSync(binary) && (process.env.COMPUTER_USE_LINUX_BIN || !installBinary())) {
15
24
  console.error(
16
25
  [
17
26
  `computer-use-linux binary not found: ${binary}`,
18
- 'Reinstall the package, run `npm rebuild computer-use-linux`, or set COMPUTER_USE_LINUX_BIN.',
27
+ 'Run `node npm/install.js` in the package directory, allow its install script, or set COMPUTER_USE_LINUX_BIN.',
19
28
  ].join('\n')
20
29
  );
21
30
  process.exit(127);
package/npm/install.js CHANGED
@@ -18,36 +18,73 @@ const binDir = path.join(__dirname, 'bin');
18
18
  const binaryPath = path.join(binDir, `computer-use-linux-${process.platform}-${process.arch}`);
19
19
  const cosmicHelperPath = path.join(binDir, 'computer-use-linux-cosmic');
20
20
  const indicatorPath = path.join(binDir, 'computer-use-linux-indicator');
21
+ // A request that receives no bytes for this long is stalled. The wrapper
22
+ // installs on first launch, so a stalled download would otherwise hold the
23
+ // MCP client's startup open and outlive it when the client gives up.
24
+ const IDLE_TIMEOUT_MS = 30_000;
25
+
26
+ // Messages can carry paths and URLs from the environment. JSON string
27
+ // escaping turns CR, LF and the other C0 control characters (U+0000-U+001F)
28
+ // into visible escapes, so a value with a newline cannot forge a log line.
29
+ function say(write, message) {
30
+ const safe = JSON.stringify(String(message)).slice(1, -1);
31
+ write(`[computer-use-linux] ${safe}`);
32
+ }
21
33
 
22
34
  function fail(message) {
23
- console.error(`[computer-use-linux] ${message}`);
35
+ say(console.error, message);
24
36
  process.exit(1);
25
37
  }
26
38
 
39
+ // Write next to the destination, then rename over it, so a server starting
40
+ // at the same time (the wrapper installs on first launch) never runs a
41
+ // half-written binary.
42
+ function place(source, destination) {
43
+ const staging = `${destination}.tmp-${process.pid}-${crypto.randomBytes(4).toString('hex')}`;
44
+ try {
45
+ fs.copyFileSync(source, staging);
46
+ fs.chmodSync(staging, 0o755);
47
+ fs.renameSync(staging, destination);
48
+ } finally {
49
+ fs.rmSync(staging, { force: true });
50
+ }
51
+ }
52
+
27
53
  function copyLocalBinary(source) {
28
54
  fs.mkdirSync(binDir, { recursive: true });
29
- fs.copyFileSync(source, binaryPath);
30
- fs.chmodSync(binaryPath, 0o755);
55
+ // Main binary last, as in main(): its presence tells the wrapper the
56
+ // helpers are in place.
31
57
  if (process.env.COMPUTER_USE_LINUX_LOCAL_COSMIC_HELPER) {
32
- fs.copyFileSync(process.env.COMPUTER_USE_LINUX_LOCAL_COSMIC_HELPER, cosmicHelperPath);
33
- fs.chmodSync(cosmicHelperPath, 0o755);
58
+ place(process.env.COMPUTER_USE_LINUX_LOCAL_COSMIC_HELPER, cosmicHelperPath);
34
59
  }
35
60
  if (process.env.COMPUTER_USE_LINUX_LOCAL_INDICATOR) {
36
- fs.copyFileSync(process.env.COMPUTER_USE_LINUX_LOCAL_INDICATOR, indicatorPath);
37
- fs.chmodSync(indicatorPath, 0o755);
61
+ place(process.env.COMPUTER_USE_LINUX_LOCAL_INDICATOR, indicatorPath);
38
62
  }
39
- console.log(`[computer-use-linux] installed local binary from ${source}`);
63
+ place(source, binaryPath);
64
+ say(console.log, `installed local binary from ${source}`);
40
65
  }
41
66
 
42
67
  function download(url, destination, redirects = 5) {
43
68
  return new Promise((resolve, reject) => {
69
+ // An explicit timer, re-armed on every chunk: Node's socket idle timeout
70
+ // did not fire at the requested time during a stalled TLS handshake.
71
+ let idle = null;
72
+ const disarm = () => clearTimeout(idle);
73
+ const arm = () => {
74
+ disarm();
75
+ idle = setTimeout(() => {
76
+ request.destroy(new Error(`no data for ${IDLE_TIMEOUT_MS / 1000} s: ${url}`));
77
+ }, IDLE_TIMEOUT_MS);
78
+ };
44
79
  const request = https.get(url, (response) => {
80
+ arm();
45
81
  if (
46
82
  response.statusCode >= 300 &&
47
83
  response.statusCode < 400 &&
48
84
  response.headers.location &&
49
85
  redirects > 0
50
86
  ) {
87
+ disarm();
51
88
  response.resume();
52
89
  const nextUrl = new URL(response.headers.location, url).toString();
53
90
  download(nextUrl, destination, redirects - 1).then(resolve, reject);
@@ -55,6 +92,7 @@ function download(url, destination, redirects = 5) {
55
92
  }
56
93
 
57
94
  if (response.statusCode !== 200) {
95
+ disarm();
58
96
  response.resume();
59
97
  const error = new Error(`download failed with HTTP ${response.statusCode}: ${url}`);
60
98
  error.statusCode = response.statusCode;
@@ -63,11 +101,22 @@ function download(url, destination, redirects = 5) {
63
101
  }
64
102
 
65
103
  const file = fs.createWriteStream(destination, { mode: 0o600 });
104
+ response.on('data', arm);
66
105
  response.pipe(file);
67
- file.on('finish', () => file.close(resolve));
68
- file.on('error', reject);
106
+ file.on('finish', () => {
107
+ disarm();
108
+ file.close(resolve);
109
+ });
110
+ file.on('error', (error) => {
111
+ disarm();
112
+ reject(error);
113
+ });
114
+ });
115
+ arm();
116
+ request.on('error', (error) => {
117
+ disarm();
118
+ reject(error);
69
119
  });
70
- request.on('error', reject);
71
120
  });
72
121
  }
73
122
 
@@ -100,7 +149,7 @@ function sha256File(filePath) {
100
149
 
101
150
  async function main() {
102
151
  if (process.env.COMPUTER_USE_LINUX_SKIP_DOWNLOAD === '1') {
103
- console.log('[computer-use-linux] skipping binary download');
152
+ say(console.log, 'skipping binary download');
104
153
  return;
105
154
  }
106
155
 
@@ -124,6 +173,14 @@ async function main() {
124
173
  const baseUrl =
125
174
  process.env.COMPUTER_USE_LINUX_DOWNLOAD_BASE ||
126
175
  `https://github.com/agent-sh/computer-use-linux/releases/download/v${pkg.version}`;
176
+ // Refuse before downloading ~15 MB that could not be installed (a global
177
+ // prefix owned by root).
178
+ try {
179
+ fs.accessSync(fs.existsSync(binDir) ? binDir : path.dirname(binDir), fs.constants.W_OK);
180
+ } catch (error) {
181
+ fail(`cannot write ${binDir}: ${error.message}`);
182
+ }
183
+
127
184
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'computer-use-linux-'));
128
185
  const tmpBinary = path.join(tmpDir, asset);
129
186
  const tmpSha = path.join(tmpDir, `${asset}.sha256`);
@@ -133,7 +190,7 @@ async function main() {
133
190
  const tmpIndicatorSha = path.join(tmpDir, `${indicatorAsset}.sha256`);
134
191
 
135
192
  try {
136
- console.log(`[computer-use-linux] downloading ${asset} from ${baseUrl}`);
193
+ say(console.log, `downloading ${asset} from ${baseUrl}`);
137
194
  await download(`${baseUrl}/${asset}`, tmpBinary);
138
195
  await download(`${baseUrl}/${asset}.sha256`, tmpSha);
139
196
  await download(`${baseUrl}/${cosmicAsset}`, tmpCosmic);
@@ -163,18 +220,20 @@ async function main() {
163
220
  }
164
221
  }
165
222
 
223
+ // The wrapper only checks for the main binary, so it goes last: once it
224
+ // exists, the helpers it points the server at exist too.
166
225
  fs.mkdirSync(binDir, { recursive: true });
167
- fs.copyFileSync(tmpBinary, binaryPath);
168
- fs.chmodSync(binaryPath, 0o755);
169
- fs.copyFileSync(tmpCosmic, cosmicHelperPath);
170
- fs.chmodSync(cosmicHelperPath, 0o755);
226
+ place(tmpCosmic, cosmicHelperPath);
171
227
  if (hasIndicator) {
172
- fs.copyFileSync(tmpIndicator, indicatorPath);
173
- fs.chmodSync(indicatorPath, 0o755);
228
+ place(tmpIndicator, indicatorPath);
174
229
  } else {
175
230
  fs.rmSync(indicatorPath, { force: true });
176
231
  }
177
- console.log(`[computer-use-linux] installed ${asset} and ${cosmicAsset}${hasIndicator ? ` and ${indicatorAsset}` : ' (release has no indicator)'}`);
232
+ place(tmpBinary, binaryPath);
233
+ say(
234
+ console.log,
235
+ `installed ${asset} and ${cosmicAsset}${hasIndicator ? ` and ${indicatorAsset}` : ' (release has no indicator)'}`
236
+ );
178
237
  } finally {
179
238
  fs.rmSync(tmpDir, { recursive: true, force: true });
180
239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-sh/computer-use-linux",
3
- "version": "0.7.38",
3
+ "version": "0.7.39",
4
4
  "description": "Native Linux desktop control for AI agents (MCP server, Pi tools, and CLI): semantic AT-SPI accessibility trees, screenshots, compositor window targeting, Wayland/X11 input, and an on-screen activity indicator.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -7,7 +7,7 @@ export interface GeneratedMcpToolDefinition {
7
7
  annotations: Record<string, unknown>;
8
8
  }
9
9
 
10
- export const GENERATED_SERVER_VERSION = "0.7.38";
10
+ export const GENERATED_SERVER_VERSION = "0.7.39";
11
11
  export const GENERATED_TOOL_CATALOG_HASH = "626768053c7e97574226d8d8b382ced55272e50273dc6fe72a81d130b20fdb7a";
12
12
  export const GENERATED_SHELL_TOOL_CATALOG_HASH = "628cbd7dc623cfcf7ff2dc18c69960f4c964cf1566045d796e89a76ba7bba9e2";
13
13
  export const GENERATED_MCP_TOOLS =