termbeam 1.8.1 → 1.10.0

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/README.md CHANGED
@@ -14,9 +14,7 @@
14
14
 
15
15
  </div>
16
16
 
17
- 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.
18
-
19
- 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-optimized UI — key bar, swipe scroll, pinch zoom — that actually works on small screens. You get multi-session tabs with split view, terminal search, a command palette, 12 themes, and secure remote access out of the box.
17
+ TermBeam lets you access your terminal from a phone, tablet, or any browser — no SSH, no port forwarding, no configuration needed. Run one command and scan the QR code.
20
18
 
21
19
  [Full documentation](https://dorlugasigal.github.io/TermBeam/) · [Website](https://termbeam.pages.dev)
22
20
 
@@ -47,90 +45,80 @@ termbeam
47
45
 
48
46
  Scan the QR code printed in your terminal, or open the URL on any device.
49
47
 
50
- > **First time?** Run `termbeam -i` for a guided setup wizard that walks you through password, port, and access mode.
51
-
52
- ### Secure by default
53
-
54
- TermBeam starts with a tunnel and auto-generated password out of the box — just run `termbeam` and scan the QR code.
55
-
56
48
  ```bash
57
49
  termbeam # tunnel + auto-password (default)
58
- termbeam --password mysecret # use a specific password
59
- termbeam --no-tunnel # LAN-only (no tunnel)
60
- termbeam --no-password # disable password protection
50
+ termbeam --password mysecret # custom password
51
+ termbeam --no-tunnel # LAN only
61
52
  termbeam -i # interactive setup wizard
62
53
  ```
63
54
 
64
- ## Remote Access
55
+ ## Features
65
56
 
66
- ```bash
67
- # Tunnel is on by default
68
- termbeam
57
+ ### Mobile-First
69
58
 
70
- # Persisted tunnel (stable URL you can bookmark, reused across restarts, 30-day expiry)
71
- termbeam --persisted-tunnel
59
+ - **No SSH client needed** just open a browser on any device
60
+ - **Touch-optimized key bar** with arrows, Tab, Ctrl, Esc, copy, paste, and more
61
+ - **Swipe scrolling**, pinch zoom, and text selection overlay for copy-paste
62
+ - **iPhone PWA safe-area support** for a native-app feel
72
63
 
73
- # LAN-only (no tunnel)
74
- termbeam --no-tunnel
75
- ```
64
+ ### Multi-Session
76
65
 
77
- If the [Dev Tunnels CLI](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started) is not installed, TermBeam will offer to install it for you automatically. You can also install it manually:
66
+ - **Tabbed terminals** with drag-to-reorder and live tab previews on hover/long-press
67
+ - **Split view** — two sessions side-by-side (auto-rotates horizontal/vertical)
68
+ - **Session colors and activity indicators** for at-a-glance status
69
+ - **Folder browser** for picking working directory, optional initial command per session
78
70
 
79
- - **Windows:** `winget install Microsoft.devtunnel`
80
- - **macOS:** `brew install --cask devtunnel`
81
- - **Linux:** `curl -sL https://aka.ms/DevTunnelCliInstall | bash`
71
+ ### Productivity
82
72
 
83
- Persisted tunnels save a tunnel ID to `~/.termbeam/tunnel.json` so the URL stays the same between sessions.
73
+ - **Terminal search** with regex, match count, and prev/next navigation
74
+ - **Command palette** (Ctrl+K / Cmd+K) for quick access to all actions
75
+ - **File upload** — send files from your phone to the session's working directory
76
+ - **Completion notifications** — browser alerts when background commands finish
77
+ - **12 color themes** with adjustable font size
78
+ - **Port preview** — reverse-proxy a local web server through TermBeam
79
+ - **Image paste** from clipboard
84
80
 
85
- ## CLI Reference
81
+ ### Secure by Default
86
82
 
87
- ```bash
88
- termbeam [shell] [args...] # start with a specific shell (default: auto-detect)
89
- termbeam --port 8080 # custom port (default: 3456)
90
- termbeam --host 0.0.0.0 # allow LAN access (default: 127.0.0.1)
91
- termbeam --lan # shortcut for --host 0.0.0.0
92
- termbeam -i # interactive setup wizard
93
- termbeam service install # interactive PM2 service setup wizard
94
- termbeam service uninstall # stop & remove PM2 service
95
- termbeam service status # show PM2 service status
96
- termbeam service logs # tail PM2 service logs
97
- termbeam service restart # restart PM2 service
83
+ - **Auto-generated password** with rate limiting and httpOnly cookies
84
+ - **QR code auto-login** with single-use share tokens (5-min expiry)
85
+ - **DevTunnel integration** for secure remote access — ephemeral or persisted URLs
86
+ - **Security headers** (X-Frame-Options, CSP, nosniff) on all responses; only detected shells allowed
87
+
88
+ ## How It Works
89
+
90
+ TermBeam starts a lightweight web server that spawns a PTY (pseudo-terminal) with your shell, serves a mobile-optimized [xterm.js](https://xtermjs.org/) UI via Express, and bridges the two over WebSocket. Multiple clients can view the same session simultaneously, and sessions persist when all clients disconnect.
91
+
92
+ ```mermaid
93
+ flowchart LR
94
+ A["Phone / Browser"] <-->|WebSocket| B["TermBeam Server"]
95
+ B <-->|PTY| C["Shell (zsh/bash)"]
96
+ B -->|Express| D["Web UI (xterm.js)"]
97
+ B -.->|Optional| E["DevTunnel"]
98
98
  ```
99
99
 
100
- | Flag | Description | Default |
101
- | --------------------- | ---------------------------------------------------- | -------------- |
102
- | `--password <pw>` | Set access password (also accepts `--password=<pw>`) | Auto-generated |
103
- | `--no-password` | Disable password (cannot combine with `--public`) | — |
104
- | `--generate-password` | Auto-generate a secure password | On |
105
- | `--tunnel` | Create an ephemeral devtunnel URL (private) | On |
106
- | `--no-tunnel` | Disable tunnel (LAN-only) | — |
107
- | `--persisted-tunnel` | Create a reusable devtunnel URL | Off |
108
- | `--public` | Allow public tunnel access | Off |
109
- | `--port <port>` | Server port | `3456` |
110
- | `--host <addr>` | Bind address | `127.0.0.1` |
111
- | `--lan` | Bind to all interfaces (LAN access) | Off |
112
- | `--log-level <level>` | Log verbosity (error/warn/info/debug) | `info` |
113
- | `-i, --interactive` | Interactive setup wizard (guided configuration) | Off |
114
- | `-h, --help` | Show help | — |
115
- | `-v, --version` | Show version | — |
116
-
117
- | Subcommand | Description |
118
- | ------------------- | ----------------------------- |
119
- | `service install` | Interactive PM2 service setup |
120
- | `service uninstall` | Stop & remove from PM2 |
121
- | `service status` | Show PM2 service status |
122
- | `service logs` | Tail PM2 service logs |
123
- | `service restart` | Restart PM2 service |
124
-
125
- Environment variables: `PORT`, `TERMBEAM_PASSWORD`, `TERMBEAM_CWD`, `TERMBEAM_LOG_LEVEL`, `SHELL` (Unix fallback), `COMSPEC` (Windows fallback). See [Configuration docs](https://dorlugasigal.github.io/TermBeam/configuration/).
100
+ ## CLI Highlights
126
101
 
127
- ## Security
102
+ | Flag | Description | Default |
103
+ | --------------------- | ----------------------------------------------- | -------------- |
104
+ | `--password <pw>` | Set access password | Auto-generated |
105
+ | `--no-password` | Disable password protection | — |
106
+ | `--tunnel` | Create an ephemeral devtunnel URL | On |
107
+ | `--no-tunnel` | Disable tunnel (LAN-only) | — |
108
+ | `--persisted-tunnel` | Reusable devtunnel URL (stable across restarts) | Off |
109
+ | `--port <port>` | Server port | `3456` |
110
+ | `--host <addr>` | Bind address | `127.0.0.1` |
111
+ | `--lan` | Bind to all interfaces (LAN access) | Off |
112
+ | `-i, --interactive` | Interactive setup wizard | Off |
113
+ | `--log-level <level>` | Log verbosity (error/warn/info/debug) | `info` |
114
+
115
+ For all flags, subcommands, and environment variables, see the [Configuration docs](https://dorlugasigal.github.io/TermBeam/configuration/).
128
116
 
129
- TermBeam auto-generates a password and creates a tunnel by default, so your terminal is protected out of the box. By default, the server binds to `127.0.0.1` (localhost only). Use `--lan` or `--host 0.0.0.0` to allow LAN access, or `--no-tunnel` to disable the tunnel.
117
+ ## Security
130
118
 
131
- 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. Each QR code contains a single-use share token (5-minute expiry) for password-free login. API clients that can't use cookies can authenticate with an `Authorization: Bearer <password>` header.
119
+ TermBeam auto-generates a password and creates a secure tunnel by default, binding to `127.0.0.1` (localhost only). Auth uses httpOnly cookies with 24-hour expiry, login is rate-limited to 5 attempts per minute, QR codes contain single-use share tokens (5-min expiry), and security headers (X-Frame-Options, CSP, nosniff) are set on all responses.
132
120
 
133
- For the full threat model, safe usage guidance, and a quick safety checklist, see [SECURITY.md](SECURITY.md). For detailed security feature documentation, see the [Security Guide](https://dorlugasigal.github.io/TermBeam/security/).
121
+ For the full threat model and safety checklist, see [SECURITY.md](SECURITY.md). For detailed security documentation, see the [Security Guide](https://dorlugasigal.github.io/TermBeam/security/).
134
122
 
135
123
  ## Contributing
136
124
 
package/bin/termbeam.js CHANGED
@@ -8,13 +8,142 @@ if (subcommand === 'service') {
8
8
  console.error(err.message);
9
9
  process.exit(1);
10
10
  });
11
+ } else if (subcommand === 'resume') {
12
+ const { resume } = require('../src/resume');
13
+ resume(process.argv.slice(3)).catch((err) => {
14
+ console.error(err.message);
15
+ process.exit(1);
16
+ });
17
+ } else if (subcommand === 'list') {
18
+ const { list } = require('../src/resume');
19
+ list().catch((err) => {
20
+ console.error(err.message);
21
+ process.exit(1);
22
+ });
11
23
  } else {
24
+ // Reject any non-flag positional arg — it's not a known subcommand
25
+ if (subcommand && !subcommand.startsWith('-')) {
26
+ const { printHelp } = require('../src/cli');
27
+ console.error(`Unknown command: ${subcommand}\n`);
28
+ printHelp();
29
+ process.exit(1);
30
+ }
31
+
12
32
  const { createTermBeamServer } = require('../src/server.js');
13
33
  const { parseArgs } = require('../src/cli');
14
34
  const { runInteractiveSetup } = require('../src/interactive');
35
+ const { readConnectionConfig } = require('../src/resume');
36
+ const http = require('http');
37
+
38
+ function httpPost(url, headers) {
39
+ return new Promise((resolve) => {
40
+ const parsed = new URL(url);
41
+ const req = http.request(
42
+ {
43
+ hostname: parsed.hostname,
44
+ port: parsed.port,
45
+ path: parsed.pathname,
46
+ method: 'POST',
47
+ headers,
48
+ timeout: 2000,
49
+ },
50
+ (res) => {
51
+ res.resume();
52
+ resolve(res.statusCode);
53
+ },
54
+ );
55
+ req.on('error', () => resolve(null));
56
+ req.on('timeout', () => {
57
+ req.destroy();
58
+ resolve(null);
59
+ });
60
+ req.end();
61
+ });
62
+ }
63
+
64
+ function checkExistingServer(config) {
65
+ if (!config) return Promise.resolve(false);
66
+ const host = config.host === 'localhost' ? '127.0.0.1' : config.host;
67
+ return new Promise((resolve) => {
68
+ const req = http.get(
69
+ `http://${host}:${config.port}/api/sessions`,
70
+ {
71
+ timeout: 2000,
72
+ headers: config.password ? { Authorization: `Bearer ${config.password}` } : {},
73
+ },
74
+ (res) => {
75
+ res.resume();
76
+ resolve(res.statusCode < 500);
77
+ },
78
+ );
79
+ req.on('error', () => resolve(false));
80
+ req.on('timeout', () => {
81
+ req.destroy();
82
+ resolve(false);
83
+ });
84
+ });
85
+ }
86
+
87
+ async function stopExistingServer(config, fallbackPassword) {
88
+ // Always target loopback — the shutdown endpoint only accepts loopback requests
89
+ const url = `http://127.0.0.1:${config.port}/api/shutdown`;
90
+ console.log(`Stopping existing server on port ${config.port}...`);
91
+
92
+ // Try with config password, then fallback password, then no password
93
+ const passwords = [config.password, fallbackPassword, null].filter(
94
+ (v, i, a) => a.indexOf(v) === i,
95
+ );
96
+ let stopped = false;
97
+ for (const pw of passwords) {
98
+ const headers = pw ? { Authorization: `Bearer ${pw}` } : {};
99
+ const status = await httpPost(url, headers);
100
+ if (status && status !== 401) {
101
+ stopped = true;
102
+ break;
103
+ }
104
+ }
105
+ if (!stopped) {
106
+ console.error(
107
+ 'Cannot stop the existing server — password mismatch.\n' +
108
+ 'Stop it manually (Ctrl+C in its terminal) and try again.',
109
+ );
110
+ process.exit(1);
111
+ }
112
+ for (let i = 0; i < 20; i++) {
113
+ await new Promise((r) => setTimeout(r, 250));
114
+ if (!(await checkExistingServer(config))) break;
115
+ }
116
+ }
15
117
 
