-
Notifications
You must be signed in to change notification settings - Fork 11.7k
feat(cli): add shortcuts to /memory list and interactive UI #20429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Oerum
wants to merge
2
commits into
google-gemini:main
Choose a base branch
from
Oerum:issue-20364
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+190
−33
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import type React from 'react'; | ||
| import { useMemo, useState } from 'react'; | ||
| import { Box, Text } from 'ink'; | ||
| import { useUIState } from '../contexts/UIStateContext.js'; | ||
| import { BaseSelectionList } from './shared/BaseSelectionList.js'; | ||
| import { theme } from '../semantic-colors.js'; | ||
| import { useKeypress } from '../hooks/useKeypress.js'; | ||
| import { keyMatchers, Command } from '../keyMatchers.js'; | ||
| import open from 'open'; | ||
| import path from 'node:path'; | ||
|
|
||
| interface MemoryListProps { | ||
| filePaths: string[]; | ||
| onClose: () => void; | ||
| onError: (message: string) => void; | ||
| } | ||
Oerum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const MemoryList: React.FC<MemoryListProps> = ({ | ||
| filePaths, | ||
| onClose, | ||
| onError, | ||
| }) => { | ||
| const { terminalWidth, terminalHeight } = useUIState(); | ||
| const [highlightedIndex, setHighlightedIndex] = useState<number>(0); | ||
|
|
||
| const items = useMemo( | ||
| () => | ||
| filePaths.map((filePath, index) => ({ | ||
| key: `file-${index}`, | ||
| value: filePath, | ||
| index, | ||
| })), | ||
| [filePaths], | ||
| ); | ||
|
|
||
| useKeypress( | ||
| (key) => { | ||
| if (keyMatchers[Command.ESCAPE](key)) { | ||
| onClose(); | ||
| return true; | ||
| } | ||
|
|
||
| if (keyMatchers[Command.OPEN_EXTERNAL_EDITOR](key)) { | ||
| const selectedFile = filePaths[highlightedIndex]; | ||
| if (selectedFile) { | ||
| // Using open package so we do not run into command injection issues | ||
| open(selectedFile).catch((e: Error) => { | ||
| onError(`Failed to open file: ${e.message}`); | ||
| }); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| if (keyMatchers[Command.OPEN_DIRECTORY](key)) { | ||
| const selectedFile = filePaths[highlightedIndex]; | ||
| if (selectedFile) { | ||
| open(path.dirname(selectedFile)).catch((e: Error) => { | ||
| onError(`Failed to open directory: ${e.message}`); | ||
| }); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| }, | ||
| { isActive: true }, | ||
| ); | ||
|
|
||
| const DIALOG_PADDING = 2; | ||
| const HEADER_HEIGHT = 2; | ||
| const CONTROLS_HEIGHT = 2; | ||
|
|
||
| const listHeight = Math.max( | ||
| 5, | ||
| terminalHeight - DIALOG_PADDING - HEADER_HEIGHT - CONTROLS_HEIGHT - 2, | ||
| ); | ||
|
|
||
| const maxItemsToShow = Math.max(1, Math.floor(listHeight)); | ||
|
|
||
| if (filePaths.length === 0) { | ||
| return ( | ||
| <Box | ||
| borderStyle="round" | ||
| borderColor={theme.border.default} | ||
| padding={1} | ||
| width={terminalWidth} | ||
| > | ||
| <Text>No GEMINI.md files found.</Text> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Box | ||
| borderStyle="round" | ||
| borderColor={theme.border.default} | ||
| flexDirection="column" | ||
| width={terminalWidth} | ||
| paddingX={1} | ||
| paddingY={1} | ||
| > | ||
| <Box marginBottom={1}> | ||
| <Text bold>{'> '}Memory Files</Text> | ||
| </Box> | ||
|
|
||
| <Box flexDirection="column" flexGrow={1}> | ||
| <BaseSelectionList | ||
| items={items} | ||
| initialIndex={highlightedIndex} | ||
| isFocused={true} | ||
| showNumbers={true} | ||
| wrapAround={false} | ||
| onSelect={() => { | ||
| // Do nothing on enter for now, or just close | ||
| onClose(); | ||
| }} | ||
| onHighlight={(item: string) => { | ||
| const index = filePaths.indexOf(item); | ||
| if (index !== -1) { | ||
| setHighlightedIndex(index); | ||
| } | ||
| }} | ||
| maxItemsToShow={maxItemsToShow} | ||
| renderItem={(itemWrapper, { isSelected }) => { | ||
| const filePath = itemWrapper.value; | ||
| const basename = path.basename(filePath); | ||
| const dir = path.dirname(filePath); | ||
|
|
||
| return ( | ||
| <Box flexDirection="column"> | ||
| <Text | ||
| color={isSelected ? theme.status.success : theme.text.primary} | ||
| > | ||
| {basename} | ||
| </Text> | ||
| <Text color={theme.text.secondary}>{dir}</Text> | ||
| </Box> | ||
| ); | ||
| }} | ||
| /> | ||
| </Box> | ||
|
|
||
| <Box marginTop={1}> | ||
| <Text color={theme.text.secondary}> | ||
| (Use Esc to close, Ctrl+X to open in editor, Alt+O to open folder) | ||
| </Text> | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.