rename headlessmode to interactive, add comments

This commit is contained in:
Cynthia Long
2026-03-18 14:36:59 +00:00
parent 33d654e7d9
commit d84b173330
4 changed files with 20 additions and 15 deletions
+1 -1
View File
@@ -272,7 +272,7 @@ export async function main() {
const isDebugMode = cliConfig.isDebugMode(argv);
const consolePatcher = new ConsolePatcher({
stderr: true,
headlessMode: isHeadlessMode() ? true : false,
interactive: isHeadlessMode() ? false : true,
debugMode: isDebugMode,
onNewMessage: (msg) => {
coreEvents.emitConsoleLog(msg.type, msg.content);
+1 -1
View File
@@ -65,7 +65,7 @@ export async function runNonInteractive({
return promptIdContext.run(prompt_id, async () => {
const consolePatcher = new ConsolePatcher({
stderr: true,
headlessMode: true,
interactive: false,
debugMode: config.getDebugMode(),
onNewMessage: (msg) => {
coreEvents.emitConsoleLog(msg.type, msg.content);
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
@@ -46,12 +46,12 @@ describe('ConsolePatcher', () => {
expect(console.info).toBe(beforeInfo);
});
describe('headlessMode', () => {
it('should ignore log and info when headlessMode is true and debugMode is false', () => {
describe('Interactive mode', () => {
it('should ignore log and info when it is not interactive and debugMode is false', () => {
patcher = new ConsolePatcher({
onNewMessage,
debugMode: false,
headlessMode: true,
interactive: false,
});
patcher.patch();
@@ -60,11 +60,11 @@ describe('ConsolePatcher', () => {
expect(onNewMessage).not.toHaveBeenCalled();
});
it('should not ignore log and info when headlessMode is true and debugMode is true', () => {
it('should not ignore log and info when it is not interactive and debugMode is true', () => {
patcher = new ConsolePatcher({
onNewMessage,
debugMode: true,
headlessMode: true,
interactive: false,
});
patcher.patch();
@@ -83,11 +83,11 @@ describe('ConsolePatcher', () => {
});
});
it('should not ignore log and info when headlessMode is false', () => {
it('should not ignore log and info when it is interactive', () => {
patcher = new ConsolePatcher({
onNewMessage,
debugMode: false,
headlessMode: false,
interactive: true,
});
patcher.patch();
+10 -5
View File
@@ -13,7 +13,7 @@ interface ConsolePatcherParams {
onNewMessage?: (message: Omit<ConsoleMessageItem, 'id'>) => void;
debugMode: boolean;
stderr?: boolean;
headlessMode?: boolean;
interactive?: boolean;
}
export class ConsolePatcher {
@@ -50,15 +50,20 @@ export class ConsolePatcher {
private patchConsoleMethod =
(type: 'log' | 'warn' | 'error' | 'debug' | 'info') =>
(...args: unknown[]) => {
if (this.params.headlessMode) {
// When it is non interactive mode, do not show info logging.
// default to true if it is undefined
if (this.params.interactive === false) {
if ((type === 'info' || type === 'log') && !this.params.debugMode) {
return;
}
}
if (type !== 'debug' || this.params.debugMode) {
if (this.params.stderr) {
// When it is stderr only mode, all console output redirect to stderr
if (this.params.stderr) {
if (type !== 'debug' || this.params.debugMode) {
this.originalConsoleError(this.formatArgs(args));
} else {
}
} else {
if (type !== 'debug' || this.params.debugMode) {
this.params.onNewMessage?.({
type,
content: this.formatArgs(args),