thrust-cli 1.0.6 → 1.0.7
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/index.js +75 -14
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Command } from 'commander';
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import os from 'os';
|
|
7
|
+
import { exec } from 'child_process';
|
|
7
8
|
import { fileURLToPath } from 'url';
|
|
8
9
|
import { startDaemon } from './utils/daemon.js';
|
|
9
10
|
import { getConfig, saveConfig } from './utils/config.js';
|
|
@@ -58,35 +59,95 @@ program
|
|
|
58
59
|
|
|
59
60
|
program.parse(process.argv);
|
|
60
61
|
|
|
61
|
-
// --- NATIVE,
|
|
62
|
+
// --- NATIVE, CROSS-PLATFORM OS STARTUP LOGIC ---
|
|
62
63
|
async function setupNativeStartup() {
|
|
64
|
+
// 1. Termux (Android)
|
|
63
65
|
if (process.env.TERMUX_VERSION) {
|
|
64
|
-
console.log('📱 Termux detected: Use `termux-boot` for OS startup.');
|
|
66
|
+
console.log('📱 Termux detected: (Tip: Use the `termux-boot` app for OS startup).');
|
|
65
67
|
return;
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
// 2. Windows
|
|
68
71
|
if (process.platform === 'win32') {
|
|
69
72
|
try {
|
|
70
|
-
//
|
|
73
|
+
// Cleanup ghost registry key from old auto-launch package
|
|
74
|
+
exec('reg delete "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" /v "ThrustAgent" /f', () => {});
|
|
75
|
+
|
|
71
76
|
const startupFolder = path.join(os.homedir(), 'AppData', 'Roaming', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup');
|
|
72
77
|
const batFilePath = path.join(startupFolder, 'thrust-agent.bat');
|
|
78
|
+
const batContent = `@echo off\ntitle Thrust Local Agent\necho Starting Thrust...\ntimeout /t 3 /nobreak > NUL\n"${process.execPath}" "${__filename}"\npause`;
|
|
73
79
|
|
|
74
|
-
|
|
75
|
-
// We use 'timeout' to give Windows network drivers 3 seconds to wake up before starting
|
|
76
|
-
const batContent = `@echo off\ntitle Thrust Local Agent\necho Starting Thrust...\ntimeout /t 3 /nobreak > NUL\nthrust\npause`;
|
|
77
|
-
|
|
78
|
-
// Write the .bat file if it doesn't already exist or if we need to update it
|
|
80
|
+
if (!fs.existsSync(startupFolder)) fs.mkdirSync(startupFolder, { recursive: true });
|
|
79
81
|
fs.writeFileSync(batFilePath, batContent, 'utf8');
|
|
80
|
-
console.log('⚙️ Windows Startup Script active.
|
|
82
|
+
console.log('⚙️ Windows Startup Script active.');
|
|
81
83
|
} catch (err) {
|
|
82
84
|
console.log(`⚠️ Failed to create Windows startup script: ${err.message}`);
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
|
|
88
|
+
// 3. macOS
|
|
89
|
+
else if (process.platform === 'darwin') {
|
|
90
|
+
try {
|
|
91
|
+
const launchAgentsDir = path.join(os.homedir(), 'Library', 'LaunchAgents');
|
|
92
|
+
const plistPath = path.join(launchAgentsDir, 'com.thrust.agent.plist');
|
|
93
|
+
|
|
94
|
+
// Native Mac LaunchDaemon XML Configuration
|
|
95
|
+
const plistContent = `<?xml version="1.0" encoding="UTF-8"?>
|
|
96
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
97
|
+
<plist version="1.0">
|
|
98
|
+
<dict>
|
|
99
|
+
<key>Label</key>
|
|
100
|
+
<string>com.thrust.agent</string>
|
|
101
|
+
<key>ProgramArguments</key>
|
|
102
|
+
<array>
|
|
103
|
+
<string>${process.execPath}</string>
|
|
104
|
+
<string>${__filename}</string>
|
|
105
|
+
</array>
|
|
106
|
+
<key>RunAtLoad</key>
|
|
107
|
+
<true/>
|
|
108
|
+
<key>KeepAlive</key>
|
|
109
|
+
<true/>
|
|
110
|
+
</dict>
|
|
111
|
+
</plist>`;
|
|
112
|
+
|
|
113
|
+
if (!fs.existsSync(launchAgentsDir)) fs.mkdirSync(launchAgentsDir, { recursive: true });
|
|
114
|
+
fs.writeFileSync(plistPath, plistContent, 'utf8');
|
|
115
|
+
|
|
116
|
+
// Register it quietly with the Mac OS
|
|
117
|
+
exec(`launchctl load -w "${plistPath}"`, () => {});
|
|
118
|
+
console.log('⚙️ macOS LaunchAgent active (Will run silently in background on boot).');
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.log(`⚠️ Failed to create macOS LaunchAgent: ${err.message}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 4. Linux (Ubuntu, Debian, Fedora, Mint, etc.)
|
|
125
|
+
else if (process.platform === 'linux') {
|
|
126
|
+
try {
|
|
127
|
+
if (!process.env.DISPLAY) {
|
|
128
|
+
console.log('🖥️ Headless Linux detected: Skipping GUI Autostart.');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const autostartDir = path.join(os.homedir(), '.config', 'autostart');
|
|
133
|
+
const desktopPath = path.join(autostartDir, 'thrust-agent.desktop');
|
|
134
|
+
|
|
135
|
+
// Native Linux XDG Autostart File
|
|
136
|
+
const desktopContent = `[Desktop Entry]
|
|
137
|
+
Type=Application
|
|
138
|
+
Exec="${process.execPath}" "${__filename}"
|
|
139
|
+
Hidden=false
|
|
140
|
+
NoDisplay=false
|
|
141
|
+
X-GNOME-Autostart-enabled=true
|
|
142
|
+
Name=Thrust Local Agent
|
|
143
|
+
Comment=Proactive AI Project Director
|
|
144
|
+
Terminal=true`;
|
|
145
|
+
|
|
146
|
+
if (!fs.existsSync(autostartDir)) fs.mkdirSync(autostartDir, { recursive: true });
|
|
147
|
+
fs.writeFileSync(desktopPath, desktopContent, 'utf8');
|
|
148
|
+
console.log('⚙️ Linux Autostart active (A terminal will open automatically on next reboot).');
|
|
149
|
+
} catch (err) {
|
|
150
|
+
console.log(`⚠️ Failed to create Linux startup script: ${err.message}`);
|
|
90
151
|
}
|
|
91
152
|
}
|
|
92
153
|
}
|