Skip to content
dsh.fish
Bundle

@lnsiaxe/dsh-web-restart

Ensure or rotate the DSH web server (detached) when this bundle is loaded in a profile

Source
LnsiAxe
License
MIT
Updated
Updated 21 days ago

Readme

# dsh-web-restart

一个 [DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness) 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 并脱管重启服务,
用于加载新插件/新代码。

## 安装

```sh
# 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 修改后自用):

```sh
dsh plugin --profile headless add file:<你的插件目录>
dsh plugin --profile web add file:<你的插件目录>
```

## 使用

```sh
# 服务挂掉后: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`)

```yaml
- 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 用)
```

## 工作原理

1. 激活时把 `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`
2. 通过 `powershell Invoke-CimMethod Win32_Process.Create` 启动脚本——新进程父进程是 WMI 宿主,
   不在 agent/服务进程树内,因此不受进程树回收影响。
3. 服务本身在 web profile 里加载本插件时(`argv` 含 `web`),自动跳过自重启,仅响应 flag。

非 Windows 平台回退为 `spawn(..., { detached: true }).unref()`。

## 相关

- [dsh-side-panel](https://github.com/ccq1/dsh-side-panel):本插件的配套面板(Git 审查 / 文件 / 终端)。
  它曾有一个"打开面板后聊天区消失"的布局 bug([issue #1](https://github.com/ccq1/dsh-side-panel/issues/1)),
  可参考该 issue 的修复思路。

## 许可证

[MIT](LICENSE)

Install

dsh plugin --profile web add github:LnsiAxe/dsh-web-restart

Profile: web

  • This source has no pinned commit, so a later push upstream changes what installs. Prefer pinning a commit.
Source