From 60b8f5faa38be76711e5518969c2f5803596444f Mon Sep 17 00:00:00 2001 From: Eyal Toledano Date: Sat, 17 May 2025 22:26:37 -0400 Subject: [PATCH] fix(expand-task): Ensure advanced parsing logic works and trimmed AI response properly if any jsonToParse modifications need to be made on initial parse of response. --- scripts/modules/task-manager/expand-task.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/modules/task-manager/expand-task.js b/scripts/modules/task-manager/expand-task.js index 5dc6d569..0aad31d9 100644 --- a/scripts/modules/task-manager/expand-task.js +++ b/scripts/modules/task-manager/expand-task.js @@ -199,7 +199,9 @@ function parseSubtasksFromText( throw new Error('AI response text is empty after trimming.'); } - let jsonToParse = text.trim(); + const originalTrimmedResponse = text.trim(); // Store the original trimmed response + let jsonToParse = originalTrimmedResponse; // Initialize jsonToParse with it + logger.debug( `Original AI Response for parsing (full length: ${jsonToParse.length}): ${jsonToParse.substring(0, 1000)}...` ); @@ -260,7 +262,7 @@ function parseSubtasksFromText( `Simple parse failed: ${e.message}. Proceeding to advanced extraction logic.` ); primaryParseAttemptFailed = true; - // jsonToParse remains originalResponseForDebug for the advanced logic + // jsonToParse is already originalTrimmedResponse if simple parse failed before modifying it for markdown } // --- Attempt 2: Advanced Extraction (if simple parse failed or produced wrong structure) --- @@ -268,7 +270,7 @@ function parseSubtasksFromText( // Ensure we try advanced if simple parse gave wrong structure logger.debug('Attempting advanced extraction logic...'); // Reset jsonToParse to the original full trimmed response for advanced logic - jsonToParse = originalResponseForDebug; + jsonToParse = originalTrimmedResponse; // (Insert the more complex extraction logic here - the one we worked on with: // - targetPattern = '{"subtasks":';