fix(headless): complete debug diagnostics parity for json and stream-json

This commit is contained in:
Dmitry Lyalin
2026-02-25 10:23:16 -08:00
parent 8fb2f1e7f8
commit 96aa6004fb
8 changed files with 401 additions and 9 deletions
+27 -1
View File
@@ -96,6 +96,8 @@ export async function runNonInteractive({
const startTime = Date.now();
let retryCount = 0;
let loopDetected = false;
let detectedLoopType: string | undefined;
const debugMode = config.getDebugMode();
const streamFormatter =
config.getOutputFormat() === OutputFormat.STREAM_JSON
@@ -377,14 +379,26 @@ export async function runNonInteractive({
}
toolCallRequests.push(event.value);
} else if (event.type === GeminiEventType.LoopDetected) {
const loopType = event.value?.loopType;
loopDetected = true;
if (loopType) {
detectedLoopType = loopType;
}
if (debugMode) {
const loopType = event.value?.loopType;
if (streamFormatter) {
streamFormatter.emitEvent({
type: JsonStreamEventType.LOOP_DETECTED,
timestamp: new Date().toISOString(),
...(loopType && { loop_type: loopType }),
});
// Keep emitting the legacy warning event for existing parsers.
streamFormatter.emitEvent({
type: JsonStreamEventType.ERROR,
timestamp: new Date().toISOString(),
severity: 'warning',
message: 'Loop detected, stopping execution',
});
} else if (config.getOutputFormat() === OutputFormat.TEXT) {
const loopTypeStr = loopType ? ` (${loopType})` : '';
process.stderr.write(
@@ -540,6 +554,12 @@ export async function runNonInteractive({
undefined,
authMethod,
userTier,
{
includeDiagnostics: debugMode,
retryCount,
loopDetected,
loopType: detectedLoopType,
},
),
);
} else {
@@ -574,6 +594,12 @@ export async function runNonInteractive({
undefined,
authMethod,
userTier,
{
includeDiagnostics: debugMode,
retryCount,
loopDetected,
loopType: detectedLoopType,
},
),
);
} else {