feat(schedule): M4 定时任务配套——跨会话全览 op=list_all + 微信 /tasks 命令
用户第 6 点(在当前会话读到他所有定时任务并管理)的两种触达: - scheduler.listUserTasks:join sessions 按 user 全览(下次执行排序),两条链路同源数据。 - schedule 工具加 op=list_all:用户问「我都有哪些闹钟」AI 自取;只读全览不拆生命周期—— update/delete 仍绑各自会话,清单每行带会话标题+id,异会话任务引导用户切过去操作 (网页打开会话 / 微信 /switch <会话id>)。default 提示行同步。 - 微信 /tasks 命令(与 /list 同族、不依赖绑定会话):markdown 全览 brief/cron/下次/上次, 尾部引导「改删先 /switch 过去;删会话连带删任务」;/help 收录。 探针 7 项全过(list_all 隔离/标题id/本会话标记、/tasks 隔离/引导/空态、/help 收录)。 定时即下班(上一笔)后每任务天然独占一会话,create 撞主键仅剩手动 delete 重建路径。
This commit is contained in:
@@ -275,7 +275,7 @@
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "schedule",
|
||||
"description": "Manage the recurring scheduled task bound to the CURRENT session. At most one task per session; it is deleted together with the session. At each trigger, the prompt is sent to this session as a new user message. Schedule times are interpreted in Asia/Shanghai (UTC+8). Call this ONLY when the user explicitly asks for something to run periodically or at a specific time.\n\nop=get No arguments.\nop=create Requires cron_expr, prompt and brief.\nop=update Requires at least one of cron_expr, prompt; only the given fields change.\nop=delete No arguments.",
|
||||
"description": "Manage the recurring scheduled task bound to the CURRENT session. At most one task per session; it is deleted together with the session. At each trigger, the prompt is sent to this session as a new user message. Schedule times are interpreted in Asia/Shanghai (UTC+8). Call this ONLY when the user explicitly asks for something to run periodically or at a specific time.\n\nop=get No arguments.\nop=list_all No arguments. Lists every scheduled task of the current user across all sessions (update/delete still act on the CURRENT session only; other rows name their session id so the user can switch there).\nop=create Requires cron_expr, prompt and brief.\nop=update Requires at least one of cron_expr, prompt; only the given fields change.\nop=delete No arguments.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -288,7 +288,8 @@
|
||||
"get",
|
||||
"create",
|
||||
"update",
|
||||
"delete"
|
||||
"delete",
|
||||
"list_all"
|
||||
],
|
||||
"description": "Operation to perform on the current session's scheduled task."
|
||||
},
|
||||
|
||||
@@ -799,12 +799,29 @@ function toolScheduleTask(ctx, args) {
|
||||
});
|
||||
return '定时任务已更新:' + t.cron_expr + ',下次执行 ' + t.next_text + '(Asia/Shanghai)。';
|
||||
}
|
||||
case 'list_all': {
|
||||
// 跨会话全览(用户问「我都有哪些定时任务」时的唯一入口):只读不拆生命周期——
|
||||
// update/delete 仍只作用本会话,其余任务靠清单里的会话 id 引导用户切过去操作。
|
||||
const me = db.prepare('SELECT user FROM sessions WHERE id = ?').get(ctx.sessionId);
|
||||
const rows = scheduler.listUserTasks(db, (me && me.user) || '');
|
||||
if (!rows.length) return '你目前没有任何定时任务。要创建用 op=create(本会话' + (scheduler.getTask(db, ctx.sessionId) ? '已有任务,需先 delete' : '当前没有任务,可直接建') + ')。';
|
||||
const lines = rows.map(t => {
|
||||
const last = t.last_run_at
|
||||
? scheduler.fmtTime(t.last_run_at) + '(' + (t.last_status || '-') + (t.last_note ? ',' + t.last_note : '') + ')'
|
||||
: '尚未执行';
|
||||
return '- 「' + (t.brief || String(t.prompt).slice(0, 40)) + '」 cron=' + t.cron_expr
|
||||
+ ',下次 ' + scheduler.fmtTime(t.next_run_at) + ',上次 ' + last
|
||||
+ ',会话「' + (t.title || t.session_id) + '」' + t.session_id
|
||||
+ (t.session_id === ctx.sessionId ? '(本会话,可直接 op=update/delete)' : '(要改删请让用户先切到该会话:网页打开它,微信发 /switch ' + t.session_id + ')');
|
||||
});
|
||||
return '全部定时任务(' + rows.length + ' 个,按下次执行排序):\n' + lines.join('\n');
|
||||
}
|
||||
case 'delete': {
|
||||
const old = scheduler.deleteTask(db, ctx.sessionId);
|
||||
return '定时任务已删除(原定 ' + old + ')。要建新任务用 op=create。';
|
||||
}
|
||||
default:
|
||||
throw new Error('未知的 op:"' + op + '"。可用:get / create(需 cron_expr、prompt、brief)/ update(需 cron_expr、prompt 至少一个)/ delete');
|
||||
throw new Error('未知的 op:"' + op + '"。可用:get / create(需 cron_expr、prompt、brief)/ update(需 cron_expr、prompt 至少一个)/ delete / list_all(跨会话全览)');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user