toolUseOptions.ts
1 import { type Option } from '@inkjs/ui' 2 import chalk from 'chalk' 3 import { 4 type ToolUseConfirm, 5 toolUseConfirmGetPrefix, 6 } from './PermissionRequest.js' 7 import { isUnsafeCompoundCommand } from '../../utils/commands.js' 8 import { getCwd } from '../../utils/state.js' 9 import { getTheme } from '../../utils/theme.js' 10 import { type OptionSubtree } from '../CustomSelect/select.js' 11 12 /** 13 * Generates options for the tool use confirmation dialog 14 */ 15 export function toolUseOptions({ 16 toolUseConfirm, 17 command, 18 }: { 19 toolUseConfirm: ToolUseConfirm 20 command: string 21 }): (Option | OptionSubtree)[] { 22 // Hide "don't ask again" options if the command is an unsafe compound command, or a potential command injection 23 const showDontAskAgainOption = 24 !isUnsafeCompoundCommand(command) && 25 toolUseConfirm.commandPrefix && 26 !toolUseConfirm.commandPrefix.commandInjectionDetected 27 const prefix = toolUseConfirmGetPrefix(toolUseConfirm) 28 const showDontAskAgainPrefixOption = showDontAskAgainOption && prefix !== null 29 30 let dontShowAgainOptions: (Option | OptionSubtree)[] = [] 31 if (showDontAskAgainPrefixOption) { 32 // Prefix option takes precedence over full command option 33 dontShowAgainOptions = [ 34 { 35 label: `Yes, and don't ask again for ${chalk.bold(prefix)} commands in ${chalk.bold(getCwd())}`, 36 value: 'yes-dont-ask-again-prefix', 37 }, 38 ] 39 } else if (showDontAskAgainOption) { 40 dontShowAgainOptions = [ 41 { 42 label: `Yes, and don't ask again for ${chalk.bold(command)} commands in ${chalk.bold(getCwd())}`, 43 value: 'yes-dont-ask-again-full', 44 }, 45 ] 46 } 47 48 return [ 49 { 50 label: 'Yes', 51 value: 'yes', 52 }, 53 ...dontShowAgainOptions, 54 { 55 label: `No, and tell Claude what to do differently (${chalk.bold.hex(getTheme().warning)('esc')})`, 56 value: 'no', 57 }, 58 ] 59 }