laobinghongcha/dsh-plugin-turn-notify ↗★ 0
dsh-plugin-turn-notify
Desktop notification plus system sound whenever a DSH turn finishes. 适合需要实时掌握AI响应状态的用户,支持自定义触发条件与防抖。
설치
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:laobinghongcha/dsh-plugin-turn-notify配置
bundle 层的 cordis.patch.yml 只负责 insert 插件行。要改默认值,请在
$DSH_PROFILE_DIR/cordis.patch.yml 里用相同 id 覆盖该行(匹配覆盖会替换整个 config,
所以要把需要保留的键一并写出):
- id: turn-notify
name: dsh-plugin-turn-notify
config:
enabled: true # 总开关
sound: true # 附带系统提示音
reasons: # 触发提醒的 turn/end reason.kind
- completed # 成功
- error # 出错
- blocked # 受阻
- max-tokens # 输出被截断
subagents: false # false = 忽略子代理会话,只提醒主会话
locale: auto # auto | zh | en
debounceMs: 800 # 同一会话 800ms 内不重复提醒
minDurationMs: 0 # 短于该时长的回合一概不提醒
includeSummary: true # 附最后一段 assistant 文本
summaryLength: 80 # 摘要字符数上限
可选 reason:completed error blocked max-tokens aborted interrupted forked。
未列出的原因一律不提醒。未识别的字段被忽略,非法值回落到默认值并打印一条 warn。
profile 的 cordis.patch.yml —— 改默认配置
- id: turn-notify name: dsh-plugin-turn-notify config: enabled: true sound: true subagents: false reasons: [completed, error, blocked, max-tokens]
### 发布到 npm(可选)
收录后市场会用 npm 或 GitHub 安装。想走 npm:
```powershell
npm login
npm pack --dry-run # 核对 files:index.js lib/ locale/ icon.svg cordis.patch.yml
npm publish
files 已排除 market/、scripts/,不会把发布脚本打进安装包。
验证
-
离线自检:
node scripts/selftest.js→ 13 sections passed。 -
真实通知链路(不依赖事件):
node scripts/test-turn-end.js # completed node scripts/test-turn-end.js error "自定义摘要" zh # 失败文案 + 中文成功输出
sent through windows-toast(或osascript/notify-send)。 -
触发一次真实 turn/end:在装好插件的 profile 里开新会话(包被重新加载才会生效), 发一句
你好让 agent 跑完一个回合。回合结束时日志应出现[turn-notify] notifying (completed): 回合完成 · — ...,桌面弹出通知。 出错文案可以用node scripts/test-turn-end.js max-tokens预览。
失败处理与边界
- 通知失败只写 console(
[turn-notify] notification failed via ...),不会 reject、不阻塞 agent loop; 监听器整体包在try/catch里,抛错也不会回到发事件的循环。 - 跨边界内容全部逐字段校验:
reason.kind必须在白名单内,turn必须是非负整数,cwd/sessionId/ 摘要都做长度截断,缺字段降级而不抛错。 - 用户/模型文本只通过子进程环境变量传给 PowerShell,从不拼进脚本;Windows 辅助脚本写在
%LOCALAPPDATA%\dsh-turn-notify(被沙箱拒绝时回落到os.tmpdir()\dsh-turn-notify)。 - 沙箱限制:DSH 的 Windows 文件沙箱不允许
node以管道方式捕获子进程输出 (spawn ... EPERM),因此本会话内运行测试脚本时 PowerShell 无法启动,日志会显示notification failed via windows: ... spawn EPERM。这是测试环境的限制,不是插件缺陷: 已完成的部分是自检、脚本生成,以及把生成好的launch.ps1在沙箱外手动执行(返回toast/balloon,退出码 0)。 由 DSH Host 进程直接拉起插件时不受该沙箱限制。
已知限制
- 无包身份(package identity)的进程不能使用 WinRT toast:脚本会写
HKCU\Software\Classes\AppUserModelId\DeepSeek Harness注册项,但在某些宿主上CreateToastNotifier仍返回0x80073D54,此时自动降级为托盘气泡(windows-balloon),再降级为消息框。 - Linux 依赖
notify-send(libnotify)与canberra-gtk-play/paplay;缺失时提醒不可见但只记日志。 - macOS 首次通知需要用户在“系统设置 → 通知”里允许对应宿主应用。