@@ -1437,26 +1437,10 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
1437
1437
}
1438
1438
}
1439
1439
1440
- /**
1441
- * Iteratively processes Cline requests using a stack-based approach to avoid recursion.
1442
- * This method handles the main request-response loop with the AI assistant, processing
1443
- * user content, making API calls, and handling tool usage responses.
1444
- *
1445
- * @param userContent - The content blocks to send to the AI assistant
1446
- * @param includeFileDetails - Whether to include detailed file information in the first request
1447
- * @returns Promise<boolean> - Returns true if the loop should end, false to continue
1448
- *
1449
- * @remarks
1450
- * This method was converted from a recursive implementation to an iterative one using
1451
- * a stack data structure to eliminate potential stack overflow issues and improve
1452
- * performance while maintaining exact same functionality and behavior.
1453
- */
1454
1440
public async recursivelyMakeClineRequests (
1455
1441
userContent : Anthropic . Messages . ContentBlockParam [ ] ,
1456
1442
includeFileDetails : boolean = false ,
1457
1443
) : Promise < boolean > {
1458
- // Use a stack to manage the iterative processing to eliminate recursion
1459
- // Each stack item contains the user content and whether to include file details
1460
1444
interface StackItem {
1461
1445
userContent : Anthropic . Messages . ContentBlockParam [ ]
1462
1446
includeFileDetails : boolean
@@ -2049,13 +2033,14 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
2049
2033
this . consecutiveMistakeCount ++
2050
2034
}
2051
2035
2052
- // ITERATIVE CHANGE: Instead of recursive call, push to stack for next iteration
2053
- // This replaces: const recDidEndLoop = await this.recursivelyMakeClineRequests(this.userMessageContent)
2054
2036
if ( this . userMessageContent . length > 0 ) {
2055
2037
stack . push ( {
2056
2038
userContent : [ ...this . userMessageContent ] , // Create a copy to avoid mutation issues
2057
2039
includeFileDetails : false , // Subsequent iterations don't need file details
2058
2040
} )
2041
+
2042
+ // Add periodic yielding to prevent blocking
2043
+ await new Promise ( ( resolve ) => setImmediate ( resolve ) )
2059
2044
}
2060
2045
// Continue to next iteration instead of setting didEndLoop from recursive call
2061
2046
continue
0 commit comments