agent-browser 0.8.2 → 0.8.4

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.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Cross-platform CLI wrapper for agent-browser
5
+ *
6
+ * This wrapper enables npx support on Windows where shell scripts don't work.
7
+ * For global installs, postinstall.js patches the shims to invoke the native
8
+ * binary directly (zero overhead).
9
+ */
10
+
11
+ import { spawn } from 'child_process';
12
+ import { existsSync } from 'fs';
13
+ import { dirname, join } from 'path';
14
+ import { fileURLToPath } from 'url';
15
+ import { platform, arch } from 'os';
16
+
17
+ const __dirname = dirname(fileURLToPath(import.meta.url));
18
+
19
+ // Map Node.js platform/arch to binary naming convention
20
+ function getBinaryName() {
21
+ const os = platform();
22
+ const cpuArch = arch();
23
+
24
+ let osKey;
25
+ switch (os) {
26
+ case 'darwin':
27
+ osKey = 'darwin';
28
+ break;
29
+ case 'linux':
30
+ osKey = 'linux';
31
+ break;
32
+ case 'win32':
33
+ osKey = 'win32';
34
+ break;
35
+ default:
36
+ return null;
37
+ }
38
+
39
+ let archKey;
40
+ switch (cpuArch) {
41
+ case 'x64':
42
+ case 'x86_64':
43
+ archKey = 'x64';
44
+ break;
45
+ case 'arm64':
46
+ case 'aarch64':
47
+ archKey = 'arm64';
48
+ break;
49
+ default:
50
+ return null;
51
+ }
52
+
53
+ const ext = os === 'win32' ? '.exe' : '';
54
+ return `agent-browser-${osKey}-${archKey}${ext}`;
55
+ }
56
+
57
+ function main() {
58
+ const binaryName = getBinaryName();
59
+
60
+ if (!binaryName) {
61
+ console.error(`Error: Unsupported platform: ${platform()}-${arch()}`);
62
+ process.exit(1);
63
+ }
64
+
65
+ const binaryPath = join(__dirname, binaryName);
66
+
67
+ if (!existsSync(binaryPath)) {
68
+ console.error(`Error: No binary found for ${platform()}-${arch()}`);
69
+ console.error(`Expected: ${binaryPath}`);
70
+ console.error('');
71
+ console.error('Run "npm run build:native" to build for your platform,');
72
+ console.error('or reinstall the package to trigger the postinstall download.');
73
+ process.exit(1);
74
+ }
75
+
76
+ // Spawn the native binary with inherited stdio
77
+ const child = spawn(binaryPath, process.argv.slice(2), {
78
+ stdio: 'inherit',
79
+ windowsHide: false,
80
+ });
81
+
82
+ child.on('error', (err) => {
83
+ console.error(`Error executing binary: ${err.message}`);
84
+ process.exit(1);
85
+ });
86
+
87
+ child.on('close', (code) => {
88
+ process.exit(code ?? 0);
89
+ });
90
+ }
91
+
92
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-browser",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "Headless browser automation CLI for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/daemon.js",
@@ -11,7 +11,7 @@
11
11
  "skills"
12
12
  ],
13
13
  "bin": {
14
- "agent-browser": "./bin/agent-browser"
14
+ "agent-browser": "./bin/agent-browser.js"
15
15
  },
16
16
  "keywords": [
17
17
  "browser",
@@ -70,7 +70,7 @@
70
70
  "test:watch": "vitest",
71
71
  "postinstall": "node scripts/postinstall.js",
72
72
  "changeset": "changeset",
73
- "ci:version": "changeset version && pnpm install --no-frozen-lockfile",
73
+ "ci:version": "changeset version && pnpm run version:sync && pnpm install --no-frozen-lockfile",
74
74
  "ci:publish": "pnpm run version:sync && pnpm run build && changeset publish"
75
75
  }
