commanderclaw 1.1.10 → 1.1.12

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.
@@ -1,78 +1,2 @@
1
1
  #!/usr/bin/env node
2
-
3
- const path = require('path');
4
- const { spawn } = require('child_process');
5
- const os = require('os');
6
- const fs = require('fs');
7
-
8
- const command = process.argv[2];
9
-
10
- // Helper to get platform identifier
11
- function getPlatformId() {
12
- const platform = os.platform();
13
- const arch = os.arch();
14
-
15
- // Normalize architecture
16
- let normalizedArch = arch;
17
- if (arch === 'x64' || arch === 'amd64') {
18
- normalizedArch = 'x64';
19
- } else if (arch === 'arm64' || arch === 'aarch64') {
20
- normalizedArch = 'arm64';
21
- }
22
-
23
- return `${platform}-${normalizedArch}`;
24
- }
25
-
26
- // Gateway start uses pre-compiled binary
27
- // Other gateway commands use TypeScript implementation
28
- if (command === 'gateway' && process.argv[3] === 'start') {
29
- const platformId = getPlatformId();
30
- const ext = os.platform() === 'win32' ? '.exe' : '';
31
- const binaryPath = path.join(
32
- __dirname,
33
- '..',
34
- 'binaries',
35
- platformId,
36
- `coordination-server${ext}`
37
- );
38
-
39
- if (!fs.existsSync(binaryPath)) {
40
- console.error(`Error: Unsupported platform: ${platformId}`);
41
- console.error('');
42
- console.error('Supported platforms:');
43
- console.error(' - darwin-x64 (macOS Intel)');
44
- console.error(' - darwin-arm64 (macOS Apple Silicon)');
45
- console.error(' - linux-x64 (Linux)');
46
- console.error(' - win32-x64 (Windows)');
47
- process.exit(1);
48
- }
49
-
50
- const configPath = path.join(__dirname, '..', 'configs', 'server.yaml');
51
- const args = ['-config', configPath, ...process.argv.slice(4)];
52
- const child = spawn(binaryPath, args, {
53
- stdio: 'inherit',
54
- env: { ...process.env },
55
- shell: os.platform() === 'win32'
56
- });
57
-
58
- child.on('error', (err) => {
59
- console.error('Failed to start server:', err.message);
60
- process.exit(1);
61
- });
62
-
63
- child.on('exit', (code) => {
64
- process.exit(code || 0);
65
- });
66
- }
67
-
68
- // Other commands use TypeScript implementation
69
- else {
70
- const cliPath = path.join(__dirname, '..', 'dist', 'cli', 'index.js');
71
-
72
- if (!fs.existsSync(cliPath)) {
73
- console.error('Error: CLI not built. Run: npm run build');
74
- process.exit(1);
75
- }
76
-
77
- require(cliPath);
78
- }
2
+ import('../dist/cli/index.js');
@@ -1,8 +1,10 @@
1
1
  const http = require('http');
2
+ const net = require('net');
2
3
  const fs = require('fs');
3
4
  const path = require('path');
4
5
 
5
- const PORT = process.env.PORT || 19730;
6
+ const WEB_PORT = process.env.PORT || 19730;
7
+ const SERVER_PORT = 19739;
6
8
  const WEB_DIR = path.join(__dirname, '..', 'web');
7
9
 
