diff options
| author | Evan Senter <[email protected]> | 2025-04-18 21:55:02 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-04-18 21:55:02 +0100 |
| commit | 482aeaff102f1f97f67bed04442dbd23a6424f2d (patch) | |
| tree | 6680807461201be565166727ce3249a59d07e7f7 /packages/cli | |
| parent | 3ed61f1ff25a50b94cb6a6235c67eb3c9d4737e7 (diff) | |
Warn if `npm run start` is out of date. (#20)
* Adding some wiring to allow the Ink app to warn if there are local development changes that haven't been captured in the recent build of the Gemini CLI.
* Adding a new useAppEffects.ts file that wores some useEffect handlers in.
* Updating package-lock.json to resolve `npm ci` issues.
* Updating package-lock.json and package.json to resolve `npm ci` issues.
Diffstat (limited to 'packages/cli')
| -rw-r--r-- | packages/cli/package.json | 3 | ||||
| -rw-r--r-- | packages/cli/src/ui/App.tsx | 47 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useAppEffects.ts | 61 |
3 files changed, 91 insertions, 20 deletions
diff --git a/packages/cli/package.json b/packages/cli/package.json index 4f2ca5fe..053aeabc 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -5,8 +5,7 @@ "type": "module", "main": "gemini.js", "scripts": { - "build": "tsc && cp package.json README.md ../../LICENSE dist/", - "clean": "rm -rf dist", + "build": "tsc && cp package.json README.md ../../LICENSE dist/ && touch dist/.last_build", "start": "node dist/gemini.js", "debug": "node --inspect-brk dist/gemini.js", "lint": "eslint . --ext .ts,.tsx", diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index 1bc0f6c6..7eae3727 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -1,5 +1,8 @@ import React, { useState, useEffect } from 'react'; import { Box, Text } from 'ink'; +import fs from 'fs'; +import path from 'path'; +import os from 'os'; import type { HistoryItem } from './types.js'; import { useGeminiStream } from './hooks/useGeminiStream.js'; import { useLoadingIndicator } from './hooks/useLoadingIndicator.js'; @@ -11,6 +14,12 @@ import InputPrompt from './components/InputPrompt.js'; import Footer from './components/Footer.js'; import { StreamingState } from '../core/gemini-stream.js'; import { PartListUnion } from '@google/genai'; +import { + useStartupWarnings, + useInitializationErrorEffect, +} from './hooks/useAppEffects.js'; + +const warningsFilePath = path.join(os.tmpdir(), 'gemini-code-cli-warnings.txt'); interface AppProps { directory: string; @@ -19,11 +28,15 @@ interface AppProps { const App = ({ directory }: AppProps) => { const [query, setQuery] = useState(''); const [history, setHistory] = useState<HistoryItem[]>([]); + const [startupWarnings, setStartupWarnings] = useState<string[]>([]); const { streamingState, submitQuery, initError } = useGeminiStream(setHistory); const { elapsedTime, currentLoadingPhrase } = useLoadingIndicator(streamingState); + useStartupWarnings(setStartupWarnings); + useInitializationErrorEffect(initError, history, setHistory); + const handleInputSubmit = (value: PartListUnion) => { submitQuery(value) .then(() => { @@ -34,24 +47,6 @@ const App = ({ directory }: AppProps) => { }); }; - useEffect(() => { - if ( - initError && - !history.some( - (item) => item.type === 'error' && item.text?.includes(initError), - ) - ) { - setHistory((prev) => [ - ...prev, - { - id: Date.now(), - type: 'error', - text: `Initialization Error: ${initError}. Please check API key and configuration.`, - } as HistoryItem, - ]); - } - }, [initError, history]); - const isWaitingForToolConfirmation = history.some( (item) => item.type === 'tool_group' && @@ -63,6 +58,22 @@ const App = ({ directory }: AppProps) => { <Box flexDirection="column" padding={1} marginBottom={1} width="100%"> <Header cwd={directory} /> + {startupWarnings.length > 0 && ( + <Box + borderStyle="round" + borderColor="yellow" + paddingX={1} + marginY={1} + flexDirection="column" + > + {startupWarnings.map((warning, index) => ( + <Text key={index} color="yellow"> + {warning} + </Text> + ))} + </Box> + )} + <Tips /> {initError && diff --git a/packages/cli/src/ui/hooks/useAppEffects.ts b/packages/cli/src/ui/hooks/useAppEffects.ts new file mode 100644 index 00000000..16f862b0 --- /dev/null +++ b/packages/cli/src/ui/hooks/useAppEffects.ts @@ -0,0 +1,61 @@ +import { useEffect } from 'react'; +import fs from 'fs'; +import path from 'path'; +import os from 'os'; +import type { HistoryItem } from '../types.js'; + +const warningsFilePath = path.join(os.tmpdir(), 'gemini-code-cli-warnings.txt'); + +// Effect to handle startup warnings +export function useStartupWarnings( + setStartupWarnings: React.Dispatch<React.SetStateAction<string[]>>, +) { + useEffect(() => { + try { + if (fs.existsSync(warningsFilePath)) { + const warningsContent = fs.readFileSync(warningsFilePath, 'utf-8'); + setStartupWarnings( + warningsContent.split('\n').filter((line) => line.trim() !== ''), + ); + try { + fs.unlinkSync(warningsFilePath); + } catch (unlinkErr: any) { + setStartupWarnings((prev) => [ + ...prev, + `Warning: Could not delete temporary warnings file.`, + ]); + } + } + } catch (err: any) { + setStartupWarnings((prev) => [ + ...prev, + `Error checking/reading warnings file: ${err.message}`, + ]); + } + }, [setStartupWarnings]); // Include setStartupWarnings in dependency array +} + +// Effect to handle initialization errors +export function useInitializationErrorEffect( + initError: string | null, + history: HistoryItem[], + setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>, +) { + useEffect(() => { + if ( + initError && + !history.some( + (item) => item.type === 'error' && item.text?.includes(initError), + ) + ) { + setHistory((prev) => [ + ...prev, + { + id: Date.now(), + type: 'error', + text: `Initialization Error: ${initError}. Please check API key and configuration.`, + } as HistoryItem, + ]); + } + }, [initError, history, setHistory]); // Include setHistory in dependency array +}
\ No newline at end of file |
