feat(schedule): create 加 script 可选标记——触发器化的脚本化暗示,零校验零强制

设计定稿(用户拍板):定时任务每次从全新回合跑,理想是首趟趟平的路沉淀成脚本、
以后触发只跑脚本;但封装与否、bash 还是 python、prompt 怎么引用,都由当回合的
模型自决——工具侧只放一个可选参数制造「该不该脚本化」的潜意识提示。

- scheduled_tasks 加 script 列(与 brief 同构迁移,默认空串);createTask 收参落库,
  update 不动它(与 brief 同为身份性字段);
- get 详情显示 script=xxx(肌肉记忆长在哪);list 保持紧凑不带;create 回执带一行
  script=(仅当提供);
- 不校验:create/触发均不查脚本存在——错误原文天然回给触发回合,prompt 自身指示
  就是回退面;schema 参数描述明说这层语义,防模型误当契约。

探针 7 项全过(回执/get 展示、list 紧凑、update 保值、默认空串、无标记不显示、
迁移幂等);agent-core 已重启应用。
This commit is contained in:
2026-09-29 17:54:59 +08:00
parent 8275750600
commit 337f79c653
4 changed files with 19 additions and 6 deletions
+5 -1
View File
@@ -292,7 +292,7 @@
"type": "function",
"function": {
"name": "schedule",
"description": "Manage your scheduled tasks (alarms). Each task lives on exactly one session (at most one per session) and is addressed by its home session id — the same id op=list shows (e.g. 'task-20260929-003'); omit id (or '0') to act on THIS session's task. At each trigger the prompt is delivered to the task's 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 Optional id (default: this session).\nop=list No arguments. Every task of the current user across all sessions, each row starting with its id — hand that id to get/update/delete to act on any task directly; never ask the user to switch sessions.\nop=create Always targets THIS session (id is rejected). Requires cron_expr, prompt and brief. After creating, this session retires into the task's dedicated home (archived; the user's next message starts a fresh session).\nop=update Optional id. Requires at least one of cron_expr, prompt; only given fields change.\nop=delete Optional id. Cancels that task.",
"description": "Manage your scheduled tasks (alarms). Each task lives on exactly one session (at most one per session) and is addressed by its home session id — the same id op=list shows (e.g. 'task-20260929-003'); omit id (or '0') to act on THIS session's task. At each trigger the prompt is delivered to the task's 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 Optional id (default: this session).\nop=list No arguments. Every task of the current user across all sessions, each row starting with its id — hand that id to get/update/delete to act on any task directly; never ask the user to switch sessions.\nop=create Always targets THIS session (id is rejected). Requires cron_expr, prompt and brief; optional script. After creating, this session retires into the task's dedicated home (archived; the user's next message starts a fresh session).\nop=update Optional id. Requires at least one of cron_expr, prompt; only given fields change.\nop=delete Optional id. Cancels that task.",
"parameters": {
"type": "object",
"required": [
@@ -325,6 +325,10 @@
"brief": {
"type": "string",
"description": "One short plain-language line (<= 40 chars) saying what this task actually accomplishes, e.g. 'collect and produce a daily news PDF report'. It is written into the assistant's long-term memory diary so the recurring job can be recalled later. Required with op=create."
},
"script": {
"type": "string",
"description": "Optional marker for op=create: a script filename (relative to the session working dir) meant to carry this task's routine, so triggers reuse muscle memory instead of redoing everything. Supplying it signals you should distill the workflow into that script (language, invocation and how the prompt wires it are yours to decide). Existence is never validated — not at create, not at trigger."
}
}
}
+6 -1
View File
@@ -916,6 +916,7 @@ function schedDetail(t) {
const lines = ['id=' + t.session_id + (t.current ? '(本会话)' : '')];
if (t.title) lines.push('name=' + t.title);
if (t.brief) lines.push('brief=' + t.brief);
if (t.script) lines.push('script=' + t.script);
lines.push('cron="' + t.cron_expr + '"');
lines.push('next=' + scheduler.fmtIso(t.next_run_at));
if (t.last_run_at) lines.push('last=' + scheduler.fmtIso(t.last_run_at) + ' last_status=' + (t.last_status || '-'));
@@ -959,10 +960,14 @@ function toolScheduleTask(ctx, args) {
if (!cronExpr) throw new Error('op=create 缺少必填参数 cron_expr');
if (!prompt) throw new Error('op=create 缺少必填参数 prompt');
const brief = String(args.brief || '').replace(/\s+/g, ' ').trim().slice(0, 80);
const t = scheduler.createTask(db, ctx.sessionId, cronExpr, prompt, brief);
// 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);
// 定时即下班:标记本回合收尾时由 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本会话即收口为该任务专柜(用户无感知,下条消息自动进新会话)。';
}
case 'update': {