feat: 每日积分模式与 Bark 完成提醒

- 按课时类型计分:文档 1 / 视频 3 / 音频 2 / 微课 2,每次 3 分,单日封顶 24 分;满额换类,无内容即停
- 积分计数落 localStorage,跨刷新/重启保留、跨天清零;面板与无头 TUI 都显示今日积分
- 运行器自己收尾时通过 Bark 推送今日积分、完成门数、用时和结束原因;手动停止与 --check 不推送
- 新增 --points-mode / --bark-* 参数及对应 YUN_XUE_TANG_* 环境变量
- 补充 points / notify 离线回归测试与 OpenSpec 配置

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
voidandClaude Sonnet 4.6 committed 2026-11-01 22:19:52 +08:00
1 parent 17217dbeb1
commit 0eb4c40629
31 files changed
+2954 -21

No files matched your search

+35
View File
@@ -8,6 +8,7 @@ import { runSession, disposeActiveSession } from './session.mjs';
import { openLog } from './log.mjs';
import { noDisplayReason, platformName } from './platform.mjs';
import { createTui } from './tui.mjs';
import { notifyRunFinished } from './notify.mjs';
const RETRY_BASE_MS = 15000;
const RETRY_MAX_MS = 120000;
@@ -58,6 +59,30 @@ export async function runSupervisor(o) {
let attempt = 0;
let last = null;
let lastNotified = '';
/**
* 收尾 Bark 通知。通知识别键相同的只发一次:配了 restartMinutes 时,
* 「今日积分已学完」这类结论会在每一轮重启后原样重复,没必要每小时推一次。
* 用户按 Ctrl+C 主动停的不发;自检模式不发。
*/
const notify = async (result) => {
if (stop.stopping || cfg.CHECK_ONLY) return;
const key = [result.kind, result.finishReason, result.completed,
result.points && result.points.text].join('|');
if (key === lastNotified) return;
lastNotified = key;
await notifyRunFinished(cfg, result, { log, warn });
};
/** 一次会话的结果 → 通知入参:卡死和无进展在退出码里是两种结论,标题也不同 */
const finishResult = (s) => ({
kind: /没有任何进展/.test((s && s.finishReason) || '') ? 'stalled' : 'done',
finishReason: (s && s.finishReason) || '',
completed: (s && s.completed) || 0,
elapsed: (s && s.elapsed) || 0,
points: s && s.points,
});
/** 收尾时先把面板收掉,退出日志和退出码提示才会逐行打印出来 */
const finishTui = (phase, tone) => {
@@ -73,6 +98,10 @@ export async function runSupervisor(o) {
last = await runSession({ ...o, cfg, tui });
if (stop.stopping) break;
if (cfg.CHECK_ONLY) break;
// 每轮会话自己结束就先推一次:配了 restartMinutes 时进程不会退出,
// 只在最终收尾推就等于永远不推。重复结论由 notify() 的识别键挡掉。
tui.set({ phase: '发送 Bark 通知', tone: 'info' });
await notify(finishResult(last));
// 正常结束:只有「脚本自己停了 / 无进展」且配了重启间隔才再来一轮
const restartable = !last.limitReached && cfg.RESTART_MINUTES > 0;
if (!restartable) break;
@@ -90,6 +119,8 @@ export async function runSupervisor(o) {
tui.set({ phase: '会话异常,准备重试', tone: 'error' });
// 连登 5 次失败基本都是密码错 / 要验证码,重试没意义,直接用专门的退出码结束
if (e && e.message && /连续 \d+ 次登录失败/.test(e.message)) {
tui.set({ phase: '发送 Bark 通知', tone: 'info' });
await notify({ kind: 'login', finishReason: e.message, completed: 0, elapsed: 0 });
finishTui('登录失败,检查账号密码 / 验证码', 'error');
return { exitCode: 3, last };
}
@@ -107,6 +138,10 @@ export async function runSupervisor(o) {
const phase = cfg.CHECK_ONLY
? (exitCode === 0 ? '自检通过' : '自检失败')
: stalled ? '退出:长时间无进展' : '正常收尾';
if (last) {
tui.set({ phase: '发送 Bark 通知', tone: 'info' });
await notify(finishResult(last));
}
finishTui(phase, exitCode === 0 ? 'ok' : (stalled ? 'warn' : 'error'));
log('=== 运行器退出 ===');