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