mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-15 20:40:35 -07:00
feat(cli): implement prompt stashing with Alt+S
This commit is contained in:
@@ -567,6 +567,8 @@ const mockUIActions: UIActions = {
|
||||
handleEmptyWalletChoice: vi.fn(),
|
||||
setQueueErrorMessage: vi.fn(),
|
||||
popAllMessages: vi.fn(),
|
||||
stashPrompt: vi.fn(),
|
||||
popStashedPrompt: vi.fn(),
|
||||
handleApiKeySubmit: vi.fn(),
|
||||
handleApiKeyCancel: vi.fn(),
|
||||
setBannerVisible: vi.fn(),
|
||||
|
||||
@@ -253,6 +253,18 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||
QUEUE_ERROR_DISPLAY_DURATION_MS,
|
||||
);
|
||||
|
||||
const [stashedPrompt, setStashedPrompt] = useState<string | null>(null);
|
||||
const stashPrompt = useCallback((text: string) => {
|
||||
if (text.length > 0) {
|
||||
setStashedPrompt(text);
|
||||
}
|
||||
}, []);
|
||||
const popStashedPrompt = useCallback(() => {
|
||||
const prompt = stashedPrompt;
|
||||
setStashedPrompt(null);
|
||||
return prompt;
|
||||
}, [stashedPrompt]);
|
||||
|
||||
const [newAgents, setNewAgents] = useState<AgentDefinition[] | null>(null);
|
||||
const [constrainHeight, setConstrainHeight] = useState<boolean>(true);
|
||||
const [expandHintTrigger, triggerExpandHint] = useTimedMessage<boolean>(
|
||||
@@ -2267,6 +2279,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
activeHooks,
|
||||
messageQueue,
|
||||
queueErrorMessage,
|
||||
stashedPrompt,
|
||||
showApprovalModeIndicator,
|
||||
allowPlanMode,
|
||||
currentModel,
|
||||
@@ -2393,6 +2406,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
activeHooks,
|
||||
messageQueue,
|
||||
queueErrorMessage,
|
||||
stashedPrompt,
|
||||
showApprovalModeIndicator,
|
||||
allowPlanMode,
|
||||
userTier,
|
||||
@@ -2492,6 +2506,8 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
handleDeleteSession,
|
||||
setQueueErrorMessage,
|
||||
popAllMessages,
|
||||
stashPrompt,
|
||||
popStashedPrompt,
|
||||
handleApiKeySubmit,
|
||||
handleApiKeyCancel,
|
||||
setBannerVisible,
|
||||
@@ -2583,6 +2599,8 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
handleDeleteSession,
|
||||
setQueueErrorMessage,
|
||||
popAllMessages,
|
||||
stashPrompt,
|
||||
popStashedPrompt,
|
||||
handleApiKeySubmit,
|
||||
handleApiKeyCancel,
|
||||
setBannerVisible,
|
||||
|
||||
@@ -158,6 +158,7 @@ const createMockUIState = (overrides: Partial<UIState> = {}): UIState =>
|
||||
contextFileNames: [],
|
||||
showApprovalModeIndicator: ApprovalMode.DEFAULT,
|
||||
messageQueue: [],
|
||||
stashedPrompt: null,
|
||||
showErrorDetails: false,
|
||||
constrainHeight: false,
|
||||
isInputActive: true,
|
||||
|
||||
@@ -39,6 +39,7 @@ import { InputPrompt } from './InputPrompt.js';
|
||||
import { Footer } from './Footer.js';
|
||||
import { ShowMoreLines } from './ShowMoreLines.js';
|
||||
import { QueuedMessageDisplay } from './QueuedMessageDisplay.js';
|
||||
import { StashedPromptDisplay } from './StashedPromptDisplay.js';
|
||||
import { OverflowProvider } from '../contexts/OverflowContext.js';
|
||||
import { ConfigInitDisplay } from './ConfigInitDisplay.js';
|
||||
import { TodoTray } from './messages/Todo.js';
|
||||
@@ -522,6 +523,10 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => {
|
||||
<ConfigInitDisplay message="Resuming session..." />
|
||||
)}
|
||||
|
||||
{showUiDetails && (
|
||||
<StashedPromptDisplay stashedPrompt={uiState.stashedPrompt} />
|
||||
)}
|
||||
|
||||
{showUiDetails && (
|
||||
<QueuedMessageDisplay messageQueue={uiState.messageQueue} />
|
||||
)}
|
||||
|
||||
@@ -190,6 +190,12 @@ export const Help: React.FC<Help> = ({ commands }) => (
|
||||
</Text>{' '}
|
||||
- Cycle through your prompt history
|
||||
</Text>
|
||||
<Text color={theme.text.primary}>
|
||||
<Text bold color={theme.text.accent}>
|
||||
{formatCommand(Command.STASH_INPUT)}
|
||||
</Text>{' '}
|
||||
- Stash current prompt (restores on next submit)
|
||||
</Text>
|
||||
<Box height={1} />
|
||||
<Text color={theme.text.primary}>
|
||||
For a full list of shortcuts, see{' '}
|
||||
|
||||
@@ -225,6 +225,8 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
setEmbeddedShellFocused,
|
||||
setShortcutsHelpVisible,
|
||||
toggleCleanUiDetailsVisible,
|
||||
stashPrompt,
|
||||
popStashedPrompt,
|
||||
} = useUIActions();
|
||||
const {
|
||||
terminalWidth,
|
||||
@@ -372,6 +374,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
onSubmit(processedValue);
|
||||
resetCompletionState();
|
||||
resetReverseSearchCompletionState();
|
||||
|
||||
// Restore stashed prompt after submit
|
||||
const stashed = popStashedPrompt();
|
||||
if (stashed) {
|
||||
buffer.setText(stashed, 'end');
|
||||
}
|
||||
},
|
||||
[
|
||||
buffer,
|
||||
@@ -380,6 +388,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
shellModeActive,
|
||||
shellHistory,
|
||||
resetReverseSearchCompletionState,
|
||||
popStashedPrompt,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1213,6 +1222,16 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
return true;
|
||||
}
|
||||
|
||||
// Stash current input
|
||||
if (keyMatchers[Command.STASH_INPUT](key)) {
|
||||
if (buffer.text.length > 0) {
|
||||
stashPrompt(buffer.text);
|
||||
buffer.setText('');
|
||||
resetCompletionState();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// External editor
|
||||
if (keyMatchers[Command.OPEN_EXTERNAL_EDITOR](key)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
@@ -1304,6 +1323,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
shouldShowSuggestions,
|
||||
isShellSuggestionsVisible,
|
||||
forceShowShellSuggestions,
|
||||
stashPrompt,
|
||||
keyMatchers,
|
||||
isHelpDismissKey,
|
||||
settings,
|
||||
|
||||
@@ -44,6 +44,10 @@ const buildShortcutItems = (): ShortcutItem[] => [
|
||||
key: formatCommand(Command.OPEN_EXTERNAL_EDITOR),
|
||||
description: 'open external editor',
|
||||
},
|
||||
{
|
||||
key: formatCommand(Command.STASH_INPUT),
|
||||
description: 'stash prompt',
|
||||
},
|
||||
];
|
||||
|
||||
const Shortcut: React.FC<{ item: ShortcutItem }> = ({ item }) => (
|
||||
@@ -73,8 +77,9 @@ export const ShortcutsHelp: React.FC = () => {
|
||||
items[7],
|
||||
items[2],
|
||||
items[8],
|
||||
items[9],
|
||||
items[10],
|
||||
items[3],
|
||||
items[9],
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { render } from '../../test-utils/render.js';
|
||||
import { StashedPromptDisplay } from './StashedPromptDisplay.js';
|
||||
|
||||
describe('StashedPromptDisplay', () => {
|
||||
it('renders nothing when no stash exists', async () => {
|
||||
const { lastFrame, unmount } = await render(
|
||||
<StashedPromptDisplay stashedPrompt={null} />,
|
||||
);
|
||||
|
||||
expect(lastFrame({ allowEmpty: true })).toBe('');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('displays stash indicator when stash exists', async () => {
|
||||
const { lastFrame, unmount } = await render(
|
||||
<StashedPromptDisplay stashedPrompt="some stashed text" />,
|
||||
);
|
||||
|
||||
const output = lastFrame();
|
||||
expect(output).toContain('Stashed (restores after submit)');
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('does not display the stashed text content', async () => {
|
||||
const { lastFrame, unmount } = await render(
|
||||
<StashedPromptDisplay stashedPrompt="secret stashed content" />,
|
||||
);
|
||||
|
||||
const output = lastFrame();
|
||||
expect(output).toContain('Stashed');
|
||||
expect(output).not.toContain('secret stashed content');
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { Box, Text } from 'ink';
|
||||
|
||||
export interface StashedPromptDisplayProps {
|
||||
stashedPrompt: string | null;
|
||||
}
|
||||
|
||||
export const StashedPromptDisplay = ({
|
||||
stashedPrompt,
|
||||
}: StashedPromptDisplayProps) => {
|
||||
if (!stashedPrompt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box paddingLeft={2} marginTop={1}>
|
||||
<Text dimColor>Stashed (restores after submit)</Text>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -202,6 +202,7 @@ const MAC_ALT_KEY_CHARACTER_MAP: Record<string, string> = {
|
||||
'\u222B': 'b', // "∫" back one word
|
||||
'\u0192': 'f', // "ƒ" forward one word
|
||||
'\u00B5': 'm', // "µ" toggle markup view
|
||||
'\u00DF': 's', // "ß" stash prompt
|
||||
'\u03A9': 'z', // "Ω" Option+z
|
||||
'\u00B8': 'Z', // "¸" Option+Shift+z
|
||||
'\u2202': 'd', // "∂" delete word forward
|
||||
|
||||
@@ -71,6 +71,8 @@ export interface UIActions {
|
||||
handleDeleteSession: (session: SessionInfo) => Promise<void>;
|
||||
setQueueErrorMessage: (message: string | null) => void;
|
||||
popAllMessages: () => string | undefined;
|
||||
stashPrompt: (text: string) => void;
|
||||
popStashedPrompt: () => string | null;
|
||||
handleApiKeySubmit: (apiKey: string) => Promise<void>;
|
||||
handleApiKeyCancel: () => void;
|
||||
setBannerVisible: (visible: boolean) => void;
|
||||
|
||||
@@ -172,6 +172,7 @@ export interface UIState {
|
||||
activeHooks: ActiveHook[];
|
||||
messageQueue: string[];
|
||||
queueErrorMessage: string | null;
|
||||
stashedPrompt: string | null;
|
||||
showApprovalModeIndicator: ApprovalMode;
|
||||
allowPlanMode: boolean;
|
||||
// Quota-related state
|
||||
|
||||
@@ -77,6 +77,7 @@ export enum Command {
|
||||
NEWLINE = 'input.newline',
|
||||
OPEN_EXTERNAL_EDITOR = 'input.openExternalEditor',
|
||||
PASTE_CLIPBOARD = 'input.paste',
|
||||
STASH_INPUT = 'input.stash',
|
||||
|
||||
// App Controls
|
||||
SHOW_ERROR_DETAILS = 'app.showErrorDetails',
|
||||
@@ -374,6 +375,8 @@ export const defaultKeyBindingConfig: KeyBindingConfig = new Map([
|
||||
],
|
||||
],
|
||||
|
||||
[Command.STASH_INPUT, [new KeyBinding('alt+s')]],
|
||||
|
||||
// App Controls
|
||||
[Command.SHOW_ERROR_DETAILS, [new KeyBinding('f12')]],
|
||||
[Command.SHOW_FULL_TODOS, [new KeyBinding('ctrl+t')]],
|
||||
@@ -491,6 +494,7 @@ export const commandCategories: readonly CommandCategory[] = [
|
||||
Command.NEWLINE,
|
||||
Command.OPEN_EXTERNAL_EDITOR,
|
||||
Command.PASTE_CLIPBOARD,
|
||||
Command.STASH_INPUT,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -597,6 +601,8 @@ export const commandDescriptions: Readonly<Record<Command, string>> = {
|
||||
[Command.OPEN_EXTERNAL_EDITOR]:
|
||||
'Open the current prompt or the plan in an external editor.',
|
||||
[Command.PASTE_CLIPBOARD]: 'Paste from the clipboard.',
|
||||
[Command.STASH_INPUT]:
|
||||
'Stash the current input to temporarily set it aside. Restores on next submit.',
|
||||
|
||||
// App Controls
|
||||
[Command.SHOW_ERROR_DETAILS]: 'Toggle detailed error information.',
|
||||
|
||||
Reference in New Issue
Block a user