dsh-notify-say 0.4.68 → 0.4.71
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/CHANGELOG.md +8 -0
- package/dsh-notify.ps1 +18 -1
- package/lib/client.js +121 -20
- package/lib/config-schema.js +16 -3
- package/lib/index.js +211 -14
- package/package.json +1 -1
- package/test/stub-child-process.mjs +51 -43
- package/test/toast-title-jump-rule.test.mjs +43 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
> 本文件由 `tools/release-build.ps1` 从开发提交自动生成,**请勿手工编辑**。
|
|
4
4
|
> 只列面向使用者的变更(新增功能与修复),不含内部维护提交。
|
|
5
5
|
|
|
6
|
+
## v0.4.71 — 2026-10-19
|
|
7
|
+
|
|
8
|
+
- feat(jump): v0.4.71 —— Toast 精准跳转(点哪个跳哪个)+ 前台也能跳
|
|
9
|
+
|
|
10
|
+
## v0.4.69 — 2026-10-19
|
|
11
|
+
|
|
12
|
+
- feat(notify): v0.4.69 —— 三级通知语义,max-tokens 不再静默
|
|
13
|
+
|
|
6
14
|
## v0.4.68 — 2026-10-19
|
|
7
15
|
|
|
8
16
|
- fix(notify): v0.4.68 —— error 在 turn/end 当场播报,不等 idle 边沿
|
package/dsh-notify.ps1
CHANGED
|
@@ -61,6 +61,11 @@ param(
|
|
|
61
61
|
# 为什么需要:日志会写进 %TEMP%,用户提 Issue 时经常直接上传。
|
|
62
62
|
# 标题与正文可能含项目名、人名,对诊断「为什么不响」却没帮助。
|
|
63
63
|
[ValidateSet('info', 'debug')]
|
|
64
|
+
# v0.4.70:会话 id。传了它且插件已完成协议注册时,Toast 的 launch 会写成
|
|
65
|
+
# dshnotify://jump?session=<id>
|
|
66
|
+
# 这样点 Toast 能**精确**跳到对应会话(多会话时不会跳错)。
|
|
67
|
+
# 不传(或插件协议没注册成功)时仍用 dsh://open,行为与以前一致。
|
|
68
|
+
[string]$SessionId = '',
|
|
64
69
|
[string]$LogLevel = 'info',
|
|
65
70
|
# v0.4.16:数字增益倍数(1.0 = 原样;2.0 = 放大一倍)。
|
|
66
71
|
#
|
|
@@ -338,7 +343,19 @@ if ($SoundOnly -or $Preview) {
|
|
|
338
343
|
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
|
|
339
344
|
$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
|
|
340
345
|
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
|
341
|
-
|
|
346
|
+
# v0.4.70:launch 按「是否拿到会话 id」决定。
|
|
347
|
+
#
|
|
348
|
+
# 为什么用自有协议:dsh://open 是 DSH 本体硬编码的精确匹配,**加参数连窗口都不拉**。
|
|
349
|
+
# dshnotify://jump?session=<id> 由插件的 jump-handler.ps1 处理,能精确识别会话;
|
|
350
|
+
# 它内部再调 dsh://open 复用官方唤窗,所以窗口该起还是会起。
|
|
351
|
+
#
|
|
352
|
+
# 会话 id 白名单校验:只接受字母数字/下划线/连字符,杜绝把怪字符拼进 XML。
|
|
353
|
+
$toastLaunch = 'dsh://open'
|
|
354
|
+
if ($SessionId -and ($SessionId -match '^[A-Za-z0-9_-]{4,128}$')) {
|
|
355
|
+
$toastLaunch = 'dshnotify://jump?session=' + $SessionId
|
|
356
|
+
}
|
|
357
|
+
$launchXml = (& $xmlEscape $toastLaunch)
|
|
358
|
+
$xml.LoadXml("<toast activationType=`"protocol`" launch=`"$launchXml`"><visual><binding template=`"ToastGeneric`"><text>$titleXml</text><text>$bodyXml</text>$detailXml</binding></visual></toast>")
|
|
342
359
|
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
|
343
360
|
# 2026-09-25 样式统一:改用官方壳注册的 AUMID(Get-StartApps 实证 com.deepseek.dsh
|
|
344
361
|
# 注册为 "DeepSeek Harness")→ 来源名与角标自动随壳;失败回退借用身份,保证通知不丢。
|
package/lib/client.js
CHANGED
|
@@ -73,6 +73,37 @@ window.__ModuleLoader__.load({
|
|
|
73
73
|
* 但没有任何单元测试覆盖到(因为两端各自都"看起来对")。
|
|
74
74
|
* 已加 C27 测试锁住返回形状。
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* 读「Toast 点击」写入的待跳转会话(v0.4.70 精准跳转)。
|
|
78
|
+
*
|
|
79
|
+
* ## 与 consumeLastSession 的分工
|
|
80
|
+
*
|
|
81
|
+
* consumeLastSession:读「最近播报队列」,**猜**是哪个会话 ——
|
|
82
|
+
* 多会话同时有通知时必然猜错(只能取最早的)。
|
|
83
|
+
* fetchPendingJump :读「用户点的那个 Toast 自带的 session id」—— **精确**。
|
|
84
|
+
*
|
|
85
|
+
* 所以先试精确的,没有再退回猜的(保持旧行为)。
|
|
86
|
+
*
|
|
87
|
+
* @returns {Promise<{sessionId:string,at:number}|null>}
|
|
88
|
+
*/
|
|
89
|
+
function fetchPendingJump() {
|
|
90
|
+
try {
|
|
91
|
+
if (typeof fetch !== 'function') return Promise.resolve(null)
|
|
92
|
+
return fetch(baseUrl() + '/pending-jump', {
|
|
93
|
+
method: 'GET',
|
|
94
|
+
headers: { 'cache-control': 'no-store' },
|
|
95
|
+
credentials: 'same-origin',
|
|
96
|
+
}).then(function (r) {
|
|
97
|
+
if (r.status === 204) return null
|
|
98
|
+
if (!r.ok) return null
|
|
99
|
+
return r.json().then(function (o) {
|
|
100
|
+
if (!o || !o.sessionId) return null
|
|
101
|
+
return { sessionId: String(o.sessionId), at: Number(o.at) || 0 }
|
|
102
|
+
})
|
|
103
|
+
}).catch(function () { return null })
|
|
104
|
+
} catch (e) { return Promise.resolve(null) }
|
|
105
|
+
}
|
|
106
|
+
|
|
76
107
|
function consumeLastSession() {
|
|
77
108
|
// ⚠️ 必须是 POST + JSON:服务端把它当写操作(会清除信号),
|
|
78
109
|
// 而 http-guard 对写操作要求 JSON content-type —— 用 GET 会收到 403,
|
|
@@ -1757,16 +1788,18 @@ window.__ModuleLoader__.load({
|
|
|
1757
1788
|
// 所以默认改成"跳最早错过的":你多半仍停在它上面,对它 openSession
|
|
1758
1789
|
// 等于无操作,于是不打断;而你最先错过的那个正好被带过去。
|
|
1759
1790
|
var JUMP_RULES = [
|
|
1791
|
+
['clicked', '点哪个就跳哪个(推荐)'],
|
|
1760
1792
|
['earliest', '跳到最早错过的那个'],
|
|
1761
1793
|
['latest', '跳到最后一个'],
|
|
1762
1794
|
['none', '都不跳,靠侧栏绿点自己看'],
|
|
1763
1795
|
]
|
|
1764
1796
|
var RULE_HINT = {
|
|
1765
|
-
|
|
1797
|
+
clicked: '推荐。你点哪个 Toast 就跳到哪个会话(精确,不靠猜)。没点 Toast 直接切回来时,退回「最早错过的」那条。',
|
|
1798
|
+
earliest: '不点 Toast、直接切回来时,跳到最早错过的那个。',
|
|
1766
1799
|
latest: '只在最后完成的那条会话上落脚。',
|
|
1767
1800
|
none: '多个会话都完成时不跳,侧栏绿点一个个自己点。单会话时照常跳。',
|
|
1768
1801
|
}
|
|
1769
|
-
var curRule = typeof v.multiJumpRule === 'string' ? v.multiJumpRule : '
|
|
1802
|
+
var curRule = typeof v.multiJumpRule === 'string' ? v.multiJumpRule : 'clicked'
|
|
1770
1803
|
rows.push(h('div', { key: 'jumpRule', style: S.row },
|
|
1771
1804
|
h('span', { style: S.label }, '多个会话完成时'),
|
|
1772
1805
|
h('select', {
|
|
@@ -2579,7 +2612,9 @@ window.__ModuleLoader__.load({
|
|
|
2579
2612
|
if (rule === 'none') return null
|
|
2580
2613
|
var sorted = list.slice().sort(function (a, b) { return a.at - b.at })
|
|
2581
2614
|
if (rule === 'latest') return sorted[sorted.length - 1]
|
|
2582
|
-
|
|
2615
|
+
// clicked:精确命中在更上层(pendingJump)已处理;走到这里说明用户没点 Toast,
|
|
2616
|
+
// 那就退回「最早错过的」——至少带他去看一条,而不是什么都不做。
|
|
2617
|
+
return sorted[0]
|
|
2583
2618
|
}
|
|
2584
2619
|
|
|
2585
2620
|
/**
|
|
@@ -2794,32 +2829,94 @@ window.__ModuleLoader__.load({
|
|
|
2794
2829
|
|
|
2795
2830
|
jumpEnabled().then(function (en) {
|
|
2796
2831
|
if (!en) { busy = false; return null }
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
leave.reset()
|
|
2813
|
-
openSession(ctx, target.sessionId)
|
|
2832
|
+
|
|
2833
|
+
// ⚠️ v0.4.70:**先试精确跳转** —— 用户点的是哪个 Toast 就跳哪个。
|
|
2834
|
+
// 命中就直接跳,不再走「按队列猜最早那条」的旧路径。
|
|
2835
|
+
return fetchPendingJump().then(function (pj) {
|
|
2836
|
+
if (pj && pj.sessionId) {
|
|
2837
|
+
// 过期保护:超过 120 秒的点击不再跳(避免久等后切窗口突然跳走)
|
|
2838
|
+
var age = Date.now() - Number(pj.at || 0)
|
|
2839
|
+
if (isFinite(age) && age >= 0 && age <= 120000) {
|
|
2840
|
+
busy = false
|
|
2841
|
+
leave.reset()
|
|
2842
|
+
if (typeof openSession === 'function') {
|
|
2843
|
+
openSession(ctx, pj.sessionId)
|
|
2844
|
+
return null
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2814
2847
|
}
|
|
2848
|
+
|
|
2849
|
+
// 没命中精确记录 → 退回旧路径(按最近播报队列猜)。
|
|
2850
|
+
// 单会话时两条路径结果相同;多会话时旧的会取最早的。
|
|
2851
|
+
return consumeLastSession().then(function (list) {
|
|
2852
|
+
busy = false
|
|
2853
|
+
if (!list || !list.length) return
|
|
2854
|
+
// 先按规则挑一个(多会话时才有区别;单会话三种规则都挑它)。
|
|
2855
|
+
var target = pickJumpTarget(list, en.multiJumpRule)
|
|
2856
|
+
if (!target) return
|
|
2857
|
+
if (shouldJump({
|
|
2858
|
+
jumpWhenBackground: en.jumpWhenBackground,
|
|
2859
|
+
jumpWhenForeground: en.jumpWhenForeground,
|
|
2860
|
+
consumed: false,
|
|
2861
|
+
sessionId: target.sessionId,
|
|
2862
|
+
notifiedAt: Number(target.at),
|
|
2863
|
+
leftAt: leave.leftAt(),
|
|
2864
|
+
returnedAt: leave.returnedAt(),
|
|
2865
|
+
})) {
|
|
2866
|
+
leave.reset()
|
|
2867
|
+
openSession(ctx, target.sessionId)
|
|
2868
|
+
}
|
|
2869
|
+
})
|
|
2815
2870
|
})
|
|
2816
2871
|
}).catch(function () { busy = false; startForegroundPoll(ctx) })
|
|
2817
2872
|
.then(function () { startForegroundPoll(ctx) })
|
|
2818
2873
|
}
|
|
2819
2874
|
|
|
2875
|
+
/**
|
|
2876
|
+
* 读一次「待跳转」并执行(v0.4.71)。
|
|
2877
|
+
*
|
|
2878
|
+
* 与 onVisibility 里的逻辑同源,但**不依赖可见性变化** ——
|
|
2879
|
+
* 前台点 Toast 时窗口本来就不隐藏,visibilitychange 不会触发。
|
|
2880
|
+
*
|
|
2881
|
+
* 防误跳:pending-jump 只有「用户真的点了 Toast」才会写入;
|
|
2882
|
+
* 服务端读取即清空;超过 120 秒不跳;800ms 节流。
|
|
2883
|
+
*/
|
|
2884
|
+
var lastTopJumpCheck = 0
|
|
2885
|
+
function tryTopJump() {
|
|
2886
|
+
try {
|
|
2887
|
+
var now = Date.now()
|
|
2888
|
+
if (now - lastTopJumpCheck < 800) return
|
|
2889
|
+
lastTopJumpCheck = now
|
|
2890
|
+
jumpEnabled().then(function (en) {
|
|
2891
|
+
if (!en) return null
|
|
2892
|
+
return fetchPendingJump().then(function (pj) {
|
|
2893
|
+
if (!pj || !pj.sessionId) return null
|
|
2894
|
+
var age = Date.now() - Number(pj.at || 0)
|
|
2895
|
+
if (!isFinite(age) || age < 0 || age > 120000) return null
|
|
2896
|
+
leave.reset()
|
|
2897
|
+
if (typeof openSession === "function") openSession(ctx, pj.sessionId)
|
|
2898
|
+
return null
|
|
2899
|
+
})
|
|
2900
|
+
}).catch(function () { /* 精确跳转失败不影响其它功能 */ })
|
|
2901
|
+
} catch (e) { /* 同上 */ }
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2820
2904
|
try {
|
|
2821
2905
|
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
2822
2906
|
document.addEventListener('visibilitychange', onVisibility)
|
|
2907
|
+
// v0.4.71:**前台点 Toast 也要跳**。
|
|
2908
|
+
//
|
|
2909
|
+
// visibilitychange 只在「隐藏↔可见」时触发;窗口一直在前台时
|
|
2910
|
+
// 用户点 Toast 拿不到那个事件,于是跳不过去。补两个监听:
|
|
2911
|
+
// · window focus 窗口获得焦点
|
|
2912
|
+
// · document mousedown 用户点了窗口里任何地方(有些壳不转 focus)
|
|
2913
|
+
// 两者都只读一次 pending-jump,靠它「只有点 Toast 才有」来防误跳。
|
|
2914
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
2915
|
+
window.addEventListener('focus', tryTopJump)
|
|
2916
|
+
}
|
|
2917
|
+
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
2918
|
+
document.addEventListener('mousedown', tryTopJump, { passive: true })
|
|
2919
|
+
}
|
|
2823
2920
|
document.addEventListener(CONFIG_CHANGED_EVENT, onConfigChanged)
|
|
2824
2921
|
}
|
|
2825
2922
|
} catch (e) { /* 拿不到 document 就算了 */ }
|
|
@@ -2839,6 +2936,10 @@ window.__ModuleLoader__.load({
|
|
|
2839
2936
|
if (typeof document !== 'undefined' && document.removeEventListener) {
|
|
2840
2937
|
document.removeEventListener('visibilitychange', onVisibility)
|
|
2841
2938
|
document.removeEventListener(CONFIG_CHANGED_EVENT, onConfigChanged)
|
|
2939
|
+
document.removeEventListener('mousedown', tryTopJump)
|
|
2940
|
+
}
|
|
2941
|
+
if (typeof window !== 'undefined' && window.removeEventListener) {
|
|
2942
|
+
window.removeEventListener('focus', tryTopJump)
|
|
2842
2943
|
}
|
|
2843
2944
|
} catch (e) { /* ignore */ }
|
|
2844
2945
|
}
|
package/lib/config-schema.js
CHANGED
|
@@ -109,7 +109,16 @@ export const FIELD_DEFAULTS = Object.freeze({
|
|
|
109
109
|
/** v0.4.68:子代理会话出错是否提醒。默认开 —— 完成可以合并,错误不能合并掉。 */
|
|
110
110
|
notifyOnSubagentError: true,
|
|
111
111
|
notifyOnBlocked: true,
|
|
112
|
+
/** v0.4.68:回合因 token 上限中断是否提醒。默认**开** —— 任务没完成,用户需要知道。 */
|
|
113
|
+
notifyOnMaxTokens: true,
|
|
112
114
|
notifyOnAborted: false,
|
|
115
|
+
/**
|
|
116
|
+
* v0.4.70:让 Toast 携带会话 id,点哪个跳哪个(第 4 批)。
|
|
117
|
+
*
|
|
118
|
+
* 默认 **false**:需要在 HKCU 注册 `dshnotify://` 协议,属于对系统的改动,
|
|
119
|
+
* 不强制所有人接受。开启后若注册失败会自动降级回 dsh://open。
|
|
120
|
+
*/
|
|
121
|
+
toastJumpSession: false,
|
|
113
122
|
notifyOnApproval: true,
|
|
114
123
|
notifyOnQuestion: true,
|
|
115
124
|
subagents: false,
|
|
@@ -132,7 +141,7 @@ export const FIELD_DEFAULTS = Object.freeze({
|
|
|
132
141
|
* latest = 最后完成的覆盖先完成的(v0.4.61 及更早的行为)。
|
|
133
142
|
* none = 多个时不跳,靠侧栏绿点自己一个个看。
|
|
134
143
|
*/
|
|
135
|
-
multiJumpRule: '
|
|
144
|
+
multiJumpRule: 'clicked',
|
|
136
145
|
/** TTS 发音人(留空=系统默认)。 */
|
|
137
146
|
ttsVoice: '',
|
|
138
147
|
/** TTS 语速 -10..10。 */
|
|
@@ -202,8 +211,12 @@ export function buildConfig(z) {
|
|
|
202
211
|
.description('子代理会话出错时也提醒(默认开:完成可以合并,错误不能静默)'),
|
|
203
212
|
notifyOnBlocked: z.boolean().default(FIELD_DEFAULTS.notifyOnBlocked)
|
|
204
213
|
.description('回合被拦截时提醒(蜂鸣,不播失败语音)'),
|
|
214
|
+
notifyOnMaxTokens: z.boolean().default(FIELD_DEFAULTS.notifyOnMaxTokens)
|
|
215
|
+
.description('回合因 token 上限中断时提醒(默认开:任务未完成)'),
|
|
205
216
|
notifyOnAborted: z.boolean().default(FIELD_DEFAULTS.notifyOnAborted)
|
|
206
217
|
.description('回合被中止/超长/中断时提醒(默认关闭)'),
|
|
218
|
+
toastJumpSession: z.boolean().default(FIELD_DEFAULTS.toastJumpSession)
|
|
219
|
+
.description('点 Toast 精确跳到对应会话(会注册 dshnotify:// 协议;注册失败自动降级)'),
|
|
207
220
|
notifyOnApproval: z.boolean().default(FIELD_DEFAULTS.notifyOnApproval)
|
|
208
221
|
.description('等待你批准操作时提醒'),
|
|
209
222
|
notifyOnQuestion: z.boolean().default(FIELD_DEFAULTS.notifyOnQuestion)
|
|
@@ -241,9 +254,9 @@ export function buildConfig(z) {
|
|
|
241
254
|
.description('窗口就在眼前时也跳过去(默认关,避免打断你正在看的会话)'),
|
|
242
255
|
// ⚠️ schemastery 没有 z.enum —— 用 union+const(同类写法见 voiceMode)。
|
|
243
256
|
multiJumpRule: z
|
|
244
|
-
.union([z.const('earliest'), z.const('latest'), z.const('none')])
|
|
257
|
+
.union([z.const('clicked'), z.const('earliest'), z.const('latest'), z.const('none')])
|
|
245
258
|
.default(FIELD_DEFAULTS.multiJumpRule)
|
|
246
|
-
.description('多个会话完成时跳哪个:earliest=最早错过的,latest=最后一个,none=都不跳'),
|
|
259
|
+
.description('多个会话完成时跳哪个:clicked=点哪个跳哪个(推荐),earliest=最早错过的,latest=最后一个,none=都不跳'),
|
|
247
260
|
|
|
248
261
|
// ── 开发开关(v0.4.3)─────────────────────────────────────────────────
|
|
249
262
|
// 改代码后自动热重载,省去重启宿主。默认关:生产安装不会重写自己的文件,
|
package/lib/index.js
CHANGED
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
* 主会话重新进入 running(用户已开始新一轮)则取消挂起。
|
|
85
85
|
* 失败一律 fail-visible:判定异常时走主任务分支照常播报,不静默用户。
|
|
86
86
|
*/
|
|
87
|
-
import { spawn } from 'node:child_process';
|
|
87
|
+
import { spawn, execFileSync } from 'node:child_process';
|
|
88
88
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, statSync } from 'node:fs';
|
|
89
89
|
import { fileURLToPath } from 'node:url';
|
|
90
90
|
import { dirname, join } from 'node:path';
|
|
@@ -316,7 +316,7 @@ function normalizeConfig(raw) {
|
|
|
316
316
|
for (const k of ['notifyOnComplete', 'notifyOnError', 'notifyOnBlocked', 'notifyOnAborted',
|
|
317
317
|
'notifyOnApproval', 'notifyOnQuestion', 'voice', 'subagents', 'idleGate',
|
|
318
318
|
// v0.4.68:子代理出错单独开关(完成可以合并,错误不能合并掉)
|
|
319
|
-
'notifyOnSubagentError',
|
|
319
|
+
'notifyOnSubagentError', 'notifyOnMaxTokens', 'toastJumpSession',
|
|
320
320
|
// v0.4.2
|
|
321
321
|
'showToast', 'jumpWhenBackground', 'jumpWhenForeground', 'multiJumpRule',
|
|
322
322
|
// v0.4.3:开发开关
|
|
@@ -689,6 +689,8 @@ export function effectiveForClient(c) {
|
|
|
689
689
|
notifyOnComplete: g.notifyOnComplete,
|
|
690
690
|
notifyOnError: g.notifyOnError,
|
|
691
691
|
notifyOnSubagentError: g.notifyOnSubagentError,
|
|
692
|
+
notifyOnMaxTokens: g.notifyOnMaxTokens,
|
|
693
|
+
toastJumpSession: g.toastJumpSession,
|
|
692
694
|
notifyOnBlocked: g.notifyOnBlocked,
|
|
693
695
|
notifyOnAborted: g.notifyOnAborted,
|
|
694
696
|
notifyOnApproval: g.notifyOnApproval,
|
|
@@ -1079,6 +1081,10 @@ export function apply(ctx, config) {
|
|
|
1079
1081
|
// 播报前现读配置:让 CLI/GUI 改的值立即生效,无需重载宿主。
|
|
1080
1082
|
refreshConfig();
|
|
1081
1083
|
|
|
1084
|
+
// v0.4.70:本条通知对应的会话 id(精准跳转用)。
|
|
1085
|
+
// 只在开关开着且协议已注册时才会被 args 构造器采用;否则降级 dsh://open。
|
|
1086
|
+
const notifySid = session && session.id !== undefined ? String(session.id) : '';
|
|
1087
|
+
|
|
1082
1088
|
// Toast 第三行:项目名(v0.4.62)。
|
|
1083
1089
|
//
|
|
1084
1090
|
// 只在"标题里没包含它"时才给 —— 否则标题已经是「优化0Deepseek…」,
|
|
@@ -1186,7 +1192,7 @@ export function apply(ctx, config) {
|
|
|
1186
1192
|
];
|
|
1187
1193
|
if (vVoice) ttsArgs.push('-VoiceName', vVoice);
|
|
1188
1194
|
// TTS 自己会出声,所以 notify.ps1 只负责弹窗(-NoSound)
|
|
1189
|
-
if (wantToast) spawnNotify(notifyArgs(psKind, title, body, true, false, detail), psKind);
|
|
1195
|
+
if (wantToast) spawnNotify(notifyArgs(psKind, title, body, true, false, detail, notifySid), psKind);
|
|
1190
1196
|
spawnTts(ttsArgs, psKind);
|
|
1191
1197
|
return;
|
|
1192
1198
|
}
|
|
@@ -1205,7 +1211,7 @@ export function apply(ctx, config) {
|
|
|
1205
1211
|
// **不传 -Voice/-Mode**,并且 ps1 侧见到 -SystemSound 就跳过语音池
|
|
1206
1212
|
// (否则 -Kind fail 会先选中 fail 池的 wav,永远走不到系统音效)。
|
|
1207
1213
|
if (wantSound && source === 'system') {
|
|
1208
|
-
const a = baseNotifyArgs(psKind, title, body, false, !wantToast, detail);
|
|
1214
|
+
const a = baseNotifyArgs(psKind, title, body, false, !wantToast, detail, notifySid);
|
|
1209
1215
|
const explicitTone = kindOr(cfg.kindSystemSound, aKind, '');
|
|
1210
1216
|
a.push('-SystemSound', explicitTone || 'auto');
|
|
1211
1217
|
spawnNotify(a);
|
|
@@ -1221,7 +1227,7 @@ export function apply(ctx, config) {
|
|
|
1221
1227
|
const kind = audioKindOf(psKind);
|
|
1222
1228
|
const file = resolveCustomFile(kind, cfg);
|
|
1223
1229
|
if (file) {
|
|
1224
|
-
const a = baseNotifyArgs(psKind, title, body, false, !wantToast, detail);
|
|
1230
|
+
const a = baseNotifyArgs(psKind, title, body, false, !wantToast, detail, notifySid);
|
|
1225
1231
|
a.push('-CustomFile', file);
|
|
1226
1232
|
// v0.4.16:自定义音频的"标准化"是**可选**的。
|
|
1227
1233
|
//
|
|
@@ -1235,7 +1241,7 @@ export function apply(ctx, config) {
|
|
|
1235
1241
|
}
|
|
1236
1242
|
// 没配文件:不要静默无声,退到系统提示音(audio-source 的回退链已算过,
|
|
1237
1243
|
// 但这里再兜一次,防止 effectiveSource 的 hasCustomFile 判断与读取不一致)
|
|
1238
|
-
const a2 = baseNotifyArgs(psKind, title, body, false, !wantToast, detail);
|
|
1244
|
+
const a2 = baseNotifyArgs(psKind, title, body, false, !wantToast, detail, notifySid);
|
|
1239
1245
|
a2.push('-SystemSound', 'auto');
|
|
1240
1246
|
spawnNotify(a2);
|
|
1241
1247
|
return;
|
|
@@ -1244,11 +1250,13 @@ export function apply(ctx, config) {
|
|
|
1244
1250
|
// ── 其余音源(bundled)走 dsh-notify.ps1 ──────────────────────────────
|
|
1245
1251
|
// 第 5 个参数是 soundOnly(v0.4.59)。原来这里传的是 source,
|
|
1246
1252
|
// 而 notifyArgs 只认 4 个参数 —— 那个多传的值一直被静默忽略。
|
|
1247
|
-
spawnNotify(notifyArgs(psKind, title, body, !wantSound, !wantToast, detail), psKind);
|
|
1253
|
+
spawnNotify(notifyArgs(psKind, title, body, !wantSound, !wantToast, detail, notifySid), psKind);
|
|
1248
1254
|
}
|
|
1249
1255
|
|
|
1250
1256
|
/** 只有基础参数的 notify 调用(供 system 音源拼装)。 */
|
|
1251
|
-
function baseNotifyArgs(psKind, title, body, noSound, soundOnly, detail) {
|
|
1257
|
+
function baseNotifyArgs(psKind, title, body, noSound, soundOnly, detail, sessionIdForArgs) {
|
|
1258
|
+
// v0.4.70:只在协议可用时才把会话 id 传给 ps1;否则继续用 dsh://open(降级)。
|
|
1259
|
+
const jumpSid = (cfg.toastJumpSession && jumpProtoState === 'ok' && sessionIdForArgs) ? sessionIdForArgs : '';
|
|
1252
1260
|
const args = [
|
|
1253
1261
|
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File',
|
|
1254
1262
|
SCRIPT_PATH, '-Kind', psKind, '-Title', title, '-Body', body,
|
|
@@ -1265,11 +1273,15 @@ export function apply(ctx, config) {
|
|
|
1265
1273
|
// v0.4.34:把日志级别传给 ps1(它决定要不要把标题/正文写进日志)
|
|
1266
1274
|
args.push('-LogLevel', cfg.logLevel === 'debug' ? 'debug' : 'info');
|
|
1267
1275
|
args.push('-Volume', String(cfg.volume));
|
|
1276
|
+
// v0.4.70:会话 id 传给 ps1,让它写进 Toast 的 launch(精准跳转用)。
|
|
1277
|
+
if (jumpSid) args.push('-SessionId', String(jumpSid));
|
|
1268
1278
|
return args;
|
|
1269
1279
|
}
|
|
1270
1280
|
|
|
1271
1281
|
/** 构造 dsh-notify.ps1 的参数。noSound=true 表示只弹窗不出声。 */
|
|
1272
|
-
function notifyArgs(psKind, title, body, noSound, soundOnly, detail) {
|
|
1282
|
+
function notifyArgs(psKind, title, body, noSound, soundOnly, detail, sessionIdForArgs) {
|
|
1283
|
+
// v0.4.70:只在协议可用时才把会话 id 传给 ps1;否则继续用 dsh://open(降级)。
|
|
1284
|
+
const jumpSid = (cfg.toastJumpSession && jumpProtoState === 'ok' && sessionIdForArgs) ? sessionIdForArgs : '';
|
|
1273
1285
|
const args = [
|
|
1274
1286
|
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File',
|
|
1275
1287
|
SCRIPT_PATH, '-Kind', psKind, '-Title', title, '-Body', body,
|
|
@@ -1377,6 +1389,106 @@ function hasVoiceLine(psKind) {
|
|
|
1377
1389
|
}
|
|
1378
1390
|
}
|
|
1379
1391
|
|
|
1392
|
+
/**
|
|
1393
|
+
* 自定义协议名。Toast 的 launch 用它携带 session id(第 4 批)。
|
|
1394
|
+
*
|
|
1395
|
+
* 为什么不用 dsh:// —— DSH 本体是精确匹配 `dsh://open`,加参数连窗口都不拉。
|
|
1396
|
+
*/
|
|
1397
|
+
const JUMP_PROTOCOL = 'dshnotify';
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* 协议注册状态(进程内缓存,避免每次播报都查注册表)。
|
|
1401
|
+
*
|
|
1402
|
+
* unknown 还没检查过
|
|
1403
|
+
* ok 已注册且指向我们的处理器(可以用 dshnotify://)
|
|
1404
|
+
* failed 注册失败或指向别处(**必须降级到 dsh://open**)
|
|
1405
|
+
* off 开关关闭(用户没启用这个功能)
|
|
1406
|
+
*/
|
|
1407
|
+
let jumpProtoState = 'unknown';
|
|
1408
|
+
|
|
1409
|
+
/** 待跳转的会话(Toast 点击写入,前端读取并消费)。v0.4.70 */
|
|
1410
|
+
let pendingJump = null;
|
|
1411
|
+
|
|
1412
|
+
/**
|
|
1413
|
+
* 注册自定义协议(HKCU,无需管理员)。
|
|
1414
|
+
*
|
|
1415
|
+
* 幂等:已存在且指向正确就直接标记 ok;指向别处则覆盖(那是我们的协议名)。
|
|
1416
|
+
*
|
|
1417
|
+
* @returns {boolean} 注册成功且可用
|
|
1418
|
+
*/
|
|
1419
|
+
function registerJumpProtocol() {
|
|
1420
|
+
try {
|
|
1421
|
+
const handler = join(PLUGIN_ROOT, 'jump-handler.ps1');
|
|
1422
|
+
if (!existsSync(handler)) { jumpProtoState = 'failed'; return false; }
|
|
1423
|
+
|
|
1424
|
+
// PowerShell 路径与主脚本一致(POWERSHELL_EXE 已算好)
|
|
1425
|
+
const cmd = `"${POWERSHELL_EXE}" -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File "${handler}" "%1"`;
|
|
1426
|
+
|
|
1427
|
+
// 用 PowerShell 写注册表:避免引入额外依赖,且引号处理更稳。
|
|
1428
|
+
const ps = [
|
|
1429
|
+
`$k = 'HKCU:\\Software\\Classes\\' + '${JUMP_PROTOCOL}';`,
|
|
1430
|
+
'if (-not (Test-Path $k)) { New-Item -Path $k -Force | Out-Null }',
|
|
1431
|
+
'Set-ItemProperty -Path $k -Name "(default)" -Value "URL:DSH Notify Jump" -Force;',
|
|
1432
|
+
'Set-ItemProperty -Path $k -Name "URL Protocol" -Value "" -Force;',
|
|
1433
|
+
`$c = Join-Path $k 'shell\\open\\command';`,
|
|
1434
|
+
'if (-not (Test-Path $c)) { New-Item -Path $c -Force | Out-Null }',
|
|
1435
|
+
'Set-ItemProperty -Path $c -Name "(default)" -Value $env:DSH_JUMP_CMD -Force;',
|
|
1436
|
+
].join(' ');
|
|
1437
|
+
|
|
1438
|
+
execFileSync(POWERSHELL_EXE, [
|
|
1439
|
+
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden',
|
|
1440
|
+
'-Command', ps,
|
|
1441
|
+
], {
|
|
1442
|
+
stdio: 'ignore',
|
|
1443
|
+
windowsHide: true,
|
|
1444
|
+
env: { ...process.env, DSH_JUMP_CMD: cmd },
|
|
1445
|
+
timeout: 15000,
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
jumpProtoState = 'ok';
|
|
1449
|
+
appendNotifyLog(`[jump-proto] registered ${JUMP_PROTOCOL}:// -> jump-handler.ps1`);
|
|
1450
|
+
return true;
|
|
1451
|
+
} catch (e) {
|
|
1452
|
+
jumpProtoState = 'failed';
|
|
1453
|
+
appendNotifyLog(`[jump-proto] register FAILED: ` + String((e && e.message) || e).slice(0, 200));
|
|
1454
|
+
return false;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* 注销自定义协议(开关关闭 / 插件卸载时调用)。
|
|
1460
|
+
*
|
|
1461
|
+
* 只删自己那个键,绝不动别人的;删不掉也只记日志(不阻塞卸载)。
|
|
1462
|
+
*/
|
|
1463
|
+
function unregisterJumpProtocol() {
|
|
1464
|
+
try {
|
|
1465
|
+
const ps = `$k = 'HKCU:\\Software\\Classes\\${JUMP_PROTOCOL}'; if (Test-Path $k) { Remove-Item $k -Recurse -Force }`;
|
|
1466
|
+
execFileSync(POWERSHELL_EXE, [
|
|
1467
|
+
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden',
|
|
1468
|
+
'-Command', ps,
|
|
1469
|
+
], { stdio: 'ignore', windowsHide: true, timeout: 10000 });
|
|
1470
|
+
jumpProtoState = 'off';
|
|
1471
|
+
appendNotifyLog(`[jump-proto] unregistered ${JUMP_PROTOCOL}://`);
|
|
1472
|
+
} catch (e) {
|
|
1473
|
+
appendNotifyLog(`[jump-proto] unregister failed: ` + String((e && e.message) || e).slice(0, 120));
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
/**
|
|
1478
|
+
* 按当前开关同步协议状态(开着就注册,关了就注销)。
|
|
1479
|
+
*
|
|
1480
|
+
* @returns {boolean} 是否可用(决定 Toast 用哪种 launch)
|
|
1481
|
+
*/
|
|
1482
|
+
function syncJumpProtocol() {
|
|
1483
|
+
if (!cfg.toastJumpSession) {
|
|
1484
|
+
if (jumpProtoState === 'ok') unregisterJumpProtocol();
|
|
1485
|
+
jumpProtoState = 'off';
|
|
1486
|
+
return false;
|
|
1487
|
+
}
|
|
1488
|
+
if (jumpProtoState === 'ok') return true;
|
|
1489
|
+
return registerJumpProtocol();
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1380
1492
|
function svc(name) {
|
|
1381
1493
|
try { return ctx.get(name, false); } catch { return undefined; }
|
|
1382
1494
|
}
|
|
@@ -1876,10 +1988,18 @@ function hasVoiceLine(psKind) {
|
|
|
1876
1988
|
// 实测:近 20 天 932 个会话中 "kind":"blocked" 命中 0 次,属极罕见路径。
|
|
1877
1989
|
gate = cfg.notifyOnBlocked; psKind = 'chime';
|
|
1878
1990
|
title = 'DSH 回合被阻塞'; body = '回合已阻塞,可能需要你介入处理';
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1991
|
+
} else if (kind === 'max-tokens') {
|
|
1992
|
+
// ⚠️ v0.4.68(第 3 批 3.3):max-tokens **单独一档,默认提醒**。
|
|
1993
|
+
// 原先它和 aborted/interrupted/forked 一起走 notifyOnAborted(默认关),
|
|
1994
|
+
// 于是「Agent 没干完就没 token 了」被完全静默 —— 用户以为它在正常跑。
|
|
1995
|
+
// 数据:2195 个会话里出现 5 次,罕见但每次都是静默停摆。
|
|
1996
|
+
gate = cfg.notifyOnMaxTokens; psKind = 'chime';
|
|
1997
|
+
title = 'DSH 回合因长度上限中断';
|
|
1998
|
+
body = '这一轮没跑完就撞到 token 上限了,任务可能没完成';
|
|
1999
|
+
} else {
|
|
2000
|
+
// aborted / interrupted / forked:用户主动取消或会话分叉,默认静默。
|
|
2001
|
+
gate = cfg.notifyOnAborted; psKind = 'chime';
|
|
2002
|
+
title = 'DSH 回合提前结束'; body = '回合结束原因:' + (kind || 'unknown');
|
|
1883
2003
|
}
|
|
1884
2004
|
// ── Toast 标题改用会话标题(v0.4.62)─────────────────────────────────
|
|
1885
2005
|
//
|
|
@@ -1898,7 +2018,8 @@ function hasVoiceLine(psKind) {
|
|
|
1898
2018
|
const gateKey = kind === 'completed' ? 'notifyOnComplete'
|
|
1899
2019
|
: kind === 'error' ? 'notifyOnError'
|
|
1900
2020
|
: kind === 'blocked' ? 'notifyOnBlocked'
|
|
1901
|
-
: '
|
|
2021
|
+
: kind === 'max-tokens' ? 'notifyOnMaxTokens'
|
|
2022
|
+
: 'notifyOnAborted';
|
|
1902
2023
|
skipLog('switch-off', kind, session, `${gateKey}=false`);
|
|
1903
2024
|
return;
|
|
1904
2025
|
}
|
|
@@ -2014,6 +2135,18 @@ function hasVoiceLine(psKind) {
|
|
|
2014
2135
|
+ `question=${cfg.notifyOnQuestion} voice=${cfg.voice}/${cfg.voiceMode} debounce=${Math.round(cfg.debounceMs / 1000)}s `
|
|
2015
2136
|
+ `idleGate=${cfg.idleGate} idleGateTimeout=${Math.round(cfg.idleGateTimeoutMs / 1000)}s)`);
|
|
2016
2137
|
|
|
2138
|
+
// ── 精准跳转:启动时同步协议注册状态(v0.4.70)────────────────────────
|
|
2139
|
+
//
|
|
2140
|
+
// 开关开着就注册 dshnotify://(HKCU,无需管理员);关着就确保已注销。
|
|
2141
|
+
// 注册失败会被降级为 dsh://open —— 「点了没反应」比「跳不到会话」更糟。
|
|
2142
|
+
try {
|
|
2143
|
+
const okProto = syncJumpProtocol();
|
|
2144
|
+
appendNotifyLog(`[jump-proto] state=${jumpProtoState} usable=${okProto}`);
|
|
2145
|
+
} catch (e) {
|
|
2146
|
+
jumpProtoState = 'failed';
|
|
2147
|
+
appendNotifyLog('[jump-proto] sync failed: ' + String((e && e.message) || e));
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2017
2150
|
// ── 会话事件流:turn/end 记 reason + approval/asked、approval/decided 审计对 + 提问 ──
|
|
2018
2151
|
ctx.on('session/event', (session, event) => {
|
|
2019
2152
|
// v0.4.36:记一次"事件到达"。
|
|
@@ -2226,6 +2359,8 @@ function hasVoiceLine(psKind) {
|
|
|
2226
2359
|
pendingDone.clear();
|
|
2227
2360
|
prevStatus.clear();
|
|
2228
2361
|
lastTurnEnd.clear();
|
|
2362
|
+
// v0.4.70:卸载时注销自定义协议,不在注册表留垃圾。
|
|
2363
|
+
try { if (jumpProtoState === 'ok') unregisterJumpProtocol(); } catch { /* 卸载期失败不影响退出 */ }
|
|
2229
2364
|
// v0.4.63:长轮询的挂起响应也要结束掉。不做的后果是热重载后
|
|
2230
2365
|
// 旧连接永远等不到响应,客户端不会再发新的 /wait(它以为还在等)。
|
|
2231
2366
|
try { bridge.disposeAllWaiters(); } catch { /* 卸载期失败不影响退出 */ }
|
|
@@ -2311,11 +2446,73 @@ function hasVoiceLine(psKind) {
|
|
|
2311
2446
|
|| head === 'consume'
|
|
2312
2447
|
// v0.4.63:/ack 只摘一条(前台跳转后确认),同样是写操作
|
|
2313
2448
|
|| head === 'ack'
|
|
2449
|
+
// v0.4.70:Toast 点击写入待跳转(写操作)
|
|
2450
|
+
|| head === 'pending-jump'
|
|
2314
2451
|
|| head === 'diagnostics'
|
|
2315
2452
|
|| (head === 'voicepacks' && (/\/install\b/.test(pathname) || /\/uninstall\b/.test(pathname)))
|
|
2316
2453
|
// v0.4.57:一次性自重载会 dispose 当前实例并重新求值模块,
|
|
2317
2454
|
// 是不可逆副作用,按写操作处理。
|
|
2318
2455
|
|| head === 'reload';
|
|
2456
|
+
// ── 精准跳转:Toast 点击的待跳转会话(v0.4.70)────────────────
|
|
2457
|
+
//
|
|
2458
|
+
// jump-handler.ps1 收到 dshnotify://jump?session=xxx 后 POST 到这里,
|
|
2459
|
+
// 前端在窗口可见时 GET 并消费。
|
|
2460
|
+
//
|
|
2461
|
+
// 为什么需要它:点 Toast 走自有协议能**精确知道**是哪个会话,
|
|
2462
|
+
// 而 dsh://open 无法携带参数(DSH 本体硬编码精确匹配)。
|
|
2463
|
+
if (head === 'pending-jump') {
|
|
2464
|
+
const isPost = String((req && req.method) || 'GET').toUpperCase() === 'POST';
|
|
2465
|
+
try {
|
|
2466
|
+
if (isPost) {
|
|
2467
|
+
// 读 body(小 JSON)
|
|
2468
|
+
let rawBody = '';
|
|
2469
|
+
req.on('data', (c) => { if (rawBody.length < 4096) rawBody += c; });
|
|
2470
|
+
req.on('end', () => {
|
|
2471
|
+
try {
|
|
2472
|
+
const o = JSON.parse(rawBody || '{}');
|
|
2473
|
+
const sid = String(o.sessionId || '');
|
|
2474
|
+
// 白名单校验:只接受像会话 id 的字符串
|
|
2475
|
+
if (/^[A-Za-z0-9_-]{4,128}$/.test(sid)) {
|
|
2476
|
+
pendingJump = { sessionId: sid, at: Date.now() };
|
|
2477
|
+
appendNotifyLog(`[jump-click] session=${sid}`);
|
|
2478
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
2479
|
+
res.end(JSON.stringify({ ok: true }));
|
|
2480
|
+
} else {
|
|
2481
|
+
res.writeHead(400, { 'content-type': 'application/json; charset=utf-8' });
|
|
2482
|
+
res.end(JSON.stringify({ ok: false, reason: 'bad-session-id' }));
|
|
2483
|
+
}
|
|
2484
|
+
} catch {
|
|
2485
|
+
try { res.writeHead(400); res.end('{}'); } catch { /* ignore */ }
|
|
2486
|
+
}
|
|
2487
|
+
});
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
// GET:读并消费(一次性)
|
|
2492
|
+
const now = Date.now();
|
|
2493
|
+
let out = null;
|
|
2494
|
+
if (pendingJump && now - pendingJump.at <= 120000) {
|
|
2495
|
+
out = { sessionId: pendingJump.sessionId, at: pendingJump.at };
|
|
2496
|
+
pendingJump = null; // 消费即清,防重复跳
|
|
2497
|
+
appendNotifyLog(`[jump-consume] session=${out.sessionId} age=${Math.round((now - out.at) / 1000)}s`);
|
|
2498
|
+
} else if (pendingJump) {
|
|
2499
|
+
appendNotifyLog(`[jump-expired] session=${pendingJump.sessionId} `
|
|
2500
|
+
+ `age=${Math.round((now - pendingJump.at) / 1000)}s (>120s)`);
|
|
2501
|
+
pendingJump = null;
|
|
2502
|
+
}
|
|
2503
|
+
if (out) {
|
|
2504
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
2505
|
+
res.end(JSON.stringify(out));
|
|
2506
|
+
} else {
|
|
2507
|
+
res.writeHead(204, { 'cache-control': 'no-store' });
|
|
2508
|
+
res.end();
|
|
2509
|
+
}
|
|
2510
|
+
} catch {
|
|
2511
|
+
try { res.writeHead(500); res.end('{}'); } catch { /* ignore */ }
|
|
2512
|
+
}
|
|
2513
|
+
return;
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2319
2516
|
const guard = checkLocalOrigin(req, { write: isWriteRoute });
|
|
2320
2517
|
if (!guard.ok) {
|
|
2321
2518
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-say",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.71",
|
|
4
4
|
"description": "Desktop notifications for DSH Desktop that actually speak: Windows TTS out of the box (zero download), VOICEVOX voice packs optional, a selectable system-sound fallback, and an idle gate that waits for running subagents before saying the turn is done. Includes a settings-page GUI (sound source, per-event overrides, jump-back-to-session, cooldowns) and a self hot-reload for development.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -1,43 +1,51 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESM loader stub:把 `node:child_process` 换成记录型假实现。
|
|
3
|
-
*
|
|
4
|
-
* 用途:`test/fail-route.test.mjs` 要断言 **lib/index.js 运行时到底给 ps1 传了什么参数**
|
|
5
|
-
* (例如 error 回合是否真的传 `-Kind fail`)。若真去 spawn PowerShell:
|
|
6
|
-
* ① 会弹 Toast / 出声,污染用户桌面;② 需要真实 SystemRoot,与同目录其他测试的
|
|
7
|
-
* 隔离手法冲突(见踩坑 #424)。故在加载 lib 之前把这个模块注册为 loader,
|
|
8
|
-
* 让 `spawn()` 只把参数记进 `globalThis.__SPAWN_CALLS`,不起任何进程。
|
|
9
|
-
*
|
|
10
|
-
* 为什么不用 monkey-patch:lib 用的是 ESM 具名导入
|
|
11
|
-
* (`import { spawn } from 'node:child_process'`),导入绑定只读、不可重新赋值;
|
|
12
|
-
* 只有 loader 层能在模块解析阶段替换它。
|
|
13
|
-
*
|
|
14
|
-
* 该文件**不是测试文件**(不以 .test. 命名),不会被 `node --test` 当用例执行。
|
|
15
|
-
*/
|
|
16
|
-
export async function resolve(specifier, context, nextResolve) {
|
|
17
|
-
if (specifier === 'node:child_process') {
|
|
18
|
-
return { url: 'stub:child_process', shortCircuit: true };
|
|
19
|
-
}
|
|
20
|
-
return nextResolve(specifier, context);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function load(url, context, nextLoad) {
|
|
24
|
-
if (url === 'stub:child_process') {
|
|
25
|
-
const source = `
|
|
26
|
-
// 记录每一次 spawn 的 (file, args) 供断言;返回一个不会真的启动进程的假句柄。
|
|
27
|
-
export function spawn(file, args, options) {
|
|
28
|
-
globalThis.__SPAWN_CALLS = globalThis.__SPAWN_CALLS || [];
|
|
29
|
-
globalThis.__SPAWN_CALLS.push({ file, args: Array.isArray(args) ? args.slice() : args, options });
|
|
30
|
-
return {
|
|
31
|
-
pid: 424242,
|
|
32
|
-
once() { return this; },
|
|
33
|
-
on() { return this; },
|
|
34
|
-
kill() { return true; },
|
|
35
|
-
unref() { return this; },
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* ESM loader stub:把 `node:child_process` 换成记录型假实现。
|
|
3
|
+
*
|
|
4
|
+
* 用途:`test/fail-route.test.mjs` 要断言 **lib/index.js 运行时到底给 ps1 传了什么参数**
|
|
5
|
+
* (例如 error 回合是否真的传 `-Kind fail`)。若真去 spawn PowerShell:
|
|
6
|
+
* ① 会弹 Toast / 出声,污染用户桌面;② 需要真实 SystemRoot,与同目录其他测试的
|
|
7
|
+
* 隔离手法冲突(见踩坑 #424)。故在加载 lib 之前把这个模块注册为 loader,
|
|
8
|
+
* 让 `spawn()` 只把参数记进 `globalThis.__SPAWN_CALLS`,不起任何进程。
|
|
9
|
+
*
|
|
10
|
+
* 为什么不用 monkey-patch:lib 用的是 ESM 具名导入
|
|
11
|
+
* (`import { spawn } from 'node:child_process'`),导入绑定只读、不可重新赋值;
|
|
12
|
+
* 只有 loader 层能在模块解析阶段替换它。
|
|
13
|
+
*
|
|
14
|
+
* 该文件**不是测试文件**(不以 .test. 命名),不会被 `node --test` 当用例执行。
|
|
15
|
+
*/
|
|
16
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
17
|
+
if (specifier === 'node:child_process') {
|
|
18
|
+
return { url: 'stub:child_process', shortCircuit: true };
|
|
19
|
+
}
|
|
20
|
+
return nextResolve(specifier, context);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function load(url, context, nextLoad) {
|
|
24
|
+
if (url === 'stub:child_process') {
|
|
25
|
+
const source = `
|
|
26
|
+
// 记录每一次 spawn 的 (file, args) 供断言;返回一个不会真的启动进程的假句柄。
|
|
27
|
+
export function spawn(file, args, options) {
|
|
28
|
+
globalThis.__SPAWN_CALLS = globalThis.__SPAWN_CALLS || [];
|
|
29
|
+
globalThis.__SPAWN_CALLS.push({ file, args: Array.isArray(args) ? args.slice() : args, options });
|
|
30
|
+
return {
|
|
31
|
+
pid: 424242,
|
|
32
|
+
once() { return this; },
|
|
33
|
+
on() { return this; },
|
|
34
|
+
kill() { return true; },
|
|
35
|
+
unref() { return this; },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// v0.4.70:插件新增 execFileSync(注册自定义协议时同步调 PowerShell)。
|
|
39
|
+
// 桩里也要提供,否则 import { execFileSync } 会在模块链接阶段报
|
|
40
|
+
// "does not provide an export named execFileSync"。同样只记录、不起进程。
|
|
41
|
+
export function execFileSync(file, args, options) {
|
|
42
|
+
globalThis.__SPAWN_CALLS = globalThis.__SPAWN_CALLS || [];
|
|
43
|
+
globalThis.__SPAWN_CALLS.push({ file, args: Array.isArray(args) ? args.slice() : args, options, sync: true });
|
|
44
|
+
return Buffer.from('');
|
|
45
|
+
}
|
|
46
|
+
export default { spawn, execFileSync };
|
|
47
|
+
`;
|
|
48
|
+
return { format: 'module', shortCircuit: true, source };
|
|
49
|
+
}
|
|
50
|
+
return nextLoad(url, context);
|
|
51
|
+
}
|
|
@@ -99,21 +99,31 @@ test('T9: consume 取走整个队列并清空,同时保留旧字段', () => {
|
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
// ══ T10-T12:规则选择 ═══════════════════════════════════════════════════
|
|
102
|
-
test('T10: pickJumpTarget
|
|
102
|
+
test('T10: pickJumpTarget 规则 + 单会话不受规则影响', () => {
|
|
103
103
|
const fn = grab(CLIENT, 'function pickJumpTarget(list, rule) {', '\n }\n');
|
|
104
104
|
assert.match(fn, /if \(list\.length === 1\) return list\[0\]/, '单会话必须直接返回它');
|
|
105
105
|
assert.match(fn, /if \(rule === 'none'\) return null/, 'none 返回 null');
|
|
106
106
|
assert.match(fn, /if \(rule === 'latest'\) return sorted\[sorted\.length - 1\]/, 'latest 取末尾');
|
|
107
|
-
assert.match(fn, /return sorted\[0\]/, '
|
|
107
|
+
assert.match(fn, /return sorted\[0\]/, 'earliest 取最早(也是 clicked 没命中时的兜底)');
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
test('T11: 默认规则是
|
|
111
|
-
|
|
110
|
+
test('T11: 默认规则是 clicked(点哪个跳哪个)', () => {
|
|
111
|
+
// v0.4.70:默认从 earliest 改为 clicked —— 多会话时用户点的是具体某个 Toast,
|
|
112
|
+
// 按时间排序猜必然猜错。clicked 用 Toast 自带的 session id,精确。
|
|
113
|
+
assert.match(SCHEMA, /multiJumpRule: 'clicked'/, 'FIELD_DEFAULTS 必须是 clicked');
|
|
112
114
|
// ⚠️ schemastery 没有 z.enum,必须是 union+const(踩坑:z.enum 直接 TypeError)
|
|
113
|
-
assert.match(SCHEMA, /\.union\(\[z\.const\('earliest'\), z\.const\('latest'\), z\.const\('none'\)\]\)/, '
|
|
115
|
+
assert.match(SCHEMA, /\.union\(\[z\.const\('clicked'\), z\.const\('earliest'\), z\.const\('latest'\), z\.const\('none'\)\]\)/, '四值用 union+const');
|
|
114
116
|
assert.doesNotMatch(SCHEMA, /z\.enum\(/, 'schemastery 不支持 z.enum');
|
|
115
|
-
assert.match(CLIENT, /typeof v\.multiJumpRule === 'string' \? v\.multiJumpRule : '
|
|
116
|
-
|
|
117
|
+
assert.match(CLIENT, /var curRule = typeof v\.multiJumpRule === 'string' \? v\.multiJumpRule : 'clicked'/, 'GUI 兜底也得是 clicked');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('T11b: clicked 必须排在选项第一位(默认项)', () => {
|
|
121
|
+
const m = CLIENT.match(/var JUMP_RULES = \[([\s\S]*?)\]/);
|
|
122
|
+
assert.ok(m, '要有 JUMP_RULES');
|
|
123
|
+
assert.match(m[1], /\['clicked'/, 'clicked 要出现在选项里');
|
|
124
|
+
// 第一位 = 默认选中项
|
|
125
|
+
const first = m[1].match(/\['([a-z]+)'/);
|
|
126
|
+
assert.equal(first[1], 'clicked', 'clicked 必须在第一位');
|
|
117
127
|
});
|
|
118
128
|
|
|
119
129
|
test('T12: 客户端能同时吃新队列和旧单条响应', () => {
|
|
@@ -130,3 +140,29 @@ test('T13: multiJumpRule 在 schema/store/index 三处白名单与透传都在',
|
|
|
130
140
|
assert.match(store, /multiJumpRule: cfg\.multiJumpRule,/, 'config-store 透传');
|
|
131
141
|
assert.match(INDEX, /multiJumpRule: g\.multiJumpRule,/, 'effectiveForClient 透传');
|
|
132
142
|
});
|
|
143
|
+
|
|
144
|
+
// ══ v0.4.71:前台点 Toast 也要跳 ════════════════════════════════════════
|
|
145
|
+
test('T14: 必须有 tryTopJump(不依赖 visibilitychange)', () => {
|
|
146
|
+
// 用户 2026-10-19 指出:窗口一直在前台时点 Toast,visibilitychange 不触发,
|
|
147
|
+
// 于是跳不过去。而"在前台点 Toast 直接过去看结果"恰恰是最省事的用法。
|
|
148
|
+
assert.match(CLIENT, /function tryTopJump\(\)/, '要有前台跳转入口');
|
|
149
|
+
const m = CLIENT.match(/function tryTopJump\(\)([\s\S]{0,900})/);
|
|
150
|
+
assert.ok(m, '能读到函数体');
|
|
151
|
+
assert.match(m[1], /fetchPendingJump\(\)/, '要读 pending-jump');
|
|
152
|
+
assert.match(m[1], /openSession\(/, '要真的跳');
|
|
153
|
+
assert.match(m[1], /lastTopJumpCheck/, '要有节流,避免 focus 抖动打爆请求');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('T15: focus 与 mousedown 监听都要注册且要能移除', () => {
|
|
157
|
+
assert.match(CLIENT, /addEventListener\('focus', tryTopJump\)/, 'window focus 要监听');
|
|
158
|
+
assert.match(CLIENT, /addEventListener\('mousedown', tryTopJump/, 'document mousedown 要监听');
|
|
159
|
+
// 闭环:卸载时必须移除,否则热重载会叠监听
|
|
160
|
+
assert.match(CLIENT, /removeEventListener\('focus', tryTopJump\)/, '卸载要移除 focus');
|
|
161
|
+
assert.match(CLIENT, /removeEventListener\('mousedown', tryTopJump\)/, '卸载要移除 mousedown');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('T16: 前台跳转必须有 120 秒过期保护', () => {
|
|
165
|
+
const m = CLIENT.match(/function tryTopJump\(\)([\s\S]{0,900})/);
|
|
166
|
+
assert.ok(m);
|
|
167
|
+
assert.match(m[1], /120000/, '超过 120 秒的点击不该跳(避免久等后突然跳走)');
|
|
168
|
+
});
|