/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ import type React from 'react'; import { Box, Text } from 'ink'; import { Colors } from '../colors.js'; import type { RadioSelectItem } from './shared/RadioButtonSelect.js'; import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; import { useKeypress } from '../hooks/useKeypress.js'; import type { TrustLevel } from '../../config/trustedFolders.js'; import type { UseHistoryManagerReturn } from '../hooks/useHistoryManager.js'; import type { PermissionsTrustRuntime } from '../hooks/usePermissionsModifyTrust.js'; import { usePermissionsTrustDialogFlow } from '../hooks/usePermissionsTrustDialogFlow.js'; import { getLocalTrustLevelDisplay, shouldDismissTrustDialog, type TrustFormChoice, } from '../trustDialogHelpers.js'; import { PermissionsTrustPathInput } from './PermissionsTrustPathInput.js'; import { PermissionsTrustRulesList } from './PermissionsTrustRulesList.js'; import { getBorderStyle } from '../contexts/UnicodeRenderingContext.js'; interface PermissionsModifyTrustDialogProps { onExit: () => void; addItem: UseHistoryManagerReturn['addItem']; config?: PermissionsTrustRuntime; } interface UpdatedPromptProps { committedTrustLevel: TrustLevel | undefined; effectiveTrustDisplay: string; } const UpdatedPrompt: React.FC = ({ committedTrustLevel, effectiveTrustDisplay, }) => ( Trust level updated Saved local fallback:{' '} {getLocalTrustLevelDisplay(committedTrustLevel)} Effective now:{' '} {effectiveTrustDisplay} Press Enter to continue. ); interface TrustFormProps { targetPath: string; isTargetCwd: boolean; currentTrustLevel: TrustLevel | undefined; getDisplayText: (level: TrustLevel | undefined) => string; warningMessage: string | null; options: Array>; initialIndex: number; onSelect: (choice: TrustFormChoice) => void | Promise; isCommitting: boolean; } const TrustForm: React.FC = ({ targetPath, isTargetCwd, currentTrustLevel, getDisplayText, warningMessage, options, initialIndex, onSelect, isCommitting, }) => ( Modify Trust Settings Folder: {targetPath} {!isTargetCwd && ( (not the current folder — trusting it does not add it to this workspace) )} Current: {getDisplayText(currentTrustLevel)} {warningMessage && ( {warningMessage} )} Select trust level: items={options} initialIndex={initialIndex} onSelect={(choice) => { if (!isCommitting) { void onSelect(choice); } }} isFocused={!isCommitting} /> (Use Enter to select, Escape to cancel) ); export const PermissionsModifyTrustDialog: React.FC< PermissionsModifyTrustDialogProps > = ({ onExit, addItem, config }) => { const flow = usePermissionsTrustDialogFlow(onExit, addItem, config); useKeypress( (key) => { if (flow.isCommitPending()) { return; } if (flow.view === 'updated') { if (shouldDismissTrustDialog(true, key.name)) { onExit(); } return; } if (key.name === 'escape') { flow.handleEscape(); } }, { isActive: true }, ); if (flow.view === 'updated') { return ( ); } if (flow.view === 'path-entry') { return ( ); } if (flow.view === 'rules') { return ( ); } return ( ); };