auvezy-terminal-remote 0.6.0 → 0.7.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
@@ -12,8 +12,8 @@
12
12
  **English** · [简体中文](./README.zh-CN.md)
13
13
 
14
14
  Remote-control any terminal program on your PC from a phone or tablet
15
- browser over LAN. One command `atr [program]`and every instance
16
- shows up as a tab in your browser's top bar.
15
+ browser over LAN. Start a broker once at boot open the browser any
16
+ time to log in, create instances, and run Claude / your shell / any TUI.
17
17
 
18
18
  <img src="./frontend/public/screenshots/desktop.png" alt="Webapp running Claude Code in a browser tab" width="720">
19
19
 
@@ -23,15 +23,61 @@ shows up as a tab in your browser's top bar.
23
23
 
24
24
  - **PTY bridge** — node-pty + xterm.js 5, full ANSI, alt-screen TUI safe
25
25
  - **Claude Code / TUI tuned** — Ink/Yoga reflow fix on resize, alt-screen blocklist, "adapt to current device" PTY sizing
26
- - **Multi-instance** — every `atr` grabs the next free port; one tab bar shows them all
26
+ - **Multi-instance** — every instance is its own subprocess; one tab bar shows them all, URL is the instance (`/i/<id>/`)
27
27
  - **Multi-client** — many browsers / `attach` clients on one instance, with master arbitration
28
28
  - **Mobile-first PWA** — IME guard, long-press, swipe scroll, viewport-aware fit, install to home screen
29
29
  - **Custom shortcuts & commands** — define on-screen keys and saved command snippets in the settings panel
30
30
  - **Reconnect with replay** — scrollback rehydrated on every reconnect, alt-screen TUIs protected
31
- - **LAN-only by design** — token + port-bound cookie, `timingSafeEqual`, loopback-only `/api/hook`
32
- - **WSL aware** — mirrored / NAT auto-detected, PowerShell port-forward script generated
31
+ - **LAN-only design** — token + shared sessions, `timingSafeEqual`, `/api/hook` is loopback-only, workers bind to 127.0.0.1
32
+ - **WSL aware** — auto-detects mirrored vs NAT mode; prints a one-liner PowerShell port-forward snippet when needed
33
+ - **Boot autostart** — `atr broker service install` writes the systemd / launchd config in one shot
33
34
 
34
- Full inventory in [`docs/FEATURES.md`](./docs/FEATURES.md).
35
+ Full list: [`docs/FEATURES.md`](./docs/FEATURES.md).
36
+
37
+ ## 🏛️ Architecture
38
+
39
+ `atr` is a two-process model: **broker** is the LAN entry and coordinator,
40
+ **worker** is a single PTY instance.
41
+
42
+ ```
43
+ Browser / phone Your PC
44
+ ┌──────────────┐ ┌──────────────────────────────────┐
45
+ │ │ ws://host │ broker (LAN: 0.0.0.0:3000) │
46
+ │ webapp PWA │ ──────────────►│ ├─ /api/* (auth / instances / │
47
+ │ │ │ │ push / config / …) │
48
+ │ │ │ ├─ /i/<id>/ → SPA + base href │
49
+ │ │ │ ├─ /i/<id>/api/* → proxy worker │
50
+ │ │ │ └─ /i/<id>/ws → proxy worker │
51
+ └──────────────┘ │ │ │
52
+ │ ▼ │
53
+ │ worker A worker B … │
54
+ │ 127.0.0.1: 127.0.0.1: │
55
+ │ 3001 3002 … │
56
+ │ ├─ PTY (claude / shell / TUI) │
57
+ │ ├─ /api/health /api/hook │
58
+ │ └─ /ws (PTY IO) │
59
+ └──────────────────────────────────┘
60
+ ```
61
+
62
+ - **broker** (LAN entry point): the only outward-facing process, listens on
63
+ `0.0.0.0:3000`. Owns all "system-level" APIs: login, user config,
64
+ instance list, push subscriptions, SSE live stream. Serves the static
65
+ frontend and injects `<base href>` for `/i/<id>/`. Long-lived — start
66
+ once at boot.
67
+ - **worker** (PTY instance): one subprocess per instance, listens on a
68
+ high port at `127.0.0.1` only. Exposes only `/api/health` (probe),
69
+ `/api/hook` (loopback only), and `/ws` (PTY IO). Spawned by the broker
70
+ via `POST /api/instances`, detached + unref so it outlives broker
71
+ restarts.
72
+ - **Shared sessions**: broker and workers share a file-locked sessions
73
+ store — one cookie authenticates everywhere.
74
+ - **Entry model**: the browser always talks to the broker; URL `/i/<id>/`
75
+ identifies an instance. F5 doesn't lose context. Single PWA, multiple
76
+ instances.
77
+
78
+ Module diagram and data flow: [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md).
79
+ Design decisions (broker/worker split, lifecycle, API ownership, base
80
+ href injection, …): [`docs/plans/path-routing/adrs/`](./docs/plans/path-routing/adrs/).
35
81
 
