dsh-power-controls: DSH Power Controls and Auto Cleanup Plugin

Introduction

DeepSeek Harness (DSH) adopts a plug-in architecture. When developing or debugging locally, it is sometimes necessary to restart the backend or shut down the service. dsh-power-controls adds two power buttons to the “General Settings” on the settings page, providing restart and shutdown capabilities. It also supports an automatic cleanup mechanism to prevent server processes from continuing to occupy memory after the page is closed.

Core Features

This plugin primarily addresses issues regarding DSH backend restarts, shutdowns, and resource release after page closure.

  1. Restart DSH (Power Cycle)
    After clicking the button, the plugin kills the currently running dsh web process, waits for port 3080 to be released, launches a new instance, and finally verifies that the port is successfully listening. The page will automatically refresh after being disconnected for a few seconds.

  2. Shut Down DSH (Backend Only)
    This only shuts down the backend service. The browser tab will remain in a disconnected state, and the user needs to double-click the DSH Web icon on the desktop to reopen it.

  3. Automatic Cleanup (Wait for all pages to stop beaconing)
    Enabled by default. When all browser tabs are closed or become invisible, the plugin waits for a period of time (default 15 seconds). It only exits the process after confirming there are no active page requests. The configuration item autoCloseMs can be set to 0 to disable this feature.

  4. Tab Icon Switching (Whale-chan)
    The plugin replaces the tab’s favicon with a Whale-chan image (128px). The server injects the resource route via tapIndex, and the client re-confirms the icon status via applyFavicon() during every re-render.

Restart Mechanism Explanation

On Windows, restarting DSH relies on the Task Scheduler rather than a simple spawn detached helper.

The early implementation involved spawning a detached helper process and then exiting. This caused a problem: when the parent process (dsh web) exited, it would reclaim the entire process tree, killing the helper process as well, which prevented the backend from restarting.

To avoid this issue, the current implementation plan is:
1. Click the “Restart DSH” button.
2. The backend registers a scheduled task named DSHPowerRestart.
3. Once the task starts, it executes the respawn-dsh-web.ps1 script:
* Find and stop the old dsh web process by port.
* Wait for port 3080 to be released (up to 60 seconds).
* Run start-dsh-web.ps1 -NoOpen to launch a new instance.
* Verify the port, retrying up to 3 times.
4. The backend plugin only allows itself to exit after the scheduled task has been successfully registered and started.

Installation and Activation

The DSH backend must be stopped before installation. This is because installing the plugin causes pnpm to re-resolve the dependency tree. If the running backend has locked the lightningcss native module, it will cause subsequent installation errors (Access Denied).

# Install from GitHub
dsh plugin --profile web add github:harmless0819-dev/dsh-power-controls

After installation is complete, refresh the settings page, and the two power buttons will be visible under “General Settings”.

Self-Check and Usage

Since there is no browser interface available, you can check the plugin status via command-line tools.

  1. Health Check Endpoint
    The plugin provides a /dsh-power/health endpoint for self-checks.
    curl http://127.0.0.1:3080/dsh-power/health
The returned data includes `lastReport` (last report time), `reportCount` (number of reports), `clicks` (number of clicks), `injected` (whether buttons were successfully injected), `reconnect` (number of reconnections), and `clients` (list of currently active clients).
  1. View Exit Logs
    The plugin records the exit reason for automatic cleanup to the log file D:\deepseek\logs\dsh-power-auto-close.log and reports it back in the lastExit field on the next startup.

Summary

dsh-power-controls simplifies the DSH backend restart and shutdown processes by adding power buttons to the settings page. Its automatic cleanup mechanism effectively prevents resource occupation by server processes after the page is closed. During installation, care must be taken to stop the backend first, and on Windows, the restart relies on the Task Scheduler.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye