dsh-remote 0.8.85 → 0.8.87

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 CHANGED
@@ -59,6 +59,8 @@ The rest:
59
59
 
60
60
  - **21 model tools** (listed so they can be copied or searched): `rw_info`, `rw_connect`, `rw_machines`, `rw_pick_workspace`, `rw_list_dir`, `rw_stat`, `rw_read_file`, `rw_write_file`, `rw_edit`, `rw_append`, `rw_mkdir`, `rw_remove`, `rw_move`, `rw_exec`, `rw_search`, `rw_download`, `rw_upload`, `rw_sync`, `rw_push`, `rw_forward`, `rw_disconnect`.
61
61
  - **Tell local and remote Sessions apart in the sidebar** (`0.8.43+`) — a remote Session row carries a **green dot** and its hover card names `user@host:port` plus the remote path; opening it also shows a host chip in the conversation header (a local Session shows neither). A Session counts as remote only when its cwd sits inside a `$DSH_HOME/remote-workspaces/…` mirror, so a machine that is merely saved never labels a local Session.
62
+ - **A terminal in a remote Session opens on the remote host out of the box** (`0.8.75+`) — the shell menu's **remote ssh** entry routes by cwd (a mirror cwd → ssh into the remote workspace; anything else → transparent local-shell fallback), and it is the **default shell** whenever neither the host nor you picked one. Saved passwords are answered through the local credential bridge (`0.8.81+`, including OS-keychain ones) — no more `password:` prompt every time a terminal opens.
63
+ - **Remote file previews have line numbers and syntax highlighting** (`0.8.86+`) — code files render through the host's own Shiki engine, and chat links carrying `file:line` (or `#L<n>`) land on that line with a flash.
62
64
  - **Open a remote machine's DSH Web UI locally** (`0.8.36+`) — nothing has to be exposed on the remote: the plugin SSHes out, starts a `dsh web` there that binds **`127.0.0.1` only**, and tunnels its port back to a loopback port on this machine. The URL carries a one-time login token, consumed once by a redirect.
63
65
  - **The audit log opens locally** — preview recent entries in the panel, or use 「打开日志文件」/「在文件夹中显示」 to open the log with a local program (the log lives on the DSH host, so a browser cannot open it).
64
66
  - **Cross-platform remotes** — all file access is SFTP-protocol-level (no POSIX shell), so Linux/macOS/Windows remotes all work.
@@ -147,23 +149,11 @@ A new tab opens showing that remote machine's full DSH interface (chat, tool tre
147
149
  from 20.12). On an older node npm only warns (EBADENGINE) and installs anyway, and the crash arrives
148
150
  later as `does not provide an export named 'parseEnv'` — check the version before you install.
149
151
 
150
- ### Cannot connect? Install dsh on the remote yourself
151
-
152
- **A failed connect is usually not the plugin's fault: the remote dsh is missing or too old.**
153
- The classic case: dsh 0.1.0-rc.6 depends on `node-pty@1.1.0`, whose published package ships
154
- **no `linux-x64` prebuild**, so `dsh web` cannot start on Linux at all.
155
-
156
- The plugin no longer installs or health-checks dsh for you. Install it on the remote the way you
157
- install anything else, then point the plugin at it: Settings → Remote workspaces → the machine row →
158
- **Edit** → Advanced → **remote dsh command** (or the global `webAttachCommand`).
159
-
160
152
  ## Use it from the TUI (dsh-tui)
161
153
 
162
- The plugin ships a TUI adaptation layer: once installed into a `dsh-tui` profile, the same machine
163
- registry, SSH pool and remote workspaces work in the terminal UI — **without patching dsh-tui itself**
164
- (everything registers through its plugin seams).
165
-
166
- ### Install
154
+ The plugin ships a TUI adaptation layer: once installed into a `dsh-tui` profile, the same
155
+ machine registry, SSH pool and remote workspaces work in the terminal UI — **without patching
156
+ dsh-tui itself** (everything registers through its plugin seams).
167
157
 
168
158
  ```bash
169
159
  # On a machine that already runs dsh-tui this is the only step; a local checkout works too
@@ -171,70 +161,14 @@ dsh plugin --profile dsh-tui add dsh-remote
171
161
  # or: dsh plugin --profile dsh-tui add /path/to/dsh-remote
172
162
  ```
173
163
 