16
118
  async function main() {
17
119
  const baseConfig = parseArgs();
120
+ const targetPort = baseConfig.port;
121
+ const targetHost = baseConfig.host === '0.0.0.0' ? '127.0.0.1' : baseConfig.host;
122
+
123
+ // Check connection.json for an existing server
124
+ const existing = readConnectionConfig();
125
+ if (existing && (await checkExistingServer(existing))) {
126
+ if (baseConfig.force) {
127
+ await stopExistingServer(existing, baseConfig.password);
128
+ } else {
129
+ const displayHost = existing.host === '127.0.0.1' ? 'localhost' : existing.host;
130
+ console.error(
131
+ `TermBeam is already running on http://${displayHost}:${existing.port}\n` +
132
+ 'Use "termbeam resume" to reconnect, "termbeam list" to list sessions,\n' +
133
+ 'or "termbeam --force" to stop the existing server and start a new one.',
134
+ );
135
+ process.exit(1);
136
+ }
137
+ }
138
+
139
+ // Also check the target port directly (handles stale/missing connection.json)
140
+ if (baseConfig.force && targetPort !== 0) {
141
+ const targetConfig = { host: targetHost, port: targetPort, password: baseConfig.password };
142
+ if (await checkExistingServer(targetConfig)) {
143
+ await stopExistingServer(targetConfig);
144
+ }
145
+ }
146
+
18
147
  let config;
19
148
  if (baseConfig.interactive) {
20
149
  config = await runInteractiveSetup(baseConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termbeam",
3
- "version": "1.8.1",
3
+ "version": "1.10.0",
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": {
@@ -1165,6 +1165,9 @@
1165
1165
  max-height: 90vh;
1166
1166
  overflow-y: auto;
1167
1167
  }
1168
+ #upload-modal .modal {
1169
+ overflow: visible;
1170
+ }
1168
1171
  .modal h2 {
1169
1172
  font-size: 18px;
1170
1173
  margin-bottom: 16px;
@@ -1982,6 +1985,53 @@
1982
1985
  <button class="key-btn icon-btn" data-key="&#x1b;[C" title="Right">→</button>
1983
1986
  </div>
1984
1987
  </div>
1988
+ <input type="file" id="upload-input" multiple hidden />
1989
+
1990
+ <!-- Upload Confirm Modal -->
1991
+ <div class="modal-overlay" id="upload-modal">
1992
+ <div class="modal">
1993
+ <h2>Upload Files</h2>
1994
+ <div
1995
+ id="upload-file-list"
1996
+ style="
1997
+ margin-bottom: 12px;
1998
+ font-size: 13px;
1999
+ color: var(--text-secondary);
2000
+ max-height: 120px;
2001
+ overflow-y: auto;
2002
+ "
2003
+ ></div>
2004
+ <label for="upload-dir">Destination directory</label>
2005
+ <div class="cwd-picker">
2006
+ <input type="text" id="upload-dir" placeholder="Session working directory" />
2007
+ <button
2008
+ type="button"
2009
+ class="cwd-browse-btn"
2010
+ id="upload-browse-btn"
2011
+ title="Browse folders"
2012
+ >
2013
+ <svg
2014
+ width="18"
2015
+ height="18"
2016
+ viewBox="0 0 24 24"
2017
+ fill="none"
2018
+ stroke="currentColor"
2019
+ stroke-width="2"
2020
+ stroke-linecap="round"
2021
+ stroke-linejoin="round"
2022
+ >
2023
+ <path
2024
+ d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"
2025
+ />
2026
+ </svg>
2027
+ </button>
2028
+ </div>
2029
+ <div class="modal-actions">
2030
+ <button class="btn-cancel" id="upload-cancel">Cancel</button>
2031
+ <button class="btn-create" id="upload-confirm">Upload</button>
2032
+ </div>
2033
+ </div>
2034
+ </div>
1985
2035
 
1986
2036
  <div id="reconnect-overlay">
1987
2037
  <div class="msg">Session disconnected</div>
@@ -2449,6 +2499,7 @@
2449
2499
  setupKeyBar();
2450
2500
  setupPaste();
2451
2501
  setupImagePaste();
2502
+ setupUpload();
2452
2503
  setupSelectMode();
2453
2504
  setupNewSessionModal();
2454
2505
  setupPreviewModal();
@@ -3739,6 +3790,167 @@
3739
3790
  );
3740
3791
  }
