/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { Box, Text } from 'ink'; import type React from 'react'; import { TrustLevel } from '../../config/trustedFolders.js'; import { useKeypress } from '../hooks/useKeypress.js'; import { usePermissionsModifyTrust } from '../hooks/usePermissionsModifyTrust.js'; import { theme } from '../semantic-colors.js'; import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; import { relaunchApp } from '../../utils/processUtils.js'; import { type UseHistoryManagerReturn } from '../hooks/useHistoryManager.js'; interface PermissionsModifyTrustDialogProps { onExit: () => void; addItem: UseHistoryManagerReturn['addItem']; } const TRUST_LEVEL_ITEMS = [ { label: 'Trust this folder', value: TrustLevel.TRUST_FOLDER, key: TrustLevel.TRUST_FOLDER, }, { label: 'Trust parent folder', value: TrustLevel.TRUST_PARENT, key: TrustLevel.TRUST_PARENT, }, { label: "Don't trust", value: TrustLevel.DO_NOT_TRUST, key: TrustLevel.DO_NOT_TRUST, }, ]; export function PermissionsModifyTrustDialog({ onExit, addItem, }: PermissionsModifyTrustDialogProps): React.JSX.Element { const { cwd, currentTrustLevel, isInheritedTrustFromParent, isInheritedTrustFromIde, needsRestart, updateTrustLevel, commitTrustLevelChange, } = usePermissionsModifyTrust(onExit, addItem); useKeypress( (key) => { if (key.name === 'escape') { onExit(); } if (needsRestart && key.name === 'r') { commitTrustLevelChange(); relaunchApp(); onExit(); } }, { isActive: true }, ); const index = TRUST_LEVEL_ITEMS.findIndex( (item) => item.value === currentTrustLevel, ); const initialIndex = index === -1 ? 0 : index; return ( <> {'> '}Modify Trust Level Folder: {cwd} Current Level: {currentTrustLevel || 'Not Set'} {isInheritedTrustFromParent && ( Note: This folder behaves as a trusted folder because one of the parent folders is trusted. It will remain trusted even if you set a different trust level here. To change this, you need to modify the trust setting in the parent folder. )} {isInheritedTrustFromIde && ( Note: This folder behaves as a trusted folder because the connected IDE workspace is trusted. It will remain trusted even if you set a different trust level here. )} (Use Enter to select) {needsRestart && ( To apply the trust changes, Qwen Code must be restarted. Press 'r' to restart CLI now. )} ); }