174
- Restart dsh-tui afterwards. Web profiles are unaffected: without terminal seams the TUI layer stays
175
- completely silent and registers nothing.
176
-
177
- ### `/dsh-remote` — the remote-server settings page, in your terminal
178
-
179
- Type `/dsh-remote` to open a full-screen settings page (the command also shows up in `/` completion
180
- and `/help`):
181
-
182
- - `↑/↓` picks a machine, `Enter` opens the action menu; `a` add, `e` edit, `d` delete, `t` test
183
- connection, `c` connect, `b` browse remote directories, `o` open the local mirror folder,
184
- `Esc`/`q` close (inside a sub-view they step back to the list first; `m` in the action menu
185
- manages workspaces).
186
- - Add/edit: name, host, port, username, auth method (password / private key / SSH agent), password or
187
- key path, group. Passwords are **write-only** and never echoed; leaving the field empty keeps the
188
- stored value.
189
- - `b` browses remote directories; `w` adopts the current one as a **workspace**: it creates the local
190
- mirror, registers it as a DSH workspace (title `<machine>-<directory>`) and, per configuration,
191
- switches the session there.
192
- - `o` opens the local mirror root `$DSH_HOME/remote-workspaces` in the system file manager (each
193
- machine's mirrors live under a `<host>-<user>-<port>` subdirectory). That directory also holds
194
- `machines.json` and other plugin data — with `credentialFallback: plain` it can contain plaintext
195
- passwords; it is only exposed locally.
196
-
197
- ### Pick a remote directory when creating a workspace
198
-
199
- - The `/workspace` picker lists every machine's recent remote projects next to local directories
200
- (badge = machine name, description = `user@host:/remote/path`). Picking one opens that remote
201
- workspace in a new session.
202
- - URI form works too: `/workspace open dshremote://<machine-name-or-id>/<URL-encoded remote absolute path>`.
203
- - Launch arguments work as well: `dst dshremote://<machine>/<remote path>`.
204
- - How many entries each machine contributes is controlled by the configuration below.
205
-
206
- ### Clean up workspaces (delete a workspace or its chats)
207
-
208
- `/dsh-remote` → pick a machine → `m` (manage workspaces) lists every local mirror of that machine:
209
-
210
- - `d`: **delete the workspace permanently** — its chats, its workspace registration, the remote
211
- path in every machine's recent list, and finally the local mirror directory
212
- `$DSH_HOME/remote-workspaces/<host>-<user>-<port>/<name>`. Removing the recent entry matters:
213
- otherwise the provider recreates the mirror from it on the next start.
214
- - `x`: delete only the chats under that workspace (mirror and registration stay); chats still in
215
- use are skipped and reported.
216
- - `r`: only forget the remote path from the recent list / current workspace (no deletion) — stops
217
- the automatic recreation.
218
- - While a chat still uses the workspace, `d` is refused (stop background sessions with `Ctrl+X` or
219
- exit the terminal that holds it). Deletion is irreversible and does **not** touch the remote
220
- directory.
221
-
222
- ### Configuration
223
-
224
- The TUI layer's five switches live on the same `cordis.patch.yml` row as every other
225
- option — see the last five rows of the [Configuration](#configuration) table
226
- (`tui` / `tuiProviderListRecent` / `tuiProviderRecentLimit` / `tuiAutoSwitchWorkspace` /
227
- `tuiLang`).
228
-
229
- ### Notes
230
-
231
- - A remote project is presented in the terminal as its **local mirror directory**: that is the
232
- session cwd and where the `rw_*` tools operate; the remote path only appears in titles and
233
- descriptions. The remote identity comes from `.dsh-remote-meta.json` inside the mirror.
234
- - The workspace provider is a newer dsh-tui seam: on older dsh-tui builds (or profiles that do not
235
- mount it) the `/dsh-remote` page and the workspace registry still work; only the picker entries are
236
- missing.
237
- - Design and host-API contract: [docs/tui.md](docs/tui.md).
164
+ Restart dsh-tui afterwards. What you get:
165
+
166
+ - `/dsh-remote` — a full-screen server page (add/edit/delete, connect, probe, browse, set-as-workspace, cleanup);
167
+ - the `/workspace` picker lists remote projects directly (or go straight: `dshremote://<machine>/<path>`);
168
+ - the status bar names the current remote machine (remote Sessions only; hover for details).
169
+
170
+ Web profiles are unaffected: without the terminal seams the layer stays off, silently. Keymap,
171
+ cleanup semantics, the host-API contract and the limits live in **[docs/tui.md](docs/tui.md)** (Chinese).
238
172
 
239
173
  ## CLI defaults (optional)
240
174
 
@@ -352,106 +286,23 @@ Deploying to a product profile is a separate, explicit action (`./sync.sh`) for
352
286
 
353
287
  ## FAQ / troubleshooting
354
288
 
355
- **`@` lists remote files but the built-in read tool cannot open them** — the harness's own file tools see the **local mirror**, which stays empty until `rw_sync` downloads it. Read remote files with `rw_read_file` or the sidebar remote tab.
356
-
357
- **A file link in a remote Session does not open** (issue #55) — fixed. When a link is clicked the harness turns it into `dsh-resource://file/session/<session>/<path>` and hands it to the built-in text preview, which reads the **local** filesystem; a remote Session's cwd is a **local mirror directory** (empty until `rw_sync`), so the open simply failed. The plugin now registers a higher-priority handler for that address and opens it over SFTP through the same editor as the sidebar "Remote Files" tab. The safety rule is deliberately conservative: it takes over only when the Session's cwd is **provably inside a mirror** and the mirror registry has loaded, so local Sessions — and the instant right after a page load — keep the built-in preview and no local file is ever mistaken for a remote one. The two cases that still cannot be mapped say so instead of showing a blank page: an address with no mirror mapping, and a Session whose workspace is not a remote mirror directory.
358
-
359
- **The sidebar terminal in a remote Session is a LOCAL one** (issue #55, the terminal half) — solved in 0.8.75, no clicks needed. The shell menu has long carried the plugin's **remote ssh** entry: a cwd-aware launcher that ssh'es into the remote workspace when the session sits in a remote mirror and falls back to a local shell otherwise. As of 0.8.75 it also becomes the **default shell**: unless the host administrator configured a default (`config.shell`) or you picked a shell from the menu yourself, "open terminal" in a remote session lands on the remote host directly, while local sessions keep opening a local shell (the launcher routes by cwd). Two safeguards: a shell you picked manually from the menu always wins, and `remoteTerminalDefault: false` restores menu-only behaviour. For a heavier-weight answer there is still the "remote DSH UI" above — your browser opens the remote machine's OWN harness, whose terminals natively run on the far side. To just run one remote command, `rw_exec` (add `pty: true` for an interactive pty).
360
-
361
- `.md`/`.markdown` links in a remote session take the same SFTP path and preview in the tab (issue #74). They used to be handed back to the built-in Markdown renderer (issue #64), which reads the local mirror and fails with `ENOENT` until `rw_sync`. The preview is now the remote bytes, rendered with the host Markdown component; builds without that component show the source. Local sessions still use the built-in preview. Images render inline in the sidebar remote tree for png/jpg/gif/webp/svg/bmp (issue #66; files over 2MB fall back to the download button).
362
-
363
- **One SFTP timeout wedged every SFTP tool on that machine** (issue #65) — fixed (0.8.52+). A single operation hitting the 20s timeout used to poison the whole process for that machine (every later SFTP call paid its own 20s, while `rw_exec` stayed fine) until a disconnect/reconnect. Now a timeout kills the channel so later requests fail fast; the native backend tears the connection down and re-handshakes after two consecutive timeouts, and the openssh backend rebuilds its sftp child — a transient network blip no longer ends with "disconnect and reconnect". As a bonus, `rw_edit` now writes atomically (temp file + rename), so an interrupted write can no longer truncate the remote file to zero bytes, and the original permission bits are preserved.
364
-
365
- **Are remote operations subject to the local sandbox?** (0.8.54+) — yes. They were not before: a local session has `ctx.sandboxPolicy` (read-only / workspace-write / danger-full-access), while every `rw_*` tool ran remote operations with NO policy at all — so a read-only session could still mutate any file on any reachable host. The sandbox was not bypassed; it simply had no say over a different machine. The plugin now applies the same resolved mode at the TOOL boundary:
366
-
367
- - `read-only` refuses remote writes, refuses running commands, refuses opening port forwards (reads and connections stay available, or the machine could not even be inspected);
368
- - `workspace-write` requires remote writes to land inside the workspace root (a path fence) and allows commands and forwards;
369
- - `danger-full-access` allows everything.
370
-
371
- Why a tool-layer fence rather than `ctx.sandbox.confine()`: the latter wraps argv for a spawn on THIS machine, while our process runs on the far side of an SSH channel — the core docs say so themselves ("remote execution replaces the surrounding capability seam"). A denial therefore carries the OFFICIAL `FS_SANDBOX_DENIED` shape (with the `[sandbox: …]` marker and the escalation hint), so the model's escalation path still works.
372
-
373
- **The threat model, stated plainly**: this is CONTAINMENT, not a security boundary (the same wording the official `dsh-fs-sandbox` header uses). Paths are compared lexically, so symlinks and TOCTOU inside the remote host can escape, and once bash runs it holds that user's own privileges. What it does buy: a confined session can no longer change remote files outside its workspace BY ACCIDENT, and a read-only session cannot quietly run commands. Deployments needing a hard boundary must confine on the REMOTE side (containers, per-user accounts, filesystem ACLs). Set `remoteSandbox: 'off'` to disable the fence.
374
-
375
- **Does a password land in plaintext when the keychain fails?** (0.8.54+) — by default, no. Previously a failed secure-store write (locked keychain / missing secret-tool / Windows DPAPI without the assembly) fell back to PLAINTEXT in `machines.json` with a warning — you asked for encryption and got something less safe than if you had not asked, and a broken keychain is exactly when nobody notices. The default is now `credentialFallback: 'refuse'`: the password is NOT saved, the machine is still saved without a credential, and the UI reports the store failure. Set `credentialFallback: 'plain'` for the legacy behaviour. Turning encryption off explicitly (`backend: 'plain'`) is unaffected.
376
-
377
- **How do I stop picking the wrong machine once I have many?** (0.8.54+) — give machines GROUP LABELS: `environment` (prod/staging…), `location` (shanghai/gpu-lab…), `description`, and `tags` (free-form). They are pure labels and change no connection behaviour. `rw_machines` filters on them (AND across dimensions, OR within a tag list): `rw_machines(environment="prod", tags="gpu")`. An empty result lists the groups that DO exist, so you never have to guess a spelling. The settings page edits them too. Past a dozen machines, "pick the right host" stops being a memory problem.
378
-
379
- **What about multi-level bastions?** (0.8.54+) — **multi-hop chains** are supported (OpenSSH `ProxyJump a,b,c` semantics): a bastion may carry its own `proxy`, and the chain is built from the FARTHEST hop inward, each hop dialed through the already-open connection to the previous one. Two constraints matter: credentials do NOT inherit across hops (the target's private key is never presented to an intermediate host — it is usually not authorized there, and handing it over would leak a secret that host should never see), and a chain deeper than 8 hops is reported as an error, which turns a config CYCLE into a clear message instead of unbounded recursion. Each hop may carry its own `privateKeyPath` / `useAgent` / `hostKeyMode`.
380
-
381
- **Can I open a remote terminal inside DSH?** (0.8.54+) — yes: an **embedded PTY terminal**. `rw_exec` runs one command and closes — no PTY, no stdin once the writer returns — so `vim`, `top`, a `sudo` prompt or any full-screen TUI is impossible. `pool.shell()` now opens a PERSISTENT PTY channel, and terminal sessions are host-owned: closing the browser does not kill the remote shell (a half-finished vim survives a reload), each session is reclaimed after 30 idle minutes, at most 8 live per process (so a UI cannot exhaust the remote `MaxSessions`), and unloading the plugin hangs up every one of them.
382
-
383
- The transport is deliberately boring: the remote session lives on the HOST and the browser POLLS for output deltas (input is a separate request written immediately, so typing never waits for the poll cadence). That avoids depending on whether the host exposes a WebSocket upgrade path. The routes are `/dsh-remote/term/{open,input,output,resize,close,list}`, and each resolves the binding from the SESSION first — a terminal opened on host A can be neither seen nor driven by a request bound to host B.
384
-
385
- **The machine's IP / username changed — must every workspace be recreated?** (issue #67) — no (0.8.52+). Edit the machine's new address on the settings page and save, or call `rw_connect(machineId=…, host=…, username=…, port=…)` with the new address: every workspace mirror bound to that machine is **rebound in place** (its `.dsh-remote-meta.json` is rewritten) — local content is kept, no re-sync needed, and the save response says how many mirrors were rebound. The mirror directory name does not follow (live Sessions hold cwd paths inside it); the name is a display label only and does not affect connectivity.
386
-
387
- **Remote Sessions could not see the workspace AGENTS.md** (issue #68) — fixed (0.8.52+). The core instruction loader only knows the local filesystem, and a remote Session's cwd is the local mirror, so the remote repo's AGENTS.md never reached the model's context. Now, when `rw_pick_workspace` succeeds, the remote workspace gets a shallow scan (root + at most two levels down, matching `AGENTS.md`/`CLAUDE.md` only); the found files are synced into the local mirror under a three-way guard (root-level copies thus enter the core's own injection path, exactly like a local Session), and an index of paths + headings is rendered into the system prompt, telling the model to read nested instruction files with `rw_read_file` before editing. Full-tree recursion and plugin-side full-text injection are deliberately **not** done (the former would scan through multi-project roots; the latter would run a second injection pipeline in parallel with the core's).
388
-
389
- **Does reading a file in a remote subdirectory pull that subdirectory's AGENTS.md into context?** (issue #71) — yes (0.8.53+). #68 fixed only the static half (workspace shallow scan + index line); the dynamic half was still broken, because the core's incremental injection recognizes only `read`/`write`/`edit` with a `file_path` argument — `rw_read_file` matches on neither name nor argument — and it expands scopes using LOCAL paths, so a remote absolute path maps onto no mirror cwd. Any one of those three gaps was enough to stop the injection from ever happening. The plugin now hooks `rw_*` file touches itself on `tools/result`, takes the WHOLE ancestor chain from the touched directory up to the workspace root (not just the deepest level, matching local Sessions: reading `a/b/c.ts` brings in both `a/AGENTS.md` and `a/b/AGENTS.md`), stats each level, and injects the current contents as ONE user message. Boundaries that matter: the cwd's own level is not re-scanned (the core baseline covers it, so reading a file directly in the workspace root triggers no extra scan); delivery is deduplicated per session by content digest, so the same content is injected once; a remote edit is re-injected on the next touch; a previously injected file that disappears produces a "removed" notice; one batch has a 16 KB budget; and an offline machine degrades silently — it hangs neither the tool call nor the prompt assembly. The message carries the plugin's own `source.kind` (`dsh-remote-instructions`), while the core's state machine claims only its own `agent-instructions`, so the two injection paths cannot fight.
390
-
391
- **Can `rw_exec` take a per-call timeout, be cancelled, and move to the background like the built-in shell?** (issue #70) — yes (0.8.53+). The transport (`pool.exec`) already supported `timeoutMs` and `AbortSignal`; what was missing was the wiring, and all three pieces are now in place: (1) a `timeoutMs` argument (clamped to 1000-600000, defaulting to `commandTimeoutMs`) whose timeout message prints the value ACTUALLY APPLIED rather than the config value; (2) `exec.signal` is forwarded, so pressing "stop" really SIGTERMs the remote process and returns at once instead of waiting out the timeout; (3) `run_in_background: true` returns a job id immediately (read with the existing `job_output`, stop with `job_kill`), and a command that outlives its timeout is PROMOTED to a background job instead of being killed (`promoteOnTimeout`, on by default). Background execution and promotion need the core `jobs` service; a composition without it (minimal embedding, test double) degrades to foreground-only execution — the 0.8.52 behaviour — rather than failing to load.
289
+ Quick answers first — the long root-cause stories moved to [docs/troubleshooting.en.md](docs/troubleshooting.en.md):
392
290
 
393
- **The terminal in a remote Session is still the local one** (issue #55) — that is **by design, and a plugin cannot change it**, but there is an equivalent: DSH's sidebar terminal is core, its PTY comes from the **context-global** `subprocess` service, and its cwd is the Session's own workspace directory (the local mirror for a remote Session). A plugin can neither replace that service nor retarget the core terminal onto SSH. For a **genuine remote terminal** use the "Remote DSH Web UI" (above): it opens the **remote machine's own** DSH in this browser, and that interface's terminal runs on the remote host, with no extra configuration. To run a single remote command instead, use `rw_exec` (add `pty: true` for an interactive PTY).
291
+ - **The built-in Files panel shows a LOCAL directory** — that is the mirror working copy (by design);
292
+ the live remote tree lives in the Remote Files tab (auto-opens on remote Sessions since 0.8.82).
293
+ - **Does the remote terminal still ask for the password?** — no: saved passwords are answered through
294
+ the local credential bridge (0.8.81+); OTP codes excepted.
295
+ - **A terminal in a remote Session opens on the remote host** — the shell menu's remote ssh is the
296
+ default shell (0.8.75+; `remoteTerminalDefault: false` opts out).
297
+ - **Host key changed** — `/remote forget-key` (or Settings → machine → trust again).
298
+ - **Authentication failed** — check username/password/key path; encrypted keys need the passphrase;
299
+ OTP needs keyboard-interactive.
300
+ - **Unreachable intranet host** — fill the Jump host field (register the bastion itself first);
301
+ multi-hop chains work (ProxyJump equivalent).
302
+ - **A container as a workspace** — yes; two recipes by whether the container exposes a port, see the manual.
394
303
 
395
- **Host key changed** — `/remote forget-key` (or Settings → machine → trust again).
396
-
397
- **"Authentication failed"** — check the username/password/key path; fill in the passphrase for an encrypted key; enable keyboard-interactive when the host requires OTP.
398
-
399
- **Cannot reach an internal machine** — set a jump host (or add the bastion as its own machine first).
400
-
401
- **The host only allows GSSAPI/Kerberos (`ssh` works after `kinit`, the plugin does not)** — in Settings → 远程工作区 → Advanced, switch **Backend** to `openssh` (drive the local `ssh`) and tick "use a ~/.ssh/config alias", with Host set to the **alias** in `~/.ssh/config` (not the IP). The login is then performed by your local ssh with your Kerberos ticket, and `ProxyCommand`, `GSSAPIAuthentication` etc. all apply per `~/.ssh/config` — **one source of truth for the configuration** (issues #50/#51). Command-line equivalent: `rw_connect(host="<alias>", useSshConfig=true, backend="openssh")`.
402
-
403
- **Can a docker container on the remote host be the workspace?** (issue #56) — Yes, and **no plugin change is needed**. There is no container-specific code anywhere in the plugin, yet the two configurations below already cover the request. Pick by whether the container **publishes a port**:
404
-
405
- - **A: the container maps its sshd** (e.g. `docker run -p 127.0.0.1:2222:22 …`) — a plain "jump host" configuration: Host `127.0.0.1`, Port `2222`, the container's user/key, and the **remote host** as the jump host. Why the files really land in the container: `proxy` means "connect to `<host>:<port>` **as resolved by the bastion**" (`lib/pool.js`: `pclient.forwardOut(...this.config.host, this.config.port...)`), and the resulting channel becomes the main connection's own transport (`opts.sock`), so SFTP rides the **container's** sshd — `rw_list_dir`/`rw_read_file`/`rw_write_file`/`rw_sync` all read and write container files. Command-line equivalent: `rw_connect(host="127.0.0.1", port=2222, username="<container user>", privateKeyPath="<key>")`. Requires `AllowTcpForwarding` on the remote sshd (the default).
406
- - **B: the container publishes nothing** — pure `~/.ssh/config` plus the system-OpenSSH backend, on **your** machine:
407
-
408
- ```sshconfig
409
- Host devbox
410
- HostName devbox.invalid
411
- User dev
412
- IdentityFile ~/.ssh/id_ed25519
413
- ProxyCommand ssh <remote-host> docker exec -i <container> sh -c 'exec socat - TCP:127.0.0.1:22'
414
- ```
415
-
416
- then `rw_connect(host="devbox", useSshConfig=true, backend="openssh")`. Why **both** commands and file operations reach the container: the `openssh` backend hands the alias to `ssh` verbatim and deliberately never emits its own `ProxyCommand` (`lib/openssh.js` omits it so that `~/.ssh/config` decides), while `ssh -s <dest> sftp` and `ssh -- <dest> <cmd>` travel the same stream. Requires an sshd inside the container plus `socat` (or an `nc` that speaks stdio).
417
- ⚠️ **A Windows caveat**: POSIX OpenSSH shell-expands `ProxyCommand`, but **Windows' own OpenSSH 9.5 does not** (measured: it passes the whole string through as literal argv). So on a Windows host either keep the `ProxyCommand` a single command with no shell metacharacters, or point "ssh path" at Git Bash's `ssh.exe`. (Also: whether `docker exec -i` carries binary data byte-for-byte is unverified here — no docker on this machine — so try a small file with B first.)
418
-
419
- **`rw_sync`/`rw_push` reports conflicts** — files changed on both sides are skipped and listed (never silently overwritten); merge manually and retry, or pass `force=true`.
420
-
421
- **Windows remotes** — everything goes over SFTP, no POSIX shell needed; read Chinese files with `encoding=gbk`.
422
-
423
- **A directory is missing from the mirror** — the default ignore rules skip `.git`/`node_modules` and similar; adjust `$DSH_HOME/remote-workspaces/.dsh-remote-ignore` (gitignore syntax).
424
-
425
- **Saving a remote file returns 409** — the remote file changed after you opened it; re-read and edit again.
426
-
427
- **How are passwords stored?** — tick "encrypt password": macOS Keychain / Windows DPAPI / Linux secret-tool (libsecret); falls back to plaintext when unavailable.
428
-
429
- **Why is the password box empty (where are the stars)?** — No secret is ever sent back to the browser, so the input stays empty; when a password IS saved its placeholder reads
430
- `•••••••• (saved — leave blank to keep)` with a hint underneath. Saving with an empty box keeps the stored password; typing a new value replaces it. Same for the private-key
431
- passphrase and the jump-host password. The password badge in the machine row means exactly this (a keychain-stored password counts as saved).
432
-
433
- **Which password does "Test connection" use?** — The form in front of you, but a blank password / key / passphrase **falls back to the value saved for that machine**, so
434
- "edit a machine that already connects → click test" now works (the success line says the saved password was used). After saving, the form stays bound to that machine so you can
435
- test immediately; press "Cancel edit" to start over.
436
-
437
- **"No credentials" even though you filled it in** — the password never actually landed on disk: when "encrypt password" is ticked and the OS store is unavailable the plugin
438
- **refuses** to write plaintext and reports a warning (`credentialFallback` defaults to `refuse`). Look for the red warning after saving, fix the store and save again, or use
439
- "Test connection" to verify on the spot. A machine with no password / key / agent is flagged in amber right inside the form.
440
-
441
- **"SSH agent unavailable"** — the machine has "use SSH agent" ticked but the DSH host process has no `SSH_AUTH_SOCK` (Windows has no agent service by default). Start an agent
442
- (and export `SSH_AUTH_SOCK`, or use Pageant) before launching DSH — or untick it and save a password / private key instead.
443
-
444
- **The plugin vanished after a DSH upgrade** — DSH's compatibility check dropped the bundle; upgrade to **0.8.29+** (see "DSH version compatibility" above).
445
-
446
- **"Remote DSH Web UI" will not connect / spins forever** — first check that `dsh web` starts on that
447
- machine *at all*. Two known traps (the plugin names them in its error):
448
- 1. **dsh 0.1.0-rc.6 cannot start the web surface on Linux** — the `node-pty@1.1.0` it depends on ships
449
- macOS/Windows prebuilds but **no `linux-x64`**, so it fails with `Failed to load native module:
450
- pty.node`. Upgrade to 0.1.5-rc.2+ (its `node-pty@1.2.0-beta.15` ships the Linux build).
451
- 2. **dsh 0.1.0-rc.6 does not know `--no-open`** (the flag came later); the plugin drops it and retries
452
- once automatically, so there is nothing to do.
453
- If the remote `dsh` is not on the SSH login PATH (a private prefix, say), point `webAttachCommand` at
454
- its absolute path.
304
+ The full troubleshooting handbook: **[docs/troubleshooting.en.md](docs/troubleshooting.en.md)**
305
+ (including the "remote DSH UI won't connect" chapter).
455
306
 
456
307
  ## Safety
457
308
 
@@ -461,11 +312,45 @@ Giving the plugin a machine's credentials lets the agent run **shell commands as
461
312
 
462
313
  MIT
463
314
 
464
- ## Contributing
315
+ ## Contributing & credits
465
316
 
466
317
  Contributions are welcome — see [CONTRIBUTING.md](./CONTRIBUTING.md). Questions, setups and "is this supported?" go to [Discussions](https://github.com/flymysql/dsh-remote/discussions); reproducible bugs go to [Issues](https://github.com/flymysql/dsh-remote/issues).
467
318
 
468
- Thanks to everyone who has landed a change here (merged PRs in parentheses):
319
+
320
+ Thanks to everyone who makes this project better (avatars link to profiles; bots excluded):
321
+
322
+ <p align="left">
323
+ <a href="https://github.com/flymysql"><img src="https://avatars.githubusercontent.com/u/37113068?s=80&v=4" width="40" height="40" alt="@flymysql" title="@flymysql" /></a>
324
+ <a href="https://github.com/baiseraku"><img src="https://avatars.githubusercontent.com/u/139727690?s=80&v=4" width="40" height="40" alt="@baiseraku" title="@baiseraku" /></a>
325
+ <a href="https://github.com/glzhangzhi"><img src="https://avatars.githubusercontent.com/u/36995275?s=80&v=4" width="40" height="40" alt="@glzhangzhi" title="@glzhangzhi" /></a>
326
+ <a href="https://github.com/hjwsm1989"><img src="https://avatars.githubusercontent.com/u/1067541?s=80&v=4" width="40" height="40" alt="@hjwsm1989" title="@hjwsm1989" /></a>
327
+ <a href="https://github.com/j10ha0"><img src="https://avatars.githubusercontent.com/u/72346906?s=80&v=4" width="40" height="40" alt="@j10ha0" title="@j10ha0" /></a>
328
+ <a href="https://github.com/FoolishWiser"><img src="https://avatars.githubusercontent.com/u/104308087?s=80&v=4" width="40" height="40" alt="@FoolishWiser" title="@FoolishWiser" /></a>
329
+ <a href="https://github.com/kakaa-nju"><img src="https://avatars.githubusercontent.com/u/79886619?s=80&v=4" width="40" height="40" alt="@kakaa-nju" title="@kakaa-nju" /></a>
330
+ <a href="https://github.com/4FMTWRV"><img src="https://avatars.githubusercontent.com/u/190457700?s=80&v=4" width="40" height="40" alt="@4FMTWRV" title="@4FMTWRV" /></a>
331
+ <a href="https://github.com/dahaipeng"><img src="https://avatars.githubusercontent.com/u/25660610?s=80&v=4" width="40" height="40" alt="@dahaipeng" title="@dahaipeng" /></a>
332
+ <a href="https://github.com/davidlin2k"><img src="https://avatars.githubusercontent.com/u/17074619?s=80&v=4" width="40" height="40" alt="@davidlin2k" title="@davidlin2k" /></a>
333
+ <a href="https://github.com/FlintyLemming"><img src="https://avatars.githubusercontent.com/u/19165511?s=80&v=4" width="40" height="40" alt="@FlintyLemming" title="@FlintyLemming" /></a>
334
+ <a href="https://github.com/GDWhisper"><img src="https://avatars.githubusercontent.com/u/129148123?s=80&v=4" width="40" height="40" alt="@GDWhisper" title="@GDWhisper" /></a>
335
+ <a href="https://github.com/YiHui-Liu"><img src="https://avatars.githubusercontent.com/u/30190271?s=80&v=4" width="40" height="40" alt="@YiHui-Liu" title="@YiHui-Liu" /></a>
336
+ <a href="https://github.com/Minggle"><img src="https://avatars.githubusercontent.com/u/35053182?s=80&v=4" width="40" height="40" alt="@Minggle" title="@Minggle" /></a>
337
+ <a href="https://github.com/nekomona"><img src="https://avatars.githubusercontent.com/u/25474483?s=80&v=4" width="40" height="40" alt="@nekomona" title="@nekomona" /></a>
338
+ <a href="https://github.com/shis23"><img src="https://avatars.githubusercontent.com/u/189869650?s=80&v=4" width="40" height="40" alt="@shis23" title="@shis23" /></a>
339
+ </p>
340
+
341
+ Recent highlight contributions (there is always room on this list):
342
+
343
+ | Contributor | What they did |
344
+ | --- | --- |
345
+ | [@baiseraku](https://github.com/baiseraku) | the whole dsh-tui adaptation layer ([#92](https://github.com/flymysql/dsh-remote/pull/92)) + the status-bar fix ([#98](https://github.com/flymysql/dsh-remote/pull/98)) |
346
+ | [@hjwsm1989](https://github.com/hjwsm1989) | both remote-.md renderer fixes: the memo guard ([#102](https://github.com/flymysql/dsh-remote/pull/102)) and the labels contract ([#107](https://github.com/flymysql/dsh-remote/pull/107)) |
347
+ | [@shis23](https://github.com/shis23) | rw_sync path-mapping fix + SFTP timeout resilience ([#105](https://github.com/flymysql/dsh-remote/pull/105)) |
348
+ | [@davidlin2k](https://github.com/davidlin2k) | dialing credential-less machines through the user's own ssh ([#100](https://github.com/flymysql/dsh-remote/pull/100)) |
349
+ | [@GDWhisper](https://github.com/GDWhisper) | the per-keystroke completion reconnect fix ([#42](https://github.com/flymysql/dsh-remote/pull/42), issue #41) |
350
+ | [@glzhangzhi](https://github.com/glzhangzhi) | the per-session SSH pool isolation behind issue #25 |
351
+
352
+ The older hand-kept roll of merged PRs (with their numbers):
353
+
469
354
 
470
355
  [@dahaipeng](https://github.com/dahaipeng) (#31) ·
471
356
  [@YiHui-Liu](https://github.com/YiHui-Liu) (#28) ·
@@ -476,6 +361,9 @@ Thanks to everyone who has landed a change here (merged PRs in parentheses):
476
361
  [4FMTWRV](https://github.com/4FMTWRV) (#6) ·
477
362
  [glzhangzhi](https://github.com/glzhangzhi) (per-session SSH pool fix)
478
363
 
364
+ > The wall updates with releases; a well-written issue report, a repro, or a root-cause lead
365
+ > is worth as much as a patch — about half of this repo's fixes started as a clear issue.
366
+
479
367
  ## Changelog
480
368
 
481
369
  See [CHANGELOG.md](./CHANGELOG.md).
package/README.md CHANGED
@@ -48,6 +48,8 @@ DSH 的 Web 界面刻意只监听 `127.0.0.1`(CLI 为安全拒绝 `--host 0.0.
48
48
 
49
49
  - **21 个模型工具**(便于复制/检索):`rw_info`、`rw_connect`、`rw_machines`、`rw_pick_workspace`、`rw_list_dir`、`rw_stat`、`rw_read_file`、`rw_write_file`、`rw_edit`、`rw_append`、`rw_mkdir`、`rw_remove`、`rw_move`、`rw_exec`、`rw_search`、`rw_download`、`rw_upload`、`rw_sync`、`rw_push`、`rw_forward`、`rw_disconnect`。
50
50
  - **会话列表里区分本地/远程**(`0.8.43+`)—— 远程会话的行首有一个**绿点**,悬停显示 `user@host:port` 与远端路径;打开该会话后,标题栏还会常显一个主机标签(本地会话两者都没有)。判定只看会话 cwd 是否落在 `$DSH_HOME/remote-workspaces/…` 镜像里,所以「保存过但没在用」的机器不会给本地会话打标。
51
+ - **远程会话的终端开箱即在远端**(`0.8.75+`)—— 侧栏终端的 shell 菜单里有插件贡献的 **remote ssh**:按 cwd 智能路由(远程镜像 → `ssh` 进远端工作目录;本地会话 → 自动回落本地 shell),在没人占位时它还是**默认 shell**。已保存的密码由本机凭据桥自动应答(`0.8.81+`,含操作系统钥匙串里的),不会再每次开终端都问一遍 `password:`。
52
+ - **远程文件预览带行号与语法高亮**(`0.8.86+`)—— 代码文件用宿主自家的 Shiki 引擎着色;AI 回答里的 `文件:行号`(或 `#L行号`)链接点开直接落到那一行并闪烁提示。
51
53
  - **把远端机器的 DSH 界面挂到本机**(`0.8.36+`)—— 不用在远端开任何端口:插件主动 SSH 连过去,在远端**只监听 `127.0.0.1`** 地起一个 `dsh web`,再把端口经隧道搬回本机的一个 loopback 端口。地址带一次性登录令牌,只在本机这次跳转里用一次。
52
54
  - **审计日志可以在本机直接打开** —— 面板里预览最近条目,另有「打开日志文件」「在文件夹中显示」直接调用本机程序打开那个日志(日志在运行 DSH 的机器上,浏览器打不开它)。
53
55
  - **远端跨平台** —— 文件访问走 SFTP 协议层(不依赖 POSIX shell),Linux/macOS/Windows 远端都能列/读/写/搜索/同步。
@@ -134,80 +136,25 @@ dsh plugin add dsh-remote
134
136
  更旧的 node 上 npm 只会给 EBADENGINE 警告、照样把包装完,直到启动才崩在
135
137
  `does not provide an export named 'parseEnv'`,所以装之前先确认版本。
136
138
 
137
- ### 连不上?远端的 dsh 需要你自己装好
138
-
139
- **连不上大多不是插件的问题,而是远端 dsh 的版本或环境不对。** 最典型的一种:dsh 0.1.0-rc.6
140
- 依赖 `node-pty@1.1.0`,而**那个版本发布的包里没有 `linux-x64` 预编译产物** ⇒ `dsh web`
141
- 在 Linux 上根本起不来。这种情况以前只能看到「没拿到启动令牌」,无从判断。
142
-
143
- 远端如果没有可用的 `dsh`,需要你自己先装好(插件不再代装):把 `webAttachCommand`
144
- 指向它的绝对路径即可(设置 → 远程工作区 → 机器行「编辑」→ 高级配置 → 远端 dsh 命令,
145
- 或全局 `webAttachCommand`)。
146
-
147
139
  ## 在 TUI(dsh-tui)里使用
148
140
 
149
141
  插件自带 TUI 适配层:装进 `dsh-tui` profile 后,同一份机器清单、SSH 池和远程工作区在
150
142
  终端界面里也能用,**不修改 dsh-tui 本体**(全部通过它的插件接缝注册)。
151
143
 
152
- ### 安装
153
-
154
144
  ```bash
155
145
  # 已装好 dsh-tui 的机器只需这一条;本地开发可直接给绝对路径
156
146
  dsh plugin --profile dsh-tui add dsh-remote
157
147
  # 或:dsh plugin --profile dsh-tui add /path/to/dsh-remote
158
148
  ```
159
149
 
160
- 装完重启 dsh-tui 生效。Web profile 不受影响:TUI 层在缺少终端接缝时静默关闭,不注册任何东西。
161
-
162
- ### `/dsh-remote` —— 终端里的远程服务器设置页
163
-
164
- 输入 `/dsh-remote` 打开全屏设置页(命令同时出现在 `/` 补全与 `/help` 里):
165
-
166
- - `↑/↓` 选机器,`Enter` 打开动作菜单;`a` 新增、`e` 编辑、`d` 删除、`t` 测试连接、
167
- `c` 连接、`b` 浏览远端目录、`o` 打开本机镜像目录、`Esc`/`q` 关闭
168
- (子视图里先返回列表;动作菜单里按 `m` 管理工作区)。
169
- - 新增/编辑:名称、主机、端口、用户名、认证方式(密码 / 私钥 / SSH agent)、密码或私钥路径、
170
- 分组。密码**只写不回显**,编辑时留空表示不修改。
171
- - `b` 浏览远端目录,按 `w` 把当前目录**设为工作区**:自动建本地镜像、注册成 DSH 工作区
172
- (标题形如 `机器名-目录名`),并按配置切换过去。
173
- - `o` 用系统默认文件管理器打开本机镜像根目录 `$DSH_HOME/remote-workspaces`
174
- (每台机器的镜像按 `<host>-<user>-<port>` 分目录存放;该目录也含 `machines.json`
175
- 等插件数据,`credentialFallback: plain` 时可能含明文密码,仅在本机可见)。
176
-
177
- ### 新建工作区时直接选远程目录
150
+ 装完重启 dsh-tui 生效。装好之后你会得到:
178
151
 
179
- - `/workspace` 的选择器里除了本地目录,还会列出每台机器的最近远程项目(徽标是机器名,
180
- 说明是 `user@host:/远端路径`)。选中即在新会话里打开该远程工作区。
181
- - 也可以直接给 URI:`/workspace open dshremote://<机器名或 id>/<URL 编码的远端绝对路径>`。
182
- - 启动参数同样支持:`dst dshremote://<机器>/<远端路径>`。
183
- - 列出的条目数量由下面的配置控制。
152
+ - `/dsh-remote` 全屏服务器管理页(增删改 / 连接 / 探测 / 浏览远端目录 / 设为工作区 / 清理);
153
+ - `/workspace` 选择器里直接列远程项目(或用 `dshremote://<机器>/<远端路径>` 直达);
154
+ - 底栏状态行显示当前远程机器(仅远程会话,悬停有详情)。
184
155
 
185
- ### 工作区清理(彻底删除工作区或其中对话)
186
-
187
- `/dsh-remote` → 选中机器 → `m`(工作区管理)列出该机器全部本地镜像:
188
-
189
- - `d`:**彻底删除该工作区** —— 依次删除它的全部对话、工作区登记、每台机器「最近工作区」
190
- 里的该远端路径,最后删掉本地镜像目录
191
- `$DSH_HOME/remote-workspaces/<host>-<user>-<port>/<name>`。删最近项是必须的,
192
- 否则 provider 下次启动会按它把镜像重建回来。
193
- - `x`:只删该工作区下的对话(保留镜像与登记);被占用的会话会跳过并在提示里报数。
194
- - `r`:只把远端路径移出「最近列表 / 当前工作区」(不删镜像、不删对话),用来止住自动重建。
195
- - 仍有会话在使用该工作区时 `d` 会被拒绝(先 `Ctrl+X` 停止后台会话,或退出对应终端);
196
- 删除不可恢复,且**不会**动远端目录(远端文件仍由你自己管理)。
197
-
198
- ### 配置
199
-
200
- TUI 适配层的五个开关与其它配置项一样写在 `cordis.patch.yml` 的同一行里,见下文
201
- [配置](#配置) 表的最后五行(`tui` / `tuiProviderListRecent` / `tuiProviderRecentLimit` /
202
- `tuiAutoSwitchWorkspace` / `tuiLang`)。
203
-
204
- ### 说明
205
-
206
- - 远程项目在终端里以**本地镜像目录**呈现:那才是会话 cwd,也是 `rw_*` 工具工作的地方;
207
- 远端路径只出现在标题/描述里。远程身份由镜像里的 `.dsh-remote-meta.json` 决定。
208
- - 工作区 provider 是 dsh-tui 较新的接缝:旧版 dsh-tui(或没挂载该服务的 profile)上,
209
- `/dsh-remote` 页面与工作区台账仍然可用,只是选择器里不会出现远程项目。
210
- - 设计与宿主 API 契约见 [docs/tui.md](docs/tui.md)。
156
+ Web profile 不受影响:TUI 层在缺少终端接缝时静默关闭。按键速查、三档清理语义、宿主 API
157
+ 契约与限制都在 **[docs/tui.md](docs/tui.md)**。
211
158
 
212
159
  ## 可选:CLI 默认机
213
160
 
@@ -326,203 +273,68 @@ scripts/dev-run.sh --status # 是否在运行
326
273
 
327
274
  ## 常见问题 / 排查
328
275
 
329
- **`@` 能列出远程文件,但内置读文件工具打不开** —— harness 自带工具看到的是**本地镜像**,要等 `rw_sync` 下载后才有内容。读远程文件请用 `rw_read_file` 或侧栏远程文件 tab。
330
-
331
- **远程会话里的文件链接打不开**(issue #55)—— 已修。链接被点开时 harness 会把它变成
332
- `dsh-resource://file/session/<会话>/<路径>`,然后交给内置的文本预览去读;而那个预览读的是**本机**
333
- 文件系统,远程会话的 cwd 是**本地镜像目录**(`rw_sync` 之前是空的),所以打开只会失败。
334
- 插件现在注册了一个更高优先级的地址处理器,把这个地址按远程主机解析后用 SFTP 打开(和侧栏「远程文件」同一个编辑器)。
335
- 安全边界是保守的:只有当该会话的 cwd **确实落在某个镜像目录里**、且镜像表已加载时才接管,
336
- 本地会话与页面刚加载的那一瞬间仍然走内置预览 —— 不会把本地文件误当成远程文件。
337
- 两个仍然开不了的情况会给出明确提示而不是空白页:链接指向的是**绝对**远端路径之外无法映射的地址,
338
- 或该会话的工作区不是一个远程镜像目录。
339
- 远程会话里的 `.md`/`.markdown` 同样走这条 SFTP 链路并在标签里预览(issue #74)。以前为了保住内置 Markdown 渲染把它们交回去(issue #64),但那个预览读的是本地镜像,文件还没 `rw_sync` 时就是 `ENOENT`。现在预览的是远端内容,用宿主自带的 Markdown 渲染;宿主没有该组件时才显示源码。本地会话仍然走内置预览。图片在侧栏远程文件树里直接内联显示 png/jpg/gif/webp/svg/bmp(issue #66,>2MB 退回下载按钮)。
340
-
341
- **SFTP 操作一旦超时就永远卡死**(issue #65)—— 已修(0.8.52+)。旧版里一次撞满 20s 超时的 SFTP 操作会把
342
- 该机器在本进程内的全部 SFTP 工具拖到永久超时(`rw_exec` 却正常),只能断连重连。现在超时即置死该通道、
343
- 后续请求立即失败;native 后端连续两次超时会废弃整条连接重新握手,openssh 后端会重建 sftp 子进程——
344
- 一次网络抖动不再需要用「断开重连」来收场。顺带,`rw_edit` 改成了「临时文件 + rename」原子写,
345
- 写一半超时不会再把远端文件截成 0 字节,原文件的权限位也会保留。
346
-
347
- **远程操作受不受本机 sandbox 约束?**(0.8.54+)—— 受。以前不受:本机会话有 `ctx.sandboxPolicy`
348
- (read-only / workspace-write / danger-full-access),而 `rw_*` 工具在远端执行**完全没有策略**,
349
- 于是一个 read-only 会话照样能改任意一台可达机器上的任意文件——沙箱没有被绕过,它对另一台机器根本
350
- 没有发言权。现在插件在**工具边界**套用同一套已解析的模式:
351
-
352
- - `read-only`:拒绝远端写入、拒绝跑命令、拒绝开端口转发(读和连接仍可用,否则连机器都看不了);
353
- - `workspace-write`:远端写入必须落在工作区根之内(按路径围栏),命令与转发放行;
354
- - `danger-full-access`:全放行。
355
-
356
- 为什么是工具层围栏而不是 `ctx.sandbox.confine()`:后者的语义是「把 argv 包起来在**本机** spawn」,
357
- 而我们的进程跑在 SSH 通道的另一端——核心文档自己也写明「远端执行会**替换**周边 capability seam」。
358
- 所以拒绝时抛出的是**官方同形状**的 `FS_SANDBOX_DENIED`(带 `[sandbox: …]` 与升级提示),模型的
359
- 升级重试路径不受影响。
360
-
361
- **威胁模型要讲清楚**:这是**遏制,不是安全边界**(与官方 `dsh-fs-sandbox` 文件头的口径一致)。
362
- 路径按字典比较,远端机上的符号链接与 TOCTOU 可以绕过;一旦 bash 跑起来,它用的是该用户自己的权限。
363
- 它真正买到的,是「受限会话不会**误**改工作区外的远端文件,且 read-only 会话不会偷偷跑命令」。
364
- 需要硬边界的部署,请在**远端那一侧**做(容器、按用户隔离、文件系统 ACL)。
365
- 不想用可设 `remoteSandbox: 'off'`(或 `'inherit'` 之外的值显式指定某一模式)。
366
-
367
- **密钥库写不进去时,密码会明文落盘吗?**(0.8.54+)—— 默认**不会**。以前系统密钥库失败
368
- (keychain 锁着 / 缺 secret-tool / Windows DPAPI 缺程序集)会**回退明文**写进 `machines.json` 并
369
- 给个警告——你本来要的是加密,结果反而更不安全,而「密钥库正好坏了」恰恰是最不容易注意到的时候。
370
- 现在默认 `credentialFallback: 'refuse'`:**不保存**该密码,机器照常保存但没有凭据,界面明确报出
371
- 密钥库失败原因。想要旧行为(宁可明文也要能连)就设 `credentialFallback: 'plain'`。
372
- 主动关掉加密(`backend: 'plain'`)不受影响,那本来就是明文。
373
-
374
- **机器多了怎么不选错?**(0.8.54+)—— 给机器打**分组标签**:`environment`(prod/staging…)、
375
- `location`(shanghai/gpu-lab…)、`description`、`tags`(一组自由标签)。它们纯粹是标签,不改变任何
376
- 连接行为。`rw_machines` 支持按这些维度筛选(维度之间 AND,标签之间 OR):
377
- `rw_machines(environment="prod", tags="gpu")`。筛不到时会列出**当前有哪些分组**,省得你猜标签拼法。
378
- 设置页同样可以编辑。机器一多,「选对机器」就从记性变成了筛选。
379
-
380
- **多级跳板机怎么办?**(0.8.54+)—— 支持**多跳链路**(等价 OpenSSH 的 `ProxyJump a,b,c`):
381
- 跳板机自己也可以带 `proxy`,链路从**最远一跳**往里建,每一跳都通过上一跳已建立的连接拨号。
382
- 两个关键约束:**凭据不跨跳继承**(绝不把目标机的私钥递给中间机——既通常没被授权,也等于把不该给的
383
- 秘密给了它);链路深度超过 8 跳会明确报错,用来把**配置成环**变成一条清晰的错误,而不是无限递归。
384
- 每一跳可以自带 `privateKeyPath` / `useAgent` / `hostKeyMode`,没写就沿用操作者自己的 ssh 环境。
385
-
386
- **能在 DSH 里直接开一个远端终端吗?**(0.8.54+)—— 能,**内嵌 PTY 终端**。`rw_exec` 是「跑一条命令
387
- 就关」,没有 PTY、stdin 也回不去,所以 `vim`、`top`、`sudo` 提示符、全屏 TUI 都用不了。
388
- 现在 `pool.shell()` 打开一条**持久的 PTY 通道**,终端会话归宿主所有:关掉浏览器不会杀掉远端 shell
389
- (写了一半的 vim 能活过刷新),每个会话有 30 分钟空闲回收、进程内最多 8 个(免得打爆远端
390
- `MaxSessions`),插件卸载时全部挂断。
391
-
392
- 传输方式刻意做得很朴素:远端会话在**宿主**,浏览器**轮询**输出增量(输入是单独请求、立即写入,
393
- 所以打字从不排队等轮询)。这样不依赖宿主是否暴露 WebSocket 升级路径。路由是
394
- `/dsh-remote/term/{open,input,output,resize,close,list}`,每个都先按**会话**解析绑定——
395
- 开在 A 机的终端,绑到 B 机的请求既看不到也驱动不了。
396
-
397
- **机器换了 IP / 用户名,工作区要全部重建吗?**(issue #67)—— 不用(0.8.52+)。在设置页编辑该机器的新
398
- 地址并保存,或 `rw_connect(machineId=…, host=…, username=…, port=…)` 同传新地址:该机器名下所有工作区
399
- 镜像会**原地重绑**(改写镜像的 `.dsh-remote-meta.json`),本地内容保留、无需重新同步,保存后会提示重绑了
400
- 几个镜像。镜像目录名不会跟着改(活 session 的 cwd 在其中),目录名只是显示标签、不影响连接。
401
-
402
- **远程会话看不到工作区的 AGENTS.md**(issue #68)—— 已修(0.8.52+)。核心的指令加载只认本地文件系统,
403
- 而远程会话的 cwd 是本地镜像,远端仓库的 AGENTS.md 以前永远进不了模型上下文。现在 `rw_pick_workspace`
404
- 成功时会对远程工作区做浅扫(根 + 向下 ≤2 层,只匹配 `AGENTS.md`/`CLAUDE.md`),把命中的文件按三向安全
405
- 规则同步进本地镜像(根级文件由此进入核心自己的注入链路,与本地会话一致),并把路径+标题索引渲染进
406
- system prompt,提示模型编辑前用 `rw_read_file` 阅读嵌套层的指令。全树递归扫描与插件侧全文注入都**刻意
407
- 不做**(前者会扫穿多项目根目录,后者会与核心的注入管线并行打架)。
408
-
409
- **读了远程子目录的文件,子目录里的 AGENTS.md 会自动进上下文吗?**(issue #71)—— 会(0.8.53+)。
410
- #68 只修了静态部分(工作区浅扫 + 索引行);动态部分当时还断着,原因是核心的增量注入只认
411
- `read`/`write`/`edit` 且只认 `file_path` 参数,而 `rw_read_file` 名字和参数都对不上,且它做作用域
412
- 扩展时用的是**本地**路径——远程绝对路径映射不到镜像 cwd,三个断点任一都足以让注入永不发生。
413
- 现在插件自己在 `tools/result` 里接 `rw_*` 文件触碰,取「被访问目录 → 工作区根」的**整条目录链**
414
- (不是最近一层,与本地会话一致:读 `a/b/c.ts` 会同时收 `a/AGENTS.md` 和 `a/b/AGENTS.md`),逐层
415
- `stat` 后把当前内容合成**一条** user message 注入。几个关键边界:cwd 自己那层不重扫(核心 baseline
416
- 已覆盖,所以读工作区根下的文件不触发任何额外扫描);按内容摘要 per-session 去重,同内容只注入一次;
417
- 远端修改后下次触碰即重新注入;注入过的文件被删除会发一条「已移除」提示;单次注入有 16 KB 预算;
418
- 机器离线时整条链路静默降级,既不挂工具调用也不挂 prompt 组装。注入消息用插件自己的
419
- `source.kind`(`dsh-remote-instructions`),核心的状态机只认领它自己的 `agent-instructions`,两条
420
- 注入路径不会互相打架。
421
-
422
- **`rw_exec` 能像内置 shell 那样自定义超时/取消/转后台吗?**(issue #70)—— 能(0.8.53+)。
423
- 底层 `pool.exec` 本来就支持 `timeoutMs` 与 `AbortSignal`,缺的是接线,现在补齐三件事:
424
- ① `timeoutMs` 参数(clamp 到 1000–600000,缺省仍用 `commandTimeoutMs`,超时文案打印**实际生效**的值,
425
- 不会印错成配置值);② `exec.signal` 透传给 `pool.exec`——点「停止」会真的 SIGTERM 掉远端进程并立即
426
- 返回,不用再等满超时;③ `run_in_background: true` 立即返回 job id(用现成的 `job_output` 读、
427
- `job_kill` 停),以及超时**转后台**而非直接杀(`promoteOnTimeout`,默认开)。后台/转后台依赖核心的
428
- `jobs` 服务;没有该服务的组合(最小嵌入、测试替身)自动退化为只有前台执行——即 0.8.52 的行为,
429
- 不会因此加载失败。
430
-
431
- **远程会话里的终端还是本机的**(issue #55)—— 已解决(0.8.75+),什么都不用点。
432
- 侧栏终端的 shell 菜单里一直有插件贡献的 **remote ssh**:那是一个按 cwd 智能路由的启动器——
433
- 会话落在远程镜像里就 `ssh` 进远端工作目录,否则自动回落成本地 shell。0.8.75 起它进一步成为
434
- **默认 shell**:只要宿主没另外配置默认终端、你也没在 shell 菜单里手动选过别的,点「打开终端」
435
- 在远程会话里就直接落进远端(本地会话照旧开本地终端,启动器会替你分流)。两个保险:菜单里手动
436
- 选过其他 shell 的话你的选择永远优先;想回到纯手动就在配置里设 `remoteTerminalDefault: false`
437
- (remote ssh 仍会留在菜单里)。想要更重度的方案还有**「远程 DSH 界面」**(见上文):本机浏览器里
438
- 打开**远端机器自己**的 DSH,那里的终端原生跑在远端。只想偶尔跑一条远程命令用 `rw_exec`
439
- (要交互式 PTY 就加 `pty: true`)。
440
-
441
- **主机指纹变了** —— `/remote forget-key`(或设置页 → 机器 → 重新信任)。
442
-
443
- **连接报「认证失败」** —— 检查用户名/密码/私钥路径;加密私钥要填 Passphrase;需要动态码时勾选 keyboard-interactive。
444
-
445
- **连不上内网机器** —— 填「跳板机」主机(也可先把跳板机本身配成一台机器)。
446
-
447
- **能不能拿远程主机上的 docker 容器当工作空间?**(issue #56)—— 能,**不需要改插件**;
448
- 插件对容器没有任何专门代码,但下面两条既有配置已经完整覆盖这个需求。请按容器**有没有对外暴露端口**二选一:
449
-
450
- - **A:容器把 sshd 端口映射出来了**(例如 `docker run -p 127.0.0.1:2222:22 …`)—— 纯「跳板机」配置:
451
- Host 填 `127.0.0.1`、Port 填 `2222`、用户/私钥填容器里的,再把「跳板机」主机填**那台远程主机**。
452
- 为什么这样文件就能落到容器里:`proxy` 的语义是「**在跳板机上**连 `<host>:<port>`」
453
- (`lib/pool.js` 的 `pclient.forwardOut(...this.config.host, this.config.port...)`),
454
- 拿到的通道会被当成主连接自己的 transport(`opts.sock`),于是 SFTP 走的是**容器自己的 sshd** ⇒
455
- `rw_list_dir`/`rw_read_file`/`rw_write_file`/`rw_sync` 全部读写的都是容器内的文件。
456
- 命令行等价写法:`rw_connect(host="127.0.0.1", port=2222, username="<容器用户>", privateKeyPath="<私钥>")`。
457
- 要求:远程主机的 sshd 允许转发(`AllowTcpForwarding yes`,默认就是)。
458
- - **B:容器没有暴露端口** —— 纯 `~/.ssh/config` + 系统 OpenSSH 后端,在**本机** `~/.ssh/config` 写:
459
-
460
- ```sshconfig
461
- Host devbox
462
- HostName devbox.invalid
463
- User dev
464
- IdentityFile ~/.ssh/id_ed25519
465
- ProxyCommand ssh <远程主机> docker exec -i <容器名> sh -c 'exec socat - TCP:127.0.0.1:22'
466
- ```
467
-
468
- 然后 `rw_connect(host="devbox", useSshConfig=true, backend="openssh")`。
469
- 为什么 `exec` 和文件操作**都会**进容器:`openssh` 后端把别名原样交给 `ssh`,
470
- 自己**从不**生成 `ProxyCommand`(`lib/openssh.js` 明确不传,就是为了让 `~/.ssh/config` 说了算),
471
- 而 `ssh -s <目标> sftp` 与 `ssh -- <目标> <命令>` 走的是同一条流 ⇒ 两者都穿过这个 ProxyCommand。
472
- 要求:容器里有 sshd,且有 `socat`(或用支持 stdio 的 `nc`)。
473
- ⚠️ **Windows 上有个坑**:POSIX OpenSSH 会把 `ProxyCommand` 交给 shell 展开,**Windows 自带的 OpenSSH 9.5 不会**
474
- (实测它把整串按字面当成 argv)。所以在 Windows 跑本插件时,要么把 `ProxyCommand` 写成
475
- 不含 shell 元字符的单条命令,要么把「ssh 路径」指向 Git Bash 的 `ssh.exe`。
476
- (另:`docker exec -i` 传二进制是否逐字节无损,我这边没有 docker 环境验证过,B 方案建议先用小文件试。)
477
-
478
- **企业机器只允许 GSSAPI/Kerberos(`kinit` 后 `ssh` 能进,插件进不去)** —— 在设置 → 远程工作区 → 高级配置里把「连接后端」改成 **`openssh`**(调用本机 `ssh`),并勾选「使用 ssh_config 别名」,Host 填 `~/.ssh/config` 里那个**别名**(不是 IP)。这样登录由本机 ssh 用你的 Kerberos 票据完成,且 `ProxyCommand`、`GSSAPIAuthentication` 等全部照 `~/.ssh/config` 生效 —— **配置只有 `~/.ssh/config` 一个来源**(issue #50/#51)。命令行等价写法:`rw_connect(host="<别名>", useSshConfig=true, backend="openssh")`。
479
-
480
- **`rw_sync`/`rw_push` 报冲突** —— 两边都改过的文件会被跳过并列出(绝不静默覆盖);手动合并后重试,或用 `force=true` 以一边为准。
481
-
482
- **Windows 远程** —— 全部走 SFTP,不依赖 POSIX shell;中文文件用 `encoding=gbk`。
276
+ 快速自救(每条一行;根因故事与设计权衡的完整版搬到了 [docs/troubleshooting.md](docs/troubleshooting.md)):
483
277
 
484
- **镜像里缺目录** —— 默认 ignore 会跳过 `.git`/`node_modules` 等;在 `$DSH_HOME/remote-workspaces/.dsh-remote-ignore` 调整(gitignore 语法)。
278
+ - **侧边栏「文件」面板显示的是本地目录** —— 那是镜像工作副本(地基如此);看远端实时树用
279
+ 「远程文件」页签(0.8.82 起进入远程会话自动展开,两个右栏世界都算)。
280
+ - **远程终端还要输密码吗?** —— 不用:存过的密码由本机凭据桥自动应答(0.8.81+);OTP 动态码除外。
281
+ - **远程会话的终端开箱即在远端** —— shell 菜单的 remote ssh 是默认终端(0.8.75+,
282
+ `remoteTerminalDefault: false` 可关)。
283
+ - **主机指纹变了** —— `/remote forget-key`(或设置页 → 机器 → 重新信任)。
284
+ - **连接报「认证失败」** —— 检查用户名/密码/私钥路径;加密私钥要填 Passphrase;OTP 勾选 keyboard-interactive。
285
+ - **连不上内网机器** —— 填「跳板机」主机(可把跳板机本身先配成一台机器);多级链路也支持。
286
+ - **想拿容器当工作空间** —— 可以,按容器有没有暴露端口二选一,详见排障手册。
485
287
 
486
- **保存远程文件报 409** —— 打开后远端已被改动,重新读取再编辑。
288
+ 完整排查手册:**[docs/troubleshooting.md](docs/troubleshooting.md)**(含「远程 DSH 界面连不上」专题)。
487
289
 
488
- **密码怎么加密保存** —— 勾选「加密保存密码」:macOS 钥匙串 / Windows DPAPI / Linux secret-tool(libsecret);后端不可用时回退明文。
290
+ ## 安全提醒
489
291
 
490
- **密码框为什么是空的(星号在哪)** —— 出于安全,**任何密码都不会回传到浏览器**,所以输入框永远是空的;已经保存过密码时,输入框的占位符会显示
491
- `••••••••(已保存,留空 = 不修改)`,下方还有一行绿字说明。留空保存 = 沿用已保存的密码,填新值 = 覆盖。passphrase 与跳板机密码同理。
492
- 机器列表里的「密码」标签也是这个含义(钥匙串里的密码同样算已保存)。
292
+ 把凭据交给插件等于允许 Agent 以你的用户身份在该主机执行 **shell 命令**——只添加可信机器。密码存在本机文件(或钥匙串),请当作敏感数据。开启 `auditLog` 时每条命令都会记入审计日志。
493
293
 
494
- **「测试连接」用哪个密码** —— 用你眼前这份表单,但**留空的密码/私钥/passphrase 会自动沿用该机器已保存的值**,所以「编辑一台已经连上的机器 → 直接点测试」是能过的
495
- (成功提示会注明「本次测试使用了已保存的密码」)。保存之后表单会**留在该机器上**,可以立刻点测试验证;想清空重来点「取消编辑」。
294
+ ## License
496
295
 
497
- **报「缺少凭据」但你确信填过** —— 说明保存时密码没有真正落盘:勾了「加密保存密码」而系统钥匙库不可用时,插件会**拒绝**把密码写成明文并给出警告
498
- (`credentialFallback` 默认 `refuse`)。看保存后有没有红色警告,按提示修好钥匙库再存一次,或用「测试连接」当场验证。机器没有密码/私钥/agent 时,编辑表单里会直接标黄提醒。
296
+ MIT
499
297
 
500
- **报「SSH agent 不可用」** —— 该机器勾了「使用 SSH agent」,但 DSH 宿主进程里没有 `SSH_AUTH_SOCK`(Windows 默认没有 agent 服务)。启动 DSH 之前把 agent 跑起来并导出
501
- `SSH_AUTH_SOCK`(或用 Pageant),或者取消勾选、改用密码/私钥。
298
+ ## 参与贡献与致谢
502
299
 
503
- **升级后插件整个不见了** —— DSH 兼容性判定丢弃了 bundle,升到 **0.8.29+** 即可(见上文「DSH 版本兼容性」)。
300
+ 欢迎贡献,请先阅读 [CONTRIBUTING.md](./CONTRIBUTING.md)。使用问题、环境配置、「支持 XX 吗」这类讨论请走 [讨论区](https://github.com/flymysql/dsh-remote/discussions);可复现的缺陷请提 [Issue](https://github.com/flymysql/dsh-remote/issues)。
504
301
 
505
- **「远程 DSH 界面」连不上/一直转圈** —— 先确认那台机器上的 `dsh web` **本身**能起来。
506
- 两个已知坑(插件会在报错里直接点出来):
507
- ① **dsh 0.1.0-rc.6 在 Linux 上无法启动 web**——它依赖的 `node-pty@1.1.0` 只带了
508
- macOS/Windows 的预编译产物,**没有 `linux-x64`**,会报 `Failed to load native module: pty.node`。
509
- 升到 0.1.5-rc.2+ 即可(其 `node-pty@1.2.0-beta.15` 带 Linux 预编译)。
510
- ② **dsh 0.1.0-rc.6 不认识 `--no-open`**(该 flag 是后加的);插件会自动去掉它重试一次,无需你处理。
511
- 如果远端 `dsh` 不在 SSH 登录 PATH 里(例如装在私有前缀),用 `webAttachCommand` 指向它的绝对路径。
512
302
 
513
- ## 安全提醒
303
+ 感谢每一位让这个项目更好的朋友(头像可点进主页;按提交数排序,机器人不计):
514
304
 
515
- 把凭据交给插件等于允许 Agent 以你的用户身份在该主机执行 **shell 命令**——只添加可信机器。密码存在本机文件(或钥匙串),请当作敏感数据。开启 `auditLog` 时每条命令都会记入审计日志。
305
+ <p align="left">
306
+ <a href="https://github.com/flymysql"><img src="https://avatars.githubusercontent.com/u/37113068?s=80&v=4" width="40" height="40" alt="@flymysql" title="@flymysql" /></a>
307
+ <a href="https://github.com/baiseraku"><img src="https://avatars.githubusercontent.com/u/139727690?s=80&v=4" width="40" height="40" alt="@baiseraku" title="@baiseraku" /></a>
308
+ <a href="https://github.com/glzhangzhi"><img src="https://avatars.githubusercontent.com/u/36995275?s=80&v=4" width="40" height="40" alt="@glzhangzhi" title="@glzhangzhi" /></a>
309
+ <a href="https://github.com/hjwsm1989"><img src="https://avatars.githubusercontent.com/u/1067541?s=80&v=4" width="40" height="40" alt="@hjwsm1989" title="@hjwsm1989" /></a>
310
+ <a href="https://github.com/j10ha0"><img src="https://avatars.githubusercontent.com/u/72346906?s=80&v=4" width="40" height="40" alt="@j10ha0" title="@j10ha0" /></a>
311
+ <a href="https://github.com/FoolishWiser"><img src="https://avatars.githubusercontent.com/u/104308087?s=80&v=4" width="40" height="40" alt="@FoolishWiser" title="@FoolishWiser" /></a>
312
+ <a href="https://github.com/kakaa-nju"><img src="https://avatars.githubusercontent.com/u/79886619?s=80&v=4" width="40" height="40" alt="@kakaa-nju" title="@kakaa-nju" /></a>
313
+ <a href="https://github.com/4FMTWRV"><img src="https://avatars.githubusercontent.com/u/190457700?s=80&v=4" width="40" height="40" alt="@4FMTWRV" title="@4FMTWRV" /></a>
314
+ <a href="https://github.com/dahaipeng"><img src="https://avatars.githubusercontent.com/u/25660610?s=80&v=4" width="40" height="40" alt="@dahaipeng" title="@dahaipeng" /></a>
315
+ <a href="https://github.com/davidlin2k"><img src="https://avatars.githubusercontent.com/u/17074619?s=80&v=4" width="40" height="40" alt="@davidlin2k" title="@davidlin2k" /></a>
316
+ <a href="https://github.com/FlintyLemming"><img src="https://avatars.githubusercontent.com/u/19165511?s=80&v=4" width="40" height="40" alt="@FlintyLemming" title="@FlintyLemming" /></a>
317
+ <a href="https://github.com/GDWhisper"><img src="https://avatars.githubusercontent.com/u/129148123?s=80&v=4" width="40" height="40" alt="@GDWhisper" title="@GDWhisper" /></a>
318
+ <a href="https://github.com/YiHui-Liu"><img src="https://avatars.githubusercontent.com/u/30190271?s=80&v=4" width="40" height="40" alt="@YiHui-Liu" title="@YiHui-Liu" /></a>
319
+ <a href="https://github.com/Minggle"><img src="https://avatars.githubusercontent.com/u/35053182?s=80&v=4" width="40" height="40" alt="@Minggle" title="@Minggle" /></a>
320
+ <a href="https://github.com/nekomona"><img src="https://avatars.githubusercontent.com/u/25474483?s=80&v=4" width="40" height="40" alt="@nekomona" title="@nekomona" /></a>
321
+ <a href="https://github.com/shis23"><img src="https://avatars.githubusercontent.com/u/189869650?s=80&v=4" width="40" height="40" alt="@shis23" title="@shis23" /></a>
322
+ </p>
516
323
 
517
- ## License
324
+ 近期的亮点贡献(欢迎随时加入这个名单):
518
325
 
519
- MIT
326
+ | 贡献者 | 做了什么 |
327
+ | --- | --- |
328
+ | [@baiseraku](https://github.com/baiseraku) | 整个 dsh-tui 适配层([#92](https://github.com/flymysql/dsh-remote/pull/92))+ 底栏机器名修正([#98](https://github.com/flymysql/dsh-remote/pull/98)) |
329
+ | [@hjwsm1989](https://github.com/hjwsm1989) | 远程 .md 渲染连环两道:memo 守卫([#102](https://github.com/flymysql/dsh-remote/pull/102))+ labels 契约([#107](https://github.com/flymysql/dsh-remote/pull/107)) |
330
+ | [@shis23](https://github.com/shis23) | rw_sync 路径映射纠偏 + SFTP 超时韧性([#105](https://github.com/flymysql/dsh-remote/pull/105)) |
331
+ | [@davidlin2k](https://github.com/davidlin2k) | 无凭据机器走用户自有 ssh([#100](https://github.com/flymysql/dsh-remote/pull/100)) |
332
+ | [@GDWhisper](https://github.com/GDWhisper) | 目录补全逐字符重连修复([#42](https://github.com/flymysql/dsh-remote/pull/42),issue #41) |
333
+ | [@glzhangzhi](https://github.com/glzhangzhi) | 多远端会话的连接池隔离(issue #25 的主体修复) |
520
334
 
521
- ## 参与贡献
335
+ 早期已合并 PR 的贡献者(考古名单):
522
336
 
523
- 欢迎贡献,请先阅读 [CONTRIBUTING.md](./CONTRIBUTING.md)。使用问题、环境配置、「支持 XX 吗」这类讨论请走 [讨论区](https://github.com/flymysql/dsh-remote/discussions);可复现的缺陷请提 [Issue](https://github.com/flymysql/dsh-remote/issues)。
524
337
 
525
- 感谢以下已合并 PR 的贡献者:
526
338
 
527
339
  [@dahaipeng](https://github.com/dahaipeng) (#31) ·
528
340
  [@YiHui-Liu](https://github.com/YiHui-Liu) (#28) ·
@@ -534,6 +346,9 @@ MIT
534
346
  [4FMTWRV](https://github.com/4FMTWRV) (#6) ·
535
347
  [glzhangzhi](https://github.com/glzhangzhi)(per-session SSH 连接池修复)
536
348
 
349
+ > 名单随版本更新;头像墙之外的每一份 issue 报告、复现步骤、根因线索同样珍贵——
350
+ > 本仓库近半修复的起点都是一条写清楚的 issue。
351
+
537
352
  ## 变更记录
538
353
 
539
354
  见 [CHANGELOG.md](./CHANGELOG.md)。
package/lib/client.js CHANGED
@@ -70,6 +70,13 @@ window.__ModuleLoader__.load({
70
70
  const HostMenu = (Primitives && typeof Primitives.Menu === 'function') ? Primitives.Menu : null
71
71
  const useModalLayerFn = (Primitives && typeof Primitives.useModalLayer === 'function') ? Primitives.useModalLayer : null
72
72
  const writeClipboardFn = (Primitives && typeof Primitives.writeClipboard === 'function') ? Primitives.writeClipboard : null
73
+ // The host's Shiki-backed code highlighter (issue #104). Contract verified
74
+ // against the bundle: useCodeHighlighter(lang) → highlight(text) → per-line
75
+ // token arrays [{text, style:{color}}], or undefined for unknown grammars.
76
+ // languageForPath maps a file extension to a grammar id. Either missing ⇒
77
+ // plain text with line numbers (the fallback still answers the issue).
78
+ const useCodeHighlighterFn = (Primitives && typeof Primitives.useCodeHighlighter === 'function') ? Primitives.useCodeHighlighter : null
79
+ const languageForPathFn = (Primitives && typeof Primitives.languageForPath === 'function') ? Primitives.languageForPath : null
73
80
  const HostSwitch = (Primitives && typeof Primitives.Switch === 'function') ? Primitives.Switch : null
74
81
  const HostSegmentedTabs = (Primitives && typeof Primitives.SegmentedTabs === 'function') ? Primitives.SegmentedTabs : null
75
82
  const HostFileTypeIcon = (Primitives && typeof Primitives.FileTypeIcon === 'function') ? Primitives.FileTypeIcon : null
@@ -222,6 +229,21 @@ window.__ModuleLoader__.load({
222
229
  'settings.fwdTargetPort': '目标端口',
223
230
  'settings.fwdAuto': '自动重连',
224
231
  'settings.fwdAdd': '添加转发',
232
+ 'settings.cleanup': '工作区清理(本地镜像与对话)',
233
+ 'settings.cleanupRefresh': '刷新',
234
+ 'settings.cleanupEmpty': '没有本地镜像。选定一个远程工作区后它会出现在这里。',
235
+ 'settings.cleanupChats': ' 个对话',
236
+ 'settings.cleanupLive': '有会话在用',
237
+ 'settings.cleanupSessions': '删对话',
238
+ 'settings.cleanupSessionsHint': '只删该工作区的全部对话(保留镜像与登记);被占用的会话会跳过',
239
+ 'settings.cleanupRecent': '移出最近',
240
+ 'settings.cleanupRecentHint': '把工作区从「最近列表/当前工作区」移出,不删镜像(止住自动重建)',
241
+ 'settings.cleanupAll': '彻底删除',
242
+ 'settings.cleanupAllHint': '对话 + 登记 + 最近记录 + 本地镜像全部删除(远端目录不动),不可恢复',
243
+ 'settings.cleanupConfirmAll': '彻底删除工作区「{path}」?它的全部对话、工作区登记、最近记录和本地镜像都会被删除(远端目录不动)。此操作不可恢复。',
244
+ 'settings.cleanupConfirmSessions': '删除工作区「{path}」的全部对话?镜像与登记保留。',
245
+ 'settings.cleanupDone': '已删除',
246
+ 'settings.cleanupFailed': '操作失败:{msg}',
225
247
  'settings.audit': '最近执行的远程命令(审计日志)',
226
248
  'settings.auditEmpty': '暂无记录(在远端执行的命令会记录到 $DSH_HOME/remote-workspaces/audit.log)',
227
249
  'settings.auditRefresh': '刷新日志',
@@ -536,6 +558,21 @@ window.__ModuleLoader__.load({
536
558
  'settings.fwdTargetPort': 'Target port',
537
559
  'settings.fwdAuto': 'Auto reconnect',
538
560
  'settings.fwdAdd': 'Add forward',
561
+ 'settings.cleanup': 'Workspace cleanup (local mirrors & chats)',
562
+ 'settings.cleanupRefresh': 'Refresh',
563
+ 'settings.cleanupEmpty': 'No local mirrors yet. Pick a remote workspace and it shows up here.',
564
+ 'settings.cleanupChats': ' chats',
565
+ 'settings.cleanupLive': 'in use',
566
+ 'settings.cleanupSessions': 'Delete chats',
567
+ 'settings.cleanupSessionsHint': 'Delete only this workspace\'s chats (mirror and registration stay); occupied sessions are skipped',
568
+ 'settings.cleanupRecent': 'Forget',
569
+ 'settings.cleanupRecentHint': 'Remove the workspace from the recent/current lists without deleting the mirror (stops auto-recreation)',
570
+ 'settings.cleanupAll': 'Delete forever',
571
+ 'settings.cleanupAllHint': 'Chats + registration + recent entry + the local mirror all go (the REMOTE directory is untouched). Irreversible',
572
+ 'settings.cleanupConfirmAll': 'Permanently delete workspace "{path}"? All its chats, the registration, the recent entry and the local mirror are removed (the remote directory stays). This cannot be undone.',
573
+ 'settings.cleanupConfirmSessions': 'Delete all chats of workspace "{path}"? The mirror and registration stay.',
574
+ 'settings.cleanupDone': 'Deleted',
575
+ 'settings.cleanupFailed': 'Failed: {msg}',
539
576
  'settings.audit': 'Recent remote commands (audit log)',
540
577
  'settings.auditEmpty': 'No records yet (commands run remotely are logged to $DSH_HOME/remote-workspaces/audit.log)',
541
578
  'settings.auditRefresh': 'Refresh log',
@@ -914,6 +951,9 @@ window.__ModuleLoader__.load({
914
951
  '.dsh-rw-row:hover{background:rgba(128,128,128,.14)}',
915
952
  '.dsh-rw-list-item{transition:background .1s ease}',
916
953
  '.dsh-rw-list-item:hover{background:rgba(128,128,128,.18)}',
954
+ // The line a chat link jumped to flashes once (issue #104).
955
+ '@keyframes dshRwLineFlash{0%{background:var(--dsw-alias-state-warning-secondary,rgba(255,213,79,.40))}100%{background:transparent}}',
956
+ '.dsh-rw-line-flash{animation:dshRwLineFlash 1.6s ease-out}',
917
957
  '.dsh-rw-tabs{display:inline-flex;padding:3px;gap:2px;border-radius:10px;background:rgba(128,128,128,.14);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35))}',
918
958
  '.dsh-rw-tab{border:none!important;background:transparent!important}',
919
959
  '.dsh-rw-tab.is-active{background:var(--dsw-alias-button-primary-fill,#2563eb)!important;color:var(--dsw-alias-label-primary-foreground,#fff)!important;font-weight:600}',
@@ -1157,6 +1197,34 @@ window.__ModuleLoader__.load({
1157
1197
  // never touch.
1158
1198
  const [fwdOpen, setFwdOpen] = React.useState(false)
1159
1199
  const [auditOpen, setAuditOpen] = React.useState(false)
1200
+ // Issue #96: workspace cleanup on Web/Desktop (the TUI's machine-menu
1201
+ // cleanup page has an in-process API; here it is these two routes).
1202
+ const [cleanupOpen, setCleanupOpen] = React.useState(false)
1203
+ const [cleanupRows, setCleanupRows] = React.useState([])
1204
+ const [cleanupBusy, setCleanupBusy] = React.useState('')
1205
+ const [cleanupMsg, setCleanupMsg] = React.useState('')
1206
+ const loadCleanup = () => api('GET', '/dsh-remote/workspace-mirrors')
1207
+ .then((r) => { if (r && r.ok) setCleanupRows(r.mirrors || []) })
1208
+ .catch(() => {})
1209
+ // Opening the section loads the list: a wrapped setter, not an effect —
1210
+ // the effect would refire on every cleanupOpen-keyed re-render.
1211
+ const openCleanupSection = (v) => { setCleanupOpen(v); if (v) loadCleanup() }
1212
+ const cleanupAct = async (row, mode) => {
1213
+ const label = row.remotePath || row.localMirror
1214
+ if (mode === 'all' && !(await confirmUi.ask(tr('settings.cleanupConfirmAll', { path: label })))) return
1215
+ if (mode === 'sessions' && !(await confirmUi.ask(tr('settings.cleanupConfirmSessions', { path: label })))) return
1216
+ setCleanupBusy(row.localMirror + ':' + mode)
1217
+ setCleanupMsg('')
1218
+ try {
1219
+ const r = await api('POST', '/dsh-remote/workspace-cleanup', { localMirror: row.localMirror, mode })
1220
+ if (r && r.ok) { setCleanupMsg(tr('settings.cleanupDone')); await loadCleanup() }
1221
+ else setCleanupMsg(tr('settings.cleanupFailed', { msg: (r && r.error) || 'unknown' }))
1222
+ } catch (e) {
1223
+ // api() throws with the host's user-facing message (incl. WORKSPACE_BUSY).
1224
+ setCleanupMsg(tr('settings.cleanupFailed', { msg: String((e && e.message) || e) }))
1225
+ }
1226
+ setCleanupBusy('')
1227
+ }
1160
1228
  // Issue #46: attach a REMOTE machine's DSH Web UI as a local page. One
1161
1229
  // session per machine; `webAttach` holds the machineId currently opening.
1162
1230
  const [webAttaches, setWebAttaches] = React.useState([])
@@ -1988,6 +2056,46 @@ window.__ModuleLoader__.load({
1988
2056
  : React.createElement('div', { style: { opacity: 0.6, fontSize: 12 } }, tr('settings.auditEmpty')))
1989
2057
  : React.createElement('div', { style: { fontSize: 11, opacity: 0.55 } }, String(auditLines.length)),
1990
2058
  ),
2059
+ // 工作区清理(issue #96):TUI 的机器菜单清理页在 Web/Desktop 的同义词。
2060
+ React.createElement('div', { style: boxS },
2061
+ sectionToggle(cleanupOpen, openCleanupSection, tr('settings.cleanup'),
2062
+ React.createElement('button', {
2063
+ type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px', fontSize: 12, marginLeft: 'auto' },
2064
+ onClick: (e) => { e.stopPropagation(); loadCleanup() },
2065
+ }, tr('settings.cleanupRefresh'))),
2066
+ cleanupOpen
2067
+ ? (cleanupRows.length
2068
+ ? React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
2069
+ cleanupRows.map((row) => React.createElement('div', {
2070
+ key: row.localMirror,
2071
+ style: { display: 'flex', alignItems: 'center', gap: 8, padding: '5px 6px', borderRadius: 6, border: '1px solid ' + T.border, fontSize: 12 },
2072
+ },
2073
+ React.createElement('div', { style: { flex: 1, minWidth: 0 } },
2074
+ React.createElement('div', { style: { fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, row.title || row.machineName || row.host),
2075
+ React.createElement('code', { style: { fontSize: 11, opacity: 0.7, wordBreak: 'break-all' } }, row.remotePath)),
2076
+ React.createElement('span', { style: { fontSize: 11, opacity: 0.65, flexShrink: 0, whiteSpace: 'nowrap' } },
2077
+ humanSize(row.mirrorBytes) + (row.mirrorSizeTruncated ? '+' : '') + ' · ' + row.sessionCount + tr('settings.cleanupChats') + (row.liveSessionCount > 0 ? ' · ' + tr('settings.cleanupLive') : '')),
2078
+ React.createElement('button', {
2079
+ type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px', fontSize: 11 },
2080
+ disabled: cleanupBusy !== '', title: tr('settings.cleanupSessionsHint'),
2081
+ onClick: () => cleanupAct(row, 'sessions'),
2082
+ }, tr('settings.cleanupSessions')),
2083
+ React.createElement('button', {
2084
+ type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px', fontSize: 11 },
2085
+ disabled: cleanupBusy !== '', title: tr('settings.cleanupRecentHint'),
2086
+ onClick: () => cleanupAct(row, 'recent'),
2087
+ }, tr('settings.cleanupRecent')),
2088
+ React.createElement('button', {
2089
+ type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px', fontSize: 11, color: T.dangerText },
2090
+ disabled: cleanupBusy !== '', title: tr('settings.cleanupAllHint'),
2091
+ onClick: () => cleanupAct(row, 'all'),
2092
+ }, tr('settings.cleanupAll')))))
2093
+ : React.createElement('div', { style: { opacity: 0.6, fontSize: 12 } }, tr('settings.cleanupEmpty')))
2094
+ : null,
2095
+ cleanupOpen && cleanupMsg
2096
+ ? React.createElement('div', { style: { fontSize: 11, marginTop: 6, lineHeight: 1.5, wordBreak: 'break-all', color: /失败|failed|拒绝|busy/i.test(cleanupMsg) ? T.warn : T.ok } }, cleanupMsg)
2097
+ : null,
2098
+ ),
1991
2099
  // Panel-level messages. They used to live ONLY inside the manual form, which is
1992
2100
  // collapsed by default now — so "已打开远程工作区 …" and a failed 连接 were
1993
2101
  // invisible after clicking something in the list.
@@ -3743,6 +3851,71 @@ window.__ModuleLoader__.load({
3743
3851
  )
3744
3852
  }
3745
3853
 
3854
+ // ── Code view with line numbers + syntax highlighting (issue #104) ────────
3855
+
3856
+ /** Split a link-carried line anchor off a path: trailing `:42` (the way
3857
+ * models cite lines) or nothing. Returns { path, line } with line ≥ 1 or
3858
+ * null. A Windows drive colon never trails a digit sequence after a path
3859
+ * separator, and `path:0` is meaningless, so the strip is unambiguous. */
3860
+ function splitLineAnchor(rawPath) {
3861
+ const m = /:(\d+)$/.exec(String(rawPath || ''))
3862
+ if (!m) return { path: String(rawPath || ''), line: null }
3863
+ const line = Number(m[1])
3864
+ const path = String(rawPath).slice(0, m.index)
3865
+ if (!path || line < 1) return { path: String(rawPath || ''), line: null }
3866
+ return { path, line }
3867
+ }
3868
+
3869
+ /**
3870
+ * Line-numbered code body. Tokens come from the host's Shiki highlighter
3871
+ * when the grammar is known; otherwise the same rows render unstyled.
3872
+ * `jumpLine` scrolls the row into view and flashes it once per open.
3873
+ */
3874
+ function CodeView(props) {
3875
+ const { code, path, jumpLine } = props
3876
+ const lang = languageForPathFn ? languageForPathFn(path || '') : undefined
3877
+ // useCodeHighlighterFn is a module-level constant, so this hook's
3878
+ // presence cannot change between renders — the order stays lawful.
3879
+ const highlight = useCodeHighlighterFn ? useCodeHighlighterFn(lang) : null
3880
+ const tokenLines = React.useMemo(() => {
3881
+ if (!highlight) return null
3882
+ try { return highlight(code) || null } catch { return null }
3883
+ }, [highlight, code])
3884
+ const lines = React.useMemo(() => tokenLines || String(code).split('\n').map((t) => [{ text: t, style: null }]), [tokenLines, code])
3885
+ const rowRefs = React.useRef(new Map())
3886
+ const digits = String(lines.length).length
3887
+ React.useEffect(() => {
3888
+ if (!jumpLine) return undefined
3889
+ const row = rowRefs.current.get(jumpLine)
3890
+ try { if (row && typeof row.scrollIntoView === 'function') row.scrollIntoView({ block: 'center' }) } catch { /* non-DOM harness */ }
3891
+ return undefined
3892
+ }, [jumpLine, code])
3893
+ return React.createElement('div', { style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', fontSize: 13, lineHeight: 1.55, padding: '8px 0', color: T.label, minWidth: 'min-content' } },
3894
+ lines.map((tokens, i) => {
3895
+ const ln = i + 1
3896
+ const isTarget = jumpLine === ln
3897
+ return React.createElement('div', {
3898
+ key: ln,
3899
+ ref: (el) => { if (el) rowRefs.current.set(ln, el); else rowRefs.current.delete(ln) },
3900
+ 'data-line': ln,
3901
+ className: isTarget ? 'dsh-rw-line-flash' : undefined,
3902
+ style: { display: 'flex', whiteSpace: 'pre', ...(isTarget ? { borderRadius: 4 } : {}) },
3903
+ },
3904
+ React.createElement('span', {
3905
+ 'aria-hidden': 'true',
3906
+ style: {
3907
+ flexShrink: 0, width: digits + 'ch', paddingRight: 12, marginRight: 12,
3908
+ textAlign: 'right', userSelect: 'none', opacity: 0.45,
3909
+ borderRight: '1px solid ' + T.border,
3910
+ },
3911
+ }, String(ln)),
3912
+ React.createElement('span', { style: { flex: 1, paddingRight: 12 } },
3913
+ tokens.map((tk, ti) => React.createElement('span', { key: ti, style: tk.style || undefined }, tk.text))),
3914
+ )
3915
+ }),
3916
+ )
3917
+ }
3918
+
3746
3919
  // ── Remote file tab (opened by the explorer; live read + explicit edit) ──
3747
3920
  /**
3748
3921
  * The host's MarkdownText reads chrome strings off `labels` while rendering
@@ -3887,8 +4060,11 @@ window.__ModuleLoader__.load({
3887
4060
  (data && data.truncated)
3888
4061
  ? React.createElement('div', { style: { color: T.warn, fontSize: 12, marginTop: 8 } }, tr('file.truncated'))
3889
4062
  : null)
3890
- : React.createElement('div', { style: { fontSize: 13, lineHeight: 1.55, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', padding: '10px 12px', whiteSpace: 'pre-wrap', wordBreak: 'break-word', color: T.label } },
3891
- (data && data.content != null) ? data.content : (err ? '' : tr('file.empty')),
4063
+ : React.createElement('div', { style: { padding: '0 12px 8px' } },
4064
+ (data && data.content != null)
4065
+ ? React.createElement(CodeView, { code: data.content, path, jumpLine: props.jumpLine || null })
4066
+ : React.createElement('div', { style: { fontSize: 13, lineHeight: 1.55, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', padding: '10px 0', whiteSpace: 'pre-wrap', wordBreak: 'break-word', color: T.label } },
4067
+ err ? '' : tr('file.empty')),
3892
4068
  (data && data.truncated)
3893
4069
  ? React.createElement('div', { style: { color: T.warn, fontSize: 12, marginTop: 8 } }, tr('file.truncated'))
3894
4070
  : null,
@@ -4011,7 +4187,14 @@ window.__ModuleLoader__.load({
4011
4187
  if (!sessionId) return null
4012
4188
  // Dropping the leading empty segment keeps a session-root address ('') a
4013
4189
  // legitimate empty path instead of turning it into '/'.
4014
- return { sessionId, path: decodeURIComponent(tail.slice(1).join('/')) }
4190
+ const decoded = decodeURIComponent(tail.slice(1).join('/'))
4191
+ // Issue #104: models cite lines as `path:42` or `path#L42`; the core keeps
4192
+ // `:` literal in segments, so both reach us intact. Strip the anchor from
4193
+ // the path (resolution must not look for a file literally named "x.c:42").
4194
+ const hashLine = /^#L?(\d+)$/i.exec(url.hash || '')
4195
+ const split = splitLineAnchor(decoded)
4196
+ const line = hashLine ? Number(hashLine[1]) : split.line
4197
+ return { sessionId, path: split.path, ...(line ? { line } : {}) }
4015
4198
  }
4016
4199
  /**
4017
4200
  * The ABSOLUTE remote path a core file address refers to, or null.
@@ -4117,7 +4300,14 @@ window.__ModuleLoader__.load({
4117
4300
  return React.createElement('div', { style: { padding: 16, fontSize: 12, opacity: 0.7 } },
4118
4301
  tr('file.linkUnresolved'))
4119
4302
  }
4120
- return React.createElement(RemoteFileTab, { key: remotePath, tab: { path: remotePath }, scope: { sessionId } })
4303
+ return React.createElement(RemoteFileTab, {
4304
+ key: remotePath,
4305
+ tab: { path: remotePath },
4306
+ scope: { sessionId },
4307
+ // Issue #104: a chat link carrying a line (`x.c:42` or `…#L42`) lands
4308
+ // the open file on that line instead of its top.
4309
+ jumpLine: (parsed && parsed.line) || null,
4310
+ })
4121
4311
  }
4122
4312
  /** The local cwd of a session, from the client's own session store. */
4123
4313
  function sessionCwdFor(sessionId) {
package/lib/index.js CHANGED
@@ -4864,6 +4864,55 @@ export async function apply(ctx, config) {
4864
4864
  return sendJson(res, 200, { ok: true, password })
4865
4865
  },
4866
4866
  },
4867
+ {
4868
+ kind: 'exact',
4869
+ path: '/dsh-remote/workspace-mirrors',
4870
+ handler: async (req, res) => {
4871
+ if (req.method !== 'GET') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
4872
+ // The settings page's cleanup section: every local mirror with its
4873
+ // sessions, sizes and occupancy, straight off the in-process API (same
4874
+ // object the TUI consumes — one implementation, two faces).
4875
+ if (!hostApi) return sendJson(res, 503, { ok: false, error: 'in-process API unavailable' })
4876
+ try {
4877
+ return sendJson(res, 200, { ok: true, mirrors: await hostApi.listWorkspaceMirrors({}) })
4878
+ } catch (err) {
4879
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
4880
+ }
4881
+ },
4882
+ },
4883
+ {
4884
+ kind: 'exact',
4885
+ path: '/dsh-remote/workspace-cleanup',
4886
+ handler: async (req, res) => {
4887
+ if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
4888
+ if (!hostApi) return sendJson(res, 503, { ok: false, error: 'in-process API unavailable' })
4889
+ try {
4890
+ const body = JSON.parse((await readBody(req)) || '{}')
4891
+ const localMirror = String(body.localMirror || '')
4892
+ const mode = String(body.mode || '')
4893
+ if (!localMirror) return sendJson(res, 400, { ok: false, error: 'localMirror is required' })
4894
+ let result
4895
+ if (mode === 'all') {
4896
+ result = await hostApi.deleteRemoteWorkspace({ localMirror, force: body.force === true })
4897
+ } else if (mode === 'sessions') {
4898
+ result = await hostApi.deleteWorkspaceSessions({ localMirror, force: body.force === true })
4899
+ } else if (mode === 'recent') {
4900
+ result = await hostApi.forgetWorkspaceRecent({ localMirror })
4901
+ } else {
4902
+ return sendJson(res, 400, { ok: false, error: 'mode must be all | sessions | recent' })
4903
+ }
4904
+ return sendJson(res, 200, { ok: true, ...result })
4905
+ } catch (err) {
4906
+ // Coded errors carry user-facing messages; WORKSPACE_BUSY must reach
4907
+ // the UI as 409 so the page can say WHICH sessions hold the workspace.
4908
+ const status = (err && err.code === 'WORKSPACE_BUSY') ? 409 : (err && err.code === 'VALIDATION') ? 400 : 500
4909
+ const out = { ok: false, error: String((err && err.message) || err) }
4910
+ if (err && err.code) out.code = err.code
4911
+ if (err && Array.isArray(err.liveSessions)) out.liveSessions = err.liveSessions
4912
+ return sendJson(res, status, out)
4913
+ }
4914
+ },
4915
+ },
4867
4916
  ]
4868
4917
 
4869
4918
  registerHttpTransports(ctx, routes)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-remote",
3
- "version": "0.8.85",
3
+ "version": "0.8.87",
4
4
  "description": "Remote-work assistant for DeepSeek Harness: connect SSH (password/key/agent/keyboard-interactive, multi-hop ProxyJump), list hosts from ~/.ssh/config, pick a remote workspace, operate on it with 21 rw_* tools, conflict-aware mirror sync, an embedded PTY terminal, remote DSH web UI attach, port forwarding, host grouping, remote sandbox fencing, audit log, keychain passwords.",
5
5
  "license": "MIT",
6
6
  "author": "flymysql <flyphp@outlook.com>",