3741
3792
 
3793
+ // ===== File Upload =====
3794
+ function setupUpload() {
3795
+ const uploadInput = document.getElementById('upload-input');
3796
+ const uploadModal = document.getElementById('upload-modal');
3797
+ const uploadDirInput = document.getElementById('upload-dir');
3798
+ const uploadFileList = document.getElementById('upload-file-list');
3799
+ const uploadConfirmBtn = document.getElementById('upload-confirm');
3800
+ const uploadCancelBtn = document.getElementById('upload-cancel');
3801
+ const uploadBrowseBtn = document.getElementById('upload-browse-btn');
3802
+
3803
+ let pendingFiles = null;
3804
+
3805
+ const MAX_FILE_SIZE = 10 * 1024 * 1024;
3806
+
3807
+ function openUploadModal(files) {
3808
+ pendingFiles = files;
3809
+ const ms = managed.get(activeId);
3810
+ const cwd = (ms && ms.cwd) || '';
3811
+ uploadDirInput.value = cwd;
3812
+ let hasOversized = false;
3813
+ uploadFileList.innerHTML = '';
3814
+ Array.from(files).forEach((f) => {
3815
+ const oversized = f.size > MAX_FILE_SIZE;
3816
+ if (oversized) hasOversized = true;
3817
+ const row = document.createElement('div');
3818
+ if (oversized) row.style.color = '#f87171';
3819
+ row.textContent =
3820
+ '📄 ' +
3821
+ f.name +
3822
+ ' (' +
3823
+ formatSize(f.size) +
3824
+ ')' +
3825
+ (oversized ? ' exceeds 10 MB limit' : '');
3826
+ uploadFileList.appendChild(row);
3827
+ });
3828
+ uploadConfirmBtn.disabled = hasOversized;
3829
+ uploadConfirmBtn.style.opacity = hasOversized ? '0.5' : '1';
3830
+ uploadModal.classList.add('visible');
3831
+ }
3832
+
3833
+ function closeUploadModal() {
3834
+ uploadModal.classList.remove('visible');
3835
+ closeBrowseDropdown();
3836
+ pendingFiles = null;
3837
+ }
3838
+
3839
+ function formatSize(bytes) {
3840
+ if (bytes < 1024) return bytes + ' B';
3841
+ if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
3842
+ return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
3843
+ }
3844
+
3845
+ uploadInput.addEventListener('change', () => {
3846
+ const files = uploadInput.files;
3847
+ if (!files || !files.length || !activeId) return;
3848
+ openUploadModal(files);
3849
+ });
3850
+
3851
+ uploadCancelBtn.addEventListener('click', closeUploadModal);
3852
+ uploadModal.addEventListener('click', (e) => {
3853
+ if (e.target === uploadModal) closeUploadModal();
3854
+ });
3855
+
3856
+ // Directory browsing (reuse /api/dirs)
3857
+ let browseDropdown = null;
3858
+
3859
+ function closeBrowseDropdown() {
3860
+ if (browseDropdown) {
3861
+ browseDropdown.remove();
3862
+ browseDropdown = null;
3863
+ }
3864
+ }
3865
+
3866
+ // Close dropdown when clicking outside
3867
+ document.addEventListener('click', (e) => {
3868
+ if (
3869
+ browseDropdown &&
3870
+ !browseDropdown.contains(e.target) &&
3871
+ e.target !== uploadBrowseBtn
3872
+ ) {
3873
+ closeBrowseDropdown();
3874
+ }
3875
+ });
3876
+
3877
+ uploadBrowseBtn.addEventListener('click', async () => {
3878
+ if (browseDropdown) {
3879
+ closeBrowseDropdown();
3880
+ return;
3881
+ }
3882
+ const q = uploadDirInput.value || '';
3883
+ try {
3884
+ const res = await fetch('/api/dirs?q=' + encodeURIComponent(q ? q + '/' : ''), {
3885
+ credentials: 'same-origin',
3886
+ });
3887
+ const data = await res.json();
3888
+ if (!data.dirs || !data.dirs.length) return;
3889
+ browseDropdown = document.createElement('div');
3890
+ browseDropdown.style.cssText =
3891
+ 'position:absolute;left:0;right:0;bottom:100%;margin-bottom:4px;max-height:150px;overflow-y:auto;background:var(--surface);border:1px solid var(--border);border-radius:6px;z-index:10;box-shadow:0 -4px 12px rgba(0,0,0,0.2);';
3892
+ data.dirs.forEach((d) => {
3893
+ const opt = document.createElement('div');
3894
+ opt.textContent = d;
3895
+ opt.style.cssText =
3896
+ 'padding:6px 10px;cursor:pointer;font-size:13px;color:var(--text);';
3897
+ opt.addEventListener('mouseenter', () => (opt.style.background = 'var(--hover)'));
3898
+ opt.addEventListener('mouseleave', () => (opt.style.background = 'none'));
3899
+ opt.addEventListener('click', () => {
3900
+ uploadDirInput.value = d;
3901
+ closeBrowseDropdown();
3902
+ });
3903
+ browseDropdown.appendChild(opt);
3904
+ });
3905
+ uploadBrowseBtn.parentElement.style.position = 'relative';
3906
+ uploadBrowseBtn.parentElement.appendChild(browseDropdown);
3907
+ } catch {}
3908
+ });
3909
+
3910
+ uploadConfirmBtn.addEventListener('click', async () => {
3911
+ if (!pendingFiles || !pendingFiles.length || !activeId) return;
3912
+ const targetDir = uploadDirInput.value.trim();
3913
+ const filesToUpload = Array.from(pendingFiles);
3914
+ closeUploadModal();
3915
+
3916
+ let uploaded = 0;
3917
+ let failed = 0;
3918
+
3919
+ for (const file of filesToUpload) {
3920
+ try {
3921
+ const headers = {
3922
+ 'Content-Type': file.type || 'application/octet-stream',
3923
+ 'X-Filename': file.name,
3924
+ };
3925
+ if (targetDir) headers['X-Target-Dir'] = targetDir;
3926
+ const res = await fetch(`/api/sessions/${activeId}/upload`, {
3927
+ method: 'POST',
3928
+ headers,
3929
+ body: file,
3930
+ credentials: 'same-origin',
3931
+ });
3932
+ if (!res.ok) {
3933
+ const err = await res.json().catch(() => ({}));
3934
+ throw new Error(err.error || 'Upload failed');
3935
+ }
3936
+ await res.json();
3937
+ uploaded++;
3938
+ } catch (err) {
3939
+ failed++;
3940
+ console.error('Upload error:', file.name, err);
3941
+ }
3942
+ }
3943
+
3944
+ if (uploaded > 0) {
3945
+ const dir = targetDir || 'session directory';
3946
+ showToast(`${uploaded} file${uploaded > 1 ? 's' : ''} uploaded to ${dir}`);
3947
+ }
3948
+ if (failed > 0) {
3949
+ showToast(`${failed} file${failed > 1 ? 's' : ''} failed to upload`);
3950
+ }
3951
+ });
3952
+ }
3953
+
3742
3954
  // ===== New Session Modal =====
