dsh-task-notifier
v1.1.0
Published
DeepSeek Harness web profile bundle: notifies the user when any session task completes, via browser Notification + cross-platform host toast.
Readme
dsh-task-notifier
DeepSeek Harness web profile bundle:当任意会话(Agent)的任务完成时,通过 浏览器通知 + Windows 托盘通知 提醒你,即使页面没有打开也能收到提醒。
这是一个独立发布的 npm 组合包(bundle),通过 pnpm 安装进 web profile 的 node_modules,与官方 dsh-better-sidebar、dsh-subagent-codex 相同的标准形态:
- 声明
dsh.bundle.patch→ 安装后自动加入 profile 的组合层栈; - 声明
dsh.client(platformweb)→ 浏览器端由 client module system 自动加载; - 含 node half(Host 端)与 browser half(Client 端)两端。
功能
- ✅ 任意会话任务完成即提醒(
running → idle转换)。 - ✅ 浏览器 Notification:WebUI 打开时,通过 Web Notification API 弹出系统通知。
- ✅ 跨平台 Host 通知:Host 端监听
agent/status,默认用node-notifier(Windows / macOS / Linux)弹出系统通知,即使没有浏览器页面也生效。 - ✅ Windows 托盘兜底(可选):
notifier: 'powershell'或auto失败时用 PowerShellSystem.Windows.Forms.NotifyIcon弹托盘气泡。 - ✅ 会话自己的
displayTitle显示在通知正文中。
安装
# 在 DeepSeek Harness 环境中(或直接对 web profile)
dsh plugin --profile web add dsh-task-notifier或者手动用 pnpm 装进 profile 的 node_modules 并重启 profile:
cd "$HOME/.dsh/profiles/web"
pnpm add dsh-task-notifier
# 然后重启该 profile(或在 cordis.patch.yml 里手动挂载)
dsh plugin会在看到包的dsh.bundle.patch声明后,自动把dsh-task-notifier追加到dsh.profile.bundles组合层栈;重启 profile 后生效。
工作原理
任务完成判定
- Host half 监听
agent/status,当某 Agentrunning → idle时判定其会话任务完成。 - Browser half 订阅
ctx.sessions.list,当某会话记录从running翻转为非running时判定完成。
浏览器通知(browser half)
订阅会话列表 observable,检测到 running → idle 边时调用:
new Notification('DeepSeek Harness', {
body: '会话任务已完成: ' + session.displayTitle,
tag: 'dsh-task-notifier:<sessionId>',
})仅当浏览器 Notification.permission === 'granted' 时显示。
Host 通知(node half)
Host 半侧在任务完成时展示系统通知,后端由 notifier 配置选择:
node-notifier(默认):跨平台,经node-notifier包调用各平台原生通知(Windows Toaster、macOS terminal-notifier、Linux notify-send);powershell:仅 Windows,隐藏启动powershell.exe,用System.Windows.Forms.NotifyIcon弹托盘气泡;auto(默认值):先尝试node-notifier,在 Windows 上失败时回退到 PowerShell 兜底。
PowerShell 后端通过 ctx.subprocess 隐藏启动,标题/正文经 TOAST_TITLE/TOAST_BODY 环境变量传入,避免注入:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$ni = New-Object System.Windows.Forms.NotifyIcon
$ni.Icon = [System.Drawing.SystemIcons]::Information
$ni.Visible = $true
$ni.BalloonTipTitle = $env:TOAST_TITLE
$ni.BalloonTipText = $env:TOAST_BODY
$ni.ShowBalloonTip(5000)
for ($i = 0; $i -lt 20; $i++) {
[System.Windows.Forms.Application]::DoEvents()
Start-Sleep -Milliseconds 150
}
$ni.Visible = $false
$ni.Dispose()配置
notifier 后端选择在 cordis 插件行上的 config.notifier 中设置(默认 auto):
# cordis.patch.yml 中挂载该插件时,在插件行上添加 config
- insert:
- id: dsh-task-notifier
name: dsh-task-notifier
# config:
# notifier: auto # 默认:node-notifier,Windows 失败回退 PowerShell
# notifier: node-notifier # 只跨平台,绝不使用 PowerShell 兜底
# notifier: powershell # 只 Windows 托盘气泡不设置任何配置即用默认 auto。
项目结构
dsh-task-notifier/
├── src/
│ ├── index.ts # node half(Host 端:agent/status → 跨平台通知/Windows 兜底)
│ ├── types.d.ts # 本地 Ctx 类型
│ └── client/index.ts # browser half(Client 端:会话完成 → 浏览器通知)
├── lib/ # 构建产物(index.js / client.js / types)
├── scripts/build.mjs # tsc 编译 + 浏览器闭包封装
├── test/
│ ├── browser-half.mjs # 浏览器半侧行为测试(running→idle 触发通知)
│ ├── node-half.mjs # node 半侧测试(powershell 兜底降级 + node-notifier 路径)
│ └── notify.ps1 # 独立的 Windows 通知脚本(手动验证)
├── cordis.patch.yml # dsh.bundle.patch 组合层(挂载插件行)
├── package.json
└── README.md构建
pnpm install
pnpm build # -> lib/index.js + lib/client.js(tsc 编译并封装浏览器闭包)
node test/browser-half.mjs # 浏览器半侧行为测试
node test/node-half.mjs # node 半侧测试发布
手动发布
pnpm publish --access public # 或 pnpm pack 产出 tarball自动发布(GitHub Actions,OIDC)
仓库已配置 .github/workflows/publish.yml:当推送版本标签 vX.Y.Z 且与 package.json 的 version 一致、且该版本尚未发布时,CI 自动构建、测试并 npm publish --provenance。
发布走 npm OIDC(可信发布者):工作流请求 id-token,npm 用它兑换短期发布令牌——无需在 GitHub 存储任何长效 npm token。
一次性设置(在 npm 网站):
- 登录 npmjs.com → 头像 → Access Tokens → Generate New Token → 选择 Publish(OIDC)。
- 绑定你的 GitHub 仓库与工作流:填
MoRanYue/dsh-task-notifier,environment 留空或选publish,并确保 workflow 引用publish.yml(与上面文件一致)。
此后发布新版本(本地已授权发布者,无 token 交互):
# 先改 package.json 的 version,再提交并打标签
git tag v1.1.0
git push origin master
git push origin v1.1.0工作流会校验 tag 版本与 package.json 一致;已存在的版本会安全跳过,不会报错。
已知限制
node-notifier需要各平台的通知机制可用:macOS 依赖terminal-notifier、Linux 依赖notify-send、Windows 依赖行动中心;在无图形会话的机器上可能失败(auto模式在 Windows 上会自动回退到 PowerShell 托盘)。- PowerShell 托盘兜底需要通过
subprocess服务执行powershell.exe,仅 Windows 生效。 - 浏览器通知需要用户授权(
Notification.requestPermission);未授权时依赖 node half 通知。
