From 1299ba4a02a9e7f9a6faa3ccad7b1947f9919f23 Mon Sep 17 00:00:00 2001 From: jinlongqi Date: Fri, 3 Jul 2026 22:10:36 +0800 Subject: [PATCH] fix(ui): use process.exit(0) instead of Ink exit() in handleExit to ensure -p mode auto-exits reliably --- packages/cli/src/ui/views/App.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/views/App.tsx b/packages/cli/src/ui/views/App.tsx index 3b2886c..ab21052 100644 --- a/packages/cli/src/ui/views/App.tsx +++ b/packages/cli/src/ui/views/App.tsx @@ -315,10 +315,10 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp } sessionManager.dispose(); - exit(); + process.exit(0); }, 0); }, - [exit, sessionManager] + [sessionManager] ); const handlePrompt = useCallback( @@ -414,6 +414,13 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp setRunningProcesses( finalActiveSessionId ? (sessionManager.getSession(finalActiveSessionId)?.processes ?? null) : null ); + // Auto-exit after initial -p/--prompt submission completes, without + // relying on the busy effect which can miss the transition when React + // batches setBusy(true) and setBusy(false) into the same render. + if (initialPromptSubmittedRef.current) { + initialPromptSubmittedRef.current = false; + handleExit({ showCommand: false, showSummary: true }); + } } }, [ @@ -562,6 +569,15 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp void run(); }, [handleSubmit, handleSelectSession, initialPrompt, navigateToSubView, refreshSessionsList, resumeSessionId]); + // Auto-exit after -p/--prompt initial submission completes + const prevBusyRef = useRef(busy); + useEffect(() => { + if (prevBusyRef.current && !busy && initialPromptSubmittedRef.current) { + handleExit({ showCommand: false, showSummary: true }); + } + prevBusyRef.current = busy; + }, [busy, handleExit]); + const handleDeleteSession = useCallback( async (id: string): Promise => { const isActiveSession = sessionManager.getActiveSessionId() === id;