/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { Box, Text } from 'ink'; import type React from 'react'; import { useMemo } from 'react'; import { theme } from '../semantic-colors.js'; import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; import type { RadioSelectItem } from './shared/RadioButtonSelect.js'; import type { FileChangeStats } from '../utils/rewindFileOps.js'; import { useKeypress } from '../hooks/useKeypress.js'; import { formatTimeAgo } from '../utils/formatters.js'; import { keyMatchers, Command } from '../keyMatchers.js'; export enum RewindOutcome { RewindAndRevert = 'rewind_and_revert', RewindOnly = 'rewind_only', RevertOnly = 'revert_only', Cancel = 'cancel', } const REWIND_OPTIONS: Array> = [ { label: 'Rewind conversation and revert code changes', value: RewindOutcome.RewindAndRevert, key: 'Rewind conversation and revert code changes', }, { label: 'Rewind conversation', value: RewindOutcome.RewindOnly, key: 'Rewind conversation', }, { label: 'Revert code changes', value: RewindOutcome.RevertOnly, key: 'Revert code changes', }, { label: 'Do nothing (esc)', value: RewindOutcome.Cancel, key: 'Do nothing (esc)', }, ]; interface RewindConfirmationProps { stats: FileChangeStats | null; onConfirm: (outcome: RewindOutcome) => void; terminalWidth: number; timestamp?: string; } export const RewindConfirmation: React.FC = ({ stats, onConfirm, terminalWidth, timestamp, }) => { useKeypress( (key) => { if (keyMatchers[Command.ESCAPE](key)) { onConfirm(RewindOutcome.Cancel); } }, { isActive: true }, ); const handleSelect = (outcome: RewindOutcome) => { onConfirm(outcome); }; const options = useMemo(() => { if (stats) { return REWIND_OPTIONS; } return REWIND_OPTIONS.filter( (option) => option.value !== RewindOutcome.RewindAndRevert && option.value !== RewindOutcome.RevertOnly, ); }, [stats]); return ( Confirm Rewind {stats && ( {stats.fileCount === 1 ? `File: ${stats.details?.at(0)?.fileName}` : `${stats.fileCount} files affected`} Lines added: {stats.addedLines}{' '} Lines removed: {stats.removedLines} {timestamp && ( {' '} ({formatTimeAgo(timestamp)}) )} ℹ Rewinding does not affect files edited manually or by the shell tool. )} {!stats && ( No code changes to revert. {timestamp && ( {' '} ({formatTimeAgo(timestamp)}) )} )} Select an action: ); };