Bundle
dsh-self-upgrade
Settings-page DSH self-upgrade: check the running host against the npm registry, run `npm install -g @deepseek-ai/dsh@latest` on confirmation, and restart the host instance.
- Source
- snow930
- License
- MIT
- Updated
- Updated 6 days ago
Readme
# dsh-self-upgrade
DSH (DeepSeek Harness) 自升级插件:在 Web GUI 设置页添加「系统更新」区块,一键检查版本并执行升级。
## 功能
- **版本检查**:自动对比运行中 DSH 宿主版本与 npm registry 最新版
- **一键升级**:点击按钮执行 `npm install -g @deepseek-ai/dsh@latest`
- **实时进度**:SSE 流式推送安装日志,无需刷新即可看到每行输出
- **自动重启**:安装完成后自动停止旧实例、等待端口释放、后台拉起新实例、刷新页面
- **安全回滚**:npm 安装失败时旧实例不受影响,天然回滚
## 安装
**推荐:从 npm 安装**:
```bash
dsh plugin --profile web add dsh-self-upgrade
```
或手动编辑 `profiles/web/package.json`:`dependencies` 增加
`"dsh-self-upgrade": "^0.1.0"`、`dsh.profile.bundles` 追加 `"dsh-self-upgrade"`,
然后在 profiles/web 下 `pnpm install`。
**本地开发(维护者迭代)**:link 到本地检出,修改源码后重启 DSH Web 即生效,
无需重新发布 npm:
```bash
dsh plugin --profile web add link:~/git/dsh-self-upgrade
```
## 工作原理
### 服务端(`lib/index.js`)
Cordis 插件,注册 4 个 loopback-only HTTP 端点:
| 端点 | 方法 | 功能 |
|---|---|---|
| `/api/self-upgrade/check` | GET | 返回 `{current, latest, hasUpdate}` |
| `/api/self-upgrade/run` | POST | 生成升级脚本并以 detached 进程执行 |
| `/api/self-upgrade/status` | GET | 返回阶段推断 + 日志尾部(轮询用) |
| `/api/self-upgrade/stream` | GET | SSE 实时流式推送日志(安装阶段用) |
升级脚本流程:`npm install -g` → `kill 旧进程` → `等端口释放` → `setsid nohup dsh web`。
### 客户端(`lib/client.js`)
通过 `settings.section` slot 注册设置页一级区块「系统更新」。安装阶段用 `EventSource` 接收 SSE 实时日志;重启阶段(旧进程已死)自动 fallback 到轮询。
## 安全
- 所有端点仅接受 loopback(127.0.0.1 / ::1)请求
- 升级脚本内容由服务端固定生成,不接受任意命令注入
- 目标版本白名单校验(仅 semver 格式)
- npm 安装失败 = 旧进程不动,零影响
## 文件结构
```
dsh-self-upgrade/
├── package.json # 插件清单 + dsh.client 声明
├── cordis.patch.yml # loader entry 注册
├── lib/
│ ├── index.js # 服务端 cordis 插件
│ └── client.js # 客户端 settings.section UI
└── README.md
```
## 卸载
从 profile `package.json` 删除 `dsh-self-upgrade` 依赖和 bundles 条目,`pnpm install` 即可。
Install
dsh plugin --profile web add github:snow930/dsh-self-upgrade#896ff0d372df0a941abf123149b081d01926b19b
Profile: web
With the hub plugin installed, ask your agent to install it by name — it resolves the same plan shown here.
dsh plugin --profile web add github:stvlynn/dsh.fish#path:packages/dsh-plugin-hub
install dsh-self-upgrade from the hub