dsh-balance-sentinel 0.1.5 → 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,28 @@
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
+
6
28
  ## [0.1.5] - 2026-11-20
7
29
 
8
30
  ### Changed
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.5/dsh-balance-sentinel-0.1.5.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.5` (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. Click **Set it up**, 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: false # off by default (same switch in the panel, no config edit needed); true appends the "via …" install line
79
- signatureText: "" # custom text; setting only this also turns the footer on
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.5/dsh-balance-sentinel-0.1.5.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.5`(见 [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: false # 默认关闭(面板同一开关,不用改配置);改 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
@@ -70,6 +70,7 @@ 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': '最近测试失败',
@@ -79,14 +80,13 @@ window.__ModuleLoader__.load({
79
80
  'push.notPersisted': '结果未写入状态文件,重启后会丢失。',
80
81
  'chan.none': '未配置', 'chan.wecom': '企业微信', 'chan.dingtalk': '钉钉', 'chan.feishu': '飞书',
81
82
  'chan.bark': 'Bark', 'chan.serverchan': 'Server酱', 'chan.telegram': 'Telegram', 'chan.generic': '通用 Webhook',
82
- 'push.hint': '低余额/恢复通知将推送到这里,保存即生效,无需重启。',
83
+
83
84
  'push.empty': '还没有配置推送通道。填好地址保存,余额不足时自动提醒到 IM。',
84
85
  'push.field.channel': '推送通道', 'push.field.url': 'Webhook 地址', 'push.field.token': 'Bot Token',
85
86
  'push.field.secret': '加签密钥(可选)', 'push.field.chat': 'chat_id',
86
87
  'push.saveTest': '保存并发送测试', 'push.save': '仅保存', 'push.saving': '保存中…',
87
- 'push.edit': '修改', 'push.setup': '配置推送', 'push.cancel': '取消', 'push.saved': '已保存,立即生效。',
88
- 'push.signature': '附上安装链接', 'push.signatureHint': '(默认关闭,开启后告警尾部会多一行署名)',
89
- 'push.signatureTitle': '默认关闭;开启后告警尾部会多一行署名与安装链接',
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} 条。',
@@ -121,6 +121,7 @@ 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',
@@ -130,15 +131,14 @@ window.__ModuleLoader__.load({
130
131
  'push.notPersisted': 'Result not written to the state file; it will be lost on restart.',
131
132
  'chan.none': 'Not set', 'chan.wecom': 'WeCom', 'chan.dingtalk': 'DingTalk', 'chan.feishu': 'Feishu',
132
133
  'chan.bark': 'Bark', 'chan.serverchan': 'ServerChan', 'chan.telegram': 'Telegram', 'chan.generic': 'Generic webhook',
133
- 'push.hint': 'Low-balance / recovery notices push here. Saving applies immediately, no restart.',
134
+
134
135
  'push.empty': 'No push channel yet. Save a URL and get IM alerts when the balance runs low.',
135
136
 
136
137
  'push.field.channel': 'Channel', 'push.field.url': 'Webhook URL', 'push.field.token': 'Bot Token',
137
138
  'push.field.secret': 'Sign secret (optional)', 'push.field.chat': 'chat_id',
138
139
  'push.saveTest': 'Save and send test', 'push.save': 'Save only', 'push.saving': 'Saving…',
139
- 'push.edit': 'Edit', 'push.setup': 'Set up push', 'push.cancel': 'Cancel', 'push.saved': 'Saved; effective immediately.',
140
- 'push.signature': 'Append the install link', 'push.signatureHint': '(off by default, adds a signature line on alerts)',
141
- 'push.signatureTitle': 'Off by default; when on, alerts end with a signature line and install link',
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.',
142
142
  'push.disable': 'Turn off', 'push.disableConfirm': 'Confirm?', 'push.disabled': 'Push turned off; configure it again anytime.',
143
143
  'push.test': 'Send test push', 'push.testing': 'Sending…',
144
144
  'push.testOk': 'Test push via {c} succeeded, {n} message(s) sent.',
@@ -624,7 +624,10 @@ window.__ModuleLoader__.load({
624
624
  const critShown = critDraft === null ? String(th.critical) : critDraft
625
625
  const warnN = Number(warnShown), critN = Number(critShown)
626
626
  const thValid = Number.isFinite(warnN) && Number.isFinite(critN) && warnN > 0 && critN > 0 && warnN > critN
627
- 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
628
631
 
629
632
  const hero = () => {
630
633
  if (!host) return null
@@ -658,40 +661,6 @@ window.__ModuleLoader__.load({
658
661
  h('div', { style: { ...css.metaDim, marginTop: 6, whiteSpace: 'pre-line' } }, t('help.' + ch + '.steps')))
659
662
  }
660
663
 
661
- // Footer opt-in lives in the panel: send the whole switch, never a delta, so
662
- // the checkbox and the state file cannot disagree after a failed write.
663
- const toggleSignature = async (on) => {
664
- setBusy('sig'); showResult(null)
665
- try {
666
- const j = await post('/notify', { signature: !!on })
667
- if (!j.ok) { showResult({ ok: false, message: j.message || '' }); return }
668
- // Same rule as a webhook save: a /status issued before this write still
669
- // reports the old switch, and letting it land would flip the checkbox
670
- // back under the user.
671
- configSeq.current += 1
672
- setHost((prev) => ({ ...(prev || {}), signature: !!j.signature }))
673
- } catch (e) { showResult({ ok: false, message: String(e?.message || e) }) }
674
- finally { setBusy('') }
675
- }
676
-
677
- const signatureToggle = (extra) => h('label', {
678
- htmlFor: 'sentinel-sig',
679
- // The full sentence lives in the tooltip: on the card it was the longest
680
- // line for the least important control.
681
- title: t('push.signatureTitle'),
682
- style: { display: 'flex', alignItems: 'flex-start', gap: 6, marginTop: 10, cursor: busy ? 'default' : 'pointer', fontSize: 12, ...extra },
683
- },
684
- h('input', {
685
- type: 'checkbox', id: 'sentinel-sig', checked: !!host?.signature, disabled: !!busy,
686
- style: { margin: '2px 0 0', accentColor: T.brand },
687
- onChange: (e) => toggleSignature(e.target.checked),
688
- }),
689
- h('span', { style: { color: T.sub, lineHeight: 1.5 } },
690
- h('span', { style: { color: T.text } }, t('push.signature')),
691
- // Chinese full-width brackets sit flush against the label; the Latin
692
- // parenthesis needs a small gap to stay legible.
693
- h('span', { style: { ...css.metaDim, marginLeft: LANG === 'en' ? 4 : 0 } }, t('push.signatureHint'))))
694
-
695
664
  const pushForm = () => h('div', { style: css.card },
696
665
  h('div', { style: css.field },
697
666
  h('label', { style: css.fieldLabel, htmlFor: 'sentinel-chan' }, t('push.field.channel')),
@@ -716,9 +685,8 @@ window.__ModuleLoader__.load({
716
685
  onChange: (e) => setForm({ ...form, secret: e.target.value }),
717
686
  })) : null,
718
687
  webhookHelp(),
719
- signatureToggle(),
720
- // Breathing room between the switch and the actions: without it the two
721
- // rows read as one block and the buttons crowd the checkbox label.
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.
722
690
  h('div', { style: { display: 'flex', gap: 8, marginTop: 10, flexWrap: 'wrap' } },
723
691
  // Also offered before the first save: the form no longer opens by
724
692
  // itself, so whoever opened it (by mistake or just to look) needs a way
@@ -740,10 +708,7 @@ window.__ModuleLoader__.load({
740
708
  type: 'button', disabled: !!busy,
741
709
  style: busy ? { ...css.btnPrimary, opacity: 0.6, cursor: 'not-allowed' } : css.btnPrimary,
742
710
  onClick: () => saveWebhook(true),
743
- }, busy === 'test' ? t('push.testing') : busy === 'save' ? t('push.saving') : t('push.saveTest'))),
744
- // Where this sentence is actually useful: it explains what saving does,
745
- // so it belongs next to the save buttons, not in the summary card.
746
- h('div', { style: { ...css.metaDim, marginTop: 8 } }, t('push.hint')))
711
+ }, busy === 'test' ? t('push.testing') : busy === 'save' ? t('push.saving') : t('push.saveTest'))))
747
712
 
748
713
  // "Configured" is not "connected": a stored webhook proves nothing until a
749
714
  // test push comes back. Four states, and only a tested-good one is green —
@@ -757,14 +722,10 @@ window.__ModuleLoader__.load({
757
722
  : connState === 'failed' ? T.error
758
723
  : connState === 'untested' ? T.brand
759
724
  : T.sub // off: a secondary grey, not the dimmed token (too faint on white)
760
- // Address and test time share one line: the pill on the title row already
761
- // says whether that test passed, so spelling out "最近测试成功" here only
762
- // added words. The failure reason stays on its own line — it is the one
763
- // thing worth reading twice.
764
- const testTime = verifyInfo && verifyInfo.at ? fmtTime(verifyInfo.at) : ''
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.
765
727
  const persistedNote = verifyInfo && verifyInfo.persisted === false ? t('push.notPersisted') : ''
766
- const metaLine = [host?.urlHost, (connState === 'verified' || connState === 'failed') ? testTime : '', persistedNote]
767
- .filter(Boolean).join(' · ')
728
+ const metaLine = [host?.urlHost ? t('push.address', { h: host.urlHost }) : '', persistedNote].filter(Boolean).join(' · ')
768
729
  const detailLine = connState === 'failed' ? t('push.failedWhy', { e: verifyInfo.error || '' })
769
730
  : connState === 'untested' ? t('push.untestedHint')
770
731
  : ''
@@ -783,14 +744,15 @@ window.__ModuleLoader__.load({
783
744
  t('push.channel', { c: t('chan.' + host.channel) })),
784
745
  h('span', { style: css.badgeSoft(connColor) }, t('push.' + connState))),
785
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')),
786
750
  // Failure text uses the same mixed ink as css.error: some skins tint the
787
751
  // raw error token pink, which is unreadable at 11.5px on a light card.
788
752
  detailLine ? h('div', { style: { ...css.metaDim, color: connState === 'failed' ? ink(T.error) : undefined } }, detailLine) : null,
789
753
  host.configured ? null : h('div', { style: css.metaDim }, t('push.empty')),
790
- // The switch keeps its own line and the explanation stays with it: this is
791
- // the only place a user learns what the toggle does. Actions sit below it,
792
- // left-aligned like the rest of the panel.
793
- signatureToggle(),
754
+ // No footer switch: an optional signature is configured in the profile
755
+ // file (notify.signatureText) and never advertised on the card itself.
794
756
  h('div', { style: { display: 'flex', gap: 8, marginTop: 10, flexWrap: 'wrap' } },
795
757
  h('button', {
796
758
  type: 'button', disabled: !!busy || !host.configured, className: 'sentinel-btn',
@@ -843,6 +805,7 @@ window.__ModuleLoader__.load({
843
805
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
844
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')),
845
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,
846
809
  h('div', { style: { ...css.metaDim, marginTop: 8 } }, t('th.hint'))) : null,
847
810
  result && result.scope === 'th' ? resultBlock(result, { marginBottom: 12 }) : null,
848
811
 
package/index.js CHANGED
@@ -33,8 +33,9 @@ export const Config = z.object({
33
33
  // Deliberately NO default: the config store materialises defaults into the
34
34
  // saved object, and a default of `false` would make "unset" indistinguishable
35
35
  // from an explicit opt-out — erasing a custom signatureText set by an older
36
- // user. Leaving it optional keeps three states: unset (footer follows
37
- // signatureText), true (append), false (never append).
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.
38
39
  signature: z.boolean(),
39
40
  signatureText: z.string().default(''),
40
41
  }).default({}),
package/lib/balance.js CHANGED
@@ -38,10 +38,31 @@ export const levelOf = (balance, warn, critical) =>
38
38
  balance < critical ? 'critical' : balance < warn ? 'warn' : 'normal'
39
39
 
40
40
  export function effectiveThresholds(state, config = {}) {
41
+ const b = config.balance || {}
42
+ // The panel refuses an inverted pair, but the YAML cannot: rejecting the whole
43
+ // profile would disable the plugin, so the merged pair is normalised here — the
44
+ // one place every consumer (classification, receipts, /status, panel) reads it.
45
+ // `warn` is the higher line by definition, so an inverted pair is swapped into
46
+ // the only coherent reading; non-positive values fall back to the defaults.
47
+ // An equal pair cannot be repaired by swapping and has no coherent reading of
48
+ // its own (a balance just under the line would jump straight to critical,
49
+ // skipping warn), so it falls back to the defaults too — and /status flags it
50
+ // (thresholdsMisconfigured) so the panel can tell the user to fix the config.
51
+ let warn = state?.prefs?.warn ?? b.warn ?? 20
52
+ let critical = state?.prefs?.critical ?? b.critical ?? 5
53
+ if (!(warn > 0) || !(critical > 0) || warn === critical) return { warn: 20, critical: 5 }
54
+ if (critical > warn) [warn, critical] = [critical, warn]
55
+ return { warn, critical }
56
+ }
57
+
58
+ // The one invalid shape the normaliser cannot repair by swapping: warn equal to
59
+ // critical. Everything else loads as a coherent pair, so only equality is worth
60
+ // surfacing in /status.
61
+ export function thresholdsMisconfigured(state, config = {}) {
41
62
  const b = config.balance || {}
42
63
  const warn = state?.prefs?.warn ?? b.warn ?? 20
43
64
  const critical = state?.prefs?.critical ?? b.critical ?? 5
44
- return { warn, critical }
65
+ return warn > 0 && critical > 0 && warn === critical
45
66
  }
46
67
 
47
68
  export function createBalanceSource(opts = {}) {
package/lib/localapi.js CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  import http from 'node:http'
9
9
  import { withSignature, signatureEnabled, effectiveNotify, isWebhookConfigured as configured } from './notify.js'
10
- import { effectiveThresholds } from './balance.js'
10
+ import { effectiveThresholds, thresholdsMisconfigured } from './balance.js'
11
11
  import { mergeStateFromDisk, stateLockHeld, webhookFingerprint } from './state.js'
12
12
 
13
13
  export const LOCAL_API_PORT = 17430
@@ -152,11 +152,15 @@ export function startLocalApi({ port = LOCAL_API_PORT, state, notifier, config,
152
152
  alert: state.alert || null,
153
153
  pending: p ? { kind: p.kind, cause: p.cause || null, hold: !!p.hold, ambiguous: !!p.ambiguous, attempts: p.attempts || 0, lastError: p.lastError || null } : null,
154
154
  thresholds: effectiveThresholds(state, config),
155
+ // An equal warn/critical pair in YAML cannot be rejected without
156
+ // disabling the plugin; it falls back to the defaults and the panel
157
+ // tells the user the config needs fixing.
158
+ thresholdsAdjusted: thresholdsMisconfigured(state, config),
155
159
  quiet: config.balance?.quiet || { start: '', end: '' },
156
160
  enabled: config.balance?.enabled !== false,
157
- // Report what the sender will actually do: config plus the panel
158
- // toggle. The footer is opt-in, so an unset config reads as "off" here
159
- // instead of claiming a line that never gets appended.
161
+ // Report what the sender will actually do: the user's custom footer
162
+ // text, minus any explicit opt-out. There is no built-in line and no
163
+ // switch left, so an untouched config reads as "off".
160
164
  signature: signatureEnabled(effectiveNotify(config.notify, state)),
161
165
  // Most recent "send test" outcome. `configured` only says a webhook is
162
166
  // stored; this is the only field that can say the channel ever worked.
@@ -237,27 +241,10 @@ export function startLocalApi({ port = LOCAL_API_PORT, state, notifier, config,
237
241
  return json(res, 200, { ok: true, thresholds: effectiveThresholds(state, config) })
238
242
  }
239
243
 
240
- // Push footer toggle. Panel-owned and stored in state rather than the
241
- // profile YAML, so opting in needs no config edit; null hands control back
242
- // to notify.signature (unset there means "follow signatureText").
243
- if (req.method === 'POST' && path === '/notify') {
244
- if (!needJson()) return json(res, 415, fail('bad-content-type', '请求格式不正确'))
245
- const body = await readJson(req)
246
- if (!body) return json(res, 400, fail('bad-json', '请求体不是合法 JSON'))
247
- const sig = body?.signature
248
- if (sig !== true && sig !== false && sig !== null) {
249
- return json(res, 400, fail('bad-signature', '开关值需为 true / false / null'))
250
- }
251
- const tx = { ...state }
252
- mergeStateFromDisk(tx)
253
- tx.notify = { ...(tx.notify || {}), signature: sig }
254
- if (save && save(tx, ['notify']) === false) {
255
- return json(res, 503, fail('busy', '状态文件被占用,请稍后重试'))
256
- }
257
- state.notify = tx.notify
258
- logger?.info?.(`推送尾注${sig === null ? '恢复为跟随配置' : sig ? '已开启' : '已关闭'}`)
259
- return json(res, 200, { ok: true, signature: signatureEnabled(effectiveNotify(config.notify, state)) })
260
- }
244
+ // There is no footer switch any more: the panel used to write
245
+ // state.notify.signature here, and the value is now read-only legacy. The
246
+ // route is gone rather than kept as a no-op so nothing can turn the old
247
+ // install line back on.
261
248
 
262
249
  // Manual retry for a held / unconfirmed pending alert. Refused while a
263
250
  // monitor cycle is in flight: resetting the shared pending mid-send would