@@ -4,6 +4,7 @@ import { Task } from "../../core/task/Task"
44import { defaultModeSlug } from "../../shared/modes"
55import type { ProviderSettings , RooCodeSettings } from "@roo-code/types"
66import { CliConfigManager } from "../config/CliConfigManager"
7+ import { getCLILogger } from "../services/CLILogger"
78
89interface BatchOptions extends CliAdapterOptions {
910 cwd : string
@@ -22,53 +23,65 @@ export class BatchProcessor {
2223 this . configManager = configManager
2324 }
2425
26+ private logDebug ( message : string , ...args : any [ ] ) : void {
27+ getCLILogger ( ) . debug ( message , ...args )
28+ }
29+
30+ private logInfo ( message : string , ...args : any [ ] ) : void {
31+ getCLILogger ( ) . info ( message , ...args )
32+ }
33+
34+ private logError ( message : string , ...args : any [ ] ) : void {
35+ getCLILogger ( ) . error ( message , ...args )
36+ }
37+
2538 async run ( taskDescription : string ) : Promise < void > {
2639 try {
27- if ( this . options . verbose ) {
28- console . log ( chalk . blue ( "Starting batch mode..." ) )
29- console . log ( chalk . gray ( `Working directory: ${ this . options . cwd } ` ) )
30- console . log ( chalk . gray ( `Task: ${ taskDescription } ` ) )
31- }
40+ this . logDebug ( "[BatchProcessor] Starting batch mode..." )
41+ this . logDebug ( `[BatchProcessor] Working directory: ${ this . options . cwd } ` )
42+ this . logDebug ( `[BatchProcessor] Task: ${ taskDescription } ` )
3243
3344 // Create CLI adapters
45+ this . logDebug ( "[BatchProcessor] Creating CLI adapters..." )
3446 const adapters = createCliAdapters ( {
3547 workspaceRoot : this . options . cwd ,
3648 isInteractive : false ,
3749 verbose : this . options . verbose ,
3850 } )
51+ this . logDebug ( "[BatchProcessor] CLI adapters created" )
3952
4053 // Load configuration
54+ this . logDebug ( "[BatchProcessor] Loading configuration..." )
55+ //const { apiConfiguration } = await this.loadConfiguration()
4156 const { apiConfiguration } = await this . loadConfiguration ( )
57+ this . logDebug ( "[BatchProcessor] Configuration loaded" )
4258
4359 // Create and execute task
44- const task = new Task ( {
60+ this . logDebug ( "[BatchProcessor] Creating task..." )
61+
62+ // Use Task.create() to get both the instance and the promise
63+ const [ task , taskPromise ] = Task . create ( {
4564 apiConfiguration,
4665 task : taskDescription ,
4766 fileSystem : adapters . fileSystem ,
4867 terminal : adapters . terminal ,
4968 browser : adapters . browser ,
5069 telemetry : adapters . telemetry ,
5170 workspacePath : this . options . cwd ,
52- globalStoragePath : process . env . HOME ? `${ process . env . HOME } /.roo-code` : "/tmp/.roo-code" ,
71+ globalStoragePath : process . env . HOME ? `${ process . env . HOME } /.agentz` : "/tmp/.agentz" ,
72+ startTask : true ,
73+ verbose : this . options . verbose ,
5374 } )
5475
55- if ( this . options . verbose ) {
56- console . log ( chalk . blue ( "Task created, starting execution..." ) )
57- }
76+ this . logDebug ( "[BatchProcessor] Task created, starting execution..." )
5877
59- // Execute the task
60- await this . executeTask ( task )
78+ // Execute the task with proper promise handling
79+ await this . executeTask ( task , taskPromise )
6180
62- if ( this . options . verbose ) {
63- console . log ( chalk . green ( "Task completed successfully" ) )
64- }
81+ this . logDebug ( "[BatchProcessor] Task completed successfully" )
6582 } catch ( error ) {
6683 const message = error instanceof Error ? error . message : String ( error )
67- if ( this . options . color ) {
68- console . error ( chalk . red ( "Batch execution failed:" ) , message )
69- } else {
70- console . error ( "Batch execution failed:" , message )
71- }
84+ this . logError ( "Batch execution failed:" , message )
7285 process . exit ( 1 )
7386 }
7487 }
@@ -161,24 +174,62 @@ export class BatchProcessor {
161174 }
162175 }
163176
164- private async executeTask ( task : Task ) : Promise < void > {
177+ private async executeTask ( task : Task , taskPromise : Promise < void > ) : Promise < void > {
165178 return new Promise ( ( resolve , reject ) => {
179+ this . logDebug ( "[BatchProcessor] Setting up task event handlers..." )
180+
166181 // Set up event handlers
167- task . on ( "taskCompleted" , ( ) => {
182+ task . on ( "taskCompleted" , ( taskId : string , tokenUsage : any , toolUsage : any ) => {
183+ this . logDebug ( `[BatchProcessor] Task completed: ${ taskId } ` )
184+ this . logDebug ( `[BatchProcessor] Token usage:` , tokenUsage )
185+ this . logDebug ( `[BatchProcessor] Tool usage:` , toolUsage )
168186 resolve ( )
169187 } )
170188
171189 task . on ( "taskAborted" , ( ) => {
190+ this . logDebug ( "[BatchProcessor] Task was aborted" )
172191 reject ( new Error ( "Task was aborted" ) )
173192 } )
174193
194+ task . on ( "taskStarted" , ( ) => {
195+ this . logDebug ( "[BatchProcessor] Task started" )
196+ } )
197+
198+ task . on ( "taskPaused" , ( ) => {
199+ this . logDebug ( "[BatchProcessor] Task paused" )
200+ } )
201+
202+ task . on ( "taskUnpaused" , ( ) => {
203+ this . logDebug ( "[BatchProcessor] Task unpaused" )
204+ } )
205+
175206 // Handle tool failures
176207 task . on ( "taskToolFailed" , ( taskId : string , tool : string , error : string ) => {
208+ this . logDebug ( `[BatchProcessor] Tool ${ tool } failed: ${ error } ` )
177209 reject ( new Error ( `Tool ${ tool } failed: ${ error } ` ) )
178210 } )
179211
180- // Start the task - this should be done automatically if startTask is true (default)
181- // The task should start automatically based on the constructor options
212+ this . logDebug ( "[BatchProcessor] Event handlers set up, waiting for task execution..." )
213+ this . logDebug ( `[BatchProcessor] Task ID: ${ task . taskId } ` )
214+ this . logDebug ( `[BatchProcessor] Task initialized: ${ task . isInitialized } ` )
215+ this . logDebug ( `[BatchProcessor] Task aborted: ${ task . abort } ` )
216+
217+ // Wait for the task promise and handle errors
218+ taskPromise . catch ( ( error ) => {
219+ this . logDebug ( `[BatchProcessor] Task promise rejected:` , error )
220+ reject ( error )
221+ } )
222+
223+ // Add a timeout to prevent hanging - increased for complex tasks
224+ const timeoutMs = 60000 // 60 seconds
225+ const timeout = setTimeout ( ( ) => {
226+ this . logDebug ( `[BatchProcessor] Task execution timeout after ${ timeoutMs } ms` )
227+ reject ( new Error ( `Task execution timeout after ${ timeoutMs } ms` ) )
228+ } , timeoutMs )
229+
230+ // Clear timeout when task completes
231+ task . on ( "taskCompleted" , ( ) => clearTimeout ( timeout ) )
232+ task . on ( "taskAborted" , ( ) => clearTimeout ( timeout ) )
182233 } )
183234 }
184235}
0 commit comments