前言¶
用 DeepSeek Harness(DSH)跑 dsh web 時,改 profile、換 bundle 或排查 host 側問題,常常需要整進程退出再拉起。在終端裏 Ctrl+C 再手動啓動可以,但 WebUI 一旦斷線,側邊欄和當前頁面狀態都會丟;若希望「點一下就能重啓,頁面還能自己回來」,單靠 Node 進程內部做不到——dsh web 是單進程,進程一退出 UI 就斷線,必須由外部守護在退出後重新拉起。
下面介紹社區插件 dsh-web-restart(維護者 DEVbyQIN):在 WebUI 側邊欄增加「重啓 DSH」按鈕,並附帶 macOS 上 launchd LaunchAgent、啓動臺圖標等配套腳本。插件本身無法在進程死後自舉;重啓按鈕與外部守護是配套的兩半,缺一不可。
這是什麼¶
dsh-web-restart 是一個 DSH profile bundle:host 側註冊重啓 HTTP 端點與可選 slash 命令,client 側在 WebUI 注入側邊欄按鈕與全屏遮罩、恢復輪詢。倉庫同時提供 launcher/macos/ 下的 launchd 安裝腳本與 AppleScript 啓動臺 App 源碼,用於崩潰或主動退出後的自動拉起與登錄自啓。
- 目錄頁:skillhub.cn/plugins/DEVbyQIN/dsh-web-restart
- 源碼與文檔:github.com/DEVbyQIN/dsh-web-restart
- 許可證:MIT(見倉庫 LICENSE)
社區插件目錄爲獨立站點,與 DeepSeek / 幻方無官方從屬關係;安裝前請自行查看源碼與許可證。
核心功能¶
| 能力 | 說明 |
|---|---|
| WebUI 重啓按鈕 | 側邊欄底部「⇄ 重啓 DSH」,兩段式確認防誤觸;觸發後全屏遮罩,進程退出後由外部守護拉起,頁面輪詢恢復並自動刷新 |
| 雙通道觸發 | 首選 DSH 官方 RPC(remote.commands.execute("/restart")),回退同源 fetch |
| launchd 守護 | KeepAlive 在崩潰或退出後自動拉起 dsh web,可配置登錄自啓 |
| 啓動臺圖標 | 可用 AppleScript 編譯 .app,點擊啓動並打開瀏覽器 |
| 可選 token | host 端點支持 Authorization / X-Dsh-Restart-Token 校驗 |
host 端(index.mjs)註冊同源 POST /api/_dsh/restart,命中後返回 202,延遲讓響應落盤再退出。默認 mode: "exit" 爲 process.exit(),交給 launchd KeepAlive 拉起;mode: "exec" 在同進程內 spawn 新 dsh web 並 unref,適合無外部守護、從終端手動跑的場景。client 端(lib/client.js)使用槽位 sidebar.footer.action,遮罩掛在 documentElement 上,每 2 秒輪詢服務是否恢復,不依賴 window.confirm(嵌入 WebView 中可能被靜默禁用)。
安裝與啓用¶
插件裝進 DSH 的 web profile,而不是憑插件名拼接 dsh plugin add。
從 GitHub 安裝(推薦)¶
在 profile 目錄 ~/.dsh/profiles/web/ 中執行:
cd ~/.dsh/profiles/web
pnpm add "dsh-web-restart@github:<你的用戶名>/<倉庫名>"
在 ~/.dsh/profiles/web/package.json 的 dsh.profile.bundles 數組末尾增加 bundle 名:
"dsh": {
"profile": {
"bundles": [
"@deepseek-ai/dsh-base",
"@deepseek-ai/dsh-web-app",
"dsh-web-restart"
]
}
}
重啓 dsh web 後生效。
本地 link(開發用)¶
cd ~/.dsh/profiles/web
pnpm add "link:/絕對/路徑/dsh-web-restart"
同樣在 bundles 中加入 "dsh-web-restart",重啓生效。
覆蓋默認配置¶
可在 profile 的 cordis.patch.yml 中覆蓋 mode、token、flushMs、enableCommand 等,例如:
- id: web-restart
name: dsh-web-restart
token: my-secret
典型用法¶
WebUI 內重啓¶
- 確認 profile 已啓用
dsh-web-restart且dsh web已重啓。 - 在 macOS 上若希望退出後能自動回來,先完成下一節的 launchd 安裝(僅
mode: "exec"且無守護時,可依賴同進程 spawn,但 README 強調與 launchd 配套使用)。 - 打開 WebUI,在側邊欄底部點擊「⇄ 重啓 DSH」,按兩段式確認。
- 全屏顯示「正在重啓 DSH…」,外部守護拉起進程後,客戶端約每 2 秒輪詢,恢復後自動刷新頁面。
macOS:launchd 守護¶
安裝腳本會複製啓動邏輯到 ~/Library/Application Support/dsh-web/(規避 launchd 在 TCC 下無法讀取 ~/Documents 等路徑裏腳本的問題),並自動探測 node 與 dsh 路徑;可用 NODE_BIN、DSH_ENTRY、DSH_HOME 覆蓋。
chmod +x launcher/macos/*.sh
launcher/macos/dsh-web-control.sh install
常用控制命令:
| 命令 | 作用 |
|---|---|
dsh-web-control.sh status |
查看 launchd 狀態 |
dsh-web-control.sh restart |
手動重啓 |
dsh-web-control.sh stop / start |
停 / 啓(停止不解除自啓) |
dsh-web-control.sh uninstall |
卸載 |
日誌路徑:~/.dsh/dsh-web.launchd.log 與 ~/.dsh/dsh-web.launchd.err.log。
啓動臺 / Dock 圖標¶
用倉庫內 AppleScript 編譯 App:
mkdir -p build
osacompile -o build/DSH.app launcher/macos/DSH-Web-Launcher.applescript
cp -R build/DSH.app /Applications/
也可新建 Automator「應用程序」,運行 shell 腳本調用 ~/Library/Application Support/dsh-web/dsh-web-start.sh,sleep 3 後 open http://127.0.0.1:3080,另存爲 DSH.app 拖到 Dock 或啓動臺。
適用場景與注意¶
適合長期在 macOS 上用 dsh web 做本地開發、需要改 bundle 後快速整進程重啓、又希望少碰終端的場景。launchd 與啓動臺腳本面向 macOS;Linux 等環境仍可使用 WebUI 按鈕與 host 端點,但「退出後自動拉起」需自行用 systemd 等外部守護,倉庫 README 以 macOS launchd 爲完整示例。
插件以當前 dsh web 進程權限運行;若配置了 token,請避免把密鑰提交到公開倉庫。重啓會中斷所有 Web 連接與進行中的會話,生產或共享環境使用前請評估影響。
開發自測(來自 README):
node --check index.mjs lib/client.js
node validate.mjs
結尾¶
dsh-web-restart 把「WebUI 一鍵重啓」與「macOS 外部拉起」拆成清晰的兩半:按鈕負責有序退出與前端恢復體驗,launchd 負責進程死後回來。在 DSH「一切皆插件」的生態裏,它補的是本地 Web 運維裏很小但高頻的一步。
- 目錄頁:https://www.skillhub.cn/plugins/DEVbyQIN/dsh-web-restart
- GitHub:https://github.com/DEVbyQIN/dsh-web-restart