Move Intro to Help and only display after help command.

This commit is contained in:
Seth Troisi 2025-05-05 20:48:34 +00:00
parent 415b757d4a
commit bb52149a06
4 changed files with 21 additions and 15 deletions

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import React, { useCallback, useMemo, useRef, useState } from 'react'; import React, { useCallback, useMemo, useState } from 'react';
import { Box, Static, Text, useStdout } from 'ink'; import { Box, Static, Text, useStdout } from 'ink';
import { StreamingState, type HistoryItem } from './types.js'; import { StreamingState, type HistoryItem } from './types.js';
import { useGeminiStream } from './hooks/useGeminiStream.js'; import { useGeminiStream } from './hooks/useGeminiStream.js';
@ -19,7 +19,7 @@ import { ThemeDialog } from './components/ThemeDialog.js';
import { useStartupWarnings } from './hooks/useAppEffects.js'; import { useStartupWarnings } from './hooks/useAppEffects.js';
import { shortenPath, type Config } from '@gemini-code/server'; import { shortenPath, type Config } from '@gemini-code/server';
import { Colors } from './colors.js'; import { Colors } from './colors.js';
import { Intro } from './components/Intro.js'; import { Help } from './components/Help.js';
import { LoadedSettings } from '../config/settings.js'; import { LoadedSettings } from '../config/settings.js';
import { Tips } from './components/Tips.js'; import { Tips } from './components/Tips.js';
import { ConsoleOutput } from './components/ConsolePatcher.js'; import { ConsoleOutput } from './components/ConsolePatcher.js';
@ -37,6 +37,7 @@ interface AppProps {
export const App = ({ config, settings, cliVersion }: AppProps) => { export const App = ({ config, settings, cliVersion }: AppProps) => {
const [history, setHistory] = useState<HistoryItem[]>([]); const [history, setHistory] = useState<HistoryItem[]>([]);
const [startupWarnings, setStartupWarnings] = useState<string[]>([]); const [startupWarnings, setStartupWarnings] = useState<string[]>([]);
const [showHelp, setShowHelp] = useState<boolean>(false);
const { const {
isThemeDialogOpen, isThemeDialogOpen,
openThemeDialog, openThemeDialog,
@ -55,7 +56,13 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
initError, initError,
debugMessage, debugMessage,
slashCommands, slashCommands,
} = useGeminiStream(setHistory, refreshStatic, config, openThemeDialog); } = useGeminiStream(
setHistory,
refreshStatic,
setShowHelp,
config,
openThemeDialog,
);
const { elapsedTime, currentLoadingPhrase } = const { elapsedTime, currentLoadingPhrase } =
useLoadingIndicator(streamingState); useLoadingIndicator(streamingState);
@ -139,7 +146,6 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
<Box flexDirection="column" key={'header-' + index}> <Box flexDirection="column" key={'header-' + index}>
<Header /> <Header />
<Tips /> <Tips />
<Intro commands={slashCommands} />
</Box> </Box>
); );
} }
@ -167,6 +173,8 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
</Box> </Box>
)} )}
{showHelp && <Help commands={slashCommands} />}
{startupWarnings.length > 0 && ( {startupWarnings.length > 0 && (
<Box <Box
borderStyle="round" borderStyle="round"

View File

@ -9,11 +9,11 @@ import { Box, Text } from 'ink';
import { Colors } from '../colors.js'; import { Colors } from '../colors.js';
import { SlashCommand } from '../hooks/slashCommandProcessor.js'; import { SlashCommand } from '../hooks/slashCommandProcessor.js';
interface Intro { interface Help {
commands: SlashCommand[]; commands: SlashCommand[];
} }
export const Intro: React.FC<Intro> = ({ commands }) => ( export const Help: React.FC<Help> = ({ commands }) => (
<Box flexDirection="column" marginBottom={1}> <Box flexDirection="column" marginBottom={1}>
<Text bold color={Colors.Foreground}> <Text bold color={Colors.Foreground}>
Abilities: Abilities:

View File

@ -29,6 +29,7 @@ const addHistoryItem = (
export const useSlashCommandProcessor = ( export const useSlashCommandProcessor = (
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>, setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
refreshStatic: () => void, refreshStatic: () => void,
setShowHelp: React.Dispatch<React.SetStateAction<boolean>>,
setDebugMessage: React.Dispatch<React.SetStateAction<string>>, setDebugMessage: React.Dispatch<React.SetStateAction<string>>,
getNextMessageId: (baseTimestamp: number) => number, getNextMessageId: (baseTimestamp: number) => number,
openThemeDialog: () => void, openThemeDialog: () => void,
@ -38,15 +39,8 @@ export const useSlashCommandProcessor = (
name: 'help', name: 'help',
description: 'for help on gemini-code', description: 'for help on gemini-code',
action: (_value: PartListUnion) => { action: (_value: PartListUnion) => {
const helpText = setDebugMessage('Opening help.');
'I am an interactive CLI tool assistant designed to ' + setShowHelp(true);
'help with software engineering tasks. I can use tools to read ' +
'and write files, search code, execute bash commands, and more ' +
'to assist with development workflows. I will explain commands ' +
'and ask for permission before running them and will not ' +
'commit changes unless explicitly instructed.';
const timestamp = getNextMessageId(Date.now());
addHistoryItem(setHistory, { type: 'info', text: helpText }, timestamp);
}, },
}, },
{ {

View File

@ -48,6 +48,7 @@ const addHistoryItem = (
export const useGeminiStream = ( export const useGeminiStream = (
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>, setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
refreshStatic: () => void, refreshStatic: () => void,
setShowHelp: React.Dispatch<React.SetStateAction<boolean>>,
config: Config, config: Config,
openThemeDialog: () => void, openThemeDialog: () => void,
) => { ) => {
@ -74,6 +75,7 @@ export const useGeminiStream = (
const { handleSlashCommand, slashCommands } = useSlashCommandProcessor( const { handleSlashCommand, slashCommands } = useSlashCommandProcessor(
setHistory, setHistory,
refreshStatic, refreshStatic,
setShowHelp,
setDebugMessage, setDebugMessage,
getNextMessageId, getNextMessageId,
openThemeDialog, openThemeDialog,
@ -154,6 +156,8 @@ export const useGeminiStream = (
messageIdCounterRef.current = 0; // Reset counter for this new submission messageIdCounterRef.current = 0; // Reset counter for this new submission
let queryToSendToGemini: PartListUnion | null = null; let queryToSendToGemini: PartListUnion | null = null;
setShowHelp(false);
if (typeof query === 'string') { if (typeof query === 'string') {
const trimmedQuery = query.trim(); const trimmedQuery = query.trim();
setDebugMessage(`User query: '${trimmedQuery}'`); setDebugMessage(`User query: '${trimmedQuery}'`);