/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { ToolConfirmationOutcome } from '@qwen-code/qwen-code-core'; import { Box, Text } from 'ink'; import type React from 'react'; import { theme } from '../semantic-colors.js'; import { RenderInline } from '../utils/InlineMarkdownRenderer.js'; import type { RadioSelectItem } from './shared/RadioButtonSelect.js'; import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; import { useKeypress } from '../hooks/useKeypress.js'; import { t } from '../../i18n/index.js'; export interface ShellConfirmationRequest { commands: string[]; onConfirm: ( outcome: ToolConfirmationOutcome, approvedCommands?: string[], ) => void; } export interface ShellConfirmationDialogProps { request: ShellConfirmationRequest; } export const ShellConfirmationDialog: React.FC< ShellConfirmationDialogProps > = ({ request }) => { const { commands, onConfirm } = request; useKeypress( (key) => { if (key.name === 'escape') { onConfirm(ToolConfirmationOutcome.Cancel); } }, { isActive: true }, ); const handleSelect = (item: ToolConfirmationOutcome) => { if (item === ToolConfirmationOutcome.Cancel) { onConfirm(item); } else { // For both ProceedOnce and ProceedAlways, we approve all the // commands that were requested. onConfirm(item, commands); } }; const options: Array> = [ { label: t('Yes, allow once'), value: ToolConfirmationOutcome.ProceedOnce, key: 'Yes, allow once', }, { label: t('Yes, allow always for this session'), value: ToolConfirmationOutcome.ProceedAlways, key: 'Yes, allow always for this session', }, { label: t('No (esc)'), value: ToolConfirmationOutcome.Cancel, key: 'No (esc)', }, ]; return ( {t('Shell Command Execution')} {t('A custom command wants to run the following shell commands:')} {commands.map((cmd) => ( ))} {t('Do you want to proceed?')} ); };