fix(cli): Add delimiter before printing tool response in non-interactive mode (#11351)

This commit is contained in:
Krishna Bajpai
2025-10-27 07:57:54 -07:00
committed by GitHub
parent 2fa13420ae
commit c7817aee30
7 changed files with 305 additions and 32 deletions
+8 -3
View File
@@ -40,6 +40,7 @@ import {
handleCancellationError,
handleMaxTurnsExceededError,
} from './utils/errors.js';
import { TextOutput } from './ui/utils/textOutput.js';
export async function runNonInteractive(
config: Config,
@@ -52,6 +53,7 @@ export async function runNonInteractive(
stderr: true,
debugMode: config.getDebugMode(),
});
const textOutput = new TextOutput();
const handleUserFeedback = (payload: UserFeedbackPayload) => {
const prefix = payload.severity.toUpperCase();
@@ -183,7 +185,9 @@ export async function runNonInteractive(
} else if (config.getOutputFormat() === OutputFormat.JSON) {
responseText += event.value;
} else {
process.stdout.write(event.value);
if (event.value) {
textOutput.write(event.value);
}
}
} else if (event.type === GeminiEventType.ToolCallRequest) {
if (streamFormatter) {
@@ -220,6 +224,7 @@ export async function runNonInteractive(
}
if (toolCallRequests.length > 0) {
textOutput.ensureTrailingNewline();
const toolResponseParts: Part[] = [];
const completedToolCalls: CompletedToolCall[] = [];
@@ -297,9 +302,9 @@ export async function runNonInteractive(
} else if (config.getOutputFormat() === OutputFormat.JSON) {
const formatter = new JsonFormatter();
const stats = uiTelemetryService.getMetrics();
process.stdout.write(formatter.format(responseText, stats));
textOutput.write(formatter.format(responseText, stats));
} else {
process.stdout.write('\n'); // Ensure a final newline
textOutput.ensureTrailingNewline(); // Ensure a final newline
}
return;
}