76
76
  }
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Verifies that package.json and cli/Cargo.toml have the same version.
5
+ * Used in CI to catch version drift.
6
+ */
7
+
8
+ import { readFileSync } from 'fs';
9
+ import { dirname, join } from 'path';
10
+ import { fileURLToPath } from 'url';
11
+
12
+ const __dirname = dirname(fileURLToPath(import.meta.url));
13
+ const rootDir = join(__dirname, '..');
14
+
15
+ // Read package.json version
16
+ const packageJson = JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf-8'));
17
+ const packageVersion = packageJson.version;
18
+
19
+ // Read Cargo.toml version
20
+ const cargoToml = readFileSync(join(rootDir, 'cli/Cargo.toml'), 'utf-8');
21
+ const cargoVersionMatch = cargoToml.match(/^version\s*=\s*"([^"]*)"/m);
22
+
23
+ if (!cargoVersionMatch) {
24
+ console.error('Could not find version in cli/Cargo.toml');
25
+ process.exit(1);
26
+ }
27
+
28
+ const cargoVersion = cargoVersionMatch[1];
29
+
30
+ if (packageVersion !== cargoVersion) {
31
+ console.error('Version mismatch detected!');
32
+ console.error(` package.json: ${packageVersion}`);
33
+ console.error(` cli/Cargo.toml: ${cargoVersion}`);
34
+ console.error('');
35
+ console.error("Run 'pnpm run version:sync' to fix this.");
36
+ process.exit(1);
37
+ }
38
+
39
+ console.log(`Versions are in sync: ${packageVersion}`);
@@ -4,9 +4,12 @@
4
4
  * Postinstall script for agent-browser
5
5
  *
6
6
  * Downloads the platform-specific native binary if not present.
7
+ * On global installs, patches npm's bin entry to use the native binary directly:
8
+ * - Windows: Overwrites .cmd/.ps1 shims
9
+ * - Mac/Linux: Replaces symlink to point to native binary
7
10
  */
8
11
 
9
- import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync } from 'fs';
12
+ import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync, writeFileSync, symlinkSync, lstatSync } from 'fs';
10
13
  import { dirname, join } from 'path';
11
14
  import { fileURLToPath } from 'url';
12
15
  import { platform, arch } from 'os';
@@ -73,6 +76,11 @@ async function main() {
73
76
  chmodSync(binaryPath, 0o755);
74
77
  }
75
78
  console.log(`✓ Native binary ready: ${binaryName}`);
79
+
80
+ // On global installs, fix npm's bin entry to use native binary directly
81
+ await fixGlobalInstallBin();
82
+
83
+ showPlaywrightReminder();
76
84
  return;
77
85
  }
78
86
 
@@ -102,7 +110,14 @@ async function main() {
102
110
  console.log(' 2. Run: npm run build:native');
103
111
  }
104
112
 
