Back to home@a1113622001

dsh-auto-update

DeepSeek Harness (cordis) plugin: self-update for the harness launcher - checks npm for a newer @deepseek-ai/dsh, stages it, and applies it on harness exit (or update-and-restart from the web panel).

Stars
0
Language
JavaScript
Created
Aug 19, 2026
Updated
Aug 20, 2026
GitHub repo

Introduction

dsh-auto-update

License Node GitHub

DeepSeek Harness(cordis)插件:让 harness 更新它自己

它定期检查 npm 上 @deepseek-ai/dsh 是否有比当前安装更新的版本;发现更新后自动下载 tarball 并暂存(stage);等 harness 进程退出时,由分离的辅助进程执行 npm install -g, 把全局安装替换成新版本;可选地按原启动参数自动重启 dsh。Web 界面右下角默认只显示一个 「检查更新」小胶囊(点击展开完整面板),面板内显示版本状态,并提供「检查更新」「更新并重启」 「取消暂存」。

工作原理

  1. 安装发现 —— 通过 process.argv[1](npm shim 启动的 …/node_modules/@deepseek-ai/dsh/lib/bin.js) 推导全局安装根目录;也可用 config.installRoot 显式指定。若 harness 是从源码 (pnpm dsh)运行的,则自动更新不可用并会在日志中说明。
  2. 版本检查 —— 调用 npm view @deepseek-ai/dsh@<distTag> version --json,复用你配置的 registry / 镜像 / 代理。内置极简 semver 比较(支持 1.2.3-rc.1 这类预发布版本)。
  3. 暂存 —— npm pack 下载精确版本的 tarball 到 $DSH_HOME/updates/,写入 pending-update.json(含 from/to、安装根、进程 pid、是否重启等)。此阶段不触碰运行中的安装。
  4. 应用 —— 在 harness 的 process.on('exit') 里分离启动 bin/apply-update.js: 等待旧进程真正退出(Windows 上运行中的进程会锁住 sharp/koffi/node-pty 等原生模块文件, 所以必须在退出后安装)→ npm install -g <tarball> → 校验安装版本 → 记录结果 → 按需用 dsh <原参数> 重启。

安装

在 profile 目录安装插件(与 dsh-session-stats-panel 一致):

corepack pnpm --dir "%USERPROFILE%\.dsh\profiles\web" add "C:\Users\baiyec\Desktop\Harness\plugins\dsh-auto-update"

或直接从 GitHub 安装(利用随包发布的 dsh.bundle 清单,插件会自动注册并激活):

dsh plugin add github:a1113622001/dsh-auto-update

手动安装时,需要把仓库根目录下的 cordis.patch.yml 作为 bundle patch 注册到 harness,插件才会随 harness 自动启动。dsh plugin add 已内置该 bundle,因此 无需手动维护(详见下面的 yaml 片段,它正是 cordis.patch.yml 的内容)。

然后在 %USERPROFILE%\.dsh\profiles\web\cordis.patch.yml 追加:

# dsh-auto-update: 让 harness 自我更新(检查 npm → 暂存 → 退出时应用)
- insert:
    - id: auto-update
      name: 'dsh-auto-update'
      config:
        distTag: latest
        checkOnStart: true
        checkIntervalMinutes: 240
        autoStage: true
        applyOnExit: true
        relaunch: false

保存后运行中的 harness 会热加载宿主插件(cordis.patch.yml 被 watch),浏览器刷新一次页面 即可在右下角看到「检查更新」胶囊(默认收纳,点击展开面板)。

配置

字段默认说明
distTaglatest跟踪的 npm dist-tag(如 latest / next
registry""npm registry 覆盖;留空使用你配置的 registry
checkOnStarttrue启动时检查一次
checkIntervalMinutes240周期检查间隔(分钟);0 关闭周期检查
autoStagetrue发现更新后自动下载并暂存
applyOnExittrueharness 退出时执行分离的应用进程
relaunchfalse应用后按原启动参数自动重启 dsh(面板上的「更新并重启」始终会重启)
installRoot""显式指定 harness 安装根目录(自动发现失败时用)
updateDir""更新文件目录;默认 $DSH_HOME/updatesC:\Users\<你>\.dsh\updates

行为细节

  • 安全默认:默认只「暂存 + 退出时应用」,不会在会话中途杀进程。要全自动闭环,把 relaunch 设为 true,或点面板上的「更新并重启」。
  • 面板按钮/autoUpdate 是仅回环(loopback)的 RPC channel,浏览器通过 POST /autoUpdate/<endpoint> 调用 status / check / stage / cancel / applyRestart
  • 手动触发applyRestart 会先强制检查、必要时补暂存,然后写 relaunch: true 到 manifest,响应返回后 ~0.8s 退出进程,由退出钩子启动应用进程并自动重启。
  • 崩溃容错:如果进程被强杀(无 exit 事件),暂存的 manifest 会保留;下次启动插件会 恢复它并重新检查,之后照常应用。
  • 更新历史$DSH_HOME/updates/update-history.jsonl 记录每次应用的结果; update-result.json 是最近一次的结果。

验证 / 手动测试

# 1) 插件语法
node --check plugins\dsh-auto-update\lib\index.js
node --check plugins\dsh-auto-update\lib\updater.js
node --check plugins\dsh-auto-update\bin\apply-update.js

# 2) 宿主 RPC 已挂载(harness 运行中)
curl -s -X POST http://127.0.0.1:3080/autoUpdate/status -H "content-type: application/json" -d '{"type":"client-request","rpcId":"t1","method":"status","payload":{}}'

# 3) 强制检查
curl -s -X POST http://127.0.0.1:3080/autoUpdate/check -H "content-type: application/json" -d '{"type":"client-request","rpcId":"t2","method":"check","payload":{}}'

已知限制

  • 仅支持 npm 全局安装的 harness(dsh CLI 装在 %APPDATA%\npm)。源码运行 (pnpm dsh / 开发 checkout)不会被更新。
  • 应用在退出后进行:若从未优雅退出(如直接杀进程、断电),更新会顺延到下次退出。
  • Windows 上原生模块(sharp/koffi/node-pty)在进程退出后仍可能让文件句柄延迟释放,导致 npm install -g 偶发 EBUSY。helper 会等到记录在案的进程真正退出,再重试若干次(带退避), 因此不会因一次句柄未释放而失败。
  • npm install -g 需要写入 npm 全局目录与缓存目录的权限(普通用户权限即可)。
  • 若把插件源码目录移走,已暂存 manifest 里记录的 helper 路径会失效;重新检查即可重新暂存。