From 4324ba46860f20d68e52e98a0fda2ee10f8f2282 Mon Sep 17 00:00:00 2001 From: "mingholy.lmh" Date: Wed, 12 Nov 2025 13:59:05 +0800 Subject: [PATCH] fix: console patcher test errors --- packages/cli/src/nonInteractive/session.ts | 42 +++++++++++++--------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/nonInteractive/session.ts b/packages/cli/src/nonInteractive/session.ts index 75f780ee..a8d6f878 100644 --- a/packages/cli/src/nonInteractive/session.ts +++ b/packages/cli/src/nonInteractive/session.ts @@ -40,6 +40,7 @@ import { } from './types.js'; import type { LoadedSettings } from '../config/settings.js'; import { runNonInteractive } from '../nonInteractiveCli.js'; +import { ConsolePatcher } from '../ui/utils/ConsolePatcher.js'; const SESSION_STATE = { INITIALIZING: 'initializing', @@ -695,21 +696,30 @@ export async function runNonInteractiveStreamJson( input: string, _promptId: string, ): Promise { - // Create initial user message from prompt input if provided - let initialPrompt: CLIUserMessage | undefined = undefined; - if (input && input.trim().length > 0) { - const sessionId = config.getSessionId(); - initialPrompt = { - type: 'user', - session_id: sessionId, - message: { - role: 'user', - content: input.trim(), - }, - parent_tool_use_id: null, - }; - } + const consolePatcher = new ConsolePatcher({ + debugMode: config.getDebugMode(), + }); + consolePatcher.patch(); - const manager = new SessionManager(config, settings, initialPrompt); - await manager.run(); + try { + // Create initial user message from prompt input if provided + let initialPrompt: CLIUserMessage | undefined = undefined; + if (input && input.trim().length > 0) { + const sessionId = config.getSessionId(); + initialPrompt = { + type: 'user', + session_id: sessionId, + message: { + role: 'user', + content: input.trim(), + }, + parent_tool_use_id: null, + }; + } + + const manager = new SessionManager(config, settings, initialPrompt); + await manager.run(); + } finally { + consolePatcher.cleanup(); + } }