From b8649b2f8db9fde1d94b0784b42dcb3e6123fb4d Mon Sep 17 00:00:00 2001 From: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Date: Fri, 11 Jul 2025 19:12:54 +0300 Subject: [PATCH] fix: mcp bug when expanding task --- scripts/modules/task-manager/expand-task.js | 28 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/modules/task-manager/expand-task.js b/scripts/modules/task-manager/expand-task.js index 379e0223..e8e4a979 100644 --- a/scripts/modules/task-manager/expand-task.js +++ b/scripts/modules/task-manager/expand-task.js @@ -461,19 +461,41 @@ async function expandTask( `${combinedAdditionalContext}\n\n# Project Context\n\n${gatheredContext}`.trim(); } + // Ensure expansionPrompt is a string (handle both string and object formats) + let expansionPromptText = undefined; + if (taskAnalysis?.expansionPrompt) { + if (typeof taskAnalysis.expansionPrompt === 'string') { + expansionPromptText = taskAnalysis.expansionPrompt; + } else if (typeof taskAnalysis.expansionPrompt === 'object' && taskAnalysis.expansionPrompt.text) { + expansionPromptText = taskAnalysis.expansionPrompt.text; + } + } + + // Ensure gatheredContext is a string (handle both string and object formats) + let gatheredContextText = gatheredContext; + if (typeof gatheredContext === 'object' && gatheredContext !== null) { + if (gatheredContext.data) { + gatheredContextText = gatheredContext.data; + } else if (gatheredContext.text) { + gatheredContextText = gatheredContext.text; + } else { + gatheredContextText = JSON.stringify(gatheredContext); + } + } + const promptParams = { task: task, subtaskCount: finalSubtaskCount, nextSubtaskId: nextSubtaskId, additionalContext: additionalContext, complexityReasoningContext: complexityReasoningContext, - gatheredContext: gatheredContext, + gatheredContext: gatheredContextText || '', useResearch: useResearch, - expansionPrompt: taskAnalysis?.expansionPrompt || undefined + expansionPrompt: expansionPromptText || undefined }; let variantKey = 'default'; - if (taskAnalysis?.expansionPrompt) { + if (expansionPromptText) { variantKey = 'complexity-report'; logger.info( `Using expansion prompt from complexity report for task ${task.id}.`