nothumanallowed 14.4.2 → 14.4.4

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": "nothumanallowed",
3
- "version": "14.4.2",
3
+ "version": "14.4.4",
4
4
  "description": "NotHumanAllowed — 38 AI agents, 80 tools, Studio (visual agentic workflows). Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, Alexandria E2E messaging, GitHub, Notion, Slack, voice chat, free AI (Liara), 28 languages. Zero-dependency CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -50,18 +50,37 @@ export async function cmdUI(args) {
50
50
  console.log(` \x1b[33m!\x1b[0m Killed previous process on port ${port} (PID ${pid})`);
51
51
  }
52
52
  } else {
53
- // Unix/Mac: lsof to find and kill
54
- const out = execSync(`lsof -ti:${port} 2>/dev/null`, { encoding: 'utf-8', timeout: 3000 }).trim();
55
- if (out) {
56
- const pids = out.split('\n').filter((p) => p && p !== String(process.pid));
57
- for (const pid of pids) {
58
- try { process.kill(parseInt(pid), 'SIGTERM'); } catch {}
59
- }
60
- if (pids.length > 0) {
61
- console.log(` \x1b[33m!\x1b[0m Killed previous process on port ${port} (PID ${pids.join(', ')})`);
62
- await new Promise((r) => setTimeout(r, 500)); // wait for port to free
53
+ // Unix/Mac: try lsof first, then fuser, then ss+kill as fallbacks
54
+ let killed = false;
55
+ // Method 1: lsof
56
+ try {
57
+ const out = execSync(`lsof -ti:${port} 2>/dev/null`, { encoding: 'utf-8', timeout: 3000 }).trim();
58
+ if (out) {
59
+ const pids = out.split('\n').filter((p) => p && p !== String(process.pid));
60
+ for (const pid of pids) { try { process.kill(parseInt(pid), 'SIGTERM'); } catch {} }
61
+ if (pids.length > 0) { killed = true; console.log(` \x1b[33m!\x1b[0m Killed previous process on port ${port} (PID ${pids.join(', ')})`); }
63
62
  }
63
+ } catch {}
64
+ // Method 2: fuser (Linux without lsof)
65
+ if (!killed) {
66
+ try {
67
+ execSync(`fuser -k ${port}/tcp 2>/dev/null`, { timeout: 3000, stdio: 'ignore' });
68
+ killed = true;
69
+ console.log(` \x1b[33m!\x1b[0m Killed previous process on port ${port} (via fuser)`);
70
+ } catch {}
71
+ }
72
+ // Method 3: ss + kill (minimal Linux)
73
+ if (!killed) {
74
+ try {
75
+ const out = execSync(`ss -tlnp 2>/dev/null | grep :${port}`, { encoding: 'utf-8', timeout: 3000 }).trim();
76
+ const pidMatch = out.match(/pid=(\d+)/);
77
+ if (pidMatch) {
78
+ try { process.kill(parseInt(pidMatch[1]), 'SIGTERM'); killed = true; } catch {}
79
+ if (killed) console.log(` \x1b[33m!\x1b[0m Killed previous process on port ${port} (PID ${pidMatch[1]})`);
80
+ }
81
+ } catch {}
64
82
  }
83
+ if (killed) await new Promise((r) => setTimeout(r, 500));
65
84
  }
66
85
  } catch { /* port is free */ }
67
86
 
package/src/constants.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
 
8
- export const VERSION = '14.4.2';
8
+ export const VERSION = '14.4.4';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
package/src/server/ws.mjs CHANGED
@@ -1,41 +1,107 @@
1
1
  /**
2
- * WebSocket handler — broadcasts daemon events to the React UI.
2
+ * WebSocket handler — broadcasts daemon events + interactive terminal.
3
3
  * Uses the `ws` package already bundled in nha-cli.
4
4
  */
5
5
 
6
6
  import { createRequire } from 'module';
7
7
  import path from 'path';
8
+ import os from 'os';
8
9
  import { fileURLToPath } from 'url';
10
+ import { spawn } from 'child_process';
11
+ import { NHA_DIR } from '../constants.mjs';
9
12
 
10
13
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
- // Resolve `ws` from nha-cli's node_modules
12
14
  const require = createRequire(import.meta.url);
13
- // __dirname = packages/nha-cli/src/server/ → ../../ = packages/nha-cli/
14
15
  const { WebSocketServer } = require(
15
16
  path.resolve(__dirname, '../../node_modules/ws/index.js')
16
17
  );
17
18
 
18
19
  let wss = null;
20
+ let wssTerminal = null;
19
21
 
20
22
  export function setupWebSocket(server) {
23
+ // ── Main WS — daemon events + version ──
21
24
  wss = new WebSocketServer({ server, path: '/api' });
22
25
 
23
26
  wss.on('connection', async (ws) => {
24
27
  const { VERSION } = await import('../constants.mjs');
25
28
  ws.send(JSON.stringify({ type: 'connected', ts: Date.now() }));
26
- // Send current server version so UI can detect updates
27
29
  ws.send(JSON.stringify({ type: 'version', version: VERSION }));
28
30
 
29
31
  ws.on('message', (data) => {
30
32
  try {
31
33
  const msg = JSON.parse(data.toString());
32
- // Echo back for now — route-specific handlers can call broadcast()
33
34
  broadcast({ type: 'echo', payload: msg });
34
- } catch { /* ignore malformed */ }
35
+ } catch {}
35
36
  });
36
37
 
37
38
  ws.on('error', () => {});
38
39
  });
40
+
41
+ // ── Terminal WS — interactive shell ──
42
+ wssTerminal = new WebSocketServer({ server, path: '/api/terminal' });
43
+
44
+ wssTerminal.on('connection', (ws, req) => {
45
+ // Parse project from query: /api/terminal?cwd=ProjectName
46
+ const url = new URL(req.url || '', 'http://localhost');
47
+ const cwdParam = url.searchParams.get('cwd') || '';
48
+ let cwd;
49
+ if (cwdParam && !cwdParam.includes('/') && !cwdParam.includes('\\')) {
50
+ // Project name → resolve to webcraft dir
51
+ cwd = path.join(NHA_DIR, 'webcraft', cwdParam);
52
+ } else if (cwdParam) {
53
+ cwd = cwdParam;
54
+ } else {
55
+ cwd = path.join(NHA_DIR, 'webcraft');
56
+ }
57
+ // Security: ensure cwd is under NHA_DIR or home
58
+ const home = os.homedir();
59
+ if (!cwd.startsWith(NHA_DIR) && !cwd.startsWith(home)) cwd = home;
60
+ // Ensure dir exists
61
+ const fs = await import('fs');
62
+ if (!fs.default.existsSync(cwd)) cwd = home;
63
+
64
+ const shell = process.platform === 'win32' ? 'cmd.exe' : (process.env.SHELL || '/bin/sh');
65
+ const shellArgs = process.platform === 'win32' ? [] : ['-i']; // interactive
66
+
67
+ const proc = spawn(shell, shellArgs, {
68
+ cwd,
69
+ env: { ...process.env, TERM: 'xterm-256color', LANG: 'en_US.UTF-8' },
70
+ stdio: ['pipe', 'pipe', 'pipe'],
71
+ });
72
+
73
+ // Shell stdout → WS
74
+ proc.stdout.on('data', (data) => {
75
+ if (ws.readyState === 1) ws.send(data);
76
+ });
77
+
78
+ // Shell stderr → WS
79
+ proc.stderr.on('data', (data) => {
80
+ if (ws.readyState === 1) ws.send(data);
81
+ });
82
+
83
+ // WS → Shell stdin
84
+ ws.on('message', (data) => {
85
+ if (proc.stdin.writable) proc.stdin.write(data);
86
+ });
87
+
88
+ // Cleanup
89
+ proc.on('exit', () => {
90
+ if (ws.readyState === 1) ws.send('\r\n[shell exited]\r\n');
91
+ ws.close();
92
+ });
93
+
94
+ ws.on('close', () => {
95
+ try { proc.kill(); } catch {}
96
+ });
97
+
98
+ ws.on('error', () => {
99
+ try { proc.kill(); } catch {}
100
+ });
101
+
102
+ // Welcome message
103
+ ws.send(`\x1b[32mNHA Terminal\x1b[0m — ${cwd}\r\n`);
104
+ });
39
105
  }
40
106
 
41
107
  export function broadcast(msg) {