@mmmbuto/nexuscrew 0.4.0 → 0.4.2

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.
@@ -11,8 +11,8 @@
11
11
  <meta name="apple-mobile-web-app-title" content="NexusCrew" />
12
12
  <link rel="manifest" href="/manifest.json" />
13
13
  <title>NexusCrew</title>
14
- <script type="module" crossorigin src="/assets/index-B41xYEDb.js"></script>
15
- <link rel="stylesheet" crossorigin href="/assets/index-Cjqxzf2o.css">
14
+ <script type="module" crossorigin src="/assets/index-Bl1a-2Lf.js"></script>
15
+ <link rel="stylesheet" crossorigin href="/assets/index-BZIjqGMo.css">
16
16
  </head>
17
17
  <body>
18
18
  <div id="root"></div>
package/lib/server.js CHANGED
@@ -5,7 +5,7 @@ const { execFileSync } = require('node:child_process');
5
5
  const express = require('express');
6
6
  const { WebSocketServer } = require('ws');
7
7
  const { defaults, assertLoopback } = require('./config.js');
8
- const { listSessions } = require('./tmux/list.js');
8
+ const { listSessions, attachedClients } = require('./tmux/list.js');
9
9
  const { runAction } = require('./tmux/actions.js');
10
10
  const { openAttach } = require('./pty/attach.js');
11
11
  const { bindWs } = require('./ws/bridge.js');
@@ -43,6 +43,7 @@ function createServer(opts = {}) {
43
43
  verifyToken: (t) => verify(token, t),
44
44
  isValidSession: (name) => sessionExists(cfg.tmuxBin, name),
45
45
  runAction: (sess, action) => runAction(cfg.tmuxBin, sess, action),
46
+ countClients: (sess) => attachedClients(cfg.tmuxBin, sess),
46
47
  defaults: { readonlyDefault: cfg.readonlyDefault, tmuxBin: cfg.tmuxBin },
47
48
  });
48
49
  });
package/lib/tmux/list.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const { execFile } = require('node:child_process');
2
+ const { execFile, execFileSync } = require('node:child_process');
3
3
 
4
4
  const FMT = "#{session_name}\t#{session_attached}\t#{session_windows}\t#{session_created}";
5
5
 
@@ -30,4 +30,17 @@ function listSessions(tmuxBin = 'tmux') {
30
30
  });
31
31
  }
32
32
 
33
- module.exports = { parseSessions, listSessions, FMT };
33
+ // How many clients are already attached to this session (before our attach).
34
+ // Used to pick a sane resize default: drive the size only when no one else is watching.
35
+ function attachedClients(tmuxBin = 'tmux', session) {
36
+ try {
37
+ const out = execFileSync(
38
+ tmuxBin,
39
+ ['display-message', '-p', '-t', `=${session}`, '#{session_attached}'],
40
+ { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] },
41
+ );
42
+ return Number(String(out).trim()) || 0;
43
+ } catch (_) { return 0; }
44
+ }
45
+
46
+ module.exports = { parseSessions, listSessions, attachedClients, FMT };
package/lib/ws/bridge.js CHANGED
@@ -11,7 +11,7 @@ function clamp(n, lo, hi, def) {
11
11
  }
12
12
 
13
13
  function bindWs(ws, deps) {
14
- const { openAttach, verifyToken, isValidSession = () => true, runAction = () => false, defaults = {} } = deps;
14
+ const { openAttach, verifyToken, isValidSession = () => true, runAction = () => false, countClients = () => 0, defaults = {} } = deps;
15
15
  let pty = null;
16
16
  let attached = false;
17
17
  let session = null;
@@ -31,9 +31,16 @@ function bindWs(ws, deps) {
31
31
  if (!isValidSession(msg.session)) return fail(4404, 'no such session');
32
32
  attached = true;
33
33
  session = msg.session;
34
+ // Resize default: when nobody else is attached, drive the session size so a
35
+ // small phone gets a usable (non-clipped) view and clean line editing. When a
36
+ // real terminal is already attached, default to ignore-size so we don't shrink
37
+ // its window. An explicit takeSize from the client always wins.
38
+ const takeSize = msg.takeSize !== undefined
39
+ ? !!msg.takeSize
40
+ : countClients(msg.session) === 0;
34
41
  pty = openAttach(msg.session, {
35
42
  readonly: msg.readonly ?? defaults.readonlyDefault ?? false,
36
- takeSize: !!msg.takeSize,
43
+ takeSize,
37
44
  cols: clamp(msg.cols, 20, 300, 80),
38
45
  rows: clamp(msg.rows, 5, 120, 24),
39
46
  tmuxBin: defaults.tmuxBin || 'tmux',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmmbuto/nexuscrew",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Faithful browser tmux client — attach to live sessions over a real PTY, localhost-only, mobile-easy",
5
5
  "main": "lib/server.js",
6
6
  "bin": {
@@ -23,10 +23,10 @@
23
23
  "dependencies": {
24
24
  "express": "^4.21.0",
25
25
  "ws": "^8.18.0",
26
- "@mmmbuto/pty-termux-utils": "^1.1.4",
27
- "node-pty": "^1.1.0"
26
+ "@mmmbuto/pty-termux-utils": "^1.1.4"
28
27
  },
29
28
  "optionalDependencies": {
29
+ "node-pty": "^1.1.0",
30
30
  "@lydell/node-pty-linux-x64": "^1.2.0-beta.12"
31
31
  },
32
32
  "engines": {