fix(logging): Ensure sandbox startup messages are routed to stderr (#5725)
This commit is contained in:
parent
99f88851fb
commit
d6a7334279
|
@ -224,7 +224,7 @@ export type Message =
|
|||
};
|
||||
|
||||
export interface ConsoleMessageItem {
|
||||
type: 'log' | 'warn' | 'error' | 'debug';
|
||||
type: 'log' | 'warn' | 'error' | 'debug' | 'info';
|
||||
content: string;
|
||||
count: number;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ export class ConsolePatcher {
|
|||
private originalConsoleWarn = console.warn;
|
||||
private originalConsoleError = console.error;
|
||||
private originalConsoleDebug = console.debug;
|
||||
private originalConsoleInfo = console.info;
|
||||
|
||||
private params: ConsolePatcherParams;
|
||||
|
||||
|
@ -30,6 +31,7 @@ export class ConsolePatcher {
|
|||
console.warn = this.patchConsoleMethod('warn', this.originalConsoleWarn);
|
||||
console.error = this.patchConsoleMethod('error', this.originalConsoleError);
|
||||
console.debug = this.patchConsoleMethod('debug', this.originalConsoleDebug);
|
||||
console.info = this.patchConsoleMethod('info', this.originalConsoleInfo);
|
||||
}
|
||||
|
||||
cleanup = () => {
|
||||
|
@ -37,13 +39,14 @@ export class ConsolePatcher {
|
|||
console.warn = this.originalConsoleWarn;
|
||||
console.error = this.originalConsoleError;
|
||||
console.debug = this.originalConsoleDebug;
|
||||
console.info = this.originalConsoleInfo;
|
||||
};
|
||||
|
||||
private formatArgs = (args: unknown[]): string => util.format(...args);
|
||||
|
||||
private patchConsoleMethod =
|
||||
(
|
||||
type: 'log' | 'warn' | 'error' | 'debug',
|
||||
type: 'log' | 'warn' | 'error' | 'debug' | 'info',
|
||||
originalMethod: (...args: unknown[]) => void,
|
||||
) =>
|
||||
(...args: unknown[]) => {
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
} from '../config/settings.js';
|
||||
import { promisify } from 'util';
|
||||
import { Config, SandboxConfig } from '@google/gemini-cli-core';
|
||||
import { ConsolePatcher } from '../ui/utils/ConsolePatcher.js';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
|
@ -185,6 +186,13 @@ export async function start_sandbox(
|
|||
nodeArgs: string[] = [],
|
||||
cliConfig?: Config,
|
||||
) {
|
||||
const patcher = new ConsolePatcher({
|
||||
debugMode: cliConfig?.getDebugMode() || !!process.env.DEBUG,
|
||||
stderr: true,
|
||||
});
|
||||
patcher.patch();
|
||||
|
||||
try {
|
||||
if (config.command === 'sandbox-exec') {
|
||||
// disallow BUILD_SANDBOX
|
||||
if (process.env.BUILD_SANDBOX) {
|
||||
|
@ -424,7 +432,10 @@ export async function start_sandbox(
|
|||
if (!fs.existsSync(userSettingsDirOnHost)) {
|
||||
fs.mkdirSync(userSettingsDirOnHost);
|
||||
}
|
||||
args.push('--volume', `${userSettingsDirOnHost}:${userSettingsDirInSandbox}`);
|
||||
args.push(
|
||||
'--volume',
|
||||
`${userSettingsDirOnHost}:${userSettingsDirInSandbox}`,
|
||||
);
|
||||
if (userSettingsDirInSandbox !== userSettingsDirOnHost) {
|
||||
args.push(
|
||||
'--volume',
|
||||
|
@ -784,6 +795,9 @@ export async function start_sandbox(
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
} finally {
|
||||
patcher.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper functions to ensure sandbox image is present
|
||||
|
|
Loading…
Reference in New Issue