From ba006b55cd8ac05c6229426c0aaf0dc79b21b554 Mon Sep 17 00:00:00 2001 From: siage Date: Sun, 13 Apr 2025 02:04:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=BB=E5=8B=99=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=A8=A1=E5=BC=8F=E3=80=8CclearAllTasks=E3=80=8D?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E6=B8=85=E9=99=A4=E6=89=80=E6=9C=89=E4=BB=BB?= =?UTF-8?q?=E5=8B=99=E4=B8=A6=E5=89=B5=E5=BB=BA=E5=82=99=E4=BB=BD=EF=BC=8C?= =?UTF-8?q?=E4=B8=A6=E6=9B=B4=E6=96=B0=E7=9B=B8=E9=97=9C=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E8=88=87=E9=82=8F=E8=BC=AF=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=BB?= =?UTF-8?q?=E5=8B=99=E7=AE=A1=E7=90=86=E7=9A=84=E9=9D=88=E6=B4=BB=E6=80=A7?= =?UTF-8?q?=E8=88=87=E6=BA=96=E7=A2=BA=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/taskModel.ts | 2 +- src/tools/taskTools.ts | 58 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/models/taskModel.ts b/src/models/taskModel.ts index 32ea8a5..8555157 100644 --- a/src/models/taskModel.ts +++ b/src/models/taskModel.ts @@ -263,7 +263,7 @@ export async function batchCreateOrUpdateTasks( dependencies?: string[]; relatedFiles?: RelatedFile[]; }>, - updateMode: "append" | "overwrite" | "selective" + updateMode: "append" | "overwrite" | "selective" | "clearAllTasks" ): Promise { // 獲取現有任務 const existingTasks = await readTasks(); diff --git a/src/tools/taskTools.ts b/src/tools/taskTools.ts index 063a8fd..f30acaf 100644 --- a/src/tools/taskTools.ts +++ b/src/tools/taskTools.ts @@ -472,10 +472,10 @@ export async function reflectTask({ export const splitTasksSchema = z .object({ updateMode: z - .enum(["append", "overwrite", "selective"]) + .enum(["append", "overwrite", "selective", "clearAllTasks"]) .optional() .describe( - "任務更新模式:'append'(保留現有任務並新增)、'overwrite'(清除所有未完成任務並重建)、'selective'(根據名稱匹配更新現有任務,保留其餘任務)" + "任務更新模式:'append'(保留現有任務並新增)、'overwrite'(清除所有未完成任務並重建)、'selective'(根據名稱匹配更新現有任務,保留其餘任務)、'clearAllTasks'(清除所有任務並創建備份)" ), tasks: z .array( @@ -551,6 +551,58 @@ export async function splitTasks({ // 如果未指定更新模式,預設為 "append" 模式 const effectiveUpdateMode = updateMode || "append"; + // 處理 clearAllTasks 模式,直接調用 modelClearAllTasks 函數 + if (effectiveUpdateMode === "clearAllTasks") { + const clearResult = await modelClearAllTasks(); + + // 記錄清除結果 + try { + await addConversationEntry( + ConversationParticipant.MCP, + `清除所有任務:${clearResult.success ? "成功" : "失敗"},${ + clearResult.message + }`, + undefined, + "任務清除" + ); + } catch (error) { + console.error("記錄對話日誌時發生錯誤:", error); + } + + // 返回清除操作結果 + let prompt = `## 任務清除結果\n\n### 系統通知\n${clearResult.message}\n\n`; + + if (clearResult.success) { + if (clearResult.backupFile) { + prompt += `### 備份信息\n備份文件已創建:${clearResult.backupFile}\n\n`; + } + + if (tasks.length > 0) { + prompt += `系統將繼續創建您請求的 ${tasks.length} 個新任務。\n`; + } else { + prompt += `### 注意\n您沒有提供任何新任務。如需創建新任務,請使用 "append" 模式並提供任務列表。\n`; + return { + content: [ + { + type: "text" as const, + text: prompt, + }, + ], + }; + } + } else { + prompt += `### 錯誤信息\n清除任務時遇到問題:${clearResult.message}\n任務清單未更改。\n`; + return { + content: [ + { + type: "text" as const, + text: prompt, + }, + ], + }; + } + } + // 根據不同更新模式生成日誌訊息 let updateModeMessage = ""; if (effectiveUpdateMode === "append") { @@ -560,6 +612,8 @@ export async function splitTasks({ } else if (effectiveUpdateMode === "selective") { updateModeMessage = "選擇性更新模式:根據任務名稱更新現有任務、新增缺少任務,保留其餘任務"; + } else if (effectiveUpdateMode === "clearAllTasks") { + updateModeMessage = "清除模式:清除所有任務並創建備份"; } // 記錄任務拆分