fix(wechat): route scheduled task cancel and spec updates through Goose MCP

Pass cancel requests to Goose like create instead of inbound title matching,
and add scheduled_task_update_spec so format or execution constraints update
taskSpec without triggering page delivery guards.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-29 09:47:39 +08:00
parent e13df82021
commit a1a921eba6
12 changed files with 265 additions and 36 deletions
+4 -17
View File
@@ -4,8 +4,6 @@ import {
parseScheduledTaskIntent,
} from '../../scheduled-task-intent.mjs';
const WEEKDAY_NAMES = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
export async function handleWechatScheduledTaskIntent({
intent,
user,
@@ -31,21 +29,10 @@ export async function handleWechatScheduledTaskIntent({
return formatScheduledTaskListReply(tasks);
}
if (taskIntent.action === 'cancel_scheduled_task') {
const titleMatch = String(intent.agentText ?? '')
.replace(/(?:取消|停止|关闭|删除|我的|定时|自动|任务)/gu, ' ')
.trim();
if (!titleMatch) {
return '请告诉我要取消哪一条定时任务,或提供任务名称关键词。';
}
const task = await scheduledTaskService.cancelTask({
userId: user.userId,
titleMatch,
});
return `已取消定时任务:${task.title}`;
}
if (taskIntent.action === 'create_scheduled_task') {
if (
taskIntent.action === 'create_scheduled_task'
|| taskIntent.action === 'cancel_scheduled_task'
) {
return null;
}
} catch (err) {
+17
View File
@@ -36,6 +36,23 @@ test('handleWechatScheduledTaskIntent passes incomplete create requests to goose
assert.equal(reply, null);
});
test('handleWechatScheduledTaskIntent passes cancel requests to goose', async () => {
const reply = await handleWechatScheduledTaskIntent({
intent: {
msgType: 'text',
agentText: '取消定时推送苏州天气任务',
msgId: 'msg-123-1',
},
user: { userId: 'user-123' },
scheduledTaskService: {
async cancelTask() {
throw new Error('should not cancel from inbound regex');
},
},
});
assert.equal(reply, null);
});
test('handleWechatScheduledTaskIntent ignores non automation text', async () => {
const reply = await handleWechatScheduledTaskIntent({
intent: {
+15 -5
View File
@@ -4,7 +4,11 @@ import {
isPageDataIntent,
} from '../../chat-skills.mjs';
import { shouldUseScheduleAssistant } from '../../schedule-intent.mjs';
import { shouldUseScheduledTaskAutomation } from '../../scheduled-task-intent.mjs';
import {
isScheduledTaskIntent,
parseScheduledTaskIntent,
shouldUseScheduledTaskAutomation,
} from '../../scheduled-task-intent.mjs';
import { buildCurrentTimeAgentPrefix } from '../../user-memory-profile.mjs';
import { isPageGenerateText, wantsDocxDownload } from '../intent/patterns.mjs';
import { buildWechatStandaloneImageInstruction } from '../image-generation-policy.mjs';
@@ -82,12 +86,18 @@ export function buildWechatAgentPrompt(intent, {
'',
].filter(Boolean).join('\n')
: '';
const scheduledTaskAutomationHint = shouldUseScheduledTaskAutomation(agentText)
const scheduledTaskIntent = parseScheduledTaskIntent(agentText);
const scheduledTaskAutomationHint = (
shouldUseScheduledTaskAutomation(agentText)
|| isScheduledTaskIntent(scheduledTaskIntent)
)
? [
'【定时自动任务要求】这条消息 Scheduled Automation(到点自动执行并推送结果),不是待办提醒。',
'【定时自动任务要求】这条消息涉及 Scheduled Automation(到点自动执行并推送结果),不是待办提醒。',
'开始前先加载 `scheduled-task-automation` skill,并严格按 skill 边界执行。',
'澄清缺失的执行时间或 taskSpec,再调用 scheduled_task_create / scheduled_task_list / scheduled_task_cancel。',
'禁止在当前对话立即执行长任务;工具成功返回后才能确认已设置。',
'创建:澄清缺失的执行时间或 taskSpec,再调用 scheduled_task_create(需用户确认卡片)。',
'取消/更新规范:必须先 scheduled_task_list 拿 taskId;取消用 scheduled_task_cancel,补充格式/长期约束用 scheduled_task_update_spec(可 mergeTaskSpec。',
'若用户只是在补充已有定时任务的执行规范(不是要做新页面),禁止走 static-page-publish 页面交付链路。',
'禁止在当前对话立即执行长任务;工具成功返回后才能确认已设置/已取消。',
'一次性任务用 runAtLocal;循环任务用 hour/minute/weekday,禁止自行估算 Unix 毫秒。',
intent?.msgId ? `调用 scheduled_task_create 时必须传入 sourceMessageId: ${intent.msgId}` : '',
'',
+1
View File
@@ -66,6 +66,7 @@ export function buildPageGenerateAgentPrompt(
return [
'【微信服务号 · 页面生成任务】',
'这是服务号专用页面生成,不是普通聊天。必须按步骤完成,未完成前禁止告诉用户“已生成/已发布”。',
'【定时任务规范】若用户是在为已有定时自动任务补充长期格式/参考页/执行约束(不是要你此刻写 HTML),改加载 scheduled-task-automation,用 scheduled_task_list + scheduled_task_update_spec;禁止走本页面交付链路。',
'',
docxBlock,
imageBlock,