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.

This commit is contained in:
Eyal Toledano
2025-05-17 22:26:37 -04:00
parent cd6e42249e
commit 60b8f5faa3

View File

@@ -199,7 +199,9 @@ function parseSubtasksFromText(
throw new Error('AI response text is empty after trimming.'); 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( logger.debug(
`Original AI Response for parsing (full length: ${jsonToParse.length}): ${jsonToParse.substring(0, 1000)}...` `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.` `Simple parse failed: ${e.message}. Proceeding to advanced extraction logic.`
); );
primaryParseAttemptFailed = true; 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) --- // --- 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 // Ensure we try advanced if simple parse gave wrong structure
logger.debug('Attempting advanced extraction logic...'); logger.debug('Attempting advanced extraction logic...');
// Reset jsonToParse to the original full trimmed response for advanced 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: // (Insert the more complex extraction logic here - the one we worked on with:
// - targetPattern = '{"subtasks":'; // - targetPattern = '{"subtasks":';