36
82
  ## 📦 Install
37
83
 
@@ -39,44 +85,100 @@ Full inventory in [`docs/FEATURES.md`](./docs/FEATURES.md).
39
85
  npm install -g auvezy-terminal-remote # -g is required (it's a CLI)
40
86
  ```
41
87
 
42
- > ⚠️ The default `npm i` command shown on the npm package page is **missing
43
- > `-g`** — without it the `atr` binary won't be on your PATH.
88
+ > ⚠️ The default `npm i` command shown on the npm package page is
89
+ > **missing `-g`** — without it the `atr` binary won't be on your PATH.
44
90
 
45
91
  ## 🚀 Quick start
46
92
 
93
+ ### Run the background service once at boot (recommended)
94
+
47
95
  ```bash
48
- atr # runs your $SHELL (zsh / bash auto-detected)
49
- atr claude # runs claude
50
- atr claude --resume foo # extra args passed through to claude
96
+ atr --install # writes systemd (Linux/WSL2) / launchd (macOS) config
97
+ # Follow the printed steps to enable + start; auto-starts at boot.
51
98
  ```
52
99
 
53
- After it starts, scan the QR code printed in the terminal — the webapp
54
- logs in automatically (token lives in `~/.auvezy/terminal-remote/config.json`).
100
+ Or run it manually (for testing / no autostart):
101
+
102
+ ```bash
103
+ atr --start # foreground, Ctrl+C to quit
104
+ ```
105
+
106
+ ### Open in a browser
107
+
108
+ ```bash
109
+ atr --status # one-shot view: process / token / entry URLs / instances
110
+ ```
111
+
112
+ The "entry URLs" section lists every reachable URL with `?token=<token>`
113
+ appended — paste any of them into a browser to log in. The default entry
114
+ is marked with ★ (Tailscale > LAN > IPv6 > loopback).
115
+
116
+ After the webapp loads, click "+ New instance", pick a cwd, and a PTY
117
+ spawns. Default command is `$SHELL`; run `claude` (or anything else)
118
+ inside it.
119
+
120
+ ### Spawn an instance directly (CLI, classic usage)
121
+
122
+ ```bash
123
+ atr # runs your $SHELL
124
+ atr claude # runs claude
125
+ atr claude --resume foo # extra args pass through
126
+ ```
55
127
 
56
- Run `atr` in different terminals to spawn more instances; the browser tab
57
- bar updates live.
128
+ The CLI auto-ensures the background service is up (forks one if not),
129
+ spawns the instance, and prints the URL.
58
130
 
59
131
  ## 🔧 Usage
60
132
 
61
133
  ```
