dsh-linked-workspace 0.16.1 → 0.17.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/CHANGELOG.md +8 -0
- package/README.en.md +12 -1
- package/README.md +13 -1
- package/docs/API.md +16 -3
- package/docs/VERIFY.md +13 -0
- package/lib/client.js +229 -1
- package/lib/index.js +303 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
English · [简体中文](CHANGELOG.zh.md)
|
|
4
4
|
|
|
5
|
+
## 0.17.0 — 2026-11-19
|
|
6
|
+
|
|
7
|
+
- New `hosts.exec`: let the model run **one** non-interactive command on the remote host (builds, tests, logs) instead of composing `ssh`. Off by default and gated three ways: the `execEnabled` switch, the host allow-list `execHostIds`, and the optional workspace allow-list `execWorkspaceIds` (empty means no restriction). Refusals are audited too.
|
|
8
|
+
- Every attempt is written to `$DSH_HOME/linked-workspace/exec-audit.jsonl`: command, `cwd`, exit code, duration, the first 4 KB of output and any refusal reason; rotated to `.1` past 5 MB. `meta.info` returns that path and the settings block can open it.
|
|
9
|
+
- Output and time are bounded: each stream is clipped to `execMaxOutputChars` (200000 by default, head+tail, flagged `truncated`), timeouts follow `execTimeoutMs` (60 s by default, 600 s per call at most) and surface as `EXEC_TIMEOUT`; `cwd` may not escape the workspace root.
|
|
10
|
+
- `linked_workspace` gained an `exec` action (`command` up to 8000 characters, optional `cwd` and `timeout_ms`) and its prompt now prefers it over hand-written `ssh`. The settings page has a “Remote command execution” block (switch, both allow-lists, timeout/output caps, open audit log).
|
|
11
|
+
- Host API revision is now `apiRevision: 3`: a Host still running older code shows the “restart DSH” banner above the tree.
|
|
12
|
+
|
|
5
13
|
## 0.16.1 — 2026-11-19
|
|
6
14
|
|
|
7
15
|
- The hover card's connection state now follows reality in both directions: the
|
package/README.en.md
CHANGED
|
@@ -112,11 +112,21 @@ Appears automatically for sessions that belong to a remote workspace (and can be
|
|
|
112
112
|
|
|
113
113
|
| Tool | Purpose |
|
|
114
114
|
| --- | --- |
|
|
115
|
-
| `linked_workspace` | `list`, `info`, `list_dir`, `read`, `write`, `replace`, `stat`, `mkdir`, `rename`, `delete`, `sync`; paths are relative to the remote root, writes are atomic, `if_modified_since` provides optimistic concurrency. Works for both linked and remote workspaces (`sync` only applies to a linked workspace with the mirror on) |
|
|
115
|
+
| `linked_workspace` | `list`, `info`, `list_dir`, `read`, `write`, `replace`, `stat`, `mkdir`, `rename`, `delete`, `sync`, `exec`; paths are relative to the remote root, writes are atomic, `if_modified_since` provides optimistic concurrency. Works for both linked and remote workspaces (`sync` only applies to a linked workspace with the mirror on) |
|
|
116
116
|
| `linked_skills` | `list` / `read` local skills (`~/.dsh/skills`, `~/.agents/skills`, `<local>/.dsh/skills`, `<local>/.agents/skills`) |
|
|
117
117
|
|
|
118
118
|
The workspace resolves automatically when the session cwd falls inside a linked workspace or a remote workspace placeholder; use the `workspace` argument (id, local/placeholder path or name) across workspaces. The remote server only needs SSH — no plugin or Python installation.
|
|
119
119
|
|
|
120
|
+
### Remote command execution (0.17.0, off by default)
|
|
121
|
+
|
|
122
|
+
`exec` lets the model run **one non-interactive command** on the remote host (builds, tests, logs) instead of composing `ssh` itself. It is off unless three things line up:
|
|
123
|
+
|
|
124
|
+
1. the `execEnabled` switch under Settings → Linked workspaces → “Remote command execution”;
|
|
125
|
+
2. the host is in the **host allow-list** `execHostIds`;
|
|
126
|
+
3. if the optional **workspace allow-list** `execWorkspaceIds` is filled in, the current workspace must be listed (an empty list means “no restriction”).
|
|
127
|
+
|
|
128
|
+
Every attempt — including refused ones — appends a line to `$DSH_HOME/linked-workspace/exec-audit.jsonl` (command, exit code, duration, first 4 KB of output, refusal reason), rotated to `.1` past 5 MB; the settings block has an “Open audit log” button. Output is clipped per stream to `execMaxOutputChars` (200000 by default), timeouts come from `execTimeoutMs` (60 s by default, 600 s per call at most), and `cwd` may not escape the workspace root.
|
|
129
|
+
|
|
120
130
|
### Running icon / local skills
|
|
121
131
|
|
|
122
132
|
- While a linked workspace has a running session, its link icon turns **blue** (refreshed about every 5 seconds).
|
|
@@ -191,6 +201,7 @@ The npm package is `dsh-linked-workspace`; released versions can also be install
|
|
|
191
201
|
- 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.
|
|
192
202
|
- The page HTTP API accepts loopback same-origin requests only (remote deployments fall back to the DSH `connection` service's Host/Origin authentication).
|
|
193
203
|
- 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.
|
|
204
|
+
- Remote command execution is off by default and, once enabled, still limited by the host allow-list (plus the optional workspace allow-list). Every attempt is audited, output is length-capped, commands have a timeout, and `cwd` cannot escape the workspace root.
|
|
194
205
|
|
|
195
206
|
## FAQ
|
|
196
207
|
|
package/README.md
CHANGED
|
@@ -111,11 +111,22 @@
|
|
|
111
111
|
|
|
112
112
|
| 工具 | 用途 |
|
|
113
113
|
| --- | --- |
|
|
114
|
-
| `linked_workspace` | `list`、`info`、`list_dir`、`read`、`write`、`replace`、`stat`、`mkdir`、`rename`、`delete`、`sync`;路径相对远端根目录,写入原子化,`if_modified_since` 做乐观并发控制。联动工作区与远程工作区都适用(远程工作区没有本地副本,`sync` 只用于开启镜像的联动工作区) |
|
|
114
|
+
| `linked_workspace` | `list`、`info`、`list_dir`、`read`、`write`、`replace`、`stat`、`mkdir`、`rename`、`delete`、`sync`、`exec`;路径相对远端根目录,写入原子化,`if_modified_since` 做乐观并发控制。联动工作区与远程工作区都适用(远程工作区没有本地副本,`sync` 只用于开启镜像的联动工作区) |
|
|
115
115
|
| `linked_skills` | `list`、`read` 本地技能(`~/.dsh/skills`、`~/.agents/skills`、`<local>/.dsh/skills`、`<local>/.agents/skills`) |
|
|
116
116
|
|
|
117
117
|
会话工作目录落在某个联动工作区或远程工作区的占位目录时会自动解析;跨工作区可用 `workspace` 参数指定(支持 id、本地/占位路径或名称)。远端服务器只需要 SSH,不需要安装插件或 Python。
|
|
118
118
|
|
|
119
|
+
### 远端命令执行(0.17.0,默认关闭)
|
|
120
|
+
|
|
121
|
+
`exec` 让模型在远端跑**一条非交互命令**(编译、跑测试、看日志),不用再自己拼 `ssh`。它默认是关的,要同时满足三件事才会执行:
|
|
122
|
+
|
|
123
|
+
1. 设置 → 联动工作区 → 「远端命令执行」里的总开关 `execEnabled`;
|
|
124
|
+
2. 该主机在**主机白名单** `execHostIds` 里;
|
|
125
|
+
3. 若填了**工作区白名单** `execWorkspaceIds`,当前工作区必须在其中(留空表示不限制)。
|
|
126
|
+
|
|
127
|
+
每次尝试——包括被拒绝的——都会写一行到 `$DSH_HOME/linked-workspace/exec-audit.jsonl`(含命令、退出码、耗时、输出的前 4 KB、拒绝原因),超过 5 MB 自动轮转为 `.1`;设置页有「打开审计日志」按钮。输出按 `execMaxOutputChars`(默认 200000 字符/流)截断,超时由 `execTimeoutMs`(默认 60 秒,单次最多 600 秒)控制,`cwd` 不能跑出工作区根目录。
|
|
128
|
+
|
|
129
|
+
|
|
119
130
|
### 运行中图标 / 本地技能
|
|
120
131
|
|
|
121
132
|
- 联动工作区下若有正在运行的会话(本地会话 turn 进行中),左侧工作区的链环图标会变成**蓝色**;刷新间隔约 5 秒。
|
|
@@ -190,6 +201,7 @@ npm 包名为 `dsh-linked-workspace`,也可以从 npm 安装已发布版本(
|
|
|
190
201
|
- 单文件保存上限 8 MB;镜像同步在后台执行,默认最多 500 文件 / 50 MB(跳过超大文件),默认排除 `.git`/`node_modules`/各类缓存目录,单文件读取 30 s 超时,不再阻塞 HTTP 请求。右键「传输」与「下载到默认文件夹」单次最多 150 文件 / 15 MB(超限会提示未全部传输)。
|
|
191
202
|
- 页面 HTTP API 只接受本机回环同源请求(远程部署时回落到 DSH `connection` 服务的 Host/Origin 鉴权)。
|
|
192
203
|
- HTML 预览跑在 `sandbox="allow-scripts"` 的 iframe 里:脚本能执行(plotly 这类图表才有内容),但处于独立的不透明源,访问不到 DSH 界面、宿主存储与标签页;Markdown/文档预览仍会移除脚本、内联样式、事件属性与 `javascript:`/`vbscript:` 等危险链接,只保留安全链接与图片 `data:` URL。
|
|
204
|
+
- 远端命令执行默认关闭,开启后仍受主机白名单(以及可选的工作区白名单)限制;每次执行(含被拒绝的尝试)都写审计日志,输出有长度上限、命令有超时,`cwd` 不能跑出工作区根目录。
|
|
193
205
|
|
|
194
206
|
## 常见问题
|
|
195
207
|
|
package/docs/API.md
CHANGED
|
@@ -57,6 +57,7 @@ scope root, or absolute inside it.
|
|
|
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
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) |
|
|
59
59
|
| `hosts.mkdir` | `{ hostId, path?, name }` | `{ path }` (creates `name` inside `path`; defaults to the login home; `409`/`FS_EXISTS` when it already exists) |
|
|
60
|
+
| `hosts.exec` | `{ hostId?/linkedId?/remoteId?, command, cwd?, timeoutMs? }` | `{ hostId, hostName, workspaceId, kind, command, cwd, exitCode, stdout, stderr, stdoutBytes, stderrBytes, truncated, durationMs, startedAt, auditId }` — runs **one** non-interactive command on the remote host. Three gates: `settings.execEnabled` must be `true`, the host must be in `settings.execHostIds`, and — when `settings.execWorkspaceIds` is non-empty — the workspace must be in it. Refusals are audited too and answer `403` (`EXEC_DISABLED` / `EXEC_HOST_NOT_ALLOWED` / `EXEC_WORKSPACE_NOT_ALLOWED`); a timeout answers `504` `EXEC_TIMEOUT`, other failures `502` `EXEC_FAILED`. Output is clipped to `settings.execMaxOutputChars` per stream (default 200000, head+tail). `cwd` is resolved inside the workspace root and may not escape it. |
|
|
60
61
|
| `remote_workspaces.list` | `{}` | `{ workspaces: RemoteWorkspaceInfo[] }` |
|
|
61
62
|
| `remote_workspaces.create` | `{ hostId, remotePath, name? }` | `{ workspace }` |
|
|
62
63
|
| `remote_workspaces.get` | `{ id }` | `{ workspace }` |
|
|
@@ -130,7 +131,17 @@ Under `$DSH_HOME/linked-workspace/`:
|
|
|
130
131
|
|
|
131
132
|
- `linked.json` — linked workspaces (no credentials).
|
|
132
133
|
- `remote-workspaces.json` — remote workspaces (no credentials).
|
|
133
|
-
- `settings.json` — `{ editorTheme, editorThemeFamily, editorThemeMode, fileOpenMode, autoSave }`.
|
|
134
|
+
- `settings.json` — `{ editorTheme, editorThemeFamily, editorThemeMode, fileOpenMode, autoSave, execEnabled, execHostIds, execWorkspaceIds, execTimeoutMs, execMaxOutputChars, execShell }`.
|
|
135
|
+
The exec keys are off unless you turn them on: `execEnabled` defaults to
|
|
136
|
+
`false`, `execHostIds` (host allow-list) starts empty, and
|
|
137
|
+
`execWorkspaceIds` is an optional second layer where an empty list means
|
|
138
|
+
"every workspace on an allowed host".
|
|
139
|
+
- `exec-audit.jsonl` — one JSON line per `hosts.exec` attempt (accepted or
|
|
140
|
+
refused): `{ ts, auditId, hostId, hostName, workspaceId, kind, command, cwd?,
|
|
141
|
+
exitCode?, durationMs?, stdoutBytes?, stderrBytes?, truncated?, stdoutHead?,
|
|
142
|
+
stderrHead?, refusal?, message? }`. Rotated to `exec-audit.jsonl.1` past 5 MB.
|
|
143
|
+
`meta.info` returns its absolute path as `execAuditFile` so the settings page
|
|
144
|
+
can open it.
|
|
134
145
|
- `known_hosts.json` — trust-on-first-use host key fingerprints.
|
|
135
146
|
- `ssh-credentials.json` — `{ version, byHostId: { <hostId>: { password?, privateKey?, passphrase? } } }`,
|
|
136
147
|
written by `hosts.credentials` with mode `0600`. Hosts listed in `~/.ssh/config`
|
|
@@ -144,13 +155,15 @@ Under `$DSH_HOME/linked-workspace/`:
|
|
|
144
155
|
|
|
145
156
|
`linked_workspace` (Host tool, JSON-Schema parameters) actions: `list`, `info`,
|
|
146
157
|
`list_dir`, `read`, `write`, `replace`, `stat`, `mkdir`, `rename`, `delete`,
|
|
147
|
-
`sync`. It resolves the workspace from the session working directory (a linked
|
|
158
|
+
`sync`, `exec`. It resolves the workspace from the session working directory (a linked
|
|
148
159
|
local directory or a remote workspace placeholder) or from an explicit
|
|
149
160
|
`workspace` reference (id, local/placeholder path, or name), confines paths to
|
|
150
161
|
the remote root, and mirrors reads/writes into `.remote/` when a linked
|
|
151
162
|
workspace mirrors. `list` shows both kinds, labelled `(linked)` and `(remote)`;
|
|
152
163
|
`info` returns `kind: "linked" | "remote"` and `sync` is rejected for remote
|
|
153
|
-
workspaces.
|
|
164
|
+
workspaces. `exec` takes `command` (≤ 8000 characters), an optional `cwd`
|
|
165
|
+
(inside the workspace root) and `timeout_ms`, and refuses unless the switches
|
|
166
|
+
described under `hosts.exec` are on.
|
|
154
167
|
|
|
155
168
|
`linked_skills` (Host tool) actions: `list`, `read` — local skills
|
|
156
169
|
(`~/.dsh/skills`, `~/.agents/skills`, `<local>/.dsh/skills`,
|
package/docs/VERIFY.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-workspace-ui`; client changes load with **应用 → 重新加载界面** (a full restart is only needed after re-installing the package). Then verify:
|
|
4
4
|
|
|
5
|
+
## 远端命令执行(0.17.0)
|
|
6
|
+
|
|
7
|
+
> 注意:本机这套 DSH **Web** 构建里没有可见的设置入口(账号菜单只有「意见反馈 / 退出登录」,`Ctrl+K` 是会话搜索,插件详情页只有「卸载」),所以设置区块的渲染要在**桌面端**确认;Host 侧行为可以直接用下面的 API 命令验证。
|
|
8
|
+
|
|
9
|
+
1. 设置 → 联动工作区 → 「远端命令执行」:默认总开关关闭、两个白名单为空、超时 60 秒、输出上限 200000;打开开关后才出现黄色警告行与两个白名单列表。
|
|
10
|
+
2. 开关关闭时执行:`hosts.exec { linkedId, command: 'echo x' }` → `403 EXEC_DISABLED`,提示里指向设置页路径。
|
|
11
|
+
3. 开关打开但主机白名单为空 → `403 EXEC_HOST_NOT_ALLOWED`;把该主机加进白名单 → `echo hi; pwd` 返回 `exitCode: 0`、`stdout` 含 `hi`、`cwd` 等于工作区远端根。
|
|
12
|
+
4. 工作区白名单填一个不相干的值 → `403 EXEC_WORKSPACE_NOT_ALLOWED`;留空表示不限制。
|
|
13
|
+
5. `command: ''` → `400 BAD_REQUEST`;`cwd: '../..'` → `400 BAD_REQUEST`;`timeoutMs: 1000` 配 `sleep 5` → `504 EXEC_TIMEOUT`。
|
|
14
|
+
6. 审计:每次尝试(含被拒绝)都往 `$DSH_HOME/linked-workspace/exec-audit.jsonl` 追加一行 JSON,含 `auditId`、`hostId`、`command`、成功时的 `exitCode`/`durationMs`/`stdoutHead`、失败时的 `refusal`/`message`;文件超过 5 MB 时轮转为 `exec-audit.jsonl.1`;设置页「打开审计日志」用系统默认应用打开它。
|
|
15
|
+
7. 模型侧:在联动/远程工作区的会话里让它「用 linked_workspace 的 exec 动作跑 uname -a」→ 工具卡片返回退出码与输出;开关关闭时模型会收到 `EXEC_DISABLED` 与开启指引。
|
|
16
|
+
8. 旧 Host:`meta.info` 的 `apiRevision` < 3 时目录树顶部出现「DSH 的插件进程仍在运行旧版代码」横幅。
|
|
17
|
+
|
|
5
18
|
## 设置 → 联动工作区
|
|
6
19
|
|
|
7
20
|
1. 左下角「账号菜单」→ 设置 →「联动工作区」。
|
package/lib/client.js
CHANGED
|
@@ -2494,6 +2494,18 @@ function attributeViolation(name, value, tagName) {
|
|
|
2494
2494
|
autoSaveHint: '编辑停顿约 1 秒后自动保存;关闭后请按 Ctrl+S 手动保存。',
|
|
2495
2495
|
autoSaveLabel: '开启自动保存',
|
|
2496
2496
|
autoSaveSaved: '自动保存设置已保存',
|
|
2497
|
+
execTitle: '远端命令执行',
|
|
2498
|
+
execHint: '默认关闭。开启后,会话里的模型可以通过 linked_workspace 的 exec 动作在远端跑命令;只对下面勾选的主机/工作区生效,每次尝试(含被拒)都记进审计日志。',
|
|
2499
|
+
execEnabledLabel: '允许在远端执行命令',
|
|
2500
|
+
execWarn: '命令会以你的 SSH 账号身份在远端运行,请只对可信主机开启。',
|
|
2501
|
+
execHostsTitle: '允许的主机',
|
|
2502
|
+
execHostsEmpty: '没有可用的 SSH 主机',
|
|
2503
|
+
execWorkspacesTitle: '允许的工作区(第二层)',
|
|
2504
|
+
execWorkspacesHint: '留空表示上一步勾选的主机全部放行;勾选后只允许这些工作区。',
|
|
2505
|
+
execTimeoutLabel: '默认超时(秒)',
|
|
2506
|
+
execOutputLabel: '输出上限(字符)',
|
|
2507
|
+
execAuditOpen: '打开审计日志',
|
|
2508
|
+
execSaved: '远端命令执行设置已保存',
|
|
2497
2509
|
shortcutTitle: '常用快捷键',
|
|
2498
2510
|
shortcutHint: '与 VS Code 类似的默认快捷键;macOS 上把 Ctrl 换成 ⌘。',
|
|
2499
2511
|
shortcutSave: '保存当前文件',
|
|
@@ -2973,6 +2985,18 @@ function attributeViolation(name, value, tagName) {
|
|
|
2973
2985
|
autoSaveHint: 'Saves about one second after you stop typing. When off, press Ctrl+S to save.',
|
|
2974
2986
|
autoSaveLabel: 'Enable auto save',
|
|
2975
2987
|
autoSaveSaved: 'Auto-save setting saved',
|
|
2988
|
+
execTitle: 'Remote command execution',
|
|
2989
|
+
execHint: 'Off by default. When on, the model can run commands on the remote host through the linked_workspace "exec" action — only for the hosts and workspaces ticked below, and every attempt (refusals included) is audited.',
|
|
2990
|
+
execEnabledLabel: 'Allow running commands remotely',
|
|
2991
|
+
execWarn: 'Commands run on the remote host with your SSH account. Enable this only for hosts you trust.',
|
|
2992
|
+
execHostsTitle: 'Allowed hosts',
|
|
2993
|
+
execHostsEmpty: 'No SSH hosts available',
|
|
2994
|
+
execWorkspacesTitle: 'Allowed workspaces (second layer)',
|
|
2995
|
+
execWorkspacesHint: 'Leave empty to allow every workspace on the hosts ticked above; tick some to restrict execution to them.',
|
|
2996
|
+
execTimeoutLabel: 'Default timeout (seconds)',
|
|
2997
|
+
execOutputLabel: 'Output limit (characters)',
|
|
2998
|
+
execAuditOpen: 'Open the audit log',
|
|
2999
|
+
execSaved: 'Remote-execution settings saved',
|
|
2976
3000
|
shortcutTitle: 'Keyboard shortcuts',
|
|
2977
3001
|
shortcutHint: 'VS Code-like defaults; use ⌘ instead of Ctrl on macOS.',
|
|
2978
3002
|
shortcutSave: 'Save the current file',
|
|
@@ -3165,7 +3189,7 @@ function attributeViolation(name, value, tagName) {
|
|
|
3165
3189
|
* Host methods the running DSH process does not have yet, the directory
|
|
3166
3190
|
* pane says so instead of surfacing an unrelated error.
|
|
3167
3191
|
*/
|
|
3168
|
-
var HOST_API_REVISION =
|
|
3192
|
+
var HOST_API_REVISION = 3;
|
|
3169
3193
|
var hostInfoProbe = null;
|
|
3170
3194
|
|
|
3171
3195
|
function probeHostInfo() {
|
|
@@ -3643,6 +3667,11 @@ function attributeViolation(name, value, tagName) {
|
|
|
3643
3667
|
'.rw-option-desc{font-size:11.5px;line-height:17px;color:var(--dsw-alias-label-tertiary)}',
|
|
3644
3668
|
'.rw-warn-box{padding:8px 10px;border-radius:8px;border:1px solid color-mix(in srgb,var(--dsw-alias-state-warn-primary) 45%,transparent);background:color-mix(in srgb,var(--dsw-alias-state-warn-primary) 8%,var(--dsw-alias-bg-layer-1));font-size:12px;line-height:18px}',
|
|
3645
3669
|
'.rw-setting-row{display:flex;align-items:center;gap:10px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:var(--dsw-alias-bg-layer-1)}',
|
|
3670
|
+
'.rw-exec-list{display:flex;flex-direction:column;gap:4px;margin-top:8px}',
|
|
3671
|
+
'.rw-exec-item{display:flex;align-items:center;gap:8px;padding:7px 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-1);cursor:pointer;font-size:13px}',
|
|
3672
|
+
'.rw-exec-item input[type=checkbox]{margin:0;flex:none}',
|
|
3673
|
+
'.rw-exec-name{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
3674
|
+
'.rw-exec-meta{flex:none;color:var(--dsw-alias-text-3);font-size:12px;font-variant-numeric:tabular-nums}',
|
|
3646
3675
|
'.rw-shortcut-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:4px 16px}',
|
|
3647
3676
|
'.rw-shortcut-row{display:flex;align-items:center;gap:10px;min-height:28px;font-size:12px;color:var(--dsw-alias-label-secondary)}',
|
|
3648
3677
|
'.rw-kbd{display:inline-flex;align-items:center;justify-content:center;min-width:64px;padding:2px 7px;border:1px solid var(--dsw-alias-border-l2);border-bottom-width:2px;border-radius:5px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:11px/16px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;white-space:nowrap}',
|
|
@@ -10455,6 +10484,199 @@ function rememberShowHidden(value) {
|
|
|
10455
10484
|
: null);
|
|
10456
10485
|
}
|
|
10457
10486
|
|
|
10487
|
+
function ExecSettingsGroup(props) {
|
|
10488
|
+
var t = props.t;
|
|
10489
|
+
var locale = props.locale;
|
|
10490
|
+
var hosts = props.hosts || [];
|
|
10491
|
+
var workspaces = props.workspaces || [];
|
|
10492
|
+
var state = useState({
|
|
10493
|
+
loading: true,
|
|
10494
|
+
saving: false,
|
|
10495
|
+
message: null,
|
|
10496
|
+
execEnabled: false,
|
|
10497
|
+
execHostIds: [],
|
|
10498
|
+
execWorkspaceIds: [],
|
|
10499
|
+
execTimeoutSec: 60,
|
|
10500
|
+
execMaxOutputChars: 200000,
|
|
10501
|
+
});
|
|
10502
|
+
var local = state[0];
|
|
10503
|
+
var setLocal = state[1];
|
|
10504
|
+
|
|
10505
|
+
var adopt = function (settings, extra) {
|
|
10506
|
+
var value = settings || {};
|
|
10507
|
+
setLocal(function (previous) {
|
|
10508
|
+
return Object.assign({}, previous, {
|
|
10509
|
+
loading: false,
|
|
10510
|
+
execEnabled: typeof value.execEnabled === 'boolean' ? value.execEnabled : previous.execEnabled,
|
|
10511
|
+
execHostIds: Array.isArray(value.execHostIds) ? value.execHostIds : previous.execHostIds,
|
|
10512
|
+
execWorkspaceIds: Array.isArray(value.execWorkspaceIds) ? value.execWorkspaceIds : previous.execWorkspaceIds,
|
|
10513
|
+
execTimeoutSec: Math.round((Number(value.execTimeoutMs) || previous.execTimeoutSec * 1000) / 1000),
|
|
10514
|
+
execMaxOutputChars: Number(value.execMaxOutputChars) || previous.execMaxOutputChars,
|
|
10515
|
+
}, extra || {});
|
|
10516
|
+
});
|
|
10517
|
+
};
|
|
10518
|
+
|
|
10519
|
+
useEffect(function () {
|
|
10520
|
+
var alive = true;
|
|
10521
|
+
apiCall('settings.get', {}).then(function (settings) {
|
|
10522
|
+
if (alive) adopt(settings);
|
|
10523
|
+
}).catch(function (error) {
|
|
10524
|
+
if (!alive) return;
|
|
10525
|
+
setLocal(function (previous) {
|
|
10526
|
+
return Object.assign({}, previous, {
|
|
10527
|
+
loading: false,
|
|
10528
|
+
message: { kind: 'error', text: messageOf(error, t, locale) },
|
|
10529
|
+
});
|
|
10530
|
+
});
|
|
10531
|
+
});
|
|
10532
|
+
return function () { alive = false; };
|
|
10533
|
+
}, []);
|
|
10534
|
+
|
|
10535
|
+
function save(patch, okText) {
|
|
10536
|
+
if (local.saving) return;
|
|
10537
|
+
setLocal(function (previous) { return Object.assign({}, previous, { saving: true, message: null }); });
|
|
10538
|
+
apiCall('settings.update', patch).then(function (settings) {
|
|
10539
|
+
adopt(settings, {
|
|
10540
|
+
saving: false,
|
|
10541
|
+
message: okText ? { kind: 'success', text: okText } : null,
|
|
10542
|
+
});
|
|
10543
|
+
}).catch(function (error) {
|
|
10544
|
+
setLocal(function (previous) {
|
|
10545
|
+
return Object.assign({}, previous, {
|
|
10546
|
+
saving: false,
|
|
10547
|
+
message: { kind: 'error', text: messageOf(error, t, locale) },
|
|
10548
|
+
});
|
|
10549
|
+
});
|
|
10550
|
+
});
|
|
10551
|
+
}
|
|
10552
|
+
|
|
10553
|
+
function withId(list, id, checked) {
|
|
10554
|
+
var next = (list || []).filter(function (item) { return item !== id; });
|
|
10555
|
+
if (checked) next.push(id);
|
|
10556
|
+
return next;
|
|
10557
|
+
}
|
|
10558
|
+
|
|
10559
|
+
function openAudit() {
|
|
10560
|
+
apiCall('meta.info', {}).then(function (info) {
|
|
10561
|
+
if (!info || !info.execAuditFile) return null;
|
|
10562
|
+
return apiCall('local.openExternal', { path: info.execAuditFile });
|
|
10563
|
+
}).catch(function (error) {
|
|
10564
|
+
setLocal(function (previous) {
|
|
10565
|
+
return Object.assign({}, previous, {
|
|
10566
|
+
message: { kind: 'error', text: messageOf(error, t, locale) },
|
|
10567
|
+
});
|
|
10568
|
+
});
|
|
10569
|
+
});
|
|
10570
|
+
}
|
|
10571
|
+
|
|
10572
|
+
function numberRow(label, value, min, max, step, onCommit) {
|
|
10573
|
+
return h('label', { className: 'rw-inline', style: { gap: 6 } },
|
|
10574
|
+
h('span', { className: 'rw-group-hint' }, label),
|
|
10575
|
+
h('input', {
|
|
10576
|
+
className: 'rw-input',
|
|
10577
|
+
style: { width: 92 },
|
|
10578
|
+
type: 'number',
|
|
10579
|
+
min: min,
|
|
10580
|
+
max: max,
|
|
10581
|
+
step: step,
|
|
10582
|
+
value: String(value),
|
|
10583
|
+
onChange: function (event) {
|
|
10584
|
+
var next = Number(event.currentTarget.value);
|
|
10585
|
+
setLocal(function (previous) {
|
|
10586
|
+
var patch = {};
|
|
10587
|
+
patch[onCommit.field] = Number.isFinite(next) ? next : previous[onCommit.field];
|
|
10588
|
+
return Object.assign({}, previous, patch);
|
|
10589
|
+
});
|
|
10590
|
+
},
|
|
10591
|
+
onBlur: function () { onCommit.commit(local[onCommit.field]); },
|
|
10592
|
+
}));
|
|
10593
|
+
}
|
|
10594
|
+
|
|
10595
|
+
var children = [
|
|
10596
|
+
h('div', { className: 'rw-group-head' },
|
|
10597
|
+
h('span', { className: 'rw-group-title' }, t('execTitle')),
|
|
10598
|
+
h('span', { className: 'rw-group-hint' }, t('execHint'))),
|
|
10599
|
+
h('div', { className: 'rw-setting-row' },
|
|
10600
|
+
h(Switch, {
|
|
10601
|
+
checked: local.execEnabled,
|
|
10602
|
+
onChange: function (next) { save({ execEnabled: Boolean(next) }, t('execSaved')); },
|
|
10603
|
+
label: t('execEnabledLabel'),
|
|
10604
|
+
text: t('execEnabledLabel'),
|
|
10605
|
+
}),
|
|
10606
|
+
local.saving ? Spinner(12) : null),
|
|
10607
|
+
];
|
|
10608
|
+
|
|
10609
|
+
if (local.execEnabled) {
|
|
10610
|
+
children.push(h('div', { className: 'rw-group-hint', style: { marginTop: 8, color: 'rgb(210,153,34)' } }, t('execWarn')));
|
|
10611
|
+
children.push(h('div', { className: 'rw-group-head', style: { marginTop: 12 } },
|
|
10612
|
+
h('span', { className: 'rw-group-title' }, t('execHostsTitle'))));
|
|
10613
|
+
children.push(hosts.length === 0
|
|
10614
|
+
? h('div', { className: 'rw-hint' }, t('execHostsEmpty'))
|
|
10615
|
+
: h('div', { className: 'rw-exec-list' }, hosts.map(function (host) {
|
|
10616
|
+
var checked = local.execHostIds.indexOf(host.id) >= 0;
|
|
10617
|
+
return h('label', { key: host.id, className: 'rw-exec-item' },
|
|
10618
|
+
h('input', {
|
|
10619
|
+
type: 'checkbox',
|
|
10620
|
+
checked: checked,
|
|
10621
|
+
onChange: function (event) {
|
|
10622
|
+
var on = event.currentTarget.checked;
|
|
10623
|
+
save({ execHostIds: withId(local.execHostIds, host.id, on) }, t('execSaved'));
|
|
10624
|
+
},
|
|
10625
|
+
}),
|
|
10626
|
+
h('span', { className: 'rw-exec-name' }, host.name || host.host || host.id),
|
|
10627
|
+
h('span', { className: 'rw-exec-meta' }, (host.username ? host.username + '@' : '') + (host.host || '') + (host.port ? ':' + host.port : '')));
|
|
10628
|
+
})));
|
|
10629
|
+
children.push(h('div', { className: 'rw-group-head', style: { marginTop: 12 } },
|
|
10630
|
+
h('span', { className: 'rw-group-title' }, t('execWorkspacesTitle')),
|
|
10631
|
+
h('span', { className: 'rw-group-hint' }, t('execWorkspacesHint'))));
|
|
10632
|
+
children.push(workspaces.length === 0
|
|
10633
|
+
? h('div', { className: 'rw-hint' }, t('execHostsEmpty'))
|
|
10634
|
+
: h('div', { className: 'rw-exec-list' }, workspaces.map(function (item) {
|
|
10635
|
+
var checked = local.execWorkspaceIds.indexOf(item.id) >= 0;
|
|
10636
|
+
return h('label', { key: item.id, className: 'rw-exec-item' },
|
|
10637
|
+
h('input', {
|
|
10638
|
+
type: 'checkbox',
|
|
10639
|
+
checked: checked,
|
|
10640
|
+
onChange: function (event) {
|
|
10641
|
+
var on = event.currentTarget.checked;
|
|
10642
|
+
save({ execWorkspaceIds: withId(local.execWorkspaceIds, item.id, on) }, t('execSaved'));
|
|
10643
|
+
},
|
|
10644
|
+
}),
|
|
10645
|
+
h('span', { className: 'rw-exec-name' }, item.name || item.id),
|
|
10646
|
+
h('span', { className: 'rw-exec-meta' }, item.remotePath || ''));
|
|
10647
|
+
})));
|
|
10648
|
+
children.push(h('div', { className: 'rw-inline', style: { marginTop: 12, flexWrap: 'wrap', gap: 12 } },
|
|
10649
|
+
numberRow(t('execTimeoutLabel'), local.execTimeoutSec, 1, 600, 1, {
|
|
10650
|
+
field: 'execTimeoutSec',
|
|
10651
|
+
commit: function (value) {
|
|
10652
|
+
save({ execTimeoutMs: Math.round((Number(value) || 60) * 1000) }, t('execSaved'));
|
|
10653
|
+
},
|
|
10654
|
+
}),
|
|
10655
|
+
numberRow(t('execOutputLabel'), local.execMaxOutputChars, 1000, 400000, 1000, {
|
|
10656
|
+
field: 'execMaxOutputChars',
|
|
10657
|
+
commit: function (value) {
|
|
10658
|
+
save({ execMaxOutputChars: Math.round(Number(value) || 200000) }, t('execSaved'));
|
|
10659
|
+
},
|
|
10660
|
+
}),
|
|
10661
|
+
h('button', {
|
|
10662
|
+
type: 'button',
|
|
10663
|
+
className: 'rw-btn rw-btn-ghost rw-btn-sm',
|
|
10664
|
+
onClick: openAudit,
|
|
10665
|
+
}, IconTerminal(13), t('execAuditOpen'))));
|
|
10666
|
+
}
|
|
10667
|
+
|
|
10668
|
+
if (local.message) {
|
|
10669
|
+
children.push(h(Banner, {
|
|
10670
|
+
kind: local.message.kind === 'success' ? 'success' : 'error',
|
|
10671
|
+
onClose: function () {
|
|
10672
|
+
setLocal(function (previous) { return Object.assign({}, previous, { message: null }); });
|
|
10673
|
+
},
|
|
10674
|
+
}, local.message.text));
|
|
10675
|
+
}
|
|
10676
|
+
|
|
10677
|
+
return h('div', { className: 'rw-group' }, children);
|
|
10678
|
+
}
|
|
10679
|
+
|
|
10458
10680
|
function ConnectionsPage(props) {
|
|
10459
10681
|
var ctx = props.ctx;
|
|
10460
10682
|
var locale = useLocale(ctx);
|
|
@@ -10515,6 +10737,12 @@ function rememberShowHidden(value) {
|
|
|
10515
10737
|
!sidebarAvailable ? h(Banner, { kind: 'warn' }, t('needsSidebar')) : null,
|
|
10516
10738
|
h(ThemeGroup, { t: t, locale: locale }),
|
|
10517
10739
|
h(EditorSettingsGroup, { t: t, locale: locale }),
|
|
10740
|
+
h(ExecSettingsGroup, {
|
|
10741
|
+
t: t,
|
|
10742
|
+
locale: locale,
|
|
10743
|
+
hosts: remote.data.hosts || [],
|
|
10744
|
+
workspaces: links.concat(remotes),
|
|
10745
|
+
}),
|
|
10518
10746
|
adding === 'linked'
|
|
10519
10747
|
? h(AddWorkspaceFlow, {
|
|
10520
10748
|
ctx: ctx, t: t, locale: locale,
|
package/lib/index.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { randomUUID } from 'node:crypto'
|
|
19
19
|
import { chmodSync, closeSync, cpSync, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
20
20
|
import { spawn } from 'node:child_process'
|
|
21
|
-
import { mkdir, readdir, rm, stat as fsStat } from 'node:fs/promises'
|
|
21
|
+
import { appendFile, mkdir, readdir, rename, rm, stat as fsStat } from 'node:fs/promises'
|
|
22
22
|
import { homedir, tmpdir } from 'node:os'
|
|
23
23
|
import { basename, dirname, extname, isAbsolute, join, posix, resolve, sep } from 'node:path'
|
|
24
24
|
import { fileURLToPath } from 'node:url'
|
|
@@ -38,7 +38,7 @@ export const inject = ['webServer', 'tools', 'systemPrompt', 'workingDirectory']
|
|
|
38
38
|
* is still running an older copy of the Host — refreshing the page only swaps
|
|
39
39
|
* the browser bundle, so the two halves can drift by one restart.
|
|
40
40
|
*/
|
|
41
|
-
const API_REVISION =
|
|
41
|
+
const API_REVISION = 3
|
|
42
42
|
|
|
43
43
|
/** When this copy of the Host was loaded; shown by `meta.info`. */
|
|
44
44
|
const STARTED_AT = new Date().toISOString()
|
|
@@ -55,7 +55,9 @@ const PACKAGE_VERSION = (() => {
|
|
|
55
55
|
|
|
56
56
|
const DATA_VERSION = 1
|
|
57
57
|
const SETTINGS_VERSION = 1
|
|
58
|
-
const SETTINGS_DEFAULTS = Object.freeze({ editorTheme: 'github-light', editorThemeFamily: 'github', editorThemeMode: 'system', fileOpenMode: 'editor', autoSave: false })
|
|
58
|
+
const SETTINGS_DEFAULTS = Object.freeze({ editorTheme: 'github-light', editorThemeFamily: 'github', editorThemeMode: 'system', fileOpenMode: 'editor', autoSave: false, execEnabled: false, execTimeoutMs: 60000, execMaxOutputChars: 200000, execShell: '' })
|
|
59
|
+
/** Exec allow-lists travel as arrays, so they are not part of the frozen defaults. */
|
|
60
|
+
const EMPTY_ID_LIST = Object.freeze([])
|
|
59
61
|
const EDITOR_THEME_FAMILIES = new Set(['github', 'solarized', 'one', 'dracula', 'monokai', 'nord', 'vscode', 'xcode', 'catppuccin'])
|
|
60
62
|
const THEME_FAMILY_OF = (id) => {
|
|
61
63
|
const value = String(id || '')
|
|
@@ -92,6 +94,17 @@ const PEEK_LIMIT = 512 * 1024
|
|
|
92
94
|
const READ_CAP = 8 * 1024 * 1024
|
|
93
95
|
const MAX_WRITE_BYTES = 8 * 1024 * 1024
|
|
94
96
|
const MAX_MEDIA_BYTES = 24 * 1024 * 1024
|
|
97
|
+
// ── remote command execution (0.17.0) ───────────────────────────────────────
|
|
98
|
+
/** Longest command line accepted; anything longer is almost always a paste error. */
|
|
99
|
+
const EXEC_MAX_COMMAND = 8000
|
|
100
|
+
const EXEC_TIMEOUT_DEFAULT = 60_000
|
|
101
|
+
const EXEC_TIMEOUT_MAX = 600_000
|
|
102
|
+
const EXEC_OUTPUT_DEFAULT = 200_000
|
|
103
|
+
const EXEC_OUTPUT_MAX = 400_000
|
|
104
|
+
const EXEC_OUTPUT_HEAD = 4000
|
|
105
|
+
const EXEC_AUDIT_NAME = 'exec-audit.jsonl'
|
|
106
|
+
const EXEC_AUDIT_MAX_BYTES = 5 * 1024 * 1024
|
|
107
|
+
const EXEC_SHELL_RE = /^[\w./-]{1,200}$/
|
|
95
108
|
const IMAGE_MIME = Object.freeze({
|
|
96
109
|
'.png': 'image/png',
|
|
97
110
|
'.jpg': 'image/jpeg',
|
|
@@ -159,6 +172,12 @@ const ERROR_STATUS = {
|
|
|
159
172
|
FS_EXISTS: 409,
|
|
160
173
|
CONFLICT: 409,
|
|
161
174
|
INTERNAL: 500,
|
|
175
|
+
// 0.17.0 — remote command execution
|
|
176
|
+
EXEC_DISABLED: 403,
|
|
177
|
+
EXEC_HOST_NOT_ALLOWED: 403,
|
|
178
|
+
EXEC_WORKSPACE_NOT_ALLOWED: 403,
|
|
179
|
+
EXEC_TIMEOUT: 504,
|
|
180
|
+
EXEC_FAILED: 502,
|
|
162
181
|
}
|
|
163
182
|
|
|
164
183
|
class ApiError extends Error {
|
|
@@ -408,10 +427,32 @@ function isThemeId(value) {
|
|
|
408
427
|
return typeof value === 'string' && /^[a-z0-9][a-z0-9-]{0,39}$/.test(value)
|
|
409
428
|
}
|
|
410
429
|
|
|
430
|
+
/** Keeps only non-empty strings, trims them and drops duplicates. */
|
|
431
|
+
function normalizeIdList(value) {
|
|
432
|
+
if (!Array.isArray(value)) return []
|
|
433
|
+
const seen = new Set()
|
|
434
|
+
const out = []
|
|
435
|
+
for (const item of value) {
|
|
436
|
+
if (typeof item !== 'string') continue
|
|
437
|
+
const id = item.trim()
|
|
438
|
+
if (id === '' || seen.has(id)) continue
|
|
439
|
+
seen.add(id)
|
|
440
|
+
out.push(id)
|
|
441
|
+
if (out.length >= 200) break
|
|
442
|
+
}
|
|
443
|
+
return out
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function clampInt(value, min, max, fallback) {
|
|
447
|
+
const number = Number(value)
|
|
448
|
+
if (!Number.isFinite(number)) return fallback
|
|
449
|
+
return Math.min(max, Math.max(min, Math.round(number)))
|
|
450
|
+
}
|
|
451
|
+
|
|
411
452
|
class SettingsStore {
|
|
412
453
|
constructor(file) {
|
|
413
454
|
this.file = file
|
|
414
|
-
this.value = { ...SETTINGS_DEFAULTS }
|
|
455
|
+
this.value = { ...SETTINGS_DEFAULTS, execHostIds: [], execWorkspaceIds: [] }
|
|
415
456
|
const raw = readJsonFile(file, { version: SETTINGS_VERSION, settings: {} })
|
|
416
457
|
const settings = raw && typeof raw === 'object' && raw.settings && typeof raw.settings === 'object'
|
|
417
458
|
? raw.settings
|
|
@@ -422,6 +463,22 @@ class SettingsStore {
|
|
|
422
463
|
if (settings && typeof settings === 'object' && FILE_OPEN_MODES.has(settings.fileOpenMode)) {
|
|
423
464
|
this.value.fileOpenMode = settings.fileOpenMode
|
|
424
465
|
}
|
|
466
|
+
if (settings && typeof settings === 'object' && typeof settings.execEnabled === 'boolean') {
|
|
467
|
+
this.value.execEnabled = settings.execEnabled
|
|
468
|
+
}
|
|
469
|
+
if (settings && typeof settings === 'object') {
|
|
470
|
+
this.value.execHostIds = normalizeIdList(settings.execHostIds)
|
|
471
|
+
this.value.execWorkspaceIds = normalizeIdList(settings.execWorkspaceIds)
|
|
472
|
+
if (settings.execTimeoutMs !== undefined) {
|
|
473
|
+
this.value.execTimeoutMs = clampInt(settings.execTimeoutMs, 1000, EXEC_TIMEOUT_MAX, EXEC_TIMEOUT_DEFAULT)
|
|
474
|
+
}
|
|
475
|
+
if (settings.execMaxOutputChars !== undefined) {
|
|
476
|
+
this.value.execMaxOutputChars = clampInt(settings.execMaxOutputChars, 1000, EXEC_OUTPUT_MAX, EXEC_OUTPUT_DEFAULT)
|
|
477
|
+
}
|
|
478
|
+
if (typeof settings.execShell === 'string' && (settings.execShell === '' || EXEC_SHELL_RE.test(settings.execShell))) {
|
|
479
|
+
this.value.execShell = settings.execShell
|
|
480
|
+
}
|
|
481
|
+
}
|
|
425
482
|
if (settings && typeof settings === 'object' && typeof settings.autoSave === 'boolean') {
|
|
426
483
|
this.value.autoSave = settings.autoSave
|
|
427
484
|
}
|
|
@@ -453,7 +510,11 @@ class SettingsStore {
|
|
|
453
510
|
}
|
|
454
511
|
|
|
455
512
|
get() {
|
|
456
|
-
return {
|
|
513
|
+
return {
|
|
514
|
+
...this.value,
|
|
515
|
+
execHostIds: this.value.execHostIds ? this.value.execHostIds.slice() : [],
|
|
516
|
+
execWorkspaceIds: this.value.execWorkspaceIds ? this.value.execWorkspaceIds.slice() : [],
|
|
517
|
+
}
|
|
457
518
|
}
|
|
458
519
|
|
|
459
520
|
update(patch = {}) {
|
|
@@ -481,6 +542,30 @@ class SettingsStore {
|
|
|
481
542
|
if (typeof patch.autoSave !== 'boolean') throw new ApiError('BAD_REQUEST', '自动保存设置无效')
|
|
482
543
|
this.value.autoSave = patch.autoSave
|
|
483
544
|
}
|
|
545
|
+
if (patch && typeof patch === 'object' && patch.execEnabled !== undefined) {
|
|
546
|
+
if (typeof patch.execEnabled !== 'boolean') throw new ApiError('BAD_REQUEST', '远端命令执行设置无效')
|
|
547
|
+
this.value.execEnabled = patch.execEnabled
|
|
548
|
+
}
|
|
549
|
+
if (patch && typeof patch === 'object' && patch.execHostIds !== undefined) {
|
|
550
|
+
if (!Array.isArray(patch.execHostIds)) throw new ApiError('BAD_REQUEST', '执行白名单必须是主机 id 数组')
|
|
551
|
+
this.value.execHostIds = normalizeIdList(patch.execHostIds)
|
|
552
|
+
}
|
|
553
|
+
if (patch && typeof patch === 'object' && patch.execWorkspaceIds !== undefined) {
|
|
554
|
+
if (!Array.isArray(patch.execWorkspaceIds)) throw new ApiError('BAD_REQUEST', '执行白名单必须是工作区 id 数组')
|
|
555
|
+
this.value.execWorkspaceIds = normalizeIdList(patch.execWorkspaceIds)
|
|
556
|
+
}
|
|
557
|
+
if (patch && typeof patch === 'object' && patch.execTimeoutMs !== undefined) {
|
|
558
|
+
this.value.execTimeoutMs = clampInt(patch.execTimeoutMs, 1000, EXEC_TIMEOUT_MAX, EXEC_TIMEOUT_DEFAULT)
|
|
559
|
+
}
|
|
560
|
+
if (patch && typeof patch === 'object' && patch.execMaxOutputChars !== undefined) {
|
|
561
|
+
this.value.execMaxOutputChars = clampInt(patch.execMaxOutputChars, 1000, EXEC_OUTPUT_MAX, EXEC_OUTPUT_DEFAULT)
|
|
562
|
+
}
|
|
563
|
+
if (patch && typeof patch === 'object' && patch.execShell !== undefined) {
|
|
564
|
+
if (typeof patch.execShell !== 'string' || (patch.execShell !== '' && !EXEC_SHELL_RE.test(patch.execShell))) {
|
|
565
|
+
throw new ApiError('BAD_REQUEST', '解释器路径无效')
|
|
566
|
+
}
|
|
567
|
+
this.value.execShell = patch.execShell
|
|
568
|
+
}
|
|
484
569
|
writeJsonAtomic(this.file, { version: SETTINGS_VERSION, settings: { ...this.value, themeExplicit: this.themeExplicit === true } })
|
|
485
570
|
return this.get()
|
|
486
571
|
}
|
|
@@ -1450,8 +1535,9 @@ export function apply(ctx) {
|
|
|
1450
1535
|
'- action "info" | "list_dir" | "read" | "write" | "replace" | "stat" | "mkdir" | "rename" | "delete" takes `path` relative to the remote root (or an absolute path inside it).',
|
|
1451
1536
|
'- Writes are atomic. Pass `if_modified_since` (epoch milliseconds from a previous read/stat) to refuse a stale overwrite.',
|
|
1452
1537
|
'- action "sync" archives the remote tree into `.remote/` and only exists for a linked workspace (a remote workspace has no local copy).',
|
|
1538
|
+
'- action "exec" runs ONE non-interactive command on the remote host (builds, tests, logs). It only works when the user switched remote execution on and allow-listed this host/workspace; every attempt is audited.',
|
|
1453
1539
|
'The workspace is resolved from the session working directory; pass `workspace` (id, local path, placeholder path or name) when working elsewhere.',
|
|
1454
|
-
'For a REMOTE workspace do not create project files in the placeholder and do not expect local paths to exist: read, write, build and inspect logs on the remote host, through linked_workspace actions or `ssh` when an action does not fit.',
|
|
1540
|
+
'For a REMOTE workspace do not create project files in the placeholder and do not expect local paths to exist: read, write, build and inspect logs on the remote host, through linked_workspace actions or `ssh` when an action does not fit. Prefer action "exec" over `ssh` when it is enabled: it keeps the audit trail and the output limits.',
|
|
1455
1541
|
'Locally installed skills (~/.dsh/skills, ~/.agents/skills) remain available; use `linked_skills` to list or read them. A linked workspace also sees the project skills of its local directory.',
|
|
1456
1542
|
'Do not hand-edit `.remote/`; it is a mirror of the remote tree. Prefer linked_workspace over bash/read/write for anything under the remote root, and list first when unsure which workspace you are in.',
|
|
1457
1543
|
].join('\n')
|
|
@@ -2165,6 +2251,48 @@ export function apply(ctx) {
|
|
|
2165
2251
|
return { ok: true, query, entries, truncated: truncatedReason !== '', truncatedReason }
|
|
2166
2252
|
}
|
|
2167
2253
|
|
|
2254
|
+
// ── remote command execution ──────────────────────────────────────────────
|
|
2255
|
+
|
|
2256
|
+
/**
|
|
2257
|
+
* Append-only audit trail for `hosts.exec` (0.17.0). Every attempt is logged,
|
|
2258
|
+
* refusals included, so a later "did the agent run anything?" question has an
|
|
2259
|
+
* answer even when the command never reached the host.
|
|
2260
|
+
*/
|
|
2261
|
+
const execAuditFile = () => join(dir, EXEC_AUDIT_NAME)
|
|
2262
|
+
|
|
2263
|
+
const rotateExecAudit = async () => {
|
|
2264
|
+
const file = execAuditFile()
|
|
2265
|
+
const info = await fsStat(file).catch(() => null)
|
|
2266
|
+
if (!info || info.size < EXEC_AUDIT_MAX_BYTES) return
|
|
2267
|
+
await rm(`${file}.1`, { force: true }).catch(() => {})
|
|
2268
|
+
await rename(file, `${file}.1`).catch(() => {})
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
const appendExecAudit = async (entry) => {
|
|
2272
|
+
const file = execAuditFile()
|
|
2273
|
+
const line = `${JSON.stringify(entry)}\n`
|
|
2274
|
+
try {
|
|
2275
|
+
await rotateExecAudit()
|
|
2276
|
+
await appendFile(file, line, { mode: 0o600 })
|
|
2277
|
+
} catch {
|
|
2278
|
+
// Auditing must not turn a successful command into a failure, but a
|
|
2279
|
+
// silently unwritable log is worse: surface it on stderr once.
|
|
2280
|
+
if (!appendExecAudit.warned) {
|
|
2281
|
+
appendExecAudit.warned = true
|
|
2282
|
+
console.error('[dsh-linked-workspace] cannot write the exec audit log')
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
const clipOutput = (text, budget) => {
|
|
2288
|
+
const value = String(text || '')
|
|
2289
|
+
return {
|
|
2290
|
+
text: value.length > budget ? value.slice(0, budget) : value,
|
|
2291
|
+
bytes: Buffer.byteLength(value, 'utf8'),
|
|
2292
|
+
truncated: value.length > budget,
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2168
2296
|
// ── method table ─────────────────────────────────────────────────────────
|
|
2169
2297
|
|
|
2170
2298
|
const methods = {
|
|
@@ -2308,6 +2436,133 @@ export function apply(ctx) {
|
|
|
2308
2436
|
return { disk: { path: target, size, used, avail, percent } }
|
|
2309
2437
|
},
|
|
2310
2438
|
|
|
2439
|
+
/**
|
|
2440
|
+
* Runs one non-interactive command on the remote host (0.17.0).
|
|
2441
|
+
*
|
|
2442
|
+
* Three gates must all pass: the feature switch, the host allow-list and —
|
|
2443
|
+
* when it is configured — the workspace allow-list. Every attempt, refusals
|
|
2444
|
+
* included, is written to `exec-audit.jsonl` before the caller hears back.
|
|
2445
|
+
*/
|
|
2446
|
+
async 'hosts.exec'(params = {}) {
|
|
2447
|
+
const settings = settingsStore.get()
|
|
2448
|
+
const startedAt = new Date().toISOString()
|
|
2449
|
+
const auditId = randomUUID()
|
|
2450
|
+
const command = String(typeof params.command === 'string' ? params.command : '').replace(/\r\n/g, '\n').trim()
|
|
2451
|
+
|
|
2452
|
+
let scope = null
|
|
2453
|
+
let host = null
|
|
2454
|
+
if (typeof params.linkedId === 'string' && params.linkedId.trim() !== '') {
|
|
2455
|
+
scope = await requireScope({ linkedId: params.linkedId })
|
|
2456
|
+
} else if (typeof params.remoteId === 'string' && params.remoteId.trim() !== '') {
|
|
2457
|
+
scope = await requireScope({ remoteId: params.remoteId })
|
|
2458
|
+
}
|
|
2459
|
+
if (scope) host = await findHost(scope.record.hostId)
|
|
2460
|
+
else if (typeof params.hostId === 'string' && params.hostId.trim() !== '') host = await findHost(params.hostId.trim())
|
|
2461
|
+
else throw new ApiError('BAD_REQUEST', 'hostId、linkedId 或 remoteId 三选一')
|
|
2462
|
+
|
|
2463
|
+
const hostId = host.id
|
|
2464
|
+
const hostName = host.name || host.host || hostId
|
|
2465
|
+
const kind = scope ? scope.kind : 'host'
|
|
2466
|
+
const workspaceId = scope && scope.record.workspaceId ? scope.record.workspaceId : ''
|
|
2467
|
+
|
|
2468
|
+
const audit = (extra) => appendExecAudit({
|
|
2469
|
+
ts: startedAt, auditId, hostId, hostName, workspaceId, kind, command, ...extra,
|
|
2470
|
+
})
|
|
2471
|
+
const denied = async (code, message) => {
|
|
2472
|
+
await audit({ refusal: code, message })
|
|
2473
|
+
return new ApiError(code, message)
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
if (settings.execEnabled !== true) {
|
|
2477
|
+
throw await denied('EXEC_DISABLED', '远端命令执行未启用:先到「设置 → 联动工作区 → 远端命令执行」打开开关,并把主机加入白名单')
|
|
2478
|
+
}
|
|
2479
|
+
if (!settings.execHostIds.includes(hostId)) {
|
|
2480
|
+
throw await denied('EXEC_HOST_NOT_ALLOWED', `主机「${hostName}」不在远端命令执行的白名单里`)
|
|
2481
|
+
}
|
|
2482
|
+
const workspaceAllow = settings.execWorkspaceIds
|
|
2483
|
+
if (workspaceAllow.length > 0) {
|
|
2484
|
+
const allowed = Boolean(scope)
|
|
2485
|
+
&& (workspaceAllow.includes(workspaceId) || workspaceAllow.includes(scope.record.id))
|
|
2486
|
+
if (!allowed) {
|
|
2487
|
+
const label = scope ? (scope.record.name || scope.record.id) : hostName
|
|
2488
|
+
throw await denied('EXEC_WORKSPACE_NOT_ALLOWED', `「${label}」不在远端命令执行的工作区白名单里`)
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
if (command === '') throw await denied('BAD_REQUEST', 'command 不能为空')
|
|
2492
|
+
if (command.length > EXEC_MAX_COMMAND) {
|
|
2493
|
+
throw await denied('BAD_REQUEST', `命令太长(上限 ${EXEC_MAX_COMMAND} 字符)`)
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
let cwd = scope ? scope.root : ''
|
|
2497
|
+
if (typeof params.cwd === 'string' && params.cwd.trim() !== '') {
|
|
2498
|
+
if (scope) {
|
|
2499
|
+
cwd = scopeTarget(scope, params.cwd)
|
|
2500
|
+
} else {
|
|
2501
|
+
const text = params.cwd.trim()
|
|
2502
|
+
if (!text.startsWith('/')) throw await denied('BAD_REQUEST', 'cwd 需要是绝对路径')
|
|
2503
|
+
cwd = posix.resolve(text)
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
const timeoutMs = clampInt(params.timeoutMs, 1000, EXEC_TIMEOUT_MAX, settings.execTimeoutMs || EXEC_TIMEOUT_DEFAULT)
|
|
2508
|
+
const budget = clampInt(settings.execMaxOutputChars, 1000, EXEC_OUTPUT_MAX, EXEC_OUTPUT_DEFAULT)
|
|
2509
|
+
const perStream = Math.max(1000, Math.floor(budget / 2))
|
|
2510
|
+
const shell = settings.execShell ? String(settings.execShell) : ''
|
|
2511
|
+
const script = shell ? `${shell} -lc ${shellQuoteArg(command)}` : command
|
|
2512
|
+
const wrapped = cwd ? `cd ${shellQuoteArg(cwd)} && ${script}` : script
|
|
2513
|
+
|
|
2514
|
+
const started = Date.now()
|
|
2515
|
+
let result
|
|
2516
|
+
try {
|
|
2517
|
+
const remote = scope ? scope.remote : await connectHost(host)
|
|
2518
|
+
result = await remote.exec(wrapped, { timeoutMs })
|
|
2519
|
+
} catch (error) {
|
|
2520
|
+
const durationMs = Date.now() - started
|
|
2521
|
+
const timedOut = error && error.code === 'TIMEOUT'
|
|
2522
|
+
const message = error && error.message ? error.message : String(error)
|
|
2523
|
+
await audit({ cwd, exitCode: null, durationMs, error: message })
|
|
2524
|
+
if (timedOut) {
|
|
2525
|
+
throw new ApiError('EXEC_TIMEOUT', `命令超时(${timeoutMs} ms 后中止):${command.slice(0, 120)}`)
|
|
2526
|
+
}
|
|
2527
|
+
throw new ApiError('EXEC_FAILED', message)
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
const durationMs = Date.now() - started
|
|
2531
|
+
const out = clipOutput(result.stdout, perStream)
|
|
2532
|
+
const err = clipOutput(result.stderr, perStream)
|
|
2533
|
+
const exitCode = Number.isFinite(result.code) ? result.code : 0
|
|
2534
|
+
const truncated = out.truncated || err.truncated
|
|
2535
|
+
const stdoutHead = out.text.slice(0, EXEC_OUTPUT_HEAD)
|
|
2536
|
+
const stderrHead = err.text.slice(0, EXEC_OUTPUT_HEAD)
|
|
2537
|
+
await audit({
|
|
2538
|
+
cwd,
|
|
2539
|
+
exitCode,
|
|
2540
|
+
durationMs,
|
|
2541
|
+
stdoutBytes: out.bytes,
|
|
2542
|
+
stderrBytes: err.bytes,
|
|
2543
|
+
truncated,
|
|
2544
|
+
stdoutHead,
|
|
2545
|
+
stderrHead,
|
|
2546
|
+
})
|
|
2547
|
+
return {
|
|
2548
|
+
hostId,
|
|
2549
|
+
hostName,
|
|
2550
|
+
workspaceId,
|
|
2551
|
+
kind,
|
|
2552
|
+
command,
|
|
2553
|
+
cwd,
|
|
2554
|
+
exitCode,
|
|
2555
|
+
stdout: out.text,
|
|
2556
|
+
stderr: err.text,
|
|
2557
|
+
stdoutBytes: out.bytes,
|
|
2558
|
+
stderrBytes: err.bytes,
|
|
2559
|
+
truncated,
|
|
2560
|
+
durationMs,
|
|
2561
|
+
startedAt,
|
|
2562
|
+
auditId,
|
|
2563
|
+
}
|
|
2564
|
+
},
|
|
2565
|
+
|
|
2311
2566
|
async 'fs.list'(params = {}) {
|
|
2312
2567
|
const scope = await requireScope(params)
|
|
2313
2568
|
const target = params.path === undefined || params.path === ''
|
|
@@ -2764,7 +3019,12 @@ export function apply(ctx) {
|
|
|
2764
3019
|
* needs newer methods.
|
|
2765
3020
|
*/
|
|
2766
3021
|
async 'meta.info'() {
|
|
2767
|
-
return {
|
|
3022
|
+
return {
|
|
3023
|
+
version: PACKAGE_VERSION,
|
|
3024
|
+
apiRevision: API_REVISION,
|
|
3025
|
+
startedAt: STARTED_AT,
|
|
3026
|
+
execAuditFile: join(dir, EXEC_AUDIT_NAME),
|
|
3027
|
+
}
|
|
2768
3028
|
},
|
|
2769
3029
|
|
|
2770
3030
|
// ── settings ───────────────────────────────────────────────────────────
|
|
@@ -3918,7 +4178,7 @@ export function apply(ctx) {
|
|
|
3918
4178
|
isConcurrencySafe: (args) => ['list', 'info', 'list_dir', 'read', 'stat'].includes(String((args && args.action) || '').trim()),
|
|
3919
4179
|
description:
|
|
3920
4180
|
'Read and edit files of a remote project over SSH: either a linked workspace (a local directory paired with a remote directory) or a remote workspace (a remote directory whose session runs in an empty local placeholder). '
|
|
3921
|
-
+ 'Actions: list (all linked and remote workspaces), info, list_dir, read, write, replace, stat, mkdir, rename, delete, sync (linked workspaces only). '
|
|
4181
|
+
+ 'Actions: list (all linked and remote workspaces), info, list_dir, read, write, replace, stat, mkdir, rename, delete, sync (linked workspaces only), exec (runs one non-interactive command on the remote host; needs the switch and allow-lists). '
|
|
3922
4182
|
+ '`path` is relative to the remote root (or an absolute path inside it). Writes are atomic; pass `if_modified_since` from a previous read/stat to refuse a stale overwrite. '
|
|
3923
4183
|
+ 'The workspace is resolved from the session working directory; pass `workspace` (id, local path, placeholder path or name) when working elsewhere. '
|
|
3924
4184
|
+ 'Local files of a linked workspace (including .local/ and .remote/) still use the normal read/write/bash tools.',
|
|
@@ -3927,8 +4187,8 @@ export function apply(ctx) {
|
|
|
3927
4187
|
properties: {
|
|
3928
4188
|
action: {
|
|
3929
4189
|
type: 'string',
|
|
3930
|
-
enum: ['list', 'info', 'list_dir', 'read', 'write', 'replace', 'stat', 'mkdir', 'rename', 'delete', 'sync'],
|
|
3931
|
-
description: 'Operation to perform. sync only applies to a linked workspace with mirroring on.',
|
|
4190
|
+
enum: ['list', 'info', 'list_dir', 'read', 'write', 'replace', 'stat', 'mkdir', 'rename', 'delete', 'sync', 'exec'],
|
|
4191
|
+
description: 'Operation to perform. sync only applies to a linked workspace with mirroring on. exec needs the remote-execution switch and allow-lists.',
|
|
3932
4192
|
},
|
|
3933
4193
|
workspace: {
|
|
3934
4194
|
type: 'string',
|
|
@@ -3945,6 +4205,9 @@ export function apply(ctx) {
|
|
|
3945
4205
|
replace_all: { type: 'boolean', description: 'Replace every occurrence (default: exactly one occurrence).' },
|
|
3946
4206
|
if_modified_since: { type: 'number', description: 'Epoch milliseconds from a previous read/stat; refuse the write when the remote mtime differs.' },
|
|
3947
4207
|
max_bytes: { type: 'number', description: 'Read cap in bytes for read/list_dir metadata (default 262144, max 524288).' },
|
|
4208
|
+
command: { type: 'string', description: 'Command line for exec (≤ 8000 characters). Runs non-interactively on the remote host.' },
|
|
4209
|
+
cwd: { type: 'string', description: 'Working directory for exec: relative to the workspace root (or an absolute path inside it).' },
|
|
4210
|
+
timeout_ms: { type: 'number', description: 'exec timeout in milliseconds (default from settings, max 600000).' },
|
|
3948
4211
|
},
|
|
3949
4212
|
required: ['action'],
|
|
3950
4213
|
},
|
|
@@ -4143,6 +4406,36 @@ export function apply(ctx) {
|
|
|
4143
4406
|
)
|
|
4144
4407
|
}
|
|
4145
4408
|
|
|
4409
|
+
if (action === 'exec') {
|
|
4410
|
+
const command = String((args && args.command) || '')
|
|
4411
|
+
if (command.trim() === '') throw new ApiError('BAD_REQUEST', 'command is required for exec')
|
|
4412
|
+
const request = { command, cwd: args.cwd, timeoutMs: args.timeout_ms }
|
|
4413
|
+
let result
|
|
4414
|
+
try {
|
|
4415
|
+
result = await methods['hosts.exec'](
|
|
4416
|
+
remoteKind ? { remoteId: link.id, ...request } : { linkedId: link.id, ...request },
|
|
4417
|
+
)
|
|
4418
|
+
} catch (error) {
|
|
4419
|
+
const apiError = asApiError(error)
|
|
4420
|
+
const gated = apiError.code === 'EXEC_DISABLED'
|
|
4421
|
+
|| apiError.code === 'EXEC_HOST_NOT_ALLOWED'
|
|
4422
|
+
|| apiError.code === 'EXEC_WORKSPACE_NOT_ALLOWED'
|
|
4423
|
+
const hint = gated
|
|
4424
|
+
? ' Remote command execution is opt-in: the switch and both allow-lists live in Settings → Linked workspaces → Remote command execution.'
|
|
4425
|
+
: ''
|
|
4426
|
+
return { text: `${LINKED_TOOL_NAME} failed: ${apiError.message}${hint}`, isError: true }
|
|
4427
|
+
}
|
|
4428
|
+
const cap = 20000
|
|
4429
|
+
const cut = (text) => (text.length > cap
|
|
4430
|
+
? `${text.slice(0, cap)}\n… ${text.length - cap} more characters (narrow the command with tail/grep)`
|
|
4431
|
+
: text)
|
|
4432
|
+
const lines = [`exit ${result.exitCode} after ${result.durationMs} ms · ${result.cwd || '(remote home)'}`]
|
|
4433
|
+
if (result.stdout.replace(/\s+$/, '') !== '') lines.push(`stdout:\n${cut(result.stdout.replace(/\s+$/, ''))}`)
|
|
4434
|
+
if (result.stderr.replace(/\s+$/, '') !== '') lines.push(`stderr:\n${cut(result.stderr.replace(/\s+$/, ''))}`)
|
|
4435
|
+
if (result.stdout.trim() === '' && result.stderr.trim() === '') lines.push('(no output)')
|
|
4436
|
+
return toolText(lines.join('\n'))
|
|
4437
|
+
}
|
|
4438
|
+
|
|
4146
4439
|
throw new ApiError('BAD_REQUEST', `unknown action: ${action}`)
|
|
4147
4440
|
} catch (error) {
|
|
4148
4441
|
const apiError = asApiError(error)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-linked-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
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",
|