dsh-remote 0.8.14 → 0.8.15

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.zh.md CHANGED
@@ -1,191 +1,196 @@
1
- [English](./README.md) · **中文**
2
-
3
- ---
4
-
5
- # dsh-remote
6
-
7
- [![npm version](https://img.shields.io/npm/v/dsh-remote)](https://www.npmjs.com/package/dsh-remote)
8
- [![license](https://img.shields.io/github/license/flymysql/dsh-remote)](LICENSE)
9
- [![dsh-plugin](https://img.shields.io/badge/topic-dsh--plugin-7a)](https://github.com/topics/dsh-plugin)
10
-
11
- **为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)打造的远程工作助手。**
12
-
13
- 维护多台 SSH 机器,然后在「选择工作区」时选一个**远程工作区**(或**本地工作区**),Agent 就能在不离开 harness 的情况下直接操作——列文件、读代码、在远程主机上跑构建/命令,并把远程目录镜像成一个真实的本地工作区对象。
14
-
15
- DSH 的 Web 界面刻意只监听 `127.0.0.1`(CLI 为安全拒绝 `--host 0.0.0.0`)。本插件反过来:**由你主动连出**到你维护的机器,选一个工作区,然后通过 DSH 原生的工作区 + 文件流来工作——**不改动 `dsh-workspace` 核心**。
16
-
17
- ## 界面预览
18
-
19
- 设置 → **远程工作区** —— 多机 SSH 列表(增/删/改/设为当前,密码本地保存、不回显):
20
-
21
- <img src="https://cdn.jsdelivr.net/gh/flymysql/dsh-remote@main/docs/ui-settings-panel.png" alt="dsh-remote 设置页 — 多机列表(浅色主题,主机已打码)" width="720"/>
22
-
23
- 原生 **「Add workspace / 选择工作区」** 流程 —— **居中弹窗**、两个 tab,**默认落在「本机」**;切到 **「远程」**:
24
-
25
- - **远程** —— 一个**机器下拉**;路径输入框**自动预填 `/` 并实时补全目录**(点选一个目录后**立即列出它的下一级**,像系统/VSCode 逐级选目录);另外有**「浏览…」浮窗**,选中仅回填到输入框(不直接提交),你复核 / 修改后点「设为远程工作区」。
26
-
27
- 真实截图(机器已打码为占位):
28
-
29
- <img src="https://cdn.jsdelivr.net/gh/flymysql/dsh-remote@main/docs/ui-picker-panel.png" alt="dsh-remote 工作区选择 — 真实弹窗;默认本机 tab;远程:机器下拉 + 预填根路径 + 自动补全" width="720"/>
30
-
31
- ---
32
-
33
- ## 功能
34
-
35
- - **多机 SSH** —— 可存任意多台主机(host/port/user + **私钥**或**密码**)。密码只存在本地,界面不回显;在设置里一键切当前机。
36
- - **双 tab 工作区选择器**(填充原生「Add workspace」流程):
37
- - **本机** —— 走 **host 端原生系统文件夹对话框**选本地目录(或直接输入本地路径)→ 直接成为普通 DSH 本地工作区(与本地工作区共存)。优先用 DSH 的 `directoryPicker` 服务,服务缺失时**回退到插件自持的原生选择器**(macOS `osascript` / Linux `zenity`→`kdialog`)——桌面启动路径上框架服务不注册也能用。
38
- - **远程** —— 选择器是**居中弹窗**(窄侧边栏也不会被挤压)。先**选机器** → Windows 主机根级显示 **「此电脑」多盘视图**(`C:\`、`D:\`、`E:\`…,而不是 Git Bash 的 MSYS 根),路径框**实时补全**目录(支持 `C:\Users\…` 或 `/c/Users/…` 任意写法,Windows 路径在底层自动改写为 Git Bash 形式);**选中一个目录立即列出它下一级**(OS/VSCode 式级联)。另有 **「浏览…」文件选择式浮层**(Windows 面包屑 `此电脑 / C:\ / Users / dev` 可点击跳级、驱动器行、大小/时间、跟随软链),选中**回填输入框不提交**,你复核/修改后再确定;「回上一级」任意深度可用(包括浮层直接打开在路径栏当前路径时)。**最近工作区**快捷入口、**`~` 主目录**、**新建目录**一键可达。确定会创建**真实本地镜像**(`$DSH_HOME/remote-workspaces/<host>-<user>-<port>/<basename>`;仅当同主机上**别的远端路径**已占用同名 basename 时才追加短路径 hash)→ harness 把它当真实工作区收养,同时 dsh-remote 通过 SFTP 保持同步。所选工作区会**持久化到该机器**,重启不丢。
39
- - **Git Bash 默认终端(Windows 主机)** —— 自动探测远程平台(`cmd /c ver`,附 `uname -s` 的 MINGW/MSYS 探测兜底);Windows 机器自动定位 Git Bash(`config.shell` 可显式指定或 `native` 关闭),所有命令经 `bash -s` 从 SSH 通道 stdin 管道执行,不依赖 cmd/PowerShell,也不受引号/反斜杠转义困扰;`rw_exec` 默认在 Git Bash 形式的 cwd(`/c/Users/…`)下执行。`/dsh-remote/status`、`rw_info`、设置页「测试连接」都会报告检测到的平台与 shell。
40
- - **Windows 路径自动改写** —— 用户输入 `C:\Users\dev\project`(或 `C:/…`、`/c/…`、`/C:/…`)时底层自动规范为 Git Bash 形式 `/c/Users/dev/project` 执行;工作区存储与展示为 Windows 形式 `C:\Users\dev\project`。模型工具全部接受并展示两种写法;SFTP 访问使用 Win32-OpenSSH 的 `/D:/…` 形式(见 `toSftpPath`)。
41
- - **双向 SFTP 同步(增量)** —— `rw_sync`(远程→镜像)、`rw_push`(镜像→远程),本地镜像改动可回传机器。两者都会**跳过 size+mtime 未变化的文件**,并有**单文件大小上限**防误拉大二进制;目录遍历带**有界并发**。
42
- - **模型工具** —— `rw_info`、`rw_connect`、`rw_pick_workspace`、`rw_list_dir`、`rw_read_file`、`rw_write_file`、`rw_exec`(默认在工作区目录执行,可传 `cwd=`)、`rw_search`(可移植递归 grep)、`rw_download`、`rw_upload`、`rw_sync`、`rw_push`、`rw_disconnect`。
43
- - **直接写远程文件** —— `rw_write_file` 直接创建/覆盖远程文件(自动建父目录),单个文件改动不必绕本地镜像来回同步;`rw_download` / `rw_upload` 可单文件双向取真字节。
44
- - **连接体检** —— 设置页提供「测试连接」按钮,在保存机器之前先验证 host/user/密码/私钥是否可用。
45
- - 当前 `user@host:/path` 会注入每次系统提示,让 Agent 明确自己的工作根。
46
- - **远端跨平台** —— 命令全部用可移植 POSIX 写法(`ls -la` / `sed -n` / `find … -exec grep`),macOS/BSD 与 GNU/Linux 远端都能用。
47
- - **主机指纹校验(TOFU)** —— 每次 SSH 连接都校验主机密钥(`hostKeyMode: accept-new`):首次连接记录,之后**密钥一旦变化立即拒绝**(防中间人)。`verify` 模式还会拒绝从未见过的机器;`off` 关闭校验。指纹存于 `$DSH_HOME/remote-workspaces/known_hosts.json`;误判可用 `/remote forget-key` 重置。
48
- - **数据跟随 Harness 根目录** —— 机器清单与镜像放在 `$DSH_HOME/remote-workspaces`(桌面版即 `userData/harness` 下);0.6 之前落在 `~/.dsh/remote-workspaces` 的数据**首次启动自动迁移**,不丢失。
49
- - **不改任何 `dsh-workspace` 官方代码** —— 全部作为普通插件实现(client 半以 `priority -100` 填充 directory-flow holes)。
50
-
51
- ## 安装
52
-
53
- ```bash
54
- dsh plugin add dsh-remote # 添加 bundle
55
- ```
56
-
57
- 一条命令装齐:从 **v0.7.2** 起,侧边栏
58
- ([dsh-better-sidebar](https://www.npmjs.com/package/dsh-better-sidebar))是
59
- **硬依赖并自动挂载** —— 装完 dsh-remote 后,侧边栏里的「🌐 远程文件」目录树和
60
- 远程文件查看器即可直接用,无需额外步骤。如果你已单独安装过该侧边栏,内嵌副本
61
- 会自动退避(不会重复挂载)。
62
-
63
- > **要求 profile 的 pnpm linker 为 `hoisted`**(DSH profile 默认,
64
- > `pnpm-workspace.yaml` 里 `nodeLinker: hoisted`)。loader 从 profile 根解析
65
- > 插件包,侧边栏必须能在顶层 `node_modules` 被解析到。如果你的
66
- > `pnpm-workspace.yaml` 被重写丢掉了 `nodeLinker: hoisted`,请补回并执行一次
67
- > `pnpm install` —— 否则内嵌侧边栏行会报
68
- > `Cannot find package 'dsh-better-sidebar'`。
69
-
70
- (或 `npm install dsh-remote`,再在 `cordis.patch.yml` 加 `- id: dsh-remote / name: dsh-remote`。)
71
-
72
- ## 快速上手
73
-
74
- 1. **加一台机器** —— 设置 → 远程工作区 → 填 host/port/user + 密码或 key →(可选)设为当前。
75
- > **保存 ≠ 激活(v0.8.8+)**:保存的机器只是备用连接,不会自动进入任何 session 的
76
- > remote context。只有「设为当前」(或 Agent 显式调用 `rw_connect`)才激活当前机器;
77
- > 「取消设为当前」可回到 `active remote = none`。
78
- 2. **选工作区** —— 点侧边栏/会话的 **Add workspace**:
79
- - **本机** → 系统文件夹选择(或输入本地路径)→ 本地工作区。
80
- - **远程** → 选机器 → 浏览到远程目录(或输入 `/path`)→ 「设为远程工作区」⇒ 创建并收养一个本地镜像工作区。
81
- 3. **让 Agent 工作** —— 把它当普通工作区用:
82
- - `rw_list_dir(path?)` / `rw_read_file` —— 查看远程文件
83
- - `rw_write_file(path, content)` —— 直接创建或覆盖远程文件
84
- - `rw_search(pattern, path?)` —— 远程 grep
85
- - `rw_exec(command, cwd?)` —— 在远程执行命令(默认在工作区目录)
86
- - `rw_sync` / `rw_push` —— 拉取/推送本地镜像 <-> 远程
87
-
88
- > **Remote context 是 session 级的(v0.8.8+)**:system prompt 只会在**当前 session 的
89
- > cwd 位于某个远程 mirror 内**(即你把远程目录选成了这个 session 的工作区)时注入
90
- > 「Remote workspace」段落;普通本地 session 不注入、侧边栏「远程文件」也不显示任何
91
- > 机器默认目录,模型不会主动调用 `rw_*`。混合访问(本地 + 远程同屏比较)请通过显式
92
- > 选择远程工作区进行。
93
-
94
- ## 可选:CLI 默认机
95
-
96
- 可在 `cordis.patch.yml` 提供默认机:
97
-
98
- ```yaml
99
- # 示例:请换成你自己的机器
100
- - id: dsh-remote
101
- name: dsh-remote
102
- config:
103
- host: 203.0.113.10 # 或你的真实主机 / hostname
104
- port: 22
105
- username: dev
106
- privateKeyPath: ~/.ssh/id_rsa
107
- # 或用密码登录:
108
- # password: '…'
109
- workspace: ~/project
110
- ```
111
-
112
- 若 `host` 为空,插件启动时处于断开状态,在 UI 里配置机器即可。
113
-
114
- ## 常用命令(安装 / 查看 / 启动)
115
-
116
- DSH 的 `dsh` 可能不在某些 shell 的 PATH(比如 Windows PowerShell 里在某个仓库目录下),所以同时列出 `dsh` 与 `npx` 两种写法。操作都要用 `--profile <name>` 指定 profile(一般 `web`):
117
-
118
- ```bash
119
- # 安装(从 npm 拉到 profile)
120
- dsh plugin --profile web add dsh-remote
121
- # 同一效果:当 `dsh` 不在 PATH 时用 npx
122
- npx --yes @deepseek-ai/dsh plugin --profile web add dsh-remote
123
-
124
- # 确认已装
125
- dsh plugin --profile web list
126
- npx --yes @deepseek-ai/dsh plugin --profile web list
127
-
128
- # 启动 web 界面(重载 profile,新插件在启动时生效)
129
- dsh --profile web
130
- npx --yes @deepseek-ai/dsh --profile web # 访问 http://127.0.0.1:3080
131
-
132
- # 迭代用本地源码替换 npm 版(便于改 dsh 插件代码后即测)
133
- npx --yes @deepseek-ai/dsh plugin --profile web add D:/path/to/dsh-remote
134
- npx --yes @deepseek-ai/dsh plugin --profile web remove dsh-remote # 恢复用发行版
135
- ```
136
-
137
- 启动成功后,设置 →「远程工作区」会出现;「Add workspace」流程会带「本机 / 远程」两个 tab(见上方效果图)。
138
-
139
- ## 开发(沙箱优先,勿改产品)
140
-
141
- 迭代**一律在沙箱**里做,绝不手工改产品 profile——产品 profile 由插件管理器重管,
142
- 重装会把手工部署的文件还原掉。用仓库内的辅助脚本:
143
-
144
- ```bash
145
- scripts/dev-run.sh --restart # 启动 / 重启隔离沙箱
146
- scripts/dev-run.sh --stop # 停止
147
- scripts/dev-run.sh --status # 是否在运行
148
- ```
149
-
150
- - 自带一套独立 DSH 实例(仓库内 `dev-harness/harness`),把 `lib/` 复制进沙箱
151
- profile——与桌面 App 走同一条 `bin.js web --patch` 启动路径,沙箱即产品启动行为。
152
- - 沙箱 web UI 在 `http://127.0.0.1:50599`,插件路由立即可见(如
153
- `GET /dsh-remote/machines`)。
154
- - **宿主半改动**(`lib/index.js`)需重启沙箱(`--restart`);**客户端半改动**
155
- (`lib/client.js`)只需刷新页面。
156
- - Node ESM 按导入文件的真实路径解析依赖,脚本用**硬链接拷贝**(`cp -al`)把
157
- `lib/` 复制进沙箱 profile,而不是软链——软链会破坏 `@deepseek-ai/*` 的解析。
158
- - 每次提交前跑 `scripts/check.mjs`(静态框架约束闸门:命令名正则等);
159
- `scripts/boot-smoke.sh` 用隔离实例证明插件仍能启动。
160
- - 完整规则见 `scripts/dev-standards.md`(命令名、cordis 服务只许 `ctx.get()`、
161
- 可选框架服务可能压根不注册、三方库回调契约以真实运行为准等)。
162
-
163
- 部署到产品 profile 是单独的受控动作(`./sync.sh`),只在确定要发布时做。
164
-
165
- ## 配置
166
-
167
- | 键 | 类型 | 默认 | 说明 |
168
- | --- | --- | --- | --- |
169
- | `host` | string | `''` | 默认 SSH 主机(空=断开) |
170
- | `port` | int | `22` | 默认 SSH 端口 |
171
- | `username` | string | `''` | 默认 SSH 用户 |
172
- | `password` | string | `''` | 默认 SSH 密码(非空覆盖 key) |
173
- | `privateKeyPath` | string | `''` | 私钥路径(仅在显式提供时使用) |
174
- | `workspace` | string | `''` | 默认远程工作区路径 |
175
- | `shell` | string | `''` | 远程命令终端策略:`''`=自动检测(Windows 找 Git Bash)、`'git-bash'`=优先 Git Bash、`'native'`=不包装、其他=显式 bash.exe 路径(如 `C:\Program Files\Git\bin\bash.exe`) |
176
- | `commandTimeoutMs` | int | 20000 | 单条远程命令超时 |
177
- | `connectTimeoutMs` | int | 15000 | SSH 连接超时 |
178
- | `maxFileBytes` | int | 52428800 | 镜像同步时跳过超过该大小的文件(0=不设上限) |
179
- | `hostKeyMode` | string | `accept-new` | 主机指纹策略:`accept-new`(首次信任)、`verify`(拒绝未知主机)、`off`(跳过校验) |
180
-
181
- ## 安全提醒
182
-
183
- 把机器凭据交给插件,等于允许 Agent 以你的用户身份在主机上执行 **shell 命令**。只添加你可信的机器。密码保存在本机文件里,请当作敏感数据处理(可收紧文件 ACL)。
184
-
185
- ## License
186
-
187
- MIT
188
-
189
- ## 变更记录
190
-
1
+ [English](./README.md) · **中文**
2
+
3
+ ---
4
+
5
+ # dsh-remote
6
+
7
+ [![npm version](https://img.shields.io/npm/v/dsh-remote)](https://www.npmjs.com/package/dsh-remote)
8
+ [![license](https://img.shields.io/github/license/flymysql/dsh-remote)](LICENSE)
9
+ [![dsh-plugin](https://img.shields.io/badge/topic-dsh--plugin-7a)](https://github.com/topics/dsh-plugin)
10
+
11
+ **为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)打造的远程工作助手。**
12
+
13
+ 维护多台 SSH 机器,然后在「选择工作区」时选一个**远程工作区**(或**本地工作区**),Agent 就能在不离开 harness 的情况下直接操作——列文件、读代码、在远程主机上跑构建/命令,并把远程目录镜像成一个真实的本地工作区对象。
14
+
15
+ DSH 的 Web 界面刻意只监听 `127.0.0.1`(CLI 为安全拒绝 `--host 0.0.0.0`)。本插件反过来:**由你主动连出**到你维护的机器,选一个工作区,然后通过 DSH 原生的工作区 + 文件流来工作——**不改动 `dsh-workspace` 核心**。
16
+
17
+ ## 界面预览
18
+
19
+ 设置 → **远程工作区** —— 多机 SSH 列表(增/删/改/设为当前,密码本地保存、不回显):
20
+
21
+ <img src="https://cdn.jsdelivr.net/gh/flymysql/dsh-remote@main/docs/ui-settings-panel.png" alt="dsh-remote 设置页 — 多机列表(浅色主题,主机已打码)" width="720"/>
22
+
23
+ 原生 **「Add workspace / 选择工作区」** 流程 —— **居中弹窗**、两个 tab,**默认落在「本机」**;切到 **「远程」**:
24
+
25
+ - **远程** —— 一个**机器下拉**;路径输入框**自动预填 `/` 并实时补全目录**(点选一个目录后**立即列出它的下一级**,像系统/VSCode 逐级选目录);另外有**「浏览…」浮窗**,选中仅回填到输入框(不直接提交),你复核 / 修改后点「设为远程工作区」。
26
+
27
+ 真实截图(机器已打码为占位):
28
+
29
+ <img src="https://cdn.jsdelivr.net/gh/flymysql/dsh-remote@main/docs/ui-picker-panel.png" alt="dsh-remote 工作区选择 — 真实弹窗;默认本机 tab;远程:机器下拉 + 预填根路径 + 自动补全" width="720"/>
30
+
31
+ ---
32
+
33
+ ## 功能
34
+
35
+ - **多机 SSH** —— 可存任意多台主机(host/port/user + **私钥**或**密码**)。密码只存在本地,界面不回显;在设置里一键切当前机。
36
+ - **双 tab 工作区选择器**(填充原生「Add workspace」流程):
37
+ - **本机** —— 走 **host 端原生系统文件夹对话框**选本地目录(或直接输入本地路径)→ 直接成为普通 DSH 本地工作区(与本地工作区共存)。优先用 DSH 的 `directoryPicker` 服务,服务缺失时**回退到插件自持的原生选择器**(macOS `osascript` / Linux `zenity`→`kdialog`)——桌面启动路径上框架服务不注册也能用。
38
+ - **远程** —— 选择器是**居中弹窗**(窄侧边栏也不会被挤压)。先**选机器** → Windows 主机根级显示 **「此电脑」多盘视图**(`C:\`、`D:\`、`E:\`…,而不是 Git Bash 的 MSYS 根),路径框**实时补全**目录(支持 `C:\Users\…` 或 `/c/Users/…` 任意写法,Windows 路径在底层自动改写为 Git Bash 形式);**选中一个目录立即列出它下一级**(OS/VSCode 式级联)。另有 **「浏览…」文件选择式浮层**(Windows 面包屑 `此电脑 / C:\ / Users / dev` 可点击跳级、驱动器行、大小/时间、跟随软链),选中**回填输入框不提交**,你复核/修改后再确定;「回上一级」任意深度可用(包括浮层直接打开在路径栏当前路径时)。**最近工作区**快捷入口、**`~` 主目录**、**新建目录**一键可达。确定会创建**真实本地镜像**(`$DSH_HOME/remote-workspaces/<host>-<user>-<port>/<basename>`;仅当同主机上**别的远端路径**已占用同名 basename 时才追加短路径 hash)→ harness 把它当真实工作区收养,同时 dsh-remote 通过 SFTP 保持同步。所选工作区会**持久化到该机器**,重启不丢。
39
+ - **Git Bash 默认终端(Windows 主机)** —— 自动探测远程平台(`cmd /c ver`,附 `uname -s` 的 MINGW/MSYS 探测兜底);Windows 机器自动定位 Git Bash(`config.shell` 可显式指定或 `native` 关闭),所有命令经 `bash -s` 从 SSH 通道 stdin 管道执行,不依赖 cmd/PowerShell,也不受引号/反斜杠转义困扰;`rw_exec` 默认在 Git Bash 形式的 cwd(`/c/Users/…`)下执行。`/dsh-remote/status`、`rw_info`、设置页「测试连接」都会报告检测到的平台与 shell。
40
+ - **Windows 路径自动改写** —— 用户输入 `C:\Users\dev\project`(或 `C:/…`、`/c/…`、`/C:/…`)时底层自动规范为 Git Bash 形式 `/c/Users/dev/project` 执行;工作区存储与展示为 Windows 形式 `C:\Users\dev\project`。模型工具全部接受并展示两种写法;SFTP 访问使用 Win32-OpenSSH 的 `/D:/…` 形式(见 `toSftpPath`)。
41
+ - **双向 SFTP 同步(增量)** —— `rw_sync`(远程→镜像)、`rw_push`(镜像→远程),本地镜像改动可回传机器。两者都会**跳过 size+mtime 未变化的文件**,并有**单文件大小上限**防误拉大二进制;目录遍历带**有界并发**。
42
+ - **模型工具** —— `rw_info`、`rw_connect`、`rw_pick_workspace`、`rw_list_dir`、`rw_read_file`、`rw_write_file`、`rw_exec`(默认在工作区目录执行,可传 `cwd=`)、`rw_search`(可移植递归 grep)、`rw_download`、`rw_upload`、`rw_sync`、`rw_push`、`rw_disconnect`。
43
+ - **直接写远程文件** —— `rw_write_file` 直接创建/覆盖远程文件(自动建父目录),单个文件改动不必绕本地镜像来回同步;`rw_download` / `rw_upload` 可单文件双向取真字节。
44
+ - **连接体检** —— 设置页提供「测试连接」按钮,在保存机器之前先验证 host/user/密码/私钥是否可用。
45
+ - 当前 `user@host:/path` 会注入每次系统提示,让 Agent 明确自己的工作根。
46
+ - **远端跨平台** —— 命令全部用可移植 POSIX 写法(`ls -la` / `sed -n` / `find … -exec grep`),macOS/BSD 与 GNU/Linux 远端都能用。
47
+ - **主机指纹校验(TOFU)** —— 每次 SSH 连接都校验主机密钥(`hostKeyMode: accept-new`):首次连接记录,之后**密钥一旦变化立即拒绝**(防中间人)。`verify` 模式还会拒绝从未见过的机器;`off` 关闭校验。指纹存于 `$DSH_HOME/remote-workspaces/known_hosts.json`;误判可用 `/remote forget-key` 重置。
48
+ - **数据跟随 Harness 根目录** —— 机器清单与镜像放在 `$DSH_HOME/remote-workspaces`(桌面版即 `userData/harness` 下);0.6 之前落在 `~/.dsh/remote-workspaces` 的数据**首次启动自动迁移**,不丢失。
49
+ - **不改任何 `dsh-workspace` 官方代码** —— 全部作为普通插件实现(client 半以 `priority -100` 填充 directory-flow holes)。
50
+
51
+ ## 安装
52
+
53
+ ```bash
54
+ dsh plugin add dsh-remote # 添加 bundle
55
+ ```
56
+
57
+ 一条命令装齐:从 **v0.7.2** 起,侧边栏
58
+ ([dsh-better-sidebar](https://www.npmjs.com/package/dsh-better-sidebar))是
59
+ **硬依赖并自动挂载** —— 装完 dsh-remote 后,侧边栏里的「🌐 远程文件」目录树和
60
+ 远程文件查看器即可直接用,无需额外步骤。如果你已单独安装过该侧边栏,内嵌副本
61
+ 会自动退避(不会重复挂载)。
62
+
63
+ > **内嵌侧边栏版本**:0.8.15 起依赖范围为 `^0.18.1`。0.8.14 及更早锁在 `^0.14.0`,
64
+ > 而 0.14.0~0.17.1 仍然 `import { settingsNamespace } from "@deepseek-ai/dsh-settings"`,
65
+ > 该导出自 dsh-settings 0.1.2-alpha.2 起被移除,静态导入失败会让整个插件树加载失败
66
+ > (issue #29)。
67
+
68
+ > **要求 profile 的 pnpm linker 为 `hoisted`**(DSH profile 默认,
69
+ > `pnpm-workspace.yaml` 里 `nodeLinker: hoisted`)。loader 从 profile 根解析
70
+ > 插件包,侧边栏必须能在顶层 `node_modules` 被解析到。如果你的
71
+ > `pnpm-workspace.yaml` 被重写丢掉了 `nodeLinker: hoisted`,请补回并执行一次
72
+ > `pnpm install` —— 否则内嵌侧边栏行会报
73
+ > `Cannot find package 'dsh-better-sidebar'`。
74
+
75
+ (或 `npm install dsh-remote`,再在 `cordis.patch.yml` 加 `- id: dsh-remote / name: dsh-remote`。)
76
+
77
+ ## 快速上手
78
+
79
+ 1. **加一台机器** —— 设置 → 远程工作区 → 填 host/port/user + 密码或 key →(可选)设为当前。
80
+ > **保存 ≠ 激活(v0.8.8+)**:保存的机器只是备用连接,不会自动进入任何 session 的
81
+ > remote context。只有「设为当前」(或 Agent 显式调用 `rw_connect`)才激活当前机器;
82
+ > 「取消设为当前」可回到 `active remote = none`。
83
+ 2. **选工作区** —— 点侧边栏/会话的 **Add workspace**:
84
+ - **本机** → 系统文件夹选择(或输入本地路径)→ 本地工作区。
85
+ - **远程** → 选机器 → 浏览到远程目录(或输入 `/path`)→ 「设为远程工作区」⇒ 创建并收养一个本地镜像工作区。
86
+ 3. **让 Agent 工作** —— 把它当普通工作区用:
87
+ - `rw_list_dir(path?)` / `rw_read_file` —— 查看远程文件
88
+ - `rw_write_file(path, content)` —— 直接创建或覆盖远程文件
89
+ - `rw_search(pattern, path?)` —— 远程 grep
90
+ - `rw_exec(command, cwd?)` —— 在远程执行命令(默认在工作区目录)
91
+ - `rw_sync` / `rw_push` —— 拉取/推送本地镜像 <-> 远程
92
+
93
+ > **Remote context 是 session 级的(v0.8.8+)**:system prompt 只会在**当前 session 的
94
+ > cwd 位于某个远程 mirror 内**(即你把远程目录选成了这个 session 的工作区)时注入
95
+ > 「Remote workspace」段落;普通本地 session 不注入、侧边栏「远程文件」也不显示任何
96
+ > 机器默认目录,模型不会主动调用 `rw_*`。混合访问(本地 + 远程同屏比较)请通过显式
97
+ > 选择远程工作区进行。
98
+
99
+ ## 可选:CLI 默认机
100
+
101
+ 可在 `cordis.patch.yml` 提供默认机:
102
+
103
+ ```yaml
104
+ # 示例:请换成你自己的机器
105
+ - id: dsh-remote
106
+ name: dsh-remote
107
+ config:
108
+ host: 203.0.113.10 # 或你的真实主机 / hostname
109
+ port: 22
110
+ username: dev
111
+ privateKeyPath: ~/.ssh/id_rsa
112
+ # 或用密码登录:
113
+ # password: '…'
114
+ workspace: ~/project
115
+ ```
116
+
117
+ 若 `host` 为空,插件启动时处于断开状态,在 UI 里配置机器即可。
118
+
119
+ ## 常用命令(安装 / 查看 / 启动)
120
+
121
+ DSH 的 `dsh` 可能不在某些 shell 的 PATH(比如 Windows PowerShell 里在某个仓库目录下),所以同时列出 `dsh` 与 `npx` 两种写法。操作都要用 `--profile <name>` 指定 profile(一般 `web`):
122
+
123
+ ```bash
124
+ # 安装(从 npm 拉到 profile)
125
+ dsh plugin --profile web add dsh-remote
126
+ # 同一效果:当 `dsh` 不在 PATH 时用 npx
127
+ npx --yes @deepseek-ai/dsh plugin --profile web add dsh-remote
128
+
129
+ # 确认已装
130
+ dsh plugin --profile web list
131
+ npx --yes @deepseek-ai/dsh plugin --profile web list
132
+
133
+ # 启动 web 界面(重载 profile,新插件在启动时生效)
134
+ dsh --profile web
135
+ npx --yes @deepseek-ai/dsh --profile web # 访问 http://127.0.0.1:3080
136
+
137
+ # 迭代用本地源码替换 npm 版(便于改 dsh 插件代码后即测)
138
+ npx --yes @deepseek-ai/dsh plugin --profile web add D:/path/to/dsh-remote
139
+ npx --yes @deepseek-ai/dsh plugin --profile web remove dsh-remote # 恢复用发行版
140
+ ```
141
+
142
+ 启动成功后,设置 →「远程工作区」会出现;「Add workspace」流程会带「本机 / 远程」两个 tab(见上方效果图)。
143
+
144
+ ## 开发(沙箱优先,勿改产品)
145
+
146
+ 迭代**一律在沙箱**里做,绝不手工改产品 profile——产品 profile 由插件管理器重管,
147
+ 重装会把手工部署的文件还原掉。用仓库内的辅助脚本:
148
+
149
+ ```bash
150
+ scripts/dev-run.sh --restart # 启动 / 重启隔离沙箱
151
+ scripts/dev-run.sh --stop # 停止
152
+ scripts/dev-run.sh --status # 是否在运行
153
+ ```
154
+
155
+ - 自带一套独立 DSH 实例(仓库内 `dev-harness/harness`),把 `lib/` 复制进沙箱
156
+ profile——与桌面 App 走同一条 `bin.js web --patch` 启动路径,沙箱即产品启动行为。
157
+ - 沙箱 web UI 在 `http://127.0.0.1:50599`,插件路由立即可见(如
158
+ `GET /dsh-remote/machines`)。
159
+ - **宿主半改动**(`lib/index.js`)需重启沙箱(`--restart`);**客户端半改动**
160
+ (`lib/client.js`)只需刷新页面。
161
+ - Node ESM 按导入文件的真实路径解析依赖,脚本用**硬链接拷贝**(`cp -al`)把
162
+ `lib/` 复制进沙箱 profile,而不是软链——软链会破坏 `@deepseek-ai/*` 的解析。
163
+ - 每次提交前跑 `scripts/check.mjs`(静态框架约束闸门:命令名正则等);
164
+ `scripts/boot-smoke.sh` 用隔离实例证明插件仍能启动。
165
+ - 完整规则见 `scripts/dev-standards.md`(命令名、cordis 服务只许 `ctx.get()`、
166
+ 可选框架服务可能压根不注册、三方库回调契约以真实运行为准等)。
167
+
168
+ 部署到产品 profile 是单独的受控动作(`./sync.sh`),只在确定要发布时做。
169
+
170
+ ## 配置
171
+
172
+ | 键 | 类型 | 默认 | 说明 |
173
+ | --- | --- | --- | --- |
174
+ | `host` | string | `''` | 默认 SSH 主机(空=断开) |
175
+ | `port` | int | `22` | 默认 SSH 端口 |
176
+ | `username` | string | `''` | 默认 SSH 用户 |
177
+ | `password` | string | `''` | 默认 SSH 密码(非空覆盖 key) |
178
+ | `privateKeyPath` | string | `''` | 私钥路径(仅在显式提供时使用) |
179
+ | `workspace` | string | `''` | 默认远程工作区路径 |
180
+ | `shell` | string | `''` | 远程命令终端策略:`''`=自动检测(Windows 找 Git Bash)、`'git-bash'`=优先 Git Bash、`'native'`=不包装、其他=显式 bash.exe 路径(如 `C:\Program Files\Git\bin\bash.exe`) |
181
+ | `commandTimeoutMs` | int | 20000 | 单条远程命令超时 |
182
+ | `connectTimeoutMs` | int | 15000 | SSH 连接超时 |
183
+ | `maxFileBytes` | int | 52428800 | 镜像同步时跳过超过该大小的文件(0=不设上限) |
184
+ | `hostKeyMode` | string | `accept-new` | 主机指纹策略:`accept-new`(首次信任)、`verify`(拒绝未知主机)、`off`(跳过校验) |
185
+
186
+ ## 安全提醒
187
+
188
+ 把机器凭据交给插件,等于允许 Agent 以你的用户身份在主机上执行 **shell 命令**。只添加你可信的机器。密码保存在本机文件里,请当作敏感数据处理(可收紧文件 ACL)。
189
+
190
+ ## License
191
+
192
+ MIT
193
+
194
+ ## 变更记录
195
+
191
196
  见 [CHANGELOG.md](./CHANGELOG.md)。
package/lib/binding.js CHANGED
@@ -1,97 +1,97 @@
1
- // Session → remote-binding resolution.
2
- //
3
- // A session's remote target is derived from its own workspace mirror, never
4
- // from the plugin's mutable active-machine state. That is what keeps concurrent
5
- // sessions on different hosts independent: with a single shared connection and
6
- // a single shared workspace value, one session switching machines redirected
7
- // every other session's commands to the wrong host (issue #25).
8
- //
9
- // The mirror directory is the durable record of that binding: `ensureMirror()`
10
- // writes `.dsh-remote-meta.json` with the remote origin (`host`/`port`/
11
- // `username`/`remotePath`) when the workspace is picked, so a session's cwd
12
- // alone identifies both the machine to connect to and the workspace root.
13
-
14
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
15
- import path from 'node:path'
16
-
17
- /** Strip trailing separators so a mirror root and a path inside it compare cleanly. */
18
- const norm = (p) => path.resolve(String(p || '')).replace(/[\\/]+$/, '') || ''
19
-
20
- /** Whether `base` is `dir` itself or nested under it (separator-aware, so
21
- * `/a/mirror-2` is NOT treated as living inside `/a/mirror`). */
22
- const isUnder = (base, dir) => base === dir || base.startsWith(dir + path.sep) || base.startsWith(dir + '/')
23
-
24
- /**
25
- * Resolve which remote workspace a LOCAL path belongs to by scanning the mirror
26
- * registry for the mirror that contains it.
27
- *
28
- * Mirrors live exactly one level under the registry root as
29
- * `<host>-<user>-<port>/<basename>`, and `mirrorDirFor()` appends a short hash
30
- * when two remote paths share a basename, so containment is unambiguous. The
31
- * longest containing path still wins, which keeps the result stable if a
32
- * future layout ever nests them.
33
- *
34
- * A mirror whose meta is missing, unparsable, or has no `host` is skipped
35
- * rather than guessed at: reporting no binding makes the caller refuse loudly,
36
- * while guessing would send commands to an unintended host.
37
- *
38
- * @param {string} local - absolute local path, typically a session's cwd.
39
- * @param {string} root - the mirror registry root (`$DSH_HOME/remote-workspaces`).
40
- * @returns {{mirrorDir: string|null, remotePath: string, machine: {host: string, port: number, username: string}|null}}
41
- * `machine` is the mirror-recorded origin, or null when `local` is not inside
42
- * a usable mirror (in which case `remotePath` is empty too).
43
- */
44
- export function resolveMirror(local, root) {
45
- let mirrorDir = null
46
- let remotePath = ''
47
- let machine = null
48
- if (!local || !root || !existsSync(root)) return { mirrorDir, remotePath, machine }
49
- const base = norm(local)
50
- let hostDirs
51
- try {
52
- hostDirs = readdirSync(root)
53
- } catch {
54
- return { mirrorDir, remotePath, machine }
55
- }
56
- for (const hostDir of hostDirs) {
57
- const hostPath = path.join(root, hostDir)
58
- if (!statSync(hostPath, { throwIfNoEntry: false })?.isDirectory?.()) continue
59
- let entries
60
- try {
61
- entries = readdirSync(hostPath)
62
- } catch {
63
- continue
64
- }
65
- for (const entry of entries) {
66
- const metaPath = path.join(hostPath, entry, '.dsh-remote-meta.json')
67
- if (!existsSync(metaPath)) continue
68
- const mirrorAbs = norm(path.join(hostPath, entry))
69
- if (!isUnder(base, mirrorAbs)) continue
70
- // Deepest match wins; an equal-length path cannot occur twice.
71
- if (mirrorDir && mirrorAbs.length <= mirrorDir.length) continue
72
- try {
73
- const meta = JSON.parse(readFileSync(metaPath, 'utf8'))
74
- if (!meta || !meta.host) continue
75
- mirrorDir = mirrorAbs
76
- remotePath = String(meta.remotePath || '')
77
- machine = {
78
- host: String(meta.host),
79
- port: Number(meta.port) || 22,
80
- username: String(meta.username || ''),
81
- }
82
- } catch { /* unparsable meta → not a usable binding */ }
83
- }
84
- }
85
- return { mirrorDir, remotePath, machine }
86
- }
87
-
88
- /**
89
- * Stable pool key for a remote identity. Two sessions on the same machine
90
- * produce the same key and therefore share one SSH connection; sessions on
91
- * different machines never collide.
92
- * @param {{host: string, port?: number|string, username?: string}} m - the remote identity.
93
- * @returns {string} the canonical `user@host:port` key.
94
- */
95
- export function poolKey(m) {
96
- return `${(m && m.username) || ''}@${(m && m.host) || ''}:${Number(m && m.port) || 22}`
97
- }
1
+ // Session → remote-binding resolution.
2
+ //
3
+ // A session's remote target is derived from its own workspace mirror, never
4
+ // from the plugin's mutable active-machine state. That is what keeps concurrent
5
+ // sessions on different hosts independent: with a single shared connection and
6
+ // a single shared workspace value, one session switching machines redirected
7
+ // every other session's commands to the wrong host (issue #25).
8
+ //
9
+ // The mirror directory is the durable record of that binding: `ensureMirror()`
10
+ // writes `.dsh-remote-meta.json` with the remote origin (`host`/`port`/
11
+ // `username`/`remotePath`) when the workspace is picked, so a session's cwd
12
+ // alone identifies both the machine to connect to and the workspace root.
13
+
14
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
15
+ import path from 'node:path'
16
+
17
+ /** Strip trailing separators so a mirror root and a path inside it compare cleanly. */
18
+ const norm = (p) => path.resolve(String(p || '')).replace(/[\\/]+$/, '') || ''
19
+
20
+ /** Whether `base` is `dir` itself or nested under it (separator-aware, so
21
+ * `/a/mirror-2` is NOT treated as living inside `/a/mirror`). */
22
+ const isUnder = (base, dir) => base === dir || base.startsWith(dir + path.sep) || base.startsWith(dir + '/')
23
+
24
+ /**
25
+ * Resolve which remote workspace a LOCAL path belongs to by scanning the mirror
26
+ * registry for the mirror that contains it.
27
+ *
28
+ * Mirrors live exactly one level under the registry root as
29
+ * `<host>-<user>-<port>/<basename>`, and `mirrorDirFor()` appends a short hash
30
+ * when two remote paths share a basename, so containment is unambiguous. The
31
+ * longest containing path still wins, which keeps the result stable if a
32
+ * future layout ever nests them.
33
+ *
34
+ * A mirror whose meta is missing, unparsable, or has no `host` is skipped
35
+ * rather than guessed at: reporting no binding makes the caller refuse loudly,
36
+ * while guessing would send commands to an unintended host.
37
+ *
38
+ * @param {string} local - absolute local path, typically a session's cwd.
39
+ * @param {string} root - the mirror registry root (`$DSH_HOME/remote-workspaces`).
40
+ * @returns {{mirrorDir: string|null, remotePath: string, machine: {host: string, port: number, username: string}|null}}
41
+ * `machine` is the mirror-recorded origin, or null when `local` is not inside
42
+ * a usable mirror (in which case `remotePath` is empty too).
43
+ */
44
+ export function resolveMirror(local, root) {
45
+ let mirrorDir = null
46
+ let remotePath = ''
47
+ let machine = null
48
+ if (!local || !root || !existsSync(root)) return { mirrorDir, remotePath, machine }
49
+ const base = norm(local)
50
+ let hostDirs
51
+ try {
52
+ hostDirs = readdirSync(root)
53
+ } catch {
54
+ return { mirrorDir, remotePath, machine }
55
+ }
56
+ for (const hostDir of hostDirs) {
57
+ const hostPath = path.join(root, hostDir)
58
+ if (!statSync(hostPath, { throwIfNoEntry: false })?.isDirectory?.()) continue
59
+ let entries
60
+ try {
61
+ entries = readdirSync(hostPath)
62
+ } catch {
63
+ continue
64
+ }
65
+ for (const entry of entries) {
66
+ const metaPath = path.join(hostPath, entry, '.dsh-remote-meta.json')
67
+ if (!existsSync(metaPath)) continue
68
+ const mirrorAbs = norm(path.join(hostPath, entry))
69
+ if (!isUnder(base, mirrorAbs)) continue
70
+ // Deepest match wins; an equal-length path cannot occur twice.
71
+ if (mirrorDir && mirrorAbs.length <= mirrorDir.length) continue
72
+ try {
73
+ const meta = JSON.parse(readFileSync(metaPath, 'utf8'))
74
+ if (!meta || !meta.host) continue
75
+ mirrorDir = mirrorAbs
76
+ remotePath = String(meta.remotePath || '')
77
+ machine = {
78
+ host: String(meta.host),
79
+ port: Number(meta.port) || 22,
80
+ username: String(meta.username || ''),
81
+ }
82
+ } catch { /* unparsable meta → not a usable binding */ }
83
+ }
84
+ }
85
+ return { mirrorDir, remotePath, machine }
86
+ }
87
+
88
+ /**
89
+ * Stable pool key for a remote identity. Two sessions on the same machine
90
+ * produce the same key and therefore share one SSH connection; sessions on
91
+ * different machines never collide.
92
+ * @param {{host: string, port?: number|string, username?: string}} m - the remote identity.
93
+ * @returns {string} the canonical `user@host:port` key.
94
+ */
95
+ export function poolKey(m) {
96
+ return `${(m && m.username) || ''}@${(m && m.host) || ''}:${Number(m && m.port) || 22}`
97
+ }