From 1231ef08923f18b4cccb430054dd175b1b4574ec Mon Sep 17 00:00:00 2001 From: XiaoFeng <117837368+Fzhiyu1@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:01:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Plan=20=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E8=BD=AC=20Agent=20=E6=A8=A1=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E9=80=92=E5=BD=92=E6=89=A7=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 pendingPlanExecution 自动执行机制,避免任务重复执行 - planAction confirm 只做 UI 切换,后端 LLM 在同一对话中执行 - planAction modify/cancel 调用 handlePlanAction 处理 - submitAnswer 改为 void 明确不等待 --- src/panels/ICHelperPanel.ts | 30 +++++++------------ src/utils/messageHandler.ts | 60 ------------------------------------- 2 files changed, 11 insertions(+), 79 deletions(-) diff --git a/src/panels/ICHelperPanel.ts b/src/panels/ICHelperPanel.ts index 92800d1..c8f2007 100644 --- a/src/panels/ICHelperPanel.ts +++ b/src/panels/ICHelperPanel.ts @@ -10,7 +10,6 @@ import { handleUserAnswer, abortCurrentDialog, handlePlanAction, - setPendingPlanExecution, getCurrentTaskId, setLastTaskId, } from "../utils/messageHandler"; @@ -282,7 +281,7 @@ export async function showICHelperPanel( break; // 新增:处理用户回答 case "submitAnswer": - handleUserAnswer( + void handleUserAnswer( message.askId, message.selected, message.customInput @@ -328,27 +327,20 @@ export async function showICHelperPanel( // 处理计划操作(只做模式切换,响应已通过 submitAnswer 发送) case "planAction": if (message.action === "confirm") { - // 确认执行:切换到 Agent 模式 + // 确认执行:切换到 Agent 模式(UI 切换) panel.webview.postMessage({ command: "switchMode", mode: "agent", }); - // 获取当前会话的 taskId,用于复用知识图谱数据 - const taskId = getCurrentTaskId(); - if (taskId) { - // 设置待执行的计划,对话结束后自动执行(复用 taskId) - setPendingPlanExecution( - panel, - message.planTitle || "计划", - context.extensionPath, - taskId, - message.model // 传递服务等级 - ); - } else { - console.warn( - "[ICHelperPanel] 无法获取当前 taskId,知识图谱数据可能丢失" - ); - } + // 注意:不再设置待执行计划;后端 LLM 会在同一对话中自动执行计划 + } else if (message.action === "modify" || message.action === "cancel") { + void handlePlanAction( + panel, + message.action, + message.planTitle || "", + context.extensionPath, + message.model + ); } break; // 添加文件上下文 - 显示工作区文件列表 diff --git a/src/utils/messageHandler.ts b/src/utils/messageHandler.ts index 0c8ef24..b0ee6b1 100644 --- a/src/utils/messageHandler.ts +++ b/src/utils/messageHandler.ts @@ -31,29 +31,6 @@ let currentSession: DialogSession | null = null; /** 最后一个活跃的 taskId(用于压缩等操作) */ let lastTaskId: string | null = null; -/** 待执行的计划(Plan 模式确认后自动执行) */ -let pendingPlanExecution: { - panel: vscode.WebviewPanel; - planTitle: string; - extensionPath: string; - taskId: string; // 保存 taskId 以便复用 - serviceTier?: ServiceTier; // 保存服务等级 -} | null = null; - -/** - * 设置待执行的计划(由 ICHelperPanel 调用) - */ -export function setPendingPlanExecution( - panel: vscode.WebviewPanel, - planTitle: string, - extensionPath: string, - taskId: string, - serviceTier?: ServiceTier -): void { - pendingPlanExecution = { panel, planTitle, extensionPath, taskId, serviceTier }; - console.log("[MessageHandler] 设置待执行计划:", planTitle, "taskId:", taskId, "serviceTier:", serviceTier); -} - /** * 处理用户消息 */ @@ -244,43 +221,6 @@ async function handleUserMessageWithBackend( console.warn("保存AI响应历史失败:", error); } - // 检查是否有待执行的计划(Plan 模式确认后自动执行) - if (pendingPlanExecution) { - const { - panel: execPanel, - planTitle, - extensionPath: execPath, - taskId: reuseTaskId, - serviceTier: savedServiceTier, - } = pendingPlanExecution; - pendingPlanExecution = null; - console.log( - "[MessageHandler] 自动执行计划:", - planTitle, - "复用 taskId:", - reuseTaskId, - "serviceTier:", - savedServiceTier - ); - - // 延迟一小段时间确保当前对话完全结束 - setTimeout(async () => { - try { - // 复用 taskId 创建新会话,确保知识图谱数据不丢失 - await handleUserMessageWithBackend( - execPanel, - `请按照刚才的计划执行:${planTitle}`, - execPath, - "agent", - reuseTaskId, // 复用 Plan 模式的 taskId - savedServiceTier // 传递保存的服务等级 - ); - } catch (err) { - console.error("[MessageHandler] 自动执行计划失败:", err); - } - }, 500); - } - resolve(); },