From 9f4bac8d6a0e41814dccae946f9cf059d3ae7cbf Mon Sep 17 00:00:00 2001 From: Eyal Toledano Date: Tue, 13 May 2025 13:21:51 -0400 Subject: [PATCH] fix(ai): Improve AI object response handling in parse-prd This commit updates to more robustly handle responses from . Previously, the module strictly expected the AI-generated object to be nested under . This change ensures that it now first checks if itself contains the expected task data object, and then falls back to checking . This enhancement increases compatibility with varying AI provider response structures, similar to the improvements recently made in . --- .taskmasterconfig | 4 ++-- scripts/modules/commands.js | 4 ++-- scripts/modules/task-manager/parse-prd.js | 24 +++++++++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.taskmasterconfig b/.taskmasterconfig index dd3f7d52..77e96286 100644 --- a/.taskmasterconfig +++ b/.taskmasterconfig @@ -1,8 +1,8 @@ { "models": { "main": { - "provider": "google", - "modelId": "gemini-2.5-pro-exp-03-25", + "provider": "anthropic", + "modelId": "claude-3-7-sonnet-20250219", "maxTokens": 100000, "temperature": 0.2 }, diff --git a/scripts/modules/commands.js b/scripts/modules/commands.js index 41ad45ff..306f1592 100644 --- a/scripts/modules/commands.js +++ b/scripts/modules/commands.js @@ -545,7 +545,7 @@ function registerCommands(programInstance) { if (!(await confirmOverwriteIfNeeded())) return; console.log(chalk.blue(`Generating ${numTasks} tasks...`)); - spinner = ora('Parsing PRD and generating tasks...').start(); + spinner = ora('Parsing PRD and generating tasks...\n').start(); await parsePRD(defaultPrdPath, outputPath, numTasks, { append: useAppend, // Changed key from useAppend to append force: useForce // Changed key from useForce to force @@ -607,7 +607,7 @@ function registerCommands(programInstance) { console.log(chalk.blue('Appending to existing tasks...')); } - spinner = ora('Parsing PRD and generating tasks...').start(); + spinner = ora('Parsing PRD and generating tasks...\n').start(); await parsePRD(inputFile, outputPath, numTasks, { useAppend: useAppend, useForce: useForce diff --git a/scripts/modules/task-manager/parse-prd.js b/scripts/modules/task-manager/parse-prd.js index 70d5d78f..8d466e78 100644 --- a/scripts/modules/task-manager/parse-prd.js +++ b/scripts/modules/task-manager/parse-prd.js @@ -226,10 +226,30 @@ Guidelines: if (!fs.existsSync(tasksDir)) { fs.mkdirSync(tasksDir, { recursive: true }); } - logFn.success('Successfully parsed PRD via AI service.'); + logFn.success('Successfully parsed PRD via AI service.\n'); // Validate and Process Tasks - const generatedData = aiServiceResponse?.mainResult?.object; + // const generatedData = aiServiceResponse?.mainResult?.object; + + // Robustly get the actual AI-generated object + let generatedData = null; + if (aiServiceResponse?.mainResult) { + if ( + typeof aiServiceResponse.mainResult === 'object' && + aiServiceResponse.mainResult !== null && + 'tasks' in aiServiceResponse.mainResult + ) { + // If mainResult itself is the object with a 'tasks' property + generatedData = aiServiceResponse.mainResult; + } else if ( + typeof aiServiceResponse.mainResult.object === 'object' && + aiServiceResponse.mainResult.object !== null && + 'tasks' in aiServiceResponse.mainResult.object + ) { + // If mainResult.object is the object with a 'tasks' property + generatedData = aiServiceResponse.mainResult.object; + } + } if (!generatedData || !Array.isArray(generatedData.tasks)) { logFn.error(