dsh-windows-notifier 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/DETAIL.md +9 -7
- package/index.js +22 -22
- package/package.json +1 -1
- package/toast-activate.ps1 +10 -2
package/docs/DETAIL.md
CHANGED
|
@@ -6,12 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
- **完成通知**:监听全局事件 `api-session/status`:agent 从 running 翻转为 idle 时触发(提问等待期间 agent 仍算 running,只有回合真正结束才触发)。
|
|
8
8
|
- **提问通知**:监听 `user-questions/request` waterfall(emit 时机),在正常转发给 answerer 之前(`next()`)弹通知,不改变提问流程。一次 `ask_user_question` 调用无论包含几个问题只弹一次通知;正文显示问题数量与第一个问题摘要。
|
|
9
|
-
- 插件激活时一次性注册 AUMID(开始菜单快捷方式 `
|
|
10
|
-
-
|
|
11
|
-
- 会话标题取不到时(如标题服务尚未生成),通知正文用「DSH」代替,不显示原始会话 id。
|
|
12
|
-
- 内存占用:插件在 DSH 进程内的常驻状态只有两个有界 Map(会话标题缓存上限 256 条、会话运行时长表随 idle/移除即清),会话移除时主动清理,不随运行时长增长;每次通知的 PowerShell 为 ~0.3 秒短命进程,跑完即释放,不常驻。
|
|
9
|
+
- 插件激活时一次性注册 AUMID(开始菜单快捷方式 `DSH Notifier.lnk` + `System.AppUserModel.ID` COM 属性,这是 Windows 对非打包应用的唯一有效注册方式),快捷方式图标指向 DSH 的 `resources\tray.ico`,并注册 `dsh-windows-notify://` 协议把点击路由到激活脚本。快捷方式已存在时跳过,不重复执行;通知标题栏显示「DSH Notifier」(取自快捷方式名)。
|
|
10
|
+
- **点击激活**:toast 带 `activationType='protocol'`,点击通知主体激活协议 → wscript 无窗口启动激活脚本 → 脚本从注册表解析出 DSH 的 exe 路径并直接启动它(不走 `dsh://open` 协议——协议激活会回到激活脚本自身,DSH 未运行时形成无限进程递归)。DSH 已在运行时,新启动的实例会把窗口交给单实例机制聚焦。
|
|
13
11
|
- 每次通知 spawn 一个 `powershell.exe`(`-EncodedCommand`,UTF-16LE base64,中文不乱码),用 WinRT `ToastNotification` 弹原生通知并播放默认提示音。进程 `unref`,不阻塞 Harness。
|
|
14
|
-
- 通知显示时长为 `duration="long"`(约 25 秒,默认短通知只有 5 秒),无额外按钮。
|
|
15
12
|
- 零第三方依赖;非 Windows 平台自动降级为 no-op。
|
|
16
13
|
|
|
17
14
|
## 配置
|
|
@@ -22,13 +19,18 @@
|
|
|
22
19
|
|---|---|---|
|
|
23
20
|
| `enabled` | `true` | 总开关 |
|
|
24
21
|
| `title` | `DSH 任务完成` | 完成通知的标题 |
|
|
25
|
-
| `bodyTemplate` | `{session} 回合已完成` | 完成通知正文,`{session}`
|
|
22
|
+
| `bodyTemplate` | `{session} 回合已完成` | 完成通知正文,`{session}` 替换为会话标题(或 DSH),`{id}` 替换为短 id |
|
|
26
23
|
| `minRunMs` | `0` | 运行时长低于该值(毫秒)不弹完成通知,用来过滤秒回的短回合 |
|
|
27
24
|
| `notifyOnQuestion` | `true` | 是否弹提问通知 |
|
|
28
25
|
| `questionTitle` | `DSH 有问题问你` | 提问通知的标题 |
|
|
29
26
|
|
|
27
|
+
## 内存占用
|
|
28
|
+
|
|
29
|
+
插件在 DSH 进程内的常驻状态只有两个有界 Map(会话标题缓存上限 256 条、会话运行时长表随 idle/移除即清),会话移除时主动清理,不随运行时长增长;每次通知的 PowerShell 为 ~0.3 秒短命进程,跑完即释放,不常驻。
|
|
30
|
+
|
|
30
31
|
## 已知限制
|
|
31
32
|
|
|
32
33
|
- Windows「专注助手」或通知静默时段会吞掉 toast。
|
|
33
34
|
- 多个会话同时结束会各弹一条,Windows 可能将它们折叠。
|
|
34
|
-
-
|
|
35
|
+
- 会话标题取不到时(如标题服务尚未生成),通知正文用「DSH」代替,不显示原始会话 id。
|
|
36
|
+
- 点击通知要求 DSH 已安装桌面版(exe 存在);纯 CLI/web 版无法被唤起。
|
package/index.js
CHANGED
|
@@ -3,28 +3,25 @@
|
|
|
3
3
|
* turn and returns to idle. Listens to the global `api-session/status` event
|
|
4
4
|
* and spawns Windows PowerShell to render a WinRT toast; no third-party
|
|
5
5
|
* dependencies. Non-Windows platforms are a no-op.
|
|
6
|
-
* @module
|
|
6
|
+
* @module dsh-windows-notifier
|
|
7
7
|
*/
|
|
8
8
|
import { spawn } from 'node:child_process'
|
|
9
9
|
import { existsSync, statSync } from 'node:fs'
|
|
10
10
|
import { dirname, join } from 'node:path'
|
|
11
11
|
import { fileURLToPath } from 'node:url'
|
|
12
12
|
|
|
13
|
+
/** App name shown in the toast header; also the Start Menu shortcut name. */
|
|
14
|
+
const NOTIFIER_NAME = 'DSH Notifier'
|
|
15
|
+
|
|
13
16
|
/** AppUserModelId registered once so toast notifications have a valid source. */
|
|
14
17
|
const AUMID = 'DSHNotifier'
|
|
15
18
|
|
|
16
|
-
/** App name shown in the toast header; also the Start Menu shortcut name. */
|
|
17
|
-
const NOTIFIER_NAME = 'DeepSeek Harness'
|
|
18
|
-
|
|
19
19
|
/** Protocol URI a toast click activates; routed through the activation script. */
|
|
20
20
|
const ACTIVATE_URI = 'dsh-windows-notify://open'
|
|
21
21
|
|
|
22
22
|
/** Bundle directory holding toast-activate.ps1 / .vbs. */
|
|
23
23
|
const BUNDLE_DIR = dirname(fileURLToPath(import.meta.url))
|
|
24
24
|
|
|
25
|
-
/** URI the DSH desktop app registers for itself; the activation script opens it. */
|
|
26
|
-
const APP_LAUNCH_URI = 'dsh://open'
|
|
27
|
-
|
|
28
25
|
const DEFAULTS = {
|
|
29
26
|
enabled: true,
|
|
30
27
|
title: 'DSH 任务完成',
|
|
@@ -83,6 +80,15 @@ function runPowerShell(script) {
|
|
|
83
80
|
child.unref()
|
|
84
81
|
}
|
|
85
82
|
|
|
83
|
+
/** Stat a path without throwing. */
|
|
84
|
+
function statSyncSafe(p) {
|
|
85
|
+
try {
|
|
86
|
+
return statSync(p).isFile()
|
|
87
|
+
} catch {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
86
92
|
/**
|
|
87
93
|
* One-time activation setup, run when the plugin loads: registers the AUMID
|
|
88
94
|
* through a Start Menu shortcut (the only registration Windows honors for
|
|
@@ -96,10 +102,16 @@ function ensureAumid() {
|
|
|
96
102
|
const activateVbs = join(BUNDLE_DIR, 'toast-activate.vbs')
|
|
97
103
|
if (!statSyncSafe(activatePs) || !statSyncSafe(activateVbs)) return
|
|
98
104
|
|
|
99
|
-
const
|
|
100
|
-
const
|
|
105
|
+
const programsDir = join(process.env.APPDATA || '', 'Microsoft', 'Windows', 'Start Menu', 'Programs')
|
|
106
|
+
const lnkPath = join(programsDir, `${NOTIFIER_NAME}.lnk`)
|
|
107
|
+
// Remove shortcuts from earlier names so only the current one remains.
|
|
108
|
+
const oldLnkPaths = [
|
|
109
|
+
join(programsDir, 'dsh-windows-notify.lnk'),
|
|
110
|
+
join(programsDir, 'DeepSeek Harness.lnk'),
|
|
111
|
+
]
|
|
101
112
|
// Already registered on a previous run: skip the PowerShell spawn entirely.
|
|
102
113
|
if (existsSync(lnkPath)) return
|
|
114
|
+
|
|
103
115
|
const installDir = dirname(process.execPath || '')
|
|
104
116
|
const iconCandidates = [
|
|
105
117
|
join(installDir, 'resources', 'tray.ico'),
|
|
@@ -109,10 +121,7 @@ function ensureAumid() {
|
|
|
109
121
|
|
|
110
122
|
const script = [
|
|
111
123
|
`$lnk = '${psSingleQuote(lnkPath)}'`,
|
|
112
|
-
`if (Test-Path -LiteralPath $
|
|
113
|
-
// Remove the previous shortcut name so only the new one remains.
|
|
114
|
-
`$oldLnk = '${psSingleQuote(oldLnkPath)}'`,
|
|
115
|
-
`if (Test-Path -LiteralPath $oldLnk) { Remove-Item -LiteralPath $oldLnk -Force }`,
|
|
124
|
+
...oldLnkPaths.map(p => `if (Test-Path -LiteralPath '${psSingleQuote(p)}') { Remove-Item -LiteralPath '${psSingleQuote(p)}' -Force }`),
|
|
116
125
|
`$ws = New-Object -ComObject WScript.Shell`,
|
|
117
126
|
`$sc = $ws.CreateShortcut($lnk)`,
|
|
118
127
|
`$sc.TargetPath = "$env:WINDIR\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"`,
|
|
@@ -180,15 +189,6 @@ function ensureAumid() {
|
|
|
180
189
|
runPowerShell(script)
|
|
181
190
|
}
|
|
182
191
|
|
|
183
|
-
/** Stat a path without throwing. */
|
|
184
|
-
function statSyncSafe(p) {
|
|
185
|
-
try {
|
|
186
|
-
return statSync(p).isFile()
|
|
187
|
-
} catch {
|
|
188
|
-
return false
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
192
|
function shortSession(sessionId) {
|
|
193
193
|
const value = String(sessionId)
|
|
194
194
|
return value.length > 12 ? value.slice(-8) : value
|
package/package.json
CHANGED
package/toast-activate.ps1
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
# toast-activate.ps1 — dsh-windows-notify 通知点击激活处理器
|
|
2
|
-
# 点击 Windows
|
|
2
|
+
# 点击 Windows 通知时被调用:启动并聚焦 DSH 主窗口。
|
|
3
|
+
# 直接启动 DSH 可执行文件而不走 dsh://open 协议——协议激活会回到本脚本,
|
|
4
|
+
# DSH 未运行时形成无限进程递归(黑框闪烁且应用不启动)。
|
|
3
5
|
param([string]$Uri)
|
|
4
6
|
try {
|
|
5
|
-
|
|
7
|
+
# 从 DSH 自注册的协议命令里解析出应用 exe 路径。
|
|
8
|
+
$cmd = (Get-ItemProperty 'HKCU:\Software\Classes\dsh\shell\open\command' -ErrorAction SilentlyContinue).'(default)'
|
|
9
|
+
if ($cmd -match '"([^"]+DeepSeek Harness\.exe)"') {
|
|
10
|
+
Start-Process $matches[1]
|
|
11
|
+
} else {
|
|
12
|
+
Start-Process 'dsh://open'
|
|
13
|
+
}
|
|
6
14
|
} catch { }
|
|
7
15
|
exit 0
|