DSH 通知插件:在 Agent 需要你介入的任何時刻發送 Windows 系統通知。
在 Agent 運行過程中,開發者往往需要離開屏幕處理其他事務,此時很難第一時間感知到 Agent 何時完成了任務、遇到了阻塞或等待人工批准。dsh-turn-notify 通過 Windows Toast 通知和系統提示音,在 Agent 需要人工操作時通知開發者。
功能特性¶
觸發時機
插件覆蓋 Agent 運行中的關鍵狀態,包括:
* 輪次完成
* 目標阻塞 / 暫停
* 對話中斷 / 中止
* 輪次出錯
* 達到輸出上限
* 會話中斷(崩潰恢復)
* 等待批准
* 等待回答(Agent 主動提問)
* 計劃待審閱
* 運行出錯(步驟級錯誤)
通知樣式與行爲
* 通知類型:支持 Windows Toast 長橫幅與特定模板。
* 內容預覽:顯示會話編號、問答內容預覽(默認截斷 15 字)。
* 提示音:默認播放 Windows Background.wav,與彈窗同步。
* 子代理靜默:僅通知根會話,子代理產生的通知會被過濾。
* 防風暴機制:同會話內同類關鍵事件在 1.5 秒內合併爲一條通知,避免重複彈窗。
* 多會話隔離:按 session.id 區分,互不干擾。
* 雙語支持:支持中文與英文。
降級方案
* 優先使用 C# 編譯的 dsh-notify.exe。
* 缺失時自動回退 notify.ps1 腳本。
* 通知失敗時降級爲日誌記錄。
安裝與啓用¶
使用官方命令安裝插件。安裝後需要在配置文件中啓用相應事件的通知。
1. 安裝插件
dsh plugin --profile web add github:Ruiming-cn/dsh-turn-notify
2. 配置補丁
在 ~/.dsh/profiles/web/cordis.patch.yml 中爲 turn-notify 條目添加 config 配置。以下配置項均爲可選,插件代碼內部已有默認值:
- id: turn-notify
config:
language: zh # zh | en
sound: true
notify:
completed: true
blocked: true
aborted: true
error: true
maxTokens: true
interrupted: true
goals: true
approvals: true
questions: true
planReview: true
agentError: true
cooldownMs: 10000
mergeWindowMs: 1500
previewChars: 15
titlePrefix: DSH
showSessionTag: true
timeoutMs: 10000
dryRun: false
rootSessionsOnly: true
3. 重啓 DSH
修改插件代碼後,必須重啓 DSH GUI 才能生效。
構建原生通知器¶
插件倉庫中不包含 dsh-notify.exe 二進制文件,需要自行編譯。
1. 準備環境
確保系統安裝了 .NET Framework 4.8 的 csc.exe(通常位於 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe)以及 Windows SDK 的 Windows.winmd。
2. 編譯
在 plugin/ 目錄下執行以下命令編譯 C# 源碼:
$winmd = "C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.26100.0\Windows.winmd"
$sysruntime = "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll"
& "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" /nologo /nostdlib /target:exe /out:"dsh-notify.exe" /r:mscorlib.dll /r:System.dll /r:System.Core.dll /r:"$sysruntime" /r:System.Windows.Forms.dll /r:System.Drawing.dll /r:System.Runtime.WindowsRuntime.dll /r:"$winmd" "dsh-notify.cs"
編譯完成後,將 plugin/ 目錄整體拷貝到全局 DSH 目錄,重啓 GUI 即可使用原生通知器。
注意事項¶
- 系統要求:僅支持 Windows 10/11。
- 重啓生效:修改插件代碼(JS 或 C#)後,必須重啓 DSH GUI 才能加載新代碼。
- 安全軟件:PowerShell 回退腳本可能被安全軟件攔截,建議自行構建
dsh-notify.exe。 - 通知特性:通知是系統級 UI,與 DSH 窗口焦點無關;如果開啓了系統的“專注助手”,可能會阻止通知彈出。