dsh-balance-sentinel 0.1.3 → 0.1.6

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 CHANGED
@@ -3,6 +3,60 @@
3
3
  All notable changes to this project are documented here. Format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/); versions follow [SemVer](https://semver.org/).
5
5
 
6
+ ## [0.1.6] - 2026-11-20
7
+
8
+ ### Changed
9
+
10
+ - **移除推送尾注的内置安装链接与面板开关**:`DEFAULT_SIGNATURE` / `INSTALL_SPEC` / `REPO_URL` 常量与 `POST /notify` 路由一并删除,摘要卡片和配置表单里都不再有「附上安装链接」勾选框。只保留用户自己写的 `notify.signatureText`(填了就作为推送最后一段附上)与显式关闭偏好:配置里的 `signature: false`,或旧版本面板写进状态文件的 `state.notify.signature: false`,仍会压掉自定义尾注。
11
+ - **旧勾选记录不再产生推广内容**:早期面板勾选写入的 `signature: true` 现在完全惰性——内置安装行已不存在,它既不会追加任何内容,也不会重新打开尾注;配置里的 `signature: true` 同样仅保留兼容(旧 profile 仍可加载),单独存在时不产生尾注。
12
+ - **推送卡片按参考稿重排**:地址行带上「当前地址:」标签(如 `当前地址:open.feishu.cn`),不再是裸主机名;「低余额/恢复通知将推送到这里,保存即生效,无需重启。」从配置表单移回摘要卡片、作为副标题一句话(编辑表单里不再重复)。测试时间不回到卡片上——何时测试、是否通过由标题行的状态徽章表达。
13
+
14
+ ### Fixed
15
+
16
+ - **纯文本通道不再丢尾注里的链接目标**:`toPlainText()` 把 `[文字](URL)` 压成 `文字 URL`(此前只留文字)。Telegram、Bark 与飞书纯文本回落不渲染 markdown,用户自定义尾注里的链接因此变成点不动的死标签。告警正文本身不含 markdown 链接,裸 URL 仍然原样保留。
17
+ - **超长自定义尾注不再导致告警重复发送**:`signatureText` 超过 200 字会被截断(加 `…`)。分块发送以整条消息为单位重试,尾注过长会把告警撑成多块,某块失败重试时已送达的块会被原样重发;截断后告警恒为单块(正文几百字,余量充足),重试不再复制已到账的内容。
18
+ - **YAML 反写阈值不再绕过校验**:面板拒绝 `warn ≤ critical`,但 YAML 无法拒绝(整体拒载会让插件失效)。现在合并面板与 YAML 配置后统一归一化(`effectiveThresholds`):反写的阈值对自动对调(`warn` 本义是更高的一条线),非正数回落默认值(20/5)。分类、恢复判定、`/status` 与面板展示读的都是同一处合并结果,不再出现「写反后以告急线当预警线」的错乱。
19
+ - **相等的阈值对不再直接告急**:`warn: 10`、`critical: 10` 时对调仍是原值,余额一旦低于 10 就跳过预警直接告急。相等对无法通过对调修复(也没有自洽读法),现在与非法值一样回退默认 20/5;`/status` 额外带 `thresholdsAdjusted` 标记,面板在阈值卡片上提示「配置里的预警与告急阈值相等……请修正配置」,输入框直接给出生效的默认值,点保存即可修正。提示状态下「保存阈值」不再灰置——给出的默认值与显示值相等,按「仅改动才可保存」的规则按钮会一直禁用,恰恰在最需要保存的时候点不了;现在异常状态本身视为可保存,保存 20/5 后提示随之消失。
20
+ - **尾注截断不再切坏链接和 emoji**:截断从 UTF-16 码元改为按码点计数(`Array.from`),emoji 这类增补平面字符不会再被切成孤代理;同时截断点若落在 Markdown 链接内部(标签、URL、乃至 `]`/`(` 之间被切开),整条链接省略而不是留半截 `[文字](url` 渲染成乱码。链接定位与截断始终在同一个码点数组上进行——丢弃链接时按码点下标切数组再拼接,而不是对拼好的字符串按 UTF-16 单元再切一次,否则 emoji 紧挨被丢弃的链接时仍会被切坏。裸 `[标签]` 是普通文本不受影响;容量以内的链接原样保留。
21
+
22
+ ### Tests
23
+
24
+ - `node scripts/selftest.mjs`:82 passed / 0 failed。F2 增加 `toPlainText` 的链接与裸 URL 断言;F7 用模拟推送走 Telegram 与 Bark 适配器,断言尾注里的标签与 URL 都到达、且不残留 `](`。F8 断言超长尾注被截断且不触发分块(含去修复即失败的探针验证),并覆盖码点截断(emoji 不切成孤代理)与链接截断(容量内的链接原样保留,容量外的整条省略),另加「emoji 紧挨被丢弃链接」的回归断言;F9 断言 YAML 反写 `{warn:5, critical:20}` 归一化为 `{warn:20, critical:5}`、相等对 `{warn:10, critical:10}` 回退默认 20/5 且 `thresholdsMisconfigured` 置位、面板偏好仍优先、偏好的 `null` 回落到 YAML 值、非正数回落默认值。其余 F2/F4/F5/B6b/B6c 围绕「没有内置尾注」:未被用户填写文本的告警、恢复通知、测试推送都不带安装链接或 `github:` 字样;`signature: true` 单独存在时不产生尾注,旧 state 里的 `true` 也不会;`signature: false`(配置或旧 state)仍压掉自定义文案;`POST /notify` 返回 404;源码层面断言 `lib/notify.js` 不再包含 `DEFAULT_SIGNATURE` / `INSTALL_SPEC`。
25
+ - `node scripts/selftest-client.mjs`:40 passed / 0 failed。P35/P37 改为断言摘要卡片与编辑表单都没有 `sentinel-sig` 开关、也没有「附上安装链接」文案;假桥接删除了 `/notify` 路由,客户端若再调用会直接让用例失败;P36 断言元信息行只有带标签的地址(`当前地址:open.feishu.cn`),摘要卡片副标题含保存说明句、表单里不再出现;P40 断言 `thresholdsAdjusted` 时阈值卡片显示配置有误提示、输入框给出默认 20/5、「保存阈值」可点且提交 20/5、标记清除后提示消失。
26
+ - `node scripts/verify-dedup.mjs`:推送计数 1(应为 1)。`node scripts/verify-market.mjs`:3 passed。`npm pack` 解包检查 7/7,含「包内不含内置安装行、不含已移除的开关文案、打包副本的纯文本扁平化保留链接目标」。
27
+
28
+ ## [0.1.5] - 2026-11-20
29
+
30
+ ### Changed
31
+
32
+ - **首次进入不再自动展开配置表单**:未配置推送通道时由顶部横幅(「监控中,通知未接通」+「现在配置」)说明并引导,表单只在点击后出现。此前进入面板即摊开一个空表单,与横幅说的是同一件事,且点「刷新」会把用户已经关掉的表单再次弹出;表单内重复的空态说明一并去掉,未配置时该卡片的入口按钮从「仅保存」改为「配置推送」(它本来也只是打开表单,并未保存任何东西;文案与同作者的 dsh-aihot-radar 对齐,横幅 CTA 仍为「现在配置」);同时未配置的表单也有了「取消」,点开看一眼或误点都能退出,不提交任何内容。
33
+ - **署名与安装尾注改为默认关闭**:低余额告警、恢复通知和测试推送在未显式开启时不再附带任何推广尾注,推送内容只讲余额。`notify.signature` 现在保留「未设置 / `true` / `false`」三态——不设默认值,避免宿主配置库把未填写补成 `false`、连带丢弃只配了 `signatureText` 的老用户的自定义尾注;只写 `signatureText` 视为开启,`signature: false` 优先于它。面板推送卡片新增「附上插件安装链接」勾选框(默认关闭,写入状态文件,不用改 YAML),`/status` 与发送端都按合并后的实际状态执行。README 中英示例配置同步为 `signature: false` 并说明三态。
34
+ - **推送卡片收紧为「一行一件事」**:地址与测试时间合并成 `open.feishu.cn · 11:31:49`(成功/失败已由标题右侧徽章表达,不再重复写「最近测试成功:」),失败原因单独一行,「低余额/恢复通知将推送到这里,保存即生效,无需重启」移到配置表单底部(那里才在解释保存行为)。安装链接开关保留自己一行并带完整说明「附上安装链接(默认关闭,开启后告警尾部会多一行署名)」,动作按钮仍在其下方左对齐,且「修改」与「发送测试推送」改用同一按钮样式(不再一实一描边);配置表单里开关与按钮之间补了 10px 间距。摘要态由 6 行减到 4 行。
35
+ - **告警标题带上插件名**:`余额哨兵 · DeepSeek 余额告急/预警/告警已解除/已恢复`。尾注默认关闭后,被转发到群里的卡片仍需能自解释来源,前缀足够短,不会被 IM 标题截断。
36
+
37
+ ### Fixed
38
+
39
+ - **尾注开关不再被旧实例改回**:`notify` 之前不在状态合并与写入保护里,面板关掉尾注后,另一个仍持有旧内存的实例只要保存一次常规状态(如余额),磁盘就会被写回「跟随配置」,等于把开关重新打开。现在读取合并(`mergeStateFromDisk`)会采纳磁盘值,写入(`SECTIONS`)把 `notify` 当作面板独占字段——不拥有它的保存方一律沿用文件内容,开启与关闭两个方向都成立。
40
+ - **取消编辑后「修改」按钮不再留一圈亮边**:表单里的「关闭推送」与摘要态的「修改」在按钮行中同处一个位置,React 复用同一个 DOM 节点;「关闭推送」额外用 `borderColor` 覆盖描边颜色,回到摘要态时该覆盖被清除,复用的按钮失去自己的内联描边色、退回 `currentColor`(再叠加品牌色 hover 规则就是一圈亮蓝描边),看起来像还停在选中态。该按钮改用 `border` 简写声明描边;面板内按钮的 hover 不再改描边色,焦点环只留给键盘(`:focus-visible`),鼠标点击不残留。
41
+ - **迟到的 `/status` 不再改回开关**:面板保存尾注开关成功后递增配置版本,保存之前发出的轮询响应整体丢弃(与保存 Webhook 同一规则),复选框不会在用户眼前跳回旧值。
42
+ - **旧查询不再覆盖新余额**:两个实例(或 poke 与在途轮询)的查询可能反序返回。轮询结果现在以「查询发起时刻」为序落地:拿到锁并合并磁盘状态后,若已记录的结论发起得不早于本轮(含同一毫秒的平局),整轮结果直接丢弃——不回写余额、不改告警等级、不触发推送,也不写盘。时间戳只有毫秒精度,两个实例可能在同一毫秒发起查询,此时谁先落盘谁就代表面板已展示的事实,宁可少落一次也不回滚。
43
+ - **丢弃旧响应后仍会自动轮询**:上一版的早退 `return` 跳过了周期末尾的 `setTimeout`,被丢弃的那台实例会就此停摆,只能靠手动刷新唤醒。定时器改为在 `finally` 里重排,任何提前返回(旧响应、停止时竞态)都不会让实例静默停转。
44
+ - **损坏的锁不再永久阻塞**:锁文件不可读(创建后未写完、写入被截断)此前一律无法接管,等于此后所有实例都不再写入和推送。锁龄现在优先取心跳时间戳、读不到时退回文件 mtime,只有「不可读且超过 TTL」才接管;刚创建尚未写完的锁与仍有效的锁都不会被抢,一直被占的写方靠 token 校验自动放弃。接管守卫文件损坏时同样按 mtime 自愈。
45
+ - **停止监控后不再发送**:`stop()` 发生在查询在途时,返回的余额此前仍会走完判定并推送。现在查询返回后先校验停止标志,已停止则本轮既不落盘也不推送。
46
+ - **失败轮询不再把旧余额当当前余额发送**:本轮查询失败时 `balance.ok` 为 false,此前待发告警仍会带着上一次的数字发出去。现在告警保留在待发槽里,等下一次查询成功、按新余额重新判定后再发。
47
+ - **宿主未登录时 API Key 回退恢复**:`signed-out` 此前会短路返回,即使配置了 Key 也走不到备用接口,与 README「否则用 `DEEPSEEK_API_KEY` 或 `balance.apiKey`」相违。现在只有「没有 Key」才报未登录;两者都不可用时面板文案改为「未登录且无可用 Key」,并写明登录与配置 Key 两条路径。
48
+ - **通知来源更正**:Bark 的 `group` 与通用 Webhook 的 `source` 从 `aihot-radar` 改为 `balance-sentinel`。
49
+
50
+ ### Tests
51
+
52
+ - `node scripts/selftest.mjs`:79 passed / 0 failed。本轮新增 12 条:C1-C4 覆盖锁恢复(过期且不可读可接管、刚创建的空锁与心跳新鲜的锁不得被抢、可读但超 TTL 仍可接管);R1 让两个实例反序返回(先发后答 vs 后发先答)断言旧结果不推送、不回写余额、不改等级;R1b 用 1s 轮询下限(测试专用环境变量 `SENTINEL_POLL_FLOOR_SEC`,生产仍是 60s)验证被丢弃的一轮之后仍会自动跑下一轮;R1c 冻结 `Date.now` 制造同毫秒平局,断言已接受的 ¥30 不会回滚成 ¥3、不告警,且该轮标记为 stale;R2 在查询在途时停止监控,断言返回后不推送不落盘;R3 断言查询失败时待发告警保留、下一次成功查询后才发出;S10/S11 覆盖宿主未登录时走 REST Key、Key 被拒时如实报 `unauthorized`;F6 断言 Bark `group` 与通用 Webhook `source` 均为 `balance-sentinel`。另外仍覆盖三种署名情况——默认关闭(默认测试消息、`critical`/`warn` 告警、`recovered` 恢复通知正文均无 `安装:`、安装 spec 与仓库地址)、显式开启(`signature: true` 正常附上尾注,Feishu 走 `lark_md` note,纯文本通道只留标签)、显式关闭(`signature: false` 即使带 `signatureText` 也不附带)。F1b 断言四类标题都以「余额哨兵 · 」开头且保留告急/预警/恢复/解除字样;F4 先用源码断言 `notify.signature` 不带任何默认值,再在装有宿主 Schema 包时用真实配置解析验证 `{ notify: { signatureText } }` 解析后 `signature` 仍为 `undefined`、未配置解析为空即关闭、显式 `false`/`true` 各自生效(未安装该包时打印 SKIP,只跑源码断言);F5 覆盖面板覆盖值与 `null`(跟随配置)的合并;B6b/B6c 起本地 hook 抓桥接真实 POST 的 `/test-push` 正文,默认无尾注、`signature: true` 有尾注,并验证 `POST /notify` 后 `/status` 与发送内容同步翻转、关回去也生效。
53
+ - `node scripts/selftest-client.mjs`:39 passed / 0 failed(P35:面板开关默认未勾选、勾选后发出 `signature: true`、再由服务端回填为勾选态、取消勾选可回到关闭;P37:旧 `/status` 返回后复选框不得跳回旧值;P38:「关闭推送」不得引入 `borderColor` 覆盖、取消后「修改」仍自带描边、hover 规则不得把描边刷成品牌色、键盘焦点仍有焦点环)。
54
+ - 针对上述两个合并点的有效性验证:M15 使用真实临时状态文件,分别以 `false`/`true` 让面板实例写一次、再让「仍持有跟随配置值」的实例只保存 `alert`,断言磁盘值不变;再断言 `mergeStateFromDisk` 会采纳磁盘值。单独移除写入保护时 M15 报 `a routine save must not overwrite false`,单独移除读取合并时报 `mergeStateFromDisk must adopt false`。P37 移除配置版本递增后报 `a stale /status turned the footer switch back off`。
55
+ - 本轮六项修复的有效性验证(逐项回退修复后跑同一套回归):去掉「已记录结论更晚」的比较后 R1 报 `a superseded reading must not push`;去掉停止标志检查后 R2 报 `a stopped monitor must not push what an old query returned`;去掉 `balance.ok` 守卫后 R3 报 `the old number must not be sent as the current balance`;把 `signed-out` 重新放回短路条件后 S10/S11 同时失败;锁接管条件改回「读不到就放弃」后 C1 报 `an expired unreadable lock must not block forever`,改成「见锁就抢」后 C3 报 `a live lock with a fresh heartbeat is never taken over`;比较改回严格大于后 R1c 报 `a tie must not push`(余额从 ¥30 回落到 ¥3 并告急);定时器移回 `finally` 之外后 R1b 报 `the dropped cycle must still re-arm the poll (calls: 1)`。
56
+ - 打包产物检查(本轮):`npm pack` 解包后从 tarball 内 import 并执行 6 项检查,6/6 通过 —— 未登录 + Key 走 REST、`balance.ok=false` 时 `deliverPending` 返回 null 且保留 pending、Bark `group` 与通用 `source` 正确、过期且不可读的锁可恢复而新锁不被抢、`client.js` 与 `locale/*.json` 已随包、打包副本可正常读写状态。
57
+ - 打包产物检查(署名改动):对 `npm pack` 的 tarball 解包后直接 import 包内 `lib/notify.js` 与 `lib/balance.js`(不读工作区源码),14/14 通过 —— `index.js` 里 `notify.signature` 无默认值、`signatureLine({})` 为空、`signatureEnabled({ signatureText })` 为真、面板覆盖优先于配置、默认测试消息与 `critical`/`warn`/`recovered` 正文均不含尾注、三类告警标题均以「余额哨兵 · 」开头、显式开启时正常附上。
58
+ - LPM 的报告针对 0.1.2,本次改动未经重新扫描,不能据此认为相关拦截已解除。
59
+
6
60
  ## [0.1.3] - 2026-11-18
7
61
 
8
62
  ### Fixed
@@ -69,6 +123,7 @@ All notable changes to this project are documented here. Format follows
69
123
  - README 面板截图前置、补「先看三行」要点;适用范围与免 Key 边界并入安装节,不再单列小节。
70
124
  - GitHub About 描述收紧为一句:低余额推送 + 本机运行边界。
71
125
 
126
+ [0.1.5]: https://github.com/liancheng2020/dsh-balance-sentinel/releases/tag/v0.1.5
72
127
  [0.1.3]: https://github.com/liancheng2020/dsh-balance-sentinel/releases/tag/v0.1.3
73
128
  [0.1.2]: https://github.com/liancheng2020/dsh-balance-sentinel/releases/tag/v0.1.2
74
129
  [0.1.0]: https://github.com/liancheng2020/dsh-balance-sentinel/releases/tag/v0.1.0
package/README.en.md CHANGED
@@ -32,33 +32,31 @@ dsh plugin --profile web add github:liancheng2020/dsh-balance-sentinel
32
32
  # or npm (published to npm alongside each Release)
33
33
  dsh plugin --profile web add dsh-balance-sentinel
34
34
  # or the pinned Release tarball
35
- dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.3/dsh-balance-sentinel-0.1.3.tgz
35
+ dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.6/dsh-balance-sentinel-0.1.6.tgz
36
36
  ```
37
37
 
38
38
  Any one of the three is enough; if the npm/Release line is not live yet, use the first. Desktop app: Settings → Plugins → add `dsh-balance-sentinel` or `github:liancheng2020/dsh-balance-sentinel`. Restart DSH once.
39
39
 
40
40
  **Where it runs**: local DSH desktop or local web host only — monitoring lives in the DSH process and **stops when DSH exits** (reopening resumes from the local state file); **no remote web panel** (the bridge binds `127.0.0.1:17430` and only accepts pages from this machine). **Key-free host accounts are supported**: the host must expose the account service with a signed-in account (key-free ≠ account-free); otherwise use `DEEPSEEK_API_KEY` or `balance.apiKey` — with neither, the panel states the exact reason.
41
41
 
42
- > Current version `0.1.3` (see [CHANGELOG](CHANGELOG.md)).
42
+ > Current version `0.1.6` (see [CHANGELOG](CHANGELOG.md)).
43
43
 
44
44
  ## First use (two steps)
45
45
 
46
- 1. Open the **Balance Sentinel** panel: your real balance immediately, or a clear reason (signed out / no account service / network…).
47
- 2. Pick a channel, paste the webhook (auto-detected) → **Save and send test**. The Feishu/DingTalk form includes "How to get a bot webhook": official doc + three-step path + the security settings that channel supports. **Until a channel is saved it watches without pushing**.
46
+ 1. Open the **Balance Sentinel** panel: the official balance right away, or a clear reason (signed out / no account service / network…).
47
+ 2. Click **Set it up**, pick a channel, paste the webhook (auto-detected) → **Save and send test**. The Feishu/DingTalk form links the official bot-webhook doc and that channel's security settings.
48
48
 
49
- Saving only gets you to "configured, not tested"; the badge turns into "last test succeeded" once a test push actually lands, and into "last test failed" (with the reason and time) when it does not. Editing the channel or credentials clears the old result, so a stale "verified" can never pass for a working endpoint.
50
-
51
- If the balance is already below a threshold when you connect, one current-state notice is sent (once).
49
+ Until a channel is saved it watches without pushing. Saving only means "configured" — the badge turns into "last test succeeded" once a test push really lands, and "last test failed" (with the reason) when it does not; editing the channel clears the old result. If the balance is already below a threshold when you connect, one current-state notice is sent (once).
52
50
 
53
51
  ## How it works
54
52
 
55
- - **Two levels**: below 20 pushes "warn", below 5 pushes "critical" (account currency, panel-editable); a top-up or a threshold tweak back above warn pushes one "recovered"/"resolved" notice, effective immediately on save.
56
- - **No spam**: same level never repeats; a real top-up pushes "recovered" (10-min anti-flap cooldown); a threshold tweak that resolves a delivered alert pushes "resolved" immediately; undelivered alerts cancel silently; quiet hours defer and merge into a single push afterwards.
57
- - **Failures are traceable and retryable**: pending alerts persist; business failures back off 10 min and hold after 3 (manual retry in the panel); timeouts and dead response bodies are "delivery unconfirmed" — held immediately, never auto re-sent; a failed state save writes a fallback receipt, so restarts and multiple instances still do not re-send it (unconfirmed restores as held, never as sent). If neither the state nor the receipt can be written, the duplicate risk is logged explicitly.
58
- - **No wedge, no duplicate across instances**: host queries have a 15s deadline and the scheduler survives any exception; desktop + web sharing `DSH_HOME` push each transition exactly once (whole-cycle lock + disk merge).
59
- - **Channels**: WeCom / DingTalk / Feishu (card) / Bark / ServerChan / Telegram / generic webhook; auto-chunking; HTTP-200 business failures count as failures.
60
- - **Follows the host skin**: the panel reads `data-ds-dark-theme`, so a light skin gets white cards, hairline borders and a soft shadow, with badges, toasts and native select menus switching with it.
61
- - Balance is the **official account number**; v1 ships no cost estimates.
53
+ - **Two levels**: below 20 pushes "warn", below 5 pushes "critical" (account currency, panel-editable); a top-up or a threshold tweak back above warn pushes one "recovered"/"resolved" notice.
54
+ - **No spam**: same level never repeats; recovery has a 10-min anti-flap cooldown; undelivered alerts cancel silently; quiet hours defer and merge into a single push.
55
+ - **Failures are traceable**: pending alerts persist; business failures back off 10 min and hold after 3 (manual retry in the panel); unconfirmed delivery is held immediately and never auto re-sent; only when even the receipt cannot be written is the duplicate risk logged.
56
+ - **No wedge, no duplicates**: host queries have a 15s deadline and the scheduler survives any exception; instances sharing `DSH_HOME` push each transition once (whole-cycle lock + disk merge).
57
+ - **Channels & look**: WeCom / DingTalk / Feishu (card) / Bark / ServerChan / Telegram / generic webhook; auto-chunking; HTTP-200 business failures count as failures; the panel follows the host light/dark skin.
58
+
59
+ Balance is the **official account number**; v1 ships no cost estimates.
62
60
 
63
61
  ## Config (optional, profile cordis.patch.yml)
64
62
 
@@ -70,18 +68,18 @@ If the balance is already below a threshold when you connect, one current-state
70
68
  enabled: true
71
69
  pollSeconds: 60 # min 60
72
70
  warn: 20
73
- critical: 5
71
+ critical: 5 # must be below warn; an inverted pair is swapped, an equal pair falls back to 20/5
74
72
  timezone: Asia/Shanghai
75
73
  quiet: { start: "", end: "" } # e.g. "23:00"–"08:00"
76
74
  apiKey: "" # fallback for older hosts only
77
75
  notify:
78
- signature: true # "via …" footer line whose install spec is tappable, opt-out
79
- signatureText: ""
76
+ signatureText: "" # optional custom footer; only appended when non-empty; truncated past 200 chars
77
+ # signature: false # optional explicit opt-out: never append, even with the text above
80
78
  localApi:
81
79
  enabled: true # panel bridge on 127.0.0.1:17430
82
80
  ```
83
81
 
84
- Thresholds and channel are also editable in the panel; saving applies without a restart.
82
+ Thresholds and channel are also editable in the panel, so you never have to touch this file. The footer only ever comes from your own `signatureText` (no built-in install link, no panel switch); `signature: false` still turns it off explicitly.
85
83
 
86
84
  ## Privacy & compliance
87
85
 
package/README.md CHANGED
@@ -32,33 +32,31 @@ dsh plugin --profile web add github:liancheng2020/dsh-balance-sentinel
32
32
  # 或 npm(随 Release 一同发布到 npm)
33
33
  dsh plugin --profile web add dsh-balance-sentinel
34
34
  # 或 Release 固定版本 tarball
35
- dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.3/dsh-balance-sentinel-0.1.3.tgz
35
+ dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentinel/releases/download/v0.1.6/dsh-balance-sentinel-0.1.6.tgz
36
36
  ```
37
37
 
38
38
  三条任选一条即可;若 npm/Release 那条还没上线,用第一条。桌面端:设置 → 插件 → 添加插件,填 `dsh-balance-sentinel` 或 `github:liancheng2020/dsh-balance-sentinel`。装完重启一次 DSH。
39
39
 
40
40
  **适用环境**:仅本机 DSH Desktop/本机 Web,监控跑在 DSH 进程里、**退出即停**(重开从本机状态继续);**不支持远程 Web 面板**(桥接只绑 `127.0.0.1:17430`,只接受本机页面)。**支持宿主账号免填 Key**:宿主内置账号服务且已登录(免填 ≠ 无需账户),否则用 `DEEPSEEK_API_KEY` 或 `balance.apiKey`,都没有时面板给出明确原因。
41
41
 
42
- > 当前版本 `0.1.3`(见 [CHANGELOG](CHANGELOG.md))。
42
+ > 当前版本 `0.1.6`(见 [CHANGELOG](CHANGELOG.md))。
43
43
 
44
44
  ## 首次使用(两步接通)
45
45
 
46
- 1. 打开 **余额哨兵** 面板:立刻看到真实余额,或明确原因(未登录 / 无账号服务 / 网络…)。
47
- 2. 「推送配置」选通道 → 粘 webhook(自动识别)→ **保存并发送测试**。飞书/钉钉框内有「如何获取机器人 Webhook」:官方链接 + 三步路径 + 该通道适用的安全设置。**没配通道前只监控不推送**。
46
+ 1. 打开 **余额哨兵** 面板:直接看到官方余额,或明确原因(未登录 / 无账号服务 / 网络…)。
47
+ 2. 点「现在配置」→ 选通道 → 粘 webhook(自动识别)→ **保存并发送测试**。飞书/钉钉框内附「如何获取机器人 Webhook」与该通道适用的安全设置。
48
48
 
49
- 保存成功只说明通道「已配置,待测试」,测试推送真的送达才会变成「最近测试成功」;失败则显示「最近测试失败」并附原因与时间。改通道或凭据后旧结果立即清除,不会有残留的「已验证」冒充接通。
50
-
51
- 接通时余额已低于阈值,会补发一条当前状态(仅一次)。
49
+ 没配通道时只监控不推送。保存成功只代表「已配置」——测试真的送达才显示「最近测试成功」,失败会附原因;改通道后旧结果立即清除。接通时余额已低于阈值,会补发一条当前状态(仅一次)。
52
50
 
53
51
  ## 它怎么工作
54
52
 
55
- - **两级阈值**:默认低于 ¥20 推「预警」、低于 ¥5 推「告急」(账户币种,面板可改);充值或调阈值回到预警之上推一条「恢复/解除」,保存即生效。
56
- - **不刷屏**:同级停留不重推;充值回升推「恢复」(10 分钟冷却防抖),调阈值解除已送达告警立即推「解除」;告警未送达时静默取消;免打扰时段顺延、出窗合并成一条。
57
- - **失败可追踪、可重试**:待发送告警持久化;业务失败 10 分钟退避、3 次后挂起可手动重试;超时等「送达不确定」立即挂起、不自动重发;状态保存失败时落盘备用回执,重启/多实例恢复后仍不重发(不确定的恢复为挂起,不标记成功)。状态与回执都无法落盘时会明确告警「去重无法保证」。
58
- - **不卡死、多实例不重推**:宿主查询 15s 兜底,任何异常后调度继续;desktop + web 共享 `DSH_HOME` 时整周期锁 + 磁盘合并,同一跃迁只推一次。
59
- - **通道**:企微 / 钉钉 / 飞书(消息卡片)/ Bark / Server酱 / Telegram / 通用 Webhook;超长自动分条;HTTP 200 但业务失败同样判失败。
60
- - **跟随宿主深浅色**:面板读 `data-ds-dark-theme`,浅色皮肤用白卡片+细描边+轻投影,卡片、徽章、浮层与原生下拉菜单同步换色。
61
- - 余额来自**官方账户同源**,v1 不做成本估算。
53
+ - **两级阈值**:默认低于 ¥20 推「预警」、低于 ¥5 推「告急」(账户币种,面板可改);充值或调阈值回升推一条「恢复/解除」,保存即生效。
54
+ - **不刷屏**:同级不重推;恢复有 10 分钟冷却;告警未送达则静默取消;免打扰时段顺延、出窗合并成一条。
55
+ - **失败可追踪**:待发告警持久化;业务失败 10 分钟退避、3 次后挂起可手动重试;送达不确定立即挂起、不自动重发;连去重回执都写不下去时才提示「去重无法保证」。
56
+ - **不卡死、多实例不重推**:查询 15s 兜底,异常后调度继续;共享 `DSH_HOME` 时整周期加锁 + 磁盘合并,同一跃迁只推一次。
57
+ - **通道与外观**:企微 / 钉钉 / 飞书卡片 / Bark / Server酱 / Telegram / 通用 Webhook,超长自动分条、HTTP 200 但业务失败同样判失败;面板跟随宿主深浅色。
58
+
59
+ 余额来自**官方账户**,与官方余额页同源;v1 不做成本估算。
62
60
 
63
61
  ## 配置(可选,profile 的 cordis.patch.yml)
64
62
 
@@ -70,18 +68,18 @@ dsh plugin --profile web add https://github.com/liancheng2020/dsh-balance-sentin
70
68
  enabled: true # 关掉即停监控,面板仅展示
71
69
  pollSeconds: 60 # 最小 60
72
70
  warn: 20 # 预警阈值(账户币种)
73
- critical: 5 # 告急阈值
71
+ critical: 5 # 告急阈值,必须小于 warn;写反会自动对调,相等则回退默认 20/5
74
72
  timezone: Asia/Shanghai
75
73
  quiet: { start: "", end: "" } # 免打扰,如 "23:00"–"08:00"
76
74
  apiKey: "" # 仅老宿主回落用;优先宿主账号/环境变量
77
75
  notify:
78
- signature: true # 推送尾部署名(安装标识可点击),可关
79
- signatureText: ""
76
+ signatureText: "" # 可选:自定义尾注,只有填了内容才会附在推送尾部;超 200 字截断
77
+ # signature: false # 可选:显式关闭,即使上面填了尾注也不附加
80
78
  localApi:
81
79
  enabled: true # 面板桥接 127.0.0.1:17430,可关
82
80
  ```
83
81
 
84
- 阈值与通道也可在面板里改,保存即生效,无需重启。
82
+ 阈值与通道也能在面板里改,保存即生效——面板够用就不必动这份配置。推送尾注只来自你填的 `signatureText`(没有内置安装链接,也没有面板开关),`signature: false` 仍可显式关闭。
85
83
 
86
84
  ## 隐私与合规
87
85
 
Binary file
package/client.js CHANGED
@@ -54,7 +54,7 @@ window.__ModuleLoader__.load({
54
54
  'level.normal': '余额正常', 'level.warn': '余额预警', 'level.critical': '余额告急',
55
55
  'reason.title': '余额暂不可用', 'reason.retry': '重试',
56
56
  'reason.no-source': '宿主没有账号服务,也未提供 API Key。带官方「设置→账号与余额」的宿主支持免填 Key;否则在配置 balance.apiKey 或环境变量 DEEPSEEK_API_KEY 提供 Key。',
57
- 'reason.signed-out': '宿主未登录 DeepSeek 账户:请在官方「设置→账号与余额」登录后重试。',
57
+ 'reason.signed-out': '宿主未登录 DeepSeek 账户,也没有可用的 API Key:请在官方「设置→账号与余额」登录,或配置 balance.apiKey / 环境变量 DEEPSEEK_API_KEY 后重试。',
58
58
  'reason.unauthorized': 'API Key 无效或过期:请更新 Key,或改用宿主账号登录(免填 Key)。',
59
59
  'reason.account-failed': '宿主账号服务查询失败,稍后自动重试。',
60
60
  'reason.account-error': '宿主账号服务调用异常,稍后自动重试。',
@@ -70,23 +70,23 @@ window.__ModuleLoader__.load({
70
70
  'quiet.on': '免打扰 {s}–{e},期间告警顺延、出窗合并推送。',
71
71
  'th.title': '告警阈值', 'th.warn': '预警阈值', 'th.critical': '告急阈值', 'th.save': '保存阈值',
72
72
  'th.saved': '阈值已保存,立即生效。', 'th.bad': '需为正数,且预警阈值大于告急阈值。',
73
+ 'th.adjusted': '配置里的预警与告急阈值相等,无法区分预警和告急,已回退默认 20/5,请修正配置。',
73
74
  'th.hint': '低于预警值推「预警」,低于告急值推「告急」;充值或调阈值回到预警值之上推一条「恢复/解除」。告警未送达时静默取消,不补发。',
74
75
  'sec.push': '推送配置', 'push.channel': '推送通道:{c}', 'push.on': '已配置', 'push.off': '未配置',
75
76
  'push.untested': '已配置,待测试', 'push.verified': '最近测试成功', 'push.failed': '最近测试失败',
76
77
  'push.untestedHint': '通道已保存,但还没有测试过发送:点「发送测试推送」确认能收到,别等真告警时才发现地址不通。',
77
- 'push.verifiedAt': '最近测试成功:{t}',
78
- 'push.failedAt': '最近测试失败:{t}{e}',
78
+ 'push.failedWhy': '失败原因:{e}',
79
79
  'push.testStale': '测试期间推送配置已变更,本次结果未计入当前通道。',
80
80
  'push.notPersisted': '结果未写入状态文件,重启后会丢失。',
81
81
  'chan.none': '未配置', 'chan.wecom': '企业微信', 'chan.dingtalk': '钉钉', 'chan.feishu': '飞书',
82
82
  'chan.bark': 'Bark', 'chan.serverchan': 'Server酱', 'chan.telegram': 'Telegram', 'chan.generic': '通用 Webhook',
83
- 'push.hint': '低余额/恢复通知将推送到这里,保存即生效,无需重启。',
83
+
84
84
  'push.empty': '还没有配置推送通道。填好地址保存,余额不足时自动提醒到 IM。',
85
- 'push.current': '当前地址:{h}',
86
85
  'push.field.channel': '推送通道', 'push.field.url': 'Webhook 地址', 'push.field.token': 'Bot Token',
87
86
  'push.field.secret': '加签密钥(可选)', 'push.field.chat': 'chat_id',
88
87
  'push.saveTest': '保存并发送测试', 'push.save': '仅保存', 'push.saving': '保存中…',
89
- 'push.edit': '修改', 'push.cancel': '取消', 'push.saved': '已保存,立即生效。',
88
+ 'push.edit': '修改', 'push.setup': '配置推送', 'push.cancel': '取消', 'push.saved': '已保存,立即生效。',
89
+ 'push.address': '当前地址:{h}', 'push.hint': '低余额/恢复通知将推送到这里,保存即生效,无需重启。',
90
90
  'push.disable': '关闭推送', 'push.disableConfirm': '确认关闭?', 'push.disabled': '已关闭推送,可随时重新配置。',
91
91
  'push.test': '发送测试推送', 'push.testing': '发送中…',
92
92
  'push.testOk': '测试推送成功:{c} 通道正常,发出 {n} 条。',
@@ -105,7 +105,7 @@ window.__ModuleLoader__.load({
105
105
  'level.normal': 'Balance OK', 'level.warn': 'Low balance', 'level.critical': 'Critical balance',
106
106
  'reason.title': 'Balance unavailable', 'reason.retry': 'Retry',
107
107
  'reason.no-source': 'No host account service and no API key. Hosts with the official "Account & Balance" page support key-free accounts; otherwise set balance.apiKey in config or the DEEPSEEK_API_KEY env var.',
108
- 'reason.signed-out': 'The host is not signed in to a DeepSeek account: sign in via the official "Account & Balance" page, then retry.',
108
+ 'reason.signed-out': 'The host is not signed in to a DeepSeek account and no API key is available: sign in via the official "Account & Balance" page, or set balance.apiKey / the DEEPSEEK_API_KEY env var, then retry.',
109
109
  'reason.unauthorized': 'API key invalid or expired: update the key, or sign in with the host account (no key needed).',
110
110
  'reason.account-failed': 'Host account service query failed; retrying automatically.',
111
111
  'reason.account-error': 'Host account service call errored; retrying automatically.',
@@ -121,23 +121,24 @@ window.__ModuleLoader__.load({
121
121
  'quiet.on': 'Quiet hours {s}–{e}: alerts defer and merge into one push afterwards.',
122
122
  'th.title': 'Alert thresholds', 'th.warn': 'Warn below', 'th.critical': 'Critical below', 'th.save': 'Save thresholds',
123
123
  'th.saved': 'Thresholds saved; effective immediately.', 'th.bad': 'Positive numbers required, warn above critical.',
124
+ 'th.adjusted': 'The config sets warn equal to critical, which cannot distinguish warn from critical; the defaults 20/5 are in effect — fix the config.',
124
125
  'th.hint': 'Below warn pushes "low", below critical pushes "critical"; a top-up or a threshold tweak back above warn pushes one "recovered"/"resolved" notice. Undelivered alerts cancel silently.',
125
126
  'sec.push': 'Push settings', 'push.channel': 'Push channel: {c}', 'push.on': 'Configured', 'push.off': 'Not set',
126
127
  'push.untested': 'Configured, not tested', 'push.verified': 'Last test succeeded', 'push.failed': 'Last test failed',
127
128
  'push.untestedHint': 'The webhook is saved but has never been tested: hit "Send test push" now, so a dead endpoint cannot stay hidden until a real alert needs it.',
128
- 'push.verifiedAt': 'Last test succeeded: {t}',
129
- 'push.failedAt': 'Last test failed: {t}{e}',
129
+ 'push.failedWhy': 'Failure: {e}',
130
130
  'push.testStale': 'The push config changed while the test was running; this result was discarded.',
131
131
  'push.notPersisted': 'Result not written to the state file; it will be lost on restart.',
132
132
  'chan.none': 'Not set', 'chan.wecom': 'WeCom', 'chan.dingtalk': 'DingTalk', 'chan.feishu': 'Feishu',
133
133
  'chan.bark': 'Bark', 'chan.serverchan': 'ServerChan', 'chan.telegram': 'Telegram', 'chan.generic': 'Generic webhook',
134
- 'push.hint': 'Low-balance / recovery notices push here. Saving applies immediately, no restart.',
134
+
135
135
  'push.empty': 'No push channel yet. Save a URL and get IM alerts when the balance runs low.',
136
- 'push.current': 'Endpoint: {h}',
136
+
137
137
  'push.field.channel': 'Channel', 'push.field.url': 'Webhook URL', 'push.field.token': 'Bot Token',
138
138
  'push.field.secret': 'Sign secret (optional)', 'push.field.chat': 'chat_id',
139
139
  'push.saveTest': 'Save and send test', 'push.save': 'Save only', 'push.saving': 'Saving…',
140
- 'push.edit': 'Edit', 'push.cancel': 'Cancel', 'push.saved': 'Saved; effective immediately.',
140
+ 'push.edit': 'Edit', 'push.setup': 'Set up push', 'push.cancel': 'Cancel', 'push.saved': 'Saved; effective immediately.',
141
+ 'push.address': 'Address: {h}', 'push.hint': 'Low-balance / recovery notices push here. Saving applies immediately, no restart.',
141
142
  'push.disable': 'Turn off', 'push.disableConfirm': 'Confirm?', 'push.disabled': 'Push turned off; configure it again anytime.',
142
143
  'push.test': 'Send test push', 'push.testing': 'Sending…',
143
144
  'push.testOk': 'Test push via {c} succeeded, {n} message(s) sent.',
@@ -230,7 +231,6 @@ window.__ModuleLoader__.load({
230
231
  live: { width: 7, height: 7, borderRadius: '50%', background: T.success },
231
232
  sub: { color: T.tertiary, fontSize: 12, margin: '3px 0 0' },
232
233
  btn: { fontSize: 12, padding: '6px 14px', borderRadius: 8, border: `1px solid ${T.border}`, background: T.layer1, color: T.sub, cursor: 'pointer', transition: 'all .15s ease', display: 'inline-flex', alignItems: 'center', gap: 6, flex: 'none' },
233
- btnOutline: { fontSize: 12, padding: '6px 14px', borderRadius: 8, border: `1px solid ${T.border}`, background: 'transparent', color: T.sub, cursor: 'pointer', display: 'inline-flex', alignItems: 'center', gap: 6, flex: 'none' },
234
234
  btnPrimary: { fontSize: 12, padding: '6px 14px', borderRadius: 8, border: `1px solid ${tint(T.brand, 45)}`, background: tint(T.brand, 16), color: T.brand, fontWeight: 600, cursor: 'pointer', display: 'inline-flex', alignItems: 'center', gap: 6, flex: 'none' },
235
235
  hero: { background: `linear-gradient(135deg, ${tint(T.brand, 10)}, var(--sentinel-surface, #1a1a1f) 60%)`, border: 'var(--sentinel-line-w, 1px) solid var(--sentinel-line, #2e2e36)', boxShadow: 'var(--sentinel-shadow, none)', borderRadius: 12, padding: '16px 18px', marginBottom: 14 },
236
236
  heroVal: { fontSize: 30, fontWeight: 700, lineHeight: 1.2 },
@@ -349,7 +349,19 @@ window.__ModuleLoader__.load({
349
349
  body:not([data-ds-dark-theme]) .sentinel-panel { --sentinel-surface: var(--dsw-alias-bg-layer-1, #ffffff); --sentinel-line: var(--dsw-alias-border-l3, #e3e6ea); --sentinel-dash: var(--dsw-alias-border-l4, #d5d9de); --sentinel-line-w: 0.5px; --sentinel-shadow: var(--dsw-shadow-lv1, 0 1px 2px rgba(0,0,0,0.06)); --sentinel-canvas: var(--dsw-static-neutral-bluish-75, #f4f6f8); --sentinel-val-warn: #9c5c00; --sentinel-val-critical: #c62828; --sentinel-val-success: #1f7a35; }
350
350
  .sentinel-panel::-webkit-scrollbar { width: 8px; }
351
351
  .sentinel-panel::-webkit-scrollbar-thumb { background: ${T.border}; border-radius: 8px; }
352
- .sentinel-btn:hover { border-color: ${T.brand}; color: ${T.text}; background: ${T.hover}; }
352
+ /* Quiet interaction states for every button in the panel. The border is
353
+ never recoloured on hover: a recycled button node can end up without
354
+ its own inline border colour (see the "turn off" button in the form),
355
+ and a brand-coloured hover rule then draws a bright ring around a
356
+ plain action like "修改" — which reads as "still selected" and, once
357
+ the pointer leaves, can survive the whole render. Focus is the same
358
+ deal: we draw the ring ourselves, and only for keyboard focus, so a
359
+ mouse click never leaves one behind. */
360
+ .sentinel-panel button { outline: none; -webkit-tap-highlight-color: transparent; }
361
+ .sentinel-panel button:hover:not(:disabled) { border-color: ${T.border}; color: ${T.text}; background: ${T.hover}; box-shadow: none; }
362
+ .sentinel-panel button:active:not(:disabled) { transform: scale(0.98); }
363
+ .sentinel-panel button:focus { outline: none; box-shadow: none; }
364
+ .sentinel-panel button:focus-visible { outline: 1px solid ${tint(T.brand, 55)}; outline-offset: 1px; }
353
365
  .sentinel-link:hover { opacity: 0.75; }
354
366
  .sentinel-toast { position: fixed; z-index: 999; pointer-events: none; display: flex; align-items: flex-start; gap: 8px; box-sizing: border-box; max-width: 80vw; padding: 10px 14px; border-radius: 10px; font-size: 12.5px; line-height: 1.45; transform: translateX(-50%); }
355
367
  .sentinel-toast-ok { background: ${tint(T.success, 16)}; border: 1px solid ${tint(T.success, 65)}; color: ${T.text}; }
@@ -379,7 +391,6 @@ window.__ModuleLoader__.load({
379
391
  let cancelled = false
380
392
  let timer = null
381
393
  let attempt = 0
382
- let seeded = false
383
394
  const load = async () => {
384
395
  // Ordering tokens taken when the request leaves, not when it returns.
385
396
  const issued = verdictSeq.current
@@ -410,10 +421,11 @@ window.__ModuleLoader__.load({
410
421
  if (verdictSeq.current > issued && j.channel === prev.channel) return { ...j, verify: prev.verify }
411
422
  return j
412
423
  })
413
- // Auto-open the setup form once, not on every poll: a later refresh
414
- // must not re-open it under a user who just closed it.
415
- if (!seeded && !j.configured) setEditing(true)
416
- seeded = true
424
+ // The setup form never opens by itself. An unconfigured channel is
425
+ // announced by the banner (with its own CTA), so first use reads as
426
+ // the monitor it is instead of a form to fill in; opening it stays a
427
+ // deliberate click, and no refresh can pop it open again.
428
+ //
417
429
  // Refresh the draft only while the user has not typed in the field.
418
430
  // This must be a synchronous ref read, not a functional setState that
419
431
  // compares against a closure variable: React runs that updater later,
@@ -612,7 +624,10 @@ window.__ModuleLoader__.load({
612
624
  const critShown = critDraft === null ? String(th.critical) : critDraft
613
625
  const warnN = Number(warnShown), critN = Number(critShown)
614
626
  const thValid = Number.isFinite(warnN) && Number.isFinite(critN) && warnN > 0 && critN > 0 && warnN > critN
615
- const thDirty = warnN !== th.warn || critN !== th.critical
627
+ // An adjusted (equal-pair) config must be saveable as-is: the offered
628
+ // defaults equal the shown values, so without this the save button would
629
+ // stay grey exactly when the user needs it most.
630
+ const thDirty = !!host?.thresholdsAdjusted || warnN !== th.warn || critN !== th.critical
616
631
 
617
632
  const hero = () => {
618
633
  if (!host) return null
@@ -647,7 +662,6 @@ window.__ModuleLoader__.load({
647
662
  }
648
663
 
649
664
  const pushForm = () => h('div', { style: css.card },
650
- host?.configured ? null : h('div', { style: { ...css.metaDim, marginBottom: 10 } }, t('push.empty')),
651
665
  h('div', { style: css.field },
652
666
  h('label', { style: css.fieldLabel, htmlFor: 'sentinel-chan' }, t('push.field.channel')),
653
667
  h('select', {
@@ -671,11 +685,22 @@ window.__ModuleLoader__.load({
671
685
  onChange: (e) => setForm({ ...form, secret: e.target.value }),
672
686
  })) : null,
673
687
  webhookHelp(),
674
- h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
675
- host?.configured ? h('button', { type: 'button', style: css.btn, disabled: !!busy, onClick: () => { setEditing(false); setOffConfirm(false); showResult(null) } }, t('push.cancel')) : null,
688
+ // Breathing room between the help box and the actions: without it the two
689
+ // read as one block and the buttons crowd the explanation.
690
+ h('div', { style: { display: 'flex', gap: 8, marginTop: 10, flexWrap: 'wrap' } },
691
+ // Also offered before the first save: the form no longer opens by
692
+ // itself, so whoever opened it (by mistake or just to look) needs a way
693
+ // back to the summary without saving anything.
694
+ h('button', { type: 'button', style: css.btn, disabled: !!busy, onClick: () => { setEditing(false); setOffConfirm(false); showResult(null) } }, t('push.cancel')),
676
695
  host?.configured ? h('button', {
677
696
  type: 'button', disabled: !!busy,
678
- style: { ...css.btn, color: offConfirm ? T.error : T.sub, borderColor: offConfirm ? T.error : T.border },
697
+ // The red border is a shorthand, not a borderColor override: this
698
+ // button sits at the same position in the row as the "修改" button of
699
+ // the summary, so React recycles one DOM node for both. When the
700
+ // extra borderColor key disappears on the way back, React clears that
701
+ // inline colour and the recycled node falls back to currentColor —
702
+ // a hard grey ring around "修改" that no longer matches its siblings.
703
+ style: { ...css.btn, color: offConfirm ? T.error : T.sub, border: `1px solid ${offConfirm ? T.error : T.border}` },
679
704
  onClick: disablePush,
680
705
  }, offConfirm ? t('push.disableConfirm') : t('push.disable')) : null,
681
706
  h('button', { type: 'button', style: css.btn, disabled: !!busy, onClick: () => saveWebhook(false) }, t('push.save')),
@@ -697,12 +722,13 @@ window.__ModuleLoader__.load({
697
722
  : connState === 'failed' ? T.error
698
723
  : connState === 'untested' ? T.brand
699
724
  : T.sub // off: a secondary grey, not the dimmed token (too faint on white)
700
- const connLine = connState === 'verified' ? t('push.verifiedAt', { t: fmtTime(verifyInfo.at) })
701
- + (verifyInfo.persisted === false ? ' · ' + t('push.notPersisted') : '')
702
- : connState === 'failed'
703
- ? t('push.failedAt', { t: fmtTime(verifyInfo.at), e: verifyInfo.error ? (LANG === 'en' ? ': ' : ':') + verifyInfo.error : '' })
704
- + (verifyInfo.persisted === false ? ' · ' + t('push.notPersisted') : '')
705
- : connState === 'untested' ? t('push.untestedHint') : ''
725
+ // The address is labelled so the line reads on its own ("当前地址:…"); when
726
+ // the test ran and whether it passed live in the badge on the title row.
727
+ const persistedNote = verifyInfo && verifyInfo.persisted === false ? t('push.notPersisted') : ''
728
+ const metaLine = [host?.urlHost ? t('push.address', { h: host.urlHost }) : '', persistedNote].filter(Boolean).join(' · ')
729
+ const detailLine = connState === 'failed' ? t('push.failedWhy', { e: verifyInfo.error || '' })
730
+ : connState === 'untested' ? t('push.untestedHint')
731
+ : ''
706
732
 
707
733
  const pushSummary = () => h('div', { style: css.card },
708
734
  h('div', { style: css.row },
@@ -717,18 +743,29 @@ window.__ModuleLoader__.load({
717
743
  }),
718
744
  t('push.channel', { c: t('chan.' + host.channel) })),
719
745
  h('span', { style: css.badgeSoft(connColor) }, t('push.' + connState))),
720
- host.urlHost ? h('div', { style: css.metaDim }, t('push.current', { h: host.urlHost })) : null,
746
+ metaLine ? h('div', { style: css.metaDim }, metaLine) : null,
747
+ // One static sentence saying what the card is for — it reads as the
748
+ // card's subtitle (per the reference mock), the form does not repeat it.
749
+ h('div', { style: css.metaDim }, t('push.hint')),
721
750
  // Failure text uses the same mixed ink as css.error: some skins tint the
722
751
  // raw error token pink, which is unreadable at 11.5px on a light card.
723
- connLine ? h('div', { style: { ...css.metaDim, color: connState === 'failed' ? ink(T.error) : undefined } }, connLine) : null,
724
- h('div', { style: css.metaDim }, host.configured ? t('push.hint') : t('push.empty')),
752
+ detailLine ? h('div', { style: { ...css.metaDim, color: connState === 'failed' ? ink(T.error) : undefined } }, detailLine) : null,
753
+ host.configured ? null : h('div', { style: css.metaDim }, t('push.empty')),
754
+ // No footer switch: an optional signature is configured in the profile
755
+ // file (notify.signatureText) and never advertised on the card itself.
725
756
  h('div', { style: { display: 'flex', gap: 8, marginTop: 10, flexWrap: 'wrap' } },
726
757
  h('button', {
727
758
  type: 'button', disabled: !!busy || !host.configured, className: 'sentinel-btn',
728
759
  style: busy || !host.configured ? { ...css.btn, opacity: 0.5, cursor: 'not-allowed' } : css.btn,
729
760
  onClick: testPush,
730
761
  }, busy === 'test' ? t('push.testing') : t('push.test')),
731
- h('button', { type: 'button', disabled: !!busy, className: 'sentinel-btn', style: host.configured ? css.btnOutline : css.btn, onClick: openForm }, host.configured ? t('push.edit') : t('push.save'))))
762
+ // With no auto-open this button is the section's only way in, so it has
763
+ // to say what it does ("configure") rather than "save" — there is
764
+ // nothing saved at this point, it just opens the form. Same wording as
765
+ // dsh-aihot-radar's push card (push.setup), so the two panels read alike.
766
+ // Same weight as the test button next to it: two equal actions, not a
767
+ // primary/secondary pair.
768
+ h('button', { type: 'button', disabled: !!busy, className: 'sentinel-btn', style: css.btn, onClick: openForm }, host.configured ? t('push.edit') : t('push.setup'))))
732
769
 
733
770
  const resultBlock = (r, extra) => h('div', { style: { marginTop: 8, ...extra } },
734
771
  h('div', { style: { color: r.ok ? T.success : T.error, fontSize: 12 } }, r.message),
@@ -768,6 +805,7 @@ window.__ModuleLoader__.load({
768
805
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
769
806
  h('button', { type: 'button', disabled: !!busy || !thValid || !thDirty, style: thValid && thDirty ? css.btnPrimary : { ...css.btnPrimary, opacity: 0.5, cursor: 'not-allowed' }, onClick: savePrefs }, t('th.save')),
770
807
  !thValid ? h('span', { style: { fontSize: 11.5 }, className: 'sentinel-th-bad' }, t('th.bad')) : null),
808
+ host.thresholdsAdjusted ? h('div', { style: { color: T.error, fontSize: 12, marginTop: 8 } }, t('th.adjusted')) : null,
771
809
  h('div', { style: { ...css.metaDim, marginTop: 8 } }, t('th.hint'))) : null,
772
810
  result && result.scope === 'th' ? resultBlock(result, { marginBottom: 12 }) : null,
773
811
 
package/index.js CHANGED
@@ -30,7 +30,13 @@ export const Config = z.object({
30
30
  apiKey: z.string().default(''),
31
31
  }).default({}),
32
32
  notify: z.object({
33
- signature: z.boolean().default(true),
33
+ // Deliberately NO default: the config store materialises defaults into the
34
+ // saved object, and a default of `false` would make "unset" indistinguishable
35
+ // from an explicit opt-out — erasing a custom signatureText set by an older
36
+ // user. There is no built-in install line any more, so `signature: true` is
37
+ // still accepted (old profiles keep loading) but adds nothing; only `false`
38
+ // suppresses a custom signatureText.
39
+ signature: z.boolean(),
34
40
  signatureText: z.string().default(''),
35
41
  }).default({}),
36
42
  localApi: z.object({