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
+46
View File
@@ -218,6 +218,51 @@ export function createScheduledTaskService(pool, { defaultTimezone = DEFAULT_TIM
return rows.map(rowToTask);
};
const updateTaskSpec = async ({
userId,
taskId,
taskSpec = null,
title = null,
mergeTaskSpec = false,
} = {}) => {
if (!userId) throw new Error('缺少用户');
const safeTaskId = String(taskId ?? '').trim();
if (!safeTaskId) throw new Error('缺少 taskId');
const safeTaskSpec = taskSpec == null ? null : String(taskSpec).trim();
const safeTitle = title == null ? null : String(title).trim();
if (!safeTaskSpec && !safeTitle) throw new Error('缺少 taskSpec 或 title');
const [rows] = await pool.query(
`SELECT *
FROM h5_scheduled_tasks
WHERE id = ? AND user_id = ? AND status IN ('active', 'locked', 'failed')
LIMIT 1`,
[safeTaskId, userId],
);
const existing = rows[0];
if (!existing) throw new Error('未找到可更新的定时任务');
let nextSpec = existing.task_spec;
if (safeTaskSpec) {
nextSpec = mergeTaskSpec
? [String(existing.task_spec ?? '').trim(), safeTaskSpec].filter(Boolean).join('\n\n')
: safeTaskSpec;
}
const nextTitle = safeTitle || existing.title;
const ts = clock.now();
await pool.query(
`UPDATE h5_scheduled_tasks
SET task_spec = ?, title = ?, updated_at = ?
WHERE id = ?`,
[nextSpec, nextTitle, ts, safeTaskId],
);
const [updated] = await pool.query(
`SELECT * FROM h5_scheduled_tasks WHERE id = ? LIMIT 1`,
[safeTaskId],
);
return rowToTask(updated[0]);
};
const cancelTask = async ({
userId,
taskId = null,
@@ -385,6 +430,7 @@ export function createScheduledTaskService(pool, { defaultTimezone = DEFAULT_TIM
return {
createTask,
listTasks,
updateTaskSpec,
cancelTask,
listDueTasks,
lockTask,