dsh-remote-vs 0.22.0 → 0.23.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 CHANGED
@@ -1,473 +1,489 @@
1
- # dsh-remote-vs · VSCode-style remote development for DSH
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
4
-
5
- [中文](./README.md) | English
6
-
7
- SSH host management inside the DSH Host process + helper push pipeline + a **VS Code-style remote
8
- workbench** (explorer / search / source control / commit graph with its commit-details pane / multi-tab editor / floating editor /
9
- side-by-side diff / multiple terminals / port forwarding). Hosts live in DSH Settings ("Remote hosts"); with `dsh-better-sidebar` installed
10
- there is an extra standalone "Remote Workspace" tab, otherwise it falls back to a native right-Sidebar "Remote Workspace"
11
- page (same content, self-opened from the guide, per-session instances). The editor is ALSO mounted into
12
- the conversation view slot as a "远程编辑器" (remote editor) tab next to "对话 / 轨迹", so the code area is
13
- full width; the sidebar copy is the narrow fallback. Since P2, native tools inside remote workspaces
14
- transparently run remotely (see below).
15
-
16
- ```text
17
- ┌─ Local DSH Host ─────────────────────────┐
18
- │ Plugin host half │ Client half │
19
- │ hosts/keys/push/ │ settings + native │
20
- │ routing │ entry takeover │
21
- │ /api/dsh-remote/* │ explorer page │
22
- └─────────────────────┴────────────────────┘
23
- │ ssh2 (files/proc/terminal) + helper RPC (remote fs)
24
- ▼
25
- ┌─ Remote Linux ─────────────────────────────┐
26
- │ ~/.dsh-helpers/<ver>/<arch>/dsh-ssh-helper│
27
- │ user-chosen remote working directory │
28
- └────────────────────────────────────────────┘
29
- ```
30
-
31
- ## Install
32
-
33
- ```sh
34
- dsh plugin --profile web add dsh-remote-vs
35
- ```
36
-
37
- (From npm, recommended; installing straight from the repository also works:
38
- `dsh plugin --profile web add github:xiray-xia/dsh-remote-vs`.)
39
-
40
- **Requires DSH `0.2.2-rc.2` or newer and below `0.3.0`** (`engines.dsh` enforces the range;
41
- **adapted to and typechecked against `0.2.2-rc.2`**). On Host `0.2.2-alpha.3` / `0.2.2-rc.1` use plugin `0.20.1`; the
42
- `0.2.2-alpha.2` generation needs `0.17.0` and the `0.2.1-rc.2` generation needs `0.9.3`. `--profile web` selects which profile to install into —
43
- this is a Web plugin, so it has to go into the profile your Web GUI runs from (`web` is
44
- the common name; use your own profile's name). Desktop uses the reserved `desktop`
45
- profile instead — see [Desktop](#desktop-dsh-desktop) below.
46
-
47
- **That one command is all it takes — no build scripts have to be approved.** The package
48
- has no `prepare`/`postinstall` and no package in the dependency tree carries an install
49
- script (`ssh2` is **bundled into the artifact**, not depended on); the repository route
50
- also ships the built `lib/`. The old "allow the printed build scripts in that profile's
51
- `pnpm-workspace.yaml` and re-run" step was pnpm 12's hard policy gate for dependencies
52
- with lifecycle scripts (`ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED` / `ERR_PNPM_IGNORED_BUILDS`);
53
- it cannot be waived from the dependency side, only removed from the tree. Then restart
54
- `dsh web` and open Settings → Remote hosts to configure.
55
-
56
- ### Desktop (DSH Desktop)
57
-
58
- The Desktop app is an Electron shell around the complete dsh Web application, but it runs
59
- in its own reserved profile, `desktop`, managed by the app itself: it does **not** share
60
- `node_modules`, lockfiles, or plugin activation with the `web` profile of `dsh web`, so the
61
- plugin has to be installed once for Desktop too. Sessions, settings, credentials and the
62
- `dsh-remote.json` host configuration under `$DSH_HOME` are shared, so the host list needs
63
- no re-setup.
64
-
65
- Install either way:
66
-
67
- 1. **Desktop's Plugins page**: launch Desktop once → enter `dsh-remote-vs` (a pinned
68
- version works too) on the Plugins page → install → **fully quit** Desktop (tray Quit /
69
- application menu exit; the window close button only hides it) and reopen it.
70
- 2. **Desktop's bundled dsh command**: application menu → **Manage dsh Command… →
71
- Install**, fully quit Desktop, run `dsh plugin --profile desktop add dsh-remote-vs`,
72
- then reopen Desktop.
73
-
74
- `desktop` is reserved for the Electron application: an **npm-installed `dsh` cannot manage
75
- it** (it answers `profile "desktop" is managed exclusively by the Electron application`),
76
- so one of the two routes above is required. The Desktop release version equals the DSH
77
- runtime it bundles, and it must satisfy `engines.dsh` (`>=0.2.2-rc.2`; check About);
78
- older releases make the Plugins page refuse the install. Desktop opens no visible Web
79
- port, but the plugin's HTTP routes and terminal socket are forwarded through Desktop's
80
- Host (the terminal resolves its address from `__DSH_TRANSPORT__.streamBaseUrl`), so no
81
- extra configuration is needed.
82
-
83
- > The package carries the prebuilt helper (`vendor/dsh-remote-helpers/`, ~45 MB), so the
84
- > first install is a large download — it is the **only** channel that delivers a helper
85
- > (the official releases ship no helper executable), and dropping it would leave new hosts
86
- > undeployable.
87
-
88
- ## Capabilities
89
-
90
- ### Remote workbench (VS Code-style UI)
91
-
92
- | Capability | Notes |
93
- | --- | --- |
94
- | Explorer | Lazy tree + one click expands/collapses a directory + hidden-files toggle; **new: a 150 ms hover prefetches** that folder's listing (the expand paints from cache and revalidates in the background; if the prefetch is still in flight, the click waits for it and shows the loading line like a cold directory). On the Host every browse request shares **one long-lived SFTP session**, cutting a listing from two round trips to one (**the first one after a cold start or after the 2 idle minutes still pays the channel open**); context menu: new / rename / delete / copy / move / paste / find in folder / insert `@` reference / **download to local** (files stream to this machine; a directory **or a multi-selection** is archived on the remote host as one `.tar.gz` and streamed, so nothing is buffered in Host memory; a native **Save as** dialog picks the destination when the browser supports it, otherwise the browser's download folder; a bottom-right **download panel** shows live progress, allows cancel, and reports completion/failure; the search-hit menu offers it too; a download ends in one of three honest states — **saved / handed to the browser / failed** — and a hand-off never reads as "done", nor does a Host failure get saved as a file; the tree's empty area has its own context menu (new / upload / paste) and uploads, pastes and drops are **serialized** (a second transfer is refused with an explanation); the tree is keyboard-operable (`↑↓` move, `←→` collapse/expand, `Enter` open, `Shift+F10` menu) and dialogs trap focus and close on `Esc`); git status colours and folder roll-up marks; **type-coloured file and folder icons** (coloured sheet + category mark, amber folders that open, same set as the local sidebar; the tree only — other lists keep the neutral glyph); **drag-hover expand**: while dragging a row or dropping OS files, resting the pointer on a collapsed directory for ~650 ms opens it (spring-loaded folder, so the drop lands inside the folder you just revealed; cancelling the drag leaves nothing half-open) |
95
- | Transfer speed | Uploads/downloads use a **256 KiB × 32 in-flight window** over SSH (pipelined SFTP): single-file downloads and drag-and-drop uploads run ~8× faster than one stream, and the helper push (45 MB) uses parallel `fastPut` too; large uploads are no longer killed by a 60 s deadline (progress watchdog instead). A **download above 4 MiB gets a second dedicated SFTP channel** (one SSH channel caps its window at 2 MiB, so each extra channel adds a window): an interleaved same-process A/B measured **about 1.1–1.4×** (medians of 1.08–1.43× across samples, link-dependent; raw read probes 1.6–1.8× — the product opens two channels, not four); small files keep one channel and one less channel slot, and uploads stay single-channel (the remote write path is the bound, extra channels gain nothing) |
96
- | Search | Two modes: **file names** (remote `find`) and **contents** (remote `grep`). Content mode has a scope folder, `Aa` (case) / `ab_` (whole word) / `.*` (regex), results grouped per file with match highlights, and clicking a hit jumps to that line; **content mode can be aborted** (changing or clearing the query kills the running remote `grep`; an older Host without the streaming route degrades to a one-shot, non-cancellable query), success with stderr warnings is reported above the results, and a **directory** hit in name mode is revealed in the tree instead of being opened as a file |
97
- | Connection status and offline read-only | The top bar and the editor info bar show the current workspace's SSH link state (**connection OK / connection issue / ready, connects on demand**): a drop is no longer silent — open editor tabs keep their cached content and turn **read-only** (saves are blocked with an explanation), the tree keeps showing cached directories while background refreshes stay quiet, and uncached directories say they are offline. When the link recovers, directories, git status, **unmodified file tabs and read-only diff tabs** refresh automatically (tabs with unsaved edits are left alone and the user is told). An errored link is retried at most three times, 30 s apart, then the chip is a manual retry control. While the link is down, "Undo this change" and the diff's hunk actions are blocked too; **a single operation's deadline is NOT treated as a broken link** — the chip stays ok and only that operation fails, with the real reason; when the link is down and the workspace has no cache, the SCM panel says it cannot read instead of sitting on "loading". **No cross-reload persistent cache** (remote source never lands on disk) — a deliberate privacy trade-off |
98
- | Source control | **Repository-folder picker** (for workspaces whose git repository lives in a sub-folder: browse the remote tree, one-click jump to any repository discovered inside the workspace, type a relative or absolute path, and see which repository each folder resolves to); changes / staged / untracked / ignored buckets; **untracked directory rows expand on click**; per-file AND **per-hunk** stage / unstage / discard (behind a confirm) / commit; branches, remotes and stash panes; sync (fetch/pull/push), with **push refspec support** (Gerrit style `HEAD:refs/for/<branch>`; empty = plain `git push`, a non-empty value is remembered); fetch/pull/push/sync get a **live output panel** (server-sent events showing git/remote output, a running clock, **cancel** that kills the remote process group, and the full log for copying afterwards; an older Host without the streaming route falls back to the one-shot result) |
99
- | Session change review | The **collapsible** panel above the composer: what THIS SESSION changed (one row per file, file-type icon, `+a −b` on the right); clicking a file opens it in the remote editor with **line shading plus character-level inline diff**, `n/N ↑↓` jumps between change points, and hovering a changed line offers **Undo this change** (remote `git apply -R`). See "Session change review" below |
100
- | Side-by-side diff | Panes stay **exactly equal** + per-hunk buttons in the middle gutter + a **top horizontal scrollbar** (a very long line can no longer break the symmetry) + pinned line numbers, **rendering only the rows inside the viewport** (a 3000-line file goes from 9000 row containers to ~174, with exactly the same scroll range as a full render); switch between "before / after", and the after side is editable and savable (the save writes the working-tree file back; a diff above 8MiB is read-only, so a truncated prefix can never be written over the real file) |
101
- | Commit graph | SVG branch/merge graph; selecting a commit opens the **resizable / expandable commit-details pane** below it with three views: **Commit details** (subject, author, time, full hash + copy, parents, refs, message body, checkout), **Contents** (changed files grouped by directory, collapsible and path-filterable; click for the diff, right-click or the row button to open in the editor), **Diff** (only the first ~1500 rows start expanded, later files start folded; both line numbers, `+/−` counts, line wrapping, previous/next-file navigation, and copy of one file's patch or the whole patch). Merge commits are shown against their **first parent** (git lists no files for a merge otherwise) |
102
- | AI review | A single-file diff OR a **whole commit** can be handed to the conversation with one click — the request is **appended to the composer draft only** (nothing is sent automatically, and you can edit it first): a diff up to 32 KiB is inlined verbatim; a larger one (or one silently truncated at the 2 MB cap) becomes a summary request — file/commit facts + hunk headers + "fetch it yourself with `git show`" (a 2 MB diff is hundreds of thousands of tokens, so inlining it is pointless); an untracked or binary file is passed by path and the model reads it. Entries: the side-by-side diff toolbar and the commit pane's Diff toolbar; the button is disabled with the reason when the current session is not bound to this remote workspace, or the host exposes no conversation input channel |
103
- | Multi-tab editor | Open/save/reload, dirty marks, several files at once; **saves are atomic** (side file + rename, writing through symlinks and keeping the mode bits); **a save is checked against the remote baseline** — when the file was written by someone else (an agent through the transparent route, a terminal, another editor) since it was opened, the save is refused and offers "overwrite / load remote version / show difference" instead of overwriting silently; image preview, Markdown/HTML preview (source vs preview); closing a tab, reloading and switching workspace all **ask first** when there are unsaved edits (a workspace switch clears every tab, so it asks); `Ctrl+S` works globally, even when the editor is not focused; **a page reload reopens the file tabs you had** (per workspace, at most 12; paths only, never contents; tabs that no longer open are skipped and counted; caret and scroll position are not restored) |
104
- | Floating editor | Three entries: "Open in floating editor" in the file-tree / search-hit / source-control context menus, plus **double-clicking the "remote editor" tab** to float the editor as it stands (same tabs, previews, diff, find and change marks — not a second, thinner editor). Drag the title bar to move, drag any of the eight edges/corners to resize, maximize/restore (or double-click the title bar); **minimize to a draggable floating ball** (dirty dot on it, click or press Enter to restore, drag to park it anywhere); `Ctrl+wheel` zooms the editor text. Position, size, font size and the ball's spot survive a page refresh |
105
- | Syntax highlighting | VS Code **Dark+ / Light+** palettes; covers java/aidl/smali, c/c++, go, rust, js/ts, json, py, yaml, xml, html/css, md, sh, properties/rc/toml, diff …; a **fallback colorer** takes over when no grammar matches, so a file is never left monochrome. Honest caveat: kotlin / gradle / smali are coloured by the Java grammar (no dedicated package), which gets keywords, strings and comments right but does not split their own syntax |
106
- | Find | In-editor `Ctrl+F` (`Aa` / `ab_` / `.*`, `3/17` count, ↑↓, `F3`/`Shift+F3`, `Esc`); **selected text is carried into the box by `Ctrl+F`**; the widget is pinned to the top-right and does not scroll away; the `n/N` count refreshes on `F3`, clicks and caret moves |
107
- | Quick open | `Ctrl+P` (`⌘+P` on macOS) jumps to a file by name instead of expanding directories one level at a time: the remote file index is fetched once (`rg --files` when available, `find` otherwise; **both caps are enforced on the remote side**, and a truncated listing says so — "index truncated, only the first N files are searchable" — instead of pretending to be complete), filtered locally by a subsequence scorer (consecutive matches, the file-name segment and word boundaries carry weight; ties break on path order so the list never reshuffles). The first screen is your recently opened files. The index lives **in memory only**, stores paths and never contents, and is rebuilt after a save/upload/delete/rename/create; writes made by a terminal or an agent bypass that and come back on a page reload. The shortcut only takes over while the remote workbench is visible — a local chat page keeps the browser's own `Ctrl+P` |
108
- | Jump | Clicking a search hit opens the file at that line, centres it and **lights the landing line** (fades after ~2.6s); repeat jumps in the same file work |
109
- | Terminals | Tabbed multi-terminal (`+` to create, `✕`/middle-click to close behind a confirm), across hosts; session ids are persisted so a page refresh reattaches to the running shells, and a session is kept for **10 minutes after its last socket goes away** (enough for a refresh or a browser-tab switch) before the remote shell is closed; **a socket drop (as opposed to a shell exit) keeps the session and offers a one-click reattach** (the same session id reattaches, and the Host still reclaims it after the 10-minute TTL above), and only a real exit clears it |
110
- | Workspaces | Binding list + routing-mode dropdown + the dual-mode (local / remote) new-workspace wizard; **unbinding asks first** (sessions and history stay readable, new remote calls are refused) |
111
- | Port forwarding | A sidebar **"Ports"** page: lists the remote host's listening TCP ports (`ss`, falling back to `netstat`) and forwards any of them to a local port in one click, with the local URL for copying/opening. Manual rules ("remote address:port → local port, which may be auto-assigned") are supported too. **The local listener binds `127.0.0.1` only** (`ssh -L` semantics — never exposed to the LAN); each rule has its own channel budget and never consumes one of the six exec/SFTP slots. An SSH drop or the idle eviction does not kill the listener: the next local connection simply re-dials. Rules live in the browser (restored after a reload) and every one can be stopped; disabling the plugin, deleting the host, or unloading it releases the local ports. When the remote has neither `ss` nor `netstat`, or the probe times out or is interrupted, the panel says "cannot enumerate" instead of showing an empty list |
112
-
113
- ### Hosts and transport
114
-
115
- | Capability | Notes |
116
- | --- | --- |
117
- | Host management | CRUD + connectivity test; key / password auth; config in `$DSH_HOME/dsh-remote.json` (0600), independent from `dsh-ssh.json` |
118
- | Key bootstrap | One click generates a dedicated keypair on password hosts and deploys `authorized_keys`, key auth from then on |
119
- | Push pipeline | Remote arch/OS probe → version compare → skip-if-same / else push; the executable channel pushes a self-built helper. A failed deploy no longer retries on every remote file operation: it backs off from **5 seconds up to 5 minutes**, and the Settings "Push" button forces an immediate retry |
120
- | Remote files | SFTP browse / read / write / create / delete / rename. Boundaries hardened: 0-byte files no longer deadlock, and every SFTP operation times out at 60s and releases its channel; **a single directory listing is capped at 20000 entries** (the first 20000 after sorting — directories first, then names — announced in the host log; the protocol carries no "truncated" field, so the UI has no marker); **a save goes through a side file and a rename** (server-side `posix-rename` when available, otherwise backup-rename-rollback), **writes through symlinks** (the link itself survives) and keeps the mode bits **on a best-effort basis**; SCM status parsing unquotes git's C-quoted paths (any name with whitespace is quoted) |
121
- | Remote terminal | ssh2 PTY + WebSocket, xterm rendering (copy-paste/theme-follow/reconnect-on-refresh); **a reattach only takes over, it does not resize** (a page reload no longer shrinks a running shell to 80×24); an output backlog applies real backpressure to the far end; **frames are capped at 1 MiB**, and pastes past 64 Ki characters are chunked on code points by the client instead of dropping the connection |
122
- | Concurrent channels | At most **6** remote channels per host at a time (no longer colliding with the far end's sshd `MaxSessions`); the 7th queues for up to **30 seconds** and then fails with `remote host <alias> is busy` instead of piling on connections |
123
- | Monitor | A sidebar **"Monitor"** page samples one host or every host **only while the panel and the page are visible**, at the configured refresh interval (5 s by default; 5/10/30 s in its settings): CPU, memory, disk, load, network rate, temperature and uptime, with 60-point history curves plus manual refresh and pause. The scope is "current host / a named host / all hosts" and survives a reload. The **first sample reports CPU% and the network rate as unknown** (both are deltas and need a second sample), and a non-Linux host shows unknown instead of 0. The Host caches one sample per alias for 3 seconds and joins concurrent requests, so one sample uses one exec channel and never the port-forward budget. Samples live in memory only — nothing is written to disk |
124
- | Timeouts and process cleanup | Ordinary git commands default to 300 s (configurable); the **network verbs (fetch/pull/push/sync) default to 20 minutes with a 30-minute ceiling**. exec runs in its own session (`setsid --wait`); on timeout OR cancel it sends TERM and **escalates to KILL after 3 seconds**, reaping the child processes with it; a host without `setsid --wait` is detected by a one-shot probe and falls back to the old behaviour, with a host-log line saying the timed-out remote command may still be running; **directory / multi-selection archive downloads carry a 600 s server-side budget** (remote `timeout -k 3 600`; a host without GNU `timeout` falls back to the unbudgeted old behaviour) and fail with the real reason when it expires |
125
- | Git graph | Remote repo status + branches + SVG commit graph + commit details/contents/diff pane (exec + frontend parsing, zero Host additions) |
126
- | Import | One-click import from `~/.ssh/config` and from an existing `dsh-ssh.json` (read once, no coupling); `Host a b` multi-pattern entries are expanded one by one, `Include` is reported as not expanded instead of being silently dropped, and every skipped host names an actionable reason (no User / no IdentityFile / invalid port …) |
127
- | Environment check | An "environment check" per host: one remote command probes OS/kernel, glibc, `git`, `ripgrep`, `tar`, `setsid --wait`, `$HOME` free space, CPU/memory, the deployed helper version and sshd's `MaxSessions`, shown as a three-state table (**available / missing / unknown**). "Could not determine" is reported as **unknown**, never as "missing" (insufficient permission, unparseable output and a dropped link are all unknown); every row keeps the remote's own words, stderr is merged rather than discarded, and the whole report copies in one click |
128
-
129
- ### Agent capabilities
130
-
131
- | Capability | Notes |
132
- | --- | --- |
133
- | Agent tools | `remote_hosts` / `remote_exec` / `remote_read` / `remote_write` / `remote_ls` |
134
- | **P2 transparent remote execution** | Native `read/write/edit/bash/glob/grep/jobs` inside remote workspaces run directly on the far end |
135
- | **P3 remote @ references** | `@` in remote sessions completes remote files (fileReferences router: scoped live listings / bare queries via a remote rg index) |
136
-
137
- ## Project structure
138
-
139
- ```text
140
- dsh_remote_vs/
141
- ├── cordis.patch.yml # composition: plugin row + private local realm + routers + preset-remote
142
- ├── src/
143
- │ ├── index.ts # plugin entry: store/pool/worlds/routes/tools/preset-switch wiring
144
- │ ├── protocol.ts # frontend/backend wire contract (route table + pure types, shared)
145
- │ ├── paths.ts # four-piece addressing under $DSH_HOME (store/keys/build cache/alias dirs)
146
- │ ├── store.ts # host + binding + tombstone persistence (0600 JSON, atomic writes)
147
- │ ├── pool.ts # ssh2 long-lived pool (exec/shell/sftp/putFile, TOFU host keys)
148
- │ ├── sftp.ts # remote file engine (SFTP windowed reads-writes/tree ops)
149
- │ ├── keygen.ts # password-host key bootstrap (generate→deploy→flip)
150
- │ ├── deploy.ts # push pipeline (probe/compare/ship/double-verify/manifest)
151
- │ ├── importers.ts # ssh_config / dsh-ssh.json parsing importers
152
- │ ├── routes.ts # /api/dsh-remote/* route table + terminal WebSocket upgrade
153
- │ ├── terminal.ts # PTY session registry (reconnect-on-refresh/disconnect cleanup)
154
- │ ├── forward.ts # local port-forward manager (direct-tcpip channels / one listener per rule / budgets)
155
- │ ├── listen-ports.ts # remote listening-port probe (ss/netstat command + pure parser)
156
- │ ├── metrics.ts # host-monitor probe (one POSIX /proc command + pure parse/CPU·net deltas)
157
- │ ├── monitor.ts # monitor sampler (per-alias TTL cache/in-flight join/counters/forget)
158
- │ ├── tools.ts # the 5 Agent tool definitions
159
- │ ├── http.ts / loopback.ts # JSON body IO + loopback trust fence
160
- │ ├── git-format.ts # git command builders + pure frontend parsing (zero Host additions)
161
- │ ├── git-ops.ts # the full remote git surface: status/diff/branch/remote/stash/commit/hunk patch builders + parsers
162
- │ ├── fs-ops.ts # remote file-operation command builders (copy/move/remove/stat)
163
- │ ├── search-ops.ts # remote content search (grep builder + NUL-separated parser + match splitting)
164
- │ ├── p2/ # ── P2 transparent routing ──
165
- │ │ ├── worlds.ts # world decisions (cwd key/alias/tombstones) + remote RPC/FS/proc contexts
166
- │ │ ├── helper-rpc.ts # helper wire protocol over an ssh2 exec channel (handshake/heartbeat)
167
- │ │ ├── router-fs.ts # transparent fs router (target→world map/path translation/policy rewrite)
168
- │ │ ├── router-subprocess.ts # transparent process router (argv0 reduction/pwsh gate)
169
- │ │ ├── ssh-proc.ts # ssh2 process runtime (setsid group kill/marker/stdin/spill)
170
- │ │ ├── shell-bash.ts # routed bash executor (local verbatim/remote strips DSH_*)
171
- │ │ ├── router-spill.ts # transparent spill router (session world key/remote dir)
172
- │ │ ├── router-refs.ts # transparent @ reference router (agent world key, P3)
173
- │ │ ├── file-refs.ts # remote @ search (live fs-ssh listings/rg index/ported stock scoring)
174
- │ │ ├── bridge.ts # private-realm local publishes (localFs and other early services)
175
- │ │ └── bridge-refs.ts # standalone refs bridge (local-refs needs workingDirectory: must split)
176
- │ └── client/ # ── browser half (React, bundled into lib/client.js) ──
177
- │ ├── index.tsx # surface decision (better-first/settle-boost/native fallback) + settings + directoryFlow takeover
178
- │ ├── store.tsx # module-level state shared by both surfaces (useSyncExternalStore; open files/terminals/view live here)
179
- │ ├── RemoteRoot.tsx # sidebar surface: VS Code activity rail (explorer/search/SCM/history/editor/terminal/workspaces)
180
- │ ├── RemoteEditorView.tsx # conversation-view surface (the "remote editor" tab next to 对话/轨迹, full width)
181
- │ ├── RemoteExplorer.tsx # explorer: tree + context menu + file ops + @ references + status marks
182
- │ ├── drag-expand.ts # drag-hover auto-expand (pure state machine, shared by both drag paths)
183
- │ ├── SearchView.tsx # search panel: name / content modes + Aa/ab_/.* + grouped hits + jump
184
- │ ├── EditorPane.tsx # editor pane: tabs + info bar (build stamp / tok count) + image/MD/HTML preview
185
- │ ├── FloatingEditorWindow.tsx # floating window frame (title-bar drag/8-way resize/maximize/ball minimize/font zoom)
186
- │ ├── float-tab-trigger.ts # double-click on the "remote editor" tab (the tab row is the host's, so label-based)
187
- │ ├── FloatingPlaceholder.tsx # "docked elsewhere" placeholder + dock button left on the other surfaces
188
- │ ├── float-editor.ts # window geometry/resize/surface rules (pure; driven directly by the self-check)
189
- │ ├── live-editor.ts # live buffer + scroll/caret handoff across a surface change
190
- │ ├── CodeEditor.tsx # CodeMirror wrapper: grammar table/theme/find widget/jump/fallback wiring
191
- │ ├── scm/ # ── source control ──
192
- │ │ ├── ScmPanel.tsx # changes/staged/untracked + per-file and per-hunk actions + commit box
193
- │ │ ├── DiffView.tsx # side-by-side diff (top scrollbar/hunk buttons/editable after side)
194
- │ │ ├── HistoryPanel.tsx # SVG commit graph + resizable/expandable commit-details pane
195
- │ │ ├── CommitPane.tsx # details/contents/diff tabs + patch toolbar + context menus
196
- │ │ ├── commit-model.ts # patch blocks/line numbers/counts/directory grouping/file stepping (pure)
197
- │ │ ├── actions.ts # remote git action layer (over the exec channel)
198
- │ │ ├── diff-model.ts # unified diff → side-by-side row projection (pure)
199
- │ │ └── status-map.ts # status bucketing + tree marks (pure)
200
- │ ├── vsc/ # ── VS Code skin and controls (zero new runtime deps) ──
201
- │ │ ├── kit.tsx / vsc.css # icons/dialogs/context menu/segmented control + all styles (scoped to .rvs-root)
202
- │ │ ├── editor-palette.ts # Dark+/Light+ palette + fixed class names (rvs-ck-*)
203
- │ │ ├── editor-theme.ts # editor chrome theme (live light/dark swap)
204
- │ │ ├── editor-langs.ts # file extension → CodeMirror grammar
205
- │ │ ├── fallback-highlight.ts# coloring used when no grammar matched (via tokenize.ts)
206
- │ │ ├── FindWidget.tsx # Ctrl+F find widget (pinned top-right)
207
- │ │ ├── reveal-line.ts # jump + landing-line highlight
208
- │ │ ├── tokenize.ts / markdown.tsx # read-only pane tokenizer / dependency-free markdown renderer
209
- │ ├── NativeExplorer.tsx# native page type definition + seat body (no-sidebar fallback)
210
- │ ├── composer.ts / use-remote-chat-target.ts / selection-popup.ts # remote @refs/selection-to-chat
211
- │ ├── ai-review.ts # AI review prompt builder (single diff / whole commit, byte tiers, pure)
212
- │ ├── api.ts # typed fetch wrapper over /api/dsh-remote
213
- │ ├── MonitorView.tsx # monitor panel (one/all hosts, curves, pause/refresh, persisted scope)
214
- │ ├── metrics-model.ts # monitor model (history window/sparkline geometry/capacity+rate formatting)
215
- │ ├── HostsView / WorkspacesView / WorkspaceWizard / TerminalView / XTerm / PortsView / Dialog
216
- │ ├── SettingsHosts.tsx # settings occupants (host mgmt/binding list, self-fetching)
217
- │ ├── DirectoryFlow.tsx # native entry occupant (local dual-mode/remote wizard)
218
- │ ├── RemoteDirectoryPicker.tsx# remote directory browser dialog
219
- │ └── i18n.ts / theme.ts / ui.tsx # bilingual dictionary/theme signal/shared styles
220
- ├── vendor/dsh-remote-helpers/ # helper seeds (shipped, seeded into cache at startup, see below)
221
- ├── docs/ # local-only working docs (only docs/media/ screenshots ship)
222
- │ ├── MAINTENANCE.md # local-only (.gitignore), not shipped: upgrade impact, checklist, pitfalls, release
223
- │ ├── VERSION-HISTORY.md # local-only: per-release change log (0.7.1 → 0.22.0)
224
- │ └── GATES.md # local-only: local gate inventory and measured assertion counts
225
- ├── locale/ # bilingual plugin metadata
226
- └── lib/ # build output (**must be committed**; only .map is ignored; restart after link install)
227
- ```
228
-
229
- `vendor/dsh-remote-helpers/` (committed) holds helper seeds: at startup the plugin spreads them into
230
- `$DSH_HOME/dsh-remote-helpers/` (copy-if-absent, never overwrites), so fresh installs can push right away.
231
- When a new helper is built, swap the 4-piece set (tarball + sha256 + helper.json + patch notes)
232
- into vendor and commit (details live in the local-only `docs/MAINTENANCE.md` §4, which is gitignored and not distributed).
233
-
234
- `.spike/` and `scripts/` (both gitignored, **never distributed with the repository**) hold the
235
- development-time verification and self-check scripts: `.spike/` has the live-host ones — `p2-router.ts`
236
- main regression (real remote + real Cordis + real router classes) and probes like `grep-probe.mjs`
237
- (build with the local `tsconfig.scratch.json`), plus `model-check.mjs` / `reveal-check.mjs` /
238
- `fallback-check.mjs` / `client-load-check.mjs` / `tool-schema-check.mjs` which need no host at all;
239
- `scripts/` has the plain-node regression gates (`node scripts/check-*.mjs`, with `verify-lib.mjs`
240
- checking the build artifact). Both are covered under "Development".
241
-
242
- ## Remote workbench (VS Code style)
243
-
244
- ![The sidebar's four views: files, search, source control, history](docs/media/sidebar-views.gif)
245
-
246
- Both surfaces share one state module (`store.tsx`): **the sidebar "Remote Workspace" page** (a standalone tab when
247
- `dsh-better-sidebar` is installed, otherwise the native right-Sidebar page) and **the conversation-view
248
- "remote editor" tab** (next to 对话/轨迹, giving the code area full width).
249
-
250
- - **Activity rail**: explorer / search / source control / commit graph / editor / terminal / workspaces.
251
- A panel stays mounted after its first visit, so switching back neither refetches nor flashes. While it is
252
- hidden it does **no remote work** (directory listings, the SCM stash/branch/remote queries and editor
253
- image reads all wait for the next foreground pass), and visibility is MEASURED on the plugin root
254
- (IntersectionObserver) instead of being taken from a host prop.
255
- - **No blank wait when switching workspaces**: the last git state read for each (workspace, repository
256
- directory) is kept in memory, so switching back paints the change list, branch and tree marks **in the
257
- same frame** and re-reads behind it. The panel says "cached · refreshing" meanwhile; the change list and
258
- the stage/commit/discard buttons still act on that workspace (⟳ and "reset repository directory" are
259
- disabled while the background read runs — pressing them would only queue a second walk of the same tree).
260
- One git read per repository DIRECTORY at a time (changing the directory lets the two directories' reads run
261
- side by side — they are two different walks); a manual refresh's answer is always post-click (it queues
262
- after the running read); a read of a workspace you left behind only fills its own cache and never repaints;
263
- a failed background read keeps the list and shows why instead of declaring the workspace "not a
264
- repository". The first visit to a workspace still waits — cache cannot invent a read.
265
- - **Editor**: tabs plus an info bar (path, language, **build stamp**, `tok N` coloured-token count,
266
- saved state, reload/save). Those three marks exist for troubleshooting: the stamp answers "is the
267
- browser running the bundle I just built?", `tok 0` answers "did a grammar match this extension?".
268
- - **Floating editor**: "Open in floating editor" from the file-tree / search-hit / source-control context
269
- menus, or double-click the "remote editor" tab, lifts the editor into a window above the shell (same tabs
270
- and buffers; closing or docking puts it back on its original surface). Drag the title bar, resize from the
271
- eight edges/corners, maximize/restore; **minimize to a 44px floating ball** (no full-width bar — park it in
272
- any corner, click/Enter restores it, and it shows a dot while there are unsaved edits); zoom the text with
273
- `Ctrl+wheel`; unsaved text is explicitly handed over between the main surface, the floating window and tab
274
- switches (the disk-side baseline is kept separately, so the dirty mark can never be mistaken for saved).
275
- - **Find and jump**: `Ctrl+F` opens a widget pinned to the editor's top-right corner
276
- (`position: fixed` anchored to the editor's rect, so no ancestor scroller can carry it away);
277
- a selection is carried into it by `Ctrl+F`; a jump from the search results centres the line and
278
- lights it up.
279
- - **Terminals**: tabbed sessions with the session id persisted one by one, so a page refresh reattaches
280
- to the shells that are still running; **a reattach only takes over, it does not resize** (a live shell is
281
- never shrunk to 80×24 — the true size comes from the one tab that can measure itself, sent as a `resize`
282
- frame); a session is kept for **10 minutes** after its last socket goes away before the remote shell is
283
- closed (it used to be kept forever, so closing the browser left the shell holding an sshd session slot).
284
- - **Known limits (stated honestly)**:
285
- - There is **no public API to select the "remote editor" view**; the plugin can only click the shell's
286
- own tab by its label and toasts a hint when that fails (`revealEditor()`).
287
- - Untracked directories arrive as a **single `dir/` row**; clicking it **expands** the files inside
288
- (one path-limited `git status -uall -- dir/`, so the cost tracks the directory, not the repository;
289
- click again to collapse). An expansion is a snapshot of the moment it was opened — collapse and
290
- re-expand to refresh it.
291
- - Opening a file is capped at 8MiB (official helper constant); beyond that it is shown read-only, and the diff's after-side is read-only for such files too (a truncated prefix is never written back).
292
- - A save checks the remote baseline it was opened from (mtime and size): if the file was written by someone else in the meantime (an agent through the transparent route, a terminal, another editor) the save is **refused** and offers "overwrite / load remote version / show difference" instead of silently replacing their work. This **narrows** the race rather than closing it: SFTP reports mtime in whole seconds, so a same-second change of the same length is still undetectable, and a window remains between the check and the moment the bytes land: a save writes a side file and then atomically renames it, so a write by someone else during that window (seconds for a large file) is still overwritten — the difference is going from "blind whole-file write" to "a much smaller window". Programmatic writes (agent tools, helper push, deploy manifest) carry no baseline and behave exactly as before.
293
- - The find widget floats above the code (like VS Code) and takes no layout space.
294
- - Output backpressure is **per shell**: one tab that cannot keep up pauses every tab attached to that
295
- shell — a deliberate trade, preferring to hold the remote command back on behalf of the slowest
296
- consumer over letting host memory grow without bound.
297
- - A directory listing past 20000 entries is truncated, and since the protocol has no "truncated" field
298
- the UI shows **no marker at all** — only the host log line
299
- `listing <path> on <alias> shows 20000 of N entries`.
300
- - **Monitor limits**: sampling happens only while the Monitor panel is the visible view AND the page is
301
- in the foreground (hidden means zero remote traffic); the complete metric set comes from Linux
302
- `/proc`, so other platforms show unknown; temperature exists only when the host exposes a thermal
303
- zone (many VMs do not); CPU% and the network rate are deltas, so the **first frame is unknown**;
304
- samples live in memory only and the curves restart after a page reload.
305
-
306
- ## Session change review (Cursor style)
307
-
308
- ![Session change review: the panel lists the files this session changed, opening one paints whole-line and intra-line differences, the top-right control steps through the changes, and hovering reverts a single change](docs/media/session-change-review.gif)
309
-
310
- The **collapsible** panel above the composer (titled "本次改动") answers, per **session**, "what did this turn
311
- change?". Its data comes from the plugin's own change ledger (`/api/dsh-remote/changes`), not from DSH's
312
- `workspaceChanges` — the latter cannot see a routed session at all (the probe measured 58 remote sessions
313
- with zero change events).
314
-
315
- - **The panel**: one row per file (file-type icon + relative path + `+a −b` on the right), aligned left and
316
- right with the composer card; click the header to collapse/expand, `⟳` forces an immediate rescan. With no
317
- changes it says "this session has not changed any file yet"; when it cannot compute, it states the
318
- **specific reason** (see the limits below) instead of handing you an empty list to guess about.
319
- - **Clicking a file** opens it in the remote editor with change marks: added lines get a **green line
320
- background**, deleted characters are drawn as an **inline struck-through chip** (a deleted character does
321
- not exist in the new file, so it can only be an inserted widget), and the left gutter carries a change bar.
322
- - **Jumping between change points**: the floating `n/N ↑↓` control at the editor's top-right
323
- (`Alt+Shift+Cmd/Ctrl+↓/↑`) cycles through them; typing in the editor invalidates the marks and says
324
- "position may be out of date".
325
- - **Undo this change**: hover a changed line and click → remote `git apply -R`. When the context no longer
326
- matches, the far end refuses outright (not one byte of the file changes); a tab with unsaved edits is
327
- refused first, so a remote patch can never overwrite your buffer; on success the caret stays where it was
328
- and the marks are re-read (they do not simply vanish because something was undone).
329
- - **Follow the session's workspace**: the sidebar, the editor's dropdown and the file tree all follow the
330
- workspace the **current session** lives in; after a manual switch they are not pulled back within that
331
- session, and a new session follows again. The capability lives in the store, so it works even when **the
332
- sidebar was never opened**; clicking a changed file is "show me this result", not a manual switch.
333
- - **Repository directory**: the one the user picked under Source control → repository directory always wins;
334
- when the session root is not a repository, a single candidate one level below is adopted automatically,
335
- while several candidates produce an explicit hint to set it in Source control.
336
-
337
- **Known limits (stated honestly)**:
338
-
339
- - The baseline is the **session start**, not HEAD: untracked files that already existed before the session
340
- began are not counted as this session's work.
341
- - Tracked files refresh when a **turn ends** (the panel polls every 3 seconds as a backstop, so the numbers
342
- usually catch up within a second or two); **new files** created in a shell are found by a **slow scan**
343
- whose single-run budget is up to **3 minutes**, re-run at a self-tuning interval (at least 5 seconds,
344
- naturally longer on a huge checkout). `⟳` forces an immediate rescan.
345
- - A non-git workspace, or one holding several repositories with no repository directory set, shows the exact
346
- reason (`no git repository at the workspace root, and N candidates below it — set the repository directory
347
- in Source Control`) rather than an empty list.
348
- - Binary and oversized files are marked "binary / too large" on the row and get no character-level diff;
349
- **non-UTF-8 text (GBK and friends) is treated as binary** (no counts, no undo) so it cannot produce
350
- garbage numbers and an undo that always fails.
351
- - When the untracked scan gives up (e.g. the far end refuses), the panel **states the reason** and keeps the
352
- refresh entry point instead of silently listing fewer rows.
353
- - Undo carries **provenance** (session / binding / repository directory), so a patch can never be applied to
354
- another host after switching sessions or bindings; a file this session created whole is not offered for
355
- undo (a reverse patch must never delete an untracked file).
356
-
357
- ## P2 transparent remote execution (Windows native)
358
-
359
- Single-Host mixed routing: native tools dispatch by which world the session cwd lands in — remote aliases go
360
- over helper RPC (fs) / ssh2 (processes), local stays untouched; both share one Host and one GUI.
361
-
362
- - Alias dirs: `$DSH_HOME/remote-ssh/aliases/<id>` (empty shells, routing keys only), auto-registered into the native workspace list as `<server> > <base>`
363
- - Routing switch (dropdown at the top of Settings → Remote hosts; underneath it is profile patch `- id: remote-vs`, `config.routingMode`, volatile, no restart):
364
- default `enforce` (real routing); switch to `off` (pure local passthrough) / `shadow` (logs, still local) as debugging escapes
365
- - New workspace: the native "Add workspace…" entry is adopted (local/remote dual tab; remote leg = host→push→bind wizard)
366
- - Presets: a `Remote` preset (bash toolset); under enforce, new remote sessions switch to it automatically (default preset only, never overrides an explicit choice)
367
- - Ground truths (measured, not assumed):
368
- - Remote `grep/glob` call remote `rg` through routing (both measured hosts ship rg 13; no remote rg means no hits)
369
- - Whole reads >8MiB report `FS_TOO_LARGE` (official helper ceiling) — use streaming/paged reads; **writes are uncapped** (a 46MiB whole write passed live)
370
- - Oversized process output lands in a Host temp spill file (`readFrom` returns tail + path, full text lives in the file — same as stock)
371
- - After unbinding, new calls are explicitly refused (fail-closed tombstones), history stays readable
372
- - Disconnects: in-flight calls are not replayed; new calls reconnect automatically; the link state is shown explicitly in the top bar / editor info bar, and while it is down the editor and cached directories stay **read-only visible** (see "Connection status and offline read-only")
373
- - Verify: `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/p2-router.js`
374
- (real remote + real Cordis + real router classes, 61/61; P0 routing and GUI need a Host restart + smoke pass)
375
- - Details: the local-only `docs/MAINTENANCE.md` (§2 coupling points, §3 checklist)
376
-
377
- ## Self-built helper (P1)
378
-
379
- Upstream never published helper binaries (all Release assets are empty), so this plugin builds its own:
380
-
381
- - Build machine: WSL2 Ubuntu-22.04 (glibc 2.35, matching the remote targets), Node v24.21.0 + pnpm 11.28.5
382
- - Sources: the `dsh-v0.2.1-alpha.2` tag (the **build baseline**: what must match is the wire protocol version, not the Host version — our protocol is still **2**, so a Host upgrade to `0.2.2-alpha.3` needs no rebuild either: the plugin intentionally stays on `dsh-ssh@0.2.1-rc.2`, and the new generation's protocol 3 is deliberately not followed — see §2.26 of the maintenance notes)
383
- - Command: stock script `pnpm exec tsx scripts/build-exe-for-ssh-helper.ts --target=node24-linux-x64`
384
- - Only deviation: no docker for the manylinux 2.28 rebuild, so a `DSH_GLIBC_CEILING`
385
- env override was added (default stays 2.28); this build targets 2.35 (see `glibc-ceiling.patch` in the cache dir)
386
- - Checks: stock `verify-ssh-helper-artifact.ts --sandbox=required`, all 8 green
387
- - Cache: `$DSH_HOME/dsh-remote-helpers/` (`*.tar.gz` + `.sha256` + `.helper.json`
388
- with binarySha256, feeding P2's helperHash)
389
- - Full rebuild procedure for upgrades: the local-only `docs/MAINTENANCE.md` §4 (gitignored, not distributed)
390
-
391
- ## Security model
392
-
393
- - All `/api/dsh-remote/*` routes are loopback + same-origin only.
394
- - Passwords / key passphrases are stored in plaintext in `dsh-remote.json` (0600) — same trust model as the existing SSH plugin.
395
- - Pushed artifacts are sha256-verified both ways (tarball in, binary out); the helper install dir is separate from workspaces; the sidecar's `version`, platform and tarball path are whitelist-validated (no unvalidated string is interpolated into a remote shell line), and a failed install keeps the previous version.
396
- - Host config writes are fsync'd and re-checked against a stamp (a concurrent Desktop/Web edit inside the read-modify-write window is replayed instead of silently overwritten).
397
- - Remote sessions may read explicit local absolute paths (the tool spill-file contract requires it); acceptable under the same model trust — a known trade-off recorded in the local maintenance notes.
398
- - **Port forwards bind `127.0.0.1` only**: another local process can reach one, which is exactly the `ssh -L` trust boundary (the local user account). The target is dialed **from the remote host**, so it can reach that host's private network; "open in browser" always builds an `http://` URL — a forwarded HTTPS service needs the scheme edited by hand.
399
-
400
- ## Development
401
-
402
- ```sh
403
- pnpm install
404
- pnpm run typecheck
405
- pnpm run build
406
- dsh plugin --profile web add link:<absolute path of this directory>
407
- ```
408
-
409
- **How a change goes live: `pnpm run build`, then restart `dsh web` — for the host half and the client half alike.**
410
- **`lib/` is committed.** The package has no `prepare` script (pnpm 12 refuses to run one for a git
411
- dependency), so a `dsh plugin add github:…` user receives the repository as it is: **after editing
412
- source you must `pnpm run build` and commit `lib/` with it** (`node scripts/verify-lib.mjs` checks that the
413
- entries are present, committed and loadable; the self-check scripts live on the maintainer's machine only,
414
- see below).
415
- The Host reads plugin bundles into memory at startup (`initialBundleSnapshot`: it stats mtime/ctime/size into a
416
- revision, then reads the bytes; the response carries `Cache-Control: public, max-age=31536000, immutable`), so a
417
- **client-only** change (`src/client/**`) behaves exactly the same way: a browser refresh — `Ctrl+Shift+R`
418
- included — only re-fetches the bytes captured at startup, under the same `rev`. How to tell:
419
-
420
- 1. Each build injects a stamp (`MMDD-HHmm`) into `lib/client.js`, shown at the right of the editor info bar;
421
- 2. Restart `dsh web` → refresh the page: **the stamp must change** (if it does not, you are still on the bytes
422
- captured at startup);
423
- 3. For colour issues, read `tok N`: `0` means no grammar matched the extension AND the fallback colorer
424
- did not take over (the console line next to it names the file).
425
-
426
- > The one exception is DSH's own development watcher (`pnpm run dev:web`, via `ClientModuleRegistry.rebuilt`);
427
- > there is no watcher on a plugin user's side and `dsh web --help` has no watch option, so "restart" is the rule.
428
-
429
- Self-checks (no host, no DSH, a few seconds each):
430
-
431
- ```sh
432
- node .spike/client-load-check.mjs # really evaluates the client modules: load-time errors tsc/bundler/other harnesses miss
433
- node .spike/tool-schema-check.mjs # all 5 agent tools: run execute, then validate the result with the RUNTIME's own validator
434
- node .spike/model-check.mjs # 55 checks: real git output → parsers, diff model, hunk patches, class↔CSS contract
435
- node .spike/reveal-check.mjs # 5 checks: jump target, landing highlight, repeat jump in one editor
436
- node .spike/fallback-check.mjs # 12 checks: the fallback colorer colours java/cpp/shell in a real DOM
437
- node .spike/editor-dom-check.mjs # 12 checks: a real CodeMirror in jsdom emits colour spans for java/shell/cpp
438
- node .spike/i18n-check.mjs # zh/en dictionary consistency: no missing key, no orphan, matching placeholders
439
- node .spike/ref-check.mjs # 32 cases: assertRef accepts real revision suffixes, rejects every injection surface
440
- node .spike/status-check.mjs # runs the generated git commands in a real shell to prove exit codes are no longer masked
441
- node .spike/cache-check.mjs # incremental token cache vs whole-document tokenizing, 9 languages × 8 edit shapes
442
- node .spike/layout-check.mjs # height chain + scrollbar contract: header rows stay pinned, the bar is wide enough to grab
443
- node .spike/viewstate-check.mjs # scroll+caret round trip across a remount (stateful scrollTop: tells "restored" from "reset")
444
- node .spike/tabswitch-check.mjs # real React drives three wirings: both ref-reading ones must fail, reporting must pass
445
- node .spike/letter-check.mjs # status letters: untracked `?` no longer collides with conflict `U`, plus both render sites
446
- ```
447
-
448
- `.spike/layout-fixture.html` (generated by `build-fixture.mjs`) is the fixture for
449
- measuring layout in a browser: it mechanically inlines the **host's real slot CSS**
450
- and the **shipped vsc.css**, so after a CSS change you re-run
451
- `node .spike/build-fixture.mjs` and can measure the height chain, the scroll
452
- container and the scrollbar width for real. Pure-CSS defects are invisible to
453
- tsc, to the bundler and to jsdom — this fixture is the only place they reproduce.
454
-
455
- `markdown-check.ts` has to be compiled first (it imports a `.tsx`, which Node cannot load):
456
- `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/markdown-check.js`.
457
-
458
- > `.spike/` is git-ignored, so these checks are local only and run in no CI. **Run them before quoting any
459
- > number** rather than copying a figure out of any file — one `model-check` count drifted across the README,
460
- > the local maintenance doc and the review reports as 44 / 48 / 55, while the harness actually prints 55/55
461
- > (its source holds 57 `check(` call sites, 2 of them inside loops and reachable only on failure, which is
462
- > exactly why "57 call sites" and "55 checks run" differ by 2).
463
-
464
- The live-host regression is still `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/p2-router.js`.
465
- Before touching anything for a new DSH release, read the local-only `docs/MAINTENANCE.md` (§2 coupling points, §3 checklist) — it is gitignored, so a clone will not have it. After any change (host half or client half) the mandatory steps are: `pnpm run build` → `node scripts/verify-lib.mjs` (entries present, committed and loadable) → restart `dsh web`; and before committing, run every local gate under `scripts/` (`node scripts/check-*.mjs`, 57 of them at the time of writing, plus `verify-lib.mjs` and the shared TS loader `_ts-hook.mjs`).
466
-
467
- ## License
468
-
469
- MIT © 2026 xiray-xia — see [LICENSE](./LICENSE).
470
-
471
- The `vendor/` helper seed is built from DeepSeek Harness sources (MIT) at tag `dsh-v0.2.1-alpha.2`
472
- with the stock build script; see "Self-built helper" above for the exact procedure and the single
473
- documented deviation (`glibc-ceiling.patch` in the seed set).
1
+ # dsh-remote-vs · VSCode-style remote development for DSH
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
4
+
5
+ [中文](./README.md) | English
6
+
7
+ SSH host management inside the DSH Host process + helper push pipeline + a **VS Code-style remote
8
+ workbench** (explorer / search / source control / commit graph with its commit-details pane / multi-tab editor / floating editor /
9
+ side-by-side diff / multiple terminals / port forwarding). Hosts live in DSH Settings ("Remote hosts"); with `dsh-better-sidebar` installed
10
+ there is an extra standalone "Remote Workspace" tab, otherwise it falls back to a native right-Sidebar "Remote Workspace"
11
+ page (same content, self-opened from the guide, per-session instances). The editor is ALSO mounted into
12
+ the conversation view slot as a "远程编辑器" (remote editor) tab next to "对话 / 轨迹", so the code area is
13
+ full width; the sidebar copy is the narrow fallback. Since P2, native tools inside remote workspaces
14
+ transparently run remotely (see below).
15
+
16
+ ```text
17
+ ┌─ Local DSH Host ─────────────────────────┐
18
+ │ Plugin host half │ Client half │
19
+ │ hosts/keys/push/ │ settings + native │
20
+ │ routing │ entry takeover │
21
+ │ /api/dsh-remote/* │ explorer page │
22
+ └─────────────────────┴────────────────────┘
23
+ │ ssh2 (files/proc/terminal) + helper RPC (remote fs)
24
+ ▼
25
+ ┌─ Remote Linux ─────────────────────────────┐
26
+ │ ~/.dsh-helpers/<ver>/<arch>/dsh-ssh-helper│
27
+ │ user-chosen remote working directory │
28
+ └────────────────────────────────────────────┘
29
+ ```
30
+
31
+ ## Install
32
+
33
+ ```sh
34
+ dsh plugin --profile web add dsh-remote-vs
35
+ ```
36
+
37
+ (From npm, recommended; installing straight from the repository also works:
38
+ `dsh plugin --profile web add github:xiray-xia/dsh-remote-vs`.)
39
+
40
+ **Requires DSH `0.2.2-rc.4` or newer and below `0.3.0`** (`engines.dsh` enforces the range;
41
+ **adapted to and typechecked against `0.2.2-rc.4`**). On Host `0.2.2-rc.2` / `0.2.2-rc.3` use plugin `0.22.0`; on `0.2.2-alpha.3` / `0.2.2-rc.1` use `0.20.1`; the
42
+ `0.2.2-alpha.2` generation needs `0.17.0` and the `0.2.1-rc.2` generation needs `0.9.3`. `--profile web` selects which profile to install into —
43
+ this is a Web plugin, so it has to go into the profile your Web GUI runs from (`web` is
44
+ the common name; use your own profile's name). Desktop uses the reserved `desktop`
45
+ profile instead — see [Desktop](#desktop-dsh-desktop) below.
46
+
47
+ > **Upgrading from `0.22.0`**: the remote helper's wire protocol moves from **2 to 3**.
48
+ > Existing host records are recognised as an older generation and the new helper is pushed
49
+ > automatically on the first connection (this needs the old build to still be in the local
50
+ > helper cache; if that cache was cleared, press **Push** once in Settings). Each host pays
51
+ > one ~47 MB upload on that first contact. The old helper directory is kept, so rolling back
52
+ > is just pushing the old version again.
53
+
54
+ **That one command is all it takes — no build scripts have to be approved.** The package
55
+ has no `prepare`/`postinstall` and no package in the dependency tree carries an install
56
+ script (`ssh2` is **bundled into the artifact**, not depended on); the repository route
57
+ also ships the built `lib/`. The old "allow the printed build scripts in that profile's
58
+ `pnpm-workspace.yaml` and re-run" step was pnpm 12's hard policy gate for dependencies
59
+ with lifecycle scripts (`ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED` / `ERR_PNPM_IGNORED_BUILDS`);
60
+ it cannot be waived from the dependency side, only removed from the tree. Then restart
61
+ `dsh web` and open Settings → Remote hosts to configure.
62
+
63
+ ### Desktop (DSH Desktop)
64
+
65
+ The Desktop app is an Electron shell around the complete dsh Web application, but it runs
66
+ in its own reserved profile, `desktop`, managed by the app itself: it does **not** share
67
+ `node_modules`, lockfiles, or plugin activation with the `web` profile of `dsh web`, so the
68
+ plugin has to be installed once for Desktop too. Sessions, settings, credentials and the
69
+ `dsh-remote.json` host configuration under `$DSH_HOME` are shared, so the host list needs
70
+ no re-setup.
71
+
72
+ Install either way:
73
+
74
+ 1. **Desktop's Plugins page**: launch Desktop once → enter `dsh-remote-vs` (a pinned
75
+ version works too) on the Plugins page → install → **fully quit** Desktop (tray Quit /
76
+ application menu exit; the window close button only hides it) and reopen it.
77
+ 2. **Desktop's bundled dsh command**: application menu → **Manage dsh Command… →
78
+ Install**, fully quit Desktop, run `dsh plugin --profile desktop add dsh-remote-vs`,
79
+ then reopen Desktop.
80
+
81
+ `desktop` is reserved for the Electron application: an **npm-installed `dsh` cannot manage
82
+ it** (it answers `profile "desktop" is managed exclusively by the Electron application`),
83
+ so one of the two routes above is required. The Desktop release version equals the DSH
84
+ runtime it bundles, and it must satisfy `engines.dsh` (`>=0.2.2-rc.4`; check About);
85
+ older releases make the Plugins page refuse the install. Desktop opens no visible Web
86
+ port, but the plugin's HTTP routes and terminal socket are forwarded through Desktop's
87
+ Host (the terminal resolves its address from `__DSH_TRANSPORT__.streamBaseUrl`), so no
88
+ extra configuration is needed.
89
+
90
+ > The package carries the prebuilt helper (`vendor/dsh-remote-helpers/`, ~47 MB), so the
91
+ > first install is a large download — it is the **only** channel that delivers a helper
92
+ > (the official releases ship no helper executable), and dropping it would leave new hosts
93
+ > undeployable.
94
+
95
+ ## Capabilities
96
+
97
+ ### Remote workbench (VS Code-style UI)
98
+
99
+ | Capability | Notes |
100
+ | --- | --- |
101
+ | Explorer | Lazy tree + one click expands/collapses a directory + hidden-files toggle; **new: a 150 ms hover prefetches** that folder's listing (the expand paints from cache and revalidates in the background; if the prefetch is still in flight, the click waits for it and shows the loading line like a cold directory). On the Host every browse request shares **one long-lived SFTP session**, cutting a listing from two round trips to one (**the first one after a cold start or after the 2 idle minutes still pays the channel open**); context menu: new / rename / delete / copy / move / paste / find in folder / insert `@` reference / **download to local** (files stream to this machine; a directory **or a multi-selection** is archived on the remote host as one `.tar.gz` and streamed, so nothing is buffered in Host memory; a native **Save as** dialog picks the destination when the browser supports it, otherwise the browser's download folder; a bottom-right **download panel** shows live progress, allows cancel, and reports completion/failure; the search-hit menu offers it too; a download ends in one of three honest states — **saved / handed to the browser / failed** — and a hand-off never reads as "done", nor does a Host failure get saved as a file; the tree's empty area has its own context menu (new / upload / paste) and uploads, pastes and drops are **serialized** (a second transfer is refused with an explanation); the tree is keyboard-operable (`↑↓` move, `←→` collapse/expand, `Enter` open, `Shift+F10` menu) and dialogs trap focus and close on `Esc`); git status colours and folder roll-up marks; **type-coloured file and folder icons** (coloured sheet + category mark, amber folders that open, same set as the local sidebar; the tree only — other lists keep the neutral glyph); **drag-hover expand**: while dragging a row or dropping OS files, resting the pointer on a collapsed directory for ~650 ms opens it (spring-loaded folder, so the drop lands inside the folder you just revealed; cancelling the drag leaves nothing half-open) |
102
+ | Transfer speed | Uploads/downloads use a **256 KiB × 32 in-flight window** over SSH (pipelined SFTP): single-file downloads and drag-and-drop uploads run ~8× faster than one stream, and the helper push (47 MB) uses parallel `fastPut` too; large uploads are no longer killed by a 60 s deadline (progress watchdog instead). A **download above 4 MiB gets a second dedicated SFTP channel** (one SSH channel caps its window at 2 MiB, so each extra channel adds a window): an interleaved same-process A/B measured **about 1.1–1.4×** (medians of 1.08–1.43× across samples, link-dependent; raw read probes 1.6–1.8× — the product opens two channels, not four); small files keep one channel and one less channel slot, and uploads stay single-channel (the remote write path is the bound, extra channels gain nothing) |
103
+ | Search | Two modes: **file names** (remote `find`) and **contents** (remote `grep`). Content mode has a scope folder, `Aa` (case) / `ab_` (whole word) / `.*` (regex), results grouped per file with match highlights, and clicking a hit jumps to that line; **content mode can be aborted** (changing or clearing the query kills the running remote `grep`; an older Host without the streaming route degrades to a one-shot, non-cancellable query), success with stderr warnings is reported above the results, and a **directory** hit in name mode is revealed in the tree instead of being opened as a file |
104
+ | Connection status and offline read-only | The top bar and the editor info bar show the current workspace's SSH link state (**connection OK / connection issue / ready, connects on demand**): a drop is no longer silent — open editor tabs keep their cached content and turn **read-only** (saves are blocked with an explanation), the tree keeps showing cached directories while background refreshes stay quiet, and uncached directories say they are offline. When the link recovers, directories, git status, **unmodified file tabs and read-only diff tabs** refresh automatically (tabs with unsaved edits are left alone and the user is told). An errored link is retried at most three times, 30 s apart, then the chip is a manual retry control. While the link is down, "Undo this change" and the diff's hunk actions are blocked too; **a single operation's deadline is NOT treated as a broken link** — the chip stays ok and only that operation fails, with the real reason; when the link is down and the workspace has no cache, the SCM panel says it cannot read instead of sitting on "loading". **No cross-reload persistent cache** (remote source never lands on disk) — a deliberate privacy trade-off |
105
+ | Source control | **Repository-folder picker** (for workspaces whose git repository lives in a sub-folder: browse the remote tree, one-click jump to any repository discovered inside the workspace, type a relative or absolute path, and see which repository each folder resolves to); changes / staged / untracked / ignored buckets; **untracked directory rows expand on click**; per-file AND **per-hunk** stage / unstage / discard (behind a confirm) / commit; branches, remotes and stash panes; sync (fetch/pull/push), with **push refspec support** (Gerrit style `HEAD:refs/for/<branch>`; empty = plain `git push`, a non-empty value is remembered); fetch/pull/push/sync get a **live output panel** (server-sent events showing git/remote output, a running clock, **cancel** that kills the remote process group, and the full log for copying afterwards; an older Host without the streaming route falls back to the one-shot result) |
106
+ | Session change review | The **collapsible** panel above the composer: what THIS SESSION changed (one row per file, file-type icon, `+a −b` on the right); clicking a file opens it in the remote editor with **line shading plus character-level inline diff**, `n/N ↑↓` jumps between change points, and hovering a changed line offers **Undo this change** (remote `git apply -R`). See "Session change review" below |
107
+ | Side-by-side diff | Panes stay **exactly equal** + per-hunk buttons in the middle gutter + a **top horizontal scrollbar** (a very long line can no longer break the symmetry) + pinned line numbers, **rendering only the rows inside the viewport** (a 3000-line file goes from 9000 row containers to ~174, with exactly the same scroll range as a full render); switch between "before / after", and the after side is editable and savable (the save writes the working-tree file back; a diff above 8MiB is read-only, so a truncated prefix can never be written over the real file) |
108
+ | Commit graph | SVG branch/merge graph; selecting a commit opens the **resizable / expandable commit-details pane** below it with three views: **Commit details** (subject, author, time, full hash + copy, parents, refs, message body, checkout), **Contents** (changed files grouped by directory, collapsible and path-filterable; click for the diff, right-click or the row button to open in the editor), **Diff** (only the first ~1500 rows start expanded, later files start folded; both line numbers, `+/−` counts, line wrapping, previous/next-file navigation, and copy of one file's patch or the whole patch). Merge commits are shown against their **first parent** (git lists no files for a merge otherwise) |
109
+ | AI review | A single-file diff OR a **whole commit** can be handed to the conversation with one click — the request is **appended to the composer draft only** (nothing is sent automatically, and you can edit it first): a diff up to 32 KiB is inlined verbatim; a larger one (or one silently truncated at the 2 MB cap) becomes a summary request — file/commit facts + hunk headers + "fetch it yourself with `git show`" (a 2 MB diff is hundreds of thousands of tokens, so inlining it is pointless); an untracked or binary file is passed by path and the model reads it. Entries: the side-by-side diff toolbar and the commit pane's Diff toolbar; the button is disabled with the reason when the current session is not bound to this remote workspace, or the host exposes no conversation input channel |
110
+ | Multi-tab editor | Open/save/reload, dirty marks, several files at once; **saves are atomic** (side file + rename, writing through symlinks and keeping the mode bits); **a save is checked against the remote baseline** — when the file was written by someone else (an agent through the transparent route, a terminal, another editor) since it was opened, the save is refused and offers "overwrite / load remote version / show difference" instead of overwriting silently; image preview, Markdown/HTML preview (source vs preview); closing a tab, reloading and switching workspace all **ask first** when there are unsaved edits (a workspace switch clears every tab, so it asks); `Ctrl+S` works globally, even when the editor is not focused; **a page reload reopens the file tabs you had** (per workspace, at most 12; paths only, never contents; tabs that no longer open are skipped and counted; caret and scroll position are not restored) |
111
+ | Floating editor | Three entries: "Open in floating editor" in the file-tree / search-hit / source-control context menus, plus **double-clicking the "remote editor" tab** to float the editor as it stands (same tabs, previews, diff, find and change marks — not a second, thinner editor). Drag the title bar to move, drag any of the eight edges/corners to resize, maximize/restore (or double-click the title bar); **minimize to a draggable floating ball** (dirty dot on it, click or press Enter to restore, drag to park it anywhere); `Ctrl+wheel` zooms the editor text. Position, size, font size and the ball's spot survive a page refresh |
112
+ | Syntax highlighting | VS Code **Dark+ / Light+** palettes; covers java/aidl/smali, c/c++, go, rust, js/ts, json, py, yaml, xml, html/css, md, sh, properties/rc/toml, diff …; a **fallback colorer** takes over when no grammar matches, so a file is never left monochrome. Honest caveat: kotlin / gradle / smali are coloured by the Java grammar (no dedicated package), which gets keywords, strings and comments right but does not split their own syntax |
113
+ | Find | In-editor `Ctrl+F` (`Aa` / `ab_` / `.*`, `3/17` count, ↑↓, `F3`/`Shift+F3`, `Esc`); **selected text is carried into the box by `Ctrl+F`**; the widget is pinned to the top-right and does not scroll away; the `n/N` count refreshes on `F3`, clicks and caret moves |
114
+ | Quick open | `Ctrl+P` (`⌘+P` on macOS) jumps to a file by name instead of expanding directories one level at a time: the remote file index is fetched once (`rg --files` when available, `find` otherwise; **both caps are enforced on the remote side**, and a truncated listing says so — "index truncated, only the first N files are searchable" — instead of pretending to be complete), filtered locally by a subsequence scorer (consecutive matches, the file-name segment and word boundaries carry weight; ties break on path order so the list never reshuffles). The first screen is your recently opened files. The index lives **in memory only**, stores paths and never contents, and is rebuilt after a save/upload/delete/rename/create; writes made by a terminal or an agent bypass that and come back on a page reload. The shortcut only takes over while the remote workbench is visible — a local chat page keeps the browser's own `Ctrl+P` |
115
+ | Jump | Clicking a search hit opens the file at that line, centres it and **lights the landing line** (fades after ~2.6s); repeat jumps in the same file work |
116
+ | Terminals | Tabbed multi-terminal (`+` to create, `✕`/middle-click to close behind a confirm), across hosts; session ids are persisted so a page refresh reattaches to the running shells, and a session is kept for **10 minutes after its last socket goes away** (enough for a refresh or a browser-tab switch) before the remote shell is closed; **a socket drop (as opposed to a shell exit) keeps the session and offers a one-click reattach** (the same session id reattaches, and the Host still reclaims it after the 10-minute TTL above), and only a real exit clears it |
117
+ | Workspaces | Binding list + routing-mode dropdown + the dual-mode (local / remote) new-workspace wizard; **unbinding asks first** (sessions and history stay readable, new remote calls are refused) |
118
+ | Port forwarding | A sidebar **"Ports"** page: lists the remote host's listening TCP ports (`ss`, falling back to `netstat`) and forwards any of them to a local port in one click, with the local URL for copying/opening. Manual rules ("remote address:port → local port, which may be auto-assigned") are supported too. **The local listener binds `127.0.0.1` only** (`ssh -L` semantics — never exposed to the LAN); each rule has its own channel budget and never consumes one of the six exec/SFTP slots. An SSH drop or the idle eviction does not kill the listener: the next local connection simply re-dials. Rules live in the browser (restored after a reload) and every one can be stopped; disabling the plugin, deleting the host, or unloading it releases the local ports. When the remote has neither `ss` nor `netstat`, or the probe times out or is interrupted, the panel says "cannot enumerate" instead of showing an empty list |
119
+
120
+ ### Hosts and transport
121
+
122
+ | Capability | Notes |
123
+ | --- | --- |
124
+ | Host management | CRUD + connectivity test; key / password auth; config in `$DSH_HOME/dsh-remote.json` (0600), independent from `dsh-ssh.json` |
125
+ | Key bootstrap | One click generates a dedicated keypair on password hosts and deploys `authorized_keys`, key auth from then on |
126
+ | Push pipeline | Remote arch/OS probe → version compare → skip-if-same / else push; the executable channel pushes a self-built helper. A failed deploy no longer retries on every remote file operation: it backs off from **5 seconds up to 5 minutes**, and the Settings "Push" button forces an immediate retry; **an automatic push (first contact or upgrade self-heal) raises a bottom-right toast on success** (`alias: pushed remote helper <version>`), while a manual push stays quiet (Settings already shows its state) |
127
+ | Remote files | SFTP browse / read / write / create / delete / rename. Boundaries hardened: 0-byte files no longer deadlock, and every SFTP operation times out at 60s and releases its channel; **a single directory listing is capped at 20000 entries** (the first 20000 after sorting — directories first, then names — announced in the host log; the protocol carries no "truncated" field, so the UI has no marker); **a save goes through a side file and a rename** (server-side `posix-rename` when available, otherwise backup-rename-rollback), **writes through symlinks** (the link itself survives) and keeps the mode bits **on a best-effort basis**; SCM status parsing unquotes git's C-quoted paths (any name with whitespace is quoted) |
128
+ | Remote terminal | ssh2 PTY + WebSocket, xterm rendering (copy-paste/theme-follow/reconnect-on-refresh); **a reattach only takes over, it does not resize** (a page reload no longer shrinks a running shell to 80×24); an output backlog applies real backpressure to the far end; **frames are capped at 1 MiB**, and pastes past 64 Ki characters are chunked on code points by the client instead of dropping the connection |
129
+ | Concurrent channels | At most **6** remote channels per host at a time (no longer colliding with the far end's sshd `MaxSessions`); the 7th queues for up to **30 seconds** and then fails with `remote host <alias> is busy` instead of piling on connections |
130
+ | Monitor | A sidebar **"Monitor"** page samples one host or every host **only while the panel and the page are visible**, at the configured refresh interval (5 s by default; 5/10/30 s in its settings): CPU, memory, disk, load, network rate, temperature and uptime, with 60-point history curves plus manual refresh and pause. The scope is "current host / a named host / all hosts" and survives a reload. The **first sample reports CPU% and the network rate as unknown** (both are deltas and need a second sample), and a non-Linux host shows unknown instead of 0. The Host caches one sample per alias for 3 seconds and joins concurrent requests, so one sample uses one exec channel and never the port-forward budget. Samples live in memory only — nothing is written to disk |
131
+ | Timeouts and process cleanup | Ordinary git commands default to 300 s (configurable); the **network verbs (fetch/pull/push/sync) default to 20 minutes with a 30-minute ceiling**. exec runs in its own session (`setsid --wait`); on timeout OR cancel it sends TERM and **escalates to KILL after 3 seconds**, reaping the child processes with it; a host without `setsid --wait` is detected by a one-shot probe and falls back to the old behaviour, with a host-log line saying the timed-out remote command may still be running; **directory / multi-selection archive downloads carry a 600 s server-side budget** (remote `timeout -k 3 600`; a host without GNU `timeout` falls back to the unbudgeted old behaviour) and fail with the real reason when it expires |
132
+ | Git graph | Remote repo status + branches + SVG commit graph + commit details/contents/diff pane (exec + frontend parsing, zero Host additions) |
133
+ | Import | One-click import from `~/.ssh/config` and from an existing `dsh-ssh.json` (read once, no coupling); `Host a b` multi-pattern entries are expanded one by one, `Include` is reported as not expanded instead of being silently dropped, and every skipped host names an actionable reason (no User / no IdentityFile / invalid port …) |
134
+ | Environment check | An "environment check" per host: one remote command probes OS/kernel, glibc, `git`, `ripgrep`, `tar`, `setsid --wait`, `$HOME` free space, CPU/memory, the deployed helper version and sshd's `MaxSessions`, shown as a three-state table (**available / missing / unknown**). "Could not determine" is reported as **unknown**, never as "missing" (insufficient permission, unparseable output and a dropped link are all unknown); every row keeps the remote's own words, stderr is merged rather than discarded, and the whole report copies in one click |
135
+
136
+ ### Agent capabilities
137
+
138
+ | Capability | Notes |
139
+ | --- | --- |
140
+ | Agent tools | `remote_hosts` / `remote_exec` / `remote_read` / `remote_write` / `remote_ls` |
141
+ | **P2 transparent remote execution** | Native `read/write/edit/bash/glob/grep/jobs` inside remote workspaces run directly on the far end |
142
+ | **P2 remote apply_patch** | The Remote preset enables `apply_patch` (**an intentional divergence from stock's `applyPatch: false`**): its Update/Delete/Move operations call `fs.patchText` / `deleteFile` / `moveFile`, which route to the helper's `fs.patch` / `fs.delete` / `fs.move` (wire protocol 3), so remote files really can be patched, deleted and moved instead of answering "not supported" |
143
+ | **P3 remote @ references** | `@` in remote sessions completes remote files (fileReferences router: scoped live listings / bare queries via a remote rg index) |
144
+
145
+ ## Project structure
146
+
147
+ ```text
148
+ dsh_remote_vs/
149
+ ├── cordis.patch.yml # composition: plugin row + private local realm + routers + preset-remote
150
+ ├── src/
151
+ │ ├── index.ts # plugin entry: store/pool/worlds/routes/tools/preset-switch wiring
152
+ │ ├── protocol.ts # frontend/backend wire contract (route table + pure types, shared)
153
+ │ ├── paths.ts # four-piece addressing under $DSH_HOME (store/keys/build cache/alias dirs)
154
+ │ ├── store.ts # host + binding + tombstone persistence (0600 JSON, atomic writes)
155
+ │ ├── pool.ts # ssh2 long-lived pool (exec/shell/sftp/putFile, TOFU host keys)
156
+ │ ├── sftp.ts # remote file engine (SFTP windowed reads-writes/tree ops)
157
+ │ ├── keygen.ts # password-host key bootstrap (generate→deploy→flip)
158
+ │ ├── deploy.ts # push pipeline (probe/compare/ship/double-verify/manifest)
159
+ │ ├── importers.ts # ssh_config / dsh-ssh.json parsing importers
160
+ │ ├── routes.ts # /api/dsh-remote/* route table + terminal WebSocket upgrade
161
+ │ ├── terminal.ts # PTY session registry (reconnect-on-refresh/disconnect cleanup)
162
+ │ ├── forward.ts # local port-forward manager (direct-tcpip channels / one listener per rule / budgets)
163
+ │ ├── listen-ports.ts # remote listening-port probe (ss/netstat command + pure parser)
164
+ │ ├── metrics.ts # host-monitor probe (one POSIX /proc command + pure parse/CPU·net deltas)
165
+ │ ├── monitor.ts # monitor sampler (per-alias TTL cache/in-flight join/counters/forget)
166
+ │ ├── tools.ts # the 5 Agent tool definitions
167
+ │ ├── http.ts / loopback.ts # JSON body IO + loopback trust fence
168
+ │ ├── git-format.ts # git command builders + pure frontend parsing (zero Host additions)
169
+ │ ├── git-ops.ts # the full remote git surface: status/diff/branch/remote/stash/commit/hunk patch builders + parsers
170
+ │ ├── fs-ops.ts # remote file-operation command builders (copy/move/remove/stat)
171
+ │ ├── search-ops.ts # remote content search (grep builder + NUL-separated parser + match splitting)
172
+ │ ├── p2/ # ── P2 transparent routing ──
173
+ │ │ ├── worlds.ts # world decisions (cwd key/alias/tombstones) + remote RPC/FS/proc contexts
174
+ │ │ ├── helper-rpc.ts # helper wire protocol over an ssh2 exec channel (handshake/heartbeat)
175
+ │ │ ├── router-fs.ts # transparent fs router (target→world map/path translation/policy rewrite)
176
+ │ │ ├── router-subprocess.ts # transparent process router (argv0 reduction/pwsh gate)
177
+ │ │ ├── ssh-proc.ts # ssh2 process runtime (setsid group kill/marker/stdin/spill)
178
+ │ │ ├── shell-bash.ts # routed bash executor (local verbatim/remote strips DSH_*)
179
+ │ │ ├── router-spill.ts # transparent spill router (session world key/remote dir)
180
+ │ │ ├── router-refs.ts # transparent @ reference router (agent world key, P3)
181
+ │ │ ├── file-refs.ts # remote @ search (live fs-ssh listings/rg index/ported stock scoring)
182
+ │ │ ├── bridge.ts # private-realm local publishes (localFs and other early services)
183
+ │ │ └── bridge-refs.ts # standalone refs bridge (local-refs needs workingDirectory: must split)
184
+ │ └── client/ # ── browser half (React, bundled into lib/client.js) ──
185
+ │ ├── index.tsx # surface decision (better-first/settle-boost/native fallback) + settings + directoryFlow takeover
186
+ │ ├── store.tsx # module-level state shared by both surfaces (useSyncExternalStore; open files/terminals/view live here)
187
+ │ ├── RemoteRoot.tsx # sidebar surface: VS Code activity rail (explorer/search/SCM/history/editor/terminal/workspaces)
188
+ │ ├── RemoteEditorView.tsx # conversation-view surface (the "remote editor" tab next to 对话/轨迹, full width)
189
+ │ ├── RemoteExplorer.tsx # explorer: tree + context menu + file ops + @ references + status marks
190
+ │ ├── drag-expand.ts # drag-hover auto-expand (pure state machine, shared by both drag paths)
191
+ │ ├── SearchView.tsx # search panel: name / content modes + Aa/ab_/.* + grouped hits + jump
192
+ │ ├── EditorPane.tsx # editor pane: tabs + info bar (build stamp / tok count) + image/MD/HTML preview
193
+ │ ├── FloatingEditorWindow.tsx # floating window frame (title-bar drag/8-way resize/maximize/ball minimize/font zoom)
194
+ │ ├── float-tab-trigger.ts # double-click on the "remote editor" tab (the tab row is the host's, so label-based)
195
+ │ ├── FloatingPlaceholder.tsx # "docked elsewhere" placeholder + dock button left on the other surfaces
196
+ │ ├── float-editor.ts # window geometry/resize/surface rules (pure; driven directly by the self-check)
197
+ │ ├── live-editor.ts # live buffer + scroll/caret handoff across a surface change
198
+ │ ├── CodeEditor.tsx # CodeMirror wrapper: grammar table/theme/find widget/jump/fallback wiring
199
+ │ ├── scm/ # ── source control ──
200
+ │ │ ├── ScmPanel.tsx # changes/staged/untracked + per-file and per-hunk actions + commit box
201
+ │ │ ├── DiffView.tsx # side-by-side diff (top scrollbar/hunk buttons/editable after side)
202
+ │ │ ├── HistoryPanel.tsx # SVG commit graph + resizable/expandable commit-details pane
203
+ │ │ ├── CommitPane.tsx # details/contents/diff tabs + patch toolbar + context menus
204
+ │ │ ├── commit-model.ts # patch blocks/line numbers/counts/directory grouping/file stepping (pure)
205
+ │ │ ├── actions.ts # remote git action layer (over the exec channel)
206
+ │ │ ├── diff-model.ts # unified diff → side-by-side row projection (pure)
207
+ │ │ └── status-map.ts # status bucketing + tree marks (pure)
208
+ │ ├── vsc/ # ── VS Code skin and controls (zero new runtime deps) ──
209
+ │ │ ├── kit.tsx / vsc.css # icons/dialogs/context menu/segmented control + all styles (scoped to .rvs-root)
210
+ │ │ ├── editor-palette.ts # Dark+/Light+ palette + fixed class names (rvs-ck-*)
211
+ │ │ ├── editor-theme.ts # editor chrome theme (live light/dark swap)
212
+ │ │ ├── editor-langs.ts # file extension → CodeMirror grammar
213
+ │ │ ├── fallback-highlight.ts# coloring used when no grammar matched (via tokenize.ts)
214
+ │ │ ├── FindWidget.tsx # Ctrl+F find widget (pinned top-right)
215
+ │ │ ├── reveal-line.ts # jump + landing-line highlight
216
+ │ │ ├── tokenize.ts / markdown.tsx # read-only pane tokenizer / dependency-free markdown renderer
217
+ │ ├── NativeExplorer.tsx# native page type definition + seat body (no-sidebar fallback)
218
+ │ ├── composer.ts / use-remote-chat-target.ts / selection-popup.ts # remote @refs/selection-to-chat
219
+ │ ├── ai-review.ts # AI review prompt builder (single diff / whole commit, byte tiers, pure)
220
+ │ ├── api.ts # typed fetch wrapper over /api/dsh-remote
221
+ │ ├── MonitorView.tsx # monitor panel (one/all hosts, curves, pause/refresh, persisted scope)
222
+ │ ├── metrics-model.ts # monitor model (history window/sparkline geometry/capacity+rate formatting)
223
+ │ ├── HostsView / WorkspacesView / WorkspaceWizard / TerminalView / XTerm / PortsView / Dialog
224
+ │ ├── SettingsHosts.tsx # settings occupants (host mgmt/binding list, self-fetching)
225
+ │ ├── DirectoryFlow.tsx # native entry occupant (local dual-mode/remote wizard)
226
+ │ ├── RemoteDirectoryPicker.tsx# remote directory browser dialog
227
+ │ └── i18n.ts / theme.ts / ui.tsx # bilingual dictionary/theme signal/shared styles
228
+ ├── vendor/dsh-remote-helpers/ # helper seeds (shipped, seeded into cache at startup, see below)
229
+ ├── docs/ # local-only working docs (only docs/media/ screenshots ship)
230
+ │ ├── MAINTENANCE.md # local-only (.gitignore), not shipped: upgrade impact, checklist, pitfalls, release
231
+ │ ├── VERSION-HISTORY.md # local-only: per-release change log (0.7.1 → 0.23.0)
232
+ │ └── GATES.md # local-only: local gate inventory and measured assertion counts
233
+ ├── locale/ # bilingual plugin metadata
234
+ └── lib/ # build output (**must be committed**; only .map is ignored; restart after link install)
235
+ ```
236
+
237
+ `vendor/dsh-remote-helpers/` (committed) holds helper seeds: at startup the plugin spreads them into
238
+ `$DSH_HOME/dsh-remote-helpers/` (copy-if-absent, never overwrites), so fresh installs can push right away.
239
+ When a new helper is built, swap the 5-piece set (tarball + sha256 + helper.json + `glibc-ceiling.patch` + `ssh-helper-runtime-deps.patch`)
240
+ into vendor, delete the three old-version files, and commit (details live in the local-only `docs/MAINTENANCE.md` §4, which is gitignored and not distributed).
241
+
242
+ `.spike/` and `scripts/` (both gitignored, **never distributed with the repository**) hold the
243
+ development-time verification and self-check scripts: `.spike/` has the live-host ones — `p2-router.ts`
244
+ main regression (real remote + real Cordis + real router classes) and probes like `grep-probe.mjs`
245
+ (build with the local `tsconfig.scratch.json`), plus `model-check.mjs` / `reveal-check.mjs` /
246
+ `fallback-check.mjs` / `client-load-check.mjs` / `tool-schema-check.mjs` which need no host at all;
247
+ `scripts/` has the plain-node regression gates (`node scripts/check-*.mjs`, with `verify-lib.mjs`
248
+ checking the build artifact). Both are covered under "Development".
249
+
250
+ ## Remote workbench (VS Code style)
251
+
252
+ ![The sidebar's four views: files, search, source control, history](docs/media/sidebar-views.gif)
253
+
254
+ Both surfaces share one state module (`store.tsx`): **the sidebar "Remote Workspace" page** (a standalone tab when
255
+ `dsh-better-sidebar` is installed, otherwise the native right-Sidebar page) and **the conversation-view
256
+ "remote editor" tab** (next to 对话/轨迹, giving the code area full width).
257
+
258
+ - **Activity rail**: explorer / search / source control / commit graph / editor / terminal / workspaces.
259
+ A panel stays mounted after its first visit, so switching back neither refetches nor flashes. While it is
260
+ hidden it does **no remote work** (directory listings, the SCM stash/branch/remote queries and editor
261
+ image reads all wait for the next foreground pass), and visibility is MEASURED on the plugin root
262
+ (IntersectionObserver) instead of being taken from a host prop.
263
+ - **No blank wait when switching workspaces**: the last git state read for each (workspace, repository
264
+ directory) is kept in memory, so switching back paints the change list, branch and tree marks **in the
265
+ same frame** and re-reads behind it. The panel says "cached · refreshing" meanwhile; the change list and
266
+ the stage/commit/discard buttons still act on that workspace (⟳ and "reset repository directory" are
267
+ disabled while the background read runs — pressing them would only queue a second walk of the same tree).
268
+ One git read per repository DIRECTORY at a time (changing the directory lets the two directories' reads run
269
+ side by side — they are two different walks); a manual refresh's answer is always post-click (it queues
270
+ after the running read); a read of a workspace you left behind only fills its own cache and never repaints;
271
+ a failed background read keeps the list and shows why instead of declaring the workspace "not a
272
+ repository". The first visit to a workspace still waits — cache cannot invent a read.
273
+ - **Editor**: tabs plus an info bar (path, language, **build stamp**, `tok N` coloured-token count,
274
+ saved state, reload/save). Those three marks exist for troubleshooting: the stamp answers "is the
275
+ browser running the bundle I just built?", `tok 0` answers "did a grammar match this extension?".
276
+ - **Floating editor**: "Open in floating editor" from the file-tree / search-hit / source-control context
277
+ menus, or double-click the "remote editor" tab, lifts the editor into a window above the shell (same tabs
278
+ and buffers; closing or docking puts it back on its original surface). Drag the title bar, resize from the
279
+ eight edges/corners, maximize/restore; **minimize to a 44px floating ball** (no full-width bar — park it in
280
+ any corner, click/Enter restores it, and it shows a dot while there are unsaved edits); zoom the text with
281
+ `Ctrl+wheel`; unsaved text is explicitly handed over between the main surface, the floating window and tab
282
+ switches (the disk-side baseline is kept separately, so the dirty mark can never be mistaken for saved).
283
+ - **Find and jump**: `Ctrl+F` opens a widget pinned to the editor's top-right corner
284
+ (`position: fixed` anchored to the editor's rect, so no ancestor scroller can carry it away);
285
+ a selection is carried into it by `Ctrl+F`; a jump from the search results centres the line and
286
+ lights it up.
287
+ - **Terminals**: tabbed sessions with the session id persisted one by one, so a page refresh reattaches
288
+ to the shells that are still running; **a reattach only takes over, it does not resize** (a live shell is
289
+ never shrunk to 80×24 — the true size comes from the one tab that can measure itself, sent as a `resize`
290
+ frame); a session is kept for **10 minutes** after its last socket goes away before the remote shell is
291
+ closed (it used to be kept forever, so closing the browser left the shell holding an sshd session slot).
292
+ - **Known limits (stated honestly)**:
293
+ - There is **no public API to select the "remote editor" view**; the plugin can only click the shell's
294
+ own tab by its label and toasts a hint when that fails (`revealEditor()`).
295
+ - Untracked directories arrive as a **single `dir/` row**; clicking it **expands** the files inside
296
+ (one path-limited `git status -uall -- dir/`, so the cost tracks the directory, not the repository;
297
+ click again to collapse). An expansion is a snapshot of the moment it was opened — collapse and
298
+ re-expand to refresh it.
299
+ - Opening a file is capped at 8MiB (official helper constant); beyond that it is shown read-only, and the diff's after-side is read-only for such files too (a truncated prefix is never written back).
300
+ - A save checks the remote baseline it was opened from (mtime and size): if the file was written by someone else in the meantime (an agent through the transparent route, a terminal, another editor) the save is **refused** and offers "overwrite / load remote version / show difference" instead of silently replacing their work. This **narrows** the race rather than closing it: SFTP reports mtime in whole seconds, so a same-second change of the same length is still undetectable, and a window remains between the check and the moment the bytes land: a save writes a side file and then atomically renames it, so a write by someone else during that window (seconds for a large file) is still overwritten — the difference is going from "blind whole-file write" to "a much smaller window". Programmatic writes (agent tools, helper push, deploy manifest) carry no baseline and behave exactly as before.
301
+ - The find widget floats above the code (like VS Code) and takes no layout space.
302
+ - Output backpressure is **per shell**: one tab that cannot keep up pauses every tab attached to that
303
+ shell — a deliberate trade, preferring to hold the remote command back on behalf of the slowest
304
+ consumer over letting host memory grow without bound.
305
+ - A directory listing past 20000 entries is truncated, and since the protocol has no "truncated" field
306
+ the UI shows **no marker at all** — only the host log line
307
+ `listing <path> on <alias> shows 20000 of N entries`.
308
+ - **Monitor limits**: sampling happens only while the Monitor panel is the visible view AND the page is
309
+ in the foreground (hidden means zero remote traffic); the complete metric set comes from Linux
310
+ `/proc`, so other platforms show unknown; temperature exists only when the host exposes a thermal
311
+ zone (many VMs do not); CPU% and the network rate are deltas, so the **first frame is unknown**;
312
+ samples live in memory only and the curves restart after a page reload.
313
+
314
+ ## Session change review (Cursor style)
315
+
316
+ ![Session change review: the panel lists the files this session changed, opening one paints whole-line and intra-line differences, the top-right control steps through the changes, and hovering reverts a single change](docs/media/session-change-review.gif)
317
+
318
+ The **collapsible** panel above the composer (titled "本次改动") answers, per **session**, "what did this turn
319
+ change?". Its data comes from the plugin's own change ledger (`/api/dsh-remote/changes`), not from DSH's
320
+ `workspaceChanges` — the latter cannot see a routed session at all (the probe measured 58 remote sessions
321
+ with zero change events).
322
+
323
+ - **The panel**: one row per file (file-type icon + relative path + `+a −b` on the right), aligned left and
324
+ right with the composer card; click the header to collapse/expand, `⟳` forces an immediate rescan. With no
325
+ changes it says "this session has not changed any file yet"; when it cannot compute, it states the
326
+ **specific reason** (see the limits below) instead of handing you an empty list to guess about.
327
+ - **Clicking a file** opens it in the remote editor with change marks: added lines get a **green line
328
+ background**, deleted characters are drawn as an **inline struck-through chip** (a deleted character does
329
+ not exist in the new file, so it can only be an inserted widget), and the left gutter carries a change bar.
330
+ - **Jumping between change points**: the floating `n/N ↑↓` control at the editor's top-right
331
+ (`Alt+Shift+Cmd/Ctrl+↓/↑`) cycles through them; typing in the editor invalidates the marks and says
332
+ "position may be out of date".
333
+ - **Undo this change**: hover a changed line and click → remote `git apply -R`. When the context no longer
334
+ matches, the far end refuses outright (not one byte of the file changes); a tab with unsaved edits is
335
+ refused first, so a remote patch can never overwrite your buffer; on success the caret stays where it was
336
+ and the marks are re-read (they do not simply vanish because something was undone).
337
+ - **Follow the session's workspace**: the sidebar, the editor's dropdown and the file tree all follow the
338
+ workspace the **current session** lives in; after a manual switch they are not pulled back within that
339
+ session, and a new session follows again. The capability lives in the store, so it works even when **the
340
+ sidebar was never opened**; clicking a changed file is "show me this result", not a manual switch.
341
+ - **Repository directory**: the one the user picked under Source control → repository directory always wins;
342
+ when the session root is not a repository, a single candidate one level below is adopted automatically,
343
+ while several candidates produce an explicit hint to set it in Source control.
344
+
345
+ **Known limits (stated honestly)**:
346
+
347
+ - The baseline is the **session start**, not HEAD: untracked files that already existed before the session
348
+ began are not counted as this session's work.
349
+ - Tracked files refresh when a **turn ends** (the panel polls every 3 seconds as a backstop, so the numbers
350
+ usually catch up within a second or two); **new files** created in a shell are found by a **slow scan**
351
+ whose single-run budget is up to **3 minutes**, re-run at a self-tuning interval (at least 5 seconds,
352
+ naturally longer on a huge checkout). `⟳` forces an immediate rescan.
353
+ - A non-git workspace, or one holding several repositories with no repository directory set, shows the exact
354
+ reason (`no git repository at the workspace root, and N candidates below it — set the repository directory
355
+ in Source Control`) rather than an empty list.
356
+ - Binary and oversized files are marked "binary / too large" on the row and get no character-level diff;
357
+ **non-UTF-8 text (GBK and friends) is treated as binary** (no counts, no undo) so it cannot produce
358
+ garbage numbers and an undo that always fails.
359
+ - When the untracked scan gives up (e.g. the far end refuses), the panel **states the reason** and keeps the
360
+ refresh entry point instead of silently listing fewer rows.
361
+ - Undo carries **provenance** (session / binding / repository directory), so a patch can never be applied to
362
+ another host after switching sessions or bindings; a file this session created whole is not offered for
363
+ undo (a reverse patch must never delete an untracked file).
364
+
365
+ ## P2 transparent remote execution (Windows native)
366
+
367
+ Single-Host mixed routing: native tools dispatch by which world the session cwd lands in — remote aliases go
368
+ over helper RPC (fs) / ssh2 (processes), local stays untouched; both share one Host and one GUI.
369
+
370
+ - Alias dirs: `$DSH_HOME/remote-ssh/aliases/<id>` (empty shells, routing keys only), auto-registered into the native workspace list as `<server> > <base>`
371
+ - Routing switch (dropdown at the top of Settings → Remote hosts; underneath it is profile patch `- id: remote-vs`, `config.routingMode`, volatile, no restart):
372
+ default `enforce` (real routing); switch to `off` (pure local passthrough) / `shadow` (logs, still local) as debugging escapes
373
+ - New workspace: the native "Add workspace…" entry is adopted (local/remote dual tab; remote leg = host→push→bind wizard)
374
+ - Presets: a `Remote` preset (bash toolset); under enforce, new remote sessions switch to it automatically (default preset only, never overrides an explicit choice)
375
+ - Ground truths (measured, not assumed):
376
+ - Remote `grep/glob` call remote `rg` through routing (both measured hosts ship rg 13; no remote rg means no hits)
377
+ - Whole reads >8MiB report `FS_TOO_LARGE` (official helper ceiling) — use streaming/paged reads; **writes are uncapped** (a 46MiB whole write passed live)
378
+ - Oversized process output lands in a Host temp spill file (`readFrom` returns tail + path, full text lives in the file — same as stock)
379
+ - After unbinding, new calls are explicitly refused (fail-closed tombstones), history stays readable
380
+ - Disconnects: in-flight calls are not replayed; new calls reconnect automatically; the link state is shown explicitly in the top bar / editor info bar, and while it is down the editor and cached directories stay **read-only visible** (see "Connection status and offline read-only")
381
+ - Verify: `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/p2-router.js`
382
+ (real remote + real Cordis + real router classes, 61/61; P0 routing and GUI need a Host restart + smoke pass)
383
+ - Details: the local-only `docs/MAINTENANCE.md` (§2 coupling points, §3 checklist)
384
+
385
+ ## Self-built helper (P1)
386
+
387
+ Upstream never published helper binaries (all Release assets are empty), so this plugin builds its own:
388
+
389
+ - Build machine: WSL2 Ubuntu-22.04 (glibc 2.35, matching the remote targets), build-host Node v24.21.0 + pnpm 11.28.5;
390
+ the node **embedded by pkg is v24.22.3** (that is what `helper.json`'s `nodeVersion` records)
391
+ - Sources: the `dsh-v0.2.2-rc.4` tag (commit `3f321d32…`) — the **build baseline tracks the wire protocol version, not the Host version**;
392
+ this generation is **protocol 3 (G2)**: besides the hello protocol literal and `policySchema.additionalWritableRoots`,
393
+ it adds `fs.patch` / `fs.delete` / `fs.move` (31 vs 28 methods). **"Protocol 3" does not imply those three methods**:
394
+ the G1 generation (`dsh-v0.2.2-alpha.2`) also reports protocol 3 but lacks them, so the helper must be built from a
395
+ G2 tag (≥ alpha.3)
396
+ - Command: stock script `pnpm exec tsx scripts/build-exe-for-ssh-helper.ts --target=node24-linux-x64`
397
+ - Deviation 1: no docker for the manylinux 2.28 rebuild, so a `DSH_GLIBC_CEILING`
398
+ env override was added (default stays 2.28); this build targets 2.35 (see `glibc-ceiling.patch`)
399
+ - Deviation 2: the upstream tag's own helper build path is missing two dependencies (`@deepseek-ai/dsh-error` is a
400
+ required peer, `@deepseek-ai/dsh-fs-patch` is never built into the runtime by `compileRuntime()`); without them the
401
+ closure gate aborts / the handshake fails with `ERR_MODULE_NOT_FOUND`. The patch is archived as `ssh-helper-runtime-deps.patch`
402
+ - Checks: stock `verify-ssh-helper-artifact.ts --archive=<tarball> --sandbox=required`, all 8 green
403
+ - Size and cache: the linux-x64 archive is **47 MB** (47,234,718 B); cache `$DSH_HOME/dsh-remote-helpers/`
404
+ (`*.tar.gz` + `.sha256` + `.helper.json` with binarySha256, feeding P2's helperHash)
405
+ - Full rebuild procedure for upgrades: the local-only `docs/MAINTENANCE.md` §4 (gitignored, not distributed)
406
+
407
+ ## Security model
408
+
409
+ - All `/api/dsh-remote/*` routes are loopback + same-origin only.
410
+ - Passwords / key passphrases are stored in plaintext in `dsh-remote.json` (0600) — same trust model as the existing SSH plugin.
411
+ - Pushed artifacts are sha256-verified both ways (tarball in, binary out); the helper install dir is separate from workspaces; the sidecar's `version`, platform and tarball path are whitelist-validated (no unvalidated string is interpolated into a remote shell line), and a failed install keeps the previous version.
412
+ - Host config writes are fsync'd and re-checked against a stamp (a concurrent Desktop/Web edit inside the read-modify-write window is replayed instead of silently overwritten).
413
+ - Remote sessions may read explicit local absolute paths (the tool spill-file contract requires it); acceptable under the same model trust — a known trade-off recorded in the local maintenance notes.
414
+ - **Port forwards bind `127.0.0.1` only**: another local process can reach one, which is exactly the `ssh -L` trust boundary (the local user account). The target is dialed **from the remote host**, so it can reach that host's private network; "open in browser" always builds an `http://` URL — a forwarded HTTPS service needs the scheme edited by hand.
415
+
416
+ ## Development
417
+
418
+ ```sh
419
+ pnpm install
420
+ pnpm run typecheck
421
+ pnpm run build
422
+ dsh plugin --profile web add link:<absolute path of this directory>
423
+ ```
424
+
425
+ **How a change goes live: `pnpm run build`, then restart `dsh web` — for the host half and the client half alike.**
426
+ **`lib/` is committed.** The package has no `prepare` script (pnpm 12 refuses to run one for a git
427
+ dependency), so a `dsh plugin add github:…` user receives the repository as it is: **after editing
428
+ source you must `pnpm run build` and commit `lib/` with it** (`node scripts/verify-lib.mjs` checks that the
429
+ entries are present, committed and loadable; the self-check scripts live on the maintainer's machine only,
430
+ see below).
431
+ The Host reads plugin bundles into memory at startup (`initialBundleSnapshot`: it stats mtime/ctime/size into a
432
+ revision, then reads the bytes; the response carries `Cache-Control: public, max-age=31536000, immutable`), so a
433
+ **client-only** change (`src/client/**`) behaves exactly the same way: a browser refresh — `Ctrl+Shift+R`
434
+ included — only re-fetches the bytes captured at startup, under the same `rev`. How to tell:
435
+
436
+ 1. Each build injects a stamp (`MMDD-HHmm`) into `lib/client.js`, shown at the right of the editor info bar;
437
+ 2. Restart `dsh web` → refresh the page: **the stamp must change** (if it does not, you are still on the bytes
438
+ captured at startup);
439
+ 3. For colour issues, read `tok N`: `0` means no grammar matched the extension AND the fallback colorer
440
+ did not take over (the console line next to it names the file).
441
+
442
+ > The one exception is DSH's own development watcher (`pnpm run dev:web`, via `ClientModuleRegistry.rebuilt`);
443
+ > there is no watcher on a plugin user's side and `dsh web --help` has no watch option, so "restart" is the rule.
444
+
445
+ Self-checks (no host, no DSH, a few seconds each):
446
+
447
+ ```sh
448
+ node .spike/client-load-check.mjs # really evaluates the client modules: load-time errors tsc/bundler/other harnesses miss
449
+ node .spike/tool-schema-check.mjs # all 5 agent tools: run execute, then validate the result with the RUNTIME's own validator
450
+ node .spike/model-check.mjs # 55 checks: real git output → parsers, diff model, hunk patches, class↔CSS contract
451
+ node .spike/reveal-check.mjs # 5 checks: jump target, landing highlight, repeat jump in one editor
452
+ node .spike/fallback-check.mjs # 12 checks: the fallback colorer colours java/cpp/shell in a real DOM
453
+ node .spike/editor-dom-check.mjs # 12 checks: a real CodeMirror in jsdom emits colour spans for java/shell/cpp
454
+ node .spike/i18n-check.mjs # zh/en dictionary consistency: no missing key, no orphan, matching placeholders
455
+ node .spike/ref-check.mjs # 32 cases: assertRef accepts real revision suffixes, rejects every injection surface
456
+ node .spike/status-check.mjs # runs the generated git commands in a real shell to prove exit codes are no longer masked
457
+ node .spike/cache-check.mjs # incremental token cache vs whole-document tokenizing, 9 languages × 8 edit shapes
458
+ node .spike/layout-check.mjs # height chain + scrollbar contract: header rows stay pinned, the bar is wide enough to grab
459
+ node .spike/viewstate-check.mjs # scroll+caret round trip across a remount (stateful scrollTop: tells "restored" from "reset")
460
+ node .spike/tabswitch-check.mjs # real React drives three wirings: both ref-reading ones must fail, reporting must pass
461
+ node .spike/letter-check.mjs # status letters: untracked `?` no longer collides with conflict `U`, plus both render sites
462
+ ```
463
+
464
+ `.spike/layout-fixture.html` (generated by `build-fixture.mjs`) is the fixture for
465
+ measuring layout in a browser: it mechanically inlines the **host's real slot CSS**
466
+ and the **shipped vsc.css**, so after a CSS change you re-run
467
+ `node .spike/build-fixture.mjs` and can measure the height chain, the scroll
468
+ container and the scrollbar width for real. Pure-CSS defects are invisible to
469
+ tsc, to the bundler and to jsdom — this fixture is the only place they reproduce.
470
+
471
+ `markdown-check.ts` has to be compiled first (it imports a `.tsx`, which Node cannot load):
472
+ `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/markdown-check.js`.
473
+
474
+ > `.spike/` is git-ignored, so these checks are local only and run in no CI. **Run them before quoting any
475
+ > number** rather than copying a figure out of any file — one `model-check` count drifted across the README,
476
+ > the local maintenance doc and the review reports as 44 / 48 / 55, while the harness actually prints 55/55
477
+ > (its source holds 57 `check(` call sites, 2 of them inside loops and reachable only on failure, which is
478
+ > exactly why "57 call sites" and "55 checks run" differ by 2).
479
+
480
+ The live-host regression is still `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/p2-router.js`.
481
+ Before touching anything for a new DSH release, read the local-only `docs/MAINTENANCE.md` (§2 coupling points, §3 checklist) — it is gitignored, so a clone will not have it. After any change (host half or client half) the mandatory steps are: `pnpm run build` → `node scripts/verify-lib.mjs` (entries present, committed and loadable) → restart `dsh web`; and before committing, run every local gate under `scripts/` (`node scripts/check-*.mjs`, 57 of them at the time of writing, plus `verify-lib.mjs` and the shared TS loader `_ts-hook.mjs`).
482
+
483
+ ## License
484
+
485
+ MIT © 2026 xiray-xia — see [LICENSE](./LICENSE).
486
+
487
+ The `vendor/` helper seed is built from DeepSeek Harness sources (MIT) at tag `dsh-v0.2.2-rc.4`
488
+ with the stock build script; see "Self-built helper" above for the exact procedure and the two
489
+ documented deviations (`glibc-ceiling.patch` and `ssh-helper-runtime-deps.patch` in the seed set).