@mmmbuto/nexuscrew 0.2.5 → 0.4.1

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.
Files changed (94) hide show
  1. package/README.md +63 -163
  2. package/bin/nexuscrew.js +1 -296
  3. package/frontend/dist/assets/index-B41xYEDb.js +81 -0
  4. package/frontend/dist/assets/index-Cjqxzf2o.css +32 -0
  5. package/frontend/dist/icon-maskable.svg +4 -0
  6. package/frontend/dist/icon.svg +4 -0
  7. package/frontend/dist/index.html +11 -3
  8. package/frontend/dist/manifest.json +24 -0
  9. package/frontend/dist/sw.js +3 -0
  10. package/frontend/index.html +20 -0
  11. package/lib/auth/token.js +26 -0
  12. package/lib/config.js +25 -0
  13. package/lib/pty/attach.js +30 -0
  14. package/lib/pty/provider.js +33 -0
  15. package/lib/server.js +62 -0
  16. package/lib/tmux/actions.js +27 -0
  17. package/lib/tmux/list.js +33 -0
  18. package/lib/ws/bridge.js +66 -0
  19. package/package.json +20 -24
  20. package/frontend/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  21. package/frontend/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  22. package/frontend/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  23. package/frontend/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  24. package/frontend/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  25. package/frontend/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  26. package/frontend/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  27. package/frontend/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  28. package/frontend/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  29. package/frontend/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  30. package/frontend/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  31. package/frontend/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  32. package/frontend/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  33. package/frontend/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  34. package/frontend/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  35. package/frontend/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  36. package/frontend/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  37. package/frontend/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  38. package/frontend/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  39. package/frontend/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  40. package/frontend/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  41. package/frontend/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  42. package/frontend/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  43. package/frontend/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  44. package/frontend/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  45. package/frontend/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  46. package/frontend/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  47. package/frontend/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  48. package/frontend/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  49. package/frontend/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  50. package/frontend/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  51. package/frontend/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  52. package/frontend/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  53. package/frontend/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  54. package/frontend/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  55. package/frontend/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  56. package/frontend/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  57. package/frontend/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  58. package/frontend/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  59. package/frontend/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  60. package/frontend/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  61. package/frontend/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  62. package/frontend/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  63. package/frontend/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  64. package/frontend/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  65. package/frontend/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  66. package/frontend/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  67. package/frontend/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  68. package/frontend/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  69. package/frontend/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  70. package/frontend/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  71. package/frontend/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  72. package/frontend/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  73. package/frontend/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  74. package/frontend/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  75. package/frontend/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  76. package/frontend/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  77. package/frontend/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  78. package/frontend/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  79. package/frontend/dist/assets/index-CSPyKzmq.js +0 -8614
  80. package/frontend/dist/assets/index-Cl7bxc7X.css +0 -1
  81. package/lib/config/paths.js +0 -30
  82. package/lib/server/routes/hosts.js +0 -82
  83. package/lib/server/routes/launchers.js +0 -17
  84. package/lib/server/routes/models.js +0 -26
  85. package/lib/server/routes/runtime.js +0 -14
  86. package/lib/server/routes/send.js +0 -236
  87. package/lib/server/routes/sessions.js +0 -104
  88. package/lib/server/routes/status.js +0 -62
  89. package/lib/server/routes/tmux.js +0 -91
  90. package/lib/server/server.js +0 -189
  91. package/lib/services/engine-discovery.js +0 -317
  92. package/lib/services/log-watcher.js +0 -279
  93. package/lib/services/session-store.js +0 -198
  94. package/lib/services/tmux-manager.js +0 -288
