thrust-cli 1.0.0 ā 1.0.2
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/package.json +4 -1
- package/utils/daemon.js +32 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thrust-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "The local agent for Thrust AI Director",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://thrust.web.app",
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
10
|
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"thrust": "./index.js"
|
|
13
|
+
},
|
|
11
14
|
"keywords": [
|
|
12
15
|
"AI",
|
|
13
16
|
"Agent",
|
package/utils/daemon.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WebSocket, WebSocketServer } from 'ws';
|
|
1
|
+
import { WebSocket, WebSocketServer } from 'ws';
|
|
2
2
|
import chokidar from 'chokidar';
|
|
3
3
|
import simpleGit from 'simple-git';
|
|
4
4
|
import express from 'express';
|
|
@@ -129,7 +129,6 @@ export async function startDaemon(preferredPort) {
|
|
|
129
129
|
safeOpenBrowser(url);
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
// --- FIX: Using WebSocketServer constructor ---
|
|
133
132
|
localWss = new WebSocketServer({ server });
|
|
134
133
|
|
|
135
134
|
localWss.on('connection', (ws) => {
|
|
@@ -155,11 +154,35 @@ export async function startDaemon(preferredPort) {
|
|
|
155
154
|
function safeOpenBrowser(url) {
|
|
156
155
|
try {
|
|
157
156
|
if (process.env.TERMUX_VERSION) {
|
|
158
|
-
exec(`termux-open-url ${url}
|
|
157
|
+
exec(`termux-open-url ${url}`, (err) => {
|
|
158
|
+
if (err) console.log("š Please open the URL manually.");
|
|
159
|
+
});
|
|
160
|
+
} else if (!process.env.DISPLAY && process.platform === 'linux') {
|
|
161
|
+
console.log("š [Headless] Please open the URL manually in a browser.");
|
|
159
162
|
} else {
|
|
160
|
-
|
|
163
|
+
// Async wrapper to handle fallback logic safely
|
|
164
|
+
const launchBrowser = async () => {
|
|
165
|
+
try {
|
|
166
|
+
// Try to launch Chrome in minimal app mode (Requires newer open version)
|
|
167
|
+
if (open.apps && open.apps.chrome) {
|
|
168
|
+
await open(url, { app: { name: open.apps.chrome, arguments: [`--app=${url}`, '--window-size=1000,800'] } });
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error("Chrome App mode unsupported by package.");
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
// Fallback to the system's default browser safely
|
|
174
|
+
try {
|
|
175
|
+
await open(url);
|
|
176
|
+
} catch (fallbackErr) {
|
|
177
|
+
console.log("\nš OS prevented launching the browser automatically. Please open the URL above manually.\n");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
launchBrowser();
|
|
161
182
|
}
|
|
162
|
-
} catch (e) {
|
|
183
|
+
} catch (e) {
|
|
184
|
+
console.log("\nš Please open the URL above manually.\n");
|
|
185
|
+
}
|
|
163
186
|
}
|
|
164
187
|
|
|
165
188
|
async function startWatching(projectPath) {
|
|
@@ -186,23 +209,16 @@ async function startWatching(projectPath) {
|
|
|
186
209
|
}
|
|
187
210
|
}
|
|
188
211
|
|
|
189
|
-
/*
|
|
190
|
-
function connectWebSocket() {
|
|
191
|
-
try {
|
|
192
|
-
globalWs = new WebSocket(`${GATEWAY_URL}?token=YOUR_TOKEN_HERE`);
|
|
193
|
-
globalWs.on('open', () => console.log('š¢ Connected to Cloud Gateway.'));
|
|
194
|
-
globalWs.on('close', () => setTimeout(connectWebSocket, 5000));
|
|
195
|
-
} catch (err) {}
|
|
196
|
-
} */
|
|
197
212
|
function connectWebSocket() {
|
|
198
213
|
try {
|
|
199
214
|
globalWs = new WebSocket(`${GATEWAY_URL}?token=YOUR_TOKEN_HERE`);
|
|
200
215
|
|
|
201
|
-
// 1. ATTACH ERROR LISTENER IMMEDIATELY to prevent "Unhandled error" crash
|
|
202
216
|
globalWs.on('error', (err) => {
|
|
203
|
-
// We log the code, but we do NOT let it bubble up to the process
|
|
204
217
|
if (err.code === 'ECONNREFUSED') {
|
|
205
|
-
|
|
218
|
+
if (!wsRetryLogged) {
|
|
219
|
+
console.log('š“ Cloud Gateway offline (ECONNREFUSED). Will retry silently...');
|
|
220
|
+
wsRetryLogged = true;
|
|
221
|
+
}
|
|
206
222
|
} else {
|
|
207
223
|
console.error(`ā ļø Cloud Gateway Error: ${err.message}`);
|
|
208
224
|
}
|
|
@@ -234,8 +250,6 @@ function connectWebSocket() {
|
|
|
234
250
|
});
|
|
235
251
|
|
|
236
252
|
} catch (err) {
|
|
237
|
-
// Fallback catch
|
|
238
|
-
console.error('ā Failed to initialize WebSocket:', err.message);
|
|
239
253
|
setTimeout(connectWebSocket, 5000);
|
|
240
254
|
}
|
|
241
255
|
}
|