commanderclaw 1.1.10 → 1.1.11
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/commanderclaw.cjs +163 -14
- package/dist/cli/index.js +1 -1
- package/package.json +1 -1
package/bin/commanderclaw.cjs
CHANGED
|
@@ -7,12 +7,17 @@ const fs = require('fs');
|
|
|
7
7
|
|
|
8
8
|
const command = process.argv[2];
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const SERVER_PORT = 19739;
|
|
11
|
+
const WEB_PORT = 19730;
|
|
12
|
+
const SERVER_PID_FILE = '/tmp/commanderclaw-server.pid';
|
|
13
|
+
const WEB_PID_FILE = '/tmp/commanderclaw-web.pid';
|
|
14
|
+
const SERVER_LOG_FILE = '/tmp/commanderclaw-server.log';
|
|
15
|
+
const WEB_LOG_FILE = '/tmp/commanderclaw-web.log';
|
|
16
|
+
|
|
11
17
|
function getPlatformId() {
|
|
12
18
|
const platform = os.platform();
|
|
13
19
|
const arch = os.arch();
|
|
14
20
|
|
|
15
|
-
// Normalize architecture
|
|
16
21
|
let normalizedArch = arch;
|
|
17
22
|
if (arch === 'x64' || arch === 'amd64') {
|
|
18
23
|
normalizedArch = 'x64';
|
|
@@ -23,9 +28,25 @@ function getPlatformId() {
|
|
|
23
28
|
return `${platform}-${normalizedArch}`;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
function isProcessRunning(pidFile) {
|
|
32
|
+
if (!fs.existsSync(pidFile)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const pid = parseInt(fs.readFileSync(pidFile, 'utf-8').trim(), 10);
|
|
37
|
+
if (isNaN(pid)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
process.kill(pid, 0);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function startServer() {
|
|
29
50
|
const platformId = getPlatformId();
|
|
30
51
|
const ext = os.platform() === 'win32' ? '.exe' : '';
|
|
31
52
|
const binaryPath = path.join(
|
|
@@ -49,23 +70,151 @@ if (command === 'gateway' && process.argv[3] === 'start') {
|
|
|
49
70
|
|
|
50
71
|
const configPath = path.join(__dirname, '..', 'configs', 'server.yaml');
|
|
51
72
|
const args = ['-config', configPath, ...process.argv.slice(4)];
|
|
73
|
+
const logFile = fs.openSync(SERVER_LOG_FILE, 'a');
|
|
74
|
+
|
|
52
75
|
const child = spawn(binaryPath, args, {
|
|
53
|
-
|
|
76
|
+
detached: true,
|
|
77
|
+
stdio: ['ignore', logFile, logFile],
|
|
54
78
|
env: { ...process.env },
|
|
55
|
-
shell: os.platform() === 'win32'
|
|
56
79
|
});
|
|
57
80
|
|
|
58
|
-
child.
|
|
59
|
-
|
|
60
|
-
process.exit(1);
|
|
61
|
-
});
|
|
81
|
+
child.unref();
|
|
82
|
+
fs.writeFileSync(SERVER_PID_FILE, String(child.pid));
|
|
62
83
|
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function startWeb() {
|
|
88
|
+
const webServerPath = path.join(__dirname, 'web-server.cjs');
|
|
89
|
+
const webDir = path.join(__dirname, '..', 'web');
|
|
90
|
+
|
|
91
|
+
if (!fs.existsSync(webDir)) {
|
|
92
|
+
console.log('(web directory not found, skipping)');
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const logFile = fs.openSync(WEB_LOG_FILE, 'a');
|
|
97
|
+
|
|
98
|
+
const child = spawn('node', [webServerPath], {
|
|
99
|
+
detached: true,
|
|
100
|
+
stdio: ['ignore', logFile, logFile],
|
|
101
|
+
env: { ...process.env, PORT: String(WEB_PORT) },
|
|
65
102
|
});
|
|
103
|
+
|
|
104
|
+
child.unref();
|
|
105
|
+
fs.writeFileSync(WEB_PID_FILE, String(child.pid));
|
|
106
|
+
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (command === 'gateway' && process.argv[3] === 'start') {
|
|
111
|
+
const serverRunning = isProcessRunning(SERVER_PID_FILE);
|
|
112
|
+
const webRunning = isProcessRunning(WEB_PID_FILE);
|
|
113
|
+
|
|
114
|
+
if (serverRunning && webRunning) {
|
|
115
|
+
console.log('Gateway is already running');
|
|
116
|
+
console.log(` Server: http://127.0.0.1:${SERVER_PORT}`);
|
|
117
|
+
console.log(` Web Console: http://127.0.0.1:${WEB_PORT}`);
|
|
118
|
+
process.exit(0);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!serverRunning) {
|
|
122
|
+
process.stdout.write(`Starting server on port ${SERVER_PORT}... `);
|
|
123
|
+
if (startServer()) {
|
|
124
|
+
console.log('OK');
|
|
125
|
+
} else {
|
|
126
|
+
console.log('Failed');
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!webRunning) {
|
|
132
|
+
process.stdout.write(`Starting web console on port ${WEB_PORT}... `);
|
|
133
|
+
if (startWeb()) {
|
|
134
|
+
console.log('OK');
|
|
135
|
+
} else {
|
|
136
|
+
console.log('Failed');
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log();
|
|
142
|
+
console.log('Gateway started successfully!');
|
|
143
|
+
console.log(` Server: http://127.0.0.1:${SERVER_PORT}`);
|
|
144
|
+
console.log(` WebSocket: ws://127.0.0.1:${SERVER_PORT}/ws`);
|
|
145
|
+
console.log(` Web Console: http://127.0.0.1:${WEB_PORT}`);
|
|
146
|
+
console.log();
|
|
147
|
+
console.log('Logs:');
|
|
148
|
+
console.log(` Server: ${SERVER_LOG_FILE}`);
|
|
149
|
+
console.log(` Web: ${WEB_LOG_FILE}`);
|
|
150
|
+
process.exit(0);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
else if (command === 'gateway' && process.argv[3] === 'stop') {
|
|
154
|
+
process.stdout.write('Stopping web console... ');
|
|
155
|
+
if (isProcessRunning(WEB_PID_FILE)) {
|
|
156
|
+
const pid = parseInt(fs.readFileSync(WEB_PID_FILE, 'utf-8').trim(), 10);
|
|
157
|
+
try {
|
|
158
|
+
process.kill(pid, 'SIGTERM');
|
|
159
|
+
} catch {}
|
|
160
|
+
fs.unlinkSync(WEB_PID_FILE);
|
|
161
|
+
console.log('OK');
|
|
162
|
+
} else {
|
|
163
|
+
console.log('(not running)');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
process.stdout.write('Stopping server... ');
|
|
167
|
+
if (isProcessRunning(SERVER_PID_FILE)) {
|
|
168
|
+
const pid = parseInt(fs.readFileSync(SERVER_PID_FILE, 'utf-8').trim(), 10);
|
|
169
|
+
try {
|
|
170
|
+
process.kill(pid, 'SIGTERM');
|
|
171
|
+
} catch {}
|
|
172
|
+
fs.unlinkSync(SERVER_PID_FILE);
|
|
173
|
+
console.log('OK');
|
|
174
|
+
} else {
|
|
175
|
+
console.log('(not running)');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
console.log('Gateway stopped');
|
|
179
|
+
process.exit(0);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
else if (command === 'gateway' && process.argv[3] === 'status') {
|
|
183
|
+
console.log('CommanderClaw Gateway Status');
|
|
184
|
+
console.log('-'.repeat(40));
|
|
185
|
+
|
|
186
|
+
const serverRunning = isProcessRunning(SERVER_PID_FILE);
|
|
187
|
+
const webRunning = isProcessRunning(WEB_PID_FILE);
|
|
188
|
+
|
|
189
|
+
let serverStatus = 'stopped';
|
|
190
|
+
let serverPid = '';
|
|
191
|
+
if (serverRunning) {
|
|
192
|
+
serverStatus = 'running';
|
|
193
|
+
serverPid = fs.readFileSync(SERVER_PID_FILE, 'utf-8').trim();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let webStatus = 'stopped';
|
|
197
|
+
let webPid = '';
|
|
198
|
+
if (webRunning) {
|
|
199
|
+
webStatus = 'running';
|
|
200
|
+
webPid = fs.readFileSync(WEB_PID_FILE, 'utf-8').trim();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
console.log(`Server (port ${SERVER_PORT}): ${serverStatus}${serverPid ? ` (PID: ${serverPid})` : ''}`);
|
|
204
|
+
console.log(`Web (port ${WEB_PORT}): ${webStatus}${webPid ? ` (PID: ${webPid})` : ''}`);
|
|
205
|
+
|
|
206
|
+
if (serverRunning) {
|
|
207
|
+
console.log();
|
|
208
|
+
console.log(`Server URL: http://127.0.0.1:${SERVER_PORT}`);
|
|
209
|
+
console.log(`WebSocket: ws://127.0.0.1:${SERVER_PORT}/ws`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (webRunning) {
|
|
213
|
+
console.log(`Web Console: http://127.0.0.1:${WEB_PORT}`);
|
|
214
|
+
}
|
|
215
|
+
process.exit(0);
|
|
66
216
|
}
|
|
67
217
|
|
|
68
|
-
// Other commands use TypeScript implementation
|
|
69
218
|
else {
|
|
70
219
|
const cliPath = path.join(__dirname, '..', 'dist', 'cli', 'index.js');
|
|
71
220
|
|
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { handleGateway } from './gateway.js';
|
|
2
2
|
import { handlePlugin } from './plugin.js';
|
|
3
3
|
import { handleConfig } from './config.js';
|
|
4
|
-
const VERSION = '1.1.
|
|
4
|
+
const VERSION = '1.1.11';
|
|
5
5
|
function printUsage() {
|
|
6
6
|
console.log('CommanderClaw - Multi-device Agent Coordination Framework');
|
|
7
7
|
console.log();
|