62
- atr [atr-flags...] [program] [program-args...]
63
- atr <subcommand> [args]
134
+ atr <service-flag> # manage background service (must follow atr)
135
+ atr [run-flags...] [program] [args...] # spawn a PTY instance
136
+ atr <subcommand> [args] # instance-level operations
64
137
  ```
65
138
 
66
- Most-used flags:
139
+ ### Service-level flags (must follow `atr`; mutually exclusive)
67
140
 
68
141
  | Flag | Purpose |
69
142
  |---|---|
70
- | `-p, --port <n>` | Port (default 3000, auto-increments) |
143
+ | `atr --start` | Start the background service (foreground, Ctrl+C to quit) |
144
+ | `atr --stop` | Stop the background service (SIGTERM → 5s grace → SIGKILL) |
145
+ | `atr --status` | One-shot view: process, token, entry URLs, instances |
146
+ | `atr --list` | List all live instances |
147
+ | `atr --logs` | Tail today's service log (`~/.atr/broker-YYYY-MM-DD.log`) |
148
+ | `atr --install` | Register autostart (systemd / launchd) |
149
+ | `atr --uninstall` | Remove autostart |
150
+
151
+ ### Run flags (used with `atr [program]`)
152
+
153
+ | Flag | Purpose |
154
+ |---|---|
155
+ | `-p, --port <n>` | Service port (default 3000); instance ports are auto-assigned |
71
156
  | `--name <s>` | Instance name (shown in webapp) |
72
- | `--no-terminal` | Don't print QR (CI / daemon-friendly) |
157
+ | `--no-terminal` | Don't print the QR / banner (CI / daemon-friendly) |
73
158
  | `--workdir <path>` | Child process cwd |
74
- | `--token <s>` | Use a fixed token instead of auto-generated |
159
+ | `--token <s>` | Use a fixed token instead of reading `~/.atrrc` |
160
+
161
+ ### Instance-level subcommands
75
162
 
76
- Subcommands: `atr list` · `atr stop [pattern]` · `atr attach <url>`.
163
+ | Command | Purpose |
164
+ |---|---|
165
+ | `atr stop [pattern]` | Stop an instance (substring match on name / cwd / host:port; no pattern = stop all) |
166
+ | `atr attach <url>` | CLI client to share a PTY with a running instance |
77
167
 
78
- Full reference (all flags, env vars, config file): [`docs/CLI.md`](./docs/CLI.md).
79
- Run `atr -h` for the inline help.
168
+ Full reference (all flags, env vars, config file):
169
+ [`docs/CLI.md`](./docs/CLI.md). Run `atr -h` for the inline help.
170
+
171
+ ## 📂 File locations
172
+
173
+ | Path | Contents |
174
+ |---|---|
175
+ | `~/.atrrc` | Main config: token, user prefs, shortcuts, command snippets |
176
+ | `~/.atr/instances.json` | Live instance registry (broker / worker share it) |
177
+ | `~/.atr/broker.json` | Broker process state (pid / port / startedAt) |
178
+ | `~/.atr/broker-YYYY-MM-DD.log` | Broker daily log (kept for 7 days) |
179
+ | `~/.atr/sessions/` | Shared session files |
180
+ | `~/.atr/vapid-keys.json` | Web Push VAPID keys |
181
+ | `~/.atr/push-subscriptions.json` | Subscribed push endpoints |
80
182
 
81
183
  ## 📱 Install as a PWA
82
184
 
@@ -88,28 +190,39 @@ app: no browser chrome, status bar tinted to match.
88
190
 
89
191
  ## 🌐 WSL → Windows browser
90
192
 
91
- WSL2 backend works out of the box on **mirrored mode**. On **NAT mode**
92
- the banner prints a one-shot PowerShell snippet to make the port reachable
93
- from Windows. Details: [`docs/WSL.md`](./docs/WSL.md).
193
+ WSL2 works out of the box on **mirrored mode**. On **NAT mode** the banner
194
+ prints a one-shot PowerShell snippet to make the port reachable from
195
+ Windows. Details: [`docs/WSL.md`](./docs/WSL.md).
94
196
 
95
197
  ## 🛣️ Roadmap
96
198
 
97
199
  Planned, evaluating, and explicitly out-of-scope items live in
98
- [`docs/ROADMAP.md`](./docs/ROADMAP.md). The README only lists what already ships.
99
-
100
- ## 🏛️ Architecture
101
-
102
- - Module diagram & data flow: [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)
103
- - Design doc & ADRs: [`docs/plans/open-claude-remote-clone/`](./docs/plans/open-claude-remote-clone/)
200
+ [`docs/ROADMAP.md`](./docs/ROADMAP.md). The README only lists what
201
+ already ships.
104
202
 
105
203
  ## 🛠️ Development
106
204
 
107
205
  ```bash
108
206
  git clone https://github.com/jjj201200/auvezy-terminal-remote.git
109
207
  cd auvezy-terminal-remote
110
- bash install.sh # checks Node 20+ / pnpm 9+ / build deps → installs → builds
111
- pnpm dev # backend (tsx watch) + frontend (vite) in parallel
112
- pnpm test # shared + backend + frontend unit tests
208
+ bash install.sh # checks Node 20+ / pnpm 9+ / build deps → installs → builds
209
+ ```
210
+
211
+ Dev startup order (broker first, then vite):
212
+
213
+ ```bash
214
+ # Terminal 1: start broker in dev mode (tsx running src)
215
+ pnpm --filter auvezy-terminal-remote exec tsx src/cli.ts broker start
216
+
217
+ # Terminal 2: vite dev server; proxies /api and /i/ to the broker (3000)
218
+ pnpm --filter auvezy-terminal-remote-frontend dev
219
+ # Open http://localhost:5173/
220
+ ```
221
+
222
+ Run tests:
223
+
224
+ ```bash
225
+ pnpm test # shared + backend + frontend unit tests
113
226
  ```
114
227
 
115
228
  Gitee mirror (faster from mainland China):