105
- // Reminder about Playwright browsers
113
+ // On global installs, fix npm's bin entry to use native binary directly
114
+ // This avoids the /bin/sh error on Windows and provides zero-overhead execution
115
+ await fixGlobalInstallBin();
116
+
117
+ showPlaywrightReminder();
118
+ }
119
+
120
+ function showPlaywrightReminder() {
106
121
  console.log('');
107
122
  console.log('╔═══════════════════════════════════════════════════════════════════════════╗');
108
123
  console.log('║ To download browser binaries, run: ║');
@@ -116,4 +131,105 @@ async function main() {
116
131
  console.log('╚═══════════════════════════════════════════════════════════════════════════╝');
117
132
  }
118
133
 
134
+ /**
135
+ * Fix npm's bin entry on global installs to use the native binary directly.
136
+ * This provides zero-overhead CLI execution for global installs.
137
+ */
138
+ async function fixGlobalInstallBin() {
139
+ if (platform() === 'win32') {
140
+ await fixWindowsShims();
141
+ } else {
142
+ await fixUnixSymlink();
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Fix npm symlink on Mac/Linux global installs.
148
+ * Replace the symlink to the JS wrapper with a symlink to the native binary.
149
+ */
150
+ async function fixUnixSymlink() {
151
+ // Get npm's global bin directory (npm prefix -g + /bin)
152
+ let npmBinDir;
153
+ try {
154
+ const prefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
155
+ npmBinDir = join(prefix, 'bin');
156
+ } catch {
157
+ return; // npm not available
158
+ }
159
+
160
+ const symlinkPath = join(npmBinDir, 'agent-browser');
161
+
162
+ // Check if symlink exists (indicates global install)
163
+ try {
164
+ const stat = lstatSync(symlinkPath);
165
+ if (!stat.isSymbolicLink()) {
166
+ return; // Not a symlink, don't touch it
167
+ }
168
+ } catch {
169
+ return; // Symlink doesn't exist, not a global install
170
+ }
171
+
172
+ // Replace symlink to point directly to native binary
173
+ try {
174
+ unlinkSync(symlinkPath);
175
+ symlinkSync(binaryPath, symlinkPath);
176
+ console.log('✓ Optimized: symlink points to native binary (zero overhead)');
177
+ } catch (err) {
178
+ // Permission error or other issue - not critical, JS wrapper still works
179
+ console.log(`⚠ Could not optimize symlink: ${err.message}`);
180
+ console.log(' CLI will work via Node.js wrapper (slightly slower startup)');
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Fix npm-generated shims on Windows global installs.
186
+ * npm generates shims that try to run /bin/sh, which doesn't exist on Windows.
187
+ * We overwrite them to invoke the native .exe directly.
188
+ */
189
+ async function fixWindowsShims() {
190
+ // Check if this is a global install by looking for npm's global prefix
191
+ let npmBinDir;
192
+ try {
193
+ npmBinDir = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
194
+ } catch {
195
+ return; // Not a global install or npm not available
196
+ }
197
+
198
+ // The shims are in the npm prefix directory (not prefix/bin on Windows)
199
+ const cmdShim = join(npmBinDir, 'agent-browser.cmd');
200
+ const ps1Shim = join(npmBinDir, 'agent-browser.ps1');
201
+
202
+ // Only fix if shims exist (indicates global install)
203
+ if (!existsSync(cmdShim)) {
204
+ return;
205
+ }
206
+
207
+ // Path to native binary relative to npm prefix
208
+ const relativeBinaryPath = 'node_modules\\agent-browser\\bin\\agent-browser-win32-x64.exe';
209
+
210
+ try {
211
+ // Overwrite .cmd shim
212
+ const cmdContent = `@ECHO off\r\n"%~dp0${relativeBinaryPath}" %*\r\n`;
213
+ writeFileSync(cmdShim, cmdContent);
214
+
215
+ // Overwrite .ps1 shim
216
+ const ps1Content = `#!/usr/bin/env pwsh
217
+ $basedir = Split-Path $MyInvocation.MyCommand.Definition -Parent
218
+ $exe = ""
219
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
220
+ $exe = ".exe"
221
+ }
222
+ & "$basedir/${relativeBinaryPath.replace(/\\/g, '/')}" $args
223
+ exit $LASTEXITCODE
224
+ `;
225
+ writeFileSync(ps1Shim, ps1Content);
226
+
227
+ console.log('✓ Optimized: shims point to native binary (zero overhead)');
228
+ } catch (err) {
229
+ // Permission error or other issue - not critical, JS wrapper still works
230
+ console.log(`⚠ Could not optimize shims: ${err.message}`);
231
+ console.log(' CLI will work via Node.js wrapper (slightly slower startup)');
232
+ }
233
+ }
234
+
119
235
  main().catch(console.error);
package/bin/agent-browser DELETED
@@ -1,28 +0,0 @@
1
- #!/bin/sh
2
- # agent-browser CLI wrapper
3
- # Detects OS/arch and runs the appropriate native binary
4
-
5
- SCRIPT="$0"
6
- while [ -L "$SCRIPT" ]; do
7
- SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd)"
8
- SCRIPT="$(readlink "$SCRIPT")"
9
- case "$SCRIPT" in /*) ;; *) SCRIPT="$SCRIPT_DIR/$SCRIPT" ;; esac
10
- done
11
- SCRIPT_DIR="$(cd "$(dirname "$SCRIPT")" && pwd)"
12
-
13
- OS=$(uname -s | tr '[:upper:]' '[:lower:]')
14
- ARCH=$(uname -m)
15
- case "$OS" in darwin) OS="darwin" ;; linux) OS="linux" ;; mingw*|msys*|cygwin*) OS="win32" ;; esac
16
- case "$ARCH" in x86_64|amd64) ARCH="x64" ;; aarch64|arm64) ARCH="arm64" ;; esac
17
-
18
- BINARY="$SCRIPT_DIR/agent-browser-${OS}-${ARCH}"
19
-
20
- if [ -f "$BINARY" ]; then
21
- # Ensure binary is executable (npm tarballs don't preserve execute bit)
22
- [ -x "$BINARY" ] || chmod +x "$BINARY" 2>/dev/null
23
- exec "$BINARY" "$@"
24
- fi
25
-
26
- echo "Error: No binary found for ${OS}-${ARCH}" >&2
27
- echo "Run 'npm run build:native' to build for your platform" >&2
28
- exit 1
@@ -1,13 +0,0 @@
1
- @echo off
2
- setlocal
3
- set "SCRIPT_DIR=%~dp0"
4
- set "BINARY=%SCRIPT_DIR%agent-browser-win32-x64.exe"
5
-
6
- if exist "%BINARY%" (
7
- "%BINARY%" %*
8
- exit /b %errorlevel%
9
- )
10
-
11
- echo Error: No binary found for win32-x64 >&2
12
- echo Run 'npm run build:native' to build for your platform >&2
13
- exit /b 1