jsgotty 1.0.0 → 1.1.3
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.en.md +116 -39
- package/README.md +130 -52
- package/client.mjs +11 -7
- package/gotty.js +372 -20
- package/package.json +1 -1
- package/rz.js +24 -6
- package/single-exe/README.md +80 -0
- package/single-exe/assetsHelper.js +90 -0
- package/single-exe/assetsLoader.mjs +85 -0
- package/single-exe/compiled.js +138 -0
- package/single-exe/entry.mjs +9 -0
- package/single-exe/packAssets.sh +7 -0
- package/static/css/kitty.css +1 -1
- package/static/help.md +125 -0
- package/static/index.html +8 -1
- package/static/js/gotty.js +633 -93
- package/static/js/gotty.licenses.txt +23 -0
- package/static/js/kitty.js +83 -16
- package/static/js/xterm-addon-unicode11.js +2 -0
- package/static/js/zmodem.js +1 -1
- package/sz.js +77 -10
- package/viu.mjs +6 -8
- package/zmodem-node.js +157 -8
package/README.en.md
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jsgotty / gotty.js
|
|
2
2
|
|
|
3
3
|
[中文 README](README.md)
|
|
4
4
|
|
|
5
5
|
## News
|
|
6
|
+
### 2026/07/03 - [1.1.0]
|
|
7
|
+
- Unicode 11 from upstream
|
|
8
|
+
- WebGL support by `--webgl` and query args
|
|
9
|
+
- Frontend help by `--help-web`
|
|
10
|
+
- Added `font-size` and `font-family`
|
|
11
|
+
- Added `touch-scroll-threshold` for fast scrolling
|
|
12
|
+
- Added experimental single-exe build commands: `--build-exe` and `--build-for <target>`
|
|
13
|
+
- Improved ZMODEM / `rz/sz` reliability for large transfers
|
|
14
|
+
* terminal mode is switched for binary transfer and restored after transfer / cancel
|
|
15
|
+
* server-side output parsers are bypassed during ZMODEM sessions
|
|
16
|
+
* ZMODEM data uses ordered WebSocket chunks with acknowledgement / retransmit handling
|
|
17
|
+
- Improved `sz` download UI
|
|
18
|
+
* streams downloads to browser file writer
|
|
19
|
+
* shows current file, transferred bytes / total bytes, progress, and verbose transfer logs
|
|
20
|
+
- Improved `rz` upload UI
|
|
21
|
+
* shows current file, transferred bytes / total bytes, progress, and verbose transfer logs
|
|
22
|
+
* supports back-to-back `sz` then `rz` sessions more reliably
|
|
23
|
+
- `rz` / `sz` terminal commands now print completion summaries with file path and byte size
|
|
24
|
+
- ZMODEM debug logs are opt-in with `JSGOTTY_ZMODEM_LOG`
|
|
25
|
+
|
|
6
26
|
### 2026/06/22 - [1.0.0]
|
|
7
27
|
- Added gotty cli client
|
|
8
28
|
* compatible with golang gotty
|
|
@@ -22,23 +42,22 @@
|
|
|
22
42
|
## Intro
|
|
23
43
|
- This is a GoTTY-compatible server rewritten in JavaScript / Bun.
|
|
24
44
|
- It is based on the original GoTTY code, with most of the new code generated by Codex.
|
|
25
|
-
- It includes a frontend and WebTTY protocol implementation adjusted for `
|
|
45
|
+
- It includes a frontend and WebTTY protocol implementation adjusted for `jsgotty`.
|
|
26
46
|
- Original repository:
|
|
27
47
|
- https://github.com/sorenisanerd/gotty
|
|
28
48
|
|
|
29
49
|
### Features
|
|
30
50
|
- Resumable reconnect: after the browser disconnects, you can reconnect to the original shell / PTY with a reconnect token instead of spawning a new shell.
|
|
51
|
+
* jsgotty supports two connection modes: normal mode and session mode.
|
|
52
|
+
* Use `--reconnect` or `--session` to enable session mode.
|
|
53
|
+
* See the detailed mode explanation below.
|
|
31
54
|
- Kitty Graphics Protocol: displays inline terminal images.
|
|
32
55
|
* For example, `bun viu.mjs 1.png` shows an image directly in the terminal.
|
|
33
56
|
* Windows does not use Kitty protocol; it uses a custom protocol.
|
|
34
57
|
- ZMODEM / `rz/sz`: select files in the browser and upload them to the remote shell.
|
|
35
58
|
* You can also download files from the remote shell.
|
|
36
59
|
* Windows does not use ZMODEM; it uses a custom protocol.
|
|
37
|
-
|
|
38
|
-
### PTY backends
|
|
39
|
-
- Linux / macOS: use Bun's built-in PTY via `Bun.spawn(..., { terminal: ... })`
|
|
40
|
-
- Windows: use patched `node-pty`, while still launching `gotty.js` through `bun`
|
|
41
|
-
* The goal is to move fully to Bun in the future
|
|
60
|
+
* Linux has been tested with uploads/downloads around an 80MB Bun binary.
|
|
42
61
|
|
|
43
62
|
## Usage
|
|
44
63
|
|
|
@@ -54,15 +73,20 @@
|
|
|
54
73
|
```sh
|
|
55
74
|
bun gotty.js -w bash
|
|
56
75
|
bun gotty.js -w --credential user:pass bash
|
|
76
|
+
bun gotty.js -w -p 8000 fish
|
|
77
|
+
|
|
78
|
+
# ↓ enables session mode
|
|
57
79
|
bun gotty.js -w --reconnect fish
|
|
58
80
|
bun gotty.js -w --reconnect --reconnect-time 30 fish
|
|
59
81
|
bun gotty.js -w --reconnect --reconnect-time -1 fish
|
|
60
|
-
bun gotty.js -w -p 8000 fish
|
|
61
82
|
|
|
62
83
|
# or npx jsgotty@latest
|
|
63
84
|
|
|
64
|
-
# show help
|
|
85
|
+
# show server / browser help
|
|
65
86
|
bun gotty.js
|
|
87
|
+
bun gotty.js --help
|
|
88
|
+
bun gotty.js --help-web
|
|
89
|
+
# ↑ browser help is also available at /help
|
|
66
90
|
```
|
|
67
91
|
|
|
68
92
|
### Windows
|
|
@@ -71,11 +95,16 @@ bun gotty.js
|
|
|
71
95
|
bun gotty.js -w cmd.exe
|
|
72
96
|
bun gotty.js -w powershell
|
|
73
97
|
|
|
98
|
+
# ↓ enables session mode
|
|
99
|
+
bun gotty.js --reconnect powershell
|
|
100
|
+
|
|
74
101
|
# or npx jsgotty@latest
|
|
75
102
|
|
|
76
|
-
# show help
|
|
103
|
+
# show server / browser help
|
|
77
104
|
bun gotty.js
|
|
78
|
-
bun gotty.js
|
|
105
|
+
bun gotty.js --help
|
|
106
|
+
bun gotty.js --help-web
|
|
107
|
+
# ↑ browser help is also available at /help
|
|
79
108
|
```
|
|
80
109
|
|
|
81
110
|
### Built-in tools
|
|
@@ -87,14 +116,19 @@ bun gotty.js --viu
|
|
|
87
116
|
bun gotty.js --client
|
|
88
117
|
```
|
|
89
118
|
|
|
90
|
-
- `--rz` starts `rz.js
|
|
91
|
-
- `--sz` starts `sz.js
|
|
92
|
-
- `--viu` starts `viu.mjs
|
|
93
|
-
- `--client` starts `client.mjs
|
|
119
|
+
- `--rz` starts `rz.js`: upload files
|
|
120
|
+
- `--sz` starts `sz.js`: download files
|
|
121
|
+
- `--viu` starts `viu.mjs`: display images
|
|
122
|
+
- `--client` starts `client.mjs`: command-line client
|
|
94
123
|
|
|
95
124
|
### CLI Client
|
|
96
125
|
|
|
97
|
-
`client.mjs` is an interactive terminal client that connects directly to GoTTY.
|
|
126
|
+
- `client.mjs` is an interactive terminal client that connects directly to GoTTY.
|
|
127
|
+
- Basic connections are compatible with Golang GoTTY.
|
|
128
|
+
- Session listing, writer management, and remote PTY termination require this project's jsgotty server.
|
|
129
|
+
- See the detailed mode explanation below for the difference between normal mode and session mode.
|
|
130
|
+
|
|
131
|
+
#### Basic connection
|
|
98
132
|
|
|
99
133
|
```sh
|
|
100
134
|
# Connect to the default ws://127.0.0.1:8080/ws
|
|
@@ -110,32 +144,42 @@ bun gotty.js --client https://example.com/terminal/
|
|
|
110
144
|
bun gotty.js --client -c user:pass 8081
|
|
111
145
|
```
|
|
112
146
|
|
|
113
|
-
|
|
147
|
+
#### Session management
|
|
114
148
|
|
|
115
149
|
```sh
|
|
116
|
-
# Resume an existing session by reconnect token or PID
|
|
117
|
-
bun gotty.js --client -r <token|pid> [target]
|
|
118
|
-
|
|
119
150
|
# List current sessions
|
|
120
151
|
bun gotty.js --client -ls [target]
|
|
121
152
|
|
|
153
|
+
# Resume an existing session by reconnect token or PID
|
|
154
|
+
# Requires session mode
|
|
155
|
+
bun gotty.js --client -r <token|pid> [target]
|
|
156
|
+
|
|
122
157
|
# Disconnect the current writer while keeping the PTY session alive
|
|
158
|
+
# Requires session mode
|
|
123
159
|
bun gotty.js --client -d <token|pid> [target]
|
|
124
160
|
|
|
125
161
|
# Terminate the matching PTY session
|
|
126
162
|
bun gotty.js --client -k <token|pid> [target]
|
|
127
163
|
```
|
|
128
164
|
|
|
129
|
-
|
|
165
|
+
The first argument can also use subcommand aliases:
|
|
166
|
+
|
|
167
|
+
- `ls`, `list`, `list-sessions` => `-ls`
|
|
168
|
+
- `attach`, `a <token|pid>` => `-r <token|pid>`
|
|
169
|
+
- `detach <token|pid>` => `-d <token|pid>`
|
|
170
|
+
- `kill-session`, `stop <token|pid>` => `-k <token|pid>`
|
|
171
|
+
|
|
130
172
|
- `-ls` reads the server's `/css.md` session list.
|
|
131
173
|
- Open `/css` to view the session list in a browser.
|
|
132
|
-
- If `/css` shows a static file list instead of sessions, the server is Golang GoTTY, not
|
|
133
|
-
- `-
|
|
174
|
+
- If `/css` shows a static file list instead of sessions, the server is Golang GoTTY, not jsgotty.
|
|
175
|
+
- `-r` requires session mode; it resumes the matching PTY session.
|
|
176
|
+
- `-d` requires session mode; after disconnecting the session writer, the session remains alive and the next writable client can take over.
|
|
134
177
|
- `-k` terminates the matching PTY/session.
|
|
135
178
|
- `--arg <value>` may be repeated to pass command arguments; `--arguments <query>` passes a raw query string.
|
|
136
179
|
- `--cols` and `--rows` set the initial terminal size.
|
|
137
180
|
- `GOTTY_CREDENTIAL` and `GOTTY_RECONNECT_TOKEN` may be used to configure credentials and the reconnect token.
|
|
138
|
-
-
|
|
181
|
+
- See "Normal Mode / Session Mode" below for PTY creation, writer/viewer roles, and reconnect retention behavior.
|
|
182
|
+
- Golang GoTTY does not support the jsgotty control protocols used by `-ls`, `-r`, `-d`, and `-k`.
|
|
139
183
|
|
|
140
184
|
### Wrapper
|
|
141
185
|
- `wgotty` is a wrapper for Linux
|
|
@@ -145,6 +189,47 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
145
189
|
- it will detect whether Bun is installed
|
|
146
190
|
- and show the installation script if needed
|
|
147
191
|
|
|
192
|
+
## Normal Mode / Session Mode
|
|
193
|
+
|
|
194
|
+
The `jsgotty` server has two connection modes:
|
|
195
|
+
|
|
196
|
+
- Normal mode: no `--reconnect` or `--session`
|
|
197
|
+
- Session mode: `--reconnect` or `--session`
|
|
198
|
+
|
|
199
|
+
### Normal Mode
|
|
200
|
+
|
|
201
|
+
- Each new browser or `client.mjs` connection creates a new `PtySession` and a new PTY.
|
|
202
|
+
- Two clients connected at the same time are usually two different shells / PTYs. They do not share screen output, input, or process state.
|
|
203
|
+
- When a client disconnects, its corresponding PTY session is closed.
|
|
204
|
+
- If the browser window, tab, or websocket closes normally, the server cleans up the PTY for that connection.
|
|
205
|
+
- Normal mode cannot resume an existing PTY. If the browser or CLI sends a reconnect token / PID, it will not resume the old session and will create a new PTY instead.
|
|
206
|
+
- `/css` and `/css.md` still list active session PIDs and command names, but they do not provide reconnect tokens or reconnect links.
|
|
207
|
+
- `client.mjs -ls` can list sessions; `-k <pid>` can terminate a session by PID; `-r` and `-d` require session mode.
|
|
208
|
+
|
|
209
|
+
### Session Mode
|
|
210
|
+
|
|
211
|
+
- Enable it with `--reconnect` or `--session`.
|
|
212
|
+
- The first connection creates a new `PtySession` and PTY unless it provides a resumable token / PID.
|
|
213
|
+
- The server generates a reconnect token for each session and sends the session PID and token to the frontend.
|
|
214
|
+
- Later, a browser or CLI can use the reconnect token or PID to resume the same PTY instead of spawning a new shell.
|
|
215
|
+
- Multiple clients can connect to the same PTY session.
|
|
216
|
+
- The first writable client becomes the writer and can send keyboard input, resize events, ZMODEM controls, and other data to the PTY.
|
|
217
|
+
- Other clients are viewers. They receive terminal output but do not write to the PTY.
|
|
218
|
+
- A client can also use `--readonly` to connect explicitly as a viewer.
|
|
219
|
+
- If the writer disconnects while the session still has viewers, existing viewers are not automatically promoted to writer. The next writable client that resumes the same session can become the new writer.
|
|
220
|
+
- After the last client disconnects, `--reconnect-time` decides whether the PTY is kept.
|
|
221
|
+
|
|
222
|
+
#### `--reconnect-time` Behavior
|
|
223
|
+
- `> 0`: keep the PTY for the specified number of seconds after the last client disconnects. It can be resumed during that window; after timeout, the PTY is closed.
|
|
224
|
+
- `= 0`: close the PTY immediately after the last client disconnects.
|
|
225
|
+
- `< 0`: keep the PTY indefinitely until the shell exits, `-k` terminates it, or the server stops.
|
|
226
|
+
|
|
227
|
+
#### Frontend Reconnect Behavior
|
|
228
|
+
- When `reconnect-time > 0`, the frontend retries automatically several times within the timeout.
|
|
229
|
+
- When `reconnect-time < 0`, the frontend retries once per minute.
|
|
230
|
+
- On disconnect, the overlay provides a `Reconnect` button for immediate manual retry.
|
|
231
|
+
- Right-click / long-press on that button lets you enter a custom reconnect token or PID.
|
|
232
|
+
|
|
148
233
|
## Tested platforms
|
|
149
234
|
- Windows x64: Windows 11
|
|
150
235
|
- Linux x64: CachyOS
|
|
@@ -156,24 +241,13 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
156
241
|
- Uses Node's built-in `http` / `https`
|
|
157
242
|
- Uses `ws` for WebSocket upgrade handling
|
|
158
243
|
- Uses bundled frontend assets in `./static`, including kitty overlay and WebTTY / ZMODEM frontend logic
|
|
159
|
-
- Supports reconnect tokens and session resume
|
|
160
244
|
- Supports inline terminal images
|
|
161
245
|
- Supports file upload / download
|
|
162
246
|
|
|
163
|
-
###
|
|
164
|
-
-
|
|
165
|
-
-
|
|
166
|
-
|
|
167
|
-
* `> 0`: keep the session alive for the specified number of seconds after disconnect
|
|
168
|
-
* `= 0`: do not keep the session alive
|
|
169
|
-
* `< 0`: keep the session alive indefinitely until the shell exits or the server stops
|
|
170
|
-
- Frontend reconnect behavior:
|
|
171
|
-
* when `reconnect-time > 0`, it retries automatically several times within the timeout
|
|
172
|
-
* when `reconnect-time < 0`, it retries once per minute
|
|
173
|
-
* the overlay provides a `Reconnect` button for immediate manual retry
|
|
174
|
-
* right-click / long-press on that button lets you enter a custom reconnect token
|
|
175
|
-
- Reconnect is "reconnect to the existing shell", not "replay all output during the disconnect window". Output produced while disconnected is not replayed.
|
|
176
|
-
- When `--reconnect` is disabled, `/css` and `/css.md` still show PID / command name, but they do not provide reconnect tokens or links.
|
|
247
|
+
### PTY backends
|
|
248
|
+
- Linux / macOS: use Bun's built-in PTY via `Bun.spawn(..., { terminal: ... })`
|
|
249
|
+
- Windows: use patched `node-pty`, while still launching `gotty.js` through `bun`
|
|
250
|
+
* Bun versions >= 1.3.14 use Bun's built-in PTY
|
|
177
251
|
|
|
178
252
|
### Kitty intro
|
|
179
253
|
- If the terminal program outputs images using Kitty Graphics Protocol on Linux, the frontend displays those images at the corresponding terminal position.
|
|
@@ -182,6 +256,7 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
182
256
|
|
|
183
257
|
```sh
|
|
184
258
|
bun viu.mjs 1.png
|
|
259
|
+
# or bun gotty.js --viu 1.png
|
|
185
260
|
```
|
|
186
261
|
|
|
187
262
|
### rz upload intro
|
|
@@ -189,6 +264,7 @@ bun viu.mjs 1.png
|
|
|
189
264
|
|
|
190
265
|
```sh
|
|
191
266
|
bun rz.js
|
|
267
|
+
# or bun gotty.js --rz
|
|
192
268
|
```
|
|
193
269
|
|
|
194
270
|
- The frontend opens a file picker. After selecting files, they are uploaded to the current shell directory using ZMODEM.
|
|
@@ -198,6 +274,7 @@ bun rz.js
|
|
|
198
274
|
|
|
199
275
|
```sh
|
|
200
276
|
bun sz.js file.txt
|
|
277
|
+
# or bun gotty.js --sz file.txt
|
|
201
278
|
```
|
|
202
279
|
|
|
203
280
|
- The frontend receives the ZMODEM download data and lets the browser download the file.
|
package/README.md
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jsgotty / gotty.js
|
|
2
2
|
|
|
3
3
|
[English README](README.en.md)
|
|
4
4
|
|
|
5
5
|
## News
|
|
6
|
+
### 2026/07/03 - [1.1.0]
|
|
7
|
+
- Unicode 11 from upstream
|
|
8
|
+
- WebGL support by `--webgl` & query args
|
|
9
|
+
- Frontend help by `--help-web`
|
|
10
|
+
- Added `font-size` and `font-family`
|
|
11
|
+
- Added `touch-scroll-threshold` for fast scrolling
|
|
12
|
+
- Added experimental single-exe build commands: `--build-exe` and `--build-for <target>`
|
|
13
|
+
- 改善 ZMODEM / `rz/sz` 大檔案傳輸可靠度
|
|
14
|
+
* 傳輸時切換終端機模式,結束或取消後恢復
|
|
15
|
+
* ZMODEM 期間繞過 server-side output parsers
|
|
16
|
+
* ZMODEM 資料改用有順序、ACK、重送處理的 WebSocket chunks
|
|
17
|
+
- 改善 `sz` 下載 UI
|
|
18
|
+
* 下載直接串流寫入瀏覽器檔案 writer
|
|
19
|
+
* 顯示目前檔案、已傳輸 bytes / 總 bytes、進度與 verbose transfer logs
|
|
20
|
+
- 改善 `rz` 上傳 UI
|
|
21
|
+
* 顯示目前檔案、已傳輸 bytes / 總 bytes、進度與 verbose transfer logs
|
|
22
|
+
* 改善連續執行 `sz` 後馬上 `rz` 的穩定性
|
|
23
|
+
- `rz` / `sz` 終端機指令完成時會顯示檔案路徑與 byte size
|
|
24
|
+
- ZMODEM debug log 改成透過 `JSGOTTY_ZMODEM_LOG` 才啟用
|
|
6
25
|
### 2026/06/22 - [1.0.0]
|
|
7
26
|
- Added gotty cli client
|
|
8
27
|
* compatible with golang gotty
|
|
@@ -19,26 +38,25 @@
|
|
|
19
38
|
|
|
20
39
|
## Intro 介紹
|
|
21
40
|
- 這是用 JavaScript / Bun 重新實作的 GoTTY 相容伺服器
|
|
22
|
-
-
|
|
23
|
-
- 包含已針對 `
|
|
24
|
-
-
|
|
25
|
-
- 原版repo:
|
|
41
|
+
- 參考原本 GoTTY 的程式碼,大部分以 Codex 生成
|
|
42
|
+
- 包含已針對 `jsgotty` 調整過的前端與 WebTTY 協定實作
|
|
43
|
+
- 原版 repo:
|
|
26
44
|
- https://github.com/sorenisanerd/gotty
|
|
27
45
|
|
|
28
46
|
### Features 特色功能
|
|
29
47
|
- Resumable reconnect: 瀏覽器斷線後可以用 reconnect token 接回原本的 shell / PTY,而不是重開一個新的 shell。
|
|
48
|
+
* jsgotty 伺服器端支援兩種連線模式
|
|
49
|
+
* 正常模式、工作階段(session)模式
|
|
50
|
+
* 當命令列參數包含 `--reconnect` 或 `--session` 時會啟用工作階段模式
|
|
51
|
+
* 見下方詳細說明兩種模式
|
|
30
52
|
- Kitty Graphics Protocol: 可以顯示終端內嵌圖片
|
|
31
53
|
* 像是用 `bun viu.mjs 1.png` 直接在終端中顯示圖片。
|
|
32
|
-
* Windows不是使用Kitty協定,而是自訂協議
|
|
33
|
-
- ZMODEM / `rz/sz
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- Linux / macOS: 使用 Bun 內建 PTY `Bun.spawn(..., { terminal: ... })`
|
|
39
|
-
- Windows: 使用patched `node-pty`,但整體以 `bun` 啟動 `gotty.js`
|
|
40
|
-
* 將來會全面使用 Bun
|
|
41
|
-
|
|
54
|
+
* Windows 不是使用 Kitty 協定,而是自訂協議
|
|
55
|
+
- ZMODEM / `rz/sz` 上傳/下載功能
|
|
56
|
+
* 可以從瀏覽器端選檔並上傳到遠端 shell
|
|
57
|
+
* 也可以從遠端 shell 下載檔案
|
|
58
|
+
* Windows 不是使用 ZMODEM,而是自訂協議
|
|
59
|
+
* 目前 Linux 系統實測能上傳/下載約 80MB 的 bun binary
|
|
42
60
|
|
|
43
61
|
## Usage 用法
|
|
44
62
|
|
|
@@ -54,15 +72,20 @@
|
|
|
54
72
|
```sh
|
|
55
73
|
bun gotty.js -w bash
|
|
56
74
|
bun gotty.js -w --credential user:pass bash
|
|
75
|
+
bun gotty.js -w -p 8000 fish
|
|
76
|
+
|
|
77
|
+
# ↓將會開啟工作階段(session)模式
|
|
57
78
|
bun gotty.js -w --reconnect fish
|
|
58
79
|
bun gotty.js -w --reconnect --reconnect-time 30 fish
|
|
59
80
|
bun gotty.js -w --reconnect --reconnect-time -1 fish
|
|
60
|
-
bun gotty.js -w -p 8000 fish
|
|
61
81
|
|
|
62
|
-
#
|
|
82
|
+
# 或 npx jsgotty@latest
|
|
63
83
|
|
|
64
|
-
#
|
|
84
|
+
# 顯示伺服器/瀏覽器端的幫助
|
|
65
85
|
bun gotty.js
|
|
86
|
+
bun gotty.js --help
|
|
87
|
+
bun gotty.js --help-web
|
|
88
|
+
# ↑瀏覽器端可導覽到/help查看
|
|
66
89
|
```
|
|
67
90
|
|
|
68
91
|
### Windows
|
|
@@ -71,14 +94,19 @@ bun gotty.js
|
|
|
71
94
|
bun gotty.js -w cmd.exe
|
|
72
95
|
bun gotty.js -w powershell
|
|
73
96
|
|
|
74
|
-
#
|
|
97
|
+
# ↓將會開啟工作階段(session)模式
|
|
98
|
+
bun gotty.js --reconnect powershell
|
|
75
99
|
|
|
76
|
-
#
|
|
100
|
+
# 或 npx jsgotty@latest
|
|
101
|
+
|
|
102
|
+
# 顯示伺服器/瀏覽器端的幫助
|
|
77
103
|
bun gotty.js
|
|
78
|
-
bun gotty.js
|
|
104
|
+
bun gotty.js --help
|
|
105
|
+
bun gotty.js --help-web
|
|
106
|
+
# ↑瀏覽器端可導覽到/help查看
|
|
79
107
|
```
|
|
80
108
|
|
|
81
|
-
###
|
|
109
|
+
### 內建工具
|
|
82
110
|
|
|
83
111
|
```sh
|
|
84
112
|
bun gotty.js --rz
|
|
@@ -87,14 +115,19 @@ bun gotty.js --viu
|
|
|
87
115
|
bun gotty.js --client
|
|
88
116
|
```
|
|
89
117
|
|
|
90
|
-
- `--rz` starts `rz.js
|
|
91
|
-
- `--sz` starts `sz.js
|
|
92
|
-
- `--viu` starts `viu.mjs
|
|
93
|
-
- `--client` starts `client.mjs
|
|
118
|
+
- `--rz` starts `rz.js`: 上傳檔案
|
|
119
|
+
- `--sz` starts `sz.js`: 下載指定檔案
|
|
120
|
+
- `--viu` starts `viu.mjs`: 顯示圖片
|
|
121
|
+
- `--client` starts `client.mjs`: 命令列客戶端
|
|
122
|
+
|
|
123
|
+
### 命令列客戶端 CLI Client
|
|
94
124
|
|
|
95
|
-
|
|
125
|
+
- `client.mjs` 是可直接連接 GoTTY 的互動式終端 client
|
|
126
|
+
- 基本連線相容 Golang GoTTY
|
|
127
|
+
- session 列表、writer 管理與遠端終止 PTY 則需要本專案的 jsgotty server
|
|
128
|
+
- 正常模式與工作階段(session)模式的差異,請見下方詳細說明兩種模式。
|
|
96
129
|
|
|
97
|
-
|
|
130
|
+
#### 基本操作:連接伺服器
|
|
98
131
|
|
|
99
132
|
```sh
|
|
100
133
|
# 連接預設 ws://127.0.0.1:8080/ws
|
|
@@ -110,32 +143,43 @@ bun gotty.js --client https://example.com/terminal/
|
|
|
110
143
|
bun gotty.js --client -c user:pass 8081
|
|
111
144
|
```
|
|
112
145
|
|
|
113
|
-
|
|
146
|
+
#### 進階操作:工作階段管理
|
|
114
147
|
|
|
115
148
|
```sh
|
|
116
|
-
# 使用 reconnect token 或 PID 接回既有 session
|
|
117
|
-
bun gotty.js --client -r <token|pid> [target]
|
|
118
|
-
|
|
119
149
|
# 列出目前 sessions
|
|
120
150
|
bun gotty.js --client -ls [target]
|
|
121
151
|
|
|
152
|
+
# 使用 reconnect token 或 PID 接回既有 session
|
|
153
|
+
# 需開啟 session 模式
|
|
154
|
+
bun gotty.js --client -r <token|pid> [target]
|
|
155
|
+
|
|
122
156
|
# 中斷目前 writer,但保留 PTY session
|
|
157
|
+
# 需開啟 session 模式
|
|
123
158
|
bun gotty.js --client -d <token|pid> [target]
|
|
124
159
|
|
|
125
160
|
# 終止對應的 PTY session
|
|
126
161
|
bun gotty.js --client -k <token|pid> [target]
|
|
127
162
|
```
|
|
128
163
|
|
|
129
|
-
|
|
164
|
+
第一個參數也可使用 subcommand alias:
|
|
165
|
+
|
|
166
|
+
- `ls`、`list`、`list-sessions` => `-ls`
|
|
167
|
+
- `attach`、`a <token|pid>` => `-r <token|pid>`
|
|
168
|
+
- `detach <token|pid>` => `-d <token|pid>`
|
|
169
|
+
- `kill-session`、`stop <token|pid>` => `-k <token|pid>`
|
|
170
|
+
|
|
130
171
|
- `-ls` 讀取 server 的 `/css.md` session 列表。
|
|
131
|
-
- 使用瀏覽器查看 session
|
|
132
|
-
- 如果 `/css` 顯示的是靜態檔案列表而不是 sessions,代表連線的是 Golang GoTTY,不是
|
|
133
|
-
- `-
|
|
172
|
+
- 使用瀏覽器查看 session 列表時請導覽到 `/css`。
|
|
173
|
+
- 如果 `/css` 顯示的是靜態檔案列表而不是 sessions,代表連線的是 Golang GoTTY,不是 jsgotty。
|
|
174
|
+
- `-r` 需開啟 session 模式;可接回指定的 PTY session。
|
|
175
|
+
- `-d` 需開啟 session 模式;中斷指定 session 的 writer 後,session 仍保留,下一個可寫 client 可接手。
|
|
134
176
|
- `-k` 會直接終止對應 PTY/session。
|
|
177
|
+
|
|
135
178
|
- `--arg <value>` 可重複指定 command arguments;`--arguments <query>` 可傳入原始 query string。
|
|
136
179
|
- `--cols`、`--rows` 可指定初始終端大小。
|
|
137
180
|
- 可用 `GOTTY_CREDENTIAL` 與 `GOTTY_RECONNECT_TOKEN` 環境變數設定 credential 和 reconnect token。
|
|
138
|
-
-
|
|
181
|
+
- PTY 建立方式、writer/viewer 權限與 reconnect 保留時間請參考下方「正常模式 / 工作階段(session)模式」。
|
|
182
|
+
- Golang GoTTY 不支援 `-ls`、`-r`、`-d`、`-k` 這些 jsgotty 控制協議。
|
|
139
183
|
|
|
140
184
|
### Wrapper
|
|
141
185
|
- wgotty is a wrapper for Linux
|
|
@@ -145,6 +189,47 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
145
189
|
- detect installation status of Bun
|
|
146
190
|
- and show installation script if needed
|
|
147
191
|
|
|
192
|
+
## 正常模式 / 工作階段(session)模式
|
|
193
|
+
|
|
194
|
+
`jsgotty` 伺服器有兩種連線模式:
|
|
195
|
+
|
|
196
|
+
- 正常模式: 未指定 `--reconnect` 或 `--session`
|
|
197
|
+
- 工作階段(session)模式: 指定 `--reconnect` 或 `--session`
|
|
198
|
+
|
|
199
|
+
### 正常模式
|
|
200
|
+
|
|
201
|
+
- 每一個新的瀏覽器或 `client.mjs` 連線,都會建立一個新的 `PtySession` 與新的 PTY。
|
|
202
|
+
- 兩個 client 同時連線時,通常就是兩個不同的 shell / PTY,彼此不共享畫面、輸入或行程狀態。
|
|
203
|
+
- client 斷線後,對應的 PTY session 會被關閉。
|
|
204
|
+
- 如果瀏覽器被關閉、tab 被關閉、或 websocket 正常斷線,server 會清理該連線對應的 PTY。
|
|
205
|
+
- 正常模式不支援接回既有 PTY;瀏覽器或 CLI 傳入 reconnect token / PID 時,不會 resume 原 session,而是開新的 PTY。
|
|
206
|
+
- `/css` 與 `/css.md` 仍會列出目前 active sessions 的 PID 與 command name,但不提供 reconnect token 或接回連結。
|
|
207
|
+
- `client.mjs -ls` 可列出 sessions;`-k <pid>` 可用 PID 終止 session;`-r` 與 `-d` 需要工作階段模式。
|
|
208
|
+
|
|
209
|
+
### 工作階段(session)模式
|
|
210
|
+
|
|
211
|
+
- 使用 `--reconnect` 或 `--session` 啟用。
|
|
212
|
+
- 第一次連線如果沒有指定可 resume 的 token / PID,server 會建立新的 `PtySession` 與新的 PTY。
|
|
213
|
+
- server 會替每個 session 產生 reconnect token,並把 session PID 與 token 傳給前端。
|
|
214
|
+
- 之後瀏覽器或 CLI 可以用 reconnect token 或 PID 接回同一個 PTY,而不是建立新的 shell。
|
|
215
|
+
- 在同一個 PTY session 裡可以有多個 client 同時連線。
|
|
216
|
+
- 第一個可寫入的 client 會成為 writer,可以送鍵盤輸入、resize、ZMODEM 控制等資料到 PTY。
|
|
217
|
+
- 其他 client 會是 viewer,只接收畫面輸出,不會寫入 PTY。
|
|
218
|
+
- client 也可以用 `--readonly` 主動以 viewer 身分連線。
|
|
219
|
+
- 如果 writer 斷線但 session 還有其他 viewer,既有 viewer 不會自動升級為 writer;下一個可寫入且接回同一 session 的 client 可以成為新的 writer。
|
|
220
|
+
- 最後一個 client 斷線後,PTY 是否保留由 `--reconnect-time` 決定。
|
|
221
|
+
|
|
222
|
+
#### `--reconnect-time` 的行為:
|
|
223
|
+
- `> 0`: 最後一個 client 斷線後保留指定秒數,期間可接回,逾時後關閉 PTY。
|
|
224
|
+
- `= 0`: 最後一個 client 斷線後立刻關閉 PTY。
|
|
225
|
+
- `< 0`: 最後一個 client 斷線後無限期保留 PTY,直到 shell 自己結束、手動 `-k` 終止、或 server 停止。
|
|
226
|
+
|
|
227
|
+
#### 前端的 reconnect 行為:
|
|
228
|
+
- `reconnect-time > 0` 時,會在期限內自動重試多次。
|
|
229
|
+
- `reconnect-time < 0` 時,會每 1 分鐘自動重試一次。
|
|
230
|
+
- 斷線時會提供 `Reconnect` 按鈕,可手動立即重試。
|
|
231
|
+
- 該按鈕右鍵/長按可輸入自訂 reconnect token 或 PID。
|
|
232
|
+
|
|
148
233
|
## Tested platforms 已測試作業系統
|
|
149
234
|
- Windows x64: Windows 11
|
|
150
235
|
- Linux x64: CachyOS
|
|
@@ -152,28 +237,18 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
152
237
|
- Android arm64: My App
|
|
153
238
|
* https://drive.google.com/drive/folders/18iwbKrAZfA-HoTSP9I5MzGz5xVFMZ4bg
|
|
154
239
|
|
|
240
|
+
|
|
155
241
|
## Current implementation 目前實做
|
|
156
242
|
- 使用node原生 `http`/`https`
|
|
157
243
|
- 使用 `ws` 處理 WebSocket upgrade
|
|
158
244
|
- 使用 `./static` 內自帶前端頁面、kitty overlay 與 WebTTY/ZMODEM 前端邏輯
|
|
159
|
-
- 支援 reconnect token 與 session resume,可接回原本 shell
|
|
160
245
|
- 支援輸出圖片到終端
|
|
161
246
|
- 支援檔案上傳/下載
|
|
162
247
|
|
|
163
|
-
###
|
|
164
|
-
-
|
|
165
|
-
-
|
|
166
|
-
|
|
167
|
-
* `> 0`: 斷線後保留 session 指定秒數
|
|
168
|
-
* `= 0`: 不保留 session
|
|
169
|
-
* `< 0`: 無限期保留 session,直到 shell 自己結束或 server 被停止
|
|
170
|
-
- 前端的 reconnect 行為:
|
|
171
|
-
* `reconnect-time > 0` 時,會在期限內自動重試多次
|
|
172
|
-
* `reconnect-time < 0` 時,會每 1 分鐘自動重試一次
|
|
173
|
-
* overlay 會提供 `Reconnect` 按鈕,可手動立即重試
|
|
174
|
-
* 該按鈕右鍵/長按可輸入自訂reconnect token
|
|
175
|
-
- 目前 reconnect 是「接回現有 shell」,不是「回放斷線期間所有輸出」。斷線期間的輸出不會補送。
|
|
176
|
-
- `--reconnect` 關閉時,`/css` 與 `/css.md` 仍會顯示 PID / command name,只是不會提供 reconnect token 與連結。
|
|
248
|
+
### PTY Backends PTY後端策略
|
|
249
|
+
- Linux / macOS: 使用 Bun 內建 PTY `Bun.spawn(..., { terminal: ... })`
|
|
250
|
+
- Windows: 使用patched `node-pty`,但整體以 `bun` 啟動 `gotty.js`
|
|
251
|
+
* Bun版本若>=1.3.14會全面使用 Bun 內建 PTY
|
|
177
252
|
|
|
178
253
|
### Kitty intro
|
|
179
254
|
- 只要終端程式使用 Kitty Graphics Protocol (Linux) 輸出圖片,前端就會把圖片顯示在終端對應位置。
|
|
@@ -182,6 +257,7 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
182
257
|
|
|
183
258
|
```sh
|
|
184
259
|
bun viu.mjs 1.png
|
|
260
|
+
# or bun gotty.js --viu 1.png
|
|
185
261
|
```
|
|
186
262
|
|
|
187
263
|
### rz upload intro
|
|
@@ -189,6 +265,7 @@ bun viu.mjs 1.png
|
|
|
189
265
|
|
|
190
266
|
```sh
|
|
191
267
|
bun rz.js
|
|
268
|
+
# or bun gotty.js --rz
|
|
192
269
|
```
|
|
193
270
|
|
|
194
271
|
- 前端會跳出檔案選擇視窗。選擇檔案後,會以 ZMODEM 上傳到目前 shell 所在目錄。
|
|
@@ -198,6 +275,7 @@ bun rz.js
|
|
|
198
275
|
|
|
199
276
|
```sh
|
|
200
277
|
bun sz.js file.txt
|
|
278
|
+
# or bun gotty.js --sz file.txt
|
|
201
279
|
```
|
|
202
280
|
|
|
203
281
|
- 前端會接收 ZMODEM 下載資料,並讓瀏覽器下載檔案。
|
package/client.mjs
CHANGED
|
@@ -30,14 +30,14 @@ Target:
|
|
|
30
30
|
Accepts http(s) page URLs or ws(s) WebSocket URLs.
|
|
31
31
|
|
|
32
32
|
Options:
|
|
33
|
+
-ls
|
|
34
|
+
List reconnectable sessions and exit
|
|
33
35
|
-r, --reconnect-token <token|pid>
|
|
34
36
|
Resume a session by token or PID
|
|
35
37
|
-d, --detach <token|pid>
|
|
36
38
|
Disconnect the active writer for a session and exit
|
|
37
39
|
-k, --kill <token|pid>
|
|
38
40
|
Terminate the session PTY for a token or PID
|
|
39
|
-
-ls
|
|
40
|
-
List reconnectable sessions and exit
|
|
41
41
|
|
|
42
42
|
-c, --credential <user:pass>
|
|
43
43
|
GoTTY credential/AuthToken
|
|
@@ -54,6 +54,12 @@ Options:
|
|
|
54
54
|
-h, --help
|
|
55
55
|
Show help
|
|
56
56
|
|
|
57
|
+
Subcommand aliases:
|
|
58
|
+
ls, list, list-sessions => -ls
|
|
59
|
+
attach, a <token|pid> => -r <token|pid>
|
|
60
|
+
detach <token|pid> => -d <token|pid>
|
|
61
|
+
kill-session, stop <token|pid> => -k <token|pid>
|
|
62
|
+
|
|
57
63
|
Environment:
|
|
58
64
|
GOTTY_CREDENTIAL
|
|
59
65
|
GOTTY_RECONNECT_TOKEN`);
|
|
@@ -688,9 +694,7 @@ pid:
|
|
|
688
694
|
});
|
|
689
695
|
}
|
|
690
696
|
|
|
691
|
-
|
|
692
|
-
await main();
|
|
693
|
-
} catch (error) {
|
|
697
|
+
main().catch((error) => {
|
|
694
698
|
console.error(`client.mjs: ${error.message}`);
|
|
695
|
-
process.
|
|
696
|
-
}
|
|
699
|
+
process.exitCode = 1;
|
|
700
|
+
});
|