@@ -108,10 +108,11 @@ function loadModel(): string | undefined {
108108async function handleCommitAndPushHeadless (
109109 apiKey : string ,
110110 baseURL ? : string ,
111- model ? : string
111+ model ? : string ,
112+ maxToolRounds ? : number
112113) : Promise < void > {
113114 try {
114- const agent = new GrokAgent ( apiKey , baseURL , model ) ;
115+ const agent = new GrokAgent ( apiKey , baseURL , model , maxToolRounds ) ;
115116
116117 // Configure confirmation service for headless mode (auto-approve all operations)
117118 const confirmationService = ConfirmationService . getInstance ( ) ;
@@ -229,10 +230,11 @@ async function processPromptHeadless(
229230 prompt : string ,
230231 apiKey : string ,
231232 baseURL ? : string ,
232- model ? : string
233+ model ? : string ,
234+ maxToolRounds ? : number
233235) : Promise < void > {
234236 try {
235- const agent = new GrokAgent ( apiKey , baseURL , model ) ;
237+ const agent = new GrokAgent ( apiKey , baseURL , model , maxToolRounds ) ;
236238
237239 // Configure confirmation service for headless mode (auto-approve all operations)
238240 const confirmationService = ConfirmationService . getInstance ( ) ;
@@ -322,6 +324,11 @@ program
322324 "-p, --prompt <prompt>" ,
323325 "process a single prompt and exit (headless mode)"
324326 )
327+ . option (
328+ "--max-tool-rounds <rounds>" ,
329+ "maximum number of tool execution rounds (default: 400)" ,
330+ "400"
331+ )
325332 . action ( async ( options ) => {
326333 if ( options . directory ) {
327334 try {
@@ -340,6 +347,7 @@ program
340347 const apiKey = options . apiKey || loadApiKey ( ) ;
341348 const baseURL = options . baseUrl || loadBaseURL ( ) ;
342349 const model = options . model || loadModel ( ) ;
350+ const maxToolRounds = parseInt ( options . maxToolRounds ) || 400 ;
343351
344352 if ( ! apiKey ) {
345353 console . error (
@@ -355,12 +363,12 @@ program
355363
356364 // Headless mode: process prompt and exit
357365 if ( options . prompt ) {
358- await processPromptHeadless ( options . prompt , apiKey , baseURL , model ) ;
366+ await processPromptHeadless ( options . prompt , apiKey , baseURL , model , maxToolRounds ) ;
359367 return ;
360368 }
361369
362370 // Interactive mode: launch UI
363- const agent = new GrokAgent ( apiKey , baseURL , model ) ;
371+ const agent = new GrokAgent ( apiKey , baseURL , model , maxToolRounds ) ;
364372 console . log ( "🤖 Starting Grok CLI Conversational Assistant...\n" ) ;
365373
366374 ensureUserSettingsDirectory ( ) ;
@@ -390,6 +398,11 @@ gitCommand
390398 "-m, --model <model>" ,
391399 "AI model to use (e.g., gemini-2.5-pro, grok-4-latest) (or set GROK_MODEL env var)"
392400 )
401+ . option (
402+ "--max-tool-rounds <rounds>" ,
403+ "maximum number of tool execution rounds (default: 400)" ,
404+ "400"
405+ )
393406 . action ( async ( options ) => {
394407 if ( options . directory ) {
395408 try {
@@ -408,6 +421,7 @@ gitCommand
408421 const apiKey = options . apiKey || loadApiKey ( ) ;
409422 const baseURL = options . baseUrl || loadBaseURL ( ) ;
410423 const model = options . model || loadModel ( ) ;
424+ const maxToolRounds = parseInt ( options . maxToolRounds ) || 400 ;
411425
412426 if ( ! apiKey ) {
413427 console . error (
@@ -421,7 +435,7 @@ gitCommand
421435 await saveCommandLineSettings ( options . apiKey , options . baseUrl ) ;
422436 }
423437
424- await handleCommitAndPushHeadless ( apiKey , baseURL , model ) ;
438+ await handleCommitAndPushHeadless ( apiKey , baseURL , model , maxToolRounds ) ;
425439 } catch ( error : any ) {
426440 console . error ( "❌ Error during git commit-and-push:" , error . message ) ;
427441 process . exit ( 1 ) ;
0 commit comments