termbeam 0.0.7 โ†’ 0.0.9

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 (3) hide show
  1. package/README.md +53 -115
  2. package/package.json +3 -1
  3. package/src/cli.js +71 -15
package/README.md CHANGED
@@ -1,40 +1,21 @@
1
- <div align="center">
1
+ # TermBeam
2
2
 
3
- # ๐Ÿ“ก TermBeam
4
-
5
- **Beam your terminal to any device**
3
+ **Beam your terminal to any device.**
6
4
 
7
5
  [![npm version](https://img.shields.io/npm/v/termbeam.svg)](https://www.npmjs.com/package/termbeam)
8
6
  [![CI](https://github.com/dorlugasigal/TermBeam/actions/workflows/ci.yml/badge.svg)](https://github.com/dorlugasigal/TermBeam/actions/workflows/ci.yml)
7
+ [![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/dorlugasigal/TermBeam/coverage-data/endpoint.json)](https://github.com/dorlugasigal/TermBeam/actions/workflows/ci.yml)
9
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
- [![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg)](https://nodejs.org)
11
-
12
- Access your terminal from your phone, tablet, or any browser.
13
- Multi-session, mobile-optimized, with touch controls.
14
9
 
15
- [Getting Started](#-quick-start) ยท [Demo](#-demo) ยท [Documentation](https://dorlugasigal.github.io/TermBeam/) ยท [Contributing](CONTRIBUTING.md)
10
+ TermBeam lets you access your terminal from a phone, tablet, or any browser โ€” no SSH, no port forwarding, no config files. Run one command and scan the QR code.
16
11
 
17
- </div>
12
+ I built this because I kept needing to run quick commands on my dev machine while away from my desk, and SSH on a phone is painful. TermBeam gives you a real terminal with a touch-friendly UI that actually works on small screens.
18
13
 
19
- ---
14
+ [Full documentation](https://dorlugasigal.github.io/TermBeam/)
20
15
 
21
16
  https://github.com/user-attachments/assets/c91ca15d-0c84-400f-bbfa-3d58d1be07ee
22
17
 
23
- ## โœจ Features
24
-
25
- - ๐Ÿ“ฑ **Mobile-first UI** โ€” Touch-friendly interface designed for phones and tablets
26
- - ๐Ÿ–ฅ๏ธ **Multi-session** โ€” Run multiple terminal sessions simultaneously
27
- - ๐Ÿ” **Password auth** โ€” Token-based authentication with rate limiting
28
- - ๐Ÿ“‚ **Folder browser** โ€” Visual directory picker with breadcrumb navigation
29
- - ๐Ÿ‘† **Touch controls** โ€” Arrow keys, Ctrl shortcuts, Tab, Esc via on-screen touch bar
30
- - ๐Ÿ”ค **Nerd Font support** โ€” Full glyph rendering with JetBrains Mono Nerd Font
31
- - ๐Ÿ“ฒ **QR code** โ€” Scan to connect instantly from your phone
32
- - ๐ŸŒ **DevTunnel** โ€” Optional public URL for remote access from anywhere
33
- - ๐Ÿ” **Adjustable font size** โ€” Pinch or button zoom for any screen
34
- - โ†”๏ธ **Swipe to delete** โ€” iOS-style session management
35
- - ๐Ÿ”„ **Smart versioning** โ€” Shows git hash in dev, clean version from npm
36
-
37
- ## ๐Ÿš€ Quick Start
18
+ ## Quick Start
38
19
 
39
20
  ```bash
40
21
  npx termbeam
@@ -47,124 +28,81 @@ npm install -g termbeam
47
28
  termbeam
48
29
  ```
49
30
 
50
- That's it. Scan the QR code printed in your terminal, or open the URL on any device.
31
+ Scan the QR code printed in your terminal, or open the URL on any device.
51
32
 
52
- ### With password protection (recommended)
33
+ ### Password protection (recommended)
53
34
 
54
35
  ```bash
55
- # Auto-generate a secure password
56
36
  termbeam --generate-password
57
37
 
58
- # Or set your own
38
+ # or set your own
59
39
  termbeam --password mysecret
60
40
  ```
61
41
 
62
- ### Remote access from anywhere
63
-
64
- ```bash
65
- termbeam --tunnel --generate-password
66
- ```
42
+ ## Features
67
43
 
68
- > Requires the [Azure Dev Tunnels CLI](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started):
69
- >
70
- > - **Windows:** `winget install Microsoft.devtunnel`
71
- > - **macOS:** `brew install --cask devtunnel`
72
- > - **Linux:** `curl -sL https://aka.ms/DevTunnelCliInstall | bash`
44
+ - **Mobile-first UI** with on-screen touch bar (arrow keys, Tab, Ctrl shortcuts, Esc) and swipe-to-delete session management
45
+ - **Multiple sessions** running simultaneously, managed from a single hub page โ€” shows connected client count per session
46
+ - **Password auth** with token-based cookies and rate-limited login
47
+ - **Folder browser** to pick working directories without typing paths
48
+ - **Initial command** โ€” optionally launch a session straight into `htop`, `vim`, or any command
49
+ - **Shell detection** โ€” auto-detects your shell on all platforms (PowerShell, cmd, bash, zsh, Git Bash, WSL)
50
+ - **QR code on startup** for instant phone connection
51
+ - **Light/dark theme** with persistent preference
52
+ - **Adjustable font size** via status bar controls, saved across sessions
53
+ - **Remote access via [DevTunnel](#remote-access)** โ€” ephemeral or persisted public URLs
73
54
 
74
- ## ๐Ÿ“– Usage
55
+ ## Remote Access
75
56
 
76
57
  ```bash
77
- # Start with your default shell
78
- termbeam
79
-
80
- # Use a specific shell
81
- termbeam /bin/bash
82
-
83
- # Custom port and listen on all interfaces (LAN access)
84
- termbeam --port 8080 --host 0.0.0.0
85
-
86
- # Public tunnel + password (access from anywhere)
58
+ # One-off tunnel (deleted on shutdown)
87
59
  termbeam --tunnel --generate-password
88
- ```
89
-
90
- ### CLI Options
91
-
92
- | Flag | Description | Default |
93
- | --------------------- | ------------------------------- | ----------- |
94
- | `--password <pw>` | Set access password | None |
95
- | `--generate-password` | Auto-generate a secure password | โ€” |
96
- | `--tunnel` | Create a public devtunnel URL | Off |
97
- | `--port <port>` | Server port | `3456` |
98
- | `--host <addr>` | Bind address | `127.0.0.1` |
99
- | `-h, --help` | Show help | โ€” |
100
- | `-v, --version` | Show version | โ€” |
101
60
 
102
- ### Environment Variables
103
-
104
- | Variable | Description |
105
- | ------------------- | ------------------------------- |
106
- | `PORT` | Server port (overrides default) |
107
- | `TERMBEAM_PASSWORD` | Access password |
108
- | `TERMBEAM_CWD` | Default working directory |
109
-
110
- ## ๐Ÿ”’ Security
61
+ # Persisted tunnel (stable URL you can bookmark, reused across restarts, 30-day expiry)
62
+ termbeam --persisted-tunnel --generate-password
63
+ ```
111
64
 
112
- TermBeam is designed for **local network use**. Key security features:
65
+ Requires the [Dev Tunnels CLI](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started):
113
66
 
114
- - ๐Ÿ”‘ **Token-based auth** with secure, httpOnly cookies (24-hour expiry)
115
- - ๐Ÿ›ก๏ธ **Rate limiting** on login (5 attempts per minute)
116
- - ๐Ÿ”’ **Security headers** (X-Frame-Options, X-Content-Type-Options, CSP, etc.)
117
- - ๐Ÿ  **Localhost by default** โ€” requires explicit `--host 0.0.0.0` for LAN access
67
+ - **Windows:** `winget install Microsoft.devtunnel`
68
+ - **macOS:** `brew install --cask devtunnel`
69
+ - **Linux:** `curl -sL https://aka.ms/DevTunnelCliInstall | bash`
118
70
 
119
- > โš ๏ธ **Always use a password when exposing to any network.** See the [Security Guide](https://dorlugasigal.github.io/TermBeam/security/) for production deployment tips.
71
+ Persisted tunnels save a tunnel ID to `~/.termbeam/tunnel.json` so the URL stays the same between sessions.
120
72
 
121
- ## ๐Ÿ—๏ธ Architecture
73
+ ## CLI Reference
122
74
 
123
- ```
124
- termbeam/
125
- โ”œโ”€โ”€ bin/termbeam.js # CLI entry point
126
- โ”œโ”€โ”€ src/
127
- โ”‚ โ”œโ”€โ”€ server.js # Main orchestrator
128
- โ”‚ โ”œโ”€โ”€ cli.js # Argument parsing & help
129
- โ”‚ โ”œโ”€โ”€ auth.js # Authentication & rate limiting
130
- โ”‚ โ”œโ”€โ”€ sessions.js # PTY session lifecycle
131
- โ”‚ โ”œโ”€โ”€ routes.js # Express HTTP routes
132
- โ”‚ โ”œโ”€โ”€ websocket.js # WebSocket terminal I/O
133
- โ”‚ โ”œโ”€โ”€ tunnel.js # DevTunnel integration
134
- โ”‚ โ””โ”€โ”€ version.js # Smart version detection
135
- โ”œโ”€โ”€ public/
136
- โ”‚ โ”œโ”€โ”€ index.html # Session manager UI (mobile)
137
- โ”‚ โ””โ”€โ”€ terminal.html # Terminal UI (xterm.js)
138
- โ”œโ”€โ”€ test/ # Unit tests (node:test)
139
- โ”œโ”€โ”€ docs/ # MkDocs documentation
140
- โ””โ”€โ”€ .github/workflows/ # CI, Release, Docs deployment
75
+ ```bash
76
+ termbeam [shell] [args...] # start with a specific shell (default: auto-detect)
77
+ termbeam --port 8080 # custom port (default: 3456)
78
+ termbeam --host 127.0.0.1 # restrict to localhost (default: 0.0.0.0)
141
79
  ```
142
80
 
143
- See the [Architecture Guide](https://dorlugasigal.github.io/TermBeam/architecture/) for details.
81
+ | Flag | Description | Default |
82
+ | --------------------- | ---------------------------------------- | ----------- |
83
+ | `--password <pw>` | Set access password | None |
84
+ | `--generate-password` | Auto-generate a secure password | โ€” |
85
+ | `--tunnel` | Create an ephemeral devtunnel URL | Off |
86
+ | `--persisted-tunnel` | Create a reusable devtunnel URL | Off |
87
+ | `--port <port>` | Server port | `3456` |
88
+ | `--host <addr>` | Bind address | `0.0.0.0` |
144
89
 
145
- ## ๐Ÿ“š Documentation
90
+ Environment variables: `PORT`, `TERMBEAM_PASSWORD`, `TERMBEAM_CWD` (see [Configuration docs](https://dorlugasigal.github.io/TermBeam/configuration/)).
146
91
 
147
- Full documentation is available at **[dorlugasigal.github.io/TermBeam](https://dorlugasigal.github.io/TermBeam/)**
92
+ ## Security
148
93
 
149
- - [Getting Started](https://dorlugasigal.github.io/TermBeam/getting-started/)
150
- - [Configuration](https://dorlugasigal.github.io/TermBeam/configuration/)
151
- - [Security](https://dorlugasigal.github.io/TermBeam/security/)
152
- - [API Reference](https://dorlugasigal.github.io/TermBeam/api/)
153
- - [Architecture](https://dorlugasigal.github.io/TermBeam/architecture/)
94
+ TermBeam binds to all interfaces (`0.0.0.0`) by default, so it's accessible on your local network out of the box. **Always set a password** when running on a shared network, or pass `--host 127.0.0.1` to restrict access to your machine only.
154
95
 
155
- ## ๐Ÿค Contributing
96
+ Auth uses secure httpOnly cookies with 24-hour expiry, login is rate-limited to 5 attempts per minute, and security headers (X-Frame-Options, X-Content-Type-Options, etc.) are set on all responses. API clients that can't use cookies can authenticate with an `Authorization: Bearer <password>` header. See the [Security Guide](https://dorlugasigal.github.io/TermBeam/security/) for more.
156
97
 
157
- Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for:
98
+ ## Contributing
158
99
 
159
- - Development setup and local workflow
160
- - Testing guide (Node.js built-in test runner)
161
- - Commit conventions and PR process
162
- - Release process (maintainers)
100
+ Contributions welcome โ€” see [CONTRIBUTING.md](CONTRIBUTING.md).
163
101
 
164
- ## ๐Ÿ“„ License
102
+ ## License
165
103
 
166
- [MIT](LICENSE) โ€” made with โค๏ธ by [@dorlugasigal](https://github.com/dorlugasigal)
104
+ [MIT](LICENSE)
167
105
 
168
- ## ๐Ÿ™ Acknowledgments
106
+ ## Acknowledgments
169
107
 
170
108
  Special thanks to [@tamirdresher](https://github.com/tamirdresher) for the [blog post](https://www.tamirdresher.com/blog/2026/02/26/squad-remote-control) that inspired the solution idea for this project, and for his [cli-tunnel](https://github.com/tamirdresher/cli-tunnel) implementation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termbeam",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Beam your terminal to any device โ€” mobile-optimized web terminal with multi-session support",
5
5
  "main": "src/server.js",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  "start": "node bin/termbeam.js",
11
11
  "dev": "node bin/termbeam.js --generate-password",
12
12
  "test": "node --test test/*.test.js",
13
+ "test:coverage": "c8 --reporter=text --reporter=lcov --reporter=json-summary --reporter=json node --test --test-reporter=spec --test-reporter-destination=stdout test/*.test.js",
13
14
  "prepare": "husky",
14
15
  "format": "prettier --write .",
15
16
  "lint": "node --check src/*.js bin/*.js",
@@ -62,6 +63,7 @@
62
63
  "ws": "^8.19.0"
63
64
  },
64
65
  "devDependencies": {
66
+ "c8": "^11.0.0",
65
67
  "husky": "^9.1.7",
66
68
  "lint-staged": "^16.2.7",
67
69
  "prettier": "^3.8.1"
package/src/cli.js CHANGED
@@ -33,28 +33,84 @@ Environment:
33
33
  `);
34
34
  }
35
35
 
36
+ /**
37
+ * Get ancestor process names on Windows by walking up the process tree.
38
+ * Fetches all processes in a single wmic call, then walks the tree in memory.
39
+ */
40
+ function getWindowsAncestors(startPid, maxDepth = 4) {
41
+ const { execFileSync } = require('child_process');
42
+ const names = [];
43
+ const safePid = parseInt(startPid, 10);
44
+ if (!Number.isFinite(safePid) || safePid <= 0) return names;
45
+
46
+ try {
47
+ const result = execFileSync(
48
+ 'wmic',
49
+ ['process', 'get', 'Name,ParentProcessId,ProcessId', '/format:csv'],
50
+ { stdio: ['pipe', 'pipe', 'ignore'], encoding: 'utf8', timeout: 5000 },
51
+ );
52
+
53
+ // Parse CSV output โ€” first non-empty line is the header
54
+ const lines = result.split(/\r?\n/).filter((l) => l.trim());
55
+ if (lines.length === 0) return names;
56
+
57
+ const header = lines[0].split(',').map((h) => h.trim());
58
+ const nameIdx = header.indexOf('Name');
59
+ const pidIdx = header.indexOf('ProcessId');
60
+ const ppidIdx = header.indexOf('ParentProcessId');
61
+ if (nameIdx === -1 || pidIdx === -1 || ppidIdx === -1) return names;
62
+
63
+ const processes = new Map();
64
+ for (let i = 1; i < lines.length; i++) {
65
+ const cols = lines[i].split(',');
66
+ if (cols.length <= Math.max(nameIdx, pidIdx, ppidIdx)) continue;
67
+ const pid = parseInt(cols[pidIdx], 10);
68
+ if (Number.isFinite(pid)) {
69
+ processes.set(pid, { name: cols[nameIdx].trim().toLowerCase(), ppid: parseInt(cols[ppidIdx], 10) });
70
+ }
71
+ }
72
+
73
+ // Walk up the tree in memory โ€” no more subprocess calls
74
+ let currentPid = safePid;
75
+ for (let i = 0; i < maxDepth; i++) {
76
+ const proc = processes.get(currentPid);
77
+ if (!proc) break;
78
+ console.log(`[termbeam] Process tree: ${proc.name}`);
79
+ names.push(proc.name);
80
+ if (!Number.isFinite(proc.ppid) || proc.ppid === 0 || proc.ppid === currentPid) break;
81
+ currentPid = proc.ppid;
82
+ }
83
+ } catch (err) {
84
+ console.log(`[termbeam] Could not query process tree: ${err.message}`);
85
+ }
86
+
87
+ return names;
88
+ }
89
+
36
90
  function getDefaultShell() {
37
91
  const { execFileSync } = require('child_process');
38
92
  const ppid = process.ppid;
39
93
  console.log(`[termbeam] Detecting shell (parent PID: ${ppid}, platform: ${os.platform()})`);
40
94
 
41
95
  if (os.platform() === 'win32') {
42
- // Detect parent process on Windows via WMIC
43
- try {
44
- const result = execFileSync(
45
- 'wmic',
46
- ['process', 'where', `ProcessId=${ppid}`, 'get', 'Name', '/value'],
47
- { stdio: ['pipe', 'pipe', 'ignore'], encoding: 'utf8', timeout: 3000 },
48
- );
49
- const match = result.match(/Name=(.+)/);
50
- if (match) {
51
- const name = match[1].trim().toLowerCase();
52
- console.log(`[termbeam] Detected parent process: ${name}`);
53
- if (name === 'pwsh.exe') return 'pwsh.exe';
54
- if (name === 'powershell.exe') return 'powershell.exe';
96
+ // Walk up the process tree (up to 4 ancestors) to find the real user shell.
97
+ // npx/npm on Windows spawns cmd.exe as intermediary, so the immediate
98
+ // parent is often cmd.exe or node.exe rather than the user's actual shell.
99
+ const ancestors = getWindowsAncestors(ppid);
100
+ const preferredShells = ['pwsh.exe', 'powershell.exe'];
101
+
102
+ let foundCmd = false;
103
+ for (const name of ancestors) {
104
+ if (preferredShells.includes(name)) {
105
+ console.log(`[termbeam] Found shell in process tree: ${name}`);
106
+ return name;
55
107
  }
56
- } catch (err) {
57
- console.log(`[termbeam] Could not detect parent process: ${err.message}`);
108
+ if (name === 'cmd.exe') foundCmd = true;
109
+ }
110
+
111
+ if (foundCmd) {
112
+ console.log(`[termbeam] Using detected shell: cmd.exe`);
113
+ return 'cmd.exe';
58
114
  }
59
115
  const fallback = process.env.COMSPEC || 'cmd.exe';
60
116
  console.log(`[termbeam] Falling back to: ${fallback}`);