8
10
  const MIME_TYPES = {
@@ -16,6 +18,11 @@ const MIME_TYPES = {
16
18
  };
17
19
 
18
20
  const server = http.createServer((req, res) => {
21
+ if (req.url.startsWith('/api/')) {
22
+ proxyRequest(req, res, SERVER_PORT);
23
+ return;
24
+ }
25
+
19
26
  let filePath = path.join(WEB_DIR, req.url === '/' ? 'index.html' : req.url);
20
27
  const ext = path.extname(filePath).toLowerCase();
21
28
  const contentType = MIME_TYPES[ext] || 'application/octet-stream';
@@ -43,6 +50,87 @@ const server = http.createServer((req, res) => {
43
50
  });
44
51
  });
45
52
 
46
- server.listen(PORT, '0.0.0.0', () => {
47
- console.log(`Web console running at http://127.0.0.1:${PORT}`);
53
+ function proxyRequest(req, res, targetPort) {
54
+ const options = {
55
+ hostname: '127.0.0.1',
56
+ port: targetPort,
57
+ path: req.url,
58
+ method: req.method,
59
+ headers: {
60
+ ...req.headers,
61
+ host: `127.0.0.1:${targetPort}`,
62
+ },
63
+ };
64
+
65
+ const proxyReq = http.request(options, (proxyRes) => {
66
+ res.writeHead(proxyRes.statusCode, proxyRes.headers);
67
+ proxyRes.pipe(res);
68
+ });
69
+
70
+ proxyReq.on('error', (err) => {
71
+ console.error('Proxy error:', err.message);
72
+ res.writeHead(502);
73
+ res.end(JSON.stringify({ error: 'Bad Gateway' }));
74
+ });
75
+
76
+ req.pipe(proxyReq);
77
+ }
78
+
79
+ server.on('upgrade', (req, socket, head) => {
80
+ if (req.url === '/ws' || req.url.startsWith('/ws?')) {
81
+ const targetPort = SERVER_PORT;
82
+
83
+ const proxyReq = http.request({
84
+ hostname: '127.0.0.1',
85
+ port: targetPort,
86
+ path: req.url,
87
+ method: 'GET',
88
+ headers: {
89
+ ...req.headers,
90
+ host: `127.0.0.1:${targetPort}`,
91
+ },
92
+ });
93
+
94
+ proxyReq.on('response', (res) => {
95
+ res.pipe(socket);
96
+ });
97
+
98
+ proxyReq.on('upgrade', (proxyRes, proxySocket, proxyHead) => {
99
+ proxyRes.on('end', () => {
100
+ socket.end();
101
+ });
102
+
103
+ socket.on('error', (err) => {
104
+ proxySocket.end();
105
+ });
106
+
107
+ proxySocket.on('error', (err) => {
108
+ socket.end();
109
+ });
110
+
111
+ socket.write(
112
+ 'HTTP/1.1 101 Switching Protocols\r\n' +
113
+ Object.entries(proxyRes.headers)
114
+ .map(([k, v]) => `${k}: ${v}`)
115
+ .join('\r\n') +
116
+ '\r\n\r\n'
117
+ );
118
+
119
+ proxySocket.pipe(socket);
120
+ socket.pipe(proxySocket);
121
+ });
122
+
123
+ proxyReq.on('error', (err) => {
124
+ console.error('WebSocket proxy error:', err.message);
125
+ socket.end();
126
+ });
127
+
128
+ proxyReq.end();
129
+ }
130
+ });
131
+
132
+ server.listen(WEB_PORT, '0.0.0.0', () => {
133
+ console.log(`Web console running at http://127.0.0.1:${WEB_PORT}`);
134
+ console.log(`Proxying /ws -> ws://127.0.0.1:${SERVER_PORT}/ws`);
135
+ console.log(`Proxying /api -> http://127.0.0.1:${SERVER_PORT}/api`);
48
136
  });
@@ -1,8 +1,12 @@
1
1
  import * as path from 'path';
2
2
  import * as fs from 'fs';
3
3
  import * as os from 'os';
4
+ import * as http from 'http';
5
+ import { fileURLToPath } from 'url';
4
6
  import { spawn, execSync } from 'child_process';
5
7
  import { getProjectRoot } from './utils.js';
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
6
10
  const SERVER_PORT = 19739;
7
11
  const WEB_PORT = 19730;
8
12
  const SERVER_PID_FILE = '/tmp/commanderclaw-server.pid';
@@ -108,7 +112,7 @@ function stopProcess(pidFile) {
108
112
  catch { }
109
113
  fs.unlinkSync(pidFile);
110
114
  }
111
- function gatewayStart() {
115
+ async function gatewayStart() {
112
116
  const serverRunning = isProcessRunning(SERVER_PID_FILE);
113
117
  const webRunning = isProcessRunning(WEB_PID_FILE);
114
118
  if (serverRunning && webRunning) {
@@ -120,7 +124,14 @@ function gatewayStart() {
120
124
  if (!serverRunning) {
121
125
  process.stdout.write(`Starting server on port ${SERVER_PORT}... `);
122
126
  if (startServer()) {
123
- console.log('OK');
127
+ const started = await waitForServer(SERVER_PORT, 5000);
128
+ if (started) {
129
+ console.log('OK');
130
+ }
131
+ else {
132
+ console.log('Failed (timeout waiting for server)');
133
+ process.exit(1);
134
+ }
124
135
  }
125
136
  else {
126
137
  console.log('Failed');
@@ -150,26 +161,58 @@ function gatewayStart() {
150
161
  function startServer() {
151
162
  try {
152
163
  const binaryPath = getBinaryPath();
153
- const logFile = fs.openSync(SERVER_LOG_FILE, 'a');
164
+ if (!fs.existsSync(binaryPath)) {
165
+ console.error(`Server binary not found: ${binaryPath}`);
166
+ return false;
167
+ }
168
+ const logStream = fs.createWriteStream(SERVER_LOG_FILE, { flags: 'a' });
154
169
  const child = spawn(binaryPath, ['-port', String(SERVER_PORT)], {
155
170
  detached: true,
156
- stdio: ['ignore', logFile, logFile],
171
+ stdio: ['ignore', 'pipe', 'pipe'],
172
+ });
173
+ child.stdout?.pipe(logStream);
174
+ child.stderr?.pipe(logStream);
175
+ child.on('error', (err) => {
176
+ console.error(`Failed to start server: ${err.message}`);
157
177
  });
158
178
  child.unref();
159
- fs.writeFileSync(SERVER_PID_FILE, String(child.pid));
160
- // Wait a bit to verify it started
161
- setTimeout(() => {
162
- if (!isProcessRunning(SERVER_PID_FILE)) {
163
- console.log('\nServer process exited immediately. Check logs at ' + SERVER_LOG_FILE);
164
- process.exit(1);
165
- }
166
- }, 500);
179
+ const pid = child.pid;
180
+ if (!pid) {
181
+ return false;
182
+ }
183
+ fs.writeFileSync(SERVER_PID_FILE, String(pid));
167
184
  return true;
168
185
  }
169
186
  catch (e) {
187
+ console.error(`Failed to start server: ${e.message}`);
170
188
  return false;
171
189
  }
172
190
  }
191
+ function waitForServer(port, timeoutMs = 5000) {
192
+ return new Promise((resolve) => {
193
+ const startTime = Date.now();
194
+ const check = () => {
195
+ if (Date.now() - startTime > timeoutMs) {
196
+ resolve(false);
197
+ return;
198
+ }
199
+ const req = http.get(`http://127.0.0.1:${port}/api/health`, { timeout: 500 }, (res) => {
200
+ if (res.statusCode === 200) {
201
+ resolve(true);
202
+ }
203
+ else {
204
+ setTimeout(check, 200);
205
+ }
206
+ });
207
+ req.on('error', () => setTimeout(check, 200));
208
+ req.on('timeout', () => {
209
+ req.destroy();
210
+ setTimeout(check, 200);
211
+ });
212
+ };
213
+ check();
214
+ });
215
+ }
173
216
  function startWeb() {
174
217
  try {
175
218
  const packageDir = path.dirname(path.dirname(__dirname));
@@ -212,12 +255,12 @@ function gatewayStop() {
212
255
  }
213
256
  console.log('Gateway stopped');
214
257
  }
215
- function gatewayRestart() {
258
+ async function gatewayRestart() {
216
259
  console.log('Restarting gateway...');
217
260
  gatewayStop();
218
- setTimeout(() => {
261
+ setTimeout(async () => {
219
262
  console.log();
220
- gatewayStart();
263
+ await gatewayStart();
221
264
  }, 500);
222
265
  }
223
266
  function gatewayStatus() {
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.9';
4
+ const VERSION = '1.1.12';
5
5
  function printUsage() {
6
6
  console.log('CommanderClaw - Multi-device Agent Coordination Framework');
7
7
  console.log();
@@ -8,7 +8,7 @@ declare const plugin: {
8
8
  id: string;
9
9
  name: string;
10
10
  description: string;
11
- configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
11
+ configSchema: any;
12
12
  register(api: any): void;
13
13
  };
14
14
  export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commanderclaw",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "Multi-device Agent Coordination Framework - CLI and OpenClaw/QClaw Plugin",
5
5
  "type": "module",
6
6
  "bin": {