READMESource: main@052f8e21
dsh-web-restart
一个 DeepSeek Harness (dsh) bundle 插件: 确保 / 重启 dsh web 服务。加载即生效——服务挂了自动拉起;需要换新代码时一键脱管重启。
背景
dsh 的 agent 运行在 web 服务进程内部。如果 agent 直接 Stop-Process 杀掉 web 服务,
等于杀掉自己所在的进程树,重启命令永远执行不到后半段("自杀式重启")。
本插件通过 WMI Win32_Process.Create 把新服务进程创建在 WMI 宿主下,
完全脱离 agent 进程树,重启后依然存活。
功能
模式 (mode) |
行为 |
|---|---|
ensure(默认) |
端口未监听 → 脱管启动 web 服务;已监听 → 不动 |
rotate |
已监听 → 脱管重启(等调用方返回后 kill 再拉起);未监听 → 直接启动 |
另外支持 flag 文件触发重启:在 web profile 内运行时(此时服务必然在跑),
创建 <DSH_HOME>/dsh-web-restart.flag,下一个会话回合开始时插件会删除 flag 并脱管重启服务,
用于加载新插件/新代码。
安装
# Install from npm (requires dsh >= 0.1.0-rc.6)
dsh plugin --profile headless add @lnsiaxe/dsh-web-restart # 服务挂了之后,跑一次 headless 任务即可复活 web 服务
dsh plugin --profile web add @lnsiaxe/dsh-web-restart # 启用 flag 触发重启
# Restart dsh web; the plugin activates on boot
dsh web
本地开发(fork 修改后自用):
dsh plugin --profile headless add file:<你的插件目录>
dsh plugin --profile web add file:<你的插件目录>
使用
# 服务挂掉后:headless 启动,插件在 boot 时自动拉起 web 服务
dsh --profile headless "启动 web 服务"
# 在 web profile 里请求重启(换新代码后):
# 1) 创建 flag: New-Item C:\Users\<you>\.dsh\dsh-web-restart.flag
# 2) 发一条消息触发新回合 → 插件自动脱管重启
配置(cordis.patch.yml)
- insert:
- id: web-restart
name: '@lnsiaxe/dsh-web-restart'
config:
port: 3080 # web 服务端口
mode: ensure # ensure | rotate
# workspace: C:\Users\<you>\my-workspace # 可选,默认取进程 cwd
# gitDir: C:\Users\<you>\git\cmd # 可选,默认 ~\git\cmd(给 side-panel 的 git 用)
工作原理
- 激活时把
dsh-web-restart-launch.cmd/dsh-web-restart-rotate.cmd生成到DSH_HOME:launch.cmd:设置DSH_HOME/PATH(含 git),cd到工作区,以node …\lib\bin.js web --port <port>前台运行并重定向日志rotate.cmd:ping延时让调用方安全返回 → kill 3080 监听进程 → 调用launch.cmd
- 通过
powershell Invoke-CimMethod Win32_Process.Create启动脚本——新进程父进程是 WMI 宿主, 不在 agent/服务进程树内,因此不受进程树回收影响。 - 服务本身在 web profile 里加载本插件时(
argv含web),自动跳过自重启,仅响应 flag。
非 Windows 平台回退为 spawn(..., { detached: true }).unref()。
相关
- dsh-side-panel:本插件的配套面板(Git 审查 / 文件 / 终端)。 它曾有一个"打开面板后聊天区消失"的布局 bug(issue #1), 可参考该 issue 的修复思路。
No comments yet. Be the first to write one.