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