feat(scheduler): 定时任务完成通知经微信直投

任务专柜下班退位后执行结果没人接——现在跑完主动推微信:
「⏰ 任务 · 完成/失败」+ 本轮收尾纯文本 + 触发时刻后 files 表新增成果文件(沙箱+限5个/20MB,
正文里的 /p/ 链同样转卡片)。超长截头部+全文落 .md 转卡片,与交互投递同款兜底。

- scheduled_tasks 加 notify_channel 列:op=create 时记本会话微信绑定(谁设的闹钟通知谁),
  建任务回执带一行事实;存量任务/无绑定退回用户全部在线绑定
- 钩点在 scheduler 阶段A(running→ok 轮询推断=定时轮收尾权威信号,用户手聊专柜不误触)与
  阶段B投递失败;notifyTask 经 server.js 惰性闭包注入(防 scheduler→wechat→engine require 环)
- 通知与交互投递共用 bid 串行链不插队;不碰 last_msg_id 游标;失败/离线只记日志不重试
- definitions.json prompt 参数撤掉 skill/webhook 自推引导(内置通知防双推)
This commit is contained in:
2026-09-29 22:21:34 +08:00
parent 16c5557045
commit ba4b1149aa
6 changed files with 120 additions and 10 deletions
+1 -1
View File
@@ -320,7 +320,7 @@
},
"prompt": {
"type": "string",
"description": "Self-contained instruction delivered as the only input at each trigger (prior history is archived). Output stays in the task's session; if the result must reach the user proactively, say how inside the prompt (e.g. via a skill or webhook). Required with op=create; optional with op=update."
"description": "Self-contained instruction delivered as the only input at each trigger (prior history is archived). Each run's closing reply plus newly written artifact files are automatically pushed to the user via WeChat, so do not wire a webhook/email push into the prompt. Required with op=create; optional with op=update."
},
"brief": {
"type": "string",
+5 -2
View File
@@ -963,12 +963,15 @@ function toolScheduleTask(ctx, args) {
// script 纯标记:存在即暗示模型把流程沉淀成脚本(怎么写、用什么跑、prompt 怎么引用由它自定);
// 创建与触发均不校验——缺脚本时 prompt 自身的指示就是回退面。
const script = String(args.script || '').replace(/\s+/g, ' ').trim().slice(0, 80);
const t = scheduler.createTask(db, ctx.sessionId, cronExpr, prompt, brief, script);
// 谁设的闹钟通知谁:本会话当前的微信绑定落进任务行(专柜退位后 channel_sessions 就没了,就地捕获)。
const chRow = db.prepare("SELECT channel FROM channel_sessions WHERE session_id = ? AND channel LIKE 'wx:%'").get(ctx.sessionId);
const t = scheduler.createTask(db, ctx.sessionId, cronExpr, prompt, brief, script, chRow ? chRow.channel : '');
// 定时即下班:标记本回合收尾时由 engine 收口(brief 碎片 + 归档 + 通道解绑,见 engine.taskClockOut)。
if (ctx.onTaskCreated) ctx.onTaskCreated();
return '已创建 id=' + ctx.sessionId + '\ncron="' + t.cron_expr + '"\nnext=' + scheduler.fmtIso(t.next_run_at)
+ (script ? '\nscript=' + script : '')
+ '\n本会话即收口为该任务专柜(用户无感知,下条消息自动进新会话)。';
+ '\n本会话即收口为该任务专柜(用户无感知,下条消息自动进新会话)。'
+ (chRow ? '\n完成/失败结果自动通知微信。' : '');
}
case 'update': {
if (!cronExpr && !prompt) throw new Error('op=update 需要 cron_expr 和 prompt 至少提供一个');