From fb23321514dbc8d1c0243457e8d5d8d953bb3985 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Tue, 29 Apr 2025 23:38:26 +0000 Subject: [PATCH] Add Intro text with list of /commands --- packages/cli/src/ui/App.tsx | 11 +++-- packages/cli/src/ui/components/Intro.tsx | 43 +++++++++++-------- .../cli/src/ui/hooks/slashCommandProcessor.ts | 10 ++--- packages/cli/src/ui/hooks/useGeminiStream.ts | 10 ++++- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index ce326af5..4bf7123e 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -32,8 +32,13 @@ interface AppProps { export const App = ({ config, cliVersion }: AppProps) => { const [history, setHistory] = useState([]); const [startupWarnings, setStartupWarnings] = useState([]); - const { streamingState, submitQuery, initError, debugMessage } = - useGeminiStream(setHistory, config); + const { + streamingState, + submitQuery, + initError, + debugMessage, + slashCommands, + } = useGeminiStream(setHistory, config); const { elapsedTime, currentLoadingPhrase } = useLoadingIndicator(streamingState); @@ -104,7 +109,7 @@ export const App = ({ config, cliVersion }: AppProps) => {
- + ); } diff --git a/packages/cli/src/ui/components/Intro.tsx b/packages/cli/src/ui/components/Intro.tsx index 04dac134..d99e5993 100644 --- a/packages/cli/src/ui/components/Intro.tsx +++ b/packages/cli/src/ui/components/Intro.tsx @@ -7,28 +7,35 @@ import React from 'react'; import { Box, Newline, Text } from 'ink'; import { Colors } from '../colors.js'; +import { SlashCommand } from '../hooks/slashCommandProcessor.js'; -export const Intro: React.FC = () => ( +interface Intro { + commands: SlashCommand[]; +} + +export const Intro: React.FC = ({ commands }) => ( - Abilities: - * Use tools to read and write files - * Semantically search and understand code - * Execute bash commands - - Commands: - - /help - {' '}- prints this help + + Abilities: - - /clear - {' '}- clear the screen + * Use tools to read and write files + + {' '} + * Semantically search and explain code - - /exit - - - /quit + * Execute bash commands + + + Commands: + {commands.map((command: SlashCommand) => ( + + + {' '} + /{command.name} + + {command.description && ' - ' + command.description} + + ))} ); diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 400597e3..6608001b 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -9,7 +9,7 @@ import { type PartListUnion } from '@google/genai'; import { HistoryItem } from '../types.js'; import { isSlashCommand } from '../utils/commandUtils.js'; -interface SlashCommand { +export interface SlashCommand { name: string; // slash command description: string; // flavor text in UI action: (value: PartListUnion) => void; @@ -43,7 +43,7 @@ export const useSlashCommandProcessor = ( }, { name: 'help', - description: '/help for help on gemini-code', + description: 'for help on gemini-code', action: (_value: PartListUnion) => { const helpText = 'I am an interactive CLI tool assistant designed to ' + @@ -58,7 +58,7 @@ export const useSlashCommandProcessor = ( }, { name: 'exit', - description: 'Exit gemini-code', + description: '', action: (_value: PartListUnion) => { setDebugMessage('Exiting. Good-bye.'); const timestamp = getNextMessageId(Date.now()); @@ -73,7 +73,7 @@ export const useSlashCommandProcessor = ( { // TODO: dedup with exit by adding altName or cmdRegex. name: 'quit', - description: 'Quit gemini-code', + description: '', action: (_value: PartListUnion) => { setDebugMessage('Quitting. Good-bye.'); const timestamp = getNextMessageId(Date.now()); @@ -121,5 +121,5 @@ export const useSlashCommandProcessor = ( [setDebugMessage, setHistory, getNextMessageId, slashCommands], ); - return { handleSlashCommand }; + return { handleSlashCommand, slashCommands }; }; diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 7e1f2177..f166bc1e 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -69,7 +69,7 @@ export const useGeminiStream = ( }, []); // Instantiate command processors - const { handleSlashCommand } = useSlashCommandProcessor( + const { handleSlashCommand, slashCommands } = useSlashCommandProcessor( setHistory, setDebugMessage, getNextMessageId, @@ -532,5 +532,11 @@ export const useGeminiStream = ( ], ); - return { streamingState, submitQuery, initError, debugMessage }; + return { + streamingState, + submitQuery, + initError, + debugMessage, + slashCommands, + }; };