@@ -0,0 +1,32 @@
1
+ .nc-sessions{display:flex;flex-direction:column;gap:6px;padding:10px;color:#cfe}.nc-sessions header{display:flex;justify-content:space-between;font-weight:600;opacity:.8}.nc-sessions header button{background:none;border:1px solid #243;color:#9fd;border-radius:6px;padding:2px 8px}.nc-session{display:flex;align-items:center;gap:8px;padding:12px;border:1px solid #1c241c;background:#0e140e;color:#cfe;border-radius:8px;text-align:left}.nc-session .dot{width:8px;height:8px;border-radius:50%;background:#355}.nc-session .dot.on{background:#0c6}.nc-session small{margin-left:auto;opacity:.6}.nc-err{color:#f88;font-size:12px}.nc-empty{opacity:.5;padding:12px}/**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * https://github.com/chjj/term.js
5
+ * @license MIT
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ * Originally forked from (with the author's permission):
26
+ * Fabrice Bellard's javascript vt100 for jslinux:
27
+ * http://bellard.org/jslinux/
28
+ * Copyright (c) 2011 Fabrice Bellard
29
+ * The original design remains. The terminal itself
30
+ * has been extended to include xterm CSI codes, among
31
+ * other features.
32
+ */.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{font-family:monospace;-webkit-user-select:text;user-select:text;white-space:pre}.xterm .xterm-accessibility-tree>div{transform-origin:left;width:fit-content}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}.xterm .xterm-scrollable-element>.scrollbar{cursor:default}.xterm .xterm-scrollable-element>.scrollbar>.scra{cursor:pointer;font-size:11px!important}.xterm .xterm-scrollable-element>.visible{opacity:1;background:#0000;transition:opacity .1s linear;z-index:11}.xterm .xterm-scrollable-element>.invisible{opacity:0;pointer-events:none}.xterm .xterm-scrollable-element>.invisible.fade{transition:opacity .8s linear}.xterm .xterm-scrollable-element>.shadow{position:absolute;display:none}.xterm .xterm-scrollable-element>.shadow.top{display:block;top:0;left:3px;height:3px;width:100%;box-shadow:var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.left{display:block;top:3px;left:0;height:100%;width:3px;box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.top-left-corner{display:block;top:0;left:0;height:3px;width:3px}.xterm .xterm-scrollable-element>.shadow.top.left{box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}.nc-terminal{position:absolute;top:0;right:0;bottom:0;left:0;padding:4px;background:#0a0e0a}.nc-terminal .xterm{height:100%}.nc-keybar{display:flex;gap:6px;overflow-x:auto;padding:8px;background:#0e140e;border-top:1px solid #1c241c;-webkit-overflow-scrolling:touch}.nc-keybar button{flex:0 0 auto;padding:10px 12px;min-width:48px;border-radius:8px;border:1px solid #243;background:#122;color:#9fd;font-size:13px}.nc-keybar button:active{background:#0c6;color:#021}.nc-keybar.copy{background:#14210f}.nc-keybar .tag{flex:0 0 auto;align-self:center;padding:0 8px;color:#8e8;font-size:12px}:root{color-scheme:dark}body,#root{margin:0;height:100vh;background:#0a0e0a;font-family:ui-monospace,monospace}.nc-app{display:flex;flex-direction:column;height:100vh}.nc-bar{display:flex;gap:10px;align-items:center;padding:8px;color:#cfe;background:#0e140e}.nc-bar button{background:none;border:1px solid #243;color:#9fd;border-radius:6px;padding:4px 10px}.nc-termwrap{position:relative;flex:1}.nc-auth{color:#cfe;padding:20px;display:flex;flex-direction:column;gap:10px;max-width:420px}.nc-auth input[type=text],.nc-auth input:not([type]){padding:10px;background:#122;border:1px solid #243;color:#cfe;border-radius:6px}.nc-auth button{padding:10px;background:#122;border:1px solid #243;color:#9fd;border-radius:6px}:root{--bg-primary: #0d1117;--bg-secondary: #161b22;--bg-tertiary: #21262d;--bg-hover: #30363d;--text-primary: #e6edf3;--text-secondary: #8b949e;--text-tertiary: #6e7681;--border: #30363d;--accent: #6c5ce7;--accent-hover: #7c6cf7;--success: #3fb950;--warning: #d29922;--error: #f85149;--user-bg: #1c2333;--assistant-bg: transparent;--font-mono: "SF Mono", monospace;--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif}*{box-sizing:border-box;margin:0;padding:0}html,body,#root{height:100%;width:100%;overflow:hidden}body{font-family:var(--font-sans);background:var(--bg-primary);color:var(--text-primary);-webkit-font-smoothing:antialiased}::-webkit-scrollbar{width:6px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:var(--bg-tertiary);border-radius:3px}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.spinning{animation:spin 1s linear infinite}
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
2
+ <rect width="512" height="512" rx="96" fill="#0d1117"/>
3
+ <text x="256" y="340" font-family="monospace" font-size="280" font-weight="bold" fill="#3fb950" text-anchor="middle">&gt;_</text>
4
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
2
+ <rect width="512" height="512" rx="96" fill="#0d1117"/>
3
+ <text x="256" y="340" font-family="monospace" font-size="280" font-weight="bold" fill="#3fb950" text-anchor="middle">&gt;_</text>
4
+ </svg>
@@ -2,12 +2,20 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
6
+ <meta name="theme-color" content="#0d1117" />
7
+ <meta name="apple-mobile-web-app-capable" content="yes" />
8
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
9
+ <meta name="mobile-web-app-capable" content="yes" />
10
+ <meta name="application-name" content="NexusCrew" />
11
+ <meta name="apple-mobile-web-app-title" content="NexusCrew" />
12
+ <link rel="manifest" href="/manifest.json" />
6
13
  <title>NexusCrew</title>
7
- <script type="module" crossorigin src="/assets/index-CSPyKzmq.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index-Cl7bxc7X.css">
14
+ <script type="module" crossorigin src="/assets/index-B41xYEDb.js"></script>
15
+ <link rel="stylesheet" crossorigin href="/assets/index-Cjqxzf2o.css">
9
16
  </head>
10
17
  <body>
11
18
  <div id="root"></div>
19
+ <script>if('serviceWorker' in navigator) navigator.serviceWorker.register('/sw.js');</script>
12
20
  </body>
13
21
  </html>
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "NexusCrew",
3
+ "short_name": "NexusCrew",
4
+ "description": "tmux-based AI cockpit",
5
+ "start_url": "/",
6
+ "display": "standalone",
7
+ "background_color": "#0d1117",
8
+ "theme_color": "#0d1117",
9
+ "orientation": "any",
10
+ "icons": [
11
+ {
12
+ "src": "/icon.svg",
13
+ "sizes": "any",
14
+ "type": "image/svg+xml",
15
+ "purpose": "any"
16
+ },
17
+ {
18
+ "src": "/icon-maskable.svg",
19
+ "sizes": "any",
20
+ "type": "image/svg+xml",
21
+ "purpose": "maskable"
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,3 @@
1
+ self.addEventListener('install', () => self.skipWaiting());
2
+ self.addEventListener('activate', () => self.clients.claim());
3
+ self.addEventListener('fetch', (e) => e.respondWith(fetch(e.request)));
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
6
+ <meta name="theme-color" content="#0d1117" />
7
+ <meta name="apple-mobile-web-app-capable" content="yes" />
8
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
9
+ <meta name="mobile-web-app-capable" content="yes" />
10
+ <meta name="application-name" content="NexusCrew" />
11
+ <meta name="apple-mobile-web-app-title" content="NexusCrew" />
12
+ <link rel="manifest" href="/manifest.json" />
13
+ <title>NexusCrew</title>
14
+ </head>
15
+ <body>
16
+ <div id="root"></div>
17
+ <script>if('serviceWorker' in navigator) navigator.serviceWorker.register('/sw.js');</script>
18
+ <script type="module" src="/src/main.jsx"></script>
19
+ </body>
20
+ </html>
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const crypto = require('node:crypto');
5
+
6
+ function loadOrCreateToken(tokenPath) {
7
+ try {
8
+ const t = fs.readFileSync(tokenPath, 'utf8').trim();
9
+ if (t) return t;
10
+ } catch (_) { /* crea sotto */ }
11
+ fs.mkdirSync(path.dirname(tokenPath), { recursive: true });
12
+ const tok = crypto.randomBytes(24).toString('base64url');
13
+ fs.writeFileSync(tokenPath, tok + '\n', { mode: 0o600 });
14
+ fs.chmodSync(tokenPath, 0o600);
15
+ return tok;
16
+ }
17
+
18
+ function verify(expected, given) {
19
+ if (typeof expected !== 'string' || typeof given !== 'string') return false;
20
+ const a = Buffer.from(expected);
21
+ const b = Buffer.from(given);
22
+ if (a.length !== b.length) return false;
23
+ return crypto.timingSafeEqual(a, b);
24
+ }
25
+
26
+ module.exports = { loadOrCreateToken, verify };
package/lib/config.js ADDED
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+ const os = require('os');
3
+ const path = require('path');
4
+
5
+ const LOOPBACK = new Set(['127.0.0.1', '::1', 'localhost']);
6
+
7
+ function assertLoopback(bind) {
8
+ if (!LOOPBACK.has(bind)) {
9
+ throw new Error(`refusing non-loopback bind "${bind}": nexuscrew is localhost-only`);
10
+ }
11
+ return bind;
12
+ }
13
+
14
+ function defaults() {
15
+ return {
16
+ bind: '127.0.0.1',
17
+ port: Number(process.env.NEXUSCREW_PORT || 41820),
18
+ tokenPath: process.env.NEXUSCREW_TOKEN_FILE
19
+ || path.join(os.homedir(), '.nexuscrew', 'token'),
20
+ tmuxBin: process.env.NEXUSCREW_TMUX || 'tmux',
21
+ readonlyDefault: process.env.NEXUSCREW_READONLY === '1' ? true : false,
22
+ };
23
+ }
24
+
25
+ module.exports = { assertLoopback, defaults, LOOPBACK };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+ const { loadPty } = require('./provider.js');
3
+
4
+ // Opens `tmux attach` inside a real PTY, non-destructive for other clients.
5
+ // With `window-size latest` + `aggressive-resize on`, a small web client would
6
+ // shrink the window for the user's real terminal too. So:
7
+ // default → `-f ignore-size` (our client does NOT drive the geometry)
8
+ // takeSize → normal attach (only when the size should be driven deliberately)
9
+ // readonly → `-f read-only,ignore-size` (note: read-only also limits copy-mode/KeyBar)
10
+ function openAttach(session, opts = {}) {
11
+ const { readonly = false, takeSize = false, cols = 80, rows = 24, tmuxBin = 'tmux' } = opts;
12
+ const pty = loadPty();
13
+ const args = ['attach-session', '-t', session];
14
+ if (readonly) args.push('-f', 'read-only,ignore-size');
15
+ else if (!takeSize) args.push('-f', 'ignore-size');
16
+ const term = pty.spawn(tmuxBin, args, {
17
+ name: 'xterm-256color',
18
+ cols, rows,
19
+ cwd: process.env.HOME,
20
+ env: process.env,
21
+ });
22
+ return {
23
+ write: (data) => term.write(data),
24
+ resize: (c, r) => { try { term.resize(c, r); } catch (_) {} },
25
+ onData: (cb) => term.onData(cb),
26
+ onExit: (cb) => term.onExit(cb),
27
+ kill: () => { try { term.kill(); } catch (_) {} },
28
+ };
29
+ }
30
+ module.exports = { openAttach };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+ // Ritorna un oggetto { spawn(file, args, opts) } con un PTY REALE.
3
+ // Termux/Android → @mmmbuto/node-pty-android-arm64 ; altrove → node-pty upstream.
4
+ // `tmux attach` ESIGE un vero tty: il fallback child_process NON è accettabile qui.
5
+ let _cached = null;
6
+
7
+ function loadPty() {
8
+ if (_cached) return _cached;
9
+ const isTermux = process.platform === 'android'
10
+ || (process.env.PREFIX || '').includes('com.termux');
11
+ const candidates = isTermux
12
+ ? ['@mmmbuto/node-pty-android-arm64', 'node-pty']
13
+ : ['node-pty', '@lydell/node-pty-linux-x64', '@mmmbuto/node-pty-android-arm64'];
14
+ for (const mod of candidates) {
15
+ try {
16
+ const pty = require(mod);
17
+ // Accept ONLY a provider with a complete PTY API; never child_process.
18
+ if (pty && typeof pty.spawn === 'function') {
19
+ const t = pty.spawn(process.env.SHELL || '/bin/sh', ['-c', 'true'], { cols: 80, rows: 24 });
20
+ const ok = t && typeof t.write === 'function' && typeof t.onData === 'function'
21
+ && typeof t.resize === 'function' && typeof t.kill === 'function';
22
+ try { t.kill(); } catch (_) {}
23
+ if (ok) {
24
+ if (process.env.NEXUSCREW_DEBUG) console.error(`[pty] provider=${mod}`);
25
+ _cached = pty;
26
+ return pty;
27
+ }
28
+ }
29
+ } catch (_) { /* prova il prossimo */ }
30
+ }
31
+ throw new Error('no real PTY provider available (need node-pty or @mmmbuto/node-pty-android-arm64)');
32
+ }
33
+ module.exports = { loadPty };
package/lib/server.js ADDED
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+ const http = require('node:http');
3
+ const path = require('node:path');
4
+ const { execFileSync } = require('node:child_process');
5
+ const express = require('express');
6
+ const { WebSocketServer } = require('ws');
7
+ const { defaults, assertLoopback } = require('./config.js');
8
+ const { listSessions } = require('./tmux/list.js');
9
+ const { runAction } = require('./tmux/actions.js');
10
+ const { openAttach } = require('./pty/attach.js');
11
+ const { bindWs } = require('./ws/bridge.js');
12
+ const { loadOrCreateToken, verify } = require('./auth/token.js');
13
+
14
+ function sessionExists(tmuxBin, name) {
15
+ if (typeof name !== 'string' || !/^[\w.@%:+-]{1,128}$/.test(name)) return false;
16
+ try { execFileSync(tmuxBin, ['has-session', '-t', `=${name}`], { stdio: 'ignore' }); return true; }
17
+ catch (_) { return false; }
18
+ }
19
+
20
+ function createServer(opts = {}) {
21
+ const cfg = { ...defaults(), ...opts };
22
+ assertLoopback(cfg.bind);
23
+ const token = loadOrCreateToken(cfg.tokenPath);
24
+
25
+ const app = express();
26
+ const distDir = path.join(__dirname, '..', 'frontend', 'dist');
27
+ // no-store on everything (HTML+assets+API): this is a local, token-adjacent tool.
28
+ app.use((_req, res, next) => { res.set('Cache-Control', 'no-store'); next(); });
29
+ app.get('/api/sessions', async (_req, res) => {
30
+ try { res.json({ sessions: await listSessions(cfg.tmuxBin) }); }
31
+ catch (e) { res.status(500).json({ error: String(e.message || e) }); }
32
+ });
33
+ // Note: the token must never be exposed here.
34
+ app.get('/api/config', (_req, res) => res.json({ readonlyDefault: cfg.readonlyDefault }));
35
+ app.use(express.static(distDir));
36
+ app.get('*', (_req, res) => res.sendFile(path.join(distDir, 'index.html')));
37
+
38
+ const server = http.createServer(app);
39
+ const wss = new WebSocketServer({ server, path: '/ws', maxPayload: 1 << 20 });
40
+ wss.on('connection', (ws) => {
41
+ bindWs(ws, {
42
+ openAttach,
43
+ verifyToken: (t) => verify(token, t),
44
+ isValidSession: (name) => sessionExists(cfg.tmuxBin, name),
45
+ runAction: (sess, action) => runAction(cfg.tmuxBin, sess, action),
46
+ defaults: { readonlyDefault: cfg.readonlyDefault, tmuxBin: cfg.tmuxBin },
47
+ });
48
+ });
49
+
50
+ return { app, server, wss, cfg, token };
51
+ }
52
+
53
+ function start(opts = {}) {
54
+ const { server, cfg, token } = createServer(opts);
55
+ server.listen(cfg.port, cfg.bind, () => {
56
+ console.log(`nexuscrew on http://${cfg.bind}:${cfg.port} (token: ${token})`);
57
+ console.log('localhost-only — reach it via SSH/autossh/VPN tunnel.');
58
+ });
59
+ return server;
60
+ }
61
+
62
+ module.exports = { createServer, start };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+ const { execFile } = require('node:child_process');
3
+
4
+ // Window/pane navigation must NOT be emulated with client-side prefix keys
5
+ // (it depends on each host's bindings, which may be remapped or broken).
6
+ // It runs server-side with direct, allowlisted tmux commands on the active session.
7
+ const ACTIONS = {
8
+ 'prev-window': ['previous-window'],
9
+ 'next-window': ['next-window'],
10
+ 'pane-left': ['select-pane', '-L'],
11
+ 'pane-right': ['select-pane', '-R'],
12
+ };
13
+
14
+ // Pure: ritorna gli arg tmux per un'azione allowlistata, o null.
15
+ function actionArgs(name) {
16
+ return Object.prototype.hasOwnProperty.call(ACTIONS, name) ? ACTIONS[name].slice() : null;
17
+ }
18
+
19
+ // Fire-and-forget: esegue l'azione sulla sessione (match esatto `=name`). false se non allowlistata.
20
+ function runAction(tmuxBin, session, name) {
21
+ const base = actionArgs(name);
22
+ if (!base) return false;
23
+ try { execFile(tmuxBin, [...base, '-t', `=${session}`], () => {}); return true; }
24
+ catch (_) { return false; }
25
+ }
26
+
27
+ module.exports = { actionArgs, runAction, ACTIONS };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+ const { execFile } = require('node:child_process');
3
+
4
+ const FMT = "#{session_name}\t#{session_attached}\t#{session_windows}\t#{session_created}";
5
+
6
+ function parseSessions(raw) {
7
+ return String(raw)
8
+ .split('\n')
9
+ .filter((l) => l.trim() !== '')
10
+ .map((line) => {
11
+ const [name, attached, windows, created] = line.split('\t');
12
+ return {
13
+ name,
14
+ attached: attached === '1',
15
+ windows: Number(windows),
16
+ created: Number(created),
17
+ };
18
+ });
19
+ }
20
+
21
+ function listSessions(tmuxBin = 'tmux') {
22
+ return new Promise((resolve, reject) => {
23
+ execFile(tmuxBin, ['list-sessions', '-F', FMT], (err, stdout, stderr) => {
24
+ if (err) {
25
+ if (/no server running/i.test(stderr || '')) return resolve([]);
26
+ return reject(new Error(`tmux list-sessions failed: ${stderr || err.message}`));
27
+ }
28
+ resolve(parseSessions(stdout));
29
+ });
30
+ });
31
+ }
32
+
33
+ module.exports = { parseSessions, listSessions, FMT };
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+ // Bridges ONE WebSocket to ONE PTY attach. Dependencies are injectable for tests.
3
+ // Hardening: close on protocol violation, no 2nd attach, clamp cols/rows,
4
+ // validated session, backpressure cutoff, errors as JSON with a code.
5
+ const MAX_BUFFERED = 12 * 1024 * 1024; // 12 MiB
6
+
7
+ function clamp(n, lo, hi, def) {
8
+ n = Number(n);
9
+ if (!Number.isFinite(n)) return def;
10
+ return Math.max(lo, Math.min(hi, Math.round(n)));
11
+ }
12
+
13
+ function bindWs(ws, deps) {
14
+ const { openAttach, verifyToken, isValidSession = () => true, runAction = () => false, defaults = {} } = deps;
15
+ let pty = null;
16
+ let attached = false;
17
+ let session = null;
18
+
19
+ function fail(code, reason) {
20
+ try { ws.send(JSON.stringify({ type: 'error', reason })); } catch (_) {}
21
+ try { ws.close(code, reason); } catch (_) {}
22
+ }
23
+
24
+ function onMessage(data, isBinary) {
25
+ if (!attached) {
26
+ if (isBinary) return fail(1002, 'binary before attach');
27
+ let msg;
28
+ try { msg = JSON.parse(data.toString()); } catch (_) { return fail(1002, 'bad handshake'); }
29
+ if (msg.type !== 'attach') return fail(1002, 'expected attach');
30
+ if (!verifyToken(msg.token)) return fail(4401, 'bad token');
31
+ if (!isValidSession(msg.session)) return fail(4404, 'no such session');
32
+ attached = true;
33
+ session = msg.session;
34
+ pty = openAttach(msg.session, {
35
+ readonly: msg.readonly ?? defaults.readonlyDefault ?? false,
36
+ takeSize: !!msg.takeSize,
37
+ cols: clamp(msg.cols, 20, 300, 80),
38
+ rows: clamp(msg.rows, 5, 120, 24),
39
+ tmuxBin: defaults.tmuxBin || 'tmux',
40
+ });
41
+ pty.onData((d) => {
42
+ try { ws.send(Buffer.from(d), { binary: true }); } catch (_) { return; }
43
+ if ((ws.bufferedAmount || 0) > MAX_BUFFERED) fail(1011, 'backpressure');
44
+ });
45
+ pty.onExit((info) => {
46
+ try { ws.send(JSON.stringify({ type: 'exit', code: info && info.exitCode })); } catch (_) {}
47
+ try { ws.close(1000, 'exit'); } catch (_) {}
48
+ });
49
+ return;
50
+ }
51
+ // dopo l'attach
52
+ if (isBinary) { pty.write(data); return; }
53
+ let msg;
54
+ try { msg = JSON.parse(data.toString()); } catch (_) { return; }
55
+ if (msg.type === 'attach') return fail(1002, 'already attached'); // no 2nd attach
56
+ if (msg.type === 'resize') pty.resize(clamp(msg.cols, 20, 300, 80), clamp(msg.rows, 5, 120, 24));
57
+ else if (msg.type === 'input') pty.write(typeof msg.data === 'string' ? msg.data : '');
58
+ else if (msg.type === 'key') pty.write(typeof msg.seq === 'string' ? msg.seq.slice(0, 64) : '');
59
+ else if (msg.type === 'action') runAction(session, msg.name); // nav window/pane server-side
60
+ }
61
+
62
+ ws.on('message', onMessage);
63
+ ws.on('close', () => { if (pty) pty.kill(); pty = null; });
64
+ ws.on('error', () => { if (pty) pty.kill(); pty = null; });
65
+ }
66
+ module.exports = { bindWs, clamp };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@mmmbuto/nexuscrew",
3
- "version": "0.2.5",
4
- "description": "tmux-based AI cockpit for real active sessions and launcher discovery across Termux, Linux, and macOS",
5
- "main": "lib/server/server.js",
3
+ "version": "0.4.1",
4
+ "description": "Faithful browser tmux client attach to live sessions over a real PTY, localhost-only, mobile-easy",
5
+ "main": "lib/server.js",
6
6
  "bin": {
7
7
  "nexuscrew": "bin/nexuscrew.js"
8
8
  },
@@ -10,26 +10,25 @@
10
10
  "bin/",
11
11
  "lib/",
12
12
  "frontend/dist/",
13
+ "frontend/index.html",
13
14
  "LICENSE",
14
15
  "README.md"
15
16
  ],
16
17
  "scripts": {
17
- "dev": "node lib/server/server.js",
18
+ "start": "node bin/nexuscrew.js",
19
+ "dev": "node bin/nexuscrew.js",
18
20
  "build": "cd frontend && npm install && npm run build && cd ..",
19
- "start": "node lib/server/server.js",
20
- "test": "node --test tests/*.test.js",
21
- "setup": "node bin/nexuscrew.js init",
22
- "prepublishOnly": "chmod +x bin/nexuscrew.js && cd frontend && npm install && npm run build",
23
- "postinstall": "node bin/nexuscrew.js init --silent"
21
+ "test": "node --test tests/*.test.js"
24
22
  },
25
23
  "dependencies": {
26
- "better-sqlite3": "npm:@mmmbuto/better-sqlite3-termux@12.8.0-termux.1",
27
- "commander": "^12.1.0",
28
- "cors": "^2.8.5",
29
24
  "express": "^4.21.0",
30
- "uuid": "^10.0.0"
25
+ "ws": "^8.18.0",
26
+ "@mmmbuto/pty-termux-utils": "^1.1.4"
27
+ },
28
+ "optionalDependencies": {
29
+ "node-pty": "^1.1.0",
30
+ "@lydell/node-pty-linux-x64": "^1.2.0-beta.12"
31
31
  },
32
- "optionalDependencies": {},
33
32
  "engines": {
34
33
  "node": ">=18"
35
34
  },
@@ -40,20 +39,17 @@
40
39
  ],
41
40
  "cpu": [
42
41
  "x64",
43
- "arm64",
44
- "arm"
42
+ "arm64"
45
43
  ],
46
44
  "keywords": [
47
45
  "tmux",
48
- "claude-code",
49
- "codex",
50
- "gemini",
51
- "qwen",
52
- "ai",
53
- "cockpit",
54
46
  "terminal",
55
- "session-manager",
56
- "ssh"
47
+ "pty",
48
+ "websocket",
49
+ "xterm",
50
+ "cockpit",
51
+ "mobile",
52
+ "session-manager"
57
53
  ],
58
54
  "repository": {
59
55
  "type": "git",