dsh-ntfy-notifier 0.0.0-stage → 1.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 ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 liangfu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,194 @@
1
- # Temporary Holding Version
1
+ # dsh-ntfy-notifier-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 把 ntfy 消息转换为 Windows 本机通知的 DeepSeek Harness(DSH)插件。
4
+
5
+ 插件直接在 Host 进程中用 Node 内置 `http`/`https` 订阅 ntfy 的 JSON 流,不依赖 `ntfy.exe`。支持配置多个 ntfy 服务器,每个服务器可配置多个频道,每个「服务器 + 频道」组合独立连接、独立重连。
6
+
7
+ 插件包名是 `dsh-ntfy-notifier`;安装后由 DSH 插件管理器按本地目录或 npm 包加载。
8
+
9
+ > **AI 开发说明**:本插件由 AI 开发,代码和文档由 AI 生成并整理。使用前请自行审查代码、配置和运行行为。
10
+
11
+ ## 功能
12
+
13
+ - 多个 ntfy 服务器,每个服务器多个频道
14
+ - 每个服务器地址、每个频道各用一个输入框;点 `+` 添加新服务器或新频道
15
+ - 订阅 ntfy 的 JSON 流,断线后指数退避重连
16
+ - 使用最后一条消息 ID 续订,并按消息 ID 去重
17
+ - 支持 `title`、`message`、`priority`
18
+ - 优先级 4/5 可选用系统闹钟铃声,其他优先级使用普通提示音
19
+ - 消息通过 base64 JSON 传给 PowerShell,避免命令行和 XML 注入
20
+ - 支持全局 Bearer Token,也支持每个服务器节点单独配置并覆盖全局 Token
21
+ - 配置页按频道显示运行状态:等待、订阅完成、心跳正常、连接失败
22
+ - 插件停用或 DSH 退出时关闭连接和通知进程
23
+
24
+ ## 环境要求
25
+
26
+ - Windows 10/11
27
+ - DeepSeek Harness(支持 `dsh.client` 与 `plugins.row.config` 的版本)
28
+ - Windows PowerShell 5.1(系统自带)
29
+ - Node.js 24 或 DSH 自带的运行时
30
+ - pnpm(安装 `@deepseek-ai/schemastery` 依赖时需要)
31
+
32
+ ## 安装
33
+
34
+ 1. 将插件目录放到本地任意位置,并在该目录中安装依赖:
35
+
36
+ ```powershell
37
+ cd <插件目录>
38
+ pnpm install --ignore-scripts
39
+ ```
40
+
41
+ 2. 在 DSH 的 **插件** 页面选择 **添加插件 → 安装第三方插件**,填入本目录的绝对路径。
42
+ 3. 安装完成后打开 `ntfy 系统通知` 的详情,在插件行 `ntfy-notifier` 点 **配置**。
43
+ 4. 填入自己的 ntfy 服务器地址和频道,保存。
44
+
45
+ > 如果配置页没有出现,先刷新一次 Web GUI。首次安装时如果客户端模块已被缓存为“无界面”,DSH 可能需要重启后才能重新扫描客户端模块。
46
+
47
+ ## 配置
48
+
49
+ ### 通过界面配置
50
+
51
+ 入口:**左侧栏「插件」→ `ntfy 系统通知` → 插件行 `ntfy-notifier` → 「配置」**。
52
+
53
+ 配置页按服务器分组:
54
+
55
+ ```text
56
+ 服务器 1
57
+ 服务器地址: [http://127.0.0.1:2586]
58
+ 访问令牌: [留空则使用全局令牌]
59
+ 频道: [message] [alerts] [+ 添加频道]
60
+
61
+ 服务器 2
62
+ 服务器地址: [https://ntfy.example.com]
63
+ 访问令牌: [可填写该服务器自己的令牌]
64
+ 频道: [system] [+ 添加频道]
65
+
66
+ [+ 添加服务器] [保存]
67
+ ```
68
+
69
+ - 每个服务器地址是一个输入框
70
+ - 每个服务器可以单独填写访问令牌;留空时使用全局 `accessToken`
71
+ - 每个频道也是一个独立输入框
72
+ - 点 **+ 添加频道** 给当前服务器增加频道输入框
73
+ - 点 **+ 添加服务器** 增加一组服务器和频道输入框
74
+ - 可移除服务器或单个频道
75
+ - 保存后 Host 会更新配置并重新建立订阅
76
+
77
+ ### 通过 YAML 配置
78
+
79
+ 在 `cordis.patch.yml` 中覆盖插件条目的 `config`:
80
+
81
+ ```yaml
82
+ - id: ntfy-notifier
83
+ name: 'dsh-ntfy-notifier'
84
+ config:
85
+ servers:
86
+ - url: 'http://127.0.0.1:2586'
87
+ topics:
88
+ - message
89
+ - alerts
90
+ accessToken: ''
91
+ - url: 'https://ntfy.example.com'
92
+ topics:
93
+ - system
94
+ accessToken: 'server-token'
95
+ accessToken: 'global-token'
96
+ appId: 'ntfy'
97
+ sound: true
98
+ highPriorityAlarm: true
99
+ reconnectDelaySeconds: 5
100
+ maxReconnectDelaySeconds: 60
101
+ ```
102
+
103
+ | 字段 | 默认值 | 说明 |
104
+ |---|---|---|
105
+ | `servers` | 一个本地服务器和一个 `message` 频道 | 服务器列表,每项包含 `url`、该服务器的 `topics` 和可选的 `accessToken` |
106
+ | `servers[].accessToken` | 空 | 可选,该服务器自己的 Bearer Token;非空时覆盖全局 `accessToken` |
107
+ | `accessToken` | 空 | 可选,全局 Bearer Token;服务器节点没有填写 `accessToken` 时使用 |
108
+ | `appId` | `ntfy` | Windows Toast 的 AUMID;未注册时自动回退到 `Microsoft.Windows.PowerShell` |
109
+ | `sound` | `true` | 是否播放通知声音 |
110
+ | `highPriorityAlarm` | `true` | 优先级 4/5 是否使用系统闹钟铃声 |
111
+ | `reconnectDelaySeconds` | `5` | 首次重连等待秒数 |
112
+ | `maxReconnectDelaySeconds` | `60` | 指数退避上限 |
113
+
114
+ 频道名不要包含空格或斜杠。如果使用反向代理子路径,`url` 填到子路径为止,例如 `https://ntfy.example.com/ntfy`,插件会请求 `https://ntfy.example.com/ntfy/<channel>/json`。
115
+
116
+ ### 运行状态
117
+
118
+ 配置页的每个频道旁会显示当前运行状态:
119
+
120
+ | 状态 | 颜色 | 含义 |
121
+ |---|---|---|
122
+ | 等待 | 黄色 | 正在连接,或等待重连 |
123
+ | 订阅完成 | 绿色 | 已收到 ntfy 的 `open` 事件 |
124
+ | 心跳正常 | 绿色 | 已收到 keepalive 或消息 |
125
+ | 连接失败 | 红色 | 连续 3 次心跳检查没有收到任何数据 |
126
+
127
+ 心跳检查每 45 秒执行一次;连续 3 次没有活动(约 135 秒)会标记为连接失败并触发重连。任何 keepalive 或消息都会重置心跳计数。
128
+
129
+ 状态由 Host 提供给配置页,不包含 Token、Authorization 头或完整服务器地址。
130
+
131
+ ## 工作原理
132
+
133
+ 1. 对每个「服务器 + 频道」组合请求 `<server>/<channel>/json`,读取换行分隔的 JSON 事件。
134
+ 2. 只处理 `event: "message"`,忽略 `open`、`keepalive` 等控制事件。
135
+ 3. 通过 `notify.ps1` 调用 Windows WinRT `ToastNotificationManager` 弹出通知。
136
+ 4. 消息标题和正文先做控制字符清理、长度截断,再以 base64 UTF-8 JSON 传给 PowerShell;PowerShell 使用 `SecurityElement.Escape` 转义 XML。
137
+ 5. 连接断开、超时或出错后按指数退避重连;续订参数使用最后一条消息的 `id`。
138
+
139
+ ## 安全说明
140
+
141
+ - 不使用外部 `ntfy.exe`,减少一个可执行文件依赖。
142
+ - 消息内容不拼接进 PowerShell 命令行,也不直接拼进 XML,避免命令和 XML 注入。
143
+ - `accessToken` 和 `servers[].accessToken` 会以明文保存在 DSH 的 profile 配置中;请确保本机账号和 profile 文件权限可信。
144
+ - 未配置服务器级 `accessToken` 的服务器会使用全局 `accessToken`;如果某台服务器不受信,建议不要设置全局令牌,或为每个服务器配置独立令牌。
145
+ - 局域网 HTTP 不加密。跨网络部署建议使用 HTTPS,并配置访问令牌。
146
+ - 插件只读取 ntfy 消息并将其显示为本机通知,不执行消息内容。
147
+
148
+ ## 开发与验证
149
+
150
+ ```powershell
151
+ # 安装运行时依赖
152
+ pnpm install --ignore-scripts
153
+
154
+ # 语法检查
155
+ node --check index.js
156
+ node --check client.js
157
+
158
+ # PowerShell 助手语法检查
159
+ $tokens = $null
160
+ $errors = $null
161
+ [System.Management.Automation.Language.Parser]::ParseFile(
162
+ (Resolve-Path '.\notify.ps1'),
163
+ [ref]$tokens,
164
+ [ref]$errors
165
+ ) | Out-Null
166
+ if ($errors.Count) { $errors | ForEach-Object Message; exit 1 }
167
+ ```
168
+
169
+ 本地测试 Windows 通知助手(会实际弹出一条通知):
170
+
171
+ ```powershell
172
+ $json = '{"title":"ntfy test","message":"notify.ps1 works","priority":3,"appId":"ntfy","sound":true,"alarm":true}'
173
+ $b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($json))
174
+ powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\notify.ps1 -PayloadBase64 $b64
175
+ ```
176
+
177
+ ## 故障排查
178
+
179
+ - **配置页看不到**:刷新 Web GUI;确认插件行是 `ntfy-notifier` 且处于启用状态;确认配置页的客户端模块已经加载。
180
+ - **没有通知**:检查 Windows 通知权限、专注助手/勿扰模式,以及 `appId` 是否被系统接受;可先用上面的助手命令测试。
181
+ - **连接失败**:确认服务器地址、频道名、反向代理路径,以及该服务器的 `servers[].accessToken` 或全局 `accessToken`;查看 DSH Host 日志中的 `ntfy:` 前缀。
182
+ - **频道重复**:同一个 URL 只会建立一条连接,重复频道会被去重。
183
+
184
+ ## 限制
185
+
186
+ - 插件仅在 DSH 运行期间监听,不是常驻 Windows 服务。
187
+ - 当前只实现 Windows Toast;其他平台会记录警告但不会弹窗。
188
+ - 首次连接只接收新消息,不补发历史消息。
189
+ - 服务器节点没有填写 `accessToken` 时,会回退到全局 `accessToken`。
190
+ - 配置页依赖 DSH 的 `plugins.row.config` 和 `settings` 服务;也可以通过 YAML 配置。
191
+
192
+ ## 许可证
193
+
194
+ MIT,见 [LICENSE](LICENSE)。