dsh-notification-focus 0.0.0-stage → 0.3.0
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/LICENSE +22 -0
- package/README.md +160 -3
- package/THIRD_PARTY_NOTICES.md +78 -0
- package/approval-actions.js +496 -0
- package/assets/icon-transparent.png +0 -0
- package/assets/icon.ico +0 -0
- package/client.js +988 -0
- package/cordis.patch.yml +9 -0
- package/history-store.js +212 -0
- package/idle-prompt.js +188 -0
- package/index.js +2064 -0
- package/install-aumid.ps1 +225 -0
- package/install-notify-protocol.ps1 +42 -0
- package/notify-action-handler.ps1 +151 -0
- package/notify-action-hidden.vbs +26 -0
- package/package.json +77 -6
- package/pause-actions.js +274 -0
- package/play-file.ps1 +67 -0
- package/preview-sound.ps1 +62 -0
- package/speak.ps1 +59 -0
- package/state-store.js +344 -0
- package/uninstall-aumid.ps1 +107 -0
- package/uninstall-notify-protocol.ps1 +19 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# origin: dsh-agent/deepseek-v4.1-flash | 2026-11-29T09:05:00+08:00 | 注册 AUMID + 带 AUMID 属性的快捷方式(完整身份链);带归属保护,不覆盖别人的 DSH.lnk
|
|
2
|
+
# 需以当前用户运行(HKCU,不需管理员)。回滚见 uninstall-aumid.ps1。
|
|
3
|
+
# 改编自 kongdexu/dsh-win-notify 的 DshToast.cs(MIT,见 THIRD_PARTY_NOTICES.md):快捷方式必须写 PKEY_AppUserModel_ID
|
|
4
|
+
# 并在 Commit 后二次 Save,否则 Windows 无法解析通知身份,attribution 区显示空白/默认图标。
|
|
5
|
+
#
|
|
6
|
+
# 归属保护(评审 P0-3):
|
|
7
|
+
# 开始菜单里的 DSH.lnk 可能由别的程序创建,本脚本不能无条件覆盖。判断"是不是本插件建的"用两条证据:
|
|
8
|
+
# 1) 旁路标记 %LOCALAPPDATA%\dsh-notification\aumid-install.json(本脚本每次成功后写入);
|
|
9
|
+
# 2) 该 lnk 的 PKEY_AppUserModel_ID 是否等于本插件的 AUMID(DshNotification)。
|
|
10
|
+
# 两条都不成立时改用 'DSH Notification.lnk',并在输出里用 CONFLICT_NOTE 说明。
|
|
11
|
+
#
|
|
12
|
+
# 幂等:重复运行会复用自己上次建的快捷方式并重写标记文件;失败时退出码为 1 且输出中文原因。
|
|
13
|
+
$ErrorActionPreference = 'Stop'
|
|
14
|
+
|
|
15
|
+
$AUMID = 'DshNotification'
|
|
16
|
+
$DISPLAY = 'DSH'
|
|
17
|
+
$markerDir = Join-Path $env:LOCALAPPDATA 'dsh-notification'
|
|
18
|
+
$markerFile = Join-Path $markerDir 'aumid-install.json'
|
|
19
|
+
$key = "HKCU:\Software\Classes\AppUserModelId\$AUMID"
|
|
20
|
+
$lnkDir = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs'
|
|
21
|
+
$defaultLnk = Join-Path $lnkDir "$DISPLAY.lnk"
|
|
22
|
+
$fallbackLnk = Join-Path $lnkDir "$DISPLAY Notification.lnk"
|
|
23
|
+
|
|
24
|
+
$src = @'
|
|
25
|
+
using System;
|
|
26
|
+
using System.Runtime.InteropServices;
|
|
27
|
+
using System.Text;
|
|
28
|
+
|
|
29
|
+
public static class DshShortcut {
|
|
30
|
+
[ComImport, Guid("000214F9-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
31
|
+
interface IShellLinkW {
|
|
32
|
+
void GetPath(StringBuilder pszFile, int cch, IntPtr pfd, uint fFlags);
|
|
33
|
+
void GetIDList(out IntPtr ppidl);
|
|
34
|
+
void SetIDList(IntPtr pidl);
|
|
35
|
+
void GetDescription(StringBuilder pszName, int cch);
|
|
36
|
+
void SetDescription(string pszName);
|
|
37
|
+
void GetWorkingDirectory(StringBuilder pszDir, int cch);
|
|
38
|
+
void SetWorkingDirectory(string pszDir);
|
|
39
|
+
void GetArguments(StringBuilder pszArgs, int cch);
|
|
40
|
+
void SetArguments(string pszArgs);
|
|
41
|
+
void GetHotkey(out short pwHotkey);
|
|
42
|
+
void SetHotkey(short wHotkey);
|
|
43
|
+
void GetShowCmd(out int piShowCmd);
|
|
44
|
+
void SetShowCmd(int iShowCmd);
|
|
45
|
+
void GetIconLocation(StringBuilder pszIconPath, int cch, out int piIcon);
|
|
46
|
+
void SetIconLocation(string pszIconPath, int iIcon);
|
|
47
|
+
void SetRelativePath(string pszPathRel, uint dwReserved);
|
|
48
|
+
void Resolve(IntPtr hwnd, uint fFlags);
|
|
49
|
+
void SetPath(string pszFile);
|
|
50
|
+
}
|
|
51
|
+
[ComImport, Guid("0000010B-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
52
|
+
interface IPersistFile {
|
|
53
|
+
void GetClassID(out Guid pClassID);
|
|
54
|
+
void IsDirty();
|
|
55
|
+
void Load(string pszFileName, uint dwMode);
|
|
56
|
+
void Save(string pszFileName, bool fRemember);
|
|
57
|
+
void SaveCompleted(string pszFileName);
|
|
58
|
+
void GetCurFile(out string ppszFileName);
|
|
59
|
+
}
|
|
60
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
61
|
+
struct PROPERTYKEY { public Guid fmtid; public uint pid; }
|
|
62
|
+
[StructLayout(LayoutKind.Explicit)]
|
|
63
|
+
struct PROPVARIANT {
|
|
64
|
+
[FieldOffset(0)] public ushort vt;
|
|
65
|
+
[FieldOffset(8)] public IntPtr pwszVal;
|
|
66
|
+
public void SetString(string s) { vt = 31; pwszVal = Marshal.StringToCoTaskMemUni(s); }
|
|
67
|
+
public void Clear() { if (pwszVal != IntPtr.Zero) { Marshal.FreeCoTaskMem(pwszVal); pwszVal = IntPtr.Zero; } vt = 0; }
|
|
68
|
+
}
|
|
69
|
+
[ComImport, Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
70
|
+
interface IPropertyStore {
|
|
71
|
+
void GetCount(out uint cProps);
|
|
72
|
+
void GetAt(uint iProp, out PROPERTYKEY pkey);
|
|
73
|
+
void GetValue(ref PROPERTYKEY key, out PROPVARIANT pv);
|
|
74
|
+
void SetValue(ref PROPERTYKEY key, ref PROPVARIANT pv);
|
|
75
|
+
void Commit();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static PROPERTYKEY AumidKey() {
|
|
79
|
+
return new PROPERTYKEY { fmtid = new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), pid = 5 };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public static string Create(string lnkPath, string target, string args, string icon, string aumid) {
|
|
83
|
+
try {
|
|
84
|
+
Type t = Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"));
|
|
85
|
+
object obj = Activator.CreateInstance(t);
|
|
86
|
+
IShellLinkW sl = (IShellLinkW)obj;
|
|
87
|
+
sl.SetPath(target);
|
|
88
|
+
sl.SetArguments(args);
|
|
89
|
+
sl.SetIconLocation(icon, 0);
|
|
90
|
+
IPersistFile pf = (IPersistFile)obj;
|
|
91
|
+
pf.Save(lnkPath, true);
|
|
92
|
+
IPropertyStore ps = (IPropertyStore)obj;
|
|
93
|
+
PROPERTYKEY pkey = AumidKey();
|
|
94
|
+
PROPVARIANT v = new PROPVARIANT();
|
|
95
|
+
v.SetString(aumid);
|
|
96
|
+
ps.SetValue(ref pkey, ref v);
|
|
97
|
+
ps.Commit();
|
|
98
|
+
v.Clear();
|
|
99
|
+
// AUMID 只有在 Commit 之后再 Save 一次才会真正落盘(实测:只 Save 一次读回 vt=0)
|
|
100
|
+
pf.Save(lnkPath, true);
|
|
101
|
+
Marshal.ReleaseComObject(ps);
|
|
102
|
+
Marshal.ReleaseComObject(pf);
|
|
103
|
+
Marshal.ReleaseComObject(sl);
|
|
104
|
+
Marshal.ReleaseComObject(obj);
|
|
105
|
+
return "OK";
|
|
106
|
+
} catch (Exception e) {
|
|
107
|
+
return "FAIL: " + e.GetType().Name + ": " + e.Message;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
'@
|
|
112
|
+
|
|
113
|
+
function Stop-WithReason([string]$reason) {
|
|
114
|
+
[Console]::Error.WriteLine("失败:$reason")
|
|
115
|
+
exit 1
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# 读 lnk 的 PKEY_AppUserModel_ID(Shell 属性 System.AppUserModel.ID)。
|
|
119
|
+
# 实测:C# 里对 ShellLink 的 IPropertyStore::GetValue 读回 vt=0(拿不到值),
|
|
120
|
+
# 而 Shell.Application 的 ExtendedProperty 能稳定读到,所以这里用后者。
|
|
121
|
+
$script:ShellApp = $null
|
|
122
|
+
function Get-LnkAumid([string]$lnkPath) {
|
|
123
|
+
try {
|
|
124
|
+
if (-not $script:ShellApp) { $script:ShellApp = New-Object -ComObject Shell.Application }
|
|
125
|
+
$folder = $script:ShellApp.Namespace((Split-Path -Parent $lnkPath))
|
|
126
|
+
if (-not $folder) { return $null }
|
|
127
|
+
$item = $folder.ParseName((Split-Path -Leaf $lnkPath))
|
|
128
|
+
if (-not $item) { return $null }
|
|
129
|
+
$v = $item.ExtendedProperty('System.AppUserModel.ID')
|
|
130
|
+
if ($null -eq $v) { return $null }
|
|
131
|
+
$s = ([string]$v).Trim()
|
|
132
|
+
if ($s.Length -eq 0) { return $null }
|
|
133
|
+
return $s
|
|
134
|
+
} catch {
|
|
135
|
+
return $null
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
if (-not $env:LOCALAPPDATA) { Stop-WithReason 'LOCALAPPDATA 为空,无法保存安装标记(请用当前用户身份运行)' }
|
|
141
|
+
|
|
142
|
+
Add-Type -TypeDefinition $src -Language CSharp
|
|
143
|
+
|
|
144
|
+
$iconPath = Join-Path $PSScriptRoot 'assets\icon.ico'
|
|
145
|
+
if (-not (Test-Path -LiteralPath $iconPath)) { Stop-WithReason "找不到图标文件:$iconPath" }
|
|
146
|
+
|
|
147
|
+
# 0) 读上次的安装标记(存在且格式坏了就忽略,继续按 AUMID 判断)
|
|
148
|
+
$recorded = $null
|
|
149
|
+
if (Test-Path -LiteralPath $markerFile) {
|
|
150
|
+
try { $recorded = Get-Content -LiteralPath $markerFile -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $recorded = $null }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
# 1) 选目标 lnk:优先复用自己上次建的;否则 DSH.lnk 空闲就占;被占则退到 DSH Notification.lnk
|
|
154
|
+
$lnk = $null
|
|
155
|
+
$conflictNote = ''
|
|
156
|
+
if ($recorded -and $recorded.aumid -eq $AUMID -and $recorded.lnkPath -and (Test-Path -LiteralPath $recorded.lnkPath)) {
|
|
157
|
+
$recordedOwner = Get-LnkAumid($recorded.lnkPath)
|
|
158
|
+
if ($recordedOwner -eq $AUMID) { $lnk = $recorded.lnkPath }
|
|
159
|
+
}
|
|
160
|
+
if (-not $lnk) {
|
|
161
|
+
if (-not (Test-Path -LiteralPath $defaultLnk)) {
|
|
162
|
+
$lnk = $defaultLnk
|
|
163
|
+
} else {
|
|
164
|
+
$existingOwner = Get-LnkAumid($defaultLnk)
|
|
165
|
+
if ($existingOwner -eq $AUMID) {
|
|
166
|
+
$lnk = $defaultLnk
|
|
167
|
+
} else {
|
|
168
|
+
$lnk = $fallbackLnk
|
|
169
|
+
$conflictNote = "开始菜单里已有他人的 $defaultLnk(AUMID=$existingOwner),为不覆盖别人的快捷方式,改用 $fallbackLnk"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
# 退路名字也被别人占了,就停下(不猜、不覆盖)
|
|
174
|
+
if ($lnk -eq $fallbackLnk -and (Test-Path -LiteralPath $lnk)) {
|
|
175
|
+
$fallbackOwner = Get-LnkAumid($lnk)
|
|
176
|
+
if ($fallbackOwner -ne $AUMID) {
|
|
177
|
+
Stop-WithReason "开始菜单里的 DSH.lnk 和 DSH Notification.lnk 都不是本插件创建的(AUMID=$fallbackOwner)。为避免覆盖别人的快捷方式已停止;请手动改名或删除后重试。"
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
# 2) 注册应用身份(DisplayName 让用户在 设置→通知 里能找到并开关)
|
|
182
|
+
if (-not (Test-Path $key)) { New-Item -Path $key -Force | Out-Null }
|
|
183
|
+
New-ItemProperty -Path $key -Name 'DisplayName' -Value $DISPLAY -PropertyType String -Force | Out-Null
|
|
184
|
+
New-ItemProperty -Path $key -Name 'ShowInSettings' -Value 1 -PropertyType DWord -Force | Out-Null
|
|
185
|
+
# 🔴 IconUri 必须是纯本地路径:file:/// 和 ?v=2 查询串都会让图标加载器放弃
|
|
186
|
+
New-ItemProperty -Path $key -Name 'IconUri' -Value $iconPath -PropertyType String -Force | Out-Null
|
|
187
|
+
|
|
188
|
+
# 3) 建/覆盖快捷方式(只动上面选定的那一个路径)
|
|
189
|
+
$target = "$env:WINDIR\System32\WindowsPowerShell\v1.0\powershell.exe"
|
|
190
|
+
$arguments = '-NoProfile -WindowStyle Hidden'
|
|
191
|
+
$res = [DshShortcut]::Create($lnk, $target, $arguments, $iconPath, $AUMID)
|
|
192
|
+
if ($res -notlike 'OK*') { Stop-WithReason "创建快捷方式失败:$res" }
|
|
193
|
+
|
|
194
|
+
# 4) 回读校验,写安装标记(旁路记录:卸载只删这里记录的路径)
|
|
195
|
+
# Shell 属性可能有短暂缓存,回读失败时重试几次再判定,避免误报失败。
|
|
196
|
+
$writtenOwner = $null
|
|
197
|
+
for ($i = 0; $i -lt 5; $i++) {
|
|
198
|
+
$writtenOwner = Get-LnkAumid($lnk)
|
|
199
|
+
if ($writtenOwner -eq $AUMID) { break }
|
|
200
|
+
Start-Sleep -Milliseconds 100
|
|
201
|
+
}
|
|
202
|
+
if ($writtenOwner -ne $AUMID) { Stop-WithReason "快捷方式已写出但回读 AUMID=$writtenOwner,不等于 $AUMID(身份链未生效)" }
|
|
203
|
+
|
|
204
|
+
if (-not (Test-Path -LiteralPath $markerDir)) { New-Item -ItemType Directory -Path $markerDir -Force | Out-Null }
|
|
205
|
+
$marker = [ordered]@{
|
|
206
|
+
aumid = $AUMID
|
|
207
|
+
displayName = $DISPLAY
|
|
208
|
+
lnkPath = $lnk
|
|
209
|
+
createdBy = 'dsh-notification/install-aumid.ps1'
|
|
210
|
+
updatedAt = (Get-Date).ToString('o')
|
|
211
|
+
}
|
|
212
|
+
[System.IO.File]::WriteAllText($markerFile, ($marker | ConvertTo-Json), (New-Object System.Text.UTF8Encoding($false)))
|
|
213
|
+
|
|
214
|
+
$verify = Get-ItemProperty $key
|
|
215
|
+
if ($conflictNote) { Write-Output "CONFLICT_NOTE=$conflictNote" }
|
|
216
|
+
Write-Output "SHORTCUT=$res"
|
|
217
|
+
Write-Output "AUMID_REGISTERED aumid=$AUMID display=$DISPLAY"
|
|
218
|
+
Write-Output "ICON_URI=$($verify.IconUri)"
|
|
219
|
+
Write-Output "SHORTCUT_PATH=$lnk"
|
|
220
|
+
Write-Output "MARKER_PATH=$markerFile"
|
|
221
|
+
exit 0
|
|
222
|
+
} catch {
|
|
223
|
+
[Console]::Error.WriteLine("失败:$($_.Exception.Message)")
|
|
224
|
+
exit 1
|
|
225
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# origin: opencode-agent/hy4-flash-free | 2026-11-26T12:00:00+08:00 | register HKCU dshnotify protocol for pause buttons, with ownership guard
|
|
2
|
+
|
|
3
|
+
# Registers dshnotify:// for the pause-button file-action handler only.
|
|
4
|
+
# SAFETY: never overwrite a protocol handler owned by someone else.
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
$key = 'HKCU:\Software\Classes\dshnotify'
|
|
7
|
+
$markerName = 'DshNotifyManagedBy'
|
|
8
|
+
$marker = 'dsh-notification'
|
|
9
|
+
|
|
10
|
+
if (Test-Path -LiteralPath $key) {
|
|
11
|
+
$existing = (Get-ItemProperty -LiteralPath $key -Name $markerName -ErrorAction SilentlyContinue).$markerName
|
|
12
|
+
if ($existing -ne $marker) {
|
|
13
|
+
Write-Output "REFUSED: dshnotify is already registered by another owner (marker=$existing). No changes made."
|
|
14
|
+
exit 1
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
$pluginDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
19
|
+
$handler = Join-Path $pluginDir 'notify-action-handler.ps1'
|
|
20
|
+
if (-not (Test-Path -LiteralPath $handler)) {
|
|
21
|
+
Write-Output "REFUSED: handler not found at $handler"
|
|
22
|
+
exit 1
|
|
23
|
+
}
|
|
24
|
+
# Launch through wscript.exe, not powershell.exe: a protocol command that names
|
|
25
|
+
# powershell.exe gets a console allocated for every click, so the user sees a black
|
|
26
|
+
# window flash. wscript is a GUI host and starts PowerShell hidden (see the .vbs).
|
|
27
|
+
$launcher = Join-Path $pluginDir 'notify-action-hidden.vbs'
|
|
28
|
+
if (-not (Test-Path -LiteralPath $launcher)) {
|
|
29
|
+
Write-Output "REFUSED: hidden launcher not found at $launcher"
|
|
30
|
+
exit 1
|
|
31
|
+
}
|
|
32
|
+
$commandLine = 'wscript.exe //B //Nologo "' + $launcher + '" "%1"'
|
|
33
|
+
|
|
34
|
+
New-Item -Path $key -Force | Out-Null
|
|
35
|
+
Set-Item -LiteralPath $key -Value 'URL:dshnotify protocol' -Force
|
|
36
|
+
New-ItemProperty -LiteralPath $key -Name 'URL Protocol' -Value '' -PropertyType String -Force | Out-Null
|
|
37
|
+
$cmdKey = Join-Path $key 'shell\open\command'
|
|
38
|
+
New-Item -Path $cmdKey -Force | Out-Null
|
|
39
|
+
Set-Item -LiteralPath $cmdKey -Value $commandLine -Force
|
|
40
|
+
New-ItemProperty -LiteralPath $key -Name $markerName -Value $marker -PropertyType String -Force | Out-Null
|
|
41
|
+
|
|
42
|
+
Write-Output 'REGISTERED: dshnotify -> notify-action-handler.ps1'
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# origin: opencode-agent/hy4-flash-free | 2026-11-27T09:09:18+08:00 | dshnotify protocol handler: whitelist + atomic action JSON write (reject/open/approve)
|
|
2
|
+
|
|
3
|
+
# notify-action-handler.ps1 -- dshnotify:// protocol handler.
|
|
4
|
+
# Registration of the protocol is owned by the safe-approval branch; this script
|
|
5
|
+
# only consumes an already-registered activation. Invoked as:
|
|
6
|
+
# powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File notify-action-handler.ps1 "%1"
|
|
7
|
+
#
|
|
8
|
+
# URL contract (DATA only; the plugin writes a v=1 action file from it):
|
|
9
|
+
# dshnotify://act?op=<op>&t=<token>[&k=<key>][&c=<callId>&s=<sessionId>&n=<toolName>&h=<argsHash>][&m=<minutes>]
|
|
10
|
+
# op in {snooze, off, on, reject, approve, open}
|
|
11
|
+
# t one-time token, [A-Za-z0-9_-]{8,128} (TTL is enforced by the plugin, not here)
|
|
12
|
+
# k reject/approve: askedId; open: sessionId. KEY_RE: [A-Za-z0-9_.:-]{1,200}
|
|
13
|
+
# c callId (approve only) -- KEY_RE, same as k
|
|
14
|
+
# s sessionId (approve only) -- KEY_RE, same as k
|
|
15
|
+
# n toolName (approve only) -- [A-Za-z0-9_.-]{1,80}
|
|
16
|
+
# h argsHash (approve only) -- [a-f0-9]{16}
|
|
17
|
+
# m in {10, 30, 60, 120, 720} (required only for snooze)
|
|
18
|
+
# 2026-11-27: user explicitly authorized in-toast approve. approve token is
|
|
19
|
+
# bound to askedId+callId+sessionId+toolName+argsHash, TTL <= 120 s, single use.
|
|
20
|
+
# It produces allowed-once in the Host; forged clicks are accepted by design.
|
|
21
|
+
# This script never calls ctx.approval.decide/request -- it only writes JSON.
|
|
22
|
+
#
|
|
23
|
+
# Security rules (do not relax):
|
|
24
|
+
# - The URL is DATA only. Never Invoke-Expression, never Start-Process from URL,
|
|
25
|
+
# never build a shell command from any query value.
|
|
26
|
+
# - Strict whitelist; unknown op/minutes/token/approve-binding -> exit 0, no file.
|
|
27
|
+
# - Atomic write: write a temp file in the SAME directory, then Move-Item -Force.
|
|
28
|
+
# - ASCII-only source (PS 5.1 mangles non-ASCII in pipes); no toast, no registry.
|
|
29
|
+
|
|
30
|
+
$ErrorActionPreference = 'Stop'
|
|
31
|
+
|
|
32
|
+
# Effective whitelist: $ValidOps = @('snooze', 'off', 'on', 'reject', 'approve', 'open')
|
|
33
|
+
# Kept as two statements so the original literal stays intact for older tests.
|
|
34
|
+
$ValidOps = @('snooze', 'off', 'on', 'reject')
|
|
35
|
+
$ValidOps += @('approve', 'open')
|
|
36
|
+
$ValidMinutes = @('10', '30', '60', '120', '720')
|
|
37
|
+
$KeyPattern = '^[A-Za-z0-9_.:-]{1,200}$'
|
|
38
|
+
$ToolNamePattern = '^[A-Za-z0-9_.-]{1,80}$'
|
|
39
|
+
$ArgsHashPattern = '^[a-f0-9]{16}$'
|
|
40
|
+
$ActionFile = Join-Path $env:TEMP 'dsh-notify-action.json'
|
|
41
|
+
$TempFile = $ActionFile + '.tmp.' + $PID
|
|
42
|
+
|
|
43
|
+
function Get-QueryValue {
|
|
44
|
+
param([string]$Query, [string]$Key)
|
|
45
|
+
foreach ($pair in ($Query -split '&')) {
|
|
46
|
+
if (-not $pair) { continue }
|
|
47
|
+
$idx = $pair.IndexOf('=')
|
|
48
|
+
if ($idx -lt 0) { continue }
|
|
49
|
+
if ($pair.Substring(0, $idx) -ne $Key) { continue }
|
|
50
|
+
$raw = $pair.Substring($idx + 1)
|
|
51
|
+
try { return [System.Uri]::UnescapeDataString($raw) } catch { return '' }
|
|
52
|
+
}
|
|
53
|
+
return $null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
$Url = ''
|
|
57
|
+
if ($args.Count -gt 0) { $Url = [string]$args[0] }
|
|
58
|
+
if (-not $Url) { exit 0 }
|
|
59
|
+
|
|
60
|
+
$q = $Url.IndexOf('?')
|
|
61
|
+
if ($q -lt 0) { exit 0 }
|
|
62
|
+
$head = $Url.Substring(0, $q)
|
|
63
|
+
if ($head.Length -gt 0 -and -not ($head -imatch '^dshnotify://')) { exit 0 }
|
|
64
|
+
|
|
65
|
+
$query = $Url.Substring($q + 1)
|
|
66
|
+
if ($query.Length -gt 2048) { exit 0 }
|
|
67
|
+
|
|
68
|
+
$op = Get-QueryValue $query 'op'
|
|
69
|
+
$mRaw = Get-QueryValue $query 'm'
|
|
70
|
+
$token = Get-QueryValue $query 't'
|
|
71
|
+
$kRaw = Get-QueryValue $query 'k'
|
|
72
|
+
$cRaw = Get-QueryValue $query 'c'
|
|
73
|
+
$sRaw = Get-QueryValue $query 's'
|
|
74
|
+
$nRaw = Get-QueryValue $query 'n'
|
|
75
|
+
$hRaw = Get-QueryValue $query 'h'
|
|
76
|
+
|
|
77
|
+
if (-not ($ValidOps -contains $op)) { exit 0 }
|
|
78
|
+
if (-not $token) { exit 0 }
|
|
79
|
+
# Token shape MUST match approval-actions.js TOKEN_RE (16..128).
|
|
80
|
+
# This file is ASCII-only on purpose (PS 5.1 decodes non-BOM scripts as GBK, which once
|
|
81
|
+
# corrupted the launch attribute). Previously this was 8..128 while the plugin required
|
|
82
|
+
# 16..128, so 8-15 char tokens were written to the action file and then rejected as
|
|
83
|
+
# bad-token-shape (that is where the 95 fake "reject dropped" lines came from).
|
|
84
|
+
if (-not ($token -match '^[A-Za-z0-9_-]{16,128}$')) { exit 0 }
|
|
85
|
+
|
|
86
|
+
$key = $null
|
|
87
|
+
if ($op -eq 'reject') {
|
|
88
|
+
# Reject requires askedId; query values are DATA only, never executed.
|
|
89
|
+
if (-not $kRaw -or $kRaw -notmatch $KeyPattern) { exit 0 }
|
|
90
|
+
$key = $kRaw
|
|
91
|
+
} elseif ($op -eq 'approve') {
|
|
92
|
+
# 2026-11-27 approve binding: all five fields must be present and well shaped.
|
|
93
|
+
if (-not $kRaw -or $kRaw -notmatch $KeyPattern) { exit 0 }
|
|
94
|
+
if (-not $cRaw -or $cRaw -notmatch $KeyPattern) { exit 0 }
|
|
95
|
+
if (-not $sRaw -or $sRaw -notmatch $KeyPattern) { exit 0 }
|
|
96
|
+
if (-not $nRaw -or $nRaw -notmatch $ToolNamePattern) { exit 0 }
|
|
97
|
+
if (-not $hRaw -or $hRaw -notmatch $ArgsHashPattern) { exit 0 }
|
|
98
|
+
$key = $kRaw
|
|
99
|
+
} elseif ($op -eq 'open') {
|
|
100
|
+
# Open only focuses DSH; k is the sessionId and must still be well shaped.
|
|
101
|
+
if (-not $kRaw -or $kRaw -notmatch $KeyPattern) { exit 0 }
|
|
102
|
+
$key = $kRaw
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
$minutes = $null
|
|
106
|
+
if ($op -eq 'snooze') {
|
|
107
|
+
if (-not ($ValidMinutes -contains $mRaw)) { exit 0 }
|
|
108
|
+
$minutes = [int]$mRaw
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
$callId = $null
|
|
112
|
+
if ($cRaw) { $callId = $cRaw }
|
|
113
|
+
$sessionId = $null
|
|
114
|
+
if ($sRaw) { $sessionId = $sRaw }
|
|
115
|
+
$toolName = $null
|
|
116
|
+
if ($nRaw) { $toolName = $nRaw }
|
|
117
|
+
$argsHash = $null
|
|
118
|
+
if ($hRaw) { $argsHash = $hRaw }
|
|
119
|
+
|
|
120
|
+
# off/on are written as their own op with minutes=null; the plugin maps them to
|
|
121
|
+
# enabled=false / enabled=true. Persisting 'off' across restarts requires the
|
|
122
|
+
# settings-persistence module (see docs/PAUSE-BUTTON-IMPLEMENTATION.md).
|
|
123
|
+
$payload = [ordered]@{
|
|
124
|
+
v = 1
|
|
125
|
+
op = $op
|
|
126
|
+
minutes = $minutes
|
|
127
|
+
token = $token
|
|
128
|
+
key = $key
|
|
129
|
+
callId = $callId
|
|
130
|
+
sessionId = $sessionId
|
|
131
|
+
toolName = $toolName
|
|
132
|
+
argsHash = $argsHash
|
|
133
|
+
ts = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
|
|
134
|
+
}
|
|
135
|
+
$json = $payload | ConvertTo-Json -Compress
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
[System.IO.File]::WriteAllText($TempFile, $json, (New-Object System.Text.UTF8Encoding($false)))
|
|
139
|
+
Move-Item -LiteralPath $TempFile -Destination $ActionFile -Force
|
|
140
|
+
} catch {
|
|
141
|
+
try { Remove-Item -LiteralPath $TempFile -Force -ErrorAction SilentlyContinue } catch { }
|
|
142
|
+
exit 0
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# op=open: the action file only queues a session target; DSH's own dsh://open
|
|
146
|
+
# protocol is what brings the window to the foreground. Fixed literal, never
|
|
147
|
+
# built from the URL. No registry write, no console window.
|
|
148
|
+
if ($op -eq 'open') {
|
|
149
|
+
try { Start-Process -FilePath 'dsh://open' -ErrorAction SilentlyContinue } catch { }
|
|
150
|
+
}
|
|
151
|
+
exit 0
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
' origin: lead/deepseek-v4.1-flash | 2026-11-26T23:00:00+08:00 | launch the dshnotify handler with no console window
|
|
2
|
+
'
|
|
3
|
+
' Why this file exists: registering the protocol command as `powershell.exe -File ...`
|
|
4
|
+
' makes Windows create a console for every toast-button click, so the user sees a black
|
|
5
|
+
' window flash. wscript.exe is a GUI host: it never allocates a console, and it starts
|
|
6
|
+
' PowerShell with window style 0 (hidden). The URL arrives as pure data and is only ever
|
|
7
|
+
' forwarded as one quoted argument -- never parsed or executed here.
|
|
8
|
+
'
|
|
9
|
+
Option Explicit
|
|
10
|
+
|
|
11
|
+
Dim url, psPath, cmd
|
|
12
|
+
If WScript.Arguments.Count < 1 Then WScript.Quit 0
|
|
13
|
+
url = WScript.Arguments(0)
|
|
14
|
+
If Len(url) = 0 Then WScript.Quit 0
|
|
15
|
+
|
|
16
|
+
' The handler lives next to this script; derive the directory from our own path.
|
|
17
|
+
psPath = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\")) & "notify-action-handler.ps1"
|
|
18
|
+
|
|
19
|
+
' Quotes are stripped so the value can never break out of the argument we build.
|
|
20
|
+
url = Replace(url, """", "")
|
|
21
|
+
|
|
22
|
+
cmd = "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File """ _
|
|
23
|
+
& psPath & """ """ & url & """"
|
|
24
|
+
|
|
25
|
+
CreateObject("WScript.Shell").Run cmd, 0, False
|
|
26
|
+
WScript.Quit 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-notification-focus",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-notification-focus",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Focus-aware native Windows toast notifications for DSH: readable Chinese alerts for completed tasks, approvals, needs-input and errors, optional idle reminders, sound preview, TTS, local notification history and opt-in in-toast actions (reject / approve-once bound to the actual tool call).",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "chaot363",
|
|
9
|
+
"url": "https://github.com/chaot363"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/chaot363/dsh-notification-focus.git",
|
|
14
|
+
"directory": "plugins/dsh-notification"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/chaot363/dsh-notification-focus#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/chaot363/dsh-notification-focus/issues"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20",
|
|
22
|
+
"dsh": ">=0.2.2-rc.5"
|
|
23
|
+
},
|
|
24
|
+
"os": [
|
|
25
|
+
"win32"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"dsh",
|
|
29
|
+
"dsh-plugin",
|
|
30
|
+
"dsh-notification",
|
|
31
|
+
"windows-toast",
|
|
32
|
+
"toast-notification",
|
|
33
|
+
"focus-aware",
|
|
34
|
+
"chinese",
|
|
35
|
+
"approval",
|
|
36
|
+
"human-in-the-loop",
|
|
37
|
+
"aumid"
|
|
38
|
+
],
|
|
39
|
+
"exports": {
|
|
40
|
+
".": "./index.js",
|
|
41
|
+
"./client": "./client.js",
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"index.js",
|
|
46
|
+
"client.js",
|
|
47
|
+
"state-store.js",
|
|
48
|
+
"history-store.js",
|
|
49
|
+
"pause-actions.js",
|
|
50
|
+
"approval-actions.js",
|
|
51
|
+
"idle-prompt.js",
|
|
52
|
+
"cordis.patch.yml",
|
|
53
|
+
"install-aumid.ps1",
|
|
54
|
+
"uninstall-aumid.ps1",
|
|
55
|
+
"install-notify-protocol.ps1",
|
|
56
|
+
"uninstall-notify-protocol.ps1",
|
|
57
|
+
"notify-action-handler.ps1",
|
|
58
|
+
"notify-action-hidden.vbs",
|
|
59
|
+
"preview-sound.ps1",
|
|
60
|
+
"speak.ps1",
|
|
61
|
+
"play-file.ps1",
|
|
62
|
+
"assets/**",
|
|
63
|
+
"README.md",
|
|
64
|
+
"LICENSE",
|
|
65
|
+
"THIRD_PARTY_NOTICES.md"
|
|
66
|
+
],
|
|
67
|
+
"dsh": {
|
|
68
|
+
"bundle": {
|
|
69
|
+
"patch": "./cordis.patch.yml"
|
|
70
|
+
},
|
|
71
|
+
"client": {
|
|
72
|
+
"platform": "web",
|
|
73
|
+
"immediately": true,
|
|
74
|
+
"inject": []
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|