import { Box, Text } from 'ink' import React, { useMemo } from 'react' import { Select } from '../../CustomSelect/select' import { basename, extname } from 'path' import { getTheme } from '../../../utils/theme' import { PermissionRequestTitle, textColorForRiskScore, } from '../PermissionRequestTitle.js' import { logUnaryEvent } from '../../../utils/unaryLogging' import { env } from '../../../utils/env' import { savePermission } from '../../../permissions' import { type ToolUseConfirm, toolUseConfirmGetPrefix, } from '../PermissionRequest.js' import { existsSync } from 'fs' import chalk from 'chalk' import { UnaryEvent, usePermissionRequestLogging, } from '../../../hooks/usePermissionRequestLogging.js' import { FileWriteToolDiff } from './FileWriteToolDiff' import { useTerminalSize } from '../../../hooks/useTerminalSize' type Props = { toolUseConfirm: ToolUseConfirm onDone(): void verbose: boolean } export function FileWritePermissionRequest({ toolUseConfirm, onDone, verbose, }: Props): React.ReactNode { const { file_path, content } = toolUseConfirm.input as { file_path: string content: string } const fileExists = useMemo(() => existsSync(file_path), [file_path]) const unaryEvent = useMemo( () => ({ completion_type: 'write_file_single', language_name: extractLanguageName(file_path), }), [file_path], ) const { columns } = useTerminalSize() usePermissionRequestLogging(toolUseConfirm, unaryEvent) return ( Do you want to {fileExists ? 'make this edit to' : 'create'}{' '} {basename(file_path)}?