/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { Box, Text } from 'ink'; import type React from 'react'; import { useEffect, useState, useCallback } from 'react'; import { theme } from '../semantic-colors.js'; import type { RadioSelectItem } from './shared/RadioButtonSelect.js'; import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; import { useKeypress } from '../hooks/useKeypress.js'; import * as process from 'node:process'; import { relaunchApp } from '../../utils/processUtils.js'; import { runExitCleanup } from '../../utils/cleanup.js'; import { ExitCodes } from '@google/gemini-cli-core'; export enum PolicyUpdateChoice { ACCEPT = 'accept', IGNORE = 'ignore', } interface PolicyUpdateDialogProps { onSelect: (choice: PolicyUpdateChoice) => void; scope: string; identifier: string; isRestarting?: boolean; } export const PolicyUpdateDialog: React.FC = ({ onSelect, scope, identifier, isRestarting, }) => { const [exiting, setExiting] = useState(false); useEffect(() => { let timer: ReturnType; if (isRestarting) { timer = setTimeout(async () => { await relaunchApp(); }, 250); } return () => { if (timer) clearTimeout(timer); }; }, [isRestarting]); const handleExit = useCallback(() => { setExiting(true); // Give time for the UI to render the exiting message setTimeout(async () => { await runExitCleanup(); process.exit(ExitCodes.FATAL_CANCELLATION_ERROR); }, 100); }, []); useKeypress( (key) => { if (key.name === 'escape') { handleExit(); return true; } return false; }, { isActive: !isRestarting }, ); const options: Array> = [ { label: 'Accept and Load (Requires Restart)', value: PolicyUpdateChoice.ACCEPT, key: 'accept', }, { label: 'Ignore (Use Default Policies)', value: PolicyUpdateChoice.IGNORE, key: 'ignore', }, ]; return ( New or changed {scope} policies detected Location: {identifier} Do you want to accept and load these policies? {isRestarting && ( Gemini CLI is restarting to apply the policy changes... )} {exiting && ( A selection must be made to continue. Exiting since escape was pressed. )} ); };