mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-08-09 08:27:00 -07:00
feat(headless): surface diagnostic monitoring data in non-interactive output
When running Gemini CLI in headless mode (-p), critical diagnostic data like auth method, API retry attempts, loop detection, and request stats was invisible despite being tracked internally. This change surfaces that data across all three output formats (stream-json, json, text). Changes: - Add RETRY and LOOP_DETECTED event types to stream-json output - Include auth_method and user_tier in init events and JSON output - Add api_requests, api_errors, and retry_count to result stats - Track and expose detected loop type (tool call, chanting, LLM-detected) - Emit [RETRY] and [WARNING] messages to stderr in text mode - Listen to CoreEvent.RetryAttempt in non-interactive CLI - Add test script (scripts/test_gemini.sh) for manual verification
This commit is contained in:
@@ -118,6 +118,9 @@ export class LoopDetectionService {
|
||||
private llmCheckInterval = DEFAULT_LLM_CHECK_INTERVAL;
|
||||
private lastCheckTurn = 0;
|
||||
|
||||
// Detected loop type tracking
|
||||
private detectedLoopType: string | null = null;
|
||||
|
||||
// Session-level disable flag
|
||||
private disabledForSession = false;
|
||||
|
||||
@@ -208,6 +211,7 @@ export class LoopDetectionService {
|
||||
this.toolCallRepetitionCount = 1;
|
||||
}
|
||||
if (this.toolCallRepetitionCount >= TOOL_CALL_LOOP_THRESHOLD) {
|
||||
this.detectedLoopType = 'consecutive_identical_tool_calls';
|
||||
logLoopDetected(
|
||||
this.config,
|
||||
new LoopDetectedEvent(
|
||||
@@ -321,6 +325,7 @@ export class LoopDetectionService {
|
||||
const chunkHash = createHash('sha256').update(currentChunk).digest('hex');
|
||||
|
||||
if (this.isLoopDetectedForChunk(currentChunk, chunkHash)) {
|
||||
this.detectedLoopType = 'chanting_identical_sentences';
|
||||
logLoopDetected(
|
||||
this.config,
|
||||
new LoopDetectedEvent(
|
||||
@@ -575,6 +580,7 @@ export class LoopDetectionService {
|
||||
result: Record<string, unknown>,
|
||||
modelName: string,
|
||||
): void {
|
||||
this.detectedLoopType = 'llm_detected_loop';
|
||||
if (
|
||||
typeof result['unproductive_state_analysis'] === 'string' &&
|
||||
result['unproductive_state_analysis']
|
||||
@@ -599,6 +605,13 @@ export class LoopDetectionService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the most recently detected loop, or null if none.
|
||||
*/
|
||||
getDetectedLoopType(): string | null {
|
||||
return this.detectedLoopType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all loop detection state.
|
||||
*/
|
||||
@@ -608,6 +621,7 @@ export class LoopDetectionService {
|
||||
this.resetContentTracking();
|
||||
this.resetLlmCheckTracking();
|
||||
this.loopDetected = false;
|
||||
this.detectedLoopType = null;
|
||||
}
|
||||
|
||||
private resetToolCallCount(): void {
|
||||
|
||||
Reference in New Issue
Block a user