@@ -108,10 +108,11 @@ function loadModel(): string | undefined {
108
108
async function handleCommitAndPushHeadless (
109
109
apiKey : string ,
110
110
baseURL ? : string ,
111
- model ? : string
111
+ model ? : string ,
112
+ maxToolRounds ? : number
112
113
) : Promise < void > {
113
114
try {
114
- const agent = new GrokAgent ( apiKey , baseURL , model ) ;
115
+ const agent = new GrokAgent ( apiKey , baseURL , model , maxToolRounds ) ;
115
116
116
117
// Configure confirmation service for headless mode (auto-approve all operations)
117
118
const confirmationService = ConfirmationService . getInstance ( ) ;
@@ -229,10 +230,11 @@ async function processPromptHeadless(
229
230
prompt : string ,
230
231
apiKey : string ,
231
232
baseURL ? : string ,
232
- model ? : string
233
+ model ? : string ,
234
+ maxToolRounds ? : number
233
235
) : Promise < void > {
234
236
try {
235
- const agent = new GrokAgent ( apiKey , baseURL , model ) ;
237
+ const agent = new GrokAgent ( apiKey , baseURL , model , maxToolRounds ) ;
236
238
237
239
// Configure confirmation service for headless mode (auto-approve all operations)
238
240
const confirmationService = ConfirmationService . getInstance ( ) ;
@@ -322,6 +324,11 @@ program
322
324
"-p, --prompt <prompt>" ,
323
325
"process a single prompt and exit (headless mode)"
324
326
)
327
+ . option (
328
+ "--max-tool-rounds <rounds>" ,
329
+ "maximum number of tool execution rounds (default: 400)" ,
330
+ "400"
331
+ )
325
332
. action ( async ( options ) => {
326
333
if ( options . directory ) {
327
334
try {
@@ -340,6 +347,7 @@ program
340
347
const apiKey = options . apiKey || loadApiKey ( ) ;
341
348
const baseURL = options . baseUrl || loadBaseURL ( ) ;
342
349
const model = options . model || loadModel ( ) ;
350
+ const maxToolRounds = parseInt ( options . maxToolRounds ) || 400 ;
343
351
344
352
if ( ! apiKey ) {
345
353
console . error (
@@ -355,12 +363,12 @@ program
355
363
356
364
// Headless mode: process prompt and exit
357
365
if ( options . prompt ) {
358
- await processPromptHeadless ( options . prompt , apiKey , baseURL , model ) ;
366
+ await processPromptHeadless ( options . prompt , apiKey , baseURL , model , maxToolRounds ) ;
359
367
return ;
360
368
}
361
369
362
370
// Interactive mode: launch UI
363
- const agent = new GrokAgent ( apiKey , baseURL , model ) ;
371
+ const agent = new GrokAgent ( apiKey , baseURL , model , maxToolRounds ) ;
364
372
console . log ( "🤖 Starting Grok CLI Conversational Assistant...\n" ) ;
365
373
366
374
ensureUserSettingsDirectory ( ) ;
@@ -390,6 +398,11 @@ gitCommand
390
398
"-m, --model <model>" ,
391
399
"AI model to use (e.g., gemini-2.5-pro, grok-4-latest) (or set GROK_MODEL env var)"
392
400
)
401
+ . option (
402
+ "--max-tool-rounds <rounds>" ,
403
+ "maximum number of tool execution rounds (default: 400)" ,
404
+ "400"
405
+ )
393
406
. action ( async ( options ) => {
394
407
if ( options . directory ) {
395
408
try {
@@ -408,6 +421,7 @@ gitCommand
408
421
const apiKey = options . apiKey || loadApiKey ( ) ;
409
422
const baseURL = options . baseUrl || loadBaseURL ( ) ;
410
423
const model = options . model || loadModel ( ) ;
424
+ const maxToolRounds = parseInt ( options . maxToolRounds ) || 400 ;
411
425
412
426
if ( ! apiKey ) {
413
427
console . error (
@@ -421,7 +435,7 @@ gitCommand
421
435
await saveCommandLineSettings ( options . apiKey , options . baseUrl ) ;
422
436
}
423
437
424
- await handleCommitAndPushHeadless ( apiKey , baseURL , model ) ;
438
+ await handleCommitAndPushHeadless ( apiKey , baseURL , model , maxToolRounds ) ;
425
439
} catch ( error : any ) {
426
440
console . error ( "❌ Error during git commit-and-push:" , error . message ) ;
427
441
process . exit ( 1 ) ;
0 commit comments