introduce headless param

This commit is contained in:
Cynthia Long
2026-03-17 14:18:09 +00:00
parent fc7a269f0a
commit abb4583554
3 changed files with 9 additions and 5 deletions
+2
View File
@@ -31,6 +31,7 @@ import {
ValidationRequiredError,
type AdminControlsSettings,
debugLogger,
isHeadlessMode,
} from '@google/gemini-cli-core';
import { loadCliConfig, parseArguments } from './config/config.js';
@@ -271,6 +272,7 @@ export async function main() {
const isDebugMode = cliConfig.isDebugMode(argv);
const consolePatcher = new ConsolePatcher({
stderr: true,
headlessMode: isHeadlessMode() ? true : false,
debugMode: isDebugMode,
onNewMessage: (msg) => {
coreEvents.emitConsoleLog(msg.type, msg.content);
+1
View File
@@ -65,6 +65,7 @@ export async function runNonInteractive({
return promptIdContext.run(prompt_id, async () => {
const consolePatcher = new ConsolePatcher({
stderr: true,
headlessMode: true,
debugMode: config.getDebugMode(),
onNewMessage: (msg) => {
coreEvents.emitConsoleLog(msg.type, msg.content);
+6 -5
View File
@@ -13,6 +13,7 @@ interface ConsolePatcherParams {
onNewMessage?: (message: Omit<ConsoleMessageItem, 'id'>) => void;
debugMode: boolean;
stderr?: boolean;
headlessMode?: boolean;
}
export class ConsolePatcher {
@@ -49,15 +50,15 @@ export class ConsolePatcher {
private patchConsoleMethod =
(type: 'log' | 'warn' | 'error' | 'debug' | 'info') =>
(...args: unknown[]) => {
if (this.params.stderr) {
if (this.params.headlessMode) {
if ((type === 'info' || type === 'log') && !this.params.debugMode) {
return;
}
if (type !== 'debug' || this.params.debugMode) {
}
if (type !== 'debug' || this.params.debugMode) {
if (this.params.stderr) {
this.originalConsoleError(this.formatArgs(args));
}
} else {
if (type !== 'debug' || this.params.debugMode) {
} else {
this.params.onNewMessage?.({
type,
content: this.formatArgs(args),