@mindexec/cli 0.2.20 → 0.2.21

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindexec/cli",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "MindExec local runtime and bridge CLI",
5
5
  "main": "server.js",
6
6
  "type": "module",
@@ -20,10 +20,11 @@
20
20
  "scripts": {
21
21
  "start": "node launch-bridge.cjs",
22
22
  "dev": "node launch-bridge.cjs --watch",
23
- "test:syntax": "node --check server.js && node --check remote-hub.js && node --check codex-runtime.js && node --check launch-bridge.cjs && node --check port-guard.cjs && node --check scripts/setup-tree-sitter-grammars.mjs && node --check scripts/remote-hub-smoke.mjs && node --check scripts/remote-hub-scale-smoke.mjs && node --check scripts/remote-fleet-render-smoke.mjs",
24
- "test:remote": "node scripts/remote-hub-smoke.mjs",
25
- "test:remote:scale": "node scripts/remote-hub-scale-smoke.mjs",
26
- "test:remote:render": "node scripts/remote-fleet-render-smoke.mjs",
23
+ "test:syntax": "node --check server.js && node --check remote-hub.js && node --check codex-runtime.js && node --check launch-bridge.cjs && node --check port-guard.cjs && node --check scripts/setup-tree-sitter-grammars.mjs && node --check scripts/remote-hub-smoke.mjs && node --check scripts/remote-hub-scale-smoke.mjs && node --check scripts/remote-fleet-render-smoke.mjs && node --check scripts/remote-http-smoke.mjs",
24
+ "test:remote": "node scripts/remote-hub-smoke.mjs",
25
+ "test:remote:scale": "node scripts/remote-hub-scale-smoke.mjs",
26
+ "test:remote:render": "node scripts/remote-fleet-render-smoke.mjs",
27
+ "test:remote:http": "node scripts/remote-http-smoke.mjs",
27
28
  "pack:dry": "npm pack --dry-run",
28
29
  "setup:grammars": "node scripts/setup-tree-sitter-grammars.mjs",
29
30
  "postinstall": "npm run setup:grammars"
@@ -0,0 +1,267 @@
1
+ #!/usr/bin/env node
2
+
3
+ import assert from 'node:assert/strict';
4
+ import net from 'node:net';
5
+ import { spawn } from 'node:child_process';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const BRIDGE_TOKEN = 'remote-http-smoke-token';
10
+ const PAIR_TOKEN = 'remote-http-pair-token';
11
+ const SYNTHETIC_COUNT = Number(process.env.REMOTE_HTTP_SMOKE_COUNT || 250);
12
+
13
+ function wait(ms) {
14
+ return new Promise(resolve => setTimeout(resolve, ms));
15
+ }
16
+
17
+ async function findFreePort() {
18
+ return await new Promise((resolve, reject) => {
19
+ const server = net.createServer();
20
+ server.unref();
21
+ server.once('error', reject);
22
+ server.listen(0, '127.0.0.1', () => {
23
+ const address = server.address();
24
+ const port = typeof address === 'object' && address ? address.port : 0;
25
+ server.close(() => resolve(port));
26
+ });
27
+ });
28
+ }
29
+
30
+ async function fetchJson(url, options = {}) {
31
+ const response = await fetch(url, {
32
+ ...options,
33
+ headers: {
34
+ ...(options.body ? { 'Content-Type': 'application/json' } : {}),
35
+ ...(options.token ? { 'X-Bridge-Token': options.token } : {}),
36
+ ...(options.headers || {})
37
+ }
38
+ });
39
+
40
+ let payload = null;
41
+ try {
42
+ payload = await response.json();
43
+ } catch {
44
+ // Some failure responses may be empty.
45
+ }
46
+
47
+ return {
48
+ status: response.status,
49
+ ok: response.ok,
50
+ payload
51
+ };
52
+ }
53
+
54
+ async function waitForBridge(baseUrl, getFailureDetails) {
55
+ const startedAt = Date.now();
56
+ while (Date.now() - startedAt < 30000) {
57
+ try {
58
+ const result = await fetchJson(`${baseUrl}/api/remote/status`, { token: BRIDGE_TOKEN });
59
+ if (result.ok && result.payload?.started === true) {
60
+ return result.payload;
61
+ }
62
+ } catch {
63
+ // Server is still starting.
64
+ }
65
+ await wait(100);
66
+ }
67
+
68
+ throw new Error(`Timed out waiting for LocalBridge RemoteHub HTTP API.\n${getFailureDetails()}`);
69
+ }
70
+
71
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
72
+ const bridgeRoot = path.resolve(__dirname, '..');
73
+ const bridgePort = await findFreePort();
74
+ const remoteHubPort = await findFreePort();
75
+ const baseUrl = `http://127.0.0.1:${bridgePort}`;
76
+
77
+ const child = spawn(process.execPath, ['server.js'], {
78
+ cwd: bridgeRoot,
79
+ stdio: ['ignore', 'pipe', 'pipe'],
80
+ windowsHide: true,
81
+ env: {
82
+ ...process.env,
83
+ BRIDGE_PORT: String(bridgePort),
84
+ BRIDGE_TOKEN,
85
+ BRIDGE_REQUIRE_TOKEN: '1',
86
+ MINDEXEC_REMOTE_HUB: '1',
87
+ REMOTE_HUB_HOST: '127.0.0.1',
88
+ REMOTE_HUB_PORT: String(remoteHubPort),
89
+ REMOTE_HUB_PAIR_TOKEN: PAIR_TOKEN,
90
+ MINDEXEC_REMOTE_SYNTHETIC_FLEET: '1',
91
+ NO_COLOR: '1'
92
+ }
93
+ });
94
+
95
+ let stdout = '';
96
+ let stderr = '';
97
+ child.stdout.on('data', chunk => {
98
+ stdout += chunk.toString();
99
+ });
100
+ child.stderr.on('data', chunk => {
101
+ stderr += chunk.toString();
102
+ });
103
+
104
+ const exitPromise = new Promise(resolve => child.once('exit', resolve));
105
+ const details = () => `stdout=${stdout}\nstderr=${stderr}`;
106
+
107
+ try {
108
+ const status = await waitForBridge(baseUrl, details);
109
+ assert.equal(status.started, true);
110
+ assert.equal(status.port, remoteHubPort);
111
+ assert.equal(status.agentPackage, '@mindexec/remote');
112
+ assert.equal(status.canvasPagination, 'none');
113
+ assert.equal(status.canvasDeviceListMode, 'all-devices');
114
+ assert.equal(status.pairToken, PAIR_TOKEN);
115
+
116
+ const unauthorizedStatus = await fetchJson(`${baseUrl}/api/remote/status`);
117
+ assert.equal(unauthorizedStatus.status, 401);
118
+ assert.equal(unauthorizedStatus.payload?.header, 'X-Bridge-Token');
119
+
120
+ const unauthorizedDelete = await fetchJson(`${baseUrl}/api/remote/synthetic`, {
121
+ method: 'DELETE'
122
+ });
123
+ assert.equal(unauthorizedDelete.status, 401);
124
+
125
+ const seed = await fetchJson(`${baseUrl}/api/remote/synthetic/seed`, {
126
+ method: 'POST',
127
+ token: BRIDGE_TOKEN,
128
+ body: JSON.stringify({
129
+ count: SYNTHETIC_COUNT,
130
+ connectedRatio: 0.84,
131
+ thumbnailRatio: 0.72,
132
+ aiAssistRatio: 0.42,
133
+ liveCount: 8,
134
+ replace: true
135
+ })
136
+ });
137
+ assert.equal(seed.ok, true, JSON.stringify(seed.payload));
138
+ assert.equal(seed.payload?.ok, true);
139
+ assert.equal(seed.payload?.seeded, SYNTHETIC_COUNT);
140
+
141
+ const devicesResult = await fetchJson(`${baseUrl}/api/remote/devices`, { token: BRIDGE_TOKEN });
142
+ assert.equal(devicesResult.ok, true, JSON.stringify(devicesResult.payload));
143
+ assert.equal(devicesResult.payload?.total, SYNTHETIC_COUNT);
144
+ assert.equal(devicesResult.payload?.pagination, 'none');
145
+ assert.equal(devicesResult.payload?.canvasDeviceListMode, 'all-devices');
146
+ assert.equal(devicesResult.payload?.devices?.length, SYNTHETIC_COUNT);
147
+ assert.equal(devicesResult.payload.devices.some(device => device.connected === false), true);
148
+
149
+ const connectedTargets = devicesResult.payload.devices
150
+ .filter(device => device.connected && device.capabilities?.taskDispatch)
151
+ .slice(0, 200)
152
+ .map(device => device.deviceId);
153
+ assert.ok(connectedTargets.length >= 100);
154
+
155
+ const batch = await fetchJson(`${baseUrl}/api/remote/tasks`, {
156
+ method: 'POST',
157
+ token: BRIDGE_TOKEN,
158
+ body: JSON.stringify({
159
+ deviceIds: connectedTargets,
160
+ allConnected: false,
161
+ title: 'HTTP smoke task batch',
162
+ instruction: 'HTTP smoke batch: report current status to the manager.',
163
+ approvalLevel: 'task-only'
164
+ })
165
+ });
166
+ assert.equal(batch.ok, true, JSON.stringify(batch.payload));
167
+ assert.equal(batch.payload?.ok, true);
168
+ assert.equal(batch.payload?.total, connectedTargets.length);
169
+ assert.equal(batch.payload?.queued, connectedTargets.length);
170
+ assert.equal(batch.payload?.batch?.completed, connectedTargets.length);
171
+ assert.equal(batch.payload?.batch?.failed, 0);
172
+ assert.equal(batch.payload?.batch?.status, 'completed');
173
+
174
+ const aiTarget = devicesResult.payload.devices.find(device =>
175
+ device.connected && device.capabilities?.taskDispatch && device.capabilities?.aiAssist);
176
+ assert.ok(aiTarget);
177
+ const aiTask = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(aiTarget.deviceId)}/tasks`, {
178
+ method: 'POST',
179
+ token: BRIDGE_TOKEN,
180
+ body: JSON.stringify({
181
+ title: 'HTTP smoke AI task',
182
+ instruction: 'HTTP smoke AI assist: summarize fleet condition.',
183
+ approvalLevel: 'ai-assist'
184
+ })
185
+ });
186
+ assert.equal(aiTask.ok, true, JSON.stringify(aiTask.payload));
187
+ assert.equal(aiTask.payload?.ok, true);
188
+ assert.equal(aiTask.payload?.approvalLevel, 'ai-assist');
189
+
190
+ const thumbnailTarget = devicesResult.payload.devices.find(device =>
191
+ device.connected && device.capabilities?.thumbnail);
192
+ assert.ok(thumbnailTarget);
193
+ const thumbnailRequest = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(thumbnailTarget.deviceId)}/thumbnail/request`, {
194
+ method: 'POST',
195
+ token: BRIDGE_TOKEN,
196
+ body: JSON.stringify({
197
+ streamId: 'http-smoke-thumb',
198
+ maxWidth: 360,
199
+ maxHeight: 220,
200
+ quality: 50
201
+ })
202
+ });
203
+ assert.equal(thumbnailRequest.ok, true, JSON.stringify(thumbnailRequest.payload));
204
+ assert.equal(thumbnailRequest.payload?.ok, true);
205
+
206
+ const thumbnail = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(thumbnailTarget.deviceId)}/thumbnail`, {
207
+ token: BRIDGE_TOKEN
208
+ });
209
+ assert.equal(thumbnail.ok, true, JSON.stringify(thumbnail.payload));
210
+ assert.equal(thumbnail.payload?.thumbnail?.streamId, 'http-smoke-thumb');
211
+ assert.ok(String(thumbnail.payload?.thumbnail?.dataUrl || '').startsWith('data:image/png;base64,'));
212
+
213
+ const liveTarget = devicesResult.payload.devices.find(device =>
214
+ device.connected && device.capabilities?.liveStream);
215
+ assert.ok(liveTarget);
216
+ const liveStart = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/start`, {
217
+ method: 'POST',
218
+ token: BRIDGE_TOKEN,
219
+ body: JSON.stringify({
220
+ streamId: 'http-smoke-live',
221
+ fps: 12,
222
+ maxWidth: 960,
223
+ maxHeight: 540,
224
+ quality: 60
225
+ })
226
+ });
227
+ assert.equal(liveStart.ok, true, JSON.stringify(liveStart.payload));
228
+ assert.equal(liveStart.payload?.ok, true);
229
+
230
+ const liveFrame = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/frame`, {
231
+ token: BRIDGE_TOKEN
232
+ });
233
+ assert.equal(liveFrame.ok, true, JSON.stringify(liveFrame.payload));
234
+ assert.equal(liveFrame.payload?.frame?.streamId, 'http-smoke-live');
235
+ assert.equal(liveFrame.payload?.frame?.mode, 'remote-fast');
236
+
237
+ const liveStop = await fetchJson(`${baseUrl}/api/remote/devices/${encodeURIComponent(liveTarget.deviceId)}/live/stop`, {
238
+ method: 'POST',
239
+ token: BRIDGE_TOKEN,
240
+ body: JSON.stringify({
241
+ streamId: 'http-smoke-live'
242
+ })
243
+ });
244
+ assert.equal(liveStop.ok, true, JSON.stringify(liveStop.payload));
245
+ assert.equal(liveStop.payload?.ok, true);
246
+
247
+ const clear = await fetchJson(`${baseUrl}/api/remote/synthetic`, {
248
+ method: 'DELETE',
249
+ token: BRIDGE_TOKEN
250
+ });
251
+ assert.equal(clear.ok, true, JSON.stringify(clear.payload));
252
+ assert.equal(clear.payload?.ok, true);
253
+ assert.equal(clear.payload?.removed, SYNTHETIC_COUNT);
254
+
255
+ console.log(`RemoteHub HTTP smoke OK (${SYNTHETIC_COUNT} synthetic devices, bridge ${bridgePort}, remote ${remoteHubPort})`);
256
+ } finally {
257
+ if (child.exitCode === null && !child.killed) {
258
+ child.kill('SIGTERM');
259
+ await Promise.race([
260
+ exitPromise,
261
+ wait(5000)
262
+ ]);
263
+ if (child.exitCode === null && !child.killed) {
264
+ child.kill('SIGKILL');
265
+ }
266
+ }
267
+ }
package/server.js CHANGED
@@ -1750,6 +1750,7 @@ const PROTECTED_BRIDGE_ROUTES = [
1750
1750
  { method: 'POST', prefix: '/api/shell/' },
1751
1751
  { method: 'GET', prefix: '/api/remote/' },
1752
1752
  { method: 'POST', prefix: '/api/remote/' },
1753
+ { method: 'DELETE', prefix: '/api/remote/' },
1753
1754
  { method: 'POST', prefix: '/project/' },
1754
1755
  { method: 'POST', exact: '/agent/connect' },
1755
1756
  { method: 'POST', exact: '/api/tool/trace' }