33 * Refactored to use specialized hooks for better maintainability
44 */
55
6- import React , { useCallback , useEffect , useRef } from "react"
6+ import React , { useCallback , useEffect , useRef , useState } from "react"
77import { Box , Text } from "ink"
88import { useAtomValue , useSetAtom } from "jotai"
99import { isStreamingAtom , errorAtom , addMessageAtom , messageResetCounterAtom } from "../state/atoms/ui.js"
@@ -27,6 +27,8 @@ import { AppOptions } from "./App.js"
2727import { logs } from "../services/logs.js"
2828import { createConfigErrorInstructions , createWelcomeMessage } from "./utils/welcomeMessage.js"
2929import { generateUpdateAvailableMessage , getAutoUpdateStatus } from "../utils/auto-update.js"
30+ import { generateNotificationMessage } from "../utils/notifications.js"
31+ import { notificationsAtom } from "../state/atoms/notifications.js"
3032import { useTerminal } from "../state/hooks/useTerminal.js"
3133
3234// Initialize commands on module load
@@ -43,6 +45,8 @@ export const UI: React.FC<UIAppProps> = ({ options, onExit }) => {
4345 const theme = useTheme ( )
4446 const configValidation = useAtomValue ( configValidationAtom )
4547 const resetCounter = useAtomValue ( messageResetCounterAtom )
48+ const notifications = useAtomValue ( notificationsAtom )
49+ const [ versionStatus , setVersionStatus ] = useState < Awaited < ReturnType < typeof getAutoUpdateStatus > > > ( )
4650
4751 // Initialize CI mode configuration
4852 const setCIMode = useSetAtom ( setCIModeAtom )
@@ -164,21 +168,28 @@ export const UI: React.FC<UIAppProps> = ({ options, onExit }) => {
164168 }
165169 } , [ options . ci , options . prompt , addMessage , configValidation ] )
166170
167- // Auto-update check on mount
168- const checkVersion = async ( ) => {
169- const status = await getAutoUpdateStatus ( )
170- if ( status . isOutdated ) {
171- addMessage ( generateUpdateAvailableMessage ( status ) )
171+ useEffect ( ( ) => {
172+ const checkVersion = async ( ) => {
173+ setVersionStatus ( await getAutoUpdateStatus ( ) )
172174 }
173- }
174175
175- useEffect ( ( ) => {
176176 if ( ! autoUpdatedCheckedRef . current && ! options . ci ) {
177177 autoUpdatedCheckedRef . current = true
178178 checkVersion ( )
179179 }
180180 } , [ ] )
181181
182+ useEffect ( ( ) => {
183+ if ( ! versionStatus ) return
184+
185+ if ( versionStatus . isOutdated ) {
186+ addMessage ( generateUpdateAvailableMessage ( versionStatus ) )
187+ } else if ( notifications . length > 0 && notifications [ 0 ] ) {
188+ // Only show notification if there's no pending update
189+ addMessage ( generateNotificationMessage ( notifications [ 0 ] ) )
190+ }
191+ } , [ notifications , versionStatus ] )
192+
182193 // Exit if provider configuration is invalid
183194 useEffect ( ( ) => {
184195 if ( ! configValidation . valid ) {
0 commit comments