@standardbeagle/agnt 0.7.5 → 0.7.6

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/bin/agnt CHANGED
@@ -4,7 +4,13 @@
4
4
  * agnt wrapper script
5
5
  *
6
6
  * This script is the entry point that npm symlinks to.
7
- * It finds and executes the downloaded Go binary.
7
+ * It handles binary updates/cleanup and executes the downloaded Go binary.
8
+ *
9
+ * Update mechanism (Windows-compatible):
10
+ * - .old files: Previous binary, renamed during update (cleanup on next run)
11
+ * - .new files: Pending update, applied on next run
12
+ *
13
+ * This allows updates even when the daemon is running (Windows locks executables).
8
14
  */
9
15
 
10
16
  const { spawn } = require('child_process');
@@ -15,6 +21,38 @@ const fs = require('fs');
15
21
  const BINARY_NAME = process.platform === 'win32' ? 'agnt-binary.exe' : 'agnt-binary';
16
22
  const binDir = __dirname;
17
23
  const binaryPath = path.join(binDir, BINARY_NAME);
24
+ const oldPath = binaryPath + '.old';
25
+ const newPath = binaryPath + '.new';
26
+
27
+ // Cleanup old binary from previous update (may fail if still locked, that's ok)
28
+ try {
29
+ if (fs.existsSync(oldPath)) {
30
+ fs.unlinkSync(oldPath);
31
+ }
32
+ } catch (e) {
33
+ // Ignore - file may still be locked by running daemon
34
+ }
35
+
36
+ // Apply pending update if exists
37
+ if (fs.existsSync(newPath)) {
38
+ try {
39
+ // Rename current to .old (works even if running on Windows)
40
+ if (fs.existsSync(binaryPath)) {
41
+ fs.renameSync(binaryPath, oldPath);
42
+ }
43
+ // Move new binary into place
44
+ fs.renameSync(newPath, binaryPath);
45
+ console.error('Updated to new version');
46
+ // Try to cleanup old
47
+ try {
48
+ fs.unlinkSync(oldPath);
49
+ } catch (e) {
50
+ // Ignore - will cleanup next time
51
+ }
52
+ } catch (e) {
53
+ console.error(`Warning: Failed to apply pending update: ${e.message}`);
54
+ }
55
+ }
18
56
 
19
57
  // Check if binary exists
20
58
  if (!fs.existsSync(binaryPath)) {
package/bin/agnt.cmd ADDED
@@ -0,0 +1,45 @@
1
+ @echo off
2
+ setlocal enabledelayedexpansion
3
+
4
+ :: agnt wrapper script for Windows
5
+ :: Handles binary updates and cleanup before executing
6
+
7
+ set "SCRIPT_DIR=%~dp0"
8
+ set "BINARY=%SCRIPT_DIR%agnt-binary.exe"
9
+ set "BINARY_NEW=%BINARY%.new"
10
+ set "BINARY_OLD=%BINARY%.old"
11
+
12
+ :: Cleanup old binary from previous update (may fail if still locked, that's ok)
13
+ if exist "%BINARY_OLD%" (
14
+ del /f /q "%BINARY_OLD%" >nul 2>&1
15
+ )
16
+
17
+ :: Apply pending update if exists
18
+ if exist "%BINARY_NEW%" (
19
+ :: Rename current to .old (works even if running via daemon)
20
+ if exist "%BINARY%" (
21
+ move /y "%BINARY%" "%BINARY_OLD%" >nul 2>&1
22
+ )
23
+ :: Move new binary into place
24
+ move /y "%BINARY_NEW%" "%BINARY%" >nul 2>&1
25
+ if !errorlevel! equ 0 (
26
+ echo Updated to new version
27
+ :: Try to cleanup old
28
+ del /f /q "%BINARY_OLD%" >nul 2>&1
29
+ )
30
+ )
31
+
32
+ :: Check if binary exists
33
+ if not exist "%BINARY%" (
34
+ echo Error: agnt binary not found at %BINARY%
35
+ echo.
36
+ echo The binary may not have been downloaded during installation.
37
+ echo Try reinstalling the package:
38
+ echo npm uninstall -g @standardbeagle/agnt
39
+ echo npm install -g @standardbeagle/agnt
40
+ exit /b 1
41
+ )
42
+
43
+ :: Execute the binary with all arguments
44
+ "%BINARY%" %*
45
+ exit /b %errorlevel%
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standardbeagle/agnt",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "description": "MCP server for AI coding agents - process management, reverse proxy with traffic logging, browser instrumentation, and sketch mode",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -98,10 +98,43 @@ async function install() {
98
98
  fs.mkdirSync(binDir, { recursive: true });
99
99
  }
100
100
 
101
- // Check if binary already exists
101
+ // Handle existing binary (might be locked on Windows if daemon is running)
102
102
  if (fs.existsSync(binaryPath)) {
103
- console.log(`${BINARY_NAME} binary already exists, skipping download`);
104
- return;
103
+ const oldPath = binaryPath + '.old';
104
+ let binaryLocked = false;
105
+
106
+ try {
107
+ // Try to delete any previous .old file first
108
+ if (fs.existsSync(oldPath)) {
109
+ try {
110
+ fs.unlinkSync(oldPath);
111
+ } catch (e) {
112
+ // Ignore - might still be locked from previous upgrade
113
+ }
114
+ }
115
+
116
+ // Rename current binary to .old (works even if file is locked on Windows)
117
+ fs.renameSync(binaryPath, oldPath);
118
+ console.log(`Renamed existing binary to ${path.basename(oldPath)}`);
119
+
120
+ // Try to delete the old file (will fail if locked, but that's ok)
121
+ try {
122
+ fs.unlinkSync(oldPath);
123
+ } catch (e) {
124
+ // File is locked (daemon running) - will be cleaned up next time
125
+ binaryLocked = true;
126
+ console.log(`Note: Old binary still in use (daemon running)`);
127
+ }
128
+ } catch (e) {
129
+ // Rename failed - binary might be the same version or something else is wrong
130
+ console.log(`${BINARY_NAME} binary already exists, skipping download`);
131
+ return;
132
+ }
133
+
134
+ // If binary was locked, suggest running agnt upgrade after install
135
+ if (binaryLocked) {
136
+ console.log(`Tip: Run 'agnt upgrade' after install to restart daemon with new version`);
137
+ }
105
138
  }
106
139
 
107
140
  const url = getDownloadUrl();