jsgotty 1.1.1 → 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 +96 -39
- package/README.md +111 -52
- package/client.mjs +8 -2
- package/gotty.js +3 -2
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jsgotty / gotty.js
|
|
2
2
|
|
|
3
3
|
[中文 README](README.md)
|
|
4
4
|
|
|
@@ -42,23 +42,22 @@
|
|
|
42
42
|
## Intro
|
|
43
43
|
- This is a GoTTY-compatible server rewritten in JavaScript / Bun.
|
|
44
44
|
- 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 `
|
|
45
|
+
- It includes a frontend and WebTTY protocol implementation adjusted for `jsgotty`.
|
|
46
46
|
- Original repository:
|
|
47
47
|
- https://github.com/sorenisanerd/gotty
|
|
48
48
|
|
|
49
49
|
### Features
|
|
50
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.
|
|
51
54
|
- Kitty Graphics Protocol: displays inline terminal images.
|
|
52
55
|
* For example, `bun viu.mjs 1.png` shows an image directly in the terminal.
|
|
53
56
|
* Windows does not use Kitty protocol; it uses a custom protocol.
|
|
54
57
|
- ZMODEM / `rz/sz`: select files in the browser and upload them to the remote shell.
|
|
55
58
|
* You can also download files from the remote shell.
|
|
56
59
|
* 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
|
|
60
|
+
* Linux has been tested with uploads/downloads around an 80MB Bun binary.
|
|
62
61
|
|
|
63
62
|
## Usage
|
|
64
63
|
|
|
@@ -74,15 +73,20 @@
|
|
|
74
73
|
```sh
|
|
75
74
|
bun gotty.js -w bash
|
|
76
75
|
bun gotty.js -w --credential user:pass bash
|
|
76
|
+
bun gotty.js -w -p 8000 fish
|
|
77
|
+
|
|
78
|
+
# ↓ enables session mode
|
|
77
79
|
bun gotty.js -w --reconnect fish
|
|
78
80
|
bun gotty.js -w --reconnect --reconnect-time 30 fish
|
|
79
81
|
bun gotty.js -w --reconnect --reconnect-time -1 fish
|
|
80
|
-
bun gotty.js -w -p 8000 fish
|
|
81
82
|
|
|
82
83
|
# or npx jsgotty@latest
|
|
83
84
|
|
|
84
|
-
# show help
|
|
85
|
+
# show server / browser help
|
|
85
86
|
bun gotty.js
|
|
87
|
+
bun gotty.js --help
|
|
88
|
+
bun gotty.js --help-web
|
|
89
|
+
# ↑ browser help is also available at /help
|
|
86
90
|
```
|
|
87
91
|
|
|
88
92
|
### Windows
|
|
@@ -91,11 +95,16 @@ bun gotty.js
|
|
|
91
95
|
bun gotty.js -w cmd.exe
|
|
92
96
|
bun gotty.js -w powershell
|
|
93
97
|
|
|
98
|
+
# ↓ enables session mode
|
|
99
|
+
bun gotty.js --reconnect powershell
|
|
100
|
+
|
|
94
101
|
# or npx jsgotty@latest
|
|
95
102
|
|
|
96
|
-
# show help
|
|
103
|
+
# show server / browser help
|
|
97
104
|
bun gotty.js
|
|
98
|
-
bun gotty.js
|
|
105
|
+
bun gotty.js --help
|
|
106
|
+
bun gotty.js --help-web
|
|
107
|
+
# ↑ browser help is also available at /help
|
|
99
108
|
```
|
|
100
109
|
|
|
101
110
|
### Built-in tools
|
|
@@ -107,14 +116,19 @@ bun gotty.js --viu
|
|
|
107
116
|
bun gotty.js --client
|
|
108
117
|
```
|
|
109
118
|
|
|
110
|
-
- `--rz` starts `rz.js
|
|
111
|
-
- `--sz` starts `sz.js
|
|
112
|
-
- `--viu` starts `viu.mjs
|
|
113
|
-
- `--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
|
|
114
123
|
|
|
115
124
|
### CLI Client
|
|
116
125
|
|
|
117
|
-
`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
|
|
118
132
|
|
|
119
133
|
```sh
|
|
120
134
|
# Connect to the default ws://127.0.0.1:8080/ws
|
|
@@ -130,32 +144,42 @@ bun gotty.js --client https://example.com/terminal/
|
|
|
130
144
|
bun gotty.js --client -c user:pass 8081
|
|
131
145
|
```
|
|
132
146
|
|
|
133
|
-
|
|
147
|
+
#### Session management
|
|
134
148
|
|
|
135
149
|
```sh
|
|
136
|
-
# Resume an existing session by reconnect token or PID
|
|
137
|
-
bun gotty.js --client -r <token|pid> [target]
|
|
138
|
-
|
|
139
150
|
# List current sessions
|
|
140
151
|
bun gotty.js --client -ls [target]
|
|
141
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
|
+
|
|
142
157
|
# Disconnect the current writer while keeping the PTY session alive
|
|
158
|
+
# Requires session mode
|
|
143
159
|
bun gotty.js --client -d <token|pid> [target]
|
|
144
160
|
|
|
145
161
|
# Terminate the matching PTY session
|
|
146
162
|
bun gotty.js --client -k <token|pid> [target]
|
|
147
163
|
```
|
|
148
164
|
|
|
149
|
-
|
|
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
|
+
|
|
150
172
|
- `-ls` reads the server's `/css.md` session list.
|
|
151
173
|
- 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
|
-
- `-
|
|
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.
|
|
154
177
|
- `-k` terminates the matching PTY/session.
|
|
155
178
|
- `--arg <value>` may be repeated to pass command arguments; `--arguments <query>` passes a raw query string.
|
|
156
179
|
- `--cols` and `--rows` set the initial terminal size.
|
|
157
180
|
- `GOTTY_CREDENTIAL` and `GOTTY_RECONNECT_TOKEN` may be used to configure credentials and the reconnect token.
|
|
158
|
-
-
|
|
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`.
|
|
159
183
|
|
|
160
184
|
### Wrapper
|
|
161
185
|
- `wgotty` is a wrapper for Linux
|
|
@@ -165,6 +189,47 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
165
189
|
- it will detect whether Bun is installed
|
|
166
190
|
- and show the installation script if needed
|
|
167
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
|
+
|
|
168
233
|
## Tested platforms
|
|
169
234
|
- Windows x64: Windows 11
|
|
170
235
|
- Linux x64: CachyOS
|
|
@@ -176,24 +241,13 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
176
241
|
- Uses Node's built-in `http` / `https`
|
|
177
242
|
- Uses `ws` for WebSocket upgrade handling
|
|
178
243
|
- Uses bundled frontend assets in `./static`, including kitty overlay and WebTTY / ZMODEM frontend logic
|
|
179
|
-
- Supports reconnect tokens and session resume
|
|
180
244
|
- Supports inline terminal images
|
|
181
245
|
- Supports file upload / download
|
|
182
246
|
|
|
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.
|
|
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
|
|
197
251
|
|
|
198
252
|
### Kitty intro
|
|
199
253
|
- If the terminal program outputs images using Kitty Graphics Protocol on Linux, the frontend displays those images at the corresponding terminal position.
|
|
@@ -202,6 +256,7 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
202
256
|
|
|
203
257
|
```sh
|
|
204
258
|
bun viu.mjs 1.png
|
|
259
|
+
# or bun gotty.js --viu 1.png
|
|
205
260
|
```
|
|
206
261
|
|
|
207
262
|
### rz upload intro
|
|
@@ -209,6 +264,7 @@ bun viu.mjs 1.png
|
|
|
209
264
|
|
|
210
265
|
```sh
|
|
211
266
|
bun rz.js
|
|
267
|
+
# or bun gotty.js --rz
|
|
212
268
|
```
|
|
213
269
|
|
|
214
270
|
- The frontend opens a file picker. After selecting files, they are uploaded to the current shell directory using ZMODEM.
|
|
@@ -218,6 +274,7 @@ bun rz.js
|
|
|
218
274
|
|
|
219
275
|
```sh
|
|
220
276
|
bun sz.js file.txt
|
|
277
|
+
# or bun gotty.js --sz file.txt
|
|
221
278
|
```
|
|
222
279
|
|
|
223
280
|
- 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
|
|
|
@@ -38,26 +38,25 @@
|
|
|
38
38
|
|
|
39
39
|
## Intro 介紹
|
|
40
40
|
- 這是用 JavaScript / Bun 重新實作的 GoTTY 相容伺服器
|
|
41
|
-
-
|
|
42
|
-
- 包含已針對 `
|
|
43
|
-
-
|
|
44
|
-
- 原版repo:
|
|
41
|
+
- 參考原本 GoTTY 的程式碼,大部分以 Codex 生成
|
|
42
|
+
- 包含已針對 `jsgotty` 調整過的前端與 WebTTY 協定實作
|
|
43
|
+
- 原版 repo:
|
|
45
44
|
- https://github.com/sorenisanerd/gotty
|
|
46
45
|
|
|
47
46
|
### Features 特色功能
|
|
48
47
|
- Resumable reconnect: 瀏覽器斷線後可以用 reconnect token 接回原本的 shell / PTY,而不是重開一個新的 shell。
|
|
48
|
+
* jsgotty 伺服器端支援兩種連線模式
|
|
49
|
+
* 正常模式、工作階段(session)模式
|
|
50
|
+
* 當命令列參數包含 `--reconnect` 或 `--session` 時會啟用工作階段模式
|
|
51
|
+
* 見下方詳細說明兩種模式
|
|
49
52
|
- Kitty Graphics Protocol: 可以顯示終端內嵌圖片
|
|
50
53
|
* 像是用 `bun viu.mjs 1.png` 直接在終端中顯示圖片。
|
|
51
|
-
* Windows不是使用Kitty協定,而是自訂協議
|
|
52
|
-
- ZMODEM / `rz/sz
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- Linux / macOS: 使用 Bun 內建 PTY `Bun.spawn(..., { terminal: ... })`
|
|
58
|
-
- Windows: 使用patched `node-pty`,但整體以 `bun` 啟動 `gotty.js`
|
|
59
|
-
* 將來會全面使用 Bun
|
|
60
|
-
|
|
54
|
+
* Windows 不是使用 Kitty 協定,而是自訂協議
|
|
55
|
+
- ZMODEM / `rz/sz` 上傳/下載功能
|
|
56
|
+
* 可以從瀏覽器端選檔並上傳到遠端 shell
|
|
57
|
+
* 也可以從遠端 shell 下載檔案
|
|
58
|
+
* Windows 不是使用 ZMODEM,而是自訂協議
|
|
59
|
+
* 目前 Linux 系統實測能上傳/下載約 80MB 的 bun binary
|
|
61
60
|
|
|
62
61
|
## Usage 用法
|
|
63
62
|
|
|
@@ -73,15 +72,20 @@
|
|
|
73
72
|
```sh
|
|
74
73
|
bun gotty.js -w bash
|
|
75
74
|
bun gotty.js -w --credential user:pass bash
|
|
75
|
+
bun gotty.js -w -p 8000 fish
|
|
76
|
+
|
|
77
|
+
# ↓將會開啟工作階段(session)模式
|
|
76
78
|
bun gotty.js -w --reconnect fish
|
|
77
79
|
bun gotty.js -w --reconnect --reconnect-time 30 fish
|
|
78
80
|
bun gotty.js -w --reconnect --reconnect-time -1 fish
|
|
79
|
-
bun gotty.js -w -p 8000 fish
|
|
80
81
|
|
|
81
|
-
#
|
|
82
|
+
# 或 npx jsgotty@latest
|
|
82
83
|
|
|
83
|
-
#
|
|
84
|
+
# 顯示伺服器/瀏覽器端的幫助
|
|
84
85
|
bun gotty.js
|
|
86
|
+
bun gotty.js --help
|
|
87
|
+
bun gotty.js --help-web
|
|
88
|
+
# ↑瀏覽器端可導覽到/help查看
|
|
85
89
|
```
|
|
86
90
|
|
|
87
91
|
### Windows
|
|
@@ -90,14 +94,19 @@ bun gotty.js
|
|
|
90
94
|
bun gotty.js -w cmd.exe
|
|
91
95
|
bun gotty.js -w powershell
|
|
92
96
|
|
|
93
|
-
#
|
|
97
|
+
# ↓將會開啟工作階段(session)模式
|
|
98
|
+
bun gotty.js --reconnect powershell
|
|
94
99
|
|
|
95
|
-
#
|
|
100
|
+
# 或 npx jsgotty@latest
|
|
101
|
+
|
|
102
|
+
# 顯示伺服器/瀏覽器端的幫助
|
|
96
103
|
bun gotty.js
|
|
97
|
-
bun gotty.js
|
|
104
|
+
bun gotty.js --help
|
|
105
|
+
bun gotty.js --help-web
|
|
106
|
+
# ↑瀏覽器端可導覽到/help查看
|
|
98
107
|
```
|
|
99
108
|
|
|
100
|
-
###
|
|
109
|
+
### 內建工具
|
|
101
110
|
|
|
102
111
|
```sh
|
|
103
112
|
bun gotty.js --rz
|
|
@@ -106,14 +115,19 @@ bun gotty.js --viu
|
|
|
106
115
|
bun gotty.js --client
|
|
107
116
|
```
|
|
108
117
|
|
|
109
|
-
- `--rz` starts `rz.js
|
|
110
|
-
- `--sz` starts `sz.js
|
|
111
|
-
- `--viu` starts `viu.mjs
|
|
112
|
-
- `--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
|
|
113
124
|
|
|
114
|
-
|
|
125
|
+
- `client.mjs` 是可直接連接 GoTTY 的互動式終端 client
|
|
126
|
+
- 基本連線相容 Golang GoTTY
|
|
127
|
+
- session 列表、writer 管理與遠端終止 PTY 則需要本專案的 jsgotty server
|
|
128
|
+
- 正常模式與工作階段(session)模式的差異,請見下方詳細說明兩種模式。
|
|
115
129
|
|
|
116
|
-
|
|
130
|
+
#### 基本操作:連接伺服器
|
|
117
131
|
|
|
118
132
|
```sh
|
|
119
133
|
# 連接預設 ws://127.0.0.1:8080/ws
|
|
@@ -129,32 +143,43 @@ bun gotty.js --client https://example.com/terminal/
|
|
|
129
143
|
bun gotty.js --client -c user:pass 8081
|
|
130
144
|
```
|
|
131
145
|
|
|
132
|
-
|
|
146
|
+
#### 進階操作:工作階段管理
|
|
133
147
|
|
|
134
148
|
```sh
|
|
135
|
-
# 使用 reconnect token 或 PID 接回既有 session
|
|
136
|
-
bun gotty.js --client -r <token|pid> [target]
|
|
137
|
-
|
|
138
149
|
# 列出目前 sessions
|
|
139
150
|
bun gotty.js --client -ls [target]
|
|
140
151
|
|
|
152
|
+
# 使用 reconnect token 或 PID 接回既有 session
|
|
153
|
+
# 需開啟 session 模式
|
|
154
|
+
bun gotty.js --client -r <token|pid> [target]
|
|
155
|
+
|
|
141
156
|
# 中斷目前 writer,但保留 PTY session
|
|
157
|
+
# 需開啟 session 模式
|
|
142
158
|
bun gotty.js --client -d <token|pid> [target]
|
|
143
159
|
|
|
144
160
|
# 終止對應的 PTY session
|
|
145
161
|
bun gotty.js --client -k <token|pid> [target]
|
|
146
162
|
```
|
|
147
163
|
|
|
148
|
-
|
|
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
|
+
|
|
149
171
|
- `-ls` 讀取 server 的 `/css.md` session 列表。
|
|
150
|
-
- 使用瀏覽器查看 session
|
|
151
|
-
- 如果 `/css` 顯示的是靜態檔案列表而不是 sessions,代表連線的是 Golang GoTTY,不是
|
|
152
|
-
- `-
|
|
172
|
+
- 使用瀏覽器查看 session 列表時請導覽到 `/css`。
|
|
173
|
+
- 如果 `/css` 顯示的是靜態檔案列表而不是 sessions,代表連線的是 Golang GoTTY,不是 jsgotty。
|
|
174
|
+
- `-r` 需開啟 session 模式;可接回指定的 PTY session。
|
|
175
|
+
- `-d` 需開啟 session 模式;中斷指定 session 的 writer 後,session 仍保留,下一個可寫 client 可接手。
|
|
153
176
|
- `-k` 會直接終止對應 PTY/session。
|
|
177
|
+
|
|
154
178
|
- `--arg <value>` 可重複指定 command arguments;`--arguments <query>` 可傳入原始 query string。
|
|
155
179
|
- `--cols`、`--rows` 可指定初始終端大小。
|
|
156
180
|
- 可用 `GOTTY_CREDENTIAL` 與 `GOTTY_RECONNECT_TOKEN` 環境變數設定 credential 和 reconnect token。
|
|
157
|
-
-
|
|
181
|
+
- PTY 建立方式、writer/viewer 權限與 reconnect 保留時間請參考下方「正常模式 / 工作階段(session)模式」。
|
|
182
|
+
- Golang GoTTY 不支援 `-ls`、`-r`、`-d`、`-k` 這些 jsgotty 控制協議。
|
|
158
183
|
|
|
159
184
|
### Wrapper
|
|
160
185
|
- wgotty is a wrapper for Linux
|
|
@@ -164,6 +189,47 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
164
189
|
- detect installation status of Bun
|
|
165
190
|
- and show installation script if needed
|
|
166
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
|
+
|
|
167
233
|
## Tested platforms 已測試作業系統
|
|
168
234
|
- Windows x64: Windows 11
|
|
169
235
|
- Linux x64: CachyOS
|
|
@@ -171,28 +237,18 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
171
237
|
- Android arm64: My App
|
|
172
238
|
* https://drive.google.com/drive/folders/18iwbKrAZfA-HoTSP9I5MzGz5xVFMZ4bg
|
|
173
239
|
|
|
240
|
+
|
|
174
241
|
## Current implementation 目前實做
|
|
175
242
|
- 使用node原生 `http`/`https`
|
|
176
243
|
- 使用 `ws` 處理 WebSocket upgrade
|
|
177
244
|
- 使用 `./static` 內自帶前端頁面、kitty overlay 與 WebTTY/ZMODEM 前端邏輯
|
|
178
|
-
- 支援 reconnect token 與 session resume,可接回原本 shell
|
|
179
245
|
- 支援輸出圖片到終端
|
|
180
246
|
- 支援檔案上傳/下載
|
|
181
247
|
|
|
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 與連結。
|
|
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
|
|
196
252
|
|
|
197
253
|
### Kitty intro
|
|
198
254
|
- 只要終端程式使用 Kitty Graphics Protocol (Linux) 輸出圖片,前端就會把圖片顯示在終端對應位置。
|
|
@@ -201,6 +257,7 @@ bun gotty.js --client -k <token|pid> [target]
|
|
|
201
257
|
|
|
202
258
|
```sh
|
|
203
259
|
bun viu.mjs 1.png
|
|
260
|
+
# or bun gotty.js --viu 1.png
|
|
204
261
|
```
|
|
205
262
|
|
|
206
263
|
### rz upload intro
|
|
@@ -208,6 +265,7 @@ bun viu.mjs 1.png
|
|
|
208
265
|
|
|
209
266
|
```sh
|
|
210
267
|
bun rz.js
|
|
268
|
+
# or bun gotty.js --rz
|
|
211
269
|
```
|
|
212
270
|
|
|
213
271
|
- 前端會跳出檔案選擇視窗。選擇檔案後,會以 ZMODEM 上傳到目前 shell 所在目錄。
|
|
@@ -217,6 +275,7 @@ bun rz.js
|
|
|
217
275
|
|
|
218
276
|
```sh
|
|
219
277
|
bun sz.js file.txt
|
|
278
|
+
# or bun gotty.js --sz file.txt
|
|
220
279
|
```
|
|
221
280
|
|
|
222
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`);
|
package/gotty.js
CHANGED
|
@@ -168,8 +168,8 @@ Options:
|
|
|
168
168
|
--title-format <value> Title format
|
|
169
169
|
(default: {{ .command }}@{{ .hostname }} )
|
|
170
170
|
|
|
171
|
-
--reconnect
|
|
172
|
-
|
|
171
|
+
--reconnect, --session Enable session mode
|
|
172
|
+
Keep the PTY session resumable after the browser disconnects
|
|
173
173
|
(default: disabled)
|
|
174
174
|
--reconnect-time <value> Time to preserve original TTY (seconds)
|
|
175
175
|
(default: -1 (forever) )
|
|
@@ -539,6 +539,7 @@ function parseArgs(argv) {
|
|
|
539
539
|
options.titleFormat = next();
|
|
540
540
|
break;
|
|
541
541
|
case "--reconnect":
|
|
542
|
+
case "--session":
|
|
542
543
|
options.reconnect = true;
|
|
543
544
|
break;
|
|
544
545
|
case "--reconnect-time":
|