Skip to content

Commit 6621538

Browse files
feat(cli): add interactive setup wizard (#72)
Adds a -i / --interactive flag that launches a guided terminal wizard for first-time users. The wizard walks through password, port, access mode (tunnel type and visibility), and log level, then starts the server with the chosen config. Key changes: - Extract prompt helpers (color, ask, choose, confirm) from service.js into src/prompts.js so both the service install wizard and the new setup wizard can share them - Add src/interactive.js with the wizard flow (runs in an alternate screen buffer) - Port validation clamped to 1-65535, passwords masked in summary output - Alternate screen buffer cleaned up on Ctrl+C - Docs updated: architecture, configuration, getting-started, README, landing page, MkDocs index Closes #71 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 683e6a4 commit 6621538

14 files changed

Lines changed: 1230 additions & 160 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ termbeam
4646

4747
Scan the QR code printed in your terminal, or open the URL on any device.
4848

49+
> **First time?** Run `termbeam -i` for a guided setup wizard that walks you through password, port, and access mode.
50+
4951
### Secure by default
5052

5153
TermBeam starts with a tunnel and auto-generated password out of the box — just run `termbeam` and scan the QR code.
@@ -55,6 +57,7 @@ termbeam # tunnel + auto-password (default)
5557
termbeam --password mysecret # use a specific password
5658
termbeam --no-tunnel # LAN-only (no tunnel)
5759
termbeam --no-password # disable password protection
60+
termbeam -i # interactive setup wizard
5861
```
5962

6063
## Remote Access
@@ -85,6 +88,7 @@ termbeam [shell] [args...] # start with a specific shell (default: auto-d
8588
termbeam --port 8080 # custom port (default: 3456)
8689
termbeam --host 0.0.0.0 # allow LAN access (default: 127.0.0.1)
8790
termbeam --lan # shortcut for --host 0.0.0.0
91+
termbeam -i # interactive setup wizard
8892
termbeam service install # interactive PM2 service setup wizard
8993
termbeam service uninstall # stop & remove PM2 service
9094
termbeam service status # show PM2 service status
@@ -105,6 +109,7 @@ termbeam service restart # restart PM2 service
105109
| `--host <addr>` | Bind address | `127.0.0.1` |
106110
| `--lan` | Bind to all interfaces (LAN access) | Off |
107111
| `--log-level <level>` | Log verbosity (error/warn/info/debug) | `info` |
112+
| `-i, --interactive` | Interactive setup wizard (guided configuration) | Off |
108113
| `-h, --help` | Show help ||
109114
| `-v, --version` | Show version ||
110115

bin/termbeam.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,33 @@ if (subcommand === 'service') {
1010
});
1111
} else {
1212
const { createTermBeamServer } = require('../src/server.js');
13-
const instance = createTermBeamServer();
13+
const { parseArgs } = require('../src/cli');
14+
const { runInteractiveSetup } = require('../src/interactive');
1415

15-
process.on('SIGINT', () => {
16-
console.log('\n[termbeam] Shutting down...');
17-
instance.shutdown();
18-
setTimeout(() => process.exit(0), 500).unref();
19-
});
20-
process.on('SIGTERM', () => {
21-
console.log('\n[termbeam] Shutting down...');
22-
instance.shutdown();
23-
setTimeout(() => process.exit(0), 500).unref();
24-
});
16+
async function main() {
17+
const baseConfig = parseArgs();
18+
let config;
19+
if (baseConfig.interactive) {
20+
config = await runInteractiveSetup(baseConfig);
21+
}
22+
const instance = createTermBeamServer(config ? { config } : undefined);
23+
24+
process.on('SIGINT', () => {
25+
console.log('\n[termbeam] Shutting down...');
26+
instance.shutdown();
27+
setTimeout(() => process.exit(0), 500).unref();
28+
});
29+
process.on('SIGTERM', () => {
30+
console.log('\n[termbeam] Shutting down...');
31+
instance.shutdown();
32+
setTimeout(() => process.exit(0), 500).unref();
33+
});
34+
35+
instance.start();
36+
}
2537

26-
instance.start();
38+
main().catch((err) => {
39+
console.error(err.message);
40+
process.exit(1);
41+
});
2742
}

docs/architecture.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ termbeam/
1818
│ ├── tunnel.js # DevTunnel integration
1919
│ ├── preview.js # Port preview reverse proxy
2020
│ ├── service.js # PM2 service management
21+
│ ├── interactive.js # Interactive setup wizard
22+
│ ├── prompts.js # Terminal prompt primitives (color, ask, choose, confirm)
2123
│ ├── shells.js # Shell detection (cross-platform)
2224
│ ├── logger.js # Structured logger with levels
2325
│ └── version.js # Smart version detection
@@ -30,6 +32,8 @@ termbeam/
3032
├── test/
3133
│ ├── auth.test.js
3234
│ ├── cli.test.js
35+
│ ├── interactive.test.js
36+
│ ├── prompts.test.js
3337
│ ├── devtunnel-install.test.js
3438
│ ├── e2e-keybar.test.js
3539
│ ├── integration.test.js
@@ -99,6 +103,14 @@ Handles automatic installation of the DevTunnel CLI when it's not found on the s
99103

100104
Manages TermBeam as a background service via PM2. Provides an interactive wizard for `termbeam service install` that walks through configuration (name, password, port, access mode, working directory, log level, boot auto-start). Also handles `service status`, `logs`, `restart`, and `uninstall` subcommands. Generates an ecosystem config file at `~/.termbeam/ecosystem.config.js`.
101105

106+
### `interactive.js` — Setup Wizard
107+
108+
Runs a step-by-step terminal wizard (in an alternate screen buffer) that walks the user through password, port, access mode, and log level configuration. Returns a config object compatible with `createTermBeamServer()`. Invoked by `bin/termbeam.js` when `--interactive` is passed. Uses prompt primitives from `prompts.js`.
109+
110+
### `prompts.js` — Terminal Prompts
111+
112+
Provides ANSI color helpers (`green`, `yellow`, `red`, `cyan`, `bold`, `dim`) and interactive prompt functions (`ask`, `choose`, `confirm`, `createRL`). Extracted from `service.js` so both the service install wizard and the interactive setup wizard can share the same prompt primitives.
113+
102114
### `version.js` — Version Detection
103115

104116
Smart version that shows `1.0.0` for npm installs and `1.0.0-dev (git-hash)` for local development.

docs/configuration.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ description: All TermBeam CLI flags and options — ports, passwords, tunnels, s
77

88
## CLI Flags
99

10-
| Flag | Description | Default |
11-
| --------------------- | ---------------------------------------------------------------- | -------------- |
12-
| `--password <pw>` | Set access password (also accepts `--password=<pw>`) | Auto-generated |
13-
| `--generate-password` | Auto-generate a secure password (default behavior) | On |
14-
| `--no-password` | Disable password authentication (cannot combine with `--public`) ||
15-
| `--tunnel` | Create an ephemeral devtunnel URL (private access) | On |
16-
| `--no-tunnel` | Disable tunnel ||
17-
| `--persisted-tunnel` | Create a reusable devtunnel URL (stable across restarts) | Off |
18-
| `--public` | Allow public tunnel access (no Microsoft login required) | Off |
19-
| `--port <port>` | Server port | `3456` |
20-
| `--host <addr>` | Bind address | `127.0.0.1` |
21-
| `--lan` | Bind to all interfaces (LAN access) | Off |
22-
| `-h, --help` | Show help ||
23-
| `-v, --version` | Show version ||
24-
| `--log-level <level>` | Set log verbosity: `error`, `warn`, `info`, `debug` | `info` |
10+
| Flag | Description | Default |
11+
| --------------------- | ------------------------------------------------------------------------------------------------------------- | -------------- |
12+
| `--password <pw>` | Set access password (also accepts `--password=<pw>`) | Auto-generated |
13+
| `--generate-password` | Auto-generate a secure password (default behavior) | On |
14+
| `--no-password` | Disable password authentication (cannot combine with `--public`) ||
15+
| `--tunnel` | Create an ephemeral devtunnel URL (private access) | On |
16+
| `--no-tunnel` | Disable tunnel ||
17+
| `--persisted-tunnel` | Create a reusable devtunnel URL (stable across restarts) | Off |
18+
| `--public` | Allow public tunnel access (no Microsoft login required) | Off |
19+
| `--port <port>` | Server port | `3456` |
20+
| `--host <addr>` | Bind address | `127.0.0.1` |
21+
| `--lan` | Bind to all interfaces (LAN access) | Off |
22+
| `-i, --interactive` | Interactive setup wizard — walks through password, port, access mode (tunnel type, visibility), and log level | Off |
23+
| `-h, --help` | Show help ||
24+
| `-v, --version` | Show version ||
25+
| `--log-level <level>` | Set log verbosity: `error`, `warn`, `info`, `debug` | `info` |
2526

2627
## Environment Variables
2728

@@ -99,6 +100,15 @@ termbeam /bin/bash
99100
termbeam --port 8080 /usr/bin/fish
100101
```
101102

103+
### Interactive Setup
104+
105+
```bash
106+
# Launch the guided setup wizard
107+
termbeam -i
108+
```
109+
110+
The wizard walks through password, port, access mode, and log level with an interactive TUI.
111+
102112
### With Authentication
103113

104114
```bash

docs/getting-started.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ termbeam
2727

2828
## First Run
2929

30+
For a guided setup that walks you through password, port, access mode, and log level:
31+
32+
```bash
33+
termbeam -i
34+
```
35+
36+
Or start directly with defaults:
37+
3038
1. Start TermBeam:
3139

3240
```bash
@@ -43,7 +51,7 @@ termbeam
4351
██║ ███████╗██║ ██║██║ ╚═╝ ██║██████╔╝███████╗██║ ██║██║ ╚═╝ ██║
4452
╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
4553
46-
Beam your terminal to any device 📡 v1.5.0
54+
Beam your terminal to any device 📡 v1.7.0
4755
4856
Shell: /bin/zsh
4957
Session: a1b2c3d4

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Built for developers who need quick remote terminal access without the hassle of
4747
- **Password auth** with auto-generation, rate limiting, and httpOnly cookies
4848
- **QR code auto-login** with single-use share tokens (5-min expiry)
4949
- **Shell validation** — only detected shells are allowed
50+
- **Interactive setup wizard** — run `termbeam -i` for guided configuration
5051

5152
## Quick Start
5253

landing/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ <h3>Instant remote access</h3>
249249
<h3>Zero config</h3>
250250
<p>
251251
No SSH keys, no port forwarding, no config files. Auto-detects your shell on every
252-
platform.
252+
platform. Run <code>termbeam -i</code> for a guided setup wizard.
253253
</p>
254254
</div>
255255

@@ -307,7 +307,8 @@ <h2>Three steps. That's it.</h2>
307307
<h3>Run one command</h3>
308308
<p>
309309
Run <code>npx termbeam</code> in your terminal. TermBeam starts a server, generates
310-
a password, and opens a tunnel.
310+
a password, and opens a tunnel. First time? Try <code>termbeam -i</code> for a
311+
guided setup.
311312
</p>
312313
</div>
313314
</div>

src/cli.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Options:
3131
--host <addr> Bind address (default: 127.0.0.1)
3232
--lan Bind to 0.0.0.0 (allow LAN access, default: localhost only)
3333
--log-level <level> Set log verbosity: error, warn, info, debug (default: info)
34+
-i, --interactive Interactive setup wizard (guided configuration)
3435
-h, --help Show this help
3536
-v, --version Show version
3637
@@ -47,6 +48,7 @@ Examples:
4748
termbeam --password secret Start with specific password
4849
termbeam --persisted-tunnel Stable tunnel URL across restarts
4950
termbeam /bin/bash Use bash instead of default shell
51+
termbeam --interactive Guided setup wizard
5052
termbeam service install Set up as background service (PM2)
5153
5254
Environment:
@@ -241,6 +243,7 @@ function parseArgs() {
241243
let noTunnel = false;
242244
let persistedTunnel = false;
243245
let publicTunnel = false;
246+
let interactive = false;
244247
let explicitPassword = !!password;
245248

246249
const args = process.argv.slice(2);
@@ -281,6 +284,8 @@ function parseArgs() {
281284
host = '0.0.0.0';
282285
} else if (args[i] === '--host' && args[i + 1]) {
283286
host = args[++i];
287+
} else if (args[i] === '--interactive' || (args[i] === '-i' && filteredArgs.length === 0)) {
288+
interactive = true;
284289
} else if (args[i] === '--log-level' && args[i + 1]) {
285290
logLevel = args[++i];
286291
} else {
@@ -335,6 +340,7 @@ function parseArgs() {
335340
defaultShell,
336341
version,
337342
logLevel,
343+
interactive,
338344
};
339345
}
340346

0 commit comments

Comments
 (0)