dsh-linked-workspace 0.16.0 → 0.16.1
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/CHANGELOG.md +17 -0
- package/README.en.md +4 -2
- package/README.md +4 -2
- package/docs/API.md +2 -1
- package/docs/VERIFY.md +8 -4
- package/lib/client.js +94 -11
- package/lib/index.js +71 -32
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
English · [简体中文](CHANGELOG.zh.md)
|
|
4
4
|
|
|
5
|
+
## 0.16.1 — 2026-11-19
|
|
6
|
+
|
|
7
|
+
- The hover card's connection state now follows reality in both directions: the
|
|
8
|
+
page polls the new `hosts.status` (memory only, no dialling) every 6 seconds
|
|
9
|
+
and repaints just that one line, even while the card is open, so a host that
|
|
10
|
+
drops shows "connection lost" within seconds and one that recovers goes back
|
|
11
|
+
to "connected" without a reload.
|
|
12
|
+
- A missing remote folder is no longer reported as a dead connection: `remote_workspaces.test`
|
|
13
|
+
returns `exists: false` and leaves the host alone, so checking a workspace
|
|
14
|
+
whose directory was renamed elsewhere no longer turns every other workspace on
|
|
15
|
+
that host red.
|
|
16
|
+
- A recorded failure decays after 60 seconds (`STATUS_TTL_MS`) instead of
|
|
17
|
+
sticking forever: an error nobody has re-checked reads as "not connected",
|
|
18
|
+
and the next successful call sets the state again.
|
|
19
|
+
- HTML preview is no longer blocked by the editor's 2 MB ceiling: it reads with `preview`, which raises the cap to the 8 MB read cap, so a 7 MB plotly page opens; only files above 8 MB show "download it to the default folder and open it in a browser", and the doubled "无法预览网页:无法预览网页" wording is gone.
|
|
20
|
+
- HTML preview now uses `sandbox="allow-scripts"`: the page's own scripts run in a separate opaque origin (charts are no longer blank) and still cannot reach the DSH UI, host storage or tabs; the status chip reads "Sandboxed preview (scripts run, no access to the DSH UI)".
|
|
21
|
+
|
|
5
22
|
## 0.16.0 — 2026-11-16
|
|
6
23
|
|
|
7
24
|
- The workspace root no longer offers “Change permissions”, and the Host rejects it too: a stray 644 on the root makes the whole workspace look empty.
|
package/README.en.md
CHANGED
|
@@ -57,6 +57,8 @@ The plugin takes over the DSH sidebar/hero directory-selection hole; the dialog
|
|
|
57
57
|
3. **Remote workspace**: SSH host + remote directory + workspace name; the placeholder directory becomes a DSH workspace and sessions run on the server.
|
|
58
58
|
|
|
59
59
|
> Linked workspace rows no longer carry a `⇄` title prefix: a scoped stylesheet keyed on `data-row-key` swaps the host folder glyph for the workspace's own icon — two interlocking links for a linked workspace, a display with an outbound arrow for a remote workspace (normal local workspaces are untouched). When the SSH connection drops the row icon turns red, and the host's hover card gains one line under the name combining the SSH host with its live state (`RTX-PRO-6000-1 · Connected`, turning red with “Connection lost” once the link drops); a remote workspace shows the remote directory, a linked one shows both the remote and local directories. This is the only DOM-level adaptation of the host row; if DSH changes the row structure the selector stops matching and the original folder icon returns, with no other breakage.
|
|
60
|
+
>
|
|
61
|
+
> That state follows the real connection in both directions: the page asks the host for every host's state once every 6 seconds (memory only, it never dials), and only repaints that one line when the value actually changed — so a host that drops shows “Connection lost” within seconds while the card stays open, and one that recovers goes back to “Connected” without a reload. A single failure only describes that moment: an error nobody has re-checked decays to “Not connected” after 60 seconds, and “Test connection” finding a missing remote directory is no longer treated as a dead link, so it cannot paint the other workspaces on the same host red.
|
|
60
62
|
|
|
61
63
|
### Sidebar: “Linked Workspace Directory”
|
|
62
64
|
|
|
@@ -77,7 +79,7 @@ hover it for the total size and the used percentage.
|
|
|
77
79
|
- Coloured file-type icons (JS/TS/Python/JSON/Markdown/Shell/YAML/images/archives/config files…).
|
|
78
80
|
- **Tabs and editor**: up to 12 tabs, local and remote files share the same editor; line numbers, syntax highlighting (overlay), theme colours, `Ctrl/Cmd+S`, conflict prompt (reload / force save), read-only protection for binary and >2 MB files; the status bar shows encoding, line endings, line count and file size.
|
|
79
81
|
- **Find and replace**: `Ctrl/Cmd + F` opens an in-editor bar with a case-sensitive toggle, previous/next, a match counter, replace and replace all. Above 5000 matches the counter shows `5000+` while replace-all still edits the whole document; `Esc` closes it from the replace field too. The Markdown document panel has its own read-only find (`Ctrl+F`, counter, next/previous).
|
|
80
|
-
- **Image, CSV and HTML previews**: PNG/JPG/GIF/WebP/BMP/ICO/AVIF/SVG render in the content panel (up to 24 MB) with zoom buttons, `Ctrl/Cmd + wheel`, fit-to-window and 1:1; CSV/TSV open as a table with a Table/Source toggle (the source view stays editable), capped at 1000 rows × 80 columns. HTML/HTM render in a sandboxed iframe
|
|
82
|
+
- **Image, CSV and HTML previews**: PNG/JPG/GIF/WebP/BMP/ICO/AVIF/SVG render in the content panel (up to 24 MB) with zoom buttons, `Ctrl/Cmd + wheel`, fit-to-window and 1:1; CSV/TSV open as a table with a Table/Source toggle (the source view stays editable), capped at 1000 rows × 80 columns. HTML/HTM render in a sandboxed iframe whose scripts run in an opaque origin (charts draw, but the frame cannot reach the DSH UI or its storage); the cap is 8 MB, and beyond that the panel tells you to download the file and open it in a browser. Markdown previews strip scripts, event attributes and dangerous links.
|
|
81
83
|
- **Shortcuts**: `Ctrl/Cmd+S` save, `Ctrl/Cmd+W` close tab (prompting when dirty), `Ctrl+Tab` / `Shift+Ctrl+Tab` cycle tabs, `Ctrl/Cmd+B` toggle the directory panel, `Ctrl/Cmd+Shift+F` file search.
|
|
82
84
|
- **Auto save**: Settings → Linked workspaces → “Editor behaviour”; saves about one second after typing stops. With it off, use `Ctrl/Cmd+S`; unsaved changes trigger a confirmation before the page unloads.
|
|
83
85
|
|
|
@@ -188,7 +190,7 @@ The npm package is `dsh-linked-workspace`; released versions can also be install
|
|
|
188
190
|
- Remote workspaces and direct file APIs are confined to the configured remote root; linked-workspace tools are confined to the remote root, and local writes to the local root.
|
|
189
191
|
- Single-file saves are capped at 8 MB; mirror sync runs in the background (500 files / 50 MB by default, skipping oversized files), excludes `.git`/`node_modules`/caches, uses a 30 s per-file timeout and never blocks an HTTP request. “Transfer” and “Download to default folder” handle at most 150 files / 15 MB per run and report partial transfers.
|
|
190
192
|
- The page HTTP API accepts loopback same-origin requests only (remote deployments fall back to the DSH `connection` service's Host/Origin authentication).
|
|
191
|
-
-
|
|
193
|
+
- HTML previews run inside a `sandbox="allow-scripts"` iframe: the page's own scripts execute (so plotly-style charts actually draw) but in a separate opaque origin that cannot reach the DSH UI, host storage or tabs. Markdown/document previews still strip scripts, inline styles, event attributes and `javascript:`/`vbscript:` links, keeping safe links and image `data:` URLs.
|
|
192
194
|
|
|
193
195
|
## FAQ
|
|
194
196
|
|
package/README.md
CHANGED
|
@@ -57,6 +57,8 @@
|
|
|
57
57
|
3. **远程工作区**:SSH 主机 + 远端目录 + 工作区名称,创建后占位目录成为 DSH 工作区,会话直接跑在远端。
|
|
58
58
|
|
|
59
59
|
> 左侧工作区行不再带 `⇄` 标题前缀:插件用一份按 `data-row-key` 定位的样式表,把宿主文件夹图标换成工作区自己的图标——联动工作区是**双链环**,远程工作区是**显示器 + 出链箭头**,普通本地工作区不受影响。SSH 连接断开时该行的图标会变红;把鼠标停在行上,宿主那张悬停信息卡里名字下面会多出一行「SSH 主机 · 连接状态」(形如 `RTX-PRO-6000-1 · 已连接`,掉线后变红并显示「连接已断开」);远程工作区显示远端目录、联动工作区同时显示远端与本地目录。这是对宿主行结构的唯一 DOM 级适配;如果 DSH 以后更改行结构,选择器会自然失配并回退到原来的文件夹图标,不破坏其他功能。
|
|
60
|
+
>
|
|
61
|
+
> 这一行状态是**跟着实际连通性走的**:页面每 6 秒向宿主取一次各主机的连接状态(只读内存、不发起新连接),只有状态真的变了才重绘那一行,卡片开着时也会即时更新——主机掉线几秒内变「连接已断开」,恢复后自动回到「已连接」,不用刷新页面。一次失败只代表当时:没人再验证的旧错误 60 秒后降级为「未连接」;「测试连接」发现远端目录不存在也不会被当成断连,不会把同一台主机上的其它工作区一起标红。
|
|
60
62
|
|
|
61
63
|
### 右侧栏「联动工作区目录」
|
|
62
64
|
|
|
@@ -76,7 +78,7 @@
|
|
|
76
78
|
- 不同文件类型使用不同彩色图标(JS/TS/Python/JSON/Markdown/Shell/YAML/图片/压缩包/配置文件等)。
|
|
77
79
|
- **标签与编辑器**:最多同时打开 12 个标签,本地与远端文件共用内部编辑器;行号、语法高亮(叠层渲染)、主题配色、`Ctrl/Cmd+S` 保存、冲突提示(重新加载/强制保存)、二进制与 >2 MB 文件只读保护;状态栏显示编码、换行符、行数与文件大小。
|
|
78
80
|
- **查找/替换**:编辑器内 `Ctrl/Cmd + F` 打开查找条,支持区分大小写、上一个/下一个、命中计数、替换与全部替换;命中超过 5000 处时计数显示 `5000+`,全部替换仍作用于全文。替换框内按 `Esc` 也能关闭查找条。Markdown 文档面板另有只读查找(同样 `Ctrl+F`,支持计数与上下跳转)。
|
|
79
|
-
- **图片、CSV 与网页预览**:PNG/JPG/GIF/WebP/BMP/ICO/AVIF/SVG 直接在内容面板按图片显示(最大 24 MB),支持按钮缩放、`Ctrl/Cmd + 滚轮` 缩放、适应窗口和 1:1 原始大小;CSV/TSV 默认按表格显示,可在「表格 / 源码」间切换,源码视图仍可编辑保存,超过 1000 行或 80 列时只展示截断后的表格。HTML/HTM 以沙箱 iframe
|
|
81
|
+
- **图片、CSV 与网页预览**:PNG/JPG/GIF/WebP/BMP/ICO/AVIF/SVG 直接在内容面板按图片显示(最大 24 MB),支持按钮缩放、`Ctrl/Cmd + 滚轮` 缩放、适应窗口和 1:1 原始大小;CSV/TSV 默认按表格显示,可在「表格 / 源码」间切换,源码视图仍可编辑保存,超过 1000 行或 80 列时只展示截断后的表格。HTML/HTM 以沙箱 iframe 渲染(脚本在独立源里运行,图表能画出来,但拿不到 DSH 界面与存储;上限 8 MB,超过时提示改下载后用浏览器打开),Markdown 预览会移除脚本、事件属性与危险链接。
|
|
80
82
|
- **快捷键**:`Ctrl/Cmd+S` 保存当前文件;`Ctrl/Cmd+W` 关闭当前标签(未保存时提示保存/放弃/取消);`Ctrl+Tab` / `Shift+Ctrl+Tab` 切换标签;`Ctrl/Cmd+B` 显示/隐藏目录面板;`Ctrl/Cmd+Shift+F` 打开文件搜索。
|
|
81
83
|
- **自动保存**:设置 → 联动工作区 →「编辑器行为」中开启;停止输入约 1 秒后自动保存。关闭时使用 `Ctrl+S` 手动保存;有未保存文件时刷新/关闭页面会弹确认。
|
|
82
84
|
|
|
@@ -187,7 +189,7 @@ npm 包名为 `dsh-linked-workspace`,也可以从 npm 安装已发布版本(
|
|
|
187
189
|
- 直接远程工作区的读写限制在该目录内;联动工作区的工具限制在远端根目录内,本地写入限制在本地根目录内。
|
|
188
190
|
- 单文件保存上限 8 MB;镜像同步在后台执行,默认最多 500 文件 / 50 MB(跳过超大文件),默认排除 `.git`/`node_modules`/各类缓存目录,单文件读取 30 s 超时,不再阻塞 HTTP 请求。右键「传输」与「下载到默认文件夹」单次最多 150 文件 / 15 MB(超限会提示未全部传输)。
|
|
189
191
|
- 页面 HTTP API 只接受本机回环同源请求(远程部署时回落到 DSH `connection` 服务的 Host/Origin 鉴权)。
|
|
190
|
-
-
|
|
192
|
+
- HTML 预览跑在 `sandbox="allow-scripts"` 的 iframe 里:脚本能执行(plotly 这类图表才有内容),但处于独立的不透明源,访问不到 DSH 界面、宿主存储与标签页;Markdown/文档预览仍会移除脚本、内联样式、事件属性与 `javascript:`/`vbscript:` 等危险链接,只保留安全链接与图片 `data:` URL。
|
|
191
193
|
|
|
192
194
|
## 常见问题
|
|
193
195
|
|
package/docs/API.md
CHANGED
|
@@ -55,13 +55,14 @@ scope root, or absolute inside it.
|
|
|
55
55
|
| `hosts.credentials` | `{ hostId, password?, passphrase?, privateKey?, clear? }` | `{ hostId, authType, hasCredential, hasStoredPassword }` (stores the secret in the plugin's own `ssh-credentials.json`; `clear: true` deletes it) |
|
|
56
56
|
| `hosts.browse` | `{ hostId, path? }` | `{ path, parent, home, entries }` (dirs + files) |
|
|
57
57
|
| `hosts.df` | `{ hostId, path? }` | `{ disk: { path, size, used, avail, percent } \| null }` (free space of the volume holding `path`; defaults to the login home) |
|
|
58
|
+
| `hosts.status` | `{ hostIds? }` | `{ statuses: { [hostId]: { state, reason?, message?, latencyMs?, checkedAt? } } }` (in-memory snapshot of the pool, never dials; an `error` older than 60 s is reported as `idle`; defaults to every known host of the host list plus every workspace's host id) |
|
|
58
59
|
| `hosts.mkdir` | `{ hostId, path?, name }` | `{ path }` (creates `name` inside `path`; defaults to the login home; `409`/`FS_EXISTS` when it already exists) |
|
|
59
60
|
| `remote_workspaces.list` | `{}` | `{ workspaces: RemoteWorkspaceInfo[] }` |
|
|
60
61
|
| `remote_workspaces.create` | `{ hostId, remotePath, name? }` | `{ workspace }` |
|
|
61
62
|
| `remote_workspaces.get` | `{ id }` | `{ workspace }` |
|
|
62
63
|
| `remote_workspaces.update` | `{ id, name? }` | `{ workspace }` |
|
|
63
64
|
| `remote_workspaces.remove` | `{ id }` | `{ removedWorkspace, removedPlaceholder }` |
|
|
64
|
-
| `remote_workspaces.test` | `{ id }` | `{ ok, latencyMs?, exists?, type?, error? }` |
|
|
65
|
+
| `remote_workspaces.test` | `{ id }` | `{ ok, latencyMs?, exists?, type?, error? }` (a missing directory comes back as `exists: false` and leaves the host's connection state untouched) |
|
|
65
66
|
| `fs.list` | `{ linkedId?/remoteId?, path, limit?, offset? }` | `{ path, entries: RemoteEntry[], total, offset, limit, hasMore }` (default 500, max 5000). Listings are cached for 5 s for `offset > 0`; writes, mkdir, rename, move, delete, copy and transfers invalidate the cache. |
|
|
66
67
|
| `fs.read` | `{ linkedId?/remoteId?, path, maxBytes? }` | `FileRead` |
|
|
67
68
|
| `media.read` | `{ linkedId?/remoteId?, path }` | `{ path, size, mtime, mime, base64 }` (PNG/JPG/GIF/WebP/BMP/ICO/AVIF/SVG, max 24 MB) |
|
package/docs/VERIFY.md
CHANGED
|
@@ -75,6 +75,9 @@ Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-wor
|
|
|
75
75
|
3. **卡片里的目录**:远程工作区的卡片只显示**远端目录**绝对路径(例如 `/shared_data_ssd1/huangjh/code`,不显示本地占位目录);联动工作区的卡片显示两行——「远端 …」与「本地 …」两个绝对路径。
|
|
76
76
|
4. **断线变红**:让主机断开 SSH(例如在服务器上执行 `pkill -u <user> sshd`,或在网络中断开)→ 左侧栏该工作区行的图标变红(`#f85149`),悬停卡片里的状态行同样变成红色的「连接已断开」。
|
|
77
77
|
5. **自动恢复**:再次访问该工作区(打开目录树 / 刷新设置页)→ 连接重建后图标恢复常规颜色,悬停卡片里的状态回到「已连接」。
|
|
78
|
+
5b. **状态跟着实际连通性走(0.16.1)**:把鼠标停在某行上让卡片保持打开,然后让该主机掉线(`hosts.credentials { hostId, clear: true }` 丢掉长连接,再把该主机从 `known_hosts.json` 的指纹改坏;或在服务器上 `pkill -u <user> sshd`)→ 最多 6 秒后卡片那一行变成红色的「连接已断开」,**全程不刷新页面**;恢复指纹/主机后随便访问一次该目录,再等 ≤6 秒,同一张还开着的卡片自动回到绿色的「已连接」。
|
|
79
|
+
5c. **目录不存在不算断连**:在插件外用 `rm -rf` 删掉某个远程工作区指向的目录,再在设置页点它的「测试连接」→ 卡片给出「远端目录不存在」一类的提示,但 `hosts.status` 里该主机仍是 `connected`,同一台主机上的其它工作区**不会**被标红;对不存在的路径 `fs.stat` / `fs.list` 也只会返回 `FS_NOT_FOUND`,主机状态不变。
|
|
80
|
+
5d. **旧错误会过期**:制造一次真实失败(`hosts.status` 里该主机为 `error`)后什么都不做,等 60 秒以上 → `hosts.status` 里它变成 `{ state: 'idle' }`,卡片显示「未连接」而不是一直红着;随后任意一次成功的目录访问会重新写回 `connected`。
|
|
78
81
|
6. **命名**:设置左侧导航显示「联动工作区」,页面标题显示「联动&远程工作区」;「添加工作区」弹窗第三个页签显示「远程工作区」。
|
|
79
82
|
|
|
80
83
|
## 深色主题(0.11.0)
|
|
@@ -196,9 +199,10 @@ Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-wor
|
|
|
196
199
|
1. 打开 PNG/SVG:图片默认适应窗口;点「适应窗口」重新适配,「1:1」恢复原始像素。
|
|
197
200
|
2. 点 `−` / `+` 时缩放比例按 20% 步进,状态栏百分比同步;`Ctrl/Cmd + 滚轮` 可连续缩放,最小 5%、最大 800%。
|
|
198
201
|
3. 放大后图片区域出现滚动条,可查看四周;缩小后图片保持居中,不出现拉伸变形。
|
|
199
|
-
4. 本地与远端各打开一个 `.html`/`.htm`:内容面板以 iframe 渲染页面,状态栏显示 HTML
|
|
200
|
-
5.
|
|
201
|
-
|
|
202
|
+
4. 本地与远端各打开一个 `.html`/`.htm`:内容面板以 iframe 渲染页面,状态栏显示 HTML、大小和「沙箱预览(脚本可运行,无法访问 DSH 界面)」。
|
|
203
|
+
5. 页面自带的脚本在沙箱里执行:打开一个 plotly 之类靠 JS 画图的页面,图表应正常绘制(沙箱是不透明源,拿不到 DSH 界面、宿主存储与标签页)。
|
|
204
|
+
5b. 打开一个 2–8 MB 的 HTML(例如 7.1 MB 的趋势图):应正常预览整页;超过 8 MB 的页面显示「文件 X 超过预览上限 8.0 MB,请右键『下载到默认文件夹』后用浏览器打开」,不再出现重复的「无法预览网页:无法预览网页」。
|
|
205
|
+
6. 读取失败的 HTML(权限/二进制)显示错误提示和重试按钮。
|
|
202
206
|
|
|
203
207
|
## 安全、分页与可访问性(0.8.2)
|
|
204
208
|
|
|
@@ -250,7 +254,7 @@ Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-wor
|
|
|
250
254
|
10. **悬停展开**:拖拽停在折叠目录行 700 ms:该目录应自动展开。
|
|
251
255
|
11. **host-api**:`node test/host-api.mjs` 应为 33 步全部通过(0.15.0 起含 `meta.info`)。
|
|
252
256
|
|
|
253
|
-
## 提示、对话框与下载(
|
|
257
|
+
## 提示、对话框与下载(0.16.1)
|
|
254
258
|
|
|
255
259
|
1. 目录栏标题右侧出现可用空间(如「7983.64 GB」),悬停显示「可用 …(已用 17%)· 已用 / 总量」;换工作区后数字随之变化。
|
|
256
260
|
2. 对含 150 个以上文件的远端目录右键「下载到默认文件夹」:提示里带文件数与体积,并以「达到上限,未全部下载」结尾;下载目录里确实是 150 个文件。
|
package/lib/client.js
CHANGED
|
@@ -1958,6 +1958,15 @@ function attributeViolation(name, value, tagName) {
|
|
|
1958
1958
|
// but a full remote listing on a huge folder is expensive; 15 s keeps the
|
|
1959
1959
|
// tree fresh without hammering the SSH channel.
|
|
1960
1960
|
var REFRESH_MIN_INTERVAL_MS = 15000;
|
|
1961
|
+
// HTML previews read the whole document (a plotly/figure page is one big
|
|
1962
|
+
// inlined script), so they ask the Host for the 8 MB read cap instead of
|
|
1963
|
+
// the editor's 2 MB one.
|
|
1964
|
+
var PREVIEW_MAX_BYTES = 8 * 1024 * 1024;
|
|
1965
|
+
// Connection state is a live fact, not a property of the workspace: the
|
|
1966
|
+
// sidebar rows and the hover card poll the Host so a dropped socket turns
|
|
1967
|
+
// red within a few seconds and a recovered one turns back. The call reads
|
|
1968
|
+
// memory only (it never dials), so a short interval is cheap.
|
|
1969
|
+
var STATUS_POLL_MS = 6000;
|
|
1961
1970
|
var linkedLocalKeys = new Set();
|
|
1962
1971
|
var linkedWorkspaceKeys = new Set();
|
|
1963
1972
|
// Remote workspaces run inside a placeholder directory, so they are matched
|
|
@@ -2201,7 +2210,9 @@ function attributeViolation(name, value, tagName) {
|
|
|
2201
2210
|
imageFit: '适应窗口',
|
|
2202
2211
|
imageActualSize: '原始大小',
|
|
2203
2212
|
htmlLoadError: '无法预览网页',
|
|
2204
|
-
|
|
2213
|
+
htmlPreviewTooLarge: '文件 {{size}} 超过预览上限 {{limit}},请右键「下载到默认文件夹」后用浏览器打开。',
|
|
2214
|
+
htmlPreviewBinary: '这是二进制文件,无法按网页预览。',
|
|
2215
|
+
htmlSandboxed: '沙箱预览(脚本可运行,无法访问 DSH 界面)',
|
|
2205
2216
|
previewOnly: '图片预览',
|
|
2206
2217
|
csvTable: '表格',
|
|
2207
2218
|
csvSource: '源码',
|
|
@@ -2678,7 +2689,9 @@ function attributeViolation(name, value, tagName) {
|
|
|
2678
2689
|
imageFit: 'Fit to window',
|
|
2679
2690
|
imageActualSize: 'Actual size',
|
|
2680
2691
|
htmlLoadError: 'Cannot preview this page',
|
|
2681
|
-
|
|
2692
|
+
htmlPreviewTooLarge: 'This file is {{size}}, above the {{limit}} preview limit. Download it to the default folder and open it in a browser.',
|
|
2693
|
+
htmlPreviewBinary: 'This is a binary file, so it cannot be previewed as a page.',
|
|
2694
|
+
htmlSandboxed: 'Sandboxed preview (scripts run, no access to the DSH UI)',
|
|
2682
2695
|
previewOnly: 'Image preview',
|
|
2683
2696
|
csvTable: 'Table',
|
|
2684
2697
|
csvSource: 'Source',
|
|
@@ -3981,17 +3994,37 @@ function attributeViolation(name, value, tagName) {
|
|
|
3981
3994
|
}
|
|
3982
3995
|
}
|
|
3983
3996
|
|
|
3997
|
+
/** Repaint the "host · state" line of an already decorated card. */
|
|
3998
|
+
function refreshHoverStatus(card, scopeKey) {
|
|
3999
|
+
var line = card.querySelector('.rw-hover-host');
|
|
4000
|
+
if (!line) return;
|
|
4001
|
+
var record = workspaceHoverRecords[scopeKey];
|
|
4002
|
+
if (!record || !record.remotePath) return;
|
|
4003
|
+
var nextText = record.host ? record.host + ' · ' + record.status : record.status;
|
|
4004
|
+
var nextClass = 'rw-hover-host' + (record.disconnected ? ' is-off' : record.connected ? ' is-on' : '');
|
|
4005
|
+
if (line.textContent === nextText && line.className === nextClass) return;
|
|
4006
|
+
line.textContent = nextText;
|
|
4007
|
+
line.className = nextClass;
|
|
4008
|
+
}
|
|
4009
|
+
|
|
3984
4010
|
function decorateHoverCard(card) {
|
|
3985
4011
|
if (!card || !hoverCardState || !card.querySelector) return;
|
|
3986
4012
|
var pathEl = card.querySelector('[class*="hoverPath"]');
|
|
3987
4013
|
if (!pathEl) return;
|
|
3988
4014
|
var known = hoverCardState.get(card);
|
|
3989
4015
|
var current = (pathEl.textContent || '').trim();
|
|
3990
|
-
// Already decorated for this very content:
|
|
3991
|
-
|
|
4016
|
+
// Already decorated for this very content: the paths stay, but the status
|
|
4017
|
+
// may have moved on (the connection drops or comes back while the card is
|
|
4018
|
+
// open), so refresh that one line instead of giving up. The key has to be
|
|
4019
|
+
// remembered, because the path text has been rewritten by now.
|
|
4020
|
+
if (known && known.rendered === current) {
|
|
4021
|
+
refreshHoverStatus(card, known.key || linkedScopeKey(current));
|
|
4022
|
+
return;
|
|
4023
|
+
}
|
|
3992
4024
|
// The host re-rendered the card for another workspace: drop our lines.
|
|
3993
4025
|
if (known) clearHoverLines(card);
|
|
3994
|
-
var
|
|
4026
|
+
var key = linkedScopeKey(current);
|
|
4027
|
+
var record = workspaceHoverRecords[key];
|
|
3995
4028
|
if (!record || !record.remotePath) return;
|
|
3996
4029
|
var t = makeT(readLocale());
|
|
3997
4030
|
var remote = record.remotePath;
|
|
@@ -4026,7 +4059,7 @@ function attributeViolation(name, value, tagName) {
|
|
|
4026
4059
|
host.setAttribute('aria-label', label.split(current).join(remote));
|
|
4027
4060
|
}
|
|
4028
4061
|
|
|
4029
|
-
hoverCardState.set(card, { rendered: (pathEl.textContent || '').trim() });
|
|
4062
|
+
hoverCardState.set(card, { rendered: (pathEl.textContent || '').trim(), key: key });
|
|
4030
4063
|
}
|
|
4031
4064
|
|
|
4032
4065
|
function applyHoverCards() {
|
|
@@ -4383,6 +4416,46 @@ function attributeViolation(name, value, tagName) {
|
|
|
4383
4416
|
};
|
|
4384
4417
|
}, [load]);
|
|
4385
4418
|
|
|
4419
|
+
// Keep the connection state in step with reality. Only the status field is
|
|
4420
|
+
// patched, and only when it actually changed, so polling never re-renders
|
|
4421
|
+
// the whole page or re-fetches the trees.
|
|
4422
|
+
var dataRef = useRef(data);
|
|
4423
|
+
dataRef.current = data;
|
|
4424
|
+
useEffect(function () {
|
|
4425
|
+
var stopped = false;
|
|
4426
|
+
var tick = function () {
|
|
4427
|
+
apiCall('hosts.status', {}).then(function (result) {
|
|
4428
|
+
if (stopped) return;
|
|
4429
|
+
var statuses = (result && result.statuses) || {};
|
|
4430
|
+
var previous = dataRef.current;
|
|
4431
|
+
var changed = false;
|
|
4432
|
+
var apply = function (list) {
|
|
4433
|
+
return (list || []).map(function (item) {
|
|
4434
|
+
var status = item && item.hostId ? statuses[item.hostId] : null;
|
|
4435
|
+
if (!status) return item;
|
|
4436
|
+
if (JSON.stringify(item.status || null) === JSON.stringify(status)) return item;
|
|
4437
|
+
changed = true;
|
|
4438
|
+
return Object.assign({}, item, { status: status });
|
|
4439
|
+
});
|
|
4440
|
+
};
|
|
4441
|
+
var links = apply(previous.links);
|
|
4442
|
+
var remotes = apply(previous.remotes);
|
|
4443
|
+
if (!changed) return;
|
|
4444
|
+
setData(function (current) {
|
|
4445
|
+
return Object.assign({}, current, { links: links, remotes: remotes });
|
|
4446
|
+
});
|
|
4447
|
+
publishWorkspaceIcons(links, remotes);
|
|
4448
|
+
}).catch(function () {});
|
|
4449
|
+
};
|
|
4450
|
+
var timer = setInterval(tick, STATUS_POLL_MS);
|
|
4451
|
+
if (timer && typeof timer.unref === 'function') timer.unref();
|
|
4452
|
+
tick();
|
|
4453
|
+
return function () {
|
|
4454
|
+
stopped = true;
|
|
4455
|
+
clearInterval(timer);
|
|
4456
|
+
};
|
|
4457
|
+
}, []);
|
|
4458
|
+
|
|
4386
4459
|
return { data: data, reload: load };
|
|
4387
4460
|
}
|
|
4388
4461
|
|
|
@@ -4982,10 +5055,18 @@ function attributeViolation(name, value, tagName) {
|
|
|
4982
5055
|
return;
|
|
4983
5056
|
}
|
|
4984
5057
|
setView({ loading: true, error: null, data: null });
|
|
4985
|
-
var request = local ? { path: filePath } : Object.assign({ path: filePath }, params);
|
|
5058
|
+
var request = local ? { path: filePath, preview: true } : Object.assign({ path: filePath, preview: true }, params);
|
|
4986
5059
|
apiCall(local ? 'local.read' : 'fs.read', request).then(function (result) {
|
|
4987
|
-
if (result.
|
|
4988
|
-
setView({
|
|
5060
|
+
if (result.tooLarge || result.truncated) {
|
|
5061
|
+
setView({
|
|
5062
|
+
loading: false,
|
|
5063
|
+
error: new Error(t('htmlPreviewTooLarge', { size: formatBytes(result.size), limit: formatBytes(PREVIEW_MAX_BYTES) })),
|
|
5064
|
+
data: null,
|
|
5065
|
+
});
|
|
5066
|
+
return;
|
|
5067
|
+
}
|
|
5068
|
+
if (result.binary) {
|
|
5069
|
+
setView({ loading: false, error: new Error(t('htmlPreviewBinary')), data: null });
|
|
4989
5070
|
return;
|
|
4990
5071
|
}
|
|
4991
5072
|
setView({ loading: false, error: null, data: result });
|
|
@@ -5022,14 +5103,16 @@ function attributeViolation(name, value, tagName) {
|
|
|
5022
5103
|
h('iframe', {
|
|
5023
5104
|
className: 'rw-html-frame',
|
|
5024
5105
|
title: name,
|
|
5025
|
-
|
|
5106
|
+
// allow-scripts runs the page's own JS (charts need it) inside an
|
|
5107
|
+
// opaque origin: no access to the DSH UI, its storage or the tree.
|
|
5108
|
+
sandbox: 'allow-scripts',
|
|
5026
5109
|
srcDoc: data.content || '',
|
|
5027
5110
|
})),
|
|
5028
5111
|
h('div', { className: 'rw-editor-status' },
|
|
5029
5112
|
h('span', { className: 'rw-status-chip' }, 'HTML'),
|
|
5030
5113
|
h('span', { className: 'rw-status-chip' }, formatBytes(data.size || 0)),
|
|
5031
5114
|
h('span', { className: 'rw-fill', style: { flex: '1 1 auto' } }),
|
|
5032
|
-
h('span', { className: 'rw-status-chip' }, t('
|
|
5115
|
+
h('span', { className: 'rw-status-chip' }, t('htmlSandboxed'))));
|
|
5033
5116
|
}
|
|
5034
5117
|
|
|
5035
5118
|
// ── editor ─────────────────────────────────────────────────────────────
|
package/lib/index.js
CHANGED
|
@@ -106,6 +106,12 @@ const IMAGE_MIME = Object.freeze({
|
|
|
106
106
|
const MAX_NAME_LENGTH = 120
|
|
107
107
|
const CONNECT_TIMEOUT_MS = 20_000
|
|
108
108
|
const OP_TIMEOUT_MS = 60_000
|
|
109
|
+
// A failed probe only describes the moment it ran: a socket that never came up
|
|
110
|
+
// says nothing about the next request, which dials again. After this window the
|
|
111
|
+
// state degrades to "unknown" so a single glitch cannot paint a workspace red
|
|
112
|
+
// for the rest of the session. A live connection is different — when it drops,
|
|
113
|
+
// noteConnectionLost() records that, and the next success clears it.
|
|
114
|
+
const STATUS_TTL_MS = 60_000
|
|
109
115
|
// Directory listings are paged so a folder with tens of thousands of entries
|
|
110
116
|
// cannot stall the Host or flood the renderer.
|
|
111
117
|
const LIST_PAGE_SIZE = 500
|
|
@@ -1054,11 +1060,30 @@ export function apply(ctx) {
|
|
|
1054
1060
|
return runningCache.keys
|
|
1055
1061
|
}
|
|
1056
1062
|
|
|
1063
|
+
/**
|
|
1064
|
+
* Status as the UI should see it. A stale failure is reported as "unknown"
|
|
1065
|
+
* instead of "error": the connection is redialled on demand, so an old failed
|
|
1066
|
+
* attempt proves nothing about the workspace right now.
|
|
1067
|
+
*/
|
|
1068
|
+
const hostStatusView = (hostId) => {
|
|
1069
|
+
const status = pool.status(hostId)
|
|
1070
|
+
if (!status || typeof status.state !== 'string' || status.state === '') return { state: 'idle' }
|
|
1071
|
+
const checkedAt = typeof status.checkedAt === 'number' ? status.checkedAt : 0
|
|
1072
|
+
const fresh = checkedAt > 0 && Date.now() - checkedAt <= STATUS_TTL_MS
|
|
1073
|
+
if (status.state === 'error' && !fresh) return { state: 'idle', checkedAt }
|
|
1074
|
+
return {
|
|
1075
|
+
state: status.state,
|
|
1076
|
+
...(status.reason ? { reason: status.reason } : {}),
|
|
1077
|
+
...(status.message ? { message: status.message } : {}),
|
|
1078
|
+
...(typeof status.latencyMs === 'number' ? { latencyMs: status.latencyMs } : {}),
|
|
1079
|
+
...(checkedAt > 0 ? { checkedAt } : {}),
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1057
1083
|
const describeLink = (record, runningKeys) => {
|
|
1058
1084
|
const host = pool.host(record.hostId)
|
|
1059
1085
|
const snapshot = record.hostSnapshot || {}
|
|
1060
1086
|
const workspace = findWorkspaceByPath(linkedRegistry(), record.localPath)
|
|
1061
|
-
const status = pool.status(record.hostId)
|
|
1062
1087
|
return {
|
|
1063
1088
|
id: record.id,
|
|
1064
1089
|
name: record.name,
|
|
@@ -1074,12 +1099,7 @@ export function apply(ctx) {
|
|
|
1074
1099
|
createdAt: record.createdAt,
|
|
1075
1100
|
workspaceId: workspace ? String(workspace.id) : null,
|
|
1076
1101
|
workspaceTitle: workspace ? workspace.title : null,
|
|
1077
|
-
status:
|
|
1078
|
-
state: status ? status.state : 'idle',
|
|
1079
|
-
...(status && status.reason ? { reason: status.reason } : {}),
|
|
1080
|
-
...(status && status.message ? { message: status.message } : {}),
|
|
1081
|
-
...(status && typeof status.latencyMs === 'number' ? { latencyMs: status.latencyMs } : {}),
|
|
1082
|
-
},
|
|
1102
|
+
status: hostStatusView(record.hostId),
|
|
1083
1103
|
}
|
|
1084
1104
|
}
|
|
1085
1105
|
|
|
@@ -1089,7 +1109,6 @@ export function apply(ctx) {
|
|
|
1089
1109
|
const describeRemote = (record) => {
|
|
1090
1110
|
const host = pool.host(record.hostId)
|
|
1091
1111
|
const snapshot = record.hostSnapshot || {}
|
|
1092
|
-
const status = pool.status(record.hostId)
|
|
1093
1112
|
return {
|
|
1094
1113
|
id: record.id,
|
|
1095
1114
|
name: record.name,
|
|
@@ -1102,12 +1121,7 @@ export function apply(ctx) {
|
|
|
1102
1121
|
placeholderPath: record.placeholderPath,
|
|
1103
1122
|
workspaceId: record.workspaceId || null,
|
|
1104
1123
|
createdAt: record.createdAt,
|
|
1105
|
-
status:
|
|
1106
|
-
state: status ? status.state : 'idle',
|
|
1107
|
-
...(status && status.reason ? { reason: status.reason } : {}),
|
|
1108
|
-
...(status && status.message ? { message: status.message } : {}),
|
|
1109
|
-
...(status && typeof status.latencyMs === 'number' ? { latencyMs: status.latencyMs } : {}),
|
|
1110
|
-
},
|
|
1124
|
+
status: hostStatusView(record.hostId),
|
|
1111
1125
|
}
|
|
1112
1126
|
}
|
|
1113
1127
|
|
|
@@ -2171,6 +2185,26 @@ export function apply(ctx) {
|
|
|
2171
2185
|
}
|
|
2172
2186
|
},
|
|
2173
2187
|
|
|
2188
|
+
/**
|
|
2189
|
+
* Cheap connection-state read for the sidebar. Reading it never dials, so the
|
|
2190
|
+
* client can poll it to keep the workspace cards honest: a dropped socket is
|
|
2191
|
+
* recorded by noteConnectionLost(), a successful request by connectHost().
|
|
2192
|
+
*/
|
|
2193
|
+
async 'hosts.status'(params = {}) {
|
|
2194
|
+
const requested = Array.isArray(params.hostIds) ? params.hostIds : null
|
|
2195
|
+
const ids = new Set()
|
|
2196
|
+
if (requested) {
|
|
2197
|
+
for (const id of requested) if (typeof id === 'string' && id !== '') ids.add(id)
|
|
2198
|
+
} else {
|
|
2199
|
+
for (const host of await refreshHosts()) ids.add(host.id)
|
|
2200
|
+
for (const record of linkedStore.list()) if (record && record.hostId) ids.add(record.hostId)
|
|
2201
|
+
for (const record of remoteStore.list()) if (record && record.hostId) ids.add(record.hostId)
|
|
2202
|
+
}
|
|
2203
|
+
const statuses = {}
|
|
2204
|
+
for (const id of ids) statuses[id] = hostStatusView(id)
|
|
2205
|
+
return { statuses }
|
|
2206
|
+
},
|
|
2207
|
+
|
|
2174
2208
|
/**
|
|
2175
2209
|
* Store a credential for one SSH host on this machine.
|
|
2176
2210
|
*
|
|
@@ -2315,8 +2349,12 @@ export function apply(ctx) {
|
|
|
2315
2349
|
const target = scopeTarget(scope, params.path)
|
|
2316
2350
|
const stat = await scope.remote.stat(target)
|
|
2317
2351
|
if (stat.type === 'dir') throw new ApiError('FS_IS_DIR', '目标是目录,无法作为文件读取')
|
|
2318
|
-
|
|
2319
|
-
|
|
2352
|
+
// `preview` lifts the editor's 2 MB ceiling to the 8 MB read cap, so a
|
|
2353
|
+
// read-only preview (HTML pages, build logs) can show files the editor
|
|
2354
|
+
// refuses to edit. Editing stays capped at EDITABLE_LIMIT either way.
|
|
2355
|
+
const softLimit = params.preview === true ? READ_CAP : EDITABLE_LIMIT
|
|
2356
|
+
const limit = Math.min(Math.max(Number(params.maxBytes) || softLimit, 1024), READ_CAP)
|
|
2357
|
+
const tooLarge = stat.size > softLimit
|
|
2320
2358
|
const read = await scope.remote.readFile(target, { maxBytes: tooLarge ? Math.min(PEEK_LIMIT, limit) : limit })
|
|
2321
2359
|
const truncated = read.truncated || read.data.length < stat.size
|
|
2322
2360
|
const binary = looksBinary(read.data)
|
|
@@ -2868,7 +2906,8 @@ export function apply(ctx) {
|
|
|
2868
2906
|
throw mapLocalFsError(error)
|
|
2869
2907
|
}
|
|
2870
2908
|
if (info.isDirectory()) throw new ApiError('FS_IS_DIR', '目标是目录,无法作为文件读取')
|
|
2871
|
-
const
|
|
2909
|
+
const softLimit = params.preview === true ? READ_CAP : EDITABLE_LIMIT
|
|
2910
|
+
const tooLarge = info.size > softLimit
|
|
2872
2911
|
const cap = tooLarge ? PEEK_LIMIT : READ_CAP
|
|
2873
2912
|
// Read at most `cap` bytes. Reading the whole file first would pull
|
|
2874
2913
|
// multi-gigabyte files into Host memory (and on Windows readFileSync
|
|
@@ -3745,25 +3784,25 @@ export function apply(ctx) {
|
|
|
3745
3784
|
|
|
3746
3785
|
const host = await findHost(record.hostId)
|
|
3747
3786
|
const started = Date.now()
|
|
3787
|
+
let remote
|
|
3788
|
+
try {
|
|
3789
|
+
// connectHost() records the connection state itself: connected on
|
|
3790
|
+
// success, error only when the dialect really failed.
|
|
3791
|
+
remote = await connectHost(host)
|
|
3792
|
+
} catch (error) {
|
|
3793
|
+
const apiError = asApiError(error)
|
|
3794
|
+
return { ok: false, error: apiError.message, latencyMs: Date.now() - started }
|
|
3795
|
+
}
|
|
3796
|
+
const latencyMs = Date.now() - started
|
|
3748
3797
|
try {
|
|
3749
|
-
const remote = await connectHost(host)
|
|
3750
3798
|
const stat = await remote.stat(record.remotePath)
|
|
3751
|
-
|
|
3752
|
-
pool.setStatus(host.id, { state: 'connected', latencyMs })
|
|
3753
|
-
return {
|
|
3754
|
-
ok: true,
|
|
3755
|
-
latencyMs,
|
|
3756
|
-
exists: stat.type === 'dir',
|
|
3757
|
-
type: stat.type,
|
|
3758
|
-
}
|
|
3799
|
+
return { ok: true, latencyMs, exists: stat.type === 'dir', type: stat.type }
|
|
3759
3800
|
} catch (error) {
|
|
3801
|
+
// The host answered, so the link is fine; only this workspace's directory
|
|
3802
|
+
// is missing or unreadable. Reporting that as a connection error would
|
|
3803
|
+
// paint every other workspace on the same host red.
|
|
3760
3804
|
const apiError = asApiError(error)
|
|
3761
|
-
|
|
3762
|
-
return {
|
|
3763
|
-
ok: false,
|
|
3764
|
-
error: apiError.message,
|
|
3765
|
-
latencyMs: Date.now() - started,
|
|
3766
|
-
}
|
|
3805
|
+
return { ok: false, exists: false, error: apiError.message, latencyMs }
|
|
3767
3806
|
}
|
|
3768
3807
|
},
|
|
3769
3808
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-linked-workspace",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Linked local ⇄ remote workspaces and remote workspaces for DeepSeek Harness: theme-aware split editor, file-type icons, and agent tools that edit remote files directly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|