@geekbeer/minion 3.5.30 → 3.5.32

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/core/db.js CHANGED
@@ -2,6 +2,8 @@
2
2
  * SQLite Database Module
3
3
  * Provides a singleton SQLite database connection for all minion stores.
4
4
  * Uses better-sqlite3 (synchronous API) with WAL mode for performance.
5
+ * Falls back to Node.js built-in node:sqlite when better-sqlite3 is unavailable
6
+ * (e.g., no prebuilt binaries for the current Node.js version on Windows).
5
7
  *
6
8
  * Database file: $DATA_DIR/minion.db
7
9
  *
@@ -33,6 +35,63 @@ function resolveDbPath() {
33
35
  }
34
36
  }
35
37
 
38
+ /**
39
+ * Open a database connection using better-sqlite3 or node:sqlite fallback.
40
+ * @param {string} dbPath
41
+ * @returns {import('better-sqlite3').Database}
42
+ */
43
+ function openDatabase(dbPath) {
44
+ // Try better-sqlite3 first (fastest, has prebuilt binaries for most platforms)
45
+ try {
46
+ const Database = require('better-sqlite3')
47
+ const db = new Database(dbPath)
48
+ db.pragma('journal_mode = WAL')
49
+ db.pragma('foreign_keys = ON')
50
+ console.log('[DB] Using better-sqlite3')
51
+ return db
52
+ } catch (e) {
53
+ console.log(`[DB] better-sqlite3 unavailable (${e.message}), trying node:sqlite...`)
54
+ }
55
+
56
+ // Fallback to Node.js built-in sqlite (available in Node 22.5.0+)
57
+ try {
58
+ const { DatabaseSync } = require('node:sqlite')
59
+ const db = new DatabaseSync(dbPath)
60
+ db.exec('PRAGMA journal_mode = WAL')
61
+ db.exec('PRAGMA foreign_keys = ON')
62
+
63
+ // Polyfill db.pragma() for compatibility with better-sqlite3 API
64
+ db.pragma = function (str) {
65
+ const stmt = db.prepare(`PRAGMA ${str}`)
66
+ return stmt.get()
67
+ }
68
+
69
+ // Polyfill db.transaction() for compatibility with better-sqlite3 API
70
+ db.transaction = function (fn) {
71
+ return function (...args) {
72
+ db.exec('BEGIN')
73
+ try {
74
+ const result = fn(...args)
75
+ db.exec('COMMIT')
76
+ return result
77
+ } catch (e) {
78
+ db.exec('ROLLBACK')
79
+ throw e
80
+ }
81
+ }
82
+ }
83
+
84
+ console.log('[DB] Using node:sqlite (built-in)')
85
+ return db
86
+ } catch (e) {
87
+ throw new Error(
88
+ `[DB] No SQLite driver available. Install better-sqlite3 or use Node.js 22.5.0+ for built-in sqlite support. ` +
89
+ `better-sqlite3 error: check that Python and build tools are installed, or use Node.js 22 LTS which has prebuilt binaries. ` +
90
+ `node:sqlite error: ${e.message}`
91
+ )
92
+ }
93
+ }
94
+
36
95
  /**
37
96
  * Get the singleton database connection.
38
97
  * Initializes the database and schema on first call.
@@ -44,12 +103,7 @@ function getDb() {
44
103
  const dbPath = resolveDbPath()
45
104
  fs.mkdirSync(path.dirname(dbPath), { recursive: true })
46
105
 
47
- const Database = require('better-sqlite3')
48
- _db = new Database(dbPath)
49
-
50
- // Performance & integrity settings
51
- _db.pragma('journal_mode = WAL')
52
- _db.pragma('foreign_keys = ON')
106
+ _db = openDatabase(dbPath)
53
107
 
54
108
  initSchema(_db)
55
109
  migrateSchema(_db)
@@ -1120,7 +1120,6 @@ SUPEOF
1120
1120
  else
1121
1121
  echo " tail -f /var/log/supervisor/minion-agent.log # View logs"
1122
1122
  fi
1123
- }
1124
1123
  echo ""
1125
1124
  echo "The minion should appear online in HQ shortly."
1126
1125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekbeer/minion",
3
- "version": "3.5.30",
3
+ "version": "3.5.32",
4
4
  "description": "AI Agent runtime for Minion - manages status and skill deployment on VPS",
5
5
  "main": "linux/server.js",
6
6
  "bin": {
@@ -27,12 +27,12 @@
27
27
  "postinstall": "node postinstall.js"
28
28
  },
29
29
  "dependencies": {
30
- "better-sqlite3": "^11.0.0",
31
30
  "croner": "^9.0.0",
32
31
  "fastify": "^5.2.2",
33
32
  "ws": "^8.0.0"
34
33
  },
35
34
  "optionalDependencies": {
35
+ "better-sqlite3": "^11.0.0",
36
36
  "node-pty": "^1.0.0"
37
37
  },
38
38
  "engines": {
@@ -996,7 +996,7 @@ function Invoke-Uninstall {
996
996
  }
997
997
  Write-Host ""
998
998
 
999
- $totalSteps = 6
999
+ $totalSteps = 7
1000
1000
 
1001
1001
  # Step 1: Stop and remove all NSSM services
1002
1002
  Write-Step 1 $totalSteps "Stopping and removing services..."
@@ -1103,8 +1103,43 @@ function Invoke-Uninstall {
1103
1103
  Write-Detail "Removed legacy service credentials file"
1104
1104
  }
1105
1105
 
1106
- # Step 6: Remove Cloudflare Tunnel configuration
1107
- Write-Step 6 $totalSteps "Removing Cloudflare Tunnel configuration..."
1106
+ # Step 6: Remove npm global bin from user PATH (added by postinstall)
1107
+ Write-Step 6 $totalSteps "Cleaning up PATH entries..."
1108
+ $npmBin = $null
1109
+ try { $npmBin = (& npm prefix -g 2>$null) } catch {}
1110
+ if ($npmBin) {
1111
+ $targetUserName = Split-Path $TargetUserProfile -Leaf
1112
+ $targetUserSid = $null
1113
+ try {
1114
+ $targetUserSid = (New-Object System.Security.Principal.NTAccount($targetUserName)).Translate(
1115
+ [System.Security.Principal.SecurityIdentifier]).Value
1116
+ } catch {}
1117
+ if ($targetUserSid) {
1118
+ $regPath = "Registry::HKEY_USERS\$targetUserSid\Environment"
1119
+ if (Test-Path $regPath) {
1120
+ $currentPath = (Get-ItemProperty -Path $regPath -Name PATH -ErrorAction SilentlyContinue).PATH
1121
+ if ($currentPath -and $currentPath -like "*$npmBin*") {
1122
+ $newPath = ($currentPath -split ';' | Where-Object { $_ -ne $npmBin }) -join ';'
1123
+ if ($newPath) {
1124
+ Set-ItemProperty -Path $regPath -Name PATH -Value $newPath
1125
+ } else {
1126
+ Remove-ItemProperty -Path $regPath -Name PATH -ErrorAction SilentlyContinue
1127
+ }
1128
+ Write-Detail "Removed $npmBin from target user's PATH"
1129
+ }
1130
+ }
1131
+ }
1132
+ # Also clean up the current user's PATH
1133
+ $userPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
1134
+ if ($userPath -and $userPath -like "*$npmBin*") {
1135
+ $newPath = ($userPath -split ';' | Where-Object { $_ -ne $npmBin }) -join ';'
1136
+ [Environment]::SetEnvironmentVariable('PATH', $newPath, 'User')
1137
+ Write-Detail "Removed $npmBin from current user's PATH"
1138
+ }
1139
+ }
1140
+
1141
+ # Step 7: Remove Cloudflare Tunnel configuration
1142
+ Write-Step 7 $totalSteps "Removing Cloudflare Tunnel configuration..."
1108
1143
  $cfConfigDir = Join-Path $TargetUserProfile '.cloudflared'
1109
1144
  if (Test-Path $cfConfigDir) {
1110
1145
  Remove-Item $cfConfigDir -Recurse -Force
@@ -1,13 +1,52 @@
1
- # postinstall.ps1 — Re-apply file ACLs after npm install -g replaces the package directory.
1
+ # postinstall.ps1 — Post-install tasks for @geekbeer/minion on Windows.
2
2
  # Called automatically from postinstall.js on Windows.
3
- # Requires Administrator privileges (npm install -g typically runs as admin).
4
- # Exit silently if not admin or if setup has never been run (no .target-user-profile).
3
+ #
4
+ # Tasks:
5
+ # 1. Ensure npm global bin directory is in the user's PATH (any user)
6
+ # 2. Re-apply file ACLs after npm install -g replaces the package directory (admin only)
5
7
 
6
8
  $ErrorActionPreference = 'SilentlyContinue'
7
9
 
10
+ # --- Ensure npm global bin is in PATH ----------------------------------------
11
+ # npm's global bin directory (where minion-cli-win.cmd is created) may not be in
12
+ # PATH, especially when Node.js was installed via winget or exe installer.
13
+ # Add it to the current user's persistent PATH if missing.
14
+
15
+ function Ensure-NpmBinInPath {
16
+ $npmBin = $null
17
+ try { $npmBin = (& npm prefix -g 2>$null) } catch {}
18
+ if (-not $npmBin -or -not (Test-Path $npmBin)) { return }
19
+
20
+ # Check if already in Machine or User PATH
21
+ $machinePath = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
22
+ $userPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
23
+ $allPath = "$machinePath;$userPath"
24
+
25
+ if ($allPath -split ';' | Where-Object { $_ -eq $npmBin }) { return }
26
+
27
+ # Append to User PATH
28
+ if ($userPath) {
29
+ # Remove trailing semicolons before appending
30
+ $userPath = $userPath.TrimEnd(';')
31
+ [Environment]::SetEnvironmentVariable('PATH', "$userPath;$npmBin", 'User')
32
+ } else {
33
+ [Environment]::SetEnvironmentVariable('PATH', $npmBin, 'User')
34
+ }
35
+
36
+ # Also update current session so subsequent commands in this process work
37
+ $env:PATH = "$env:PATH;$npmBin"
38
+
39
+ Write-Host "[@geekbeer/minion] Added npm global bin to PATH: $npmBin"
40
+ Write-Host "[@geekbeer/minion] Please restart your terminal for the PATH change to take effect."
41
+ }
42
+
43
+ Ensure-NpmBinInPath
44
+
8
45
  # --- Locate setup metadata ---------------------------------------------------
9
46
  # During setup, .minion/.target-user-profile is written to the target user's
10
47
  # home directory. We need to find it by scanning user profiles.
48
+ # ACL restoration requires Administrator privileges.
49
+ # Exit silently if not admin or if setup has never been run (no .target-user-profile).
11
50
 
12
51
  function Find-TargetUserProfile {
13
52
  $profiles = Get-CimInstance Win32_UserProfile -ErrorAction SilentlyContinue |