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/state-store.js ADDED
@@ -0,0 +1,344 @@
1
+ // origin: opencode-agent/hy4-flash-free | 2026-11-26T11:29:12+08:00 | 设置持久化模块:fail-open 读取 / 原子写入(已接入 index.js 的 load/config/动作通道)
2
+
3
+ // 设计目标(详见 docs/SETTINGS-PERSISTENCE.md):
4
+ // 1. 绝不 throw:文件损坏、权限不足、路径不对一律回退默认值/当前值;
5
+ // 2. 只存白名单字段(enabled/types/sounds/quiet/snoozeUntil/mutedSessions),不存任何凭据;
6
+ // 3. 原子写:临时文件 + rename,且写入串行化,不留半截 JSON;
7
+ // 4. 严格 schema:逐字段校验,非法字段单独丢弃,不整份作废;
8
+ // 5. 默认不接入:本模块只提供能力,集成指引写文档,index.js 保持原样。
9
+
10
+ import * as nodeFs from 'node:fs'
11
+ import * as nodePath from 'node:path'
12
+ import { homedir } from 'node:os'
13
+
14
+ export const SCHEMA_VERSION = 1
15
+
16
+ // 与 index.js 的 VALID / SOUND_CHOICES 对齐(只读常量,来自该分支的 main 8634797)
17
+ export const VALID_TYPES = Object.freeze(['success', 'approval', 'needs-input', 'error', 'idle'])
18
+ export const SOUND_CHOICES = Object.freeze([
19
+ 'Notification.Default', 'Notification.IM', 'Notification.Mail',
20
+ 'Notification.Reminder', 'Notification.LoopingCall', 'Notification.LoopingAlarm',
21
+ 'Notification.LoopingAlarm2', 'Notification.LoopingCall2', 'None',
22
+ ])
23
+
24
+ // 默认值与 index.js 进程内存默认一致:总开关开、类型全开、四种默认音效、无静音、无 snooze。
25
+ export const DEFAULT_STATE = Object.freeze({
26
+ enabled: true,
27
+ types: [],
28
+ sounds: Object.freeze({
29
+ success: 'Notification.IM',
30
+ approval: 'Notification.Reminder',
31
+ 'needs-input': 'Notification.Mail',
32
+ error: 'Notification.Default',
33
+ }),
34
+ quiet: Object.freeze({ start: '', end: '' }),
35
+ snoozeUntil: 0,
36
+ idleEnabled: false,
37
+ idleMs: 60 * 1000,
38
+ approvalGraceMs: 6000,
39
+ alwaysNotify: false,
40
+ clickEnabled: false,
41
+ pauseButtons: false,
42
+ approvalButtons: false,
43
+ // 通知内"批准一次"是高级选项,默认关闭:默认只有导航/拒绝,没有授权按钮。
44
+ approveEnabled: false,
45
+ ttsEnabled: false,
46
+ ttsVoice: '',
47
+ customSounds: Object.freeze({}),
48
+ historyEnabled: true,
49
+ // 按会话免打扰(🔔):sessionId 字符串数组,命中者不弹 toast/不写历史/不播音效。
50
+ mutedSessions: [],
51
+ })
52
+
53
+ const VOICE_RE = /^[A-Za-z0-9 .()\-]{0,100}$/
54
+ // 允许中文路径;只挡控制字符/URL/通配符/UNC/引号,要求 Windows 绝对路径
55
+ const LOCAL_PATH_RE = /^[A-Za-z]:[\\\/][^\u0000-\u001f\u007f*?"<>|]+$/
56
+ // 会话 ID 形状与 index.js 的导航/审批键一致;按会话免打扰用它逐元素过滤。
57
+ const SESSION_ID_RE = /^[A-Za-z0-9_.:-]{1,200}$/
58
+ const MAX_MUTED_SESSIONS = 200
59
+
60
+ // 自定义音只接受本地路径的白名单字符;不允许 URL、通配符或引号。
61
+ function validAudioPath(value) {
62
+ return typeof value === 'string'
63
+ && value.length <= 4096
64
+ && LOCAL_PATH_RE.test(value)
65
+ && !value.includes('://')
66
+ && !value.startsWith('\\\\')
67
+ && !/[\u0000-\u001f\u007f*?"<>|]/.test(value)
68
+ }
69
+
70
+ const HHMM_RE = /^([01]?\d|2[0-3]):([0-5]\d)$/
71
+ const QUIET_RAW_RE = /^(\d{1,2}:\d{2})-(\d{1,2}:\d{2})$/
72
+
73
+ function isPlainObject(v) {
74
+ return v !== null && typeof v === 'object' && !Array.isArray(v)
75
+ }
76
+
77
+ function validHHMM(s) {
78
+ return typeof s === 'string' && (s === '' || HHMM_RE.test(s))
79
+ }
80
+
81
+ // quiet 接受两种形状:{start,end} 或 env 风的 'HH:MM-HH:MM';空串表示关闭。
82
+ function normalizeQuiet(value) {
83
+ if (typeof value === 'string') {
84
+ if (value === '') return { start: '', end: '' }
85
+ const m = QUIET_RAW_RE.exec(value)
86
+ if (!m || !validHHMM(m[1]) || !validHHMM(m[2])) return null
87
+ return { start: m[1], end: m[2] }
88
+ }
89
+ if (!isPlainObject(value)) return null
90
+ if (!validHHMM(value.start) || !validHHMM(value.end)) return null
91
+ return { start: value.start, end: value.end }
92
+ }
93
+
94
+ // 只保留白名单字段;每个字段独立判断,非法字段丢弃、其余照常保留。
95
+ export function validateState(state) {
96
+ const out = {}
97
+ if (!isPlainObject(state)) return out
98
+
99
+ if (typeof state.enabled === 'boolean') out.enabled = state.enabled
100
+
101
+ if (Array.isArray(state.types)) {
102
+ const seen = new Set()
103
+ const types = []
104
+ for (const t of state.types) {
105
+ if (typeof t === 'string' && VALID_TYPES.includes(t) && !seen.has(t)) {
106
+ seen.add(t)
107
+ types.push(t)
108
+ }
109
+ }
110
+ out.types = types // 空数组合法(= 全开),保留以免被默认值覆盖
111
+ }
112
+
113
+ // 🔔 按会话免打扰:只接受 sessionId 形状的字符串,非法元素单独丢弃、去重、最多 200 个。
114
+ if (Array.isArray(state.mutedSessions)) {
115
+ const seen = new Set()
116
+ const mutedSessions = []
117
+ for (const sid of state.mutedSessions) {
118
+ if (typeof sid !== 'string' || !SESSION_ID_RE.test(sid) || seen.has(sid)) continue
119
+ seen.add(sid)
120
+ mutedSessions.push(sid)
121
+ if (mutedSessions.length >= MAX_MUTED_SESSIONS) break
122
+ }
123
+ out.mutedSessions = mutedSessions // 空数组合法(= 无人免打扰),保留以免被默认值覆盖
124
+ }
125
+
126
+ if (isPlainObject(state.sounds)) {
127
+ const sounds = {}
128
+ // 只遍历白名单 key,天然挡掉 __proto__ / constructor 之类的原型污染
129
+ for (const k of VALID_TYPES) {
130
+ if (!Object.prototype.hasOwnProperty.call(state.sounds, k)) continue
131
+ const v = state.sounds[k]
132
+ if (typeof v === 'string' && SOUND_CHOICES.includes(v)) sounds[k] = v
133
+ }
134
+ // 全无效 → 丢弃整个字段,回退默认音效
135
+ if (Object.keys(sounds).length > 0) out.sounds = sounds
136
+ }
137
+
138
+ const quiet = normalizeQuiet(state.quiet)
139
+ if (quiet) out.quiet = quiet
140
+
141
+ // 上界必须存在:否则损坏/篡改文件里的 1e300 会让 isSnoozed() 恒真 = 永久静音(对抗审查 P2-2)。
142
+ // 上限 30 天,远超 snooze 路由自身允许的 1440 分钟。
143
+ if (Number.isSafeInteger(state.snoozeUntil) && state.snoozeUntil >= 0 && state.snoozeUntil <= 30 * 864e5) {
144
+ out.snoozeUntil = state.snoozeUntil
145
+ }
146
+
147
+ // 空闲提醒:开关必须 boolean;阈值 1 秒 ~ 24 小时,超界丢弃回默认
148
+ if (typeof state.idleEnabled === 'boolean') out.idleEnabled = state.idleEnabled
149
+ const im = Number(state.idleMs)
150
+ if (state.idleMs !== undefined && Number.isFinite(im) && im >= 1000 && im <= 24 * 60 * 60 * 1000) {
151
+ out.idleMs = im
152
+ }
153
+ const ag = Number(state.approvalGraceMs)
154
+ if (state.approvalGraceMs !== undefined && Number.isFinite(ag) && ag >= 0 && ag <= 60000) {
155
+ out.approvalGraceMs = ag
156
+ }
157
+ if (typeof state.alwaysNotify === 'boolean') out.alwaysNotify = state.alwaysNotify
158
+ for (const key of ['clickEnabled', 'pauseButtons', 'approvalButtons', 'approveEnabled', 'ttsEnabled', 'historyEnabled']) {
159
+ if (typeof state[key] === 'boolean') out[key] = state[key]
160
+ }
161
+ if (typeof state.ttsVoice === 'string' && VOICE_RE.test(state.ttsVoice)) out.ttsVoice = state.ttsVoice
162
+ if (isPlainObject(state.customSounds)) {
163
+ const sounds = {}
164
+ for (const k of VALID_TYPES) {
165
+ if (!Object.prototype.hasOwnProperty.call(state.customSounds, k)) continue
166
+ if (validAudioPath(state.customSounds[k])) sounds[k] = state.customSounds[k]
167
+ }
168
+ out.customSounds = sounds
169
+ }
170
+
171
+ return out
172
+ }
173
+
174
+ // 校验 + 补默认,返回全新的普通对象(调用方改它不会污染 DEFAULT_STATE)。
175
+ export function mergeDefaults(partial) {
176
+ const clean = validateState(partial)
177
+ return {
178
+ version: SCHEMA_VERSION,
179
+ enabled: clean.enabled !== undefined ? clean.enabled : DEFAULT_STATE.enabled,
180
+ types: clean.types !== undefined ? clean.types.slice() : DEFAULT_STATE.types.slice(),
181
+ sounds: clean.sounds !== undefined ? { ...clean.sounds } : { ...DEFAULT_STATE.sounds },
182
+ quiet: clean.quiet !== undefined ? { ...clean.quiet } : { ...DEFAULT_STATE.quiet },
183
+ snoozeUntil: clean.snoozeUntil !== undefined ? clean.snoozeUntil : DEFAULT_STATE.snoozeUntil,
184
+ idleEnabled: clean.idleEnabled !== undefined ? clean.idleEnabled : DEFAULT_STATE.idleEnabled,
185
+ idleMs: clean.idleMs !== undefined ? clean.idleMs : DEFAULT_STATE.idleMs,
186
+ approvalGraceMs: clean.approvalGraceMs !== undefined ? clean.approvalGraceMs : DEFAULT_STATE.approvalGraceMs,
187
+ alwaysNotify: clean.alwaysNotify !== undefined ? clean.alwaysNotify : DEFAULT_STATE.alwaysNotify,
188
+ clickEnabled: clean.clickEnabled !== undefined ? clean.clickEnabled : DEFAULT_STATE.clickEnabled,
189
+ pauseButtons: clean.pauseButtons !== undefined ? clean.pauseButtons : DEFAULT_STATE.pauseButtons,
190
+ approvalButtons: clean.approvalButtons !== undefined ? clean.approvalButtons : DEFAULT_STATE.approvalButtons,
191
+ approveEnabled: clean.approveEnabled !== undefined ? clean.approveEnabled : DEFAULT_STATE.approveEnabled,
192
+ ttsEnabled: clean.ttsEnabled !== undefined ? clean.ttsEnabled : DEFAULT_STATE.ttsEnabled,
193
+ ttsVoice: clean.ttsVoice !== undefined ? clean.ttsVoice : DEFAULT_STATE.ttsVoice,
194
+ customSounds: clean.customSounds !== undefined ? { ...clean.customSounds } : { ...DEFAULT_STATE.customSounds },
195
+ historyEnabled: clean.historyEnabled !== undefined ? clean.historyEnabled : DEFAULT_STATE.historyEnabled,
196
+ mutedSessions: clean.mutedSessions !== undefined ? clean.mutedSessions.slice() : DEFAULT_STATE.mutedSessions.slice(),
197
+ }
198
+ }
199
+
200
+ // 默认路径在仓库外:Windows 用 %LOCALAPPDATA%\dsh-notification\settings.json。
201
+ export function resolveDefaultPath(pathImpl, env, platform) {
202
+ const P = pathImpl || nodePath
203
+ const E = env || process.env
204
+ const plat = platform || process.platform
205
+ let base
206
+ if (plat === 'win32') {
207
+ base = E.LOCALAPPDATA
208
+ || (E.USERPROFILE ? P.join(E.USERPROFILE, 'AppData', 'Local') : P.join(homedir(), 'AppData', 'Local'))
209
+ } else {
210
+ base = E.XDG_DATA_HOME || P.join(E.HOME || homedir(), '.local', 'share')
211
+ }
212
+ return P.join(base, 'dsh-notification', 'settings.json')
213
+ }
214
+
215
+ // 同时兼容 promise 风格(fs.promises)和同步替身(内存 fs)。
216
+ function pickFn(fs, asyncName, syncName) {
217
+ if (!fs) return null
218
+ if (typeof fs[asyncName] === 'function') return fs[asyncName].bind(fs)
219
+ if (typeof fs[syncName] === 'function') return fs[syncName].bind(fs)
220
+ return null
221
+ }
222
+
223
+ const REAL_FS = {
224
+ readFile: nodeFs.promises.readFile,
225
+ writeFile: nodeFs.promises.writeFile,
226
+ rename: nodeFs.promises.rename,
227
+ mkdir: nodeFs.promises.mkdir,
228
+ unlink: nodeFs.promises.unlink,
229
+ }
230
+
231
+ function looksNotFound(err) {
232
+ return err && (err.code === 'ENOENT' || /ENOENT|no such file/i.test(String(err.message || err)))
233
+ }
234
+
235
+ export function createStateStore(options = {}) {
236
+ const {
237
+ fs = REAL_FS,
238
+ path = nodePath,
239
+ filePath,
240
+ now = () => Date.now(),
241
+ pid = process.pid,
242
+ } = options
243
+ const target = filePath || resolveDefaultPath(path, process.env, process.platform)
244
+
245
+ const readFn = pickFn(fs, 'readFile', 'readFileSync')
246
+ const writeFn = pickFn(fs, 'writeFile', 'writeFileSync')
247
+ const renameFn = pickFn(fs, 'rename', 'renameSync')
248
+ const mkdirFn = pickFn(fs, 'mkdir', 'mkdirSync')
249
+ const unlinkFn = pickFn(fs, 'unlink', 'unlinkSync')
250
+
251
+ let seq = 0
252
+ let queue = Promise.resolve() // 写入串行化:并发 save 不会互相踩踏
253
+
254
+ function stamp() {
255
+ try {
256
+ const n = Number(now())
257
+ return Number.isFinite(n) ? n : 0
258
+ } catch {
259
+ return 0
260
+ }
261
+ }
262
+
263
+ function tempPath() {
264
+ seq += 1
265
+ return `${target}.tmp-${pid}-${stamp()}-${seq}`
266
+ }
267
+
268
+ async function ensureDir() {
269
+ if (!mkdirFn) return // 内存替身不需要建目录
270
+ await mkdirFn(path.dirname(target), { recursive: true })
271
+ }
272
+
273
+ // 读取:任何错误都返回「调用方给的当前内存基线」,绝不 reject。
274
+ // 🔴 基线必须是 env 初始化后的当前值:否则文件不存在/损坏时返回 mergeDefaults({})
275
+ // 会把用户用 DSH_NOTIFICATION_QUIET/TYPES 等设置的配置冲掉(对抗审查 P0)。
276
+ async function load(fallback = null) {
277
+ const base = fallback && typeof fallback === 'object' ? fallback : mergeDefaults({})
278
+ try {
279
+ if (!readFn) return mergeDefaults(base)
280
+ const raw = await readFn(target, 'utf8')
281
+ if (typeof raw !== 'string' || raw.length === 0) return mergeDefaults(base)
282
+ let parsed
283
+ try {
284
+ parsed = JSON.parse(raw)
285
+ } catch {
286
+ return mergeDefaults(base) // 损坏 JSON:fail-open,保留 env 值
287
+ }
288
+ // JSON 合法但不是对象(null / [] / 字符串)=没有可用配置,保留 env 基线
289
+ if (!isPlainObject(parsed)) return mergeDefaults(base)
290
+ return mergeDefaults(parsed) // 逐字段校验,非法字段丢弃
291
+ } catch {
292
+ return mergeDefaults(base) // 权限/路径/磁盘错误:fail-open,保留 env 值
293
+ }
294
+ }
295
+
296
+ // 原子写:先写临时文件,再 rename 覆盖;失败清理临时文件并返回 false(不抛)。
297
+ function save(state) {
298
+ let json
299
+ try {
300
+ json = JSON.stringify(mergeDefaults(state))
301
+ } catch {
302
+ return Promise.resolve(false)
303
+ }
304
+ const tmp = tempPath()
305
+ const job = queue.then(async () => {
306
+ try {
307
+ if (!writeFn || !renameFn) return false
308
+ await ensureDir()
309
+ await writeFn(tmp, json, { encoding: 'utf8', mode: 0o600, flush: true })
310
+ await renameFn(tmp, target)
311
+ return true
312
+ } catch {
313
+ try { if (unlinkFn) await unlinkFn(tmp) } catch { /* ignore */ }
314
+ return false
315
+ }
316
+ })
317
+ queue = job.catch(() => true) // 双保险:即便未来改动引入 reject 也不阻塞队列
318
+ return job
319
+ }
320
+
321
+ // 恢复默认:删掉持久化文件;不存在视为成功,其余错误 fail-open 返回 false。
322
+ function reset() {
323
+ const job = queue.then(async () => {
324
+ if (!unlinkFn) return true
325
+ try {
326
+ await unlinkFn(target)
327
+ return true
328
+ } catch (err) {
329
+ return looksNotFound(err) ? true : false
330
+ }
331
+ })
332
+ queue = job.catch(() => true)
333
+ return job
334
+ }
335
+
336
+ return {
337
+ filePath: target,
338
+ load,
339
+ save,
340
+ reset,
341
+ validate: validateState,
342
+ mergeDefaults,
343
+ }
344
+ }
@@ -0,0 +1,107 @@
1
+ # origin: dsh-agent/deepseek-v4.1-flash | 2026-11-29T09:10:00+08:00 | 回滚 install-aumid.ps1 的系统改动;只删本插件创建的快捷方式,不删别人的 DSH.lnk
2
+ #
3
+ # 归属保护(评审 P0-3):
4
+ # 优先读旁路标记 %LOCALAPPDATA%\dsh-notification\aumid-install.json,只删它记录的 lnk 路径;
5
+ # 标记不存在时按历史安装处理:仅当 DSH.lnk / DSH Notification.lnk 的
6
+ # PKEY_AppUserModel_ID 等于本插件 AUMID(DshNotification)才删除。
7
+ # 因此别人建的 DSH.lnk 不会被删。
8
+ #
9
+ # 幂等:什么都没装时输出 NOT_INSTALLED 并返回 0;出错返回 1 且输出中文原因。
10
+ $ErrorActionPreference = 'Stop'
11
+
12
+ $AUMID = 'DshNotification'
13
+ $DISPLAY = 'DSH'
14
+ $key = "HKCU:\Software\Classes\AppUserModelId\$AUMID"
15
+ $markerDir = Join-Path $env:LOCALAPPDATA 'dsh-notification'
16
+ $markerFile = Join-Path $markerDir 'aumid-install.json'
17
+ $lnkDir = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs'
18
+ $defaultLnk = Join-Path $lnkDir "$DISPLAY.lnk"
19
+ $fallbackLnk = Join-Path $lnkDir "$DISPLAY Notification.lnk"
20
+
21
+ # 读 lnk 的 PKEY_AppUserModel_ID(Shell 属性 System.AppUserModel.ID)。
22
+ # 实测:C# 里对 ShellLink 的 IPropertyStore::GetValue 读回 vt=0(拿不到值),
23
+ # 而 Shell.Application 的 ExtendedProperty 能稳定读到,所以这里用后者。
24
+ $script:ShellApp = $null
25
+ function Get-LnkAumid([string]$lnkPath) {
26
+ try {
27
+ if (-not $script:ShellApp) { $script:ShellApp = New-Object -ComObject Shell.Application }
28
+ $folder = $script:ShellApp.Namespace((Split-Path -Parent $lnkPath))
29
+ if (-not $folder) { return $null }
30
+ $item = $folder.ParseName((Split-Path -Leaf $lnkPath))
31
+ if (-not $item) { return $null }
32
+ $v = $item.ExtendedProperty('System.AppUserModel.ID')
33
+ if ($null -eq $v) { return $null }
34
+ $s = ([string]$v).Trim()
35
+ if ($s.Length -eq 0) { return $null }
36
+ return $s
37
+ } catch {
38
+ return $null
39
+ }
40
+ }
41
+
42
+ try {
43
+ if (-not $env:LOCALAPPDATA) { throw 'LOCALAPPDATA 为空,无法定位安装标记(请用当前用户身份运行)' }
44
+
45
+ $removed = New-Object System.Collections.ArrayList
46
+ $kept = New-Object System.Collections.ArrayList
47
+
48
+ # 1) 清通知中心里本 AUMID 的历史通知(非致命)
49
+ try {
50
+ [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType=WindowsRuntime] | Out-Null
51
+ $hist = [Windows.UI.Notifications.ToastNotificationManager]::History
52
+ $hist.Clear($AUMID)
53
+ } catch { Write-Output 'note: could not clear toast history (non-fatal)' }
54
+
55
+ # 2) 删快捷方式:有标记只删标记记录的路径;无标记只删 AUMID 确实是本插件的
56
+ $recorded = $null
57
+ if (Test-Path -LiteralPath $markerFile) {
58
+ try { $recorded = Get-Content -LiteralPath $markerFile -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $recorded = $null }
59
+ }
60
+
61
+ if ($recorded -and $recorded.lnkPath) {
62
+ $p = [string]$recorded.lnkPath
63
+ if (Test-Path -LiteralPath $p) {
64
+ $owner = Get-LnkAumid $p
65
+ if ($owner -eq $AUMID) {
66
+ Remove-Item -LiteralPath $p -Force
67
+ [void]$removed.Add($p)
68
+ } else {
69
+ [void]$kept.Add("$p(AUMID=$owner,已不是本插件的快捷方式,保留)")
70
+ }
71
+ }
72
+ } else {
73
+ # 历史安装没有标记:逐个候选核对 AUMID,只删确实是本插件的
74
+ foreach ($p in @($defaultLnk, $fallbackLnk)) {
75
+ if (Test-Path -LiteralPath $p) {
76
+ $owner = Get-LnkAumid $p
77
+ if ($owner -eq $AUMID) {
78
+ Remove-Item -LiteralPath $p -Force
79
+ [void]$removed.Add($p)
80
+ } else {
81
+ [void]$kept.Add("$p(AUMID=$owner,不是本插件创建的,保留)")
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ # 3) 删注册表键(键名就是本插件 AUMID,属于自己)
88
+ if (Test-Path $key) {
89
+ Remove-Item -Path $key -Recurse -Force
90
+ [void]$removed.Add("HKCU:\Software\Classes\AppUserModelId\$AUMID")
91
+ }
92
+
93
+ # 4) 删安装标记(最后一步,失败时标记还在,下次还能重试)
94
+ if (Test-Path -LiteralPath $markerFile) { Remove-Item -LiteralPath $markerFile -Force }
95
+ if ((Test-Path -LiteralPath $markerDir) -and -not (Get-ChildItem -LiteralPath $markerDir -Force | Select-Object -First 1)) {
96
+ Remove-Item -LiteralPath $markerDir -Force
97
+ }
98
+
99
+ foreach ($k in $kept) { Write-Output "KEPT=$k" }
100
+ if ($removed.Count -eq 0) { Write-Output 'NOT_INSTALLED: 没有找到本插件的通知身份或快捷方式,无需卸载' }
101
+ else { foreach ($r in $removed) { Write-Output "REMOVED=$r" } }
102
+ Write-Output "AUMID_UNINSTALLED aumid=$AUMID"
103
+ exit 0
104
+ } catch {
105
+ [Console]::Error.WriteLine("失败:$($_.Exception.Message)")
106
+ exit 1
107
+ }
@@ -0,0 +1,19 @@
1
+ # origin: opencode-agent/hy4-flash-free | 2026-11-26T12:00:00+08:00 | remove HKCU dshnotify protocol only when marked as ours
2
+
3
+ # Exact rollback: only removes a registration this plugin created.
4
+ $ErrorActionPreference = 'Stop'
5
+ $key = 'HKCU:\Software\Classes\dshnotify'
6
+ $markerName = 'DshNotifyManagedBy'
7
+ $marker = 'dsh-notification'
8
+
9
+ if (-not (Test-Path -LiteralPath $key)) {
10
+ Write-Output 'NOOP: dshnotify was not registered'
11
+ exit 0
12
+ }
13
+ $existing = (Get-ItemProperty -LiteralPath $key -Name $markerName -ErrorAction SilentlyContinue).$markerName
14
+ if ($existing -ne $marker) {
15
+ Write-Output "REFUSED: dshnotify is owned by someone else (marker=$existing). No changes made."
16
+ exit 1
17
+ }
18
+ Remove-Item -LiteralPath $key -Recurse -Force
19
+ Write-Output 'REMOVED: dshnotify registration'