efd6eb8fb9
Exclude tiny QR-login icon candidates, expose captured QR dimensions in the Web UI, and refresh the portable Hermes skill release archives.
2.5 KiB
2.5 KiB
单次最大推送商品数配置(2026-05)
背景
BOSS 希望在每商品单独推送之后,增加一个“单次运行最多推送多少个商品”的可配置项,避免一次分析结果过多导致飞书/微信刷屏。
实现要点
- 配置字段:
maxNotifyItems- 默认:
10 - 保存时限制范围:
1–50 - 位置:
data/notify-config.json
- 默认:
- 后端:
lib/analyzer.mjs+lib/notifier.mjsbuildAnalysis()会先按hermesAnalysis.score从高到低排序:sort((a, b) => b.score - a.score),再生成summary.topItems。sendNotifications()/selectNotificationItems()从已经排序好的summary.topItems里筛选recommend或达到minScore的商品,再.slice(0, maxNotifyItems)。- 因此单次最大推送数语义是:按评分高到低,最多推送满足通知条件的前 N 个商品。
- 如果未来改动
summary.topItems来源,必须保留“先按评分降序排序,再截断推送数量”的顺序,避免低分商品占用推送名额。
- 前端:
public/index.html+public/app.js- 通知设置弹窗增加输入框:
单次最多推送商品数。 loadNotifyConfig()回填n-max-items。collectNotifyConfig()提交maxNotifyItems。
- 通知设置弹窗增加输入框:
- 测试通知:
server.mjs的/api/notify-test读取 config 中的maxNotifyItems,但测试样例本身仍只有 1 个商品。
验证命令
cd /Users/chick/.Hermes/workspace/research/xianyu-hunter
node --check lib/notifier.mjs
node --check server.mjs
node --check public/app.js
node --input-type=module <<'JS'
import { getNotifyConfig, saveNotifyConfig, sendNotifications } from './lib/notifier.mjs';
const before = getNotifyConfig();
const saved = saveNotifyConfig({ enabled: true, notifyOnlyGood: false, minScore: 50, perItem: true, maxNotifyItems: 3, channels: [] });
const summary = { topItems: Array.from({length: 8}, (_, i) => ({ id: String(1000+i), title: `候选${i+1}`, score: 90-i, verdict: 'recommend', price: '150', location: '测试', reason: '验证单次最大推送数量', href: `https://www.goofish.com/item?id=${1000+i}` })) };
const result = await sendNotifications({ id:'t', name:'maxNotifyItems 验证' }, summary, { force: true, config: saved });
console.log(result.messages.length); // expected: 3
saveNotifyConfig(before);
JS
运行时注意
修改 lib/notifier.mjs / server.mjs 后必须重启正在监听 3000 的 node server.mjs,否则 Web API 和通知逻辑仍可能是旧代码。