@aiassesstech/mighty-mark 0.5.5 → 0.5.6

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": "@aiassesstech/mighty-mark",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "System Health Sentinel for AI Assess Tech Fleet — autonomous monitoring, watchdog recovery, and fleet infrastructure oversight.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -337,78 +337,99 @@ echo ""
337
337
  # 6. Fleet-Bus Transport Test (requires --live)
338
338
  ###############################################################################
339
339
  if $LIVE_TEST; then
340
- echo "=== 6. Live Transport Test (fleet/ping) ==="
341
-
342
- GW_PORT=$(python3 -c "
343
- import json
344
- with open('$OPENCLAW_HOME/openclaw.json') as f:
345
- cfg = json.load(f)
346
- print(cfg.get('gateway', {}).get('port', 18789))
347
- " 2>/dev/null || echo "18789")
348
-
349
- GW_TOKEN=$(python3 -c "
350
- import json
351
- with open('$OPENCLAW_HOME/openclaw.json') as f:
352
- cfg = json.load(f)
353
- print(cfg.get('gateway', {}).get('auth', {}).get('token', ''))
354
- " 2>/dev/null || echo "")
340
+ echo "=== 6. Live Transport Test (fleet/ping via callGateway) ==="
341
+
342
+ LIVE_SCRIPT=$(mktemp /tmp/fleet-live-ping-XXXXXX.mjs)
343
+ cat > "$LIVE_SCRIPT" << 'NODESCRIPT'
344
+ import { existsSync } from 'node:fs';
345
+ import { dirname, join } from 'node:path';
346
+ import { randomBytes } from 'node:crypto';
347
+
348
+ async function resolveCallGateway() {
349
+ const mainScript = process.argv[1] ?? '';
350
+ const home = process.env.HOME ?? '/root';
351
+ const packageNames = ['clawdbot', 'openclaw'];
352
+ const globalRoots = [
353
+ '/usr/lib/node_modules',
354
+ '/usr/local/lib/node_modules',
355
+ join(home, '.local', 'lib', 'node_modules'),
356
+ ];
357
+ const paths = globalRoots.flatMap(root =>
358
+ packageNames.map(pkg => join(root, pkg, 'dist', 'gateway', 'call.js'))
359
+ );
360
+ for (const p of paths) {
361
+ if (!existsSync(p)) continue;
362
+ try {
363
+ const mod = await import(`file://${p}`);
364
+ if (typeof mod.callGateway === 'function') return mod.callGateway;
365
+ } catch {}
366
+ }
367
+ return null;
368
+ }
355
369
 
356
- GW_URL="http://127.0.0.1:${GW_PORT}"
370
+ try {
371
+ const callGateway = await resolveCallGateway();
372
+ if (!callGateway) {
373
+ console.log('RESULT:FAIL:callGateway not resolved — gateway/call.js not found');
374
+ process.exit(0);
375
+ }
376
+
377
+ const msg = {
378
+ id: `fm-diag-${Date.now()}-${randomBytes(4).toString('hex')}`,
379
+ from: 'mighty-mark',
380
+ to: 'jessie',
381
+ method: 'fleet/ping',
382
+ params: { source: 'diagnostics', timestamp: new Date().toISOString() },
383
+ timestamp: new Date().toISOString(),
384
+ nonce: randomBytes(8).toString('hex'),
385
+ version: '1.0',
386
+ };
387
+
388
+ const serialized = '%%FLEET%%' + JSON.stringify(msg);
389
+ const start = Date.now();
390
+
391
+ const result = await callGateway({
392
+ method: 'agent',
393
+ params: {
394
+ agentId: 'jessie',
395
+ message: serialized,
396
+ deliver: false,
397
+ timeoutSeconds: 15,
398
+ label: 'fleet:fleet/ping',
399
+ },
400
+ timeoutMs: 20000,
401
+ mode: 'backend',
402
+ clientName: 'fleet-bus-diagnostics',
403
+ clientDisplayName: 'Fleet Diagnostics',
404
+ });
405
+
406
+ const duration = Date.now() - start;
407
+ const hasResponse = result && (typeof result === 'object' || typeof result === 'string');
408
+
409
+ if (hasResponse) {
410
+ const summary = typeof result === 'string' ? result.slice(0, 100) : JSON.stringify(result).slice(0, 100);
411
+ console.log(`RESULT:PASS:fleet/ping delivered to jessie (${duration}ms) — response: ${summary}`);
412
+ } else {
413
+ console.log(`RESULT:PASS:fleet/ping accepted by gateway (${duration}ms) — fire-and-forget`);
414
+ }
415
+ } catch (err) {
416
+ console.log(`RESULT:FAIL:${err.message?.slice(0, 150) || 'unknown error'}`);
417
+ }
418
+ process.exit(0);
419
+ NODESCRIPT
357
420
 
358
- if [ -z "$GW_TOKEN" ]; then
359
- check "Gateway token" "WARN" "no auth token found — live test may fail"
360
- fi
421
+ LIVE_RESULT=$(node "$LIVE_SCRIPT" 2>/dev/null || echo "RESULT:FAIL:node execution failed")
422
+ rm -f "$LIVE_SCRIPT"
361
423
 
362
- echo " Gateway: $GW_URL"
363
- echo ""
424
+ LIVE_STATUS=$(echo "$LIVE_RESULT" | grep '^RESULT:' | head -1 | cut -d: -f2)
425
+ LIVE_DETAIL=$(echo "$LIVE_RESULT" | grep '^RESULT:' | head -1 | cut -d: -f3-)
364
426
 
365
- PING_MSG=$(python3 -c "
366
- import json, time, secrets
367
- msg = {
368
- 'id': f'fm-diag-{int(time.time())}-{secrets.token_hex(4)}',
369
- 'from': 'mighty-mark',
370
- 'to': 'jessie',
371
- 'method': 'fleet/ping',
372
- 'params': {'source': 'diagnostics', 'timestamp': '$(date -u +%Y-%m-%dT%H:%M:%SZ)'},
373
- 'timestamp': '$(date -u +%Y-%m-%dT%H:%M:%SZ)',
374
- 'nonce': secrets.token_hex(8),
375
- 'version': '1.0'
376
- }
377
- print('%%FLEET%%' + json.dumps(msg))
378
- ")
379
-
380
- RESPONSE=$(curl -s -w "\n%{http_code}" \
381
- -X POST "$GW_URL/api/v1/agent" \
382
- -H "Content-Type: application/json" \
383
- -H "Authorization: Bearer $GW_TOKEN" \
384
- -d "$(python3 -c "
385
- import json
386
- print(json.dumps({
387
- 'agentId': 'jessie',
388
- 'message': '''$PING_MSG''',
389
- 'deliver': False,
390
- 'timeoutSeconds': 10,
391
- 'label': 'fleet:fleet/ping'
392
- }))
393
- ")" 2>/dev/null || echo -e "\n000")
394
-
395
- HTTP_CODE=$(echo "$RESPONSE" | tail -1)
396
- BODY=$(echo "$RESPONSE" | head -n -1)
397
-
398
- if [ "$HTTP_CODE" = "200" ]; then
399
- check "Live ping (Mark → Jessie)" "PASS" "HTTP 200 — gateway accepted fleet/ping"
400
- if $VERBOSE; then
401
- echo " Response: $(echo "$BODY" | head -c 200)"
402
- fi
403
- elif [ "$HTTP_CODE" = "401" ] || [ "$HTTP_CODE" = "403" ]; then
404
- check "Live ping (Mark → Jessie)" "FAIL" "HTTP $HTTP_CODE — auth rejected (check gateway token)"
405
- elif [ "$HTTP_CODE" = "000" ]; then
406
- check "Live ping (Mark → Jessie)" "FAIL" "connection refused — is the gateway running?"
427
+ if [ "$LIVE_STATUS" = "PASS" ]; then
428
+ check "Live ping (Mark → Jessie)" "PASS" "$LIVE_DETAIL"
429
+ elif [ "$LIVE_STATUS" = "FAIL" ]; then
430
+ check "Live ping (Mark → Jessie)" "FAIL" "$LIVE_DETAIL"
407
431
  else
408
- check "Live ping (Mark → Jessie)" "WARN" "HTTP $HTTP_CODE — unexpected response"
409
- if $VERBOSE; then
410
- echo " Response: $(echo "$BODY" | head -c 200)"
411
- fi
432
+ check "Live ping (Mark → Jessie)" "WARN" "unexpected result: $LIVE_RESULT"
412
433
  fi
413
434
  echo ""
414
435
  fi