3743
3955
  let shellsLoaded = false;
3744
3956
 
@@ -4164,6 +4376,19 @@
4164
4376
  category: 'Session',
4165
4377
  action: () => openNewSessionModal(),
4166
4378
  },
4379
+ {
4380
+ icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>',
4381
+ label: 'Upload files',
4382
+ category: 'Session',
4383
+ action: () => {
4384
+ if (!activeId) {
4385
+ showToast('No active session');
4386
+ return;
4387
+ }
4388
+ document.getElementById('upload-input').value = '';
4389
+ document.getElementById('upload-input').click();
4390
+ },
4391
+ },
4167
4392
  {
4168
4393
  icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
4169
4394
  label: 'Close tab',
@@ -4348,8 +4573,8 @@
4348
4573
  btn.innerHTML =
4349
4574
  '<span class="palette-action-icon">' + a.icon + '</span>' + esc(a.label);
4350
4575
  btn.addEventListener('click', () => {
4351
- if (!a.keepOpen) closePalette();
4352
4576
  a.action();
4577
+ if (!a.keepOpen) closePalette();
4353
4578
  });
4354
4579
  body.appendChild(btn);
4355
4580
  });
package/src/cli.js CHANGED
@@ -10,6 +10,8 @@ termbeam — Beam your terminal to any device
10
10
 
