jsgotty 0.9.1 → 1.0.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.en.md +209 -0
- package/README.md +68 -0
- package/client.mjs +696 -0
- package/gotty.js +384 -50
- package/package.json +1 -1
- package/static/js/gotty.js +6 -2
- package/viu.mjs +1 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# js-gotty / gotty.js
|
|
2
|
+
|
|
3
|
+
[中文 README](README.md)
|
|
4
|
+
|
|
5
|
+
## News
|
|
6
|
+
### 2026/06/22 - [1.0.0]
|
|
7
|
+
- Added gotty cli client
|
|
8
|
+
* compatible with golang gotty
|
|
9
|
+
* jsgotty --client -h for more info
|
|
10
|
+
- Added /css to list sessions
|
|
11
|
+
* when --reconnect enabled, /css can reconnect to existing sessions
|
|
12
|
+
|
|
13
|
+
### 2026/04/23
|
|
14
|
+
- Added optional `noWinOpenUseFetch()` on the frontend for Bun markdown TUI:
|
|
15
|
+
- https://github.com/jjtseng93/bun-taskmgr
|
|
16
|
+
|
|
17
|
+
### 2026/04/21
|
|
18
|
+
- Added dialog text display on the frontend:
|
|
19
|
+
- `alert_advanced(getTerminalText())`
|
|
20
|
+
- for copying text on mobile devices
|
|
21
|
+
|
|
22
|
+
## Intro
|
|
23
|
+
- This is a GoTTY-compatible server rewritten in JavaScript / Bun.
|
|
24
|
+
- 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 `js-gotty`.
|
|
26
|
+
- Original repository:
|
|
27
|
+
- https://github.com/sorenisanerd/gotty
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
- Resumable reconnect: after the browser disconnects, you can reconnect to the original shell / PTY with a reconnect token instead of spawning a new shell.
|
|
31
|
+
- Kitty Graphics Protocol: displays inline terminal images.
|
|
32
|
+
* For example, `bun viu.mjs 1.png` shows an image directly in the terminal.
|
|
33
|
+
* Windows does not use Kitty protocol; it uses a custom protocol.
|
|
34
|
+
- ZMODEM / `rz/sz`: select files in the browser and upload them to the remote shell.
|
|
35
|
+
* You can also download files from the remote shell.
|
|
36
|
+
* 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
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Install Bun
|
|
46
|
+
- Android / Termux:
|
|
47
|
+
* `pkg install npm`
|
|
48
|
+
* `npm install -g bun`
|
|
49
|
+
- Other platforms:
|
|
50
|
+
* https://bun.com
|
|
51
|
+
|
|
52
|
+
### Linux
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
bun gotty.js -w bash
|
|
56
|
+
bun gotty.js -w --credential user:pass bash
|
|
57
|
+
bun gotty.js -w --reconnect fish
|
|
58
|
+
bun gotty.js -w --reconnect --reconnect-time 30 fish
|
|
59
|
+
bun gotty.js -w --reconnect --reconnect-time -1 fish
|
|
60
|
+
bun gotty.js -w -p 8000 fish
|
|
61
|
+
|
|
62
|
+
# or npx jsgotty@latest
|
|
63
|
+
|
|
64
|
+
# show help
|
|
65
|
+
bun gotty.js
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Windows
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
bun gotty.js -w cmd.exe
|
|
72
|
+
bun gotty.js -w powershell
|
|
73
|
+
|
|
74
|
+
# or npx jsgotty@latest
|
|
75
|
+
|
|
76
|
+
# show help
|
|
77
|
+
bun gotty.js
|
|
78
|
+
bun gotty.js -h
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Built-in tools
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
bun gotty.js --rz
|
|
85
|
+
bun gotty.js --sz
|
|
86
|
+
bun gotty.js --viu
|
|
87
|
+
bun gotty.js --client
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `--rz` starts `rz.js`
|
|
91
|
+
- `--sz` starts `sz.js`
|
|
92
|
+
- `--viu` starts `viu.mjs`
|
|
93
|
+
- `--client` starts `client.mjs`
|
|
94
|
+
|
|
95
|
+
### CLI Client
|
|
96
|
+
|
|
97
|
+
`client.mjs` is an interactive terminal client that connects directly to GoTTY. Basic connections are compatible with Golang GoTTY. Session listing, writer management, and remote PTY termination require this project's js-gotty server.
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
# Connect to the default ws://127.0.0.1:8080/ws
|
|
101
|
+
bun gotty.js --client
|
|
102
|
+
|
|
103
|
+
# Connect to 127.0.0.1:8081
|
|
104
|
+
bun gotty.js --client 8081
|
|
105
|
+
|
|
106
|
+
# HTTP(S) page URLs and WS(S) URLs are accepted
|
|
107
|
+
bun gotty.js --client https://example.com/terminal/
|
|
108
|
+
|
|
109
|
+
# Connect with credentials
|
|
110
|
+
bun gotty.js --client -c user:pass 8081
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The first writable client becomes the writer, while additional connections are read-only viewers. Use `--readonly` to connect explicitly as a viewer. The client reports its current writer/viewer role. When the server enables `--reconnect`, it also reports the session PID and reconnect token.
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
# Resume an existing session by reconnect token or PID
|
|
117
|
+
bun gotty.js --client -r <token|pid> [target]
|
|
118
|
+
|
|
119
|
+
# List current sessions
|
|
120
|
+
bun gotty.js --client -ls [target]
|
|
121
|
+
|
|
122
|
+
# Disconnect the current writer while keeping the PTY session alive
|
|
123
|
+
bun gotty.js --client -d <token|pid> [target]
|
|
124
|
+
|
|
125
|
+
# Terminate the matching PTY session
|
|
126
|
+
bun gotty.js --client -k <token|pid> [target]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- `-r` resumes an existing session; lookup by PID is a js-gotty extension.
|
|
130
|
+
- `-ls` reads the server's `/css.md` session list.
|
|
131
|
+
- 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 js-gotty.
|
|
133
|
+
- `-d` requires `--reconnect` on the server. The session remains alive after its writer is disconnected, allowing another client to take over.
|
|
134
|
+
- `-k` terminates the matching PTY/session.
|
|
135
|
+
- `--arg <value>` may be repeated to pass command arguments; `--arguments <query>` passes a raw query string.
|
|
136
|
+
- `--cols` and `--rows` set the initial terminal size.
|
|
137
|
+
- `GOTTY_CREDENTIAL` and `GOTTY_RECONNECT_TOKEN` may be used to configure credentials and the reconnect token.
|
|
138
|
+
- Golang GoTTY does not support the js-gotty control protocols used by `-ls`, `-d`, and `-k`.
|
|
139
|
+
|
|
140
|
+
### Wrapper
|
|
141
|
+
- `wgotty` is a wrapper for Linux
|
|
142
|
+
- or for Windows with `busybox64u.exe bash`
|
|
143
|
+
- https://frippery.org/busybox/
|
|
144
|
+
- just run `./wgotty`
|
|
145
|
+
- it will detect whether Bun is installed
|
|
146
|
+
- and show the installation script if needed
|
|
147
|
+
|
|
148
|
+
## Tested platforms
|
|
149
|
+
- Windows x64: Windows 11
|
|
150
|
+
- Linux x64: CachyOS
|
|
151
|
+
- Android arm64: Termux Native / Proot
|
|
152
|
+
- Android arm64: My App
|
|
153
|
+
* https://drive.google.com/drive/folders/18iwbKrAZfA-HoTSP9I5MzGz5xVFMZ4bg
|
|
154
|
+
|
|
155
|
+
## Current implementation
|
|
156
|
+
- Uses Node's built-in `http` / `https`
|
|
157
|
+
- Uses `ws` for WebSocket upgrade handling
|
|
158
|
+
- Uses bundled frontend assets in `./static`, including kitty overlay and WebTTY / ZMODEM frontend logic
|
|
159
|
+
- Supports reconnect tokens and session resume
|
|
160
|
+
- Supports inline terminal images
|
|
161
|
+
- Supports file upload / download
|
|
162
|
+
|
|
163
|
+
### Reconnect / Resume
|
|
164
|
+
- `--reconnect` is not just reopening a websocket. The server keeps the current PTY session alive so the browser can reconnect to the original shell.
|
|
165
|
+
- The server generates a reconnect token for each reconnectable session. The frontend stores this token automatically and prefers it on reconnect.
|
|
166
|
+
- `--reconnect-time` semantics:
|
|
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.
|
|
177
|
+
|
|
178
|
+
### Kitty intro
|
|
179
|
+
- If the terminal program outputs images using Kitty Graphics Protocol on Linux, the frontend displays those images at the corresponding terminal position.
|
|
180
|
+
- Windows uses a custom protocol.
|
|
181
|
+
- Usage:
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
bun viu.mjs 1.png
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### rz upload intro
|
|
188
|
+
- When the remote shell runs:
|
|
189
|
+
|
|
190
|
+
```sh
|
|
191
|
+
bun rz.js
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
- The frontend opens a file picker. After selecting files, they are uploaded to the current shell directory using ZMODEM.
|
|
195
|
+
|
|
196
|
+
### sz download intro
|
|
197
|
+
- When the remote shell runs:
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
bun sz.js file.txt
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- The frontend receives the ZMODEM download data and lets the browser download the file.
|
|
204
|
+
|
|
205
|
+
## Notes
|
|
206
|
+
- The goal is to emulate the main behavior of the original GoTTY and add additional features.
|
|
207
|
+
- Bun is the primary runtime.
|
|
208
|
+
- On Linux / macOS, PTY support will not work unless the program is launched with Bun.
|
|
209
|
+
- GoTTY config file loading is not implemented yet.
|
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# js-gotty / gotty.js
|
|
2
2
|
|
|
3
|
+
[English README](README.en.md)
|
|
4
|
+
|
|
3
5
|
## News
|
|
6
|
+
### 2026/06/22 - [1.0.0]
|
|
7
|
+
- Added gotty cli client
|
|
8
|
+
* compatible with golang gotty
|
|
9
|
+
* jsgotty --client -h for more info
|
|
10
|
+
- Added /css to list sessions
|
|
11
|
+
* when --reconnect enabled, /css can reconnect to existing sessions
|
|
4
12
|
### 2026/04/23
|
|
5
13
|
- Added optional noWinOpenUseFetch() at the frontend for Bun markdown TUI:
|
|
6
14
|
- https://github.com/jjtseng93/bun-taskmgr
|
|
@@ -70,6 +78,65 @@ bun gotty.js
|
|
|
70
78
|
bun gotty.js -h
|
|
71
79
|
```
|
|
72
80
|
|
|
81
|
+
### Built-in tools
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
bun gotty.js --rz
|
|
85
|
+
bun gotty.js --sz
|
|
86
|
+
bun gotty.js --viu
|
|
87
|
+
bun gotty.js --client
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `--rz` starts `rz.js`
|
|
91
|
+
- `--sz` starts `sz.js`
|
|
92
|
+
- `--viu` starts `viu.mjs`
|
|
93
|
+
- `--client` starts `client.mjs`
|
|
94
|
+
|
|
95
|
+
### CLI Client
|
|
96
|
+
|
|
97
|
+
`client.mjs` 是可直接連接 GoTTY 的互動式終端 client。基本連線相容 Golang GoTTY;session 列表、writer 管理與遠端終止 PTY 則需要本專案的 js-gotty server。
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
# 連接預設 ws://127.0.0.1:8080/ws
|
|
101
|
+
bun gotty.js --client
|
|
102
|
+
|
|
103
|
+
# 連接 127.0.0.1:8081
|
|
104
|
+
bun gotty.js --client 8081
|
|
105
|
+
|
|
106
|
+
# 可使用 HTTP(S) 頁面網址或 WS(S) 網址
|
|
107
|
+
bun gotty.js --client https://example.com/terminal/
|
|
108
|
+
|
|
109
|
+
# 使用帳號密碼
|
|
110
|
+
bun gotty.js --client -c user:pass 8081
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
連線後,第一個可寫入的 client 會成為 writer,其餘連線為唯讀 viewer。也可使用 `--readonly` 主動以 viewer 身分連線。client 會顯示目前的 writer/viewer 權限;server 啟用 `--reconnect` 時,還會顯示 session PID 與 reconnect token。
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
# 使用 reconnect token 或 PID 接回既有 session
|
|
117
|
+
bun gotty.js --client -r <token|pid> [target]
|
|
118
|
+
|
|
119
|
+
# 列出目前 sessions
|
|
120
|
+
bun gotty.js --client -ls [target]
|
|
121
|
+
|
|
122
|
+
# 中斷目前 writer,但保留 PTY session
|
|
123
|
+
bun gotty.js --client -d <token|pid> [target]
|
|
124
|
+
|
|
125
|
+
# 終止對應的 PTY session
|
|
126
|
+
bun gotty.js --client -k <token|pid> [target]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- `-r` 可接回既有 session;PID 查找是 js-gotty 擴充功能。
|
|
130
|
+
- `-ls` 讀取 server 的 `/css.md` session 列表。
|
|
131
|
+
- 使用瀏覽器查看 session 列表時請開啟 `/css`。
|
|
132
|
+
- 如果 `/css` 顯示的是靜態檔案列表而不是 sessions,代表連線的是 Golang GoTTY,不是 js-gotty。
|
|
133
|
+
- `-d` 需要 server 啟用 `--reconnect`,中斷 writer 後 session 仍保留,其他 client 可接手。
|
|
134
|
+
- `-k` 會直接終止對應 PTY/session。
|
|
135
|
+
- `--arg <value>` 可重複指定 command arguments;`--arguments <query>` 可傳入原始 query string。
|
|
136
|
+
- `--cols`、`--rows` 可指定初始終端大小。
|
|
137
|
+
- 可用 `GOTTY_CREDENTIAL` 與 `GOTTY_RECONNECT_TOKEN` 環境變數設定 credential 和 reconnect token。
|
|
138
|
+
- Golang GoTTY 不支援 `-ls`、`-d`、`-k` 這些 js-gotty 控制協議。
|
|
139
|
+
|
|
73
140
|
### Wrapper
|
|
74
141
|
- wgotty is a wrapper for Linux
|
|
75
142
|
- or Windows with busybox64u.exe bash
|
|
@@ -106,6 +173,7 @@ bun gotty.js -h
|
|
|
106
173
|
* overlay 會提供 `Reconnect` 按鈕,可手動立即重試
|
|
107
174
|
* 該按鈕右鍵/長按可輸入自訂reconnect token
|
|
108
175
|
- 目前 reconnect 是「接回現有 shell」,不是「回放斷線期間所有輸出」。斷線期間的輸出不會補送。
|
|
176
|
+
- `--reconnect` 關閉時,`/css` 與 `/css.md` 仍會顯示 PID / command name,只是不會提供 reconnect token 與連結。
|
|
109
177
|
|
|
110
178
|
### Kitty intro
|
|
111
179
|
- 只要終端程式使用 Kitty Graphics Protocol (Linux) 輸出圖片,前端就會把圖片顯示在終端對應位置。
|