11
11
  Usage:
12
12
  termbeam [options] [shell] [args...]
13
+ termbeam resume [name] [options] Reconnect to a running session
14
+ termbeam list List running sessions
13
15
  termbeam service <action> Manage as a background service (PM2)
14
16
 
15
17
  Actions (service):
@@ -31,6 +33,7 @@ Options:
31
33
  --host <addr> Bind address (default: 127.0.0.1)
32
34
  --lan Bind to 0.0.0.0 (allow LAN access, default: localhost only)
33
35
  --log-level <level> Set log verbosity: error, warn, info, debug (default: info)
36
+ --force Stop any existing server before starting a new one
34
37
  -i, --interactive Interactive setup wizard (guided configuration)
35
38
  -h, --help Show this help
36
39
  -v, --version Show version
@@ -50,6 +53,8 @@ Examples:
50
53
  termbeam /bin/bash Use bash instead of default shell
51
54
  termbeam --interactive Guided setup wizard
52
55
  termbeam service install Set up as background service (PM2)
56
+ termbeam resume Reconnect to an active session
57
+ termbeam list List all active sessions
53
58
 
54
59
  Environment:
55
60
  PORT Server port (default: 3456)
@@ -244,6 +249,7 @@ function parseArgs() {
244
249
  let persistedTunnel = false;
245
250
  let publicTunnel = false;
246
251
  let interactive = false;
252
+ let force = false;
247
253
  let explicitPassword = !!password;
248
254
 
249
255
  const args = process.argv.slice(2);
@@ -288,6 +294,14 @@ function parseArgs() {
288
294
  interactive = true;
289
295
  } else if (args[i] === '--log-level' && args[i + 1]) {
290
296
  logLevel = args[++i];
297
+ } else if (args[i].startsWith('--log-level=')) {
298
+ logLevel = args[i].split('=')[1];
299
+ } else if (args[i] === '--force') {
300
+ force = true;
301
+ } else if (args[i].startsWith('--')) {
302
+ console.error(`Unknown flag: ${args[i]}\n`);
303
+ printHelp();
304
+ process.exit(1);
291
305
  } else {
292
306
  filteredArgs.push(args[i]);
293
307
  }
@@ -341,6 +355,7 @@ function parseArgs() {
341
355
  version,
342
356
  logLevel,
343
357
  interactive,
358
+ force,
344
359
  };
345
360
  }
346
361